Skip to content

Commit 1ff362a

Browse files
committed
Speed up agent editor loading with deferred Advanced data
Open Easy mode with only the main instruction prompt and fetch the remaining prompt files on first Advanced entry. Preserve unsaved edits, checkpoints, project scope changes and ACE undo history. Keep full loads as the API default for existing clients. Inventory prompt files once per root per request and render capability lists and tool actions only when expanded, avoiding work while those views are closed. Validation: 325 focused regression tests pass in the Docker framework runtime. Live browser and HTTP checks cover Global/project saves, deferred loading, mode switching, unsaved edits, action controls, ACE undo, and failed-load retry. The full suite reports 2,939 passed and 48 skipped; all 14 failures also reproduce against the unchanged HEAD before this change.
1 parent 345571c commit 1ff362a

9 files changed

Lines changed: 295 additions & 25 deletions

File tree

‎plugins/_agent_editor/AGENTS.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@
1919
- Plugin profile metadata layers merge bundled roots before user roots using
2020
stable root-priority sorting, matching runtime profile loading and catalogs.
2121
- The editor performs zero model calls.
22+
- Editor loads request `mode: easy` for only the main instruction prompt;
23+
omitted API modes retain the full catalog. The first Advanced entry loads
24+
the remaining prompts through the same scoped, authenticated handler and
25+
merges them into draft and checkpoints without overwriting Easy edits.
26+
Ignore late responses after the draft, scope or modal changes. Scope reloads
27+
include the full catalog once Advanced has been used.
28+
- Prompt catalogs inventory Markdown and processor files once per root per
29+
request and reuse source labels. Keep ordered inheritance, raw reads,
30+
recursive include previews and unreadable-file reporting; never retain the
31+
inventory across requests or run prompt processors.
2232
- Profile list requests stay lightweight: summary rows inspect only sparse
2333
editor-owned keys and files and never construct full save or removal plans.
2434
- Writes are limited to the selected profile layer — global
@@ -82,6 +92,10 @@
8292
state only. Show the enabled-action summary only when at least one action is
8393
off. Advanced action searches reveal matching children without narrowing the
8494
parent control's scope; opening and searching never write policy.
95+
- Closed Easy capability lists and collapsed action rows mount their controls
96+
only when expanded. Advanced mounts after its first prompt load, then stays
97+
mounted when returning to Easy so ACE undo history survives. Opening or closing
98+
these views must not change policy or lose pending prompt edits.
8599
- Model selection in both modes reuses `_model_config`'s compact preset dropdown
86100
and preset editor; Agent Editor persists only the scoped preset reference.
87101
- The exact `default` profile is an internal baseline and is omitted only from

‎plugins/_agent_editor/README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ Skills default switch. Easy places each chooser below its default switch;
1414
Advanced gives Tools, MCPs, and Skills separate searchable sections and adds
1515
retained unavailable entries plus ACE-based prompt editing.
1616

17+
Easy loads the main instructions first; the remaining prompt files load when
18+
you first open Advanced. Switching modes keeps unsaved edits and the prompt
19+
editor's undo history. Capability lists render their controls when expanded.
20+
1721
Bundled tools with multiple operations appear once in the list. Expand a tool
1822
to choose individual actions, such as Text Editor's Read / Write / Patch,
1923
with their available descriptions below the “Individual tool actions” subtitle.

‎plugins/_agent_editor/api/agent_editor.py‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@ async def process(self, input: dict, request: Request) -> dict | Response:
2121
profile_id = editor.validate_profile_id(input.get("profile_id"))
2222
return {
2323
"ok": True,
24-
"state": editor.build_editor_state(profile_id, context),
24+
"state": editor.build_editor_state(
25+
profile_id, context, mode=str(input.get("mode") or "advanced"),
26+
),
27+
}
28+
if action == "prompts":
29+
profile_id = editor.validate_profile_id(input.get("profile_id"))
30+
return {
31+
"ok": True,
32+
"prompts": editor.prompt_catalog(editor.EditorAgent(profile_id, context)),
2533
}
2634
if action == "quick_create":
2735
profile_id, receipt = editor.save_easy_profile(

‎plugins/_agent_editor/helpers/editor.py‎

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,16 @@ def list_profiles(context: Any | None = None) -> list[dict[str, Any]]:
230230
def build_editor_state(
231231
profile_id: str,
232232
context: Any | None = None,
233+
*,
234+
mode: str = "advanced",
233235
) -> dict[str, Any]:
236+
if mode not in {"easy", "advanced"}:
237+
raise ValueError("Unknown editor mode.")
234238
profile_id = validate_profile_id(profile_id)
235239
agent = EditorAgent(profile_id, context)
236-
prompt_files = prompt_catalog(agent)
240+
prompt_files = prompt_catalog(
241+
agent, names={SPECIFICS_FILE} if mode == "easy" else None,
242+
)
237243
from plugins._model_config.helpers import model_config
238244

239245
presets: list[dict[str, Any]] = []
@@ -309,6 +315,7 @@ def build_editor_state(
309315
return {
310316
"profile": build_profile_state(profile_id, context),
311317
"prompts": prompt_files,
318+
"prompts_complete": mode == "advanced",
312319
"tools": _editor_tool_state(agent, tool_scope),
313320
"skills": {
314321
"policy": skill_policy,
@@ -480,28 +487,40 @@ def _scope_has_overrides(profile_id: str, context: Any | None = None) -> bool:
480487
return any(any(key in _read_mapping(path) for key in keys) for path, keys in checks)
481488

482489

483-
def prompt_catalog(agent: EditorAgent) -> list[dict[str, Any]]:
490+
def prompt_catalog(agent: EditorAgent, *, names: set[str] | None = None) -> list[dict[str, Any]]:
484491
roots = [Path(path) for path in subagents.get_paths(agent, "prompts")]
485-
names = {
486-
path.name
492+
root_files = {
493+
root: {
494+
path.name: path
495+
for path in root.glob("*")
496+
if path.suffix in {".md", ".py"} and path.is_file()
497+
}
487498
for root in roots
488-
if root.is_dir()
489-
for path in root.glob("*.md")
490-
if path.is_file() and path.name not in NON_PROMPT_MARKDOWN
491499
}
500+
names = set(names) if names is not None else {
501+
name
502+
for paths in root_files.values()
503+
for name in paths
504+
if name.endswith(".md") and name not in NON_PROMPT_MARKDOWN
505+
}
506+
processors = {name for paths in root_files.values() for name in paths if name.endswith(".py")}
492507
names.add(SPECIFICS_FILE)
493508
project_name = _context_project_name(agent.context)
494509
scope_prompt_dir = _profile_root(agent.config.profile, project_name) / "prompts"
495510
project_root = (
496511
Path(projects.get_project_meta(project_name)) if project_name else None
497512
)
513+
sources = {
514+
root: _prompt_source(root, scope_prompt_dir, project_root)
515+
for root in roots if root_files[root]
516+
}
498517
result: list[dict[str, Any]] = []
499518
for name in sorted(names, key=lambda value: (_prompt_group(value)[0], value)):
500519
occurrences: list[tuple[Path, str, str]] = []
501520
for root in roots:
502-
path = root / name
503-
if path.is_file():
504-
kind, label = _prompt_source(root, scope_prompt_dir, project_root)
521+
path = root_files[root].get(name)
522+
if path is not None:
523+
kind, label = sources[root]
505524
occurrences.append((path, kind, label))
506525

507526
effective = occurrences[0] if occurrences else None
@@ -557,9 +576,7 @@ def prompt_catalog(agent: EditorAgent) -> list[dict[str, Any]]:
557576
],
558577
"preview": preview,
559578
"error": effective_error or override_error or inherited_error,
560-
"dynamic_processor": any(
561-
(root / f"{Path(name).stem}.py").is_file() for root in roots
562-
),
579+
"dynamic_processor": f"{Path(name).stem}.py" in processors,
563580
}
564581
)
565582
return result

‎plugins/_agent_editor/webui/agent-editor-store.js‎

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ const model = {
119119
mode: "easy",
120120
section: "1",
121121
loading: false,
122+
advancedLoaded: false,
123+
advancedLoading: false,
122124
saving: false,
123125
avatarUploading: false,
124126
error: "",
@@ -375,7 +377,7 @@ const model = {
375377
await modelConfigStore.loadAgentProfiles(true);
376378
if (editorState) {
377379
await this.loadEditor(profile.id, false);
378-
this.setMode(editorState.mode, editorState.section, false);
380+
await this.setMode(editorState.mode, editorState.section, false);
379381
}
380382
} catch (error) {
381383
this.error = error.message || String(error);
@@ -452,6 +454,7 @@ const model = {
452454
const data = await callJsonApi(API, {
453455
action: "load",
454456
profile_id: this.draft.creating ? "new-agent" : this.draft.profileId,
457+
mode: this.advancedLoaded ? "advanced" : "easy",
455458
...this.scopeInput(),
456459
});
457460
this.state = data.state;
@@ -519,6 +522,7 @@ const model = {
519522
const data = await callJsonApi(API, {
520523
action: "load",
521524
profile_id: profileId,
525+
mode: "easy",
522526
...this.scopeInput(),
523527
});
524528
this.state = data.state;
@@ -537,6 +541,8 @@ const model = {
537541
},
538542

539543
makeDraft(creating) {
544+
this.advancedLoaded = this.state.prompts_complete !== false;
545+
this.advancedLoading = false;
540546
this.expandedTools = {};
541547
const metadata = this.state.profile.metadata;
542548
const prompts = {};
@@ -699,7 +705,40 @@ const model = {
699705
this.setModalTitle("Manage agents");
700706
},
701707

702-
setMode(mode, section = "", preview = true) {
708+
async setMode(mode, section = "", preview = true) {
709+
if (this.advancedLoading) return;
710+
if (mode === "advanced" && !this.advancedLoaded) {
711+
if (this.loading || !this.draft) return;
712+
const draft = this.draft;
713+
const root = this.root;
714+
const projectName = this.projectName;
715+
this.advancedLoading = true;
716+
this.error = "";
717+
try {
718+
const data = await callJsonApi(API, {
719+
action: "prompts",
720+
profile_id: this.state.profile.id,
721+
...this.scopeInput(),
722+
});
723+
if (this.draft !== draft || this.projectName !== projectName || root?.isConnected === false) return;
724+
for (const item of data.prompts) {
725+
if (draft.prompts[item.filename]) continue;
726+
const value = String(item.effective || "");
727+
const prompt = { ...item, value, initialValue: value, reset: false };
728+
draft.prompts[item.filename] = prompt;
729+
this.initialDraft.prompts[item.filename] = clone(prompt);
730+
this.promptEditBaselines[item.filename] = { value, reset: false };
731+
}
732+
this.state.prompts = data.prompts;
733+
this.state.prompts_complete = true;
734+
this.advancedLoaded = true;
735+
} catch (error) {
736+
if (this.draft === draft && this.projectName === projectName) this.error = error.message || String(error);
737+
return;
738+
} finally {
739+
if (this.draft === draft) this.advancedLoading = false;
740+
}
741+
}
703742
this.mode = mode === "advanced" ? "advanced" : "easy";
704743
if (section) this.setSection(section, preview);
705744
else if (preview && this.mode === "advanced" && this.section === "6") this.previewPlan();
@@ -1161,6 +1200,7 @@ const model = {
11611200
const data = await callJsonApi(API, {
11621201
action: "load",
11631202
profile_id: this.draft.profileId || "new-agent",
1203+
mode: "easy",
11641204
...this.scopeInput(),
11651205
});
11661206
this.state.model_presets = data.state.model_presets;
@@ -1403,7 +1443,7 @@ const model = {
14031443
this.plan = data;
14041444
this.planStatus = "ready";
14051445
this.pendingMutation = { destructive };
1406-
this.setMode("advanced", "6", false);
1446+
await this.setMode("advanced", "6", false);
14071447
} catch (error) {
14081448
this.error = error.message || String(error);
14091449
} finally {

‎plugins/_agent_editor/webui/main.html‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@
124124
</div>
125125
<div class="agent-editor-topbar-actions">
126126
<div class="agent-mode-switch" role="group" aria-label="Editor mode">
127-
<button type="button" :class="{ active: $store.agentEditor.mode === 'easy' }" :aria-pressed="$store.agentEditor.mode === 'easy'" @click="$store.agentEditor.setMode('easy')">Easy</button>
128-
<button type="button" :class="{ active: $store.agentEditor.mode === 'advanced' }" :aria-pressed="$store.agentEditor.mode === 'advanced'" @click="$store.agentEditor.setMode('advanced')">Advanced</button>
127+
<button type="button" :class="{ active: $store.agentEditor.mode === 'easy' }" :aria-pressed="$store.agentEditor.mode === 'easy'" :disabled="$store.agentEditor.advancedLoading" @click="$store.agentEditor.setMode('easy')">Easy</button>
128+
<button type="button" :class="{ active: $store.agentEditor.mode === 'advanced' }" :aria-pressed="$store.agentEditor.mode === 'advanced'" :disabled="$store.agentEditor.advancedLoading" @click="$store.agentEditor.setMode('advanced')" x-text="$store.agentEditor.advancedLoading ? 'Loading…' : 'Advanced'">Advanced</button>
129129
</div>
130130
</div>
131131
</header>
@@ -183,45 +183,52 @@
183183
<div class="agent-field-heading"><div><div class="agent-field-label">Capabilities</div><p>Choose the default access, or set individual items On or Off.</p></div></div>
184184
<div class="capability-policy-group">
185185
<div class="future-policy-control"><strong>Allow tools by default</strong><label class="toggle"><input type="checkbox" :checked="$store.agentEditor.policyDefault('tool') === 'allow'" @change="$store.agentEditor.setPolicyDefault('tool', $event.target.checked ? 'allow' : 'block')" aria-label="Allow tools by default"><span class="toggler"></span></label></div>
186-
<details class="capability-accordion">
186+
<details class="capability-accordion" x-data="{ expanded: false }" @toggle.self="expanded = $el.open">
187187
<summary><span>Choose individual tools</span><x-icon name="expand_more"></x-icon></summary>
188+
<template x-if="expanded">
188189
<div class="policy-items" role="list" aria-label="Tools this agent can use">
189190
<template x-for="tool in $store.agentEditor.standardToolCatalog" :key="tool.id">
190191
<div><x-component path="/plugins/_agent_editor/webui/tool-policy-row.html"></x-component></div>
191192
</template>
192193
<p class="policy-empty" x-show="!$store.agentEditor.standardToolCatalog.length">No configurable tools are available.</p>
193194
</div>
195+
</template>
194196
</details>
195197
</div>
196198

197199
<div class="capability-policy-group">
198200
<div class="future-policy-control"><strong>Allow MCPs by default</strong><label class="toggle"><input type="checkbox" :checked="$store.agentEditor.policyDefault('mcp') === 'allow'" @change="$store.agentEditor.setPolicyDefault('mcp', $event.target.checked ? 'allow' : 'block')" aria-label="Allow MCPs by default"><span class="toggler"></span></label></div>
199-
<details class="capability-accordion">
201+
<details class="capability-accordion" x-data="{ expanded: false }" @toggle.self="expanded = $el.open">
200202
<summary><span>Choose individual MCPs</span><x-icon name="expand_more"></x-icon></summary>
203+
<template x-if="expanded">
201204
<div class="policy-items" role="list" aria-label="MCP tools this agent can use">
202205
<template x-for="tool in $store.agentEditor.mcpCatalog" :key="tool.id">
203206
<div class="policy-item" role="listitem"><div class="policy-item-copy"><strong x-text="tool.label"></strong><p class="policy-item-description" x-show="tool.description" x-text="tool.description"></p></div><div class="policy-state-control" role="group" :aria-label="`${tool.label} access`"><button type="button" :class="{ active: $store.agentEditor.policyItemState('mcp', tool.id) === 'allow' }" :aria-pressed="$store.agentEditor.policyItemState('mcp', tool.id) === 'allow'" @click="$store.agentEditor.setPolicyItem('mcp', tool.id, 'allow')">On</button><button type="button" :class="{ active: $store.agentEditor.policyItemState('mcp', tool.id) === 'default' }" :aria-pressed="$store.agentEditor.policyItemState('mcp', tool.id) === 'default'" @click="$store.agentEditor.setPolicyItem('mcp', tool.id, 'default')" x-text="`Default (${$store.agentEditor.policyDefault('mcp') === 'allow' ? 'on' : 'off'})`"></button><button type="button" :class="{ active: $store.agentEditor.policyItemState('mcp', tool.id) === 'block' }" :aria-pressed="$store.agentEditor.policyItemState('mcp', tool.id) === 'block'" @click="$store.agentEditor.setPolicyItem('mcp', tool.id, 'block')">Off</button></div></div>
204207
</template>
205208
<p class="policy-empty" x-show="!$store.agentEditor.mcpCatalog.length">No MCP tools are available.</p>
206209
</div>
210+
</template>
207211
</details>
208212
</div>
209213

210214
<div class="capability-policy-group">
211215
<div class="future-policy-control"><strong>Allow skills by default</strong><label class="toggle"><input type="checkbox" :checked="$store.agentEditor.policyDefault('skill') === 'allow'" @change="$store.agentEditor.setPolicyDefault('skill', $event.target.checked ? 'allow' : 'block')" aria-label="Allow skills by default"><span class="toggler"></span></label></div>
212-
<details class="capability-accordion">
216+
<details class="capability-accordion" x-data="{ expanded: false }" @toggle.self="expanded = $el.open">
213217
<summary><span>Choose individual skills</span><x-icon name="expand_more"></x-icon></summary>
218+
<template x-if="expanded">
214219
<div class="policy-items" role="list" aria-label="Skills this agent can use">
215220
<template x-for="skill in $store.agentEditor.skillCatalog" :key="skill.path">
216221
<div class="policy-item" role="listitem"><div class="policy-item-copy"><strong x-text="skill.name"></strong><p class="policy-item-description" x-show="skill.description" x-text="skill.description"></p><em x-show="$store.agentEditor.skillWarnings(skill).length" x-text="`Expects blocked tool: ${$store.agentEditor.skillWarnings(skill).join(', ')}`"></em></div><div class="policy-state-control" role="group" :aria-label="`${skill.name} access`"><button type="button" :class="{ active: $store.agentEditor.policyItemState('skill', skill.name) === 'allow' }" :aria-pressed="$store.agentEditor.policyItemState('skill', skill.name) === 'allow'" @click="$store.agentEditor.setPolicyItem('skill', skill.name, 'allow')">On</button><button type="button" :class="{ active: $store.agentEditor.policyItemState('skill', skill.name) === 'default' }" :aria-pressed="$store.agentEditor.policyItemState('skill', skill.name) === 'default'" @click="$store.agentEditor.setPolicyItem('skill', skill.name, 'default')" x-text="`Default (${$store.agentEditor.policyDefault('skill') === 'allow' ? 'on' : 'off'})`"></button><button type="button" :class="{ active: $store.agentEditor.policyItemState('skill', skill.name) === 'block' }" :aria-pressed="$store.agentEditor.policyItemState('skill', skill.name) === 'block'" @click="$store.agentEditor.setPolicyItem('skill', skill.name, 'block')">Off</button></div></div>
217222
</template>
218223
<p class="policy-empty" x-show="!$store.agentEditor.skillCatalog.length">No configurable skills are available.</p>
219224
</div>
225+
</template>
220226
</details>
221227
</div>
222228
</section>
223229
</main>
224230

231+
<template x-if="$store.agentEditor.advancedLoaded">
225232
<div class="agent-advanced" x-show="$store.agentEditor.mode === 'advanced'">
226233
<nav class="agent-advanced-nav" aria-label="Advanced editor sections">
227234
<template x-for="item in [{id:'1',label:'Identity'},{id:'2',label:'Prompt files'},{id:'3',label:'Tools'},{id:'4',label:'MCPs'},{id:'5',label:'Skills'},{id:'6',label:'Review'}]" :key="item.id">
@@ -371,6 +378,7 @@ <h4>Customized by you</h4><p x-text="`Remove only the customizations shown in th
371378
</section>
372379
</div>
373380
</div>
381+
</template>
374382

375383
</div>
376384
</template>

‎plugins/_agent_editor/webui/tool-policy-row.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<p class="tool-actions-hint" x-show="tool.visibleActions"
4646
x-text="`${tool.visibleActions?.length} matching actions of ${tool.actions.length}. Controls above apply to the whole tool.`"></p>
4747
<div role="list" :aria-label="`${tool.label} individual actions`">
48-
<template x-for="action in (tool.visibleActions || tool.actions)" :key="action.id">
48+
<template x-for="action in ($store.agentEditor.toolExpanded(tool) ? (tool.visibleActions || tool.actions) : [])" :key="action.id">
4949
<div class="policy-item tool-action-row" role="listitem">
5050
<div class="policy-item-copy">
5151
<span class="tool-action-name" x-text="action.action_label"></span>

0 commit comments

Comments
 (0)