dvalincode 0.12.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/README.md +122 -24
  2. package/README.zh-CN.md +52 -4
  3. package/dist/agent/compact.d.ts +4 -2
  4. package/dist/agent/compact.js +41 -7
  5. package/dist/agent/compact.js.map +1 -1
  6. package/dist/agent/loop.js +30 -31
  7. package/dist/agent/loop.js.map +1 -1
  8. package/dist/agent/modes.d.ts +2 -2
  9. package/dist/agent/modes.js +6 -3
  10. package/dist/agent/modes.js.map +1 -1
  11. package/dist/agent/runner.d.ts +14 -6
  12. package/dist/agent/runner.js +370 -75
  13. package/dist/agent/runner.js.map +1 -1
  14. package/dist/agent/session.d.ts +3 -1
  15. package/dist/agent/session.js +23 -2
  16. package/dist/agent/session.js.map +1 -1
  17. package/dist/agent/types.d.ts +10 -5
  18. package/dist/agent/types.js +12 -2
  19. package/dist/agent/types.js.map +1 -1
  20. package/dist/audit/log.d.ts +4 -1
  21. package/dist/audit/log.js.map +1 -1
  22. package/dist/audit/report.js +5 -0
  23. package/dist/audit/report.js.map +1 -1
  24. package/dist/cli.js +6 -1
  25. package/dist/cli.js.map +1 -1
  26. package/dist/commands/chat.js +1 -1
  27. package/dist/commands/chat.js.map +1 -1
  28. package/dist/commands/dvalin.d.ts +9 -0
  29. package/dist/commands/dvalin.js +222 -0
  30. package/dist/commands/dvalin.js.map +1 -0
  31. package/dist/commands/provider.js +3 -3
  32. package/dist/commands/provider.js.map +1 -1
  33. package/dist/commands/tui.js +2 -2
  34. package/dist/commands/tui.js.map +1 -1
  35. package/dist/commands/update.d.ts +2 -0
  36. package/dist/commands/update.js +238 -0
  37. package/dist/commands/update.js.map +1 -0
  38. package/dist/core/context.d.ts +4 -0
  39. package/dist/core/context.js +8 -1
  40. package/dist/core/context.js.map +1 -1
  41. package/dist/core/guiUpdate.d.ts +27 -0
  42. package/dist/core/guiUpdate.js +65 -0
  43. package/dist/core/guiUpdate.js.map +1 -0
  44. package/dist/core/policy.d.ts +6 -3
  45. package/dist/core/policy.js +8 -1
  46. package/dist/core/policy.js.map +1 -1
  47. package/dist/core/selfUpdate.d.ts +108 -0
  48. package/dist/core/selfUpdate.js +180 -0
  49. package/dist/core/selfUpdate.js.map +1 -0
  50. package/dist/core/subprocessSandbox.d.ts +16 -0
  51. package/dist/core/subprocessSandbox.js +168 -28
  52. package/dist/core/subprocessSandbox.js.map +1 -1
  53. package/dist/core/trust.d.ts +8 -0
  54. package/dist/core/trust.js +1 -10
  55. package/dist/core/trust.js.map +1 -1
  56. package/dist/core/workspace.js +2 -1
  57. package/dist/core/workspace.js.map +1 -1
  58. package/dist/providers/anthropic.d.ts +14 -0
  59. package/dist/providers/anthropic.js +244 -0
  60. package/dist/providers/anthropic.js.map +1 -0
  61. package/dist/providers/manager.d.ts +3 -0
  62. package/dist/providers/manager.js +13 -2
  63. package/dist/providers/manager.js.map +1 -1
  64. package/dist/providers/openaiCompatible.d.ts +12 -1
  65. package/dist/providers/openaiCompatible.js +21 -6
  66. package/dist/providers/openaiCompatible.js.map +1 -1
  67. package/dist/providers/pool.js +3 -4
  68. package/dist/providers/pool.js.map +1 -1
  69. package/dist/providers/trustedBaseUrls.js +1 -0
  70. package/dist/providers/trustedBaseUrls.js.map +1 -1
  71. package/dist/providers/types.d.ts +20 -4
  72. package/dist/remediation/automate.d.ts +18 -0
  73. package/dist/remediation/automate.js +78 -0
  74. package/dist/remediation/automate.js.map +1 -0
  75. package/dist/remediation/localScan.js +9 -1
  76. package/dist/remediation/localScan.js.map +1 -1
  77. package/dist/remediation/sarif.js +18 -4
  78. package/dist/remediation/sarif.js.map +1 -1
  79. package/dist/remediation/scannerSuite.d.ts +43 -0
  80. package/dist/remediation/scannerSuite.js +248 -0
  81. package/dist/remediation/scannerSuite.js.map +1 -0
  82. package/dist/server/routes/config.js +2 -3
  83. package/dist/server/routes/config.js.map +1 -1
  84. package/dist/server/routes/remediation.js +34 -0
  85. package/dist/server/routes/remediation.js.map +1 -1
  86. package/dist/server/scannerWorkspaceGrants.d.ts +7 -0
  87. package/dist/server/scannerWorkspaceGrants.js +48 -0
  88. package/dist/server/scannerWorkspaceGrants.js.map +1 -0
  89. package/dist/server/security.js +20 -6
  90. package/dist/server/security.js.map +1 -1
  91. package/dist/server/wsHandler.js.map +1 -1
  92. package/dist/skills/store.js +28 -0
  93. package/dist/skills/store.js.map +1 -1
  94. package/dist/tools/registry.d.ts +7 -0
  95. package/dist/tools/registry.js +30 -0
  96. package/dist/tools/registry.js.map +1 -1
  97. package/dist/tools/runCheck.js +1 -0
  98. package/dist/tools/runCheck.js.map +1 -1
  99. package/dist/tools/runSecuritySuite.d.ts +14 -0
  100. package/dist/tools/runSecuritySuite.js +35 -0
  101. package/dist/tools/runSecuritySuite.js.map +1 -0
  102. package/dist/tools/shell.d.ts +3 -1
  103. package/dist/tools/shell.js +16 -6
  104. package/dist/tools/shell.js.map +1 -1
  105. package/dist/tui/app.d.ts +1 -0
  106. package/dist/tui/app.js +110 -16
  107. package/dist/tui/app.js.map +1 -1
  108. package/dist/tui/presets.d.ts +2 -2
  109. package/dist/tui/presets.js +1 -0
  110. package/dist/tui/presets.js.map +1 -1
  111. package/dist/tui/render.js +2 -1
  112. package/dist/tui/render.js.map +1 -1
  113. package/dist/version.d.ts +8 -0
  114. package/dist/version.js +9 -0
  115. package/dist/version.js.map +1 -0
  116. package/package.json +4 -3
@@ -1 +1 @@
1
- {"version":3,"file":"loop.js","sourceRoot":"","sources":["../../src/agent/loop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA+E,mBAAmB,EAAkB,MAAM,YAAY,CAAC;AACzJ,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtE,OAAO,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,CAAC,CAAC,EAAE,CAAC,CAAC;YAC5E,MAAM,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC;YACzE,OAAO;gBACL,QAAQ,EAAE,IAAI;gBACd,MAAM,EAAE,sCAAsC,QAAQ,CAAC,MAAM,OAAO,IAAI,CAAC,MAAM,YAAY;aAC5F,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
@@ -1,6 +1,6 @@
1
1
  import type { ApprovalMode } from '../core/context.js';
2
- /** Top-level agent mode (mirrors the GUI's Chat / Cowork / Code switch). */
3
- export type AgentMode = 'chat' | 'cowork' | 'code';
2
+ /** Top-level agent mode. Home in the GUI maps to Chat or Cowork. */
3
+ export type AgentMode = 'chat' | 'cowork' | 'code' | 'dvalin';
4
4
  /** Fine-grained permission within Code mode. */
5
5
  export type CodePermissionMode = 'ask' | 'plan' | 'auto' | 'bypass';
6
6
  /** Tools allowed per mode; `null` means all registered tools. */
@@ -14,11 +14,13 @@ export const MODE_TOOLS = {
14
14
  ],
15
15
  cowork: null,
16
16
  code: null,
17
+ dvalin: null,
17
18
  };
18
19
  export const MODE_APPROVAL = {
19
20
  chat: 'readonly',
20
21
  cowork: 'auto-edit',
21
22
  code: 'full-auto',
23
+ dvalin: 'full-auto',
22
24
  };
23
25
  export const CODE_PERMISSION_APPROVAL = {
24
26
  ask: 'auto-edit',
@@ -29,16 +31,17 @@ export const CODE_PERMISSION_APPROVAL = {
29
31
  export const MODE_PROMPT = {
30
32
  chat: 'You are in Chat mode. Answer questions, explain code, and discuss ideas. Do NOT write, edit, delete files or run shell commands — read-only tools only.',
31
33
  cowork: 'You are in Cowork mode. Work collaboratively. Briefly explain your plan before making changes. Prefer focused, surgical edits. File writes and shell commands require user approval.',
32
- code: 'You are in Code mode. Work autonomously to complete the task efficiently. Use all available tools as needed. For git fetch/pull/push/clone or package downloads that need outbound network access, use shell with networkAccess="unrestricted" so the user can approve running outside the local subprocess network sandbox when required.',
34
+ code: 'You are in Code mode. Work autonomously to complete the task efficiently. For bug fixes, investigate before editing: first reproduce or inspect the failure, then use search/read evidence to identify the responsible file and line, and only then make the smallest justified change. After editing, rerun the focused failing check before broader validation. Use all available tools as needed. Git and GitHub CLI (gh) operations are supported through shell. For git fetch/pull/push/clone, gh operations, or package downloads that need outbound network access, use shell with networkAccess="unrestricted"; the selected permission mode determines whether runtime approval is required.',
35
+ dvalin: 'You are in Dvalin mode: a security engineering agent for white-box assessment and test-backed remediation. Start from scanner evidence, inspect source and data flow before editing, remove the vulnerability class with the smallest safe change, and rerun focused tests plus the Dvalin security suite. Treat findings as hypotheses until code evidence confirms them. Never weaken tests, suppress a rule, or mark a case verified merely to make a scan pass. Before publishing, review the diff, report remaining risk, and create a draft pull request only when the user explicitly requests publication. Use run_security_suite, remediation cases, isolated worktrees, tests, git, and repository CLI tools as appropriate.',
33
36
  };
34
37
  export const CODE_PERMISSION_PROMPT = {
35
38
  ask: 'Code permission mode: Ask Permissions. Request approval before edits, deletes, or shell commands.',
36
39
  plan: 'Code permission mode: Plan Mode. Create a clear plan only. Do not write files, delete files, or run shell commands.',
37
40
  auto: 'Code permission mode: Auto Mode. Complete the task autonomously with normal tool access.',
38
- bypass: 'Code permission mode: Bypass Permissions. Complete the task without approval prompts. When policy permits, shell commands may run with unrestricted subprocess network access instead of the local network sandbox.',
41
+ bypass: 'Code permission mode: Bypass Permissions. Automatically approve every runtime permission request without prompting, including unrestricted subprocess network access. Organization policy restrictions remain enforced.',
39
42
  };
40
43
  /** Resolve the effective approval mode for a (mode, codePermissionMode) pair. */
41
44
  export function resolveApprovalMode(mode, codePermissionMode) {
42
- return mode === 'code' ? CODE_PERMISSION_APPROVAL[codePermissionMode] : MODE_APPROVAL[mode];
45
+ return mode === 'code' || mode === 'dvalin' ? CODE_PERMISSION_APPROVAL[codePermissionMode] : MODE_APPROVAL[mode];
43
46
  }
44
47
  //# sourceMappingURL=modes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"modes.js","sourceRoot":"","sources":["../../src/agent/modes.ts"],"names":[],"mappings":"AAQA,iEAAiE;AACjE,MAAM,CAAC,MAAM,UAAU,GAAuC;IAC5D,IAAI,EAAI;QACN,WAAW;QACX,YAAY;QACZ,aAAa;QACb,YAAY;QACZ,UAAU;QACV,iBAAiB;QACjB,eAAe;QACf,aAAa;QACb,YAAY;QACZ,wBAAwB;KACzB;IACD,MAAM,EAAE,IAAI;IACZ,IAAI,EAAI,IAAI;CACb,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAoC;IAC5D,IAAI,EAAI,UAAU;IAClB,MAAM,EAAE,WAAW;IACnB,IAAI,EAAI,WAAW;CACpB,CAAC;AAEF,MAAM,CAAC,MAAM,wBAAwB,GAA6C;IAChF,GAAG,EAAK,WAAW;IACnB,IAAI,EAAI,UAAU;IAClB,IAAI,EAAI,WAAW;IACnB,MAAM,EAAE,QAAQ;CACjB,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAA8B;IACpD,IAAI,EACF,yJAAyJ;IAC3J,MAAM,EACJ,sLAAsL;IACxL,IAAI,EACF,4UAA4U;CAC/U,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAuC;IACxE,GAAG,EAAK,mGAAmG;IAC3G,IAAI,EAAI,qHAAqH;IAC7H,IAAI,EAAI,0FAA0F;IAClG,MAAM,EAAE,qNAAqN;CAC9N,CAAC;AAEF,iFAAiF;AACjF,MAAM,UAAU,mBAAmB,CAAC,IAAe,EAAE,kBAAsC;IACzF,OAAO,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,wBAAwB,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;AAC9F,CAAC"}
1
+ {"version":3,"file":"modes.js","sourceRoot":"","sources":["../../src/agent/modes.ts"],"names":[],"mappings":"AAQA,iEAAiE;AACjE,MAAM,CAAC,MAAM,UAAU,GAAuC;IAC5D,IAAI,EAAI;QACN,WAAW;QACX,YAAY;QACZ,aAAa;QACb,YAAY;QACZ,UAAU;QACV,iBAAiB;QACjB,eAAe;QACf,aAAa;QACb,YAAY;QACZ,wBAAwB;KACzB;IACD,MAAM,EAAE,IAAI;IACZ,IAAI,EAAI,IAAI;IACZ,MAAM,EAAE,IAAI;CACb,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAoC;IAC5D,IAAI,EAAI,UAAU;IAClB,MAAM,EAAE,WAAW;IACnB,IAAI,EAAI,WAAW;IACnB,MAAM,EAAE,WAAW;CACpB,CAAC;AAEF,MAAM,CAAC,MAAM,wBAAwB,GAA6C;IAChF,GAAG,EAAK,WAAW;IACnB,IAAI,EAAI,UAAU;IAClB,IAAI,EAAI,WAAW;IACnB,MAAM,EAAE,QAAQ;CACjB,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAA8B;IACpD,IAAI,EACF,yJAAyJ;IAC3J,MAAM,EACJ,sLAAsL;IACxL,IAAI,EACF,uqBAAuqB;IACzqB,MAAM,EACJ,wsBAAwsB;CAC3sB,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAuC;IACxE,GAAG,EAAK,mGAAmG;IAC3G,IAAI,EAAI,qHAAqH;IAC7H,IAAI,EAAI,0FAA0F;IAClG,MAAM,EAAE,yNAAyN;CAClO,CAAC;AAEF,iFAAiF;AACjF,MAAM,UAAU,mBAAmB,CAAC,IAAe,EAAE,kBAAsC;IACzF,OAAO,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,wBAAwB,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;AACnH,CAAC"}
@@ -1,5 +1,5 @@
1
- import type { ChatMessage, ProviderAdapter } from '../providers/types.js';
2
- import type { ToolRegistry } from '../tools/registry.js';
1
+ import type { ChatMessage, TokenUsage, ProviderAdapter } from '../providers/types.js';
2
+ import { type ToolRegistry } from '../tools/registry.js';
3
3
  import type { DvalinContext } from '../core/context.js';
4
4
  import type { TurnConfig, UndoEntry, AgentEventHandler } from './types.js';
5
5
  export type RunnerOptions = {
@@ -9,7 +9,17 @@ export type RunnerOptions = {
9
9
  config: TurnConfig;
10
10
  systemPrompt: string;
11
11
  sharedUndoStack?: UndoEntry[];
12
+ compactHistory?: (messages: ChatMessage[], signal?: AbortSignal) => Promise<ChatMessage[]>;
12
13
  };
14
+ /** Carries the completed model/tool state so an interrupted turn can resume. */
15
+ export declare class TurnInterruptedError extends Error {
16
+ readonly messages: ChatMessage[];
17
+ readonly iterationsUsed: number;
18
+ readonly usage?: TokenUsage | undefined;
19
+ constructor(messages: ChatMessage[], iterationsUsed: number, usage?: TokenUsage | undefined);
20
+ }
21
+ /** Detect a process update that must not be mistaken for a final answer. */
22
+ export declare function looksLikePendingWork(content: string, finishReason?: string): boolean;
13
23
  export declare class AgentRunner {
14
24
  private provider;
15
25
  private registry;
@@ -17,6 +27,7 @@ export declare class AgentRunner {
17
27
  private config;
18
28
  private systemPrompt;
19
29
  private iterationCount;
30
+ private compactHistory?;
20
31
  /** Stack of executed tool calls for undo support */
21
32
  private undoStack;
22
33
  constructor(options: RunnerOptions);
@@ -27,10 +38,7 @@ export declare class AgentRunner {
27
38
  messages: ChatMessage[];
28
39
  finalResponse: string;
29
40
  iterationsUsed: number;
30
- usage?: {
31
- inputTokens: number;
32
- outputTokens: number;
33
- };
41
+ usage?: TokenUsage;
34
42
  }>;
35
43
  private buildToolDefs;
36
44
  private parseToolCalls;
@@ -1,3 +1,56 @@
1
+ import { truncateToolOutput } from '../tools/registry.js';
2
+ import { estimateRequestTokens } from './compact.js';
3
+ /** Carries the completed model/tool state so an interrupted turn can resume. */
4
+ export class TurnInterruptedError extends Error {
5
+ messages;
6
+ iterationsUsed;
7
+ usage;
8
+ constructor(messages, iterationsUsed, usage) {
9
+ super('interrupted');
10
+ this.messages = messages;
11
+ this.iterationsUsed = iterationsUsed;
12
+ this.usage = usage;
13
+ this.name = 'TurnInterruptedError';
14
+ }
15
+ }
16
+ const PENDING_WORK_NUDGE = [
17
+ 'Runtime completion check: your previous response described work that is still pending.',
18
+ 'Continue the task now by calling the next required tool. Do not merely describe what you will do.',
19
+ 'Only return a response without tool calls when the requested task and its focused validation are complete.',
20
+ ].join(' ');
21
+ const INVESTIGATION_NUDGE = [
22
+ 'Runtime investigation check: the first requested action was a source edit, so it was deferred once.',
23
+ 'Before editing, reproduce or inspect the failure and use read/search/command evidence to identify the responsible file and line.',
24
+ 'Then retry the smallest justified edit and rerun the focused failing check.',
25
+ ].join(' ');
26
+ const STALL_NUDGE = [
27
+ 'Runtime progress check: recent actions show no new evidence or verification.',
28
+ 'Pause the current approach, restate the leading hypothesis from observed results, and choose a materially different diagnostic step.',
29
+ 'Do not repeat the same command or keep editing the same area without a new read or focused check.',
30
+ ].join(' ');
31
+ const WRITE_TOOLS = new Set(['edit_file', 'write_file', 'delete_file']);
32
+ const INVESTIGATION_TOOLS = new Set([
33
+ 'read_file',
34
+ 'search_text',
35
+ 'list_files',
36
+ 'git_diff',
37
+ 'git_status',
38
+ 'project_scripts',
39
+ 'run_check',
40
+ 'shell',
41
+ ]);
42
+ /** Detect a process update that must not be mistaken for a final answer. */
43
+ export function looksLikePendingWork(content, finishReason) {
44
+ if (finishReason === 'length' || finishReason === 'max_tokens')
45
+ return true;
46
+ const text = content.trim();
47
+ if (!text)
48
+ return true;
49
+ const englishFutureAction = /\b(?:let me|i(?:'ll| will| need to| am going to)|next,?\s+i(?:'ll| will)|now,?\s+i(?:'ll| will))\s+(?:check|inspect|verify|validate|fix|edit|update|add|run|test|implement|continue|review|open|read|write|create|remove|ensure)\b/i;
50
+ const chineseFutureAction = /(?:让我|我(?:将|会|需要|准备)|接下来|下一步|现在(?:让我|我来|我将|我要)|继续)(?:检查|验证|确认|修复|修改|更新|添加|运行|测试|实现|继续|查看|读取|编写|创建|删除|确保|完成)/;
51
+ const explicitIncomplete = /\b(?:still need to|work remains|remaining steps?)\b|(?:还需要|尚未完成|仍需|待完成)/i;
52
+ return englishFutureAction.test(text) || chineseFutureAction.test(text) || explicitIncomplete.test(text);
53
+ }
1
54
  export class AgentRunner {
2
55
  provider;
3
56
  registry;
@@ -5,6 +58,7 @@ export class AgentRunner {
5
58
  config;
6
59
  systemPrompt;
7
60
  iterationCount = 0;
61
+ compactHistory;
8
62
  /** Stack of executed tool calls for undo support */
9
63
  undoStack;
10
64
  constructor(options) {
@@ -14,6 +68,7 @@ export class AgentRunner {
14
68
  this.config = options.config;
15
69
  this.systemPrompt = options.systemPrompt;
16
70
  this.undoStack = options.sharedUndoStack ?? [];
71
+ this.compactHistory = options.compactHistory;
17
72
  }
18
73
  /** Undo the last N tool calls. Returns a description of what was undone. */
19
74
  async undoLast(count = 1) {
@@ -50,83 +105,181 @@ export class AgentRunner {
50
105
  }
51
106
  /** Run a single turn: user message → LLM → (tool calls → LLM) → final response */
52
107
  async runTurn(userMessage, history, onEvent, signal) {
53
- const messages = [...history, { role: 'user', content: userMessage }];
108
+ let messages = [...history, { role: 'user', content: userMessage }];
54
109
  this.iterationCount = 0;
55
110
  let totalUsage;
56
- while (this.iterationCount < this.config.maxIterations) {
57
- if (signal?.aborted)
58
- throw new Error('interrupted');
59
- this.iterationCount++;
60
- // Build tool definitions from registry
61
- const toolDefs = this.buildToolDefs();
62
- // Call LLM (streaming if onEvent is provided)
63
- const response = await this.provider.chat({
64
- system: this.systemPrompt,
65
- messages,
66
- tools: toolDefs.length > 0 ? toolDefs : undefined,
67
- signal,
68
- onDelta: onEvent ? (delta) => onEvent({ type: 'token_delta', content: delta }) : undefined,
69
- runtime: {
70
- policy: this.context.policy,
71
- audit: this.context.audit,
72
- },
73
- });
74
- // Accumulate token usage across all iterations
75
- if (response.usage) {
76
- if (!totalUsage)
77
- totalUsage = { inputTokens: 0, outputTokens: 0 };
78
- totalUsage.inputTokens += response.usage.inputTokens;
79
- totalUsage.outputTokens += response.usage.outputTokens;
80
- }
81
- // Add assistant message — include tool_calls if present (required by OpenAI-compatible APIs)
82
- const assistantMsg = {
83
- role: 'assistant',
84
- content: response.content,
85
- tool_calls: response.toolCalls && response.toolCalls.length > 0 ? response.toolCalls : undefined,
86
- };
87
- messages.push(assistantMsg);
88
- // Check for tool calls — prefer native API response, fallback to @tool() text parsing
89
- let toolCalls = [];
90
- if (response.toolCalls && response.toolCalls.length > 0) {
91
- toolCalls = response.toolCalls;
92
- }
93
- else {
94
- toolCalls = this.parseToolCalls(response.content);
95
- }
96
- if (toolCalls.length === 0) {
97
- // No tool calls — this is the final response
98
- return { messages, finalResponse: response.content, iterationsUsed: this.iterationCount, usage: totalUsage };
99
- }
100
- // Cap tool calls per turn
101
- const callsToExecute = toolCalls.slice(0, this.config.maxToolCallsPerTurn);
102
- // Execute tool calls
103
- for (const tc of callsToExecute) {
104
- try {
105
- const parsedInput = JSON.parse(tc.arguments);
106
- onEvent?.({ type: 'tool_call', name: tc.name, id: tc.id, input: parsedInput });
107
- const result = await this.registry.run(tc.name, parsedInput, this.context);
108
- // Record undo entry for this tool call
109
- this.undoStack.push({
110
- toolName: tc.name,
111
- input: parsedInput,
112
- result: {
113
- title: result.title,
114
- output: result.output,
115
- metadata: result.metadata,
116
- },
117
- reverseInput: null,
118
- timestamp: new Date().toISOString(),
119
- });
120
- onEvent?.({ type: 'tool_result', name: tc.name, id: tc.id, output: result.output, metadata: result.metadata });
121
- messages.push({
122
- role: 'tool',
123
- content: `[Tool ${tc.name} result]:\n${result.output}`,
124
- tool_call_id: tc.id,
125
- name: tc.name,
126
- });
111
+ let lastCompactionAtTokens = 0;
112
+ let totalToolCalls = 0;
113
+ let hasInvestigated = history.some(message => message.role === 'tool' && Boolean(message.name && INVESTIGATION_TOOLS.has(message.name)));
114
+ let investigationNudged = false;
115
+ let stallNudges = 0;
116
+ const changedFiles = new Set();
117
+ const stall = {
118
+ recentActions: [],
119
+ recentLabels: [],
120
+ repeatCount: 0,
121
+ consecutiveEdits: 0,
122
+ writeGeneration: 0,
123
+ };
124
+ try {
125
+ while (this.iterationCount < this.config.maxIterations) {
126
+ if (signal?.aborted)
127
+ throw new Error('interrupted');
128
+ this.iterationCount++;
129
+ onEvent?.({ type: 'llm_iteration', iteration: this.iterationCount });
130
+ // Build tool definitions from registry
131
+ const toolDefs = this.buildToolDefs();
132
+ // Long coding turns grow after every tool result. Compact at iteration
133
+ // boundaries so the turn can continue instead of hitting the provider's
134
+ // context limit halfway through the task.
135
+ const triggerTokens = this.config.contextTokenLimit * this.config.compactThreshold;
136
+ const requestTokens = estimateRequestTokens(messages, this.systemPrompt, toolDefs);
137
+ if (this.compactHistory &&
138
+ requestTokens > triggerTokens &&
139
+ requestTokens > lastCompactionAtTokens + 1_000) {
140
+ lastCompactionAtTokens = requestTokens;
141
+ messages = await this.compactHistory(messages, signal);
142
+ if (signal?.aborted)
143
+ throw new Error('interrupted');
144
+ }
145
+ // Call LLM (streaming if onEvent is provided)
146
+ const response = await this.provider.chat({
147
+ system: this.systemPrompt,
148
+ messages,
149
+ tools: toolDefs.length > 0 ? toolDefs : undefined,
150
+ signal,
151
+ onDelta: onEvent ? (delta) => onEvent({ type: 'token_delta', content: delta }) : undefined,
152
+ runtime: {
153
+ policy: this.context.policy,
154
+ audit: this.context.audit,
155
+ },
156
+ });
157
+ // Accumulate token usage across all iterations
158
+ if (response.usage) {
159
+ totalUsage = accumulateUsage(totalUsage, response.usage);
160
+ }
161
+ // Add assistant message — include tool_calls if present (required by OpenAI-compatible APIs)
162
+ const assistantMsg = {
163
+ role: 'assistant',
164
+ content: response.content,
165
+ tool_calls: response.toolCalls && response.toolCalls.length > 0 ? response.toolCalls : undefined,
166
+ };
167
+ messages.push(assistantMsg);
168
+ // Check for tool calls — prefer native API response, fallback to @tool() text parsing
169
+ let toolCalls = [];
170
+ if (response.toolCalls && response.toolCalls.length > 0) {
171
+ toolCalls = response.toolCalls;
127
172
  }
128
- catch (err) {
129
- const error = err instanceof Error ? err.message : String(err);
173
+ else {
174
+ toolCalls = this.parseToolCalls(response.content);
175
+ }
176
+ if (toolCalls.length === 0) {
177
+ // Some models occasionally emit a narration such as "let me verify
178
+ // the file" without the promised tool call. Treat that as an
179
+ // incomplete checkpoint and immediately ask for the actual action.
180
+ if (looksLikePendingWork(response.content, response.finishReason)) {
181
+ // Keep the request prefix append-only so provider prompt caches can
182
+ // reuse every prior message on the next iteration.
183
+ messages.push({ role: 'user', content: PENDING_WORK_NUDGE });
184
+ continue;
185
+ }
186
+ // A tool-free response with no pending-work signal is the final answer.
187
+ return { messages, finalResponse: response.content, iterationsUsed: this.iterationCount, usage: totalUsage };
188
+ }
189
+ // Enforce the budget across the entire turn. Previously this slice was
190
+ // reset on every model iteration, so a nominal 15-call limit could grow
191
+ // to hundreds of actions and make simple tasks spiral.
192
+ const remainingToolCalls = Math.max(0, this.config.maxToolCallsPerTurn - totalToolCalls);
193
+ const callsToExecute = toolCalls.slice(0, remainingToolCalls);
194
+ const skippedCalls = toolCalls.slice(remainingToolCalls);
195
+ let deferredFirstEdit = false;
196
+ let stallReason;
197
+ // Execute tool calls
198
+ for (const tc of callsToExecute) {
199
+ if (signal?.aborted)
200
+ throw new Error('interrupted');
201
+ let parsedInput;
202
+ try {
203
+ parsedInput = JSON.parse(tc.arguments);
204
+ // A one-shot soft gate prevents a model from acting directly on
205
+ // issue wording before it has gathered any workspace evidence.
206
+ if (WRITE_TOOLS.has(tc.name) && !hasInvestigated && !investigationNudged) {
207
+ investigationNudged = true;
208
+ deferredFirstEdit = true;
209
+ const error = 'Deferred once: inspect/reproduce and locate the responsible code before the first source edit.';
210
+ onEvent?.({ type: 'tool_error', name: tc.name, id: tc.id, error });
211
+ messages.push({
212
+ role: 'tool',
213
+ content: `[Tool ${tc.name} error]: ${error}`,
214
+ tool_call_id: tc.id,
215
+ name: tc.name,
216
+ });
217
+ observeAction(stall, tc.name, parsedInput, undefined, error, this.config);
218
+ totalToolCalls++;
219
+ continue;
220
+ }
221
+ onEvent?.({ type: 'tool_call', name: tc.name, id: tc.id, input: parsedInput });
222
+ const result = await this.registry.run(tc.name, parsedInput, signal ? { ...this.context, signal } : this.context);
223
+ const bounded = truncateToolOutput(result.output, this.config.maxToolResultBytes ?? 32_000);
224
+ const visibleResult = bounded.output;
225
+ // Record undo entry for this tool call
226
+ this.undoStack.push({
227
+ toolName: tc.name,
228
+ input: parsedInput,
229
+ result: {
230
+ title: result.title,
231
+ output: visibleResult,
232
+ metadata: result.metadata,
233
+ },
234
+ reverseInput: null,
235
+ timestamp: new Date().toISOString(),
236
+ });
237
+ onEvent?.({
238
+ type: 'tool_result',
239
+ name: tc.name,
240
+ id: tc.id,
241
+ output: visibleResult,
242
+ metadata: bounded.truncated
243
+ ? { ...result.metadata, outputTruncated: true, omittedBytes: bounded.omittedBytes }
244
+ : result.metadata,
245
+ });
246
+ messages.push({
247
+ role: 'tool',
248
+ content: `[Tool ${tc.name} result]:\n${visibleResult}`,
249
+ tool_call_id: tc.id,
250
+ name: tc.name,
251
+ });
252
+ if (INVESTIGATION_TOOLS.has(tc.name))
253
+ hasInvestigated = true;
254
+ if (WRITE_TOOLS.has(tc.name)) {
255
+ const path = toolPath(parsedInput);
256
+ if (path)
257
+ changedFiles.add(path);
258
+ }
259
+ stallReason ??= observeAction(stall, tc.name, parsedInput, result.metadata, undefined, this.config);
260
+ }
261
+ catch (err) {
262
+ if (signal?.aborted)
263
+ throw err;
264
+ const error = err instanceof Error ? err.message : String(err);
265
+ onEvent?.({ type: 'tool_error', name: tc.name, id: tc.id, error });
266
+ messages.push({
267
+ role: 'tool',
268
+ content: `[Tool ${tc.name} error]: ${error}`,
269
+ tool_call_id: tc.id,
270
+ name: tc.name,
271
+ });
272
+ stallReason ??= observeAction(stall, tc.name, parsedInput ?? tc.arguments, undefined, error, this.config);
273
+ }
274
+ totalToolCalls++;
275
+ }
276
+ if (deferredFirstEdit) {
277
+ messages.push({ role: 'user', content: INVESTIGATION_NUDGE });
278
+ }
279
+ // Native tool-call protocols require one tool response for every call
280
+ // in the assistant message, including calls rejected by the budget.
281
+ for (const tc of skippedCalls) {
282
+ const error = `Skipped: reached the ${this.config.maxToolCallsPerTurn}-action turn limit.`;
130
283
  onEvent?.({ type: 'tool_error', name: tc.name, id: tc.id, error });
131
284
  messages.push({
132
285
  role: 'tool',
@@ -135,13 +288,45 @@ export class AgentRunner {
135
288
  name: tc.name,
136
289
  });
137
290
  }
291
+ if (totalToolCalls >= this.config.maxToolCallsPerTurn || skippedCalls.length > 0) {
292
+ return {
293
+ messages,
294
+ finalResponse: `Task paused after ${totalToolCalls} actions, the configured per-turn safety limit. Review the completed actions or send "continue" if more work is needed.`,
295
+ iterationsUsed: this.iterationCount,
296
+ usage: totalUsage,
297
+ };
298
+ }
299
+ if (stallReason) {
300
+ if (stallNudges === 0) {
301
+ stallNudges++;
302
+ messages.push({ role: 'user', content: `${STALL_NUDGE}\n\nDetected: ${stallReason}` });
303
+ resetStallCheckpoint(stall);
304
+ continue;
305
+ }
306
+ return {
307
+ messages,
308
+ finalResponse: renderStallSummary(stallReason, changedFiles, stall.recentLabels),
309
+ iterationsUsed: this.iterationCount,
310
+ usage: totalUsage,
311
+ };
312
+ }
313
+ }
314
+ }
315
+ catch (err) {
316
+ if (signal?.aborted || (err instanceof Error && err.message === 'interrupted')) {
317
+ throw new TurnInterruptedError(messages, this.iterationCount, totalUsage);
138
318
  }
319
+ throw err;
139
320
  }
140
321
  // Max iterations reached
141
322
  const lastMsg = messages.filter(m => m.role === 'assistant').pop();
323
+ const detail = lastMsg?.content.trim();
142
324
  return {
143
325
  messages,
144
- finalResponse: lastMsg?.content ?? 'Max iterations reached without final response.',
326
+ finalResponse: [
327
+ detail,
328
+ `Task paused after reaching the ${this.config.maxIterations}-iteration safety limit. Send \"continue\" to resume from the saved tool state.`,
329
+ ].filter(Boolean).join('\n\n'),
145
330
  iterationsUsed: this.iterationCount,
146
331
  usage: totalUsage,
147
332
  };
@@ -168,4 +353,114 @@ export class AgentRunner {
168
353
  return calls;
169
354
  }
170
355
  }
356
+ function accumulateUsage(total, next) {
357
+ const merged = {
358
+ inputTokens: (total?.inputTokens ?? 0) + next.inputTokens,
359
+ outputTokens: (total?.outputTokens ?? 0) + next.outputTokens,
360
+ };
361
+ for (const key of ['cachedInputTokens', 'cacheMissInputTokens', 'cacheWriteInputTokens']) {
362
+ const value = (total?.[key] ?? 0) + (next[key] ?? 0);
363
+ if (value > 0 || total?.[key] !== undefined || next[key] !== undefined)
364
+ merged[key] = value;
365
+ }
366
+ return merged;
367
+ }
368
+ function observeAction(state, toolName, input, metadata, error, config) {
369
+ const signature = `${toolName}:${stableStringify(input)}`;
370
+ const label = `${toolName} ${summarizeInput(input)}`.trim();
371
+ const window = Math.max(2, config.stallWindow ?? 8);
372
+ state.recentActions.push(signature);
373
+ state.recentLabels.push(label);
374
+ if (state.recentActions.length > window)
375
+ state.recentActions.shift();
376
+ if (state.recentLabels.length > window)
377
+ state.recentLabels.shift();
378
+ if (signature === state.lastSignature)
379
+ state.repeatCount++;
380
+ else {
381
+ state.lastSignature = signature;
382
+ state.repeatCount = 1;
383
+ }
384
+ if (WRITE_TOOLS.has(toolName) && !error) {
385
+ state.consecutiveEdits++;
386
+ state.writeGeneration++;
387
+ }
388
+ else if (INVESTIGATION_TOOLS.has(toolName)) {
389
+ state.consecutiveEdits = 0;
390
+ }
391
+ const maxRepeats = Math.max(2, config.maxRepeats ?? 2);
392
+ if (state.repeatCount >= maxRepeats) {
393
+ return `the exact action “${label}” repeated ${state.repeatCount} times consecutively`;
394
+ }
395
+ const exitCode = typeof metadata?.exitCode === 'number' ? metadata.exitCode : undefined;
396
+ if (isTestAction(toolName, input) && (error || (exitCode !== undefined && exitCode !== 0))) {
397
+ const prior = state.lastFailedTest;
398
+ if (prior?.signature === signature && prior.writeGeneration === state.writeGeneration) {
399
+ prior.count++;
400
+ }
401
+ else {
402
+ state.lastFailedTest = { signature, writeGeneration: state.writeGeneration, count: 1 };
403
+ }
404
+ if ((state.lastFailedTest?.count ?? 0) >= maxRepeats) {
405
+ return `the same focused check failed ${state.lastFailedTest.count} times without an intervening source edit`;
406
+ }
407
+ }
408
+ const maxUnverifiedEdits = Math.max(2, config.maxUnverifiedEdits ?? 4);
409
+ if (state.consecutiveEdits >= maxUnverifiedEdits) {
410
+ return `${state.consecutiveEdits} consecutive source edits were made without a read, diff, or validation step`;
411
+ }
412
+ return undefined;
413
+ }
414
+ function resetStallCheckpoint(state) {
415
+ state.recentActions = [];
416
+ state.recentLabels = [];
417
+ state.lastSignature = undefined;
418
+ state.repeatCount = 0;
419
+ state.consecutiveEdits = 0;
420
+ state.lastFailedTest = undefined;
421
+ }
422
+ function renderStallSummary(reason, changedFiles, recentLabels) {
423
+ const files = changedFiles.size > 0 ? [...changedFiles].sort().join(', ') : 'none';
424
+ const actions = recentLabels.length > 0 ? recentLabels.map(action => `- ${action}`).join('\n') : '- none';
425
+ return [
426
+ 'Task paused early because the agent remained stalled after a corrective checkpoint.',
427
+ '',
428
+ `Stall reason: ${reason}.`,
429
+ `Files changed this turn: ${files}.`,
430
+ 'Recent actions:',
431
+ actions,
432
+ '',
433
+ 'Resume with a different hypothesis or provide additional diagnostic context.',
434
+ ].join('\n');
435
+ }
436
+ function toolPath(input) {
437
+ if (!input || typeof input !== 'object')
438
+ return undefined;
439
+ const value = input.filePath;
440
+ return typeof value === 'string' ? value : undefined;
441
+ }
442
+ function isTestAction(toolName, input) {
443
+ if (toolName === 'run_check')
444
+ return input?.kind === 'test';
445
+ if (toolName !== 'shell' || !input || typeof input !== 'object')
446
+ return false;
447
+ const record = input;
448
+ const command = [record.command, ...(Array.isArray(record.args) ? record.args : [])].join(' ');
449
+ return /\b(?:pytest|py\.test|vitest|jest|test|check)\b/i.test(command);
450
+ }
451
+ function summarizeInput(input) {
452
+ const text = stableStringify(input);
453
+ return text.length > 120 ? `${text.slice(0, 120)}…` : text;
454
+ }
455
+ function stableStringify(value) {
456
+ if (Array.isArray(value))
457
+ return `[${value.map(stableStringify).join(',')}]`;
458
+ if (value && typeof value === 'object') {
459
+ return `{${Object.entries(value)
460
+ .sort(([a], [b]) => a.localeCompare(b))
461
+ .map(([key, entry]) => `${JSON.stringify(key)}:${stableStringify(entry)}`)
462
+ .join(',')}}`;
463
+ }
464
+ return JSON.stringify(value);
465
+ }
171
466
  //# sourceMappingURL=runner.js.map