@aiwg/cli 2026.10.16 → 2026.10.19

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 (155) hide show
  1. package/agentic/code/providers/capability-matrix.yaml +51 -0
  2. package/agentic/code/providers/flue/README.md +62 -0
  3. package/agentic/code/providers/flue/templates/aiwg/tools.ts +120 -0
  4. package/agentic/code/providers/model-capabilities.v1.json +23 -0
  5. package/agentic/code/providers/model-catalog.v1.json +9 -0
  6. package/dist/src/artifacts/corpus-tools/resolve.js +28 -6
  7. package/dist/src/artifacts/query-engine-corpus.js +217 -0
  8. package/dist/src/artifacts/query-engine-discover-output.js +229 -0
  9. package/dist/src/artifacts/query-engine-discover.js +285 -0
  10. package/dist/src/artifacts/query-engine-entries.js +188 -0
  11. package/dist/src/artifacts/query-engine-index.js +249 -0
  12. package/dist/src/artifacts/query-engine-matching.js +143 -0
  13. package/dist/src/artifacts/query-engine-options.js +2 -0
  14. package/dist/src/artifacts/query-engine-rules.js +202 -0
  15. package/dist/src/artifacts/query-engine-scoring.js +436 -0
  16. package/dist/src/artifacts/query-engine-show-card.js +194 -0
  17. package/dist/src/artifacts/query-engine-show-load.js +211 -0
  18. package/dist/src/artifacts/query-engine-show.js +300 -0
  19. package/dist/src/artifacts/query-engine.js +7 -2576
  20. package/dist/src/cli/handlers/help.js +1 -1
  21. package/dist/src/cli/handlers/init.js +1 -0
  22. package/dist/src/cli/handlers/mc-agents.js +111 -0
  23. package/dist/src/cli/handlers/mc-args.js +54 -0
  24. package/dist/src/cli/handlers/mc-control.js +227 -0
  25. package/dist/src/cli/handlers/mc-dispatch.js +203 -0
  26. package/dist/src/cli/handlers/mc-help.js +171 -0
  27. package/dist/src/cli/handlers/mc-run.js +343 -0
  28. package/dist/src/cli/handlers/mc-session.js +138 -0
  29. package/dist/src/cli/handlers/mc-status.js +258 -0
  30. package/dist/src/cli/handlers/mc-summary.js +43 -0
  31. package/dist/src/cli/handlers/mc-types.js +3 -0
  32. package/dist/src/cli/handlers/mc-worker.js +205 -0
  33. package/dist/src/cli/handlers/mc.js +12 -1665
  34. package/dist/src/cli/handlers/models-refusal.js +13 -0
  35. package/dist/src/cli/handlers/models.js +2 -1
  36. package/dist/src/cli/handlers/remove-bundled.js +133 -0
  37. package/dist/src/cli/handlers/remove-options.js +31 -0
  38. package/dist/src/cli/handlers/remove-user.js +174 -0
  39. package/dist/src/cli/handlers/remove.js +201 -0
  40. package/dist/src/cli/handlers/subcommands-bundles.js +257 -0
  41. package/dist/src/cli/handlers/subcommands-discovery.js +165 -0
  42. package/dist/src/cli/handlers/subcommands-list-format.js +129 -0
  43. package/dist/src/cli/handlers/subcommands-list.js +250 -0
  44. package/dist/src/cli/handlers/subcommands-plugins.js +213 -0
  45. package/dist/src/cli/handlers/subcommands-quickref.js +58 -0
  46. package/dist/src/cli/handlers/subcommands-rlm.js +113 -0
  47. package/dist/src/cli/handlers/subcommands-services.js +66 -0
  48. package/dist/src/cli/handlers/subcommands-storage.js +259 -0
  49. package/dist/src/cli/handlers/subcommands.js +18 -1984
  50. package/dist/src/cli/handlers/use.js +11 -5
  51. package/dist/src/cli/scope-resolver.js +1 -142
  52. package/dist/src/cli/services/deployment-verification.js +3 -0
  53. package/dist/src/cli/user-scope-mirror.js +173 -0
  54. package/dist/src/config/dispatch-host-thresholds.js +2 -0
  55. package/dist/src/config/dispatch-thresholds-runtime.mjs +4 -0
  56. package/dist/src/config/host-resource-report.d.mts +5 -0
  57. package/dist/src/config/host-resource-report.mjs +36 -6
  58. package/dist/src/config/host-resource-runtime.d.mts +3 -0
  59. package/dist/src/config/host-resource-runtime.mjs +9 -6
  60. package/dist/src/decision/ensemble-study/artifacts.js +7 -0
  61. package/dist/src/decision/ensemble-study/gate-policy.js +58 -0
  62. package/dist/src/decision/ensemble-study/gates.js +78 -0
  63. package/dist/src/decision/ensemble-study/protocol.js +18 -21
  64. package/dist/src/decision/ensemble-study/score.js +3 -2
  65. package/dist/src/decision/ensemble-study/statistics.js +7 -26
  66. package/dist/src/decision/sensitivity/comparative-gates.js +135 -0
  67. package/dist/src/decision/sensitivity/comparative.js +18 -41
  68. package/dist/src/extensions/claude-hooks-installer.js +18 -0
  69. package/dist/src/gates/evaluate.js +2 -358
  70. package/dist/src/gates/observations.js +363 -0
  71. package/dist/src/gates/pack-composition.js +270 -0
  72. package/dist/src/gates/pack-tightening.js +197 -0
  73. package/dist/src/gates/pack-validation.js +262 -0
  74. package/dist/src/gates/registry-error.js +5 -0
  75. package/dist/src/gates/registry.js +13 -685
  76. package/dist/src/mcp/json-document.mjs +29 -0
  77. package/dist/src/mcp/muse-native-config.mjs +1 -28
  78. package/dist/src/memory/provider-memory-adapter.js +1 -0
  79. package/dist/src/mission-protocol/worker-review-gate.js +7 -0
  80. package/dist/src/models/model-capabilities.v1.json +23 -0
  81. package/dist/src/models/model-catalog.v1.json +9 -0
  82. package/dist/src/models/policy-resources.js +1 -1
  83. package/dist/src/models/worker-plan.js +5 -5
  84. package/dist/src/plugin/command-ownership.js +34 -0
  85. package/dist/src/plugin/skill-command-frontmatter.js +197 -0
  86. package/dist/src/plugin/skill-command-translator.js +6 -232
  87. package/dist/src/providers/capability-matrix.yaml +51 -0
  88. package/dist/src/providers/context-output-ownership.js +26 -0
  89. package/dist/src/providers/deployment-ownership.d.mts +20 -0
  90. package/dist/src/providers/deployment-ownership.mjs +236 -0
  91. package/dist/src/providers/deployment-removal.js +222 -0
  92. package/dist/src/providers/provider-context-contracts.js +8 -0
  93. package/dist/src/providers/provider-definition-schema.js +1 -0
  94. package/dist/src/providers/provider-definitions.js +1 -0
  95. package/dist/src/providers/provider-seeds-3.js +18 -0
  96. package/dist/src/providers/removal-transaction.js +86 -0
  97. package/dist/src/providers/settings-document.d.mts +3 -0
  98. package/dist/src/providers/settings-document.mjs +47 -0
  99. package/dist/src/providers/settings-removal.js +190 -0
  100. package/dist/src/providers/skill-ownership.d.mts +20 -2
  101. package/dist/src/providers/skill-ownership.mjs +12 -4
  102. package/dist/src/providers/transformation-receipt-integration.js +15 -271
  103. package/dist/src/providers/transformation-receipt-outputs.js +99 -0
  104. package/dist/src/providers/transformation-receipt-source.js +194 -0
  105. package/dist/src/research/identity.js +8 -2
  106. package/dist/src/research/reference-match.js +66 -8
  107. package/dist/src/rules/activation.mjs +15 -6
  108. package/dist/src/rules/core-startup.mjs +2 -2
  109. package/dist/src/serve/mission-conductor.js +4 -0
  110. package/dist/src/serve/mission-summary.js +56 -0
  111. package/dist/src/skills/deployment-ownership.js +2 -2
  112. package/dist/src/skills/deployment-policy.js +9 -0
  113. package/dist/src/smiths/context-pipeline/aiwg-md.js +23 -0
  114. package/dist/src/smiths/context-pipeline/context-file-safety.js +3 -0
  115. package/dist/src/smiths/context-pipeline/flue-context.js +25 -0
  116. package/dist/src/smiths/context-pipeline/generator.js +7 -2
  117. package/dist/src/smiths/context-pipeline/workspace-bootstrap.js +9 -7
  118. package/dist/src/smiths/hook-bridge/index.js +9 -0
  119. package/package.json +5 -1
  120. package/schemas/decision/D17StudyProtocol.v1.schema.json +39 -67
  121. package/tools/agents/deploy-agents.mjs +21 -680
  122. package/tools/agents/deploy-command-mirrors.mjs +229 -0
  123. package/tools/agents/deploy-options.mjs +267 -0
  124. package/tools/agents/deploy-support.mjs +165 -0
  125. package/tools/agents/providers/base-addon-discovery.mjs +139 -0
  126. package/tools/agents/providers/base-behaviors.mjs +168 -0
  127. package/tools/agents/providers/base-context.mjs +205 -0
  128. package/tools/agents/providers/base-contract.mjs +116 -0
  129. package/tools/agents/providers/base-files.mjs +252 -0
  130. package/tools/agents/providers/base-flat-artifacts.mjs +233 -0
  131. package/tools/agents/providers/base-framework-discovery.mjs +309 -0
  132. package/tools/agents/providers/base-frontmatter.mjs +196 -0
  133. package/tools/agents/providers/base-inventory.mjs +269 -0
  134. package/tools/agents/providers/base-kernel-skills.mjs +354 -0
  135. package/tools/agents/providers/base-migrations.mjs +258 -0
  136. package/tools/agents/providers/base-models-platforms.mjs +273 -0
  137. package/tools/agents/providers/base-rule-index.mjs +450 -0
  138. package/tools/agents/providers/base-runtime.mjs +60 -0
  139. package/tools/agents/providers/base-skill-copy.mjs +273 -0
  140. package/tools/agents/providers/base.mjs +16 -3364
  141. package/tools/agents/providers/claude-post-deploy.mjs +10 -2
  142. package/tools/agents/providers/flue-project.mjs +79 -0
  143. package/tools/agents/providers/flue-specialists.mjs +64 -0
  144. package/tools/agents/providers/flue.mjs +50 -0
  145. package/tools/agents/providers/hermes-startup.mjs +0 -5
  146. package/tools/agents/providers/muse.mjs +7 -2
  147. package/tools/agents/providers/rule-delivery-surface.mjs +33 -5
  148. package/tools/agents/providers/rule-deployment-commit.mjs +19 -15
  149. package/tools/agents/providers/rule-deployment-prepare.mjs +13 -3
  150. package/tools/agents/providers/rule-projection.mjs +3 -0
  151. package/tools/agents/providers/rule-startup.mjs +3 -3
  152. package/tools/agents/use-rule-selection.mjs +17 -0
  153. package/tools/ralph-external/lib/worker-invocation-processes.mjs +4 -2
  154. package/tools/ralph-external/lib/worker-termination.mjs +15 -8
  155. package/vscode-extension/schemas/aiwg.config.v1.json +2 -4
@@ -0,0 +1,229 @@
1
+ // Project command-shaped skills into provider command surfaces.
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import os from "node:os";
5
+ import { addManagedMarker, collectFrameworkArtifacts, contentHash, extractFrameworkSlug, getAddonSkillDirs, listSkillDirs, parseFrontmatter, updateSidecarManifest } from "./providers/base.mjs";
6
+
7
+ const MIRRORED_STANDARD_COMMAND_SKILLS = new Set([
8
+ 'aiwg-setup-project',
9
+ 'aiwg-update-claude',
10
+ 'aiwg-update-agents-md',
11
+ 'sdlc-accelerate',
12
+ 'project-status',
13
+ 'intake-wizard',
14
+ 'intake-from-codebase',
15
+ 'intake-start',
16
+ // Issue-workflow entry commands — invoked directly by users; mirror as
17
+ // commands so they reach .opencode/command/, .claude/commands/, etc. (#1549).
18
+ 'address-issues',
19
+ 'issue-audit',
20
+ ]);
21
+
22
+ const MIRRORED_KERNEL_COMMAND_SKILLS = new Set([
23
+ 'aiwg-refresh',
24
+ 'aiwg-doctor',
25
+ 'aiwg-status',
26
+ 'aiwg-help',
27
+ 'aiwg-regenerate',
28
+ 'aiwg-regenerate-claude',
29
+ 'aiwg-regenerate-codex',
30
+ 'aiwg-regenerate-opencode',
31
+ 'aiwg-regenerate-agents',
32
+ 'aiwg-issue',
33
+ 'aiwg-pr',
34
+ 'aiwg-mission',
35
+ 'use',
36
+ 'steward',
37
+ ]);
38
+
39
+
40
+ const DEFAULT_COMMAND_MIRROR_POLICY = { standard: MIRRORED_STANDARD_COMMAND_SKILLS, kernel: MIRRORED_KERNEL_COMMAND_SKILLS };
41
+
42
+ function providerUsesSkillsNatively(providerName) {
43
+ return ['antigravity', 'claude', 'cursor', 'deepseek-harness', 'hermes', 'openhuman', 'pi', 'omp'].includes(providerName);
44
+ }
45
+
46
+ function shouldMirrorStandardCommandSkill(skillName, policy) {
47
+ return (
48
+ skillName.startsWith('flow-') ||
49
+ policy.standard.has(skillName)
50
+ );
51
+ }
52
+
53
+ function shouldMirrorCommandSkill(providerName, skillName, policy) {
54
+ if (policy.kernel.has(skillName)) {
55
+ return !providerUsesSkillsNatively(providerName);
56
+ }
57
+
58
+ return shouldMirrorStandardCommandSkill(skillName, policy);
59
+ }
60
+
61
+ function uniquePaths(paths) {
62
+ return [...new Set(paths.filter(Boolean))];
63
+ }
64
+
65
+ export function collectMirrorSkillDirs(srcRoot, mode, providerName) {
66
+ const dirs = [];
67
+
68
+ const directSkillsDir = path.join(srcRoot, 'skills');
69
+ dirs.push(...listSkillDirs(directSkillsDir));
70
+
71
+ // If --source itself is a skills directory, support that shape too.
72
+ dirs.push(...listSkillDirs(srcRoot));
73
+
74
+ const repoFrameworksRoot = path.join(srcRoot, 'agentic', 'code', 'frameworks');
75
+ if (fs.existsSync(repoFrameworksRoot)) {
76
+ const artifacts = collectFrameworkArtifacts(srcRoot, mode, {
77
+ includeAgents: false,
78
+ includeCommands: false,
79
+ includeSkills: true,
80
+ includeRules: false,
81
+ });
82
+ dirs.push(...artifacts.skills);
83
+ // Pi's provider collector already deploys all eligible addon skills for
84
+ // every root framework mode. Mirror the command-shaped addon skills in
85
+ // that same root pass so `aiwg use` does not need to repeat the entire
86
+ // deployment once per addon merely to produce these wrappers. Keep addon
87
+ // skills after framework skills: this preserves the existing per-addon
88
+ // winner when a framework and addon expose the same command name.
89
+ if (mode === 'all'
90
+ || (providerName === 'pi' && ['general', 'sdlc', 'both'].includes(mode))) {
91
+ dirs.push(...getAddonSkillDirs(srcRoot));
92
+ }
93
+ }
94
+
95
+ return uniquePaths(dirs);
96
+ }
97
+
98
+ function resolveCommandMirrorDir(provider, target) {
99
+ const commandsPath = provider.paths?.commands;
100
+ if (commandsPath) {
101
+ return path.isAbsolute(commandsPath) ? commandsPath : path.join(target, commandsPath);
102
+ }
103
+
104
+ // Closest conventional location for providers whose primary command
105
+ // surface is MCP/aggregation rather than a documented command directory.
106
+ if (provider.name === 'hermes') {
107
+ // #2119: HERMES_HOME is the single source of truth the running Hermes
108
+ // runtime uses to locate its files — resolve the home the same way the
109
+ // provider does instead of hardcoding $HOME/.hermes.
110
+ const hermesHome = typeof provider.getHermesHome === 'function'
111
+ ? provider.getHermesHome()
112
+ : path.join(os.homedir(), '.hermes');
113
+ return path.resolve(hermesHome, 'commands');
114
+ }
115
+
116
+ return null;
117
+ }
118
+
119
+ function commandFileExtensionForProvider(provider) {
120
+ if (provider.name === 'copilot') return '.prompt.md';
121
+ return '.md';
122
+ }
123
+
124
+ function resolveSkillCommandPolicy(commandHint = {}) {
125
+ const legacy = String(commandHint.model || '').trim().toLowerCase();
126
+ const legacyRole = legacy === 'opus' ? 'reasoning'
127
+ : legacy === 'haiku' ? 'efficiency'
128
+ : legacy ? 'coding' : null;
129
+ const modelRole = commandHint.modelRole || legacyRole;
130
+ if (!modelRole) return null;
131
+ const modelTier = commandHint.modelTier
132
+ || (modelRole === 'reasoning' ? 'premium'
133
+ : modelRole === 'efficiency' ? 'economy' : 'standard');
134
+ return {
135
+ modelRole,
136
+ modelTier,
137
+ modelEffort: commandHint.modelEffort,
138
+ modelRationale: commandHint.modelRationale,
139
+ };
140
+ }
141
+
142
+ function parseSkillCommandHint(raw) {
143
+ const { frontmatter } = parseFrontmatter(raw);
144
+ const block = frontmatter?.match(/^commandHint:\s*\n((?:[ \t]+[^\n]*\n?)*)/m)?.[1] || '';
145
+ const hint = {};
146
+ for (const line of block.split('\n')) {
147
+ const match = line.trim().match(/^(model|modelRole|modelTier|modelEffort|modelRationale):\s*(.+)$/);
148
+ if (match) hint[match[1]] = match[2].trim().replace(/^['"]|['"]$/g, '');
149
+ }
150
+ return hint;
151
+ }
152
+
153
+ function skillToCommandContent(skillDir) {
154
+ const skillName = path.basename(skillDir);
155
+ const skillPath = path.join(skillDir, 'SKILL.md');
156
+ const raw = fs.readFileSync(skillPath, 'utf8');
157
+ const { metadata, body } = parseFrontmatter(raw);
158
+ const description = metadata.description || `Run AIWG skill ${skillName}`;
159
+ const policy = resolveSkillCommandPolicy(parseSkillCommandHint(raw));
160
+ const policyLines = policy ? [
161
+ `aiwg-model-role: ${policy.modelRole}`,
162
+ `aiwg-model-tier: ${policy.modelTier}`,
163
+ ...(policy.modelEffort ? [`aiwg-model-effort: ${policy.modelEffort}`] : []),
164
+ ...(policy.modelRationale ? [`aiwg-model-rationale: ${policy.modelRationale}`] : []),
165
+ ] : [];
166
+
167
+ return `---\nname: ${skillName}\ndescription: ${description}\n${policyLines.join('\n')}${policyLines.length ? '\n' : ''}---\n\n${body.trim()}\n`;
168
+ }
169
+
170
+ export function mirrorSkillsAsCommands(provider, target, srcRoot, opts) {
171
+ if (!opts.deployCommands && !opts.commandsOnly) return 0;
172
+ const policy = opts.commandMirrorPolicy ?? DEFAULT_COMMAND_MIRROR_POLICY;
173
+
174
+ const targetDir = resolveCommandMirrorDir(provider, target);
175
+ if (!targetDir) return 0;
176
+
177
+ const skillDirs = collectMirrorSkillDirs(srcRoot, opts.mode, provider.name)
178
+ .filter((dir) => shouldMirrorCommandSkill(provider.name, path.basename(dir), policy));
179
+
180
+ if (skillDirs.length === 0) return 0;
181
+ if (!opts.dryRun) fs.mkdirSync(targetDir, { recursive: true });
182
+
183
+ const ext = commandFileExtensionForProvider(provider);
184
+ const deployedEntries = [];
185
+ let count = 0;
186
+
187
+ for (const skillDir of skillDirs) {
188
+ const skillName = path.basename(skillDir);
189
+ let content = skillToCommandContent(skillDir);
190
+ if (typeof provider.transformCommand === 'function') {
191
+ content = provider.transformCommand(path.join(skillDir, `${skillName}.md`), content, opts);
192
+ }
193
+ // #2507: mirrored wrappers used to be written with no ownership signal, so
194
+ // AIWG could neither count them as deployed nor prune them when the source
195
+ // skill went away — a later run reported its own 46 wrappers as unmanaged
196
+ // artifacts the operator should delete. They carry the same managed marker
197
+ // and sidecar entry as any other deployed command now.
198
+ content = addManagedMarker(content, opts.deployVersion || 'unknown', opts.deploySource || 'bundled');
199
+
200
+ const filename = `${skillName}${ext}`;
201
+ const dest = path.join(targetDir, filename);
202
+ if (opts.dryRun) {
203
+ if (opts.verbose) console.log(`[dry-run] mirror skill command ${skillName} -> ${dest}`);
204
+ const raw = fs.readFileSync(path.join(skillDir, 'SKILL.md'), 'utf8');
205
+ const policy = resolveSkillCommandPolicy(parseSkillCommandHint(raw));
206
+ if (policy && opts.verbose) {
207
+ const outcome = provider.name === 'claude' ? 'native'
208
+ : provider.name === 'factory' ? 'informational' : 'unsupported';
209
+ console.log(`[dry-run] skill model policy ${skillName}: ${outcome} (${policy.modelRole}/${policy.modelTier})`);
210
+ }
211
+ } else {
212
+ fs.writeFileSync(dest, content, 'utf8');
213
+ }
214
+ const sourcePath = path.join(skillDir, 'SKILL.md');
215
+ deployedEntries.push({ filename, hash: contentHash(content), kind: 'skill-command', sourcePath,
216
+ frameworkSlug: extractFrameworkSlug(opts.logicalInputPath?.(sourcePath) || sourcePath) });
217
+ count++;
218
+ }
219
+
220
+ if (deployedEntries.length > 0) {
221
+ updateSidecarManifest(targetDir, deployedEntries, {
222
+ dryRun: opts.dryRun,
223
+ version: opts.deployVersion || 'unknown',
224
+ source: opts.deploySource || 'bundled',
225
+ });
226
+ }
227
+
228
+ return count;
229
+ }
@@ -0,0 +1,267 @@
1
+ // Parse deploy options and resolve provider modules.
2
+ import path from "node:path";
3
+ export function parseArgs(args = process.argv.slice(2)) {
4
+ const cfg = {
5
+ source: null,
6
+ userScope: false,
7
+ target: process.cwd(),
8
+ mode: 'all', // 'general', 'sdlc', 'marketing', 'media-curator', 'research', 'both' (legacy), or 'all'
9
+ dryRun: false,
10
+ force: false,
11
+ provider: 'claude',
12
+ model: null, // Blanket override for all tiers
13
+ modelTier: null, // Blanket canonical tier override
14
+ reasoningModel: null,
15
+ codingModel: null,
16
+ efficiencyModel: null,
17
+ asAgentsMd: false,
18
+ createAgentsMd: false,
19
+ contextFiles: true,
20
+ projectScope: false,
21
+ deployCommands: false,
22
+ deploySkills: false,
23
+ deployRules: false,
24
+ deployBehaviors: false, // Deploy behaviors (native on openclaw, emulated on others)
25
+ commandsOnly: false,
26
+ skillsOnly: false,
27
+ rulesOnly: false,
28
+ strict: false,
29
+ reportOnly: true,
30
+ kernelOnly: false,
31
+ deferRuleProjection: false,
32
+ ruleSelectionMode: null,
33
+ additionalSources: [],
34
+ filter: null, // Glob pattern for agent names
35
+ filterRole: null, // Filter by role: reasoning|coding|efficiency
36
+ save: false, // Save model config to project models.json
37
+ saveUser: false, // Save model config to ~/.config/aiwg/models.json
38
+ verbose: false, // Show per-file deployment details
39
+ quiet: false, // Suppress all non-error output (for embedding in use.ts)
40
+ asPlugin: false, // Generate .factory-plugin/ bundle (Factory provider only)
41
+ deployBehaviors: false, // Deploy behaviors in addition to agents
42
+ skipCommandsMigration: false, // Skip commands → skills migration (warns about duplicates)
43
+ warnOnSkippedCommandsMigration: true, // Emit the duplicate warning when the migration is skipped
44
+ // Managed-marker provenance (#2502). Deployers that are not shipping the
45
+ // bundled framework corpus (project-local bundles, in particular) must
46
+ // override these so `aiwg refresh` does not mistake their artifacts for
47
+ // stale copies of packaged ones.
48
+ deploySource: null, // Managed-marker source; defaults to 'bundled'
49
+ listingBudget: false, // Honor the provider startup-listing cap despite --copy-all (#2561)
50
+ deployVersion: null, // Managed-marker version; defaults to srcRoot package.json
51
+ mcp: false, // #228: opt-in MCP settings profile (Muse provider)
52
+ hooks: true, // #228: managed project hooks (Muse provider); --no-hooks opts out
53
+ };
54
+ for (let i = 0; i < args.length; i++) {
55
+ const a = args[i];
56
+ if (a === '--source' && args[i + 1]) cfg.source = path.resolve(args[++i]);
57
+ else if (a === '--additional-source') {
58
+ const source = args[++i];
59
+ if (!source || source.startsWith('--')) throw new Error('--additional-source requires a source directory');
60
+ cfg.additionalSources.push(path.resolve(source));
61
+ }
62
+ else if (a === '--target' && args[i + 1]) cfg.target = path.resolve(args[++i]);
63
+ else if (a === '--mode' && args[i + 1]) cfg.mode = String(args[++i]).toLowerCase();
64
+ // Internal use orchestration: selection survives source-specific passes.
65
+ else if (a === '--rule-selection-mode') {
66
+ const mode = args[++i];
67
+ if (!mode || mode.startsWith('--')) throw new Error('--rule-selection-mode requires a deployment mode');
68
+ cfg.ruleSelectionMode = mode.toLowerCase();
69
+ }
70
+ else if (a === '--scope') {
71
+ const scope = args[++i];
72
+ if (scope !== 'user' && scope !== 'project') {
73
+ throw new Error(`--scope expected 'user' or 'project', got '${scope ?? '(missing)'}'`);
74
+ }
75
+ cfg.userScope = scope === 'user';
76
+ cfg.projectScope = scope === 'project';
77
+ }
78
+ else if (a === '--user') cfg.userScope = true;
79
+ else if (a === '--dry-run') cfg.dryRun = true;
80
+ else if (a === '--force') cfg.force = true;
81
+ else if ((a === '--provider' || a === '--platform') && args[i + 1]) cfg.provider = String(args[++i]).toLowerCase();
82
+ else if (a === '--model' && args[i + 1]) cfg.model = args[++i];
83
+ else if (a === '--model-tier' && args[i + 1]) cfg.modelTier = String(args[++i]).toLowerCase();
84
+ else if ((a === '--reasoning-model' || a === '--reasoning') && args[i + 1]) cfg.reasoningModel = args[++i];
85
+ else if ((a === '--coding-model' || a === '--coding') && args[i + 1]) cfg.codingModel = args[++i];
86
+ else if ((a === '--efficiency-model' || a === '--efficiency') && args[i + 1]) cfg.efficiencyModel = args[++i];
87
+ else if (a === '--as-agents-md') cfg.asAgentsMd = true;
88
+ else if (a === '--create-agents-md') cfg.createAgentsMd = true;
89
+ else if (a === '--deploy-commands') cfg.deployCommands = true;
90
+ else if (a === '--deploy-skills') cfg.deploySkills = true;
91
+ else if (a === '--deploy-rules') cfg.deployRules = true;
92
+ else if (a === '--deploy-behaviors') cfg.deployBehaviors = true;
93
+ else if (a === '--commands-only') cfg.commandsOnly = true;
94
+ else if (a === '--skills-only') cfg.skillsOnly = true;
95
+ else if (a === '--rules-only') cfg.rulesOnly = true;
96
+ else if (a === '--strict') { cfg.strict = true; cfg.reportOnly = false; }
97
+ else if (a === '--allow-over-budget') cfg.allowOverBudget = true;
98
+ else if (a === '--report-only') cfg.reportOnly = true;
99
+ else if (a === '--kernel-only') cfg.kernelOnly = true;
100
+ // Internal use orchestration: the final source owns rule presentation.
101
+ else if (a === '--defer-rule-projection') cfg.deferRuleProjection = true;
102
+ else if (a === '--deploy-behaviors') cfg.deployBehaviors = true;
103
+ else if (a === '--filter' && args[i + 1]) cfg.filter = args[++i];
104
+ else if (a === '--filter-role' && args[i + 1]) cfg.filterRole = args[++i];
105
+ else if (a === '--save') cfg.save = true;
106
+ else if (a === '--save-user') cfg.saveUser = true;
107
+ else if (a === '--verbose' || a === '-v') cfg.verbose = true;
108
+ else if (a === '--quiet' || a === '-q') cfg.quiet = true;
109
+ else if (a === '--as-plugin') cfg.asPlugin = true;
110
+ else if (a === '--skip-commands-migration') cfg.skipCommandsMigration = true;
111
+ // Structural opt-out: skip the migration without claiming the operator declined it (#2541).
112
+ else if (a === '--no-commands-warning') cfg.warnOnSkippedCommandsMigration = false;
113
+ else if (a === '--copy-all' || a === '--copy-standard-skills') cfg.copyStandardSkills = true;
114
+ // #228: Muse provider — explicit opt-in MCP settings profile, and the
115
+ // managed-hooks opt-out (default on, mirroring the Claude autoInstall policy).
116
+ else if (a === '--mcp') cfg.mcp = true;
117
+ else if (a === '--no-hooks') cfg.hooks = false;
118
+ else if (a === '--no-attribution') cfg.attribution = false;
119
+ else if (a === '--no-context-files') cfg.contextFiles = false;
120
+ else if (a === '--deploy-source' && args[i + 1]) cfg.deploySource = String(args[++i]);
121
+ else if (a === '--listing-budget') cfg.listingBudget = true;
122
+ else if (a === '--deploy-version' && args[i + 1]) cfg.deployVersion = String(args[++i]);
123
+ else if (a === '--help' || a === '-h') {
124
+ cfg.help = true;
125
+ }
126
+ }
127
+ return cfg;
128
+ }
129
+
130
+ export function printHelp() {
131
+ console.log(`
132
+ Deploy Agents and Commands
133
+
134
+ Usage:
135
+ node tools/agents/deploy-agents.mjs [options]
136
+ aiwg -deploy-agents [options]
137
+
138
+ Options:
139
+ --source <path> Source directory (defaults to repo root)
140
+ --target <path> Target directory (defaults to cwd)
141
+ --scope <user|project> Deployment scope (default: project)
142
+ --user Shorthand for --scope user
143
+ --mode <type> Deployment mode: general, sdlc, marketing (alias: mmk), media-curator, research, both, or all (default)
144
+ --deploy-commands Deploy commands in addition to agents
145
+ --deploy-skills Deploy skills in addition to agents
146
+ --deploy-rules Deploy rules in addition to agents
147
+ --commands-only Deploy only commands (skip agents)
148
+ --skills-only Deploy only skills (skip agents)
149
+ --rules-only Deploy only rules (skip agents)
150
+ --kernel-only Deploy kernel skills and rules; prune managed bulk agents/commands
151
+ --dry-run Show what would be deployed without writing
152
+ --force Overwrite existing files
153
+ --provider <name> Target provider (see below)
154
+ --model <name> Override model for all tiers (blanket)
155
+ --reasoning-model <name> Override model for reasoning tasks (alias: --reasoning)
156
+ --coding-model <name> Override model for coding tasks (alias: --coding)
157
+ --efficiency-model <name> Override model for efficiency tasks (alias: --efficiency)
158
+ --model-tier <tier> Override all artifacts with economy|standard|premium
159
+ --filter <pattern> Only deploy agents matching pattern (glob)
160
+ --filter-role <role> Only deploy agents of role: reasoning|coding|efficiency
161
+ --save Save model config to project models.json
162
+ --save-user Save model config to ~/.config/aiwg/models.json
163
+ --mcp Muse provider: opt in to the AIWG MCP settings profile
164
+ (merges the aiwg stdio server into user settings
165
+ mcp_servers; default off)
166
+ --no-hooks Muse provider: skip managed project hooks
167
+ (.muse/hooks.json; installed by default)
168
+ --no-attribution Claude provider: leave attribution settings untouched
169
+ --as-agents-md Aggregate to single AGENTS.md (Codex)
170
+ --create-agents-md Create/update AGENTS.md template
171
+ --no-context-files Preserve WORKSPACE.md, AIWG.md and AGENTS.md (including managed blocks)
172
+ --skip-commands-migration Skip deleting the commands directory before skills deployment
173
+ --listing-budget Honor the provider startup-listing cap even with --copy-all
174
+ --deploy-source <name> Managed-marker source stamped into deployed artifacts.
175
+ Defaults to 'bundled'. Deploys that do not ship the packaged
176
+ framework corpus (e.g. project-local bundles) MUST override
177
+ this so refresh's stale-artifact prune skips them (#2502).
178
+ --deploy-version <version> Managed-marker version stamped into deployed artifacts.
179
+ Defaults to the --source tree's package.json version.
180
+ --copy-all Copy ALL skills per-project (legacy mirror at <provider>/.aiwg/skills/).
181
+ For aiwg use all, this also restores the legacy full agent,
182
+ command, and expanded-rule copy. Default bulk deployment is
183
+ kernel-only + index-driven discovery for the rest (#1217).
184
+ Use this for sandboxed runtimes / air-gapped corpora where
185
+ $AIWG_ROOT isn't readable from the agent's working dir.
186
+ Alias: --copy-standard-skills — rc.29 era).
187
+ (warns about duplicate entries in the provider command palette)
188
+
189
+ Model Override Examples:
190
+ # Use sonnet for everything
191
+ aiwg use sdlc --model sonnet
192
+
193
+ # Override individual tiers
194
+ aiwg use sdlc --reasoning opus --coding sonnet --efficiency haiku
195
+
196
+ # Use a specific model ID for coding tier
197
+ aiwg use sdlc --provider factory --coding-model gpt-5.6-terra
198
+
199
+ # Blanket with per-tier override (reasoning uses opus, others use sonnet)
200
+ aiwg use sdlc --model sonnet --reasoning opus
201
+
202
+ # Save overrides to project models.json for future deployments
203
+ aiwg use sdlc --model sonnet --save
204
+
205
+ Model Precedence:
206
+ CLI flags > project models.json > user ~/.config/aiwg/models.json > AIWG defaults
207
+
208
+ Shorthand Values:
209
+ opus, sonnet, haiku, inherit — resolved per provider to full model IDs
210
+
211
+ Providers (all deploy agents, commands, skills, and rules):
212
+ claude - Claude Code (default)
213
+ Paths: .claude/agents/, .claude/commands/, .claude/skills/, .claude/rules/
214
+ factory - Factory AI
215
+ Paths: .factory/droids/, .factory/commands/, .factory/skills/, .factory/rules/
216
+ codex - OpenAI Codex (alias: openai)
217
+ Paths: .codex/agents/, .codex/commands/, .codex/skills/, .codex/rules/
218
+ opencode - OpenCode
219
+ Paths: .opencode/skill/, .opencode/rule/ (agents/commands not file-based in OpenCode)
220
+ copilot - GitHub Copilot
221
+ Paths: .github/agents/, .github/commands/, .github/skills/, .github/copilot-rules/
222
+ cursor - Cursor IDE
223
+ Paths: .cursor/agents/, .cursor/commands/, .cursor/skills/, .cursor/rules/
224
+ warp - Warp Terminal
225
+ Paths: .warp/agents/, .warp/commands/, .warp/skills/, .warp/rules/ + WARP.md
226
+ flue - Flue (experimental app target; project scope only)
227
+ Paths: .agents/skills/, inline AGENTS.md, source-root db.ts, .gitignore
228
+ deepseek-harness - DeepSeek Harness (alias: dsh; experimental)
229
+ Paths: AGENTS.md, .agents/skills/, .dsh/aiwg.cordis.patch.yml
230
+ devin - Devin Desktop (preferred; aliases: devin-desktop, windsurf)
231
+ Paths: .windsurf/agents/, .windsurf/workflows/, .windsurf/skills/, .windsurf/rules/
232
+ grokbot - Grok Bot (AGENTS.md bridge; skills only with AIWG_GROKBOT_SKILLS_DIR)
233
+ grok-build - Grok Build (experimental; .grok paths + $GROK_HOME; no bare grok alias)
234
+ muse - Muse Code (stable; AGENTS.md bridge; .agents/skills + XDG user root; managed hooks, opt-in --mcp; no aliases)
235
+ hermes - Hermes Agent (MCP-based integration)
236
+ Skills: $HERMES_HOME/skills/ (user-global; defaults to ~/.hermes/skills/) | Agents: AGENTS.md
237
+ Commands/Rules: served via MCP, not file-deployed
238
+
239
+ Modes:
240
+ general - Writing-quality addon agents and commands (alias: writing)
241
+ sdlc - SDLC Complete framework agents and commands
242
+ marketing - Media/Marketing Kit framework agents and commands (alias: mmk)
243
+ media-curator - Media Curator framework agents and commands
244
+ research - Research Complete framework agents and commands
245
+ both - writing + SDLC (legacy compatibility)
246
+ all - All frameworks + addons (default)
247
+
248
+ Examples:
249
+ # Deploy SDLC framework to Claude Code
250
+ aiwg -deploy-agents --mode sdlc
251
+
252
+ # Deploy to Factory with commands and AGENTS.md
253
+ aiwg -deploy-agents --provider factory --mode sdlc --deploy-commands --create-agents-md
254
+
255
+ # Deploy to GitHub Copilot
256
+ aiwg -deploy-agents --provider copilot --mode sdlc
257
+
258
+ # Override model for all tiers
259
+ aiwg -deploy-agents --mode sdlc --model sonnet
260
+
261
+ # Override individual tiers
262
+ aiwg -deploy-agents --mode sdlc --reasoning opus --coding sonnet --efficiency haiku
263
+
264
+ # Dry run to preview deployment
265
+ aiwg -deploy-agents --provider cursor --mode sdlc --dry-run
266
+ `);
267
+ }
@@ -0,0 +1,165 @@
1
+ // Model persistence and interactive command migration support.
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import os from "node:os";
5
+ import readline from "node:readline";
6
+ export function resolveShorthand(value, shorthandMap, modelsConfig, provider, tier) {
7
+ if (!value) return null;
8
+
9
+ const clean = value.toLowerCase().replace(/['"]/g, '');
10
+
11
+ // Check shorthand map first
12
+ if (shorthandMap[clean]) return shorthandMap[clean];
13
+
14
+ // Check provider-specific tier config (e.g., modelsConfig.factory.reasoning.model)
15
+ const providerConfig = modelsConfig?.[provider];
16
+ if (providerConfig?.[tier]?.model && clean === tier) {
17
+ return providerConfig[tier].model;
18
+ }
19
+
20
+ // Not a shorthand — return as literal model ID
21
+ return value;
22
+ }
23
+
24
+ // ============================================================================
25
+ // Model Configuration Persistence
26
+ // ============================================================================
27
+
28
+ /**
29
+ * Save model configuration to project or user config file
30
+ * @param {object} cfg - Configuration with model overrides
31
+ * @param {string} providerName - Provider name for provider-specific config
32
+ */
33
+ export async function saveModelConfig(cfg, providerName) {
34
+ // Build config object with only the provided overrides
35
+ const modelConfig = {};
36
+ if (cfg.modelTier) {
37
+ modelConfig.defaults = { tier: cfg.modelTier };
38
+ }
39
+
40
+ // Provider-specific tier configuration
41
+ if (cfg.reasoningModel || cfg.codingModel || cfg.efficiencyModel) {
42
+ modelConfig[providerName] = {};
43
+ if (cfg.reasoningModel) {
44
+ modelConfig[providerName].reasoning = { model: cfg.reasoningModel };
45
+ }
46
+ if (cfg.codingModel) {
47
+ modelConfig[providerName].coding = { model: cfg.codingModel };
48
+ }
49
+ if (cfg.efficiencyModel) {
50
+ modelConfig[providerName].efficiency = { model: cfg.efficiencyModel };
51
+ }
52
+ }
53
+
54
+ // Shorthand mappings
55
+ if (cfg.reasoningModel || cfg.codingModel || cfg.efficiencyModel) {
56
+ modelConfig.shorthand = {};
57
+ if (cfg.reasoningModel) modelConfig.shorthand.opus = cfg.reasoningModel;
58
+ if (cfg.codingModel) modelConfig.shorthand.sonnet = cfg.codingModel;
59
+ if (cfg.efficiencyModel) modelConfig.shorthand.haiku = cfg.efficiencyModel;
60
+ }
61
+
62
+ // Determine target path
63
+ let targetPath;
64
+ if (cfg.saveUser) {
65
+ const configDir = path.join(os.homedir(), '.config', 'aiwg');
66
+ if (!fs.existsSync(configDir)) {
67
+ fs.mkdirSync(configDir, { recursive: true });
68
+ }
69
+ targetPath = path.join(configDir, 'models.json');
70
+ } else {
71
+ targetPath = path.join(cfg.target, 'models.json');
72
+ }
73
+
74
+ // Merge with existing config if it exists
75
+ let existingConfig = {};
76
+ if (fs.existsSync(targetPath)) {
77
+ try {
78
+ existingConfig = JSON.parse(fs.readFileSync(targetPath, 'utf8'));
79
+ } catch {
80
+ // Ignore parse errors, start fresh
81
+ }
82
+ }
83
+
84
+ // Deep merge: existing config + new overrides
85
+ const mergedConfig = deepMerge(existingConfig, modelConfig);
86
+
87
+ // Write the config
88
+ fs.writeFileSync(targetPath, JSON.stringify(mergedConfig, null, 2) + '\n', 'utf8');
89
+ console.log(`\nModel configuration saved to: ${targetPath}`);
90
+ }
91
+
92
+ /**
93
+ * Deep merge two objects
94
+ */
95
+ function deepMerge(target, source) {
96
+ const result = { ...target };
97
+ for (const key of Object.keys(source)) {
98
+ if (source[key] && typeof source[key] === 'object' && !Array.isArray(source[key])) {
99
+ result[key] = deepMerge(result[key] || {}, source[key]);
100
+ } else {
101
+ result[key] = source[key];
102
+ }
103
+ }
104
+ return result;
105
+ }
106
+
107
+ // ============================================================================
108
+ // Commands → Skills Migration
109
+ // ============================================================================
110
+
111
+ /**
112
+ * Ask the user whether to delete the provider's commands directory before
113
+ * deploying skills. Skipped automatically when not running in a TTY (CI/pipe)
114
+ * or when --quiet is set.
115
+ *
116
+ * @param {object} cfg - Parsed CLI config
117
+ * @param {object} provider - Loaded provider module
118
+ * @param {string} targetDir - Resolved target directory
119
+ * @returns {Promise<boolean>} true = proceed with migration, false = skip
120
+ */
121
+ export async function promptCommandsMigration(cfg, provider, targetDir, interactive = process.stdout.isTTY) {
122
+ // Home-directory providers share commands across projects — do not delete.
123
+ if (provider.capabilities?.homeDirectoryDeploy) return false;
124
+ // Some providers intentionally expose both surfaces with different runtime
125
+ // semantics. Pi prompt templates (/name) are not aliases for Agent Skills
126
+ // (/skill:name), so command-to-skill migration would destroy valid prompts.
127
+ if (provider.capabilities?.parallelCommandAndSkillSurfaces) return false;
128
+
129
+ const commandsRelPath = provider.paths?.commands;
130
+ if (!commandsRelPath) return false;
131
+
132
+ const commandsDir = path.join(targetDir, commandsRelPath);
133
+ if (!fs.existsSync(commandsDir)) return false;
134
+
135
+ const entries = fs.readdirSync(commandsDir).filter(e => e.endsWith('.md'));
136
+ if (entries.length === 0) return false;
137
+
138
+ // Non-interactive context: migrate silently.
139
+ if (cfg.quiet || !interactive) return true;
140
+
141
+ const rel = path.relative(process.cwd(), commandsDir);
142
+ console.log(`\n⚠ Commands → Skills Migration`);
143
+ console.log(` ${rel} contains ${entries.length} legacy command file(s).`);
144
+ console.log(` AIWG now serves these as skills (.claude/skills/).`);
145
+ console.log(` Keeping both causes duplicate entries in the Claude Code command palette.`);
146
+ console.log('');
147
+
148
+ const answer = await new Promise(resolve => {
149
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
150
+ rl.question(' Remove commands directory and migrate? [Y/n] ', ans => {
151
+ rl.close();
152
+ resolve(ans.trim().toLowerCase());
153
+ });
154
+ });
155
+
156
+ if (answer === 'n' || answer === 'no') {
157
+ console.log('');
158
+ console.log(' Skipping migration. Run `aiwg use` again without --skip-commands-migration');
159
+ console.log(` to clean up, or delete ${rel} manually.`);
160
+ console.log('');
161
+ return false;
162
+ }
163
+
164
+ return true;
165
+ }