@buildr-ai/buildr 0.1.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +15 -0
- package/docs/cli-architecture.md +62 -0
- package/docs/cli-reference.md +67 -0
- package/docs/known-limitations.md +13 -0
- package/examples/minimal-workspace/README.md +24 -0
- package/package/README.md +28 -0
- package/package/bootstrap/contract.yml +122 -0
- package/package/bootstrap/guide.md +79 -0
- package/package/manifest.yml +144 -0
- package/package/targets/runtime/skills/buildr/SKILL.md +151 -0
- package/package/targets/workspace/.buildr/workspace.yml +5 -0
- package/package/targets/workspace/AGENTS.md +5 -0
- package/package/targets/workspace/commands/buildr/openspec/manifest.yml +15 -0
- package/package/targets/workspace/commands/manifest.yml +2 -0
- package/package/targets/workspace/components/buildr/openspec/component.yml +16 -0
- package/package/targets/workspace/components/buildr/openspec/contributions/openspec-apply-sidebar.md +3 -0
- package/package/targets/workspace/components/buildr/openspec/contributions/openspec-archive-sidebar.md +3 -0
- package/package/targets/workspace/components/buildr/openspec/contributions/openspec-explore-sidebar.md +3 -0
- package/package/targets/workspace/components/buildr/openspec/contributions/openspec-propose-sidebar.md +3 -0
- package/package/targets/workspace/components/buildr/openspec/contributions/openspec-sync-sidebar.md +3 -0
- package/package/targets/workspace/components/buildr/openspec/contributions/task-finish-post-sync.md +1 -0
- package/package/targets/workspace/components/buildr/openspec/contributions/task-finish-pre-sync.md +1 -0
- package/package/targets/workspace/components/buildr/openspec/contributions/task-triage-change-ready.md +10 -0
- package/package/targets/workspace/components/manifest.yml +2 -0
- package/package/targets/workspace/gitignore +13 -0
- package/package/targets/workspace/projects/AGENTS.project.md +25 -0
- package/package/targets/workspace/projects/manifest.yml +2 -0
- package/package/targets/workspace/projects/services/manifest.yml +3 -0
- package/package/targets/workspace/projects/skills/manifest.yml +2 -0
- package/package/targets/workspace/rules/buildr/core.md +63 -0
- package/package/targets/workspace/rules/manifest.yml +9 -0
- package/package/targets/workspace/skills/buildr/git-ops/SKILL.md +73 -0
- package/package/targets/workspace/skills/buildr/openspec-contract-guard/SKILL.md +67 -0
- package/package/targets/workspace/skills/buildr/task-finish/SKILL.md +104 -0
- package/package/targets/workspace/skills/buildr/task-triage/SKILL.md +103 -0
- package/package/targets/workspace/skills/buildr/task-worktree/SKILL.md +104 -0
- package/package/targets/workspace/skills/manifest.yml +38 -0
- package/package/targets/workspace/skills/openspec/openspec-apply-change/SKILL.md +159 -0
- package/package/targets/workspace/skills/openspec/openspec-archive-change/SKILL.md +117 -0
- package/package/targets/workspace/skills/openspec/openspec-explore/SKILL.md +287 -0
- package/package/targets/workspace/skills/openspec/openspec-propose/SKILL.md +111 -0
- package/package/targets/workspace/skills/openspec/openspec-sync-specs/SKILL.md +147 -0
- package/package.json +67 -0
- package/tools/buildr +11 -0
- package/tools/cli/application/cli-update.mjs +219 -0
- package/tools/cli/application/compose-runtime.mjs +38 -0
- package/tools/cli/application/doctor/runtime-diagnostics.mjs +226 -0
- package/tools/cli/application/doctor/scope-diagnostics.mjs +440 -0
- package/tools/cli/application/doctor/service-diagnostics.mjs +184 -0
- package/tools/cli/application/doctor.mjs +201 -0
- package/tools/cli/application/package-maintenance/builtin-receipts.mjs +73 -0
- package/tools/cli/application/package-maintenance/output.mjs +148 -0
- package/tools/cli/application/package-maintenance/smoke-checks.mjs +469 -0
- package/tools/cli/application/package-maintenance/static-validation.mjs +678 -0
- package/tools/cli/application/package-maintenance.mjs +538 -0
- package/tools/cli/application/runtime.mjs +118 -0
- package/tools/cli/application/workspace-operations.mjs +310 -0
- package/tools/cli/bootstrap.mjs +6 -0
- package/tools/cli/command/help.mjs +292 -0
- package/tools/cli/command/registry.mjs +97 -0
- package/tools/cli/domains/commands.mjs +661 -0
- package/tools/cli/domains/components.mjs +922 -0
- package/tools/cli/domains/openspec.mjs +603 -0
- package/tools/cli/domains/package-assets.mjs +652 -0
- package/tools/cli/domains/rules.mjs +380 -0
- package/tools/cli/domains/runtime.mjs +94 -0
- package/tools/cli/domains/skills.mjs +647 -0
- package/tools/cli/domains/workspace.mjs +571 -0
- package/tools/cli/shared/infrastructure.mjs +411 -0
- package/tools/cli/shared/json-contracts.mjs +22 -0
- package/tools/cli/shared/platform.mjs +52 -0
- package/tools/runtime/adapter-contract.mjs +330 -0
- package/tools/runtime/check-claude-code.mjs +26 -0
- package/tools/runtime/check-codex.mjs +26 -0
- package/tools/runtime/projection.mjs +163 -0
- package/tools/runtime/render-claude-code-rules.mjs +459 -0
- package/tools/runtime/render-claude-code.mjs +59 -0
- package/tools/runtime/skills/arguments.mjs +51 -0
- package/tools/runtime/skills/contributions.mjs +171 -0
- package/tools/runtime/skills/manifests.mjs +167 -0
- package/tools/runtime/skills/primitives.mjs +86 -0
- package/tools/runtime/skills/render-plan.mjs +244 -0
- package/tools/runtime/skills/sources.mjs +276 -0
- package/tools/shared/fetch-remote-text.mjs +78 -0
- package/tools/verification/integrity/managed-data-integrity.mjs +107 -0
- package/tools/verification/integrity/managed-mutations.mjs +72 -0
- package/tools/verification/openspec/contract.mjs +212 -0
- package/tools/verification/runtime/adapter-contract.mjs +102 -0
- package/tools/verification/runtime/adapter-parity.mjs +99 -0
|
@@ -0,0 +1,440 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
export function createServiceDiagnostics(deps) {
|
|
2
|
+
const {
|
|
3
|
+
addDoctorFinding,
|
|
4
|
+
existsDirectory,
|
|
5
|
+
existsFile,
|
|
6
|
+
fs,
|
|
7
|
+
gitBoundaryFor,
|
|
8
|
+
gitBoundaryIgnored,
|
|
9
|
+
gitCurrentBranch,
|
|
10
|
+
gitignoreLines,
|
|
11
|
+
listManagedDirectories,
|
|
12
|
+
parseServicesManifestYaml,
|
|
13
|
+
path,
|
|
14
|
+
projectDoctorContextFor,
|
|
15
|
+
readGitRemote,
|
|
16
|
+
toPosixRelative,
|
|
17
|
+
validateServicesManifest,
|
|
18
|
+
} = deps;
|
|
19
|
+
|
|
20
|
+
function diagnoseServicesMetadata(result, targetRoot, owner, metadataPath, baseRoot, serviceLabel, ignoreLines) {
|
|
21
|
+
if (!existsFile(metadataPath)) {
|
|
22
|
+
if (existsDirectory(baseRoot)) {
|
|
23
|
+
addDoctorFinding(result, 'warning', 'services.manifest_missing', `Service manifest 缺失:${serviceLabel}`, {
|
|
24
|
+
path: toPosixRelative(targetRoot, metadataPath),
|
|
25
|
+
suggestion: '运行 buildr update 或 buildr sync 创建 services/manifest.yml。',
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let manifest;
|
|
32
|
+
try {
|
|
33
|
+
manifest = parseServicesManifestYaml(fs.readFileSync(metadataPath, 'utf8'));
|
|
34
|
+
} catch (error) {
|
|
35
|
+
addDoctorFinding(result, 'warning', 'services.manifest_invalid', `Service manifest 不可解析:${error.message}`, {
|
|
36
|
+
path: toPosixRelative(targetRoot, metadataPath),
|
|
37
|
+
suggestion: '修复 services/manifest.yml 语法后重新运行 doctor。',
|
|
38
|
+
});
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const validationErrors = validateServicesManifest(manifest, owner.project);
|
|
43
|
+
for (const message of validationErrors) {
|
|
44
|
+
addDoctorFinding(result, 'warning', 'services.manifest_invalid', message, {
|
|
45
|
+
path: toPosixRelative(targetRoot, metadataPath),
|
|
46
|
+
suggestion: '运行 buildr update 或 buildr sync 修复低风险默认值并清理未知字段;project 字段冲突需要人工确认。',
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (existsFile(path.join(baseRoot, 'services.yml'))) {
|
|
51
|
+
addDoctorFinding(result, 'warning', 'services.legacy_manifest_present', `旧 Service registry 文件仍存在:${serviceLabel}`, {
|
|
52
|
+
path: toPosixRelative(targetRoot, path.join(baseRoot, 'services.yml')),
|
|
53
|
+
suggestion: '运行 buildr update 或 buildr sync 转换或删除旧 services.yml。',
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const registered = new Set(Object.keys(manifest.services || {}));
|
|
58
|
+
const servicesRoot = path.join(baseRoot, 'services');
|
|
59
|
+
for (const serviceName of listManagedDirectories(servicesRoot)) {
|
|
60
|
+
if (!registered.has(serviceName)) {
|
|
61
|
+
addDoctorFinding(result, 'warning', 'services.unregistered', `Service 目录未登记:${serviceLabel}/${serviceName}`, {
|
|
62
|
+
path: toPosixRelative(targetRoot, path.join(servicesRoot, serviceName)),
|
|
63
|
+
suggestion: '运行 buildr update 或 buildr sync 将既有 Service 目录补登记到 services/manifest.yml。',
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
for (const [serviceName, metadata] of Object.entries(manifest.services || {})) {
|
|
69
|
+
if (owner.servicePath && owner.servicePath.split('/')[0] !== serviceName) continue;
|
|
70
|
+
const repo = metadata.repo || {};
|
|
71
|
+
const repoPath = path.join(baseRoot, metadata.path || `services/${serviceName}`);
|
|
72
|
+
const service = {
|
|
73
|
+
org: owner.org,
|
|
74
|
+
project: owner.project || null,
|
|
75
|
+
name: serviceName,
|
|
76
|
+
title: metadata.title || null,
|
|
77
|
+
description: metadata.description || null,
|
|
78
|
+
type: metadata.type || null,
|
|
79
|
+
repo: repo,
|
|
80
|
+
path: toPosixRelative(targetRoot, repoPath),
|
|
81
|
+
exists: repoPath ? existsDirectory(repoPath) : false,
|
|
82
|
+
isGitRepository: repoPath ? existsDirectory(path.join(repoPath, '.git')) : false,
|
|
83
|
+
};
|
|
84
|
+
result.services.push(service);
|
|
85
|
+
|
|
86
|
+
if (!metadata.description || String(metadata.description).startsWith('TODO:')) {
|
|
87
|
+
addDoctorFinding(result, 'warning', 'services.description_todo', `Service 缺少有效 description:${serviceLabel}/${serviceName}`, {
|
|
88
|
+
path: toPosixRelative(targetRoot, metadataPath),
|
|
89
|
+
suggestion: '补充 Service description,说明该 Service 的适用场景和用途。',
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (!repo.kind) {
|
|
94
|
+
addDoctorFinding(result, 'warning', 'service.repo_kind_missing', `Service 缺少 repo kind:${serviceLabel}/${serviceName}`, {
|
|
95
|
+
path: toPosixRelative(targetRoot, metadataPath),
|
|
96
|
+
suggestion: '运行 buildr update 或 buildr sync 补齐 repo.kind。',
|
|
97
|
+
});
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (!service.exists) {
|
|
102
|
+
const suggestion = repo.kind === 'git' && repo.url
|
|
103
|
+
? '询问用户是否根据 metadata 自动 clone 该 service repo。'
|
|
104
|
+
: '确认 service repo 路径是否变更。';
|
|
105
|
+
const command = repo.kind === 'git' && repo.url
|
|
106
|
+
? `buildr service create ${owner.project}/${serviceName} ${repo.url}${repo.branch ? ` --branch ${repo.branch}` : ''} --target ${targetRoot}`
|
|
107
|
+
: undefined;
|
|
108
|
+
addDoctorFinding(result, repo.kind === 'git' ? 'warning' : 'error', `service.${repo.kind}.missing`, `Service repo 缺失:${serviceLabel}/${serviceName}`, {
|
|
109
|
+
path: service.path,
|
|
110
|
+
suggestion,
|
|
111
|
+
command,
|
|
112
|
+
});
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (repo.kind === 'git' && !service.isGitRepository) {
|
|
117
|
+
addDoctorFinding(result, 'error', 'service.not_git_repository', `Service 路径不是 Git repo:${serviceLabel}/${serviceName}`, {
|
|
118
|
+
path: service.path,
|
|
119
|
+
suggestion: '确认路径是否指向正确的 service repo。',
|
|
120
|
+
});
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (repo.kind === 'git' && !repo.url) {
|
|
125
|
+
addDoctorFinding(result, 'warning', 'service.git_url_missing', `Git Service 缺少 repo.url:${serviceLabel}/${serviceName}`, {
|
|
126
|
+
path: toPosixRelative(targetRoot, metadataPath),
|
|
127
|
+
suggestion: '补充 Git remote URL,或确认该 Service 只作为本地 Git 资产管理。',
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (repo.kind === 'git' && repo.url) {
|
|
132
|
+
const remoteName = repo.remote || 'origin';
|
|
133
|
+
const actualRemote = readGitRemote(repoPath, remoteName);
|
|
134
|
+
service.actualRemote = actualRemote;
|
|
135
|
+
if (actualRemote !== repo.url) {
|
|
136
|
+
addDoctorFinding(result, 'warning', 'service.remote_mismatch', `Service remote 与 metadata 不一致:${serviceLabel}/${serviceName}`, {
|
|
137
|
+
path: service.path,
|
|
138
|
+
expected: repo.url,
|
|
139
|
+
actual: actualRemote,
|
|
140
|
+
suggestion: '确认 repo 来源,必要时更新 metadata 或 Git remote。',
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (repo.kind === 'git') {
|
|
146
|
+
service.currentBranch = gitCurrentBranch(repoPath);
|
|
147
|
+
if (repo.branch && service.currentBranch !== repo.branch) {
|
|
148
|
+
addDoctorFinding(result, 'warning', 'service.branch_mismatch', `Service 当前分支与 metadata branch intent 不一致:${serviceLabel}/${serviceName}`, {
|
|
149
|
+
path: service.path,
|
|
150
|
+
expected: repo.branch,
|
|
151
|
+
actual: service.currentBranch,
|
|
152
|
+
suggestion: `切换到 ${repo.branch},或显式更新 Service branch intent。`,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const boundary = gitBoundaryFor(targetRoot, { type: 'service', project: owner.project, service: serviceName, assetRoot: repoPath });
|
|
158
|
+
service.ignoredByWorkspace = gitBoundaryIgnored(boundary);
|
|
159
|
+
if (!service.ignoredByWorkspace) {
|
|
160
|
+
addDoctorFinding(result, 'warning', 'gitignore.service_repo_not_ignored', `嵌套 service repo 未被上级 .gitignore 忽略:${serviceLabel}/${serviceName}`, {
|
|
161
|
+
path: service.path,
|
|
162
|
+
suggestion: '运行 buildr update 或 buildr sync 补齐最近上级 Git repo 的 .gitignore 边界。',
|
|
163
|
+
pattern: boundary?.pattern,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function diagnoseServices(result, targetRoot, scopes) {
|
|
170
|
+
result.services = [];
|
|
171
|
+
const ignoreLines = gitignoreLines(targetRoot);
|
|
172
|
+
|
|
173
|
+
for (const item of scopes) {
|
|
174
|
+
if (!item.project) continue;
|
|
175
|
+
const { projectRoot, metadataPath } = projectDoctorContextFor(targetRoot, item);
|
|
176
|
+
diagnoseServicesMetadata(result, targetRoot, item, metadataPath, projectRoot, item.project, ignoreLines);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return {
|
|
181
|
+
diagnoseServicesMetadata,
|
|
182
|
+
diagnoseServices,
|
|
183
|
+
};
|
|
184
|
+
}
|