@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,678 @@
1
+ export function createPackageStaticValidator(deps) {
2
+ const {
3
+ LEGACY_PACKAGE_PATHS,
4
+ PACKAGE_RUNTIME_TARGET,
5
+ PACKAGE_WORKSPACE_TARGET,
6
+ collectFiles,
7
+ componentMemberPaths,
8
+ existsDirectory,
9
+ existsFile,
10
+ fs,
11
+ isManifestSourceLabel,
12
+ isPlainObject,
13
+ normalizeRelativePathForBuildr,
14
+ packageComponentDefinition,
15
+ packageComponentSourcePath,
16
+ packageWorkspaceTargetRoot,
17
+ parseCommandsManifestYaml,
18
+ parseManifestFileEntry,
19
+ parseProjectsYaml,
20
+ parseSkillFrontmatter,
21
+ parseSkillSourceRef,
22
+ path,
23
+ readPackageManifest,
24
+ readSkillManifest,
25
+ toPosixRelative,
26
+ validateBootstrapContract,
27
+ validateCommandsManifest,
28
+ validatePackageComponentMembers,
29
+ validateProjectsRegistry,
30
+ validateSkillManifestEntries,
31
+ } = deps;
32
+
33
+ function validateWorkspaceSkillsBaseline(root, problems) {
34
+ const workspaceSkillsRoot = path.join(root, 'skills');
35
+ const workspaceManifest = path.join(workspaceSkillsRoot, 'manifest.yml');
36
+ const baselineSkillsRoot = path.join(packageWorkspaceTargetRoot(), 'skills');
37
+ const baselineManifest = path.join(baselineSkillsRoot, 'manifest.yml');
38
+ const packageSkillSourceIds = new Set(readPackageManifest().skillSources.map((source) => source.id));
39
+
40
+ if (!existsFile(workspaceManifest) || !existsFile(baselineManifest)) return;
41
+
42
+ const workspaceSkills = new Map(readSkillManifest(workspaceManifest).map((skill) => [skill.id, skill]));
43
+ for (const baselineSkill of readSkillManifest(baselineManifest)) {
44
+ if (!baselineSkill.id || (baselineSkill.path === undefined && baselineSkill.source === undefined && baselineSkill.resolved === undefined)) {
45
+ problems.push('Workspace skills baseline manifest entries must include id and path, source, or resolved.');
46
+ continue;
47
+ }
48
+
49
+ const workspaceSkill = workspaceSkills.get(baselineSkill.id);
50
+ if (!workspaceSkill) {
51
+ problems.push(`Workspace skills baseline ${baselineSkill.id} is missing from root skills/manifest.yml.`);
52
+ continue;
53
+ }
54
+ if (baselineSkill.path !== undefined && workspaceSkill.path !== baselineSkill.path) {
55
+ problems.push(`Workspace skills baseline ${baselineSkill.id} path differs from root skills manifest: ${baselineSkill.path} != ${workspaceSkill.path}`);
56
+ continue;
57
+ }
58
+ if (baselineSkill.source !== undefined && JSON.stringify(workspaceSkill.source) !== JSON.stringify(baselineSkill.source)) {
59
+ problems.push(`Workspace skills baseline ${baselineSkill.id} source differs from root skills manifest.`);
60
+ continue;
61
+ }
62
+ if (baselineSkill.resolved !== undefined && JSON.stringify(workspaceSkill.resolved) !== JSON.stringify(baselineSkill.resolved)) {
63
+ problems.push(`Workspace skills baseline ${baselineSkill.id} resolved differs from root skills manifest.`);
64
+ continue;
65
+ }
66
+
67
+ if ((baselineSkill.source !== undefined && !(baselineSkill.path !== undefined && isManifestSourceLabel(baselineSkill.source))) || baselineSkill.resolved !== undefined) {
68
+ try {
69
+ if (typeof baselineSkill.source === 'string' && !isManifestSourceLabel(baselineSkill.source)) {
70
+ const parsed = parseSkillSourceRef(baselineSkill.source);
71
+ if (parsed.type === 'package' && !packageSkillSourceIds.has(parsed.id)) {
72
+ problems.push(`Workspace skills baseline ${baselineSkill.id} references unknown package Skill source: ${baselineSkill.source}`);
73
+ }
74
+ }
75
+ } catch (error) {
76
+ problems.push(error.message);
77
+ }
78
+ continue;
79
+ }
80
+
81
+ const baselineSkillFile = path.join(baselineSkillsRoot, baselineSkill.path, 'SKILL.md');
82
+ const workspaceSkillFile = path.join(workspaceSkillsRoot, workspaceSkill.path, 'SKILL.md');
83
+ if (!existsFile(baselineSkillFile)) {
84
+ problems.push(`Workspace skills baseline SKILL.md does not exist: ${PACKAGE_WORKSPACE_TARGET}/skills/${baselineSkill.path}/SKILL.md`);
85
+ continue;
86
+ }
87
+ if (!existsFile(workspaceSkillFile)) {
88
+ problems.push(`Root workspace skill SKILL.md does not exist: skills/${workspaceSkill.path}/SKILL.md`);
89
+ continue;
90
+ }
91
+
92
+ const baselineContent = fs.readFileSync(baselineSkillFile, 'utf8');
93
+ const workspaceContent = fs.readFileSync(workspaceSkillFile, 'utf8');
94
+ if (baselineContent !== workspaceContent) {
95
+ problems.push(`Workspace skills baseline ${baselineSkill.id} differs from root skills/${workspaceSkill.path}/SKILL.md.`);
96
+ }
97
+ }
98
+ }
99
+
100
+ function validateWorkspaceRulesBaseline(root, problems) {
101
+ const baselinePairs = [
102
+ ['AGENTS.md', 'AGENTS.md'],
103
+ ['rules/manifest.yml', 'rules/manifest.yml'],
104
+ ['rules/buildr/core.md', 'rules/buildr/core.md'],
105
+ ];
106
+
107
+ for (const [rootRelative, packageRelative] of baselinePairs) {
108
+ const rootFile = path.join(root, rootRelative);
109
+ const packageFile = path.join(packageWorkspaceTargetRoot(), packageRelative);
110
+ if (existsFile(rootFile) && existsFile(packageFile)) {
111
+ const rootContent = fs.readFileSync(rootFile, 'utf8');
112
+ const packageContent = fs.readFileSync(packageFile, 'utf8');
113
+ if (rootContent !== packageContent) {
114
+ problems.push(`Root ${rootRelative} differs from ${PACKAGE_WORKSPACE_TARGET}/${packageRelative}.`);
115
+ }
116
+ }
117
+ }
118
+
119
+ for (const legacyRule of ['rules/AGENTS.workspace.md', 'rules/AGENTS.project.md']) {
120
+ if (existsFile(path.join(root, legacyRule))) {
121
+ problems.push(`Legacy workspace rule source must not remain in root: ${legacyRule}`);
122
+ }
123
+ }
124
+ }
125
+
126
+ function validatePackageMetadata(context) {
127
+ const { root, problems } = context;
128
+ const packageMetadataPath = path.join(root, 'package.json');
129
+ if (!existsFile(packageMetadataPath)) {
130
+ problems.push('Public npm package metadata is missing: package.json');
131
+ } else {
132
+ let packageMetadata;
133
+ try { packageMetadata = JSON.parse(fs.readFileSync(packageMetadataPath, 'utf8')); } catch (error) { problems.push(`package.json is invalid JSON: ${error.message}`); }
134
+ if (packageMetadata) {
135
+ if (packageMetadata.name !== '@buildr-ai/buildr') problems.push('package.json must declare the official @buildr-ai/buildr package identity.');
136
+ if (!/^\d+\.\d+\.\d+(?:[-+].+)?$/.test(packageMetadata.version || '') || packageMetadata.version === '0.0.0') problems.push('package.json must declare a non-placeholder semantic version.');
137
+ if (packageMetadata.private === true) problems.push('package.json must not block public packaging with private: true.');
138
+ if (packageMetadata.license !== 'MIT') problems.push('package.json must declare the MIT license.');
139
+ if (packageMetadata.repository?.url !== 'git+https://github.com/elevenching/Buildr.git' || packageMetadata.repository?.directory !== 'projects/product') problems.push('package.json repository must identify the canonical GitHub product directory.');
140
+ if (packageMetadata.homepage !== 'https://github.com/elevenching/Buildr#readme') problems.push('package.json homepage must identify the canonical GitHub README.');
141
+ if (packageMetadata.bugs?.url !== 'https://github.com/elevenching/Buildr/issues') problems.push('package.json bugs URL must identify canonical GitHub Issues.');
142
+ if (packageMetadata.publishConfig?.access !== 'public') problems.push('package.json publishConfig.access must be public.');
143
+ for (const keyword of ['agent', 'agentic-coding', 'cli', 'developer-tools', 'workspace']) {
144
+ if (!packageMetadata.keywords?.includes(keyword)) problems.push(`package.json keywords must include ${keyword}.`);
145
+ }
146
+ const packagedFiles = new Set(packageMetadata.files || []);
147
+ for (const required of ['LICENSE', 'tools/buildr', 'tools/cli/', 'tools/shared/fetch-remote-text.mjs', 'docs/cli-reference.md', 'docs/cli-architecture.md', 'docs/known-limitations.md', 'examples/minimal-workspace/README.md', 'package/']) {
148
+ if (!packagedFiles.has(required)) problems.push(`package.json files must include ${required}.`);
149
+ }
150
+ for (const obsolete of ['tools/check-runtime-skills.mjs', 'tools/render-codex.mjs']) {
151
+ if (packagedFiles.has(obsolete)) problems.push(`package.json files must not include unused standalone runtime entry: ${obsolete}.`);
152
+ }
153
+ }
154
+ }
155
+ for (const required of ['LICENSE', 'docs/cli-reference.md', 'docs/cli-architecture.md', 'docs/known-limitations.md', 'examples/minimal-workspace/README.md']) {
156
+ if (!fs.existsSync(path.join(root, required))) problems.push(`Open-source product baseline is missing: ${required}`);
157
+ }
158
+ if (existsFile(path.join(root, 'tools', 'install-buildr-cli'))) {
159
+ for (const required of ['tools/verification/onboarding/repository.mjs', 'tools/verification/onboarding/init.mjs', 'tools/verification/onboarding/service-branch.mjs', 'tools/verification/network/remote-text.mjs', 'tools/verification/cli/architecture.mjs', 'tools/verification/cli/compatibility.mjs', 'tools/verification/cli/package-parity.mjs', 'tools/verification/release/open-source-candidate.mjs', 'tools/verification/release/release-contract.mjs']) {
160
+ if (!existsFile(path.join(root, required))) problems.push(`Development checkout verification is missing: ${required}`);
161
+ }
162
+ }
163
+
164
+ for (const legacyPath of LEGACY_PACKAGE_PATHS) {
165
+ if (fs.existsSync(path.join(root, legacyPath))) {
166
+ problems.push(`Legacy package path must not remain: ${legacyPath}`);
167
+ }
168
+ }
169
+ }
170
+
171
+ function parseJsonOutput(label, output) {
172
+ try {
173
+ return JSON.parse(output);
174
+ } catch (error) {
175
+ const match = error.message.match(/position (\d+)/);
176
+ const position = match ? Number(match[1]) : 0;
177
+ const excerpt = output.slice(Math.max(0, position - 240), position + 240);
178
+ throw new Error(`${label} returned invalid JSON: ${error.message}\n${excerpt}`);
179
+ }
180
+ }
181
+
182
+ function validateMappedEntries(context) {
183
+ const { root, manifest, files, problems, mappedEntries } = context;
184
+ for (const includePath of manifest.include) {
185
+ const absolutePath = path.resolve(root, includePath);
186
+ if (!fs.existsSync(absolutePath)) {
187
+ problems.push(`Manifest include does not exist: ${includePath}`);
188
+ continue;
189
+ }
190
+ files.push(...collectFiles(absolutePath));
191
+ }
192
+
193
+ for (const section of ['workspaceFiles', 'projectFiles']) {
194
+ for (const rawEntry of manifest[section]) {
195
+ let entry;
196
+ try {
197
+ entry = parseManifestFileEntry(rawEntry, section);
198
+ } catch (error) {
199
+ problems.push(error.message);
200
+ continue;
201
+ }
202
+ mappedEntries.push(entry);
203
+ if (LEGACY_PACKAGE_PATHS.some((legacyPath) => entry.source === legacyPath || entry.source.startsWith(`${legacyPath}/`))) {
204
+ problems.push(`Package manifest must not reference legacy package source: ${entry.raw}`);
205
+ }
206
+ if (!entry.source.startsWith(`${PACKAGE_WORKSPACE_TARGET}/`)) {
207
+ problems.push(`Package manifest ${section} source must be under ${PACKAGE_WORKSPACE_TARGET}/: ${entry.raw}`);
208
+ }
209
+ if (entry.source.includes('AGENTS.private')) {
210
+ problems.push(`Package manifest must not publish private business rule: ${entry.raw}`);
211
+ }
212
+ if (entry.source.includes('package/workspace-rules/') || entry.source.includes('package/workspace-skills/') || entry.source.includes('package/baseline/')) {
213
+ problems.push(`Package manifest must use ${PACKAGE_WORKSPACE_TARGET}/ as the source for workspace baseline assets: ${entry.raw}`);
214
+ }
215
+ if (entry.source.startsWith('rules/')) {
216
+ problems.push(`Package manifest must use ${PACKAGE_WORKSPACE_TARGET}/rules/ as the source for published rule modules: ${entry.raw}`);
217
+ }
218
+ if (entry.target.startsWith('rules/') && !entry.source.startsWith(`${PACKAGE_WORKSPACE_TARGET}/rules/`)) {
219
+ problems.push(`Package manifest rule targets must source from ${PACKAGE_WORKSPACE_TARGET}/rules/: ${entry.raw}`);
220
+ }
221
+ if (entry.source.startsWith('product/')) {
222
+ problems.push(`Package manifest source must be relative to the product root, not product/ prefixed: ${entry.raw}`);
223
+ }
224
+ if (path.isAbsolute(entry.source) || entry.source.startsWith('..')) {
225
+ problems.push(`Package manifest source must stay inside product root: ${entry.raw}`);
226
+ continue;
227
+ }
228
+ if (path.isAbsolute(entry.target) || entry.target.startsWith('..')) {
229
+ problems.push(`Package manifest target must stay inside generated workspace: ${entry.raw}`);
230
+ }
231
+ const sourceFile = path.resolve(root, entry.source);
232
+ if (!existsFile(sourceFile)) {
233
+ problems.push(`Package manifest source does not exist: ${entry.source}`);
234
+ continue;
235
+ }
236
+ files.push(sourceFile);
237
+ }
238
+ }
239
+ }
240
+
241
+ function validatePackageComponents(context) {
242
+ const { root, manifest, files, problems, mappedEntries } = context;
243
+ const componentIds = new Set();
244
+ const componentOwnedWorkspaceFiles = new Set();
245
+ const componentMemberOwners = new Map();
246
+ for (const entry of manifest.components) {
247
+ const label = `components.${entry.id || '<missing>'}`;
248
+ for (const key of Object.keys(entry)) if (!['id', 'path', 'defaultEnabled', 'required'].includes(key)) problems.push(`${label}.${key} is not supported.`);
249
+ if (!entry.id || !entry.path || typeof entry.defaultEnabled !== 'boolean' || typeof entry.required !== 'boolean') {
250
+ problems.push(`${label} must include id, path, defaultEnabled, and required.`);
251
+ continue;
252
+ }
253
+ if (componentIds.has(entry.id)) problems.push(`Duplicate package Component id: ${entry.id}`);
254
+ componentIds.add(entry.id);
255
+ const expectedSuffix = `/components/`;
256
+ const componentPathParts = entry.path.split('/');
257
+ const exactComponentPath = entry.path.startsWith(`${PACKAGE_WORKSPACE_TARGET}${expectedSuffix}`)
258
+ && componentPathParts.at(-1) === 'component.yml'
259
+ && componentPathParts.at(-2) === entry.id
260
+ && componentPathParts.length === PACKAGE_WORKSPACE_TARGET.split('/').length + 4;
261
+ if (!exactComponentPath || path.isAbsolute(entry.path) || entry.path.startsWith('..')) {
262
+ problems.push(`${label}.path must be ${PACKAGE_WORKSPACE_TARGET}/components/<source>/${entry.id}/component.yml.`);
263
+ continue;
264
+ }
265
+ try {
266
+ const record = packageComponentDefinition(entry);
267
+ files.push(record.file);
268
+ componentOwnedWorkspaceFiles.add(toPosixRelative(root, record.file));
269
+ for (const message of validatePackageComponentMembers(manifest, record)) problems.push(message);
270
+ for (const member of componentMemberPaths(record.definition)) {
271
+ const previousOwner = componentMemberOwners.get(member);
272
+ if (previousOwner && previousOwner !== entry.id) problems.push(`Package Component ownership conflict for ${member}: ${previousOwner}, ${entry.id}.`);
273
+ componentMemberOwners.set(member, entry.id);
274
+ const source = packageComponentSourcePath(member);
275
+ for (const file of existsDirectory(source) ? collectFiles(source) : existsFile(source) ? [source] : []) {
276
+ files.push(file);
277
+ componentOwnedWorkspaceFiles.add(toPosixRelative(root, file));
278
+ }
279
+ if (member.endsWith('/manifest.yml') && member.startsWith('commands/')) {
280
+ const commandManifest = parseCommandsManifestYaml(fs.readFileSync(source, 'utf8'));
281
+ for (const message of validateCommandsManifest(commandManifest)) problems.push(`Package Component ${entry.id} command collection: ${message}`);
282
+ }
283
+ if (member.startsWith('skills/')) {
284
+ const skillFile = path.join(source, 'SKILL.md');
285
+ const content = fs.readFileSync(skillFile, 'utf8');
286
+ if (member === 'skills/buildr/openspec-contract-guard') {
287
+ if (!content.includes('author: buildr')) problems.push('OpenSpec contract guard Skill must declare Buildr as its author.');
288
+ if (!content.includes(`supportedOpenSpec: "${record.definition.upstream.version}"`)) {
289
+ problems.push(`OpenSpec contract guard Skill must declare supportedOpenSpec ${record.definition.upstream.version}.`);
290
+ }
291
+ } else {
292
+ const expected = `generatedBy: "${record.definition.upstream.version}"`;
293
+ if (!content.includes(expected)) problems.push(`Package Component ${entry.id} Skill generatedBy must match upstream version ${record.definition.upstream.version}: ${member}.`);
294
+ }
295
+ }
296
+ }
297
+ } catch (error) {
298
+ problems.push(`${label} is invalid: ${error.message}`);
299
+ }
300
+ }
301
+
302
+ const mappedSources = new Set(mappedEntries.map((entry) => entry.source));
303
+ for (const entry of mappedEntries) {
304
+ for (const member of componentMemberOwners.keys()) {
305
+ if (entry.target === member || entry.target.startsWith(`${member}/`)) {
306
+ problems.push(`Component member must not also be installed through workspaceFiles: ${entry.raw}`);
307
+ }
308
+ }
309
+ }
310
+ const workspaceSourceRoot = packageWorkspaceTargetRoot();
311
+ for (const workspaceFile of collectFiles(workspaceSourceRoot)) {
312
+ const relativeFile = toPosixRelative(root, workspaceFile);
313
+ if (!mappedSources.has(relativeFile) && !componentOwnedWorkspaceFiles.has(relativeFile)) {
314
+ problems.push(`Package workspace source file must be explicitly mapped in package/manifest.yml: ${relativeFile}`);
315
+ }
316
+ }
317
+ }
318
+
319
+ function validatePackageSkills(context) {
320
+ const { root, manifest, files, problems } = context;
321
+ const agentSkillIds = new Set();
322
+ for (const skill of manifest.agentSkills) {
323
+ if (!skill.id || !skill.path) {
324
+ problems.push('Package manifest agentSkills entries must include id and path.');
325
+ continue;
326
+ }
327
+ if (!skill.path.startsWith(`${PACKAGE_RUNTIME_TARGET}/skills/`)) {
328
+ problems.push(`Package agentSkill path must be under ${PACKAGE_RUNTIME_TARGET}/skills/: ${skill.path}`);
329
+ }
330
+ if (agentSkillIds.has(skill.id)) {
331
+ problems.push(`Duplicate package agentSkill id: ${skill.id}`);
332
+ }
333
+ agentSkillIds.add(skill.id);
334
+ if (!Array.isArray(skill.runtimes) || skill.runtimes.length === 0) {
335
+ problems.push(`Package agentSkill must declare at least one runtime: ${skill.id}`);
336
+ }
337
+ if (path.isAbsolute(skill.path) || skill.path.startsWith('..')) {
338
+ problems.push(`Package agentSkill path must stay inside product root: ${skill.path}`);
339
+ continue;
340
+ }
341
+ const skillDir = path.resolve(root, skill.path);
342
+ const skillFile = path.join(skillDir, 'SKILL.md');
343
+ if (!existsFile(skillFile)) {
344
+ problems.push(`Package agentSkill SKILL.md does not exist: ${skill.path}/SKILL.md`);
345
+ continue;
346
+ }
347
+ files.push(skillFile);
348
+ }
349
+
350
+ const skillSourceIds = new Set();
351
+ for (const skill of manifest.skillSources) {
352
+ if (!skill.id || !skill.path) {
353
+ problems.push('Package manifest skillSources entries must include id and path.');
354
+ continue;
355
+ }
356
+ if (skillSourceIds.has(skill.id)) {
357
+ problems.push(`Duplicate package skillSource id: ${skill.id}`);
358
+ }
359
+ skillSourceIds.add(skill.id);
360
+ if (!Array.isArray(skill.runtimes) || skill.runtimes.length === 0) {
361
+ problems.push(`Package skillSource must declare at least one runtime: ${skill.id}`);
362
+ }
363
+ if (path.isAbsolute(skill.path) || skill.path.startsWith('..')) {
364
+ problems.push(`Package skillSource path must stay inside product root: ${skill.path}`);
365
+ continue;
366
+ }
367
+ if (skill.runtimePath !== undefined) {
368
+ try {
369
+ normalizeRelativePathForBuildr(skill.runtimePath, `Package skillSource runtimePath must stay relative: ${skill.runtimePath}`);
370
+ } catch (error) {
371
+ problems.push(error.message);
372
+ }
373
+ }
374
+ const skillDir = path.resolve(root, skill.path);
375
+ const skillFile = path.join(skillDir, 'SKILL.md');
376
+ if (!existsFile(skillFile)) {
377
+ problems.push(`Package skillSource SKILL.md does not exist: ${skill.path}/SKILL.md`);
378
+ continue;
379
+ }
380
+ try {
381
+ const metadata = parseSkillFrontmatter(skillFile);
382
+ if (metadata.name !== skill.id) {
383
+ problems.push(`Package skillSource id must match SKILL.md frontmatter name: ${skill.id} != ${metadata.name}`);
384
+ }
385
+ } catch (error) {
386
+ problems.push(error.message);
387
+ }
388
+ files.push(...collectFiles(skillDir));
389
+ }
390
+ return skillSourceIds;
391
+ }
392
+
393
+ function validatePackageBuiltins(context, skillSourceIds) {
394
+ const { root, manifest, files, problems } = context;
395
+ const builtinIds = new Set();
396
+ function validateLegacyIntegrities(builtin, label) {
397
+ if (builtin.legacyIntegrities === undefined) return;
398
+ if (!Array.isArray(builtin.legacyIntegrities)) {
399
+ problems.push(`${label}.legacyIntegrities must be an array.`);
400
+ return;
401
+ }
402
+ const seen = new Set();
403
+ for (const integrity of builtin.legacyIntegrities) {
404
+ if (!/^sha256-[a-f0-9]{64}$/.test(integrity || '')) problems.push(`${label}.legacyIntegrities contains an invalid SHA-256 integrity.`);
405
+ if (seen.has(integrity)) problems.push(`${label}.legacyIntegrities contains a duplicate integrity: ${integrity}`);
406
+ seen.add(integrity);
407
+ }
408
+ }
409
+ for (const rule of manifest.builtins.rules) {
410
+ const label = `builtins.rules.${rule.id || '<missing>'}`;
411
+ validateLegacyIntegrities(rule, label);
412
+ if (!rule.id || !rule.path || !rule.target || !rule.description || typeof rule.required !== 'boolean') {
413
+ problems.push(`${label} must include id, path, target, description, and required.`);
414
+ continue;
415
+ }
416
+ if (builtinIds.has(`rule:${rule.id}`)) problems.push(`Duplicate builtin rule id: ${rule.id}`);
417
+ builtinIds.add(`rule:${rule.id}`);
418
+ if (!rule.target.startsWith('rules/buildr/') || !rule.target.endsWith('.md')) {
419
+ problems.push(`${label}.target must be rules/buildr/*.md.`);
420
+ }
421
+ if (!rule.path.startsWith(`${PACKAGE_WORKSPACE_TARGET}/rules/`)) {
422
+ problems.push(`${label}.path must be under ${PACKAGE_WORKSPACE_TARGET}/rules/.`);
423
+ }
424
+ if (path.isAbsolute(rule.path) || rule.path.startsWith('..') || path.isAbsolute(rule.target) || rule.target.startsWith('..')) {
425
+ problems.push(`${label} paths must stay relative.`);
426
+ continue;
427
+ }
428
+ const sourceFile = path.resolve(root, rule.path);
429
+ if (!existsFile(sourceFile)) {
430
+ problems.push(`${label}.path does not exist: ${rule.path}`);
431
+ } else {
432
+ files.push(sourceFile);
433
+ }
434
+ }
435
+ if (!manifest.builtins.rules.some((rule) => rule.id === 'buildr-core' && rule.required === true && rule.target === 'rules/buildr/core.md')) {
436
+ problems.push('builtins.rules must declare required buildr-core at rules/buildr/core.md.');
437
+ }
438
+
439
+ for (const skill of manifest.builtins.skills) {
440
+ const label = `builtins.skills.${skill.id || '<missing>'}`;
441
+ validateLegacyIntegrities(skill, label);
442
+ if (!skill.id || !skill.path || !skill.target || !skill.description || typeof skill.required !== 'boolean') {
443
+ problems.push(`${label} must include id, path, target, description, and required.`);
444
+ continue;
445
+ }
446
+ if (builtinIds.has(`skill:${skill.id}`)) problems.push(`Duplicate builtin skill id: ${skill.id}`);
447
+ builtinIds.add(`skill:${skill.id}`);
448
+ const isOpenSpecUpstreamSkill = skill.component === 'openspec' && skill.id.startsWith('openspec-') && skill.id !== 'openspec-contract-guard';
449
+ const expectedSkillRoot = isOpenSpecUpstreamSkill ? 'skills/openspec/' : 'skills/buildr/';
450
+ if (!skill.target.startsWith(expectedSkillRoot)) {
451
+ problems.push(`${label}.target must be under ${expectedSkillRoot}.`);
452
+ }
453
+ if (!skill.path.startsWith(`${PACKAGE_WORKSPACE_TARGET}/skills/`)) {
454
+ problems.push(`${label}.path must be under ${PACKAGE_WORKSPACE_TARGET}/skills/.`);
455
+ }
456
+ if (!Array.isArray(skill.runtimes) || !skill.runtimes.includes('claude-code') || !skill.runtimes.includes('codex')) {
457
+ problems.push(`${label}.runtimes must include claude-code and codex.`);
458
+ }
459
+ if (path.isAbsolute(skill.path) || skill.path.startsWith('..') || path.isAbsolute(skill.target) || skill.target.startsWith('..')) {
460
+ problems.push(`${label} paths must stay relative.`);
461
+ continue;
462
+ }
463
+ const skillDir = path.resolve(root, skill.path);
464
+ const skillFile = path.join(skillDir, 'SKILL.md');
465
+ if (!existsFile(skillFile)) {
466
+ problems.push(`${label}.path must contain SKILL.md: ${skill.path}`);
467
+ continue;
468
+ }
469
+ try {
470
+ const metadata = parseSkillFrontmatter(skillFile);
471
+ if (metadata.name !== skill.id) problems.push(`${label}.id must match SKILL.md frontmatter name: ${skill.id} != ${metadata.name}`);
472
+ } catch (error) {
473
+ problems.push(error.message);
474
+ }
475
+ const skillContent = fs.readFileSync(skillFile, 'utf8');
476
+ if (skill.id === 'task-worktree') {
477
+ for (const requiredText of [
478
+ '<workspace-root>/.worktrees/<task-id>',
479
+ 'canonical worktree 路径和任务分支',
480
+ '不得静默回退到 `/tmp`',
481
+ 'propose 和创建 change artifacts 前',
482
+ 'artifacts、实现和合并前候选验证都只能写入该 worktree',
483
+ '验证证据边界',
484
+ '最终候选 Git tree',
485
+ '三级验证门禁',
486
+ '单任务最小反馈',
487
+ '任务组受影响范围验证',
488
+ '最终候选完整验证',
489
+ '同一候选状态不机械重复该底层检查',
490
+ '修复期间优先重跑失败项和受影响专项检查',
491
+ 'wait、poll 或 resume 继续同一进程',
492
+ '暂时无输出不得触发相同命令重复启动',
493
+ '不在主开发分支重复运行相同 E2E',
494
+ '候选 tree 已改变时沿用旧验证结果',
495
+ '不从未合并 task checkout 更新主自举 workspace',
496
+ ]) {
497
+ if (!skillContent.includes(requiredText)) problems.push(`task-worktree Skill must include ${JSON.stringify(requiredText)}.`);
498
+ }
499
+ }
500
+ if (skill.id === 'git-ops') {
501
+ for (const requiredText of [
502
+ '最终候选 Git tree',
503
+ 'rebase 前后必须比较最终候选 Git tree',
504
+ '改变已验证 tree 时,原验证结果失效',
505
+ '相同 tree',
506
+ '不因 checkout、commit hash 或分支名称改变而重复运行相同验证',
507
+ ]) {
508
+ if (!skillContent.includes(requiredText)) problems.push(`git-ops Skill must include ${JSON.stringify(requiredText)}.`);
509
+ }
510
+ if (skill.description.includes('收尾')) {
511
+ problems.push('git-ops builtin description must not claim the complete task closeout intent.');
512
+ }
513
+ try {
514
+ const metadata = parseSkillFrontmatter(skillFile);
515
+ if (String(metadata.description || '').includes('收尾')) {
516
+ problems.push('git-ops Skill description must not claim the complete task closeout intent.');
517
+ }
518
+ } catch {
519
+ // Frontmatter errors are already reported above.
520
+ }
521
+ }
522
+ if (skill.id === 'task-finish') {
523
+ for (const requiredText of [
524
+ '一次性授权',
525
+ 'openspec status --change <id> --json',
526
+ 'new blank line at EOF',
527
+ '恰好以一个换行结束',
528
+ 'git rev-parse HEAD^{tree}',
529
+ 'fast-forward-only',
530
+ '不删除远端任务分支',
531
+ '工作目录切换到主 workspace',
532
+ '修复期间已经优先重跑失败项和受影响专项检查',
533
+ '候选重新稳定后完成一次新的最终完整验证',
534
+ 'wait、poll 或 resume 同一进程',
535
+ '暂时无输出不得启动第二个相同验证',
536
+ '停止尚未执行的 archive、commit、rebase、merge、push 或 cleanup',
537
+ '<!-- buildr:skill-contributions pre-spec-sync -->',
538
+ '<!-- buildr:skill-contributions post-spec-sync -->',
539
+ ]) {
540
+ if (!skillContent.includes(requiredText)) problems.push(`task-finish Skill must include ${JSON.stringify(requiredText)}.`);
541
+ }
542
+ if (skillContent.includes('buildr openspec')) problems.push('task-finish source must not hard-code OpenSpec contract guard commands; installed Components contribute them at render time.');
543
+ }
544
+ if (skill.id === 'task-triage') {
545
+ for (const requiredText of ['OpenSpec change 状态', 'artifact 或 task 进度', '下一步或阻塞原因', 'openspec status --change <id> --json', '文档正文使用中文', 'openspec-*` Skills', '实现型任务的验证编排', '有语义的任务组', '完整候选验证放在全部实现', '不得把 Buildr 产品仓的 package check', '<!-- buildr:skill-contributions change-ready -->']) {
546
+ if (!skillContent.includes(requiredText)) problems.push(`task-triage Skill must include ${JSON.stringify(requiredText)}.`);
547
+ }
548
+ if (skillContent.includes('buildr openspec')) problems.push('task-triage source must not hard-code OpenSpec contract guard commands; installed Components contribute them at render time.');
549
+ }
550
+ if (skill.id === 'openspec-contract-guard') {
551
+ for (const requiredText of ['buildr openspec baseline create', '--stage pre-sync', '--stage post-sync', '不修改外部 `openspec-*` Skills']) {
552
+ if (!skillContent.includes(requiredText)) problems.push(`openspec-contract-guard Skill must include ${JSON.stringify(requiredText)}.`);
553
+ }
554
+ }
555
+ if (skill.id.startsWith('openspec-') && skill.id !== 'openspec-contract-guard' && skillContent.includes('buildr openspec')) {
556
+ problems.push(`${label} must not embed Buildr contract guard commands; the sidebar Skill owns that workflow.`);
557
+ }
558
+ if (isOpenSpecUpstreamSkill && skill.target.startsWith('skills/buildr/')) problems.push(`${label} must preserve upstream ownership outside skills/buildr/.`);
559
+ files.push(...collectFiles(skillDir));
560
+ }
561
+ if (!manifest.builtins.skills.some((skill) => skill.id === 'task-finish' && skill.required === false)) {
562
+ problems.push('builtins.skills must declare optional task-finish.');
563
+ }
564
+
565
+ for (const command of manifest.builtins.commands) {
566
+ validateLegacyIntegrities(command, `builtins.commands.${command.id || '<missing>'}`);
567
+ if (!command.id || typeof command.required !== 'boolean' || !isPlainObject(command.manifestEntry)) {
568
+ problems.push(`builtins.commands entries must include id, required, and manifestEntry.`);
569
+ }
570
+ }
571
+
572
+ const productAgentsPath = path.join(root, 'AGENTS.md');
573
+ if (existsFile(productAgentsPath)) {
574
+ const productAgents = fs.readFileSync(productAgentsPath, 'utf8');
575
+ files.push(productAgentsPath);
576
+ for (const requiredText of [
577
+ '合并前候选验证使用临时 workspace 或 task worktree 自身',
578
+ '最终候选 Git tree',
579
+ '不在主开发分支重复 E2E',
580
+ '候选 tree 改变时',
581
+ '单任务最小反馈、任务组受影响范围验证、最终候选完整验证',
582
+ '不得在每个普通任务后运行产品总验证或临时 workspace E2E',
583
+ '继续等待同一进程,不重复启动相同命令',
584
+ '修复循环优先重跑失败项和受影响检查',
585
+ '不作为相同 tree 后续 Git 动作的重复产品验证门禁',
586
+ '使用 `task-finish` 编排',
587
+ '不授权 force push、merge commit、远端任务分支删除',
588
+ ]) {
589
+ if (!productAgents.includes(requiredText)) problems.push(`Product AGENTS.md must include ${JSON.stringify(requiredText)}.`);
590
+ }
591
+ }
592
+
593
+ const baselineSkillsManifest = path.join(packageWorkspaceTargetRoot(), 'skills', 'manifest.yml');
594
+ if (existsFile(baselineSkillsManifest)) {
595
+ try {
596
+ const baselineSkills = readSkillManifest(baselineSkillsManifest);
597
+ validateSkillManifestEntries(baselineSkills, baselineSkillsManifest);
598
+ const taskFinish = baselineSkills.find((entry) => entry.id === 'task-finish');
599
+ if (!taskFinish || taskFinish.source !== 'buildr' || taskFinish.state !== 'installed' || taskFinish.enabled !== true) {
600
+ problems.push('Workspace skills baseline must declare enabled installed Buildr task-finish.');
601
+ }
602
+ for (const skill of baselineSkills.filter((entry) => entry.source !== undefined)) {
603
+ if (typeof skill.source === 'string' && !isManifestSourceLabel(skill.source)) {
604
+ const parsed = parseSkillSourceRef(skill.source);
605
+ if (parsed.type === 'package' && !skillSourceIds.has(parsed.id)) {
606
+ problems.push(`Workspace skills baseline references unknown package skillSource: ${skill.source}`);
607
+ }
608
+ }
609
+ }
610
+ } catch (error) {
611
+ problems.push(error.message);
612
+ }
613
+ }
614
+
615
+ const baselineProjectsRegistry = path.join(packageWorkspaceTargetRoot(), 'projects', 'manifest.yml');
616
+ if (existsFile(baselineProjectsRegistry)) {
617
+ try {
618
+ const registry = parseProjectsYaml(fs.readFileSync(baselineProjectsRegistry, 'utf8'));
619
+ const errors = validateProjectsRegistry(registry);
620
+ if (errors.length > 0) {
621
+ problems.push(`Workspace projects/manifest.yml baseline is invalid:\n- ${errors.join('\n- ')}`);
622
+ }
623
+ } catch (error) {
624
+ problems.push(`Workspace projects/manifest.yml baseline is invalid: ${error.message}`);
625
+ }
626
+ }
627
+ }
628
+
629
+ function validatePackageAssets(context) {
630
+ const { root, workspaceRoot, manifestPath, manifest, allowedVariables, files, problems } = context;
631
+ const bootstrapContract = validateBootstrapContract(root, files, problems);
632
+ if (workspaceRoot) {
633
+ validateWorkspaceSkillsBaseline(workspaceRoot, problems);
634
+ validateWorkspaceRulesBaseline(workspaceRoot, problems);
635
+ }
636
+
637
+ for (const file of [...new Set(files)]) {
638
+ const relativeFile = toPosixRelative(root, file);
639
+ const content = fs.readFileSync(file, 'utf8');
640
+ if (path.basename(file) === '.gitkeep') {
641
+ problems.push(`Package assets must not use .gitkeep placeholders: ${relativeFile}`);
642
+ }
643
+
644
+ const contentForForbiddenScan = path.resolve(file) === manifestPath
645
+ ? content.replace(/\nforbiddenPatterns:\n(?:\s+-\s+.+\n?)*/m, '\nforbiddenPatterns:\n')
646
+ : content;
647
+
648
+ for (const pattern of manifest.forbiddenPatterns) {
649
+ if (pattern && contentForForbiddenScan.includes(pattern)) {
650
+ problems.push(`Forbidden pattern ${JSON.stringify(pattern)} found in ${relativeFile}`);
651
+ }
652
+ }
653
+
654
+ for (const match of content.matchAll(/\{\{([A-Za-z0-9_]+)\}\}/g)) {
655
+ if (!allowedVariables.has(match[1])) {
656
+ problems.push(`Template variable ${match[1]} is not declared in manifest: ${relativeFile}`);
657
+ }
658
+ }
659
+ }
660
+ return bootstrapContract;
661
+ }
662
+
663
+ function validatePackageStatic(context) {
664
+ validatePackageMetadata(context);
665
+ validateMappedEntries(context);
666
+ validatePackageComponents(context);
667
+ const skillSourceIds = validatePackageSkills(context);
668
+ validatePackageBuiltins(context, skillSourceIds);
669
+ const bootstrapContract = validatePackageAssets(context);
670
+ return { bootstrapContract, parseJsonOutput };
671
+ }
672
+
673
+ return {
674
+ validateWorkspaceSkillsBaseline,
675
+ validateWorkspaceRulesBaseline,
676
+ validatePackageStatic,
677
+ };
678
+ }