aodw-skill 0.11.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 (48) 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 +11 -0
  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 +4 -4
  8. package/.aodw-next/02-workflow/rt-manager.md +64 -0
  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 +19 -1
  16. package/.aodw-next/templates/environments.template.md +54 -0
  17. package/.aodw-next/templates/lessons.template.md +7 -0
  18. package/.aodw-next/templates/orca-handoff-template.md +2 -1
  19. package/.aodw-next/templates/release/checklist.template.md +29 -0
  20. package/.aodw-next/templates/release/notes.template.md +22 -0
  21. package/.aodw-next/templates/release/plan.template.md +15 -0
  22. package/.aodw-next/templates/release/retro-index.template.md +8 -0
  23. package/.aodw-next/templates/release/retro-topic.template.md +33 -0
  24. package/.aodw-next/templates/rt-lite.template.md +1 -0
  25. package/.aodw-next/templates/shared-verification-host-profile.template.md +50 -0
  26. package/.aodw-next/tools/rel-plan.mjs +203 -0
  27. package/AODW_Adapters/README.md +22 -126
  28. package/AODW_Adapters/agents/AGENTS.md +11 -0
  29. package/AODW_Adapters/antigravity/.agent/rules/aodw-next.md +2 -72
  30. package/AODW_Adapters/claude/CLAUDE.md +2 -72
  31. package/AODW_Adapters/copilot/.github/copilot-instructions.md +3 -0
  32. package/AODW_Adapters/cursor/.cursor/rules/aodw-next.mdc +3 -75
  33. package/AODW_Adapters/openclaw/SKILL.md +3 -106
  34. package/README.md +60 -22
  35. package/bin/aodw.js +351 -333
  36. package/bin/commands/update.js +387 -0
  37. package/bin/commands/verify.js +420 -0
  38. package/bin/utils/lock.js +343 -0
  39. package/bin/utils/path-guard.js +449 -0
  40. package/bin/utils/release.js +36 -0
  41. package/bin/utils/tool-entries.js +506 -0
  42. package/package.json +8 -2
  43. package/.aodw-next/templates/aodw-kernel-loader-template.md +0 -71
  44. package/AODW_Adapters/cursor/.cursor/commands/README.md +0 -37
  45. package/AODW_Adapters/cursor/.cursor/rules/aodw-autopilot-continue.mdc +0 -42
  46. package/AODW_Adapters/openclaw/AGENTS.md +0 -142
  47. package/bin/processors/index.js +0 -98
  48. package/bin/update-adapters-from-template.js +0 -76
@@ -0,0 +1,506 @@
1
+ import crypto from 'node:crypto';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { LOCK_SCHEMA_VERSION } from './lock.js';
6
+ import {
7
+ LOCK_FILENAME,
8
+ ENTRIES_FILENAME,
9
+ assertSafeWriteTargets,
10
+ isInsideDir,
11
+ replaceFileEntry,
12
+ resolveOnDiskCorePath,
13
+ resolveSafeFileInDir,
14
+ validateCoreDirName,
15
+ walkRealPath,
16
+ } from './path-guard.js';
17
+
18
+ // 始终安装的入口:仓根相对路径 → 模板在 AODW_Adapters/ 下的路径。
19
+ // AGENTS.md 是唯一规范入口;其余四个薄壳只指向它,装哪一套不随使用的 AI 工具变化。
20
+ export const STANDARD_ENTRIES = [
21
+ ['AGENTS.md', 'agents/AGENTS.md'],
22
+ ['CLAUDE.md', 'claude/CLAUDE.md'],
23
+ ['.cursor/rules/aodw-next.mdc', 'cursor/.cursor/rules/aodw-next.mdc'],
24
+ ['.agent/rules/aodw-next.md', 'antigravity/.agent/rules/aodw-next.md'],
25
+ ['.github/copilot-instructions.md', 'copilot/.github/copilot-instructions.md'],
26
+ ];
27
+ // 按需追加的入口。
28
+ export const OPTIONAL_ENTRIES = { openclaw: ['SKILL.md', 'openclaw/SKILL.md'] };
29
+ const ENTRY_TEMPLATES = [...STANDARD_ENTRIES, ...Object.values(OPTIONAL_ENTRIES)];
30
+ const MANAGED_PATHS = new Set(ENTRY_TEMPLATES.map(([rel]) => rel));
31
+
32
+ // verify 检查的入口文件:本版管理的入口,加上历史版本与旧名称留下的入口。
33
+ export const KNOWN_TOOL_ENTRIES = [
34
+ ...MANAGED_PATHS,
35
+ '.cursor/rules/aodw.mdc',
36
+ '.agent/rules/aodw.md',
37
+ '.claude/CLAUDE.md',
38
+ ];
39
+
40
+ const CHANNEL_MARKER = '.aodw-channel.json';
41
+ const DEFAULT_CORE = '.aodw-next';
42
+ const packagedAdapters = fileURLToPath(new URL('../../AODW_Adapters/', import.meta.url));
43
+ const SOURCE_ADAPTERS = fs.existsSync(packagedAdapters)
44
+ ? packagedAdapters
45
+ : fileURLToPath(new URL('../../../templates/AODW_Adapters/', import.meta.url));
46
+ const CORE_TOKEN = '{{AODW_DIR}}';
47
+
48
+ export function validateEntryCoreDirName(coreDirName) {
49
+ const check = validateCoreDirName(coreDirName);
50
+ if (!check.ok) return check;
51
+ const dir = coreDirName.toLowerCase().split('/');
52
+ if (dir[0] === CHANNEL_MARKER || dir[0] === '.git') {
53
+ return { ok: false, reason: `核心目录配置非法 (${coreDirName}): 与仓根元数据重叠` };
54
+ }
55
+ // 共享前缀必须是完整路径段;大小写变体在不区分大小写的文件系统上也是同一落点。
56
+ const conflict = KNOWN_TOOL_ENTRIES.find((rel) => rel.toLowerCase().split('/')
57
+ .every((segment, i) => i >= dir.length || segment === dir[i]));
58
+ return conflict
59
+ ? { ok: false, reason: `通道目录与工具入口重叠 (${coreDirName}): ${conflict}` }
60
+ : check;
61
+ }
62
+
63
+ const channelError = (reason) => ({ ok: false, errors: [reason] });
64
+
65
+ function hasLegacyLock(projectRoot, dir) {
66
+ const lockPath = walkRealPath(projectRoot, `${dir}/${LOCK_FILENAME}`);
67
+ if (!lockPath.ok || !lockPath.stat.isFile()) return false;
68
+ let lock;
69
+ try {
70
+ lock = JSON.parse(fs.readFileSync(lockPath.absPath, 'utf8'));
71
+ } catch (err) {
72
+ if (err instanceof SyntaxError) return false;
73
+ throw err;
74
+ }
75
+ return lock?.schema_version === LOCK_SCHEMA_VERSION && lock.algorithm === 'sha256' &&
76
+ SHA256_RE.test(lock.files?.['manifest.yaml'] ?? '');
77
+ }
78
+
79
+ function legacyInstalls(projectRoot, requested) {
80
+ // 探测仓根直属目录与显式指定的目录;不递归扫描项目,不把备份或 AGENTS 中的文字当成安装。
81
+ const candidates = new Set([requested, DEFAULT_CORE]);
82
+ for (const item of fs.readdirSync(projectRoot, { withFileTypes: true })) {
83
+ if (item.isDirectory() && item.name.toLowerCase() !== 'node_modules' && !/\.backup-\d{12}(?:-|$)/.test(item.name)) {
84
+ candidates.add(item.name);
85
+ }
86
+ }
87
+ const installed = [];
88
+ const seen = new Set();
89
+ const realRoot = fs.realpathSync(projectRoot);
90
+ for (const dir of candidates) {
91
+ if (!validateEntryCoreDirName(dir).ok) continue;
92
+ const record = readRecord(projectRoot, realRoot, dir);
93
+ const hasRecord = record && typeof record !== 'string';
94
+ if (!hasRecord && !hasLegacyLock(projectRoot, dir)) continue;
95
+ const onDisk = resolveOnDiskCorePath(projectRoot, `${dir}/${hasRecord ? ENTRIES_FILENAME : LOCK_FILENAME}`);
96
+ const identity = onDisk === null ? dir : path.posix.dirname(onDisk);
97
+ if (seen.has(identity)) continue;
98
+ seen.add(identity);
99
+ installed.push({ dir, entries: hasRecord ? record.entries : undefined });
100
+ }
101
+ return installed;
102
+ }
103
+
104
+ function matchesEntryTemplate(text, template) {
105
+ if (text === template) return true;
106
+ const parts = template.split(CORE_TOKEN);
107
+ const slots = parts.length - 1;
108
+ if (!slots || !text.startsWith(parts[0])) return false;
109
+ // 每个占位使用同一目录名;长度确定后再比较整份入口。
110
+ const width = (text.length - template.length) / slots + CORE_TOKEN.length;
111
+ if (!Number.isInteger(width) || width <= 0) return false;
112
+ const candidate = text.slice(parts[0].length, parts[0].length + width);
113
+ return validateEntryCoreDirName(candidate).ok && parts.join(candidate) === text;
114
+ }
115
+
116
+ function legacyEntryEvidence(projectRoot, installed) {
117
+ const owners = new Set();
118
+ let unbound = null;
119
+ for (const [rel, templateRel] of ENTRY_TEMPLATES) {
120
+ if (unbound && !installed.some(({ entries }) => entries?.[rel])) continue;
121
+ const entry = walkRealPath(projectRoot, rel);
122
+ if (!entry.ok || !entry.stat.isFile()) continue;
123
+ const data = fs.readFileSync(entry.absPath);
124
+ let hash;
125
+ let owned = false;
126
+ for (const { dir, entries } of installed) {
127
+ const registeredHash = entries?.[rel];
128
+ if (registeredHash && registeredHash === (hash ??= digest(data))) {
129
+ owners.add(dir);
130
+ owned = true;
131
+ }
132
+ }
133
+ // 模板只能证明还有未解释的生成线索,不能选通道或取得归属。
134
+ if (owned || unbound) continue;
135
+ const template = readEntryTemplate(SOURCE_ADAPTERS, templateRel).replace(/\r\n/g, '\n');
136
+ const text = data.toString('utf8').replace(/\r\n/g, '\n');
137
+ const standard = renderEntryTemplate(template, { coreDirName: CORE_TOKEN });
138
+ if (matchesEntryTemplate(text, standard) || (ORCA_BLOCK_RE.test(template) &&
139
+ matchesEntryTemplate(text, renderEntryTemplate(template, { coreDirName: CORE_TOKEN, devEnv: 'orca' })))) unbound = rel;
140
+ }
141
+ return { owners, unbound };
142
+ }
143
+
144
+ // 根入口为全仓共享:通道标记与核心目录分别保存,手工删除核心目录不会清除活动通道。
145
+ export function checkProjectChannel(projectRoot, coreDirName, { confirmNewChannel = false } = {}) {
146
+ const dirCheck = validateEntryCoreDirName(coreDirName);
147
+ if (!dirCheck.ok) return channelError(dirCheck.reason);
148
+ const marker = walkRealPath(projectRoot, CHANNEL_MARKER, { allowMissing: true });
149
+ if (!marker.ok) return channelError(`${CHANNEL_MARKER} 无法读取:${marker.reason}`);
150
+ let active;
151
+ let entriesPending = false;
152
+ if (marker.exists) {
153
+ if (!marker.stat.isFile()) return channelError(`${CHANNEL_MARKER} 必须是普通文件`);
154
+ let state;
155
+ try {
156
+ state = JSON.parse(fs.readFileSync(marker.absPath, 'utf8'));
157
+ } catch (err) {
158
+ return channelError(`${CHANNEL_MARKER} 无法读取或解析:${err.message}`);
159
+ }
160
+ if (state?.schema_version !== 1 || !validateEntryCoreDirName(state.core_dir).ok) {
161
+ return channelError(`${CHANNEL_MARKER} 的通道记录非法,请从版本库或备份恢复`);
162
+ }
163
+ active = state.core_dir;
164
+ entriesPending = state.entries_pending === true;
165
+ } else {
166
+ let legacy;
167
+ let unbound;
168
+ try {
169
+ const installed = legacyInstalls(projectRoot, coreDirName);
170
+ const evidence = installed.length || !confirmNewChannel ? legacyEntryEvidence(projectRoot, installed) : null;
171
+ // 有仓根归属证明的通道优先,但它不能为未匹配的入口提供证明。
172
+ legacy = evidence?.owners.size ? [...evidence.owners] : installed.map(({ dir }) => dir);
173
+ unbound = evidence?.unbound;
174
+ } catch (err) {
175
+ return channelError(`无法检查遗留 AODW 通道:${err.message}`);
176
+ }
177
+ if (legacy.length > 1) {
178
+ return channelError(`发现多个遗留 AODW 通道(${legacy.join('、')});请先核对入口登记、备份并整理原安装,再选择原通道迁移。`);
179
+ }
180
+ active = legacy[0];
181
+ if (unbound && (!active || active === coreDirName)) {
182
+ return channelError(`无法判定既有 AODW 工具入口所属通道 (${unbound})。迁移旧安装时请用 AODW_CORE_DIR 指定原目录重跑 init;仅在确认没有旧安装、这些文件是项目预置入口时,才使用 init --confirm-new-channel。`);
183
+ }
184
+ }
185
+ if (active && active !== coreDirName) {
186
+ return channelError(`仓根已有活动 AODW 通道 ${active}(请求 ${coreDirName})。请设置 AODW_CORE_DIR 为 ${active};切换前备份项目文件并用原通道卸载,若目录已丢失先从备份恢复。`);
187
+ }
188
+ return { ok: true, markerPath: marker.exists ? marker.absPath : null, entriesPending };
189
+ }
190
+
191
+ function channelMarkerBytes(coreDirName, pending = false) {
192
+ const state = { schema_version: 1, core_dir: coreDirName };
193
+ if (pending) state.entries_pending = true;
194
+ return Buffer.from(`${JSON.stringify(state)}\n`);
195
+ }
196
+
197
+ // 登记更新期间即使旧锁和旧登记仍完整,verify 也不能把未完成安装判为通过。
198
+ function setEntryInstallPending(projectRoot, coreDirName, pending) {
199
+ const absPath = path.join(projectRoot, CHANNEL_MARKER);
200
+ replaceFileEntry(absPath, channelMarkerBytes(coreDirName, pending), fs.lstatSync(absPath).mode & 0o7777);
201
+ }
202
+
203
+ export function claimProjectChannel(projectRoot, coreDirName, options) {
204
+ const check = checkProjectChannel(projectRoot, coreDirName, options);
205
+ if (!check.ok || check.markerPath) return check;
206
+ try {
207
+ fs.writeFileSync(path.join(projectRoot, CHANNEL_MARKER), channelMarkerBytes(coreDirName), { flag: 'wx' });
208
+ } catch (err) {
209
+ return channelError(`无法写入通道标记 ${CHANNEL_MARKER}:${err.message}`);
210
+ }
211
+ return check;
212
+ }
213
+
214
+ export const ENTRIES_SCHEMA_VERSION = 1;
215
+ const SHA256_RE = /^[0-9a-f]{64}$/;
216
+ // 仅 dev_env=orca 时保留的引用块。
217
+ const ORCA_BLOCK_RE = /<!-- AODW_ORCA_START -->\n([\s\S]*?)<!-- AODW_ORCA_END -->\n/;
218
+
219
+ function entryAbsPath(projectRoot, rel) {
220
+ return path.join(projectRoot, ...rel.split('/'));
221
+ }
222
+
223
+ function digest(data) {
224
+ return crypto.createHash('sha256').update(data).digest('hex');
225
+ }
226
+
227
+ function isOwn(object, key) {
228
+ return Object.prototype.hasOwnProperty.call(object, key);
229
+ }
230
+
231
+ function isDigestMap(value) {
232
+ return Boolean(value) && typeof value === 'object' && !Array.isArray(value) &&
233
+ Object.values(value).every((hash) => typeof hash === 'string' && SHA256_RE.test(hash));
234
+ }
235
+
236
+ // 读入口登记(逐段校验无符号链接且位于仓内)。没有登记返回 null;存在但非法或越界时返回说明字符串。
237
+ function readRecord(projectRoot, realProjectRoot, coreDirName) {
238
+ const dirCheck = validateCoreDirName(coreDirName);
239
+ if (!dirCheck.ok) return dirCheck.reason;
240
+ const rel = `${coreDirName}/${ENTRIES_FILENAME}`;
241
+ const safe = resolveSafeFileInDir(projectRoot, realProjectRoot, rel, { rejectSymlinks: true });
242
+ if (!safe.ok) {
243
+ return safe.code === 'missing' ? null : `${rel} 无法读取(${safe.reason})`;
244
+ }
245
+ let record;
246
+ try {
247
+ record = JSON.parse(fs.readFileSync(safe.absPath, 'utf8'));
248
+ } catch (err) {
249
+ return `${rel} 不是合法 JSON: ${err?.message || String(err)}`;
250
+ }
251
+ if (!record || typeof record !== 'object' || Array.isArray(record) ||
252
+ record.schema_version !== ENTRIES_SCHEMA_VERSION || !isDigestMap(record.entries)) {
253
+ return `${rel} 结构非法(需要 schema_version=${ENTRIES_SCHEMA_VERSION} 与 entries 路径→SHA-256 映射)`;
254
+ }
255
+ return record;
256
+ }
257
+
258
+ function writeRecord(projectRoot, coreDirName, entries) {
259
+ const absPath = entryAbsPath(projectRoot, `${coreDirName}/${ENTRIES_FILENAME}`);
260
+ fs.mkdirSync(path.dirname(absPath), { recursive: true });
261
+ const record = { schema_version: ENTRIES_SCHEMA_VERSION, entries };
262
+ const mode = fs.lstatSync(absPath, { throwIfNoEntry: false })?.mode ?? (0o666 & ~process.umask());
263
+ replaceFileEntry(absPath, Buffer.from(`${JSON.stringify(record, null, 2)}\n`), mode & 0o7777);
264
+ }
265
+
266
+ function rollbackUnrecordedEntries(projectRoot, created, updated, errors) {
267
+ // 只回退本轮 wx 创建的文件以及此前摘要已验证的旧登记入口。
268
+ for (const { rel, previous, mode } of [...created.map(rel => ({ rel })), ...updated]) {
269
+ const absPath = entryAbsPath(projectRoot, rel);
270
+ try {
271
+ if (previous) replaceFileEntry(absPath, previous, mode);
272
+ else fs.unlinkSync(absPath);
273
+ } catch (err) {
274
+ if (!err.syscall) throw err;
275
+ errors.push(`无法撤回本轮入口 ${rel}:${err.message};请备份并人工核对该入口后再重跑 init`);
276
+ }
277
+ }
278
+ }
279
+
280
+ function readEntryTemplate(sourceAdapters, templateRel) {
281
+ return fs.readFileSync(path.join(sourceAdapters, ...templateRel.split('/')), 'utf8');
282
+ }
283
+
284
+ // 模板只做两处替换:通道目录名,以及仅 dev_env=orca 时保留的 Orca 引用块。
285
+ export function renderEntryTemplate(template, { coreDirName, devEnv = 'none' } = {}) {
286
+ return template
287
+ .replace(ORCA_BLOCK_RE, (_, block) => (devEnv === 'orca' ? block : ''))
288
+ .replaceAll(CORE_TOKEN, () => coreDirName);
289
+ }
290
+
291
+ // init 会写入的仓根路径:选中的入口与登记文件。供写前边界检查使用。
292
+ export function entryWriteTargets(coreDirName, extras = []) {
293
+ const wanted = [...STANDARD_ENTRIES, ...extras.map((name) => OPTIONAL_ENTRIES[name]).filter(Boolean)];
294
+ return [...wanted.map(([rel]) => rel), `${coreDirName}/${ENTRIES_FILENAME}`];
295
+ }
296
+
297
+ /**
298
+ * 安装入口。所有权规则:
299
+ * - 所有权只来自本次确实创建,或已有可信登记且当前字节仍等于登记摘要;
300
+ * - 已有但未登记的文件(即使字节恰好与模板相同)或生成后被改过的文件,一律视为项目自有,原样保留且不认领,--force 也不覆盖;
301
+ * - 写入集合与登记文件先过写前边界(任何已存在的路径段是符号链接或通道目录越界就整体拒绝);
302
+ * - 登记文件损坏时按没有登记处理并重建,此时既有入口全部按项目自有保留,不认领。
303
+ */
304
+ export function syncToolEntries(projectRoot, { coreDirName, sourceAdapters = SOURCE_ADAPTERS, devEnv = 'none', extras = [] } = {}) {
305
+ const dirCheck = validateEntryCoreDirName(coreDirName);
306
+ if (!dirCheck.ok) return { ok: false, code: 'boundary', errors: [dirCheck.reason] };
307
+ const wanted = [...STANDARD_ENTRIES, ...extras.map((name) => OPTIONAL_ENTRIES[name]).filter(Boolean)];
308
+ const boundary = assertSafeWriteTargets(projectRoot, entryWriteTargets(coreDirName, extras));
309
+ if (!boundary.ok) return { ok: false, code: 'boundary', errors: boundary.errors };
310
+ const channel = claimProjectChannel(projectRoot, coreDirName);
311
+ if (!channel.ok) return { ...channel, code: 'boundary' };
312
+
313
+ const realProjectRoot = fs.realpathSync(projectRoot);
314
+ const record = readRecord(projectRoot, realProjectRoot, coreDirName);
315
+ const warnings = [];
316
+ if (typeof record === 'string') warnings.push(`${record};本次按没有登记处理并重建`);
317
+ const registered = record && typeof record !== 'string' ? record.entries : {};
318
+
319
+ const entries = Object.fromEntries(Object.entries(registered).filter(([rel]) => MANAGED_PATHS.has(rel)));
320
+ const created = [];
321
+ const updated = [];
322
+ const kept = [];
323
+ const errors = [];
324
+ try {
325
+ setEntryInstallPending(projectRoot, coreDirName, true);
326
+ } catch (err) {
327
+ if (!err.syscall) throw err;
328
+ return { ok: false, code: 'io', errors: [`无法保存入口安装状态,未写入任何工具入口:${err.message}`] };
329
+ }
330
+ try {
331
+ for (const [rel, templateRel] of wanted) {
332
+ const template = readEntryTemplate(sourceAdapters, templateRel);
333
+ const content = Buffer.from(renderEntryTemplate(template, { coreDirName, devEnv }), 'utf8');
334
+ const hash = digest(content);
335
+ const walk = walkRealPath(projectRoot, rel, { allowMissing: true });
336
+ if (!walk.ok) {
337
+ errors.push(`入口路径异常 (${rel}): ${walk.reason}`);
338
+ break;
339
+ }
340
+
341
+ if (!walk.exists) {
342
+ const absPath = entryAbsPath(projectRoot, rel);
343
+ fs.mkdirSync(path.dirname(absPath), { recursive: true });
344
+ fs.writeFileSync(absPath, content, { flag: 'wx' });
345
+ created.push(rel);
346
+ entries[rel] = hash;
347
+ continue;
348
+ }
349
+
350
+ if (!walk.stat.isFile() || !isInsideDir(realProjectRoot, walk.realPath)) {
351
+ delete entries[rel];
352
+ kept.push(rel);
353
+ continue;
354
+ }
355
+
356
+ const previous = fs.readFileSync(walk.absPath);
357
+ const currentHash = digest(previous);
358
+ // 未登记的既有文件即使字节恰好与模板相同,仍属项目自有,不认领。
359
+ const ownedByAodw = isOwn(registered, rel) && currentHash === registered[rel];
360
+ if (!ownedByAodw) {
361
+ delete entries[rel];
362
+ kept.push(rel);
363
+ continue;
364
+ }
365
+ if (currentHash !== hash) {
366
+ const mode = walk.stat.mode & 0o7777;
367
+ replaceFileEntry(walk.absPath, content, mode);
368
+ updated.push({ rel, previous, mode });
369
+ }
370
+ entries[rel] = hash;
371
+ }
372
+
373
+ // 未选的可选入口不写入。仍匹配的登记(以及缺失待修复的登记)不因本次选择而丢失。
374
+ for (const [rel] of Object.values(OPTIONAL_ENTRIES)) {
375
+ if (!isOwn(entries, rel) || wanted.some(([entry]) => entry === rel)) continue;
376
+ const safe = resolveSafeFileInDir(projectRoot, realProjectRoot, rel, { rejectSymlinks: true });
377
+ if (safe.ok && digest(fs.readFileSync(safe.absPath)) !== entries[rel]) {
378
+ delete entries[rel];
379
+ kept.push(rel);
380
+ }
381
+ }
382
+ } catch (err) {
383
+ if (!err.syscall) throw err;
384
+ errors.push(err.message);
385
+ }
386
+
387
+ // 壳写失败时登记已成功写入的入口;登记提交本身失败时回退写入,保留待修复状态。
388
+ try {
389
+ writeRecord(projectRoot, coreDirName, entries);
390
+ } catch (err) {
391
+ if (!err.syscall) throw err;
392
+ errors.push(`入口登记写入失败:${err.message}`);
393
+ rollbackUnrecordedEntries(projectRoot, created, updated, errors);
394
+ return { ok: false, code: 'io', errors };
395
+ }
396
+ if (errors.length) {
397
+ if (created.length || updated.length) errors.push(`本轮已登记:${[...created, ...updated.map(({ rel }) => rel)].join('、')}`);
398
+ return { ok: false, code: 'io', errors };
399
+ }
400
+ try {
401
+ setEntryInstallPending(projectRoot, coreDirName, false);
402
+ } catch (err) {
403
+ if (!err.syscall) throw err;
404
+ return { ok: false, code: 'io', errors: [`无法完成入口安装状态提交:${err.message}`] };
405
+ }
406
+ return { ok: true, created, updated: updated.map(({ rel }) => rel), kept, warnings };
407
+ }
408
+
409
+ // 校验卸载目标通道目录:拒绝越界路径、绝对路径、符号链接及非目录占位。
410
+ export function validateUninstallCore(projectRoot, coreDirName) {
411
+ const channel = checkProjectChannel(projectRoot, coreDirName);
412
+ if (!channel.ok) return channel;
413
+ const realProjectRoot = fs.realpathSync(projectRoot);
414
+ const walk = walkRealPath(projectRoot, coreDirName, { allowMissing: true });
415
+ if (!walk.ok) {
416
+ return { ok: false, errors: [`拒绝卸载通道目录 (${coreDirName}): ${walk.reason}`] };
417
+ }
418
+ if (walk.exists) {
419
+ if (!walk.stat.isDirectory()) {
420
+ return { ok: false, errors: [`拒绝卸载通道目录 (${coreDirName}): 目标不是普通目录`] };
421
+ }
422
+ if (!isInsideDir(realProjectRoot, walk.realPath)) {
423
+ return { ok: false, errors: [`拒绝卸载通道目录 (${coreDirName}): 真实路径越出项目根目录`] };
424
+ }
425
+ }
426
+ return { ...channel, exists: walk.exists, absPath: walk.absPath };
427
+ }
428
+
429
+ // 卸载入口:只移除登记在案、落点在仓内(逐段无符号链接)且字节未变的入口;
430
+ // 其余入口(项目自有、被修改、或路径上出现符号链接)原样保留并报告。
431
+ export function removeToolEntries(projectRoot, coreDirName) {
432
+ const realProjectRoot = fs.realpathSync(projectRoot);
433
+ const record = readRecord(projectRoot, realProjectRoot, coreDirName);
434
+ const warnings = [];
435
+ if (typeof record === 'string') warnings.push(`${record};无法确认入口归属,保留所有入口文件`);
436
+ const registered = record && typeof record !== 'string' ? record.entries : {};
437
+ const removed = [];
438
+ const blocked = new Set();
439
+
440
+ for (const [rel, expected] of Object.entries(registered)) {
441
+ if (!MANAGED_PATHS.has(rel)) continue;
442
+ const safe = resolveSafeFileInDir(projectRoot, realProjectRoot, rel, { rejectSymlinks: true });
443
+ if (!safe.ok) {
444
+ if (safe.code === 'symlink') {
445
+ blocked.add(rel);
446
+ warnings.push(`拒绝卸载入口 (${rel}): ${safe.reason},已保留未触碰目标`);
447
+ }
448
+ continue;
449
+ }
450
+ if (digest(fs.readFileSync(safe.absPath)) === expected) {
451
+ fs.unlinkSync(safe.absPath);
452
+ removed.push(rel);
453
+ }
454
+ }
455
+
456
+ const kept = KNOWN_TOOL_ENTRIES.filter((rel) => {
457
+ if (removed.includes(rel)) return false;
458
+ if (blocked.has(rel)) return true;
459
+ const walk = walkRealPath(projectRoot, rel, { allowMissing: true });
460
+ return walk.ok ? walk.exists : false;
461
+ });
462
+ return { removed, kept, warnings };
463
+ }
464
+
465
+ // 完整卸载:先校验通道目录路径边界,再按归属清理入口薄壳并删除通道目录。
466
+ export function uninstallProject(projectRoot, coreDirName) {
467
+ const check = validateUninstallCore(projectRoot, coreDirName);
468
+ if (!check.ok) return { ok: false, code: 'boundary', errors: check.errors, removed: [], kept: [], warnings: [] };
469
+
470
+ const entries = removeToolEntries(projectRoot, coreDirName);
471
+ if (check.exists) fs.rmSync(check.absPath, { recursive: true, force: true });
472
+ if (check.markerPath) fs.unlinkSync(check.markerPath);
473
+ return { ok: true, code: 'ok', removedCore: check.exists, ...entries, errors: [] };
474
+ }
475
+
476
+ // verify 用:验证登记本身,条目路径的 IO 和引用检查交给同一个逐入口扫描。
477
+ export function verifyEntryRegistration(projectRoot, realProjectRoot, coreDirName) {
478
+ const registered = new Set();
479
+ const errors = [];
480
+ const result = { registered, errors };
481
+ if (!validateCoreDirName(coreDirName).ok) return result; // 完整性锁检查已报告该目录错误
482
+ const channel = checkProjectChannel(projectRoot, coreDirName);
483
+ if (!channel.ok) return { registered, errors: channel.errors };
484
+ const record = readRecord(projectRoot, realProjectRoot, coreDirName);
485
+ if (typeof record === 'string') {
486
+ errors.push(record);
487
+ return result;
488
+ }
489
+ if (!record) {
490
+ if (channel.markerPath) {
491
+ errors.push(`入口登记缺失 (${coreDirName}/${ENTRIES_FILENAME}):安装未完成或登记被移除,请用原通道重跑 npx aodw-skill init`);
492
+ }
493
+ return result;
494
+ }
495
+ if (!channel.markerPath) {
496
+ errors.push(`缺少仓根通道标记 ${CHANNEL_MARKER}:请确认既有通道并用原通道重跑 npx aodw-skill init`);
497
+ return result;
498
+ }
499
+ if (channel.entriesPending || record.incomplete) {
500
+ errors.push(`入口安装未完成 (${coreDirName}/${ENTRIES_FILENAME}):修复路径或权限后用原通道重跑 npx aodw-skill init`);
501
+ }
502
+ for (const rel of Object.keys(record.entries)) {
503
+ if (MANAGED_PATHS.has(rel)) registered.add(rel);
504
+ }
505
+ return result;
506
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aodw-skill",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
4
4
  "description": "Next-channel CLI tool to scaffold AODW in your project",
5
5
  "main": "bin/aodw.js",
6
6
  "files": [
@@ -12,9 +12,15 @@
12
12
  "aodw-skill": "bin/aodw.js"
13
13
  },
14
14
  "scripts": {
15
- "test": "node test/template-assets.test.mjs",
15
+ "test": "node test/template-assets.test.mjs && node test/path-guard.test.mjs && node test/verify-lock.test.mjs && node test/verify-entries.test.mjs && node test/verify-core-io.test.mjs && node test/tool-entries.test.mjs && node test/update-upstream.test.mjs && node test/release.test.mjs && node test/rel-plan.test.mjs",
16
+ "test:path-guard": "node test/path-guard.test.mjs",
17
+ "test:verify": "node test/verify-lock.test.mjs && node test/verify-entries.test.mjs && node test/verify-core-io.test.mjs",
18
+ "test:update": "node test/update-upstream.test.mjs",
19
+ "test:release": "node test/release.test.mjs",
20
+ "test:entries": "node test/tool-entries.test.mjs",
16
21
  "test:gates": "bash ../templates/.aodw-next/tools/rt-guard.sh --self-test",
17
22
  "test:skills": "bash ../templates/.aodw-next/tools/fixtures/run-skill-fixtures.sh",
23
+ "test:rt-guard-doc": "/bin/bash test/e2e-rt-guard-ci-doc.sh",
18
24
  "pack:check": "npm pack --dry-run"
19
25
  },
20
26
  "keywords": [
@@ -1,71 +0,0 @@
1
- # AODW-Next Kernel Loader
2
- # 版本: 4.0.0 (Unified)
3
-
4
- ## 0. 语言要求 (Language Requirement)
5
-
6
- **中文交流 (Chinese Communication)**:所有回复、思考过程、任务清单、文档内容均须使用中文。
7
-
8
- ---
9
-
10
- 你是一个 **AODW-Next (AI 编排开发工作流) 协作 Agent**。
11
-
12
- ## 1. 核心指令 (The Prime Directive)
13
- 你 **必须** 在开始任何任务前,优先读取并遵循以下 **Kernel (宪章)** 文件:
14
-
15
- - {{REF_PREFIX}}.aodw-next/01-core/aodw-constitution.md
16
-
17
- **注意**:
18
- - 该文件是你行为的最高准则。
19
- - 该文件包含了所有阶段的 **Context Loading Directives (上下文加载指令)**。
20
- - 你必须根据宪章的指示,在不同阶段**按需加载**其他规则文件。
21
- - ⚠️ **Token 优化原则**:只在需要时加载相关文件,避免一次性加载所有文件。详见 `.aodw-next/01-core/aodw-constitution.md` 第 6 节"文件加载策略"。
22
-
23
- ## 2. 命令索引 (Command Index)
24
-
25
- 当用户表达以下意图时,参考对应的核心规则:
26
-
27
- | 用户意图 | 核心规则 | 说明 |
28
- |---------|---------|------|
29
- | **创建新 RT** | {{REF_PREFIX}}.aodw-next/02-workflow/rt-manager.md (Sec 1-4, 8-9)<br/>{{REF_PREFIX}}.aodw-next/01-core/ai-knowledge-rules.md (Sec 3.1)<br/>{{REF_PREFIX}}.aodw-next/01-core/ai-interaction-rules.md (Sec 1-4) | 生成 RT-ID,创建目录,Intake 流程 |
30
- | **选择模式** | {{REF_PREFIX}}.aodw-next/02-workflow/rt-manager.md (Sec 5)<br/>{{REF_PREFIX}}.aodw-next/02-workflow/spec-full-profile.md<br/>{{REF_PREFIX}}.aodw-next/02-workflow/spec-lite-profile.md | 决策 Spec-Full/Spec-Lite,创建分支 |
31
- | **工具初始化** | {{REF_PREFIX}}.aodw-next/05-tooling/ai-tools-init-rules.md | 初始化开发工具(ESLint、Prettier、Ruff、Black 等) |
32
- | **项目概览初始化** | {{REF_PREFIX}}.aodw-next/01-core/ai-project-overview-rules.md | 初始化或完善项目概览信息(技术栈、架构、模块等) |
33
- | **分析阶段** | {{REF_PREFIX}}.aodw-next/03-standards/ai-coding-rules.md (Sec 2-3)<br/>{{REF_PREFIX}}.aodw-next/01-core/ai-knowledge-rules.md (Sec 3.4) | 影响分析、不变量检查,更新 impact.md, invariants.md |
34
- | **实现阶段** | {{REF_PREFIX}}.aodw-next/03-standards/ai-coding-rules.md (Sec 6)<br/>{{REF_PREFIX}}.aodw-next/01-core/ai-knowledge-rules.md (Sec 3.5)<br/>{{REF_PREFIX}}.aodw-next/01-core/module-doc-rules.md | 代码实现、测试编写、模块文档更新 |
35
- | **验证阶段** | {{REF_PREFIX}}.aodw-next/01-core/ai-knowledge-rules.md (Sec 5)<br/>{{REF_PREFIX}}.aodw-next/01-core/test-discipline.md | 验证文档与代码一致,检查 RT 完整性;按判据纪律写验收判据(判据 / AI 评审 / 读产出三格) |
36
- | **CSF 审查** | {{REF_PREFIX}}.aodw-next/01-core/csf-thinking-framework.md | 执行 CSF 思维框架审查(以终为始、结构化分解、关键要素识别等) |
37
- | **执行需求审计** | {{REF_PREFIX}}.aodw-next/04-auditors/aodw-requirement-auditor-rules.md | 调用需求阶段审计官,对需求文档进行审计(自动触发或手动触发) |
38
- | **执行开发审计** | {{REF_PREFIX}}.aodw-next/04-auditors/aodw-development-auditor-rules.md | 调用开发阶段审计官,对代码进行审计(自动触发或手动触发) |
39
- | **执行综合审计** | {{REF_PREFIX}}.aodw-next/04-auditors/aodw-full-auditor-rules.md | 调用综合审计官,执行全流程审计(需求 + 开发) |
40
- | **完成 RT** | {{REF_PREFIX}}.aodw-next/01-core/git-discipline.md<br/>{{REF_PREFIX}}.aodw-next/01-core/ai-knowledge-rules.md (Sec 9) | 合并分支,知识蒸馏,更新状态 |
41
- | **打开 RT** | {{REF_PREFIX}}.aodw-next/02-workflow/rt-manager.md | 打开已有 RT,加载上下文 |
42
- | **流程控制** | {{REF_PREFIX}}.aodw-next/01-core/ai-interaction-rules.md (Sec 5) | 暂停/恢复流程 |
43
-
44
- ## 3. RT 生命周期
45
-
46
- ```
47
- 创建 → 立项 → 决策 → 分析 → 实现 → 验证 → 完成
48
- ```
49
-
50
- 每个阶段对应的核心规则和操作,详见上述命令索引。
51
-
52
- ## 4. 关键检查点
53
-
54
- ### 4.1 分支管理(必须)
55
- - 所有代码修改必须在 feature 分支上进行
56
- - 严禁在 main/master 分支直接修改业务代码
57
- - 在修改代码前必须验证当前分支
58
-
59
- ### 4.2 Plan 批准节点(必须)
60
- - Plan 完成后执行 CSF 审查:Spec-Full 必须执行;Spec-Lite 可选但推荐
61
- - Plan 批准前通过 CSF 审查:Spec-Full 必须通过;Spec-Lite 可选但推荐
62
- - 严禁未获批准前开始修改代码
63
-
64
- ### 4.3 提交前确认(必须)
65
- - 代码修改完成后,必须展示 git status 和关键 diff
66
- - 询问用户"修改已完成,是否提交?"
67
- - 严禁未获用户确认前直接 Commit
68
- - **Autopilot 例外**:当 RT `meta.yaml` 含 `autopilot: true` 且 GRV 已用户确认、`phase=implementing` 时,由机械 Gate(tests/lint/guard)替代本条「询问是否提交」;轮末用 `CONTINUE`/`DONE`/`blocked` + `rt-grv-continue.sh` 续跑,禁止停问是否继续。详见 `autopilot-protocol.md` 与 Cursor 规则 `aodw-autopilot-continue`。
69
-
70
- ## 5. 兜底机制
71
- 如果你无法读取 {{REF_PREFIX}}.aodw-next/01-core/aodw-constitution.md,请立即停止并要求用户提供该文件。
@@ -1,37 +0,0 @@
1
- # Cursor Commands Directory
2
-
3
- This directory is for **your project-specific commands**.
4
-
5
- ## About This Directory
6
-
7
- Cursor allows you to define custom commands in `.cursor/commands/` directory.
8
- These commands can be invoked by the AI to help with project-specific tasks.
9
-
10
- ## AODW Commands
11
-
12
- **AODW does not provide default commands here.**
13
-
14
- AODW functionality is managed through the **rules system**:
15
- - See `.cursor/rules/aodw.mdc` for the AODW Kernel Loader
16
- - The rule file contains a command index table that references core AODW rules
17
-
18
- ## Adding Your Own Commands
19
-
20
- You can create project-specific commands here, for example:
21
- - Deployment workflows
22
- - Testing procedures
23
- - Code generation scripts
24
- - Database migration helpers
25
-
26
- Each command should be a markdown file describing what the AI should do.
27
-
28
- ## Example Structure
29
-
30
- ```
31
- .cursor/commands/
32
- ├── README.md (this file)
33
- ├── deploy.md (your deployment command)
34
- └── test.md (your testing command)
35
- ```
36
-
37
- Refer to Cursor documentation for command file format.