pantheon-opencode 1.6.0-beta.9 → 1.6.1

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.
Files changed (140) hide show
  1. package/AGENTS.global.md +118 -0
  2. package/AGENTS.md +18 -168
  3. package/CHANGELOG.md +144 -365
  4. package/README.md +124 -607
  5. package/README.pt-BR.md +120 -345
  6. package/bin/pantheon-init.mjs +504 -141
  7. package/commands/pantheon-deepwork.md +14 -3
  8. package/commands/pantheon-vision.md +61 -12
  9. package/package.json +22 -13
  10. package/plugin.json +1 -1
  11. package/pyproject.toml +6 -2
  12. package/scripts/_pantheon_paths.py +24 -0
  13. package/scripts/build-agents-md.mjs +368 -69
  14. package/scripts/changelog-merge.mjs +161 -0
  15. package/scripts/check-plugin-v2-coverage.mjs +11 -8
  16. package/scripts/docs-check-changelog.mjs +204 -0
  17. package/scripts/docs-link-check.mjs +314 -0
  18. package/scripts/docs-media.mjs +157 -0
  19. package/scripts/doctor.mjs +850 -45
  20. package/scripts/install/agents-md.mjs +2 -2
  21. package/scripts/install/backup.mjs +648 -0
  22. package/scripts/install/cli-ui.mjs +303 -72
  23. package/scripts/install/component-selection.mjs +61 -0
  24. package/scripts/install/config-migration.mjs +583 -27
  25. package/scripts/install/exit-codes.mjs +26 -0
  26. package/scripts/install/file-inventory.mjs +555 -0
  27. package/scripts/install/health-check.mjs +31 -25
  28. package/scripts/install/interactive.mjs +99 -383
  29. package/scripts/install/interrupt.mjs +78 -0
  30. package/scripts/install/migrate.mjs +49 -25
  31. package/scripts/install/model-picker.mjs +218 -250
  32. package/scripts/install/opencode-state.mjs +91 -0
  33. package/scripts/install/opencode-version.mjs +83 -21
  34. package/scripts/install/opencode.mjs +1675 -187
  35. package/scripts/install/plan-artifact.mjs +517 -0
  36. package/scripts/install/plan.mjs +475 -0
  37. package/scripts/install/plugin.mjs +214 -27
  38. package/scripts/install/prompt-result.mjs +2 -0
  39. package/scripts/install/run-record.mjs +115 -0
  40. package/scripts/install/shared.mjs +256 -99
  41. package/scripts/install/state.mjs +63 -8
  42. package/scripts/install/strings.mjs +93 -8
  43. package/scripts/install/v2-capabilities.mjs +205 -0
  44. package/scripts/install/venv.mjs +90 -47
  45. package/scripts/install/verify.mjs +128 -0
  46. package/scripts/install/vision-prompt.mjs +173 -0
  47. package/scripts/install-mcp.mjs +2 -2
  48. package/scripts/manifest-inventory.mjs +49 -3
  49. package/scripts/mcp_persistence.py +1535 -1050
  50. package/scripts/memory_mcp.py +12 -843
  51. package/scripts/node-engine-policy.mjs +85 -0
  52. package/scripts/package-evidence.mjs +10 -2
  53. package/scripts/postinstall.mjs +26 -26
  54. package/scripts/probe-pantheon-cost.mjs +118 -19
  55. package/scripts/prune.mjs +9 -3
  56. package/scripts/reconcile.mjs +325 -0
  57. package/scripts/release-gates.mjs +687 -0
  58. package/scripts/restore.mjs +222 -0
  59. package/scripts/run-node-tests.mjs +24 -8
  60. package/scripts/sync-artifacts.mjs +19 -7
  61. package/scripts/sync-tui.mjs +5 -1
  62. package/scripts/test-opencode-v2-sandbox.sh +36 -123
  63. package/scripts/uninstall.mjs +369 -34
  64. package/scripts/update.mjs +164 -0
  65. package/scripts/validate-node-engine-policy.mjs +13 -0
  66. package/scripts/version-check.mjs +34 -1
  67. package/scripts/versioning.mjs +23 -3
  68. package/scripts/vision-status.mjs +682 -0
  69. package/skills-lock.json +8 -8
  70. package/src/agents/aphrodite.md +13 -10
  71. package/src/agents/apollo.md +4 -5
  72. package/src/agents/athena.md +74 -46
  73. package/src/agents/demeter.md +10 -7
  74. package/src/agents/gaia.md +0 -1
  75. package/src/agents/hephaestus.md +4 -3
  76. package/src/agents/hermes.md +10 -9
  77. package/src/agents/iris.md +6 -1
  78. package/src/agents/mnemosyne.md +10 -4
  79. package/src/agents/nyx.md +4 -4
  80. package/src/agents/prometheus.md +12 -11
  81. package/src/agents/talos.md +6 -0
  82. package/src/agents/zeus.md +84 -56
  83. package/src/instructions/agent-return-format.instructions.md +12 -41
  84. package/src/instructions/memory-protocol.instructions.md +5 -11
  85. package/src/instructions/test-economy.instructions.md +12 -0
  86. package/src/instructions/yagni.instructions.md +6 -15
  87. package/src/instructions/zeus-anti-stall.instructions.md +6 -6
  88. package/src/instructions/zeus-communication-rules.instructions.md +6 -6
  89. package/src/instructions/zeus-council-synthesis.instructions.md +11 -12
  90. package/src/instructions/zeus-memory-operations.instructions.md +13 -7
  91. package/src/instructions/zeus-timeout-retry.instructions.md +36 -10
  92. package/src/mcp/_pantheon_paths.py +24 -0
  93. package/src/mcp/mcp_codemap_module.py +86 -18
  94. package/src/mcp/mcp_persistence.py +1535 -1050
  95. package/src/mcp/memory_mcp.py +444 -94
  96. package/src/mcp/pantheon_vision.py +285 -41
  97. package/src/mcp/requirements-mcp.txt +6 -1
  98. package/src/mcp/requirements-vision.txt +1 -1
  99. package/src/pantheon/context-pruner.ts +541 -0
  100. package/src/pantheon/cost-command.ts +901 -60
  101. package/src/pantheon/delegation-enforce.ts +160 -23
  102. package/src/pantheon/goal-loop.ts +11 -8
  103. package/src/pantheon/guard-path.ts +162 -0
  104. package/src/pantheon/memory-context.ts +1017 -0
  105. package/src/pantheon/model-agents.ts +19 -0
  106. package/src/pantheon/model-command.ts +218 -56
  107. package/src/pantheon/model-pricing.ts +536 -0
  108. package/src/pantheon/presets.mjs +2 -0
  109. package/src/pantheon/task-result-guard.ts +50 -14
  110. package/src/pantheon/v2-bounded-read.ts +654 -0
  111. package/src/pantheon/v2-bridge.ts +27 -0
  112. package/src/pantheon/v2-delegation-enforce.ts +133 -6
  113. package/src/pantheon/v2-execute-after.ts +135 -24
  114. package/src/pantheon/v2-model-overrides.ts +275 -0
  115. package/src/pantheon/v2-shell-hooks.ts +260 -0
  116. package/src/pantheon/v2-tools.ts +89 -35
  117. package/src/pantheon/v2-unsupported.mjs +34 -7
  118. package/src/pantheon/v2-vision.ts +622 -0
  119. package/src/pantheon/vision-local.ts +531 -0
  120. package/src/pantheon/vision.ts +1166 -116
  121. package/src/plugin-v2.ts +1039 -171
  122. package/src/plugin.ts +37 -13
  123. package/src/plugins/tui/dist/tui-v2.d.ts +1029 -2
  124. package/src/plugins/tui/dist/tui-v2.d.ts.map +1 -1
  125. package/src/plugins/tui/dist/tui-v2.js +3742 -85
  126. package/src/plugins/tui/dist/tui.js +1 -1
  127. package/src/plugins/tui/package-lock.json +15 -15
  128. package/src/plugins/tui/package.json +7 -5
  129. package/src/plugins/tui/src/index-v2.tsx +4314 -50
  130. package/src/plugins/tui/tsconfig.typecheck.json +5 -0
  131. package/src/routing.yml +50 -5
  132. package/src/skills/agent-coordination/SKILL.md +7 -2
  133. package/src/skills/artifact-management/SKILL.md +5 -1
  134. package/src/skills/auto-continue/SKILL.md +14 -6
  135. package/src/skills/codemap/SKILL.md +1 -1
  136. package/src/skills/memory-bank/SKILL.md +21 -13
  137. package/src/skills/session-goal/SKILL.md +12 -22
  138. package/src/skills/spec-driven-development/SKILL.md +3 -1
  139. package/src/skills/worktrees/SKILL.md +30 -11
  140. package/scripts/probe-context-rehydrate.mjs +0 -263
@@ -1,406 +1,122 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { emitKeypressEvents } from 'node:readline'
4
- import { colors } from './cli-ui.mjs'
3
+ import * as clack from '@clack/prompts'
4
+ import { PROMPT_CANCELED } from './prompt-result.mjs'
5
+ import { strings } from './strings.mjs'
5
6
 
6
- const cursorHide = () => process.stdout.write('\x1b[?25l')
7
- const cursorShow = () => process.stdout.write('\x1b[?25h')
8
- const cursorUp = (n) => process.stdout.write(`\x1b[${n}A`)
9
- const clearDown = () => process.stdout.write('\x1b[J')
7
+ export { PROMPT_CANCELED }
10
8
 
11
- function setupStdin() {
12
- if (!process.stdin.isTTY) return false
13
- if (!process.stdout.isTTY) return false
14
- emitKeypressEvents(process.stdin)
15
- try {
16
- process.stdin.setRawMode(true)
17
- } catch {
18
- return false
19
- }
20
- process.stdin.resume()
21
- return true
9
+ function isTerminal() {
10
+ return Boolean(process.stdin.isTTY && process.stdout.isTTY)
22
11
  }
23
12
 
24
- function teardownStdin() {
25
- try {
26
- process.stdin.setRawMode(false)
27
- process.stdin.removeAllListeners('keypress')
28
- process.stdin.pause()
29
- } catch {
30
- /* safe to ignore */
31
- }
13
+ /**
14
+ * Print the ONE cancel line, naming where the user stopped.
15
+ *
16
+ * The point is a stable key from the string table (`cancelPoints`), so the same
17
+ * identifier can be persisted in the run record without parsing prose.
18
+ *
19
+ * @param {typeof clack} prompts
20
+ * @param {unknown} value a prompt result
21
+ * @param {string} point stable cancel-point key
22
+ * @returns {boolean} whether the prompt was canceled
23
+ */
24
+ function cancelPrompt(prompts, value, point) {
25
+ if (!prompts.isCancel(value)) return false
26
+ const S = strings()
27
+ prompts.cancel(S.canceledAt(S.cancelPoints[point] ?? point))
28
+ return true
32
29
  }
33
30
 
34
- export async function promptMultiSelect(
35
- options,
36
- { title = '', selected = new Set(), pageSize = 6 } = {},
31
+ /**
32
+ * Prompt for authorization to apply a reviewed installer plan.
33
+ *
34
+ * @param {string} planSummary Summary of the changes that require approval.
35
+ * @param {{ default?: boolean, prompts?: typeof clack, isTTY?: boolean }} [options]
36
+ * @returns {Promise<boolean | typeof PROMPT_CANCELED>} True if authorized, false if declined, or the cancellation sentinel.
37
+ */
38
+ export async function promptReview(
39
+ planSummary,
40
+ { default: defaultValue = false, prompts = clack, isTTY = isTerminal() } = {},
37
41
  ) {
38
- if (options.length === 0) return new Set()
39
-
40
- const preSelected = selected instanceof Set ? selected : new Set(selected)
41
- const items = options.map((o) => ({
42
- name: o.name,
43
- value: o.value,
44
- description: o.description || '',
45
- checked: o.checked || preSelected.has(o.value),
46
- }))
47
-
48
- let cursor = 0
49
- let scroll = 0
50
- const maxVisible = Math.min(pageSize, options.length)
51
- let previousLineCount = 0
52
-
53
- const isTTY = setupStdin()
54
- if (!isTTY) {
55
- return new Set(items.filter((i) => i.checked).map((i) => i.value))
56
- }
57
- cursorHide()
58
-
59
- function render() {
60
- if (cursor < scroll) scroll = cursor
61
- if (cursor >= scroll + maxVisible) scroll = cursor - maxVisible + 1
62
-
63
- const visible = items.slice(scroll, scroll + maxVisible)
64
- const lines = []
65
-
66
- if (title) lines.push(colors.bold(title))
67
-
68
- const hasMoreAbove = scroll > 0
69
- const hasMoreBelow = scroll + maxVisible < options.length
70
-
71
- if (hasMoreAbove) lines.push(colors.dim(' ...'))
72
-
73
- for (let i = 0; i < visible.length; i++) {
74
- const item = visible[i]
75
- const idx = scroll + i
76
- const active = idx === cursor
77
- const box = item.checked ? '[x]' : '[ ]'
78
- const ptr = active ? `${colors.cyan('>')} ` : ' '
79
- const name = active ? colors.cyan(item.name) : item.name
80
- const desc = item.description ? colors.dim(` — ${item.description}`) : ''
81
- lines.push(`${ptr}${colors.bold(box)} ${name}${desc}`)
82
- }
83
-
84
- if (hasMoreBelow) lines.push(colors.dim(' ...'))
85
-
86
- const count = items.filter((i) => i.checked).length
87
- const total = items.length
88
- const noun = count === 1 ? 'selected' : 'selected'
89
- lines.push(
90
- colors.dim(
91
- `(${count}/${total} ${noun}) — ${colors.cyan('↑')}${colors.dim('/')}${colors.cyan('↓')} navigate · ${colors.cyan('Space')}${colors.dim(' toggle · ')}${colors.cyan('Enter')}${colors.dim(' confirm')}`,
92
- ),
93
- )
94
-
95
- const lineCount = lines.length
96
- if (previousLineCount > 0) cursorUp(previousLineCount)
97
- clearDown()
98
- process.stdout.write(`${lines.join('\n')}\n`)
99
- previousLineCount = lineCount
100
- }
101
-
102
- return new Promise((resolve, reject) => {
103
- let settled = false
104
-
105
- function finalize(result) {
106
- if (settled) return
107
- settled = true
108
- cursorShow()
109
- teardownStdin()
110
- if (previousLineCount > 0) cursorUp(previousLineCount)
111
- clearDown()
112
- resolve(result)
113
- }
114
-
115
- function cancel() {
116
- if (settled) return
117
- settled = true
118
- cursorShow()
119
- teardownStdin()
120
- if (previousLineCount > 0) cursorUp(previousLineCount)
121
- clearDown()
122
- reject(new Error('Canceled'))
123
- }
124
-
125
- function handler(_str, key) {
126
- if (!key) return
127
- if ((key.ctrl && key.name === 'c') || key.name === 'escape') {
128
- cancel()
129
- return
130
- }
131
- if (key.name === 'return' || key.name === 'enter') {
132
- const result = new Set(items.filter((i) => i.checked).map((i) => i.value))
133
- finalize(result)
134
- return
135
- }
136
- if (key.name === 'up') {
137
- cursor = (cursor - 1 + items.length) % items.length
138
- render()
139
- return
140
- }
141
- if (key.name === 'down') {
142
- cursor = (cursor + 1) % items.length
143
- render()
144
- return
145
- }
146
- if (key.name === 'space') {
147
- items[cursor].checked = !items[cursor].checked
148
- render()
149
- return
150
- }
151
- }
152
-
153
- process.stdin.on('keypress', handler)
154
- render()
155
- })
156
- }
157
-
158
- export async function promptConfirm(message, { default: def = true } = {}) {
159
- const label = def ? 'Y/n' : 'y/N'
160
- const isTTY = setupStdin()
161
- if (!isTTY) return def
162
-
163
- cursorHide()
164
- process.stdout.write(`${colors.bold('?')} ${message} ${colors.cyan(label)} `)
165
-
166
- return new Promise((resolve, reject) => {
167
- let settled = false
168
-
169
- function finalize(result) {
170
- if (settled) return
171
- settled = true
172
- cursorShow()
173
- teardownStdin()
174
- process.stdout.write(`${result ? 'Yes' : 'No'}\n`)
175
- resolve(result)
176
- }
177
-
178
- function cancel() {
179
- if (settled) return
180
- settled = true
181
- cursorShow()
182
- teardownStdin()
183
- process.stdout.write('\n')
184
- reject(new Error('Canceled'))
185
- }
186
-
187
- function handler(_str, key) {
188
- if (!key) return
189
- if ((key.ctrl && key.name === 'c') || key.name === 'escape') {
190
- cancel()
191
- return
192
- }
193
- if (key.name === 'return' || key.name === 'enter') {
194
- finalize(def)
195
- return
196
- }
197
- if (str) {
198
- const ch = str.toLowerCase()
199
- if (ch === 'y' || ch === 'yes') {
200
- finalize(true)
201
- } else if (ch === 'n' || ch === 'no') {
202
- finalize(false)
203
- }
204
- }
205
- }
206
-
207
- process.stdin.on('keypress', handler)
208
- })
42
+ if (!isTTY) return false
43
+ const result = await prompts.confirm({ message: planSummary, initialValue: defaultValue })
44
+ if (cancelPrompt(prompts, result, 'review')) return PROMPT_CANCELED
45
+ return result === true
209
46
  }
210
47
 
211
- export async function promptList(options, { title = '' } = {}) {
212
- if (options.length === 0) throw new Error('No options provided')
213
- if (options.length === 1) return options[0].value
214
-
215
- const items = options.map((o) => ({
216
- name: o.name,
217
- value: o.value,
218
- description: o.description || '',
219
- }))
220
-
221
- let cursor = 0
222
- const pageSize = Math.min(8, options.length)
223
- let scroll = 0
224
- const maxVisible = Math.min(pageSize, options.length)
225
- let previousLineCount = 0
226
-
227
- const isTTY = setupStdin()
228
- if (!isTTY) return items[0].value
229
- cursorHide()
230
-
231
- function render() {
232
- if (cursor < scroll) scroll = cursor
233
- if (cursor >= scroll + maxVisible) scroll = cursor - maxVisible + 1
234
-
235
- const visible = items.slice(scroll, scroll + maxVisible)
236
- const lines = []
237
-
238
- if (title) lines.push(colors.bold(title))
239
-
240
- const hasMoreAbove = scroll > 0
241
- const hasMoreBelow = scroll + maxVisible < options.length
242
-
243
- if (hasMoreAbove) lines.push(colors.dim(' ...'))
244
-
245
- for (let i = 0; i < visible.length; i++) {
246
- const item = visible[i]
247
- const idx = scroll + i
248
- const active = idx === cursor
249
- const ptr = active ? `${colors.cyan('>')} ` : ' '
250
- const name = active ? colors.cyan(item.name) : item.name
251
- const desc = item.description ? colors.dim(` — ${item.description}`) : ''
252
- lines.push(`${ptr}${colors.bold('◉')} ${name}${desc}`)
253
- }
254
-
255
- if (hasMoreBelow) lines.push(colors.dim(' ...'))
256
-
257
- lines.push(
258
- colors.dim(
259
- `(${colors.cyan('↑')}${colors.dim('/')}${colors.cyan('↓')} navigate · ${colors.cyan('Enter')}${colors.dim(' select')}`,
260
- ),
261
- )
262
-
263
- const lineCount = lines.length
264
- if (previousLineCount > 0) cursorUp(previousLineCount)
265
- clearDown()
266
- process.stdout.write(`${lines.join('\n')}\n`)
267
- previousLineCount = lineCount
268
- }
269
-
270
- return new Promise((resolve, reject) => {
271
- let settled = false
272
-
273
- function finalize(result) {
274
- if (settled) return
275
- settled = true
276
- cursorShow()
277
- teardownStdin()
278
- if (previousLineCount > 0) cursorUp(previousLineCount)
279
- clearDown()
280
- resolve(result)
281
- }
282
-
283
- function cancel() {
284
- if (settled) return
285
- settled = true
286
- cursorShow()
287
- teardownStdin()
288
- if (previousLineCount > 0) cursorUp(previousLineCount)
289
- clearDown()
290
- reject(new Error('Canceled'))
291
- }
292
-
293
- function handler(_str, key) {
294
- if (!key) return
295
- if ((key.ctrl && key.name === 'c') || key.name === 'escape') {
296
- cancel()
297
- return
298
- }
299
- if (key.name === 'return' || key.name === 'enter') {
300
- finalize(items[cursor].value)
301
- return
302
- }
303
- if (key.name === 'up') {
304
- cursor = (cursor - 1 + items.length) % items.length
305
- render()
306
- return
307
- }
308
- if (key.name === 'down') {
309
- cursor = (cursor + 1) % items.length
310
- render()
311
- return
312
- }
313
- }
314
-
315
- process.stdin.on('keypress', handler)
316
- render()
317
- })
318
- }
319
-
320
- export async function runInteractiveInstall({ components = [], defaultComponents = [] } = {}) {
321
- const defaultSet = new Set(defaultComponents.length > 0 ? defaultComponents : components)
48
+ /**
49
+ * Collect interactive setup choices before the installer begins any writes.
50
+ *
51
+ * @param {{ components?: string[], defaultComponents?: string[], noMcp?: boolean, prompts?: typeof clack, isTTY?: boolean }} [options]
52
+ * @returns {Promise<{ components?: Set<string>, target?: string, confirmed?: boolean, canceled?: boolean, cancelPoint?: string }>}
53
+ *
54
+ * `cancelPoint` names the step the user stopped at (`components`, `target`,
55
+ * `confirmation`), so the caller can print one explainable line and persist the
56
+ * same stable key in the run record.
57
+ */
58
+ export async function runInteractiveInstall({
59
+ components = [],
60
+ defaultComponents = [],
61
+ noMcp = false,
62
+ prompts = clack,
63
+ isTTY = isTerminal(),
64
+ } = {}) {
65
+ const isAllowed = (component) => !noMcp || component !== 'runtime'
66
+ const defaults = (defaultComponents.length > 0 ? defaultComponents : components).filter(isAllowed)
67
+ const defaultSet = new Set(defaults)
68
+
69
+ // Preserve the prior no-TTY fallback (defaults, global target, and no apply
70
+ // authorization) without asking a terminal prompt library to access stdin.
71
+ if (!isTTY) return { components: defaultSet, target: 'global', confirmed: true }
72
+
73
+ prompts.intro?.('OpenCode Installer')
322
74
 
323
75
  const componentOptions = [
324
- {
325
- name: 'agents',
326
- value: 'agents',
327
- description: `Agent configurations and routing (${14} agents)`,
328
- },
329
- {
330
- name: 'skills',
331
- value: 'skills',
332
- description: `Reusable skill workflows (${20} skills)`,
333
- },
334
- {
335
- name: 'instructions',
336
- value: 'instructions',
337
- description: 'AGENTS.md and instructional files',
338
- },
339
- {
340
- name: 'prompts',
341
- value: 'prompts',
342
- description: 'Prompt templates for agents',
343
- },
344
- {
345
- name: 'commands',
346
- value: 'commands',
347
- description: 'OpenCode command shortcuts',
348
- },
349
- {
350
- name: 'plugins',
351
- value: 'plugins',
352
- description: 'TUI sidebar plugin',
353
- },
354
- {
355
- name: 'runtime',
356
- value: 'runtime',
357
- description: 'Python venv + MCP server scripts',
358
- },
359
- ]
360
-
361
- process.stdout.write('\n')
362
- process.stdout.write(`${colors.bold(colors.cyan('📦 OpenCode Installer'))}\n\n`)
363
-
364
- const selectedComponents = await promptMultiSelect(componentOptions, {
365
- title: 'Select components to install:',
366
- selected: defaultSet,
367
- pageSize: 7,
76
+ { label: 'agents', value: 'agents', hint: 'Agent configurations and routing (14 agents)' },
77
+ { label: 'skills', value: 'skills', hint: `Reusable skill workflows (${20} skills)` },
78
+ { label: 'instructions', value: 'instructions', hint: 'AGENTS.md and instructional files' },
79
+ { label: 'prompts', value: 'prompts', hint: 'Prompt templates for agents' },
80
+ { label: 'commands', value: 'commands', hint: 'OpenCode command shortcuts' },
81
+ { label: 'plugins', value: 'plugins', hint: 'TUI sidebar plugin' },
82
+ { label: 'runtime', value: 'runtime', hint: 'Python venv + MCP server scripts' },
83
+ ].filter((option) => isAllowed(option.value))
84
+ const chosen = await prompts.multiselect({
85
+ message: 'Select components to install:',
86
+ options: componentOptions,
87
+ initialValues: [...defaultSet],
88
+ required: false,
368
89
  })
90
+ if (cancelPrompt(prompts, chosen, 'components'))
91
+ return { canceled: true, cancelPoint: 'components' }
369
92
 
370
- process.stdout.write('\n')
371
-
93
+ const selectedComponents = new Set(chosen.filter(isAllowed))
372
94
  if (selectedComponents.size === 0) {
373
- process.stdout.write(`${colors.yellow('No components selected — using defaults\n')}`)
374
- defaultSet.forEach((v) => {
375
- selectedComponents.add(v)
376
- })
95
+ const S = strings()
96
+ prompts.cancel?.(S.canceledAt(S.cancelPoints.components))
97
+ return { canceled: true, cancelPoint: 'components' }
377
98
  }
378
99
 
379
- const targetOptions = [
380
- {
381
- name: 'Global directory',
382
- value: 'global',
383
- description: '~/.config/opencode (shared across projects)',
384
- },
385
- {
386
- name: 'Current project',
387
- value: 'project',
388
- description: './.opencode (scoped to this project)',
389
- },
390
- ]
391
-
392
- const target = await promptList(targetOptions, {
393
- title: 'Install location:',
100
+ const target = await prompts.select({
101
+ message: 'Install location:',
102
+ options: [
103
+ {
104
+ label: 'Global directory',
105
+ value: 'global',
106
+ hint: '~/.config/opencode (shared across projects)',
107
+ },
108
+ { label: 'Current project', value: 'project', hint: './.opencode (scoped to this project)' },
109
+ ],
394
110
  })
111
+ if (cancelPrompt(prompts, target, 'target')) return { canceled: true, cancelPoint: 'target' }
395
112
 
396
- process.stdout.write('\n')
397
-
398
- const confirmed = await promptConfirm(
399
- `Install ${selectedComponents.size} component(s) in ${target === 'global' ? 'global config' : 'current project'}?`,
400
- { default: true },
401
- )
402
-
403
- process.stdout.write('\n')
113
+ const confirmed = await prompts.confirm({
114
+ message: `Install ${selectedComponents.size} component(s) in ${target === 'global' ? 'global config' : 'current project'}?`,
115
+ initialValue: true,
116
+ })
117
+ if (cancelPrompt(prompts, confirmed, 'confirmation')) {
118
+ return { canceled: true, cancelPoint: 'confirmation' }
119
+ }
404
120
 
405
121
  return { components: selectedComponents, target, confirmed }
406
122
  }
@@ -0,0 +1,78 @@
1
+ /**
2
+ * interrupt.mjs — Ctrl-C behaves like every other cancel, for the window in
3
+ * which the installer is actually working.
4
+ *
5
+ * Before this existed, NOTHING under `bin/` or `scripts/install/` handled
6
+ * SIGINT: an interrupted install died by default action, printed no reason, and
7
+ * left no trace — the user could not tell an interrupt from a crash, and a
8
+ * re-run could not tell what the previous attempt did. The prompt library
9
+ * consumes Ctrl-C in raw mode while a question is on screen, so this covers the
10
+ * rest of the run (backup, copies, config write, state write).
11
+ *
12
+ * LIFETIME MATTERS AS MUCH AS THE MESSAGE: the handler is registered when the
13
+ * install starts and must be DEACTIVATED once the run has been recorded. Left
14
+ * registered, a Ctrl-C during the post-install `--doctor` step would rewrite a
15
+ * COMPLETED install as `canceled / applied:false` and claim nothing was
16
+ * applied. {@link createInterruptHandler} therefore owns its registration and
17
+ * exposes `deactivate()` for the caller to call at that point.
18
+ *
19
+ * Contract, all of it pinned by tests:
20
+ * - exactly ONE message is printed, and it names the interrupt as the point;
21
+ * - with `--json`, the message goes to stderr so stdout stays parsable;
22
+ * - the outcome is recorded once (a second Ctrl-C must not record twice);
23
+ * - the exit code is 130, the documented "canceled" code;
24
+ * - after `deactivate()`, the signal is no longer handled at all.
25
+ *
26
+ * Kept injectable rather than reading globals so the exit code, the streams,
27
+ * the emitter and the record call are all observable in a unit test.
28
+ *
29
+ * @module interrupt
30
+ */
31
+
32
+ /**
33
+ * Build and REGISTER a SIGINT handler.
34
+ *
35
+ * @param {{
36
+ * message: string,
37
+ * json?: boolean,
38
+ * onInterrupt?: () => void,
39
+ * endGaugeLine?: () => void,
40
+ * writeStderr?: (line: string) => void,
41
+ * logStderr?: (line: string) => void,
42
+ * exit?: (code: number) => void,
43
+ * emitter?: { once: (event: string, listener: () => void) => unknown, removeListener: (event: string, listener: () => void) => unknown },
44
+ * }} options
45
+ * @returns {(() => void) & { deactivate: () => void }} the registered handler
46
+ */
47
+ export function createInterruptHandler({
48
+ message,
49
+ json = false,
50
+ onInterrupt = () => {},
51
+ endGaugeLine = () => {},
52
+ writeStderr = (line) => process.stderr.write(`${line}\n`),
53
+ logStderr = (line) => console.error(line),
54
+ exit = (code) => process.exit(code),
55
+ emitter = process,
56
+ }) {
57
+ let handled = false
58
+ const handle = function handleInterrupt() {
59
+ if (handled) return
60
+ handled = true
61
+ try {
62
+ // The progress gauge owns the current terminal line; close it so the
63
+ // message is not appended to a half-drawn bar and then erased.
64
+ endGaugeLine()
65
+ if (json) writeStderr(message)
66
+ else logStderr(message)
67
+ onInterrupt()
68
+ } finally {
69
+ exit(130)
70
+ }
71
+ }
72
+ /** Stop handling SIGINT: the run this handler described is over. */
73
+ handle.deactivate = () => {
74
+ emitter.removeListener('SIGINT', handle)
75
+ }
76
+ emitter.once('SIGINT', handle)
77
+ return handle
78
+ }