@aiwg/cli 2026.10.12 → 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 (56) hide show
  1. package/agentic/code/providers/pi/aiwg-bridge.ts +44 -1
  2. package/dist/src/cli/handlers/use-bundle-counts.js +32 -6
  3. package/dist/src/cli/handlers/use-skill-assets.js +207 -0
  4. package/dist/src/cli/handlers/use.js +30 -193
  5. package/dist/src/config/authorization-cli.js +11 -3
  6. package/dist/src/decision/context-pruning-common.js +41 -0
  7. package/dist/src/decision/context-pruning-evaluation.js +366 -0
  8. package/dist/src/decision/context-pruning-pilot.js +431 -0
  9. package/dist/src/decision/context-pruning-types.js +19 -0
  10. package/dist/src/decision/context-pruning.js +5 -847
  11. package/dist/src/decision/ensemble/contract.js +4 -24
  12. package/dist/src/decision/qualification/release.js +5 -62
  13. package/dist/src/extensions/manifest.js +8 -1
  14. package/dist/src/extensions/project-local-doctor.js +78 -2
  15. package/dist/src/extensions/validation.js +10 -11
  16. package/dist/src/gates/evaluate.js +3 -13
  17. package/dist/src/gates/upstream-ceiling.js +111 -0
  18. package/dist/src/models/provider-models.js +5 -8
  19. package/dist/src/models/wrapper-definitions.js +14 -0
  20. package/dist/src/models/wrapper-deployment.js +48 -25
  21. package/dist/src/models/wrapper-enforcement.js +72 -0
  22. package/dist/src/policy/hitl-check.js +80 -0
  23. package/dist/src/rules/activation.d.mts +2 -0
  24. package/dist/src/rules/activation.mjs +23 -0
  25. package/dist/src/skills/adapters/local.js +32 -9
  26. package/dist/src/skills/agent-skills.js +2 -0
  27. package/dist/src/skills/cli-display.js +33 -0
  28. package/dist/src/skills/cli.js +2 -26
  29. package/dist/src/skills/collision-discovery.js +84 -0
  30. package/dist/src/skills/deployer.js +20 -75
  31. package/dist/src/skills/deployment-ownership.js +74 -0
  32. package/dist/src/skills/doctor.js +2 -2
  33. package/dist/src/skills/importer.js +4 -26
  34. package/dist/src/skills/registry.js +22 -7
  35. package/dist/src/smiths/context-pipeline/parallelism-section.js +7 -3
  36. package/package.json +3 -1
  37. package/tools/agents/providers/antigravity.mjs +3 -5
  38. package/tools/agents/providers/base.mjs +3 -3
  39. package/tools/agents/providers/claude.mjs +3 -5
  40. package/tools/agents/providers/codex.mjs +3 -5
  41. package/tools/agents/providers/copilot.mjs +3 -5
  42. package/tools/agents/providers/cursor.mjs +3 -5
  43. package/tools/agents/providers/factory.mjs +3 -5
  44. package/tools/agents/providers/grok-build.mjs +9 -7
  45. package/tools/agents/providers/model-wrapper.mjs +86 -0
  46. package/tools/agents/providers/omp.mjs +3 -1
  47. package/tools/agents/providers/openclaw.mjs +3 -5
  48. package/tools/agents/providers/opencode.mjs +3 -5
  49. package/tools/agents/providers/provider-paths-staging.mjs +9 -0
  50. package/tools/agents/providers/rule-delivery.mjs +4 -4
  51. package/tools/agents/providers/warp.mjs +3 -5
  52. package/tools/agents/providers/windsurf.mjs +3 -5
  53. package/tools/plugin/package-plugins.mjs +2 -2
  54. package/tools/skills/codex-skill-transform.mjs +232 -0
  55. package/tools/skills/deploy-skills-codex.mjs +8 -249
  56. package/tools/warp/warp-content.mjs +548 -0
@@ -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
@@ -1,4 +1,13 @@
1
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
+
2
11
  export function captureProviderPathDescriptors(provider) {
3
12
  return Object.getOwnPropertyDescriptors(provider.paths);
4
13
  }
@@ -12,7 +12,7 @@ import {
12
12
  addManagedMarker, contentHash, replaceBoundRulesBlock, deployEmulatedBehaviors, filterAgentFiles,
13
13
  } from './base.mjs';
14
14
 
15
- const { parseRuleFrontmatter, inferRuleActivation, readCoreBody, validateCoreSet, CORE_RULES_START, CORE_RULES_END } = await importImpl(import.meta.url, 'rules/activation.mjs');
15
+ const { parseRuleFrontmatter, inferRuleActivation, readCoreBody, validateCoreSet, formatRuleFrontmatterError, CORE_RULES_START, CORE_RULES_END } = await importImpl(import.meta.url, 'rules/activation.mjs');
16
16
  const { resolveDeployVersion } = await importImpl(import.meta.url, 'providers/deploy-version.mjs');
17
17
  const { trackTemporaryDirectory } = await importImpl(import.meta.url, 'utils/temporary-directory.js');
18
18
  const { loadRulePinConfigs, installedRuleCapabilities, resolveRulePins } = await importImpl(import.meta.url, 'rules/pins.mjs');
@@ -20,7 +20,7 @@ const { guardRulesInlineBudget } = await importImpl(import.meta.url, 'rules/inli
20
20
  const { userConfigFile } = await importImpl(import.meta.url, 'config/user-config-dir.mjs');
21
21
  const { resolveProjectAiwgDir } = await importImpl(import.meta.url, 'config/project-artifacts-runtime.mjs');
22
22
  import { writeContextFileSync, CONTEXT_STAGE_ENV } from './context-write.mjs';
23
- import { captureProviderPathDescriptors, setStagedProviderPath, restoreProviderPaths } from './provider-paths-staging.mjs';
23
+ import { captureProviderPathDescriptors, setStagedProviderPath, restoreProviderPaths, logicalProviderOutputPath } from './provider-paths-staging.mjs';
24
24
  import { resolveDeliveryRuleBindings } from './rule-binding-targets.mjs';
25
25
  import { projectOnDemandReferences, renderRuleKernelIndex } from './rule-presentation.mjs';
26
26
  export { renderRuleKernelIndex } from './rule-presentation.mjs';
@@ -135,7 +135,7 @@ export async function prepareRuleDelivery(opts) {
135
135
  const rules = collectDeploymentRuleSources(opts).map(file => {
136
136
  const content = fs.readFileSync(file, 'utf8');
137
137
  const parsed = parseRuleFrontmatter(content);
138
- if (!parsed.valid) throw new Error(`${file}: ${parsed.diagnostics.map(d => d.message).join('; ')}`);
138
+ if (!parsed.valid) throw new Error(formatRuleFrontmatterError(opts.logicalInputPath ? opts.logicalInputPath(file) : file, parsed.data, parsed.diagnostics));
139
139
  const behavior = path.basename(file) === 'BEHAVIOR.md';
140
140
  const rule = { ...parsed.rule, file, content, body: parsed.body, behavior,
141
141
  name: behavior ? `behavior/${path.basename(path.dirname(file))}` : parsed.data.name || path.basename(file, '.md') };
@@ -1116,7 +1116,7 @@ export async function prepareRuleDeployment(original, provider, deploy) {
1116
1116
  }
1117
1117
  delivery.bindings = remappedBindings;
1118
1118
  preimages.push(...snapshotPreimages([...delivery.rules.map(rule => rule.file), ...delivery.targets.map(entry => entry.source), path.join(target, '.aiwg', 'aiwg.config')]));
1119
- const opts = { ...original, target: stage, dryRun: false, ruleDelivery: delivery,
1119
+ const opts = { ...original, target: stage, dryRun: false, ruleDelivery: delivery, logicalOutputPath: file => logicalProviderOutputPath(file, stage, target, mappings),
1120
1120
  kernelSkillsPath: kernel, deploymentHome: home, activeWorkspace, hermesLegacySkills, legacyCodexSkills, staging: true };
1121
1121
  await deploySelectedSurface(opts, provider, deploy);
1122
1122
  if (!opts.commandsOnly && !opts.skillsOnly && !opts.rulesOnly && opts.deployBehaviors !== false) {
@@ -1,3 +1,4 @@
1
+ import { withModelWrapper } from './model-wrapper.mjs';
1
2
  import { importImpl } from '../../_resolve-impl.mjs';
2
3
  /**
3
4
  * Warp Terminal Provider
@@ -20,7 +21,6 @@ import { importImpl } from '../../_resolve-impl.mjs';
20
21
  * - Backup creation with timestamp
21
22
  * - CLAUDE.md symlink support
22
23
  */
23
-
24
24
  import realFs from 'fs';
25
25
  import { createRequire } from 'module';
26
26
  const _require = createRequire(import.meta.url);
@@ -48,13 +48,10 @@ import {
48
48
  normalizeDeploymentMode,
49
49
  collectFrameworkArtifacts
50
50
  } from './base.mjs';
51
-
52
51
  import { writeContextFileSync } from './context-write.mjs';
53
-
54
52
  // ============================================================================
55
53
  // Provider Configuration
56
54
  // ============================================================================
57
-
58
55
  export const name = 'warp';
59
56
  export const aliases = [];
60
57
 
@@ -141,7 +138,8 @@ export function mapModel(shorthand, modelCfg, modelsConfig) {
141
138
  /**
142
139
  * Transform agent content for Warp
143
140
  */
144
- export function transformAgent(srcPath, content, opts) {
141
+ export const transformAgent = withModelWrapper('warp', translateAgent);
142
+ function translateAgent(srcPath, content, opts) {
145
143
  const { reasoningModel, codingModel, efficiencyModel } = opts;
146
144
 
147
145
  // Only transform if model overrides specified
@@ -1,3 +1,4 @@
1
+ import { withModelWrapper } from './model-wrapper.mjs';
1
2
  import { importImpl } from '../../_resolve-impl.mjs';
2
3
  /**
3
4
  * Devin Desktop Provider (Windsurf compatibility adapter)
@@ -23,7 +24,6 @@ import { importImpl } from '../../_resolve-impl.mjs';
23
24
  * - Conventional skills and rules deployment
24
25
  * - Devin Desktop selectors resolve to the stable `windsurf` provider id
25
26
  */
26
-
27
27
  import realFs from 'fs';
28
28
  import { createRequire } from 'module';
29
29
  const _require = createRequire(import.meta.url);
@@ -55,13 +55,10 @@ import {
55
55
  filterCommandsAgainstSkills,
56
56
  deploySoulCompanions
57
57
  } from './base.mjs';
58
-
59
58
  import { writeContextFileSync } from './context-write.mjs';
60
-
61
59
  // ============================================================================
62
60
  // Provider Configuration
63
61
  // ============================================================================
64
-
65
62
  export const name = 'windsurf';
66
63
  export const aliases = ['devin', 'devin-desktop', 'devin-local', 'cascade'];
67
64
 
@@ -98,7 +95,8 @@ export const capabilities = {
98
95
  /**
99
96
  * Transform agent content to Windsurf format (plain markdown, no YAML frontmatter)
100
97
  */
101
- export function transformAgent(srcPath, content, opts) {
98
+ export const transformAgent = withModelWrapper('windsurf', translateAgent);
99
+ function translateAgent(srcPath, content, opts) {
102
100
  const fmMatch = content.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
103
101
  if (!fmMatch) return content;
104
102
 
@@ -227,7 +227,6 @@ Writing quality validation and AI pattern detection.
227
227
  - Discord: https://discord.gg/BuAusFMxdA
228
228
  `
229
229
  },
230
-
231
230
  'utils': {
232
231
  name: 'utils',
233
232
  displayName: 'AIWG Utilities',
@@ -240,7 +239,8 @@ Writing quality validation and AI pattern detection.
240
239
  extraCopy: [
241
240
  { from: 'agentic/code/addons/aiwg-utils/rules/skill-discovery.md', to: 'rules/skill-discovery.md' },
242
241
  { from: 'agentic/code/addons/aiwg-utils/rules/skill-discovery-guidance.md', to: 'rules/skill-discovery-guidance.md' },
243
- { from: 'agentic/code/addons/aiwg-utils/rules/cli-secondary.md', to: 'rules/cli-secondary.md' }
242
+ { from: 'agentic/code/addons/aiwg-utils/rules/cli-secondary.md', to: 'rules/cli-secondary.md' },
243
+ { from: 'agentic/code/addons/aiwg-utils/templates/subagent-brief.md', to: 'templates/subagent-brief.md' }
244
244
  ],
245
245
  readme: `# AIWG Utilities
246
246
 
@@ -0,0 +1,232 @@
1
+ // Transform AIWG skill instructions and metadata for Codex deployment.
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import { skillMatchesProvider } from '../agents/providers/base.mjs';
5
+
6
+ const MAX_NAME_LENGTH = 100;
7
+ const MAX_DESCRIPTION_LENGTH = 500;
8
+
9
+ export function stripWrappingQuotes(value) {
10
+ const trimmed = String(value ?? '').trim();
11
+ if (
12
+ (trimmed.startsWith('"') && trimmed.endsWith('"')) ||
13
+ (trimmed.startsWith("'") && trimmed.endsWith("'"))
14
+ ) {
15
+ return trimmed.slice(1, -1);
16
+ }
17
+ return trimmed;
18
+ }
19
+
20
+ function yamlDoubleQuoted(value) {
21
+ return String(value ?? '')
22
+ .replace(/\\/g, '\\\\')
23
+ .replace(/"/g, '\\"')
24
+ .replace(/\r?\n/g, ' ')
25
+ .trim();
26
+ }
27
+
28
+ function codexDisplayName(skillName) {
29
+ const acronyms = new Map([
30
+ ['aiwg', 'AIWG'],
31
+ ['dfir', 'DFIR'],
32
+ ['sdlc', 'SDLC'],
33
+ ['mcp', 'MCP'],
34
+ ['pr', 'PR'],
35
+ ]);
36
+
37
+ return String(skillName)
38
+ .split('-')
39
+ .filter(Boolean)
40
+ .map((part) => acronyms.get(part.toLowerCase()) || part.charAt(0).toUpperCase() + part.slice(1))
41
+ .join(' ');
42
+ }
43
+
44
+ function codexOpenAiMetadata(skill) {
45
+ return `interface:
46
+ display_name: "${yamlDoubleQuoted(codexDisplayName(skill.name))}"
47
+ short_description: "${yamlDoubleQuoted(skill.description)}"
48
+ `;
49
+ }
50
+
51
+ function resolveSkillModelPolicy(frontmatter) {
52
+ const block = frontmatter.match(/^commandHint:\s*\n((?:[ \t]+[^\n]*\n?)*)/m)?.[1] || '';
53
+ const hint = {};
54
+ for (const line of block.split('\n')) {
55
+ const match = line.trim().match(/^(model|modelRole|modelTier|modelEffort|modelRationale):\s*(.+)$/);
56
+ if (match) hint[match[1]] = stripWrappingQuotes(match[2]);
57
+ }
58
+ const legacy = String(hint.model || '').toLowerCase();
59
+ const role = hint.modelRole || (legacy === 'opus' ? 'reasoning'
60
+ : legacy === 'haiku' ? 'efficiency' : legacy ? 'coding' : null);
61
+ if (!role) return null;
62
+ return {
63
+ role,
64
+ tier: hint.modelTier || (role === 'reasoning' ? 'premium'
65
+ : role === 'efficiency' ? 'economy' : 'standard'),
66
+ effort: hint.modelEffort,
67
+ rationale: hint.modelRationale,
68
+ };
69
+ }
70
+
71
+ /**
72
+ * Parse AIWG SKILL.md - handles both frontmatter and non-frontmatter formats
73
+ */
74
+ function parseSkillContent(content, skillName) {
75
+ // Try YAML frontmatter format first
76
+ const fmMatch = content.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
77
+ if (fmMatch) {
78
+ const [, frontmatter, body] = fmMatch;
79
+ const metadata = {};
80
+
81
+ // Parse YAML-like frontmatter
82
+ for (const line of frontmatter.split('\n')) {
83
+ const colonIdx = line.indexOf(':');
84
+ if (colonIdx > 0) {
85
+ const key = line.slice(0, colonIdx).trim();
86
+ const value = line.slice(colonIdx + 1).trim();
87
+ metadata[key] = stripWrappingQuotes(value);
88
+ }
89
+ }
90
+
91
+ return { metadata, body, modelPolicy: resolveSkillModelPolicy(frontmatter) };
92
+ }
93
+
94
+ // Fallback: Parse non-frontmatter format (# skill-name header)
95
+ const lines = content.split('\n');
96
+ let name = skillName;
97
+ let description = '';
98
+ let bodyStartIdx = 0;
99
+
100
+ // Look for # header as name
101
+ for (let i = 0; i < lines.length; i++) {
102
+ const line = lines[i].trim();
103
+ if (line.startsWith('# ')) {
104
+ name = line.slice(2).trim();
105
+ bodyStartIdx = i + 1;
106
+ break;
107
+ }
108
+ }
109
+
110
+ // Look for first paragraph as description (skip empty lines)
111
+ for (let i = bodyStartIdx; i < lines.length; i++) {
112
+ const line = lines[i].trim();
113
+ if (
114
+ line &&
115
+ !line.endsWith(':') &&
116
+ !line.startsWith('#') &&
117
+ !line.startsWith('-') &&
118
+ !line.startsWith('|')
119
+ ) {
120
+ description = line;
121
+ break;
122
+ }
123
+ }
124
+
125
+ // If description is too short, try next paragraph
126
+ if (description.length < 20) {
127
+ for (let i = bodyStartIdx; i < lines.length; i++) {
128
+ const line = lines[i].trim();
129
+ if (line.startsWith('## ') && line.toLowerCase().includes('purpose')) {
130
+ // Look for content after ## Purpose
131
+ for (let j = i + 1; j < lines.length && j < i + 10; j++) {
132
+ const purposeLine = lines[j].trim();
133
+ if (purposeLine && !purposeLine.startsWith('#') && !purposeLine.startsWith('-')) {
134
+ description = purposeLine;
135
+ break;
136
+ }
137
+ }
138
+ break;
139
+ }
140
+ }
141
+ }
142
+
143
+ return {
144
+ metadata: { name, description },
145
+ body: content
146
+ };
147
+ }
148
+
149
+ /**
150
+ * Transform AIWG skill to Codex format
151
+ */
152
+ export function transformToCodexSkill(skillDir) {
153
+ const skillPath = path.join(skillDir, 'SKILL.md');
154
+ const skillName = path.basename(skillDir);
155
+ const content = fs.readFileSync(skillPath, 'utf8');
156
+
157
+ // Platform filtering: skip skills with explicit restrictions that exclude codex.
158
+ // Skills using platforms: [all] (the standard token) always pass this check.
159
+ if (!skillMatchesProvider(content, 'codex')) {
160
+ return null;
161
+ }
162
+
163
+ const parsed = parseSkillContent(content, skillName);
164
+
165
+ if (!parsed) {
166
+ console.warn(`Warning: Could not parse ${skillPath}`);
167
+ return null;
168
+ }
169
+
170
+ const { metadata, body, modelPolicy } = parsed;
171
+
172
+ // Validate and truncate
173
+ const name = (metadata.name || path.basename(skillDir)).slice(0, MAX_NAME_LENGTH);
174
+ let description = metadata.description || '';
175
+
176
+ // Codex REQUIRES a non-empty description — it rejects SKILL.md files that
177
+ // lack one. Fail loudly rather than silently writing `description: ""`
178
+ // (the exact regression this guard defends against).
179
+ if (!description || !String(description).trim()) {
180
+ console.error(
181
+ `ERROR: Skill '${name}' has empty/missing description in source ${skillPath}`
182
+ );
183
+ console.error(
184
+ ` Codex rejects SKILL.md files without a description field.`
185
+ );
186
+ console.error(
187
+ ` Fix the source file: add a non-empty 'description:' to the frontmatter.`
188
+ );
189
+ return null;
190
+ }
191
+
192
+ // Truncate description to 500 chars, ending at word boundary
193
+ if (description.length > MAX_DESCRIPTION_LENGTH) {
194
+ description = description.slice(0, MAX_DESCRIPTION_LENGTH - 3);
195
+ const lastSpace = description.lastIndexOf(' ');
196
+ if (lastSpace > MAX_DESCRIPTION_LENGTH - 50) {
197
+ description = description.slice(0, lastSpace);
198
+ }
199
+ description += '...';
200
+ }
201
+
202
+ // Final guard: never emit `description: ""` under any circumstance.
203
+ const quotedDescription = yamlDoubleQuoted(description);
204
+ if (!quotedDescription || !quotedDescription.trim()) {
205
+ console.error(
206
+ `ERROR: Skill '${name}' description collapsed to empty after normalization (source: ${skillPath})`
207
+ );
208
+ return null;
209
+ }
210
+
211
+ // Build Codex skill format — include platforms: [codex] so deployed skills are self-describing
212
+ const codexContent = `---
213
+ name: "${yamlDoubleQuoted(name)}"
214
+ description: "${quotedDescription}"
215
+ platforms: [codex]
216
+ ---
217
+
218
+ ${modelPolicy
219
+ ? `<!-- aiwg:model-policy role=${modelPolicy.role} tier=${modelPolicy.tier}${modelPolicy.effort ? ` effort=${modelPolicy.effort}` : ''} outcome=unsupported${modelPolicy.rationale ? ` rationale=${yamlDoubleQuoted(modelPolicy.rationale)}` : ''} -->\n\n`
220
+ : ''}${body.trim()}
221
+ `;
222
+
223
+ return {
224
+ name,
225
+ description,
226
+ content: codexContent,
227
+ metadataContent: codexOpenAiMetadata({ name, description }),
228
+ sourcePath: skillPath,
229
+ modelPolicy,
230
+ };
231
+ }
232
+