@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,276 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { fetchRemoteText } from '../../shared/fetch-remote-text.mjs';
|
|
5
|
+
import { resolveSkillContributions } from './contributions.mjs';
|
|
6
|
+
import { isSourceLabel, parseSkillsManifest } from './manifests.mjs';
|
|
7
|
+
import { ensureFile, normalizeRelativePath, packageRoot, parseSkillFrontmatterName, parseSkillFrontmatterNameFromContent, productRoot, unquoteYamlScalar } from './primitives.mjs';
|
|
8
|
+
|
|
9
|
+
function readPackageSkillEntries(section, runtime) {
|
|
10
|
+
const manifestPath = path.join(packageRoot(), 'manifest.yml');
|
|
11
|
+
if (!fs.existsSync(manifestPath)) return [];
|
|
12
|
+
|
|
13
|
+
const skills = [];
|
|
14
|
+
let inSection = false;
|
|
15
|
+
let current = null;
|
|
16
|
+
let inRuntimes = false;
|
|
17
|
+
|
|
18
|
+
for (const rawLine of fs.readFileSync(manifestPath, 'utf8').split(/\r?\n/)) {
|
|
19
|
+
const line = rawLine.trimEnd();
|
|
20
|
+
const trimmed = line.trim();
|
|
21
|
+
if (!trimmed || trimmed.startsWith('#')) continue;
|
|
22
|
+
|
|
23
|
+
const topLevel = line.match(/^([A-Za-z][A-Za-z0-9_-]*):\s*$/);
|
|
24
|
+
if (topLevel) {
|
|
25
|
+
if (current) skills.push(current);
|
|
26
|
+
current = null;
|
|
27
|
+
inRuntimes = false;
|
|
28
|
+
inSection = topLevel[1] === section;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (!inSection) continue;
|
|
32
|
+
|
|
33
|
+
const idMatch = trimmed.match(/^-\s+id:\s*(.+)$/);
|
|
34
|
+
if (idMatch) {
|
|
35
|
+
if (current) skills.push(current);
|
|
36
|
+
current = { id: unquoteYamlScalar(idMatch[1]), runtimes: [] };
|
|
37
|
+
inRuntimes = false;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (!current) {
|
|
41
|
+
throw new Error(`Invalid ${section} entry in ${manifestPath}: ${rawLine}`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const pathMatch = trimmed.match(/^path:\s*(.+)$/);
|
|
45
|
+
if (pathMatch) {
|
|
46
|
+
current.path = unquoteYamlScalar(pathMatch[1]);
|
|
47
|
+
inRuntimes = false;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const runtimePathMatch = trimmed.match(/^runtimePath:\s*(.+)$/);
|
|
51
|
+
if (runtimePathMatch && section === 'skillSources') {
|
|
52
|
+
current.runtimePath = unquoteYamlScalar(runtimePathMatch[1]);
|
|
53
|
+
inRuntimes = false;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (trimmed === 'runtimes:') {
|
|
57
|
+
inRuntimes = true;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const runtimeMatch = trimmed.match(/^-\s+(.+)$/);
|
|
61
|
+
if (runtimeMatch && inRuntimes) {
|
|
62
|
+
current.runtimes.push(unquoteYamlScalar(runtimeMatch[1]));
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
throw new Error(`Unsupported ${section} syntax in ${manifestPath}: ${rawLine}`);
|
|
66
|
+
}
|
|
67
|
+
if (current) skills.push(current);
|
|
68
|
+
|
|
69
|
+
return skills
|
|
70
|
+
.filter((skill) => skill.runtimes.includes(runtime))
|
|
71
|
+
.map((skill) => {
|
|
72
|
+
if (!skill.id || !skill.path) {
|
|
73
|
+
throw new Error(`${section} entries must include id and path in ${manifestPath}`);
|
|
74
|
+
}
|
|
75
|
+
const skillPath = normalizeRelativePath(skill.path);
|
|
76
|
+
const sourceFile = path.join(productRoot(), skillPath, 'SKILL.md');
|
|
77
|
+
ensureFile(sourceFile, `Package Skill SKILL.md not found: ${sourceFile}`);
|
|
78
|
+
const result = {
|
|
79
|
+
id: skill.id,
|
|
80
|
+
sourceFile,
|
|
81
|
+
origin: section === 'agentSkills' ? 'product' : 'package',
|
|
82
|
+
runtime,
|
|
83
|
+
displaySource: `${skillPath}/SKILL.md`,
|
|
84
|
+
};
|
|
85
|
+
if (section === 'skillSources') {
|
|
86
|
+
if (skill.runtimePath !== undefined) result.runtimePath = normalizeRelativePath(skill.runtimePath).split(path.sep).join('/');
|
|
87
|
+
result.sourceKind = 'source';
|
|
88
|
+
}
|
|
89
|
+
return result;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function readPackageAgentSkills(runtime) {
|
|
94
|
+
return readPackageSkillEntries('agentSkills', runtime);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function readPackageSkillSources(runtime) {
|
|
98
|
+
return readPackageSkillEntries('skillSources', runtime);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function resolvePackageAgentSkill(runtime, skillId = 'buildr') {
|
|
102
|
+
const skill = readPackageAgentSkills(runtime).find((entry) => entry.id === skillId);
|
|
103
|
+
if (!skill) {
|
|
104
|
+
throw new Error(`Product Agent Skill not found for ${runtime}: ${skillId}`);
|
|
105
|
+
}
|
|
106
|
+
return skill;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function parseSkillSourceRef(sourceRef) {
|
|
110
|
+
const match = sourceRef.match(/^package:([A-Za-z0-9._-]+)$/);
|
|
111
|
+
if (!match) {
|
|
112
|
+
throw new Error(`Unsupported Skill source reference: ${sourceRef}. Supported format: package:<source-id>`);
|
|
113
|
+
}
|
|
114
|
+
return { type: 'package', id: match[1] };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function hashContent(content) {
|
|
118
|
+
return crypto.createHash('sha256').update(content).digest('hex');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function verifyIntegrity(content, integrity, label) {
|
|
122
|
+
if (!integrity) return;
|
|
123
|
+
const match = integrity.match(/^sha256-([A-Fa-f0-9]{64})$/);
|
|
124
|
+
if (!match) {
|
|
125
|
+
throw new Error(`Unsupported integrity format for ${label}: ${integrity}. Use sha256-<hex>.`);
|
|
126
|
+
}
|
|
127
|
+
const actual = hashContent(content);
|
|
128
|
+
if (actual !== match[1].toLowerCase()) {
|
|
129
|
+
throw new Error(`Integrity mismatch for ${label}: expected ${integrity}, actual sha256-${actual}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function resolveSkillUrl(skill, layerOrigin) {
|
|
134
|
+
const content = fetchRemoteText(skill.resolved.url, { label: `workspace Skill ${skill.id}` });
|
|
135
|
+
verifyIntegrity(content, skill.resolved.integrity, skill.id);
|
|
136
|
+
const sourceName = parseSkillFrontmatterNameFromContent(content, skill.resolved.url);
|
|
137
|
+
if (sourceName !== skill.id) {
|
|
138
|
+
throw new Error(`Skill id does not match resolved SKILL.md frontmatter name: ${skill.id} != ${sourceName}`);
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
id: skill.id,
|
|
142
|
+
origin: layerOrigin,
|
|
143
|
+
sourceKind: 'resolved',
|
|
144
|
+
resolved: skill.resolved,
|
|
145
|
+
source: skill.source,
|
|
146
|
+
sourceContent: content,
|
|
147
|
+
displaySource: skill.resolved.url,
|
|
148
|
+
runtimePath: skill.id,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function resolveAgentInstallSkill(skill, layerOrigin, manifestPath) {
|
|
153
|
+
return {
|
|
154
|
+
id: skill.id,
|
|
155
|
+
origin: layerOrigin,
|
|
156
|
+
sourceKind: 'agent-install',
|
|
157
|
+
source: skill.source,
|
|
158
|
+
resolved: skill.resolved,
|
|
159
|
+
installMode: 'agent',
|
|
160
|
+
displaySource: manifestPath,
|
|
161
|
+
runtimePath: skill.id,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function resolveReferencedSkill(skill, packageSourcesById, runtime) {
|
|
166
|
+
const parsed = parseSkillSourceRef(skill.source);
|
|
167
|
+
const packageSource = packageSourcesById.get(parsed.id);
|
|
168
|
+
if (!packageSource) {
|
|
169
|
+
throw new Error(`Package Skill source not found for ${runtime}: ${skill.source}`);
|
|
170
|
+
}
|
|
171
|
+
const sourceName = parseSkillFrontmatterName(packageSource.sourceFile);
|
|
172
|
+
if (sourceName !== skill.id) {
|
|
173
|
+
throw new Error(`Skill id does not match referenced SKILL.md frontmatter name: ${skill.id} != ${sourceName}`);
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
...packageSource,
|
|
177
|
+
id: skill.id,
|
|
178
|
+
sourceRef: skill.source,
|
|
179
|
+
runtimePath: packageSource.runtimePath ?? normalizeRelativePath(skill.runtimePath ?? skill.id).split(path.sep).join('/'),
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function loadLayer(manifestPath, options = {}) {
|
|
184
|
+
const manifestDir = path.dirname(manifestPath);
|
|
185
|
+
const runtime = options.runtime ?? 'claude-code';
|
|
186
|
+
const layerOrigin = options.origin ?? 'workspace';
|
|
187
|
+
const packageSourcesById = options.packageSourcesById ?? new Map();
|
|
188
|
+
const seen = new Set();
|
|
189
|
+
return parseSkillsManifest(manifestPath).map((skill) => {
|
|
190
|
+
if (seen.has(skill.id)) {
|
|
191
|
+
throw new Error(`Duplicate skill id in same manifest: ${skill.id} (${manifestPath})`);
|
|
192
|
+
}
|
|
193
|
+
seen.add(skill.id);
|
|
194
|
+
if (skill.enabled === false || skill.state === 'uninstalled') {
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
if (Array.isArray(skill.runtimes) && !skill.runtimes.includes(runtime)) {
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
if (typeof skill.source === 'string') {
|
|
201
|
+
if (skill.path !== undefined && isSourceLabel(skill.source)) {
|
|
202
|
+
// source is an ownership label; resolve the local path below.
|
|
203
|
+
} else {
|
|
204
|
+
return resolveReferencedSkill(skill, packageSourcesById, runtime);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const hasLocalSourceLabel = skill.path !== undefined && typeof skill.source === 'string' && isSourceLabel(skill.source);
|
|
208
|
+
if (skill.install?.mode === 'agent' || (skill.source !== undefined && skill.resolved === undefined && !hasLocalSourceLabel)) {
|
|
209
|
+
return resolveAgentInstallSkill(skill, layerOrigin, manifestPath);
|
|
210
|
+
}
|
|
211
|
+
if (skill.resolved !== undefined) {
|
|
212
|
+
return resolveSkillUrl(skill, layerOrigin);
|
|
213
|
+
}
|
|
214
|
+
const skillPath = normalizeRelativePath(skill.path);
|
|
215
|
+
const sourceDir = path.join(manifestDir, skillPath);
|
|
216
|
+
const sourceFile = path.join(sourceDir, 'SKILL.md');
|
|
217
|
+
ensureFile(sourceFile, `Skill SKILL.md not found: ${sourceFile}`);
|
|
218
|
+
const sourceName = parseSkillFrontmatterName(sourceFile);
|
|
219
|
+
if (sourceName !== skill.id) {
|
|
220
|
+
throw new Error(`Skill id does not match SKILL.md frontmatter name: ${skill.id} != ${sourceName}`);
|
|
221
|
+
}
|
|
222
|
+
const runtimePath = skill.runtimePath !== undefined ? normalizeRelativePath(skill.runtimePath) : skillPath;
|
|
223
|
+
return {
|
|
224
|
+
id: skill.id,
|
|
225
|
+
sourceFile,
|
|
226
|
+
origin: isSourceLabel(skill.source) ? skill.source : layerOrigin,
|
|
227
|
+
sourceKind: 'path',
|
|
228
|
+
runtimePath: runtimePath.split(path.sep).join('/'),
|
|
229
|
+
};
|
|
230
|
+
}).filter(Boolean);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export function resolveSkills(organizationRoot, projectRoot, options = {}) {
|
|
234
|
+
const runtime = options.runtime ?? 'claude-code';
|
|
235
|
+
const layers = [];
|
|
236
|
+
const organizationManifest = path.join(organizationRoot, 'skills', 'manifest.yml');
|
|
237
|
+
if (options.includeWorkspace !== false && fs.existsSync(organizationManifest)) {
|
|
238
|
+
layers.push(organizationManifest);
|
|
239
|
+
}
|
|
240
|
+
if (projectRoot) {
|
|
241
|
+
const projectManifest = path.join(projectRoot, 'skills', 'manifest.yml');
|
|
242
|
+
if (fs.existsSync(projectManifest)) {
|
|
243
|
+
layers.push(projectManifest);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const productSkillsById = new Map(readPackageAgentSkills(runtime).map((skill) => [skill.id, skill]));
|
|
248
|
+
const packageSourcesById = new Map(readPackageSkillSources(runtime).map((skill) => [skill.id, skill]));
|
|
249
|
+
const resolved = new Map();
|
|
250
|
+
for (const manifestPath of layers) {
|
|
251
|
+
const layerOrigin = projectRoot && manifestPath.startsWith(projectRoot) ? 'project' : 'workspace';
|
|
252
|
+
for (const skill of loadLayer(manifestPath, { runtime, layerOrigin, packageSourcesById })) {
|
|
253
|
+
const productSkill = productSkillsById.get(skill.id);
|
|
254
|
+
if (productSkill) {
|
|
255
|
+
const displaySource = skill.sourceFile ?? skill.displaySource ?? skill.resolved?.url ?? skill.source?.url ?? 'skills/manifest.yml';
|
|
256
|
+
throw new Error(`Skill id conflict: ${skill.id} is provided by product Agent Skill (${productSkill.displaySource}) and workspace/project Skill (${displaySource}). Rename the workspace/project Skill.`);
|
|
257
|
+
}
|
|
258
|
+
resolved.set(skill.id, skill);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
for (const contribution of resolveSkillContributions(organizationRoot)) {
|
|
262
|
+
const target = resolved.get(contribution.skillId);
|
|
263
|
+
if (!target) continue;
|
|
264
|
+
if (contribution.placement === 'slot') {
|
|
265
|
+
const source = target.sourceContent ?? fs.readFileSync(target.sourceFile, 'utf8');
|
|
266
|
+
const marker = `<!-- buildr:skill-contributions ${contribution.slot} -->`;
|
|
267
|
+
const markerCount = source.split(marker).length - 1;
|
|
268
|
+
if (markerCount !== 1) {
|
|
269
|
+
throw new Error(`Skill contribution slot must appear exactly once: ${contribution.skillId}#${contribution.slot} (${contribution.componentId}); found ${markerCount}`);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (!target.skillContributions) target.skillContributions = [];
|
|
273
|
+
target.skillContributions.push(contribution);
|
|
274
|
+
}
|
|
275
|
+
return [...resolved.values()];
|
|
276
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import process from 'node:process';
|
|
3
|
+
|
|
4
|
+
const MAX_TIMEOUT_MS = 120000;
|
|
5
|
+
const DEFAULT_INACTIVITY_TIMEOUT_MS = 10000;
|
|
6
|
+
const DEFAULT_TOTAL_TIMEOUT_MS = 30000;
|
|
7
|
+
|
|
8
|
+
function timeoutValue(env, name, fallback) {
|
|
9
|
+
const raw = env[name];
|
|
10
|
+
if (raw === undefined || raw === '') return fallback;
|
|
11
|
+
const value = Number(raw);
|
|
12
|
+
if (!Number.isInteger(value) || value <= 0 || value > MAX_TIMEOUT_MS) {
|
|
13
|
+
throw new Error(`${name} must be an integer between 1 and ${MAX_TIMEOUT_MS} milliseconds.`);
|
|
14
|
+
}
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function remoteTextTimeouts(env = process.env) {
|
|
19
|
+
return {
|
|
20
|
+
inactivityTimeoutMs: timeoutValue(env, 'BUILDR_REMOTE_SKILL_INACTIVITY_TIMEOUT_MS', DEFAULT_INACTIVITY_TIMEOUT_MS),
|
|
21
|
+
totalTimeoutMs: timeoutValue(env, 'BUILDR_REMOTE_SKILL_TOTAL_TIMEOUT_MS', DEFAULT_TOTAL_TIMEOUT_MS),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function fetchRemoteText(url, options = {}) {
|
|
26
|
+
const parsed = new URL(url);
|
|
27
|
+
if (!['http:', 'https:'].includes(parsed.protocol)) throw new Error(`Remote text URL must use http or https: ${url}`);
|
|
28
|
+
const { inactivityTimeoutMs, totalTimeoutMs } = remoteTextTimeouts(options.env ?? process.env);
|
|
29
|
+
const label = options.label ?? 'remote text';
|
|
30
|
+
const script = `
|
|
31
|
+
const http = require('node:http');
|
|
32
|
+
const https = require('node:https');
|
|
33
|
+
const initialUrl = process.argv[1];
|
|
34
|
+
const inactivityTimeoutMs = Number(process.argv[2]);
|
|
35
|
+
function fail(message) {
|
|
36
|
+
console.error(message);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
function request(nextUrl, redirects = 0) {
|
|
40
|
+
const parsed = new URL(nextUrl);
|
|
41
|
+
if (!['http:', 'https:'].includes(parsed.protocol)) fail('Unsupported redirect protocol: ' + parsed.protocol);
|
|
42
|
+
const client = parsed.protocol === 'https:' ? https : http;
|
|
43
|
+
const req = client.get(parsed, (res) => {
|
|
44
|
+
res.setTimeout(inactivityTimeoutMs, () => res.destroy(new Error('Remote response inactivity timeout after ' + inactivityTimeoutMs + 'ms')));
|
|
45
|
+
if ([301, 302, 303, 307, 308].includes(res.statusCode) && res.headers.location) {
|
|
46
|
+
res.resume();
|
|
47
|
+
if (redirects >= 5) fail('Too many redirects');
|
|
48
|
+
request(new URL(res.headers.location, parsed).toString(), redirects + 1);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (res.statusCode < 200 || res.statusCode >= 300) {
|
|
52
|
+
res.resume();
|
|
53
|
+
fail('HTTP ' + res.statusCode + ' for ' + nextUrl);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
res.setEncoding('utf8');
|
|
57
|
+
res.on('data', (chunk) => process.stdout.write(chunk));
|
|
58
|
+
res.on('error', (error) => fail(error.message));
|
|
59
|
+
});
|
|
60
|
+
req.setTimeout(inactivityTimeoutMs, () => req.destroy(new Error('Remote request inactivity timeout after ' + inactivityTimeoutMs + 'ms')));
|
|
61
|
+
req.on('error', (error) => fail(error.message));
|
|
62
|
+
}
|
|
63
|
+
request(initialUrl);
|
|
64
|
+
`;
|
|
65
|
+
try {
|
|
66
|
+
return execFileSync(process.execPath, ['-e', script, url, String(inactivityTimeoutMs)], {
|
|
67
|
+
encoding: 'utf8',
|
|
68
|
+
maxBuffer: 10 * 1024 * 1024,
|
|
69
|
+
timeout: totalTimeoutMs,
|
|
70
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
71
|
+
});
|
|
72
|
+
} catch (error) {
|
|
73
|
+
const detail = error.killed || error.signal
|
|
74
|
+
? `total timeout after ${totalTimeoutMs}ms`
|
|
75
|
+
: String(error.stderr || error.message || 'unknown error').trim();
|
|
76
|
+
throw new Error(`Failed to fetch ${label} (${url}): ${detail}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
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 { spawnSync } from 'node:child_process';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
import YAML from 'yaml';
|
|
9
|
+
|
|
10
|
+
const productRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../..');
|
|
11
|
+
const buildr = path.join(productRoot, 'tools', 'buildr');
|
|
12
|
+
const fixtureRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'buildr-managed-integrity-'));
|
|
13
|
+
const workspace = path.join(fixtureRoot, 'workspace');
|
|
14
|
+
|
|
15
|
+
function run(args, options = {}) {
|
|
16
|
+
const result = spawnSync(process.execPath, [buildr, ...args], {
|
|
17
|
+
cwd: productRoot,
|
|
18
|
+
encoding: 'utf8',
|
|
19
|
+
env: { ...process.env, ...(options.env || {}) },
|
|
20
|
+
});
|
|
21
|
+
if (options.expectFailure ? result.status === 0 : result.status !== 0) {
|
|
22
|
+
throw new Error(`Unexpected command result (${result.status}): buildr ${args.join(' ')}\n${result.stdout}\n${result.stderr}`);
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function git(args, cwd = fixtureRoot) {
|
|
28
|
+
const result = spawnSync('git', args, { cwd, encoding: 'utf8' });
|
|
29
|
+
if (result.status !== 0) throw new Error(`git ${args.join(' ')} failed: ${result.stderr}`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
run(['init', '--target', workspace, '--name', 'integrity-fixture']);
|
|
34
|
+
|
|
35
|
+
for (const id of ['.', '..']) {
|
|
36
|
+
const before = fs.readFileSync(path.join(workspace, 'projects', 'manifest.yml'), 'utf8');
|
|
37
|
+
run(['project', 'create', id, '--target', workspace], { expectFailure: true });
|
|
38
|
+
if (fs.readFileSync(path.join(workspace, 'projects', 'manifest.yml'), 'utf8') !== before) throw new Error(`Invalid Project id mutated registry: ${id}`);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const ruleFile = path.join(workspace, 'rules', 'fixture.md');
|
|
42
|
+
fs.writeFileSync(ruleFile, '# Fixture\n');
|
|
43
|
+
run(['rules', 'add', 'fixture', '--description', 'fixture rule', '--target', workspace]);
|
|
44
|
+
run(['rules', 'remove', 'fixture', '--target', workspace]);
|
|
45
|
+
if (fs.existsSync(ruleFile)) throw new Error('Normal Rule member deletion was blocked.');
|
|
46
|
+
|
|
47
|
+
const escapedDescription = 'line one\nline "two"';
|
|
48
|
+
run(['commands', 'add', 'fixture-tool', '--purpose', 'fixture', '--description', escapedDescription, '--install-hint', 'https://example.com/tool', '--target', workspace]);
|
|
49
|
+
const commands = YAML.parse(fs.readFileSync(path.join(workspace, 'commands', 'manifest.yml'), 'utf8'));
|
|
50
|
+
if (commands.commands.find((item) => item.id === 'fixture-tool')?.description !== escapedDescription) throw new Error('YAML escaped scalar did not round-trip.');
|
|
51
|
+
|
|
52
|
+
const output = path.join(fixtureRoot, 'package-output');
|
|
53
|
+
run(['package', 'build', '--out', output]);
|
|
54
|
+
run(['package', 'build', '--out', output]);
|
|
55
|
+
if (!fs.existsSync(path.join(output, '.buildr-package-output.json'))) throw new Error('Package output receipt is missing.');
|
|
56
|
+
fs.appendFileSync(path.join(output, 'README.md'), '\nmodified\n');
|
|
57
|
+
run(['package', 'build', '--out', output], { expectFailure: true });
|
|
58
|
+
if (!fs.readFileSync(path.join(output, 'README.md'), 'utf8').includes('modified')) throw new Error('Modified package output was overwritten.');
|
|
59
|
+
const unowned = path.join(fixtureRoot, 'unowned');
|
|
60
|
+
fs.mkdirSync(unowned);
|
|
61
|
+
fs.writeFileSync(path.join(unowned, 'keep.txt'), 'keep');
|
|
62
|
+
run(['package', 'build', '--out', unowned], { expectFailure: true });
|
|
63
|
+
if (fs.readFileSync(path.join(unowned, 'keep.txt'), 'utf8') !== 'keep') throw new Error('Unowned package output was modified.');
|
|
64
|
+
run(['package', 'build', '--out', productRoot], { expectFailure: true });
|
|
65
|
+
|
|
66
|
+
const projectRemoteA = path.join(fixtureRoot, 'project-a.git');
|
|
67
|
+
const projectRemoteB = path.join(fixtureRoot, 'project-b.git');
|
|
68
|
+
git(['init', '--bare', projectRemoteA]);
|
|
69
|
+
git(['init', '--bare', projectRemoteB]);
|
|
70
|
+
run(['project', 'create', 'git-project', '--repo', `file://${projectRemoteA}`, '--target', workspace]);
|
|
71
|
+
run(['project', 'create', 'git-project', '--repo', `file://${projectRemoteA}`, '--target', workspace]);
|
|
72
|
+
const projectRegistryBefore = fs.readFileSync(path.join(workspace, 'projects', 'manifest.yml'), 'utf8');
|
|
73
|
+
run(['project', 'create', 'git-project', '--repo', `file://${projectRemoteB}`, '--target', workspace], { expectFailure: true });
|
|
74
|
+
if (fs.readFileSync(path.join(workspace, 'projects', 'manifest.yml'), 'utf8') !== projectRegistryBefore) throw new Error('Project identity conflict mutated registry.');
|
|
75
|
+
|
|
76
|
+
const serviceRemoteA = path.join(fixtureRoot, 'service-a.git');
|
|
77
|
+
const serviceRemoteB = path.join(fixtureRoot, 'service-b.git');
|
|
78
|
+
git(['init', '--bare', serviceRemoteA]);
|
|
79
|
+
git(['init', '--bare', serviceRemoteB]);
|
|
80
|
+
run(['service', 'create', 'git-project/api', `file://${serviceRemoteA}`, '--target', workspace]);
|
|
81
|
+
run(['service', 'create', 'git-project/api', `file://${serviceRemoteA}`, '--target', workspace]);
|
|
82
|
+
const serviceManifest = path.join(workspace, 'projects', 'git-project', 'services', 'manifest.yml');
|
|
83
|
+
const serviceRegistryBefore = fs.readFileSync(serviceManifest, 'utf8');
|
|
84
|
+
run(['service', 'create', 'git-project/api', `file://${serviceRemoteB}`, '--target', workspace], { expectFailure: true });
|
|
85
|
+
if (fs.readFileSync(serviceManifest, 'utf8') !== serviceRegistryBefore) throw new Error('Service identity conflict mutated metadata.');
|
|
86
|
+
|
|
87
|
+
run(['component', 'uninstall', 'openspec', '--agent', 'codex', '--target', workspace], { expectFailure: true, env: { BUILDR_FAULT_AFTER_MUTATION_WRITE: '1' } });
|
|
88
|
+
run(['component', 'check', 'openspec', '--target', workspace, '--json']);
|
|
89
|
+
if (!fs.existsSync(path.join(workspace, 'components', 'buildr', 'openspec', 'component.yml'))) throw new Error('Component rollback lost installed definition.');
|
|
90
|
+
|
|
91
|
+
const transactionId = 'fixture-transaction';
|
|
92
|
+
const transactionRoot = path.join(workspace, '.buildr', 'mutations', transactionId);
|
|
93
|
+
fs.mkdirSync(path.join(transactionRoot, 'backup'), { recursive: true });
|
|
94
|
+
const journal = { schemaVersion: 'buildr.mutation/v1', transactionId, operation: 'fixture', phase: 'rollback-failed', affectedPaths: [], snapshots: [] };
|
|
95
|
+
fs.writeFileSync(path.join(transactionRoot, 'journal.json'), `${JSON.stringify(journal)}\n`);
|
|
96
|
+
fs.writeFileSync(path.join(workspace, '.buildr', 'mutations', 'lock.json'), `${JSON.stringify(journal)}\n`);
|
|
97
|
+
const doctor = run(['doctor', '--agent', 'codex', '--target', workspace, '--json'], { expectFailure: true });
|
|
98
|
+
const doctorJson = JSON.parse(doctor.stdout);
|
|
99
|
+
if (!doctorJson.findings.some((item) => item.code === 'mutation.transaction_incomplete')) throw new Error('Doctor did not report incomplete transaction.');
|
|
100
|
+
run(['commands', 'remove', 'fixture-tool', '--target', workspace], { expectFailure: true });
|
|
101
|
+
run(['mutation', 'recover', transactionId, '--target', workspace]);
|
|
102
|
+
if (fs.existsSync(path.join(workspace, '.buildr', 'mutations', 'lock.json'))) throw new Error('Mutation recovery did not remove matching lock.');
|
|
103
|
+
|
|
104
|
+
console.log('Managed data integrity verification passed.');
|
|
105
|
+
} finally {
|
|
106
|
+
fs.rmSync(fixtureRoot, { recursive: true, force: true });
|
|
107
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
|
|
7
|
+
const productRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../..');
|
|
8
|
+
const packageManifest = JSON.parse(fs.readFileSync(path.join(productRoot, 'package.json'), 'utf8'));
|
|
9
|
+
const productionFiles = [];
|
|
10
|
+
for (const entry of packageManifest.files.filter((file) => file.startsWith('tools/'))) {
|
|
11
|
+
if (entry.startsWith('tools/verification/')) continue;
|
|
12
|
+
const absolute = path.join(productRoot, entry);
|
|
13
|
+
if (!fs.existsSync(absolute)) continue;
|
|
14
|
+
if (fs.statSync(absolute).isFile()) {
|
|
15
|
+
if (!path.basename(entry).startsWith('verify-')) productionFiles.push(entry);
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
const visit = (dir) => {
|
|
19
|
+
for (const item of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
20
|
+
const child = path.join(dir, item.name);
|
|
21
|
+
if (item.isDirectory()) visit(child);
|
|
22
|
+
else if (!item.name.startsWith('verify-') && item.name.endsWith('.mjs')) {
|
|
23
|
+
productionFiles.push(path.relative(productRoot, child).split(path.sep).join('/'));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
visit(absolute);
|
|
28
|
+
}
|
|
29
|
+
productionFiles.sort();
|
|
30
|
+
const allowed = new Map([
|
|
31
|
+
['tools/cli/shared/infrastructure.mjs', new Set([
|
|
32
|
+
'atomicWriteFile', 'snapshotMutationPath', 'restoreMutationSnapshot', 'withWorkspaceMutation',
|
|
33
|
+
])],
|
|
34
|
+
['tools/cli/domains/workspace.mjs', new Set(['createProject', 'createService'])],
|
|
35
|
+
['tools/cli/domains/rules.mjs', new Set(['rulesRemoveUnsafe'])],
|
|
36
|
+
['tools/cli/domains/skills.mjs', new Set(['copySupportedSkillSource', 'skillsRemoveUnsafe'])],
|
|
37
|
+
['tools/cli/domains/components.mjs', new Set(['removeComponentMember', 'installComponentMember'])],
|
|
38
|
+
['tools/cli/domains/package-assets.mjs', new Set(['convergeServiceManifest', 'convergeRegistryManifests'])],
|
|
39
|
+
['tools/cli/application/package-maintenance.mjs', new Set([
|
|
40
|
+
'syncPackageBuiltins', 'builtinUninstallUnsafe',
|
|
41
|
+
])],
|
|
42
|
+
['tools/cli/application/package-maintenance/output.mjs', new Set(['buildPackageOutput', 'packageBuild'])],
|
|
43
|
+
['tools/cli/application/package-maintenance/smoke-checks.mjs', new Set([
|
|
44
|
+
'verifyRecursiveRules', 'verifyWorkspaceAssetLifecycle', 'verifyInitializedWorkspace',
|
|
45
|
+
'verifyExistingAgentsCompatibility', 'runPackageSmokeChecks',
|
|
46
|
+
])],
|
|
47
|
+
['tools/cli/application/workspace-operations.mjs', new Set(['mutationRecover'])],
|
|
48
|
+
['tools/runtime/adapter-contract.mjs', new Set(['reconcileRuntimePlan'])],
|
|
49
|
+
['tools/runtime/skills/render-plan.mjs', new Set(['applySkillRenderPlan'])],
|
|
50
|
+
['tools/runtime/render-claude-code-rules.mjs', new Set(['applyRulesRenderPlan'])],
|
|
51
|
+
]);
|
|
52
|
+
|
|
53
|
+
const violations = [];
|
|
54
|
+
for (const relativeFile of productionFiles) {
|
|
55
|
+
const lines = fs.readFileSync(path.join(productRoot, relativeFile), 'utf8').split(/\r?\n/);
|
|
56
|
+
let currentFunction = '<top-level>';
|
|
57
|
+
for (const [index, line] of lines.entries()) {
|
|
58
|
+
const declaration = line.match(/^\s*(?:export\s+)?function\s+([A-Za-z0-9_]+)/);
|
|
59
|
+
if (declaration) currentFunction = declaration[1];
|
|
60
|
+
if (!/fs\.(?:rmSync|writeFileSync|appendFileSync|copyFileSync|cpSync|renameSync)\s*\(/.test(line)) continue;
|
|
61
|
+
if (!allowed.get(relativeFile)?.has(currentFunction)) violations.push(`${relativeFile}:${index + 1}: direct mutation in ${currentFunction}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (violations.length) {
|
|
66
|
+
console.error('Managed mutation verification failed:');
|
|
67
|
+
for (const violation of violations) console.error(`- ${violation}`);
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const allowedFunctionCount = [...allowed.values()].reduce((count, functions) => count + functions.size, 0);
|
|
72
|
+
console.log(`Managed mutation verification passed. Reviewed ${productionFiles.length} production files and ${allowedFunctionCount} explicit mutation functions.`);
|