minicode-ai 0.11.1 → 0.13.1
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 +95 -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/minicode.js +6 -0
- 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 +36 -6
- 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
|
@@ -84,12 +84,16 @@ export interface TurnSummary {
|
|
|
84
84
|
toolsInterrupted: number
|
|
85
85
|
filesChanged: number
|
|
86
86
|
checkpointId?: string
|
|
87
|
+
testSummary?: { passed: number; failed: number; summary: string }
|
|
88
|
+
evidenceComplete?: boolean
|
|
87
89
|
durationMs: number
|
|
88
90
|
}
|
|
89
91
|
|
|
90
92
|
/** Bukti konsekuensi (receipt) — view atas journal/checkpoint, bukan tracker baru. */
|
|
91
93
|
export interface Receipt {
|
|
92
94
|
toolCallId: string
|
|
95
|
+
sessionId?: string
|
|
96
|
+
turnId?: number
|
|
93
97
|
journalSeq?: number
|
|
94
98
|
checkpointId?: string
|
|
95
99
|
paths?: string[]
|
|
@@ -102,6 +106,7 @@ export interface Receipt {
|
|
|
102
106
|
export interface ContentRef {
|
|
103
107
|
toolCallId: string
|
|
104
108
|
idx: number
|
|
109
|
+
kind?: "output" | "diff" | "reasoning" | "diagnostic"
|
|
105
110
|
/** True bila store meng-evict entry (Fase 4): proyeksi tampilkan penanda retensi. */
|
|
106
111
|
dead?: boolean
|
|
107
112
|
}
|
|
@@ -124,6 +129,26 @@ interface Base {
|
|
|
124
129
|
ts: number
|
|
125
130
|
sessionId: string
|
|
126
131
|
turnId: number
|
|
132
|
+
// M1 correlator (ADR-002, additive-optional): korelasi execution tanpa
|
|
133
|
+
// mengganti domain identity. Absent = event legacy / jalur belum wiring
|
|
134
|
+
// (M10 yang memasang penuh); parser lama tetap membaca (decode hanya
|
|
135
|
+
// mensyaratkan Base + shape per-tipe, lihat persistence.ts).
|
|
136
|
+
/** Identity instance execution (allocated `exec_<UUIDv4>` / derived 32-hex). */
|
|
137
|
+
executionId?: string
|
|
138
|
+
/** Parent execution (absent pada root — bukan null/placeholder). */
|
|
139
|
+
parentExecutionId?: string
|
|
140
|
+
/** Root forest korelasi (immutable; retry/detach tak boleh rewrite — M7). */
|
|
141
|
+
rootExecutionId?: string
|
|
142
|
+
/** Kind datar M1: turn | tool_call | task | child | background. */
|
|
143
|
+
executionKind?: string
|
|
144
|
+
/** Owner menurut arsitektur (session/task id); bukan authority user input. */
|
|
145
|
+
ownerId?: string
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export interface UserMessageEvent extends Base {
|
|
149
|
+
type: "user.message"
|
|
150
|
+
text: string
|
|
151
|
+
promptRef: string
|
|
127
152
|
}
|
|
128
153
|
|
|
129
154
|
export interface TurnStartedEvent extends Base {
|
|
@@ -241,7 +266,118 @@ export interface ContextCompactedEvent extends Base {
|
|
|
241
266
|
reason: string
|
|
242
267
|
}
|
|
243
268
|
|
|
269
|
+
export type SemanticSeverity = "info" | "warning" | "error" | "critical"
|
|
270
|
+
export type PlanStepStatus = "pending" | "active" | "completed" | "cancelled" | "blocked"
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* One step of a plan.
|
|
274
|
+
*
|
|
275
|
+
* PHASE 3B: `taskId` is the canonical identity; `ordinal` is display position.
|
|
276
|
+
*
|
|
277
|
+
* `stepId` is NOT identity. It is a positional label (`String(i + 1)`) that
|
|
278
|
+
* predates canonical task ids and is still consumed by projection, reducer and
|
|
279
|
+
* ACP, so it is retained for compatibility and explicitly documented as
|
|
280
|
+
* non-canonical. It is also deliberately NOT mirrored from `taskId`: mirroring
|
|
281
|
+
* would change what existing consumers observe.
|
|
282
|
+
*
|
|
283
|
+
* Both new fields are OPTIONAL and additive. Durable `plan.updated` rows written
|
|
284
|
+
* before this change carry neither, and still satisfy the `isValidEventShape`
|
|
285
|
+
* gate in `src/session/persistence.ts`, so replay is unaffected.
|
|
286
|
+
*/
|
|
287
|
+
export interface PlanStep {
|
|
288
|
+
/** Positional compatibility label. NOT canonical identity. */
|
|
289
|
+
stepId: string
|
|
290
|
+
/** Canonical TaskStore identity (`t<n>`), present only on payloadVersion=2. */
|
|
291
|
+
taskId?: string
|
|
292
|
+
/** Display position within the plan. Explicitly not identity. */
|
|
293
|
+
ordinal?: number
|
|
294
|
+
title?: string
|
|
295
|
+
status: PlanStepStatus
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export interface PlanUpdatedEvent extends Base {
|
|
299
|
+
type: "plan.updated"
|
|
300
|
+
planId: string
|
|
301
|
+
status: "open" | "completed" | "cancelled"
|
|
302
|
+
/**
|
|
303
|
+
* `2` means step identity is `taskId`-based and every step carries a
|
|
304
|
+
* `taskId`. Absent means positional `stepId` only. The adapter emits `2` only
|
|
305
|
+
* when identity resolution is total, so `payloadVersion === 2` is a truthful
|
|
306
|
+
* statement that this event carries no positional identity.
|
|
307
|
+
*/
|
|
308
|
+
payloadVersion?: 2
|
|
309
|
+
steps: PlanStep[]
|
|
310
|
+
expandRef?: ContentRef
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
export interface FindingDetectedEvent extends Base {
|
|
314
|
+
type: "finding.detected"
|
|
315
|
+
findingId: string
|
|
316
|
+
category: string
|
|
317
|
+
severity: SemanticSeverity
|
|
318
|
+
summary: string
|
|
319
|
+
evidence?: string[]
|
|
320
|
+
/** Forward anak: taut ke delegate_task pemanggil (absen = finding sesi biasa). */
|
|
321
|
+
parentLink?: ChildSessionLink
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
export interface ResultProducedEvent extends Base {
|
|
325
|
+
type: "result.produced"
|
|
326
|
+
resultId: string
|
|
327
|
+
status: "completed" | "failed" | "cancelled"
|
|
328
|
+
summary: string
|
|
329
|
+
action?: string
|
|
330
|
+
expandRef?: ContentRef
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export interface DiagnosticRaisedEvent extends Base {
|
|
334
|
+
type: "diagnostic.raised"
|
|
335
|
+
category: string
|
|
336
|
+
severity: SemanticSeverity
|
|
337
|
+
message: string
|
|
338
|
+
cause?: string
|
|
339
|
+
action?: string
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
export interface CheckpointCreatedEvent extends Base {
|
|
343
|
+
type: "checkpoint.created"
|
|
344
|
+
checkpointId: string
|
|
345
|
+
paths?: string[]
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Observasi verifikasi P2.11 — BUKAN bukti baru, melainkan proyeksi observasi
|
|
350
|
+
* atas intent/terminal/verdict yang sudah durable di jurnal mutasi.
|
|
351
|
+
*
|
|
352
|
+
* `verdict` hanya present|absent|inconclusive: ketiadaan event ini untuk suatu
|
|
353
|
+
* invokasi berarti UNKNOWN (diturunkan di proyeksi, bukan di sini). Event ini
|
|
354
|
+
* tidak pernah mengubah status/history/lifecycle activity — hanya menempelkan
|
|
355
|
+
* `verification` untuk display. `evidenceReference` TIDAK dibawa ke sini
|
|
356
|
+
* (tetap di jurnal); yang dibawa hanya identitas + verdict + metode.
|
|
357
|
+
*/
|
|
358
|
+
export type VerificationDisplayVerdict = "present" | "absent" | "inconclusive"
|
|
359
|
+
|
|
360
|
+
/** Tampilan verifikasi per activity — observasi, bukan otoritas efek. */
|
|
361
|
+
export interface VerificationDisplay {
|
|
362
|
+
invocationId: string
|
|
363
|
+
verdict: VerificationDisplayVerdict
|
|
364
|
+
method: string
|
|
365
|
+
observedAt: number
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
export interface VerificationObservedEvent extends Base {
|
|
369
|
+
type: "verification.observed"
|
|
370
|
+
toolCallId: string
|
|
371
|
+
invocationId: string
|
|
372
|
+
verdict: VerificationDisplayVerdict
|
|
373
|
+
method: string
|
|
374
|
+
observedAt: number
|
|
375
|
+
/** Forward anak: taut ke delegate_task pemanggil (absen = observasi sesi biasa). */
|
|
376
|
+
parentLink?: ChildSessionLink
|
|
377
|
+
}
|
|
378
|
+
|
|
244
379
|
export type DomainEvent =
|
|
380
|
+
| UserMessageEvent
|
|
245
381
|
| TurnStartedEvent
|
|
246
382
|
| TurnCompletedEvent
|
|
247
383
|
| TurnFailedEvent
|
|
@@ -261,11 +397,20 @@ export type DomainEvent =
|
|
|
261
397
|
| FileChangedEvent
|
|
262
398
|
| TestCompletedEvent
|
|
263
399
|
| ContextCompactedEvent
|
|
400
|
+
| PlanUpdatedEvent
|
|
401
|
+
| FindingDetectedEvent
|
|
402
|
+
| ResultProducedEvent
|
|
403
|
+
| DiagnosticRaisedEvent
|
|
404
|
+
| CheckpointCreatedEvent
|
|
405
|
+
| VerificationObservedEvent
|
|
264
406
|
|
|
265
407
|
export type DomainEventType = DomainEvent["type"]
|
|
266
408
|
|
|
409
|
+
export const PROPOSED_EVENT_TYPES = ["tool.progress"] as const satisfies readonly DomainEventType[]
|
|
410
|
+
|
|
267
411
|
/** Kebijakan durable vs live (§7 V2.1): restart merekonstruksi tanpa delta. */
|
|
268
412
|
export const DURABILITY: Record<DomainEventType, { durable: boolean; replayable: boolean }> = {
|
|
413
|
+
"user.message": { durable: true, replayable: true },
|
|
269
414
|
"turn.started": { durable: true, replayable: true },
|
|
270
415
|
"turn.completed": { durable: true, replayable: true },
|
|
271
416
|
"turn.failed": { durable: true, replayable: true },
|
|
@@ -285,6 +430,12 @@ export const DURABILITY: Record<DomainEventType, { durable: boolean; replayable:
|
|
|
285
430
|
"file.changed": { durable: true, replayable: true },
|
|
286
431
|
"test.completed": { durable: true, replayable: true },
|
|
287
432
|
"context.compacted": { durable: true, replayable: true },
|
|
433
|
+
"plan.updated": { durable: true, replayable: true },
|
|
434
|
+
"finding.detected": { durable: true, replayable: true },
|
|
435
|
+
"result.produced": { durable: true, replayable: true },
|
|
436
|
+
"diagnostic.raised": { durable: true, replayable: true },
|
|
437
|
+
"checkpoint.created": { durable: true, replayable: true },
|
|
438
|
+
"verification.observed": { durable: true, replayable: true },
|
|
288
439
|
}
|
|
289
440
|
|
|
290
441
|
/**
|
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
// Bentuk state presentasi V2.1 (§14 plan) — murni tipe + konstruktor.
|
|
2
|
-
//
|
|
3
|
-
// Kenapa terpisah dari reducer: proyeksi dan cli boleh mengimpor tipe tanpa
|
|
4
|
-
// menarik logika reduce; coverage floor reducer diuji terpisah. Tanpa IO/
|
|
5
|
-
// clock/env — jam hanya di adapter (tepi).
|
|
6
|
-
|
|
7
1
|
import type {
|
|
8
2
|
ApprovalOutcome,
|
|
9
3
|
ContentRef,
|
|
10
4
|
DenyReason,
|
|
11
5
|
FailCause,
|
|
6
|
+
PlanStep,
|
|
12
7
|
Receipt,
|
|
8
|
+
SemanticSeverity,
|
|
13
9
|
ToolIdentity,
|
|
14
10
|
TurnSummary,
|
|
11
|
+
VerificationDisplay,
|
|
15
12
|
} from "./events.ts"
|
|
16
13
|
|
|
17
|
-
/** Status final tool — `running` hanya live; `interrupted` disimpulkan saat rebuild. */
|
|
18
14
|
export type ToolStatus = "running" | "completed" | "failed" | "denied" | "cancelled" | "interrupted"
|
|
19
|
-
|
|
20
|
-
/** Status final turn — `interrupted` = proses mati tanpa turn-settle durable. */
|
|
21
15
|
export type TurnStatus = "running" | "completed" | "failed" | "cancelled" | "interrupted"
|
|
16
|
+
export type PlanStatus = "open" | "completed" | "cancelled"
|
|
17
|
+
export type ResultStatus = "completed" | "failed" | "cancelled"
|
|
18
|
+
export type SystemKind = "context_compacted" | "recovery" | "checkpoint" | "notice"
|
|
19
|
+
export const MAX_STATE_ENTRIES = 4096
|
|
22
20
|
|
|
23
21
|
export interface ActivityEntry {
|
|
24
22
|
kind: "tool"
|
|
@@ -34,7 +32,6 @@ export interface ActivityEntry {
|
|
|
34
32
|
tsStart: number
|
|
35
33
|
tsEnd?: number
|
|
36
34
|
durationMs?: number
|
|
37
|
-
/** eventSeq terminal — dasar aturan supersedes (old terminal < new started). */
|
|
38
35
|
endSeq?: number
|
|
39
36
|
progress?: string
|
|
40
37
|
summary?: string
|
|
@@ -44,8 +41,9 @@ export interface ActivityEntry {
|
|
|
44
41
|
approvalId?: string
|
|
45
42
|
expandRef?: ContentRef
|
|
46
43
|
receipt?: Receipt
|
|
47
|
-
/** Terminal tanpa tool.started (race/crash) — observability, jangan throw. */
|
|
48
44
|
incomplete?: boolean
|
|
45
|
+
/** Observasi verifikasi terakhir (last-wins); absen = UNKNOWN. */
|
|
46
|
+
verification?: VerificationDisplay
|
|
49
47
|
}
|
|
50
48
|
|
|
51
49
|
export interface TurnEntry {
|
|
@@ -53,17 +51,21 @@ export interface TurnEntry {
|
|
|
53
51
|
seq: number
|
|
54
52
|
turnId: number
|
|
55
53
|
sessionId: string
|
|
54
|
+
promptRef?: string
|
|
56
55
|
status: TurnStatus
|
|
57
56
|
tsStart: number
|
|
58
57
|
tsEnd?: number
|
|
59
58
|
summary?: TurnSummary
|
|
60
59
|
error?: string
|
|
60
|
+
checkpointId?: string
|
|
61
|
+
evidenceComplete?: boolean
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
export interface ApprovalEntry {
|
|
64
65
|
kind: "approval"
|
|
65
66
|
seq: number
|
|
66
67
|
turnId: number
|
|
68
|
+
sessionId: string
|
|
67
69
|
approvalId: string
|
|
68
70
|
toolCallId: string
|
|
69
71
|
identity: ToolIdentity
|
|
@@ -73,17 +75,23 @@ export interface ApprovalEntry {
|
|
|
73
75
|
|
|
74
76
|
export interface ConversationEntry {
|
|
75
77
|
kind: "message"
|
|
78
|
+
id: string
|
|
76
79
|
seq: number
|
|
80
|
+
sessionId: string
|
|
77
81
|
turnId: number
|
|
78
82
|
role: "user" | "assistant"
|
|
79
83
|
text: string
|
|
80
84
|
truncated: boolean
|
|
85
|
+
promptRef?: string
|
|
86
|
+
sourceRef?: string
|
|
81
87
|
expandRef?: ContentRef
|
|
82
88
|
}
|
|
83
89
|
|
|
84
90
|
export interface ReasoningEntry {
|
|
85
91
|
kind: "reasoning"
|
|
92
|
+
id: string
|
|
86
93
|
seq: number
|
|
94
|
+
sessionId: string
|
|
87
95
|
turnId: number
|
|
88
96
|
truncated: boolean
|
|
89
97
|
expandRef: ContentRef
|
|
@@ -91,9 +99,63 @@ export interface ReasoningEntry {
|
|
|
91
99
|
|
|
92
100
|
export interface SystemEntry {
|
|
93
101
|
kind: "system"
|
|
102
|
+
id: string
|
|
94
103
|
seq: number
|
|
104
|
+
sessionId: string
|
|
95
105
|
turnId: number
|
|
106
|
+
systemKind: SystemKind
|
|
96
107
|
text: string
|
|
108
|
+
reason?: string
|
|
109
|
+
severity: SemanticSeverity
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface PlanEntry {
|
|
113
|
+
kind: "plan"
|
|
114
|
+
planId: string
|
|
115
|
+
seq: number
|
|
116
|
+
sessionId: string
|
|
117
|
+
turnId: number
|
|
118
|
+
status: PlanStatus
|
|
119
|
+
steps: PlanStep[]
|
|
120
|
+
expandRef?: ContentRef
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface FindingEntry {
|
|
124
|
+
kind: "finding"
|
|
125
|
+
findingId: string
|
|
126
|
+
seq: number
|
|
127
|
+
sessionId: string
|
|
128
|
+
turnId: number
|
|
129
|
+
category: string
|
|
130
|
+
severity: SemanticSeverity
|
|
131
|
+
summary: string
|
|
132
|
+
evidence: string[]
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export interface ResultEntry {
|
|
136
|
+
kind: "result"
|
|
137
|
+
resultId: string
|
|
138
|
+
seq: number
|
|
139
|
+
sessionId: string
|
|
140
|
+
turnId: number
|
|
141
|
+
status: ResultStatus
|
|
142
|
+
summary: string
|
|
143
|
+
action?: string
|
|
144
|
+
expandRef?: ContentRef
|
|
145
|
+
receipt?: Receipt
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export interface DiagnosticEntry {
|
|
149
|
+
kind: "diagnostic"
|
|
150
|
+
id: string
|
|
151
|
+
seq: number
|
|
152
|
+
sessionId: string
|
|
153
|
+
turnId: number
|
|
154
|
+
category: string
|
|
155
|
+
severity: SemanticSeverity
|
|
156
|
+
message: string
|
|
157
|
+
cause?: string
|
|
158
|
+
action?: string
|
|
97
159
|
}
|
|
98
160
|
|
|
99
161
|
export type PresentationEntry =
|
|
@@ -103,30 +165,41 @@ export type PresentationEntry =
|
|
|
103
165
|
| ConversationEntry
|
|
104
166
|
| ReasoningEntry
|
|
105
167
|
| SystemEntry
|
|
168
|
+
| PlanEntry
|
|
169
|
+
| FindingEntry
|
|
170
|
+
| ResultEntry
|
|
171
|
+
| DiagnosticEntry
|
|
172
|
+
|
|
173
|
+
export type PresentationEntryKind = PresentationEntry["kind"]
|
|
106
174
|
|
|
107
|
-
/** Penunjuk urutan tampil — resolve ke entry via Map/array pemilik. */
|
|
108
175
|
export interface EntryRef {
|
|
109
|
-
kind:
|
|
110
|
-
|
|
176
|
+
kind: PresentationEntryKind
|
|
177
|
+
id: string
|
|
178
|
+
seq: number
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export interface EvictionMarker {
|
|
182
|
+
kind: PresentationEntryKind
|
|
111
183
|
id: string
|
|
112
184
|
seq: number
|
|
185
|
+
reason: "bounded"
|
|
113
186
|
}
|
|
114
187
|
|
|
115
|
-
/**
|
|
116
|
-
* Core state presentasi — kecil, replayable; konten besar hanya via ContentRef
|
|
117
|
-
* (ContentStore sibling Fase 4, bukan nested di sini).
|
|
118
|
-
*/
|
|
119
188
|
export interface PresentationState {
|
|
120
189
|
sessionId: string
|
|
121
|
-
/** eventSeq terakhir yang diterapkan — basis replay/determinisme. */
|
|
122
190
|
seq: number
|
|
123
|
-
/** key = `${sessionId}:${turnId}` (anak numbering sendiri). */
|
|
124
191
|
turns: Map<string, TurnEntry>
|
|
125
|
-
/** key = `${sessionId}:${toolCallId}`. */
|
|
126
192
|
activities: Map<string, ActivityEntry>
|
|
127
193
|
approvals: Map<string, ApprovalEntry>
|
|
128
194
|
conversation: ConversationEntry[]
|
|
195
|
+
reasoning: ReasoningEntry[]
|
|
196
|
+
system: SystemEntry[]
|
|
197
|
+
plans: Map<string, PlanEntry>
|
|
198
|
+
findings: Map<string, FindingEntry>
|
|
199
|
+
results: Map<string, ResultEntry>
|
|
200
|
+
diagnostics: DiagnosticEntry[]
|
|
129
201
|
order: EntryRef[]
|
|
202
|
+
evicted: EvictionMarker[]
|
|
130
203
|
}
|
|
131
204
|
|
|
132
205
|
export function turnKey(sessionId: string, turnId: number): string {
|
|
@@ -137,6 +210,33 @@ export function activityKey(sessionId: string, toolCallId: string): string {
|
|
|
137
210
|
return `${sessionId}:${toolCallId}`
|
|
138
211
|
}
|
|
139
212
|
|
|
213
|
+
export function approvalKey(sessionId: string, approvalId: string): string {
|
|
214
|
+
return `${sessionId}:${approvalId}`
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export function conversationKey(
|
|
218
|
+
sessionId: string,
|
|
219
|
+
turnId: number,
|
|
220
|
+
role: "user" | "assistant",
|
|
221
|
+
): string {
|
|
222
|
+
return `${sessionId}:${turnId}:${role}`
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function copyRef(ref: ContentRef | undefined): ContentRef | undefined {
|
|
226
|
+
return ref ? { ...ref } : undefined
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function copyReceipt(receipt: Receipt | undefined): Receipt | undefined {
|
|
230
|
+
if (!receipt) return undefined
|
|
231
|
+
return {
|
|
232
|
+
...receipt,
|
|
233
|
+
...(receipt.paths ? { paths: [...receipt.paths] } : {}),
|
|
234
|
+
...(receipt.stats ? { stats: { ...receipt.stats } } : {}),
|
|
235
|
+
...(receipt.test ? { test: { ...receipt.test } } : {}),
|
|
236
|
+
...(receipt.cmd ? { cmd: { ...receipt.cmd } } : {}),
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
140
240
|
export function createInitialState(sessionId: string): PresentationState {
|
|
141
241
|
return {
|
|
142
242
|
sessionId,
|
|
@@ -145,28 +245,81 @@ export function createInitialState(sessionId: string): PresentationState {
|
|
|
145
245
|
activities: new Map(),
|
|
146
246
|
approvals: new Map(),
|
|
147
247
|
conversation: [],
|
|
248
|
+
reasoning: [],
|
|
249
|
+
system: [],
|
|
250
|
+
plans: new Map(),
|
|
251
|
+
findings: new Map(),
|
|
252
|
+
results: new Map(),
|
|
253
|
+
diagnostics: [],
|
|
148
254
|
order: [],
|
|
255
|
+
evicted: [],
|
|
149
256
|
}
|
|
150
257
|
}
|
|
151
258
|
|
|
152
|
-
/** Snapshot deep-equal-friendly (test determinisme/replay; bukan jalur panas). */
|
|
153
259
|
export function cloneState(s: PresentationState): PresentationState {
|
|
154
260
|
return {
|
|
155
261
|
sessionId: s.sessionId,
|
|
156
262
|
seq: s.seq,
|
|
157
|
-
turns: new Map(
|
|
263
|
+
turns: new Map(
|
|
264
|
+
[...s.turns].map(([k, v]) => [
|
|
265
|
+
k,
|
|
266
|
+
{
|
|
267
|
+
...v,
|
|
268
|
+
...(v.summary ? { summary: { ...v.summary } } : {}),
|
|
269
|
+
},
|
|
270
|
+
]),
|
|
271
|
+
),
|
|
158
272
|
activities: new Map(
|
|
159
273
|
[...s.activities].map(([k, v]) => [
|
|
160
274
|
k,
|
|
161
275
|
{
|
|
162
276
|
...v,
|
|
163
|
-
|
|
164
|
-
|
|
277
|
+
identity: { ...v.identity },
|
|
278
|
+
...(v.error ? { error: { ...v.error } } : {}),
|
|
279
|
+
...(v.expandRef ? { expandRef: copyRef(v.expandRef) } : {}),
|
|
280
|
+
receipt: copyReceipt(v.receipt),
|
|
281
|
+
},
|
|
282
|
+
]),
|
|
283
|
+
),
|
|
284
|
+
approvals: new Map(
|
|
285
|
+
[...s.approvals].map(([k, v]) => [
|
|
286
|
+
k,
|
|
287
|
+
{
|
|
288
|
+
...v,
|
|
289
|
+
identity: { ...v.identity },
|
|
290
|
+
...(v.outcome ? { outcome: { ...v.outcome } } : {}),
|
|
291
|
+
},
|
|
292
|
+
]),
|
|
293
|
+
),
|
|
294
|
+
conversation: s.conversation.map((m) => ({
|
|
295
|
+
...m,
|
|
296
|
+
...(m.expandRef ? { expandRef: copyRef(m.expandRef) } : {}),
|
|
297
|
+
})),
|
|
298
|
+
reasoning: s.reasoning.map((r) => ({ ...r, expandRef: { ...r.expandRef } })),
|
|
299
|
+
system: s.system.map((e) => ({ ...e })),
|
|
300
|
+
plans: new Map(
|
|
301
|
+
[...s.plans].map(([k, v]) => [
|
|
302
|
+
k,
|
|
303
|
+
{
|
|
304
|
+
...v,
|
|
305
|
+
steps: v.steps.map((step) => ({ ...step })),
|
|
306
|
+
...(v.expandRef ? { expandRef: copyRef(v.expandRef) } : {}),
|
|
307
|
+
},
|
|
308
|
+
]),
|
|
309
|
+
),
|
|
310
|
+
findings: new Map([...s.findings].map(([k, v]) => [k, { ...v, evidence: [...v.evidence] }])),
|
|
311
|
+
results: new Map(
|
|
312
|
+
[...s.results].map(([k, v]) => [
|
|
313
|
+
k,
|
|
314
|
+
{
|
|
315
|
+
...v,
|
|
316
|
+
...(v.expandRef ? { expandRef: copyRef(v.expandRef) } : {}),
|
|
317
|
+
receipt: copyReceipt(v.receipt),
|
|
165
318
|
},
|
|
166
319
|
]),
|
|
167
320
|
),
|
|
168
|
-
|
|
169
|
-
conversation: s.conversation.map((m) => ({ ...m })),
|
|
321
|
+
diagnostics: s.diagnostics.map((d) => ({ ...d })),
|
|
170
322
|
order: s.order.map((o) => ({ ...o })),
|
|
323
|
+
evicted: s.evicted.map((e) => ({ ...e })),
|
|
171
324
|
}
|
|
172
325
|
}
|