@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
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { applyFacetFusion } from './discover-facets.js';
|
|
2
|
+
import { refreshFrameworkCapabilities, resolveFrameworkCorpusRoot } from './framework-capabilities.js';
|
|
3
|
+
import { resolveFrameworkIndexRoot } from './framework-index-paths.js';
|
|
4
|
+
import { loadGraphIndexFile, loadMetadataIndex } from './index-reader.js';
|
|
5
|
+
import { emitDiscoverResults } from './query-engine-discover-output.js';
|
|
6
|
+
import { compareDiscoverResults, dedupeDiscoverResults, DEFAULT_ARTIFACT_SEARCH_BACKEND, DEFAULT_DISCOVER_TYPES, defaultCapabilityGraphs, discoveryIdForEntry, isOrdinaryMemoryEntry, projectAllowsUserIndices, projectCapabilityFallback, withIndexProvenance, } from './query-engine-entries.js';
|
|
7
|
+
import { scoreEntryDetailed } from './query-engine-scoring.js';
|
|
8
|
+
import { emptyRuleStats, selectPrebuiltRelations } from './relations.js';
|
|
9
|
+
import { loadGlobalGraphConfigs } from './types.js';
|
|
10
|
+
export async function discoverCapability(cwd, params) {
|
|
11
|
+
loadGlobalGraphConfigs();
|
|
12
|
+
const startTime = Date.now();
|
|
13
|
+
const types = params.typeFilter && params.typeFilter.length > 0
|
|
14
|
+
? params.typeFilter
|
|
15
|
+
: DEFAULT_DISCOVER_TYPES;
|
|
16
|
+
// Default top-K = 5 (Wave A from #1218): peer-reviewed work on tool
|
|
17
|
+
// retrieval (Semantic Tool Discovery for MCP, arXiv:2603.20313) reports
|
|
18
|
+
// 97.1% hit@K=3 at scale; K=5 keeps a buffer above K=3 while halving
|
|
19
|
+
// the prior K=10 default. Operators wanting more breadth can pass
|
|
20
|
+
// `--limit N` explicitly.
|
|
21
|
+
const limit = params.limit ?? 5;
|
|
22
|
+
// For framework-graph entries, anchor returned paths to AIWG_ROOT so
|
|
23
|
+
// they resolve from any project working directory (#1217).
|
|
24
|
+
const aiwgRoot = resolveFrameworkIndexRoot(cwd);
|
|
25
|
+
// Source: prefer `framework` graph (built post-deploy), fall back to
|
|
26
|
+
// project / codebase / legacy depending on what's available.
|
|
27
|
+
let entries = [];
|
|
28
|
+
const backend = params.backend ?? DEFAULT_ARTIFACT_SEARCH_BACKEND;
|
|
29
|
+
let fortemiCoreDiscoveryScores = null;
|
|
30
|
+
let resourceSource = params.resourceSource ?? 'local';
|
|
31
|
+
let resolvedWebRelease;
|
|
32
|
+
let verifiedSourcePaths;
|
|
33
|
+
const prebuiltRelations = resourceSource !== 'web' && (!params.graph || params.graph === 'framework')
|
|
34
|
+
? selectPrebuiltRelations(cwd).reader : null;
|
|
35
|
+
if ((!prebuiltRelations || backend === 'local') && resourceSource !== 'web' && (!params.graph || params.graph === 'framework')) {
|
|
36
|
+
const root = resolveFrameworkCorpusRoot(cwd) ?? aiwgRoot;
|
|
37
|
+
if (root) {
|
|
38
|
+
try {
|
|
39
|
+
await refreshFrameworkCapabilities(root, backend === 'fortemi-core');
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
console.error(`Warning: capability index refresh failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (resourceSource === 'auto') {
|
|
47
|
+
const { loadFortemiCoreMetadataEntries } = await import('./fortemi-core-query-adapter.js');
|
|
48
|
+
const localGraphs = params.graph ? [params.graph] : defaultCapabilityGraphs(cwd);
|
|
49
|
+
const localAvailable = localGraphs.some((graph) => loadFortemiCoreMetadataEntries(cwd, graph).entries.length > 0
|
|
50
|
+
|| Object.keys(loadGraphIndexFile(cwd, 'metadata.json', graph)?.entries ?? {}).length > 0);
|
|
51
|
+
resourceSource = localAvailable ? 'local' : 'web';
|
|
52
|
+
}
|
|
53
|
+
if (resourceSource === 'web') {
|
|
54
|
+
if (backend !== 'fortemi-core') {
|
|
55
|
+
console.error('Error: --resource-source web requires the Fortemi Core query backend; --backend local remains available with local resources.');
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
if (params.graph && params.graph !== 'framework') {
|
|
59
|
+
console.error("Error: web-backed capability discovery currently supports only the 'framework' graph.");
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
const { resolveWebRelease } = await import('../resources/web-release.js');
|
|
64
|
+
const release = await resolveWebRelease({
|
|
65
|
+
...params.webReleaseOptions,
|
|
66
|
+
selector: params.aiwgVersion ?? 'stable',
|
|
67
|
+
offline: params.offline,
|
|
68
|
+
});
|
|
69
|
+
resolvedWebRelease = release;
|
|
70
|
+
verifiedSourcePaths = {
|
|
71
|
+
manifestPath: release.fortemiManifestPath,
|
|
72
|
+
exportPath: release.fortemiExportPath,
|
|
73
|
+
manifestSha256: release.fortemiManifestSha256,
|
|
74
|
+
manifestSize: release.fortemiManifestSize,
|
|
75
|
+
exportSha256: release.fortemiExportSha256,
|
|
76
|
+
exportSize: release.fortemiExportSize,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
console.error(`Error: AIWG web resource resolution failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (backend === 'fortemi-core') {
|
|
85
|
+
const graphs = resourceSource === 'web'
|
|
86
|
+
? ['framework']
|
|
87
|
+
: params.graph ? [params.graph] : defaultCapabilityGraphs(cwd);
|
|
88
|
+
const { loadFortemiCoreMetadataEntries, queryFortemiCoreAiwgDiscovery, } = await import('./fortemi-core-query-adapter.js');
|
|
89
|
+
let unavailableReason;
|
|
90
|
+
for (const graph of graphs) {
|
|
91
|
+
const loaded = loadFortemiCoreMetadataEntries(cwd, graph, verifiedSourcePaths);
|
|
92
|
+
if (loaded.reason && graph === 'project' && !params.graph) {
|
|
93
|
+
const fallback = projectCapabilityFallback(cwd);
|
|
94
|
+
if (fallback) {
|
|
95
|
+
entries.push(...fallback);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (loaded.sourceIndexNewer && resourceSource === 'local') {
|
|
100
|
+
// Do not silently omit a graph whose derived cache is stale. Rank its
|
|
101
|
+
// current source metadata, without consulting scores from the old cache.
|
|
102
|
+
const index = loadGraphIndexFile(cwd, 'metadata.json', graph);
|
|
103
|
+
if (index) {
|
|
104
|
+
console.error(`Warning: ${graph} capability cache is unavailable or stale; using the local ${graph} index. ${loaded.reason}`);
|
|
105
|
+
entries.push(...Object.values(index.entries).map((entry) => withIndexProvenance(entry, graph)));
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (loaded.reason) {
|
|
110
|
+
unavailableReason ??= loaded.reason;
|
|
111
|
+
if (graph === 'framework' && !params.graph) {
|
|
112
|
+
console.error(`Warning: framework capabilities are unavailable: ${loaded.reason}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
entries.push(...loaded.entries.map((entry) => withIndexProvenance(entry, graph)));
|
|
116
|
+
const discovered = await queryFortemiCoreAiwgDiscovery(cwd, {
|
|
117
|
+
graph,
|
|
118
|
+
text: params.phrase,
|
|
119
|
+
limit: Math.max(limit * 10, 50),
|
|
120
|
+
types,
|
|
121
|
+
sourcePaths: verifiedSourcePaths,
|
|
122
|
+
});
|
|
123
|
+
if (!discovered.reason) {
|
|
124
|
+
fortemiCoreDiscoveryScores ??= new Map();
|
|
125
|
+
for (const result of discovered.results) {
|
|
126
|
+
if (result.score <= 0)
|
|
127
|
+
continue;
|
|
128
|
+
fortemiCoreDiscoveryScores.set(result.entry.path, Math.max(fortemiCoreDiscoveryScores.get(result.entry.path) ?? 0, result.score));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (entries.length === 0 && unavailableReason) {
|
|
133
|
+
if (params.json) {
|
|
134
|
+
console.log(JSON.stringify({
|
|
135
|
+
query: {
|
|
136
|
+
phrase: params.phrase,
|
|
137
|
+
types,
|
|
138
|
+
limit,
|
|
139
|
+
backend: 'fortemi-core',
|
|
140
|
+
graph: resourceSource === 'web' ? 'framework' : params.graph ?? 'capability-default',
|
|
141
|
+
...(resourceSource === 'web'
|
|
142
|
+
? {
|
|
143
|
+
resource_source: 'web',
|
|
144
|
+
aiwg_selector: resolvedWebRelease?.selector,
|
|
145
|
+
aiwg_version: resolvedWebRelease?.version,
|
|
146
|
+
manifest_sha256: resolvedWebRelease?.manifestDigest,
|
|
147
|
+
manifest_url: resolvedWebRelease?.manifestUrl,
|
|
148
|
+
}
|
|
149
|
+
: {}),
|
|
150
|
+
},
|
|
151
|
+
results: [],
|
|
152
|
+
rule_stats: emptyRuleStats(),
|
|
153
|
+
total: 0,
|
|
154
|
+
hint: unavailableReason,
|
|
155
|
+
}, null, 2));
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
console.error('Error: ' + unavailableReason);
|
|
159
|
+
}
|
|
160
|
+
process.exit(1);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
else if (params.graph) {
|
|
164
|
+
const idx = loadGraphIndexFile(cwd, 'metadata.json', params.graph);
|
|
165
|
+
if (idx)
|
|
166
|
+
entries = Object.values(idx.entries).map((entry) => withIndexProvenance(entry, params.graph));
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
// discover is EXCLUSIVELY the agentic-capability surface (#1545): source
|
|
170
|
+
// the `framework` graph (deployed AIWG capabilities) + project-local
|
|
171
|
+
// capability artifacts. NEVER `codebase` — source code is not a capability
|
|
172
|
+
// surface. The framework
|
|
173
|
+
// index is reconciled with its source above, including existing indexes
|
|
174
|
+
// left behind by an older runtime or a different checkout.
|
|
175
|
+
const fwIdx = loadGraphIndexFile(cwd, 'metadata.json', 'framework');
|
|
176
|
+
const includeUser = projectAllowsUserIndices(cwd);
|
|
177
|
+
// Project-local operational artifacts authored in this project. The
|
|
178
|
+
// DEFAULT_DISCOVER_TYPES filter keeps non-capability project artifacts
|
|
179
|
+
// (requirements, ADRs, …) out of results.
|
|
180
|
+
const projIdx = loadGraphIndexFile(cwd, 'metadata.json', 'project');
|
|
181
|
+
if (projIdx)
|
|
182
|
+
entries.push(...Object.values(projIdx.entries).map((entry) => withIndexProvenance(entry, 'project')));
|
|
183
|
+
if (includeUser) {
|
|
184
|
+
const userIdx = loadGraphIndexFile(cwd, 'metadata.json', 'user');
|
|
185
|
+
if (userIdx)
|
|
186
|
+
entries.push(...Object.values(userIdx.entries).map((entry) => withIndexProvenance(entry, 'user')));
|
|
187
|
+
}
|
|
188
|
+
if (fwIdx)
|
|
189
|
+
entries.push(...Object.values(fwIdx.entries).map((entry) => withIndexProvenance(entry, 'framework')));
|
|
190
|
+
if (entries.length === 0) {
|
|
191
|
+
const legacy = loadMetadataIndex(cwd);
|
|
192
|
+
if (legacy)
|
|
193
|
+
entries.push(...Object.values(legacy.entries));
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (entries.length === 0 && backend !== 'fortemi-core') {
|
|
197
|
+
// Empty-index case (#1221). Surface a hint that explains the gap rather
|
|
198
|
+
// than returning a bare zero-result envelope — the latter trains agents
|
|
199
|
+
// to conclude "AIWG doesn't have a skill for that" when in fact the
|
|
200
|
+
// index simply hasn't been built in this workspace yet.
|
|
201
|
+
const hint = 'No artifact index found. Run `aiwg index build --graph framework` (or `aiwg use <framework>`) first.';
|
|
202
|
+
if (params.json) {
|
|
203
|
+
console.log(JSON.stringify({
|
|
204
|
+
query: { phrase: params.phrase, types },
|
|
205
|
+
results: [],
|
|
206
|
+
rule_stats: emptyRuleStats(),
|
|
207
|
+
total: 0,
|
|
208
|
+
hint,
|
|
209
|
+
}, null, 2));
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
console.error('Error: No artifact index found.');
|
|
213
|
+
console.log('Run `aiwg index build --graph framework` (or `aiwg use <framework>`) first.');
|
|
214
|
+
}
|
|
215
|
+
process.exit(1);
|
|
216
|
+
}
|
|
217
|
+
// Filter by type
|
|
218
|
+
entries = entries.filter(entry => isOrdinaryMemoryEntry(entry, cwd));
|
|
219
|
+
const candidates = entries.filter(e => types.includes(e.type));
|
|
220
|
+
// Score (strict overlap gate). Keep the full sorted list so the facet
|
|
221
|
+
// fusion below can inject/lift curated capabilities into the top-K before
|
|
222
|
+
// truncation — a capability that the lexical pass ranked outside `limit`
|
|
223
|
+
// (or missed entirely) still surfaces when the query activates its facet.
|
|
224
|
+
const lexicalDiagnostics = new Map();
|
|
225
|
+
const legacyStrictScored = candidates
|
|
226
|
+
.map(entry => {
|
|
227
|
+
const detailed = scoreEntryDetailed(entry, params.phrase);
|
|
228
|
+
const legacyScore = detailed.score;
|
|
229
|
+
const fortemiScore = fortemiCoreDiscoveryScores?.get(entry.path) ?? 0;
|
|
230
|
+
lexicalDiagnostics.set(entry.path, detailed.diagnostic);
|
|
231
|
+
return {
|
|
232
|
+
entry,
|
|
233
|
+
score: legacyScore > 0 ? legacyScore : fortemiScore * 0.2,
|
|
234
|
+
legacyScore,
|
|
235
|
+
};
|
|
236
|
+
})
|
|
237
|
+
.filter(r => r.score > 0)
|
|
238
|
+
.sort(compareDiscoverResults);
|
|
239
|
+
const strictScored = (legacyStrictScored.some(result => result.legacyScore > 0)
|
|
240
|
+
? legacyStrictScored.filter(result => result.legacyScore > 0)
|
|
241
|
+
: legacyStrictScored).map(({ entry, score }) => ({ entry, score }));
|
|
242
|
+
// Single-pass facet fusion (#1623 U3): fuse the curated feature→capability
|
|
243
|
+
// facets (expansion / persona / project / provider-capability) into the
|
|
244
|
+
// lexical ranking so canonical domain phrases rank their owning capability
|
|
245
|
+
// top-K instead of being out-scored by artifacts that merely mention the
|
|
246
|
+
// word. Facet activation can also rescue an otherwise-empty strict pass.
|
|
247
|
+
// #154 — a strict result anywhere in the corpus must not suppress relevant
|
|
248
|
+
// partial matches for a natural-language query. Score the relaxed pass on
|
|
249
|
+
// matched terms (unmatched terms do not divide the score), apply a noise
|
|
250
|
+
// floor, and union it with strict matches before ranking. Word-boundary
|
|
251
|
+
// token matching keeps this from resurrecting substring noise such as UX in
|
|
252
|
+
// Linux.
|
|
253
|
+
const RELAXED_MIN_SCORE = 0.02;
|
|
254
|
+
const strictPaths = new Set(strictScored.map(result => result.entry.path));
|
|
255
|
+
const combinedByPath = new Map(strictScored.map(result => [result.entry.path, result]));
|
|
256
|
+
for (const entry of candidates) {
|
|
257
|
+
const detailed = scoreEntryDetailed(entry, params.phrase, { relaxOverlap: true });
|
|
258
|
+
if (detailed.score < RELAXED_MIN_SCORE)
|
|
259
|
+
continue;
|
|
260
|
+
const existing = combinedByPath.get(entry.path);
|
|
261
|
+
if (!existing || detailed.score > existing.score) {
|
|
262
|
+
combinedByPath.set(entry.path, { entry, score: detailed.score });
|
|
263
|
+
lexicalDiagnostics.set(entry.path, detailed.diagnostic);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
const scored = dedupeDiscoverResults(await applyFacetFusion(Array.from(combinedByPath.values()).sort(compareDiscoverResults), candidates, params.phrase)).slice(0, limit);
|
|
267
|
+
const relaxed = scored.some(result => !strictPaths.has(result.entry.path));
|
|
268
|
+
if (params.shadowRoute) {
|
|
269
|
+
try {
|
|
270
|
+
await params.shadowRoute.observe(params.phrase, scored.map(result => ({
|
|
271
|
+
id: discoveryIdForEntry(result.entry), name: result.entry.name ?? result.entry.title,
|
|
272
|
+
type: result.entry.type, capability: result.entry.capability ?? result.entry.summary,
|
|
273
|
+
score: result.score,
|
|
274
|
+
})));
|
|
275
|
+
}
|
|
276
|
+
catch {
|
|
277
|
+
// An optional observation failure must never replace deterministic discovery.
|
|
278
|
+
params.shadowRoute.disable();
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
const queryTimeMs = Date.now() - startTime;
|
|
282
|
+
await emitDiscoverResults({ cwd, params, types, limit, aiwgRoot, entries, backend, resourceSource,
|
|
283
|
+
resolvedWebRelease, prebuiltRelations, scored, relaxed, queryTimeMs, lexicalDiagnostics });
|
|
284
|
+
}
|
|
285
|
+
//# sourceMappingURL=query-engine-discover.js.map
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
// Share entry identity, provenance, graph selection, and discovery ordering helpers.
|
|
2
|
+
import * as fs from 'node:fs';
|
|
3
|
+
import * as path from 'node:path';
|
|
4
|
+
import { projectAiwgPath, projectControlPath } from '../config/project-artifacts.js';
|
|
5
|
+
import { recordTypeForEntry, stableRecordId } from './browser-export.js';
|
|
6
|
+
import { loadGraphIndexFile } from './index-reader.js';
|
|
7
|
+
import { isOperationalShowType, OPERATIONAL_DISCOVERY_TYPES } from './types.js';
|
|
8
|
+
export function normalizeIndexedPath(entryPath) {
|
|
9
|
+
return entryPath.replace(/\\/g, '/');
|
|
10
|
+
}
|
|
11
|
+
/** Historical records stay in the index for explicit show/history lookup. */
|
|
12
|
+
export function isOrdinaryMemoryEntry(entry, _cwd) {
|
|
13
|
+
// Maintenance owners publish dispositions into the index before returning.
|
|
14
|
+
// Retrieval must not read sources: ordinary legacy entries need no memory
|
|
15
|
+
// stamp, and temporary source I/O failures cannot hide active metadata.
|
|
16
|
+
return !entry.memoryRecord || (entry.memoryRecord.lifecycle === 'active' && entry.memoryRecord.placement !== 'archived');
|
|
17
|
+
}
|
|
18
|
+
export const DEFAULT_ARTIFACT_SEARCH_BACKEND = 'fortemi-core';
|
|
19
|
+
export const DISCOVER_TYPE_ORDER = new Map([...OPERATIONAL_DISCOVERY_TYPES, 'hook', 'doc'].map((type, index) => [type, index]));
|
|
20
|
+
export function canonicalLocalityRank(entryPath) {
|
|
21
|
+
const normalized = entryPath.replace(/\\/g, '/');
|
|
22
|
+
if (normalized.startsWith('.aiwg/') || normalized.includes('/.aiwg/'))
|
|
23
|
+
return 0;
|
|
24
|
+
// Top-level persona mirrors are the least canonical source for a name a bundle
|
|
25
|
+
// also owns. Without this they fell into the catch-all below and scored 1,
|
|
26
|
+
// beating the bundle copy at 2 — the opposite of #1643. It only ever looked
|
|
27
|
+
// correct because a populated user index supplied provenance and `scopeRank`
|
|
28
|
+
// never reached this fallback (#2544).
|
|
29
|
+
if (normalized.startsWith('agentic/code/agents/') || normalized.includes('/agentic/code/agents/'))
|
|
30
|
+
return 4;
|
|
31
|
+
if (normalized.includes('/plugins/') || normalized.startsWith('agentic/code/plugins/'))
|
|
32
|
+
return 3;
|
|
33
|
+
if (normalized.includes('/frameworks/') ||
|
|
34
|
+
normalized.includes('/addons/') ||
|
|
35
|
+
normalized.includes('/extensions/') ||
|
|
36
|
+
normalized.startsWith('agentic/code/frameworks/') ||
|
|
37
|
+
normalized.startsWith('agentic/code/addons/') ||
|
|
38
|
+
normalized.startsWith('agentic/code/extensions/')) {
|
|
39
|
+
return 2;
|
|
40
|
+
}
|
|
41
|
+
return 1;
|
|
42
|
+
}
|
|
43
|
+
export function graphScope(graph) {
|
|
44
|
+
if (graph === 'project')
|
|
45
|
+
return 'project';
|
|
46
|
+
if (graph === 'user' || graph.startsWith('user-'))
|
|
47
|
+
return 'user';
|
|
48
|
+
if (graph === 'framework')
|
|
49
|
+
return 'packaged';
|
|
50
|
+
if (graph === 'codebase' || graph === 'source')
|
|
51
|
+
return 'codebase';
|
|
52
|
+
return 'custom';
|
|
53
|
+
}
|
|
54
|
+
export function withIndexProvenance(entry, graph) {
|
|
55
|
+
return { ...entry, indexGraph: graph, indexScope: graphScope(graph) };
|
|
56
|
+
}
|
|
57
|
+
/** Keep existing project capabilities visible while their derived cache is unavailable. */
|
|
58
|
+
export function projectCapabilityFallback(cwd) {
|
|
59
|
+
const index = loadGraphIndexFile(cwd, 'metadata.json', 'project');
|
|
60
|
+
if (index) {
|
|
61
|
+
const entries = Object.values(index.entries).map((entry) => withIndexProvenance(entry, 'project'));
|
|
62
|
+
if (entries.length > 0) {
|
|
63
|
+
// One diagnostic per command, on stderr so JSON and skill bodies stay parseable.
|
|
64
|
+
console.error('Warning: project capability cache is unavailable or stale; using the local project index. Run `aiwg index sync` to repair the cache.');
|
|
65
|
+
return entries;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (['extensions', 'addons', 'frameworks', 'plugins', 'skills'].some((dir) => fs.existsSync(projectAiwgPath(cwd, dir)))) {
|
|
69
|
+
console.error('Warning: project capabilities could not be loaded: the cache is unavailable and the local project index is missing or empty. Run `aiwg index build --graph project` to repair discovery.');
|
|
70
|
+
}
|
|
71
|
+
return index ? [] : null;
|
|
72
|
+
}
|
|
73
|
+
export function discoveryIdForEntry(entry) {
|
|
74
|
+
return stableRecordId(recordTypeForEntry(entry, 'v2'), entry.path);
|
|
75
|
+
}
|
|
76
|
+
export function logicalDiscoverKey(entry) {
|
|
77
|
+
const identity = (entry.name ?? entry.title ?? path.basename(entry.path))
|
|
78
|
+
.toLowerCase()
|
|
79
|
+
.replace(/[-_\s]+/g, ' ')
|
|
80
|
+
.trim();
|
|
81
|
+
return `${entry.type}:${identity}`;
|
|
82
|
+
}
|
|
83
|
+
export function dedupeDiscoverResults(results) {
|
|
84
|
+
const bestByIdentity = new Map();
|
|
85
|
+
for (const result of results) {
|
|
86
|
+
const key = logicalDiscoverKey(result.entry);
|
|
87
|
+
const existing = bestByIdentity.get(key);
|
|
88
|
+
if (!existing || compareDiscoverResults(result, existing) < 0) {
|
|
89
|
+
bestByIdentity.set(key, result);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return Array.from(bestByIdentity.values()).sort(compareDiscoverResults);
|
|
93
|
+
}
|
|
94
|
+
export function scopeRank(entry) {
|
|
95
|
+
const scope = entry.indexScope;
|
|
96
|
+
if (scope === 'project')
|
|
97
|
+
return 0;
|
|
98
|
+
if (scope === 'user')
|
|
99
|
+
return 1;
|
|
100
|
+
if (scope === 'custom')
|
|
101
|
+
return 2;
|
|
102
|
+
if (scope === 'packaged')
|
|
103
|
+
return 3;
|
|
104
|
+
if (scope === 'codebase')
|
|
105
|
+
return 4;
|
|
106
|
+
return canonicalLocalityRank(entry.path);
|
|
107
|
+
}
|
|
108
|
+
export function compareText(left, right) {
|
|
109
|
+
return (left ?? '').localeCompare(right ?? '');
|
|
110
|
+
}
|
|
111
|
+
export function compareDiscoverResults(left, right) {
|
|
112
|
+
const scoreCmp = right.score - left.score;
|
|
113
|
+
if (scoreCmp !== 0)
|
|
114
|
+
return scoreCmp;
|
|
115
|
+
const localityCmp = scopeRank(left.entry) - scopeRank(right.entry);
|
|
116
|
+
if (localityCmp !== 0)
|
|
117
|
+
return localityCmp;
|
|
118
|
+
const typeCmp = (DISCOVER_TYPE_ORDER.get(left.entry.type) ?? 99) -
|
|
119
|
+
(DISCOVER_TYPE_ORDER.get(right.entry.type) ?? 99);
|
|
120
|
+
if (typeCmp !== 0)
|
|
121
|
+
return typeCmp;
|
|
122
|
+
const nameCmp = compareText(left.entry.name ?? left.entry.title, right.entry.name ?? right.entry.title);
|
|
123
|
+
if (nameCmp !== 0)
|
|
124
|
+
return nameCmp;
|
|
125
|
+
return left.entry.path.localeCompare(right.entry.path);
|
|
126
|
+
}
|
|
127
|
+
export const DEFAULT_DISCOVER_TYPES = [...OPERATIONAL_DISCOVERY_TYPES];
|
|
128
|
+
export const DEFAULT_CAPABILITY_GRAPHS = ['project', 'user', 'framework'];
|
|
129
|
+
export function projectAllowsUserIndices(cwd) {
|
|
130
|
+
try {
|
|
131
|
+
const configPath = projectControlPath(cwd, 'aiwg.config');
|
|
132
|
+
if (!fs.existsSync(configPath))
|
|
133
|
+
return true;
|
|
134
|
+
const parsed = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
|
135
|
+
const index = parsed.index;
|
|
136
|
+
const userIndices = index?.userIndices;
|
|
137
|
+
if (userIndices?.enabled === false)
|
|
138
|
+
return false;
|
|
139
|
+
const indices = parsed.indices;
|
|
140
|
+
const user = indices?.user;
|
|
141
|
+
if (user?.enabled === false)
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
export function defaultCapabilityGraphs(cwd) {
|
|
150
|
+
if (projectAllowsUserIndices(cwd))
|
|
151
|
+
return DEFAULT_CAPABILITY_GRAPHS;
|
|
152
|
+
return DEFAULT_CAPABILITY_GRAPHS.filter((graph) => graph !== 'user' && !graph.startsWith('user-'));
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Resolve the AIWG installation root for path-anchoring discover output.
|
|
156
|
+
* Discover returns paths anchored to AIWG_ROOT so the agent's `Read`
|
|
157
|
+
* tool can resolve them from any project working directory (#1217).
|
|
158
|
+
*/
|
|
159
|
+
/**
|
|
160
|
+
* Build the `run_hint` string for a script-bearing skill entry (#1227).
|
|
161
|
+
*
|
|
162
|
+
* Format: `aiwg run skill <name> [-- <argsHint>]`. The skill name is the
|
|
163
|
+
* basename of its source directory (skills/<name>/SKILL.md), which is
|
|
164
|
+
* what `aiwg run skill` accepts.
|
|
165
|
+
*/
|
|
166
|
+
export function buildRunHint(entry) {
|
|
167
|
+
// Use the directory basename for slug-layout skills, filename stem otherwise.
|
|
168
|
+
const lastSlash = entry.path.lastIndexOf('/');
|
|
169
|
+
const tail = lastSlash >= 0 ? entry.path.slice(lastSlash + 1) : entry.path;
|
|
170
|
+
let name;
|
|
171
|
+
if (tail === 'SKILL.md' && lastSlash >= 0) {
|
|
172
|
+
const dir = entry.path.slice(0, lastSlash);
|
|
173
|
+
const dirSlash = dir.lastIndexOf('/');
|
|
174
|
+
name = dirSlash >= 0 ? dir.slice(dirSlash + 1) : dir;
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
name = tail.replace(/\.[^.]+$/, '');
|
|
178
|
+
}
|
|
179
|
+
const argsHint = entry.script?.argsHint ? ` -- ${entry.script.argsHint}` : '';
|
|
180
|
+
return `aiwg run skill ${name}${argsHint}`;
|
|
181
|
+
}
|
|
182
|
+
export function showHintForDiscoverResult(entry, id) {
|
|
183
|
+
if (isOperationalShowType(entry.type)) {
|
|
184
|
+
return `aiwg show ${entry.type} ${id}`;
|
|
185
|
+
}
|
|
186
|
+
return `aiwg show ${id}`;
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=query-engine-entries.js.map
|