minicode-ai 0.14.6 → 0.20.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/README.md +6 -4
- package/cli/args.ts +20 -8
- package/cli/commands/exec.ts +17 -14
- package/cli/commands/openwork.ts +1 -1
- package/cli/commands.ts +39 -23
- package/cli/index.ts +29 -7
- package/cli/model-manager.ts +1 -1
- package/cli/router.ts +22 -9
- package/cli/setup.ts +77 -35
- package/cli/tui.ts +179 -25
- package/docs/CONTROL-PLANE-MAP.md +7 -5
- package/docs/OUTPUT_EVENT_MODEL.md +4 -3
- package/docs/OUTPUT_PROTOCOL_SPEC.md +1 -1
- package/docs/OUTPUT_RENDERING_SPEC.md +16 -4
- package/docs/OUTPUT_UX_RULES.md +38 -32
- package/docs/P14_OPEN_WORK.md +290 -0
- package/docs/README.md +1 -1
- package/docs/SUMMARY.md +36 -22
- package/docs/TERMINAL_CONTRACT.md +89 -17
- package/docs/UI_RENDER_PIPELINE.md +47 -8
- package/docs/agents.md +1 -1
- package/docs/architecture.md +10 -8
- package/docs/autonomous-scheduler.md +142 -0
- package/docs/choosing-mode.md +4 -2
- package/docs/cli.md +11 -9
- package/docs/concepts.md +5 -5
- package/docs/config-providers.md +3 -3
- package/docs/config.md +1 -1
- package/docs/contributing.md +7 -9
- package/docs/environment.md +8 -5
- package/docs/getting-started.md +5 -5
- package/docs/mcp-lsp.md +2 -2
- package/docs/memory-sessions.md +3 -3
- package/docs/policy-sandbox.md +7 -4
- package/docs/pricing-budget.md +3 -3
- package/docs/quickstart.md +1 -1
- package/docs/repl.md +11 -8
- package/docs/security-model.md +4 -2
- package/docs/security.md +9 -8
- package/docs/skills.md +2 -2
- package/docs/terminal.md +10 -2
- package/docs/tools.md +4 -4
- package/docs/troubleshooting.md +3 -3
- package/docs/verify-benchmark.md +0 -3
- package/package.json +9 -18
- package/scripts/vendor-overlays/minicode-context.patch +1 -1
- package/src/app/mentions.ts +1 -1
- package/src/app/rag-layer.ts +11 -2
- package/src/app/session.ts +128 -10
- package/src/constants.ts +32 -1
- package/src/daemon/client.ts +11 -6
- package/src/daemon/control.ts +2 -9
- package/src/daemon/resource.ts +5 -4
- package/src/hooks/run.ts +5 -6
- package/src/lib/keystore.ts +11 -9
- package/src/lib/net.ts +8 -3
- package/src/lib/safe-open.ts +29 -5
- package/src/lib/trusted-exec.ts +4 -1
- package/src/lsp/client.ts +9 -10
- package/src/mcp/http-transport.ts +1 -1
- package/src/mcp/server.ts +17 -7
- package/src/memory/files.ts +2 -1
- package/src/memory/vector.ts +25 -16
- package/src/policy/bash-guard.ts +58 -16
- package/src/policy/bpe.ts +110 -0
- package/src/policy/compaction.ts +139 -22
- package/src/policy/consequence-engine.ts +3 -3
- package/src/policy/context-window.ts +43 -1
- package/src/policy/context.ts +50 -12
- package/src/policy/jail.ts +48 -3
- package/src/policy/no-progress.ts +15 -8
- package/src/policy/permission.ts +243 -5
- package/src/policy/tokenizer-registry.ts +104 -0
- package/src/policy/usage.ts +20 -13
- package/src/policy/verifier.ts +7 -4
- package/src/policy/work-mode.ts +9 -5
- package/src/presentation/adapter.ts +8 -4
- package/src/presentation/events.ts +2 -2
- package/src/presentation/label.ts +3 -3
- package/src/presentation/model.ts +4 -0
- package/src/presentation/projection.ts +10 -2
- package/src/presentation/store.ts +2 -2
- package/src/providers/anthropic.ts +13 -3
- package/src/providers/responses.ts +16 -6
- package/src/runtime/capability.ts +22 -4
- package/src/runtime/child-execution.ts +1 -1
- package/src/runtime/composition.ts +5 -5
- package/src/runtime/execution-journal.ts +13 -7
- package/src/runtime/execution-registry.ts +1 -1
- package/src/runtime/production-execution.ts +7 -6
- package/src/runtime/production-runtime.ts +2 -2
- package/src/runtime/runtime-capabilities.ts +1 -1
- package/src/runtime/runtime-status-facts.ts +1 -1
- package/src/runtime/runtime-task-admission.ts +2 -2
- package/src/sandbox/os.ts +4 -3
- package/src/session/checkpoint.ts +29 -4
- package/src/session/context-assembly.ts +8 -1
- package/src/session/context-identity.ts +2 -2
- package/src/session/context-projection.ts +36 -11
- package/src/session/persistence.ts +22 -11
- package/src/task/autonomous-context.ts +2 -3
- package/src/task/autonomous-policy.ts +3 -3
- package/src/task/model.ts +2 -2
- package/src/task/production-scheduler.ts +2 -2
- package/src/task/scheduler-observability.ts +1 -0
- package/src/task/scheduler.ts +3 -2
- package/src/task/scheduling-policy.ts +2 -1
- package/src/task/trigger.ts +5 -5
- package/src/tools/git.ts +22 -4
- package/src/tools/lsp.ts +10 -8
- package/src/tools/read_image.ts +2 -1
- package/src/tools/task.ts +1 -1
- package/src/tools/web_fetch.ts +6 -2
- package/src/tools/web_search.ts +2 -1
- package/src/ui/assistant/simple.ts +42 -33
- package/src/ui/contract.ts +4 -0
- package/src/ui/footer.ts +63 -12
- package/src/ui/i18n/en.ts +14 -2
- package/src/ui/i18n/id.ts +14 -2
- package/src/ui/input/prompt-engine.ts +36 -10
- package/src/ui/render/cells.ts +320 -0
- package/src/ui/render/composer-wrap.ts +73 -0
- package/src/ui/render/detail.ts +2 -2
- package/src/ui/render/diff.ts +14 -5
- package/src/ui/render/highlight.ts +4 -4
- package/src/ui/render/ledger.ts +47 -0
- package/src/ui/render/markdown.ts +12 -5
- package/src/ui/render/session-summary.ts +50 -0
- package/src/ui/render/table-grid.ts +134 -6
- package/src/ui/render/theme.ts +49 -4
- package/src/ui/render/width.ts +91 -4
- package/src/ui/render/wrap.ts +5 -3
- package/src/ui/runtime/screen.ts +100 -22
- package/src/ui/runtime/statusline.ts +26 -0
- package/src/ui/screens/model-manager.ts +1 -1
- package/src/ui/session-state.ts +27 -1
- package/src/ui/tui/app.ts +336 -65
- package/src/ui/tui/transcript.ts +335 -104
- package/vendor/minicore/VENDOR.md +16 -12
- package/vendor/minicore/src/core/events.ts +1 -0
- package/vendor/minicore/src/core/loop.ts +11 -1
- package/vendor/minicore/src/core/session.ts +39 -0
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// yang adil untuk sesi panjang. Reducer TIDAK PERNAH membaca store untuk
|
|
6
6
|
// keputusan (I-A04) — store hanya dilayani expand/proyeksi.
|
|
7
7
|
//
|
|
8
|
-
//
|
|
8
|
+
// Besar angka = `src/ui/session-state.ts` (200K per-entry / 500K total) — dipertahankan
|
|
9
9
|
// sebagai awal, bukan angka magis baru. Evict = FIFO tertua + tandai dead
|
|
10
10
|
// (bukan hapus diam-diam): proyeksi menampilkan penanda retensi, bukan string
|
|
11
11
|
// kosong yang menyesatkan.
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
//
|
|
17
17
|
// Pola potong (surrogate-safe + splitTrailingEscape) DIUlang di sini (bukan
|
|
18
18
|
// impor src/ui — boundary src/** non-ui dilarang impor src/ui). Pola sama
|
|
19
|
-
// dengan
|
|
19
|
+
// dengan `src/ui/session-state.ts`; trigonometri escape disederhanakan untuk kasus
|
|
20
20
|
// tail yang mungkin terpotong.
|
|
21
21
|
|
|
22
22
|
import type { ContentRef } from "./events.ts"
|
|
@@ -145,6 +145,11 @@ export function createAnthropicProvider(config: AnthropicConfig): ModelProvider
|
|
|
145
145
|
{ id: string; name: string; args: string; argsBytes: number }
|
|
146
146
|
>()
|
|
147
147
|
let pendingToolArgBytes = 0
|
|
148
|
+
// Pertahankan input/cache tokens dari message_start agar message_delta
|
|
149
|
+
// (yang sering hanya mengirim output_tokens) tidak menimpa snapshot jadi 0.
|
|
150
|
+
let startInputTokens: number | undefined
|
|
151
|
+
let startCacheReadTokens: number | undefined
|
|
152
|
+
let startCacheWriteTokens: number | undefined
|
|
148
153
|
|
|
149
154
|
// Anthropic SSE: event: ...\ndata: {...}
|
|
150
155
|
let currentEvent = ""
|
|
@@ -183,10 +188,10 @@ export function createAnthropicProvider(config: AnthropicConfig): ModelProvider
|
|
|
183
188
|
type: "extension",
|
|
184
189
|
kind: "usage",
|
|
185
190
|
data: {
|
|
186
|
-
inputTokens: usage.input_tokens,
|
|
191
|
+
inputTokens: usage.input_tokens ?? startInputTokens,
|
|
187
192
|
outputTokens: usage.output_tokens,
|
|
188
|
-
cacheReadTokens: usage.cache_read_input_tokens,
|
|
189
|
-
cacheWriteTokens: usage.cache_creation_input_tokens,
|
|
193
|
+
cacheReadTokens: usage.cache_read_input_tokens ?? startCacheReadTokens,
|
|
194
|
+
cacheWriteTokens: usage.cache_creation_input_tokens ?? startCacheWriteTokens,
|
|
190
195
|
cacheIncluded: true,
|
|
191
196
|
},
|
|
192
197
|
}
|
|
@@ -194,6 +199,11 @@ export function createAnthropicProvider(config: AnthropicConfig): ModelProvider
|
|
|
194
199
|
} else if (evType === "message_start") {
|
|
195
200
|
const usage = raw.message?.usage
|
|
196
201
|
if (usage) {
|
|
202
|
+
if (typeof usage.input_tokens === "number") startInputTokens = usage.input_tokens
|
|
203
|
+
if (typeof usage.cache_read_input_tokens === "number")
|
|
204
|
+
startCacheReadTokens = usage.cache_read_input_tokens
|
|
205
|
+
if (typeof usage.cache_creation_input_tokens === "number")
|
|
206
|
+
startCacheWriteTokens = usage.cache_creation_input_tokens
|
|
197
207
|
yield {
|
|
198
208
|
type: "extension",
|
|
199
209
|
kind: "usage",
|
|
@@ -137,6 +137,9 @@ export function createResponsesProvider(config: ResponsesConfig): ModelProvider
|
|
|
137
137
|
throw new ProviderError("network", e instanceof Error ? e.message : String(e))
|
|
138
138
|
}
|
|
139
139
|
if (!res.ok) {
|
|
140
|
+
// Bila request gagal saat membawa previous_response_id, hapus ID tersebut
|
|
141
|
+
// agar turn berikutnya tidak macet permanen pada ID yang kedaluwarsa/ditolak.
|
|
142
|
+
if (prev) lastResponseByModel.delete(modelKey)
|
|
140
143
|
const txt = await readProviderErrorBody(res).catch(() => "")
|
|
141
144
|
const retryAfter = res.headers.get("retry-after")
|
|
142
145
|
if (res.status === 429) {
|
|
@@ -375,12 +378,19 @@ export function createResponsesProvider(config: ResponsesConfig): ModelProvider
|
|
|
375
378
|
typeof data.arguments === "string" ? data.arguments : "",
|
|
376
379
|
)
|
|
377
380
|
}
|
|
378
|
-
const
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
381
|
+
const isToolEvent =
|
|
382
|
+
dtype === "response.output_item.added" ||
|
|
383
|
+
dtype === "response.function_call_arguments.delta" ||
|
|
384
|
+
dtype === "response.function_call_arguments.done" ||
|
|
385
|
+
dtype === "response.output_item.done" ||
|
|
386
|
+
dtype === "function_call"
|
|
387
|
+
const text =
|
|
388
|
+
reasoningText || isToolEvent
|
|
389
|
+
? undefined
|
|
390
|
+
: ((typeof rawDelta === "string" ? rawDelta : undefined) ??
|
|
391
|
+
drec.text ??
|
|
392
|
+
drec.content ??
|
|
393
|
+
drec.output_text)
|
|
384
394
|
if (typeof text === "string" && text) yield { type: "text", text }
|
|
385
395
|
const finish =
|
|
386
396
|
(data as { finish_reason?: string }).finish_reason ??
|
|
@@ -119,8 +119,14 @@ export function normalizeScopePath(path: string): string {
|
|
|
119
119
|
if (path.includes("\0")) throw new Error("capability: NUL byte in path")
|
|
120
120
|
const isWin = process.platform === "win32"
|
|
121
121
|
let p = path.replace(/\\/g, "/")
|
|
122
|
+
// Pertahankan drive prefix Windows (mis. "C:") agar segmen ".." tidak mem-pop
|
|
123
|
+
// huruf drive keluar dari parts dan menghasilkan path relatif palsu.
|
|
124
|
+
const driveMatch = /^([A-Za-z]:)(?:\/|$)/.exec(p)
|
|
125
|
+
const drivePrefix = driveMatch ? driveMatch[1]! : ""
|
|
126
|
+
const rest = drivePrefix ? p.slice(drivePrefix.length) : p
|
|
127
|
+
const isAbs = drivePrefix !== "" || p.startsWith("/")
|
|
122
128
|
const parts: string[] = []
|
|
123
|
-
for (const seg of
|
|
129
|
+
for (const seg of rest.split("/")) {
|
|
124
130
|
if (seg === "" || seg === ".") continue
|
|
125
131
|
if (seg === "..") {
|
|
126
132
|
if (parts.length > 0 && parts[parts.length - 1] !== "..") parts.pop()
|
|
@@ -129,8 +135,14 @@ export function normalizeScopePath(path: string): string {
|
|
|
129
135
|
}
|
|
130
136
|
parts.push(seg)
|
|
131
137
|
}
|
|
132
|
-
|
|
133
|
-
if (
|
|
138
|
+
const joined = parts.join("/")
|
|
139
|
+
if (drivePrefix) {
|
|
140
|
+
p = joined ? `${drivePrefix}/${joined}` : drivePrefix
|
|
141
|
+
} else if (isAbs) {
|
|
142
|
+
p = `/${joined}`
|
|
143
|
+
} else {
|
|
144
|
+
p = joined || "."
|
|
145
|
+
}
|
|
134
146
|
return isWin ? p.toLowerCase() : p
|
|
135
147
|
}
|
|
136
148
|
|
|
@@ -138,8 +150,14 @@ export function normalizeScopePath(path: string): string {
|
|
|
138
150
|
export function isPathWithin(parentPath: string, childPath: string): boolean {
|
|
139
151
|
const parent = normalizeScopePath(parentPath)
|
|
140
152
|
const child = normalizeScopePath(childPath)
|
|
153
|
+
// Segmen ".." yang tersisa berarti child meloloskan diri di atas root leksikal.
|
|
154
|
+
if (/(?:^|\/)\.\.(?:\/|$)/.test(child)) return false
|
|
141
155
|
if (child === parent) return true
|
|
142
|
-
if (parent === ".")
|
|
156
|
+
if (parent === ".") {
|
|
157
|
+
// Scope "." (workspace relatif) tidak boleh mencakup path absolut ("/etc", "c:/...").
|
|
158
|
+
if (child.startsWith("/") || /^[a-z]:/i.test(child)) return false
|
|
159
|
+
return !child.startsWith("..")
|
|
160
|
+
}
|
|
143
161
|
return child.startsWith(parent.endsWith("/") ? parent : `${parent}/`)
|
|
144
162
|
}
|
|
145
163
|
|
|
@@ -151,7 +151,7 @@ export function admitChild(
|
|
|
151
151
|
return { admitted: false, reason: `capability: ${attenuated.denied}` }
|
|
152
152
|
|
|
153
153
|
// 4. Deadline: ≤ sisa parent; tak diketahui = ceiling backend existing.
|
|
154
|
-
// Evidence ceiling: SUB_AGENT_TIMEOUT_MS (task.ts
|
|
154
|
+
// Evidence ceiling: SUB_AGENT_TIMEOUT_MS (dipakai di `src/tools/task.ts`).
|
|
155
155
|
const backendCeiling = LIMITS.SUB_AGENT_TIMEOUT_MS
|
|
156
156
|
let effectiveDeadlineMs: number | null
|
|
157
157
|
if (spec.parentRemainingDeadlineMs !== undefined) {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
// mutable di module scope: dua komposisi (session/workspace berbeda) tidak
|
|
18
18
|
// mungkin saling melihat event, jurnal, atau dispatch satu sama lain.
|
|
19
19
|
// - Journal path EKSPLISIT dari caller. Tidak ada default global dan tidak ada
|
|
20
|
-
//
|
|
20
|
+
// pengambilan dari acak: resume berarti caller memberikan path yang SAMA.
|
|
21
21
|
// - Journal wajib secara default (fail-closed): open gagal = konstruksi gagal.
|
|
22
22
|
// "Tak ada jurnal" hanya boleh terjadi bila mode non-durable diminta eksplisit.
|
|
23
23
|
//
|
|
@@ -34,15 +34,15 @@
|
|
|
34
34
|
// - host.shutdown() = latch admitting/run + hook onShutdown milik PEMILIK. Hook
|
|
35
35
|
// itu adalah tempat owner menghentikan produsen event; karena itu hook berjalan
|
|
36
36
|
// SEBELUM drain/flush, bukan sesudah.
|
|
37
|
-
// - Execution drain = menunggu kerja in-flight yang DIDAFTARKAN runtime (track())
|
|
38
|
-
//
|
|
37
|
+
// - Execution drain = menunggu kerja in-flight yang DIDAFTARKAN runtime (track()).
|
|
38
|
+
// Executions non-terminal yang TIDAK dilacak TIDAK ditulis ulang:
|
|
39
39
|
// shutdown tak pernah mengarang COMPLETED; ia melapor, dan M12 yang menafsirkan.
|
|
40
40
|
// - Event delivery drain: M10 emit() sepenuhnya sinkron (tak ada antrean), jadi
|
|
41
41
|
// satu-satunya pengiriman async adalah append M11. Drain menunggu append yang
|
|
42
42
|
// masih jalan, termasuk yang muncul selama drain itu sendiri.
|
|
43
43
|
// - journal.flush() setelah drain: inilah batas durability. Setelah flush, hook
|
|
44
44
|
// berhenti append (barrier) — sehingga tak ada append SETELAH flush, dan
|
|
45
|
-
//
|
|
45
|
+
// pastinya tak ada reopen yang diam-diam.
|
|
46
46
|
// - journal.close() sesudah flush: bukti durable sudah dicatat; gagalnya close
|
|
47
47
|
// tak boleh membatalkan bukti itu.
|
|
48
48
|
// - host.close() TERAKHIR: host tak memegang jurnal, jadi menutupnya lebih dulu
|
|
@@ -505,7 +505,7 @@ export function createRuntimeComposition(opts: RuntimeCompositionOptions): Runti
|
|
|
505
505
|
// admitted ⇔ kernel punya record ADMITTED. Gagal = reason jujur ke M13 supaya
|
|
506
506
|
// state dispatch-nya benar (BLOCKED/REJECTED), bukan "sukses".
|
|
507
507
|
// Latch diperiksa LEBIH DALAM dari hostState: jeda antara latch composition dan
|
|
508
|
-
// host.shutdown() itu async, jadi satu-satunya cara
|
|
508
|
+
// host.shutdown() itu async, jadi satu-satunya cara deterministik untuk menutup
|
|
509
509
|
// admission adalah memeriksa latch itu sendiri.
|
|
510
510
|
const bridge = createDispatchBridge({
|
|
511
511
|
admission: {
|
|
@@ -407,14 +407,16 @@ export function openExecutionJournal(
|
|
|
407
407
|
const checkpointFn = opts?.checkpoint
|
|
408
408
|
let db: Database | null = null
|
|
409
409
|
let openError: JournalError | null = null
|
|
410
|
-
// Statement
|
|
411
|
-
//
|
|
412
|
-
//
|
|
413
|
-
const
|
|
410
|
+
// Statement cache di scope fungsi (bukan blok try): satu prepared statement
|
|
411
|
+
// per SQL string agar tidak bocor ribuan handle pada jurnal berumur panjang,
|
|
412
|
+
// dan close() mem-finalize semuanya agar Windows file lock lepas.
|
|
413
|
+
const statementMap = new Map<string, Statement>()
|
|
414
414
|
const prep = (sql: string): Statement => {
|
|
415
415
|
if (!db) throw new Error("journal closed")
|
|
416
|
+
const cached = statementMap.get(sql)
|
|
417
|
+
if (cached) return cached
|
|
416
418
|
const stmt = db.prepare(sql)
|
|
417
|
-
|
|
419
|
+
statementMap.set(sql, stmt)
|
|
418
420
|
return stmt
|
|
419
421
|
}
|
|
420
422
|
try {
|
|
@@ -882,13 +884,16 @@ export function openExecutionJournal(
|
|
|
882
884
|
|
|
883
885
|
integrityCheck(): { checked: number; mismatched: number[] } {
|
|
884
886
|
// Mismatch dilaporkan (seq list), TAK PERNAH dibuang diam-diam.
|
|
885
|
-
// Reuse storedEventContent agar definisi konten tunggal
|
|
887
|
+
// Reuse storedEventContent + storedIntentContent agar definisi konten tunggal.
|
|
886
888
|
const records = api.readAll()
|
|
887
889
|
const mismatched: number[] = []
|
|
888
890
|
for (const rec of records) {
|
|
889
891
|
if (rec.kind === "event") {
|
|
890
892
|
if (hashRecord(storedEventContent(rec)) !== rec.recordHash)
|
|
891
893
|
mismatched.push(rec.journalSequence)
|
|
894
|
+
} else if (rec.kind === "intent") {
|
|
895
|
+
if (hashRecord(storedIntentContent(rec)) !== rec.recordHash)
|
|
896
|
+
mismatched.push(rec.journalSequence)
|
|
892
897
|
}
|
|
893
898
|
}
|
|
894
899
|
return { checked: records.length, mismatched }
|
|
@@ -901,11 +906,12 @@ export function openExecutionJournal(
|
|
|
901
906
|
close(): void {
|
|
902
907
|
// Idempoten: ganda aman; post-close append = already-closed eksplisit.
|
|
903
908
|
// Finalize statements DULU (Windows file lock), baru db.close().
|
|
904
|
-
for (const stmt of
|
|
909
|
+
for (const stmt of statementMap.values()) {
|
|
905
910
|
try {
|
|
906
911
|
stmt.finalize()
|
|
907
912
|
} catch {}
|
|
908
913
|
}
|
|
914
|
+
statementMap.clear()
|
|
909
915
|
if (db) {
|
|
910
916
|
try {
|
|
911
917
|
db.close()
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
// Mutasi hasil inspect TAK PERNAH menyentuh internal.
|
|
18
18
|
// - Retensi terkontestasi (BUKAN arbitrasi — FINAL QA P2): bila dua observasi
|
|
19
19
|
// terminal BERBEDA tiba untuk satu id, registry TIDAK TAHU mana yang commit
|
|
20
|
-
// duluan (otoritas serialisasi = Kernel M8,
|
|
20
|
+
// duluan (otoritas serialisasi = Kernel M8, `src/runtime/execution-kernel.ts`). Yang disimpan adalah
|
|
21
21
|
// observasi pertama (retensi deterministik anti-flap) + flag `contested:true`
|
|
22
22
|
// yang menyatakan "butuh kernel truth untuk resolve — JANGAN baca snapshot
|
|
23
23
|
// ini sebagai keputusan lifecycle". Observasi non-terminal sesudah terminal
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// composition root, sub-agen, dan scheduler, sehingga lifecycle turn tidak punya
|
|
6
6
|
// authority yang jelas dan tidak pernah masuk jurnal durable M11. M15 tidak
|
|
7
7
|
// menulis lifecycle semantics baru: ia MEMINDAHKAN pencatatan lifecycle turn ke
|
|
8
|
-
// Kernel yang sudah ada (M8) melalui admission M13,
|
|
8
|
+
// Kernel yang sudah ada (M8) melalui admission M13, sementara eksekusi fisiknya
|
|
9
9
|
// tetap milik lapisan yang sudah terbukti benar (vendor MiniCore + tool executor).
|
|
10
10
|
//
|
|
11
11
|
// Aturan yang dikunci (jangan dilonggarkan tanpa ADR baru):
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
// - Mode `off` = tak ada runtime; jalur legacy persis seperti sebelum M15.
|
|
20
20
|
// - Pemetaan hasil (COMPLETED/FAILED/CANCELLED/TIMED_OUT/BUDGET_EXCEEDED) memakai
|
|
21
21
|
// taksonomi yang SUDAH ADA (AgentError.kind). Tidak ada taksonomi baru; error
|
|
22
|
-
// asli selalu dilempar ulang apa adanya
|
|
23
|
-
// - Setiap pekerjaan yang runtime
|
|
22
|
+
// asli selalu dilempar ulang apa adanya sehingga atribusi error tak berubah.
|
|
23
|
+
// - Setiap pekerjaan yang runtime ini daftarkan masuk ke `track()` sehingga
|
|
24
24
|
// drain M14 benar-benar menutup eksekusi milik runtime (utang M14 resolved).
|
|
25
25
|
// - Tanpa efek samping di modul ini: tidak ada spawn, tidak ada network, tidak
|
|
26
26
|
// ada akses langsung ke TaskStore/scheduler/UI/CLI.
|
|
@@ -324,9 +324,6 @@ export function createProductionExecutionRunner(deps: {
|
|
|
324
324
|
}
|
|
325
325
|
const executionId = record.executionId
|
|
326
326
|
m.admitted++
|
|
327
|
-
// Parent lineage (M7): turn anak WAJIB menunjuk turn ini sebagai
|
|
328
|
-
// parentExecutionId, bukan menjadi akar sendiri.
|
|
329
|
-
if (request.kind === "turn") currentParentExecutionId.value = executionId
|
|
330
327
|
|
|
331
328
|
// Bukti durable: intent dispatch ditulis SETELAH admission sukses dan
|
|
332
329
|
// DITUNGGU, jadi redelivery lintas proses bisa dibuktikan (bukan
|
|
@@ -365,6 +362,10 @@ export function createProductionExecutionRunner(deps: {
|
|
|
365
362
|
record,
|
|
366
363
|
)
|
|
367
364
|
}
|
|
365
|
+
// Parent lineage (M7): catat sebagai parentExecutionId hanya SETELAH
|
|
366
|
+
// transisi RUNNING komit, agar turn yang ditolak RUNNING tidak menimpa
|
|
367
|
+
// parentExecutionId aktif milik turn sebelumnya.
|
|
368
|
+
if (request.kind === "turn") currentParentExecutionId.value = executionId
|
|
368
369
|
|
|
369
370
|
// track() menutup utang M14: pekerjaan yang masih berjalan saat shutdown
|
|
370
371
|
// HARUS terdaftar, supaya flush jurnal tak mendahului event terakhirnya.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// M14/M15 — Produksi runtime composition: SATU seam,
|
|
1
|
+
// M14/M15 — Produksi runtime composition: SATU seam, mode bertingkat.
|
|
2
2
|
//
|
|
3
3
|
// Kenapa berkas ini ada: `createRuntimeComposition` (composition.ts) merakit satu
|
|
4
4
|
// runtime, tapi tidak tahu BAGAIMANA produksi memanggilnya. Tanpa lapisan ini,
|
|
@@ -185,7 +185,7 @@ export { runtimeFactsFrom } from "./runtime-status-facts.ts"
|
|
|
185
185
|
* sini — flush adalah operasi drain, bukan probe; memanggilnya dari jalur
|
|
186
186
|
* status akan memicu drain setiap kali status dibaca.
|
|
187
187
|
*
|
|
188
|
-
* Sumber kebenaran:(handle → composition). FAKTA runtime dibaca dari komposisi
|
|
188
|
+
* Sumber kebenaran: (handle → composition). FAKTA runtime dibaca dari komposisi
|
|
189
189
|
* (satu-satunya pemilik state runtime); observation hanya menimpa fakta
|
|
190
190
|
* lapisan task (scheduler/TaskStore) yang memang tak bisa dibaca dari dalam.
|
|
191
191
|
*/
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
//
|
|
8
8
|
// BEDA dari M6 (`src/runtime/capability.ts`): M6 adalah izin EKSEKUSI per
|
|
9
9
|
// eksekusi (request → grant → approval, anak ⊆ parent). Yang di sini adalah
|
|
10
|
-
// pernyataan KETERSEDIAAN runtime — "apakah lapisan ini bisa
|
|
10
|
+
// pernyataan KETERSEDIAAN runtime — "apakah lapisan ini bisa dipakai SEKARANG",
|
|
11
11
|
// bukan "apakah operasi ini diizinkan". Mencampur keduanya menghasilkan
|
|
12
12
|
// "runtime punya kapabilitas" yang sebenarnya "eksekusi ini diizinkan".
|
|
13
13
|
//
|
|
@@ -22,7 +22,7 @@ import type { FailureClassification } from "./supervisor.ts"
|
|
|
22
22
|
/**
|
|
23
23
|
* Bentuk hasil drain jurnal runtime.
|
|
24
24
|
*
|
|
25
|
-
* PADA: bentuk "drain selesai + berapa append
|
|
25
|
+
* PADA: bentuk "drain selesai + berapa append yang selesai" — BUKAN probe
|
|
26
26
|
* readiness. Keberadaan drain yang berhasil tak berarti persistence-nya utuh
|
|
27
27
|
* saat ini (dan sebaliknya, drain yang belum jalan tak berarti persistence-nya
|
|
28
28
|
* rusak) — dua hal yang beda, jadi bentuknya dipisah dari bukti readiness.
|
|
@@ -39,11 +39,11 @@
|
|
|
39
39
|
// HISTORY EKSEKUSI (intent dispatch + event kernel), bukan syarat kerja:
|
|
40
40
|
// mode non-durable (`journalRequired: false`, dipakai mode runtime
|
|
41
41
|
// `constructed`) secara resmi berjalan tanpa jurnal — jadi menjadikannya
|
|
42
|
-
// syarat akan
|
|
42
|
+
// syarat akan menutup gerbang untuk konfigurasi yang sah. Yang TIDAK boleh
|
|
43
43
|
// hilang adalah otoritas task (TaskStore) dan pemiliknya (scheduler).
|
|
44
44
|
//
|
|
45
45
|
// SEMUA BUTIR HANYA YANG BISA DIBUKTI DARI KODE. Tidak ada kapabilitas yang
|
|
46
|
-
// diANGGAP lebih tinggi dari yang
|
|
46
|
+
// diANGGAP lebih tinggi dari yang dilalui jalur kode nyata.
|
|
47
47
|
|
|
48
48
|
import {
|
|
49
49
|
createRequirementMap,
|
package/src/sandbox/os.ts
CHANGED
|
@@ -87,11 +87,12 @@ export function runInOsSandbox(
|
|
|
87
87
|
const timeout = opts.timeoutMs ?? LIMITS.DOCKER_TIMEOUT_MS
|
|
88
88
|
|
|
89
89
|
if (type === "seatbelt") {
|
|
90
|
-
// macOS seatbelt - simple deny network profile
|
|
90
|
+
// macOS seatbelt - simple deny network profile (escape \ dan " pada path)
|
|
91
|
+
const escapedAbs = abs.replace(/\\/g, "\\\\").replace(/"/g, '\\"')
|
|
91
92
|
const profile = `(version 1)
|
|
92
93
|
(deny default)
|
|
93
94
|
(allow process-exec)
|
|
94
|
-
(allow file-read* file-write* (subpath "${
|
|
95
|
+
(allow file-read* file-write* (subpath "${escapedAbs}"))
|
|
95
96
|
(allow file-read* (subpath "/usr") (subpath "/bin") (subpath "/private/tmp"))
|
|
96
97
|
(allow sysctl-read)
|
|
97
98
|
(deny network*)
|
|
@@ -111,7 +112,7 @@ export function runInOsSandbox(
|
|
|
111
112
|
"--ro-bind",
|
|
112
113
|
"/lib",
|
|
113
114
|
"/lib",
|
|
114
|
-
"--ro-bind",
|
|
115
|
+
"--ro-bind-try",
|
|
115
116
|
"/lib64",
|
|
116
117
|
"/lib64",
|
|
117
118
|
"--proc",
|
|
@@ -6,7 +6,12 @@ import { LIMITS } from "../constants.ts"
|
|
|
6
6
|
import { atomicWriteText } from "../lib/atomic-write.ts"
|
|
7
7
|
import { GIT_SAFE_BASE } from "../lib/git-hardening.ts"
|
|
8
8
|
import { sanitizeSessionPart } from "../lib/session-id.ts"
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
isOwnedState,
|
|
11
|
+
isPathOutsideRoot,
|
|
12
|
+
isRealPathOutsideRoot,
|
|
13
|
+
isSensitive,
|
|
14
|
+
} from "../policy/jail.ts"
|
|
10
15
|
import { appendUndoMarker, loadJournal } from "./journal.ts"
|
|
11
16
|
import { diffTrees, ephemeralTree, isGitRepo, restoreTree, snapshotTree } from "./shadow-git.ts"
|
|
12
17
|
|
|
@@ -308,7 +313,23 @@ export async function snapshotWorkspace(
|
|
|
308
313
|
.slice(0, limit)
|
|
309
314
|
if (dirty.length > 0) {
|
|
310
315
|
const snaps: FileSnapshot[] = []
|
|
311
|
-
|
|
316
|
+
const seen = new Set<string>()
|
|
317
|
+
for (const f of dirty) {
|
|
318
|
+
const snap = await captureFileSnapshot(resolve(cwd, f), cwd)
|
|
319
|
+
seen.add(snap.path)
|
|
320
|
+
snaps.push(snap)
|
|
321
|
+
}
|
|
322
|
+
if (snaps.length < limit) {
|
|
323
|
+
const extra: string[] = []
|
|
324
|
+
await walkFiles(cwd, "", extra, limit)
|
|
325
|
+
for (const f of extra) {
|
|
326
|
+
if (snaps.length >= limit) break
|
|
327
|
+
const snap = await captureFileSnapshot(resolve(cwd, f), cwd)
|
|
328
|
+
if (seen.has(snap.path)) continue
|
|
329
|
+
seen.add(snap.path)
|
|
330
|
+
snaps.push(snap)
|
|
331
|
+
}
|
|
332
|
+
}
|
|
312
333
|
return snaps
|
|
313
334
|
}
|
|
314
335
|
}
|
|
@@ -441,16 +462,20 @@ export async function recordCheckpointFromSnapshots(
|
|
|
441
462
|
})
|
|
442
463
|
}
|
|
443
464
|
|
|
444
|
-
// Terapkan snapshot dengan jail path: path di luar workspace dilewati.
|
|
465
|
+
// Terapkan snapshot dengan jail path: path di luar workspace atau sensitif dilewati.
|
|
445
466
|
async function applySnapshots(snapshots: FileSnapshot[], cwd: string): Promise<string[]> {
|
|
446
467
|
const root = resolve(cwd)
|
|
447
468
|
const applied: string[] = []
|
|
448
469
|
for (const snap of snapshots) {
|
|
449
470
|
const absPath = resolve(root, snap.path)
|
|
450
|
-
if (isPathOutsideRoot(absPath, root)) {
|
|
471
|
+
if (isPathOutsideRoot(absPath, root) || isRealPathOutsideRoot(absPath, root)) {
|
|
451
472
|
applied.push(`${snap.path} (skipped: outside workspace)`)
|
|
452
473
|
continue
|
|
453
474
|
}
|
|
475
|
+
if (isSensitive(absPath) || isOwnedState(absPath)) {
|
|
476
|
+
applied.push(`${snap.path} (skipped: protected path)`)
|
|
477
|
+
continue
|
|
478
|
+
}
|
|
454
479
|
if (snap.content === null) {
|
|
455
480
|
if (existsSync(absPath)) {
|
|
456
481
|
await rm(absPath, { force: true }).catch(() => {})
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
// - Tanpa state durable: ContextView hidup hanya di RAM per proses.
|
|
17
17
|
//
|
|
18
18
|
// Bentuk ringkasan sintetis mengikuti konvensi vendor yang sudah ada
|
|
19
|
-
// (vendor/minicore/src/core/compact.ts:
|
|
19
|
+
// (vendor/minicore/src/core/compact.ts:48-51 — {role:"user", content:"Previous
|
|
20
20
|
// context:\n..."}): pesan user biasa, TANPA field persistence-only (event_id,
|
|
21
21
|
// seq, run_id, thread_id, migrated, …) dan tidak pernah ditulis balik ke histori.
|
|
22
22
|
|
|
@@ -180,6 +180,13 @@ function assembleViewMessages(
|
|
|
180
180
|
*
|
|
181
181
|
* Fallback = histori kanonik utuh, tanpa filter/urutan/transformasi — identik
|
|
182
182
|
* dengan replay `loadSession` hari ini.
|
|
183
|
+
*
|
|
184
|
+
* LEGACY (T7): tidak lagi di-wire ke jalur produksi — `selectContext`
|
|
185
|
+
* (context-selector.ts) adalah satu-satunya selector produksi (superset:
|
|
186
|
+
* CURRENT + STALE-rule-8 + budget-tail + fallback-unknown). Fungsi ini dan
|
|
187
|
+
* primitif di bawahnya (`boundaryIsSafe`, `syntheticSummaryMessage`, …) TETAP
|
|
188
|
+
* diekspor karena dipakai sebagai primitif bersama oleh selector P3.3 dan
|
|
189
|
+
* diuji langsung oleh `context-assembly.test.ts`.
|
|
183
190
|
*/
|
|
184
191
|
export function assembleContext(
|
|
185
192
|
sessionId: string,
|
|
@@ -40,7 +40,7 @@ export type ContextFrontierRelation = "EQUAL" | "A_AHEAD" | "B_AHEAD" | "DIVERGE
|
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
42
|
* Referensi event kanonis — bentuk baris durable `messages` (lihat
|
|
43
|
-
* loadSession di persistence.ts:
|
|
43
|
+
* loadSession di persistence.ts:1513). `content` di sini adalah nilai
|
|
44
44
|
* TERSIMPAN (sudah safeContent/scrub/cap saat tulis), bukan objek runtime:
|
|
45
45
|
* hanya dari sanalah anchor stabil lintas replay/restart.
|
|
46
46
|
*/
|
|
@@ -361,7 +361,7 @@ export function assessContextFreshness(
|
|
|
361
361
|
* Derivasikan revisi kanonis dari daftar event durable: jumlah event
|
|
362
362
|
* `context.compacted` yang durable+replayable (events.ts DURABILITY).
|
|
363
363
|
* Jembatan kernel `context:compacted` → durable `context.compacted` ada di
|
|
364
|
-
* adapter.ts:
|
|
364
|
+
* adapter.ts:1123-1129, jadi setiap kompaksi loop/recovery meninggalkan satu
|
|
365
365
|
* marker durable — kecuali jalur yang tak memasang adapter (headless tanpa
|
|
366
366
|
* presentation): revisi undercount di sana adalah seam P3.5, bukan angka
|
|
367
367
|
* yang boleh ditebak di sini (fail-closed: hitung yang durable saja).
|
|
@@ -13,9 +13,10 @@
|
|
|
13
13
|
// - TULIS = HANYA `history_projections` (derived). NEVER `messages`/head/run.
|
|
14
14
|
// - Bukan otoritas: proyeksi tetap cache; `saveSession` tetap satu-satunya
|
|
15
15
|
// penulis kanonik.
|
|
16
|
-
// - Ringkasan = render fold
|
|
17
|
-
// PREFIX kanonik [0, baseSeq); ekor
|
|
18
|
-
// algoritma A+C lanjutan (P3.7),
|
|
16
|
+
// - Ringkasan = render fold HOST yang SUDAH ADA (`mechanicalKeepResults` —
|
|
17
|
+
// mempertahankan hasil tool) atas PREFIX kanonik [0, baseSeq); ekor
|
|
18
|
+
// [baseSeq, head] tetap verbatim. BUKAN algoritma A+C lanjutan (P3.7),
|
|
19
|
+
// bukan LLM/embedding/network.
|
|
19
20
|
// - Deterministik: urutan kanonik, tanpa Date.now/random di jalur derivasi
|
|
20
21
|
// (built_at diisi primitif P2.7, bukan klaim cakupan).
|
|
21
22
|
//
|
|
@@ -27,9 +28,13 @@
|
|
|
27
28
|
//
|
|
28
29
|
// Runtime adapter / revision bridge ke runtime = P3.5 (di luar modul ini).
|
|
29
30
|
|
|
30
|
-
import { ContextStore
|
|
31
|
+
import { ContextStore } from "#minicore"
|
|
31
32
|
import type { Message } from "#minicore/core/types.ts"
|
|
32
33
|
import { LIMITS } from "../constants.ts"
|
|
34
|
+
// R10/A — pakai folder HOST (mempertahankan hasil tool) alih-alih folder kernel
|
|
35
|
+
// (`mechanicalCompaction`) yang menulis `<result omitted>`; proyeksi durable
|
|
36
|
+
// yang dipakai saat resume tidak boleh membuang fakta hasil tool.
|
|
37
|
+
import { mechanicalKeepResults } from "../policy/compaction.ts"
|
|
33
38
|
import { renderFullHistoryFold } from "./full-history-fold.ts"
|
|
34
39
|
import {
|
|
35
40
|
buildProjection,
|
|
@@ -53,9 +58,9 @@ export interface ProjectionProducePolicy {
|
|
|
53
58
|
readonly keepRecentTurns: number
|
|
54
59
|
/**
|
|
55
60
|
* P3.7 — strategi fold. `"mechanical"` (default) = perilaku P3.4 yang sudah
|
|
56
|
-
* ada (prefix parsial via
|
|
57
|
-
* (cakupan penuh [0, N), CURRENT-capable).
|
|
58
|
-
* lama bila field absen.
|
|
61
|
+
* ada (prefix parsial via folder host yang mempertahankan hasil tool).
|
|
62
|
+
* `"full-history"` = renderer P3.7 (cakupan penuh [0, N), CURRENT-capable).
|
|
63
|
+
* Default eksplisit menjaga perilaku lama bila field absen.
|
|
59
64
|
*/
|
|
60
65
|
readonly fold?: "mechanical" | "full-history"
|
|
61
66
|
}
|
|
@@ -74,8 +79,9 @@ export interface ProjectionProduceResult {
|
|
|
74
79
|
|
|
75
80
|
/**
|
|
76
81
|
* Derivasi DETERMINISTIK {summaryText, baseSeq} dari baris kanonik memakai render
|
|
77
|
-
* fold
|
|
78
|
-
* tak memutasi input). Mengembalikan null bila tak ada
|
|
82
|
+
* fold HOST yang SUDAH ADA (`mechanicalKeepResults`, mempertahankan hasil tool).
|
|
83
|
+
* MURNI (tak menyentuh DB, tak memutasi input). Mengembalikan null bila tak ada
|
|
84
|
+
* prefix untuk diringkas.
|
|
79
85
|
*
|
|
80
86
|
* base_seq = jumlah baris prefix yang diringkas = total - |ekor verbatim|.
|
|
81
87
|
*/
|
|
@@ -84,13 +90,27 @@ export function deriveSummaryFromCanonical(
|
|
|
84
90
|
policy: ProjectionProducePolicy,
|
|
85
91
|
): { summaryText: string; baseSeq: number } | null {
|
|
86
92
|
if (messages.length === 0) return null
|
|
93
|
+
// R10/T1 — bila messages[0] SUDAH merupakan ringkasan kernel (LLM/mechanical,
|
|
94
|
+
// ber-prefix "Previous context"), JANGAN re-fold mekanikal (itu menurunkan
|
|
95
|
+
// fidelitas: ringkasan LLM yang kaya berubah jadi head per-baris yang kasar).
|
|
96
|
+
// Reuse apa adanya sehingga resume melihat ringkasan yang SAMA dengan yang
|
|
97
|
+
// dilihat model saat kompaksi. baseSeq=1: ringkasan mewakili baris indeks 0,
|
|
98
|
+
// ekor [1, N) verbatim.
|
|
99
|
+
const first = messages[0] as { role?: unknown; content?: unknown } | undefined
|
|
100
|
+
if (
|
|
101
|
+
first?.role === "user" &&
|
|
102
|
+
typeof first.content === "string" &&
|
|
103
|
+
first.content.startsWith("Previous context")
|
|
104
|
+
) {
|
|
105
|
+
return { summaryText: first.content, baseSeq: 1 }
|
|
106
|
+
}
|
|
87
107
|
const keep =
|
|
88
108
|
Number.isInteger(policy.keepRecentTurns) && policy.keepRecentTurns >= 1
|
|
89
109
|
? policy.keepRecentTurns
|
|
90
110
|
: 1
|
|
91
111
|
const store = new ContextStore()
|
|
92
112
|
store.appendAll(messages)
|
|
93
|
-
const folded =
|
|
113
|
+
const folded = mechanicalKeepResults(store, keep)
|
|
94
114
|
// Tak ada fold (prefix kosong) → tak ada cakupan untuk proyeksi.
|
|
95
115
|
if (folded.length >= messages.length) return null
|
|
96
116
|
const kept = folded.length - 1
|
|
@@ -102,7 +122,12 @@ export function deriveSummaryFromCanonical(
|
|
|
102
122
|
}
|
|
103
123
|
|
|
104
124
|
function boundProjectionSummary(text: string): string {
|
|
105
|
-
|
|
125
|
+
// R10/T1 — proyeksi boleh membawa ringkasan kernel yang lebih kaya (hasil
|
|
126
|
+
// `summaryCharBudgetForWindow`, hingga jendela besar). Atapnya dinaikkan dari
|
|
127
|
+
// 4k char ke `COMPACTION_SUMMARY_SCALED_MAX_CHARS` supaya ringkasan LLM untuk
|
|
128
|
+
// model 1M tidak terpotong di batas proyeksi. Storage hard-cap (512KB) tetap
|
|
129
|
+
// dijaga lapisan persistence.
|
|
130
|
+
const cap = LIMITS.COMPACTION_SUMMARY_SCALED_MAX_CHARS
|
|
106
131
|
if (text.length <= cap) return text
|
|
107
132
|
const marker = "\n[projection summary truncated; older details may be missing]"
|
|
108
133
|
let head = text.slice(0, Math.max(0, cap - marker.length))
|
|
@@ -121,7 +121,7 @@ function open(cwd?: string, local = false): Database {
|
|
|
121
121
|
// [Phase 7 / Live #1] Pembukaan koneksi + PRAGMA setup dibungkus dengan
|
|
122
122
|
// withBusyRetrySync. Sebelumnya hanya DDL yang di-retry; `new Database(p)`
|
|
123
123
|
// dan `PRAGMA journal_mode=WAL` bisa gagal SQLITE_BUSY saat dua proses CLI
|
|
124
|
-
// paralel membuka DB bersamaan (race nyata
|
|
124
|
+
// paralel membuka DB bersamaan (race nyata saat dua proses CLI membuka DB). Dengan
|
|
125
125
|
// membungkus seluruh urutan inisialisasi, proses yang kalah tunggu lalu
|
|
126
126
|
// coba ulang sampai lock dilepas (backoff eksponensial + jitter, 8×).
|
|
127
127
|
// PRAGMA busy_timeout DIATUR dalam retry yang sama SEBELUM journal_mode:
|
|
@@ -1344,16 +1344,27 @@ export function purgeExpired(db: Database, now = Date.now()): number {
|
|
|
1344
1344
|
// than duplicated for exactly that reason: 6O ADR-9's rule is ONE deletion
|
|
1345
1345
|
// architecture, so the ordering cannot drift between these two entry points.
|
|
1346
1346
|
const expiring = db
|
|
1347
|
-
.prepare(`SELECT id FROM sessions WHERE COALESCE(updated_at, created_at) < ?`)
|
|
1348
|
-
.all(cutoff) as { id: string }[]
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1347
|
+
.prepare(`SELECT id, cwd FROM sessions WHERE COALESCE(updated_at, created_at) < ?`)
|
|
1348
|
+
.all(cutoff) as { id: string; cwd?: string | null }[]
|
|
1349
|
+
|
|
1350
|
+
if (expiring.length > 0) {
|
|
1351
|
+
const { TaskStore } = require("../task/store.ts") as typeof import("../task/store.ts")
|
|
1352
|
+
const fallbackCwd = sessionCwdOf(db, expiring)
|
|
1353
|
+
const byCwd = new Map<string | undefined, string[]>()
|
|
1354
|
+
for (const row of expiring) {
|
|
1355
|
+
const key = row.cwd || fallbackCwd
|
|
1356
|
+
const list = byCwd.get(key) ?? []
|
|
1357
|
+
list.push(row.id)
|
|
1358
|
+
byCwd.set(key, list)
|
|
1359
|
+
}
|
|
1360
|
+
for (const [cwd, ids] of byCwd) {
|
|
1361
|
+
const tasks = new TaskStore(cwd)
|
|
1362
|
+
for (const sid of ids) {
|
|
1363
|
+
// 1. invalidate in-flight executions, 2. remove task rows.
|
|
1364
|
+
tasks.bumpSessionIncarnation(sid)
|
|
1365
|
+
tasks.deleteSessionTasks(sid)
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1357
1368
|
}
|
|
1358
1369
|
|
|
1359
1370
|
const gone = db
|