minicode-ai 0.11.0 → 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 +98 -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 -66
- 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 +17 -7
- 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 +54 -18
- package/src/ui/i18n/en.ts +62 -6
- package/src/ui/i18n/id.ts +62 -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 +598 -133
- 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 -165
- package/docs/USAGE.md +0 -11
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
// P13.3 Stage A — Fakta runtime: TIPE + satu pemetaan murni, dipakai beberapa
|
|
2
|
+
// pemanggil.
|
|
3
|
+
//
|
|
4
|
+
// Kenapa modul netral: pemetaan "state runtime → fakta kontrak" dibutuhkan
|
|
5
|
+
// oleh (a) composition (yang tahu state internalnya) dan (b) production-runtime
|
|
6
|
+
// (yang memegang handle). Meletakkannya di salah satu dari keduanya membuat
|
|
7
|
+
// siklus import, jadi ia diletakkan di modul ini — tanpa state, tanpa I/O.
|
|
8
|
+
//
|
|
9
|
+
// Modul ini juga jadi pemilik TIPE fakta (RuntimeFacts/RuntimeEvidence) dan
|
|
10
|
+
// bentuk hasil drain (RuntimeFlushReport), supaya `runtime-status.ts` tak perlu
|
|
11
|
+
// mengimpor `composition.ts` — dan dengan begitu graf import src/runtime/**
|
|
12
|
+
// tetap bebas siklus (guard m16 G1).
|
|
13
|
+
//
|
|
14
|
+
// Murni: semua primitif masuk lewat argumen. Tidak ada jam internal, tidak ada
|
|
15
|
+
// sumber data tersembunyi.
|
|
16
|
+
|
|
17
|
+
import type { HaltReason } from "../daemon/protocol.ts"
|
|
18
|
+
import type { FlushResult } from "./execution-journal.ts"
|
|
19
|
+
import type { RuntimeAttachment } from "./runtime-capabilities.ts"
|
|
20
|
+
import type { FailureClassification } from "./supervisor.ts"
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Bentuk hasil drain jurnal runtime.
|
|
24
|
+
*
|
|
25
|
+
* PADA: bentuk "drain selesai + berapa append yangnyelesai" — BUKAN probe
|
|
26
|
+
* readiness. Keberadaan drain yang berhasil tak berarti persistence-nya utuh
|
|
27
|
+
* saat ini (dan sebaliknya, drain yang belum jalan tak berarti persistence-nya
|
|
28
|
+
* rusak) — dua hal yang beda, jadi bentuknya dipisah dari bukti readiness.
|
|
29
|
+
*/
|
|
30
|
+
export interface RuntimeFlushReport {
|
|
31
|
+
readonly journal: FlushResult["status"] | "disabled"
|
|
32
|
+
/** Append yang sudah selesai pada drain ini. */
|
|
33
|
+
readonly drained: number
|
|
34
|
+
/** Append yang MASIH jalan saat batas drain tercapai (dilaporkan, bukan didiamkan). */
|
|
35
|
+
readonly unfinished: number
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Status flush jurnal (dipakai laporan drain di atas). */
|
|
39
|
+
export type { FlushResult }
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Bukti operative runtime.
|
|
43
|
+
*
|
|
44
|
+
* Tri-state: `true` = terverifikasi ada, `false` = terverifikasi tidak ada,
|
|
45
|
+
* `null` = belum diketahui. `null` tak pernah berarti "boleh" — ia berarti
|
|
46
|
+
* "belum boleh", karena bukti yang tak ada tak bisa menopang keputusan.
|
|
47
|
+
*/
|
|
48
|
+
export interface RuntimeEvidence {
|
|
49
|
+
/** Gate runtime terbuka (konfigurasi mengaktifkan runtime). */
|
|
50
|
+
readonly gateEnabled: boolean
|
|
51
|
+
/** Runtime benar-benar dibangun (komposisi selesai). */
|
|
52
|
+
readonly constructed: boolean
|
|
53
|
+
/** Runtime sudah ditutup (composition.close selesai). */
|
|
54
|
+
readonly closed: boolean
|
|
55
|
+
/**
|
|
56
|
+
* Bukti persistence: jurnal durable terbuka DAN tak ada append gagal pada
|
|
57
|
+
* incarnation ini. `null` = belum diketahui.
|
|
58
|
+
*/
|
|
59
|
+
readonly journalWritable: boolean | null
|
|
60
|
+
/** Bukti storage: TaskStore otoritas task bisa dibuka. `null` = belum diketahui. */
|
|
61
|
+
readonly storeOpen: boolean | null
|
|
62
|
+
/** Scheduler terpasang. `null` = belum diketahui. */
|
|
63
|
+
readonly schedulerAttached: boolean | null
|
|
64
|
+
/**
|
|
65
|
+
* Supervisor terpasang. `null` = belum ada kemampuan diklaim (P13.1: proses
|
|
66
|
+
* anak belum disupervisi — lihat runtime-capabilities.ts).
|
|
67
|
+
*/
|
|
68
|
+
readonly supervisorAttached: boolean | null
|
|
69
|
+
/**
|
|
70
|
+
* Supervisi proses DIHARAPKAN runtime ini (komposisi dikonfigurasi untuk
|
|
71
|
+
* supervisi) tapi TIDAK tersedia: establishment gagal, atau recovery
|
|
72
|
+
* kehabisan percobaan. Runtime jadi DEGRADED — bukan HEALTHY — dan
|
|
73
|
+
* kapabilitas `process-supervision` TIDAK diiklankan (tak ada yang diklaim
|
|
74
|
+
* punya). Tanpa medan ini, kegagalan establishment akan terlihat sebagai
|
|
75
|
+
* runtime yang sehat-normal.
|
|
76
|
+
*/
|
|
77
|
+
readonly supervisionExpected: boolean
|
|
78
|
+
/** Append jurnal yang belum selesai (proxy pekerjaan yang menunggu checkpoint). */
|
|
79
|
+
readonly pendingJournalAppends: number
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Fakta runtime yang diturunkan dari state nyata (input kontrak status). */
|
|
83
|
+
export interface RuntimeFacts {
|
|
84
|
+
/** Fase lifecycle runtime. */
|
|
85
|
+
readonly phase: RuntimePhase
|
|
86
|
+
/** Terminasi: apa yang terjadi pada runtime ini. */
|
|
87
|
+
readonly termination: RuntimeTermination
|
|
88
|
+
/** Alasan halt — HANYA sah bila termination = REQUESTED | HALTED. */
|
|
89
|
+
readonly haltReason?: HaltReason
|
|
90
|
+
/** Penyebab kegagalan — HANYA sah bila termination = FAILED. */
|
|
91
|
+
readonly failure?: FailureClassification
|
|
92
|
+
/** Bukti operative. */
|
|
93
|
+
readonly evidence: RuntimeEvidence
|
|
94
|
+
/** Fakta pemasangan (dasar deklarasi kapabilitas). */
|
|
95
|
+
readonly attachment: RuntimeAttachment
|
|
96
|
+
/**
|
|
97
|
+
* Jumlah anak proses yang tercatat di jalur ownership proses runtime.
|
|
98
|
+
*
|
|
99
|
+
* INI BEDA dari kapabilitas `process-supervision`: kapabilitas berarti "jalur
|
|
100
|
+
* supervisi terpasang", angka ini berarti "ada anak yang tercatat". Runtime
|
|
101
|
+
* dengan jalur terpasang tapi tanpa anak (mis. belum ada LSP yang dikonfigurasi)
|
|
102
|
+
* tetap healthy: ia siap menerima kerja, hanya tak ada proses anak yang
|
|
103
|
+
* dikuasai. Tanpa pemisahan ini, pembaca status bisa salah menyimpulkan
|
|
104
|
+
* "runtime sudah menjalankan proses" dari sekadar melihat kapabilitasnya.
|
|
105
|
+
*/
|
|
106
|
+
readonly supervisedChildren: number
|
|
107
|
+
/** Hasil drain terakhir. BUKAN bukti readiness. */
|
|
108
|
+
readonly lastFlush?: RuntimeFlushReport | null
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Fase lifecycle runtime. BUKAN `SchedulerState` — scheduler punya IDLE/RUNNING sendiri. */
|
|
112
|
+
export type RuntimePhase = "ABSENT" | "STARTING" | "ACTIVE" | "STOPPING" | "STOPPED"
|
|
113
|
+
|
|
114
|
+
/** Terminasi runtime: `REQUESTED` ≠ `HALTED` (halt diminta vs selesai). */
|
|
115
|
+
export type RuntimeTermination = "NONE" | "REQUESTED" | "HALTED" | "FAILED"
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Fakta lapisan TASK (scheduler/TaskStore).
|
|
119
|
+
*
|
|
120
|
+
* Lapisan task dimiliki lapisan task (`src/task/`); runtime tidak menebak
|
|
121
|
+
* keberadaannya. Yang tidak diketahui dilaporkan `null` (belum diketahui), bukan
|
|
122
|
+
* `false` (dinyatakan tidak ada) — dua hal yang beda dan tak boleh dicampur.
|
|
123
|
+
*/
|
|
124
|
+
export interface TaskLayerFacts {
|
|
125
|
+
/** Scheduler terpasang? `null` = belum diketahui. */
|
|
126
|
+
readonly schedulerAttached: boolean | null
|
|
127
|
+
/** TaskStore otoritas task terbuka? `null` = belum diketahui. */
|
|
128
|
+
readonly storeOpen: boolean | null
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Fakta mentah runtime — semua primitif, tanpa handle (inti murni). */
|
|
132
|
+
export interface ProductionRuntimeFactsInput {
|
|
133
|
+
readonly enabled: boolean
|
|
134
|
+
readonly constructed: boolean
|
|
135
|
+
readonly closed: boolean
|
|
136
|
+
/** Admission runtime masih terbuka (belum masuk drain shutdown). */
|
|
137
|
+
readonly admissionOpen: boolean
|
|
138
|
+
/** Runtime punya jurnal durable. */
|
|
139
|
+
readonly durable: boolean
|
|
140
|
+
/** Append jurnal yang gagal pada incarnation ini. */
|
|
141
|
+
readonly journalAppendFailures: number
|
|
142
|
+
/** Append jurnal yang belum selesai. */
|
|
143
|
+
readonly pendingJournalAppends: number
|
|
144
|
+
/**
|
|
145
|
+
* Supervisi proses ATTACHED? true = instance supervisi benar-benar ada
|
|
146
|
+
* (attachment valid → kapabilitas boleh diiklankan). false = establishment
|
|
147
|
+
* gagal → tak ada yang boleh mengklaim punya.
|
|
148
|
+
*/
|
|
149
|
+
readonly supervisionEstablished: boolean
|
|
150
|
+
/**
|
|
151
|
+
* Supervisi proses OPERATIONAL? false = establishment GAGAL atau recovery
|
|
152
|
+
* kehabisan percobaan (supervisi sudah ada tapi tak lagi bisa bekerja).
|
|
153
|
+
*/
|
|
154
|
+
readonly supervisorAttached: boolean
|
|
155
|
+
/** Jumlah anak proses yang tercatat di jalur ownership proses. */
|
|
156
|
+
readonly supervisedChildren: number
|
|
157
|
+
readonly schedulerAttached?: boolean | null
|
|
158
|
+
readonly storeOpen?: boolean | null
|
|
159
|
+
/** Hasil drain terakhir (BUKAN bukti readiness — lihat RuntimeFacts). */
|
|
160
|
+
readonly lastFlush?: RuntimeFlushReport | null
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Inti murni jembatan: fakta mentah → fakta kontrak.
|
|
165
|
+
*
|
|
166
|
+
* Dipisah dari pembacaan handle supaya pemetaan fase/terminasi bisa diuji
|
|
167
|
+
* tanpa membangun runtime sungguhan (deterministik, tanpa I/O).
|
|
168
|
+
*/
|
|
169
|
+
export function runtimeFactsFrom(input: ProductionRuntimeFactsInput): RuntimeFacts {
|
|
170
|
+
let phase: RuntimePhase
|
|
171
|
+
if (!input.enabled) phase = "ABSENT"
|
|
172
|
+
else if (!input.constructed) phase = "STARTING"
|
|
173
|
+
else if (input.closed) phase = "STOPPED"
|
|
174
|
+
else if (!input.admissionOpen) phase = "STOPPING"
|
|
175
|
+
else phase = "ACTIVE"
|
|
176
|
+
|
|
177
|
+
let termination: RuntimeTermination = "NONE"
|
|
178
|
+
let haltReason: HaltReason | undefined
|
|
179
|
+
if (phase === "STOPPING") {
|
|
180
|
+
// Halt DIMINTA, belum selesai — bukan "HALTED" (yang berarti sudah stop).
|
|
181
|
+
termination = "REQUESTED"
|
|
182
|
+
haltReason = "SHUTTING_DOWN"
|
|
183
|
+
} else if (phase === "STOPPED") {
|
|
184
|
+
termination = "HALTED"
|
|
185
|
+
haltReason = "SHUTTING_DOWN"
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const attachment: RuntimeAttachment = {
|
|
189
|
+
journal: input.durable,
|
|
190
|
+
taskStore: input.storeOpen === true,
|
|
191
|
+
scheduler: input.schedulerAttached === true,
|
|
192
|
+
// Kapabilitas diiklankan HANYA setelah attachment VALID: instance supervisi
|
|
193
|
+
// benar-benar ada. Establishment yang GAGAL → tak diiklankan (tak ada yang
|
|
194
|
+
// boleh mengklaim punya), dan runtime jadi DEGRADED lewat bukti
|
|
195
|
+
// `supervisionExpected`.
|
|
196
|
+
supervisor: input.supervisionEstablished,
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const evidence: RuntimeEvidence = {
|
|
200
|
+
gateEnabled: input.enabled,
|
|
201
|
+
constructed: input.constructed,
|
|
202
|
+
closed: input.closed,
|
|
203
|
+
journalWritable: input.durable ? input.journalAppendFailures === 0 : null,
|
|
204
|
+
storeOpen: input.storeOpen ?? null,
|
|
205
|
+
schedulerAttached: input.schedulerAttached ?? null,
|
|
206
|
+
supervisorAttached: input.supervisorAttached,
|
|
207
|
+
// Runtime yang punya komposisi SELALU dikonfigurasi untuk supervisi
|
|
208
|
+
// (P13.2) — jadi supervisi yang hilang = degradation, bukan "tak relevan".
|
|
209
|
+
supervisionExpected: input.constructed,
|
|
210
|
+
pendingJournalAppends: input.pendingJournalAppends,
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return {
|
|
214
|
+
phase,
|
|
215
|
+
termination,
|
|
216
|
+
...(haltReason !== undefined ? { haltReason } : {}),
|
|
217
|
+
evidence,
|
|
218
|
+
attachment,
|
|
219
|
+
supervisedChildren: input.supervisedChildren,
|
|
220
|
+
...(input.lastFlush !== undefined ? { lastFlush: input.lastFlush } : {}),
|
|
221
|
+
}
|
|
222
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// P13.1 — Seam DI status runtime: SATU sumber status untuk daemon & CLI.
|
|
2
|
+
//
|
|
3
|
+
// Kenapa berkas ini ada: model status runtime (runtime-status.ts) murni, tapi
|
|
4
|
+
// konsumennya (CLI, daemon) butuh "status runtime SEKARANG" tanpa masing-masing
|
|
5
|
+
// membangun runtime sendiri. Tanpa seam ini, tiap konsumen akan menghitung
|
|
6
|
+
// statusnya sendiri — itu persis dual-authority yang dilarang repo ini.
|
|
7
|
+
//
|
|
8
|
+
// Pola yang dipakai sama dengan DI lain repo ini (mis. `setSubAgentExecutionRunner`):
|
|
9
|
+
// composition root memasang penyedia, konsumen membaca. Tanpa pemasang, pembaca
|
|
10
|
+
// mendapat view ABSENT kanonik — bukan error dan bukan tebakan.
|
|
11
|
+
//
|
|
12
|
+
// CATATAN: ini BUKAN state runtime. Yang di sini hanya cara meng-query status.
|
|
13
|
+
// Kalau sembarang pihak menulis ke sini, status yang tampil bukan status runtime
|
|
14
|
+
// itu. Penulis tunggal: composition root.
|
|
15
|
+
|
|
16
|
+
import { deriveRuntimeView, type RuntimeFacts, type RuntimeView } from "./runtime-status.ts"
|
|
17
|
+
|
|
18
|
+
/** Penyedia status runtime: mengembalikan view kanonik saat ini. */
|
|
19
|
+
export type RuntimeStatusProvider = () => RuntimeView
|
|
20
|
+
|
|
21
|
+
let provider: RuntimeStatusProvider | null = null
|
|
22
|
+
|
|
23
|
+
/** Pasang penyedia status (composition root). `null` melepas pemasangan. */
|
|
24
|
+
export function installRuntimeStatusProvider(next: RuntimeStatusProvider | null): void {
|
|
25
|
+
provider = next
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* View ABSENT kanonik — dipakai saat tak ada runtime terpasang.
|
|
30
|
+
*
|
|
31
|
+
* `closed: true` konsisten dengan handle inert produksi (`isClosed()` selalu
|
|
32
|
+
* true saat gate tertutup), jadi view ini bukan kondisi aneh tapi keadaan
|
|
33
|
+
* normal proses yang memang tak menjalankan runtime.
|
|
34
|
+
*/
|
|
35
|
+
export function absentRuntimeView(note?: string): RuntimeView {
|
|
36
|
+
const facts: RuntimeFacts = {
|
|
37
|
+
phase: "ABSENT",
|
|
38
|
+
termination: "NONE",
|
|
39
|
+
evidence: {
|
|
40
|
+
gateEnabled: false,
|
|
41
|
+
constructed: false,
|
|
42
|
+
closed: true,
|
|
43
|
+
journalWritable: null,
|
|
44
|
+
storeOpen: null,
|
|
45
|
+
schedulerAttached: null,
|
|
46
|
+
supervisorAttached: null,
|
|
47
|
+
// Tak ada runtime ⇒ tak ada supervisi yang diharapkan (bukan "supervisi
|
|
48
|
+
// hilang" — runtime-nya memang tak ada).
|
|
49
|
+
supervisionExpected: false,
|
|
50
|
+
pendingJournalAppends: 0,
|
|
51
|
+
},
|
|
52
|
+
attachment: { journal: false, taskStore: false, scheduler: false, supervisor: false },
|
|
53
|
+
supervisedChildren: 0,
|
|
54
|
+
}
|
|
55
|
+
const view = deriveRuntimeView(facts)
|
|
56
|
+
return note === undefined ? view : { ...view, note }
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* View runtime saat ini.
|
|
61
|
+
*
|
|
62
|
+
* Tak pernah melempar: konsumen status (CLI/daemon) lebih baik melihat
|
|
63
|
+
* "tidak ada runtime" daripada ikut mati karena penyedia-nya salah. Kegagalan
|
|
64
|
+
* penyedia dilaporkan lewat `note`, bukan lewat exception.
|
|
65
|
+
*/
|
|
66
|
+
export function currentRuntimeView(): RuntimeView {
|
|
67
|
+
if (!provider) return absentRuntimeView("tak ada runtime terpasang pada proses ini")
|
|
68
|
+
try {
|
|
69
|
+
return provider()
|
|
70
|
+
} catch (e) {
|
|
71
|
+
const reason = e instanceof Error ? e.message : String(e)
|
|
72
|
+
return absentRuntimeView(`penyedia status runtime gagal: ${reason}`)
|
|
73
|
+
}
|
|
74
|
+
}
|