@canonical/pragma-cli 0.30.0 → 0.31.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 (254) hide show
  1. package/README.md +64 -35
  2. package/dist/pragma +0 -0
  3. package/package.json +15 -13
  4. package/src/completions/constants.ts +7 -0
  5. package/src/completions/handleQuery.test.ts +32 -0
  6. package/src/completions/handleQuery.ts +20 -1
  7. package/src/completions/queryCompletions.test.ts +5 -0
  8. package/src/completions/queryCompletions.ts +17 -3
  9. package/src/completions/querySocket.test.ts +31 -0
  10. package/src/completions/querySocket.ts +36 -9
  11. package/src/config/parseConfigValues.ts +2 -0
  12. package/src/config/readConfigLayers.test.ts +2 -0
  13. package/src/config/readConfigLayers.ts +3 -0
  14. package/src/config/types.ts +7 -0
  15. package/src/constants.ts +3 -1
  16. package/src/domains/block/commands/sample.ts +2 -1
  17. package/src/domains/block/formatters/list.test.ts +3 -3
  18. package/src/domains/block/formatters/lookup.test.ts +5 -5
  19. package/src/domains/block/orchestration/enrichBlocks.ts +6 -3
  20. package/src/domains/block/stories.ts +9 -3
  21. package/src/domains/config/commands/channel.test.ts +16 -0
  22. package/src/domains/config/commands/channel.ts +14 -1
  23. package/src/domains/config/commands/framework.test.ts +14 -0
  24. package/src/domains/config/commands/framework.ts +13 -1
  25. package/src/domains/config/commands/tier.test.ts +7 -0
  26. package/src/domains/config/commands/tier.ts +14 -1
  27. package/src/domains/config/operations/validateTier.test.ts +9 -0
  28. package/src/domains/config/operations/validateTier.ts +10 -2
  29. package/src/domains/create/generatorPack/bundled.ts +49 -0
  30. package/src/domains/create/generatorPack/compileGeneratorPack.test.ts +159 -0
  31. package/src/domains/create/generatorPack/compileGeneratorPack.ts +312 -0
  32. package/src/domains/create/index.ts +13 -7
  33. package/src/domains/create/mcp/specs.ts +6 -161
  34. package/src/domains/create/renderGeneratorUi.test.ts +103 -0
  35. package/src/domains/create/renderGeneratorUi.ts +65 -0
  36. package/src/domains/doctor/formatters/doctor.test.ts +50 -2
  37. package/src/domains/doctor/formatters/doctor.ts +90 -38
  38. package/src/domains/doctor/operations/checks/checkMcpCommands.ts +9 -6
  39. package/src/domains/doctor/operations/checks/checkPackageRefs.ts +30 -12
  40. package/src/domains/doctor/operations/checks.test.ts +6 -4
  41. package/src/domains/doctor/operations/types.ts +23 -1
  42. package/src/domains/graph/commands/inspect.test.ts +2 -2
  43. package/src/domains/graph/commands/query.test.ts +5 -3
  44. package/src/domains/graph/formatters/inspect.ts +7 -7
  45. package/src/domains/graph/formatters/query.test.ts +87 -0
  46. package/src/domains/graph/formatters/query.ts +42 -5
  47. package/src/domains/graph/operations/inspectUri.test.ts +5 -5
  48. package/src/domains/graphql/commands/serve.test.ts +12 -6
  49. package/src/domains/graphql/commands/serve.ts +16 -6
  50. package/src/domains/graphql/helpers/parsePrefixes.test.ts +3 -3
  51. package/src/domains/graphql/helpers/parsePrefixes.ts +3 -3
  52. package/src/domains/graphql/helpers/resolveSourceFiles.test.ts +9 -0
  53. package/src/domains/graphql/helpers/resolveSourceFiles.ts +24 -3
  54. package/src/domains/graphql/operations/compileSchema.test.ts +2 -2
  55. package/src/domains/graphql/operations/createSchemaServer.test.ts +2 -2
  56. package/src/domains/graphql/operations/ensureSchemaArtifact.test.ts +167 -0
  57. package/src/domains/graphql/operations/ensureSchemaArtifact.ts +178 -0
  58. package/src/domains/graphql/operations/index.ts +5 -0
  59. package/src/domains/info/formatters/upgrade.test.ts +7 -4
  60. package/src/domains/info/formatters/upgrade.ts +3 -1
  61. package/src/domains/info/operations/collectEntityCounts.test.ts +156 -0
  62. package/src/domains/info/operations/collectEntityCounts.ts +123 -0
  63. package/src/domains/info/operations/index.ts +1 -0
  64. package/src/domains/info/types.ts +13 -0
  65. package/src/domains/llm/capabilities.test.ts +23 -3
  66. package/src/domains/llm/commands/capabilities.ts +12 -3
  67. package/src/domains/llm/commands/llm.ts +5 -1
  68. package/src/domains/llm/data/commandReference.ts +20 -11
  69. package/src/domains/llm/data/decisionTrees.ts +10 -5
  70. package/src/domains/llm/data/toolCatalog.ts +49 -18
  71. package/src/domains/llm/formatters/orientation.ts +5 -1
  72. package/src/domains/llm/llmCommand.test.ts +11 -3
  73. package/src/domains/llm/mcp/specs.ts +3 -4
  74. package/src/domains/llm/operations/collectContext.test.ts +64 -0
  75. package/src/domains/llm/operations/collectContext.ts +7 -17
  76. package/src/domains/modifier/commands/sample.ts +2 -1
  77. package/src/domains/modifier/operations/lookup.ts +5 -3
  78. package/src/domains/modifier/stories.ts +9 -0
  79. package/src/domains/ontology/commands/list.test.ts +5 -3
  80. package/src/domains/ontology/commands/show.test.ts +85 -9
  81. package/src/domains/ontology/formatters/index.ts +1 -0
  82. package/src/domains/ontology/formatters/list.ts +37 -12
  83. package/src/domains/ontology/formatters/show.ts +358 -67
  84. package/src/domains/ontology/helpers/buildClassTree.ts +89 -0
  85. package/src/domains/ontology/helpers/completeClassNames.ts +43 -0
  86. package/src/domains/ontology/helpers/expandOntologyIris.ts +79 -0
  87. package/src/domains/ontology/helpers/index.ts +14 -0
  88. package/src/domains/ontology/helpers/queryClasses.ts +32 -16
  89. package/src/domains/ontology/helpers/queryProperties.ts +39 -6
  90. package/src/domains/ontology/helpers/queryTboxFacts.ts +160 -0
  91. package/src/domains/ontology/operations/listOntologies.test.ts +80 -3
  92. package/src/domains/ontology/operations/listOntologies.ts +126 -30
  93. package/src/domains/ontology/operations/showOntology.test.ts +131 -12
  94. package/src/domains/ontology/operations/showOntology.ts +289 -7
  95. package/src/domains/ontology/operations/showOntologyRaw.test.ts +4 -2
  96. package/src/domains/ontology/stories.ts +53 -8
  97. package/src/domains/refs/operations/updateRefs.ts +0 -1
  98. package/src/domains/setup/commands/index.ts +1 -0
  99. package/src/domains/setup/commands/setup.ts +70 -0
  100. package/src/domains/setup/index.ts +7 -3
  101. package/src/domains/setup/operations/setupLsp.test.ts +3 -2
  102. package/src/domains/setup/operations/setupLsp.ts +7 -2
  103. package/src/domains/shared/bootStore.bareCore.test.ts +63 -0
  104. package/src/domains/shared/bootStore.test.ts +82 -0
  105. package/src/domains/shared/bootStore.ts +56 -20
  106. package/src/domains/shared/emptyErrorRecovery.test.ts +23 -26
  107. package/src/domains/shared/extractLocalName.test.ts +3 -3
  108. package/src/domains/shared/formatters.ts +23 -2
  109. package/src/domains/shared/listTiers.ts +40 -0
  110. package/src/domains/shared/loaders/bundledLoader.ts +48 -0
  111. package/src/domains/shared/loaders/gitLoader.ts +1 -2
  112. package/src/domains/shared/loaders/localLoader.ts +2 -18
  113. package/src/domains/shared/loaders/readPackageDir.test.ts +58 -0
  114. package/src/domains/shared/loaders/readPackageDir.ts +46 -8
  115. package/src/domains/shared/lookupMany.test.ts +15 -0
  116. package/src/domains/shared/lookupMany.ts +22 -6
  117. package/src/domains/shared/namespaces.ts +13 -5
  118. package/src/domains/shared/parseSampleCount.test.ts +47 -0
  119. package/src/domains/shared/parseSampleCount.ts +45 -0
  120. package/src/domains/shared/prefixes.test.ts +211 -0
  121. package/src/domains/shared/prefixes.ts +182 -15
  122. package/src/domains/shared/renderers.ts +5 -5
  123. package/src/domains/shared/resolveLookupExitCode.test.ts +48 -0
  124. package/src/domains/shared/resolveLookupExitCode.ts +42 -0
  125. package/src/domains/shared/semanticPackage.test.ts +89 -0
  126. package/src/domains/shared/semanticPackage.ts +17 -2
  127. package/src/domains/shared/stories/compileLookupCommand.ts +3 -1
  128. package/src/domains/shared/stories/compileLookupTool.ts +1 -1
  129. package/src/domains/shared/stories/pack/applyPackFilters.test.ts +49 -0
  130. package/src/domains/shared/stories/pack/applyPackFilters.ts +46 -11
  131. package/src/domains/shared/stories/pack/applyPackSearch.test.ts +57 -0
  132. package/src/domains/shared/stories/pack/applyPackSearch.ts +41 -0
  133. package/src/domains/shared/stories/pack/buildLookupQuery.test.ts +30 -0
  134. package/src/domains/shared/stories/pack/buildLookupQuery.ts +75 -1
  135. package/src/domains/shared/stories/pack/bundled/index.ts +23 -0
  136. package/src/domains/shared/stories/pack/bundled/standardPack.ts +164 -0
  137. package/src/domains/shared/stories/pack/bundled/tierPack.ts +50 -0
  138. package/src/domains/shared/stories/pack/collectPackStories.test.ts +305 -7
  139. package/src/domains/shared/stories/pack/collectPackStories.ts +90 -8
  140. package/src/domains/shared/stories/pack/compilePackCommands.ts +17 -7
  141. package/src/domains/shared/stories/pack/compilePackStories.test.ts +607 -2
  142. package/src/domains/shared/stories/pack/compilePackStories.ts +544 -73
  143. package/src/domains/shared/stories/pack/compilePackToolSpecs.ts +20 -8
  144. package/src/domains/shared/stories/pack/index.ts +14 -0
  145. package/src/domains/shared/stories/pack/reservedVerbs.test.ts +213 -0
  146. package/src/domains/shared/stories/pack/reservedVerbs.ts +170 -0
  147. package/src/domains/shared/stories/pack/standardParity.test.ts +293 -220
  148. package/src/domains/shared/stories/pack/types.ts +123 -3
  149. package/src/domains/shared/stories/pack/validateStoryPackDefinition.test.ts +502 -0
  150. package/src/domains/shared/stories/pack/validateStoryPackDefinition.ts +475 -24
  151. package/src/domains/shared/stories/types.ts +9 -1
  152. package/src/domains/shared/types/index.ts +5 -9
  153. package/src/domains/shared/types/ontology.ts +119 -24
  154. package/src/domains/shared/types/standard.ts +9 -52
  155. package/src/domains/token/commands/lookup.test.ts +8 -0
  156. package/src/domains/token/commands/lookup.ts +12 -0
  157. package/src/domains/token/commands/sample.ts +2 -1
  158. package/src/domains/token/featureFlag.ts +17 -0
  159. package/src/domains/token/index.ts +5 -0
  160. package/src/domains/token/mcp/specs.ts +13 -1
  161. package/src/domains/trace/commands/resolveTraceLimit.test.ts +31 -0
  162. package/src/domains/trace/commands/show.ts +30 -4
  163. package/src/index.ts +1 -13
  164. package/src/mcp/registerResources.test.ts +2 -2
  165. package/src/mcp/resources/pickPrimaryType.test.ts +5 -5
  166. package/src/mcp/tools/index.ts +18 -10
  167. package/src/mcp/tools/registerTools.test.ts +106 -30
  168. package/src/pipeline/collectCommands.test.ts +151 -1
  169. package/src/pipeline/collectCommands.ts +34 -19
  170. package/src/pipeline/createProgram.test.ts +5 -1
  171. package/src/pipeline/createProgram.ts +2 -2
  172. package/src/pipeline/firstRun.test.ts +80 -0
  173. package/src/pipeline/firstRun.ts +99 -0
  174. package/src/pipeline/parseGlobalFlags.test.ts +102 -1
  175. package/src/pipeline/parseGlobalFlags.ts +98 -9
  176. package/src/pipeline/resolveCommandKind.test.ts +12 -0
  177. package/src/pipeline/resolveCommandKind.ts +4 -0
  178. package/src/pipeline/rootHelp.test.ts +87 -0
  179. package/src/pipeline/rootHelp.ts +265 -0
  180. package/src/pipeline/runCli.orchestration.test.ts +28 -12
  181. package/src/pipeline/runCli.test.ts +17 -4
  182. package/src/pipeline/runCli.ts +162 -19
  183. package/src/testing/cli.ts +30 -2
  184. package/src/testing/dsFixtures.ts +21 -4
  185. package/src/testing/index.ts +1 -4
  186. package/src/testing/integration/__snapshots__/executor-golden.test.ts.snap +4 -4
  187. package/src/testing/integration/cli-user-stories.test.ts +63 -0
  188. package/src/testing/integration/cross-binary-byte-equality.test.ts +2 -2
  189. package/src/testing/integration/edge-cases.test.ts +62 -50
  190. package/src/testing/integration/executor-execution.test.ts +6 -4
  191. package/src/testing/integration/executor-golden.test.ts +2 -2
  192. package/src/testing/integration/mcp-surface.test.ts +40 -15
  193. package/src/testing/integration/parity.test.ts +119 -70
  194. package/src/testing/setupXdgIsolation.ts +16 -5
  195. package/src/testing/standardParityFixtures.ts +26 -83
  196. package/src/testing/store.ts +4 -4
  197. package/src/domains/create/commands/component.test.ts +0 -166
  198. package/src/domains/create/commands/component.ts +0 -123
  199. package/src/domains/create/commands/index.ts +0 -3
  200. package/src/domains/create/commands/package.test.ts +0 -35
  201. package/src/domains/create/commands/package.ts +0 -21
  202. package/src/domains/create/generators.ts +0 -8
  203. package/src/domains/standard/commands/categories.test.ts +0 -70
  204. package/src/domains/standard/commands/categories.ts +0 -48
  205. package/src/domains/standard/commands/index.ts +0 -6
  206. package/src/domains/standard/commands/list.test.ts +0 -105
  207. package/src/domains/standard/commands/list.ts +0 -11
  208. package/src/domains/standard/commands/lookup.test.ts +0 -135
  209. package/src/domains/standard/commands/lookup.ts +0 -14
  210. package/src/domains/standard/commands/sample.ts +0 -57
  211. package/src/domains/standard/formatters/categories.test.ts +0 -44
  212. package/src/domains/standard/formatters/categories.ts +0 -38
  213. package/src/domains/standard/formatters/index.ts +0 -10
  214. package/src/domains/standard/formatters/list.test.ts +0 -169
  215. package/src/domains/standard/formatters/list.ts +0 -184
  216. package/src/domains/standard/formatters/lookup.test.ts +0 -95
  217. package/src/domains/standard/formatters/lookup.ts +0 -101
  218. package/src/domains/standard/formatters/sample.ts +0 -15
  219. package/src/domains/standard/formatters/types.ts +0 -31
  220. package/src/domains/standard/index.ts +0 -40
  221. package/src/domains/standard/mcp/index.ts +0 -2
  222. package/src/domains/standard/mcp/specs.ts +0 -89
  223. package/src/domains/standard/operations/categories.test.ts +0 -61
  224. package/src/domains/standard/operations/categories.ts +0 -38
  225. package/src/domains/standard/operations/index.ts +0 -6
  226. package/src/domains/standard/operations/list.test.ts +0 -75
  227. package/src/domains/standard/operations/list.ts +0 -64
  228. package/src/domains/standard/operations/lookup.test.ts +0 -58
  229. package/src/domains/standard/operations/lookup.ts +0 -151
  230. package/src/domains/standard/operations/sample.ts +0 -35
  231. package/src/domains/standard/orchestration/buildStandardFilters.ts +0 -11
  232. package/src/domains/standard/orchestration/index.ts +0 -4
  233. package/src/domains/standard/orchestration/resolveStandardList.ts +0 -45
  234. package/src/domains/standard/orchestration/resolveStandardLookup.ts +0 -33
  235. package/src/domains/standard/orchestration/standardEmptyError.test.ts +0 -33
  236. package/src/domains/standard/orchestration/standardEmptyError.ts +0 -29
  237. package/src/domains/standard/standardConfig.ts +0 -42
  238. package/src/domains/standard/stories.test.ts +0 -24
  239. package/src/domains/standard/stories.ts +0 -151
  240. package/src/domains/standard/types.ts +0 -15
  241. package/src/domains/tier/commands/index.ts +0 -3
  242. package/src/domains/tier/commands/list.test.ts +0 -67
  243. package/src/domains/tier/commands/list.ts +0 -9
  244. package/src/domains/tier/formatters/index.ts +0 -3
  245. package/src/domains/tier/formatters/list.test.ts +0 -33
  246. package/src/domains/tier/formatters/list.ts +0 -45
  247. package/src/domains/tier/index.ts +0 -17
  248. package/src/domains/tier/mcp/index.ts +0 -2
  249. package/src/domains/tier/mcp/specs.ts +0 -12
  250. package/src/domains/tier/operations/index.ts +0 -3
  251. package/src/domains/tier/operations/list.test.ts +0 -32
  252. package/src/domains/tier/operations/list.ts +0 -33
  253. package/src/domains/tier/stories.test.ts +0 -22
  254. package/src/domains/tier/stories.ts +0 -52
@@ -2,49 +2,144 @@
2
2
 
3
3
  /** Summary of a loaded ontology namespace from `ontology list`. */
4
4
  export interface OntologySummary {
5
- /** Short prefix alias (e.g., `"ds"`, `"cs"`). */
5
+ /** Short prefix alias (e.g., `"ds"`), or `""` when none is registered. */
6
6
  readonly prefix: string;
7
7
  /** Full namespace URI the prefix expands to. */
8
8
  readonly namespace: string;
9
+ /** rdfs:label of the namespace's owl:Ontology header, when declared. */
10
+ readonly title?: string;
11
+ /** owl:versionInfo of the namespace's owl:Ontology header, when declared. */
12
+ readonly version?: string;
9
13
  /** Number of OWL/RDFS classes defined in this namespace. */
10
14
  readonly classCount: number;
11
- /** Number of properties (object + datatype) defined in this namespace. */
12
- readonly propertyCount: number;
15
+ /** Number of object properties (class-to-class relations). */
16
+ readonly relationCount: number;
17
+ /** Number of datatype properties (literal-valued attributes). */
18
+ readonly attributeCount: number;
19
+ /** Number of SHACL node shapes constraining this namespace. */
20
+ readonly shapeCount: number;
13
21
  readonly anatomyCount: number;
14
22
  }
15
23
 
16
- /** A class in an ontology's class hierarchy. */
24
+ /**
25
+ * A property in an ontology namespace.
26
+ *
27
+ * All IRIs are compact (`ds:tier`); the owning {@link OntologyDetailed}
28
+ * carries the `prefixes` map needed to expand them.
29
+ */
30
+ export interface OntologyProperty {
31
+ /** Compact IRI of the property. */
32
+ readonly iri: string;
33
+ /** Human-readable label (rdfs:label, falling back to the local name). */
34
+ readonly label: string;
35
+ /** Whether this is an object property (links classes) or datatype property (links to literals). */
36
+ readonly kind: "object" | "datatype";
37
+ /** Compact IRI of the domain class this property applies to, if declared. */
38
+ readonly domain?: string;
39
+ /** Compact IRI of the range class or datatype, if declared. */
40
+ readonly range?: string;
41
+ /** Present (true) when the property is an owl:FunctionalProperty. */
42
+ readonly functional?: true;
43
+ }
44
+
45
+ /**
46
+ * A class in an ontology's class hierarchy.
47
+ *
48
+ * Classes arrive in deterministic topological order (roots first,
49
+ * alphabetical among siblings) with their direct properties attached.
50
+ */
17
51
  export interface OntologyClass {
18
- /** Full URI of the class. */
19
- readonly uri: string;
20
- /** Human-readable label (rdfs:label). */
52
+ /** Compact IRI of the class. */
53
+ readonly iri: string;
54
+ /** Human-readable label (rdfs:label, falling back to the local name). */
21
55
  readonly label: string;
22
- /** URI of the direct superclass, if declared. */
23
- readonly superclass?: string;
56
+ /** Class documentation (rdfs:comment), omitted when absent. */
57
+ readonly comment?: string;
58
+ /** Compact IRIs of all direct superclasses (empty for roots). */
59
+ readonly subClassOf: readonly string[];
60
+ /** Number of instances typed with this class, omitted when zero. */
61
+ readonly instances?: number;
62
+ /** Properties whose rdfs:domain is this class. */
63
+ readonly properties: readonly OntologyProperty[];
24
64
  }
25
65
 
26
- /** A property in an ontology namespace. */
27
- export interface OntologyProperty {
28
- /** Full URI of the property. */
29
- readonly uri: string;
30
- /** Human-readable label (rdfs:label). */
66
+ /** Summary of a SHACL node shape constraining a class. */
67
+ export interface OntologyConstraint {
68
+ /** Compact IRI of the sh:NodeShape. */
69
+ readonly shape: string;
70
+ /** Compact IRI of the sh:targetClass, if declared. */
71
+ readonly targetClass?: string;
72
+ /** Number of sh:property constraints on the shape. */
73
+ readonly propertyCount: number;
74
+ }
75
+
76
+ /** owl:Ontology header metadata, when the namespace declares one. */
77
+ export interface OntologyMeta {
78
+ /** rdfs:label / dcterms:title of the ontology node. */
79
+ readonly title?: string;
80
+ /** owl:versionInfo. */
81
+ readonly version?: string;
82
+ /** Compact IRIs of owl:imports. */
83
+ readonly imports?: readonly string[];
84
+ }
85
+
86
+ /** A ready-to-run SPARQL hint for follow-up querying. */
87
+ export interface OntologyQueryHint {
88
+ /** What the query answers (e.g. "instances of ds:Component"). */
31
89
  readonly label: string;
32
- /** URI of the domain class this property applies to, if declared. */
33
- readonly domain?: string;
34
- /** URI of the range class or datatype, if declared. */
35
- readonly range?: string;
36
- /** Whether this is an object property (links classes) or datatype property (links to literals). */
37
- readonly type: "object" | "datatype";
90
+ /**
91
+ * SPARQL using compact IRIs — runnable as-is via `pragma graph query`,
92
+ * which resolves the store's prefix map.
93
+ */
94
+ readonly sparql: string;
38
95
  }
39
96
 
40
- /** Detailed view of a single ontology namespace from `ontology show`. */
97
+ /** Deep-dive view of one class, produced by `ontology show <ns> --class <C>`. */
98
+ export interface OntologyClassFocus {
99
+ /** Compact IRI of the focused class. */
100
+ readonly iri: string;
101
+ readonly label: string;
102
+ readonly comment?: string;
103
+ /** Superclass chain within the namespace, nearest first. */
104
+ readonly superChain: readonly string[];
105
+ /** Compact IRIs of direct subclasses. */
106
+ readonly subclasses: readonly string[];
107
+ /** Number of instances typed with this class. */
108
+ readonly instances: number;
109
+ /** Properties declared directly on this class. */
110
+ readonly directProperties: readonly OntologyProperty[];
111
+ /** Properties inherited from the super chain. */
112
+ readonly inheritedProperties: readonly OntologyProperty[];
113
+ /** Properties elsewhere in the namespace whose range is this class. */
114
+ readonly referencedBy: readonly OntologyProperty[];
115
+ /** Up to a few instance IRIs, as entry points for `graph inspect` / lookups. */
116
+ readonly sampleInstances: readonly string[];
117
+ /** Ready-to-run SPARQL for the natural follow-up questions. */
118
+ readonly queries: readonly OntologyQueryHint[];
119
+ }
120
+
121
+ /**
122
+ * Detailed view of a single ontology namespace from `ontology show`.
123
+ *
124
+ * This is the single complete structure every output mode projects:
125
+ * plain, `--llm`, `--format json`, and the MCP `ontology_show` envelope
126
+ * all render from this shape and nothing else.
127
+ */
41
128
  export interface OntologyDetailed {
42
129
  /** Short prefix alias (e.g., `"ds"`). */
43
130
  readonly prefix: string;
44
131
  /** Full namespace URI the prefix expands to. */
45
132
  readonly namespace: string;
46
- /** All classes defined in this namespace. */
133
+ /** Prefix map covering every compact IRI used in this structure. */
134
+ readonly prefixes: Readonly<Record<string, string>>;
135
+ /** owl:Ontology header metadata, omitted when the namespace declares none. */
136
+ readonly meta?: OntologyMeta;
137
+ /** All classes, topologically ordered, with direct properties attached. */
47
138
  readonly classes: readonly OntologyClass[];
48
- /** All properties defined in this namespace. */
49
- readonly properties: readonly OntologyProperty[];
139
+ /** Properties with no domain, or a domain outside this namespace's classes. */
140
+ readonly unattached: readonly OntologyProperty[];
141
+ /** SHACL node-shape summaries, omitted when none exist. */
142
+ readonly constraints?: readonly OntologyConstraint[];
143
+ /** Per-class deep dive, present when a class filter was requested. */
144
+ readonly focus?: OntologyClassFocus;
50
145
  }
@@ -1,58 +1,15 @@
1
- /** Standard domain return types. */
1
+ /**
2
+ * Standard cross-reference type.
3
+ *
4
+ * The hand-written standard domain's return types (StandardSummary,
5
+ * StandardDetailed, CodeBlock, …) were deleted with the domain — the
6
+ * `standard` noun is served by the bundled story pack, whose rows and
7
+ * entities are generic string records. Only {@link StandardRef} remains:
8
+ * block lookups still cross-reference standards by name/URI/category.
9
+ */
2
10
 
3
11
  import type { URI } from "@canonical/ke";
4
12
 
5
- /** Summary view of a design-system standard (guideline or rule). */
6
- export interface StandardSummary {
7
- /** Full RDF URI identifying this standard in the ke store. */
8
- readonly uri: URI;
9
- /** Human-readable name of the standard. */
10
- readonly name: string;
11
- /** Category grouping (e.g., `"accessibility"`, `"layout"`). */
12
- readonly category: string;
13
- /** Brief prose description of what the standard prescribes. */
14
- readonly description: string;
15
- /** URI of the parent standard this one extends, if any. */
16
- readonly extends?: string;
17
- }
18
-
19
- /** Digest view of a standard for generic list contracts. */
20
- export type StandardDigest = StandardSummary;
21
-
22
- /** Fenced code block used in standard do/don't examples. */
23
- export interface CodeBlock {
24
- /** Programming language identifier for syntax highlighting. */
25
- readonly language: string;
26
- /** Source code content of the example. */
27
- readonly code: string;
28
- /** Optional explanatory caption displayed alongside the code. */
29
- readonly caption?: string;
30
- }
31
-
32
- /** Detailed view of a standard, extending the summary with code examples. */
33
- export interface StandardDetailed extends StandardSummary {
34
- /** Positive examples demonstrating correct usage. */
35
- readonly dos: readonly CodeBlock[];
36
- /** Negative examples demonstrating incorrect usage. */
37
- readonly donts: readonly CodeBlock[];
38
- }
39
-
40
- /** Summary of a standards category with its member count. */
41
- export interface CategorySummary {
42
- /** Category name (e.g., `"accessibility"`, `"layout"`). */
43
- readonly name: string;
44
- /** Number of standards belonging to this category. */
45
- readonly standardCount: number;
46
- }
47
-
48
- /** Optional filters for narrowing the standards list. */
49
- export interface StandardListFilters {
50
- /** Restrict results to a single category name. */
51
- readonly category?: string;
52
- /** Free-text search term matched against standard names and descriptions. */
53
- readonly search?: string;
54
- }
55
-
56
13
  /** Lightweight reference to a standard, used in block cross-references. */
57
14
  export interface StandardRef {
58
15
  /** Human-readable standard name. */
@@ -122,4 +122,12 @@ describe("token lookup command", () => {
122
122
  expect(text).toContain("color.primary");
123
123
  expect(text).toContain("spacing.sm");
124
124
  });
125
+
126
+ it("rejects an empty names list with INVALID_INPUT", async () => {
127
+ const ctx = makeCtx();
128
+ const cmd = lookupCommand(ctx);
129
+ await expect(cmd.execute({ names: [] }, ctx)).rejects.toMatchObject({
130
+ code: "INVALID_INPUT",
131
+ });
132
+ });
125
133
  });
@@ -10,9 +10,11 @@ import {
10
10
  createOutputResult,
11
11
  } from "@canonical/cli-core";
12
12
  import { createLookupView } from "#tui";
13
+ import { PragmaError } from "../../../error/index.js";
13
14
  import type { PragmaContext } from "../../shared/context.js";
14
15
  import type { LookupResult } from "../../shared/contracts.js";
15
16
  import { renderLookupResults } from "../../shared/formatters.js";
17
+ import resolveLookupExitCode from "../../shared/resolveLookupExitCode.js";
16
18
  import {
17
19
  createLookupFormatters,
18
20
  createTokenInkLookupOptions,
@@ -56,6 +58,15 @@ export default function buildLookupCommand(
56
58
  },
57
59
  async execute(params: Record<string, unknown>) {
58
60
  const names = normalizeNames(params.names, params.name);
61
+ if (names.length === 0) {
62
+ throw PragmaError.invalidInput("names", "(empty)", {
63
+ recovery: {
64
+ message: "List available tokens.",
65
+ cli: "pragma token list",
66
+ mcp: { tool: "token_list" },
67
+ },
68
+ });
69
+ }
59
70
  const detailed = (params.detailed as boolean) ?? false;
60
71
  const contract = await resolveTokenLookup(ctx.store, names);
61
72
 
@@ -77,6 +88,7 @@ export default function buildLookupCommand(
77
88
  options: createTokenInkLookupOptions({ detailed: isDetailed }),
78
89
  }),
79
90
  },
91
+ resolveLookupExitCode(contract.result),
80
92
  );
81
93
  },
82
94
  };
@@ -11,6 +11,7 @@ import {
11
11
  } from "@canonical/cli-core";
12
12
  import type { PragmaContext } from "../../shared/context.js";
13
13
  import { selectFormatter } from "../../shared/formatters.js";
14
+ import parseSampleCount from "../../shared/parseSampleCount.js";
14
15
  import type { SampleOutput, TokenDetailed } from "../../shared/types/index.js";
15
16
  import { sampleFormatters } from "../formatters/index.js";
16
17
  import { sampleTokens } from "../operations/index.js";
@@ -37,7 +38,7 @@ export default function sampleCommand(ctx: PragmaContext): CommandDefinition {
37
38
  examples: ["pragma token sample", "pragma token sample --count 3"],
38
39
  },
39
40
  async execute(params) {
40
- const count = Number(params.count ?? 2);
41
+ const count = parseSampleCount(params.count);
41
42
  const result = await sampleTokens(ctx.store, count);
42
43
 
43
44
  const output: SampleOutput<TokenDetailed> = {
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Feature flag for the token *read* surface (`token list`, `token lookup`,
3
+ * `token sample` and their MCP twins `token_list`, `token_lookup`,
4
+ * `token_sample`).
5
+ *
6
+ * Disabled until token data ships in the semantic packages: the current
7
+ * `@canonical/design-system` data (bundled and `#main`) contains no token
8
+ * instances, so every read command returned EMPTY_RESULTS while the docs
9
+ * and LLM orientation advertised the surface. Flip this to `true` once the
10
+ * ontology publishes token data — commands, MCP tools, and the LLM
11
+ * orientation (tool catalog, command reference, decision trees) all key
12
+ * off this single constant.
13
+ *
14
+ * `pragma tokens add-config` is unaffected: it scaffolds Terrazzo config
15
+ * from package conventions and does not depend on store data.
16
+ */
17
+ export const TOKEN_READ_SURFACE_ENABLED = false;
@@ -14,8 +14,12 @@ import {
14
14
  lookupCommand,
15
15
  sampleCommand,
16
16
  } from "./commands/index.js";
17
+ import { TOKEN_READ_SURFACE_ENABLED } from "./featureFlag.js";
17
18
 
18
19
  export function commands(ctx: PragmaContext): CommandDefinition[] {
20
+ if (!TOKEN_READ_SURFACE_ENABLED) {
21
+ return [addConfigCommand()];
22
+ }
19
23
  return [
20
24
  listCommand(ctx),
21
25
  lookupCommand(ctx),
@@ -24,6 +28,7 @@ export function commands(ctx: PragmaContext): CommandDefinition[] {
24
28
  ];
25
29
  }
26
30
 
31
+ export { TOKEN_READ_SURFACE_ENABLED } from "./featureFlag.js";
27
32
  export { specs as mcpSpecs } from "./mcp/index.js";
28
33
  export type { AddConfigResult, TokenListFilters } from "./operations/index.js";
29
34
  export {
@@ -9,6 +9,7 @@ import { writeFileSync } from "node:fs";
9
9
  import { PragmaError } from "#error";
10
10
  import { lookupToolMeta } from "../../shared/lookupMany.js";
11
11
  import type { ToolSpec } from "../../shared/ToolSpec.js";
12
+ import { TOKEN_READ_SURFACE_ENABLED } from "../featureFlag.js";
12
13
  import {
13
14
  createLookupFormatters as createTokenLookupFmt,
14
15
  listFormatters as tokenListFmt,
@@ -20,7 +21,7 @@ import {
20
21
  resolveTokenLookup,
21
22
  } from "../orchestration/index.js";
22
23
 
23
- const specs: readonly ToolSpec[] = [
24
+ const allSpecs: readonly ToolSpec[] = [
24
25
  {
25
26
  name: "token_list",
26
27
  description:
@@ -192,4 +193,15 @@ const specs: readonly ToolSpec[] = [
192
193
  },
193
194
  ] as const;
194
195
 
196
+ /** Token read tools gated by {@link TOKEN_READ_SURFACE_ENABLED}. */
197
+ const TOKEN_READ_TOOLS = new Set([
198
+ "token_list",
199
+ "token_lookup",
200
+ "token_sample",
201
+ ]);
202
+
203
+ const specs: readonly ToolSpec[] = TOKEN_READ_SURFACE_ENABLED
204
+ ? allSpecs
205
+ : allSpecs.filter((spec) => !TOKEN_READ_TOOLS.has(spec.name));
206
+
195
207
  export default specs;
@@ -0,0 +1,31 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { PragmaError } from "#error";
3
+ import { resolveTraceLimit } from "./show.js";
4
+
5
+ describe("resolveTraceLimit", () => {
6
+ it("defaults to 50 when absent", () => {
7
+ expect(resolveTraceLimit(undefined)).toBe(50);
8
+ expect(resolveTraceLimit("")).toBe(50);
9
+ });
10
+
11
+ it("accepts a positive integer", () => {
12
+ expect(resolveTraceLimit("20")).toBe(20);
13
+ expect(resolveTraceLimit(" 5 ")).toBe(5);
14
+ });
15
+
16
+ it.each([
17
+ "notanumber",
18
+ "-5",
19
+ "0",
20
+ "3.5",
21
+ "1e1",
22
+ "0x5",
23
+ ])("rejects the non-positive-integer value %j", (value) => {
24
+ expect(() => resolveTraceLimit(value)).toThrowError(PragmaError);
25
+ try {
26
+ resolveTraceLimit(value);
27
+ } catch (error) {
28
+ expect((error as PragmaError).code).toBe("INVALID_INPUT");
29
+ }
30
+ });
31
+ });
@@ -9,6 +9,7 @@ import {
9
9
  type CommandDefinition,
10
10
  createOutputResult,
11
11
  } from "@canonical/cli-core";
12
+ import { PragmaError } from "#error";
12
13
  import { traceDir } from "../../refs/operations/paths.js";
13
14
  import { selectFormatter } from "../../shared/formatters.js";
14
15
  import {
@@ -22,6 +23,30 @@ import {
22
23
  readTraceLog,
23
24
  } from "../operations/index.js";
24
25
 
26
+ /** Number of trace records shown when `--limit` is omitted. */
27
+ const DEFAULT_TRACE_LIMIT = 50;
28
+
29
+ /**
30
+ * Resolve the `--limit` value into a positive integer record count.
31
+ *
32
+ * @param raw - The raw param value.
33
+ * @returns The default when absent, else the validated positive integer.
34
+ * @throws PragmaError INVALID_INPUT when present but not a positive integer.
35
+ */
36
+ export function resolveTraceLimit(raw: unknown): number {
37
+ if (raw === undefined || raw === null || raw === "") {
38
+ return DEFAULT_TRACE_LIMIT;
39
+ }
40
+ const text = String(raw).trim();
41
+ const parsed = Number(text);
42
+ if (!/^\d+$/.test(text) || parsed < 1) {
43
+ throw PragmaError.invalidInput("limit", String(raw), {
44
+ recovery: { message: "Provide a positive integer." },
45
+ });
46
+ }
47
+ return parsed;
48
+ }
49
+
25
50
  function formatOneLine(r: import("../types.js").TraceRecord): string {
26
51
  const d = new Date(r.ts);
27
52
  const time = [
@@ -81,6 +106,10 @@ const showCommand: CommandDefinition = {
81
106
  ],
82
107
  },
83
108
  async execute(params, ctx) {
109
+ // Validate --limit up front so a bad value is rejected regardless of
110
+ // whether any sessions exist.
111
+ const limit = resolveTraceLimit(params.limit);
112
+
84
113
  const dir = traceDir();
85
114
  const sessions = listSessions(dir);
86
115
 
@@ -129,10 +158,7 @@ const showCommand: CommandDefinition = {
129
158
  return createOutputResult("", { plain: () => "" });
130
159
  }
131
160
 
132
- // Normal mode — read and format
133
- const limit =
134
- typeof params.limit === "string" ? Number.parseInt(params.limit, 10) : 50;
135
-
161
+ // Normal mode — read and format (limit validated at the top of execute).
136
162
  const records = readTraceLog({ path: target.path, limit });
137
163
  const data = { sessionId: target.sessionId, records };
138
164
 
package/src/index.ts CHANGED
@@ -43,8 +43,6 @@ export type {
43
43
  BlockDetailed,
44
44
  BlockDigest,
45
45
  BlockSummary,
46
- CategorySummary,
47
- CodeBlock,
48
46
  Disclosure,
49
47
  FilterConfig,
50
48
  InspectResult,
@@ -54,10 +52,7 @@ export type {
54
52
  OntologyProperty,
55
53
  OntologySummary,
56
54
  PredicateGroup,
57
- StandardDetailed,
58
- StandardListFilters,
59
55
  StandardRef,
60
- StandardSummary,
61
56
  TierEntry,
62
57
  TokenDetailed,
63
58
  TokenRef,
@@ -90,18 +85,11 @@ export {
90
85
  showOntology,
91
86
  showOntologyRaw,
92
87
  } from "./domains/ontology/operations/index.js";
88
+ export { listTiers } from "./domains/shared/listTiers.js";
93
89
  export {
94
90
  discoverSkills,
95
91
  listSkills,
96
92
  } from "./domains/skill/operations/index.js";
97
- export {
98
- listCategories,
99
- listStandards,
100
- lookupStandard,
101
- resolveStandardList,
102
- resolveStandardLookup,
103
- } from "./domains/standard/index.js";
104
- export { listTiers } from "./domains/tier/operations/index.js";
105
93
  export {
106
94
  listTokens,
107
95
  lookupToken,
@@ -1,7 +1,7 @@
1
1
  import type { Client } from "@modelcontextprotocol/sdk/client/index.js";
2
2
  import { afterAll, beforeAll, describe, expect, it } from "vitest";
3
3
  import { createTestMcpClient, createTestStore } from "#testing";
4
- import { P, PREFIX_MAP } from "../domains/shared/prefixes.js";
4
+ import { DEFAULT_PREFIX_MAP, P } from "../domains/shared/prefixes.js";
5
5
  import type { PragmaRuntime } from "../domains/shared/runtime.js";
6
6
  import createClientFromRuntime from "../testing/helpers/createTestMcpClient.js";
7
7
  import {
@@ -227,7 +227,7 @@ describe("resource listing — capping", () => {
227
227
  { length: overflow },
228
228
  (_, i) => `ds:widget_${i} a ds:Gadget ; ds:name "Widget ${i}" .`,
229
229
  ).join("\n");
230
- const ttl = `@prefix ds: <${PREFIX_MAP.ds}> .
230
+ const ttl = `@prefix ds: <${DEFAULT_PREFIX_MAP.ds}> .
231
231
  @prefix owl: <http://www.w3.org/2002/07/owl#> .
232
232
  @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
233
233
 
@@ -1,11 +1,11 @@
1
1
  import { describe, expect, it } from "vitest";
2
- import { PREFIX_MAP } from "../../domains/shared/prefixes.js";
2
+ import { DEFAULT_PREFIX_MAP } from "../../domains/shared/prefixes.js";
3
3
  import pickPrimaryType from "./pickPrimaryType.js";
4
4
 
5
- const COMPONENT = `${PREFIX_MAP.ds}Component`;
6
- const BLOCK = `${PREFIX_MAP.ds}Block`;
7
- const NAMED_INDIVIDUAL = `${PREFIX_MAP.owl}NamedIndividual`;
8
- const OWL_THING = `${PREFIX_MAP.owl}Thing`;
5
+ const COMPONENT = `${DEFAULT_PREFIX_MAP.ds}Component`;
6
+ const BLOCK = `${DEFAULT_PREFIX_MAP.ds}Block`;
7
+ const NAMED_INDIVIDUAL = `${DEFAULT_PREFIX_MAP.owl}NamedIndividual`;
8
+ const OWL_THING = `${DEFAULT_PREFIX_MAP.owl}Thing`;
9
9
 
10
10
  describe("pickPrimaryType", () => {
11
11
  it("returns null for no types", () => {
@@ -18,20 +18,26 @@ import { specs as orientationSpecs } from "../../domains/llm/mcp/index.js";
18
18
  import { specs as modifierSpecs } from "../../domains/modifier/mcp/index.js";
19
19
  import { specs as ontologySpecs } from "../../domains/ontology/mcp/index.js";
20
20
  import type { PragmaRuntime } from "../../domains/shared/runtime.js";
21
- import { compilePackToolSpecs } from "../../domains/shared/stories/pack/index.js";
21
+ import {
22
+ compilePackToolSpecs,
23
+ deriveReservedVerbs,
24
+ nounVerbFromToolName,
25
+ } from "../../domains/shared/stories/pack/index.js";
22
26
  import type { ToolSpec } from "../../domains/shared/ToolSpec.js";
23
27
  import { specs as skillSpecs } from "../../domains/skill/mcp/index.js";
24
- import { specs as standardSpecs } from "../../domains/standard/mcp/index.js";
25
- import { specs as tierSpecs } from "../../domains/tier/mcp/index.js";
26
28
  import { specs as tokenSpecs } from "../../domains/token/mcp/index.js";
27
29
  import registerFromSpec from "./registerFromSpec.js";
28
30
 
29
- const allSpecs: readonly ToolSpec[] = [
31
+ /**
32
+ * The full built-in MCP tool surface, in registration order.
33
+ *
34
+ * Exported so tests can derive the reserved-verb map from the identical
35
+ * array production consumes (see the cross-surface reservation invariant).
36
+ */
37
+ export const allSpecs: readonly ToolSpec[] = [
30
38
  ...blockSpecs,
31
- ...standardSpecs,
32
39
  ...modifierSpecs,
33
40
  ...tokenSpecs,
34
- ...tierSpecs,
35
41
  ...configSpecs,
36
42
  ...ontologySpecs,
37
43
  ...graphSpecs,
@@ -56,11 +62,13 @@ export default function registerAllTools(
56
62
  registerFromSpec(server, runtime, spec);
57
63
  }
58
64
 
59
- // Story packs project onto the same surface; built-in nouns are reserved.
60
- const reservedNouns = new Set(
61
- allSpecs.map((spec) => spec.name.split("_").at(0) ?? ""),
65
+ // Story packs project onto the same surface. Leaf read nouns reserve only
66
+ // the (noun, verb) pairs they own, so a pack can add a verb no built-in
67
+ // owns; operational nouns (config, graph, …) stay reserved wholesale.
68
+ const reserved = deriveReservedVerbs(
69
+ allSpecs.map((spec) => nounVerbFromToolName(spec.name)),
62
70
  );
63
- for (const spec of compilePackToolSpecs(runtime, reservedNouns)) {
71
+ for (const spec of compilePackToolSpecs(runtime, reserved)) {
64
72
  registerFromSpec(server, runtime, spec);
65
73
  }
66
74
  }