@aiwg/cli 2026.10.12 → 2026.10.15

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 (104) hide show
  1. package/agentic/code/addons/aiwg-utils/rules/anti-laziness.core.md +13 -0
  2. package/agentic/code/addons/aiwg-utils/rules/anti-laziness.md +118 -0
  3. package/agentic/code/providers/pi/aiwg-bridge.ts +44 -1
  4. package/dist/src/artifacts/corpus-tools/cli.js +32 -0
  5. package/dist/src/artifacts/corpus-tools/discovery-log.js +1 -1
  6. package/dist/src/artifacts/corpus-tools/expand-cli.js +89 -0
  7. package/dist/src/artifacts/corpus-tools/expand-queue.js +38 -0
  8. package/dist/src/artifacts/corpus-tools/expand-state.js +40 -0
  9. package/dist/src/artifacts/corpus-tools/expand.js +125 -0
  10. package/dist/src/artifacts/corpus-tools/resolve-cli.js +91 -0
  11. package/dist/src/artifacts/corpus-tools/resolve-corpus.js +41 -0
  12. package/dist/src/artifacts/corpus-tools/resolve.js +105 -0
  13. package/dist/src/cli/handlers/doctor-args.js +40 -0
  14. package/dist/src/cli/handlers/doctor-help.js +4 -2
  15. package/dist/src/cli/handlers/use-bundle-counts.js +32 -6
  16. package/dist/src/cli/handlers/use-skill-assets.js +207 -0
  17. package/dist/src/cli/handlers/use.js +30 -193
  18. package/dist/src/cli/handlers/utilities.js +5 -31
  19. package/dist/src/config/authorization-cli.js +11 -3
  20. package/dist/src/config/worker-context.js +33 -4
  21. package/dist/src/decision/context-pruning-common.js +41 -0
  22. package/dist/src/decision/context-pruning-evaluation.js +366 -0
  23. package/dist/src/decision/context-pruning-pilot.js +431 -0
  24. package/dist/src/decision/context-pruning-types.js +19 -0
  25. package/dist/src/decision/context-pruning.js +5 -847
  26. package/dist/src/decision/ensemble/contract.js +4 -24
  27. package/dist/src/decision/heldout/collector.js +1 -1
  28. package/dist/src/decision/qualification/release.js +5 -62
  29. package/dist/src/extensions/manifest.js +8 -1
  30. package/dist/src/extensions/project-local-doctor.js +78 -2
  31. package/dist/src/extensions/validation.js +10 -11
  32. package/dist/src/features/catalog.js +1 -1
  33. package/dist/src/gates/evaluate.js +5 -15
  34. package/dist/src/gates/heldout.js +42 -0
  35. package/dist/src/gates/index.js +2 -1
  36. package/dist/src/gates/upstream-ceiling.js +111 -0
  37. package/dist/src/models/provider-models.js +5 -8
  38. package/dist/src/models/worker-installation-store.mjs +228 -0
  39. package/dist/src/models/worker-installation.mjs +7 -162
  40. package/dist/src/models/wrapper-definitions.js +14 -0
  41. package/dist/src/models/wrapper-deployment.js +48 -25
  42. package/dist/src/models/wrapper-enforcement.js +72 -0
  43. package/dist/src/policy/hitl-check.js +80 -0
  44. package/dist/src/providers/provider-definitions.js +10 -10
  45. package/dist/src/research/clients/arxiv.js +10 -4
  46. package/dist/src/research/clients/base.js +5 -4
  47. package/dist/src/research/clients/crossref.js +9 -1
  48. package/dist/src/research/clients/semantic-scholar.js +73 -44
  49. package/dist/src/research/identity.js +85 -0
  50. package/dist/src/research/index.js +1 -0
  51. package/dist/src/research/reference-match.js +89 -0
  52. package/dist/src/rules/activation.d.mts +2 -0
  53. package/dist/src/rules/activation.mjs +23 -0
  54. package/dist/src/rules/core-startup.d.mts +2 -0
  55. package/dist/src/rules/core-startup.mjs +31 -0
  56. package/dist/src/skills/adapters/local.js +32 -9
  57. package/dist/src/skills/agent-skills.js +2 -0
  58. package/dist/src/skills/cli-display.js +33 -0
  59. package/dist/src/skills/cli.js +2 -26
  60. package/dist/src/skills/collision-discovery.js +84 -0
  61. package/dist/src/skills/deployer.js +20 -75
  62. package/dist/src/skills/deployment-ownership.js +74 -0
  63. package/dist/src/skills/doctor.js +2 -2
  64. package/dist/src/skills/importer.js +4 -26
  65. package/dist/src/skills/registry.js +22 -7
  66. package/dist/src/smiths/context-pipeline/agents-md.js +34 -0
  67. package/dist/src/smiths/context-pipeline/aiwg-md.js +3 -0
  68. package/dist/src/smiths/context-pipeline/bridge-ownership.js +50 -0
  69. package/dist/src/smiths/context-pipeline/generator.js +40 -104
  70. package/dist/src/smiths/context-pipeline/managed-hook.js +10 -0
  71. package/dist/src/smiths/context-pipeline/parallelism-section.js +7 -3
  72. package/package.json +6 -2
  73. package/tools/agents/deploy-agents.mjs +2 -123
  74. package/tools/agents/providers/antigravity.mjs +4 -6
  75. package/tools/agents/providers/base.mjs +3 -3
  76. package/tools/agents/providers/claude.mjs +3 -5
  77. package/tools/agents/providers/codex.mjs +3 -5
  78. package/tools/agents/providers/context-write.mjs +12 -0
  79. package/tools/agents/providers/copilot.mjs +3 -5
  80. package/tools/agents/providers/cursor.mjs +3 -5
  81. package/tools/agents/providers/factory.mjs +3 -5
  82. package/tools/agents/providers/grok-build.mjs +17 -12
  83. package/tools/agents/providers/hermes-skill-lifecycle.mjs +144 -0
  84. package/tools/agents/providers/hermes-startup.mjs +209 -0
  85. package/tools/agents/providers/hermes.mjs +9 -359
  86. package/tools/agents/providers/model-wrapper.mjs +90 -0
  87. package/tools/agents/providers/muse.mjs +3 -3
  88. package/tools/agents/providers/omp.mjs +3 -1
  89. package/tools/agents/providers/openclaw.mjs +3 -5
  90. package/tools/agents/providers/opencode.mjs +3 -5
  91. package/tools/agents/providers/pi.mjs +1 -1
  92. package/tools/agents/providers/provider-paths-staging.mjs +9 -0
  93. package/tools/agents/providers/rule-delivery.mjs +26 -228
  94. package/tools/agents/providers/rule-presentation.mjs +13 -4
  95. package/tools/agents/providers/rule-projection.mjs +119 -0
  96. package/tools/agents/providers/rule-startup.mjs +70 -0
  97. package/tools/agents/providers/stale-artifact-prune.mjs +128 -0
  98. package/tools/agents/providers/warp.mjs +5 -7
  99. package/tools/agents/providers/windsurf.mjs +14 -62
  100. package/tools/plugin/package-plugins.mjs +2 -2
  101. package/tools/plugin/plugin-links.mjs +3 -0
  102. package/tools/skills/codex-skill-transform.mjs +232 -0
  103. package/tools/skills/deploy-skills-codex.mjs +8 -249
  104. package/tools/warp/warp-content.mjs +548 -0
@@ -0,0 +1,548 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Setup Warp - Intelligent WARP.md Merge Tool
4
+ *
5
+ * Mirrors the proven pattern from aiwg-setup-project and aiwg-update-claude.
6
+ * Aggregates all AIWG agents and commands into a single WARP.md file for Warp Terminal.
7
+ *
8
+ * Usage:
9
+ * node tools/warp/setup-warp.mjs [options]
10
+ *
11
+ * Options:
12
+ * --target <path> Target directory (default: cwd)
13
+ * --mode <type> Mode: general, sdlc, or both (default: both)
14
+ * --update Update mode (fail if no WARP.md exists)
15
+ * --dry-run Preview changes without writing
16
+ * --force Overwrite WARP.md (discard user content)
17
+ *
18
+ * Modes:
19
+ * general - Deploy only general-purpose agents and commands
20
+ * sdlc - Deploy only SDLC Complete framework agents and commands
21
+ * both - Deploy everything (default)
22
+ */
23
+
24
+ import { fileURLToPath } from 'node:url';
25
+ import fs from 'fs';
26
+ import path from 'path';
27
+ import { listOnDemandRuleFiles, renderOnDemandRuleSection } from '../agents/providers/base.mjs';
28
+
29
+ // AIWG-managed section headings (will be replaced on update)
30
+ const AIWG_MANAGED_SECTIONS = [
31
+ 'AIWG SDLC Framework',
32
+ 'AIWG SDLC Framework',
33
+ 'SDLC Agents',
34
+ 'SDLC Commands',
35
+ 'Platform Compatibility',
36
+ 'Core Orchestrator',
37
+ 'Core Platform Orchestrator',
38
+ 'Natural Language',
39
+ 'Natural Language Command Translation',
40
+ 'Phase Overview',
41
+ 'Quick Start',
42
+ 'Common Patterns',
43
+ 'Troubleshooting',
44
+ 'Resources'
45
+ ];
46
+
47
+ export function parseArgs() {
48
+ const args = process.argv.slice(2);
49
+ const cfg = {
50
+ target: process.cwd(),
51
+ mode: 'both',
52
+ update: false,
53
+ dryRun: false,
54
+ force: false,
55
+ strict: false,
56
+ reportOnly: true
57
+ };
58
+ for (let i = 0; i < args.length; i++) {
59
+ const a = args[i];
60
+ if (a === '--target' && args[i + 1]) cfg.target = path.resolve(args[++i]);
61
+ else if (a === '--mode' && args[i + 1]) cfg.mode = String(args[++i]).toLowerCase();
62
+ else if (a === '--update') cfg.update = true;
63
+ else if (a === '--dry-run') cfg.dryRun = true;
64
+ else if (a === '--force') cfg.force = true;
65
+ else if (a === '--strict') cfg.strict = true;
66
+ else if (a === '--report-only') cfg.reportOnly = true;
67
+ }
68
+ return cfg;
69
+ }
70
+
71
+ /**
72
+ * Resolve AIWG installation path
73
+ * Priority: $AIWG_ROOT -> ~/.local/share/ai-writing-guide -> /usr/local/share/ai-writing-guide
74
+ */
75
+ export function resolveAIWGRoot() {
76
+ const candidates = [
77
+ process.env.AIWG_ROOT,
78
+ path.join(process.env.HOME || '', '.local', 'share', 'ai-writing-guide'),
79
+ '/usr/local/share/ai-writing-guide',
80
+ // Development fallback (repo root)
81
+ path.resolve(path.dirname(new URL(import.meta.url).pathname), '..', '..')
82
+ ];
83
+
84
+ for (const candidate of candidates) {
85
+ if (!candidate) continue;
86
+ const testPath = path.join(candidate, 'agentic', 'code', 'frameworks', 'sdlc-complete');
87
+ if (fs.existsSync(testPath)) {
88
+ return candidate;
89
+ }
90
+ }
91
+
92
+ throw new Error(
93
+ 'AIWG installation not found. Please install AIWG first:\n' +
94
+ ' curl -fsSL https://raw.githubusercontent.com/jmagly/ai-writing-guide/refs/heads/main/tools/install/install.sh | bash\n\n' +
95
+ 'Or set AIWG_ROOT environment variable if installed elsewhere.'
96
+ );
97
+ }
98
+
99
+ /**
100
+ * Parse markdown into sections based on ## headings
101
+ */
102
+ function parseMarkdownSections(content) {
103
+ const lines = content.split('\n');
104
+ const sections = [];
105
+ let currentSection = null;
106
+
107
+ for (let i = 0; i < lines.length; i++) {
108
+ const line = lines[i];
109
+ const match = line.match(/^##\s+(.+)$/);
110
+
111
+ if (match) {
112
+ // New section found
113
+ if (currentSection) {
114
+ sections.push(currentSection);
115
+ }
116
+ currentSection = {
117
+ heading: match[1].trim(),
118
+ startLine: i,
119
+ lines: [line]
120
+ };
121
+ } else if (currentSection) {
122
+ currentSection.lines.push(line);
123
+ } else {
124
+ // Before first ## heading (document header)
125
+ if (sections.length === 0) {
126
+ sections.push({
127
+ heading: '__HEADER__',
128
+ startLine: 0,
129
+ lines: [line]
130
+ });
131
+ } else {
132
+ sections[sections.length - 1].lines.push(line);
133
+ }
134
+ }
135
+ }
136
+
137
+ if (currentSection) {
138
+ sections.push(currentSection);
139
+ }
140
+
141
+ return sections;
142
+ }
143
+
144
+ /**
145
+ * Check if a section heading is AIWG-managed (will be replaced)
146
+ */
147
+ function isAIWGManagedSection(heading) {
148
+ if (heading === '__HEADER__') return false;
149
+ return AIWG_MANAGED_SECTIONS.some(managed =>
150
+ heading.toLowerCase().includes(managed.toLowerCase())
151
+ );
152
+ }
153
+
154
+ /**
155
+ * List markdown files in a directory (non-recursive)
156
+ */
157
+ function listMdFiles(dir) {
158
+ if (!fs.existsSync(dir)) return [];
159
+ const defaultExcluded = ['README.md', 'manifest.md', 'agent-template.md', 'openai-compat.md', 'DEVELOPMENT_GUIDE.md'];
160
+ return fs
161
+ .readdirSync(dir, { withFileTypes: true })
162
+ .filter((e) => e.isFile() && e.name.toLowerCase().endsWith('.md') && !defaultExcluded.includes(e.name))
163
+ .map((e) => path.join(dir, e.name));
164
+ }
165
+
166
+ /**
167
+ * Transform agent markdown file to WARP.md section format
168
+ */
169
+ function transformAgentToSection(agentPath, opts = {}) {
170
+ const content = fs.readFileSync(agentPath, 'utf8');
171
+ if (opts.ruleDelivery?.bindings.has(path.resolve(agentPath))) return `### ${path.basename(agentPath, '.md')}\n\nRead and follow .warp/agents/${path.basename(agentPath)} before invocation.\n`;
172
+ const name = path.basename(agentPath, '.md');
173
+
174
+ // Extract frontmatter and body
175
+ const fmMatch = content.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
176
+ if (!fmMatch) return null;
177
+
178
+ const [, frontmatter, body] = fmMatch;
179
+
180
+ // Parse frontmatter
181
+ const fm = {};
182
+ frontmatter.split('\n').forEach(line => {
183
+ const match = line.match(/^(\w[\w-]*)\s*:\s*(.+)$/);
184
+ if (match) {
185
+ fm[match[1]] = match[2].trim();
186
+ }
187
+ });
188
+
189
+ // Extract description and tools
190
+ const description = fm.description || '';
191
+ const tools = fm['allowed-tools'] || '';
192
+
193
+ // Format as WARP.md section
194
+ let section = `### ${name.split('-').map(w => w.charAt(0).toUpperCase() + w.slice(1)).join(' ')}\n\n`;
195
+ if (tools) {
196
+ section += `**Tools**: ${tools}\n\n`;
197
+ }
198
+ if (description) {
199
+ section += `**Purpose**: ${description}\n\n`;
200
+ }
201
+
202
+ // Add body content (strip excessive blank lines)
203
+ const cleanBody = body.trim().replace(/\n{3,}/g, '\n\n');
204
+ if (cleanBody) {
205
+ section += cleanBody + '\n';
206
+ }
207
+
208
+ return section;
209
+ }
210
+
211
+ /**
212
+ * Transform command markdown file to WARP.md section format
213
+ */
214
+ function transformCommandToSection(commandPath, opts = {}) {
215
+ const content = fs.readFileSync(commandPath, 'utf8');
216
+ if (opts.ruleDelivery?.bindings.has(path.resolve(commandPath))) return `### ${path.basename(commandPath, '.md')}\n\nRead and follow .warp/commands/${path.basename(commandPath)} before invocation.\n`;
217
+ const name = path.basename(commandPath, '.md');
218
+
219
+ // Extract frontmatter and body
220
+ const fmMatch = content.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
221
+ if (!fmMatch) return null;
222
+
223
+ const [, frontmatter, body] = fmMatch;
224
+
225
+ // Parse frontmatter
226
+ const fm = {};
227
+ frontmatter.split('\n').forEach(line => {
228
+ const match = line.match(/^(\w[\w-]*)\s*:\s*(.+)$/);
229
+ if (match) {
230
+ fm[match[1]] = match[2].trim();
231
+ }
232
+ });
233
+
234
+ // Extract description
235
+ const description = fm.description || '';
236
+
237
+ // Format as WARP.md section
238
+ let section = `### /${name}\n\n`;
239
+ if (description) {
240
+ section += `**Purpose**: ${description}\n\n`;
241
+ }
242
+
243
+ // Add usage/parameters section if present in body
244
+ const cleanBody = body.trim().replace(/\n{3,}/g, '\n\n');
245
+ if (cleanBody) {
246
+ // Extract first paragraph or two for context
247
+ const paragraphs = cleanBody.split('\n\n');
248
+ const preview = paragraphs.slice(0, 2).join('\n\n');
249
+ section += preview + '\n';
250
+ }
251
+
252
+ return section;
253
+ }
254
+
255
+ /**
256
+ * Transform rule markdown file to WARP.md section format.
257
+ * Rule content is inlined verbatim under an H3 heading (the rule name in
258
+ * Title Case), so Warp agents see the full rule body in their context.
259
+ * Per #1346 — closes cross-provider parity gap on the skill-discovery
260
+ * rule and other aiwg-utils rules that Warp's "rules via WARP.md only"
261
+ * convention previously left unwired.
262
+ */
263
+ function transformRuleToSection(rulePath) {
264
+ const content = fs.readFileSync(rulePath, 'utf8');
265
+ const name = path.basename(rulePath, '.md');
266
+
267
+ // Strip frontmatter if present; the agent doesn't need the YAML.
268
+ const fmMatch = content.match(/^---\n[\s\S]*?\n---\n([\s\S]*)$/);
269
+ const body = (fmMatch ? fmMatch[1] : content).trim();
270
+
271
+ // Rules typically start with their own H1 (# Rule Name) — we want H3 in
272
+ // WARP.md so the rule slots under "## AIWG Rules". Strip a leading H1
273
+ // and rely on the section heading below; downshift surviving H2/H3.
274
+ const downshifted = body
275
+ .replace(/^# .+\n+/, '') // drop leading H1
276
+ .replace(/^## /gm, '#### ')
277
+ .replace(/^### /gm, '##### ');
278
+
279
+ const title = name.split('-').map(w => w.charAt(0).toUpperCase() + w.slice(1)).join(' ');
280
+ return `### ${title}\n\n${downshifted}\n`;
281
+ }
282
+
283
+ /**
284
+ * Collect aiwg-utils rule file paths for inlining into WARP.md.
285
+ * Focused on cross-provider parity rules: discover-first is the linchpin
286
+ * (#1343, #1346); other aiwg-utils rules are included to match the
287
+ * intent of "rules via WARP.md" stated in tools/agents/providers/warp.mjs.
288
+ * Per the activity-log rule and feedback_parity_no_removal: always-deploy.
289
+ */
290
+ function collectAiwgRulePaths(aiwgRoot) {
291
+ const utilsRules = path.join(aiwgRoot, 'agentic', 'code', 'addons', 'aiwg-utils', 'rules');
292
+ if (!fs.existsSync(utilsRules)) return [];
293
+ return listMdFiles(utilsRules)
294
+ // RULES-INDEX.md is a navigation aid for filesystem deployments; for
295
+ // Warp's inlined aggregation the full rule bodies are inlined directly,
296
+ // so the index would be duplicate content. Skip it.
297
+ .filter(p => !path.basename(p).startsWith('RULES-INDEX'));
298
+ }
299
+
300
+ /**
301
+ * Generate AIWG content section (aggregate agents, commands, and rules)
302
+ */
303
+ export function generateAIWGContent(aiwgRoot, mode, opts = {}) {
304
+ let content = '';
305
+
306
+ // Add marker comments
307
+ content += '<!-- AIWG SDLC Framework (auto-updated) -->\n';
308
+ content += '<!-- Managed by aiwg use -->\n\n';
309
+ content += '---\n\n';
310
+
311
+ // Add framework overview
312
+ content += '## AIWG SDLC Framework\n\n';
313
+ content += `**AIWG Installation**: ${aiwgRoot}\n\n`;
314
+ content += 'This project uses the **AIWG SDLC framework** for software development lifecycle management.\n\n';
315
+ content += '### What is AIWG?\n\n';
316
+ content += 'AIWG provides:\n\n';
317
+ content += '- **58+ specialized agents** covering all lifecycle phases (Inception → Elaboration → Construction → Transition → Production)\n';
318
+ content += '- **42+ commands** for project management, security, testing, deployment, and traceability\n';
319
+ content += '- **100+ templates** for requirements, architecture, testing, security, deployment artifacts\n';
320
+ content += '- **Phase-based workflows** with gate criteria and milestone tracking\n';
321
+ content += '- **Multi-agent orchestration** patterns for collaborative artifact generation\n\n';
322
+
323
+ // Aggregate agents
324
+ content += '---\n\n';
325
+ content += '## SDLC Agents (Specialized Roles)\n\n';
326
+
327
+ const agentPaths = [];
328
+ if (mode === 'general' || mode === 'both') {
329
+ const generalAgents = path.join(aiwgRoot, 'agents');
330
+ if (fs.existsSync(generalAgents)) {
331
+ agentPaths.push(...listMdFiles(generalAgents));
332
+ }
333
+ }
334
+
335
+ // Addon agents (dynamically discovered)
336
+ const addonsRoot = path.join(aiwgRoot, 'agentic', 'code', 'addons');
337
+ if (fs.existsSync(addonsRoot)) {
338
+ const addonDirs = fs.readdirSync(addonsRoot, { withFileTypes: true })
339
+ .filter(e => e.isDirectory())
340
+ .map(e => path.join(addonsRoot, e.name, 'agents'));
341
+
342
+ for (const addonAgentsDir of addonDirs) {
343
+ if (fs.existsSync(addonAgentsDir)) {
344
+ agentPaths.push(...listMdFiles(addonAgentsDir));
345
+ }
346
+ }
347
+ }
348
+
349
+ if (mode === 'sdlc' || mode === 'both') {
350
+ const sdlcAgents = path.join(aiwgRoot, 'agentic', 'code', 'frameworks', 'sdlc-complete', 'agents');
351
+ if (fs.existsSync(sdlcAgents)) {
352
+ agentPaths.push(...listMdFiles(sdlcAgents));
353
+ }
354
+ }
355
+
356
+ for (const agentPath of agentPaths) {
357
+ const section = transformAgentToSection(agentPath, opts);
358
+ if (section) {
359
+ content += section + '\n';
360
+ }
361
+ }
362
+
363
+ // Aggregate commands
364
+ content += '---\n\n';
365
+ content += '## SDLC Commands (Workflows)\n\n';
366
+
367
+ const commandPaths = [];
368
+ if (mode === 'general' || mode === 'both') {
369
+ const generalCommands = path.join(aiwgRoot, 'commands');
370
+ if (fs.existsSync(generalCommands)) {
371
+ commandPaths.push(...listMdFiles(generalCommands));
372
+ }
373
+ }
374
+
375
+ // Addon commands (dynamically discovered)
376
+ if (fs.existsSync(addonsRoot)) {
377
+ const addonCommandDirs = fs.readdirSync(addonsRoot, { withFileTypes: true })
378
+ .filter(e => e.isDirectory())
379
+ .map(e => path.join(addonsRoot, e.name, 'commands'));
380
+
381
+ for (const addonCommandsDir of addonCommandDirs) {
382
+ if (fs.existsSync(addonCommandsDir)) {
383
+ commandPaths.push(...listMdFiles(addonCommandsDir));
384
+ }
385
+ }
386
+ }
387
+
388
+ if (mode === 'sdlc' || mode === 'both') {
389
+ const sdlcCommands = path.join(aiwgRoot, 'agentic', 'code', 'frameworks', 'sdlc-complete', 'commands');
390
+ if (fs.existsSync(sdlcCommands)) {
391
+ commandPaths.push(...listMdFiles(sdlcCommands));
392
+ }
393
+ }
394
+
395
+ for (const commandPath of commandPaths) {
396
+ const section = transformCommandToSection(commandPath, opts);
397
+ if (section) {
398
+ content += section + '\n';
399
+ }
400
+ }
401
+
402
+ // Aggregate cross-provider rules into WARP.md (#1346 — Warp parity fix).
403
+ // Warp's only rule-delivery channel is WARP.md (no .warp/rules/ scan),
404
+ // so the aiwg-utils rules — including the load-bearing skill-discovery
405
+ // protocol — must be inlined here to reach Warp agents.
406
+ const rulePaths = collectAiwgRulePaths(aiwgRoot).filter(file => {
407
+ const rule = opts.ruleDelivery?.rules.find(rule => rule.file === file);
408
+ return rule ? !rule.tagged : true;
409
+ });
410
+ if (rulePaths.length > 0) {
411
+ content += '---\n\n';
412
+ content += '## AIWG Rules\n\n';
413
+ content += 'These rules govern agent behavior across all AIWG-supported providers. Warp delivers them via this aggregated section because Warp does not natively scan `.warp/rules/`. The full source for each rule lives at `$AIWG_ROOT/agentic/code/addons/aiwg-utils/rules/<rule-name>.md`.\n\n';
414
+ // Place skill-discovery first — it is the load-bearing rule the parity
415
+ // fix exists to surface (per #1343/#1346). Agents that read top-down
416
+ // hit the discover-first protocol immediately.
417
+ const sorted = [...rulePaths].sort((a, b) => {
418
+ const ax = path.basename(a, '.md');
419
+ const bx = path.basename(b, '.md');
420
+ if (ax === 'skill-discovery') return -1;
421
+ if (bx === 'skill-discovery') return 1;
422
+ return ax.localeCompare(bx);
423
+ });
424
+ for (const rulePath of sorted) {
425
+ const section = transformRuleToSection(rulePath);
426
+ if (section) {
427
+ content += section + '\n';
428
+ }
429
+ }
430
+ }
431
+
432
+ // On-demand tier (#1675): the MEDIUM/LOW rules NOT inlined above. Warp has no
433
+ // scanned `.warp/rules/` dir, so the bridge notes the tier with fetch hints.
434
+ // Exclude anything already inlined verbatim in the AIWG Rules section.
435
+ const inlinedRuleNames = rulePaths.map((p) => path.basename(p, '.md'));
436
+ const onDemandSection = renderOnDemandRuleSection(
437
+ listOnDemandRuleFiles(aiwgRoot),
438
+ { exclude: inlinedRuleNames },
439
+ );
440
+ if (onDemandSection) {
441
+ content += '---\n\n';
442
+ content += onDemandSection + '\n\n';
443
+ }
444
+
445
+ // Add natural language section
446
+ content += '---\n\n';
447
+ content += '## Natural Language Command Translation\n\n';
448
+ content += 'You can use natural language to trigger SDLC workflows. Examples:\n\n';
449
+ content += '**Phase Transitions**:\n';
450
+ content += '- "Let\'s transition to Elaboration"\n';
451
+ content += '- "Move to Construction"\n';
452
+ content += '- "Ready to deploy"\n\n';
453
+ content += '**Review Cycles**:\n';
454
+ content += '- "Run security review"\n';
455
+ content += '- "Execute test suite"\n';
456
+ content += '- "Check compliance"\n\n';
457
+ content += '**Artifact Generation**:\n';
458
+ content += '- "Create architecture baseline"\n';
459
+ content += '- "Generate SAD"\n';
460
+ content += '- "Build test plan"\n\n';
461
+ content += '**Status Checks**:\n';
462
+ content += '- "Where are we?"\n';
463
+ content += '- "Can we transition?"\n';
464
+ content += '- "Check project health"\n\n';
465
+
466
+ // Add resources
467
+ content += '---\n\n';
468
+ content += '## Resources\n\n';
469
+ content += `- **AIWG Framework**: ${aiwgRoot}/agentic/code/frameworks/sdlc-complete/README.md\n`;
470
+ content += `- **Template Library**: ${aiwgRoot}/agentic/code/frameworks/sdlc-complete/templates/\n`;
471
+ content += `- **Agent Catalog**: ${aiwgRoot}/agentic/code/frameworks/sdlc-complete/agents/\n`;
472
+ content += `- **Natural Language Guide**: ${aiwgRoot}/agentic/code/frameworks/sdlc-complete/docs/simple-language-translations.md\n`;
473
+ content += '- **Warp Documentation**: https://docs.warp.dev/knowledge-and-collaboration/rules\n\n';
474
+
475
+ return content;
476
+ }
477
+
478
+ /**
479
+ * Merge WARP.md intelligently (preserve user content, replace AIWG sections)
480
+ */
481
+ export function mergeWarpMd(existingContent, aiwgContent, force) {
482
+ const start = '<!-- AIWG:warp-context:start -->';
483
+ const end = '<!-- AIWG:warp-context:end -->';
484
+ const managed = `${start}\n${aiwgContent}\n${end}`;
485
+ const clean = (existingContent || '').replace(/\n?<!-- AIWG:rule-startup:start -->[\s\S]*?<!-- AIWG:rule-startup:end -->\n?/g, '');
486
+ if (clean.includes(start)) return clean.replace(/<!-- AIWG:warp-context:start -->[\s\S]*?<!-- AIWG:warp-context:end -->/, managed);
487
+ if (!clean || force) return `# Project Context\n\n${managed}\n`;
488
+ const sections = parseMarkdownSections(clean);
489
+ const user = sections.filter(section => !isAIWGManagedSection(section.heading)).map(section => section.lines.join('\n')).join('\n');
490
+ return `${user.trim()}\n\n${managed}\n`;
491
+ }
492
+
493
+ /**
494
+ * Create backup of existing WARP.md
495
+ */
496
+ function createBackup(warpMdPath) {
497
+ if (!fs.existsSync(warpMdPath)) return null;
498
+
499
+ const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
500
+ const backupPath = `${warpMdPath}.backup-${timestamp}`;
501
+ fs.copyFileSync(warpMdPath, backupPath);
502
+ return backupPath;
503
+ }
504
+
505
+ /**
506
+ * Validate WARP.md structure
507
+ */
508
+ function validateWarpMd(warpMdPath) {
509
+ if (!fs.existsSync(warpMdPath)) {
510
+ return {
511
+ valid: false,
512
+ errors: ['WARP.md not found']
513
+ };
514
+ }
515
+
516
+ const content = fs.readFileSync(warpMdPath, 'utf8');
517
+ const errors = [];
518
+ const warnings = [];
519
+
520
+ // Check for AIWG section
521
+ if (!content.includes('## AIWG')) {
522
+ errors.push('Missing AIWG section');
523
+ }
524
+
525
+ // Check for agents
526
+ const agentCount = (content.match(/^### /gm) || []).length;
527
+ if (agentCount < 10) {
528
+ warnings.push(`Only ${agentCount} agents found (expected 58+)`);
529
+ }
530
+
531
+ // Check for commands
532
+ const commandCount = (content.match(/^### \//gm) || []).length;
533
+ if (commandCount < 10) {
534
+ warnings.push(`Only ${commandCount} commands found (expected 42+)`);
535
+ }
536
+
537
+ return {
538
+ valid: errors.length === 0,
539
+ errors,
540
+ warnings,
541
+ agentCount,
542
+ commandCount
543
+ };
544
+ }
545
+
546
+ /**
547
+ * Main execution
548
+ */