@aiwg/cli 2026.8.18 → 2026.8.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/THIRD_PARTY_NOTICES.md +12 -0
  2. package/dist/src/api/index.d.ts +2 -0
  3. package/dist/src/api/index.js +2 -0
  4. package/dist/src/artifacts/backend-runtime.js +26 -0
  5. package/dist/src/artifacts/backends/sqlite-backend.js +204 -28
  6. package/dist/src/artifacts/dep-graph.js +27 -5
  7. package/dist/src/artifacts/graph-backend.js +2 -2
  8. package/dist/src/artifacts/graph-query.js +21 -9
  9. package/dist/src/artifacts/index-builder.js +78 -12
  10. package/dist/src/artifacts/index-files.js +26 -5
  11. package/dist/src/artifacts/index-status.js +4 -1
  12. package/dist/src/artifacts/query-engine.js +67 -67
  13. package/dist/src/artifacts/stats.js +9 -2
  14. package/dist/src/artifacts/types.js +14 -2
  15. package/dist/src/cli/handlers/help.js +2 -0
  16. package/dist/src/cli/handlers/index.js +6 -2
  17. package/dist/src/cli/handlers/installation.js +1 -1
  18. package/dist/src/cli/handlers/mission.js +27 -0
  19. package/dist/src/cli/handlers/refresh.js +6 -4
  20. package/dist/src/cli/handlers/runtime-info.js +29 -0
  21. package/dist/src/cli/handlers/steward.js +12 -0
  22. package/dist/src/cli/handlers/uhp.js +88 -0
  23. package/dist/src/cli/handlers/use.js +19 -4
  24. package/dist/src/config/aiwg-config.js +10 -0
  25. package/dist/src/extensions/commands/definitions.js +38 -0
  26. package/dist/src/installation/manager-command.mjs +31 -0
  27. package/dist/src/installation/manager.mjs +21 -0
  28. package/dist/src/mission-protocol/codecs.js +265 -0
  29. package/dist/src/mission-protocol/index.js +3 -0
  30. package/dist/src/mission-protocol/types.js +2 -0
  31. package/dist/src/smiths/context-pipeline/claude-hook.js +8 -5
  32. package/dist/src/smiths/context-pipeline/line-endings.js +12 -0
  33. package/dist/src/smiths/context-pipeline/managed-hook.js +8 -5
  34. package/dist/src/smiths/context-pipeline/workspace-context.js +3 -1
  35. package/dist/src/storage/backend-contract.js +64 -0
  36. package/dist/src/storage/index.js +2 -0
  37. package/dist/src/storage/migration-protocol.js +378 -0
  38. package/dist/src/uhp/client.js +374 -0
  39. package/dist/src/uhp/config.js +130 -0
  40. package/dist/src/uhp/errors.js +63 -0
  41. package/dist/src/uhp/index.js +7 -0
  42. package/dist/src/uhp/mission.js +111 -0
  43. package/dist/src/uhp/sse.js +76 -0
  44. package/dist/src/uhp/types.js +2 -0
  45. package/dist/src/update/service.mjs +3 -1
  46. package/package.json +1 -1
  47. package/tools/agents/deploy-agents.mjs +28 -8
  48. package/tools/agents/providers/base.mjs +5 -3
@@ -2,7 +2,7 @@
2
2
  * Artifact Index Builder
3
3
  *
4
4
  * Scans .aiwg/ directories, extracts metadata from artifact frontmatter,
5
- * computes checksums, extracts @-mention dependencies, and builds a
5
+ * computes checksums, extracts @-mention and Markdown-link dependencies, and builds a
6
6
  * structured index at .aiwg/.index/.
7
7
  *
8
8
  * @implements #415
@@ -68,6 +68,57 @@ export function extractMentions(content) {
68
68
  }
69
69
  return Array.from(mentions);
70
70
  }
71
+ /**
72
+ * Extract relative Markdown links that may resolve to graph-local artifacts.
73
+ *
74
+ * External URLs, absolute paths, and anchor-only links are intentionally absent
75
+ * from the accepted pattern. Resolution still happens later against indexed
76
+ * nodes, so a parsed link outside the active graph cannot create an edge.
77
+ */
78
+ export function extractMarkdownLinks(content) {
79
+ const links = new Set();
80
+ const pattern = /(!?)\[[^\]]+\]\((\.\/?[^)#\s]+)(?:#[^)]+)?\)/g;
81
+ let match;
82
+ while ((match = pattern.exec(content)) !== null) {
83
+ if (match[1] === '!')
84
+ continue;
85
+ links.add(match[2]);
86
+ }
87
+ return Array.from(links);
88
+ }
89
+ function resolveMarkdownLinkDependency(cwd, sourcePath, rawLink, entries, graph) {
90
+ const target = rawLink.split('#')[0]?.trim();
91
+ if (!target)
92
+ return null;
93
+ const sourceFullPath = absoluteEntryPath(cwd, sourcePath, graph);
94
+ const targetFullPath = path.resolve(path.dirname(sourceFullPath), target);
95
+ let stat;
96
+ try {
97
+ stat = fs.statSync(targetFullPath);
98
+ }
99
+ catch {
100
+ return null;
101
+ }
102
+ if (!stat.isFile())
103
+ return null;
104
+ const indexedPath = indexPathFor(cwd, targetFullPath, graph);
105
+ return entries[indexedPath] ? indexedPath : null;
106
+ }
107
+ function addDependencyEdge(depGraph, entries, sourcePath, targetPath, type) {
108
+ if (sourcePath === targetPath)
109
+ return false;
110
+ if (!depGraph[sourcePath])
111
+ depGraph[sourcePath] = { upstream: [], downstream: [] };
112
+ if (!depGraph[targetPath])
113
+ depGraph[targetPath] = { upstream: [], downstream: [] };
114
+ if (depGraph[sourcePath].upstream.some(edge => edge.path === targetPath))
115
+ return false;
116
+ depGraph[sourcePath].upstream.push({ path: targetPath, type });
117
+ depGraph[targetPath].downstream.push({ path: sourcePath, type });
118
+ if (entries[targetPath])
119
+ entries[targetPath].dependents.push(sourcePath);
120
+ return true;
121
+ }
71
122
  /**
72
123
  * Extract title from content (first # heading or frontmatter title)
73
124
  */
@@ -846,6 +897,7 @@ export async function buildIndex(cwd, options = {}) {
846
897
  const tags = flow ? flow.tags : (Array.isArray(data.tags) ? data.tags.map(String) : []);
847
898
  const summary = flow?.description ?? schemaDoc?.capability ?? runbook?.capability ?? extractSummary(data, body);
848
899
  const dependencies = extractMentions(content);
900
+ const markdownLinks = extractMarkdownLinks(content);
849
901
  // Discovery metadata (#1214, #1540, #1792) — meaningful for operational
850
902
  // AIWG artifact kinds. Kept undefined on document types so the index file
851
903
  // stays small for the common case.
@@ -879,6 +931,7 @@ export async function buildIndex(cwd, options = {}) {
879
931
  checksum,
880
932
  summary,
881
933
  dependencies,
934
+ ...(markdownLinks.length > 0 ? { markdownLinks } : {}),
882
935
  dependents: [], // Computed after all entries are processed
883
936
  ...(name ? { name } : {}),
884
937
  ...(triggers && triggers.length > 0 ? { triggers } : {}),
@@ -915,6 +968,7 @@ export async function buildIndex(cwd, options = {}) {
915
968
  }
916
969
  }
917
970
  // Build dependency graph and compute dependents
971
+ let markdownLinkEdgeCount = 0;
918
972
  for (const entry of Object.values(entries)) {
919
973
  if (!depGraph[entry.path]) {
920
974
  depGraph[entry.path] = { upstream: [], downstream: [] };
@@ -923,17 +977,13 @@ export async function buildIndex(cwd, options = {}) {
923
977
  // Normalize: check if referenced path exists in the index
924
978
  const normalizedDep = Object.keys(entries).find(p => p === dep || p.endsWith(dep));
925
979
  if (normalizedDep && normalizedDep !== entry.path) {
926
- const upEdge = { path: normalizedDep, type: 'depends-on' };
927
- depGraph[entry.path].upstream.push(upEdge);
928
- if (!depGraph[normalizedDep]) {
929
- depGraph[normalizedDep] = { upstream: [], downstream: [] };
930
- }
931
- const downEdge = { path: entry.path, type: 'depends-on' };
932
- depGraph[normalizedDep].downstream.push(downEdge);
933
- // Also update the dependents field on the target entry
934
- if (entries[normalizedDep]) {
935
- entries[normalizedDep].dependents.push(entry.path);
936
- }
980
+ addDependencyEdge(depGraph, entries, entry.path, normalizedDep, 'depends-on');
981
+ }
982
+ }
983
+ for (const link of entry.markdownLinks ?? []) {
984
+ const normalizedDep = resolveMarkdownLinkDependency(cwd, entry.path, link, entries, graph);
985
+ if (normalizedDep && addDependencyEdge(depGraph, entries, entry.path, normalizedDep, 'markdown-link')) {
986
+ markdownLinkEdgeCount++;
937
987
  }
938
988
  }
939
989
  }
@@ -1027,6 +1077,20 @@ export async function buildIndex(cwd, options = {}) {
1027
1077
  writeIndexFile(effectiveOutputCwd, 'metadata.json', index, indexOutputDir);
1028
1078
  writeIndexFile(effectiveOutputCwd, 'tags.json', tagIndex, indexOutputDir);
1029
1079
  writeIndexFile(effectiveOutputCwd, 'dependencies.json', depGraph, indexOutputDir);
1080
+ // Materialize the configured backend and always retain dependencies.json as
1081
+ // the stable compatibility/export contract.
1082
+ const { createGraphBackend } = await import('./graph-backend.js');
1083
+ const { resolveGraphBackendType } = await import('./types.js');
1084
+ const backendType = resolveGraphBackendType(graph);
1085
+ const persistentPath = backendType === 'sqlite' ? path.join(indexOutputDir, 'graph.db') : undefined;
1086
+ let selectedBackend;
1087
+ try {
1088
+ selectedBackend = await createGraphBackend(backendType, persistentPath);
1089
+ selectedBackend.deserialize(depGraph);
1090
+ }
1091
+ finally {
1092
+ await selectedBackend?.close?.();
1093
+ }
1030
1094
  // Update and persist the checksum manifest for faster future builds (#794).
1031
1095
  // The next manifest contains entries for every file we processed this build.
1032
1096
  // Files that disappeared from disk are pruned; the resulting manifest is
@@ -1068,7 +1132,9 @@ export async function buildIndex(cwd, options = {}) {
1068
1132
  byType,
1069
1133
  tagDistribution: tagDist,
1070
1134
  graphMetrics: {
1135
+ backend: backendType,
1071
1136
  totalEdges,
1137
+ markdownLinkEdges: markdownLinkEdgeCount,
1072
1138
  ...(citationMetrics ? {
1073
1139
  canonicalEdges: citationMetrics.canonicalEdges,
1074
1140
  outgoingDeclarations: citationMetrics.outgoingDeclarations,
@@ -31,22 +31,40 @@ export function indexPathFor(cwd, fullPath, graph) {
31
31
  return toPosixPath(relative);
32
32
  return fullPath;
33
33
  }
34
- /** Recursively find indexable files, excluding hidden directories such as .index. */
35
34
  export function findArtifactFiles(dir, extensions = DEFAULT_INDEX_EXTENSIONS) {
35
+ return walkArtifactFiles(dir, extensions, new Set());
36
+ }
37
+ /** Recursively find indexable files, excluding hidden directories such as .index. */
38
+ function walkArtifactFiles(dir, extensions, seenRealDirs) {
36
39
  const results = [];
37
40
  if (!fs.existsSync(dir))
38
41
  return results;
42
+ let realDir;
43
+ try {
44
+ realDir = fs.realpathSync(dir);
45
+ }
46
+ catch {
47
+ return results;
48
+ }
49
+ if (seenRealDirs.has(realDir))
50
+ return results;
51
+ seenRealDirs.add(realDir);
39
52
  const entries = fs.readdirSync(dir, { withFileTypes: true });
40
53
  for (const entry of entries) {
41
54
  const fullPath = path.join(dir, entry.name);
42
- if (entry.isSymbolicLink() && !fs.existsSync(fullPath))
55
+ let stat;
56
+ try {
57
+ stat = fs.statSync(fullPath);
58
+ }
59
+ catch {
43
60
  continue;
44
- if (entry.isDirectory()) {
61
+ }
62
+ if (stat.isDirectory()) {
45
63
  if (entry.name.startsWith('.'))
46
64
  continue;
47
- results.push(...findArtifactFiles(fullPath, extensions));
65
+ results.push(...walkArtifactFiles(fullPath, extensions, seenRealDirs));
48
66
  }
49
- else if (extensions.some(extension => entry.name.endsWith(extension))) {
67
+ else if (stat.isFile() && extensions.some(extension => entry.name.endsWith(extension))) {
50
68
  results.push(fullPath);
51
69
  }
52
70
  }
@@ -55,6 +73,9 @@ export function findArtifactFiles(dir, extensions = DEFAULT_INDEX_EXTENSIONS) {
55
73
  /** Return the exact current source-file set used by a standard graph build. */
56
74
  export async function collectGraphIndexFiles(cwd, graph) {
57
75
  const config = graph ? GRAPH_CONFIGS[graph] : undefined;
76
+ if (graph && !config) {
77
+ throw new Error(`Unknown graph: ${graph}`);
78
+ }
58
79
  const scanDirs = config
59
80
  ? config.scanDirs.map(directory => resolveGraphScanDir(cwd, directory))
60
81
  : [resolveProjectAiwgDir(cwd)];
@@ -18,7 +18,7 @@
18
18
  */
19
19
  import * as fs from 'node:fs';
20
20
  import * as path from 'node:path';
21
- import { GRAPH_CONFIGS, BUILTIN_GRAPH_CONFIGS, getGraphIndexDir, getProjectIndexRoot, loadGlobalGraphConfigs, loadUserGraphConfigs, } from './types.js';
21
+ import { GRAPH_CONFIGS, BUILTIN_GRAPH_CONFIGS, getGraphIndexDir, getProjectIndexRoot, loadGlobalGraphConfigs, loadUserGraphConfigs, resolveGraphBackendType, } from './types.js';
22
22
  import { getFortemiCoreSyncStatus, } from './fortemi-core-sync.js';
23
23
  function readBuiltMeta(indexDir) {
24
24
  try {
@@ -62,6 +62,7 @@ export function collectIndexStatus(cwd, nowMs) {
62
62
  }
63
63
  graphs.push({
64
64
  name,
65
+ backend: resolveGraphBackendType(name),
65
66
  origin: name in BUILTIN_GRAPH_CONFIGS ? 'builtin' : 'registered',
66
67
  shared: config.shared,
67
68
  defaultBuild: config.defaultBuild,
@@ -131,6 +132,7 @@ export async function showIndexStatus(cwd, opts = {}) {
131
132
  'GRAPH'.padEnd(22) +
132
133
  'ORIGIN'.padEnd(12) +
133
134
  'STATE'.padEnd(10) +
135
+ 'BACKEND'.padEnd(12) +
134
136
  'ENTRIES'.padEnd(9) +
135
137
  'AGE'.padEnd(10) +
136
138
  'LOCATION');
@@ -145,6 +147,7 @@ export async function showIndexStatus(cwd, opts = {}) {
145
147
  g.name.padEnd(22) +
146
148
  g.origin.padEnd(12) +
147
149
  state.padEnd(10) +
150
+ g.backend.padEnd(12) +
148
151
  String(g.entries ?? '—').padEnd(9) +
149
152
  age.padEnd(10) +
150
153
  shortenPath(g.location, cwd));
@@ -181,7 +181,7 @@ const SCORE_STOPWORDS = new Set([
181
181
  'with', 'into', 'from', 'is', 'are', 'be', 'i', 'we', 'my',
182
182
  // pronouns / determiners / fillers
183
183
  'it', 'you', 'me', 'us', 'your', 'our', 'this', 'that', 'these', 'those',
184
- 'there', 'here', 'some', 'any', 'all', 'also', 'please', 'about',
184
+ 'there', 'here', 'some', 'any', 'all', 'also', 'please', 'about', 'project',
185
185
  // question words
186
186
  'how', 'what', 'which', 'where', 'when', 'who', 'why',
187
187
  // asking / request verbs ("find a skill that handles …")
@@ -191,6 +191,7 @@ const SCORE_STOPWORDS = new Set([
191
191
  // AIWG meta-type nouns — zero discriminating signal in a discover query
192
192
  'aiwg', 'skill', 'skills', 'agent', 'agents', 'command', 'commands',
193
193
  'rule', 'rules', 'schema', 'schemas', 'flow', 'flows', 'workflow', 'workflows',
194
+ 'template', 'templates',
194
195
  ]);
195
196
  /**
196
197
  * Tokenize a query phrase into lowercased keywords for multi-word
@@ -200,8 +201,18 @@ const SCORE_STOPWORDS = new Set([
200
201
  function tokenize(text) {
201
202
  return text
202
203
  .toLowerCase()
203
- .split(/[^a-z0-9-]+/)
204
- .filter(t => t.length > 1 && !SCORE_STOPWORDS.has(t));
204
+ .split(/[^a-z0-9]+/)
205
+ .filter(t => t.length > 1 && !SCORE_STOPWORDS.has(t))
206
+ .map(token => token.length > 4 && token.endsWith('s') && !token.endsWith('ss')
207
+ ? token.slice(0, -1)
208
+ : token);
209
+ }
210
+ function matchedFieldTokens(queryTokens, field) {
211
+ const fieldTokens = new Set(tokenize(field));
212
+ return queryTokens.filter(token => fieldTokens.has(token));
213
+ }
214
+ function fieldContainsQuery(field, queryTokens) {
215
+ return containsTokenSequence(tokenize(field), queryTokens);
205
216
  }
206
217
  /**
207
218
  * Score a metadata entry against a keyword query.
@@ -297,6 +308,7 @@ function scoreEntryDetailed(entry, text, opts = {}) {
297
308
  const personaIdentitySuppressed = diagnoseFacetActivations(text).some((activation) => activation.facet === 'persona-identity' && activation.status === 'suppressed');
298
309
  let score = 0;
299
310
  const matches = [];
311
+ const creditedTokens = new Set();
300
312
  const finish = (uncappedScore = score, cap = 1) => ({
301
313
  score: Math.min(uncappedScore, cap),
302
314
  diagnostic: {
@@ -311,6 +323,17 @@ function scoreEntryDetailed(entry, text, opts = {}) {
311
323
  score += contribution;
312
324
  matches.push({ ...match, contribution });
313
325
  };
326
+ const addTokenMatch = (contributionPerToken, hits, match) => {
327
+ const newlyMatched = hits.filter(token => !creditedTokens.has(token));
328
+ if (newlyMatched.length === 0)
329
+ return;
330
+ newlyMatched.forEach(token => creditedTokens.add(token));
331
+ addMatch(contributionPerToken * newlyMatched.length, {
332
+ ...match,
333
+ matched_tokens: newlyMatched,
334
+ query_token_coverage: tokens.length > 0 ? newlyMatched.length / tokens.length : 0,
335
+ });
336
+ };
314
337
  // Exact-name floor (#1233) — if the query (normalized) exactly matches
315
338
  // the entry's canonical name, this is the artifact the user is asking
316
339
  // for and it must surface at the top regardless of how cluttered the
@@ -422,14 +445,12 @@ function scoreEntryDetailed(entry, text, opts = {}) {
422
445
  });
423
446
  }
424
447
  else if (useMultiToken) {
425
- const hits = tokens.filter(t => trigger.includes(t));
448
+ const hits = matchedFieldTokens(tokens, trigger);
426
449
  if (overlapOK(hits.length)) {
427
- addMatch(0.06 * 4 * (hits.length / tokens.length), {
450
+ addTokenMatch(0.1 * 4, hits, {
428
451
  field: 'trigger',
429
452
  match: 'token-overlap',
430
453
  value: trigger,
431
- matched_tokens: hits,
432
- query_token_coverage: hits.length / tokens.length,
433
454
  });
434
455
  }
435
456
  }
@@ -437,7 +458,7 @@ function scoreEntryDetailed(entry, text, opts = {}) {
437
458
  }
438
459
  // Capability description (2x weight) — full phrase first, then tokens
439
460
  if (capabilityLower) {
440
- if (capabilityLower.includes(lower)) {
461
+ if (fieldContainsQuery(capabilityLower, tokens)) {
441
462
  addMatch(0.2 * 2, {
442
463
  field: 'capability',
443
464
  match: 'contained-phrase',
@@ -445,20 +466,18 @@ function scoreEntryDetailed(entry, text, opts = {}) {
445
466
  });
446
467
  }
447
468
  else if (useMultiToken) {
448
- const hits = tokens.filter(t => capabilityLower.includes(t));
469
+ const hits = matchedFieldTokens(tokens, capabilityLower);
449
470
  if (overlapOK(hits.length)) {
450
- addMatch(0.1 * 2 * (hits.length / tokens.length), {
471
+ addTokenMatch(0.1 * 2, hits, {
451
472
  field: 'capability',
452
473
  match: 'token-overlap',
453
474
  value: entry.capability,
454
- matched_tokens: hits,
455
- query_token_coverage: hits.length / tokens.length,
456
475
  });
457
476
  }
458
477
  }
459
478
  }
460
479
  // Title (3x weight)
461
- if (titleLower.includes(lower)) {
480
+ if (fieldContainsQuery(titleLower, tokens)) {
462
481
  addMatch(0.3 * 3, {
463
482
  field: 'title',
464
483
  match: titleLower === lower ? 'exact' : 'contained-phrase',
@@ -469,93 +488,83 @@ function scoreEntryDetailed(entry, text, opts = {}) {
469
488
  }
470
489
  }
471
490
  else if (useMultiToken) {
472
- const hits = tokens.filter(t => titleLower.includes(t));
491
+ const hits = matchedFieldTokens(tokens, titleLower);
473
492
  if (overlapOK(hits.length)) {
474
- addMatch(0.08 * 3 * (hits.length / tokens.length), {
493
+ addTokenMatch(0.08 * 3, hits, {
475
494
  field: 'title',
476
495
  match: 'token-overlap',
477
496
  value: entry.title,
478
- matched_tokens: hits,
479
- query_token_coverage: hits.length / tokens.length,
480
497
  });
481
498
  }
482
499
  }
483
500
  // Tags (2x weight)
484
501
  for (const tag of tagsLower) {
485
- if (tag.includes(lower)) {
502
+ if (fieldContainsQuery(tag, tokens)) {
486
503
  addMatch(0.2 * 2, { field: 'tag', match: 'contained-phrase', value: tag });
487
504
  }
488
505
  else if (useMultiToken) {
489
- const hits = tokens.filter(t => tag.includes(t));
506
+ const hits = matchedFieldTokens(tokens, tag);
490
507
  if (overlapOK(hits.length)) {
491
- addMatch(0.05 * 2 * (hits.length / tokens.length), {
508
+ addTokenMatch(0.05 * 2, hits, {
492
509
  field: 'tag',
493
510
  match: 'token-overlap',
494
511
  value: tag,
495
- matched_tokens: hits,
496
- query_token_coverage: hits.length / tokens.length,
497
512
  });
498
513
  }
499
514
  }
500
515
  }
501
516
  // Structure-aware language terms (1.5x weight). These are deliberately
502
517
  // below declared triggers/capabilities but above generic body summaries.
503
- if (searchTermsLower.includes(lower)) {
518
+ if (fieldContainsQuery(searchTermsLower, tokens)) {
504
519
  addMatch(0.18 * 1.5, { field: 'search_terms', match: 'contained-phrase' });
505
520
  }
506
521
  else if (useMultiToken) {
507
- const hits = tokens.filter(t => searchTermsLower.includes(t));
522
+ const hits = matchedFieldTokens(tokens, searchTermsLower);
508
523
  if (overlapOK(hits.length)) {
509
- addMatch(0.06 * 1.5 * (hits.length / tokens.length), {
524
+ addTokenMatch(0.06 * 1.5, hits, {
510
525
  field: 'search_terms',
511
526
  match: 'token-overlap',
512
- matched_tokens: hits,
513
- query_token_coverage: hits.length / tokens.length,
514
527
  });
515
528
  }
516
529
  }
517
530
  // Exact declarative kind and physical source classification are compact,
518
531
  // useful routing signals (e.g. FlowPlaybook vs OpsInventory; runbook that
519
532
  // originated under templates/).
520
- if (kindLower.includes(lower)) {
533
+ if (fieldContainsQuery(kindLower, tokens)) {
521
534
  addMatch(0.15, { field: 'kind', match: 'contained-phrase', value: entry.kind });
522
535
  }
523
- if (sourceTypeLower.includes(lower)) {
536
+ if (fieldContainsQuery(sourceTypeLower, tokens)) {
524
537
  addMatch(0.08, { field: 'source_type', match: 'contained-phrase', value: entry.sourceType });
525
538
  }
526
539
  // Summary (1x weight)
527
- if (summaryLower.includes(lower)) {
540
+ if (fieldContainsQuery(summaryLower, tokens)) {
528
541
  addMatch(0.15, { field: 'summary', match: 'contained-phrase' });
529
542
  }
530
543
  else if (useMultiToken) {
531
- const hits = tokens.filter(t => summaryLower.includes(t));
544
+ const hits = matchedFieldTokens(tokens, summaryLower);
532
545
  if (overlapOK(hits.length)) {
533
- addMatch(0.04 * (hits.length / tokens.length), {
546
+ addTokenMatch(0.04, hits, {
534
547
  field: 'summary',
535
548
  match: 'token-overlap',
536
- matched_tokens: hits,
537
- query_token_coverage: hits.length / tokens.length,
538
549
  });
539
550
  }
540
551
  }
541
552
  // Path (0.5x weight)
542
- if (pathLower.includes(lower)) {
553
+ if (fieldContainsQuery(pathLower, tokens)) {
543
554
  addMatch(0.1, { field: 'path', match: 'contained-phrase', value: entry.path });
544
555
  }
545
556
  else if (useMultiToken) {
546
- const hits = tokens.filter(t => pathLower.includes(t));
557
+ const hits = matchedFieldTokens(tokens, pathLower);
547
558
  if (overlapOK(hits.length)) {
548
- addMatch(0.03 * (hits.length / tokens.length), {
559
+ addTokenMatch(0.03, hits, {
549
560
  field: 'path',
550
561
  match: 'token-overlap',
551
562
  value: entry.path,
552
- matched_tokens: hits,
553
- query_token_coverage: hits.length / tokens.length,
554
563
  });
555
564
  }
556
565
  }
557
566
  // Type (0.5x weight)
558
- if (typeLower.includes(lower)) {
567
+ if (fieldContainsQuery(typeLower, tokens)) {
559
568
  addMatch(0.1, { field: 'type', match: 'contained-phrase', value: entry.type });
560
569
  }
561
570
  return finish();
@@ -1078,36 +1087,27 @@ export async function discoverCapability(cwd, params) {
1078
1087
  // lexical ranking so canonical domain phrases rank their owning capability
1079
1088
  // top-K instead of being out-scored by artifacts that merely mention the
1080
1089
  // word. Facet activation can also rescue an otherwise-empty strict pass.
1081
- let scored = dedupeDiscoverResults(await applyFacetFusion(strictScored, candidates, params.phrase)).slice(0, limit);
1082
- // #1561 verbose-query fallback. A wordy full-sentence query
1083
- // ("find me a skill that handles intake forms") dilutes the token hit ratio
1084
- // below the strict ceil(n/2) overlap gate and returns nothing, training
1085
- // agents to conclude "no skill exists" the exact decline-without-search
1086
- // failure the skill-discovery rule guards against. When the strict pass
1087
- // dead-ends, re-score with a relaxed (single-hit) overlap so the meaningful
1088
- // tokens still surface ranked candidates rather than an empty set.
1089
- let relaxed = false;
1090
- if (scored.length === 0) {
1091
- // Floor the relaxed pass so a single incidental path/summary token hit
1092
- // (~0.006–0.008) doesn't surface as noise. Capability/title/trigger field
1093
- // hits land ~0.04+, so this keeps meaningful matches while dropping junk —
1094
- // if nothing clears the floor, we fall through to the no-match hint, which
1095
- // is more honest than surfacing a 0.01 path match.
1096
- const RELAXED_MIN_SCORE = 0.02;
1097
- const relaxedFull = candidates
1098
- .map(entry => {
1099
- const detailed = scoreEntryDetailed(entry, params.phrase, { relaxOverlap: true });
1090
+ // #154 a strict result anywhere in the corpus must not suppress relevant
1091
+ // partial matches for a natural-language query. Score the relaxed pass on
1092
+ // matched terms (unmatched terms do not divide the score), apply a noise
1093
+ // floor, and union it with strict matches before ranking. Word-boundary
1094
+ // token matching keeps this from resurrecting substring noise such as UX in
1095
+ // Linux.
1096
+ const RELAXED_MIN_SCORE = 0.02;
1097
+ const strictPaths = new Set(strictScored.map(result => result.entry.path));
1098
+ const combinedByPath = new Map(strictScored.map(result => [result.entry.path, result]));
1099
+ for (const entry of candidates) {
1100
+ const detailed = scoreEntryDetailed(entry, params.phrase, { relaxOverlap: true });
1101
+ if (detailed.score < RELAXED_MIN_SCORE)
1102
+ continue;
1103
+ const existing = combinedByPath.get(entry.path);
1104
+ if (!existing || detailed.score > existing.score) {
1105
+ combinedByPath.set(entry.path, { entry, score: detailed.score });
1100
1106
  lexicalDiagnostics.set(entry.path, detailed.diagnostic);
1101
- return { entry, score: detailed.score };
1102
- })
1103
- .filter(r => r.score >= RELAXED_MIN_SCORE)
1104
- .sort(compareDiscoverResults);
1105
- const relaxedScored = dedupeDiscoverResults(await applyFacetFusion(relaxedFull, candidates, params.phrase)).slice(0, limit);
1106
- if (relaxedScored.length > 0) {
1107
- scored = relaxedScored;
1108
- relaxed = true;
1109
1107
  }
1110
1108
  }
1109
+ const scored = dedupeDiscoverResults(await applyFacetFusion(Array.from(combinedByPath.values()).sort(compareDiscoverResults), candidates, params.phrase)).slice(0, limit);
1110
+ const relaxed = scored.some(result => !strictPaths.has(result.entry.path));
1111
1111
  const queryTimeMs = Date.now() - startTime;
1112
1112
  /**
1113
1113
  * Resolve a stored framework-graph path to an absolute AIWG_ROOT
@@ -7,7 +7,7 @@
7
7
  * @source @src/artifacts/types.ts
8
8
  * @tests @test/unit/artifacts/stats.test.ts
9
9
  */
10
- import { GRAPH_CONFIGS, loadUserGraphConfigs } from './types.js';
10
+ import { GRAPH_CONFIGS, loadGlobalGraphConfigs, loadUserGraphConfigs, resolveGraphBackendType } from './types.js';
11
11
  import { loadIndexStats, loadGraphIndexFile } from './index-reader.js';
12
12
  import { collectGraphIndexFiles, indexPathFor } from './index-files.js';
13
13
  /** Calculate coverage over the same current file set used by the index builder. */
@@ -30,6 +30,8 @@ async function calculateCoverage(cwd, stats, graphType) {
30
30
  */
31
31
  export async function showStats(cwd, options = {}) {
32
32
  const { graph } = options;
33
+ loadUserGraphConfigs(cwd);
34
+ loadGlobalGraphConfigs();
33
35
  if (graph) {
34
36
  // Single graph mode
35
37
  const stats = loadGraphIndexFile(cwd, 'stats.json', graph);
@@ -42,7 +44,6 @@ export async function showStats(cwd, options = {}) {
42
44
  return;
43
45
  }
44
46
  // No graph specified: show all graphs with defaultBuild=true
45
- loadUserGraphConfigs(cwd);
46
47
  const graphTypes = Object.entries(GRAPH_CONFIGS)
47
48
  .filter(([, config]) => config.defaultBuild)
48
49
  .map(([name]) => name);
@@ -70,6 +71,7 @@ export async function showStats(cwd, options = {}) {
70
71
  const coverage = await calculateCoverage(cwd, s, type);
71
72
  combined[type] = {
72
73
  ...s,
74
+ backend: resolveGraphBackendType(type),
73
75
  coverage,
74
76
  };
75
77
  }
@@ -90,6 +92,7 @@ async function renderStats(cwd, stats, options, graphType) {
90
92
  const coverage = await calculateCoverage(cwd, stats, graphType);
91
93
  console.log(JSON.stringify({
92
94
  ...stats,
95
+ backend: resolveGraphBackendType(graphType),
93
96
  coverage,
94
97
  }, null, 2));
95
98
  return;
@@ -100,6 +103,7 @@ async function renderStats(cwd, stats, options, graphType) {
100
103
  console.log(`Index version: ${stats.version}`);
101
104
  console.log(`Last built: ${stats.builtAt}`);
102
105
  console.log(`Build time: ${stats.buildTimeMs}ms`);
106
+ console.log(`Graph backend: ${resolveGraphBackendType(graphType)}`);
103
107
  console.log('');
104
108
  // By phase
105
109
  console.log('Artifacts by Phase:');
@@ -128,6 +132,9 @@ async function renderStats(cwd, stats, options, graphType) {
128
132
  // Dependency graph
129
133
  console.log('Dependency Graph:');
130
134
  console.log(` Total edges: ${stats.graphMetrics.totalEdges}`);
135
+ if (stats.graphMetrics.markdownLinkEdges !== undefined) {
136
+ console.log(` Markdown link edges:${String(stats.graphMetrics.markdownLinkEdges).padStart(3)}`);
137
+ }
131
138
  if (stats.graphMetrics.canonicalEdges !== undefined) {
132
139
  console.log(` Canonical edges: ${stats.graphMetrics.canonicalEdges}`);
133
140
  console.log(` Outgoing declares: ${stats.graphMetrics.outgoingDeclarations}`);
@@ -104,7 +104,7 @@ export const INDEX_VERSION = '1.0.0';
104
104
  * making the serialized index schema incompatible; a mismatch simply forces a
105
105
  * one-time content re-extraction during the next incremental build.
106
106
  */
107
- export const INDEX_EXTRACTOR_VERSION = '2026.07.21.2';
107
+ export const INDEX_EXTRACTOR_VERSION = '2026.08.24.1';
108
108
  /**
109
109
  * Built-in graph definitions
110
110
  */
@@ -195,6 +195,11 @@ export const BUILTIN_GRAPH_CONFIGS = {
195
195
  * @implements #426
196
196
  */
197
197
  export const GRAPH_CONFIGS = { ...BUILTIN_GRAPH_CONFIGS };
198
+ let projectGraphBackend;
199
+ /** Resolve backend precedence: graph override, project default, then JSON. */
200
+ export function resolveGraphBackendType(graph) {
201
+ return (graph ? GRAPH_CONFIGS[graph]?.graphBackend : undefined) ?? projectGraphBackend ?? 'json';
202
+ }
198
203
  function freshBuiltinGraphConfig(name) {
199
204
  const config = BUILTIN_GRAPH_CONFIGS[name];
200
205
  return {
@@ -459,6 +464,7 @@ export function loadUserGraphConfigs(cwd, diagnostics) {
459
464
  // Reset on every project load so a prior cwd cannot leak its override or
460
465
  // detected Python package roots into a later build in the same process.
461
466
  GRAPH_CONFIGS.codebase = detectPythonCodebaseConfig(cwd, freshBuiltinGraphConfig('codebase'));
467
+ projectGraphBackend = undefined;
462
468
  // Load module-declared graphs first (frameworks/addons)
463
469
  const moduleLoaded = loadModuleGraphConfigs(cwd, diagnostics);
464
470
  const loaded = [...moduleLoaded];
@@ -469,12 +475,16 @@ export function loadUserGraphConfigs(cwd, diagnostics) {
469
475
  let graphs;
470
476
  let graphOverrides;
471
477
  let fromDeprecatedYaml = false;
478
+ let canonicalIndexPresent = false;
472
479
  // (a) Canonical: .aiwg/aiwg.config (JSON).
473
480
  try {
474
481
  const aiwgConfigPath = projectControlPath(cwd, 'aiwg.config');
475
482
  if (fs.existsSync(aiwgConfigPath)) {
476
483
  const parsed = JSON.parse(fs.readFileSync(aiwgConfigPath, 'utf-8'));
477
484
  const idx = parsed.index;
485
+ canonicalIndexPresent = idx !== undefined;
486
+ if (idx?.graphBackend === 'json' || idx?.graphBackend === 'graphology' || idx?.graphBackend === 'sqlite')
487
+ projectGraphBackend = idx.graphBackend;
478
488
  const g = idx?.graphs;
479
489
  if (g && typeof g === 'object')
480
490
  graphs = g;
@@ -493,12 +503,14 @@ export function loadUserGraphConfigs(cwd, diagnostics) {
493
503
  });
494
504
  }
495
505
  // (b) Fallback: legacy .aiwg/config.yaml.
496
- if (!graphs && !graphOverrides) {
506
+ if (!canonicalIndexPresent && !graphs && !graphOverrides) {
497
507
  try {
498
508
  const configPath = projectAiwgPath(cwd, 'config.yaml');
499
509
  if (fs.existsSync(configPath)) {
500
510
  const config = loadYaml(fs.readFileSync(configPath, 'utf-8'));
501
511
  const idx = config?.index;
512
+ if (idx?.graphBackend === 'json' || idx?.graphBackend === 'graphology' || idx?.graphBackend === 'sqlite')
513
+ projectGraphBackend = idx.graphBackend;
502
514
  const g = idx?.graphs;
503
515
  if (g && typeof g === 'object') {
504
516
  graphs = g;
@@ -71,6 +71,8 @@ function displayHelp() {
71
71
  ['runtime-info', 'Show runtime environment summary'],
72
72
  ['runtime-info --discover', 'Full tool discovery and catalog generation'],
73
73
  ['runtime-info --check <tool>', 'Check specific tool availability'],
74
+ ['runtime-info --transports', 'Show configured transport capabilities separately from providers'],
75
+ ['uhp <operation> --profile <name>', 'Inspect or smoke-test an explicit experimental UHP endpoint profile'],
74
76
  ]);
75
77
  helpGroup('CATALOG', [
76
78
  ['catalog list', 'List all models in catalog'],