@canonical/pragma-cli 0.18.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.
- package/README.md +377 -0
- package/package.json +78 -0
- package/src/bin.test.ts +52 -0
- package/src/bin.ts +19 -0
- package/src/compile-validation.runner.ts +137 -0
- package/src/compile-validation.ts +192 -0
- package/src/completions/computeSocketPath.test.ts +26 -0
- package/src/completions/computeSocketPath.ts +16 -0
- package/src/completions/constants.ts +18 -0
- package/src/completions/handleQuery.test.ts +93 -0
- package/src/completions/handleQuery.ts +30 -0
- package/src/completions/index.ts +14 -0
- package/src/completions/queryCompletions.test.ts +100 -0
- package/src/completions/queryCompletions.ts +61 -0
- package/src/completions/querySocket.test.ts +70 -0
- package/src/completions/querySocket.ts +44 -0
- package/src/completions/startCompletionsServer.test.ts +74 -0
- package/src/completions/startCompletionsServer.ts +75 -0
- package/src/completions/startCompletionsServer.unit.test.ts +131 -0
- package/src/completions/waitForSocket.test.ts +27 -0
- package/src/completions/waitForSocket.ts +27 -0
- package/src/config/configExists.ts +14 -0
- package/src/config/index.ts +6 -0
- package/src/config/readConfig.test.ts +152 -0
- package/src/config/readConfig.ts +64 -0
- package/src/config/resolveConfigPath.test.ts +20 -0
- package/src/config/resolveConfigPath.ts +11 -0
- package/src/config/types.ts +26 -0
- package/src/config/writeConfig.ts +49 -0
- package/src/constants.ts +78 -0
- package/src/domains/block/blockConfig.ts +53 -0
- package/src/domains/block/commands/index.ts +4 -0
- package/src/domains/block/commands/list.test.ts +111 -0
- package/src/domains/block/commands/list.ts +69 -0
- package/src/domains/block/commands/lookup.test.ts +187 -0
- package/src/domains/block/commands/lookup.ts +199 -0
- package/src/domains/block/formatters/index.ts +4 -0
- package/src/domains/block/formatters/list.test.ts +107 -0
- package/src/domains/block/formatters/list.ts +64 -0
- package/src/domains/block/formatters/lookup.test.ts +317 -0
- package/src/domains/block/formatters/lookup.ts +354 -0
- package/src/domains/block/formatters/types.ts +16 -0
- package/src/domains/block/helpers/index.ts +4 -0
- package/src/domains/block/helpers/resolveAspects.test.ts +64 -0
- package/src/domains/block/helpers/resolveAspects.ts +35 -0
- package/src/domains/block/index.ts +25 -0
- package/src/domains/block/mcp/index.ts +2 -0
- package/src/domains/block/mcp/specs.ts +199 -0
- package/src/domains/block/operations/index.ts +4 -0
- package/src/domains/block/operations/list.test.ts +80 -0
- package/src/domains/block/operations/list.ts +72 -0
- package/src/domains/block/operations/lookup.test.ts +108 -0
- package/src/domains/block/operations/lookup.ts +359 -0
- package/src/domains/block/orchestration/blockEmptyError.ts +19 -0
- package/src/domains/block/orchestration/buildBlockFilters.ts +12 -0
- package/src/domains/block/orchestration/enrichBlocks.ts +37 -0
- package/src/domains/block/orchestration/index.ts +5 -0
- package/src/domains/block/orchestration/resolveBlockList.ts +39 -0
- package/src/domains/block/orchestration/resolveBlockLookup.ts +21 -0
- package/src/domains/block/types.ts +30 -0
- package/src/domains/config/commands/channel.test.ts +101 -0
- package/src/domains/config/commands/channel.ts +80 -0
- package/src/domains/config/commands/index.ts +4 -0
- package/src/domains/config/commands/show.test.ts +61 -0
- package/src/domains/config/commands/show.ts +51 -0
- package/src/domains/config/commands/tier.test.ts +84 -0
- package/src/domains/config/commands/tier.ts +78 -0
- package/src/domains/config/formatters/channel.test.ts +56 -0
- package/src/domains/config/formatters/channel.ts +34 -0
- package/src/domains/config/formatters/index.ts +4 -0
- package/src/domains/config/formatters/show.test.ts +126 -0
- package/src/domains/config/formatters/show.ts +66 -0
- package/src/domains/config/formatters/tier.test.ts +70 -0
- package/src/domains/config/formatters/tier.ts +40 -0
- package/src/domains/config/index.ts +23 -0
- package/src/domains/config/mcp/index.ts +2 -0
- package/src/domains/config/mcp/specs.ts +108 -0
- package/src/domains/config/operations/index.ts +5 -0
- package/src/domains/config/operations/show.test.ts +60 -0
- package/src/domains/config/operations/show.ts +42 -0
- package/src/domains/config/operations/types.ts +13 -0
- package/src/domains/config/operations/validateChannel.test.ts +36 -0
- package/src/domains/config/operations/validateChannel.ts +24 -0
- package/src/domains/config/operations/validateTier.test.ts +56 -0
- package/src/domains/config/operations/validateTier.ts +35 -0
- package/src/domains/create/commands/component.test.ts +166 -0
- package/src/domains/create/commands/component.ts +129 -0
- package/src/domains/create/commands/index.ts +3 -0
- package/src/domains/create/commands/package.test.ts +35 -0
- package/src/domains/create/commands/package.ts +21 -0
- package/src/domains/create/index.ts +15 -0
- package/src/domains/create/mcp/index.ts +2 -0
- package/src/domains/create/mcp/specs.ts +174 -0
- package/src/domains/doctor/commands/doctor.test.ts +75 -0
- package/src/domains/doctor/commands/doctor.ts +43 -0
- package/src/domains/doctor/commands/index.ts +2 -0
- package/src/domains/doctor/formatters/doctor.test.ts +117 -0
- package/src/domains/doctor/formatters/doctor.ts +84 -0
- package/src/domains/doctor/formatters/index.ts +2 -0
- package/src/domains/doctor/index.ts +9 -0
- package/src/domains/doctor/mcp/index.ts +2 -0
- package/src/domains/doctor/mcp/specs.ts +88 -0
- package/src/domains/doctor/operations/checks/checkConfigFile.ts +28 -0
- package/src/domains/doctor/operations/checks/checkKeStore.ts +38 -0
- package/src/domains/doctor/operations/checks/checkMcpConfigured.ts +65 -0
- package/src/domains/doctor/operations/checks/checkNodeVersion.ts +25 -0
- package/src/domains/doctor/operations/checks/checkPragmaVersion.ts +20 -0
- package/src/domains/doctor/operations/checks/checkShellCompletions.ts +42 -0
- package/src/domains/doctor/operations/checks/checkSkillsSymlinked.ts +64 -0
- package/src/domains/doctor/operations/checks/index.ts +8 -0
- package/src/domains/doctor/operations/checks.test.ts +151 -0
- package/src/domains/doctor/operations/index.ts +3 -0
- package/src/domains/doctor/operations/runChecks.test.ts +89 -0
- package/src/domains/doctor/operations/runChecks.ts +38 -0
- package/src/domains/doctor/operations/types.ts +20 -0
- package/src/domains/graph/commands/index.ts +4 -0
- package/src/domains/graph/commands/inspect.test.ts +94 -0
- package/src/domains/graph/commands/inspect.ts +63 -0
- package/src/domains/graph/commands/query.test.ts +92 -0
- package/src/domains/graph/commands/query.ts +60 -0
- package/src/domains/graph/formatters/index.ts +4 -0
- package/src/domains/graph/formatters/inspect.ts +45 -0
- package/src/domains/graph/formatters/query.ts +37 -0
- package/src/domains/graph/helpers/index.ts +3 -0
- package/src/domains/graph/helpers/resolveUri.ts +70 -0
- package/src/domains/graph/index.ts +22 -0
- package/src/domains/graph/mcp/index.ts +2 -0
- package/src/domains/graph/mcp/specs.ts +82 -0
- package/src/domains/graph/operations/executeQuery.test.ts +68 -0
- package/src/domains/graph/operations/executeQuery.ts +32 -0
- package/src/domains/graph/operations/index.ts +4 -0
- package/src/domains/graph/operations/inspectUri.test.ts +101 -0
- package/src/domains/graph/operations/inspectUri.ts +61 -0
- package/src/domains/info/commands/index.ts +4 -0
- package/src/domains/info/commands/info.test.ts +88 -0
- package/src/domains/info/commands/info.ts +47 -0
- package/src/domains/info/commands/upgrade.test.ts +183 -0
- package/src/domains/info/commands/upgrade.ts +150 -0
- package/src/domains/info/constants.test.ts +22 -0
- package/src/domains/info/constants.ts +15 -0
- package/src/domains/info/formatters/index.ts +8 -0
- package/src/domains/info/formatters/info.test.ts +173 -0
- package/src/domains/info/formatters/info.ts +116 -0
- package/src/domains/info/formatters/upgrade.test.ts +133 -0
- package/src/domains/info/formatters/upgrade.ts +68 -0
- package/src/domains/info/index.ts +7 -0
- package/src/domains/info/operations/checkRegistryVersion.test.ts +124 -0
- package/src/domains/info/operations/checkRegistryVersion.ts +45 -0
- package/src/domains/info/operations/collectInfo.test.ts +111 -0
- package/src/domains/info/operations/collectInfo.ts +68 -0
- package/src/domains/info/operations/collectStoreSummary.test.ts +61 -0
- package/src/domains/info/operations/collectStoreSummary.ts +42 -0
- package/src/domains/info/operations/index.ts +5 -0
- package/src/domains/info/types.test-d.ts +35 -0
- package/src/domains/info/types.ts +46 -0
- package/src/domains/llm/commands/index.ts +3 -0
- package/src/domains/llm/commands/llm.ts +37 -0
- package/src/domains/llm/data/commandReference.ts +25 -0
- package/src/domains/llm/data/decisionTrees.ts +46 -0
- package/src/domains/llm/data/index.ts +4 -0
- package/src/domains/llm/formatters/index.ts +3 -0
- package/src/domains/llm/formatters/orientation.ts +53 -0
- package/src/domains/llm/index.ts +8 -0
- package/src/domains/llm/llmCommand.test.ts +93 -0
- package/src/domains/llm/mcp/index.ts +2 -0
- package/src/domains/llm/mcp/specs.ts +87 -0
- package/src/domains/llm/operations/collectContext.ts +47 -0
- package/src/domains/llm/operations/index.ts +3 -0
- package/src/domains/llm/types.ts +32 -0
- package/src/domains/modifier/commands/index.ts +4 -0
- package/src/domains/modifier/commands/list.test.ts +57 -0
- package/src/domains/modifier/commands/list.ts +33 -0
- package/src/domains/modifier/commands/lookup.test.ts +91 -0
- package/src/domains/modifier/commands/lookup.ts +105 -0
- package/src/domains/modifier/formatters/index.ts +4 -0
- package/src/domains/modifier/formatters/list.test.ts +38 -0
- package/src/domains/modifier/formatters/list.ts +35 -0
- package/src/domains/modifier/formatters/lookup.test.ts +33 -0
- package/src/domains/modifier/formatters/lookup.ts +38 -0
- package/src/domains/modifier/index.ts +22 -0
- package/src/domains/modifier/mcp/index.ts +2 -0
- package/src/domains/modifier/mcp/specs.ts +97 -0
- package/src/domains/modifier/operations/index.ts +4 -0
- package/src/domains/modifier/operations/list.test.ts +39 -0
- package/src/domains/modifier/operations/list.ts +41 -0
- package/src/domains/modifier/operations/lookup.test.ts +37 -0
- package/src/domains/modifier/operations/lookup.ts +57 -0
- package/src/domains/modifier/orchestration/index.ts +3 -0
- package/src/domains/modifier/orchestration/modifierEmptyError.ts +10 -0
- package/src/domains/modifier/orchestration/resolveModifierList.ts +16 -0
- package/src/domains/modifier/orchestration/resolveModifierLookup.ts +20 -0
- package/src/domains/modifier/types.ts +5 -0
- package/src/domains/ontology/commands/index.ts +4 -0
- package/src/domains/ontology/commands/list.test.ts +82 -0
- package/src/domains/ontology/commands/list.ts +46 -0
- package/src/domains/ontology/commands/show.test.ts +103 -0
- package/src/domains/ontology/commands/show.ts +66 -0
- package/src/domains/ontology/formatters/index.ts +4 -0
- package/src/domains/ontology/formatters/list.ts +37 -0
- package/src/domains/ontology/formatters/show.ts +74 -0
- package/src/domains/ontology/helpers/findNamespace.ts +23 -0
- package/src/domains/ontology/helpers/index.ts +7 -0
- package/src/domains/ontology/helpers/queryClasses.ts +50 -0
- package/src/domains/ontology/helpers/queryProperties.ts +57 -0
- package/src/domains/ontology/helpers/resolvePrefix.ts +45 -0
- package/src/domains/ontology/index.ts +26 -0
- package/src/domains/ontology/mcp/index.ts +2 -0
- package/src/domains/ontology/mcp/specs.ts +93 -0
- package/src/domains/ontology/operations/index.ts +5 -0
- package/src/domains/ontology/operations/listOntologies.test.ts +45 -0
- package/src/domains/ontology/operations/listOntologies.ts +101 -0
- package/src/domains/ontology/operations/showOntology.test.ts +65 -0
- package/src/domains/ontology/operations/showOntology.ts +41 -0
- package/src/domains/ontology/operations/showOntologyRaw.test.ts +39 -0
- package/src/domains/ontology/operations/showOntologyRaw.ts +50 -0
- package/src/domains/setup/commands/all.ts +58 -0
- package/src/domains/setup/commands/completions.ts +85 -0
- package/src/domains/setup/commands/entrypoints.test.ts +170 -0
- package/src/domains/setup/commands/index.ts +6 -0
- package/src/domains/setup/commands/lsp.ts +49 -0
- package/src/domains/setup/commands/mcp.ts +119 -0
- package/src/domains/setup/commands/skills.test.ts +64 -0
- package/src/domains/setup/commands/skills.ts +106 -0
- package/src/domains/setup/formatters/index.ts +2 -0
- package/src/domains/setup/formatters/skills.test.ts +103 -0
- package/src/domains/setup/formatters/skills.ts +112 -0
- package/src/domains/setup/formatters/types.ts +7 -0
- package/src/domains/setup/helpers/completionScripts.test.ts +58 -0
- package/src/domains/setup/helpers/completionScripts.ts +92 -0
- package/src/domains/setup/helpers/constants.ts +2 -0
- package/src/domains/setup/helpers/detectShell.test.ts +48 -0
- package/src/domains/setup/helpers/detectShell.ts +20 -0
- package/src/domains/setup/helpers/index.ts +12 -0
- package/src/domains/setup/helpers/runSetupTask.test.ts +279 -0
- package/src/domains/setup/helpers/runSetupTask.ts +229 -0
- package/src/domains/setup/index.ts +33 -0
- package/src/domains/setup/operations/index.ts +6 -0
- package/src/domains/setup/operations/setupAll.test.ts +48 -0
- package/src/domains/setup/operations/setupAll.ts +41 -0
- package/src/domains/setup/operations/setupCompletions.test.ts +94 -0
- package/src/domains/setup/operations/setupCompletions.ts +54 -0
- package/src/domains/setup/operations/setupLsp.test.ts +29 -0
- package/src/domains/setup/operations/setupLsp.ts +17 -0
- package/src/domains/setup/operations/setupMcp.test.ts +115 -0
- package/src/domains/setup/operations/setupMcp.ts +108 -0
- package/src/domains/setup/operations/setupSkills.test.ts +191 -0
- package/src/domains/setup/operations/setupSkills.ts +160 -0
- package/src/domains/setup/types.ts +18 -0
- package/src/domains/shared/ToolSpec.ts +49 -0
- package/src/domains/shared/bootStore.ts +77 -0
- package/src/domains/shared/buildQuery.ts +18 -0
- package/src/domains/shared/compactUri.test.ts +21 -0
- package/src/domains/shared/compactUri.ts +16 -0
- package/src/domains/shared/context.ts +15 -0
- package/src/domains/shared/contracts.ts +113 -0
- package/src/domains/shared/extractLocalName.test.ts +21 -0
- package/src/domains/shared/extractLocalName.ts +14 -0
- package/src/domains/shared/filters/buildChannelFilter.test.ts +52 -0
- package/src/domains/shared/filters/buildChannelFilter.ts +41 -0
- package/src/domains/shared/filters/buildFilterConfig.ts +16 -0
- package/src/domains/shared/filters/buildFilters.test.ts +33 -0
- package/src/domains/shared/filters/buildFilters.ts +30 -0
- package/src/domains/shared/filters/buildTierFilter.test.ts +78 -0
- package/src/domains/shared/filters/buildTierFilter.ts +69 -0
- package/src/domains/shared/filters/describeFilters.ts +14 -0
- package/src/domains/shared/filters/index.ts +10 -0
- package/src/domains/shared/formatters.ts +35 -0
- package/src/domains/shared/lookupMany.ts +45 -0
- package/src/domains/shared/namespaces.ts +18 -0
- package/src/domains/shared/packages.ts +76 -0
- package/src/domains/shared/prefixes.ts +37 -0
- package/src/domains/shared/runtime.ts +62 -0
- package/src/domains/shared/types.test-d.ts +127 -0
- package/src/domains/shared/types.ts +348 -0
- package/src/domains/skill/commands/index.ts +2 -0
- package/src/domains/skill/commands/list.test.ts +111 -0
- package/src/domains/skill/commands/list.ts +69 -0
- package/src/domains/skill/formatters/index.ts +2 -0
- package/src/domains/skill/formatters/list.test.ts +140 -0
- package/src/domains/skill/formatters/list.ts +119 -0
- package/src/domains/skill/formatters/types.ts +8 -0
- package/src/domains/skill/helpers/index.ts +6 -0
- package/src/domains/skill/helpers/parseFrontmatter.test.ts +122 -0
- package/src/domains/skill/helpers/parseFrontmatter.ts +112 -0
- package/src/domains/skill/helpers/resolveSkillSources.ts +34 -0
- package/src/domains/skill/index.ts +19 -0
- package/src/domains/skill/mcp/index.ts +2 -0
- package/src/domains/skill/mcp/specs.ts +38 -0
- package/src/domains/skill/operations/discover.test.ts +145 -0
- package/src/domains/skill/operations/discover.ts +68 -0
- package/src/domains/skill/operations/index.ts +4 -0
- package/src/domains/skill/operations/list.test.ts +68 -0
- package/src/domains/skill/operations/list.ts +47 -0
- package/src/domains/skill/types.ts +25 -0
- package/src/domains/standard/commands/categories.test.ts +70 -0
- package/src/domains/standard/commands/categories.ts +48 -0
- package/src/domains/standard/commands/index.ts +5 -0
- package/src/domains/standard/commands/list.test.ts +105 -0
- package/src/domains/standard/commands/list.ts +81 -0
- package/src/domains/standard/commands/lookup.test.ts +135 -0
- package/src/domains/standard/commands/lookup.ts +127 -0
- package/src/domains/standard/formatters/categories.test.ts +44 -0
- package/src/domains/standard/formatters/categories.ts +38 -0
- package/src/domains/standard/formatters/index.ts +6 -0
- package/src/domains/standard/formatters/list.test.ts +166 -0
- package/src/domains/standard/formatters/list.ts +156 -0
- package/src/domains/standard/formatters/lookup.test.ts +95 -0
- package/src/domains/standard/formatters/lookup.ts +86 -0
- package/src/domains/standard/formatters/types.ts +31 -0
- package/src/domains/standard/index.ts +32 -0
- package/src/domains/standard/mcp/index.ts +2 -0
- package/src/domains/standard/mcp/specs.ts +197 -0
- package/src/domains/standard/operations/categories.test.ts +61 -0
- package/src/domains/standard/operations/categories.ts +38 -0
- package/src/domains/standard/operations/index.ts +5 -0
- package/src/domains/standard/operations/list.test.ts +75 -0
- package/src/domains/standard/operations/list.ts +64 -0
- package/src/domains/standard/operations/lookup.test.ts +58 -0
- package/src/domains/standard/operations/lookup.ts +142 -0
- package/src/domains/standard/orchestration/buildStandardFilters.ts +11 -0
- package/src/domains/standard/orchestration/index.ts +4 -0
- package/src/domains/standard/orchestration/resolveStandardList.ts +42 -0
- package/src/domains/standard/orchestration/resolveStandardLookup.ts +20 -0
- package/src/domains/standard/orchestration/standardEmptyError.ts +19 -0
- package/src/domains/standard/types.ts +15 -0
- package/src/domains/tier/commands/index.ts +3 -0
- package/src/domains/tier/commands/list.test.ts +67 -0
- package/src/domains/tier/commands/list.ts +43 -0
- package/src/domains/tier/formatters/index.ts +3 -0
- package/src/domains/tier/formatters/list.test.ts +33 -0
- package/src/domains/tier/formatters/list.ts +40 -0
- package/src/domains/tier/index.ts +17 -0
- package/src/domains/tier/mcp/index.ts +2 -0
- package/src/domains/tier/mcp/specs.ts +38 -0
- package/src/domains/tier/operations/index.ts +3 -0
- package/src/domains/tier/operations/list.test.ts +32 -0
- package/src/domains/tier/operations/list.ts +33 -0
- package/src/domains/token/commands/add-config.test.ts +68 -0
- package/src/domains/token/commands/add-config.ts +62 -0
- package/src/domains/token/commands/index.ts +5 -0
- package/src/domains/token/commands/list.test.ts +82 -0
- package/src/domains/token/commands/list.ts +45 -0
- package/src/domains/token/commands/lookup.test.ts +125 -0
- package/src/domains/token/commands/lookup.ts +121 -0
- package/src/domains/token/formatters/index.ts +4 -0
- package/src/domains/token/formatters/list.test.ts +37 -0
- package/src/domains/token/formatters/list.ts +37 -0
- package/src/domains/token/formatters/lookup.test.ts +61 -0
- package/src/domains/token/formatters/lookup.ts +72 -0
- package/src/domains/token/index.ts +32 -0
- package/src/domains/token/mcp/index.ts +2 -0
- package/src/domains/token/mcp/specs.ts +145 -0
- package/src/domains/token/operations/add-config.test.ts +68 -0
- package/src/domains/token/operations/add-config.ts +61 -0
- package/src/domains/token/operations/index.ts +7 -0
- package/src/domains/token/operations/list.test.ts +50 -0
- package/src/domains/token/operations/list.ts +52 -0
- package/src/domains/token/operations/lookup.test.ts +42 -0
- package/src/domains/token/operations/lookup.ts +66 -0
- package/src/domains/token/orchestration/index.ts +3 -0
- package/src/domains/token/orchestration/resolveTokenList.ts +17 -0
- package/src/domains/token/orchestration/resolveTokenLookup.ts +20 -0
- package/src/domains/token/orchestration/tokenEmptyError.ts +17 -0
- package/src/domains/token/types.ts +6 -0
- package/src/error/PragmaError.test.ts +121 -0
- package/src/error/PragmaError.ts +164 -0
- package/src/error/constants.ts +12 -0
- package/src/error/index.ts +4 -0
- package/src/error/types.ts +41 -0
- package/src/index.ts +141 -0
- package/src/mcp/createMcpServer.test.ts +41 -0
- package/src/mcp/createMcpServer.ts +53 -0
- package/src/mcp/error/buildRecovery.test.ts +37 -0
- package/src/mcp/error/buildRecovery.ts +17 -0
- package/src/mcp/error/index.ts +12 -0
- package/src/mcp/error/serializeError.test.ts +121 -0
- package/src/mcp/error/serializeError.ts +31 -0
- package/src/mcp/error/serializeErrorPayload.test.ts +38 -0
- package/src/mcp/error/serializeErrorPayload.ts +27 -0
- package/src/mcp/error/types.ts +51 -0
- package/src/mcp/index.ts +15 -0
- package/src/mcp/registerResources.test.ts +236 -0
- package/src/mcp/registerResources.ts +303 -0
- package/src/mcp/runMcpServer.test.ts +66 -0
- package/src/mcp/runMcpServer.ts +24 -0
- package/src/mcp/tools/index.ts +55 -0
- package/src/mcp/tools/registerFromSpec.ts +97 -0
- package/src/mcp/tools/registerTools.test.ts +1124 -0
- package/src/mcp/types.ts +62 -0
- package/src/mcp/utils/estimateTokens.test.ts +14 -0
- package/src/mcp/utils/estimateTokens.ts +9 -0
- package/src/mcp/utils/index.ts +11 -0
- package/src/mcp/utils/wrapTool.test.ts +108 -0
- package/src/mcp/utils/wrapTool.ts +81 -0
- package/src/package-manager/constants.ts +29 -0
- package/src/package-manager/detectInstallSource.test.ts +23 -0
- package/src/package-manager/detectInstallSource.ts +111 -0
- package/src/package-manager/detectLocalInstall.test.ts +16 -0
- package/src/package-manager/detectLocalInstall.ts +43 -0
- package/src/package-manager/detectPackageManager.test.ts +81 -0
- package/src/package-manager/detectPackageManager.ts +30 -0
- package/src/package-manager/index.ts +6 -0
- package/src/package-manager/types.ts +12 -0
- package/src/pipeline/collectCommands.test.ts +37 -0
- package/src/pipeline/collectCommands.ts +47 -0
- package/src/pipeline/constants.ts +14 -0
- package/src/pipeline/createProgram.test.ts +112 -0
- package/src/pipeline/createProgram.ts +70 -0
- package/src/pipeline/formatTerminal.test.ts +43 -0
- package/src/pipeline/formatTerminal.ts +53 -0
- package/src/pipeline/index.ts +19 -0
- package/src/pipeline/mapExitCode.test.ts +41 -0
- package/src/pipeline/mapExitCode.ts +12 -0
- package/src/pipeline/parseGlobalFlags.ts +21 -0
- package/src/pipeline/renderError.test.ts +151 -0
- package/src/pipeline/renderError.ts +114 -0
- package/src/pipeline/resolveCommandKind.test.ts +68 -0
- package/src/pipeline/resolveCommandKind.ts +71 -0
- package/src/pipeline/runCli.orchestration.test.ts +418 -0
- package/src/pipeline/runCli.test.ts +70 -0
- package/src/pipeline/runCli.ts +215 -0
- package/src/pipeline/types.ts +17 -0
- package/src/testing/cli.ts +43 -0
- package/src/testing/createTestMcpClient.ts +64 -0
- package/src/testing/dsFixtures.ts +506 -0
- package/src/testing/fixtures/canonical-config.json +4 -0
- package/src/testing/fixtures/canonical.ttl +437 -0
- package/src/testing/fixtures/filtered-config.json +4 -0
- package/src/testing/fixtures.ts +34 -0
- package/src/testing/helpers/assertParity.ts +28 -0
- package/src/testing/helpers/createTestMcpClient.ts +40 -0
- package/src/testing/helpers/createTestRuntime.ts +67 -0
- package/src/testing/index.ts +8 -0
- package/src/testing/integration/agent-session.test.ts +148 -0
- package/src/testing/integration/boot.test.ts +67 -0
- package/src/testing/integration/mcp-surface.test.ts +574 -0
- package/src/testing/integration/parity.test.ts +192 -0
- package/src/testing/store.ts +39 -0
- package/src/testing/types.ts +20 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { PragmaRuntime } from "../../shared/runtime.js";
|
|
2
|
+
import { listModifiers } from "../operations/index.js";
|
|
3
|
+
import type { ModifierListResolution } from "../types.js";
|
|
4
|
+
import modifierEmptyError from "./modifierEmptyError.js";
|
|
5
|
+
|
|
6
|
+
export default async function resolveModifierList(
|
|
7
|
+
rt: Pick<PragmaRuntime, "store">,
|
|
8
|
+
): Promise<ModifierListResolution> {
|
|
9
|
+
const items = await listModifiers(rt.store);
|
|
10
|
+
|
|
11
|
+
if (items.length === 0) {
|
|
12
|
+
throw modifierEmptyError();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return { items };
|
|
16
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { LookupContract, LookupResult } from "../../shared/contracts.js";
|
|
2
|
+
import lookupMany from "../../shared/lookupMany.js";
|
|
3
|
+
import type { PragmaRuntime } from "../../shared/runtime.js";
|
|
4
|
+
import type { ModifierFamily } from "../../shared/types.js";
|
|
5
|
+
import { lookupModifier } from "../operations/index.js";
|
|
6
|
+
|
|
7
|
+
export default async function resolveModifierLookup(
|
|
8
|
+
store: Pick<PragmaRuntime, "store">["store"],
|
|
9
|
+
queries: readonly string[],
|
|
10
|
+
): Promise<LookupContract<ModifierFamily>> {
|
|
11
|
+
const result: LookupResult<ModifierFamily> = await lookupMany(
|
|
12
|
+
queries,
|
|
13
|
+
(query) => lookupModifier(store, query),
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
params: { names: queries },
|
|
18
|
+
result,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { CommandDefinition } from "@canonical/cli-core";
|
|
2
|
+
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
3
|
+
import createTestRuntime from "../../../testing/helpers/createTestRuntime.js";
|
|
4
|
+
import type { PragmaContext } from "../../shared/context.js";
|
|
5
|
+
import type { PragmaRuntime } from "../../shared/runtime.js";
|
|
6
|
+
import type { OntologySummary } from "../../shared/types.js";
|
|
7
|
+
import buildListCommand from "./list.js";
|
|
8
|
+
|
|
9
|
+
let runtime: PragmaRuntime;
|
|
10
|
+
|
|
11
|
+
beforeAll(async () => {
|
|
12
|
+
runtime = await createTestRuntime();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
afterAll(() => {
|
|
16
|
+
runtime.dispose();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
function makeCtx(overrides: Partial<PragmaContext> = {}): PragmaContext {
|
|
20
|
+
return {
|
|
21
|
+
...runtime,
|
|
22
|
+
globalFlags: { llm: false, format: "text" as const, verbose: false },
|
|
23
|
+
...overrides,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function executeOutput(
|
|
28
|
+
cmd: CommandDefinition,
|
|
29
|
+
params: Record<string, unknown>,
|
|
30
|
+
ctx: PragmaContext,
|
|
31
|
+
): Promise<{ value: unknown; text: string }> {
|
|
32
|
+
const result = await cmd.execute(params, ctx);
|
|
33
|
+
expect(result.tag).toBe("output");
|
|
34
|
+
if (result.tag !== "output") throw new Error("Expected output result");
|
|
35
|
+
return { value: result.value, text: result.render.plain(result.value) };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
describe("ontology list command", () => {
|
|
39
|
+
it("returns ontology summaries", async () => {
|
|
40
|
+
const ctx = makeCtx();
|
|
41
|
+
const cmd = buildListCommand(ctx);
|
|
42
|
+
const { value } = await executeOutput(cmd, {}, ctx);
|
|
43
|
+
|
|
44
|
+
const prefixes = (value as OntologySummary[]).map((item) => item.prefix);
|
|
45
|
+
expect(prefixes).toContain("ds");
|
|
46
|
+
expect(prefixes).toContain("cs");
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("renders plain output", async () => {
|
|
50
|
+
const ctx = makeCtx();
|
|
51
|
+
const cmd = buildListCommand(ctx);
|
|
52
|
+
const { text } = await executeOutput(cmd, {}, ctx);
|
|
53
|
+
|
|
54
|
+
expect(text).toContain("ds");
|
|
55
|
+
expect(text).toContain("classes:");
|
|
56
|
+
expect(text).toContain("anatomy:");
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("renders llm output", async () => {
|
|
60
|
+
const ctx = makeCtx({
|
|
61
|
+
globalFlags: { llm: true, format: "text" as const, verbose: false },
|
|
62
|
+
});
|
|
63
|
+
const cmd = buildListCommand(ctx);
|
|
64
|
+
const { text } = await executeOutput(cmd, {}, ctx);
|
|
65
|
+
|
|
66
|
+
expect(text).toContain("## Ontologies");
|
|
67
|
+
expect(text).toContain("**ds:**");
|
|
68
|
+
expect(text).toContain("anatomy:");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("renders json output", async () => {
|
|
72
|
+
const ctx = makeCtx({
|
|
73
|
+
globalFlags: { llm: false, format: "json" as const, verbose: false },
|
|
74
|
+
});
|
|
75
|
+
const cmd = buildListCommand(ctx);
|
|
76
|
+
const { text } = await executeOutput(cmd, {}, ctx);
|
|
77
|
+
|
|
78
|
+
const parsed = JSON.parse(text) as OntologySummary[];
|
|
79
|
+
expect(Array.isArray(parsed)).toBe(true);
|
|
80
|
+
expect(parsed.some((item) => item.prefix === "ds")).toBe(true);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type CommandDefinition,
|
|
3
|
+
type CommandResult,
|
|
4
|
+
createOutputResult,
|
|
5
|
+
} from "@canonical/cli-core";
|
|
6
|
+
import { PragmaError } from "#error";
|
|
7
|
+
import type { PragmaContext } from "../../shared/context.js";
|
|
8
|
+
import { selectFormatter } from "../../shared/formatters.js";
|
|
9
|
+
import { listFormatters } from "../formatters/index.js";
|
|
10
|
+
import { listOntologies } from "../operations/index.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Builds the `pragma ontology list` command definition.
|
|
14
|
+
*
|
|
15
|
+
* Lists all loaded ontology namespaces with class and property counts.
|
|
16
|
+
*
|
|
17
|
+
* @param ctx - Pragma runtime context providing the ke store and config.
|
|
18
|
+
* @returns A command definition for `ontology list`.
|
|
19
|
+
*/
|
|
20
|
+
export default function buildListCommand(
|
|
21
|
+
ctx: PragmaContext,
|
|
22
|
+
): CommandDefinition {
|
|
23
|
+
return {
|
|
24
|
+
path: ["ontology", "list"],
|
|
25
|
+
description: "List loaded ontologies",
|
|
26
|
+
parameters: [],
|
|
27
|
+
meta: {
|
|
28
|
+
examples: ["pragma ontology list", "pragma ontology list --llm"],
|
|
29
|
+
},
|
|
30
|
+
execute: async (): Promise<CommandResult> => {
|
|
31
|
+
const ontologies = await listOntologies(ctx.store);
|
|
32
|
+
|
|
33
|
+
if (ontologies.length === 0) {
|
|
34
|
+
throw PragmaError.emptyResults("ontology", {
|
|
35
|
+
recovery: {
|
|
36
|
+
message: "Ensure design system packages are installed.",
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return createOutputResult(ontologies, {
|
|
42
|
+
plain: selectFormatter(ctx, listFormatters),
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { CommandDefinition } from "@canonical/cli-core";
|
|
2
|
+
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
3
|
+
import createTestRuntime from "../../../testing/helpers/createTestRuntime.js";
|
|
4
|
+
import type { PragmaContext } from "../../shared/context.js";
|
|
5
|
+
import type { PragmaRuntime } from "../../shared/runtime.js";
|
|
6
|
+
import type { OntologyDetailed } from "../../shared/types.js";
|
|
7
|
+
import buildShowCommand from "./show.js";
|
|
8
|
+
|
|
9
|
+
let runtime: PragmaRuntime;
|
|
10
|
+
|
|
11
|
+
beforeAll(async () => {
|
|
12
|
+
runtime = await createTestRuntime();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
afterAll(() => {
|
|
16
|
+
runtime.dispose();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
function makeCtx(overrides: Partial<PragmaContext> = {}): PragmaContext {
|
|
20
|
+
return {
|
|
21
|
+
...runtime,
|
|
22
|
+
globalFlags: { llm: false, format: "text" as const, verbose: false },
|
|
23
|
+
...overrides,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function executeOutput(
|
|
28
|
+
cmd: CommandDefinition,
|
|
29
|
+
params: Record<string, unknown>,
|
|
30
|
+
ctx: PragmaContext,
|
|
31
|
+
): Promise<{ value: unknown; text: string }> {
|
|
32
|
+
const result = await cmd.execute(params, ctx);
|
|
33
|
+
expect(result.tag).toBe("output");
|
|
34
|
+
if (result.tag !== "output") throw new Error("Expected output result");
|
|
35
|
+
return { value: result.value, text: result.render.plain(result.value) };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
describe("ontology show command", () => {
|
|
39
|
+
it("returns ontology details", async () => {
|
|
40
|
+
const ctx = makeCtx();
|
|
41
|
+
const cmd = buildShowCommand(ctx);
|
|
42
|
+
const { value } = await executeOutput(cmd, { prefix: "ds" }, ctx);
|
|
43
|
+
|
|
44
|
+
const result = value as OntologyDetailed;
|
|
45
|
+
expect(result.prefix).toBe("ds");
|
|
46
|
+
expect(result.classes.length).toBeGreaterThan(0);
|
|
47
|
+
expect(result.properties.length).toBeGreaterThan(0);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("completes ontology prefixes", async () => {
|
|
51
|
+
const ctx = makeCtx();
|
|
52
|
+
const cmd = buildShowCommand(ctx);
|
|
53
|
+
const complete = cmd.parameters[0]?.complete;
|
|
54
|
+
|
|
55
|
+
expect(complete).toBeTypeOf("function");
|
|
56
|
+
const matches = await complete?.("d", ctx);
|
|
57
|
+
expect(matches).toContain("ds");
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("renders plain output", async () => {
|
|
61
|
+
const ctx = makeCtx();
|
|
62
|
+
const cmd = buildShowCommand(ctx);
|
|
63
|
+
const { text } = await executeOutput(cmd, { prefix: "ds" }, ctx);
|
|
64
|
+
|
|
65
|
+
expect(text).toContain("Classes");
|
|
66
|
+
expect(text).toContain("Properties");
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("renders llm output", async () => {
|
|
70
|
+
const ctx = makeCtx({
|
|
71
|
+
globalFlags: { llm: true, format: "text" as const, verbose: false },
|
|
72
|
+
});
|
|
73
|
+
const cmd = buildShowCommand(ctx);
|
|
74
|
+
const { text } = await executeOutput(cmd, { prefix: "ds" }, ctx);
|
|
75
|
+
|
|
76
|
+
expect(text).toContain("## ds:");
|
|
77
|
+
expect(text).toContain("### Classes");
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("renders json output", async () => {
|
|
81
|
+
const ctx = makeCtx({
|
|
82
|
+
globalFlags: { llm: false, format: "json" as const, verbose: false },
|
|
83
|
+
});
|
|
84
|
+
const cmd = buildShowCommand(ctx);
|
|
85
|
+
const { text } = await executeOutput(cmd, { prefix: "ds" }, ctx);
|
|
86
|
+
|
|
87
|
+
const parsed = JSON.parse(text) as OntologyDetailed;
|
|
88
|
+
expect(parsed.prefix).toBe("ds");
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("throws structured error when prefix is missing", async () => {
|
|
92
|
+
const ctx = makeCtx();
|
|
93
|
+
const cmd = buildShowCommand(ctx);
|
|
94
|
+
|
|
95
|
+
await expect(cmd.execute({}, ctx)).rejects.toMatchObject({
|
|
96
|
+
code: "INVALID_INPUT",
|
|
97
|
+
recovery: {
|
|
98
|
+
cli: "pragma ontology list",
|
|
99
|
+
mcp: { tool: "ontology_list" },
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type CommandDefinition,
|
|
3
|
+
type CommandResult,
|
|
4
|
+
createOutputResult,
|
|
5
|
+
} from "@canonical/cli-core";
|
|
6
|
+
import { PragmaError } from "#error";
|
|
7
|
+
import type { PragmaContext } from "../../shared/context.js";
|
|
8
|
+
import { selectFormatter } from "../../shared/formatters.js";
|
|
9
|
+
import { showFormatters } from "../formatters/index.js";
|
|
10
|
+
import { listOntologies, showOntology } from "../operations/index.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Builds the `pragma ontology show` command definition.
|
|
14
|
+
*
|
|
15
|
+
* Displays detailed schema (classes and properties) for a given ontology
|
|
16
|
+
* prefix. Provides tab-completion for the prefix parameter.
|
|
17
|
+
*
|
|
18
|
+
* @param ctx - Pragma runtime context providing the ke store and config.
|
|
19
|
+
* @returns A command definition for `ontology show`.
|
|
20
|
+
*/
|
|
21
|
+
export default function buildShowCommand(
|
|
22
|
+
ctx: PragmaContext,
|
|
23
|
+
): CommandDefinition {
|
|
24
|
+
return {
|
|
25
|
+
path: ["ontology", "show"],
|
|
26
|
+
description: "Show ontology schema details",
|
|
27
|
+
parameters: [
|
|
28
|
+
{
|
|
29
|
+
name: "prefix",
|
|
30
|
+
description: "Ontology prefix (e.g. 'ds', 'cs')",
|
|
31
|
+
type: "string",
|
|
32
|
+
positional: true,
|
|
33
|
+
required: true,
|
|
34
|
+
complete: async (partial: string) => {
|
|
35
|
+
const all = await listOntologies(ctx.store);
|
|
36
|
+
return all
|
|
37
|
+
.map((o) => o.prefix)
|
|
38
|
+
.filter((p) => p.toLowerCase().startsWith(partial.toLowerCase()));
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
meta: {
|
|
43
|
+
examples: ["pragma ontology show ds", "pragma ontology show cs --llm"],
|
|
44
|
+
},
|
|
45
|
+
execute: async (
|
|
46
|
+
params: Record<string, unknown>,
|
|
47
|
+
): Promise<CommandResult> => {
|
|
48
|
+
const prefix = params.prefix as string;
|
|
49
|
+
if (!prefix) {
|
|
50
|
+
throw PragmaError.invalidInput("prefix", "(empty)", {
|
|
51
|
+
recovery: {
|
|
52
|
+
message: "List loaded ontologies to find valid prefixes.",
|
|
53
|
+
cli: "pragma ontology list",
|
|
54
|
+
mcp: { tool: "ontology_list" },
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const result = await showOntology(ctx.store, prefix);
|
|
60
|
+
|
|
61
|
+
return createOutputResult(result, {
|
|
62
|
+
plain: selectFormatter(ctx, showFormatters),
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import type { Formatters } from "../../shared/formatters.js";
|
|
3
|
+
import type { OntologySummary } from "../../shared/types.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Formatters for `pragma ontology list` output.
|
|
7
|
+
*
|
|
8
|
+
* - **plain**: one line per ontology with chalk-styled prefix, namespace, and counts.
|
|
9
|
+
* - **llm**: condensed Markdown bullet list under an `## Ontologies` heading.
|
|
10
|
+
* - **json**: serialized ontology summary array as indented JSON.
|
|
11
|
+
*/
|
|
12
|
+
const formatters: Formatters<readonly OntologySummary[]> = {
|
|
13
|
+
plain(ontologies) {
|
|
14
|
+
return ontologies
|
|
15
|
+
.map(
|
|
16
|
+
(o) =>
|
|
17
|
+
`${chalk.bold(o.prefix)} ${chalk.dim(`(${o.namespace})`)} classes: ${o.classCount} properties: ${o.propertyCount} anatomy: ${o.anatomyCount}`,
|
|
18
|
+
)
|
|
19
|
+
.join("\n");
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
llm(ontologies) {
|
|
23
|
+
const lines = ["## Ontologies", ""];
|
|
24
|
+
for (const o of ontologies) {
|
|
25
|
+
lines.push(
|
|
26
|
+
`- **${o.prefix}:** (${o.namespace}) | classes: ${o.classCount} | properties: ${o.propertyCount} | anatomy: ${o.anatomyCount}`,
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
return lines.join("\n");
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
json(ontologies) {
|
|
33
|
+
return JSON.stringify(ontologies, null, 2);
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export default formatters;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { formatHeading, formatSection } from "#pipeline";
|
|
3
|
+
import type { Formatters } from "../../shared/formatters.js";
|
|
4
|
+
import type { OntologyDetailed } from "../../shared/types.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Formatters for `pragma ontology show` output.
|
|
8
|
+
*
|
|
9
|
+
* - **plain**: chalk-styled heading with Classes and Properties sections.
|
|
10
|
+
* - **llm**: condensed Markdown with `### Classes` and `### Properties` sub-headings.
|
|
11
|
+
* - **json**: serialized {@link OntologyDetailed} as indented JSON.
|
|
12
|
+
*/
|
|
13
|
+
const formatters: Formatters<OntologyDetailed> = {
|
|
14
|
+
plain(data) {
|
|
15
|
+
const lines: string[] = [];
|
|
16
|
+
|
|
17
|
+
lines.push(formatHeading(`${data.prefix}: (${data.namespace})`));
|
|
18
|
+
|
|
19
|
+
if (data.classes.length > 0) {
|
|
20
|
+
const classLines = data.classes
|
|
21
|
+
.map((c) => {
|
|
22
|
+
const sup = c.superclass ? chalk.dim(` extends ${c.superclass}`) : "";
|
|
23
|
+
return ` ${chalk.bold(c.label)}${sup}`;
|
|
24
|
+
})
|
|
25
|
+
.join("\n");
|
|
26
|
+
lines.push("");
|
|
27
|
+
lines.push(formatSection("Classes", classLines));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (data.properties.length > 0) {
|
|
31
|
+
const propLines = data.properties
|
|
32
|
+
.map((p) => {
|
|
33
|
+
const domain = p.domain ? chalk.dim(` domain: ${p.domain}`) : "";
|
|
34
|
+
const range = p.range ? chalk.dim(` range: ${p.range}`) : "";
|
|
35
|
+
return ` ${chalk.bold(p.label)} (${p.type})${domain}${range}`;
|
|
36
|
+
})
|
|
37
|
+
.join("\n");
|
|
38
|
+
lines.push("");
|
|
39
|
+
lines.push(formatSection("Properties", propLines));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return lines.join("\n");
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
llm(data) {
|
|
46
|
+
const lines = [`## ${data.prefix}: (${data.namespace})`, ""];
|
|
47
|
+
|
|
48
|
+
if (data.classes.length > 0) {
|
|
49
|
+
lines.push("### Classes");
|
|
50
|
+
for (const c of data.classes) {
|
|
51
|
+
const sup = c.superclass ? ` extends ${c.superclass}` : "";
|
|
52
|
+
lines.push(`- **${c.label}**${sup}`);
|
|
53
|
+
}
|
|
54
|
+
lines.push("");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (data.properties.length > 0) {
|
|
58
|
+
lines.push("### Properties");
|
|
59
|
+
for (const p of data.properties) {
|
|
60
|
+
const domain = p.domain ? ` domain: ${p.domain}` : "";
|
|
61
|
+
const range = p.range ? ` range: ${p.range}` : "";
|
|
62
|
+
lines.push(`- **${p.label}** (${p.type})${domain}${range}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return lines.join("\n");
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
json(data) {
|
|
70
|
+
return JSON.stringify(data, null, 2);
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export default formatters;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds the namespace prefix for a given URI by matching against registered
|
|
3
|
+
* prefix entries. When multiple prefixes match, selects the longest
|
|
4
|
+
* (most specific) namespace.
|
|
5
|
+
*
|
|
6
|
+
* @param uri - The full URI to look up.
|
|
7
|
+
* @param prefixEntries - Array of `[prefix, namespace]` tuples from the store.
|
|
8
|
+
* @returns The matching `{ prefix, namespace }` or `undefined` if no prefix matches.
|
|
9
|
+
*/
|
|
10
|
+
export default function findNamespace(
|
|
11
|
+
uri: string,
|
|
12
|
+
prefixEntries: [string, string][],
|
|
13
|
+
): { prefix: string; namespace: string } | undefined {
|
|
14
|
+
let best: { prefix: string; namespace: string } | undefined;
|
|
15
|
+
for (const [prefix, namespace] of prefixEntries) {
|
|
16
|
+
if (uri.startsWith(namespace)) {
|
|
17
|
+
if (!best || namespace.length > best.namespace.length) {
|
|
18
|
+
best = { prefix, namespace };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return best;
|
|
23
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** @module Barrel for ontology helpers. */
|
|
2
|
+
|
|
3
|
+
export { default as extractLocalName } from "../../shared/extractLocalName.js";
|
|
4
|
+
export { default as findNamespace } from "./findNamespace.js";
|
|
5
|
+
export { default as queryClasses } from "./queryClasses.js";
|
|
6
|
+
export { default as queryProperties } from "./queryProperties.js";
|
|
7
|
+
export { default as resolvePrefix } from "./resolvePrefix.js";
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Store } from "@canonical/ke";
|
|
2
|
+
import { buildQuery } from "../../shared/buildQuery.js";
|
|
3
|
+
import extractLocalName from "../../shared/extractLocalName.js";
|
|
4
|
+
import { P } from "../../shared/prefixes.js";
|
|
5
|
+
import type { OntologyClass } from "../../shared/types.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Queries all `owl:Class` definitions within a namespace.
|
|
9
|
+
*
|
|
10
|
+
* Deduplicates by class URI -- when a class has multiple `rdfs:subClassOf`
|
|
11
|
+
* values, only the first superclass encountered is kept.
|
|
12
|
+
*
|
|
13
|
+
* @note Queries ke store
|
|
14
|
+
*
|
|
15
|
+
* @param store - The ke store to query.
|
|
16
|
+
* @param namespace - The namespace URI to filter classes by.
|
|
17
|
+
* @returns An array of {@link OntologyClass} entries.
|
|
18
|
+
*/
|
|
19
|
+
export default async function queryClasses(
|
|
20
|
+
store: Store,
|
|
21
|
+
namespace: string,
|
|
22
|
+
): Promise<OntologyClass[]> {
|
|
23
|
+
const result = await store.query(
|
|
24
|
+
buildQuery(`
|
|
25
|
+
SELECT ?class ?label ?superclass
|
|
26
|
+
WHERE {
|
|
27
|
+
?class a ${P.owl}Class .
|
|
28
|
+
FILTER(STRSTARTS(STR(?class), "${namespace}"))
|
|
29
|
+
OPTIONAL { ?class ${P.rdfs}label ?label }
|
|
30
|
+
OPTIONAL { ?class ${P.rdfs}subClassOf ?superclass }
|
|
31
|
+
}
|
|
32
|
+
ORDER BY ?class
|
|
33
|
+
`),
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
if (result.type !== "select") return [];
|
|
37
|
+
|
|
38
|
+
const seen = new Map<string, OntologyClass>();
|
|
39
|
+
for (const b of result.bindings) {
|
|
40
|
+
const uri = b.class ?? "";
|
|
41
|
+
if (seen.has(uri)) continue;
|
|
42
|
+
seen.set(uri, {
|
|
43
|
+
uri,
|
|
44
|
+
label: b.label ?? extractLocalName(uri),
|
|
45
|
+
...(b.superclass ? { superclass: b.superclass } : {}),
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return [...seen.values()];
|
|
50
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Store } from "@canonical/ke";
|
|
2
|
+
import { buildQuery } from "../../shared/buildQuery.js";
|
|
3
|
+
import extractLocalName from "../../shared/extractLocalName.js";
|
|
4
|
+
import { P } from "../../shared/prefixes.js";
|
|
5
|
+
import type { OntologyProperty } from "../../shared/types.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Queries all `owl:ObjectProperty` and `owl:DatatypeProperty` definitions
|
|
9
|
+
* within a namespace.
|
|
10
|
+
*
|
|
11
|
+
* Deduplicates by property URI -- when a property has multiple `rdfs:domain`
|
|
12
|
+
* or `rdfs:range` values, only the first encountered is kept.
|
|
13
|
+
*
|
|
14
|
+
* @note Queries ke store
|
|
15
|
+
*
|
|
16
|
+
* @param store - The ke store to query.
|
|
17
|
+
* @param namespace - The namespace URI to filter properties by.
|
|
18
|
+
* @returns An array of {@link OntologyProperty} entries.
|
|
19
|
+
*/
|
|
20
|
+
export default async function queryProperties(
|
|
21
|
+
store: Store,
|
|
22
|
+
namespace: string,
|
|
23
|
+
): Promise<OntologyProperty[]> {
|
|
24
|
+
const result = await store.query(
|
|
25
|
+
buildQuery(`
|
|
26
|
+
SELECT ?prop ?label ?domain ?range ?propType
|
|
27
|
+
WHERE {
|
|
28
|
+
?prop a ?propType .
|
|
29
|
+
VALUES ?propType { ${P.owl}ObjectProperty ${P.owl}DatatypeProperty }
|
|
30
|
+
FILTER(STRSTARTS(STR(?prop), "${namespace}"))
|
|
31
|
+
OPTIONAL { ?prop ${P.rdfs}label ?label }
|
|
32
|
+
OPTIONAL { ?prop ${P.rdfs}domain ?domain }
|
|
33
|
+
OPTIONAL { ?prop ${P.rdfs}range ?range }
|
|
34
|
+
}
|
|
35
|
+
ORDER BY ?prop
|
|
36
|
+
`),
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
if (result.type !== "select") return [];
|
|
40
|
+
|
|
41
|
+
const seen = new Map<string, OntologyProperty>();
|
|
42
|
+
for (const b of result.bindings) {
|
|
43
|
+
const uri = b.prop ?? "";
|
|
44
|
+
if (seen.has(uri)) continue;
|
|
45
|
+
seen.set(uri, {
|
|
46
|
+
uri,
|
|
47
|
+
label: b.label ?? extractLocalName(uri),
|
|
48
|
+
...(b.domain ? { domain: b.domain } : {}),
|
|
49
|
+
...(b.range ? { range: b.range } : {}),
|
|
50
|
+
type: b.propType?.includes("ObjectProperty")
|
|
51
|
+
? ("object" as const)
|
|
52
|
+
: ("datatype" as const),
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return [...seen.values()];
|
|
57
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { PragmaError } from "#error";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Resolves a prefix string or full namespace URI to both prefix and namespace.
|
|
5
|
+
*
|
|
6
|
+
* Accepts either a short prefix (e.g. `ds`) or a full namespace URI
|
|
7
|
+
* (e.g. `https://ds.canonical.com/`) and returns the matching pair.
|
|
8
|
+
*
|
|
9
|
+
* @param prefixOrUri - A short prefix or full namespace URI.
|
|
10
|
+
* @param prefixes - Registered prefix-to-namespace mapping from the store.
|
|
11
|
+
* @returns An object with `prefix` and `namespace` strings.
|
|
12
|
+
* @throws PragmaError.invalidInput if the prefix or namespace is unknown.
|
|
13
|
+
*/
|
|
14
|
+
export default function resolvePrefix(
|
|
15
|
+
prefixOrUri: string,
|
|
16
|
+
prefixes: Readonly<Record<string, string>>,
|
|
17
|
+
): { prefix: string; namespace: string } {
|
|
18
|
+
if (prefixOrUri.startsWith("http://") || prefixOrUri.startsWith("https://")) {
|
|
19
|
+
const entry = Object.entries(prefixes).find(([, ns]) => ns === prefixOrUri);
|
|
20
|
+
if (entry) return { prefix: entry[0], namespace: entry[1] };
|
|
21
|
+
|
|
22
|
+
throw PragmaError.invalidInput("namespace", prefixOrUri, {
|
|
23
|
+
validOptions: Object.values(prefixes),
|
|
24
|
+
recovery: {
|
|
25
|
+
message: "List loaded ontology namespaces.",
|
|
26
|
+
cli: "pragma ontology list",
|
|
27
|
+
mcp: { tool: "ontology_list" },
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const namespace = prefixes[prefixOrUri];
|
|
33
|
+
if (namespace === undefined) {
|
|
34
|
+
throw PragmaError.invalidInput("prefix", prefixOrUri, {
|
|
35
|
+
validOptions: Object.keys(prefixes),
|
|
36
|
+
recovery: {
|
|
37
|
+
message: "List loaded ontologies.",
|
|
38
|
+
cli: "pragma ontology list",
|
|
39
|
+
mcp: { tool: "ontology_list" },
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return { prefix: prefixOrUri, namespace };
|
|
45
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Ontology domain barrel.
|
|
3
|
+
*
|
|
4
|
+
* Provides ontology listing, detailed schema inspection, and raw triple retrieval.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { CommandDefinition } from "@canonical/cli-core";
|
|
8
|
+
import type { PragmaContext } from "../shared/context.js";
|
|
9
|
+
import { listCommand, showCommand } from "./commands/index.js";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Returns all command definitions for the ontology domain.
|
|
13
|
+
*
|
|
14
|
+
* @param ctx - Pragma runtime context.
|
|
15
|
+
* @returns An array of command definitions (`ontology list`, `ontology show`).
|
|
16
|
+
*/
|
|
17
|
+
export function commands(ctx: PragmaContext): CommandDefinition[] {
|
|
18
|
+
return [listCommand(ctx), showCommand(ctx)];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { specs as mcpSpecs } from "./mcp/index.js";
|
|
22
|
+
export {
|
|
23
|
+
listOntologies,
|
|
24
|
+
showOntology,
|
|
25
|
+
showOntologyRaw,
|
|
26
|
+
} from "./operations/index.js";
|