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,208 @@
|
|
|
1
|
+
// [Fase 4 / LOOP-13, LOOP-INV-16, LOOP-G18] Runtime State Header — Dual-Buffer
|
|
2
|
+
// Operational Context yang Survives Compaction.
|
|
3
|
+
//
|
|
4
|
+
// Header deterministik yang disuntikkan langsung dari sumber durable
|
|
5
|
+
// (TaskStore, persistence, pending tools, usage) pada saat perakitan konteks,
|
|
6
|
+
// sehingga fakta operasional kritis tidak hilang akibat kompaksi riwayat percakapan.
|
|
7
|
+
//
|
|
8
|
+
// Batas keras modul ini:
|
|
9
|
+
// - MURNI: hanya rendering string dari state terstruktur.
|
|
10
|
+
// - Tidak ada I/O, tidak ada write, tidak ada mutation.
|
|
11
|
+
// - Format stabil (tidak bergantung pada model eksternal).
|
|
12
|
+
|
|
13
|
+
import type { ConsequenceDecision } from "../policy/consequence-engine.ts"
|
|
14
|
+
import type { Usage as UsageSession } from "../policy/usage.ts"
|
|
15
|
+
import type { TaskEvidence } from "../task/model.ts"
|
|
16
|
+
import { TaskStore } from "../task/store.ts"
|
|
17
|
+
|
|
18
|
+
/** State operasonal minimal yang diperlukan untuk rendering header. */
|
|
19
|
+
export interface OperationalStateSnapshot {
|
|
20
|
+
readonly runId?: string
|
|
21
|
+
readonly turnCount: number
|
|
22
|
+
readonly maxTurns?: number | null
|
|
23
|
+
readonly budgetRemainingUsd?: number | null
|
|
24
|
+
readonly pendingToolIds?: readonly string[]
|
|
25
|
+
readonly unknownOutcomeTools?: readonly string[] // tool call yang timeout = UNKNOWN
|
|
26
|
+
readonly pendingApprovals?: readonly { id: string; action?: string }[]
|
|
27
|
+
readonly inProgressTasks?: number
|
|
28
|
+
readonly verifyingTasks?: number
|
|
29
|
+
readonly blockedTasks?: number
|
|
30
|
+
readonly completedVerifiedTasks?: number
|
|
31
|
+
readonly activeTasks?: readonly {
|
|
32
|
+
readonly id: string
|
|
33
|
+
readonly status: string
|
|
34
|
+
readonly verificationVerdict?: "passed" | "failed" | "stale"
|
|
35
|
+
}[]
|
|
36
|
+
/**
|
|
37
|
+
* [Fase 6A / ACE-01] Keputusan consequence terakhir. Opsional: sesi lama
|
|
38
|
+
* tanpa verifikasi tidak memiliki baris `ace_state`.
|
|
39
|
+
*/
|
|
40
|
+
readonly aceDecision?: ConsequenceDecision | null
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Render header operasional deterministik yang aman masuk ke prompt.
|
|
45
|
+
* Format dibungkus tag tegas agar model memperlakukan sebagai metadata
|
|
46
|
+
* operasional, bukan instruksi user biasa.
|
|
47
|
+
*/
|
|
48
|
+
export function buildRuntimeStateHeader(state: OperationalStateSnapshot): string {
|
|
49
|
+
const lines: string[] = []
|
|
50
|
+
lines.push("[RUNTIME_STATE_HEADER — AUTHORITATIVE_OPERATIONAL_STATE]")
|
|
51
|
+
|
|
52
|
+
// Baris satu: identitas run & progress turn + budget
|
|
53
|
+
const runIdStr = state.runId ? `${state.runId}` : "-"
|
|
54
|
+
const maxTurnsStr =
|
|
55
|
+
state.maxTurns === undefined || state.maxTurns === null
|
|
56
|
+
? `${state.turnCount}/unbounded`
|
|
57
|
+
: `${state.turnCount}/${state.maxTurns}`
|
|
58
|
+
const budgetStr =
|
|
59
|
+
state.budgetRemainingUsd === undefined || state.budgetRemainingUsd === null
|
|
60
|
+
? "?"
|
|
61
|
+
: `$${state.budgetRemainingUsd.toFixed(6)}`
|
|
62
|
+
lines.push(`run_id: ${runIdStr} | turn: ${maxTurnsStr} | budget_remaining_usd: ${budgetStr}`)
|
|
63
|
+
|
|
64
|
+
// Baris dua: tool tracking + approval pending
|
|
65
|
+
const pendingList =
|
|
66
|
+
state.pendingToolIds && state.pendingToolIds.length > 0
|
|
67
|
+
? `[${state.pendingToolIds.join(",")}]`
|
|
68
|
+
: "[]"
|
|
69
|
+
const unknownList =
|
|
70
|
+
state.unknownOutcomeTools && state.unknownOutcomeTools.length > 0
|
|
71
|
+
? `[${state.unknownOutcomeTools.join(",")}]`
|
|
72
|
+
: "[]"
|
|
73
|
+
const approvalsList =
|
|
74
|
+
state.pendingApprovals && state.pendingApprovals.length > 0
|
|
75
|
+
? `[${state.pendingApprovals.map((a) => a.id).join(",")}]`
|
|
76
|
+
: "[]"
|
|
77
|
+
lines.push(
|
|
78
|
+
`pending_tool_ids: ${pendingList} | unknown_outcome_tools: ${unknownList} | pending_approvals: ${approvalsList}`,
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
// Baris tiga: ringkasan task counter
|
|
82
|
+
const counters: string[] = []
|
|
83
|
+
if (typeof state.inProgressTasks === "number")
|
|
84
|
+
counters.push(`in_progress=${state.inProgressTasks}`)
|
|
85
|
+
if (typeof state.verifyingTasks === "number") counters.push(`verifying=${state.verifyingTasks}`)
|
|
86
|
+
if (typeof state.blockedTasks === "number") counters.push(`blocked=${state.blockedTasks}`)
|
|
87
|
+
if (typeof state.completedVerifiedTasks === "number")
|
|
88
|
+
counters.push(`completed_verified=${state.completedVerifiedTasks}`)
|
|
89
|
+
const summary = counters.length > 0 ? counters.join(" ") : "none"
|
|
90
|
+
lines.push(`tasks_summary: ${summary}`)
|
|
91
|
+
|
|
92
|
+
// Baris empat: daftar aktif singkat (task_id + status + verdict bila ada)
|
|
93
|
+
if (state.activeTasks && state.activeTasks.length > 0) {
|
|
94
|
+
const activeLines = state.activeTasks.map((t) => {
|
|
95
|
+
const v = t.verificationVerdict ? ` [verdict:${t.verificationVerdict}]` : ""
|
|
96
|
+
return ` - ${t.id}: ${t.status}${v}`
|
|
97
|
+
})
|
|
98
|
+
lines.push(`active_tasks: ${activeLines.join("; ")}`)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Baris lima: keputusan consequence ACE-Lite (bila sudah ada verifikasi).
|
|
102
|
+
if (state.aceDecision) {
|
|
103
|
+
const d = state.aceDecision
|
|
104
|
+
lines.push(
|
|
105
|
+
`ace_state: verdict=${d.verdict} | failure_class=${d.failureClass} | next_action=${d.nextAction} | new_evidence=${d.newEvidenceSinceLastAttempt === true}`,
|
|
106
|
+
)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
lines.push("[END_RUNTIME_STATE_HEADER]")
|
|
110
|
+
return lines.join("\n")
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Wrap context assembly dengan injection header jika state tersedia.
|
|
115
|
+
* Fungsi helper untuk diintegrasikan ke `assembleContext` atau pemanggil lain.
|
|
116
|
+
*/
|
|
117
|
+
export function injectRuntimeHeaderIntoContent(
|
|
118
|
+
content: string,
|
|
119
|
+
state: OperationalStateSnapshot | null,
|
|
120
|
+
): string {
|
|
121
|
+
if (!state) return content
|
|
122
|
+
const header = buildRuntimeStateHeader(state)
|
|
123
|
+
return `${header}\n\n${content}`
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* [Audit #2 A.3] Parse `verdict` dari `detail` evidence "verify" secara LOKAL:
|
|
128
|
+
* satu detail korup tidak boleh membatalkan seluruh snapshot `collectOperationalState`.
|
|
129
|
+
*/
|
|
130
|
+
function evidenceVerdict(detail: string): "passed" | "failed" | "stale" | undefined {
|
|
131
|
+
try {
|
|
132
|
+
const v = JSON.parse(detail) as { verdict?: unknown }
|
|
133
|
+
const verdict = v.verdict
|
|
134
|
+
return verdict === "passed" || verdict === "failed" || verdict === "stale" ? verdict : undefined
|
|
135
|
+
} catch {
|
|
136
|
+
return undefined
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** Evidence ber-`kind === "verify"` PALING AKHIR (bukan sekadar elemen terakhir). */
|
|
141
|
+
function lastVerifyEvidence(list: TaskEvidence[] | undefined): TaskEvidence | undefined {
|
|
142
|
+
if (!list) return undefined
|
|
143
|
+
for (let i = list.length - 1; i >= 0; i--) {
|
|
144
|
+
if (list[i]!.kind === "verify") return list[i]!
|
|
145
|
+
}
|
|
146
|
+
return undefined
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Build snapshot dari sumber-sumber operasional yang ada di CLI. */
|
|
150
|
+
export function collectOperationalState(
|
|
151
|
+
sessionId: string,
|
|
152
|
+
cwd: string,
|
|
153
|
+
usage: { getSession(): UsageSession; getTurnCount(): number },
|
|
154
|
+
maxTurns?: number | null,
|
|
155
|
+
aceDecision?: ConsequenceDecision | null,
|
|
156
|
+
): OperationalStateSnapshot | null {
|
|
157
|
+
try {
|
|
158
|
+
const store = new TaskStore(cwd)
|
|
159
|
+
const tasks = store.listTasks(sessionId)
|
|
160
|
+
|
|
161
|
+
const inProgressTasks = tasks.filter((t) => t.status === "IN_PROGRESS").length
|
|
162
|
+
const verifyingTasks = tasks.filter((t) => t.status === "VERIFYING").length
|
|
163
|
+
const blockedTasks = tasks.filter((t) => t.status === "BLOCKED").length
|
|
164
|
+
const completedVerifiedTasks = tasks.filter((t) => {
|
|
165
|
+
if (t.status !== "COMPLETED") return false
|
|
166
|
+
return (t.evidence ?? []).some(
|
|
167
|
+
(e) => e.kind === "verify" && evidenceVerdict(e.detail) === "passed",
|
|
168
|
+
)
|
|
169
|
+
}).length
|
|
170
|
+
|
|
171
|
+
const activeTasks = tasks
|
|
172
|
+
.filter((t) => ["IN_PROGRESS", "VERIFYING", "BLOCKED", "PENDING"].includes(t.status))
|
|
173
|
+
.slice(0, 16) // Limit tampilan ke 16 task aktif saja
|
|
174
|
+
.map((t) => {
|
|
175
|
+
// [Audit #2 A.3] Ambil evidence "verify" PALING AKHIR (bukan sekadar
|
|
176
|
+
// elemen terakhir array yang bisa ber-kind lain), lalu parse secara aman.
|
|
177
|
+
const verify = lastVerifyEvidence(t.evidence)
|
|
178
|
+
return {
|
|
179
|
+
id: t.id,
|
|
180
|
+
status: t.status,
|
|
181
|
+
verificationVerdict: verify ? evidenceVerdict(verify.detail) : undefined,
|
|
182
|
+
}
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
return {
|
|
186
|
+
runId: undefined, // DIISI oleh caller dari session state
|
|
187
|
+
turnCount: usage.getTurnCount(),
|
|
188
|
+
maxTurns: maxTurns,
|
|
189
|
+
budgetRemainingUsd: (() => {
|
|
190
|
+
const c = usage.getSession().cost
|
|
191
|
+
return typeof maxTurns === "number" || typeof c !== "number"
|
|
192
|
+
? undefined
|
|
193
|
+
: Math.max(0, 1 - c)
|
|
194
|
+
})(),
|
|
195
|
+
pendingToolIds: undefined, // DIISI oleh caller dari pending-tools state
|
|
196
|
+
unknownOutcomeTools: undefined, // DIISI oleh caller dari journal state
|
|
197
|
+
pendingApprovals: undefined, // DIISI oleh caller dari presentation_events
|
|
198
|
+
inProgressTasks,
|
|
199
|
+
verifyingTasks,
|
|
200
|
+
blockedTasks,
|
|
201
|
+
completedVerifiedTasks,
|
|
202
|
+
activeTasks: activeTasks.length > 0 ? activeTasks : undefined,
|
|
203
|
+
...(aceDecision ? { aceDecision } : {}),
|
|
204
|
+
}
|
|
205
|
+
} catch {
|
|
206
|
+
return null
|
|
207
|
+
}
|
|
208
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { spawn } from "node:child_process"
|
|
2
2
|
import { randomUUID } from "node:crypto"
|
|
3
3
|
import { rm } from "node:fs/promises"
|
|
4
|
-
import { join, resolve } from "node:path"
|
|
4
|
+
import { isAbsolute, join, relative, resolve } from "node:path"
|
|
5
5
|
import { LIMITS } from "../constants.ts"
|
|
6
6
|
import { GIT_NO_DIFF_DRIVERS, GIT_SAFE_BASE, gitFilterNeutralizers } from "../lib/git-hardening.ts"
|
|
7
7
|
import { sanitizeSessionPart } from "../lib/session-id.ts"
|
|
@@ -238,6 +238,17 @@ export interface RestoreResult {
|
|
|
238
238
|
skipped: string[]
|
|
239
239
|
}
|
|
240
240
|
|
|
241
|
+
/**
|
|
242
|
+
* [XP-1] Cek apakah `p` berada di dalam workspace `root` lewat `path.relative`.
|
|
243
|
+
* Pengganti pola `abs.startsWith(root + sep)` yang gagal saat `root` adalah
|
|
244
|
+
* root drive (`D:\` → `D:\\`, `/` → `//`). Diekspor untuk test.
|
|
245
|
+
*/
|
|
246
|
+
export function isPathWithinWorkspace(root: string, p: string): boolean {
|
|
247
|
+
const abs = resolve(root, p)
|
|
248
|
+
const rel = relative(root, abs)
|
|
249
|
+
return rel === "" || (!rel.startsWith("..") && !isAbsolute(rel))
|
|
250
|
+
}
|
|
251
|
+
|
|
241
252
|
/**
|
|
242
253
|
* Pulihkan workspace ke `tree`, menyentuh HANYA path yang berbeda dari kondisi
|
|
243
254
|
* sekarang. File yang muncul setelah snapshot dihapus; yang berubah/terhapus
|
|
@@ -259,10 +270,7 @@ export async function restoreTree(cwd: string, tree: string): Promise<RestoreRes
|
|
|
259
270
|
const changes = await diffTrees(cwd, tree, now)
|
|
260
271
|
if (changes.length === 0) return { applied, skipped: [] }
|
|
261
272
|
|
|
262
|
-
const inside = (p: string): boolean =>
|
|
263
|
-
const abs = resolve(root, p)
|
|
264
|
-
return abs === root || abs.startsWith(root + (process.platform === "win32" ? "\\" : "/"))
|
|
265
|
-
}
|
|
273
|
+
const inside = (p: string): boolean => isPathWithinWorkspace(root, p)
|
|
266
274
|
|
|
267
275
|
// Path yang harus DIAMBIL dari tree lama (berubah di tree lama → sekarang
|
|
268
276
|
// sebagai M, atau hilang sekarang sebagai D dari sudut pandang diff).
|