@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,227 +0,0 @@
1
- export function createRuntimeDiagnostics(deps) {
2
- const {
3
- RUNTIME_CHECKERS,
4
- SUPPORTED_AGENT_IDS,
5
- UNSUPPORTED_AGENT_GUIDANCE,
6
- addDoctorFinding,
7
- componentRegistryPath,
8
- existsFile,
9
- getRuntimeAdapter,
10
- isSupportedAgent,
11
- managedRuntimeSkillOrphans,
12
- packageComponentsStatus,
13
- path,
14
- runCommandsCheck,
15
- runtimeImplementation,
16
- toPosixRelative,
17
- } = deps;
18
-
19
- function runtimeFindingsForDoctor(findings, includeInfo) {
20
- return includeInfo ? findings : findings.filter((finding) => finding.status !== 'info');
21
- }
22
-
23
- function summarizeRuntimeFindings(findings) {
24
- const counts = { ok: 0, info: 0, warning: 0, missing: 0, stale: 0, orphan: 0, conflict: 0 };
25
- for (const finding of findings) {
26
- counts[finding.status] = (counts[finding.status] ?? 0) + 1;
27
- }
28
- return counts;
29
- }
30
-
31
- function addUnsupportedAgentFinding(result, agent) {
32
- addDoctorFinding(result, 'warning', 'runtime.agent_unsupported', `${UNSUPPORTED_AGENT_GUIDANCE.message}${UNSUPPORTED_AGENT_GUIDANCE.nextStep}`, {
33
- path: '.',
34
- agent,
35
- supportedAgents: SUPPORTED_AGENT_IDS,
36
- userActionRequired: true,
37
- mustNotUseFallbackAdapter: true,
38
- suggestion: UNSUPPORTED_AGENT_GUIDANCE.nextStep,
39
- });
40
- }
41
-
42
- function diagnoseRuntime(result, targetRoot, scopes, options = {}) {
43
- const includeInfo = options.includeInfo === true;
44
- const selectedAgent = options.agent || null;
45
- const runtimeResultKey = (agent) => getRuntimeAdapter(agent).traits.checker.resultKey ?? agent.replace(/-([a-z])/g, (_match, letter) => letter.toUpperCase());
46
- result.runtime = Object.fromEntries(SUPPORTED_AGENT_IDS.map((agent) => [runtimeResultKey(agent), []]));
47
- if (selectedAgent && !isSupportedAgent(selectedAgent)) {
48
- addUnsupportedAgentFinding(result, selectedAgent);
49
- return;
50
- }
51
-
52
- const runtimeScopes = scopes.map((item) => item.scope);
53
- const seenFindings = Object.fromEntries(SUPPORTED_AGENT_IDS.map((agent) => [agent, new Set()]));
54
- const dedupeFindings = (agent, findings) => findings.filter((finding) => {
55
- const key = [finding.code || finding.status, finding.path, finding.expected || '', finding.actual || ''].join('|');
56
- if (seenFindings[agent].has(key)) return false;
57
- seenFindings[agent].add(key);
58
- return true;
59
- });
60
-
61
- for (const scope of runtimeScopes) {
62
- for (const agent of selectedAgent ? [selectedAgent] : SUPPORTED_AGENT_IDS) {
63
- const adapter = getRuntimeAdapter(agent);
64
- const checker = runtimeImplementation(adapter, 'checker', RUNTIME_CHECKERS);
65
- const resultKey = runtimeResultKey(agent);
66
- const codeId = agent.replaceAll('-', '_');
67
- try {
68
- const check = checker(['--scope', scope, '--target', targetRoot], {
69
- repoRoot: targetRoot,
70
- adapterId: adapter.id,
71
- command: 'buildr doctor',
72
- });
73
- const findings = dedupeFindings(agent, runtimeFindingsForDoctor(check.findings, includeInfo));
74
- result.runtime[resultKey].push({ agent, scope, counts: summarizeRuntimeFindings(findings), findings, environmentChecks: check.environmentChecks, activation: check.activation });
75
- if (findings.some((finding) => ['missing', 'stale', 'orphan'].includes(finding.status))) {
76
- addDoctorFinding(result, 'warning', `runtime.${codeId}_stale`, `${adapter.displayName} runtime 缺失或过期:${scope}`, {
77
- path: toPosixRelative(targetRoot, check.targetRoot),
78
- agent,
79
- suggestion: `按 doctor 输出的修复命令同步 ${adapter.displayName} runtime;需要 adapter 细节时再运行 runtime check。`,
80
- commands: check.repairCommands,
81
- });
82
- }
83
- if (findings.some((finding) => finding.status === 'warning')) {
84
- addDoctorFinding(result, 'warning', `runtime.${codeId}_warning`, `${adapter.displayName} runtime 存在警告:${scope}`, {
85
- path: toPosixRelative(targetRoot, check.targetRoot),
86
- agent,
87
- suggestion: '优先查看 doctor 输出中的 runtime findings;需要 adapter 细节时再运行 runtime check。',
88
- });
89
- }
90
- if (findings.some((finding) => finding.status === 'conflict')) {
91
- addDoctorFinding(result, 'error', `runtime.${codeId}_conflict`, `${adapter.displayName} runtime 存在非 Buildr 管理或冲突文件:${scope}`, {
92
- path: toPosixRelative(targetRoot, check.targetRoot),
93
- agent,
94
- suggestion: '将手写内容迁移回 Buildr 资产源,再重新 render。',
95
- });
96
- }
97
- if (includeInfo) {
98
- for (const finding of findings.filter((item) => item.status === 'info')) {
99
- addDoctorFinding(result, 'info', finding.code ?? 'runtime.info', finding.message, {
100
- path: finding.path,
101
- agent,
102
- impact: finding.impact,
103
- userActionRequired: finding.userActionRequired,
104
- repair: finding.repair,
105
- suggestion: finding.suggestion,
106
- });
107
- }
108
- }
109
- } catch (error) {
110
- const missingManifest = error.message.startsWith('Manifest not found:');
111
- const missingCode = adapter.traits.checker.skillsManifestAbsentCode ?? `runtime.${codeId}_skills_manifest_absent`;
112
- addDoctorFinding(result, missingManifest ? 'ok' : 'error', missingManifest ? missingCode : `runtime.${codeId}_unchecked`, missingManifest ? `未声明 ${adapter.displayName} Skills manifest,跳过 Skills runtime 检查:${scope}` : `无法检查 ${adapter.displayName} runtime:${scope}`, missingManifest ? {} : {
113
- agent,
114
- suggestion: error.message,
115
- });
116
- }
117
- }
118
- }
119
- }
120
-
121
- function diagnoseCommands(result, targetRoot) {
122
- const commandsResult = runCommandsCheck(targetRoot);
123
- result.commandLineTools = commandsResult;
124
- for (const finding of commandsResult.findings) {
125
- addDoctorFinding(result, finding.status, finding.code, finding.message, {
126
- path: finding.path,
127
- suggestion: finding.suggestion,
128
- installHint: finding.installHint,
129
- commandId: finding.commandId,
130
- executable: finding.executable,
131
- sources: finding.sources,
132
- expected: finding.expected,
133
- actual: finding.actual,
134
- });
135
- }
136
- }
137
-
138
- function diagnoseComponents(result, targetRoot, includeInfo = false, selectedAgent = null) {
139
- if (!existsFile(componentRegistryPath(targetRoot))) {
140
- addDoctorFinding(result, 'warning', 'components.registry_missing', 'Component registry 缺失。', {
141
- path: 'components/manifest.yml',
142
- suggestion: `运行 buildr sync <agent> --target ${targetRoot} 创建 registry、迁移默认 Component 并准备当前 Agent runtime。`,
143
- command: `buildr sync <agent> --target ${targetRoot}`,
144
- });
145
- }
146
- let status;
147
- try {
148
- status = packageComponentsStatus(targetRoot);
149
- } catch (error) {
150
- result.components = { items: [], ownership: {}, findings: [] };
151
- addDoctorFinding(result, 'error', 'components.registry_invalid', error.message, {
152
- path: 'components/manifest.yml',
153
- suggestion: '修复 Component registry 后重新运行 doctor。',
154
- });
155
- return;
156
- }
157
- result.components = {
158
- items: status.components,
159
- ownership: Object.fromEntries(status.ownership),
160
- findings: status.findings,
161
- };
162
- for (const finding of status.findings) {
163
- addDoctorFinding(result, 'error', finding.code || 'components.invalid', finding.message || `Component ownership conflict: ${finding.member || ''}`, {
164
- path: finding.member || 'components/manifest.yml',
165
- componentId: finding.componentId,
166
- owners: finding.owners,
167
- suggestion: '修复 Component definition、成员路径或唯一所有权冲突后重试。',
168
- });
169
- }
170
- for (const item of status.components) {
171
- if (['invalid', 'modified', 'missing'].includes(item.status)) {
172
- addDoctorFinding(result, 'error', `components.${item.status}`, `Component ${item.id} 状态异常:${item.status}`, {
173
- path: `components/${item.id}`,
174
- componentId: item.id,
175
- error: item.error,
176
- members: item.members,
177
- suggestion: item.status === 'missing'
178
- ? `运行 buildr component install ${item.id} --agent <agent> --target ${targetRoot},或确认是否应保留卸载状态。`
179
- : '检查成员差异;不要通过单项资产命令覆盖 Component 成员。',
180
- });
181
- } else if (item.status === 'update-available') {
182
- addDoctorFinding(result, 'warning', 'components.update_available', `Component ${item.id} 有可用更新。`, {
183
- componentId: item.id,
184
- expected: item.availableVersion,
185
- actual: item.installedVersion,
186
- suggestion: '运行 buildr update,或通过当前 Agent 执行 buildr sync <agent>。',
187
- });
188
- } else if (includeInfo) {
189
- addDoctorFinding(result, 'info', `components.${item.status}`, `Component ${item.id}:${item.status}`, {
190
- componentId: item.id,
191
- installedVersion: item.installedVersion,
192
- availableVersion: item.availableVersion,
193
- });
194
- }
195
- }
196
- const uninstalledOwners = new Map();
197
- for (const item of status.components.filter((component) => component.status === 'uninstalled')) {
198
- for (const member of item.members.filter((entry) => entry.path.startsWith('skills/'))) uninstalledOwners.set(path.basename(member.path), item.id);
199
- }
200
- const componentRuntimeAgents = selectedAgent
201
- ? isSupportedAgent(selectedAgent) ? [selectedAgent] : []
202
- : SUPPORTED_AGENT_IDS;
203
- for (const agent of componentRuntimeAgents) {
204
- for (const orphan of managedRuntimeSkillOrphans(targetRoot, agent)) {
205
- const componentId = uninstalledOwners.get(orphan.runtimePath) || null;
206
- addDoctorFinding(result, 'warning', 'components.runtime_orphan', componentId
207
- ? `已卸载 Component ${componentId} 仍有 ${agent} runtime Skill 投射:${orphan.runtimePath}`
208
- : `Buildr-managed ${agent} runtime Skill 没有有效源资产:${orphan.runtimePath}`, {
209
- path: orphan.path,
210
- componentId,
211
- agent,
212
- suggestion: `运行 buildr render ${agent} --scope . --target ${targetRoot} 清理受管 runtime orphan。`,
213
- command: `buildr render ${agent} --scope . --target ${targetRoot}`,
214
- });
215
- }
216
- }
217
- }
218
-
219
- return {
220
- runtimeFindingsForDoctor,
221
- summarizeRuntimeFindings,
222
- addUnsupportedAgentFinding,
223
- diagnoseRuntime,
224
- diagnoseCommands,
225
- diagnoseComponents,
226
- };
227
- }
@@ -1,440 +0,0 @@
1
- export function createScopeDiagnostics(deps) {
2
- const {
3
- addDoctorFinding,
4
- execFileSync,
5
- existsDirectory,
6
- existsFile,
7
- fs,
8
- gitBoundaryFor,
9
- gitBoundaryIgnored,
10
- gitOutput,
11
- parseProjectsYaml,
12
- parseYamlValue,
13
- path,
14
- projectsManifestPath,
15
- servicesManifestPath,
16
- toPosixRelative,
17
- validateProjectsRegistry,
18
- } = deps;
19
-
20
- function scopeParts(scope) {
21
- const parts = scope === '.' ? ['.'] : scope.split('/').filter(Boolean);
22
- const isRootScope = parts.length === 1 && parts[0] === '.';
23
- const isRootProjectScope = parts[0] === 'projects';
24
- if (parts[0] === 'organizations') {
25
- throw new Error(`organizations/<org>/ scopes are not supported. Use root-relative scopes such as projects/<project>: ${scope}`);
26
- }
27
- if (parts[0] === 'shared') {
28
- throw new Error(`shared scopes are not supported. Put shared or foundation services under a project, for example projects/foundation/services/<service>: ${scope}`);
29
- }
30
- if (!isRootScope && !isRootProjectScope) {
31
- throw new Error(`Unsupported doctor scope: ${scope}`);
32
- }
33
- if (isRootProjectScope && parts.length < 2) {
34
- throw new Error(`Doctor project scope must be projects/<project>[/services/<service>[/path...]]: ${scope}`);
35
- }
36
- return parts;
37
- }
38
-
39
- function workspaceName(targetRoot) {
40
- const metadataPath = path.join(targetRoot, '.buildr', 'workspace.yml');
41
- if (!existsFile(metadataPath)) return path.basename(targetRoot);
42
- const content = fs.readFileSync(metadataPath, 'utf8');
43
- const match = content.match(/^name:\s*(.+)$/m);
44
- return match ? parseYamlValue(match[1].trim()) : path.basename(targetRoot);
45
- }
46
-
47
- function readProjectsRegistryIfExists(targetRoot) {
48
- const file = projectsManifestPath(targetRoot);
49
- if (!existsFile(file)) return null;
50
- return parseProjectsYaml(fs.readFileSync(file, 'utf8'));
51
- }
52
-
53
- function discoverDoctorScopes(targetRoot, requestedScope, registry = null) {
54
- if (requestedScope) {
55
- const parts = scopeParts(requestedScope);
56
- if (parts[0] === '.') {
57
- return [{ org: workspaceName(targetRoot), project: null, servicePath: null, scope: '.' }];
58
- }
59
- if (parts[0] === 'projects') {
60
- return [{
61
- org: workspaceName(targetRoot),
62
- project: parts[1],
63
- servicePath: parts[2] === 'services' && parts.length > 3
64
- ? parts.slice(3).join('/')
65
- : parts.length > 2 ? parts.slice(2).join('/') : null,
66
- scope: requestedScope,
67
- }];
68
- }
69
- }
70
-
71
- const scopes = [];
72
- if (existsDirectory(path.join(targetRoot, 'projects')) || existsFile(path.join(targetRoot, '.buildr', 'workspace.yml'))) {
73
- scopes.push({ org: workspaceName(targetRoot), project: null, servicePath: null, scope: '.' });
74
- const projectNames = new Set();
75
- if (registry?.projects) {
76
- for (const project of Object.keys(registry.projects)) projectNames.add(project);
77
- }
78
- const projectsRoot = path.join(targetRoot, 'projects');
79
- if (existsDirectory(projectsRoot)) {
80
- const projects = fs.readdirSync(projectsRoot).filter((project) => existsDirectory(path.join(projectsRoot, project))).sort();
81
- for (const project of projects) projectNames.add(project);
82
- }
83
- for (const project of [...projectNames].sort()) {
84
- scopes.push({ org: workspaceName(targetRoot), project, servicePath: null, scope: `projects/${project}` });
85
- }
86
- }
87
- return scopes;
88
- }
89
-
90
- function resolveRepoPath(projectRoot, repoPath) {
91
- if (!repoPath) return null;
92
- return path.isAbsolute(repoPath) ? repoPath : path.resolve(projectRoot, repoPath);
93
- }
94
-
95
- function readGitRemote(repoPath, remoteName) {
96
- try {
97
- return gitOutput(['remote', 'get-url', remoteName], repoPath);
98
- } catch {
99
- return null;
100
- }
101
- }
102
-
103
- function gitignoreLines(targetRoot) {
104
- const gitignore = path.join(targetRoot, '.gitignore');
105
- if (!existsFile(gitignore)) return [];
106
- return fs.readFileSync(gitignore, 'utf8').split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
107
- }
108
-
109
- function isIgnoredByWorkspace(targetRoot, serviceRepoPath, lines) {
110
- const relative = toPosixRelative(targetRoot, serviceRepoPath);
111
- try {
112
- execFileSync('git', ['check-ignore', '--quiet', relative], { cwd: targetRoot, stdio: 'ignore' });
113
- return true;
114
- } catch {
115
- // Fall through to the text-only check for non-Git workspaces or unusual Git setups.
116
- }
117
-
118
- const withSlash = relative.endsWith('/') ? relative : `${relative}/`;
119
- const parentPattern = `${path.posix.dirname(relative) || '.'}/*/`;
120
- if (lines.includes(withSlash) || lines.includes(parentPattern)) return true;
121
-
122
- const segments = relative.split('/');
123
- for (let index = 1; index < segments.length; index += 1) {
124
- const ancestor = `${segments.slice(0, index).join('/')}/`;
125
- if (lines.includes(ancestor)) return true;
126
- }
127
- return false;
128
- }
129
-
130
- function projectDoctorContextFor(targetRoot, item) {
131
- const orgRoot = targetRoot;
132
- const projectRoot = item.project ? path.join(orgRoot, 'projects', item.project) : null;
133
- return {
134
- orgRoot,
135
- projectRoot,
136
- metadataPath: projectRoot ? servicesManifestPath(projectRoot) : null,
137
- servicesRoot: projectRoot ? path.join(projectRoot, 'services') : null,
138
- };
139
- }
140
-
141
- function projectBaselineStatus(projectRoot) {
142
- return {
143
- agentsFile: existsFile(path.join(projectRoot, 'AGENTS.md')),
144
- openspecSpecs: existsDirectory(path.join(projectRoot, 'openspec', 'specs')),
145
- openspecKnowledge: existsDirectory(path.join(projectRoot, 'openspec', 'knowledge')),
146
- openspecChanges: existsDirectory(path.join(projectRoot, 'openspec', 'changes')),
147
- skills: existsDirectory(path.join(projectRoot, 'skills')),
148
- skillsManifest: existsFile(path.join(projectRoot, 'skills', 'manifest.yml')),
149
- servicesMetadata: existsFile(servicesManifestPath(projectRoot)),
150
- servicesDirectory: existsDirectory(path.join(projectRoot, 'services')),
151
- };
152
- }
153
-
154
- function missingProjectBaselineAssets(status) {
155
- const labels = {
156
- agentsFile: 'AGENTS.md',
157
- openspecSpecs: 'openspec/specs',
158
- openspecKnowledge: 'openspec/knowledge',
159
- openspecChanges: 'openspec/changes',
160
- skills: 'skills',
161
- skillsManifest: 'skills/manifest.yml',
162
- servicesMetadata: 'services/manifest.yml',
163
- servicesDirectory: 'services',
164
- };
165
- return Object.entries(status)
166
- .filter(([, exists]) => !exists)
167
- .map(([key]) => labels[key]);
168
- }
169
-
170
- function diagnoseProjectRegistry(result, targetRoot) {
171
- const registryPath = projectsManifestPath(targetRoot);
172
- const registryResult = {
173
- path: 'projects/manifest.yml',
174
- exists: existsFile(registryPath),
175
- valid: false,
176
- schemaVersion: null,
177
- projects: [],
178
- };
179
- result.projectRegistry = registryResult;
180
-
181
- if (existsFile(path.join(targetRoot, 'projects.yml'))) {
182
- addDoctorFinding(result, 'warning', 'projects.legacy_registry_present', '旧 Project registry 文件仍存在:projects.yml', {
183
- path: 'projects.yml',
184
- suggestion: '运行 buildr update 或 buildr sync 删除旧文件;该文件不会作为迁移来源读取。',
185
- });
186
- }
187
-
188
- if (!registryResult.exists) {
189
- if (result.workspace?.initialized) {
190
- addDoctorFinding(result, 'warning', 'projects.registry_missing', 'Project registry 缺失:projects/manifest.yml', {
191
- path: registryResult.path,
192
- suggestion: '运行 buildr update 或 buildr sync 创建 projects/manifest.yml,并补登记既有 Project 目录。',
193
- });
194
- }
195
- return null;
196
- }
197
-
198
- let registry;
199
- try {
200
- registry = readProjectsRegistryIfExists(targetRoot);
201
- } catch (error) {
202
- addDoctorFinding(result, 'warning', 'projects.registry_invalid', `Project registry 不可解析:${error.message}`, {
203
- path: registryResult.path,
204
- suggestion: '修复 projects/manifest.yml 语法后重新运行 doctor。',
205
- });
206
- return null;
207
- }
208
-
209
- registryResult.schemaVersion = registry.schemaVersion;
210
- const validationErrors = validateProjectsRegistry(registry);
211
- if (validationErrors.length > 0) {
212
- for (const message of validationErrors) {
213
- addDoctorFinding(result, 'warning', 'projects.registry_invalid', message, {
214
- path: registryResult.path,
215
- suggestion: '运行 buildr update 或 buildr sync 修复低风险默认值并清理未知字段;路径或 project 字段冲突需要人工确认。',
216
- });
217
- }
218
- }
219
- registryResult.valid = validationErrors.length === 0;
220
-
221
- for (const [projectName, project] of Object.entries(registry.projects || {}).sort(([left], [right]) => left.localeCompare(right))) {
222
- registryResult.projects.push({
223
- name: projectName,
224
- title: project.title || null,
225
- description: project.description || null,
226
- path: project.path || `projects/${projectName}`,
227
- repo: project.repo || null,
228
- });
229
- if (!project.title) {
230
- addDoctorFinding(result, 'warning', 'projects.title_missing', `Project 缺少 title:${projectName}`, {
231
- path: registryResult.path,
232
- suggestion: '运行 buildr update 或 buildr sync 补齐默认 title。',
233
- command: `buildr project create ${projectName} --target ${targetRoot}`,
234
- });
235
- }
236
- if (!project.description || String(project.description).startsWith('TODO:')) {
237
- addDoctorFinding(result, 'warning', 'projects.description_todo', `Project 缺少有效 description:${projectName}`, {
238
- path: registryResult.path,
239
- suggestion: '补充 Project description,说明该 Project 的适用场景和用途。',
240
- });
241
- }
242
- if (project.repo?.kind === 'git' && !project.repo.url) {
243
- addDoctorFinding(result, 'warning', 'projects.git_url_missing', `Git Project 缺少 repo.url:${projectName}`, {
244
- path: registryResult.path,
245
- suggestion: '补充 Git remote URL,或确认该 Project 只作为本地 Git 资产管理。',
246
- });
247
- }
248
- }
249
-
250
- const registered = new Set(Object.keys(registry.projects || {}));
251
- const projectsRoot = path.join(targetRoot, 'projects');
252
- if (existsDirectory(projectsRoot)) {
253
- for (const projectName of fs.readdirSync(projectsRoot).filter((project) => existsDirectory(path.join(projectsRoot, project))).sort()) {
254
- if (!registered.has(projectName)) {
255
- addDoctorFinding(result, 'warning', 'projects.unregistered', `Project 目录未登记:${projectName}`, {
256
- path: `projects/${projectName}`,
257
- suggestion: '通过 buildr project create 补齐 Project registry,或删除该目录。',
258
- command: `buildr project create ${projectName} --target ${targetRoot}`,
259
- });
260
- }
261
- }
262
- }
263
-
264
- return registry;
265
- }
266
-
267
- function diagnoseWorkspace(result, targetRoot) {
268
- const hasRootModel = existsDirectory(path.join(targetRoot, 'projects')) || existsFile(path.join(targetRoot, '.buildr', 'workspace.yml'));
269
- const workspace = {
270
- initialized: existsFile(path.join(targetRoot, 'AGENTS.md')) && hasRootModel,
271
- agentsFile: existsFile(path.join(targetRoot, 'AGENTS.md')),
272
- rootOrganization: hasRootModel,
273
- metadataFile: existsFile(path.join(targetRoot, '.buildr', 'workspace.yml')),
274
- };
275
- result.workspace = workspace;
276
-
277
- if (!workspace.initialized) {
278
- const selectedAgent = result.agentRuntime?.selected;
279
- addDoctorFinding(result, 'error', 'workspace.not_initialized', '当前目录不是完整 Buildr workspace。', {
280
- path: targetRoot,
281
- suggestion: selectedAgent ? '执行带当前 Agent 的高层 init,一次完成 workspace、runtime 和最终 doctor。' : '先确认 Agent runtime adapter,再执行 buildr init 初始化 workspace。',
282
- command: `buildr init${selectedAgent ? ` --agent ${selectedAgent}` : ''} --target ${targetRoot} --name ${path.basename(targetRoot)}`,
283
- });
284
- }
285
-
286
- if (existsDirectory(path.join(targetRoot, 'organizations'))) {
287
- addDoctorFinding(result, 'error', 'workspace.organizations_unsupported', '当前目录包含不再支持的 organizations/ 布局。', {
288
- path: 'organizations',
289
- suggestion: '将需要保留的单个组织资产迁移到 Buildr root,使用 projects/ 作为默认入口。',
290
- });
291
- }
292
-
293
- if (existsDirectory(path.join(targetRoot, 'shared'))) {
294
- addDoctorFinding(result, 'warning', 'workspace.shared_unsupported', '当前目录包含不再作为默认模型支持的 shared/ 入口。', {
295
- path: 'shared',
296
- suggestion: '将共享、基础或平台服务迁移到某个 Project,例如 projects/foundation/services/。',
297
- });
298
- }
299
- }
300
-
301
- function diagnoseLegacyPractices(result, targetRoot, scopes, includeInfo = false) {
302
- if (!includeInfo) return;
303
- const roots = [{ path: 'practices', root: path.join(targetRoot, 'practices'), scope: 'workspace' }];
304
- for (const item of scopes) {
305
- if (!item.project) continue;
306
- roots.push({
307
- path: `projects/${item.project}/practices`,
308
- root: path.join(targetRoot, 'projects', item.project, 'practices'),
309
- scope: `projects/${item.project}`,
310
- });
311
- }
312
- for (const legacy of roots) {
313
- if (!existsDirectory(legacy.root)) continue;
314
- addDoctorFinding(result, 'info', 'practices.legacy_directory_present', `检测到已退出当前资产模型的遗留 Practices 目录:${legacy.path}`, {
315
- path: legacy.path,
316
- scope: legacy.scope,
317
- userActionRequired: false,
318
- suggestion: '按内容语义人工审阅:约束迁移为 Rule,可复用专业动作迁移为 Skill,产品事实、需求与变更迁移为 OpenSpec,其他说明保留为普通 docs;Buildr 不会自动读取、迁移或删除该目录。',
319
- });
320
- }
321
- }
322
-
323
- function diagnoseHierarchy(result, targetRoot, scopes, registry = null) {
324
- result.organizations = [];
325
- result.projects = [];
326
- const seenOrganizations = new Set();
327
- const ignoreLines = gitignoreLines(targetRoot);
328
-
329
- for (const item of scopes) {
330
- const { orgRoot, projectRoot, metadataPath, servicesRoot } = projectDoctorContextFor(targetRoot, item);
331
- const registryEntry = item.project ? registry?.projects?.[item.project] || null : null;
332
- const organization = { name: item.org, path: toPosixRelative(targetRoot, orgRoot), exists: existsDirectory(orgRoot) };
333
- const organizationKey = `${organization.path}|${organization.name}`;
334
- if (!seenOrganizations.has(organizationKey)) {
335
- result.organizations.push(organization);
336
- seenOrganizations.add(organizationKey);
337
- }
338
- if (!organization.exists) {
339
- const selectedAgent = result.agentRuntime?.selected;
340
- addDoctorFinding(result, 'error', 'organization.missing', `Organization 缺失:${item.org}`, {
341
- path: organization.path,
342
- suggestion: selectedAgent ? '执行带当前 Agent 的高层 init,一次完成根组织上下文、runtime 和最终 doctor。' : '先确认 Agent runtime adapter,再执行 buildr init 初始化根组织上下文。',
343
- command: `buildr init${selectedAgent ? ` --agent ${selectedAgent}` : ''} --target ${targetRoot} --name ${item.org}`,
344
- });
345
- continue;
346
- }
347
-
348
- if (!item.project) continue;
349
-
350
- const project = {
351
- org: item.org,
352
- name: item.project,
353
- title: registryEntry?.title || null,
354
- description: registryEntry?.description || null,
355
- path: toPosixRelative(targetRoot, projectRoot),
356
- registered: Boolean(registryEntry),
357
- repo: registryEntry?.repo || null,
358
- exists: existsDirectory(projectRoot),
359
- servicesMetadata: toPosixRelative(targetRoot, metadataPath),
360
- servicesDirectory: toPosixRelative(targetRoot, servicesRoot),
361
- baseline: projectBaselineStatus(projectRoot),
362
- openspec: existsDirectory(path.join(projectRoot, 'openspec')),
363
- };
364
- result.projects.push(project);
365
-
366
- if (!project.exists) {
367
- const command = registryEntry?.repo?.kind === 'git' && registryEntry.repo.url
368
- ? `buildr project create ${item.project} --repo ${registryEntry.repo.url} --target ${targetRoot}`
369
- : `buildr project create ${item.project} --target ${targetRoot}`;
370
- addDoctorFinding(result, 'error', 'project.missing', `Project 缺失:${item.project}`, {
371
- path: project.path,
372
- suggestion: registryEntry?.repo?.kind === 'git' && registryEntry.repo.url
373
- ? '询问用户是否根据 registry 自动 clone 该 Project 资产 repo。'
374
- : '创建缺失的项目资产。',
375
- command,
376
- });
377
- continue;
378
- }
379
-
380
- const missingBaseline = missingProjectBaselineAssets(project.baseline);
381
- if (missingBaseline.length > 0) {
382
- addDoctorFinding(result, 'warning', 'project.baseline_incomplete', `Project baseline 不完整:${item.project}`, {
383
- path: project.path,
384
- missing: missingBaseline,
385
- suggestion: '运行 buildr project create 补齐项目骨架。',
386
- command: `buildr project create ${item.project} --target ${targetRoot}`,
387
- });
388
- }
389
-
390
- if (registryEntry?.repo?.kind === 'git') {
391
- project.isGitRepository = existsDirectory(path.join(projectRoot, '.git'));
392
- if (!project.isGitRepository) {
393
- addDoctorFinding(result, 'error', 'project.not_git_repository', `Project 资产目录不是 Git repo:${item.project}`, {
394
- path: project.path,
395
- suggestion: '确认 Project 资产 repo 是否正确 clone 到 projects/<project>/。',
396
- command: registryEntry.repo.url ? `buildr project create ${item.project} --repo ${registryEntry.repo.url} --target ${targetRoot}` : undefined,
397
- });
398
- } else {
399
- const remoteName = registryEntry.repo.remote || 'origin';
400
- project.actualRemote = readGitRemote(projectRoot, remoteName);
401
- if (registryEntry.repo.url && project.actualRemote !== registryEntry.repo.url) {
402
- addDoctorFinding(result, 'warning', 'project.remote_mismatch', `Project remote 与 registry 不一致:${item.project}`, {
403
- path: project.path,
404
- expected: registryEntry.repo.url,
405
- actual: project.actualRemote,
406
- suggestion: '确认 Project 资产 repo 来源,必要时更新 registry 或 Git remote。',
407
- });
408
- }
409
- }
410
- const boundary = gitBoundaryFor(targetRoot, { type: 'project', project: item.project, assetRoot: projectRoot });
411
- project.ignoredByWorkspace = gitBoundaryIgnored(boundary);
412
- if (!project.ignoredByWorkspace) {
413
- addDoctorFinding(result, 'warning', 'gitignore.project_repo_not_ignored', `嵌套 Project repo 未被 workspace .gitignore 忽略:${item.project}`, {
414
- path: project.path,
415
- suggestion: '更新 workspace .gitignore,避免外层 Git 误提交 Project 资产 repo 内容。',
416
- pattern: boundary?.pattern,
417
- });
418
- }
419
- }
420
- }
421
- }
422
-
423
- return {
424
- scopeParts,
425
- workspaceName,
426
- readProjectsRegistryIfExists,
427
- discoverDoctorScopes,
428
- resolveRepoPath,
429
- readGitRemote,
430
- gitignoreLines,
431
- isIgnoredByWorkspace,
432
- projectDoctorContextFor,
433
- projectBaselineStatus,
434
- missingProjectBaselineAssets,
435
- diagnoseProjectRegistry,
436
- diagnoseWorkspace,
437
- diagnoseLegacyPractices,
438
- diagnoseHierarchy,
439
- };
440
- }