synarcx 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +23 -0
- package/README.md +90 -0
- package/bin/synarcx.js +3 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +474 -0
- package/dist/commands/change.d.ts +35 -0
- package/dist/commands/change.js +278 -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/feedback.d.ts +9 -0
- package/dist/commands/feedback.js +170 -0
- package/dist/commands/schema.d.ts +6 -0
- package/dist/commands/schema.js +870 -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 +226 -0
- package/dist/commands/validate.d.ts +24 -0
- package/dist/commands/validate.js +295 -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 +29 -0
- package/dist/commands/workflow/instructions.js +327 -0
- package/dist/commands/workflow/new-change.d.ts +11 -0
- package/dist/commands/workflow/new-change.js +45 -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 +57 -0
- package/dist/commands/workflow/shared.js +117 -0
- package/dist/commands/workflow/status.d.ts +14 -0
- package/dist/commands/workflow/status.js +75 -0
- package/dist/commands/workflow/templates.d.ts +16 -0
- package/dist/commands/workflow/templates.js +69 -0
- package/dist/commands/workspace/open.d.ts +29 -0
- package/dist/commands/workspace/open.js +84 -0
- package/dist/commands/workspace/operations.d.ts +18 -0
- package/dist/commands/workspace/operations.js +461 -0
- package/dist/commands/workspace/selection.d.ts +5 -0
- package/dist/commands/workspace/selection.js +90 -0
- package/dist/commands/workspace/types.d.ts +83 -0
- package/dist/commands/workspace/types.js +36 -0
- package/dist/commands/workspace.d.ts +3 -0
- package/dist/commands/workspace.js +635 -0
- package/dist/core/archive.d.ts +11 -0
- package/dist/core/archive.js +319 -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 +8 -0
- package/dist/core/artifact-graph/index.js +14 -0
- package/dist/core/artifact-graph/instruction-loader.d.ts +143 -0
- package/dist/core/artifact-graph/instruction-loader.js +217 -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 +258 -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 +45 -0
- package/dist/core/artifact-graph/types.js +43 -0
- package/dist/core/available-tools.d.ts +17 -0
- package/dist/core/available-tools.js +43 -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 +27 -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 +7 -0
- package/dist/core/completions/command-registry.js +596 -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/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 +19 -0
- package/dist/core/config.js +38 -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 +3 -0
- package/dist/core/index.js +4 -0
- package/dist/core/init.d.ts +37 -0
- package/dist/core/init.js +585 -0
- package/dist/core/legacy-cleanup.d.ts +169 -0
- package/dist/core/legacy-cleanup.js +578 -0
- package/dist/core/list.d.ts +9 -0
- package/dist/core/list.js +172 -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/profile-sync-drift.d.ts +38 -0
- package/dist/core/profile-sync-drift.js +197 -0
- package/dist/core/profiles.d.ts +26 -0
- package/dist/core/profiles.js +37 -0
- package/dist/core/project-config.d.ts +64 -0
- package/dist/core/project-config.js +224 -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 +90 -0
- package/dist/core/shared/tool-detection.d.ts +71 -0
- package/dist/core/shared/tool-detection.js +152 -0
- package/dist/core/specs-apply.d.ts +73 -0
- package/dist/core/specs-apply.js +393 -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 +15 -0
- package/dist/core/templates/skill-templates.js +14 -0
- package/dist/core/templates/types.d.ts +19 -0
- package/dist/core/templates/types.js +5 -0
- package/dist/core/templates/workflows/analyze.d.ts +4 -0
- package/dist/core/templates/workflows/analyze.js +101 -0
- package/dist/core/templates/workflows/apply-change.d.ts +10 -0
- package/dist/core/templates/workflows/apply-change.js +308 -0
- package/dist/core/templates/workflows/archive-change.d.ts +10 -0
- package/dist/core/templates/workflows/archive-change.js +271 -0
- package/dist/core/templates/workflows/clarify.d.ts +4 -0
- package/dist/core/templates/workflows/clarify.js +108 -0
- package/dist/core/templates/workflows/debug.d.ts +4 -0
- package/dist/core/templates/workflows/debug.js +117 -0
- package/dist/core/templates/workflows/explore.d.ts +10 -0
- package/dist/core/templates/workflows/explore.js +479 -0
- package/dist/core/templates/workflows/propose.d.ts +10 -0
- package/dist/core/templates/workflows/propose.js +216 -0
- package/dist/core/templates/workflows/sync.d.ts +4 -0
- package/dist/core/templates/workflows/sync.js +108 -0
- package/dist/core/update.d.ts +82 -0
- package/dist/core/update.js +555 -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 +169 -0
- package/dist/core/workspace/foundation.d.ts +79 -0
- package/dist/core/workspace/foundation.js +367 -0
- package/dist/core/workspace/index.d.ts +5 -0
- package/dist/core/workspace/index.js +5 -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 +24 -0
- package/dist/core/workspace/open-surface.js +137 -0
- package/dist/core/workspace/openers.d.ts +21 -0
- package/dist/core/workspace/openers.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/ui/ascii-patterns.d.ts +25 -0
- package/dist/ui/ascii-patterns.js +140 -0
- package/dist/ui/welcome-screen.d.ts +10 -0
- package/dist/ui/welcome-screen.js +144 -0
- package/dist/utils/change-metadata.d.ts +51 -0
- package/dist/utils/change-metadata.js +147 -0
- package/dist/utils/change-utils.d.ts +62 -0
- package/dist/utils/change-utils.js +122 -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 +73 -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 +76 -0
- package/schemas/synarcx/schema.yaml +153 -0
- package/schemas/synarcx/templates/design.md +19 -0
- package/schemas/synarcx/templates/proposal.md +23 -0
- package/schemas/synarcx/templates/spec.md +8 -0
- package/schemas/synarcx/templates/tasks.md +9 -0
- package/scripts/postinstall.js +83 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import ora from 'ora';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { Validator } from '../core/validation/validator.js';
|
|
4
|
+
import { isInteractive, resolveNoInteractive } from '../utils/interactive.js';
|
|
5
|
+
import { getActiveChangeIds, getSpecIds } from '../utils/item-discovery.js';
|
|
6
|
+
import { nearestMatches } from '../utils/match.js';
|
|
7
|
+
import { SYNSPEC_DIR_NAME } from '../core/config.js';
|
|
8
|
+
export class ValidateCommand {
|
|
9
|
+
async execute(itemName, options = {}) {
|
|
10
|
+
const interactive = isInteractive(options);
|
|
11
|
+
// Handle bulk flags first
|
|
12
|
+
if (options.all || options.changes || options.specs) {
|
|
13
|
+
await this.runBulkValidation({
|
|
14
|
+
changes: !!options.all || !!options.changes,
|
|
15
|
+
specs: !!options.all || !!options.specs,
|
|
16
|
+
}, { strict: !!options.strict, json: !!options.json, concurrency: options.concurrency, noInteractive: resolveNoInteractive(options) });
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
// No item and no flags
|
|
20
|
+
if (!itemName) {
|
|
21
|
+
if (interactive) {
|
|
22
|
+
await this.runInteractiveSelector({ strict: !!options.strict, json: !!options.json, concurrency: options.concurrency });
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
this.printNonInteractiveHint();
|
|
26
|
+
process.exitCode = 1;
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
// Direct item validation with type detection or override
|
|
30
|
+
const typeOverride = this.normalizeType(options.type);
|
|
31
|
+
await this.validateDirectItem(itemName, { typeOverride, strict: !!options.strict, json: !!options.json });
|
|
32
|
+
}
|
|
33
|
+
normalizeType(value) {
|
|
34
|
+
if (!value)
|
|
35
|
+
return undefined;
|
|
36
|
+
const v = value.toLowerCase();
|
|
37
|
+
if (v === 'change' || v === 'spec')
|
|
38
|
+
return v;
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
async runInteractiveSelector(opts) {
|
|
42
|
+
const { select } = await import('@inquirer/prompts');
|
|
43
|
+
const choice = await select({
|
|
44
|
+
message: 'What would you like to validate?',
|
|
45
|
+
choices: [
|
|
46
|
+
{ name: 'All (changes + specs)', value: 'all' },
|
|
47
|
+
{ name: 'All changes', value: 'changes' },
|
|
48
|
+
{ name: 'All specs', value: 'specs' },
|
|
49
|
+
{ name: 'Pick a specific change or spec', value: 'one' },
|
|
50
|
+
],
|
|
51
|
+
});
|
|
52
|
+
if (choice === 'all')
|
|
53
|
+
return this.runBulkValidation({ changes: true, specs: true }, opts);
|
|
54
|
+
if (choice === 'changes')
|
|
55
|
+
return this.runBulkValidation({ changes: true, specs: false }, opts);
|
|
56
|
+
if (choice === 'specs')
|
|
57
|
+
return this.runBulkValidation({ changes: false, specs: true }, opts);
|
|
58
|
+
// one
|
|
59
|
+
const [changes, specs] = await Promise.all([getActiveChangeIds(), getSpecIds()]);
|
|
60
|
+
const items = [];
|
|
61
|
+
items.push(...changes.map(id => ({ name: `change/${id}`, value: { type: 'change', id } })));
|
|
62
|
+
items.push(...specs.map(id => ({ name: `spec/${id}`, value: { type: 'spec', id } })));
|
|
63
|
+
if (items.length === 0) {
|
|
64
|
+
console.error('No items found to validate.');
|
|
65
|
+
process.exitCode = 1;
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const picked = await select({ message: 'Pick an item', choices: items });
|
|
69
|
+
await this.validateByType(picked.type, picked.id, opts);
|
|
70
|
+
}
|
|
71
|
+
printNonInteractiveHint() {
|
|
72
|
+
console.error('Nothing to validate. Try one of:');
|
|
73
|
+
console.error(' synarcx validate --all');
|
|
74
|
+
console.error(' synarcx validate --changes');
|
|
75
|
+
console.error(' synarcx validate --specs');
|
|
76
|
+
console.error(' synarcx validate <item-name>');
|
|
77
|
+
console.error('Or run in an interactive terminal.');
|
|
78
|
+
}
|
|
79
|
+
async validateDirectItem(itemName, opts) {
|
|
80
|
+
const [changes, specs] = await Promise.all([getActiveChangeIds(), getSpecIds()]);
|
|
81
|
+
const isChange = changes.includes(itemName);
|
|
82
|
+
const isSpec = specs.includes(itemName);
|
|
83
|
+
const type = opts.typeOverride ?? (isChange ? 'change' : isSpec ? 'spec' : undefined);
|
|
84
|
+
if (!type) {
|
|
85
|
+
console.error(`Unknown item '${itemName}'`);
|
|
86
|
+
const suggestions = nearestMatches(itemName, [...changes, ...specs]);
|
|
87
|
+
if (suggestions.length)
|
|
88
|
+
console.error(`Did you mean: ${suggestions.join(', ')}?`);
|
|
89
|
+
process.exitCode = 1;
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (!opts.typeOverride && isChange && isSpec) {
|
|
93
|
+
console.error(`Ambiguous item '${itemName}' matches both a change and a spec.`);
|
|
94
|
+
console.error('Pass --type change|spec, or use: synarcx change validate / synarcx spec validate');
|
|
95
|
+
process.exitCode = 1;
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
await this.validateByType(type, itemName, opts);
|
|
99
|
+
}
|
|
100
|
+
async validateByType(type, id, opts) {
|
|
101
|
+
const validator = new Validator(opts.strict);
|
|
102
|
+
if (type === 'change') {
|
|
103
|
+
const changeDir = path.join(process.cwd(), SYNSPEC_DIR_NAME, 'changes', id);
|
|
104
|
+
const start = Date.now();
|
|
105
|
+
const report = await validator.validateChangeDeltaSpecs(changeDir);
|
|
106
|
+
const durationMs = Date.now() - start;
|
|
107
|
+
this.printReport('change', id, report, durationMs, opts.json);
|
|
108
|
+
// Non-zero exit if invalid (keeps enriched output test semantics)
|
|
109
|
+
process.exitCode = report.valid ? 0 : 1;
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const file = path.join(process.cwd(), SYNSPEC_DIR_NAME, 'specs', id, 'spec.md');
|
|
113
|
+
const start = Date.now();
|
|
114
|
+
const report = await validator.validateSpec(file);
|
|
115
|
+
const durationMs = Date.now() - start;
|
|
116
|
+
this.printReport('spec', id, report, durationMs, opts.json);
|
|
117
|
+
process.exitCode = report.valid ? 0 : 1;
|
|
118
|
+
}
|
|
119
|
+
printReport(type, id, report, durationMs, json) {
|
|
120
|
+
if (json) {
|
|
121
|
+
const out = { items: [{ id, type, valid: report.valid, issues: report.issues, durationMs }], summary: { totals: { items: 1, passed: report.valid ? 1 : 0, failed: report.valid ? 0 : 1 }, byType: { [type]: { items: 1, passed: report.valid ? 1 : 0, failed: report.valid ? 0 : 1 } } }, version: '1.0' };
|
|
122
|
+
console.log(JSON.stringify(out, null, 2));
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (report.valid) {
|
|
126
|
+
console.log(`${type === 'change' ? 'Change' : 'Specification'} '${id}' is valid`);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
console.error(`${type === 'change' ? 'Change' : 'Specification'} '${id}' has issues`);
|
|
130
|
+
for (const issue of report.issues) {
|
|
131
|
+
const label = issue.level === 'ERROR' ? 'ERROR' : issue.level;
|
|
132
|
+
const prefix = issue.level === 'ERROR' ? '✗' : issue.level === 'WARNING' ? '⚠' : 'ℹ';
|
|
133
|
+
console.error(`${prefix} [${label}] ${issue.path}: ${issue.message}`);
|
|
134
|
+
}
|
|
135
|
+
this.printNextSteps(type);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
printNextSteps(type) {
|
|
139
|
+
const bullets = [];
|
|
140
|
+
if (type === 'change') {
|
|
141
|
+
bullets.push('- Ensure change has deltas in specs/: use headers ## ADDED/MODIFIED/REMOVED/RENAMED Requirements');
|
|
142
|
+
bullets.push('- Each requirement MUST include at least one #### Scenario: block');
|
|
143
|
+
bullets.push('- Debug parsed deltas: synarcx change show <id> --json --deltas-only');
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
bullets.push('- Ensure spec includes ## Purpose and ## Requirements sections');
|
|
147
|
+
bullets.push('- Each requirement MUST include at least one #### Scenario: block');
|
|
148
|
+
bullets.push('- Re-run with --json to see structured report');
|
|
149
|
+
}
|
|
150
|
+
console.error('Next steps:');
|
|
151
|
+
bullets.forEach(b => console.error(` ${b}`));
|
|
152
|
+
}
|
|
153
|
+
async runBulkValidation(scope, opts) {
|
|
154
|
+
const spinner = !opts.json && !opts.noInteractive ? ora('Validating...').start() : undefined;
|
|
155
|
+
const [changeIds, specIds] = await Promise.all([
|
|
156
|
+
scope.changes ? getActiveChangeIds() : Promise.resolve([]),
|
|
157
|
+
scope.specs ? getSpecIds() : Promise.resolve([]),
|
|
158
|
+
]);
|
|
159
|
+
const DEFAULT_CONCURRENCY = 6;
|
|
160
|
+
const maxSuggestions = 5; // used by nearestMatches
|
|
161
|
+
const concurrency = normalizeConcurrency(opts.concurrency) ?? normalizeConcurrency(process.env.SYNARCX_CONCURRENCY) ?? DEFAULT_CONCURRENCY;
|
|
162
|
+
const validator = new Validator(opts.strict);
|
|
163
|
+
const queue = [];
|
|
164
|
+
for (const id of changeIds) {
|
|
165
|
+
queue.push(async () => {
|
|
166
|
+
const start = Date.now();
|
|
167
|
+
const changeDir = path.join(process.cwd(), SYNSPEC_DIR_NAME, 'changes', id);
|
|
168
|
+
const report = await validator.validateChangeDeltaSpecs(changeDir);
|
|
169
|
+
const durationMs = Date.now() - start;
|
|
170
|
+
return { id, type: 'change', valid: report.valid, issues: report.issues, durationMs };
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
for (const id of specIds) {
|
|
174
|
+
queue.push(async () => {
|
|
175
|
+
const start = Date.now();
|
|
176
|
+
const file = path.join(process.cwd(), SYNSPEC_DIR_NAME, 'specs', id, 'spec.md');
|
|
177
|
+
const report = await validator.validateSpec(file);
|
|
178
|
+
const durationMs = Date.now() - start;
|
|
179
|
+
return { id, type: 'spec', valid: report.valid, issues: report.issues, durationMs };
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
if (queue.length === 0) {
|
|
183
|
+
spinner?.stop();
|
|
184
|
+
const summary = {
|
|
185
|
+
totals: { items: 0, passed: 0, failed: 0 },
|
|
186
|
+
byType: {
|
|
187
|
+
...(scope.changes ? { change: { items: 0, passed: 0, failed: 0 } } : {}),
|
|
188
|
+
...(scope.specs ? { spec: { items: 0, passed: 0, failed: 0 } } : {}),
|
|
189
|
+
},
|
|
190
|
+
};
|
|
191
|
+
if (opts.json) {
|
|
192
|
+
const out = { items: [], summary, version: '1.0' };
|
|
193
|
+
console.log(JSON.stringify(out, null, 2));
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
console.log('No items found to validate.');
|
|
197
|
+
}
|
|
198
|
+
process.exitCode = 0;
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const results = [];
|
|
202
|
+
let index = 0;
|
|
203
|
+
let running = 0;
|
|
204
|
+
let passed = 0;
|
|
205
|
+
let failed = 0;
|
|
206
|
+
await new Promise((resolve) => {
|
|
207
|
+
const next = () => {
|
|
208
|
+
while (running < concurrency && index < queue.length) {
|
|
209
|
+
const currentIndex = index++;
|
|
210
|
+
const task = queue[currentIndex];
|
|
211
|
+
running++;
|
|
212
|
+
if (spinner)
|
|
213
|
+
spinner.text = `Validating (${currentIndex + 1}/${queue.length})...`;
|
|
214
|
+
task()
|
|
215
|
+
.then(res => {
|
|
216
|
+
results.push(res);
|
|
217
|
+
if (res.valid)
|
|
218
|
+
passed++;
|
|
219
|
+
else
|
|
220
|
+
failed++;
|
|
221
|
+
})
|
|
222
|
+
.catch((error) => {
|
|
223
|
+
const message = error?.message || 'Unknown error';
|
|
224
|
+
const res = { id: getPlannedId(currentIndex, changeIds, specIds) ?? 'unknown', type: getPlannedType(currentIndex, changeIds, specIds) ?? 'change', valid: false, issues: [{ level: 'ERROR', path: 'file', message }], durationMs: 0 };
|
|
225
|
+
results.push(res);
|
|
226
|
+
failed++;
|
|
227
|
+
})
|
|
228
|
+
.finally(() => {
|
|
229
|
+
running--;
|
|
230
|
+
if (index >= queue.length && running === 0)
|
|
231
|
+
resolve();
|
|
232
|
+
else
|
|
233
|
+
next();
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
next();
|
|
238
|
+
});
|
|
239
|
+
spinner?.stop();
|
|
240
|
+
results.sort((a, b) => a.id.localeCompare(b.id));
|
|
241
|
+
const summary = {
|
|
242
|
+
totals: { items: results.length, passed, failed },
|
|
243
|
+
byType: {
|
|
244
|
+
...(scope.changes ? { change: summarizeType(results, 'change') } : {}),
|
|
245
|
+
...(scope.specs ? { spec: summarizeType(results, 'spec') } : {}),
|
|
246
|
+
},
|
|
247
|
+
};
|
|
248
|
+
if (opts.json) {
|
|
249
|
+
const out = { items: results, summary, version: '1.0' };
|
|
250
|
+
console.log(JSON.stringify(out, null, 2));
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
for (const res of results) {
|
|
254
|
+
if (res.valid)
|
|
255
|
+
console.log(`✓ ${res.type}/${res.id}`);
|
|
256
|
+
else
|
|
257
|
+
console.error(`✗ ${res.type}/${res.id}`);
|
|
258
|
+
}
|
|
259
|
+
console.log(`Totals: ${summary.totals.passed} passed, ${summary.totals.failed} failed (${summary.totals.items} items)`);
|
|
260
|
+
}
|
|
261
|
+
process.exitCode = failed > 0 ? 1 : 0;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
function summarizeType(results, type) {
|
|
265
|
+
const filtered = results.filter(r => r.type === type);
|
|
266
|
+
const items = filtered.length;
|
|
267
|
+
const passed = filtered.filter(r => r.valid).length;
|
|
268
|
+
const failed = items - passed;
|
|
269
|
+
return { items, passed, failed };
|
|
270
|
+
}
|
|
271
|
+
function normalizeConcurrency(value) {
|
|
272
|
+
if (!value)
|
|
273
|
+
return undefined;
|
|
274
|
+
const n = parseInt(value, 10);
|
|
275
|
+
if (Number.isNaN(n) || n <= 0)
|
|
276
|
+
return undefined;
|
|
277
|
+
return n;
|
|
278
|
+
}
|
|
279
|
+
function getPlannedId(index, changeIds, specIds) {
|
|
280
|
+
const totalChanges = changeIds.length;
|
|
281
|
+
if (index < totalChanges)
|
|
282
|
+
return changeIds[index];
|
|
283
|
+
const specIndex = index - totalChanges;
|
|
284
|
+
return specIds[specIndex];
|
|
285
|
+
}
|
|
286
|
+
function getPlannedType(index, changeIds, specIds) {
|
|
287
|
+
const totalChanges = changeIds.length;
|
|
288
|
+
if (index < totalChanges)
|
|
289
|
+
return 'change';
|
|
290
|
+
const specIndex = index - totalChanges;
|
|
291
|
+
if (specIndex >= 0 && specIndex < specIds.length)
|
|
292
|
+
return 'spec';
|
|
293
|
+
return undefined;
|
|
294
|
+
}
|
|
295
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow CLI Commands
|
|
3
|
+
*
|
|
4
|
+
* Commands for the artifact-driven workflow: status, instructions, templates, schemas, new change.
|
|
5
|
+
*/
|
|
6
|
+
export { statusCommand } from './status.js';
|
|
7
|
+
export type { StatusOptions } from './status.js';
|
|
8
|
+
export { instructionsCommand, applyInstructionsCommand } from './instructions.js';
|
|
9
|
+
export type { InstructionsOptions } from './instructions.js';
|
|
10
|
+
export { templatesCommand } from './templates.js';
|
|
11
|
+
export type { TemplatesOptions } from './templates.js';
|
|
12
|
+
export { schemasCommand } from './schemas.js';
|
|
13
|
+
export type { SchemasOptions } from './schemas.js';
|
|
14
|
+
export { newChangeCommand } from './new-change.js';
|
|
15
|
+
export type { NewChangeOptions } from './new-change.js';
|
|
16
|
+
export { DEFAULT_SCHEMA } from './shared.js';
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow CLI Commands
|
|
3
|
+
*
|
|
4
|
+
* Commands for the artifact-driven workflow: status, instructions, templates, schemas, new change.
|
|
5
|
+
*/
|
|
6
|
+
export { statusCommand } from './status.js';
|
|
7
|
+
export { instructionsCommand, applyInstructionsCommand } from './instructions.js';
|
|
8
|
+
export { templatesCommand } from './templates.js';
|
|
9
|
+
export { schemasCommand } from './schemas.js';
|
|
10
|
+
export { newChangeCommand } from './new-change.js';
|
|
11
|
+
export { DEFAULT_SCHEMA } from './shared.js';
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Instructions Command
|
|
3
|
+
*
|
|
4
|
+
* Generates enriched instructions for creating artifacts or applying tasks.
|
|
5
|
+
* Includes both artifact instructions and apply instructions.
|
|
6
|
+
*/
|
|
7
|
+
import { type ArtifactInstructions } from '../../core/artifact-graph/index.js';
|
|
8
|
+
import { type ApplyInstructions } from './shared.js';
|
|
9
|
+
export interface InstructionsOptions {
|
|
10
|
+
change?: string;
|
|
11
|
+
schema?: string;
|
|
12
|
+
json?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface ApplyInstructionsOptions {
|
|
15
|
+
change?: string;
|
|
16
|
+
schema?: string;
|
|
17
|
+
json?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare function instructionsCommand(artifactId: string | undefined, options: InstructionsOptions): Promise<void>;
|
|
20
|
+
export declare function printInstructionsText(instructions: ArtifactInstructions, isBlocked: boolean): void;
|
|
21
|
+
/**
|
|
22
|
+
* Generates apply instructions for implementing tasks from a change.
|
|
23
|
+
* Schema-aware: reads apply phase configuration from schema to determine
|
|
24
|
+
* required artifacts, tracking file, and instruction.
|
|
25
|
+
*/
|
|
26
|
+
export declare function generateApplyInstructions(projectRoot: string, changeName: string, schemaName?: string): Promise<ApplyInstructions>;
|
|
27
|
+
export declare function applyInstructionsCommand(options: ApplyInstructionsOptions): Promise<void>;
|
|
28
|
+
export declare function printApplyInstructionsText(instructions: ApplyInstructions): void;
|
|
29
|
+
//# sourceMappingURL=instructions.d.ts.map
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Instructions Command
|
|
3
|
+
*
|
|
4
|
+
* Generates enriched instructions for creating artifacts or applying tasks.
|
|
5
|
+
* Includes both artifact instructions and apply instructions.
|
|
6
|
+
*/
|
|
7
|
+
import ora from 'ora';
|
|
8
|
+
import path from 'path';
|
|
9
|
+
import * as fs from 'fs';
|
|
10
|
+
import { loadChangeContext, generateInstructions, resolveSchema, resolveArtifactOutputs, } from '../../core/artifact-graph/index.js';
|
|
11
|
+
import { validateChangeExists, validateSchemaExists, } from './shared.js';
|
|
12
|
+
// -----------------------------------------------------------------------------
|
|
13
|
+
// Artifact Instructions Command
|
|
14
|
+
// -----------------------------------------------------------------------------
|
|
15
|
+
export async function instructionsCommand(artifactId, options) {
|
|
16
|
+
const spinner = options.json ? undefined : ora('Generating instructions...').start();
|
|
17
|
+
try {
|
|
18
|
+
const projectRoot = process.cwd();
|
|
19
|
+
const changeName = await validateChangeExists(options.change, projectRoot);
|
|
20
|
+
// Validate schema if explicitly provided
|
|
21
|
+
if (options.schema) {
|
|
22
|
+
validateSchemaExists(options.schema, projectRoot);
|
|
23
|
+
}
|
|
24
|
+
// loadChangeContext will auto-detect schema from metadata if not provided
|
|
25
|
+
const context = loadChangeContext(projectRoot, changeName, options.schema);
|
|
26
|
+
if (!artifactId) {
|
|
27
|
+
spinner?.stop();
|
|
28
|
+
const validIds = context.graph.getAllArtifacts().map((a) => a.id);
|
|
29
|
+
throw new Error(`Missing required argument <artifact>. Valid artifacts:\n ${validIds.join('\n ')}`);
|
|
30
|
+
}
|
|
31
|
+
const artifact = context.graph.getArtifact(artifactId);
|
|
32
|
+
if (!artifact) {
|
|
33
|
+
spinner?.stop();
|
|
34
|
+
const validIds = context.graph.getAllArtifacts().map((a) => a.id);
|
|
35
|
+
throw new Error(`Artifact '${artifactId}' not found in schema '${context.schemaName}'. Valid artifacts:\n ${validIds.join('\n ')}`);
|
|
36
|
+
}
|
|
37
|
+
const instructions = generateInstructions(context, artifactId, projectRoot);
|
|
38
|
+
const isBlocked = instructions.dependencies.some((d) => !d.done);
|
|
39
|
+
spinner?.stop();
|
|
40
|
+
if (options.json) {
|
|
41
|
+
console.log(JSON.stringify(instructions, null, 2));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
printInstructionsText(instructions, isBlocked);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
spinner?.stop();
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export function printInstructionsText(instructions, isBlocked) {
|
|
52
|
+
const { artifactId, changeName, schemaName, changeDir, outputPath, description, instruction, context, rules, template, dependencies, unlocks, } = instructions;
|
|
53
|
+
// Opening tag
|
|
54
|
+
console.log(`<artifact id="${artifactId}" change="${changeName}" schema="${schemaName}">`);
|
|
55
|
+
console.log();
|
|
56
|
+
// Warning for blocked artifacts
|
|
57
|
+
if (isBlocked) {
|
|
58
|
+
const missing = dependencies.filter((d) => !d.done).map((d) => d.id);
|
|
59
|
+
console.log('<warning>');
|
|
60
|
+
console.log('This artifact has unmet dependencies. Complete them first or proceed with caution.');
|
|
61
|
+
console.log(`Missing: ${missing.join(', ')}`);
|
|
62
|
+
console.log('</warning>');
|
|
63
|
+
console.log();
|
|
64
|
+
}
|
|
65
|
+
// Task directive
|
|
66
|
+
console.log('<task>');
|
|
67
|
+
console.log(`Create the ${artifactId} artifact for change "${changeName}".`);
|
|
68
|
+
console.log(description);
|
|
69
|
+
console.log('</task>');
|
|
70
|
+
console.log();
|
|
71
|
+
// Project context (AI constraint - do not include in output)
|
|
72
|
+
if (context) {
|
|
73
|
+
console.log('<project_context>');
|
|
74
|
+
console.log('<!-- This is background information for you. Do NOT include this in your output. -->');
|
|
75
|
+
console.log(context);
|
|
76
|
+
console.log('</project_context>');
|
|
77
|
+
console.log();
|
|
78
|
+
}
|
|
79
|
+
// Rules (AI constraint - do not include in output)
|
|
80
|
+
if (rules && rules.length > 0) {
|
|
81
|
+
console.log('<rules>');
|
|
82
|
+
console.log('<!-- These are constraints for you to follow. Do NOT include this in your output. -->');
|
|
83
|
+
for (const rule of rules) {
|
|
84
|
+
console.log(`- ${rule}`);
|
|
85
|
+
}
|
|
86
|
+
console.log('</rules>');
|
|
87
|
+
console.log();
|
|
88
|
+
}
|
|
89
|
+
// Dependencies (files to read for context)
|
|
90
|
+
if (dependencies.length > 0) {
|
|
91
|
+
console.log('<dependencies>');
|
|
92
|
+
console.log('Read these files for context before creating this artifact:');
|
|
93
|
+
console.log();
|
|
94
|
+
for (const dep of dependencies) {
|
|
95
|
+
const status = dep.done ? 'done' : 'missing';
|
|
96
|
+
const fullPath = path.join(changeDir, dep.path);
|
|
97
|
+
console.log(`<dependency id="${dep.id}" status="${status}">`);
|
|
98
|
+
console.log(` <path>${fullPath}</path>`);
|
|
99
|
+
console.log(` <description>${dep.description}</description>`);
|
|
100
|
+
console.log('</dependency>');
|
|
101
|
+
}
|
|
102
|
+
console.log('</dependencies>');
|
|
103
|
+
console.log();
|
|
104
|
+
}
|
|
105
|
+
// Output location
|
|
106
|
+
console.log('<output>');
|
|
107
|
+
console.log(`Write to: ${path.join(changeDir, outputPath)}`);
|
|
108
|
+
console.log('</output>');
|
|
109
|
+
console.log();
|
|
110
|
+
// Instruction (guidance)
|
|
111
|
+
if (instruction) {
|
|
112
|
+
console.log('<instruction>');
|
|
113
|
+
console.log(instruction.trim());
|
|
114
|
+
console.log('</instruction>');
|
|
115
|
+
console.log();
|
|
116
|
+
}
|
|
117
|
+
// Template
|
|
118
|
+
console.log('<template>');
|
|
119
|
+
console.log('<!-- Use this as the structure for your output file. Fill in the sections. -->');
|
|
120
|
+
console.log(template.trim());
|
|
121
|
+
console.log('</template>');
|
|
122
|
+
console.log();
|
|
123
|
+
// Success criteria placeholder
|
|
124
|
+
console.log('<success_criteria>');
|
|
125
|
+
console.log('<!-- To be defined in schema validation rules -->');
|
|
126
|
+
console.log('</success_criteria>');
|
|
127
|
+
console.log();
|
|
128
|
+
// Unlocks
|
|
129
|
+
if (unlocks.length > 0) {
|
|
130
|
+
console.log('<unlocks>');
|
|
131
|
+
console.log(`Completing this artifact enables: ${unlocks.join(', ')}`);
|
|
132
|
+
console.log('</unlocks>');
|
|
133
|
+
console.log();
|
|
134
|
+
}
|
|
135
|
+
// Closing tag
|
|
136
|
+
console.log('</artifact>');
|
|
137
|
+
}
|
|
138
|
+
// -----------------------------------------------------------------------------
|
|
139
|
+
// Apply Instructions Command
|
|
140
|
+
// -----------------------------------------------------------------------------
|
|
141
|
+
/**
|
|
142
|
+
* Parses tasks.md content and extracts task items with their completion status.
|
|
143
|
+
*/
|
|
144
|
+
function parseTasksFile(content) {
|
|
145
|
+
const tasks = [];
|
|
146
|
+
const lines = content.split('\n');
|
|
147
|
+
let taskIndex = 0;
|
|
148
|
+
for (const line of lines) {
|
|
149
|
+
// Match checkbox patterns: - [ ] or - [x] or - [X]
|
|
150
|
+
const checkboxMatch = line.match(/^[-*]\s*\[([ xX])\]\s*(.+)\s*$/);
|
|
151
|
+
if (checkboxMatch) {
|
|
152
|
+
taskIndex++;
|
|
153
|
+
const done = checkboxMatch[1].toLowerCase() === 'x';
|
|
154
|
+
const description = checkboxMatch[2].trim();
|
|
155
|
+
tasks.push({
|
|
156
|
+
id: `${taskIndex}`,
|
|
157
|
+
description,
|
|
158
|
+
done,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return tasks;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Generates apply instructions for implementing tasks from a change.
|
|
166
|
+
* Schema-aware: reads apply phase configuration from schema to determine
|
|
167
|
+
* required artifacts, tracking file, and instruction.
|
|
168
|
+
*/
|
|
169
|
+
export async function generateApplyInstructions(projectRoot, changeName, schemaName) {
|
|
170
|
+
// loadChangeContext will auto-detect schema from metadata if not provided
|
|
171
|
+
const context = loadChangeContext(projectRoot, changeName, schemaName);
|
|
172
|
+
const changeDir = context.changeDir;
|
|
173
|
+
// Get the full schema to access the apply phase configuration
|
|
174
|
+
const schema = resolveSchema(context.schemaName, projectRoot);
|
|
175
|
+
const applyConfig = schema.apply;
|
|
176
|
+
// Determine required artifacts and tracking file from schema
|
|
177
|
+
// Fallback: if no apply block, require all artifacts
|
|
178
|
+
const requiredArtifactIds = applyConfig?.requires ?? schema.artifacts.map((a) => a.id);
|
|
179
|
+
const tracksFile = applyConfig?.tracks ?? null;
|
|
180
|
+
const schemaInstruction = applyConfig?.instruction ?? null;
|
|
181
|
+
// Check which required artifacts are missing
|
|
182
|
+
const missingArtifacts = [];
|
|
183
|
+
for (const artifactId of requiredArtifactIds) {
|
|
184
|
+
const artifact = schema.artifacts.find((a) => a.id === artifactId);
|
|
185
|
+
if (artifact && resolveArtifactOutputs(changeDir, artifact.generates).length === 0) {
|
|
186
|
+
missingArtifacts.push(artifactId);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
// Build context files from all existing artifacts in schema
|
|
190
|
+
const contextFiles = {};
|
|
191
|
+
for (const artifact of schema.artifacts) {
|
|
192
|
+
const outputs = resolveArtifactOutputs(changeDir, artifact.generates);
|
|
193
|
+
if (outputs.length > 0) {
|
|
194
|
+
contextFiles[artifact.id] = outputs;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
// Parse tasks if tracking file exists
|
|
198
|
+
let tasks = [];
|
|
199
|
+
let tracksFileExists = false;
|
|
200
|
+
if (tracksFile) {
|
|
201
|
+
const tracksPath = path.join(changeDir, tracksFile);
|
|
202
|
+
tracksFileExists = fs.existsSync(tracksPath);
|
|
203
|
+
if (tracksFileExists) {
|
|
204
|
+
const tasksContent = await fs.promises.readFile(tracksPath, 'utf-8');
|
|
205
|
+
tasks = parseTasksFile(tasksContent);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
// Calculate progress
|
|
209
|
+
const total = tasks.length;
|
|
210
|
+
const complete = tasks.filter((t) => t.done).length;
|
|
211
|
+
const remaining = total - complete;
|
|
212
|
+
// Determine state and instruction
|
|
213
|
+
let state;
|
|
214
|
+
let instruction;
|
|
215
|
+
if (missingArtifacts.length > 0) {
|
|
216
|
+
state = 'blocked';
|
|
217
|
+
instruction = `Cannot apply this change yet. Missing artifacts: ${missingArtifacts.join(', ')}.\nUse the syn:propose command to create the missing artifacts first.`;
|
|
218
|
+
}
|
|
219
|
+
else if (tracksFile && !tracksFileExists) {
|
|
220
|
+
// Tracking file configured but doesn't exist yet
|
|
221
|
+
const tracksFilename = path.basename(tracksFile);
|
|
222
|
+
state = 'blocked';
|
|
223
|
+
instruction = `The ${tracksFilename} file is missing and must be created.\nUse /syn:propose to generate the tracking file.`;
|
|
224
|
+
}
|
|
225
|
+
else if (tracksFile && tracksFileExists && total === 0) {
|
|
226
|
+
// Tracking file exists but contains no tasks
|
|
227
|
+
const tracksFilename = path.basename(tracksFile);
|
|
228
|
+
state = 'blocked';
|
|
229
|
+
instruction = `The ${tracksFilename} file exists but contains no tasks.\nAdd tasks to ${tracksFilename} or regenerate it with /syn:propose.`;
|
|
230
|
+
}
|
|
231
|
+
else if (tracksFile && remaining === 0 && total > 0) {
|
|
232
|
+
state = 'all_done';
|
|
233
|
+
instruction = 'All tasks are complete! This change is ready to be archived.\nConsider running tests and reviewing the changes before archiving.';
|
|
234
|
+
}
|
|
235
|
+
else if (!tracksFile) {
|
|
236
|
+
// No tracking file configured in schema - ready to apply
|
|
237
|
+
state = 'ready';
|
|
238
|
+
instruction = schemaInstruction?.trim() ?? 'All required artifacts complete. Proceed with implementation.';
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
state = 'ready';
|
|
242
|
+
instruction = schemaInstruction?.trim() ?? 'Read context files, work through pending tasks, mark complete as you go.\nPause if you hit blockers or need clarification.';
|
|
243
|
+
}
|
|
244
|
+
return {
|
|
245
|
+
changeName,
|
|
246
|
+
changeDir,
|
|
247
|
+
schemaName: context.schemaName,
|
|
248
|
+
contextFiles,
|
|
249
|
+
progress: { total, complete, remaining },
|
|
250
|
+
tasks,
|
|
251
|
+
state,
|
|
252
|
+
missingArtifacts: missingArtifacts.length > 0 ? missingArtifacts : undefined,
|
|
253
|
+
instruction,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
export async function applyInstructionsCommand(options) {
|
|
257
|
+
const spinner = options.json ? undefined : ora('Generating apply instructions...').start();
|
|
258
|
+
try {
|
|
259
|
+
const projectRoot = process.cwd();
|
|
260
|
+
const changeName = await validateChangeExists(options.change, projectRoot);
|
|
261
|
+
// Validate schema if explicitly provided
|
|
262
|
+
if (options.schema) {
|
|
263
|
+
validateSchemaExists(options.schema, projectRoot);
|
|
264
|
+
}
|
|
265
|
+
// generateApplyInstructions uses loadChangeContext which auto-detects schema
|
|
266
|
+
const instructions = await generateApplyInstructions(projectRoot, changeName, options.schema);
|
|
267
|
+
spinner?.stop();
|
|
268
|
+
if (options.json) {
|
|
269
|
+
console.log(JSON.stringify(instructions, null, 2));
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
printApplyInstructionsText(instructions);
|
|
273
|
+
}
|
|
274
|
+
catch (error) {
|
|
275
|
+
spinner?.stop();
|
|
276
|
+
throw error;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
export function printApplyInstructionsText(instructions) {
|
|
280
|
+
const { changeName, schemaName, contextFiles, progress, tasks, state, missingArtifacts, instruction } = instructions;
|
|
281
|
+
console.log(`## Apply: ${changeName}`);
|
|
282
|
+
console.log(`Schema: ${schemaName}`);
|
|
283
|
+
console.log();
|
|
284
|
+
// Warning for blocked state
|
|
285
|
+
if (state === 'blocked' && missingArtifacts) {
|
|
286
|
+
console.log('### ⚠️ Blocked');
|
|
287
|
+
console.log();
|
|
288
|
+
console.log(`Missing artifacts: ${missingArtifacts.join(', ')}`);
|
|
289
|
+
console.log('Use the syn:propose command to create these first.');
|
|
290
|
+
console.log();
|
|
291
|
+
}
|
|
292
|
+
// Context files (dynamically from schema)
|
|
293
|
+
const contextFileEntries = Object.entries(contextFiles);
|
|
294
|
+
if (contextFileEntries.length > 0) {
|
|
295
|
+
console.log('### Context Files');
|
|
296
|
+
for (const [artifactId, filePaths] of contextFileEntries) {
|
|
297
|
+
for (const filePath of filePaths) {
|
|
298
|
+
console.log(`- ${artifactId}: ${filePath}`);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
console.log();
|
|
302
|
+
}
|
|
303
|
+
// Progress (only show if we have tracking)
|
|
304
|
+
if (progress.total > 0 || tasks.length > 0) {
|
|
305
|
+
console.log('### Progress');
|
|
306
|
+
if (state === 'all_done') {
|
|
307
|
+
console.log(`${progress.complete}/${progress.total} complete ✓`);
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
console.log(`${progress.complete}/${progress.total} complete`);
|
|
311
|
+
}
|
|
312
|
+
console.log();
|
|
313
|
+
}
|
|
314
|
+
// Tasks
|
|
315
|
+
if (tasks.length > 0) {
|
|
316
|
+
console.log('### Tasks');
|
|
317
|
+
for (const task of tasks) {
|
|
318
|
+
const checkbox = task.done ? '[x]' : '[ ]';
|
|
319
|
+
console.log(`- ${checkbox} ${task.description}`);
|
|
320
|
+
}
|
|
321
|
+
console.log();
|
|
322
|
+
}
|
|
323
|
+
// Instruction
|
|
324
|
+
console.log('### Instruction');
|
|
325
|
+
console.log(instruction);
|
|
326
|
+
}
|
|
327
|
+
//# sourceMappingURL=instructions.js.map
|