minicode-ai 0.11.1 → 0.13.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.
- package/CHANGELOG.md +89 -0
- package/LICENSE +21 -21
- package/README.md +4 -4
- package/cli/args.ts +46 -0
- package/cli/commands/acp.ts +163 -10
- package/cli/commands/config.ts +33 -18
- package/cli/commands/daemon.ts +515 -0
- package/cli/commands/exec.ts +145 -53
- package/cli/commands/openwork.ts +986 -0
- package/cli/commands/sessions.ts +4 -1
- package/cli/commands/stats.ts +34 -4
- package/cli/commands.ts +217 -2
- package/cli/index.ts +146 -14
- package/cli/recovery-warning.ts +115 -0
- package/cli/router.ts +32 -1
- package/cli/setup.ts +2332 -171
- package/cli/tui.ts +113 -7
- package/docs/OUTPUT_ARCHITECTURE_AUDIT.md +489 -0
- package/docs/OUTPUT_EVENT_MODEL.md +289 -0
- package/docs/OUTPUT_IMPLEMENTATION_PLAN.md +391 -0
- package/docs/OUTPUT_PROTOCOL_SPEC.md +285 -0
- package/docs/OUTPUT_RENDERING_SPEC.md +248 -0
- package/docs/OUTPUT_UX_RULES.md +449 -0
- package/docs/PLAN_UIUX_V6.md +2 -2
- package/docs/README.md +4 -3
- package/docs/TERMINAL_CONTRACT.md +278 -71
- package/docs/architecture.md +89 -7
- package/docs/changelog.md +1 -1
- package/docs/choosing-mode.md +2 -2
- package/docs/cli.md +9 -5
- package/docs/concepts.md +1 -1
- package/docs/contributing.md +9 -2
- package/docs/environment.md +6 -2
- package/docs/exec.md +46 -5
- package/docs/memory-sessions.md +2 -0
- package/docs/policy-sandbox.md +1 -1
- package/docs/pricing-budget.md +1 -1
- package/docs/quickstart.md +2 -2
- package/docs/repl.md +6 -2
- package/docs/security-model.md +1 -1
- package/docs/security.md +1 -1
- package/docs/skills.md +2 -2
- package/docs/terminal.md +9 -5
- package/docs/tools.md +1 -1
- package/package.json +35 -5
- package/src/app/session.ts +261 -15
- package/src/app/tool-layer.ts +94 -7
- package/src/daemon/approvals.ts +361 -0
- package/src/daemon/capability.ts +145 -0
- package/src/daemon/children.ts +142 -0
- package/src/daemon/client.ts +267 -0
- package/src/daemon/control.ts +350 -0
- package/src/daemon/discovery.ts +234 -0
- package/src/daemon/feed.ts +155 -0
- package/src/daemon/framing.ts +94 -0
- package/src/daemon/host.ts +316 -0
- package/src/daemon/protocol.ts +217 -0
- package/src/daemon/resource.ts +170 -0
- package/src/daemon/sanitize.ts +57 -0
- package/src/daemon/server.ts +627 -0
- package/src/daemon/store.ts +317 -0
- package/src/daemon/subscription.ts +270 -0
- package/src/daemon/telemetry.ts +81 -0
- package/src/hooks/run.ts +12 -1
- package/src/lib/atomic-write.ts +29 -3
- package/src/lib/db-path.ts +26 -0
- package/src/lib/keystore.ts +544 -42
- package/src/lib/net.ts +43 -1
- package/src/lib/safe-open.ts +116 -1
- package/src/lib/session-id.ts +15 -0
- package/src/lsp/client.ts +123 -5
- package/src/mcp/client.ts +139 -17
- package/src/mcp/server.ts +177 -50
- package/src/mcp/transport.ts +16 -19
- package/src/memory/vector.ts +770 -55
- package/src/policy/allowlist.ts +14 -2
- package/src/policy/bash-guard.ts +105 -10
- package/src/policy/compaction.ts +82 -5
- package/src/policy/consequence-engine.ts +220 -0
- package/src/policy/context.ts +132 -0
- package/src/policy/executor.ts +187 -121
- package/src/policy/no-progress.ts +559 -0
- package/src/policy/permission.ts +4 -8
- package/src/policy/pricing.ts +17 -3
- package/src/policy/scrub.ts +69 -2
- package/src/policy/tool-contract.ts +515 -0
- package/src/policy/usage.ts +310 -24
- package/src/policy/verifier.ts +6 -3
- package/src/policy/work-mode.ts +182 -0
- package/src/presentation/adapter.ts +533 -26
- package/src/presentation/events.ts +151 -0
- package/src/presentation/model.ts +180 -27
- package/src/presentation/projection.ts +858 -0
- package/src/presentation/reducer.ts +645 -310
- package/src/presentation/store.ts +12 -7
- package/src/providers/anthropic.ts +18 -10
- package/src/providers/responses.ts +2 -2
- package/src/runtime/capability.ts +409 -0
- package/src/runtime/child-execution.ts +274 -0
- package/src/runtime/composition.ts +958 -0
- package/src/runtime/dispatch.ts +591 -0
- package/src/runtime/execution-backend.ts +632 -0
- package/src/runtime/execution-events.ts +272 -0
- package/src/runtime/execution-id.ts +230 -0
- package/src/runtime/execution-journal.ts +926 -0
- package/src/runtime/execution-kernel.ts +456 -0
- package/src/runtime/execution-registry.ts +379 -0
- package/src/runtime/process-supervision.ts +276 -0
- package/src/runtime/production-execution.ts +551 -0
- package/src/runtime/production-runtime.ts +217 -0
- package/src/runtime/recovery-safety.ts +70 -0
- package/src/runtime/recovery.ts +477 -0
- package/src/runtime/runtime-capabilities.ts +179 -0
- package/src/runtime/runtime-diagnostics.ts +141 -0
- package/src/runtime/runtime-host.ts +365 -0
- package/src/runtime/runtime-status-facts.ts +222 -0
- package/src/runtime/runtime-status-provider.ts +74 -0
- package/src/runtime/runtime-status.ts +459 -0
- package/src/runtime/runtime-task-admission.ts +101 -0
- package/src/runtime/supervisor.ts +444 -0
- package/src/session/authority.ts +168 -0
- package/src/session/checkpoint.ts +88 -1
- package/src/session/context-adapter.ts +251 -0
- package/src/session/context-assembly.ts +242 -0
- package/src/session/context-identity.ts +389 -0
- package/src/session/context-projection.ts +248 -0
- package/src/session/context-selector.ts +500 -0
- package/src/session/cross-session-adoption.ts +249 -0
- package/src/session/full-history-fold.ts +171 -0
- package/src/session/identity.ts +192 -0
- package/src/session/journal.ts +805 -102
- package/src/session/open-work-intent.ts +732 -0
- package/src/session/open-work.ts +767 -0
- package/src/session/pending-tools.ts +94 -0
- package/src/session/persistence.ts +3569 -127
- package/src/session/runtime-header.ts +208 -0
- package/src/session/shadow-git.ts +13 -5
- package/src/session/verification.ts +1623 -0
- package/src/task/assignment.ts +136 -0
- package/src/task/autonomous-adapter.ts +168 -0
- package/src/task/autonomous-context.ts +630 -0
- package/src/task/autonomous-policy.ts +490 -0
- package/src/task/continuity.ts +179 -0
- package/src/task/execution-cancellation.ts +165 -0
- package/src/task/graph-validate.ts +379 -0
- package/src/task/graph.ts +305 -0
- package/src/task/identity.ts +230 -0
- package/src/task/model.ts +417 -0
- package/src/task/production-scheduler.ts +293 -0
- package/src/task/readiness.ts +229 -0
- package/src/task/scheduler-observability.ts +387 -0
- package/src/task/scheduler.ts +1197 -0
- package/src/task/scheduling-policy.ts +165 -0
- package/src/task/session-authority.ts +148 -0
- package/src/task/session-ownership.ts +211 -0
- package/src/task/store.ts +2887 -0
- package/src/task/sync.ts +343 -0
- package/src/task/trigger.ts +260 -0
- package/src/tools/bash.ts +377 -211
- package/src/tools/code_run.ts +1 -1
- package/src/tools/delete_file.ts +1 -1
- package/src/tools/edit.ts +33 -6
- package/src/tools/evidence.ts +30 -0
- package/src/tools/git.ts +4 -4
- package/src/tools/glob.ts +12 -3
- package/src/tools/grep.ts +1 -1
- package/src/tools/lsp.ts +4 -4
- package/src/tools/mcp_call.ts +11 -4
- package/src/tools/memory.ts +153 -18
- package/src/tools/move_file.ts +1 -1
- package/src/tools/patch.ts +1 -1
- package/src/tools/read_file.ts +1 -1
- package/src/tools/read_image.ts +1 -1
- package/src/tools/submit_result.ts +1 -1
- package/src/tools/task.ts +437 -41
- package/src/tools/todo.ts +662 -35
- package/src/tools/web_fetch.ts +4 -2
- package/src/tools/web_search.ts +9 -3
- package/src/tools/write_file.ts +1 -1
- package/src/ui/assistant/simple.ts +123 -50
- package/src/ui/assistant/turn-status.ts +17 -3
- package/src/ui/contract.ts +184 -0
- package/src/ui/footer.ts +52 -19
- package/src/ui/i18n/en.ts +58 -6
- package/src/ui/i18n/id.ts +58 -6
- package/src/ui/input/prompt-engine.ts +120 -25
- package/src/ui/render/errors.ts +39 -1
- package/src/ui/render/markdown-table.ts +455 -0
- package/src/ui/render/markdown.ts +22 -1
- package/src/ui/render/table-grid.ts +184 -0
- package/src/ui/render/table.ts +15 -76
- package/src/ui/runtime/screen.ts +7 -2
- package/src/ui/runtime/statusline.ts +25 -6
- package/src/ui/tui/app.ts +507 -169
- package/src/ui/tui/transcript.ts +531 -89
- package/vendor/minicore/VENDOR.md +1 -1
- package/vendor/minicore/src/core/budget.ts +25 -25
- package/vendor/minicore/src/core/compact.ts +75 -75
- package/vendor/minicore/src/core/errors.ts +59 -59
- package/vendor/minicore/src/core/events.ts +73 -73
- package/vendor/minicore/src/core/executor.ts +139 -139
- package/vendor/minicore/src/core/history.ts +31 -31
- package/vendor/minicore/src/core/index.ts +41 -41
- package/vendor/minicore/src/core/loop.ts +355 -355
- package/vendor/minicore/src/core/permission.ts +22 -22
- package/vendor/minicore/src/core/provider.ts +39 -39
- package/vendor/minicore/src/core/recovery.ts +35 -35
- package/vendor/minicore/src/core/session.ts +327 -327
- package/vendor/minicore/src/core/snapshot.ts +146 -146
- package/vendor/minicore/src/core/tokens.ts +107 -107
- package/vendor/minicore/src/core/tool.ts +115 -115
- package/vendor/minicore/src/core/types.ts +50 -50
- package/vendor/minicore/src/providers/openai-compat.ts +417 -417
- package/AGENTS.md +0 -45
- package/PLAN.md +0 -491
- package/docs/ARCHITECTURE.html +0 -1248
- package/docs/CONTROL-PLANE-MAP.md +0 -139
- package/docs/HARNESS.md +0 -150
- package/docs/SUMMARY.md +0 -52
- package/docs/UI_RENDER_PIPELINE.md +0 -169
- package/docs/USAGE.md +0 -11
package/src/tools/task.ts
CHANGED
|
@@ -1,13 +1,40 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { existsSync } from "node:fs"
|
|
2
|
+
import { dirname } from "node:path"
|
|
2
3
|
import type { ModelProvider, Tool } from "#minicore"
|
|
3
4
|
import { createOpenAICompatProvider } from "#minicore/providers/openai-compat.ts"
|
|
4
5
|
import { Pool } from "../agents/pool.ts"
|
|
5
6
|
import { loadConfig } from "../config.ts"
|
|
6
7
|
import { LIMITS } from "../constants.ts"
|
|
8
|
+
import { resolveLocalDbPath } from "../lib/db-path.ts"
|
|
9
|
+
import { evaluateConsequence, isAceEnabled } from "../policy/consequence-engine.ts"
|
|
10
|
+
import type { NoProgressOptions } from "../policy/no-progress.ts"
|
|
7
11
|
import type { RateLimiter } from "../policy/ratelimit.ts"
|
|
12
|
+
import type { WorkMode } from "../policy/work-mode.ts"
|
|
8
13
|
import { buildProviderListAsync } from "../providers/build.ts"
|
|
9
14
|
import { createRouterProvider } from "../providers/router.ts"
|
|
10
|
-
import {
|
|
15
|
+
import type { ProductionExecutionRunner } from "../runtime/production-execution.ts"
|
|
16
|
+
import { acquireSessionWriter, releaseSessionWriter } from "../session/authority.ts"
|
|
17
|
+
import type { AceResultSnapshot } from "../session/journal.ts"
|
|
18
|
+
import {
|
|
19
|
+
allocateChildSessionId,
|
|
20
|
+
completeRun,
|
|
21
|
+
createChildSession,
|
|
22
|
+
DEFAULT_THREAD_ID,
|
|
23
|
+
failRun,
|
|
24
|
+
interruptRun,
|
|
25
|
+
readWriterEpoch,
|
|
26
|
+
transitionRun,
|
|
27
|
+
} from "../session/persistence.ts"
|
|
28
|
+
import {
|
|
29
|
+
buildChildResultEnvelope,
|
|
30
|
+
type ChildStatus,
|
|
31
|
+
childStatusOutcomeFlags,
|
|
32
|
+
classifyChildStatus,
|
|
33
|
+
type EffectIntentResult,
|
|
34
|
+
persistEffectIntent,
|
|
35
|
+
persistEffectReceipt,
|
|
36
|
+
} from "../session/verification.ts"
|
|
37
|
+
import { withEvidence } from "./evidence.ts"
|
|
11
38
|
import { todoSession } from "./todo.ts"
|
|
12
39
|
|
|
13
40
|
const pool = new Pool(LIMITS.SUB_AGENT_POOL_SIZE)
|
|
@@ -16,20 +43,11 @@ const pool = new Pool(LIMITS.SUB_AGENT_POOL_SIZE)
|
|
|
16
43
|
// (--tool-scope explore). Satu daftar, satu makna: scoping per fase (pelajaran
|
|
17
44
|
// Vercel: tool minimum per fase, bukan semua 36 sekaligus). Diuji oleh
|
|
18
45
|
// test/harness-p2 + audit invariant bench/harness-audit.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"todo_read",
|
|
25
|
-
"git_status",
|
|
26
|
-
"git_log",
|
|
27
|
-
"lsp_diagnostics",
|
|
28
|
-
"lsp_definition",
|
|
29
|
-
"lsp_hover",
|
|
30
|
-
"lsp_workspace_symbols",
|
|
31
|
-
"mcp_list",
|
|
32
|
-
]
|
|
46
|
+
// [Fase 2 / TOOL-01] Diimpor dari registry kontrak tool — dulu daftar manual
|
|
47
|
+
// di sini yang harus disinkronkan dengan tool-layer.
|
|
48
|
+
import { EXPLORE_TOOL_NAMES } from "../policy/tool-contract.ts"
|
|
49
|
+
|
|
50
|
+
export { EXPLORE_TOOL_NAMES }
|
|
33
51
|
|
|
34
52
|
// Factory sesi sub-agen di-inject dari composition root (cli/index.ts memakai
|
|
35
53
|
// createMinicodeSession). Lapisan tool tidak lagi mengimpor lapisan sesi/app
|
|
@@ -47,6 +65,14 @@ export interface SubAgentSpec {
|
|
|
47
65
|
// parent ask adalah eskalasi (satu approval delegasi menjadi N aksi
|
|
48
66
|
// tak-disetujui), jadi pembatasan ditaruh di mode alat, bukan izin.
|
|
49
67
|
permissionMode: "auto" | "allowlist"
|
|
68
|
+
/**
|
|
69
|
+
* P12 S2.2 — WorkMode sesi anak (intent layer di ATAS permissionMode).
|
|
70
|
+
* Diisi delegateTaskTool dari WorkMode induk (lihat subAgentWorkMode).
|
|
71
|
+
* EXECUTE = tanpa ceiling tambahan (perilaku lama). Non-EXECUTE dipakai
|
|
72
|
+
* factory (`cli/index.ts`) untuk membangun `createMinicodeSession` anak
|
|
73
|
+
* dengan ceiling WorkMode sendiri — menutup eskalasi jalur PLAN×auto.
|
|
74
|
+
*/
|
|
75
|
+
workMode?: WorkMode
|
|
50
76
|
maxSteps: number
|
|
51
77
|
timeoutMs: number
|
|
52
78
|
systemExtra: string
|
|
@@ -63,6 +89,11 @@ export interface SubAgentSpec {
|
|
|
63
89
|
* (live, ikut /model mid-session); opsional agar factory lama tetap jalan.
|
|
64
90
|
*/
|
|
65
91
|
model?: string
|
|
92
|
+
/** [Fase 7 / LOOP-INV-15] Konfigurasi NoProgressDetector anak. Default =
|
|
93
|
+
* aktif (createMinicodeSession aktif secara default); field ini
|
|
94
|
+
* memungkinkan factory menurunkan ambang thrashing read-only karena anak
|
|
95
|
+
* explore/plan memang read-only (stagnasi = perulangan grep/glob). */
|
|
96
|
+
noProgress?: NoProgressOptions
|
|
66
97
|
}
|
|
67
98
|
|
|
68
99
|
/** Subset struktural sesi yang dibutuhkan tool ini — tanpa tipe lapisan app. */
|
|
@@ -82,11 +113,31 @@ export function setSubAgentSessionFactory(factory: SubAgentSessionFactory): void
|
|
|
82
113
|
sessionFactory = factory
|
|
83
114
|
}
|
|
84
115
|
|
|
116
|
+
// ── [P1 M15] Admission runtime untuk turn anak ───────────────────────────────
|
|
117
|
+
//
|
|
118
|
+
// Kenapa DI, bukan import langsung: `src/tools/` tidak boleh tahu soal host /
|
|
119
|
+
// journal runtime, dan composition root adalah satu-satunya pemilik runtime
|
|
120
|
+
// sesi. Tanpa setter, tool ini kembali persis ke perilaku sebelum M15 (legacy run
|
|
121
|
+
// langsung) — jadi mode `off` tak pernah berubah bentuk.
|
|
122
|
+
let childExecutionRunner: ProductionExecutionRunner | undefined
|
|
123
|
+
|
|
124
|
+
export function setSubAgentExecutionRunner(runner: ProductionExecutionRunner | undefined): void {
|
|
125
|
+
childExecutionRunner = runner
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export function getSubAgentExecutionRunner(): ProductionExecutionRunner | undefined {
|
|
129
|
+
return childExecutionRunner
|
|
130
|
+
}
|
|
131
|
+
|
|
85
132
|
// Seam uji: kembalikan ke fail-closed tanpa factory (isolasi antar test file,
|
|
86
133
|
// karena factory adalah state module-global).
|
|
87
134
|
export function clearSubAgentSessionFactory(): void {
|
|
88
135
|
sessionFactory = undefined
|
|
89
136
|
parentRouting = {}
|
|
137
|
+
childExecutionRunner = undefined
|
|
138
|
+
parentRunIdFn = () => null
|
|
139
|
+
// P12 S2.2 — reset WorkMode induk agar test terisolasi (pola reset lain).
|
|
140
|
+
subAgentWorkModeFn = () => undefined
|
|
90
141
|
}
|
|
91
142
|
|
|
92
143
|
/**
|
|
@@ -103,6 +154,48 @@ export interface SubAgentParentRouting {
|
|
|
103
154
|
|
|
104
155
|
let parentRouting: SubAgentParentRouting = {}
|
|
105
156
|
|
|
157
|
+
/**
|
|
158
|
+
* P2.9: sumber durable untuk parent Run id saat anak_REQUIRED. Vendor
|
|
159
|
+
* ToolContext tak membawa execution id, jadi composition root (satu-satunya
|
|
160
|
+
* pemilik Run hidup) menyuntikkannya — bukan dialing di sini.
|
|
161
|
+
*/
|
|
162
|
+
let parentRunIdFn: () => string | null = () => null
|
|
163
|
+
|
|
164
|
+
export function setSubAgentParentRunId(fn: () => string | null): void {
|
|
165
|
+
parentRunIdFn = fn
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Diperuhi/test: lineage parent Run untuk anak berikutnya. */
|
|
169
|
+
export function subAgentParentRunId(): string | null {
|
|
170
|
+
try {
|
|
171
|
+
return parentRunIdFn()
|
|
172
|
+
} catch {
|
|
173
|
+
return null
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// P12 S2.2 — WorkMode sesi induk (intent layer). ToolContext.permissionMode
|
|
178
|
+
// hanya membawa permission mode (bukan WorkMode), dan kontrak vendor tak boleh
|
|
179
|
+
// diubah — jadi WorkMode induk disuntikkan dari composition root (satu-satunya
|
|
180
|
+
// pemilik WorkMode efektif), pola identik `setSubAgentParentRunId`. Tanpa ini
|
|
181
|
+
// jalur `PLAN × auto` (delegate_task di-approve) melahirkan anak `auto` dengan
|
|
182
|
+
// tool penuh — eskalasi terhadap ceiling WorkMode induk. Setter menerima fn
|
|
183
|
+
// (dibaca live saat delegate) bukan nilai, agar resume/Shift+Tab tak basi.
|
|
184
|
+
let subAgentWorkModeFn: () => WorkMode | undefined = () => undefined
|
|
185
|
+
|
|
186
|
+
export function setSubAgentWorkMode(fn: () => WorkMode | undefined): void {
|
|
187
|
+
subAgentWorkModeFn = fn
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** WorkMode induk saat ini (live), undefined = EXECUTE (perilaku lama). */
|
|
191
|
+
export function subAgentWorkMode(): WorkMode {
|
|
192
|
+
try {
|
|
193
|
+
return subAgentWorkModeFn() ?? "EXECUTE"
|
|
194
|
+
} catch {
|
|
195
|
+
return "EXECUTE"
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
106
199
|
export function setSubAgentParentRouting(c: SubAgentParentRouting): void {
|
|
107
200
|
parentRouting = {
|
|
108
201
|
...(c.rateLimiter ? { rateLimiter: c.rateLimiter } : {}),
|
|
@@ -173,7 +266,26 @@ export const delegateTaskTool: Tool = {
|
|
|
173
266
|
const parentMode = (ctx as unknown as { permissionMode?: string }).permissionMode
|
|
174
267
|
const forcedExplore = parentMode === "plan" || parentMode === "readonly" || parentMode === "ask"
|
|
175
268
|
const m = forcedExplore ? "explore" : ((mode as string) ?? "explore")
|
|
269
|
+
// P12 S2.2 — anak mewarisi WorkMode induk (intent layer, di-inject dari
|
|
270
|
+
// composition root via subAgentWorkMode). ToolContext.permissionMode hanya
|
|
271
|
+
// membawa PM (bukan WorkMode) dan vendor tak boleh diubah — jadi WorkMode
|
|
272
|
+
// induk disuntikkan. Tanpa ini jalur `PLAN × auto` (delegate_task
|
|
273
|
+
// di-approve, parentMode="auto" → forcedExplore=false) melahirkan anak
|
|
274
|
+
// `auto` mode "plan" dengan tool penuh: eskalasi ceiling WorkMode induk.
|
|
275
|
+
// Anak non-EXECUTE dipaksa workMode yang sama → ceiling handler anak
|
|
276
|
+
// menahan tulis (INV-WM1: WorkMode tak pernah memperluas akses).
|
|
277
|
+
const childWorkMode = subAgentWorkMode()
|
|
176
278
|
const requested = Number(maxSteps)
|
|
279
|
+
// P9.1 (ADR-25 — mode-specific contracts): DUA kontrak admission yang
|
|
280
|
+
// sengaja terpisah. Cabang fallback di bawah (tanpa maxSteps eksplisit)
|
|
281
|
+
// EKUIVALEN dengan M7 `modeStepCap` — keduanya membaca konstanta yang SAMA
|
|
282
|
+
// (SUB_AGENT_BUDGET_EXPLORE/PLAN); karena 5/15 < DEFAULT_MAX_STEPS, min-nya
|
|
283
|
+
// konstan-fold ke cap mode. Cabang eksplisit TIDAK diklamp ke cap mode
|
|
284
|
+
// (min(requested, 50)) — M7 justru `min(requested, modeCap)`, jadi lebih
|
|
285
|
+
// ketat; menyamakannya = perubahan perilaku observable (butuh ADR owner).
|
|
286
|
+
// Jalur autonomous TIDAK memakai M7: mode-less (readonly tetap) + default 8
|
|
287
|
+
// tak representable tanpa mengarang mode/grant. Kontrak dipin test
|
|
288
|
+
// `test/p9-admission-boundaries.test.ts`; jangan menyeragamkan tanpa ADR.
|
|
177
289
|
const cap =
|
|
178
290
|
Number.isFinite(requested) && requested > 0
|
|
179
291
|
? Math.min(Math.floor(requested), LIMITS.DEFAULT_MAX_STEPS)
|
|
@@ -201,12 +313,26 @@ export const delegateTaskTool: Tool = {
|
|
|
201
313
|
)
|
|
202
314
|
const subTools =
|
|
203
315
|
m === "explore" ? base.filter((t) => EXPLORE_TOOL_NAMES.includes(t.name)) : base
|
|
316
|
+
// P12 S2.2 — visibilitas tool anak mengikuti WorkMode (INV-WM1). Untuk
|
|
317
|
+
// child non-EXECUTE, tool tulis/eksekusi disembunyikan dari daftar agar
|
|
318
|
+
// model tidak buang langkah mencoba yang pasti ditolak ceiling (mis.
|
|
319
|
+
// parent PLAN×auto yang melahirkan anak workMode PLAN). Catatan: `base`
|
|
320
|
+
// di atas sudah membuang todo_write/delegate_task/submit_result (milik
|
|
321
|
+
// parent), jadi satu-satunya tool ekstra mode "plan" yang tersisa adalah
|
|
322
|
+
// file-write/bash — yang persis ingin disembunyikan ceiling WorkMode.
|
|
323
|
+
// EXPLORE_TOOL_NAMES adalah satu-satunya sumber read-only yang dipakai
|
|
324
|
+
// sesi utama (tool-layer), jadi anak memakai set yang sama — tanpa
|
|
325
|
+
// menduplikasi daftar.
|
|
326
|
+
const subToolsFiltered =
|
|
327
|
+
childWorkMode === "DISCUSS" || childWorkMode === "PLAN"
|
|
328
|
+
? subTools.filter((t) => EXPLORE_TOOL_NAMES.includes(t.name))
|
|
329
|
+
: subTools
|
|
204
330
|
// F-07: anak tidak punya bash_output/bash_kill (diamputasi di atas),
|
|
205
331
|
// sehingga background:true di anak = proses yatim di tabel job global:
|
|
206
332
|
// tak bisa dibaca, tak bisa di-kill, menghabiskan slot parent. Tolak
|
|
207
333
|
// eksplisit di sini (tool layer tahu ia membangun sesi anak; kernel
|
|
208
334
|
// tak perlu tahu konsep parent/anak).
|
|
209
|
-
const subToolsGuarded: Tool[] =
|
|
335
|
+
const subToolsGuarded: Tool[] = subToolsFiltered.map((t) => {
|
|
210
336
|
if (t.name !== "bash") return t
|
|
211
337
|
return {
|
|
212
338
|
...t,
|
|
@@ -219,44 +345,178 @@ export const delegateTaskTool: Tool = {
|
|
|
219
345
|
},
|
|
220
346
|
}
|
|
221
347
|
})
|
|
222
|
-
//
|
|
223
|
-
//
|
|
224
|
-
|
|
225
|
-
const parentCwd = (ctx as unknown as { cwd?: string })?.cwd ?? process.cwd()
|
|
348
|
+
// Child tools are wrapped with canonical P2.10 evidence after the child
|
|
349
|
+
// identity and authoritative domain exist (see below).
|
|
350
|
+
const parentCwd = ctx.cwd ?? process.cwd()
|
|
226
351
|
const parentId = todoSession.id || "main"
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
352
|
+
// P2.9: id anak = identitas Session KANONIK (128-bit). Id P1 lawas
|
|
353
|
+
// `sub_<8hex>` (32-bit) tidak cukup untuk durable authority; prefix `sub_`
|
|
354
|
+
// dipertahankan agar jurnal/presentasi/diagnostik tetap kompatibel.
|
|
355
|
+
const childId = allocateChildSessionId()
|
|
356
|
+
// P2.9 Model C: anak = Session + Thread + Run kanonik dengan lineage
|
|
357
|
+
// durable ke parent Session DAN parent Run. Dibuat SEBELUM factory
|
|
358
|
+
// (factory memasang presentation adapter yang menulis presentation_events)
|
|
359
|
+
// ⇒ tak ada lagi namespace anak tanpa baris `sessions` (cacat purge).
|
|
360
|
+
// P2.9: TUNGGU domain otoritatif SEBELUM operasi durable apa pun.
|
|
361
|
+
//
|
|
362
|
+
// `resolveDbPath` memilih global bila `<cwd>/.minicode` belum ada, sedangkan
|
|
363
|
+
// `acquireSessionWriter` → `new TaskStore` memakai `resolveLocalDbPath` yang
|
|
364
|
+
// SELALU membuat `<cwd>/.minicode`. Tanpa pin, urutannya jadi:
|
|
365
|
+
// createChildSession → DB global (karena .minicode belum ada)
|
|
366
|
+
// acquireSessionWriter → mkdir lokal + lease di tasks.db lokal
|
|
367
|
+
// transitionRun → resolveDbPath sekarang memilih LOKAL → "run not found"
|
|
368
|
+
// Satu siklus anak jatuh ke DUA DB. Pin-nya memakai pola NATIF yang sama
|
|
369
|
+
// dengan TaskStore (`resolveLocalDbPath`), sehingga domain sesi/thread/run/
|
|
370
|
+
// epoch/presentasi anak identik dengan domain yang sudah dipakai penulis
|
|
371
|
+
// parent (admission parent di cli/setup.ts juga membuat `.minicode` dulu —
|
|
372
|
+
// jadi pemilihan lokal di sini TIDAK memindahkan parent global yang sah;
|
|
373
|
+
// parent yang lewat setup memang sudah lokal).
|
|
374
|
+
let pinnedDb: string
|
|
375
|
+
try {
|
|
376
|
+
pinnedDb = resolveLocalDbPath("sessions.db", parentCwd)
|
|
377
|
+
} catch (e) {
|
|
378
|
+
return `[sub-agent error] REFUSED_CHILD_SESSION_PERSISTENCE: cannot resolve authoritative DB (${String(
|
|
379
|
+
(e as Error).message ?? e,
|
|
380
|
+
).slice(0, 200)})`
|
|
381
|
+
}
|
|
382
|
+
// Pin gagal (cwd tak bisa ditulis) = domain tak bisa dipastikan. Menulis
|
|
383
|
+
// anak sekarang berarti jatuh ke DB global yang tak terkait (polusi) —
|
|
384
|
+
// tolak dulu, sebelum satu baris pun dibuat.
|
|
385
|
+
if (!existsSync(dirname(pinnedDb))) {
|
|
386
|
+
return `[sub-agent error] REFUSED_CHILD_SESSION_PERSISTENCE: cannot pin authoritative DB at ${pinnedDb}`
|
|
387
|
+
}
|
|
388
|
+
let childRunId: string | null = null
|
|
389
|
+
let childEpoch: string | undefined
|
|
390
|
+
let childEpochHeld = false
|
|
391
|
+
// P2.9 FORENSIC: TANPA degradasi. Anak WAJIB kanonik — Session + Thread +
|
|
392
|
+
// Run — di DB yang sudah dipin di atas. `createChildSession` MEMATERIALISASIKAN
|
|
393
|
+
// baris parent yang belum ada dengan pola txn yang sama persis dengan
|
|
394
|
+
// ensureDefaultThreadInTxn/saveSession (§4: materialisasi, bukan melewatkan
|
|
395
|
+
// kanonisasi). Dulu ada gerbang `parentDurable` yang diam-diam menjatuhkan
|
|
396
|
+
// anak ke jalur jurnal-hantu `sub_*` tanpa baris `sessions` — itu persis
|
|
397
|
+
// yang dilarang: purger memakan presentation_events-nya dan pemulihan parent
|
|
398
|
+
// tak bisa menemukannya. Bila materialisasi/kanonisasi apa pun gagal →
|
|
399
|
+
// fail-closed (REFUSED_CHILD_SESSION_PERSISTENCE): delegasi tak jalan sama
|
|
400
|
+
// sekali, tidak pernah berjalan sebagai phantom namespace.
|
|
401
|
+
try {
|
|
402
|
+
const child = createChildSession({
|
|
403
|
+
parentSessionId: parentId,
|
|
404
|
+
parentRunId: subAgentParentRunId(),
|
|
405
|
+
cwd: parentCwd,
|
|
406
|
+
childSessionId: childId,
|
|
407
|
+
})
|
|
408
|
+
childRunId = child.runId
|
|
409
|
+
// Writer admission KHUSUS anak (P2.2 di-re-use): anak tak pernah menulis
|
|
410
|
+
// di bawah epoch parent — takeover parent tak mengikat epoch anak.
|
|
411
|
+
// Admission ditolak = anak tak punya otoritas penulis sendiri → gagal,
|
|
412
|
+
// jangan jalankan anak tanpa pagar epoch (invarian §15.6).
|
|
413
|
+
const admission = acquireSessionWriter({
|
|
414
|
+
sessionId: childId,
|
|
415
|
+
cwd: parentCwd,
|
|
416
|
+
bootId: `child-${childId}`,
|
|
417
|
+
})
|
|
418
|
+
if (!admission.ok) throw new Error(`writer admission refused: ${admission.error.message}`)
|
|
419
|
+
childEpoch = admission.admission.token
|
|
420
|
+
childEpochHeld = true
|
|
421
|
+
// P2.9: Run anak CREATED → RUNNING (P2.6 state machine, epoch anak).
|
|
422
|
+
transitionRun(childRunId, "RUNNING", parentCwd, {
|
|
423
|
+
expectedEpoch: readWriterEpoch(childId, parentCwd),
|
|
424
|
+
})
|
|
425
|
+
} catch (e) {
|
|
426
|
+
// Residu kanonis (bila ada) dimatikan SEBELUM menolak: tidak boleh ada
|
|
427
|
+
// Run anak RUNNING yang tak terlacak setelah delegasi menolak. Keadaan
|
|
428
|
+
// CREATED→INTERRUPTED sah (RUN_EDGES) — jadi residu juga bersih.
|
|
429
|
+
if (childRunId !== null) {
|
|
430
|
+
try {
|
|
431
|
+
interruptRun(childRunId, parentCwd, { recoveryStatus: "UNKNOWN" })
|
|
432
|
+
} catch {}
|
|
433
|
+
if (childEpoch !== undefined && childEpochHeld) {
|
|
434
|
+
try {
|
|
435
|
+
releaseSessionWriter(childId, childEpoch, parentCwd)
|
|
436
|
+
} catch {}
|
|
437
|
+
childEpochHeld = false
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
return `[sub-agent error] REFUSED_CHILD_SESSION_PERSISTENCE: ${String(
|
|
441
|
+
(e as Error).message ?? e,
|
|
442
|
+
).slice(0, 300)}`
|
|
443
|
+
}
|
|
444
|
+
// P2.10 canonical coverage for plain child tools. Delegate itself keeps
|
|
445
|
+
// its explicit parent-side intent; dotted tools are excluded by design.
|
|
446
|
+
const verifiedSubTools = subToolsGuarded.map((tool) =>
|
|
447
|
+
withEvidence(tool, {
|
|
448
|
+
sessionId: childId,
|
|
449
|
+
threadId: DEFAULT_THREAD_ID,
|
|
450
|
+
cwd: parentCwd,
|
|
451
|
+
childOf: parentId,
|
|
452
|
+
}),
|
|
453
|
+
)
|
|
454
|
+
const intent: EffectIntentResult = await persistEffectIntent({
|
|
455
|
+
sessionId: parentId,
|
|
456
|
+
threadId: DEFAULT_THREAD_ID,
|
|
230
457
|
tool: "delegate_task",
|
|
231
458
|
cwd: parentCwd,
|
|
232
459
|
childSessionId: childId,
|
|
233
|
-
|
|
460
|
+
args: { prompt: String(prompt), mode: m },
|
|
461
|
+
specialPath: "delegate-task",
|
|
234
462
|
})
|
|
463
|
+
// Canonical intent is also the fail-closed evidence gate: without a
|
|
464
|
+
// durable delegation identity the child must not start.
|
|
465
|
+
if (!intent.durable) {
|
|
466
|
+
return `[sub-agent error] REFUSED_VERIFICATION_EVIDENCE: durable EffectIntent unavailable for ${childId}`
|
|
467
|
+
}
|
|
235
468
|
let terminal: "committed" | "failed" = "committed"
|
|
236
469
|
// committed = delegasi benar-benar jalan di sesi anak (efeknya di jurnal
|
|
237
470
|
// anak). Factory/provider gagal = tak ada yang jalan = failed.
|
|
238
471
|
let childRan = false
|
|
472
|
+
// P9.2.1: observasi untuk amplop durable di receipt (tak mengubah string
|
|
473
|
+
// parent atau state receipt). Default konservatif = runner tak pernah
|
|
474
|
+
// jalan; tiap cabang yang mencapai runner menimpanya dengan bukti yang
|
|
475
|
+
// ada. Dua dimensi sengaja terpisah: `terminal` = protokol efek lama,
|
|
476
|
+
// `childStatus` = apa yang teramati dari turn anak.
|
|
477
|
+
let childStatus: ChildStatus = "failed_to_start"
|
|
478
|
+
let observedSummary: string | null = null
|
|
479
|
+
let observedSteps: number | null = null
|
|
480
|
+
let childAceVerdict: AceResultSnapshot | null = null
|
|
239
481
|
try {
|
|
240
482
|
const out = await pool.run(async () => {
|
|
241
483
|
ctx.signal.throwIfAborted()
|
|
242
484
|
// Cek factory dulu: fail-closed deterministik tanpa menyentuh config/env.
|
|
243
485
|
const factory = sessionFactory
|
|
244
|
-
if (!factory)
|
|
486
|
+
if (!factory) {
|
|
487
|
+
// P9.2.1: runner tak pernah jalan (`failed_to_start` default);
|
|
488
|
+
// ringkasan = string yang dilihat parent (tetap byte-identik).
|
|
489
|
+
observedSummary = "[sub-agent error] session factory not configured"
|
|
490
|
+
return observedSummary
|
|
491
|
+
}
|
|
245
492
|
let provider: Awaited<ReturnType<typeof getProvider>>
|
|
246
493
|
try {
|
|
247
494
|
provider = await getProvider()
|
|
248
495
|
} catch (e) {
|
|
249
|
-
|
|
496
|
+
observedSummary = `[sub-agent error] provider: ${(e as Error).message}`
|
|
497
|
+
return observedSummary
|
|
250
498
|
}
|
|
251
499
|
|
|
252
500
|
const session = await factory({
|
|
253
501
|
provider,
|
|
254
|
-
tools:
|
|
502
|
+
tools: verifiedSubTools,
|
|
255
503
|
cwd: parentCwd,
|
|
256
504
|
// Parent allowlist → anak allowlist (lihat komentar tipe di atas).
|
|
257
505
|
permissionMode: parentMode === "allowlist" ? "allowlist" : "auto",
|
|
506
|
+
// P12 S2.2 — child mewarisi WorkMode induk (ceiling WorkMode anak
|
|
507
|
+
// dipasang di createMinicodeSession oleh factory). EXECUTE = perilaku
|
|
508
|
+
// lama (tanpa ceiling tambahan).
|
|
509
|
+
workMode: childWorkMode,
|
|
258
510
|
maxSteps: cap,
|
|
259
511
|
timeoutMs: LIMITS.SUB_AGENT_TIMEOUT_MS,
|
|
512
|
+
// [Fase 7 / LOOP-INV-15] NoProgressDetector anak EKSPLISIT (bukan
|
|
513
|
+
// hanya default aktif): subagent explore/plan memang read-only, jadi
|
|
514
|
+
// stagnasi yang relevan adalah perulangan read yang tak membuahkan
|
|
515
|
+
// apa-apa. Ambang diturunkan dari 15 (default) ke 8 agar thrashing
|
|
516
|
+
// read-only terdeteksi lebih cepat dan anak berhenti deterministik
|
|
517
|
+
// dengan alasan no_progress_detected (bukan menggantung sampai
|
|
518
|
+
// SUB_AGENT_TIMEOUT habis).
|
|
519
|
+
noProgress: { maxConsecutiveReadCalls: 8 },
|
|
260
520
|
// Warisan model parent (audit #14): baca live dari ToolContext agar
|
|
261
521
|
// ikut /model mid-session; absen = default router seperti dulu.
|
|
262
522
|
...(() => {
|
|
@@ -316,11 +576,66 @@ export const delegateTaskTool: Tool = {
|
|
|
316
576
|
})
|
|
317
577
|
|
|
318
578
|
try {
|
|
319
|
-
|
|
320
|
-
|
|
579
|
+
// [P1 M15] Turn anak mengikuti admission runtime bila runtime punya
|
|
580
|
+
// sesi ini (mode `owned`); tanpa runner = perilaku lama persis.
|
|
581
|
+
// `parentExecutionId` memakai id anak yang sudah ada (dialihkan lewat
|
|
582
|
+
// M7 lewat admission M13), jadi lineage tetap satu parental, bukan
|
|
583
|
+
// dua mechanism penomoran.
|
|
584
|
+
const runChild = () => session.run(String(prompt), { signal: ctx.signal })
|
|
585
|
+
const runner = childExecutionRunner
|
|
586
|
+
// Parent lineage diambil dari runner (turn parent yang sedang berjalan),
|
|
587
|
+
// bukan dari ToolContext: vendor ToolContext tak membawa execution id,
|
|
588
|
+
// dan mengarangnya di sini berarti lineage child jadi mechanism kedua.
|
|
589
|
+
const parent = runner?.parentExecutionId() ?? undefined
|
|
590
|
+
const res = runner
|
|
591
|
+
? ((
|
|
592
|
+
await runner.run(
|
|
593
|
+
{
|
|
594
|
+
kind: "child",
|
|
595
|
+
schedulerSource: "delegate_task",
|
|
596
|
+
authorityHeld: true,
|
|
597
|
+
provenance: { requestedBy: "delegate_task", reason: `mode=${m}` },
|
|
598
|
+
...(parent ? { parentExecutionId: parent } : {}),
|
|
599
|
+
},
|
|
600
|
+
runChild,
|
|
601
|
+
{ signal: ctx.signal },
|
|
602
|
+
)
|
|
603
|
+
).result as Awaited<ReturnType<typeof runChild>>)
|
|
604
|
+
: await runChild()
|
|
605
|
+
// P9.2.1: runner kembali normal = observasi `returned`; string
|
|
606
|
+
// parent di bawah ini byte-identik dengan sebelum amplop ada.
|
|
607
|
+
childStatus = "returned"
|
|
608
|
+
observedSteps = res.usage?.steps ?? null
|
|
609
|
+
// String parent BYTE-IDENTIK dengan kontrak P9.2.1 yang lama — jangan
|
|
610
|
+
// ubah wording di sini karena test mengharapkan exact match. ACE-Lite
|
|
611
|
+
// verdict tetap tersurat dalam amplop durable (envelope.aceVerdict),
|
|
612
|
+
// tidak bocor ke observasi parent sebagai string terpisah.
|
|
613
|
+
// [Fase 9 / 9.1] Rollback switch: `MINICODE_ACE_ENABLED=0` → lewati
|
|
614
|
+
// evaluasi consequence; `childAceVerdict` tetap null (tanpa aceVerdict).
|
|
615
|
+
if (isAceEnabled()) {
|
|
616
|
+
childAceVerdict = evaluateConsequence({ verificationPassed: true })
|
|
617
|
+
}
|
|
618
|
+
observedSummary = `sub-agent (${m}) done: ${res.finalText?.slice(0, 2000) ?? "(no output)"} [steps ${res.usage.steps}]`
|
|
619
|
+
return observedSummary
|
|
321
620
|
} catch (e) {
|
|
322
621
|
const msg = e instanceof Error ? e.message : String(e)
|
|
323
|
-
|
|
622
|
+
// P9.2.1: turn anak lempar = klasifikasikan dari `kind`
|
|
623
|
+
// terstruktur (tak pernah dari wording pesan); string parent tetap
|
|
624
|
+
// byte-identik, receipt `state` tetap `committed` seperti dulu.
|
|
625
|
+
childStatus = classifyChildStatus(e)
|
|
626
|
+
// [Fase 7 / LOOP-INV-13/15] ACE verdict untuk jalur error: failure
|
|
627
|
+
// type dipetakan deterministik dari childStatus → verdict FAIL/BLOCKED
|
|
628
|
+
// sesuai consequence-engine. `timeout`/`aborted` = timeout; lainnya = functional.
|
|
629
|
+
// [Fase 9 / 9.1] Rollback switch: skip saat ACE disabled.
|
|
630
|
+
if (isAceEnabled()) {
|
|
631
|
+
childAceVerdict = evaluateConsequence({
|
|
632
|
+
verificationPassed: false,
|
|
633
|
+
failureType:
|
|
634
|
+
childStatus === "aborted" || childStatus === "timeout" ? "timeout" : "functional",
|
|
635
|
+
})
|
|
636
|
+
}
|
|
637
|
+
observedSummary = `[sub-agent ${m} error] ${msg.slice(0, 500)}`
|
|
638
|
+
return observedSummary
|
|
324
639
|
} finally {
|
|
325
640
|
offUsage()
|
|
326
641
|
offExec()
|
|
@@ -333,20 +648,101 @@ export const delegateTaskTool: Tool = {
|
|
|
333
648
|
// Abort/pool-reject: delegasi tak selesai → failed (ambigu, verifikasi).
|
|
334
649
|
// Efek anak yang telat tetap tercatat di jurnal ANAK, bukan di sini.
|
|
335
650
|
terminal = "failed"
|
|
651
|
+
// P9.2.1: penolakan sebelum runner jalan = `failed_to_start` (default
|
|
652
|
+
// di atas sudah benar); bila anak sempat jalan lalu jalurnya sendiri
|
|
653
|
+
// yang lempar di luar turn (praktis tak terjadi — turn ditangkap di
|
|
654
|
+
// dalam), pilih `error` konservatif: jalan tapi hasilnya tak pasti.
|
|
655
|
+
// Ringkasan memakai batas error 500 yang lama; tak ada string parent
|
|
656
|
+
// di jalur ini (lempar ulang), jadi amplop mencatat alasan penolakan.
|
|
657
|
+
const msg = e instanceof Error ? e.message : String(e)
|
|
658
|
+
if (observedSummary === null) observedSummary = msg.slice(0, 500)
|
|
659
|
+
if (childRan) childStatus = "error"
|
|
336
660
|
throw e
|
|
337
661
|
} finally {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
662
|
+
// P2.9: tutup Run anak secara durable SEBELUMmelepas epoch-nya —
|
|
663
|
+
// durable causality: efek terminal tercatat sebelum otoritas dicabut.
|
|
664
|
+
if (childRunId !== null) {
|
|
665
|
+
try {
|
|
666
|
+
const childEpochNow = readWriterEpoch(childId, parentCwd)
|
|
667
|
+
// P9.3.1: turn yang dipotong dari luar (timeout/abort terstruktur)
|
|
668
|
+
// BUKAN turn yang selesai — Run-nya INTERRUPTED/UNKNOWN, bukan
|
|
669
|
+
// COMPLETED. Receipt tetap `committed` (protokol efek tak tersentuh;
|
|
670
|
+
// delegasi memang jalan), string parent tak berubah, amplop sudah
|
|
671
|
+
// mencatat statusnya. Hanya dua status eksogen ini yang dipindah;
|
|
672
|
+
// `error`/`max_steps_exceeded` = turn berakhir oleh aturannya
|
|
673
|
+
// sendiri → tetap COMPLETED seperti dulu. Predikat via helper
|
|
674
|
+
// (bukan perbandingan inline) karena penugasan di closure pool-body
|
|
675
|
+
// tak terbaca CFA di situs finally.
|
|
676
|
+
const cutShort = childStatusOutcomeFlags(childStatus)
|
|
677
|
+
if (
|
|
678
|
+
terminal === "committed" &&
|
|
679
|
+
childRan &&
|
|
680
|
+
(cutShort.timeout === true || cutShort.aborted === true)
|
|
681
|
+
)
|
|
682
|
+
interruptRun(childRunId, parentCwd, {
|
|
683
|
+
expectedEpoch: childEpochNow,
|
|
684
|
+
recoveryStatus: "UNKNOWN",
|
|
685
|
+
})
|
|
686
|
+
else if (terminal === "committed" && childRan)
|
|
687
|
+
completeRun(childRunId, parentCwd, {
|
|
688
|
+
expectedEpoch: childEpochNow,
|
|
689
|
+
})
|
|
690
|
+
else if (terminal === "committed" && !childRan)
|
|
691
|
+
failRun(childRunId, parentCwd, {
|
|
692
|
+
expectedEpoch: childEpochNow,
|
|
693
|
+
})
|
|
694
|
+
else
|
|
695
|
+
interruptRun(childRunId, parentCwd, {
|
|
696
|
+
expectedEpoch: childEpochNow,
|
|
697
|
+
recoveryStatus: "UNKNOWN",
|
|
698
|
+
})
|
|
699
|
+
} catch {
|
|
700
|
+
// Terminalisasi gagal = residu RUNNING; sweep anak pada resume
|
|
701
|
+
// parent akan menombaknya (INTERRUPTED/UNKNOWN). Tidak pernah COMPLETED.
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
if (childEpochHeld && childEpoch) {
|
|
705
|
+
try {
|
|
706
|
+
releaseSessionWriter(childId, childEpoch, parentCwd)
|
|
707
|
+
} catch {}
|
|
708
|
+
}
|
|
709
|
+
// P9.2.1: amplop observasi durable di receipt yang sudah ada — BUKAN
|
|
710
|
+
// otoritas baru. `state`/`terminal` tak tersentuh (makna committed/
|
|
711
|
+
// failed persis seperti dulu); status anak, ringkasan, run, dan langkah
|
|
712
|
+
// tercatat sebagai observasi untuk pemulihan/diagnosis. Flag
|
|
713
|
+
// outcome-level memakai kosakata yang sudah ada (konsisten dengan
|
|
714
|
+
// summarizeObservedReturn), bukan status baru.
|
|
715
|
+
const envelope = buildChildResultEnvelope({
|
|
716
|
+
childStatus,
|
|
717
|
+
summary: observedSummary ?? "",
|
|
718
|
+
runId: childRunId,
|
|
719
|
+
steps: observedSteps,
|
|
720
|
+
...(childAceVerdict !== null ? { aceVerdict: childAceVerdict } : {}),
|
|
721
|
+
})
|
|
722
|
+
await persistEffectReceipt({
|
|
723
|
+
sessionId: parentId,
|
|
724
|
+
threadId: DEFAULT_THREAD_ID,
|
|
725
|
+
tool: "delegate_task",
|
|
726
|
+
cwd: parentCwd,
|
|
727
|
+
invocation: intent.invocation,
|
|
728
|
+
intent: {
|
|
729
|
+
id: intent.record.id,
|
|
730
|
+
seq: intent.record.seq,
|
|
731
|
+
tool: intent.record.tool,
|
|
732
|
+
session: intent.record.session,
|
|
733
|
+
...(intent.record.invocationId ? { invocationId: intent.record.invocationId } : {}),
|
|
734
|
+
...(intent.record.argsHash ? { argsHash: intent.record.argsHash } : {}),
|
|
735
|
+
},
|
|
736
|
+
state: terminal,
|
|
737
|
+
outcome: {
|
|
346
738
|
note: childId,
|
|
739
|
+
childResult: envelope,
|
|
740
|
+
...(envelope.truncated ? { truncated: true as const } : {}),
|
|
741
|
+
...childStatusOutcomeFlags(childStatus),
|
|
347
742
|
},
|
|
348
|
-
childId,
|
|
349
|
-
|
|
743
|
+
childSessionId: childId,
|
|
744
|
+
specialPath: "delegate-task",
|
|
745
|
+
})
|
|
350
746
|
}
|
|
351
747
|
},
|
|
352
748
|
}
|