@kbdavis07/openspec 1.5.0-nov.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 +239 -0
- package/bin/openspec.js +5 -0
- package/dist/cli/index.d.ts +10 -0
- package/dist/cli/index.js +544 -0
- package/dist/commands/change.d.ts +38 -0
- package/dist/commands/change.js +245 -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 +552 -0
- package/dist/commands/context.d.ts +3 -0
- package/dist/commands/context.js +155 -0
- package/dist/commands/doctor.d.ts +8 -0
- package/dist/commands/doctor.js +163 -0
- package/dist/commands/feedback.d.ts +9 -0
- package/dist/commands/feedback.js +183 -0
- package/dist/commands/schema.d.ts +6 -0
- package/dist/commands/schema.js +869 -0
- package/dist/commands/shared-gather.d.ts +14 -0
- package/dist/commands/shared-gather.js +31 -0
- package/dist/commands/shared-output.d.ts +18 -0
- package/dist/commands/shared-output.js +61 -0
- package/dist/commands/show.d.ts +19 -0
- package/dist/commands/show.js +177 -0
- package/dist/commands/spec.d.ts +19 -0
- package/dist/commands/spec.js +236 -0
- package/dist/commands/store.d.ts +3 -0
- package/dist/commands/store.js +547 -0
- package/dist/commands/validate.d.ts +34 -0
- package/dist/commands/validate.js +342 -0
- package/dist/commands/workflow/index.d.ts +17 -0
- package/dist/commands/workflow/index.js +12 -0
- package/dist/commands/workflow/instructions.d.ts +39 -0
- package/dist/commands/workflow/instructions.js +393 -0
- package/dist/commands/workflow/new-change.d.ts +20 -0
- package/dist/commands/workflow/new-change.js +109 -0
- package/dist/commands/workflow/schemas.d.ts +10 -0
- package/dist/commands/workflow/schemas.js +34 -0
- package/dist/commands/workflow/shared.d.ts +74 -0
- package/dist/commands/workflow/shared.js +170 -0
- package/dist/commands/workflow/status.d.ts +16 -0
- package/dist/commands/workflow/status.js +92 -0
- package/dist/commands/workflow/templates.d.ts +16 -0
- package/dist/commands/workflow/templates.js +69 -0
- package/dist/commands/workset-input.d.ts +19 -0
- package/dist/commands/workset-input.js +112 -0
- package/dist/commands/workset-prompts.d.ts +12 -0
- package/dist/commands/workset-prompts.js +143 -0
- package/dist/commands/workset.d.ts +25 -0
- package/dist/commands/workset.js +446 -0
- package/dist/core/archive.d.ts +22 -0
- package/dist/core/archive.js +496 -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 +188 -0
- package/dist/core/artifact-graph/instruction-loader.js +233 -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 +19 -0
- package/dist/core/change-metadata/schema.js +30 -0
- package/dist/core/change-status-policy.d.ts +37 -0
- package/dist/core/change-status-policy.js +35 -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 +32 -0
- package/dist/core/command-generation/adapters/claude.d.ts +13 -0
- package/dist/core/command-generation/adapters/claude.js +39 -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 +31 -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 +34 -0
- package/dist/core/command-generation/adapters/index.js +34 -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/oh-my-pi.d.ts +21 -0
- package/dist/core/command-generation/adapters/oh-my-pi.js +44 -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 +42 -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/trae.d.ts +13 -0
- package/dist/core/command-generation/adapters/trae.js +48 -0
- package/dist/core/command-generation/adapters/windsurf.d.ts +14 -0
- package/dist/core/command-generation/adapters/windsurf.js +38 -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 +102 -0
- package/dist/core/command-generation/types.d.ts +56 -0
- package/dist/core/command-generation/types.js +8 -0
- package/dist/core/command-generation/yaml.d.ts +22 -0
- package/dist/core/command-generation/yaml.js +38 -0
- package/dist/core/completions/command-registry.d.ts +3 -0
- package/dist/core/completions/command-registry.js +759 -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 +276 -0
- package/dist/core/completions/installers/bash-installer.d.ts +87 -0
- package/dist/core/completions/installers/bash-installer.js +321 -0
- package/dist/core/completions/installers/fish-installer.d.ts +43 -0
- package/dist/core/completions/installers/fish-installer.js +151 -0
- package/dist/core/completions/installers/powershell-installer.d.ts +102 -0
- package/dist/core/completions/installers/powershell-installer.js +415 -0
- package/dist/core/completions/installers/zsh-installer.d.ts +117 -0
- package/dist/core/completions/installers/zsh-installer.js +424 -0
- package/dist/core/completions/shared-flags.d.ts +13 -0
- package/dist/core/completions/shared-flags.js +33 -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 +87 -0
- package/dist/core/config-schema.js +239 -0
- package/dist/core/config.d.ts +18 -0
- package/dist/core/config.js +40 -0
- package/dist/core/converters/json-converter.d.ts +6 -0
- package/dist/core/converters/json-converter.js +51 -0
- package/dist/core/file-state.d.ts +36 -0
- package/dist/core/file-state.js +112 -0
- package/dist/core/global-config.d.ts +51 -0
- package/dist/core/global-config.js +124 -0
- package/dist/core/id.d.ts +17 -0
- package/dist/core/id.js +30 -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 +614 -0
- package/dist/core/legacy-cleanup.d.ts +162 -0
- package/dist/core/legacy-cleanup.js +514 -0
- package/dist/core/list.d.ts +11 -0
- package/dist/core/list.js +214 -0
- package/dist/core/migration.d.ts +23 -0
- package/dist/core/migration.js +108 -0
- package/dist/core/openers.d.ts +77 -0
- package/dist/core/openers.js +251 -0
- package/dist/core/openspec-root.d.ts +45 -0
- package/dist/core/openspec-root.js +195 -0
- package/dist/core/parsers/change-parser.d.ts +13 -0
- package/dist/core/parsers/change-parser.js +198 -0
- package/dist/core/parsers/markdown-parser.d.ts +23 -0
- package/dist/core/parsers/markdown-parser.js +173 -0
- package/dist/core/parsers/requirement-blocks.d.ts +48 -0
- package/dist/core/parsers/requirement-blocks.js +235 -0
- package/dist/core/parsers/requirement-text.d.ts +55 -0
- package/dist/core/parsers/requirement-text.js +136 -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 +16 -0
- package/dist/core/planning-home.js +67 -0
- package/dist/core/profile-sync-drift.d.ts +38 -0
- package/dist/core/profile-sync-drift.js +201 -0
- package/dist/core/profiles.d.ts +26 -0
- package/dist/core/profiles.js +41 -0
- package/dist/core/project-config.d.ts +107 -0
- package/dist/core/project-config.js +373 -0
- package/dist/core/references.d.ts +63 -0
- package/dist/core/references.js +310 -0
- package/dist/core/relationship-health.d.ts +65 -0
- package/dist/core/relationship-health.js +64 -0
- package/dist/core/root-selection.d.ts +122 -0
- package/dist/core/root-selection.js +337 -0
- package/dist/core/schemas/base.schema.d.ts +13 -0
- package/dist/core/schemas/base.schema.js +18 -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/allowed-tools.d.ts +12 -0
- package/dist/core/shared/allowed-tools.js +12 -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 +100 -0
- package/dist/core/shared/tool-detection.d.ts +71 -0
- package/dist/core/shared/tool-detection.js +160 -0
- package/dist/core/specs-apply.d.ts +78 -0
- package/dist/core/specs-apply.js +428 -0
- package/dist/core/store/errors.d.ts +20 -0
- package/dist/core/store/errors.js +22 -0
- package/dist/core/store/foundation.d.ts +56 -0
- package/dist/core/store/foundation.js +251 -0
- package/dist/core/store/git.d.ts +23 -0
- package/dist/core/store/git.js +137 -0
- package/dist/core/store/index.d.ts +5 -0
- package/dist/core/store/index.js +5 -0
- package/dist/core/store/operations.d.ts +114 -0
- package/dist/core/store/operations.js +803 -0
- package/dist/core/store/registry.d.ts +58 -0
- package/dist/core/store/registry.js +275 -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 +20 -0
- package/dist/core/templates/skill-templates.js +19 -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 +315 -0
- package/dist/core/templates/workflows/archive-change.d.ts +10 -0
- package/dist/core/templates/workflows/archive-change.js +278 -0
- package/dist/core/templates/workflows/bulk-archive-change.d.ts +10 -0
- package/dist/core/templates/workflows/bulk-archive-change.js +493 -0
- package/dist/core/templates/workflows/continue-change.d.ts +10 -0
- package/dist/core/templates/workflows/continue-change.js +239 -0
- package/dist/core/templates/workflows/explore.d.ts +10 -0
- package/dist/core/templates/workflows/explore.js +464 -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 +205 -0
- package/dist/core/templates/workflows/new-change.d.ts +10 -0
- package/dist/core/templates/workflows/new-change.js +148 -0
- package/dist/core/templates/workflows/onboard.d.ts +10 -0
- package/dist/core/templates/workflows/onboard.js +566 -0
- package/dist/core/templates/workflows/propose.d.ts +10 -0
- package/dist/core/templates/workflows/propose.js +223 -0
- package/dist/core/templates/workflows/store-selection.d.ts +8 -0
- package/dist/core/templates/workflows/store-selection.js +8 -0
- package/dist/core/templates/workflows/sync-specs.d.ts +10 -0
- package/dist/core/templates/workflows/sync-specs.js +291 -0
- package/dist/core/templates/workflows/update-change.d.ts +10 -0
- package/dist/core/templates/workflows/update-change.js +167 -0
- package/dist/core/templates/workflows/verify-change.d.ts +10 -0
- package/dist/core/templates/workflows/verify-change.js +339 -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 +51 -0
- package/dist/core/validation/validator.js +498 -0
- package/dist/core/view.d.ts +8 -0
- package/dist/core/view.js +168 -0
- package/dist/core/working-set.d.ts +47 -0
- package/dist/core/working-set.js +43 -0
- package/dist/core/worksets.d.ts +75 -0
- package/dist/core/worksets.js +245 -0
- package/dist/core/zod-issues.d.ts +4 -0
- package/dist/core/zod-issues.js +10 -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 +55 -0
- package/dist/utils/change-metadata.js +141 -0
- package/dist/utils/change-utils.d.ts +85 -0
- package/dist/utils/change-utils.js +173 -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 +320 -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 +17 -0
- package/dist/utils/task-progress.js +100 -0
- package/package.json +85 -0
- package/schemas/spec-driven/schema.yaml +153 -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/scripts/postinstall.js +83 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import { getTaskProgressForChange } from '../utils/task-progress.js';
|
|
5
|
+
import { MarkdownParser } from './parsers/markdown-parser.js';
|
|
6
|
+
export class ViewCommand {
|
|
7
|
+
async execute(targetPath = '.') {
|
|
8
|
+
const openspecDir = path.join(targetPath, 'openspec');
|
|
9
|
+
if (!fs.existsSync(openspecDir)) {
|
|
10
|
+
console.error(chalk.red('No openspec directory found'));
|
|
11
|
+
process.exit(1);
|
|
12
|
+
}
|
|
13
|
+
console.log(chalk.bold('\nOpenSpec Dashboard\n'));
|
|
14
|
+
console.log('═'.repeat(60));
|
|
15
|
+
// Get changes and specs data
|
|
16
|
+
const changesData = await this.getChangesData(openspecDir);
|
|
17
|
+
const specsData = await this.getSpecsData(openspecDir);
|
|
18
|
+
// Display summary metrics
|
|
19
|
+
this.displaySummary(changesData, specsData);
|
|
20
|
+
// Display draft changes
|
|
21
|
+
if (changesData.draft.length > 0) {
|
|
22
|
+
console.log(chalk.bold.gray('\nDraft Changes'));
|
|
23
|
+
console.log('─'.repeat(60));
|
|
24
|
+
changesData.draft.forEach((change) => {
|
|
25
|
+
console.log(` ${chalk.gray('○')} ${change.name}`);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
// Display active changes
|
|
29
|
+
if (changesData.active.length > 0) {
|
|
30
|
+
console.log(chalk.bold.cyan('\nActive Changes'));
|
|
31
|
+
console.log('─'.repeat(60));
|
|
32
|
+
changesData.active.forEach((change) => {
|
|
33
|
+
const progressBar = this.createProgressBar(change.progress.completed, change.progress.total);
|
|
34
|
+
const percentage = change.progress.total > 0
|
|
35
|
+
? Math.round((change.progress.completed / change.progress.total) * 100)
|
|
36
|
+
: 0;
|
|
37
|
+
console.log(` ${chalk.yellow('◉')} ${chalk.bold(change.name.padEnd(30))} ${progressBar} ${chalk.dim(`${percentage}%`)}`);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
// Display completed changes
|
|
41
|
+
if (changesData.completed.length > 0) {
|
|
42
|
+
console.log(chalk.bold.green('\nCompleted Changes'));
|
|
43
|
+
console.log('─'.repeat(60));
|
|
44
|
+
changesData.completed.forEach((change) => {
|
|
45
|
+
console.log(` ${chalk.green('✓')} ${change.name}`);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
// Display specifications
|
|
49
|
+
if (specsData.length > 0) {
|
|
50
|
+
console.log(chalk.bold.blue('\nSpecifications'));
|
|
51
|
+
console.log('─'.repeat(60));
|
|
52
|
+
// Sort specs by requirement count (descending)
|
|
53
|
+
specsData.sort((a, b) => b.requirementCount - a.requirementCount);
|
|
54
|
+
specsData.forEach(spec => {
|
|
55
|
+
const reqLabel = spec.requirementCount === 1 ? 'requirement' : 'requirements';
|
|
56
|
+
console.log(` ${chalk.blue('▪')} ${chalk.bold(spec.name.padEnd(30))} ${chalk.dim(`${spec.requirementCount} ${reqLabel}`)}`);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
console.log('\n' + '═'.repeat(60));
|
|
60
|
+
console.log(chalk.dim(`\nUse ${chalk.white('openspec list --changes')} or ${chalk.white('openspec list --specs')} for detailed views`));
|
|
61
|
+
}
|
|
62
|
+
async getChangesData(openspecDir) {
|
|
63
|
+
const changesDir = path.join(openspecDir, 'changes');
|
|
64
|
+
if (!fs.existsSync(changesDir)) {
|
|
65
|
+
return { draft: [], active: [], completed: [] };
|
|
66
|
+
}
|
|
67
|
+
const draft = [];
|
|
68
|
+
const active = [];
|
|
69
|
+
const completed = [];
|
|
70
|
+
const entries = fs.readdirSync(changesDir, { withFileTypes: true });
|
|
71
|
+
for (const entry of entries) {
|
|
72
|
+
if (entry.isDirectory() && entry.name !== 'archive') {
|
|
73
|
+
const progress = await getTaskProgressForChange(changesDir, entry.name, path.dirname(openspecDir));
|
|
74
|
+
if (progress.total === 0) {
|
|
75
|
+
// No tasks defined yet - still in planning/draft phase
|
|
76
|
+
draft.push({ name: entry.name });
|
|
77
|
+
}
|
|
78
|
+
else if (progress.completed === progress.total) {
|
|
79
|
+
// All tasks complete
|
|
80
|
+
completed.push({ name: entry.name });
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
// Has tasks but not all complete
|
|
84
|
+
active.push({ name: entry.name, progress });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// Sort all categories by name for deterministic ordering
|
|
89
|
+
draft.sort((a, b) => a.name.localeCompare(b.name));
|
|
90
|
+
// Sort active changes by completion percentage (ascending) and then by name
|
|
91
|
+
active.sort((a, b) => {
|
|
92
|
+
const percentageA = a.progress.total > 0 ? a.progress.completed / a.progress.total : 0;
|
|
93
|
+
const percentageB = b.progress.total > 0 ? b.progress.completed / b.progress.total : 0;
|
|
94
|
+
if (percentageA < percentageB)
|
|
95
|
+
return -1;
|
|
96
|
+
if (percentageA > percentageB)
|
|
97
|
+
return 1;
|
|
98
|
+
return a.name.localeCompare(b.name);
|
|
99
|
+
});
|
|
100
|
+
completed.sort((a, b) => a.name.localeCompare(b.name));
|
|
101
|
+
return { draft, active, completed };
|
|
102
|
+
}
|
|
103
|
+
async getSpecsData(openspecDir) {
|
|
104
|
+
const specsDir = path.join(openspecDir, 'specs');
|
|
105
|
+
if (!fs.existsSync(specsDir)) {
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
const specs = [];
|
|
109
|
+
const entries = fs.readdirSync(specsDir, { withFileTypes: true });
|
|
110
|
+
for (const entry of entries) {
|
|
111
|
+
if (entry.isDirectory()) {
|
|
112
|
+
const specFile = path.join(specsDir, entry.name, 'spec.md');
|
|
113
|
+
if (fs.existsSync(specFile)) {
|
|
114
|
+
try {
|
|
115
|
+
const content = fs.readFileSync(specFile, 'utf-8');
|
|
116
|
+
const parser = new MarkdownParser(content);
|
|
117
|
+
const spec = parser.parseSpec(entry.name);
|
|
118
|
+
const requirementCount = spec.requirements.length;
|
|
119
|
+
specs.push({ name: entry.name, requirementCount });
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
// If spec cannot be parsed, include with 0 count
|
|
123
|
+
specs.push({ name: entry.name, requirementCount: 0 });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return specs;
|
|
129
|
+
}
|
|
130
|
+
displaySummary(changesData, specsData) {
|
|
131
|
+
const totalChanges = changesData.draft.length + changesData.active.length + changesData.completed.length;
|
|
132
|
+
const totalSpecs = specsData.length;
|
|
133
|
+
const totalRequirements = specsData.reduce((sum, spec) => sum + spec.requirementCount, 0);
|
|
134
|
+
// Calculate total task progress
|
|
135
|
+
let totalTasks = 0;
|
|
136
|
+
let completedTasks = 0;
|
|
137
|
+
changesData.active.forEach((change) => {
|
|
138
|
+
totalTasks += change.progress.total;
|
|
139
|
+
completedTasks += change.progress.completed;
|
|
140
|
+
});
|
|
141
|
+
changesData.completed.forEach(() => {
|
|
142
|
+
// Completed changes count as 100% done (we don't know exact task count)
|
|
143
|
+
// This is a simplification
|
|
144
|
+
});
|
|
145
|
+
console.log(chalk.bold('Summary:'));
|
|
146
|
+
console.log(` ${chalk.cyan('●')} Specifications: ${chalk.bold(totalSpecs)} specs, ${chalk.bold(totalRequirements)} requirements`);
|
|
147
|
+
if (changesData.draft.length > 0) {
|
|
148
|
+
console.log(` ${chalk.gray('●')} Draft Changes: ${chalk.bold(changesData.draft.length)}`);
|
|
149
|
+
}
|
|
150
|
+
console.log(` ${chalk.yellow('●')} Active Changes: ${chalk.bold(changesData.active.length)} in progress`);
|
|
151
|
+
console.log(` ${chalk.green('●')} Completed Changes: ${chalk.bold(changesData.completed.length)}`);
|
|
152
|
+
if (totalTasks > 0) {
|
|
153
|
+
const overallProgress = Math.round((completedTasks / totalTasks) * 100);
|
|
154
|
+
console.log(` ${chalk.magenta('●')} Task Progress: ${chalk.bold(`${completedTasks}/${totalTasks}`)} (${overallProgress}% complete)`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
createProgressBar(completed, total, width = 20) {
|
|
158
|
+
if (total === 0)
|
|
159
|
+
return chalk.dim('─'.repeat(width));
|
|
160
|
+
const percentage = completed / total;
|
|
161
|
+
const filled = Math.round(percentage * width);
|
|
162
|
+
const empty = width - filled;
|
|
163
|
+
const filledBar = chalk.green('█'.repeat(filled));
|
|
164
|
+
const emptyBar = chalk.dim('░'.repeat(empty));
|
|
165
|
+
return `[${filledBar}${emptyBar}]`;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=view.js.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Working-set assembly (slice 4.1): the full set a root's declarations
|
|
3
|
+
* describe — the OpenSpec root and its referenced stores — as an
|
|
4
|
+
* agent-consumable brief. A local convenience
|
|
5
|
+
* computed from declared relationships, never a planning system; no
|
|
6
|
+
* clone/sync/launch machinery. Unresolvable members are reported, not
|
|
7
|
+
* guessed.
|
|
8
|
+
*/
|
|
9
|
+
import type { StoreDiagnostic } from './store/errors.js';
|
|
10
|
+
import { type ReferenceIndexEntry } from './references.js';
|
|
11
|
+
import { type ResolvedOpenSpecRoot } from './root-selection.js';
|
|
12
|
+
export type WorkingSetRole = 'referenced_store';
|
|
13
|
+
export interface WorkingSetMember {
|
|
14
|
+
role: WorkingSetRole;
|
|
15
|
+
id: string;
|
|
16
|
+
path?: string;
|
|
17
|
+
remote?: string;
|
|
18
|
+
fetch?: string;
|
|
19
|
+
status: StoreDiagnostic[];
|
|
20
|
+
}
|
|
21
|
+
export interface WorkingSet {
|
|
22
|
+
root: {
|
|
23
|
+
path: string;
|
|
24
|
+
source: ResolvedOpenSpecRoot['source'];
|
|
25
|
+
store_id?: string;
|
|
26
|
+
role: 'openspec_root';
|
|
27
|
+
};
|
|
28
|
+
members: WorkingSetMember[];
|
|
29
|
+
status: StoreDiagnostic[];
|
|
30
|
+
}
|
|
31
|
+
export interface AssembleWorkingSetInput {
|
|
32
|
+
root: ResolvedOpenSpecRoot;
|
|
33
|
+
referenceEntries: ReferenceIndexEntry[];
|
|
34
|
+
/** The composition's top-level status; the working set keeps only
|
|
35
|
+
* the registry-unreadable degradation (selected by code, never by
|
|
36
|
+
* position). */
|
|
37
|
+
topLevelStatus?: StoreDiagnostic[];
|
|
38
|
+
}
|
|
39
|
+
/** AVAILABLE = path present AND per-entry status empty. */
|
|
40
|
+
export declare function isAvailableMember(member: WorkingSetMember): boolean;
|
|
41
|
+
export declare function assembleWorkingSet(input: AssembleWorkingSetInput): WorkingSet;
|
|
42
|
+
/**
|
|
43
|
+
* Pure builder for the `.code-workspace` editor view — one consumer of
|
|
44
|
+
* assembly, not the feature. Available members only.
|
|
45
|
+
*/
|
|
46
|
+
export declare function buildCodeWorkspaceJson(workingSet: WorkingSet, rootName: string): string;
|
|
47
|
+
//# sourceMappingURL=working-set.d.ts.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { fetchRecipe } from './references.js';
|
|
2
|
+
import { toRootOutput } from './root-selection.js';
|
|
3
|
+
/** AVAILABLE = path present AND per-entry status empty. */
|
|
4
|
+
export function isAvailableMember(member) {
|
|
5
|
+
return member.path !== undefined && member.status.length === 0;
|
|
6
|
+
}
|
|
7
|
+
export function assembleWorkingSet(input) {
|
|
8
|
+
const members = [];
|
|
9
|
+
for (const entry of input.referenceEntries) {
|
|
10
|
+
members.push({
|
|
11
|
+
role: 'referenced_store',
|
|
12
|
+
id: entry.store_id,
|
|
13
|
+
...(entry.root !== undefined ? { path: entry.root } : {}),
|
|
14
|
+
...(entry.root !== undefined && entry.status.length === 0
|
|
15
|
+
? { fetch: fetchRecipe(entry.store_id) }
|
|
16
|
+
: {}),
|
|
17
|
+
status: entry.status,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
const status = (input.topLevelStatus ?? []).filter((entry) => entry.code === 'relationship_registry_unreadable');
|
|
21
|
+
return {
|
|
22
|
+
root: { ...toRootOutput(input.root), role: 'openspec_root' },
|
|
23
|
+
members,
|
|
24
|
+
status,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Pure builder for the `.code-workspace` editor view — one consumer of
|
|
29
|
+
* assembly, not the feature. Available members only.
|
|
30
|
+
*/
|
|
31
|
+
export function buildCodeWorkspaceJson(workingSet, rootName) {
|
|
32
|
+
const folders = [
|
|
33
|
+
{ name: rootName, path: workingSet.root.path },
|
|
34
|
+
];
|
|
35
|
+
for (const member of workingSet.members) {
|
|
36
|
+
if (!isAvailableMember(member)) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
folders.push({ name: `ref:${member.id}`, path: member.path });
|
|
40
|
+
}
|
|
41
|
+
return JSON.stringify({ folders }, null, 2) + '\n';
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=working-set.js.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { StoreError } from './store/errors.js';
|
|
2
|
+
/**
|
|
3
|
+
* Personal worksets (slice 7.1): purely local, manually composed,
|
|
4
|
+
* named working views. The whole feature's state lives under
|
|
5
|
+
* <globalDataDir>/worksets/ - the saved-views file plus the generated
|
|
6
|
+
* .code-workspace files - so deleting that one directory removes
|
|
7
|
+
* every trace. Nothing here is committed, shared, or derived from
|
|
8
|
+
* declarations, and nothing is ever written into a member folder.
|
|
9
|
+
*/
|
|
10
|
+
export declare const WORKSETS_DIR_NAME = "worksets";
|
|
11
|
+
export declare const WORKSETS_FILE_NAME = "worksets.yaml";
|
|
12
|
+
export interface WorksetPathOptions {
|
|
13
|
+
globalDataDir?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface WorksetMember {
|
|
16
|
+
/** Display label; the .code-workspace folder name. */
|
|
17
|
+
name: string;
|
|
18
|
+
/** Absolute path to the member directory. */
|
|
19
|
+
path: string;
|
|
20
|
+
}
|
|
21
|
+
export interface Workset {
|
|
22
|
+
name: string;
|
|
23
|
+
/** Preferred opener id; validated only at open time. */
|
|
24
|
+
tool?: string;
|
|
25
|
+
/** Ordered; the first member is the primary (session cwd). */
|
|
26
|
+
members: WorksetMember[];
|
|
27
|
+
}
|
|
28
|
+
export interface WorksetsState {
|
|
29
|
+
version: 1;
|
|
30
|
+
worksets: Record<string, {
|
|
31
|
+
tool?: string;
|
|
32
|
+
members: WorksetMember[];
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
export declare function getWorksetsDir(options?: WorksetPathOptions): string;
|
|
36
|
+
export declare function getWorksetsFilePath(options?: WorksetPathOptions): string;
|
|
37
|
+
export declare function getWorksetCodeWorkspacePath(name: string, options?: WorksetPathOptions): string;
|
|
38
|
+
export declare function validateWorksetName(name: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* Returns a problem description for a member list, or null when valid.
|
|
41
|
+
* Shared by the file parser (wrapping as invalid_workset_file) and the
|
|
42
|
+
* compose flow (wrapping as workset_member_invalid).
|
|
43
|
+
*/
|
|
44
|
+
export declare function memberListProblem(members: WorksetMember[]): string | null;
|
|
45
|
+
export declare function memberLabelProblem(label: string): string | null;
|
|
46
|
+
export declare function parseWorksetsState(content: string, options?: WorksetPathOptions): WorksetsState;
|
|
47
|
+
export declare function serializeWorksetsState(state: WorksetsState, options?: WorksetPathOptions): string;
|
|
48
|
+
/** Absent file reads as the empty state; a corrupt file throws. */
|
|
49
|
+
export declare function readWorksetsState(options?: WorksetPathOptions): Promise<WorksetsState>;
|
|
50
|
+
export declare function updateWorksetsState(updater: (state: WorksetsState) => WorksetsState | Promise<WorksetsState>, options?: WorksetPathOptions): Promise<WorksetsState>;
|
|
51
|
+
/**
|
|
52
|
+
* Lock-scoped read without a write-back of the saved-views file.
|
|
53
|
+
* `open` uses this to read the state and regenerate the derived
|
|
54
|
+
* .code-workspace coherently; the lock is released before any spawn.
|
|
55
|
+
*/
|
|
56
|
+
export declare function withWorksetsLock<T>(fn: (state: WorksetsState) => T | Promise<T>, options?: WorksetPathOptions): Promise<T>;
|
|
57
|
+
export declare function worksetNotFoundError(name: string, state: WorksetsState): StoreError;
|
|
58
|
+
export declare function withWorkset(state: WorksetsState, workset: Workset): WorksetsState;
|
|
59
|
+
export declare function withoutWorkset(state: WorksetsState, name: string): WorksetsState;
|
|
60
|
+
/**
|
|
61
|
+
* Removes a saved workset and its derived .code-workspace under one
|
|
62
|
+
* lock. The derived-file cleanup runs AFTER the durable write (a
|
|
63
|
+
* failed write must not have already destroyed the artifact); a
|
|
64
|
+
* never-opened workset has no file - ENOENT is fine.
|
|
65
|
+
*/
|
|
66
|
+
export declare function removeWorkset(name: string, options?: WorksetPathOptions): Promise<void>;
|
|
67
|
+
export declare function listWorksets(state: WorksetsState): Workset[];
|
|
68
|
+
export declare function getWorkset(state: WorksetsState, name: string): Workset | null;
|
|
69
|
+
/**
|
|
70
|
+
* The generated .code-workspace content: members in saved order with
|
|
71
|
+
* their saved names, absolute paths, two-space JSON, trailing newline
|
|
72
|
+
* (the working-set builder's conventions).
|
|
73
|
+
*/
|
|
74
|
+
export declare function buildWorksetCodeWorkspaceJson(members: WorksetMember[]): string;
|
|
75
|
+
//# sourceMappingURL=worksets.d.ts.map
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import * as nodeFs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { parse as parseYaml, stringify as stringifyYaml } from 'yaml';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { getGlobalDataDir } from './global-config.js';
|
|
6
|
+
import { FileSystemUtils } from '../utils/file-system.js';
|
|
7
|
+
import { acquireFileLock, makeLockErrorFactory, pathIsFile, releaseFileLock, writeFileAtomically, } from './file-state.js';
|
|
8
|
+
import { StoreError } from './store/errors.js';
|
|
9
|
+
import { folderStyleNameProblem, isKebabId, KEBAB_ID_DESCRIPTION, KEBAB_ID_FIX, } from './id.js';
|
|
10
|
+
import { formatZodIssues } from './zod-issues.js';
|
|
11
|
+
const fs = nodeFs.promises;
|
|
12
|
+
/**
|
|
13
|
+
* Personal worksets (slice 7.1): purely local, manually composed,
|
|
14
|
+
* named working views. The whole feature's state lives under
|
|
15
|
+
* <globalDataDir>/worksets/ - the saved-views file plus the generated
|
|
16
|
+
* .code-workspace files - so deleting that one directory removes
|
|
17
|
+
* every trace. Nothing here is committed, shared, or derived from
|
|
18
|
+
* declarations, and nothing is ever written into a member folder.
|
|
19
|
+
*/
|
|
20
|
+
export const WORKSETS_DIR_NAME = 'worksets';
|
|
21
|
+
export const WORKSETS_FILE_NAME = 'worksets.yaml';
|
|
22
|
+
const CODE_WORKSPACE_EXTENSION = '.code-workspace';
|
|
23
|
+
export function getWorksetsDir(options = {}) {
|
|
24
|
+
return FileSystemUtils.joinPath(options.globalDataDir ?? getGlobalDataDir(), WORKSETS_DIR_NAME);
|
|
25
|
+
}
|
|
26
|
+
export function getWorksetsFilePath(options = {}) {
|
|
27
|
+
return FileSystemUtils.joinPath(getWorksetsDir(options), WORKSETS_FILE_NAME);
|
|
28
|
+
}
|
|
29
|
+
export function getWorksetCodeWorkspacePath(name, options = {}) {
|
|
30
|
+
return FileSystemUtils.joinPath(getWorksetsDir(options), `${name}${CODE_WORKSPACE_EXTENSION}`);
|
|
31
|
+
}
|
|
32
|
+
export function validateWorksetName(name) {
|
|
33
|
+
if (!isKebabId(name)) {
|
|
34
|
+
throw new StoreError(`Workset name '${name}' ${KEBAB_ID_DESCRIPTION}.`, 'invalid_workset_name', {
|
|
35
|
+
target: 'workset.name',
|
|
36
|
+
fix: KEBAB_ID_FIX,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return name;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Returns a problem description for a member list, or null when valid.
|
|
43
|
+
* Shared by the file parser (wrapping as invalid_workset_file) and the
|
|
44
|
+
* compose flow (wrapping as workset_member_invalid).
|
|
45
|
+
*/
|
|
46
|
+
export function memberListProblem(members) {
|
|
47
|
+
if (members.length === 0) {
|
|
48
|
+
return 'members must not be empty';
|
|
49
|
+
}
|
|
50
|
+
const seen = new Set();
|
|
51
|
+
for (const member of members) {
|
|
52
|
+
const labelProblem = memberLabelProblem(member.name);
|
|
53
|
+
if (labelProblem !== null) {
|
|
54
|
+
return labelProblem;
|
|
55
|
+
}
|
|
56
|
+
if (seen.has(member.name)) {
|
|
57
|
+
return `duplicate member name '${member.name}' (use the name=path form to label members distinctly)`;
|
|
58
|
+
}
|
|
59
|
+
seen.add(member.name);
|
|
60
|
+
if (!path.isAbsolute(member.path)) {
|
|
61
|
+
return `member path '${member.path}' must be absolute`;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
export function memberLabelProblem(label) {
|
|
67
|
+
return folderStyleNameProblem(label, 'member name');
|
|
68
|
+
}
|
|
69
|
+
const WorksetMemberSchema = z
|
|
70
|
+
.object({
|
|
71
|
+
name: z.string(),
|
|
72
|
+
path: z.string(),
|
|
73
|
+
})
|
|
74
|
+
.strict();
|
|
75
|
+
const WorksetEntrySchema = z
|
|
76
|
+
.object({
|
|
77
|
+
tool: z.string().min(1).optional(),
|
|
78
|
+
members: z.array(WorksetMemberSchema),
|
|
79
|
+
})
|
|
80
|
+
.strict();
|
|
81
|
+
const WorksetsStateSchema = z
|
|
82
|
+
.object({
|
|
83
|
+
version: z.literal(1),
|
|
84
|
+
worksets: z.record(z.string(), WorksetEntrySchema),
|
|
85
|
+
})
|
|
86
|
+
.strict();
|
|
87
|
+
function invalidWorksetsFileError(message, options) {
|
|
88
|
+
return new StoreError(`Invalid worksets file: ${message}`, 'invalid_workset_file', {
|
|
89
|
+
target: 'workset.file',
|
|
90
|
+
fix: `Repair or remove ${getWorksetsFilePath(options)}.`,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
export function parseWorksetsState(content, options = {}) {
|
|
94
|
+
let raw;
|
|
95
|
+
try {
|
|
96
|
+
raw = parseYaml(content);
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
100
|
+
throw invalidWorksetsFileError(message, options);
|
|
101
|
+
}
|
|
102
|
+
const result = WorksetsStateSchema.safeParse(raw);
|
|
103
|
+
if (!result.success) {
|
|
104
|
+
throw invalidWorksetsFileError(formatZodIssues(result.error), options);
|
|
105
|
+
}
|
|
106
|
+
for (const [name, entry] of Object.entries(result.data.worksets)) {
|
|
107
|
+
if (!isKebabId(name)) {
|
|
108
|
+
throw invalidWorksetsFileError(`workset name '${name}' ${KEBAB_ID_DESCRIPTION}`, options);
|
|
109
|
+
}
|
|
110
|
+
const problem = memberListProblem(entry.members);
|
|
111
|
+
if (problem !== null) {
|
|
112
|
+
throw invalidWorksetsFileError(`workset '${name}': ${problem}`, options);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return result.data;
|
|
116
|
+
}
|
|
117
|
+
export function serializeWorksetsState(state, options = {}) {
|
|
118
|
+
const result = WorksetsStateSchema.safeParse(state);
|
|
119
|
+
if (!result.success) {
|
|
120
|
+
throw invalidWorksetsFileError(formatZodIssues(result.error), options);
|
|
121
|
+
}
|
|
122
|
+
// The strict schema already guarantees the entry shape; the sort is
|
|
123
|
+
// the only real work here.
|
|
124
|
+
return stringifyYaml({
|
|
125
|
+
version: 1,
|
|
126
|
+
worksets: Object.fromEntries(Object.entries(result.data.worksets).sort(([a], [b]) => a.localeCompare(b))),
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
/** Absent file reads as the empty state; a corrupt file throws. */
|
|
130
|
+
export async function readWorksetsState(options = {}) {
|
|
131
|
+
const filePath = getWorksetsFilePath(options);
|
|
132
|
+
if (!(await pathIsFile(filePath))) {
|
|
133
|
+
return { version: 1, worksets: {} };
|
|
134
|
+
}
|
|
135
|
+
return parseWorksetsState(await fs.readFile(filePath, 'utf-8'), options);
|
|
136
|
+
}
|
|
137
|
+
const worksetsLockError = makeLockErrorFactory({
|
|
138
|
+
createSubject: 'the worksets lock file',
|
|
139
|
+
busyMessage: 'The worksets file is busy.',
|
|
140
|
+
code: 'workset_file_busy',
|
|
141
|
+
target: 'workset.file',
|
|
142
|
+
});
|
|
143
|
+
export async function updateWorksetsState(updater, options = {}) {
|
|
144
|
+
return withWorksetsLock(async (state) => {
|
|
145
|
+
const next = await updater(state);
|
|
146
|
+
await writeFileAtomically(getWorksetsFilePath(options), serializeWorksetsState(next, options));
|
|
147
|
+
return next;
|
|
148
|
+
}, options);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Lock-scoped read without a write-back of the saved-views file.
|
|
152
|
+
* `open` uses this to read the state and regenerate the derived
|
|
153
|
+
* .code-workspace coherently; the lock is released before any spawn.
|
|
154
|
+
*/
|
|
155
|
+
export async function withWorksetsLock(fn, options = {}) {
|
|
156
|
+
const lockPath = `${getWorksetsFilePath(options)}.lock`;
|
|
157
|
+
const lock = await acquireFileLock({
|
|
158
|
+
lockPath,
|
|
159
|
+
errorFor: worksetsLockError,
|
|
160
|
+
});
|
|
161
|
+
try {
|
|
162
|
+
return await fn(await readWorksetsState(options));
|
|
163
|
+
}
|
|
164
|
+
finally {
|
|
165
|
+
await releaseFileLock(lock, lockPath);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
export function worksetNotFoundError(name, state) {
|
|
169
|
+
const savedNames = Object.keys(state.worksets).sort((a, b) => a.localeCompare(b));
|
|
170
|
+
return new StoreError(`Workset '${name}' is not saved on this machine.`, 'workset_not_found', {
|
|
171
|
+
target: 'workset.name',
|
|
172
|
+
fix: savedNames.length > 0
|
|
173
|
+
? `Saved worksets: ${savedNames.join(', ')}. See them with: openspec workset list`
|
|
174
|
+
: `Create it first: openspec workset create ${name}`,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
export function withWorkset(state, workset) {
|
|
178
|
+
if (state.worksets[workset.name] !== undefined) {
|
|
179
|
+
throw new StoreError(`Workset '${workset.name}' already exists.`, 'workset_exists', {
|
|
180
|
+
target: 'workset.name',
|
|
181
|
+
fix: `Choose another name, or remove it first: openspec workset remove ${workset.name}`,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
version: 1,
|
|
186
|
+
worksets: {
|
|
187
|
+
...state.worksets,
|
|
188
|
+
[workset.name]: {
|
|
189
|
+
...(workset.tool !== undefined ? { tool: workset.tool } : {}),
|
|
190
|
+
members: workset.members,
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
export function withoutWorkset(state, name) {
|
|
196
|
+
if (state.worksets[name] === undefined) {
|
|
197
|
+
throw worksetNotFoundError(name, state);
|
|
198
|
+
}
|
|
199
|
+
const remaining = { ...state.worksets };
|
|
200
|
+
delete remaining[name];
|
|
201
|
+
return { version: 1, worksets: remaining };
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Removes a saved workset and its derived .code-workspace under one
|
|
205
|
+
* lock. The derived-file cleanup runs AFTER the durable write (a
|
|
206
|
+
* failed write must not have already destroyed the artifact); a
|
|
207
|
+
* never-opened workset has no file - ENOENT is fine.
|
|
208
|
+
*/
|
|
209
|
+
export async function removeWorkset(name, options = {}) {
|
|
210
|
+
await withWorksetsLock(async (state) => {
|
|
211
|
+
const next = withoutWorkset(state, name);
|
|
212
|
+
await writeFileAtomically(getWorksetsFilePath(options), serializeWorksetsState(next, options));
|
|
213
|
+
await fs.rm(getWorksetCodeWorkspacePath(name, options), { force: true });
|
|
214
|
+
}, options);
|
|
215
|
+
}
|
|
216
|
+
function toWorkset(name, entry) {
|
|
217
|
+
return {
|
|
218
|
+
name,
|
|
219
|
+
...(entry.tool !== undefined ? { tool: entry.tool } : {}),
|
|
220
|
+
members: entry.members,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
export function listWorksets(state) {
|
|
224
|
+
return Object.entries(state.worksets)
|
|
225
|
+
.map(([name, entry]) => toWorkset(name, entry))
|
|
226
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
227
|
+
}
|
|
228
|
+
export function getWorkset(state, name) {
|
|
229
|
+
const entry = state.worksets[name];
|
|
230
|
+
return entry === undefined ? null : toWorkset(name, entry);
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* The generated .code-workspace content: members in saved order with
|
|
234
|
+
* their saved names, absolute paths, two-space JSON, trailing newline
|
|
235
|
+
* (the working-set builder's conventions).
|
|
236
|
+
*/
|
|
237
|
+
export function buildWorksetCodeWorkspaceJson(members) {
|
|
238
|
+
return (JSON.stringify({
|
|
239
|
+
folders: members.map((member) => ({
|
|
240
|
+
name: member.name,
|
|
241
|
+
path: member.path,
|
|
242
|
+
})),
|
|
243
|
+
}, null, 2) + '\n');
|
|
244
|
+
}
|
|
245
|
+
//# sourceMappingURL=worksets.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** One rendering for zod issues across every state/config parser. */
|
|
2
|
+
export function formatZodIssues(error, fallbackLocation = 'root') {
|
|
3
|
+
return error.issues
|
|
4
|
+
.map((issue) => {
|
|
5
|
+
const location = issue.path.length > 0 ? issue.path.join('.') : fallbackLocation;
|
|
6
|
+
return `${location}: ${issue.message}`;
|
|
7
|
+
})
|
|
8
|
+
.join('; ');
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=zod-issues.js.map
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
interface Choice {
|
|
2
|
+
name: string;
|
|
3
|
+
value: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
configured?: boolean;
|
|
6
|
+
detected?: boolean;
|
|
7
|
+
configuredLabel?: string;
|
|
8
|
+
preSelected?: boolean;
|
|
9
|
+
}
|
|
10
|
+
interface Config {
|
|
11
|
+
message: string;
|
|
12
|
+
choices: Choice[];
|
|
13
|
+
pageSize?: number;
|
|
14
|
+
validate?: (selected: string[]) => boolean | string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A searchable multi-select prompt with visible search box,
|
|
18
|
+
* selected items display, and intuitive keyboard navigation.
|
|
19
|
+
*
|
|
20
|
+
* - Type to filter choices
|
|
21
|
+
* - ↑↓ to navigate
|
|
22
|
+
* - Space to toggle highlighted item selection
|
|
23
|
+
* - Backspace to remove last selected item (or delete search char)
|
|
24
|
+
* - Enter to confirm selections
|
|
25
|
+
*/
|
|
26
|
+
export declare function searchableMultiSelect(config: Config): Promise<string[]>;
|
|
27
|
+
export default searchableMultiSelect;
|
|
28
|
+
//# sourceMappingURL=searchable-multi-select.d.ts.map
|