minicode-ai 0.13.1 → 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 +17 -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/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 +2 -1
- 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
package/cli/setup.ts
CHANGED
|
@@ -47,6 +47,7 @@ import {
|
|
|
47
47
|
runVerify,
|
|
48
48
|
runWithSelfHeal,
|
|
49
49
|
} from "../src/policy/verifier.ts"
|
|
50
|
+
import { VerifyWorkModeConflictError } from "../src/policy/work-mode.ts"
|
|
50
51
|
import { createPresentationAdapter, type PresentationAdapter } from "../src/presentation/adapter.ts"
|
|
51
52
|
import { type DomainEvent, DURABILITY } from "../src/presentation/events.ts"
|
|
52
53
|
import { createInitialState, type PresentationState } from "../src/presentation/model.ts"
|
|
@@ -156,10 +157,12 @@ import {
|
|
|
156
157
|
loadPresentationEvents,
|
|
157
158
|
loadSession,
|
|
158
159
|
loadSessionUsageSummary,
|
|
160
|
+
loadSessionWorkMode,
|
|
159
161
|
loadThreadHistoryWithSeq,
|
|
160
162
|
type PresentationPersistStats,
|
|
161
163
|
RefusedHistoryRewriteError,
|
|
162
164
|
saveSession,
|
|
165
|
+
saveSessionWorkMode,
|
|
163
166
|
shrinkThreadHistory,
|
|
164
167
|
ThreadArchivedError,
|
|
165
168
|
terminalizeChildRuns,
|
|
@@ -183,6 +186,7 @@ import {
|
|
|
183
186
|
} from "../src/task/production-scheduler.ts"
|
|
184
187
|
import { SchedulerObservability } from "../src/task/scheduler-observability.ts"
|
|
185
188
|
import { SESSION_RENEW_INTERVAL_MS } from "../src/task/session-authority.ts"
|
|
189
|
+
import { setTaskTransitionSink, TaskStore } from "../src/task/store.ts"
|
|
186
190
|
import { createTaskIdentityResolver, settleSessionVerifyingTasks } from "../src/task/sync.ts"
|
|
187
191
|
import {
|
|
188
192
|
classifyToolResult,
|
|
@@ -221,8 +225,43 @@ import type {
|
|
|
221
225
|
UiTurnSummary,
|
|
222
226
|
} from "../src/ui/contract.ts"
|
|
223
227
|
import { c } from "../src/ui/render/theme.ts"
|
|
228
|
+
// [Area A · PROMPT 06] State UI per-sesi. Satu instance per `createCliSession`.
|
|
229
|
+
import { UiSessionState } from "../src/ui/session-state.ts"
|
|
224
230
|
import { runSetupWizard } from "./wizard.ts"
|
|
225
231
|
|
|
232
|
+
/**
|
|
233
|
+
* P2.3 (Session 4): kontrak runtime single-session ditegakkan di boundary RUN,
|
|
234
|
+
* bukan hanya didokumentasikan. Satu proses hanya boleh menjalankan SATU sesi
|
|
235
|
+
* agent pada satu waktu. Konstruksi dua sesi tetap boleh (mis. UI isolation
|
|
236
|
+
* test), dan daemon multi-consumer tetap berjalan karena hanya ada satu sesi.
|
|
237
|
+
* Sesi berikutnya boleh berjalan setelah sesi aktif selesai/ditutup.
|
|
238
|
+
*/
|
|
239
|
+
let activeAgentSessionId: string | null = null
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Seam uji deterministik untuk memegang guard tanpa menjalankan provider.
|
|
243
|
+
* Produksi TIDAK pernah memanggil ini; hanya test yang menggunakannya agar
|
|
244
|
+
* tidak bergantung pada timing abort provider nyata.
|
|
245
|
+
*/
|
|
246
|
+
export function __setActiveAgentSessionForTest(sessionId: string | null): void {
|
|
247
|
+
activeAgentSessionId = sessionId
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export function __getActiveAgentSessionForTest(): string | null {
|
|
251
|
+
return activeAgentSessionId
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export class ConcurrentAgentSessionError extends Error {
|
|
255
|
+
readonly code = "CONCURRENT_SESSION"
|
|
256
|
+
constructor(active: string, attempted: string) {
|
|
257
|
+
super(
|
|
258
|
+
`[runtime] CONCURRENT_SESSION: session ${active} is already running in this process; ` +
|
|
259
|
+
`session ${attempted} refused (one agent session per process)`,
|
|
260
|
+
)
|
|
261
|
+
this.name = "ConcurrentAgentSessionError"
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
226
265
|
export interface CliSessionOptions {
|
|
227
266
|
cwd?: string
|
|
228
267
|
sessionId: string
|
|
@@ -266,6 +305,15 @@ export interface CliSessionOptions {
|
|
|
266
305
|
* setupToolLayer (visibilitas) dan createMinicodeSession (handler ceiling).
|
|
267
306
|
*/
|
|
268
307
|
workMode?: "DISCUSS" | "PLAN" | "EXECUTE"
|
|
308
|
+
/**
|
|
309
|
+
* P12 S2.2 (D-2) — transparansi resume. Benar bila operator memberi sinyal
|
|
310
|
+
* WorkMode eksplisit (--work-mode / MINICODE_WORK_MODE). WorkMode TIDAK
|
|
311
|
+
* dipersist antar-sesi; saat resume tanpa sinyal eksplisit, WorkMode kembali
|
|
312
|
+
* ke EXECUTE. Bila scope ini `false` DAN identitas sesi `resumed`, composition
|
|
313
|
+
* root menulis SATU baris stderr human-facing (bukan output machine) agar
|
|
314
|
+
* transisi tidak terjadi diam-diam.
|
|
315
|
+
*/
|
|
316
|
+
workModeExplicit?: boolean
|
|
269
317
|
/**
|
|
270
318
|
* [PHASE 6U] Opt-in autonomous Scheduler. DEFAULT OFF - `undefined` and
|
|
271
319
|
* `false` behave identically, and for both the composition root is never called.
|
|
@@ -361,14 +409,32 @@ export interface CliSession {
|
|
|
361
409
|
usage: ReturnType<typeof createUsageCollector>
|
|
362
410
|
budget?: number
|
|
363
411
|
budgetStrict?: boolean
|
|
412
|
+
/** F-CTX-1: jendela konteks yang dipakai footer TUI (window %) — flag --context-window. */
|
|
413
|
+
contextWindowTokens?: number
|
|
364
414
|
/** Flag opt-in local config sesi ini — dipakai perintah REPL (/sync,
|
|
365
415
|
* /provider, /model) agar konsisten dengan provider/tool yang aktif. */
|
|
366
416
|
allowLocalConfig: boolean
|
|
367
417
|
/** P2.3: jumlah hit RAG memory yang di-inject ke system prompt sesi ini. */
|
|
368
418
|
memoryHits: number
|
|
369
419
|
detachSimple: () => void
|
|
420
|
+
/**
|
|
421
|
+
* [Area A · PROMPT 06] State UI milik SESI ini (collapse/detail/reasoning +
|
|
422
|
+
* buffer /copy + error tertunda). SATU instance per sesi; TUI dan printer
|
|
423
|
+
* linier sesi yang sama berbagi instance ini, sedangkan sesi lain di proses
|
|
424
|
+
* yang sama punya instance sendiri — dua sesi tak saling menimpa.
|
|
425
|
+
*/
|
|
426
|
+
uiState: UiSessionState
|
|
370
427
|
persistCurrent: (usageData: unknown) => Promise<void>
|
|
371
428
|
runPromptWithVerify: (prompt: string, signal?: AbortSignal) => Promise<void>
|
|
429
|
+
/**
|
|
430
|
+
* P2.3 daemon: identitas/status run LIVE untuk operator control. runId
|
|
431
|
+
* berasal dari jurnal Run kanonik (bukan id sintetis daemon); status
|
|
432
|
+
* RUNNING selama turn belum terminal. Absen = belum ada run di sesi ini.
|
|
433
|
+
*/
|
|
434
|
+
runState: () => {
|
|
435
|
+
runId: string | null
|
|
436
|
+
status: "RUNNING" | "COMPLETED" | "FAILED" | "INTERRUPTED" | null
|
|
437
|
+
}
|
|
372
438
|
/**
|
|
373
439
|
* P11.1 — ringkasan hasil verify terakhir, read-only untuk summary mesin
|
|
374
440
|
* (`exec --json`). Null bila verify belum pernah jalan di sesi ini.
|
|
@@ -448,7 +514,7 @@ export interface CliSession {
|
|
|
448
514
|
adoption: AdoptionResult | null
|
|
449
515
|
}
|
|
450
516
|
|
|
451
|
-
|
|
517
|
+
function mapPresentationEvent(event: DomainEvent): UiPresentationEvent | null {
|
|
452
518
|
switch (event.type) {
|
|
453
519
|
case "user.message":
|
|
454
520
|
return {
|
|
@@ -575,6 +641,7 @@ export function toPresentationEvent(event: DomainEvent): UiPresentationEvent | n
|
|
|
575
641
|
message: event.message,
|
|
576
642
|
cause: event.cause,
|
|
577
643
|
...(event.hint ? { hint: event.hint } : {}),
|
|
644
|
+
...(event.schemaDrift ? { schemaDrift: event.schemaDrift } : {}),
|
|
578
645
|
expandRef: event.expandRef,
|
|
579
646
|
...(event.parentLink ? { parentToolCallId: event.parentLink.parentToolCallId } : {}),
|
|
580
647
|
}
|
|
@@ -610,6 +677,8 @@ export function toPresentationEvent(event: DomainEvent): UiPresentationEvent | n
|
|
|
610
677
|
qualified: event.identity.qualified,
|
|
611
678
|
target: event.argsSummary.target,
|
|
612
679
|
via: event.via,
|
|
680
|
+
...(event.riskTier ? { riskTier: event.riskTier } : {}),
|
|
681
|
+
...(event.diffPreview ? { diffPreview: event.diffPreview } : {}),
|
|
613
682
|
}
|
|
614
683
|
case "approval.settled":
|
|
615
684
|
return {
|
|
@@ -713,6 +782,54 @@ export function toPresentationEvent(event: DomainEvent): UiPresentationEvent | n
|
|
|
713
782
|
checkpointId: event.checkpointId,
|
|
714
783
|
paths: event.paths,
|
|
715
784
|
}
|
|
785
|
+
case "consequence.decided":
|
|
786
|
+
return {
|
|
787
|
+
type: event.type,
|
|
788
|
+
seq: event.eventSeq,
|
|
789
|
+
turnId: event.turnId,
|
|
790
|
+
verdict: event.verdict,
|
|
791
|
+
failureClass: event.failureClass,
|
|
792
|
+
nextAction: event.nextAction,
|
|
793
|
+
message: event.rationale,
|
|
794
|
+
severity: event.verdict === "FAIL" || event.verdict === "BLOCKED" ? "error" : "warning",
|
|
795
|
+
...(event.newEvidenceSinceLastAttempt !== undefined
|
|
796
|
+
? { newEvidenceSinceLastAttempt: event.newEvidenceSinceLastAttempt }
|
|
797
|
+
: {}),
|
|
798
|
+
}
|
|
799
|
+
case "context.window":
|
|
800
|
+
return {
|
|
801
|
+
type: event.type,
|
|
802
|
+
seq: event.eventSeq,
|
|
803
|
+
turnId: event.turnId,
|
|
804
|
+
usedTokens: event.usedTokens,
|
|
805
|
+
windowTokens: event.windowTokens,
|
|
806
|
+
...(event.percent !== undefined ? { percent: event.percent } : {}),
|
|
807
|
+
...(event.costUsd !== undefined ? { costUsd: event.costUsd } : {}),
|
|
808
|
+
...(event.providerModel ? { providerModel: event.providerModel } : {}),
|
|
809
|
+
}
|
|
810
|
+
case "context.cutoff":
|
|
811
|
+
return {
|
|
812
|
+
type: event.type,
|
|
813
|
+
seq: event.eventSeq,
|
|
814
|
+
turnId: event.turnId,
|
|
815
|
+
reason: event.reason,
|
|
816
|
+
message: event.reason,
|
|
817
|
+
severity: "warning",
|
|
818
|
+
...(event.usedTokens !== undefined ? { usedTokens: event.usedTokens } : {}),
|
|
819
|
+
...(event.windowTokens !== undefined ? { windowTokens: event.windowTokens } : {}),
|
|
820
|
+
}
|
|
821
|
+
case "task.status":
|
|
822
|
+
return {
|
|
823
|
+
type: event.type,
|
|
824
|
+
seq: event.eventSeq,
|
|
825
|
+
turnId: event.turnId,
|
|
826
|
+
taskId: event.taskId,
|
|
827
|
+
taskStatus: event.status,
|
|
828
|
+
...(event.parentId ? { parentId: event.parentId } : {}),
|
|
829
|
+
...(event.dependsOn ? { dependsOn: [...event.dependsOn] } : {}),
|
|
830
|
+
...(event.revision !== undefined ? { revision: event.revision } : {}),
|
|
831
|
+
...(event.verification ? { taskVerification: event.verification } : {}),
|
|
832
|
+
}
|
|
716
833
|
default: {
|
|
717
834
|
const exhaustive: never = event
|
|
718
835
|
void exhaustive
|
|
@@ -721,6 +838,23 @@ export function toPresentationEvent(event: DomainEvent): UiPresentationEvent | n
|
|
|
721
838
|
}
|
|
722
839
|
}
|
|
723
840
|
|
|
841
|
+
/**
|
|
842
|
+
* P1.6: proyeksi UI membawa identitas session/child-run tanpa mengulang setiap
|
|
843
|
+
* case. `sessionId` DomainEvent adalah session pemilik event (anak untuk forward),
|
|
844
|
+
* `parentLink` adalah taut ke pemanggil — tiga makna yang tidak boleh disamakan.
|
|
845
|
+
*/
|
|
846
|
+
export function toPresentationEvent(event: DomainEvent): UiPresentationEvent | null {
|
|
847
|
+
const mapped = mapPresentationEvent(event)
|
|
848
|
+
if (!mapped) return null
|
|
849
|
+
const link = (event as { parentLink?: { childSessionId?: string; runId?: string } }).parentLink
|
|
850
|
+
return {
|
|
851
|
+
...mapped,
|
|
852
|
+
sessionId: event.sessionId,
|
|
853
|
+
...(link?.childSessionId ? { childSessionId: link.childSessionId } : {}),
|
|
854
|
+
...(link?.runId ? { runId: link.runId } : {}),
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
|
|
724
858
|
export function parseVerifyTestEvidence(
|
|
725
859
|
command: string,
|
|
726
860
|
output: string,
|
|
@@ -766,6 +900,7 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
766
900
|
adoptTask,
|
|
767
901
|
allowLocalConfig,
|
|
768
902
|
workMode = "EXECUTE",
|
|
903
|
+
workModeExplicit = false,
|
|
769
904
|
maxSteps,
|
|
770
905
|
contextWindowTokens,
|
|
771
906
|
keepRecentTurns,
|
|
@@ -773,6 +908,11 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
773
908
|
rateLimiter,
|
|
774
909
|
sandboxNotice,
|
|
775
910
|
} = opts
|
|
911
|
+
// [Area A · PROMPT 06] State UI milik SESI ini. Dibuat SEKALI per sesi dan
|
|
912
|
+
// dipakai bersama oleh TUI (Transcript) + printer linier sesi yang sama.
|
|
913
|
+
// Env hanya jadi nilai awal; sesi lain di proses yang sama punya state
|
|
914
|
+
// sendiri sehingga tak saling menimpa collapse/compact/reasoning.
|
|
915
|
+
const uiState = new UiSessionState()
|
|
776
916
|
const modelRef = { current: modelOverride }
|
|
777
917
|
// P2.1 — SATU-SATUNYA keputusan identitas sesi. Sesudah baris ini,
|
|
778
918
|
// `sessionId` adalah identitas kanonik durable; id volatil hanya `bootId`
|
|
@@ -836,6 +976,17 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
836
976
|
`${c.dim(`[adopt] ADOPTED ${adoptTask.taskId} ${adoptTask.sourceSessionId} -> ${sessionId} revision=${moved?.revision ?? "?"} status=${moved?.status ?? "?"} exec=${adoption.transfer?.execGeneration ?? "?"}${adoption.fencedFormerOwner ? " (former owner fenced)" : ""}\n`)}`,
|
|
837
977
|
)
|
|
838
978
|
}
|
|
979
|
+
// P0.2 (Q5): saat `--resume` tanpa sinyal WorkMode eksplisit, pulihkan
|
|
980
|
+
// WorkMode tersimpan dari metadata sesi (NULL legacy → default EXECUTE).
|
|
981
|
+
const persistedWorkMode = identity.resumed ? loadSessionWorkMode(sessionId, cwd) : undefined
|
|
982
|
+
const effectiveWorkMode: "DISCUSS" | "PLAN" | "EXECUTE" =
|
|
983
|
+
identity.resumed && !workModeExplicit ? (persistedWorkMode ?? "EXECUTE") : workMode
|
|
984
|
+
// P0.2 (Q4): tolak startup (fail-closed) bila `--verify` digabung dengan
|
|
985
|
+
// WorkMode DISCUSS atau PLAN (baik dari flag/env maupun pulihan `--resume`).
|
|
986
|
+
if (verify && effectiveWorkMode !== "EXECUTE") {
|
|
987
|
+
releaseSessionWriter(sessionId, writerToken, cwd)
|
|
988
|
+
throw new VerifyWorkModeConflictError(effectiveWorkMode)
|
|
989
|
+
}
|
|
839
990
|
// P2.6 — kubur residu crash: RUNNING tanpa holder hidup (admission di atas
|
|
840
991
|
// membuktikan tak ada penulis hidup) → INTERRUPTED/UNKNOWN. BUKAN
|
|
841
992
|
// auto-continue/replay; tanpa ini satu crash mengganjal RUNNING unik
|
|
@@ -1069,9 +1220,12 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
1069
1220
|
cfg,
|
|
1070
1221
|
prompt,
|
|
1071
1222
|
cwd,
|
|
1072
|
-
// RAG retrieval tak boleh menulis access_count di mode tanpa-mutasi
|
|
1073
|
-
//
|
|
1074
|
-
trackAccess:
|
|
1223
|
+
// RAG retrieval tak boleh menulis access_count di mode tanpa-mutasi
|
|
1224
|
+
// (PermissionMode readonly/plan maupun WorkMode DISCUSS/PLAN).
|
|
1225
|
+
trackAccess:
|
|
1226
|
+
(permissionMode as string) !== "readonly" &&
|
|
1227
|
+
permissionMode !== "plan" &&
|
|
1228
|
+
effectiveWorkMode === "EXECUTE",
|
|
1075
1229
|
}),
|
|
1076
1230
|
)
|
|
1077
1231
|
|
|
@@ -1106,6 +1260,18 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
1106
1260
|
// kanonik — jadi persist harus menyusun ulang: baseline ++ ekor baru.
|
|
1107
1261
|
let contextCanonicalBaseline: readonly unknown[] | undefined
|
|
1108
1262
|
if (identity.resumed) {
|
|
1263
|
+
// P0.2 (Q5 / Invariant #6) — transparansi resume: WorkMode dipulihkan dari
|
|
1264
|
+
// metadata sesi bila operator tidak memberi sinyal eksplisit (NULL legacy
|
|
1265
|
+
// kembali ke default EXECUTE). Satu baris stderr human-facing memastikan
|
|
1266
|
+
// otoritas sesi hasil resume selalu terlihat eksplisit.
|
|
1267
|
+
const resumeNotice = !workModeExplicit
|
|
1268
|
+
? persistedWorkMode !== undefined
|
|
1269
|
+
? `[resume] WorkMode ${effectiveWorkMode} restored from session; pass --work-mode DISCUSS|PLAN|EXECUTE to override\n`
|
|
1270
|
+
: `[resume] WorkMode default EXECUTE (legacy session without saved workMode); pass --work-mode DISCUSS|PLAN to change\n`
|
|
1271
|
+
: persistedWorkMode !== undefined && persistedWorkMode !== effectiveWorkMode
|
|
1272
|
+
? `[resume] WorkMode ${effectiveWorkMode} (overriding saved ${persistedWorkMode})\n`
|
|
1273
|
+
: ""
|
|
1274
|
+
if (resumeNotice) process.stderr.write(resumeNotice)
|
|
1109
1275
|
// P2.4: aktivasi default Thread SEBELUM seed kernel — backfill aditif
|
|
1110
1276
|
// berpagar (konten/seq tak tersentuh). Basi di sini = gagal loud
|
|
1111
1277
|
// (dunia bergerak pasca-admission); warn-swallow di bawah tak berlaku.
|
|
@@ -1463,6 +1629,8 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
1463
1629
|
}
|
|
1464
1630
|
: {}),
|
|
1465
1631
|
...(a.parentToolCallId ? { parentToolCallId: a.parentToolCallId } : {}),
|
|
1632
|
+
...(a.childSessionId ? { childSessionId: a.childSessionId } : {}),
|
|
1633
|
+
...(a.runId ? { runId: a.runId } : {}),
|
|
1466
1634
|
...(a.supersedes ? { supersedes: a.supersedes } : {}),
|
|
1467
1635
|
...(a.expandRef
|
|
1468
1636
|
? { expandRef: { toolCallId: a.expandRef.toolCallId, idx: a.expandRef.idx } }
|
|
@@ -1509,6 +1677,11 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
1509
1677
|
text: entry.text,
|
|
1510
1678
|
...(entry.reason ? { reason: entry.reason } : {}),
|
|
1511
1679
|
severity: entry.severity,
|
|
1680
|
+
...(entry.taskId ? { taskId: entry.taskId } : {}),
|
|
1681
|
+
...(entry.taskStatus ? { taskStatus: entry.taskStatus } : {}),
|
|
1682
|
+
...(entry.parentId ? { parentId: entry.parentId } : {}),
|
|
1683
|
+
...(entry.dependsOn?.length ? { dependsOn: [...entry.dependsOn] } : {}),
|
|
1684
|
+
...(entry.revision !== undefined ? { revision: entry.revision } : {}),
|
|
1512
1685
|
}))
|
|
1513
1686
|
const plans: UiPresentationPlan[] = [...shadowState.plans.values()].map((entry) => ({
|
|
1514
1687
|
planId: entry.planId,
|
|
@@ -1602,6 +1775,9 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
1602
1775
|
inputTokens: u.inputTokens,
|
|
1603
1776
|
outputTokens: u.outputTokens,
|
|
1604
1777
|
totalTokens: u.totalTokens,
|
|
1778
|
+
// P1.4: atribusi biaya compaction memakai model yang benar-benar
|
|
1779
|
+
// dipakai (deepseek-chat), bukan model utama sesi.
|
|
1780
|
+
model: "deepseek-chat",
|
|
1605
1781
|
},
|
|
1606
1782
|
})
|
|
1607
1783
|
} catch {}
|
|
@@ -1612,6 +1788,7 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
1612
1788
|
sessionTools,
|
|
1613
1789
|
evidenceMode,
|
|
1614
1790
|
setWorkMode: setToolWorkMode,
|
|
1791
|
+
setPermissionMode: setToolPermissionMode,
|
|
1615
1792
|
} = await startupPhase("tool-layer", () =>
|
|
1616
1793
|
setupToolLayer(
|
|
1617
1794
|
cfg,
|
|
@@ -1625,8 +1802,10 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
1625
1802
|
// F-03 (P5 §C2): background bash job diikat ke sid kanonik sesi ini —
|
|
1626
1803
|
// instance yang diikat sid tidak pernah dipasok lewat argumen tool.
|
|
1627
1804
|
sessionId,
|
|
1628
|
-
// P12 S2.2: ceiling WorkMode
|
|
1629
|
-
|
|
1805
|
+
// P12 S2.2 + P0.2: ceiling WorkMode efektif (termasuk hasil pulihan resume).
|
|
1806
|
+
effectiveWorkMode,
|
|
1807
|
+
// P2.3: pin skema MCP per-workspace.
|
|
1808
|
+
cwd,
|
|
1630
1809
|
),
|
|
1631
1810
|
)
|
|
1632
1811
|
|
|
@@ -1663,7 +1842,7 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
1663
1842
|
// saat itu — bukan snapshot lama. Tanpa ini ToolContext.permissionMode
|
|
1664
1843
|
// (hanya PM, bukan WorkMode) membuat delegate_task melahirkan anak tanpa
|
|
1665
1844
|
// ceiling WorkMode.
|
|
1666
|
-
setSubAgentWorkMode(() => workModeControl?.getWorkMode() ??
|
|
1845
|
+
setSubAgentWorkMode(() => workModeControl?.getWorkMode() ?? effectiveWorkMode)
|
|
1667
1846
|
|
|
1668
1847
|
let permissions: PermissionControl | undefined
|
|
1669
1848
|
let noProgressDetector: NoProgressDetector | null = null
|
|
@@ -1687,11 +1866,8 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
1687
1866
|
cwd,
|
|
1688
1867
|
permissionMode,
|
|
1689
1868
|
allowLocalConfig,
|
|
1690
|
-
// P12 S2.2 — WorkMode efektif sesi ini (
|
|
1691
|
-
|
|
1692
|
-
// yang memakai permissionHandler terinjeksi (6S/autonomous) akan
|
|
1693
|
-
// di-reject oleh fail-closed di sana (tak pernah melewati ceiling).
|
|
1694
|
-
workMode,
|
|
1869
|
+
// P12 S2.2 + P0.2 — WorkMode efektif sesi ini (termasuk pulihan resume).
|
|
1870
|
+
workMode: effectiveWorkMode,
|
|
1695
1871
|
// [Fase 4 / LOOP-13, LOOP-INV-16] Header operasional deterministik di
|
|
1696
1872
|
// system prompt = buffer kedua yang selalu dikirim dan tak pernah
|
|
1697
1873
|
// dikompaksi; tidak pernah masuk histori kanonik. Absen = perilaku lama.
|
|
@@ -1713,19 +1889,27 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
1713
1889
|
if (journalHandle !== null) await journalHandle.preflightIntent(call)
|
|
1714
1890
|
},
|
|
1715
1891
|
onPermissions: (ctl) => {
|
|
1716
|
-
permissions =
|
|
1892
|
+
permissions = {
|
|
1893
|
+
setMode: (m) => {
|
|
1894
|
+
ctl.setMode(m)
|
|
1895
|
+
setToolPermissionMode?.(m)
|
|
1896
|
+
},
|
|
1897
|
+
getMode: () => ctl.getMode(),
|
|
1898
|
+
}
|
|
1717
1899
|
},
|
|
1718
1900
|
// P12 S2.2 Slice 5 — handle kontrol WorkMode runtime. Setelah sesi
|
|
1719
1901
|
// dibangun, handle ini di-warisi ke sub-agent/hooks/footer sehingga
|
|
1720
1902
|
// transisi operator berlaku pada sesi yang sedang berjalan.
|
|
1721
1903
|
onWorkMode: (ctl) => {
|
|
1722
|
-
// P12 S2.2 Slice 5 - SATU sumber state: handler WorkMode (ctl).
|
|
1723
|
-
// Visibilitas tool
|
|
1724
|
-
// terpisah) supaya ceiling dan daftar tool tak bisa berbeda.
|
|
1904
|
+
// P12 S2.2 Slice 5 + P0.2 - SATU sumber state: handler WorkMode (ctl).
|
|
1905
|
+
// Visibilitas tool + metadata sesi durable diturunkan dari state sama.
|
|
1725
1906
|
workModeControl = {
|
|
1726
1907
|
setWorkMode: (m) => {
|
|
1727
1908
|
ctl.setWorkMode(m)
|
|
1728
1909
|
setToolWorkMode?.(m)
|
|
1910
|
+
try {
|
|
1911
|
+
saveSessionWorkMode(sessionId, m, cwd, { expectedEpoch })
|
|
1912
|
+
} catch {}
|
|
1729
1913
|
},
|
|
1730
1914
|
getWorkMode: () => ctl.getWorkMode(),
|
|
1731
1915
|
}
|
|
@@ -1772,6 +1956,55 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
1772
1956
|
taskIdentityProvider: createTaskIdentityResolver(cwd ?? process.cwd()),
|
|
1773
1957
|
...(shadowState ? { initialSeq: shadowState.seq, initialTurn, initialTurnStartTs } : {}),
|
|
1774
1958
|
})
|
|
1959
|
+
// P1.6: lifecycle task kanonik dipancarkan pada transisi nyata (bukan hanya
|
|
1960
|
+
// setelah verify-settle). Dedupe per (id,status,revision) agar tidak
|
|
1961
|
+
// double-report saat verify menyelesaikan task yang sama.
|
|
1962
|
+
const taskStatusSeen = new Map<string, string>()
|
|
1963
|
+
const emitTaskStatuses = (): void => {
|
|
1964
|
+
try {
|
|
1965
|
+
// Sinkron: one-shot/exec dapat keluar tepat setelah turn selesai; dynamic
|
|
1966
|
+
// import async bisa tidak sempat berjalan sebelum proses berhenti.
|
|
1967
|
+
const tasks = new TaskStore(cwd ?? process.cwd()).listTasks(sessionId)
|
|
1968
|
+
for (const task of tasks) {
|
|
1969
|
+
const key = `${task.status}:${task.revision}`
|
|
1970
|
+
if (taskStatusSeen.get(task.id) === key) continue
|
|
1971
|
+
taskStatusSeen.set(task.id, key)
|
|
1972
|
+
presentation?.noteTaskStatus({
|
|
1973
|
+
taskId: task.id,
|
|
1974
|
+
status: task.status,
|
|
1975
|
+
...(task.parentId ? { parentId: task.parentId } : {}),
|
|
1976
|
+
...(task.dependsOn?.length ? { dependsOn: [...task.dependsOn] } : {}),
|
|
1977
|
+
revision: task.revision,
|
|
1978
|
+
verification: task.verification
|
|
1979
|
+
? { verdict: task.verification.verdict, checkedAt: task.verification.checkedAt }
|
|
1980
|
+
: { verdict: "unverified", checkedAt: "" },
|
|
1981
|
+
turnId: session.state.turnCount,
|
|
1982
|
+
})
|
|
1983
|
+
}
|
|
1984
|
+
} catch {}
|
|
1985
|
+
}
|
|
1986
|
+
session.events.on("execution:completed", (e) => {
|
|
1987
|
+
const call = (e as { execution?: { call?: { name?: unknown } } }).execution?.call
|
|
1988
|
+
if (call?.name === "todo_write") emitTaskStatuses()
|
|
1989
|
+
})
|
|
1990
|
+
// P2.3: transisi AUTHORITATIVE (claim/verify/merge/cancel/fail) diproyeksikan
|
|
1991
|
+
// setelah commit DB oleh sink TaskStore — bukan ditebak dari perubahan teks.
|
|
1992
|
+
setTaskTransitionSink(({ task }) => {
|
|
1993
|
+
const key = `${task.status}:${task.revision}`
|
|
1994
|
+
if (taskStatusSeen.get(task.id) === key) return
|
|
1995
|
+
taskStatusSeen.set(task.id, key)
|
|
1996
|
+
presentation?.noteTaskStatus({
|
|
1997
|
+
taskId: task.id,
|
|
1998
|
+
status: task.status,
|
|
1999
|
+
...(task.parentId ? { parentId: task.parentId } : {}),
|
|
2000
|
+
...(task.dependsOn?.length ? { dependsOn: [...task.dependsOn] } : {}),
|
|
2001
|
+
revision: task.revision,
|
|
2002
|
+
verification: task.verification
|
|
2003
|
+
? { verdict: task.verification.verdict, checkedAt: task.verification.checkedAt }
|
|
2004
|
+
: { verdict: "unverified", checkedAt: "" },
|
|
2005
|
+
turnId: session.state.turnCount,
|
|
2006
|
+
})
|
|
2007
|
+
})
|
|
1775
2008
|
try {
|
|
1776
2009
|
if (!shadowState) shadowState = createInitialState(sessionId)
|
|
1777
2010
|
if (!shadowDiag) shadowDiag = createReducerDiagnostics()
|
|
@@ -2158,7 +2391,11 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
2158
2391
|
exitCode: number
|
|
2159
2392
|
} | null = null
|
|
2160
2393
|
setCompletionEvidence(() => {
|
|
2161
|
-
|
|
2394
|
+
const liveWm = workModeControl?.getWorkMode() ?? effectiveWorkMode
|
|
2395
|
+
const livePm = permissions?.getMode() ?? permissionMode
|
|
2396
|
+
if (!verifyActive || liveWm !== "EXECUTE" || livePm === "readonly" || livePm === "plan") {
|
|
2397
|
+
return { verdict: "unverified" }
|
|
2398
|
+
}
|
|
2162
2399
|
// [Fase 3 / LOOP-INV-12, LOOP-G20] Saat `--verify` aktif tetapi verifier
|
|
2163
2400
|
// belum menghasilkan verdict pertama, tandai `requireVerified: true` agar
|
|
2164
2401
|
// klaim `completed` ditahan di `VERIFYING` (bukan diloloskan fail-open).
|
|
@@ -2260,6 +2497,17 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
2260
2497
|
insufficientEvidence: !effectiveOk && effectiveOutput.trim().length === 0,
|
|
2261
2498
|
baselineContentChanged: false,
|
|
2262
2499
|
})
|
|
2500
|
+
// F-CTRL-1/F-CTRL-2: keputusan consequence terstruktur masuk observability
|
|
2501
|
+
// (bukan hanya stderr). VERIFYING / Tamper Guard kini terlihat lewat
|
|
2502
|
+
// `newEvidenceSinceLastAttempt` + `failureClass`/`nextAction`.
|
|
2503
|
+
presentation?.noteConsequenceDecided({
|
|
2504
|
+
verdict: lastAceDecision.verdict,
|
|
2505
|
+
failureClass: lastAceDecision.failureClass,
|
|
2506
|
+
nextAction: lastAceDecision.nextAction,
|
|
2507
|
+
rationale: lastAceDecision.rationale,
|
|
2508
|
+
newEvidenceSinceLastAttempt: lastAceDecision.newEvidenceSinceLastAttempt,
|
|
2509
|
+
turnId: session.state.turnCount,
|
|
2510
|
+
})
|
|
2263
2511
|
if (lastAceDecision && lastAceDecision.verdict === "BLOCKED") {
|
|
2264
2512
|
process.stderr.write(
|
|
2265
2513
|
c.dim(
|
|
@@ -2292,6 +2540,10 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
2292
2540
|
summary: effectiveOutput.slice(0, 300) || verifyCommand,
|
|
2293
2541
|
integrityOk: integrityOk && !tampered,
|
|
2294
2542
|
})
|
|
2543
|
+
// F-TASK-1/P1.6: status task kanonik (t<n>) + DAG diamati sebagai event,
|
|
2544
|
+
// bukan hanya efek samping TaskStore. Dedupe yang sama dengan jalur
|
|
2545
|
+
// todo_write agar satu transisi tidak dilaporkan dua kali.
|
|
2546
|
+
emitTaskStatuses()
|
|
2295
2547
|
} catch {}
|
|
2296
2548
|
const evidence = parseVerifyTestEvidence(verifyCommand, effectiveOutput)
|
|
2297
2549
|
if (evidence) {
|
|
@@ -2321,25 +2573,44 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
2321
2573
|
// `hooksAllowed` saat session dibuat) supaya transisi WorkMode operator
|
|
2322
2574
|
// berlaku pada sesi yang sedang berjalan.
|
|
2323
2575
|
let hooksSkippedNotice = false
|
|
2576
|
+
let verifySkippedNotice = false
|
|
2324
2577
|
const runHooksGated = async (
|
|
2325
2578
|
phase: "pre" | "post",
|
|
2326
2579
|
ctx: { phase: "pre" | "post"; prompt: string; cwd?: string; result?: unknown },
|
|
2327
2580
|
signal?: AbortSignal,
|
|
2328
2581
|
): Promise<void> => {
|
|
2329
|
-
const liveWorkMode = workModeControl?.getWorkMode() ??
|
|
2330
|
-
|
|
2582
|
+
const liveWorkMode = workModeControl?.getWorkMode() ?? effectiveWorkMode
|
|
2583
|
+
const livePm = permissions?.getMode() ?? permissionMode
|
|
2584
|
+
if (!shouldRunHooks(livePm, liveWorkMode)) {
|
|
2331
2585
|
if (!hooksSkippedNotice) {
|
|
2332
2586
|
hooksSkippedNotice = true
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
)
|
|
2587
|
+
const reasonLabel =
|
|
2588
|
+
liveWorkMode !== "EXECUTE" ? `work-mode ${liveWorkMode}` : `${livePm} mode`
|
|
2589
|
+
process.stderr.write(c.dim(`[hooks] skipped in ${reasonLabel} (read-only contract)\n`))
|
|
2336
2590
|
}
|
|
2337
2591
|
return
|
|
2338
2592
|
}
|
|
2339
2593
|
await runRunHooks(phase, ctx, signal)
|
|
2340
2594
|
}
|
|
2341
2595
|
|
|
2596
|
+
/**
|
|
2597
|
+
* Guard single-session: tolak run kedua dari sesi lain sebelum menyentuh
|
|
2598
|
+
* provider/jurnal. Release di finally — termasuk saat turn melempar.
|
|
2599
|
+
*/
|
|
2342
2600
|
async function runPromptWithVerify(p: string, signal?: AbortSignal): Promise<void> {
|
|
2601
|
+
if (activeAgentSessionId !== null && activeAgentSessionId !== sessionId) {
|
|
2602
|
+
throw new ConcurrentAgentSessionError(activeAgentSessionId, sessionId)
|
|
2603
|
+
}
|
|
2604
|
+
const previous = activeAgentSessionId
|
|
2605
|
+
activeAgentSessionId = sessionId
|
|
2606
|
+
try {
|
|
2607
|
+
return await runPromptWithVerifyImpl(p, signal)
|
|
2608
|
+
} finally {
|
|
2609
|
+
if (activeAgentSessionId === sessionId) activeAgentSessionId = previous ?? null
|
|
2610
|
+
}
|
|
2611
|
+
}
|
|
2612
|
+
|
|
2613
|
+
async function runPromptWithVerifyImpl(p: string, signal?: AbortSignal): Promise<void> {
|
|
2343
2614
|
// [Fase 7 / Live #3] Root wall-clock: kalau timeout CLI sudah lewat saat
|
|
2344
2615
|
// turn mau mulai (setup/retry memakan seluruh budget), tolak langsung
|
|
2345
2616
|
// dengan alasan jelas — jangan biarkan turn baru melebihi deadline total.
|
|
@@ -2435,6 +2706,20 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
2435
2706
|
getTokens: () => usage.getSession().totalTokens,
|
|
2436
2707
|
getTurns: () => session.state.turnCount,
|
|
2437
2708
|
onOver: (st, cost) => {
|
|
2709
|
+
// F-CTX-2: pemotongan mi-stream yang durable → masuk transkrip.
|
|
2710
|
+
presentation?.noteContextCutoff({
|
|
2711
|
+
reason:
|
|
2712
|
+
st === "max-turns"
|
|
2713
|
+
? `max turns (${effectiveMaxTurns}) reached`
|
|
2714
|
+
: st === "over" && cost != null && budget != null
|
|
2715
|
+
? `budget exceeded: ${formatUsd(cost)} > ${formatUsd(budget)}`
|
|
2716
|
+
: "budget exceeded: cost unknown (model without pricing)",
|
|
2717
|
+
// Occupancy konteks (bukan spend sesi) — budget cutoff adalah
|
|
2718
|
+
// peristiwa berbeda; field tetap konsisten dengan meter context.
|
|
2719
|
+
usedTokens: session.contextTokens,
|
|
2720
|
+
windowTokens: contextWindowTokens ?? 0,
|
|
2721
|
+
turnId: session.state.turnCount,
|
|
2722
|
+
})
|
|
2438
2723
|
process.stderr.write(
|
|
2439
2724
|
st === "max-turns"
|
|
2440
2725
|
? `[budget] max turns (${effectiveMaxTurns}) reached - stopping turn.\n`
|
|
@@ -2465,6 +2750,26 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
2465
2750
|
getInputTokens: () => usage.get().inputTokens,
|
|
2466
2751
|
getOutputTokens: () => usage.get().outputTokens,
|
|
2467
2752
|
onOver: (allowed, actual) => {
|
|
2753
|
+
const windowTokens = contextWindowTokens ?? 0
|
|
2754
|
+
// F-CTX-1 + P1.4: meter occupancy konteks (bukan output cutoff).
|
|
2755
|
+
// `actual` adalah token output yang memicu cutoff; occupancy adalah
|
|
2756
|
+
// ukuran konteks saat ini dari kernel. Dua angka ini tidak boleh
|
|
2757
|
+
// saling menggantikan.
|
|
2758
|
+
const occupancy = session.contextTokens
|
|
2759
|
+
presentation?.noteContextWindow({
|
|
2760
|
+
usedTokens: occupancy,
|
|
2761
|
+
windowTokens,
|
|
2762
|
+
percent: windowTokens > 0 ? Math.min(100, (occupancy / windowTokens) * 100) : undefined,
|
|
2763
|
+
costUsd: usage.getSession().cost,
|
|
2764
|
+
turnId: session.state.turnCount,
|
|
2765
|
+
})
|
|
2766
|
+
// F-CTX-2: pemotongan mi-stream yang durable → masuk transkrip.
|
|
2767
|
+
presentation?.noteContextCutoff({
|
|
2768
|
+
reason: `context window exceeded: output ${actual} > allowance ${allowed} (window ${windowTokens})`,
|
|
2769
|
+
usedTokens: actual,
|
|
2770
|
+
windowTokens,
|
|
2771
|
+
turnId: session.state.turnCount,
|
|
2772
|
+
})
|
|
2468
2773
|
process.stderr.write(
|
|
2469
2774
|
`[context] stream truncated: context-window limit reached (output ${actual} > allowance ${allowed} of window ${contextWindowTokens})\n`,
|
|
2470
2775
|
)
|
|
@@ -2516,7 +2821,19 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
2516
2821
|
turnStatus?.endTurn()
|
|
2517
2822
|
}
|
|
2518
2823
|
}
|
|
2519
|
-
|
|
2824
|
+
const liveWm = workModeControl?.getWorkMode() ?? effectiveWorkMode
|
|
2825
|
+
const livePm = permissions?.getMode() ?? permissionMode
|
|
2826
|
+
const verifyRunnableNow =
|
|
2827
|
+
verifyActive && liveWm === "EXECUTE" && livePm !== "readonly" && livePm !== "plan"
|
|
2828
|
+
if (!verifyRunnableNow) {
|
|
2829
|
+
// P0.2 (Q4 / Invariant #8): bila operator menurunkan WorkMode ke DISCUSS/
|
|
2830
|
+
// PLAN (atau PM ke readonly/plan) di tengah sesi TUI, lewati baseline
|
|
2831
|
+
// shell verify, self-heal, dan auto-memory write secara otomatis.
|
|
2832
|
+
if (verifyActive && !verifySkippedNotice) {
|
|
2833
|
+
verifySkippedNotice = true
|
|
2834
|
+
const modeLabel = liveWm !== "EXECUTE" ? `work-mode ${liveWm}` : `${livePm} mode`
|
|
2835
|
+
warnLine(`verify skipped in ${modeLabel} (read-only contract)`)
|
|
2836
|
+
}
|
|
2520
2837
|
await runOnce(p, signal)
|
|
2521
2838
|
await runHooksGated(
|
|
2522
2839
|
"post",
|
|
@@ -2638,6 +2955,9 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
2638
2955
|
quiet: enterRepl === true || machineOutput,
|
|
2639
2956
|
getSnapshot: getPresentationSnapshot,
|
|
2640
2957
|
onPresentationEvent,
|
|
2958
|
+
// [Area A · PROMPT 06] State sesi — buffer /copy & error tertunda
|
|
2959
|
+
// bertahan lintas re-attach per turn dan tak bocor ke sesi lain.
|
|
2960
|
+
uiState,
|
|
2641
2961
|
policy: {
|
|
2642
2962
|
describeActivity,
|
|
2643
2963
|
matchTurn: matchTurnBySummary,
|
|
@@ -2714,6 +3034,7 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
2714
3034
|
try {
|
|
2715
3035
|
await saveSession(sessionId, cwd, undefined, durableHistory, usageData, {
|
|
2716
3036
|
expectedEpoch,
|
|
3037
|
+
workMode: workModeControl?.getWorkMode() ?? effectiveWorkMode,
|
|
2717
3038
|
...(currentRunId ? { runId: currentRunId } : {}),
|
|
2718
3039
|
})
|
|
2719
3040
|
} catch (e) {
|
|
@@ -3141,6 +3462,8 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
3141
3462
|
} catch {}
|
|
3142
3463
|
presentation = null
|
|
3143
3464
|
setAskApprovalHook(undefined)
|
|
3465
|
+
// P2.3: lepas sink transisi task milik sesi ini (single-session).
|
|
3466
|
+
setTaskTransitionSink(null)
|
|
3144
3467
|
// background job harus mati bersama CLI — jangan tinggalkan proses yatim
|
|
3145
3468
|
killAllBackgroundJobs()
|
|
3146
3469
|
await mcpCloseAll()
|
|
@@ -3213,7 +3536,9 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
3213
3536
|
effectiveInitialModel,
|
|
3214
3537
|
effectiveTimeoutMs,
|
|
3215
3538
|
permissionMode,
|
|
3216
|
-
workMode
|
|
3539
|
+
get workMode() {
|
|
3540
|
+
return workModeControl?.getWorkMode() ?? effectiveWorkMode
|
|
3541
|
+
},
|
|
3217
3542
|
workModeControl,
|
|
3218
3543
|
allowLocalConfig: allowLocalConfig === true,
|
|
3219
3544
|
sessionTools,
|
|
@@ -3221,10 +3546,26 @@ export async function createCliSession(opts: CliSessionOptions): Promise<CliSess
|
|
|
3221
3546
|
usage,
|
|
3222
3547
|
budget,
|
|
3223
3548
|
budgetStrict,
|
|
3549
|
+
contextWindowTokens,
|
|
3224
3550
|
memoryHits,
|
|
3225
3551
|
detachSimple: () => detachUI(),
|
|
3552
|
+
// [Area A · PROMPT 06] State UI sesi ini (lihat interface CliSession).
|
|
3553
|
+
uiState,
|
|
3226
3554
|
persistCurrent,
|
|
3227
3555
|
runPromptWithVerify,
|
|
3556
|
+
runState: () => ({
|
|
3557
|
+
runId: currentRunId,
|
|
3558
|
+
status:
|
|
3559
|
+
currentRunId === null
|
|
3560
|
+
? null
|
|
3561
|
+
: lastTurnOutcome === "completed"
|
|
3562
|
+
? "COMPLETED"
|
|
3563
|
+
: lastTurnOutcome === "failed"
|
|
3564
|
+
? "FAILED"
|
|
3565
|
+
: lastTurnOutcome === "interrupted"
|
|
3566
|
+
? "INTERRUPTED"
|
|
3567
|
+
: "RUNNING",
|
|
3568
|
+
}),
|
|
3228
3569
|
// P11.1 — baca TERAKHIR-menang: self-heal menimpa lastVerify tiap
|
|
3229
3570
|
// siklus, jadi yang terbaca di sini selalu hasil final. Salin nilai
|
|
3230
3571
|
// (bukan referensi) agar summary mesin tak bisa memutasi state sesi.
|