Skip to content

Agent Zero AI framework

Stabilize Agent Editor client workflows

Alessandrob5ab1d5b8f37
diff --git a/plugins/_agent_editor/webui/agent-editor-store.js b/plugins/_agent_editor/webui/agent-editor-store.js
index 3edcc811e..105dfa725 100644
--- a/plugins/_agent_editor/webui/agent-editor-store.js
+++ b/plugins/_agent_editor/webui/agent-editor-store.js
@@ -306,6 +306,49 @@ const model = {
this.projectName = previous;
return;
}
+ const reviewActive = this.mode === "advanced" && this.section === "5";
+ const creatingDraft = this.draft?.creating ? this.draft : null;
+ const creatingInitial = creatingDraft ? this.initialDraft : null;
+ const creatingState = creatingDraft ? this.state : null;
+ const selectedPrompt = this.selectedPrompt;
+ const comparePrompt = this.comparePrompt;
+ const promptChanges = creatingDraft
+ ? Object.values(creatingDraft.prompts).flatMap((prompt) => {
+ const initial = creatingInitial?.prompts?.[prompt.filename];
+ if (!initial || prompt.reset || prompt.value === initial.value) return [];
+ const baseline = this.promptEditBaselines[prompt.filename];
+ const initialBaseline = { value: initial.value, reset: initial.reset };
+ return [{
+ filename: prompt.filename,
+ value: prompt.value,
+ baseline: baseline && !same(baseline, initialBaseline) ? clone(baseline) : null,
+ }];
+ })
+ : [];
+ const policyChanges = [];
+ if (creatingDraft) {
+ for (const [kind, key, idKey] of [
+ ["tools", "toolPolicy", "id"],
+ ["skills", "skillPolicy", "name"],
+ ]) {
+ const policy = creatingDraft[key];
+ if (policy.mode !== "custom" || same(policy, creatingInitial[key])) continue;
+ const oldState = creatingState[kind];
+ policyChanges.push({
+ kind: kind === "tools" ? "tool" : "skill",
+ key,
+ idKey,
+ default: policy.default,
+ choices: (oldState.catalog || [])
+ .map((item) => [
+ item[idKey],
+ policyAllows(policy, item[idKey]),
+ policyAllows(oldState.effective_policy, item[idKey]),
+ ])
+ .filter(([, allowed, inherited]) => allowed !== inherited),
+ });
+ }
+ }
this.intent = { ...this.intent, projectName: next };
this.loading = true;
this.error = "";
@@ -325,7 +368,48 @@ const model = {
...this.scopeInput(),
});
this.state = data.state;
- if (!this.draft.creating) this.makeDraft(false);
+ if (!creatingDraft) {
+ this.makeDraft(false);
+ } else {
+ const avatarChanged = !same(
+ [creatingDraft.avatar, creatingDraft.avatarToken, creatingDraft.metadataResets.includes("avatar")],
+ [creatingInitial.avatar, creatingInitial.avatarToken, creatingInitial.metadataResets.includes("avatar")],
+ );
+ const modelPresetChanged = creatingDraft.modelPreset !== creatingInitial.modelPreset;
+ this.makeDraft(true);
+ this.draft.profileId = creatingDraft.profileId;
+ this.draft.title = creatingDraft.title;
+ this.draft.description = creatingDraft.description;
+ this.draft.context = creatingDraft.context;
+ for (const change of promptChanges) {
+ const prompt = this.draft.prompts[change.filename];
+ if (!prompt) continue;
+ prompt.value = change.value;
+ prompt.reset = false;
+ if (change.baseline) this.promptEditBaselines[change.filename] = change.baseline;
+ }
+ if (this.draft.prompts[selectedPrompt]) this.selectedPrompt = selectedPrompt;
+ this.comparePrompt = comparePrompt;
+ if (avatarChanged) {
+ this.draft.avatar = clone(creatingDraft.avatar);
+ this.draft.avatarToken = creatingDraft.avatarToken;
+ this.draft.avatarPreview = creatingDraft.avatarPreview;
+ if (creatingDraft.metadataResets.includes("avatar")) {
+ this.draft.metadataResets.push("avatar");
+ }
+ }
+ if (modelPresetChanged) this.draft.modelPreset = creatingDraft.modelPreset;
+ for (const change of policyChanges) {
+ this.customizePolicy(change.kind);
+ this.setPolicyDefault(change.kind, change.default);
+ const catalog = this.state[change.kind === "tool" ? "tools" : "skills"].catalog || [];
+ const nextIds = new Set(catalog.map((item) => item[change.idKey]));
+ for (const [id, allowed] of change.choices) {
+ if (nextIds.has(id)) movePolicyItem(this.draft[change.key], id, allowed);
+ }
+ }
+ }
+ if (reviewActive) await this.previewPlan();
} catch (error) {
if (this.view === "editor" && this.projectName !== previous) {
this.projectName = previous;
@@ -500,6 +584,20 @@ const model = {
inner?.classList.toggle("agent-editor-easy", this.mode !== "advanced");
},
+ enterManager() {
+ this.revokePreview();
+ this.draft = null;
+ this.initialDraft = null;
+ this.promptEditBaselines = {};
+ this.pendingMutation = null;
+ this.plan = { written: [], deleted: [], warnings: [] };
+ this.planStatus = "idle";
+ this.view = "manage";
+ this.mode = "easy";
+ this.syncSurface();
+ this.setModalTitle("Manage agents");
+ },
+
setMode(mode, section = "", preview = true) {
this.mode = mode === "advanced" ? "advanced" : "easy";
if (section) this.setSection(section, preview);
@@ -634,6 +732,7 @@ const model = {
},
metadataProvenance(key) {
+ if (this.draft?.creating) return "";
const metadata = this.state?.profile?.metadata?.[key] || {};
if (metadata.has_override && !this.metadataResetPending(key)) return "Customized by you";
if (this.projectName) return "Inherited from Global";
@@ -942,9 +1041,16 @@ const model = {
if (this.profileConflict) {
issues.push({ key: "name", section: "1", field: "agent-editor-advanced-name", label: "Agent name", message: `An agent with profile ID ${this.draft.profileId} already exists.` });
}
- if (!this.instructions?.value.trim()) {
- issues.push({ key: "instructions", section: "2", field: "agent-editor-prompt-text", label: "Instructions", message: "Instructions are required for a new agent." });
- }
+ }
+ const instructions = this.instructions;
+ if (!instructions?.reset && !instructions?.value.trim()
+ && (this.draft?.creating
+ || (this.mode === "easy" && instructions?.value !== instructions?.initialValue))) {
+ const fallback = this.projectName ? "inherited" : "default";
+ const message = this.draft.creating
+ ? "Instructions are required for a new agent."
+ : `Instructions can’t be empty. Use ${fallback} instructions instead.`;
+ issues.push({ key: "instructions", section: "2", field: "agent-editor-prompt-text", label: "Instructions", message });
}
if (this.avatarUploading) {
issues.push({ key: "avatar", section: "1", field: "agent-editor-advanced-name", label: "Avatar", message: "Wait for the avatar upload to finish." });
@@ -978,7 +1084,8 @@ const model = {
};
const metadata = { set: {}, reset: unique(this.draft.metadataResets) };
for (const key of ["title", "description", "context"]) {
- if (this.draft.creating ? key === "title" : this.draft[key] !== this.initialDraft[key]) {
+ if ((this.draft.creating && key === "title")
+ || this.draft[key] !== this.initialDraft[key]) {
if (!metadata.reset.includes(key)) metadata.set[key] = this.draft[key];
}
}
@@ -1052,7 +1159,7 @@ const model = {
},
async save(test = false) {
- if (this.saving || !this.draft) return false;
+ if (this.saving || !this.draft || this.pendingMutation) return false;
const errors = this.validationErrors();
if (errors.length) {
this.error = "";
@@ -1132,6 +1239,10 @@ const model = {
},
async planRemoval(destructive = false) {
+ if (this.dirty) {
+ this.error = "Save or discard your changes before removing customizations.";
+ return false;
+ }
this.planLoading = true;
this.error = "";
try {
@@ -1154,6 +1265,10 @@ const model = {
async applyPendingMutation() {
if (!this.pendingMutation) return;
+ if (this.dirty) {
+ this.error = "Save or discard your changes before applying the removal plan.";
+ return false;
+ }
const planned = [
["Will update", this.plan.written || []],
["Will delete", this.plan.deleted || []],
@@ -1173,6 +1288,7 @@ const model = {
action: "remove_changes",
profile_id: this.draft.profileId,
destructive: this.pendingMutation.destructive,
+ confirm: this.pendingMutation.destructive ? true : undefined,
...this.scopeInput(),
});
this.pendingMutation = null;
@@ -1184,6 +1300,7 @@ const model = {
},
async deleteProfile(profileId) {
+ this.error = "";
try {
const confirmed = await showConfirmDialog({
title: `Delete ${escapeHtml(profileId)}?`,
@@ -1200,8 +1317,7 @@ const model = {
});
await this.loadProfiles();
await modelConfigStore.loadAgentProfiles(true);
- this.view = "manage";
- this.setModalTitle("Manage agents");
+ this.enterManager();
globalThis.justToast?.(`Agent deleted from ${this.scopeLabel}.`, "success", 1800);
} catch (error) {
this.error = error.message || String(error);
@@ -1210,10 +1326,8 @@ const model = {
showManager() {
if (this.dirty && !window.confirm("You have unsaved changes that will be lost. Continue?")) return;
- this.view = "manage";
- this.mode = "easy";
- this.syncSurface();
- this.setModalTitle("Manage agents");
+ this.error = "";
+ this.enterManager();
this.loadProfiles();
},
};
diff --git a/plugins/_agent_editor/webui/main.html b/plugins/_agent_editor/webui/main.html
index 4ebac0e11..f40b7da56 100644
--- a/plugins/_agent_editor/webui/main.html
+++ b/plugins/_agent_editor/webui/main.html
@@ -159,7 +159,7 @@
<section class="agent-easy-field agent-easy-tools">
<div class="agent-field-heading">
- <div><div class="agent-field-label">Tools</div><p>Choose which tools this agent can use.</p></div>
+ <div><div class="agent-field-label">Tools <span class="field-count" x-text="`— ${$store.agentEditor.toolCatalog.length} ${$store.agentEditor.toolCatalog.length === 1 ? 'tool' : 'tools'}`"></span></div><p>Choose which tools this agent can use.</p></div>
</div>
<div class="easy-tool-list" role="list" aria-label="Tools this agent can use">
<template x-for="tool in $store.agentEditor.toolCatalog" :key="tool.id">
@@ -202,9 +202,9 @@
</div>
</div>
<div class="identity-fields">
- <div class="agent-field"><label for="agent-editor-advanced-name" class="agent-field-label">Agent name</label><input id="agent-editor-advanced-name" type="text" x-model="$store.agentEditor.draft.title" @input="$store.agentEditor.onNameInput(); $store.agentEditor.markMetadataSet('title')" :aria-invalid="$store.agentEditor.fieldIssue('name') ? 'true' : null" :aria-describedby="$store.agentEditor.fieldIssue('name') ? 'agent-editor-advanced-name-error' : null"><span id="agent-editor-advanced-name-error" class="field-error" role="alert" x-show="$store.agentEditor.fieldIssue('name')" x-text="$store.agentEditor.fieldIssue('name')?.message"></span><small class="field-provenance" x-text="$store.agentEditor.metadataProvenance('title')"></small><button type="button" class="text-button" x-show="$store.agentEditor.canResetMetadata('title')" @click="$store.agentEditor.resetMetadata('title')">Reset to inherited</button><small class="field-status" x-show="$store.agentEditor.metadataResetPending('title')">Will reset to inherited on save.</small></div>
+ <div class="agent-field"><label for="agent-editor-advanced-name" class="agent-field-label">Agent name</label><input id="agent-editor-advanced-name" type="text" x-model="$store.agentEditor.draft.title" @input="$store.agentEditor.onNameInput(); $store.agentEditor.markMetadataSet('title')" :aria-invalid="$store.agentEditor.fieldIssue('name') ? 'true' : null" :aria-describedby="$store.agentEditor.fieldIssue('name') ? 'agent-editor-advanced-name-error' : null"><span id="agent-editor-advanced-name-error" class="field-error" role="alert" x-show="$store.agentEditor.fieldIssue('name')" x-text="$store.agentEditor.fieldIssue('name')?.message"></span><small class="field-provenance" x-show="$store.agentEditor.metadataProvenance('title')" x-text="$store.agentEditor.metadataProvenance('title')"></small><button type="button" class="text-button" x-show="$store.agentEditor.canResetMetadata('title')" @click="$store.agentEditor.resetMetadata('title')">Reset to inherited</button><small class="field-status" x-show="$store.agentEditor.metadataResetPending('title')">Will reset to inherited on save.</small></div>
<label class="agent-field"><span class="agent-field-label">Profile ID</span><input type="text" :value="$store.agentEditor.draft.profileId" readonly aria-describedby="profile-id-help"><small id="profile-id-help">Used as the profile folder name. Existing IDs do not change when the display name changes.</small></label>
- <div class="agent-field wide"><label for="agent-editor-description" class="agent-field-label">Description</label><textarea id="agent-editor-description" rows="2" x-model="$store.agentEditor.draft.description" @input="$store.agentEditor.markMetadataSet('description')"></textarea><small>Short summary shown in profile lists.</small><small class="field-provenance" x-text="$store.agentEditor.metadataProvenance('description')"></small><button type="button" class="text-button" x-show="$store.agentEditor.canResetMetadata('description')" @click="$store.agentEditor.resetMetadata('description')">Reset to inherited</button><small class="field-status" x-show="$store.agentEditor.metadataResetPending('description')">Will reset to inherited on save.</small></div>
+ <div class="agent-field wide"><label for="agent-editor-description" class="agent-field-label">Description</label><textarea id="agent-editor-description" rows="2" x-model="$store.agentEditor.draft.description" @input="$store.agentEditor.markMetadataSet('description')"></textarea><small>Short summary shown in profile lists.</small><small class="field-provenance" x-show="$store.agentEditor.metadataProvenance('description')" x-text="$store.agentEditor.metadataProvenance('description')"></small><button type="button" class="text-button" x-show="$store.agentEditor.canResetMetadata('description')" @click="$store.agentEditor.resetMetadata('description')">Reset to inherited</button><small class="field-status" x-show="$store.agentEditor.metadataResetPending('description')">Will reset to inherited on save.</small></div>
<div class="agent-field wide agent-model-preset">
<label for="agent-editor-model-preset" class="agent-field-label">Model preset</label>
<div class="agent-model-preset-picker">
@@ -218,7 +218,7 @@
</div>
<small>Use the current preset or choose another setup for this agent.</small>
</div>
- <div class="agent-field wide"><label for="agent-editor-context" class="agent-field-label">When should other agents use this agent?</label><textarea id="agent-editor-context" rows="3" x-model="$store.agentEditor.draft.context" @input="$store.agentEditor.markMetadataSet('context')"></textarea><small>Helps Agent Zero decide when to delegate work to this profile.</small><small class="field-provenance" x-text="$store.agentEditor.metadataProvenance('context')"></small><button type="button" class="text-button" x-show="$store.agentEditor.canResetMetadata('context')" @click="$store.agentEditor.resetMetadata('context')">Reset to inherited</button><small class="field-status" x-show="$store.agentEditor.metadataResetPending('context')">Will reset to inherited on save.</small><span class="field-status" x-show="!$store.agentEditor.draft.context">Delegation quality can be lower while this is empty.</span></div>
+ <div class="agent-field wide"><label for="agent-editor-context" class="agent-field-label">When should other agents use this agent?</label><textarea id="agent-editor-context" rows="3" x-model="$store.agentEditor.draft.context" @input="$store.agentEditor.markMetadataSet('context')"></textarea><small>Helps Agent Zero decide when to delegate work to this profile.</small><small class="field-provenance" x-show="$store.agentEditor.metadataProvenance('context')" x-text="$store.agentEditor.metadataProvenance('context')"></small><button type="button" class="text-button" x-show="$store.agentEditor.canResetMetadata('context')" @click="$store.agentEditor.resetMetadata('context')">Reset to inherited</button><small class="field-status" x-show="$store.agentEditor.metadataResetPending('context')">Will reset to inherited on save.</small><span class="field-status" x-show="!$store.agentEditor.draft.context">Delegation quality can be lower while this is empty.</span></div>
</div>
</div>
</section>
@@ -270,14 +270,14 @@
<section x-show="$store.agentEditor.section === '3'" data-agent-editor-section="3" tabindex="-1" aria-labelledby="agent-section-3-title">
<header class="advanced-section-heading"><h3 id="agent-section-3-title">Tools</h3><p>Choose which tools this agent can use.</p></header>
- <div class="policy-mode-row"><label><input type="radio" name="tool-policy-mode" :checked="$store.agentEditor.draft.toolPolicy.mode === 'inherit'" @change="$store.agentEditor.useStandardTools()"><span><span x-text="$store.agentEditor.projectName ? 'Use inherited tool access' : 'Use standard tool access'"></span> <small x-text="`(${$store.agentEditor.toolCatalog.length} tools)`"></small></span></label><label><input type="radio" name="tool-policy-mode" :checked="$store.agentEditor.draft.toolPolicy.mode === 'custom'" @change="$store.agentEditor.chooseTools()">Choose tools</label></div>
+ <div class="policy-mode-row"><label><input type="radio" name="tool-policy-mode" :checked="$store.agentEditor.draft.toolPolicy.mode === 'inherit'" @change="$store.agentEditor.useStandardTools()"><span><span x-text="$store.agentEditor.projectName ? 'Use inherited tool access' : 'Use standard tool access'"></span> <small x-text="`(${$store.agentEditor.toolCatalog.length} ${$store.agentEditor.toolCatalog.length === 1 ? 'tool' : 'tools'})`"></small></span></label><label><input type="radio" name="tool-policy-mode" :checked="$store.agentEditor.draft.toolPolicy.mode === 'custom'" @change="$store.agentEditor.chooseTools()">Choose tools</label></div>
<fieldset class="policy-editor" :disabled="$store.agentEditor.draft.toolPolicy.mode !== 'custom'">
<legend class="sr-only">Tool access selection</legend>
<div class="policy-filters tools"><label class="policy-search"><x-icon name="search"></x-icon><span class="sr-only">Search tools</span><input type="search" x-model="$store.agentEditor.toolSearch" placeholder="Search tools"></label><label>Category <select x-model="$store.agentEditor.toolCategory"><option value="all">All</option><option value="local">Local</option><option value="plugin">Plugin</option><option value="mcp">MCP</option></select></label><label>Origin <select x-model="$store.agentEditor.toolOrigin"><option value="all">All</option><template x-for="origin in $store.agentEditor.toolOrigins" :key="origin"><option :value="origin" x-text="origin"></option></template></select></label></div>
<div class="policy-lists">
- <section class="policy-list" aria-labelledby="allowed-tools-title"><header><div><h4 id="allowed-tools-title">Allowed</h4><span x-text="`${$store.agentEditor.filteredTools(true).length} tools`"></span></div><button type="button" class="button policy-bulk" x-show="$store.agentEditor.draft.toolPolicy.mode === 'custom' && $store.agentEditor.filteredTools(true).length" @click="$store.agentEditor.moveAllVisibleTools(false)" x-text="`Block ${$store.agentEditor.filteredTools(true).length} shown`"></button></header><div class="policy-items"><p class="policy-empty" x-show="!$store.agentEditor.filteredTools(true).length">No allowed tools — select items on the right, or allow new tools automatically.</p><template x-for="tool in $store.agentEditor.filteredTools(true)" :key="tool.id"><div class="policy-item"><input type="checkbox" :value="tool.id" x-model="$store.agentEditor.selectedAllowedTools" :aria-label="`Select ${tool.label}`"><div><strong x-text="tool.label"></strong><small x-text="tool.id"></small><p class="policy-item-description" x-show="tool.description" x-text="tool.description"></p><em x-show="!tool.available">Unavailable — kept in your settings</em></div></div></template></div></section>
+ <section class="policy-list" aria-labelledby="allowed-tools-title"><header><div><h4 id="allowed-tools-title">Allowed</h4><span x-text="`${$store.agentEditor.filteredTools(true).length} ${$store.agentEditor.filteredTools(true).length === 1 ? 'tool' : 'tools'}`"></span></div><button type="button" class="button policy-bulk" x-show="$store.agentEditor.draft.toolPolicy.mode === 'custom' && $store.agentEditor.filteredTools(true).length" @click="$store.agentEditor.moveAllVisibleTools(false)" x-text="`Block ${$store.agentEditor.filteredTools(true).length} shown`"></button></header><div class="policy-items"><p class="policy-empty" x-show="!$store.agentEditor.filteredTools(true).length">No allowed tools — select items on the right, or allow new tools automatically.</p><template x-for="tool in $store.agentEditor.filteredTools(true)" :key="tool.id"><div class="policy-item"><input type="checkbox" :value="tool.id" x-model="$store.agentEditor.selectedAllowedTools" :aria-label="`Select ${tool.label}`"><div><strong x-text="tool.label"></strong><small x-text="tool.id"></small><p class="policy-item-description" x-show="tool.description" x-text="tool.description"></p><em x-show="!tool.available">Unavailable — kept in your settings</em></div></div></template></div></section>
<div class="policy-transfer-actions" role="group" aria-label="Move selected tools"><button type="button" class="button icon" :disabled="!$store.agentEditor.selectedAllowedTools.length" aria-label="Block selected tools" @click="$store.agentEditor.moveTools($store.agentEditor.selectedAllowedTools, false)"><x-icon name="arrow_forward"></x-icon></button><button type="button" class="button icon" :disabled="!$store.agentEditor.selectedBlockedTools.length" aria-label="Allow selected tools" @click="$store.agentEditor.moveTools($store.agentEditor.selectedBlockedTools, true)"><x-icon name="arrow_back"></x-icon></button></div>
- <section class="policy-list" aria-labelledby="blocked-tools-title"><header><div><h4 id="blocked-tools-title">Blocked</h4><span x-text="`${$store.agentEditor.filteredTools(false).length} tools`"></span></div><button type="button" class="button policy-bulk" x-show="$store.agentEditor.draft.toolPolicy.mode === 'custom' && $store.agentEditor.filteredTools(false).length" @click="$store.agentEditor.moveAllVisibleTools(true)" x-text="`Allow ${$store.agentEditor.filteredTools(false).length} shown`"></button></header><div class="policy-items"><p class="policy-empty" x-show="!$store.agentEditor.filteredTools(false).length" x-text="$store.agentEditor.draft.toolPolicy.mode === 'custom' ? 'No blocked tools — select items on the left, or block new tools until reviewed.' : 'Choose tools to customize standard access.'"></p><template x-for="tool in $store.agentEditor.filteredTools(false)" :key="tool.id"><div class="policy-item"><input type="checkbox" :value="tool.id" x-model="$store.agentEditor.selectedBlockedTools" :aria-label="`Select ${tool.label}`"><div><strong x-text="tool.label"></strong><small x-text="tool.id"></small><p class="policy-item-description" x-show="tool.description" x-text="tool.description"></p><em x-show="!tool.available">Unavailable — kept in your settings</em></div></div></template></div></section>
+ <section class="policy-list" aria-labelledby="blocked-tools-title"><header><div><h4 id="blocked-tools-title">Blocked</h4><span x-text="`${$store.agentEditor.filteredTools(false).length} ${$store.agentEditor.filteredTools(false).length === 1 ? 'tool' : 'tools'}`"></span></div><button type="button" class="button policy-bulk" x-show="$store.agentEditor.draft.toolPolicy.mode === 'custom' && $store.agentEditor.filteredTools(false).length" @click="$store.agentEditor.moveAllVisibleTools(true)" x-text="`Allow ${$store.agentEditor.filteredTools(false).length} shown`"></button></header><div class="policy-items"><p class="policy-empty" x-show="!$store.agentEditor.filteredTools(false).length" x-text="$store.agentEditor.draft.toolPolicy.mode === 'custom' ? 'No blocked tools — select items on the left, or block new tools until reviewed.' : 'Choose tools to customize standard access.'"></p><template x-for="tool in $store.agentEditor.filteredTools(false)" :key="tool.id"><div class="policy-item"><input type="checkbox" :value="tool.id" x-model="$store.agentEditor.selectedBlockedTools" :aria-label="`Select ${tool.label}`"><div><strong x-text="tool.label"></strong><small x-text="tool.id"></small><p class="policy-item-description" x-show="tool.description" x-text="tool.description"></p><em x-show="!tool.available">Unavailable — kept in your settings</em></div></div></template></div></section>
</div>
<fieldset class="future-default"><legend>When new tools are installed later</legend><label><input type="radio" name="tool-future-default" value="allow" :checked="$store.agentEditor.draft.toolPolicy.default === 'allow'" @change="$store.agentEditor.setPolicyDefault('tool','allow')">Allow automatically</label><label><input type="radio" name="tool-future-default" value="block" :checked="$store.agentEditor.draft.toolPolicy.default === 'block'" @change="$store.agentEditor.setPolicyDefault('tool','block')">Block until reviewed</label></fieldset>
</fieldset>
@@ -285,14 +285,14 @@
<section x-show="$store.agentEditor.section === '4'" data-agent-editor-section="4" tabindex="-1" aria-labelledby="agent-section-4-title">
<header class="advanced-section-heading"><h3 id="agent-section-4-title">Skills</h3><p>Choose which skills this agent can find and use.</p></header>
- <div class="policy-mode-row"><label><input type="radio" name="skill-policy-mode" :checked="$store.agentEditor.draft.skillPolicy.mode === 'inherit'" @change="$store.agentEditor.useStandardSkills()"><span><span x-text="$store.agentEditor.projectName ? 'Use inherited skill access' : 'Use standard skill access'"></span> <small x-text="`(${$store.agentEditor.skillCatalog.length} skills)`"></small></span></label><label><input type="radio" name="skill-policy-mode" :checked="$store.agentEditor.draft.skillPolicy.mode === 'custom'" @change="$store.agentEditor.chooseSkills()">Choose skills</label></div>
+ <div class="policy-mode-row"><label><input type="radio" name="skill-policy-mode" :checked="$store.agentEditor.draft.skillPolicy.mode === 'inherit'" @change="$store.agentEditor.useStandardSkills()"><span><span x-text="$store.agentEditor.projectName ? 'Use inherited skill access' : 'Use standard skill access'"></span> <small x-text="`(${$store.agentEditor.skillCatalog.length} ${$store.agentEditor.skillCatalog.length === 1 ? 'skill' : 'skills'})`"></small></span></label><label><input type="radio" name="skill-policy-mode" :checked="$store.agentEditor.draft.skillPolicy.mode === 'custom'" @change="$store.agentEditor.chooseSkills()">Choose skills</label></div>
<fieldset class="policy-editor" :disabled="$store.agentEditor.draft.skillPolicy.mode !== 'custom'">
<legend class="sr-only">Skill access selection</legend>
<div class="policy-filters skills"><label class="policy-search"><x-icon name="search"></x-icon><span class="sr-only">Search skills</span><input type="search" x-model="$store.agentEditor.skillSearch" placeholder="Search skills"></label><label>Origin <select x-model="$store.agentEditor.skillOrigin"><option value="all">All</option><template x-for="origin in $store.agentEditor.skillOrigins" :key="origin"><option :value="origin" x-text="origin"></option></template></select></label></div>
<div class="policy-lists">
- <section class="policy-list" aria-labelledby="allowed-skills-title"><header><div><h4 id="allowed-skills-title">Allowed</h4><span x-text="`${$store.agentEditor.filteredSkills(true).length} skills`"></span></div><button type="button" class="button policy-bulk" x-show="$store.agentEditor.draft.skillPolicy.mode === 'custom' && $store.agentEditor.filteredSkills(true).length" @click="$store.agentEditor.moveAllVisibleSkills(false)" x-text="`Block ${$store.agentEditor.filteredSkills(true).length} shown`"></button></header><div class="policy-items"><p class="policy-empty" x-show="!$store.agentEditor.filteredSkills(true).length">No allowed skills — select items on the right, or allow new skills automatically.</p><template x-for="skill in $store.agentEditor.filteredSkills(true)" :key="skill.path"><div class="policy-item"><input type="checkbox" :value="skill.name" x-model="$store.agentEditor.selectedAllowedSkills" :aria-label="`Select ${skill.name}`"><div><strong x-text="skill.name"></strong><small x-text="skill.origin"></small><p class="policy-item-description" x-show="skill.description" x-text="skill.description"></p><em x-show="skill.available === false">Unavailable — kept in your settings</em><em x-show="$store.agentEditor.skillWarnings(skill).length" x-text="`Expects blocked tool: ${$store.agentEditor.skillWarnings(skill).join(', ')}`"></em></div></div></template></div></section>
+ <section class="policy-list" aria-labelledby="allowed-skills-title"><header><div><h4 id="allowed-skills-title">Allowed</h4><span x-text="`${$store.agentEditor.filteredSkills(true).length} ${$store.agentEditor.filteredSkills(true).length === 1 ? 'skill' : 'skills'}`"></span></div><button type="button" class="button policy-bulk" x-show="$store.agentEditor.draft.skillPolicy.mode === 'custom' && $store.agentEditor.filteredSkills(true).length" @click="$store.agentEditor.moveAllVisibleSkills(false)" x-text="`Block ${$store.agentEditor.filteredSkills(true).length} shown`"></button></header><div class="policy-items"><p class="policy-empty" x-show="!$store.agentEditor.filteredSkills(true).length">No allowed skills — select items on the right, or allow new skills automatically.</p><template x-for="skill in $store.agentEditor.filteredSkills(true)" :key="skill.path"><div class="policy-item"><input type="checkbox" :value="skill.name" x-model="$store.agentEditor.selectedAllowedSkills" :aria-label="`Select ${skill.name}`"><div><strong x-text="skill.name"></strong><small x-text="skill.origin"></small><p class="policy-item-description" x-show="skill.description" x-text="skill.description"></p><em x-show="skill.available === false">Unavailable — kept in your settings</em><em x-show="$store.agentEditor.skillWarnings(skill).length" x-text="`Expects blocked tool: ${$store.agentEditor.skillWarnings(skill).join(', ')}`"></em></div></div></template></div></section>
<div class="policy-transfer-actions" role="group" aria-label="Move selected skills"><button type="button" class="button icon" :disabled="!$store.agentEditor.selectedAllowedSkills.length" aria-label="Block selected skills" @click="$store.agentEditor.moveSkills($store.agentEditor.selectedAllowedSkills, false)"><x-icon name="arrow_forward"></x-icon></button><button type="button" class="button icon" :disabled="!$store.agentEditor.selectedBlockedSkills.length" aria-label="Allow selected skills" @click="$store.agentEditor.moveSkills($store.agentEditor.selectedBlockedSkills, true)"><x-icon name="arrow_back"></x-icon></button></div>
- <section class="policy-list" aria-labelledby="blocked-skills-title"><header><div><h4 id="blocked-skills-title">Blocked</h4><span x-text="`${$store.agentEditor.filteredSkills(false).length} skills`"></span></div><button type="button" class="button policy-bulk" x-show="$store.agentEditor.draft.skillPolicy.mode === 'custom' && $store.agentEditor.filteredSkills(false).length" @click="$store.agentEditor.moveAllVisibleSkills(true)" x-text="`Allow ${$store.agentEditor.filteredSkills(false).length} shown`"></button></header><div class="policy-items"><p class="policy-empty" x-show="!$store.agentEditor.filteredSkills(false).length" x-text="$store.agentEditor.draft.skillPolicy.mode === 'custom' ? 'No blocked skills — select items on the left, or block new skills until reviewed.' : 'Choose skills to customize standard access.'"></p><template x-for="skill in $store.agentEditor.filteredSkills(false)" :key="skill.path"><div class="policy-item"><input type="checkbox" :value="skill.name" x-model="$store.agentEditor.selectedBlockedSkills" :aria-label="`Select ${skill.name}`"><div><strong x-text="skill.name"></strong><small x-text="skill.origin"></small><p class="policy-item-description" x-show="skill.description" x-text="skill.description"></p><em x-show="skill.available === false">Unavailable — kept in your settings</em></div></div></template></div></section>
+ <section class="policy-list" aria-labelledby="blocked-skills-title"><header><div><h4 id="blocked-skills-title">Blocked</h4><span x-text="`${$store.agentEditor.filteredSkills(false).length} ${$store.agentEditor.filteredSkills(false).length === 1 ? 'skill' : 'skills'}`"></span></div><button type="button" class="button policy-bulk" x-show="$store.agentEditor.draft.skillPolicy.mode === 'custom' && $store.agentEditor.filteredSkills(false).length" @click="$store.agentEditor.moveAllVisibleSkills(true)" x-text="`Allow ${$store.agentEditor.filteredSkills(false).length} shown`"></button></header><div class="policy-items"><p class="policy-empty" x-show="!$store.agentEditor.filteredSkills(false).length" x-text="$store.agentEditor.draft.skillPolicy.mode === 'custom' ? 'No blocked skills — select items on the left, or block new skills until reviewed.' : 'Choose skills to customize standard access.'"></p><template x-for="skill in $store.agentEditor.filteredSkills(false)" :key="skill.path"><div class="policy-item"><input type="checkbox" :value="skill.name" x-model="$store.agentEditor.selectedBlockedSkills" :aria-label="`Select ${skill.name}`"><div><strong x-text="skill.name"></strong><small x-text="skill.origin"></small><p class="policy-item-description" x-show="skill.description" x-text="skill.description"></p><em x-show="skill.available === false">Unavailable — kept in your settings</em></div></div></template></div></section>
</div>
<fieldset class="future-default"><legend>When new skills are installed later</legend><label><input type="radio" name="skill-future-default" :checked="$store.agentEditor.draft.skillPolicy.default === 'allow'" @change="$store.agentEditor.setPolicyDefault('skill','allow')">Allow automatically</label><label><input type="radio" name="skill-future-default" :checked="$store.agentEditor.draft.skillPolicy.default === 'block'" @change="$store.agentEditor.setPolicyDefault('skill','block')">Block until reviewed</label></fieldset>
</fieldset>
@@ -314,11 +314,11 @@
<template x-if="$store.agentEditor.plan.warnings?.length"><section><h4>Notices</h4><ul><template x-for="warning in $store.agentEditor.plan.warnings" :key="warning"><li x-text="warning"></li></template></ul></section></template>
</div>
<div class="review-actions" x-show="$store.agentEditor.pendingMutation"><button type="button" class="button danger" @click="$store.agentEditor.applyPendingMutation()"><x-icon name="delete"></x-icon>Apply removal plan</button><button type="button" class="text-button" @click="$store.agentEditor.pendingMutation = null; $store.agentEditor.previewPlan()">Cancel removal</button></div>
- <div class="profile-maintenance" x-show="!$store.agentEditor.draft.creating && $store.agentEditor.state.profile.scope_has_overrides && !$store.agentEditor.state.profile.deletable">
+ <div class="profile-maintenance" x-show="!$store.agentEditor.pendingMutation && !$store.agentEditor.draft.creating && $store.agentEditor.state.profile.scope_has_overrides && !$store.agentEditor.state.profile.deletable">
<h4>Customized by you</h4><p x-text="`Remove only the customizations shown in this editor from ${$store.agentEditor.scopeLabel}. Other files stay in place.`"></p><button type="button" class="button danger" @click="$store.agentEditor.planRemoval(false)"><x-icon name="delete_sweep"></x-icon>Remove my changes</button>
<details><summary x-text="`Delete all customizations in ${$store.agentEditor.scopeLabel}`"></summary><p>This removes every customization saved in this scope after showing each affected file. Inherited files remain untouched.</p><button type="button" class="button danger" @click="$store.agentEditor.planRemoval(true)"><x-icon name="delete_forever"></x-icon>Review files to delete</button></details>
</div>
- <div class="profile-maintenance" x-show="!$store.agentEditor.draft.creating && $store.agentEditor.state.profile.deletable"><h4>Delete custom agent</h4><p>Projects and open chats that use this agent are shown before confirmation, together with its files and settings.</p><button type="button" class="button danger" @click="$store.agentEditor.deleteProfile($store.agentEditor.draft.profileId)">Delete agent</button></div>
+ <div class="profile-maintenance" x-show="!$store.agentEditor.pendingMutation && !$store.agentEditor.draft.creating && $store.agentEditor.state.profile.deletable"><h4>Delete custom agent</h4><p>Projects and open chats that use this agent are shown before confirmation, together with its files and settings.</p><button type="button" class="button danger" @click="$store.agentEditor.deleteProfile($store.agentEditor.draft.profileId)">Delete agent</button></div>
</section>
</div>
</div>
@@ -326,7 +326,7 @@
</div>
</template>
- <div class="modal-footer agent-editor-footer" data-modal-footer x-show="!$store.agentEditor.loading">
+ <div class="modal-footer agent-editor-footer" data-modal-footer x-show="!$store.agentEditor.loading && !($store.agentEditor.view === 'editor' && $store.agentEditor.pendingMutation)">
<div class="footer-left">
<button type="button" class="btn btn-cancel" x-show="$store.agentEditor.view === 'manage'" @click="window.closeModal?.()">Close</button>
<button type="button" class="btn btn-cancel" x-show="$store.agentEditor.view === 'editor'" @click="window.closeModal?.()">Cancel</button>
@@ -352,7 +352,7 @@
}
.agent-editor h2,.agent-editor h3,.agent-editor h4,.agent-editor p { margin: 0; }
.agent-editor button,.agent-editor input,.agent-editor textarea,.agent-editor select { font: inherit; }
- .agent-editor input[type="search"],.agent-editor select { min-width:0; min-height:2.25rem; box-sizing:border-box; padding:.5rem .6rem; border:1px solid var(--color-border); border-radius:7px; background:var(--color-input); color:var(--color-text); color-scheme:dark; }
+ .agent-editor input[type="search"],.agent-editor select { min-width:0; min-height:2.25rem; box-sizing:border-box; padding:.5rem .6rem; border:1px solid var(--color-border); border-radius:7px; background:var(--color-input); color:var(--color-text); }
.agent-editor input[type="checkbox"],.agent-editor input[type="radio"] { appearance:none; flex:0 0 auto; width:1.5rem; height:1.5rem; margin:.05rem 0; border:1px solid var(--color-border); background:var(--color-input); }
.agent-editor input[type="checkbox"] { display:grid; place-content:center; border-radius:4px; }
.agent-editor input[type="checkbox"]::before { content:""; width:.55rem; height:.3rem; border:solid white; border-width:0 0 2px 2px; opacity:0; transform:translateY(-1px) rotate(-45deg); }
@@ -390,6 +390,7 @@
.agent-field-label { font-weight:650; font-size:.92rem; }
.agent-field input,.agent-field textarea,.agent-easy textarea,.prompt-find input,.policy-filters input,.policy-filters select,.compact-search input { width:100%; box-sizing:border-box; }
.agent-field small,.agent-field-heading p,.field-status { color:var(--color-text-secondary); font-size:.79rem; }
+ .field-count { color:var(--color-text-secondary); font-size:.79rem; font-weight:400; }
.field-status { display:block; margin-top:.15rem; }
.field-error { display:block; color:var(--color-text); font-size:.79rem; font-weight:600; line-height:1.35; }
.agent-id-feedback { display:flex; flex-wrap:wrap; align-items:center; gap:.35rem .65rem; }
@@ -399,7 +400,7 @@
.agent-editor .text-button:hover { text-decoration:underline; }
.agent-easy textarea { min-height:11rem; resize:vertical; }
.restore-action { display:inline-flex; align-items:center; gap:.25rem; margin-top:.4rem; }
- .easy-tool-list { display:flex; flex-direction:column; max-height:18rem; overflow-y:auto; padding:.2rem .35rem .2rem 0; }
+ .easy-tool-list { display:flex; flex-direction:column; padding:.2rem .35rem .2rem 0; }
.easy-tool-list .policy-item { cursor:pointer; }
.easy-skills-hint { margin:.55rem 0 0; color:var(--color-text-secondary); font-size:.79rem; }
.agent-advanced { display:grid; grid-template-columns:14rem minmax(0,1fr); gap:1rem; min-height:0; }
@@ -503,7 +504,7 @@
.footer-actions { display:flex; gap:.5rem; margin-left:auto; }
.agent-editor-footer .btn-cancel,.agent-editor-secondary-action { border:1px solid var(--color-border); background:transparent; color:var(--color-text); }
.agent-editor-footer .btn-cancel:hover,.agent-editor-secondary-action:hover { border-color:color-mix(in srgb,var(--agent-editor-action) 50%,var(--color-border)); background:color-mix(in srgb,var(--agent-editor-action) 10%,transparent); color:var(--color-text); }
- .agent-editor-secondary-action { display:inline-flex; align-items:center; color:color-mix(in srgb,#fff 82%,var(--agent-editor-action)); }
+ .agent-editor-secondary-action { display:inline-flex; align-items:center; }
.agent-editor .button.danger { display:inline-flex; align-items:center; gap:.35rem; border-color:color-mix(in srgb,var(--agent-editor-danger) 60%,var(--color-border)); color:var(--agent-editor-danger); background:color-mix(in srgb,var(--agent-editor-danger) 7%,var(--color-panel)); }
.agent-editor .button.danger:hover { background:color-mix(in srgb,var(--agent-editor-danger) 15%,var(--color-panel)); }
.agent-manager { display:flex; flex-direction:column; gap:1rem; }
@@ -526,6 +527,7 @@
.agent-manager-avatar img { width:100%; height:100%; object-fit:cover; }
.agent-manager-copy { min-width:0; }
.agent-manager-name { display:flex; flex-wrap:wrap; align-items:center; gap:.4rem; }
+ .agent-manager-name strong,.agent-manager-copy p { overflow-wrap:anywhere; }
.agent-customized-indicator { display:inline-grid; place-items:center; color:var(--color-text-secondary); }
.agent-customized-indicator x-icon { font-size:1rem; }
.agent-editor .agent-manager-inline-action { gap:.25rem; margin-top:.15rem; color:var(--color-message-text); opacity:.7; }
diff --git a/plugins/_model_config/AGENTS.md b/plugins/_model_config/AGENTS.md
index e68e7ed34..6c2abc172 100644
--- a/plugins/_model_config/AGENTS.md
+++ b/plugins/_model_config/AGENTS.md
@@ -31,6 +31,8 @@
- The adjacent agent-profile selector reads the always-enabled Agent Editor list endpoint directly so the active profile shows its effective title and avatar, and omits profiles disabled in the chat's current scope.
- Reload the agent-profile selector catalog when a chat changes project or
active profile so project-only profiles never linger in the visible choices.
+- When forced agent-profile catalog loads overlap, only the newest request may
+ replace selector state or finish its loading lifecycle.
- Preset editor reset actions must remove the user override through the preset API and refresh the open draft from bundled defaults.
- Preset rename, delete, and reset actions must repair scoped config and durable/live chat references; removed definitions fall back to `Default`.
- Migration must preserve existing definitions and distinct scoped model choices, back up replaced user files once, strip inline secrets, and remain idempotent.
diff --git a/plugins/_model_config/extensions/webui/chat-input-progress-start/model-switcher.html b/plugins/_model_config/extensions/webui/chat-input-progress-start/model-switcher.html
index 07a4c6f22..48f67cf0e 100644
--- a/plugins/_model_config/extensions/webui/chat-input-progress-start/model-switcher.html
+++ b/plugins/_model_config/extensions/webui/chat-input-progress-start/model-switcher.html
@@ -134,6 +134,7 @@
<template x-for="profile in $store.modelConfig.getAgentProfileList($store.chats.selectedContext.agent_profile, $store.chats.selectedContext.agent_profile_label)" :key="profile.key">
<div class="agent-profile-row"
+ x-show="!$store.modelConfig.agentProfilesLoading"
:class="{ 'active': profile.key === $store.chats.selectedContext.agent_profile }">
<button type="button" class="model-switcher-item agent-profile-item"
:disabled="$store.chats.selectedContext.running || $store.modelConfig.agentProfileSaving"
diff --git a/plugins/_model_config/webui/switcher-mixin.js b/plugins/_model_config/webui/switcher-mixin.js
index 1977a324c..d4df9fa42 100644
--- a/plugins/_model_config/webui/switcher-mixin.js
+++ b/plugins/_model_config/webui/switcher-mixin.js
@@ -34,12 +34,14 @@ export const switcherState = {
agentProfiles: [],
agentProfilesLoading: true,
agentProfilesLoaded: false,
+ agentProfilesLoadSeq: 0,
agentProfileSaving: false,
};
export const switcherMethods = {
async loadAgentProfiles(force = false) {
if (!force && this.agentProfilesLoaded) return this.agentProfiles;
+ const requestSeq = ++this.agentProfilesLoadSeq;
this.agentProfilesLoading = true;
try {
const contextId = window.Alpine?.store("chats")?.selected || "";
@@ -47,6 +49,7 @@ export const switcherMethods = {
action: "list",
context_id: contextId,
});
+ if (requestSeq !== this.agentProfilesLoadSeq) return this.agentProfiles;
this.agentProfiles = (data.profiles || [])
.filter(profile => profile.id && profile.id !== "_example" && profile.enabled !== false)
.map(profile => ({
@@ -57,11 +60,14 @@ export const switcherMethods = {
}));
this.agentProfilesLoaded = true;
} catch (e) {
+ if (requestSeq !== this.agentProfilesLoadSeq) return this.agentProfiles;
console.error("Agent profile list load failed:", e);
this.agentProfiles = [];
this.agentProfilesLoaded = false;
} finally {
- this.agentProfilesLoading = false;
+ if (requestSeq === this.agentProfilesLoadSeq) {
+ this.agentProfilesLoading = false;
+ }
}
return this.agentProfiles;
},
diff --git a/tests/test_agent_editor_webui.py b/tests/test_agent_editor_webui.py
index da8548355..72098e1ed 100644
--- a/tests/test_agent_editor_webui.py
+++ b/tests/test_agent_editor_webui.py
@@ -76,6 +76,9 @@ def test_agent_editor_surface_has_normative_entry_points_and_accessible_controls
assert "model-preset-row" not in modal
assert 'class="easy-tool-details"' not in modal
assert 'x-for="tool in $store.agentEditor.toolCatalog"' in easy_surface
+ assert 'class="field-count"' in easy_surface
+ assert "toolCatalog.length === 1 ? 'tool' : 'tools'" in modal
+ assert "skillCatalog.length === 1 ? 'skill' : 'skills'" in modal
assert ':checked="$store.agentEditor.isToolAllowed(tool)"' in easy_surface
assert "$store.agentEditor.setEasyToolAllowed(tool.id, $event.target.checked)" in easy_surface
assert "Choose tools in Advanced" not in modal
@@ -155,11 +158,16 @@ def test_agent_editor_surface_has_normative_entry_points_and_accessible_controls
assert modal.count('role="alert"') >= 4
assert "Fix ${$store.agentEditor.validationIssues().length}" in modal
assert modal.count("$store.agentEditor.validationIssues().length > 0") == 2
+ assert "!($store.agentEditor.view === 'editor' && $store.agentEditor.pendingMutation)" in modal
+ assert 'x-show="$store.agentEditor.view === \'editor\' && !$store.agentEditor.draft?.creating"' in modal
+ assert 'class="btn btn-ok" x-show="$store.agentEditor.view === \'editor\'"' in modal
assert "Delete all customizations in" in modal
assert 'input[type="checkbox"]' in modal and "appearance:none" in modal
assert 'promptDisplayState(prompt)' in modal
assert 'promptSourceChain($store.agentEditor.selectedPromptDraft)' in modal
assert "Will reset to inherited on save." in modal
+ for key in ("title", "description", "context"):
+ assert f'x-show="$store.agentEditor.metadataProvenance(\'{key}\')"' in modal
assert ':title="prompt.filename"' not in modal
assert "promptEditPending($store.agentEditor.selectedPromptDraft)" in modal
assert 'aria-label="Discard current edit"' in modal
@@ -178,6 +186,11 @@ def test_agent_editor_surface_has_normative_entry_points_and_accessible_controls
assert "customized: !!profile.has_user_overrides" not in switcher_mixin
assert 'name="palette"' in modal and 'name="add_photo_alternate"' in modal
assert ".easy-tool-summary" not in modal
+ easy_tool_list_style = re.search(
+ r"\.easy-tool-list\s*\{([^}]*)\}", modal
+ ).group(1)
+ assert "max-height" not in easy_tool_list_style
+ assert "overflow-y" not in easy_tool_list_style
assert "grid-template-columns:minmax(0,1fr) 2.5rem minmax(0,1fr)" in modal
assert ".policy-lists .policy-transfer-actions { flex-direction:row; }" in modal
assert "easyToolsOpen" not in store_source
@@ -186,10 +199,14 @@ def test_agent_editor_surface_has_normative_entry_points_and_accessible_controls
assert "get easyTools" not in store_source
assert "firstSentence" not in store_source
assert '.agent-editor [aria-invalid="true"]' not in modal
+ assert "color-scheme:dark" not in modal
+ assert "#fff 82%" not in modal
+ assert ".agent-manager-name strong,.agent-manager-copy p { overflow-wrap:anywhere; }" in modal
assert ".field-error { display:block; color:var(--color-text)" in modal
assert ".prompt-pane { min-width:0; min-height:0;" in modal
assert 'callJsonApi("/plugins/_agent_editor/agent_editor"' in switcher_mixin
assert "profile.enabled !== false" in switcher_mixin
+ assert 'x-show="!$store.modelConfig.agentProfilesLoading"' in switcher
assert "@keydown.ctrl.s.prevent" in modal
assert "@media (max-width: 760px)" in modal
assert modal.count("data-modal-footer") == 1
@@ -218,12 +235,23 @@ def test_local_slugging_and_fresh_chat_profile_selection_are_deterministic() ->
const calls = [];
const confirmations = [];
let setEnabledHandler = null;
+let loadHandler = null;
+let confirmResult = false;
const createStore = (_name, value) => value;
const callJsonApi = async (endpoint, payload) => {
calls.push({ endpoint, payload });
+ if (payload?.action === "load" && loadHandler) return loadHandler(payload);
if (payload?.action === "set_enabled") return setEnabledHandler
? setEnabledHandler(payload)
: { ok: true, active_profile: "default", active_profile_label: "Default" };
+ if (payload?.action === "plan") return {
+ ok: true,
+ written: [payload.project_name
+ ? `usr/projects/${payload.project_name}/.a0proj/agents/${payload.patch.profile_id}/agent.yaml`
+ : `usr/agents/${payload.patch.profile_id}/agent.yaml`],
+ deleted: [],
+ warnings: [],
+ };
if (payload?.action === "duplicate") return {
ok: true,
profile_id: "researcher-1",
@@ -235,7 +263,7 @@ const callJsonApi = async (endpoint, payload) => {
const fetchApi = async () => ({ ok: true, json: async () => ({}) });
const closeModal = async () => {};
const openModal = async () => {};
-const showConfirmDialog = async options => { confirmations.push(options); return false; };
+const showConfirmDialog = async options => { confirmations.push(options); return confirmResult; };
const chatsStore = {
selected: "old-chat",
selectedContext: { project: { name: "demo" }, agent_profile: "researcher" },
@@ -260,6 +288,7 @@ globalThis.CustomEvent = class { constructor(type) { this.type = type; } };
globalThis.sessionStorage = { setItem: () => {}, getItem: () => "", removeItem: () => {} };
globalThis.localStorage = { setItem: () => {}, getItem: () => "" };
globalThis.requestAnimationFrame = callback => callback();
+globalThis.confirm = () => true;
"""
checks = r"""
if (slugifyProfileName(" Crème Brûlée__Lab ") !== "creme-brulee-lab") throw new Error("slug mismatch");
@@ -295,12 +324,15 @@ if (store.error) throw new Error("validation leaked into dismissible error banne
store.state.profile.id = "new-agent";
store.state.profile.origin = "Built-in";
store.state.profile.metadata.title = { inherited_source: "agents/new-agent/agent.yaml" };
+if (store.metadataProvenance("title") !== "") throw new Error("new profile showed misleading provenance");
+store.draft.creating = false;
if (store.metadataProvenance("title") !== "Using the default") throw new Error("default provenance mismatch");
store.profiles = [{ id: "researcher", title: "Researcher" }];
store.state.profile.metadata.title = { inherited_source: "agents/researcher/agent.yaml" };
if (store.metadataProvenance("title") !== "Inherited from Researcher") throw new Error("inherited provenance mismatch");
store.state.profile.metadata.title.has_override = true;
if (store.metadataProvenance("title") !== "Customized by you") throw new Error("custom provenance mismatch");
+store.draft.creating = true;
store.state.tools.catalog = [
{ id: "local:shell", name: "shell", label: "Shell", origin: "Agent Zero", available: true },
{ id: "local:gone", name: "gone", label: "Gone", origin: "Unavailable", available: false },
@@ -391,18 +423,103 @@ if (store.draft.skillPolicy.mode !== "custom" || store.draft.skillPolicy.default
store.draft.title = "Preserved Agent";
store.onNameInput();
store.instructions.value = "Preserved instructions";
+store.draft.description = "Created description";
+store.draft.context = "Delegate created work";
+const createdMetadata = store.buildPatch().metadata.set;
+if (createdMetadata.description !== "Created description" || createdMetadata.context !== "Delegate created work") throw new Error("Advanced create metadata was omitted");
+store.mode = "advanced";
+store.instructions.value = "";
+const callsBeforeInvalidAdvancedCreate = calls.length;
+if (!store.fieldIssue("instructions")) throw new Error("Advanced create accepted empty instructions");
+await store.save();
+if (calls.length !== callsBeforeInvalidAdvancedCreate) throw new Error("Advanced create submitted empty instructions");
+store.instructions.value = "Preserved instructions";
store.draft.creating = false;
+store.mode = "easy";
+store.instructions.initialValue = "Preserved instructions";
+store.instructions.value = "";
+if (!store.fieldIssue("instructions")) throw new Error("existing empty Easy instructions were accepted");
+store.instructions.value = "Preserved instructions";
+if (store.fieldIssue("instructions")) throw new Error("corrected Easy instructions kept a validation error");
+store.mode = "advanced";
store.instructions.value = "";
-if (store.fieldIssue("instructions")) throw new Error("existing empty instructions were rejected");
+if (store.fieldIssue("instructions")) throw new Error("Advanced empty instructions were rejected");
store.instructions.value = "Preserved instructions";
store.markPromptSet("agent.system.main.specifics.md");
if (store.instructions.reset || store.promptEditPending(store.instructions)) throw new Error("Easy instructions did not update its edit checkpoint");
store.restoreInstructions();
if (!store.instructions.reset || store.instructions.value !== "" || store.promptEditPending(store.instructions)) throw new Error("default instructions were not restored");
-store.draft.creating = true;
-store.instructions.value = "Preserved instructions";
-store.instructions.reset = false;
+store.state = {
+ profile: { id: "new-agent", avatar_url: "", metadata: { title: {}, description: {}, context: {}, avatar: { effective: { kind: "color", value: "#111111" } } } },
+ prompts: [
+ { filename: "agent.system.main.specifics.md", group: "2.1", group_label: "Agent instructions", effective: "", inherited: "Old instructions", source: "old-source", source_chain: ["Old"] },
+ { filename: "agent.system.main.communication.md", group: "2.4", group_label: "Communication", effective: "Old comm", inherited: "Old comm", source: "old-source", source_chain: ["Old"], state: "Inherited", has_override: false },
+ ],
+ model_preset: { has_override: false, effective: "Default" },
+ model_presets: [],
+ tools: { policy: { mode: "inherit" }, effective_policy: { mode: "inherit", default: "allow", allowed: [], blocked: [] }, has_override: false, catalog: [
+ { id: "local:shell", name: "shell", label: "Shell", origin: "Agent Zero", available: true },
+ { id: "local:old", name: "old", label: "Old", origin: "Old scope", available: true },
+ ] },
+ skills: { policy: { mode: "inherit" }, effective_policy: { mode: "inherit", default: "allow", allowed: [], blocked: [] }, has_override: false, catalog: [
+ { name: "Research", path: "skills/research/SKILL.md", origin: "Agent Zero", description: "Research", available: true, tags: [], allowed_tools: [] },
+ { name: "Old skill", path: "skills/old/SKILL.md", origin: "Old scope", description: "Old", available: true, tags: [], allowed_tools: [] },
+ ] },
+};
+store.view = "editor";
+store.intent = { ...store.intent, view: "create", projectName: "" };
+store.makeDraft(true);
+store.draft.title = "Scoped Agent";
+store.onNameInput();
+store.draft.description = "Scoped description";
+store.draft.context = "Use for scoped work";
+store.instructions.value = "Authored instructions";
+store.markPromptSet("agent.system.main.specifics.md");
+store.draft.prompts["agent.system.main.communication.md"].value = "Authored communication";
+store.acceptPromptEdit("agent.system.main.communication.md");
+store.chooseAvatarColor("#ABCDEF");
+store.setEasyToolAllowed("local:shell", false);
+store.setPolicyDefault("tool", "block");
+store.chooseSkills();
+store.moveSkills(["Research"], false);
+const projectState = {
+ profile: { id: "new-agent", avatar_url: "", metadata: { title: {}, description: {}, context: {}, avatar: { effective: { kind: "color", value: "#222222" } } } },
+ prompts: [
+ { filename: "agent.system.main.specifics.md", group: "2.1", group_label: "Agent instructions", effective: "", inherited: "Project instructions", source: "project-source", source_chain: ["Project"] },
+ { filename: "agent.system.main.communication.md", group: "2.4", group_label: "Communication", effective: "Inherited comm", inherited: "Inherited comm", source: "project-source", source_chain: ["Project"], state: "Inherited", has_override: false },
+ ],
+ model_preset: { has_override: false, effective: "Default" },
+ model_presets: [],
+ tools: { policy: { mode: "inherit" }, effective_policy: { mode: "inherit", default: "allow", allowed: [], blocked: [] }, has_override: false, catalog: [
+ { id: "local:shell", name: "shell", label: "Shell", origin: "Agent Zero", available: true },
+ { id: "local:new", name: "new", label: "New", origin: "Project", available: true },
+ ] },
+ skills: { policy: { mode: "inherit" }, effective_policy: { mode: "inherit", default: "allow", allowed: [], blocked: [] }, has_override: false, catalog: [
+ { name: "Research", path: "skills/research/SKILL.md", origin: "Agent Zero", description: "Research", available: true, tags: [], allowed_tools: [] },
+ { name: "New skill", path: "skills/new/SKILL.md", origin: "Project", description: "New", available: true, tags: [], allowed_tools: [] },
+ ] },
+};
+loadHandler = () => ({ ok: true, state: projectState });
+store.mode = "advanced";
+store.section = "5";
+store.projectName = "demo";
+store.intent = { ...store.intent, projectName: "" };
+calls.length = 0;
+await store.onScopeChanged();
+if (store.state !== projectState || store.draft.title !== "Scoped Agent" || store.draft.profileId !== "scoped-agent") throw new Error("create scope rebase lost identity");
+if (store.draft.description !== "Scoped description" || store.draft.context !== "Use for scoped work") throw new Error("create scope rebase lost authored metadata");
+if (store.instructions.value !== "Authored instructions" || store.instructions.source !== "project-source") throw new Error("create scope rebase kept stale prompt provenance");
+if (store.draft.avatar?.value !== "#ABCDEF" || store.isToolAllowed(projectState.tools.catalog[0]) || !store.isToolAllowed(projectState.tools.catalog[1]) || store.draft.toolPolicy.default !== "block") throw new Error("create scope rebase lost avatar or explicit tool decision");
+if (store.isSkillAllowed(projectState.skills.catalog[0]) || !store.isSkillAllowed(projectState.skills.catalog[1])) throw new Error("create scope rebase lost explicit skill decision");
+if (store.draft.prompts["agent.system.main.communication.md"].value !== "Authored communication" || store.draft.prompts["agent.system.main.communication.md"].source !== "project-source" || store.promptEditPending(store.draft.prompts["agent.system.main.communication.md"])) throw new Error("create scope rebase lost an accepted prompt edit or kept stale provenance");
+if (calls.at(-1)?.payload?.action !== "plan" || calls.at(-1)?.payload?.project_name !== "demo" || store.planStatus !== "ready" || !store.plan.written[0].startsWith("usr/projects/demo/.a0proj/agents/scoped-agent/")) throw new Error("Review plan was not recomputed after scope change");
+loadHandler = null;
+store.projectName = "";
+store.intent = { ...store.intent, projectName: "" };
const communication = store.draft.prompts["agent.system.main.communication.md"];
+communication.value = communication.initialValue;
+communication.reset = false;
+store.acceptPromptEdit(communication.filename);
if (store.filteredPromptFiles("2.4")[0] !== communication) throw new Error("grouped prompt filter mismatch");
if (store.promptEditPending(communication) || store.promptDisplayState(communication) !== "Default") throw new Error("default prompt checkpoint mismatch");
communication.value += "\nNew rule";
@@ -442,15 +559,33 @@ calls.length = 0;
store.projectName = "demo";
await store.openFreshChat("researcher", false);
if (calls[1].endpoint !== "/projects" || calls[1].payload.action !== "activate" || calls[1].payload.name !== "demo") throw new Error("project test chat did not activate selected scope");
+store.draft.title = `${store.draft.title} dirty`;
+calls.length = 0;
+if (await store.planRemoval(true)) throw new Error("removal plan accepted unsaved edits");
+if (calls.length || !store.error.includes("Save or discard")) throw new Error("dirty removal plan was not blocked locally");
+store.initialDraft = clone(store.draft);
+store.error = "";
await store.planRemoval(true);
if (!store.pendingMutation?.destructive || store.section !== "5" || store.planStatus !== "ready") throw new Error("removal plan was replaced");
if (calls.at(-1).payload.action !== "plan_remove_changes") throw new Error("removal plan request missing");
if (calls.at(-1).payload.project_name !== "demo") throw new Error("removal request lost selected scope");
+const callsBeforePendingSave = calls.length;
+if (await store.save() || calls.length !== callsBeforePendingSave) throw new Error("ordinary save ran over a pending removal plan");
+store.draft.title += " changed after planning";
+if (await store.applyPendingMutation() !== false || confirmations.length || calls.length !== callsBeforePendingSave || !store.error.includes("before applying")) throw new Error("removal plan discarded edits made after planning");
+store.draft.title = store.initialDraft.title;
+store.error = "";
store.plan = { written: ["usr/agents/researcher/agent.yaml"], deleted: ["usr/agents/researcher/prompts/old.md"], warnings: [] };
+confirmResult = true;
+loadHandler = () => ({ ok: true, state: store.state });
await store.applyPendingMutation();
if (confirmations.length !== 1 || confirmations[0].type !== "danger") throw new Error("danger confirmation missing");
if (!confirmations[0].message.includes("agent.yaml") || !confirmations[0].message.includes("old.md")) throw new Error("planned paths missing from confirmation");
if (confirmations[0].title !== "Delete all customizations for this profile?") throw new Error("cleanup confirmation title mismatch");
+const removalCall = calls.find(item => item.payload?.action === "remove_changes");
+if (!removalCall || removalCall.payload.confirm !== true || removalCall.payload.destructive !== true) throw new Error("destructive removal omitted explicit confirmation");
+loadHandler = null;
+confirmResult = false;
confirmations.length = 0;
calls.length = 0;
store.projectName = "";
@@ -458,6 +593,58 @@ await store.deleteProfile("custom-agent");
if (calls.length) throw new Error("cancelled deletion made an API request");
if (confirmations.length !== 1 || confirmations[0].title !== "Delete custom-agent?") throw new Error("delete confirmation mismatch");
if (confirmations[0].message !== "<p>This agent profile will be permanently deleted from Global and cannot be recovered.</p>") throw new Error("delete confirmation is not concise");
+confirmResult = true;
+store.view = "editor";
+store.mode = "advanced";
+store.draft = { title: "dirty", avatar: null, avatarToken: "", metadataResets: [] };
+store.initialDraft = { title: "clean", avatar: null, avatarToken: "", metadataResets: [] };
+store.promptEditBaselines = { stale: { value: "stale", reset: false } };
+await store.deleteProfile("custom-agent");
+if (store.view !== "manage" || store.mode !== "easy" || store.draft !== null || store.initialDraft !== null || Object.keys(store.promptEditBaselines).length) throw new Error("delete did not enter a clean Manage state");
+store.view = "editor";
+store.mode = "advanced";
+store.draft = { title: "dirty" };
+store.initialDraft = { title: "clean" };
+store.promptEditBaselines = { stale: { value: "stale", reset: false } };
+store.error = "stale";
+store.showManager();
+if (store.view !== "manage" || store.mode !== "easy" || store.draft !== null || store.initialDraft !== null || store.error || Object.keys(store.promptEditBaselines).length) throw new Error("Back did not discard editor state before Manage");
+"""
+ module_source = harness + "\n" + source + "\n" + checks
+ module_url = "data:text/javascript;base64," + base64.b64encode(
+ module_source.encode("utf-8")
+ ).decode("ascii")
+ subprocess.run(
+ ["node", "--input-type=module", "-e", f"await import('{module_url}')"],
+ check=True,
+ text=True,
+ )
+
+
[email protected](not shutil.which("node"), reason="node is required")
+def test_latest_agent_profile_load_owns_switcher_state() -> None:
+ source = SWITCHER_MIXIN.read_text(encoding="utf-8")
+ source = re.sub(r"^import .*?;\n", "", source, flags=re.MULTILINE)
+ harness = r"""
+const pending = [];
+const callJsonApi = async () => await new Promise(resolve => pending.push(resolve));
+const fetchApi = async () => ({ ok: true, json: async () => ({}) });
+globalThis.window = { Alpine: { store: () => ({ selected: "ctx" }) } };
+"""
+ checks = r"""
+const store = { ...switcherState, ...switcherMethods };
+const older = store.loadAgentProfiles(true);
+const newer = store.loadAgentProfiles(true);
+if (pending.length !== 2 || !store.agentProfilesLoading) throw new Error("overlapping profile loads did not start");
+pending[1]({ profiles: [{ id: "new", title: "New", enabled: true }] });
+await newer;
+if (store.agentProfiles[0]?.key !== "new" || store.agentProfilesLoading || !store.agentProfilesLoaded) throw new Error("newest profile load did not settle");
+pending[0]({ profiles: [{ id: "old", title: "Old", enabled: true }] });
+await older;
+if (store.agentProfiles[0]?.key !== "new" || store.agentProfilesLoading || !store.agentProfilesLoaded) throw new Error("stale profile load replaced newer state");
+const requestCount = pending.length;
+await store.loadAgentProfiles();
+if (pending.length !== requestCount) throw new Error("cached profile catalog unexpectedly reloaded");
"""
module_source = harness + "\n" + source + "\n" + checks
module_url = "data:text/javascript;base64," + base64.b64encode(