@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,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compile-time type tests for info + upgrade domain types.
|
|
3
|
+
*
|
|
4
|
+
* Checked by `tsc --noEmit`, not executed at runtime.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { expectTypeOf } from "expect-type";
|
|
8
|
+
import type {
|
|
9
|
+
InfoData,
|
|
10
|
+
RegistryCheckResult,
|
|
11
|
+
StoreSummary,
|
|
12
|
+
UpgradeData,
|
|
13
|
+
} from "./types.js";
|
|
14
|
+
|
|
15
|
+
// InfoData
|
|
16
|
+
expectTypeOf<InfoData["version"]>().toBeString();
|
|
17
|
+
expectTypeOf<InfoData["pm"]>().toBeString();
|
|
18
|
+
expectTypeOf<InfoData["tier"]>().toEqualTypeOf<string | undefined>();
|
|
19
|
+
expectTypeOf<InfoData["tierChain"]>().toEqualTypeOf<readonly string[]>();
|
|
20
|
+
expectTypeOf<InfoData["updateSkipped"]>().toBeBoolean();
|
|
21
|
+
|
|
22
|
+
// UpgradeData
|
|
23
|
+
expectTypeOf<UpgradeData["current"]>().toBeString();
|
|
24
|
+
expectTypeOf<UpgradeData["latest"]>().toEqualTypeOf<string | undefined>();
|
|
25
|
+
expectTypeOf<UpgradeData["dryRun"]>().toBeBoolean();
|
|
26
|
+
expectTypeOf<UpgradeData["offline"]>().toBeBoolean();
|
|
27
|
+
expectTypeOf<UpgradeData["executed"]>().toBeBoolean();
|
|
28
|
+
|
|
29
|
+
// RegistryCheckResult
|
|
30
|
+
expectTypeOf<RegistryCheckResult["latest"]>().toBeString();
|
|
31
|
+
expectTypeOf<RegistryCheckResult["distTag"]>().toBeString();
|
|
32
|
+
|
|
33
|
+
// StoreSummary
|
|
34
|
+
expectTypeOf<StoreSummary["tripleCount"]>().toBeNumber();
|
|
35
|
+
expectTypeOf<StoreSummary["graphNames"]>().toEqualTypeOf<readonly string[]>();
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** Data collected by `pragma info` for rendering. */
|
|
2
|
+
export interface InfoData {
|
|
3
|
+
readonly version: string;
|
|
4
|
+
readonly pm: string;
|
|
5
|
+
readonly installSource: string;
|
|
6
|
+
readonly configPath: string;
|
|
7
|
+
readonly tier: string | undefined;
|
|
8
|
+
readonly tierChain: readonly string[];
|
|
9
|
+
readonly channel: string;
|
|
10
|
+
readonly channelReleases: readonly string[];
|
|
11
|
+
readonly update:
|
|
12
|
+
| {
|
|
13
|
+
readonly current: string;
|
|
14
|
+
readonly latest: string;
|
|
15
|
+
readonly command: string;
|
|
16
|
+
}
|
|
17
|
+
| undefined;
|
|
18
|
+
readonly updateSkipped: boolean;
|
|
19
|
+
readonly store:
|
|
20
|
+
| { readonly tripleCount: number; readonly graphNames: readonly string[] }
|
|
21
|
+
| undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Data collected by `pragma upgrade` for rendering. */
|
|
25
|
+
export interface UpgradeData {
|
|
26
|
+
readonly pm: string;
|
|
27
|
+
readonly current: string;
|
|
28
|
+
readonly latest: string | undefined;
|
|
29
|
+
readonly command: string;
|
|
30
|
+
readonly dryRun: boolean;
|
|
31
|
+
readonly alreadyLatest: boolean;
|
|
32
|
+
readonly offline: boolean;
|
|
33
|
+
readonly executed: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Result of checking the npm registry for the latest package version. */
|
|
37
|
+
export interface RegistryCheckResult {
|
|
38
|
+
readonly latest: string;
|
|
39
|
+
readonly distTag: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Summary statistics from the ke store (triple count and named graphs). */
|
|
43
|
+
export interface StoreSummary {
|
|
44
|
+
readonly tripleCount: number;
|
|
45
|
+
readonly graphNames: readonly string[];
|
|
46
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type CommandDefinition,
|
|
3
|
+
type CommandResult,
|
|
4
|
+
createOutputResult,
|
|
5
|
+
} from "@canonical/cli-core";
|
|
6
|
+
import type { PragmaContext } from "../../shared/context.js";
|
|
7
|
+
import { COMMAND_REFERENCE, DECISION_TREES } from "../data/index.js";
|
|
8
|
+
import renderLlmOrientation from "../formatters/orientation.js";
|
|
9
|
+
import collectContext from "../operations/collectContext.js";
|
|
10
|
+
import type { LlmData } from "../types.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Builds the `pragma llm` command definition.
|
|
14
|
+
*
|
|
15
|
+
* Produces an LLM orientation document containing live context (entity counts,
|
|
16
|
+
* tier/channel), static decision trees, and a command reference table.
|
|
17
|
+
*
|
|
18
|
+
* @param ctx - Pragma runtime context providing the ke store and config.
|
|
19
|
+
* @returns A command definition for `llm`.
|
|
20
|
+
*/
|
|
21
|
+
export default function buildLlmCommand(ctx: PragmaContext): CommandDefinition {
|
|
22
|
+
return {
|
|
23
|
+
path: ["llm"],
|
|
24
|
+
description:
|
|
25
|
+
"LLM orientation — context, decision trees, and command reference",
|
|
26
|
+
parameters: [],
|
|
27
|
+
execute: async (): Promise<CommandResult> => {
|
|
28
|
+
const context = await collectContext(ctx.store, ctx.config);
|
|
29
|
+
const data: LlmData = {
|
|
30
|
+
context,
|
|
31
|
+
decisionTrees: DECISION_TREES,
|
|
32
|
+
commandReference: COMMAND_REFERENCE,
|
|
33
|
+
};
|
|
34
|
+
return createOutputResult(data, { plain: renderLlmOrientation });
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { CommandRefEntry } from "../types.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Static command reference table with approximate token-cost estimates.
|
|
5
|
+
*
|
|
6
|
+
* Used by the `pragma llm` orientation output to help LLMs budget context.
|
|
7
|
+
*/
|
|
8
|
+
export const COMMAND_REFERENCE: readonly CommandRefEntry[] = [
|
|
9
|
+
{ command: "block list", tokens: "~200" },
|
|
10
|
+
{ command: "block lookup <name> --detailed", tokens: "~500" },
|
|
11
|
+
{ command: "standard list --category <cat>", tokens: "~100" },
|
|
12
|
+
{ command: "standard lookup <name> --detailed", tokens: "~400" },
|
|
13
|
+
{ command: "standard categories", tokens: "~50" },
|
|
14
|
+
{ command: "modifier list", tokens: "~100" },
|
|
15
|
+
{ command: "modifier lookup <name>", tokens: "~80" },
|
|
16
|
+
{ command: "token list", tokens: "~400" },
|
|
17
|
+
{ command: "token lookup <name> --detailed", tokens: "~150" },
|
|
18
|
+
{ command: "tier list", tokens: "~50" },
|
|
19
|
+
{ command: "ontology list", tokens: "~80" },
|
|
20
|
+
{ command: "ontology show <prefix>", tokens: "~300" },
|
|
21
|
+
{ command: 'graph query "<sparql>"', tokens: "varies" },
|
|
22
|
+
{ command: "graph inspect <uri>", tokens: "~200" },
|
|
23
|
+
{ command: "config show", tokens: "~50" },
|
|
24
|
+
{ command: "info", tokens: "~100" },
|
|
25
|
+
];
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { DecisionTree } from "../types.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Static decision trees guiding LLMs through common pragma workflows.
|
|
5
|
+
*
|
|
6
|
+
* Each tree maps an intent (e.g. "Build a block") to a compact ASCII
|
|
7
|
+
* flowchart with token-cost annotations.
|
|
8
|
+
*/
|
|
9
|
+
export const DECISION_TREES: readonly DecisionTree[] = [
|
|
10
|
+
{
|
|
11
|
+
intent: "Build a block",
|
|
12
|
+
tree: `? Know name?
|
|
13
|
+
yes → block lookup <name> --detailed [~500]
|
|
14
|
+
no → block list [~200] → pick → lookup`,
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
intent: "Audit standards",
|
|
18
|
+
tree: `? Know standard?
|
|
19
|
+
yes → standard lookup <name> --detailed [~400]
|
|
20
|
+
no → ? Know block?
|
|
21
|
+
yes → block lookup <name> --detailed [~500]
|
|
22
|
+
→ inspect related guidance manually Σ500
|
|
23
|
+
no → standard list --category <cat> [~100]
|
|
24
|
+
→ standard lookup <std> --detailed [~400] Σ500`,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
intent: "Find a token",
|
|
28
|
+
tree: `? Know name?
|
|
29
|
+
yes → token lookup <name> --detailed [~150]
|
|
30
|
+
no → token list --category <cat> [~100]
|
|
31
|
+
→ token lookup <name> --detailed [~150] Σ250`,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
intent: "Explore the design system",
|
|
35
|
+
tree: `high-level → ontology list [~80] → ontology show <ns> [~300]
|
|
36
|
+
modifiers → modifier list [~100] → modifier lookup <name> [~80]
|
|
37
|
+
tiers → tier list [~50]
|
|
38
|
+
raw → graph query "SELECT ..." → graph inspect <uri> [~200]`,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
intent: "Configure",
|
|
42
|
+
tree: `tier → config tier <path> → config show [~50]
|
|
43
|
+
channel → config channel <value> (normal|experimental|prerelease)
|
|
44
|
+
status → info [~100]`,
|
|
45
|
+
},
|
|
46
|
+
];
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { LlmData } from "../types.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Renders the `pragma llm` orientation document.
|
|
5
|
+
*
|
|
6
|
+
* Produces a single condensed Markdown output (budget: <=800 tokens) containing
|
|
7
|
+
* context summary, decision trees, and a command reference table.
|
|
8
|
+
*
|
|
9
|
+
* @param data - The assembled LLM orientation data.
|
|
10
|
+
* @returns A Markdown string for LLM context injection.
|
|
11
|
+
*/
|
|
12
|
+
export default function renderLlmOrientation(data: LlmData): string {
|
|
13
|
+
const lines: string[] = [];
|
|
14
|
+
|
|
15
|
+
// --- Context block ---
|
|
16
|
+
const { context: ctx } = data;
|
|
17
|
+
const tierDisplay = ctx.tier
|
|
18
|
+
? `${ctx.tier} (${ctx.tierChain.join(" → ")})`
|
|
19
|
+
: "(none)";
|
|
20
|
+
|
|
21
|
+
lines.push("# Pragma — Design System CLI");
|
|
22
|
+
lines.push("");
|
|
23
|
+
lines.push("## Context");
|
|
24
|
+
lines.push(`tier: ${tierDisplay} | channel: ${ctx.channel}`);
|
|
25
|
+
lines.push(
|
|
26
|
+
`data: ${ctx.counts.blocks} blocks, ${ctx.counts.standards} standards, ${ctx.counts.modifierFamilies} modifier families, ${ctx.counts.tokens} tokens`,
|
|
27
|
+
);
|
|
28
|
+
lines.push(`namespaces: ${ctx.namespaces.join(", ")}`);
|
|
29
|
+
lines.push("");
|
|
30
|
+
|
|
31
|
+
// --- Decision trees ---
|
|
32
|
+
lines.push("## Decision Trees");
|
|
33
|
+
lines.push("");
|
|
34
|
+
for (const tree of data.decisionTrees) {
|
|
35
|
+
lines.push(`### ${tree.intent}`);
|
|
36
|
+
lines.push("```");
|
|
37
|
+
lines.push(tree.tree);
|
|
38
|
+
lines.push("```");
|
|
39
|
+
lines.push("");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// --- Command reference ---
|
|
43
|
+
lines.push("## Commands");
|
|
44
|
+
lines.push("| Command | Tokens |");
|
|
45
|
+
lines.push("|---|---|");
|
|
46
|
+
for (const ref of data.commandReference) {
|
|
47
|
+
lines.push(`| \`${ref.command}\` | ${ref.tokens} |`);
|
|
48
|
+
}
|
|
49
|
+
lines.push("");
|
|
50
|
+
lines.push("Append `--llm` to all commands for token-optimized output.");
|
|
51
|
+
|
|
52
|
+
return lines.join("\n");
|
|
53
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { CommandDefinition } from "@canonical/cli-core";
|
|
2
|
+
import type { Store } from "@canonical/ke";
|
|
3
|
+
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
4
|
+
import { createTestStore, DS_ALL_TTL } from "#testing";
|
|
5
|
+
import type { PragmaContext } from "../shared/context.js";
|
|
6
|
+
import { buildLlmCommand } from "./commands/index.js";
|
|
7
|
+
import type { LlmData } from "./types.js";
|
|
8
|
+
|
|
9
|
+
let store: Store;
|
|
10
|
+
let cleanup: () => void;
|
|
11
|
+
|
|
12
|
+
beforeAll(async () => {
|
|
13
|
+
const result = await createTestStore({ ttl: DS_ALL_TTL });
|
|
14
|
+
store = result.store;
|
|
15
|
+
cleanup = result.cleanup;
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
afterAll(() => cleanup());
|
|
19
|
+
|
|
20
|
+
function makeCtx(overrides: Partial<PragmaContext> = {}): PragmaContext {
|
|
21
|
+
return {
|
|
22
|
+
cwd: "/tmp",
|
|
23
|
+
globalFlags: { llm: false, format: "text" as const, verbose: false },
|
|
24
|
+
store,
|
|
25
|
+
config: { tier: undefined, channel: "prerelease" },
|
|
26
|
+
...overrides,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function executeOutput(
|
|
31
|
+
cmd: CommandDefinition,
|
|
32
|
+
ctx: PragmaContext,
|
|
33
|
+
): Promise<{ value: LlmData; text: string }> {
|
|
34
|
+
const result = await cmd.execute({}, ctx);
|
|
35
|
+
expect(result.tag).toBe("output");
|
|
36
|
+
if (result.tag !== "output") throw new Error("Expected output result");
|
|
37
|
+
const text = result.render.plain(result.value);
|
|
38
|
+
return { value: result.value as LlmData, text };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
describe("buildLlmCommand", () => {
|
|
42
|
+
it("returns an output result", async () => {
|
|
43
|
+
const ctx = makeCtx();
|
|
44
|
+
const cmd = buildLlmCommand(ctx);
|
|
45
|
+
const result = await cmd.execute({}, ctx);
|
|
46
|
+
expect(result.tag).toBe("output");
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("output contains all three sections", async () => {
|
|
50
|
+
const ctx = makeCtx();
|
|
51
|
+
const cmd = buildLlmCommand(ctx);
|
|
52
|
+
const { text } = await executeOutput(cmd, ctx);
|
|
53
|
+
expect(text).toContain("## Context");
|
|
54
|
+
expect(text).toContain("## Decision Trees");
|
|
55
|
+
expect(text).toContain("## Commands");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("context block reflects store state", async () => {
|
|
59
|
+
const ctx = makeCtx({
|
|
60
|
+
config: { tier: "apps/lxd", channel: "normal" },
|
|
61
|
+
});
|
|
62
|
+
const cmd = buildLlmCommand(ctx);
|
|
63
|
+
const { text, value } = await executeOutput(cmd, ctx);
|
|
64
|
+
|
|
65
|
+
expect(text).toContain("apps/lxd");
|
|
66
|
+
expect(text).toContain("normal");
|
|
67
|
+
expect(value.context.tierChain).toEqual(["global", "apps", "apps/lxd"]);
|
|
68
|
+
expect(value.context.counts.blocks).toBeGreaterThan(0);
|
|
69
|
+
expect(value.context.counts.standards).toBeGreaterThan(0);
|
|
70
|
+
expect(value.context.counts.modifierFamilies).toBeGreaterThan(0);
|
|
71
|
+
expect(value.context.counts.tokens).toBeGreaterThan(0);
|
|
72
|
+
expect(value.context.namespaces.length).toBeGreaterThan(0);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("includes all 5 decision trees", async () => {
|
|
76
|
+
const ctx = makeCtx();
|
|
77
|
+
const cmd = buildLlmCommand(ctx);
|
|
78
|
+
const { value, text } = await executeOutput(cmd, ctx);
|
|
79
|
+
expect(value.decisionTrees).toHaveLength(5);
|
|
80
|
+
expect(text).toContain("Build a block");
|
|
81
|
+
expect(text).toContain("Audit standards");
|
|
82
|
+
expect(text).toContain("Find a token");
|
|
83
|
+
expect(text).toContain("Explore the design system");
|
|
84
|
+
expect(text).toContain("Configure");
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("output stays within 800-token budget (≤3200 chars)", async () => {
|
|
88
|
+
const ctx = makeCtx();
|
|
89
|
+
const cmd = buildLlmCommand(ctx);
|
|
90
|
+
const { text } = await executeOutput(cmd, ctx);
|
|
91
|
+
expect(text.length).toBeLessThanOrEqual(3200);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP tool specs for llm domain — capabilities, llm.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { buildFilterConfig } from "../../shared/filters/index.js";
|
|
6
|
+
import type { ToolSpec } from "../../shared/ToolSpec.js";
|
|
7
|
+
import { COMMAND_REFERENCE, DECISION_TREES } from "../data/index.js";
|
|
8
|
+
import { collectContext } from "../operations/index.js";
|
|
9
|
+
import type { LlmData } from "../types.js";
|
|
10
|
+
|
|
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
|
+
];
|
|
47
|
+
|
|
48
|
+
const specs: readonly ToolSpec[] = [
|
|
49
|
+
{
|
|
50
|
+
name: "capabilities",
|
|
51
|
+
description:
|
|
52
|
+
"List all available pragma MCP tools with counts by category. Call this first to discover what pragma can do. (~100 tokens)",
|
|
53
|
+
readOnly: true,
|
|
54
|
+
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
|
+
};
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: "llm",
|
|
71
|
+
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.",
|
|
73
|
+
readOnly: true,
|
|
74
|
+
async execute(rt) {
|
|
75
|
+
const filters = buildFilterConfig(rt);
|
|
76
|
+
const context = await collectContext(rt.store, filters);
|
|
77
|
+
const data: LlmData = {
|
|
78
|
+
context,
|
|
79
|
+
decisionTrees: DECISION_TREES,
|
|
80
|
+
commandReference: COMMAND_REFERENCE,
|
|
81
|
+
};
|
|
82
|
+
return { data };
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
];
|
|
86
|
+
|
|
87
|
+
export default specs;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Store } from "@canonical/ke";
|
|
2
|
+
import { listBlocks } from "../../block/operations/index.js";
|
|
3
|
+
import { listModifiers } from "../../modifier/operations/index.js";
|
|
4
|
+
import { listOntologies } from "../../ontology/operations/index.js";
|
|
5
|
+
import { resolveTierChain } from "../../shared/filters/buildTierFilter.js";
|
|
6
|
+
import type { FilterConfig } from "../../shared/types.js";
|
|
7
|
+
import { listStandards } from "../../standard/operations/index.js";
|
|
8
|
+
import { listTokens } from "../../token/operations/index.js";
|
|
9
|
+
import type { LlmContext } from "../types.js";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Collects dynamic context for the `pragma llm` orientation output.
|
|
13
|
+
*
|
|
14
|
+
* Queries the store in parallel for block, standard, modifier, token, and
|
|
15
|
+
* ontology counts, and combines them with tier/channel config state.
|
|
16
|
+
*
|
|
17
|
+
* @note Queries ke store
|
|
18
|
+
*
|
|
19
|
+
* @param store - The ke store to query.
|
|
20
|
+
* @param config - Filter config providing tier and channel settings.
|
|
21
|
+
* @returns An {@link LlmContext} with entity counts and namespace list.
|
|
22
|
+
*/
|
|
23
|
+
export default async function collectContext(
|
|
24
|
+
store: Store,
|
|
25
|
+
config: FilterConfig,
|
|
26
|
+
): Promise<LlmContext> {
|
|
27
|
+
const [blocks, standards, modifiers, tokens, ontologies] = await Promise.all([
|
|
28
|
+
listBlocks(store, config),
|
|
29
|
+
listStandards(store),
|
|
30
|
+
listModifiers(store),
|
|
31
|
+
listTokens(store),
|
|
32
|
+
listOntologies(store),
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
tier: config.tier,
|
|
37
|
+
tierChain: resolveTierChain(config.tier),
|
|
38
|
+
channel: config.channel,
|
|
39
|
+
counts: {
|
|
40
|
+
blocks: blocks.length,
|
|
41
|
+
standards: standards.length,
|
|
42
|
+
modifierFamilies: modifiers.length,
|
|
43
|
+
tokens: tokens.length,
|
|
44
|
+
},
|
|
45
|
+
namespaces: ontologies.map((o) => o.prefix),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** Dynamic context snapshot: tier, channel, entity counts, and namespaces. */
|
|
2
|
+
export interface LlmContext {
|
|
3
|
+
readonly tier: string | undefined;
|
|
4
|
+
readonly tierChain: readonly string[];
|
|
5
|
+
readonly channel: string;
|
|
6
|
+
readonly counts: {
|
|
7
|
+
readonly blocks: number;
|
|
8
|
+
readonly standards: number;
|
|
9
|
+
readonly modifierFamilies: number;
|
|
10
|
+
readonly tokens: number;
|
|
11
|
+
};
|
|
12
|
+
readonly namespaces: readonly string[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** A single intent-to-flowchart mapping used in LLM orientation output. */
|
|
16
|
+
export interface DecisionTree {
|
|
17
|
+
readonly intent: string;
|
|
18
|
+
readonly tree: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** A command name paired with its approximate output token cost. */
|
|
22
|
+
export interface CommandRefEntry {
|
|
23
|
+
readonly command: string;
|
|
24
|
+
readonly tokens: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Complete payload rendered by `pragma llm`: context, trees, and reference. */
|
|
28
|
+
export interface LlmData {
|
|
29
|
+
readonly context: LlmContext;
|
|
30
|
+
readonly decisionTrees: readonly DecisionTree[];
|
|
31
|
+
readonly commandReference: readonly CommandRefEntry[];
|
|
32
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { CommandOutputResult } from "@canonical/cli-core";
|
|
2
|
+
import type { Store } from "@canonical/ke";
|
|
3
|
+
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
4
|
+
import { createTestStore, DS_ALL_TTL } from "#testing";
|
|
5
|
+
import type { PragmaContext } from "../../shared/context.js";
|
|
6
|
+
import listCommand from "./list.js";
|
|
7
|
+
|
|
8
|
+
let store: Store;
|
|
9
|
+
let cleanup: () => void;
|
|
10
|
+
|
|
11
|
+
beforeAll(async () => {
|
|
12
|
+
const result = await createTestStore({ ttl: DS_ALL_TTL });
|
|
13
|
+
store = result.store;
|
|
14
|
+
cleanup = result.cleanup;
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
afterAll(() => cleanup());
|
|
18
|
+
|
|
19
|
+
function makeCtx(
|
|
20
|
+
overrides?: Partial<PragmaContext["globalFlags"]>,
|
|
21
|
+
): PragmaContext {
|
|
22
|
+
return {
|
|
23
|
+
cwd: "/tmp",
|
|
24
|
+
store,
|
|
25
|
+
config: { tier: undefined, channel: "normal" },
|
|
26
|
+
globalFlags: {
|
|
27
|
+
llm: false,
|
|
28
|
+
format: "text",
|
|
29
|
+
verbose: false,
|
|
30
|
+
...overrides,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
describe("modifier list command", () => {
|
|
36
|
+
it("returns output result with all families", async () => {
|
|
37
|
+
const ctx = makeCtx();
|
|
38
|
+
const cmd = listCommand(ctx);
|
|
39
|
+
const result = await cmd.execute({}, ctx);
|
|
40
|
+
expect(result.tag).toBe("output");
|
|
41
|
+
|
|
42
|
+
const output = result as CommandOutputResult;
|
|
43
|
+
const text = output.render.plain(output.value);
|
|
44
|
+
expect(text).toContain("importance");
|
|
45
|
+
expect(text).toContain("density");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("renders LLM format with --llm", async () => {
|
|
49
|
+
const ctx = makeCtx({ llm: true });
|
|
50
|
+
const cmd = listCommand(ctx);
|
|
51
|
+
const result = await cmd.execute({}, ctx);
|
|
52
|
+
const output = result as CommandOutputResult;
|
|
53
|
+
const text = output.render.plain(output.value);
|
|
54
|
+
expect(text).toContain("## Modifier Families");
|
|
55
|
+
expect(text).toContain("**importance**");
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
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 type { PragmaContext } from "../../shared/context.js";
|
|
13
|
+
import { selectFormatter } from "../../shared/formatters.js";
|
|
14
|
+
import { listFormatters } from "../formatters/index.js";
|
|
15
|
+
import { resolveModifierList } from "../orchestration/index.js";
|
|
16
|
+
|
|
17
|
+
export default function listCommand(ctx: PragmaContext): CommandDefinition {
|
|
18
|
+
return {
|
|
19
|
+
path: ["modifier", "list"],
|
|
20
|
+
description: "List all modifier families",
|
|
21
|
+
parameters: [],
|
|
22
|
+
meta: {
|
|
23
|
+
examples: ["pragma modifier list", "pragma modifier list --llm"],
|
|
24
|
+
},
|
|
25
|
+
async execute() {
|
|
26
|
+
const resolution = await resolveModifierList(ctx);
|
|
27
|
+
|
|
28
|
+
return createOutputResult([...resolution.items], {
|
|
29
|
+
plain: selectFormatter(ctx, listFormatters),
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|