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,343 @@
1
+ import crypto from 'node:crypto';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import {
5
+ LOCK_FILENAME,
6
+ NON_UPSTREAM_TOP_DIRS,
7
+ NON_UPSTREAM_TOP_FILES,
8
+ assertSafeWriteTargets,
9
+ isInsideDir,
10
+ isProtectedCorePath,
11
+ isProtectedIdentity,
12
+ mapProtectedCoreIdentities,
13
+ onDiskCorePath,
14
+ protectedCoreIdentities,
15
+ planReleaseIdentities,
16
+ refusalReason,
17
+ replaceFileEntry,
18
+ resolveOnDiskCorePath,
19
+ volumeIgnoresCase,
20
+ resolveSafeFileInDir,
21
+ traceCoreEntry,
22
+ validateCoreDirName,
23
+ validateLockRelPath,
24
+ validateRelativePosixPath,
25
+ walkRealPath,
26
+ } from './path-guard.js';
27
+
28
+ export {
29
+ LOCK_FILENAME,
30
+ NON_UPSTREAM_TOP_DIRS,
31
+ NON_UPSTREAM_TOP_FILES,
32
+ assertSafeWriteTargets,
33
+ isInsideDir,
34
+ isProtectedCorePath,
35
+ isProtectedIdentity,
36
+ onDiskCorePath,
37
+ protectedCoreIdentities,
38
+ planReleaseIdentities,
39
+ replaceFileEntry,
40
+ resolveOnDiskCorePath,
41
+ volumeIgnoresCase,
42
+ resolveSafeFileInDir,
43
+ traceCoreEntry,
44
+ validateCoreDirName,
45
+ validateLockRelPath,
46
+ walkRealPath,
47
+ };
48
+
49
+ export const LOCK_SCHEMA_VERSION = 1;
50
+
51
+ const IGNORED_UNTRACKED_NAMES = new Set(['.DS_Store', '__pycache__']);
52
+ const SHA256_RE = /^[0-9a-f]{64}$/;
53
+
54
+ function compareCodePoints(a, b) {
55
+ return a < b ? -1 : a > b ? 1 : 0;
56
+ }
57
+
58
+ export function sha256File(absPath) {
59
+ return crypto.createHash('sha256').update(fs.readFileSync(absPath)).digest('hex');
60
+ }
61
+
62
+ export function collectUpstreamFiles(sourceCore, excludedAbsPaths = new Set()) {
63
+ const results = [];
64
+ function walk(dir, relPrefix) {
65
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
66
+ const abs = path.join(dir, entry.name);
67
+ if (excludedAbsPaths.has(abs)) continue;
68
+ const relPosix = relPrefix ? `${relPrefix}/${entry.name}` : entry.name;
69
+ if (isProtectedCorePath(relPosix)) continue;
70
+ if (entry.isDirectory()) walk(abs, relPosix);
71
+ else if (entry.isFile()) results.push(relPosix);
72
+ }
73
+ }
74
+ walk(sourceCore, '');
75
+ results.sort(compareCodePoints);
76
+ return results;
77
+ }
78
+
79
+ export function buildAndWriteLock(targetCore, relPaths, { version = '', devEnv = 'none' } = {}) {
80
+ const coreStat = fs.lstatSync(targetCore);
81
+ if (coreStat.isSymbolicLink() || !coreStat.isDirectory()) {
82
+ throw new Error(`核心目录必须是普通目录,拒绝生成锁: ${targetCore}`);
83
+ }
84
+ const realTargetCore = fs.realpathSync(targetCore);
85
+
86
+ const lockCheck = walkRealPath(targetCore, LOCK_FILENAME, { allowMissing: true });
87
+ if (!lockCheck.ok || (lockCheck.exists && !lockCheck.stat.isFile())) {
88
+ throw new Error(`拒绝写入锁文件 ${LOCK_FILENAME}: ${lockCheck.reason || '目标不是普通文件'}`);
89
+ }
90
+
91
+ const sorted = [...relPaths].sort(compareCodePoints);
92
+ const identities = protectedCoreIdentities(targetCore);
93
+ const entryOwners = new Map(); // 目录项的实际身份 -> 锁内路径
94
+ const files = {};
95
+ for (const rel of sorted) {
96
+ const lex = validateLockRelPath(rel);
97
+ if (!lex.ok) throw new Error(`非法锁路径 ${rel}: ${lex.reason}`);
98
+ const safe = resolveSafeFileInDir(targetCore, realTargetCore, rel, { rejectSymlinks: true });
99
+ if (!safe.ok) throw new Error(`上游文件不可安全读取 (${rel}): ${safe.reason}`);
100
+ // 按目录项的实际身份:指向保护路径的键、与另一条键是同一个目录项的键,都不能登记。
101
+ const realPath = onDiskCorePath(targetCore, rel);
102
+ if (isProtectedIdentity(realPath, identities)) throw new Error(`非法锁路径 ${rel}: 指向受保护路径 (${realPath})`);
103
+ if (entryOwners.has(realPath)) throw new Error(`非法锁路径 ${rel}: 与 ${entryOwners.get(realPath)} 是同一个目录项`);
104
+ entryOwners.set(realPath, rel);
105
+ files[rel] = sha256File(safe.absPath);
106
+ }
107
+
108
+ const lock = {
109
+ schema_version: LOCK_SCHEMA_VERSION,
110
+ aodw_version: String(version),
111
+ dev_env: devEnv === 'orca' ? 'orca' : 'none',
112
+ algorithm: 'sha256',
113
+ files,
114
+ };
115
+ // 同目录临时文件 + rename:已有锁若与别的名字是硬链接,那个名字保持原字节。
116
+ const lockMode = lockCheck.exists ? lockCheck.stat.mode & 0o777 : 0o666 & ~process.umask();
117
+ replaceFileEntry(
118
+ path.join(targetCore, LOCK_FILENAME),
119
+ Buffer.from(`${JSON.stringify(lock, null, 2)}\n`, 'utf8'),
120
+ lockMode,
121
+ );
122
+ return lock;
123
+ }
124
+
125
+ export function hasExistingUpstreamFiles(coreDir) {
126
+ if (!fs.existsSync(coreDir)) return false;
127
+ function scan(dir, relPrefix) {
128
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
129
+ if (IGNORED_UNTRACKED_NAMES.has(entry.name)) continue;
130
+ const relPosix = relPrefix ? `${relPrefix}/${entry.name}` : entry.name;
131
+ if (isProtectedCorePath(relPosix)) continue;
132
+ if (entry.isDirectory()) {
133
+ if (scan(path.join(dir, entry.name), relPosix)) return true;
134
+ } else {
135
+ return true;
136
+ }
137
+ }
138
+ return false;
139
+ }
140
+ return scan(coreDir, '');
141
+ }
142
+
143
+ function collectUntrackedFiles(coreDir, entryOwners, identities, inspect) {
144
+ const untracked = [];
145
+ function walk(dir, relPrefix) {
146
+ const names = inspect(relPrefix, () => fs.readdirSync(dir));
147
+ if (names === undefined) return;
148
+ for (const name of names) {
149
+ if (IGNORED_UNTRACKED_NAMES.has(name)) continue;
150
+ const relPosix = relPrefix ? `${relPrefix}/${name}` : name;
151
+ // readdir 给出盘面拼写;先排除保护身份,再检查目录类型,避免进入保护层或跟随符号链接。
152
+ if (isProtectedCorePath(relPosix) || isProtectedIdentity(relPosix, identities) ||
153
+ !validateRelativePosixPath(relPosix).ok) continue;
154
+ const abs = path.join(dir, name);
155
+ const entry = inspect(relPosix, () => fs.lstatSync(abs));
156
+ if (entry === undefined) continue;
157
+ if (entry.isDirectory()) {
158
+ walk(abs, relPosix);
159
+ continue;
160
+ }
161
+ if (!entryOwners.has(relPosix)) untracked.push(relPosix);
162
+ }
163
+ }
164
+ walk(coreDir, '');
165
+ untracked.sort(compareCodePoints);
166
+ return untracked;
167
+ }
168
+
169
+ export function verifyCoreLock(projectRoot, coreDirName = '.aodw-next', { scanUntracked = true } = {}) {
170
+ const result = {
171
+ ok: false,
172
+ status: 'ok',
173
+ lock: null,
174
+ modified: [],
175
+ missing: [],
176
+ invalidPaths: [],
177
+ boundaryErrors: [],
178
+ warnings: [],
179
+ errors: [],
180
+ };
181
+
182
+ const nameCheck = validateCoreDirName(coreDirName);
183
+ if (!nameCheck.ok) {
184
+ result.status = 'invalid_core';
185
+ result.errors.push(nameCheck.reason);
186
+ return result;
187
+ }
188
+
189
+ function reportBoundary(rel, reason) {
190
+ result.boundaryErrors.push({ path: rel || '.', reason });
191
+ result.errors.push(`核心路径无法检查 (${coreDirName}/${rel}): ${reason}`);
192
+ }
193
+ function inspect(rel, read) {
194
+ try {
195
+ return read();
196
+ } catch (err) {
197
+ const reason = refusalReason(err);
198
+ if (reason === null) throw err;
199
+ reportBoundary(rel, reason);
200
+ return undefined;
201
+ }
202
+ }
203
+
204
+ const realProjectRoot = inspect('', () => fs.realpathSync(projectRoot));
205
+ if (realProjectRoot === undefined) {
206
+ result.status = 'invalid_core';
207
+ return result;
208
+ }
209
+ const coreWalk = walkRealPath(projectRoot, coreDirName);
210
+ if (!coreWalk.ok) {
211
+ result.status = coreWalk.code === 'missing' ? 'missing_core' : 'invalid_core';
212
+ if (coreWalk.code === 'error') reportBoundary('', coreWalk.reason);
213
+ else result.errors.push(
214
+ coreWalk.code === 'missing'
215
+ ? `未找到 ${coreDirName}/ 目录,请先运行 npx aodw-skill init`
216
+ : `${coreDirName}/ 必须是仓库内的普通目录(${coreWalk.reason})`,
217
+ );
218
+ return result;
219
+ }
220
+ if (!coreWalk.stat.isDirectory() || !isInsideDir(realProjectRoot, coreWalk.realPath)) {
221
+ result.status = 'invalid_core';
222
+ result.errors.push(`${coreDirName}/ 必须是仓库内的普通目录且不得越出项目根目录`);
223
+ return result;
224
+ }
225
+
226
+ const coreDir = coreWalk.absPath;
227
+ const realCoreDir = coreWalk.realPath;
228
+ const lockWalk = walkRealPath(coreDir, LOCK_FILENAME);
229
+ if (!lockWalk.ok) {
230
+ result.status = lockWalk.code === 'missing' ? 'missing_lock' : 'invalid_lock';
231
+ if (lockWalk.code === 'error') reportBoundary(LOCK_FILENAME, lockWalk.reason);
232
+ else result.errors.push(
233
+ lockWalk.code === 'missing'
234
+ ? `缺少 ${coreDirName}/${LOCK_FILENAME}(旧版安装或锁文件已删除);拒绝将现有文件自动认证为上游`
235
+ : `${coreDirName}/${LOCK_FILENAME} 必须是 ${coreDirName}/ 内的普通文件(${lockWalk.reason})`,
236
+ );
237
+ return result;
238
+ }
239
+ if (!lockWalk.stat.isFile() || !isInsideDir(realCoreDir, lockWalk.realPath)) {
240
+ result.status = 'invalid_lock';
241
+ result.errors.push(`${coreDirName}/${LOCK_FILENAME} 必须是 ${coreDirName}/ 内的普通文件`);
242
+ return result;
243
+ }
244
+
245
+ const rawLock = inspect(LOCK_FILENAME, () => fs.readFileSync(lockWalk.absPath, 'utf8'));
246
+ if (rawLock === undefined) {
247
+ result.status = 'invalid_lock';
248
+ return result;
249
+ }
250
+
251
+ let lock;
252
+ try {
253
+ lock = JSON.parse(rawLock);
254
+ } catch (err) {
255
+ if (!(err instanceof SyntaxError)) throw err;
256
+ result.status = 'invalid_lock';
257
+ result.errors.push(`${coreDirName}/${LOCK_FILENAME} 不是合法 JSON: ${err.message}`);
258
+ return result;
259
+ }
260
+
261
+ if (
262
+ !lock || typeof lock !== 'object' || Array.isArray(lock) ||
263
+ lock.schema_version !== LOCK_SCHEMA_VERSION || lock.algorithm !== 'sha256' ||
264
+ !lock.files || typeof lock.files !== 'object' || Array.isArray(lock.files) ||
265
+ Object.keys(lock.files).length === 0
266
+ ) {
267
+ result.status = 'invalid_lock';
268
+ result.errors.push(`${coreDirName}/${LOCK_FILENAME} 结构非法(需要 schema_version=${LOCK_SCHEMA_VERSION}、algorithm="sha256" 与非空 files)`);
269
+ return result;
270
+ }
271
+
272
+ result.lock = lock;
273
+ const identities = mapProtectedCoreIdentities(name => inspect(name, () => onDiskCorePath(coreDir, name)));
274
+ const identitiesComplete = result.boundaryErrors.length === 0;
275
+ const entryOwners = new Map(); // 目录项的实际身份 -> 锁内路径
276
+ for (const [relPath, expectedHash] of Object.entries(lock.files)) {
277
+ const pathCheck = validateLockRelPath(relPath);
278
+ if (!pathCheck.ok) {
279
+ result.invalidPaths.push({ path: relPath, reason: pathCheck.reason });
280
+ result.errors.push(`锁内路径非法 (${relPath}): ${pathCheck.reason}`);
281
+ continue;
282
+ }
283
+ // 按目录项的实际身份查保护:盘面叫 Project.yaml、06-ProjecT/… 的项目文件,不因为拼写不同就算上游。
284
+ const realPath = inspect(relPath, () => onDiskCorePath(coreDir, relPath));
285
+ if (realPath === undefined) continue;
286
+ if (realPath !== null && isProtectedIdentity(realPath, identities)) {
287
+ const reason = `指向受保护路径 (${realPath})`;
288
+ result.invalidPaths.push({ path: relPath, reason });
289
+ result.errors.push(`锁内路径非法 (${relPath}): ${reason}`);
290
+ continue;
291
+ }
292
+ // 两条锁键落到同一个目录项:后一条读到的是前一条的字节,不能各自算通过。
293
+ if (realPath !== null) {
294
+ if (entryOwners.has(realPath)) {
295
+ const reason = `与 ${entryOwners.get(realPath)} 是同一个目录项 (${realPath})`;
296
+ result.invalidPaths.push({ path: relPath, reason });
297
+ result.errors.push(`锁内路径非法 (${relPath}): ${reason}`);
298
+ continue;
299
+ }
300
+ entryOwners.set(realPath, relPath);
301
+ }
302
+ if (typeof expectedHash !== 'string' || !SHA256_RE.test(expectedHash)) {
303
+ result.invalidPaths.push({ path: relPath, reason: 'SHA-256 摘要格式非法' });
304
+ result.errors.push(`锁内摘要非法 (${relPath}): 必须为 64 位小写十六进制 SHA-256`);
305
+ continue;
306
+ }
307
+
308
+ const resolved = resolveSafeFileInDir(coreDir, realCoreDir, relPath, { rejectSymlinks: true });
309
+ if (!resolved.ok) {
310
+ if (resolved.code === 'missing') {
311
+ result.missing.push(relPath);
312
+ result.errors.push(`上游文件缺失: ${coreDirName}/${relPath}`);
313
+ } else {
314
+ result.boundaryErrors.push({ path: relPath, reason: resolved.reason });
315
+ result.errors.push(`上游文件路径异常 (${coreDirName}/${relPath}): ${resolved.reason}`);
316
+ }
317
+ continue;
318
+ }
319
+
320
+ // 无法确认保护身份时,仍检查路径与缺失,但不能读取可能属于保护层的内容。
321
+ if (!identitiesComplete) continue;
322
+ const actualHash = inspect(relPath, () => sha256File(resolved.absPath));
323
+ if (actualHash === undefined) continue;
324
+ if (actualHash !== expectedHash) {
325
+ result.modified.push({ path: relPath, expected: expectedHash, actual: actualHash });
326
+ result.errors.push(`上游文件已被修改: ${coreDirName}/${relPath}`);
327
+ }
328
+ }
329
+
330
+ if (scanUntracked && identitiesComplete) {
331
+ for (const extra of collectUntrackedFiles(coreDir, entryOwners, identities, inspect)) {
332
+ result.warnings.push(`发现未纳入锁的上游层外加文件: ${coreDirName}/${extra}(建议移至 ${coreDirName}/06-project/)`);
333
+ }
334
+ }
335
+
336
+ if (result.errors.length === 0) {
337
+ result.ok = true;
338
+ result.status = 'ok';
339
+ } else {
340
+ result.status = result.invalidPaths.length > 0 ? 'invalid_lock' : 'drifted';
341
+ }
342
+ return result;
343
+ }