@canonical/pragma-cli 0.27.1-experimental.0 → 0.30.0

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 (344) hide show
  1. package/README.md +67 -15
  2. package/dist/pragma +0 -0
  3. package/package.json +16 -17
  4. package/src/config/defaultConfig.test.ts +33 -0
  5. package/src/config/defaultConfig.ts +59 -0
  6. package/src/config/defaults.json +17 -0
  7. package/src/config/findProjectConfigPath.test.ts +53 -0
  8. package/src/config/findProjectConfigPath.ts +36 -0
  9. package/src/config/index.ts +17 -2
  10. package/src/config/mergeConfigFileUpdate.ts +58 -0
  11. package/src/config/parseConfigValues.ts +215 -0
  12. package/src/config/readConfig.test.ts +104 -13
  13. package/src/config/readConfig.ts +12 -117
  14. package/src/config/readConfigLayers.test.ts +107 -0
  15. package/src/config/readConfigLayers.ts +115 -0
  16. package/src/config/resolveGlobalConfigPath.ts +13 -0
  17. package/src/config/resolveWriteConfigPath.test.ts +53 -0
  18. package/src/config/resolveWriteConfigPath.ts +31 -0
  19. package/src/config/types.ts +88 -2
  20. package/src/config/writeConfig.ts +25 -43
  21. package/src/constants.ts +12 -1
  22. package/src/domains/block/commands/index.ts +2 -1
  23. package/src/domains/block/commands/list.ts +5 -90
  24. package/src/domains/block/commands/lookup.ts +8 -167
  25. package/src/domains/block/commands/sample.ts +55 -0
  26. package/src/domains/block/formatters/index.ts +2 -1
  27. package/src/domains/block/formatters/sample.ts +21 -0
  28. package/src/domains/block/index.ts +3 -3
  29. package/src/domains/block/mcp/specs.ts +36 -168
  30. package/src/domains/block/operations/index.ts +2 -1
  31. package/src/domains/block/operations/lookup.ts +9 -0
  32. package/src/domains/block/operations/sample.ts +41 -0
  33. package/src/domains/block/orchestration/blockEmptyError.test.ts +26 -0
  34. package/src/domains/block/orchestration/resolveBlockLookup.ts +11 -3
  35. package/src/domains/block/stories.test.ts +28 -0
  36. package/src/domains/block/stories.ts +254 -0
  37. package/src/domains/config/commands/channel.test.ts +14 -3
  38. package/src/domains/config/commands/channel.ts +11 -7
  39. package/src/domains/config/commands/configScope.ts +46 -0
  40. package/src/domains/config/commands/framework.test.ts +105 -0
  41. package/src/domains/config/commands/framework.ts +91 -0
  42. package/src/domains/config/commands/index.ts +2 -0
  43. package/src/domains/config/commands/show.ts +5 -45
  44. package/src/domains/config/commands/tier.test.ts +13 -2
  45. package/src/domains/config/commands/tier.ts +11 -7
  46. package/src/domains/config/commands/trace.test.ts +165 -0
  47. package/src/domains/config/commands/trace.ts +83 -0
  48. package/src/domains/config/formatters/channel.test.ts +20 -6
  49. package/src/domains/config/formatters/channel.ts +14 -11
  50. package/src/domains/config/formatters/framework.ts +37 -0
  51. package/src/domains/config/formatters/index.ts +2 -0
  52. package/src/domains/config/formatters/show.test.ts +27 -0
  53. package/src/domains/config/formatters/show.ts +27 -4
  54. package/src/domains/config/formatters/tier.test.ts +26 -10
  55. package/src/domains/config/formatters/tier.ts +19 -11
  56. package/src/domains/config/formatters/trace.ts +28 -0
  57. package/src/domains/config/index.ts +15 -2
  58. package/src/domains/config/mcp/specs.ts +33 -53
  59. package/src/domains/config/operations/index.ts +1 -0
  60. package/src/domains/config/operations/show.test.ts +18 -0
  61. package/src/domains/config/operations/show.ts +7 -1
  62. package/src/domains/config/operations/types.ts +7 -0
  63. package/src/domains/config/operations/validateFramework.ts +24 -0
  64. package/src/domains/config/stories.ts +42 -0
  65. package/src/domains/config/tasks/index.ts +3 -0
  66. package/src/domains/config/tasks/setChannel.ts +13 -22
  67. package/src/domains/config/tasks/setFramework.ts +21 -0
  68. package/src/domains/config/tasks/setTier.ts +10 -23
  69. package/src/domains/config/tasks/setTrace.ts +20 -0
  70. package/src/domains/config/tasks/writeConfigField.ts +41 -0
  71. package/src/domains/create/commands/component.ts +5 -5
  72. package/src/domains/doctor/operations/checks/checkConfigFile.ts +19 -5
  73. package/src/domains/doctor/operations/checks/checkKeStore.ts +5 -5
  74. package/src/domains/doctor/operations/checks/checkMcpCommands.ts +130 -0
  75. package/src/domains/doctor/operations/checks/checkMcpConfigured.ts +1 -1
  76. package/src/domains/doctor/operations/checks/checkPackageRefs.ts +30 -48
  77. package/src/domains/doctor/operations/checks/checkSkillsSymlinked.ts +1 -1
  78. package/src/domains/doctor/operations/checks/index.ts +1 -0
  79. package/src/domains/doctor/operations/checks.test.ts +162 -8
  80. package/src/domains/doctor/operations/runChecks.test.ts +85 -4
  81. package/src/domains/doctor/operations/runChecks.ts +50 -12
  82. package/src/domains/graph/helpers/resolveUri.test.ts +50 -0
  83. package/src/domains/graph/helpers/resolveUri.ts +28 -21
  84. package/src/domains/graphql/commands/build.test.ts +196 -0
  85. package/src/domains/graphql/commands/build.ts +117 -0
  86. package/src/domains/graphql/commands/check.test.ts +141 -0
  87. package/src/domains/graphql/commands/check.ts +81 -0
  88. package/src/domains/graphql/commands/index.ts +5 -0
  89. package/src/domains/graphql/commands/serve.test.ts +40 -0
  90. package/src/domains/graphql/commands/serve.ts +131 -0
  91. package/src/domains/graphql/constants.ts +10 -0
  92. package/src/domains/graphql/formatters/index.ts +3 -0
  93. package/src/domains/graphql/formatters/report.ts +78 -0
  94. package/src/domains/graphql/helpers/gatherSources.test.ts +92 -0
  95. package/src/domains/graphql/helpers/gatherSources.ts +58 -0
  96. package/src/domains/graphql/helpers/index.ts +6 -0
  97. package/src/domains/graphql/helpers/parsePrefixes.test.ts +44 -0
  98. package/src/domains/graphql/helpers/parsePrefixes.ts +38 -0
  99. package/src/domains/graphql/helpers/resolveSourceFiles.test.ts +56 -0
  100. package/src/domains/graphql/helpers/resolveSourceFiles.ts +45 -0
  101. package/src/domains/graphql/helpers/routeGraphql.test.ts +43 -0
  102. package/src/domains/graphql/helpers/routeGraphql.ts +28 -0
  103. package/src/domains/graphql/index.ts +24 -0
  104. package/src/domains/graphql/operations/compileSchema.test.ts +95 -0
  105. package/src/domains/graphql/operations/compileSchema.ts +107 -0
  106. package/src/domains/graphql/operations/createSchemaServer.test.ts +50 -0
  107. package/src/domains/graphql/operations/createSchemaServer.ts +75 -0
  108. package/src/domains/graphql/operations/index.ts +12 -0
  109. package/src/domains/graphql/types.ts +29 -0
  110. package/src/domains/info/operations/collectInfo.test.ts +16 -5
  111. package/src/domains/info/operations/collectInfo.ts +16 -19
  112. package/src/domains/llm/capabilities.test.ts +91 -0
  113. package/src/domains/llm/commands/capabilities.ts +28 -0
  114. package/src/domains/llm/commands/index.ts +1 -0
  115. package/src/domains/llm/data/commandReference.ts +90 -18
  116. package/src/domains/llm/data/decisionTrees.ts +15 -13
  117. package/src/domains/llm/data/index.ts +2 -0
  118. package/src/domains/llm/data/toolCatalog.ts +190 -0
  119. package/src/domains/llm/formatters/capabilities.ts +50 -0
  120. package/src/domains/llm/formatters/index.ts +1 -0
  121. package/src/domains/llm/index.ts +3 -2
  122. package/src/domains/llm/mcp/index.ts +1 -1
  123. package/src/domains/llm/mcp/specs.ts +59 -52
  124. package/src/domains/llm/types.ts +40 -0
  125. package/src/domains/modifier/commands/index.ts +2 -1
  126. package/src/domains/modifier/commands/list.ts +5 -38
  127. package/src/domains/modifier/commands/lookup.ts +8 -79
  128. package/src/domains/modifier/commands/sample.ts +53 -0
  129. package/src/domains/modifier/formatters/index.ts +2 -1
  130. package/src/domains/modifier/formatters/sample.ts +15 -0
  131. package/src/domains/modifier/index.ts +7 -3
  132. package/src/domains/modifier/mcp/specs.ts +38 -70
  133. package/src/domains/modifier/operations/index.ts +2 -1
  134. package/src/domains/modifier/operations/lookup.ts +9 -0
  135. package/src/domains/modifier/operations/sample.ts +32 -0
  136. package/src/domains/modifier/orchestration/modifierEmptyError.test.ts +26 -0
  137. package/src/domains/modifier/orchestration/modifierEmptyError.ts +7 -2
  138. package/src/domains/modifier/orchestration/resolveModifierLookup.ts +15 -2
  139. package/src/domains/modifier/stories.test.ts +20 -0
  140. package/src/domains/modifier/stories.ts +77 -0
  141. package/src/domains/ontology/commands/list.ts +5 -58
  142. package/src/domains/ontology/commands/show.ts +6 -58
  143. package/src/domains/ontology/formatters/show.ts +7 -1
  144. package/src/domains/ontology/mcp/specs.ts +7 -84
  145. package/src/domains/ontology/stories.test.ts +36 -0
  146. package/src/domains/ontology/stories.ts +108 -0
  147. package/src/domains/refs/operations/index.ts +1 -1
  148. package/src/domains/refs/operations/paths.ts +29 -1
  149. package/src/domains/refs/operations/updateRefs.test.ts +6 -3
  150. package/src/domains/refs/operations/updateRefs.ts +2 -36
  151. package/src/domains/setup/commands/skills.test.ts +6 -2
  152. package/src/domains/setup/commands/skills.ts +6 -2
  153. package/src/domains/setup/helpers/runSetupTask.test.ts +148 -150
  154. package/src/domains/setup/helpers/runSetupTask.ts +62 -70
  155. package/src/domains/setup/operations/setupMcp.test.ts +6 -1
  156. package/src/domains/shared/bootStore.ts +92 -50
  157. package/src/domains/shared/compactUri.test.ts +11 -0
  158. package/src/domains/shared/compactUri.ts +10 -5
  159. package/src/domains/shared/context.ts +2 -2
  160. package/src/domains/shared/contracts.ts +12 -0
  161. package/src/domains/shared/createInteractivePromptSession.test.ts +439 -0
  162. package/src/domains/shared/createInteractivePromptSession.ts +236 -0
  163. package/src/domains/shared/emptyErrorRecovery.test.ts +109 -0
  164. package/src/domains/shared/loaders/bundledLoader.test.ts +248 -0
  165. package/src/domains/shared/loaders/bundledLoader.ts +206 -0
  166. package/src/domains/shared/loaders/gitLoader.ts +31 -0
  167. package/src/domains/shared/loaders/index.ts +9 -0
  168. package/src/domains/shared/loaders/localLoader.ts +87 -0
  169. package/src/domains/shared/loaders/readPackageDir.ts +147 -0
  170. package/src/domains/shared/loaders/storyAssetsPlugin.test.ts +84 -0
  171. package/src/domains/shared/loaders/storyAssetsPlugin.ts +46 -0
  172. package/src/domains/shared/lookupMany.test.ts +120 -0
  173. package/src/domains/shared/lookupMany.ts +43 -3
  174. package/src/domains/shared/mergeAndParseRefs.test.ts +89 -0
  175. package/src/domains/shared/mergeAndParseRefs.ts +44 -0
  176. package/src/domains/shared/packages.ts +14 -120
  177. package/src/domains/shared/pickRandom.ts +22 -0
  178. package/src/domains/shared/resolveConfiguredGraphs.test.ts +27 -0
  179. package/src/domains/shared/resolveConfiguredGraphs.ts +41 -0
  180. package/src/domains/shared/runtime.ts +7 -63
  181. package/src/domains/shared/sampleFormatters.ts +47 -0
  182. package/src/domains/shared/semanticPackage.ts +112 -0
  183. package/src/domains/shared/stories/compileLookupCommand.test.ts +145 -0
  184. package/src/domains/shared/stories/compileLookupCommand.ts +100 -0
  185. package/src/domains/shared/stories/compileLookupTool.test.ts +105 -0
  186. package/src/domains/shared/stories/compileLookupTool.ts +96 -0
  187. package/src/domains/shared/stories/compileReadCommand.test.ts +121 -0
  188. package/src/domains/shared/stories/compileReadCommand.ts +48 -0
  189. package/src/domains/shared/stories/compileReadTool.test.ts +64 -0
  190. package/src/domains/shared/stories/compileReadTool.ts +38 -0
  191. package/src/domains/shared/stories/condense.test.ts +18 -0
  192. package/src/domains/shared/stories/condense.ts +15 -0
  193. package/src/domains/shared/stories/index.ts +20 -0
  194. package/src/domains/shared/stories/normalizeNames.test.ts +20 -0
  195. package/src/domains/shared/stories/normalizeNames.ts +22 -0
  196. package/src/domains/shared/stories/pack/applyPackFilters.test.ts +102 -0
  197. package/src/domains/shared/stories/pack/applyPackFilters.ts +76 -0
  198. package/src/domains/shared/stories/pack/buildLookupQuery.test.ts +51 -0
  199. package/src/domains/shared/stories/pack/buildLookupQuery.ts +80 -0
  200. package/src/domains/shared/stories/pack/collectPackStories.test.ts +108 -0
  201. package/src/domains/shared/stories/pack/collectPackStories.ts +76 -0
  202. package/src/domains/shared/stories/pack/compilePackCommands.ts +40 -0
  203. package/src/domains/shared/stories/pack/compilePackStories.test.ts +146 -0
  204. package/src/domains/shared/stories/pack/compilePackStories.ts +253 -0
  205. package/src/domains/shared/stories/pack/compilePackToolSpecs.ts +43 -0
  206. package/src/domains/shared/stories/pack/index.ts +28 -0
  207. package/src/domains/shared/stories/pack/runSelectQuery.ts +31 -0
  208. package/src/domains/shared/stories/pack/standardParity.test.ts +308 -0
  209. package/src/domains/shared/stories/pack/types.ts +104 -0
  210. package/src/domains/shared/stories/pack/validateStoryPackDefinition.test.ts +240 -0
  211. package/src/domains/shared/stories/pack/validateStoryPackDefinition.ts +408 -0
  212. package/src/domains/shared/stories/projectCliParameters.test.ts +59 -0
  213. package/src/domains/shared/stories/projectCliParameters.ts +57 -0
  214. package/src/domains/shared/stories/projectToolParams.test.ts +50 -0
  215. package/src/domains/shared/stories/projectToolParams.ts +32 -0
  216. package/src/domains/shared/stories/requirePragmaContext.test.ts +23 -0
  217. package/src/domains/shared/stories/requirePragmaContext.ts +23 -0
  218. package/src/domains/shared/stories/resolveLookupDetailed.test.ts +57 -0
  219. package/src/domains/shared/stories/resolveLookupDetailed.ts +27 -0
  220. package/src/domains/shared/stories/types.ts +171 -0
  221. package/src/domains/shared/suggestions/detectCrossDomain.test.ts +43 -0
  222. package/src/domains/shared/suggestions/detectCrossDomain.ts +116 -0
  223. package/src/domains/shared/suggestions/expandGlob.test.ts +92 -0
  224. package/src/domains/shared/suggestions/expandGlob.ts +52 -0
  225. package/src/domains/shared/suggestions/expandLookupQueries.ts +57 -0
  226. package/src/domains/shared/suggestions/index.ts +7 -0
  227. package/src/domains/shared/suggestions/listDomainNames.ts +61 -0
  228. package/src/domains/shared/suggestions/suggestNames.test.ts +70 -0
  229. package/src/domains/shared/suggestions/suggestNames.ts +130 -0
  230. package/src/domains/shared/types/index.ts +1 -0
  231. package/src/domains/shared/types/runtime.ts +4 -1
  232. package/src/domains/shared/types/sample.ts +17 -0
  233. package/src/domains/skill/commands/index.ts +3 -1
  234. package/src/domains/skill/commands/list.test.ts +6 -2
  235. package/src/domains/skill/commands/list.ts +5 -63
  236. package/src/domains/skill/commands/lookup.test.ts +118 -0
  237. package/src/domains/skill/commands/lookup.ts +14 -0
  238. package/src/domains/skill/formatters/index.ts +1 -0
  239. package/src/domains/skill/formatters/lookup.test.ts +46 -0
  240. package/src/domains/skill/formatters/lookup.ts +57 -0
  241. package/src/domains/skill/helpers/resolveSkillSources.ts +48 -16
  242. package/src/domains/skill/index.ts +7 -3
  243. package/src/domains/skill/mcp/specs.ts +10 -29
  244. package/src/domains/skill/operations/discover.test.ts +61 -30
  245. package/src/domains/skill/operations/discover.ts +28 -37
  246. package/src/domains/skill/operations/index.ts +2 -1
  247. package/src/domains/skill/operations/list.test.ts +15 -7
  248. package/src/domains/skill/operations/lookup.test.ts +91 -0
  249. package/src/domains/skill/operations/lookup.ts +70 -0
  250. package/src/domains/skill/stories.test.ts +43 -0
  251. package/src/domains/skill/stories.ts +103 -0
  252. package/src/domains/skill/types.ts +8 -0
  253. package/src/domains/standard/commands/index.ts +2 -1
  254. package/src/domains/standard/commands/list.ts +5 -84
  255. package/src/domains/standard/commands/lookup.ts +8 -93
  256. package/src/domains/standard/commands/sample.ts +57 -0
  257. package/src/domains/standard/formatters/index.ts +2 -1
  258. package/src/domains/standard/formatters/sample.ts +15 -0
  259. package/src/domains/standard/index.ts +8 -1
  260. package/src/domains/standard/mcp/specs.ts +44 -152
  261. package/src/domains/standard/operations/index.ts +2 -1
  262. package/src/domains/standard/operations/lookup.ts +9 -0
  263. package/src/domains/standard/operations/sample.ts +35 -0
  264. package/src/domains/standard/orchestration/resolveStandardLookup.ts +15 -2
  265. package/src/domains/standard/orchestration/standardEmptyError.test.ts +33 -0
  266. package/src/domains/standard/orchestration/standardEmptyError.ts +16 -6
  267. package/src/domains/standard/stories.test.ts +24 -0
  268. package/src/domains/standard/stories.ts +151 -0
  269. package/src/domains/tier/commands/list.ts +5 -55
  270. package/src/domains/tier/mcp/specs.ts +5 -31
  271. package/src/domains/tier/stories.test.ts +22 -0
  272. package/src/domains/tier/stories.ts +52 -0
  273. package/src/domains/token/commands/index.ts +2 -1
  274. package/src/domains/token/commands/sample.ts +53 -0
  275. package/src/domains/token/formatters/index.ts +2 -1
  276. package/src/domains/token/formatters/sample.ts +16 -0
  277. package/src/domains/token/index.ts +8 -1
  278. package/src/domains/token/mcp/specs.ts +52 -2
  279. package/src/domains/token/operations/index.ts +2 -1
  280. package/src/domains/token/operations/lookup.ts +9 -0
  281. package/src/domains/token/operations/sample.ts +32 -0
  282. package/src/domains/token/orchestration/resolveTokenLookup.ts +15 -2
  283. package/src/domains/token/orchestration/tokenEmptyError.test.ts +33 -0
  284. package/src/domains/token/orchestration/tokenEmptyError.ts +5 -2
  285. package/src/domains/trace/commands/clear.ts +71 -0
  286. package/src/domains/trace/commands/index.ts +5 -0
  287. package/src/domains/trace/commands/sessions.ts +32 -0
  288. package/src/domains/trace/commands/show.ts +145 -0
  289. package/src/domains/trace/formatters/index.ts +9 -0
  290. package/src/domains/trace/formatters/sessions.ts +80 -0
  291. package/src/domains/trace/formatters/show.ts +122 -0
  292. package/src/domains/trace/index.ts +17 -0
  293. package/src/domains/trace/operations/index.ts +8 -0
  294. package/src/domains/trace/operations/listSessions.test.ts +55 -0
  295. package/src/domains/trace/operations/listSessions.ts +52 -0
  296. package/src/domains/trace/operations/readTraceLog.test.ts +100 -0
  297. package/src/domains/trace/operations/readTraceLog.ts +104 -0
  298. package/src/domains/trace/tracePlugin.test.ts +171 -0
  299. package/src/domains/trace/tracePlugin.ts +159 -0
  300. package/src/domains/trace/types.ts +65 -0
  301. package/src/error/PragmaError.ts +15 -2
  302. package/src/error/types.ts +15 -1
  303. package/src/mcp/error/serializeErrorPayload.ts +7 -0
  304. package/src/mcp/error/types.ts +8 -0
  305. package/src/mcp/registerResources.test.ts +405 -75
  306. package/src/mcp/registerResources.ts +5 -299
  307. package/src/mcp/resources/buildGraphIndex.ts +167 -0
  308. package/src/mcp/resources/buildResourceList.test.ts +97 -0
  309. package/src/mcp/resources/buildResourceList.ts +176 -0
  310. package/src/mcp/resources/classifyEntity.test.ts +40 -0
  311. package/src/mcp/resources/classifyEntity.ts +27 -0
  312. package/src/mcp/resources/constants.ts +105 -0
  313. package/src/mcp/resources/displayPredicates.ts +62 -0
  314. package/src/mcp/resources/pickFirstValue.test.ts +29 -0
  315. package/src/mcp/resources/pickFirstValue.ts +26 -0
  316. package/src/mcp/resources/pickPrimaryType.test.ts +41 -0
  317. package/src/mcp/resources/pickPrimaryType.ts +26 -0
  318. package/src/mcp/resources/rankUriCompletions.test.ts +52 -0
  319. package/src/mcp/resources/rankUriCompletions.ts +64 -0
  320. package/src/mcp/resources/readEntity.ts +169 -0
  321. package/src/mcp/resources/registerResources.ts +126 -0
  322. package/src/mcp/resources/types.ts +128 -0
  323. package/src/mcp/tools/index.ts +9 -0
  324. package/src/mcp/tools/registerTools.test.ts +84 -12
  325. package/src/mcp/types.ts +4 -0
  326. package/src/mcp/utils/wrapTool.test.ts +1 -0
  327. package/src/pipeline/collectCommands.ts +15 -2
  328. package/src/pipeline/renderError.ts +15 -0
  329. package/src/pipeline/resolveCommandKind.ts +8 -1
  330. package/src/pipeline/runCli.ts +51 -6
  331. package/src/testing/createTestMcpClient.ts +5 -1
  332. package/src/testing/graphqlFixtures.ts +72 -0
  333. package/src/testing/index.ts +17 -0
  334. package/src/testing/integration/__snapshots__/executor-golden.test.ts.snap +1207 -0
  335. package/src/testing/integration/cross-binary-byte-equality.test.ts +129 -0
  336. package/src/testing/integration/executor-execution.test.ts +101 -0
  337. package/src/testing/integration/executor-golden.test.ts +145 -0
  338. package/src/testing/integration/mcp-surface.test.ts +11 -5
  339. package/src/testing/integration/parity.test.ts +17 -12
  340. package/src/testing/regression/0001-skill-discovery-granularity.test.ts +71 -0
  341. package/src/testing/setupXdgIsolation.ts +15 -0
  342. package/src/testing/standardParityFixtures.ts +92 -0
  343. package/src/testing/storyFixtures.ts +63 -0
  344. package/src/pipeline/runInteractiveCommand.ts +0 -198
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * @module LLM domain barrel.
3
3
  *
4
- * Provides the `pragma llm` command for LLM orientation context generation.
4
+ * Provides the `pragma capabilities` and `pragma llm` commands
5
+ * for LLM orientation context generation.
5
6
  */
6
7
 
7
- export { buildLlmCommand } from "./commands/index.js";
8
+ export { buildCapabilitiesCommand, buildLlmCommand } from "./commands/index.js";
8
9
  export { specs as mcpSpecs } from "./mcp/index.js";
@@ -1,2 +1,2 @@
1
1
  /** @module LLM domain MCP barrel — capabilities, llm. */
2
- export { default as specs } from "./specs.js";
2
+ export { buildCapabilitiesData, default as specs } from "./specs.js";
@@ -2,74 +2,80 @@
2
2
  * MCP tool specs for llm domain — capabilities, llm.
3
3
  */
4
4
 
5
+ import { VERSION } from "#constants";
5
6
  import { buildFilterConfig } from "../../shared/filters/index.js";
6
7
  import type { ToolSpec } from "../../shared/ToolSpec.js";
7
- import { COMMAND_REFERENCE, DECISION_TREES } from "../data/index.js";
8
+ import {
9
+ COMMAND_REFERENCE,
10
+ DECISION_TREES,
11
+ TOOL_CATALOG,
12
+ } from "../data/index.js";
8
13
  import { collectContext } from "../operations/index.js";
9
- import type { LlmData } from "../types.js";
14
+ import type { CapabilitiesData, LlmData } from "../types.js";
10
15
 
11
- /** All registered tool names, categorized for the capabilities response. */
12
- const toolNames = {
13
- read: [
14
- "block_list",
15
- "block_lookup",
16
- "standard_list",
17
- "standard_lookup",
18
- "standard_categories",
19
- "modifier_list",
20
- "modifier_lookup",
21
- "token_list",
22
- "token_lookup",
23
- "tier_list",
24
- "config_show",
25
- "ontology_list",
26
- "ontology_show",
27
- "graph_query",
28
- "graph_inspect",
29
- "skill_list",
30
- ],
31
- write: [
32
- "config_tier",
33
- "config_channel",
34
- "tokens_add_config",
35
- "create_component",
36
- "create_package",
37
- ],
38
- orientation: ["llm", "capabilities"],
39
- diagnostic: ["doctor", "info"],
40
- };
41
- const allToolNames = [
42
- ...toolNames.read,
43
- ...toolNames.write,
44
- ...toolNames.orientation,
45
- ...toolNames.diagnostic,
46
- ];
16
+ /** Build the static capabilities response. */
17
+ function buildCapabilitiesData(): CapabilitiesData {
18
+ const counts = {
19
+ total: TOOL_CATALOG.length,
20
+ read: TOOL_CATALOG.filter((t) => t.category === "read").length,
21
+ write: TOOL_CATALOG.filter((t) => t.category === "write").length,
22
+ orientation: TOOL_CATALOG.filter((t) => t.category === "orientation")
23
+ .length,
24
+ diagnostic: TOOL_CATALOG.filter((t) => t.category === "diagnostic").length,
25
+ };
26
+
27
+ return {
28
+ version: VERSION,
29
+ conventions: {
30
+ system:
31
+ "Pragma is a CLI and MCP server for querying a design system knowledge graph — blocks, tokens, modifiers, standards, and ontologies.",
32
+ model:
33
+ "Data is scoped by tier (hierarchical, e.g. global > apps > apps/lxd) and channel (normal, experimental, prerelease). Set these via config_tier and config_channel.",
34
+ querying:
35
+ "All queries run against an RDF triple store. Prefixed IRIs (e.g. ds:global.component.button) identify entities. Use ontology_list to discover namespaces.",
36
+ },
37
+ discovery_sequence: [
38
+ {
39
+ stage: 1,
40
+ tool: "capabilities",
41
+ purpose: "Understand conventions, available tools, and how to navigate",
42
+ },
43
+ {
44
+ stage: 2,
45
+ tool: "*_sample",
46
+ purpose:
47
+ "Call block_sample, standard_sample, token_sample, or modifier_sample to see real data shapes before querying. Prevents guessing at property names.",
48
+ },
49
+ {
50
+ stage: 3,
51
+ tool: "domain tools",
52
+ purpose:
53
+ "Query specific entities — block_list, standard_lookup, token_list, etc. Use the use_when hints above to pick the right tool.",
54
+ },
55
+ ],
56
+ tools: TOOL_CATALOG,
57
+ counts,
58
+ limits: {
59
+ output_modes: ["text", "json", "llm"],
60
+ condensed_available: true,
61
+ },
62
+ };
63
+ }
47
64
 
48
65
  const specs: readonly ToolSpec[] = [
49
66
  {
50
67
  name: "capabilities",
51
68
  description:
52
- "List all available pragma MCP tools with counts by category. Call this first to discover what pragma can do. (~100 tokens)",
69
+ "Discover pragma conventions, available tools with behavioral hints, and discovery sequence. Call this first at session start.",
53
70
  readOnly: true,
54
71
  async execute() {
55
- return {
56
- data: {
57
- tools: allToolNames,
58
- counts: {
59
- total: allToolNames.length,
60
- read: toolNames.read.length,
61
- write: toolNames.write.length,
62
- orientation: toolNames.orientation.length,
63
- diagnostic: toolNames.diagnostic.length,
64
- },
65
- },
66
- };
72
+ return { data: buildCapabilitiesData() };
67
73
  },
68
74
  },
69
75
  {
70
76
  name: "llm",
71
77
  description:
72
- "Get LLM orientation for the pragma design system CLI. Returns context, decision trees for common intents, and command reference with token costs. Call this first when starting a design system task.",
78
+ "Get live LLM orientation — context snapshot (tier, channel, entity counts), decision trees for common intents, and command reference with token costs. Call after capabilities when starting design system work.",
73
79
  readOnly: true,
74
80
  async execute(rt) {
75
81
  const filters = buildFilterConfig(rt);
@@ -84,4 +90,5 @@ const specs: readonly ToolSpec[] = [
84
90
  },
85
91
  ];
86
92
 
93
+ export { buildCapabilitiesData };
87
94
  export default specs;
@@ -1,3 +1,42 @@
1
+ import type { ToolEntry } from "./data/toolCatalog.js";
2
+
3
+ // — Capabilities ——————————————————————————————————————————————————————————————
4
+
5
+ /** Structured system map returned by `pragma capabilities`. */
6
+ export interface CapabilitiesData {
7
+ readonly version: string;
8
+ readonly conventions: {
9
+ readonly system: string;
10
+ readonly model: string;
11
+ readonly querying: string;
12
+ };
13
+ readonly discovery_sequence: readonly DiscoveryStage[];
14
+ readonly tools: readonly ToolEntry[];
15
+ readonly counts: ToolCounts;
16
+ readonly limits: {
17
+ readonly output_modes: readonly string[];
18
+ readonly condensed_available: boolean;
19
+ };
20
+ }
21
+
22
+ /** A single stage in the discovery flow. */
23
+ export interface DiscoveryStage {
24
+ readonly stage: number;
25
+ readonly tool: string;
26
+ readonly purpose: string;
27
+ }
28
+
29
+ /** Tool counts by category. */
30
+ export interface ToolCounts {
31
+ readonly total: number;
32
+ readonly read: number;
33
+ readonly write: number;
34
+ readonly orientation: number;
35
+ readonly diagnostic: number;
36
+ }
37
+
38
+ // — LLM orientation ———————————————————————————————————————————————————————————
39
+
1
40
  /** Dynamic context snapshot: tier, channel, entity counts, and namespaces. */
2
41
  export interface LlmContext {
3
42
  readonly tier: string | undefined;
@@ -22,6 +61,7 @@ export interface DecisionTree {
22
61
  export interface CommandRefEntry {
23
62
  readonly command: string;
24
63
  readonly tokens: string;
64
+ readonly use_when: string;
25
65
  }
26
66
 
27
67
  /** Complete payload rendered by `pragma llm`: context, trees, and reference. */
@@ -1,4 +1,5 @@
1
- /** @module Re-exports modifier command builders (`lookup`, `list`). */
1
+ /** @module Re-exports modifier command builders (`list`, `lookup`, `sample`). */
2
2
 
3
3
  export { default as listCommand } from "./list.js";
4
4
  export { default as lookupCommand } from "./lookup.js";
5
+ export { default as sampleCommand } from "./sample.js";
@@ -1,42 +1,9 @@
1
- /**
2
- * Wires the `pragma modifier list` CLI command.
3
- *
4
- * Lists all modifier families with their allowed values. Throws a
5
- * structured recovery error when no families are found.
6
- */
7
-
8
- import {
9
- type CommandDefinition,
10
- createOutputResult,
11
- } from "@canonical/cli-core";
12
- import { createListView } from "#tui";
1
+ import type { CommandDefinition } from "@canonical/cli-core";
13
2
  import type { PragmaContext } from "../../shared/context.js";
14
- import { selectFormatter } from "../../shared/formatters.js";
15
- import { listFormatters } from "../formatters/index.js";
16
- import { modifierConfig } from "../modifierConfig.js";
17
- import { resolveModifierList } from "../orchestration/index.js";
3
+ import { compileReadCommand } from "../../shared/stories/index.js";
4
+ import { modifierListStory } from "../stories.js";
18
5
 
6
+ /** Wire the `pragma modifier list` CLI command from the modifier list story. */
19
7
  export default function listCommand(ctx: PragmaContext): CommandDefinition {
20
- return {
21
- path: ["modifier", "list"],
22
- description: "List all modifier families",
23
- parameters: [],
24
- meta: {
25
- examples: ["pragma modifier list", "pragma modifier list --llm"],
26
- },
27
- async execute() {
28
- const resolution = await resolveModifierList(ctx);
29
-
30
- return createOutputResult([...resolution.items], {
31
- plain: selectFormatter(ctx, listFormatters),
32
- ink: (data) =>
33
- createListView({
34
- heading: "Modifiers",
35
- domain: "modifier",
36
- items: data,
37
- columns: modifierConfig.listColumns,
38
- }),
39
- });
40
- },
41
- };
8
+ return compileReadCommand(ctx, modifierListStory);
42
9
  }
@@ -1,85 +1,14 @@
1
- /**
2
- * Wires the `pragma modifier lookup <name...>` CLI command.
3
- *
4
- * Retrieves a single modifier family by name and renders its values.
5
- */
6
-
7
- import {
8
- type CommandDefinition,
9
- createOutputResult,
10
- } from "@canonical/cli-core";
11
- import { createLookupView } from "#tui";
1
+ import type { CommandDefinition } from "@canonical/cli-core";
12
2
  import type { PragmaContext } from "../../shared/context.js";
13
- import type { LookupResult } from "../../shared/contracts.js";
14
- import { renderLookupResults } from "../../shared/formatters.js";
15
- import {
16
- createInkLookupOptions,
17
- lookupFormatters,
18
- } from "../formatters/index.js";
19
- import type { lookupModifier } from "../operations/index.js";
20
- import { resolveModifierLookup } from "../orchestration/index.js";
21
-
22
- interface ModifierLookupOutput {
23
- readonly result: LookupResult<Awaited<ReturnType<typeof lookupModifier>>>;
24
- }
3
+ import { compileLookupCommand } from "../../shared/stories/index.js";
4
+ import { modifierLookupStory } from "../stories.js";
25
5
 
6
+ /**
7
+ * Wire the `pragma modifier lookup <name...>` CLI command from the
8
+ * modifier lookup story.
9
+ */
26
10
  export default function buildLookupCommand(
27
11
  ctx: PragmaContext,
28
12
  ): CommandDefinition {
29
- return {
30
- path: ["modifier", "lookup"],
31
- description: "Look up a modifier family and its values",
32
- parameters: [
33
- {
34
- name: "names",
35
- description: "Modifier family names or IRIs",
36
- type: "multiselect",
37
- positional: true,
38
- required: true,
39
- },
40
- ],
41
- meta: {
42
- examples: [
43
- "pragma modifier lookup importance",
44
- "pragma modifier lookup importance density",
45
- "pragma modifier lookup importance --llm",
46
- ],
47
- },
48
- async execute(params: Record<string, unknown>) {
49
- const names = normalizeNames(params.names, params.name);
50
- const contract = await resolveModifierLookup(ctx.store, names);
51
-
52
- return createOutputResult<ModifierLookupOutput>(
53
- { result: contract.result },
54
- {
55
- plain: ({ result }) =>
56
- renderLookupResults({
57
- ctx,
58
- result,
59
- formatters: lookupFormatters,
60
- mapResult: (family) => family,
61
- }),
62
- ink: ({ result }) =>
63
- createLookupView({
64
- results: result.results,
65
- errors: result.errors,
66
- domain: "modifier",
67
- options: createInkLookupOptions(),
68
- }),
69
- },
70
- );
71
- },
72
- };
73
- }
74
-
75
- function normalizeNames(names: unknown, legacyName?: unknown): string[] {
76
- if (Array.isArray(names)) {
77
- return names.filter(
78
- (name): name is string => typeof name === "string" && name.length > 0,
79
- );
80
- }
81
- if (typeof legacyName === "string" && legacyName.length > 0) {
82
- return [legacyName];
83
- }
84
- return [];
13
+ return compileLookupCommand(ctx, modifierLookupStory);
85
14
  }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Wires the `pragma modifier sample` CLI command.
3
+ *
4
+ * Returns 1–5 complete modifier family instances as exemplars so agents
5
+ * can learn the data shape before writing queries.
6
+ */
7
+
8
+ import {
9
+ type CommandDefinition,
10
+ createOutputResult,
11
+ } from "@canonical/cli-core";
12
+ import type { PragmaContext } from "../../shared/context.js";
13
+ import { selectFormatter } from "../../shared/formatters.js";
14
+ import type { ModifierFamily, SampleOutput } from "../../shared/types/index.js";
15
+ import { sampleFormatters } from "../formatters/index.js";
16
+ import { sampleModifiers } from "../operations/index.js";
17
+
18
+ const NEXT_STEPS = [
19
+ "Use modifier_lookup to inspect specific modifier families by name.",
20
+ "Use modifier_list to see all available modifier families.",
21
+ ];
22
+
23
+ export default function sampleCommand(ctx: PragmaContext): CommandDefinition {
24
+ return {
25
+ path: ["modifier", "sample"],
26
+ description:
27
+ "Return randomly selected complete modifier family instances as exemplars for shape discovery",
28
+ parameters: [
29
+ {
30
+ name: "count",
31
+ type: "string",
32
+ description: "Number of samples to return (1–5, default 2)",
33
+ required: false,
34
+ },
35
+ ],
36
+ meta: {
37
+ examples: ["pragma modifier sample", "pragma modifier sample --count 3"],
38
+ },
39
+ async execute(params) {
40
+ const count = Number(params.count ?? 2);
41
+ const result = await sampleModifiers(ctx.store, count);
42
+
43
+ const output: SampleOutput<ModifierFamily> = {
44
+ ...result,
45
+ nextSteps: NEXT_STEPS,
46
+ };
47
+
48
+ return createOutputResult(output, {
49
+ plain: selectFormatter(ctx, sampleFormatters),
50
+ });
51
+ },
52
+ };
53
+ }
@@ -1,7 +1,8 @@
1
- /** @module Re-exports modifier formatters (`lookupFormatters`, `listFormatters`). */
1
+ /** @module Re-exports modifier formatters (`listFormatters`, `lookupFormatters`, `sampleFormatters`). */
2
2
 
3
3
  export { default as listFormatters } from "./list.js";
4
4
  export {
5
5
  createInkLookupOptions,
6
6
  default as lookupFormatters,
7
7
  } from "./lookup.js";
8
+ export { default as sampleFormatters } from "./sample.js";
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Sample formatter for the modifier domain.
3
+ *
4
+ * Delegates to the shared factory, rendering each item via the
5
+ * existing modifier lookup formatter.
6
+ */
7
+
8
+ import createSampleFormatters from "../../shared/sampleFormatters.js";
9
+ import type { ModifierFamily } from "../../shared/types/index.js";
10
+ import lookupFormatters from "./lookup.js";
11
+
12
+ export default createSampleFormatters<ModifierFamily>(
13
+ "modifiers",
14
+ (family, mode) => lookupFormatters[mode](family),
15
+ );
@@ -7,15 +7,19 @@
7
7
 
8
8
  import type { CommandDefinition } from "@canonical/cli-core";
9
9
  import type { PragmaContext } from "../shared/context.js";
10
- import { listCommand, lookupCommand } from "./commands/index.js";
10
+ import { listCommand, lookupCommand, sampleCommand } from "./commands/index.js";
11
11
 
12
12
  export function commands(ctx: PragmaContext): CommandDefinition[] {
13
- return [listCommand(ctx), lookupCommand(ctx)];
13
+ return [listCommand(ctx), lookupCommand(ctx), sampleCommand(ctx)];
14
14
  }
15
15
 
16
16
  export { specs as mcpSpecs } from "./mcp/index.js";
17
17
  export { modifierConfig } from "./modifierConfig.js";
18
- export { listModifiers, lookupModifier } from "./operations/index.js";
18
+ export {
19
+ listModifiers,
20
+ lookupModifier,
21
+ sampleModifiers,
22
+ } from "./operations/index.js";
19
23
  export {
20
24
  modifierEmptyError,
21
25
  resolveModifierList,
@@ -1,60 +1,35 @@
1
1
  /**
2
- * MCP tool specs for the modifier domain.
2
+ * MCP tool specs for the modifier domain — modifier_list, modifier_lookup,
3
+ * modifier_sample.
3
4
  *
4
- * Declarative definitions — no MCP imports. The adapter layer
5
- * converts these into registered MCP tools via `registerFromSpec()`.
5
+ * The list and lookup tools are compiled from the modifier read stories in
6
+ * `../stories.ts`; only the sample tool is spec'd by hand. The adapter
7
+ * layer converts these into registered MCP tools via `registerFromSpec()`.
6
8
  */
7
9
 
8
- import type { ToolSpec } from "../../shared/ToolSpec.js";
9
- import {
10
- listFormatters as modifierListFmt,
11
- lookupFormatters as modifierLookupFmt,
12
- } from "../formatters/index.js";
13
10
  import {
14
- resolveModifierList,
15
- resolveModifierLookup,
16
- } from "../orchestration/index.js";
11
+ compileLookupTool,
12
+ compileReadTool,
13
+ condense,
14
+ } from "../../shared/stories/index.js";
15
+ import type { ToolSpec } from "../../shared/ToolSpec.js";
16
+ import { sampleFormatters as modifierSampleFmt } from "../formatters/index.js";
17
+ import { sampleModifiers } from "../operations/index.js";
18
+ import { modifierListStory, modifierLookupStory } from "../stories.js";
17
19
 
18
20
  const specs: readonly ToolSpec[] = [
21
+ compileReadTool(modifierListStory),
22
+ compileLookupTool(modifierLookupStory),
19
23
  {
20
- name: "modifier_list",
21
- description: "List all modifier families with their values.",
24
+ name: "modifier_sample",
25
+ description:
26
+ "Return 1–5 randomly selected complete modifier family instances as exemplars. Use BEFORE writing queries to see actual data shapes, property names, and value formats. Each call returns different instances.",
22
27
  params: {
23
- condensed: {
24
- type: "boolean",
25
- description: "Token-optimized output",
28
+ count: {
29
+ type: "string",
30
+ description: "Number of samples (1–5, default 2)",
26
31
  optional: true,
27
32
  },
28
- },
29
- readOnly: true,
30
- async execute(rt, { condensed }) {
31
- const resolution = await resolveModifierList(rt);
32
-
33
- if (condensed) {
34
- const text = modifierListFmt.llm([...resolution.items]);
35
- return {
36
- condensed: true,
37
- text,
38
- tokens: `~${Math.ceil(text.length / 4)}`,
39
- };
40
- }
41
-
42
- return {
43
- data: resolution.items,
44
- meta: { count: resolution.items.length },
45
- };
46
- },
47
- },
48
-
49
- {
50
- name: "modifier_lookup",
51
- description: "Get one or more modifier families and their values.",
52
- params: {
53
- names: {
54
- type: "string[]",
55
- description: "Modifier family names or IRIs to look up",
56
- optional: false,
57
- },
58
33
  condensed: {
59
34
  type: "boolean",
60
35
  description: "Token-optimized output",
@@ -62,34 +37,27 @@ const specs: readonly ToolSpec[] = [
62
37
  },
63
38
  },
64
39
  readOnly: true,
65
- async execute(rt, { names, condensed }) {
66
- const contract = await resolveModifierLookup(rt.store, names as string[]);
67
- const result = contract.result;
40
+ async execute(rt, { count, condensed }) {
41
+ const n = Number(count ?? 2);
42
+ const result = await sampleModifiers(rt.store, n);
43
+ const nextSteps = [
44
+ `These are ${result.samples.length} of ${result.totalCount} total modifier families.`,
45
+ "Use modifier_lookup to inspect specific modifier families by name.",
46
+ "Use modifier_list to see all available modifier families.",
47
+ ];
68
48
 
69
49
  if (condensed) {
70
- const textParts = result.results.map((family) =>
71
- modifierLookupFmt.llm(family),
72
- );
73
-
74
- if (result.errors.length > 0) {
75
- textParts.push(
76
- [
77
- "### Errors",
78
- ...result.errors.map(
79
- (error) => `- ${error.query}: ${error.message}`,
80
- ),
81
- ].join("\n"),
82
- );
83
- }
84
-
85
- return {
86
- condensed: true,
87
- text: textParts.join("\n\n"),
88
- tokens: `~${Math.ceil(textParts.join("\n\n").length / 4)}`,
89
- };
50
+ return condense(modifierSampleFmt.llm({ ...result, nextSteps }));
90
51
  }
91
52
 
92
- return { data: result, meta: { count: result.results.length } };
53
+ return {
54
+ data: {
55
+ samples: result.samples,
56
+ totalCount: result.totalCount,
57
+ nextSteps,
58
+ },
59
+ meta: { count: result.samples.length },
60
+ };
93
61
  },
94
62
  },
95
63
  ] as const;
@@ -1,4 +1,5 @@
1
- /** @module Re-exports modifier operations (`lookupModifier`, `listModifiers`). */
1
+ /** @module Re-exports modifier operations (`listModifiers`, `lookupModifier`, `sampleModifiers`). */
2
2
 
3
3
  export { default as listModifiers } from "./list.js";
4
4
  export { default as lookupModifier } from "./lookup.js";
5
+ export { default as sampleModifiers } from "./sample.js";
@@ -13,6 +13,11 @@ import { escapeSparqlValue } from "@canonical/ke";
13
13
  import { PragmaError } from "#error";
14
14
  import { buildQuery } from "../../shared/buildQuery.js";
15
15
  import { P } from "../../shared/prefixes.js";
16
+ import {
17
+ detectCrossDomain,
18
+ listDomainNames,
19
+ suggestNames,
20
+ } from "../../shared/suggestions/index.js";
16
21
  import type { ModifierFamily } from "../../shared/types/index.js";
17
22
 
18
23
  export default async function lookupModifier(
@@ -39,12 +44,16 @@ export default async function lookupModifier(
39
44
  );
40
45
 
41
46
  if (result.type !== "select" || result.bindings.length === 0) {
47
+ const candidates = await listDomainNames(store, "modifier");
48
+ const crossDomain = await detectCrossDomain(name, "modifier", store);
42
49
  throw PragmaError.notFound("modifier", name, {
50
+ suggestions: suggestNames(name, candidates),
43
51
  recovery: {
44
52
  message: "List available modifiers.",
45
53
  cli: "pragma modifier list",
46
54
  mcp: { tool: "modifier_list" },
47
55
  },
56
+ crossDomain: crossDomain ?? undefined,
48
57
  });
49
58
  }
50
59
 
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Returns a small number of complete modifier family instances as exemplars.
3
+ *
4
+ * Composes the existing list and lookup operations to avoid duplicating
5
+ * any SPARQL logic. Agents use this to learn the data shape before querying.
6
+ *
7
+ * @param store - ke store to query
8
+ * @param count - number of samples (clamped 1–5, default 2)
9
+ * @returns sample result with detailed modifier families and total count
10
+ * @note Queries ke store
11
+ */
12
+
13
+ import type { Store } from "@canonical/ke";
14
+ import pickRandom from "../../shared/pickRandom.js";
15
+ import type { ModifierFamily, SampleResult } from "../../shared/types/index.js";
16
+ import listModifiers from "./list.js";
17
+ import lookupModifier from "./lookup.js";
18
+
19
+ export default async function sampleModifiers(
20
+ store: Store,
21
+ count = 2,
22
+ ): Promise<SampleResult<ModifierFamily>> {
23
+ const clamped = Math.max(1, Math.min(5, count));
24
+ const all = await listModifiers(store);
25
+ const selected = pickRandom(all, clamped);
26
+
27
+ const samples = await Promise.all(
28
+ selected.map((m) => lookupModifier(store, m.name)),
29
+ );
30
+
31
+ return { samples, totalCount: all.length };
32
+ }