@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,538 @@
|
|
|
1
|
+
import {
|
|
2
|
+
fs,
|
|
3
|
+
crypto,
|
|
4
|
+
os,
|
|
5
|
+
path,
|
|
6
|
+
process,
|
|
7
|
+
execFileSync,
|
|
8
|
+
spawnSync,
|
|
9
|
+
checkClaudeCodeRuntime,
|
|
10
|
+
buildRuleDiscoveryPlan,
|
|
11
|
+
hasManagedRulesMarker,
|
|
12
|
+
renderClaudeCodeRules,
|
|
13
|
+
resolveRuleScope,
|
|
14
|
+
checkCodexRuntime,
|
|
15
|
+
PACKAGE_WORKSPACE_TARGET,
|
|
16
|
+
PACKAGE_RUNTIME_TARGET,
|
|
17
|
+
LEGACY_PACKAGE_PATHS,
|
|
18
|
+
BUILDR_REQUIRED_BLOCK_START,
|
|
19
|
+
} from '../shared/platform.mjs';
|
|
20
|
+
import { PUBLIC_JSON_SCHEMAS, withJsonSchema } from '../shared/json-contracts.mjs';
|
|
21
|
+
import { createPackageOutput } from './package-maintenance/output.mjs';
|
|
22
|
+
import { createPackageSmokeChecks } from './package-maintenance/smoke-checks.mjs';
|
|
23
|
+
import { createPackageStaticValidator } from './package-maintenance/static-validation.mjs';
|
|
24
|
+
import { createBuiltinReceipts } from './package-maintenance/builtin-receipts.mjs';
|
|
25
|
+
|
|
26
|
+
export function registerApplicationPackageMaintenance(runtime) {
|
|
27
|
+
const parseCommandsManifestYaml = (...args) => runtime.parseCommandsManifestYaml(...args);
|
|
28
|
+
const isPlainObject = (...args) => runtime.isPlainObject(...args);
|
|
29
|
+
const validateCommandsManifest = (...args) => runtime.validateCommandsManifest(...args);
|
|
30
|
+
const readCommandsManifestForWrite = (...args) => runtime.readCommandsManifestForWrite(...args);
|
|
31
|
+
const writeCommandsManifest = (...args) => runtime.writeCommandsManifest(...args);
|
|
32
|
+
const assertNoUnknownOptions = (...args) => runtime.assertNoUnknownOptions(...args);
|
|
33
|
+
const positionalArgs = (...args) => runtime.positionalArgs(...args);
|
|
34
|
+
const commandsCheck = (...args) => runtime.commandsCheck(...args);
|
|
35
|
+
const componentMemberPaths = (...args) => runtime.componentMemberPaths(...args);
|
|
36
|
+
const packageComponentDefinition = (...args) => runtime.packageComponentDefinition(...args);
|
|
37
|
+
const packageComponentSourcePath = (...args) => runtime.packageComponentSourcePath(...args);
|
|
38
|
+
const validatePackageComponentMembers = (...args) => runtime.validatePackageComponentMembers(...args);
|
|
39
|
+
const packageComponentsStatus = (...args) => runtime.packageComponentsStatus(...args);
|
|
40
|
+
const readPackageManifest = (...args) => runtime.readPackageManifest(...args);
|
|
41
|
+
const parseManifestFileEntry = (...args) => runtime.parseManifestFileEntry(...args);
|
|
42
|
+
const collectFiles = (...args) => runtime.collectFiles(...args);
|
|
43
|
+
const validateBootstrapContract = (...args) => runtime.validateBootstrapContract(...args);
|
|
44
|
+
const builtinRuleEntry = (...args) => runtime.builtinRuleEntry(...args);
|
|
45
|
+
const builtinSkillEntry = (...args) => runtime.builtinSkillEntry(...args);
|
|
46
|
+
const builtinCommandEntry = (...args) => runtime.builtinCommandEntry(...args);
|
|
47
|
+
const sourcePathFromBuiltin = (...args) => runtime.sourcePathFromBuiltin(...args);
|
|
48
|
+
const targetPathFromBuiltin = (...args) => runtime.targetPathFromBuiltin(...args);
|
|
49
|
+
const convergeRegistryManifests = (...args) => runtime.convergeRegistryManifests(...args);
|
|
50
|
+
const parseRulesManifestYaml = (...args) => runtime.parseRulesManifestYaml(...args);
|
|
51
|
+
const readRulesManifestForWrite = (...args) => runtime.readRulesManifestForWrite(...args);
|
|
52
|
+
const writeRulesManifest = (...args) => runtime.writeRulesManifest(...args);
|
|
53
|
+
const readSkillManifest = (...args) => runtime.readSkillManifest(...args);
|
|
54
|
+
const validateSkillManifestEntries = (...args) => runtime.validateSkillManifestEntries(...args);
|
|
55
|
+
const isManifestSourceLabel = (...args) => runtime.isManifestSourceLabel(...args);
|
|
56
|
+
const normalizeRelativePathForBuildr = (...args) => runtime.normalizeRelativePathForBuildr(...args);
|
|
57
|
+
const parseSkillSourceRef = (...args) => runtime.parseSkillSourceRef(...args);
|
|
58
|
+
const readSkillsManifestForWrite = (...args) => runtime.readSkillsManifestForWrite(...args);
|
|
59
|
+
const writeSkillsManifest = (...args) => runtime.writeSkillsManifest(...args);
|
|
60
|
+
const parseSkillFrontmatter = (...args) => runtime.parseSkillFrontmatter(...args);
|
|
61
|
+
const parseProjectsYaml = (...args) => runtime.parseProjectsYaml(...args);
|
|
62
|
+
const validateProjectsRegistry = (...args) => runtime.validateProjectsRegistry(...args);
|
|
63
|
+
const writeServicesManifest = (...args) => runtime.writeServicesManifest(...args);
|
|
64
|
+
const optionValue = (...args) => runtime.optionValue(...args);
|
|
65
|
+
const ensureDirectory = (...args) => runtime.ensureDirectory(...args);
|
|
66
|
+
const atomicWriteJson = (...args) => runtime.atomicWriteJson(...args);
|
|
67
|
+
const assertSafeAssetTarget = (...args) => runtime.assertSafeAssetTarget(...args);
|
|
68
|
+
const withWorkspaceMutation = (...args) => runtime.withWorkspaceMutation(...args);
|
|
69
|
+
const productRoot = (...args) => runtime.productRoot(...args);
|
|
70
|
+
const packageRoot = (...args) => runtime.packageRoot(...args);
|
|
71
|
+
const packageWorkspaceTargetRoot = (...args) => runtime.packageWorkspaceTargetRoot(...args);
|
|
72
|
+
const developmentWorkspaceRoot = (...args) => runtime.developmentWorkspaceRoot(...args);
|
|
73
|
+
const appendGitignoreEntries = (...args) => runtime.appendGitignoreEntries(...args);
|
|
74
|
+
const hasFlag = (...args) => runtime.hasFlag(...args);
|
|
75
|
+
const toPosixRelative = (...args) => runtime.toPosixRelative(...args);
|
|
76
|
+
const existsDirectory = (...args) => runtime.existsDirectory(...args);
|
|
77
|
+
const existsFile = (...args) => runtime.existsFile(...args);
|
|
78
|
+
const ensureRootRequiredBlock = (...args) => runtime.ensureRootRequiredBlock(...args);
|
|
79
|
+
const copyFileIfChanged = (...args) => runtime.copyFileIfChanged(...args);
|
|
80
|
+
const copyDirectoryIfChanged = (...args) => runtime.copyDirectoryIfChanged(...args);
|
|
81
|
+
const assertInitializedBuildrWorkspace = (...args) => runtime.assertInitializedBuildrWorkspace(...args);
|
|
82
|
+
|
|
83
|
+
const {
|
|
84
|
+
key: builtinReceiptKey,
|
|
85
|
+
snapshot: builtinSnapshot,
|
|
86
|
+
read: readBuiltinReceipts,
|
|
87
|
+
write: writeBuiltinReceipts,
|
|
88
|
+
fromSnapshot: receiptFromSnapshot,
|
|
89
|
+
resolveState: resolveBuiltinState,
|
|
90
|
+
} = createBuiltinReceipts({ atomicWriteJson, collectFiles, crypto, ensureDirectory, existsDirectory, existsFile, fs, isPlainObject, path, toPosixRelative });
|
|
91
|
+
|
|
92
|
+
function syncPackageBuiltins(targetRoot, options = {}) {
|
|
93
|
+
const manifest = readPackageManifest();
|
|
94
|
+
const changed = [];
|
|
95
|
+
const findings = [];
|
|
96
|
+
const restoreId = options.restoreId || null;
|
|
97
|
+
const checkOnly = options.checkOnly === true;
|
|
98
|
+
const componentStatusById = new Map(packageComponentsStatus(targetRoot, manifest).components.map((item) => [item.id, item.status]));
|
|
99
|
+
const receipts = readBuiltinReceipts(targetRoot);
|
|
100
|
+
const receiptByKey = new Map(receipts.builtins.map((item) => [builtinReceiptKey(item.type, item.id), item]));
|
|
101
|
+
let receiptsChanged = false;
|
|
102
|
+
|
|
103
|
+
const updateReceipt = (type, builtin, snapshot) => {
|
|
104
|
+
const key = builtinReceiptKey(type, builtin.id);
|
|
105
|
+
const next = receiptFromSnapshot(type, builtin, snapshot);
|
|
106
|
+
const existing = receiptByKey.get(key);
|
|
107
|
+
if (JSON.stringify(existing) === JSON.stringify(next)) return;
|
|
108
|
+
if (existing) receipts.builtins[receipts.builtins.indexOf(existing)] = next;
|
|
109
|
+
else receipts.builtins.push(next);
|
|
110
|
+
receiptByKey.set(key, next);
|
|
111
|
+
receiptsChanged = true;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const removeReceipt = (type, builtin) => {
|
|
115
|
+
const key = builtinReceiptKey(type, builtin.id);
|
|
116
|
+
const existing = receiptByKey.get(key);
|
|
117
|
+
if (!existing) return;
|
|
118
|
+
receipts.builtins.splice(receipts.builtins.indexOf(existing), 1);
|
|
119
|
+
receiptByKey.delete(key);
|
|
120
|
+
receiptsChanged = true;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
if (!checkOnly) {
|
|
124
|
+
ensureRootRequiredBlock(targetRoot, changed);
|
|
125
|
+
changed.push(...convergeRegistryManifests(targetRoot));
|
|
126
|
+
if (appendGitignoreEntries(path.join(targetRoot, '.gitignore'), [
|
|
127
|
+
'# Agent runtime directories generated by Buildr',
|
|
128
|
+
'CLAUDE.md',
|
|
129
|
+
'.claude/',
|
|
130
|
+
'.agents/',
|
|
131
|
+
'.trae/',
|
|
132
|
+
'.cursor/',
|
|
133
|
+
'.qoder/',
|
|
134
|
+
'# Buildr transaction state',
|
|
135
|
+
'/.buildr/mutations/',
|
|
136
|
+
'# Task worktrees',
|
|
137
|
+
'/.worktrees/',
|
|
138
|
+
])) {
|
|
139
|
+
changed.push('.gitignore');
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const rulesManifest = readRulesManifestForWrite(targetRoot);
|
|
144
|
+
const rulesById = new Map(rulesManifest.rules.map((rule, index) => [rule.id, { rule, index }]));
|
|
145
|
+
for (const builtin of manifest.builtins.rules) {
|
|
146
|
+
if (builtin.component) {
|
|
147
|
+
findings.push({ type: 'rule', id: builtin.id, required: builtin.required === true, status: componentStatusById.get(builtin.component) || 'missing', path: builtin.target, component: builtin.component, lifecycle: `buildr component check ${builtin.component} --target ${targetRoot} --json` });
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
const sourceFile = sourcePathFromBuiltin(builtin);
|
|
151
|
+
const targetFile = targetPathFromBuiltin(targetRoot, builtin);
|
|
152
|
+
const existing = rulesById.get(builtin.id)?.rule || null;
|
|
153
|
+
const isRestore = restoreId === builtin.id;
|
|
154
|
+
const isNew = !existing;
|
|
155
|
+
const isUninstalled = existing?.state === 'uninstalled' || existing?.enabled === false;
|
|
156
|
+
const desired = builtinRuleEntry(builtin);
|
|
157
|
+
const newSnapshot = builtinSnapshot(sourceFile, 'rule');
|
|
158
|
+
const liveSnapshot = builtinSnapshot(targetFile, 'rule');
|
|
159
|
+
const state = resolveBuiltinState({ type: 'rule', builtin, liveSnapshot, newSnapshot, oldReceipt: receiptByKey.get(builtinReceiptKey('rule', builtin.id)), isRestore, required: builtin.required === true });
|
|
160
|
+
const status = isUninstalled && !isRestore ? 'uninstalled' : state.status;
|
|
161
|
+
findings.push({ type: 'rule', id: builtin.id, required: builtin.required === true, status, path: builtin.target });
|
|
162
|
+
|
|
163
|
+
if (checkOnly) continue;
|
|
164
|
+
if (isUninstalled && !isRestore && !builtin.required) {
|
|
165
|
+
removeReceipt('rule', builtin);
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
if (!builtin.required && !isNew && !isRestore && status === 'modified') {
|
|
169
|
+
const updated = { ...existing, state: 'modified' };
|
|
170
|
+
rulesManifest.rules[rulesById.get(builtin.id).index] = updated;
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
if (!builtin.required && !isNew && !isRestore && status === 'missing') {
|
|
174
|
+
const updated = { ...existing, state: 'missing' };
|
|
175
|
+
rulesManifest.rules[rulesById.get(builtin.id).index] = updated;
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
if (builtin.required || isNew || isRestore || state.converge || state.adopt) {
|
|
179
|
+
if (copyFileIfChanged(sourceFile, targetFile)) changed.push(builtin.target);
|
|
180
|
+
if (rulesById.has(builtin.id)) {
|
|
181
|
+
rulesManifest.rules[rulesById.get(builtin.id).index] = desired;
|
|
182
|
+
} else {
|
|
183
|
+
rulesManifest.rules.push(desired);
|
|
184
|
+
}
|
|
185
|
+
updateReceipt('rule', builtin, newSnapshot);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
if (!checkOnly) {
|
|
189
|
+
const rulesPath = writeRulesManifest(targetRoot, rulesManifest);
|
|
190
|
+
changed.push(toPosixRelative(targetRoot, rulesPath));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const skillsManifest = readSkillsManifestForWrite(targetRoot);
|
|
194
|
+
const skillsById = new Map(skillsManifest.map((skill, index) => [skill.id, { skill, index }]));
|
|
195
|
+
for (const builtin of manifest.builtins.skills) {
|
|
196
|
+
if (builtin.component) {
|
|
197
|
+
findings.push({ type: 'skill', id: builtin.id, required: builtin.required === true, status: componentStatusById.get(builtin.component) || 'missing', path: builtin.target, component: builtin.component, lifecycle: `buildr component check ${builtin.component} --target ${targetRoot} --json` });
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
const sourceDir = sourcePathFromBuiltin(builtin);
|
|
201
|
+
const targetDir = targetPathFromBuiltin(targetRoot, builtin);
|
|
202
|
+
const existing = skillsById.get(builtin.id)?.skill || null;
|
|
203
|
+
const isRestore = restoreId === builtin.id;
|
|
204
|
+
const isNew = !existing;
|
|
205
|
+
const isUninstalled = existing?.state === 'uninstalled' || existing?.enabled === false;
|
|
206
|
+
const desired = builtinSkillEntry(builtin);
|
|
207
|
+
const newSnapshot = builtinSnapshot(sourceDir, 'skill');
|
|
208
|
+
const liveSnapshot = builtinSnapshot(targetDir, 'skill');
|
|
209
|
+
const state = resolveBuiltinState({ type: 'skill', builtin, liveSnapshot, newSnapshot, oldReceipt: receiptByKey.get(builtinReceiptKey('skill', builtin.id)), isRestore, required: builtin.required === true });
|
|
210
|
+
const status = isUninstalled && !isRestore ? 'uninstalled' : state.status;
|
|
211
|
+
findings.push({ type: 'skill', id: builtin.id, required: builtin.required === true, status, path: builtin.target });
|
|
212
|
+
|
|
213
|
+
if (checkOnly) continue;
|
|
214
|
+
if (isUninstalled && !isRestore && !builtin.required) {
|
|
215
|
+
removeReceipt('skill', builtin);
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
if (!builtin.required && !isNew && !isRestore && status === 'modified') {
|
|
219
|
+
skillsManifest[skillsById.get(builtin.id).index] = { ...existing, state: 'modified' };
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
if (!builtin.required && !isNew && !isRestore && status === 'missing') {
|
|
223
|
+
skillsManifest[skillsById.get(builtin.id).index] = { ...existing, state: 'missing' };
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
if (builtin.required || isNew || isRestore || state.converge || state.adopt) {
|
|
227
|
+
if (state.converge && existsDirectory(targetDir)) fs.rmSync(targetDir, { recursive: true, force: true });
|
|
228
|
+
if (copyDirectoryIfChanged(sourceDir, targetDir)) changed.push(builtin.target);
|
|
229
|
+
if (skillsById.has(builtin.id)) {
|
|
230
|
+
skillsManifest[skillsById.get(builtin.id).index] = desired;
|
|
231
|
+
} else {
|
|
232
|
+
skillsManifest.push(desired);
|
|
233
|
+
}
|
|
234
|
+
updateReceipt('skill', builtin, newSnapshot);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (!checkOnly) {
|
|
238
|
+
const skillsPath = writeSkillsManifest(targetRoot, skillsManifest);
|
|
239
|
+
changed.push(toPosixRelative(targetRoot, skillsPath));
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const commandsManifest = readCommandsManifestForWrite(targetRoot);
|
|
243
|
+
const commandsById = new Map(commandsManifest.commands.map((command, index) => [command.id, { command, index }]));
|
|
244
|
+
for (const builtin of manifest.builtins.commands) {
|
|
245
|
+
if (builtin.component) {
|
|
246
|
+
findings.push({ type: 'command', id: builtin.id, required: builtin.required === true, status: componentStatusById.get(builtin.component) || 'missing', path: 'commands/manifest.yml', component: builtin.component, lifecycle: `buildr component check ${builtin.component} --target ${targetRoot} --json` });
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
const existing = commandsById.get(builtin.id)?.command || null;
|
|
250
|
+
const isRestore = restoreId === builtin.id;
|
|
251
|
+
const isNew = !existing;
|
|
252
|
+
const isUninstalled = existing?.state === 'uninstalled' || existing?.enabled === false;
|
|
253
|
+
const desired = builtinCommandEntry(builtin);
|
|
254
|
+
const newSnapshot = builtinSnapshot(desired, 'command');
|
|
255
|
+
const liveSnapshot = existing ? builtinSnapshot(existing, 'command') : null;
|
|
256
|
+
const state = resolveBuiltinState({ type: 'command', builtin, liveSnapshot, newSnapshot, oldReceipt: receiptByKey.get(builtinReceiptKey('command', builtin.id)), isRestore, required: builtin.required === true });
|
|
257
|
+
const status = isUninstalled && !isRestore ? 'uninstalled' : state.status;
|
|
258
|
+
findings.push({ type: 'command', id: builtin.id, required: builtin.required === true, status, path: 'commands/manifest.yml' });
|
|
259
|
+
if (checkOnly) continue;
|
|
260
|
+
if (isUninstalled && !isRestore && !builtin.required) {
|
|
261
|
+
removeReceipt('command', builtin);
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
if (commandsById.has(builtin.id) && (builtin.required || isRestore || state.converge || state.adopt)) {
|
|
265
|
+
commandsManifest.commands[commandsById.get(builtin.id).index] = desired;
|
|
266
|
+
} else if (isNew || isRestore || builtin.required) {
|
|
267
|
+
commandsManifest.commands.push(desired);
|
|
268
|
+
}
|
|
269
|
+
if (builtin.required || isNew || isRestore || state.converge || state.adopt) updateReceipt('command', builtin, newSnapshot);
|
|
270
|
+
}
|
|
271
|
+
if (!checkOnly) {
|
|
272
|
+
const commandsPath = writeCommandsManifest(targetRoot, commandsManifest);
|
|
273
|
+
changed.push(toPosixRelative(targetRoot, commandsPath));
|
|
274
|
+
if (receiptsChanged) changed.push(writeBuiltinReceipts(targetRoot, receipts));
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
return { targetRoot, changed: [...new Set(changed)], findings };
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function builtinList(args) {
|
|
281
|
+
const targetRoot = path.resolve(optionValue(args, '--target', process.cwd()));
|
|
282
|
+
const json = hasFlag(args, '--json');
|
|
283
|
+
const result = syncPackageBuiltins(targetRoot, { checkOnly: true });
|
|
284
|
+
if (json) {
|
|
285
|
+
console.log(JSON.stringify(withJsonSchema(PUBLIC_JSON_SCHEMAS.builtinList, result), null, 2));
|
|
286
|
+
} else {
|
|
287
|
+
console.log(`Buildr builtins for ${targetRoot}`);
|
|
288
|
+
for (const finding of result.findings) {
|
|
289
|
+
console.log(`[${finding.status}] ${finding.type}:${finding.id} ${finding.path}${finding.component ? ` component=${finding.component}` : ''}`);
|
|
290
|
+
if (finding.lifecycle) console.log(` lifecycle: ${finding.lifecycle}`);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function packageBuiltinComponent(id) {
|
|
296
|
+
const manifest = readPackageManifest();
|
|
297
|
+
for (const kind of ['rules', 'skills', 'commands']) {
|
|
298
|
+
const builtin = manifest.builtins[kind].find((item) => item.id === id);
|
|
299
|
+
if (builtin?.component) return builtin.component;
|
|
300
|
+
}
|
|
301
|
+
return null;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function findBuiltinManifestEntry(targetRoot, id) {
|
|
305
|
+
const rulesManifest = readRulesManifestForWrite(targetRoot);
|
|
306
|
+
const ruleIndex = rulesManifest.rules.findIndex((rule) => rule.id === id && rule.source === 'buildr');
|
|
307
|
+
if (ruleIndex !== -1) return { type: 'rule', manifest: rulesManifest, index: ruleIndex, entry: rulesManifest.rules[ruleIndex] };
|
|
308
|
+
|
|
309
|
+
const skillsManifest = readSkillsManifestForWrite(targetRoot);
|
|
310
|
+
const skillIndex = skillsManifest.findIndex((skill) => skill.id === id && skill.source === 'buildr');
|
|
311
|
+
if (skillIndex !== -1) return { type: 'skill', manifest: skillsManifest, index: skillIndex, entry: skillsManifest[skillIndex] };
|
|
312
|
+
|
|
313
|
+
const commandsManifest = readCommandsManifestForWrite(targetRoot);
|
|
314
|
+
const commandIndex = commandsManifest.commands.findIndex((command) => command.id === id && command.source === 'buildr');
|
|
315
|
+
if (commandIndex !== -1) return { type: 'command', manifest: commandsManifest, index: commandIndex, entry: commandsManifest.commands[commandIndex] };
|
|
316
|
+
|
|
317
|
+
throw new Error(`Buildr builtin not found: ${id}`);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function builtinUninstallUnsafe(args) {
|
|
321
|
+
const allowedFlags = new Set(['--target', '--reason']);
|
|
322
|
+
assertNoUnknownOptions(args, allowedFlags);
|
|
323
|
+
const [id] = positionalArgs(args);
|
|
324
|
+
if (!id) throw new Error('Missing builtin id');
|
|
325
|
+
const targetRoot = path.resolve(optionValue(args, '--target', process.cwd()));
|
|
326
|
+
const reason = optionValue(args, '--reason', null);
|
|
327
|
+
assertInitializedBuildrWorkspace(targetRoot);
|
|
328
|
+
const component = packageBuiltinComponent(id);
|
|
329
|
+
if (component) throw new Error(`Buildr builtin ${id} is managed by Component ${component}. Use buildr component uninstall ${component} --agent <agent> --target ${targetRoot}.`);
|
|
330
|
+
const found = findBuiltinManifestEntry(targetRoot, id);
|
|
331
|
+
if (found.entry.required === true) throw new Error(`Required Buildr builtin cannot be uninstalled: ${id}`);
|
|
332
|
+
|
|
333
|
+
const updated = { ...found.entry, enabled: false, state: 'uninstalled' };
|
|
334
|
+
if (reason) updated.reason = reason;
|
|
335
|
+
const changed = [];
|
|
336
|
+
const receipts = readBuiltinReceipts(targetRoot);
|
|
337
|
+
const receiptIndex = receipts.builtins.findIndex((item) => item.type === found.type && item.id === id);
|
|
338
|
+
if (receiptIndex !== -1) {
|
|
339
|
+
receipts.builtins.splice(receiptIndex, 1);
|
|
340
|
+
changed.push(writeBuiltinReceipts(targetRoot, receipts));
|
|
341
|
+
}
|
|
342
|
+
if (found.type === 'rule') {
|
|
343
|
+
found.manifest.rules[found.index] = updated;
|
|
344
|
+
if (found.entry.path && existsFile(path.join(targetRoot, found.entry.path))) {
|
|
345
|
+
fs.rmSync(path.join(targetRoot, found.entry.path), { force: true });
|
|
346
|
+
changed.push(found.entry.path);
|
|
347
|
+
}
|
|
348
|
+
changed.push(toPosixRelative(targetRoot, writeRulesManifest(targetRoot, found.manifest)));
|
|
349
|
+
} else if (found.type === 'skill') {
|
|
350
|
+
found.manifest[found.index] = updated;
|
|
351
|
+
const skillDir = path.join(targetRoot, 'skills', found.entry.path || id);
|
|
352
|
+
if (existsDirectory(skillDir)) {
|
|
353
|
+
fs.rmSync(skillDir, { recursive: true, force: true });
|
|
354
|
+
changed.push(toPosixRelative(targetRoot, skillDir));
|
|
355
|
+
}
|
|
356
|
+
for (const runtimeRoot of ['.claude', '.agents']) {
|
|
357
|
+
const runtimeDir = path.join(targetRoot, runtimeRoot, 'skills', found.entry.runtimePath || id);
|
|
358
|
+
if (existsDirectory(runtimeDir)) {
|
|
359
|
+
fs.rmSync(runtimeDir, { recursive: true, force: true });
|
|
360
|
+
changed.push(toPosixRelative(targetRoot, runtimeDir));
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
changed.push(toPosixRelative(targetRoot, writeSkillsManifest(targetRoot, found.manifest)));
|
|
364
|
+
} else {
|
|
365
|
+
found.manifest.commands[found.index] = updated;
|
|
366
|
+
changed.push(toPosixRelative(targetRoot, writeCommandsManifest(targetRoot, found.manifest)));
|
|
367
|
+
}
|
|
368
|
+
console.log(`已卸载 Buildr builtin:${id}`);
|
|
369
|
+
for (const file of [...new Set(changed)]) console.log(` ${file}`);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function builtinUninstall(args) {
|
|
373
|
+
const targetRoot = path.resolve(optionValue(args, '--target', process.cwd()));
|
|
374
|
+
return withWorkspaceMutation(targetRoot, 'builtin.uninstall', [
|
|
375
|
+
path.join(targetRoot, 'rules'),
|
|
376
|
+
path.join(targetRoot, 'skills'),
|
|
377
|
+
path.join(targetRoot, 'commands'),
|
|
378
|
+
path.join(targetRoot, '.claude', 'skills'),
|
|
379
|
+
path.join(targetRoot, '.agents', 'skills'),
|
|
380
|
+
path.join(targetRoot, '.buildr', 'builtin-receipts.json'),
|
|
381
|
+
], () => builtinUninstallUnsafe(args));
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function builtinRestoreUnsafe(args) {
|
|
385
|
+
const allowedFlags = new Set(['--target']);
|
|
386
|
+
assertNoUnknownOptions(args, allowedFlags);
|
|
387
|
+
const [id] = positionalArgs(args);
|
|
388
|
+
if (!id) throw new Error('Missing builtin id');
|
|
389
|
+
const targetRoot = path.resolve(optionValue(args, '--target', process.cwd()));
|
|
390
|
+
assertInitializedBuildrWorkspace(targetRoot);
|
|
391
|
+
const component = packageBuiltinComponent(id);
|
|
392
|
+
if (component) throw new Error(`Buildr builtin ${id} is managed by Component ${component}. Use buildr component install ${component} --agent <agent> --target ${targetRoot}.`);
|
|
393
|
+
const result = syncPackageBuiltins(targetRoot, { restoreId: id });
|
|
394
|
+
if (!result.findings.some((finding) => finding.id === id)) throw new Error(`Buildr builtin not found in package: ${id}`);
|
|
395
|
+
console.log(`已恢复 Buildr builtin:${id}`);
|
|
396
|
+
for (const file of result.changed) console.log(` ${file}`);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function builtinRestore(args) {
|
|
400
|
+
const targetRoot = path.resolve(optionValue(args, '--target', process.cwd()));
|
|
401
|
+
return withWorkspaceMutation(targetRoot, 'builtin.restore', [path.join(targetRoot, 'rules'), path.join(targetRoot, 'skills'), path.join(targetRoot, 'commands'), path.join(targetRoot, 'components'), path.join(targetRoot, '.buildr', 'builtin-receipts.json')], () => builtinRestoreUnsafe(args));
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
const {
|
|
405
|
+
validateWorkspaceSkillsBaseline,
|
|
406
|
+
validateWorkspaceRulesBaseline,
|
|
407
|
+
validatePackageStatic,
|
|
408
|
+
} = createPackageStaticValidator({
|
|
409
|
+
LEGACY_PACKAGE_PATHS,
|
|
410
|
+
PACKAGE_RUNTIME_TARGET,
|
|
411
|
+
PACKAGE_WORKSPACE_TARGET,
|
|
412
|
+
collectFiles,
|
|
413
|
+
componentMemberPaths,
|
|
414
|
+
existsDirectory,
|
|
415
|
+
existsFile,
|
|
416
|
+
fs,
|
|
417
|
+
isManifestSourceLabel,
|
|
418
|
+
isPlainObject,
|
|
419
|
+
normalizeRelativePathForBuildr,
|
|
420
|
+
packageComponentDefinition,
|
|
421
|
+
packageComponentSourcePath,
|
|
422
|
+
packageWorkspaceTargetRoot,
|
|
423
|
+
parseCommandsManifestYaml,
|
|
424
|
+
parseManifestFileEntry,
|
|
425
|
+
parseProjectsYaml,
|
|
426
|
+
parseSkillFrontmatter,
|
|
427
|
+
parseSkillSourceRef,
|
|
428
|
+
path,
|
|
429
|
+
readPackageManifest,
|
|
430
|
+
readSkillManifest,
|
|
431
|
+
toPosixRelative,
|
|
432
|
+
validateBootstrapContract,
|
|
433
|
+
validateCommandsManifest,
|
|
434
|
+
validatePackageComponentMembers,
|
|
435
|
+
validateProjectsRegistry,
|
|
436
|
+
validateSkillManifestEntries,
|
|
437
|
+
});
|
|
438
|
+
const {
|
|
439
|
+
runPackageSmokeChecks,
|
|
440
|
+
} = createPackageSmokeChecks({
|
|
441
|
+
BUILDR_REQUIRED_BLOCK_START,
|
|
442
|
+
buildRuleDiscoveryPlan,
|
|
443
|
+
checkClaudeCodeRuntime,
|
|
444
|
+
checkCodexRuntime,
|
|
445
|
+
collectFiles,
|
|
446
|
+
commandsCheck,
|
|
447
|
+
ensureDirectory,
|
|
448
|
+
execFileSync,
|
|
449
|
+
existsDirectory,
|
|
450
|
+
existsFile,
|
|
451
|
+
fs,
|
|
452
|
+
hasManagedRulesMarker,
|
|
453
|
+
os,
|
|
454
|
+
parseCommandsManifestYaml,
|
|
455
|
+
parseManifestFileEntry,
|
|
456
|
+
parseProjectsYaml,
|
|
457
|
+
parseRulesManifestYaml,
|
|
458
|
+
path,
|
|
459
|
+
process,
|
|
460
|
+
readSkillManifest,
|
|
461
|
+
renderClaudeCodeRules,
|
|
462
|
+
resolveRuleScope,
|
|
463
|
+
spawnSync,
|
|
464
|
+
toPosixRelative,
|
|
465
|
+
writeServicesManifest,
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
function packageCheck() {
|
|
469
|
+
const root = productRoot();
|
|
470
|
+
const workspaceRoot = developmentWorkspaceRoot();
|
|
471
|
+
const manifestPath = path.join(packageRoot(), 'manifest.yml');
|
|
472
|
+
const manifest = readPackageManifest();
|
|
473
|
+
const allowedVariables = new Set(manifest.templateVariables);
|
|
474
|
+
const files = [];
|
|
475
|
+
const problems = [];
|
|
476
|
+
const mappedEntries = [];
|
|
477
|
+
|
|
478
|
+
const context = { root, workspaceRoot, manifestPath, manifest, allowedVariables, files, problems, mappedEntries };
|
|
479
|
+
const { bootstrapContract, parseJsonOutput } = validatePackageStatic(context);
|
|
480
|
+
runPackageSmokeChecks({ ...context, bootstrapContract, parseJsonOutput });
|
|
481
|
+
|
|
482
|
+
if (problems.length > 0) {
|
|
483
|
+
console.error('Buildr package check failed:');
|
|
484
|
+
for (const problem of problems) console.error(`- ${problem}`);
|
|
485
|
+
process.exit(1);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
console.log(`Buildr package check passed. Checked ${manifest.include.length} include entries and ${files.length} files.`);
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
const {
|
|
492
|
+
packageOutputInventory,
|
|
493
|
+
packageOutputIntegrity,
|
|
494
|
+
readPackageOutputReceipt,
|
|
495
|
+
assertSafePackageOutput,
|
|
496
|
+
validateReplaceablePackageOutput,
|
|
497
|
+
buildPackageOutput,
|
|
498
|
+
packageBuild,
|
|
499
|
+
} = createPackageOutput({
|
|
500
|
+
assertSafeAssetTarget,
|
|
501
|
+
atomicWriteJson,
|
|
502
|
+
collectFiles,
|
|
503
|
+
crypto,
|
|
504
|
+
ensureDirectory,
|
|
505
|
+
existsDirectory,
|
|
506
|
+
existsFile,
|
|
507
|
+
fs,
|
|
508
|
+
optionValue,
|
|
509
|
+
packageRoot,
|
|
510
|
+
parseManifestFileEntry,
|
|
511
|
+
path,
|
|
512
|
+
productRoot,
|
|
513
|
+
readPackageManifest,
|
|
514
|
+
toPosixRelative,
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
Object.assign(runtime, {
|
|
518
|
+
syncPackageBuiltins,
|
|
519
|
+
builtinList,
|
|
520
|
+
packageBuiltinComponent,
|
|
521
|
+
findBuiltinManifestEntry,
|
|
522
|
+
builtinUninstallUnsafe,
|
|
523
|
+
builtinUninstall,
|
|
524
|
+
builtinRestoreUnsafe,
|
|
525
|
+
builtinRestore,
|
|
526
|
+
validateWorkspaceSkillsBaseline,
|
|
527
|
+
validateWorkspaceRulesBaseline,
|
|
528
|
+
packageCheck,
|
|
529
|
+
packageOutputInventory,
|
|
530
|
+
packageOutputIntegrity,
|
|
531
|
+
readPackageOutputReceipt,
|
|
532
|
+
assertSafePackageOutput,
|
|
533
|
+
validateReplaceablePackageOutput,
|
|
534
|
+
buildPackageOutput,
|
|
535
|
+
packageBuild,
|
|
536
|
+
});
|
|
537
|
+
return runtime;
|
|
538
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import {
|
|
2
|
+
path,
|
|
3
|
+
process,
|
|
4
|
+
spawnSync,
|
|
5
|
+
resolveRuleScope,
|
|
6
|
+
assembleRuntimeProjection,
|
|
7
|
+
getRuntimeAdapter,
|
|
8
|
+
reconcileRuntimePlan,
|
|
9
|
+
} from '../shared/platform.mjs';
|
|
10
|
+
|
|
11
|
+
export function registerApplicationRuntime(runtime) {
|
|
12
|
+
const syncPackageBuiltins = (...args) => runtime.syncPackageBuiltins(...args);
|
|
13
|
+
const doctor = (...args) => runtime.doctor(...args);
|
|
14
|
+
const syncPackageComponents = (...args) => runtime.syncPackageComponents(...args);
|
|
15
|
+
const buildRuntimeOrphanRemovalPlan = (...args) => runtime.buildRuntimeOrphanRemovalPlan(...args);
|
|
16
|
+
const optionValue = (...args) => runtime.optionValue(...args);
|
|
17
|
+
const withResolvedTarget = (...args) => runtime.withResolvedTarget(...args);
|
|
18
|
+
const skillScopeForRuleScope = (...args) => runtime.skillScopeForRuleScope(...args);
|
|
19
|
+
const withWorkspaceMutation = (...args) => runtime.withWorkspaceMutation(...args);
|
|
20
|
+
const productRoot = (...args) => runtime.productRoot(...args);
|
|
21
|
+
const toPosixRelative = (...args) => runtime.toPosixRelative(...args);
|
|
22
|
+
const assertInitializedBuildrWorkspace = (...args) => runtime.assertInitializedBuildrWorkspace(...args);
|
|
23
|
+
|
|
24
|
+
function renderRuntime(agent, args, options = {}) {
|
|
25
|
+
const renderArgs = [...args];
|
|
26
|
+
if (!renderArgs.includes('--scope')) {
|
|
27
|
+
renderArgs.push('--scope', '.');
|
|
28
|
+
}
|
|
29
|
+
const renderCommand = withResolvedTarget(renderArgs);
|
|
30
|
+
const { targetRoot } = renderCommand;
|
|
31
|
+
const requestedScope = optionValue(renderCommand.args, '--scope', '.');
|
|
32
|
+
const scopeInfo = resolveRuleScope(targetRoot, requestedScope);
|
|
33
|
+
const skillScope = skillScopeForRuleScope(scopeInfo.scope);
|
|
34
|
+
const removals = buildRuntimeOrphanRemovalPlan(targetRoot, agent, skillScope).map((item) => ({ ...item, targetFile: item.path }));
|
|
35
|
+
const { plan } = assembleRuntimeProjection({ repoRoot: targetRoot, targetRoot, scope: scopeInfo.scope, adapterId: agent, selection: { productSkill: options.productSkill === true, rules: true, workspaceSkills: true }, removals });
|
|
36
|
+
reconcileRuntimePlan(plan);
|
|
37
|
+
return { targetRoot, files: [...plan.writes.map((item) => item.targetFile), ...plan.removals.map((item) => item.targetFile)], rulesActions: plan.ruleActions, warnings: plan.warnings, scope: scopeInfo.scope };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function renderSkillsRuntime(agent, args) {
|
|
41
|
+
const renderCommand = withResolvedTarget(args);
|
|
42
|
+
const skillScope = optionValue(renderCommand.args, '--scope', '.');
|
|
43
|
+
const orphanPlan = buildRuntimeOrphanRemovalPlan(renderCommand.targetRoot, agent, skillScope).map((item) => ({ ...item, targetFile: item.path }));
|
|
44
|
+
const { plan } = assembleRuntimeProjection({ repoRoot: renderCommand.targetRoot, targetRoot: renderCommand.targetRoot, scope: skillScope, adapterId: agent, selection: { workspaceSkills: true }, removals: orphanPlan });
|
|
45
|
+
reconcileRuntimePlan(plan);
|
|
46
|
+
const files = [...plan.writes.map((item) => item.targetFile), ...plan.removals.map((item) => item.targetFile)];
|
|
47
|
+
const remaining = buildRuntimeOrphanRemovalPlan(renderCommand.targetRoot, agent, skillScope);
|
|
48
|
+
if (remaining.length) throw new Error(`运行时同步未完成,请重新运行 buildr skills render ${agent}。`);
|
|
49
|
+
return { targetRoot: renderCommand.targetRoot, files, plan: plan.writes };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function renderRulesRuntime(agent, args) {
|
|
53
|
+
const renderCommand = withResolvedTarget(args);
|
|
54
|
+
const scope = optionValue(renderCommand.args, '--scope', '.');
|
|
55
|
+
const { plan } = assembleRuntimeProjection({ repoRoot: renderCommand.targetRoot, targetRoot: renderCommand.targetRoot, scope, adapterId: agent, selection: { rules: true } });
|
|
56
|
+
reconcileRuntimePlan(plan);
|
|
57
|
+
return { targetRoot: renderCommand.targetRoot, files: plan.writes.map((item) => item.targetFile), actions: plan.ruleActions, warnings: plan.warnings };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function syncRuntime(agent, args) {
|
|
61
|
+
const adapter = getRuntimeAdapter(agent);
|
|
62
|
+
const syncArgs = [...args];
|
|
63
|
+
if (!syncArgs.includes('--scope')) syncArgs.push('--scope', '.');
|
|
64
|
+
const targetRoot = path.resolve(optionValue(syncArgs, '--target', process.cwd()));
|
|
65
|
+
assertInitializedBuildrWorkspace(targetRoot);
|
|
66
|
+
const updated = withWorkspaceMutation(targetRoot, `buildr.sync:${agent}`, [
|
|
67
|
+
path.join(targetRoot, 'AGENTS.md'),
|
|
68
|
+
path.join(targetRoot, '.gitignore'),
|
|
69
|
+
path.join(targetRoot, 'projects'),
|
|
70
|
+
path.join(targetRoot, 'rules'),
|
|
71
|
+
path.join(targetRoot, 'skills'),
|
|
72
|
+
path.join(targetRoot, 'commands'),
|
|
73
|
+
path.join(targetRoot, 'components'),
|
|
74
|
+
path.join(targetRoot, '.buildr', 'builtin-receipts.json'),
|
|
75
|
+
], () => {
|
|
76
|
+
const sourceUpdate = syncPackageBuiltins(targetRoot);
|
|
77
|
+
const components = syncPackageComponents(targetRoot);
|
|
78
|
+
if (components.errors.length) {
|
|
79
|
+
throw new Error(`sync 暂停:Component 源资产存在冲突。\n- ${components.errors.map((item) => item.error).join('\n- ')}`);
|
|
80
|
+
}
|
|
81
|
+
const needsDecision = sourceUpdate.findings.filter((finding) => !finding.component && !finding.required && ['modified', 'missing'].includes(finding.status));
|
|
82
|
+
if (needsDecision.length) {
|
|
83
|
+
throw new Error(`sync 暂停:以下 optional Buildr 内置能力需要用户决策。\n- ${needsDecision.map((item) => `${item.type}:${item.id} (${item.status})`).join('\n- ')}`);
|
|
84
|
+
}
|
|
85
|
+
sourceUpdate.changed.push(...components.changed);
|
|
86
|
+
return sourceUpdate;
|
|
87
|
+
});
|
|
88
|
+
const rendered = renderRuntime(agent, syncArgs, { productSkill: true });
|
|
89
|
+
const doctorResult = spawnSync(process.execPath, [path.join(productRoot(), 'tools', 'buildr'), 'doctor', '--agent', agent, '--target', targetRoot, '--json'], {
|
|
90
|
+
cwd: productRoot(),
|
|
91
|
+
encoding: 'utf8',
|
|
92
|
+
});
|
|
93
|
+
console.log(`已同步 Buildr 到 ${agent}:${targetRoot}`);
|
|
94
|
+
if (updated.changed.length > 0) {
|
|
95
|
+
console.log('产品能力变更:');
|
|
96
|
+
for (const file of updated.changed) console.log(` ${file}`);
|
|
97
|
+
}
|
|
98
|
+
if (rendered.files.length > 0) {
|
|
99
|
+
console.log('runtime 渲染:');
|
|
100
|
+
const ruleTargets = new Set(rendered.rulesActions.map((item) => item.targetFile));
|
|
101
|
+
for (const item of rendered.rulesActions) console.log(` [${item.action}] ${toPosixRelative(targetRoot, item.targetFile)}`);
|
|
102
|
+
for (const file of rendered.files) {
|
|
103
|
+
if (!ruleTargets.has(file)) console.log(` ${toPosixRelative(targetRoot, file)}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
for (const warning of rendered.warnings) console.error(`Warning: ${warning}`);
|
|
107
|
+
if (doctorResult.status !== 0) {
|
|
108
|
+
console.log('doctor 仍有需要处理的问题:');
|
|
109
|
+
process.stdout.write(doctorResult.stdout || '');
|
|
110
|
+
process.stderr.write(doctorResult.stderr || '');
|
|
111
|
+
throw new Error(`${agent} sync 未完成:最终 doctor 未通过。`);
|
|
112
|
+
}
|
|
113
|
+
console.log('doctor 通过。');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
Object.assign(runtime, { renderRuntime, renderSkillsRuntime, renderRulesRuntime, syncRuntime });
|
|
117
|
+
return runtime;
|
|
118
|
+
}
|