@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.
- package/dist/src/artifacts/corpus-tools/resolve.js +21 -4
- 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/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/scope-resolver.js +1 -142
- 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/mission-protocol/worker-review-gate.js +7 -0
- 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/context-output-ownership.js +26 -0
- package/dist/src/providers/deployment-ownership.d.mts +19 -0
- package/dist/src/providers/deployment-ownership.mjs +226 -0
- package/dist/src/providers/deployment-removal.js +200 -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 +19 -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 +42 -7
- 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/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/generator.js +1 -1
- package/dist/src/smiths/hook-bridge/index.js +9 -0
- package/package.json +4 -1
- package/schemas/decision/D17StudyProtocol.v1.schema.json +39 -67
- package/tools/agents/deploy-agents.mjs +16 -677
- package/tools/agents/deploy-command-mirrors.mjs +229 -0
- package/tools/agents/deploy-options.mjs +258 -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/hermes-startup.mjs +0 -5
- package/tools/agents/providers/muse.mjs +7 -2
- package/tools/agents/providers/rule-delivery-surface.mjs +31 -4
- package/tools/agents/providers/rule-deployment-commit.mjs +19 -15
- package/tools/agents/providers/rule-deployment-prepare.mjs +11 -2
- package/tools/agents/providers/rule-projection.mjs +3 -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
|
@@ -37,7 +37,17 @@ export async function resolveReference(input, root, year, clients = createResolv
|
|
|
37
37
|
const identifier = reference.identifier;
|
|
38
38
|
async function attempt(source, method, query, run, byId = false) {
|
|
39
39
|
try {
|
|
40
|
-
const returned = (await run()).slice(0, 5).
|
|
40
|
+
const returned = (await run()).slice(0, 5).flatMap(paper => {
|
|
41
|
+
try {
|
|
42
|
+
return [canonicalPaper(paper)];
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
// Missing years are record quality, not a failed request; retain valid siblings.
|
|
46
|
+
if (error instanceof ResearchError && error.code === ResearchErrorCode.RF_301)
|
|
47
|
+
return [];
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
41
51
|
if (returned.some(paper => !paper.id || !normalizeTitle(paper.title))) {
|
|
42
52
|
throw new ResearchError(ResearchErrorCode.RF_301, 'Response lacks a paper identity or title');
|
|
43
53
|
}
|
|
@@ -65,8 +75,13 @@ export async function resolveReference(input, root, year, clients = createResolv
|
|
|
65
75
|
}
|
|
66
76
|
catch (error) {
|
|
67
77
|
const missing = error instanceof ResearchError && error.code === ResearchErrorCode.RF_300;
|
|
78
|
+
const retryable = error instanceof ResearchError && [
|
|
79
|
+
ResearchErrorCode.RF_103, ResearchErrorCode.RF_104, ResearchErrorCode.RF_200,
|
|
80
|
+
ResearchErrorCode.RF_201, ResearchErrorCode.RF_202, ResearchErrorCode.RF_500,
|
|
81
|
+
ResearchErrorCode.RF_501, ResearchErrorCode.RF_502,
|
|
82
|
+
].includes(error.code);
|
|
68
83
|
paths.push({ source, method, query, status: missing ? 'empty' : 'error', returned: [],
|
|
69
|
-
...(missing ? {} : { error: error instanceof Error ? error.message : String(error) }) });
|
|
84
|
+
...(missing ? {} : { error: error instanceof Error ? error.message : String(error), retryable }) });
|
|
70
85
|
}
|
|
71
86
|
}
|
|
72
87
|
if (identifier) {
|
|
@@ -104,13 +119,15 @@ export async function resolveReference(input, root, year, clients = createResolv
|
|
|
104
119
|
}
|
|
105
120
|
}
|
|
106
121
|
const classified = classifyCandidates(candidates);
|
|
107
|
-
const incomplete = paths.some(path => path.
|
|
122
|
+
const incomplete = paths.some(path => path.retryable);
|
|
108
123
|
const titleAmbiguous = needsTitleDisambiguation(reference, candidates, incomplete);
|
|
109
124
|
const status = classified === 'unresolved' && incomplete ? 'deferred'
|
|
110
125
|
: classified === 'resolved' && (identifierUnresolved || titleAmbiguous) ? 'ambiguous' : classified;
|
|
111
126
|
if (titleAmbiguous && classified !== 'unresolved')
|
|
112
127
|
findings.push({ type: 'title_ambiguous',
|
|
113
|
-
supplied: reference.title, returned:
|
|
128
|
+
supplied: reference.title, returned: reference.year === undefined
|
|
129
|
+
? 'Supply a year, author, or verified identifier to disambiguate this title'
|
|
130
|
+
: 'Supply an author or verified identifier to disambiguate this title' });
|
|
114
131
|
const paper = status === 'resolved' ? candidates[0].paper : undefined;
|
|
115
132
|
const corpusMatches = paper ? findInCorpus(root, paper) : [];
|
|
116
133
|
return { input, reference, status, incomplete, candidates,
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
// Find operational artifacts in the source corpus when indexes lack a match.
|
|
2
|
+
/**
|
|
3
|
+
* Scan bundle `gate-packs/` directories for a pack matching `needle` (#2830).
|
|
4
|
+
*
|
|
5
|
+
* Accepts the full namespaced id, the rest-path or the short pack name and
|
|
6
|
+
* probes `<bundle>/gate-packs/<pack>.gatepack.{yaml,yml,json}`. Never looks
|
|
7
|
+
* under `gates/`, which agent-persistence HITL owns.
|
|
8
|
+
*/
|
|
9
|
+
export async function findGatePackInCorpus(groups, needle) {
|
|
10
|
+
const path = await import('node:path');
|
|
11
|
+
const fsp = (await import('node:fs')).promises;
|
|
12
|
+
const trimmed = needle.trim();
|
|
13
|
+
const rest = trimmed.includes(':') ? trimmed.slice(trimmed.indexOf(':') + 1) : trimmed;
|
|
14
|
+
const slash = rest.indexOf('/');
|
|
15
|
+
const wantedBundle = slash >= 0 ? rest.slice(0, slash) : null;
|
|
16
|
+
const wantedPack = slash >= 0 ? rest.slice(slash + 1) : rest;
|
|
17
|
+
if (!wantedPack || /\s/.test(wantedPack) || wantedPack.includes(':') || wantedPack.includes('/'))
|
|
18
|
+
return null;
|
|
19
|
+
const extensions = ['.gatepack.yaml', '.gatepack.yml', '.gatepack.json'];
|
|
20
|
+
const ordered = wantedBundle
|
|
21
|
+
? groups.flatMap(group => [{ group, bundle: wantedBundle }])
|
|
22
|
+
: null;
|
|
23
|
+
const probe = async (group, bundle) => {
|
|
24
|
+
for (const extension of extensions) {
|
|
25
|
+
const candidate = path.join(group.dir, bundle, 'gate-packs', `${wantedPack}${extension}`);
|
|
26
|
+
try {
|
|
27
|
+
const stat = await fsp.stat(candidate);
|
|
28
|
+
if (stat.isFile())
|
|
29
|
+
return { path: candidate, bundleKind: group.kind, bundleId: bundle };
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// not present — continue
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
};
|
|
37
|
+
if (ordered) {
|
|
38
|
+
for (const { group, bundle } of ordered) {
|
|
39
|
+
const found = await probe(group, bundle);
|
|
40
|
+
if (found)
|
|
41
|
+
return found;
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
for (const group of groups) {
|
|
46
|
+
let bundles;
|
|
47
|
+
try {
|
|
48
|
+
bundles = (await fsp.readdir(group.dir, { withFileTypes: true }))
|
|
49
|
+
.filter(d => d.isDirectory())
|
|
50
|
+
.map(d => d.name)
|
|
51
|
+
.sort();
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
for (const bundle of bundles) {
|
|
57
|
+
const found = await probe(group, bundle);
|
|
58
|
+
if (found)
|
|
59
|
+
return found;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Scan the AIWG_ROOT corpus for an artifact matching `name` (#1221).
|
|
66
|
+
*
|
|
67
|
+
* Walks the well-known artifact layouts under
|
|
68
|
+
* `agentic/code/{frameworks,addons,extensions,plugins}/<bundle>/{skills,agents,commands,rules,templates,behaviors,flows}/`
|
|
69
|
+
* and returns the first match. Used as a fallback in `aiwg show` when an
|
|
70
|
+
* artifact isn't in any built index — either because the workspace hasn't
|
|
71
|
+
* been deployed to yet, or because the bundle hasn't been installed.
|
|
72
|
+
*
|
|
73
|
+
* Returns the resolved absolute path plus enough metadata for the caller
|
|
74
|
+
* to surface a useful install hint. Returns null if nothing matches.
|
|
75
|
+
*/
|
|
76
|
+
export async function findCorpusArtifact(aiwgRoot, name, typeFilter) {
|
|
77
|
+
const fs = await import('node:fs');
|
|
78
|
+
const path = await import('node:path');
|
|
79
|
+
const fsp = fs.promises;
|
|
80
|
+
const groups = [
|
|
81
|
+
{ kind: 'framework', dir: path.join(aiwgRoot, 'agentic/code/frameworks') },
|
|
82
|
+
{ kind: 'addon', dir: path.join(aiwgRoot, 'agentic/code/addons') },
|
|
83
|
+
{ kind: 'extension', dir: path.join(aiwgRoot, 'agentic/code/extensions') },
|
|
84
|
+
{ kind: 'plugin', dir: path.join(aiwgRoot, 'agentic/code/plugins') },
|
|
85
|
+
];
|
|
86
|
+
// (subdir, type, layout) — 'flat' = `<name>.md`, 'slug' = `<name>/SKILL.md`
|
|
87
|
+
const tries = [
|
|
88
|
+
{ sub: 'skills', type: 'skill', layout: 'slug' },
|
|
89
|
+
{ sub: 'skills', type: 'skill', layout: 'flat' },
|
|
90
|
+
{ sub: 'agents', type: 'agent', layout: 'flat' },
|
|
91
|
+
{ sub: 'commands', type: 'command', layout: 'flat' },
|
|
92
|
+
{ sub: 'rules', type: 'rule', layout: 'flat' },
|
|
93
|
+
{ sub: 'templates', type: 'template', layout: 'flat' },
|
|
94
|
+
{ sub: 'behaviors', type: 'behavior', layout: 'flat' },
|
|
95
|
+
{ sub: 'flows', type: 'flow', layout: 'flat' },
|
|
96
|
+
{ sub: 'runbooks', type: 'runbook', layout: 'flat' },
|
|
97
|
+
{ sub: 'decisions', type: 'decision-definition', layout: 'flat', extension: '.json' },
|
|
98
|
+
{ sub: 'rulesets', type: 'decision-ruleset', layout: 'flat', extension: '.json' },
|
|
99
|
+
{ sub: 'bindings', type: 'decision-binding', layout: 'flat', extension: '.json' },
|
|
100
|
+
];
|
|
101
|
+
for (const group of groups) {
|
|
102
|
+
let bundles;
|
|
103
|
+
try {
|
|
104
|
+
bundles = (await fsp.readdir(group.dir, { withFileTypes: true }))
|
|
105
|
+
.filter(d => d.isDirectory())
|
|
106
|
+
.map(d => d.name);
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
for (const bundle of bundles) {
|
|
112
|
+
for (const t of tries) {
|
|
113
|
+
if (typeFilter.length > 0 && !typeFilter.includes(t.type))
|
|
114
|
+
continue;
|
|
115
|
+
const candidate = t.layout === 'slug'
|
|
116
|
+
? path.join(group.dir, bundle, t.sub, name, 'SKILL.md')
|
|
117
|
+
: path.join(group.dir, bundle, t.sub, `${name}${t.extension ?? '.md'}`);
|
|
118
|
+
try {
|
|
119
|
+
const stat = await fsp.stat(candidate);
|
|
120
|
+
if (stat.isFile()) {
|
|
121
|
+
return { path: candidate, type: t.type, bundleKind: group.kind, bundleId: bundle };
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
// not present — continue
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
// Gate packs live in `<bundle>/gate-packs/*.gatepack.yaml|json` (never
|
|
131
|
+
// `gates/`, which agent-persistence HITL uses). The needle may be the full
|
|
132
|
+
// namespaced id (`aiwg:decision-engine/integrity-ceiling`), the rest-path
|
|
133
|
+
// (`decision-engine/integrity-ceiling`) or the short pack name
|
|
134
|
+
// (`integrity-ceiling`). (#2830)
|
|
135
|
+
if (typeFilter.length === 0 || typeFilter.includes('gate-pack')) {
|
|
136
|
+
const gateMatch = await findGatePackInCorpus(groups, name);
|
|
137
|
+
if (gateMatch)
|
|
138
|
+
return { ...gateMatch, type: 'gate-pack' };
|
|
139
|
+
}
|
|
140
|
+
// Top-level agents live at `agentic/code/agents/<category>/<name>.md`
|
|
141
|
+
// (e.g. `personas/aiwg-writer.md`) — a flat-under-category layout the
|
|
142
|
+
// bundle groups above do not cover. Scan it directly so persona/agent
|
|
143
|
+
// `show` survives un-indexed (or stale-framework-index) workspaces, where
|
|
144
|
+
// the corpus fallback is the only resolution path. (#1623 U5)
|
|
145
|
+
if (typeFilter.length === 0 || typeFilter.includes('agent')) {
|
|
146
|
+
const agentMatch = await findAgentInCorpus(path.join(aiwgRoot, 'agentic/code/agents'), name);
|
|
147
|
+
if (agentMatch) {
|
|
148
|
+
return { path: agentMatch, type: 'agent', bundleKind: null, bundleId: null };
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
// Behaviors commonly use a slug layout: `behaviors/<name>/BEHAVIOR.md`.
|
|
152
|
+
if (typeFilter.length === 0 || typeFilter.includes('behavior')) {
|
|
153
|
+
for (const group of groups) {
|
|
154
|
+
let bundles;
|
|
155
|
+
try {
|
|
156
|
+
bundles = (await fsp.readdir(group.dir, { withFileTypes: true }))
|
|
157
|
+
.filter(d => d.isDirectory())
|
|
158
|
+
.map(d => d.name);
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
for (const bundle of bundles) {
|
|
164
|
+
const candidate = path.join(group.dir, bundle, 'behaviors', name, 'BEHAVIOR.md');
|
|
165
|
+
try {
|
|
166
|
+
const stat = await fsp.stat(candidate);
|
|
167
|
+
if (stat.isFile()) {
|
|
168
|
+
return { path: candidate, type: 'behavior', bundleKind: group.kind, bundleId: bundle };
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
// not present — continue
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Recursively scan `agentic/code/agents` for a flat `<name>.md` agent file.
|
|
181
|
+
*
|
|
182
|
+
* Agents use an `agents/<category>/<name>.md` layout (e.g. `personas/`) that
|
|
183
|
+
* differs from the bundle `<dir>/<bundle>/<sub>/<name>.md` layout the generic
|
|
184
|
+
* corpus scan walks, so persona agents are otherwise missed. Bounded depth —
|
|
185
|
+
* the agents tree is shallow. Returns the first matching absolute path, or
|
|
186
|
+
* null. Direct files at each level take priority over subdirectories. (#1623)
|
|
187
|
+
*/
|
|
188
|
+
export async function findAgentInCorpus(agentsRoot, name, depth = 0) {
|
|
189
|
+
if (depth > 3)
|
|
190
|
+
return null;
|
|
191
|
+
const fs = await import('node:fs');
|
|
192
|
+
const path = await import('node:path');
|
|
193
|
+
const fsp = fs.promises;
|
|
194
|
+
let entries;
|
|
195
|
+
try {
|
|
196
|
+
entries = await fsp.readdir(agentsRoot, { withFileTypes: true });
|
|
197
|
+
}
|
|
198
|
+
catch {
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
// Prefer a direct `<name>.md` at this level before descending.
|
|
202
|
+
for (const entry of entries) {
|
|
203
|
+
if (entry.isFile() && entry.name === `${name}.md`) {
|
|
204
|
+
return path.join(agentsRoot, entry.name);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
// Descend into category subdirectories (e.g. personas/).
|
|
208
|
+
for (const entry of entries) {
|
|
209
|
+
if (entry.isDirectory()) {
|
|
210
|
+
const found = await findAgentInCorpus(path.join(agentsRoot, entry.name), name, depth + 1);
|
|
211
|
+
if (found)
|
|
212
|
+
return found;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=query-engine-corpus.js.map
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
// Shape capability discovery diagnostics, rule checks, and CLI output.
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { diagnoseFacetActivations } from './discover-facets.js';
|
|
4
|
+
import { buildRunHint, DISCOVER_TYPE_ORDER, discoveryIdForEntry, normalizeIndexedPath, scopeRank, showHintForDiscoverResult, } from './query-engine-entries.js';
|
|
5
|
+
import { boundRuleDescriptor, compoundGoverningRules, governingRuleFields, governingRuleStats, RULE_CHECK_OBLIGATION, statsText, } from './query-engine-rules.js';
|
|
6
|
+
import { tokenize } from './query-engine-scoring.js';
|
|
7
|
+
import { ensureRelations } from './relations.js';
|
|
8
|
+
export async function emitDiscoverResults(context) {
|
|
9
|
+
const { cwd, params, types, limit, aiwgRoot, entries, backend, resourceSource, resolvedWebRelease, prebuiltRelations, scored, relaxed, queryTimeMs, lexicalDiagnostics } = context;
|
|
10
|
+
/**
|
|
11
|
+
* Resolve a stored framework-graph path to an absolute AIWG_ROOT
|
|
12
|
+
* path (#1217). Framework-graph entries are stored as paths relative
|
|
13
|
+
* to the AIWG repo root (e.g. `agentic/code/frameworks/.../SKILL.md`);
|
|
14
|
+
* anchoring them to `AIWG_ROOT` makes them readable from any project
|
|
15
|
+
* working directory.
|
|
16
|
+
*
|
|
17
|
+
* Kernel skills are anchored the same way (#1230) — `aiwg show` reads
|
|
18
|
+
* the source corpus, not platform deploy mirrors, so kernel entries
|
|
19
|
+
* need the same `AIWG_ROOT` anchoring as non-kernel framework entries.
|
|
20
|
+
* Non-framework entries (project / codebase graphs) keep their stored
|
|
21
|
+
* paths unchanged.
|
|
22
|
+
*/
|
|
23
|
+
function resolvePath(entry) {
|
|
24
|
+
const normalizedPath = normalizeIndexedPath(entry.path);
|
|
25
|
+
if (!aiwgRoot)
|
|
26
|
+
return normalizedPath;
|
|
27
|
+
if (path.isAbsolute(entry.path))
|
|
28
|
+
return entry.path;
|
|
29
|
+
if (normalizedPath.startsWith('agentic/code/'))
|
|
30
|
+
return path.join(aiwgRoot, normalizedPath);
|
|
31
|
+
return normalizedPath;
|
|
32
|
+
}
|
|
33
|
+
// Build a hint string when the index has entries but no scored matches —
|
|
34
|
+
// this is the second silent-failure mode #1221 calls out. When the workspace
|
|
35
|
+
// has project-local content (.aiwg/{extensions,addons,frameworks,plugins,providers}/)
|
|
36
|
+
// surface a project-graph rebuild hint (#1235).
|
|
37
|
+
// discover-appropriate hint (#1545): never push index/graph mechanics. If
|
|
38
|
+
// nothing scored, the phrase didn't match an indexed capability — suggest a
|
|
39
|
+
// broader phrase / type filter, and a capability refresh via `aiwg use`.
|
|
40
|
+
const emptyResultHint = scored.length === 0
|
|
41
|
+
? backend === 'fortemi-core'
|
|
42
|
+
? `No capability matched "${params.phrase}" among ${entries.length} Fortemi Core static-cache capabilities. Try a broader phrase or a \`--type\` filter. If the local index changed, refresh the cache with \`aiwg index sync ${params.graph ? `--graph ${params.graph}` : '--all'}\`, or pass \`--backend local\` to use the legacy local index.`
|
|
43
|
+
: `No capability matched "${params.phrase}" among ${entries.length} indexed capabilities. Try a broader phrase or a \`--type\` filter. If you just installed or authored capabilities, refresh discovery with \`aiwg use <framework>\` (or \`aiwg index build\`).`
|
|
44
|
+
: null;
|
|
45
|
+
const relations = resourceSource === 'local' && (!params.graph || params.graph === 'framework')
|
|
46
|
+
? prebuiltRelations ?? await ensureRelations(cwd) : undefined;
|
|
47
|
+
const governing = scored.map(result => compoundGoverningRules(entries, result.entry, relations ?? undefined, params.phrase));
|
|
48
|
+
const responseRules = new Map();
|
|
49
|
+
for (const item of governing.flat()) {
|
|
50
|
+
const key = `${item.rule.type}:${item.rule.path}`, prior = responseRules.get(key);
|
|
51
|
+
responseRules.set(key, { rule: item.rule, applicability: [...new Set([...(prior?.applicability ?? []), ...item.applicability])] });
|
|
52
|
+
}
|
|
53
|
+
const responseFields = governingRuleFields([...responseRules.values()]);
|
|
54
|
+
const responseRuleStats = governingRuleStats([...responseRules.values()]);
|
|
55
|
+
const includePaths = params.includePaths ?? true;
|
|
56
|
+
const facetActivations = diagnoseFacetActivations(params.phrase);
|
|
57
|
+
const roundDiagnostic = (value) => Math.round(value * 1_000_000) / 1_000_000;
|
|
58
|
+
const rankingDiagnostic = (entry, finalScore, facetDiagnostics) => {
|
|
59
|
+
const lexical = lexicalDiagnostics.get(entry.path) ?? {
|
|
60
|
+
content_tokens: tokenize(params.phrase),
|
|
61
|
+
raw_score: 0,
|
|
62
|
+
score: 0,
|
|
63
|
+
score_cap_applied: false,
|
|
64
|
+
matches: [],
|
|
65
|
+
};
|
|
66
|
+
const scope = entry.indexScope ?? 'unknown';
|
|
67
|
+
return {
|
|
68
|
+
lexical_score: roundDiagnostic(lexical.score),
|
|
69
|
+
lexical_raw_score: roundDiagnostic(lexical.raw_score),
|
|
70
|
+
final_score: roundDiagnostic(finalScore),
|
|
71
|
+
score_cap_applied: lexical.score_cap_applied,
|
|
72
|
+
matches: lexical.matches.map((match) => ({
|
|
73
|
+
...match,
|
|
74
|
+
contribution: roundDiagnostic(match.contribution),
|
|
75
|
+
...(match.query_token_coverage === undefined
|
|
76
|
+
? {}
|
|
77
|
+
: { query_token_coverage: roundDiagnostic(match.query_token_coverage) }),
|
|
78
|
+
})),
|
|
79
|
+
facets: (facetDiagnostics ?? []).map((facet) => ({
|
|
80
|
+
...facet,
|
|
81
|
+
activation_floor: roundDiagnostic(facet.activation_floor),
|
|
82
|
+
base_score: roundDiagnostic(facet.base_score),
|
|
83
|
+
rrf_tiebreak: roundDiagnostic(facet.rrf_tiebreak),
|
|
84
|
+
})),
|
|
85
|
+
tie_breakers: {
|
|
86
|
+
scope,
|
|
87
|
+
scope_rank: scopeRank(entry),
|
|
88
|
+
type_rank: DISCOVER_TYPE_ORDER.get(entry.type) ?? 99,
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
const { loadRelations } = await import('./relations.js');
|
|
93
|
+
const ruleRelations = resourceSource === 'local' ? loadRelations(cwd) ?? (aiwgRoot ? loadRelations(aiwgRoot, cwd) : null) : null;
|
|
94
|
+
if (params.json) {
|
|
95
|
+
const jsonIndent = params.jsonPretty === false ? undefined : 2;
|
|
96
|
+
console.log(JSON.stringify({
|
|
97
|
+
query: {
|
|
98
|
+
phrase: params.phrase,
|
|
99
|
+
types,
|
|
100
|
+
limit,
|
|
101
|
+
aiwg_root: aiwgRoot ?? null,
|
|
102
|
+
backend,
|
|
103
|
+
graph: backend === 'fortemi-core'
|
|
104
|
+
? resourceSource === 'web' ? 'framework' : params.graph ?? 'capability-default'
|
|
105
|
+
: params.graph,
|
|
106
|
+
...(resourceSource === 'web'
|
|
107
|
+
? {
|
|
108
|
+
resource_source: 'web',
|
|
109
|
+
aiwg_selector: resolvedWebRelease?.selector,
|
|
110
|
+
aiwg_version: resolvedWebRelease?.version,
|
|
111
|
+
manifest_sha256: resolvedWebRelease?.manifestDigest,
|
|
112
|
+
manifest_url: resolvedWebRelease?.manifestUrl,
|
|
113
|
+
}
|
|
114
|
+
: {}),
|
|
115
|
+
},
|
|
116
|
+
results: scored.map((r, resultIndex) => ({
|
|
117
|
+
id: discoveryIdForEntry(r.entry),
|
|
118
|
+
...(includePaths ? { path: resolvePath(r.entry) } : {}),
|
|
119
|
+
type: r.entry.type,
|
|
120
|
+
name: r.entry.name,
|
|
121
|
+
title: r.entry.title,
|
|
122
|
+
score: Math.round(r.score * 100) / 100,
|
|
123
|
+
ranking: rankingDiagnostic(r.entry, r.score, r.facetDiagnostics),
|
|
124
|
+
...governingRuleFields(governing[resultIndex]),
|
|
125
|
+
triggers: r.entry.triggers ?? [],
|
|
126
|
+
capability: r.entry.capability ?? r.entry.summary,
|
|
127
|
+
kernel: r.entry.kernel ?? false,
|
|
128
|
+
...(['skill', 'agent', 'flow', 'command'].includes(r.entry.type) && ruleRelations
|
|
129
|
+
&& ruleRelations.rulesForTarget(r.entry.type, discoveryIdForEntry(r.entry)).length ? {
|
|
130
|
+
startup_rule_stats: ruleRelations.ruleStats(r.entry.type, discoveryIdForEntry(r.entry)),
|
|
131
|
+
} : {}),
|
|
132
|
+
provenance: {
|
|
133
|
+
graph: r.entry.indexGraph ?? null,
|
|
134
|
+
scope: r.entry.indexScope ?? null,
|
|
135
|
+
},
|
|
136
|
+
// #1227 — surface script-bearing skills so agents know to use
|
|
137
|
+
// `aiwg run skill <name>` instead of executing instructions
|
|
138
|
+
// themselves.
|
|
139
|
+
...(r.entry.script
|
|
140
|
+
? {
|
|
141
|
+
executable: true,
|
|
142
|
+
run_hint: buildRunHint(r.entry),
|
|
143
|
+
}
|
|
144
|
+
: {}),
|
|
145
|
+
})),
|
|
146
|
+
rule_stats: responseRuleStats,
|
|
147
|
+
...(responseFields.required_rule_checks ? { required_rule_checks: responseFields.required_rule_checks, rule_check_obligation: RULE_CHECK_OBLIGATION } : {}),
|
|
148
|
+
total: scored.length,
|
|
149
|
+
query_time_ms: queryTimeMs,
|
|
150
|
+
diagnostics: {
|
|
151
|
+
content_tokens: tokenize(params.phrase),
|
|
152
|
+
facet_activations: facetActivations,
|
|
153
|
+
score_tie_break_order: ['score', 'scope', 'type', 'name', 'path'],
|
|
154
|
+
},
|
|
155
|
+
...(relaxed ? { relaxed_overlap: true } : {}),
|
|
156
|
+
...(emptyResultHint ? { hint: emptyResultHint } : {}),
|
|
157
|
+
}, null, jsonIndent));
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (scored.length === 0) {
|
|
161
|
+
console.log(`No discovery matches for "${params.phrase}" in types: ${types.join(',')}.`);
|
|
162
|
+
console.log(backend === 'fortemi-core'
|
|
163
|
+
? emptyResultHint
|
|
164
|
+
: 'Try a broader phrase or a `--type` filter. If capabilities were just added, refresh with `aiwg use <framework>` (or `aiwg index build`).');
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const relaxedNote = relaxed ? ' — relaxed match (verbose query)' : '';
|
|
168
|
+
console.log(`Discovery results for "${params.phrase}" (${scored.length} matches, ${queryTimeMs}ms)${relaxedNote}:`);
|
|
169
|
+
console.log(statsText(responseRuleStats));
|
|
170
|
+
console.log('');
|
|
171
|
+
for (const diagnostic of facetActivations) {
|
|
172
|
+
if (diagnostic.status === 'suppressed' && diagnostic.reason) {
|
|
173
|
+
console.log(`Routing diagnostic: ${diagnostic.reason}.`);
|
|
174
|
+
console.log('');
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
for (let i = 0; i < scored.length; i++) {
|
|
178
|
+
const r = scored[i];
|
|
179
|
+
const ranking = rankingDiagnostic(r.entry, r.score, r.facetDiagnostics);
|
|
180
|
+
const id = discoveryIdForEntry(r.entry);
|
|
181
|
+
const score = r.score.toFixed(2);
|
|
182
|
+
const flags = [
|
|
183
|
+
r.entry.kernel ? 'kernel' : null,
|
|
184
|
+
r.entry.script ? 'exec' : null,
|
|
185
|
+
].filter(Boolean).join(', ');
|
|
186
|
+
const locator = includePaths ? resolvePath(r.entry) : id;
|
|
187
|
+
const topTriggerMatch = ranking.matches
|
|
188
|
+
.filter((match) => match.field === 'trigger')
|
|
189
|
+
.reduce((best, match) => !best || match.contribution > best.contribution ? match : best, undefined);
|
|
190
|
+
const topTrigger = topTriggerMatch?.value ??
|
|
191
|
+
(r.entry.triggers && r.entry.triggers.length > 0 ? r.entry.triggers[0] : '');
|
|
192
|
+
console.log(`${i + 1}. ${r.entry.title}`);
|
|
193
|
+
console.log(` type: ${r.entry.type} score: ${score}${flags ? ` flags: ${flags}` : ''}`);
|
|
194
|
+
console.log(` ${includePaths ? 'path' : 'id'}: ${locator}`);
|
|
195
|
+
if (r.entry.name) {
|
|
196
|
+
console.log(` name: ${r.entry.name}`);
|
|
197
|
+
}
|
|
198
|
+
if (r.entry.capability) {
|
|
199
|
+
console.log(` capability: ${r.entry.capability}`);
|
|
200
|
+
}
|
|
201
|
+
if (topTrigger) {
|
|
202
|
+
console.log(` trigger: "${topTrigger}"`);
|
|
203
|
+
}
|
|
204
|
+
const triggerCoverage = topTriggerMatch?.query_token_coverage;
|
|
205
|
+
const rankingParts = [
|
|
206
|
+
`lexical ${ranking.lexical_score.toFixed(4)} -> final ${ranking.final_score.toFixed(4)}`,
|
|
207
|
+
triggerCoverage === undefined
|
|
208
|
+
? null
|
|
209
|
+
: `trigger covers ${Math.round(triggerCoverage * 100)}% of query tokens`,
|
|
210
|
+
`scope ${ranking.tie_breakers.scope}`,
|
|
211
|
+
].filter((part) => Boolean(part));
|
|
212
|
+
console.log(` ranking: ${rankingParts.join('; ')}`);
|
|
213
|
+
if (governing[i].length) {
|
|
214
|
+
console.log(` ${statsText(governingRuleStats(governing[i]))}`);
|
|
215
|
+
console.log(` ${RULE_CHECK_OBLIGATION}`);
|
|
216
|
+
for (const { rule, applicability } of governing[i])
|
|
217
|
+
console.log(` - ${rule.name ?? rule.path}: ${rule.ruleSummary ?? ''} (${applicability.join('; ')}) — \`${boundRuleDescriptor(rule).show_command}\``);
|
|
218
|
+
}
|
|
219
|
+
if (r.entry.script) {
|
|
220
|
+
console.log(` run: ${buildRunHint(r.entry)}`);
|
|
221
|
+
}
|
|
222
|
+
else if (!includePaths) {
|
|
223
|
+
console.log(` show: ${showHintForDiscoverResult(r.entry, id)}`);
|
|
224
|
+
}
|
|
225
|
+
console.log('');
|
|
226
|
+
}
|
|
227
|
+
console.log('Use `--format json` for machine-readable output. Use `aiwg show metadata <id>` for paths and full metadata.');
|
|
228
|
+
}
|
|
229
|
+
//# sourceMappingURL=query-engine-discover-output.js.map
|