@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,219 @@
|
|
|
1
|
+
import { fs, path, process, spawnSync } from '../shared/platform.mjs';
|
|
2
|
+
import { PUBLIC_JSON_SCHEMAS, withJsonSchema } from '../shared/json-contracts.mjs';
|
|
3
|
+
|
|
4
|
+
function run(command, args, options = {}) {
|
|
5
|
+
const result = spawnSync(command, args, { encoding: 'utf8', ...options });
|
|
6
|
+
return {
|
|
7
|
+
ok: result.status === 0,
|
|
8
|
+
status: result.status,
|
|
9
|
+
stdout: (result.stdout || '').trim(),
|
|
10
|
+
stderr: (result.stderr || '').trim(),
|
|
11
|
+
error: result.error?.message || null,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function readPackage(file) {
|
|
16
|
+
try { return JSON.parse(fs.readFileSync(file, 'utf8')); } catch { return null; }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function registryPrefixForProductRoot(root) {
|
|
20
|
+
const normalized = path.resolve(root);
|
|
21
|
+
const marker = process.platform === 'win32'
|
|
22
|
+
? `${path.sep}node_modules${path.sep}`
|
|
23
|
+
: `${path.sep}lib${path.sep}node_modules${path.sep}`;
|
|
24
|
+
const index = normalized.lastIndexOf(marker);
|
|
25
|
+
return index > 0 ? normalized.slice(0, index) : null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function compareVersions(left, right) {
|
|
29
|
+
const parse = (value) => String(value || '').replace(/^v/, '').split('-', 1)[0].split('.').map((part) => Number(part));
|
|
30
|
+
const a = parse(left);
|
|
31
|
+
const b = parse(right);
|
|
32
|
+
for (let index = 0; index < Math.max(a.length, b.length); index += 1) {
|
|
33
|
+
const delta = (a[index] || 0) - (b[index] || 0);
|
|
34
|
+
if (delta !== 0) return delta;
|
|
35
|
+
}
|
|
36
|
+
return 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function identifyCliSource(productRoot) {
|
|
40
|
+
const root = path.resolve(productRoot);
|
|
41
|
+
const packageFile = path.join(root, 'package.json');
|
|
42
|
+
const manifest = readPackage(packageFile);
|
|
43
|
+
const base = {
|
|
44
|
+
productRoot: root,
|
|
45
|
+
package: manifest?.name || null,
|
|
46
|
+
version: manifest?.version || null,
|
|
47
|
+
};
|
|
48
|
+
if (manifest?.name !== '@buildr-ai/buildr') {
|
|
49
|
+
return { ...base, mode: 'unknown', installPrefix: null, blockingReasons: ['当前 executable 的产品根没有声明 @buildr-ai/buildr package identity。'] };
|
|
50
|
+
}
|
|
51
|
+
const gitRoot = run('git', ['-C', root, 'rev-parse', '--show-toplevel']);
|
|
52
|
+
if (gitRoot.ok) {
|
|
53
|
+
const resolvedGitRoot = fs.realpathSync(path.resolve(gitRoot.stdout));
|
|
54
|
+
return { ...base, mode: 'development-checkout', gitRoot: resolvedGitRoot, installPrefix: null, blockingReasons: [] };
|
|
55
|
+
}
|
|
56
|
+
const installPrefix = registryPrefixForProductRoot(root);
|
|
57
|
+
if (installPrefix) {
|
|
58
|
+
return { ...base, mode: 'registry-package', installPrefix, blockingReasons: [] };
|
|
59
|
+
}
|
|
60
|
+
return { ...base, mode: 'unknown', installPrefix: null, blockingReasons: ['无法证明当前 executable 来自 Buildr Git checkout 或支持的 npm global prefix。'] };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function gitValue(root, args) {
|
|
64
|
+
const result = run('git', ['-C', root, ...args]);
|
|
65
|
+
return result.ok ? result.stdout : null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function gitUpdatePlan(source, { fetch = true } = {}) {
|
|
69
|
+
const root = source.gitRoot;
|
|
70
|
+
const blockingReasons = [];
|
|
71
|
+
const branch = gitValue(root, ['symbolic-ref', '--quiet', '--short', 'HEAD']);
|
|
72
|
+
const head = gitValue(root, ['rev-parse', 'HEAD']);
|
|
73
|
+
const upstream = gitValue(root, ['rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{upstream}']);
|
|
74
|
+
const dirty = Boolean(gitValue(root, ['status', '--porcelain=v1', '--untracked-files=normal']));
|
|
75
|
+
if (!branch) blockingReasons.push('当前 checkout 处于 detached HEAD。');
|
|
76
|
+
if (!upstream) blockingReasons.push('当前 branch 没有 upstream。');
|
|
77
|
+
if (dirty) blockingReasons.push('当前 checkout 存在未提交改动。');
|
|
78
|
+
let fetchResult = null;
|
|
79
|
+
if (fetch && upstream && !dirty) {
|
|
80
|
+
fetchResult = run('git', ['-C', root, 'fetch', '--quiet']);
|
|
81
|
+
if (!fetchResult.ok) blockingReasons.push(`无法 fetch 远端:${fetchResult.stderr || fetchResult.error || 'unknown error'}`);
|
|
82
|
+
}
|
|
83
|
+
let ahead = null;
|
|
84
|
+
let behind = null;
|
|
85
|
+
if (upstream && (!fetchResult || fetchResult.ok)) {
|
|
86
|
+
const counts = gitValue(root, ['rev-list', '--left-right', '--count', `HEAD...${upstream}`]);
|
|
87
|
+
if (counts) [ahead, behind] = counts.split(/\s+/).map(Number);
|
|
88
|
+
}
|
|
89
|
+
let strategy = 'none';
|
|
90
|
+
if (blockingReasons.length === 0 && ahead === 0 && behind > 0) strategy = 'fast-forward';
|
|
91
|
+
else if (blockingReasons.length === 0 && ahead > 0 && behind > 0) {
|
|
92
|
+
const remoteContainsHead = run('git', ['-C', root, 'branch', '-r', '--contains', 'HEAD']);
|
|
93
|
+
if (remoteContainsHead.ok && remoteContainsHead.stdout) blockingReasons.push('当前 HEAD 已存在于远端分支,无法证明这些提交未共享。');
|
|
94
|
+
else strategy = 'rebase';
|
|
95
|
+
}
|
|
96
|
+
const status = blockingReasons.length ? 'blocked' : strategy === 'none' ? 'up-to-date' : 'update-available';
|
|
97
|
+
return {
|
|
98
|
+
mode: source.mode,
|
|
99
|
+
current: { version: source.version, productRoot: source.productRoot, gitRoot: root, branch, head, upstream, ahead, behind, dirty },
|
|
100
|
+
available: { upstream, commitsBehind: behind },
|
|
101
|
+
status,
|
|
102
|
+
strategy,
|
|
103
|
+
blockingReasons,
|
|
104
|
+
nextActions: blockingReasons.length
|
|
105
|
+
? ['处理上述 Git 状态后重新运行 buildr update check --json。']
|
|
106
|
+
: strategy === 'none'
|
|
107
|
+
? []
|
|
108
|
+
: ['运行 buildr update 更新 Buildr CLI;成功后由 Agent 按用户意图决定是否执行 buildr sync <agent>。'],
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function registryUpdatePlan(source) {
|
|
113
|
+
const blockingReasons = [];
|
|
114
|
+
const result = run('npm', ['view', source.package, 'version', '--json']);
|
|
115
|
+
let availableVersion = null;
|
|
116
|
+
if (!result.ok) blockingReasons.push(`无法查询 npm registry:${result.stderr || result.error || 'unknown error'}`);
|
|
117
|
+
else {
|
|
118
|
+
try { availableVersion = JSON.parse(result.stdout); } catch { blockingReasons.push('npm registry 返回了无法解析的版本。'); }
|
|
119
|
+
}
|
|
120
|
+
const updateAvailable = availableVersion && compareVersions(availableVersion, source.version) > 0;
|
|
121
|
+
return {
|
|
122
|
+
mode: source.mode,
|
|
123
|
+
current: { package: source.package, version: source.version, productRoot: source.productRoot, installPrefix: source.installPrefix },
|
|
124
|
+
available: { version: availableVersion },
|
|
125
|
+
status: blockingReasons.length ? 'blocked' : updateAvailable ? 'update-available' : 'up-to-date',
|
|
126
|
+
strategy: updateAvailable ? 'npm-install' : 'none',
|
|
127
|
+
blockingReasons,
|
|
128
|
+
nextActions: blockingReasons.length
|
|
129
|
+
? ['检查当前 npm registry、网络和安装 prefix 后重试。']
|
|
130
|
+
: updateAvailable
|
|
131
|
+
? ['运行 buildr update 更新 Buildr CLI;成功后由 Agent 按用户意图决定是否执行 buildr sync <agent>。']
|
|
132
|
+
: [],
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function buildCliUpdatePlan(productRoot, options = {}) {
|
|
137
|
+
const source = identifyCliSource(productRoot);
|
|
138
|
+
if (source.mode === 'development-checkout') return gitUpdatePlan(source, options);
|
|
139
|
+
if (source.mode === 'registry-package') return registryUpdatePlan(source);
|
|
140
|
+
return {
|
|
141
|
+
mode: 'unknown',
|
|
142
|
+
current: { package: source.package, version: source.version, productRoot: source.productRoot },
|
|
143
|
+
available: null,
|
|
144
|
+
status: 'blocked',
|
|
145
|
+
strategy: 'none',
|
|
146
|
+
blockingReasons: source.blockingReasons,
|
|
147
|
+
nextActions: ['使用 Buildr 开发 checkout 安装脚本或受支持的 npm registry package 重新安装 CLI。'],
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export function executeCliUpdatePlan(plan, options = {}) {
|
|
152
|
+
if (plan.status !== 'update-available') return { ok: plan.status === 'up-to-date', status: plan.status === 'up-to-date' ? 0 : 1, stdout: '', stderr: '', error: null };
|
|
153
|
+
return plan.mode === 'development-checkout'
|
|
154
|
+
? run('git', ['-C', plan.current.gitRoot, plan.strategy === 'fast-forward' ? 'merge' : 'rebase', ...(plan.strategy === 'fast-forward' ? ['--ff-only'] : []), plan.current.upstream], options)
|
|
155
|
+
: run(process.platform === 'win32' ? 'npm.cmd' : 'npm', ['install', '--global', '--prefix', plan.current.installPrefix, `${plan.current.package}@${plan.available.version}`], {
|
|
156
|
+
...options,
|
|
157
|
+
shell: process.platform === 'win32',
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function printPlan(plan, label) {
|
|
162
|
+
console.log(`${label}: ${plan.status}`);
|
|
163
|
+
console.log(`mode: ${plan.mode}`);
|
|
164
|
+
if (plan.current?.version) console.log(`current: ${plan.current.version}`);
|
|
165
|
+
if (plan.available?.version) console.log(`available: ${plan.available.version}`);
|
|
166
|
+
if (plan.current?.branch) console.log(`branch: ${plan.current.branch}`);
|
|
167
|
+
if (plan.current?.upstream) console.log(`upstream: ${plan.current.upstream}`);
|
|
168
|
+
for (const reason of plan.blockingReasons) console.log(`blocked: ${reason}`);
|
|
169
|
+
for (const action of plan.nextActions) console.log(`next: ${action}`);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function registerApplicationCliUpdate(runtime) {
|
|
173
|
+
const productRoot = (...args) => runtime.productRoot(...args);
|
|
174
|
+
const assertNoUnknownOptions = (...args) => runtime.assertNoUnknownOptions(...args);
|
|
175
|
+
const hasFlag = (...args) => runtime.hasFlag(...args);
|
|
176
|
+
|
|
177
|
+
function updateCheck(args) {
|
|
178
|
+
if (args.includes('--target')) throw new Error('buildr update 不接收 workspace --target;请使用 buildr sync <agent> --target <dir> 同步 workspace。');
|
|
179
|
+
assertNoUnknownOptions(args, new Set(['--json']));
|
|
180
|
+
const plan = buildCliUpdatePlan(productRoot());
|
|
181
|
+
if (hasFlag(args, '--json')) process.stdout.write(`${JSON.stringify(withJsonSchema(PUBLIC_JSON_SCHEMAS.updateCheck, plan), null, 2)}\n`);
|
|
182
|
+
else printPlan(plan, 'Buildr CLI update check');
|
|
183
|
+
if (plan.status === 'blocked') process.exitCode = 1;
|
|
184
|
+
return plan;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function updateBuildr(args) {
|
|
188
|
+
if (args.includes('--target')) throw new Error('buildr update 不接收 workspace --target;请使用 buildr sync <agent> --target <dir> 同步 workspace。');
|
|
189
|
+
assertNoUnknownOptions(args, new Set(['--json']));
|
|
190
|
+
const json = hasFlag(args, '--json');
|
|
191
|
+
const plan = buildCliUpdatePlan(productRoot());
|
|
192
|
+
if (plan.status === 'blocked') {
|
|
193
|
+
if (json) process.stdout.write(`${JSON.stringify(withJsonSchema(PUBLIC_JSON_SCHEMAS.update, plan), null, 2)}\n`);
|
|
194
|
+
else printPlan(plan, 'Buildr CLI update');
|
|
195
|
+
process.exitCode = 1;
|
|
196
|
+
return plan;
|
|
197
|
+
}
|
|
198
|
+
if (plan.status === 'up-to-date') {
|
|
199
|
+
if (json) process.stdout.write(`${JSON.stringify(withJsonSchema(PUBLIC_JSON_SCHEMAS.update, plan), null, 2)}\n`);
|
|
200
|
+
else printPlan(plan, 'Buildr CLI update');
|
|
201
|
+
return plan;
|
|
202
|
+
}
|
|
203
|
+
const result = executeCliUpdatePlan(plan);
|
|
204
|
+
if (!result.ok) {
|
|
205
|
+
const failed = { ...plan, status: 'blocked', blockingReasons: [`CLI 更新失败:${result.stderr || result.error || 'unknown error'}`], nextActions: plan.mode === 'development-checkout' && plan.strategy === 'rebase' ? ['检查 Git rebase 状态并决定继续或中止;Buildr 不会自动解决冲突。'] : ['处理安装错误后重新运行 buildr update。'] };
|
|
206
|
+
if (json) process.stdout.write(`${JSON.stringify(withJsonSchema(PUBLIC_JSON_SCHEMAS.update, failed), null, 2)}\n`);
|
|
207
|
+
else printPlan(failed, 'Buildr CLI update');
|
|
208
|
+
process.exitCode = 1;
|
|
209
|
+
return failed;
|
|
210
|
+
}
|
|
211
|
+
const completed = { ...plan, status: 'updated', blockingReasons: [], nextActions: ['CLI 已更新。若用户要求完整更新 Buildr,重新解析 buildr 入口并运行 buildr sync <agent> --target <workspace>。'] };
|
|
212
|
+
if (json) process.stdout.write(`${JSON.stringify(withJsonSchema(PUBLIC_JSON_SCHEMAS.update, completed), null, 2)}\n`);
|
|
213
|
+
else printPlan(completed, 'Buildr CLI update');
|
|
214
|
+
return completed;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
Object.assign(runtime, { updateCheck, updateBuildr });
|
|
218
|
+
return runtime;
|
|
219
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { registerSharedInfrastructure } from '../shared/infrastructure.mjs';
|
|
2
|
+
import { registerDomainsRuntime } from '../domains/runtime.mjs';
|
|
3
|
+
import { registerDomainsWorkspace } from '../domains/workspace.mjs';
|
|
4
|
+
import { registerDomainsComponents } from '../domains/components.mjs';
|
|
5
|
+
import { registerDomainsCommands } from '../domains/commands.mjs';
|
|
6
|
+
import { registerDomainsRules } from '../domains/rules.mjs';
|
|
7
|
+
import { registerDomainsOpenspec } from '../domains/openspec.mjs';
|
|
8
|
+
import { registerApplicationDoctor } from '../application/doctor.mjs';
|
|
9
|
+
import { registerDomainsPackageAssets } from '../domains/package-assets.mjs';
|
|
10
|
+
import { registerDomainsSkills } from '../domains/skills.mjs';
|
|
11
|
+
import { registerApplicationPackageMaintenance } from '../application/package-maintenance.mjs';
|
|
12
|
+
import { registerApplicationWorkspaceOperations } from '../application/workspace-operations.mjs';
|
|
13
|
+
import { registerApplicationRuntime } from '../application/runtime.mjs';
|
|
14
|
+
import { registerApplicationCliUpdate } from '../application/cli-update.mjs';
|
|
15
|
+
import * as platform from '../shared/platform.mjs';
|
|
16
|
+
|
|
17
|
+
const REGISTRATIONS = [
|
|
18
|
+
registerSharedInfrastructure,
|
|
19
|
+
registerDomainsRuntime,
|
|
20
|
+
registerDomainsWorkspace,
|
|
21
|
+
registerDomainsComponents,
|
|
22
|
+
registerDomainsCommands,
|
|
23
|
+
registerDomainsRules,
|
|
24
|
+
registerDomainsOpenspec,
|
|
25
|
+
registerApplicationDoctor,
|
|
26
|
+
registerDomainsPackageAssets,
|
|
27
|
+
registerDomainsSkills,
|
|
28
|
+
registerApplicationPackageMaintenance,
|
|
29
|
+
registerApplicationWorkspaceOperations,
|
|
30
|
+
registerApplicationCliUpdate,
|
|
31
|
+
registerApplicationRuntime,
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
export function createRuntime() {
|
|
35
|
+
const runtime = { ...platform };
|
|
36
|
+
for (const register of REGISTRATIONS) register(runtime);
|
|
37
|
+
return runtime;
|
|
38
|
+
}
|
|
@@ -0,0 +1,226 @@
|
|
|
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) => agent === 'claude-code' ? 'claudeCode' : 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
|
+
command: 'buildr doctor',
|
|
71
|
+
});
|
|
72
|
+
const findings = dedupeFindings(agent, runtimeFindingsForDoctor(check.findings, includeInfo));
|
|
73
|
+
result.runtime[resultKey].push({ agent, scope, counts: summarizeRuntimeFindings(findings), findings });
|
|
74
|
+
if (findings.some((finding) => ['missing', 'stale', 'orphan'].includes(finding.status))) {
|
|
75
|
+
addDoctorFinding(result, 'warning', `runtime.${codeId}_stale`, `${adapter.displayName} runtime 缺失或过期:${scope}`, {
|
|
76
|
+
path: toPosixRelative(targetRoot, check.targetRoot),
|
|
77
|
+
agent,
|
|
78
|
+
suggestion: `按 doctor 输出的修复命令同步 ${adapter.displayName} runtime;需要 adapter 细节时再运行 runtime check。`,
|
|
79
|
+
commands: check.repairCommands,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
if (findings.some((finding) => finding.status === 'warning')) {
|
|
83
|
+
addDoctorFinding(result, 'warning', `runtime.${codeId}_warning`, `${adapter.displayName} runtime 存在警告:${scope}`, {
|
|
84
|
+
path: toPosixRelative(targetRoot, check.targetRoot),
|
|
85
|
+
agent,
|
|
86
|
+
suggestion: '优先查看 doctor 输出中的 runtime findings;需要 adapter 细节时再运行 runtime check。',
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (findings.some((finding) => finding.status === 'conflict')) {
|
|
90
|
+
addDoctorFinding(result, 'error', `runtime.${codeId}_conflict`, `${adapter.displayName} runtime 存在非 Buildr 管理或冲突文件:${scope}`, {
|
|
91
|
+
path: toPosixRelative(targetRoot, check.targetRoot),
|
|
92
|
+
agent,
|
|
93
|
+
suggestion: '将手写内容迁移回 Buildr 资产源,再重新 render。',
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
if (includeInfo) {
|
|
97
|
+
for (const finding of findings.filter((item) => item.status === 'info')) {
|
|
98
|
+
addDoctorFinding(result, 'info', finding.code ?? 'runtime.info', finding.message, {
|
|
99
|
+
path: finding.path,
|
|
100
|
+
agent,
|
|
101
|
+
impact: finding.impact,
|
|
102
|
+
userActionRequired: finding.userActionRequired,
|
|
103
|
+
repair: finding.repair,
|
|
104
|
+
suggestion: finding.suggestion,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
} catch (error) {
|
|
109
|
+
const missingManifest = error.message.startsWith('Manifest not found:');
|
|
110
|
+
const missingCode = agent === 'claude-code' ? 'runtime.skills_manifest_absent' : `runtime.${codeId}_skills_manifest_absent`;
|
|
111
|
+
addDoctorFinding(result, missingManifest ? 'ok' : 'error', missingManifest ? missingCode : `runtime.${codeId}_unchecked`, missingManifest ? `未声明 ${adapter.displayName} Skills manifest,跳过 Skills runtime 检查:${scope}` : `无法检查 ${adapter.displayName} runtime:${scope}`, missingManifest ? {} : {
|
|
112
|
+
agent,
|
|
113
|
+
suggestion: error.message,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function diagnoseCommands(result, targetRoot) {
|
|
121
|
+
const commandsResult = runCommandsCheck(targetRoot);
|
|
122
|
+
result.commandLineTools = commandsResult;
|
|
123
|
+
for (const finding of commandsResult.findings) {
|
|
124
|
+
addDoctorFinding(result, finding.status, finding.code, finding.message, {
|
|
125
|
+
path: finding.path,
|
|
126
|
+
suggestion: finding.suggestion,
|
|
127
|
+
installHint: finding.installHint,
|
|
128
|
+
commandId: finding.commandId,
|
|
129
|
+
executable: finding.executable,
|
|
130
|
+
sources: finding.sources,
|
|
131
|
+
expected: finding.expected,
|
|
132
|
+
actual: finding.actual,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function diagnoseComponents(result, targetRoot, includeInfo = false, selectedAgent = null) {
|
|
138
|
+
if (!existsFile(componentRegistryPath(targetRoot))) {
|
|
139
|
+
addDoctorFinding(result, 'warning', 'components.registry_missing', 'Component registry 缺失。', {
|
|
140
|
+
path: 'components/manifest.yml',
|
|
141
|
+
suggestion: `运行 buildr sync <agent> --target ${targetRoot} 创建 registry、迁移默认 Component 并准备当前 Agent runtime。`,
|
|
142
|
+
command: `buildr sync <agent> --target ${targetRoot}`,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
let status;
|
|
146
|
+
try {
|
|
147
|
+
status = packageComponentsStatus(targetRoot);
|
|
148
|
+
} catch (error) {
|
|
149
|
+
result.components = { items: [], ownership: {}, findings: [] };
|
|
150
|
+
addDoctorFinding(result, 'error', 'components.registry_invalid', error.message, {
|
|
151
|
+
path: 'components/manifest.yml',
|
|
152
|
+
suggestion: '修复 Component registry 后重新运行 doctor。',
|
|
153
|
+
});
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
result.components = {
|
|
157
|
+
items: status.components,
|
|
158
|
+
ownership: Object.fromEntries(status.ownership),
|
|
159
|
+
findings: status.findings,
|
|
160
|
+
};
|
|
161
|
+
for (const finding of status.findings) {
|
|
162
|
+
addDoctorFinding(result, 'error', finding.code || 'components.invalid', finding.message || `Component ownership conflict: ${finding.member || ''}`, {
|
|
163
|
+
path: finding.member || 'components/manifest.yml',
|
|
164
|
+
componentId: finding.componentId,
|
|
165
|
+
owners: finding.owners,
|
|
166
|
+
suggestion: '修复 Component definition、成员路径或唯一所有权冲突后重试。',
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
for (const item of status.components) {
|
|
170
|
+
if (['invalid', 'modified', 'missing'].includes(item.status)) {
|
|
171
|
+
addDoctorFinding(result, 'error', `components.${item.status}`, `Component ${item.id} 状态异常:${item.status}`, {
|
|
172
|
+
path: `components/${item.id}`,
|
|
173
|
+
componentId: item.id,
|
|
174
|
+
error: item.error,
|
|
175
|
+
members: item.members,
|
|
176
|
+
suggestion: item.status === 'missing'
|
|
177
|
+
? `运行 buildr component install ${item.id} --agent <agent> --target ${targetRoot},或确认是否应保留卸载状态。`
|
|
178
|
+
: '检查成员差异;不要通过单项资产命令覆盖 Component 成员。',
|
|
179
|
+
});
|
|
180
|
+
} else if (item.status === 'update-available') {
|
|
181
|
+
addDoctorFinding(result, 'warning', 'components.update_available', `Component ${item.id} 有可用更新。`, {
|
|
182
|
+
componentId: item.id,
|
|
183
|
+
expected: item.availableVersion,
|
|
184
|
+
actual: item.installedVersion,
|
|
185
|
+
suggestion: '运行 buildr update,或通过当前 Agent 执行 buildr sync <agent>。',
|
|
186
|
+
});
|
|
187
|
+
} else if (includeInfo) {
|
|
188
|
+
addDoctorFinding(result, 'info', `components.${item.status}`, `Component ${item.id}:${item.status}`, {
|
|
189
|
+
componentId: item.id,
|
|
190
|
+
installedVersion: item.installedVersion,
|
|
191
|
+
availableVersion: item.availableVersion,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
const uninstalledOwners = new Map();
|
|
196
|
+
for (const item of status.components.filter((component) => component.status === 'uninstalled')) {
|
|
197
|
+
for (const member of item.members.filter((entry) => entry.path.startsWith('skills/'))) uninstalledOwners.set(path.basename(member.path), item.id);
|
|
198
|
+
}
|
|
199
|
+
const componentRuntimeAgents = selectedAgent
|
|
200
|
+
? isSupportedAgent(selectedAgent) ? [selectedAgent] : []
|
|
201
|
+
: SUPPORTED_AGENT_IDS;
|
|
202
|
+
for (const agent of componentRuntimeAgents) {
|
|
203
|
+
for (const orphan of managedRuntimeSkillOrphans(targetRoot, agent)) {
|
|
204
|
+
const componentId = uninstalledOwners.get(orphan.runtimePath) || null;
|
|
205
|
+
addDoctorFinding(result, 'warning', 'components.runtime_orphan', componentId
|
|
206
|
+
? `已卸载 Component ${componentId} 仍有 ${agent} runtime Skill 投射:${orphan.runtimePath}`
|
|
207
|
+
: `Buildr-managed ${agent} runtime Skill 没有有效源资产:${orphan.runtimePath}`, {
|
|
208
|
+
path: orphan.path,
|
|
209
|
+
componentId,
|
|
210
|
+
agent,
|
|
211
|
+
suggestion: `运行 buildr render ${agent} --scope . --target ${targetRoot} 清理受管 runtime orphan。`,
|
|
212
|
+
command: `buildr render ${agent} --scope . --target ${targetRoot}`,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return {
|
|
219
|
+
runtimeFindingsForDoctor,
|
|
220
|
+
summarizeRuntimeFindings,
|
|
221
|
+
addUnsupportedAgentFinding,
|
|
222
|
+
diagnoseRuntime,
|
|
223
|
+
diagnoseCommands,
|
|
224
|
+
diagnoseComponents,
|
|
225
|
+
};
|
|
226
|
+
}
|