@aiwg/cli 2026.10.19 → 2026.11.1

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 (143) hide show
  1. package/README.md +1 -0
  2. package/agentic/code/providers/flue/README.md +2 -1
  3. package/dist/src/artifacts/cli.js +3 -2
  4. package/dist/src/artifacts/discover-facets.js +2 -0
  5. package/dist/src/artifacts/discover-session-facets.js +14 -0
  6. package/dist/src/artifacts/fortemi-core-query-adapter.js +4 -4
  7. package/dist/src/artifacts/framework-capabilities.js +7 -3
  8. package/dist/src/artifacts/index-builder.js +2 -3
  9. package/dist/src/artifacts/query-engine-discover-output.js +3 -3
  10. package/dist/src/artifacts/query-engine-discover.js +61 -14
  11. package/dist/src/artifacts/query-engine-entries.js +52 -9
  12. package/dist/src/artifacts/query-engine-installation.js +27 -0
  13. package/dist/src/artifacts/query-engine-rules.js +1 -2
  14. package/dist/src/artifacts/query-engine-scoring.js +33 -31
  15. package/dist/src/artifacts/query-engine-show-card.js +6 -2
  16. package/dist/src/artifacts/query-engine-show.js +2 -2
  17. package/dist/src/artifacts/relations.js +17 -10
  18. package/dist/src/cli/handlers/bundle-declaration.js +55 -0
  19. package/dist/src/cli/handlers/bundle-deployment-mode.js +71 -0
  20. package/dist/src/cli/handlers/bundle-hash-prune.js +37 -0
  21. package/dist/src/cli/handlers/bundle-reconciliation.js +140 -0
  22. package/dist/src/cli/handlers/checkpoint.js +143 -0
  23. package/dist/src/cli/handlers/help.js +1 -0
  24. package/dist/src/cli/handlers/index.js +4 -2
  25. package/dist/src/cli/handlers/models-resource-sample.js +7 -3
  26. package/dist/src/cli/handlers/ralph-launcher.js +1 -1
  27. package/dist/src/cli/handlers/refresh-bundles.js +35 -0
  28. package/dist/src/cli/handlers/refresh-rule-inventory.js +10 -0
  29. package/dist/src/cli/handlers/refresh.js +15 -52
  30. package/dist/src/cli/handlers/remove-bundled.js +7 -4
  31. package/dist/src/cli/handlers/remove-flue-modules.js +19 -0
  32. package/dist/src/cli/handlers/remove-historical-bundle.js +18 -0
  33. package/dist/src/cli/handlers/remove.js +8 -0
  34. package/dist/src/cli/handlers/script-runner.js +12 -1
  35. package/dist/src/cli/handlers/steward-signing.js +44 -0
  36. package/dist/src/cli/handlers/steward.js +5 -0
  37. package/dist/src/cli/handlers/subcommands-list-format.js +4 -4
  38. package/dist/src/cli/handlers/update.js +18 -8
  39. package/dist/src/cli/handlers/use-additive-bundles.js +87 -0
  40. package/dist/src/cli/handlers/use-bundle-counts.js +5 -1
  41. package/dist/src/cli/handlers/use-owned-counts.js +75 -0
  42. package/dist/src/cli/handlers/use-provider-results.js +17 -0
  43. package/dist/src/cli/handlers/use.js +53 -114
  44. package/dist/src/cli/router.js +12 -2
  45. package/dist/src/cli/services/deployment-verification.js +2 -1
  46. package/dist/src/cli/user-scope-mirror.js +3 -1
  47. package/dist/src/config/aiwg-config.js +15 -6
  48. package/dist/src/config/cli.js +1 -0
  49. package/dist/src/config/delivery-validation.js +21 -0
  50. package/dist/src/config/framework-aliases.js +14 -0
  51. package/dist/src/config/host-resource-report.d.mts +1 -1
  52. package/dist/src/config/host-resource-report.mjs +23 -4
  53. package/dist/src/config/host-resource-runtime.d.mts +8 -0
  54. package/dist/src/config/host-resource-runtime.mjs +67 -24
  55. package/dist/src/config/index-graph-overrides.js +4 -0
  56. package/dist/src/config/installed-selection.js +9 -1
  57. package/dist/src/config/installed-validation.js +35 -0
  58. package/dist/src/config/worker-attribution.d.mts +7 -0
  59. package/dist/src/config/worker-attribution.mjs +44 -0
  60. package/dist/src/delivery/git.js +62 -0
  61. package/dist/src/delivery/pr.js +149 -0
  62. package/dist/src/delivery/tracker.js +33 -0
  63. package/dist/src/discovery/interview.js +1 -1
  64. package/dist/src/extensions/claude-hooks-installer.js +1 -0
  65. package/dist/src/extensions/loader.js +2 -1
  66. package/dist/src/extensions/project-local-doctor.js +1 -1
  67. package/dist/src/extensions/project-local-remove.js +3 -3
  68. package/dist/src/issues/cli.js +12 -3
  69. package/dist/src/issues/external-cli.js +76 -0
  70. package/dist/src/issues/live.js +18 -1
  71. package/dist/src/issues/tracker-policy.js +17 -0
  72. package/dist/src/mcp/cli.mjs +12 -7
  73. package/dist/src/mcp/helpers.mjs +5 -1
  74. package/dist/src/mcp/http-options.mjs +101 -0
  75. package/dist/src/mcp/http-tools.mjs +51 -0
  76. package/dist/src/mcp/http-transport.mjs +201 -0
  77. package/dist/src/mcp/server.mjs +9 -7
  78. package/dist/src/mcp/tool-context.mjs +25 -0
  79. package/dist/src/mcp/tools/orchestration.mjs +2 -1
  80. package/dist/src/mcp/tools/worker-invoke.mjs +2 -1
  81. package/dist/src/mcp/tools/worker-stdin-runtime.mjs +12 -0
  82. package/dist/src/models/conductor-data-policy.d.mts +3 -2
  83. package/dist/src/models/conductor-data-policy.mjs +94 -5
  84. package/dist/src/models/worker-plan.js +3 -3
  85. package/dist/src/models/worker-selection-policy.js +2 -1
  86. package/dist/src/providers/deployment-lock.js +77 -0
  87. package/dist/src/providers/deployment-ownership.d.mts +12 -2
  88. package/dist/src/providers/deployment-ownership.mjs +127 -19
  89. package/dist/src/providers/deployment-preservation.d.mts +6 -0
  90. package/dist/src/providers/deployment-preservation.mjs +113 -0
  91. package/dist/src/providers/deployment-removal.js +4 -2
  92. package/dist/src/providers/flue-package-mode.js +19 -0
  93. package/dist/src/providers/provider-definitions.js +4 -0
  94. package/dist/src/providers/skill-ownership.mjs +1 -0
  95. package/dist/src/research/reference-match.js +4 -0
  96. package/dist/src/serve/worker-invocation-preparation.js +3 -1
  97. package/dist/src/serve/worker-invocation.js +2 -0
  98. package/dist/src/skills/run.js +5 -0
  99. package/dist/src/smiths/hook-bridge/codex-translator.js +3 -1
  100. package/dist/src/smiths/hook-bridge/hermes-translator.js +3 -1
  101. package/dist/src/smiths/hook-bridge/prompt-discovery-gaps.js +6 -0
  102. package/package.json +5 -2
  103. package/schemas/models/model-config-compatibility.v1.schema.json +4 -0
  104. package/tools/agents/deploy-agents.mjs +21 -1
  105. package/tools/agents/deploy-options.mjs +2 -0
  106. package/tools/agents/providers/base-contract.mjs +7 -1
  107. package/tools/agents/providers/base-inventory.mjs +41 -14
  108. package/tools/agents/providers/base-kernel-skills.mjs +9 -5
  109. package/tools/agents/providers/base-migrations.mjs +1 -0
  110. package/tools/agents/providers/base-skill-copy.mjs +9 -1
  111. package/tools/agents/providers/base.mjs +1 -1
  112. package/tools/agents/providers/claude.mjs +2 -1
  113. package/tools/agents/providers/codex.mjs +5 -1
  114. package/tools/agents/providers/conductor-data-guard.mjs +35 -11
  115. package/tools/agents/providers/flue-bundles.mjs +42 -0
  116. package/tools/agents/providers/flue-cloudflare.mjs +20 -0
  117. package/tools/agents/providers/flue-project.mjs +45 -6
  118. package/tools/agents/providers/flue-skill-copy.mjs +25 -0
  119. package/tools/agents/providers/flue-skills.mjs +45 -0
  120. package/tools/agents/providers/flue-specialists.mjs +36 -18
  121. package/tools/agents/providers/flue-validation.mjs +14 -0
  122. package/tools/agents/providers/flue.mjs +12 -8
  123. package/tools/agents/providers/hermes-skill-lifecycle.mjs +1 -0
  124. package/tools/agents/providers/muse-hooks.mjs +4 -0
  125. package/tools/agents/providers/muse-prompt-discovery.mjs +22 -0
  126. package/tools/agents/providers/provider-prepare-coordinator.mjs +15 -10
  127. package/tools/agents/providers/rule-delivery-surface.mjs +18 -1
  128. package/tools/agents/providers/rule-deployment-commit.mjs +24 -0
  129. package/tools/agents/providers/rule-deployment-prepare.mjs +4 -0
  130. package/tools/agents/providers/skill-copy-prune.mjs +49 -0
  131. package/tools/agents/providers/stale-artifact-prune.mjs +10 -8
  132. package/tools/ralph-external/lib/worker-capture.mjs +157 -0
  133. package/tools/ralph-external/lib/worker-health.mjs +3 -0
  134. package/tools/ralph-external/lib/worker-invocation-processes.mjs +9 -6
  135. package/tools/ralph-external/lib/worker-launch-cli.mjs +10 -1
  136. package/tools/ralph-external/lib/worker-process-identity.mjs +30 -0
  137. package/tools/ralph-external/lib/worker-retry-evidence.mjs +87 -6
  138. package/tools/ralph-external/lib/worker-termination.mjs +56 -6
  139. package/tools/ralph-external/process-monitor.mjs +12 -18
  140. package/tools/ralph-external/session-launcher.mjs +43 -29
  141. package/tools/skills/codex-skill-metadata.mjs +22 -0
  142. package/tools/skills/deploy-skills-codex.mjs +8 -7
  143. package/vscode-extension/schemas/aiwg.config.v1.json +59 -19
@@ -110,6 +110,8 @@ export function parseArgs(args = process.argv.slice(2)) {
110
110
  else if (a === '--skip-commands-migration') cfg.skipCommandsMigration = true;
111
111
  // Structural opt-out: skip the migration without claiming the operator declined it (#2541).
112
112
  else if (a === '--no-commands-warning') cfg.warnOnSkippedCommandsMigration = false;
113
+ else if (a === '--index-mode') cfg.indexMode = true; // internal: forced local copies still use index cleanup
114
+ else if (a === '--package') cfg.fluePackage = true;
113
115
  else if (a === '--copy-all' || a === '--copy-standard-skills') cfg.copyStandardSkills = true;
114
116
  // #228: Muse provider — explicit opt-in MCP settings profile, and the
115
117
  // managed-hooks opt-out (default on, mirroring the Claude autoInstall policy).
@@ -1,5 +1,6 @@
1
1
  // Shared provider contract utilities.
2
2
  import { path } from './base-runtime.mjs';
3
+ import { importImpl } from '../../_resolve-impl.mjs';
3
4
 
4
5
 
5
6
  // ============================================================================
@@ -110,7 +111,12 @@ export function injectBoundRules(content, source, opts = {}) {
110
111
  * kernel passes leave rule delivery to the final source in the invocation. */
111
112
  export async function withRuleDeployment(opts, provider, deploy) {
112
113
  if (opts.kernelOnly && opts.deferRuleProjection && provider.name !== 'warp'
113
- && !globalThis[Symbol.for('aiwg.provider-preparation-hook.v1')]) return deploy(opts);
114
+ && !globalThis[Symbol.for('aiwg.provider-preparation-hook.v1')]) {
115
+ const shared = [...Object.values(provider.paths), provider.kernelSkillsPath].some(dir => dir && path.isAbsolute(dir));
116
+ if (!shared || opts.dryRun) return deploy(opts);
117
+ const { withProviderDeploymentLock } = await importImpl(import.meta.url, 'providers/deployment-lock.js');
118
+ return withProviderDeploymentLock(() => deploy(opts));
119
+ }
114
120
  const { deployWithRuleDelivery } = await import('./rule-delivery.mjs');
115
121
  return deployWithRuleDelivery(opts, provider, deploy);
116
122
  }
@@ -1,9 +1,9 @@
1
1
  // Shared provider inventory utilities.
2
- import { fs, path } from './base-runtime.mjs';
2
+ import { extractFrameworkSlug, fs, path } from './base-runtime.mjs';
3
3
  import { collectFrameworkArtifacts } from './base-framework-discovery.mjs';
4
4
  import { getAddonAgentFiles, getAddonCommandFiles } from './base-addon-discovery.mjs';
5
5
  import { getAddonRuleFiles } from './base-rule-index.mjs';
6
- import { MANAGED_MARKER_RE, MANIFEST_FILENAME, readSidecarManifest, writeSidecarManifest } from './base-files.mjs';
6
+ import { contentHash, MANAGED_MARKER_RE, MANIFEST_FILENAME, readSidecarManifest, writeSidecarManifest } from './base-files.mjs';
7
7
 
8
8
 
9
9
  // ============================================================================
@@ -40,8 +40,9 @@ export function artifactStem(name) {
40
40
  * deliberate and mirrors `computeAllKernelNames` for skills: `aiwg use sdlc`
41
41
  * must not prune a marketing agent that a prior `aiwg use all` deployed and
42
42
  * that is still a valid AIWG artifact. Only artifacts whose source no longer
43
- * exists ANYWHERE in the tree (renamed/removed) fall out of this set and
44
- * become prune-eligible.
43
+ * exists ANYWHERE in the tree (renamed/removed) fall out of this set.
44
+ * Receipts with bundle identity use the owner inventory instead, so an
45
+ * unrelated bundle's same-named artifact cannot hide a retired artifact.
45
46
  *
46
47
  * Anchors to the AIWG root (resolved by walking up from `srcRoot` for the
47
48
  * `agentic/code/frameworks` + `agentic/code/addons` pair, or `AIWG_ROOT`),
@@ -57,12 +58,25 @@ export function artifactStem(name) {
57
58
  * if the AIWG framework/addon tree can't be located
58
59
  */
59
60
  export function computeAllArtifactBasenames(srcRoot, type) {
61
+ return computeArtifactInventory(srcRoot, type)?.stems ?? null;
62
+ }
63
+
64
+ /** Global and per-bundle stems from the same mode-independent discovery pass. */
65
+ export function computeArtifactInventory(srcRoot, type) {
60
66
  const aiwgRoot = resolveAiwgRoot(srcRoot);
61
67
  if (!aiwgRoot) return null;
62
68
 
63
69
  const stems = new Set();
70
+ const ownerStems = new Map();
64
71
  const add = (files) => {
65
- for (const f of files) stems.add(artifactStem(path.basename(f)));
72
+ for (const f of files) {
73
+ const stem = artifactStem(path.basename(f));
74
+ stems.add(stem);
75
+ const owner = extractFrameworkSlug(f);
76
+ if (!owner) continue;
77
+ if (!ownerStems.has(owner)) ownerStems.set(owner, new Set());
78
+ ownerStems.get(owner).add(stem);
79
+ }
66
80
  };
67
81
 
68
82
  const frameworkArtifacts = collectFrameworkArtifacts(aiwgRoot, 'all', {
@@ -87,7 +101,7 @@ export function computeAllArtifactBasenames(srcRoot, type) {
87
101
  add(getAddonRuleFiles(aiwgRoot, [], { includeExplicit: true }));
88
102
  }
89
103
 
90
- return stems;
104
+ return { stems, ownerStems };
91
105
  }
92
106
 
93
107
 
@@ -170,24 +184,27 @@ export function computeAllSkillNames(srcRoot) {
170
184
  * 1. It has an allowed deployed-artifact extension (`.md` / `.mdc` by
171
185
  * default; callers may include `.toml`), is not `RULES-INDEX.md`,
172
186
  * and not the sidecar manifest.
173
- * 2. Its stem is NOT in `desiredStems` (the source no longer ships it).
187
+ * 2. No recorded owner still ships its stem. Receipts without bundle
188
+ * identity fall back to the global `desiredStems` check.
174
189
  * 3. It carries an AIWG ownership signal — either a `.aiwg-manifest.json`
175
190
  * sidecar entry, or an in-file `aiwg:managed` marker.
191
+ * 4. Its bytes match the sidecar's hash. Markers alone never permit deletion.
176
192
  *
177
- * User-authored files (no ownership signal) and current AIWG artifacts (stem
178
- * in the desired set) are never touched. Pruned files also have their sidecar
193
+ * User-authored files (no ownership signal) and artifacts still shipped by a
194
+ * recorded owner are never touched. Pruned files also have their sidecar
179
195
  * entry dropped so the manifest stays accurate.
180
196
  *
181
- * Safe to call on every deploy invocation: `desiredStems` is the global
182
- * (mode-independent) source set, so sibling-framework files are never
183
- * collateral.
197
+ * Shared-path rule: retain the file if ANY recorded owner still ships the
198
+ * stem, including when another recorded owner has retired it. Inventory is
199
+ * mode-independent so sibling-framework files remain protected.
184
200
  *
185
201
  * @param {string} destDir absolute path to the provider artifact dir
186
202
  * @param {Set<string>|string[]} desiredStems stems that should remain
187
- * @param {object} opts `{ dryRun, verbose }`
203
+ * @param {object} opts `{ dryRun, verbose, ownerStems?: Map<string, Set<string>> }`
188
204
  * @returns {string[]} removed (or would-be-removed) file paths
189
205
  */
190
206
  export function pruneStaleAiwgFiles(destDir, desiredStems, opts = {}) {
207
+ if (opts.copyMode ?? opts.copyStandardSkills) return [];
191
208
  const { dryRun = false, verbose = false } = opts;
192
209
  const artifactExtensions = opts.artifactExtensions || ['.md', '.mdc'];
193
210
  // When supplied, skill-command wrappers are retired against the set of skills
@@ -223,7 +240,13 @@ export function pruneStaleAiwgFiles(destDir, desiredStems, opts = {}) {
223
240
  const lower = name.toLowerCase();
224
241
  if (!artifactExtensions.some(extension => lower.endsWith(extension))) continue;
225
242
 
226
- if (desired.has(artifactStem(name))) continue;
243
+ const stem = artifactStem(name);
244
+ const record = managed[name];
245
+ const owners = [record?.frameworkSlug, ...(Array.isArray(record?.owners) ? record.owners : [])]
246
+ .filter(owner => typeof owner === 'string' && owner.length > 0);
247
+ // Wrappers belong to the skill inventory below, not the command inventory.
248
+ const ownerAware = opts.ownerStems instanceof Map && owners.length > 0 && record?.kind !== 'skill-command';
249
+ if (ownerAware ? owners.some(owner => opts.ownerStems.get(owner)?.has(stem)) : desired.has(stem)) continue;
227
250
 
228
251
  // Skill-command wrappers are named after skills, not command sources, so
229
252
  // they are absent from the command desired set by construction — pruning
@@ -246,6 +269,10 @@ export function pruneStaleAiwgFiles(destDir, desiredStems, opts = {}) {
246
269
  if (!owned) continue;
247
270
 
248
271
  const target = path.join(destDir, name);
272
+ if (!managed[name]?.hash || managed[name].hash !== `sha256:${contentHash(fs.readFileSync(target))}`) {
273
+ console.warn(`${target}: kept (${managed[name]?.hash ? 'operator-edited' : 'unverifiable ownership'})`);
274
+ continue;
275
+ }
249
276
  removed.push(target);
250
277
  if (dryRun) {
251
278
  if (verbose) console.log(`[dry-run] would prune stale AIWG artifact: ${path.relative(process.cwd(), target)}`);
@@ -1,4 +1,5 @@
1
1
  // Shared provider kernel skills utilities.
2
+ import { removeSkillCopy } from './skill-copy-prune.mjs';
2
3
  import { fs, path } from './base-runtime.mjs';
3
4
  import { parseFrontmatter } from './base-frontmatter.mjs';
4
5
  import { ensureDir } from './base-files.mjs';
@@ -140,7 +141,7 @@ export function deploySkillsWithKernelRouting(
140
141
  } catch { /* preserve unreadable/operator-owned content */ }
141
142
  }
142
143
  if (!managed) continue;
143
- fs.rmSync(target, { recursive: true, force: true });
144
+ if (!removeSkillCopy(target, { ...opts, tierMove: true, replacement: path.join(kernelDestDir, entry.name) })) continue;
144
145
  prunedKernelFromStandardDir++;
145
146
  if (opts?.verbose) console.log(`pruned promoted kernel from standard dir: ${entry.name}`);
146
147
  }
@@ -160,7 +161,10 @@ export function deploySkillsWithKernelRouting(
160
161
  if (!standardNames.has(entry.name)) continue;
161
162
  const target = path.join(kernelDestDir, entry.name);
162
163
  try {
163
- fs.rmSync(target, { recursive: true, force: true });
164
+ // Index mode serves standard skills from $AIWG_ROOT; copy mode must have
165
+ // written the standard-tier copy before the kernel copy goes.
166
+ const replacement = copyStandardSkills && standardDestDir ? path.join(standardDestDir, entry.name) : undefined;
167
+ if (!removeSkillCopy(target, { ...opts, tierMove: true, replacement })) continue;
164
168
  prunedFromKernelDir++;
165
169
  if (opts?.verbose) console.log(`pruned legacy from kernel dir: ${entry.name}`);
166
170
  } catch (err) {
@@ -187,7 +191,7 @@ export function deploySkillsWithKernelRouting(
187
191
  if (!allSkillNames.has(entry.name)) continue;
188
192
  const target = path.join(standardDestDir, entry.name);
189
193
  try {
190
- fs.rmSync(target, { recursive: true, force: true });
194
+ if (!removeSkillCopy(target, opts)) continue;
191
195
  prunedFromStandardDir++;
192
196
  if (opts?.verbose) console.log(`pruned legacy from standard dir: ${entry.name}`);
193
197
  } catch (err) {
@@ -316,7 +320,7 @@ export function computeAllKernelNames(srcRoot) {
316
320
  * @returns {number} count of pruned entries
317
321
  */
318
322
  export function pruneStaleAiwgSkills(kernelDestDir, desiredKernelNames, opts = {}) {
319
- if (!kernelDestDir || !fs.existsSync(kernelDestDir)) return 0;
323
+ if ((opts.copyMode ?? opts.copyStandardSkills) || !kernelDestDir || !fs.existsSync(kernelDestDir)) return 0;
320
324
  // No global desired set — skip pruning rather than delete everything (#123).
321
325
  if (desiredKernelNames == null) return 0;
322
326
  if (opts.dryRun) return 0;
@@ -343,7 +347,7 @@ export function pruneStaleAiwgSkills(kernelDestDir, desiredKernelNames, opts = {
343
347
  if (!isAiwgManaged) continue;
344
348
 
345
349
  try {
346
- fs.rmSync(path.join(kernelDestDir, entry.name), { recursive: true, force: true });
350
+ if (!removeSkillCopy(path.join(kernelDestDir, entry.name), opts)) continue;
347
351
  pruned++;
348
352
  if (opts.verbose) console.log(`pruned stale AIWG skill: ${entry.name}`);
349
353
  } catch (err) {
@@ -39,6 +39,7 @@ import { MANAGED_MARKER_RE, MANIFEST_FILENAME, readSidecarManifest, writeSidecar
39
39
  export function cleanupOldRuleFiles(rulesDir, opts = {}) {
40
40
  const { dryRun = false, cleanRules = false, incomingFiles } = opts;
41
41
  const removed = [];
42
+ if (opts.copyMode ?? opts.copyStandardSkills) return removed;
42
43
 
43
44
  if (!fs.existsSync(rulesDir)) return removed;
44
45
  if (!cleanRules) return removed;
@@ -8,7 +8,7 @@ import { getFrameworksForMode } from './base-framework-discovery.mjs';
8
8
 
9
9
  /** Source-scoped cleanup also works when a removed standard skill is absent from this deploy's input. */
10
10
  export function pruneMissingStandardSkills(destDir, opts) {
11
- if (!destDir || !opts?.srcRoot || opts.dryRun || !fs.existsSync(destDir)) return 0;
11
+ if ((opts?.copyMode ?? opts?.copyStandardSkills) || !destDir || !opts?.srcRoot || opts.dryRun || !fs.existsSync(destDir)) return 0;
12
12
  const sourceRoot = path.resolve(opts.srcRoot);
13
13
  let pruned = 0;
14
14
  for (const entry of fs.readdirSync(destDir, { withFileTypes: true })) {
@@ -99,6 +99,11 @@ export function deploySkillDir(skillDir, destDir, opts) {
99
99
  };
100
100
  if (fs.existsSync(destPath)) {
101
101
  const destContent = fs.readFileSync(destPath, 'utf8');
102
+ if (previous?.managed?.[relative]?.hash && previous.managed[relative].hash !== `sha256:${contentHash(destContent)}`) {
103
+ managed[relative] = previous.managed[relative];
104
+ console.warn(`${opts.logicalOutputPath?.(destPath) || destPath}: kept (operator-edited)`);
105
+ continue;
106
+ }
102
107
  if (destContent === srcContent && !force) {
103
108
  if (verbose) console.log(`skip (unchanged): ${path.relative(destDir, destPath)}`);
104
109
  continue;
@@ -117,6 +122,9 @@ export function deploySkillDir(skillDir, destDir, opts) {
117
122
 
118
123
  copyRecursive(skillDir, destSkillDir);
119
124
  pruneRecordedSkillFiles(destSkillDir, previous?.managed, new Set(Object.keys(managed)), opts);
125
+ for (const [name, record] of Object.entries(previous?.managed || {})) {
126
+ if (!managed[name] && fs.existsSync(path.join(destSkillDir, name))) managed[name] = record;
127
+ }
120
128
  writeSidecarManifest(destSkillDir, { managed, skillSource: path.resolve(skillDir) }, dryRun);
121
129
 
122
130
  // Drop a `.aiwg-managed` marker so future cleanup runs can identify
@@ -5,7 +5,7 @@ export { loadModelConfig, loadRuntimeModelCatalog, parseSkillPlatforms, skillMat
5
5
  export { parseFrontmatter, stringifyFrontmatter, toKebabCase, stripJsonComments, inferAgentCategory, parseTools, filterCommandsAgainstSkills } from './base-frontmatter.mjs';
6
6
  export { deployFiles, deploySoulCompanions } from './base-flat-artifacts.mjs';
7
7
  export { isKernelSkill, deploySkillsWithKernelRouting, computeAllKernelNames, pruneStaleAiwgSkills } from './base-kernel-skills.mjs';
8
- export { artifactStem, computeAllArtifactBasenames, resolveAiwgRoot, computeAllSkillNames, pruneStaleAiwgFiles } from './base-inventory.mjs';
8
+ export { artifactStem, computeAllArtifactBasenames, computeArtifactInventory, resolveAiwgRoot, computeAllSkillNames, pruneStaleAiwgFiles } from './base-inventory.mjs';
9
9
  export { deploySkillDir, initializeFrameworkWorkspace } from './base-skill-copy.mjs';
10
10
  export { buildRemotesTopologyBlock, interpolateContextTokens, createManagedMdFromTemplate, createAgentsMdFromTemplate } from './base-context.mjs';
11
11
  export { shouldDeployAgent, matchesGlob, filterAgentFiles, normalizeDeploymentMode, discoverFrameworks, getFrameworksForMode, collectFrameworkArtifacts } from './base-framework-discovery.mjs';
@@ -1,3 +1,4 @@
1
+ import { removeSkillCopy } from './skill-copy-prune.mjs';
1
2
  import { withModelWrapper } from './model-wrapper.mjs';
2
3
  import { postDeploy } from './claude-post-deploy.mjs';
3
4
  export { postDeploy };
@@ -267,7 +268,7 @@ function cleanupLegacyBuiltinCollisions(destDir, opts) {
267
268
  if (!/^namespace:\s*aiwg\s*$/m.test(content)) continue;
268
269
 
269
270
  try {
270
- fs.rmSync(skillPath, { recursive: true, force: true });
271
+ if (!removeSkillCopy(skillPath, opts)) continue;
271
272
  if (opts.verbose) console.log(`removed legacy skill: ${name} (superseded by aiwg-${name})`);
272
273
  } catch { /* non-fatal */ }
273
274
  }
@@ -1,3 +1,4 @@
1
+ import { removeSkillCopy } from './skill-copy-prune.mjs';
1
2
  import { withModelWrapper } from './model-wrapper.mjs';
2
3
  import { postDeploy } from './codex-post-deploy.mjs';
3
4
  export { postDeploy };
@@ -286,6 +287,7 @@ export async function deployCommands(targetDir, srcRoot, opts) {
286
287
  if (opts.force) args.push('--force');
287
288
  if (opts.mode) args.push('--mode', opts.mode);
288
289
  if (opts.copyStandardSkills === true) args.push('--copy-all');
290
+ if (opts.copyMode === false) args.push('--index-mode');
289
291
  // A copy-all the deployer forced on the caller's behalf (project-local
290
292
  // bundles) still honors the startup listing cap (#2561).
291
293
  if (opts.listingBudget === true) args.push('--listing-budget');
@@ -322,6 +324,7 @@ export async function deploySkills(targetDir, srcRoot, opts) {
322
324
  if (opts.force) args.push('--force');
323
325
  if (opts.mode) args.push('--mode', opts.mode);
324
326
  if (opts.copyStandardSkills === true) args.push('--copy-all');
327
+ if (opts.copyMode === false) args.push('--index-mode');
325
328
  // A copy-all the deployer forced on the caller's behalf (project-local
326
329
  // bundles) still honors the startup listing cap (#2561).
327
330
  if (opts.listingBudget === true) args.push('--listing-budget');
@@ -342,6 +345,7 @@ export async function deploySkills(targetDir, srcRoot, opts) {
342
345
  * touched. The now-empty legacy dir is removed if AIWG owned everything in it.
343
346
  */
344
347
  export function pruneLegacyCodexSkills(opts = {}, legacyDir = path.join(os.homedir(), '.codex', 'skills')) {
348
+ if (opts.copyMode ?? opts.copyStandardSkills) return 0;
345
349
  let entries;
346
350
  try {
347
351
  entries = fs.readdirSync(legacyDir, { withFileTypes: true });
@@ -365,7 +369,7 @@ export function pruneLegacyCodexSkills(opts = {}, legacyDir = path.join(os.homed
365
369
  if (opts.dryRun) {
366
370
  console.log(`[dry-run] would prune legacy AIWG skill ${skillDir}`);
367
371
  } else {
368
- fs.rmSync(skillDir, { recursive: true, force: true });
372
+ if (!removeSkillCopy(skillDir, opts)) continue;
369
373
  }
370
374
  pruned++;
371
375
  }
@@ -6,26 +6,50 @@ import { importImpl, resolveImpl } from '../../_resolve-impl.mjs';
6
6
 
7
7
  const quote = value => `'${value.replace(/'/g, `'"'"'`)}'`;
8
8
 
9
- // Local-only paths are declared only in project/user models.json or project
10
- // parallelism (the built-in defaults declare none). Skip the full model-config
11
- // load when none of them mention the field, so ordinary deploys never depend
12
- // on the framework default config (absent from the slim CLI package).
13
- function declaresLocalOnlyPaths(targetDir) {
9
+ // Avoid the full model-config load for ordinary deploys, including slim CLI installs
10
+ // without framework defaults. Declared guards use the same validated loader as paths.
11
+ function declaresGuardPolicy(targetDir, provider) {
14
12
  const userDir = process.env.AIWG_CONFIG || path.join(os.homedir(), '.config/aiwg');
15
13
  return [path.join(targetDir, 'models.json'), path.join(userDir, 'models.json'), path.join(targetDir, '.aiwg/aiwg.config')]
16
- .some(file => { try { return fs.readFileSync(file, 'utf8').includes('localOnlyPaths'); } catch { return false; } });
14
+ .some(file => { try {
15
+ const source = fs.readFileSync(file, 'utf8');
16
+ if (source.includes('localOnlyPaths')) return true;
17
+ if (provider !== 'claude' || !source.includes('denyConductorWorkerExecution')) return false;
18
+ const value = JSON.parse(source)?.defaults?.workerSelection?.guards?.denyConductorWorkerExecution;
19
+ return value !== undefined && value !== false;
20
+ } catch (error) { return error instanceof SyntaxError; } });
21
+ }
22
+
23
+ // Turn off a previously deployed opt-in check without removing retained read rules.
24
+ function disableExecutionCheck(targetDir, provider, opts) {
25
+ if (provider !== 'claude' || opts.dryRun) return;
26
+ const root = path.resolve(targetDir), hookPath = path.join(root, '.claude/hooks/aiwg-local-only.mjs');
27
+ if (!fs.existsSync(hookPath)) return;
28
+ const source = fs.readFileSync(hookPath, 'utf8');
29
+ const start = source.lastIndexOf(`\nrunConductorDataHook(${JSON.stringify(root)}, `);
30
+ if (start >= 0 && source.endsWith(', true);\n')) {
31
+ fs.writeFileSync(hookPath, source.slice(0, -', true);\n'.length) + ', false);\n');
32
+ }
17
33
  }
18
34
 
19
35
  export async function deployConductorDataGuard(targetDir, provider, opts = {}) {
20
- if (!declaresLocalOnlyPaths(targetDir)) return [];
36
+ if (!declaresGuardPolicy(targetDir, provider)) {
37
+ disableExecutionCheck(targetDir, provider, opts);
38
+ return [];
39
+ }
21
40
  // Always resolve policy through the existing loader, including inherited restrictions.
22
- const { ConfigLoader } = await importImpl(import.meta.url, 'models/config-loader.js');
23
41
  const { readAiwgConfig } = await importImpl(import.meta.url, 'config/aiwg-config.js');
42
+ const { ConfigLoader } = await importImpl(import.meta.url, 'models/config-loader.js');
24
43
  const guard = await importImpl(import.meta.url, 'models/conductor-data-policy.mjs');
25
44
  const config = await readAiwgConfig(targetDir);
26
45
  const models = await new ConfigLoader(targetDir).load(config?.parallelism);
46
+ const executionGuard = provider === 'claude' && models.defaults.workerSelection?.guards?.denyConductorWorkerExecution === true;
27
47
  const paths = guard.collectLocalOnlyPaths(models.defaults.workerSelection, config?.parallelism);
28
- if (!paths.length || opts.dryRun) return paths;
48
+ if (!paths.length && !executionGuard) {
49
+ disableExecutionCheck(targetDir, provider, opts);
50
+ return paths;
51
+ }
52
+ if (opts.dryRun) return paths;
29
53
  const root = path.resolve(targetDir);
30
54
  if (provider === 'claude') {
31
55
  const settingsPath = path.join(root, '.claude/settings.json');
@@ -33,7 +57,7 @@ export async function deployConductorDataGuard(targetDir, provider, opts = {}) {
33
57
  const hookPath = path.join(root, '.claude/hooks/aiwg-local-only.mjs');
34
58
  const hookSource = fs.readFileSync(resolveImpl(import.meta.url, 'models/conductor-data-policy.mjs'), 'utf8');
35
59
  fs.mkdirSync(path.dirname(hookPath), { recursive: true });
36
- fs.writeFileSync(hookPath, `${hookSource}\nrunConductorDataHook(${JSON.stringify(root)}, ${JSON.stringify(paths)});\n`);
60
+ fs.writeFileSync(hookPath, `${hookSource}\nrunConductorDataHook(${JSON.stringify(root)}, ${JSON.stringify(paths)}, ${JSON.stringify(executionGuard)});\n`);
37
61
  settings.permissions ??= {};
38
62
  settings.permissions.deny = [...new Set([...(settings.permissions.deny ?? []), ...paths.flatMap(file => [
39
63
  `Read(//${path.join(root, file).slice(1)})`, `Read(//${path.join(root, file).slice(1)}/**)`,
@@ -56,6 +80,6 @@ export async function deployConductorDataGuard(targetDir, provider, opts = {}) {
56
80
  fs.mkdirSync(path.dirname(rulesPath), { recursive: true });
57
81
  fs.writeFileSync(rulesPath, lines.join('\n') + '\n');
58
82
  }
59
- console.log(`Local-only conductor guard (${provider}): ${paths.join(', ')}; shell coverage is limited.`);
83
+ console.log(`Conductor guard (${provider}): ${paths.join(', ')}${executionGuard ? '; worker execution checks enabled' : ''}; shell coverage is limited.`);
60
84
  return paths;
61
85
  }
@@ -0,0 +1,42 @@
1
+ // Resolve Flue bundle manifests and the invocation-wide app selection.
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import { resolveAiwgRoot } from './base-inventory.mjs';
5
+ import { getFrameworksForMode } from './base-framework-discovery.mjs';
6
+ import { importImpl } from '../../_resolve-impl.mjs';
7
+ const { frameworkRegistryId } = await importImpl(import.meta.url, 'config/framework-aliases.js');
8
+
9
+ export const camel = value => value.replace(/-([a-z0-9])/g, (_, char) => char.toUpperCase()).replace(/^[0-9]/, digit => `_${digit}`);
10
+ export function flueBundleInventory(opts) {
11
+ const root = resolveAiwgRoot(opts.srcRoot);
12
+ const bundles = [];
13
+ const add = dir => {
14
+ const file = path.join(dir, 'manifest.json');
15
+ if (!fs.existsSync(file)) return;
16
+ const manifest = JSON.parse(fs.readFileSync(file, 'utf8'));
17
+ const id = path.basename(dir);
18
+ bundles.push({ id, root: dir, manifest });
19
+ };
20
+ if (root) for (const group of ['frameworks', 'addons', 'extensions']) {
21
+ const dir = path.join(root, 'agentic/code', group);
22
+ if (fs.existsSync(dir)) for (const entry of fs.readdirSync(dir, { withFileTypes: true })) if (entry.isDirectory()) add(path.join(dir, entry.name));
23
+ }
24
+ for (const entry of Object.values(opts.config?.installed || {})) {
25
+ if (!entry.deployedTo?.flue || !entry.localPath || !opts.target) continue;
26
+ const logical = path.resolve(opts.logicalOutputPath?.(opts.target) || opts.target, entry.localPath);
27
+ const dir = opts.mapInputPath?.(logical) || logical;
28
+ if (!bundles.some(bundle => bundle.root === dir)) add(dir);
29
+ }
30
+ if (!bundles.some(bundle => path.resolve(bundle.root) === path.resolve(opts.srcRoot))) add(opts.srcRoot);
31
+ return bundles;
32
+ }
33
+ export function selectedFlueBundles(opts) {
34
+ const inventory = flueBundleInventory(opts);
35
+ const names = Object.entries(opts.config?.installed || {}).filter(([, entry]) => entry.deployedTo?.flue).map(([id]) => frameworkRegistryId(id));
36
+ const invoked = inventory.find(bundle => path.resolve(bundle.root) === path.resolve(opts.srcRoot));
37
+ if (invoked) names.push(invoked.id);
38
+ else names.push(...getFrameworksForMode(opts.srcRoot, opts.mode || 'sdlc').map(bundle => bundle.id));
39
+ // `all` preserves the existing kernel skill surface, including addon kernels.
40
+ if ((opts.mode === 'all' && !invoked) || names.includes('all')) names.push(...inventory.map(bundle => bundle.id));
41
+ return inventory.filter(bundle => names.includes(bundle.id)).sort((a, b) => a.id.localeCompare(b.id));
42
+ }
@@ -0,0 +1,20 @@
1
+ // Generate a portable remote connection resolved only inside Worker execution.
2
+ export function cloudflareTools({ fluePackage }) {
3
+ return `${fluePackage ? "import { createAiwgConnection } from '@aiwg/flue/tools';" : `import { defineMcpConnection } from '@flue/runtime';
4
+ function createAiwgConnection({ url, token }: { url: string; token: string }) {
5
+ return defineMcpConnection({ name: 'aiwg', url, auth: token, tools: ['discover', 'skill-show', 'artifact-write'] });
6
+ }`}
7
+ import { getCloudflareContext } from '@flue/runtime/cloudflare';
8
+
9
+ export function aiwgConnection() {
10
+ const { env } = getCloudflareContext();
11
+ const url = env.AIWG_MCP_URL;
12
+ const token = env.AIWG_MCP_TOKEN;
13
+ if (typeof url !== 'string' || !url || typeof token !== 'string' || !token) {
14
+ throw new Error('AIWG remote tools require Worker bindings AIWG_MCP_URL and AIWG_MCP_TOKEN');
15
+ }
16
+ return createAiwgConnection({ url, token });
17
+ }
18
+ export { bindRemoteSpecialist } from '${fluePackage ? '@aiwg/flue/specialists' : './remote-specialist.js'}';
19
+ `;
20
+ }
@@ -2,6 +2,9 @@
2
2
  import fs from 'node:fs';
3
3
  import path from 'node:path';
4
4
  import { createHash } from 'node:crypto';
5
+ import { importImpl } from '../../_resolve-impl.mjs';
6
+ const { providerCopyMode } = await importImpl(import.meta.url, 'providers/deployment-preservation.mjs');
7
+ const { deploymentOwner } = await importImpl(import.meta.url, 'providers/deployment-ownership.mjs');
5
8
 
6
9
  const exists = file => { try { fs.lstatSync(file); return true; } catch (error) { if (error.code === 'ENOENT') return false; throw error; } };
7
10
  const directory = file => exists(file) && fs.lstatSync(file).isDirectory();
@@ -11,10 +14,10 @@ const configFiles = ['ts', 'mts', 'mjs', 'js', 'cjs', 'cts'].map(ext => `flue.co
11
14
  export function flueDeploymentFiles(target) {
12
15
  const source = ['.flue', 'src'].find(dir => directory(path.join(target, dir))) || 'src';
13
16
  // Snapshot config and conventional entries too: deployment reads a staged project.
14
- return [...new Set([path.join(source, 'db.ts'), '.gitignore', 'src/aiwg/tools.ts', 'src/aiwg/specialists.ts',
15
- ...configFiles, ...databaseFiles()])];
17
+ return [...new Set([path.join(source, 'db.ts'), '.gitignore', 'src/aiwg/tools.ts', 'src/aiwg/specialists.ts', 'src/aiwg/skills.ts',
18
+ ...configFiles, ...databaseFiles(), 'wrangler.jsonc', 'src/aiwg/remote-specialist.js', 'src/aiwg/remote-specialist.d.ts'])];
16
19
  }
17
- function explicitDatabase(target) {
20
+ function configProperty(target, key) {
18
21
  const config = configFiles.find(file => exists(path.join(target, file)));
19
22
  if (!config) return;
20
23
  // Static tokens only; comments and string/template contents cannot become keys.
@@ -34,8 +37,8 @@ function explicitDatabase(target) {
34
37
  const nesting = [];
35
38
  for (let index = start; index < code.length; index++) {
36
39
  const token = code[index];
37
- if (nesting.length === 1 && ['db', '"db"', "'db'"].includes(token)
38
- && ['{', ','].includes(code[index - 1]) && code[index + 1] === ':') return config;
40
+ if (nesting.length === 1 && [key, `"${key}"`, `'${key}'`].includes(token)
41
+ && ['{', ','].includes(code[index - 1]) && code[index + 1] === ':') return { config, value: code[index + 2] };
39
42
  if (['{', '[', '('].includes(token)) nesting.push(token);
40
43
  else if (['}', ']', ')'].includes(token)) {
41
44
  nesting.pop();
@@ -43,6 +46,14 @@ function explicitDatabase(target) {
43
46
  }
44
47
  }
45
48
  }
49
+ export function detectFlueTarget(target, { warn = false } = {}) {
50
+ const value = configProperty(target, 'target')?.value;
51
+ if (["'cloudflare'", '"cloudflare"', '`cloudflare`'].includes(value)) return 'cloudflare';
52
+ if (warn && exists(path.join(target, 'wrangler.jsonc'))) {
53
+ console.warn("Flue (experimental): wrangler.jsonc found without an explicit target: 'cloudflare' in flue.config.*; keeping Node deployment.");
54
+ }
55
+ return 'node';
56
+ }
46
57
  export function claimRecordedFile(target, file, opts) {
47
58
  if (!exists(file)) return false;
48
59
  let record;
@@ -53,8 +64,36 @@ export function claimRecordedFile(target, file, opts) {
53
64
  opts.writtenFiles?.push(file);
54
65
  return true;
55
66
  }
67
+ export function retireFlueTargetFiles(target, opts) {
68
+ const cloudflare = opts.flueTarget === 'cloudflare';
69
+ const candidates = cloudflare ? databaseFiles() : ['src/aiwg/remote-specialist.js', 'src/aiwg/remote-specialist.d.ts'];
70
+ const receiptFile = path.join(target, '.aiwg/.aiwg-manifest.json');
71
+ let receipt;
72
+ try { receipt = JSON.parse(fs.readFileSync(receiptFile, 'utf8')); } catch { receipt = {}; }
73
+ let changed = false;
74
+ for (const relative of candidates) {
75
+ const file = path.join(target, relative);
76
+ if (!exists(file)) continue;
77
+ const record = receipt.managed?.[relative.split(path.sep).join('/')];
78
+ const copy = (opts.copyMode ?? opts.copyStandardSkills) || (record?.owners || []).some(owner =>
79
+ providerCopyMode(target, 'flue', owner, opts.config, deploymentOwner(opts)));
80
+ const reason = copy ? 'copy mode' : cloudflare && record?.filePreimage?.present ? 'operator database module'
81
+ : !claimRecordedFile(target, file, {}) ? 'edited or unrecorded file' : undefined;
82
+ if (reason) {
83
+ console.warn(`Flue (experimental): keeping ${opts.logicalOutputPath?.(file) || file} (${reason}); remove this file manually if no longer needed for the new target.`);
84
+ continue;
85
+ }
86
+ if (!opts.dryRun) {
87
+ fs.rmSync(file);
88
+ delete receipt.managed[relative.split(path.sep).join('/')];
89
+ changed = true;
90
+ }
91
+ }
92
+ if (changed) (opts.writeReceipt || fs.writeFileSync)(receiptFile, `${JSON.stringify(receipt, null, 2)}\n`);
93
+ }
56
94
  export function deployFlueDatabase(target, opts) {
57
- const config = explicitDatabase(target);
95
+ if (detectFlueTarget(target) === 'cloudflare') return;
96
+ const config = configProperty(target, 'db')?.config;
58
97
  if (config) {
59
98
  console.warn(`Flue (experimental): keeping explicit db entry in ${config}; verify the operator module selects durable SQLite at .flue-state/state.db.`);
60
99
  return;
@@ -0,0 +1,25 @@
1
+ // Preserve operator skill directories before using the shared bundle copier.
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import { createHash } from 'node:crypto';
5
+ import { deploySkillDir } from './base-skill-copy.mjs';
6
+ export function deployFlueSkill(dir, destination, opts) {
7
+ const target = path.join(destination, path.basename(dir));
8
+ if (fs.existsSync(target)) {
9
+ let receipt;
10
+ try { receipt = JSON.parse(fs.readFileSync(path.join(target, '.aiwg-manifest.json'), 'utf8')); } catch { /* Unrecorded files are operator-owned. */ }
11
+ const managed = receipt?.managed;
12
+ const pristine = managed?.['SKILL.md'] && Object.entries(managed).every(([relative, record]) => {
13
+ const file = path.resolve(target, relative);
14
+ if (!file.startsWith(`${path.resolve(target)}${path.sep}`)) return false;
15
+ try {
16
+ return fs.lstatSync(file).isFile() && `sha256:${createHash('sha256').update(fs.readFileSync(file)).digest('hex')}` === record.hash;
17
+ } catch { return false; }
18
+ });
19
+ if (!pristine) {
20
+ console.warn(`Flue (experimental): keeping operator-edited or unrecorded skill ${opts.logicalOutputPath?.(target) || target}`);
21
+ return false;
22
+ }
23
+ }
24
+ return deploySkillDir(dir, destination, opts);
25
+ }
@@ -0,0 +1,45 @@
1
+ // Generate static skill imports from selected bundles and actual deployed files.
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import { getFrameworksForMode } from './base-framework-discovery.mjs';
5
+ import { listSkillDirs } from './base-files.mjs';
6
+ import { skillMatchesProvider } from './base-models-platforms.mjs';
7
+ import { validateFlueSkill } from './flue-validation.mjs';
8
+ import { importImpl } from '../../_resolve-impl.mjs';
9
+ const { frameworkRegistryId } = await importImpl(import.meta.url, 'config/framework-aliases.js');
10
+ import { camel, selectedFlueBundles } from './flue-bundles.mjs';
11
+
12
+ function publishedSkill(bundle, name) {
13
+ if (!['frameworks', 'addons'].includes(path.basename(path.dirname(bundle.root)))) throw new Error(`${bundle.id}: @aiwg/flue publishes frameworks and addons only; use workspace copy mode`);
14
+ const file = path.join(bundle.root, bundle.manifest.entry?.skills || 'skills', name, 'SKILL.md');
15
+ const content = fs.readFileSync(file, 'utf8');
16
+ if (!skillMatchesProvider(content, 'flue')) return false;
17
+ try { validateFlueSkill(content, file); return true; } catch (error) {
18
+ if (path.basename(path.dirname(bundle.root)) === 'frameworks') throw error;
19
+ return false;
20
+ }
21
+ }
22
+ export function generateFlueSkills(target, opts) {
23
+ const selected = selectedFlueBundles(opts);
24
+ const exact = selected.find(bundle => path.resolve(bundle.root) === path.resolve(opts.srcRoot));
25
+ const invoked = new Set(exact ? [exact.id] : getFrameworksForMode(opts.srcRoot, opts.mode || 'sdlc').map(bundle => bundle.id));
26
+ const all = opts.mode === 'all' && !exact;
27
+ const bundles = selected.filter(bundle => !(all && opts.fluePackage) || ['frameworks', 'addons'].includes(path.basename(path.dirname(bundle.root)))).map(bundle => {
28
+ const current = all || invoked.has(bundle.id);
29
+ const declared = Object.entries(opts.config?.installed || {}).find(([id]) => frameworkRegistryId(id) === bundle.id);
30
+ const packageMode = current ? opts.fluePackage : (declared ? declared[1].deployedTo?.flue?.package === true : opts.fluePackage);
31
+ return { ...bundle, packageMode,
32
+ skills: listSkillDirs(path.join(bundle.root, bundle.manifest.entry?.skills || 'skills'))
33
+ .map(dir => path.basename(dir)).filter(name => packageMode ? publishedSkill(bundle, name) : fs.existsSync(path.join(target, '.agents/skills', name, 'SKILL.md'))).sort(),
34
+ };
35
+ });
36
+ const packaged = new Set(bundles.filter(bundle => bundle.packageMode).flatMap(bundle => bundle.skills));
37
+ const names = [...new Set(bundles.flatMap(bundle => bundle.skills))].sort();
38
+ const exports = new Map();
39
+ for (const name of names) {
40
+ const identifier = camel(name);
41
+ if (!/^[a-zA-Z_$][\w$]*$/.test(identifier) || exports.has(identifier)) throw new Error(`Ambiguous Flue skill export: ${name}`);
42
+ exports.set(identifier, name);
43
+ }
44
+ return `// AIWG bundle skills; static imports are required by Flue.\nimport { useSkill } from '@flue/runtime';\n${names.map(name => `import ${camel(name)} from '${packaged.has(name) ? '@aiwg/flue/skills' : '../../.agents/skills'}/${name}/SKILL.md';`).join('\n')}\n\n${names.length ? `export { ${names.map(camel).join(', ')} };\n\n` : ''}${bundles.map(bundle => `export const ${camel(bundle.id === 'sdlc-complete' ? 'sdlc' : bundle.id)}Skills = [${bundle.skills.map(camel).join(', ')}] as const;`).join('\n')}\n\nexport function useAiwgSkills(...bundles: ReadonlyArray<readonly Parameters<typeof useSkill>[0][]>) {\n for (const skill of new Set(bundles.flat())) useSkill(skill);\n}\n`;
45
+ }