@aiwg/cli 2026.10.16 → 2026.10.18

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 (128) hide show
  1. package/dist/src/artifacts/corpus-tools/resolve.js +21 -4
  2. package/dist/src/artifacts/query-engine-corpus.js +217 -0
  3. package/dist/src/artifacts/query-engine-discover-output.js +229 -0
  4. package/dist/src/artifacts/query-engine-discover.js +285 -0
  5. package/dist/src/artifacts/query-engine-entries.js +188 -0
  6. package/dist/src/artifacts/query-engine-index.js +249 -0
  7. package/dist/src/artifacts/query-engine-matching.js +143 -0
  8. package/dist/src/artifacts/query-engine-options.js +2 -0
  9. package/dist/src/artifacts/query-engine-rules.js +202 -0
  10. package/dist/src/artifacts/query-engine-scoring.js +436 -0
  11. package/dist/src/artifacts/query-engine-show-card.js +194 -0
  12. package/dist/src/artifacts/query-engine-show-load.js +211 -0
  13. package/dist/src/artifacts/query-engine-show.js +300 -0
  14. package/dist/src/artifacts/query-engine.js +7 -2576
  15. package/dist/src/cli/handlers/mc-agents.js +111 -0
  16. package/dist/src/cli/handlers/mc-args.js +54 -0
  17. package/dist/src/cli/handlers/mc-control.js +227 -0
  18. package/dist/src/cli/handlers/mc-dispatch.js +203 -0
  19. package/dist/src/cli/handlers/mc-help.js +171 -0
  20. package/dist/src/cli/handlers/mc-run.js +343 -0
  21. package/dist/src/cli/handlers/mc-session.js +138 -0
  22. package/dist/src/cli/handlers/mc-status.js +258 -0
  23. package/dist/src/cli/handlers/mc-summary.js +43 -0
  24. package/dist/src/cli/handlers/mc-types.js +3 -0
  25. package/dist/src/cli/handlers/mc-worker.js +205 -0
  26. package/dist/src/cli/handlers/mc.js +12 -1665
  27. package/dist/src/cli/handlers/models-refusal.js +13 -0
  28. package/dist/src/cli/handlers/models.js +2 -1
  29. package/dist/src/cli/handlers/remove-bundled.js +133 -0
  30. package/dist/src/cli/handlers/remove-options.js +31 -0
  31. package/dist/src/cli/handlers/remove-user.js +174 -0
  32. package/dist/src/cli/handlers/remove.js +201 -0
  33. package/dist/src/cli/handlers/subcommands-bundles.js +257 -0
  34. package/dist/src/cli/handlers/subcommands-discovery.js +165 -0
  35. package/dist/src/cli/handlers/subcommands-list-format.js +129 -0
  36. package/dist/src/cli/handlers/subcommands-list.js +250 -0
  37. package/dist/src/cli/handlers/subcommands-plugins.js +213 -0
  38. package/dist/src/cli/handlers/subcommands-quickref.js +58 -0
  39. package/dist/src/cli/handlers/subcommands-rlm.js +113 -0
  40. package/dist/src/cli/handlers/subcommands-services.js +66 -0
  41. package/dist/src/cli/handlers/subcommands-storage.js +259 -0
  42. package/dist/src/cli/handlers/subcommands.js +18 -1984
  43. package/dist/src/cli/scope-resolver.js +1 -142
  44. package/dist/src/cli/user-scope-mirror.js +173 -0
  45. package/dist/src/config/dispatch-host-thresholds.js +2 -0
  46. package/dist/src/config/dispatch-thresholds-runtime.mjs +4 -0
  47. package/dist/src/config/host-resource-report.d.mts +5 -0
  48. package/dist/src/config/host-resource-report.mjs +36 -6
  49. package/dist/src/config/host-resource-runtime.d.mts +3 -0
  50. package/dist/src/config/host-resource-runtime.mjs +9 -6
  51. package/dist/src/decision/ensemble-study/artifacts.js +7 -0
  52. package/dist/src/decision/ensemble-study/gate-policy.js +58 -0
  53. package/dist/src/decision/ensemble-study/gates.js +78 -0
  54. package/dist/src/decision/ensemble-study/protocol.js +18 -21
  55. package/dist/src/decision/ensemble-study/score.js +3 -2
  56. package/dist/src/decision/ensemble-study/statistics.js +7 -26
  57. package/dist/src/decision/sensitivity/comparative-gates.js +135 -0
  58. package/dist/src/decision/sensitivity/comparative.js +18 -41
  59. package/dist/src/extensions/claude-hooks-installer.js +18 -0
  60. package/dist/src/gates/evaluate.js +2 -358
  61. package/dist/src/gates/observations.js +363 -0
  62. package/dist/src/gates/pack-composition.js +270 -0
  63. package/dist/src/gates/pack-tightening.js +197 -0
  64. package/dist/src/gates/pack-validation.js +262 -0
  65. package/dist/src/gates/registry-error.js +5 -0
  66. package/dist/src/gates/registry.js +13 -685
  67. package/dist/src/mcp/json-document.mjs +29 -0
  68. package/dist/src/mcp/muse-native-config.mjs +1 -28
  69. package/dist/src/mission-protocol/worker-review-gate.js +7 -0
  70. package/dist/src/models/worker-plan.js +5 -5
  71. package/dist/src/plugin/command-ownership.js +34 -0
  72. package/dist/src/plugin/skill-command-frontmatter.js +197 -0
  73. package/dist/src/plugin/skill-command-translator.js +6 -232
  74. package/dist/src/providers/context-output-ownership.js +26 -0
  75. package/dist/src/providers/deployment-ownership.d.mts +19 -0
  76. package/dist/src/providers/deployment-ownership.mjs +226 -0
  77. package/dist/src/providers/deployment-removal.js +200 -0
  78. package/dist/src/providers/removal-transaction.js +86 -0
  79. package/dist/src/providers/settings-document.d.mts +3 -0
  80. package/dist/src/providers/settings-document.mjs +47 -0
  81. package/dist/src/providers/settings-removal.js +190 -0
  82. package/dist/src/providers/skill-ownership.d.mts +19 -2
  83. package/dist/src/providers/skill-ownership.mjs +12 -4
  84. package/dist/src/providers/transformation-receipt-integration.js +15 -271
  85. package/dist/src/providers/transformation-receipt-outputs.js +99 -0
  86. package/dist/src/providers/transformation-receipt-source.js +194 -0
  87. package/dist/src/research/identity.js +8 -2
  88. package/dist/src/research/reference-match.js +42 -7
  89. package/dist/src/rules/activation.mjs +15 -6
  90. package/dist/src/rules/core-startup.mjs +2 -2
  91. package/dist/src/serve/mission-conductor.js +4 -0
  92. package/dist/src/serve/mission-summary.js +56 -0
  93. package/dist/src/smiths/context-pipeline/aiwg-md.js +23 -0
  94. package/dist/src/smiths/context-pipeline/context-file-safety.js +3 -0
  95. package/dist/src/smiths/context-pipeline/generator.js +1 -1
  96. package/dist/src/smiths/hook-bridge/index.js +9 -0
  97. package/package.json +4 -1
  98. package/schemas/decision/D17StudyProtocol.v1.schema.json +39 -67
  99. package/tools/agents/deploy-agents.mjs +16 -677
  100. package/tools/agents/deploy-command-mirrors.mjs +229 -0
  101. package/tools/agents/deploy-options.mjs +258 -0
  102. package/tools/agents/deploy-support.mjs +165 -0
  103. package/tools/agents/providers/base-addon-discovery.mjs +139 -0
  104. package/tools/agents/providers/base-behaviors.mjs +168 -0
  105. package/tools/agents/providers/base-context.mjs +205 -0
  106. package/tools/agents/providers/base-contract.mjs +116 -0
  107. package/tools/agents/providers/base-files.mjs +252 -0
  108. package/tools/agents/providers/base-flat-artifacts.mjs +233 -0
  109. package/tools/agents/providers/base-framework-discovery.mjs +309 -0
  110. package/tools/agents/providers/base-frontmatter.mjs +196 -0
  111. package/tools/agents/providers/base-inventory.mjs +269 -0
  112. package/tools/agents/providers/base-kernel-skills.mjs +354 -0
  113. package/tools/agents/providers/base-migrations.mjs +258 -0
  114. package/tools/agents/providers/base-models-platforms.mjs +273 -0
  115. package/tools/agents/providers/base-rule-index.mjs +450 -0
  116. package/tools/agents/providers/base-runtime.mjs +60 -0
  117. package/tools/agents/providers/base-skill-copy.mjs +273 -0
  118. package/tools/agents/providers/base.mjs +16 -3364
  119. package/tools/agents/providers/claude-post-deploy.mjs +10 -2
  120. package/tools/agents/providers/hermes-startup.mjs +0 -5
  121. package/tools/agents/providers/muse.mjs +7 -2
  122. package/tools/agents/providers/rule-delivery-surface.mjs +31 -4
  123. package/tools/agents/providers/rule-deployment-commit.mjs +19 -15
  124. package/tools/agents/providers/rule-deployment-prepare.mjs +11 -2
  125. package/tools/agents/providers/rule-projection.mjs +3 -0
  126. package/tools/ralph-external/lib/worker-invocation-processes.mjs +4 -2
  127. package/tools/ralph-external/lib/worker-termination.mjs +15 -8
  128. package/vscode-extension/schemas/aiwg.config.v1.json +2 -4
@@ -0,0 +1,29 @@
1
+ // Parse JSON settings with string-aware comment handling.
2
+ /**
3
+ * JSONC-tolerant parse. String-aware twin of `stripJsonComments` in
4
+ * tools/agents/providers/base.mjs: `//` in URLs and `/*` in glob
5
+ * matchers survive.
6
+ */
7
+ export function parseJson(raw) {
8
+ const text = String(raw);
9
+ let out = '';
10
+ let i = 0;
11
+ while (i < text.length) {
12
+ const ch = text[i];
13
+ if (ch === '"') {
14
+ let j = i + 1;
15
+ while (j < text.length && text[j] !== '"') j += text[j] === '\\' ? 2 : 1;
16
+ out += text.slice(i, j + 1);
17
+ i = j + 1;
18
+ } else if (ch === '/' && text[i + 1] === '/') {
19
+ while (i < text.length && text[i] !== '\n') i++;
20
+ } else if (ch === '/' && text[i + 1] === '*') {
21
+ const end = text.indexOf('*/', i + 2);
22
+ i = end === -1 ? text.length : end + 2;
23
+ } else {
24
+ out += ch;
25
+ i++;
26
+ }
27
+ }
28
+ return JSON.parse(out);
29
+ }
@@ -13,34 +13,7 @@ const MUSE_HOOKS_SIDECAR_REL = join('.muse', '.aiwg-hooks.json');
13
13
 
14
14
  const MUSE_VERSION_TIMEOUT_MS = 5_000;
15
15
 
16
- /**
17
- * JSONC-tolerant parse. String-aware twin of `stripJsonComments` in
18
- * tools/agents/providers/base.mjs: `//` in URLs and `/*` in glob
19
- * matchers survive.
20
- */
21
- function parseJson(raw) {
22
- const text = String(raw);
23
- let out = '';
24
- let i = 0;
25
- while (i < text.length) {
26
- const ch = text[i];
27
- if (ch === '"') {
28
- let j = i + 1;
29
- while (j < text.length && text[j] !== '"') j += text[j] === '\\' ? 2 : 1;
30
- out += text.slice(i, j + 1);
31
- i = j + 1;
32
- } else if (ch === '/' && text[i + 1] === '/') {
33
- while (i < text.length && text[i] !== '\n') i++;
34
- } else if (ch === '/' && text[i + 1] === '*') {
35
- const end = text.indexOf('*/', i + 2);
36
- i = end === -1 ? text.length : end + 2;
37
- } else {
38
- out += ch;
39
- i++;
40
- }
41
- }
42
- return JSON.parse(out);
43
- }
16
+ import { parseJson } from './json-document.mjs';
44
17
 
45
18
  function deepEqual(a, b) {
46
19
  return JSON.stringify(a) === JSON.stringify(b);
@@ -2,6 +2,13 @@
2
2
  import { workerReviewLineageDiagnostics } from '../models/worker-review-lineage.js';
3
3
  import { WorkerContractError, } from './types.js';
4
4
  function fail(message) { throw new WorkerContractError('OG_CONTRACT_INVALID', message); }
5
+ /** Read an existing verifier verdict; never promote worker completion to acceptance. */
6
+ export function hasIndependentWorkerAcceptance(verification) {
7
+ return verification.status === 'accepted'
8
+ && !!verification.reviewRounds?.length
9
+ && verification.evidence.length > 0
10
+ && workerReviewEvidenceErrors(verification).length === 0;
11
+ }
5
12
  /** Additional relational checks after JSON Schema shape validation. */
6
13
  export function workerReviewEvidenceErrors(verification) {
7
14
  const errors = [];
@@ -42,10 +42,10 @@ export function resolveWorkerPlan(snapshot, request, ceilingDefaults = {}) {
42
42
  policy: structuredClone(policy), origins: structuredClone(snapshot.models.workerPolicyOrigins),
43
43
  choice: null, capacity: 'conductor-guidance-only', ceilings: {},
44
44
  };
45
- if (snapshot.hostResources) {
46
- plan.resources = hostResourceReport({ config: snapshot.config, live: snapshot.hostResources });
47
- plan.slots = plan.resources.slots;
48
- }
45
+ const resourceInput = { config: snapshot.config, live: snapshot.hostResources ?? { supported: false, reason: 'host snapshot missing' },
46
+ now: () => Date.parse(request.now) };
47
+ plan.resources = hostResourceReport(resourceInput);
48
+ plan.slots = plan.resources.slots;
49
49
  const diagnostic = (code, pointer, message) => ({ code, pointer, message });
50
50
  const block = (code, pointer, message) => {
51
51
  plan.diagnostics.push(diagnostic(code, pointer, message));
@@ -285,7 +285,7 @@ export function resolveWorkerPlan(snapshot, request, ceilingDefaults = {}) {
285
285
  const caps = [...capEntries.map(([, value]) => value), snapshot.constraints?.maxParallel, request.maxParallel]
286
286
  .filter((value) => value !== undefined);
287
287
  // The shared report owns project/group caps; the remaining entries scope the tuple.
288
- const resources = snapshot.hostResources && hostResourceReport({ config: snapshot.config, live: snapshot.hostResources, group: groupId,
288
+ const resources = hostResourceReport({ ...resourceInput, group: groupId,
289
289
  caps: [...capEntries.slice(3).map(([threshold, limit]) => ({ threshold, limit })),
290
290
  { threshold: 'constraints.maxParallel', limit: snapshot.constraints?.maxParallel, running: 0 },
291
291
  { threshold: 'request.maxParallel', limit: request.maxParallel, running: 0 }] });
@@ -0,0 +1,34 @@
1
+ // Preserve source skill ownership when emitting command wrappers and prompts.
2
+ import { createHash } from 'node:crypto';
3
+ import fs from 'node:fs/promises';
4
+ import path from 'node:path';
5
+ import { extractFrameworkSlug, mergeArtifactOwnership } from '../providers/skill-ownership.mjs';
6
+ export async function recordManagedCommands(targetDir, entries, version, source) {
7
+ if (!entries.length)
8
+ return;
9
+ const sidecarPath = path.join(targetDir, '.aiwg-manifest.json');
10
+ let receipt = { managed: {} };
11
+ try {
12
+ receipt = JSON.parse(await fs.readFile(sidecarPath, 'utf8'));
13
+ }
14
+ catch (error) {
15
+ if (error.code !== 'ENOENT')
16
+ throw error;
17
+ }
18
+ for (const entry of entries) {
19
+ let skill;
20
+ try {
21
+ skill = JSON.parse(await fs.readFile(path.join(path.dirname(entry.sourcePath), '.aiwg-manifest.json'), 'utf8'));
22
+ }
23
+ catch { /* Canonical sources may not be deployed skills. */ }
24
+ const sourceEntry = skill?.managed?.['SKILL.md'];
25
+ const owners = sourceEntry?.owners || [sourceEntry?.frameworkSlug
26
+ || extractFrameworkSlug(`${skill?.skillSource}/SKILL.md`) || extractFrameworkSlug(entry.sourcePath) || source];
27
+ const record = { hash: `sha256:${createHash('sha256').update(entry.content).digest('hex')}`,
28
+ source, version, kind: 'skill-command', sourcePath: entry.sourcePath,
29
+ frameworkSlug: sourceEntry?.frameworkSlug || extractFrameworkSlug(`${skill?.skillSource}/SKILL.md`) || extractFrameworkSlug(entry.sourcePath) || owners[0] };
30
+ receipt.managed[entry.filename] = owners.reduce((current, owner) => mergeArtifactOwnership(receipt.managed[entry.filename], current, owner), record);
31
+ }
32
+ await fs.writeFile(sidecarPath, `${JSON.stringify(receipt, null, 2)}\n`);
33
+ }
34
+ //# sourceMappingURL=command-ownership.js.map
@@ -0,0 +1,197 @@
1
+ // ============================================
2
+ // Provider Configuration
3
+ // ============================================
4
+ /**
5
+ * Providers that need command files generated from skills.
6
+ *
7
+ * Providers not listed here get skills deployed natively (no translation needed).
8
+ */
9
+ const PROVIDERS_NEEDING_COMMANDS = new Set([
10
+ 'factory',
11
+ 'opencode', // OpenCode scans .opencode/command/**/*.md via ConfigCommand.load() (PUW-006 #1107)
12
+ 'warp',
13
+ 'windsurf',
14
+ 'copilot',
15
+ 'codex',
16
+ 'openclaw',
17
+ ]);
18
+ /**
19
+ * Providers where skills are deployed natively (no command generation needed).
20
+ */
21
+ const SKILLS_ONLY_PROVIDERS = new Set([
22
+ 'antigravity',
23
+ 'claude',
24
+ 'cursor',
25
+ 'grokbot',
26
+ 'hermes',
27
+ 'muse', // #236: skills deploy natively; no command translation (indexed-only agents/commands/rules)
28
+ 'openhuman',
29
+ 'pi',
30
+ 'omp',
31
+ ]);
32
+ /**
33
+ * Check if a provider needs command files generated from skills.
34
+ */
35
+ export function providerNeedsCommands(provider) {
36
+ return PROVIDERS_NEEDING_COMMANDS.has(provider);
37
+ }
38
+ /**
39
+ * Check if a provider uses skills natively (no command translation).
40
+ */
41
+ export function providerUsesSkillsNatively(provider) {
42
+ return SKILLS_ONLY_PROVIDERS.has(provider);
43
+ }
44
+ // ============================================
45
+ // Frontmatter Parsing
46
+ // ============================================
47
+ /**
48
+ * Parse YAML-like frontmatter from a SKILL.md file.
49
+ *
50
+ * This is a lightweight parser that handles the subset of YAML used in
51
+ * SKILL.md frontmatter. For full YAML support, a library like js-yaml
52
+ * would be needed, but the frontmatter format is simple enough for this.
53
+ */
54
+ export function parseFrontmatter(content) {
55
+ const fmMatch = content.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]*)$/);
56
+ if (!fmMatch) {
57
+ return { frontmatter: {}, body: content };
58
+ }
59
+ const fmRaw = fmMatch[1];
60
+ const body = fmMatch[2];
61
+ const frontmatter = {};
62
+ // Parse top-level keys
63
+ const lines = fmRaw.split('\n');
64
+ let i = 0;
65
+ while (i < lines.length) {
66
+ const line = lines[i];
67
+ // description: ...
68
+ const descMatch = line.match(/^description:\s*(.+)/);
69
+ if (descMatch) {
70
+ frontmatter.description = descMatch[1].trim();
71
+ i++;
72
+ continue;
73
+ }
74
+ // userInvocable: false
75
+ const uiMatch = line.match(/^userInvocable:\s*(true|false)/i);
76
+ if (uiMatch) {
77
+ frontmatter.userInvocable = uiMatch[1].toLowerCase() === 'true';
78
+ i++;
79
+ continue;
80
+ }
81
+ // user-invocable: false (kebab-case variant)
82
+ const uiKebabMatch = line.match(/^user-invocable:\s*(true|false)/i);
83
+ if (uiKebabMatch) {
84
+ frontmatter.userInvocable = uiKebabMatch[1].toLowerCase() === 'true';
85
+ i++;
86
+ continue;
87
+ }
88
+ // effort: N
89
+ const effortMatch = line.match(/^effort:\s*(\d+)/);
90
+ if (effortMatch) {
91
+ frontmatter.effort = parseInt(effortMatch[1], 10);
92
+ i++;
93
+ continue;
94
+ }
95
+ // context: fork|inherit
96
+ const ctxMatch = line.match(/^context:\s*(\w+)/);
97
+ if (ctxMatch) {
98
+ frontmatter.context = ctxMatch[1];
99
+ i++;
100
+ continue;
101
+ }
102
+ // disableModelInvocation: true
103
+ const dmiMatch = line.match(/^(?:disableModelInvocation|disable-model-invocation):\s*(true|false)/i);
104
+ if (dmiMatch) {
105
+ frontmatter.disableModelInvocation = dmiMatch[1].toLowerCase() === 'true';
106
+ i++;
107
+ continue;
108
+ }
109
+ // allowed-tools: (top-level, for the skill itself)
110
+ const atMatch = line.match(/^allowed-tools:\s*(.+)/);
111
+ if (atMatch) {
112
+ frontmatter.allowedTools = atMatch[1].trim();
113
+ i++;
114
+ continue;
115
+ }
116
+ // commandHint: block
117
+ if (line.match(/^commandHint:\s*$/)) {
118
+ const hint = {};
119
+ i++;
120
+ while (i < lines.length && lines[i].match(/^\s+/)) {
121
+ const hintLine = lines[i].trim();
122
+ const ahMatch = hintLine.match(/^argumentHint:\s*(.+)/);
123
+ if (ahMatch) {
124
+ hint.argumentHint = ahMatch[1].trim();
125
+ i++;
126
+ continue;
127
+ }
128
+ const hatMatch = hintLine.match(/^allowedTools:\s*(.+)/);
129
+ if (hatMatch) {
130
+ hint.allowedTools = hatMatch[1].trim();
131
+ i++;
132
+ continue;
133
+ }
134
+ const tmplMatch = hintLine.match(/^template:\s*(.+)/);
135
+ if (tmplMatch) {
136
+ hint.template = tmplMatch[1].trim();
137
+ i++;
138
+ continue;
139
+ }
140
+ const modMatch = hintLine.match(/^model:\s*(.+)/);
141
+ if (modMatch) {
142
+ hint.model = modMatch[1].trim();
143
+ i++;
144
+ continue;
145
+ }
146
+ const roleMatch = hintLine.match(/^modelRole:\s*(reasoning|coding|efficiency)\s*$/);
147
+ if (roleMatch) {
148
+ hint.modelRole = roleMatch[1];
149
+ i++;
150
+ continue;
151
+ }
152
+ const tierMatch = hintLine.match(/^modelTier:\s*(economy|standard|premium)\s*$/);
153
+ if (tierMatch) {
154
+ hint.modelTier = tierMatch[1];
155
+ i++;
156
+ continue;
157
+ }
158
+ const effortMatch = hintLine.match(/^modelEffort:\s*(minimal|low|medium|high|xhigh)\s*$/);
159
+ if (effortMatch) {
160
+ hint.modelEffort = effortMatch[1];
161
+ i++;
162
+ continue;
163
+ }
164
+ const rationaleMatch = hintLine.match(/^modelRationale:\s*(.+)$/);
165
+ if (rationaleMatch) {
166
+ hint.modelRationale = rationaleMatch[1].trim();
167
+ i++;
168
+ continue;
169
+ }
170
+ const catMatch = hintLine.match(/^category:\s*(.+)/);
171
+ if (catMatch) {
172
+ hint.category = catMatch[1].trim();
173
+ i++;
174
+ continue;
175
+ }
176
+ const orchMatch = hintLine.match(/^orchestration:\s*(true|false)/i);
177
+ if (orchMatch) {
178
+ hint.orchestration = orchMatch[1].toLowerCase() === 'true';
179
+ i++;
180
+ continue;
181
+ }
182
+ const cliMatch = hintLine.match(/^cliDisabled:\s*(true|false)/i);
183
+ if (cliMatch) {
184
+ hint.cliDisabled = cliMatch[1].toLowerCase() === 'true';
185
+ i++;
186
+ continue;
187
+ }
188
+ i++;
189
+ }
190
+ frontmatter.commandHint = hint;
191
+ continue;
192
+ }
193
+ i++;
194
+ }
195
+ return { frontmatter, body };
196
+ }
197
+ //# sourceMappingURL=skill-command-frontmatter.js.map
@@ -11,9 +11,11 @@
11
11
  * @implements .aiwg/architecture/adr-skills-canonical-extension-type.md
12
12
  * @issue #550
13
13
  */
14
- import { createHash } from 'node:crypto';
15
14
  import fs from 'fs/promises';
16
15
  import path from 'path';
16
+ export { parseFrontmatter, providerNeedsCommands, providerUsesSkillsNatively } from './skill-command-frontmatter.js';
17
+ import { recordManagedCommands } from './command-ownership.js';
18
+ import { parseFrontmatter, providerNeedsCommands } from './skill-command-frontmatter.js';
17
19
  /**
18
20
  * Ownership signal for generated command files (#2507).
19
21
  *
@@ -24,7 +26,6 @@ import path from 'path';
24
26
  * same signals as any other deployed artifact, tagged `skill-command` so the
25
27
  * flat-command prune leaves them to the skills prune that governs their source.
26
28
  */
27
- const MANAGED_SIDECAR = '.aiwg-manifest.json';
28
29
  const MANAGED_MARKER_PATTERN = /^(?:<!--\s*aiwg:managed\s|#\s*aiwg:managed\s)/m;
29
30
  function addManagedMarker(content, version, source) {
30
31
  if (MANAGED_MARKER_PATTERN.test(content))
@@ -35,235 +36,8 @@ function addManagedMarker(content, version, source) {
35
36
  return `<!-- aiwg:managed v${version} ${source} -->\n${content}`;
36
37
  }
37
38
  /**
38
- * Merge generated command entries into a directory's managed sidecar.
39
- *
40
- * Best-effort: a translation that cannot record ownership still produced a
41
- * usable command file, so a sidecar failure must not fail the deploy.
42
- */
43
- async function recordManagedCommands(targetDir, entries, version, source) {
44
- if (entries.length === 0)
45
- return;
46
- const sidecarPath = path.join(targetDir, MANAGED_SIDECAR);
47
- let sidecar = { managed: {} };
48
- try {
49
- const parsed = JSON.parse(await fs.readFile(sidecarPath, 'utf-8'));
50
- if (parsed && typeof parsed === 'object' && parsed.managed)
51
- sidecar = parsed;
52
- }
53
- catch {
54
- // No sidecar yet, or unreadable — start a fresh managed map.
55
- }
56
- for (const entry of entries) {
57
- sidecar.managed[entry.filename] = {
58
- hash: `sha256:${createHash('sha256').update(entry.content).digest('hex')}`,
59
- source,
60
- version,
61
- kind: 'skill-command',
62
- };
63
- }
64
- try {
65
- await fs.writeFile(sidecarPath, `${JSON.stringify(sidecar, null, 2)}\n`, 'utf-8');
66
- }
67
- catch {
68
- // Non-fatal — the command files themselves are already written.
69
- }
70
- }
71
- // ============================================
72
- // Provider Configuration
73
- // ============================================
74
- /**
75
- * Providers that need command files generated from skills.
76
- *
77
- * Providers not listed here get skills deployed natively (no translation needed).
78
- */
79
- const PROVIDERS_NEEDING_COMMANDS = new Set([
80
- 'factory',
81
- 'opencode', // OpenCode scans .opencode/command/**/*.md via ConfigCommand.load() (PUW-006 #1107)
82
- 'warp',
83
- 'windsurf',
84
- 'copilot',
85
- 'codex',
86
- 'openclaw',
87
- ]);
88
- /**
89
- * Providers where skills are deployed natively (no command generation needed).
90
- */
91
- const SKILLS_ONLY_PROVIDERS = new Set([
92
- 'antigravity',
93
- 'claude',
94
- 'cursor',
95
- 'grokbot',
96
- 'hermes',
97
- 'muse', // #236: skills deploy natively; no command translation (indexed-only agents/commands/rules)
98
- 'openhuman',
99
- 'pi',
100
- 'omp',
101
- ]);
102
- /**
103
- * Check if a provider needs command files generated from skills.
104
- */
105
- export function providerNeedsCommands(provider) {
106
- return PROVIDERS_NEEDING_COMMANDS.has(provider);
107
- }
108
- /**
109
- * Check if a provider uses skills natively (no command translation).
39
+ * Parsed SKILL.md frontmatter fields relevant to command translation
110
40
  */
111
- export function providerUsesSkillsNatively(provider) {
112
- return SKILLS_ONLY_PROVIDERS.has(provider);
113
- }
114
- // ============================================
115
- // Frontmatter Parsing
116
- // ============================================
117
- /**
118
- * Parse YAML-like frontmatter from a SKILL.md file.
119
- *
120
- * This is a lightweight parser that handles the subset of YAML used in
121
- * SKILL.md frontmatter. For full YAML support, a library like js-yaml
122
- * would be needed, but the frontmatter format is simple enough for this.
123
- */
124
- export function parseFrontmatter(content) {
125
- const fmMatch = content.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]*)$/);
126
- if (!fmMatch) {
127
- return { frontmatter: {}, body: content };
128
- }
129
- const fmRaw = fmMatch[1];
130
- const body = fmMatch[2];
131
- const frontmatter = {};
132
- // Parse top-level keys
133
- const lines = fmRaw.split('\n');
134
- let i = 0;
135
- while (i < lines.length) {
136
- const line = lines[i];
137
- // description: ...
138
- const descMatch = line.match(/^description:\s*(.+)/);
139
- if (descMatch) {
140
- frontmatter.description = descMatch[1].trim();
141
- i++;
142
- continue;
143
- }
144
- // userInvocable: false
145
- const uiMatch = line.match(/^userInvocable:\s*(true|false)/i);
146
- if (uiMatch) {
147
- frontmatter.userInvocable = uiMatch[1].toLowerCase() === 'true';
148
- i++;
149
- continue;
150
- }
151
- // user-invocable: false (kebab-case variant)
152
- const uiKebabMatch = line.match(/^user-invocable:\s*(true|false)/i);
153
- if (uiKebabMatch) {
154
- frontmatter.userInvocable = uiKebabMatch[1].toLowerCase() === 'true';
155
- i++;
156
- continue;
157
- }
158
- // effort: N
159
- const effortMatch = line.match(/^effort:\s*(\d+)/);
160
- if (effortMatch) {
161
- frontmatter.effort = parseInt(effortMatch[1], 10);
162
- i++;
163
- continue;
164
- }
165
- // context: fork|inherit
166
- const ctxMatch = line.match(/^context:\s*(\w+)/);
167
- if (ctxMatch) {
168
- frontmatter.context = ctxMatch[1];
169
- i++;
170
- continue;
171
- }
172
- // disableModelInvocation: true
173
- const dmiMatch = line.match(/^(?:disableModelInvocation|disable-model-invocation):\s*(true|false)/i);
174
- if (dmiMatch) {
175
- frontmatter.disableModelInvocation = dmiMatch[1].toLowerCase() === 'true';
176
- i++;
177
- continue;
178
- }
179
- // allowed-tools: (top-level, for the skill itself)
180
- const atMatch = line.match(/^allowed-tools:\s*(.+)/);
181
- if (atMatch) {
182
- frontmatter.allowedTools = atMatch[1].trim();
183
- i++;
184
- continue;
185
- }
186
- // commandHint: block
187
- if (line.match(/^commandHint:\s*$/)) {
188
- const hint = {};
189
- i++;
190
- while (i < lines.length && lines[i].match(/^\s+/)) {
191
- const hintLine = lines[i].trim();
192
- const ahMatch = hintLine.match(/^argumentHint:\s*(.+)/);
193
- if (ahMatch) {
194
- hint.argumentHint = ahMatch[1].trim();
195
- i++;
196
- continue;
197
- }
198
- const hatMatch = hintLine.match(/^allowedTools:\s*(.+)/);
199
- if (hatMatch) {
200
- hint.allowedTools = hatMatch[1].trim();
201
- i++;
202
- continue;
203
- }
204
- const tmplMatch = hintLine.match(/^template:\s*(.+)/);
205
- if (tmplMatch) {
206
- hint.template = tmplMatch[1].trim();
207
- i++;
208
- continue;
209
- }
210
- const modMatch = hintLine.match(/^model:\s*(.+)/);
211
- if (modMatch) {
212
- hint.model = modMatch[1].trim();
213
- i++;
214
- continue;
215
- }
216
- const roleMatch = hintLine.match(/^modelRole:\s*(reasoning|coding|efficiency)\s*$/);
217
- if (roleMatch) {
218
- hint.modelRole = roleMatch[1];
219
- i++;
220
- continue;
221
- }
222
- const tierMatch = hintLine.match(/^modelTier:\s*(economy|standard|premium)\s*$/);
223
- if (tierMatch) {
224
- hint.modelTier = tierMatch[1];
225
- i++;
226
- continue;
227
- }
228
- const effortMatch = hintLine.match(/^modelEffort:\s*(minimal|low|medium|high|xhigh)\s*$/);
229
- if (effortMatch) {
230
- hint.modelEffort = effortMatch[1];
231
- i++;
232
- continue;
233
- }
234
- const rationaleMatch = hintLine.match(/^modelRationale:\s*(.+)$/);
235
- if (rationaleMatch) {
236
- hint.modelRationale = rationaleMatch[1].trim();
237
- i++;
238
- continue;
239
- }
240
- const catMatch = hintLine.match(/^category:\s*(.+)/);
241
- if (catMatch) {
242
- hint.category = catMatch[1].trim();
243
- i++;
244
- continue;
245
- }
246
- const orchMatch = hintLine.match(/^orchestration:\s*(true|false)/i);
247
- if (orchMatch) {
248
- hint.orchestration = orchMatch[1].toLowerCase() === 'true';
249
- i++;
250
- continue;
251
- }
252
- const cliMatch = hintLine.match(/^cliDisabled:\s*(true|false)/i);
253
- if (cliMatch) {
254
- hint.cliDisabled = cliMatch[1].toLowerCase() === 'true';
255
- i++;
256
- continue;
257
- }
258
- i++;
259
- }
260
- frontmatter.commandHint = hint;
261
- continue;
262
- }
263
- i++;
264
- }
265
- return { frontmatter, body };
266
- }
267
41
  // ============================================
268
42
  // Command Generation
269
43
  // ============================================
@@ -413,9 +187,9 @@ export async function translateSkillsToCommands(skillsDir, options) {
413
187
  const promptPath = path.join(promptsDir, `${skillName}.prompt.md`);
414
188
  await fs.mkdir(promptsDir, { recursive: true });
415
189
  await fs.writeFile(promptPath, commandContent, 'utf-8');
416
- promptEntries.push({ filename: `${skillName}.prompt.md`, content: commandContent });
190
+ promptEntries.push({ filename: `${skillName}.prompt.md`, content: commandContent, sourcePath: skillMdPath });
417
191
  }
418
- managedEntries.push({ filename: commandFilename, content: commandContent });
192
+ managedEntries.push({ filename: commandFilename, content: commandContent, sourcePath: skillMdPath });
419
193
  }
420
194
  result.translated.push(translated);
421
195
  if (options.verbose) {
@@ -0,0 +1,26 @@
1
+ // Refresh recorded context digests through the same rollback-safe writer.
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ export function refreshRecordedContextOutput(file, previousHash, currentHash, write) {
5
+ if (!previousHash || previousHash === currentHash || path.basename(file) === '.aiwg-manifest.json')
6
+ return;
7
+ const sidecar = path.join(path.dirname(file), '.aiwg', '.aiwg-manifest.json');
8
+ let receipt;
9
+ try {
10
+ if (!fs.lstatSync(path.dirname(sidecar)).isDirectory() || fs.lstatSync(path.dirname(sidecar)).isSymbolicLink()
11
+ || !fs.lstatSync(sidecar).isFile() || fs.lstatSync(sidecar).isSymbolicLink())
12
+ return;
13
+ receipt = JSON.parse(fs.readFileSync(sidecar, 'utf8'));
14
+ }
15
+ catch (error) {
16
+ if (['ENOENT', 'ENOTDIR'].includes(error.code || '') || error instanceof SyntaxError)
17
+ return;
18
+ throw error;
19
+ }
20
+ const entry = receipt.scope === 'project' && receipt.managed?.[path.basename(file)];
21
+ if (!entry?.owners?.length || entry.hash !== `sha256:${previousHash}`)
22
+ return;
23
+ entry.hash = `sha256:${currentHash}`;
24
+ write(sidecar, `${JSON.stringify(receipt, null, 2)}\n`);
25
+ }
26
+ //# sourceMappingURL=context-output-ownership.js.map
@@ -0,0 +1,19 @@
1
+ import type { PathLike } from 'node:fs';
2
+ export interface DeploymentOwnershipOptions {
3
+ dryRun?: boolean;
4
+ claimUnchangedSettings?: boolean;
5
+ onlyDeclared?: boolean;
6
+ srcRoot?: string;
7
+ target?: string;
8
+ writeReceipt?: (file: string, content: string) => void;
9
+ mode?: string;
10
+ frameworkSlug?: string;
11
+ writtenFiles?: string[];
12
+ logicalInputPath?: (file: string) => string;
13
+ }
14
+ export function deploymentOutputRoots(provider: { name: string; paths?: Record<string, string>; kernelSkillsPath?: string }, target: string): string[];
15
+ export function captureDeploymentOutputs(roots: PathLike[]): Map<string, Buffer>;
16
+ export function recordDeploymentOutputs(before: Map<string, Buffer>, roots: PathLike[], opts?: DeploymentOwnershipOptions): void;
17
+ export function refreshSettingsDigests(record: { settings?: Record<string, unknown> }): void;
18
+
19
+ export function deploymentOwner(opts: DeploymentOwnershipOptions): string | undefined;