@buildr-ai/buildr 0.1.0-rc.2 → 0.1.0-rc.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/README.md +47 -5
  2. package/application-payload.json +595 -0
  3. package/bin/buildr.mjs +14 -0
  4. package/installation-origin.json +13 -0
  5. package/package.json +16 -45
  6. package/payload/licenses/dependencies/yaml-LICENSE +13 -0
  7. package/payload/product/LICENSE +21 -0
  8. package/payload/product/README.md +59 -0
  9. package/payload/product/package/README.md +42 -0
  10. package/{package → payload/product/package}/bootstrap/contract.yml +26 -11
  11. package/{package → payload/product/package}/bootstrap/guide.md +11 -11
  12. package/payload/product/package/launchers/assets/Buildr.icns +0 -0
  13. package/payload/product/package/launchers/assets/Buildr.ico +0 -0
  14. package/payload/product/package/manifest.yml +547 -0
  15. package/payload/product/package/targets/runtime/skills/buildr/SKILL.md +174 -0
  16. package/{package → payload/product/package}/targets/workspace/commands/buildr/openspec/manifest.yml +2 -2
  17. package/payload/product/package/targets/workspace/components/buildr/openspec/component.yml +79 -0
  18. package/payload/product/package/targets/workspace/components/buildr/openspec/contributions/openspec-apply-sidebar.md +21 -0
  19. package/payload/product/package/targets/workspace/components/buildr/openspec/contributions/openspec-archive-converge.md +5 -0
  20. package/payload/product/package/targets/workspace/components/buildr/openspec/contributions/openspec-explore-terminology.md +5 -0
  21. package/payload/product/package/targets/workspace/components/buildr/openspec/contributions/openspec-propose-sidebar.md +21 -0
  22. package/payload/product/package/targets/workspace/components/buildr/openspec/contributions/openspec-sync-converge.md +5 -0
  23. package/payload/product/package/targets/workspace/components/buildr/openspec/contributions/openspec-update-sidebar.md +13 -0
  24. package/payload/product/package/targets/workspace/gitattributes +1 -0
  25. package/payload/product/package/targets/workspace/gitignore +31 -0
  26. package/{package → payload/product/package}/targets/workspace/projects/AGENTS.project.md +1 -1
  27. package/payload/product/package/targets/workspace/rules/buildr/core.md +62 -0
  28. package/payload/product/package/targets/workspace/skills/buildr/capability-adaptation/SKILL.md +56 -0
  29. package/payload/product/package/targets/workspace/skills/buildr/capability-adaptation/agents/openai.yaml +4 -0
  30. package/payload/product/package/targets/workspace/skills/buildr/current-knowledge-maintenance/SKILL.md +103 -0
  31. package/payload/product/package/targets/workspace/skills/buildr/declaration-intake/SKILL.md +65 -0
  32. package/payload/product/package/targets/workspace/skills/buildr/git-operations/SKILL.md +100 -0
  33. package/payload/product/package/targets/workspace/skills/buildr/openspec-contract-guard/SKILL.md +65 -0
  34. package/payload/product/package/targets/workspace/skills/buildr/project-daily-progress/SKILL.md +52 -0
  35. package/payload/product/package/targets/workspace/skills/buildr/project-testing/SKILL.md +84 -0
  36. package/payload/product/package/targets/workspace/skills/buildr/project-testing/references/testing-model-v1.md +116 -0
  37. package/payload/product/package/targets/workspace/skills/buildr/task-development/SKILL.md +108 -0
  38. package/payload/product/package/targets/workspace/skills/buildr/task-environment/SKILL.md +42 -0
  39. package/payload/product/package/targets/workspace/skills/buildr/task-environment/agents/openai.yaml +4 -0
  40. package/payload/product/package/targets/workspace/skills/buildr/task-environment/references/project-environment-preparation-v1.md +14 -0
  41. package/payload/product/package/targets/workspace/skills/buildr/task-environment/templates/project-preparation.yml +20 -0
  42. package/payload/product/package/targets/workspace/skills/buildr/task-environment/templates/task-environment-plan-request.json +17 -0
  43. package/payload/product/package/targets/workspace/skills/buildr/task-finish/SKILL.md +80 -0
  44. package/payload/product/package/targets/workspace/skills/buildr/task-manager/SKILL.md +47 -0
  45. package/payload/product/package/targets/workspace/skills/buildr/task-manager/agents/openai.yaml +4 -0
  46. package/payload/product/package/targets/workspace/skills/buildr/task-retrospective/SKILL.md +101 -0
  47. package/payload/product/package/targets/workspace/skills/buildr/task-retrospective/agents/openai.yaml +4 -0
  48. package/payload/product/package/targets/workspace/skills/buildr/task-review/SKILL.md +60 -0
  49. package/payload/product/package/targets/workspace/skills/buildr/task-review/agents/openai.yaml +4 -0
  50. package/payload/product/package/targets/workspace/skills/buildr/task-triage/SKILL.md +119 -0
  51. package/payload/product/package/targets/workspace/skills/buildr/task-verification/SKILL.md +142 -0
  52. package/payload/product/package/targets/workspace/skills/buildr/task-verification/references/project-verification-v2.md +51 -0
  53. package/payload/product/package/targets/workspace/skills/buildr/task-verification/templates/project-verification.yml +16 -0
  54. package/payload/product/package/targets/workspace/skills/buildr/task-worktree/SKILL.md +28 -0
  55. package/payload/product/package/targets/workspace/skills/buildr/terminology-governance/SKILL.md +60 -0
  56. package/payload/product/package/targets/workspace/skills/buildr/ui-preview/SKILL.md +74 -0
  57. package/payload/product/package/targets/workspace/skills/contracts/buildr/current-knowledge-maintenance/v1.md +36 -0
  58. package/payload/product/package/targets/workspace/skills/contracts/buildr/current-knowledge-maintenance/v2.md +45 -0
  59. package/payload/product/package/targets/workspace/skills/contracts/buildr/git-operations/v1.md +39 -0
  60. package/payload/product/package/targets/workspace/skills/contracts/buildr/git-worktree-provider/v1.md +35 -0
  61. package/payload/product/package/targets/workspace/skills/contracts/buildr/task-development/v2.md +61 -0
  62. package/payload/product/package/targets/workspace/skills/contracts/buildr/task-environment/v1.md +37 -0
  63. package/payload/product/package/targets/workspace/skills/contracts/buildr/task-finish/v1.md +59 -0
  64. package/payload/product/package/targets/workspace/skills/contracts/buildr/task-record/v2.md +35 -0
  65. package/payload/product/package/targets/workspace/skills/contracts/buildr/task-retrospective/v2.md +41 -0
  66. package/payload/product/package/targets/workspace/skills/contracts/buildr/task-review/v1.md +39 -0
  67. package/payload/product/package/targets/workspace/skills/contracts/buildr/task-verification/v3.md +63 -0
  68. package/payload/product/package/targets/workspace/skills/contracts/buildr/terminology-governance/v1.md +36 -0
  69. package/{package → payload/product/package}/targets/workspace/skills/openspec/openspec-apply-change/SKILL.md +4 -3
  70. package/{package → payload/product/package}/targets/workspace/skills/openspec/openspec-archive-change/SKILL.md +4 -3
  71. package/{package → payload/product/package}/targets/workspace/skills/openspec/openspec-explore/SKILL.md +4 -1
  72. package/{package → payload/product/package}/targets/workspace/skills/openspec/openspec-propose/SKILL.md +4 -1
  73. package/{package → payload/product/package}/targets/workspace/skills/openspec/openspec-sync-specs/SKILL.md +4 -3
  74. package/payload/product/package/targets/workspace/skills/openspec/openspec-update-change/SKILL.md +86 -0
  75. package/payload/product/package.json +33 -0
  76. package/payload/product/src/infrastructure/sqlite/migrations/0000_create_migration_ledger.sql +16 -0
  77. package/payload/product/src/infrastructure/sqlite/migrations/0001_create_task_store.sql +47 -0
  78. package/payload/product/src/infrastructure/sqlite/migrations/0002_create_parent_task_relations.sql +7 -0
  79. package/payload/product/src/infrastructure/sqlite/migrations/0003_inline_parent_task_column.sql +19 -0
  80. package/payload/product/src/infrastructure/sqlite/migrations/0004_create_task_current_records.sql +16 -0
  81. package/payload/product/src/infrastructure/sqlite/migrations/0005_create_task_retrospective_current.sql +4 -0
  82. package/payload/product/src/infrastructure/sqlite/migrations/0006_create_task_lifecycle_current.sql +4 -0
  83. package/payload/product/src/infrastructure/sqlite/migrations/0007_create_task_finish_current.sql +46 -0
  84. package/payload/product/src/infrastructure/sqlite/migrations/0008_create_task_environment_current.sql +8 -0
  85. package/payload/product/src/infrastructure/sqlite/migrations/0009_retire_task_lifecycle_current.sql +107 -0
  86. package/payload/product/src/infrastructure/sqlite/migrations/0010_add_task_retrospective_disposition.sql +19 -0
  87. package/payload/product/src/infrastructure/sqlite/migrations/0011_create_task_execution_records.sql +115 -0
  88. package/payload/product/src/infrastructure/sqlite/migrations/0012_compact_task_finish_current.sql +261 -0
  89. package/payload/product/src/infrastructure/sqlite/migrations/0013_add_todo_task_retrospective_sources.sql +56 -0
  90. package/payload/product/src/infrastructure/sqlite/migrations/0014_add_task_execution_invocation_identity.sql +14 -0
  91. package/payload/product/src/infrastructure/sqlite/migrations/0015_add_task_execution_unknown_outcome.sql +143 -0
  92. package/payload/product/src/infrastructure/sqlite/migrations/0016_allow_terminal_task_finish_target_lease.sql +83 -0
  93. package/payload/product/src/infrastructure/sqlite/migrations/0017_expand_task_finish_repository_set.sql +111 -0
  94. package/payload/product/src/interfaces/local-app/web-dist/assets/antd-NAtxFWmu.js +394 -0
  95. package/payload/product/src/interfaces/local-app/web-dist/assets/index-BqoyfMSY.css +1 -0
  96. package/payload/product/src/interfaces/local-app/web-dist/assets/index-DTqvE0TF.js +39 -0
  97. package/payload/product/src/interfaces/local-app/web-dist/assets/react-9kRp7SbA.js +28 -0
  98. package/payload/product/src/interfaces/local-app/web-dist/index.html +19 -0
  99. package/payload/runtime/read-worker.cjs +45071 -0
  100. package/runtime/buildr.cjs +51533 -0
  101. package/scripts/postinstall.mjs +15 -0
  102. package/docs/agent-runtime-adapters.md +0 -94
  103. package/docs/cli-architecture.md +0 -65
  104. package/docs/cli-reference.md +0 -67
  105. package/docs/known-limitations.md +0 -15
  106. package/examples/minimal-workspace/README.md +0 -24
  107. package/package/README.md +0 -28
  108. package/package/manifest.yml +0 -150
  109. package/package/targets/runtime/skills/buildr/SKILL.md +0 -154
  110. package/package/targets/workspace/.buildr/workspace.yml +0 -5
  111. package/package/targets/workspace/commands/manifest.yml +0 -2
  112. package/package/targets/workspace/components/buildr/openspec/component.yml +0 -16
  113. package/package/targets/workspace/components/buildr/openspec/contributions/openspec-apply-sidebar.md +0 -3
  114. package/package/targets/workspace/components/buildr/openspec/contributions/openspec-archive-sidebar.md +0 -3
  115. package/package/targets/workspace/components/buildr/openspec/contributions/openspec-explore-sidebar.md +0 -3
  116. package/package/targets/workspace/components/buildr/openspec/contributions/openspec-propose-sidebar.md +0 -3
  117. package/package/targets/workspace/components/buildr/openspec/contributions/openspec-sync-sidebar.md +0 -3
  118. package/package/targets/workspace/components/buildr/openspec/contributions/task-finish-post-sync.md +0 -1
  119. package/package/targets/workspace/components/buildr/openspec/contributions/task-finish-pre-sync.md +0 -1
  120. package/package/targets/workspace/components/buildr/openspec/contributions/task-triage-change-ready.md +0 -10
  121. package/package/targets/workspace/components/manifest.yml +0 -2
  122. package/package/targets/workspace/gitignore +0 -16
  123. package/package/targets/workspace/projects/manifest.yml +0 -2
  124. package/package/targets/workspace/projects/services/manifest.yml +0 -3
  125. package/package/targets/workspace/projects/skills/manifest.yml +0 -2
  126. package/package/targets/workspace/rules/buildr/core.md +0 -65
  127. package/package/targets/workspace/rules/manifest.yml +0 -9
  128. package/package/targets/workspace/skills/buildr/git-ops/SKILL.md +0 -73
  129. package/package/targets/workspace/skills/buildr/openspec-contract-guard/SKILL.md +0 -67
  130. package/package/targets/workspace/skills/buildr/task-finish/SKILL.md +0 -104
  131. package/package/targets/workspace/skills/buildr/task-triage/SKILL.md +0 -103
  132. package/package/targets/workspace/skills/buildr/task-worktree/SKILL.md +0 -104
  133. package/package/targets/workspace/skills/manifest.yml +0 -38
  134. package/tools/buildr +0 -11
  135. package/tools/cli/application/cli-update.mjs +0 -219
  136. package/tools/cli/application/compose-runtime.mjs +0 -38
  137. package/tools/cli/application/doctor/runtime-diagnostics.mjs +0 -227
  138. package/tools/cli/application/doctor/scope-diagnostics.mjs +0 -440
  139. package/tools/cli/application/doctor/service-diagnostics.mjs +0 -184
  140. package/tools/cli/application/doctor.mjs +0 -201
  141. package/tools/cli/application/package-maintenance/builtin-receipts.mjs +0 -73
  142. package/tools/cli/application/package-maintenance/output.mjs +0 -148
  143. package/tools/cli/application/package-maintenance/smoke-checks.mjs +0 -463
  144. package/tools/cli/application/package-maintenance/static-validation.mjs +0 -680
  145. package/tools/cli/application/package-maintenance.mjs +0 -540
  146. package/tools/cli/application/runtime.mjs +0 -118
  147. package/tools/cli/application/workspace-operations.mjs +0 -311
  148. package/tools/cli/bootstrap.mjs +0 -6
  149. package/tools/cli/command/help.mjs +0 -296
  150. package/tools/cli/command/registry.mjs +0 -97
  151. package/tools/cli/domains/commands.mjs +0 -661
  152. package/tools/cli/domains/components.mjs +0 -922
  153. package/tools/cli/domains/openspec.mjs +0 -603
  154. package/tools/cli/domains/package-assets.mjs +0 -652
  155. package/tools/cli/domains/rules.mjs +0 -380
  156. package/tools/cli/domains/runtime.mjs +0 -87
  157. package/tools/cli/domains/skills.mjs +0 -647
  158. package/tools/cli/domains/workspace.mjs +0 -571
  159. package/tools/cli/shared/infrastructure.mjs +0 -411
  160. package/tools/cli/shared/json-contracts.mjs +0 -22
  161. package/tools/cli/shared/platform.mjs +0 -52
  162. package/tools/runtime/adapter-contract.mjs +0 -655
  163. package/tools/runtime/check-claude-code.mjs +0 -23
  164. package/tools/runtime/check-codex.mjs +0 -23
  165. package/tools/runtime/check-runtime.mjs +0 -98
  166. package/tools/runtime/projection.mjs +0 -375
  167. package/tools/runtime/render-claude-code-rules.mjs +0 -459
  168. package/tools/runtime/render-claude-code.mjs +0 -59
  169. package/tools/runtime/skills/arguments.mjs +0 -51
  170. package/tools/runtime/skills/contributions.mjs +0 -171
  171. package/tools/runtime/skills/manifests.mjs +0 -167
  172. package/tools/runtime/skills/primitives.mjs +0 -86
  173. package/tools/runtime/skills/render-plan.mjs +0 -243
  174. package/tools/runtime/skills/sources.mjs +0 -276
  175. package/tools/shared/fetch-remote-text.mjs +0 -78
  176. package/tools/verification/integrity/managed-data-integrity.mjs +0 -107
  177. package/tools/verification/integrity/managed-mutations.mjs +0 -72
  178. package/tools/verification/openspec/contract.mjs +0 -212
  179. package/tools/verification/runtime/adapter-contract.mjs +0 -218
  180. package/tools/verification/runtime/adapter-parity.mjs +0 -173
  181. /package/{package → payload/product/package}/targets/workspace/AGENTS.md +0 -0
@@ -1,571 +0,0 @@
1
- import {
2
- fs,
3
- crypto,
4
- path,
5
- process,
6
- execFileSync,
7
- spawnSync,
8
- YAML,
9
- } from '../shared/platform.mjs';
10
-
11
- export function registerDomainsWorkspace(runtime) {
12
- const readGitRemote = (...args) => runtime.readGitRemote(...args);
13
- const gitignoreLines = (...args) => runtime.gitignoreLines(...args);
14
- const isPlainObject = (...args) => runtime.isPlainObject(...args);
15
- const assertNoUnknownOptions = (...args) => runtime.assertNoUnknownOptions(...args);
16
- const positionalArgs = (...args) => runtime.positionalArgs(...args);
17
- const readPackageManifest = (...args) => runtime.readPackageManifest(...args);
18
- const parseManifestFileEntry = (...args) => runtime.parseManifestFileEntry(...args);
19
- const isValidAssetId = (...args) => runtime.isValidAssetId(...args);
20
- const assertName = (...args) => runtime.assertName(...args);
21
- const renderSkillsManifestYaml = (...args) => runtime.renderSkillsManifestYaml(...args);
22
- const optionValue = (...args) => runtime.optionValue(...args);
23
- const ensureDirectory = (...args) => runtime.ensureDirectory(...args);
24
- const atomicWriteFile = (...args) => runtime.atomicWriteFile(...args);
25
- const parseYamlDocument = (...args) => runtime.parseYamlDocument(...args);
26
- const sameGitIdentity = (...args) => runtime.sameGitIdentity(...args);
27
- const withWorkspaceMutation = (...args) => runtime.withWorkspaceMutation(...args);
28
- const writeIfMissing = (...args) => runtime.writeIfMissing(...args);
29
- const writeMappedFileIfMissing = (...args) => runtime.writeMappedFileIfMissing(...args);
30
- const appendGitignoreEntries = (...args) => runtime.appendGitignoreEntries(...args);
31
- const toPosixRelative = (...args) => runtime.toPosixRelative(...args);
32
- const existsDirectory = (...args) => runtime.existsDirectory(...args);
33
- const existsFile = (...args) => runtime.existsFile(...args);
34
-
35
- function parseProjectRef(ref) {
36
- const parts = ref.split('/').filter(Boolean);
37
- if (parts.length === 1) {
38
- assertName(parts[0], 'Project');
39
- return { project: parts[0] };
40
- }
41
- throw new Error(`Project ref must be <project>. Organization-prefixed refs are not supported: ${ref}`);
42
- }
43
-
44
- function parseServiceRef(ref) {
45
- const parts = ref.split('/').filter(Boolean);
46
- if (parts.length === 2) {
47
- assertName(parts[0], 'Project');
48
- assertName(parts[1], 'Service');
49
- return { project: parts[0], service: parts[1] };
50
- }
51
- throw new Error(`Service ref must be <project>/<service>. Organization-prefixed refs are not supported: ${ref}`);
52
- }
53
-
54
- function isGitUrl(value) {
55
- return /^(https?:\/\/|ssh:\/\/|git@)/.test(value) || /\.git$/.test(value);
56
- }
57
-
58
- function isProjectGitUrl(value) {
59
- return /^(https?:\/\/|ssh:\/\/|git@|file:\/\/)/.test(value);
60
- }
61
-
62
- function quoteYaml(value) {
63
- if (Array.isArray(value)) return JSON.stringify(value.map((item) => String(item)));
64
- if (typeof value === 'boolean') return value ? 'true' : 'false';
65
- return JSON.stringify(String(value));
66
- }
67
-
68
- function parseYamlValue(value) {
69
- const document = YAML.parseDocument(value, { uniqueKeys: true, prettyErrors: true });
70
- if (document.errors.length) throw new Error(`Invalid YAML value: ${value} (${document.errors.map((error) => error.message).join('; ')})`);
71
- return document.toJS();
72
- }
73
-
74
- function parseServicesYaml(content) {
75
- const parsed = parseYamlDocument(content, 'legacy services.yml');
76
- return isPlainObject(parsed.services) ? parsed.services : parsed;
77
- }
78
-
79
- function parseServicesManifestYaml(content) {
80
- const manifest = parseYamlDocument(content, 'services/manifest.yml');
81
- if (!isPlainObject(manifest.services)) manifest.services = {};
82
- return manifest;
83
- }
84
-
85
- function parseProjectsYaml(content) {
86
- const registry = parseYamlDocument(content, 'projects/manifest.yml');
87
- if (!isPlainObject(registry.projects)) registry.projects = {};
88
- return registry;
89
- }
90
-
91
- function renderProjectsYaml(registry) {
92
- const projects = registry.projects || {};
93
- const names = Object.keys(projects).sort();
94
- const lines = ['schemaVersion: buildr.projects/v1'];
95
- if (names.length === 0) {
96
- lines.push('projects: {}');
97
- return `${lines.join('\n')}\n`;
98
- }
99
-
100
- lines.push('projects:');
101
- for (const name of names) {
102
- const project = projects[name];
103
- lines.push(` ${name}:`);
104
- for (const key of ['title', 'description', 'path']) {
105
- if (project[key] !== undefined) lines.push(` ${key}: ${quoteYaml(project[key])}`);
106
- }
107
- if (project.repo) {
108
- lines.push(' repo:');
109
- for (const key of ['kind', 'url', 'remote', 'defaultBranch']) {
110
- if (project.repo[key] !== undefined) lines.push(` ${key}: ${quoteYaml(project.repo[key])}`);
111
- }
112
- }
113
- }
114
- return `${lines.join('\n')}\n`;
115
- }
116
-
117
- function validateProjectsRegistry(registry) {
118
- const errors = [];
119
- if (String(registry.schemaVersion) !== 'buildr.projects/v1') {
120
- errors.push('projects/manifest.yml schemaVersion must be buildr.projects/v1.');
121
- }
122
- if (!isPlainObject(registry.projects)) {
123
- errors.push('projects/manifest.yml projects must be an object.');
124
- return errors;
125
- }
126
-
127
- for (const [projectName, project] of Object.entries(registry.projects)) {
128
- const label = `projects.${projectName}`;
129
- if (!isValidAssetId(projectName)) {
130
- errors.push(`${label} key must contain only letters, digits, dots, underscores, or dashes.`);
131
- }
132
- if (!isPlainObject(project)) {
133
- errors.push(`${label} must be an object.`);
134
- continue;
135
- }
136
- const allowedKeys = new Set(['title', 'description', 'path', 'repo']);
137
- for (const key of Object.keys(project)) {
138
- if (!allowedKeys.has(key)) errors.push(`${label}.${key} is not a supported projects/manifest.yml field.`);
139
- }
140
- if (!project.title || typeof project.title !== 'string') {
141
- errors.push(`${label}.title is required.`);
142
- }
143
- if (!project.description || typeof project.description !== 'string') {
144
- errors.push(`${label}.description is required.`);
145
- }
146
- if (project.path !== `projects/${projectName}`) {
147
- errors.push(`${label}.path must be projects/${projectName}.`);
148
- }
149
- if (!isPlainObject(project.repo)) {
150
- errors.push(`${label}.repo is required.`);
151
- continue;
152
- }
153
- const allowedRepoKeys = new Set(['kind', 'url', 'remote', 'defaultBranch']);
154
- for (const key of Object.keys(project.repo)) {
155
- if (!allowedRepoKeys.has(key)) errors.push(`${label}.repo.${key} is not a supported repo field.`);
156
- }
157
- if (!['workspace', 'git'].includes(project.repo.kind)) {
158
- errors.push(`${label}.repo.kind must be workspace or git.`);
159
- }
160
- if (project.repo.kind === 'workspace') {
161
- for (const key of ['url', 'remote', 'defaultBranch']) {
162
- if (project.repo[key] !== undefined) errors.push(`${label}.repo.${key} is only supported for git-managed Projects.`);
163
- }
164
- }
165
- if (project.repo.kind === 'git') {
166
- if (project.repo.url !== undefined && typeof project.repo.url !== 'string') errors.push(`${label}.repo.url must be a string when provided.`);
167
- if (project.repo.remote !== undefined && typeof project.repo.remote !== 'string') errors.push(`${label}.repo.remote must be a string when provided.`);
168
- if (project.repo.defaultBranch !== undefined && typeof project.repo.defaultBranch !== 'string') errors.push(`${label}.repo.defaultBranch must be a string when provided.`);
169
- }
170
- }
171
-
172
- return errors;
173
- }
174
-
175
- function renderServicesManifestYaml(manifest) {
176
- const services = manifest.services || {};
177
- const names = Object.keys(services).sort();
178
- const lines = ['schemaVersion: buildr.services/v1', `project: ${quoteYaml(manifest.project)}`];
179
- if (names.length === 0) {
180
- lines.push('services: {}');
181
- return `${lines.join('\n')}\n`;
182
- }
183
-
184
- lines.push('services:');
185
- for (const name of names) {
186
- const service = services[name];
187
- lines.push(` ${name}:`);
188
- for (const key of ['title', 'description', 'type', 'path']) {
189
- if (service[key] !== undefined) lines.push(` ${key}: ${quoteYaml(service[key])}`);
190
- }
191
- if (service.repo) {
192
- lines.push(' repo:');
193
- for (const key of ['kind', 'url', 'remote', 'defaultBranch', 'branch']) {
194
- if (service.repo[key] !== undefined) lines.push(` ${key}: ${quoteYaml(service.repo[key])}`);
195
- }
196
- }
197
- }
198
- return `${lines.join('\n')}\n`;
199
- }
200
-
201
- function validateServicesManifest(manifest, expectedProject) {
202
- const errors = [];
203
- if (manifest.schemaVersion !== 'buildr.services/v1') {
204
- errors.push('services/manifest.yml schemaVersion must be buildr.services/v1.');
205
- }
206
- if (manifest.project !== expectedProject) {
207
- errors.push(`services/manifest.yml project must be ${expectedProject}.`);
208
- }
209
- if (!isPlainObject(manifest.services)) {
210
- errors.push('services/manifest.yml services must be an object.');
211
- return errors;
212
- }
213
- for (const [serviceName, service] of Object.entries(manifest.services)) {
214
- const label = `services.${serviceName}`;
215
- if (!isValidAssetId(serviceName)) {
216
- errors.push(`${label} key must contain only letters, digits, dots, underscores, or dashes.`);
217
- }
218
- if (!isPlainObject(service)) {
219
- errors.push(`${label} must be an object.`);
220
- continue;
221
- }
222
- const allowedKeys = new Set(['title', 'description', 'type', 'path', 'repo']);
223
- for (const key of Object.keys(service)) {
224
- if (!allowedKeys.has(key)) errors.push(`${label}.${key} is not a supported services/manifest.yml field.`);
225
- }
226
- if (!service.title || typeof service.title !== 'string') errors.push(`${label}.title is required.`);
227
- if (!service.description || typeof service.description !== 'string') errors.push(`${label}.description is required.`);
228
- if (!service.type || typeof service.type !== 'string') errors.push(`${label}.type is required.`);
229
- if (service.path !== `services/${serviceName}`) errors.push(`${label}.path must be services/${serviceName}.`);
230
- if (!isPlainObject(service.repo)) {
231
- errors.push(`${label}.repo is required.`);
232
- continue;
233
- }
234
- const allowedRepoKeys = new Set(['kind', 'url', 'remote', 'defaultBranch', 'branch']);
235
- for (const key of Object.keys(service.repo)) {
236
- if (!allowedRepoKeys.has(key)) errors.push(`${label}.repo.${key} is not a supported repo field.`);
237
- }
238
- if (!['workspace', 'git'].includes(service.repo.kind)) errors.push(`${label}.repo.kind must be workspace or git.`);
239
- if (service.repo.kind === 'workspace') {
240
- for (const key of ['url', 'remote', 'defaultBranch', 'branch']) {
241
- if (service.repo[key] !== undefined) errors.push(`${label}.repo.${key} is only supported for git-managed Services.`);
242
- }
243
- }
244
- if (service.repo.kind === 'git') {
245
- if (service.repo.url !== undefined && typeof service.repo.url !== 'string') errors.push(`${label}.repo.url must be a string when provided.`);
246
- if (service.repo.remote !== undefined && typeof service.repo.remote !== 'string') errors.push(`${label}.repo.remote must be a string when provided.`);
247
- if (service.repo.defaultBranch !== undefined && typeof service.repo.defaultBranch !== 'string') errors.push(`${label}.repo.defaultBranch must be a string when provided.`);
248
- if (service.repo.branch !== undefined && (typeof service.repo.branch !== 'string' || !service.repo.branch)) errors.push(`${label}.repo.branch must be a non-empty string when provided.`);
249
- }
250
- }
251
- return errors;
252
- }
253
-
254
- function readProjectsRegistryForWrite(targetRoot) {
255
- const file = projectsManifestPath(targetRoot);
256
- if (!existsFile(file)) return { schemaVersion: 'buildr.projects/v1', projects: {} };
257
- const registry = parseProjectsYaml(fs.readFileSync(file, 'utf8'));
258
- const errors = validateProjectsRegistry(registry)
259
- .filter((message) => !message.endsWith('.title is required.'))
260
- .filter((message) => !message.endsWith('.description is required.'));
261
- if (errors.length > 0) {
262
- throw new Error(`projects/manifest.yml is invalid:\n- ${errors.join('\n- ')}`);
263
- }
264
- return registry;
265
- }
266
-
267
- function writeProjectsRegistry(targetRoot, registry) {
268
- const file = projectsManifestPath(targetRoot);
269
- atomicWriteFile(file, renderProjectsYaml(registry));
270
- return file;
271
- }
272
-
273
- function projectsManifestPath(targetRoot) {
274
- return path.join(targetRoot, 'projects', 'manifest.yml');
275
- }
276
-
277
- function servicesManifestPath(projectRoot) {
278
- return path.join(projectRoot, 'services', 'manifest.yml');
279
- }
280
-
281
- function readServicesManifestForWrite(projectRoot, projectName) {
282
- const file = servicesManifestPath(projectRoot);
283
- if (!existsFile(file)) return { schemaVersion: 'buildr.services/v1', project: projectName, services: {} };
284
- const manifest = parseServicesManifestYaml(fs.readFileSync(file, 'utf8'));
285
- const errors = validateServicesManifest(manifest, projectName)
286
- .filter((message) => !message.endsWith('.title is required.'))
287
- .filter((message) => !message.endsWith('.description is required.'))
288
- .filter((message) => !message.endsWith('.type is required.'));
289
- if (errors.length > 0) {
290
- throw new Error(`services/manifest.yml is invalid:\n- ${errors.join('\n- ')}`);
291
- }
292
- return manifest;
293
- }
294
-
295
- function writeServicesManifest(projectRoot, manifest) {
296
- const file = servicesManifestPath(projectRoot);
297
- atomicWriteFile(file, renderServicesManifestYaml(manifest));
298
- return file;
299
- }
300
-
301
- function updateServicesManifest(projectRoot, projectName, serviceName, metadata) {
302
- const manifest = readServicesManifestForWrite(projectRoot, projectName);
303
- manifest.schemaVersion = 'buildr.services/v1';
304
- manifest.project = projectName;
305
- manifest.services[serviceName] = metadata;
306
- return writeServicesManifest(projectRoot, manifest);
307
- }
308
-
309
- function gitOutput(args, cwd) {
310
- return execFileSync('git', args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
311
- }
312
-
313
- function gitCurrentBranch(repoPath) {
314
- try {
315
- const branch = gitOutput(['symbolic-ref', '--short', 'HEAD'], repoPath);
316
- return branch || 'HEAD';
317
- } catch {
318
- return 'HEAD';
319
- }
320
- }
321
-
322
- function gitDefaultBranch(repoPath, remote = 'origin') {
323
- const remoteUrl = readGitRemote(repoPath, remote);
324
- if (remoteUrl) {
325
- const result = spawnSync('git', ['ls-remote', '--symref', remoteUrl, 'HEAD'], {
326
- cwd: repoPath,
327
- encoding: 'utf8',
328
- timeout: 30000,
329
- });
330
- if (result.status === 0) {
331
- const match = result.stdout.match(/^ref:\s+refs\/heads\/(.+)\s+HEAD$/m);
332
- if (match) return match[1];
333
- }
334
- }
335
- try {
336
- const reference = gitOutput(['symbolic-ref', '--short', `refs/remotes/${remote}/HEAD`], repoPath);
337
- return reference.startsWith(`${remote}/`) ? reference.slice(remote.length + 1) : reference;
338
- } catch {
339
- return gitCurrentBranch(repoPath);
340
- }
341
- }
342
-
343
- function assertGitBranch(value) {
344
- if (!value) return;
345
- const result = spawnSync('git', ['check-ref-format', '--branch', value], { encoding: 'utf8' });
346
- if (result.status !== 0) throw new Error(`Invalid Git branch: ${value}`);
347
- }
348
-
349
- function defaultAssetDescription(kind, id) {
350
- return `TODO: 补充 ${kind} ${id} 的用途说明。`;
351
- }
352
-
353
- function inferRepoKind(assetRoot) {
354
- return existsDirectory(path.join(assetRoot, '.git')) ? 'git' : 'workspace';
355
- }
356
-
357
- function ensureIgnoreEntry(repoRoot, pattern) {
358
- const changed = appendGitignoreEntries(path.join(repoRoot, '.gitignore'), [pattern]);
359
- return changed ? toPosixRelative(process.cwd(), path.join(repoRoot, '.gitignore')) : null;
360
- }
361
-
362
- function gitBoundaryFor(targetRoot, item) {
363
- if (!existsDirectory(path.join(item.assetRoot, '.git'))) return null;
364
- const projectRoot = path.join(targetRoot, 'projects', item.project);
365
- if (item.type === 'project') {
366
- if (existsDirectory(path.join(targetRoot, '.git'))) {
367
- return { repoRoot: targetRoot, pattern: `/projects/${item.project}/` };
368
- }
369
- return null;
370
- }
371
- if (existsDirectory(path.join(projectRoot, '.git'))) {
372
- return { repoRoot: projectRoot, pattern: `/services/${item.service}/` };
373
- }
374
- if (existsDirectory(path.join(targetRoot, '.git'))) {
375
- return { repoRoot: targetRoot, pattern: `/projects/${item.project}/services/${item.service}/` };
376
- }
377
- return null;
378
- }
379
-
380
- function ensureGitBoundaries(targetRoot, items) {
381
- const changed = [];
382
- for (const item of items) {
383
- const boundary = gitBoundaryFor(targetRoot, item);
384
- if (!boundary) continue;
385
- const updated = ensureIgnoreEntry(boundary.repoRoot, boundary.pattern);
386
- if (updated) changed.push(toPosixRelative(targetRoot, path.join(boundary.repoRoot, '.gitignore')));
387
- }
388
- return [...new Set(changed)];
389
- }
390
-
391
- function gitBoundaryIgnored(boundary) {
392
- if (!boundary) return true;
393
- const lines = gitignoreLines(boundary.repoRoot);
394
- return lines.includes(boundary.pattern);
395
- }
396
-
397
- function trackWrite(targetRoot, file, content, created) {
398
- if (writeIfMissing(file, content)) {
399
- created.push(path.relative(targetRoot, file).split(path.sep).join('/'));
400
- }
401
- }
402
-
403
- function printResult(title, targetRoot, created, changed = []) {
404
- console.log(title);
405
- if (created.length > 0) {
406
- console.log('Created:');
407
- for (const file of created) console.log(` ${file}`);
408
- }
409
- if (changed.length > 0) {
410
- console.log('Updated:');
411
- for (const file of changed) console.log(` ${file}`);
412
- }
413
- }
414
-
415
- function displayScope(scope) {
416
- return scope === '.' ? 'root (.)' : scope;
417
- }
418
-
419
- function createProject(args) {
420
- const allowedFlags = new Set(['--target', '--repo', '--title', '--description']);
421
- assertNoUnknownOptions(args, allowedFlags);
422
- const ref = positionalArgs(args)[0];
423
- if (!ref) throw new Error('Missing project ref');
424
- const { project } = parseProjectRef(ref);
425
- const targetRoot = path.resolve(optionValue(args, '--target', process.cwd()));
426
- const repoRef = optionValue(args, '--repo', null);
427
- const titleOption = optionValue(args, '--title', null);
428
- const descriptionOption = optionValue(args, '--description', null);
429
- const projectRoot = path.join(targetRoot, 'projects', project);
430
- const created = [];
431
- const changed = [];
432
- const manifest = readPackageManifest();
433
- const registry = readProjectsRegistryForWrite(targetRoot);
434
- const existingEntry = registry.projects[project] || null;
435
- const title = titleOption ?? existingEntry?.title ?? project;
436
- const description = descriptionOption ?? existingEntry?.description ?? defaultAssetDescription('Project', project);
437
-
438
- if (repoRef && !isProjectGitUrl(repoRef)) {
439
- throw new Error(`Project --repo only supports Git URLs. Project assets must be materialized under projects/${project}; external local Project links are not supported.`);
440
- }
441
- if (repoRef && existsDirectory(projectRoot) && !existsDirectory(path.join(projectRoot, '.git'))) {
442
- throw new Error(`Project repo target exists but is not a Git repository: projects/${project}`);
443
- }
444
- if (repoRef && existsDirectory(projectRoot)) {
445
- const actualUrl = readGitRemote(projectRoot, 'origin');
446
- if (!actualUrl || !sameGitIdentity(actualUrl, repoRef)) {
447
- throw new Error(`Project repo identity conflicts for ${project}: expected ${repoRef}, actual ${actualUrl || '<missing origin>'}. Buildr will not relink an existing Project.`);
448
- }
449
- if (existingEntry?.repo?.kind && existingEntry.repo.kind !== 'git') {
450
- throw new Error(`Project registry identity conflicts for ${project}: existing repo.kind is ${existingEntry.repo.kind}, requested git.`);
451
- }
452
- if (existingEntry?.repo?.url && !sameGitIdentity(existingEntry.repo.url, repoRef)) {
453
- throw new Error(`Project registry URL conflicts for ${project}: expected ${repoRef}, recorded ${existingEntry.repo.url}.`);
454
- }
455
- }
456
- if (!repoRef && existingEntry?.repo?.kind === 'git' && !existsDirectory(path.join(projectRoot, '.git'))) {
457
- throw new Error(`Project registry expects a Git repo but materialized Project is not Git-managed: ${project}`);
458
- }
459
-
460
- const affected = [projectRoot, projectsManifestPath(targetRoot), path.join(targetRoot, '.gitignore')];
461
- return withWorkspaceMutation(targetRoot, `project.create:${project}`, affected, () => {
462
- const staging = path.join(path.dirname(projectRoot), `.${project}.buildr-stage-${crypto.randomUUID()}`);
463
- try {
464
- if (repoRef && !existsDirectory(projectRoot)) {
465
- execFileSync('git', ['clone', repoRef, staging], { stdio: 'inherit' });
466
- fs.renameSync(staging, projectRoot);
467
- }
468
- ensureDirectory(projectRoot);
469
- for (const relativeDir of manifest.projectDirectories) ensureDirectory(path.join(projectRoot, relativeDir));
470
- const variables = { project };
471
- for (const rawEntry of manifest.projectFiles) {
472
- const entry = parseManifestFileEntry(rawEntry, 'projectFiles');
473
- writeMappedFileIfMissing(targetRoot, projectRoot, entry, variables, created);
474
- }
475
- trackWrite(targetRoot, path.join(projectRoot, 'skills', 'manifest.yml'), renderSkillsManifestYaml([]), created);
476
- trackWrite(targetRoot, servicesManifestPath(projectRoot), renderServicesManifestYaml({ schemaVersion: 'buildr.services/v1', project, services: {} }), created);
477
-
478
- const repoMetadata = repoRef ? { kind: 'git', url: repoRef, remote: 'origin', defaultBranch: gitDefaultBranch(projectRoot) }
479
- : existingEntry?.repo?.kind === 'git' ? existingEntry.repo : { kind: 'workspace' };
480
- registry.projects[project] = { title, description, path: `projects/${project}`, repo: repoMetadata };
481
- const registryPath = writeProjectsRegistry(targetRoot, registry);
482
- changed.push(toPosixRelative(targetRoot, registryPath));
483
- changed.push(...ensureGitBoundaries(targetRoot, [{ type: 'project', project, assetRoot: projectRoot }]));
484
- printResult(`Created project ${project}`, targetRoot, created, changed);
485
- } finally {
486
- if (fs.existsSync(staging)) fs.rmSync(staging, { recursive: true, force: true });
487
- }
488
- });
489
- }
490
-
491
- function createService(args) {
492
- assertNoUnknownOptions(args, new Set(['--target', '--type', '--rules', '--branch']));
493
- const ref = args[0];
494
- const repoRef = args[1];
495
- if (!ref) throw new Error('Missing service ref');
496
- if (!repoRef) throw new Error('Missing repo ref');
497
-
498
- const { project, service } = parseServiceRef(ref);
499
- const targetRoot = path.resolve(optionValue(args, '--target', process.cwd()));
500
- const serviceType = optionValue(args, '--type', null);
501
- const rulesSource = optionValue(args, '--rules', null);
502
- const branchInput = optionValue(args, '--branch', null);
503
- assertGitBranch(branchInput);
504
- const projectRoot = path.join(targetRoot, 'projects', project);
505
- const servicesRoot = path.join(projectRoot, 'services');
506
- const servicePath = path.join(servicesRoot, service);
507
- const changed = [];
508
-
509
- if (!fs.existsSync(projectRoot)) {
510
- createProject([project, '--target', targetRoot]);
511
- }
512
-
513
- const gitSource = isGitUrl(repoRef);
514
- const existingManifest = readServicesManifestForWrite(projectRoot, project);
515
- const existingEntry = existingManifest.services[service] || null;
516
- if (branchInput && !gitSource) throw new Error('--branch is only supported for Git Service sources.');
517
- if (branchInput && existingEntry?.repo?.branch && existingEntry.repo.branch !== branchInput) {
518
- throw new Error(`Service branch intent conflicts for ${project}/${service}: requested ${branchInput}, recorded ${existingEntry.repo.branch}.`);
519
- }
520
- const requestedBranch = branchInput || existingEntry?.repo?.branch || null;
521
- if (gitSource && existsDirectory(servicePath)) {
522
- if (!existsDirectory(path.join(servicePath, '.git'))) throw new Error(`Service Git target exists but is not a Git repository: projects/${project}/services/${service}`);
523
- const actualUrl = readGitRemote(servicePath, 'origin');
524
- if (!actualUrl || !sameGitIdentity(actualUrl, repoRef)) throw new Error(`Service repo identity conflicts for ${project}/${service}: expected ${repoRef}, actual ${actualUrl || '<missing origin>'}.`);
525
- if (existingEntry?.repo?.kind && existingEntry.repo.kind !== 'git') throw new Error(`Service metadata identity conflicts for ${project}/${service}: existing repo.kind is ${existingEntry.repo.kind}, requested git.`);
526
- if (existingEntry?.repo?.url && !sameGitIdentity(existingEntry.repo.url, repoRef)) throw new Error(`Service metadata URL conflicts for ${project}/${service}: expected ${repoRef}, recorded ${existingEntry.repo.url}.`);
527
- const actualBranch = gitCurrentBranch(servicePath);
528
- if (requestedBranch && actualBranch !== requestedBranch) throw new Error(`Service branch conflicts for ${project}/${service}: expected ${requestedBranch}, actual ${actualBranch}.`);
529
- }
530
- const localPath = gitSource ? null : path.resolve(repoRef);
531
- if (!gitSource && !fs.existsSync(localPath)) throw new Error(`Local service source path does not exist: ${repoRef}`);
532
- if (!gitSource && fs.existsSync(servicePath)) throw new Error(`Service target already exists: projects/${project}/services/${service}`);
533
-
534
- const affected = [servicePath, servicesManifestPath(projectRoot), path.join(projectRoot, '.gitignore'), path.join(targetRoot, '.gitignore')];
535
- return withWorkspaceMutation(targetRoot, `service.create:${project}/${service}`, affected, () => {
536
- ensureDirectory(servicesRoot);
537
- const staging = path.join(servicesRoot, `.${service}.buildr-stage-${crypto.randomUUID()}`);
538
- try {
539
- if (!fs.existsSync(servicePath)) {
540
- if (gitSource) {
541
- const cloneArgs = ['clone'];
542
- if (requestedBranch) cloneArgs.push('--branch', requestedBranch, '--single-branch');
543
- cloneArgs.push(repoRef, staging);
544
- execFileSync('git', cloneArgs, { stdio: 'inherit' });
545
- }
546
- else fs.cpSync(localPath, staging, { recursive: true });
547
- fs.renameSync(staging, servicePath);
548
- }
549
- const repo = gitSource ? { kind: 'git', url: repoRef, remote: 'origin', defaultBranch: gitDefaultBranch(servicePath) } : { kind: inferRepoKind(servicePath) };
550
- if (gitSource && requestedBranch) repo.branch = requestedBranch;
551
- if (repo.kind === 'git' && !gitSource) {
552
- repo.remote = 'origin';
553
- repo.defaultBranch = gitDefaultBranch(servicePath);
554
- const url = readGitRemote(servicePath, 'origin');
555
- if (url) repo.url = url;
556
- }
557
- const metadata = { title: service, description: defaultAssetDescription('Service', service), type: serviceType || 'service', path: `services/${service}`, repo };
558
- if (rulesSource) console.error('Warning: --rules is deprecated. Service AGENTS.md is treated as the service rule asset and is not recorded in services/manifest.yml.');
559
- const metadataPath = updateServicesManifest(projectRoot, project, service, metadata);
560
- changed.push(path.relative(targetRoot, metadataPath).split(path.sep).join('/'));
561
- for (const file of ensureGitBoundaries(targetRoot, [{ type: 'service', project, service, assetRoot: servicePath }])) changed.push(file);
562
- printResult(`Created service ${project}/${service}`, targetRoot, [], changed);
563
- } finally {
564
- if (fs.existsSync(staging)) fs.rmSync(staging, { recursive: true, force: true });
565
- }
566
- });
567
- }
568
-
569
- Object.assign(runtime, { parseProjectRef, parseServiceRef, isGitUrl, isProjectGitUrl, quoteYaml, parseYamlValue, parseServicesYaml, parseServicesManifestYaml, parseProjectsYaml, renderProjectsYaml, validateProjectsRegistry, renderServicesManifestYaml, validateServicesManifest, readProjectsRegistryForWrite, writeProjectsRegistry, projectsManifestPath, servicesManifestPath, readServicesManifestForWrite, writeServicesManifest, updateServicesManifest, gitOutput, gitCurrentBranch, gitDefaultBranch, assertGitBranch, defaultAssetDescription, inferRepoKind, ensureIgnoreEntry, gitBoundaryFor, ensureGitBoundaries, gitBoundaryIgnored, trackWrite, printResult, displayScope, createProject, createService });
570
- return runtime;
571
- }