@buildr-ai/buildr 0.1.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +15 -0
- package/docs/cli-architecture.md +62 -0
- package/docs/cli-reference.md +67 -0
- package/docs/known-limitations.md +13 -0
- package/examples/minimal-workspace/README.md +24 -0
- package/package/README.md +28 -0
- package/package/bootstrap/contract.yml +122 -0
- package/package/bootstrap/guide.md +79 -0
- package/package/manifest.yml +144 -0
- package/package/targets/runtime/skills/buildr/SKILL.md +151 -0
- package/package/targets/workspace/.buildr/workspace.yml +5 -0
- package/package/targets/workspace/AGENTS.md +5 -0
- package/package/targets/workspace/commands/buildr/openspec/manifest.yml +15 -0
- package/package/targets/workspace/commands/manifest.yml +2 -0
- package/package/targets/workspace/components/buildr/openspec/component.yml +16 -0
- package/package/targets/workspace/components/buildr/openspec/contributions/openspec-apply-sidebar.md +3 -0
- package/package/targets/workspace/components/buildr/openspec/contributions/openspec-archive-sidebar.md +3 -0
- package/package/targets/workspace/components/buildr/openspec/contributions/openspec-explore-sidebar.md +3 -0
- package/package/targets/workspace/components/buildr/openspec/contributions/openspec-propose-sidebar.md +3 -0
- package/package/targets/workspace/components/buildr/openspec/contributions/openspec-sync-sidebar.md +3 -0
- package/package/targets/workspace/components/buildr/openspec/contributions/task-finish-post-sync.md +1 -0
- package/package/targets/workspace/components/buildr/openspec/contributions/task-finish-pre-sync.md +1 -0
- package/package/targets/workspace/components/buildr/openspec/contributions/task-triage-change-ready.md +10 -0
- package/package/targets/workspace/components/manifest.yml +2 -0
- package/package/targets/workspace/gitignore +13 -0
- package/package/targets/workspace/projects/AGENTS.project.md +25 -0
- package/package/targets/workspace/projects/manifest.yml +2 -0
- package/package/targets/workspace/projects/services/manifest.yml +3 -0
- package/package/targets/workspace/projects/skills/manifest.yml +2 -0
- package/package/targets/workspace/rules/buildr/core.md +63 -0
- package/package/targets/workspace/rules/manifest.yml +9 -0
- package/package/targets/workspace/skills/buildr/git-ops/SKILL.md +73 -0
- package/package/targets/workspace/skills/buildr/openspec-contract-guard/SKILL.md +67 -0
- package/package/targets/workspace/skills/buildr/task-finish/SKILL.md +104 -0
- package/package/targets/workspace/skills/buildr/task-triage/SKILL.md +103 -0
- package/package/targets/workspace/skills/buildr/task-worktree/SKILL.md +104 -0
- package/package/targets/workspace/skills/manifest.yml +38 -0
- package/package/targets/workspace/skills/openspec/openspec-apply-change/SKILL.md +159 -0
- package/package/targets/workspace/skills/openspec/openspec-archive-change/SKILL.md +117 -0
- package/package/targets/workspace/skills/openspec/openspec-explore/SKILL.md +287 -0
- package/package/targets/workspace/skills/openspec/openspec-propose/SKILL.md +111 -0
- package/package/targets/workspace/skills/openspec/openspec-sync-specs/SKILL.md +147 -0
- package/package.json +67 -0
- package/tools/buildr +11 -0
- package/tools/cli/application/cli-update.mjs +219 -0
- package/tools/cli/application/compose-runtime.mjs +38 -0
- package/tools/cli/application/doctor/runtime-diagnostics.mjs +226 -0
- package/tools/cli/application/doctor/scope-diagnostics.mjs +440 -0
- package/tools/cli/application/doctor/service-diagnostics.mjs +184 -0
- package/tools/cli/application/doctor.mjs +201 -0
- package/tools/cli/application/package-maintenance/builtin-receipts.mjs +73 -0
- package/tools/cli/application/package-maintenance/output.mjs +148 -0
- package/tools/cli/application/package-maintenance/smoke-checks.mjs +469 -0
- package/tools/cli/application/package-maintenance/static-validation.mjs +678 -0
- package/tools/cli/application/package-maintenance.mjs +538 -0
- package/tools/cli/application/runtime.mjs +118 -0
- package/tools/cli/application/workspace-operations.mjs +310 -0
- package/tools/cli/bootstrap.mjs +6 -0
- package/tools/cli/command/help.mjs +292 -0
- package/tools/cli/command/registry.mjs +97 -0
- package/tools/cli/domains/commands.mjs +661 -0
- package/tools/cli/domains/components.mjs +922 -0
- package/tools/cli/domains/openspec.mjs +603 -0
- package/tools/cli/domains/package-assets.mjs +652 -0
- package/tools/cli/domains/rules.mjs +380 -0
- package/tools/cli/domains/runtime.mjs +94 -0
- package/tools/cli/domains/skills.mjs +647 -0
- package/tools/cli/domains/workspace.mjs +571 -0
- package/tools/cli/shared/infrastructure.mjs +411 -0
- package/tools/cli/shared/json-contracts.mjs +22 -0
- package/tools/cli/shared/platform.mjs +52 -0
- package/tools/runtime/adapter-contract.mjs +330 -0
- package/tools/runtime/check-claude-code.mjs +26 -0
- package/tools/runtime/check-codex.mjs +26 -0
- package/tools/runtime/projection.mjs +163 -0
- package/tools/runtime/render-claude-code-rules.mjs +459 -0
- package/tools/runtime/render-claude-code.mjs +59 -0
- package/tools/runtime/skills/arguments.mjs +51 -0
- package/tools/runtime/skills/contributions.mjs +171 -0
- package/tools/runtime/skills/manifests.mjs +167 -0
- package/tools/runtime/skills/primitives.mjs +86 -0
- package/tools/runtime/skills/render-plan.mjs +244 -0
- package/tools/runtime/skills/sources.mjs +276 -0
- package/tools/shared/fetch-remote-text.mjs +78 -0
- package/tools/verification/integrity/managed-data-integrity.mjs +107 -0
- package/tools/verification/integrity/managed-mutations.mjs +72 -0
- package/tools/verification/openspec/contract.mjs +212 -0
- package/tools/verification/runtime/adapter-contract.mjs +102 -0
- package/tools/verification/runtime/adapter-parity.mjs +99 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import process from 'node:process';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
import { spawnSync } from 'node:child_process';
|
|
9
|
+
|
|
10
|
+
const productRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../..');
|
|
11
|
+
const buildr = path.join(productRoot, 'tools', 'buildr');
|
|
12
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'buildr-openspec-contract-'));
|
|
13
|
+
const project = 'demo';
|
|
14
|
+
const projectRoot = path.join(root, 'projects', project);
|
|
15
|
+
const specsRoot = path.join(projectRoot, 'openspec', 'specs');
|
|
16
|
+
const changesRoot = path.join(projectRoot, 'openspec', 'changes');
|
|
17
|
+
|
|
18
|
+
function fail(message) {
|
|
19
|
+
throw new Error(message);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function run(args, expected = 0) {
|
|
23
|
+
const result = spawnSync(process.execPath, [buildr, ...args], { cwd: productRoot, encoding: 'utf8' });
|
|
24
|
+
if (result.status !== expected) {
|
|
25
|
+
fail(`buildr ${args.join(' ')} exited ${result.status}, expected ${expected}: ${(result.stderr || result.stdout).trim()}`);
|
|
26
|
+
}
|
|
27
|
+
const payload = args.includes('--json') && result.stdout.trim() ? JSON.parse(result.stdout) : null;
|
|
28
|
+
if (payload && args[0] === 'openspec') {
|
|
29
|
+
const expectedSchema = args[1] === 'baseline' ? 'buildr.openspec-baseline/v1' : 'buildr.openspec-check/v1';
|
|
30
|
+
if (payload.schemaVersion !== expectedSchema) fail(`Expected ${expectedSchema}, got ${payload.schemaVersion}`);
|
|
31
|
+
}
|
|
32
|
+
return payload;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function write(file, content) {
|
|
36
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
37
|
+
fs.writeFileSync(file, content);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function requirement(title, detail) {
|
|
41
|
+
return [
|
|
42
|
+
`### Requirement: ${title}`,
|
|
43
|
+
`系统 MUST ${detail}。`,
|
|
44
|
+
'',
|
|
45
|
+
`#### Scenario: ${title} works`,
|
|
46
|
+
'- **WHEN** 条件满足',
|
|
47
|
+
'- **THEN** 结果成立',
|
|
48
|
+
'',
|
|
49
|
+
].join('\n');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function canonical(capability, blocks) {
|
|
53
|
+
write(path.join(specsRoot, capability, 'spec.md'), `# ${capability} Specification\n\n## Requirements\n${blocks.join('\n')}`);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function change(id, capability, kind, delta) {
|
|
57
|
+
const isNew = kind === 'new';
|
|
58
|
+
write(path.join(changesRoot, id, '.openspec.yaml'), 'schema: spec-driven\ncreated: 2026-07-11\n');
|
|
59
|
+
write(path.join(changesRoot, id, 'proposal.md'), [
|
|
60
|
+
'## Capabilities',
|
|
61
|
+
'',
|
|
62
|
+
'### New Capabilities',
|
|
63
|
+
...(isNew ? [`- \`${capability}\`: fixture`] : []),
|
|
64
|
+
'',
|
|
65
|
+
'### Modified Capabilities',
|
|
66
|
+
...(!isNew ? [`- \`${capability}\`: fixture`] : []),
|
|
67
|
+
'',
|
|
68
|
+
].join('\n'));
|
|
69
|
+
write(path.join(changesRoot, id, 'specs', capability, 'spec.md'), delta);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function removeChange(id) {
|
|
73
|
+
fs.rmSync(path.join(changesRoot, id), { recursive: true, force: true });
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function baseline(id, options = []) {
|
|
77
|
+
return run(['openspec', 'baseline', 'create', id, '--project', project, '--target', root, '--json', ...options]);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function check(id, stage, expected = 0) {
|
|
81
|
+
return run(['openspec', 'check', id, '--stage', stage, '--project', project, '--target', root, '--json'], expected);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function assertError(result, code) {
|
|
85
|
+
if (!result.findings.some((finding) => finding.code === code)) fail(`Expected finding ${code}: ${JSON.stringify(result.findings)}`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
run(['init', '--target', root, '--name', 'contract-fixture', '--profile', 'team']);
|
|
90
|
+
run(['project', 'create', project, '--target', root]);
|
|
91
|
+
|
|
92
|
+
const existing = requirement('Existing', '保留既有行为');
|
|
93
|
+
const untouched = requirement('Untouched', '保持不变');
|
|
94
|
+
canonical('demo', [existing, untouched]);
|
|
95
|
+
|
|
96
|
+
const unknownProject = spawnSync(process.execPath, [buildr, 'openspec', 'check', 'missing', '--stage', 'proposal', '--project', 'missing', '--target', root, '--json'], { cwd: productRoot, encoding: 'utf8' });
|
|
97
|
+
if (unknownProject.status === 0 || !unknownProject.stderr.includes('Project is not registered')) fail('unknown Project must be rejected before OpenSpec sidecar access');
|
|
98
|
+
|
|
99
|
+
const modified = requirement('Existing', '使用更新后的行为');
|
|
100
|
+
change('safe-modified', 'demo', 'modified', `## MODIFIED Requirements\n\n${modified}`);
|
|
101
|
+
baseline('safe-modified');
|
|
102
|
+
if (!check('safe-modified', 'proposal').ok) fail('safe modified proposal check must pass');
|
|
103
|
+
if (!check('safe-modified', 'pre-sync').ok) fail('safe modified pre-sync check must pass');
|
|
104
|
+
canonical('demo', [modified, untouched]);
|
|
105
|
+
if (!check('safe-modified', 'post-sync').ok) fail('safe modified post-sync check must pass');
|
|
106
|
+
const safeModifiedReceipt = JSON.parse(fs.readFileSync(path.join(changesRoot, 'safe-modified', '.buildr', 'contract-pre-sync-receipt.json'), 'utf8'));
|
|
107
|
+
if (!safeModifiedReceipt.postSyncSpecIntegrities?.demo?.startsWith('sha256-')) fail('post-sync receipt must bind the resulting canonical spec integrity');
|
|
108
|
+
removeChange('safe-modified');
|
|
109
|
+
|
|
110
|
+
const added = requirement('Added', '提供新增能力');
|
|
111
|
+
change('safe-added', 'demo', 'modified', `## ADDED Requirements\n\n${added}`);
|
|
112
|
+
baseline('safe-added');
|
|
113
|
+
check('safe-added', 'pre-sync');
|
|
114
|
+
canonical('demo', [modified, untouched, added]);
|
|
115
|
+
if (!check('safe-added', 'post-sync').ok) fail('safe added post-sync check must pass');
|
|
116
|
+
removeChange('safe-added');
|
|
117
|
+
|
|
118
|
+
change('safe-removed', 'demo', 'modified', `## REMOVED Requirements\n\n${added}`);
|
|
119
|
+
baseline('safe-removed');
|
|
120
|
+
check('safe-removed', 'pre-sync');
|
|
121
|
+
canonical('demo', [modified, untouched]);
|
|
122
|
+
if (!check('safe-removed', 'post-sync').ok) fail('safe removed post-sync check must pass');
|
|
123
|
+
removeChange('safe-removed');
|
|
124
|
+
|
|
125
|
+
const legacy = requirement('Legacy', '保留名称前的内容');
|
|
126
|
+
canonical('demo', [legacy, untouched]);
|
|
127
|
+
change('safe-renamed', 'demo', 'modified', '## RENAMED Requirements\n\n- FROM: `### Requirement: Legacy`\n- TO: `### Requirement: Modern`\n');
|
|
128
|
+
baseline('safe-renamed');
|
|
129
|
+
check('safe-renamed', 'pre-sync');
|
|
130
|
+
canonical('demo', [legacy.replace('### Requirement: Legacy', '### Requirement: Modern'), untouched]);
|
|
131
|
+
if (!check('safe-renamed', 'post-sync').ok) fail('safe renamed post-sync check must pass');
|
|
132
|
+
removeChange('safe-renamed');
|
|
133
|
+
|
|
134
|
+
canonical('demo', [existing, untouched]);
|
|
135
|
+
change('proposal-mismatch', 'demo', 'modified', `## MODIFIED Requirements\n\n${modified}`);
|
|
136
|
+
baseline('proposal-mismatch');
|
|
137
|
+
write(path.join(changesRoot, 'proposal-mismatch', 'proposal.md'), '## Capabilities\n\n### New Capabilities\n\n### Modified Capabilities\n');
|
|
138
|
+
assertError(check('proposal-mismatch', 'proposal', 1), 'openspec_contract.proposal_delta_missing');
|
|
139
|
+
removeChange('proposal-mismatch');
|
|
140
|
+
|
|
141
|
+
change('incomplete-baseline', 'demo', 'modified', `## MODIFIED Requirements\n\n${modified}`);
|
|
142
|
+
baseline('incomplete-baseline');
|
|
143
|
+
fs.appendFileSync(path.join(changesRoot, 'incomplete-baseline', 'specs', 'demo', 'spec.md'), `\n## ADDED Requirements\n\n${requirement('Later', '在基线后新增')}`);
|
|
144
|
+
assertError(check('incomplete-baseline', 'proposal', 1), 'openspec_contract.baseline_incomplete');
|
|
145
|
+
removeChange('incomplete-baseline');
|
|
146
|
+
|
|
147
|
+
change('adopted', 'demo', 'modified', `## MODIFIED Requirements\n\n${modified}`);
|
|
148
|
+
const adopted = baseline('adopted', ['--adopt-current']);
|
|
149
|
+
if (adopted.adopted !== true) fail('explicit adopted baseline must be marked in JSON output');
|
|
150
|
+
removeChange('adopted');
|
|
151
|
+
|
|
152
|
+
change('corrupt-baseline', 'demo', 'modified', `## MODIFIED Requirements\n\n${modified}`);
|
|
153
|
+
baseline('corrupt-baseline');
|
|
154
|
+
fs.writeFileSync(path.join(changesRoot, 'corrupt-baseline', '.buildr', 'contract-baseline.json'), '{ invalid json\n');
|
|
155
|
+
assertError(check('corrupt-baseline', 'proposal', 1), 'openspec_contract.baseline_invalid');
|
|
156
|
+
removeChange('corrupt-baseline');
|
|
157
|
+
|
|
158
|
+
canonical('demo', [existing, untouched]);
|
|
159
|
+
change('conflict-a', 'demo', 'modified', `## MODIFIED Requirements\n\n${modified}`);
|
|
160
|
+
change('conflict-b', 'demo', 'modified', `## MODIFIED Requirements\n\n${modified}`);
|
|
161
|
+
baseline('conflict-a');
|
|
162
|
+
baseline('conflict-b');
|
|
163
|
+
assertError(check('conflict-a', 'pre-sync', 1), 'openspec_contract.active_conflict');
|
|
164
|
+
removeChange('conflict-a');
|
|
165
|
+
removeChange('conflict-b');
|
|
166
|
+
|
|
167
|
+
change('stale', 'demo', 'modified', `## MODIFIED Requirements\n\n${modified}`);
|
|
168
|
+
baseline('stale');
|
|
169
|
+
canonical('demo', [requirement('Existing', '已被前序 change 改变'), untouched]);
|
|
170
|
+
assertError(check('stale', 'pre-sync', 1), 'openspec_contract.baseline_stale');
|
|
171
|
+
removeChange('stale');
|
|
172
|
+
|
|
173
|
+
canonical('demo', [existing, untouched]);
|
|
174
|
+
change('occupied-added', 'demo', 'modified', `## ADDED Requirements\n\n${added}`);
|
|
175
|
+
baseline('occupied-added');
|
|
176
|
+
canonical('demo', [existing, untouched, added]);
|
|
177
|
+
assertError(check('occupied-added', 'pre-sync', 1), 'openspec_contract.baseline_stale');
|
|
178
|
+
removeChange('occupied-added');
|
|
179
|
+
|
|
180
|
+
canonical('demo', [existing, untouched]);
|
|
181
|
+
change('partial', 'demo', 'modified', `## MODIFIED Requirements\n\n${modified}`);
|
|
182
|
+
baseline('partial');
|
|
183
|
+
check('partial', 'pre-sync');
|
|
184
|
+
canonical('demo', [modified, requirement('Untouched', '被错误改写')]);
|
|
185
|
+
assertError(check('partial', 'post-sync', 1), 'openspec_contract.post_sync_untouched_changed');
|
|
186
|
+
removeChange('partial');
|
|
187
|
+
|
|
188
|
+
canonical('demo', [existing, untouched]);
|
|
189
|
+
change('receipt-changed', 'demo', 'modified', `## MODIFIED Requirements\n\n${modified}`);
|
|
190
|
+
baseline('receipt-changed');
|
|
191
|
+
check('receipt-changed', 'pre-sync');
|
|
192
|
+
fs.appendFileSync(path.join(changesRoot, 'receipt-changed', 'specs', 'demo', 'spec.md'), '\n<!-- fixture mutation -->\n');
|
|
193
|
+
assertError(check('receipt-changed', 'post-sync', 1), 'openspec_contract.receipt_delta_changed');
|
|
194
|
+
removeChange('receipt-changed');
|
|
195
|
+
|
|
196
|
+
change('missing-baseline', 'demo', 'modified', `## MODIFIED Requirements\n\n${modified}`);
|
|
197
|
+
assertError(check('missing-baseline', 'proposal', 1), 'openspec_contract.baseline_missing');
|
|
198
|
+
removeChange('missing-baseline');
|
|
199
|
+
|
|
200
|
+
const definition = path.join(root, 'components', 'buildr', 'openspec', 'component.yml');
|
|
201
|
+
const originalDefinition = fs.readFileSync(definition, 'utf8');
|
|
202
|
+
fs.writeFileSync(definition, originalDefinition.replace('version: "1.4.1"', 'version: "9.9.9"'));
|
|
203
|
+
change('unsupported-upstream', 'demo', 'modified', `## MODIFIED Requirements\n\n${modified}`);
|
|
204
|
+
const unsupported = spawnSync(process.execPath, [buildr, 'openspec', 'baseline', 'create', 'unsupported-upstream', '--project', project, '--target', root, '--json'], { cwd: productRoot, encoding: 'utf8' });
|
|
205
|
+
if (unsupported.status === 0 || !unsupported.stderr.includes('does not support upstream version')) fail('unsupported OpenSpec upstream version must fail closed');
|
|
206
|
+
fs.writeFileSync(definition, originalDefinition);
|
|
207
|
+
removeChange('unsupported-upstream');
|
|
208
|
+
|
|
209
|
+
console.log('OpenSpec contract fixtures passed.');
|
|
210
|
+
} finally {
|
|
211
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
212
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import crypto from 'node:crypto';
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import os from 'node:os';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import {
|
|
9
|
+
REQUIRED_RENDER_CAPABILITIES,
|
|
10
|
+
RUNTIME_ADAPTERS,
|
|
11
|
+
SUPPORTED_AGENT_IDS,
|
|
12
|
+
createRuntimeAdapterRegistry,
|
|
13
|
+
createRuntimeContext,
|
|
14
|
+
createRuntimePlan,
|
|
15
|
+
getRuntimeAdapter,
|
|
16
|
+
reconcileRuntimePlan,
|
|
17
|
+
validateRuntimePlan,
|
|
18
|
+
} from '../../runtime/adapter-contract.mjs';
|
|
19
|
+
import { resolveSkillContributions } from '../../runtime/render-claude-code.mjs';
|
|
20
|
+
|
|
21
|
+
assert.deepEqual(SUPPORTED_AGENT_IDS, ['claude-code', 'codex']);
|
|
22
|
+
for (const adapter of Object.values(RUNTIME_ADAPTERS)) {
|
|
23
|
+
assert.deepEqual(Object.keys(adapter.renderCapabilities), REQUIRED_RENDER_CAPABILITIES);
|
|
24
|
+
const root = path.join(os.tmpdir(), `buildr-adapter-${adapter.id}`);
|
|
25
|
+
const context = createRuntimeContext({
|
|
26
|
+
adapterId: adapter.id,
|
|
27
|
+
targetRoot: root,
|
|
28
|
+
scope: '.',
|
|
29
|
+
rules: { writes: [], nativeAssets: [path.join(root, 'AGENTS.md')], removals: [], actions: [] },
|
|
30
|
+
skills: { writes: [], removals: [] },
|
|
31
|
+
});
|
|
32
|
+
validateRuntimePlan(adapter.planRuntime(context), adapter);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
assert.throws(() => getRuntimeAdapter('fake-runtime'), /Unsupported Agent runtime/);
|
|
36
|
+
assert.throws(() => createRuntimeAdapterRegistry([{ id: 'fake-runtime', runtimeTargets: [], renderCapabilities: {}, recommendedCommands: {} }], { testOnly: true }), /Invalid runtime adapter registry/);
|
|
37
|
+
|
|
38
|
+
const fakeCapabilities = Object.fromEntries(REQUIRED_RENDER_CAPABILITIES.map((capability) => [capability, { supported: true }]));
|
|
39
|
+
const fakeRegistry = createRuntimeAdapterRegistry([{
|
|
40
|
+
id: 'fake-runtime',
|
|
41
|
+
displayName: 'Fake Runtime',
|
|
42
|
+
runtimeTargets: ['.fake/'],
|
|
43
|
+
implementation: { skills: 'fake', rules: 'fake', checker: 'fake' },
|
|
44
|
+
renderCapabilities: fakeCapabilities,
|
|
45
|
+
recommendedCommands: {},
|
|
46
|
+
planRuntime(context) { return { ...context, schemaVersion: 'buildr.runtime-plan/v1', writes: [], nativeAssets: [], removals: [], capabilityEvidence: REQUIRED_RENDER_CAPABILITIES.map((capability) => ({ capability, supported: true })), findings: [], repairs: [], warnings: [], ruleActions: [] }; },
|
|
47
|
+
}], { testOnly: true });
|
|
48
|
+
assert.equal(fakeRegistry['fake-runtime'].id, 'fake-runtime');
|
|
49
|
+
assert.equal(RUNTIME_ADAPTERS['fake-runtime'], undefined);
|
|
50
|
+
|
|
51
|
+
const codex = RUNTIME_ADAPTERS.codex;
|
|
52
|
+
const root = path.join(os.tmpdir(), 'buildr-invalid-plan');
|
|
53
|
+
const context = createRuntimeContext({ adapterId: 'codex', targetRoot: root, scope: '.', rules: { writes: [], nativeAssets: [], removals: [], actions: [] }, skills: { writes: [], removals: [] } });
|
|
54
|
+
const valid = codex.planRuntime(context);
|
|
55
|
+
assert.throws(() => validateRuntimePlan({ ...valid, writes: [{ targetFile: path.join(root, '..', 'escape'), content: 'bad' }] }, codex), /outside target root/);
|
|
56
|
+
assert.throws(() => validateRuntimePlan({ ...valid, capabilityEvidence: [] }, codex), /missing capability evidence/);
|
|
57
|
+
|
|
58
|
+
const symlinkPlanRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'buildr-runtime-plan-symlink-'));
|
|
59
|
+
const symlinkPlanOutside = fs.mkdtempSync(path.join(os.tmpdir(), 'buildr-runtime-plan-outside-'));
|
|
60
|
+
fs.mkdirSync(path.join(symlinkPlanRoot, '.agents'), { recursive: true });
|
|
61
|
+
fs.symlinkSync(symlinkPlanOutside, path.join(symlinkPlanRoot, '.agents', 'skills'), 'dir');
|
|
62
|
+
const symlinkPlanTarget = path.join(symlinkPlanRoot, '.agents', 'skills', 'demo', 'SKILL.md');
|
|
63
|
+
assert.throws(() => validateRuntimePlan({ ...valid, targetRoot: symlinkPlanRoot, writes: [{ targetFile: symlinkPlanTarget, content: 'bad' }] }, codex), /crosses a symbolic link/);
|
|
64
|
+
assert.throws(() => validateRuntimePlan({ ...valid, targetRoot: symlinkPlanRoot, removals: [{ targetFile: symlinkPlanTarget }] }, codex), /crosses a symbolic link/);
|
|
65
|
+
|
|
66
|
+
const reconcileRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'buildr-runtime-reconcile-'));
|
|
67
|
+
const targetFile = path.join(reconcileRoot, '.agents', 'skills', 'demo', 'SKILL.md');
|
|
68
|
+
const orphanFile = path.join(reconcileRoot, '.agents', 'buildr', 'skill-install-plans', 'orphan.md');
|
|
69
|
+
fs.mkdirSync(path.dirname(orphanFile), { recursive: true });
|
|
70
|
+
fs.writeFileSync(orphanFile, '<!-- Generated by Buildr. Agent action required. -->\n');
|
|
71
|
+
const evidence = REQUIRED_RENDER_CAPABILITIES.map((capability) => ({ capability, supported: true }));
|
|
72
|
+
const reconcilePlan = createRuntimePlan({ adapterId: 'codex', targetRoot: reconcileRoot, scope: '.', writes: [{ targetFile, content: 'managed\n', source: 'test', isManaged: (content) => content === 'managed\n' }], nativeAssets: [], removals: [{ targetFile: orphanFile, isManaged: (content) => content.includes('Generated by Buildr') }], capabilityEvidence: evidence });
|
|
73
|
+
assert.equal(reconcileRuntimePlan(reconcilePlan).changed.length, 1);
|
|
74
|
+
assert.equal(fs.existsSync(orphanFile), false);
|
|
75
|
+
assert.equal(reconcileRuntimePlan(reconcilePlan).changed.length, 0);
|
|
76
|
+
fs.writeFileSync(targetFile, 'raw source\n');
|
|
77
|
+
const adoptionPlan = createRuntimePlan({ adapterId: 'codex', targetRoot: reconcileRoot, scope: '.', writes: [{ targetFile, content: 'managed adoption\n', sourceContent: 'raw source\n', source: 'test', isManaged: () => false }], nativeAssets: [], removals: [], capabilityEvidence: evidence });
|
|
78
|
+
assert.equal(reconcileRuntimePlan(adoptionPlan).changed.length, 1);
|
|
79
|
+
fs.writeFileSync(targetFile, 'user content\n');
|
|
80
|
+
assert.throws(() => reconcileRuntimePlan(reconcilePlan), /no files were changed/);
|
|
81
|
+
assert.equal(fs.readFileSync(targetFile, 'utf8'), 'user content\n');
|
|
82
|
+
|
|
83
|
+
const componentRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'buildr-runtime-component-'));
|
|
84
|
+
const componentDir = path.join(componentRoot, 'components', 'workspace', 'demo');
|
|
85
|
+
const fragmentRelative = 'components/workspace/demo/contributions/demo.md';
|
|
86
|
+
const ruleRelative = 'rules/demo.md';
|
|
87
|
+
fs.mkdirSync(path.join(componentRoot, 'components'), { recursive: true });
|
|
88
|
+
fs.mkdirSync(path.dirname(path.join(componentRoot, fragmentRelative)), { recursive: true });
|
|
89
|
+
fs.mkdirSync(path.join(componentRoot, 'rules'), { recursive: true });
|
|
90
|
+
fs.writeFileSync(path.join(componentRoot, 'components', 'manifest.yml'), 'schemaVersion: buildr.components/v1\ncomponents:\n - id: demo\n path: components/workspace/demo\n enabled: true\n state: installed\n');
|
|
91
|
+
fs.writeFileSync(path.join(componentRoot, fragmentRelative), 'Contribution\n');
|
|
92
|
+
fs.writeFileSync(path.join(componentRoot, ruleRelative), 'Rule\n');
|
|
93
|
+
const integrity = (relative) => `sha256-${crypto.createHash('sha256').update(fs.readFileSync(path.join(componentRoot, relative))).digest('hex')}`;
|
|
94
|
+
const definition = (extra = '') => `schemaVersion: buildr.component/v1\nid: demo\nkind: addon\nversion: 1.0.0\nsource: workspace\n${extra}members:\n rules: [${JSON.stringify(ruleRelative)}]\n skills: []\n commandCollections: []\n skillContributions: [${JSON.stringify(fragmentRelative)}]\ncontributions:\n skillFragments: [${JSON.stringify(`buildr#slot=${fragmentRelative}`)}]\nintegrity: [${JSON.stringify(`${ruleRelative}=${integrity(ruleRelative)}`)}, ${JSON.stringify(`${fragmentRelative}=${integrity(fragmentRelative)}`)}]\n`;
|
|
95
|
+
fs.writeFileSync(path.join(componentDir, 'component.yml'), definition('adapter: ./adapter.mjs\n'));
|
|
96
|
+
assert.throws(() => resolveSkillContributions(componentRoot), /cannot extend runtime adapters/);
|
|
97
|
+
fs.writeFileSync(path.join(componentDir, 'component.yml'), definition());
|
|
98
|
+
assert.equal(resolveSkillContributions(componentRoot).length, 1);
|
|
99
|
+
fs.writeFileSync(path.join(componentRoot, ruleRelative), 'modified\n');
|
|
100
|
+
assert.throws(() => resolveSkillContributions(componentRoot), /Component member integrity mismatch/);
|
|
101
|
+
|
|
102
|
+
console.log('runtime adapter contract verification passed');
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import crypto from 'node:crypto';
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import os from 'node:os';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { execFileSync, spawnSync } from 'node:child_process';
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
|
|
11
|
+
const productRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../..');
|
|
12
|
+
const buildr = path.join(productRoot, 'tools', 'buildr');
|
|
13
|
+
const workspace = fs.mkdtempSync(path.join(os.tmpdir(), 'buildr-runtime-parity-'));
|
|
14
|
+
|
|
15
|
+
function run(args, options = {}) {
|
|
16
|
+
const result = spawnSync(process.execPath, [buildr, ...args], { cwd: productRoot, encoding: 'utf8' });
|
|
17
|
+
if (!options.allowFailure && result.status !== 0) throw new Error(`${args.join(' ')} failed:\n${result.stdout}\n${result.stderr}`);
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function digestRuntime() {
|
|
22
|
+
const hash = crypto.createHash('sha256');
|
|
23
|
+
const visit = (directory) => {
|
|
24
|
+
if (!fs.existsSync(directory)) return;
|
|
25
|
+
for (const entry of fs.readdirSync(directory, { withFileTypes: true }).sort((left, right) => left.name.localeCompare(right.name))) {
|
|
26
|
+
const item = path.join(directory, entry.name);
|
|
27
|
+
if (entry.isDirectory()) visit(item);
|
|
28
|
+
else if (entry.isFile()) {
|
|
29
|
+
hash.update(path.relative(workspace, item));
|
|
30
|
+
hash.update('\0');
|
|
31
|
+
hash.update(fs.readFileSync(item));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
visit(path.join(workspace, '.agents'));
|
|
36
|
+
visit(path.join(workspace, '.claude'));
|
|
37
|
+
for (const file of ['CLAUDE.md', 'AGENTS.md']) if (fs.existsSync(path.join(workspace, file))) hash.update(fs.readFileSync(path.join(workspace, file)));
|
|
38
|
+
return hash.digest('hex');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
run(['init', '--target', workspace, '--name', 'runtime-parity']);
|
|
42
|
+
|
|
43
|
+
const symlinkWorkspace = fs.mkdtempSync(path.join(os.tmpdir(), 'buildr-runtime-symlink-'));
|
|
44
|
+
const symlinkOutside = fs.mkdtempSync(path.join(os.tmpdir(), 'buildr-runtime-outside-'));
|
|
45
|
+
run(['init', '--target', symlinkWorkspace, '--name', 'runtime-symlink']);
|
|
46
|
+
fs.mkdirSync(path.join(symlinkWorkspace, '.agents'), { recursive: true });
|
|
47
|
+
fs.symlinkSync(symlinkOutside, path.join(symlinkWorkspace, '.agents', 'skills'), 'dir');
|
|
48
|
+
const symlinkInstall = run(['skill', 'install', 'codex', '--target', symlinkWorkspace], { allowFailure: true });
|
|
49
|
+
assert.notEqual(symlinkInstall.status, 0, 'runtime install must reject a target path that crosses a symbolic link');
|
|
50
|
+
assert.equal(fs.existsSync(path.join(symlinkOutside, 'buildr', 'SKILL.md')), false, 'runtime install must not write outside the workspace through a symbolic link');
|
|
51
|
+
|
|
52
|
+
run(['project', 'create', 'scope-alpha', '--target', workspace, '--description', 'scope alpha']);
|
|
53
|
+
run(['project', 'create', 'scope-beta', '--target', workspace, '--description', 'scope beta']);
|
|
54
|
+
run(['skills', 'add', 'beta-remote', '--remote-source', 'https://example.com/beta-remote', '--scope', 'projects/scope-beta', '--target', workspace, '--description', 'beta remote']);
|
|
55
|
+
run(['skills', 'render', 'codex', '--scope', '.', '--target', workspace]);
|
|
56
|
+
const betaPlan = path.join(workspace, '.agents', 'buildr', 'skill-install-plans', 'beta-remote.md');
|
|
57
|
+
assert.ok(fs.existsSync(betaPlan));
|
|
58
|
+
const betaManifest = path.join(workspace, 'projects', 'scope-beta', 'skills', 'manifest.yml');
|
|
59
|
+
const betaManifestContent = fs.readFileSync(betaManifest, 'utf8');
|
|
60
|
+
fs.writeFileSync(betaManifest, 'schemaVersion: [invalid\n', 'utf8');
|
|
61
|
+
const scopedRender = run(['skills', 'render', 'codex', '--scope', 'projects/scope-alpha', '--target', workspace], { allowFailure: true });
|
|
62
|
+
assert.equal(scopedRender.status, 0, 'Project-scoped render must not fail because an unrelated Project manifest is invalid');
|
|
63
|
+
assert.ok(fs.existsSync(betaPlan), 'Project-scoped render must not remove an unrelated Project install plan');
|
|
64
|
+
fs.writeFileSync(betaManifest, betaManifestContent, 'utf8');
|
|
65
|
+
|
|
66
|
+
for (const agent of ['codex', 'claude-code']) {
|
|
67
|
+
run(['skill', 'install', agent, '--target', workspace]);
|
|
68
|
+
run(['render', agent, '--scope', '.', '--target', workspace]);
|
|
69
|
+
const check = run(['runtime', 'check', agent, '--scope', '.', '--target', workspace]);
|
|
70
|
+
assert.equal(check.status, 0, `${agent} runtime check should pass after render`);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
assert.ok(fs.existsSync(path.join(workspace, '.agents', 'skills', 'buildr', 'SKILL.md')));
|
|
74
|
+
assert.ok(fs.existsSync(path.join(workspace, '.claude', 'skills', 'buildr', 'SKILL.md')));
|
|
75
|
+
assert.ok(fs.readFileSync(path.join(workspace, 'CLAUDE.md'), 'utf8').includes('@AGENTS.md'));
|
|
76
|
+
assert.ok(!fs.existsSync(path.join(workspace, '.agents', 'CLAUDE.md')));
|
|
77
|
+
|
|
78
|
+
const codexBuildr = fs.readFileSync(path.join(workspace, '.agents', 'skills', 'task-finish', 'SKILL.md'), 'utf8');
|
|
79
|
+
const claudeBuildr = fs.readFileSync(path.join(workspace, '.claude', 'skills', 'task-finish', 'SKILL.md'), 'utf8');
|
|
80
|
+
assert.ok(codexBuildr.includes('buildr:contribution openspec#pre-spec-sync'));
|
|
81
|
+
assert.ok(claudeBuildr.includes('buildr:contribution openspec#pre-spec-sync'));
|
|
82
|
+
|
|
83
|
+
const orphan = path.join(workspace, '.agents', 'skills', 'runtime-orphan', 'SKILL.md');
|
|
84
|
+
fs.mkdirSync(path.dirname(orphan), { recursive: true });
|
|
85
|
+
fs.writeFileSync(orphan, '---\nname: runtime-orphan\n---\n<!-- Generated by Buildr. Hash: deadbeef. Do not edit. -->\n');
|
|
86
|
+
run(['render', 'codex', '--scope', '.', '--target', workspace]);
|
|
87
|
+
assert.equal(fs.existsSync(path.dirname(orphan)), false);
|
|
88
|
+
|
|
89
|
+
const before = digestRuntime();
|
|
90
|
+
for (const agent of ['codex', 'claude-code']) run(['render', agent, '--scope', '.', '--target', workspace]);
|
|
91
|
+
assert.equal(digestRuntime(), before, 'repeated render must be idempotent');
|
|
92
|
+
|
|
93
|
+
const doctor = JSON.parse(execFileSync(process.execPath, [buildr, 'doctor', '--agent', 'codex', '--target', workspace, '--json'], { cwd: productRoot, encoding: 'utf8' }));
|
|
94
|
+
assert.equal(doctor.agentRuntime.requested, 'codex');
|
|
95
|
+
assert.equal(doctor.agentRuntime.supported, true);
|
|
96
|
+
assert.equal(doctor.runtime.claudeCode.length, 0);
|
|
97
|
+
assert.ok(doctor.runtime.codex.length > 0);
|
|
98
|
+
|
|
99
|
+
console.log('runtime adapter parity verification passed');
|