@buildr-ai/buildr 0.1.0-rc.2 → 0.1.0-rc.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -5
- package/application-payload.json +595 -0
- package/bin/buildr.mjs +14 -0
- package/installation-origin.json +13 -0
- package/package.json +16 -45
- package/payload/licenses/dependencies/yaml-LICENSE +13 -0
- package/payload/product/LICENSE +21 -0
- package/payload/product/README.md +59 -0
- package/payload/product/package/README.md +42 -0
- package/{package → payload/product/package}/bootstrap/contract.yml +26 -11
- package/{package → payload/product/package}/bootstrap/guide.md +11 -11
- package/payload/product/package/launchers/assets/Buildr.icns +0 -0
- package/payload/product/package/launchers/assets/Buildr.ico +0 -0
- package/payload/product/package/manifest.yml +547 -0
- package/payload/product/package/targets/runtime/skills/buildr/SKILL.md +174 -0
- package/{package → payload/product/package}/targets/workspace/commands/buildr/openspec/manifest.yml +2 -2
- package/payload/product/package/targets/workspace/components/buildr/openspec/component.yml +79 -0
- package/payload/product/package/targets/workspace/components/buildr/openspec/contributions/openspec-apply-sidebar.md +21 -0
- package/payload/product/package/targets/workspace/components/buildr/openspec/contributions/openspec-archive-converge.md +5 -0
- package/payload/product/package/targets/workspace/components/buildr/openspec/contributions/openspec-explore-terminology.md +5 -0
- package/payload/product/package/targets/workspace/components/buildr/openspec/contributions/openspec-propose-sidebar.md +21 -0
- package/payload/product/package/targets/workspace/components/buildr/openspec/contributions/openspec-sync-converge.md +5 -0
- package/payload/product/package/targets/workspace/components/buildr/openspec/contributions/openspec-update-sidebar.md +13 -0
- package/payload/product/package/targets/workspace/gitattributes +1 -0
- package/payload/product/package/targets/workspace/gitignore +31 -0
- package/{package → payload/product/package}/targets/workspace/projects/AGENTS.project.md +1 -1
- package/payload/product/package/targets/workspace/rules/buildr/core.md +62 -0
- package/payload/product/package/targets/workspace/skills/buildr/capability-adaptation/SKILL.md +56 -0
- package/payload/product/package/targets/workspace/skills/buildr/capability-adaptation/agents/openai.yaml +4 -0
- package/payload/product/package/targets/workspace/skills/buildr/current-knowledge-maintenance/SKILL.md +103 -0
- package/payload/product/package/targets/workspace/skills/buildr/declaration-intake/SKILL.md +65 -0
- package/payload/product/package/targets/workspace/skills/buildr/git-operations/SKILL.md +100 -0
- package/payload/product/package/targets/workspace/skills/buildr/openspec-contract-guard/SKILL.md +65 -0
- package/payload/product/package/targets/workspace/skills/buildr/project-daily-progress/SKILL.md +52 -0
- package/payload/product/package/targets/workspace/skills/buildr/project-testing/SKILL.md +84 -0
- package/payload/product/package/targets/workspace/skills/buildr/project-testing/references/testing-model-v1.md +116 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-development/SKILL.md +108 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-environment/SKILL.md +42 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-environment/agents/openai.yaml +4 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-environment/references/project-environment-preparation-v1.md +14 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-environment/templates/project-preparation.yml +20 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-environment/templates/task-environment-plan-request.json +17 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-finish/SKILL.md +80 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-manager/SKILL.md +47 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-manager/agents/openai.yaml +4 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-retrospective/SKILL.md +101 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-retrospective/agents/openai.yaml +4 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-review/SKILL.md +60 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-review/agents/openai.yaml +4 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-triage/SKILL.md +119 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-verification/SKILL.md +142 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-verification/references/project-verification-v2.md +51 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-verification/templates/project-verification.yml +16 -0
- package/payload/product/package/targets/workspace/skills/buildr/task-worktree/SKILL.md +28 -0
- package/payload/product/package/targets/workspace/skills/buildr/terminology-governance/SKILL.md +60 -0
- package/payload/product/package/targets/workspace/skills/buildr/ui-preview/SKILL.md +74 -0
- package/payload/product/package/targets/workspace/skills/contracts/buildr/current-knowledge-maintenance/v1.md +36 -0
- package/payload/product/package/targets/workspace/skills/contracts/buildr/current-knowledge-maintenance/v2.md +45 -0
- package/payload/product/package/targets/workspace/skills/contracts/buildr/git-operations/v1.md +39 -0
- package/payload/product/package/targets/workspace/skills/contracts/buildr/git-worktree-provider/v1.md +35 -0
- package/payload/product/package/targets/workspace/skills/contracts/buildr/task-development/v2.md +61 -0
- package/payload/product/package/targets/workspace/skills/contracts/buildr/task-environment/v1.md +37 -0
- package/payload/product/package/targets/workspace/skills/contracts/buildr/task-finish/v1.md +59 -0
- package/payload/product/package/targets/workspace/skills/contracts/buildr/task-record/v2.md +35 -0
- package/payload/product/package/targets/workspace/skills/contracts/buildr/task-retrospective/v2.md +41 -0
- package/payload/product/package/targets/workspace/skills/contracts/buildr/task-review/v1.md +39 -0
- package/payload/product/package/targets/workspace/skills/contracts/buildr/task-verification/v3.md +63 -0
- package/payload/product/package/targets/workspace/skills/contracts/buildr/terminology-governance/v1.md +36 -0
- package/{package → payload/product/package}/targets/workspace/skills/openspec/openspec-apply-change/SKILL.md +4 -3
- package/{package → payload/product/package}/targets/workspace/skills/openspec/openspec-archive-change/SKILL.md +4 -3
- package/{package → payload/product/package}/targets/workspace/skills/openspec/openspec-explore/SKILL.md +4 -1
- package/{package → payload/product/package}/targets/workspace/skills/openspec/openspec-propose/SKILL.md +4 -1
- package/{package → payload/product/package}/targets/workspace/skills/openspec/openspec-sync-specs/SKILL.md +4 -3
- package/payload/product/package/targets/workspace/skills/openspec/openspec-update-change/SKILL.md +86 -0
- package/payload/product/package.json +33 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0000_create_migration_ledger.sql +16 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0001_create_task_store.sql +47 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0002_create_parent_task_relations.sql +7 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0003_inline_parent_task_column.sql +19 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0004_create_task_current_records.sql +16 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0005_create_task_retrospective_current.sql +4 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0006_create_task_lifecycle_current.sql +4 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0007_create_task_finish_current.sql +46 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0008_create_task_environment_current.sql +8 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0009_retire_task_lifecycle_current.sql +107 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0010_add_task_retrospective_disposition.sql +19 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0011_create_task_execution_records.sql +115 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0012_compact_task_finish_current.sql +261 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0013_add_todo_task_retrospective_sources.sql +56 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0014_add_task_execution_invocation_identity.sql +14 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0015_add_task_execution_unknown_outcome.sql +143 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0016_allow_terminal_task_finish_target_lease.sql +83 -0
- package/payload/product/src/infrastructure/sqlite/migrations/0017_expand_task_finish_repository_set.sql +111 -0
- package/payload/product/src/interfaces/local-app/web-dist/assets/antd-NAtxFWmu.js +394 -0
- package/payload/product/src/interfaces/local-app/web-dist/assets/index-BqoyfMSY.css +1 -0
- package/payload/product/src/interfaces/local-app/web-dist/assets/index-DTqvE0TF.js +39 -0
- package/payload/product/src/interfaces/local-app/web-dist/assets/react-9kRp7SbA.js +28 -0
- package/payload/product/src/interfaces/local-app/web-dist/index.html +19 -0
- package/payload/runtime/read-worker.cjs +45071 -0
- package/runtime/buildr.cjs +51533 -0
- package/scripts/postinstall.mjs +15 -0
- package/docs/agent-runtime-adapters.md +0 -94
- package/docs/cli-architecture.md +0 -65
- package/docs/cli-reference.md +0 -67
- package/docs/known-limitations.md +0 -15
- package/examples/minimal-workspace/README.md +0 -24
- package/package/README.md +0 -28
- package/package/manifest.yml +0 -150
- package/package/targets/runtime/skills/buildr/SKILL.md +0 -154
- package/package/targets/workspace/.buildr/workspace.yml +0 -5
- package/package/targets/workspace/commands/manifest.yml +0 -2
- package/package/targets/workspace/components/buildr/openspec/component.yml +0 -16
- package/package/targets/workspace/components/buildr/openspec/contributions/openspec-apply-sidebar.md +0 -3
- package/package/targets/workspace/components/buildr/openspec/contributions/openspec-archive-sidebar.md +0 -3
- package/package/targets/workspace/components/buildr/openspec/contributions/openspec-explore-sidebar.md +0 -3
- package/package/targets/workspace/components/buildr/openspec/contributions/openspec-propose-sidebar.md +0 -3
- package/package/targets/workspace/components/buildr/openspec/contributions/openspec-sync-sidebar.md +0 -3
- package/package/targets/workspace/components/buildr/openspec/contributions/task-finish-post-sync.md +0 -1
- package/package/targets/workspace/components/buildr/openspec/contributions/task-finish-pre-sync.md +0 -1
- package/package/targets/workspace/components/buildr/openspec/contributions/task-triage-change-ready.md +0 -10
- package/package/targets/workspace/components/manifest.yml +0 -2
- package/package/targets/workspace/gitignore +0 -16
- package/package/targets/workspace/projects/manifest.yml +0 -2
- package/package/targets/workspace/projects/services/manifest.yml +0 -3
- package/package/targets/workspace/projects/skills/manifest.yml +0 -2
- package/package/targets/workspace/rules/buildr/core.md +0 -65
- package/package/targets/workspace/rules/manifest.yml +0 -9
- package/package/targets/workspace/skills/buildr/git-ops/SKILL.md +0 -73
- package/package/targets/workspace/skills/buildr/openspec-contract-guard/SKILL.md +0 -67
- package/package/targets/workspace/skills/buildr/task-finish/SKILL.md +0 -104
- package/package/targets/workspace/skills/buildr/task-triage/SKILL.md +0 -103
- package/package/targets/workspace/skills/buildr/task-worktree/SKILL.md +0 -104
- package/package/targets/workspace/skills/manifest.yml +0 -38
- package/tools/buildr +0 -11
- package/tools/cli/application/cli-update.mjs +0 -219
- package/tools/cli/application/compose-runtime.mjs +0 -38
- package/tools/cli/application/doctor/runtime-diagnostics.mjs +0 -227
- package/tools/cli/application/doctor/scope-diagnostics.mjs +0 -440
- package/tools/cli/application/doctor/service-diagnostics.mjs +0 -184
- package/tools/cli/application/doctor.mjs +0 -201
- package/tools/cli/application/package-maintenance/builtin-receipts.mjs +0 -73
- package/tools/cli/application/package-maintenance/output.mjs +0 -148
- package/tools/cli/application/package-maintenance/smoke-checks.mjs +0 -463
- package/tools/cli/application/package-maintenance/static-validation.mjs +0 -680
- package/tools/cli/application/package-maintenance.mjs +0 -540
- package/tools/cli/application/runtime.mjs +0 -118
- package/tools/cli/application/workspace-operations.mjs +0 -311
- package/tools/cli/bootstrap.mjs +0 -6
- package/tools/cli/command/help.mjs +0 -296
- package/tools/cli/command/registry.mjs +0 -97
- package/tools/cli/domains/commands.mjs +0 -661
- package/tools/cli/domains/components.mjs +0 -922
- package/tools/cli/domains/openspec.mjs +0 -603
- package/tools/cli/domains/package-assets.mjs +0 -652
- package/tools/cli/domains/rules.mjs +0 -380
- package/tools/cli/domains/runtime.mjs +0 -87
- package/tools/cli/domains/skills.mjs +0 -647
- package/tools/cli/domains/workspace.mjs +0 -571
- package/tools/cli/shared/infrastructure.mjs +0 -411
- package/tools/cli/shared/json-contracts.mjs +0 -22
- package/tools/cli/shared/platform.mjs +0 -52
- package/tools/runtime/adapter-contract.mjs +0 -655
- package/tools/runtime/check-claude-code.mjs +0 -23
- package/tools/runtime/check-codex.mjs +0 -23
- package/tools/runtime/check-runtime.mjs +0 -98
- package/tools/runtime/projection.mjs +0 -375
- package/tools/runtime/render-claude-code-rules.mjs +0 -459
- package/tools/runtime/render-claude-code.mjs +0 -59
- package/tools/runtime/skills/arguments.mjs +0 -51
- package/tools/runtime/skills/contributions.mjs +0 -171
- package/tools/runtime/skills/manifests.mjs +0 -167
- package/tools/runtime/skills/primitives.mjs +0 -86
- package/tools/runtime/skills/render-plan.mjs +0 -243
- package/tools/runtime/skills/sources.mjs +0 -276
- package/tools/shared/fetch-remote-text.mjs +0 -78
- package/tools/verification/integrity/managed-data-integrity.mjs +0 -107
- package/tools/verification/integrity/managed-mutations.mjs +0 -72
- package/tools/verification/openspec/contract.mjs +0 -212
- package/tools/verification/runtime/adapter-contract.mjs +0 -218
- package/tools/verification/runtime/adapter-parity.mjs +0 -173
- /package/{package → payload/product/package}/targets/workspace/AGENTS.md +0 -0
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
export function createServiceDiagnostics(deps) {
|
|
2
|
-
const {
|
|
3
|
-
addDoctorFinding,
|
|
4
|
-
existsDirectory,
|
|
5
|
-
existsFile,
|
|
6
|
-
fs,
|
|
7
|
-
gitBoundaryFor,
|
|
8
|
-
gitBoundaryIgnored,
|
|
9
|
-
gitCurrentBranch,
|
|
10
|
-
gitignoreLines,
|
|
11
|
-
listManagedDirectories,
|
|
12
|
-
parseServicesManifestYaml,
|
|
13
|
-
path,
|
|
14
|
-
projectDoctorContextFor,
|
|
15
|
-
readGitRemote,
|
|
16
|
-
toPosixRelative,
|
|
17
|
-
validateServicesManifest,
|
|
18
|
-
} = deps;
|
|
19
|
-
|
|
20
|
-
function diagnoseServicesMetadata(result, targetRoot, owner, metadataPath, baseRoot, serviceLabel, ignoreLines) {
|
|
21
|
-
if (!existsFile(metadataPath)) {
|
|
22
|
-
if (existsDirectory(baseRoot)) {
|
|
23
|
-
addDoctorFinding(result, 'warning', 'services.manifest_missing', `Service manifest 缺失:${serviceLabel}`, {
|
|
24
|
-
path: toPosixRelative(targetRoot, metadataPath),
|
|
25
|
-
suggestion: '运行 buildr update 或 buildr sync 创建 services/manifest.yml。',
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
let manifest;
|
|
32
|
-
try {
|
|
33
|
-
manifest = parseServicesManifestYaml(fs.readFileSync(metadataPath, 'utf8'));
|
|
34
|
-
} catch (error) {
|
|
35
|
-
addDoctorFinding(result, 'warning', 'services.manifest_invalid', `Service manifest 不可解析:${error.message}`, {
|
|
36
|
-
path: toPosixRelative(targetRoot, metadataPath),
|
|
37
|
-
suggestion: '修复 services/manifest.yml 语法后重新运行 doctor。',
|
|
38
|
-
});
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const validationErrors = validateServicesManifest(manifest, owner.project);
|
|
43
|
-
for (const message of validationErrors) {
|
|
44
|
-
addDoctorFinding(result, 'warning', 'services.manifest_invalid', message, {
|
|
45
|
-
path: toPosixRelative(targetRoot, metadataPath),
|
|
46
|
-
suggestion: '运行 buildr update 或 buildr sync 修复低风险默认值并清理未知字段;project 字段冲突需要人工确认。',
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (existsFile(path.join(baseRoot, 'services.yml'))) {
|
|
51
|
-
addDoctorFinding(result, 'warning', 'services.legacy_manifest_present', `旧 Service registry 文件仍存在:${serviceLabel}`, {
|
|
52
|
-
path: toPosixRelative(targetRoot, path.join(baseRoot, 'services.yml')),
|
|
53
|
-
suggestion: '运行 buildr update 或 buildr sync 转换或删除旧 services.yml。',
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const registered = new Set(Object.keys(manifest.services || {}));
|
|
58
|
-
const servicesRoot = path.join(baseRoot, 'services');
|
|
59
|
-
for (const serviceName of listManagedDirectories(servicesRoot)) {
|
|
60
|
-
if (!registered.has(serviceName)) {
|
|
61
|
-
addDoctorFinding(result, 'warning', 'services.unregistered', `Service 目录未登记:${serviceLabel}/${serviceName}`, {
|
|
62
|
-
path: toPosixRelative(targetRoot, path.join(servicesRoot, serviceName)),
|
|
63
|
-
suggestion: '运行 buildr update 或 buildr sync 将既有 Service 目录补登记到 services/manifest.yml。',
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
for (const [serviceName, metadata] of Object.entries(manifest.services || {})) {
|
|
69
|
-
if (owner.servicePath && owner.servicePath.split('/')[0] !== serviceName) continue;
|
|
70
|
-
const repo = metadata.repo || {};
|
|
71
|
-
const repoPath = path.join(baseRoot, metadata.path || `services/${serviceName}`);
|
|
72
|
-
const service = {
|
|
73
|
-
org: owner.org,
|
|
74
|
-
project: owner.project || null,
|
|
75
|
-
name: serviceName,
|
|
76
|
-
title: metadata.title || null,
|
|
77
|
-
description: metadata.description || null,
|
|
78
|
-
type: metadata.type || null,
|
|
79
|
-
repo: repo,
|
|
80
|
-
path: toPosixRelative(targetRoot, repoPath),
|
|
81
|
-
exists: repoPath ? existsDirectory(repoPath) : false,
|
|
82
|
-
isGitRepository: repoPath ? existsDirectory(path.join(repoPath, '.git')) : false,
|
|
83
|
-
};
|
|
84
|
-
result.services.push(service);
|
|
85
|
-
|
|
86
|
-
if (!metadata.description || String(metadata.description).startsWith('TODO:')) {
|
|
87
|
-
addDoctorFinding(result, 'warning', 'services.description_todo', `Service 缺少有效 description:${serviceLabel}/${serviceName}`, {
|
|
88
|
-
path: toPosixRelative(targetRoot, metadataPath),
|
|
89
|
-
suggestion: '补充 Service description,说明该 Service 的适用场景和用途。',
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (!repo.kind) {
|
|
94
|
-
addDoctorFinding(result, 'warning', 'service.repo_kind_missing', `Service 缺少 repo kind:${serviceLabel}/${serviceName}`, {
|
|
95
|
-
path: toPosixRelative(targetRoot, metadataPath),
|
|
96
|
-
suggestion: '运行 buildr update 或 buildr sync 补齐 repo.kind。',
|
|
97
|
-
});
|
|
98
|
-
continue;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (!service.exists) {
|
|
102
|
-
const suggestion = repo.kind === 'git' && repo.url
|
|
103
|
-
? '询问用户是否根据 metadata 自动 clone 该 service repo。'
|
|
104
|
-
: '确认 service repo 路径是否变更。';
|
|
105
|
-
const command = repo.kind === 'git' && repo.url
|
|
106
|
-
? `buildr service create ${owner.project}/${serviceName} ${repo.url}${repo.branch ? ` --branch ${repo.branch}` : ''} --target ${targetRoot}`
|
|
107
|
-
: undefined;
|
|
108
|
-
addDoctorFinding(result, repo.kind === 'git' ? 'warning' : 'error', `service.${repo.kind}.missing`, `Service repo 缺失:${serviceLabel}/${serviceName}`, {
|
|
109
|
-
path: service.path,
|
|
110
|
-
suggestion,
|
|
111
|
-
command,
|
|
112
|
-
});
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (repo.kind === 'git' && !service.isGitRepository) {
|
|
117
|
-
addDoctorFinding(result, 'error', 'service.not_git_repository', `Service 路径不是 Git repo:${serviceLabel}/${serviceName}`, {
|
|
118
|
-
path: service.path,
|
|
119
|
-
suggestion: '确认路径是否指向正确的 service repo。',
|
|
120
|
-
});
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (repo.kind === 'git' && !repo.url) {
|
|
125
|
-
addDoctorFinding(result, 'warning', 'service.git_url_missing', `Git Service 缺少 repo.url:${serviceLabel}/${serviceName}`, {
|
|
126
|
-
path: toPosixRelative(targetRoot, metadataPath),
|
|
127
|
-
suggestion: '补充 Git remote URL,或确认该 Service 只作为本地 Git 资产管理。',
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (repo.kind === 'git' && repo.url) {
|
|
132
|
-
const remoteName = repo.remote || 'origin';
|
|
133
|
-
const actualRemote = readGitRemote(repoPath, remoteName);
|
|
134
|
-
service.actualRemote = actualRemote;
|
|
135
|
-
if (actualRemote !== repo.url) {
|
|
136
|
-
addDoctorFinding(result, 'warning', 'service.remote_mismatch', `Service remote 与 metadata 不一致:${serviceLabel}/${serviceName}`, {
|
|
137
|
-
path: service.path,
|
|
138
|
-
expected: repo.url,
|
|
139
|
-
actual: actualRemote,
|
|
140
|
-
suggestion: '确认 repo 来源,必要时更新 metadata 或 Git remote。',
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (repo.kind === 'git') {
|
|
146
|
-
service.currentBranch = gitCurrentBranch(repoPath);
|
|
147
|
-
if (repo.branch && service.currentBranch !== repo.branch) {
|
|
148
|
-
addDoctorFinding(result, 'warning', 'service.branch_mismatch', `Service 当前分支与 metadata branch intent 不一致:${serviceLabel}/${serviceName}`, {
|
|
149
|
-
path: service.path,
|
|
150
|
-
expected: repo.branch,
|
|
151
|
-
actual: service.currentBranch,
|
|
152
|
-
suggestion: `切换到 ${repo.branch},或显式更新 Service branch intent。`,
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const boundary = gitBoundaryFor(targetRoot, { type: 'service', project: owner.project, service: serviceName, assetRoot: repoPath });
|
|
158
|
-
service.ignoredByWorkspace = gitBoundaryIgnored(boundary);
|
|
159
|
-
if (!service.ignoredByWorkspace) {
|
|
160
|
-
addDoctorFinding(result, 'warning', 'gitignore.service_repo_not_ignored', `嵌套 service repo 未被上级 .gitignore 忽略:${serviceLabel}/${serviceName}`, {
|
|
161
|
-
path: service.path,
|
|
162
|
-
suggestion: '运行 buildr update 或 buildr sync 补齐最近上级 Git repo 的 .gitignore 边界。',
|
|
163
|
-
pattern: boundary?.pattern,
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function diagnoseServices(result, targetRoot, scopes) {
|
|
170
|
-
result.services = [];
|
|
171
|
-
const ignoreLines = gitignoreLines(targetRoot);
|
|
172
|
-
|
|
173
|
-
for (const item of scopes) {
|
|
174
|
-
if (!item.project) continue;
|
|
175
|
-
const { projectRoot, metadataPath } = projectDoctorContextFor(targetRoot, item);
|
|
176
|
-
diagnoseServicesMetadata(result, targetRoot, item, metadataPath, projectRoot, item.project, ignoreLines);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
return {
|
|
181
|
-
diagnoseServicesMetadata,
|
|
182
|
-
diagnoseServices,
|
|
183
|
-
};
|
|
184
|
-
}
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
fs,
|
|
3
|
-
path,
|
|
4
|
-
execFileSync,
|
|
5
|
-
SUPPORTED_AGENT_IDS,
|
|
6
|
-
UNSUPPORTED_AGENT_GUIDANCE,
|
|
7
|
-
getRuntimeAdapter,
|
|
8
|
-
isSupportedAgent,
|
|
9
|
-
RUNTIME_CHECKERS,
|
|
10
|
-
} from '../shared/platform.mjs';
|
|
11
|
-
import { createRuntimeDiagnostics } from './doctor/runtime-diagnostics.mjs';
|
|
12
|
-
import { createScopeDiagnostics } from './doctor/scope-diagnostics.mjs';
|
|
13
|
-
import { createServiceDiagnostics } from './doctor/service-diagnostics.mjs';
|
|
14
|
-
|
|
15
|
-
export function registerApplicationDoctor(runtime) {
|
|
16
|
-
const runCommandsCheck = (...args) => runtime.runCommandsCheck(...args);
|
|
17
|
-
const componentRegistryPath = (...args) => runtime.componentRegistryPath(...args);
|
|
18
|
-
const packageComponentsStatus = (...args) => runtime.packageComponentsStatus(...args);
|
|
19
|
-
const managedRuntimeSkillOrphans = (...args) => runtime.managedRuntimeSkillOrphans(...args);
|
|
20
|
-
const listManagedDirectories = (...args) => runtime.listManagedDirectories(...args);
|
|
21
|
-
const runtimeImplementation = (...args) => runtime.runtimeImplementation(...args);
|
|
22
|
-
const readSkillManifestSchemaVersion = (...args) => runtime.readSkillManifestSchemaVersion(...args);
|
|
23
|
-
const skillsManifestPath = (...args) => runtime.skillsManifestPath(...args);
|
|
24
|
-
const parseYamlValue = (...args) => runtime.parseYamlValue(...args);
|
|
25
|
-
const parseServicesManifestYaml = (...args) => runtime.parseServicesManifestYaml(...args);
|
|
26
|
-
const parseProjectsYaml = (...args) => runtime.parseProjectsYaml(...args);
|
|
27
|
-
const validateProjectsRegistry = (...args) => runtime.validateProjectsRegistry(...args);
|
|
28
|
-
const validateServicesManifest = (...args) => runtime.validateServicesManifest(...args);
|
|
29
|
-
const projectsManifestPath = (...args) => runtime.projectsManifestPath(...args);
|
|
30
|
-
const servicesManifestPath = (...args) => runtime.servicesManifestPath(...args);
|
|
31
|
-
const gitOutput = (...args) => runtime.gitOutput(...args);
|
|
32
|
-
const gitCurrentBranch = (...args) => runtime.gitCurrentBranch(...args);
|
|
33
|
-
const gitBoundaryFor = (...args) => runtime.gitBoundaryFor(...args);
|
|
34
|
-
const gitBoundaryIgnored = (...args) => runtime.gitBoundaryIgnored(...args);
|
|
35
|
-
const toPosixRelative = (...args) => runtime.toPosixRelative(...args);
|
|
36
|
-
const existsDirectory = (...args) => runtime.existsDirectory(...args);
|
|
37
|
-
const existsFile = (...args) => runtime.existsFile(...args);
|
|
38
|
-
const addDoctorFinding = (...args) => runtime.addDoctorFinding(...args);
|
|
39
|
-
|
|
40
|
-
const {
|
|
41
|
-
scopeParts,
|
|
42
|
-
workspaceName,
|
|
43
|
-
readProjectsRegistryIfExists,
|
|
44
|
-
discoverDoctorScopes,
|
|
45
|
-
resolveRepoPath,
|
|
46
|
-
readGitRemote,
|
|
47
|
-
gitignoreLines,
|
|
48
|
-
isIgnoredByWorkspace,
|
|
49
|
-
projectDoctorContextFor,
|
|
50
|
-
projectBaselineStatus,
|
|
51
|
-
missingProjectBaselineAssets,
|
|
52
|
-
diagnoseProjectRegistry,
|
|
53
|
-
diagnoseWorkspace,
|
|
54
|
-
diagnoseLegacyPractices,
|
|
55
|
-
diagnoseHierarchy,
|
|
56
|
-
} = createScopeDiagnostics({
|
|
57
|
-
addDoctorFinding,
|
|
58
|
-
execFileSync,
|
|
59
|
-
existsDirectory,
|
|
60
|
-
existsFile,
|
|
61
|
-
fs,
|
|
62
|
-
gitBoundaryFor,
|
|
63
|
-
gitBoundaryIgnored,
|
|
64
|
-
gitOutput,
|
|
65
|
-
parseProjectsYaml,
|
|
66
|
-
parseYamlValue,
|
|
67
|
-
path,
|
|
68
|
-
projectsManifestPath,
|
|
69
|
-
servicesManifestPath,
|
|
70
|
-
toPosixRelative,
|
|
71
|
-
validateProjectsRegistry,
|
|
72
|
-
});
|
|
73
|
-
const {
|
|
74
|
-
diagnoseServicesMetadata,
|
|
75
|
-
diagnoseServices,
|
|
76
|
-
} = createServiceDiagnostics({
|
|
77
|
-
addDoctorFinding,
|
|
78
|
-
existsDirectory,
|
|
79
|
-
existsFile,
|
|
80
|
-
fs,
|
|
81
|
-
gitBoundaryFor,
|
|
82
|
-
gitBoundaryIgnored,
|
|
83
|
-
gitCurrentBranch,
|
|
84
|
-
gitignoreLines,
|
|
85
|
-
listManagedDirectories,
|
|
86
|
-
parseServicesManifestYaml,
|
|
87
|
-
path,
|
|
88
|
-
projectDoctorContextFor,
|
|
89
|
-
readGitRemote,
|
|
90
|
-
toPosixRelative,
|
|
91
|
-
validateServicesManifest,
|
|
92
|
-
});
|
|
93
|
-
const {
|
|
94
|
-
runtimeFindingsForDoctor,
|
|
95
|
-
summarizeRuntimeFindings,
|
|
96
|
-
addUnsupportedAgentFinding,
|
|
97
|
-
diagnoseRuntime,
|
|
98
|
-
diagnoseCommands,
|
|
99
|
-
diagnoseComponents,
|
|
100
|
-
} = createRuntimeDiagnostics({
|
|
101
|
-
RUNTIME_CHECKERS,
|
|
102
|
-
SUPPORTED_AGENT_IDS,
|
|
103
|
-
UNSUPPORTED_AGENT_GUIDANCE,
|
|
104
|
-
addDoctorFinding,
|
|
105
|
-
componentRegistryPath,
|
|
106
|
-
existsFile,
|
|
107
|
-
getRuntimeAdapter,
|
|
108
|
-
isSupportedAgent,
|
|
109
|
-
managedRuntimeSkillOrphans,
|
|
110
|
-
packageComponentsStatus,
|
|
111
|
-
path,
|
|
112
|
-
runCommandsCheck,
|
|
113
|
-
runtimeImplementation,
|
|
114
|
-
toPosixRelative,
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
function diagnoseSkillsManifestSchemas(result, targetRoot, scopes) {
|
|
118
|
-
const checked = new Set();
|
|
119
|
-
const scopeRoots = [targetRoot];
|
|
120
|
-
for (const scope of scopes) {
|
|
121
|
-
if (scope.project) scopeRoots.push(path.join(targetRoot, 'projects', scope.project));
|
|
122
|
-
}
|
|
123
|
-
for (const scopeRoot of scopeRoots) {
|
|
124
|
-
const manifestPath = skillsManifestPath(scopeRoot);
|
|
125
|
-
const relative = toPosixRelative(targetRoot, manifestPath);
|
|
126
|
-
if (checked.has(relative) || !existsFile(manifestPath)) continue;
|
|
127
|
-
checked.add(relative);
|
|
128
|
-
const schemaVersion = readSkillManifestSchemaVersion(manifestPath);
|
|
129
|
-
if (schemaVersion !== 'buildr.skills/v1') {
|
|
130
|
-
addDoctorFinding(result, 'warning', 'skills.schema_version_invalid', `Skills manifest schemaVersion 缺失或不支持:${relative}`, {
|
|
131
|
-
path: relative,
|
|
132
|
-
suggestion: '运行 buildr update 或 buildr sync 补齐 schemaVersion: buildr.skills/v1。',
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function finalizeDoctorResult(result) {
|
|
139
|
-
const counts = { ok: 0, info: 0, warning: 0, error: 0 };
|
|
140
|
-
for (const finding of result.findings) {
|
|
141
|
-
counts[finding.status] = (counts[finding.status] ?? 0) + 1;
|
|
142
|
-
}
|
|
143
|
-
result.summary = counts;
|
|
144
|
-
result.ok = counts.error === 0;
|
|
145
|
-
result.nextSteps = result.findings
|
|
146
|
-
.filter((finding) => finding.suggestion && finding.userActionRequired !== false)
|
|
147
|
-
.map((finding) => ({ code: finding.code, suggestion: finding.suggestion, command: finding.command, commands: finding.commands }))
|
|
148
|
-
.slice(0, 10);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function printDoctorReport(result) {
|
|
152
|
-
console.log(`Buildr doctor for ${result.targetRoot}`);
|
|
153
|
-
console.log(`Status: ok=${result.summary.ok} info=${result.summary.info} warning=${result.summary.warning} error=${result.summary.error}`);
|
|
154
|
-
console.log('');
|
|
155
|
-
|
|
156
|
-
if (result.findings.length === 0) {
|
|
157
|
-
console.log('[ok] 未发现问题。');
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
for (const finding of result.findings) {
|
|
162
|
-
const location = finding.path ? ` (${finding.path})` : '';
|
|
163
|
-
console.log(`[${finding.status}] ${finding.code}${location} - ${finding.message}`);
|
|
164
|
-
if (finding.suggestion) console.log(` 建议:${finding.suggestion}`);
|
|
165
|
-
if (finding.command) console.log(` 命令:${finding.command}`);
|
|
166
|
-
if (finding.commands) {
|
|
167
|
-
for (const command of finding.commands) console.log(` 命令:${command}`);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
Object.assign(runtime, {
|
|
173
|
-
scopeParts,
|
|
174
|
-
workspaceName,
|
|
175
|
-
readProjectsRegistryIfExists,
|
|
176
|
-
discoverDoctorScopes,
|
|
177
|
-
resolveRepoPath,
|
|
178
|
-
readGitRemote,
|
|
179
|
-
gitignoreLines,
|
|
180
|
-
isIgnoredByWorkspace,
|
|
181
|
-
projectDoctorContextFor,
|
|
182
|
-
projectBaselineStatus,
|
|
183
|
-
missingProjectBaselineAssets,
|
|
184
|
-
diagnoseProjectRegistry,
|
|
185
|
-
diagnoseWorkspace,
|
|
186
|
-
diagnoseLegacyPractices,
|
|
187
|
-
diagnoseHierarchy,
|
|
188
|
-
diagnoseServicesMetadata,
|
|
189
|
-
diagnoseServices,
|
|
190
|
-
runtimeFindingsForDoctor,
|
|
191
|
-
summarizeRuntimeFindings,
|
|
192
|
-
addUnsupportedAgentFinding,
|
|
193
|
-
diagnoseRuntime,
|
|
194
|
-
diagnoseCommands,
|
|
195
|
-
diagnoseComponents,
|
|
196
|
-
diagnoseSkillsManifestSchemas,
|
|
197
|
-
finalizeDoctorResult,
|
|
198
|
-
printDoctorReport,
|
|
199
|
-
});
|
|
200
|
-
return runtime;
|
|
201
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
export function createBuiltinReceipts(deps) {
|
|
2
|
-
const { atomicWriteJson, collectFiles, crypto, ensureDirectory, existsDirectory, existsFile, fs, isPlainObject, path, toPosixRelative } = deps;
|
|
3
|
-
const schemaVersion = 'buildr.builtin-receipts/v1';
|
|
4
|
-
const relativePath = '.buildr/builtin-receipts.json';
|
|
5
|
-
const sha256 = (value) => `sha256-${crypto.createHash('sha256').update(value).digest('hex')}`;
|
|
6
|
-
|
|
7
|
-
function assetInventory(assetPath, kind) {
|
|
8
|
-
if (kind === 'command') return [{ path: 'manifest-entry', integrity: sha256(JSON.stringify(assetPath)) }];
|
|
9
|
-
if (kind === 'rule') {
|
|
10
|
-
if (!existsFile(assetPath)) return null;
|
|
11
|
-
if (fs.lstatSync(assetPath).isSymbolicLink()) throw new Error(`Builtin asset must not be a symlink: ${assetPath}`);
|
|
12
|
-
return [{ path: path.basename(assetPath), integrity: sha256(fs.readFileSync(assetPath)) }];
|
|
13
|
-
}
|
|
14
|
-
if (!existsDirectory(assetPath)) return null;
|
|
15
|
-
const inventory = [];
|
|
16
|
-
for (const file of collectFiles(assetPath).sort()) {
|
|
17
|
-
if (fs.lstatSync(file).isSymbolicLink()) throw new Error(`Builtin asset must not contain symlinks: ${file}`);
|
|
18
|
-
const relative = toPosixRelative(assetPath, file);
|
|
19
|
-
if (!relative || relative.startsWith('../') || path.isAbsolute(relative)) throw new Error(`Builtin asset path escapes its root: ${file}`);
|
|
20
|
-
inventory.push({ path: relative, integrity: sha256(fs.readFileSync(file)) });
|
|
21
|
-
}
|
|
22
|
-
return inventory;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const inventoryIntegrity = (inventory) => inventory === null ? null : sha256(JSON.stringify(inventory));
|
|
26
|
-
function snapshot(assetPath, kind) {
|
|
27
|
-
const files = assetInventory(assetPath, kind);
|
|
28
|
-
return files === null ? null : { files, integrity: inventoryIntegrity(files) };
|
|
29
|
-
}
|
|
30
|
-
const key = (type, id) => `${type}:${id}`;
|
|
31
|
-
|
|
32
|
-
function read(targetRoot) {
|
|
33
|
-
const receiptPath = path.join(targetRoot, relativePath);
|
|
34
|
-
if (!existsFile(receiptPath)) return { schemaVersion, builtins: [] };
|
|
35
|
-
let value;
|
|
36
|
-
try { value = JSON.parse(fs.readFileSync(receiptPath, 'utf8')); } catch (error) { throw new Error(`Invalid Builtin receipt JSON: ${error.message}`); }
|
|
37
|
-
if (!isPlainObject(value) || value.schemaVersion !== schemaVersion || !Array.isArray(value.builtins)) throw new Error(`Invalid Builtin receipt schema: ${receiptPath}`);
|
|
38
|
-
const seen = new Set();
|
|
39
|
-
for (const item of value.builtins) {
|
|
40
|
-
if (!isPlainObject(item) || !['rule', 'skill', 'command'].includes(item.type) || typeof item.id !== 'string' || typeof item.target !== 'string' || !/^sha256-[a-f0-9]{64}$/.test(item.integrity || '') || !Array.isArray(item.files)) throw new Error(`Invalid Builtin receipt entry: ${JSON.stringify(item)}`);
|
|
41
|
-
const itemKey = key(item.type, item.id);
|
|
42
|
-
if (seen.has(itemKey)) throw new Error(`Duplicate Builtin receipt entry: ${itemKey}`);
|
|
43
|
-
seen.add(itemKey);
|
|
44
|
-
if (path.isAbsolute(item.target) || item.target.split('/').includes('..')) throw new Error(`Builtin receipt target escapes workspace: ${item.target}`);
|
|
45
|
-
const paths = new Set();
|
|
46
|
-
for (const file of item.files) {
|
|
47
|
-
if (!isPlainObject(file) || typeof file.path !== 'string' || !file.path || path.isAbsolute(file.path) || file.path.split('/').includes('..') || !/^sha256-[a-f0-9]{64}$/.test(file.integrity || '') || paths.has(file.path)) throw new Error(`Invalid Builtin receipt inventory for ${itemKey}`);
|
|
48
|
-
paths.add(file.path);
|
|
49
|
-
}
|
|
50
|
-
if (inventoryIntegrity(item.files) !== item.integrity) throw new Error(`Builtin receipt integrity mismatch: ${itemKey}`);
|
|
51
|
-
}
|
|
52
|
-
return value;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function write(targetRoot, receipts) {
|
|
56
|
-
receipts.builtins.sort((left, right) => key(left.type, left.id).localeCompare(key(right.type, right.id)));
|
|
57
|
-
ensureDirectory(path.dirname(path.join(targetRoot, relativePath)));
|
|
58
|
-
atomicWriteJson(path.join(targetRoot, relativePath), receipts);
|
|
59
|
-
return relativePath;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const fromSnapshot = (type, builtin, value) => ({ type, id: builtin.id, target: type === 'command' ? 'commands/manifest.yml' : builtin.target, integrity: value.integrity, files: value.files });
|
|
63
|
-
|
|
64
|
-
function resolveState({ builtin, liveSnapshot, newSnapshot, oldReceipt, isRestore, required }) {
|
|
65
|
-
if (liveSnapshot?.integrity === newSnapshot.integrity) return { status: 'installed', converge: false, adopt: true };
|
|
66
|
-
if (isRestore || required) return { status: liveSnapshot ? 'modified' : 'missing', converge: true, adopt: true };
|
|
67
|
-
if (oldReceipt && liveSnapshot?.integrity === oldReceipt.integrity) return { status: 'installed', converge: true, adopt: true };
|
|
68
|
-
if (!oldReceipt && liveSnapshot && (builtin.legacyIntegrities || []).includes(liveSnapshot.integrity)) return { status: 'installed', converge: true, adopt: true, legacy: true };
|
|
69
|
-
return { status: liveSnapshot ? 'modified' : 'missing', converge: false, adopt: false };
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return { relativePath, key, snapshot, read, write, fromSnapshot, resolveState };
|
|
73
|
-
}
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
export function createPackageOutput(deps) {
|
|
2
|
-
const {
|
|
3
|
-
assertSafeAssetTarget,
|
|
4
|
-
atomicWriteJson,
|
|
5
|
-
collectFiles,
|
|
6
|
-
crypto,
|
|
7
|
-
ensureDirectory,
|
|
8
|
-
existsDirectory,
|
|
9
|
-
existsFile,
|
|
10
|
-
fs,
|
|
11
|
-
optionValue,
|
|
12
|
-
packageRoot,
|
|
13
|
-
parseManifestFileEntry,
|
|
14
|
-
path,
|
|
15
|
-
productRoot,
|
|
16
|
-
readPackageManifest,
|
|
17
|
-
toPosixRelative,
|
|
18
|
-
} = deps;
|
|
19
|
-
|
|
20
|
-
const PACKAGE_OUTPUT_RECEIPT = '.buildr-package-output.json';
|
|
21
|
-
const PACKAGE_OUTPUT_RECEIPT_SCHEMA = 'buildr.package-output/v1';
|
|
22
|
-
|
|
23
|
-
function packageOutputInventory(outputRoot) {
|
|
24
|
-
if (!existsDirectory(outputRoot)) return [];
|
|
25
|
-
return collectFiles(outputRoot)
|
|
26
|
-
.filter((file) => path.basename(file) !== PACKAGE_OUTPUT_RECEIPT)
|
|
27
|
-
.map((file) => ({
|
|
28
|
-
path: toPosixRelative(outputRoot, file),
|
|
29
|
-
integrity: `sha256-${crypto.createHash('sha256').update(fs.readFileSync(file)).digest('hex')}`,
|
|
30
|
-
}))
|
|
31
|
-
.sort((left, right) => left.path.localeCompare(right.path));
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function packageOutputIntegrity(inventory) {
|
|
35
|
-
return `sha256-${crypto.createHash('sha256').update(JSON.stringify(inventory)).digest('hex')}`;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function readPackageOutputReceipt(outDir) {
|
|
39
|
-
const file = path.join(outDir, PACKAGE_OUTPUT_RECEIPT);
|
|
40
|
-
if (!existsFile(file)) return null;
|
|
41
|
-
let receipt;
|
|
42
|
-
try { receipt = JSON.parse(fs.readFileSync(file, 'utf8')); } catch (error) { throw new Error(`Package output receipt is invalid JSON: ${error.message}`); }
|
|
43
|
-
if (receipt?.schemaVersion !== PACKAGE_OUTPUT_RECEIPT_SCHEMA || !Array.isArray(receipt.files) || typeof receipt.integrity !== 'string') {
|
|
44
|
-
throw new Error('Package output receipt has an unsupported schema.');
|
|
45
|
-
}
|
|
46
|
-
return receipt;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function assertSafePackageOutput(outDir) {
|
|
50
|
-
const root = productRoot();
|
|
51
|
-
const candidate = path.resolve(outDir);
|
|
52
|
-
assertSafeAssetTarget(root, candidate, path.dirname(candidate), 'Package output');
|
|
53
|
-
if (fs.existsSync(candidate) && fs.lstatSync(candidate).isSymbolicLink()) throw new Error(`Package output is a symbolic link: ${candidate}`);
|
|
54
|
-
for (const collection of ['package', 'tools', 'openspec', 'docs', 'agents', 'skills', 'capabilities', 'services']) {
|
|
55
|
-
if (candidate === path.join(root, collection)) throw new Error(`Package output is a protected Product collection root: ${candidate}`);
|
|
56
|
-
}
|
|
57
|
-
return candidate;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function validateReplaceablePackageOutput(outDir) {
|
|
61
|
-
if (!fs.existsSync(outDir)) return;
|
|
62
|
-
if (!existsDirectory(outDir)) throw new Error(`Package output target is not a directory: ${outDir}`);
|
|
63
|
-
if (fs.readdirSync(outDir).length === 0) return;
|
|
64
|
-
const receipt = readPackageOutputReceipt(outDir);
|
|
65
|
-
if (!receipt) throw new Error(`Refusing to replace non-empty package output without ${PACKAGE_OUTPUT_RECEIPT}: ${outDir}`);
|
|
66
|
-
const liveFiles = packageOutputInventory(outDir);
|
|
67
|
-
const liveIntegrity = packageOutputIntegrity(liveFiles);
|
|
68
|
-
if (liveIntegrity !== receipt.integrity || JSON.stringify(liveFiles) !== JSON.stringify(receipt.files)) {
|
|
69
|
-
throw new Error(`Refusing to replace modified package output: ${outDir}`);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function buildPackageOutput(outDir, root, manifest) {
|
|
74
|
-
ensureDirectory(outDir);
|
|
75
|
-
|
|
76
|
-
const manifestSource = path.join(packageRoot(), 'manifest.yml');
|
|
77
|
-
const manifestTarget = path.join(outDir, 'package/manifest.yml');
|
|
78
|
-
ensureDirectory(path.dirname(manifestTarget));
|
|
79
|
-
fs.copyFileSync(manifestSource, manifestTarget);
|
|
80
|
-
|
|
81
|
-
for (const includePath of manifest.include) {
|
|
82
|
-
const source = path.resolve(root, includePath);
|
|
83
|
-
if (!fs.existsSync(source)) {
|
|
84
|
-
throw new Error(`Manifest include does not exist: ${includePath}`);
|
|
85
|
-
}
|
|
86
|
-
const target = path.join(outDir, includePath);
|
|
87
|
-
ensureDirectory(path.dirname(target));
|
|
88
|
-
fs.cpSync(source, target, { recursive: true });
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
for (const section of ['workspaceFiles', 'projectFiles']) {
|
|
92
|
-
for (const rawEntry of manifest[section]) {
|
|
93
|
-
const entry = parseManifestFileEntry(rawEntry, section);
|
|
94
|
-
const source = path.resolve(root, entry.source);
|
|
95
|
-
if (!fs.existsSync(source)) {
|
|
96
|
-
throw new Error(`Manifest source does not exist: ${entry.source}`);
|
|
97
|
-
}
|
|
98
|
-
const target = path.join(outDir, entry.source);
|
|
99
|
-
ensureDirectory(path.dirname(target));
|
|
100
|
-
fs.copyFileSync(source, target);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const files = packageOutputInventory(outDir);
|
|
105
|
-
atomicWriteJson(path.join(outDir, PACKAGE_OUTPUT_RECEIPT), {
|
|
106
|
-
schemaVersion: PACKAGE_OUTPUT_RECEIPT_SCHEMA,
|
|
107
|
-
generatedAt: new Date().toISOString(),
|
|
108
|
-
productVersion: (() => { try { return JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8')).version; } catch { return null; } })(),
|
|
109
|
-
files,
|
|
110
|
-
integrity: packageOutputIntegrity(files),
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function packageBuild(args) {
|
|
115
|
-
const root = productRoot();
|
|
116
|
-
const manifest = readPackageManifest();
|
|
117
|
-
const outDir = assertSafePackageOutput(path.resolve(optionValue(args, '--out', path.join(root, 'dist', 'buildr-package'))));
|
|
118
|
-
validateReplaceablePackageOutput(outDir);
|
|
119
|
-
const staging = path.join(path.dirname(outDir), `.${path.basename(outDir)}.buildr-stage-${crypto.randomUUID()}`);
|
|
120
|
-
const backup = path.join(path.dirname(outDir), `.${path.basename(outDir)}.buildr-backup-${crypto.randomUUID()}`);
|
|
121
|
-
try {
|
|
122
|
-
buildPackageOutput(staging, root, manifest);
|
|
123
|
-
if (fs.existsSync(outDir)) fs.renameSync(outDir, backup);
|
|
124
|
-
fs.renameSync(staging, outDir);
|
|
125
|
-
if (fs.existsSync(backup)) fs.rmSync(backup, { recursive: true, force: true });
|
|
126
|
-
} catch (error) {
|
|
127
|
-
if (fs.existsSync(backup)) {
|
|
128
|
-
if (fs.existsSync(outDir)) fs.rmSync(outDir, { recursive: true, force: true });
|
|
129
|
-
fs.renameSync(backup, outDir);
|
|
130
|
-
}
|
|
131
|
-
throw error;
|
|
132
|
-
} finally {
|
|
133
|
-
if (fs.existsSync(staging)) fs.rmSync(staging, { recursive: true, force: true });
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
console.log(`Built Buildr package assets at ${outDir}`);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return {
|
|
140
|
-
packageOutputInventory,
|
|
141
|
-
packageOutputIntegrity,
|
|
142
|
-
readPackageOutputReceipt,
|
|
143
|
-
assertSafePackageOutput,
|
|
144
|
-
validateReplaceablePackageOutput,
|
|
145
|
-
buildPackageOutput,
|
|
146
|
-
packageBuild,
|
|
147
|
-
};
|
|
148
|
-
}
|