@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,310 @@
|
|
|
1
|
+
import {
|
|
2
|
+
fs,
|
|
3
|
+
path,
|
|
4
|
+
process,
|
|
5
|
+
SUPPORTED_AGENT_IDS,
|
|
6
|
+
UNSUPPORTED_AGENT_GUIDANCE,
|
|
7
|
+
isSupportedAgent,
|
|
8
|
+
} from '../shared/platform.mjs';
|
|
9
|
+
import { PUBLIC_JSON_SCHEMAS, withJsonSchema } from '../shared/json-contracts.mjs';
|
|
10
|
+
|
|
11
|
+
export function registerApplicationWorkspaceOperations(runtime) {
|
|
12
|
+
const discoverDoctorScopes = (...args) => runtime.discoverDoctorScopes(...args);
|
|
13
|
+
const diagnoseProjectRegistry = (...args) => runtime.diagnoseProjectRegistry(...args);
|
|
14
|
+
const diagnoseWorkspace = (...args) => runtime.diagnoseWorkspace(...args);
|
|
15
|
+
const diagnoseLegacyPractices = (...args) => runtime.diagnoseLegacyPractices(...args);
|
|
16
|
+
const diagnoseHierarchy = (...args) => runtime.diagnoseHierarchy(...args);
|
|
17
|
+
const diagnoseServices = (...args) => runtime.diagnoseServices(...args);
|
|
18
|
+
const diagnoseRuntime = (...args) => runtime.diagnoseRuntime(...args);
|
|
19
|
+
const diagnoseCommands = (...args) => runtime.diagnoseCommands(...args);
|
|
20
|
+
const diagnoseComponents = (...args) => runtime.diagnoseComponents(...args);
|
|
21
|
+
const diagnoseSkillsManifestSchemas = (...args) => runtime.diagnoseSkillsManifestSchemas(...args);
|
|
22
|
+
const syncPackageBuiltins = (...args) => runtime.syncPackageBuiltins(...args);
|
|
23
|
+
const finalizeDoctorResult = (...args) => runtime.finalizeDoctorResult(...args);
|
|
24
|
+
const printDoctorReport = (...args) => runtime.printDoctorReport(...args);
|
|
25
|
+
const positionalArgs = (...args) => runtime.positionalArgs(...args);
|
|
26
|
+
const syncPackageComponents = (...args) => runtime.syncPackageComponents(...args);
|
|
27
|
+
const readPackageManifest = (...args) => runtime.readPackageManifest(...args);
|
|
28
|
+
const parseManifestFileEntry = (...args) => runtime.parseManifestFileEntry(...args);
|
|
29
|
+
const diagnoseRules = (...args) => runtime.diagnoseRules(...args);
|
|
30
|
+
const assertName = (...args) => runtime.assertName(...args);
|
|
31
|
+
const assertAgentId = (...args) => runtime.assertAgentId(...args);
|
|
32
|
+
const renderSkillsManifestYaml = (...args) => runtime.renderSkillsManifestYaml(...args);
|
|
33
|
+
const trackWrite = (...args) => runtime.trackWrite(...args);
|
|
34
|
+
const printResult = (...args) => runtime.printResult(...args);
|
|
35
|
+
const optionValue = (...args) => runtime.optionValue(...args);
|
|
36
|
+
const ensureDirectory = (...args) => runtime.ensureDirectory(...args);
|
|
37
|
+
const mutationStateRoot = (...args) => runtime.mutationStateRoot(...args);
|
|
38
|
+
const mutationLockPath = (...args) => runtime.mutationLockPath(...args);
|
|
39
|
+
const withWorkspaceMutation = (...args) => runtime.withWorkspaceMutation(...args);
|
|
40
|
+
const packageRoot = (...args) => runtime.packageRoot(...args);
|
|
41
|
+
const writeMappedFileIfMissing = (...args) => runtime.writeMappedFileIfMissing(...args);
|
|
42
|
+
const appendGitignoreEntries = (...args) => runtime.appendGitignoreEntries(...args);
|
|
43
|
+
const hasFlag = (...args) => runtime.hasFlag(...args);
|
|
44
|
+
const toPosixRelative = (...args) => runtime.toPosixRelative(...args);
|
|
45
|
+
const existsDirectory = (...args) => runtime.existsDirectory(...args);
|
|
46
|
+
const existsFile = (...args) => runtime.existsFile(...args);
|
|
47
|
+
const ensureRootRequiredBlock = (...args) => runtime.ensureRootRequiredBlock(...args);
|
|
48
|
+
const assertInitializedBuildrWorkspace = (...args) => runtime.assertInitializedBuildrWorkspace(...args);
|
|
49
|
+
const addDoctorFinding = (...args) => runtime.addDoctorFinding(...args);
|
|
50
|
+
|
|
51
|
+
function bootstrapGuide() {
|
|
52
|
+
const guidePath = path.join(packageRoot(), 'bootstrap', 'guide.md');
|
|
53
|
+
if (!existsFile(guidePath)) {
|
|
54
|
+
throw new Error(`Bootstrap guide not found: ${guidePath}`);
|
|
55
|
+
}
|
|
56
|
+
process.stdout.write(fs.readFileSync(guidePath, 'utf8'));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function mutationTransactions(targetRoot) {
|
|
60
|
+
const stateRoot = mutationStateRoot(targetRoot);
|
|
61
|
+
if (!existsDirectory(stateRoot)) return [];
|
|
62
|
+
return fs.readdirSync(stateRoot, { withFileTypes: true })
|
|
63
|
+
.filter((entry) => entry.isDirectory())
|
|
64
|
+
.map((entry) => {
|
|
65
|
+
const transactionRoot = path.join(stateRoot, entry.name);
|
|
66
|
+
const journalFile = path.join(transactionRoot, 'journal.json');
|
|
67
|
+
let journal = null;
|
|
68
|
+
let parseError = null;
|
|
69
|
+
try { journal = JSON.parse(fs.readFileSync(journalFile, 'utf8')); } catch (error) { parseError = error.message; }
|
|
70
|
+
return { id: entry.name, transactionRoot, journalFile, journal, parseError };
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function diagnoseMutations(result, targetRoot) {
|
|
75
|
+
const lockFile = mutationLockPath(targetRoot);
|
|
76
|
+
let lock = null;
|
|
77
|
+
if (existsFile(lockFile)) {
|
|
78
|
+
try { lock = JSON.parse(fs.readFileSync(lockFile, 'utf8')); } catch { lock = { invalid: true }; }
|
|
79
|
+
}
|
|
80
|
+
const transactions = mutationTransactions(targetRoot);
|
|
81
|
+
result.mutations = { blocked: Boolean(lock || transactions.length), lock, transactions: transactions.map((item) => ({ id: item.id, operation: item.journal?.operation || null, phase: item.journal?.phase || null, affectedPaths: item.journal?.affectedPaths || [], parseError: item.parseError })) };
|
|
82
|
+
for (const transaction of transactions) {
|
|
83
|
+
addDoctorFinding(result, 'error', 'mutation.transaction_incomplete', `检测到未完成 Buildr source mutation:${transaction.id}`, {
|
|
84
|
+
path: toPosixRelative(targetRoot, transaction.transactionRoot),
|
|
85
|
+
transactionId: transaction.id,
|
|
86
|
+
operation: transaction.journal?.operation || lock?.operation || null,
|
|
87
|
+
phase: transaction.journal?.phase || lock?.phase || 'unknown',
|
|
88
|
+
affectedPaths: transaction.journal?.affectedPaths || lock?.affectedPaths || [],
|
|
89
|
+
suggestion: transaction.parseError ? '保留 transaction 目录并人工检查损坏 journal。' : '运行 mutation recover 恢复操作前源资产;恢复前不要删除 backup。',
|
|
90
|
+
command: transaction.parseError ? undefined : `buildr mutation recover ${transaction.id} --target ${targetRoot}`,
|
|
91
|
+
userActionRequired: true,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
if (lock && transactions.length === 0) {
|
|
95
|
+
addDoctorFinding(result, 'error', 'mutation.lock_orphaned', '检测到没有 transaction journal 的 mutation lock。', {
|
|
96
|
+
path: toPosixRelative(targetRoot, lockFile),
|
|
97
|
+
operation: lock.operation || null,
|
|
98
|
+
suggestion: '保留 lock 并检查 workspace;无法证明状态前不要继续 source mutation。',
|
|
99
|
+
userActionRequired: true,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function mutationRecover(args) {
|
|
105
|
+
const [id] = positionalArgs(args);
|
|
106
|
+
if (!id) throw new Error('Missing mutation transaction id.');
|
|
107
|
+
assertName(id, 'Mutation transaction id');
|
|
108
|
+
const targetRoot = path.resolve(optionValue(args, '--target', process.cwd()));
|
|
109
|
+
const transactionRoot = path.join(mutationStateRoot(targetRoot), id);
|
|
110
|
+
const journalFile = path.join(transactionRoot, 'journal.json');
|
|
111
|
+
if (!existsFile(journalFile)) throw new Error(`Mutation transaction journal not found: ${id}`);
|
|
112
|
+
const journal = JSON.parse(fs.readFileSync(journalFile, 'utf8'));
|
|
113
|
+
if (journal.schemaVersion !== 'buildr.mutation/v1' || journal.transactionId !== id || !Array.isArray(journal.snapshots)) throw new Error(`Mutation transaction journal is invalid: ${id}`);
|
|
114
|
+
const lockFile = mutationLockPath(targetRoot);
|
|
115
|
+
let lock = null;
|
|
116
|
+
if (existsFile(lockFile)) {
|
|
117
|
+
lock = JSON.parse(fs.readFileSync(lockFile, 'utf8'));
|
|
118
|
+
if (lock.transactionId !== id) throw new Error(`Mutation lock belongs to another transaction: ${lock.transactionId}`);
|
|
119
|
+
}
|
|
120
|
+
const restorePlan = [...journal.snapshots].reverse().map((snapshot) => {
|
|
121
|
+
const target = path.resolve(snapshot.target);
|
|
122
|
+
const relative = path.relative(targetRoot, target);
|
|
123
|
+
if (!relative || relative.startsWith('..') || path.isAbsolute(relative) || relative.startsWith(`.buildr${path.sep}mutations`)) throw new Error(`Mutation recovery target is unsafe: ${snapshot.target}`);
|
|
124
|
+
const backup = path.join(transactionRoot, 'backup', String(snapshot.index));
|
|
125
|
+
if (snapshot.existed && !fs.existsSync(backup)) throw new Error(`Mutation backup is missing for ${snapshot.relative}`);
|
|
126
|
+
return { ...snapshot, target, backup };
|
|
127
|
+
});
|
|
128
|
+
for (const snapshot of restorePlan) {
|
|
129
|
+
const { target, backup } = snapshot;
|
|
130
|
+
if (fs.existsSync(target)) fs.rmSync(target, { recursive: true, force: true });
|
|
131
|
+
if (snapshot.existed) {
|
|
132
|
+
ensureDirectory(path.dirname(target));
|
|
133
|
+
fs.cpSync(backup, target, { recursive: true, preserveTimestamps: true });
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
fs.rmSync(transactionRoot, { recursive: true, force: true });
|
|
137
|
+
if (lock) fs.rmSync(lockFile, { force: true });
|
|
138
|
+
console.log(`已恢复 Buildr source mutation:${id}`);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function doctor(args) {
|
|
142
|
+
const targetRoot = path.resolve(optionValue(args, '--target', process.cwd()));
|
|
143
|
+
const requestedScope = optionValue(args, '--scope', null);
|
|
144
|
+
const requestedAgent = optionValue(args, '--agent', null);
|
|
145
|
+
if (requestedAgent !== null) assertAgentId(requestedAgent);
|
|
146
|
+
const json = hasFlag(args, '--json');
|
|
147
|
+
const includeInfo = hasFlag(args, '--include-info') || hasFlag(args, '--verbose');
|
|
148
|
+
const result = {
|
|
149
|
+
targetRoot,
|
|
150
|
+
scope: requestedScope || null,
|
|
151
|
+
agentRuntime: requestedAgent
|
|
152
|
+
? {
|
|
153
|
+
requested: requestedAgent,
|
|
154
|
+
supported: isSupportedAgent(requestedAgent),
|
|
155
|
+
selected: isSupportedAgent(requestedAgent) ? requestedAgent : null,
|
|
156
|
+
supportedAgents: SUPPORTED_AGENT_IDS,
|
|
157
|
+
mustNotUseFallbackAdapter: !isSupportedAgent(requestedAgent) || undefined,
|
|
158
|
+
}
|
|
159
|
+
: {
|
|
160
|
+
requested: null,
|
|
161
|
+
supported: null,
|
|
162
|
+
selected: null,
|
|
163
|
+
supportedAgents: SUPPORTED_AGENT_IDS,
|
|
164
|
+
compatibilityMode: true,
|
|
165
|
+
},
|
|
166
|
+
ok: true,
|
|
167
|
+
summary: { ok: 0, info: 0, warning: 0, error: 0 },
|
|
168
|
+
workspace: null,
|
|
169
|
+
projectRegistry: null,
|
|
170
|
+
organizations: [],
|
|
171
|
+
projects: [],
|
|
172
|
+
services: [],
|
|
173
|
+
components: { items: [], ownership: {}, findings: [] },
|
|
174
|
+
builtins: { items: [] },
|
|
175
|
+
commandLineTools: null,
|
|
176
|
+
runtime: { claudeCode: [], codex: [] },
|
|
177
|
+
mutations: { blocked: false, lock: null, transactions: [] },
|
|
178
|
+
findings: [],
|
|
179
|
+
nextSteps: [],
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
diagnoseWorkspace(result, targetRoot);
|
|
183
|
+
diagnoseMutations(result, targetRoot);
|
|
184
|
+
if (result.workspace?.initialized) diagnoseRules(result, targetRoot);
|
|
185
|
+
const registry = diagnoseProjectRegistry(result, targetRoot);
|
|
186
|
+
const scopes = discoverDoctorScopes(targetRoot, requestedScope, registry);
|
|
187
|
+
if (result.workspace?.initialized && scopes.length === 0) {
|
|
188
|
+
addDoctorFinding(result, 'warning', 'workspace.empty', 'Buildr root 尚未创建项目。', {
|
|
189
|
+
path: targetRoot,
|
|
190
|
+
suggestion: '按需创建项目;共享或基础服务也应放入某个项目,例如 foundation。',
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
diagnoseLegacyPractices(result, targetRoot, scopes, includeInfo);
|
|
194
|
+
diagnoseHierarchy(result, targetRoot, scopes, registry);
|
|
195
|
+
diagnoseServices(result, targetRoot, scopes);
|
|
196
|
+
diagnoseSkillsManifestSchemas(result, targetRoot, scopes);
|
|
197
|
+
if (result.workspace?.initialized) {
|
|
198
|
+
try {
|
|
199
|
+
const builtinStatus = syncPackageBuiltins(targetRoot, { checkOnly: true });
|
|
200
|
+
result.builtins.items = builtinStatus.findings;
|
|
201
|
+
for (const finding of builtinStatus.findings.filter((item) => !item.component)) {
|
|
202
|
+
if (finding.status === 'installed' || (finding.status === 'uninstalled' && !includeInfo)) continue;
|
|
203
|
+
const status = finding.status === 'uninstalled' ? 'info' : 'warning';
|
|
204
|
+
addDoctorFinding(result, status, `builtin.${finding.status}`, `Buildr builtin ${finding.type}:${finding.id} 状态为 ${finding.status}。`, {
|
|
205
|
+
path: finding.path,
|
|
206
|
+
suggestion: finding.status === 'uninstalled' ? '这是显式卸载状态;需要恢复时运行 builtin restore。' : `检查差异;确认放弃本地内容时运行 buildr builtin restore ${finding.id} --target ${targetRoot}。`,
|
|
207
|
+
command: finding.status === 'uninstalled' ? `buildr builtin restore ${finding.id} --target ${targetRoot}` : undefined,
|
|
208
|
+
userActionRequired: finding.status !== 'uninstalled',
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
} catch (error) {
|
|
212
|
+
addDoctorFinding(result, 'error', 'builtin.receipt_invalid', `Builtin 安装回执无效:${error.message}`, {
|
|
213
|
+
path: '.buildr/builtin-receipts.json',
|
|
214
|
+
suggestion: '保留回执与 live 资产并检查损坏;无法证明安装状态前不要继续 sync。',
|
|
215
|
+
userActionRequired: true,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
diagnoseComponents(result, targetRoot, includeInfo, requestedAgent);
|
|
220
|
+
diagnoseCommands(result, targetRoot);
|
|
221
|
+
diagnoseRuntime(result, targetRoot, scopes, { includeInfo, agent: requestedAgent });
|
|
222
|
+
finalizeDoctorResult(result);
|
|
223
|
+
|
|
224
|
+
if (json) {
|
|
225
|
+
process.stdout.write(`${JSON.stringify(withJsonSchema(PUBLIC_JSON_SCHEMAS.doctor, result), null, 2)}\n`);
|
|
226
|
+
} else {
|
|
227
|
+
printDoctorReport(result);
|
|
228
|
+
}
|
|
229
|
+
process.exitCode = result.ok ? 0 : 1;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function initBuildr(args) {
|
|
233
|
+
const targetRoot = path.resolve(optionValue(args, '--target', process.cwd()));
|
|
234
|
+
const name = optionValue(args, '--name', path.basename(targetRoot));
|
|
235
|
+
const profile = optionValue(args, '--profile', 'team');
|
|
236
|
+
const agent = optionValue(args, '--agent', null);
|
|
237
|
+
assertName(name, 'Workspace name');
|
|
238
|
+
assertName(profile, 'Workspace profile');
|
|
239
|
+
if (agent !== null) {
|
|
240
|
+
assertAgentId(agent);
|
|
241
|
+
if (!isSupportedAgent(agent)) {
|
|
242
|
+
throw new Error(`Unsupported Agent runtime: ${agent}. Supported Agent runtime adapters: ${SUPPORTED_AGENT_IDS.join(', ')}. ${UNSUPPORTED_AGENT_GUIDANCE.message}${UNSUPPORTED_AGENT_GUIDANCE.nextStep}`);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const manifest = readPackageManifest();
|
|
246
|
+
const created = [];
|
|
247
|
+
const changed = [];
|
|
248
|
+
|
|
249
|
+
ensureDirectory(targetRoot);
|
|
250
|
+
for (const relativeDir of manifest.workspaceDirectories) {
|
|
251
|
+
ensureDirectory(path.join(targetRoot, relativeDir));
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const variables = { name, profile };
|
|
255
|
+
for (const rawEntry of manifest.workspaceFiles) {
|
|
256
|
+
const entry = parseManifestFileEntry(rawEntry, 'workspaceFiles');
|
|
257
|
+
writeMappedFileIfMissing(targetRoot, targetRoot, entry, variables, created);
|
|
258
|
+
}
|
|
259
|
+
ensureRootRequiredBlock(targetRoot, changed);
|
|
260
|
+
trackWrite(targetRoot, path.join(targetRoot, 'skills', 'manifest.yml'), renderSkillsManifestYaml([]), created);
|
|
261
|
+
const componentResult = syncPackageComponents(targetRoot);
|
|
262
|
+
if (componentResult.errors.length) throw new Error(componentResult.errors.map((item) => item.error).join('\n'));
|
|
263
|
+
changed.push(...componentResult.changed);
|
|
264
|
+
|
|
265
|
+
const gitignoreChanged = appendGitignoreEntries(path.join(targetRoot, '.gitignore'), [
|
|
266
|
+
'# Agent runtime directories generated by Buildr',
|
|
267
|
+
'CLAUDE.md',
|
|
268
|
+
'.claude/',
|
|
269
|
+
'.agents/',
|
|
270
|
+
'.trae/',
|
|
271
|
+
'.cursor/',
|
|
272
|
+
'.qoder/',
|
|
273
|
+
'# Buildr transaction state',
|
|
274
|
+
'/.buildr/mutations/',
|
|
275
|
+
'# Task worktrees',
|
|
276
|
+
'/.worktrees/',
|
|
277
|
+
]);
|
|
278
|
+
if (gitignoreChanged) changed.push('.gitignore');
|
|
279
|
+
|
|
280
|
+
console.log(`Initialized Buildr root organization context at ${targetRoot}`);
|
|
281
|
+
console.log(`Name: ${name}`);
|
|
282
|
+
console.log(`Profile: ${profile}`);
|
|
283
|
+
printResult('Workspace assets initialized', targetRoot, created, changed);
|
|
284
|
+
if (agent !== null) {
|
|
285
|
+
console.log('');
|
|
286
|
+
console.log(`正在准备 ${agent} runtime;该步骤复用 buildr sync ${agent} 并执行最终 doctor。`);
|
|
287
|
+
try {
|
|
288
|
+
runtime.syncRuntime(agent, ['--target', targetRoot]);
|
|
289
|
+
} catch (error) {
|
|
290
|
+
throw new Error(`Workspace 源资产已初始化,但 ${agent} onboarding 未完成。\n修复问题后运行:buildr sync ${agent} --target ${targetRoot}\n原因:${error.message}`);
|
|
291
|
+
}
|
|
292
|
+
console.log(`Buildr onboarding 已完成:${agent}(包含 sync 与最终 doctor)。`);
|
|
293
|
+
console.log(`下一步可按需创建 Project:buildr project create <project> --target ${targetRoot}`);
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
console.log('');
|
|
297
|
+
console.log('仅初始化源资产的后续步骤:');
|
|
298
|
+
console.log(' buildr runtime list --json');
|
|
299
|
+
console.log(` buildr sync <agent> --target ${targetRoot}`);
|
|
300
|
+
console.log(` buildr project create <project> --target ${targetRoot}`);
|
|
301
|
+
console.log('');
|
|
302
|
+
console.log('Agent runtime:');
|
|
303
|
+
console.log(' 先用 runtime list 确认当前 Agent 是否受支持;不支持时停止当前 Buildr 操作,请联系 Buildr 作者反馈该 Agent。');
|
|
304
|
+
console.log(` 当前命令未写入 Agent runtime;受支持时,用 buildr sync <agent> --target ${targetRoot} 完成 runtime 与最终 doctor。`);
|
|
305
|
+
console.log(' 完整 Agent onboarding guidance:buildr bootstrap guide');
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
Object.assign(runtime, { bootstrapGuide, mutationTransactions, diagnoseMutations, mutationRecover, doctor, initBuildr });
|
|
309
|
+
return runtime;
|
|
310
|
+
}
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { path, SUPPORTED_AGENT_IDS } from '../shared/platform.mjs';
|
|
2
|
+
|
|
3
|
+
export function registerCommandHelp(runtime) {
|
|
4
|
+
const doctor = (...args) => runtime.doctor(...args);
|
|
5
|
+
|
|
6
|
+
function usage() {
|
|
7
|
+
const runtimeIds = SUPPORTED_AGENT_IDS.join('|');
|
|
8
|
+
console.error('Usage:');
|
|
9
|
+
console.error(` buildr init [--agent <${runtimeIds}>] [--target <dir>] [--name <name>] [--profile <personal|team|company>]`);
|
|
10
|
+
console.error(' buildr project create <project> [--target <dir>] [--repo <git-url>] [--title <text>] [--description <text>]');
|
|
11
|
+
console.error(' buildr service create <project>/<service> <repo-ref> [--target <dir>] [--type <type>] [--branch <branch>]');
|
|
12
|
+
console.error(' buildr doctor [--agent <agent>] [--target <dir>] [--scope <.|projects/project[/services/service[/path...]]>] [--json] [--include-info] [--verbose]');
|
|
13
|
+
console.error(' buildr mutation recover <transaction-id> [--target <dir>]');
|
|
14
|
+
console.error(' buildr commands add <id> --purpose <text> [--target <dir>] [--collection <path>] [--executable <name>] [--name <text>] [--description <text>] [--version-constraint <constraint>] [--version-args <args>] [--install-hint <text>] [--replace]');
|
|
15
|
+
console.error(' buildr commands remove <id> [--target <dir>] [--collection <path>]');
|
|
16
|
+
console.error(' buildr commands check [--target <dir>] [--json]');
|
|
17
|
+
console.error(' buildr openspec baseline create <change> --project <project> [--target <dir>] [--adopt-current] [--update] [--json]');
|
|
18
|
+
console.error(' buildr openspec check <change> --stage <proposal|pre-sync|post-sync> --project <project> [--target <dir>] [--json]');
|
|
19
|
+
console.error(' buildr component list [--target <dir>] [--json]');
|
|
20
|
+
console.error(' buildr component check [<id>] [--target <dir>] [--json]');
|
|
21
|
+
console.error(' buildr component install <id> --agent <agent> [--target <dir>]');
|
|
22
|
+
console.error(' buildr component uninstall <id> --agent <agent> [--target <dir>] [--reason <text>]');
|
|
23
|
+
console.error(' buildr builtin list [--target <dir>] [--json]');
|
|
24
|
+
console.error(' buildr builtin uninstall <id> --target <dir> [--reason <text>]');
|
|
25
|
+
console.error(' buildr builtin restore <id> --target <dir>');
|
|
26
|
+
console.error(' buildr update [--json]');
|
|
27
|
+
console.error(' buildr update check [--json]');
|
|
28
|
+
console.error(' buildr runtime list [--json]');
|
|
29
|
+
console.error(` buildr render <${runtimeIds}> --target <dir> [--scope <scope>]`);
|
|
30
|
+
console.error(` buildr sync <${runtimeIds}> --target <dir> [--scope <scope>]`);
|
|
31
|
+
console.error(' buildr bootstrap guide');
|
|
32
|
+
console.error(' buildr package check');
|
|
33
|
+
console.error(' buildr package build [--out <dir>]');
|
|
34
|
+
console.error(` buildr skill install <${runtimeIds}> --target <dir>`);
|
|
35
|
+
console.error(' buildr skills add [<id>] --source <skill-dir> --scope <.|projects/project> [--target <dir>] [--replace] [--ignore-unsupported]');
|
|
36
|
+
console.error(' buildr skills add <id> --remote-source <url> --scope <.|projects/project> [--target <dir>] [--source-kind <kind>] [--description <text>] [--replace]');
|
|
37
|
+
console.error(' buildr skills add <id> --resolved-source <url> --scope <.|projects/project> [--target <dir>] [--resolved-kind <kind>] [--remote-source <url>] [--source-kind <kind>] [--version <version>] [--integrity <hash>] [--description <text>] [--replace]');
|
|
38
|
+
console.error(' buildr skills remove <id> --scope <.|projects/project> [--target <dir>]');
|
|
39
|
+
console.error(` buildr skills render <${runtimeIds}> --scope <.|projects/project> --target <dir>`);
|
|
40
|
+
console.error(' buildr rules add <id> [--path <rules/file.md>] --description <text> [--target <dir>] [--replace]');
|
|
41
|
+
console.error(' buildr rules remove <id> [--target <dir>] [--keep-file]');
|
|
42
|
+
console.error(' buildr rules render claude-code --scope <.|projects/project[/services/service[/path...]]> --target <dir>');
|
|
43
|
+
console.error(` buildr runtime check <${runtimeIds}> --scope <.|projects/project[/services/service[/path...]]> --target <dir>`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const HELP_TOPICS = {
|
|
47
|
+
root: [
|
|
48
|
+
'Usage: buildr <command> [options]',
|
|
49
|
+
'',
|
|
50
|
+
'Public workspace commands:',
|
|
51
|
+
' init 初始化 Buildr workspace;传入 --agent 时一次完成 runtime 与最终 doctor。',
|
|
52
|
+
' project create 创建或登记 Project。',
|
|
53
|
+
' service create 创建或登记 Service。',
|
|
54
|
+
' doctor 诊断 workspace、源资产和 Agent runtime render 状态。',
|
|
55
|
+
' mutation recover 从保留 backup 恢复不完整 source mutation。',
|
|
56
|
+
' runtime list 列出 Buildr 支持的 Agent runtime adapter。',
|
|
57
|
+
' runtime check 专项检查某个 Agent runtime render 状态。',
|
|
58
|
+
' render 渲染指定 Agent 的 rules entry 和 workspace/project Skills。',
|
|
59
|
+
' sync 同步 Buildr 产品能力并准备当前 Agent 的 workspace 入口 runtime。',
|
|
60
|
+
' skill install 安装产品入口 Buildr Skill。',
|
|
61
|
+
' skills add/remove/render',
|
|
62
|
+
' commands add/remove/check',
|
|
63
|
+
' component list/check/install/uninstall',
|
|
64
|
+
' rules add/remove/render',
|
|
65
|
+
' builtin list/uninstall/restore',
|
|
66
|
+
' update/check',
|
|
67
|
+
' bootstrap guide',
|
|
68
|
+
'',
|
|
69
|
+
'Product maintenance / workflow internals:',
|
|
70
|
+
' package check/build 校验或构建 Buildr 产品包。',
|
|
71
|
+
' openspec baseline/check 供 Buildr OpenSpec workflow 管理契约基线与同步门禁。',
|
|
72
|
+
'',
|
|
73
|
+
'表面分类说明用途与支持边界,不是权限或安全限制;以上命令仍可执行并可查看主题帮助。',
|
|
74
|
+
],
|
|
75
|
+
init: [
|
|
76
|
+
`Usage: buildr init [--agent <${SUPPORTED_AGENT_IDS.join('|')}>] [--target <dir>] [--name <name>] [--profile <personal|team|company>]`,
|
|
77
|
+
'',
|
|
78
|
+
'首次 onboarding 推荐传入 --agent:初始化源资产后复用完整 sync,并以最终 doctor 通过作为完成条件。',
|
|
79
|
+
'不传 --agent 时只初始化源资产;已有 workspace 的日常更新继续使用 buildr sync <agent>。',
|
|
80
|
+
'--help 只输出帮助,不会写入文件。',
|
|
81
|
+
],
|
|
82
|
+
'project create': [
|
|
83
|
+
'Usage: buildr project create <project> [--target <dir>] [--repo <git-url>] [--title <text>] [--description <text>]',
|
|
84
|
+
'',
|
|
85
|
+
'创建或登记 Project,并写入 Project registry: projects/manifest.yml。',
|
|
86
|
+
],
|
|
87
|
+
'service create': [
|
|
88
|
+
'Usage: buildr service create <project>/<service> <repo-ref> [--target <dir>] [--type <type>] [--branch <branch>]',
|
|
89
|
+
'',
|
|
90
|
+
'创建或登记 Service,并写入所属 Project 的 Service registry: services/manifest.yml。',
|
|
91
|
+
'Service 规则入口是 Service 目录中的 AGENTS.md,不在 Service registry 中记录规则路径。',
|
|
92
|
+
],
|
|
93
|
+
doctor: [
|
|
94
|
+
'Usage: buildr doctor [--agent <agent>] [--target <dir>] [--scope <.|projects/project[/services/service[/path...]]>] [--json] [--include-info] [--verbose]',
|
|
95
|
+
'',
|
|
96
|
+
'诊断 workspace 源资产和 Agent runtime render 状态。传入 --agent 时只检查该 Agent adapter。',
|
|
97
|
+
],
|
|
98
|
+
'mutation recover': [
|
|
99
|
+
'Usage: buildr mutation recover <transaction-id> [--target <dir>]',
|
|
100
|
+
'',
|
|
101
|
+
'从完整 transaction journal 和 backup 恢复操作前源资产;不会猜测或接受半完成新状态。',
|
|
102
|
+
],
|
|
103
|
+
'runtime list': [
|
|
104
|
+
'Usage: buildr runtime list [--json]',
|
|
105
|
+
'',
|
|
106
|
+
'列出 Buildr 支持的 Agent runtime adapter;不要求当前目录是 Buildr workspace。',
|
|
107
|
+
],
|
|
108
|
+
'runtime check': [
|
|
109
|
+
`Usage: buildr runtime check <${SUPPORTED_AGENT_IDS.join('|')}> --scope <.|projects/project[/services/service[/path...]]> --target <dir>`,
|
|
110
|
+
'',
|
|
111
|
+
'专项检查某个 Agent runtime render 状态。',
|
|
112
|
+
],
|
|
113
|
+
sync: [
|
|
114
|
+
`Usage: buildr sync <${SUPPORTED_AGENT_IDS.join('|')}> --target <dir> [--scope <scope>]`,
|
|
115
|
+
'',
|
|
116
|
+
'同步 Buildr 产品能力,安装产品入口 Buildr Skill,并准备当前 Agent 的 workspace 入口 runtime。不是 Project scope 同步工具。',
|
|
117
|
+
],
|
|
118
|
+
render: [
|
|
119
|
+
`Usage: buildr render <${SUPPORTED_AGENT_IDS.join('|')}> --target <dir> [--scope <scope>]`,
|
|
120
|
+
'',
|
|
121
|
+
'组合渲染 rules entry 和 workspace/project Skills;不安装产品入口 Buildr Skill。',
|
|
122
|
+
],
|
|
123
|
+
'skill install': [
|
|
124
|
+
`Usage: buildr skill install <${SUPPORTED_AGENT_IDS.join('|')}> --target <dir>`,
|
|
125
|
+
'',
|
|
126
|
+
'只安装或修复产品入口 Buildr Skill。',
|
|
127
|
+
],
|
|
128
|
+
'skills add': [
|
|
129
|
+
'Usage: buildr skills add [<id>] --source <skill-dir> --scope <.|projects/project> [--target <dir>] [--replace] [--ignore-unsupported]',
|
|
130
|
+
'Usage: buildr skills add <id> --remote-source <url> --scope <.|projects/project> [--target <dir>] [--source-kind <kind>] [--description <text>] [--replace]',
|
|
131
|
+
'Usage: buildr skills add <id> --resolved-source <url> --scope <.|projects/project> [--target <dir>] [--resolved-kind <kind>] [--remote-source <url>] [--source-kind <kind>] [--version <version>] [--integrity <hash>] [--description <text>] [--replace]',
|
|
132
|
+
'',
|
|
133
|
+
'维护 workspace/project Skills 源资产。',
|
|
134
|
+
],
|
|
135
|
+
'skills remove': [
|
|
136
|
+
'Usage: buildr skills remove <id> --scope <.|projects/project> [--target <dir>]',
|
|
137
|
+
'',
|
|
138
|
+
'删除 workspace/project Skills 源资产登记。',
|
|
139
|
+
],
|
|
140
|
+
'skills render': [
|
|
141
|
+
`Usage: buildr skills render <${SUPPORTED_AGENT_IDS.join('|')}> --scope <.|projects/project> --target <dir>`,
|
|
142
|
+
'',
|
|
143
|
+
'只渲染 workspace/project Skills 和 Skill install plans。',
|
|
144
|
+
],
|
|
145
|
+
'commands add': [
|
|
146
|
+
'Usage: buildr commands add <id> --purpose <text> [--target <dir>] [--collection <path>] [--executable <name>] [--name <text>] [--description <text>] [--version-constraint <constraint>] [--version-args <args>] [--install-hint <text>] [--replace]',
|
|
147
|
+
'',
|
|
148
|
+
'新增或替换命令行工具清单条目。',
|
|
149
|
+
],
|
|
150
|
+
'commands remove': [
|
|
151
|
+
'Usage: buildr commands remove <id> [--target <dir>] [--collection <path>]',
|
|
152
|
+
'',
|
|
153
|
+
'删除命令行工具清单条目。',
|
|
154
|
+
],
|
|
155
|
+
'commands check': [
|
|
156
|
+
'Usage: buildr commands check [--target <dir>] [--json]',
|
|
157
|
+
'',
|
|
158
|
+
'检查命令行工具清单和本机可用状态。',
|
|
159
|
+
],
|
|
160
|
+
'openspec baseline create': [
|
|
161
|
+
'Usage: buildr openspec baseline create <change> --project <project> [--target <dir>] [--adopt-current] [--update] [--json]',
|
|
162
|
+
'',
|
|
163
|
+
'供 Buildr OpenSpec workflow 为 active change 显式创建或更新 Requirement 契约基线。不会安装或升级外部 OpenSpec CLI。',
|
|
164
|
+
],
|
|
165
|
+
'openspec check': [
|
|
166
|
+
'Usage: buildr openspec check <change> --stage <proposal|pre-sync|post-sync> --project <project> [--target <dir>] [--json]',
|
|
167
|
+
'',
|
|
168
|
+
'供 Buildr OpenSpec workflow 检查 proposal、基线、活动 change 冲突和同步结果。',
|
|
169
|
+
],
|
|
170
|
+
'component list': [
|
|
171
|
+
'Usage: buildr component list [--target <dir>] [--json]',
|
|
172
|
+
'',
|
|
173
|
+
'列出 workspace Components。当前不支持 Project 或 Service scope。',
|
|
174
|
+
],
|
|
175
|
+
'component check': [
|
|
176
|
+
'Usage: buildr component check [<id>] [--target <dir>] [--json]',
|
|
177
|
+
'',
|
|
178
|
+
'检查 Component definition、成员 integrity 和唯一所有权。',
|
|
179
|
+
],
|
|
180
|
+
'component install': [
|
|
181
|
+
`Usage: buildr component install <id> --agent <${SUPPORTED_AGENT_IDS.join('|')}> [--target <dir>]`,
|
|
182
|
+
'',
|
|
183
|
+
'安装 workspace Component,reconcile 指定 Agent runtime,并运行 doctor。',
|
|
184
|
+
],
|
|
185
|
+
'component uninstall': [
|
|
186
|
+
`Usage: buildr component uninstall <id> --agent <${SUPPORTED_AGENT_IDS.join('|')}> [--target <dir>] [--reason <text>]`,
|
|
187
|
+
'',
|
|
188
|
+
'卸载 workspace Component 及其受管源资产;不会卸载外部 CLI,也不会删除 Project 内容。',
|
|
189
|
+
],
|
|
190
|
+
'rules add': [
|
|
191
|
+
'Usage: buildr rules add <id> [--path <rules/file.md>] --description <text> [--target <dir>] [--replace]',
|
|
192
|
+
'',
|
|
193
|
+
'注册已存在的 root Rule 文件到 rules/manifest.yml。未传 --path 时默认使用 rules/<id>.md。',
|
|
194
|
+
],
|
|
195
|
+
'rules remove': [
|
|
196
|
+
'Usage: buildr rules remove <id> [--target <dir>] [--keep-file]',
|
|
197
|
+
'',
|
|
198
|
+
'删除 root Rule 登记和规则文件。传入 --keep-file 时只取消注册并保留文件。',
|
|
199
|
+
],
|
|
200
|
+
'builtin list': [
|
|
201
|
+
'Usage: buildr builtin list [--target <dir>] [--json]',
|
|
202
|
+
'',
|
|
203
|
+
'列出 Buildr 内置能力状态。',
|
|
204
|
+
],
|
|
205
|
+
'builtin uninstall': [
|
|
206
|
+
'Usage: buildr builtin uninstall <id> --target <dir> [--reason <text>]',
|
|
207
|
+
'',
|
|
208
|
+
'卸载 optional Buildr 内置能力。required 内置能力不能卸载。',
|
|
209
|
+
],
|
|
210
|
+
'builtin restore': [
|
|
211
|
+
'Usage: buildr builtin restore <id> --target <dir>',
|
|
212
|
+
'',
|
|
213
|
+
'恢复 optional Buildr 内置能力。',
|
|
214
|
+
],
|
|
215
|
+
update: [
|
|
216
|
+
'Usage: buildr update [--json]',
|
|
217
|
+
'',
|
|
218
|
+
'根据当前命令来源更新 Buildr CLI 自身;不读取或同步 workspace。',
|
|
219
|
+
'同步 workspace 请使用 buildr sync <agent> --target <dir>。',
|
|
220
|
+
],
|
|
221
|
+
'update check': [
|
|
222
|
+
'Usage: buildr update check [--json]',
|
|
223
|
+
'',
|
|
224
|
+
'检查 Buildr CLI 来源、远端版本和安全更新状态;不读取 workspace。',
|
|
225
|
+
],
|
|
226
|
+
'package check': [
|
|
227
|
+
'Usage: buildr package check',
|
|
228
|
+
'',
|
|
229
|
+
'供 Buildr 产品维护者检查产品包发布边界和基础行为;不是 workspace onboarding 必需步骤。',
|
|
230
|
+
],
|
|
231
|
+
'package build': [
|
|
232
|
+
'Usage: buildr package build [--out <dir>]',
|
|
233
|
+
'',
|
|
234
|
+
'供 Buildr 产品维护者构建产品包文件;不是 workspace onboarding 必需步骤。',
|
|
235
|
+
],
|
|
236
|
+
'bootstrap guide': [
|
|
237
|
+
'Usage: buildr bootstrap guide',
|
|
238
|
+
'',
|
|
239
|
+
'输出最小 bootstrap 指南。',
|
|
240
|
+
],
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
function commandTopic(rawArgs) {
|
|
244
|
+
const [domain, action, runtime] = rawArgs.filter((arg) => !['--help', '-h'].includes(arg));
|
|
245
|
+
if (!domain || domain === 'help') return 'root';
|
|
246
|
+
if (domain === 'project' && action === 'create') return 'project create';
|
|
247
|
+
if (domain === 'service' && action === 'create') return 'service create';
|
|
248
|
+
if (domain === 'runtime' && action === 'list') return 'runtime list';
|
|
249
|
+
if (domain === 'mutation' && action === 'recover') return 'mutation recover';
|
|
250
|
+
if (domain === 'runtime' && action === 'check') return 'runtime check';
|
|
251
|
+
if (domain === 'skill' && action === 'install') return 'skill install';
|
|
252
|
+
if (domain === 'skills' && ['add', 'remove'].includes(action)) return `skills ${action}`;
|
|
253
|
+
if (domain === 'skills' && action === 'render') return 'skills render';
|
|
254
|
+
if (domain === 'commands' && ['add', 'remove', 'check'].includes(action)) return `commands ${action}`;
|
|
255
|
+
if (domain === 'openspec' && action === 'baseline' && runtime === 'create') return 'openspec baseline create';
|
|
256
|
+
if (domain === 'openspec' && action === 'check') return 'openspec check';
|
|
257
|
+
if (domain === 'component' && ['list', 'check', 'install', 'uninstall'].includes(action)) return `component ${action}`;
|
|
258
|
+
if (domain === 'rules' && ['add', 'remove'].includes(action)) return `rules ${action}`;
|
|
259
|
+
if (domain === 'builtin' && ['list', 'uninstall', 'restore'].includes(action)) return `builtin ${action}`;
|
|
260
|
+
if (domain === 'update' && action === 'check') return 'update check';
|
|
261
|
+
if (domain === 'update') return 'update';
|
|
262
|
+
if (domain === 'package' && ['check', 'build'].includes(action)) return `package ${action}`;
|
|
263
|
+
if (domain === 'bootstrap' && action === 'guide') return 'bootstrap guide';
|
|
264
|
+
if (domain === 'render') return 'render';
|
|
265
|
+
if (domain === 'sync') return 'sync';
|
|
266
|
+
if (domain === 'doctor') return 'doctor';
|
|
267
|
+
if (domain === 'init') return 'init';
|
|
268
|
+
if (domain === 'rules' && action === 'render') {
|
|
269
|
+
return 'rules render';
|
|
270
|
+
}
|
|
271
|
+
return 'root';
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
HELP_TOPICS['rules render'] = [
|
|
275
|
+
'Usage: buildr rules render claude-code --scope <.|projects/project[/services/service[/path...]]> --target <dir>',
|
|
276
|
+
'',
|
|
277
|
+
'递归发现 canonical workspace scope 的祖先链和子树,为 Claude Code reconcile 同目录 rules entry bridge。Codex 原生读取 AGENTS.md,不执行 rules render。',
|
|
278
|
+
];
|
|
279
|
+
|
|
280
|
+
function printHelp(rawArgs) {
|
|
281
|
+
const topic = commandTopic(rawArgs);
|
|
282
|
+
const lines = HELP_TOPICS[topic] ?? HELP_TOPICS.root;
|
|
283
|
+
console.log(lines.join('\n'));
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function isHelpRequest(rawArgs) {
|
|
287
|
+
return rawArgs.length === 0 || rawArgs.some((arg) => arg === '--help' || arg === '-h') || (rawArgs.length === 1 && rawArgs[0] === 'help');
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
Object.assign(runtime, { usage, commandTopic, printHelp, isHelpRequest });
|
|
291
|
+
return runtime;
|
|
292
|
+
}
|