minicode-ai 0.13.0 → 0.14.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 +23 -0
- package/LICENSE +21 -21
- package/README.md +4 -0
- package/cli/args.ts +50 -2
- package/cli/commands/acp.ts +18 -3
- package/cli/commands/daemon.ts +114 -19
- package/cli/commands/exec.ts +95 -7
- package/cli/commands/mcp.ts +66 -5
- package/cli/commands/memory.ts +46 -14
- package/cli/commands.ts +5 -0
- package/cli/index.ts +30 -5
- package/cli/minicode.js +6 -0
- package/cli/setup.ts +365 -24
- package/cli/tui.ts +72 -27
- package/docs/TERMINAL_CONTRACT.md +91 -24
- package/docs/agents.md +2 -2
- package/docs/cli.md +1 -0
- package/docs/environment.md +1 -0
- package/docs/memory-sessions.md +5 -0
- package/package.json +3 -2
- package/src/app/session.ts +153 -35
- package/src/app/tool-layer.ts +67 -61
- package/src/daemon/approvals.ts +25 -1
- package/src/daemon/client.ts +51 -1
- package/src/daemon/control.ts +8 -0
- package/src/daemon/protocol.ts +47 -1
- package/src/daemon/server.ts +45 -9
- package/src/daemon/subscription.ts +25 -1
- package/src/daemon/telemetry.ts +4 -0
- package/src/hooks/run.ts +5 -1
- package/src/mcp/client.ts +349 -90
- package/src/mcp/http-transport.ts +7 -0
- package/src/mcp/transport.ts +5 -0
- package/src/memory/files.ts +69 -3
- package/src/memory/vector.ts +556 -160
- package/src/policy/approval-binding.ts +199 -0
- package/src/policy/context.ts +20 -1
- package/src/policy/executor.ts +44 -5
- package/src/policy/permission.ts +243 -26
- package/src/policy/tool-contract.ts +77 -0
- package/src/policy/usage.ts +3 -1
- package/src/policy/work-mode.ts +49 -1
- package/src/presentation/adapter.ts +157 -7
- package/src/presentation/events.ts +173 -1
- package/src/presentation/model.ts +37 -0
- package/src/presentation/projection.ts +107 -18
- package/src/presentation/reducer.ts +134 -10
- package/src/sandbox/os.ts +18 -1
- package/src/session/persistence.ts +153 -11
- package/src/task/store.ts +43 -3
- package/src/tools/memory.ts +70 -10
- package/src/tools/task.ts +7 -1
- package/src/tools/todo.ts +14 -4
- package/src/ui/approval/prompt.ts +52 -7
- package/src/ui/assistant/simple.ts +160 -57
- package/src/ui/contract.ts +46 -0
- package/src/ui/footer.ts +14 -5
- package/src/ui/i18n/en.ts +9 -0
- package/src/ui/i18n/id.ts +9 -0
- package/src/ui/render/collapse.ts +24 -52
- package/src/ui/render/detail.ts +14 -9
- package/src/ui/render/errors.ts +8 -0
- package/src/ui/render/reasoning.ts +13 -8
- package/src/ui/session-state.ts +243 -0
- package/src/ui/tui/app.ts +7 -3
- package/src/ui/tui/transcript.ts +271 -30
- 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
|
@@ -23,15 +23,21 @@ import type {
|
|
|
23
23
|
ArgsSummary,
|
|
24
24
|
CancelReason,
|
|
25
25
|
ChildSessionLink,
|
|
26
|
+
ConsequenceFailureClass,
|
|
27
|
+
ConsequenceNextAction,
|
|
28
|
+
ConsequenceVerdict,
|
|
26
29
|
DomainEvent,
|
|
27
30
|
EventBusLike,
|
|
28
31
|
FailCause,
|
|
32
|
+
McpSchemaDrift,
|
|
29
33
|
PlanStep,
|
|
30
34
|
SemanticSeverity,
|
|
35
|
+
TaskStatusDisplay,
|
|
31
36
|
ToolIdentity,
|
|
32
37
|
TurnSummary,
|
|
33
38
|
VerificationDisplayVerdict,
|
|
34
39
|
} from "./events.ts"
|
|
40
|
+
import { EVENT_SCHEMA_VERSION } from "./events.ts"
|
|
35
41
|
import { type ContentStore, MAX_SECTION_CHARS } from "./store.ts"
|
|
36
42
|
|
|
37
43
|
export interface AdapterDiagnostics {
|
|
@@ -125,6 +131,41 @@ export interface PresentationAdapter {
|
|
|
125
131
|
turnId?: number
|
|
126
132
|
parentLink?: ChildSessionLink
|
|
127
133
|
}): void
|
|
134
|
+
/** F-CTRL-1: terbitkan `consequence.decided` dari keputusan ACE (policy). */
|
|
135
|
+
noteConsequenceDecided(info: {
|
|
136
|
+
verdict: ConsequenceVerdict
|
|
137
|
+
failureClass: ConsequenceFailureClass
|
|
138
|
+
nextAction: ConsequenceNextAction
|
|
139
|
+
rationale: string
|
|
140
|
+
newEvidenceSinceLastAttempt?: boolean
|
|
141
|
+
turnId?: number
|
|
142
|
+
}): void
|
|
143
|
+
/** F-CTX-1: meter jendela konteks live (non-durable). */
|
|
144
|
+
noteContextWindow(info: {
|
|
145
|
+
usedTokens: number
|
|
146
|
+
windowTokens: number
|
|
147
|
+
percent?: number
|
|
148
|
+
costUsd?: number
|
|
149
|
+
providerModel?: string
|
|
150
|
+
turnId?: number
|
|
151
|
+
}): void
|
|
152
|
+
/** F-CTX-2: pemotongan mi-stream yang durable (masuk transkrip). */
|
|
153
|
+
noteContextCutoff(info: {
|
|
154
|
+
reason: string
|
|
155
|
+
usedTokens?: number
|
|
156
|
+
windowTokens?: number
|
|
157
|
+
turnId?: number
|
|
158
|
+
}): void
|
|
159
|
+
/** F-TASK-1: transisi status task kanonik + DAG. */
|
|
160
|
+
noteTaskStatus(info: {
|
|
161
|
+
taskId: string
|
|
162
|
+
status: TaskStatusDisplay
|
|
163
|
+
parentId?: string
|
|
164
|
+
dependsOn?: string[]
|
|
165
|
+
revision?: number
|
|
166
|
+
verification?: { verdict: "passed" | "failed" | "unverified"; checkedAt: string }
|
|
167
|
+
turnId?: number
|
|
168
|
+
}): void
|
|
128
169
|
setTurnSummaryProvider(provider: TurnSummaryProvider | undefined): void
|
|
129
170
|
getDiagnostics(): AdapterDiagnostics
|
|
130
171
|
dispose(): void
|
|
@@ -194,6 +235,18 @@ function mapToolFailCause(content: unknown): FailCause {
|
|
|
194
235
|
return "exec"
|
|
195
236
|
}
|
|
196
237
|
|
|
238
|
+
/**
|
|
239
|
+
* F-TOOL-1: deteksi drift skema MCP dari marker error terstruktur
|
|
240
|
+
* (`mcpSchemaDriftError` di `src/mcp/client.ts`) menjadi `McpSchemaDrift`
|
|
241
|
+
* terstruktur — BUKAN string mentah. Balanced, bukan menebak teks bebas.
|
|
242
|
+
*/
|
|
243
|
+
function detectSchemaDrift(content: unknown): McpSchemaDrift | undefined {
|
|
244
|
+
const text = typeof content === "string" ? content : contentText(content)
|
|
245
|
+
const m = /MCP_SCHEMA_DRIFT_DETECTED:\s*tool\s+"([^"]+)\.([^"]+)"/.exec(text)
|
|
246
|
+
if (!m) return undefined
|
|
247
|
+
return { serverId: m[1]!, toolName: m[2]! }
|
|
248
|
+
}
|
|
249
|
+
|
|
197
250
|
/**
|
|
198
251
|
* Runtime assert bentuk execution (Fase 2): cast `as unknown` di cli/tui.ts
|
|
199
252
|
* menutupi payload rusak — adaptor tidak boleh crash, hanya lewati + counter.
|
|
@@ -344,6 +397,7 @@ export function createPresentationAdapter(
|
|
|
344
397
|
ts: Date.now(),
|
|
345
398
|
sessionId,
|
|
346
399
|
turnId,
|
|
400
|
+
v: EVENT_SCHEMA_VERSION,
|
|
347
401
|
executionId: `exec_${Date.now()}:${rootExecutionId || ""}:${Math.random().toString(36).slice(2, 8)}`,
|
|
348
402
|
...(rootExecutionId ? { rootExecutionId } : {}),
|
|
349
403
|
})
|
|
@@ -358,6 +412,7 @@ export function createPresentationAdapter(
|
|
|
358
412
|
ts: Date.now(),
|
|
359
413
|
sessionId: childId,
|
|
360
414
|
turnId,
|
|
415
|
+
v: EVENT_SCHEMA_VERSION,
|
|
361
416
|
...(parentLink ? { parentLink } : {}),
|
|
362
417
|
...(rootExecutionId ? { rootExecutionId } : {}),
|
|
363
418
|
parentExecutionId: `exec_${Date.now()}:${rootExecutionId || ""}:${Math.random().toString(36).slice(2, 8)}`, // PSEUDO-UPPER: actual parent will be set by caller
|
|
@@ -556,9 +611,14 @@ export function createPresentationAdapter(
|
|
|
556
611
|
* Pasangkan forward anak dengan induk: tepat SATU call delegate_task pending
|
|
557
612
|
* → taut; nol = orphan; >1 = paralel ambigu → tanpa taut (jangan tebak).
|
|
558
613
|
*/
|
|
559
|
-
const resolveChildLink = (childId: string): ChildSessionLink | undefined => {
|
|
614
|
+
const resolveChildLink = (childId: string, runId?: string): ChildSessionLink | undefined => {
|
|
560
615
|
const hit = childLinks.get(childId)
|
|
561
|
-
if (hit)
|
|
616
|
+
if (hit) {
|
|
617
|
+
// F-AGENT-1: completed may carry the runId too; fill it if the started
|
|
618
|
+
// event predated the enrichment (defensive backfill, idempotent).
|
|
619
|
+
if (runId && !hit.runId) hit.runId = runId
|
|
620
|
+
return hit
|
|
621
|
+
}
|
|
562
622
|
if (pendingDelegateCalls.length !== 1) {
|
|
563
623
|
diag.orphanChild++
|
|
564
624
|
return undefined
|
|
@@ -567,6 +627,7 @@ export function createPresentationAdapter(
|
|
|
567
627
|
parentToolCallId: pendingDelegateCalls[0]!,
|
|
568
628
|
childSessionId: childId,
|
|
569
629
|
parentSessionId: sessionId,
|
|
630
|
+
...(runId ? { runId } : {}),
|
|
570
631
|
}
|
|
571
632
|
childLinks.set(childId, link)
|
|
572
633
|
return link
|
|
@@ -577,6 +638,12 @@ export function createPresentationAdapter(
|
|
|
577
638
|
return typeof f === "string" && f ? f : undefined
|
|
578
639
|
}
|
|
579
640
|
|
|
641
|
+
/** F-AGENT-1: id Run anak dari event forward (dipasang delegate_task). */
|
|
642
|
+
const extractForwardRunId = (e: unknown): string | undefined => {
|
|
643
|
+
const r = (e as { childRunId?: unknown } | null)?.childRunId
|
|
644
|
+
return typeof r === "string" && r ? r : undefined
|
|
645
|
+
}
|
|
646
|
+
|
|
580
647
|
const cascadeOpenTools = (reason: CancelReason): void => {
|
|
581
648
|
for (const [id, meta] of openTools) {
|
|
582
649
|
if (!markTerminal(id)) continue
|
|
@@ -629,13 +696,18 @@ export function createPresentationAdapter(
|
|
|
629
696
|
}
|
|
630
697
|
|
|
631
698
|
const unsubs: (() => void)[] = []
|
|
632
|
-
|
|
699
|
+
// [F-TYPE-1] `any` dikesampingkan. Payload tiap call-site sudah dianotasi
|
|
700
|
+
// (lihat 9 pemanggil di bawah); `sub` generik menjaga anotasi itu — E diinfer
|
|
701
|
+
// dari handler — sementara bus kernel tetap `unknown` di tepi (EventBusLike.on).
|
|
702
|
+
// Satu-satunya cast `e as E` menandai perpindahan unknown → bentuk yang
|
|
703
|
+
// dideklarasikan call-site (bukan lagi melunturkan semuanya ke `any`).
|
|
704
|
+
const sub = <E = unknown>(type: string, fn: (e: E) => void): void => {
|
|
633
705
|
try {
|
|
634
706
|
unsubs.push(
|
|
635
|
-
source.on(type, (e:
|
|
707
|
+
source.on(type, (e: unknown) => {
|
|
636
708
|
diag.eventsIn++
|
|
637
709
|
try {
|
|
638
|
-
fn(e)
|
|
710
|
+
fn(e as E)
|
|
639
711
|
} catch {
|
|
640
712
|
diag.errors++
|
|
641
713
|
}
|
|
@@ -737,6 +809,7 @@ export function createPresentationAdapter(
|
|
|
737
809
|
openTools.delete(id)
|
|
738
810
|
toolStarts.delete(id)
|
|
739
811
|
counts.failed++
|
|
812
|
+
const drift = detectSchemaDrift(r.content)
|
|
740
813
|
publish({
|
|
741
814
|
...base(currentTurn),
|
|
742
815
|
type: "tool.failed",
|
|
@@ -745,6 +818,7 @@ export function createPresentationAdapter(
|
|
|
745
818
|
cause: "exec",
|
|
746
819
|
message: firstLine(r.content, 200),
|
|
747
820
|
expandRef: { toolCallId: id, idx: 0 },
|
|
821
|
+
...(drift ? { schemaDrift: drift } : {}),
|
|
748
822
|
})
|
|
749
823
|
}
|
|
750
824
|
})
|
|
@@ -762,7 +836,8 @@ export function createPresentationAdapter(
|
|
|
762
836
|
const call = e.execution.call
|
|
763
837
|
const childId = extractForward(e)
|
|
764
838
|
noteDelegateStarted(call.id, call.name, childId)
|
|
765
|
-
const
|
|
839
|
+
const childRunId = extractForwardRunId(e)
|
|
840
|
+
const parentLink = childId ? resolveChildLink(childId, childRunId) : undefined
|
|
766
841
|
toolStarts.set(call.id, Date.now())
|
|
767
842
|
openTools.set(call.id, {
|
|
768
843
|
name: call.name,
|
|
@@ -810,8 +885,10 @@ export function createPresentationAdapter(
|
|
|
810
885
|
const result = e.execution.result
|
|
811
886
|
const childId = extractForward(e)
|
|
812
887
|
noteDelegateSettled(call.id, call.name, childId)
|
|
888
|
+
const childRunId = extractForwardRunId(e)
|
|
813
889
|
const meta = openTools.get(call.id)
|
|
814
|
-
const parentLink =
|
|
890
|
+
const parentLink =
|
|
891
|
+
meta?.parentLink ?? (childId ? resolveChildLink(childId, childRunId) : undefined)
|
|
815
892
|
const t0 = toolStarts.get(call.id)
|
|
816
893
|
const durationMs = t0 !== undefined ? Math.max(0, Date.now() - t0) : 0
|
|
817
894
|
if (!markTerminal(call.id)) return
|
|
@@ -928,6 +1005,7 @@ export function createPresentationAdapter(
|
|
|
928
1005
|
return
|
|
929
1006
|
}
|
|
930
1007
|
if (count) counts.failed++
|
|
1008
|
+
const drift = detectSchemaDrift(result.content)
|
|
931
1009
|
publish(
|
|
932
1010
|
withLink({
|
|
933
1011
|
...nextBase(),
|
|
@@ -937,6 +1015,7 @@ export function createPresentationAdapter(
|
|
|
937
1015
|
cause: mapToolFailCause(result.content),
|
|
938
1016
|
message: firstLine(result.content, 200),
|
|
939
1017
|
expandRef: { toolCallId: call.id, idx: 0 },
|
|
1018
|
+
...(drift ? { schemaDrift: drift } : {}),
|
|
940
1019
|
}),
|
|
941
1020
|
)
|
|
942
1021
|
},
|
|
@@ -1018,6 +1097,8 @@ export function createPresentationAdapter(
|
|
|
1018
1097
|
identity,
|
|
1019
1098
|
argsSummary,
|
|
1020
1099
|
via: e.via,
|
|
1100
|
+
...(e.riskTier ? { riskTier: e.riskTier } : {}),
|
|
1101
|
+
...(e.diffPreview ? { diffPreview: e.diffPreview } : {}),
|
|
1021
1102
|
}
|
|
1022
1103
|
if (toolCallId !== undefined) out.toolCallId = toolCallId
|
|
1023
1104
|
publish(out)
|
|
@@ -1087,6 +1168,71 @@ export function createPresentationAdapter(
|
|
|
1087
1168
|
}
|
|
1088
1169
|
}
|
|
1089
1170
|
|
|
1171
|
+
const noteConsequenceDecided: PresentationAdapter["noteConsequenceDecided"] = (info) => {
|
|
1172
|
+
try {
|
|
1173
|
+
publish({
|
|
1174
|
+
...base(info.turnId ?? currentTurn),
|
|
1175
|
+
type: "consequence.decided",
|
|
1176
|
+
verdict: info.verdict,
|
|
1177
|
+
failureClass: info.failureClass,
|
|
1178
|
+
nextAction: info.nextAction,
|
|
1179
|
+
rationale: info.rationale,
|
|
1180
|
+
...(info.newEvidenceSinceLastAttempt !== undefined
|
|
1181
|
+
? { newEvidenceSinceLastAttempt: info.newEvidenceSinceLastAttempt }
|
|
1182
|
+
: {}),
|
|
1183
|
+
})
|
|
1184
|
+
} catch {
|
|
1185
|
+
diag.errors++
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
const noteContextWindow: PresentationAdapter["noteContextWindow"] = (info) => {
|
|
1190
|
+
try {
|
|
1191
|
+
publish({
|
|
1192
|
+
...base(info.turnId ?? currentTurn),
|
|
1193
|
+
type: "context.window",
|
|
1194
|
+
usedTokens: info.usedTokens,
|
|
1195
|
+
windowTokens: info.windowTokens,
|
|
1196
|
+
...(info.percent !== undefined ? { percent: info.percent } : {}),
|
|
1197
|
+
...(info.costUsd !== undefined ? { costUsd: info.costUsd } : {}),
|
|
1198
|
+
...(info.providerModel ? { providerModel: info.providerModel } : {}),
|
|
1199
|
+
})
|
|
1200
|
+
} catch {
|
|
1201
|
+
diag.errors++
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
const noteContextCutoff: PresentationAdapter["noteContextCutoff"] = (info) => {
|
|
1206
|
+
try {
|
|
1207
|
+
publish({
|
|
1208
|
+
...base(info.turnId ?? currentTurn),
|
|
1209
|
+
type: "context.cutoff",
|
|
1210
|
+
reason: info.reason,
|
|
1211
|
+
...(info.usedTokens !== undefined ? { usedTokens: info.usedTokens } : {}),
|
|
1212
|
+
...(info.windowTokens !== undefined ? { windowTokens: info.windowTokens } : {}),
|
|
1213
|
+
})
|
|
1214
|
+
} catch {
|
|
1215
|
+
diag.errors++
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
const noteTaskStatus: PresentationAdapter["noteTaskStatus"] = (info) => {
|
|
1220
|
+
try {
|
|
1221
|
+
publish({
|
|
1222
|
+
...base(info.turnId ?? currentTurn),
|
|
1223
|
+
type: "task.status",
|
|
1224
|
+
taskId: info.taskId,
|
|
1225
|
+
status: info.status,
|
|
1226
|
+
...(info.parentId ? { parentId: info.parentId } : {}),
|
|
1227
|
+
...(info.dependsOn ? { dependsOn: [...info.dependsOn] } : {}),
|
|
1228
|
+
...(info.revision !== undefined ? { revision: info.revision } : {}),
|
|
1229
|
+
...(info.verification ? { verification: info.verification } : {}),
|
|
1230
|
+
})
|
|
1231
|
+
} catch {
|
|
1232
|
+
diag.errors++
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1090
1236
|
const noteCheckpoint: PresentationAdapter["noteCheckpoint"] = (info) => {
|
|
1091
1237
|
try {
|
|
1092
1238
|
publish({
|
|
@@ -1184,6 +1330,10 @@ export function createPresentationAdapter(
|
|
|
1184
1330
|
noteTestCompleted,
|
|
1185
1331
|
noteVerificationObserved,
|
|
1186
1332
|
noteCheckpoint,
|
|
1333
|
+
noteConsequenceDecided,
|
|
1334
|
+
noteContextWindow,
|
|
1335
|
+
noteContextCutoff,
|
|
1336
|
+
noteTaskStatus,
|
|
1187
1337
|
notePlanReconciled(info) {
|
|
1188
1338
|
const owner = info.sessionId ?? sessionId
|
|
1189
1339
|
const plan = planFromTodos({ todos: info.todos }, owner)
|
|
@@ -67,7 +67,17 @@ export type ApprovalOutcome =
|
|
|
67
67
|
| {
|
|
68
68
|
decision: "deny"
|
|
69
69
|
by: "user" | "system"
|
|
70
|
-
|
|
70
|
+
// [Area B · PROMPT 06] "approval-stale" = user menyetujui, tapi target
|
|
71
|
+
// file berubah selama prompt ⇒ fail-closed (additive, tak mengubah
|
|
72
|
+
// makna reason yang sudah ada).
|
|
73
|
+
reason?:
|
|
74
|
+
| "declined"
|
|
75
|
+
| "headless"
|
|
76
|
+
| "no-ask"
|
|
77
|
+
| "no-view"
|
|
78
|
+
| "prompt-error"
|
|
79
|
+
| "parent-aborted"
|
|
80
|
+
| "approval-stale"
|
|
71
81
|
}
|
|
72
82
|
| {
|
|
73
83
|
decision: "cancelled"
|
|
@@ -122,13 +132,29 @@ export interface ChildSessionLink {
|
|
|
122
132
|
parentToolCallId: string
|
|
123
133
|
childSessionId: string
|
|
124
134
|
parentSessionId?: string
|
|
135
|
+
/**
|
|
136
|
+
* F-AGENT-1: id Run kanonik anak (`allocateRunId`) — identitas eksekusi yang
|
|
137
|
+
* membedakan penyelesaian/retry anak, BUKAN childSessionId (identity session)
|
|
138
|
+
* maupun parentToolCallId (taut ke pemanggil). Absen = jalur lama belum
|
|
139
|
+
* membawanya (tetap sah, hanya tanpa identitas run anak).
|
|
140
|
+
*/
|
|
141
|
+
runId?: string
|
|
125
142
|
}
|
|
126
143
|
|
|
144
|
+
/**
|
|
145
|
+
* P1.6: versi skema event durable. Additive: event lama tanpa `v` dibaca sebagai
|
|
146
|
+
* v1 (decoder tidak mensyaratkan field ini), sehingga penambahan field opsional
|
|
147
|
+
* tetap kompatibel. Naikkan hanya bila field wajib berubah/bermakna baru.
|
|
148
|
+
*/
|
|
149
|
+
export const EVENT_SCHEMA_VERSION = 1
|
|
150
|
+
|
|
127
151
|
interface Base {
|
|
128
152
|
eventSeq: number
|
|
129
153
|
ts: number
|
|
130
154
|
sessionId: string
|
|
131
155
|
turnId: number
|
|
156
|
+
/** Versi skema durable; absen = v1 (kompatibilitas replay lama). */
|
|
157
|
+
v?: number
|
|
132
158
|
// M1 correlator (ADR-002, additive-optional): korelasi execution tanpa
|
|
133
159
|
// mengganti domain identity. Absent = event legacy / jalur belum wiring
|
|
134
160
|
// (M10 yang memasang penuh); parser lama tetap membaca (decode hanya
|
|
@@ -218,6 +244,12 @@ export interface ToolFailedEvent extends Base {
|
|
|
218
244
|
hint?: string
|
|
219
245
|
expandRef: ContentRef
|
|
220
246
|
parentLink?: ChildSessionLink
|
|
247
|
+
/**
|
|
248
|
+
* F-TOOL-1: drift skema MCP terstruktur (bukan `message` yang mengandung
|
|
249
|
+
* string error mentah). Absen = kegagalan bukan drift skema (atau jalur
|
|
250
|
+
* legacy yang belum mendeteksinya).
|
|
251
|
+
*/
|
|
252
|
+
schemaDrift?: McpSchemaDrift
|
|
221
253
|
}
|
|
222
254
|
export interface ToolDeniedEvent extends Base {
|
|
223
255
|
type: "tool.denied"
|
|
@@ -240,6 +272,13 @@ export interface ApprovalRequestedEvent extends Base {
|
|
|
240
272
|
identity: ToolIdentity
|
|
241
273
|
argsSummary: ArgsSummary
|
|
242
274
|
via: "prompt" | "system"
|
|
275
|
+
/** F-APPROVAL-1: tier risiko efek samping tool (dari kontrak tool). */
|
|
276
|
+
riskTier?: SideEffectTierDisplay
|
|
277
|
+
/**
|
|
278
|
+
* F-APPROVAL-1: pratinjau diff ringkas untuk preview persetujuan (satu baris,
|
|
279
|
+
* sudah di-scrub secret). Absen = tidak ada diff yang tersedia/tidak relevan.
|
|
280
|
+
*/
|
|
281
|
+
diffPreview?: string
|
|
243
282
|
}
|
|
244
283
|
export interface ApprovalSettledEvent extends Base {
|
|
245
284
|
type: "approval.settled"
|
|
@@ -355,6 +394,66 @@ export interface CheckpointCreatedEvent extends Base {
|
|
|
355
394
|
* `verification` untuk display. `evidenceReference` TIDAK dibawa ke sini
|
|
356
395
|
* (tetap di jurnal); yang dibawa hanya identitas + verdict + metode.
|
|
357
396
|
*/
|
|
397
|
+
// ── Literal tampilan (didefinisikan ulang di sini) ──
|
|
398
|
+
//
|
|
399
|
+
// Lapisan presentasi TIDAK mengimpor `src/policy`/`src/task` untuk keputusan
|
|
400
|
+
// semantik: literal-literal ini adalah salinan ringkas dari kosakata domain
|
|
401
|
+
// yang hanya untuk display (pola yang sama dengan `VerificationDisplayVerdict`).
|
|
402
|
+
// Renderer memakai nilai final dari proyeksi; definisi ulang ini memutus
|
|
403
|
+
// dependensi lapisan tanpa mengarang nilai baru.
|
|
404
|
+
|
|
405
|
+
/** Verdict consequence (F-CTRL-1) — cermin `AceVerdict` di policy. */
|
|
406
|
+
export type ConsequenceVerdict = "PASS" | "FAIL" | "BLOCKED" | "INCONCLUSIVE"
|
|
407
|
+
|
|
408
|
+
/** Kelas kegagalan consequence — cermin `AceFailureClass`. */
|
|
409
|
+
export type ConsequenceFailureClass =
|
|
410
|
+
| "NONE"
|
|
411
|
+
| "TRANSIENT_ENV"
|
|
412
|
+
| "FUNCTIONAL_TEST_FAIL"
|
|
413
|
+
| "REGRESSION_DETECTED"
|
|
414
|
+
| "REPEATED_NO_EVIDENCE"
|
|
415
|
+
| "INSUFFICIENT_EVIDENCE"
|
|
416
|
+
| "PERMISSION_OR_EXTERNAL_BLOCKER"
|
|
417
|
+
| "EVALUATOR_TAMPER_ATTEMPT"
|
|
418
|
+
|
|
419
|
+
/** Aksi lanjut consequence — cermin `AceNextAction`. */
|
|
420
|
+
export type ConsequenceNextAction =
|
|
421
|
+
| "COMPLETE_AFTER_VERIFICATION"
|
|
422
|
+
| "RETRY_TRANSIENT"
|
|
423
|
+
| "ANALYZE_FAILURE"
|
|
424
|
+
| "REVISE_HYPOTHESIS"
|
|
425
|
+
| "GATHER_EVIDENCE"
|
|
426
|
+
| "CHANGE_STRATEGY"
|
|
427
|
+
| "REQUEST_HUMAN"
|
|
428
|
+
| "STOP_AND_REPORT"
|
|
429
|
+
|
|
430
|
+
/** Tier efek samping untuk approval (F-APPROVAL-1) — cermin `SideEffectTier`. */
|
|
431
|
+
export type SideEffectTierDisplay =
|
|
432
|
+
| "PURE_READ"
|
|
433
|
+
| "WORKSPACE_MUTATION"
|
|
434
|
+
| "LOCAL_ENV_MUTATION"
|
|
435
|
+
| "EXTERNAL_IRREVERSIBLE"
|
|
436
|
+
| "UNKNOWN"
|
|
437
|
+
|
|
438
|
+
/** Status task kanonik (F-TASK-1) — cermin `TaskStatus` di `src/task`. */
|
|
439
|
+
export type TaskStatusDisplay =
|
|
440
|
+
| "PENDING"
|
|
441
|
+
| "IN_PROGRESS"
|
|
442
|
+
| "VERIFYING"
|
|
443
|
+
| "BLOCKED"
|
|
444
|
+
| "FAILED"
|
|
445
|
+
| "RETRYING"
|
|
446
|
+
| "COMPLETED"
|
|
447
|
+
| "CANCELLED"
|
|
448
|
+
|
|
449
|
+
/** Drift skema MCP terstruktur (F-TOOL-1) — BUKAN string error mentah. */
|
|
450
|
+
export interface McpSchemaDrift {
|
|
451
|
+
/** Id server MCP (`srv` pada `srv.search`). */
|
|
452
|
+
serverId: string
|
|
453
|
+
/** Nama tool lokal (`search`). */
|
|
454
|
+
toolName: string
|
|
455
|
+
}
|
|
456
|
+
|
|
358
457
|
export type VerificationDisplayVerdict = "present" | "absent" | "inconclusive"
|
|
359
458
|
|
|
360
459
|
/** Tampilan verifikasi per activity — observasi, bukan otoritas efek. */
|
|
@@ -376,6 +475,67 @@ export interface VerificationObservedEvent extends Base {
|
|
|
376
475
|
parentLink?: ChildSessionLink
|
|
377
476
|
}
|
|
378
477
|
|
|
478
|
+
/**
|
|
479
|
+
* F-CTRL-1/F-CTRL-2: keputusan consequence terstruktur (ACE) — BUKAN string
|
|
480
|
+
* stderr. Diterjemahkan dari `ConsequenceDecision` di policy ke literal display
|
|
481
|
+
* yang stabil. `newEvidenceSinceLastAttempt` membawa alasan "VERIFYING / Tamper
|
|
482
|
+
* Guard" yang tadinya hanya terlihat di stderr.
|
|
483
|
+
*/
|
|
484
|
+
export interface ConsequenceDecidedEvent extends Base {
|
|
485
|
+
type: "consequence.decided"
|
|
486
|
+
verdict: ConsequenceVerdict
|
|
487
|
+
failureClass: ConsequenceFailureClass
|
|
488
|
+
nextAction: ConsequenceNextAction
|
|
489
|
+
rationale: string
|
|
490
|
+
/** Bukti baru sejak percobaan terakhir (F-CTRL-2); absen = tidak dilacak. */
|
|
491
|
+
newEvidenceSinceLastAttempt?: boolean
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* F-CTX-1: meter jendela konteks live — NON-durable (tidak pernah dipersist),
|
|
496
|
+
* hanya untuk footer/machine. `percent` dihitung pemanggil dari angka nyata;
|
|
497
|
+
* `costUsd`/`providerModel` opsional karena pricing model bisa tak dikenal.
|
|
498
|
+
*/
|
|
499
|
+
export interface ContextWindowEvent extends Base {
|
|
500
|
+
type: "context.window"
|
|
501
|
+
usedTokens: number
|
|
502
|
+
windowTokens: number
|
|
503
|
+
/** 0–100 (boleh desimal); absen = tidak dapat dihitung (window tak dikenal). */
|
|
504
|
+
percent?: number
|
|
505
|
+
costUsd?: number
|
|
506
|
+
providerModel?: string
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* F-CTX-2: pemotongan mi-stream dari `watchContextWindowLimit`/`watchBudgetLimit`
|
|
511
|
+
* yang DURABLE — masuk transkrip, bukan hanya stderr, agar operator tahu persis
|
|
512
|
+
* di mana stream dipangkas saat replay.
|
|
513
|
+
*/
|
|
514
|
+
export interface ContextCutoffEvent extends Base {
|
|
515
|
+
type: "context.cutoff"
|
|
516
|
+
reason: string
|
|
517
|
+
usedTokens?: number
|
|
518
|
+
windowTokens?: number
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* F-TASK-1: transisi status task kanonik (`t<n>`) + DAG (parent/dependsOn).
|
|
523
|
+
* Id/status dibawa apa adanya dari TaskStore; renderer hanya menampilkan.
|
|
524
|
+
*/
|
|
525
|
+
export interface TaskStatusEvent extends Base {
|
|
526
|
+
type: "task.status"
|
|
527
|
+
taskId: string
|
|
528
|
+
status: TaskStatusDisplay
|
|
529
|
+
parentId?: string
|
|
530
|
+
dependsOn?: string[]
|
|
531
|
+
revision?: number
|
|
532
|
+
/**
|
|
533
|
+
* P1.5: bukti verifikasi yang menempel pada task. `COMPLETED` tanpa
|
|
534
|
+
* `verdict=passed` BUKAN "PASS" — UI wajib menandainya unverified.
|
|
535
|
+
*/
|
|
536
|
+
verification?: { verdict: "passed" | "failed" | "unverified"; checkedAt: string }
|
|
537
|
+
}
|
|
538
|
+
|
|
379
539
|
export type DomainEvent =
|
|
380
540
|
| UserMessageEvent
|
|
381
541
|
| TurnStartedEvent
|
|
@@ -403,6 +563,10 @@ export type DomainEvent =
|
|
|
403
563
|
| DiagnosticRaisedEvent
|
|
404
564
|
| CheckpointCreatedEvent
|
|
405
565
|
| VerificationObservedEvent
|
|
566
|
+
| ConsequenceDecidedEvent
|
|
567
|
+
| ContextWindowEvent
|
|
568
|
+
| ContextCutoffEvent
|
|
569
|
+
| TaskStatusEvent
|
|
406
570
|
|
|
407
571
|
export type DomainEventType = DomainEvent["type"]
|
|
408
572
|
|
|
@@ -436,6 +600,10 @@ export const DURABILITY: Record<DomainEventType, { durable: boolean; replayable:
|
|
|
436
600
|
"diagnostic.raised": { durable: true, replayable: true },
|
|
437
601
|
"checkpoint.created": { durable: true, replayable: true },
|
|
438
602
|
"verification.observed": { durable: true, replayable: true },
|
|
603
|
+
"consequence.decided": { durable: true, replayable: true },
|
|
604
|
+
"context.window": { durable: false, replayable: false },
|
|
605
|
+
"context.cutoff": { durable: true, replayable: true },
|
|
606
|
+
"task.status": { durable: true, replayable: true },
|
|
439
607
|
}
|
|
440
608
|
|
|
441
609
|
/**
|
|
@@ -464,6 +632,10 @@ export type ApprovalHookEvent =
|
|
|
464
632
|
approvalId: string
|
|
465
633
|
call: ApprovalPromptCall
|
|
466
634
|
via: "prompt" | "system"
|
|
635
|
+
/** F-APPROVAL-1: tier risiko efek samping (dihitung pemanggil dari kontrak). */
|
|
636
|
+
riskTier?: SideEffectTierDisplay
|
|
637
|
+
/** F-APPROVAL-1: pratinjau diff ringkas (sudah di-scrub secret). */
|
|
638
|
+
diffPreview?: string
|
|
467
639
|
}
|
|
468
640
|
| {
|
|
469
641
|
kind: "settled"
|
|
@@ -3,9 +3,11 @@ import type {
|
|
|
3
3
|
ContentRef,
|
|
4
4
|
DenyReason,
|
|
5
5
|
FailCause,
|
|
6
|
+
McpSchemaDrift,
|
|
6
7
|
PlanStep,
|
|
7
8
|
Receipt,
|
|
8
9
|
SemanticSeverity,
|
|
10
|
+
SideEffectTierDisplay,
|
|
9
11
|
ToolIdentity,
|
|
10
12
|
TurnSummary,
|
|
11
13
|
VerificationDisplay,
|
|
@@ -26,6 +28,20 @@ export interface ActivityEntry {
|
|
|
26
28
|
toolCallId: string
|
|
27
29
|
sessionId: string
|
|
28
30
|
parentToolCallId?: string
|
|
31
|
+
/**
|
|
32
|
+
* F-AGENT-1: identitas session anak (`sub_*`) untuk tool yang berjalan di
|
|
33
|
+
* dalam sub-agent. Berbeda dari `sessionId`? Tidak — untuk event anak,
|
|
34
|
+
* `sessionId` SUDAH id anak; field ini menyimpan makna yang sama secara
|
|
35
|
+
* eksplisit di jalur yang memisahkan parent/child lewat parentToolCallId.
|
|
36
|
+
* Disimpan agar snapshot UI dapat membedakan child tanpa menebak dari prefix.
|
|
37
|
+
*/
|
|
38
|
+
childSessionId?: string
|
|
39
|
+
/**
|
|
40
|
+
* F-AGENT-1: id Run kanonik anak — identitas eksekusi (bukan identity session
|
|
41
|
+
* `childSessionId`, bukan taut `parentToolCallId`). Satu delegate_task punya
|
|
42
|
+
* satu run anak; retry = run baru.
|
|
43
|
+
*/
|
|
44
|
+
runId?: string
|
|
29
45
|
identity: ToolIdentity
|
|
30
46
|
target?: string
|
|
31
47
|
status: ToolStatus
|
|
@@ -44,6 +60,8 @@ export interface ActivityEntry {
|
|
|
44
60
|
incomplete?: boolean
|
|
45
61
|
/** Observasi verifikasi terakhir (last-wins); absen = UNKNOWN. */
|
|
46
62
|
verification?: VerificationDisplay
|
|
63
|
+
/** F-TOOL-1: drift skema MCP terstruktur (absen = bukan drift). */
|
|
64
|
+
schemaDrift?: McpSchemaDrift
|
|
47
65
|
}
|
|
48
66
|
|
|
49
67
|
export interface TurnEntry {
|
|
@@ -71,6 +89,10 @@ export interface ApprovalEntry {
|
|
|
71
89
|
identity: ToolIdentity
|
|
72
90
|
state: "requested" | "settled"
|
|
73
91
|
outcome?: ApprovalOutcome
|
|
92
|
+
/** F-APPROVAL-1: tier risiko efek samping (dari kontrak tool). */
|
|
93
|
+
riskTier?: SideEffectTierDisplay
|
|
94
|
+
/** F-APPROVAL-1: pratinjau diff ringkas (sudah di-scrub secret). */
|
|
95
|
+
diffPreview?: string
|
|
74
96
|
}
|
|
75
97
|
|
|
76
98
|
export interface ConversationEntry {
|
|
@@ -107,6 +129,16 @@ export interface SystemEntry {
|
|
|
107
129
|
text: string
|
|
108
130
|
reason?: string
|
|
109
131
|
severity: SemanticSeverity
|
|
132
|
+
/**
|
|
133
|
+
* F-TASK-1: transisi status task kanonik disimpan TERSTRUKTUR, bukan hanya
|
|
134
|
+
* dirangkai ke `text`. Snapshot/proyeksi butuh id/parent/DAG/revisi tanpa
|
|
135
|
+
* mem-parse teks tampilan (renderer dilarang mem-parse).
|
|
136
|
+
*/
|
|
137
|
+
taskId?: string
|
|
138
|
+
taskStatus?: string
|
|
139
|
+
parentId?: string
|
|
140
|
+
dependsOn?: string[]
|
|
141
|
+
revision?: number
|
|
110
142
|
}
|
|
111
143
|
|
|
112
144
|
export interface PlanEntry {
|
|
@@ -156,6 +188,10 @@ export interface DiagnosticEntry {
|
|
|
156
188
|
message: string
|
|
157
189
|
cause?: string
|
|
158
190
|
action?: string
|
|
191
|
+
/** F-CTRL-1: verdict consequence terstruktur (absen = bukan consequence). */
|
|
192
|
+
verdict?: string
|
|
193
|
+
/** F-CTRL-2: ada bukti baru sejak percobaan terakhir (alasan VERIFYING/Tamper Guard). */
|
|
194
|
+
newEvidenceSinceLastAttempt?: boolean
|
|
159
195
|
}
|
|
160
196
|
|
|
161
197
|
export type PresentationEntry =
|
|
@@ -277,6 +313,7 @@ export function cloneState(s: PresentationState): PresentationState {
|
|
|
277
313
|
identity: { ...v.identity },
|
|
278
314
|
...(v.error ? { error: { ...v.error } } : {}),
|
|
279
315
|
...(v.expandRef ? { expandRef: copyRef(v.expandRef) } : {}),
|
|
316
|
+
...(v.schemaDrift ? { schemaDrift: { ...v.schemaDrift } } : {}),
|
|
280
317
|
receipt: copyReceipt(v.receipt),
|
|
281
318
|
},
|
|
282
319
|
]),
|