@superkou/openspec 1.4.1
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/LICENSE +22 -0
- package/README.md +213 -0
- package/bin/openspec.js +5 -0
- package/dist/cli/index.d.ts +5 -0
- package/dist/cli/index.js +544 -0
- package/dist/commands/change.d.ts +35 -0
- package/dist/commands/change.js +277 -0
- package/dist/commands/completion.d.ts +72 -0
- package/dist/commands/completion.js +264 -0
- package/dist/commands/config.d.ts +36 -0
- package/dist/commands/config.js +611 -0
- package/dist/commands/context-store.d.ts +3 -0
- package/dist/commands/context-store.js +475 -0
- package/dist/commands/feedback.d.ts +9 -0
- package/dist/commands/feedback.js +183 -0
- package/dist/commands/initiative.d.ts +13 -0
- package/dist/commands/initiative.js +318 -0
- package/dist/commands/schema.d.ts +6 -0
- package/dist/commands/schema.js +869 -0
- package/dist/commands/show.d.ts +14 -0
- package/dist/commands/show.js +132 -0
- package/dist/commands/spec.d.ts +15 -0
- package/dist/commands/spec.js +225 -0
- package/dist/commands/validate.d.ts +24 -0
- package/dist/commands/validate.js +294 -0
- package/dist/commands/workflow/index.d.ts +19 -0
- package/dist/commands/workflow/index.js +13 -0
- package/dist/commands/workflow/initiative-link.d.ts +24 -0
- package/dist/commands/workflow/initiative-link.js +47 -0
- package/dist/commands/workflow/instructions.d.ts +29 -0
- package/dist/commands/workflow/instructions.js +344 -0
- package/dist/commands/workflow/new-change.d.ts +17 -0
- package/dist/commands/workflow/new-change.js +141 -0
- package/dist/commands/workflow/schemas.d.ts +10 -0
- package/dist/commands/workflow/schemas.js +34 -0
- package/dist/commands/workflow/set-change.d.ts +13 -0
- package/dist/commands/workflow/set-change.js +87 -0
- package/dist/commands/workflow/shared.d.ts +59 -0
- package/dist/commands/workflow/shared.js +116 -0
- package/dist/commands/workflow/status.d.ts +14 -0
- package/dist/commands/workflow/status.js +90 -0
- package/dist/commands/workflow/templates.d.ts +16 -0
- package/dist/commands/workflow/templates.js +69 -0
- package/dist/commands/workspace/context-status.d.ts +4 -0
- package/dist/commands/workspace/context-status.js +59 -0
- package/dist/commands/workspace/open-target-selection.d.ts +13 -0
- package/dist/commands/workspace/open-target-selection.js +146 -0
- package/dist/commands/workspace/open-view.d.ts +62 -0
- package/dist/commands/workspace/open-view.js +249 -0
- package/dist/commands/workspace/open.d.ts +37 -0
- package/dist/commands/workspace/open.js +110 -0
- package/dist/commands/workspace/opener-selection.d.ts +11 -0
- package/dist/commands/workspace/opener-selection.js +98 -0
- package/dist/commands/workspace/operations.d.ts +29 -0
- package/dist/commands/workspace/operations.js +543 -0
- package/dist/commands/workspace/prompt-theme.d.ts +29 -0
- package/dist/commands/workspace/prompt-theme.js +24 -0
- package/dist/commands/workspace/registration.d.ts +13 -0
- package/dist/commands/workspace/registration.js +84 -0
- package/dist/commands/workspace/selection.d.ts +8 -0
- package/dist/commands/workspace/selection.js +104 -0
- package/dist/commands/workspace/setup-prompts.d.ts +13 -0
- package/dist/commands/workspace/setup-prompts.js +121 -0
- package/dist/commands/workspace/types.d.ts +103 -0
- package/dist/commands/workspace/types.js +36 -0
- package/dist/commands/workspace.d.ts +5 -0
- package/dist/commands/workspace.js +577 -0
- package/dist/core/archive.d.ts +11 -0
- package/dist/core/archive.js +318 -0
- package/dist/core/artifact-graph/graph.d.ts +56 -0
- package/dist/core/artifact-graph/graph.js +141 -0
- package/dist/core/artifact-graph/index.d.ts +9 -0
- package/dist/core/artifact-graph/index.js +14 -0
- package/dist/core/artifact-graph/instruction-loader.d.ts +183 -0
- package/dist/core/artifact-graph/instruction-loader.js +256 -0
- package/dist/core/artifact-graph/outputs.d.ts +14 -0
- package/dist/core/artifact-graph/outputs.js +39 -0
- package/dist/core/artifact-graph/resolver.d.ts +81 -0
- package/dist/core/artifact-graph/resolver.js +257 -0
- package/dist/core/artifact-graph/schema.d.ts +13 -0
- package/dist/core/artifact-graph/schema.js +108 -0
- package/dist/core/artifact-graph/state.d.ts +12 -0
- package/dist/core/artifact-graph/state.js +31 -0
- package/dist/core/artifact-graph/types.d.ts +40 -0
- package/dist/core/artifact-graph/types.js +29 -0
- package/dist/core/available-tools.d.ts +17 -0
- package/dist/core/available-tools.js +43 -0
- package/dist/core/change-metadata/index.d.ts +2 -0
- package/dist/core/change-metadata/index.js +2 -0
- package/dist/core/change-metadata/schema.d.ts +18 -0
- package/dist/core/change-metadata/schema.js +28 -0
- package/dist/core/change-status-policy.d.ts +50 -0
- package/dist/core/change-status-policy.js +70 -0
- package/dist/core/collections/index.d.ts +3 -0
- package/dist/core/collections/index.js +3 -0
- package/dist/core/collections/initiatives/collection.d.ts +4 -0
- package/dist/core/collections/initiatives/collection.js +17 -0
- package/dist/core/collections/initiatives/index.d.ts +6 -0
- package/dist/core/collections/initiatives/index.js +6 -0
- package/dist/core/collections/initiatives/operations.d.ts +49 -0
- package/dist/core/collections/initiatives/operations.js +175 -0
- package/dist/core/collections/initiatives/resolution.d.ts +87 -0
- package/dist/core/collections/initiatives/resolution.js +374 -0
- package/dist/core/collections/initiatives/schema.d.ts +41 -0
- package/dist/core/collections/initiatives/schema.js +134 -0
- package/dist/core/collections/initiatives/templates.d.ts +12 -0
- package/dist/core/collections/initiatives/templates.js +90 -0
- package/dist/core/collections/runtime.d.ts +46 -0
- package/dist/core/collections/runtime.js +194 -0
- package/dist/core/command-generation/adapters/amazon-q.d.ts +13 -0
- package/dist/core/command-generation/adapters/amazon-q.js +26 -0
- package/dist/core/command-generation/adapters/antigravity.d.ts +13 -0
- package/dist/core/command-generation/adapters/antigravity.js +26 -0
- package/dist/core/command-generation/adapters/auggie.d.ts +13 -0
- package/dist/core/command-generation/adapters/auggie.js +27 -0
- package/dist/core/command-generation/adapters/bob.d.ts +14 -0
- package/dist/core/command-generation/adapters/bob.js +45 -0
- package/dist/core/command-generation/adapters/claude.d.ts +13 -0
- package/dist/core/command-generation/adapters/claude.js +50 -0
- package/dist/core/command-generation/adapters/cline.d.ts +14 -0
- package/dist/core/command-generation/adapters/cline.js +27 -0
- package/dist/core/command-generation/adapters/codebuddy.d.ts +13 -0
- package/dist/core/command-generation/adapters/codebuddy.js +28 -0
- package/dist/core/command-generation/adapters/codex.d.ts +16 -0
- package/dist/core/command-generation/adapters/codex.js +39 -0
- package/dist/core/command-generation/adapters/continue.d.ts +13 -0
- package/dist/core/command-generation/adapters/continue.js +28 -0
- package/dist/core/command-generation/adapters/costrict.d.ts +13 -0
- package/dist/core/command-generation/adapters/costrict.js +27 -0
- package/dist/core/command-generation/adapters/crush.d.ts +13 -0
- package/dist/core/command-generation/adapters/crush.js +30 -0
- package/dist/core/command-generation/adapters/cursor.d.ts +14 -0
- package/dist/core/command-generation/adapters/cursor.js +44 -0
- package/dist/core/command-generation/adapters/factory.d.ts +13 -0
- package/dist/core/command-generation/adapters/factory.js +27 -0
- package/dist/core/command-generation/adapters/gemini.d.ts +13 -0
- package/dist/core/command-generation/adapters/gemini.js +26 -0
- package/dist/core/command-generation/adapters/github-copilot.d.ts +13 -0
- package/dist/core/command-generation/adapters/github-copilot.js +26 -0
- package/dist/core/command-generation/adapters/iflow.d.ts +13 -0
- package/dist/core/command-generation/adapters/iflow.js +29 -0
- package/dist/core/command-generation/adapters/index.d.ts +32 -0
- package/dist/core/command-generation/adapters/index.js +32 -0
- package/dist/core/command-generation/adapters/junie.d.ts +13 -0
- package/dist/core/command-generation/adapters/junie.js +26 -0
- package/dist/core/command-generation/adapters/kilocode.d.ts +14 -0
- package/dist/core/command-generation/adapters/kilocode.js +23 -0
- package/dist/core/command-generation/adapters/kiro.d.ts +13 -0
- package/dist/core/command-generation/adapters/kiro.js +26 -0
- package/dist/core/command-generation/adapters/lingma.d.ts +13 -0
- package/dist/core/command-generation/adapters/lingma.js +30 -0
- package/dist/core/command-generation/adapters/opencode.d.ts +13 -0
- package/dist/core/command-generation/adapters/opencode.js +29 -0
- package/dist/core/command-generation/adapters/pi.d.ts +18 -0
- package/dist/core/command-generation/adapters/pi.js +55 -0
- package/dist/core/command-generation/adapters/qoder.d.ts +13 -0
- package/dist/core/command-generation/adapters/qoder.js +30 -0
- package/dist/core/command-generation/adapters/qwen.d.ts +13 -0
- package/dist/core/command-generation/adapters/qwen.js +26 -0
- package/dist/core/command-generation/adapters/roocode.d.ts +14 -0
- package/dist/core/command-generation/adapters/roocode.js +27 -0
- package/dist/core/command-generation/adapters/windsurf.d.ts +14 -0
- package/dist/core/command-generation/adapters/windsurf.js +51 -0
- package/dist/core/command-generation/generator.d.ts +21 -0
- package/dist/core/command-generation/generator.js +27 -0
- package/dist/core/command-generation/index.d.ts +22 -0
- package/dist/core/command-generation/index.js +24 -0
- package/dist/core/command-generation/registry.d.ts +36 -0
- package/dist/core/command-generation/registry.js +98 -0
- package/dist/core/command-generation/types.d.ts +56 -0
- package/dist/core/command-generation/types.js +8 -0
- package/dist/core/completions/command-registry.d.ts +3 -0
- package/dist/core/completions/command-registry.js +961 -0
- package/dist/core/completions/completion-provider.d.ts +71 -0
- package/dist/core/completions/completion-provider.js +129 -0
- package/dist/core/completions/factory.d.ts +64 -0
- package/dist/core/completions/factory.js +75 -0
- package/dist/core/completions/generators/bash-generator.d.ts +35 -0
- package/dist/core/completions/generators/bash-generator.js +230 -0
- package/dist/core/completions/generators/fish-generator.d.ts +32 -0
- package/dist/core/completions/generators/fish-generator.js +160 -0
- package/dist/core/completions/generators/powershell-generator.d.ts +36 -0
- package/dist/core/completions/generators/powershell-generator.js +266 -0
- package/dist/core/completions/generators/zsh-generator.d.ts +47 -0
- package/dist/core/completions/generators/zsh-generator.js +274 -0
- package/dist/core/completions/installers/bash-installer.d.ts +87 -0
- package/dist/core/completions/installers/bash-installer.js +318 -0
- package/dist/core/completions/installers/fish-installer.d.ts +43 -0
- package/dist/core/completions/installers/fish-installer.js +143 -0
- package/dist/core/completions/installers/powershell-installer.d.ts +102 -0
- package/dist/core/completions/installers/powershell-installer.js +387 -0
- package/dist/core/completions/installers/zsh-installer.d.ts +117 -0
- package/dist/core/completions/installers/zsh-installer.js +421 -0
- package/dist/core/completions/shared-flags.d.ts +12 -0
- package/dist/core/completions/shared-flags.js +28 -0
- package/dist/core/completions/templates/bash-templates.d.ts +6 -0
- package/dist/core/completions/templates/bash-templates.js +30 -0
- package/dist/core/completions/templates/fish-templates.d.ts +7 -0
- package/dist/core/completions/templates/fish-templates.js +45 -0
- package/dist/core/completions/templates/powershell-templates.d.ts +6 -0
- package/dist/core/completions/templates/powershell-templates.js +34 -0
- package/dist/core/completions/templates/zsh-templates.d.ts +6 -0
- package/dist/core/completions/templates/zsh-templates.js +45 -0
- package/dist/core/completions/types.d.ts +101 -0
- package/dist/core/completions/types.js +2 -0
- package/dist/core/config-prompts.d.ts +9 -0
- package/dist/core/config-prompts.js +34 -0
- package/dist/core/config-schema.d.ts +86 -0
- package/dist/core/config-schema.js +213 -0
- package/dist/core/config.d.ts +18 -0
- package/dist/core/config.js +39 -0
- package/dist/core/context-store/binding.d.ts +53 -0
- package/dist/core/context-store/binding.js +197 -0
- package/dist/core/context-store/errors.d.ts +20 -0
- package/dist/core/context-store/errors.js +22 -0
- package/dist/core/context-store/foundation.d.ts +55 -0
- package/dist/core/context-store/foundation.js +321 -0
- package/dist/core/context-store/index.d.ts +6 -0
- package/dist/core/context-store/index.js +6 -0
- package/dist/core/context-store/operations.d.ts +85 -0
- package/dist/core/context-store/operations.js +528 -0
- package/dist/core/context-store/registry.d.ts +45 -0
- package/dist/core/context-store/registry.js +229 -0
- package/dist/core/converters/json-converter.d.ts +6 -0
- package/dist/core/converters/json-converter.js +51 -0
- package/dist/core/global-config.d.ts +49 -0
- package/dist/core/global-config.js +124 -0
- package/dist/core/index.d.ts +6 -0
- package/dist/core/index.js +7 -0
- package/dist/core/init.d.ts +37 -0
- package/dist/core/init.js +593 -0
- package/dist/core/legacy-cleanup.d.ts +162 -0
- package/dist/core/legacy-cleanup.js +514 -0
- package/dist/core/list.d.ts +9 -0
- package/dist/core/list.js +171 -0
- package/dist/core/migration.d.ts +23 -0
- package/dist/core/migration.js +108 -0
- package/dist/core/parsers/change-parser.d.ts +13 -0
- package/dist/core/parsers/change-parser.js +197 -0
- package/dist/core/parsers/markdown-parser.d.ts +26 -0
- package/dist/core/parsers/markdown-parser.js +227 -0
- package/dist/core/parsers/requirement-blocks.d.ts +37 -0
- package/dist/core/parsers/requirement-blocks.js +201 -0
- package/dist/core/parsers/spec-structure.d.ts +9 -0
- package/dist/core/parsers/spec-structure.js +88 -0
- package/dist/core/planning-home.d.ts +21 -0
- package/dist/core/planning-home.js +108 -0
- package/dist/core/profile-sync-drift.d.ts +38 -0
- package/dist/core/profile-sync-drift.js +200 -0
- package/dist/core/profiles.d.ts +26 -0
- package/dist/core/profiles.js +40 -0
- package/dist/core/project-config.d.ts +64 -0
- package/dist/core/project-config.js +223 -0
- package/dist/core/schemas/base.schema.d.ts +13 -0
- package/dist/core/schemas/base.schema.js +13 -0
- package/dist/core/schemas/change.schema.d.ts +73 -0
- package/dist/core/schemas/change.schema.js +31 -0
- package/dist/core/schemas/index.d.ts +4 -0
- package/dist/core/schemas/index.js +4 -0
- package/dist/core/schemas/spec.schema.d.ts +18 -0
- package/dist/core/schemas/spec.schema.js +15 -0
- package/dist/core/shared/index.d.ts +8 -0
- package/dist/core/shared/index.js +8 -0
- package/dist/core/shared/skill-generation.d.ts +49 -0
- package/dist/core/shared/skill-generation.js +96 -0
- package/dist/core/shared/tool-detection.d.ts +71 -0
- package/dist/core/shared/tool-detection.js +158 -0
- package/dist/core/specs-apply.d.ts +73 -0
- package/dist/core/specs-apply.js +392 -0
- package/dist/core/styles/palette.d.ts +7 -0
- package/dist/core/styles/palette.js +8 -0
- package/dist/core/templates/index.d.ts +8 -0
- package/dist/core/templates/index.js +9 -0
- package/dist/core/templates/skill-templates.d.ts +19 -0
- package/dist/core/templates/skill-templates.js +18 -0
- package/dist/core/templates/types.d.ts +19 -0
- package/dist/core/templates/types.js +5 -0
- package/dist/core/templates/workflows/apply-change.d.ts +10 -0
- package/dist/core/templates/workflows/apply-change.js +314 -0
- package/dist/core/templates/workflows/archive-change.d.ts +10 -0
- package/dist/core/templates/workflows/archive-change.js +277 -0
- package/dist/core/templates/workflows/bulk-archive-change.d.ts +10 -0
- package/dist/core/templates/workflows/bulk-archive-change.js +492 -0
- package/dist/core/templates/workflows/continue-change.d.ts +10 -0
- package/dist/core/templates/workflows/continue-change.js +234 -0
- package/dist/core/templates/workflows/explore.d.ts +10 -0
- package/dist/core/templates/workflows/explore.js +459 -0
- package/dist/core/templates/workflows/feedback.d.ts +9 -0
- package/dist/core/templates/workflows/feedback.js +108 -0
- package/dist/core/templates/workflows/ff-change.d.ts +10 -0
- package/dist/core/templates/workflows/ff-change.js +200 -0
- package/dist/core/templates/workflows/new-change.d.ts +10 -0
- package/dist/core/templates/workflows/new-change.js +143 -0
- package/dist/core/templates/workflows/onboard.d.ts +10 -0
- package/dist/core/templates/workflows/onboard.js +563 -0
- package/dist/core/templates/workflows/propose.d.ts +10 -0
- package/dist/core/templates/workflows/propose.js +218 -0
- package/dist/core/templates/workflows/sync-specs.d.ts +10 -0
- package/dist/core/templates/workflows/sync-specs.js +290 -0
- package/dist/core/templates/workflows/verify-change.d.ts +10 -0
- package/dist/core/templates/workflows/verify-change.js +338 -0
- package/dist/core/update.d.ts +82 -0
- package/dist/core/update.js +557 -0
- package/dist/core/validation/constants.d.ts +34 -0
- package/dist/core/validation/constants.js +40 -0
- package/dist/core/validation/types.d.ts +18 -0
- package/dist/core/validation/types.js +2 -0
- package/dist/core/validation/validator.d.ts +43 -0
- package/dist/core/validation/validator.js +435 -0
- package/dist/core/view.d.ts +8 -0
- package/dist/core/view.js +168 -0
- package/dist/core/workspace/foundation.d.ts +67 -0
- package/dist/core/workspace/foundation.js +295 -0
- package/dist/core/workspace/index.d.ts +8 -0
- package/dist/core/workspace/index.js +8 -0
- package/dist/core/workspace/legacy-state.d.ts +28 -0
- package/dist/core/workspace/legacy-state.js +200 -0
- package/dist/core/workspace/link-input.d.ts +9 -0
- package/dist/core/workspace/link-input.js +32 -0
- package/dist/core/workspace/open-surface.d.ts +45 -0
- package/dist/core/workspace/open-surface.js +215 -0
- package/dist/core/workspace/openers.d.ts +21 -0
- package/dist/core/workspace/openers.js +124 -0
- package/dist/core/workspace/registry.d.ts +24 -0
- package/dist/core/workspace/registry.js +146 -0
- package/dist/core/workspace/skills.d.ts +57 -0
- package/dist/core/workspace/skills.js +334 -0
- package/dist/core/workspace/state-io.d.ts +10 -0
- package/dist/core/workspace/state-io.js +121 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/prompts/searchable-multi-select.d.ts +28 -0
- package/dist/prompts/searchable-multi-select.js +159 -0
- package/dist/telemetry/config.d.ts +38 -0
- package/dist/telemetry/config.js +136 -0
- package/dist/telemetry/index.d.ts +31 -0
- package/dist/telemetry/index.js +164 -0
- package/dist/ui/ascii-patterns.d.ts +16 -0
- package/dist/ui/ascii-patterns.js +133 -0
- package/dist/ui/welcome-screen.d.ts +10 -0
- package/dist/ui/welcome-screen.js +146 -0
- package/dist/utils/change-metadata.d.ts +54 -0
- package/dist/utils/change-metadata.js +141 -0
- package/dist/utils/change-utils.d.ts +71 -0
- package/dist/utils/change-utils.js +123 -0
- package/dist/utils/command-references.d.ts +18 -0
- package/dist/utils/command-references.js +20 -0
- package/dist/utils/file-system.d.ts +41 -0
- package/dist/utils/file-system.js +301 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.js +9 -0
- package/dist/utils/interactive.d.ts +18 -0
- package/dist/utils/interactive.js +21 -0
- package/dist/utils/item-discovery.d.ts +4 -0
- package/dist/utils/item-discovery.js +72 -0
- package/dist/utils/match.d.ts +3 -0
- package/dist/utils/match.js +22 -0
- package/dist/utils/shell-detection.d.ts +20 -0
- package/dist/utils/shell-detection.js +41 -0
- package/dist/utils/task-progress.d.ts +8 -0
- package/dist/utils/task-progress.js +36 -0
- package/package.json +85 -0
- package/schemas/spec-driven/schema.yaml +151 -0
- package/schemas/spec-driven/templates/design.md +19 -0
- package/schemas/spec-driven/templates/proposal.md +23 -0
- package/schemas/spec-driven/templates/spec.md +8 -0
- package/schemas/spec-driven/templates/tasks.md +9 -0
- package/schemas/workspace-planning/schema.yaml +72 -0
- package/schemas/workspace-planning/templates/design.md +33 -0
- package/schemas/workspace-planning/templates/proposal.md +28 -0
- package/schemas/workspace-planning/templates/spec.md +9 -0
- package/schemas/workspace-planning/templates/tasks.md +15 -0
- package/scripts/postinstall.js +83 -0
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
import * as os from 'node:os';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { ContextStoreError, doctorContextStores, getDefaultContextStoreRoot, listContextStores, prepareContextStoreSetup, prepareContextStoreCleanup, registerExistingContextStore, removeContextStore, setupPreparedContextStore, unregisterContextStore, validateContextStoreId, } from '../core/context-store/index.js';
|
|
4
|
+
import { isInteractive } from '../utils/interactive.js';
|
|
5
|
+
function printJson(payload) {
|
|
6
|
+
console.log(JSON.stringify(payload, null, 2));
|
|
7
|
+
}
|
|
8
|
+
function asErrorMessage(error) {
|
|
9
|
+
return error instanceof Error ? error.message : String(error);
|
|
10
|
+
}
|
|
11
|
+
function appendStatus(payload, status) {
|
|
12
|
+
return {
|
|
13
|
+
...payload,
|
|
14
|
+
status: [...payload.status, status],
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function toStoreOutput(store) {
|
|
18
|
+
return {
|
|
19
|
+
id: store.id,
|
|
20
|
+
root: store.root,
|
|
21
|
+
...(store.metadataPath ? { metadata_path: store.metadataPath } : {}),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function toMutationOutput(result) {
|
|
25
|
+
return {
|
|
26
|
+
context_store: toStoreOutput(result.store),
|
|
27
|
+
registry: {
|
|
28
|
+
path: result.registryCommit.path,
|
|
29
|
+
registered: true,
|
|
30
|
+
},
|
|
31
|
+
git: {
|
|
32
|
+
is_repository: result.git.isRepository,
|
|
33
|
+
initialized: result.git.initialized,
|
|
34
|
+
},
|
|
35
|
+
created_files: result.createdArtifacts,
|
|
36
|
+
status: [],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function toCleanupOutput(result) {
|
|
40
|
+
return {
|
|
41
|
+
context_store: toStoreOutput(result.store),
|
|
42
|
+
registry: {
|
|
43
|
+
path: result.registryCommit.path,
|
|
44
|
+
removed: result.registryCommit.removed,
|
|
45
|
+
},
|
|
46
|
+
files: {
|
|
47
|
+
deleted: result.files.deleted,
|
|
48
|
+
deleted_path: result.files.deletedPath ?? null,
|
|
49
|
+
left_on_disk: result.files.leftOnDisk ?? null,
|
|
50
|
+
},
|
|
51
|
+
status: result.diagnostics,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function toListOutput(result) {
|
|
55
|
+
return {
|
|
56
|
+
context_stores: result.stores.map(toStoreOutput),
|
|
57
|
+
status: [],
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function toDoctorStoreOutput(store) {
|
|
61
|
+
return {
|
|
62
|
+
...toStoreOutput(store),
|
|
63
|
+
metadata: store.metadata,
|
|
64
|
+
git: {
|
|
65
|
+
is_repository: store.git.isRepository,
|
|
66
|
+
},
|
|
67
|
+
status: store.diagnostics,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function toDoctorOutput(result) {
|
|
71
|
+
return {
|
|
72
|
+
context_stores: result.stores.map(toDoctorStoreOutput),
|
|
73
|
+
status: result.diagnostics,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function asStatus(error) {
|
|
77
|
+
if (error instanceof ContextStoreError) {
|
|
78
|
+
return error.diagnostic;
|
|
79
|
+
}
|
|
80
|
+
const message = asErrorMessage(error);
|
|
81
|
+
return {
|
|
82
|
+
severity: 'error',
|
|
83
|
+
code: 'context_store_error',
|
|
84
|
+
message,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function isPromptCancellationError(error) {
|
|
88
|
+
return (error instanceof Error &&
|
|
89
|
+
(error.name === 'ExitPromptError' || error.message.includes('force closed the prompt with SIGINT')));
|
|
90
|
+
}
|
|
91
|
+
async function shouldInitializeGit(options) {
|
|
92
|
+
if (options.initGit !== undefined) {
|
|
93
|
+
return options.initGit;
|
|
94
|
+
}
|
|
95
|
+
if (options.json || !isInteractive()) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
const { confirm } = await import('@inquirer/prompts');
|
|
99
|
+
return confirm({
|
|
100
|
+
message: 'Initialize Git in this context store?',
|
|
101
|
+
default: true,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
function formatPathForHuman(targetPath) {
|
|
105
|
+
const home = os.homedir();
|
|
106
|
+
const normalizedHome = path.resolve(home);
|
|
107
|
+
const normalizedTarget = path.resolve(targetPath);
|
|
108
|
+
if (normalizedTarget === normalizedHome)
|
|
109
|
+
return '~';
|
|
110
|
+
if (normalizedTarget.startsWith(`${normalizedHome}${path.sep}`)) {
|
|
111
|
+
return `~${path.sep}${path.relative(normalizedHome, normalizedTarget)}`;
|
|
112
|
+
}
|
|
113
|
+
return targetPath;
|
|
114
|
+
}
|
|
115
|
+
async function promptContextStoreId() {
|
|
116
|
+
const { input } = await import('@inquirer/prompts');
|
|
117
|
+
return input({
|
|
118
|
+
message: 'Context store name',
|
|
119
|
+
required: true,
|
|
120
|
+
validate(value) {
|
|
121
|
+
try {
|
|
122
|
+
validateContextStoreId(value);
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
return asErrorMessage(error);
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
async function promptContextStorePath(id) {
|
|
132
|
+
const { input } = await import('@inquirer/prompts');
|
|
133
|
+
const defaultPath = getDefaultContextStoreRoot(id);
|
|
134
|
+
return input({
|
|
135
|
+
message: 'Where should this context store live?',
|
|
136
|
+
default: defaultPath,
|
|
137
|
+
prefill: 'editable',
|
|
138
|
+
required: true,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
function isSetupInsideGitRepositoryError(error) {
|
|
142
|
+
return (error instanceof ContextStoreError &&
|
|
143
|
+
error.diagnostic.code === 'context_store_setup_inside_git_repo');
|
|
144
|
+
}
|
|
145
|
+
async function resolveSetupInput(id, options) {
|
|
146
|
+
const interactive = !options.json && isInteractive();
|
|
147
|
+
if (!id && !interactive) {
|
|
148
|
+
throw new ContextStoreError('Pass a context store name.', 'context_store_setup_id_required', {
|
|
149
|
+
target: 'context_store.id',
|
|
150
|
+
fix: 'openspec context-store setup <id> --path /path/to/context-store --json',
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
const resolvedId = id ? validateContextStoreId(id) : await promptContextStoreId();
|
|
154
|
+
const promptedPath = !id && options.path === undefined
|
|
155
|
+
? await promptContextStorePath(resolvedId)
|
|
156
|
+
: undefined;
|
|
157
|
+
return {
|
|
158
|
+
id: resolvedId,
|
|
159
|
+
path: options.path ?? promptedPath,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
async function prepareSetupInput(input, options) {
|
|
163
|
+
try {
|
|
164
|
+
return await prepareContextStoreSetup(input);
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
if (!isSetupInsideGitRepositoryError(error) || options.json || !isInteractive()) {
|
|
168
|
+
throw error;
|
|
169
|
+
}
|
|
170
|
+
const { confirm } = await import('@inquirer/prompts');
|
|
171
|
+
const shouldContinue = await confirm({
|
|
172
|
+
message: `${asErrorMessage(error)}. Use this location anyway?`,
|
|
173
|
+
default: false,
|
|
174
|
+
});
|
|
175
|
+
if (!shouldContinue) {
|
|
176
|
+
throw new ContextStoreError('Context store setup cancelled.', 'context_store_setup_cancelled', {
|
|
177
|
+
target: 'context_store.root',
|
|
178
|
+
fix: 'Choose another path or rerun setup later.',
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
return prepareContextStoreSetup({
|
|
182
|
+
...input,
|
|
183
|
+
allowInsideGitRepository: true,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
async function confirmSetup(prepared, initGit) {
|
|
188
|
+
const { confirm } = await import('@inquirer/prompts');
|
|
189
|
+
console.log('');
|
|
190
|
+
console.log('OpenSpec will create:');
|
|
191
|
+
console.log('');
|
|
192
|
+
console.log(` Context store: ${prepared.id}`);
|
|
193
|
+
console.log(` Location: ${formatPathForHuman(prepared.root)}`);
|
|
194
|
+
console.log(` Git: ${initGit ? 'initialized' : 'not initialized'}`);
|
|
195
|
+
console.log('');
|
|
196
|
+
const confirmed = await confirm({
|
|
197
|
+
message: 'Create this context store?',
|
|
198
|
+
default: true,
|
|
199
|
+
});
|
|
200
|
+
if (!confirmed) {
|
|
201
|
+
throw new ContextStoreError('Context store setup cancelled.', 'context_store_setup_cancelled', {
|
|
202
|
+
target: 'context_store.root',
|
|
203
|
+
fix: 'Rerun setup when you are ready.',
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
async function confirmRemove(id, root, options) {
|
|
208
|
+
if (options.yes)
|
|
209
|
+
return;
|
|
210
|
+
if (options.json || !isInteractive()) {
|
|
211
|
+
throw new ContextStoreError('Pass --yes to delete context-store files non-interactively.', 'context_store_remove_confirmation_required', {
|
|
212
|
+
target: 'context_store.root',
|
|
213
|
+
fix: `openspec context-store remove ${id} --yes`,
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
const { confirm } = await import('@inquirer/prompts');
|
|
217
|
+
const confirmed = await confirm({
|
|
218
|
+
message: `Delete local context-store folder ${formatPathForHuman(root)}?`,
|
|
219
|
+
default: false,
|
|
220
|
+
});
|
|
221
|
+
if (!confirmed) {
|
|
222
|
+
throw new ContextStoreError('Context store remove cancelled.', 'context_store_remove_cancelled', {
|
|
223
|
+
target: 'context_store.root',
|
|
224
|
+
fix: 'Run context-store unregister if you only want to forget the local registration.',
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function printMutationHuman(title, payload) {
|
|
229
|
+
if (!payload.context_store || !payload.registry || !payload.git) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
console.log(`${title}: ${payload.context_store.id}`);
|
|
233
|
+
console.log(`Location: ${formatPathForHuman(payload.context_store.root)}`);
|
|
234
|
+
console.log('');
|
|
235
|
+
console.log(`Next: ask your agent to create an initiative in ${payload.context_store.id}.`);
|
|
236
|
+
}
|
|
237
|
+
function printCleanupHuman(title, payload) {
|
|
238
|
+
if (!payload.context_store || !payload.registry || !payload.files) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
console.log(`${title}: ${payload.context_store.id}`);
|
|
242
|
+
if (payload.files.deleted_path) {
|
|
243
|
+
console.log(`Deleted: ${formatPathForHuman(payload.files.deleted_path)}`);
|
|
244
|
+
}
|
|
245
|
+
else if (payload.files.left_on_disk) {
|
|
246
|
+
console.log(`Files kept at: ${formatPathForHuman(payload.files.left_on_disk)}`);
|
|
247
|
+
}
|
|
248
|
+
else if (!payload.files.deleted) {
|
|
249
|
+
console.log(`Files were already missing: ${formatPathForHuman(payload.context_store.root)}`);
|
|
250
|
+
}
|
|
251
|
+
for (const status of payload.status) {
|
|
252
|
+
console.log(`${status.severity === 'warning' ? 'Note' : 'Issue'}: ${status.message}`);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
function printListHuman(payload) {
|
|
256
|
+
if (payload.context_stores.length === 0) {
|
|
257
|
+
console.log('No context stores registered.');
|
|
258
|
+
console.log('');
|
|
259
|
+
console.log('Next:');
|
|
260
|
+
console.log(' openspec context-store setup team-context');
|
|
261
|
+
console.log(' openspec context-store register /path/to/context-store');
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
console.log(`OpenSpec context stores (${payload.context_stores.length})`);
|
|
265
|
+
console.log('');
|
|
266
|
+
console.log(`${'ID'.padEnd(16)}Location`);
|
|
267
|
+
for (const store of payload.context_stores) {
|
|
268
|
+
console.log(`${store.id.padEnd(16)}${store.root}`);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
function formatMetadataHuman(store) {
|
|
272
|
+
if (store.metadata.valid)
|
|
273
|
+
return 'ok';
|
|
274
|
+
if (store.metadata.present === false)
|
|
275
|
+
return 'missing';
|
|
276
|
+
if (store.metadata.present === null)
|
|
277
|
+
return 'unknown';
|
|
278
|
+
return 'invalid';
|
|
279
|
+
}
|
|
280
|
+
function formatDoctorGitHuman(store) {
|
|
281
|
+
if (store.git.is_repository === null)
|
|
282
|
+
return 'unknown';
|
|
283
|
+
return store.git.is_repository ? 'repository detected' : 'not detected';
|
|
284
|
+
}
|
|
285
|
+
function printDoctorHuman(payload) {
|
|
286
|
+
if (payload.context_stores.length === 0) {
|
|
287
|
+
console.log('No context stores registered.');
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
console.log('Context store doctor');
|
|
291
|
+
for (const store of payload.context_stores) {
|
|
292
|
+
console.log('');
|
|
293
|
+
console.log(store.id);
|
|
294
|
+
console.log(` Location: ${store.root}`);
|
|
295
|
+
console.log(` Metadata: ${formatMetadataHuman(store)}`);
|
|
296
|
+
console.log(` Git: ${formatDoctorGitHuman(store)}`);
|
|
297
|
+
if (store.status.length === 0) {
|
|
298
|
+
console.log(' Issues: none');
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
console.log(' Issues:');
|
|
302
|
+
for (const status of store.status) {
|
|
303
|
+
console.log(` - ${status.message}`);
|
|
304
|
+
if (status.fix) {
|
|
305
|
+
console.log(` Fix: ${status.fix}`);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
class ContextStoreCommand {
|
|
311
|
+
async setup(id, options = {}) {
|
|
312
|
+
try {
|
|
313
|
+
const setupInput = await resolveSetupInput(id, options);
|
|
314
|
+
const prepared = await prepareSetupInput(setupInput, options);
|
|
315
|
+
const initGit = await shouldInitializeGit(options);
|
|
316
|
+
if (!options.json && isInteractive()) {
|
|
317
|
+
await confirmSetup(prepared, initGit);
|
|
318
|
+
}
|
|
319
|
+
const payload = toMutationOutput(await setupPreparedContextStore(prepared, {
|
|
320
|
+
initGit,
|
|
321
|
+
}));
|
|
322
|
+
if (options.json) {
|
|
323
|
+
printJson(payload);
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
printMutationHuman('Context store ready', payload);
|
|
327
|
+
}
|
|
328
|
+
catch (error) {
|
|
329
|
+
this.handleFailure(options.json, { context_store: null, registry: null, git: null, created_files: [], status: [] }, error);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
async register(inputPath, options = {}) {
|
|
333
|
+
try {
|
|
334
|
+
const payload = toMutationOutput(await registerExistingContextStore({
|
|
335
|
+
path: inputPath,
|
|
336
|
+
id: options.id,
|
|
337
|
+
}));
|
|
338
|
+
if (options.json) {
|
|
339
|
+
printJson(payload);
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
printMutationHuman('Context store registered', payload);
|
|
343
|
+
}
|
|
344
|
+
catch (error) {
|
|
345
|
+
this.handleFailure(options.json, { context_store: null, registry: null, git: null, created_files: [], status: [] }, error);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
async unregister(id, options = {}) {
|
|
349
|
+
try {
|
|
350
|
+
const payload = toCleanupOutput(await unregisterContextStore({ id }));
|
|
351
|
+
if (options.json) {
|
|
352
|
+
printJson(payload);
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
printCleanupHuman('Unregistered context store', payload);
|
|
356
|
+
}
|
|
357
|
+
catch (error) {
|
|
358
|
+
this.handleFailure(options.json, { context_store: null, registry: null, files: null, status: [] }, error);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
async remove(id, options = {}) {
|
|
362
|
+
try {
|
|
363
|
+
const target = await prepareContextStoreCleanup({ id });
|
|
364
|
+
await confirmRemove(target.id, target.root, options);
|
|
365
|
+
const payload = toCleanupOutput(await removeContextStore(target));
|
|
366
|
+
if (options.json) {
|
|
367
|
+
printJson(payload);
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
printCleanupHuman('Removed context store', payload);
|
|
371
|
+
}
|
|
372
|
+
catch (error) {
|
|
373
|
+
this.handleFailure(options.json, { context_store: null, registry: null, files: null, status: [] }, error);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
async list(options = {}) {
|
|
377
|
+
try {
|
|
378
|
+
const payload = toListOutput(await listContextStores());
|
|
379
|
+
if (options.json) {
|
|
380
|
+
printJson(payload);
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
printListHuman(payload);
|
|
384
|
+
}
|
|
385
|
+
catch (error) {
|
|
386
|
+
this.handleFailure(options.json, { context_stores: [], status: [] }, error);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
async doctor(id, options = {}) {
|
|
390
|
+
try {
|
|
391
|
+
const payload = toDoctorOutput(await doctorContextStores(id));
|
|
392
|
+
if (options.json) {
|
|
393
|
+
printJson(payload);
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
printDoctorHuman(payload);
|
|
397
|
+
}
|
|
398
|
+
catch (error) {
|
|
399
|
+
this.handleFailure(options.json, { context_stores: [], status: [] }, error);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
handleFailure(json, payload, error) {
|
|
403
|
+
if (!json && isPromptCancellationError(error)) {
|
|
404
|
+
console.error('Cancelled.');
|
|
405
|
+
process.exitCode = 130;
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
const status = asStatus(error);
|
|
409
|
+
if (json) {
|
|
410
|
+
printJson(appendStatus(payload, status));
|
|
411
|
+
process.exitCode = 1;
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
console.error(`Error: ${status.message}`);
|
|
415
|
+
if (status.fix) {
|
|
416
|
+
console.error(`Fix: ${status.fix}`);
|
|
417
|
+
}
|
|
418
|
+
process.exitCode = 1;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
export function registerContextStoreCommand(program) {
|
|
422
|
+
const contextStoreCommand = new ContextStoreCommand();
|
|
423
|
+
const contextStore = program
|
|
424
|
+
.command('context-store')
|
|
425
|
+
.description('Set up and inspect local context stores');
|
|
426
|
+
contextStore
|
|
427
|
+
.command('setup [id]')
|
|
428
|
+
.description('Create and register a local context store')
|
|
429
|
+
.option('--path <path>', 'Context store folder path; defaults to OpenSpec managed local data')
|
|
430
|
+
.option('--init-git', 'Initialize a Git repository in the context store')
|
|
431
|
+
.option('--no-init-git', 'Do not initialize a Git repository')
|
|
432
|
+
.option('--json', 'Output as JSON')
|
|
433
|
+
.action(async (id, options) => {
|
|
434
|
+
await contextStoreCommand.setup(id, options);
|
|
435
|
+
});
|
|
436
|
+
contextStore
|
|
437
|
+
.command('register [path]')
|
|
438
|
+
.description('Register an existing local context store')
|
|
439
|
+
.option('--id <id>', 'Context store id; defaults to metadata or folder name')
|
|
440
|
+
.option('--json', 'Output as JSON')
|
|
441
|
+
.action(async (inputPath, options) => {
|
|
442
|
+
await contextStoreCommand.register(inputPath, options);
|
|
443
|
+
});
|
|
444
|
+
contextStore
|
|
445
|
+
.command('unregister <id>')
|
|
446
|
+
.description('Forget a local context-store registration without deleting files')
|
|
447
|
+
.option('--json', 'Output as JSON')
|
|
448
|
+
.action(async (id, options) => {
|
|
449
|
+
await contextStoreCommand.unregister(id, options);
|
|
450
|
+
});
|
|
451
|
+
contextStore
|
|
452
|
+
.command('remove <id>')
|
|
453
|
+
.description('Forget a local context-store registration and delete its local folder')
|
|
454
|
+
.option('--yes', 'Confirm local context-store folder deletion')
|
|
455
|
+
.option('--json', 'Output as JSON')
|
|
456
|
+
.action(async (id, options) => {
|
|
457
|
+
await contextStoreCommand.remove(id, options);
|
|
458
|
+
});
|
|
459
|
+
contextStore
|
|
460
|
+
.command('list')
|
|
461
|
+
.alias('ls')
|
|
462
|
+
.description('List locally registered context stores')
|
|
463
|
+
.option('--json', 'Output as JSON')
|
|
464
|
+
.action(async (options) => {
|
|
465
|
+
await contextStoreCommand.list(options);
|
|
466
|
+
});
|
|
467
|
+
contextStore
|
|
468
|
+
.command('doctor [id]')
|
|
469
|
+
.description('Check local context-store registration and metadata')
|
|
470
|
+
.option('--json', 'Output as JSON')
|
|
471
|
+
.action(async (id, options) => {
|
|
472
|
+
await contextStoreCommand.doctor(id, options);
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
//# sourceMappingURL=context-store.js.map
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { execSync, execFileSync } from 'child_process';
|
|
2
|
+
import { createRequire } from 'module';
|
|
3
|
+
import os from 'os';
|
|
4
|
+
const require = createRequire(import.meta.url);
|
|
5
|
+
/**
|
|
6
|
+
* Check if gh CLI is installed and available in PATH
|
|
7
|
+
* Uses platform-appropriate command: 'where' on Windows, 'which' on Unix/macOS
|
|
8
|
+
*/
|
|
9
|
+
function isGhInstalled() {
|
|
10
|
+
try {
|
|
11
|
+
const command = process.platform === 'win32' ? 'where gh' : 'which gh';
|
|
12
|
+
execSync(command, { stdio: 'pipe' });
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Check if gh CLI is authenticated
|
|
21
|
+
*/
|
|
22
|
+
function isGhAuthenticated() {
|
|
23
|
+
try {
|
|
24
|
+
execSync('gh auth status', { stdio: 'pipe' });
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get OpenSpec version from package.json
|
|
33
|
+
*/
|
|
34
|
+
function getVersion() {
|
|
35
|
+
try {
|
|
36
|
+
const { version } = require('../../package.json');
|
|
37
|
+
return version;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return 'unknown';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Get platform name
|
|
45
|
+
*/
|
|
46
|
+
function getPlatform() {
|
|
47
|
+
return os.platform();
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Get current timestamp in ISO format
|
|
51
|
+
*/
|
|
52
|
+
function getTimestamp() {
|
|
53
|
+
return new Date().toISOString();
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Generate metadata footer for feedback
|
|
57
|
+
*/
|
|
58
|
+
function generateMetadata() {
|
|
59
|
+
const version = getVersion();
|
|
60
|
+
const platform = getPlatform();
|
|
61
|
+
const timestamp = getTimestamp();
|
|
62
|
+
return `---
|
|
63
|
+
Submitted via OpenSpec CLI
|
|
64
|
+
- Version: ${version}
|
|
65
|
+
- Platform: ${platform}
|
|
66
|
+
- Timestamp: ${timestamp}`;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Format the feedback title
|
|
70
|
+
*/
|
|
71
|
+
function formatTitle(message) {
|
|
72
|
+
return `Feedback: ${message}`;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Format the full feedback body
|
|
76
|
+
*/
|
|
77
|
+
function formatBody(bodyText) {
|
|
78
|
+
const parts = [];
|
|
79
|
+
if (bodyText) {
|
|
80
|
+
parts.push(bodyText);
|
|
81
|
+
parts.push(''); // Empty line before metadata
|
|
82
|
+
}
|
|
83
|
+
parts.push(generateMetadata());
|
|
84
|
+
return parts.join('\n');
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Generate a pre-filled GitHub issue URL for manual submission
|
|
88
|
+
*/
|
|
89
|
+
function generateManualSubmissionUrl(title, body) {
|
|
90
|
+
const repo = 'Fission-AI/OpenSpec';
|
|
91
|
+
const encodedTitle = encodeURIComponent(title);
|
|
92
|
+
const encodedBody = encodeURIComponent(body);
|
|
93
|
+
const encodedLabels = encodeURIComponent('feedback');
|
|
94
|
+
return `https://github.com/${repo}/issues/new?title=${encodedTitle}&body=${encodedBody}&labels=${encodedLabels}`;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Display formatted feedback content for manual submission
|
|
98
|
+
*/
|
|
99
|
+
function displayFormattedFeedback(title, body) {
|
|
100
|
+
console.log('\n--- 格式化反馈 ---');
|
|
101
|
+
console.log(`标题:${title}`);
|
|
102
|
+
console.log(`标签:feedback`);
|
|
103
|
+
console.log('\n内容:');
|
|
104
|
+
console.log(body);
|
|
105
|
+
console.log('--- 反馈结束 ---\n');
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Submit feedback via gh CLI
|
|
109
|
+
* Uses execFileSync to prevent shell injection vulnerabilities
|
|
110
|
+
*/
|
|
111
|
+
function submitViaGhCli(title, body) {
|
|
112
|
+
try {
|
|
113
|
+
const result = execFileSync('gh', [
|
|
114
|
+
'issue',
|
|
115
|
+
'create',
|
|
116
|
+
'--repo',
|
|
117
|
+
'Fission-AI/OpenSpec',
|
|
118
|
+
'--title',
|
|
119
|
+
title,
|
|
120
|
+
'--body',
|
|
121
|
+
body,
|
|
122
|
+
'--label',
|
|
123
|
+
'feedback',
|
|
124
|
+
], { encoding: 'utf-8', stdio: 'pipe' });
|
|
125
|
+
const issueUrl = result.trim();
|
|
126
|
+
console.log(`\n✓ 反馈提交成功!`);
|
|
127
|
+
console.log(`问题链接:${issueUrl}\n`);
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
// Display the error output from gh CLI
|
|
131
|
+
if (error.stderr) {
|
|
132
|
+
console.error(error.stderr.toString());
|
|
133
|
+
}
|
|
134
|
+
else if (error.message) {
|
|
135
|
+
console.error(error.message);
|
|
136
|
+
}
|
|
137
|
+
// Exit with the same code as gh CLI
|
|
138
|
+
process.exit(error.status ?? 1);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Handle fallback when gh CLI is not available or not authenticated
|
|
143
|
+
*/
|
|
144
|
+
function handleFallback(title, body, reason) {
|
|
145
|
+
if (reason === 'missing') {
|
|
146
|
+
console.log('⚠️ 未找到 GitHub CLI。需要手动提交。');
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
console.log('⚠️ 需要 GitHub 认证。需要手动提交。');
|
|
150
|
+
}
|
|
151
|
+
displayFormattedFeedback(title, body);
|
|
152
|
+
const manualUrl = generateManualSubmissionUrl(title, body);
|
|
153
|
+
console.log('请手动提交你的反馈:');
|
|
154
|
+
console.log(manualUrl);
|
|
155
|
+
if (reason === 'unauthenticated') {
|
|
156
|
+
console.log('\nTo auto-submit in the future: gh auth login');
|
|
157
|
+
}
|
|
158
|
+
// Exit with success code (fallback is successful)
|
|
159
|
+
process.exit(0);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Feedback command implementation
|
|
163
|
+
*/
|
|
164
|
+
export class FeedbackCommand {
|
|
165
|
+
async execute(message, options) {
|
|
166
|
+
// Format title and body once for all code paths
|
|
167
|
+
const title = formatTitle(message);
|
|
168
|
+
const body = formatBody(options?.body);
|
|
169
|
+
// Check if gh CLI is installed
|
|
170
|
+
if (!isGhInstalled()) {
|
|
171
|
+
handleFallback(title, body, 'missing');
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
// Check if gh CLI is authenticated
|
|
175
|
+
if (!isGhAuthenticated()) {
|
|
176
|
+
handleFallback(title, body, 'unauthenticated');
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
// Submit via gh CLI
|
|
180
|
+
submitViaGhCli(title, body);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=feedback.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { type InitiativeResolutionDetails, type InitiativeDiagnostic } from '../core/collections/initiatives/index.js';
|
|
3
|
+
export declare class InitiativeCliError extends Error {
|
|
4
|
+
readonly diagnostic: InitiativeDiagnostic;
|
|
5
|
+
constructor(message: string, code: string, options?: {
|
|
6
|
+
target?: string;
|
|
7
|
+
fix?: string;
|
|
8
|
+
details?: InitiativeResolutionDetails;
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
export declare function initiativeDiagnosticFromError(error: unknown): InitiativeDiagnostic;
|
|
12
|
+
export declare function registerInitiativeCommand(program: Command): void;
|
|
13
|
+
//# sourceMappingURL=initiative.d.ts.map
|