aodw-skill 0.10.0 → 0.13.0

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.
Files changed (57) hide show
  1. package/.aodw-next/01-core/ai-knowledge-rules.md +35 -2
  2. package/.aodw-next/01-core/aodw-constitution.md +22 -3
  3. package/.aodw-next/01-core/git-discipline.md +110 -52
  4. package/.aodw-next/01-core/test-discipline.md +2 -0
  5. package/.aodw-next/02-workflow/autopilot-protocol.md +4 -1
  6. package/.aodw-next/02-workflow/environment-roles.md +106 -0
  7. package/.aodw-next/02-workflow/orca-multi-session.md +80 -0
  8. package/.aodw-next/02-workflow/rt-manager.md +83 -12
  9. package/.aodw-next/02-workflow/shared-verification-host.md +103 -0
  10. package/.aodw-next/02-workflow/sub-agent-driven-profile.md +2 -1
  11. package/.aodw-next/04-auditors/aodw-development-auditor-rules.md +2 -6
  12. package/.aodw-next/04-auditors/aodw-full-auditor-rules.md +2 -6
  13. package/.aodw-next/README.md +168 -7
  14. package/.aodw-next/SKILL.md +4 -1
  15. package/.aodw-next/manifest.yaml +26 -2
  16. package/.aodw-next/project.yaml +4 -0
  17. package/.aodw-next/skills/handover-pack/scripts/next-number.sh +1 -1
  18. package/.aodw-next/skills/handover-pack/templates/handover-template.md +3 -1
  19. package/.aodw-next/templates/dev-session-guide-template.md +20 -0
  20. package/.aodw-next/templates/environments.template.md +54 -0
  21. package/.aodw-next/templates/lessons.template.md +7 -0
  22. package/.aodw-next/templates/main-session-handover-template.md +19 -0
  23. package/.aodw-next/templates/orca-handoff-template.md +31 -0
  24. package/.aodw-next/templates/release/checklist.template.md +29 -0
  25. package/.aodw-next/templates/release/notes.template.md +22 -0
  26. package/.aodw-next/templates/release/plan.template.md +15 -0
  27. package/.aodw-next/templates/release/retro-index.template.md +8 -0
  28. package/.aodw-next/templates/release/retro-topic.template.md +33 -0
  29. package/.aodw-next/templates/rt-lite.template.md +1 -0
  30. package/.aodw-next/templates/rt-meta-template.yaml +2 -2
  31. package/.aodw-next/templates/shared-verification-host-profile.template.md +50 -0
  32. package/.aodw-next/tools/next-rt-id.sh +39 -0
  33. package/.aodw-next/tools/rel-plan.mjs +203 -0
  34. package/.aodw-next/tools/worktree-gc.sh +260 -0
  35. package/AODW_Adapters/README.md +22 -126
  36. package/AODW_Adapters/agents/AGENTS.md +11 -0
  37. package/AODW_Adapters/antigravity/.agent/rules/aodw-next.md +2 -72
  38. package/AODW_Adapters/claude/CLAUDE.md +2 -72
  39. package/AODW_Adapters/copilot/.github/copilot-instructions.md +3 -0
  40. package/AODW_Adapters/cursor/.cursor/rules/aodw-next.mdc +3 -75
  41. package/AODW_Adapters/openclaw/SKILL.md +3 -106
  42. package/README.md +60 -22
  43. package/bin/aodw.js +374 -279
  44. package/bin/commands/new.js +21 -25
  45. package/bin/commands/update.js +387 -0
  46. package/bin/commands/verify.js +420 -0
  47. package/bin/utils/lock.js +343 -0
  48. package/bin/utils/path-guard.js +449 -0
  49. package/bin/utils/release.js +36 -0
  50. package/bin/utils/tool-entries.js +506 -0
  51. package/package.json +8 -2
  52. package/.aodw-next/templates/aodw-kernel-loader-template.md +0 -71
  53. package/AODW_Adapters/cursor/.cursor/commands/README.md +0 -37
  54. package/AODW_Adapters/cursor/.cursor/rules/aodw-autopilot-continue.mdc +0 -42
  55. package/AODW_Adapters/openclaw/AGENTS.md +0 -142
  56. package/bin/processors/index.js +0 -98
  57. package/bin/update-adapters-from-template.js +0 -76
@@ -1,3 +1,4 @@
1
+ import { spawnSync } from 'child_process';
1
2
  import fs from 'fs-extra';
2
3
  import path from 'path';
3
4
  import { fileURLToPath } from 'url';
@@ -43,29 +44,6 @@ function getProjectName() {
43
44
  return path.basename(process.cwd());
44
45
  }
45
46
 
46
- function getLocalMaxSeq() {
47
- const rtDir = path.join(process.cwd(), 'RT');
48
- if (!fs.existsSync(rtDir)) return 0;
49
-
50
- const dirs = fs.readdirSync(rtDir);
51
- let maxSeq = 0;
52
-
53
- for (const dir of dirs) {
54
- const match = dir.match(/^RT-(\d+)$/);
55
- if (match) {
56
- const seq = parseInt(match[1], 10);
57
- if (seq > maxSeq) maxSeq = seq;
58
- }
59
- }
60
-
61
- return maxSeq;
62
- }
63
-
64
- function getLocalNextId() {
65
- const maxSeq = getLocalMaxSeq();
66
- return `RT-${String(maxSeq + 1).padStart(3, '0')}`;
67
- }
68
-
69
47
  const EXECUTION_MODES = ['collaborative', 'autopilot'];
70
48
 
71
49
  async function resolveExecutionMode(options) {
@@ -101,6 +79,14 @@ async function resolveExecutionMode(options) {
101
79
  }
102
80
 
103
81
  export async function createNewRT(options) {
82
+ const root = spawnSync('git', ['rev-parse', '--show-toplevel'], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] });
83
+ if (root.status !== 0) {
84
+ console.error(chalk.red('错误:请在 Git 工作树里创建 RT。'));
85
+ process.exitCode = 1;
86
+ return;
87
+ }
88
+ process.chdir(root.stdout.replace(/\r?\n$/, ''));
89
+
104
90
  // Determine Project Name: Flag > Config/Package/Dir
105
91
  const project = options.project || getProjectName();
106
92
 
@@ -118,8 +104,18 @@ export async function createNewRT(options) {
118
104
 
119
105
  const executionMode = await resolveExecutionMode(options);
120
106
 
121
- // 固定独立模式:始终本地生成 RT-ID
122
- const id = getLocalNextId();
107
+ // 从 CLI 包取脚本,老项目无需先安装新版内核。
108
+ const binDir = path.dirname(fileURLToPath(import.meta.url));
109
+ const packagedScript = path.join(binDir, '../../.aodw-next/tools/next-rt-id.sh');
110
+ const script = fs.existsSync(packagedScript) ? packagedScript :
111
+ path.join(binDir, '../../../templates/.aodw-next/tools/next-rt-id.sh');
112
+ const result = spawnSync('bash', [script, '.'], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'inherit'] });
113
+ if (result.status !== 0) {
114
+ console.error(chalk.red('错误:next-rt-id.sh 开号失败,未创建 RT。'));
115
+ process.exitCode = 1;
116
+ return;
117
+ }
118
+ const id = result.stdout.trim();
123
119
  console.log(chalk.yellow(`Using local ID generation: ${id}`));
124
120
 
125
121
  // Create Directory
@@ -0,0 +1,387 @@
1
+ import crypto from 'node:crypto';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import {
5
+ LOCK_FILENAME,
6
+ assertSafeWriteTargets,
7
+ buildAndWriteLock,
8
+ isProtectedIdentity,
9
+ onDiskCorePath,
10
+ protectedCoreIdentities,
11
+ replaceFileEntry,
12
+ planReleaseIdentities,
13
+ resolveSafeFileInDir,
14
+ sha256File,
15
+ validateLockRelPath,
16
+ verifyCoreLock,
17
+ } from '../utils/lock.js';
18
+ import { collectReleaseFiles, readReleaseFile } from '../utils/release.js';
19
+ import { printUpdatePreflightError, printWriteBoundaryError, verifyToolEntries } from './verify.js';
20
+
21
+ function digest(data) {
22
+ return crypto.createHash('sha256').update(data).digest('hex');
23
+ }
24
+
25
+ // 递归复制目录内容:只用 Node 16.0 已有的 API。符号链接原样重建(不跟随);文件的权限位照源设置。
26
+ // 目录在整份复制期间一律保持 0700:源目录的权限位先记进 pendingModes,等全部复制完再从深到广收紧。
27
+ // 这样复制途中失败时,本次新建的每个目录都还能删。遇到不支持的类型(管道、套接字、设备等)直接抛错。
28
+ function copyTree(sourceDir, targetDir, pendingModes) {
29
+ for (const entry of fs.readdirSync(sourceDir, { withFileTypes: true })) {
30
+ const source = path.join(sourceDir, entry.name);
31
+ const target = path.join(targetDir, entry.name);
32
+ if (entry.isDirectory()) {
33
+ fs.mkdirSync(target, { mode: 0o700 });
34
+ copyTree(source, target, pendingModes);
35
+ pendingModes.push([target, fs.statSync(source).mode & 0o777]);
36
+ } else if (entry.isSymbolicLink()) {
37
+ fs.symlinkSync(fs.readlinkSync(source), target);
38
+ } else if (entry.isFile()) {
39
+ fs.copyFileSync(source, target);
40
+ fs.chmodSync(target, fs.statSync(source).mode & 0o777);
41
+ } else {
42
+ throw new Error(`不支持备份的文件类型:${source}`);
43
+ }
44
+ }
45
+ }
46
+
47
+ // 删掉本次独占新建的备份:先把它里面每个目录恢复成属主可读写执行,再整份删除。
48
+ // 只碰 backupPath 之下的目录,从不 chmod 源目录或链接之外的路径;删不掉的如实返回,不盖住主错误。
49
+ function discardBackup(backupPath) {
50
+ const pending = [backupPath];
51
+ while (pending.length > 0) {
52
+ const dir = pending.pop();
53
+ try {
54
+ fs.chmodSync(dir, (fs.statSync(dir).mode & 0o777) | 0o700);
55
+ } catch {
56
+ // 放不开也没关系:目录本来就能进就继续往下,进不去的会留在残留清单里
57
+ }
58
+ let entries = [];
59
+ try {
60
+ entries = fs.readdirSync(dir, { withFileTypes: true });
61
+ } catch {
62
+ continue;
63
+ }
64
+ for (const entry of entries) {
65
+ if (entry.isDirectory() && !entry.isSymbolicLink()) pending.push(path.join(dir, entry.name));
66
+ }
67
+ }
68
+ try {
69
+ fs.rmSync(backupPath, { recursive: true, force: true });
70
+ } catch {
71
+ // 下面按实际情况报告
72
+ }
73
+ return fs.existsSync(backupPath) ? [backupPath] : [];
74
+ }
75
+
76
+ // 独占创建备份目录:先查前缀落点,再用 mkdtemp 在通道目录旁新建,既有的同名目录或符号链接不会被复用。
77
+ // 复制与失败清理是同一个生命周期:复制期间根目录与所有子目录保持 0700,整份复制成功后才收紧到源的权限位
78
+ // (子目录从深到广,最后是取原通道目录权限位的根目录),不比原目录更开放。
79
+ // 复制或收紧任一步失败,都保留原始错误,删掉本次新建的那份,删不掉的列出残留;原目录从不被改动。
80
+ function createBackup(projectRoot, coreDirName, coreDir) {
81
+ const stamp = new Date().toISOString().replace(/[-:T]/g, '').slice(0, 12);
82
+ const prefix = `${coreDirName}.backup-${stamp}-`;
83
+ const boundary = assertSafeWriteTargets(projectRoot, [prefix]);
84
+ if (!boundary.ok) return { code: 'boundary', errors: boundary.errors };
85
+ const backupPath = fs.mkdtempSync(path.join(projectRoot, prefix));
86
+ const pendingModes = [];
87
+ try {
88
+ copyTree(coreDir, backupPath, pendingModes);
89
+ for (const [dir, mode] of pendingModes) fs.chmodSync(dir, mode);
90
+ fs.chmodSync(backupPath, fs.statSync(coreDir).mode & 0o777);
91
+ } catch (err) {
92
+ const residue = discardBackup(backupPath);
93
+ return {
94
+ code: 'backup_failed',
95
+ errors: [
96
+ `备份 ${coreDirName}/ 未完成,已中止且未改动原目录:${err.message}`,
97
+ ...(residue.length > 0 ? [`本次新建的备份没能删干净,请手工删除:${residue.join(' ')}`] : []),
98
+ ],
99
+ };
100
+ }
101
+ return { backupPath };
102
+ }
103
+
104
+ /**
105
+ * 只按受信发行清单更新上游文件并重新加锁。所有权规则:
106
+ * - 写入集合只来自受信发行清单(发行模板 ∩ 锁内 dev_env 的安装集),锁内路径不作写入目标;
107
+ * - 仓根文件、平台入口、钩子、project.yaml、config.yaml、tools-status.yaml、06-project/ 永不触碰;
108
+ * - 预检(完整性锁)失败默认拒绝。--force 只多给“覆盖上游落点”的许可:先备份再按发行清单覆盖,
109
+ * - 通道目录、aodw.lock、上游落点或备份落点上任一段是符号链接或越界时整体拒绝,--force 也不例外;
110
+ * --force 的备份目录在通道目录旁独占创建(前缀 + 时间戳 + 随机后缀),既有同名条目不会被复用;
111
+ * - 新增的上游路径被未登记的本地文件占用时默认拒绝,本地文件与新版字节完全相同也算占位;--force 才备份后接管并登记;
112
+ * - 上游已下线的文件,只有本地仍是旧锁登记字节时才移除;含本地改动的留在原处、不再登记;
113
+ * - 旧锁对同一个目录项登记了不同的摘要时整体拒绝,--force 也不替用户认定哪一条是对的;下线按目录项去重,只删一次;
114
+ * - 未登记的本地文件一律不动,也不会被写进新锁。
115
+ */
116
+ export function updateUpstream(projectRoot, {
117
+ coreDirName = '.aodw-next',
118
+ sourceCore,
119
+ releaseVersion = '',
120
+ force = false,
121
+ recordedDevEnv,
122
+ } = {}) {
123
+ const coreDir = path.join(projectRoot, coreDirName);
124
+ const result = {
125
+ ok: false,
126
+ code: 'ok',
127
+ devEnv: 'none',
128
+ preflight: null,
129
+ wouldOverwrite: [],
130
+ wouldAdd: [],
131
+ conflicts: [],
132
+ kept: [],
133
+ backupPath: null,
134
+ added: [],
135
+ updated: [],
136
+ overwrote: [],
137
+ removed: [],
138
+ danglingEntries: [],
139
+ errors: [],
140
+ warnings: [],
141
+ };
142
+ const refuse = (code, errors) => {
143
+ result.code = code;
144
+ result.errors.push(...errors);
145
+ return result;
146
+ };
147
+
148
+ // 预检同时校验通道目录名与目录本身:越界、符号链接或根本没有安装目录时,--force 也不写。
149
+ const preflight = verifyCoreLock(projectRoot, coreDirName);
150
+ result.preflight = preflight;
151
+ if (preflight.status === 'missing_core' || preflight.status === 'invalid_core') {
152
+ return refuse(preflight.status, preflight.errors);
153
+ }
154
+
155
+ // 锁落点只能是“缺失”或“普通文件”:目录或其他类型占着 aodw.lock 时,默认与 --force 都在动文件之前拒绝。
156
+ let lockStat = null;
157
+ try {
158
+ lockStat = fs.lstatSync(path.join(projectRoot, coreDirName, LOCK_FILENAME));
159
+ } catch (err) {
160
+ if (err.code !== 'ENOENT') throw err;
161
+ }
162
+ if (lockStat && !lockStat.isFile()) {
163
+ return refuse('boundary', [`${coreDirName}/${LOCK_FILENAME} 落点不是普通文件,拒绝在它上面重建锁`]);
164
+ }
165
+
166
+ const realCoreDir = fs.realpathSync(coreDir);
167
+ // 有锁时以锁内 dev_env 为准(登记的就是实际装着的那一套);锁缺失或不可解析时才读 project.yaml 的记录。
168
+ const lock = preflight.lock;
169
+ const devEnv = lock
170
+ ? (lock.dev_env === 'orca' ? 'orca' : 'none')
171
+ : (recordedDevEnv === 'orca' ? 'orca' : 'none');
172
+ result.devEnv = devEnv;
173
+ const release = collectReleaseFiles(sourceCore, devEnv);
174
+ const lockedFiles = lock?.files || {};
175
+
176
+ // 写前边界:通道目录本身已由预检逐段查过,这里再查 aodw.lock 与每个上游落点;
177
+ // 任何已存在的路径段是符号链接就整体拒绝,--force 也不例外。
178
+ const boundary = assertSafeWriteTargets(projectRoot, [
179
+ `${coreDirName}/${LOCK_FILENAME}`,
180
+ ...release.map(rel => `${coreDirName}/${rel}`),
181
+ ]);
182
+ if (!boundary.ok) return refuse('boundary', boundary.errors);
183
+
184
+ if (!preflight.ok && !force) {
185
+ // 漂移安装已由预检点名被改的文件;其余状态没有可信基线,按新版发行清单逐个比对给出预览。
186
+ if (preflight.status !== 'drifted') {
187
+ for (const rel of release) {
188
+ const local = resolveSafeFileInDir(coreDir, realCoreDir, rel);
189
+ if (!local.ok) result.wouldAdd.push(rel);
190
+ else if (sha256File(local.absPath) !== digest(readReleaseFile(sourceCore, rel, devEnv))) {
191
+ result.wouldOverwrite.push(rel);
192
+ }
193
+ }
194
+ }
195
+ return refuse('preflight', preflight.errors);
196
+ }
197
+
198
+ // 目录项身份:已有的条目按磁盘上的真实拼写认,保护命名空间也按它在磁盘上的实际身份认。
199
+ // 旧锁键与发行路径都先解析成身份再比较,不看请求时的拼写。写集与下线计划共用这一份索引:一个目录项只算一条登记。
200
+ const protectedNs = protectedCoreIdentities(coreDir);
201
+ const registered = new Map(); // 目录项的实际身份 -> { keys: 登记它的锁键, digests: 登记过的摘要 }
202
+ for (const key of Object.keys(lockedFiles)) {
203
+ if (!validateLockRelPath(key).ok) continue;
204
+ const identity = onDiskCorePath(coreDir, key);
205
+ if (identity === null) continue; // 文件已不在,或不是普通文件:没有可删的目录项
206
+ const record = registered.get(identity) ?? { keys: [], digests: new Set() };
207
+ record.keys.push(key);
208
+ record.digests.add(lockedFiles[key]);
209
+ registered.set(identity, record);
210
+ }
211
+ // 两条锁键落到同一个目录项却登记了不同的摘要:锁自相矛盾,哪一条是对的没人知道。--force 只授权覆盖,
212
+ // 不授权替用户认定归属,所以在任何备份或写入之前整体拒绝。
213
+ const ambiguous = [...registered].filter(([, record]) => record.digests.size > 1);
214
+ if (ambiguous.length > 0) {
215
+ return refuse('ambiguous_lock', ambiguous.map(
216
+ ([identity, record]) => `旧锁对同一个目录项登记了不同的摘要 (${coreDirName}/${identity}): ${record.keys.join(' ')};` +
217
+ `无法判断哪一条是对的,请先用 verify 核对并修正 ${coreDirName}/${LOCK_FILENAME}`,
218
+ ));
219
+ }
220
+
221
+ // 写前计划:发行路径在目标卷上的目录项身份——已有的按磁盘上的真实拼写认,尚不存在的在通道目录所在卷
222
+ // 独占的临时命名空间里问文件系统。所有必须在写入之前拒绝的情况都在这里报出:指向保护路径、
223
+ // 发行内部落到同一个目录项、文件与目录冲突。--force 也不越过这些边界。
224
+ const plan = planReleaseIdentities(coreDir, release, { coreDirName });
225
+ const boundaryErrors = [...plan.errors];
226
+ const releaseEntries = new Set([...plan.entries.values()].filter(Boolean)); // 发行路径占着的现存目录项
227
+ const writes = [];
228
+ for (const rel of release) {
229
+ const existing = plan.entries.get(rel);
230
+ if (existing === undefined) continue; // 已经作为边界错误报过了
231
+ const content = readReleaseFile(sourceCore, rel, devEnv);
232
+ const localHash = existing !== null ? sha256File(path.join(coreDir, ...rel.split('/'))) : null;
233
+ // 已登记 = 旧锁里有键与这个目录项是同一个身份(两边的拼写可以不同),且本地字节就是登记的字节。
234
+ const record = existing !== null ? registered.get(existing) : undefined;
235
+ const pristine = record !== undefined && record.digests.has(localHash);
236
+ // 已到位 = 登记过、仍是登记的字节、文件名拼写与新版一致且已是新版字节。只改了大小写或 Unicode 规范化的
237
+ // 落点是同一条目录项,仍要换成新版的拼写;上级目录只差大小写时文件本身不动。
238
+ // 未登记的本地文件即使与新版字节完全相同也是占位:默认不接管,--force 才备份后接管并登记。
239
+ if (pristine && existing !== null && path.posix.basename(existing) === path.posix.basename(rel) && localHash === digest(content)) continue;
240
+ if (existing !== null && !pristine && !force) {
241
+ result.conflicts.push(rel);
242
+ continue;
243
+ }
244
+ writes.push({
245
+ rel,
246
+ kind: existing === null ? 'added' : pristine ? 'updated' : 'overwrote',
247
+ absPath: path.join(coreDir, ...rel.split('/')),
248
+ content,
249
+ mode: fs.statSync(path.join(sourceCore, ...rel.split('/'))).mode & 0o777,
250
+ });
251
+ }
252
+ if (boundaryErrors.length > 0) return refuse('boundary', boundaryErrors);
253
+ if (result.conflicts.length > 0) {
254
+ return refuse('conflict', result.conflicts.map(
255
+ rel => `上游新增路径已被未登记的本地文件占用: ${coreDirName}/${rel}`,
256
+ ));
257
+ }
258
+
259
+ // 下线计划与写集用同一份目录项索引:一个目录项最多删一次,两条只差拼写的锁键不会让同一个文件删两遍。
260
+ // 硬链接的不同名字是不同的目录项,各算各的,不按 inode 合并。
261
+ const removals = [];
262
+ for (const [identity, record] of registered) {
263
+ // 发行路径正占着的目录项不删;落在保护命名空间里的条目(盘面拼写再怎么变)不删。
264
+ if (releaseEntries.has(identity) || isProtectedIdentity(identity, protectedNs)) continue;
265
+ const local = resolveSafeFileInDir(coreDir, realCoreDir, identity);
266
+ if (!local.ok) continue;
267
+ if (sha256File(local.absPath) === [...record.digests][0]) removals.push(identity);
268
+ else result.kept.push(identity);
269
+ }
270
+
271
+ // 只有 --force 会覆盖带本地内容的文件;这时先把整个通道目录备份到它的同级目录。
272
+ if (force && writes.some(item => item.kind !== 'added')) {
273
+ const backup = createBackup(projectRoot, coreDirName, coreDir);
274
+ if (backup.errors) return refuse(backup.code, backup.errors);
275
+ result.backupPath = backup.backupPath;
276
+ }
277
+
278
+ // step 记录正在做的那一步,失败时报告能点名是哪条文件、哪个阶段。
279
+ let step = '准备写入';
280
+ try {
281
+ for (const item of writes) {
282
+ step = `写入 ${coreDirName}/${item.rel}`;
283
+ fs.mkdirSync(path.dirname(item.absPath), { recursive: true });
284
+ // 同目录临时文件 + rename:落点若与项目层或仓外文件是硬链接,那个名字保持原字节与权限。
285
+ replaceFileEntry(item.absPath, item.content, item.mode);
286
+ result[item.kind].push(item.rel);
287
+ }
288
+ for (const identity of removals) {
289
+ step = `删除 ${coreDirName}/${identity}`;
290
+ fs.unlinkSync(path.join(coreDir, ...identity.split('/')));
291
+ result.removed.push(identity);
292
+ }
293
+
294
+ step = '重建 aodw.lock';
295
+ buildAndWriteLock(coreDir, release, { version: releaseVersion, devEnv });
296
+ } catch (err) {
297
+ // 写入不是事务:如实报出已经改了什么、备份在哪,不回滚,也不吞掉错误。
298
+ const done = [...result.added, ...result.updated, ...result.overwrote];
299
+ return refuse('write_failed', [
300
+ `${step}失败:${err.message}`,
301
+ `已改的上游文件(${done.length} 个):${done.length > 0 ? done.join(' ') : '无'}`,
302
+ `已删除的上游文件(${result.removed.length} 个):${result.removed.length > 0 ? result.removed.join(' ') : '无'}`,
303
+ 'aodw.lock 未重建,再次 update 前请先用 verify 核对',
304
+ result.backupPath
305
+ ? `原通道的完整备份在 ${path.relative(projectRoot, result.backupPath)}`
306
+ : '本次没有创建备份(没有覆盖带本地内容的文件)',
307
+ ]);
308
+ }
309
+ const verify = verifyCoreLock(projectRoot, coreDirName);
310
+ result.warnings = verify.warnings;
311
+ if (!verify.ok) return refuse('verify_failed', verify.errors);
312
+ // 下线后的入口扫描逐条告警,不改入口;只报告本次退役的悬空引用,其余既有悬空路径交给 verify。
313
+ if (result.removed.length > 0) {
314
+ const removedRefs = new Set();
315
+ for (const rel of result.removed) {
316
+ removedRefs.add(`${coreDirName}/${rel}`);
317
+ for (const key of registered.get(rel).keys) removedRefs.add(`${coreDirName}/${key}`);
318
+ }
319
+ verifyToolEntries(projectRoot, fs.realpathSync(projectRoot), {
320
+ coreDirName,
321
+ onInvalidReference(refPath, error) {
322
+ if (removedRefs.has(path.posix.normalize(refPath))) result.danglingEntries.push(error);
323
+ },
324
+ onEntryDiagnostic(error) {
325
+ result.danglingEntries.push(error);
326
+ },
327
+ });
328
+ }
329
+ result.ok = true;
330
+ return result;
331
+ }
332
+
333
+ function printPreview(title, rels, coreDirName) {
334
+ if (rels.length === 0) return;
335
+ console.error(`${title}:`);
336
+ for (const rel of rels) console.error(` - ${coreDirName}/${rel}`);
337
+ }
338
+
339
+ export function runUpdate({
340
+ coreDirName = process.env.AODW_CORE_DIR || '.aodw-next',
341
+ sourceCore,
342
+ releaseVersion = '',
343
+ force = false,
344
+ recordedDevEnv,
345
+ } = {}) {
346
+ const result = updateUpstream(process.cwd(), {
347
+ coreDirName, sourceCore, releaseVersion, force, recordedDevEnv,
348
+ });
349
+
350
+ for (const warning of result.warnings) console.warn(`⚠️ ${warning}`);
351
+ if (!result.ok) {
352
+ if (result.code === 'preflight') printUpdatePreflightError(result.preflight, coreDirName);
353
+ else if (result.code === 'boundary') printWriteBoundaryError(result.errors);
354
+ else if (result.code === 'backup_failed') {
355
+ console.error('❌ 更新未执行:原通道的备份没有完成,没有改动任何文件。');
356
+ for (const error of result.errors) console.error(` - ${error}`);
357
+ } else if (result.code === 'write_failed') {
358
+ console.error('❌ 更新在写入阶段失败,通道处于部分更新的状态:');
359
+ for (const error of result.errors) console.error(` - ${error}`);
360
+ } else {
361
+ console.error(`❌ 拒绝更新(${result.code}):`);
362
+ for (const error of result.errors) console.error(` - ${error}`);
363
+ }
364
+ printPreview('本地内容与新版发行模板不同的上游文件(--force 会先备份再覆盖)', result.wouldOverwrite, coreDirName);
365
+ printPreview('本地缺失的上游文件(--force 会新增)', result.wouldAdd, coreDirName);
366
+ if (result.code === 'conflict') {
367
+ console.error(`提示:请把项目定制移至 ${coreDirName}/06-project/,或加 "--force" 备份后用上游文件覆盖。`);
368
+ }
369
+ process.exitCode = 1;
370
+ return result;
371
+ }
372
+
373
+ if (result.backupPath) console.log(`📦 已备份原 ${coreDirName}/ 到 ${path.basename(result.backupPath)}`);
374
+ console.log(
375
+ `✅ AODW-Next 上游文件已更新到 ${releaseVersion}:新增 ${result.added.length},更新 ${result.updated.length},` +
376
+ `覆盖 ${result.overwrote.length},移除 ${result.removed.length}(开发环境:${result.devEnv})。`,
377
+ );
378
+ for (const rel of result.kept) console.log(`• 未移除(含本地改动,已不再登记):${coreDirName}/${rel}`);
379
+ for (const error of result.danglingEntries) console.warn(`⚠️ ${error}`);
380
+ if (result.danglingEntries.length > 0) {
381
+ console.error('提示:update 不改工具入口;以上是附带检查的告警(下线的上游文件可能仍被入口引用,或个别入口读不了),可运行 aodw-skill verify 复核。');
382
+ } else if (result.removed.length > 0) {
383
+ console.log(`ℹ️ 本次移除了 ${result.removed.length} 个上游文件;项目入口若引用过它们会失效,可运行 verify 复核。`);
384
+ }
385
+ console.log(`仓根文件、平台入口、钩子、${coreDirName}/project.yaml、运行态配置与 06-project/ 未改动。`);
386
+ return result;
387
+ }