@denizokcu/haze 0.9.0 → 0.11.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 (241) hide show
  1. package/CHANGELOG.md +133 -17
  2. package/README.md +164 -68
  3. package/SECURITY.md +22 -0
  4. package/bin/haze.js +102 -1
  5. package/dist/buildInfo.json +7 -0
  6. package/dist/cli/chat/TaskBar.d.ts +2 -1
  7. package/dist/cli/chat/TaskBar.js +7 -4
  8. package/dist/cli/chat/chatMetrics.d.ts +17 -1
  9. package/dist/cli/chat/chatMetrics.js +22 -5
  10. package/dist/cli/chat/contextReport.d.ts +11 -0
  11. package/dist/cli/chat/contextReport.js +46 -0
  12. package/dist/cli/chat/fileMentionSuggestions.d.ts +29 -0
  13. package/dist/cli/chat/fileMentionSuggestions.js +92 -0
  14. package/dist/cli/chat/inputSuggestions.d.ts +5 -0
  15. package/dist/cli/chat/inputSuggestions.js +17 -3
  16. package/dist/cli/chat/liveRegion.d.ts +25 -0
  17. package/dist/cli/chat/liveRegion.js +48 -0
  18. package/dist/cli/chat/messages.d.ts +33 -2
  19. package/dist/cli/chat/messages.js +216 -33
  20. package/dist/cli/chat/sessionLifecycle.d.ts +67 -0
  21. package/dist/cli/chat/sessionLifecycle.js +205 -0
  22. package/dist/cli/chat/sessionRecorder.js +80 -14
  23. package/dist/cli/chat/startupInfo.js +11 -4
  24. package/dist/cli/chat/tips.d.ts +21 -0
  25. package/dist/cli/chat/tips.js +43 -0
  26. package/dist/cli/chat/wizardDispatch.d.ts +64 -0
  27. package/dist/cli/chat/wizardDispatch.js +744 -0
  28. package/dist/cli/commands/chat.d.ts +6 -0
  29. package/dist/cli/commands/chat.js +373 -790
  30. package/dist/cli/commands/chatModes.d.ts +1 -1
  31. package/dist/cli/commands/chatModes.js +7 -2
  32. package/dist/cli/commands/commandHelp.js +5 -3
  33. package/dist/cli/commands/commands.d.ts +5 -2
  34. package/dist/cli/commands/commands.js +22 -18
  35. package/dist/cli/commands/doctor.d.ts +19 -0
  36. package/dist/cli/commands/doctor.js +76 -0
  37. package/dist/cli/commands/fleetCommand.d.ts +14 -0
  38. package/dist/cli/commands/fleetCommand.js +46 -0
  39. package/dist/cli/commands/formatters.d.ts +5 -0
  40. package/dist/cli/commands/formatters.js +35 -6
  41. package/dist/cli/commands/logsCommand.js +1 -7
  42. package/dist/cli/commands/modelCommand.js +1 -1
  43. package/dist/cli/commands/ndjsonSink.d.ts +23 -0
  44. package/dist/cli/commands/ndjsonSink.js +38 -0
  45. package/dist/cli/commands/providerWizard.d.ts +10 -2
  46. package/dist/cli/commands/providerWizard.js +50 -4
  47. package/dist/cli/commands/runCommand.d.ts +4 -0
  48. package/dist/cli/commands/runCommand.js +142 -16
  49. package/dist/cli/commands/sessionPicker.d.ts +9 -0
  50. package/dist/cli/commands/sessionPicker.js +29 -0
  51. package/dist/cli/commands/settingsSummary.js +6 -4
  52. package/dist/cli/commands/skillConfirmRemove.js +4 -3
  53. package/dist/cli/commands/skillWizard.d.ts +2 -0
  54. package/dist/cli/commands/skillWizard.js +16 -6
  55. package/dist/cli/commands/streaming/abortCause.d.ts +24 -0
  56. package/dist/cli/commands/streaming/abortCause.js +16 -0
  57. package/dist/cli/commands/streaming/assistantText.js +9 -2
  58. package/dist/cli/commands/streaming/goalCheckpoint.d.ts +65 -0
  59. package/dist/cli/commands/streaming/goalCheckpoint.js +23 -0
  60. package/dist/cli/commands/streaming/goalSupervisor.d.ts +64 -0
  61. package/dist/cli/commands/streaming/goalSupervisor.js +127 -0
  62. package/dist/cli/commands/streaming/idleTimer.d.ts +26 -0
  63. package/dist/cli/commands/streaming/idleTimer.js +24 -0
  64. package/dist/cli/commands/streaming/toolCallRecovery.d.ts +2 -0
  65. package/dist/cli/commands/streaming/toolCallRecovery.js +24 -0
  66. package/dist/cli/commands/streaming/toolGroupRenderer.d.ts +31 -0
  67. package/dist/cli/commands/streaming/toolGroupRenderer.js +50 -2
  68. package/dist/cli/commands/streaming/toolResultState.d.ts +6 -1
  69. package/dist/cli/commands/streaming/toolResultState.js +29 -7
  70. package/dist/cli/commands/streaming/turnOutcome.d.ts +17 -0
  71. package/dist/cli/commands/streaming/turnOutcome.js +27 -11
  72. package/dist/cli/commands/streaming/turnRuntime.js +6 -4
  73. package/dist/cli/commands/streaming.d.ts +82 -3
  74. package/dist/cli/commands/streaming.js +528 -91
  75. package/dist/cli/commands/wizardActions.d.ts +7 -0
  76. package/dist/cli/commands/wizardActions.js +7 -0
  77. package/dist/cli/commands/wizardPrompts.js +7 -1
  78. package/dist/cli/commands/wizardSuggestions.d.ts +8 -0
  79. package/dist/cli/commands/wizardSuggestions.js +64 -14
  80. package/dist/cli/commands/wizardTransition.d.ts +4 -0
  81. package/dist/cli/commands/wizardTransition.js +1 -2
  82. package/dist/cli/index.js +82 -22
  83. package/dist/cli/terminalTitle.d.ts +6 -0
  84. package/dist/cli/terminalTitle.js +36 -0
  85. package/dist/config/inputHistory.d.ts +3 -3
  86. package/dist/config/inputHistory.js +12 -18
  87. package/dist/config/modelDiscovery.d.ts +71 -0
  88. package/dist/config/modelDiscovery.js +214 -0
  89. package/dist/config/privateStorage.js +28 -2
  90. package/dist/config/providerAuth.d.ts +14 -0
  91. package/dist/config/providerAuth.js +49 -0
  92. package/dist/config/providerPresets.d.ts +49 -5
  93. package/dist/config/providerPresets.js +573 -73
  94. package/dist/config/providers.d.ts +2 -0
  95. package/dist/config/providers.js +9 -0
  96. package/dist/config/settings.d.ts +58 -0
  97. package/dist/config/settings.js +38 -1
  98. package/dist/config/skillSettings.d.ts +6 -13
  99. package/dist/config/skillSettings.js +20 -19
  100. package/dist/core/agent/budgets.d.ts +36 -0
  101. package/dist/core/agent/budgets.js +44 -0
  102. package/dist/core/agent/compaction.d.ts +38 -0
  103. package/dist/core/agent/compaction.js +108 -19
  104. package/dist/core/agent/completionController.d.ts +230 -0
  105. package/dist/core/agent/completionController.js +287 -0
  106. package/dist/core/agent/contextBudget.d.ts +46 -0
  107. package/dist/core/agent/contextBudget.js +89 -7
  108. package/dist/core/agent/errors.js +6 -2
  109. package/dist/core/agent/events.d.ts +86 -0
  110. package/dist/core/agent/reasoningPolicy.d.ts +31 -0
  111. package/dist/core/agent/reasoningPolicy.js +27 -0
  112. package/dist/core/agent/toolCapabilities.d.ts +27 -0
  113. package/dist/core/agent/toolCapabilities.js +58 -0
  114. package/dist/core/agent/toolExecutionBudget.d.ts +35 -0
  115. package/dist/core/agent/toolExecutionBudget.js +49 -0
  116. package/dist/core/agent/toolOutputStore.d.ts +13 -0
  117. package/dist/core/agent/toolOutputStore.js +27 -10
  118. package/dist/core/agent/toolResults.d.ts +12 -0
  119. package/dist/core/agent/toolResults.js +38 -0
  120. package/dist/core/agent/turnBudget.d.ts +35 -0
  121. package/dist/core/agent/turnBudget.js +27 -0
  122. package/dist/core/agent/turnPolicy.d.ts +11 -0
  123. package/dist/core/agent/turnPolicy.js +19 -0
  124. package/dist/core/agent/workState.d.ts +76 -1
  125. package/dist/core/agent/workState.js +120 -13
  126. package/dist/core/attachments/imageAttachments.d.ts +90 -0
  127. package/dist/core/attachments/imageAttachments.js +245 -0
  128. package/dist/core/attachments/readBlessings.d.ts +37 -0
  129. package/dist/core/attachments/readBlessings.js +79 -0
  130. package/dist/core/deadline.d.ts +33 -0
  131. package/dist/core/deadline.js +74 -0
  132. package/dist/core/goal/completionPolicy.d.ts +27 -0
  133. package/dist/core/goal/completionPolicy.js +37 -1
  134. package/dist/core/goal/requestClassifier.d.ts +0 -3
  135. package/dist/core/goal/requestClassifier.js +0 -13
  136. package/dist/core/io/boundedRead.js +76 -29
  137. package/dist/core/limits/byteBudgets.d.ts +7 -0
  138. package/dist/core/limits/byteBudgets.js +7 -0
  139. package/dist/core/limits/textBudgets.d.ts +25 -0
  140. package/dist/core/limits/textBudgets.js +25 -0
  141. package/dist/core/log/llmLog.js +7 -0
  142. package/dist/core/persistence/orderedFileWriter.d.ts +10 -0
  143. package/dist/core/persistence/orderedFileWriter.js +16 -2
  144. package/dist/core/process/backgroundRegistry.d.ts +35 -0
  145. package/dist/core/process/backgroundRegistry.js +195 -0
  146. package/dist/core/process/runBoundedProcess.d.ts +9 -0
  147. package/dist/core/process/runBoundedProcess.js +74 -29
  148. package/dist/core/safety/missingExecutable.d.ts +42 -0
  149. package/dist/core/safety/missingExecutable.js +77 -0
  150. package/dist/core/safety/urlGuard.d.ts +2 -1
  151. package/dist/core/safety/urlGuard.js +3 -2
  152. package/dist/core/session/sessionSlimming.js +47 -4
  153. package/dist/core/session/sessionStore.d.ts +74 -0
  154. package/dist/core/session/sessionStore.js +268 -18
  155. package/dist/core/subagent/contracts.d.ts +120 -0
  156. package/dist/core/subagent/contracts.js +55 -0
  157. package/dist/core/subagent/executionProfiles.d.ts +28 -0
  158. package/dist/core/subagent/executionProfiles.js +45 -0
  159. package/dist/core/subagent/subagentCoordinator.d.ts +78 -0
  160. package/dist/core/subagent/subagentCoordinator.js +164 -0
  161. package/dist/core/subagent/subagentRunner.d.ts +211 -145
  162. package/dist/core/subagent/subagentRunner.js +208 -98
  163. package/dist/core/subagent/workspaceMutationPolicy.d.ts +11 -0
  164. package/dist/core/subagent/workspaceMutationPolicy.js +52 -0
  165. package/dist/core/tasks/taskStorage.js +12 -1
  166. package/dist/llm/client.d.ts +36 -29
  167. package/dist/llm/client.js +102 -33
  168. package/dist/llm/hazeTools.d.ts +2559 -150
  169. package/dist/llm/hazeTools.js +119 -31
  170. package/dist/llm/lsp.d.ts +26 -4
  171. package/dist/llm/lsp.js +90 -14
  172. package/dist/llm/lspTools.d.ts +2366 -0
  173. package/dist/llm/lspTools.js +87 -79
  174. package/dist/llm/openaiCodex.d.ts +3 -0
  175. package/dist/llm/openaiCodex.js +47 -0
  176. package/dist/llm/openaiCodexOAuth.d.ts +54 -0
  177. package/dist/llm/openaiCodexOAuth.js +214 -0
  178. package/dist/llm/requestContext.d.ts +25 -1
  179. package/dist/llm/requestContext.js +51 -8
  180. package/dist/llm/systemPrompt.d.ts +15 -1
  181. package/dist/llm/systemPrompt.js +24 -8
  182. package/dist/llm/toolResultTypes.d.ts +8 -1
  183. package/dist/llm/tools/bashTool.d.ts +906 -32
  184. package/dist/llm/tools/bashTool.js +30 -4
  185. package/dist/llm/tools/editMatch.d.ts +14 -0
  186. package/dist/llm/tools/editMatch.js +72 -0
  187. package/dist/llm/tools/failures.d.ts +2 -0
  188. package/dist/llm/tools/failures.js +1 -0
  189. package/dist/llm/tools/fetchTool.d.ts +42 -26
  190. package/dist/llm/tools/fetchTool.js +1 -1
  191. package/dist/llm/tools/fileToolShared.d.ts +6 -4
  192. package/dist/llm/tools/fileToolShared.js +18 -23
  193. package/dist/llm/tools/gitIgnore.d.ts +49 -0
  194. package/dist/llm/tools/gitIgnore.js +129 -0
  195. package/dist/llm/tools/grepRunner.d.ts +5 -0
  196. package/dist/llm/tools/grepRunner.js +52 -71
  197. package/dist/llm/tools/outputCap.d.ts +2 -6
  198. package/dist/llm/tools/outputCap.js +2 -6
  199. package/dist/llm/tools/processTool.d.ts +1077 -0
  200. package/dist/llm/tools/processTool.js +41 -0
  201. package/dist/llm/tools/readRecovery.d.ts +10 -0
  202. package/dist/llm/tools/readRecovery.js +135 -0
  203. package/dist/llm/tools/toolContext.d.ts +9 -1
  204. package/dist/llm/tools/toolContext.js +83 -43
  205. package/dist/llm/tools/workspaceFile.d.ts +9 -1
  206. package/dist/llm/tools/workspaceFile.js +33 -4
  207. package/dist/llm/webFetch.d.ts +17 -0
  208. package/dist/llm/webFetch.js +66 -86
  209. package/dist/llm/workerContext.d.ts +18 -0
  210. package/dist/llm/workerContext.js +55 -0
  211. package/dist/skills/SkillLoader.d.ts +2 -2
  212. package/dist/skills/SkillRegistry.d.ts +3 -2
  213. package/dist/skills/SkillRegistry.js +43 -13
  214. package/dist/skills/builder/SkillBuilder.d.ts +3 -0
  215. package/dist/skills/builder/SkillBuilder.js +23 -5
  216. package/dist/skills/skillTools.js +11 -4
  217. package/dist/skills/types.d.ts +6 -1
  218. package/dist/ui/codeHighlight.d.ts +4 -0
  219. package/dist/ui/codeHighlight.js +31 -0
  220. package/dist/ui/components/Header.d.ts +1 -1
  221. package/dist/ui/components/MarkdownText.d.ts +16 -2
  222. package/dist/ui/components/MarkdownText.js +244 -34
  223. package/dist/ui/components/TextInput.d.ts +12 -2
  224. package/dist/ui/components/TextInput.js +80 -8
  225. package/dist/ui/theme.d.ts +4 -3
  226. package/dist/ui/theme.js +5 -4
  227. package/dist/utils/buildInfo.d.ts +104 -0
  228. package/dist/utils/buildInfo.js +253 -0
  229. package/dist/utils/format.d.ts +2 -0
  230. package/dist/utils/format.js +8 -0
  231. package/dist/utils/fs.d.ts +9 -1
  232. package/dist/utils/fs.js +87 -29
  233. package/dist/utils/openPath.d.ts +2 -0
  234. package/dist/utils/openPath.js +22 -0
  235. package/dist/utils/path.d.ts +2 -0
  236. package/dist/utils/path.js +5 -1
  237. package/dist/utils/utf8.d.ts +22 -0
  238. package/dist/utils/utf8.js +54 -0
  239. package/dist/utils/version.d.ts +9 -3
  240. package/dist/utils/version.js +28 -2
  241. package/package.json +24 -19
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Turn-wide budget envelope. Values are the existing global limits — recovery
3
+ * slices count against these and must never increase them.
4
+ */
5
+ export interface TurnBudget {
6
+ /** Maximum completed model steps across the whole turn (incl. recovery). */
7
+ stepLimit: number;
8
+ /** Maximum completed tool calls across the whole turn (incl. recovery). */
9
+ toolCallLimit: number;
10
+ /** Maximum completed tool-only steps across the whole turn. */
11
+ toolOnlyStepLimit: number;
12
+ }
13
+ export declare function mainTurnBudget(): TurnBudget;
14
+ /** Steps still available to the turn given usage so far (never negative). */
15
+ export declare function remainingSteps(used: number, budget: TurnBudget): number;
16
+ /** Tool calls still available to the turn given usage so far (never negative). */
17
+ export declare function remainingToolCalls(used: number, budget: TurnBudget): number;
18
+ /** True when adding `extra` tool calls would meet or exceed the call budget. */
19
+ export declare function wouldExceedToolCalls(used: number, extra: number, budget: TurnBudget): boolean;
20
+ /** A recovery slice can only run if at least one step and one tool call remain. */
21
+ export declare function hasUsableBudget(used: {
22
+ steps: number;
23
+ toolCalls: number;
24
+ }, budget: TurnBudget): boolean;
25
+ /** Clamp a requested slice size to what the turn budget actually allows. */
26
+ export declare function clampSlice(requested: {
27
+ steps: number;
28
+ toolCalls: number;
29
+ }, remaining: {
30
+ steps: number;
31
+ toolCalls: number;
32
+ }): {
33
+ steps: number;
34
+ toolCalls: number;
35
+ };
@@ -0,0 +1,27 @@
1
+ import { MAIN_STEP_LIMIT, MAIN_TOOL_CALL_LIMIT, MAIN_TOOL_ONLY_STEP_LIMIT } from './budgets.js';
2
+ export function mainTurnBudget() {
3
+ return { stepLimit: MAIN_STEP_LIMIT, toolCallLimit: MAIN_TOOL_CALL_LIMIT, toolOnlyStepLimit: MAIN_TOOL_ONLY_STEP_LIMIT };
4
+ }
5
+ /** Steps still available to the turn given usage so far (never negative). */
6
+ export function remainingSteps(used, budget) {
7
+ return Math.max(0, budget.stepLimit - used);
8
+ }
9
+ /** Tool calls still available to the turn given usage so far (never negative). */
10
+ export function remainingToolCalls(used, budget) {
11
+ return Math.max(0, budget.toolCallLimit - used);
12
+ }
13
+ /** True when adding `extra` tool calls would meet or exceed the call budget. */
14
+ export function wouldExceedToolCalls(used, extra, budget) {
15
+ return used + extra >= budget.toolCallLimit;
16
+ }
17
+ /** A recovery slice can only run if at least one step and one tool call remain. */
18
+ export function hasUsableBudget(used, budget) {
19
+ return used.steps < budget.stepLimit && used.toolCalls < budget.toolCallLimit;
20
+ }
21
+ /** Clamp a requested slice size to what the turn budget actually allows. */
22
+ export function clampSlice(requested, remaining) {
23
+ return {
24
+ steps: Math.max(0, Math.min(requested.steps, remaining.steps)),
25
+ toolCalls: Math.max(0, Math.min(requested.toolCalls, remaining.toolCalls)),
26
+ };
27
+ }
@@ -2,6 +2,17 @@ export declare function uniqueRepeatedToolNames(toolCalls: Array<{
2
2
  toolName: string;
3
3
  input: unknown;
4
4
  }>): string[];
5
+ /**
6
+ * Return tool names whose latest-step calls repeat an earlier identical call.
7
+ * Restricting only the immediately following step prevents one duplicate from
8
+ * disabling an entire tool category for the rest of the turn.
9
+ */
10
+ export declare function latestRepeatedToolNames(steps: Array<{
11
+ toolCalls: Array<{
12
+ toolName: string;
13
+ input: unknown;
14
+ }>;
15
+ }>): string[];
5
16
  export declare function toolOnlyStepCount(steps: Array<{
6
17
  toolCalls: unknown[];
7
18
  text: string;
@@ -12,6 +12,25 @@ export function uniqueRepeatedToolNames(toolCalls) {
12
12
  }
13
13
  return [...repeated];
14
14
  }
15
+ /**
16
+ * Return tool names whose latest-step calls repeat an earlier identical call.
17
+ * Restricting only the immediately following step prevents one duplicate from
18
+ * disabling an entire tool category for the rest of the turn.
19
+ */
20
+ export function latestRepeatedToolNames(steps) {
21
+ const latest = steps.at(-1);
22
+ if (!latest)
23
+ return [];
24
+ const seen = new Set(steps.slice(0, -1).flatMap(step => step.toolCalls).map(stableToolKey));
25
+ const repeated = new Set();
26
+ for (const toolCall of latest.toolCalls) {
27
+ const key = stableToolKey(toolCall);
28
+ if (seen.has(key))
29
+ repeated.add(toolCall.toolName);
30
+ seen.add(key);
31
+ }
32
+ return [...repeated];
33
+ }
15
34
  export function toolOnlyStepCount(steps) {
16
35
  let count = 0;
17
36
  for (const step of [...steps].reverse()) {
@@ -1,8 +1,20 @@
1
1
  import type { RequestIntent } from '../goal/requestClassifier.js';
2
+ import { type ValidationKind, type ValidationSummary } from '../../llm/toolResultTypes.js';
2
3
  export type WorkFileAction = 'read' | 'created' | 'modified';
3
4
  export type WorkValidationStatus = 'pending' | 'passed' | 'failed';
4
5
  export type WorkStatus = 'active' | 'needs-user' | 'blocked' | 'complete' | 'aborted';
5
6
  export type WorkPhase = 'starting' | 'inspecting' | 'editing' | 'validating' | 'summarizing' | 'done';
7
+ /**
8
+ * Derived validation outcome for a turn, used as bounded completion evidence.
9
+ * - `passed`: a classifier-confirmed validation passed after the latest mutation.
10
+ * - `failed`: a validation failed and is the most recent result.
11
+ * - `stale`: a validation ran but predates the latest mutation (no longer trustworthy).
12
+ * - `absent`: validation was expected for this request but never ran.
13
+ * - `not_applicable`: the request does not call for validation (answer/review/plan).
14
+ */
15
+ export type ValidationOutcome = 'passed' | 'failed' | 'stale' | 'absent' | 'not_applicable';
16
+ /** Request intents where a missing validation is itself meaningful evidence. */
17
+ export declare function intentExpectsValidation(intent: RequestIntent): boolean;
6
18
  export interface WorkState {
7
19
  id: string;
8
20
  goal: string;
@@ -25,20 +37,75 @@ export interface WorkState {
25
37
  command: string;
26
38
  status: Exclude<WorkValidationStatus, 'pending'>;
27
39
  summary: string;
40
+ kind?: ValidationKind;
28
41
  }>;
29
42
  validationCommands: Array<{
30
43
  command: string;
31
44
  status: WorkValidationStatus;
32
45
  }>;
46
+ /** Number of successful workspace mutations observed this turn. */
47
+ mutationCount: number;
48
+ /** Monotonic sequence number of the latest successful mutation (0 = none). */
49
+ mutationSeq: number;
50
+ /** Monotonic sequence number of the latest validation (0 = none). */
51
+ validationSeq: number;
52
+ /**
53
+ * Current-turn task-list evidence, recorded only from a successful `writeTasks`
54
+ * result. Counts only — never task titles or raw output — so malformed tool
55
+ * output can never fabricate or erase completion evidence. Absent when the
56
+ * turn never declared a task list (a stale workspace tasks.json from an
57
+ * earlier turn must not block completion).
58
+ */
59
+ taskProgress?: WorkTaskProgress;
60
+ /**
61
+ * Validation evidence carried from earlier physical turns of the same
62
+ * logical goal (see the goal supervisor). Used by `deriveValidationOutcome`
63
+ * only while this turn itself has recorded no validation; a fresh
64
+ * validation this turn supersedes it. Bounded to status/kind — never a
65
+ * command or output.
66
+ */
67
+ carriedValidation?: {
68
+ status: 'passed' | 'failed';
69
+ kind?: ValidationKind;
70
+ };
71
+ /** Single source of truth for blockers; the most recent entry is the current one (CR-023). */
33
72
  blockers: string[];
34
73
  pending: string[];
35
74
  nextAction?: string;
36
75
  status: WorkStatus;
37
76
  phase: WorkPhase;
38
- blocker?: string;
39
77
  lastProgressAt: number;
40
78
  revision: number;
41
79
  }
80
+ /** Compact current-turn task-list evidence parsed from a successful `writeTasks` result. */
81
+ export interface WorkTaskProgress {
82
+ total: number;
83
+ pending: number;
84
+ inProgress: number;
85
+ completed: number;
86
+ /** WorkState revision when this snapshot was recorded. */
87
+ revision: number;
88
+ }
89
+ /**
90
+ * Extract bounded task counts from a successful `writeTasks` structured result.
91
+ * Parses only numeric counts (`taskCount`, `counts.pending/in_progress/completed`),
92
+ * never titles or raw output. A non-empty list without a fully valid counts
93
+ * breakdown is ignored (rather than guessed) so partial shapes stay inert.
94
+ */
95
+ export declare function taskProgressFromOutput(output: unknown, revision: number): WorkTaskProgress | undefined;
96
+ /**
97
+ * Seed a fresh per-turn work state with cumulative evidence from earlier
98
+ * physical turns of the same logical goal, so a new turn cannot complete while
99
+ * previously-declared tasks remain or previously-made edits still lack fresh
100
+ * validation. Seq baselines keep `deriveValidationOutcome` truthful across the
101
+ * boundary: a carried `stale`/`absent` outcome keeps demanding validation, a
102
+ * carried `passed`/`failed` outcome stands until this turn mutates or validates.
103
+ */
104
+ export declare function seedCarriedGoalEvidence(state: WorkState, carried: {
105
+ mutationCount: number;
106
+ validationOutcome: ValidationOutcome;
107
+ taskProgress?: WorkTaskProgress;
108
+ }): void;
42
109
  export interface WorkToolEvent {
43
110
  toolName: string;
44
111
  input?: unknown;
@@ -46,6 +113,14 @@ export interface WorkToolEvent {
46
113
  output?: unknown;
47
114
  duplicateSkipped?: boolean;
48
115
  }
116
+ /** Extract a classifier-confirmed validation summary from a tool output, if any. */
117
+ export declare function validationSummaryFromOutput(output: unknown): ValidationSummary | undefined;
49
118
  export declare function createWorkState(goal: string, intent: RequestIntent, successCriteria: string[], now?: number): WorkState;
50
119
  export declare function observeWorkToolEvent(state: WorkState, event: WorkToolEvent, now?: number): WorkState;
120
+ /**
121
+ * Derive the bounded validation outcome for completion evidence.
122
+ * See `ValidationOutcome` for the contract. Honors mutation/validation
123
+ * ordering so a result that predates the latest mutation is `stale`.
124
+ */
125
+ export declare function deriveValidationOutcome(state: WorkState): ValidationOutcome;
51
126
  export declare function workStatePrompt(state: WorkState): string;
@@ -1,4 +1,66 @@
1
+ import { isValidationSummary } from '../../llm/toolResultTypes.js';
1
2
  import { toolInputField, toolOutputOk } from './toolResults.js';
3
+ /** Request intents where a missing validation is itself meaningful evidence. */
4
+ export function intentExpectsValidation(intent) {
5
+ return intent === 'implement' || intent === 'fix' || intent === 'test';
6
+ }
7
+ /** Upper bound for parsed task counts; anything larger is treated as malformed. */
8
+ const TASK_COUNT_LIMIT = 10_000;
9
+ function boundedTaskCount(value) {
10
+ if (typeof value === 'number' && Number.isInteger(value) && value >= 0 && value <= TASK_COUNT_LIMIT)
11
+ return value;
12
+ if (typeof value === 'string' && /^(0|[1-9]\d{0,4})$/.test(value))
13
+ return Number(value);
14
+ return undefined;
15
+ }
16
+ /**
17
+ * Extract bounded task counts from a successful `writeTasks` structured result.
18
+ * Parses only numeric counts (`taskCount`, `counts.pending/in_progress/completed`),
19
+ * never titles or raw output. A non-empty list without a fully valid counts
20
+ * breakdown is ignored (rather than guessed) so partial shapes stay inert.
21
+ */
22
+ export function taskProgressFromOutput(output, revision) {
23
+ if (typeof output !== 'object' || output == null)
24
+ return undefined;
25
+ const candidate = output;
26
+ if (candidate.ok !== true)
27
+ return undefined;
28
+ const total = boundedTaskCount(candidate.taskCount);
29
+ if (total === undefined)
30
+ return undefined;
31
+ if (total === 0)
32
+ return { total: 0, pending: 0, inProgress: 0, completed: 0, revision };
33
+ if (typeof candidate.counts !== 'object' || candidate.counts === null)
34
+ return undefined;
35
+ const counts = candidate.counts;
36
+ const pending = boundedTaskCount(counts.pending);
37
+ const inProgress = boundedTaskCount(counts.in_progress);
38
+ const completed = boundedTaskCount(counts.completed);
39
+ if (pending === undefined || inProgress === undefined || completed === undefined)
40
+ return undefined;
41
+ return { total, pending, inProgress, completed, revision };
42
+ }
43
+ /**
44
+ * Seed a fresh per-turn work state with cumulative evidence from earlier
45
+ * physical turns of the same logical goal, so a new turn cannot complete while
46
+ * previously-declared tasks remain or previously-made edits still lack fresh
47
+ * validation. Seq baselines keep `deriveValidationOutcome` truthful across the
48
+ * boundary: a carried `stale`/`absent` outcome keeps demanding validation, a
49
+ * carried `passed`/`failed` outcome stands until this turn mutates or validates.
50
+ */
51
+ export function seedCarriedGoalEvidence(state, carried) {
52
+ if (carried.taskProgress && carried.taskProgress.total > 0) {
53
+ state.taskProgress = { ...carried.taskProgress, revision: 1 };
54
+ }
55
+ if (carried.mutationCount > 0) {
56
+ state.mutationCount = carried.mutationCount;
57
+ state.mutationSeq = 1;
58
+ }
59
+ if (carried.validationOutcome === 'passed' || carried.validationOutcome === 'failed') {
60
+ state.validationSeq = 1;
61
+ state.carriedValidation = carried.validationOutcome === 'passed' ? { status: 'passed' } : { status: 'failed' };
62
+ }
63
+ }
2
64
  function upsertFile(state, path, action, note) {
3
65
  const existing = state.files.find(file => file.path === path);
4
66
  if (existing) {
@@ -25,18 +87,25 @@ function outputSummary(output) {
25
87
  return `exit ${String(output.code)}`;
26
88
  return '';
27
89
  }
28
- function upsertValidation(state, command, status, summary) {
90
+ function upsertValidation(state, command, status, summary, kind) {
29
91
  const existing = state.validations.find(validation => validation.command === command);
30
92
  if (existing)
31
- Object.assign(existing, { status, summary });
93
+ Object.assign(existing, { status, summary, ...(kind ? { kind } : {}) });
32
94
  else
33
- state.validations.push({ command, status, summary });
95
+ state.validations.push({ command, status, summary, ...(kind ? { kind } : {}) });
34
96
  const existingCommand = state.validationCommands.find(item => item.command === command);
35
97
  if (existingCommand)
36
98
  existingCommand.status = status;
37
99
  else
38
100
  state.validationCommands.push({ command, status });
39
101
  }
102
+ /** Extract a classifier-confirmed validation summary from a tool output, if any. */
103
+ export function validationSummaryFromOutput(output) {
104
+ if (typeof output !== 'object' || output == null)
105
+ return undefined;
106
+ const candidate = output.validationSummary;
107
+ return isValidationSummary(candidate) ? candidate : undefined;
108
+ }
40
109
  export function createWorkState(goal, intent, successCriteria, now = Date.now()) {
41
110
  return {
42
111
  id: `goal-${now}-${Math.random().toString(36).slice(2)}`,
@@ -51,6 +120,9 @@ export function createWorkState(goal, intent, successCriteria, now = Date.now())
51
120
  touchedFiles: [],
52
121
  validations: [],
53
122
  validationCommands: [],
123
+ mutationCount: 0,
124
+ mutationSeq: 0,
125
+ validationSeq: 0,
54
126
  blockers: [],
55
127
  pending: [],
56
128
  status: 'active',
@@ -64,6 +136,9 @@ export function observeWorkToolEvent(state, event, now = Date.now()) {
64
136
  return state;
65
137
  const ok = toolOutputOk(event.output, event.success);
66
138
  const path = toolInputField(event.input, 'path');
139
+ // Monotonic turn-wide clock. mutationSeq/validationSeq snapshot this value so
140
+ // a validation that predates the latest mutation can be marked stale.
141
+ const seq = state.revision + 1;
67
142
  if (ok && path && ['listFiles', 'readFile', 'grep'].includes(event.toolName)) {
68
143
  if (event.toolName === 'readFile')
69
144
  upsertFile(state, path, 'read');
@@ -77,32 +152,64 @@ export function observeWorkToolEvent(state, event, now = Date.now()) {
77
152
  state.phase = 'editing';
78
153
  state.lastProgressAt = now;
79
154
  state.blockers = state.blockers.filter(blocker => !blocker.includes(path));
80
- if (state.blocker?.includes(path))
81
- state.blocker = undefined;
155
+ state.mutationCount += 1;
156
+ state.mutationSeq = seq;
82
157
  }
83
158
  else {
84
- state.blocker = `File edit failed for ${path}; recovery read is required before retry.`;
85
159
  state.blockers = [...new Set([...state.blockers, `Edit failed for ${path}: ${outputSummary(event.output) || 'fresh read required'}`])];
86
160
  state.nextAction = `Read ${path}, then retry the edit with current content.`;
87
161
  }
88
162
  }
163
+ // Only a classifier-confirmed bash command is a validation step. An arbitrary
164
+ // shell call (inspection, mkdir, echo) is process work, not validation; the
165
+ // bash tool embeds a `validationSummary` exactly when the classifier says so.
89
166
  if (event.toolName === 'bash') {
90
167
  const command = toolInputField(event.input, 'command');
91
- if (command) {
92
- const status = ok ? 'passed' : 'failed';
93
- const summary = outputSummary(event.output);
94
- upsertValidation(state, command, status, summary);
168
+ const summary = validationSummaryFromOutput(event.output);
169
+ if (command && summary) {
170
+ const status = summary.status === 'passed' ? 'passed' : 'failed';
171
+ upsertValidation(state, command, status, summary.summaryText, summary.kind);
172
+ state.validationSeq = seq;
95
173
  state.phase = 'validating';
96
174
  state.lastProgressAt = now;
97
- if (!ok) {
98
- state.blocker = `Validation command failed: ${command}`;
175
+ if (status === 'failed') {
99
176
  state.blockers = [...new Set([...state.blockers, `Validation failed: ${command}`])];
100
177
  }
101
178
  }
102
179
  }
103
- state.revision += 1;
180
+ // Task-list coordination: a successful writeTasks result records bounded
181
+ // current-turn task counts as completion evidence. It is not a file mutation,
182
+ // and a failed call leaves prior evidence untouched.
183
+ if (ok && event.toolName === 'writeTasks') {
184
+ const progress = taskProgressFromOutput(event.output, seq);
185
+ if (progress) {
186
+ state.taskProgress = progress;
187
+ state.lastProgressAt = now;
188
+ }
189
+ }
190
+ state.revision = seq;
104
191
  return state;
105
192
  }
193
+ /**
194
+ * Derive the bounded validation outcome for completion evidence.
195
+ * See `ValidationOutcome` for the contract. Honors mutation/validation
196
+ * ordering so a result that predates the latest mutation is `stale`.
197
+ */
198
+ export function deriveValidationOutcome(state) {
199
+ const hasValidation = state.validationSeq > 0;
200
+ if (!hasValidation) {
201
+ return intentExpectsValidation(state.normalizedIntent) ? 'absent' : 'not_applicable';
202
+ }
203
+ // A validation is stale when a mutation happened after it. `mutationSeq === 0`
204
+ // means no mutation occurred (e.g. a pure test/run request), so the latest
205
+ // validation stands on its own. With no validation this turn, a carried
206
+ // outcome from an earlier physical turn of the same logical goal stands in.
207
+ const stale = state.mutationSeq > 0 && state.validationSeq < state.mutationSeq;
208
+ if (stale)
209
+ return 'stale';
210
+ const latest = state.validations.at(-1) ?? state.carriedValidation;
211
+ return latest?.status === 'passed' ? 'passed' : 'failed';
212
+ }
106
213
  export function workStatePrompt(state) {
107
214
  return `<work_state>\n${JSON.stringify(state)}\n</work_state>`;
108
215
  }
@@ -0,0 +1,90 @@
1
+ import type { ModelMessage } from 'ai';
2
+ /**
3
+ * User-attached images for one prompt (F03).
4
+ *
5
+ * Attachments are resolved from `@path` mentions typed by the user in the
6
+ * interactive chat: host-path allowed (workspace-relative, absolute, or `~/`),
7
+ * real-path deduped, extension-allowlisted, byte-bounded. The module is UI-
8
+ * and provider-agnostic (constitution VI): the capability gate takes the
9
+ * provider shape explicitly, never settings I/O.
10
+ */
11
+ /** Extension allowlist → media type. Only these image kinds can be attached. */
12
+ export declare const IMAGE_MEDIA_TYPES: Readonly<Record<string, string>>;
13
+ export declare const IMAGE_EXTENSIONS: string[];
14
+ export interface ImageAttachment {
15
+ /** Display path: workspace-relative inside the project, `~/…` under the home directory, absolute otherwise. */
16
+ displayPath: string;
17
+ absolutePath: string;
18
+ fileName: string;
19
+ mediaType: string;
20
+ bytes: number;
21
+ data: Uint8Array;
22
+ }
23
+ export interface ResolvedImageAttachments {
24
+ /** Prompt text with attached mentions removed. */
25
+ text: string;
26
+ attachments: ImageAttachment[];
27
+ }
28
+ export interface PathMention {
29
+ /** Full match as it appears in the prompt (`@path` for explicit mentions, the path itself for bare). */
30
+ mention: string;
31
+ /** The path token after the `@`, or the bare path itself. */
32
+ token: string;
33
+ }
34
+ /**
35
+ * Extract path-like attachment candidates from prompt text. Two forms are
36
+ * recognised:
37
+ *
38
+ * - Explicit `@token` mentions: any path-like token after `@`. A candidate
39
+ * must contain a `.` or `/` so bare handles (`@here`) are skipped.
40
+ * - Bare paths: a token that ends in an allowlisted image extension AND
41
+ * contains `/`. The separator keeps prose like "I named it cat.png" out;
42
+ * the existence check during resolution is the final gate.
43
+ *
44
+ * Whether a candidate is really an attachment is decided during resolution.
45
+ */
46
+ export declare function extractPathMentions(text: string): PathMention[];
47
+ /**
48
+ * Resolve `@path` mentions into image attachments.
49
+ *
50
+ * - Mentions that do not resolve to an existing file stay literal
51
+ * prompt text (emails, handles, typos) — no error.
52
+ * - Existing paths with a non-image extension stay literal text too; the
53
+ * read-blessing resolver picks them up so the model can `readFile` them.
54
+ * - Existing image-extension paths that are not regular files (e.g. a
55
+ * directory named `foo.png`) fail loudly — that is a genuine attach-intent
56
+ * mismatch, not silent drop.
57
+ * - An `@` mention is an explicit user-typed reference, so any host path
58
+ * works: workspace-relative (including `../`), absolute, or `~/`. The real
59
+ * path dedupes aliases (symlinks, `..` segments) instead of confining
60
+ * reads; `.gitignore` is not enforced here (documented in AGENTS.md).
61
+ * - Size and per-message count are bounded by named limits; errors name them.
62
+ * - The same file mentioned twice is attached once; both mentions are stripped.
63
+ */
64
+ export declare function resolveImageAttachments(text: string): Promise<ResolvedImageAttachments>;
65
+ /** Build the turn's user message: plain string without attachments, multipart with. */
66
+ export declare function userTurnMessage(text: string, attachments: readonly ImageAttachment[]): ModelMessage;
67
+ /** Minimal prompt text used when a message contains only images. */
68
+ export declare const IMAGE_ONLY_PROMPT_TEXT = "See the attached image.";
69
+ /** Minimal provider shape the capability gate needs (no settings I/O). */
70
+ export interface ImageCapableProviderLike {
71
+ name: string;
72
+ capabilities?: {
73
+ images?: boolean;
74
+ };
75
+ }
76
+ /**
77
+ * Loud capability gate (constitution VII): images only go to providers the
78
+ * user explicitly marked image-capable. Returns undefined when the provider
79
+ * may receive image parts, otherwise an actionable error message.
80
+ */
81
+ export declare function imageCapabilityError(provider: ImageCapableProviderLike | undefined): string | undefined;
82
+ /** Guard for AI SDK `file` parts carrying images, in any message role. */
83
+ export declare function isImageFilePart(value: unknown): value is {
84
+ type: 'file';
85
+ mediaType: string;
86
+ data?: unknown;
87
+ filename?: unknown;
88
+ };
89
+ /** Byte size of a file part's data without serializing it. */
90
+ export declare function imageFilePartBytes(data: unknown): number;