@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,380 +0,0 @@
1
- import { fs, path, process } from '../shared/platform.mjs';
2
-
3
- export function registerDomainsRules(runtime) {
4
- const doctor = (...args) => runtime.doctor(...args);
5
- const isPlainObject = (...args) => runtime.isPlainObject(...args);
6
- const assertNoUnknownOptions = (...args) => runtime.assertNoUnknownOptions(...args);
7
- const positionalArgs = (...args) => runtime.positionalArgs(...args);
8
- const componentOwnerForMember = (...args) => runtime.componentOwnerForMember(...args);
9
- const isValidAssetId = (...args) => runtime.isValidAssetId(...args);
10
- const assertName = (...args) => runtime.assertName(...args);
11
- const normalizeRelativePathForBuildr = (...args) => runtime.normalizeRelativePathForBuildr(...args);
12
- const quoteYaml = (...args) => runtime.quoteYaml(...args);
13
- const optionValue = (...args) => runtime.optionValue(...args);
14
- const atomicWriteFile = (...args) => runtime.atomicWriteFile(...args);
15
- const parseYamlDocument = (...args) => runtime.parseYamlDocument(...args);
16
- const assertSafeAssetTarget = (...args) => runtime.assertSafeAssetTarget(...args);
17
- const withWorkspaceMutation = (...args) => runtime.withWorkspaceMutation(...args);
18
- const hasFlag = (...args) => runtime.hasFlag(...args);
19
- const toPosixRelative = (...args) => runtime.toPosixRelative(...args);
20
- const existsDirectory = (...args) => runtime.existsDirectory(...args);
21
- const existsFile = (...args) => runtime.existsFile(...args);
22
- const rootRequiredBlockStatus = (...args) => runtime.rootRequiredBlockStatus(...args);
23
- const assertInitializedBuildrWorkspace = (...args) => runtime.assertInitializedBuildrWorkspace(...args);
24
- const addDoctorFinding = (...args) => runtime.addDoctorFinding(...args);
25
-
26
- function rulesManifestPath(scopeRoot) {
27
- return path.join(scopeRoot, 'rules', 'manifest.yml');
28
- }
29
-
30
- function parseRulesManifestYaml(content) {
31
- const manifest = parseYamlDocument(content, 'rules/manifest.yml');
32
- return manifest;
33
- }
34
-
35
- function renderRulesManifestYaml(manifest) {
36
- const lines = ['schemaVersion: buildr.rules/v1'];
37
- if (!manifest.rules || manifest.rules.length === 0) {
38
- lines.push('rules: []');
39
- return `${lines.join('\n')}\n`;
40
- }
41
- lines.push('rules:');
42
- for (const rule of manifest.rules) {
43
- lines.push(` - id: ${quoteYaml(rule.id)}`);
44
- for (const key of ['source', 'path', 'description']) {
45
- if (rule[key] !== undefined) lines.push(` ${key}: ${quoteYaml(rule[key])}`);
46
- }
47
- if (rule.enabled !== undefined) lines.push(` enabled: ${quoteYaml(Boolean(rule.enabled))}`);
48
- if (rule.required !== undefined) lines.push(` required: ${quoteYaml(Boolean(rule.required))}`);
49
- for (const key of ['state', 'reason']) {
50
- if (rule[key] !== undefined) lines.push(` ${key}: ${quoteYaml(rule[key])}`);
51
- }
52
- }
53
- return `${lines.join('\n')}\n`;
54
- }
55
-
56
- function validateRulesManifest(manifest) {
57
- const errors = [];
58
- if (manifest.schemaVersion !== 'buildr.rules/v1') {
59
- errors.push('rules manifest schemaVersion must be buildr.rules/v1.');
60
- }
61
- if (!Array.isArray(manifest.rules)) {
62
- errors.push('rules manifest must declare rules as an array.');
63
- return errors;
64
- }
65
- const ids = new Set();
66
- const allowedKeys = new Set(['id', 'source', 'path', 'description', 'enabled', 'required', 'state', 'reason']);
67
- for (const [index, rule] of manifest.rules.entries()) {
68
- const label = `rules[${index}]`;
69
- if (!isPlainObject(rule)) {
70
- errors.push(`${label} must be an object.`);
71
- continue;
72
- }
73
- for (const key of Object.keys(rule)) {
74
- if (!allowedKeys.has(key)) errors.push(`${label}.${key} is not a supported rules manifest field.`);
75
- }
76
- if (!isValidAssetId(rule.id)) {
77
- errors.push(`${label}.id must contain only letters, digits, dots, underscores, or dashes.`);
78
- } else if (ids.has(rule.id)) {
79
- errors.push(`Duplicate rule id: ${rule.id}.`);
80
- } else {
81
- ids.add(rule.id);
82
- }
83
- if (!['buildr', 'workspace', 'project', 'service'].includes(rule.source)) {
84
- errors.push(`${label}.source must be buildr, workspace, project, or service.`);
85
- }
86
- if (!rule.path || typeof rule.path !== 'string') {
87
- errors.push(`${label}.path is required.`);
88
- } else {
89
- normalizeRelativePathForBuildr(rule.path, `${label}.path must stay relative: ${rule.path}`);
90
- if (!rule.path.endsWith('.md')) errors.push(`${label}.path must point to a Markdown file.`);
91
- }
92
- if (!rule.description || typeof rule.description !== 'string') {
93
- errors.push(`${label}.description is required and must describe when to read the rule.`);
94
- }
95
- if (rule.enabled !== undefined && typeof rule.enabled !== 'boolean') {
96
- errors.push(`${label}.enabled must be a boolean.`);
97
- }
98
- if (rule.required !== undefined && typeof rule.required !== 'boolean') {
99
- errors.push(`${label}.required must be a boolean.`);
100
- }
101
- if (rule.state !== undefined && !['installed', 'modified', 'uninstalled', 'missing'].includes(rule.state)) {
102
- errors.push(`${label}.state must be installed, modified, uninstalled, or missing.`);
103
- }
104
- }
105
- return errors;
106
- }
107
-
108
- function readRulesManifestForWrite(scopeRoot) {
109
- const manifestPath = rulesManifestPath(scopeRoot);
110
- if (!existsFile(manifestPath)) return { schemaVersion: 'buildr.rules/v1', rules: [] };
111
- const manifest = parseRulesManifestYaml(fs.readFileSync(manifestPath, 'utf8'));
112
- const validationErrors = validateRulesManifest(manifest);
113
- if (validationErrors.length > 0) {
114
- throw new Error(`rules/manifest.yml is invalid:\n- ${validationErrors.join('\n- ')}`);
115
- }
116
- return manifest;
117
- }
118
-
119
- function writeRulesManifest(scopeRoot, manifest) {
120
- const manifestPath = rulesManifestPath(scopeRoot);
121
- atomicWriteFile(manifestPath, renderRulesManifestYaml(manifest), 'utf8');
122
- return manifestPath;
123
- }
124
-
125
- function resolveRootRulesScope(args) {
126
- const scope = optionValue(args, '--scope', '.');
127
- if (scope !== '.') {
128
- throw new Error(`rules add/remove currently support only root scope ".". Project rules are maintained through projects/<project>/AGENTS.md: ${scope}`);
129
- }
130
- }
131
-
132
- function normalizeRootRulePath(targetRoot, rulePath) {
133
- const normalized = normalizeRelativePathForBuildr(rulePath, `Rule path must stay relative: ${rulePath}`).split(path.sep).join('/');
134
- if (!normalized.startsWith('rules/')) {
135
- throw new Error(`Rule path must be under rules/: ${normalized}`);
136
- }
137
- if (normalized === 'rules/manifest.yml') {
138
- throw new Error('Rule path must point to a Markdown rule file, not rules/manifest.yml.');
139
- }
140
- if (normalized.startsWith('rules/buildr/')) {
141
- throw new Error('rules/buildr/ is reserved for Buildr-managed Rules. Use a user-managed path under rules/.');
142
- }
143
- const absolute = path.resolve(targetRoot, normalized);
144
- const relative = path.relative(targetRoot, absolute);
145
- if (!relative || relative.startsWith('..') || path.isAbsolute(relative)) {
146
- throw new Error(`Rule path must stay inside workspace: ${normalized}`);
147
- }
148
- if (!normalized.endsWith('.md')) {
149
- throw new Error(`Rule path must point to a Markdown file: ${normalized}`);
150
- }
151
- return normalized;
152
- }
153
-
154
- function buildRuleEntry(id, args, targetRoot) {
155
- assertName(id, 'Rule id');
156
- const description = optionValue(args, '--description', null);
157
- if (!description) throw new Error('Missing required option: --description');
158
- const rulePath = normalizeRootRulePath(targetRoot, optionValue(args, '--path', `rules/${id}.md`));
159
- if (!existsFile(path.join(targetRoot, rulePath))) {
160
- throw new Error(`rules add registers an existing root Rule file. Create the file first: ${rulePath}`);
161
- }
162
- const entry = {
163
- id,
164
- source: 'workspace',
165
- path: rulePath,
166
- description,
167
- enabled: true,
168
- required: false,
169
- state: 'installed',
170
- };
171
- const errors = validateRulesManifest({ schemaVersion: 'buildr.rules/v1', rules: [entry] });
172
- if (errors.length > 0) throw new Error(errors.join('\n'));
173
- return entry;
174
- }
175
-
176
- function printRulesMutationReceipt(action, targetRoot, id, updatedPaths, nextAction) {
177
- console.log(`已${action}规则资产:${id}`);
178
- console.log('已更新 Buildr 源资产:');
179
- for (const file of updatedPaths) console.log(` ${toPosixRelative(targetRoot, file)}`);
180
- console.log('下一步:');
181
- console.log(` ${nextAction}`);
182
- }
183
-
184
- function rulesAddUnsafe(args) {
185
- const allowedFlags = new Set(['--target', '--scope', '--path', '--description', '--replace']);
186
- assertNoUnknownOptions(args, allowedFlags, new Set(['--replace']));
187
- resolveRootRulesScope(args);
188
- const [id] = positionalArgs(args);
189
- if (!id) throw new Error('Missing rule id');
190
- const targetRoot = path.resolve(optionValue(args, '--target', process.cwd()));
191
- assertInitializedBuildrWorkspace(targetRoot);
192
-
193
- const manifest = readRulesManifestForWrite(targetRoot);
194
- const entry = buildRuleEntry(id, args, targetRoot);
195
- const replace = hasFlag(args, '--replace');
196
- const existingIndex = manifest.rules.findIndex((rule) => rule.id === id);
197
- if (existingIndex !== -1 && !replace) {
198
- throw new Error(`Rule already exists in rules/manifest.yml: ${id}. Use --replace to replace the whole entry.`);
199
- }
200
- if (existingIndex === -1) {
201
- manifest.rules.push(entry);
202
- } else {
203
- const existing = manifest.rules[existingIndex];
204
- if (existing.source === 'buildr' && existing.required === true) {
205
- throw new Error(`Required Buildr Rule cannot be replaced through rules add: ${id}`);
206
- }
207
- manifest.rules[existingIndex] = entry;
208
- }
209
-
210
- const manifestPath = writeRulesManifest(targetRoot, manifest);
211
- printRulesMutationReceipt(
212
- existingIndex === -1 ? '添加' : '替换',
213
- targetRoot,
214
- id,
215
- [manifestPath],
216
- '运行 buildr doctor --agent <agent> --target <dir> --json 复查;需要 Agent runtime 投射时再按当前 adapter 执行 rules render、runtime check 或 sync。'
217
- );
218
- }
219
-
220
- function rulesAdd(args) {
221
- const targetRoot = path.resolve(optionValue(args, '--target', process.cwd()));
222
- return withWorkspaceMutation(targetRoot, 'rules.add', [path.join(targetRoot, 'rules')], () => rulesAddUnsafe(args));
223
- }
224
-
225
- function rulesRemoveUnsafe(args) {
226
- const allowedFlags = new Set(['--target', '--scope', '--keep-file']);
227
- assertNoUnknownOptions(args, allowedFlags, new Set(['--keep-file']));
228
- resolveRootRulesScope(args);
229
- const [id] = positionalArgs(args);
230
- if (!id) throw new Error('Missing rule id');
231
- assertName(id, 'Rule id');
232
- const targetRoot = path.resolve(optionValue(args, '--target', process.cwd()));
233
- assertInitializedBuildrWorkspace(targetRoot);
234
-
235
- const manifest = readRulesManifestForWrite(targetRoot);
236
- const existingIndex = manifest.rules.findIndex((rule) => rule.id === id);
237
- if (existingIndex === -1) {
238
- throw new Error(`Rule not found in rules/manifest.yml: ${id}`);
239
- }
240
- const removed = manifest.rules[existingIndex];
241
- const owner = componentOwnerForMember(targetRoot, removed.path);
242
- if (owner) throw new Error(`Rule is managed by Component ${owner}: ${removed.path}. Use buildr component lifecycle commands.`);
243
- manifest.rules.splice(existingIndex, 1);
244
- if (removed.source === 'buildr' && removed.required === true) {
245
- throw new Error(`Required Buildr Rule cannot be removed through rules remove: ${id}`);
246
- }
247
- if (removed.source === 'buildr') {
248
- throw new Error(`Buildr-managed Rule cannot be removed through rules remove: ${id}. Use buildr builtin uninstall for optional builtins.`);
249
- }
250
-
251
- const updatedPaths = [];
252
- const manifestPath = writeRulesManifest(targetRoot, manifest);
253
- updatedPaths.push(manifestPath);
254
- if (!hasFlag(args, '--keep-file')) {
255
- const rulePath = normalizeRootRulePath(targetRoot, removed.path);
256
- const absoluteRulePath = path.join(targetRoot, rulePath);
257
- if (existsFile(absoluteRulePath)) {
258
- assertSafeAssetTarget(targetRoot, absoluteRulePath, path.join(targetRoot, 'rules'), 'Rule delete target');
259
- fs.rmSync(absoluteRulePath, { force: true });
260
- updatedPaths.push(absoluteRulePath);
261
- }
262
- }
263
- printRulesMutationReceipt(
264
- '删除',
265
- targetRoot,
266
- id,
267
- updatedPaths,
268
- hasFlag(args, '--keep-file')
269
- ? '运行 buildr doctor --agent <agent> --target <dir> --json;保留的规则文件会作为未登记文件提示,后续可重新注册、移动归档或删除。'
270
- : '运行 buildr doctor --agent <agent> --target <dir> --json 复查;需要 Agent runtime 投射时再按当前 adapter 执行 rules render、runtime check 或 sync。'
271
- );
272
- }
273
-
274
- function rulesRemove(args) {
275
- const targetRoot = path.resolve(optionValue(args, '--target', process.cwd()));
276
- return withWorkspaceMutation(targetRoot, 'rules.remove', [path.join(targetRoot, 'rules')], () => rulesRemoveUnsafe(args));
277
- }
278
-
279
- function listMarkdownFiles(rootDir) {
280
- if (!existsDirectory(rootDir)) return [];
281
- const files = [];
282
- for (const entry of fs.readdirSync(rootDir).sort()) {
283
- const entryPath = path.join(rootDir, entry);
284
- if (existsDirectory(entryPath)) {
285
- files.push(...listMarkdownFiles(entryPath));
286
- } else if (entry.endsWith('.md') && existsFile(entryPath)) {
287
- files.push(entryPath);
288
- }
289
- }
290
- return files;
291
- }
292
-
293
- function diagnoseRules(result, targetRoot) {
294
- const manifestPath = rulesManifestPath(targetRoot);
295
- const rules = {
296
- manifest: {
297
- path: 'rules/manifest.yml',
298
- exists: existsFile(manifestPath),
299
- valid: false,
300
- schemaVersion: null,
301
- },
302
- entries: [],
303
- };
304
- result.rules = rules;
305
-
306
- const requiredStatus = rootRequiredBlockStatus(targetRoot);
307
- result.workspace.requiredBlock = requiredStatus;
308
- if (!requiredStatus.valid) {
309
- addDoctorFinding(result, 'warning', 'rules.required_block_invalid', '根 AGENTS.md 缺少或破坏 Buildr required block。', {
310
- path: 'AGENTS.md',
311
- suggestion: '运行 buildr update 或 buildr sync 恢复 required block;该操作只修复 Buildr block,不覆盖用户正文。',
312
- });
313
- }
314
-
315
- if (!rules.manifest.exists) {
316
- if (result.workspace?.initialized) {
317
- addDoctorFinding(result, 'warning', 'rules.manifest_missing', '规则清单不存在:rules/manifest.yml', {
318
- path: rules.manifest.path,
319
- suggestion: '运行 buildr sync <agent> 同步 Buildr 内置规则清单和当前 Agent runtime。',
320
- });
321
- }
322
- return;
323
- }
324
-
325
- let manifest;
326
- try {
327
- manifest = parseRulesManifestYaml(fs.readFileSync(manifestPath, 'utf8'));
328
- rules.manifest.schemaVersion = manifest.schemaVersion;
329
- const validationErrors = validateRulesManifest(manifest);
330
- if (validationErrors.length > 0) {
331
- for (const message of validationErrors) {
332
- addDoctorFinding(result, 'warning', 'rules.manifest_invalid', message, {
333
- path: rules.manifest.path,
334
- suggestion: '修复 rules/manifest.yml;规则 description 必须说明语义边界和用途,用于 Agent 判断相关规则。',
335
- });
336
- }
337
- return;
338
- }
339
- } catch (error) {
340
- addDoctorFinding(result, 'warning', 'rules.manifest_invalid', `规则清单不可解析:${error.message}`, {
341
- path: rules.manifest.path,
342
- suggestion: '修复 rules/manifest.yml 后重新运行 doctor。',
343
- });
344
- return;
345
- }
346
- rules.manifest.valid = true;
347
-
348
- const registeredPaths = new Set();
349
- for (const rule of manifest.rules) {
350
- const exists = existsFile(path.join(targetRoot, rule.path));
351
- registeredPaths.add(rule.path);
352
- const status = rule.enabled === false || rule.state === 'uninstalled'
353
- ? 'uninstalled'
354
- : exists ? 'installed' : 'missing';
355
- rules.entries.push({ id: rule.id, source: rule.source, path: rule.path, description: rule.description, enabled: rule.enabled !== false, required: rule.required === true, state: rule.state || status, exists });
356
- if (!exists && rule.state !== 'uninstalled' && rule.enabled !== false) {
357
- addDoctorFinding(result, rule.required ? 'warning' : 'warning', 'rules.file_missing', `规则清单登记的文件缺失:${rule.id}`, {
358
- path: rule.path,
359
- suggestion: rule.required ? '运行 buildr update 或 buildr sync 恢复 required 规则。' : '确认是否要恢复该规则文件;不再需要时可运行 buildr rules remove <id> --keep-file 取消登记,或手工修复 rules/manifest.yml。',
360
- });
361
- }
362
- }
363
-
364
- const rulesRoot = path.join(targetRoot, 'rules');
365
- for (const file of listMarkdownFiles(rulesRoot)) {
366
- const relative = toPosixRelative(targetRoot, file);
367
- if (!registeredPaths.has(relative)) {
368
- addDoctorFinding(result, 'warning', relative.startsWith('rules/buildr/') ? 'rules.buildr_unregistered' : 'rules.unregistered', `规则文件未登记到 rules/manifest.yml:${relative}`, {
369
- path: relative,
370
- suggestion: relative.startsWith('rules/buildr/')
371
- ? '运行 buildr update 或 buildr sync 恢复 Buildr 内置规则登记。'
372
- : `运行 buildr rules add <id> --path ${relative} --description <text> 注册该规则,或移动/删除该文件。`,
373
- });
374
- }
375
- }
376
- }
377
-
378
- Object.assign(runtime, { rulesManifestPath, parseRulesManifestYaml, renderRulesManifestYaml, validateRulesManifest, readRulesManifestForWrite, writeRulesManifest, resolveRootRulesScope, normalizeRootRulePath, buildRuleEntry, printRulesMutationReceipt, rulesAddUnsafe, rulesAdd, rulesRemoveUnsafe, rulesRemove, listMarkdownFiles, diagnoseRules });
379
- return runtime;
380
- }
@@ -1,87 +0,0 @@
1
- import {
2
- path,
3
- process,
4
- parseInstallClaudeCodeBuildrSkillArgs,
5
- assembleRuntimeProjection,
6
- RUNTIME_ADAPTERS,
7
- SUPPORTED_AGENT_IDS,
8
- UNSUPPORTED_AGENT_GUIDANCE,
9
- reconcileRuntimePlan,
10
- runtimeDiscoveryPayload,
11
- selectAdapterImplementation,
12
- RUNTIME_CHECKERS,
13
- RUNTIME_CHECK_PRINTERS,
14
- } from '../shared/platform.mjs';
15
- import { PUBLIC_JSON_SCHEMAS, withJsonSchema } from '../shared/json-contracts.mjs';
16
-
17
- export function registerDomainsRuntime(runtime) {
18
- const assertNoUnknownOptions = (...args) => runtime.assertNoUnknownOptions(...args);
19
- const isValidAssetId = (...args) => runtime.isValidAssetId(...args);
20
- const hasFlag = (...args) => runtime.hasFlag(...args);
21
- const existsDirectory = (...args) => runtime.existsDirectory(...args);
22
-
23
- function assertName(value, label) {
24
- if (!isValidAssetId(value)) {
25
- throw new Error(`${label} must contain only letters, digits, dots, underscores, or dashes: ${value || ''}`);
26
- }
27
- }
28
-
29
- function assertAgentId(value) {
30
- if (!isValidAssetId(value)) {
31
- throw new Error(`Agent id must contain only letters, digits, dots, underscores, or dashes: ${value || ''}`);
32
- }
33
- }
34
-
35
- function runtimeList(args) {
36
- assertNoUnknownOptions(args, new Set(['--json']));
37
- const json = hasFlag(args, '--json');
38
- const payload = runtimeDiscoveryPayload();
39
- if (json) {
40
- process.stdout.write(`${JSON.stringify(withJsonSchema(PUBLIC_JSON_SCHEMAS.runtimeList, payload), null, 2)}\n`);
41
- return;
42
- }
43
-
44
- console.log('Buildr supported Agent runtime adapters');
45
- console.log('');
46
- for (const agent of SUPPORTED_AGENT_IDS) {
47
- const adapter = RUNTIME_ADAPTERS[agent];
48
- const rulesEntry = adapter.renderCapabilities['rules-entry'];
49
- console.log(`- ${adapter.id} (${adapter.displayName})`);
50
- console.log(` render targets: ${adapter.runtimeTargets.join(', ')}`);
51
- console.log(` rules: ${rulesEntry.projection.mode}; ${rulesEntry.sourceDiscovery.mode} ${rulesEntry.sourceDiscovery.pattern}; includes ancestors: ${rulesEntry.sourceDiscovery.includesAncestors}`);
52
- console.log(` sync: ${adapter.recommendedCommands.syncWorkspaceEntry}`);
53
- console.log(` render: ${adapter.recommendedCommands.renderScope}`);
54
- console.log(` skills render: ${adapter.recommendedCommands.renderSkillsScope}`);
55
- console.log(` skill install: ${adapter.recommendedCommands.installProductSkill}`);
56
- console.log(` runtime check: ${adapter.recommendedCommands.runtimeCheckScope}`);
57
- }
58
- console.log('');
59
- console.log(`Unsupported Agent: ${UNSUPPORTED_AGENT_GUIDANCE.message}${UNSUPPORTED_AGENT_GUIDANCE.nextStep}`);
60
- }
61
-
62
- function runtimeImplementation(adapter, kind, implementations) {
63
- return selectAdapterImplementation(adapter, kind, implementations);
64
- }
65
-
66
- function installProductRuntimeSkill(agent, args, options = {}) {
67
- const repoRoot = options.repoRoot ?? process.cwd();
68
- const command = options.command ?? `buildr skill install ${agent}`;
69
- const parsed = parseInstallClaudeCodeBuildrSkillArgs(args, command);
70
- const targetRoot = path.resolve(repoRoot, parsed.target);
71
- if (!existsDirectory(targetRoot)) throw new Error(`Target directory does not exist: ${targetRoot}`);
72
- const { plan } = assembleRuntimeProjection({ repoRoot, targetRoot, scope: '.', adapterId: agent, selection: { productSkill: true } });
73
- reconcileRuntimePlan(plan);
74
- return { targetRoot, files: plan.writes.map((item) => item.targetFile), plan };
75
- }
76
-
77
- Object.assign(runtime, {
78
- assertName,
79
- assertAgentId,
80
- runtimeList,
81
- runtimeImplementation,
82
- installProductRuntimeSkill,
83
- RUNTIME_CHECKERS,
84
- RUNTIME_CHECK_PRINTERS,
85
- });
86
- return runtime;
87
- }