Compare commits

...
Author SHA1 Message Date
netcatty-bot d15d43e7b2 fix(#3546): automated AI fix 2026-09-28 17:32:10 +00:00
2 changed files with 77 additions and 15 deletions

No files matched your search

@@ -40,3 +40,53 @@ test('system prompt does not tell Catty to call host_open', () => {
assert.match(prompt, /cannot open new terminal sessions yourself/i);
assert.match(prompt, /ask them to open/i);
});
test('system prompt keeps static content before dynamic sections for prompt caching', () => {
const turnA = buildSystemPrompt({
scopeType: 'workspace',
hosts: [{ sessionId: 's1', hostname: 'a.example', label: 'A', connected: true }],
permissionMode: 'confirm',
});
const turnB = buildSystemPrompt({
scopeType: 'workspace',
hosts: [
{ sessionId: 's1', hostname: 'a.example', label: 'A', connected: false },
{ sessionId: 's2', hostname: 'b.example', label: 'B', connected: true },
],
permissionMode: 'auto',
webSearchEnabled: true,
});
const guidelines = turnA.indexOf('## Guidelines');
const currentScope = turnA.indexOf('## Current Scope');
assert.ok(guidelines > -1 && currentScope > -1);
assert.ok(guidelines < currentScope, 'static Guidelines must precede dynamic Current Scope');
// Static prefix (intro + Guidelines) is identical across turns even when
// dynamic context changes.
assert.ok(turnA.startsWith('You are **Catty Agent**'));
const staticEndA = turnA.indexOf('---');
assert.ok(staticEndA > guidelines);
assert.strictEqual(turnA.slice(0, staticEndA), turnB.slice(0, staticEndA));
});
test('system prompt renders web search guidance without breaking guideline numbering', () => {
const withSearch = buildSystemPrompt({
scopeType: 'global',
hosts: [],
permissionMode: 'auto',
webSearchEnabled: true,
});
const withoutSearch = buildSystemPrompt({
scopeType: 'global',
hosts: [],
permissionMode: 'auto',
});
assert.match(withSearch, /## Web Search/);
assert.match(withSearch, /web_search/);
assert.doesNotMatch(withoutSearch, /## Web Search/);
// Guideline 10 is the last numbered guideline; web search moved to a
// dedicated dynamic section after the dynamic context blocks.
assert.ok(withSearch.indexOf('10. **Network device sessions.**') < withSearch.indexOf('## Web Search'));
});
+27 -15
View File
@@ -33,20 +33,13 @@ export function buildSystemPrompt(context: SystemPromptContext): string {
const hostList = buildHostList(hosts);
const permissionRules = buildPermissionRules(permissionMode);
// Static content must come first so provider prompt caches (which only match
// exact token prefixes) can be reused across turns. Dynamic segments
// (scope, sessions, permission mode, user skills) are appended at the end so
// any per-turn change invalidates only the suffix, not the long Guidelines
// block.
return `You are **Catty Agent**, a terminal automation assistant built into netcatty. You help users operate terminal sessions managed by Netcatty, including remote hosts and the user's local terminal.
## Current Scope
${scopeDescription}
## Available Sessions
${hostList}
## Permission Mode: ${permissionMode}
${permissionRules}
## Guidelines
1. **Plan before acting.** When a task involves multiple steps, present a brief numbered plan to the user before executing.
@@ -83,10 +76,29 @@ ${permissionRules}
9. **Fetch URLs when provided.** When the user shares a URL or asks you to read a webpage, use \`url_fetch\` to retrieve its content.
10. **Network device sessions.** Sessions with \`protocol: serial\` (shell: raw) or \`deviceType: network\` (SSH-connected network equipment) are connected to network devices or embedded systems. They do NOT run a standard shell (bash/zsh/etc). Commands are sent as-is without shell wrapping. Do not use shell syntax (pipes, redirects, environment variables, subshells). Use the device's native CLI commands (e.g. Cisco IOS, Huawei VRP, Juniper JunOS). Exit codes are unavailable. Consider disabling pagination first (\`screen-length 0 temporary\` for Huawei, \`terminal length 0\` for Cisco). SFTP is not available for serial sessions.${webSearchEnabled ? `
10. **Network device sessions.** Sessions with \`protocol: serial\` (shell: raw) or \`deviceType: network\` (SSH-connected network equipment) are connected to network devices or embedded systems. They do NOT run a standard shell (bash/zsh/etc). Commands are sent as-is without shell wrapping. Do not use shell syntax (pipes, redirects, environment variables, subshells). Use the device's native CLI commands (e.g. Cisco IOS, Huawei VRP, Juniper JunOS). Exit codes are unavailable. Consider disabling pagination first (\`screen-length 0 temporary\` for Huawei, \`terminal length 0\` for Cisco). SFTP is not available for serial sessions.
11. **Search proactively.** You have access to \`web_search\`. Use it whenever you encounter something you are unsure about, don't fully understand, or need to verify — including unfamiliar commands, tools, error messages, configuration syntax, or any factual claims. Don't guess; search first. Also use it when the user asks about current events or recent information. Cite sources when presenting search results.` : ''}
${userSkillsContext ? `\n\n## User Skills\n\n${userSkillsContext}` : ''}`;
---
## Current Scope
${scopeDescription}
## Available Sessions
${hostList}
## Permission Mode: ${permissionMode}
${permissionRules}${webSearchEnabled ? `
## Web Search
You have access to \`web_search\`. Use it whenever you encounter something you are unsure about, don't fully understand, or need to verify — including unfamiliar commands, tools, error messages, configuration syntax, or any factual claims. Don't guess; search first. Also use it when the user asks about current events or recent information. Cite sources when presenting search results.` : ''}${userSkillsContext ? `
## User Skills
${userSkillsContext}` : ''}`;
}
function buildScopeDescription(