minicode-ai 0.13.0 → 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 +23 -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/minicode.js +6 -0
- 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 +3 -2
- 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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.14.0] - 2026-11-05
|
|
4
|
+
|
|
5
|
+
### WorkMode, observability, reliability & repository consolidation (P0–P2 + P2.3)
|
|
6
|
+
|
|
7
|
+
Integrasi tahap **P0–P2** dan penutupan **P2.3**, lalu **Final Integration & Repository Consolidation**. Detail stage-scoped per subfase ada di `docs/audit/` (P0_FOUNDATION…, P1_…, P2_OPERATIONAL_…, P2_3_OPERATIONAL_…, FINAL_INTEGRATION_…).
|
|
8
|
+
|
|
9
|
+
- **P0 — Kontrak WorkMode** (`DISCUSS`/`PLAN`/`EXECUTE`, lapis intent terpisah dari PermissionMode): registry/dispatch selaras agar tool yang terlihat = yang dapat dieksekusi; network read dilarang di `DISCUSS` dan butuh approval di `PLAN`; hooks/verify digerbangi WorkMode; persistensi & resume WorkMode; parity `daemon`/`ACP`/`exec`.
|
|
10
|
+
- **P1 — Correctness & operator UX**: validasi `supersedes_id` + tombstone dua-arah seluruh chunk memori (tanpa resurrection via reconcile); machine/task observability dengan identitas child-session/run; ACE/verification/denial visibility di TUI; context occupancy ≠ session spend; approval binding dua lapis + `always` hanya bila dapat dipersist; proyeksi error context-window dan peringatan flag setelah prompt.
|
|
11
|
+
- **P2 — State/type & performance**: decoder durable ber-versi `v:1` (fail-safe untuk versi masa depan/payload rusak); keputusan single-session; katalog ownership state; MCP schema-pin **persisten** + pagination + multi-session refcount; daemon `run.interrupt/cancel` nyata + replay backpressure resumable; cache proyeksi transkrip (25–140×) dan index `order` reducer (~30×).
|
|
12
|
+
- **P2.3 — Lifecycle closure**: MCP **bounded reconnect** (retry limit/backoff/jitter/single-flight; pin diverifikasi ulang, drift tetap fail-closed); status recovery daemon untuk run yatim (`INTERRUPTED`/`UNKNOWN`, tanpa auto-resume); producer transisi task **authoritative** (create/update/claim/merge-cancel); guard **single-session** di boundary run; quarantine (bukan fuzzy delete) untuk baris memori legacy yang ambigu.
|
|
13
|
+
- **Feature gates/bench**: audit harness, gate bash, benchmark smoke/render, dan PTY suite tetap hijau. **Keterbatasan terdokumentasi**: subscriptions/notifications MCP belum didukung; `FAILED`/`RETRYING` belum punya producer (keputusan produk); daemon tidak auto-resume; manual TUI UAT & gateway cache UNVERIFIED.
|
|
14
|
+
- **Budget ukuran paket** re-baseline **3.840 → 3.920 KiB** (ukuran aktual 3.902,6 KiB, 22/23 cek `gate:pack` lolos tanpa node_modules/test/secret ikut).
|
|
15
|
+
|
|
16
|
+
### Konsolidasi repository
|
|
17
|
+
|
|
18
|
+
- Peta dokumen kanonik + status fase aktif di `AGENTS.md`; koreksi budget & semantik sub-agent agar dokumen = implementasi; hapus artefak generated/temp (128 path) tanpa menghapus file historis/user-owned.
|
|
19
|
+
|
|
20
|
+
## [0.13.1] - 2026-11-01
|
|
21
|
+
|
|
22
|
+
### Fixed — bin distribusi `minicode`
|
|
23
|
+
|
|
24
|
+
- `bin` sebelumnya menunjuk `./cli/index.ts` dengan prefix `./`; npm me-normalisasi prefix itu dan melaporkan warning `"bin[minicode]" ... was invalid and removed` saat publish. `bin` kini menunjuk wrapper `.js` (`cli/minicode.js`, shebang `#!/usr/bin/env bun`) yang memuat `cli/index.ts` — tanpa prefix `./` dan berekstensi `.js` sehingga kompatibilitas bin npm lebih baik dan warning publish hilang. Gateway distribusi (`scripts/pack-check.ts`) diperluas agar menelusuri side-effect import sehingga graf `cli/index.ts` tetap terverifikasi sebelum publish.
|
|
25
|
+
|
|
3
26
|
## [0.13.0] - 2026-11-01
|
|
4
27
|
|
|
5
28
|
### Frontier Harness — 6 dimensi frontier terintegrasi penuh (Fase 1–12)
|
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 startupmini
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 startupmini
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -198,3 +198,7 @@ Catatan lingkungan:
|
|
|
198
198
|
**MIT License.** Bebas pakai, modifikasi, distribusi — lihat [LICENSE](LICENSE). Copyright (c) 2026 startupmini.
|
|
199
199
|
|
|
200
200
|
Lihat `docs/ARCHITECTURE.html` + `docs/HARNESS.md` + `ROADMAP.md` (roadmap arsitektur aktif) + `PLAN.md` (ledger legacy).
|
|
201
|
+
|
|
202
|
+
## Status proyek
|
|
203
|
+
|
|
204
|
+
Fase aktif: **Final Integration & Repository Consolidation** — P0–P2 dan penutupan P2.3 berada pada **stage-scoped closure** (tidak ada fase produk P3). Ringkasan kesehatan repository, temuan integrasi, cleanup, dan limitasi: `docs/audit/FINAL_INTEGRATION_AND_REPOSITORY_CONSOLIDATION_REPORT_2026-11-05.md`. Aturan agent dan peta dokumen kanonik: `AGENTS.md` (keduanya di repository, tidak ikut paket npm).
|
package/cli/args.ts
CHANGED
|
@@ -124,14 +124,20 @@ export function parseWorkModeValue(raw: string): CliWorkMode | undefined {
|
|
|
124
124
|
*/
|
|
125
125
|
export function resolveWorkModeFlag(getArg: (n: string) => string | undefined): {
|
|
126
126
|
workMode: CliWorkMode
|
|
127
|
+
/** Benar bila operator memberi sinyal WorkMode eksplisit (flag ATAU env),
|
|
128
|
+
* terlepas nilainya sah/tidak. Dipakai composition root untuk transparansi
|
|
129
|
+
* resume (D-2): WorkMode TIDAK dipersist, jadi resume tanpa sinyal eksplisit
|
|
130
|
+
* kembali ke EXECUTE dan diberi tahu satu baris. */
|
|
131
|
+
explicit: boolean
|
|
127
132
|
warning?: string
|
|
128
133
|
} {
|
|
129
134
|
const raw = getArg("--work-mode") ?? process.env.MINICODE_WORK_MODE
|
|
130
|
-
if (raw === undefined) return { workMode: "EXECUTE" }
|
|
135
|
+
if (raw === undefined) return { workMode: "EXECUTE", explicit: false }
|
|
131
136
|
const parsed = parseWorkModeValue(raw)
|
|
132
|
-
if (parsed) return { workMode: parsed }
|
|
137
|
+
if (parsed) return { workMode: parsed, explicit: true }
|
|
133
138
|
return {
|
|
134
139
|
workMode: "EXECUTE",
|
|
140
|
+
explicit: true,
|
|
135
141
|
warning: `--work-mode requires DISCUSS|PLAN|EXECUTE, ignoring "${raw}" (using EXECUTE)`,
|
|
136
142
|
}
|
|
137
143
|
}
|
|
@@ -213,6 +219,48 @@ export function promptFromArgs(argv: string[]): string {
|
|
|
213
219
|
return out.join(" ")
|
|
214
220
|
}
|
|
215
221
|
|
|
222
|
+
/**
|
|
223
|
+
* [Live Hardening 0.13.x §8.3/§7.1] Daftar flag YANG DIKENAL yang muncul SETELAH
|
|
224
|
+
* prompt boundary (kata prompt pertama, atau separator `--`). `promptFromArgs`
|
|
225
|
+
* sengaja menghentikan pemindaian flag pada boundary itu (pertahanan anti-injeksi),
|
|
226
|
+
* sehingga flag semacam itu menjadi bagian teks prompt — bukan flag yang diparse.
|
|
227
|
+
*
|
|
228
|
+
* Tanpa peringatan, operator yang mengetik `minicode "refactor" --work-mode PLAN`
|
|
229
|
+
* diam-diam menjalankan satu run tanpa work-mode yang diminta (kasus stage5: resume
|
|
230
|
+
* dibuang). Helper ini memurnikan deteksi agar CLI dapat memberi `[warn]` yang
|
|
231
|
+
* actionable. Nama flag di-dedupe menjaga urutan kemunculan; hanya flag dikenal
|
|
232
|
+
* yang dilaporkan (flag tak dikenal memang tak akan pernah dijalankan sebagai flag).
|
|
233
|
+
*/
|
|
234
|
+
export function flagsAfterPromptBoundary(argv: string[]): string[] {
|
|
235
|
+
const found: string[] = []
|
|
236
|
+
let afterBoundary = false
|
|
237
|
+
for (let i = 0; i < argv.length; i++) {
|
|
238
|
+
const a = argv[i]
|
|
239
|
+
if (a === undefined) break
|
|
240
|
+
if (a === "--") {
|
|
241
|
+
// Separator eksplisit: semua token setelahnya adalah prompt (flag pun).
|
|
242
|
+
afterBoundary = true
|
|
243
|
+
continue
|
|
244
|
+
}
|
|
245
|
+
if (afterBoundary) {
|
|
246
|
+
const f = flagNameOf(a)
|
|
247
|
+
if (f && !found.includes(f)) found.push(f)
|
|
248
|
+
continue
|
|
249
|
+
}
|
|
250
|
+
const fname = flagNameOf(a)
|
|
251
|
+
if (fname === null) {
|
|
252
|
+
// Token prompt pertama (bukan flag dikenal) → boundary di titik ini;
|
|
253
|
+
// token ini sendiri adalah prompt, bukan flag.
|
|
254
|
+
afterBoundary = true
|
|
255
|
+
continue
|
|
256
|
+
}
|
|
257
|
+
// Flag dikenal SEBELUM boundary: lewati flag + nilainya (bila value flag
|
|
258
|
+
// bentuk terpisah) persis seperti promptFromArgs.
|
|
259
|
+
if (valueFlags.has(fname) && !a.includes("=")) i++
|
|
260
|
+
}
|
|
261
|
+
return found
|
|
262
|
+
}
|
|
263
|
+
|
|
216
264
|
export function readPrompt(): Promise<string> {
|
|
217
265
|
if (process.stdin.isTTY) return Promise.resolve("")
|
|
218
266
|
return new Promise((resolve) => {
|
package/cli/commands/acp.ts
CHANGED
|
@@ -35,6 +35,7 @@ import { createCliSession } from "../setup.ts"
|
|
|
35
35
|
// <- {"type":"turn.started|completed|failed|cancelled",...} ...
|
|
36
36
|
// <- {"type":"file.changed|test.completed|diagnostic.raised|checkpoint.created",...} ...
|
|
37
37
|
// <- {"type":"plan.updated|finding.detected|result.produced|context.compacted",...} ...
|
|
38
|
+
// <- {"type":"task.status","taskId":"t1","status":"COMPLETED","parentId":"t0",...} ...
|
|
38
39
|
// <- {"id":2,"result":{"ok":true,"tokens":123,"steps":4,"turns":1,"text":"..."}}
|
|
39
40
|
// -> {"id":3,"method":"cancel"} (menggugurkan run yang berjalan)
|
|
40
41
|
// -> {"id":4,"method":"shutdown"} (keluar 0 setelah run selesai/dibatalkan)
|
|
@@ -119,9 +120,13 @@ export function parseRunParams(
|
|
|
119
120
|
const mode =
|
|
120
121
|
p.mode === undefined || p.mode === "auto" ? "auto" : p.mode === "plan" ? "plan" : null
|
|
121
122
|
if (mode === null) return { ok: false, error: 'params.mode must be "auto" or "plan"' }
|
|
122
|
-
// P12 S2.2
|
|
123
|
-
//
|
|
124
|
-
|
|
123
|
+
// P12 S2.2 + P0.2 (Q5) — WorkMode: params.workMode eksplisit mengalahkan env
|
|
124
|
+
// MINICODE_WORK_MODE; keduanya absen → EXECUTE. Nilai params.workMode yang
|
|
125
|
+
// invalid ditolak fail-closed (bukan diam melebar).
|
|
126
|
+
const envWmRaw = (process.env.MINICODE_WORK_MODE ?? "").trim().toUpperCase()
|
|
127
|
+
const envWorkMode =
|
|
128
|
+
envWmRaw === "DISCUSS" || envWmRaw === "PLAN" || envWmRaw === "EXECUTE" ? envWmRaw : "EXECUTE"
|
|
129
|
+
const wmRaw = p.workMode === undefined ? envWorkMode : String(p.workMode).toUpperCase()
|
|
125
130
|
const workMode =
|
|
126
131
|
wmRaw === "DISCUSS"
|
|
127
132
|
? "DISCUSS"
|
|
@@ -258,6 +263,15 @@ function projectAcpLifecycle(
|
|
|
258
263
|
...(event.parentToolCallId ? { parentToolCallId: event.parentToolCallId } : {}),
|
|
259
264
|
...(event.provenance ? { provenance: event.provenance } : {}),
|
|
260
265
|
}
|
|
266
|
+
if (event.type === "task.status")
|
|
267
|
+
return {
|
|
268
|
+
...base,
|
|
269
|
+
...(event.taskId ? { taskId: event.taskId } : {}),
|
|
270
|
+
...(event.taskStatus ? { status: event.taskStatus } : {}),
|
|
271
|
+
...(event.parentId ? { parentId: event.parentId } : {}),
|
|
272
|
+
...(event.dependsOn?.length ? { dependsOn: event.dependsOn } : {}),
|
|
273
|
+
...(event.revision !== undefined ? { revision: event.revision } : {}),
|
|
274
|
+
}
|
|
261
275
|
if (event.type === "diagnostic.raised")
|
|
262
276
|
return {
|
|
263
277
|
...base,
|
|
@@ -457,6 +471,7 @@ export async function runAcpSession(
|
|
|
457
471
|
ok: true,
|
|
458
472
|
sessionId: ctx.sessionId,
|
|
459
473
|
model: ctx.modelRef.current,
|
|
474
|
+
workMode: (ctx as { workMode?: string }).workMode ?? rp.workMode ?? "EXECUTE",
|
|
460
475
|
tokens: ue.totalTokens,
|
|
461
476
|
inputTokens: ue.inputTokens,
|
|
462
477
|
outputTokens: ue.outputTokens,
|
package/cli/commands/daemon.ts
CHANGED
|
@@ -18,12 +18,14 @@ import { createStoreFeed } from "../../src/daemon/feed.ts"
|
|
|
18
18
|
import type { DaemonHost } from "../../src/daemon/host.ts"
|
|
19
19
|
import { DAEMON_SCOPES, type DaemonScope } from "../../src/daemon/protocol.ts"
|
|
20
20
|
import { sanitizeLabel } from "../../src/daemon/sanitize.ts"
|
|
21
|
+
import { VerifyWorkModeConflictError, type WorkMode } from "../../src/policy/work-mode.ts"
|
|
21
22
|
import { DURABILITY } from "../../src/presentation/events.ts"
|
|
22
23
|
import {
|
|
23
24
|
type RuntimeProductionMode,
|
|
24
25
|
resolveRuntimeMode,
|
|
25
26
|
} from "../../src/runtime/production-execution.ts"
|
|
26
|
-
import {
|
|
27
|
+
import { listSessionRuns } from "../../src/session/persistence.ts"
|
|
28
|
+
import { flagNameOf, resolveWorkModeFlag, valueFlags } from "../args.ts"
|
|
27
29
|
import type { CliSession, CliSessionOptions } from "../setup.ts"
|
|
28
30
|
|
|
29
31
|
export async function handleDaemon(
|
|
@@ -88,7 +90,7 @@ export async function handleDaemon(
|
|
|
88
90
|
|
|
89
91
|
const DAEMON_HELP = `minicode daemon <mulai|status|stop|issue|sessions|help>
|
|
90
92
|
|
|
91
|
-
start [--port N] [--cwd D] [--prompt P] [--session S] [--runtime <mode>] [--json]
|
|
93
|
+
start [--port N] [--cwd D] [--prompt P] [--session S] [--runtime <mode>] [--work-mode <mode>] [--json]
|
|
92
94
|
Jalankan host daemon (blocking). Tanpa --prompt hanya melayani
|
|
93
95
|
konsumen; dengan --prompt sesi di-host di dalam proses daemon.
|
|
94
96
|
--runtime constructed|owned menyalakan runtime ter-supervisi pada
|
|
@@ -198,6 +200,12 @@ export async function startDaemonHostedRuntime(opts: {
|
|
|
198
200
|
* append sesungguhnya).
|
|
199
201
|
*/
|
|
200
202
|
readonly presentationAppend?: CliSessionOptions["presentationAppend"]
|
|
203
|
+
/**
|
|
204
|
+
* P2.3: jalankan `--prompt` yang di-host. Default false agar tes komposisi
|
|
205
|
+
* yang tidak ingin turn tetap deterministik; `startDaemon` (produksi)
|
|
206
|
+
* menyalakannya.
|
|
207
|
+
*/
|
|
208
|
+
readonly autoRunPrompt?: boolean
|
|
201
209
|
}): Promise<DaemonHostedRuntime> {
|
|
202
210
|
const { sub, getArg, cwd } = opts
|
|
203
211
|
const portRaw = getArg("--port")
|
|
@@ -212,6 +220,9 @@ export async function startDaemonHostedRuntime(opts: {
|
|
|
212
220
|
// [P13.3 Stage C] Scheduler mengikuti mode runtime, bukan flag terpisah:
|
|
213
221
|
// daemon `owned` memang ingin kerja durable berlanjut; mode lain tetap inert.
|
|
214
222
|
const schedulerEnabled = schedulerEnabledForDaemon(runtimeMode)
|
|
223
|
+
// P0.2 (Q5): parity WorkMode di daemon (`--work-mode` > `MINICODE_WORK_MODE`
|
|
224
|
+
// > default EXECUTE; invalid = EXECUTE + warning di startDaemon).
|
|
225
|
+
const workModeResolved = resolveWorkModeFlag(getArg)
|
|
215
226
|
|
|
216
227
|
const { DaemonHost } = await import("../../src/daemon/host.ts")
|
|
217
228
|
const feeds = new Map<string, SessionFeed>()
|
|
@@ -227,33 +238,51 @@ export async function startDaemonHostedRuntime(opts: {
|
|
|
227
238
|
// lifecycle sesi selesai — termasuk pembersihan anak proses yang disupervisi.
|
|
228
239
|
let sessionRef: CliSession | null = null
|
|
229
240
|
let sessionClosed = false
|
|
241
|
+
// P2.3: satu controller untuk run yang sedang berjalan. Interrupt/cancel
|
|
242
|
+
// meng-abort run ini (bukan hanya mengembalikan status palsu).
|
|
243
|
+
let activeRunCtl: AbortController | null = null
|
|
230
244
|
const closeHostedSession = async (): Promise<void> => {
|
|
231
245
|
if (sessionClosed) return
|
|
232
246
|
sessionClosed = true
|
|
247
|
+
try {
|
|
248
|
+
activeRunCtl?.abort(new Error("daemon shutdown"))
|
|
249
|
+
} catch {}
|
|
250
|
+
activeRunCtl = null
|
|
233
251
|
const s = sessionRef
|
|
234
252
|
sessionRef = null
|
|
235
253
|
if (!s) return
|
|
236
254
|
await s.close()
|
|
237
255
|
}
|
|
238
256
|
|
|
257
|
+
// P2.3: abort run yang benar-benar berjalan. runId dari state kanonik; call
|
|
258
|
+
// dengan runId lain ditolak agar sinyal tidak salah arah ke sesi/run lain.
|
|
259
|
+
const abortHostedRun = (
|
|
260
|
+
sid: string,
|
|
261
|
+
runId: string | null,
|
|
262
|
+
reason: string,
|
|
263
|
+
): { ok: true } | { ok: false; code: "RUN_TERMINAL" | "SESSION_MISMATCH"; message: string } => {
|
|
264
|
+
const s = sessionRef
|
|
265
|
+
if (!s || s.sessionId !== sid)
|
|
266
|
+
return { ok: false, code: "SESSION_MISMATCH", message: "sesi bukan milik daemon ini" }
|
|
267
|
+
const state = s.runState()
|
|
268
|
+
if (!state.runId || state.status !== "RUNNING")
|
|
269
|
+
return { ok: false, code: "RUN_TERMINAL", message: "tidak ada run aktif untuk dihentikan" }
|
|
270
|
+
if (runId !== null && runId !== state.runId)
|
|
271
|
+
return { ok: false, code: "RUN_TERMINAL", message: `run ${runId} bukan run aktif` }
|
|
272
|
+
if (!activeRunCtl || activeRunCtl.signal.aborted)
|
|
273
|
+
return { ok: false, code: "RUN_TERMINAL", message: "run tidak dapat diinterupsi" }
|
|
274
|
+
activeRunCtl.abort(new Error(reason))
|
|
275
|
+
return { ok: true }
|
|
276
|
+
}
|
|
277
|
+
|
|
239
278
|
// Aksi kontrol dibangun dari state yang benar-benar diketahui proses ini.
|
|
240
279
|
// Tanpa sesi yang di-host, operasi yang butuh aksi MENOLAK — bukan berpura-
|
|
241
280
|
// pura berhasil (lihat control.ts).
|
|
242
281
|
const actions: ControlActions = {
|
|
243
282
|
listSessions: () => [...hosted.values()],
|
|
244
283
|
sessionStatus: (sid) => hosted.get(sid) ?? null,
|
|
245
|
-
interrupt: (sid) =>
|
|
246
|
-
|
|
247
|
-
return { ok: false, code: "RUN_TERMINAL", message: "tidak ada jalur interupsi pada sesi ini" }
|
|
248
|
-
},
|
|
249
|
-
cancel: (sid) => {
|
|
250
|
-
void sid
|
|
251
|
-
return {
|
|
252
|
-
ok: false,
|
|
253
|
-
code: "RUN_TERMINAL",
|
|
254
|
-
message: "tidak ada jalur pembatalan pada sesi ini",
|
|
255
|
-
}
|
|
256
|
-
},
|
|
284
|
+
interrupt: (sid, runId) => abortHostedRun(sid, runId, "interrupted by daemon operator"),
|
|
285
|
+
cancel: (sid, runId) => abortHostedRun(sid, runId, "cancelled by daemon operator"),
|
|
257
286
|
shutdown: (reason) => {
|
|
258
287
|
const h = hostRef
|
|
259
288
|
if (!h) return
|
|
@@ -306,7 +335,9 @@ export async function startDaemonHostedRuntime(opts: {
|
|
|
306
335
|
}),
|
|
307
336
|
plan: false,
|
|
308
337
|
allowlist: false,
|
|
309
|
-
verify:
|
|
338
|
+
verify: sub.includes("--verify"),
|
|
339
|
+
workMode: workModeResolved.workMode,
|
|
340
|
+
workModeExplicit: workModeResolved.explicit,
|
|
310
341
|
// [P13.2] Mode runtime yang sama dengan CLI → komposisi yang di-host
|
|
311
342
|
// punya jalur ownership proses + status kanonik yang sama.
|
|
312
343
|
runtimeMode,
|
|
@@ -355,13 +386,62 @@ export async function startDaemonHostedRuntime(opts: {
|
|
|
355
386
|
sid: session.sessionId,
|
|
356
387
|
hosted: true,
|
|
357
388
|
writerEpoch: session.writerEpoch,
|
|
358
|
-
|
|
359
|
-
|
|
389
|
+
// P2.3: status dibaca LIVE dari run kanonik sesi, bukan snapshot null.
|
|
390
|
+
get runId() {
|
|
391
|
+
return session.runState().runId
|
|
392
|
+
},
|
|
393
|
+
get runStatus() {
|
|
394
|
+
return session.runState().status
|
|
395
|
+
},
|
|
360
396
|
presentationHead: durable.head(),
|
|
397
|
+
get workMode() {
|
|
398
|
+
return session.workMode
|
|
399
|
+
},
|
|
400
|
+
// P2.3: recovery run terakhir yang durable — setelah restart run mati
|
|
401
|
+
// tampil INTERRUPTED + recovery UNKNOWN, tidak pernah disamarkan LIVE.
|
|
402
|
+
get recoveryStatus() {
|
|
403
|
+
try {
|
|
404
|
+
const runs = listSessionRuns(session.sessionId, cwd)
|
|
405
|
+
const last = runs[runs.length - 1]
|
|
406
|
+
return last?.recovery_status ?? null
|
|
407
|
+
} catch {
|
|
408
|
+
return null
|
|
409
|
+
}
|
|
410
|
+
},
|
|
361
411
|
})
|
|
412
|
+
|
|
413
|
+
if (opts.autoRunPrompt === true && prompt !== undefined && prompt.trim().length > 0) {
|
|
414
|
+
const ctl = new AbortController()
|
|
415
|
+
activeRunCtl = ctl
|
|
416
|
+
void session
|
|
417
|
+
.runPromptWithVerify(prompt, ctl.signal)
|
|
418
|
+
.catch((e) => {
|
|
419
|
+
if (!ctl.signal.aborted) {
|
|
420
|
+
process.stderr.write(`[daemon] hosted run failed: ${(e as Error).message}\n`)
|
|
421
|
+
}
|
|
422
|
+
})
|
|
423
|
+
.finally(() => {
|
|
424
|
+
if (activeRunCtl === ctl) activeRunCtl = null
|
|
425
|
+
})
|
|
426
|
+
}
|
|
427
|
+
} else if (sub.includes("--verify") && workModeResolved.workMode !== "EXECUTE") {
|
|
428
|
+
// P0.2 (Q4): fail-closed sekalipun daemon start dipanggil dengan --verify
|
|
429
|
+
// tanpa --prompt pada mode non-EXECUTE.
|
|
430
|
+
try {
|
|
431
|
+
await host.shutdown("verify-work-mode-conflict")
|
|
432
|
+
} catch {
|
|
433
|
+
/* abaikan error shutdown */
|
|
434
|
+
}
|
|
435
|
+
throw new VerifyWorkModeConflictError(workModeResolved.workMode)
|
|
362
436
|
}
|
|
363
437
|
|
|
364
|
-
return {
|
|
438
|
+
return {
|
|
439
|
+
host,
|
|
440
|
+
session: ctx,
|
|
441
|
+
closeHostedSession,
|
|
442
|
+
workMode: ctx?.workMode ?? workModeResolved.workMode,
|
|
443
|
+
...(workModeResolved.warning ? { workModeWarning: workModeResolved.warning } : {}),
|
|
444
|
+
}
|
|
365
445
|
}
|
|
366
446
|
|
|
367
447
|
/**
|
|
@@ -377,6 +457,10 @@ export interface DaemonHostedRuntime {
|
|
|
377
457
|
readonly session: CliSession | null
|
|
378
458
|
/** Tutup sesi yang di-host (idempoten). Dipakai daemon saat shutdown. */
|
|
379
459
|
readonly closeHostedSession: () => Promise<void>
|
|
460
|
+
/** P0.2 (Q5): WorkMode efektif daemon / sesi yang di-host. */
|
|
461
|
+
readonly workMode: WorkMode
|
|
462
|
+
/** P0.2 (Q5): Peringatan bila nilai `--work-mode` / env tidak valid. */
|
|
463
|
+
readonly workModeWarning?: string
|
|
380
464
|
}
|
|
381
465
|
|
|
382
466
|
async function startDaemon(
|
|
@@ -385,7 +469,16 @@ async function startDaemon(
|
|
|
385
469
|
cwd: string | undefined,
|
|
386
470
|
json: boolean,
|
|
387
471
|
): Promise<void> {
|
|
388
|
-
|
|
472
|
+
let started: DaemonHostedRuntime
|
|
473
|
+
try {
|
|
474
|
+
started = await startDaemonHostedRuntime({ sub, getArg, cwd, autoRunPrompt: true })
|
|
475
|
+
} catch (e) {
|
|
476
|
+
if (e instanceof VerifyWorkModeConflictError) {
|
|
477
|
+
fail(json ? { ok: false, code: "USER_ERROR", reason: e.message } : null, e.message, 2)
|
|
478
|
+
}
|
|
479
|
+
throw e
|
|
480
|
+
}
|
|
481
|
+
const { host, session, workMode, workModeWarning } = started
|
|
389
482
|
|
|
390
483
|
const lines = [
|
|
391
484
|
`daemon: listening on ${host.port} (incarnation ${host.incarnation})`,
|
|
@@ -398,6 +491,8 @@ async function startDaemon(
|
|
|
398
491
|
incarnation: host.incarnation,
|
|
399
492
|
endpoint: host.endpointPath,
|
|
400
493
|
hostedSessions: session ? [session.sessionId] : [],
|
|
494
|
+
workMode,
|
|
495
|
+
...(workModeWarning ? { warning: workModeWarning } : {}),
|
|
401
496
|
}
|
|
402
497
|
emit(lines, json ? JSON.stringify(payload) : null)
|
|
403
498
|
|
package/cli/commands/exec.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { resolve as resolvePath } from "node:path"
|
|
2
2
|
import { NoProviderError } from "../../src/app/provider-layer.ts"
|
|
3
|
+
// F3.2 parity: exec ikut menghormati MINICODE_COMPACT_KEEP_TURNS, sama seperti
|
|
4
|
+
// jalur one-shot (cli/index.ts) — sebelumnya env ini hanya berlaku di REPL.
|
|
5
|
+
import { parseCompactKeepTurns } from "../../src/policy/compaction.ts"
|
|
3
6
|
import { createRateLimiter } from "../../src/policy/ratelimit.ts"
|
|
4
7
|
import { resolveSandbox, sandboxRefusalReason } from "../../src/policy/sandbox-policy.ts"
|
|
5
8
|
import { scrubSecrets } from "../../src/policy/scrub.ts"
|
|
6
9
|
import { budgetStatus } from "../../src/policy/usage.ts"
|
|
10
|
+
import { VerifyWorkModeConflictError } from "../../src/policy/work-mode.ts"
|
|
7
11
|
import {
|
|
8
12
|
MACHINE_SCHEMA,
|
|
9
13
|
machineError,
|
|
@@ -16,6 +20,7 @@ import { formatUsd } from "../../src/ui/render/money.ts"
|
|
|
16
20
|
import { cleanUntrusted } from "../../src/ui/render/sanitize.ts"
|
|
17
21
|
import {
|
|
18
22
|
allowLocalConfig,
|
|
23
|
+
flagsAfterPromptBoundary,
|
|
19
24
|
hasFlag,
|
|
20
25
|
promptFromArgs,
|
|
21
26
|
getArg as rawGetArg,
|
|
@@ -108,6 +113,15 @@ export async function handleExec(
|
|
|
108
113
|
const workModeResolved = resolveWorkModeFlag(getArg)
|
|
109
114
|
const workMode = workModeResolved.workMode
|
|
110
115
|
if (workModeResolved.warning) console.error(`[warn] ${workModeResolved.warning}`)
|
|
116
|
+
// P12 S2.2 (F-DISCUSS-4): exec non-JSON = linear manusia tanpa footer TUI.
|
|
117
|
+
// Mode non-EXECUTE ditulis SATU baris stderr human-facing agar ceiling
|
|
118
|
+
// read-only/rencana terlihat, bukan diam-diam. JSON memakai field terstruktur
|
|
119
|
+
// (summary.workMode) — bukan teks dekoratif. EXECUTE = default = tanpa baris.
|
|
120
|
+
if (!jsonMode && workMode !== "EXECUTE") {
|
|
121
|
+
process.stderr.write(
|
|
122
|
+
`[work-mode] ${workMode}${workMode === "PLAN" ? " (read-only planning)" : " (read-only)"}\n`,
|
|
123
|
+
)
|
|
124
|
+
}
|
|
111
125
|
const ratelimitRaw = getArg("--ratelimit")
|
|
112
126
|
let rateLimiter: ReturnType<typeof createRateLimiter> | undefined
|
|
113
127
|
if (ratelimitRaw) {
|
|
@@ -121,10 +135,57 @@ export async function handleExec(
|
|
|
121
135
|
}
|
|
122
136
|
}
|
|
123
137
|
|
|
138
|
+
// Live Hardening 0.13.x — parity flag runtime dengan jalur one-shot
|
|
139
|
+
// (cli/index.ts): --max-steps, --context-window, --timeout, dan env
|
|
140
|
+
// MINICODE_COMPACT_KEEP_TURNS kini diteruskan ke sesi. Sebelumnya exec
|
|
141
|
+
// menyaring nilai flag ini dari prompt tetapi tidak pernah menerapkannya —
|
|
142
|
+
// operator mengira batas aktif padahal sesi berjalan dengan default kernel
|
|
143
|
+
// (silently ignored). Parsing + warn tiruan persis jalur one-shot.
|
|
144
|
+
const maxStepsRaw = getArg("--max-steps")
|
|
145
|
+
let maxSteps = maxStepsRaw ? Number(maxStepsRaw) : undefined
|
|
146
|
+
if (maxStepsRaw && (!Number.isFinite(maxSteps) || (maxSteps as number) <= 0)) {
|
|
147
|
+
process.stderr.write(
|
|
148
|
+
`[warn] --max-steps requires a positive number, ignoring "${maxStepsRaw}"\n`,
|
|
149
|
+
)
|
|
150
|
+
maxSteps = undefined
|
|
151
|
+
}
|
|
152
|
+
const ctxWindowRaw = getArg("--context-window")
|
|
153
|
+
let contextWindowTokens = ctxWindowRaw ? Number(ctxWindowRaw) : undefined
|
|
154
|
+
if (
|
|
155
|
+
ctxWindowRaw &&
|
|
156
|
+
(!Number.isFinite(contextWindowTokens) || (contextWindowTokens as number) <= 0)
|
|
157
|
+
) {
|
|
158
|
+
process.stderr.write(
|
|
159
|
+
`[warn] --context-window requires a positive number, ignoring "${ctxWindowRaw}"\n`,
|
|
160
|
+
)
|
|
161
|
+
contextWindowTokens = undefined
|
|
162
|
+
}
|
|
163
|
+
const keepTurnsRaw = (process.env.MINICODE_COMPACT_KEEP_TURNS ?? "").trim()
|
|
164
|
+
const keepRecentTurns = parseCompactKeepTurns(keepTurnsRaw || undefined)
|
|
165
|
+
if (keepTurnsRaw && keepRecentTurns === undefined)
|
|
166
|
+
process.stderr.write(
|
|
167
|
+
`[warn] MINICODE_COMPACT_KEEP_TURNS requires an integer >= 1, ignoring "${keepTurnsRaw}"\n`,
|
|
168
|
+
)
|
|
169
|
+
const timeoutRaw = getArg("--timeout")
|
|
170
|
+
let timeoutMs = timeoutRaw ? Number(timeoutRaw) : undefined
|
|
171
|
+
if (timeoutRaw && (!Number.isFinite(timeoutMs) || (timeoutMs as number) < 0)) {
|
|
172
|
+
process.stderr.write(
|
|
173
|
+
`[warn] --timeout requires a non-negative number, ignoring "${timeoutRaw}"\n`,
|
|
174
|
+
)
|
|
175
|
+
timeoutMs = undefined
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const ignoredFlags = flagsAfterPromptBoundary(subArgs)
|
|
179
|
+
if (ignoredFlags.length > 0) {
|
|
180
|
+
process.stderr.write(
|
|
181
|
+
`[warn] ignored flag(s) after the prompt: ${ignoredFlags.join(", ")} — put flags before the prompt (e.g. minicode exec ${ignoredFlags.join(" ")} "your prompt")\n`,
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
|
|
124
185
|
const effectivePrompt = prompt.trim()
|
|
125
186
|
if (!effectivePrompt) {
|
|
126
187
|
console.error(
|
|
127
|
-
'usage: minicode exec
|
|
188
|
+
'usage: minicode exec [--json] [--work-mode DISCUSS|PLAN|EXECUTE] [--cwd <dir>] [--model <m>] [--sandbox docker|os] "prompt"',
|
|
128
189
|
)
|
|
129
190
|
if (jsonMode)
|
|
130
191
|
writeMachineLine(
|
|
@@ -158,19 +219,36 @@ export async function handleExec(
|
|
|
158
219
|
budget,
|
|
159
220
|
budgetStrict,
|
|
160
221
|
toolScope,
|
|
222
|
+
// Live Hardening 0.13.x — parity runtime-limit one-shot (lihat blok parse
|
|
223
|
+
// di atas); undefined = default kernel, perilaku lama tak berubah.
|
|
224
|
+
...(maxSteps ? { maxSteps } : {}),
|
|
225
|
+
...(contextWindowTokens && contextWindowTokens > 0 ? { contextWindowTokens } : {}),
|
|
226
|
+
...(keepRecentTurns ? { keepRecentTurns } : {}),
|
|
227
|
+
...(timeoutMs !== undefined ? { timeoutMs } : {}),
|
|
161
228
|
// P12 S2.2 — WorkMode efektif (sudah di-resolve, default EXECUTE).
|
|
162
229
|
workMode,
|
|
230
|
+
workModeExplicit: workModeResolved.explicit,
|
|
163
231
|
rateLimiter,
|
|
164
232
|
// Notice hanya bila user eksplisit meminta mode (daemon mati / tak dikenal).
|
|
165
233
|
sandboxNotice: requestedSandbox ? sandbox.notice : undefined,
|
|
166
234
|
}).catch((e) => {
|
|
167
|
-
// Setup gagal SEBELUM envelope JSON dipasang (tanpa provider):
|
|
168
|
-
// mesin tetap pulang membawa satu baris summary agar pipeline CI tak
|
|
169
|
-
// menerima stream kosong — stderr manusia + exit 1
|
|
170
|
-
if (e instanceof NoProviderError) {
|
|
171
|
-
if (jsonMode)
|
|
235
|
+
// Setup gagal SEBELUM envelope JSON dipasang (tanpa provider / salah pakai):
|
|
236
|
+
// mode mesin tetap pulang membawa satu baris summary agar pipeline CI tak
|
|
237
|
+
// menerima stream kosong — stderr manusia + exit code jujur (2 usage, 1 runtime).
|
|
238
|
+
if (e instanceof NoProviderError || e instanceof VerifyWorkModeConflictError) {
|
|
239
|
+
if (jsonMode) {
|
|
240
|
+
const payload =
|
|
241
|
+
e instanceof VerifyWorkModeConflictError
|
|
242
|
+
? machineSummary(false, {
|
|
243
|
+
prompt: effectivePrompt,
|
|
244
|
+
workMode,
|
|
245
|
+
error: { category: "USER_ERROR", message: e.message },
|
|
246
|
+
})
|
|
247
|
+
: machineFailure(effectivePrompt, e)
|
|
248
|
+
writeMachineLine(JSON.stringify(payload))
|
|
249
|
+
}
|
|
172
250
|
console.error(e.message)
|
|
173
|
-
process.exit(1)
|
|
251
|
+
process.exit(e instanceof VerifyWorkModeConflictError ? 2 : 1)
|
|
174
252
|
}
|
|
175
253
|
// Setup lain yang gagal (config rusak, dsb.): mesin tetap pulang membawa
|
|
176
254
|
// envelope terminal agar stream tidak kosong, lalu error asli dilempar
|
|
@@ -243,7 +321,17 @@ export async function handleExec(
|
|
|
243
321
|
steps: ctx.session.state.stepCount,
|
|
244
322
|
turns: ctx.session.state.turnCount,
|
|
245
323
|
usage: ue,
|
|
324
|
+
// P1.4: context occupancy/capacity adalah angka berbeda dari session
|
|
325
|
+
// spend (`usage`). Machine consumer harus bisa membedakannya.
|
|
326
|
+
contextTokens: ctx.session.contextTokens,
|
|
327
|
+
...(ctx.contextWindowTokens ? { contextWindowTokens: ctx.contextWindowTokens } : {}),
|
|
328
|
+
// Cache hanya dilaporkan bila provider benar-benar mengirimnya; absen =
|
|
329
|
+
// UNKNOWN, bukan 0 yang menyiratkan "tidak ada cache".
|
|
330
|
+
...(ue.cacheReadTokens ? { cacheReadTokens: ue.cacheReadTokens } : {}),
|
|
331
|
+
...(ue.cacheWriteTokens ? { cacheWriteTokens: ue.cacheWriteTokens } : {}),
|
|
246
332
|
eventCount: streamed,
|
|
333
|
+
// P12 S2.2 (F-DISCUSS-4) + P0.2: surface terstruktur WorkMode efektif di summary mesin
|
|
334
|
+
workMode: ctx.workMode,
|
|
247
335
|
...(submitted ? { submitted: submitted.result } : {}),
|
|
248
336
|
...(lastVerify
|
|
249
337
|
? {
|