minicode-ai 0.11.1 → 0.13.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 +89 -0
- package/LICENSE +21 -21
- package/README.md +4 -4
- package/cli/args.ts +46 -0
- package/cli/commands/acp.ts +163 -10
- package/cli/commands/config.ts +33 -18
- package/cli/commands/daemon.ts +515 -0
- package/cli/commands/exec.ts +145 -53
- package/cli/commands/openwork.ts +986 -0
- package/cli/commands/sessions.ts +4 -1
- package/cli/commands/stats.ts +34 -4
- package/cli/commands.ts +217 -2
- package/cli/index.ts +146 -14
- package/cli/recovery-warning.ts +115 -0
- package/cli/router.ts +32 -1
- package/cli/setup.ts +2332 -171
- package/cli/tui.ts +113 -7
- package/docs/OUTPUT_ARCHITECTURE_AUDIT.md +489 -0
- package/docs/OUTPUT_EVENT_MODEL.md +289 -0
- package/docs/OUTPUT_IMPLEMENTATION_PLAN.md +391 -0
- package/docs/OUTPUT_PROTOCOL_SPEC.md +285 -0
- package/docs/OUTPUT_RENDERING_SPEC.md +248 -0
- package/docs/OUTPUT_UX_RULES.md +449 -0
- package/docs/PLAN_UIUX_V6.md +2 -2
- package/docs/README.md +4 -3
- package/docs/TERMINAL_CONTRACT.md +278 -71
- package/docs/architecture.md +89 -7
- package/docs/changelog.md +1 -1
- package/docs/choosing-mode.md +2 -2
- package/docs/cli.md +9 -5
- package/docs/concepts.md +1 -1
- package/docs/contributing.md +9 -2
- package/docs/environment.md +6 -2
- package/docs/exec.md +46 -5
- package/docs/memory-sessions.md +2 -0
- package/docs/policy-sandbox.md +1 -1
- package/docs/pricing-budget.md +1 -1
- package/docs/quickstart.md +2 -2
- package/docs/repl.md +6 -2
- package/docs/security-model.md +1 -1
- package/docs/security.md +1 -1
- package/docs/skills.md +2 -2
- package/docs/terminal.md +9 -5
- package/docs/tools.md +1 -1
- package/package.json +35 -5
- package/src/app/session.ts +261 -15
- package/src/app/tool-layer.ts +94 -7
- package/src/daemon/approvals.ts +361 -0
- package/src/daemon/capability.ts +145 -0
- package/src/daemon/children.ts +142 -0
- package/src/daemon/client.ts +267 -0
- package/src/daemon/control.ts +350 -0
- package/src/daemon/discovery.ts +234 -0
- package/src/daemon/feed.ts +155 -0
- package/src/daemon/framing.ts +94 -0
- package/src/daemon/host.ts +316 -0
- package/src/daemon/protocol.ts +217 -0
- package/src/daemon/resource.ts +170 -0
- package/src/daemon/sanitize.ts +57 -0
- package/src/daemon/server.ts +627 -0
- package/src/daemon/store.ts +317 -0
- package/src/daemon/subscription.ts +270 -0
- package/src/daemon/telemetry.ts +81 -0
- package/src/hooks/run.ts +12 -1
- package/src/lib/atomic-write.ts +29 -3
- package/src/lib/db-path.ts +26 -0
- package/src/lib/keystore.ts +544 -42
- package/src/lib/net.ts +43 -1
- package/src/lib/safe-open.ts +116 -1
- package/src/lib/session-id.ts +15 -0
- package/src/lsp/client.ts +123 -5
- package/src/mcp/client.ts +139 -17
- package/src/mcp/server.ts +177 -50
- package/src/mcp/transport.ts +16 -19
- package/src/memory/vector.ts +770 -55
- package/src/policy/allowlist.ts +14 -2
- package/src/policy/bash-guard.ts +105 -10
- package/src/policy/compaction.ts +82 -5
- package/src/policy/consequence-engine.ts +220 -0
- package/src/policy/context.ts +132 -0
- package/src/policy/executor.ts +187 -121
- package/src/policy/no-progress.ts +559 -0
- package/src/policy/permission.ts +4 -8
- package/src/policy/pricing.ts +17 -3
- package/src/policy/scrub.ts +69 -2
- package/src/policy/tool-contract.ts +515 -0
- package/src/policy/usage.ts +310 -24
- package/src/policy/verifier.ts +6 -3
- package/src/policy/work-mode.ts +182 -0
- package/src/presentation/adapter.ts +533 -26
- package/src/presentation/events.ts +151 -0
- package/src/presentation/model.ts +180 -27
- package/src/presentation/projection.ts +858 -0
- package/src/presentation/reducer.ts +645 -310
- package/src/presentation/store.ts +12 -7
- package/src/providers/anthropic.ts +18 -10
- package/src/providers/responses.ts +2 -2
- package/src/runtime/capability.ts +409 -0
- package/src/runtime/child-execution.ts +274 -0
- package/src/runtime/composition.ts +958 -0
- package/src/runtime/dispatch.ts +591 -0
- package/src/runtime/execution-backend.ts +632 -0
- package/src/runtime/execution-events.ts +272 -0
- package/src/runtime/execution-id.ts +230 -0
- package/src/runtime/execution-journal.ts +926 -0
- package/src/runtime/execution-kernel.ts +456 -0
- package/src/runtime/execution-registry.ts +379 -0
- package/src/runtime/process-supervision.ts +276 -0
- package/src/runtime/production-execution.ts +551 -0
- package/src/runtime/production-runtime.ts +217 -0
- package/src/runtime/recovery-safety.ts +70 -0
- package/src/runtime/recovery.ts +477 -0
- package/src/runtime/runtime-capabilities.ts +179 -0
- package/src/runtime/runtime-diagnostics.ts +141 -0
- package/src/runtime/runtime-host.ts +365 -0
- package/src/runtime/runtime-status-facts.ts +222 -0
- package/src/runtime/runtime-status-provider.ts +74 -0
- package/src/runtime/runtime-status.ts +459 -0
- package/src/runtime/runtime-task-admission.ts +101 -0
- package/src/runtime/supervisor.ts +444 -0
- package/src/session/authority.ts +168 -0
- package/src/session/checkpoint.ts +88 -1
- package/src/session/context-adapter.ts +251 -0
- package/src/session/context-assembly.ts +242 -0
- package/src/session/context-identity.ts +389 -0
- package/src/session/context-projection.ts +248 -0
- package/src/session/context-selector.ts +500 -0
- package/src/session/cross-session-adoption.ts +249 -0
- package/src/session/full-history-fold.ts +171 -0
- package/src/session/identity.ts +192 -0
- package/src/session/journal.ts +805 -102
- package/src/session/open-work-intent.ts +732 -0
- package/src/session/open-work.ts +767 -0
- package/src/session/pending-tools.ts +94 -0
- package/src/session/persistence.ts +3569 -127
- package/src/session/runtime-header.ts +208 -0
- package/src/session/shadow-git.ts +13 -5
- package/src/session/verification.ts +1623 -0
- package/src/task/assignment.ts +136 -0
- package/src/task/autonomous-adapter.ts +168 -0
- package/src/task/autonomous-context.ts +630 -0
- package/src/task/autonomous-policy.ts +490 -0
- package/src/task/continuity.ts +179 -0
- package/src/task/execution-cancellation.ts +165 -0
- package/src/task/graph-validate.ts +379 -0
- package/src/task/graph.ts +305 -0
- package/src/task/identity.ts +230 -0
- package/src/task/model.ts +417 -0
- package/src/task/production-scheduler.ts +293 -0
- package/src/task/readiness.ts +229 -0
- package/src/task/scheduler-observability.ts +387 -0
- package/src/task/scheduler.ts +1197 -0
- package/src/task/scheduling-policy.ts +165 -0
- package/src/task/session-authority.ts +148 -0
- package/src/task/session-ownership.ts +211 -0
- package/src/task/store.ts +2887 -0
- package/src/task/sync.ts +343 -0
- package/src/task/trigger.ts +260 -0
- package/src/tools/bash.ts +377 -211
- package/src/tools/code_run.ts +1 -1
- package/src/tools/delete_file.ts +1 -1
- package/src/tools/edit.ts +33 -6
- package/src/tools/evidence.ts +30 -0
- package/src/tools/git.ts +4 -4
- package/src/tools/glob.ts +12 -3
- package/src/tools/grep.ts +1 -1
- package/src/tools/lsp.ts +4 -4
- package/src/tools/mcp_call.ts +11 -4
- package/src/tools/memory.ts +153 -18
- package/src/tools/move_file.ts +1 -1
- package/src/tools/patch.ts +1 -1
- package/src/tools/read_file.ts +1 -1
- package/src/tools/read_image.ts +1 -1
- package/src/tools/submit_result.ts +1 -1
- package/src/tools/task.ts +437 -41
- package/src/tools/todo.ts +662 -35
- package/src/tools/web_fetch.ts +4 -2
- package/src/tools/web_search.ts +9 -3
- package/src/tools/write_file.ts +1 -1
- package/src/ui/assistant/simple.ts +123 -50
- package/src/ui/assistant/turn-status.ts +17 -3
- package/src/ui/contract.ts +184 -0
- package/src/ui/footer.ts +52 -19
- package/src/ui/i18n/en.ts +58 -6
- package/src/ui/i18n/id.ts +58 -6
- package/src/ui/input/prompt-engine.ts +120 -25
- package/src/ui/render/errors.ts +39 -1
- package/src/ui/render/markdown-table.ts +455 -0
- package/src/ui/render/markdown.ts +22 -1
- package/src/ui/render/table-grid.ts +184 -0
- package/src/ui/render/table.ts +15 -76
- package/src/ui/runtime/screen.ts +7 -2
- package/src/ui/runtime/statusline.ts +25 -6
- package/src/ui/tui/app.ts +507 -169
- package/src/ui/tui/transcript.ts +531 -89
- package/vendor/minicore/VENDOR.md +1 -1
- package/vendor/minicore/src/core/budget.ts +25 -25
- package/vendor/minicore/src/core/compact.ts +75 -75
- package/vendor/minicore/src/core/errors.ts +59 -59
- package/vendor/minicore/src/core/events.ts +73 -73
- package/vendor/minicore/src/core/executor.ts +139 -139
- package/vendor/minicore/src/core/history.ts +31 -31
- package/vendor/minicore/src/core/index.ts +41 -41
- package/vendor/minicore/src/core/loop.ts +355 -355
- package/vendor/minicore/src/core/permission.ts +22 -22
- package/vendor/minicore/src/core/provider.ts +39 -39
- package/vendor/minicore/src/core/recovery.ts +35 -35
- package/vendor/minicore/src/core/session.ts +327 -327
- package/vendor/minicore/src/core/snapshot.ts +146 -146
- package/vendor/minicore/src/core/tokens.ts +107 -107
- package/vendor/minicore/src/core/tool.ts +115 -115
- package/vendor/minicore/src/core/types.ts +50 -50
- package/vendor/minicore/src/providers/openai-compat.ts +417 -417
- package/AGENTS.md +0 -45
- package/PLAN.md +0 -491
- package/docs/ARCHITECTURE.html +0 -1248
- package/docs/CONTROL-PLANE-MAP.md +0 -139
- package/docs/HARNESS.md +0 -150
- package/docs/SUMMARY.md +0 -52
- package/docs/UI_RENDER_PIPELINE.md +0 -169
- package/docs/USAGE.md +0 -11
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
// M14/M15 — Produksi runtime composition: SATU seam,Mode bertingkat.
|
|
2
|
+
//
|
|
3
|
+
// Kenapa berkas ini ada: `createRuntimeComposition` (composition.ts) merakit satu
|
|
4
|
+
// runtime, tapi tidak tahu BAGAIMANA produksi memanggilnya. Tanpa lapisan ini,
|
|
5
|
+
// pemanggil pertama akan membangun runtime dari dalam `createCliSession`,
|
|
6
|
+
// dan "gate mati berarti tak ada yang dibangun" mustahil dibuktikan — cukup satu
|
|
7
|
+
// `await create(...)` yang tak dijaga.
|
|
8
|
+
//
|
|
9
|
+
// Pola yang dipakai persis mengikuti 6U (`src/task/production-scheduler.ts`):
|
|
10
|
+
// gate dicek SEBELUM konstruksi, dan dependency datang sebagai THUNK yang tak
|
|
11
|
+
// dipanggil saat gate tutup. Jadi "default config tak membuka journal SQLite,
|
|
12
|
+
// tak membangun kernel/host, dan tak menambah handler apa pun" adalah sifat
|
|
13
|
+
// alur kontrol — bukan janji di komentar.
|
|
14
|
+
//
|
|
15
|
+
// Batas yang disengaja:
|
|
16
|
+
// - Mode default `off`: tak ada runtime yang dibangun, jalur legacy utuh.
|
|
17
|
+
// - M15 memakai MODE bertingkat (`off` / `constructed` / `owned`, lihat
|
|
18
|
+
// production-execution.ts) alih-alih boolean M14; boolean `constructed` M14
|
|
19
|
+
// adalah stage "runtime ada, eksekusi belum dimiliki".
|
|
20
|
+
// - Tidak ada lifecycle/dispatch/recovery/dispatch policy BARU di sini: yang
|
|
21
|
+
// dipanggil persis modul M8–M13 via composition.ts.
|
|
22
|
+
|
|
23
|
+
import { resolveLocalDbPath } from "../lib/db-path.ts"
|
|
24
|
+
import {
|
|
25
|
+
createRuntimeComposition,
|
|
26
|
+
type RuntimeComposition,
|
|
27
|
+
type RuntimeCompositionOptions,
|
|
28
|
+
type RuntimeFlushReport,
|
|
29
|
+
type RuntimeShutdownResult,
|
|
30
|
+
} from "./composition.ts"
|
|
31
|
+
import { type RuntimeProductionMode, runtimeModeFor } from "./production-execution.ts"
|
|
32
|
+
import type { RuntimeFacts } from "./runtime-status.ts"
|
|
33
|
+
import { runtimeFactsFrom } from "./runtime-status-facts.ts"
|
|
34
|
+
|
|
35
|
+
export type RuntimeGateSource = "session-option" | "absent"
|
|
36
|
+
|
|
37
|
+
export interface RuntimeGate {
|
|
38
|
+
readonly enabled: boolean
|
|
39
|
+
readonly source: RuntimeGateSource
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const RUNTIME_GATE_DISABLED: RuntimeGate = { enabled: false, source: "absent" }
|
|
43
|
+
export const RUNTIME_GATE_ENABLED: RuntimeGate = { enabled: true, source: "session-option" }
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Gate M15 dibaca dari MODE, bukan boolean: `off` = tak dibangun sama sekali;
|
|
47
|
+
* `constructed`/`owned` = dibangun. Nilai tak dikenal (atau `undefined`) = mati
|
|
48
|
+
* secara struktur — jalur legacy utuh bila tak ada yang mengaktifkan.
|
|
49
|
+
*/
|
|
50
|
+
export function runtimeGateFor(mode: RuntimeProductionMode | undefined): RuntimeGate {
|
|
51
|
+
return runtimeModeFor(mode) === "off" ? RUNTIME_GATE_DISABLED : RUNTIME_GATE_ENABLED
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Dependency runtime — hanya dibutuhkan bila gate terbuka. */
|
|
55
|
+
export type ProductionRuntimeDeps = Omit<
|
|
56
|
+
RuntimeCompositionOptions,
|
|
57
|
+
"sessionId" | "workspaceCwd" | "journalPath"
|
|
58
|
+
> &
|
|
59
|
+
Pick<RuntimeCompositionOptions, "sessionId" | "workspaceCwd" | "journalPath">
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Handle yang dipegang produksi. Setiap metode AMAN saat gate tutup dan melaporkan
|
|
63
|
+
* `null`/`false` alih-alih melempar: pemanggil yang lupa memeriksa gate harus
|
|
64
|
+
* berakhir "tak terjadi apa-apa", bukan "runtime jalan karena error ditelan".
|
|
65
|
+
*/
|
|
66
|
+
export interface ProductionRuntimeHandle {
|
|
67
|
+
readonly enabled: boolean
|
|
68
|
+
/** True setelah komposisi benar-benar dibangun (bukan setelah gate di-check). */
|
|
69
|
+
readonly constructed: boolean
|
|
70
|
+
isClosed(): boolean
|
|
71
|
+
/** Komposisi milik sesi ini; `null` bila gate tutup. */
|
|
72
|
+
runtime(): RuntimeComposition | null
|
|
73
|
+
/** Drain + checkpoint jurnal; `null` bila gate tutup. */
|
|
74
|
+
flush(): Promise<RuntimeFlushReport | null>
|
|
75
|
+
/**
|
|
76
|
+
* Tutup runtime. Meneruskan SATU shutdown lifecycle ke composition (tak ada
|
|
77
|
+
* journal/host closure kedua di sini — pemilik closure tetap composition).
|
|
78
|
+
* Idempoten + concurrency-safe: pemanggil kedua menerima hasil yang SAMA.
|
|
79
|
+
* `null` hanya bila gate tutup (tidak ada yang harus ditutup).
|
|
80
|
+
*/
|
|
81
|
+
stop(): Promise<RuntimeShutdownResult | null>
|
|
82
|
+
/** Hasil shutdown terakhir; `null` bila belum ada / gate tutup. */
|
|
83
|
+
shutdownResult(): RuntimeShutdownResult | null
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Handle mati: hanya objek itself, tanpa journal/host/kernel/backend. */
|
|
87
|
+
function inertHandle(gate: RuntimeGate): ProductionRuntimeHandle {
|
|
88
|
+
return {
|
|
89
|
+
enabled: gate.enabled,
|
|
90
|
+
constructed: false,
|
|
91
|
+
isClosed: () => true,
|
|
92
|
+
runtime: () => null,
|
|
93
|
+
flush: () => Promise.resolve(null),
|
|
94
|
+
stop: () => Promise.resolve(null),
|
|
95
|
+
shutdownResult: () => null,
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Path jurnal runtime: workspace-LOCAL (`.minicode/`), satu berkas per identitas
|
|
101
|
+
* sesi. Dua aturan yang dijaga di sini:
|
|
102
|
+
* - Path berasal dari identitas yang DIBERIKAN caller (resume memakai identitas
|
|
103
|
+
* sesi yang di-resume), tak pernah dari acak — resume harus menemukan jurnal
|
|
104
|
+
* lamanya, bukan membuat jurnal baru yang kosong.
|
|
105
|
+
* - `..`, separator, dan NUL DITOLAK fail-closed: nama berkas dari identitas
|
|
106
|
+
* tak boleh pernah bisa keluar dari `.minicode/`.
|
|
107
|
+
*/
|
|
108
|
+
export function runtimeJournalPath(cwd: string, identity: string): string {
|
|
109
|
+
if (typeof identity !== "string" || identity.length === 0)
|
|
110
|
+
throw new Error("production-runtime: identity is required (never derived here)")
|
|
111
|
+
if (identity.includes("..") || /[/\\\0]/.test(identity))
|
|
112
|
+
throw new Error("production-runtime: identity must not contain path separators or '..'")
|
|
113
|
+
const safe = identity.replace(/[^A-Za-z0-9._-]/g, "-").slice(0, 64)
|
|
114
|
+
if (safe.length === 0) throw new Error("production-runtime: identity has no usable characters")
|
|
115
|
+
return resolveLocalDbPath(`runtime-journal-${safe}.db`, cwd)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* THE PRODUCTION COMPOSITION ROOT untuk runtime P1.
|
|
120
|
+
*
|
|
121
|
+
* `deps` adalah THUNK dan hanya dipanggil saat gate terbuka — itulah yang membuat
|
|
122
|
+
* mode default benar-benar bebas (tak ada journal, tak ada host, tak ada event).
|
|
123
|
+
*/
|
|
124
|
+
export async function createProductionRuntime(
|
|
125
|
+
gate: RuntimeGate,
|
|
126
|
+
deps: () => ProductionRuntimeDeps | Promise<ProductionRuntimeDeps>,
|
|
127
|
+
): Promise<ProductionRuntimeHandle> {
|
|
128
|
+
if (!gate.enabled) return inertHandle(gate)
|
|
129
|
+
|
|
130
|
+
const d = await deps()
|
|
131
|
+
// Konstruksi gagal (jurnal tak bisa dibuka) = fail-closed propagasi ke pemanggil:
|
|
132
|
+
// runtime tanpa durability bukan runtime, dan diam-diam berjalan tanpa history
|
|
133
|
+
// adalah kegagalan yang jauh lebih mahal daripada cli yang gagal start.
|
|
134
|
+
const runtime = createRuntimeComposition(d)
|
|
135
|
+
|
|
136
|
+
const handle: ProductionRuntimeHandle = {
|
|
137
|
+
enabled: true,
|
|
138
|
+
constructed: true,
|
|
139
|
+
isClosed: () => runtime.isClosed(),
|
|
140
|
+
runtime: () => runtime,
|
|
141
|
+
flush: () => runtime.flush(),
|
|
142
|
+
// Delegasi murni: SATU pemilik closure tetap composition, dan promise yang
|
|
143
|
+
// sama dikembalikan ke semua pemanggil (tak ada flush/close kedua).
|
|
144
|
+
stop: () => runtime.shutdown(),
|
|
145
|
+
shutdownResult: () => runtime.shutdownResult(),
|
|
146
|
+
}
|
|
147
|
+
return handle
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// ── P13.1 — Jembatan handle produksi → fakta kontrak status runtime ─────────
|
|
151
|
+
//
|
|
152
|
+
// Kenapa jembatan ini di lapisan runtime: hanya pemilik handle yang boleh
|
|
153
|
+
// membaca state nyata runtime. Kalau CLI/daemon menghitung statusnya sendiri,
|
|
154
|
+
// kita kembali ke N sumber status (persis dual-authority yang dilarang).
|
|
155
|
+
//
|
|
156
|
+
// Yang DIAMBIL dari handle (fakta nyata, bukan dugaan):
|
|
157
|
+
// - gate/constructed/closed: langsung dari handle.
|
|
158
|
+
// - `journalWritable`: jurnal durable = `composition.durable` (jurnal benar-benar
|
|
159
|
+
// dibuka saat konstruksi — konstruksi gagal mempropagasi error), dan tak ada
|
|
160
|
+
// append yang gagal pada incarnation ini (`journalAppendFailures`).
|
|
161
|
+
// - admission tertutup (`isAdmissionOpen()`): membedakan "masih melayani" dari
|
|
162
|
+
// "sedang berhenti" — handle saja tak bisa membedakan keduanya.
|
|
163
|
+
//
|
|
164
|
+
// Yang TIDAK boleh ditebak: keberadaan scheduler/TaskStore (milik lapisan task)
|
|
165
|
+
// dan supervisor (belum terpasang produksi pada P13.1). Kalau pemanggil tak
|
|
166
|
+
// menyediakannya, nilainya `null` = belum diketahui → fail-closed, bukan "besar".
|
|
167
|
+
|
|
168
|
+
/** Fakta dari lapisan lain yang tak bisa dibaca runtime (lapisan task). */
|
|
169
|
+
export interface ProductionRuntimeObservation {
|
|
170
|
+
/** Scheduler terpasang? `null` = belum diketahui. */
|
|
171
|
+
readonly schedulerAttached?: boolean | null
|
|
172
|
+
/** TaskStore otoritas task terbuka? `null` = belum diketahui. */
|
|
173
|
+
readonly storeOpen?: boolean | null
|
|
174
|
+
/** Hasil drain terakhir, bila composition root sudah menangkapnya. */
|
|
175
|
+
readonly lastFlush?: RuntimeFlushReport | null
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export type { ProductionRuntimeFactsInput, TaskLayerFacts } from "./runtime-status-facts.ts"
|
|
179
|
+
export { runtimeFactsFrom } from "./runtime-status-facts.ts"
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Turunkan fakta kontrak dari handle produksi.
|
|
183
|
+
*
|
|
184
|
+
* Murni: tidak mengubah apa pun pada runtime. `flush()` TIDAK dipanggil di
|
|
185
|
+
* sini — flush adalah operasi drain, bukan probe; memanggilnya dari jalur
|
|
186
|
+
* status akan memicu drain setiap kali status dibaca.
|
|
187
|
+
*
|
|
188
|
+
* Sumber kebenaran:(handle → composition). FAKTA runtime dibaca dari komposisi
|
|
189
|
+
* (satu-satunya pemilik state runtime); observation hanya menimpa fakta
|
|
190
|
+
* lapisan task (scheduler/TaskStore) yang memang tak bisa dibaca dari dalam.
|
|
191
|
+
*/
|
|
192
|
+
export function observeProductionRuntime(
|
|
193
|
+
handle: ProductionRuntimeHandle,
|
|
194
|
+
observation: ProductionRuntimeObservation = {},
|
|
195
|
+
): RuntimeFacts {
|
|
196
|
+
const runtime = handle.runtime()
|
|
197
|
+
if (!runtime) {
|
|
198
|
+
// Handle inert (gate tertutup): tak ada komposisi, jadi tak ada runtime.
|
|
199
|
+
return runtimeFactsFrom({
|
|
200
|
+
enabled: handle.enabled,
|
|
201
|
+
constructed: false,
|
|
202
|
+
closed: handle.isClosed(),
|
|
203
|
+
admissionOpen: false,
|
|
204
|
+
durable: false,
|
|
205
|
+
journalAppendFailures: 0,
|
|
206
|
+
pendingJournalAppends: 0,
|
|
207
|
+
supervisionEstablished: false,
|
|
208
|
+
supervisorAttached: false,
|
|
209
|
+
supervisedChildren: 0,
|
|
210
|
+
...observation,
|
|
211
|
+
})
|
|
212
|
+
}
|
|
213
|
+
return runtime.statusFacts({
|
|
214
|
+
schedulerAttached: observation.schedulerAttached ?? null,
|
|
215
|
+
storeOpen: observation.storeOpen ?? null,
|
|
216
|
+
})
|
|
217
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Recovery safety contract: SATU definisi kanonis predicate redispatch aman.
|
|
2
|
+
//
|
|
3
|
+
// Kenapa berkas ini ada (P1 M9→M12, §36): predicate awalnya diimplementasikan
|
|
4
|
+
// di supervisor.ts (konsumen mekanis). M12 membutuhkannya sebagai konsumen
|
|
5
|
+
// semantik. Dua copy = dua kebenaran yang dapat divergen — maka SATU modul
|
|
6
|
+
// netral ini memilikinya; supervisor mengimpor ulang (re-export compat).
|
|
7
|
+
// Isi dipindahkan VERBATIM dari supervisor.ts (tanpa perubahan semantik).
|
|
8
|
+
|
|
9
|
+
export interface RedispatchSafety {
|
|
10
|
+
readonly authorityHeld: boolean
|
|
11
|
+
readonly budgetRemaining: number | null
|
|
12
|
+
readonly deadlineRemainingMs: number | null
|
|
13
|
+
readonly effectDefinitelyNotStarted: boolean
|
|
14
|
+
readonly idempotent: boolean
|
|
15
|
+
readonly dedupeKeyPresent: boolean
|
|
16
|
+
readonly dedupeCheckPass: boolean
|
|
17
|
+
readonly verifierConfirmedNotExecuted: boolean
|
|
18
|
+
readonly evidenceRecorded: boolean
|
|
19
|
+
/**
|
|
20
|
+
* [Fase 2 / LOOP-INV-07] Tool berakhir UNKNOWN (mis. timeout): efek mungkin
|
|
21
|
+
* sudah terjadi dan tidak ada bukti yang membatalkannya. Predicate menolak
|
|
22
|
+
* redispatch otomatis APA PUN sebelum verifikasi, termasuk saat
|
|
23
|
+
* `effectDefinitelyNotStarted` diklaim benar — dua sinyal yang bertentangan
|
|
24
|
+
* tidak boleh diselesaikan demi izin.
|
|
25
|
+
*/
|
|
26
|
+
readonly unknownToolOutcome?: boolean
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Predicate formal tunggal:
|
|
31
|
+
* re_dispatch ⟺ authority && budget && deadline &&
|
|
32
|
+
* (not-started || (idempotent && key && check) || (verifier-confirm && evidence)).
|
|
33
|
+
* Selain itu = NO automatic re-dispatch (UNKNOWN default aman).
|
|
34
|
+
*/
|
|
35
|
+
export function isRedispatchAllowed(safety: RedispatchSafety): boolean {
|
|
36
|
+
if (!safety.authorityHeld) return false
|
|
37
|
+
// [P1 Hygiene F2] Non-finite = invalid, bukan "available": `NaN <= 0` adalah
|
|
38
|
+
// false (lolos diam-diam) dan +Infinity bukan bukti pagu. null tetap berarti
|
|
39
|
+
// unbounded (kontrak yang sudah ada); <= 0 tetap berarti exhausted.
|
|
40
|
+
if (
|
|
41
|
+
safety.budgetRemaining !== null &&
|
|
42
|
+
(!Number.isFinite(safety.budgetRemaining) || safety.budgetRemaining <= 0)
|
|
43
|
+
)
|
|
44
|
+
return false
|
|
45
|
+
if (
|
|
46
|
+
safety.deadlineRemainingMs !== null &&
|
|
47
|
+
(!Number.isFinite(safety.deadlineRemainingMs) || safety.deadlineRemainingMs <= 0)
|
|
48
|
+
)
|
|
49
|
+
return false
|
|
50
|
+
// UNKNOWN mengalahkan seluruh disjunct izin di bawah: hasil tool yang ambigu
|
|
51
|
+
// bukan bukti "belum terjadi", dan retry buta pada efek yang mungkin sudah
|
|
52
|
+
// berjalan adalah persis kelas bug yang ditutup Fase 2.
|
|
53
|
+
if (safety.unknownToolOutcome === true) return false
|
|
54
|
+
if (safety.effectDefinitelyNotStarted) return true
|
|
55
|
+
if (hasDedupeProof(safety)) return true
|
|
56
|
+
if (safety.verifierConfirmedNotExecuted && safety.evidenceRecorded) return true
|
|
57
|
+
return false
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* [P1 M16] Salah satu disjunct di atas, diekstrak karena M12 sering butuh penilaian yang sama dengan framing
|
|
62
|
+
* TERBALIK ("belum ada bukti bahwa efek tidak terjadi?"). Tanpa helper ini, tiga
|
|
63
|
+
* syarat itu ditulis ulang inline di M12 — salinan yang bisa melenceng diam-diam
|
|
64
|
+
* dari predicate.
|
|
65
|
+
*/
|
|
66
|
+
export function hasDedupeProof(
|
|
67
|
+
safety: Pick<RedispatchSafety, "idempotent" | "dedupeKeyPresent" | "dedupeCheckPass">,
|
|
68
|
+
): boolean {
|
|
69
|
+
return safety.idempotent && safety.dedupeKeyPresent && safety.dedupeCheckPass
|
|
70
|
+
}
|