@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
@@ -85,8 +85,6 @@ import {
85
85
  addManagedMarker,
86
86
  collectBehaviorDirs,
87
87
  collectFrameworkArtifacts,
88
- computeAllArtifactBasenames,
89
- computeAllSkillNames,
90
88
  contentHash,
91
89
  deployEmulatedBehaviors,
92
90
  getAddonSkillDirs,
@@ -95,7 +93,6 @@ import {
95
93
  loadRuntimeModelCatalog,
96
94
  migrateCommandsDirectory,
97
95
  parseFrontmatter,
98
- pruneStaleAiwgFiles,
99
96
  resolveAiwgRoot,
100
97
  updateSidecarManifest,
101
98
  } from './providers/base.mjs';
@@ -345,126 +342,8 @@ function mirrorSkillsAsCommands(provider, target, srcRoot, opts) {
345
342
  }
346
343
 
347
344
 
348
- // ============================================================================
349
- // Stale-Artifact Prune (agents / commands / rules) — #1627
350
- // ============================================================================
351
-
352
- /**
353
- * After a deploy, prune AIWG-managed flat artifacts (agents/commands/rules)
354
- * whose source no longer ships them — mirroring the skills holistic prune.
355
- *
356
- * Safety boundaries:
357
- * - Runs ONLY for AIWG framework/addon deploys (default source = AIWG root,
358
- * or `--source` under `<aiwgRoot>/agentic/code`). Project-local bundle
359
- * deploys (`--source <bundle>`) are skipped so a bundle's just-deployed
360
- * artifacts are never mistaken for stale framework files.
361
- * - `pruneStaleAiwgFiles` itself only removes files carrying an AIWG
362
- * ownership signal (sidecar entry or `aiwg:managed` marker) AND whose
363
- * stem is absent from the global, mode-independent source set, so
364
- * user-authored files and sibling-framework artifacts always survive.
365
- * - Aggregate-file paths (e.g. `AGENTS.md`) and unset paths are skipped.
366
- *
367
- * @param {object} provider loaded provider module
368
- * @param {string} target deploy target dir
369
- * @param {string} srcRoot effective deploy source
370
- * @param {object} opts deploy opts (dryRun/verbose/quiet + deploy flags)
371
- * @param {string|null} explicitSource the raw `--source` value (null when unset)
372
- */
373
- /** Bundles whose deploy is itself the kernel-only bulk install. */
374
- const BULK_INSTALL_BUNDLES = new Set(['all']);
375
-
376
- /**
377
- * True when the kernel-only bulk install is the only thing this project has
378
- * deployed, so clearing leftover flat artifacts is a migration and not a
379
- * deletion of another bundle's surface (#2508).
380
- *
381
- * A project with no readable `.aiwg/aiwg.config` has no recorded owner, so the
382
- * pre-#152 migration cleanup still applies.
383
- */
384
- export function bulkInstallOwnsFlatArtifacts(target) {
385
- let installed;
386
- try {
387
- const raw = realFs.readFileSync(path.join(target, '.aiwg', 'aiwg.config'), 'utf8');
388
- installed = JSON.parse(raw)?.installed;
389
- } catch {
390
- return true;
391
- }
392
- if (!installed || typeof installed !== 'object') return true;
393
- return !Object.keys(installed).some(name => !BULK_INSTALL_BUNDLES.has(name));
394
- }
395
-
396
- function pruneStaleAiwgArtifacts(provider, target, srcRoot, opts, explicitSource) {
397
- if (opts.skillsOnly && !opts.kernelOnly) return; // skills run their own prune in the provider
398
-
399
- const aiwgRoot = resolveAiwgRoot(srcRoot);
400
- if (!aiwgRoot) return; // no AIWG tree → bundle/standalone deploy; never prune
401
-
402
- // Gate: only framework/addon deploys are eligible. A default deploy (no
403
- // --source) sources from the AIWG root. An explicit --source is eligible
404
- // only when it lives under <aiwgRoot>/agentic/code (bundled fw/addon).
405
- if (explicitSource) {
406
- const codeRoot = path.join(aiwgRoot, 'agentic', 'code');
407
- const rel = path.relative(codeRoot, path.resolve(explicitSource));
408
- const underCode = !!rel && !rel.startsWith('..') && !path.isAbsolute(rel);
409
- if (!underCode) return; // project-local bundle / external source → skip
410
- }
411
-
412
- if (opts.kernelOnly) {
413
- // Kernel-only delivers skills and rules. The empty desired set below
414
- // applies only to bulk agents/commands left by
415
- // the pre-#152 bulk default, when the bulk install is the only thing this
416
- // project ever deployed.
417
- //
418
- // #2508: applying it unconditionally deleted every artifact a sibling
419
- // bundle owned — `aiwg use sdlc` followed by `aiwg use all` took
420
- // .claude/agents from 139 to 0. When another bundle is installed, it owns
421
- // this surface deliberately and the migration assumption does not hold.
422
- if (!bulkInstallOwnsFlatArtifacts(target)) {
423
- if (opts.verbose) {
424
- console.log('skip kernel-only flat prune: another installed bundle owns agents/commands/rules');
425
- }
426
- return;
427
- }
428
- for (const type of ['agents', 'commands']) {
429
- const relPath = provider.paths?.[type];
430
- if (!relPath || relPath.endsWith('.md')) continue;
431
- const destDir = path.isAbsolute(relPath) ? relPath : path.join(target, relPath);
432
- pruneStaleAiwgFiles(destDir, new Set(), {
433
- dryRun: opts.dryRun,
434
- verbose: opts.verbose,
435
- artifactExtensions: ['.md', '.mdc', '.toml'],
436
- });
437
- }
438
- return;
439
- }
440
-
441
- const typesThisRun = [];
442
- if (!opts.commandsOnly && !opts.rulesOnly) typesThisRun.push('agents');
443
- if (opts.deployCommands || opts.commandsOnly) typesThisRun.push('commands');
444
- if (opts.deployRules || opts.rulesOnly) typesThisRun.push('rules');
445
-
446
- for (const type of typesThisRun) {
447
- const relPath = provider.paths?.[type];
448
- if (!relPath) continue; // type not file-deployed by provider
449
- if (relPath.endsWith('.md')) continue; // aggregate file (e.g. AGENTS.md)
450
-
451
- const desired = computeAllArtifactBasenames(srcRoot, type);
452
- if (!desired) continue; // no global desired set → skip
453
-
454
- const destDir = path.isAbsolute(relPath) ? relPath : path.join(target, relPath);
455
- const removed = pruneStaleAiwgFiles(destDir, desired, {
456
- dryRun: opts.dryRun,
457
- verbose: opts.verbose,
458
- // Retire wrappers whose source skill no longer ships (#2511). Only the
459
- // command directory holds them; the kernel-only branch returns earlier,
460
- // so a bulk install still cannot touch wrappers it did not write.
461
- skillCommandStems: type === 'commands' ? computeAllSkillNames(srcRoot) : null,
462
- });
463
- if (removed.length > 0 && !opts.quiet) {
464
- console.log(` Pruned: ${removed.length} stale AIWG ${type} file${removed.length === 1 ? '' : 's'}`);
465
- }
466
- }
467
- }
345
+ export { bulkInstallOwnsFlatArtifacts } from './providers/stale-artifact-prune.mjs';
346
+ import { pruneStaleAiwgArtifacts } from './providers/stale-artifact-prune.mjs';
468
347
 
469
348
  // ============================================================================
470
349
  // Argument Parsing
@@ -1,3 +1,4 @@
1
+ import { withModelWrapper } from './model-wrapper.mjs';
1
2
  /** Google Antigravity CLI project resource deployment, qualified against 1.1.26. */
2
3
  import fs from 'node:fs';
3
4
  import path from 'node:path';
@@ -15,10 +16,9 @@ import {
15
16
  normalizeDeploymentMode,
16
17
  resolveAiwgRoot,
17
18
  } from './base.mjs';
18
-
19
19
  export const name = 'antigravity';
20
20
  export const aliases = ['agy'];
21
- export const paths = { agents: '.agents/agents', commands: '', skills: '.agents/skills', rules: '' };
21
+ export const paths = { agents: '.agents/agents', commands: '', skills: '.agents/skills', rules: '.antigravity/rules' };
22
22
  export const kernelSkillsPath = '.agents/skills';
23
23
  export const support = { agents: 'degraded', commands: 'indexed', skills: 'native', rules: 'context' };
24
24
  export const capabilities = {
@@ -29,9 +29,7 @@ export const capabilities = {
29
29
  homeDirectoryDeploy: false,
30
30
  parallelCommandAndSkillSurfaces: false,
31
31
  };
32
-
33
32
  export const mapModel = model => model;
34
-
35
33
  const ANTIGRAVITY_TOOL_MAP = new Map([
36
34
  ['Read', 'view_file'],
37
35
  ['Write', 'write_to_file'],
@@ -39,7 +37,6 @@ const ANTIGRAVITY_TOOL_MAP = new Map([
39
37
  ['Grep', 'grep_search'],
40
38
  ['Bash', 'run_command'],
41
39
  ]);
42
-
43
40
  function mapTools(value) {
44
41
  if (!value) return [];
45
42
  return value
@@ -49,7 +46,8 @@ function mapTools(value) {
49
46
  .filter(Boolean);
50
47
  }
51
48
 
52
- export function transformAgent(_source, content) {
49
+ export const transformAgent = withModelWrapper('antigravity', translateAgent);
50
+ function translateAgent(_source, content) {
53
51
  const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]*)$/);
54
52
  if (!match) return content;
55
53
  const frontmatter = match[1];
@@ -890,7 +890,7 @@ export function deployFiles(files, destDir, opts, transformFn) {
890
890
  if (a.type === 'deploy') {
891
891
  if (dryRun) console.log(`[dry-run] deploy ${a.src} -> ${a.dest} (${a.reason})`);
892
892
  else writeFile(a.dest, a.content, false);
893
- if (verbose) console.log(`deployed ${path.basename(a.src)} -> ${path.relative(process.cwd(), a.dest)} (${a.reason})`);
893
+ if (verbose) console.log(`deployed ${path.basename(a.src)} -> ${path.relative(process.cwd(), opts.logicalOutputPath?.(a.dest) || a.dest)} (${a.reason})`);
894
894
  deployedEntries.push({ filename: path.basename(a.dest), hash: a.hash, frameworkSlug: a.frameworkSlug, sourcePath: path.resolve(a.src) });
895
895
  } else if (a.type === 'skip') {
896
896
  if (verbose) console.log(`skip (${a.reason}): ${path.basename(a.dest)}`);
@@ -1577,7 +1577,7 @@ function pruneMissingStandardSkills(destDir, opts) {
1577
1577
  export function deploySkillDir(skillDir, destDir, opts) {
1578
1578
  const { force = false, dryRun = false, provider, transformSkillMd } = opts;
1579
1579
  const verbose = opts.verbose === true;
1580
- const skillName = path.basename(skillDir);
1580
+ const skillName = opts.skillName || path.basename(skillDir);
1581
1581
 
1582
1582
  // Check SKILL.md for explicit platform restriction before deploying anything
1583
1583
  const skillMdPath = path.join(skillDir, 'SKILL.md');
@@ -1592,7 +1592,7 @@ export function deploySkillDir(skillDir, destDir, opts) {
1592
1592
  const destSkillDir = path.join(destDir, skillName);
1593
1593
  const previous = readSidecarManifest(destSkillDir);
1594
1594
  const frameworkSlug = extractFrameworkSlug(skillMdPath);
1595
- if (!canDeploySkill(previous, skillDir, opts)) return;
1595
+ if (!canDeploySkill(previous, skillDir, opts)) return false;
1596
1596
  const managed = {};
1597
1597
  if (!dryRun) ensureDir(destSkillDir);
1598
1598
 
@@ -1,3 +1,4 @@
1
+ import { withModelWrapper } from './model-wrapper.mjs';
1
2
  import { postDeploy } from './claude-post-deploy.mjs';
2
3
  export { postDeploy };
3
4
  import { importImpl } from '../../_resolve-impl.mjs';
@@ -22,7 +23,6 @@ import { importImpl } from '../../_resolve-impl.mjs';
22
23
  * - Rules: .claude/rules/ (platform-native)
23
24
  * - Hooks/settings: .claude/ (platform-native)
24
25
  */
25
-
26
26
  import realFs from 'fs';
27
27
  import { createRequire } from 'module';
28
28
  const _require = createRequire(import.meta.url);
@@ -62,13 +62,10 @@ import {
62
62
  buildRemotesTopologyBlock,
63
63
  interpolateContextTokens
64
64
  } from './base.mjs';
65
-
66
65
  import { writeContextFileSync } from './context-write.mjs';
67
-
68
66
  // ============================================================================
69
67
  // Provider Configuration
70
68
  // ============================================================================
71
-
72
69
  export const name = 'claude';
73
70
  export const aliases = [];
74
71
 
@@ -165,7 +162,8 @@ export function mapModel(shorthand, modelCfg, modelsConfig) {
165
162
  * Transform agent content for Claude
166
163
  * Claude is the native format - minimal transformation needed
167
164
  */
168
- export function transformAgent(srcPath, content, opts) {
165
+ export const transformAgent = withModelWrapper('claude', translateAgent);
166
+ function translateAgent(srcPath, content, opts) {
169
167
  const { reasoningModel, codingModel, efficiencyModel } = opts;
170
168
 
171
169
  // Explicit overrides re-map every classified model, pinned or not.
@@ -1,3 +1,4 @@
1
+ import { withModelWrapper } from './model-wrapper.mjs';
1
2
  import { postDeploy } from './codex-post-deploy.mjs';
2
3
  export { postDeploy };
3
4
  import { importImpl } from '../../_resolve-impl.mjs';
@@ -28,7 +29,6 @@ import { importImpl } from '../../_resolve-impl.mjs';
28
29
  * - Delegates commands to deploy-prompts-codex.mjs (deploys to ~/.codex/prompts/)
29
30
  * - Delegates skills to deploy-skills-codex.mjs (deploys to .agents/skills/)
30
31
  */
31
-
32
32
  import realFs from 'fs';
33
33
  import { createRequire } from 'module';
34
34
  const _require = createRequire(import.meta.url);
@@ -69,15 +69,12 @@ import {
69
69
  parseFrontmatter,
70
70
  resolveAiwgRoot
71
71
  } from './base.mjs';
72
-
73
72
  import { writeContextFileSync } from './context-write.mjs';
74
-
75
73
  function resolveCodexHelperRoot(srcRoot) {
76
74
  const resolved = resolveAiwgRoot(srcRoot);
77
75
  if (resolved) return resolved;
78
76
  return path.resolve(path.dirname(new URL(import.meta.url).pathname), '..', '..', '..');
79
77
  }
80
-
81
78
  // ============================================================================
82
79
  // Provider Configuration
83
80
  // ============================================================================
@@ -206,7 +203,8 @@ export function renderAgentToml(srcPath, content, models) {
206
203
  /**
207
204
  * Transform agent content for Codex
208
205
  */
209
- export function transformAgent(srcPath, content, opts) {
206
+ export const transformAgent = withModelWrapper('codex', translateAgent);
207
+ function translateAgent(srcPath, content, opts) {
210
208
  const { reasoningModel, codingModel, efficiencyModel } = opts;
211
209
  const catalogModels = (opts.modelCatalog || loadRuntimeModelCatalog(staticModelCatalog)).providers.codex.roles;
212
210
 
@@ -14,8 +14,10 @@ export const CONTEXT_STAGE_ENV = 'AIWG_CONTEXT_STAGE_LOG';
14
14
 
15
15
  let loadError = null;
16
16
  let writer = null;
17
+ let ownership = null;
17
18
  try {
18
19
  writer = await importImpl(import.meta.url, 'smiths/context-pipeline/context-file-safety.js');
20
+ ownership = await importImpl(import.meta.url, 'smiths/context-pipeline/bridge-ownership.js');
19
21
  } catch (error) {
20
22
  loadError = error;
21
23
  }
@@ -26,3 +28,13 @@ export function writeContextFileSync(file, content, encoding) {
26
28
  }
27
29
  return writer.writeContextFileSync(file, content, encoding);
28
30
  }
31
+
32
+ export function normalizeRuleStartup(content, bootstrap, agentsHeader) {
33
+ if (!ownership) throw new Error('Startup ownership layer is unavailable', { cause: loadError });
34
+ return ownership.normalizeRuleStartup(content, bootstrap, agentsHeader);
35
+ }
36
+
37
+ export function retireLegacyBridge(content) {
38
+ if (!ownership) throw new Error('Startup ownership layer is unavailable', { cause: loadError });
39
+ return ownership.retireLegacyBridge(content);
40
+ }
@@ -1,3 +1,4 @@
1
+ import { withModelWrapper } from './model-wrapper.mjs';
1
2
  import { importImpl } from '../../_resolve-impl.mjs';
2
3
  /**
3
4
  * GitHub Copilot Provider
@@ -19,7 +20,6 @@ import { importImpl } from '../../_resolve-impl.mjs';
19
20
  * - Tool mapping to Copilot built-in tools
20
21
  * - Creates copilot-instructions.md
21
22
  */
22
-
23
23
  import realFs from 'fs';
24
24
  import { createRequire } from 'module';
25
25
  const _require = createRequire(import.meta.url);
@@ -55,14 +55,11 @@ import {
55
55
  deploySoulCompanions,
56
56
  loadRuntimeModelCatalog
57
57
  } from './base.mjs';
58
-
59
58
  import { writeContextFileSync } from './context-write.mjs';
60
59
  const modelCatalog = loadRuntimeModelCatalog(staticModelCatalog);
61
-
62
60
  // ============================================================================
63
61
  // Provider Configuration
64
62
  // ============================================================================
65
-
66
63
  export const name = 'copilot';
67
64
  export const aliases = [];
68
65
 
@@ -191,7 +188,8 @@ export function getTools(category, toolsString) {
191
188
  * Transform AIWG agent to GitHub Copilot .agent.md format.
192
189
  * Output: YAML frontmatter with name, description, tools, model + markdown body (system prompt).
193
190
  */
194
- export function transformAgent(srcPath, content, opts) {
191
+ export const transformAgent = withModelWrapper('copilot', translateAgent);
192
+ function translateAgent(srcPath, content, opts) {
195
193
  const { modelsConfig = {} } = opts;
196
194
 
197
195
  // Parse existing frontmatter
@@ -1,3 +1,4 @@
1
+ import { withModelWrapper } from './model-wrapper.mjs';
1
2
  /**
2
3
  * Cursor IDE Provider
3
4
  *
@@ -17,7 +18,6 @@
17
18
  * - $ARGUMENTS -> [arguments] conversion for rules
18
19
  * - Delegates rules deployment to deploy-rules-cursor.mjs
19
20
  */
20
-
21
21
  import realFs from 'fs';
22
22
  import { createRequire } from 'module';
23
23
  const _require = createRequire(import.meta.url);
@@ -56,14 +56,11 @@ import {
56
56
  loadRuntimeModelCatalog
57
57
  } from './base.mjs';
58
58
  const modelCatalog = loadRuntimeModelCatalog(staticModelCatalog);
59
-
60
59
  // ============================================================================
61
60
  // Provider Configuration
62
61
  // ============================================================================
63
-
64
62
  export const name = 'cursor';
65
63
  export const aliases = [];
66
-
67
64
  export const paths = {
68
65
  agents: '.cursor/agents/',
69
66
  commands: '.cursor/commands/',
@@ -99,7 +96,8 @@ export const capabilities = {
99
96
  * Transform agent content for Cursor
100
97
  * Cursor uses conventional deployment - minimal transformation needed
101
98
  */
102
- export function transformAgent(srcPath, content, opts) {
99
+ export const transformAgent = withModelWrapper('cursor', translateAgent);
100
+ function translateAgent(srcPath, content, opts) {
103
101
  const model = content.match(/^model:\s*(.+)$/m)?.[1]?.trim().replace(/['"]/g, '');
104
102
  if (!model) return content;
105
103
  const roles = modelCatalog.providers.cursor.roles;
@@ -1,3 +1,4 @@
1
+ import { withModelWrapper } from './model-wrapper.mjs';
1
2
  /**
2
3
  * Factory AI Provider
3
4
  *
@@ -16,7 +17,6 @@
16
17
  * - Enables custom droids in ~/.factory/settings.json
17
18
  * - Creates/updates AGENTS.md from template
18
19
  */
19
-
20
20
  import realFs from 'fs';
21
21
  import { createRequire } from 'module';
22
22
  const _require = createRequire(import.meta.url);
@@ -55,14 +55,11 @@ import {
55
55
  deploySoulCompanions
56
56
  } from './base.mjs';
57
57
  const modelCatalog = loadRuntimeModelCatalog(staticModelCatalog);
58
-
59
58
  // ============================================================================
60
59
  // Provider Configuration
61
60
  // ============================================================================
62
-
63
61
  export const name = 'factory';
64
62
  export const aliases = [];
65
-
66
63
  export const paths = {
67
64
  agents: '.factory/droids/',
68
65
  commands: '.factory/commands/',
@@ -297,7 +294,8 @@ export function mapModel(originalModel, modelCfg, modelsConfig) {
297
294
  /**
298
295
  * Transform AIWG agent to Factory droid format
299
296
  */
300
- export function transformAgent(srcPath, content, opts) {
297
+ export const transformAgent = withModelWrapper('factory', translateAgent);
298
+ function translateAgent(srcPath, content, opts) {
301
299
  const { modelsConfig = {} } = opts;
302
300
 
303
301
  // Parse existing frontmatter
@@ -1,3 +1,4 @@
1
+ import { withModelWrapper } from './model-wrapper.mjs';
1
2
  /**
2
3
  * Grok Build provider (experimental).
3
4
  * Project skills under `.grok/skills`; user home via $GROK_HOME (default ~/.grok).
@@ -5,7 +6,7 @@
5
6
  *
6
7
  * Native agent compilation is deliberately limited to the three AIWG model
7
8
  * workers until the wider corpus has a qualified Grok tool mapping (#2577).
8
- * Rules remain indexed; Grok loads AGENTS.md and native .grok/rules itself.
9
+ * Rules are written to .grok/rules and loaded by Grok alongside AGENTS.md.
9
10
  *
10
11
  * @issue #2575
11
12
  */
@@ -35,7 +36,7 @@ export const aliases = [];
35
36
  export const paths = {
36
37
  agents: '.grok/agents',
37
38
  skills: '.grok/skills',
38
- rules: '',
39
+ rules: '.grok/rules',
39
40
  hooks: '.grok/hooks',
40
41
  config: '.grok/config.toml',
41
42
  };
@@ -47,12 +48,15 @@ export const support = {
47
48
  agents: 'native',
48
49
  commands: 'indexed', // discoverable through the AIWG index; no native command writer
49
50
  skills: 'native',
50
- rules: 'indexed', // deferred native writer until #2577; host still loads AGENTS.md + .grok/rules hierarchically
51
+ // CONTEXT_CONTRACTS: https://docs.x.ai/build/features/project-rules
52
+ // .grok/rules/*.md loads hierarchically on every task; no frontmatter marker
53
+ // is required for always-on rules (unlike Windsurf's trigger field).
54
+ rules: 'native', // always-on Markdown rules discovered root-to-cwd by Grok Build
51
55
  };
52
56
 
53
57
  export const capabilities = {
54
58
  skills: true,
55
- rules: false, // indexed/deferred — do not claim native rule transforms yet
59
+ rules: true, // Native Markdown; path activation uses the index
56
60
  yamlFormat: false,
57
61
  aggregatedOutput: false,
58
62
  homeDirectoryDeploy: true,
@@ -137,7 +141,8 @@ const ROLE_FROM_ALIAS = { opus: 'reasoning', sonnet: 'coding', haiku: 'efficienc
137
141
  const GROK_TOOLS = new Set(['Bash', 'Read', 'Write', 'Edit', 'Grep', 'Glob']);
138
142
 
139
143
  /** Grok agent files accept a small YAML frontmatter subset, not AIWG metadata. */
140
- export function compileGrokAgent(source, content, opts = {}) {
144
+ export const compileGrokAgent = withModelWrapper('grok-build', translateAgent);
145
+ function translateAgent(source, content, opts = {}) {
141
146
  const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]*)$/);
142
147
  if (!match) throw new Error(`${source}: expected YAML agent frontmatter`);
143
148
  const metadata = yaml.load(match[1]);
@@ -146,8 +151,8 @@ export function compileGrokAgent(source, content, opts = {}) {
146
151
  }
147
152
  const name = metadata.name;
148
153
  const role = metadata['model-role'] || ROLE_FROM_ALIAS[metadata.model];
149
- if (!/^aiwg-model-(reasoning|coding|efficiency)-worker$/.test(String(name)) || !WORKER_ROLES.has(role)) {
150
- throw new Error(`${source}: Grok Build native compilation currently supports only the three AIWG model-worker roles; use aiwg show agent for other roles`);
154
+ if (!/^aiwg-model-((reasoning|coding|efficiency)-worker|explorer|verifier)$/.test(String(name)) || !WORKER_ROLES.has(role)) {
155
+ throw new Error(`${source}: Grok Build native compilation currently supports only the five AIWG model wrappers; use aiwg show agent for other roles`);
151
156
  }
152
157
  if (typeof metadata.description !== 'string' || !metadata.description.trim()) {
153
158
  throw new Error(`${source}: agent description is required`);
@@ -179,7 +184,7 @@ export function compileGrokAgent(source, content, opts = {}) {
179
184
  }
180
185
 
181
186
  export function deployAgents(agentFiles, targetDir, opts = {}) {
182
- const selected = agentFiles.filter(file => /^aiwg-model-(reasoning|coding|efficiency)-worker\.md$/.test(path.basename(file)));
187
+ const selected = agentFiles.filter(file => /^aiwg-model-((reasoning|coding|efficiency)-worker|explorer|verifier)\.md$/.test(path.basename(file)));
183
188
  const dir = assertSafeNativeDirectory(targetDir, paths.agents);
184
189
  for (const source of selected) {
185
190
  const dest = path.join(dir, path.basename(source));
@@ -291,7 +296,7 @@ export function uninstall(target, opts = {}) {
291
296
  }
292
297
  manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
293
298
  for (const [name, record] of Object.entries(manifest.managed ?? {})) {
294
- if (path.basename(name) !== name || !/^aiwg-model-(reasoning|coding|efficiency)-worker\.md$/.test(name)) continue;
299
+ if (path.basename(name) !== name || !/^aiwg-model-((reasoning|coding|efficiency)-worker|explorer|verifier)\.md$/.test(name)) continue;
295
300
  const file = path.join(agentsDir, name);
296
301
  const relative = path.relative(root, file);
297
302
  if (!fs.existsSync(file) || fs.lstatSync(file).isSymbolicLink() || !fs.lstatSync(file).isFile()) {
@@ -345,7 +350,7 @@ export async function postDeploy(target, opts = {}) {
345
350
  console.log(
346
351
  `Grok Build (experimental): kernel skills → ${kernelSkillsPath}; ` +
347
352
  `standard skills index-driven (opt-in mirror → ${standardSkillsPath} with --copy-all); ` +
348
- `model-worker agents → ${paths.agents}; rules indexed; user home → ${home || '(unresolved GROK_HOME)'}. ` +
353
+ `model-worker agents → ${paths.agents}; rules → ${paths.rules}; user home → ${home || '(unresolved GROK_HOME)'}. ` +
349
354
  'Distinct from grokbot.',
350
355
  );
351
356
  }
@@ -377,8 +382,8 @@ async function deploySelected(opts) {
377
382
  let count = 0;
378
383
  if (!opts.commandsOnly && !opts.skillsOnly && !opts.rulesOnly) {
379
384
  const workerDir = path.join(aiwgRoot, 'agentic', 'code', 'addons', 'aiwg-utils', 'agents');
380
- const workers = ['reasoning', 'coding', 'efficiency']
381
- .map(role => path.join(workerDir, `aiwg-model-${role}-worker.md`))
385
+ const workers = ['reasoning-worker', 'coding-worker', 'efficiency-worker', 'explorer', 'verifier']
386
+ .map(role => path.join(workerDir, `aiwg-model-${role}.md`))
382
387
  .filter(file => fs.existsSync(file));
383
388
  count += deployAgents(workers, opts.target, opts).filter(action => action.type === 'deploy').length;
384
389
  }
@@ -0,0 +1,144 @@
1
+ /** Preserve Hermes curator registration and migrate the legacy skill directory. */
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ export function createHermesSkillLifecycle({ getHermesHome, paths, kernelSkillsPath }) {
5
+ /**
6
+ * Hermes v0.12.0+ ships an autonomous Curator (`agent/curator.py`) that
7
+ * grades and archives skills on a 7-day cycle. Skills are excluded from
8
+ * archival if either:
9
+ * (a) they appear in `~/.hermes/skills/.bundled_manifest` (one name per
10
+ * line, format `name:tag`), or
11
+ * (b) their path's first component starts with `.` (verified at
12
+ * `tools/skill_usage.py:241-243`).
13
+ *
14
+ * AIWG standard skills under `~/.hermes/skills/.aiwg/...` are protected
15
+ * by (b) automatically. AIWG kernel skills land at the top level
16
+ * (`~/.hermes/skills/<name>/SKILL.md`) and need explicit (a) registration.
17
+ *
18
+ * This function writes/updates the bundled manifest with the kernel-skill
19
+ * names AIWG owns. Idempotent: existing entries (from Hermes's own bundle
20
+ * or other tools) are preserved.
21
+ */
22
+ function updateBundledManifest(kernelSkillNames, opts) {
23
+ const { dryRun, quiet } = opts;
24
+ const manifestPath = path.join(opts.kernelSkillsPath || kernelSkillsPath, '.bundled_manifest');
25
+ const aiwgTag = 'aiwg-managed';
26
+
27
+ // Read existing manifest (if any) and split into "ours" vs "theirs"
28
+ let existing = '';
29
+ try {
30
+ existing = fs.readFileSync(manifestPath, 'utf-8');
31
+ } catch {
32
+ existing = '';
33
+ }
34
+ const theirs = [];
35
+ for (const rawLine of existing.split('\n')) {
36
+ const line = rawLine.trim();
37
+ if (!line) continue;
38
+ if (line.endsWith(`:${aiwgTag}`)) continue; // ours — drop, will re-add below
39
+ theirs.push(line);
40
+ }
41
+ const ours = kernelSkillNames.map((n) => `${n}:${aiwgTag}`);
42
+
43
+ // Stable order: theirs first (preserve operator/Hermes-bundled order), then ours
44
+ const merged = [...theirs, ...ours].join('\n') + '\n';
45
+
46
+ if (dryRun) {
47
+ if (!quiet) {
48
+ console.log(` [curator] [dry-run] Would write ${manifestPath} with ${ours.length} AIWG kernel + ${theirs.length} preserved entries`);
49
+ }
50
+ return;
51
+ }
52
+
53
+ try {
54
+ fs.mkdirSync(path.dirname(manifestPath), { recursive: true });
55
+ fs.writeFileSync(manifestPath, merged, 'utf-8');
56
+ if (!quiet) {
57
+ console.log(` [curator] Bundled manifest updated: ${ours.length} AIWG kernel skills protected (preserved ${theirs.length} pre-existing entries)`);
58
+ }
59
+ } catch (err) {
60
+ if (!quiet) {
61
+ console.log(` [curator] Warning: could not write bundled manifest: ${err.message}`);
62
+ }
63
+ }
64
+ }
65
+
66
+ // ============================================================================
67
+ // Legacy skill path migration (#1316 / S5)
68
+ // ============================================================================
69
+
70
+ /**
71
+ * Remove the legacy `~/.hermes/.aiwg/skills/` directory if it exists and the
72
+ * new path `~/.hermes/skills/.aiwg/` is populated with AIWG content.
73
+ *
74
+ * Idempotent: re-running after migration is a no-op.
75
+ *
76
+ * Safety:
77
+ * - Only removes when the new path exists and contains files
78
+ * - Skips removal if the new path is empty (avoids losing skills during
79
+ * an in-progress deploy where the new path hasn't been written yet)
80
+ * - Operates only on the documented legacy path — never touches user-managed
81
+ * directories under ~/.hermes/
82
+ */
83
+ function migrateLegacySkillPath(opts) {
84
+ const { dryRun, quiet } = opts;
85
+ // Resolve through the same HERMES_HOME contract as every other path in
86
+ // this provider (env var first, platform default otherwise): with
87
+ // HERMES_HOME set, the legacy tree lives under that root — never under
88
+ // the process home directory.
89
+ const legacyPath = opts.hermesLegacySkills || path.join(getHermesHome(), '.aiwg', 'skills');
90
+ const newPath = paths.skills;
91
+
92
+ let legacyExists = false;
93
+ try {
94
+ legacyExists = fs.statSync(legacyPath).isDirectory();
95
+ } catch {
96
+ return; // no legacy path — nothing to migrate
97
+ }
98
+ if (!legacyExists) return;
99
+
100
+ // Sanity: new path must exist and be non-empty before we remove the legacy one
101
+ let newPopulated = false;
102
+ try {
103
+ const entries = fs.readdirSync(newPath);
104
+ newPopulated = entries.length > 0;
105
+ } catch {
106
+ newPopulated = false;
107
+ }
108
+
109
+ if (!newPopulated) {
110
+ if (!quiet) {
111
+ console.log(` [migrate] Legacy skills detected at ${legacyPath}; new path not yet populated. Skipping cleanup until next deploy.`);
112
+ }
113
+ return;
114
+ }
115
+
116
+ if (dryRun) {
117
+ console.log(` [migrate] [dry-run] Would remove legacy skill path: ${legacyPath}`);
118
+ return;
119
+ }
120
+
121
+ try {
122
+ fs.rmSync(legacyPath, { recursive: true, force: true });
123
+ // Also remove the empty parent if it's now empty
124
+ const parent = path.dirname(legacyPath);
125
+ try {
126
+ const remaining = fs.readdirSync(parent);
127
+ if (remaining.length === 0) {
128
+ fs.rmdirSync(parent);
129
+ }
130
+ } catch {
131
+ // parent removal is best-effort
132
+ }
133
+ if (!quiet) {
134
+ console.log(` [migrate] Removed legacy skill path: ${legacyPath}`);
135
+ }
136
+ } catch (err) {
137
+ if (!quiet) {
138
+ console.log(` [migrate] Warning: could not remove legacy path ${legacyPath}: ${err.message}`);
139
+ }
140
+ }
141
+ }
142
+
143
+ return { updateBundledManifest, migrateLegacySkillPath };
144
+ }