@jspg-ai/coding-bb 0.0.3-beta.8 → 0.0.4
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/cbb/dev-standards/rules/cbb-ai-behavior.md +0 -15
- package/cbb/dev-standards/rules/cbb-workspace-discipline.md +38 -0
- package/cbb/lib/external/index.js +228 -0
- package/cbb/lib/install/agents-nav.js +92 -0
- package/cbb/lib/install/claude-code.js +8 -1
- package/cbb/lib/install/command-skill.js +105 -0
- package/cbb/lib/install/init.js +399 -129
- package/cbb/lib/install/minimax.js +60 -0
- package/cbb/lib/install/rule-rewrite.js +1 -1
- package/cbb/lib/install/setup-decision.js +92 -0
- package/cbb/lib/install/tool-selection.js +23 -0
- package/cbb/lib/install/trae.js +18 -8
- package/cbb/lib/install/workbuddy.js +36 -0
- package/cbb/lib/install/workspaces.js +15 -61
- package/cbb/lib/utils/check-update.js +13 -5
- package/cbb/lib/utils/githook.js +230 -0
- package/cbb/lib/utils/gitignore.js +17 -4
- package/cbb/lib/utils/plugin-hook.js +92 -0
- package/cbb/worktrees/_shared/scripts/check-local-state.js +114 -0
- package/cbb/worktrees/_shared/scripts/check-unarchived.js +77 -0
- package/cbb/worktrees/_shared/scripts/delete-branches.js +147 -0
- package/cbb/worktrees/_shared/scripts/deprecate-branches.js +119 -0
- package/cbb/worktrees/_shared/scripts/find-target-worktree.js +148 -96
- package/cbb/worktrees/_shared/scripts/find-workspace-root.js +8 -8
- package/cbb/worktrees/_shared/scripts/install-git-hook.js +70 -0
- package/cbb/worktrees/_shared/scripts/junction-ai-config.js +192 -0
- package/cbb/worktrees/_shared/scripts/merge-branches.js +469 -0
- package/cbb/worktrees/_shared/scripts/push-core.js +1 -1
- package/cbb/worktrees/_shared/scripts/silence-popup.js +1 -1
- package/cbb/worktrees/_shared/scripts/start-local.js +180 -0
- package/cbb/worktrees/skills/cbb-local-mode/SKILL.md +194 -0
- package/cbb/worktrees/skills/cbb-local-mode/scripts/check-local-state.js +114 -0
- package/cbb/worktrees/skills/cbb-local-mode/scripts/delete-branches.js +147 -0
- package/cbb/worktrees/skills/cbb-local-mode/scripts/deprecate-branches.js +119 -0
- package/cbb/worktrees/skills/cbb-local-mode/scripts/install-git-hook.js +70 -0
- package/cbb/worktrees/skills/cbb-local-mode/scripts/merge-branches.js +469 -0
- package/cbb/worktrees/skills/cbb-local-mode/scripts/silence-popup.js +23 -0
- package/cbb/worktrees/skills/cbb-local-mode/scripts/start-local.js +180 -0
- package/cbb/worktrees/skills/cbb-worktree-close/SKILL.md +133 -81
- package/cbb/worktrees/skills/cbb-worktree-close/scripts/check-env.js +3 -3
- package/cbb/worktrees/skills/cbb-worktree-close/scripts/check-unarchived.js +77 -48
- package/cbb/worktrees/skills/cbb-worktree-close/scripts/delete-branches.js +147 -136
- package/cbb/worktrees/skills/cbb-worktree-close/scripts/deprecate-branches.js +119 -0
- package/cbb/worktrees/skills/cbb-worktree-close/scripts/discover-apps.js +14 -5
- package/cbb/worktrees/skills/cbb-worktree-close/scripts/find-target-worktree.js +148 -96
- package/cbb/worktrees/skills/cbb-worktree-close/scripts/find-workspace-root.js +8 -8
- package/cbb/worktrees/skills/cbb-worktree-close/scripts/junction-ai-config.js +192 -0
- package/cbb/worktrees/skills/cbb-worktree-close/scripts/merge-branches.js +469 -0
- package/cbb/worktrees/skills/cbb-worktree-close/scripts/remove-worktrees.js +44 -9
- package/cbb/worktrees/skills/cbb-worktree-close/scripts/safety-check.js +15 -4
- package/cbb/worktrees/skills/cbb-worktree-close/scripts/silence-popup.js +1 -1
- package/cbb/worktrees/skills/cbb-worktree-init/SKILL.md +136 -123
- package/cbb/worktrees/skills/cbb-worktree-init/scripts/check-env.js +1 -1
- package/cbb/worktrees/skills/cbb-worktree-init/scripts/check-repos.js +2 -2
- package/cbb/worktrees/skills/cbb-worktree-init/scripts/create-branches.js +33 -8
- package/cbb/worktrees/skills/cbb-worktree-init/scripts/create-worktrees.js +60 -46
- package/cbb/worktrees/skills/cbb-worktree-init/scripts/install-git-hook.js +70 -0
- package/cbb/worktrees/skills/cbb-worktree-init/scripts/junction-ai-config.js +192 -0
- package/cbb/worktrees/skills/cbb-worktree-init/scripts/parse-config.js +7 -7
- package/cbb/worktrees/skills/cbb-worktree-init/scripts/push-branches.js +3 -3
- package/cbb/worktrees/skills/cbb-worktree-init/scripts/push-core.js +1 -1
- package/cbb/worktrees/skills/cbb-worktree-init/scripts/silence-popup.js +1 -1
- package/cbb/worktrees/skills/cbb-worktree-init/scripts/sync-repos.js +11 -7
- package/cbb/worktrees/skills/cbb-worktree-init/scripts/update-gitignore.js +37 -9
- package/cbb/worktrees/skills/cbb-worktree-push/SKILL.md +212 -56
- package/cbb/worktrees/skills/cbb-worktree-push/scripts/check-unarchived.js +77 -0
- package/cbb/worktrees/skills/cbb-worktree-push/scripts/commit-worktrees.js +70 -12
- package/cbb/worktrees/skills/cbb-worktree-push/scripts/find-target-worktree.js +148 -96
- package/cbb/worktrees/skills/cbb-worktree-push/scripts/find-workspace-root.js +8 -8
- package/cbb/worktrees/skills/cbb-worktree-push/scripts/make-mr-urls.js +211 -0
- package/cbb/worktrees/skills/cbb-worktree-push/scripts/merge-branches.js +469 -0
- package/cbb/worktrees/skills/cbb-worktree-push/scripts/push-core.js +1 -1
- package/cbb/worktrees/skills/cbb-worktree-push/scripts/push-worktrees.js +67 -20
- package/cbb/worktrees/skills/cbb-worktree-push/scripts/silence-popup.js +1 -1
- package/config/{workspace-config.sample.json → CBB-WORKSPACE.sample.json} +1 -1
- package/config/openspec/schemas/spec-driven/schema.yaml +20 -0
- package/config/upstream-mirrors.json +5 -0
- package/external/frontend-design/.version +6 -0
- package/external/frontend-design/LICENSE.txt +177 -0
- package/external/frontend-design/SKILL.md +71 -0
- package/openspec/.version +2 -2
- package/openspec/commands/archive.md +15 -8
- package/openspec/commands/bulk-archive.md +13 -6
- package/openspec/commands/continue.md +0 -1
- package/openspec/commands/explore.md +1 -1
- package/openspec/commands/ff.md +1 -1
- package/openspec/commands/onboard.md +9 -4
- package/openspec/commands/update.md +11 -5
- package/openspec/commands/verify.md +57 -26
- package/openspec/skills/openspec-apply-change/SKILL.md +1 -1
- package/openspec/skills/openspec-archive-change/SKILL.md +16 -9
- package/openspec/skills/openspec-bulk-archive-change/SKILL.md +14 -7
- package/openspec/skills/openspec-continue-change/SKILL.md +1 -2
- package/openspec/skills/openspec-explore/SKILL.md +2 -2
- package/openspec/skills/openspec-ff-change/SKILL.md +2 -2
- package/openspec/skills/openspec-new-change/SKILL.md +1 -1
- package/openspec/skills/openspec-onboard/SKILL.md +10 -5
- package/openspec/skills/openspec-propose/SKILL.md +1 -1
- package/openspec/skills/openspec-sync-specs/SKILL.md +1 -1
- package/openspec/skills/openspec-update-change/SKILL.md +12 -6
- package/openspec/skills/openspec-verify-change/SKILL.md +59 -27
- package/package.json +3 -2
- package/superpowers/.version +3 -3
- package/superpowers/skills/writing-plans/SKILL.md +32 -20
- package/cbb/lib/install/codebuddy.js +0 -30
- package/cbb/worktrees/skills/cbb-worktree-init/scripts/find-workspace-root.js +0 -67
- package/config/workspace-agents.sample.md +0 -41
- package/superpowers/skills/writing-plans/plan-document-reviewer-prompt.md +0 -49
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* worktree 模式 AI 配置 junction(ADR 0002,防线 B)。
|
|
4
|
+
*
|
|
5
|
+
* 用法:node junction-ai-config.js <ws_root> <wt_path> [--remove]
|
|
6
|
+
*
|
|
7
|
+
* 目的:让开发会话能开进 worktree(工作树内加载 AI 配置),同时保持
|
|
8
|
+
* 「单层安装」实质——配置唯一物理副本在空间根,cbb update 一处生效。
|
|
9
|
+
*
|
|
10
|
+
* 策略(规避 ADR 0001 否决时的状态污染):
|
|
11
|
+
* - 只 junction **只读内容子目录**(rules / skills / commands):
|
|
12
|
+
* 工具向配置根写状态(如 settings.local.json)落在 worktree 自建的
|
|
13
|
+
* 物理(空壳)配置目录里,按项目隔离,不互相覆盖;
|
|
14
|
+
* - 配置根目录本身在 worktree 侧是物理目录(不是链接);
|
|
15
|
+
* - .opencode/opencode.json 为文件(junction 不支持文件):直接复制
|
|
16
|
+
* (cbb update 后需重跑本脚本同步;worktree 为瞬态,影响可控)。
|
|
17
|
+
*
|
|
18
|
+
* 幂等:linkPath 已指向同一 target → skip;指向不同 → 重建;
|
|
19
|
+
* 存在同名**物理目录**(非链接)→ warn 跳过(不覆盖用户内容)。
|
|
20
|
+
*
|
|
21
|
+
* --remove(cbb-worktree-close 调用):
|
|
22
|
+
* - 拆除 worktree 内已建 junction 与复制件,**源文件零接触**:
|
|
23
|
+
* 只解除链接本身(fs.rmSync 对 reparse point 仅删链接、不穿透目标,
|
|
24
|
+
* 已由 Windows 实测验证),复制件为普通文件直接删除;
|
|
25
|
+
* - 拆除前校验链接目标位于空间根内——目标在空间根外 / readlink 失败
|
|
26
|
+
* → 跳过并警告(防误删外部目录);同名物理目录/文件 → 跳过不碰。
|
|
27
|
+
*
|
|
28
|
+
* 退出码:0 成功(含全部 skip);1 参数错误;2 执行失败。
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
const fs = require('fs');
|
|
32
|
+
const path = require('path');
|
|
33
|
+
|
|
34
|
+
const wsRoot = process.argv[2];
|
|
35
|
+
const wtPath = process.argv[3];
|
|
36
|
+
const removeMode = process.argv[4] === '--remove';
|
|
37
|
+
|
|
38
|
+
if (!wsRoot || !wtPath) {
|
|
39
|
+
console.error('Usage: node junction-ai-config.js <ws_root> <wt_path> [--remove]');
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// 各工具的项目级配置根(存在才处理)与本包部署的内容子目录
|
|
44
|
+
const CONFIG_ROOTS = ['.claude', '.qoder', '.opencode', '.workbuddy', '.trae', '.minimax'];
|
|
45
|
+
const CONTENT_SUBDIRS = ['rules', 'skills', 'commands'];
|
|
46
|
+
// 文件级内容(复制而非 junction):opencode 的 instructions 登记
|
|
47
|
+
const CONTENT_FILES = { '.opencode': ['opencode.json'] };
|
|
48
|
+
|
|
49
|
+
const linked = [];
|
|
50
|
+
const copied = [];
|
|
51
|
+
const skipped = [];
|
|
52
|
+
const warned = [];
|
|
53
|
+
let hasFailure = false;
|
|
54
|
+
|
|
55
|
+
/** 归一化 junction 目标路径(Windows readlink 返回 \\?\ 前缀) */
|
|
56
|
+
function normLinkTarget(p) {
|
|
57
|
+
return path.resolve(String(p).replace(/^\\\\\?\\/, ''));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** 目标是否位于空间根内(防误删空间根外目录的守卫) */
|
|
61
|
+
function isWithin(p, root) {
|
|
62
|
+
const r = path.resolve(root) + path.sep;
|
|
63
|
+
return path.resolve(p).startsWith(r);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// ── remove 模式:显式拆除 junction 与复制件(源文件零接触)──
|
|
67
|
+
if (removeMode) {
|
|
68
|
+
const removed = [];
|
|
69
|
+
const guarded = [];
|
|
70
|
+
|
|
71
|
+
for (const root of CONFIG_ROOTS) {
|
|
72
|
+
for (const sub of CONTENT_SUBDIRS) {
|
|
73
|
+
const linkPath = path.join(wtPath, root, sub);
|
|
74
|
+
const label = root + '/' + sub;
|
|
75
|
+
let st;
|
|
76
|
+
try { st = fs.lstatSync(linkPath); } catch (e) { continue; } // 不存在 → 跳过(dangling 链接 lstat 仍成功,可拆)
|
|
77
|
+
if (!st.isSymbolicLink()) continue; // 物理目录/文件(工具状态空壳或用户内容)→ 不碰
|
|
78
|
+
|
|
79
|
+
const target = normLinkTarget(fs.readlinkSync(linkPath));
|
|
80
|
+
if (!isWithin(target, wsRoot)) {
|
|
81
|
+
guarded.push(label + ' → ' + target + '(目标不在空间根内,跳过)');
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
// 只解除链接:Node 对 reparse point 仅删除链接本身,不递归、不触达目标内容
|
|
87
|
+
fs.rmSync(linkPath, { recursive: true, force: true });
|
|
88
|
+
removed.push(label);
|
|
89
|
+
} catch (e) {
|
|
90
|
+
console.error('❌ 拆除失败 ' + label + ' — ' + e.message);
|
|
91
|
+
hasFailure = true;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
for (const file of (CONTENT_FILES[root] || [])) {
|
|
96
|
+
const linkPath = path.join(wtPath, root, file);
|
|
97
|
+
if (!fs.existsSync(linkPath)) continue;
|
|
98
|
+
try {
|
|
99
|
+
fs.unlinkSync(linkPath); // 复制件为普通文件,删除不影响源
|
|
100
|
+
removed.push(root + '/' + file);
|
|
101
|
+
} catch (e) {
|
|
102
|
+
console.error('❌ 删除失败 ' + root + '/' + file + ' — ' + e.message);
|
|
103
|
+
hasFailure = true;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (removed.length) console.log('✅ 已拆除 junction/复制件:' + removed.join(', '));
|
|
109
|
+
if (guarded.length) console.log('⚠️ ' + guarded.join(';'));
|
|
110
|
+
if (removed.length === 0 && guarded.length === 0) console.log('ℹ️ 无待拆除项(幂等)');
|
|
111
|
+
|
|
112
|
+
console.log('---');
|
|
113
|
+
console.log('JUNCTION_REMOVE_RESULT', JSON.stringify({ removed, guarded, wt: wtPath }));
|
|
114
|
+
process.exit(hasFailure ? 2 : 0);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function linkDir(target, linkPath, label) {
|
|
118
|
+
if (fs.existsSync(linkPath)) {
|
|
119
|
+
const st = fs.lstatSync(linkPath);
|
|
120
|
+
if (st.isSymbolicLink()) {
|
|
121
|
+
const existing = normLinkTarget(fs.readlinkSync(linkPath));
|
|
122
|
+
if (existing === path.resolve(target)) {
|
|
123
|
+
skipped.push(label);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
fs.unlinkSync(linkPath); // 指向不同 → 重建
|
|
127
|
+
} else if (st.isDirectory()) {
|
|
128
|
+
warned.push(label + '(存在同名物理目录,未覆盖)');
|
|
129
|
+
return;
|
|
130
|
+
} else {
|
|
131
|
+
fs.unlinkSync(linkPath); // 同名文件,罕见,重建
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
fs.mkdirSync(path.dirname(linkPath), { recursive: true });
|
|
135
|
+
try {
|
|
136
|
+
if (process.platform === 'win32') {
|
|
137
|
+
fs.symlinkSync(path.resolve(target), linkPath, 'junction');
|
|
138
|
+
} else {
|
|
139
|
+
fs.symlinkSync(path.resolve(target), linkPath, 'dir');
|
|
140
|
+
}
|
|
141
|
+
linked.push(label);
|
|
142
|
+
} catch (e) {
|
|
143
|
+
console.error('❌ junction 失败 ' + label + ' — ' + e.message);
|
|
144
|
+
hasFailure = true;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function copyFile(target, dest, label) {
|
|
149
|
+
if (fs.existsSync(dest) && fs.existsSync(target) &&
|
|
150
|
+
fs.readFileSync(dest, 'utf-8') === fs.readFileSync(target, 'utf-8')) {
|
|
151
|
+
skipped.push(label);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
156
|
+
fs.copyFileSync(target, dest);
|
|
157
|
+
copied.push(label);
|
|
158
|
+
} catch (e) {
|
|
159
|
+
console.error('❌ 复制失败 ' + label + ' — ' + e.message);
|
|
160
|
+
hasFailure = true;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
for (const root of CONFIG_ROOTS) {
|
|
165
|
+
const srcRoot = path.join(wsRoot, root);
|
|
166
|
+
if (!fs.existsSync(srcRoot) || !fs.statSync(srcRoot).isDirectory()) continue;
|
|
167
|
+
|
|
168
|
+
for (const sub of CONTENT_SUBDIRS) {
|
|
169
|
+
const src = path.join(srcRoot, sub);
|
|
170
|
+
if (!fs.existsSync(src) || !fs.statSync(src).isDirectory()) continue;
|
|
171
|
+
linkDir(src, path.join(wtPath, root, sub), root + '/' + sub);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
for (const file of (CONTENT_FILES[root] || [])) {
|
|
175
|
+
const src = path.join(srcRoot, file);
|
|
176
|
+
if (!fs.existsSync(src) || !fs.statSync(src).isFile()) continue;
|
|
177
|
+
copyFile(src, path.join(wtPath, root, file), root + '/' + file);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (linked.length === 0 && copied.length === 0 && skipped.length === 0 && warned.length === 0) {
|
|
182
|
+
console.log('ℹ️ 空间根无 AI 配置目录,跳过(cbb setup 选择工具后再装)');
|
|
183
|
+
} else {
|
|
184
|
+
if (linked.length) console.log('✅ junction:' + linked.join(', '));
|
|
185
|
+
if (copied.length) console.log('✅ 复制:' + copied.join(', '));
|
|
186
|
+
if (skipped.length) console.log('⏭️ 已就绪:' + skipped.join(', '));
|
|
187
|
+
if (warned.length) console.log('⚠️ ' + warned.join(';'));
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
console.log('---');
|
|
191
|
+
console.log('JUNCTION_RESULT', JSON.stringify({ linked, copied, skipped, warned, wt: wtPath }));
|
|
192
|
+
process.exit(hasFailure ? 2 : 0);
|
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
require('./silence-popup');
|
|
3
|
+
/**
|
|
4
|
+
* 收尾 / 交付合并门禁 —— 直合并通道 + 合并判定(ADR 0007 / 0008)
|
|
5
|
+
*
|
|
6
|
+
* 把需求分支合并进目标分支并推送远端:
|
|
7
|
+
* - 供 cbb-worktree-close / cbb-local-mode 的收尾门禁调用(默认目标 = 主干)
|
|
8
|
+
* - 供 cbb-worktree-push Step 7 的"直接合并"出口调用(--target 可指定测试分支)
|
|
9
|
+
* 默认交付走 MR(人工在浏览器合入);本脚本是用户在门禁处**显式确认**后的
|
|
10
|
+
* "由 agent 直接完成合并"通道。
|
|
11
|
+
*
|
|
12
|
+
* 用法:
|
|
13
|
+
* node merge-branches.js <ws_root> <branch> [--apps a,b] [--target <分支>] [--allow-checkout] [--dry-run]
|
|
14
|
+
* node merge-branches.js <ws_root> <branch> [--apps a,b] [--target <分支>] --check # 仅判定,不合并
|
|
15
|
+
*
|
|
16
|
+
* 目标分支:
|
|
17
|
+
* 缺省 / --target 等于该仓库探测主干 → 主干快路径(本地主干检出上 merge --no-ff → push)
|
|
18
|
+
* --target 指定非主干分支 → 临时 worktree(基于 origin/<target>,不动用户检出)
|
|
19
|
+
*
|
|
20
|
+
* 模式:
|
|
21
|
+
* --check 逐仓库判定是否已合并到目标(主干含 release-* 中转 / squash / cherry-pick 兜底,
|
|
22
|
+
* 算法与 cbb-worktree-close 的 safety-check.js 同源);不修改任何状态
|
|
23
|
+
* 默认 两阶段(ADR 0007):
|
|
24
|
+
* 1. 预检:逐仓库校验(目标可解析 / 检出干净 / 分支存在)
|
|
25
|
+
* 任一不过 → 退出 2,不执行任何合并
|
|
26
|
+
* 2. 执行:merge --no-ff → push;执行中失败 → 停止并报告已完成清单(不回滚;重跑幂等)
|
|
27
|
+
* --dry-run 只做预检,不执行
|
|
28
|
+
*
|
|
29
|
+
* 退出码:0 全部成功(含 skipped / merged)/ 1 参数错误 / 2 预检或执行失败(含 need-mr / unmerged)
|
|
30
|
+
* 末行:MERGE_RESULT [...] 或 MERGE_CHECK_RESULT [...]
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
const { execSync } = require('child_process');
|
|
34
|
+
const fs = require('fs');
|
|
35
|
+
const os = require('os');
|
|
36
|
+
const path = require('path');
|
|
37
|
+
|
|
38
|
+
function run(cmd, cwd) {
|
|
39
|
+
try {
|
|
40
|
+
return {
|
|
41
|
+
ok: true,
|
|
42
|
+
out: execSync(cmd, {
|
|
43
|
+
cwd,
|
|
44
|
+
encoding: 'utf-8',
|
|
45
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
46
|
+
timeout: 120000,
|
|
47
|
+
env: { ...process.env, GIT_TERMINAL_PROMPT: '0' },
|
|
48
|
+
}).trim(),
|
|
49
|
+
};
|
|
50
|
+
} catch (e) {
|
|
51
|
+
return { ok: false, err: (e.stderr || e.message || String(e)).trim() };
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function detectMain(repoPath) {
|
|
56
|
+
const remote = run('git remote', repoPath);
|
|
57
|
+
if (!remote.ok || !remote.out) return '';
|
|
58
|
+
const r = remote.out.split(/\r?\n/)[0];
|
|
59
|
+
const symbolic = run('git symbolic-ref "refs/remotes/' + r + '/HEAD"', repoPath);
|
|
60
|
+
if (symbolic.ok && symbolic.out) return symbolic.out.replace('refs/remotes/' + r + '/', '');
|
|
61
|
+
return '';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ── 合并判定(与 cbb-worktree-close/scripts/safety-check.js 同源) ──
|
|
65
|
+
// 0=merged, 1=unmerged, 2=to-ref-missing
|
|
66
|
+
function mergedTo(repoPath, from, to) {
|
|
67
|
+
if (!run('git rev-parse --verify --quiet "' + from + '"', repoPath).ok) return 1;
|
|
68
|
+
if (!run('git rev-parse --verify --quiet "' + to + '"', repoPath).ok) return 2;
|
|
69
|
+
if (run('git merge-base --is-ancestor "' + from + '" "' + to + '" && echo Y', repoPath).out === 'Y') return 0;
|
|
70
|
+
// 跨平台:不用 grep(Windows 无 grep),解析 git cherry 输出(+ 前缀 = 未合并提交)
|
|
71
|
+
const cherry = run('git cherry "' + to + '" "' + from + '"', repoPath);
|
|
72
|
+
if (!cherry.ok) return 1;
|
|
73
|
+
if (cherry.out.split(/\r?\n/).filter(Boolean).some(l => l.indexOf('+') === 0)) return 1;
|
|
74
|
+
return 0;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function mergedToMain(repoPath, branchName, main) {
|
|
78
|
+
if (mergedTo(repoPath, branchName, main) === 0) return 'main';
|
|
79
|
+
if (mergedTo(repoPath, branchName, 'origin/' + main) === 0) return 'origin/' + main;
|
|
80
|
+
const releaseList = run('git for-each-ref --format="%(refname:short)" "refs/heads/release-*" "refs/remotes/origin/release-*"', repoPath);
|
|
81
|
+
if (releaseList.ok && releaseList.out) {
|
|
82
|
+
const releases = releaseList.out.split(/\r?\n/).filter(Boolean).sort();
|
|
83
|
+
for (const rel of releases) {
|
|
84
|
+
if (mergedTo(repoPath, branchName, rel) === 0) {
|
|
85
|
+
if (mergedTo(repoPath, rel, main) === 0) return 'main-via-' + rel;
|
|
86
|
+
if (mergedTo(repoPath, rel, 'origin/' + main) === 0) return 'origin/' + main + '-via-' + rel;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** 目标为具体分支时的已合并判定(含 origin 镜像,不做 release 中转) */
|
|
94
|
+
function mergedToTarget(repoPath, branchName, target) {
|
|
95
|
+
if (mergedTo(repoPath, branchName, target) === 0) return target;
|
|
96
|
+
if (mergedTo(repoPath, branchName, 'origin/' + target) === 0) return 'origin/' + target;
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function classifyPushError(stderr) {
|
|
101
|
+
const s = (stderr || '').toLowerCase();
|
|
102
|
+
if (s.includes('protected branch') || s.includes('deny updating')) return 'branch-protected';
|
|
103
|
+
if (s.includes('non-fast-forward') || s.includes('fetch first') || s.includes('rejected')) return 'non-fast-forward';
|
|
104
|
+
if (s.includes('permission denied (publickey)')) return 'ssh-auth-failed';
|
|
105
|
+
if (s.includes('authentication failed')) return 'https-auth-failed';
|
|
106
|
+
if (s.includes('could not resolve host') || s.includes('connection refused') || s.includes('hung up')) return 'network-unreachable';
|
|
107
|
+
return 'unknown';
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function loadApps(wsRoot) {
|
|
111
|
+
try {
|
|
112
|
+
const config = JSON.parse(fs.readFileSync(path.join(wsRoot, 'CBB-WORKSPACE.json'), 'utf-8'));
|
|
113
|
+
return Array.isArray(config.apps) ? config.apps : [];
|
|
114
|
+
} catch (e) {
|
|
115
|
+
return [];
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** 参与仓库:workspace(根 = 主干检出)+ 各 app(.codespace/<app> = 主干检出) */
|
|
120
|
+
function buildRepos(wsRoot, appFilter) {
|
|
121
|
+
const repos = [{ name: 'workspace', repo: wsRoot, work: wsRoot }];
|
|
122
|
+
for (const app of loadApps(wsRoot)) {
|
|
123
|
+
if (appFilter && !appFilter.has(app.name)) continue;
|
|
124
|
+
const dir = path.join(wsRoot, '.codespace', app.name);
|
|
125
|
+
repos.push({ name: app.name, repo: dir, work: dir });
|
|
126
|
+
}
|
|
127
|
+
return repos;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function hasRef(repoPath, ref) {
|
|
131
|
+
return run('git rev-parse --verify --quiet "' + ref + '"', repoPath).ok;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** 清理临时 worktree(失败仅警告,不阻断) */
|
|
135
|
+
function cleanupTempWorktree(repoPath, tmpDir) {
|
|
136
|
+
if (!tmpDir) return;
|
|
137
|
+
const removed = run('git worktree remove --force "' + tmpDir + '"', repoPath);
|
|
138
|
+
if (!removed.ok && fs.existsSync(tmpDir)) {
|
|
139
|
+
try { fs.rmSync(tmpDir, { recursive: true, force: true }); } catch (e) { /* Windows 锁:留给用户 */ }
|
|
140
|
+
}
|
|
141
|
+
run('git worktree prune', repoPath);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function main() {
|
|
145
|
+
const args = process.argv.slice(2);
|
|
146
|
+
const wsRoot = args[0];
|
|
147
|
+
const branch = args[1];
|
|
148
|
+
|
|
149
|
+
if (!wsRoot || !branch || branch.indexOf('--') === 0) {
|
|
150
|
+
console.error('Usage: node merge-branches.js <ws_root> <branch> [--apps a,b] [--target b] [--allow-checkout] [--dry-run] [--check]');
|
|
151
|
+
process.exit(1);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const appsIdx = args.indexOf('--apps');
|
|
155
|
+
const appFilter = appsIdx >= 0
|
|
156
|
+
? new Set((args[appsIdx + 1] || '').split(',').map(s => s.trim()).filter(Boolean))
|
|
157
|
+
: null;
|
|
158
|
+
const targetIdx = args.indexOf('--target');
|
|
159
|
+
const targetArg = targetIdx >= 0 ? (args[targetIdx + 1] || '').trim() : '';
|
|
160
|
+
if (targetIdx >= 0 && !targetArg) {
|
|
161
|
+
console.error('--target 需要提供分支名');
|
|
162
|
+
process.exit(1);
|
|
163
|
+
}
|
|
164
|
+
const allowCheckout = args.includes('--allow-checkout');
|
|
165
|
+
const dryRun = args.includes('--dry-run');
|
|
166
|
+
const checkOnly = args.includes('--check');
|
|
167
|
+
|
|
168
|
+
const repos = buildRepos(wsRoot, appFilter);
|
|
169
|
+
|
|
170
|
+
// ── --check:仅判定每仓库是否已合并到目标 ─────────────────
|
|
171
|
+
if (checkOnly) {
|
|
172
|
+
const results = [];
|
|
173
|
+
for (const rp of repos) {
|
|
174
|
+
const rec = { name: rp.name, status: 'unmerged', merged: null, main: null, target: null };
|
|
175
|
+
if (!fs.existsSync(path.join(rp.repo, '.git'))) {
|
|
176
|
+
rec.status = 'no-repo';
|
|
177
|
+
results.push(rec);
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
run('git fetch --quiet origin', rp.repo);
|
|
181
|
+
const main = detectMain(rp.repo);
|
|
182
|
+
if (!main) {
|
|
183
|
+
rec.status = 'failed';
|
|
184
|
+
results.push(rec);
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
rec.main = main;
|
|
188
|
+
const target = targetArg || main;
|
|
189
|
+
rec.target = target;
|
|
190
|
+
if (!hasRef(rp.repo, 'refs/heads/' + branch)) {
|
|
191
|
+
rec.status = 'no-branch';
|
|
192
|
+
results.push(rec);
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
const merged = (!targetArg || target === main)
|
|
196
|
+
? mergedToMain(rp.repo, branch, main)
|
|
197
|
+
: mergedToTarget(rp.repo, branch, target);
|
|
198
|
+
rec.merged = merged;
|
|
199
|
+
rec.status = merged ? 'merged' : 'unmerged';
|
|
200
|
+
results.push(rec);
|
|
201
|
+
}
|
|
202
|
+
results.forEach(r => console.log(r.status.toUpperCase() + ' ' + r.name + (r.merged ? ' → ' + r.merged : '') + (r.target ? ' [target: ' + r.target + ']' : '')));
|
|
203
|
+
const ok = results.every(r => r.status !== 'unmerged' && r.status !== 'failed');
|
|
204
|
+
console.log('---');
|
|
205
|
+
console.log('MERGE_CHECK_RESULT', JSON.stringify({ branch, target: targetArg || null, results }));
|
|
206
|
+
process.exit(ok ? 0 : 2);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// ── 阶段 1:预检 ──────────────────────────────────────────
|
|
210
|
+
const prechecks = [];
|
|
211
|
+
for (const rp of repos) {
|
|
212
|
+
const rec = { name: rp.name, status: 'ok', main: null, target: null, temp: false, reason: null };
|
|
213
|
+
if (!fs.existsSync(path.join(rp.repo, '.git'))) {
|
|
214
|
+
rec.status = 'skipped';
|
|
215
|
+
rec.reason = 'no-repo';
|
|
216
|
+
prechecks.push(rec);
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
const fetch = run('git fetch --quiet origin', rp.repo);
|
|
220
|
+
if (!fetch.ok) {
|
|
221
|
+
rec.status = 'failed';
|
|
222
|
+
rec.reason = 'fetch-failed';
|
|
223
|
+
prechecks.push(rec);
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
const main = detectMain(rp.repo);
|
|
227
|
+
if (!main) {
|
|
228
|
+
rec.status = 'failed';
|
|
229
|
+
rec.reason = 'cannot-detect-main';
|
|
230
|
+
prechecks.push(rec);
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
rec.main = main;
|
|
234
|
+
const target = targetArg || main;
|
|
235
|
+
rec.target = target;
|
|
236
|
+
|
|
237
|
+
if (!hasRef(rp.repo, 'refs/heads/' + branch)) {
|
|
238
|
+
rec.status = 'skipped';
|
|
239
|
+
rec.reason = 'no-branch';
|
|
240
|
+
prechecks.push(rec);
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
const targetLocal = hasRef(rp.repo, 'refs/heads/' + target);
|
|
244
|
+
const targetRemote = hasRef(rp.repo, 'refs/remotes/origin/' + target);
|
|
245
|
+
if (!targetLocal && !targetRemote) {
|
|
246
|
+
rec.status = 'failed';
|
|
247
|
+
rec.reason = 'target-not-found';
|
|
248
|
+
prechecks.push(rec);
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (target === main) {
|
|
253
|
+
// 主干路径(快路径,与 ADR 0007 收尾门禁一致)
|
|
254
|
+
if (mergedToMain(rp.repo, branch, main)) {
|
|
255
|
+
rec.status = 'skipped';
|
|
256
|
+
rec.reason = 'already-merged';
|
|
257
|
+
prechecks.push(rec);
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
const status = run('git status --porcelain', rp.work);
|
|
261
|
+
if (!status.ok || status.out) {
|
|
262
|
+
rec.status = 'failed';
|
|
263
|
+
rec.reason = 'dirty-worktree';
|
|
264
|
+
prechecks.push(rec);
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
const current = run('git branch --show-current', rp.work);
|
|
268
|
+
if (current.out && current.out !== main && !allowCheckout) {
|
|
269
|
+
rec.status = 'failed';
|
|
270
|
+
rec.reason = 'not-on-main';
|
|
271
|
+
prechecks.push(rec);
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
const ahead = run('git rev-list --count "origin/' + main + '..' + main + '"', rp.repo);
|
|
275
|
+
if (ahead.ok && ahead.out && parseInt(ahead.out, 10) > 0) {
|
|
276
|
+
rec.status = 'failed';
|
|
277
|
+
rec.reason = 'main-ahead-of-origin';
|
|
278
|
+
prechecks.push(rec);
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
} else {
|
|
282
|
+
// 指定分支路径:已合并则跳过;当前检出即目标且干净 → 就地;否则临时 worktree
|
|
283
|
+
if (mergedToTarget(rp.repo, branch, target)) {
|
|
284
|
+
rec.status = 'skipped';
|
|
285
|
+
rec.reason = 'already-merged';
|
|
286
|
+
prechecks.push(rec);
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
const current = run('git branch --show-current', rp.work);
|
|
290
|
+
if (current.out === target) {
|
|
291
|
+
const status = run('git status --porcelain', rp.work);
|
|
292
|
+
if (!status.ok || status.out) {
|
|
293
|
+
rec.status = 'failed';
|
|
294
|
+
rec.reason = 'dirty-worktree';
|
|
295
|
+
prechecks.push(rec);
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
} else {
|
|
299
|
+
rec.temp = true; // 执行阶段创建临时 worktree
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
prechecks.push(rec);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const hasPrecheckFailure = prechecks.some(p => p.status === 'failed');
|
|
306
|
+
prechecks.forEach(p => {
|
|
307
|
+
if (p.status === 'failed') console.log('FAIL ' + p.name + ': ' + p.reason);
|
|
308
|
+
else if (p.status === 'skipped') console.log('SKIP ' + p.name + ': ' + p.reason);
|
|
309
|
+
else console.log('OK ' + p.name + ' → 合并至 ' + p.target + (p.temp ? '(临时 worktree)' : ''));
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
if (hasPrecheckFailure) {
|
|
313
|
+
console.log('---');
|
|
314
|
+
console.log('MERGE_RESULT', JSON.stringify({ phase: 'precheck', results: prechecks }));
|
|
315
|
+
process.exit(2);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
if (dryRun) {
|
|
319
|
+
console.log('---');
|
|
320
|
+
console.log('MERGE_RESULT', JSON.stringify({ phase: 'precheck', dry_run: true, results: prechecks }));
|
|
321
|
+
process.exit(0);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// ── 阶段 2:执行(停止式,不回滚) ────────────────────────
|
|
325
|
+
const results = prechecks.map(p => ({ ...p, status: p.status, detail: null }));
|
|
326
|
+
let stopped = false;
|
|
327
|
+
|
|
328
|
+
for (let i = 0; i < prechecks.length; i += 1) {
|
|
329
|
+
const p = prechecks[i];
|
|
330
|
+
const rp = repos[i];
|
|
331
|
+
if (p.status !== 'ok') continue;
|
|
332
|
+
if (stopped) {
|
|
333
|
+
results[i].status = 'not-attempted';
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const target = p.target;
|
|
338
|
+
const mergeMsg = "Merge branch '" + branch + "'";
|
|
339
|
+
|
|
340
|
+
if (target === p.main) {
|
|
341
|
+
// ── 主干路径(快路径) ──
|
|
342
|
+
const current = run('git branch --show-current', rp.work);
|
|
343
|
+
if (current.out !== target) {
|
|
344
|
+
const co = run('git checkout --quiet "' + target + '"', rp.work);
|
|
345
|
+
if (!co.ok) {
|
|
346
|
+
results[i].status = 'failed';
|
|
347
|
+
results[i].detail = 'checkout-failed: ' + co.err.split(/\r?\n/)[0];
|
|
348
|
+
stopped = true;
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
const pull = run('git pull --ff-only --quiet origin "' + target + '"', rp.repo);
|
|
353
|
+
if (!pull.ok) {
|
|
354
|
+
results[i].status = 'failed';
|
|
355
|
+
results[i].detail = 'pull-failed: ' + pull.err.split(/\r?\n/)[0];
|
|
356
|
+
stopped = true;
|
|
357
|
+
continue;
|
|
358
|
+
}
|
|
359
|
+
const merge = run('git merge --no-ff -m "' + mergeMsg + '" "' + branch + '"', rp.repo);
|
|
360
|
+
if (!merge.ok) {
|
|
361
|
+
run('git merge --abort', rp.repo);
|
|
362
|
+
results[i].status = 'failed';
|
|
363
|
+
results[i].detail = 'merge-failed: ' + merge.err.split(/\r?\n/)[0];
|
|
364
|
+
stopped = true;
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
let push = run('git push origin "' + target + '"', rp.repo);
|
|
368
|
+
if (!push.ok) {
|
|
369
|
+
const code = classifyPushError(push.err);
|
|
370
|
+
if (code === 'non-fast-forward') {
|
|
371
|
+
const retryPull = run('git pull --ff-only --quiet origin "' + target + '"', rp.repo);
|
|
372
|
+
push = retryPull.ok ? run('git push origin "' + target + '"', rp.repo) : retryPull;
|
|
373
|
+
}
|
|
374
|
+
if (!push.ok) {
|
|
375
|
+
const code2 = classifyPushError(push.err);
|
|
376
|
+
if (code2 === 'branch-protected') {
|
|
377
|
+
results[i].status = 'need-mr';
|
|
378
|
+
results[i].detail = 'branch-protected(目标分支受保护,请改用 MR 出口)';
|
|
379
|
+
} else {
|
|
380
|
+
results[i].status = 'failed';
|
|
381
|
+
results[i].detail = 'push-failed: ' + (push.err || '').split(/\r?\n/)[0];
|
|
382
|
+
}
|
|
383
|
+
stopped = true;
|
|
384
|
+
continue;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
results[i].status = 'merged';
|
|
388
|
+
results[i].detail = 'merged+pushed origin/' + target;
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// ── 指定分支路径(当前检出即目标 → 就地;否则临时 worktree) ──
|
|
393
|
+
let workDir = rp.work;
|
|
394
|
+
let tmpDir = null;
|
|
395
|
+
const current = run('git branch --show-current', rp.work);
|
|
396
|
+
if (current.out !== target) {
|
|
397
|
+
tmpDir = path.join(os.tmpdir(), 'cbb-merge-' + process.pid + '-' + i);
|
|
398
|
+
const base = hasRef(rp.repo, 'refs/remotes/origin/' + target) ? 'origin/' + target : target;
|
|
399
|
+
const add = run('git worktree add --detach "' + tmpDir + '" "' + base + '"', rp.repo);
|
|
400
|
+
if (!add.ok) {
|
|
401
|
+
results[i].status = 'failed';
|
|
402
|
+
results[i].detail = 'worktree-add-failed: ' + add.err.split(/\r?\n/)[0];
|
|
403
|
+
stopped = true;
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
workDir = tmpDir;
|
|
407
|
+
} else {
|
|
408
|
+
const pull = run('git pull --ff-only --quiet origin "' + target + '"', rp.repo);
|
|
409
|
+
if (!pull.ok) {
|
|
410
|
+
results[i].status = 'failed';
|
|
411
|
+
results[i].detail = 'pull-failed: ' + pull.err.split(/\r?\n/)[0];
|
|
412
|
+
stopped = true;
|
|
413
|
+
continue;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
const merge = run('git merge --no-ff -m "' + mergeMsg + '" "' + branch + '"', workDir);
|
|
418
|
+
if (!merge.ok) {
|
|
419
|
+
run('git merge --abort', workDir);
|
|
420
|
+
cleanupTempWorktree(rp.repo, tmpDir);
|
|
421
|
+
results[i].status = 'failed';
|
|
422
|
+
results[i].detail = 'merge-failed: ' + merge.err.split(/\r?\n/)[0];
|
|
423
|
+
stopped = true;
|
|
424
|
+
continue;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
let push = run('git push origin "HEAD:refs/heads/' + target + '"', workDir);
|
|
428
|
+
if (!push.ok) {
|
|
429
|
+
const code = classifyPushError(push.err);
|
|
430
|
+
if (code === 'non-fast-forward') {
|
|
431
|
+
// 远端已前进:在合并工作区 ff 同步后重试一次
|
|
432
|
+
const retry = run('git fetch --quiet origin "' + target + '" && git reset --hard FETCH_HEAD', workDir);
|
|
433
|
+
if (retry.ok) {
|
|
434
|
+
const rem = run('git merge --no-ff -m "' + mergeMsg + '" "' + branch + '"', workDir);
|
|
435
|
+
if (rem.ok) push = run('git push origin "HEAD:refs/heads/' + target + '"', workDir);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
if (!push.ok) {
|
|
439
|
+
const code2 = classifyPushError(push.err);
|
|
440
|
+
cleanupTempWorktree(rp.repo, tmpDir);
|
|
441
|
+
if (code2 === 'branch-protected') {
|
|
442
|
+
results[i].status = 'need-mr';
|
|
443
|
+
results[i].detail = 'branch-protected(目标分支受保护,请改用 MR 出口)';
|
|
444
|
+
} else {
|
|
445
|
+
results[i].status = 'failed';
|
|
446
|
+
results[i].detail = 'push-failed: ' + (push.err || '').split(/\r?\n/)[0];
|
|
447
|
+
}
|
|
448
|
+
stopped = true;
|
|
449
|
+
continue;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
cleanupTempWorktree(rp.repo, tmpDir);
|
|
453
|
+
results[i].status = 'merged';
|
|
454
|
+
results[i].detail = 'merged+pushed origin/' + target + (tmpDir ? '(临时 worktree)' : '');
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
results.forEach(r => {
|
|
458
|
+
console.log(r.status.toUpperCase() + ' ' + r.name + (r.detail ? ' — ' + r.detail : ''));
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
const ok = results.every(r => r.status === 'merged' || r.status === 'skipped');
|
|
462
|
+
console.log('---');
|
|
463
|
+
console.log('MERGE_RESULT', JSON.stringify({ phase: 'execute', target: targetArg || null, results }));
|
|
464
|
+
process.exit(ok ? 0 : 2);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
if (require.main === module) main();
|
|
468
|
+
|
|
469
|
+
module.exports = { run, detectMain, mergedTo, mergedToMain, mergedToTarget, classifyPushError, loadApps, buildRepos };
|
|
@@ -3,7 +3,7 @@ require('./silence-popup');
|
|
|
3
3
|
* openspec-shared 推送核心模块
|
|
4
4
|
*
|
|
5
5
|
* 唯一真源:cbb/worktrees/_shared/scripts/push-core.js
|
|
6
|
-
* 由 scripts/sync-shared.js 展开到各 skill 的 scripts/ 下(init
|
|
6
|
+
* 由 scripts/sync-shared.js 展开到各 skill 的 scripts/ 下(init / push)。
|
|
7
7
|
*
|
|
8
8
|
* 公开 API:
|
|
9
9
|
* - tryExec(cmd, cwd, execImpl) 包装 execSync,统一返回 {ok, out|err}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// koffi is resolved from cbb global install (no local node_modules needed).
|
|
5
5
|
//
|
|
6
6
|
// 唯一真源:cbb/worktrees/_shared/scripts/silence-popup.js
|
|
7
|
-
// 由 scripts/sync-shared.js 展开到各 skill 的 scripts/ 下(init /
|
|
7
|
+
// 由 scripts/sync-shared.js 展开到各 skill 的 scripts/ 下(init / close / push / local-mode)。
|
|
8
8
|
// skill 内同目录引用:脚本第一行 `require('./silence-popup')`。
|
|
9
9
|
if (process.platform === 'win32') {
|
|
10
10
|
try {
|