@orion-agents/orion-code 0.4.7 → 0.4.9

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 (142) hide show
  1. package/CHANGELOG.md +17 -1
  2. package/README.md +8 -9
  3. package/README.zh-CN.md +8 -8
  4. package/dist/acp/session-updates.js +1 -0
  5. package/dist/cli.js +42 -3
  6. package/dist/commands/session-command-handlers.js +8 -3
  7. package/dist/commands/system-commands.js +3 -3
  8. package/dist/commands/types.d.ts +3 -0
  9. package/dist/framework/loop-progress.js +3 -1
  10. package/dist/framework/query.d.ts +6 -8
  11. package/dist/framework/query.js +39 -76
  12. package/dist/framework/tool-serializer.d.ts +12 -0
  13. package/dist/framework/tool-serializer.js +35 -0
  14. package/dist/framework/tool.d.ts +2 -0
  15. package/dist/framework/verification-command.d.ts +21 -0
  16. package/dist/framework/verification-command.js +53 -4
  17. package/dist/harness/context-harness.d.ts +3 -9
  18. package/dist/harness/context-harness.js +43 -163
  19. package/dist/harness/ledger.js +2 -1
  20. package/dist/harness/state.d.ts +3 -0
  21. package/dist/harness/state.js +37 -4
  22. package/dist/harness/task-checklist.d.ts +1 -1
  23. package/dist/harness/task-checklist.js +1 -1
  24. package/dist/harness/types.d.ts +1 -0
  25. package/dist/harness/verification.js +5 -4
  26. package/dist/print-ui/delivery.d.ts +15 -0
  27. package/dist/print-ui/delivery.js +131 -0
  28. package/dist/print-ui/event-stream.d.ts +6 -1
  29. package/dist/print-ui/event-stream.js +56 -10
  30. package/dist/print-ui/launch.d.ts +5 -0
  31. package/dist/print-ui/launch.js +66 -9
  32. package/dist/runtime/agent-loop.d.ts +3 -1
  33. package/dist/runtime/agent-loop.js +26 -41
  34. package/dist/runtime/agent-runtime-controller.d.ts +4 -1
  35. package/dist/runtime/agent-runtime-controller.js +36 -22
  36. package/dist/runtime/agent-runtime-runner.d.ts +4 -0
  37. package/dist/runtime/agent-runtime-runner.js +9 -0
  38. package/dist/runtime/builtin-tool-provider.js +6 -5
  39. package/dist/runtime/composer/layout.d.ts +1 -1
  40. package/dist/runtime/composer/layout.js +5 -5
  41. package/dist/runtime/core-tools/descriptors.d.ts +1 -1
  42. package/dist/runtime/core-tools/descriptors.js +39 -1
  43. package/dist/runtime/first-party-core-provider.js +1 -0
  44. package/dist/runtime/first-party-tool-services.js +10 -0
  45. package/dist/runtime/goal-lifecycle-v2.js +5 -0
  46. package/dist/runtime/goal-runtime-coordinator.js +6 -2
  47. package/dist/runtime/goals/evidence.js +2 -0
  48. package/dist/runtime/legacy-thread-materializer.d.ts +7 -0
  49. package/dist/runtime/legacy-thread-materializer.js +32 -6
  50. package/dist/runtime/orion-runtime-v1.d.ts +2 -1
  51. package/dist/runtime/orion-runtime-v1.js +34 -6
  52. package/dist/runtime/product-bootstrap.d.ts +2 -0
  53. package/dist/runtime/product-bootstrap.js +1 -0
  54. package/dist/runtime/product-orion-runtime.d.ts +2 -1
  55. package/dist/runtime/product-orion-runtime.js +7 -2
  56. package/dist/runtime/rich-text/layout.d.ts +3 -1
  57. package/dist/runtime/rich-text/layout.js +37 -22
  58. package/dist/runtime/shell-process-sessions.d.ts +41 -0
  59. package/dist/runtime/shell-process-sessions.js +258 -0
  60. package/dist/runtime/step-snapshot.js +61 -11
  61. package/dist/runtime/subagents/presets.d.ts +1 -1
  62. package/dist/runtime/subagents/presets.js +1 -0
  63. package/dist/runtime/task-context-recovery.js +14 -3
  64. package/dist/runtime/task-context-service.d.ts +2 -6
  65. package/dist/runtime/task-context-service.js +3 -12
  66. package/dist/runtime/thread-event-store.d.ts +3 -0
  67. package/dist/runtime/thread-event-store.js +35 -22
  68. package/dist/runtime/thread-session-index.d.ts +15 -3
  69. package/dist/runtime/thread-session-index.js +152 -45
  70. package/dist/runtime/thread-session-view.js +1 -1
  71. package/dist/runtime/thread-ui-adapter.d.ts +1 -1
  72. package/dist/runtime/thread-ui-adapter.js +23 -5
  73. package/dist/runtime/tool-gateway.d.ts +1 -0
  74. package/dist/runtime/tool-gateway.js +1 -0
  75. package/dist/runtime/tool-transcript-entry.d.ts +8 -1
  76. package/dist/runtime/tool-transcript-entry.js +35 -7
  77. package/dist/runtime/ui-events.d.ts +10 -0
  78. package/dist/runtime/verification-feedback.d.ts +4 -0
  79. package/dist/runtime/verification-feedback.js +61 -0
  80. package/dist/services/global-config.d.ts +1 -1
  81. package/dist/services/global-config.js +2 -0
  82. package/dist/services/llm.d.ts +3 -0
  83. package/dist/services/llm.js +48 -4
  84. package/dist/terminal-ui/raw-editor.js +2 -1
  85. package/dist/tools/bash_security.d.ts +1 -24
  86. package/dist/tools/bash_security.js +7 -124
  87. package/dist/tools/core/exec-command.js +51 -42
  88. package/dist/tools/core/index.d.ts +2 -1
  89. package/dist/tools/core/index.js +4 -1
  90. package/dist/tools/core/process-session.d.ts +2 -0
  91. package/dist/tools/core/process-session.js +54 -0
  92. package/dist/tools/todo.js +9 -13
  93. package/dist/tui-core/frame.d.ts +2 -0
  94. package/dist/tui-core/frame.js +19 -0
  95. package/dist/tui-core/input-parser.d.ts +4 -1
  96. package/dist/tui-core/input-parser.js +22 -0
  97. package/dist/tui-ui/chrome-view-model.d.ts +0 -2
  98. package/dist/tui-ui/chrome-view-model.js +54 -56
  99. package/dist/tui-ui/launch.js +133 -202
  100. package/dist/tui-ui/layout.d.ts +16 -41
  101. package/dist/tui-ui/layout.js +408 -295
  102. package/dist/tui-ui/render-scheduler.d.ts +2 -5
  103. package/dist/tui-ui/render-scheduler.js +10 -10
  104. package/dist/tui-ui/response-clipboard.d.ts +17 -0
  105. package/dist/tui-ui/response-clipboard.js +201 -0
  106. package/dist/tui-ui/runner.d.ts +65 -80
  107. package/dist/tui-ui/runner.js +545 -738
  108. package/dist/tui-ui/session-picker-preview.d.ts +8 -0
  109. package/dist/tui-ui/session-picker-preview.js +119 -0
  110. package/dist/tui-ui/session-picker.d.ts +20 -0
  111. package/dist/tui-ui/session-picker.js +42 -0
  112. package/dist/tui-ui/state.d.ts +34 -81
  113. package/dist/tui-ui/state.js +155 -288
  114. package/dist/tui-ui/terminal-image.d.ts +3 -7
  115. package/dist/tui-ui/terminal-image.js +18 -47
  116. package/dist/tui-ui/terminal-viewport.d.ts +55 -0
  117. package/dist/tui-ui/terminal-viewport.js +221 -0
  118. package/dist/tui-ui/transcript-layout.d.ts +5 -0
  119. package/dist/tui-ui/transcript-layout.js +43 -28
  120. package/dist/tui-ui/transcript-pager.d.ts +39 -0
  121. package/dist/tui-ui/transcript-pager.js +278 -0
  122. package/dist/tui-ui/transcript-tool-output.d.ts +16 -0
  123. package/dist/tui-ui/transcript-tool-output.js +102 -0
  124. package/dist/utils/bounded-file.d.ts +4 -0
  125. package/dist/utils/bounded-file.js +30 -0
  126. package/dist/utils/command-process.d.ts +4 -0
  127. package/dist/utils/command-process.js +23 -0
  128. package/dist/utils/shell-command.d.ts +29 -0
  129. package/dist/utils/shell-command.js +185 -0
  130. package/docs/cli-guide.md +50 -6
  131. package/npm-shrinkwrap.json +115 -15
  132. package/package.json +4 -1
  133. package/dist/tui-ui/inline-surface.d.ts +0 -191
  134. package/dist/tui-ui/inline-surface.js +0 -644
  135. package/dist/tui-ui/input-ownership.d.ts +0 -46
  136. package/dist/tui-ui/input-ownership.js +0 -74
  137. package/dist/tui-ui/transcript-inspector-layout.d.ts +0 -9
  138. package/dist/tui-ui/transcript-inspector-layout.js +0 -107
  139. package/dist/tui-ui/transcript-inspector-surface.d.ts +0 -18
  140. package/dist/tui-ui/transcript-inspector-surface.js +0 -91
  141. package/dist/tui-ui/transcript-inspector.d.ts +0 -36
  142. package/dist/tui-ui/transcript-inspector.js +0 -129
@@ -1,6 +1,23 @@
1
1
  export declare const LOCAL_VERIFICATION_KINDS: readonly ["test", "build", "lint", "typecheck", "diff"];
2
2
  export type LocalVerificationKind = (typeof LOCAL_VERIFICATION_KINDS)[number];
3
3
  export type VerificationCommandKind = LocalVerificationKind | 'generic';
4
+ /** Model-visible diagnostic. Evidence is derived independently from executor receipts. */
5
+ export interface VerificationToolFeedback {
6
+ readonly kind: VerificationCommandKind;
7
+ readonly status: 'passed' | 'failed' | 'unverified';
8
+ readonly reason?: 'shell_pipeline' | 'compound_shell' | 'workspace_unavailable' | 'interrupted' | 'process_did_not_exit';
9
+ readonly message?: string;
10
+ readonly retry?: {
11
+ readonly tool: 'exec_command';
12
+ readonly args: {
13
+ readonly command: string;
14
+ readonly cwd: string;
15
+ readonly maxOutput: number;
16
+ readonly timeout?: number;
17
+ };
18
+ };
19
+ }
20
+ export type VerificationToolStatus = Pick<VerificationToolFeedback, 'kind' | 'status' | 'reason'>;
4
21
  /** Projected by the authoritative executor, outside of model-visible tool output. */
5
22
  export interface LocalVerificationReceipt {
6
23
  readonly kind: VerificationCommandKind;
@@ -10,7 +27,11 @@ export interface LocalVerificationReceipt {
10
27
  readonly passed: boolean;
11
28
  }
12
29
  export declare function isLocalVerificationKind(value: unknown): value is LocalVerificationKind;
30
+ export declare function verificationToolStatus(value: unknown): VerificationToolStatus | undefined;
31
+ export declare function hasNonzeroShellExitCode(metadata: Record<string, unknown> | undefined): boolean;
13
32
  export declare const SHELL_CONTROL_OPERATOR: RegExp;
33
+ /** Identify a runner for diagnostics when shell composition prevents a receipt. */
34
+ export declare function identifyVerificationRunner(command: string): LocalVerificationKind | undefined;
14
35
  export declare function classifyDirectVerificationCommand(command: string): VerificationCommandKind | undefined;
15
36
  /** Support an explicitly requested script without treating arbitrary script runs as checks. */
16
37
  export declare function classifyVerificationSelector(command: string): VerificationCommandKind | undefined;
@@ -2,12 +2,39 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SHELL_CONTROL_OPERATOR = exports.LOCAL_VERIFICATION_KINDS = void 0;
4
4
  exports.isLocalVerificationKind = isLocalVerificationKind;
5
+ exports.verificationToolStatus = verificationToolStatus;
6
+ exports.hasNonzeroShellExitCode = hasNonzeroShellExitCode;
7
+ exports.identifyVerificationRunner = identifyVerificationRunner;
5
8
  exports.classifyDirectVerificationCommand = classifyDirectVerificationCommand;
6
9
  exports.classifyVerificationSelector = classifyVerificationSelector;
10
+ const shell_command_1 = require("../utils/shell-command");
7
11
  exports.LOCAL_VERIFICATION_KINDS = ['test', 'build', 'lint', 'typecheck', 'diff'];
8
12
  function isLocalVerificationKind(value) {
9
13
  return exports.LOCAL_VERIFICATION_KINDS.some(kind => kind === value);
10
14
  }
15
+ function verificationToolStatus(value) {
16
+ if (!value || typeof value !== 'object')
17
+ return;
18
+ const { kind, status, reason } = value;
19
+ if ((kind === 'generic' || isLocalVerificationKind(kind)) &&
20
+ (status === 'passed' || status === 'failed' || status === 'unverified')) {
21
+ return {
22
+ kind,
23
+ status,
24
+ ...(reason === 'shell_pipeline' ||
25
+ reason === 'compound_shell' ||
26
+ reason === 'workspace_unavailable' ||
27
+ reason === 'interrupted' ||
28
+ reason === 'process_did_not_exit'
29
+ ? { reason }
30
+ : {}),
31
+ };
32
+ }
33
+ }
34
+ function hasNonzeroShellExitCode(metadata) {
35
+ const exitCode = metadata?.exitCode;
36
+ return typeof exitCode === 'number' && Number.isSafeInteger(exitCode) && exitCode > 0;
37
+ }
11
38
  exports.SHELL_CONTROL_OPERATOR = /[;&|\x60\n\r]|\$\(/u;
12
39
  const directChecks = {
13
40
  test: /^(?:(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?test|(?:npx\s+)?(?:jest|vitest)|(?:python3?\s+-m\s+)?pytest|(?:go|cargo|make)\s+test)(?=\s|$)/u,
@@ -17,14 +44,36 @@ const directChecks = {
17
44
  diff: /^git\s+diff\s+(?:(?:--cached|--staged)\s+)?--check(?=\s|$)/u,
18
45
  };
19
46
  // These calls can return zero without running a check.
20
- const nonCheckingOption = /(?:^|[\s'"])(?:-h|--help|--version|--listTests|--listFilesOnly|--showConfig|--collect-only|--dry-run|--no-run|--passWithNoTests|--pass-with-no-tests|--if-present|-list)(?=[\s'"=]|$)/u;
47
+ const nonCheckingOption = /^(?:-h|--help|--version|--listTests|--listFilesOnly|--showConfig|--collect-only|--dry-run|--no-run|--passWithNoTests|--pass-with-no-tests|--if-present|-list)(?==|$)/u;
48
+ const pytestInvocation = /^(?:(?:python3?\s+-m\s+)?pytest)(?=\s|$)/u;
49
+ const pytestListingOption = /^(?:-[qvsxlf]*[Vh][qvsxlf]*|--co|--collectonly|--cache-show|--fixtures|--fixtures-per-test|--markers|--setup-plan|--setup-only)(?==|$)/u;
21
50
  const nonCheckingInvocation = /^(?:npx\s+)?(?:vitest\s+list|tsc\s+(?:-v|--init))(?=\s|$)/u;
22
51
  const fileAssertion = /^test\s+-(?:e|f|d|s)\s+(?:"[^"]+"|'[^']+'|[^\s'"<>]+)$/u;
23
52
  const customCheck = /^(?:(?:python3?|node)\s+(?:"[^"]+\.(?:py|[cm]?js)"|'[^']+\.(?:py|[cm]?js)'|[^\s'"<>]+\.(?:py|[cm]?js))|\.\/[^\s'"<>]+|(?:npm|pnpm|yarn|bun)\s+run\s+[\w:.-]+)(?=\s|$)/u;
53
+ function isCheckingArguments(command, words) {
54
+ return (!words.some(word => nonCheckingOption.test(word)) &&
55
+ !(pytestInvocation.test(command) && words.some(word => pytestListingOption.test(word))) &&
56
+ !nonCheckingInvocation.test(words.join(' ')));
57
+ }
24
58
  function isCheckingInvocation(command) {
25
- return (!exports.SHELL_CONTROL_OPERATOR.test(command) &&
26
- !nonCheckingOption.test(command) &&
27
- !nonCheckingInvocation.test(command));
59
+ let compound = false;
60
+ const scan = (0, shell_command_1.scanShellCommand)(command, () => {
61
+ compound = true;
62
+ });
63
+ if (compound || !scan.supported || scan.segments.length !== 1)
64
+ return false;
65
+ const words = (0, shell_command_1.literalShellWords)(scan.segments[0]);
66
+ if (!words?.length)
67
+ return false;
68
+ return isCheckingArguments(command, words);
69
+ }
70
+ /** Identify a runner for diagnostics when shell composition prevents a receipt. */
71
+ function identifyVerificationRunner(command) {
72
+ const normalized = command.trim();
73
+ const words = (0, shell_command_1.literalShellWords)(normalized);
74
+ if (words && !isCheckingArguments(normalized, words))
75
+ return;
76
+ return exports.LOCAL_VERIFICATION_KINDS.find(kind => directChecks[kind].test(normalized));
28
77
  }
29
78
  function classifyDirectVerificationCommand(command) {
30
79
  const normalized = command.trim();
@@ -2,7 +2,7 @@ import type { LLMResponse, Message } from '../services/llm';
2
2
  import type { TodoItem, TodoWriteAdjustment } from '../framework/tool-state';
3
3
  import { type PromptAssemblyOptions } from './assembler';
4
4
  import { type CreateTurnSummaryInput } from './turn-summary';
5
- import type { CompletionGateResult, CapabilityProfileInput, ContextCapsule, DriftCheckResult, HarnessConfig, HarnessProgressState, HarnessState, IntentUpdate, ProgressDelta, TaskPlanStop, TaskTodoObservation, TaskWorkspaceAction, ToolResultObservation, TurnSummary } from './types';
5
+ import type { CompletionGateResult, CapabilityProfileInput, ContextCapsule, DriftCheckResult, HarnessConfig, HarnessProgressState, HarnessState, IntentUpdate, ProgressDelta, TaskTodoObservation, TaskWorkspaceAction, ToolResultObservation, TurnSummary } from './types';
6
6
  export interface ContextHarnessOptions {
7
7
  cwd: string;
8
8
  modelId: string;
@@ -19,7 +19,6 @@ export declare class HarnessKernel {
19
19
  private contract;
20
20
  private ledger;
21
21
  private capsule?;
22
- private completionBlockCount;
23
22
  private taskEpoch;
24
23
  private taskChecklistRequired;
25
24
  private taskChecklistTargets;
@@ -27,8 +26,7 @@ export declare class HarnessKernel {
27
26
  private goalTaskId?;
28
27
  private goalVerificationBlocker?;
29
28
  private taskTodos;
30
- private reportedTaskBlocker?;
31
- private readonly taskTodoReceipts;
29
+ private taskTodoReceipts;
32
30
  private rootObjective?;
33
31
  private activeInstruction?;
34
32
  private intentHistory;
@@ -40,7 +38,6 @@ export declare class HarnessKernel {
40
38
  private promptAssemblyStats?;
41
39
  private diagnostics;
42
40
  private readonly progressController;
43
- private readonly stopController;
44
41
  private capabilityProfile;
45
42
  private capabilityHistory;
46
43
  private reconciledAt?;
@@ -51,12 +48,10 @@ export declare class HarnessKernel {
51
48
  observeGoalSteering(input: string, goalId: string): void;
52
49
  activeTaskTodo(): string | undefined;
53
50
  hasTaskTodos(): boolean;
54
- missingExecutionChecklist(action?: TaskWorkspaceAction): string | undefined;
51
+ deferredWorkspaceWriteReason(action: TaskWorkspaceAction): string | undefined;
55
52
  private checkDeferredWorkspaceAction;
56
- prepareTaskPlanStopCheck(): () => TaskPlanStop | undefined;
57
53
  private hasOnlyDeferredWork;
58
54
  private deferTaskTodos;
59
- requiresVerification(): boolean;
60
55
  recordTaskTodoReceipt(step: string, observation: TaskTodoObservation): void;
61
56
  updateTaskTodos(todos: TodoItem[], blockedReason?: string): TodoWriteAdjustment | string | undefined;
62
57
  private taskTodoId;
@@ -87,7 +82,6 @@ export declare class HarnessKernel {
87
82
  progressState(): HarnessProgressState;
88
83
  recordProgress(baseline?: HarnessProgressState, unconfirmedWorkspaceRevisions?: number): ProgressDelta;
89
84
  beforeComplete(enforceTaskTodos?: boolean, requireEveryCriterion?: boolean): CompletionGateResult;
90
- asCompletionBlockedMessage(result: CompletionGateResult): Message;
91
85
  asToolBlockedResult(result: DriftCheckResult): string;
92
86
  getCapsule(): ContextCapsule | undefined;
93
87
  linkEvidenceToCriterion(criterionId: string, evidenceRef: string): boolean;
@@ -7,7 +7,6 @@ const crypto_1 = require("crypto");
7
7
  const path_1 = require("path");
8
8
  const redaction_1 = require("../services/redaction");
9
9
  const tool_serializer_1 = require("../framework/tool-serializer");
10
- const stop_decision_1 = require("../framework/stop-decision");
11
10
  const verification_command_1 = require("../framework/verification-command");
12
11
  const assembler_1 = require("./assembler");
13
12
  const capability_profile_1 = require("./capability-profile");
@@ -21,7 +20,6 @@ const intent_1 = require("./intent");
21
20
  const ledger_1 = require("./ledger");
22
21
  const progress_controller_1 = require("./progress-controller");
23
22
  const state_1 = require("./state");
24
- const stop_controller_1 = require("./stop-controller");
25
23
  const task_checklist_1 = require("./task-checklist");
26
24
  const turn_summary_1 = require("./turn-summary");
27
25
  const verification_1 = require("./verification");
@@ -32,7 +30,6 @@ const DEFAULT_CONFIG = {
32
30
  maxRecentTurns: 8,
33
31
  evidenceBudgetRatio: 0.3,
34
32
  driftGuard: 'warn',
35
- completionGate: 'warn',
36
33
  };
37
34
  /** Canonical v0.1.9 task-state owner; ContextHarness remains a compatibility alias. */
38
35
  class HarnessKernel {
@@ -46,7 +43,6 @@ class HarnessKernel {
46
43
  this.ledger = new ledger_1.ContextLedger(state.ledger, state.workspaceRevision);
47
44
  this.verificationWorkspace = state.verificationWorkspace;
48
45
  this.capsule = state.capsule;
49
- this.completionBlockCount = state.completionBlockCount ?? 0;
50
46
  this.taskEpoch = state.taskEpoch ?? 1;
51
47
  this.goalTaskId = state.goalTaskId;
52
48
  this.goalVerificationBlocker = state.goalVerificationBlocker;
@@ -60,11 +56,7 @@ class HarnessKernel {
60
56
  byDescription.get(savedId) ?? savedId,
61
57
  ...receipt,
62
58
  ]);
63
- this.taskTodos = todos.map(todo => {
64
- return todo.status === 'completed' && this.missingTodoEvidence(todo)
65
- ? { ...todo, status: 'pending' }
66
- : todo;
67
- });
59
+ this.taskTodos = todos;
68
60
  this.rootObjective = state.rootObjective;
69
61
  this.activeInstruction = state.activeInstruction;
70
62
  this.intentHistory = state.intentHistory ?? [];
@@ -78,14 +70,12 @@ class HarnessKernel {
78
70
  this.promptAssemblyStats = state.promptAssemblyStats;
79
71
  this.diagnostics = state.diagnostics ?? [];
80
72
  this.progressController = new progress_controller_1.ProgressController(state.progressState);
81
- this.stopController = new stop_controller_1.StopController();
82
73
  this.capabilityProfile = state.capabilityProfile;
83
74
  this.capabilityHistory = state.capabilityHistory ?? [];
84
75
  this.reconciledAt = state.reconciledAt;
85
76
  this.updatedAt = state.updatedAt;
86
77
  }
87
78
  updateContractFromUserInput(input, goalTaskId) {
88
- this.reportedTaskBlocker = undefined;
89
79
  if (this.config.enabled === false)
90
80
  return;
91
81
  if (goalTaskId && this.goalTaskId === goalTaskId && this.contract)
@@ -124,7 +114,6 @@ class HarnessKernel {
124
114
  this.taskTodos = [];
125
115
  this.taskTodoReceipts.length = 0;
126
116
  this.goalVerificationBlocker = undefined;
127
- this.completionBlockCount = 0;
128
117
  this.activeConstraints = [];
129
118
  this.nonGoals = [];
130
119
  this.openQuestions = [];
@@ -241,18 +230,13 @@ class HarnessKernel {
241
230
  hasTaskTodos() {
242
231
  return this.taskTodos.length > 0;
243
232
  }
244
- missingExecutionChecklist(action) {
233
+ deferredWorkspaceWriteReason(action) {
245
234
  if (this.hasOnlyDeferredWork()) {
246
235
  return 'The user deferred the remaining steps. Wait for explicit continuation.';
247
236
  }
248
- if (action && this.taskTodos.some(todo => todo.deferredReason)) {
249
- const scoped = this.checkDeferredWorkspaceAction(action);
250
- if (scoped)
251
- return scoped;
237
+ if (this.taskTodos.some(todo => todo.deferredReason)) {
238
+ return this.checkDeferredWorkspaceAction(action);
252
239
  }
253
- if (!this.taskChecklistRequired)
254
- return undefined;
255
- return (0, task_checklist_1.executionChecklistIssue)(this.taskTodos, this.taskChecklistTargets, this.cwd);
256
240
  }
257
241
  checkDeferredWorkspaceAction(action) {
258
242
  const target = action.path ? (0, verification_1.workspaceArtifactPath)(this.cwd, action.path) : undefined;
@@ -273,19 +257,6 @@ class HarnessKernel {
273
257
  }
274
258
  return 'The user deferred part of the checklist. Use a file tool for the active step or run its required check before making other workspace changes.';
275
259
  }
276
- prepareTaskPlanStopCheck() {
277
- return () => {
278
- if (this.hasOnlyDeferredWork()) {
279
- return {
280
- code: 'task_deferred',
281
- message: 'The remaining checklist steps are deferred at your request. Say “continue” to resume them.',
282
- };
283
- }
284
- const blocker = this.reportedTaskBlocker;
285
- this.reportedTaskBlocker = undefined;
286
- return blocker;
287
- };
288
- }
289
260
  hasOnlyDeferredWork() {
290
261
  return (this.taskTodos.some(todo => todo.deferredReason) &&
291
262
  this.taskTodos.every(todo => todo.deferredReason || todo.status === 'completed'));
@@ -307,13 +278,6 @@ class HarnessKernel {
307
278
  this.refreshCapsule();
308
279
  this.touch();
309
280
  }
310
- requiresVerification() {
311
- if (this.config.enabled === false ||
312
- (this.config.completionGate !== 'block' && this.config.completionGate !== true))
313
- return false;
314
- return (this.contract?.criteria?.some(item => (0, verification_1.requiredVerificationKinds)(item.statement).length > 0) ||
315
- (0, drift_guard_1.hasExplicitVerificationNeed)(this.contract));
316
- }
317
281
  recordTaskTodoReceipt(step, observation) {
318
282
  const todo = this.taskTodos.find(item => item.status === 'in_progress');
319
283
  if (todo?.id !== step)
@@ -367,62 +331,48 @@ class HarnessKernel {
367
331
  const previousByRequest = new Map();
368
332
  if (requested.size !== todos.length)
369
333
  return 'Todo descriptions must be unique.';
370
- if (this.taskTodos.some(todo => todo.deferredReason) && todos.length > this.taskTodos.length) {
334
+ const hasDeferredTodos = this.taskTodos.some(todo => todo.deferredReason);
335
+ if (hasDeferredTodos && todos.length > this.taskTodos.length) {
371
336
  return 'The user deferred part of the checklist. Wait for their continuation before adding steps.';
372
337
  }
373
338
  for (const previous of this.taskTodos) {
374
339
  let replacement = requested.get(previous.content);
375
- if (!replacement && previous.status !== 'completed' && !previous.deferredReason) {
340
+ if (!replacement &&
341
+ !previous.deferredReason &&
342
+ (previous.status !== 'completed' || this.missingTodoEvidence(previous))) {
376
343
  const refinements = todos.filter(todo => !originalNames.has(todo.content) &&
377
344
  !previousByRequest.has(todo.content) &&
378
345
  (0, task_checklist_1.clarifiesTodoFileTarget)(previous, todo, this.cwd, this.taskChecklistTargets));
379
346
  if (refinements.length === 1)
380
347
  replacement = refinements[0];
381
348
  }
382
- if (!replacement)
383
- return `Keep the existing todo "${previous.content}" in the checklist.`;
384
- if (previous.deferredReason && replacement.status !== 'pending') {
349
+ if (previous.deferredReason && replacement?.status !== 'pending') {
385
350
  return `The user deferred "${previous.content}". Keep it pending until they explicitly continue.`;
386
351
  }
387
- if (previous.status === 'completed' &&
388
- replacement.status !== 'completed' &&
389
- !this.missingTodoEvidence(previous)) {
390
- return `Add a new todo for further work on "${previous.content}".`;
352
+ if (hasDeferredTodos && !replacement) {
353
+ return `Keep the existing todo "${previous.content}" while the user has deferred steps.`;
391
354
  }
392
- previousByRequest.set(replacement.content, previous);
355
+ if (replacement)
356
+ previousByRequest.set(replacement.content, previous);
393
357
  }
394
- const warnings = [];
395
- let hasIndependentUpdate = false;
396
- let triedToAdvanceActiveTodo = false;
397
358
  const next = todos.map(input => {
398
359
  const previous = previousByRequest.get(input.content);
399
- const todo = withTodoVerification(input, previous?.id ?? this.taskTodoId(input.content), previous);
400
- const missing = todo.status === 'completed' ? this.missingTodoEvidence(todo) : undefined;
401
- if (missing) {
402
- warnings.push(missing);
403
- triedToAdvanceActiveTodo || (triedToAdvanceActiveTodo = previous?.status === 'in_progress');
404
- return { ...todo, status: 'pending' };
405
- }
406
- hasIndependentUpdate || (hasIndependentUpdate = !previous ||
407
- previous.status !== todo.status ||
408
- previous.content !== todo.content ||
409
- previous.verification?.length !== todo.verification?.length);
410
- return todo;
360
+ return withTodoVerification(input, previous?.id ?? this.taskTodoId(input.content), previous);
411
361
  });
412
- // Keep the active step if it still needs evidence so its next tool call
413
- // can supply it. Repeated stale claims on inactive steps can stay pending.
414
- if (warnings.length && (triedToAdvanceActiveTodo || !hasIndependentUpdate)) {
415
- return warnings.join('\n');
416
- }
362
+ const warnings = [];
417
363
  if (blockedReason !== undefined) {
418
364
  const active = next.find(todo => todo.status === 'in_progress');
419
365
  if (!active || !blockedReason.trim())
420
366
  return 'Report the blocker on an active todo.';
421
- this.reportedTaskBlocker = {
422
- code: 'task_step_blocked',
423
- message: `Blocked at “${active.content}”. ${(0, redaction_1.redactTraceText)(blockedReason.trim())}`,
424
- };
367
+ warnings.push(`Reported blocker for “${active.content}”. ${(0, redaction_1.redactTraceText)(blockedReason.trim())}`);
368
+ }
369
+ for (const todo of next) {
370
+ const missing = todo.status === 'completed' ? this.missingTodoEvidence(todo) : undefined;
371
+ if (missing)
372
+ warnings.push(missing);
425
373
  }
374
+ const retained = new Set(next.map(todo => todo.id));
375
+ this.taskTodoReceipts = this.taskTodoReceipts.filter(([id]) => retained.has(id));
426
376
  this.taskTodos = next;
427
377
  this.touch();
428
378
  if (warnings.length) {
@@ -445,7 +395,6 @@ class HarnessKernel {
445
395
  const receipts = this.taskTodoReceipts.filter(([step]) => step === todo.id);
446
396
  const description = (0, redaction_1.redactTraceText)(todo.content);
447
397
  const problems = [];
448
- let missingChecks = [];
449
398
  const implementation = (0, task_checklist_1.isImplementationTodo)(todo);
450
399
  if (todo.verification?.length) {
451
400
  const expected = todoChecks(todo.content);
@@ -455,7 +404,7 @@ class HarnessKernel {
455
404
  result.workspaceRevision === this.ledger.workspaceRevision
456
405
  ? [result]
457
406
  : []);
458
- missingChecks = todo.verification.flatMap(kind => {
407
+ const missingChecks = todo.verification.flatMap(kind => {
459
408
  const selectors = expected.filter(check => check.kind === kind);
460
409
  if (selectors.length) {
461
410
  return selectors
@@ -467,7 +416,7 @@ class HarnessKernel {
467
416
  return [kind === 'diff' ? this.diffTodoCheckHint() : kind];
468
417
  });
469
418
  if (missingChecks.length) {
470
- problems.push('Run each check directly with exec_command while this todo is in progress.');
419
+ problems.push(`No matching passing check was recorded for ${missingChecks.join(', ')}.`);
471
420
  if (missingChecks.some(item => item.includes('git diff'))) {
472
421
  problems.push('A patch display only shows the changes. A compound shell call reports its overall result. A direct diff check records the verification receipt.');
473
422
  }
@@ -481,29 +430,20 @@ class HarnessKernel {
481
430
  !changedFiles.has(target.candidates[0]) &&
482
431
  [...changedFiles].some(path => (0, path_1.basename)(path) === target.declared)));
483
432
  if (needsClarification.length) {
484
- problems.push(`Clarify the exact workspace-relative path for ${needsClarification.map(target => target.declared).join(', ')} in this todo.`);
433
+ problems.push(`The workspace-relative path is ambiguous for ${needsClarification.map(target => target.declared).join(', ')}.`);
485
434
  }
486
435
  const remaining = targets.filter(target => !needsClarification.includes(target) &&
487
436
  (target.candidates.length !== 1 || !changedFiles.has(target.candidates[0])));
488
437
  if (remaining.length) {
489
438
  const paths = remaining.map(target => target.candidates[0] ?? target.declared).join(', ');
490
- problems.push(`Wait for verified file changes for: ${(0, redaction_1.redactTraceText)(paths)}.`);
439
+ problems.push(`No matching file change was recorded for ${(0, redaction_1.redactTraceText)(paths)}.`);
491
440
  }
492
441
  else if (!targets.length && !changedFiles.size) {
493
- problems.push('Record a successful workspace change for this step.');
442
+ problems.push('No successful workspace change was recorded for this step.');
494
443
  }
495
444
  }
496
- if (problems.length) {
497
- const required = missingChecks.length
498
- ? ` until its required checks pass: ${missingChecks.join(', ')}`
499
- : '';
500
- return `Keep "${description}" open${required}. ${problems.join(' ')}`;
501
- }
502
- if (implementation || todo.verification?.length)
503
- return undefined;
504
- if (receipts.some(([, , result]) => !result))
505
- return undefined;
506
- return `Keep "${description}" open until a successful tool receipt is recorded for that step.`;
445
+ if (problems.length)
446
+ return `"${description}" is unverified. ${problems.join(' ')}`;
507
447
  }
508
448
  formatTodoCheck(command, cwd) {
509
449
  const path = (0, path_1.relative)(this.cwd, (0, path_1.resolve)(this.cwd, cwd ?? '.'));
@@ -759,76 +699,20 @@ class HarnessKernel {
759
699
  };
760
700
  }
761
701
  if (enforceTaskTodos) {
762
- const checklist = this.missingExecutionChecklist();
763
- if (checklist)
764
- result.missing.push(checklist);
765
702
  for (const todo of this.taskTodos) {
766
- if (todo.status !== 'completed')
767
- result.missing.push(`Unfinished todo: ${todo.content}`);
703
+ const remaining = todo.status === 'completed'
704
+ ? this.missingTodoEvidence(todo)
705
+ : `Unfinished todo: ${todo.content}`;
706
+ if (remaining)
707
+ result.missing.push(remaining);
768
708
  }
769
- if (result.missing.length > 0)
770
- result.canComplete = false;
771
- }
772
- const goalBlocker = requireEveryCriterion ? this.goalVerificationBlocker : undefined;
773
- if (goalBlocker) {
774
- result.missing.push(goalBlocker);
775
- result.canComplete = false;
776
- }
777
- const progressDelta = this.recordProgress();
778
- result.progressDelta = progressDelta;
779
- const completion = this.stopController.decideCompletion(result, progressDelta);
780
- result.stopDecision = goalBlocker
781
- ? (0, stop_decision_1.createStopDecision)({
782
- ...completion,
783
- status: 'blocked',
784
- reason: { code: 'task_step_blocked', message: goalBlocker },
785
- nextActions: [
786
- {
787
- kind: 'resume',
788
- label: 'Resume and send the exact replacement check.',
789
- command: '/goal resume',
790
- },
791
- ],
792
- })
793
- : completion;
794
- const mode = this.config.completionGate === true
795
- ? 'block'
796
- : this.config.completionGate === false
797
- ? 'off'
798
- : (this.config.completionGate ?? 'warn');
799
- if (!result.canComplete && mode !== 'off') {
800
- this.ledger.add({
801
- type: mode === 'block' ? 'blocker' : 'risk',
802
- content: `Completion gate missing: ${result.missing.join('; ')}`,
803
- source: { kind: 'system', ref: 'completion_gate' },
804
- importance: 5,
805
- ttl: 'task',
806
- metadata: { missing: result.missing, mode },
807
- });
808
- this.refreshCapsule();
809
- this.touch();
810
- }
811
- // Block completion until evidence is provided. Track consecutive blocks
812
- // so callers can detect a stalled loop, but never silently pass the gate
813
- // without evidence.
814
- if (!result.canComplete && (mode === 'block' || requireEveryCriterion)) {
815
- this.completionBlockCount++;
816
- this.touch();
817
- return result;
818
709
  }
819
- if (result.canComplete) {
820
- const changed = this.completionBlockCount !== 0;
821
- this.completionBlockCount = 0;
822
- if (changed)
823
- this.touch();
710
+ if (requireEveryCriterion && this.goalVerificationBlocker) {
711
+ result.missing.push(this.goalVerificationBlocker);
824
712
  }
825
- return { ...result, canComplete: true };
826
- }
827
- asCompletionBlockedMessage(result) {
828
- return {
829
- role: 'user',
830
- content: `[Harness Completion Gate]\nThe task is not ready to finish.\nMissing:\n${result.missing.map(item => `- ${item}`).join('\n')}\nContinue working or explicitly explain why verification cannot be run.`,
831
- };
713
+ result.canComplete = result.missing.length === 0;
714
+ result.progressDelta = this.recordProgress();
715
+ return result;
832
716
  }
833
717
  asToolBlockedResult(result) {
834
718
  return JSON.stringify({
@@ -918,7 +802,6 @@ class HarnessKernel {
918
802
  workspaceRevision: this.ledger.workspaceRevision,
919
803
  ...(this.verificationWorkspace ? { verificationWorkspace: this.verificationWorkspace } : {}),
920
804
  capsule: this.capsule,
921
- completionBlockCount: this.completionBlockCount,
922
805
  taskEpoch: this.taskEpoch,
923
806
  ...(this.taskChecklistRequired ? { taskChecklistRequired: true } : {}),
924
807
  ...(this.taskChecklistTargets.length
@@ -995,9 +878,6 @@ class HarnessKernel {
995
878
  : criterion),
996
879
  };
997
880
  }
998
- this.taskTodos = this.taskTodos.map(todo => todo.status === 'completed' && todo.verification?.length && this.missingTodoEvidence(todo)
999
- ? { ...todo, status: 'pending' }
1000
- : todo);
1001
881
  }
1002
882
  autoLinkVerificationEvidence(entry) {
1003
883
  if (!this.contract?.criteria || !(0, verification_1.isTrustedEvidence)(entry))
@@ -1143,8 +1023,8 @@ function diffCheckSelector(command) {
1143
1023
  }
1144
1024
  function matchesTodoCheck(observed, check, workspace) {
1145
1025
  return (observed.kind === check.kind &&
1146
- observed.command === check.command &&
1147
- (!check.cwd || (0, path_1.resolve)(workspace, observed.cwd ?? '.') === (0, path_1.resolve)(workspace, check.cwd)));
1026
+ observed.command !== undefined &&
1027
+ (0, verification_1.matchesRequestedCheckInvocation)(observed.command, observed.cwd, check, workspace));
1148
1028
  }
1149
1029
  function sameTodoEvidenceTarget(previous, next) {
1150
1030
  if (!previous || !next)
@@ -131,7 +131,8 @@ class ContextLedger {
131
131
  const cwd = receipt?.cwd ?? cwdFromArgs(params.args);
132
132
  // Use summary when available to reduce evidence size
133
133
  const output = params.summary || parsed.error || params.error || parsed.output || params.result;
134
- const shell = params.name === 'exec_command' || params.name === 'bash';
134
+ const shell = (params.name === 'exec_command' || params.name === 'bash') &&
135
+ params.args.interactive !== true;
135
136
  // A production shell descriptor is conservatively write-capable. Its
136
137
  // individual invocation can still be a recognized read for task progress.
137
138
  const readOnly = params.readOnly === true || (shell && !!command && (0, bash_security_1.isReadOnlyCommand)(command));
@@ -3,6 +3,9 @@ interface TranscriptMessage {
3
3
  role: string;
4
4
  content: string;
5
5
  }
6
+ /** Matches feedback inserted by older runtimes as a synthetic user message. */
7
+ export declare function isLegacyCompletionFeedback(message: TranscriptMessage): boolean;
8
+ export declare function withoutLegacyGoalGate(content: string): string | undefined;
6
9
  export declare function upgradeHarnessState(state?: Partial<HarnessState> | null, options?: {
7
10
  cwd?: string;
8
11
  messages?: TranscriptMessage[];
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isLegacyCompletionFeedback = isLegacyCompletionFeedback;
4
+ exports.withoutLegacyGoalGate = withoutLegacyGoalGate;
3
5
  exports.upgradeHarnessState = upgradeHarnessState;
4
6
  exports.summarizeHarnessStateForMeta = summarizeHarnessStateForMeta;
5
7
  const capsule_1 = require("./capsule");
@@ -7,6 +9,19 @@ const clarification_1 = require("./clarification");
7
9
  const contract_1 = require("./contract");
8
10
  const evidence_1 = require("./evidence");
9
11
  const intent_1 = require("./intent");
12
+ /** Matches feedback inserted by older runtimes as a synthetic user message. */
13
+ function isLegacyCompletionFeedback(message) {
14
+ return (message.role === 'user' &&
15
+ message.content.startsWith('[Harness Completion Gate]\nThe task is not ready to finish.\nMissing:\n- ') &&
16
+ message.content.endsWith('\nContinue working or explicitly explain why verification cannot be run.'));
17
+ }
18
+ const legacyGoalGate = '\nDo not claim completion unless the TaskContext completion gate verifies every criterion.';
19
+ function withoutLegacyGoalGate(content) {
20
+ if (content.startsWith('Continue the active Goal using saved state and receipts.\nObjective: ') &&
21
+ content.endsWith(legacyGoalGate)) {
22
+ return content.slice(0, -legacyGoalGate.length);
23
+ }
24
+ }
10
25
  function unique(items) {
11
26
  return [...new Set(items.map(item => item.trim()).filter(Boolean))];
12
27
  }
@@ -27,13 +42,19 @@ function firstRealUserMessage(messages) {
27
42
  }
28
43
  function upgradeHarnessState(state, options = {}) {
29
44
  const now = Date.now();
30
- const ledger = state?.ledger ?? [];
45
+ const ledger = (state?.ledger ?? []).filter(entry => entry.source.kind !== 'system' || entry.source.ref !== 'completion_gate');
31
46
  const diagnostics = [...(state?.diagnostics ?? [])].filter(message => message !==
32
47
  'latest transcript user message differs from active instruction; using stored active instruction' &&
33
48
  message !==
34
49
  'root objective does not exactly match the first transcript user message; preserving harness root objective');
35
- const firstUser = firstRealUserMessage(options.messages);
36
- const lastUser = latestRealUserMessage(options.messages);
50
+ const recordedUserInputs = new Set([
51
+ state?.activeInstruction,
52
+ state?.contract?.userIntent,
53
+ ...ledger.filter(entry => entry.source.kind === 'user').map(entry => entry.content),
54
+ ]);
55
+ const messages = options.messages?.filter(message => !isLegacyCompletionFeedback(message) || recordedUserInputs.has(message.content));
56
+ const firstUser = firstRealUserMessage(messages);
57
+ const lastUser = latestRealUserMessage(messages);
37
58
  const explicitObjective = firstUser ? (0, contract_1.extractExplicitObjective)(firstUser) : undefined;
38
59
  const storedContract = state?.contract
39
60
  ? {
@@ -61,7 +82,13 @@ function upgradeHarnessState(state, options = {}) {
61
82
  (0, intent_1.shouldReplaceActiveInstruction)(intent) &&
62
83
  !(0, clarification_1.isReadOnlyQuestion)(intent.input))?.activeInstruction ?? rootObjective)
63
84
  : storedInstruction;
64
- const turnSummaries = state?.turnSummaries ?? [];
85
+ const turnSummaries = (state?.turnSummaries ?? []).map(summary => summary.assistantOutcome.startsWith('Completion gate stopped this turn: ')
86
+ ? {
87
+ ...summary,
88
+ assistantOutcome: 'The previous turn ended with incomplete verification.',
89
+ decisions: summary.decisions.filter(decision => decision !== summary.assistantOutcome),
90
+ }
91
+ : summary);
65
92
  const evidenceIndex = (0, evidence_1.buildEvidenceIndex)({
66
93
  ledger,
67
94
  turnSummaries,
@@ -72,6 +99,12 @@ function upgradeHarnessState(state, options = {}) {
72
99
  : contract || ledger.length > 0
73
100
  ? (0, capsule_1.createContextCapsule)(contract, ledger, state?.workspaceRevision)
74
101
  : undefined;
102
+ if (capsule?.verification) {
103
+ capsule.verification = {
104
+ ...capsule.verification,
105
+ warnings: capsule.verification.warnings.filter(warning => !warning.startsWith('Completion gate missing: ')),
106
+ };
107
+ }
75
108
  if (state && state.version !== 2) {
76
109
  diagnostics.push('upgraded legacy harness state to v2');
77
110
  }