@aiwg/cli 2026.10.15 → 2026.10.18

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 (286) hide show
  1. package/agentic/code/providers/pi/aiwg-bridge.ts +45 -7
  2. package/dist/src/artifacts/citation-parser.js +7 -6
  3. package/dist/src/artifacts/corpus-tools/citation-densify.js +4 -2
  4. package/dist/src/artifacts/corpus-tools/cli.js +8 -3
  5. package/dist/src/artifacts/corpus-tools/discovery-log.js +26 -24
  6. package/dist/src/artifacts/corpus-tools/expand-cli.js +3 -2
  7. package/dist/src/artifacts/corpus-tools/expand-dates.js +107 -0
  8. package/dist/src/artifacts/corpus-tools/expand-queue.js +4 -1
  9. package/dist/src/artifacts/corpus-tools/expand-review.js +104 -0
  10. package/dist/src/artifacts/corpus-tools/expand-state.js +17 -1
  11. package/dist/src/artifacts/corpus-tools/expand.js +16 -17
  12. package/dist/src/artifacts/corpus-tools/induction-audit.js +7 -6
  13. package/dist/src/artifacts/corpus-tools/integrity-scan.js +3 -3
  14. package/dist/src/artifacts/corpus-tools/radar-shared.js +7 -9
  15. package/dist/src/artifacts/corpus-tools/ref-files.js +11 -0
  16. package/dist/src/artifacts/corpus-tools/resolve-cli.js +11 -3
  17. package/dist/src/artifacts/corpus-tools/resolve.js +42 -11
  18. package/dist/src/artifacts/corpus-tools/retrieval-lab.js +2 -1
  19. package/dist/src/artifacts/corpus-tools/sidecar-lint.js +4 -4
  20. package/dist/src/artifacts/corpus-tools/sidecar-repair.js +2 -1
  21. package/dist/src/artifacts/corpus-views/ref-parser.js +3 -17
  22. package/dist/src/artifacts/graph-query.js +5 -3
  23. package/dist/src/artifacts/hybrid-query.js +11 -2
  24. package/dist/src/artifacts/index-refresh.js +2 -0
  25. package/dist/src/artifacts/query-engine-corpus.js +217 -0
  26. package/dist/src/artifacts/query-engine-discover-output.js +229 -0
  27. package/dist/src/artifacts/query-engine-discover.js +285 -0
  28. package/dist/src/artifacts/query-engine-entries.js +188 -0
  29. package/dist/src/artifacts/query-engine-index.js +249 -0
  30. package/dist/src/artifacts/query-engine-matching.js +143 -0
  31. package/dist/src/artifacts/query-engine-options.js +2 -0
  32. package/dist/src/artifacts/query-engine-rules.js +202 -0
  33. package/dist/src/artifacts/query-engine-scoring.js +436 -0
  34. package/dist/src/artifacts/query-engine-show-card.js +194 -0
  35. package/dist/src/artifacts/query-engine-show-load.js +211 -0
  36. package/dist/src/artifacts/query-engine-show.js +300 -0
  37. package/dist/src/artifacts/query-engine.js +7 -2576
  38. package/dist/src/cli/handlers/daemon.js +17 -1
  39. package/dist/src/cli/handlers/doctor-args.js +10 -5
  40. package/dist/src/cli/handlers/doctor-help.js +4 -1
  41. package/dist/src/cli/handlers/index.js +2 -2
  42. package/dist/src/cli/handlers/mc-agents.js +111 -0
  43. package/dist/src/cli/handlers/mc-args.js +54 -0
  44. package/dist/src/cli/handlers/mc-control.js +227 -0
  45. package/dist/src/cli/handlers/mc-dispatch.js +203 -0
  46. package/dist/src/cli/handlers/mc-help.js +171 -0
  47. package/dist/src/cli/handlers/mc-run.js +343 -0
  48. package/dist/src/cli/handlers/mc-session.js +138 -0
  49. package/dist/src/cli/handlers/mc-status.js +258 -0
  50. package/dist/src/cli/handlers/mc-summary.js +43 -0
  51. package/dist/src/cli/handlers/mc-types.js +3 -0
  52. package/dist/src/cli/handlers/mc-worker.js +205 -0
  53. package/dist/src/cli/handlers/mc.js +12 -1665
  54. package/dist/src/cli/handlers/models-refusal.js +13 -0
  55. package/dist/src/cli/handlers/models-resource-sample.js +10 -0
  56. package/dist/src/cli/handlers/models.js +5 -3
  57. package/dist/src/cli/handlers/regenerate.js +8 -16
  58. package/dist/src/cli/handlers/remove-bundled.js +133 -0
  59. package/dist/src/cli/handlers/remove-options.js +31 -0
  60. package/dist/src/cli/handlers/remove-user.js +174 -0
  61. package/dist/src/cli/handlers/remove.js +201 -0
  62. package/dist/src/cli/handlers/sessions.js +7 -7
  63. package/dist/src/cli/handlers/subcommands-bundles.js +257 -0
  64. package/dist/src/cli/handlers/subcommands-discovery.js +165 -0
  65. package/dist/src/cli/handlers/subcommands-list-format.js +129 -0
  66. package/dist/src/cli/handlers/subcommands-list.js +250 -0
  67. package/dist/src/cli/handlers/subcommands-plugins.js +213 -0
  68. package/dist/src/cli/handlers/subcommands-quickref.js +58 -0
  69. package/dist/src/cli/handlers/subcommands-rlm.js +113 -0
  70. package/dist/src/cli/handlers/subcommands-services.js +66 -0
  71. package/dist/src/cli/handlers/subcommands-storage.js +259 -0
  72. package/dist/src/cli/handlers/subcommands.js +18 -1976
  73. package/dist/src/cli/handlers/update.js +157 -0
  74. package/dist/src/cli/handlers/use.js +14 -4
  75. package/dist/src/cli/handlers/utilities.js +3 -560
  76. package/dist/src/cli/handlers/utility-doctor.js +412 -0
  77. package/dist/src/cli/scope-resolver.js +1 -142
  78. package/dist/src/cli/services/deployment-verification.js +0 -1
  79. package/dist/src/cli/user-scope-mirror.js +173 -0
  80. package/dist/src/config/aiwg-config.js +2 -1
  81. package/dist/src/config/authorization-cli.js +7 -3
  82. package/dist/src/config/dispatch-host-thresholds.js +2 -0
  83. package/dist/src/config/dispatch-thresholds-runtime.d.mts +3 -2
  84. package/dist/src/config/dispatch-thresholds-runtime.mjs +21 -7
  85. package/dist/src/config/framework-aliases.js +12 -0
  86. package/dist/src/config/host-resource-report.d.mts +24 -0
  87. package/dist/src/config/host-resource-report.mjs +110 -0
  88. package/dist/src/config/host-resource-runtime.d.mts +37 -0
  89. package/dist/src/config/host-resource-runtime.mjs +296 -0
  90. package/dist/src/config/installed-selection.js +22 -0
  91. package/dist/src/config/worker-invocation-marker.d.mts +1 -0
  92. package/dist/src/config/worker-invocation-marker.mjs +2 -0
  93. package/dist/src/decision/ensemble-study/artifacts.js +7 -0
  94. package/dist/src/decision/ensemble-study/gate-policy.js +58 -0
  95. package/dist/src/decision/ensemble-study/gates.js +78 -0
  96. package/dist/src/decision/ensemble-study/protocol.js +18 -21
  97. package/dist/src/decision/ensemble-study/score.js +3 -2
  98. package/dist/src/decision/ensemble-study/statistics.js +7 -26
  99. package/dist/src/decision/heldout/access.js +74 -0
  100. package/dist/src/decision/heldout/calibration.js +1 -0
  101. package/dist/src/decision/heldout/collector.js +8 -1
  102. package/dist/src/decision/sensitivity/comparative-gates.js +135 -0
  103. package/dist/src/decision/sensitivity/comparative.js +18 -41
  104. package/dist/src/effects/verifiers/file.js +22 -5
  105. package/dist/src/extensions/claude-attribution.js +82 -0
  106. package/dist/src/extensions/claude-hooks-installer.js +133 -69
  107. package/dist/src/extensions/commands/daemon.js +109 -0
  108. package/dist/src/extensions/commands/definitions.js +5 -89
  109. package/dist/src/gates/evaluate.js +2 -358
  110. package/dist/src/gates/heldout.js +17 -7
  111. package/dist/src/gates/observations.js +363 -0
  112. package/dist/src/gates/pack-composition.js +270 -0
  113. package/dist/src/gates/pack-tightening.js +197 -0
  114. package/dist/src/gates/pack-validation.js +262 -0
  115. package/dist/src/gates/registry-error.js +5 -0
  116. package/dist/src/gates/registry.js +13 -685
  117. package/dist/src/lint/check-patterns.js +163 -0
  118. package/dist/src/lint/checks.js +268 -0
  119. package/dist/src/lint/reference-resolution.js +54 -0
  120. package/dist/src/lint/runner.js +3 -465
  121. package/dist/src/mcp/helpers.mjs +11 -1
  122. package/dist/src/mcp/json-document.mjs +29 -0
  123. package/dist/src/mcp/muse-native-config.mjs +1 -28
  124. package/dist/src/memory/project-registry.js +44 -4
  125. package/dist/src/mission-protocol/worker-review-gate.js +7 -0
  126. package/dist/src/models/worker-plan.js +36 -5
  127. package/dist/src/models/wrapper-deployment.js +25 -12
  128. package/dist/src/models/wrapper-enforcement.js +47 -7
  129. package/dist/src/network-analysis/research.js +2 -1
  130. package/dist/src/plugin/command-ownership.js +34 -0
  131. package/dist/src/plugin/skill-command-frontmatter.js +197 -0
  132. package/dist/src/plugin/skill-command-translator.js +6 -232
  133. package/dist/src/policy/hitl-check.js +14 -4
  134. package/dist/src/policy/hitl-consume.js +54 -0
  135. package/dist/src/policy/hitl-receipt.js +2 -0
  136. package/dist/src/policy/hitl.js +11 -3
  137. package/dist/src/providers/context-output-ownership.js +26 -0
  138. package/dist/src/providers/deployment-ownership.d.mts +19 -0
  139. package/dist/src/providers/deployment-ownership.mjs +226 -0
  140. package/dist/src/providers/deployment-removal.js +200 -0
  141. package/dist/src/providers/provider-context-contracts.js +162 -0
  142. package/dist/src/providers/provider-definition-schema.js +136 -0
  143. package/dist/src/providers/provider-definitions.js +8 -1298
  144. package/dist/src/providers/provider-seeds-1.js +360 -0
  145. package/dist/src/providers/provider-seeds-2.js +387 -0
  146. package/dist/src/providers/provider-seeds-3.js +262 -0
  147. package/dist/src/providers/removal-transaction.js +86 -0
  148. package/dist/src/providers/settings-document.d.mts +3 -0
  149. package/dist/src/providers/settings-document.mjs +47 -0
  150. package/dist/src/providers/settings-removal.js +190 -0
  151. package/dist/src/providers/skill-ownership.d.mts +19 -2
  152. package/dist/src/providers/skill-ownership.mjs +12 -4
  153. package/dist/src/providers/transformation-receipt-integration.js +15 -271
  154. package/dist/src/providers/transformation-receipt-outputs.js +99 -0
  155. package/dist/src/providers/transformation-receipt-source.js +194 -0
  156. package/dist/src/research/clients/arxiv.js +4 -30
  157. package/dist/src/research/clients/base.js +48 -22
  158. package/dist/src/research/identity.js +42 -4
  159. package/dist/src/research/query-cli.js +3 -87
  160. package/dist/src/research/query-options.js +87 -0
  161. package/dist/src/research/reference-match.js +105 -24
  162. package/dist/src/research/services/acquisition.js +9 -7
  163. package/dist/src/research/services/citation.js +5 -2
  164. package/dist/src/research/types.js +2 -0
  165. package/dist/src/rules/activation.mjs +15 -6
  166. package/dist/src/rules/core-startup.mjs +2 -2
  167. package/dist/src/serve/mission-conductor.js +52 -4
  168. package/dist/src/serve/mission-summary.js +56 -0
  169. package/dist/src/sessions/adapters/grok-build-native.js +23 -0
  170. package/dist/src/sessions/adapters/grok-build.js +14 -7
  171. package/dist/src/sessions/workspace-discovery.js +5 -5
  172. package/dist/src/smiths/context-pipeline/aiwg-md.js +39 -46
  173. package/dist/src/smiths/context-pipeline/claude-hook.js +1 -1
  174. package/dist/src/smiths/context-pipeline/code-regions.js +28 -0
  175. package/dist/src/smiths/context-pipeline/context-file-safety.js +3 -0
  176. package/dist/src/smiths/context-pipeline/finalization.js +81 -51
  177. package/dist/src/smiths/context-pipeline/generator.js +10 -11
  178. package/dist/src/smiths/context-pipeline/managed-hook.js +1 -1
  179. package/dist/src/smiths/context-pipeline/muse-bridge.js +2 -2
  180. package/dist/src/smiths/context-pipeline/provider-policy.js +6 -12
  181. package/dist/src/smiths/context-pipeline/workspace-audit.js +299 -0
  182. package/dist/src/smiths/context-pipeline/workspace-bootstrap.js +148 -0
  183. package/dist/src/smiths/context-pipeline/workspace-context-shared.js +111 -0
  184. package/dist/src/smiths/context-pipeline/workspace-context.js +8 -1373
  185. package/dist/src/smiths/context-pipeline/workspace-doctor.js +192 -0
  186. package/dist/src/smiths/context-pipeline/workspace-document.js +201 -0
  187. package/dist/src/smiths/context-pipeline/workspace-extraction.js +205 -0
  188. package/dist/src/smiths/context-pipeline/workspace-migration.js +250 -0
  189. package/dist/src/smiths/hook-bridge/index.js +9 -0
  190. package/package.json +13 -1
  191. package/schemas/decision/D17StudyProtocol.v1.schema.json +39 -67
  192. package/schemas/decision/D29Study.v10.schema.json +65 -0
  193. package/tools/agents/deploy-agents.mjs +24 -675
  194. package/tools/agents/deploy-command-mirrors.mjs +229 -0
  195. package/tools/agents/deploy-options.mjs +258 -0
  196. package/tools/agents/deploy-support.mjs +165 -0
  197. package/tools/agents/providers/base-addon-discovery.mjs +139 -0
  198. package/tools/agents/providers/base-behaviors.mjs +168 -0
  199. package/tools/agents/providers/base-context.mjs +205 -0
  200. package/tools/agents/providers/base-contract.mjs +116 -0
  201. package/tools/agents/providers/base-files.mjs +252 -0
  202. package/tools/agents/providers/base-flat-artifacts.mjs +233 -0
  203. package/tools/agents/providers/base-framework-discovery.mjs +309 -0
  204. package/tools/agents/providers/base-frontmatter.mjs +196 -0
  205. package/tools/agents/providers/base-inventory.mjs +269 -0
  206. package/tools/agents/providers/base-kernel-skills.mjs +354 -0
  207. package/tools/agents/providers/base-migrations.mjs +258 -0
  208. package/tools/agents/providers/base-models-platforms.mjs +273 -0
  209. package/tools/agents/providers/base-rule-index.mjs +450 -0
  210. package/tools/agents/providers/base-runtime.mjs +60 -0
  211. package/tools/agents/providers/base-skill-copy.mjs +273 -0
  212. package/tools/agents/providers/base.mjs +16 -3364
  213. package/tools/agents/providers/claude-post-deploy.mjs +20 -1
  214. package/tools/agents/providers/context-write.mjs +4 -0
  215. package/tools/agents/providers/hermes-startup.mjs +0 -5
  216. package/tools/agents/providers/muse.mjs +7 -2
  217. package/tools/agents/providers/pi.mjs +3 -1
  218. package/tools/agents/providers/rule-delivery-surface.mjs +359 -0
  219. package/tools/agents/providers/rule-delivery.mjs +20 -1144
  220. package/tools/agents/providers/rule-deployment-commit.mjs +148 -0
  221. package/tools/agents/providers/rule-deployment-prepare.mjs +461 -0
  222. package/tools/agents/providers/rule-deployment-state.mjs +300 -0
  223. package/tools/agents/providers/rule-projection.mjs +3 -0
  224. package/tools/daemon/README.md +511 -0
  225. package/tools/daemon/adapters/base-adapter.mjs +84 -0
  226. package/tools/daemon/adapters/webhook-adapter.mjs +107 -0
  227. package/tools/daemon/agent-supervisor.mjs +299 -0
  228. package/tools/daemon/automation-engine.mjs +310 -0
  229. package/tools/daemon/autonomous-engine.mjs +346 -0
  230. package/tools/daemon/behavior-loader.mjs +316 -0
  231. package/tools/daemon/behavior.mjs +174 -0
  232. package/tools/daemon/concierge/intent-router.mjs +401 -0
  233. package/tools/daemon/concierge/orchestrator.mjs +272 -0
  234. package/tools/daemon/concierge/response-translator.mjs +462 -0
  235. package/tools/daemon/config.mjs +377 -0
  236. package/tools/daemon/cron-scheduler.mjs +178 -0
  237. package/tools/daemon/daemon-main.mjs +1169 -0
  238. package/tools/daemon/event-router.mjs +84 -0
  239. package/tools/daemon/file-watcher.mjs +383 -0
  240. package/tools/daemon/index.mjs +1181 -0
  241. package/tools/daemon/init-profile.mjs +124 -0
  242. package/tools/daemon/ipc-client.mjs +197 -0
  243. package/tools/daemon/ipc-ops-handlers.mjs +236 -0
  244. package/tools/daemon/ipc-server.mjs +275 -0
  245. package/tools/daemon/maintenance-owner.mjs +79 -0
  246. package/tools/daemon/memory-manager.mjs +386 -0
  247. package/tools/daemon/message-router.mjs +194 -0
  248. package/tools/daemon/provider-watcher.mjs +585 -0
  249. package/tools/daemon/pty-adapter.mjs +420 -0
  250. package/tools/daemon/repl-chat.mjs +359 -0
  251. package/tools/daemon/resource-bounds.mjs +88 -0
  252. package/tools/daemon/sandbox-transport.mjs +295 -0
  253. package/tools/daemon/scheduled-task-runner.mjs +535 -0
  254. package/tools/daemon/task-store.mjs +450 -0
  255. package/tools/daemon/tmux-manager.mjs +324 -0
  256. package/tools/daemon/update-policy.mjs +517 -0
  257. package/tools/daemon/web-server.mjs +399 -0
  258. package/tools/daemon/web-ui/index.html +585 -0
  259. package/tools/daemon/web-ui/styles.css +156 -0
  260. package/tools/docker/Dockerfile.daemon +35 -0
  261. package/tools/docker/container-manager.mjs +291 -0
  262. package/tools/messaging/adapter-registry.mjs +230 -0
  263. package/tools/messaging/adapters/base.mjs +326 -0
  264. package/tools/messaging/adapters/discord.mjs +462 -0
  265. package/tools/messaging/adapters/slack.mjs +402 -0
  266. package/tools/messaging/adapters/telegram.mjs +552 -0
  267. package/tools/messaging/chat-handler.mjs +297 -0
  268. package/tools/messaging/command-router.mjs +269 -0
  269. package/tools/messaging/event-bus.mjs +199 -0
  270. package/tools/messaging/index.mjs +456 -0
  271. package/tools/messaging/message-formatter.mjs +320 -0
  272. package/tools/messaging/room-manager.mjs +277 -0
  273. package/tools/messaging/types.mjs +94 -0
  274. package/tools/providers/pi-bridge-policy.mjs +4 -0
  275. package/tools/ralph-external/daemon-supervisor.mjs +394 -0
  276. package/tools/ralph-external/lib/behavior-registry.mjs +270 -0
  277. package/tools/ralph-external/lib/worker-invocation-processes.mjs +7 -4
  278. package/tools/ralph-external/lib/worker-isolation-args.mjs +217 -0
  279. package/tools/ralph-external/lib/worker-isolation-status.mjs +19 -0
  280. package/tools/ralph-external/lib/worker-isolation.mjs +11 -237
  281. package/tools/ralph-external/lib/worker-overflow.mjs +10 -2
  282. package/tools/ralph-external/lib/worker-termination.mjs +15 -8
  283. package/tools/ralph-external/lib/worker-unit-cleanup.mjs +72 -0
  284. package/tools/ralph-external/session-launcher.mjs +7 -7
  285. package/tools/scripts/resource-preflight.mjs +3 -242
  286. package/vscode-extension/schemas/aiwg.config.v1.json +2 -4
@@ -79,28 +79,16 @@ import path from 'path';
79
79
  import { importImpl } from '../_resolve-impl.mjs';
80
80
  const { resolveDeployVersion } = await importImpl(import.meta.url, 'providers/deploy-version.mjs');
81
81
  import os from 'os';
82
- import readline from 'readline';
83
82
  import { fileURLToPath } from 'url';
84
83
  import {
85
- addManagedMarker,
86
84
  collectBehaviorDirs,
87
- collectFrameworkArtifacts,
88
- contentHash,
89
85
  deployEmulatedBehaviors,
90
- getAddonSkillDirs,
91
- listSkillDirs,
92
86
  loadModelConfig,
93
87
  loadRuntimeModelCatalog,
94
88
  migrateCommandsDirectory,
95
- parseFrontmatter,
96
89
  resolveAiwgRoot,
97
- updateSidecarManifest,
98
90
  } from './providers/base.mjs';
99
91
 
100
- // ============================================================================
101
- // Provider Registry
102
- // ============================================================================
103
-
104
92
  const PROVIDER_ALIASES = {
105
93
  agy: 'antigravity',
106
94
  'openai': 'codex',
@@ -122,488 +110,6 @@ const UNSUPPORTED_PROVIDER_HINTS = {
122
110
  ],
123
111
  };
124
112
 
125
- const MIRRORED_STANDARD_COMMAND_SKILLS = new Set([
126
- 'aiwg-setup-project',
127
- 'aiwg-update-claude',
128
- 'aiwg-update-agents-md',
129
- 'sdlc-accelerate',
130
- 'project-status',
131
- 'intake-wizard',
132
- 'intake-from-codebase',
133
- 'intake-start',
134
- // Issue-workflow entry commands — invoked directly by users; mirror as
135
- // commands so they reach .opencode/command/, .claude/commands/, etc. (#1549).
136
- 'address-issues',
137
- 'issue-audit',
138
- ]);
139
-
140
- const MIRRORED_KERNEL_COMMAND_SKILLS = new Set([
141
- 'aiwg-refresh',
142
- 'aiwg-doctor',
143
- 'aiwg-status',
144
- 'aiwg-help',
145
- 'aiwg-regenerate',
146
- 'aiwg-regenerate-claude',
147
- 'aiwg-regenerate-codex',
148
- 'aiwg-regenerate-opencode',
149
- 'aiwg-regenerate-agents',
150
- 'aiwg-issue',
151
- 'aiwg-pr',
152
- 'aiwg-mission',
153
- 'use',
154
- 'steward',
155
- ]);
156
-
157
- function providerUsesSkillsNatively(providerName) {
158
- return ['antigravity', 'claude', 'cursor', 'deepseek-harness', 'hermes', 'openhuman', 'pi', 'omp'].includes(providerName);
159
- }
160
-
161
- function shouldMirrorStandardCommandSkill(skillName) {
162
- return (
163
- skillName.startsWith('flow-') ||
164
- MIRRORED_STANDARD_COMMAND_SKILLS.has(skillName)
165
- );
166
- }
167
-
168
- function shouldMirrorCommandSkill(providerName, skillName) {
169
- if (MIRRORED_KERNEL_COMMAND_SKILLS.has(skillName)) {
170
- return !providerUsesSkillsNatively(providerName);
171
- }
172
-
173
- return shouldMirrorStandardCommandSkill(skillName);
174
- }
175
-
176
- function uniquePaths(paths) {
177
- return [...new Set(paths.filter(Boolean))];
178
- }
179
-
180
- export function collectMirrorSkillDirs(srcRoot, mode, providerName) {
181
- const dirs = [];
182
-
183
- const directSkillsDir = path.join(srcRoot, 'skills');
184
- dirs.push(...listSkillDirs(directSkillsDir));
185
-
186
- // If --source itself is a skills directory, support that shape too.
187
- dirs.push(...listSkillDirs(srcRoot));
188
-
189
- const repoFrameworksRoot = path.join(srcRoot, 'agentic', 'code', 'frameworks');
190
- if (fs.existsSync(repoFrameworksRoot)) {
191
- const artifacts = collectFrameworkArtifacts(srcRoot, mode, {
192
- includeAgents: false,
193
- includeCommands: false,
194
- includeSkills: true,
195
- includeRules: false,
196
- });
197
- dirs.push(...artifacts.skills);
198
-
199
- // Pi's provider collector already deploys all eligible addon skills for
200
- // every root framework mode. Mirror the command-shaped addon skills in
201
- // that same root pass so `aiwg use` does not need to repeat the entire
202
- // deployment once per addon merely to produce these wrappers. Keep addon
203
- // skills after framework skills: this preserves the existing per-addon
204
- // winner when a framework and addon expose the same command name.
205
- if (mode === 'all'
206
- || (providerName === 'pi' && ['general', 'sdlc', 'both'].includes(mode))) {
207
- dirs.push(...getAddonSkillDirs(srcRoot));
208
- }
209
- }
210
-
211
- return uniquePaths(dirs);
212
- }
213
-
214
- function resolveCommandMirrorDir(provider, target) {
215
- const commandsPath = provider.paths?.commands;
216
- if (commandsPath) {
217
- return path.isAbsolute(commandsPath) ? commandsPath : path.join(target, commandsPath);
218
- }
219
-
220
- // Closest conventional location for providers whose primary command
221
- // surface is MCP/aggregation rather than a documented command directory.
222
- if (provider.name === 'hermes') {
223
- // #2119: HERMES_HOME is the single source of truth the running Hermes
224
- // runtime uses to locate its files — resolve the home the same way the
225
- // provider does instead of hardcoding $HOME/.hermes.
226
- const hermesHome = typeof provider.getHermesHome === 'function'
227
- ? provider.getHermesHome()
228
- : path.join(os.homedir(), '.hermes');
229
- return path.resolve(hermesHome, 'commands');
230
- }
231
-
232
- return null;
233
- }
234
-
235
- function commandFileExtensionForProvider(provider) {
236
- if (provider.name === 'copilot') return '.prompt.md';
237
- return '.md';
238
- }
239
-
240
- function resolveSkillCommandPolicy(commandHint = {}) {
241
- const legacy = String(commandHint.model || '').trim().toLowerCase();
242
- const legacyRole = legacy === 'opus' ? 'reasoning'
243
- : legacy === 'haiku' ? 'efficiency'
244
- : legacy ? 'coding' : null;
245
- const modelRole = commandHint.modelRole || legacyRole;
246
- if (!modelRole) return null;
247
- const modelTier = commandHint.modelTier
248
- || (modelRole === 'reasoning' ? 'premium'
249
- : modelRole === 'efficiency' ? 'economy' : 'standard');
250
- return {
251
- modelRole,
252
- modelTier,
253
- modelEffort: commandHint.modelEffort,
254
- modelRationale: commandHint.modelRationale,
255
- };
256
- }
257
-
258
- function parseSkillCommandHint(raw) {
259
- const { frontmatter } = parseFrontmatter(raw);
260
- const block = frontmatter?.match(/^commandHint:\s*\n((?:[ \t]+[^\n]*\n?)*)/m)?.[1] || '';
261
- const hint = {};
262
- for (const line of block.split('\n')) {
263
- const match = line.trim().match(/^(model|modelRole|modelTier|modelEffort|modelRationale):\s*(.+)$/);
264
- if (match) hint[match[1]] = match[2].trim().replace(/^['"]|['"]$/g, '');
265
- }
266
- return hint;
267
- }
268
-
269
- function skillToCommandContent(skillDir) {
270
- const skillName = path.basename(skillDir);
271
- const skillPath = path.join(skillDir, 'SKILL.md');
272
- const raw = fs.readFileSync(skillPath, 'utf8');
273
- const { metadata, body } = parseFrontmatter(raw);
274
- const description = metadata.description || `Run AIWG skill ${skillName}`;
275
- const policy = resolveSkillCommandPolicy(parseSkillCommandHint(raw));
276
- const policyLines = policy ? [
277
- `aiwg-model-role: ${policy.modelRole}`,
278
- `aiwg-model-tier: ${policy.modelTier}`,
279
- ...(policy.modelEffort ? [`aiwg-model-effort: ${policy.modelEffort}`] : []),
280
- ...(policy.modelRationale ? [`aiwg-model-rationale: ${policy.modelRationale}`] : []),
281
- ] : [];
282
-
283
- return `---\nname: ${skillName}\ndescription: ${description}\n${policyLines.join('\n')}${policyLines.length ? '\n' : ''}---\n\n${body.trim()}\n`;
284
- }
285
-
286
- function mirrorSkillsAsCommands(provider, target, srcRoot, opts) {
287
- if (!opts.deployCommands && !opts.commandsOnly) return 0;
288
-
289
- const targetDir = resolveCommandMirrorDir(provider, target);
290
- if (!targetDir) return 0;
291
-
292
- const skillDirs = collectMirrorSkillDirs(srcRoot, opts.mode, provider.name)
293
- .filter((dir) => shouldMirrorCommandSkill(provider.name, path.basename(dir)));
294
-
295
- if (skillDirs.length === 0) return 0;
296
- if (!opts.dryRun) fs.mkdirSync(targetDir, { recursive: true });
297
-
298
- const ext = commandFileExtensionForProvider(provider);
299
- const deployedEntries = [];
300
- let count = 0;
301
-
302
- for (const skillDir of skillDirs) {
303
- const skillName = path.basename(skillDir);
304
- let content = skillToCommandContent(skillDir);
305
- if (typeof provider.transformCommand === 'function') {
306
- content = provider.transformCommand(path.join(skillDir, `${skillName}.md`), content, opts);
307
- }
308
- // #2507: mirrored wrappers used to be written with no ownership signal, so
309
- // AIWG could neither count them as deployed nor prune them when the source
310
- // skill went away — a later run reported its own 46 wrappers as unmanaged
311
- // artifacts the operator should delete. They carry the same managed marker
312
- // and sidecar entry as any other deployed command now.
313
- content = addManagedMarker(content, opts.deployVersion || 'unknown', opts.deploySource || 'bundled');
314
-
315
- const filename = `${skillName}${ext}`;
316
- const dest = path.join(targetDir, filename);
317
- if (opts.dryRun) {
318
- if (opts.verbose) console.log(`[dry-run] mirror skill command ${skillName} -> ${dest}`);
319
- const raw = fs.readFileSync(path.join(skillDir, 'SKILL.md'), 'utf8');
320
- const policy = resolveSkillCommandPolicy(parseSkillCommandHint(raw));
321
- if (policy && opts.verbose) {
322
- const outcome = provider.name === 'claude' ? 'native'
323
- : provider.name === 'factory' ? 'informational' : 'unsupported';
324
- console.log(`[dry-run] skill model policy ${skillName}: ${outcome} (${policy.modelRole}/${policy.modelTier})`);
325
- }
326
- } else {
327
- fs.writeFileSync(dest, content, 'utf8');
328
- }
329
- deployedEntries.push({ filename, hash: contentHash(content), kind: 'skill-command' });
330
- count++;
331
- }
332
-
333
- if (deployedEntries.length > 0) {
334
- updateSidecarManifest(targetDir, deployedEntries, {
335
- dryRun: opts.dryRun,
336
- version: opts.deployVersion || 'unknown',
337
- source: opts.deploySource || 'bundled',
338
- });
339
- }
340
-
341
- return count;
342
- }
343
-
344
-
345
- export { bulkInstallOwnsFlatArtifacts } from './providers/stale-artifact-prune.mjs';
346
- import { pruneStaleAiwgArtifacts } from './providers/stale-artifact-prune.mjs';
347
-
348
- // ============================================================================
349
- // Argument Parsing
350
- // ============================================================================
351
-
352
- export function parseArgs(args = process.argv.slice(2)) {
353
- const cfg = {
354
- source: null,
355
- userScope: false,
356
- target: process.cwd(),
357
- mode: 'all', // 'general', 'sdlc', 'marketing', 'media-curator', 'research', 'both' (legacy), or 'all'
358
- dryRun: false,
359
- force: false,
360
- provider: 'claude',
361
- model: null, // Blanket override for all tiers
362
- modelTier: null, // Blanket canonical tier override
363
- reasoningModel: null,
364
- codingModel: null,
365
- efficiencyModel: null,
366
- asAgentsMd: false,
367
- createAgentsMd: false,
368
- contextFiles: true,
369
- projectScope: false,
370
- deployCommands: false,
371
- deploySkills: false,
372
- deployRules: false,
373
- deployBehaviors: false, // Deploy behaviors (native on openclaw, emulated on others)
374
- commandsOnly: false,
375
- skillsOnly: false,
376
- rulesOnly: false,
377
- strict: false,
378
- reportOnly: true,
379
- kernelOnly: false,
380
- deferRuleProjection: false,
381
- additionalSources: [],
382
- filter: null, // Glob pattern for agent names
383
- filterRole: null, // Filter by role: reasoning|coding|efficiency
384
- save: false, // Save model config to project models.json
385
- saveUser: false, // Save model config to ~/.config/aiwg/models.json
386
- verbose: false, // Show per-file deployment details
387
- quiet: false, // Suppress all non-error output (for embedding in use.ts)
388
- asPlugin: false, // Generate .factory-plugin/ bundle (Factory provider only)
389
- deployBehaviors: false, // Deploy behaviors in addition to agents
390
- skipCommandsMigration: false, // Skip commands → skills migration (warns about duplicates)
391
- warnOnSkippedCommandsMigration: true, // Emit the duplicate warning when the migration is skipped
392
- // Managed-marker provenance (#2502). Deployers that are not shipping the
393
- // bundled framework corpus (project-local bundles, in particular) must
394
- // override these so `aiwg refresh` does not mistake their artifacts for
395
- // stale copies of packaged ones.
396
- deploySource: null, // Managed-marker source; defaults to 'bundled'
397
- listingBudget: false, // Honor the provider startup-listing cap despite --copy-all (#2561)
398
- deployVersion: null, // Managed-marker version; defaults to srcRoot package.json
399
- mcp: false, // #228: opt-in MCP settings profile (Muse provider)
400
- hooks: true, // #228: managed project hooks (Muse provider); --no-hooks opts out
401
- };
402
- for (let i = 0; i < args.length; i++) {
403
- const a = args[i];
404
- if (a === '--source' && args[i + 1]) cfg.source = path.resolve(args[++i]);
405
- else if (a === '--additional-source') {
406
- const source = args[++i];
407
- if (!source || source.startsWith('--')) throw new Error('--additional-source requires a source directory');
408
- cfg.additionalSources.push(path.resolve(source));
409
- }
410
- else if (a === '--target' && args[i + 1]) cfg.target = path.resolve(args[++i]);
411
- else if (a === '--mode' && args[i + 1]) cfg.mode = String(args[++i]).toLowerCase();
412
- else if (a === '--scope') {
413
- const scope = args[++i];
414
- if (scope !== 'user' && scope !== 'project') {
415
- throw new Error(`--scope expected 'user' or 'project', got '${scope ?? '(missing)'}'`);
416
- }
417
- cfg.userScope = scope === 'user';
418
- cfg.projectScope = scope === 'project';
419
- }
420
- else if (a === '--user') cfg.userScope = true;
421
- else if (a === '--dry-run') cfg.dryRun = true;
422
- else if (a === '--force') cfg.force = true;
423
- else if ((a === '--provider' || a === '--platform') && args[i + 1]) cfg.provider = String(args[++i]).toLowerCase();
424
- else if (a === '--model' && args[i + 1]) cfg.model = args[++i];
425
- else if (a === '--model-tier' && args[i + 1]) cfg.modelTier = String(args[++i]).toLowerCase();
426
- else if ((a === '--reasoning-model' || a === '--reasoning') && args[i + 1]) cfg.reasoningModel = args[++i];
427
- else if ((a === '--coding-model' || a === '--coding') && args[i + 1]) cfg.codingModel = args[++i];
428
- else if ((a === '--efficiency-model' || a === '--efficiency') && args[i + 1]) cfg.efficiencyModel = args[++i];
429
- else if (a === '--as-agents-md') cfg.asAgentsMd = true;
430
- else if (a === '--create-agents-md') cfg.createAgentsMd = true;
431
- else if (a === '--deploy-commands') cfg.deployCommands = true;
432
- else if (a === '--deploy-skills') cfg.deploySkills = true;
433
- else if (a === '--deploy-rules') cfg.deployRules = true;
434
- else if (a === '--deploy-behaviors') cfg.deployBehaviors = true;
435
- else if (a === '--commands-only') cfg.commandsOnly = true;
436
- else if (a === '--skills-only') cfg.skillsOnly = true;
437
- else if (a === '--rules-only') cfg.rulesOnly = true;
438
- else if (a === '--strict') { cfg.strict = true; cfg.reportOnly = false; }
439
- else if (a === '--allow-over-budget') cfg.allowOverBudget = true;
440
- else if (a === '--report-only') cfg.reportOnly = true;
441
- else if (a === '--kernel-only') cfg.kernelOnly = true;
442
- // Internal use orchestration: the final source owns rule presentation.
443
- else if (a === '--defer-rule-projection') cfg.deferRuleProjection = true;
444
- else if (a === '--deploy-behaviors') cfg.deployBehaviors = true;
445
- else if (a === '--filter' && args[i + 1]) cfg.filter = args[++i];
446
- else if (a === '--filter-role' && args[i + 1]) cfg.filterRole = args[++i];
447
- else if (a === '--save') cfg.save = true;
448
- else if (a === '--save-user') cfg.saveUser = true;
449
- else if (a === '--verbose' || a === '-v') cfg.verbose = true;
450
- else if (a === '--quiet' || a === '-q') cfg.quiet = true;
451
- else if (a === '--as-plugin') cfg.asPlugin = true;
452
- else if (a === '--skip-commands-migration') cfg.skipCommandsMigration = true;
453
- // Structural opt-out: skip the migration without claiming the operator declined it (#2541).
454
- else if (a === '--no-commands-warning') cfg.warnOnSkippedCommandsMigration = false;
455
- else if (a === '--copy-all' || a === '--copy-standard-skills') cfg.copyStandardSkills = true;
456
- // #228: Muse provider — explicit opt-in MCP settings profile, and the
457
- // managed-hooks opt-out (default on, mirroring the Claude autoInstall policy).
458
- else if (a === '--mcp') cfg.mcp = true;
459
- else if (a === '--no-hooks') cfg.hooks = false;
460
- else if (a === '--no-context-files') cfg.contextFiles = false;
461
- else if (a === '--deploy-source' && args[i + 1]) cfg.deploySource = String(args[++i]);
462
- else if (a === '--listing-budget') cfg.listingBudget = true;
463
- else if (a === '--deploy-version' && args[i + 1]) cfg.deployVersion = String(args[++i]);
464
- else if (a === '--help' || a === '-h') {
465
- cfg.help = true;
466
- }
467
- }
468
- return cfg;
469
- }
470
-
471
- function printHelp() {
472
- console.log(`
473
- Deploy Agents and Commands
474
-
475
- Usage:
476
- node tools/agents/deploy-agents.mjs [options]
477
- aiwg -deploy-agents [options]
478
-
479
- Options:
480
- --source <path> Source directory (defaults to repo root)
481
- --target <path> Target directory (defaults to cwd)
482
- --scope <user|project> Deployment scope (default: project)
483
- --user Shorthand for --scope user
484
- --mode <type> Deployment mode: general, sdlc, marketing (alias: mmk), media-curator, research, both, or all (default)
485
- --deploy-commands Deploy commands in addition to agents
486
- --deploy-skills Deploy skills in addition to agents
487
- --deploy-rules Deploy rules in addition to agents
488
- --commands-only Deploy only commands (skip agents)
489
- --skills-only Deploy only skills (skip agents)
490
- --rules-only Deploy only rules (skip agents)
491
- --kernel-only Deploy kernel skills and rules; prune managed bulk agents/commands
492
- --dry-run Show what would be deployed without writing
493
- --force Overwrite existing files
494
- --provider <name> Target provider (see below)
495
- --model <name> Override model for all tiers (blanket)
496
- --reasoning-model <name> Override model for reasoning tasks (alias: --reasoning)
497
- --coding-model <name> Override model for coding tasks (alias: --coding)
498
- --efficiency-model <name> Override model for efficiency tasks (alias: --efficiency)
499
- --model-tier <tier> Override all artifacts with economy|standard|premium
500
- --filter <pattern> Only deploy agents matching pattern (glob)
501
- --filter-role <role> Only deploy agents of role: reasoning|coding|efficiency
502
- --save Save model config to project models.json
503
- --save-user Save model config to ~/.config/aiwg/models.json
504
- --mcp Muse provider: opt in to the AIWG MCP settings profile
505
- (merges the aiwg stdio server into user settings
506
- mcp_servers; default off)
507
- --no-hooks Muse provider: skip managed project hooks
508
- (.muse/hooks.json; installed by default)
509
- --as-agents-md Aggregate to single AGENTS.md (Codex)
510
- --create-agents-md Create/update AGENTS.md template
511
- --no-context-files Preserve WORKSPACE.md, AIWG.md and AGENTS.md (including managed blocks)
512
- --skip-commands-migration Skip deleting the commands directory before skills deployment
513
- --listing-budget Honor the provider startup-listing cap even with --copy-all
514
- --deploy-source <name> Managed-marker source stamped into deployed artifacts.
515
- Defaults to 'bundled'. Deploys that do not ship the packaged
516
- framework corpus (e.g. project-local bundles) MUST override
517
- this so refresh's stale-artifact prune skips them (#2502).
518
- --deploy-version <version> Managed-marker version stamped into deployed artifacts.
519
- Defaults to the --source tree's package.json version.
520
- --copy-all Copy ALL skills per-project (legacy mirror at <provider>/.aiwg/skills/).
521
- For aiwg use all, this also restores the legacy full agent,
522
- command, and expanded-rule copy. Default bulk deployment is
523
- kernel-only + index-driven discovery for the rest (#1217).
524
- Use this for sandboxed runtimes / air-gapped corpora where
525
- $AIWG_ROOT isn't readable from the agent's working dir.
526
- Alias: --copy-standard-skills — rc.29 era).
527
- (warns about duplicate entries in the provider command palette)
528
-
529
- Model Override Examples:
530
- # Use sonnet for everything
531
- aiwg use sdlc --model sonnet
532
-
533
- # Override individual tiers
534
- aiwg use sdlc --reasoning opus --coding sonnet --efficiency haiku
535
-
536
- # Use a specific model ID for coding tier
537
- aiwg use sdlc --provider factory --coding-model gpt-5.6-terra
538
-
539
- # Blanket with per-tier override (reasoning uses opus, others use sonnet)
540
- aiwg use sdlc --model sonnet --reasoning opus
541
-
542
- # Save overrides to project models.json for future deployments
543
- aiwg use sdlc --model sonnet --save
544
-
545
- Model Precedence:
546
- CLI flags > project models.json > user ~/.config/aiwg/models.json > AIWG defaults
547
-
548
- Shorthand Values:
549
- opus, sonnet, haiku, inherit — resolved per provider to full model IDs
550
-
551
- Providers (all deploy agents, commands, skills, and rules):
552
- claude - Claude Code (default)
553
- Paths: .claude/agents/, .claude/commands/, .claude/skills/, .claude/rules/
554
- factory - Factory AI
555
- Paths: .factory/droids/, .factory/commands/, .factory/skills/, .factory/rules/
556
- codex - OpenAI Codex (alias: openai)
557
- Paths: .codex/agents/, .codex/commands/, .codex/skills/, .codex/rules/
558
- opencode - OpenCode
559
- Paths: .opencode/skill/, .opencode/rule/ (agents/commands not file-based in OpenCode)
560
- copilot - GitHub Copilot
561
- Paths: .github/agents/, .github/commands/, .github/skills/, .github/copilot-rules/
562
- cursor - Cursor IDE
563
- Paths: .cursor/agents/, .cursor/commands/, .cursor/skills/, .cursor/rules/
564
- warp - Warp Terminal
565
- Paths: .warp/agents/, .warp/commands/, .warp/skills/, .warp/rules/ + WARP.md
566
- deepseek-harness - DeepSeek Harness (alias: dsh; experimental)
567
- Paths: AGENTS.md, .agents/skills/, .dsh/aiwg.cordis.patch.yml
568
- devin - Devin Desktop (preferred; aliases: devin-desktop, windsurf)
569
- Paths: .windsurf/agents/, .windsurf/workflows/, .windsurf/skills/, .windsurf/rules/
570
- grokbot - Grok Bot (AGENTS.md bridge; skills only with AIWG_GROKBOT_SKILLS_DIR)
571
- grok-build - Grok Build (experimental; .grok paths + $GROK_HOME; no bare grok alias)
572
- muse - Muse Code (stable; AGENTS.md bridge; .agents/skills + XDG user root; managed hooks, opt-in --mcp; no aliases)
573
- hermes - Hermes Agent (MCP-based integration)
574
- Skills: $HERMES_HOME/skills/ (user-global; defaults to ~/.hermes/skills/) | Agents: AGENTS.md
575
- Commands/Rules: served via MCP, not file-deployed
576
-
577
- Modes:
578
- general - Writing-quality addon agents and commands (alias: writing)
579
- sdlc - SDLC Complete framework agents and commands
580
- marketing - Media/Marketing Kit framework agents and commands (alias: mmk)
581
- media-curator - Media Curator framework agents and commands
582
- research - Research Complete framework agents and commands
583
- both - writing + SDLC (legacy compatibility)
584
- all - All frameworks + addons (default)
585
-
586
- Examples:
587
- # Deploy SDLC framework to Claude Code
588
- aiwg -deploy-agents --mode sdlc
589
-
590
- # Deploy to Factory with commands and AGENTS.md
591
- aiwg -deploy-agents --provider factory --mode sdlc --deploy-commands --create-agents-md
592
-
593
- # Deploy to GitHub Copilot
594
- aiwg -deploy-agents --provider copilot --mode sdlc
595
-
596
- # Override model for all tiers
597
- aiwg -deploy-agents --mode sdlc --model sonnet
598
-
599
- # Override individual tiers
600
- aiwg -deploy-agents --mode sdlc --reasoning opus --coding sonnet --efficiency haiku
601
-
602
- # Dry run to preview deployment
603
- aiwg -deploy-agents --provider cursor --mode sdlc --dry-run
604
- `);
605
- }
606
-
607
113
  // ============================================================================
608
114
  // Provider Loading
609
115
  // ============================================================================
@@ -611,7 +117,7 @@ Examples:
611
117
  /**
612
118
  * Resolve provider name (handle aliases)
613
119
  */
614
- function resolveProvider(name) {
120
+ export function resolveProvider(name) {
615
121
  const candidate = String(name || '').trim().toLowerCase();
616
122
  const resolved = PROVIDER_ALIASES[candidate] || candidate;
617
123
  if (!AVAILABLE_PROVIDERS.includes(resolved)) {
@@ -630,7 +136,7 @@ function resolveProvider(name) {
630
136
  /**
631
137
  * Dynamically load provider module
632
138
  */
633
- async function loadProvider(providerName) {
139
+ export async function loadProvider(providerName) {
634
140
  const resolved = resolveProvider(providerName);
635
141
  // Resolve against this module, not the caller's cwd: in-process callers
636
142
  // (including module runners such as Vitest) cannot resolve a bare relative
@@ -646,187 +152,16 @@ async function loadProvider(providerName) {
646
152
  }
647
153
  }
648
154
 
649
- // ============================================================================
650
- // Model Shorthand Resolution
651
- // ============================================================================
652
-
653
- /**
654
- * Resolve a shorthand model value to a full model ID
655
- *
656
- * If the value is a known shorthand (opus, sonnet, haiku, inherit), resolve it
657
- * through the provider's shorthand map. Otherwise treat it as a literal model ID.
658
- *
659
- * @param {string|null} value - CLI flag value (e.g., "opus" or "claude-opus-5")
660
- * @param {object} shorthandMap - Provider shorthand map (e.g., { opus: "claude-opus-5" })
661
- * @param {object} modelsConfig - Full models config from loadModelConfig()
662
- * @param {string} provider - Provider name
663
- * @param {string} tier - Tier name: "reasoning", "coding", or "efficiency"
664
- * @returns {string|null} Resolved model ID or null if input was null
665
- */
666
- function resolveShorthand(value, shorthandMap, modelsConfig, provider, tier) {
667
- if (!value) return null;
668
-
669
- const clean = value.toLowerCase().replace(/['"]/g, '');
670
-
671
- // Check shorthand map first
672
- if (shorthandMap[clean]) return shorthandMap[clean];
673
-
674
- // Check provider-specific tier config (e.g., modelsConfig.factory.reasoning.model)
675
- const providerConfig = modelsConfig?.[provider];
676
- if (providerConfig?.[tier]?.model && clean === tier) {
677
- return providerConfig[tier].model;
678
- }
679
-
680
- // Not a shorthand — return as literal model ID
681
- return value;
682
- }
683
-
684
- // ============================================================================
685
- // Model Configuration Persistence
686
- // ============================================================================
687
-
688
- /**
689
- * Save model configuration to project or user config file
690
- * @param {object} cfg - Configuration with model overrides
691
- * @param {string} providerName - Provider name for provider-specific config
692
- */
693
- async function saveModelConfig(cfg, providerName) {
694
- // Build config object with only the provided overrides
695
- const modelConfig = {};
696
- if (cfg.modelTier) {
697
- modelConfig.defaults = { tier: cfg.modelTier };
698
- }
699
-
700
- // Provider-specific tier configuration
701
- if (cfg.reasoningModel || cfg.codingModel || cfg.efficiencyModel) {
702
- modelConfig[providerName] = {};
703
- if (cfg.reasoningModel) {
704
- modelConfig[providerName].reasoning = { model: cfg.reasoningModel };
705
- }
706
- if (cfg.codingModel) {
707
- modelConfig[providerName].coding = { model: cfg.codingModel };
708
- }
709
- if (cfg.efficiencyModel) {
710
- modelConfig[providerName].efficiency = { model: cfg.efficiencyModel };
711
- }
712
- }
713
-
714
- // Shorthand mappings
715
- if (cfg.reasoningModel || cfg.codingModel || cfg.efficiencyModel) {
716
- modelConfig.shorthand = {};
717
- if (cfg.reasoningModel) modelConfig.shorthand.opus = cfg.reasoningModel;
718
- if (cfg.codingModel) modelConfig.shorthand.sonnet = cfg.codingModel;
719
- if (cfg.efficiencyModel) modelConfig.shorthand.haiku = cfg.efficiencyModel;
720
- }
721
-
722
- // Determine target path
723
- let targetPath;
724
- if (cfg.saveUser) {
725
- const configDir = path.join(os.homedir(), '.config', 'aiwg');
726
- if (!fs.existsSync(configDir)) {
727
- fs.mkdirSync(configDir, { recursive: true });
728
- }
729
- targetPath = path.join(configDir, 'models.json');
730
- } else {
731
- targetPath = path.join(cfg.target, 'models.json');
732
- }
733
-
734
- // Merge with existing config if it exists
735
- let existingConfig = {};
736
- if (fs.existsSync(targetPath)) {
737
- try {
738
- existingConfig = JSON.parse(fs.readFileSync(targetPath, 'utf8'));
739
- } catch {
740
- // Ignore parse errors, start fresh
741
- }
742
- }
743
-
744
- // Deep merge: existing config + new overrides
745
- const mergedConfig = deepMerge(existingConfig, modelConfig);
746
-
747
- // Write the config
748
- fs.writeFileSync(targetPath, JSON.stringify(mergedConfig, null, 2) + '\n', 'utf8');
749
- console.log(`\nModel configuration saved to: ${targetPath}`);
750
- }
751
-
752
- /**
753
- * Deep merge two objects
754
- */
755
- function deepMerge(target, source) {
756
- const result = { ...target };
757
- for (const key of Object.keys(source)) {
758
- if (source[key] && typeof source[key] === 'object' && !Array.isArray(source[key])) {
759
- result[key] = deepMerge(result[key] || {}, source[key]);
760
- } else {
761
- result[key] = source[key];
762
- }
763
- }
764
- return result;
765
- }
766
-
767
- // ============================================================================
768
- // Commands → Skills Migration
769
- // ============================================================================
770
-
771
- /**
772
- * Ask the user whether to delete the provider's commands directory before
773
- * deploying skills. Skipped automatically when not running in a TTY (CI/pipe)
774
- * or when --quiet is set.
775
- *
776
- * @param {object} cfg - Parsed CLI config
777
- * @param {object} provider - Loaded provider module
778
- * @param {string} targetDir - Resolved target directory
779
- * @returns {Promise<boolean>} true = proceed with migration, false = skip
780
- */
781
- async function promptCommandsMigration(cfg, provider, targetDir, interactive = process.stdout.isTTY) {
782
- // Home-directory providers share commands across projects — do not delete.
783
- if (provider.capabilities?.homeDirectoryDeploy) return false;
784
- // Some providers intentionally expose both surfaces with different runtime
785
- // semantics. Pi prompt templates (/name) are not aliases for Agent Skills
786
- // (/skill:name), so command-to-skill migration would destroy valid prompts.
787
- if (provider.capabilities?.parallelCommandAndSkillSurfaces) return false;
788
-
789
- const commandsRelPath = provider.paths?.commands;
790
- if (!commandsRelPath) return false;
791
-
792
- const commandsDir = path.join(targetDir, commandsRelPath);
793
- if (!fs.existsSync(commandsDir)) return false;
794
-
795
- const entries = fs.readdirSync(commandsDir).filter(e => e.endsWith('.md'));
796
- if (entries.length === 0) return false;
797
-
798
- // Non-interactive context: migrate silently.
799
- if (cfg.quiet || !interactive) return true;
800
-
801
- const rel = path.relative(process.cwd(), commandsDir);
802
- console.log(`\n⚠ Commands → Skills Migration`);
803
- console.log(` ${rel} contains ${entries.length} legacy command file(s).`);
804
- console.log(` AIWG now serves these as skills (.claude/skills/).`);
805
- console.log(` Keeping both causes duplicate entries in the Claude Code command palette.`);
806
- console.log('');
807
-
808
- const answer = await new Promise(resolve => {
809
- const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
810
- rl.question(' Remove commands directory and migrate? [Y/n] ', ans => {
811
- rl.close();
812
- resolve(ans.trim().toLowerCase());
813
- });
814
- });
815
155
 
816
- if (answer === 'n' || answer === 'no') {
817
- console.log('');
818
- console.log(' Skipping migration. Run `aiwg use` again without --skip-commands-migration');
819
- console.log(` to clean up, or delete ${rel} manually.`);
820
- console.log('');
821
- return false;
822
- }
823
-
824
- return true;
825
- }
156
+ export { bulkInstallOwnsFlatArtifacts } from './providers/stale-artifact-prune.mjs';
157
+ import { pruneStaleAiwgArtifacts } from './providers/stale-artifact-prune.mjs';
826
158
 
827
- // ============================================================================
828
- // Main Entry Point
829
- // ============================================================================
159
+ export { parseArgs } from './deploy-options.mjs';
160
+ export { collectMirrorSkillDirs } from './deploy-command-mirrors.mjs';
161
+ import { parseArgs, printHelp } from './deploy-options.mjs';
162
+ import { mirrorSkillsAsCommands } from './deploy-command-mirrors.mjs';
163
+ import { resolveShorthand, saveModelConfig, promptCommandsMigration } from './deploy-support.mjs';
164
+ const { captureDeploymentOutputs, recordDeploymentOutputs, deploymentOutputRoots } = await importImpl(import.meta.url, 'providers/deployment-ownership.mjs');
830
165
 
831
166
  export async function main(args = process.argv.slice(2), internal = {}) {
832
167
  const cfg = parseArgs(args);
@@ -910,7 +245,9 @@ export async function main(args = process.argv.slice(2), internal = {}) {
910
245
  if (!cfg.quiet) console.log(`\nLoaded provider: ${provider.name}`);
911
246
 
912
247
  // Build options for provider
248
+ const { writeContextFileSync } = await import('./providers/context-write.mjs');
913
249
  const opts = {
250
+ writeReceipt: writeContextFileSync,
914
251
  srcRoot,
915
252
  target: cfg.target,
916
253
  ...(cfg.userScope ? { userScope: true } : {}),
@@ -962,6 +299,7 @@ export async function main(args = process.argv.slice(2), internal = {}) {
962
299
  // #228: Muse provider hooks/MCP profile surface.
963
300
  mcp: cfg.mcp === true,
964
301
  hooks: cfg.hooks !== false,
302
+ attribution: cfg.attribution !== false,
965
303
  listingBudget: cfg.listingBudget === true,
966
304
  deployVersion: resolveDeployVersion(resolveAiwgRoot(srcRoot) || srcRoot, cfg.deployVersion),
967
305
  deploySource: cfg.deploySource || 'bundled',
@@ -1003,6 +341,9 @@ export async function main(args = process.argv.slice(2), internal = {}) {
1003
341
  // must remain on the same side of the transaction boundary as serial deploy.
1004
342
  if (internal.preflightOnly) return;
1005
343
 
344
+ const ownershipRoots = deploymentOutputRoots(provider, cfg.target);
345
+ const ownershipBefore = cfg.dryRun || preparationActive || internal.preflightOnly ? null : captureDeploymentOutputs(ownershipRoots);
346
+
1006
347
  // Delegate to provider
1007
348
  try {
1008
349
  if (!internal.finalizeOnly) {
@@ -1014,6 +355,13 @@ export async function main(args = process.argv.slice(2), internal = {}) {
1014
355
  }
1015
356
  if (preparationActive) return;
1016
357
 
358
+ // User settings are outside staging: write only after a real promotion.
359
+ if (provider.name === 'claude' && cfg.userScope && !cfg.dryRun && cfg.attribution !== false) {
360
+ const { installAiwgHooks } = await importImpl(import.meta.url, 'extensions/claude-hooks-installer.js');
361
+ const result = await installAiwgHooks({ projectPath: os.homedir(), frameworkRoot: srcRoot, hooks: false });
362
+ for (const warning of result?.warnings || []) console.warn(`Claude settings: ${warning}`);
363
+ }
364
+
1017
365
  const mirroredCommandCount = mirrorSkillsAsCommands(provider, cfg.target, srcRoot, opts);
1018
366
  if (mirroredCommandCount > 0 && !cfg.quiet) {
1019
367
  console.log(` Mirrored: ${mirroredCommandCount} skill command wrapper${mirroredCommandCount === 1 ? '' : 's'}`);
@@ -1036,6 +384,7 @@ export async function main(args = process.argv.slice(2), internal = {}) {
1036
384
  await saveModelConfig(cfg, provider.name);
1037
385
  }
1038
386
 
387
+ if (ownershipBefore) recordDeploymentOutputs(ownershipBefore, ownershipRoots, opts);
1039
388
  if (!cfg.quiet) console.log(`\n=== Deployment complete ===\n`);
1040
389
  } catch (err) {
1041
390
  if (preparationActive || internal.finalizeOnly) throw err;