@aiwg/cli 2026.10.11 → 2026.10.14

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 (174) hide show
  1. package/agentic/code/providers/model-catalog.v1.json +62 -12
  2. package/agentic/code/providers/pi/aiwg-bridge.ts +44 -1
  3. package/dist/src/artifacts/binding-target-identity.js +51 -0
  4. package/dist/src/artifacts/checksum-manifest.js +12 -0
  5. package/dist/src/artifacts/index-builder.js +11 -13
  6. package/dist/src/artifacts/query-engine.js +5 -11
  7. package/dist/src/cli/handlers/doctor-help.js +32 -0
  8. package/dist/src/cli/handlers/gates.js +19 -18
  9. package/dist/src/cli/handlers/models-help.js +7 -1
  10. package/dist/src/cli/handlers/models.js +3 -3
  11. package/dist/src/cli/handlers/script-runner.js +8 -5
  12. package/dist/src/cli/handlers/sessions-intake.js +104 -0
  13. package/dist/src/cli/handlers/sessions-tail.js +172 -0
  14. package/dist/src/cli/handlers/sessions.js +90 -17
  15. package/dist/src/cli/handlers/skill-lint.js +10 -3
  16. package/dist/src/cli/handlers/steward-format.js +100 -0
  17. package/dist/src/cli/handlers/steward-models.js +167 -0
  18. package/dist/src/cli/handlers/steward.js +14 -248
  19. package/dist/src/cli/handlers/use-bundle-counts.js +87 -0
  20. package/dist/src/cli/handlers/use-skill-assets.js +207 -0
  21. package/dist/src/cli/handlers/use.js +35 -216
  22. package/dist/src/cli/handlers/utilities.js +1 -24
  23. package/dist/src/config/aiwg-config.js +7 -0
  24. package/dist/src/config/authorization-cli.js +97 -0
  25. package/dist/src/config/cli-help.js +1 -0
  26. package/dist/src/config/cli.js +10 -1
  27. package/dist/src/decision/context-pruning-common.js +41 -0
  28. package/dist/src/decision/context-pruning-evaluation.js +366 -0
  29. package/dist/src/decision/context-pruning-pilot.js +431 -0
  30. package/dist/src/decision/context-pruning-types.js +19 -0
  31. package/dist/src/decision/context-pruning.js +5 -846
  32. package/dist/src/decision/ensemble/contract.js +17 -26
  33. package/dist/src/decision/ensemble-study/artifacts.js +5 -0
  34. package/dist/src/decision/ensemble-study/score.js +4 -3
  35. package/dist/src/decision/feature-export.js +3 -9
  36. package/dist/src/decision/heldout/collector.js +2 -2
  37. package/dist/src/decision/issue-triage/runtime.js +3 -9
  38. package/dist/src/decision/qualification/gates.js +2 -1
  39. package/dist/src/decision/qualification/release.js +6 -64
  40. package/dist/src/decision/routing/report.js +2 -0
  41. package/dist/src/decision/sdlc-screening.js +3 -5
  42. package/dist/src/decision/sensitivity/comparative.js +5 -3
  43. package/dist/src/extensions/manifest.js +8 -1
  44. package/dist/src/extensions/project-local-doctor.js +78 -2
  45. package/dist/src/extensions/validation.js +10 -11
  46. package/dist/src/gates/driver.js +6 -77
  47. package/dist/src/gates/evaluate.js +6 -23
  48. package/dist/src/gates/floors.js +4 -4
  49. package/dist/src/gates/index.js +3 -3
  50. package/dist/src/gates/lattice.js +26 -0
  51. package/dist/src/gates/registry.js +2 -1
  52. package/dist/src/gates/report.js +19 -7
  53. package/dist/src/gates/upstream-ceiling.js +111 -0
  54. package/dist/src/issues/audit-cli.js +120 -0
  55. package/dist/src/issues/audit-contract.js +64 -0
  56. package/dist/src/issues/audit-local.js +82 -0
  57. package/dist/src/issues/audit.js +220 -0
  58. package/dist/src/lint/rule-activation.js +15 -1
  59. package/dist/src/mission-protocol/canonical-codecs.js +270 -0
  60. package/dist/src/mission-protocol/codecs.js +22 -550
  61. package/dist/src/mission-protocol/health-trace-codecs.js +281 -0
  62. package/dist/src/mission-protocol/health-trace-types.js +43 -0
  63. package/dist/src/mission-protocol/types.js +2 -42
  64. package/dist/src/mission-protocol/worker-contract-json.js +10 -0
  65. package/dist/src/mission-protocol/worker-review-gate.js +100 -0
  66. package/dist/src/mission-protocol/worker-review-types.js +2 -0
  67. package/dist/src/models/catalog-policy.js +280 -0
  68. package/dist/src/models/index.js +1 -1
  69. package/dist/src/models/model-catalog.v1.json +62 -12
  70. package/dist/src/models/policy-resources.js +28 -0
  71. package/dist/src/models/provider-models.js +5 -8
  72. package/dist/src/models/provider-policy.js +10 -546
  73. package/dist/src/models/resolver.js +26 -8
  74. package/dist/src/models/router.js +15 -2
  75. package/dist/src/models/tiers.js +13 -0
  76. package/dist/src/models/types.js +0 -6
  77. package/dist/src/models/worker-ceilings.js +59 -0
  78. package/dist/src/models/worker-invocation-policy.js +243 -0
  79. package/dist/src/models/worker-plan.js +16 -20
  80. package/dist/src/models/worker-review-lineage.js +55 -0
  81. package/dist/src/models/worker-selection-policy.js +1 -1
  82. package/dist/src/models/wrapper-definitions.js +14 -0
  83. package/dist/src/models/wrapper-deployment.js +48 -25
  84. package/dist/src/models/wrapper-enforcement.js +72 -0
  85. package/dist/src/models/wrapper-route.js +6 -3
  86. package/dist/src/policy/authorization.js +1 -0
  87. package/dist/src/policy/hitl-check.js +80 -0
  88. package/dist/src/policy/hitl-config.js +63 -0
  89. package/dist/src/policy/hitl-receipt.js +57 -0
  90. package/dist/src/policy/hitl-types.js +4 -0
  91. package/dist/src/policy/hitl-validation.js +39 -0
  92. package/dist/src/policy/hitl.js +117 -0
  93. package/dist/src/rules/activation.d.mts +3 -1
  94. package/dist/src/rules/activation.mjs +23 -2
  95. package/dist/src/rules/gate-coverage.js +51 -0
  96. package/dist/src/rules/gate-references.js +16 -0
  97. package/dist/src/rules/rule-frontmatter.schema.json +7 -1
  98. package/dist/src/serve/worker-command-request.js +21 -4
  99. package/dist/src/serve/worker-invocation-preparation.js +3 -1
  100. package/dist/src/serve/worker-invocation.js +21 -10
  101. package/dist/src/sessions/adapters/deepseek-harness.js +1 -0
  102. package/dist/src/sessions/adapters/grok-build-native.js +269 -0
  103. package/dist/src/sessions/adapters/grok-build.js +57 -15
  104. package/dist/src/sessions/adapters/hermes-state-db.js +252 -0
  105. package/dist/src/sessions/adapters/hermes.js +42 -3
  106. package/dist/src/sessions/adapters/warp.js +1 -1
  107. package/dist/src/sessions/batch-import.js +10 -0
  108. package/dist/src/sessions/contracts.js +1 -1
  109. package/dist/src/sessions/discovery-capability.js +38 -0
  110. package/dist/src/sessions/importer.js +8 -251
  111. package/dist/src/sessions/index.js +4 -0
  112. package/dist/src/sessions/intake-dir.js +71 -0
  113. package/dist/src/sessions/normalization.js +251 -0
  114. package/dist/src/sessions/tail.js +91 -0
  115. package/dist/src/sessions/workspace-discovery.js +83 -7
  116. package/dist/src/skills/adapters/local.js +32 -9
  117. package/dist/src/skills/agent-skill-sidecar.js +28 -0
  118. package/dist/src/skills/agent-skills.js +6 -23
  119. package/dist/src/skills/claude-surface-projection.js +25 -0
  120. package/dist/src/skills/cli-display.js +33 -0
  121. package/dist/src/skills/cli.js +2 -26
  122. package/dist/src/skills/collision-discovery.js +84 -0
  123. package/dist/src/skills/deployer.js +26 -361
  124. package/dist/src/skills/deployment-ownership.js +74 -0
  125. package/dist/src/skills/deployment-policy.js +114 -0
  126. package/dist/src/skills/deployment-projection.js +152 -0
  127. package/dist/src/skills/deployment-types.js +20 -0
  128. package/dist/src/skills/doctor.js +2 -2
  129. package/dist/src/skills/exporter.js +8 -31
  130. package/dist/src/skills/importer.js +4 -26
  131. package/dist/src/skills/provider-extensions.js +41 -0
  132. package/dist/src/skills/registry.js +22 -7
  133. package/dist/src/skills/run.js +6 -0
  134. package/dist/src/skills/types.js +0 -8
  135. package/dist/src/skills/validator-resources.js +68 -0
  136. package/dist/src/skills/validator.js +6 -55
  137. package/dist/src/smiths/context-pipeline/parallelism-section.js +7 -3
  138. package/dist/src/storage/cli-migrate-options.js +125 -0
  139. package/dist/src/storage/cli-migrate.js +111 -0
  140. package/dist/src/storage/cli.js +4 -279
  141. package/dist/src/storage/migration-adapter.js +79 -0
  142. package/dist/src/storage/migration-copy.js +108 -0
  143. package/dist/src/storage/migration-protocol.js +14 -197
  144. package/dist/src/storage/migration-records.js +186 -0
  145. package/dist/src/storage/migration-types.js +12 -0
  146. package/dist/src/tracker/forge-http.js +2 -1
  147. package/dist/src/tracker/issue-pages.js +110 -0
  148. package/package.json +3 -1
  149. package/schemas/mission-v1.schema.json +335 -0
  150. package/schemas/models/model-catalog.v1.schema.json +19 -1
  151. package/schemas/models/model-config-compatibility.v1.schema.json +3 -2
  152. package/schemas/models/model-policy.v1.schema.json +1 -1
  153. package/tools/agents/providers/antigravity.mjs +3 -5
  154. package/tools/agents/providers/base.mjs +3 -3
  155. package/tools/agents/providers/claude.mjs +3 -5
  156. package/tools/agents/providers/codex.mjs +3 -5
  157. package/tools/agents/providers/copilot.mjs +3 -5
  158. package/tools/agents/providers/cursor.mjs +3 -5
  159. package/tools/agents/providers/factory.mjs +3 -5
  160. package/tools/agents/providers/grok-build.mjs +9 -7
  161. package/tools/agents/providers/model-wrapper.mjs +86 -0
  162. package/tools/agents/providers/omp.mjs +3 -1
  163. package/tools/agents/providers/openclaw.mjs +3 -5
  164. package/tools/agents/providers/opencode.mjs +3 -5
  165. package/tools/agents/providers/provider-paths-staging.mjs +44 -0
  166. package/tools/agents/providers/rule-binding-targets.mjs +146 -0
  167. package/tools/agents/providers/rule-delivery.mjs +9 -128
  168. package/tools/agents/providers/warp.mjs +3 -5
  169. package/tools/agents/providers/windsurf.mjs +3 -5
  170. package/tools/plugin/package-plugins.mjs +2 -2
  171. package/tools/skills/codex-skill-transform.mjs +232 -0
  172. package/tools/skills/deploy-skills-codex.mjs +8 -249
  173. package/tools/warp/warp-content.mjs +548 -0
  174. package/vscode-extension/schemas/aiwg.config.v1.json +177 -0
@@ -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
 
@@ -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).
@@ -137,7 +138,8 @@ const ROLE_FROM_ALIAS = { opus: 'reasoning', sonnet: 'coding', haiku: 'efficienc
137
138
  const GROK_TOOLS = new Set(['Bash', 'Read', 'Write', 'Edit', 'Grep', 'Glob']);
138
139
 
139
140
  /** Grok agent files accept a small YAML frontmatter subset, not AIWG metadata. */
140
- export function compileGrokAgent(source, content, opts = {}) {
141
+ export const compileGrokAgent = withModelWrapper('grok-build', translateAgent);
142
+ function translateAgent(source, content, opts = {}) {
141
143
  const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]*)$/);
142
144
  if (!match) throw new Error(`${source}: expected YAML agent frontmatter`);
143
145
  const metadata = yaml.load(match[1]);
@@ -146,8 +148,8 @@ export function compileGrokAgent(source, content, opts = {}) {
146
148
  }
147
149
  const name = metadata.name;
148
150
  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`);
151
+ if (!/^aiwg-model-((reasoning|coding|efficiency)-worker|explorer|verifier)$/.test(String(name)) || !WORKER_ROLES.has(role)) {
152
+ throw new Error(`${source}: Grok Build native compilation currently supports only the five AIWG model wrappers; use aiwg show agent for other roles`);
151
153
  }
152
154
  if (typeof metadata.description !== 'string' || !metadata.description.trim()) {
153
155
  throw new Error(`${source}: agent description is required`);
@@ -179,7 +181,7 @@ export function compileGrokAgent(source, content, opts = {}) {
179
181
  }
180
182
 
181
183
  export function deployAgents(agentFiles, targetDir, opts = {}) {
182
- const selected = agentFiles.filter(file => /^aiwg-model-(reasoning|coding|efficiency)-worker\.md$/.test(path.basename(file)));
184
+ const selected = agentFiles.filter(file => /^aiwg-model-((reasoning|coding|efficiency)-worker|explorer|verifier)\.md$/.test(path.basename(file)));
183
185
  const dir = assertSafeNativeDirectory(targetDir, paths.agents);
184
186
  for (const source of selected) {
185
187
  const dest = path.join(dir, path.basename(source));
@@ -291,7 +293,7 @@ export function uninstall(target, opts = {}) {
291
293
  }
292
294
  manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
293
295
  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;
296
+ if (path.basename(name) !== name || !/^aiwg-model-((reasoning|coding|efficiency)-worker|explorer|verifier)\.md$/.test(name)) continue;
295
297
  const file = path.join(agentsDir, name);
296
298
  const relative = path.relative(root, file);
297
299
  if (!fs.existsSync(file) || fs.lstatSync(file).isSymbolicLink() || !fs.lstatSync(file).isFile()) {
@@ -377,8 +379,8 @@ async function deploySelected(opts) {
377
379
  let count = 0;
378
380
  if (!opts.commandsOnly && !opts.skillsOnly && !opts.rulesOnly) {
379
381
  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`))
382
+ const workers = ['reasoning-worker', 'coding-worker', 'efficiency-worker', 'explorer', 'verifier']
383
+ .map(role => path.join(workerDir, `aiwg-model-${role}.md`))
382
384
  .filter(file => fs.existsSync(file));
383
385
  count += deployAgents(workers, opts.target, opts).filter(action => action.type === 'deploy').length;
384
386
  }
@@ -0,0 +1,86 @@
1
+ // Apply canonical wrapper pins and read-only controls after each provider's native translation.
2
+ import { load, dump } from 'js-yaml';
3
+ import { importImpl } from '../../_resolve-impl.mjs';
4
+ const { MODEL_WRAPPER_DEFINITIONS } = await importImpl(import.meta.url, 'models/wrapper-definitions.js');
5
+ // These TypeScript graphs import siblings by their compiled .js names, so they
6
+ // load only from dist/. Run `npm run build:cli` before using a checkout's tools.
7
+ async function compiled(module) {
8
+ try { return await importImpl(import.meta.url, module); }
9
+ catch (error) {
10
+ if (error?.code !== 'ERR_MODULE_NOT_FOUND') throw error;
11
+ throw Object.assign(new Error(`provider translators need the compiled ${module} from dist/; run \`npm run build:cli\` first (${error.message})`),
12
+ { code: 'AIWG_BUILD_REQUIRED', cause: error });
13
+ }
14
+ }
15
+ const { loadProviderModelCatalog } = await compiled('models/catalog-policy.js');
16
+ const { resolveWrapperPin } = await compiled('models/wrapper-enforcement.js');
17
+
18
+ function parse(content) {
19
+ const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]*)$/);
20
+ return match ? { metadata: load(match[1]) || {}, body: match[2] } : null;
21
+ }
22
+
23
+ /** Ordinary agents retain their provider translator; only the five canonical wrappers opt in. */
24
+ export function withModelWrapper(provider, translate) {
25
+ return (source, content, opts = {}) => {
26
+ const parsed = parse(content);
27
+ const wrapper = MODEL_WRAPPER_DEFINITIONS.find(item => item.name === parsed?.metadata.name);
28
+ if (!wrapper) return translate(source, content, opts);
29
+ const catalog = opts.modelCatalog || loadProviderModelCatalog();
30
+ const config = opts.modelsConfig?.[provider]?.[wrapper.role];
31
+ const sourceModel = parsed.metadata.model;
32
+ const override = parsed.metadata['model-override'] || opts[`${wrapper.role}Model`]
33
+ || config?.model || (sourceModel && !['opus', 'sonnet', 'haiku', 'inherit', 'auto'].includes(sourceModel) ? sourceModel : undefined);
34
+ // Reuse #2643 election checks, including catalog entries marked user-elected.
35
+ // Wrappers never supply election authority, even if a parent session has it.
36
+ const effort = parsed.metadata['model-effort'] || parsed.metadata.model_reasoning_effort
37
+ || parsed.metadata.reasoningEffort || parsed.metadata.thinkingLevel || parsed.metadata.effort
38
+ || config?.reasoningEffort;
39
+ const { tier, role, model: pin, effort: nativeEffort, controls, enforcement } =
40
+ resolveWrapperPin(provider, wrapper, { catalog, override, effort });
41
+ // Legacy translators read a single tools line; normalize YAML lists before mapping.
42
+ const toolList = parsed.metadata.tools;
43
+ const normalized = Array.isArray(toolList) && ['antigravity', 'copilot', 'factory', 'windsurf'].includes(provider)
44
+ ? content.replace(/^tools:[^\n]*(?:\n[ \t]+- [^\n]*)*/m,
45
+ `tools: ${provider === 'antigravity' ? `[${toolList.join(', ')}]` : JSON.stringify(toolList)}`)
46
+ : content;
47
+ const mapped = translate(source, normalized, opts);
48
+ const notice = `AIWG wrapper tier: ${tier}; catalog role: ${role}. `
49
+ + `Tier enforcement: ${enforcement}; effort: ${nativeEffort ? `pinned (${nativeEffort})` : 'not enforced per wrapper'}. `
50
+ + (pin ? `Model selector: ${pin}.` : 'The automatic selector is not a model pin. Model control is inherited or informational; stop unless the conductor confirms the required non-flagship session.')
51
+ + (provider === 'grok-build' ? ' Native-agent tier enforcement remains gated by #2577; not enforced.' : '');
52
+ if (provider === 'codex') {
53
+ let output = mapped.replace(/^model = .*$/m, `model = ${JSON.stringify(pin)}`);
54
+ if (!pin) throw new Error(`${source}: Codex wrapper needs a catalog model pin`);
55
+ output = output.replace(/^model_reasoning_effort = .*$/m, `model_reasoning_effort = ${JSON.stringify(nativeEffort)}`);
56
+ output = output.replace(/^developer_instructions = (.*)$/m, (_line, value) =>
57
+ `developer_instructions = ${JSON.stringify(`${notice}\n\n${JSON.parse(value)}`)}`);
58
+ if (wrapper.readOnly) output += 'sandbox_mode = "read-only"\n';
59
+ return output;
60
+ }
61
+ const target = parse(mapped);
62
+ if (!target) return `${mapped.trim()}\n\n${notice}\n`;
63
+ const metadata = target.metadata;
64
+ if (pin) metadata[controls.model] = pin;
65
+ else if (!override) delete metadata.model;
66
+ if (nativeEffort) metadata[controls.effort] = nativeEffort;
67
+ if (metadata['model-tier']) metadata['model-tier'] = tier;
68
+ if (wrapper.readOnly) {
69
+ if (provider === 'opencode') {
70
+ // OpenCode uses permission rules rather than a tools list. Unknown tools deny.
71
+ metadata.permission = { '*': 'deny', read: 'allow', grep: 'allow', glob: 'allow',
72
+ bash: 'ask', edit: 'deny', task: 'deny' };
73
+ } else if (provider === 'cursor') metadata.readonly = true;
74
+ else if (provider === 'claude') metadata.disallowedTools = ['Write', 'Edit', 'Task', 'Agent'];
75
+ }
76
+ let header = dump(metadata, { lineWidth: -1, noRefs: true });
77
+ // Keep the translator's own tools line (Factory JSON, Copilot quoted list);
78
+ // the wrapper never changes tools, and a block list breaks those formats.
79
+ const nativeHeader = mapped.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n/)?.[1] ?? '';
80
+ const nativeTools = nativeHeader.match(/^tools:[^\n]*(?:\n[ \t]+- [^\n]*)*/m)?.[0];
81
+ if (nativeTools) header = header.replace(/^tools:[^\n]*(?:\n[ \t]+- [^\n]*)*/m, () => nativeTools);
82
+ // Keep Grok's quoted native model selector, including operator-supplied IDs.
83
+ if (provider === 'grok-build' && metadata.model) header = header.replace(/^model: .*$/m, `model: ${JSON.stringify(metadata.model)}`);
84
+ return `---\n${header}---\n\n${notice}\n\n${target.body.trim()}\n`;
85
+ };
86
+ }
@@ -6,6 +6,7 @@ import YAML from 'yaml';
6
6
  import { importImpl } from '../../_resolve-impl.mjs';
7
7
  import { withRuleDeployment, collectFrameworkArtifacts, getAddonFiles, isKernelSkill, listMdFiles, listSkillDirs, normalizeDeploymentMode, resolveAiwgRoot } from './base.mjs';
8
8
 
9
+ import { withModelWrapper } from './model-wrapper.mjs';
9
10
  import { writeContextFileSync } from './context-write.mjs';
10
11
  export const name = 'omp';
11
12
  export const aliases = ['oh-my-pi'];
@@ -23,7 +24,8 @@ function diagnostic(opts, message) { opts.diagnostics?.push(message); if (!opts.
23
24
  // Resolved through the shared resolver: an installed package ships these
24
25
  // modules under dist/src, not src, so a literal path into src fails there.
25
26
  const { resolveOmpPaths } = await importImpl(import.meta.url, 'providers/omp-paths.mjs');
26
- const { transformAgent, mapModel } = await importImpl(import.meta.url, 'providers/omp-agent.mjs');
27
+ const { transformAgent: translateAgent, mapModel } = await importImpl(import.meta.url, 'providers/omp-agent.mjs');
28
+ const transformAgent = withModelWrapper('omp', translateAgent);
27
29
  export { transformAgent, mapModel };
28
30
  const array = value => Array.isArray(value) ? value : typeof value === 'string' ? value.split(',').map(s => s.trim()).filter(Boolean) : [];
29
31
  export function transformCommand(src, content, opts = {}) {
@@ -1,3 +1,4 @@
1
+ import { withModelWrapper } from './model-wrapper.mjs';
1
2
  /**
2
3
  * OpenClaw Provider
3
4
  *
@@ -17,7 +18,6 @@
17
18
  *
18
19
  * See: docs/openclaw-guide.md
19
20
  */
20
-
21
21
  import realFs from 'fs';
22
22
  import { createRequire } from 'module';
23
23
  const _require = createRequire(import.meta.url);
@@ -52,14 +52,11 @@ import {
52
52
  createAgentsMdFromTemplate,
53
53
  createManagedMdFromTemplate,
54
54
  } from './base.mjs';
55
-
56
55
  // ============================================================================
57
56
  // Provider Configuration
58
57
  // ============================================================================
59
-
60
58
  export const name = 'openclaw';
61
59
  export const aliases = [];
62
-
63
60
  const openclawHome = path.join(os.homedir(), '.openclaw');
64
61
 
65
62
  export const paths = {
@@ -141,7 +138,8 @@ export function mapModel(shorthand, modelCfg, modelsConfig) {
141
138
  // Content Transformation (passthrough — OpenClaw uses AIWG native format)
142
139
  // ============================================================================
143
140
 
144
- export function transformAgent(srcPath, content, opts) {
141
+ export const transformAgent = withModelWrapper('openclaw', translateAgent);
142
+ function translateAgent(srcPath, content, opts) {
145
143
  // AIWG's catalog intentionally records configured/<role> placeholders for
146
144
  // OpenClaw because the exact provider/model namespace is installation
147
145
  // specific. Omit the portable Markdown pin and inherit the configured
@@ -1,3 +1,4 @@
1
+ import { withModelWrapper } from './model-wrapper.mjs';
1
2
  /**
2
3
  * OpenCode Provider
3
4
  *
@@ -15,7 +16,6 @@
15
16
  * - Permission system with bash command whitelist
16
17
  * - Temperature and steps per category
17
18
  */
18
-
19
19
  import realFs from 'fs';
20
20
  import { createRequire } from 'module';
21
21
  const _require = createRequire(import.meta.url);
@@ -54,14 +54,11 @@ import {
54
54
  } from './base.mjs';
55
55
  const { assertConfigDestination, writeConfigAtomic } = await importImpl(import.meta.url, 'mcp/config-file.mjs');
56
56
  const modelCatalog = loadRuntimeModelCatalog(staticModelCatalog);
57
-
58
57
  // ============================================================================
59
58
  // Provider Configuration
60
59
  // ============================================================================
61
-
62
60
  export const name = 'opencode';
63
61
  export const aliases = [];
64
-
65
62
  export const paths = {
66
63
  agents: '.opencode/agent/', // Discovered via {agent,agents}/**/*.md glob (#773)
67
64
  commands: '.opencode/command/',
@@ -208,7 +205,8 @@ export function getAgentConfig(category, name) {
208
205
  /**
209
206
  * Transform AIWG agent to OpenCode agent format
210
207
  */
211
- export function transformAgent(srcPath, content, opts) {
208
+ export const transformAgent = withModelWrapper('opencode', translateAgent);
209
+ function translateAgent(srcPath, content, opts) {
212
210
  const { modelsConfig = {} } = opts;
213
211
 
214
212
  // Parse existing frontmatter
@@ -0,0 +1,44 @@
1
+ /** Stage and restore provider path overrides without writing through getter-only accessors. */
2
+ import { sep } from 'node:path';
3
+
4
+ export function logicalProviderOutputPath(file, stage, target, mappings = []) {
5
+ const mapping = [...mappings].sort((a, b) => b.to.length - a.to.length)
6
+ .find(item => file === item.to || file.startsWith(`${item.to}${sep}`));
7
+ if (mapping) return mapping.from + file.slice(mapping.to.length);
8
+ return file === stage || file.startsWith(`${stage}${sep}`) ? target + file.slice(stage.length) : file;
9
+ }
10
+
11
+ export function captureProviderPathDescriptors(provider) {
12
+ return Object.getOwnPropertyDescriptors(provider.paths);
13
+ }
14
+
15
+ export function setStagedProviderPath(provider, key, value) {
16
+ try {
17
+ Object.defineProperty(provider.paths, key, {
18
+ value,
19
+ writable: true,
20
+ enumerable: true,
21
+ configurable: true,
22
+ });
23
+ return;
24
+ } catch {
25
+ const descriptor = Object.getOwnPropertyDescriptor(provider.paths, key);
26
+ if (descriptor?.set || descriptor?.writable) provider.paths[key] = value;
27
+ else throw new Error(`Cannot stage provider path '${key}': accessor has no setter and cannot be redefined`);
28
+ }
29
+ }
30
+
31
+ export function restoreProviderPaths(provider, descriptors) {
32
+ for (const key of Object.keys(provider.paths)) {
33
+ if (!(key in descriptors)) {
34
+ try { delete provider.paths[key]; } catch { /* keep operator-owned key */ }
35
+ }
36
+ }
37
+ for (const [key, descriptor] of Object.entries(descriptors)) {
38
+ try {
39
+ Object.defineProperty(provider.paths, key, descriptor);
40
+ } catch {
41
+ if (descriptor.set || descriptor.writable) provider.paths[key] = descriptor.value;
42
+ }
43
+ }
44
+ }
@@ -0,0 +1,146 @@
1
+ /** Discover and bind rule targets from indexed and currently deployed bundle sources. */
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import { importImpl } from '../../_resolve-impl.mjs';
5
+ import { contentHash } from './base.mjs';
6
+ const { RULE_BINDING_TYPES } = await importImpl(import.meta.url, 'rules/activation.mjs');
7
+
8
+ function isPackageSource(directory, root) {
9
+ return path.relative(root, directory).split(path.sep).slice(0, 2).join('/') === 'agentic/code';
10
+ }
11
+
12
+ function bindingBundleRoot(file, root) {
13
+ // Packaged contracts retain their established project/user override policy.
14
+ if (isPackageSource(file, root)) return undefined;
15
+ let directory = path.dirname(file);
16
+ while (path.dirname(directory) !== directory) {
17
+ if (['rules', 'behaviors'].includes(path.basename(directory))) return path.dirname(directory);
18
+ directory = path.dirname(directory);
19
+ }
20
+ return undefined;
21
+ }
22
+
23
+ export async function resolveDeliveryRuleBindings(opts, rules, configs, root, packageRelations) {
24
+ const bindings = new Map();
25
+ const targets = [];
26
+ const targetKeys = new Set();
27
+ if (rules.some(rule => Object.values(rule.bound_to).some(ids => ids.length))) {
28
+ const { loadLocalCapabilityEntries, loadLocalOverrideCapabilityEntries, createRuleBindingTargetResolver } = await importImpl(import.meta.url, 'artifacts/query-engine.js');
29
+ // Framework graph paths are package-relative; project graph paths belong
30
+ // to the queried project. Normalize before merging so one source cannot
31
+ // become two apparently ambiguous targets after a source-index rebuild.
32
+ const indexEntries = new Map();
33
+ const entryPaths = new Map();
34
+ const loadEntries = (cwd, overridesOnly = false) => (overridesOnly
35
+ ? loadLocalOverrideCapabilityEntries(cwd)
36
+ : loadLocalCapabilityEntries(cwd, undefined, indexEntries)).map(entry => {
37
+ const anchor = entry.path.startsWith('agentic/code/') ? root : cwd;
38
+ const key = `${anchor}\0${entry.path}`;
39
+ if (!entryPaths.has(key)) entryPaths.set(key, path.resolve(anchor, entry.path));
40
+ const resolvedPath = entryPaths.get(key);
41
+ // Canonical IDs hash the indexed package-relative path. Keep it through
42
+ // resolution; the selected target is anchored to root below.
43
+ return { ...entry, path: entry.path.startsWith('agentic/code/') ? entry.path
44
+ : opts.mapInputPath ? opts.mapInputPath(resolvedPath) : resolvedPath };
45
+ });
46
+ let rebuilt = false;
47
+ const cacheDir = process.env.AIWG_RULE_BINDING_INDEX_CACHE;
48
+ const cacheFile = cacheDir && path.join(cacheDir, `${contentHash(opts.logicalInputPath ? opts.logicalInputPath(root) : root)}.json`);
49
+ const buildSourceEntries = async (refresh = false) => {
50
+ if (!refresh && cacheFile) {
51
+ try { return JSON.parse(fs.readFileSync(cacheFile, 'utf8')).map(entry => ({ ...entry, path: path.isAbsolute(entry.path) && opts.mapInputPath ? opts.mapInputPath(entry.path) : entry.path })); }
52
+ catch (error) {
53
+ if (error.code !== 'ENOENT' && !(error instanceof SyntaxError)) throw error;
54
+ }
55
+ }
56
+ const { collectRuleBindingEntries } = await importImpl(import.meta.url, 'artifacts/index-builder.js');
57
+ const sourceEntries = await collectRuleBindingEntries(root,
58
+ root === opts.srcRoot && !fs.existsSync(path.join(root, 'agentic')) ? '.' : 'agentic/code');
59
+ rebuilt = true;
60
+ const entries = sourceEntries.map(entry => ({ ...entry, path: entry.path.startsWith('agentic/code/')
61
+ ? entry.path : path.resolve(root, entry.path) }));
62
+ if (cacheFile) {
63
+ fs.mkdirSync(cacheDir, { recursive: true });
64
+ // Workers may publish the same immutable source snapshot concurrently.
65
+ const temporary = `${cacheFile}.${process.pid}.tmp`;
66
+ fs.writeFileSync(temporary, JSON.stringify(entries.map(entry => ({ ...entry, path: opts.logicalInputPath ? opts.logicalInputPath(entry.path) : entry.path }))));
67
+ fs.renameSync(temporary, cacheFile);
68
+ }
69
+ return entries;
70
+ };
71
+ const localEntries = opts.bindingEntries || loadEntries(opts.target, Boolean(packageRelations));
72
+ let entries = [...localEntries];
73
+ if (!opts.bindingEntries) {
74
+ // The validated package table is authoritative for its exact source digest.
75
+ // Keep the canonical resolver for aliases, local overrides and ambiguity.
76
+ const sourceEntries = packageRelations
77
+ ? Object.values(packageRelations.index.artifacts).map(entry => ({ ...entry,
78
+ indexScope: 'packaged', indexGraph: 'framework' }))
79
+ : loadEntries(root);
80
+ // A relocated project graph may also be visible while querying the
81
+ // package root. Keep its project-anchored instance only.
82
+ const uniqueSources = sourceEntries.filter(entry => !(opts.sharedProjectGraph &&
83
+ entry.path.startsWith(path.join(root, '.aiwg') + path.sep) &&
84
+ localEntries.some(local => local.type === entry.type && local.name === entry.name)));
85
+ entries.push(...uniqueSources);
86
+ if (!sourceEntries.length) entries.push(...await buildSourceEntries());
87
+ }
88
+ // Include first-time invocations before their installed entry is persisted.
89
+ // Scan only selected bundle roots; use the existing metadata extractor without
90
+ // creating a full index or treating a stale project index as authoritative.
91
+ if (!opts.bindingEntries) {
92
+ const selectedRoots = new Set([opts.srcRoot, ...(opts.additionalSources || []),
93
+ ...rules.map(rule => bindingBundleRoot(rule.file, root)).filter(Boolean),
94
+ ...Object.values(configs.project.installed || {}).filter(entry => entry.localPath)
95
+ .map(entry => path.resolve(opts.target, entry.localPath))]);
96
+ const { collectRuleBindingEntries } = await importImpl(import.meta.url, 'artifacts/index-builder.js');
97
+ for (const localRoot of selectedRoots) {
98
+ if (localRoot === root || isPackageSource(localRoot, root) || !fs.existsSync(localRoot)) continue;
99
+ const scoped = (await collectRuleBindingEntries(localRoot, '.'))
100
+ .map(entry => ({ ...entry, path: path.resolve(localRoot, entry.path) }));
101
+ localEntries.push(...scoped);
102
+ entries.push(...scoped);
103
+ }
104
+ }
105
+ // A stored index can predate the source tree (edge/dev checkouts). Rebuild once from source
106
+ // before reporting a binding target as missing.
107
+ const resolvedTargets = new Map();
108
+ const identityOptions = { cwd: opts.target, packageRoot: root, logicalPath: opts.logicalInputPath };
109
+ let resolveBinding = createRuleBindingTargetResolver(entries, identityOptions);
110
+ const resolveTarget = async (type, id, bundleRoot) => {
111
+ const key = `${bundleRoot}:${type}:${id}`;
112
+ if (resolvedTargets.has(key)) return resolvedTargets.get(key);
113
+ let target;
114
+ try { target = resolveBinding(type, id, bundleRoot); }
115
+ catch (error) {
116
+ if (packageRelations || rebuilt || opts.bindingEntries || !/^Missing /.test(error.message)) throw error;
117
+ indexEntries.clear();
118
+ entryPaths.clear();
119
+ entries = [...localEntries, ...await buildSourceEntries(true)];
120
+ rebuilt = true;
121
+ resolveBinding = createRuleBindingTargetResolver(entries, identityOptions);
122
+ target = resolveBinding(type, id, bundleRoot);
123
+ // A rebuild replaces the input set for every lookup.
124
+ resolvedTargets.clear();
125
+ }
126
+ resolvedTargets.set(key, target);
127
+ return target;
128
+ };
129
+ for (const rule of rules.filter(rule => rule.tagged)) {
130
+ for (const [key, type] of Object.entries(RULE_BINDING_TYPES)) {
131
+ for (const id of rule.bound_to[key]) {
132
+ const target = await resolveTarget(type, id, bindingBundleRoot(rule.file, root));
133
+ const source = path.isAbsolute(target.path) ? target.path : path.resolve(target.path.startsWith('agentic/code/') ? root : opts.target, target.path);
134
+ if (!fs.existsSync(source)) throw new Error(`${rule.file}: binding target content missing: ${source}`);
135
+ bindings.set(source, [...(bindings.get(source) || []), rule]);
136
+ const key = `${target.type}:${source}`;
137
+ if (!targetKeys.has(key)) {
138
+ targetKeys.add(key);
139
+ targets.push({ ...target, source });
140
+ }
141
+ }
142
+ }
143
+ }
144
+ }
145
+ return { bindings, targets };
146
+ }