minicode-ai 0.27.0 → 0.30.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 (145) hide show
  1. package/README.md +1 -1
  2. package/cli/args.ts +184 -57
  3. package/cli/bootstrap/presentation-bridge.ts +383 -0
  4. package/cli/commands/acp.ts +45 -29
  5. package/cli/commands/auth.ts +17 -17
  6. package/cli/commands/config.ts +65 -66
  7. package/cli/commands/daemon.ts +44 -16
  8. package/cli/commands/doctor.ts +18 -15
  9. package/cli/commands/exec.ts +41 -89
  10. package/cli/commands/mcp.ts +25 -8
  11. package/cli/commands/memory.ts +16 -24
  12. package/cli/commands/openwork.ts +6 -2
  13. package/cli/commands/pricing.ts +14 -12
  14. package/cli/commands/providers.ts +36 -57
  15. package/cli/commands/sessions.ts +24 -18
  16. package/cli/commands/skills.ts +33 -18
  17. package/cli/commands/stats.ts +15 -30
  18. package/cli/commands.ts +73 -44
  19. package/cli/context-command-run.ts +30 -18
  20. package/cli/index.ts +51 -100
  21. package/cli/model-manager.ts +7 -2
  22. package/cli/provider-manager.ts +33 -18
  23. package/cli/router.ts +41 -12
  24. package/cli/setup.ts +241 -485
  25. package/cli/tui.ts +303 -100
  26. package/docs/TERMINAL_CONTRACT.md +258 -73
  27. package/docs/UI_RENDER_PIPELINE.md +9 -1
  28. package/docs/agents.md +2 -2
  29. package/docs/architecture.md +17 -32
  30. package/docs/choosing-mode.md +7 -9
  31. package/docs/cli.md +3 -5
  32. package/docs/environment.md +1 -2
  33. package/docs/policy-sandbox.md +3 -3
  34. package/docs/repl.md +2 -2
  35. package/docs/tools.md +1 -1
  36. package/package.json +1 -1
  37. package/src/app/mentions.ts +60 -13
  38. package/src/app/rag-layer.ts +17 -20
  39. package/src/app/session.ts +144 -68
  40. package/src/app/tool-layer.ts +38 -16
  41. package/src/config.ts +64 -104
  42. package/src/constants.ts +4 -6
  43. package/src/daemon/capability.ts +8 -1
  44. package/src/daemon/control.ts +3 -2
  45. package/src/daemon/server.ts +57 -0
  46. package/src/hooks/run.ts +73 -41
  47. package/src/lib/atomic-write.ts +31 -59
  48. package/src/lib/db-path.ts +47 -0
  49. package/src/lib/process-tree.ts +62 -0
  50. package/src/lib/public-http.ts +88 -23
  51. package/src/lib/trusted-exec.ts +48 -1
  52. package/src/lsp/client.ts +62 -17
  53. package/src/mcp/client.ts +85 -38
  54. package/src/mcp/http-transport.ts +28 -16
  55. package/src/mcp/transport.ts +42 -6
  56. package/src/memory/files.ts +164 -134
  57. package/src/memory/vector.ts +371 -420
  58. package/src/policy/approval-binding.ts +122 -45
  59. package/src/policy/bash-guard.ts +18 -7
  60. package/src/policy/compaction.ts +51 -18
  61. package/src/policy/context-window.ts +31 -8
  62. package/src/policy/context.ts +62 -36
  63. package/src/policy/executor.ts +17 -7
  64. package/src/policy/jail.ts +6 -8
  65. package/src/policy/microcompact.ts +4 -3
  66. package/src/policy/no-progress.ts +103 -22
  67. package/src/policy/permission.ts +36 -12
  68. package/src/policy/tool-contract.ts +74 -416
  69. package/src/policy/usage.ts +24 -2
  70. package/src/policy/verifier.ts +50 -2
  71. package/src/policy/work-mode.ts +28 -54
  72. package/src/presentation/adapter.ts +24 -16
  73. package/src/providers/anthropic.ts +16 -5
  74. package/src/providers/provision.ts +6 -56
  75. package/src/providers/responses.ts +38 -7
  76. package/src/providers/sse-bounds.ts +6 -4
  77. package/src/runtime/execution-journal.ts +4 -29
  78. package/src/sandbox/docker.ts +58 -34
  79. package/src/sandbox/mask.ts +157 -0
  80. package/src/sandbox/os.ts +107 -73
  81. package/src/session/authority.ts +29 -10
  82. package/src/session/context-projection.ts +6 -5
  83. package/src/session/db/runs.ts +397 -0
  84. package/src/session/db/schema.ts +358 -0
  85. package/src/session/open-work.ts +26 -3
  86. package/src/session/persistence.ts +74 -998
  87. package/src/session/verification.ts +170 -20
  88. package/src/skills/loader.ts +31 -16
  89. package/src/task/db/schema.ts +325 -0
  90. package/src/task/db/types.ts +269 -0
  91. package/src/task/production-scheduler.ts +13 -1
  92. package/src/task/store.ts +92 -1021
  93. package/src/telemetry/trace.ts +27 -0
  94. package/src/tools/ask_user.ts +1 -13
  95. package/src/tools/bash.ts +27 -92
  96. package/src/tools/code_run.ts +1 -1
  97. package/src/tools/context.ts +133 -0
  98. package/src/tools/delete_file.ts +3 -2
  99. package/src/tools/edit.ts +37 -72
  100. package/src/tools/git.ts +86 -9
  101. package/src/tools/glob.ts +26 -51
  102. package/src/tools/grep.ts +67 -57
  103. package/src/tools/hashline.ts +4 -0
  104. package/src/tools/lsp.ts +11 -8
  105. package/src/tools/mcp_call.ts +9 -6
  106. package/src/tools/memory.ts +56 -33
  107. package/src/tools/move_file.ts +36 -10
  108. package/src/tools/patch.ts +13 -21
  109. package/src/tools/read_file.ts +18 -25
  110. package/src/tools/read_image.ts +35 -33
  111. package/src/tools/submit_result.ts +29 -8
  112. package/src/tools/task.ts +74 -17
  113. package/src/tools/todo.ts +181 -74
  114. package/src/tools/web_fetch.ts +42 -2
  115. package/src/tools/web_search.ts +47 -8
  116. package/src/ui/approval/prompt.ts +206 -47
  117. package/src/ui/assistant/turn-status.ts +14 -5
  118. package/src/ui/footer.ts +4 -4
  119. package/src/ui/i18n/en.ts +47 -23
  120. package/src/ui/i18n/id.ts +76 -51
  121. package/src/ui/input/input.ts +4 -3
  122. package/src/ui/input/prompt-engine.ts +35 -5
  123. package/src/ui/render/activity-panel.ts +4 -2
  124. package/src/ui/render/hint.ts +7 -4
  125. package/src/ui/render/list.ts +32 -0
  126. package/src/ui/render/markdown.ts +6 -3
  127. package/src/ui/render/notice.ts +19 -0
  128. package/src/ui/render/table-grid.ts +7 -8
  129. package/src/ui/render/theme.ts +113 -39
  130. package/src/ui/runtime/screen.ts +74 -10
  131. package/src/ui/runtime/spinner.ts +19 -6
  132. package/src/ui/screens/dialog.ts +19 -1
  133. package/src/ui/screens/form.ts +80 -35
  134. package/src/ui/screens/model-manager.ts +82 -61
  135. package/src/ui/screens/output-window.ts +263 -0
  136. package/src/ui/screens/picker.ts +94 -81
  137. package/src/ui/screens/provider-manager.ts +100 -69
  138. package/src/ui/screens/wizard.ts +117 -28
  139. package/src/ui/tui/app.ts +196 -33
  140. package/src/ui/tui/transcript.ts +158 -25
  141. package/vendor/minicore/src/core/executor.ts +2 -0
  142. package/vendor/minicore/src/core/loop.ts +17 -6
  143. package/vendor/minicore/src/core/session.ts +3 -0
  144. package/vendor/minicore/src/core/tool.ts +1 -0
  145. package/vendor/minicore/src/providers/openai-compat.ts +35 -19
@@ -67,438 +67,96 @@ export interface ToolContractMetadata {
67
67
  readonly journalMutation: boolean
68
68
  }
69
69
 
70
- const C = (m: ToolContractMetadata): ToolContractMetadata => m
70
+ type ContractFlags = Partial<
71
+ Omit<ToolContractMetadata, "name" | "sideEffectTier" | "concurrencyClass">
72
+ >
73
+
74
+ const C = (
75
+ name: string,
76
+ sideEffectTier: SideEffectTier,
77
+ concurrencyClass: ConcurrencyClass,
78
+ opts: ContractFlags = {},
79
+ ): ToolContractMetadata => ({
80
+ name,
81
+ sideEffectTier,
82
+ concurrencyClass,
83
+ gatedByDefault: opts.gatedByDefault ?? false,
84
+ allowedInExplore: opts.allowedInExplore ?? false,
85
+ allowedInAutonomous: opts.allowedInAutonomous ?? false,
86
+ allowedInReadonly: opts.allowedInReadonly ?? false,
87
+ idempotent: opts.idempotent ?? false,
88
+ journalMutation: opts.journalMutation ?? false,
89
+ })
90
+
91
+ const pr = (name: string, opts: ContractFlags = {}) =>
92
+ C(name, "PURE_READ", "parallel-read", {
93
+ allowedInExplore: true,
94
+ allowedInAutonomous: true,
95
+ allowedInReadonly: true,
96
+ idempotent: true,
97
+ ...opts,
98
+ })
99
+ const ws = (name: string, idempotent = false) =>
100
+ C(name, "WORKSPACE_MUTATION", "path-serialized-write", { idempotent, journalMutation: true })
101
+ const lm = (name: string, cc: ConcurrencyClass, opts: ContractFlags = {}) =>
102
+ C(name, "LOCAL_ENV_MUTATION", cc, opts)
103
+ const ex = (name: string, cc: ConcurrencyClass, opts: ContractFlags = {}) =>
104
+ C(name, "EXTERNAL_IRREVERSIBLE", cc, opts)
71
105
 
72
106
  /**
73
- * Registry 37 tool bawaan. Urutan di sini adalah urutan tampilan/derivasi;
107
+ * Registry 38 tool bawaan. Urutan di sini adalah urutan tampilan/derivasi;
74
108
  * tidak ada konsumen yang boleh mengandalkan urutan selain derivasi daftar.
75
109
  */
76
110
  export const TOOL_CONTRACTS: readonly ToolContractMetadata[] = [
77
111
  // ── PURE_READ ────────────────────────────────────────────────────────────
78
- C({
79
- name: "read_file",
80
- sideEffectTier: "PURE_READ",
81
- concurrencyClass: "parallel-read",
82
- gatedByDefault: false,
83
- allowedInExplore: true,
84
- allowedInAutonomous: true,
85
- allowedInReadonly: true,
86
- idempotent: true,
87
- journalMutation: false,
88
- }),
89
- C({
90
- name: "read_image",
91
- sideEffectTier: "PURE_READ",
92
- concurrencyClass: "parallel-read",
93
- gatedByDefault: false,
94
- allowedInExplore: false,
95
- allowedInAutonomous: true,
96
- allowedInReadonly: true,
97
- idempotent: true,
98
- journalMutation: false,
99
- }),
100
- C({
101
- name: "glob",
102
- sideEffectTier: "PURE_READ",
103
- concurrencyClass: "parallel-read",
104
- gatedByDefault: false,
105
- allowedInExplore: true,
106
- allowedInAutonomous: true,
107
- allowedInReadonly: true,
108
- idempotent: true,
109
- journalMutation: false,
110
- }),
111
- C({
112
- name: "grep",
113
- sideEffectTier: "PURE_READ",
114
- concurrencyClass: "parallel-read",
115
- gatedByDefault: false,
116
- allowedInExplore: true,
117
- allowedInAutonomous: true,
118
- allowedInReadonly: true,
119
- idempotent: true,
120
- journalMutation: false,
121
- }),
122
- C({
123
- name: "git_status",
124
- sideEffectTier: "PURE_READ",
125
- concurrencyClass: "parallel-read",
126
- gatedByDefault: false,
127
- allowedInExplore: true,
128
- allowedInAutonomous: true,
129
- allowedInReadonly: true,
130
- idempotent: true,
131
- journalMutation: false,
132
- }),
133
- C({
134
- name: "git_diff",
135
- sideEffectTier: "PURE_READ",
136
- concurrencyClass: "parallel-read",
137
- gatedByDefault: false,
138
- allowedInExplore: false,
139
- allowedInAutonomous: true,
140
- allowedInReadonly: true,
141
- idempotent: true,
142
- journalMutation: false,
143
- }),
144
- C({
145
- name: "git_log",
146
- sideEffectTier: "PURE_READ",
147
- concurrencyClass: "parallel-read",
148
- gatedByDefault: false,
149
- allowedInExplore: true,
150
- allowedInAutonomous: true,
151
- allowedInReadonly: true,
152
- idempotent: true,
153
- journalMutation: false,
154
- }),
155
- C({
156
- name: "read_memory",
157
- sideEffectTier: "PURE_READ",
158
- concurrencyClass: "parallel-read",
159
- gatedByDefault: false,
160
- allowedInExplore: true,
161
- allowedInAutonomous: true,
162
- allowedInReadonly: true,
163
- idempotent: true,
164
- journalMutation: false,
165
- }),
166
- C({
167
- name: "todo_read",
168
- sideEffectTier: "PURE_READ",
169
- concurrencyClass: "parallel-read",
170
- gatedByDefault: false,
171
- allowedInExplore: true,
172
- allowedInAutonomous: true,
173
- allowedInReadonly: true,
174
- idempotent: true,
175
- journalMutation: false,
176
- }),
177
- C({
178
- name: "mcp_list",
179
- sideEffectTier: "PURE_READ",
180
- concurrencyClass: "parallel-read",
181
- gatedByDefault: false,
182
- allowedInExplore: true,
183
- allowedInAutonomous: true,
184
- allowedInReadonly: true,
185
- idempotent: true,
186
- journalMutation: false,
187
- }),
188
- C({
189
- name: "lsp_diagnostics",
190
- sideEffectTier: "PURE_READ",
191
- concurrencyClass: "parallel-read",
192
- gatedByDefault: false,
193
- allowedInExplore: true,
194
- allowedInAutonomous: true,
195
- allowedInReadonly: true,
196
- idempotent: true,
197
- journalMutation: false,
198
- }),
199
- C({
200
- name: "lsp_definition",
201
- sideEffectTier: "PURE_READ",
202
- concurrencyClass: "parallel-read",
203
- gatedByDefault: false,
204
- allowedInExplore: true,
205
- allowedInAutonomous: true,
206
- allowedInReadonly: true,
207
- idempotent: true,
208
- journalMutation: false,
209
- }),
210
- C({
211
- name: "lsp_references",
212
- sideEffectTier: "PURE_READ",
213
- concurrencyClass: "parallel-read",
214
- gatedByDefault: false,
215
- allowedInExplore: false,
216
- allowedInAutonomous: true,
217
- allowedInReadonly: true,
218
- idempotent: true,
219
- journalMutation: false,
220
- }),
221
- C({
222
- name: "lsp_hover",
223
- sideEffectTier: "PURE_READ",
224
- concurrencyClass: "parallel-read",
225
- gatedByDefault: false,
226
- allowedInExplore: true,
227
- allowedInAutonomous: true,
228
- allowedInReadonly: true,
229
- idempotent: true,
230
- journalMutation: false,
231
- }),
232
- C({
233
- name: "lsp_symbols",
234
- sideEffectTier: "PURE_READ",
235
- concurrencyClass: "parallel-read",
236
- gatedByDefault: false,
237
- allowedInExplore: false,
238
- allowedInAutonomous: true,
239
- allowedInReadonly: true,
240
- idempotent: true,
241
- journalMutation: false,
242
- }),
243
- C({
244
- name: "lsp_workspace_symbols",
245
- sideEffectTier: "PURE_READ",
246
- concurrencyClass: "parallel-read",
247
- gatedByDefault: false,
248
- allowedInExplore: true,
249
- allowedInAutonomous: true,
250
- allowedInReadonly: true,
251
- idempotent: true,
252
- journalMutation: false,
253
- }),
254
- C({
255
- name: "bash_output",
256
- sideEffectTier: "PURE_READ",
257
- concurrencyClass: "parallel-read",
258
- gatedByDefault: false,
112
+ pr("read_file"),
113
+ pr("read_image", { allowedInExplore: false }),
114
+ pr("glob"),
115
+ pr("grep"),
116
+ pr("git_status"),
117
+ pr("git_diff", { allowedInExplore: false }),
118
+ pr("git_log"),
119
+ pr("read_memory"),
120
+ pr("todo_read"),
121
+ pr("mcp_list"),
122
+ pr("lsp_diagnostics"),
123
+ pr("lsp_definition"),
124
+ pr("lsp_references", { allowedInExplore: false }),
125
+ pr("lsp_hover"),
126
+ pr("lsp_symbols", { allowedInExplore: false }),
127
+ pr("lsp_workspace_symbols"),
128
+ pr("bash_output", {
259
129
  allowedInExplore: false,
260
130
  allowedInAutonomous: false,
261
131
  allowedInReadonly: false,
262
- idempotent: true,
263
- journalMutation: false,
264
132
  }),
265
133
 
266
134
  // ── WORKSPACE_MUTATION (path tunggal → slot tulis + file-lock) ───────────
267
- C({
268
- name: "write_file",
269
- sideEffectTier: "WORKSPACE_MUTATION",
270
- concurrencyClass: "path-serialized-write",
271
- gatedByDefault: false,
272
- allowedInExplore: false,
273
- allowedInAutonomous: false,
274
- allowedInReadonly: false,
275
- idempotent: true,
276
- journalMutation: true,
277
- }),
278
- C({
279
- name: "edit",
280
- sideEffectTier: "WORKSPACE_MUTATION",
281
- concurrencyClass: "path-serialized-write",
282
- gatedByDefault: false,
283
- allowedInExplore: false,
284
- allowedInAutonomous: false,
285
- allowedInReadonly: false,
286
- idempotent: false,
287
- journalMutation: true,
288
- }),
289
- C({
290
- name: "apply_patch",
291
- sideEffectTier: "WORKSPACE_MUTATION",
292
- concurrencyClass: "path-serialized-write",
293
- gatedByDefault: false,
294
- allowedInExplore: false,
295
- allowedInAutonomous: false,
296
- allowedInReadonly: false,
297
- idempotent: false,
298
- journalMutation: true,
299
- }),
300
- C({
301
- name: "move_file",
302
- sideEffectTier: "WORKSPACE_MUTATION",
303
- concurrencyClass: "path-serialized-write",
304
- gatedByDefault: false,
305
- allowedInExplore: false,
306
- allowedInAutonomous: false,
307
- allowedInReadonly: false,
308
- idempotent: false,
309
- journalMutation: true,
310
- }),
311
- C({
312
- name: "delete_file",
313
- sideEffectTier: "WORKSPACE_MUTATION",
314
- concurrencyClass: "path-serialized-write",
315
- gatedByDefault: false,
316
- allowedInExplore: false,
317
- allowedInAutonomous: false,
318
- allowedInReadonly: false,
319
- idempotent: true,
320
- journalMutation: true,
321
- }),
135
+ ws("write_file", true),
136
+ ws("edit"),
137
+ ws("apply_patch"),
138
+ ws("move_file"),
139
+ ws("delete_file", true),
322
140
 
323
141
  // ── LOCAL_ENV_MUTATION ──────────────────────────────────────────────────
324
- C({
325
- name: "bash",
326
- sideEffectTier: "LOCAL_ENV_MUTATION",
327
- concurrencyClass: "exclusive",
328
- gatedByDefault: false,
329
- allowedInExplore: false,
330
- allowedInAutonomous: false,
331
- allowedInReadonly: false,
332
- idempotent: false,
333
- journalMutation: true,
334
- }),
335
- C({
336
- name: "bash_kill",
337
- sideEffectTier: "LOCAL_ENV_MUTATION",
338
- concurrencyClass: "parallel-read",
339
- gatedByDefault: false,
340
- allowedInExplore: false,
341
- allowedInAutonomous: false,
342
- allowedInReadonly: false,
343
- idempotent: false,
344
- journalMutation: false,
345
- }),
346
- C({
347
- name: "code_run",
348
- sideEffectTier: "LOCAL_ENV_MUTATION",
349
- concurrencyClass: "exclusive",
350
- gatedByDefault: false,
351
- allowedInExplore: false,
352
- allowedInAutonomous: false,
353
- allowedInReadonly: false,
354
- idempotent: false,
355
- journalMutation: true,
356
- }),
357
- C({
358
- name: "write_memory",
359
- sideEffectTier: "LOCAL_ENV_MUTATION",
360
- concurrencyClass: "exclusive",
361
- gatedByDefault: false,
362
- allowedInExplore: false,
363
- allowedInAutonomous: false,
364
- allowedInReadonly: false,
365
- idempotent: false,
366
- journalMutation: true,
367
- }),
368
- C({
369
- name: "forget_memory",
370
- sideEffectTier: "LOCAL_ENV_MUTATION",
371
- concurrencyClass: "exclusive",
372
- gatedByDefault: false,
373
- allowedInExplore: false,
374
- allowedInAutonomous: false,
375
- allowedInReadonly: false,
376
- idempotent: true,
377
- journalMutation: true,
378
- }),
379
- C({
380
- name: "todo_write",
381
- sideEffectTier: "LOCAL_ENV_MUTATION",
382
- concurrencyClass: "exclusive",
383
- gatedByDefault: false,
384
- allowedInExplore: false,
385
- allowedInAutonomous: false,
386
- allowedInReadonly: false,
387
- idempotent: true,
388
- journalMutation: false,
389
- }),
390
- C({
391
- name: "submit_result",
392
- sideEffectTier: "LOCAL_ENV_MUTATION",
393
- concurrencyClass: "parallel-read",
394
- gatedByDefault: false,
395
- allowedInExplore: false,
396
- allowedInAutonomous: false,
397
- allowedInReadonly: false,
398
- idempotent: false,
399
- journalMutation: false,
400
- }),
401
- C({
402
- name: "ask_user",
403
- sideEffectTier: "LOCAL_ENV_MUTATION",
404
- concurrencyClass: "parallel-read",
405
- gatedByDefault: true,
406
- allowedInExplore: false,
407
- allowedInAutonomous: false,
408
- allowedInReadonly: false,
409
- idempotent: false,
410
- journalMutation: false,
411
- }),
142
+ lm("bash", "exclusive", { journalMutation: true }),
143
+ lm("bash_kill", "parallel-read"),
144
+ lm("code_run", "exclusive", { journalMutation: true }),
145
+ lm("write_memory", "exclusive", { journalMutation: true }),
146
+ lm("forget_memory", "exclusive", { idempotent: true, journalMutation: true }),
147
+ lm("todo_write", "exclusive", { idempotent: true }),
148
+ lm("submit_result", "parallel-read"),
149
+ lm("ask_user", "parallel-read", { gatedByDefault: true }),
412
150
 
413
151
  // ── EXTERNAL_IRREVERSIBLE ───────────────────────────────────────────────
414
- C({
415
- name: "git_commit",
416
- sideEffectTier: "EXTERNAL_IRREVERSIBLE",
417
- concurrencyClass: "exclusive",
418
- gatedByDefault: true,
419
- allowedInExplore: false,
420
- allowedInAutonomous: false,
421
- allowedInReadonly: false,
422
- idempotent: false,
423
- journalMutation: true,
424
- }),
425
- C({
426
- name: "git_push",
427
- sideEffectTier: "EXTERNAL_IRREVERSIBLE",
428
- concurrencyClass: "exclusive",
429
- gatedByDefault: true,
430
- allowedInExplore: false,
431
- allowedInAutonomous: false,
432
- allowedInReadonly: false,
433
- idempotent: false,
434
- journalMutation: true,
435
- }),
436
- C({
437
- name: "delegate_task",
438
- sideEffectTier: "EXTERNAL_IRREVERSIBLE",
439
- concurrencyClass: "parallel-read",
440
- gatedByDefault: true,
441
- allowedInExplore: false,
442
- allowedInAutonomous: false,
443
- allowedInReadonly: false,
444
- idempotent: false,
445
- journalMutation: true,
446
- }),
447
- C({
448
- name: "mcp_call",
449
- sideEffectTier: "EXTERNAL_IRREVERSIBLE",
450
- concurrencyClass: "parallel-read",
451
- gatedByDefault: true,
452
- allowedInExplore: false,
453
- allowedInAutonomous: false,
454
- allowedInReadonly: false,
455
- idempotent: false,
456
- journalMutation: true,
457
- }),
458
- C({
459
- name: "mcp_read",
460
- sideEffectTier: "EXTERNAL_IRREVERSIBLE",
461
- concurrencyClass: "parallel-read",
462
- gatedByDefault: true,
463
- allowedInExplore: false,
464
- allowedInAutonomous: false,
465
- allowedInReadonly: false,
466
- idempotent: true,
467
- journalMutation: false,
468
- }),
469
- C({
470
- name: "mcp_prompt",
471
- sideEffectTier: "EXTERNAL_IRREVERSIBLE",
472
- concurrencyClass: "parallel-read",
473
- gatedByDefault: true,
474
- allowedInExplore: false,
475
- allowedInAutonomous: false,
476
- allowedInReadonly: false,
477
- idempotent: true,
478
- journalMutation: false,
479
- }),
480
- C({
481
- name: "web_fetch",
482
- sideEffectTier: "EXTERNAL_IRREVERSIBLE",
483
- concurrencyClass: "parallel-read",
484
- gatedByDefault: false,
485
- allowedInExplore: false,
486
- allowedInAutonomous: false,
487
- allowedInReadonly: true,
488
- idempotent: true,
489
- journalMutation: false,
490
- }),
491
- C({
492
- name: "web_search",
493
- sideEffectTier: "EXTERNAL_IRREVERSIBLE",
494
- concurrencyClass: "parallel-read",
495
- gatedByDefault: false,
496
- allowedInExplore: false,
497
- allowedInAutonomous: false,
498
- allowedInReadonly: true,
499
- idempotent: true,
500
- journalMutation: false,
501
- }),
152
+ ex("git_commit", "exclusive", { gatedByDefault: true, journalMutation: true }),
153
+ ex("git_push", "exclusive", { gatedByDefault: true, journalMutation: true }),
154
+ ex("delegate_task", "parallel-read", { gatedByDefault: true, journalMutation: true }),
155
+ ex("mcp_call", "parallel-read", { gatedByDefault: true, journalMutation: true }),
156
+ ex("mcp_read", "parallel-read", { gatedByDefault: true, idempotent: true }),
157
+ ex("mcp_prompt", "parallel-read", { gatedByDefault: true, idempotent: true }),
158
+ ex("web_fetch", "parallel-read", { allowedInReadonly: true, idempotent: true }),
159
+ ex("web_search", "parallel-read", { allowedInReadonly: true, idempotent: true }),
502
160
  ]
503
161
 
504
162
  const BY_NAME: ReadonlyMap<string, ToolContractMetadata> = new Map(
@@ -358,7 +358,7 @@ export function createUsageCollector(
358
358
  // Total bersih = snapshot TERAKHIR (overwrite), bukan penjumlahan chunk.
359
359
  // Pada batas permintaan berikutnya (step:started/turn:started), baseline
360
360
  // di-reset ke snapshot terakhir (yang sudah penuh terlihat).
361
- let pendingRequestTokens: {
361
+ type SegmentSnapshot = {
362
362
  inputTokens: number
363
363
  outputTokens: number
364
364
  totalTokens: number
@@ -366,13 +366,21 @@ export function createUsageCollector(
366
366
  cacheWriteTokens: number
367
367
  cost: number | undefined
368
368
  segModel: string | undefined
369
- } | null = null
369
+ }
370
+ let pendingRequestTokens: SegmentSnapshot | null = null
370
371
  let requestBoundary = 0
371
372
  // totalTokens permintaan yang sedang berjalan. Digunakan untuk mendeteksi
372
373
  // MULAI permintaan BARU dalam satu step yang sama (mis. retry recovery
373
374
  // kernel): total kumulatif streaming hanya bertambah dalam satu permintaan,
374
375
  // jadi nilai yang MENURUN menandakan permintaan baru (bukan chunk lagi).
375
376
  let lastRequestTotal = 0
377
+ const childPending = new Map<
378
+ string,
379
+ {
380
+ lastTotal: number
381
+ pending: SegmentSnapshot | null
382
+ }
383
+ >()
376
384
 
377
385
  // Terapkan snapshot ke turn+session. `prev` = snapshot permintaan yang sama
378
386
  // sebelumnya (null untuk event pertama) — bila ada, hanya SELISIH yang
@@ -444,12 +452,14 @@ export function createUsageCollector(
444
452
  sessionTurns += 1
445
453
  // Selesaikan snapshot permintaan terakhir di turn ini.
446
454
  flushPendingRequest()
455
+ childPending.clear()
447
456
  })
448
457
  } catch {}
449
458
 
450
459
  try {
451
460
  bus.on("turn:started", () => {
452
461
  beginRequest()
462
+ childPending.clear()
453
463
  })
454
464
  } catch {}
455
465
 
@@ -461,7 +471,10 @@ export function createUsageCollector(
461
471
  } catch {}
462
472
 
463
473
  bus.on("provider:extension", (e) => {
474
+ const forwardedChild = (e as { forwardedChild?: unknown }).forwardedChild
475
+ const isForwarded = forwardedChild != null
464
476
  if (e.kind === "effective-model") {
477
+ if (isForwarded) return
465
478
  const d = e.data as { requested?: string; effective?: string; provider?: string }
466
479
  effectiveModel = d.effective ?? effectiveModel
467
480
  effectiveProvider = d.provider ?? effectiveProvider
@@ -519,6 +532,15 @@ export function createUsageCollector(
519
532
  applyPending(newSnapshot, null)
520
533
  return
521
534
  }
535
+ if (isForwarded) {
536
+ const childKey = String((e as { childRunId?: unknown }).childRunId ?? forwardedChild)
537
+ const prevChild = childPending.get(childKey)
538
+ const prevSnap =
539
+ prevChild && reportedTotal < prevChild.lastTotal ? null : (prevChild?.pending ?? null)
540
+ applyPending(newSnapshot, prevSnap)
541
+ childPending.set(childKey, { lastTotal: reportedTotal, pending: newSnapshot })
542
+ return
543
+ }
522
544
  lastProviderUsage = { inputTokens: input, outputTokens: output, totalTokens: reportedTotal }
523
545
 
524
546
  // [Fase 7 / Live #2] JANGAN `+=` langsung ke turn+session per chunk SSE.
@@ -14,6 +14,40 @@ export interface VerifyResult {
14
14
  command: string
15
15
  /** [Fase 3 / LOOP-INV-12] Kode keluar proses verifier (0 = lulus). Opsional demi back-compat. */
16
16
  exitCode?: number
17
+ /** True bila proses verifier dipotong timeout internal runner (bukan assertion gagal). */
18
+ timedOut?: boolean
19
+ }
20
+
21
+ const TEST_OUTPUT_NOISE_RE =
22
+ /^\s*(?:\(fail\)|Expected:|Received:|at\s+.*:\d+:\d+|\d+\s*\||\^|expect\()/
23
+
24
+ /**
25
+ * Klasifikasikan penyebab kegagalan verifier secara ketat agar teks assertion
26
+ * test fungsional (mis. pesan error yang kebetulan menyebut kata "network" atau
27
+ * "permission denied") tidak salah diklasifikasikan sebagai TRANSIENT_ENV /
28
+ * PERMISSION_OR_EXTERNAL_BLOCKER di lapisan ACE.
29
+ */
30
+ export function classifyVerifyFailure(input: {
31
+ ok: boolean
32
+ output?: string
33
+ timedOut?: boolean
34
+ }): { transient: boolean; permissionBlocked: boolean } {
35
+ if (input.ok) return { transient: false, permissionBlocked: false }
36
+ const raw = String(input.output ?? "")
37
+ const infraLines = raw
38
+ .split(/\r?\n/)
39
+ .filter((line) => !TEST_OUTPUT_NOISE_RE.test(line))
40
+ .join("\n")
41
+ const transient =
42
+ input.timedOut === true ||
43
+ /\b(?:ECONNREFUSED|ECONNRESET|ETIMEDOUT|EAI_AGAIN|ENOTFOUND|ESOCKETTIMEDOUT)\b|\bsocket hang up\b|\bHTTP\s*(?:429|503)\b/i.test(
44
+ infraLines,
45
+ )
46
+ const permissionBlocked =
47
+ /\b(?:EACCES|EPERM)\b|operation not permitted|EACCES:.*permission denied|permission denied:\s*\//i.test(
48
+ infraLines,
49
+ )
50
+ return { transient, permissionBlocked }
17
51
  }
18
52
 
19
53
  /**
@@ -53,11 +87,25 @@ export async function runVerify(
53
87
  // kegagalan verifikasi — lempar agar self-heal/REPL berhenti, bukan
54
88
  // memperbaiki.
55
89
  if (signal?.aborted) signal.throwIfAborted()
56
- const err = e as { stdout?: string; stderr?: string; message?: string; code?: unknown }
90
+ const err = e as {
91
+ stdout?: string
92
+ stderr?: string
93
+ message?: string
94
+ code?: unknown
95
+ killed?: boolean
96
+ signal?: string | null
97
+ }
57
98
  const rawOut = `${err.stdout ?? ""}${err.stderr ? `\n${err.stderr}` : ""}`.trim() || String(e)
58
99
  const output = scrubSecrets(rawOut)
59
100
  const exitCode = typeof err.code === "number" && Number.isFinite(err.code) ? err.code : 1
60
- return { ok: false, output: output.slice(0, 8000), command, exitCode }
101
+ const timedOut = err.killed === true && (err.signal === "SIGTERM" || err.signal === "SIGKILL")
102
+ return {
103
+ ok: false,
104
+ output: output.slice(0, 8000),
105
+ command,
106
+ exitCode,
107
+ ...(timedOut ? { timedOut: true } : {}),
108
+ }
61
109
  }
62
110
  }
63
111
  // Deteksi perintah verify yang masuk akal untuk proyek di `cwd`.