@aiwg/cli 2026.10.15 → 2026.10.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (286) hide show
  1. package/agentic/code/providers/pi/aiwg-bridge.ts +45 -7
  2. package/dist/src/artifacts/citation-parser.js +7 -6
  3. package/dist/src/artifacts/corpus-tools/citation-densify.js +4 -2
  4. package/dist/src/artifacts/corpus-tools/cli.js +8 -3
  5. package/dist/src/artifacts/corpus-tools/discovery-log.js +26 -24
  6. package/dist/src/artifacts/corpus-tools/expand-cli.js +3 -2
  7. package/dist/src/artifacts/corpus-tools/expand-dates.js +107 -0
  8. package/dist/src/artifacts/corpus-tools/expand-queue.js +4 -1
  9. package/dist/src/artifacts/corpus-tools/expand-review.js +104 -0
  10. package/dist/src/artifacts/corpus-tools/expand-state.js +17 -1
  11. package/dist/src/artifacts/corpus-tools/expand.js +16 -17
  12. package/dist/src/artifacts/corpus-tools/induction-audit.js +7 -6
  13. package/dist/src/artifacts/corpus-tools/integrity-scan.js +3 -3
  14. package/dist/src/artifacts/corpus-tools/radar-shared.js +7 -9
  15. package/dist/src/artifacts/corpus-tools/ref-files.js +11 -0
  16. package/dist/src/artifacts/corpus-tools/resolve-cli.js +11 -3
  17. package/dist/src/artifacts/corpus-tools/resolve.js +42 -11
  18. package/dist/src/artifacts/corpus-tools/retrieval-lab.js +2 -1
  19. package/dist/src/artifacts/corpus-tools/sidecar-lint.js +4 -4
  20. package/dist/src/artifacts/corpus-tools/sidecar-repair.js +2 -1
  21. package/dist/src/artifacts/corpus-views/ref-parser.js +3 -17
  22. package/dist/src/artifacts/graph-query.js +5 -3
  23. package/dist/src/artifacts/hybrid-query.js +11 -2
  24. package/dist/src/artifacts/index-refresh.js +2 -0
  25. package/dist/src/artifacts/query-engine-corpus.js +217 -0
  26. package/dist/src/artifacts/query-engine-discover-output.js +229 -0
  27. package/dist/src/artifacts/query-engine-discover.js +285 -0
  28. package/dist/src/artifacts/query-engine-entries.js +188 -0
  29. package/dist/src/artifacts/query-engine-index.js +249 -0
  30. package/dist/src/artifacts/query-engine-matching.js +143 -0
  31. package/dist/src/artifacts/query-engine-options.js +2 -0
  32. package/dist/src/artifacts/query-engine-rules.js +202 -0
  33. package/dist/src/artifacts/query-engine-scoring.js +436 -0
  34. package/dist/src/artifacts/query-engine-show-card.js +194 -0
  35. package/dist/src/artifacts/query-engine-show-load.js +211 -0
  36. package/dist/src/artifacts/query-engine-show.js +300 -0
  37. package/dist/src/artifacts/query-engine.js +7 -2576
  38. package/dist/src/cli/handlers/daemon.js +17 -1
  39. package/dist/src/cli/handlers/doctor-args.js +10 -5
  40. package/dist/src/cli/handlers/doctor-help.js +4 -1
  41. package/dist/src/cli/handlers/index.js +2 -2
  42. package/dist/src/cli/handlers/mc-agents.js +111 -0
  43. package/dist/src/cli/handlers/mc-args.js +54 -0
  44. package/dist/src/cli/handlers/mc-control.js +227 -0
  45. package/dist/src/cli/handlers/mc-dispatch.js +203 -0
  46. package/dist/src/cli/handlers/mc-help.js +171 -0
  47. package/dist/src/cli/handlers/mc-run.js +343 -0
  48. package/dist/src/cli/handlers/mc-session.js +138 -0
  49. package/dist/src/cli/handlers/mc-status.js +258 -0
  50. package/dist/src/cli/handlers/mc-summary.js +43 -0
  51. package/dist/src/cli/handlers/mc-types.js +3 -0
  52. package/dist/src/cli/handlers/mc-worker.js +205 -0
  53. package/dist/src/cli/handlers/mc.js +12 -1665
  54. package/dist/src/cli/handlers/models-refusal.js +13 -0
  55. package/dist/src/cli/handlers/models-resource-sample.js +10 -0
  56. package/dist/src/cli/handlers/models.js +5 -3
  57. package/dist/src/cli/handlers/regenerate.js +8 -16
  58. package/dist/src/cli/handlers/remove-bundled.js +133 -0
  59. package/dist/src/cli/handlers/remove-options.js +31 -0
  60. package/dist/src/cli/handlers/remove-user.js +174 -0
  61. package/dist/src/cli/handlers/remove.js +201 -0
  62. package/dist/src/cli/handlers/sessions.js +7 -7
  63. package/dist/src/cli/handlers/subcommands-bundles.js +257 -0
  64. package/dist/src/cli/handlers/subcommands-discovery.js +165 -0
  65. package/dist/src/cli/handlers/subcommands-list-format.js +129 -0
  66. package/dist/src/cli/handlers/subcommands-list.js +250 -0
  67. package/dist/src/cli/handlers/subcommands-plugins.js +213 -0
  68. package/dist/src/cli/handlers/subcommands-quickref.js +58 -0
  69. package/dist/src/cli/handlers/subcommands-rlm.js +113 -0
  70. package/dist/src/cli/handlers/subcommands-services.js +66 -0
  71. package/dist/src/cli/handlers/subcommands-storage.js +259 -0
  72. package/dist/src/cli/handlers/subcommands.js +18 -1976
  73. package/dist/src/cli/handlers/update.js +157 -0
  74. package/dist/src/cli/handlers/use.js +14 -4
  75. package/dist/src/cli/handlers/utilities.js +3 -560
  76. package/dist/src/cli/handlers/utility-doctor.js +412 -0
  77. package/dist/src/cli/scope-resolver.js +1 -142
  78. package/dist/src/cli/services/deployment-verification.js +0 -1
  79. package/dist/src/cli/user-scope-mirror.js +173 -0
  80. package/dist/src/config/aiwg-config.js +2 -1
  81. package/dist/src/config/authorization-cli.js +7 -3
  82. package/dist/src/config/dispatch-host-thresholds.js +2 -0
  83. package/dist/src/config/dispatch-thresholds-runtime.d.mts +3 -2
  84. package/dist/src/config/dispatch-thresholds-runtime.mjs +21 -7
  85. package/dist/src/config/framework-aliases.js +12 -0
  86. package/dist/src/config/host-resource-report.d.mts +24 -0
  87. package/dist/src/config/host-resource-report.mjs +110 -0
  88. package/dist/src/config/host-resource-runtime.d.mts +37 -0
  89. package/dist/src/config/host-resource-runtime.mjs +296 -0
  90. package/dist/src/config/installed-selection.js +22 -0
  91. package/dist/src/config/worker-invocation-marker.d.mts +1 -0
  92. package/dist/src/config/worker-invocation-marker.mjs +2 -0
  93. package/dist/src/decision/ensemble-study/artifacts.js +7 -0
  94. package/dist/src/decision/ensemble-study/gate-policy.js +58 -0
  95. package/dist/src/decision/ensemble-study/gates.js +78 -0
  96. package/dist/src/decision/ensemble-study/protocol.js +18 -21
  97. package/dist/src/decision/ensemble-study/score.js +3 -2
  98. package/dist/src/decision/ensemble-study/statistics.js +7 -26
  99. package/dist/src/decision/heldout/access.js +74 -0
  100. package/dist/src/decision/heldout/calibration.js +1 -0
  101. package/dist/src/decision/heldout/collector.js +8 -1
  102. package/dist/src/decision/sensitivity/comparative-gates.js +135 -0
  103. package/dist/src/decision/sensitivity/comparative.js +18 -41
  104. package/dist/src/effects/verifiers/file.js +22 -5
  105. package/dist/src/extensions/claude-attribution.js +82 -0
  106. package/dist/src/extensions/claude-hooks-installer.js +133 -69
  107. package/dist/src/extensions/commands/daemon.js +109 -0
  108. package/dist/src/extensions/commands/definitions.js +5 -89
  109. package/dist/src/gates/evaluate.js +2 -358
  110. package/dist/src/gates/heldout.js +17 -7
  111. package/dist/src/gates/observations.js +363 -0
  112. package/dist/src/gates/pack-composition.js +270 -0
  113. package/dist/src/gates/pack-tightening.js +197 -0
  114. package/dist/src/gates/pack-validation.js +262 -0
  115. package/dist/src/gates/registry-error.js +5 -0
  116. package/dist/src/gates/registry.js +13 -685
  117. package/dist/src/lint/check-patterns.js +163 -0
  118. package/dist/src/lint/checks.js +268 -0
  119. package/dist/src/lint/reference-resolution.js +54 -0
  120. package/dist/src/lint/runner.js +3 -465
  121. package/dist/src/mcp/helpers.mjs +11 -1
  122. package/dist/src/mcp/json-document.mjs +29 -0
  123. package/dist/src/mcp/muse-native-config.mjs +1 -28
  124. package/dist/src/memory/project-registry.js +44 -4
  125. package/dist/src/mission-protocol/worker-review-gate.js +7 -0
  126. package/dist/src/models/worker-plan.js +36 -5
  127. package/dist/src/models/wrapper-deployment.js +25 -12
  128. package/dist/src/models/wrapper-enforcement.js +47 -7
  129. package/dist/src/network-analysis/research.js +2 -1
  130. package/dist/src/plugin/command-ownership.js +34 -0
  131. package/dist/src/plugin/skill-command-frontmatter.js +197 -0
  132. package/dist/src/plugin/skill-command-translator.js +6 -232
  133. package/dist/src/policy/hitl-check.js +14 -4
  134. package/dist/src/policy/hitl-consume.js +54 -0
  135. package/dist/src/policy/hitl-receipt.js +2 -0
  136. package/dist/src/policy/hitl.js +11 -3
  137. package/dist/src/providers/context-output-ownership.js +26 -0
  138. package/dist/src/providers/deployment-ownership.d.mts +19 -0
  139. package/dist/src/providers/deployment-ownership.mjs +226 -0
  140. package/dist/src/providers/deployment-removal.js +200 -0
  141. package/dist/src/providers/provider-context-contracts.js +162 -0
  142. package/dist/src/providers/provider-definition-schema.js +136 -0
  143. package/dist/src/providers/provider-definitions.js +8 -1298
  144. package/dist/src/providers/provider-seeds-1.js +360 -0
  145. package/dist/src/providers/provider-seeds-2.js +387 -0
  146. package/dist/src/providers/provider-seeds-3.js +262 -0
  147. package/dist/src/providers/removal-transaction.js +86 -0
  148. package/dist/src/providers/settings-document.d.mts +3 -0
  149. package/dist/src/providers/settings-document.mjs +47 -0
  150. package/dist/src/providers/settings-removal.js +190 -0
  151. package/dist/src/providers/skill-ownership.d.mts +19 -2
  152. package/dist/src/providers/skill-ownership.mjs +12 -4
  153. package/dist/src/providers/transformation-receipt-integration.js +15 -271
  154. package/dist/src/providers/transformation-receipt-outputs.js +99 -0
  155. package/dist/src/providers/transformation-receipt-source.js +194 -0
  156. package/dist/src/research/clients/arxiv.js +4 -30
  157. package/dist/src/research/clients/base.js +48 -22
  158. package/dist/src/research/identity.js +42 -4
  159. package/dist/src/research/query-cli.js +3 -87
  160. package/dist/src/research/query-options.js +87 -0
  161. package/dist/src/research/reference-match.js +105 -24
  162. package/dist/src/research/services/acquisition.js +9 -7
  163. package/dist/src/research/services/citation.js +5 -2
  164. package/dist/src/research/types.js +2 -0
  165. package/dist/src/rules/activation.mjs +15 -6
  166. package/dist/src/rules/core-startup.mjs +2 -2
  167. package/dist/src/serve/mission-conductor.js +52 -4
  168. package/dist/src/serve/mission-summary.js +56 -0
  169. package/dist/src/sessions/adapters/grok-build-native.js +23 -0
  170. package/dist/src/sessions/adapters/grok-build.js +14 -7
  171. package/dist/src/sessions/workspace-discovery.js +5 -5
  172. package/dist/src/smiths/context-pipeline/aiwg-md.js +39 -46
  173. package/dist/src/smiths/context-pipeline/claude-hook.js +1 -1
  174. package/dist/src/smiths/context-pipeline/code-regions.js +28 -0
  175. package/dist/src/smiths/context-pipeline/context-file-safety.js +3 -0
  176. package/dist/src/smiths/context-pipeline/finalization.js +81 -51
  177. package/dist/src/smiths/context-pipeline/generator.js +10 -11
  178. package/dist/src/smiths/context-pipeline/managed-hook.js +1 -1
  179. package/dist/src/smiths/context-pipeline/muse-bridge.js +2 -2
  180. package/dist/src/smiths/context-pipeline/provider-policy.js +6 -12
  181. package/dist/src/smiths/context-pipeline/workspace-audit.js +299 -0
  182. package/dist/src/smiths/context-pipeline/workspace-bootstrap.js +148 -0
  183. package/dist/src/smiths/context-pipeline/workspace-context-shared.js +111 -0
  184. package/dist/src/smiths/context-pipeline/workspace-context.js +8 -1373
  185. package/dist/src/smiths/context-pipeline/workspace-doctor.js +192 -0
  186. package/dist/src/smiths/context-pipeline/workspace-document.js +201 -0
  187. package/dist/src/smiths/context-pipeline/workspace-extraction.js +205 -0
  188. package/dist/src/smiths/context-pipeline/workspace-migration.js +250 -0
  189. package/dist/src/smiths/hook-bridge/index.js +9 -0
  190. package/package.json +13 -1
  191. package/schemas/decision/D17StudyProtocol.v1.schema.json +39 -67
  192. package/schemas/decision/D29Study.v10.schema.json +65 -0
  193. package/tools/agents/deploy-agents.mjs +24 -675
  194. package/tools/agents/deploy-command-mirrors.mjs +229 -0
  195. package/tools/agents/deploy-options.mjs +258 -0
  196. package/tools/agents/deploy-support.mjs +165 -0
  197. package/tools/agents/providers/base-addon-discovery.mjs +139 -0
  198. package/tools/agents/providers/base-behaviors.mjs +168 -0
  199. package/tools/agents/providers/base-context.mjs +205 -0
  200. package/tools/agents/providers/base-contract.mjs +116 -0
  201. package/tools/agents/providers/base-files.mjs +252 -0
  202. package/tools/agents/providers/base-flat-artifacts.mjs +233 -0
  203. package/tools/agents/providers/base-framework-discovery.mjs +309 -0
  204. package/tools/agents/providers/base-frontmatter.mjs +196 -0
  205. package/tools/agents/providers/base-inventory.mjs +269 -0
  206. package/tools/agents/providers/base-kernel-skills.mjs +354 -0
  207. package/tools/agents/providers/base-migrations.mjs +258 -0
  208. package/tools/agents/providers/base-models-platforms.mjs +273 -0
  209. package/tools/agents/providers/base-rule-index.mjs +450 -0
  210. package/tools/agents/providers/base-runtime.mjs +60 -0
  211. package/tools/agents/providers/base-skill-copy.mjs +273 -0
  212. package/tools/agents/providers/base.mjs +16 -3364
  213. package/tools/agents/providers/claude-post-deploy.mjs +20 -1
  214. package/tools/agents/providers/context-write.mjs +4 -0
  215. package/tools/agents/providers/hermes-startup.mjs +0 -5
  216. package/tools/agents/providers/muse.mjs +7 -2
  217. package/tools/agents/providers/pi.mjs +3 -1
  218. package/tools/agents/providers/rule-delivery-surface.mjs +359 -0
  219. package/tools/agents/providers/rule-delivery.mjs +20 -1144
  220. package/tools/agents/providers/rule-deployment-commit.mjs +148 -0
  221. package/tools/agents/providers/rule-deployment-prepare.mjs +461 -0
  222. package/tools/agents/providers/rule-deployment-state.mjs +300 -0
  223. package/tools/agents/providers/rule-projection.mjs +3 -0
  224. package/tools/daemon/README.md +511 -0
  225. package/tools/daemon/adapters/base-adapter.mjs +84 -0
  226. package/tools/daemon/adapters/webhook-adapter.mjs +107 -0
  227. package/tools/daemon/agent-supervisor.mjs +299 -0
  228. package/tools/daemon/automation-engine.mjs +310 -0
  229. package/tools/daemon/autonomous-engine.mjs +346 -0
  230. package/tools/daemon/behavior-loader.mjs +316 -0
  231. package/tools/daemon/behavior.mjs +174 -0
  232. package/tools/daemon/concierge/intent-router.mjs +401 -0
  233. package/tools/daemon/concierge/orchestrator.mjs +272 -0
  234. package/tools/daemon/concierge/response-translator.mjs +462 -0
  235. package/tools/daemon/config.mjs +377 -0
  236. package/tools/daemon/cron-scheduler.mjs +178 -0
  237. package/tools/daemon/daemon-main.mjs +1169 -0
  238. package/tools/daemon/event-router.mjs +84 -0
  239. package/tools/daemon/file-watcher.mjs +383 -0
  240. package/tools/daemon/index.mjs +1181 -0
  241. package/tools/daemon/init-profile.mjs +124 -0
  242. package/tools/daemon/ipc-client.mjs +197 -0
  243. package/tools/daemon/ipc-ops-handlers.mjs +236 -0
  244. package/tools/daemon/ipc-server.mjs +275 -0
  245. package/tools/daemon/maintenance-owner.mjs +79 -0
  246. package/tools/daemon/memory-manager.mjs +386 -0
  247. package/tools/daemon/message-router.mjs +194 -0
  248. package/tools/daemon/provider-watcher.mjs +585 -0
  249. package/tools/daemon/pty-adapter.mjs +420 -0
  250. package/tools/daemon/repl-chat.mjs +359 -0
  251. package/tools/daemon/resource-bounds.mjs +88 -0
  252. package/tools/daemon/sandbox-transport.mjs +295 -0
  253. package/tools/daemon/scheduled-task-runner.mjs +535 -0
  254. package/tools/daemon/task-store.mjs +450 -0
  255. package/tools/daemon/tmux-manager.mjs +324 -0
  256. package/tools/daemon/update-policy.mjs +517 -0
  257. package/tools/daemon/web-server.mjs +399 -0
  258. package/tools/daemon/web-ui/index.html +585 -0
  259. package/tools/daemon/web-ui/styles.css +156 -0
  260. package/tools/docker/Dockerfile.daemon +35 -0
  261. package/tools/docker/container-manager.mjs +291 -0
  262. package/tools/messaging/adapter-registry.mjs +230 -0
  263. package/tools/messaging/adapters/base.mjs +326 -0
  264. package/tools/messaging/adapters/discord.mjs +462 -0
  265. package/tools/messaging/adapters/slack.mjs +402 -0
  266. package/tools/messaging/adapters/telegram.mjs +552 -0
  267. package/tools/messaging/chat-handler.mjs +297 -0
  268. package/tools/messaging/command-router.mjs +269 -0
  269. package/tools/messaging/event-bus.mjs +199 -0
  270. package/tools/messaging/index.mjs +456 -0
  271. package/tools/messaging/message-formatter.mjs +320 -0
  272. package/tools/messaging/room-manager.mjs +277 -0
  273. package/tools/messaging/types.mjs +94 -0
  274. package/tools/providers/pi-bridge-policy.mjs +4 -0
  275. package/tools/ralph-external/daemon-supervisor.mjs +394 -0
  276. package/tools/ralph-external/lib/behavior-registry.mjs +270 -0
  277. package/tools/ralph-external/lib/worker-invocation-processes.mjs +7 -4
  278. package/tools/ralph-external/lib/worker-isolation-args.mjs +217 -0
  279. package/tools/ralph-external/lib/worker-isolation-status.mjs +19 -0
  280. package/tools/ralph-external/lib/worker-isolation.mjs +11 -237
  281. package/tools/ralph-external/lib/worker-overflow.mjs +10 -2
  282. package/tools/ralph-external/lib/worker-termination.mjs +15 -8
  283. package/tools/ralph-external/lib/worker-unit-cleanup.mjs +72 -0
  284. package/tools/ralph-external/session-launcher.mjs +7 -7
  285. package/tools/scripts/resource-preflight.mjs +3 -242
  286. package/vscode-extension/schemas/aiwg.config.v1.json +2 -4
@@ -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