feat: add agent prompt editing and update functionality

This commit is contained in:
2026-04-29 10:35:47 +09:00
parent e6d34a5cb6
commit 64cf6d364f
+50 -3
View File
@@ -130,6 +130,12 @@ export class SidebarChatProvider implements vscode.WebviewViewProvider, BridgeIn
case 'setBrainProfile':
await this._setActiveBrainProfile(data.id);
break;
case 'getAgentContent':
await this._sendAgentContent(data.path);
break;
case 'updateAgent':
await this._updateAgent(data.path, data.content);
break;
case 'refreshModels':
await this._sendModels();
break;
@@ -622,6 +628,24 @@ export class SidebarChatProvider implements vscode.WebviewViewProvider, BridgeIn
await this._sendAgentsList();
}
private async _sendAgentContent(agentPath: string) {
if (!this._view || !agentPath || agentPath === 'none') return;
if (fs.existsSync(agentPath)) {
const content = fs.readFileSync(agentPath, 'utf8');
this._view.webview.postMessage({ type: 'agentContent', value: content });
}
}
private async _updateAgent(agentPath: string, content: string) {
if (!agentPath || agentPath === 'none') return;
try {
fs.writeFileSync(agentPath, content, 'utf8');
vscode.window.showInformationMessage('Agent skill updated successfully.');
} catch (err: any) {
vscode.window.showErrorMessage(`Failed to update agent: ${err.message}`);
}
}
private async _handlePrompt(data: any) {
if (!this._view) return;
@@ -1001,8 +1025,14 @@ export class SidebarChatProvider implements vscode.WebviewViewProvider, BridgeIn
</div>
<div class="input-wrap">
<div id="agentConfigPanel" style="display:none; padding-bottom:8px;">
<textarea id="negativePrompt" rows="2" placeholder="Negative Prompt (What NOT to do)..." style="font-size:11.5px; padding:8px; border-radius:8px; border:1px solid var(--border); background:var(--input-bg); color:var(--text-bright); width:100%; resize:vertical; font-family:inherit; outline:none;"></textarea>
<div id="agentConfigPanel" style="display:none; padding-bottom:8px; flex-direction: column; gap: 8px;">
<div style="font-size: 10px; color: var(--text-dim); margin-bottom: -4px;">Agent Persona/Instructions</div>
<textarea id="agentPrompt" rows="5" placeholder="Agent Persona & Instructions..." style="font-size:11.5px; padding:8px; border-radius:8px; border:1px solid var(--border); background:var(--input-bg); color:var(--text-bright); width:100%; resize:vertical; font-family:inherit; outline:none;"></textarea>
<div style="font-size: 10px; color: var(--text-dim); margin-bottom: -4px;">Negative Prompt (Strict Rules)</div>
<textarea id="negativePrompt" rows="2" placeholder="What NOT to do..." style="font-size:11.5px; padding:8px; border-radius:8px; border:1px solid var(--border); background:var(--input-bg); color:var(--text-bright); width:100%; resize:vertical; font-family:inherit; outline:none;"></textarea>
<button id="updateAgentBtn" style="background: var(--surface); border: 1px solid var(--border); color: var(--text-primary); padding: 6px; font-size: 10px; border-radius: 6px; cursor: pointer; transition: 0.2s;">Update Agent Skill</button>
</div>
<div class="input-box">
<div id="attachPreview" class="attachment-preview"></div>
@@ -1036,7 +1066,9 @@ export class SidebarChatProvider implements vscode.WebviewViewProvider, BridgeIn
const agentSel = document.getElementById('agentSel');
const addAgentBtn = document.getElementById('addAgentBtn');
const agentConfigPanel = document.getElementById('agentConfigPanel');
const agentPrompt = document.getElementById('agentPrompt');
const negativePrompt = document.getElementById('negativePrompt');
const updateAgentBtn = document.getElementById('updateAgentBtn');
let streamBody = null;
let internetEnabled = false;
@@ -1163,6 +1195,9 @@ export class SidebarChatProvider implements vscode.WebviewViewProvider, BridgeIn
agentSel.appendChild(o);
});
break;
case 'agentContent':
agentPrompt.value = msg.value;
break;
case 'error':
thinkingBar.classList.remove('active'); sendBtn.disabled = false;
addMsg(msg.value, 'error');
@@ -1242,13 +1277,25 @@ export class SidebarChatProvider implements vscode.WebviewViewProvider, BridgeIn
agentSel.onchange = () => {
if (agentSel.value !== 'none') {
agentConfigPanel.style.display = 'block';
agentConfigPanel.style.display = 'flex';
vscode.postMessage({ type: 'getAgentContent', path: agentSel.value });
} else {
agentConfigPanel.style.display = 'none';
agentPrompt.value = '';
negativePrompt.value = '';
}
};
updateAgentBtn.onclick = () => {
if (agentSel.value !== 'none') {
vscode.postMessage({
type: 'updateAgent',
path: agentSel.value,
content: agentPrompt.value
});
}
};
addAgentBtn.onclick = () => vscode.postMessage({ type: 'createAgent' });
vscode.postMessage({ type: 'getModels' });