@buildr-ai/buildr 0.1.0-rc.2 → 0.1.0-rc.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -5
- package/application-payload.json +595 -0
- package/bin/buildr.mjs +14 -0
- package/installation-origin.json +13 -0
- package/package.json +16 -45
- package/payload/licenses/dependencies/yaml-LICENSE +13 -0
- package/payload/product/LICENSE +21 -0
- package/payload/product/README.md +59 -0
- package/payload/product/package/README.md +42 -0
- package/{package → payload/product/package}/bootstrap/contract.yml +26 -11
- package/{package → payload/product/package}/bootstrap/guide.md +11 -11
- package/payload/product/package/launchers/assets/Buildr.icns +0 -0
- package/payload/product/package/launchers/assets/Buildr.ico +0 -0
- package/payload/product/package/manifest.yml +547 -0
- package/payload/product/package/targets/runtime/skills/buildr/SKILL.md +174 -0
- package/{package → payload/product/package}/targets/workspace/commands/buildr/openspec/manifest.yml +2 -2
- package/payload/product/package/targets/workspace/components/buildr/openspec/component.yml +79 -0
- package/payload/product/package/targets/workspace/components/buildr/openspec/contributions/openspec-apply-sidebar.md +21 -0
- package/payload/product/package/targets/workspace/components/buildr/openspec/contributions/openspec-archive-converge.md +5 -0
- package/payload/product/package/targets/workspace/components/buildr/openspec/contributions/openspec-explore-terminology.md +5 -0
- package/payload/product/package/targets/workspace/components/buildr/openspec/contributions/openspec-propose-sidebar.md +21 -0
- package/payload/product/package/targets/workspace/components/buildr/openspec/contributions/openspec-sync-converge.md +5 -0
- package/payload/product/package/targets/workspace/components/buildr/openspec/contributions/openspec-update-sidebar.md +13 -0
- package/payload/product/package/targets/workspace/gitattributes +1 -0
- package/payload/product/package/targets/workspace/gitignore +31 -0
- package/{package → payload/product/package}/targets/workspace/projects/AGENTS.project.md +1 -1
- package/payload/product/package/targets/workspace/rules/buildr/core.md +62 -0
- package/payload/product/package/targets/workspace/skills/buildr/capability-adaptation/SKILL.md +56 -0
- package/payload/product/package/targets/workspace/skills/buildr/capability-adaptation/agents/openai.yaml +4 -0
- package/payload/product/package/targets/workspace/skills/buildr/current-knowledge-maintenance/SKILL.md +103 -0
- package/payload/product/package/targets/workspace/skills/buildr/declaration-intake/SKILL.md +65 -0
- package/payload/product/package/targets/workspace/skills/buildr/git-operations/SKILL.md +100 -0
- package/payload/product/package/targets/workspace/skills/buildr/openspec-contract-guard/SKILL.md +65 -0
- package/payload/product/package/targets/workspace/skills/buildr/project-daily-progress/SKILL.md +52 -0
- package/payload/product/package/targets/workspace/skills/buildr/project-testing/SKILL.md +84 -0
- package/payload/product/package/targets/workspace/skills/buildr/project-testing/references/testing-model-v1.md +116 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-development/SKILL.md +108 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-environment/SKILL.md +42 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-environment/agents/openai.yaml +4 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-environment/references/project-environment-preparation-v1.md +14 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-environment/templates/project-preparation.yml +20 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-environment/templates/task-environment-plan-request.json +17 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-finish/SKILL.md +80 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-manager/SKILL.md +47 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-manager/agents/openai.yaml +4 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-retrospective/SKILL.md +101 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-retrospective/agents/openai.yaml +4 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-review/SKILL.md +60 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-review/agents/openai.yaml +4 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-triage/SKILL.md +119 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-verification/SKILL.md +142 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-verification/references/project-verification-v2.md +51 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-verification/templates/project-verification.yml +16 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-worktree/SKILL.md +28 -0
- package/payload/product/package/targets/workspace/skills/buildr/terminology-governance/SKILL.md +60 -0
- package/payload/product/package/targets/workspace/skills/buildr/ui-preview/SKILL.md +74 -0
- package/payload/product/package/targets/workspace/skills/contracts/buildr/current-knowledge-maintenance/v1.md +36 -0
- package/payload/product/package/targets/workspace/skills/contracts/buildr/current-knowledge-maintenance/v2.md +45 -0
- package/payload/product/package/targets/workspace/skills/contracts/buildr/git-operations/v1.md +39 -0
- package/payload/product/package/targets/workspace/skills/contracts/buildr/git-worktree-provider/v1.md +35 -0
- package/payload/product/package/targets/workspace/skills/contracts/buildr/task-development/v2.md +61 -0
- package/payload/product/package/targets/workspace/skills/contracts/buildr/task-environment/v1.md +37 -0
- package/payload/product/package/targets/workspace/skills/contracts/buildr/task-finish/v1.md +59 -0
- package/payload/product/package/targets/workspace/skills/contracts/buildr/task-record/v2.md +35 -0
- package/payload/product/package/targets/workspace/skills/contracts/buildr/task-retrospective/v2.md +41 -0
- package/payload/product/package/targets/workspace/skills/contracts/buildr/task-review/v1.md +39 -0
- package/payload/product/package/targets/workspace/skills/contracts/buildr/task-verification/v3.md +63 -0
- package/payload/product/package/targets/workspace/skills/contracts/buildr/terminology-governance/v1.md +36 -0
- package/{package → payload/product/package}/targets/workspace/skills/openspec/openspec-apply-change/SKILL.md +4 -3
- package/{package → payload/product/package}/targets/workspace/skills/openspec/openspec-archive-change/SKILL.md +4 -3
- package/{package → payload/product/package}/targets/workspace/skills/openspec/openspec-explore/SKILL.md +4 -1
- package/{package → payload/product/package}/targets/workspace/skills/openspec/openspec-propose/SKILL.md +4 -1
- package/{package → payload/product/package}/targets/workspace/skills/openspec/openspec-sync-specs/SKILL.md +4 -3
- package/payload/product/package/targets/workspace/skills/openspec/openspec-update-change/SKILL.md +86 -0
- package/payload/product/package.json +33 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0000_create_migration_ledger.sql +16 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0001_create_task_store.sql +47 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0002_create_parent_task_relations.sql +7 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0003_inline_parent_task_column.sql +19 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0004_create_task_current_records.sql +16 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0005_create_task_retrospective_current.sql +4 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0006_create_task_lifecycle_current.sql +4 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0007_create_task_finish_current.sql +46 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0008_create_task_environment_current.sql +8 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0009_retire_task_lifecycle_current.sql +107 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0010_add_task_retrospective_disposition.sql +19 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0011_create_task_execution_records.sql +115 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0012_compact_task_finish_current.sql +261 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0013_add_todo_task_retrospective_sources.sql +56 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0014_add_task_execution_invocation_identity.sql +14 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0015_add_task_execution_unknown_outcome.sql +143 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0016_allow_terminal_task_finish_target_lease.sql +83 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0017_expand_task_finish_repository_set.sql +111 -0
- package/payload/product/src/interfaces/local-app/web-dist/assets/antd-NAtxFWmu.js +394 -0
- package/payload/product/src/interfaces/local-app/web-dist/assets/index-BqoyfMSY.css +1 -0
- package/payload/product/src/interfaces/local-app/web-dist/assets/index-DTqvE0TF.js +39 -0
- package/payload/product/src/interfaces/local-app/web-dist/assets/react-9kRp7SbA.js +28 -0
- package/payload/product/src/interfaces/local-app/web-dist/index.html +19 -0
- package/payload/runtime/read-worker.cjs +45071 -0
- package/runtime/buildr.cjs +51533 -0
- package/scripts/postinstall.mjs +15 -0
- package/docs/agent-runtime-adapters.md +0 -94
- package/docs/cli-architecture.md +0 -65
- package/docs/cli-reference.md +0 -67
- package/docs/known-limitations.md +0 -15
- package/examples/minimal-workspace/README.md +0 -24
- package/package/README.md +0 -28
- package/package/manifest.yml +0 -150
- package/package/targets/runtime/skills/buildr/SKILL.md +0 -154
- package/package/targets/workspace/.buildr/workspace.yml +0 -5
- package/package/targets/workspace/commands/manifest.yml +0 -2
- package/package/targets/workspace/components/buildr/openspec/component.yml +0 -16
- package/package/targets/workspace/components/buildr/openspec/contributions/openspec-apply-sidebar.md +0 -3
- package/package/targets/workspace/components/buildr/openspec/contributions/openspec-archive-sidebar.md +0 -3
- package/package/targets/workspace/components/buildr/openspec/contributions/openspec-explore-sidebar.md +0 -3
- package/package/targets/workspace/components/buildr/openspec/contributions/openspec-propose-sidebar.md +0 -3
- package/package/targets/workspace/components/buildr/openspec/contributions/openspec-sync-sidebar.md +0 -3
- package/package/targets/workspace/components/buildr/openspec/contributions/task-finish-post-sync.md +0 -1
- package/package/targets/workspace/components/buildr/openspec/contributions/task-finish-pre-sync.md +0 -1
- package/package/targets/workspace/components/buildr/openspec/contributions/task-triage-change-ready.md +0 -10
- package/package/targets/workspace/components/manifest.yml +0 -2
- package/package/targets/workspace/gitignore +0 -16
- package/package/targets/workspace/projects/manifest.yml +0 -2
- package/package/targets/workspace/projects/services/manifest.yml +0 -3
- package/package/targets/workspace/projects/skills/manifest.yml +0 -2
- package/package/targets/workspace/rules/buildr/core.md +0 -65
- package/package/targets/workspace/rules/manifest.yml +0 -9
- package/package/targets/workspace/skills/buildr/git-ops/SKILL.md +0 -73
- package/package/targets/workspace/skills/buildr/openspec-contract-guard/SKILL.md +0 -67
- package/package/targets/workspace/skills/buildr/task-finish/SKILL.md +0 -104
- package/package/targets/workspace/skills/buildr/task-triage/SKILL.md +0 -103
- package/package/targets/workspace/skills/buildr/task-worktree/SKILL.md +0 -104
- package/package/targets/workspace/skills/manifest.yml +0 -38
- package/tools/buildr +0 -11
- package/tools/cli/application/cli-update.mjs +0 -219
- package/tools/cli/application/compose-runtime.mjs +0 -38
- package/tools/cli/application/doctor/runtime-diagnostics.mjs +0 -227
- package/tools/cli/application/doctor/scope-diagnostics.mjs +0 -440
- package/tools/cli/application/doctor/service-diagnostics.mjs +0 -184
- package/tools/cli/application/doctor.mjs +0 -201
- package/tools/cli/application/package-maintenance/builtin-receipts.mjs +0 -73
- package/tools/cli/application/package-maintenance/output.mjs +0 -148
- package/tools/cli/application/package-maintenance/smoke-checks.mjs +0 -463
- package/tools/cli/application/package-maintenance/static-validation.mjs +0 -680
- package/tools/cli/application/package-maintenance.mjs +0 -540
- package/tools/cli/application/runtime.mjs +0 -118
- package/tools/cli/application/workspace-operations.mjs +0 -311
- package/tools/cli/bootstrap.mjs +0 -6
- package/tools/cli/command/help.mjs +0 -296
- package/tools/cli/command/registry.mjs +0 -97
- package/tools/cli/domains/commands.mjs +0 -661
- package/tools/cli/domains/components.mjs +0 -922
- package/tools/cli/domains/openspec.mjs +0 -603
- package/tools/cli/domains/package-assets.mjs +0 -652
- package/tools/cli/domains/rules.mjs +0 -380
- package/tools/cli/domains/runtime.mjs +0 -87
- package/tools/cli/domains/skills.mjs +0 -647
- package/tools/cli/domains/workspace.mjs +0 -571
- package/tools/cli/shared/infrastructure.mjs +0 -411
- package/tools/cli/shared/json-contracts.mjs +0 -22
- package/tools/cli/shared/platform.mjs +0 -52
- package/tools/runtime/adapter-contract.mjs +0 -655
- package/tools/runtime/check-claude-code.mjs +0 -23
- package/tools/runtime/check-codex.mjs +0 -23
- package/tools/runtime/check-runtime.mjs +0 -98
- package/tools/runtime/projection.mjs +0 -375
- package/tools/runtime/render-claude-code-rules.mjs +0 -459
- package/tools/runtime/render-claude-code.mjs +0 -59
- package/tools/runtime/skills/arguments.mjs +0 -51
- package/tools/runtime/skills/contributions.mjs +0 -171
- package/tools/runtime/skills/manifests.mjs +0 -167
- package/tools/runtime/skills/primitives.mjs +0 -86
- package/tools/runtime/skills/render-plan.mjs +0 -243
- package/tools/runtime/skills/sources.mjs +0 -276
- package/tools/shared/fetch-remote-text.mjs +0 -78
- package/tools/verification/integrity/managed-data-integrity.mjs +0 -107
- package/tools/verification/integrity/managed-mutations.mjs +0 -72
- package/tools/verification/openspec/contract.mjs +0 -212
- package/tools/verification/runtime/adapter-contract.mjs +0 -218
- package/tools/verification/runtime/adapter-parity.mjs +0 -173
- /package/{package → payload/product/package}/targets/workspace/AGENTS.md +0 -0
|
@@ -1,603 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
fs,
|
|
3
|
-
crypto,
|
|
4
|
-
path,
|
|
5
|
-
process,
|
|
6
|
-
OPENSPEC_CONTRACT_BASELINE_SCHEMA,
|
|
7
|
-
OPENSPEC_CONTRACT_RECEIPT_SCHEMA,
|
|
8
|
-
OPENSPEC_CONTRACT_SUPPORTED_UPSTREAM_VERSIONS,
|
|
9
|
-
} from '../shared/platform.mjs';
|
|
10
|
-
import { PUBLIC_JSON_SCHEMAS, withJsonSchema } from '../shared/json-contracts.mjs';
|
|
11
|
-
|
|
12
|
-
export function registerDomainsOpenspec(runtime) {
|
|
13
|
-
const readProjectsRegistryIfExists = (...args) => runtime.readProjectsRegistryIfExists(...args);
|
|
14
|
-
const usage = (...args) => runtime.usage(...args);
|
|
15
|
-
const isPlainObject = (...args) => runtime.isPlainObject(...args);
|
|
16
|
-
const assertNoUnknownOptions = (...args) => runtime.assertNoUnknownOptions(...args);
|
|
17
|
-
const positionalArgs = (...args) => runtime.positionalArgs(...args);
|
|
18
|
-
const runCommandsCheck = (...args) => runtime.runCommandsCheck(...args);
|
|
19
|
-
const readComponentsManifestForWrite = (...args) => runtime.readComponentsManifestForWrite(...args);
|
|
20
|
-
const readComponentDefinition = (...args) => runtime.readComponentDefinition(...args);
|
|
21
|
-
const componentDefinitionFile = (...args) => runtime.componentDefinitionFile(...args);
|
|
22
|
-
const assertName = (...args) => runtime.assertName(...args);
|
|
23
|
-
const optionValue = (...args) => runtime.optionValue(...args);
|
|
24
|
-
const atomicWriteJson = (...args) => runtime.atomicWriteJson(...args);
|
|
25
|
-
const hasFlag = (...args) => runtime.hasFlag(...args);
|
|
26
|
-
const toPosixRelative = (...args) => runtime.toPosixRelative(...args);
|
|
27
|
-
const existsDirectory = (...args) => runtime.existsDirectory(...args);
|
|
28
|
-
const existsFile = (...args) => runtime.existsFile(...args);
|
|
29
|
-
const assertInitializedBuildrWorkspace = (...args) => runtime.assertInitializedBuildrWorkspace(...args);
|
|
30
|
-
|
|
31
|
-
function normalizeOpenSpecContractText(content) {
|
|
32
|
-
return String(content).replace(/\r\n/g, '\n').replace(/[ \t]+$/gm, '').replace(/\n+$/, '\n');
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function openSpecContractHash(value) {
|
|
36
|
-
return `sha256-${crypto.createHash('sha256').update(typeof value === 'string' ? value : JSON.stringify(value)).digest('hex')}`;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function openSpecContractChangePath(projectRoot, change) {
|
|
40
|
-
assertName(change, 'OpenSpec change');
|
|
41
|
-
const changesRoot = path.join(projectRoot, 'openspec', 'changes');
|
|
42
|
-
const changeRoot = path.join(changesRoot, change);
|
|
43
|
-
if (!changeRoot.startsWith(`${changesRoot}${path.sep}`) || !existsDirectory(changeRoot)) {
|
|
44
|
-
throw new Error(`Active OpenSpec change not found: ${change}`);
|
|
45
|
-
}
|
|
46
|
-
if (!existsFile(path.join(changeRoot, '.openspec.yaml'))) {
|
|
47
|
-
throw new Error(`OpenSpec change is missing .openspec.yaml: ${change}`);
|
|
48
|
-
}
|
|
49
|
-
return changeRoot;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function resolveOpenSpecContractProject(targetRoot, project) {
|
|
53
|
-
assertInitializedBuildrWorkspace(targetRoot);
|
|
54
|
-
assertName(project, 'Project');
|
|
55
|
-
const registry = readProjectsRegistryIfExists(targetRoot);
|
|
56
|
-
if (!registry || !registry.projects?.[project]) throw new Error(`Project is not registered in projects/manifest.yml: ${project}`);
|
|
57
|
-
const projectRoot = path.join(targetRoot, 'projects', project);
|
|
58
|
-
if (!existsDirectory(projectRoot)) throw new Error(`Project directory is missing: projects/${project}`);
|
|
59
|
-
const planningRoot = path.join(projectRoot, 'openspec');
|
|
60
|
-
if (!existsDirectory(path.join(planningRoot, 'specs')) || !existsDirectory(path.join(planningRoot, 'changes'))) {
|
|
61
|
-
throw new Error(`Project does not contain an initialized OpenSpec planning root: projects/${project}/openspec`);
|
|
62
|
-
}
|
|
63
|
-
return { projectRoot, planningRoot };
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function openSpecContractComponent(targetRoot) {
|
|
67
|
-
const registry = readComponentsManifestForWrite(targetRoot);
|
|
68
|
-
const entry = registry.components.find((item) => item.id === 'openspec');
|
|
69
|
-
if (!entry || entry.enabled === false || entry.state === 'uninstalled') {
|
|
70
|
-
throw new Error('OpenSpec Component is not installed. Run buildr component install openspec --agent <agent> --target <workspace>.');
|
|
71
|
-
}
|
|
72
|
-
const definition = readComponentDefinition(componentDefinitionFile(targetRoot, entry), 'openspec');
|
|
73
|
-
const upstreamVersion = definition.upstream?.version;
|
|
74
|
-
if (!upstreamVersion || !OPENSPEC_CONTRACT_SUPPORTED_UPSTREAM_VERSIONS.has(upstreamVersion)) {
|
|
75
|
-
throw new Error(`OpenSpec contract guard does not support upstream version ${upstreamVersion || '<missing>'}. Update Buildr/OpenSpec Component and rerun verification.`);
|
|
76
|
-
}
|
|
77
|
-
const commands = runCommandsCheck(targetRoot);
|
|
78
|
-
const openspec = commands.commands.find((item) => item.id === 'openspec');
|
|
79
|
-
if (!openspec || openspec.status !== 'ok' || openspec.version?.current !== upstreamVersion) {
|
|
80
|
-
const actual = openspec?.version?.current || openspec?.status || '<missing>';
|
|
81
|
-
throw new Error(`OpenSpec CLI does not satisfy Component upstream version ${upstreamVersion}: ${actual}. ${openspec?.installHint || 'Install the declared OpenSpec CLI version; Buildr does not install it automatically.'}`);
|
|
82
|
-
}
|
|
83
|
-
return { entry, definition, upstreamVersion };
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function parseOpenSpecRequirementBlocks(content, label) {
|
|
87
|
-
const normalized = normalizeOpenSpecContractText(content);
|
|
88
|
-
const matches = [...normalized.matchAll(/^### Requirement:\s*(.+?)\s*$/gm)];
|
|
89
|
-
const requirements = new Map();
|
|
90
|
-
for (let index = 0; index < matches.length; index += 1) {
|
|
91
|
-
const title = matches[index][1].trim();
|
|
92
|
-
if (!title) throw new Error(`${label} contains an empty Requirement title.`);
|
|
93
|
-
if (requirements.has(title)) throw new Error(`${label} contains duplicate Requirement: ${title}`);
|
|
94
|
-
const start = matches[index].index;
|
|
95
|
-
const end = index + 1 < matches.length ? matches[index + 1].index : normalized.length;
|
|
96
|
-
requirements.set(title, normalizeOpenSpecContractText(normalized.slice(start, end)));
|
|
97
|
-
}
|
|
98
|
-
return requirements;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function openSpecSection(content, name) {
|
|
102
|
-
const normalized = normalizeOpenSpecContractText(content);
|
|
103
|
-
const header = new RegExp(`^## ${name}\\s*$`, 'm');
|
|
104
|
-
const match = header.exec(normalized);
|
|
105
|
-
if (!match) return '';
|
|
106
|
-
const next = /^## /gm;
|
|
107
|
-
next.lastIndex = match.index + match[0].length;
|
|
108
|
-
const nextMatch = next.exec(normalized);
|
|
109
|
-
return normalized.slice(match.index + match[0].length, nextMatch ? nextMatch.index : normalized.length);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function parseOpenSpecDeltaSpec(content, capability, label) {
|
|
113
|
-
const operations = [];
|
|
114
|
-
for (const [section, type] of [['ADDED Requirements', 'ADDED'], ['MODIFIED Requirements', 'MODIFIED'], ['REMOVED Requirements', 'REMOVED']]) {
|
|
115
|
-
const requirements = parseOpenSpecRequirementBlocks(openSpecSection(content, section), `${label} ${section}`);
|
|
116
|
-
for (const [title, requirement] of requirements) operations.push({ type, capability, title, requirement });
|
|
117
|
-
}
|
|
118
|
-
const renamed = openSpecSection(content, 'RENAMED Requirements');
|
|
119
|
-
const renamePattern = /-\s*FROM:\s*`?### Requirement:\s*(.+?)`?\s*\n\s*-\s*TO:\s*`?### Requirement:\s*(.+?)`?\s*(?=\n|$)/g;
|
|
120
|
-
for (const match of renamed.matchAll(renamePattern)) {
|
|
121
|
-
const from = match[1].trim();
|
|
122
|
-
const to = match[2].trim();
|
|
123
|
-
if (!from || !to || from === to) throw new Error(`${label} contains an invalid RENAMED Requirement.`);
|
|
124
|
-
operations.push({ type: 'RENAMED', capability, from, to });
|
|
125
|
-
}
|
|
126
|
-
if (renamed.trim() && operations.filter((item) => item.type === 'RENAMED').length === 0) {
|
|
127
|
-
throw new Error(`${label} contains an unsupported RENAMED Requirements format.`);
|
|
128
|
-
}
|
|
129
|
-
return operations;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function parseOpenSpecChangeDelta(changeRoot) {
|
|
133
|
-
const specsRoot = path.join(changeRoot, 'specs');
|
|
134
|
-
if (!existsDirectory(specsRoot)) return { capabilities: new Map(), operations: [], hash: openSpecContractHash('') };
|
|
135
|
-
const capabilities = new Map();
|
|
136
|
-
const operations = [];
|
|
137
|
-
for (const entry of fs.readdirSync(specsRoot, { withFileTypes: true }).sort((left, right) => left.name.localeCompare(right.name))) {
|
|
138
|
-
if (!entry.isDirectory()) continue;
|
|
139
|
-
assertName(entry.name, 'OpenSpec capability');
|
|
140
|
-
const file = path.join(specsRoot, entry.name, 'spec.md');
|
|
141
|
-
if (!existsFile(file)) throw new Error(`Delta spec is missing spec.md: specs/${entry.name}`);
|
|
142
|
-
const content = normalizeOpenSpecContractText(fs.readFileSync(file, 'utf8'));
|
|
143
|
-
const items = parseOpenSpecDeltaSpec(content, entry.name, `Delta specs/${entry.name}/spec.md`);
|
|
144
|
-
if (items.length === 0) throw new Error(`Delta spec does not declare any Requirement operation: specs/${entry.name}/spec.md`);
|
|
145
|
-
capabilities.set(entry.name, { file, content, operations: items });
|
|
146
|
-
operations.push(...items);
|
|
147
|
-
}
|
|
148
|
-
const identities = new Set();
|
|
149
|
-
for (const operation of operations) {
|
|
150
|
-
const names = operation.type === 'RENAMED' ? [operation.from, operation.to] : [operation.title];
|
|
151
|
-
for (const name of names) {
|
|
152
|
-
const identity = `${operation.capability}\u0000${name}`;
|
|
153
|
-
if (identities.has(identity)) throw new Error(`Delta declares conflicting Requirement operations: ${operation.capability} / ${name}`);
|
|
154
|
-
identities.add(identity);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
return { capabilities, operations, hash: openSpecContractHash([...capabilities.values()].map((item) => `${item.file}\n${item.content}`).join('\n')) };
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function readOpenSpecCanonicalRequirements(projectRoot, capability) {
|
|
161
|
-
assertName(capability, 'OpenSpec capability');
|
|
162
|
-
const file = path.join(projectRoot, 'openspec', 'specs', capability, 'spec.md');
|
|
163
|
-
if (!existsFile(file)) return { file, requirements: new Map() };
|
|
164
|
-
return { file, requirements: parseOpenSpecRequirementBlocks(fs.readFileSync(file, 'utf8'), `Canonical specs/${capability}/spec.md`) };
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function parseOpenSpecProposalCapabilities(changeRoot) {
|
|
168
|
-
const file = path.join(changeRoot, 'proposal.md');
|
|
169
|
-
if (!existsFile(file)) throw new Error('OpenSpec proposal.md is missing.');
|
|
170
|
-
const content = normalizeOpenSpecContractText(fs.readFileSync(file, 'utf8'));
|
|
171
|
-
const result = { new: new Set(), modified: new Set() };
|
|
172
|
-
for (const [heading, target] of [['New Capabilities', result.new], ['Modified Capabilities', result.modified]]) {
|
|
173
|
-
const section = openSpecSection(content, `# ${heading}`).trim() || (() => {
|
|
174
|
-
const match = new RegExp(`^### ${heading}\\s*$`, 'm').exec(content);
|
|
175
|
-
if (!match) return '';
|
|
176
|
-
const rest = content.slice(match.index + match[0].length);
|
|
177
|
-
const next = /^### /m.exec(rest);
|
|
178
|
-
return next ? rest.slice(0, next.index) : rest;
|
|
179
|
-
})();
|
|
180
|
-
for (const match of section.matchAll(/^-\s+`([A-Za-z0-9._-]+)`\s*:/gm)) target.add(match[1]);
|
|
181
|
-
}
|
|
182
|
-
return result;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function openSpecBaselinePath(changeRoot) {
|
|
186
|
-
return path.join(changeRoot, '.buildr', 'contract-baseline.json');
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
function openSpecReceiptPath(changeRoot) {
|
|
190
|
-
return path.join(changeRoot, '.buildr', 'contract-pre-sync-receipt.json');
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
function readOpenSpecContractJson(file, schema) {
|
|
194
|
-
if (!existsFile(file)) return null;
|
|
195
|
-
let value;
|
|
196
|
-
try {
|
|
197
|
-
value = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
198
|
-
} catch (error) {
|
|
199
|
-
throw new Error(`OpenSpec contract sidecar is invalid JSON: ${toPosixRelative(process.cwd(), file)} (${error.message})`);
|
|
200
|
-
}
|
|
201
|
-
if (!isPlainObject(value) || value.schemaVersion !== schema) throw new Error(`OpenSpec contract sidecar has unsupported schema: ${toPosixRelative(process.cwd(), file)}`);
|
|
202
|
-
return value;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
function writeOpenSpecContractJson(file, value) {
|
|
206
|
-
atomicWriteJson(file, value);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
function baselineTargetsForDelta(projectRoot, delta) {
|
|
210
|
-
const targets = [];
|
|
211
|
-
for (const operation of delta.operations) {
|
|
212
|
-
const canonical = readOpenSpecCanonicalRequirements(projectRoot, operation.capability).requirements;
|
|
213
|
-
if (operation.type === 'RENAMED') {
|
|
214
|
-
for (const [title, expectedState] of [[operation.from, 'present'], [operation.to, 'absent']]) {
|
|
215
|
-
targets.push({ capability: operation.capability, title, operation: operation.type, state: expectedState, content: canonical.get(title) || null });
|
|
216
|
-
}
|
|
217
|
-
} else {
|
|
218
|
-
const expectedState = operation.type === 'ADDED' ? 'absent' : 'present';
|
|
219
|
-
targets.push({ capability: operation.capability, title: operation.title, operation: operation.type, state: expectedState, content: canonical.get(operation.title) || null });
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
for (const target of targets) {
|
|
223
|
-
if ((target.state === 'present') !== Boolean(target.content)) {
|
|
224
|
-
throw new Error(`Canonical Requirement state does not match delta operation: ${target.capability} / ${target.title}`);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
return targets;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
function expectedOpenSpecBaselineTargets(delta) {
|
|
231
|
-
const targets = [];
|
|
232
|
-
for (const operation of delta.operations) {
|
|
233
|
-
if (operation.type === 'RENAMED') {
|
|
234
|
-
targets.push({ capability: operation.capability, title: operation.from, operation: operation.type, state: 'present' });
|
|
235
|
-
targets.push({ capability: operation.capability, title: operation.to, operation: operation.type, state: 'absent' });
|
|
236
|
-
} else {
|
|
237
|
-
targets.push({ capability: operation.capability, title: operation.title, operation: operation.type, state: operation.type === 'ADDED' ? 'absent' : 'present' });
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
return targets;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
function baselineTargetMap(baseline) {
|
|
244
|
-
const targets = Array.isArray(baseline?.targets) ? baseline.targets : [];
|
|
245
|
-
const result = new Map();
|
|
246
|
-
for (const target of targets) {
|
|
247
|
-
if (!isPlainObject(target) || typeof target.capability !== 'string' || typeof target.title !== 'string'
|
|
248
|
-
|| !['present', 'absent'].includes(target.state) || typeof target.operation !== 'string') {
|
|
249
|
-
throw new Error('OpenSpec contract baseline contains an invalid target.');
|
|
250
|
-
}
|
|
251
|
-
const key = `${target.capability}\u0000${target.title}`;
|
|
252
|
-
if (result.has(key)) throw new Error(`OpenSpec contract baseline contains duplicate target: ${target.capability} / ${target.title}`);
|
|
253
|
-
if (target.state === 'present' && typeof target.content !== 'string') throw new Error(`OpenSpec contract baseline is missing content: ${target.capability} / ${target.title}`);
|
|
254
|
-
if (target.state === 'absent' && target.content !== null) throw new Error(`OpenSpec contract baseline must record null content for absent Requirement: ${target.capability} / ${target.title}`);
|
|
255
|
-
result.set(key, target);
|
|
256
|
-
}
|
|
257
|
-
return result;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
function createOpenSpecContractResult(stage, change, project, upstreamVersion) {
|
|
261
|
-
return {
|
|
262
|
-
stage,
|
|
263
|
-
change,
|
|
264
|
-
project,
|
|
265
|
-
upstreamVersion,
|
|
266
|
-
baselineState: 'missing',
|
|
267
|
-
conflicts: [],
|
|
268
|
-
findings: [],
|
|
269
|
-
ok: false,
|
|
270
|
-
nextActions: [],
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
function addOpenSpecContractFinding(result, severity, code, message, extra = {}) {
|
|
275
|
-
result.findings.push({ severity, code, message, ...extra });
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
function finishOpenSpecContractResult(result) {
|
|
279
|
-
result.ok = !result.findings.some((finding) => finding.severity === 'error');
|
|
280
|
-
result.nextActions = [...new Map(result.findings
|
|
281
|
-
.filter((finding) => finding.nextAction)
|
|
282
|
-
.map((finding) => [finding.nextAction, finding.nextAction])).values()];
|
|
283
|
-
return result;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
function printOpenSpecContractResult(result) {
|
|
287
|
-
console.log(`Buildr OpenSpec contract ${result.stage}: ${result.project}/${result.change}`);
|
|
288
|
-
console.log(`Status: ${result.ok ? 'passed' : 'blocked'}; baseline=${result.baselineState}; conflicts=${result.conflicts.length}`);
|
|
289
|
-
for (const finding of result.findings) {
|
|
290
|
-
console.log(`[${finding.severity}] ${finding.code} - ${finding.message}`);
|
|
291
|
-
if (finding.nextAction) console.log(` 下一步:${finding.nextAction}`);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
function validateOpenSpecProposalAlignment(projectRoot, changeRoot, delta, baseline, result) {
|
|
296
|
-
let proposal;
|
|
297
|
-
try {
|
|
298
|
-
proposal = parseOpenSpecProposalCapabilities(changeRoot);
|
|
299
|
-
} catch (error) {
|
|
300
|
-
addOpenSpecContractFinding(result, 'error', 'openspec_contract.proposal_invalid', error.message, {
|
|
301
|
-
nextAction: '修复 proposal.md 的 Capabilities 列表后重新运行 proposal check。',
|
|
302
|
-
});
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
const deltaCapabilities = new Set(delta.capabilities.keys());
|
|
306
|
-
for (const capability of deltaCapabilities) {
|
|
307
|
-
if (!proposal.new.has(capability) && !proposal.modified.has(capability)) {
|
|
308
|
-
addOpenSpecContractFinding(result, 'error', 'openspec_contract.proposal_delta_missing', `proposal 未声明 delta capability:${capability}`, {
|
|
309
|
-
capability,
|
|
310
|
-
nextAction: '在 proposal.md 的 Capabilities 中声明该 capability,或移除无关 delta spec。',
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
const exists = existsFile(path.join(projectRoot, 'openspec', 'specs', capability, 'spec.md'));
|
|
314
|
-
if (proposal.new.has(capability) && exists) addOpenSpecContractFinding(result, 'error', 'openspec_contract.proposal_kind_mismatch', `proposal 将已有 canonical capability 标为 new:${capability}`, { capability });
|
|
315
|
-
if (proposal.modified.has(capability) && !exists) addOpenSpecContractFinding(result, 'error', 'openspec_contract.proposal_kind_mismatch', `proposal 将不存在的 canonical capability 标为 modified:${capability}`, { capability });
|
|
316
|
-
}
|
|
317
|
-
for (const capability of [...proposal.new, ...proposal.modified]) {
|
|
318
|
-
if (!deltaCapabilities.has(capability)) addOpenSpecContractFinding(result, 'error', 'openspec_contract.proposal_delta_absent', `proposal capability 缺少 delta spec:${capability}`, {
|
|
319
|
-
capability,
|
|
320
|
-
nextAction: '创建对应 specs/<capability>/spec.md,或移除 proposal 中的 capability。',
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
if (!baseline) return;
|
|
324
|
-
let baselineTargets;
|
|
325
|
-
try {
|
|
326
|
-
baselineTargets = baselineTargetMap(baseline);
|
|
327
|
-
} catch (error) {
|
|
328
|
-
addOpenSpecContractFinding(result, 'error', 'openspec_contract.baseline_invalid', error.message, { nextAction: '使用 baseline create --update 显式重建基线。' });
|
|
329
|
-
return;
|
|
330
|
-
}
|
|
331
|
-
const expected = expectedOpenSpecBaselineTargets(delta);
|
|
332
|
-
const expectedMap = new Map(expected.map((target) => [`${target.capability}\u0000${target.title}`, target]));
|
|
333
|
-
for (const [key, target] of expectedMap) {
|
|
334
|
-
const actual = baselineTargets.get(key);
|
|
335
|
-
if (!actual || actual.operation !== target.operation || actual.state !== target.state) {
|
|
336
|
-
addOpenSpecContractFinding(result, 'error', 'openspec_contract.baseline_incomplete', `基线未覆盖当前 delta target:${target.capability} / ${target.title}`, {
|
|
337
|
-
capability: target.capability,
|
|
338
|
-
requirement: target.title,
|
|
339
|
-
nextAction: '审阅当前 canonical facts 后运行 baseline create --update。',
|
|
340
|
-
});
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
for (const [key, target] of baselineTargets) {
|
|
344
|
-
if (!expectedMap.has(key)) addOpenSpecContractFinding(result, 'error', 'openspec_contract.baseline_extra', `基线包含当前 delta 未触达的 target:${target.capability} / ${target.title}`, {
|
|
345
|
-
capability: target.capability,
|
|
346
|
-
requirement: target.title,
|
|
347
|
-
nextAction: '审阅 delta 后运行 baseline create --update。',
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
if (baseline.deltaHash !== delta.hash) addOpenSpecContractFinding(result, 'error', 'openspec_contract.baseline_delta_changed', 'delta 在创建基线后已变化。', {
|
|
351
|
-
nextAction: '审阅变更范围后运行 baseline create --update。',
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
function listActiveOpenSpecChangeRoots(projectRoot) {
|
|
356
|
-
const root = path.join(projectRoot, 'openspec', 'changes');
|
|
357
|
-
if (!existsDirectory(root)) return [];
|
|
358
|
-
return fs.readdirSync(root, { withFileTypes: true })
|
|
359
|
-
.filter((entry) => entry.isDirectory() && entry.name !== 'archive' && existsFile(path.join(root, entry.name, '.openspec.yaml')))
|
|
360
|
-
.map((entry) => ({ id: entry.name, root: path.join(root, entry.name) }));
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
function openSpecDeltaIdentities(delta) {
|
|
364
|
-
const identities = [];
|
|
365
|
-
for (const operation of delta.operations) {
|
|
366
|
-
const names = operation.type === 'RENAMED' ? [operation.from, operation.to] : [operation.title];
|
|
367
|
-
for (const requirement of names) identities.push({ capability: operation.capability, requirement, operation: operation.type });
|
|
368
|
-
}
|
|
369
|
-
return identities;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
function detectOpenSpecActiveConflicts(projectRoot, change, delta, result) {
|
|
373
|
-
const current = new Set(openSpecDeltaIdentities(delta).map((item) => `${item.capability}\u0000${item.requirement}`));
|
|
374
|
-
for (const candidate of listActiveOpenSpecChangeRoots(projectRoot)) {
|
|
375
|
-
if (candidate.id === change) continue;
|
|
376
|
-
let other;
|
|
377
|
-
try {
|
|
378
|
-
other = parseOpenSpecChangeDelta(candidate.root);
|
|
379
|
-
} catch (error) {
|
|
380
|
-
addOpenSpecContractFinding(result, 'error', 'openspec_contract.active_change_invalid', `无法解析 active change ${candidate.id}:${error.message}`, {
|
|
381
|
-
change: candidate.id,
|
|
382
|
-
nextAction: '修复或归档无效 active change 后重新检查。',
|
|
383
|
-
});
|
|
384
|
-
continue;
|
|
385
|
-
}
|
|
386
|
-
for (const identity of openSpecDeltaIdentities(other)) {
|
|
387
|
-
const key = `${identity.capability}\u0000${identity.requirement}`;
|
|
388
|
-
if (!current.has(key)) continue;
|
|
389
|
-
const conflict = { change: candidate.id, capability: identity.capability, requirement: identity.requirement };
|
|
390
|
-
result.conflicts.push(conflict);
|
|
391
|
-
addOpenSpecContractFinding(result, 'error', 'openspec_contract.active_conflict', `active changes 同时触达 Requirement:${identity.capability} / ${identity.requirement} (${candidate.id})`, {
|
|
392
|
-
...conflict,
|
|
393
|
-
nextAction: '合并语义相同的 change,或先完成并重新建立后续 change 的基线。',
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
function validateOpenSpecBaselineCurrent(projectRoot, baseline, result) {
|
|
400
|
-
let targets;
|
|
401
|
-
try {
|
|
402
|
-
targets = baselineTargetMap(baseline);
|
|
403
|
-
} catch (error) {
|
|
404
|
-
addOpenSpecContractFinding(result, 'error', 'openspec_contract.baseline_invalid', error.message, { nextAction: '使用 baseline create --update 显式重建基线。' });
|
|
405
|
-
return;
|
|
406
|
-
}
|
|
407
|
-
for (const target of targets.values()) {
|
|
408
|
-
const actual = readOpenSpecCanonicalRequirements(projectRoot, target.capability).requirements.get(target.title) || null;
|
|
409
|
-
const expected = target.content;
|
|
410
|
-
if (actual !== expected) {
|
|
411
|
-
result.baselineState = 'stale';
|
|
412
|
-
addOpenSpecContractFinding(result, 'error', 'openspec_contract.baseline_stale', `canonical Requirement 已偏离基线:${target.capability} / ${target.title}`, {
|
|
413
|
-
capability: target.capability,
|
|
414
|
-
requirement: target.title,
|
|
415
|
-
expectedState: target.state,
|
|
416
|
-
nextAction: '先审阅并合并已发生的契约变化,再显式更新或重建该 change 的基线。',
|
|
417
|
-
});
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
function snapshotOpenSpecCapabilities(projectRoot, delta) {
|
|
423
|
-
const capabilities = {};
|
|
424
|
-
for (const capability of delta.capabilities.keys()) {
|
|
425
|
-
const requirements = readOpenSpecCanonicalRequirements(projectRoot, capability).requirements;
|
|
426
|
-
capabilities[capability] = Object.fromEntries([...requirements.entries()].sort(([left], [right]) => left.localeCompare(right)));
|
|
427
|
-
}
|
|
428
|
-
return capabilities;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
function snapshotOpenSpecSpecIntegrities(projectRoot, delta) {
|
|
432
|
-
const integrities = {};
|
|
433
|
-
for (const capability of delta.capabilities.keys()) {
|
|
434
|
-
const file = path.join(projectRoot, 'openspec', 'specs', capability, 'spec.md');
|
|
435
|
-
const content = existsFile(file) ? normalizeOpenSpecContractText(fs.readFileSync(file, 'utf8')) : '';
|
|
436
|
-
integrities[capability] = openSpecContractHash(content);
|
|
437
|
-
}
|
|
438
|
-
return integrities;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
function renameRequirementBlock(content, from, to) {
|
|
442
|
-
return normalizeOpenSpecContractText(content.replace(`### Requirement: ${from}`, `### Requirement: ${to}`));
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
function validateOpenSpecPostSync(projectRoot, delta, receipt, result) {
|
|
446
|
-
if (receipt.deltaHash !== delta.hash) {
|
|
447
|
-
addOpenSpecContractFinding(result, 'error', 'openspec_contract.receipt_delta_changed', 'delta 在 pre-sync 后发生变化。', {
|
|
448
|
-
nextAction: '重新运行 pre-sync check 后再验证同步结果。',
|
|
449
|
-
});
|
|
450
|
-
return;
|
|
451
|
-
}
|
|
452
|
-
const touched = new Map();
|
|
453
|
-
for (const operation of delta.operations) {
|
|
454
|
-
const names = operation.type === 'RENAMED' ? [operation.from, operation.to] : [operation.title];
|
|
455
|
-
for (const name of names) touched.set(`${operation.capability}\u0000${name}`, operation);
|
|
456
|
-
const requirements = readOpenSpecCanonicalRequirements(projectRoot, operation.capability).requirements;
|
|
457
|
-
if (operation.type === 'ADDED' || operation.type === 'MODIFIED') {
|
|
458
|
-
if (requirements.get(operation.title) !== operation.requirement) addOpenSpecContractFinding(result, 'error', 'openspec_contract.post_sync_result_mismatch', `同步结果不匹配 ${operation.type} Requirement:${operation.capability} / ${operation.title}`, { capability: operation.capability, requirement: operation.title });
|
|
459
|
-
} else if (operation.type === 'REMOVED') {
|
|
460
|
-
if (requirements.has(operation.title)) addOpenSpecContractFinding(result, 'error', 'openspec_contract.post_sync_result_mismatch', `同步结果仍保留 REMOVED Requirement:${operation.capability} / ${operation.title}`, { capability: operation.capability, requirement: operation.title });
|
|
461
|
-
} else if (operation.type === 'RENAMED') {
|
|
462
|
-
const before = receipt.capabilities?.[operation.capability]?.[operation.from];
|
|
463
|
-
const expected = before ? renameRequirementBlock(before, operation.from, operation.to) : null;
|
|
464
|
-
if (requirements.has(operation.from) || !expected || requirements.get(operation.to) !== expected) addOpenSpecContractFinding(result, 'error', 'openspec_contract.post_sync_rename_mismatch', `同步结果不匹配 RENAMED Requirement:${operation.capability} / ${operation.from} -> ${operation.to}`, { capability: operation.capability, requirement: operation.from });
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
for (const [capability, snapshot] of Object.entries(receipt.capabilities || {})) {
|
|
468
|
-
const current = readOpenSpecCanonicalRequirements(projectRoot, capability).requirements;
|
|
469
|
-
const names = new Set([...Object.keys(snapshot), ...current.keys()]);
|
|
470
|
-
for (const name of names) {
|
|
471
|
-
if (touched.has(`${capability}\u0000${name}`)) continue;
|
|
472
|
-
if ((snapshot[name] || null) !== (current.get(name) || null)) addOpenSpecContractFinding(result, 'error', 'openspec_contract.post_sync_untouched_changed', `同步修改了未触达 Requirement:${capability} / ${name}`, { capability, requirement: name });
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
function openSpecContractContext(args, options = {}) {
|
|
478
|
-
const allowed = new Set(['--target', '--project', '--json', '--adopt-current', '--update', '--stage']);
|
|
479
|
-
assertNoUnknownOptions(args, allowed, new Set(['--json', '--adopt-current', '--update']));
|
|
480
|
-
const positionals = positionalArgs(args);
|
|
481
|
-
const change = positionals[0];
|
|
482
|
-
if (!change || positionals.length !== 1) throw new Error(`Usage: ${options.usage}`);
|
|
483
|
-
const targetRoot = path.resolve(optionValue(args, '--target', process.cwd()));
|
|
484
|
-
const project = optionValue(args, '--project');
|
|
485
|
-
const { projectRoot } = resolveOpenSpecContractProject(targetRoot, project);
|
|
486
|
-
const component = openSpecContractComponent(targetRoot);
|
|
487
|
-
const changeRoot = openSpecContractChangePath(projectRoot, change);
|
|
488
|
-
const delta = parseOpenSpecChangeDelta(changeRoot);
|
|
489
|
-
if (delta.operations.length === 0) throw new Error(`OpenSpec change has no delta Requirements: ${change}`);
|
|
490
|
-
return { targetRoot, project, projectRoot, component, change, changeRoot, delta };
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
function openspecBaselineCreate(args) {
|
|
494
|
-
const context = openSpecContractContext(args, {
|
|
495
|
-
usage: 'buildr openspec baseline create <change> --project <project> [--target <dir>] [--adopt-current] [--update] [--json]',
|
|
496
|
-
});
|
|
497
|
-
const json = hasFlag(args, '--json');
|
|
498
|
-
const baselineFile = openSpecBaselinePath(context.changeRoot);
|
|
499
|
-
if (existsFile(baselineFile) && !hasFlag(args, '--update')) {
|
|
500
|
-
throw new Error(`OpenSpec contract baseline already exists: ${toPosixRelative(context.projectRoot, baselineFile)}. Use --update only after reviewing the canonical facts.`);
|
|
501
|
-
}
|
|
502
|
-
const targets = baselineTargetsForDelta(context.projectRoot, context.delta);
|
|
503
|
-
const baseline = {
|
|
504
|
-
schemaVersion: OPENSPEC_CONTRACT_BASELINE_SCHEMA,
|
|
505
|
-
change: context.change,
|
|
506
|
-
project: context.project,
|
|
507
|
-
upstreamVersion: context.component.upstreamVersion,
|
|
508
|
-
deltaHash: context.delta.hash,
|
|
509
|
-
adopted: hasFlag(args, '--adopt-current'),
|
|
510
|
-
targets,
|
|
511
|
-
};
|
|
512
|
-
writeOpenSpecContractJson(baselineFile, baseline);
|
|
513
|
-
const payload = {
|
|
514
|
-
ok: true,
|
|
515
|
-
change: context.change,
|
|
516
|
-
project: context.project,
|
|
517
|
-
upstreamVersion: context.component.upstreamVersion,
|
|
518
|
-
baselinePath: toPosixRelative(context.projectRoot, baselineFile),
|
|
519
|
-
adopted: baseline.adopted,
|
|
520
|
-
targetCount: targets.length,
|
|
521
|
-
nextActions: [`buildr openspec check ${context.change} --stage proposal --project ${context.project} --target ${context.targetRoot} --json`],
|
|
522
|
-
};
|
|
523
|
-
if (json) process.stdout.write(`${JSON.stringify(withJsonSchema(PUBLIC_JSON_SCHEMAS.openspecBaseline, payload), null, 2)}\n`);
|
|
524
|
-
else console.log(`Created OpenSpec contract baseline: ${payload.baselinePath} (${targets.length} targets)`);
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
function openspecCheck(args) {
|
|
528
|
-
const context = openSpecContractContext(args, {
|
|
529
|
-
usage: 'buildr openspec check <change> --stage <proposal|pre-sync|post-sync> --project <project> [--target <dir>] [--json]',
|
|
530
|
-
});
|
|
531
|
-
const stage = optionValue(args, '--stage');
|
|
532
|
-
if (!['proposal', 'pre-sync', 'post-sync'].includes(stage)) throw new Error(`Unsupported OpenSpec contract stage: ${stage || '<missing>'}`);
|
|
533
|
-
const json = hasFlag(args, '--json');
|
|
534
|
-
const result = createOpenSpecContractResult(stage, context.change, context.project, context.component.upstreamVersion);
|
|
535
|
-
const baselineFile = openSpecBaselinePath(context.changeRoot);
|
|
536
|
-
let baseline;
|
|
537
|
-
try {
|
|
538
|
-
baseline = readOpenSpecContractJson(baselineFile, OPENSPEC_CONTRACT_BASELINE_SCHEMA);
|
|
539
|
-
} catch (error) {
|
|
540
|
-
addOpenSpecContractFinding(result, 'error', 'openspec_contract.baseline_invalid', error.message, { nextAction: `buildr openspec baseline create ${context.change} --project ${context.project} --target ${context.targetRoot}` });
|
|
541
|
-
}
|
|
542
|
-
if (!baseline) {
|
|
543
|
-
addOpenSpecContractFinding(result, 'error', 'openspec_contract.baseline_missing', 'OpenSpec change 缺少契约基线。', { nextAction: `buildr openspec baseline create ${context.change} --project ${context.project} --target ${context.targetRoot}` });
|
|
544
|
-
} else if (baseline.change !== context.change || baseline.project !== context.project || baseline.upstreamVersion !== context.component.upstreamVersion) {
|
|
545
|
-
result.baselineState = 'stale';
|
|
546
|
-
addOpenSpecContractFinding(result, 'error', 'openspec_contract.baseline_metadata_mismatch', '契约基线的 change、Project 或 upstream version 与当前事实不一致。', { nextAction: `审阅后运行 buildr openspec baseline create ${context.change} --project ${context.project} --target ${context.targetRoot} --update` });
|
|
547
|
-
} else {
|
|
548
|
-
result.baselineState = 'recorded';
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
if (stage === 'proposal') {
|
|
552
|
-
validateOpenSpecProposalAlignment(context.projectRoot, context.changeRoot, context.delta, baseline, result);
|
|
553
|
-
if (!result.findings.some((finding) => finding.severity === 'error') && baseline) result.baselineState = 'current';
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
if (stage === 'pre-sync') {
|
|
557
|
-
validateOpenSpecProposalAlignment(context.projectRoot, context.changeRoot, context.delta, baseline, result);
|
|
558
|
-
detectOpenSpecActiveConflicts(context.projectRoot, context.change, context.delta, result);
|
|
559
|
-
if (baseline) validateOpenSpecBaselineCurrent(context.projectRoot, baseline, result);
|
|
560
|
-
if (!result.findings.some((finding) => finding.severity === 'error')) {
|
|
561
|
-
const receipt = {
|
|
562
|
-
schemaVersion: OPENSPEC_CONTRACT_RECEIPT_SCHEMA,
|
|
563
|
-
change: context.change,
|
|
564
|
-
project: context.project,
|
|
565
|
-
upstreamVersion: context.component.upstreamVersion,
|
|
566
|
-
deltaHash: context.delta.hash,
|
|
567
|
-
baselineHash: openSpecContractHash(baseline),
|
|
568
|
-
capabilities: snapshotOpenSpecCapabilities(context.projectRoot, context.delta),
|
|
569
|
-
};
|
|
570
|
-
writeOpenSpecContractJson(openSpecReceiptPath(context.changeRoot), receipt);
|
|
571
|
-
result.baselineState = 'current';
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
if (stage === 'post-sync') {
|
|
576
|
-
const receiptFile = openSpecReceiptPath(context.changeRoot);
|
|
577
|
-
let receipt;
|
|
578
|
-
try {
|
|
579
|
-
receipt = readOpenSpecContractJson(receiptFile, OPENSPEC_CONTRACT_RECEIPT_SCHEMA);
|
|
580
|
-
} catch (error) {
|
|
581
|
-
addOpenSpecContractFinding(result, 'error', 'openspec_contract.receipt_invalid', error.message, { nextAction: '重新运行 pre-sync check 后再验证同步结果。' });
|
|
582
|
-
}
|
|
583
|
-
if (!receipt) addOpenSpecContractFinding(result, 'error', 'openspec_contract.receipt_missing', '缺少成功 pre-sync 的 contract receipt。', { nextAction: '重新运行 pre-sync check 后再执行或验证同步。' });
|
|
584
|
-
else if (receipt.change !== context.change || receipt.project !== context.project || receipt.upstreamVersion !== context.component.upstreamVersion) addOpenSpecContractFinding(result, 'error', 'openspec_contract.receipt_metadata_mismatch', 'pre-sync receipt 与当前 change、Project 或 upstream version 不一致。', { nextAction: '重新运行 pre-sync check。' });
|
|
585
|
-
else validateOpenSpecPostSync(context.projectRoot, context.delta, receipt, result);
|
|
586
|
-
if (!result.findings.some((finding) => finding.severity === 'error')) {
|
|
587
|
-
result.baselineState = 'contract-applied';
|
|
588
|
-
receipt.postSyncVerified = true;
|
|
589
|
-
receipt.postSyncDeltaHash = context.delta.hash;
|
|
590
|
-
receipt.postSyncSpecIntegrities = snapshotOpenSpecSpecIntegrities(context.projectRoot, context.delta);
|
|
591
|
-
writeOpenSpecContractJson(receiptFile, receipt);
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
finishOpenSpecContractResult(result);
|
|
596
|
-
if (json) process.stdout.write(`${JSON.stringify(withJsonSchema(PUBLIC_JSON_SCHEMAS.openspecCheck, result), null, 2)}\n`);
|
|
597
|
-
else printOpenSpecContractResult(result);
|
|
598
|
-
process.exitCode = result.ok ? 0 : 1;
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
Object.assign(runtime, { normalizeOpenSpecContractText, openSpecContractHash, openSpecContractChangePath, resolveOpenSpecContractProject, openSpecContractComponent, parseOpenSpecRequirementBlocks, openSpecSection, parseOpenSpecDeltaSpec, parseOpenSpecChangeDelta, readOpenSpecCanonicalRequirements, parseOpenSpecProposalCapabilities, openSpecBaselinePath, openSpecReceiptPath, readOpenSpecContractJson, writeOpenSpecContractJson, baselineTargetsForDelta, expectedOpenSpecBaselineTargets, baselineTargetMap, createOpenSpecContractResult, addOpenSpecContractFinding, finishOpenSpecContractResult, printOpenSpecContractResult, validateOpenSpecProposalAlignment, listActiveOpenSpecChangeRoots, openSpecDeltaIdentities, detectOpenSpecActiveConflicts, validateOpenSpecBaselineCurrent, snapshotOpenSpecCapabilities, snapshotOpenSpecSpecIntegrities, renameRequirementBlock, validateOpenSpecPostSync, openSpecContractContext, openspecBaselineCreate, openspecCheck });
|
|
602
|
-
return runtime;
|
|
603
|
-
}
|