@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.
Files changed (90) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +15 -0
  3. package/docs/cli-architecture.md +62 -0
  4. package/docs/cli-reference.md +67 -0
  5. package/docs/known-limitations.md +13 -0
  6. package/examples/minimal-workspace/README.md +24 -0
  7. package/package/README.md +28 -0
  8. package/package/bootstrap/contract.yml +122 -0
  9. package/package/bootstrap/guide.md +79 -0
  10. package/package/manifest.yml +144 -0
  11. package/package/targets/runtime/skills/buildr/SKILL.md +151 -0
  12. package/package/targets/workspace/.buildr/workspace.yml +5 -0
  13. package/package/targets/workspace/AGENTS.md +5 -0
  14. package/package/targets/workspace/commands/buildr/openspec/manifest.yml +15 -0
  15. package/package/targets/workspace/commands/manifest.yml +2 -0
  16. package/package/targets/workspace/components/buildr/openspec/component.yml +16 -0
  17. package/package/targets/workspace/components/buildr/openspec/contributions/openspec-apply-sidebar.md +3 -0
  18. package/package/targets/workspace/components/buildr/openspec/contributions/openspec-archive-sidebar.md +3 -0
  19. package/package/targets/workspace/components/buildr/openspec/contributions/openspec-explore-sidebar.md +3 -0
  20. package/package/targets/workspace/components/buildr/openspec/contributions/openspec-propose-sidebar.md +3 -0
  21. package/package/targets/workspace/components/buildr/openspec/contributions/openspec-sync-sidebar.md +3 -0
  22. package/package/targets/workspace/components/buildr/openspec/contributions/task-finish-post-sync.md +1 -0
  23. package/package/targets/workspace/components/buildr/openspec/contributions/task-finish-pre-sync.md +1 -0
  24. package/package/targets/workspace/components/buildr/openspec/contributions/task-triage-change-ready.md +10 -0
  25. package/package/targets/workspace/components/manifest.yml +2 -0
  26. package/package/targets/workspace/gitignore +13 -0
  27. package/package/targets/workspace/projects/AGENTS.project.md +25 -0
  28. package/package/targets/workspace/projects/manifest.yml +2 -0
  29. package/package/targets/workspace/projects/services/manifest.yml +3 -0
  30. package/package/targets/workspace/projects/skills/manifest.yml +2 -0
  31. package/package/targets/workspace/rules/buildr/core.md +63 -0
  32. package/package/targets/workspace/rules/manifest.yml +9 -0
  33. package/package/targets/workspace/skills/buildr/git-ops/SKILL.md +73 -0
  34. package/package/targets/workspace/skills/buildr/openspec-contract-guard/SKILL.md +67 -0
  35. package/package/targets/workspace/skills/buildr/task-finish/SKILL.md +104 -0
  36. package/package/targets/workspace/skills/buildr/task-triage/SKILL.md +103 -0
  37. package/package/targets/workspace/skills/buildr/task-worktree/SKILL.md +104 -0
  38. package/package/targets/workspace/skills/manifest.yml +38 -0
  39. package/package/targets/workspace/skills/openspec/openspec-apply-change/SKILL.md +159 -0
  40. package/package/targets/workspace/skills/openspec/openspec-archive-change/SKILL.md +117 -0
  41. package/package/targets/workspace/skills/openspec/openspec-explore/SKILL.md +287 -0
  42. package/package/targets/workspace/skills/openspec/openspec-propose/SKILL.md +111 -0
  43. package/package/targets/workspace/skills/openspec/openspec-sync-specs/SKILL.md +147 -0
  44. package/package.json +67 -0
  45. package/tools/buildr +11 -0
  46. package/tools/cli/application/cli-update.mjs +219 -0
  47. package/tools/cli/application/compose-runtime.mjs +38 -0
  48. package/tools/cli/application/doctor/runtime-diagnostics.mjs +226 -0
  49. package/tools/cli/application/doctor/scope-diagnostics.mjs +440 -0
  50. package/tools/cli/application/doctor/service-diagnostics.mjs +184 -0
  51. package/tools/cli/application/doctor.mjs +201 -0
  52. package/tools/cli/application/package-maintenance/builtin-receipts.mjs +73 -0
  53. package/tools/cli/application/package-maintenance/output.mjs +148 -0
  54. package/tools/cli/application/package-maintenance/smoke-checks.mjs +469 -0
  55. package/tools/cli/application/package-maintenance/static-validation.mjs +678 -0
  56. package/tools/cli/application/package-maintenance.mjs +538 -0
  57. package/tools/cli/application/runtime.mjs +118 -0
  58. package/tools/cli/application/workspace-operations.mjs +310 -0
  59. package/tools/cli/bootstrap.mjs +6 -0
  60. package/tools/cli/command/help.mjs +292 -0
  61. package/tools/cli/command/registry.mjs +97 -0
  62. package/tools/cli/domains/commands.mjs +661 -0
  63. package/tools/cli/domains/components.mjs +922 -0
  64. package/tools/cli/domains/openspec.mjs +603 -0
  65. package/tools/cli/domains/package-assets.mjs +652 -0
  66. package/tools/cli/domains/rules.mjs +380 -0
  67. package/tools/cli/domains/runtime.mjs +94 -0
  68. package/tools/cli/domains/skills.mjs +647 -0
  69. package/tools/cli/domains/workspace.mjs +571 -0
  70. package/tools/cli/shared/infrastructure.mjs +411 -0
  71. package/tools/cli/shared/json-contracts.mjs +22 -0
  72. package/tools/cli/shared/platform.mjs +52 -0
  73. package/tools/runtime/adapter-contract.mjs +330 -0
  74. package/tools/runtime/check-claude-code.mjs +26 -0
  75. package/tools/runtime/check-codex.mjs +26 -0
  76. package/tools/runtime/projection.mjs +163 -0
  77. package/tools/runtime/render-claude-code-rules.mjs +459 -0
  78. package/tools/runtime/render-claude-code.mjs +59 -0
  79. package/tools/runtime/skills/arguments.mjs +51 -0
  80. package/tools/runtime/skills/contributions.mjs +171 -0
  81. package/tools/runtime/skills/manifests.mjs +167 -0
  82. package/tools/runtime/skills/primitives.mjs +86 -0
  83. package/tools/runtime/skills/render-plan.mjs +244 -0
  84. package/tools/runtime/skills/sources.mjs +276 -0
  85. package/tools/shared/fetch-remote-text.mjs +78 -0
  86. package/tools/verification/integrity/managed-data-integrity.mjs +107 -0
  87. package/tools/verification/integrity/managed-mutations.mjs +72 -0
  88. package/tools/verification/openspec/contract.mjs +212 -0
  89. package/tools/verification/runtime/adapter-contract.mjs +102 -0
  90. package/tools/verification/runtime/adapter-parity.mjs +99 -0
@@ -0,0 +1,652 @@
1
+ import { fs, path, PACKAGE_BOOTSTRAP_CONTRACT } from '../shared/platform.mjs';
2
+
3
+ export function registerDomainsPackageAssets(runtime) {
4
+ const readGitRemote = (...args) => runtime.readGitRemote(...args);
5
+ const isPlainObject = (...args) => runtime.isPlainObject(...args);
6
+ const readSkillManifest = (...args) => runtime.readSkillManifest(...args);
7
+ const readSkillManifestSchemaVersion = (...args) => runtime.readSkillManifestSchemaVersion(...args);
8
+ const renderSkillsManifestYaml = (...args) => runtime.renderSkillsManifestYaml(...args);
9
+ const skillsManifestPath = (...args) => runtime.skillsManifestPath(...args);
10
+ const parseYamlValue = (...args) => runtime.parseYamlValue(...args);
11
+ const parseServicesYaml = (...args) => runtime.parseServicesYaml(...args);
12
+ const parseServicesManifestYaml = (...args) => runtime.parseServicesManifestYaml(...args);
13
+ const parseProjectsYaml = (...args) => runtime.parseProjectsYaml(...args);
14
+ const renderProjectsYaml = (...args) => runtime.renderProjectsYaml(...args);
15
+ const renderServicesManifestYaml = (...args) => runtime.renderServicesManifestYaml(...args);
16
+ const writeProjectsRegistry = (...args) => runtime.writeProjectsRegistry(...args);
17
+ const projectsManifestPath = (...args) => runtime.projectsManifestPath(...args);
18
+ const servicesManifestPath = (...args) => runtime.servicesManifestPath(...args);
19
+ const writeServicesManifest = (...args) => runtime.writeServicesManifest(...args);
20
+ const gitDefaultBranch = (...args) => runtime.gitDefaultBranch(...args);
21
+ const defaultAssetDescription = (...args) => runtime.defaultAssetDescription(...args);
22
+ const inferRepoKind = (...args) => runtime.inferRepoKind(...args);
23
+ const ensureGitBoundaries = (...args) => runtime.ensureGitBoundaries(...args);
24
+ const ensureDirectory = (...args) => runtime.ensureDirectory(...args);
25
+ const atomicWriteFile = (...args) => runtime.atomicWriteFile(...args);
26
+ const parseYamlDocument = (...args) => runtime.parseYamlDocument(...args);
27
+ const productRoot = (...args) => runtime.productRoot(...args);
28
+ const packageRoot = (...args) => runtime.packageRoot(...args);
29
+ const packageBootstrapContractPath = (...args) => runtime.packageBootstrapContractPath(...args);
30
+ const writeMappedFileIfMissing = (...args) => runtime.writeMappedFileIfMissing(...args);
31
+ const toPosixRelative = (...args) => runtime.toPosixRelative(...args);
32
+ const existsDirectory = (...args) => runtime.existsDirectory(...args);
33
+ const existsFile = (...args) => runtime.existsFile(...args);
34
+ const writeFileIfChanged = (...args) => runtime.writeFileIfChanged(...args);
35
+
36
+ function readPackageManifest() {
37
+ const manifestPath = path.join(packageRoot(), 'manifest.yml');
38
+ if (!existsFile(manifestPath)) {
39
+ throw new Error(`Package manifest not found: ${manifestPath}`);
40
+ }
41
+
42
+ {
43
+ const parsed = parseYamlDocument(fs.readFileSync(manifestPath, 'utf8'), 'package/manifest.yml');
44
+ return {
45
+ include: [],
46
+ agentSkills: [],
47
+ skillSources: [],
48
+ builtins: { rules: [], skills: [], commands: [] },
49
+ components: [],
50
+ workspaceDirectories: [],
51
+ workspaceFiles: [],
52
+ projectDirectories: [],
53
+ projectFiles: [],
54
+ templateVariables: [],
55
+ forbiddenPatterns: [],
56
+ ...parsed,
57
+ builtins: {
58
+ rules: parsed.builtins?.rules || [],
59
+ skills: parsed.builtins?.skills || [],
60
+ commands: parsed.builtins?.commands || [],
61
+ },
62
+ };
63
+ }
64
+
65
+ const manifest = {
66
+ include: [],
67
+ agentSkills: [],
68
+ skillSources: [],
69
+ builtins: { rules: [], skills: [], commands: [] },
70
+ components: [],
71
+ workspaceDirectories: [],
72
+ workspaceFiles: [],
73
+ projectDirectories: [],
74
+ projectFiles: [],
75
+ templateVariables: [],
76
+ forbiddenPatterns: [],
77
+ };
78
+ let currentList = null;
79
+ let currentPackageSkill = null;
80
+ let currentPackageSkillList = null;
81
+ let inPackageSkillRuntimes = false;
82
+
83
+ function finishPackageSkill() {
84
+ if (!currentPackageSkill) return;
85
+ manifest[currentPackageSkillList].push(currentPackageSkill);
86
+ currentPackageSkill = null;
87
+ currentPackageSkillList = null;
88
+ inPackageSkillRuntimes = false;
89
+ }
90
+
91
+ for (const rawLine of fs.readFileSync(manifestPath, 'utf8').split(/\r?\n/)) {
92
+ const line = rawLine.trimEnd();
93
+ if (!line.trim() || line.trim().startsWith('#')) continue;
94
+
95
+ const keyMatch = line.match(/^([A-Za-z][A-Za-z0-9_-]*):\s*$/);
96
+ if (keyMatch) {
97
+ finishPackageSkill();
98
+ currentList = keyMatch[1] !== 'components' && Object.hasOwn(manifest, keyMatch[1]) && Array.isArray(manifest[keyMatch[1]]) ? keyMatch[1] : null;
99
+ continue;
100
+ }
101
+
102
+ if (currentList === 'agentSkills' || currentList === 'skillSources') {
103
+ const idMatch = line.trim().match(/^-\s+id:\s*(.+)$/);
104
+ if (idMatch) {
105
+ finishPackageSkill();
106
+ currentPackageSkill = { id: parseYamlValue(idMatch[1].trim()), runtimes: [] };
107
+ currentPackageSkillList = currentList;
108
+ continue;
109
+ }
110
+ if (!currentPackageSkill) {
111
+ throw new Error(`Invalid ${currentList} entry in package manifest: ${rawLine}`);
112
+ }
113
+ const pathMatch = line.trim().match(/^path:\s*(.+)$/);
114
+ if (pathMatch) {
115
+ currentPackageSkill.path = parseYamlValue(pathMatch[1].trim());
116
+ inPackageSkillRuntimes = false;
117
+ continue;
118
+ }
119
+ const runtimePathMatch = line.trim().match(/^runtimePath:\s*(.+)$/);
120
+ if (runtimePathMatch && currentList === 'skillSources') {
121
+ currentPackageSkill.runtimePath = parseYamlValue(runtimePathMatch[1].trim());
122
+ inPackageSkillRuntimes = false;
123
+ continue;
124
+ }
125
+ if (line.trim() === 'runtimes:') {
126
+ inPackageSkillRuntimes = true;
127
+ continue;
128
+ }
129
+ const runtimeMatch = line.trim().match(/^-\s+(.+)$/);
130
+ if (runtimeMatch && inPackageSkillRuntimes) {
131
+ currentPackageSkill.runtimes.push(parseYamlValue(runtimeMatch[1].trim()));
132
+ continue;
133
+ }
134
+ throw new Error(`Unsupported ${currentList} syntax in package manifest: ${rawLine}`);
135
+ }
136
+
137
+ const itemMatch = line.match(/^\s*-\s+(.+)$/);
138
+ if (itemMatch && currentList) {
139
+ manifest[currentList].push(parseYamlValue(itemMatch[1].trim()));
140
+ }
141
+ }
142
+ finishPackageSkill();
143
+ manifest.builtins = readPackageBuiltinsManifest(manifestPath);
144
+ manifest.components = readPackageComponentsManifest(manifestPath);
145
+ return manifest;
146
+ }
147
+
148
+ function readPackageComponentsManifest(manifestPath) {
149
+ const components = [];
150
+ let inComponents = false;
151
+ let current = null;
152
+ function finish() {
153
+ if (current) components.push(current);
154
+ current = null;
155
+ }
156
+ for (const rawLine of fs.readFileSync(manifestPath, 'utf8').split(/\r?\n/)) {
157
+ const line = rawLine.trimEnd();
158
+ if (!line.trim() || line.trim().startsWith('#')) continue;
159
+ if (/^[A-Za-z][A-Za-z0-9_-]*:\s*$/.test(line)) {
160
+ finish();
161
+ inComponents = line === 'components:';
162
+ continue;
163
+ }
164
+ if (!inComponents) continue;
165
+ const idMatch = line.match(/^ - id:\s*(.+)$/);
166
+ if (idMatch) {
167
+ finish();
168
+ current = { id: parseYamlValue(idMatch[1].trim()) };
169
+ continue;
170
+ }
171
+ const fieldMatch = line.match(/^ ([A-Za-z][A-Za-z0-9_-]*):\s*(.+)$/);
172
+ if (fieldMatch && current) {
173
+ current[fieldMatch[1]] = parseYamlValue(fieldMatch[2].trim());
174
+ continue;
175
+ }
176
+ }
177
+ finish();
178
+ return components;
179
+ }
180
+
181
+ function readPackageBuiltinsManifest(manifestPath) {
182
+ const builtins = { rules: [], skills: [], commands: [] };
183
+ let inBuiltins = false;
184
+ let currentKind = null;
185
+ let currentEntry = null;
186
+ let currentObject = null;
187
+
188
+ function finishEntry() {
189
+ if (!currentEntry || !currentKind) return;
190
+ builtins[currentKind].push(currentEntry);
191
+ currentEntry = null;
192
+ currentObject = null;
193
+ }
194
+
195
+ for (const rawLine of fs.readFileSync(manifestPath, 'utf8').split(/\r?\n/)) {
196
+ const line = rawLine.trimEnd();
197
+ const trimmed = line.trim();
198
+ if (!trimmed || trimmed.startsWith('#')) continue;
199
+
200
+ if (/^[A-Za-z][A-Za-z0-9_-]*:\s*$/.test(line)) {
201
+ finishEntry();
202
+ inBuiltins = trimmed === 'builtins:';
203
+ currentKind = null;
204
+ continue;
205
+ }
206
+ if (!inBuiltins) continue;
207
+
208
+ const kindMatch = line.match(/^ (rules|skills|commands):\s*(?:\[\s*\])?$/);
209
+ if (kindMatch) {
210
+ finishEntry();
211
+ currentKind = kindMatch[1];
212
+ continue;
213
+ }
214
+
215
+ const idMatch = line.match(/^ - id:\s*(.+)$/);
216
+ if (idMatch && currentKind) {
217
+ finishEntry();
218
+ currentEntry = { id: parseYamlValue(idMatch[1].trim()) };
219
+ continue;
220
+ }
221
+
222
+ const objectStartMatch = line.match(/^ ([A-Za-z][A-Za-z0-9_-]*):\s*$/);
223
+ if (objectStartMatch && currentEntry) {
224
+ currentObject = objectStartMatch[1];
225
+ currentEntry[currentObject] = {};
226
+ continue;
227
+ }
228
+
229
+ const nestedMatch = line.match(/^ ([A-Za-z][A-Za-z0-9_-]*):\s*(.+)$/);
230
+ if (nestedMatch && currentEntry && currentObject) {
231
+ currentEntry[currentObject][nestedMatch[1]] = parseYamlValue(nestedMatch[2].trim());
232
+ continue;
233
+ }
234
+
235
+ const fieldMatch = line.match(/^ ([A-Za-z][A-Za-z0-9_-]*):\s*(.+)$/);
236
+ if (fieldMatch && currentEntry) {
237
+ currentObject = null;
238
+ currentEntry[fieldMatch[1]] = parseYamlValue(fieldMatch[2].trim());
239
+ continue;
240
+ }
241
+ }
242
+ finishEntry();
243
+
244
+ return builtins;
245
+ }
246
+
247
+ function parseManifestFileEntry(entry, section) {
248
+ const match = entry.match(/^(.+?)\s*=>\s*(.+?)(?:\s+(copy|render))?$/);
249
+ if (!match) {
250
+ throw new Error(`Invalid ${section} entry: ${entry}`);
251
+ }
252
+ return {
253
+ source: match[1].trim(),
254
+ target: match[2].trim(),
255
+ mode: match[3] ?? 'copy',
256
+ raw: entry,
257
+ };
258
+ }
259
+
260
+ function collectFiles(entryPath) {
261
+ if (existsFile(entryPath)) return [entryPath];
262
+ if (!existsDirectory(entryPath)) return [];
263
+ const files = [];
264
+ for (const entry of fs.readdirSync(entryPath).sort()) {
265
+ files.push(...collectFiles(path.join(entryPath, entry)));
266
+ }
267
+ return files;
268
+ }
269
+
270
+ function readSimpleYaml(file, listKeys, scalarKeys = []) {
271
+ const result = {
272
+ ...Object.fromEntries(listKeys.map((key) => [key, []])),
273
+ ...Object.fromEntries(scalarKeys.map((key) => [key, null])),
274
+ };
275
+ const allowedKeys = new Set([...listKeys, ...scalarKeys]);
276
+ let currentKey = null;
277
+ for (const rawLine of fs.readFileSync(file, 'utf8').split(/\r?\n/)) {
278
+ const line = rawLine.trimEnd();
279
+ const trimmed = line.trim();
280
+ if (!trimmed || trimmed.startsWith('#')) continue;
281
+
282
+ const scalarMatch = trimmed.match(/^([A-Za-z][A-Za-z0-9_-]*):\s+(.+)$/);
283
+ if (scalarMatch && allowedKeys.has(scalarMatch[1])) {
284
+ currentKey = null;
285
+ result[scalarMatch[1]] = parseYamlValue(scalarMatch[2].trim());
286
+ continue;
287
+ }
288
+
289
+ const keyMatch = trimmed.match(/^([A-Za-z][A-Za-z0-9_-]*):\s*$/);
290
+ if (keyMatch) {
291
+ currentKey = listKeys.includes(keyMatch[1]) ? keyMatch[1] : null;
292
+ continue;
293
+ }
294
+
295
+ const itemMatch = trimmed.match(/^-\s+(.+)$/);
296
+ if (itemMatch && currentKey) {
297
+ result[currentKey].push(parseYamlValue(itemMatch[1].trim()));
298
+ }
299
+ }
300
+ return result;
301
+ }
302
+
303
+ function validateBootstrapContract(root, files, problems) {
304
+ const contractPath = packageBootstrapContractPath();
305
+ if (!existsFile(contractPath)) {
306
+ problems.push(`Bootstrap contract is missing: ${PACKAGE_BOOTSTRAP_CONTRACT}`);
307
+ return;
308
+ }
309
+ files.push(contractPath);
310
+
311
+ const contract = readSimpleYaml(
312
+ contractPath,
313
+ [
314
+ 'bootstrapGuideRequiredText',
315
+ 'bootstrapGuideForbiddenText',
316
+ 'buildrSkillRequiredSections',
317
+ 'buildrSkillRequiredText',
318
+ 'buildrSkillForbiddenText',
319
+ 'globalForbiddenText',
320
+ 'generatedSkillRequiredText',
321
+ ],
322
+ ['bootstrapGuidePath', 'bootstrapGuideMaxLines', 'buildrSkillPath', 'buildrSkillMaxLines'],
323
+ );
324
+
325
+ function readArtifact(artifact, label) {
326
+ if (!artifact) {
327
+ problems.push(`Bootstrap contract must declare ${label}.`);
328
+ return null;
329
+ }
330
+ if (path.isAbsolute(artifact) || artifact.startsWith('..')) {
331
+ problems.push(`Bootstrap contract artifact must stay inside product root: ${artifact}`);
332
+ return null;
333
+ }
334
+
335
+ const artifactPath = path.resolve(root, artifact);
336
+ if (!existsFile(artifactPath)) {
337
+ problems.push(`Bootstrap contract artifact does not exist: ${artifact}`);
338
+ return null;
339
+ }
340
+ files.push(artifactPath);
341
+ return fs.readFileSync(artifactPath, 'utf8');
342
+ }
343
+
344
+ function validateRequiredText(content, artifact, requiredText) {
345
+ if (!content) return;
346
+ for (const required of requiredText) {
347
+ if (!content.includes(required)) {
348
+ problems.push(`Bootstrap contract required text ${JSON.stringify(required)} missing from ${artifact}`);
349
+ }
350
+ }
351
+ }
352
+
353
+ function validateForbiddenText(content, artifact, forbiddenText) {
354
+ if (!content) return;
355
+ for (const forbidden of forbiddenText) {
356
+ if (forbidden && content.includes(forbidden)) {
357
+ problems.push(`Bootstrap contract forbidden text ${JSON.stringify(forbidden)} found in ${artifact}`);
358
+ }
359
+ }
360
+ }
361
+
362
+ function validateMaxLines(content, artifact, maxLines) {
363
+ if (!content || !maxLines) return;
364
+ const lineCount = content.split(/\r?\n/).length;
365
+ if (lineCount > Number(maxLines)) {
366
+ problems.push(`Bootstrap contract max lines exceeded in ${artifact}: ${lineCount} > ${maxLines}`);
367
+ }
368
+ }
369
+
370
+ function validateSections(content, artifact, sections) {
371
+ if (!content) return;
372
+ for (const section of sections) {
373
+ if (!content.includes(`## ${section}`)) {
374
+ problems.push(`Bootstrap contract required section ${JSON.stringify(section)} missing from ${artifact}`);
375
+ }
376
+ }
377
+ }
378
+
379
+ const guideContent = readArtifact(contract.bootstrapGuidePath, 'bootstrapGuidePath');
380
+ const skillContent = readArtifact(contract.buildrSkillPath, 'buildrSkillPath');
381
+
382
+ validateMaxLines(guideContent, contract.bootstrapGuidePath, contract.bootstrapGuideMaxLines);
383
+ validateRequiredText(guideContent, contract.bootstrapGuidePath, contract.bootstrapGuideRequiredText);
384
+ validateForbiddenText(guideContent, contract.bootstrapGuidePath, [
385
+ ...contract.globalForbiddenText,
386
+ ...contract.bootstrapGuideForbiddenText,
387
+ ]);
388
+
389
+ validateMaxLines(skillContent, contract.buildrSkillPath, contract.buildrSkillMaxLines);
390
+ validateSections(skillContent, contract.buildrSkillPath, contract.buildrSkillRequiredSections);
391
+ validateRequiredText(skillContent, contract.buildrSkillPath, contract.buildrSkillRequiredText);
392
+ validateForbiddenText(skillContent, contract.buildrSkillPath, [
393
+ ...contract.globalForbiddenText,
394
+ ...contract.buildrSkillForbiddenText,
395
+ ]);
396
+
397
+ return contract;
398
+ }
399
+
400
+ function builtinRuleEntry(builtin) {
401
+ return {
402
+ id: builtin.id,
403
+ source: 'buildr',
404
+ path: builtin.target,
405
+ description: builtin.description,
406
+ enabled: true,
407
+ required: builtin.required === true,
408
+ state: 'installed',
409
+ };
410
+ }
411
+
412
+ function builtinSkillEntry(builtin) {
413
+ return {
414
+ id: builtin.id,
415
+ source: builtin.target.startsWith('skills/openspec/') ? 'openspec' : 'buildr',
416
+ path: builtin.target.replace(/^skills\//, ''),
417
+ description: builtin.description,
418
+ enabled: true,
419
+ required: builtin.required === true,
420
+ state: 'installed',
421
+ runtimes: builtin.runtimes || ['claude-code', 'codex'],
422
+ runtimePath: builtin.id,
423
+ };
424
+ }
425
+
426
+ function builtinCommandEntry(builtin) {
427
+ return {
428
+ id: builtin.id,
429
+ source: 'buildr',
430
+ enabled: true,
431
+ required: builtin.required === true,
432
+ state: 'installed',
433
+ ...(builtin.manifestEntry || {}),
434
+ };
435
+ }
436
+
437
+ function sourcePathFromBuiltin(builtin) {
438
+ return path.resolve(productRoot(), builtin.path);
439
+ }
440
+
441
+ function targetPathFromBuiltin(targetRoot, builtin) {
442
+ return path.join(targetRoot, builtin.target);
443
+ }
444
+
445
+ function fileDiffStatus(sourceFile, targetFile) {
446
+ if (!existsFile(targetFile)) return 'missing';
447
+ return fs.readFileSync(sourceFile, 'utf8') === fs.readFileSync(targetFile, 'utf8') ? 'installed' : 'modified';
448
+ }
449
+
450
+ function directoryDiffStatus(sourceDir, targetDir) {
451
+ if (!existsDirectory(targetDir)) return 'missing';
452
+ for (const sourceFile of collectFiles(sourceDir)) {
453
+ const relative = path.relative(sourceDir, sourceFile);
454
+ const targetFile = path.join(targetDir, relative);
455
+ if (!existsFile(targetFile) || fs.readFileSync(sourceFile, 'utf8') !== fs.readFileSync(targetFile, 'utf8')) {
456
+ return 'modified';
457
+ }
458
+ }
459
+ return 'installed';
460
+ }
461
+
462
+ function isValidAssetId(value) {
463
+ return typeof value === 'string' && value !== '.' && value !== '..' && !/[\x00-\x1f\x7f]/.test(value) && /^[A-Za-z0-9._-]+$/.test(value);
464
+ }
465
+
466
+ function listManagedDirectories(parent) {
467
+ if (!existsDirectory(parent)) return [];
468
+ return fs.readdirSync(parent)
469
+ .filter((entry) => isValidAssetId(entry) && existsDirectory(path.join(parent, entry)))
470
+ .sort();
471
+ }
472
+
473
+ function normalizeProjectEntry(projectName, entry = {}, projectRoot = null) {
474
+ const rawRepo = isPlainObject(entry.repo) ? entry.repo : {};
475
+ const kind = rawRepo.kind === 'git' || rawRepo.kind === 'local'
476
+ ? (rawRepo.url || (projectRoot && inferRepoKind(projectRoot) === 'git') ? 'git' : 'workspace')
477
+ : ['workspace', 'git'].includes(rawRepo.kind) ? rawRepo.kind : projectRoot ? inferRepoKind(projectRoot) : 'workspace';
478
+ const repo = { kind };
479
+ if (kind === 'git') {
480
+ if (rawRepo.url) repo.url = rawRepo.url;
481
+ if (rawRepo.remote) repo.remote = rawRepo.remote;
482
+ if (rawRepo.defaultBranch) repo.defaultBranch = rawRepo.defaultBranch;
483
+ if (!repo.remote && projectRoot && existsDirectory(path.join(projectRoot, '.git'))) repo.remote = 'origin';
484
+ if (!repo.defaultBranch && projectRoot && existsDirectory(path.join(projectRoot, '.git'))) repo.defaultBranch = gitDefaultBranch(projectRoot);
485
+ }
486
+ return {
487
+ title: typeof entry.title === 'string' && entry.title ? entry.title : projectName,
488
+ description: typeof entry.description === 'string' && entry.description ? entry.description : defaultAssetDescription('Project', projectName),
489
+ path: `projects/${projectName}`,
490
+ repo,
491
+ };
492
+ }
493
+
494
+ function normalizeServiceEntry(serviceName, entry = {}, serviceRoot = null) {
495
+ const rawRepo = isPlainObject(entry.repo) ? entry.repo : {};
496
+ const kind = rawRepo.kind === 'git' || rawRepo.kind === 'local'
497
+ ? (rawRepo.url || (serviceRoot && inferRepoKind(serviceRoot) === 'git') ? 'git' : 'workspace')
498
+ : ['workspace', 'git'].includes(rawRepo.kind) ? rawRepo.kind : serviceRoot ? inferRepoKind(serviceRoot) : 'workspace';
499
+ const repo = { kind };
500
+ if (kind === 'git') {
501
+ if (rawRepo.url) repo.url = rawRepo.url;
502
+ if (rawRepo.remote) repo.remote = rawRepo.remote;
503
+ if (rawRepo.defaultBranch) repo.defaultBranch = rawRepo.defaultBranch;
504
+ if (rawRepo.branch) repo.branch = rawRepo.branch;
505
+ if (!repo.remote && serviceRoot && existsDirectory(path.join(serviceRoot, '.git'))) repo.remote = 'origin';
506
+ if (!repo.defaultBranch && serviceRoot && existsDirectory(path.join(serviceRoot, '.git'))) repo.defaultBranch = gitDefaultBranch(serviceRoot);
507
+ if (!repo.url && serviceRoot && existsDirectory(path.join(serviceRoot, '.git'))) {
508
+ const url = readGitRemote(serviceRoot, repo.remote || 'origin');
509
+ if (url) repo.url = url;
510
+ }
511
+ }
512
+ return {
513
+ title: typeof entry.title === 'string' && entry.title ? entry.title : serviceName,
514
+ description: typeof entry.description === 'string' && entry.description ? entry.description : defaultAssetDescription('Service', serviceName),
515
+ type: typeof entry.type === 'string' && entry.type ? entry.type : 'service',
516
+ path: `services/${serviceName}`,
517
+ repo,
518
+ };
519
+ }
520
+
521
+ function repairProjectBaseline(targetRoot, projectName, changed) {
522
+ const manifest = readPackageManifest();
523
+ const projectRoot = path.join(targetRoot, 'projects', projectName);
524
+ ensureDirectory(projectRoot);
525
+ for (const relativeDir of manifest.projectDirectories) ensureDirectory(path.join(projectRoot, relativeDir));
526
+ const variables = { project: projectName };
527
+ for (const rawEntry of manifest.projectFiles) {
528
+ const entry = parseManifestFileEntry(rawEntry, 'projectFiles');
529
+ if (entry.target === 'services/manifest.yml' && existsFile(path.join(projectRoot, 'services.yml'))) {
530
+ continue;
531
+ }
532
+ const before = changed.length;
533
+ writeMappedFileIfMissing(targetRoot, projectRoot, entry, variables, changed);
534
+ if (changed.length > before) changed[changed.length - 1] = `projects/${projectName}/${entry.target}`;
535
+ }
536
+ const skillsFile = path.join(projectRoot, 'skills', 'manifest.yml');
537
+ if (writeFileIfChanged(skillsFile, existsFile(skillsFile) ? renderSkillsManifestYaml(readSkillManifest(skillsFile)) : renderSkillsManifestYaml([]))) {
538
+ changed.push(toPosixRelative(targetRoot, skillsFile));
539
+ }
540
+ const servicesFile = servicesManifestPath(projectRoot);
541
+ if (!existsFile(servicesFile) && !existsFile(path.join(projectRoot, 'services.yml'))) {
542
+ writeServicesManifest(projectRoot, { schemaVersion: 'buildr.services/v1', project: projectName, services: {} });
543
+ changed.push(toPosixRelative(targetRoot, servicesFile));
544
+ }
545
+ }
546
+
547
+ function convergeSkillsManifestSchema(targetRoot, scopeRoot, changed) {
548
+ const file = skillsManifestPath(scopeRoot);
549
+ if (!existsFile(file)) return;
550
+ const schemaVersion = readSkillManifestSchemaVersion(file);
551
+ if (schemaVersion === 'buildr.skills/v1') return;
552
+ const skills = readSkillManifest(file);
553
+ atomicWriteFile(file, renderSkillsManifestYaml(skills));
554
+ changed.push(toPosixRelative(targetRoot, file));
555
+ }
556
+
557
+ function convergeServiceManifest(targetRoot, projectName, changed) {
558
+ const projectRoot = path.join(targetRoot, 'projects', projectName);
559
+ const servicesRoot = path.join(projectRoot, 'services');
560
+ const manifestFile = servicesManifestPath(projectRoot);
561
+ const legacyFile = path.join(projectRoot, 'services.yml');
562
+ let manifest;
563
+
564
+ ensureDirectory(servicesRoot);
565
+ if (!existsFile(manifestFile) && existsFile(legacyFile)) {
566
+ const legacyServices = parseServicesYaml(fs.readFileSync(legacyFile, 'utf8'));
567
+ manifest = { schemaVersion: 'buildr.services/v1', project: projectName, services: {} };
568
+ for (const [serviceName, service] of Object.entries(legacyServices)) {
569
+ manifest.services[serviceName] = normalizeServiceEntry(serviceName, service, path.join(servicesRoot, serviceName));
570
+ }
571
+ } else if (existsFile(manifestFile)) {
572
+ manifest = parseServicesManifestYaml(fs.readFileSync(manifestFile, 'utf8'));
573
+ } else {
574
+ manifest = { schemaVersion: 'buildr.services/v1', project: projectName, services: {} };
575
+ }
576
+
577
+ for (const serviceName of listManagedDirectories(servicesRoot)) {
578
+ if (!manifest.services[serviceName]) {
579
+ manifest.services[serviceName] = normalizeServiceEntry(serviceName, {}, path.join(servicesRoot, serviceName));
580
+ }
581
+ }
582
+ for (const [serviceName, service] of Object.entries(manifest.services || {})) {
583
+ manifest.services[serviceName] = normalizeServiceEntry(serviceName, service, path.join(servicesRoot, serviceName));
584
+ }
585
+ manifest.schemaVersion = 'buildr.services/v1';
586
+ manifest.project = projectName;
587
+
588
+ const nextContent = renderServicesManifestYaml(manifest);
589
+ if (!existsFile(manifestFile) || fs.readFileSync(manifestFile, 'utf8') !== nextContent) {
590
+ writeServicesManifest(projectRoot, manifest);
591
+ changed.push(toPosixRelative(targetRoot, manifestFile));
592
+ }
593
+ if (existsFile(legacyFile)) {
594
+ fs.rmSync(legacyFile, { force: true });
595
+ changed.push(toPosixRelative(targetRoot, legacyFile));
596
+ }
597
+ convergeSkillsManifestSchema(targetRoot, projectRoot, changed);
598
+ return manifest;
599
+ }
600
+
601
+ function convergeRegistryManifests(targetRoot) {
602
+ const changed = [];
603
+ const legacyProjectsFile = path.join(targetRoot, 'projects.yml');
604
+ if (existsFile(legacyProjectsFile)) {
605
+ fs.rmSync(legacyProjectsFile, { force: true });
606
+ changed.push('projects.yml');
607
+ }
608
+
609
+ ensureDirectory(path.join(targetRoot, 'projects'));
610
+ let registry = existsFile(projectsManifestPath(targetRoot))
611
+ ? parseProjectsYaml(fs.readFileSync(projectsManifestPath(targetRoot), 'utf8'))
612
+ : { schemaVersion: 'buildr.projects/v1', projects: {} };
613
+ registry.projects = isPlainObject(registry.projects) ? registry.projects : {};
614
+
615
+ for (const projectName of listManagedDirectories(path.join(targetRoot, 'projects'))) {
616
+ const projectRoot = path.join(targetRoot, 'projects', projectName);
617
+ if (!registry.projects[projectName]) registry.projects[projectName] = {};
618
+ registry.projects[projectName] = normalizeProjectEntry(projectName, registry.projects[projectName], projectRoot);
619
+ }
620
+
621
+ for (const projectName of listManagedDirectories(path.join(targetRoot, 'projects'))) {
622
+ const projectRoot = path.join(targetRoot, 'projects', projectName);
623
+ repairProjectBaseline(targetRoot, projectName, changed);
624
+ registry.projects[projectName] = normalizeProjectEntry(projectName, registry.projects[projectName], projectRoot);
625
+ convergeServiceManifest(targetRoot, projectName, changed);
626
+ }
627
+ registry.schemaVersion = 'buildr.projects/v1';
628
+ const nextContent = renderProjectsYaml(registry);
629
+ const registryFile = projectsManifestPath(targetRoot);
630
+ if (!existsFile(registryFile) || fs.readFileSync(registryFile, 'utf8') !== nextContent) {
631
+ writeProjectsRegistry(targetRoot, registry);
632
+ changed.push(toPosixRelative(targetRoot, registryFile));
633
+ }
634
+
635
+ convergeSkillsManifestSchema(targetRoot, targetRoot, changed);
636
+
637
+ const boundaryItems = [];
638
+ for (const projectName of Object.keys(registry.projects)) {
639
+ const projectRoot = path.join(targetRoot, 'projects', projectName);
640
+ boundaryItems.push({ type: 'project', project: projectName, assetRoot: projectRoot });
641
+ const servicesRoot = path.join(projectRoot, 'services');
642
+ for (const serviceName of listManagedDirectories(servicesRoot)) {
643
+ boundaryItems.push({ type: 'service', project: projectName, service: serviceName, assetRoot: path.join(servicesRoot, serviceName) });
644
+ }
645
+ }
646
+ changed.push(...ensureGitBoundaries(targetRoot, boundaryItems));
647
+ return [...new Set(changed)];
648
+ }
649
+
650
+ Object.assign(runtime, { readPackageManifest, readPackageComponentsManifest, readPackageBuiltinsManifest, parseManifestFileEntry, collectFiles, readSimpleYaml, validateBootstrapContract, builtinRuleEntry, builtinSkillEntry, builtinCommandEntry, sourcePathFromBuiltin, targetPathFromBuiltin, fileDiffStatus, directoryDiffStatus, isValidAssetId, listManagedDirectories, normalizeProjectEntry, normalizeServiceEntry, repairProjectBaseline, convergeSkillsManifestSchema, convergeServiceManifest, convergeRegistryManifests });
651
+ return runtime;
652
+ }