minicode-ai 0.27.0 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/cli/args.ts +184 -57
- package/cli/bootstrap/presentation-bridge.ts +383 -0
- package/cli/commands/acp.ts +45 -29
- package/cli/commands/auth.ts +17 -17
- package/cli/commands/config.ts +65 -66
- package/cli/commands/daemon.ts +44 -16
- package/cli/commands/doctor.ts +18 -15
- package/cli/commands/exec.ts +41 -89
- package/cli/commands/mcp.ts +25 -8
- package/cli/commands/memory.ts +16 -24
- package/cli/commands/openwork.ts +6 -2
- package/cli/commands/pricing.ts +14 -12
- package/cli/commands/providers.ts +36 -57
- package/cli/commands/sessions.ts +24 -18
- package/cli/commands/skills.ts +33 -18
- package/cli/commands/stats.ts +15 -30
- package/cli/commands.ts +73 -44
- package/cli/context-command-run.ts +30 -18
- package/cli/index.ts +51 -100
- package/cli/model-manager.ts +7 -2
- package/cli/provider-manager.ts +33 -18
- package/cli/router.ts +41 -12
- package/cli/setup.ts +241 -485
- package/cli/tui.ts +303 -100
- package/docs/TERMINAL_CONTRACT.md +258 -73
- package/docs/UI_RENDER_PIPELINE.md +9 -1
- package/docs/agents.md +2 -2
- package/docs/architecture.md +17 -32
- package/docs/choosing-mode.md +7 -9
- package/docs/cli.md +3 -5
- package/docs/environment.md +1 -2
- package/docs/policy-sandbox.md +3 -3
- package/docs/repl.md +2 -2
- package/docs/tools.md +1 -1
- package/package.json +1 -1
- package/src/app/mentions.ts +60 -13
- package/src/app/rag-layer.ts +17 -20
- package/src/app/session.ts +144 -68
- package/src/app/tool-layer.ts +38 -16
- package/src/config.ts +64 -104
- package/src/constants.ts +4 -6
- package/src/daemon/capability.ts +8 -1
- package/src/daemon/control.ts +3 -2
- package/src/daemon/server.ts +57 -0
- package/src/hooks/run.ts +73 -41
- package/src/lib/atomic-write.ts +31 -59
- package/src/lib/db-path.ts +47 -0
- package/src/lib/process-tree.ts +62 -0
- package/src/lib/public-http.ts +88 -23
- package/src/lib/trusted-exec.ts +48 -1
- package/src/lsp/client.ts +62 -17
- package/src/mcp/client.ts +85 -38
- package/src/mcp/http-transport.ts +28 -16
- package/src/mcp/transport.ts +42 -6
- package/src/memory/files.ts +164 -134
- package/src/memory/vector.ts +371 -420
- package/src/policy/approval-binding.ts +122 -45
- package/src/policy/bash-guard.ts +18 -7
- package/src/policy/compaction.ts +51 -18
- package/src/policy/context-window.ts +31 -8
- package/src/policy/context.ts +62 -36
- package/src/policy/executor.ts +17 -7
- package/src/policy/jail.ts +6 -8
- package/src/policy/microcompact.ts +4 -3
- package/src/policy/no-progress.ts +103 -22
- package/src/policy/permission.ts +36 -12
- package/src/policy/tool-contract.ts +74 -416
- package/src/policy/usage.ts +24 -2
- package/src/policy/verifier.ts +50 -2
- package/src/policy/work-mode.ts +28 -54
- package/src/presentation/adapter.ts +24 -16
- package/src/providers/anthropic.ts +16 -5
- package/src/providers/provision.ts +6 -56
- package/src/providers/responses.ts +38 -7
- package/src/providers/sse-bounds.ts +6 -4
- package/src/runtime/execution-journal.ts +4 -29
- package/src/sandbox/docker.ts +58 -34
- package/src/sandbox/mask.ts +157 -0
- package/src/sandbox/os.ts +107 -73
- package/src/session/authority.ts +29 -10
- package/src/session/context-projection.ts +6 -5
- package/src/session/db/runs.ts +397 -0
- package/src/session/db/schema.ts +358 -0
- package/src/session/open-work.ts +26 -3
- package/src/session/persistence.ts +74 -998
- package/src/session/verification.ts +170 -20
- package/src/skills/loader.ts +31 -16
- package/src/task/db/schema.ts +325 -0
- package/src/task/db/types.ts +269 -0
- package/src/task/production-scheduler.ts +13 -1
- package/src/task/store.ts +92 -1021
- package/src/telemetry/trace.ts +27 -0
- package/src/tools/ask_user.ts +1 -13
- package/src/tools/bash.ts +27 -92
- package/src/tools/code_run.ts +1 -1
- package/src/tools/context.ts +133 -0
- package/src/tools/delete_file.ts +3 -2
- package/src/tools/edit.ts +37 -72
- package/src/tools/git.ts +86 -9
- package/src/tools/glob.ts +26 -51
- package/src/tools/grep.ts +67 -57
- package/src/tools/hashline.ts +4 -0
- package/src/tools/lsp.ts +11 -8
- package/src/tools/mcp_call.ts +9 -6
- package/src/tools/memory.ts +56 -33
- package/src/tools/move_file.ts +36 -10
- package/src/tools/patch.ts +13 -21
- package/src/tools/read_file.ts +18 -25
- package/src/tools/read_image.ts +35 -33
- package/src/tools/submit_result.ts +29 -8
- package/src/tools/task.ts +74 -17
- package/src/tools/todo.ts +181 -74
- package/src/tools/web_fetch.ts +42 -2
- package/src/tools/web_search.ts +47 -8
- package/src/ui/approval/prompt.ts +206 -47
- package/src/ui/assistant/turn-status.ts +14 -5
- package/src/ui/footer.ts +4 -4
- package/src/ui/i18n/en.ts +47 -23
- package/src/ui/i18n/id.ts +76 -51
- package/src/ui/input/input.ts +4 -3
- package/src/ui/input/prompt-engine.ts +35 -5
- package/src/ui/render/activity-panel.ts +4 -2
- package/src/ui/render/hint.ts +7 -4
- package/src/ui/render/list.ts +32 -0
- package/src/ui/render/markdown.ts +6 -3
- package/src/ui/render/notice.ts +19 -0
- package/src/ui/render/table-grid.ts +7 -8
- package/src/ui/render/theme.ts +113 -39
- package/src/ui/runtime/screen.ts +74 -10
- package/src/ui/runtime/spinner.ts +19 -6
- package/src/ui/screens/dialog.ts +19 -1
- package/src/ui/screens/form.ts +80 -35
- package/src/ui/screens/model-manager.ts +82 -61
- package/src/ui/screens/output-window.ts +263 -0
- package/src/ui/screens/picker.ts +94 -81
- package/src/ui/screens/provider-manager.ts +100 -69
- package/src/ui/screens/wizard.ts +117 -28
- package/src/ui/tui/app.ts +196 -33
- package/src/ui/tui/transcript.ts +158 -25
- package/vendor/minicore/src/core/executor.ts +2 -0
- package/vendor/minicore/src/core/loop.ts +17 -6
- package/vendor/minicore/src/core/session.ts +3 -0
- package/vendor/minicore/src/core/tool.ts +1 -0
- package/vendor/minicore/src/providers/openai-compat.ts +35 -19
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
import { createLlmCompaction } from "../../src/policy/compaction.ts"
|
|
2
|
+
import type { DomainEvent } from "../../src/presentation/events.ts"
|
|
3
|
+
import type { UiPresentationEvent } from "../../src/ui/contract.ts"
|
|
4
|
+
|
|
5
|
+
/** Peta exhaustive dari `DomainEvent` ke kontrak event UI lintas lapisan. */
|
|
6
|
+
function mapPresentationEvent(event: DomainEvent): UiPresentationEvent | null {
|
|
7
|
+
switch (event.type) {
|
|
8
|
+
case "user.message":
|
|
9
|
+
return {
|
|
10
|
+
type: event.type,
|
|
11
|
+
seq: event.eventSeq,
|
|
12
|
+
turnId: event.turnId,
|
|
13
|
+
text: event.text,
|
|
14
|
+
promptRef: event.promptRef,
|
|
15
|
+
}
|
|
16
|
+
case "turn.started":
|
|
17
|
+
return {
|
|
18
|
+
type: event.type,
|
|
19
|
+
seq: event.eventSeq,
|
|
20
|
+
turnId: event.turnId,
|
|
21
|
+
promptRef: event.promptRef,
|
|
22
|
+
}
|
|
23
|
+
case "turn.completed":
|
|
24
|
+
return {
|
|
25
|
+
type: event.type,
|
|
26
|
+
seq: event.eventSeq,
|
|
27
|
+
turnId: event.turnId,
|
|
28
|
+
summary: event.summary,
|
|
29
|
+
}
|
|
30
|
+
case "turn.failed":
|
|
31
|
+
return {
|
|
32
|
+
type: event.type,
|
|
33
|
+
seq: event.eventSeq,
|
|
34
|
+
turnId: event.turnId,
|
|
35
|
+
error: event.error.message,
|
|
36
|
+
cause: event.error.cause,
|
|
37
|
+
}
|
|
38
|
+
case "turn.cancelled":
|
|
39
|
+
return {
|
|
40
|
+
type: event.type,
|
|
41
|
+
seq: event.eventSeq,
|
|
42
|
+
turnId: event.turnId,
|
|
43
|
+
reason: event.reason,
|
|
44
|
+
}
|
|
45
|
+
case "model.delta":
|
|
46
|
+
return {
|
|
47
|
+
type: event.type,
|
|
48
|
+
seq: event.eventSeq,
|
|
49
|
+
turnId: event.turnId,
|
|
50
|
+
delta: event.delta,
|
|
51
|
+
}
|
|
52
|
+
case "model.completed":
|
|
53
|
+
return {
|
|
54
|
+
type: event.type,
|
|
55
|
+
seq: event.eventSeq,
|
|
56
|
+
turnId: event.turnId,
|
|
57
|
+
text: event.text,
|
|
58
|
+
truncated: event.truncated,
|
|
59
|
+
...(event.expandRef ? { expandRef: event.expandRef } : {}),
|
|
60
|
+
}
|
|
61
|
+
case "reasoning.delta":
|
|
62
|
+
return {
|
|
63
|
+
type: event.type,
|
|
64
|
+
seq: event.eventSeq,
|
|
65
|
+
turnId: event.turnId,
|
|
66
|
+
delta: event.delta,
|
|
67
|
+
}
|
|
68
|
+
case "reasoning.completed":
|
|
69
|
+
return {
|
|
70
|
+
type: event.type,
|
|
71
|
+
seq: event.eventSeq,
|
|
72
|
+
turnId: event.turnId,
|
|
73
|
+
truncated: event.truncated,
|
|
74
|
+
expandRef: event.expandRef,
|
|
75
|
+
}
|
|
76
|
+
case "tool.started":
|
|
77
|
+
return {
|
|
78
|
+
type: event.type,
|
|
79
|
+
seq: event.eventSeq,
|
|
80
|
+
turnId: event.turnId,
|
|
81
|
+
stepId: event.stepId,
|
|
82
|
+
toolCallId: event.toolCallId,
|
|
83
|
+
name: event.identity.name,
|
|
84
|
+
qualified: event.identity.qualified,
|
|
85
|
+
target: event.argsSummary.target,
|
|
86
|
+
status: "running",
|
|
87
|
+
tsStart: event.ts,
|
|
88
|
+
...(event.parentLink ? { parentToolCallId: event.parentLink.parentToolCallId } : {}),
|
|
89
|
+
}
|
|
90
|
+
case "tool.progress":
|
|
91
|
+
return {
|
|
92
|
+
type: event.type,
|
|
93
|
+
seq: event.eventSeq,
|
|
94
|
+
turnId: event.turnId,
|
|
95
|
+
toolCallId: event.toolCallId,
|
|
96
|
+
status: "running",
|
|
97
|
+
message: event.message,
|
|
98
|
+
}
|
|
99
|
+
case "tool.completed":
|
|
100
|
+
return {
|
|
101
|
+
type: event.type,
|
|
102
|
+
seq: event.eventSeq,
|
|
103
|
+
turnId: event.turnId,
|
|
104
|
+
toolCallId: event.toolCallId,
|
|
105
|
+
status: "completed",
|
|
106
|
+
durationMs: event.durationMs,
|
|
107
|
+
toolSummary: event.summary,
|
|
108
|
+
expandRef: event.expandRef,
|
|
109
|
+
...(event.receipt
|
|
110
|
+
? {
|
|
111
|
+
receipt: {
|
|
112
|
+
...(event.receipt.paths ? { paths: event.receipt.paths } : {}),
|
|
113
|
+
...(event.receipt.checkpointId ? { checkpointId: event.receipt.checkpointId } : {}),
|
|
114
|
+
...(event.receipt.stats ? { stats: event.receipt.stats } : {}),
|
|
115
|
+
...(event.receipt.test ? { test: event.receipt.test } : {}),
|
|
116
|
+
...(event.receipt.cmd ? { cmd: event.receipt.cmd } : {}),
|
|
117
|
+
},
|
|
118
|
+
}
|
|
119
|
+
: {}),
|
|
120
|
+
...(event.parentLink ? { parentToolCallId: event.parentLink.parentToolCallId } : {}),
|
|
121
|
+
}
|
|
122
|
+
case "tool.failed":
|
|
123
|
+
return {
|
|
124
|
+
type: event.type,
|
|
125
|
+
seq: event.eventSeq,
|
|
126
|
+
turnId: event.turnId,
|
|
127
|
+
toolCallId: event.toolCallId,
|
|
128
|
+
status: "failed",
|
|
129
|
+
durationMs: event.durationMs,
|
|
130
|
+
message: event.message,
|
|
131
|
+
cause: event.cause,
|
|
132
|
+
...(event.hint ? { hint: event.hint } : {}),
|
|
133
|
+
...(event.schemaDrift ? { schemaDrift: event.schemaDrift } : {}),
|
|
134
|
+
expandRef: event.expandRef,
|
|
135
|
+
...(event.parentLink ? { parentToolCallId: event.parentLink.parentToolCallId } : {}),
|
|
136
|
+
}
|
|
137
|
+
case "tool.denied":
|
|
138
|
+
return {
|
|
139
|
+
type: event.type,
|
|
140
|
+
seq: event.eventSeq,
|
|
141
|
+
turnId: event.turnId,
|
|
142
|
+
toolCallId: event.toolCallId,
|
|
143
|
+
status: "denied",
|
|
144
|
+
message: event.message,
|
|
145
|
+
reason: event.reason,
|
|
146
|
+
...(event.parentLink ? { parentToolCallId: event.parentLink.parentToolCallId } : {}),
|
|
147
|
+
}
|
|
148
|
+
case "tool.cancelled":
|
|
149
|
+
return {
|
|
150
|
+
type: event.type,
|
|
151
|
+
seq: event.eventSeq,
|
|
152
|
+
turnId: event.turnId,
|
|
153
|
+
toolCallId: event.toolCallId,
|
|
154
|
+
status: "cancelled",
|
|
155
|
+
reason: event.reason,
|
|
156
|
+
...(event.parentLink ? { parentToolCallId: event.parentLink.parentToolCallId } : {}),
|
|
157
|
+
}
|
|
158
|
+
case "approval.requested":
|
|
159
|
+
return {
|
|
160
|
+
type: event.type,
|
|
161
|
+
seq: event.eventSeq,
|
|
162
|
+
turnId: event.turnId,
|
|
163
|
+
approvalId: event.approvalId,
|
|
164
|
+
toolCallId: event.toolCallId,
|
|
165
|
+
name: event.identity.name,
|
|
166
|
+
qualified: event.identity.qualified,
|
|
167
|
+
target: event.argsSummary.target,
|
|
168
|
+
via: event.via,
|
|
169
|
+
...(event.riskTier ? { riskTier: event.riskTier } : {}),
|
|
170
|
+
...(event.diffPreview ? { diffPreview: event.diffPreview } : {}),
|
|
171
|
+
}
|
|
172
|
+
case "approval.settled":
|
|
173
|
+
return {
|
|
174
|
+
type: event.type,
|
|
175
|
+
seq: event.eventSeq,
|
|
176
|
+
turnId: event.turnId,
|
|
177
|
+
approvalId: event.approvalId,
|
|
178
|
+
toolCallId: event.toolCallId,
|
|
179
|
+
outcome: event.outcome,
|
|
180
|
+
}
|
|
181
|
+
case "file.changed":
|
|
182
|
+
return {
|
|
183
|
+
type: event.type,
|
|
184
|
+
seq: event.eventSeq,
|
|
185
|
+
turnId: event.turnId,
|
|
186
|
+
toolCallId: event.toolCallId,
|
|
187
|
+
paths: event.paths,
|
|
188
|
+
...(event.journalSeq !== undefined ? { journalSeq: event.journalSeq } : {}),
|
|
189
|
+
...(event.checkpointId ? { checkpointId: event.checkpointId } : {}),
|
|
190
|
+
}
|
|
191
|
+
case "test.completed":
|
|
192
|
+
return {
|
|
193
|
+
type: event.type,
|
|
194
|
+
seq: event.eventSeq,
|
|
195
|
+
turnId: event.turnId,
|
|
196
|
+
toolCallId: event.toolCallId,
|
|
197
|
+
test: { passed: event.passed, failed: event.failed, summary: event.summary },
|
|
198
|
+
}
|
|
199
|
+
case "verification.observed":
|
|
200
|
+
return {
|
|
201
|
+
type: event.type,
|
|
202
|
+
seq: event.eventSeq,
|
|
203
|
+
turnId: event.turnId,
|
|
204
|
+
toolCallId: event.toolCallId,
|
|
205
|
+
invocationId: event.invocationId,
|
|
206
|
+
verification: {
|
|
207
|
+
invocationId: event.invocationId,
|
|
208
|
+
verdict: event.verdict,
|
|
209
|
+
method: event.method,
|
|
210
|
+
observedAt: event.observedAt,
|
|
211
|
+
},
|
|
212
|
+
...(event.parentLink ? { parentToolCallId: event.parentLink.parentToolCallId } : {}),
|
|
213
|
+
}
|
|
214
|
+
case "context.compacted":
|
|
215
|
+
return {
|
|
216
|
+
type: event.type,
|
|
217
|
+
seq: event.eventSeq,
|
|
218
|
+
turnId: event.turnId,
|
|
219
|
+
reason: event.reason,
|
|
220
|
+
compactionReason: event.reason,
|
|
221
|
+
}
|
|
222
|
+
case "plan.updated":
|
|
223
|
+
return {
|
|
224
|
+
type: event.type,
|
|
225
|
+
seq: event.eventSeq,
|
|
226
|
+
turnId: event.turnId,
|
|
227
|
+
planId: event.planId,
|
|
228
|
+
status: event.status === "open" ? "running" : event.status,
|
|
229
|
+
steps: event.steps,
|
|
230
|
+
...(event.expandRef ? { expandRef: event.expandRef } : {}),
|
|
231
|
+
}
|
|
232
|
+
case "finding.detected":
|
|
233
|
+
return {
|
|
234
|
+
type: event.type,
|
|
235
|
+
seq: event.eventSeq,
|
|
236
|
+
turnId: event.turnId,
|
|
237
|
+
findingId: event.findingId,
|
|
238
|
+
category: event.category,
|
|
239
|
+
severity: event.severity,
|
|
240
|
+
text: event.summary,
|
|
241
|
+
evidence: event.evidence,
|
|
242
|
+
...(event.parentLink ? { parentToolCallId: event.parentLink.parentToolCallId } : {}),
|
|
243
|
+
}
|
|
244
|
+
case "result.produced":
|
|
245
|
+
return {
|
|
246
|
+
type: event.type,
|
|
247
|
+
seq: event.eventSeq,
|
|
248
|
+
turnId: event.turnId,
|
|
249
|
+
resultId: event.resultId,
|
|
250
|
+
status: event.status === "completed" ? "completed" : event.status,
|
|
251
|
+
toolSummary: event.summary,
|
|
252
|
+
action: event.action,
|
|
253
|
+
...(event.expandRef ? { expandRef: event.expandRef } : {}),
|
|
254
|
+
}
|
|
255
|
+
case "diagnostic.raised":
|
|
256
|
+
return {
|
|
257
|
+
type: event.type,
|
|
258
|
+
seq: event.eventSeq,
|
|
259
|
+
turnId: event.turnId,
|
|
260
|
+
category: event.category,
|
|
261
|
+
severity: event.severity,
|
|
262
|
+
message: event.message,
|
|
263
|
+
cause: event.cause,
|
|
264
|
+
action: event.action,
|
|
265
|
+
}
|
|
266
|
+
case "checkpoint.created":
|
|
267
|
+
return {
|
|
268
|
+
type: event.type,
|
|
269
|
+
seq: event.eventSeq,
|
|
270
|
+
turnId: event.turnId,
|
|
271
|
+
checkpointId: event.checkpointId,
|
|
272
|
+
paths: event.paths,
|
|
273
|
+
}
|
|
274
|
+
case "consequence.decided":
|
|
275
|
+
return {
|
|
276
|
+
type: event.type,
|
|
277
|
+
seq: event.eventSeq,
|
|
278
|
+
turnId: event.turnId,
|
|
279
|
+
verdict: event.verdict,
|
|
280
|
+
failureClass: event.failureClass,
|
|
281
|
+
nextAction: event.nextAction,
|
|
282
|
+
message: event.rationale,
|
|
283
|
+
severity: event.verdict === "FAIL" || event.verdict === "BLOCKED" ? "error" : "warning",
|
|
284
|
+
...(event.newEvidenceSinceLastAttempt !== undefined
|
|
285
|
+
? { newEvidenceSinceLastAttempt: event.newEvidenceSinceLastAttempt }
|
|
286
|
+
: {}),
|
|
287
|
+
}
|
|
288
|
+
case "context.window":
|
|
289
|
+
return {
|
|
290
|
+
type: event.type,
|
|
291
|
+
seq: event.eventSeq,
|
|
292
|
+
turnId: event.turnId,
|
|
293
|
+
usedTokens: event.usedTokens,
|
|
294
|
+
windowTokens: event.windowTokens,
|
|
295
|
+
...(event.percent !== undefined ? { percent: event.percent } : {}),
|
|
296
|
+
...(event.costUsd !== undefined ? { costUsd: event.costUsd } : {}),
|
|
297
|
+
...(event.providerModel ? { providerModel: event.providerModel } : {}),
|
|
298
|
+
}
|
|
299
|
+
case "context.cutoff":
|
|
300
|
+
return {
|
|
301
|
+
type: event.type,
|
|
302
|
+
seq: event.eventSeq,
|
|
303
|
+
turnId: event.turnId,
|
|
304
|
+
reason: event.reason,
|
|
305
|
+
message: event.reason,
|
|
306
|
+
severity: "warning",
|
|
307
|
+
...(event.usedTokens !== undefined ? { usedTokens: event.usedTokens } : {}),
|
|
308
|
+
...(event.windowTokens !== undefined ? { windowTokens: event.windowTokens } : {}),
|
|
309
|
+
}
|
|
310
|
+
case "task.status":
|
|
311
|
+
return {
|
|
312
|
+
type: event.type,
|
|
313
|
+
seq: event.eventSeq,
|
|
314
|
+
turnId: event.turnId,
|
|
315
|
+
taskId: event.taskId,
|
|
316
|
+
taskStatus: event.status,
|
|
317
|
+
...(event.parentId ? { parentId: event.parentId } : {}),
|
|
318
|
+
...(event.dependsOn ? { dependsOn: [...event.dependsOn] } : {}),
|
|
319
|
+
...(event.revision !== undefined ? { revision: event.revision } : {}),
|
|
320
|
+
...(event.verification ? { taskVerification: event.verification } : {}),
|
|
321
|
+
}
|
|
322
|
+
default: {
|
|
323
|
+
const exhaustive: never = event
|
|
324
|
+
void exhaustive
|
|
325
|
+
return null
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* P1.6: proyeksi UI membawa identitas session/child-run tanpa mengulang setiap
|
|
332
|
+
* case. `sessionId` DomainEvent adalah session pemilik event (anak untuk forward),
|
|
333
|
+
* `parentLink` adalah taut ke pemanggil.
|
|
334
|
+
*/
|
|
335
|
+
export function toPresentationEvent(event: DomainEvent): UiPresentationEvent | null {
|
|
336
|
+
const mapped = mapPresentationEvent(event)
|
|
337
|
+
if (!mapped) return null
|
|
338
|
+
const link = (event as { parentLink?: { childSessionId?: string; runId?: string } }).parentLink
|
|
339
|
+
return {
|
|
340
|
+
...mapped,
|
|
341
|
+
sessionId: event.sessionId,
|
|
342
|
+
...(link?.childSessionId ? { childSessionId: link.childSessionId } : {}),
|
|
343
|
+
...(link?.runId ? { runId: link.runId } : {}),
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
export function parseVerifyTestEvidence(
|
|
348
|
+
command: string,
|
|
349
|
+
output: string,
|
|
350
|
+
): { passed: number; failed: number; summary: string } | undefined {
|
|
351
|
+
if (!/(?:test|vitest|jest|pytest|cargo\s+test)/i.test(command)) return undefined
|
|
352
|
+
const passedMatch = /(\d+)\s+(?:pass(?:ed)?|successful?)/i.exec(output)
|
|
353
|
+
const failedMatch = /(\d+)\s+(?:fail(?:ed|ures?)?|failing)/i.exec(output)
|
|
354
|
+
if (!passedMatch && !failedMatch) return undefined
|
|
355
|
+
return {
|
|
356
|
+
passed: passedMatch ? Number(passedMatch[1]) : 0,
|
|
357
|
+
failed: failedMatch ? Number(failedMatch[1]) : 0,
|
|
358
|
+
summary:
|
|
359
|
+
output
|
|
360
|
+
.split(/\r?\n/)
|
|
361
|
+
.find((line) => /(?:pass|fail)/i.test(line))
|
|
362
|
+
?.trim()
|
|
363
|
+
.slice(0, 500) ?? "verify completed",
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/** Kompaksi LLM child session bersama (`canPersistMemory: false` mencegah polusi global). */
|
|
368
|
+
export function createChildCompaction(opts: {
|
|
369
|
+
provider: unknown
|
|
370
|
+
model?: string
|
|
371
|
+
cwd?: string
|
|
372
|
+
contextWindowTokensForModel?: (model?: string) => number
|
|
373
|
+
getContextModel?: () => string | undefined
|
|
374
|
+
}) {
|
|
375
|
+
const getWindow = opts.contextWindowTokensForModel
|
|
376
|
+
return createLlmCompaction({
|
|
377
|
+
provider: opts.provider as never,
|
|
378
|
+
getModel: () => opts.getContextModel?.() ?? opts.model,
|
|
379
|
+
cwd: opts.cwd ?? process.cwd(),
|
|
380
|
+
...(getWindow ? { getContextWindowTokens: () => getWindow(opts.model) } : {}),
|
|
381
|
+
canPersistMemory: () => false,
|
|
382
|
+
})
|
|
383
|
+
}
|
package/cli/commands/acp.ts
CHANGED
|
@@ -15,9 +15,28 @@ import { formatError } from "../../src/ui/assistant/simple.ts"
|
|
|
15
15
|
import type { UiPresentationEvent, UiPresentationSnapshot } from "../../src/ui/contract.ts"
|
|
16
16
|
import { formatUsd } from "../../src/ui/render/money.ts"
|
|
17
17
|
import { cleanUntrusted } from "../../src/ui/render/sanitize.ts"
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
allowLocalSubcommand,
|
|
20
|
+
displayWorkMode,
|
|
21
|
+
guardSubcommand,
|
|
22
|
+
parseWorkModeValue,
|
|
23
|
+
resolveWorkModeFlag,
|
|
24
|
+
} from "../args.ts"
|
|
19
25
|
import { createCliSession } from "../setup.ts"
|
|
20
26
|
|
|
27
|
+
const ACP_HELP = `minicode acp — minimal JSON-RPC stdio server for IDEs
|
|
28
|
+
|
|
29
|
+
minicode acp [--allow-local-config]`
|
|
30
|
+
|
|
31
|
+
const writeStdoutLine = (line: string): void => {
|
|
32
|
+
try {
|
|
33
|
+
process.stdout.write(`${line}\n`)
|
|
34
|
+
} catch {}
|
|
35
|
+
}
|
|
36
|
+
const writeStderrLine = (line: string): void => {
|
|
37
|
+
process.stderr.write(`${line}\n`)
|
|
38
|
+
}
|
|
39
|
+
|
|
21
40
|
// minicode acp — server JSON-RPC via stdio untuk IDE (Fase 5, subset minimal).
|
|
22
41
|
//
|
|
23
42
|
// BUKAN klaim kompatibel ACP penuh (Zed/JetBrains): hanya tiga method yang
|
|
@@ -27,7 +46,7 @@ import { createCliSession } from "../setup.ts"
|
|
|
27
46
|
//
|
|
28
47
|
// -> {"id":1,"method":"initialize","params":{"client":"zed"}}
|
|
29
48
|
// <- {"id":1,"result":{"server":"minicode-acp","capabilities":{...}}}
|
|
30
|
-
// -> {"id":2,"method":"run","params":{"prompt":"...","cwd":"...","model":"...","maxSteps":50,"timeoutMs":600000,"budget":0.5,"mode":"auto"|"ask","workMode":"DISCUSS"|"
|
|
49
|
+
// -> {"id":2,"method":"run","params":{"prompt":"...","cwd":"...","model":"...","maxSteps":50,"timeoutMs":600000,"budget":0.5,"mode":"auto"|"ask","workMode":"DISCUSS"|"BUILD"}}
|
|
31
50
|
// <- {"type":"text","delta":"..."} ... (notifikasi, tanpa id)
|
|
32
51
|
// <- {"type":"tool","name":"read_file"} ... (notifikasi legacy, tanpa id)
|
|
33
52
|
// <- {"type":"tool.started","toolCallId":"...","name":"read_file"} ...
|
|
@@ -95,7 +114,7 @@ export interface AcpRunParams {
|
|
|
95
114
|
budget?: number
|
|
96
115
|
mode?: "auto" | "ask"
|
|
97
116
|
/** WorkMode terpisah dari mode persetujuan; input BUILD dipetakan internal. */
|
|
98
|
-
workMode?: "DISCUSS" | "
|
|
117
|
+
workMode?: "DISCUSS" | "EXECUTE"
|
|
99
118
|
}
|
|
100
119
|
|
|
101
120
|
/** Validasi params `run`: prompt wajib non-kosong; angka harus hingga-positif;
|
|
@@ -125,7 +144,7 @@ export function parseRunParams(
|
|
|
125
144
|
? resolveWorkModeFlag(() => undefined).workMode
|
|
126
145
|
: parseWorkModeValue(String(p.workMode))
|
|
127
146
|
if (workMode === undefined)
|
|
128
|
-
return { ok: false, error: 'params.workMode must be "DISCUSS" | "
|
|
147
|
+
return { ok: false, error: 'params.workMode must be "DISCUSS" | "BUILD"' }
|
|
129
148
|
const out: AcpRunParams = { prompt, mode, workMode }
|
|
130
149
|
if (typeof p.cwd === "string" && p.cwd) out.cwd = p.cwd
|
|
131
150
|
if (typeof p.model === "string" && p.model) out.model = p.model
|
|
@@ -354,6 +373,7 @@ export interface AcpSessionDeps {
|
|
|
354
373
|
shouldExit: () => boolean
|
|
355
374
|
exit: (code: number) => void
|
|
356
375
|
createSession?: typeof createCliSession
|
|
376
|
+
allowLocalConfig?: boolean
|
|
357
377
|
}
|
|
358
378
|
|
|
359
379
|
/** Satu `run`: validasi → sesi headless → stream notifikasi → hasil/error
|
|
@@ -392,9 +412,9 @@ export async function runAcpSession(
|
|
|
392
412
|
verbose: false,
|
|
393
413
|
allowAll: false,
|
|
394
414
|
ask: rp.mode === "ask",
|
|
395
|
-
plan: false,
|
|
396
415
|
allowlist: false,
|
|
397
416
|
verify: false,
|
|
417
|
+
...(deps.allowLocalConfig ? { allowLocalConfig: true } : {}),
|
|
398
418
|
// WorkMode terpisah dari mode persetujuan; default DISCUSS.
|
|
399
419
|
workMode: rp.workMode,
|
|
400
420
|
budget: rp.budget,
|
|
@@ -452,7 +472,8 @@ export async function runAcpSession(
|
|
|
452
472
|
: `[budget] cost unknown (model without pricing) with ${ue.totalTokens} tokens spent - over budget, stopping.`
|
|
453
473
|
write(acpErr(id, msg, machineError(new Error(msg))))
|
|
454
474
|
} else {
|
|
455
|
-
const submitted = getSubmittedResult()
|
|
475
|
+
const submitted = getSubmittedResult(sessionId)
|
|
476
|
+
clearSubmittedResult(sessionId)
|
|
456
477
|
// submitted verbatim seperti exec --json (pipeline tak menebak
|
|
457
478
|
// batas); teks dis-scrub + di-cap (bisa megabyte).
|
|
458
479
|
write(
|
|
@@ -461,9 +482,9 @@ export async function runAcpSession(
|
|
|
461
482
|
sessionId: ctx.sessionId,
|
|
462
483
|
model: ctx.modelRef.current,
|
|
463
484
|
workMode: displayWorkMode(
|
|
464
|
-
((ctx as { workMode?: "DISCUSS" | "
|
|
485
|
+
((ctx as { workMode?: "DISCUSS" | "EXECUTE" }).workMode ??
|
|
465
486
|
rp.workMode ??
|
|
466
|
-
"DISCUSS") as "DISCUSS" | "
|
|
487
|
+
"DISCUSS") as "DISCUSS" | "EXECUTE",
|
|
467
488
|
),
|
|
468
489
|
tokens: ue.totalTokens,
|
|
469
490
|
inputTokens: ue.inputTokens,
|
|
@@ -485,13 +506,19 @@ export async function runAcpSession(
|
|
|
485
506
|
try {
|
|
486
507
|
const persist = (ctx as { persistCurrent?: (usage: unknown) => Promise<void> })
|
|
487
508
|
.persistCurrent
|
|
488
|
-
if (typeof persist === "function")
|
|
509
|
+
if (typeof persist === "function") {
|
|
510
|
+
const turnUsage =
|
|
511
|
+
typeof ctx.usage.get === "function"
|
|
512
|
+
? ctx.usage.get(ctx.modelRef.current)
|
|
513
|
+
: ctx.usage.getSession(ctx.modelRef.current)
|
|
514
|
+
await persist(turnUsage)
|
|
515
|
+
}
|
|
489
516
|
// P2.2: respons sukses sudah terkirim di atas (tepat-sekali per run);
|
|
490
517
|
// histori yang tak durable dilaporkan via stderr diagnostik, bukan
|
|
491
518
|
// pesan protokol kedua.
|
|
492
519
|
if (ctx.isWriterStale()) {
|
|
493
|
-
|
|
494
|
-
`[writer] stale writer sid=${ctx.sessionId}, history NOT durable: ${ctx.writerStaleNote()}
|
|
520
|
+
writeStderrLine(
|
|
521
|
+
`[writer] stale writer sid=${ctx.sessionId}, history NOT durable: ${ctx.writerStaleNote()}`,
|
|
495
522
|
)
|
|
496
523
|
}
|
|
497
524
|
} catch {}
|
|
@@ -568,14 +595,10 @@ export async function dispatchAcpLine(line: string, loop: AcpLoop): Promise<void
|
|
|
568
595
|
}
|
|
569
596
|
}
|
|
570
597
|
|
|
571
|
-
export async function handleAcp(): Promise<void> {
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
try {
|
|
576
|
-
process.stdout.write(`${line}\n`)
|
|
577
|
-
} catch {}
|
|
578
|
-
}
|
|
598
|
+
export async function handleAcp(args: readonly string[] = []): Promise<void> {
|
|
599
|
+
guardSubcommand(args, "acp", ACP_HELP, writeStdoutLine, writeStderrLine)
|
|
600
|
+
const allowLocalConfig = allowLocalSubcommand(args)
|
|
601
|
+
const write = writeStdoutLine
|
|
579
602
|
const flight = createFlight()
|
|
580
603
|
let shuttingDown = false
|
|
581
604
|
// Run sedang berjalan (termasuk antrean setup): flight.active() saja TIDAK
|
|
@@ -591,6 +614,7 @@ export async function handleAcp(): Promise<void> {
|
|
|
591
614
|
startFlight: (abort) => flight.start(abort),
|
|
592
615
|
shouldExit: () => shuttingDown,
|
|
593
616
|
exit: (code) => process.exit(code),
|
|
617
|
+
allowLocalConfig,
|
|
594
618
|
})
|
|
595
619
|
} finally {
|
|
596
620
|
busy = false
|
|
@@ -606,22 +630,14 @@ export async function handleAcp(): Promise<void> {
|
|
|
606
630
|
shuttingDown = true
|
|
607
631
|
},
|
|
608
632
|
exit: (code) => process.exit(code),
|
|
609
|
-
warnMalformed: () =>
|
|
633
|
+
warnMalformed: () => writeStderrLine("[acp] ignoring malformed line"),
|
|
610
634
|
}
|
|
611
635
|
|
|
612
636
|
const rl = createInterface({ input: process.stdin, crlfDelay: Infinity })
|
|
613
|
-
// Event-driven, BUKAN for-await sekuensial: `cancel`/`shutdown` harus bisa
|
|
614
|
-
// menyela run yang berjalan. for-await menahan baris berikutnya sampai run
|
|
615
|
-
// selesai — cancel di stdin tak pernah terbaca (fitur mati di produksi).
|
|
616
|
-
// Tiap baris didispatch tanpa await; prefik sinkron dispatch (parse →
|
|
617
|
-
// runOne → startFlight) tetap berurutan per event, jadi run kedua melihat
|
|
618
|
-
// flight aktif dan ditolak jujur.
|
|
619
637
|
let inflight: Promise<void> | null = null
|
|
620
638
|
rl.on("line", (line: string) => {
|
|
621
639
|
const p = dispatchAcpLine(line, loop).catch((e: unknown) => {
|
|
622
|
-
|
|
623
|
-
// jangan biarkan satu baris jahat membunuh server diam-diam.
|
|
624
|
-
process.stderr.write(`[acp] dispatch failed: ${(e as Error)?.message ?? e}\n`)
|
|
640
|
+
writeStderrLine(`[acp] dispatch failed: ${(e as Error)?.message ?? e}`)
|
|
625
641
|
})
|
|
626
642
|
inflight = p
|
|
627
643
|
void p.finally(() => {
|
package/cli/commands/auth.ts
CHANGED
|
@@ -7,7 +7,10 @@ import {
|
|
|
7
7
|
OAUTH_PROVIDERS,
|
|
8
8
|
} from "../../src/providers/oauth.ts"
|
|
9
9
|
import { saveProvider } from "../../src/providers/provision.ts"
|
|
10
|
-
import {
|
|
10
|
+
import { formatError } from "../../src/ui/render/errors.ts"
|
|
11
|
+
import { sanitizeAnsiLine } from "../../src/ui/render/sanitize.ts"
|
|
12
|
+
import { c } from "../../src/ui/render/theme.ts"
|
|
13
|
+
import { hasHelpFlag, positionalSubArg } from "../args.ts"
|
|
11
14
|
|
|
12
15
|
function usage(code = 0): never {
|
|
13
16
|
console.log(`minicode auth — OAuth login (no API key)
|
|
@@ -24,7 +27,7 @@ Tokens are stored at ${authFilePath()} (chmod 600), NOT in config.json.`)
|
|
|
24
27
|
export async function handleAuth(args: string[]): Promise<never> {
|
|
25
28
|
const sub = (args[1] ?? "").toLowerCase()
|
|
26
29
|
|
|
27
|
-
if (!sub || sub === "help" ||
|
|
30
|
+
if (!sub || sub === "help" || hasHelpFlag(args)) usage()
|
|
28
31
|
|
|
29
32
|
if (sub === "list") {
|
|
30
33
|
console.log(`\n${c.bold("Providers with OAuth support")}`)
|
|
@@ -50,44 +53,41 @@ export async function handleAuth(args: string[]): Promise<never> {
|
|
|
50
53
|
? c.yellow("expired (auto-refresh)")
|
|
51
54
|
: c.red("expired (re-login required)")
|
|
52
55
|
: c.green("active")
|
|
53
|
-
console.log(
|
|
56
|
+
console.log(
|
|
57
|
+
` ${c.cyan(sanitizeAnsiLine(r.providerId).padEnd(12))} ${state} ${c.dim(`exp ${exp}`)}`,
|
|
58
|
+
)
|
|
54
59
|
}
|
|
55
60
|
console.log("")
|
|
56
61
|
process.exit(0)
|
|
57
62
|
}
|
|
58
63
|
|
|
59
64
|
if (sub === "logout") {
|
|
60
|
-
|
|
61
|
-
// --cwd X` adalah lupa argumen, bukan kredensial bernama "--cwd".
|
|
62
|
-
const id = args[2] && !args[2]!.startsWith("-") ? args[2] : undefined
|
|
65
|
+
const id = positionalSubArg(args, 2)
|
|
63
66
|
if (!id) {
|
|
64
67
|
console.error("usage: minicode auth logout <provider>")
|
|
65
68
|
process.exit(2)
|
|
66
69
|
}
|
|
67
70
|
const ok = await removeAuth(id)
|
|
71
|
+
const safeId = sanitizeAnsiLine(id)
|
|
68
72
|
console.log(
|
|
69
|
-
ok ? `${c.green(
|
|
73
|
+
ok ? `${c.green("ok")} credentials "${safeId}" removed` : `(no credentials for "${safeId}")`,
|
|
70
74
|
)
|
|
71
75
|
process.exit(0)
|
|
72
76
|
}
|
|
73
77
|
|
|
74
78
|
if (sub !== "login") {
|
|
75
|
-
|
|
76
|
-
// dan bukan gagal runtime (exit 1).
|
|
77
|
-
console.error(`unknown auth subcommand: ${sub}`)
|
|
79
|
+
console.error(`unknown auth subcommand: ${sanitizeAnsiLine(sub)}`)
|
|
78
80
|
usage(2)
|
|
79
81
|
}
|
|
80
82
|
|
|
81
83
|
// ── login ──
|
|
82
|
-
// Device flow butuh browser + persetujuan manusia — di non-TTY (CI/pipe)
|
|
83
|
-
// gagalkan cepat dengan pesan jelas, bukan menembak jaringan lalu gagal 400.
|
|
84
84
|
if (!process.stdin.isTTY) {
|
|
85
85
|
console.error(
|
|
86
86
|
"auth login needs an interactive terminal (device-code approval happens in a browser)",
|
|
87
87
|
)
|
|
88
88
|
process.exit(1)
|
|
89
89
|
}
|
|
90
|
-
const requested = args
|
|
90
|
+
const requested = positionalSubArg(args, 2) ?? OAUTH_PROVIDERS[0]?.id
|
|
91
91
|
if (!requested) {
|
|
92
92
|
console.error("no OAuth providers registered")
|
|
93
93
|
process.exit(1)
|
|
@@ -95,7 +95,7 @@ export async function handleAuth(args: string[]): Promise<never> {
|
|
|
95
95
|
const spec = findOAuthProvider(requested)
|
|
96
96
|
if (!spec) {
|
|
97
97
|
console.error(
|
|
98
|
-
`provider "${requested}" does not support OAuth. Available: ${OAUTH_PROVIDERS.map((p) => p.id).join(", ")}`,
|
|
98
|
+
`provider "${sanitizeAnsiLine(requested)}" does not support OAuth. Available: ${OAUTH_PROVIDERS.map((p) => p.id).join(", ")}`,
|
|
99
99
|
)
|
|
100
100
|
process.exit(1)
|
|
101
101
|
}
|
|
@@ -127,7 +127,7 @@ export async function handleAuth(args: string[]): Promise<never> {
|
|
|
127
127
|
},
|
|
128
128
|
})
|
|
129
129
|
process.stderr.write("\r \r")
|
|
130
|
-
console.log(`${c.green(
|
|
130
|
+
console.log(`${c.green("ok")} login successful`)
|
|
131
131
|
|
|
132
132
|
// Daftarkan provider bila belum ada. apiKey dibiarkan kosong: tokennya
|
|
133
133
|
// hidup di auth.json dan diambil saat runtime oleh buildProviderListAsync.
|
|
@@ -155,13 +155,13 @@ export async function handleAuth(args: string[]): Promise<never> {
|
|
|
155
155
|
{ global: true },
|
|
156
156
|
)
|
|
157
157
|
console.log(
|
|
158
|
-
`${c.green(
|
|
158
|
+
`${c.green("ok")} provider "${c.bold(spec.id)}" ready (${models.length} models)\n` +
|
|
159
159
|
` ${c.dim(`try: minicode --provider ${spec.id} "hello"`)}\n`,
|
|
160
160
|
)
|
|
161
161
|
process.exit(0)
|
|
162
162
|
} catch (e) {
|
|
163
163
|
process.stderr.write("\r \r")
|
|
164
|
-
console.error(
|
|
164
|
+
console.error(c.red(formatError(e)))
|
|
165
165
|
process.exit(1)
|
|
166
166
|
} finally {
|
|
167
167
|
process.off("SIGINT", onSigint)
|