minicode-ai 0.9.29 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +45 -0
- package/CHANGELOG.md +79 -1
- package/PLAN.md +491 -0
- package/README.md +2 -2
- package/cli/args.ts +1 -0
- package/cli/commands/acp.ts +485 -0
- package/cli/commands/auth.ts +7 -4
- package/cli/commands/config.ts +41 -27
- package/cli/commands/exec.ts +33 -12
- package/cli/commands/mcp.ts +3 -2
- package/cli/commands/memory.ts +1 -1
- package/cli/commands/pricing.ts +6 -4
- package/cli/commands/providers.ts +18 -8
- package/cli/commands/sessions.ts +11 -4
- package/cli/commands/skills.ts +3 -3
- package/cli/commands/stats.ts +3 -1
- package/cli/commands.ts +225 -103
- package/cli/index.ts +89 -62
- package/cli/model-manager.ts +8 -8
- package/cli/provider-manager.ts +13 -13
- package/cli/router.ts +7 -0
- package/cli/setup.ts +349 -4
- package/cli/tui.ts +542 -0
- package/cli/wizard.ts +2 -1
- package/docs/ARCHITECTURE.html +62 -36
- package/docs/CONTROL-PLANE-MAP.md +139 -0
- package/docs/HARNESS.md +150 -0
- package/docs/PLAN_UIUX_V6.md +209 -0
- package/docs/README.md +1 -1
- package/docs/SUMMARY.md +52 -0
- package/docs/TERMINAL_CONTRACT.md +367 -0
- package/docs/UI_RENDER_PIPELINE.md +165 -0
- package/docs/USAGE.md +11 -0
- package/docs/agents.md +31 -0
- package/docs/architecture.md +3 -3
- package/docs/choosing-mode.md +34 -0
- package/docs/cli.md +130 -0
- package/docs/concepts.md +53 -0
- package/docs/config-providers.md +87 -0
- package/docs/config.md +63 -0
- package/docs/contributing.md +79 -0
- package/docs/environment.md +95 -0
- package/docs/exec.md +73 -0
- package/docs/getting-started.md +102 -0
- package/docs/glossary.md +37 -0
- package/docs/mcp-lsp.md +54 -0
- package/docs/memory-sessions.md +63 -0
- package/docs/policy-sandbox.md +72 -0
- package/docs/pricing-budget.md +49 -0
- package/docs/quickstart.md +60 -0
- package/docs/repl.md +67 -0
- package/docs/security-model.md +95 -0
- package/docs/security.md +91 -0
- package/docs/skills.md +48 -0
- package/docs/terminal.md +79 -0
- package/docs/tools.md +123 -0
- package/docs/troubleshooting.md +40 -0
- package/docs/verify-benchmark.md +58 -0
- package/package.json +8 -5
- package/src/app/provider-layer.ts +12 -4
- package/src/app/rag-layer.ts +7 -2
- package/src/app/session.ts +6 -0
- package/src/app/tool-layer.ts +2 -1
- package/src/config.ts +30 -1
- package/src/constants.ts +35 -0
- package/src/lib/net.ts +6 -1
- package/src/lsp/client.ts +41 -8
- package/src/mcp/http-transport.ts +52 -15
- package/src/mcp/transport.ts +32 -1
- package/src/memory/files.ts +6 -5
- package/src/policy/allowlist.ts +1 -1
- package/src/policy/bash-guard.ts +213 -17
- package/src/policy/compaction.ts +57 -3
- package/src/policy/context.ts +4 -0
- package/src/policy/jail.ts +49 -4
- package/src/policy/permission.ts +152 -12
- package/src/policy/pricing.ts +12 -9
- package/src/policy/update-check.ts +4 -1
- package/src/presentation/adapter.ts +721 -0
- package/src/presentation/events.ts +324 -0
- package/src/presentation/label.ts +140 -0
- package/src/presentation/model.ts +172 -0
- package/src/presentation/reducer.ts +486 -0
- package/src/presentation/store.ts +256 -0
- package/src/providers/anthropic.ts +22 -4
- package/src/providers/detect.ts +2 -1
- package/src/providers/router.ts +13 -0
- package/src/repo/repomap.ts +2 -29
- package/src/session/checkpoint.ts +27 -9
- package/src/session/journal.ts +27 -5
- package/src/skills/loader.ts +88 -5
- package/src/telemetry/trace.ts +36 -15
- package/src/tools/ask_user.ts +73 -4
- package/src/tools/bash.ts +23 -17
- package/src/tools/glob.ts +10 -11
- package/src/tools/lsp.ts +3 -56
- package/src/tools/memory.ts +13 -12
- package/src/tools/task.ts +7 -1
- package/src/tools/web_fetch.ts +11 -2
- package/src/tools/web_search.ts +4 -1
- package/src/ui/approval/prompt.ts +96 -22
- package/src/ui/assistant/simple.ts +188 -44
- package/src/ui/assistant/turn-status.ts +32 -10
- package/src/ui/contract.ts +119 -0
- package/src/ui/footer.ts +35 -14
- package/src/ui/i18n/en.ts +253 -0
- package/src/ui/i18n/id.ts +255 -0
- package/src/ui/i18n/locale.ts +68 -0
- package/src/ui/input/input.ts +189 -81
- package/src/ui/input/prompt-engine.ts +139 -4
- package/src/ui/render/collapse.ts +20 -13
- package/src/ui/render/diff.ts +7 -2
- package/src/ui/render/errors.ts +75 -50
- package/src/ui/render/format.ts +26 -8
- package/src/ui/render/highlight.ts +12 -5
- package/src/ui/render/markdown.ts +5 -1
- package/src/ui/render/sanitize.ts +29 -2
- package/src/ui/render/table.ts +12 -6
- package/src/ui/render/theme.ts +23 -4
- package/src/ui/render/width.ts +104 -17
- package/src/ui/runtime/motion.ts +16 -0
- package/src/ui/runtime/screen.ts +242 -0
- package/src/ui/runtime/spinner.ts +50 -4
- package/src/ui/runtime/statusline.ts +50 -1
- package/src/ui/screens/dialog.ts +174 -0
- package/src/ui/screens/form.ts +486 -0
- package/src/ui/screens/model-manager.ts +289 -134
- package/src/ui/screens/picker.ts +264 -109
- package/src/ui/screens/provider-manager.ts +385 -172
- package/src/ui/screens/wizard.ts +165 -102
- package/src/ui/tui/app.ts +951 -0
- package/src/ui/tui/transcript.ts +475 -0
- package/vendor/minicore/LICENSE +21 -0
- package/vendor/minicore/VENDOR.md +6 -3
- package/vendor/minicore/package.json +6 -3
- package/vendor/minicore/src/core/loop.ts +12 -2
- package/vendor/minicore/src/core/snapshot.ts +4 -0
- package/vendor/minicore/src/providers/openai-compat.ts +76 -25
- package/cli/repl.ts +0 -740
- package/src/ui/runtime/chrome.ts +0 -369
- package/src/ui/screens/overlay.ts +0 -61
package/cli/setup.ts
CHANGED
|
@@ -31,6 +31,19 @@ import {
|
|
|
31
31
|
runVerify,
|
|
32
32
|
runWithSelfHeal,
|
|
33
33
|
} from "../src/policy/verifier.ts"
|
|
34
|
+
import { createPresentationAdapter, type PresentationAdapter } from "../src/presentation/adapter.ts"
|
|
35
|
+
import type { DomainEvent } from "../src/presentation/events.ts"
|
|
36
|
+
import { createInitialState, type PresentationState } from "../src/presentation/model.ts"
|
|
37
|
+
import {
|
|
38
|
+
createReducerDiagnostics,
|
|
39
|
+
type ReducerDiagnostics,
|
|
40
|
+
reduce,
|
|
41
|
+
} from "../src/presentation/reducer.ts"
|
|
42
|
+
import {
|
|
43
|
+
type ContentEntry,
|
|
44
|
+
type ContentStore,
|
|
45
|
+
createContentStore,
|
|
46
|
+
} from "../src/presentation/store.ts"
|
|
34
47
|
import {
|
|
35
48
|
beginTurnSnapshot,
|
|
36
49
|
reconcileUndoRedoPointer,
|
|
@@ -53,12 +66,20 @@ import {
|
|
|
53
66
|
summarizeArgs,
|
|
54
67
|
writeStepTrace,
|
|
55
68
|
} from "../src/telemetry/trace.ts"
|
|
56
|
-
import { setAskTextFn } from "../src/tools/ask_user.ts"
|
|
69
|
+
import { setAskApprovalHook, setAskTextFn } from "../src/tools/ask_user.ts"
|
|
57
70
|
import { killAllBackgroundJobs } from "../src/tools/bash.ts"
|
|
58
71
|
import { setSubAgentParentRouting } from "../src/tools/task.ts"
|
|
59
72
|
import { todoSession } from "../src/tools/todo.ts"
|
|
60
73
|
import { promptAsk, promptAskText } from "../src/ui/approval/prompt.ts"
|
|
61
74
|
import { attachSimpleLogger } from "../src/ui/assistant/simple.ts"
|
|
75
|
+
import type {
|
|
76
|
+
UiPresentationActivity,
|
|
77
|
+
UiPresentationEvent,
|
|
78
|
+
UiPresentationSnapshot,
|
|
79
|
+
UiPresentationTurn,
|
|
80
|
+
UiToolStatus,
|
|
81
|
+
UiTurnSummary,
|
|
82
|
+
} from "../src/ui/contract.ts"
|
|
62
83
|
import { c } from "../src/ui/render/theme.ts"
|
|
63
84
|
import { runSetupWizard } from "./wizard.ts"
|
|
64
85
|
|
|
@@ -87,6 +108,11 @@ export interface CliSessionOptions {
|
|
|
87
108
|
toolScope?: "full" | "explore"
|
|
88
109
|
maxSteps?: number
|
|
89
110
|
contextWindowTokens?: number
|
|
111
|
+
/** F3.2: override keepRecentTurns kompaksi kernel (berapa turn terakhir
|
|
112
|
+
* dipertahankan saat kompaksi). Default = kernel (DEFAULT_KEEP_RECENT_TURNS).
|
|
113
|
+
* Diisi dari env MINICODE_COMPACT_KEEP_TURNS (bilangan >=1, selain itu
|
|
114
|
+
* diabaikan + warn di composition root). */
|
|
115
|
+
keepRecentTurns?: number
|
|
90
116
|
timeoutMs?: number
|
|
91
117
|
rateLimiter?: RateLimiter
|
|
92
118
|
concurrency?: number
|
|
@@ -124,6 +150,21 @@ export interface CliSession {
|
|
|
124
150
|
/** Kontrol mode permission saat runtime (Shift+Tab / /mode di REPL). */
|
|
125
151
|
permissions?: PermissionControl
|
|
126
152
|
close: () => Promise<void>
|
|
153
|
+
/** Fase 3 dark-launch: counter shadow reducer (divergensi harus 0). */
|
|
154
|
+
getShadowDiagnostics: () => {
|
|
155
|
+
divergence: number
|
|
156
|
+
eventsIn: number
|
|
157
|
+
duplicateTerminal: number
|
|
158
|
+
lateEvent: number
|
|
159
|
+
orphanTool: number
|
|
160
|
+
orphanApproval: number
|
|
161
|
+
duplicateTurn: number
|
|
162
|
+
}
|
|
163
|
+
/** Content store untuk /expand [id]. */
|
|
164
|
+
expandContent: (toolCallId: string) => ContentEntry[]
|
|
165
|
+
expandAllContent: () => ContentEntry[]
|
|
166
|
+
getPresentationSnapshot: () => UiPresentationSnapshot
|
|
167
|
+
onPresentationEvent: (handler: (event: UiPresentationEvent) => void) => () => void
|
|
127
168
|
}
|
|
128
169
|
|
|
129
170
|
export async function createCliSession(opts: CliSessionOptions): Promise<CliSession> {
|
|
@@ -147,6 +188,7 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
147
188
|
allowLocalConfig,
|
|
148
189
|
maxSteps,
|
|
149
190
|
contextWindowTokens,
|
|
191
|
+
keepRecentTurns,
|
|
150
192
|
timeoutMs,
|
|
151
193
|
rateLimiter,
|
|
152
194
|
sandboxNotice,
|
|
@@ -322,6 +364,184 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
322
364
|
let sessionEvents: {
|
|
323
365
|
emit: (e: { type: "provider:extension"; kind: string; data: unknown }) => void
|
|
324
366
|
} | null = null
|
|
367
|
+
// Adaptor semantik presentasi Fase 1 (AGENT_PRESENTATION_ARCHITECTURE_V2_1):
|
|
368
|
+
// mengamati bus kernel dan memancarkan DomainEvent ke subscriber-nya sendiri.
|
|
369
|
+
// Dual-subscribe dengan sink lama — perilaku user NOL berubah pada Fase 1.
|
|
370
|
+
let presentation: PresentationAdapter | null = null
|
|
371
|
+
// Fase 3 dark-launch: reducer berjalan paralel (shadow) — hasil DIBUANG,
|
|
372
|
+
// tidak mengontrol output. Divergensi = reduce melempar (harusnya 0).
|
|
373
|
+
let shadowState: PresentationState | null = null
|
|
374
|
+
let shadowDiag: ReducerDiagnostics | null = null
|
|
375
|
+
let shadowDivergence = 0
|
|
376
|
+
let shadowUnsub: (() => void) | null = null
|
|
377
|
+
const presentationSubscribers = new Set<(event: UiPresentationEvent) => void>()
|
|
378
|
+
// Content store in-memory untuk query /expand; presentation V2 adalah jalur
|
|
379
|
+
// production setelah cleanup Fase 7.
|
|
380
|
+
let contentStore: ContentStore | null = null
|
|
381
|
+
const getShadowDiagnostics = (): {
|
|
382
|
+
divergence: number
|
|
383
|
+
eventsIn: number
|
|
384
|
+
duplicateTerminal: number
|
|
385
|
+
lateEvent: number
|
|
386
|
+
orphanTool: number
|
|
387
|
+
orphanApproval: number
|
|
388
|
+
duplicateTurn: number
|
|
389
|
+
} => ({
|
|
390
|
+
divergence: shadowDivergence,
|
|
391
|
+
eventsIn: shadowDiag?.eventsIn ?? 0,
|
|
392
|
+
duplicateTerminal: shadowDiag?.duplicateTerminal ?? 0,
|
|
393
|
+
lateEvent: shadowDiag?.lateEvent ?? 0,
|
|
394
|
+
orphanTool: shadowDiag?.orphanTool ?? 0,
|
|
395
|
+
orphanApproval: shadowDiag?.orphanApproval ?? 0,
|
|
396
|
+
duplicateTurn: shadowDiag?.duplicateTurn ?? 0,
|
|
397
|
+
})
|
|
398
|
+
const getPresentationSnapshot = (): UiPresentationSnapshot => {
|
|
399
|
+
if (!shadowState) return { activities: [], turns: [] }
|
|
400
|
+
const activities: UiPresentationActivity[] = [...shadowState.activities.values()].map((a) => ({
|
|
401
|
+
seq: a.seq,
|
|
402
|
+
turnId: a.turnId,
|
|
403
|
+
sessionId: a.sessionId,
|
|
404
|
+
toolCallId: a.toolCallId,
|
|
405
|
+
name: a.identity.name,
|
|
406
|
+
qualified: a.identity.qualified,
|
|
407
|
+
...(a.target ? { target: a.target } : {}),
|
|
408
|
+
status: a.status as UiToolStatus,
|
|
409
|
+
tsStart: a.tsStart,
|
|
410
|
+
...(a.tsEnd !== undefined ? { tsEnd: a.tsEnd } : {}),
|
|
411
|
+
...(a.durationMs !== undefined ? { durationMs: a.durationMs } : {}),
|
|
412
|
+
...(a.summary ? { summary: a.summary } : {}),
|
|
413
|
+
...(a.error
|
|
414
|
+
? {
|
|
415
|
+
error: {
|
|
416
|
+
cause: a.error.cause,
|
|
417
|
+
message: a.error.message,
|
|
418
|
+
...(a.error.hint ? { hint: a.error.hint } : {}),
|
|
419
|
+
},
|
|
420
|
+
}
|
|
421
|
+
: {}),
|
|
422
|
+
...(a.denyReason ? { denyReason: a.denyReason } : {}),
|
|
423
|
+
...(a.receipt
|
|
424
|
+
? {
|
|
425
|
+
receipt: {
|
|
426
|
+
...(a.receipt.paths ? { paths: a.receipt.paths } : {}),
|
|
427
|
+
...(a.receipt.checkpointId ? { checkpointId: a.receipt.checkpointId } : {}),
|
|
428
|
+
...(a.receipt.stats ? { stats: a.receipt.stats } : {}),
|
|
429
|
+
...(a.receipt.test ? { test: a.receipt.test } : {}),
|
|
430
|
+
...(a.receipt.cmd ? { cmd: a.receipt.cmd } : {}),
|
|
431
|
+
},
|
|
432
|
+
}
|
|
433
|
+
: {}),
|
|
434
|
+
...(a.parentToolCallId ? { parentToolCallId: a.parentToolCallId } : {}),
|
|
435
|
+
...(a.supersedes ? { supersedes: a.supersedes } : {}),
|
|
436
|
+
...(a.expandRef
|
|
437
|
+
? { expandRef: { toolCallId: a.expandRef.toolCallId, idx: a.expandRef.idx } }
|
|
438
|
+
: {}),
|
|
439
|
+
}))
|
|
440
|
+
const turns: UiPresentationTurn[] = [...shadowState.turns.values()].map((turn) => ({
|
|
441
|
+
turnId: turn.turnId,
|
|
442
|
+
status: turn.status,
|
|
443
|
+
...(turn.summary ? { summary: turn.summary as UiTurnSummary } : {}),
|
|
444
|
+
}))
|
|
445
|
+
return { activities, turns }
|
|
446
|
+
}
|
|
447
|
+
const toPresentationEvent = (event: DomainEvent): UiPresentationEvent | null => {
|
|
448
|
+
switch (event.type) {
|
|
449
|
+
case "turn.started":
|
|
450
|
+
return { type: event.type, seq: event.eventSeq, turnId: event.turnId }
|
|
451
|
+
case "turn.completed":
|
|
452
|
+
return {
|
|
453
|
+
type: event.type,
|
|
454
|
+
seq: event.eventSeq,
|
|
455
|
+
turnId: event.turnId,
|
|
456
|
+
summary: event.summary,
|
|
457
|
+
}
|
|
458
|
+
case "turn.failed":
|
|
459
|
+
return {
|
|
460
|
+
type: event.type,
|
|
461
|
+
seq: event.eventSeq,
|
|
462
|
+
turnId: event.turnId,
|
|
463
|
+
error: event.error.message,
|
|
464
|
+
cause: event.error.cause,
|
|
465
|
+
}
|
|
466
|
+
case "turn.cancelled":
|
|
467
|
+
return {
|
|
468
|
+
type: event.type,
|
|
469
|
+
seq: event.eventSeq,
|
|
470
|
+
turnId: event.turnId,
|
|
471
|
+
reason: event.reason,
|
|
472
|
+
}
|
|
473
|
+
case "tool.started":
|
|
474
|
+
return {
|
|
475
|
+
type: event.type,
|
|
476
|
+
seq: event.eventSeq,
|
|
477
|
+
turnId: event.turnId,
|
|
478
|
+
toolCallId: event.toolCallId,
|
|
479
|
+
name: event.identity.name,
|
|
480
|
+
qualified: event.identity.qualified,
|
|
481
|
+
target: event.argsSummary.target,
|
|
482
|
+
status: "running",
|
|
483
|
+
tsStart: event.ts,
|
|
484
|
+
}
|
|
485
|
+
case "tool.completed":
|
|
486
|
+
case "tool.failed":
|
|
487
|
+
case "tool.denied":
|
|
488
|
+
case "tool.cancelled":
|
|
489
|
+
return {
|
|
490
|
+
type: event.type,
|
|
491
|
+
seq: event.eventSeq,
|
|
492
|
+
turnId: event.turnId,
|
|
493
|
+
toolCallId: event.toolCallId,
|
|
494
|
+
status:
|
|
495
|
+
event.type === "tool.completed"
|
|
496
|
+
? "completed"
|
|
497
|
+
: event.type === "tool.failed"
|
|
498
|
+
? "failed"
|
|
499
|
+
: event.type === "tool.denied"
|
|
500
|
+
? "denied"
|
|
501
|
+
: "cancelled",
|
|
502
|
+
...("durationMs" in event ? { durationMs: event.durationMs } : {}),
|
|
503
|
+
...("message" in event ? { message: event.message } : {}),
|
|
504
|
+
...("cause" in event ? { cause: event.cause } : {}),
|
|
505
|
+
...("reason" in event ? { reason: event.reason } : {}),
|
|
506
|
+
}
|
|
507
|
+
case "approval.requested":
|
|
508
|
+
return {
|
|
509
|
+
type: event.type,
|
|
510
|
+
seq: event.eventSeq,
|
|
511
|
+
turnId: event.turnId,
|
|
512
|
+
approvalId: event.approvalId,
|
|
513
|
+
toolCallId: event.toolCallId,
|
|
514
|
+
name: event.identity.name,
|
|
515
|
+
qualified: event.identity.qualified,
|
|
516
|
+
target: event.argsSummary.target,
|
|
517
|
+
via: event.via,
|
|
518
|
+
}
|
|
519
|
+
case "approval.settled":
|
|
520
|
+
return {
|
|
521
|
+
type: event.type,
|
|
522
|
+
seq: event.eventSeq,
|
|
523
|
+
turnId: event.turnId,
|
|
524
|
+
approvalId: event.approvalId,
|
|
525
|
+
toolCallId: event.toolCallId,
|
|
526
|
+
outcome: event.outcome,
|
|
527
|
+
}
|
|
528
|
+
default:
|
|
529
|
+
return null
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
const onPresentationEvent = (handler: (event: UiPresentationEvent) => void): (() => void) => {
|
|
533
|
+
presentationSubscribers.add(handler)
|
|
534
|
+
return () => presentationSubscribers.delete(handler)
|
|
535
|
+
}
|
|
536
|
+
const publishPresentationEvent = (event: Parameters<typeof toPresentationEvent>[0]): void => {
|
|
537
|
+
const projected = toPresentationEvent(event)
|
|
538
|
+
if (!projected) return
|
|
539
|
+
for (const handler of [...presentationSubscribers]) {
|
|
540
|
+
try {
|
|
541
|
+
handler(projected)
|
|
542
|
+
} catch {}
|
|
543
|
+
}
|
|
544
|
+
}
|
|
325
545
|
const compaction = process.env.DEEPSEEK_API_KEY
|
|
326
546
|
? createLlmCompaction({
|
|
327
547
|
apiKey: process.env.DEEPSEEK_API_KEY,
|
|
@@ -354,6 +574,10 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
354
574
|
// View pertanyaan ask_user — composition root meng-inject, tool menolak
|
|
355
575
|
// jalan tanpanya (fail-closed, sama seperti `ask` pada permission).
|
|
356
576
|
setAskTextFn(promptAskText)
|
|
577
|
+
// Cermin observability ask_user → adaptor presentasi (perilaku tool utuh).
|
|
578
|
+
setAskApprovalHook((e) => {
|
|
579
|
+
presentation?.publishApproval(e)
|
|
580
|
+
})
|
|
357
581
|
// Warisan routing sub-agen (audit #14): anak memakai limiter BERSAMA
|
|
358
582
|
// (satu bucket — tak memicu 429 yang baru dihindari parent) dan menghormati
|
|
359
583
|
// --provider parent. Model diwarisi live via ToolContext (lihat task.ts).
|
|
@@ -382,6 +606,11 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
382
606
|
systemExtra: (systemExtra ?? "") + recoveryAppendix,
|
|
383
607
|
model: modelRef.current,
|
|
384
608
|
ask: promptAsk,
|
|
609
|
+
// Cermin observability persetujuan → adaptor presentasi. Keputusan gate
|
|
610
|
+
// tetap milik permission handler; hook ini hanya melaporkan.
|
|
611
|
+
onApprovalEvent: (e) => {
|
|
612
|
+
presentation?.publishApproval(e)
|
|
613
|
+
},
|
|
385
614
|
onPermissions: (ctl) => {
|
|
386
615
|
permissions = ctl
|
|
387
616
|
},
|
|
@@ -389,6 +618,7 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
389
618
|
...(resumeTurnCount !== undefined ? { turnCount: resumeTurnCount } : {}),
|
|
390
619
|
...(maxSteps ? { maxSteps } : {}),
|
|
391
620
|
...(contextWindowTokens ? { contextWindowTokens } : {}),
|
|
621
|
+
...(keepRecentTurns ? { keepRecentTurns } : {}),
|
|
392
622
|
...(safeConcurrency ? { concurrency: safeConcurrency } : {}),
|
|
393
623
|
...(safeWriteConcurrency ? { writeConcurrency: safeWriteConcurrency } : {}),
|
|
394
624
|
timeoutMs: effectiveTimeoutMs === 0 ? Infinity : effectiveTimeoutMs,
|
|
@@ -398,13 +628,48 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
398
628
|
// Kontrak control-plane (Phase 6): late-binding bus untuk usage kompaksi —
|
|
399
629
|
// onUsage dipanggil di tengah turn, saat bus sudah hidup.
|
|
400
630
|
sessionEvents = session.events
|
|
631
|
+
// Content store Fase 4: adapter menaruh konten completed ke store (put
|
|
632
|
+
// selalu jalan); expand(id) di tui di belakang flag.
|
|
633
|
+
contentStore = createContentStore()
|
|
634
|
+
// Adaptor mulai mengamati sejak bus hidup (closure onApprovalEvent di atas
|
|
635
|
+
// aman: check() pertama selalu terjadi setelah wiring ini, saat run()).
|
|
636
|
+
presentation = createPresentationAdapter(session.events, {
|
|
637
|
+
sessionId,
|
|
638
|
+
...(contentStore ? { contentStore } : {}),
|
|
639
|
+
})
|
|
640
|
+
// Shadow reducer (Fase 3): consume DomainEvent yang sama, hasil dibuang.
|
|
641
|
+
// Shadow reducer berjalan paralel (observability), output TUI/linear memakai
|
|
642
|
+
// proyeksi presentasi yang sama.
|
|
643
|
+
try {
|
|
644
|
+
shadowState = createInitialState(sessionId)
|
|
645
|
+
shadowDiag = createReducerDiagnostics()
|
|
646
|
+
shadowUnsub = presentation.onEvent((e) => {
|
|
647
|
+
try {
|
|
648
|
+
if (shadowState && shadowDiag) reduce(shadowState, e, shadowDiag)
|
|
649
|
+
} catch {
|
|
650
|
+
shadowDivergence++
|
|
651
|
+
}
|
|
652
|
+
publishPresentationEvent(e)
|
|
653
|
+
})
|
|
654
|
+
} catch {
|
|
655
|
+
shadowDivergence++
|
|
656
|
+
}
|
|
401
657
|
|
|
402
658
|
const effectiveInitialModel = modelRef.current ?? cfg.providers[0]?.models[0] ?? "default"
|
|
403
659
|
|
|
404
660
|
// ── Mutation journal wiring (AUDIT #01C): intent di execution:started,
|
|
405
661
|
// terminal di execution:completed — keduanya post-gate kernel. Total:
|
|
406
662
|
// kegagalan tulis jurnal tak pernah menggagalkan turn (degraded-loud).
|
|
407
|
-
|
|
663
|
+
// Fase 4: onCommitted → file.changed (receipt paths+journalSeq) ke adapter.
|
|
664
|
+
attachMutationJournal(session, {
|
|
665
|
+
sessionId,
|
|
666
|
+
cwd,
|
|
667
|
+
onCommitted: (info) => {
|
|
668
|
+
try {
|
|
669
|
+
presentation?.noteFileChanged(info)
|
|
670
|
+
} catch {}
|
|
671
|
+
},
|
|
672
|
+
})
|
|
408
673
|
|
|
409
674
|
// ── Shadow checkpoint ──
|
|
410
675
|
// Repo git: simpan SHA tree pre/post turn (O(delta), tanpa cap file, tidak
|
|
@@ -485,6 +750,10 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
485
750
|
...(t0 !== undefined ? { durationMs: Date.now() - t0 } : {}),
|
|
486
751
|
args: summarizeArgs(call.args),
|
|
487
752
|
sandbox: process.env.MINICODE_SANDBOX ?? "none",
|
|
753
|
+
// F1.2: token kumulatif sesi saat tool selesai — bahan kurva token.
|
|
754
|
+
// `usage` dideklarasikan di bawah, tapi callback ini baru jalan setelah
|
|
755
|
+
// createCliSession selesai — aman dari TDZ.
|
|
756
|
+
totalTokens: usage.getSession().totalTokens,
|
|
488
757
|
}).catch(() => {})
|
|
489
758
|
} catch {}
|
|
490
759
|
})
|
|
@@ -499,6 +768,8 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
499
768
|
tools: s.toolCalls.length,
|
|
500
769
|
errors: s.results.filter((r) => r.isError).length,
|
|
501
770
|
sandbox: process.env.MINICODE_SANDBOX ?? "none",
|
|
771
|
+
// F1.2: sama seperti baris tool — kumulatif sesi saat step selesai.
|
|
772
|
+
totalTokens: usage.getSession().totalTokens,
|
|
502
773
|
}).catch(() => {})
|
|
503
774
|
} catch {}
|
|
504
775
|
})
|
|
@@ -595,7 +866,22 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
595
866
|
},
|
|
596
867
|
})
|
|
597
868
|
try {
|
|
598
|
-
|
|
869
|
+
try {
|
|
870
|
+
await session.run(prompt, { model: modelRef.current, signal: ctl.signal })
|
|
871
|
+
} catch (e) {
|
|
872
|
+
// Kernel diam pada gagal/abort/timeout (turn:completed hanya sukses):
|
|
873
|
+
// adaptor merekonstruksi turn.failed/cancelled dari sini. Error asli
|
|
874
|
+
// selalu dilempar ulang — observability tak menutupi kegagalan.
|
|
875
|
+
try {
|
|
876
|
+
presentation?.noteRunSettled(e, {
|
|
877
|
+
aborted: ctl.signal.aborted,
|
|
878
|
+
parentAborted: s?.aborted === true,
|
|
879
|
+
})
|
|
880
|
+
} catch {
|
|
881
|
+
// Diagnostik adaptor tak boleh menutupi error turn.
|
|
882
|
+
}
|
|
883
|
+
throw e
|
|
884
|
+
}
|
|
599
885
|
} finally {
|
|
600
886
|
stopWatch()
|
|
601
887
|
if (s) s.removeEventListener("abort", onParentAbort)
|
|
@@ -696,7 +982,21 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
696
982
|
const richStatus = process.env.MINICODE_STATUSLINE === "rich"
|
|
697
983
|
const attachUI = () => {
|
|
698
984
|
detachUI()
|
|
699
|
-
|
|
985
|
+
// Mode interaktif = TUI fullscreen memiliki layar (kontrak I3: App
|
|
986
|
+
// penulis tunggal). Printer linier + spinner turn-status DITEKAN agar tak
|
|
987
|
+
// mengotori alt-screen — state tetap jalan (quiet: rememberTurn untuk
|
|
988
|
+
// /copy, collapsed view untuk /expand). One-shot/exec (enterRepl false)
|
|
989
|
+
// tetap melukis seperti dulu.
|
|
990
|
+
detachSimple = attachSimpleLogger(session.events, {
|
|
991
|
+
verbose,
|
|
992
|
+
quiet: enterRepl === true,
|
|
993
|
+
getSnapshot: getPresentationSnapshot,
|
|
994
|
+
onPresentationEvent,
|
|
995
|
+
})
|
|
996
|
+
if (enterRepl === true) {
|
|
997
|
+
turnStatus = null
|
|
998
|
+
return
|
|
999
|
+
}
|
|
700
1000
|
turnStatus = attachTurnStatus(session.events, {
|
|
701
1001
|
initialModel: effectiveInitialModel,
|
|
702
1002
|
getModel: () => modelRef.current ?? effectiveInitialModel,
|
|
@@ -739,6 +1039,19 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
739
1039
|
async function close(): Promise<void> {
|
|
740
1040
|
detachUI()
|
|
741
1041
|
detachBusDebug()
|
|
1042
|
+
try {
|
|
1043
|
+
shadowUnsub?.()
|
|
1044
|
+
} catch {}
|
|
1045
|
+
shadowUnsub = null
|
|
1046
|
+
presentationSubscribers.clear()
|
|
1047
|
+
shadowState = null
|
|
1048
|
+
shadowDiag = null
|
|
1049
|
+
contentStore = null
|
|
1050
|
+
try {
|
|
1051
|
+
presentation?.dispose()
|
|
1052
|
+
} catch {}
|
|
1053
|
+
presentation = null
|
|
1054
|
+
setAskApprovalHook(undefined)
|
|
742
1055
|
// background job harus mati bersama CLI — jangan tinggalkan proses yatim
|
|
743
1056
|
killAllBackgroundJobs()
|
|
744
1057
|
await mcpCloseAll()
|
|
@@ -776,5 +1089,37 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
776
1089
|
runPromptWithVerify,
|
|
777
1090
|
permissions,
|
|
778
1091
|
close,
|
|
1092
|
+
/** Fase 3 dark-launch: counter shadow reducer (divergensi harus 0). */
|
|
1093
|
+
getShadowDiagnostics,
|
|
1094
|
+
getPresentationSnapshot,
|
|
1095
|
+
onPresentationEvent,
|
|
1096
|
+
expandAllContent: (): ContentEntry[] => contentStore?.expandAll() ?? [],
|
|
1097
|
+
/** Query content store untuk /expand [id] (buka-ulang identik). */
|
|
1098
|
+
expandContent: (toolCallId: string): ContentEntry[] => {
|
|
1099
|
+
if (!contentStore) return []
|
|
1100
|
+
// Durable fallback: sqlite tool result full (hanya output; reasoning
|
|
1101
|
+
// di luar retensi = penanda). Best-effort — miss = tanpa konten.
|
|
1102
|
+
const durable = (id: string): string | undefined => {
|
|
1103
|
+
try {
|
|
1104
|
+
const sess = loadSession(resumeId ?? sessionId, cwd)
|
|
1105
|
+
if (!sess) return undefined
|
|
1106
|
+
for (const m of sess.messages as {
|
|
1107
|
+
role?: string
|
|
1108
|
+
toolCallId?: string
|
|
1109
|
+
content?: unknown
|
|
1110
|
+
}[]) {
|
|
1111
|
+
if (m.role === "tool" && m.toolCallId === id) {
|
|
1112
|
+
return typeof m.content === "string"
|
|
1113
|
+
? m.content
|
|
1114
|
+
: m.content != null
|
|
1115
|
+
? JSON.stringify(m.content)
|
|
1116
|
+
: undefined
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
} catch {}
|
|
1120
|
+
return undefined
|
|
1121
|
+
}
|
|
1122
|
+
return contentStore.expand(toolCallId, durable)
|
|
1123
|
+
},
|
|
779
1124
|
}
|
|
780
1125
|
}
|