@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,211 @@
1
+ // Load local or verified web metadata for show lookups.
2
+ import * as fs from 'node:fs';
3
+ import * as path from 'node:path';
4
+ import { projectAiwgPath } from '../config/project-artifacts.js';
5
+ import { refreshFrameworkCapabilities, resolveFrameworkCorpusRoot } from './framework-capabilities.js';
6
+ import { resolveFrameworkIndexRoot } from './framework-index-paths.js';
7
+ import { loadGraphIndexFile, loadMetadataIndex } from './index-reader.js';
8
+ import { DEFAULT_ARTIFACT_SEARCH_BACKEND, defaultCapabilityGraphs, discoveryIdForEntry, isOrdinaryMemoryEntry, normalizeIndexedPath, projectCapabilityFallback, withIndexProvenance, } from './query-engine-entries.js';
9
+ import { findShowMatches } from './query-engine-matching.js';
10
+ import { ensureRelations } from './relations.js';
11
+ import { getGraphIndexDir, OPERATIONAL_SHOW_TYPES } from './types.js';
12
+ export function resolveMetadataPath(cwd, aiwgRoot, entry) {
13
+ if (path.isAbsolute(entry.path))
14
+ return entry.path;
15
+ const normalizedPath = normalizeIndexedPath(entry.path);
16
+ if (aiwgRoot && normalizedPath.startsWith('agentic/code/')) {
17
+ return path.join(aiwgRoot, normalizedPath);
18
+ }
19
+ if (entry.indexScope === 'user' && normalizedPath.startsWith('~/.aiwg/')) {
20
+ return path.join(process.env.HOME ?? '', normalizedPath.slice(2));
21
+ }
22
+ if (normalizedPath.startsWith('.aiwg/')) {
23
+ return projectAiwgPath(cwd, normalizedPath.slice('.aiwg/'.length));
24
+ }
25
+ return path.join(cwd, normalizedPath);
26
+ }
27
+ export async function loadShowEntries(cwd, params, compact = false) {
28
+ const aiwgRoot = resolveFrameworkIndexRoot(cwd);
29
+ const backend = params.backend ?? DEFAULT_ARTIFACT_SEARCH_BACKEND;
30
+ let resourceSource = params.resourceSource ?? 'local';
31
+ let entries = [];
32
+ let relations;
33
+ if (compact && resourceSource !== 'web' && (!params.graph || params.graph === 'framework')) {
34
+ relations = await ensureRelations(cwd) ?? undefined;
35
+ if (relations?.index.artifacts) {
36
+ const reader = relations;
37
+ const matched = findShowMatches(Object.values(reader.index.artifacts), params.typeFilter ?? [...OPERATIONAL_SHOW_TYPES], params.name.trim());
38
+ const frameworkEntries = matched.map(entry => {
39
+ const id = discoveryIdForEntry(entry);
40
+ const rule = reader.index.rules[id];
41
+ return withIndexProvenance({ ...entry, phase: '', tags: [], created: '', updated: '', checksum: '', summary: '', dependencies: [], dependents: [],
42
+ ...(rule ? { activation: reader.pinnedRuleIds.has(id) ? 'kernel' : rule.activation ?? undefined,
43
+ ruleSummary: rule.summary, ruleEnforcement: rule.enforcement ?? undefined, bound_to: rule.bound_to } : {}),
44
+ }, 'framework');
45
+ });
46
+ const localEntries = params.graph ? [] : defaultCapabilityGraphs(cwd).filter(graph => graph !== 'framework')
47
+ .flatMap(graph => loadLocalCapabilityEntries(cwd, graph, undefined, true));
48
+ const compactEntries = [...localEntries, ...frameworkEntries];
49
+ if ((params.typeFilter?.every(type => ['skill', 'agent', 'flow', 'command', 'rule', 'behavior'].includes(type)))
50
+ || findShowMatches(compactEntries, params.typeFilter ?? [...OPERATIONAL_SHOW_TYPES], params.name.trim()).length) {
51
+ return { entries: compactEntries, aiwgRoot, resourceSource: 'local', relations };
52
+ }
53
+ }
54
+ }
55
+ if (resourceSource !== 'web' && (!params.graph || params.graph === 'framework')) {
56
+ const root = resolveFrameworkCorpusRoot(cwd) ?? aiwgRoot;
57
+ if (root) {
58
+ try {
59
+ await refreshFrameworkCapabilities(root, backend === 'fortemi-core' && params.backend !== undefined);
60
+ }
61
+ catch (error) {
62
+ console.error(`Warning: capability index refresh failed: ${error instanceof Error ? error.message : String(error)}`);
63
+ }
64
+ }
65
+ }
66
+ if (resourceSource === 'auto' && backend === 'fortemi-core') {
67
+ const { loadFortemiCoreMetadataEntries } = await import('./fortemi-core-query-adapter.js');
68
+ const localGraphs = params.graph ? [params.graph] : defaultCapabilityGraphs(cwd);
69
+ resourceSource = localGraphs.some((graph) => loadFortemiCoreMetadataEntries(cwd, graph).entries.length > 0) ? 'local' : 'web';
70
+ }
71
+ else if (resourceSource === 'auto') {
72
+ resourceSource = 'local';
73
+ }
74
+ if (resourceSource === 'web') {
75
+ if (backend !== 'fortemi-core') {
76
+ console.error('Error: --resource-source web requires the Fortemi Core query backend; --backend local remains available with local resources.');
77
+ process.exit(1);
78
+ }
79
+ if (params.graph && params.graph !== 'framework') {
80
+ console.error("Error: web-backed show currently supports only the 'framework' graph.");
81
+ process.exit(1);
82
+ }
83
+ try {
84
+ const { resolveWebRelease } = await import('../resources/web-release.js');
85
+ const webRelease = await resolveWebRelease({
86
+ ...params.webReleaseOptions,
87
+ selector: params.aiwgVersion ?? 'stable',
88
+ offline: params.offline,
89
+ });
90
+ const sourcePaths = {
91
+ manifestPath: webRelease.fortemiManifestPath,
92
+ exportPath: webRelease.fortemiExportPath,
93
+ manifestSha256: webRelease.fortemiManifestSha256,
94
+ manifestSize: webRelease.fortemiManifestSize,
95
+ exportSha256: webRelease.fortemiExportSha256,
96
+ exportSize: webRelease.fortemiExportSize,
97
+ };
98
+ const { loadFortemiCoreMetadataEntries } = await import('./fortemi-core-query-adapter.js');
99
+ const loaded = loadFortemiCoreMetadataEntries(cwd, 'framework', sourcePaths);
100
+ if (loaded.reason)
101
+ throw new Error(loaded.reason);
102
+ entries = loaded.entries.map((entry) => withIndexProvenance(entry, 'framework'));
103
+ return { entries, aiwgRoot, resourceSource: 'web', webRelease, sourcePaths };
104
+ }
105
+ catch (error) {
106
+ console.error(`Error: AIWG web resource resolution failed: ${error instanceof Error ? error.message : String(error)}`);
107
+ process.exit(1);
108
+ }
109
+ }
110
+ // Preserve the direct API's historical local-index behavior when callers
111
+ // omit `backend`. The CLI always passes its explicit Fortemi default, while
112
+ // an explicit `auto` source also opts into Fortemi-backed availability.
113
+ if (params.backend === 'fortemi-core' || params.resourceSource === 'auto') {
114
+ const { loadFortemiCoreMetadataEntries } = await import('./fortemi-core-query-adapter.js');
115
+ const graphs = params.graph ? [params.graph] : defaultCapabilityGraphs(cwd);
116
+ let unavailableReason;
117
+ for (const graph of graphs) {
118
+ const loaded = loadFortemiCoreMetadataEntries(cwd, graph);
119
+ if (loaded.reason && graph === 'project' && !params.graph) {
120
+ const fallback = projectCapabilityFallback(cwd);
121
+ if (fallback) {
122
+ entries.push(...fallback);
123
+ continue;
124
+ }
125
+ }
126
+ if (loaded.reason) {
127
+ unavailableReason ??= loaded.reason;
128
+ if (graph === 'framework' && !params.graph) {
129
+ console.error(`Warning: framework capabilities are unavailable: ${loaded.reason}`);
130
+ }
131
+ }
132
+ entries.push(...loaded.entries.map((entry) => withIndexProvenance(entry, graph)));
133
+ }
134
+ if (entries.length === 0 && unavailableReason) {
135
+ if (params.json) {
136
+ console.log(JSON.stringify({
137
+ backend: 'fortemi-core',
138
+ name: params.name,
139
+ error: unavailableReason,
140
+ }, null, 2));
141
+ }
142
+ else {
143
+ console.error('Error: ' + unavailableReason);
144
+ }
145
+ process.exit(1);
146
+ }
147
+ }
148
+ else {
149
+ entries = loadLocalCapabilityEntries(cwd, params.graph, undefined, true);
150
+ }
151
+ return { entries, aiwgRoot, resourceSource: 'local', relations };
152
+ }
153
+ /** Local index inputs shared by show and exact rule-binding validation (#2938). */
154
+ export function loadLocalCapabilityEntries(cwd, graph, snapshot, includeHistory = false) {
155
+ const entries = [];
156
+ for (const selectedGraph of graph ? [graph] : defaultCapabilityGraphs(cwd)) {
157
+ const key = snapshot && `${selectedGraph}:${getGraphIndexDir(cwd, selectedGraph)}`;
158
+ let selected = key ? snapshot.get(key) : undefined;
159
+ if (!selected) {
160
+ const index = loadGraphIndexFile(cwd, 'metadata.json', selectedGraph);
161
+ selected = index ? Object.values(index.entries).map(entry => withIndexProvenance(entry, selectedGraph)) : [];
162
+ if (key)
163
+ snapshot.set(key, selected);
164
+ }
165
+ entries.push(...selected);
166
+ }
167
+ if (!graph && entries.length === 0) {
168
+ const legacy = loadMetadataIndex(cwd);
169
+ if (legacy)
170
+ entries.push(...Object.values(legacy.entries));
171
+ }
172
+ return includeHistory ? entries : entries.filter(entry => isOrdinaryMemoryEntry(entry, cwd));
173
+ }
174
+ /** Project/user inputs only; package artifacts come from a validated compact table. */
175
+ export function loadLocalOverrideCapabilityEntries(cwd) {
176
+ const local = defaultCapabilityGraphs(cwd).filter(graph => graph !== 'framework')
177
+ .flatMap(graph => loadLocalCapabilityEntries(cwd, graph));
178
+ if (local.length)
179
+ return local;
180
+ const canonical = (directory) => {
181
+ try {
182
+ return fs.realpathSync(directory);
183
+ }
184
+ catch {
185
+ return path.resolve(directory);
186
+ }
187
+ };
188
+ const packageRoot = canonical(resolveFrameworkIndexRoot(cwd));
189
+ // Retain the legacy PROJECT index, never use the package's full index as a fallback.
190
+ if (canonical(cwd) === packageRoot)
191
+ return [];
192
+ const legacy = loadMetadataIndex(cwd);
193
+ return Object.values(legacy?.entries ?? {}).filter(entry => {
194
+ const provenance = entry;
195
+ if (provenance.indexGraph === 'framework' || provenance.indexScope === 'packaged'
196
+ || normalizeIndexedPath(entry.path).startsWith('agentic/code/'))
197
+ return false;
198
+ const relative = path.relative(packageRoot, path.resolve(cwd, entry.path));
199
+ return relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative);
200
+ }).map(entry => withIndexProvenance(entry, 'project'));
201
+ }
202
+ export async function fortemiRecordForEntry(cwd, entry, sourcePaths) {
203
+ const graph = (entry.indexGraph ?? 'project');
204
+ const { loadFortemiCoreExport } = await import('./fortemi-core-query-adapter.js');
205
+ const loaded = loadFortemiCoreExport(cwd, graph, sourcePaths);
206
+ if (!loaded.exported)
207
+ return null;
208
+ const id = discoveryIdForEntry(entry);
209
+ return loaded.exported.items.find((record) => record.id === id || record.source.path === entry.path) ?? null;
210
+ }
211
+ //# sourceMappingURL=query-engine-show-load.js.map
@@ -0,0 +1,300 @@
1
+ // Serve artifact bodies and metadata through the show surface.
2
+ import * as path from 'node:path';
3
+ import { loadProviderModelMetadata } from '../models/provider-models.js';
4
+ import { isCorpusBundleInstalled } from './framework-capabilities.js';
5
+ import { findCorpusArtifact } from './query-engine-corpus.js';
6
+ import { buildRunHint, DEFAULT_ARTIFACT_SEARCH_BACKEND, discoveryIdForEntry, normalizeIndexedPath, } from './query-engine-entries.js';
7
+ import { findShowMatches } from './query-engine-matching.js';
8
+ import { showBindings } from './query-engine-rules.js';
9
+ import { emitShowCard } from './query-engine-show-card.js';
10
+ import { fortemiRecordForEntry, loadShowEntries, resolveMetadataPath } from './query-engine-show-load.js';
11
+ import { loadGlobalGraphConfigs, OPERATIONAL_SHOW_TYPES } from './types.js';
12
+ /**
13
+ * Emit a metadata card, with opt-in body/section drill-ins for a
14
+ * SKILL.md. Consumers don't need to know where AIWG stores skills —
15
+ * they pass the skill name and the CLI reads the file from the indexed
16
+ * location.
17
+ *
18
+ * Lookup order:
19
+ * 1. Stable discover/Fortemi id
20
+ * 2. Exact path match against any indexed entry's stored path
21
+ * 3. Basename match (e.g. `intake-wizard` matches an entry whose
22
+ * directory basename is `intake-wizard`)
23
+ * 4. Title match (case-insensitive)
24
+ * 5. Corpus fallback under AIWG_ROOT (#1221)
25
+ *
26
+ * On ambiguity, lists all matches and exits with code 2 unless
27
+ * `--first` is supplied.
28
+ */
29
+ export async function showArtifact(cwd, params) {
30
+ loadGlobalGraphConfigs();
31
+ const { promises: fs } = await import('node:fs');
32
+ const types = params.typeFilter && params.typeFilter.length > 0
33
+ ? params.typeFilter
34
+ : [...OPERATIONAL_SHOW_TYPES];
35
+ const { entries, aiwgRoot, resourceSource, webRelease, relations, } = await loadShowEntries(cwd, params, true);
36
+ if (entries.length === 0 && !relations && params.backend !== 'fortemi-core') {
37
+ console.error('Error: No artifact index found.');
38
+ console.error('Run `aiwg index build --graph framework` (or `aiwg use <framework>`) first.');
39
+ process.exit(1);
40
+ }
41
+ const needle = params.name.trim();
42
+ let matches = findShowMatches(entries, types, needle);
43
+ if (matches.length === 0) {
44
+ // Corpus fallback (#1221): when the artifact isn't in any indexed graph,
45
+ // scan the AIWG_ROOT corpus for a likely match and render it with an
46
+ // installation-aware banner. This keeps `aiwg show` useful in workspaces
47
+ // where the operator hasn't run `aiwg use` yet, or where the framework
48
+ // index is stale, rather than exiting with a misleading "not found".
49
+ if (resourceSource === 'local' && aiwgRoot && params.backend !== 'fortemi-core') {
50
+ const corpusMatch = await findCorpusArtifact(aiwgRoot, needle, types);
51
+ if (corpusMatch) {
52
+ let content;
53
+ try {
54
+ content = await fs.readFile(corpusMatch.path, 'utf8');
55
+ }
56
+ catch (err) {
57
+ const e = err;
58
+ console.error(`Error reading ${corpusMatch.path}: ${e.message ?? String(err)}`);
59
+ process.exit(1);
60
+ }
61
+ const localPin = corpusMatch.type === 'rule' ? (await import('../rules/pin-state.js')).rulePinState(cwd, aiwgRoot).rules.find(rule => rule.path === corpusMatch.path) : undefined;
62
+ const installed = await isCorpusBundleInstalled(cwd, aiwgRoot, corpusMatch.bundleKind, corpusMatch.bundleId);
63
+ const installHint = installed
64
+ ? 'The installed bundle is missing from this index. Run `aiwg index build --graph framework` to refresh it.'
65
+ : corpusMatch.bundleKind && corpusMatch.bundleId
66
+ ? `Run \`aiwg use ${corpusMatch.bundleId}\` to install this ${corpusMatch.bundleKind} into the workspace.`
67
+ : 'Run `aiwg index build --graph framework` to refresh the artifact index.';
68
+ const fallbackEntry = { path: path.relative(aiwgRoot, corpusMatch.path), type: corpusMatch.type, name: needle, title: needle };
69
+ const bindings = await showBindings(entries, fallbackEntry, content, params, rule => fs.readFile(resolveMetadataPath(cwd, aiwgRoot, rule), 'utf8'), relations);
70
+ await emitShowCard(cwd, aiwgRoot, fallbackEntry, corpusMatch.path, content, params, bindings, { uninstalled: !installed, installed, hint: installHint,
71
+ ...(localPin ? { local_pin: localPin } : {}) }, true);
72
+ return;
73
+ }
74
+ }
75
+ console.error(`Error: no artifact found matching "${needle}".`);
76
+ console.error('Try `aiwg discover "<phrase>"` to find the right name.');
77
+ process.exit(1);
78
+ }
79
+ // Resolve relative framework-graph paths to absolute paths.
80
+ // Kernel entries are anchored the same way as non-kernel framework entries
81
+ // (#1230) — show reads the source corpus, not platform deploy mirrors.
82
+ const resolvePath = (entry) => resourceSource === 'web'
83
+ ? `raw/${normalizeIndexedPath(entry.path)}`
84
+ : resolveMetadataPath(cwd, aiwgRoot, entry);
85
+ if (matches.length > 1 && !params.first) {
86
+ if (params.json) {
87
+ console.log(JSON.stringify({
88
+ ambiguous: true,
89
+ name: needle,
90
+ matches: matches.map(e => ({
91
+ id: discoveryIdForEntry(e),
92
+ path: resolvePath(e),
93
+ type: e.type,
94
+ name: e.name,
95
+ title: e.title,
96
+ kernel: e.kernel ?? false,
97
+ provenance: {
98
+ graph: e.indexGraph ?? null,
99
+ scope: e.indexScope ?? null,
100
+ ...(webRelease
101
+ ? {
102
+ resource_source: 'web',
103
+ aiwg_selector: webRelease.selector,
104
+ aiwg_version: webRelease.version,
105
+ manifest_sha256: webRelease.manifestDigest,
106
+ manifest_url: webRelease.manifestUrl,
107
+ }
108
+ : {}),
109
+ },
110
+ })),
111
+ }, null, 2));
112
+ }
113
+ else {
114
+ console.error(`Ambiguous: "${needle}" matches ${matches.length} artifacts. Disambiguate with --type or pass the stable id:`);
115
+ for (const e of matches) {
116
+ console.error(` ${e.type.padEnd(7)} ${discoveryIdForEntry(e)} ${e.title}`);
117
+ }
118
+ console.error('');
119
+ console.error('Re-run with `--first` to pick the top match, `--type skill` to filter, or `aiwg show metadata <id>` for paths.');
120
+ }
121
+ process.exit(2);
122
+ }
123
+ const entry = matches[0];
124
+ const filePath = resolvePath(entry);
125
+ let content;
126
+ if (resourceSource === 'web') {
127
+ try {
128
+ if (!webRelease)
129
+ throw new Error('verified web release context is unavailable');
130
+ const { logicalIdFromFirstPartyPath, resolveAiwgResourceBytes } = await import('../resources/resolver.js');
131
+ const logicalId = logicalIdFromFirstPartyPath(entry.path);
132
+ if (!logicalId)
133
+ throw new Error(`indexed path is not a first-party AIWG resource: ${entry.path}`);
134
+ const resolved = await resolveAiwgResourceBytes(logicalId, {
135
+ source: 'web',
136
+ frameworkRoot: aiwgRoot ?? cwd,
137
+ webRelease,
138
+ webReleaseOptions: params.webReleaseOptions,
139
+ offline: params.offline,
140
+ });
141
+ content = resolved.bytes.toString('utf8');
142
+ }
143
+ catch (error) {
144
+ console.error(`Error: AIWG web resource show failed: ${error instanceof Error ? error.message : String(error)}`);
145
+ process.exit(1);
146
+ }
147
+ }
148
+ else {
149
+ try {
150
+ content = await fs.readFile(filePath, 'utf8');
151
+ }
152
+ catch (err) {
153
+ const e = err;
154
+ console.error(`Error reading ${filePath}: ${e.message ?? String(err)}`);
155
+ process.exit(1);
156
+ }
157
+ }
158
+ const localPin = entry.type === 'rule' ? (await import('../rules/pin-state.js')).rulePinState(cwd, aiwgRoot ?? cwd).rules.find(rule => rule.path === filePath) : undefined;
159
+ const bindings = await showBindings(entries, entry, content, params, async (rule) => {
160
+ if (resourceSource === 'local')
161
+ return fs.readFile(resolvePath(rule), 'utf8');
162
+ const { logicalIdFromFirstPartyPath, resolveAiwgResourceBytes } = await import('../resources/resolver.js');
163
+ const logicalId = logicalIdFromFirstPartyPath(rule.path);
164
+ if (!logicalId || !webRelease)
165
+ throw new Error(`Cannot resolve bound rule: ${rule.path}`);
166
+ const resolved = await resolveAiwgResourceBytes(logicalId, {
167
+ source: 'web', frameworkRoot: aiwgRoot ?? cwd, webRelease,
168
+ webReleaseOptions: params.webReleaseOptions, offline: params.offline,
169
+ });
170
+ return resolved.bytes.toString('utf8');
171
+ }, relations);
172
+ const providerModels = resourceSource === 'local' ? await loadProviderModelMetadata(cwd, aiwgRoot) : null;
173
+ await emitShowCard(cwd, aiwgRoot, entry, filePath, content, params, bindings, {
174
+ provenance: {
175
+ graph: entry.indexGraph ?? null,
176
+ scope: entry.indexScope ?? null,
177
+ ...(webRelease ? { resource_source: 'web', aiwg_selector: webRelease.selector, aiwg_version: webRelease.version,
178
+ manifest_sha256: webRelease.manifestDigest, manifest_url: webRelease.manifestUrl } : {}),
179
+ },
180
+ ...(entry.script ? { executable: true, run_hint: buildRunHint(entry) } : {}),
181
+ ...(providerModels ? { providerModels } : {}),
182
+ ...(localPin ? { local_pin: localPin } : {}),
183
+ }, resourceSource === 'local', webRelease);
184
+ }
185
+ export async function showMetadata(cwd, params) {
186
+ loadGlobalGraphConfigs();
187
+ const types = params.typeFilter && params.typeFilter.length > 0
188
+ ? params.typeFilter
189
+ : [...OPERATIONAL_SHOW_TYPES];
190
+ const { entries, aiwgRoot, resourceSource, webRelease, sourcePaths, } = await loadShowEntries(cwd, params);
191
+ if (entries.length === 0 && params.backend !== 'fortemi-core') {
192
+ console.error('Error: No artifact index found.');
193
+ console.error('Run `aiwg index build --graph framework` (or `aiwg use <framework>`) first.');
194
+ process.exit(1);
195
+ }
196
+ const needle = params.name.trim();
197
+ const matches = findShowMatches(entries, types, needle);
198
+ if (matches.length === 0) {
199
+ console.error(`Error: no artifact metadata found matching "${needle}".`);
200
+ console.error('Try `aiwg discover "<phrase>" --json` to find the stable id.');
201
+ process.exit(1);
202
+ }
203
+ const resolvePath = (entry) => resourceSource === 'web'
204
+ ? `raw/${normalizeIndexedPath(entry.path)}`
205
+ : resolveMetadataPath(cwd, aiwgRoot, entry);
206
+ if (matches.length > 1 && !params.first) {
207
+ if (params.json) {
208
+ console.log(JSON.stringify({
209
+ ambiguous: true,
210
+ name: needle,
211
+ matches: matches.map((entry) => ({
212
+ id: discoveryIdForEntry(entry),
213
+ type: entry.type,
214
+ name: entry.name,
215
+ title: entry.title,
216
+ provenance: {
217
+ graph: entry.indexGraph ?? null,
218
+ scope: entry.indexScope ?? null,
219
+ ...(webRelease
220
+ ? {
221
+ resource_source: 'web',
222
+ aiwg_selector: webRelease.selector,
223
+ aiwg_version: webRelease.version,
224
+ manifest_sha256: webRelease.manifestDigest,
225
+ manifest_url: webRelease.manifestUrl,
226
+ }
227
+ : {}),
228
+ },
229
+ })),
230
+ }, null, 2));
231
+ }
232
+ else {
233
+ console.error(`Ambiguous: "${needle}" matches ${matches.length} artifacts. Disambiguate with the stable id:`);
234
+ for (const entry of matches) {
235
+ console.error(` ${entry.type.padEnd(7)} ${discoveryIdForEntry(entry)} ${entry.title}`);
236
+ }
237
+ }
238
+ process.exit(2);
239
+ }
240
+ const entry = matches[0];
241
+ const absolutePath = resolvePath(entry);
242
+ const backend = params.backend ?? DEFAULT_ARTIFACT_SEARCH_BACKEND;
243
+ const record = backend === 'fortemi-core'
244
+ ? await fortemiRecordForEntry(cwd, entry, sourcePaths)
245
+ : null;
246
+ const payload = {
247
+ id: discoveryIdForEntry(entry),
248
+ backend,
249
+ type: entry.type,
250
+ name: entry.name,
251
+ title: entry.title,
252
+ paths: {
253
+ absolute: absolutePath,
254
+ indexed: entry.path,
255
+ repo_relative: record?.source.repo_relative_path ?? entry.path,
256
+ locator: record?.source.locator ?? entry.name ?? entry.title,
257
+ },
258
+ provenance: {
259
+ graph: entry.indexGraph ?? null,
260
+ scope: entry.indexScope ?? null,
261
+ ...(webRelease
262
+ ? {
263
+ resource_source: 'web',
264
+ aiwg_selector: webRelease.selector,
265
+ aiwg_version: webRelease.version,
266
+ manifest_sha256: webRelease.manifestDigest,
267
+ manifest_url: webRelease.manifestUrl,
268
+ }
269
+ : {}),
270
+ },
271
+ metadata: record ?? entry,
272
+ providerModels: resourceSource === 'local'
273
+ ? await loadProviderModelMetadata(cwd, aiwgRoot)
274
+ : null,
275
+ };
276
+ if (params.json) {
277
+ console.log(JSON.stringify(payload, null, 2));
278
+ return;
279
+ }
280
+ console.log(`${payload.type} ${payload.title}`);
281
+ console.log(` id: ${payload.id}`);
282
+ if (payload.name)
283
+ console.log(` name: ${payload.name}`);
284
+ console.log(` graph: ${payload.provenance.graph ?? 'unknown'}`);
285
+ console.log(` scope: ${payload.provenance.scope ?? 'unknown'}`);
286
+ console.log(` path: ${payload.paths.absolute}`);
287
+ console.log(` indexed_path: ${payload.paths.indexed}`);
288
+ if (payload.providerModels) {
289
+ console.log(' provider_models:');
290
+ for (const [provider, hints] of Object.entries(payload.providerModels.providers)) {
291
+ console.log(` ${provider}:`);
292
+ for (const hint of hints) {
293
+ console.log(` ${hint.role}: ${hint.model} (wrapper: ${hint.wrapper}, status: ${hint.status})`);
294
+ }
295
+ }
296
+ }
297
+ console.log('');
298
+ console.log(JSON.stringify(payload.metadata, null, 2));
299
+ }
300
+ //# sourceMappingURL=query-engine-show.js.map