@aiwg/cli 2026.10.16 → 2026.10.19
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.
- package/agentic/code/providers/capability-matrix.yaml +51 -0
- package/agentic/code/providers/flue/README.md +62 -0
- package/agentic/code/providers/flue/templates/aiwg/tools.ts +120 -0
- package/agentic/code/providers/model-capabilities.v1.json +23 -0
- package/agentic/code/providers/model-catalog.v1.json +9 -0
- package/dist/src/artifacts/corpus-tools/resolve.js +28 -6
- package/dist/src/artifacts/query-engine-corpus.js +217 -0
- package/dist/src/artifacts/query-engine-discover-output.js +229 -0
- package/dist/src/artifacts/query-engine-discover.js +285 -0
- package/dist/src/artifacts/query-engine-entries.js +188 -0
- package/dist/src/artifacts/query-engine-index.js +249 -0
- package/dist/src/artifacts/query-engine-matching.js +143 -0
- package/dist/src/artifacts/query-engine-options.js +2 -0
- package/dist/src/artifacts/query-engine-rules.js +202 -0
- package/dist/src/artifacts/query-engine-scoring.js +436 -0
- package/dist/src/artifacts/query-engine-show-card.js +194 -0
- package/dist/src/artifacts/query-engine-show-load.js +211 -0
- package/dist/src/artifacts/query-engine-show.js +300 -0
- package/dist/src/artifacts/query-engine.js +7 -2576
- package/dist/src/cli/handlers/help.js +1 -1
- package/dist/src/cli/handlers/init.js +1 -0
- package/dist/src/cli/handlers/mc-agents.js +111 -0
- package/dist/src/cli/handlers/mc-args.js +54 -0
- package/dist/src/cli/handlers/mc-control.js +227 -0
- package/dist/src/cli/handlers/mc-dispatch.js +203 -0
- package/dist/src/cli/handlers/mc-help.js +171 -0
- package/dist/src/cli/handlers/mc-run.js +343 -0
- package/dist/src/cli/handlers/mc-session.js +138 -0
- package/dist/src/cli/handlers/mc-status.js +258 -0
- package/dist/src/cli/handlers/mc-summary.js +43 -0
- package/dist/src/cli/handlers/mc-types.js +3 -0
- package/dist/src/cli/handlers/mc-worker.js +205 -0
- package/dist/src/cli/handlers/mc.js +12 -1665
- package/dist/src/cli/handlers/models-refusal.js +13 -0
- package/dist/src/cli/handlers/models.js +2 -1
- package/dist/src/cli/handlers/remove-bundled.js +133 -0
- package/dist/src/cli/handlers/remove-options.js +31 -0
- package/dist/src/cli/handlers/remove-user.js +174 -0
- package/dist/src/cli/handlers/remove.js +201 -0
- package/dist/src/cli/handlers/subcommands-bundles.js +257 -0
- package/dist/src/cli/handlers/subcommands-discovery.js +165 -0
- package/dist/src/cli/handlers/subcommands-list-format.js +129 -0
- package/dist/src/cli/handlers/subcommands-list.js +250 -0
- package/dist/src/cli/handlers/subcommands-plugins.js +213 -0
- package/dist/src/cli/handlers/subcommands-quickref.js +58 -0
- package/dist/src/cli/handlers/subcommands-rlm.js +113 -0
- package/dist/src/cli/handlers/subcommands-services.js +66 -0
- package/dist/src/cli/handlers/subcommands-storage.js +259 -0
- package/dist/src/cli/handlers/subcommands.js +18 -1984
- package/dist/src/cli/handlers/use.js +11 -5
- package/dist/src/cli/scope-resolver.js +1 -142
- package/dist/src/cli/services/deployment-verification.js +3 -0
- package/dist/src/cli/user-scope-mirror.js +173 -0
- package/dist/src/config/dispatch-host-thresholds.js +2 -0
- package/dist/src/config/dispatch-thresholds-runtime.mjs +4 -0
- package/dist/src/config/host-resource-report.d.mts +5 -0
- package/dist/src/config/host-resource-report.mjs +36 -6
- package/dist/src/config/host-resource-runtime.d.mts +3 -0
- package/dist/src/config/host-resource-runtime.mjs +9 -6
- package/dist/src/decision/ensemble-study/artifacts.js +7 -0
- package/dist/src/decision/ensemble-study/gate-policy.js +58 -0
- package/dist/src/decision/ensemble-study/gates.js +78 -0
- package/dist/src/decision/ensemble-study/protocol.js +18 -21
- package/dist/src/decision/ensemble-study/score.js +3 -2
- package/dist/src/decision/ensemble-study/statistics.js +7 -26
- package/dist/src/decision/sensitivity/comparative-gates.js +135 -0
- package/dist/src/decision/sensitivity/comparative.js +18 -41
- package/dist/src/extensions/claude-hooks-installer.js +18 -0
- package/dist/src/gates/evaluate.js +2 -358
- package/dist/src/gates/observations.js +363 -0
- package/dist/src/gates/pack-composition.js +270 -0
- package/dist/src/gates/pack-tightening.js +197 -0
- package/dist/src/gates/pack-validation.js +262 -0
- package/dist/src/gates/registry-error.js +5 -0
- package/dist/src/gates/registry.js +13 -685
- package/dist/src/mcp/json-document.mjs +29 -0
- package/dist/src/mcp/muse-native-config.mjs +1 -28
- package/dist/src/memory/provider-memory-adapter.js +1 -0
- package/dist/src/mission-protocol/worker-review-gate.js +7 -0
- package/dist/src/models/model-capabilities.v1.json +23 -0
- package/dist/src/models/model-catalog.v1.json +9 -0
- package/dist/src/models/policy-resources.js +1 -1
- package/dist/src/models/worker-plan.js +5 -5
- package/dist/src/plugin/command-ownership.js +34 -0
- package/dist/src/plugin/skill-command-frontmatter.js +197 -0
- package/dist/src/plugin/skill-command-translator.js +6 -232
- package/dist/src/providers/capability-matrix.yaml +51 -0
- package/dist/src/providers/context-output-ownership.js +26 -0
- package/dist/src/providers/deployment-ownership.d.mts +20 -0
- package/dist/src/providers/deployment-ownership.mjs +236 -0
- package/dist/src/providers/deployment-removal.js +222 -0
- package/dist/src/providers/provider-context-contracts.js +8 -0
- package/dist/src/providers/provider-definition-schema.js +1 -0
- package/dist/src/providers/provider-definitions.js +1 -0
- package/dist/src/providers/provider-seeds-3.js +18 -0
- package/dist/src/providers/removal-transaction.js +86 -0
- package/dist/src/providers/settings-document.d.mts +3 -0
- package/dist/src/providers/settings-document.mjs +47 -0
- package/dist/src/providers/settings-removal.js +190 -0
- package/dist/src/providers/skill-ownership.d.mts +20 -2
- package/dist/src/providers/skill-ownership.mjs +12 -4
- package/dist/src/providers/transformation-receipt-integration.js +15 -271
- package/dist/src/providers/transformation-receipt-outputs.js +99 -0
- package/dist/src/providers/transformation-receipt-source.js +194 -0
- package/dist/src/research/identity.js +8 -2
- package/dist/src/research/reference-match.js +66 -8
- package/dist/src/rules/activation.mjs +15 -6
- package/dist/src/rules/core-startup.mjs +2 -2
- package/dist/src/serve/mission-conductor.js +4 -0
- package/dist/src/serve/mission-summary.js +56 -0
- package/dist/src/skills/deployment-ownership.js +2 -2
- package/dist/src/skills/deployment-policy.js +9 -0
- package/dist/src/smiths/context-pipeline/aiwg-md.js +23 -0
- package/dist/src/smiths/context-pipeline/context-file-safety.js +3 -0
- package/dist/src/smiths/context-pipeline/flue-context.js +25 -0
- package/dist/src/smiths/context-pipeline/generator.js +7 -2
- package/dist/src/smiths/context-pipeline/workspace-bootstrap.js +9 -7
- package/dist/src/smiths/hook-bridge/index.js +9 -0
- package/package.json +5 -1
- package/schemas/decision/D17StudyProtocol.v1.schema.json +39 -67
- package/tools/agents/deploy-agents.mjs +21 -680
- package/tools/agents/deploy-command-mirrors.mjs +229 -0
- package/tools/agents/deploy-options.mjs +267 -0
- package/tools/agents/deploy-support.mjs +165 -0
- package/tools/agents/providers/base-addon-discovery.mjs +139 -0
- package/tools/agents/providers/base-behaviors.mjs +168 -0
- package/tools/agents/providers/base-context.mjs +205 -0
- package/tools/agents/providers/base-contract.mjs +116 -0
- package/tools/agents/providers/base-files.mjs +252 -0
- package/tools/agents/providers/base-flat-artifacts.mjs +233 -0
- package/tools/agents/providers/base-framework-discovery.mjs +309 -0
- package/tools/agents/providers/base-frontmatter.mjs +196 -0
- package/tools/agents/providers/base-inventory.mjs +269 -0
- package/tools/agents/providers/base-kernel-skills.mjs +354 -0
- package/tools/agents/providers/base-migrations.mjs +258 -0
- package/tools/agents/providers/base-models-platforms.mjs +273 -0
- package/tools/agents/providers/base-rule-index.mjs +450 -0
- package/tools/agents/providers/base-runtime.mjs +60 -0
- package/tools/agents/providers/base-skill-copy.mjs +273 -0
- package/tools/agents/providers/base.mjs +16 -3364
- package/tools/agents/providers/claude-post-deploy.mjs +10 -2
- package/tools/agents/providers/flue-project.mjs +79 -0
- package/tools/agents/providers/flue-specialists.mjs +64 -0
- package/tools/agents/providers/flue.mjs +50 -0
- package/tools/agents/providers/hermes-startup.mjs +0 -5
- package/tools/agents/providers/muse.mjs +7 -2
- package/tools/agents/providers/rule-delivery-surface.mjs +33 -5
- package/tools/agents/providers/rule-deployment-commit.mjs +19 -15
- package/tools/agents/providers/rule-deployment-prepare.mjs +13 -3
- package/tools/agents/providers/rule-projection.mjs +3 -0
- package/tools/agents/providers/rule-startup.mjs +3 -3
- package/tools/agents/use-rule-selection.mjs +17 -0
- package/tools/ralph-external/lib/worker-invocation-processes.mjs +4 -2
- package/tools/ralph-external/lib/worker-termination.mjs +15 -8
- package/vscode-extension/schemas/aiwg.config.v1.json +2 -4
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
// Shared provider rule index utilities.
|
|
2
|
+
import { DEFAULT_RULES_INLINE_BUDGET_TOKENS, fs, inferRuleActivation, parseRuleFrontmatter, path, resolveRulesInlineBudget } from './base-runtime.mjs';
|
|
3
|
+
import { resolveAiwgRoot } from './base-inventory.mjs';
|
|
4
|
+
import { addManagedMarker, listMdFiles } from './base-files.mjs';
|
|
5
|
+
import { discoverAddons } from './base-addon-discovery.mjs';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Get all rule files from all addons
|
|
10
|
+
* @param {string} srcRoot - Source root directory
|
|
11
|
+
* @param {string[]} excludeAddons - Addon names to exclude (default: none)
|
|
12
|
+
* @returns {string[]} - Array of rule file paths
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Read a rule's enforcement level from its `enforcement:` frontmatter
|
|
16
|
+
* (#1673). Returns 'critical' | 'high' | 'medium' | 'low' | null.
|
|
17
|
+
*/
|
|
18
|
+
export function ruleEnforcementLevel(content) {
|
|
19
|
+
const m = content.match(/^---\n([\s\S]*?)\n---/);
|
|
20
|
+
if (m) {
|
|
21
|
+
const e = m[1].match(/^enforcement:\s*([A-Za-z]+)/m);
|
|
22
|
+
if (e) return e[1].toLowerCase();
|
|
23
|
+
}
|
|
24
|
+
// Rules without frontmatter declare the level in the body header.
|
|
25
|
+
const body = content.match(/^\*\*Enforcement Level\*\*:\s*([A-Za-z]+)/m);
|
|
26
|
+
return body ? body[1].toLowerCase() : null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Default inline rule budget (#2562). Every inlined rule is loaded into every
|
|
32
|
+
* session AND every subagent dispatch, so the always-on set must leave room
|
|
33
|
+
* for the agent definition, the system prompt, and the task itself inside the
|
|
34
|
+
* standard 200K window. 64K tokens (~256 KB) keeps a full CRITICAL+HIGH
|
|
35
|
+
* deployment dispatchable; `AIWG_RULES_INLINE_BUDGET_TOKENS=0` disables the
|
|
36
|
+
* budget, any other value overrides it.
|
|
37
|
+
*/
|
|
38
|
+
export function resolveRulesInlineBudgetTokens(env = process.env) {
|
|
39
|
+
return resolveRulesInlineBudget({}, env);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
/** Sidecar recording which rules the inline budget moved on demand (#2562). */
|
|
44
|
+
export const RULE_BUDGET_SIDECAR = '.aiwg-rules-budget.json';
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
export function readRuleBudgetSidecar(destDir) {
|
|
48
|
+
try {
|
|
49
|
+
const parsed = JSON.parse(fs.readFileSync(path.join(destDir, RULE_BUDGET_SIDECAR), 'utf8'));
|
|
50
|
+
if (!parsed || typeof parsed !== 'object' || !Array.isArray(parsed.demoted)) return null;
|
|
51
|
+
return { budgetTokens: Number(parsed.budgetTokens) || 0, demoted: parsed.demoted.map(String) };
|
|
52
|
+
} catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
// Compatibility exports: budgets never change selection or retain demotions.
|
|
59
|
+
export function reconcileInlineRuleBudget(destDir, budgetTokens, opts = {}) {
|
|
60
|
+
if (!opts.dryRun) fs.rmSync(path.join(destDir, RULE_BUDGET_SIDECAR), { force: true });
|
|
61
|
+
return { demoted: [], removed: [] };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function applyInlineRuleBudget(ruleFiles) {
|
|
65
|
+
return { inline: [...(ruleFiles || [])], demoted: [] };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Tier gate (#1673, enforcement-tiered deployment ADR). Only CRITICAL and HIGH
|
|
71
|
+
* rules are inlined into a provider's always-on rule directory; MEDIUM/LOW are
|
|
72
|
+
* left on-demand (reachable via `aiwg show rule <name> --body` and the assembled
|
|
73
|
+
* RULES-INDEX pointer index). Index files and rules with no enforcement marker
|
|
74
|
+
* default to always-on, so an un-triaged or structural file is never dropped.
|
|
75
|
+
*/
|
|
76
|
+
export function isAlwaysOnRule(filePath) {
|
|
77
|
+
const base = path.basename(filePath);
|
|
78
|
+
if (base === 'RULES-INDEX.md' || base === 'RULES-ONDEMAND.md') return true;
|
|
79
|
+
try {
|
|
80
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
81
|
+
const parsed = parseRuleFrontmatter(content);
|
|
82
|
+
if (!parsed.valid) throw new Error(`${filePath}: ${parsed.diagnostics.map(d => d.message).join('; ')}`);
|
|
83
|
+
const activation = parsed.rule.tagged ? parsed.rule.activation : inferRuleActivation(ruleEnforcementLevel(content));
|
|
84
|
+
return activation === 'kernel' || activation === 'paths';
|
|
85
|
+
} catch (error) {
|
|
86
|
+
if (error.code === 'ENOENT') return true;
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Enumerate MEDIUM/LOW rule files for the whole installed AIWG corpus.
|
|
94
|
+
* `srcRoot` may be the repository root or a bundled framework/addon/extension
|
|
95
|
+
* root during a multi-pass deploy; normalize it before discovery so a later
|
|
96
|
+
* pass never truncates an index written by an earlier pass.
|
|
97
|
+
*/
|
|
98
|
+
export function listOnDemandRuleFiles(srcRoot, excludeAddons = []) {
|
|
99
|
+
const out = [];
|
|
100
|
+
const aiwgRoot = resolveAiwgRoot(srcRoot) || srcRoot;
|
|
101
|
+
const consider = (dir) => {
|
|
102
|
+
if (!fs.existsSync(dir)) return;
|
|
103
|
+
for (const f of listMdFiles(dir)) {
|
|
104
|
+
const b = path.basename(f);
|
|
105
|
+
if (b === 'RULES-INDEX.md' || b === 'RULES-ONDEMAND.md') continue;
|
|
106
|
+
const parsed = parseRuleFrontmatter(fs.readFileSync(f, 'utf8'));
|
|
107
|
+
if (!parsed.valid) throw new Error(`${f}: invalid rule frontmatter`);
|
|
108
|
+
if (!parsed.rule.tagged && !isAlwaysOnRule(f)) out.push(f);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
for (const addon of discoverAddons(aiwgRoot)) {
|
|
112
|
+
if (excludeAddons.includes(addon.name)) continue;
|
|
113
|
+
consider(path.join(addon.path, 'rules'));
|
|
114
|
+
}
|
|
115
|
+
const codeRoot = path.join(aiwgRoot, 'agentic', 'code');
|
|
116
|
+
for (const fwDir of ['frameworks', 'extensions']) {
|
|
117
|
+
const base = path.join(codeRoot, fwDir);
|
|
118
|
+
if (!fs.existsSync(base)) continue;
|
|
119
|
+
for (const entry of fs.readdirSync(base, { withFileTypes: true })) {
|
|
120
|
+
if (entry.isDirectory()) consider(path.join(base, entry.name, 'rules'));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return out;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Sorted, de-duplicated rule names (basename minus `.md`) from a list of
|
|
129
|
+
* on-demand rule file paths. Shared by the discrete index writer and the
|
|
130
|
+
* aggregated-bridge section renderer so both stay in lock-step.
|
|
131
|
+
*/
|
|
132
|
+
export function onDemandRuleNames(onDemandFiles, exclude = []) {
|
|
133
|
+
const skip = new Set(exclude);
|
|
134
|
+
return [...new Set((onDemandFiles || []).map((f) => path.basename(f).replace(/\.md$/, '')))]
|
|
135
|
+
.filter((n) => !skip.has(n))
|
|
136
|
+
.sort();
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Render the on-demand rule list as a markdown section (#1675) for aggregated
|
|
142
|
+
* providers whose rules live in a single bridge file (WARP.md, AGENTS.md)
|
|
143
|
+
* rather than a discrete `RULES-ONDEMAND.md`. Returns '' when nothing is
|
|
144
|
+
* on-demand so callers can skip the section entirely. `exclude` drops names
|
|
145
|
+
* already inlined verbatim in the bridge (e.g. Warp's aiwg-utils set).
|
|
146
|
+
*/
|
|
147
|
+
export function renderOnDemandRuleSection(onDemandFiles, opts = {}) {
|
|
148
|
+
const names = onDemandRuleNames(onDemandFiles, opts.exclude || []);
|
|
149
|
+
if (names.length === 0) return '';
|
|
150
|
+
const heading = opts.heading || '## On-Demand Rules';
|
|
151
|
+
return [
|
|
152
|
+
heading,
|
|
153
|
+
'',
|
|
154
|
+
'These MEDIUM/LOW-enforcement rules are not inlined here, to keep the',
|
|
155
|
+
'always-on context small. They still apply when relevant — fetch any body',
|
|
156
|
+
'on demand:',
|
|
157
|
+
'',
|
|
158
|
+
'```bash',
|
|
159
|
+
'aiwg show rule <name> --body',
|
|
160
|
+
'```',
|
|
161
|
+
'',
|
|
162
|
+
...names.map((n) => `- \`${n}\` — \`aiwg show rule ${n} --body\``),
|
|
163
|
+
].join('\n');
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Write a compact on-demand rule index (#1673) into a provider's rule dir.
|
|
169
|
+
* Lists the MEDIUM/LOW rules that are NOT inlined at startup, with the
|
|
170
|
+
* `aiwg show rule <name> --body` fetch hint. Removes a stale index when empty.
|
|
171
|
+
*/
|
|
172
|
+
export function writeOnDemandRuleIndex(destDir, onDemandFiles, opts = {}) {
|
|
173
|
+
const indexPath = path.join(destDir, 'RULES-ONDEMAND.md');
|
|
174
|
+
const demotedNames = [...new Set([...onDemandRuleNames(opts.demotedFiles || []), ...(opts.demotedNames || [])])].sort();
|
|
175
|
+
const names = onDemandRuleNames(onDemandFiles, demotedNames);
|
|
176
|
+
if (names.length === 0 && demotedNames.length === 0) {
|
|
177
|
+
try {
|
|
178
|
+
if (fs.existsSync(indexPath) && !opts.dryRun) fs.rmSync(indexPath);
|
|
179
|
+
} catch { /* ignore */ }
|
|
180
|
+
return 0;
|
|
181
|
+
}
|
|
182
|
+
const lines = [
|
|
183
|
+
'# On-Demand Rules (not inlined at startup)',
|
|
184
|
+
'',
|
|
185
|
+
'These MEDIUM/LOW-enforcement rules are not loaded into every session, to keep',
|
|
186
|
+
'the standard-context startup budget small. They still apply when relevant —',
|
|
187
|
+
'fetch any rule body on demand:',
|
|
188
|
+
'',
|
|
189
|
+
'```bash',
|
|
190
|
+
'aiwg show rule <name> --body',
|
|
191
|
+
'```',
|
|
192
|
+
'',
|
|
193
|
+
...names.map((n) => `- \`${n}\` — \`aiwg show rule ${n} --body\``),
|
|
194
|
+
'',
|
|
195
|
+
];
|
|
196
|
+
if (demotedNames.length > 0) {
|
|
197
|
+
// HIGH rules that did not fit the inline budget (#2562). They remain
|
|
198
|
+
// binding; they are fetched on demand so subagent dispatch keeps working.
|
|
199
|
+
lines.push(
|
|
200
|
+
'## Binding rules moved on demand to fit the inline budget',
|
|
201
|
+
'',
|
|
202
|
+
'These HIGH-enforcement rules still apply in full. They are not inlined because the',
|
|
203
|
+
`always-on rule set would otherwise exceed the ${(opts.inlineBudgetTokens ?? DEFAULT_RULES_INLINE_BUDGET_TOKENS).toLocaleString()}-token inline budget`,
|
|
204
|
+
'(AIWG_RULES_INLINE_BUDGET_TOKENS) and break subagent dispatch with "Prompt is too long".',
|
|
205
|
+
'Fetch any of them before work they govern:',
|
|
206
|
+
'',
|
|
207
|
+
...demotedNames.map((n) => `- \`${n}\` — \`aiwg show rule ${n} --body\``),
|
|
208
|
+
'',
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
let content = lines.join('\n');
|
|
212
|
+
content = addManagedMarker(content, opts.deployVersion || 'unknown', opts.deploySource || 'bundled');
|
|
213
|
+
if (!opts.dryRun) fs.writeFileSync(indexPath, content, 'utf8');
|
|
214
|
+
return names.length + demotedNames.length;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
export function getAddonRuleFiles(srcRoot, excludeAddons = [], options = {}) {
|
|
219
|
+
const addons = discoverAddons(srcRoot, options);
|
|
220
|
+
const files = [];
|
|
221
|
+
|
|
222
|
+
for (const addon of addons) {
|
|
223
|
+
if (excludeAddons.includes(addon.name)) continue;
|
|
224
|
+
|
|
225
|
+
const rulesDir = path.join(addon.path, 'rules');
|
|
226
|
+
if (fs.existsSync(rulesDir)) {
|
|
227
|
+
for (const file of listMdFiles(rulesDir)) {
|
|
228
|
+
// Consolidation remains a legacy inventory policy. Explicit activation
|
|
229
|
+
// owns delivery, including the desired set used by the outer prune.
|
|
230
|
+
if (addon.manifest?.consolidation?.deployIndexOnly) {
|
|
231
|
+
const parsed = parseRuleFrontmatter(fs.readFileSync(file, 'utf8'));
|
|
232
|
+
if (!parsed.valid) throw new Error(`${file}: invalid rule frontmatter`);
|
|
233
|
+
if (!parsed.rule.tagged) continue;
|
|
234
|
+
}
|
|
235
|
+
files.push(file);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Activation selects bodies; only untagged rules use the old severity tier.
|
|
241
|
+
// The deploy enumeration and prune desired set must select the same bodies.
|
|
242
|
+
return files.filter(isAlwaysOnRule);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
// ============================================================================
|
|
247
|
+
// Consolidated Rules Deployment
|
|
248
|
+
// ============================================================================
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Load rules manifest from source directory.
|
|
252
|
+
* Inventory metadata only: delivery is decided by rule `activation` (rule-delivery.mjs);
|
|
253
|
+
* the former manifest `tiers` deploy policy was never consulted and was removed (#3450).
|
|
254
|
+
* @param {string} srcRoot - Source root directory
|
|
255
|
+
* @returns {object|null} - Parsed manifest or null if not found
|
|
256
|
+
*/
|
|
257
|
+
export function loadRulesManifest(srcRoot) {
|
|
258
|
+
const manifestPath = path.join(srcRoot, 'agentic', 'code', 'frameworks', 'sdlc-complete', 'rules', 'manifest.json');
|
|
259
|
+
if (!fs.existsSync(manifestPath)) return null;
|
|
260
|
+
try {
|
|
261
|
+
return JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
|
262
|
+
} catch (e) {
|
|
263
|
+
console.warn(`Warning: Could not parse rules manifest: ${e.message}`);
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Group rules by tier
|
|
271
|
+
* @param {Array} rules - Array of rule objects from manifest
|
|
272
|
+
* @returns {{core: Array, sdlc: Array, research: Array}}
|
|
273
|
+
*/
|
|
274
|
+
export function groupRulesByTier(rules) {
|
|
275
|
+
const groups = { core: [], sdlc: [], research: [] };
|
|
276
|
+
for (const rule of rules) {
|
|
277
|
+
const tier = rule.tier || 'sdlc';
|
|
278
|
+
if (groups[tier]) {
|
|
279
|
+
groups[tier].push(rule);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return groups;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Group rules by enforcement level within a tier
|
|
288
|
+
* @param {Array} rules - Array of rule objects
|
|
289
|
+
* @returns {{critical: Array, high: Array, medium: Array}}
|
|
290
|
+
*/
|
|
291
|
+
export function groupByEnforcement(rules) {
|
|
292
|
+
const groups = { critical: [], high: [], medium: [] };
|
|
293
|
+
for (const rule of rules) {
|
|
294
|
+
const level = (rule.enforcement || 'medium').toLowerCase();
|
|
295
|
+
if (groups[level]) {
|
|
296
|
+
groups[level].push(rule);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return groups;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Get the RULES-INDEX.md path for a component (framework or addon).
|
|
305
|
+
* Checks the component's manifest.json for consolidation.rulesIndex.
|
|
306
|
+
* @param {string} componentPath - Path to the component directory
|
|
307
|
+
* @returns {string|null} - Path to the component's RULES-INDEX.md or null
|
|
308
|
+
*/
|
|
309
|
+
export function getComponentRulesIndexPath(componentPath) {
|
|
310
|
+
const manifestPath = path.join(componentPath, 'manifest.json');
|
|
311
|
+
if (!fs.existsSync(manifestPath)) return null;
|
|
312
|
+
|
|
313
|
+
try {
|
|
314
|
+
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
|
315
|
+
const rulesIndex = manifest.consolidation?.rulesIndex;
|
|
316
|
+
if (!rulesIndex) return null;
|
|
317
|
+
|
|
318
|
+
const indexPath = path.join(componentPath, rulesIndex);
|
|
319
|
+
return fs.existsSync(indexPath) ? indexPath : null;
|
|
320
|
+
} catch (e) {
|
|
321
|
+
return null;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Assemble the deployed RULES-INDEX.md from the global template and all
|
|
328
|
+
* installed component indexes.
|
|
329
|
+
*
|
|
330
|
+
* Flow:
|
|
331
|
+
* 1. Read global template from agentic/code/RULES-INDEX.md
|
|
332
|
+
* 2. For each component with consolidation support, read its RULES-INDEX.md
|
|
333
|
+
* 3. Concatenate: global header + component indexes + global quick reference
|
|
334
|
+
*
|
|
335
|
+
* @param {string} srcRoot - Source root directory
|
|
336
|
+
* @returns {string|null} - Assembled content or null if global template missing
|
|
337
|
+
*/
|
|
338
|
+
export function assembleRulesIndex(srcRoot) {
|
|
339
|
+
const globalPath = path.join(srcRoot, 'agentic', 'code', 'RULES-INDEX.md');
|
|
340
|
+
if (!fs.existsSync(globalPath)) return null;
|
|
341
|
+
|
|
342
|
+
const globalContent = fs.readFileSync(globalPath, 'utf8');
|
|
343
|
+
|
|
344
|
+
// Find the Quick Reference section in the global template
|
|
345
|
+
const qrMarker = '## Quick Reference by Context';
|
|
346
|
+
const qrIndex = globalContent.indexOf(qrMarker);
|
|
347
|
+
|
|
348
|
+
// Split global into header (before Quick Reference) and footer (Quick Reference + rest)
|
|
349
|
+
let header, footer;
|
|
350
|
+
if (qrIndex >= 0) {
|
|
351
|
+
header = globalContent.substring(0, qrIndex).trimEnd();
|
|
352
|
+
footer = globalContent.substring(qrIndex);
|
|
353
|
+
} else {
|
|
354
|
+
header = globalContent;
|
|
355
|
+
footer = '';
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// Collect component indexes
|
|
359
|
+
const componentSections = [];
|
|
360
|
+
|
|
361
|
+
// 1. Framework indexes (sdlc-complete, etc.)
|
|
362
|
+
const frameworksDir = path.join(srcRoot, 'agentic', 'code', 'frameworks');
|
|
363
|
+
if (fs.existsSync(frameworksDir)) {
|
|
364
|
+
for (const entry of fs.readdirSync(frameworksDir, { withFileTypes: true })) {
|
|
365
|
+
if (!entry.isDirectory()) continue;
|
|
366
|
+
const fwPath = path.join(frameworksDir, entry.name);
|
|
367
|
+
const indexPath = getComponentRulesIndexPath(fwPath);
|
|
368
|
+
if (indexPath) {
|
|
369
|
+
componentSections.push(fs.readFileSync(indexPath, 'utf8').trim());
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
// 2. Addon indexes
|
|
375
|
+
const addons = discoverAddons(srcRoot);
|
|
376
|
+
for (const addon of addons) {
|
|
377
|
+
const indexPath = getComponentRulesIndexPath(addon.path);
|
|
378
|
+
if (indexPath) {
|
|
379
|
+
componentSections.push(fs.readFileSync(indexPath, 'utf8').trim());
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// Assemble: header + component indexes + footer
|
|
384
|
+
const parts = [header];
|
|
385
|
+
if (componentSections.length > 0) {
|
|
386
|
+
parts.push('');
|
|
387
|
+
parts.push(componentSections.join('\n\n'));
|
|
388
|
+
}
|
|
389
|
+
if (footer) {
|
|
390
|
+
parts.push('');
|
|
391
|
+
parts.push(footer);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
return parts.join('\n');
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Get the RULES-INDEX.md file path from source
|
|
400
|
+
* @param {string} srcRoot - Source root directory
|
|
401
|
+
* @returns {string|null} - Path to RULES-INDEX.md or null
|
|
402
|
+
*/
|
|
403
|
+
export function getRulesIndexPath(srcRoot) {
|
|
404
|
+
const indexPath = path.join(srcRoot, 'agentic', 'code', 'frameworks', 'sdlc-complete', 'rules', 'RULES-INDEX.md');
|
|
405
|
+
return fs.existsSync(indexPath) ? indexPath : null;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Generate consolidated rules content from manifest for a specific provider.
|
|
411
|
+
* Used by content-injection providers (copilot, warp, windsurf) that need
|
|
412
|
+
* the rules content inline rather than as a file.
|
|
413
|
+
*
|
|
414
|
+
* @param {string} srcRoot - Source root directory
|
|
415
|
+
* @param {string} provider - Provider name (for @-link formatting)
|
|
416
|
+
* @param {string[]} [addonRuleFiles] - Optional addon rule file paths
|
|
417
|
+
* @returns {string|null} - Generated content or null if manifest/index missing
|
|
418
|
+
*/
|
|
419
|
+
export function generateConsolidatedRulesContent(srcRoot, provider, addonRuleFiles = []) {
|
|
420
|
+
// Try assembled index first (new multi-component assembly)
|
|
421
|
+
const assembled = assembleRulesIndex(srcRoot);
|
|
422
|
+
if (assembled) {
|
|
423
|
+
let content = assembled;
|
|
424
|
+
// Append any remaining non-consolidated addon rules
|
|
425
|
+
if (addonRuleFiles.length > 0) {
|
|
426
|
+
content += '\n\n---\n\n## Additional Addon Rules\n\n';
|
|
427
|
+
for (const ruleFile of addonRuleFiles) {
|
|
428
|
+
const ruleName = path.basename(ruleFile, '.md');
|
|
429
|
+
content += `- **${ruleName}**: @${path.relative(srcRoot, ruleFile)}\n`;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
return content;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
// Fallback: legacy single-index behavior
|
|
436
|
+
const indexPath = getRulesIndexPath(srcRoot);
|
|
437
|
+
if (!indexPath) return null;
|
|
438
|
+
|
|
439
|
+
let content = fs.readFileSync(indexPath, 'utf8');
|
|
440
|
+
|
|
441
|
+
if (addonRuleFiles.length > 0) {
|
|
442
|
+
content += '\n\n---\n\n## Addon Rules\n\n';
|
|
443
|
+
for (const ruleFile of addonRuleFiles) {
|
|
444
|
+
const ruleName = path.basename(ruleFile, '.md');
|
|
445
|
+
content += `- **${ruleName}**: @${path.relative(srcRoot, ruleFile)}\n`;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
return content;
|
|
450
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Shared provider runtime utilities.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Shared utilities for provider modules
|
|
5
|
+
*
|
|
6
|
+
* This module contains common functions used across all providers:
|
|
7
|
+
* - File operations (ensureDir, listMdFiles, writeFile, etc.)
|
|
8
|
+
* - Model configuration loading
|
|
9
|
+
* - Frontmatter parsing
|
|
10
|
+
* - Other shared utilities
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import realFs from 'fs';
|
|
14
|
+
|
|
15
|
+
import path from 'path';
|
|
16
|
+
|
|
17
|
+
import os from 'os';
|
|
18
|
+
|
|
19
|
+
import yaml from 'yaml';
|
|
20
|
+
|
|
21
|
+
import { classifyModelRole } from './model-role.mjs';
|
|
22
|
+
|
|
23
|
+
import { createHash } from 'crypto';
|
|
24
|
+
|
|
25
|
+
import { createRequire } from 'module';
|
|
26
|
+
|
|
27
|
+
import { importImpl } from '../../_resolve-impl.mjs';
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
import { writeContextFileSync } from './context-write.mjs';
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
const { parseRuleFrontmatter, inferRuleActivation } = await importImpl(import.meta.url, 'rules/activation.mjs');
|
|
34
|
+
|
|
35
|
+
const { resolveRulesInlineBudget, DEFAULT_RULES_INLINE_BUDGET_TOKENS } = await importImpl(import.meta.url, 'rules/inline-budget.mjs');
|
|
36
|
+
|
|
37
|
+
const { boundedExecFileSync } = await importImpl(import.meta.url, 'process/bounded-child-process.mjs');
|
|
38
|
+
|
|
39
|
+
const { helperEnvironment } = await importImpl(import.meta.url, 'process/cli-command.mjs');
|
|
40
|
+
|
|
41
|
+
const { extractFrameworkSlug, sameSkillOwner, mergeArtifactOwnership, canDeploySkill, pruneRecordedSkillFiles, releaseSkillOwnership } =
|
|
42
|
+
await importImpl(import.meta.url, 'providers/skill-ownership.mjs');
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
// Use graceful-fs to prevent EMFILE crashes on systems with low ulimit.
|
|
46
|
+
// graceful-fs queues open() calls when FD pressure is detected and retries
|
|
47
|
+
// after a backoff, transparently wrapping the native fs module.
|
|
48
|
+
let fs;
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
const require = createRequire(import.meta.url);
|
|
52
|
+
const gracefulFs = require('graceful-fs');
|
|
53
|
+
gracefulFs.gracefulify(realFs);
|
|
54
|
+
fs = realFs;
|
|
55
|
+
} catch {
|
|
56
|
+
// graceful-fs not available — fall back to native fs
|
|
57
|
+
fs = realFs;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { realFs, path, os, yaml, classifyModelRole, createHash, createRequire, importImpl, writeContextFileSync, parseRuleFrontmatter, inferRuleActivation, resolveRulesInlineBudget, DEFAULT_RULES_INLINE_BUDGET_TOKENS, boundedExecFileSync, helperEnvironment, extractFrameworkSlug, sameSkillOwner, mergeArtifactOwnership, canDeploySkill, pruneRecordedSkillFiles, releaseSkillOwnership, fs };
|