@thiagodiogo/pastelsdd 1.0.0-beta.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 +3 -0
- package/bin/pastelsdd.js +5 -0
- package/dist/cli/index.d.ts +5 -0
- package/dist/cli/index.js +526 -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 +282 -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-view.d.ts +62 -0
- package/dist/commands/workspace/open-view.js +228 -0
- package/dist/commands/workspace/open.d.ts +37 -0
- package/dist/commands/workspace/open.js +102 -0
- package/dist/commands/workspace/opener-selection.d.ts +11 -0
- package/dist/commands/workspace/opener-selection.js +93 -0
- package/dist/commands/workspace/operations.d.ts +28 -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 +6 -0
- package/dist/commands/workspace/selection.js +122 -0
- package/dist/commands/workspace/types.d.ts +103 -0
- package/dist/commands/workspace/types.js +36 -0
- package/dist/commands/workspace.d.ts +6 -0
- package/dist/commands/workspace.js +678 -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 +939 -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 +38 -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 +54 -0
- package/dist/core/context-store/foundation.js +318 -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 +62 -0
- package/dist/core/context-store/operations.js +352 -0
- package/dist/core/context-store/registry.d.ts +35 -0
- package/dist/core/context-store/registry.js +158 -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 +33 -0
- package/dist/core/validation/validator.js +418 -0
- package/dist/core/view.d.ts +8 -0
- package/dist/core/view.js +168 -0
- package/dist/core/workspace/foundation.d.ts +62 -0
- package/dist/core/workspace/foundation.js +274 -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 +43 -0
- package/dist/core/workspace/open-surface.js +214 -0
- package/dist/core/workspace/openers.d.ts +21 -0
- package/dist/core/workspace/openers.js +119 -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 +119 -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 +84 -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/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,197 @@
|
|
|
1
|
+
import { getContextStoreMetadataPath, readOptionalContextStoreMetadataState, resolveGitContextStoreBackendConfig, validateContextStoreId, } from './foundation.js';
|
|
2
|
+
import { ContextStoreError } from './errors.js';
|
|
3
|
+
import { resolveRegisteredContextStore, } from './registry.js';
|
|
4
|
+
export function createRegisteredContextStoreBinding(id) {
|
|
5
|
+
const validatedId = validateContextStoreId(id);
|
|
6
|
+
return {
|
|
7
|
+
id: validatedId,
|
|
8
|
+
selector: {
|
|
9
|
+
kind: 'registry',
|
|
10
|
+
id: validatedId,
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function createPathContextStoreBinding(input) {
|
|
15
|
+
const id = validateContextStoreId(input.id);
|
|
16
|
+
if (input.path.length === 0) {
|
|
17
|
+
throw new Error('Context store binding path must not be empty.');
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
id,
|
|
21
|
+
selector: {
|
|
22
|
+
kind: 'path',
|
|
23
|
+
path: input.path,
|
|
24
|
+
observed_id: id,
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export function normalizeContextStoreBinding(binding) {
|
|
29
|
+
const id = validateContextStoreId(binding.id);
|
|
30
|
+
if (binding.selector.kind === 'registry') {
|
|
31
|
+
return createRegisteredContextStoreBinding(binding.selector.id);
|
|
32
|
+
}
|
|
33
|
+
if (binding.selector.path.length === 0) {
|
|
34
|
+
throw new Error('Context store binding path must not be empty.');
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
id,
|
|
38
|
+
selector: {
|
|
39
|
+
kind: 'path',
|
|
40
|
+
path: binding.selector.path,
|
|
41
|
+
...(binding.selector.observed_id
|
|
42
|
+
? { observed_id: validateContextStoreId(binding.selector.observed_id) }
|
|
43
|
+
: {}),
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export function sameContextStoreBinding(left, right) {
|
|
48
|
+
const normalizedLeft = normalizeContextStoreBinding(left);
|
|
49
|
+
const normalizedRight = normalizeContextStoreBinding(right);
|
|
50
|
+
if (normalizedLeft.selector.kind !== normalizedRight.selector.kind) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
if (normalizedLeft.selector.kind === 'registry' &&
|
|
54
|
+
normalizedRight.selector.kind === 'registry') {
|
|
55
|
+
return normalizedLeft.selector.id === normalizedRight.selector.id;
|
|
56
|
+
}
|
|
57
|
+
if (normalizedLeft.selector.kind === 'path' &&
|
|
58
|
+
normalizedRight.selector.kind === 'path') {
|
|
59
|
+
return normalizedLeft.selector.path === normalizedRight.selector.path;
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
export function formatContextStoreBinding(binding) {
|
|
64
|
+
const normalized = normalizeContextStoreBinding(binding);
|
|
65
|
+
if (normalized.selector.kind === 'registry') {
|
|
66
|
+
return normalized.selector.id;
|
|
67
|
+
}
|
|
68
|
+
return `${normalized.id} via ${normalized.selector.path}`;
|
|
69
|
+
}
|
|
70
|
+
export function formatContextStoreBindingSelector(binding) {
|
|
71
|
+
const normalized = normalizeContextStoreBinding(binding);
|
|
72
|
+
return normalized.selector.kind === 'registry'
|
|
73
|
+
? `--store ${normalized.selector.id}`
|
|
74
|
+
: `--store-path ${normalized.selector.path}`;
|
|
75
|
+
}
|
|
76
|
+
export function formatContextStoreSelector(selected) {
|
|
77
|
+
return selected.source === 'registry'
|
|
78
|
+
? `--store ${selected.id}`
|
|
79
|
+
: `--store-path ${selected.root}`;
|
|
80
|
+
}
|
|
81
|
+
export function createContextStoreBindingFromSelected(selected) {
|
|
82
|
+
return selected.source === 'registry'
|
|
83
|
+
? createRegisteredContextStoreBinding(selected.id)
|
|
84
|
+
: createPathContextStoreBinding({
|
|
85
|
+
id: selected.id,
|
|
86
|
+
path: selected.root,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function validateSelectorConflict(options, commandName) {
|
|
90
|
+
if (options.store !== undefined && options.storePath !== undefined) {
|
|
91
|
+
throw new ContextStoreError('Pass either --store <id> or --store-path <path>, not both.', 'context_store_selector_conflict', {
|
|
92
|
+
target: 'context_store',
|
|
93
|
+
fix: `pastelsdd ${commandName} --store <id>`,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
export function requireContextStoreSelector(options, commandName) {
|
|
98
|
+
validateSelectorConflict(options, commandName);
|
|
99
|
+
if (options.store === undefined && options.storePath === undefined) {
|
|
100
|
+
throw new ContextStoreError('Pass --store <id> or --store-path <path>.', 'context_store_required', {
|
|
101
|
+
target: 'context_store',
|
|
102
|
+
fix: `pastelsdd ${commandName} --store <id>`,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
export async function resolveSelectedContextStore(options, commandName, pathOptions = {}) {
|
|
107
|
+
requireContextStoreSelector(options, commandName);
|
|
108
|
+
if (options.store !== undefined) {
|
|
109
|
+
const resolved = await resolveRegisteredContextStore({
|
|
110
|
+
id: options.store,
|
|
111
|
+
globalDataDir: pathOptions.globalDataDir,
|
|
112
|
+
});
|
|
113
|
+
return {
|
|
114
|
+
id: resolved.id,
|
|
115
|
+
root: resolved.storeRoot,
|
|
116
|
+
source: 'registry',
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
const storePath = options.storePath ?? '';
|
|
120
|
+
let root;
|
|
121
|
+
try {
|
|
122
|
+
const backend = await resolveGitContextStoreBackendConfig({
|
|
123
|
+
localPath: storePath,
|
|
124
|
+
});
|
|
125
|
+
root = backend.local_path;
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
throw new ContextStoreError(error instanceof Error ? error.message : String(error), 'invalid_context_store_path', {
|
|
129
|
+
target: 'context_store.path',
|
|
130
|
+
fix: 'Pass an existing context store root.',
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
let metadata;
|
|
134
|
+
try {
|
|
135
|
+
metadata = await readOptionalContextStoreMetadataState(root);
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
throw new ContextStoreError(error instanceof Error ? error.message : String(error), 'invalid_context_store_metadata', {
|
|
139
|
+
target: 'context_store.metadata',
|
|
140
|
+
fix: `Fix ${getContextStoreMetadataPath(root)} before using this store.`,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
if (!metadata) {
|
|
144
|
+
throw new ContextStoreError(`Context store metadata not found at ${getContextStoreMetadataPath(root)}`, 'context_store_metadata_not_found', {
|
|
145
|
+
target: 'context_store.metadata',
|
|
146
|
+
fix: 'Pass a context store root that contains .pastelsdd-store/store.yaml.',
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
id: metadata.id,
|
|
151
|
+
root,
|
|
152
|
+
source: 'path',
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
export async function resolveContextStoreBinding(binding, options = {}) {
|
|
156
|
+
const normalized = normalizeContextStoreBinding(binding);
|
|
157
|
+
if (normalized.selector.kind === 'registry') {
|
|
158
|
+
const registered = await resolveRegisteredContextStore({
|
|
159
|
+
id: normalized.selector.id,
|
|
160
|
+
globalDataDir: options.globalDataDir,
|
|
161
|
+
});
|
|
162
|
+
return {
|
|
163
|
+
binding: normalized,
|
|
164
|
+
id: registered.id,
|
|
165
|
+
root: registered.storeRoot,
|
|
166
|
+
source: 'registry',
|
|
167
|
+
registered,
|
|
168
|
+
warnings: [],
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
const backend = await resolveGitContextStoreBackendConfig({
|
|
172
|
+
localPath: normalized.selector.path,
|
|
173
|
+
});
|
|
174
|
+
const root = backend.local_path;
|
|
175
|
+
const metadata = await readOptionalContextStoreMetadataState(root);
|
|
176
|
+
if (!metadata) {
|
|
177
|
+
throw new Error(`Context store metadata not found at ${getContextStoreMetadataPath(root)}`);
|
|
178
|
+
}
|
|
179
|
+
const warnings = [];
|
|
180
|
+
const observedId = normalized.selector.observed_id ?? normalized.id;
|
|
181
|
+
if (metadata.id !== observedId) {
|
|
182
|
+
warnings.push({
|
|
183
|
+
code: 'context_store_binding_id_changed',
|
|
184
|
+
message: `Context store at ${root} now reports id '${metadata.id}' instead of '${observedId}'.`,
|
|
185
|
+
target: 'metadata.id',
|
|
186
|
+
fix: `Review ${getContextStoreMetadataPath(root)} or re-open the workspace with the intended context store.`,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
return {
|
|
190
|
+
binding: normalized,
|
|
191
|
+
id: metadata.id,
|
|
192
|
+
root,
|
|
193
|
+
source: 'path',
|
|
194
|
+
warnings,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=binding.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type ContextStoreDiagnosticSeverity = 'error' | 'warning';
|
|
2
|
+
export interface ContextStoreDiagnostic {
|
|
3
|
+
severity: ContextStoreDiagnosticSeverity;
|
|
4
|
+
code: string;
|
|
5
|
+
message: string;
|
|
6
|
+
target?: string;
|
|
7
|
+
fix?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class ContextStoreError extends Error {
|
|
10
|
+
readonly diagnostic: ContextStoreDiagnostic;
|
|
11
|
+
constructor(message: string, code: string, options?: {
|
|
12
|
+
target?: string;
|
|
13
|
+
fix?: string;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
export declare function makeContextStoreDiagnostic(severity: ContextStoreDiagnosticSeverity, code: string, message: string, options?: {
|
|
17
|
+
target?: string;
|
|
18
|
+
fix?: string;
|
|
19
|
+
}): ContextStoreDiagnostic;
|
|
20
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export class ContextStoreError extends Error {
|
|
2
|
+
diagnostic;
|
|
3
|
+
constructor(message, code, options = {}) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = 'ContextStoreError';
|
|
6
|
+
this.diagnostic = {
|
|
7
|
+
severity: 'error',
|
|
8
|
+
code,
|
|
9
|
+
message,
|
|
10
|
+
...options,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function makeContextStoreDiagnostic(severity, code, message, options = {}) {
|
|
15
|
+
return {
|
|
16
|
+
severity,
|
|
17
|
+
code,
|
|
18
|
+
message,
|
|
19
|
+
...options,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export declare const CONTEXT_STORE_METADATA_DIR_NAME = ".pastelsdd-store";
|
|
2
|
+
export declare const CONTEXT_STORE_METADATA_FILE_NAME = "store.yaml";
|
|
3
|
+
export declare const CONTEXT_STORES_DIR_NAME = "context-stores";
|
|
4
|
+
export declare const CONTEXT_STORE_REGISTRY_FILE_NAME = "registry.yaml";
|
|
5
|
+
export interface ContextStorePathOptions {
|
|
6
|
+
globalDataDir?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface ContextStoreGitBackendConfig {
|
|
9
|
+
type: 'git';
|
|
10
|
+
local_path: string;
|
|
11
|
+
remote?: string;
|
|
12
|
+
branch?: string;
|
|
13
|
+
}
|
|
14
|
+
export type ContextStoreBackendConfig = ContextStoreGitBackendConfig;
|
|
15
|
+
export interface ContextStoreRegistryEntryState {
|
|
16
|
+
backend: ContextStoreBackendConfig;
|
|
17
|
+
}
|
|
18
|
+
export interface ContextStoreRegistryState {
|
|
19
|
+
version: 1;
|
|
20
|
+
stores: Record<string, ContextStoreRegistryEntryState>;
|
|
21
|
+
}
|
|
22
|
+
export interface ContextStoreRegistryEntry {
|
|
23
|
+
id: string;
|
|
24
|
+
backend: ContextStoreBackendConfig;
|
|
25
|
+
}
|
|
26
|
+
export interface ContextStoreMetadataState {
|
|
27
|
+
version: 1;
|
|
28
|
+
id: string;
|
|
29
|
+
}
|
|
30
|
+
export interface ResolveGitContextStoreBackendInput {
|
|
31
|
+
localPath: string;
|
|
32
|
+
remote?: string;
|
|
33
|
+
branch?: string;
|
|
34
|
+
}
|
|
35
|
+
export declare function getContextStoresDir(options?: ContextStorePathOptions): string;
|
|
36
|
+
export declare function getContextStoreRegistryPath(options?: ContextStorePathOptions): string;
|
|
37
|
+
export declare function getContextStoreMetadataDir(storeRoot: string): string;
|
|
38
|
+
export declare function getContextStoreMetadataPath(storeRoot: string): string;
|
|
39
|
+
export declare function validateContextStoreId(id: string): string;
|
|
40
|
+
export declare function isValidContextStoreId(id: string): boolean;
|
|
41
|
+
export declare function parseContextStoreRegistryState(content: string): ContextStoreRegistryState;
|
|
42
|
+
export declare function parseContextStoreMetadataState(content: string): ContextStoreMetadataState;
|
|
43
|
+
export declare function serializeContextStoreRegistryState(state: ContextStoreRegistryState): string;
|
|
44
|
+
export declare function serializeContextStoreMetadataState(state: ContextStoreMetadataState): string;
|
|
45
|
+
export declare function listContextStoreRegistryEntries(registry: ContextStoreRegistryState): ContextStoreRegistryEntry[];
|
|
46
|
+
export declare function isContextStoreRoot(candidateRoot: string): Promise<boolean>;
|
|
47
|
+
export declare function readContextStoreRegistryState(options?: ContextStorePathOptions): Promise<ContextStoreRegistryState | null>;
|
|
48
|
+
export declare function writeContextStoreRegistryState(state: ContextStoreRegistryState, options?: ContextStorePathOptions): Promise<void>;
|
|
49
|
+
export declare function updateContextStoreRegistryState(updater: (state: ContextStoreRegistryState | null) => ContextStoreRegistryState, options?: ContextStorePathOptions): Promise<ContextStoreRegistryState>;
|
|
50
|
+
export declare function readContextStoreMetadataState(storeRoot: string): Promise<ContextStoreMetadataState>;
|
|
51
|
+
export declare function readOptionalContextStoreMetadataState(storeRoot: string): Promise<ContextStoreMetadataState | null>;
|
|
52
|
+
export declare function writeContextStoreMetadataState(storeRoot: string, state: ContextStoreMetadataState): Promise<void>;
|
|
53
|
+
export declare function resolveGitContextStoreBackendConfig(input: ResolveGitContextStoreBackendInput, cwd?: string): Promise<ContextStoreGitBackendConfig>;
|
|
54
|
+
//# sourceMappingURL=foundation.d.ts.map
|
|
@@ -0,0 +1,318 @@
|
|
|
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 { ContextStoreError } from './errors.js';
|
|
8
|
+
const fs = nodeFs.promises;
|
|
9
|
+
export const CONTEXT_STORE_METADATA_DIR_NAME = '.pastelsdd-store';
|
|
10
|
+
export const CONTEXT_STORE_METADATA_FILE_NAME = 'store.yaml';
|
|
11
|
+
export const CONTEXT_STORES_DIR_NAME = 'context-stores';
|
|
12
|
+
export const CONTEXT_STORE_REGISTRY_FILE_NAME = 'registry.yaml';
|
|
13
|
+
function joinContextStorePath(basePath, ...segments) {
|
|
14
|
+
return FileSystemUtils.joinPath(basePath, ...segments);
|
|
15
|
+
}
|
|
16
|
+
export function getContextStoresDir(options = {}) {
|
|
17
|
+
return joinContextStorePath(options.globalDataDir ?? getGlobalDataDir(), CONTEXT_STORES_DIR_NAME);
|
|
18
|
+
}
|
|
19
|
+
export function getContextStoreRegistryPath(options = {}) {
|
|
20
|
+
return joinContextStorePath(getContextStoresDir(options), CONTEXT_STORE_REGISTRY_FILE_NAME);
|
|
21
|
+
}
|
|
22
|
+
export function getContextStoreMetadataDir(storeRoot) {
|
|
23
|
+
return joinContextStorePath(storeRoot, CONTEXT_STORE_METADATA_DIR_NAME);
|
|
24
|
+
}
|
|
25
|
+
export function getContextStoreMetadataPath(storeRoot) {
|
|
26
|
+
return joinContextStorePath(getContextStoreMetadataDir(storeRoot), CONTEXT_STORE_METADATA_FILE_NAME);
|
|
27
|
+
}
|
|
28
|
+
function validateFolderStyleName(name, label) {
|
|
29
|
+
if (name.length === 0) {
|
|
30
|
+
throw new Error(`${label} must not be empty`);
|
|
31
|
+
}
|
|
32
|
+
if (name === '.' || name === '..') {
|
|
33
|
+
throw new Error(`${label} must not be '${name}'`);
|
|
34
|
+
}
|
|
35
|
+
if (/[\\/]/u.test(name)) {
|
|
36
|
+
throw new Error(`${label} must not contain path separators`);
|
|
37
|
+
}
|
|
38
|
+
return name;
|
|
39
|
+
}
|
|
40
|
+
export function validateContextStoreId(id) {
|
|
41
|
+
try {
|
|
42
|
+
validateFolderStyleName(id, 'Context store id');
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
throw new ContextStoreError(error instanceof Error ? error.message : String(error), 'invalid_context_store_id', {
|
|
46
|
+
target: 'context_store.id',
|
|
47
|
+
fix: 'Use kebab-case with lowercase letters, numbers, and single hyphen separators.',
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/u.test(id)) {
|
|
51
|
+
throw new ContextStoreError('Context store id must be kebab-case with lowercase letters, numbers, and single hyphen separators', 'invalid_context_store_id', {
|
|
52
|
+
target: 'context_store.id',
|
|
53
|
+
fix: 'Use kebab-case with lowercase letters, numbers, and single hyphen separators.',
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return id;
|
|
57
|
+
}
|
|
58
|
+
export function isValidContextStoreId(id) {
|
|
59
|
+
try {
|
|
60
|
+
validateContextStoreId(id);
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async function pathIsFile(filePath) {
|
|
68
|
+
try {
|
|
69
|
+
return (await fs.stat(filePath)).isFile();
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async function pathIsDirectory(dirPath) {
|
|
76
|
+
try {
|
|
77
|
+
return (await fs.stat(dirPath)).isDirectory();
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function isFileNotFoundError(error) {
|
|
84
|
+
return isNodeErrorCode(error, 'ENOENT');
|
|
85
|
+
}
|
|
86
|
+
function isNodeErrorCode(error, code) {
|
|
87
|
+
return (typeof error === 'object' &&
|
|
88
|
+
error !== null &&
|
|
89
|
+
'code' in error &&
|
|
90
|
+
error.code === code);
|
|
91
|
+
}
|
|
92
|
+
function normalizeExistingPathForStorage(existingPath) {
|
|
93
|
+
return FileSystemUtils.canonicalizeExistingPath(existingPath);
|
|
94
|
+
}
|
|
95
|
+
function nonEmptyOptionalString() {
|
|
96
|
+
return z.string().min(1).optional();
|
|
97
|
+
}
|
|
98
|
+
const GitBackendConfigSchema = z.object({
|
|
99
|
+
type: z.literal('git'),
|
|
100
|
+
local_path: z.string().min(1),
|
|
101
|
+
remote: nonEmptyOptionalString(),
|
|
102
|
+
branch: nonEmptyOptionalString(),
|
|
103
|
+
}).strict();
|
|
104
|
+
const RegistryEntrySchema = z.object({
|
|
105
|
+
backend: GitBackendConfigSchema,
|
|
106
|
+
}).strict();
|
|
107
|
+
const RegistryStateSchema = z.object({
|
|
108
|
+
version: z.literal(1),
|
|
109
|
+
stores: z.record(z.string(), RegistryEntrySchema),
|
|
110
|
+
}).strict();
|
|
111
|
+
const MetadataStateSchema = z.object({
|
|
112
|
+
version: z.literal(1),
|
|
113
|
+
id: z.string(),
|
|
114
|
+
}).strict();
|
|
115
|
+
function formatZodIssues(error) {
|
|
116
|
+
return error.issues
|
|
117
|
+
.map((issue) => {
|
|
118
|
+
const location = issue.path.length > 0 ? issue.path.join('.') : 'root';
|
|
119
|
+
return `${location}: ${issue.message}`;
|
|
120
|
+
})
|
|
121
|
+
.join('; ');
|
|
122
|
+
}
|
|
123
|
+
function contextStoreStateDiagnostic(label) {
|
|
124
|
+
if (label.includes('metadata')) {
|
|
125
|
+
return {
|
|
126
|
+
code: 'invalid_context_store_metadata',
|
|
127
|
+
target: 'context_store.metadata',
|
|
128
|
+
fix: 'Repair .pastelsdd-store/store.yaml.',
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
code: 'invalid_context_store_registry',
|
|
133
|
+
target: 'context_store.registry',
|
|
134
|
+
fix: 'Repair or remove the context-store registry file.',
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function invalidContextStoreStateError(label, message) {
|
|
138
|
+
const diagnostic = contextStoreStateDiagnostic(label);
|
|
139
|
+
return new ContextStoreError(`Invalid ${label}: ${message}`, diagnostic.code, {
|
|
140
|
+
target: diagnostic.target,
|
|
141
|
+
fix: diagnostic.fix,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
function parseYamlObject(content, label) {
|
|
145
|
+
try {
|
|
146
|
+
return parseYaml(content);
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
150
|
+
throw invalidContextStoreStateError(label, message);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function assertValidContextStoreIds(ids, label) {
|
|
154
|
+
for (const id of ids) {
|
|
155
|
+
try {
|
|
156
|
+
validateContextStoreId(id);
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
160
|
+
throw invalidContextStoreStateError(label, `'${id}': ${message}`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
export function parseContextStoreRegistryState(content) {
|
|
165
|
+
const raw = parseYamlObject(content, 'context store registry state');
|
|
166
|
+
const result = RegistryStateSchema.safeParse(raw);
|
|
167
|
+
if (!result.success) {
|
|
168
|
+
throw invalidContextStoreStateError('context store registry state', formatZodIssues(result.error));
|
|
169
|
+
}
|
|
170
|
+
assertValidContextStoreIds(Object.keys(result.data.stores), 'context store id');
|
|
171
|
+
return {
|
|
172
|
+
version: 1,
|
|
173
|
+
stores: result.data.stores,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
export function parseContextStoreMetadataState(content) {
|
|
177
|
+
const raw = parseYamlObject(content, 'context store metadata state');
|
|
178
|
+
const result = MetadataStateSchema.safeParse(raw);
|
|
179
|
+
if (!result.success) {
|
|
180
|
+
throw invalidContextStoreStateError('context store metadata state', formatZodIssues(result.error));
|
|
181
|
+
}
|
|
182
|
+
validateContextStoreId(result.data.id);
|
|
183
|
+
return {
|
|
184
|
+
version: 1,
|
|
185
|
+
id: result.data.id,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
export function serializeContextStoreRegistryState(state) {
|
|
189
|
+
const result = RegistryStateSchema.safeParse(state);
|
|
190
|
+
if (!result.success) {
|
|
191
|
+
throw invalidContextStoreStateError('context store registry state', formatZodIssues(result.error));
|
|
192
|
+
}
|
|
193
|
+
assertValidContextStoreIds(Object.keys(result.data.stores), 'context store id');
|
|
194
|
+
return stringifyYaml({
|
|
195
|
+
version: 1,
|
|
196
|
+
stores: result.data.stores,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
export function serializeContextStoreMetadataState(state) {
|
|
200
|
+
const result = MetadataStateSchema.safeParse(state);
|
|
201
|
+
if (!result.success) {
|
|
202
|
+
throw invalidContextStoreStateError('context store metadata state', formatZodIssues(result.error));
|
|
203
|
+
}
|
|
204
|
+
validateContextStoreId(result.data.id);
|
|
205
|
+
return stringifyYaml({
|
|
206
|
+
version: 1,
|
|
207
|
+
id: result.data.id,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
export function listContextStoreRegistryEntries(registry) {
|
|
211
|
+
return Object.entries(registry.stores)
|
|
212
|
+
.map(([id, store]) => ({ id, backend: store.backend }))
|
|
213
|
+
.sort((a, b) => a.id.localeCompare(b.id));
|
|
214
|
+
}
|
|
215
|
+
export async function isContextStoreRoot(candidateRoot) {
|
|
216
|
+
return pathIsFile(getContextStoreMetadataPath(candidateRoot));
|
|
217
|
+
}
|
|
218
|
+
export async function readContextStoreRegistryState(options = {}) {
|
|
219
|
+
const registryPath = getContextStoreRegistryPath(options);
|
|
220
|
+
if (!(await pathIsFile(registryPath))) {
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
return parseContextStoreRegistryState(await fs.readFile(registryPath, 'utf-8'));
|
|
224
|
+
}
|
|
225
|
+
export async function writeContextStoreRegistryState(state, options = {}) {
|
|
226
|
+
await writeFileAtomically(getContextStoreRegistryPath(options), serializeContextStoreRegistryState(state));
|
|
227
|
+
}
|
|
228
|
+
async function writeFileAtomically(filePath, content) {
|
|
229
|
+
const dirPath = path.dirname(filePath);
|
|
230
|
+
await FileSystemUtils.createDirectory(dirPath);
|
|
231
|
+
const tempPath = path.join(dirPath, `.${path.basename(filePath)}.${process.pid}.${Date.now()}.${Math.random().toString(36).slice(2)}.tmp`);
|
|
232
|
+
try {
|
|
233
|
+
await fs.writeFile(tempPath, content, 'utf-8');
|
|
234
|
+
await fs.rename(tempPath, filePath);
|
|
235
|
+
}
|
|
236
|
+
catch (error) {
|
|
237
|
+
await fs.rm(tempPath, { force: true }).catch(() => undefined);
|
|
238
|
+
throw error;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
async function sleep(milliseconds) {
|
|
242
|
+
await new Promise((resolve) => setTimeout(resolve, milliseconds));
|
|
243
|
+
}
|
|
244
|
+
async function acquireContextStoreRegistryLock(options) {
|
|
245
|
+
const registryPath = getContextStoreRegistryPath(options);
|
|
246
|
+
const lockPath = `${registryPath}.lock`;
|
|
247
|
+
await FileSystemUtils.createDirectory(path.dirname(registryPath));
|
|
248
|
+
const deadline = Date.now() + 5000;
|
|
249
|
+
while (true) {
|
|
250
|
+
try {
|
|
251
|
+
return await fs.open(lockPath, 'wx');
|
|
252
|
+
}
|
|
253
|
+
catch (error) {
|
|
254
|
+
if (!isNodeErrorCode(error, 'EEXIST') || Date.now() >= deadline) {
|
|
255
|
+
throw new ContextStoreError('Context store registry is busy.', 'context_store_registry_busy', {
|
|
256
|
+
target: 'context_store.registry',
|
|
257
|
+
fix: 'Retry the command after the current registry update finishes.',
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
await sleep(25);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
export async function updateContextStoreRegistryState(updater, options = {}) {
|
|
265
|
+
const registryPath = getContextStoreRegistryPath(options);
|
|
266
|
+
const lockPath = `${registryPath}.lock`;
|
|
267
|
+
const lock = await acquireContextStoreRegistryLock(options);
|
|
268
|
+
try {
|
|
269
|
+
const next = updater(await readContextStoreRegistryState(options));
|
|
270
|
+
await writeContextStoreRegistryState(next, options);
|
|
271
|
+
return next;
|
|
272
|
+
}
|
|
273
|
+
finally {
|
|
274
|
+
await lock.close().catch(() => undefined);
|
|
275
|
+
await fs.rm(lockPath, { force: true }).catch(() => undefined);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
export async function readContextStoreMetadataState(storeRoot) {
|
|
279
|
+
return parseContextStoreMetadataState(await fs.readFile(getContextStoreMetadataPath(storeRoot), 'utf-8'));
|
|
280
|
+
}
|
|
281
|
+
export async function readOptionalContextStoreMetadataState(storeRoot) {
|
|
282
|
+
try {
|
|
283
|
+
return await readContextStoreMetadataState(storeRoot);
|
|
284
|
+
}
|
|
285
|
+
catch (error) {
|
|
286
|
+
if (isFileNotFoundError(error)) {
|
|
287
|
+
return null;
|
|
288
|
+
}
|
|
289
|
+
throw error;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
export async function writeContextStoreMetadataState(storeRoot, state) {
|
|
293
|
+
await FileSystemUtils.writeFile(getContextStoreMetadataPath(storeRoot), serializeContextStoreMetadataState(state));
|
|
294
|
+
}
|
|
295
|
+
export async function resolveGitContextStoreBackendConfig(input, cwd = process.cwd()) {
|
|
296
|
+
if (input.localPath.length === 0) {
|
|
297
|
+
throw new Error('Context store local path must not be empty.');
|
|
298
|
+
}
|
|
299
|
+
const resolvedPath = path.isAbsolute(input.localPath)
|
|
300
|
+
? path.resolve(input.localPath)
|
|
301
|
+
: path.resolve(cwd, input.localPath);
|
|
302
|
+
if (!(await pathIsDirectory(resolvedPath))) {
|
|
303
|
+
throw new Error(`Context store local path does not exist: ${input.localPath}`);
|
|
304
|
+
}
|
|
305
|
+
if (input.remote !== undefined && input.remote.length === 0) {
|
|
306
|
+
throw new Error('Context store remote must not be empty when provided.');
|
|
307
|
+
}
|
|
308
|
+
if (input.branch !== undefined && input.branch.length === 0) {
|
|
309
|
+
throw new Error('Context store branch must not be empty when provided.');
|
|
310
|
+
}
|
|
311
|
+
return {
|
|
312
|
+
type: 'git',
|
|
313
|
+
local_path: normalizeExistingPathForStorage(resolvedPath),
|
|
314
|
+
...(input.remote ? { remote: input.remote } : {}),
|
|
315
|
+
...(input.branch ? { branch: input.branch } : {}),
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
//# sourceMappingURL=foundation.js.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type ContextStoreGitBackendConfig, type ContextStoreRegistryState } from './foundation.js';
|
|
2
|
+
import { type ContextStoreDiagnostic } from './errors.js';
|
|
3
|
+
type PathKind = 'missing' | 'directory' | 'file' | 'other';
|
|
4
|
+
export interface ContextStoreInfo {
|
|
5
|
+
id: string;
|
|
6
|
+
root: string;
|
|
7
|
+
metadataPath?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ContextStoreMutationResult {
|
|
10
|
+
store: ContextStoreInfo;
|
|
11
|
+
registryCommit: {
|
|
12
|
+
path: string;
|
|
13
|
+
};
|
|
14
|
+
git: {
|
|
15
|
+
isRepository: boolean;
|
|
16
|
+
initialized: boolean;
|
|
17
|
+
};
|
|
18
|
+
createdArtifacts: string[];
|
|
19
|
+
}
|
|
20
|
+
export interface ContextStoreListResult {
|
|
21
|
+
stores: ContextStoreInfo[];
|
|
22
|
+
}
|
|
23
|
+
export interface ContextStoreDoctorResult {
|
|
24
|
+
stores: ContextStoreInspection[];
|
|
25
|
+
diagnostics: ContextStoreDiagnostic[];
|
|
26
|
+
}
|
|
27
|
+
export interface ContextStoreInspection extends ContextStoreInfo {
|
|
28
|
+
metadata: {
|
|
29
|
+
present: boolean | null;
|
|
30
|
+
valid: boolean | null;
|
|
31
|
+
id?: string;
|
|
32
|
+
};
|
|
33
|
+
git: {
|
|
34
|
+
isRepository: boolean | null;
|
|
35
|
+
};
|
|
36
|
+
diagnostics: ContextStoreDiagnostic[];
|
|
37
|
+
}
|
|
38
|
+
export interface SetupContextStoreInput {
|
|
39
|
+
id?: string;
|
|
40
|
+
path?: string;
|
|
41
|
+
initGit?: boolean;
|
|
42
|
+
}
|
|
43
|
+
export interface RegisterExistingContextStoreInput {
|
|
44
|
+
path?: string;
|
|
45
|
+
id?: string;
|
|
46
|
+
}
|
|
47
|
+
export interface PreparedContextStoreSetup {
|
|
48
|
+
id: string;
|
|
49
|
+
root: string;
|
|
50
|
+
rootKind: Extract<PathKind, 'missing' | 'directory'>;
|
|
51
|
+
backend?: ContextStoreGitBackendConfig;
|
|
52
|
+
registry: ContextStoreRegistryState | null;
|
|
53
|
+
}
|
|
54
|
+
export declare function prepareContextStoreSetup(input: Pick<SetupContextStoreInput, 'id' | 'path'>): Promise<PreparedContextStoreSetup>;
|
|
55
|
+
export declare function setupPreparedContextStore(prepared: PreparedContextStoreSetup, input?: Pick<SetupContextStoreInput, 'initGit'>): Promise<ContextStoreMutationResult>;
|
|
56
|
+
export declare function setupContextStore(input: SetupContextStoreInput): Promise<ContextStoreMutationResult>;
|
|
57
|
+
export declare function registerExistingContextStore(input: RegisterExistingContextStoreInput): Promise<ContextStoreMutationResult>;
|
|
58
|
+
export declare function listContextStores(): Promise<ContextStoreListResult>;
|
|
59
|
+
export declare function doctorContextStores(id?: string): Promise<ContextStoreDoctorResult>;
|
|
60
|
+
export declare function normalizeContextStorePathForComparison(targetPath: string): string;
|
|
61
|
+
export {};
|
|
62
|
+
//# sourceMappingURL=operations.d.ts.map
|