@plainconceptsplatform/agent-harness 3.9.0 → 3.11.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.
Files changed (145) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +555 -551
  3. package/cli/commands/join.js +259 -259
  4. package/cli/commands/migrate.js +310 -310
  5. package/cli/commands/shared.js +27 -27
  6. package/cli/commands/single.js +79 -79
  7. package/cli/commands/update.js +121 -121
  8. package/cli/commands/wizard.js +134 -134
  9. package/cli/fragments/archive/az.md +97 -97
  10. package/cli/fragments/archive/gh.md +96 -96
  11. package/cli/fragments/archive/gl.md +96 -96
  12. package/cli/fragments/archive/none.md +75 -75
  13. package/cli/fragments/guardrails/codegraph.md +5 -5
  14. package/cli/fragments/guardrails/humanizer.md +4 -4
  15. package/cli/fragments/guardrails/memory.md +4 -4
  16. package/cli/fragments/guardrails/rtk.md +3 -3
  17. package/cli/fragments/guardrails/simple-english.md +4 -4
  18. package/cli/fragments/ops-backlog/az.md +28 -28
  19. package/cli/fragments/ops-backlog/gh.md +28 -28
  20. package/cli/fragments/ops-backlog/jira.md +28 -28
  21. package/cli/fragments/ops-review/az.md +62 -62
  22. package/cli/fragments/ops-review/gh.md +51 -51
  23. package/cli/fragments/ops-review/gl.md +55 -55
  24. package/cli/fragments/ops-ship/az.md +81 -81
  25. package/cli/fragments/ops-ship/gh.md +67 -67
  26. package/cli/fragments/ops-ship/gl.md +84 -84
  27. package/cli/index.js +116 -116
  28. package/cli/presets/agents-content.json +34 -34
  29. package/cli/presets/browser.json +10 -10
  30. package/cli/presets/clean.json +21 -21
  31. package/cli/presets/models.json +68 -68
  32. package/cli/presets/optimization.json +32 -32
  33. package/cli/presets/platforms.json +76 -76
  34. package/cli/presets/source.json +23 -23
  35. package/cli/steps/browser/index.js +52 -48
  36. package/cli/steps/clean/index.js +120 -120
  37. package/cli/steps/copy/agents.js +176 -176
  38. package/cli/steps/copy/commands.js +79 -79
  39. package/cli/steps/copy/fullstack-engineer.js +81 -81
  40. package/cli/steps/copy/index.js +88 -88
  41. package/cli/steps/copy/opencode-json.js +359 -324
  42. package/cli/steps/copy/skills.js +353 -316
  43. package/cli/steps/metadata/index.js +115 -115
  44. package/cli/steps/models/format.js +88 -88
  45. package/cli/steps/models/index.js +64 -64
  46. package/cli/steps/models/write.js +38 -38
  47. package/cli/steps/openspec/index.js +136 -136
  48. package/cli/steps/optimization/codegraph.js +141 -141
  49. package/cli/steps/optimization/detect.js +66 -66
  50. package/cli/steps/optimization/humanizer.js +17 -17
  51. package/cli/steps/optimization/index.js +158 -158
  52. package/cli/steps/optimization/memory.js +91 -91
  53. package/cli/steps/optimization/patch-guardrails.js +111 -111
  54. package/cli/steps/optimization/simple-english.js +17 -17
  55. package/cli/steps/optimization/skills-lock.js +30 -30
  56. package/cli/steps/platform/index.js +109 -109
  57. package/cli/steps/source/index.js +123 -123
  58. package/cli/utils/agent-color.js +111 -111
  59. package/cli/utils/copy.js +134 -134
  60. package/cli/utils/exec-spinner.js +47 -47
  61. package/cli/utils/exec.js +134 -134
  62. package/cli/utils/legacy-check.js +30 -30
  63. package/cli/utils/models-cache.js +58 -58
  64. package/cli/utils/models-pricing.js +42 -42
  65. package/cli/utils/paths.js +82 -82
  66. package/cli/utils/process.js +3 -3
  67. package/cli/utils/terminal.js +6 -6
  68. package/cli/utils/update-manifest.js +75 -75
  69. package/harness/.opencode/_gitignore +12 -12
  70. package/harness/.opencode/commands/init.md +5 -5
  71. package/harness/.opencode/commands/make-architecture.md +5 -5
  72. package/harness/.opencode/commands/make-design.md +5 -5
  73. package/harness/.opencode/commands/make-engineer.md +5 -5
  74. package/harness/.opencode/commands/make-guardrails.md +5 -5
  75. package/harness/.opencode/commands/make-user-model.md +5 -5
  76. package/harness/.opencode/commands/ops-backlog.md +10 -10
  77. package/harness/.opencode/commands/ops-review.md +10 -10
  78. package/harness/.opencode/commands/ops-ship.md +9 -9
  79. package/harness/.opencode/commands/plan-apply.md +9 -9
  80. package/harness/.opencode/commands/plan-archive.md +7 -7
  81. package/harness/.opencode/commands/plan-explore.md +11 -11
  82. package/harness/.opencode/commands/plan-goal.md +5 -5
  83. package/harness/.opencode/commands/plan-mockup.md +11 -0
  84. package/harness/.opencode/commands/plan-propose.md +11 -11
  85. package/harness/.opencode/commands/plan-quick.md +7 -7
  86. package/harness/.opencode/commands/plan-story.md +11 -11
  87. package/harness/.opencode/commands/repo-audit.md +7 -7
  88. package/harness/.opencode/commands/repo-help.md +5 -5
  89. package/harness/.opencode/commands/repo-initialize.md +5 -5
  90. package/harness/.opencode/commands/repo-onboard.md +5 -5
  91. package/harness/.opencode/commands/repo-verify.md +5 -5
  92. package/harness/.opencode/plugins/pc-commit-coauthor.js +41 -41
  93. package/harness/.opencode/plugins/pc-subagent-monitor.js +184 -184
  94. package/harness/.opencode/plugins/pc-system-reminders.js +424 -424
  95. package/harness/.opencode/scripts/check-diff.mjs +305 -305
  96. package/harness/.opencode/scripts/code-rules.mjs +288 -288
  97. package/harness/.opencode/scripts/platform-contract.mjs +366 -366
  98. package/harness/AGENTS.md +55 -55
  99. package/harness/ARCHITECTURE.md +13 -13
  100. package/harness/DESIGN.md +13 -13
  101. package/harness/opencode.jsonc +37 -36
  102. package/harness/openspec/config.yaml +20 -20
  103. package/harness/skills-lock.json +23 -17
  104. package/package.json +14 -12
  105. package/skills/README.md +18 -18
  106. package/skills/agent-harness-cli/SKILL.md +86 -86
  107. package/skills/browser-automation/SKILL.md +100 -72
  108. package/skills/pc-guardrails-generic/SKILL.md +53 -53
  109. package/skills/pc-guardrails-project/SKILL.md +8 -8
  110. package/skills/pc-make-architecture/SKILL.md +33 -33
  111. package/skills/pc-make-architecture/structure-template.md +64 -64
  112. package/skills/pc-make-design/SKILL.md +45 -45
  113. package/skills/pc-make-engineer/SKILL.md +59 -59
  114. package/skills/pc-make-engineer/signal-mapping.md +53 -53
  115. package/skills/pc-make-engineer/template.md +36 -36
  116. package/skills/pc-make-guardrails/SKILL.md +44 -44
  117. package/skills/pc-make-guardrails/category-reference.md +112 -112
  118. package/skills/pc-make-merge-risk-assess/SKILL.md +70 -70
  119. package/skills/pc-make-merge-risk-assess/category-reference.md +114 -114
  120. package/skills/pc-make-user-model/SKILL.md +56 -56
  121. package/skills/pc-ops-ship/SKILL.md +22 -22
  122. package/skills/pc-plan-apply/SKILL.md +92 -90
  123. package/skills/pc-plan-apply/simple-mode.md +21 -21
  124. package/skills/pc-plan-archive/SKILL.md +66 -66
  125. package/skills/pc-plan-explore/SKILL.md +22 -21
  126. package/skills/pc-plan-goal/SKILL.md +91 -91
  127. package/skills/pc-plan-goal/branching.md +39 -39
  128. package/skills/pc-plan-goal/failure-policy.md +30 -30
  129. package/skills/pc-plan-goal/output-mode.md +10 -10
  130. package/skills/pc-plan-goal/output.md +71 -71
  131. package/skills/pc-plan-mockup/SKILL.md +85 -0
  132. package/skills/pc-plan-mockup/mockup-contract.md +65 -0
  133. package/skills/pc-plan-propose/SKILL.md +127 -127
  134. package/skills/pc-plan-propose/task-annotation.md +39 -39
  135. package/skills/pc-plan-quick/SKILL.md +46 -46
  136. package/skills/pc-plan-story/SKILL.md +96 -93
  137. package/skills/pc-repo-audit/SKILL.md +44 -44
  138. package/skills/pc-repo-help/SKILL.md +90 -87
  139. package/skills/pc-repo-initialize/SKILL.md +119 -119
  140. package/skills/pc-repo-onboard/SKILL.md +32 -32
  141. package/skills/pc-repo-verify/SKILL.md +150 -150
  142. package/skills/pc-userstory-az/SKILL.md +71 -71
  143. package/skills/pc-userstory-browser/SKILL.md +73 -64
  144. package/skills/pc-userstory-gh/SKILL.md +63 -63
  145. package/skills/pc-userstory-jira/SKILL.md +74 -74
@@ -1,66 +1,66 @@
1
- import fse from 'fs-extra'
2
- import path from 'node:path'
3
- import { parse } from 'jsonc-parser'
4
-
5
- /**
6
- * Work out which optional tools a project actually has, rather than trusting
7
- * the flags in harness.json.
8
- *
9
- * Those flags drift. Numa and Odissey both had codegraph and agentmemory MCP
10
- * servers enabled in opencode.jsonc and the humanizer and simple-english skills
11
- * installed, while harness.json recorded `codegraph: false`, `memory: false` and
12
- * no humanizer key at all. patchGuardrails believed the config and emptied those
13
- * marker sections, so agents lost the guidance for tools the project was running.
14
- *
15
- * Detection only ever turns a tool ON. A flag that is already true is left
16
- * alone, because some of these install globally and cannot be seen from inside
17
- * the repository at all.
18
- */
19
-
20
- function mcpServers(cwd) {
21
- const configPath = path.join(cwd, 'opencode.jsonc')
22
- if (!fse.pathExistsSync(configPath)) return {}
23
- const errors = []
24
- const parsed = parse(fse.readFileSync(configPath, 'utf-8'), errors)
25
- if (errors.length > 0 || typeof parsed !== 'object' || parsed === null) return {}
26
- return parsed.mcp ?? {}
27
- }
28
-
29
- function hasSkill(cwd, name) {
30
- return fse.pathExistsSync(path.join(cwd, '.agents', 'skills', name))
31
- }
32
-
33
- /** An MCP server counts as present unless it is explicitly disabled. */
34
- function hasMcp(servers, name) {
35
- const server = servers[name]
36
- if (!server) return false
37
- return server.enabled !== false
38
- }
39
-
40
- export function detectInstalledTools(cwd = process.cwd()) {
41
- const servers = mcpServers(cwd)
42
- return {
43
- // rtk is a global CLI with nothing to find in the repo, so it is not
44
- // detectable here and the saved flag stands on its own.
45
- codegraph: hasMcp(servers, 'codegraph') || fse.pathExistsSync(path.join(cwd, '.codegraph')),
46
- memory: hasMcp(servers, 'agentmemory'),
47
- simpleEnglish: hasSkill(cwd, 'simple-english'),
48
- humanizer: hasSkill(cwd, 'humanizer'),
49
- quota: fse.pathExistsSync(path.join(cwd, '.opencode', 'opencode-quota')),
50
- }
51
- }
52
-
53
- /**
54
- * Saved flags merged with what is on disk. Detection can only add, so a tool
55
- * recorded as enabled stays enabled even when nothing local proves it.
56
- */
57
- export function reconcileTools(saved = {}, cwd = process.cwd()) {
58
- const detected = detectInstalledTools(cwd)
59
- const merged = { ...saved }
60
- for (const [key, present] of Object.entries(detected)) {
61
- if (present) merged[key] = true
62
- }
63
- // simpleEnglish replaced caveman; honour the old key one last time.
64
- if (saved.caveman) merged.simpleEnglish = true
65
- return merged
66
- }
1
+ import fse from 'fs-extra'
2
+ import path from 'node:path'
3
+ import { parse } from 'jsonc-parser'
4
+
5
+ /**
6
+ * Work out which optional tools a project actually has, rather than trusting
7
+ * the flags in harness.json.
8
+ *
9
+ * Those flags drift. Numa and Odissey both had codegraph and agentmemory MCP
10
+ * servers enabled in opencode.jsonc and the humanizer and simple-english skills
11
+ * installed, while harness.json recorded `codegraph: false`, `memory: false` and
12
+ * no humanizer key at all. patchGuardrails believed the config and emptied those
13
+ * marker sections, so agents lost the guidance for tools the project was running.
14
+ *
15
+ * Detection only ever turns a tool ON. A flag that is already true is left
16
+ * alone, because some of these install globally and cannot be seen from inside
17
+ * the repository at all.
18
+ */
19
+
20
+ function mcpServers(cwd) {
21
+ const configPath = path.join(cwd, 'opencode.jsonc')
22
+ if (!fse.pathExistsSync(configPath)) return {}
23
+ const errors = []
24
+ const parsed = parse(fse.readFileSync(configPath, 'utf-8'), errors)
25
+ if (errors.length > 0 || typeof parsed !== 'object' || parsed === null) return {}
26
+ return parsed.mcp ?? {}
27
+ }
28
+
29
+ function hasSkill(cwd, name) {
30
+ return fse.pathExistsSync(path.join(cwd, '.agents', 'skills', name))
31
+ }
32
+
33
+ /** An MCP server counts as present unless it is explicitly disabled. */
34
+ function hasMcp(servers, name) {
35
+ const server = servers[name]
36
+ if (!server) return false
37
+ return server.enabled !== false
38
+ }
39
+
40
+ export function detectInstalledTools(cwd = process.cwd()) {
41
+ const servers = mcpServers(cwd)
42
+ return {
43
+ // rtk is a global CLI with nothing to find in the repo, so it is not
44
+ // detectable here and the saved flag stands on its own.
45
+ codegraph: hasMcp(servers, 'codegraph') || fse.pathExistsSync(path.join(cwd, '.codegraph')),
46
+ memory: hasMcp(servers, 'agentmemory'),
47
+ simpleEnglish: hasSkill(cwd, 'simple-english'),
48
+ humanizer: hasSkill(cwd, 'humanizer'),
49
+ quota: fse.pathExistsSync(path.join(cwd, '.opencode', 'opencode-quota')),
50
+ }
51
+ }
52
+
53
+ /**
54
+ * Saved flags merged with what is on disk. Detection can only add, so a tool
55
+ * recorded as enabled stays enabled even when nothing local proves it.
56
+ */
57
+ export function reconcileTools(saved = {}, cwd = process.cwd()) {
58
+ const detected = detectInstalledTools(cwd)
59
+ const merged = { ...saved }
60
+ for (const [key, present] of Object.entries(detected)) {
61
+ if (present) merged[key] = true
62
+ }
63
+ // simpleEnglish replaced caveman; honour the old key one last time.
64
+ if (saved.caveman) merged.simpleEnglish = true
65
+ return merged
66
+ }
@@ -1,17 +1,17 @@
1
- import { addSkillToLock } from './skills-lock.js'
2
- import { header, success, info } from '../../utils/exec.js'
3
-
4
- const SKILL_ENTRY = {
5
- source: 'blader/humanizer',
6
- sourceType: 'github',
7
- skillPath: 'SKILL.md',
8
- }
9
-
10
- export async function installHumanizer(options = {}) {
11
- if (!options.skipHeader) header('Installing humanizer')
12
-
13
- info('Adding humanizer to skills-lock.json for batch install')
14
- await addSkillToLock('humanizer', SKILL_ENTRY)
15
- success('humanizer queued for installation')
16
- return { optedIn: true, installed: true }
17
- }
1
+ import { addSkillToLock } from './skills-lock.js'
2
+ import { header, success, info } from '../../utils/exec.js'
3
+
4
+ const SKILL_ENTRY = {
5
+ source: 'blader/humanizer',
6
+ sourceType: 'github',
7
+ skillPath: 'SKILL.md',
8
+ }
9
+
10
+ export async function installHumanizer(options = {}) {
11
+ if (!options.skipHeader) header('Installing humanizer')
12
+
13
+ info('Adding humanizer to skills-lock.json for batch install')
14
+ await addSkillToLock('humanizer', SKILL_ENTRY)
15
+ success('humanizer queued for installation')
16
+ return { optedIn: true, installed: true }
17
+ }
@@ -1,158 +1,158 @@
1
- import { checkbox, confirm } from '@inquirer/prompts'
2
- import { execa } from 'execa'
3
- import fse from 'fs-extra'
4
- import path from 'path'
5
- import { fileURLToPath } from 'url'
6
- import { code, commandExists, header, info, loading, success, warn } from '../../utils/exec.js'
7
- import { installSimpleEnglish } from './simple-english.js'
8
- import { installCodegraph } from './codegraph.js'
9
- import { installMemory } from './memory.js'
10
- import { installHumanizer } from './humanizer.js'
11
- import { patchGuardrails } from './patch-guardrails.js'
12
-
13
- const __dirname = path.dirname(fileURLToPath(import.meta.url))
14
- const OPTIMIZATION_PRESET_PATH = path.resolve(__dirname, '../../presets/optimization.json')
15
- const optimizationPreset = await fse.readJson(OPTIMIZATION_PRESET_PATH)
16
-
17
- export async function checkRtk(options = {}) {
18
- if (!options.skipHeader) header('Checking rtk')
19
-
20
- let shouldCheck = true
21
- if (!options.skipPrompt) {
22
- info('Recommended: install and verify rtk for safer agent CLI command execution.')
23
- shouldCheck = await confirm({
24
- message: 'Check rtk now?',
25
- default: true,
26
- })
27
- }
28
-
29
- if (!shouldCheck) {
30
- warn('Skipped rtk check (you can install it later)')
31
- return { optedIn: false, checked: false, available: false }
32
- }
33
-
34
- loading('checking rtk...')
35
-
36
- const available = await commandExists('rtk')
37
-
38
- if (available) {
39
- success('rtk is available')
40
- return { optedIn: true, checked: true, available: true }
41
- }
42
-
43
- warn('rtk not found on PATH.')
44
- console.log()
45
- info('rtk is required for agents to run CLI commands safely.')
46
- info('Install it from: https://github.com/rtk-ai/rtk#pre-built-binaries')
47
- console.log()
48
- info('After installing, verify with:')
49
- code(['rtk --version'])
50
- return { optedIn: true, checked: true, available: false }
51
- }
52
-
53
- export async function tokenOptimizationStep(options = {}) {
54
- header('Step 8, Token optimization tools')
55
-
56
- const defaultSelected = optimizationPreset.choices
57
- .filter(choice => choice.checked)
58
- .map(choice => choice.value)
59
- let selected = defaultSelected
60
-
61
- if (!options.skipPrompt && process.stdin.isTTY) {
62
- info(optimizationPreset.info)
63
- // Abort the prompt via signal instead of racing it: a raced prompt keeps
64
- // stdin in raw mode after "losing" and rejects unhandled on a later Ctrl+C.
65
- const controller = new AbortController()
66
- const timer = setTimeout(() => controller.abort(), optimizationPreset.timeoutMs)
67
- try {
68
- selected = await checkbox(
69
- {
70
- message: optimizationPreset.message,
71
- choices: optimizationPreset.choices,
72
- },
73
- { signal: controller.signal },
74
- )
75
- } catch (err) {
76
- if (err.name !== 'AbortPromptError') throw err
77
- selected = defaultSelected
78
- info('No response: continuing with the recommended defaults.')
79
- } finally {
80
- clearTimeout(timer)
81
- }
82
- }
83
-
84
- loading('applying token optimization selections...')
85
-
86
- const installScope = options.ctx?.installScope || 'local'
87
-
88
- const has = value => selected.includes(value)
89
-
90
- const rtk = has('rtk')
91
- ? await checkRtk({ skipHeader: true, skipPrompt: true })
92
- : { optedIn: false, checked: false, available: false }
93
-
94
- const simpleEnglish = has('simpleEnglish')
95
- ? await installSimpleEnglish({
96
- skipHeader: true,
97
- skipPrompt: true,
98
- installScope,
99
- })
100
- : { optedIn: false, installed: false }
101
-
102
- const codegraph = has('codegraph')
103
- ? await installCodegraph({ skipHeader: true, installScope })
104
- : { optedIn: false, installed: false }
105
-
106
- const memory = has('memory')
107
- ? await installMemory({ skipHeader: true })
108
- : { optedIn: false, installed: false }
109
-
110
- const humanizer = has('humanizer')
111
- ? await installHumanizer({ skipHeader: true, installScope })
112
- : { optedIn: false, installed: false }
113
-
114
- // Run a single npx skills experimental_install to pick up all skills
115
- // that were added to skills-lock.json by the individual installers above.
116
- await syncSkillsLock()
117
-
118
- // Patch guardrails skill with selected tool guidance sections
119
- await patchGuardrails({
120
- rtk: rtk.available,
121
- codegraph: codegraph.optedIn,
122
- memory: memory.optedIn,
123
- simpleEnglish: simpleEnglish.installed,
124
- humanizer: humanizer.optedIn,
125
- })
126
-
127
- if (selected.length === 0) warn('No token optimization tools selected')
128
- else success('Token optimization step completed')
129
-
130
- return { rtk, simpleEnglish, codegraph, memory, humanizer }
131
- }
132
-
133
- async function syncSkillsLock() {
134
- const destLock = path.join(process.cwd(), 'skills-lock.json')
135
- if (!await fse.pathExists(destLock)) {
136
- info('No skills-lock.json found, skipping skills sync')
137
- return
138
- }
139
-
140
- loading('syncing skills via npx skills experimental_install...')
141
- try {
142
- const result = await execa('npx', ['skills', 'experimental_install', '--yes'], {
143
- cwd: process.cwd(),
144
- reject: false,
145
- stdio: 'pipe',
146
- timeout: 600000,
147
- })
148
-
149
- if (result.exitCode === 0) {
150
- success('Skills synced from skills-lock.json')
151
- } else {
152
- const errLine = result.stderr?.trim().split('\n').slice(-3).join('\n')
153
- warn(`npx skills experimental_install exited with non-zero code${errLine ? `: ${errLine}` : ''}`)
154
- }
155
- } catch (err) {
156
- warn(`npx skills experimental_install failed: ${err.message}`)
157
- }
158
- }
1
+ import { checkbox, confirm } from '@inquirer/prompts'
2
+ import { execa } from 'execa'
3
+ import fse from 'fs-extra'
4
+ import path from 'path'
5
+ import { fileURLToPath } from 'url'
6
+ import { code, commandExists, header, info, loading, success, warn } from '../../utils/exec.js'
7
+ import { installSimpleEnglish } from './simple-english.js'
8
+ import { installCodegraph } from './codegraph.js'
9
+ import { installMemory } from './memory.js'
10
+ import { installHumanizer } from './humanizer.js'
11
+ import { patchGuardrails } from './patch-guardrails.js'
12
+
13
+ const __dirname = path.dirname(fileURLToPath(import.meta.url))
14
+ const OPTIMIZATION_PRESET_PATH = path.resolve(__dirname, '../../presets/optimization.json')
15
+ const optimizationPreset = await fse.readJson(OPTIMIZATION_PRESET_PATH)
16
+
17
+ export async function checkRtk(options = {}) {
18
+ if (!options.skipHeader) header('Checking rtk')
19
+
20
+ let shouldCheck = true
21
+ if (!options.skipPrompt) {
22
+ info('Recommended: install and verify rtk for safer agent CLI command execution.')
23
+ shouldCheck = await confirm({
24
+ message: 'Check rtk now?',
25
+ default: true,
26
+ })
27
+ }
28
+
29
+ if (!shouldCheck) {
30
+ warn('Skipped rtk check (you can install it later)')
31
+ return { optedIn: false, checked: false, available: false }
32
+ }
33
+
34
+ loading('checking rtk...')
35
+
36
+ const available = await commandExists('rtk')
37
+
38
+ if (available) {
39
+ success('rtk is available')
40
+ return { optedIn: true, checked: true, available: true }
41
+ }
42
+
43
+ warn('rtk not found on PATH.')
44
+ console.log()
45
+ info('rtk is required for agents to run CLI commands safely.')
46
+ info('Install it from: https://github.com/rtk-ai/rtk#pre-built-binaries')
47
+ console.log()
48
+ info('After installing, verify with:')
49
+ code(['rtk --version'])
50
+ return { optedIn: true, checked: true, available: false }
51
+ }
52
+
53
+ export async function tokenOptimizationStep(options = {}) {
54
+ header('Step 8, Token optimization tools')
55
+
56
+ const defaultSelected = optimizationPreset.choices
57
+ .filter(choice => choice.checked)
58
+ .map(choice => choice.value)
59
+ let selected = defaultSelected
60
+
61
+ if (!options.skipPrompt && process.stdin.isTTY) {
62
+ info(optimizationPreset.info)
63
+ // Abort the prompt via signal instead of racing it: a raced prompt keeps
64
+ // stdin in raw mode after "losing" and rejects unhandled on a later Ctrl+C.
65
+ const controller = new AbortController()
66
+ const timer = setTimeout(() => controller.abort(), optimizationPreset.timeoutMs)
67
+ try {
68
+ selected = await checkbox(
69
+ {
70
+ message: optimizationPreset.message,
71
+ choices: optimizationPreset.choices,
72
+ },
73
+ { signal: controller.signal },
74
+ )
75
+ } catch (err) {
76
+ if (err.name !== 'AbortPromptError') throw err
77
+ selected = defaultSelected
78
+ info('No response: continuing with the recommended defaults.')
79
+ } finally {
80
+ clearTimeout(timer)
81
+ }
82
+ }
83
+
84
+ loading('applying token optimization selections...')
85
+
86
+ const installScope = options.ctx?.installScope || 'local'
87
+
88
+ const has = value => selected.includes(value)
89
+
90
+ const rtk = has('rtk')
91
+ ? await checkRtk({ skipHeader: true, skipPrompt: true })
92
+ : { optedIn: false, checked: false, available: false }
93
+
94
+ const simpleEnglish = has('simpleEnglish')
95
+ ? await installSimpleEnglish({
96
+ skipHeader: true,
97
+ skipPrompt: true,
98
+ installScope,
99
+ })
100
+ : { optedIn: false, installed: false }
101
+
102
+ const codegraph = has('codegraph')
103
+ ? await installCodegraph({ skipHeader: true, installScope })
104
+ : { optedIn: false, installed: false }
105
+
106
+ const memory = has('memory')
107
+ ? await installMemory({ skipHeader: true })
108
+ : { optedIn: false, installed: false }
109
+
110
+ const humanizer = has('humanizer')
111
+ ? await installHumanizer({ skipHeader: true, installScope })
112
+ : { optedIn: false, installed: false }
113
+
114
+ // Run a single npx skills experimental_install to pick up all skills
115
+ // that were added to skills-lock.json by the individual installers above.
116
+ await syncSkillsLock()
117
+
118
+ // Patch guardrails skill with selected tool guidance sections
119
+ await patchGuardrails({
120
+ rtk: rtk.available,
121
+ codegraph: codegraph.optedIn,
122
+ memory: memory.optedIn,
123
+ simpleEnglish: simpleEnglish.installed,
124
+ humanizer: humanizer.optedIn,
125
+ })
126
+
127
+ if (selected.length === 0) warn('No token optimization tools selected')
128
+ else success('Token optimization step completed')
129
+
130
+ return { rtk, simpleEnglish, codegraph, memory, humanizer }
131
+ }
132
+
133
+ async function syncSkillsLock() {
134
+ const destLock = path.join(process.cwd(), 'skills-lock.json')
135
+ if (!await fse.pathExists(destLock)) {
136
+ info('No skills-lock.json found, skipping skills sync')
137
+ return
138
+ }
139
+
140
+ loading('syncing skills via npx skills experimental_install...')
141
+ try {
142
+ const result = await execa('npx', ['skills', 'experimental_install', '--yes'], {
143
+ cwd: process.cwd(),
144
+ reject: false,
145
+ stdio: 'pipe',
146
+ timeout: 600000,
147
+ })
148
+
149
+ if (result.exitCode === 0) {
150
+ success('Skills synced from skills-lock.json')
151
+ } else {
152
+ const errLine = result.stderr?.trim().split('\n').slice(-3).join('\n')
153
+ warn(`npx skills experimental_install exited with non-zero code${errLine ? `: ${errLine}` : ''}`)
154
+ }
155
+ } catch (err) {
156
+ warn(`npx skills experimental_install failed: ${err.message}`)
157
+ }
158
+ }