wangchuan 5.0.0 → 5.2.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.
- package/README.md +19 -8
- package/README.zh-CN.md +19 -8
- package/dist/bin/wangchuan.d.ts +10 -7
- package/dist/bin/wangchuan.d.ts.map +1 -1
- package/dist/bin/wangchuan.js +31 -11
- package/dist/bin/wangchuan.js.map +1 -1
- package/dist/src/agents/index.d.ts +5 -0
- package/dist/src/agents/index.d.ts.map +1 -1
- package/dist/src/agents/index.js +32 -0
- package/dist/src/agents/index.js.map +1 -1
- package/dist/src/commands/doctor.d.ts.map +1 -1
- package/dist/src/commands/doctor.js +3 -17
- package/dist/src/commands/doctor.js.map +1 -1
- package/dist/src/commands/init.d.ts.map +1 -1
- package/dist/src/commands/init.js +70 -6
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/commands/key.d.ts.map +1 -1
- package/dist/src/commands/key.js +1 -17
- package/dist/src/commands/key.js.map +1 -1
- package/dist/src/commands/memory.js +44 -2
- package/dist/src/commands/memory.js.map +1 -1
- package/dist/src/commands/pull.js.map +1 -1
- package/dist/src/commands/push.js.map +1 -1
- package/dist/src/commands/snapshot.d.ts.map +1 -1
- package/dist/src/commands/snapshot.js +1 -19
- package/dist/src/commands/snapshot.js.map +1 -1
- package/dist/src/commands/sync.d.ts.map +1 -1
- package/dist/src/commands/sync.js +1 -15
- package/dist/src/commands/sync.js.map +1 -1
- package/dist/src/commands/watch.js.map +1 -1
- package/dist/src/core/config.d.ts.map +1 -1
- package/dist/src/core/config.js +4 -2
- package/dist/src/core/config.js.map +1 -1
- package/dist/src/core/crypto.d.ts +2 -0
- package/dist/src/core/crypto.d.ts.map +1 -1
- package/dist/src/core/crypto.js +10 -2
- package/dist/src/core/crypto.js.map +1 -1
- package/dist/src/core/merge.d.ts +1 -1
- package/dist/src/core/merge.d.ts.map +1 -1
- package/dist/src/core/merge.js +2 -18
- package/dist/src/core/merge.js.map +1 -1
- package/dist/src/core/migrate.d.ts.map +1 -1
- package/dist/src/core/migrate.js +5 -20
- package/dist/src/core/migrate.js.map +1 -1
- package/dist/src/core/sync-lock.d.ts.map +1 -1
- package/dist/src/core/sync-lock.js +20 -1
- package/dist/src/core/sync-lock.js.map +1 -1
- package/dist/src/core/sync.d.ts +4 -4
- package/dist/src/core/sync.d.ts.map +1 -1
- package/dist/src/core/sync.js +60 -25
- package/dist/src/core/sync.js.map +1 -1
- package/dist/src/i18n.d.ts.map +1 -1
- package/dist/src/i18n.js +17 -1
- package/dist/src/i18n.js.map +1 -1
- package/dist/src/types.d.ts +13 -3
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js.map +1 -1
- package/dist/src/utils/fs.d.ts +18 -0
- package/dist/src/utils/fs.d.ts.map +1 -0
- package/dist/src/utils/fs.js +56 -0
- package/dist/src/utils/fs.js.map +1 -0
- package/dist/src/utils/lcs.d.ts +8 -0
- package/dist/src/utils/lcs.d.ts.map +1 -0
- package/dist/src/utils/lcs.js +20 -0
- package/dist/src/utils/lcs.js.map +1 -0
- package/dist/src/utils/linediff.d.ts +1 -1
- package/dist/src/utils/linediff.d.ts.map +1 -1
- package/dist/src/utils/linediff.js +22 -39
- package/dist/src/utils/linediff.js.map +1 -1
- package/dist/test/merge.test.d.ts +5 -0
- package/dist/test/merge.test.d.ts.map +1 -0
- package/dist/test/merge.test.js +226 -0
- package/dist/test/merge.test.js.map +1 -0
- package/package.json +2 -2
- package/skill/SKILL.md +50 -3
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fs.ts — Shared filesystem utilities
|
|
3
|
+
*
|
|
4
|
+
* Consolidates walkDir and copyDirSync implementations previously
|
|
5
|
+
* duplicated across sync.ts, doctor.ts, key.ts, snapshot.ts, migrate.ts.
|
|
6
|
+
*/
|
|
7
|
+
import fs from 'fs';
|
|
8
|
+
import path from 'path';
|
|
9
|
+
/**
|
|
10
|
+
* Recursively list all file paths under a directory.
|
|
11
|
+
* Returns paths relative to dirAbs.
|
|
12
|
+
* @param filter Optional predicate to exclude relative paths (return false to skip)
|
|
13
|
+
*/
|
|
14
|
+
export function walkDir(dirAbs, filter) {
|
|
15
|
+
const results = [];
|
|
16
|
+
if (!fs.existsSync(dirAbs))
|
|
17
|
+
return results;
|
|
18
|
+
function walk(subPath) {
|
|
19
|
+
const full = path.join(dirAbs, subPath);
|
|
20
|
+
if (fs.statSync(full).isDirectory()) {
|
|
21
|
+
fs.readdirSync(full).forEach(f => walk(path.join(subPath, f)));
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
if (filter && !filter(subPath))
|
|
25
|
+
return;
|
|
26
|
+
results.push(subPath);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
fs.readdirSync(dirAbs).forEach(f => walk(f));
|
|
30
|
+
return results;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Recursively copy a directory. Returns the number of files copied.
|
|
34
|
+
* @param skipNames Optional set of entry names to skip (e.g. '.git')
|
|
35
|
+
*/
|
|
36
|
+
export function copyDirSync(src, dest, skipNames) {
|
|
37
|
+
let count = 0;
|
|
38
|
+
if (!fs.existsSync(src))
|
|
39
|
+
return count;
|
|
40
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
41
|
+
for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
|
|
42
|
+
if (skipNames?.has(entry.name))
|
|
43
|
+
continue;
|
|
44
|
+
const srcPath = path.join(src, entry.name);
|
|
45
|
+
const destPath = path.join(dest, entry.name);
|
|
46
|
+
if (entry.isDirectory()) {
|
|
47
|
+
count += copyDirSync(srcPath, destPath, skipNames);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
fs.copyFileSync(srcPath, destPath);
|
|
51
|
+
count++;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return count;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=fs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACxC,KAAK,MAAM,KAAK,IAAI,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;QACjE,IAAI,SAAS,EAAE,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC;YAAE,SAAS;QACzC,MAAM,OAAO,GAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;QAC5C,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;QAC7C,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;YACxB,KAAK,IAAI,WAAW,CAAC,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;QACrD,CAAC;aAAM,CAAC;YACN,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;YACnC,KAAK,EAAE,CAAC;QACV,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* lcs.ts — Shared Longest Common Subsequence (LCS) table builder
|
|
3
|
+
*
|
|
4
|
+
* Used by both linediff.ts (unified diff) and merge.ts (three-way merge).
|
|
5
|
+
*/
|
|
6
|
+
/** Build the LCS traceback table for two string arrays (iterative, O(m*n) time and space) */
|
|
7
|
+
export declare function buildLcsTable(a: readonly string[], b: readonly string[]): number[][];
|
|
8
|
+
//# sourceMappingURL=lcs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lcs.d.ts","sourceRoot":"","sources":["../../../src/utils/lcs.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,6FAA6F;AAC7F,wBAAgB,aAAa,CAAC,CAAC,EAAE,SAAS,MAAM,EAAE,EAAE,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,EAAE,CAcpF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* lcs.ts — Shared Longest Common Subsequence (LCS) table builder
|
|
3
|
+
*
|
|
4
|
+
* Used by both linediff.ts (unified diff) and merge.ts (three-way merge).
|
|
5
|
+
*/
|
|
6
|
+
/** Build the LCS traceback table for two string arrays (iterative, O(m*n) time and space) */
|
|
7
|
+
export function buildLcsTable(a, b) {
|
|
8
|
+
const m = a.length;
|
|
9
|
+
const n = b.length;
|
|
10
|
+
const dp = Array.from({ length: m + 1 }, () => new Array(n + 1).fill(0));
|
|
11
|
+
for (let i = 1; i <= m; i++) {
|
|
12
|
+
for (let j = 1; j <= n; j++) {
|
|
13
|
+
dp[i][j] = a[i - 1] === b[j - 1]
|
|
14
|
+
? (dp[i - 1][j - 1] + 1)
|
|
15
|
+
: Math.max(dp[i - 1][j], dp[i][j - 1]);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return dp;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=lcs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lcs.js","sourceRoot":"","sources":["../../../src/utils/lcs.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,6FAA6F;AAC7F,MAAM,UAAU,aAAa,CAAC,CAAoB,EAAE,CAAoB;IACtE,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;IACnB,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;IACnB,MAAM,EAAE,GAAe,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,GAAG,EAAE,CACxD,IAAI,KAAK,CAAS,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CACjC,CAAC;IACF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YAC5B,EAAE,CAAC,CAAC,CAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;gBAC/B,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAE,CAAC,CAAC,GAAG,CAAC,CAAE,GAAG,CAAC,CAAC;gBAC1B,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAE,CAAC,CAAC,CAAE,EAAE,EAAE,CAAC,CAAC,CAAE,CAAC,CAAC,GAAG,CAAC,CAAE,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* linediff.ts — Line-level unified diff tool (no external dependencies)
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Uses the shared LCS algorithm from lcs.ts,
|
|
5
5
|
* outputs human-readable unified diff format.
|
|
6
6
|
*/
|
|
7
7
|
export interface DiffLine {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linediff.d.ts","sourceRoot":"","sources":["../../../src/utils/linediff.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"linediff.d.ts","sourceRoot":"","sources":["../../../src/utils/linediff.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;IAC/C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,SAAS,QAAQ,EAAE,CAAC;IACpC,0CAA0C;IAC1C,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC7B;AAsBD;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,SAAI,GAAG,QAAQ,EAAE,CA8B/E"}
|
|
@@ -1,47 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* linediff.ts — Line-level unified diff tool (no external dependencies)
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Uses the shared LCS algorithm from lcs.ts,
|
|
5
5
|
* outputs human-readable unified diff format.
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
import { buildLcsTable } from './lcs.js';
|
|
8
|
+
/** Generate diff line list from the LCS traceback table (iterative to avoid stack overflow on large files) */
|
|
9
|
+
function traceback(dp, a, b) {
|
|
10
|
+
const stack = [];
|
|
11
|
+
let i = a.length;
|
|
12
|
+
let j = b.length;
|
|
13
|
+
while (i > 0 || j > 0) {
|
|
14
|
+
if (i > 0 && j > 0 && a[i - 1] === b[j - 1]) {
|
|
15
|
+
stack.push({ type: 'context', content: a[i - 1] });
|
|
16
|
+
i--;
|
|
17
|
+
j--;
|
|
18
|
+
}
|
|
19
|
+
else if (i > 0 && (j === 0 || dp[i - 1][j] >= dp[i][j - 1])) {
|
|
20
|
+
stack.push({ type: 'removed', content: a[i - 1] });
|
|
21
|
+
i--;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
stack.push({ type: 'added', content: b[j - 1] });
|
|
25
|
+
j--;
|
|
17
26
|
}
|
|
18
27
|
}
|
|
19
|
-
return
|
|
20
|
-
}
|
|
21
|
-
/** Generate diff line list from the LCS traceback table */
|
|
22
|
-
function traceback(dp, a, b, i, j, out) {
|
|
23
|
-
if (i === 0 && j === 0)
|
|
24
|
-
return;
|
|
25
|
-
if (i === 0) {
|
|
26
|
-
traceback(dp, a, b, 0, j - 1, out);
|
|
27
|
-
out.push({ type: 'added', content: b[j - 1] });
|
|
28
|
-
}
|
|
29
|
-
else if (j === 0) {
|
|
30
|
-
traceback(dp, a, b, i - 1, 0, out);
|
|
31
|
-
out.push({ type: 'removed', content: a[i - 1] });
|
|
32
|
-
}
|
|
33
|
-
else if (a[i - 1] === b[j - 1]) {
|
|
34
|
-
traceback(dp, a, b, i - 1, j - 1, out);
|
|
35
|
-
out.push({ type: 'context', content: a[i - 1] });
|
|
36
|
-
}
|
|
37
|
-
else if (dp[i - 1][j] >= dp[i][j - 1]) {
|
|
38
|
-
traceback(dp, a, b, i - 1, j, out);
|
|
39
|
-
out.push({ type: 'removed', content: a[i - 1] });
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
traceback(dp, a, b, i, j - 1, out);
|
|
43
|
-
out.push({ type: 'added', content: b[j - 1] });
|
|
44
|
-
}
|
|
28
|
+
return stack.reverse();
|
|
45
29
|
}
|
|
46
30
|
/**
|
|
47
31
|
* Perform line-level diff on two texts, return a DiffLine list.
|
|
@@ -51,8 +35,7 @@ export function diffText(before, after, context = 3) {
|
|
|
51
35
|
const a = before.split('\n');
|
|
52
36
|
const b = after.split('\n');
|
|
53
37
|
const dp = buildLcsTable(a, b);
|
|
54
|
-
const all =
|
|
55
|
-
traceback(dp, a, b, a.length, b.length, all);
|
|
38
|
+
const all = traceback(dp, a, b);
|
|
56
39
|
// Trim large unchanged-context blocks in the middle, keeping only context lines
|
|
57
40
|
const changed = all.map((l, i) => (l.type !== 'context' ? i : -1)).filter(i => i >= 0);
|
|
58
41
|
if (changed.length === 0)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linediff.js","sourceRoot":"","sources":["../../../src/utils/linediff.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"linediff.js","sourceRoot":"","sources":["../../../src/utils/linediff.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAezC,8GAA8G;AAC9G,SAAS,SAAS,CAAC,EAAc,EAAE,CAAW,EAAE,CAAW;IACzD,MAAM,KAAK,GAAe,EAAE,CAAC;IAC7B,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;IACjB,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;IACjB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACtB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YAC5C,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAE,EAAE,CAAC,CAAC;YACpD,CAAC,EAAE,CAAC;YAAC,CAAC,EAAE,CAAC;QACX,CAAC;aAAM,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAE,CAAC,CAAC,CAAE,IAAI,EAAE,CAAC,CAAC,CAAE,CAAC,CAAC,GAAG,CAAC,CAAE,CAAC,EAAE,CAAC;YAClE,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAE,EAAE,CAAC,CAAC;YACpD,CAAC,EAAE,CAAC;QACN,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,IAAI,CAAC,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AAE,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;IAED,mDAAmD;IACnD,MAAM,MAAM,GAAe,EAAE,CAAC;IAC9B,IAAI,QAAQ,GAAG,CAAC,CAAC,CAAC;IAClB,MAAM,MAAM,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAClD,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;QACzB,IAAI,QAAQ,IAAI,CAAC,IAAI,GAAG,GAAG,QAAQ,GAAG,CAAC,EAAE,CAAC;YACxC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;QACnD,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAE,CAAC,CAAC;QACvB,QAAQ,GAAG,GAAG,CAAC;IACjB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.test.d.ts","sourceRoot":"","sources":["../../test/merge.test.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* merge.test.ts — Three-way merge module unit tests
|
|
3
|
+
*/
|
|
4
|
+
import { describe, it } from 'node:test';
|
|
5
|
+
import assert from 'node:assert/strict';
|
|
6
|
+
import { threeWayMerge } from '../src/core/merge.js';
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
// 1. Fast paths
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
describe('threeWayMerge fast paths', () => {
|
|
11
|
+
it('local === remote → returns local as-is, no conflicts', () => {
|
|
12
|
+
const base = 'a\nb\nc';
|
|
13
|
+
const local = 'a\nX\nc';
|
|
14
|
+
const remote = 'a\nX\nc';
|
|
15
|
+
const result = threeWayMerge(base, local, remote);
|
|
16
|
+
assert.equal(result.merged, local);
|
|
17
|
+
assert.equal(result.hasConflicts, false);
|
|
18
|
+
});
|
|
19
|
+
it('local === base → returns remote (only remote changed)', () => {
|
|
20
|
+
const base = 'a\nb\nc';
|
|
21
|
+
const local = 'a\nb\nc';
|
|
22
|
+
const remote = 'a\nB\nc';
|
|
23
|
+
const result = threeWayMerge(base, local, remote);
|
|
24
|
+
assert.equal(result.merged, remote);
|
|
25
|
+
assert.equal(result.hasConflicts, false);
|
|
26
|
+
});
|
|
27
|
+
it('remote === base → returns local (only local changed)', () => {
|
|
28
|
+
const base = 'a\nb\nc';
|
|
29
|
+
const local = 'a\nL\nc';
|
|
30
|
+
const remote = 'a\nb\nc';
|
|
31
|
+
const result = threeWayMerge(base, local, remote);
|
|
32
|
+
assert.equal(result.merged, local);
|
|
33
|
+
assert.equal(result.hasConflicts, false);
|
|
34
|
+
});
|
|
35
|
+
it('all three identical → returns as-is, no conflicts', () => {
|
|
36
|
+
const text = 'hello\nworld';
|
|
37
|
+
const result = threeWayMerge(text, text, text);
|
|
38
|
+
assert.equal(result.merged, text);
|
|
39
|
+
assert.equal(result.hasConflicts, false);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
// ---------------------------------------------------------------------------
|
|
43
|
+
// 2. Non-overlapping edits
|
|
44
|
+
// ---------------------------------------------------------------------------
|
|
45
|
+
describe('threeWayMerge non-overlapping edits', () => {
|
|
46
|
+
it('local edits top, remote edits bottom → clean merge', () => {
|
|
47
|
+
const base = 'a\nb\nc\nd\ne';
|
|
48
|
+
const local = 'A\nb\nc\nd\ne'; // changed line 1
|
|
49
|
+
const remote = 'a\nb\nc\nd\nE'; // changed line 5
|
|
50
|
+
const result = threeWayMerge(base, local, remote);
|
|
51
|
+
assert.equal(result.hasConflicts, false);
|
|
52
|
+
assert.equal(result.merged, 'A\nb\nc\nd\nE');
|
|
53
|
+
});
|
|
54
|
+
it('local inserts a line, remote edits a different line → clean merge', () => {
|
|
55
|
+
const base = 'a\nb\nc';
|
|
56
|
+
const local = 'a\nb\nINSERTED\nc'; // insertion between b and c
|
|
57
|
+
const remote = 'a\nB\nc'; // edit line 2
|
|
58
|
+
const result = threeWayMerge(base, local, remote);
|
|
59
|
+
assert.equal(result.hasConflicts, false);
|
|
60
|
+
// Both changes should be present
|
|
61
|
+
assert.ok(result.merged.includes('B'));
|
|
62
|
+
assert.ok(result.merged.includes('INSERTED'));
|
|
63
|
+
});
|
|
64
|
+
it('local deletes a line, remote edits a different line → clean merge', () => {
|
|
65
|
+
const base = 'a\nb\nc\nd';
|
|
66
|
+
const local = 'a\nc\nd'; // deleted line 2 (b)
|
|
67
|
+
const remote = 'a\nb\nc\nD'; // edited line 4
|
|
68
|
+
const result = threeWayMerge(base, local, remote);
|
|
69
|
+
assert.equal(result.hasConflicts, false);
|
|
70
|
+
assert.ok(!result.merged.includes('b'));
|
|
71
|
+
assert.ok(result.merged.includes('D'));
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
// 3. Identical overlapping edits → auto-resolve
|
|
76
|
+
// ---------------------------------------------------------------------------
|
|
77
|
+
describe('threeWayMerge identical overlapping edits', () => {
|
|
78
|
+
it('both sides make the same edit → auto-resolved, no conflict', () => {
|
|
79
|
+
const base = 'a\nb\nc';
|
|
80
|
+
const local = 'a\nX\nc';
|
|
81
|
+
const remote = 'a\nX\nc';
|
|
82
|
+
const result = threeWayMerge(base, local, remote);
|
|
83
|
+
assert.equal(result.hasConflicts, false);
|
|
84
|
+
assert.equal(result.merged, 'a\nX\nc');
|
|
85
|
+
});
|
|
86
|
+
it('both sides delete the same line → auto-resolved', () => {
|
|
87
|
+
const base = 'a\nb\nc';
|
|
88
|
+
const local = 'a\nc';
|
|
89
|
+
const remote = 'a\nc';
|
|
90
|
+
const result = threeWayMerge(base, local, remote);
|
|
91
|
+
assert.equal(result.hasConflicts, false);
|
|
92
|
+
assert.equal(result.merged, 'a\nc');
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
// ---------------------------------------------------------------------------
|
|
96
|
+
// 4. Conflicting edits → conflict markers
|
|
97
|
+
// ---------------------------------------------------------------------------
|
|
98
|
+
describe('threeWayMerge conflicting edits', () => {
|
|
99
|
+
it('both sides edit the same line differently → conflict markers', () => {
|
|
100
|
+
const base = 'a\nb\nc';
|
|
101
|
+
const local = 'a\nL\nc';
|
|
102
|
+
const remote = 'a\nR\nc';
|
|
103
|
+
const result = threeWayMerge(base, local, remote);
|
|
104
|
+
assert.equal(result.hasConflicts, true);
|
|
105
|
+
assert.ok(result.merged.includes('<<<<<<< LOCAL'));
|
|
106
|
+
assert.ok(result.merged.includes('======='));
|
|
107
|
+
assert.ok(result.merged.includes('>>>>>>> REMOTE'));
|
|
108
|
+
assert.ok(result.merged.includes('L'));
|
|
109
|
+
assert.ok(result.merged.includes('R'));
|
|
110
|
+
});
|
|
111
|
+
it('conflict markers are properly structured', () => {
|
|
112
|
+
const base = 'x\ny\nz';
|
|
113
|
+
const local = 'x\nLOCAL_Y\nz';
|
|
114
|
+
const remote = 'x\nREMOTE_Y\nz';
|
|
115
|
+
const result = threeWayMerge(base, local, remote);
|
|
116
|
+
const lines = result.merged.split('\n');
|
|
117
|
+
const markerStart = lines.indexOf('<<<<<<< LOCAL');
|
|
118
|
+
const separator = lines.indexOf('=======');
|
|
119
|
+
const markerEnd = lines.indexOf('>>>>>>> REMOTE');
|
|
120
|
+
assert.ok(markerStart >= 0, 'should have LOCAL marker');
|
|
121
|
+
assert.ok(separator > markerStart, 'separator after LOCAL marker');
|
|
122
|
+
assert.ok(markerEnd > separator, 'REMOTE marker after separator');
|
|
123
|
+
// Local content between LOCAL marker and separator
|
|
124
|
+
const localContent = lines.slice(markerStart + 1, separator);
|
|
125
|
+
assert.ok(localContent.includes('LOCAL_Y'));
|
|
126
|
+
// Remote content between separator and REMOTE marker
|
|
127
|
+
const remoteContent = lines.slice(separator + 1, markerEnd);
|
|
128
|
+
assert.ok(remoteContent.includes('REMOTE_Y'));
|
|
129
|
+
});
|
|
130
|
+
it('surrounding unchanged lines are preserved around conflict', () => {
|
|
131
|
+
const base = 'first\nmiddle\nlast';
|
|
132
|
+
const local = 'first\nL\nlast';
|
|
133
|
+
const remote = 'first\nR\nlast';
|
|
134
|
+
const result = threeWayMerge(base, local, remote);
|
|
135
|
+
const lines = result.merged.split('\n');
|
|
136
|
+
assert.equal(lines[0], 'first');
|
|
137
|
+
assert.equal(lines[lines.length - 1], 'last');
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
// ---------------------------------------------------------------------------
|
|
141
|
+
// 5. Empty inputs
|
|
142
|
+
// ---------------------------------------------------------------------------
|
|
143
|
+
describe('threeWayMerge empty inputs', () => {
|
|
144
|
+
it('all three empty → empty result, no conflicts', () => {
|
|
145
|
+
const result = threeWayMerge('', '', '');
|
|
146
|
+
assert.equal(result.merged, '');
|
|
147
|
+
assert.equal(result.hasConflicts, false);
|
|
148
|
+
});
|
|
149
|
+
it('base empty, local and remote add identical content → auto-resolve', () => {
|
|
150
|
+
const result = threeWayMerge('', 'new line', 'new line');
|
|
151
|
+
assert.equal(result.hasConflicts, false);
|
|
152
|
+
assert.equal(result.merged, 'new line');
|
|
153
|
+
});
|
|
154
|
+
it('base empty, local and remote add different content → conflict', () => {
|
|
155
|
+
const result = threeWayMerge('', 'local line', 'remote line');
|
|
156
|
+
assert.equal(result.hasConflicts, true);
|
|
157
|
+
assert.ok(result.merged.includes('<<<<<<< LOCAL'));
|
|
158
|
+
assert.ok(result.merged.includes('>>>>>>> REMOTE'));
|
|
159
|
+
});
|
|
160
|
+
it('base has content, both local and remote are empty → auto-resolve (identical delete)', () => {
|
|
161
|
+
const result = threeWayMerge('some content', '', '');
|
|
162
|
+
assert.equal(result.hasConflicts, false);
|
|
163
|
+
assert.equal(result.merged, '');
|
|
164
|
+
});
|
|
165
|
+
it('base has content, only local is empty → return local (remote unchanged)', () => {
|
|
166
|
+
const base = 'content';
|
|
167
|
+
const result = threeWayMerge(base, '', base);
|
|
168
|
+
assert.equal(result.hasConflicts, false);
|
|
169
|
+
assert.equal(result.merged, '');
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
// ---------------------------------------------------------------------------
|
|
173
|
+
// 6. Trailing newlines
|
|
174
|
+
// ---------------------------------------------------------------------------
|
|
175
|
+
describe('threeWayMerge trailing newlines', () => {
|
|
176
|
+
it('preserves trailing newline when present in both', () => {
|
|
177
|
+
const base = 'a\nb\n';
|
|
178
|
+
const local = 'a\nL\n';
|
|
179
|
+
const remote = 'a\nb\n';
|
|
180
|
+
const result = threeWayMerge(base, local, remote);
|
|
181
|
+
assert.equal(result.hasConflicts, false);
|
|
182
|
+
assert.equal(result.merged, 'a\nL\n');
|
|
183
|
+
});
|
|
184
|
+
it('local adds trailing newline, remote unchanged → local wins', () => {
|
|
185
|
+
const base = 'a\nb';
|
|
186
|
+
const local = 'a\nb\n';
|
|
187
|
+
const remote = 'a\nb';
|
|
188
|
+
const result = threeWayMerge(base, local, remote);
|
|
189
|
+
assert.equal(result.hasConflicts, false);
|
|
190
|
+
assert.equal(result.merged, 'a\nb\n');
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
// ---------------------------------------------------------------------------
|
|
194
|
+
// 7. Multiple conflict regions in one merge
|
|
195
|
+
// ---------------------------------------------------------------------------
|
|
196
|
+
describe('threeWayMerge multiple conflict regions', () => {
|
|
197
|
+
it('two separate conflict regions produce two sets of markers', () => {
|
|
198
|
+
const base = 'a\nb\nc\nd\ne';
|
|
199
|
+
const local = 'L1\nb\nc\nd\nL2';
|
|
200
|
+
const remote = 'R1\nb\nc\nd\nR2';
|
|
201
|
+
const result = threeWayMerge(base, local, remote);
|
|
202
|
+
assert.equal(result.hasConflicts, true);
|
|
203
|
+
const markers = result.merged.split('\n').filter(l => l === '<<<<<<< LOCAL');
|
|
204
|
+
assert.equal(markers.length, 2, 'should have two conflict regions');
|
|
205
|
+
});
|
|
206
|
+
it('mix of clean merge and conflict in one file', () => {
|
|
207
|
+
// Line layout: a / b / c / d / e / f / g
|
|
208
|
+
// local: A / b / c / L / e / f / g (edit a→A, edit d→L)
|
|
209
|
+
// remote: a / b / c / R / e / f / G (edit d→R, edit g→G)
|
|
210
|
+
// Expected: A cleanly merged, d→conflict, G cleanly merged
|
|
211
|
+
const base = 'a\nb\nc\nd\ne\nf\ng';
|
|
212
|
+
const local = 'A\nb\nc\nL\ne\nf\ng';
|
|
213
|
+
const remote = 'a\nb\nc\nR\ne\nf\nG';
|
|
214
|
+
const result = threeWayMerge(base, local, remote);
|
|
215
|
+
assert.equal(result.hasConflicts, true);
|
|
216
|
+
const lines = result.merged.split('\n');
|
|
217
|
+
// a→A should be cleanly resolved
|
|
218
|
+
assert.equal(lines[0], 'A');
|
|
219
|
+
// g→G should be cleanly resolved
|
|
220
|
+
assert.equal(lines[lines.length - 1], 'G');
|
|
221
|
+
// Only one conflict region (for d)
|
|
222
|
+
const conflictCount = lines.filter(l => l === '<<<<<<< LOCAL').length;
|
|
223
|
+
assert.equal(conflictCount, 1);
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
//# sourceMappingURL=merge.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.test.js","sourceRoot":"","sources":["../../test/merge.test.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,8EAA8E;AAC9E,gBAAgB;AAChB,8EAA8E;AAE9E,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IACxC,EAAE,CAAC,sDAAsD,EAAE,GAAG,EAAE;QAC9D,MAAM,IAAI,GAAG,SAAS,CAAC;QACvB,MAAM,KAA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C,CAAC,CAAC;IACtE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6CAA6C,EAAE,GAAG,EAAE;QACrD,yCAAyC;QACzC,2DAA2D;QAC3D,2DAA2D;QAC3D,2DAA2D;QAC3D,MAAM,IAAI,GAAK,qBAAqB,CAAC;QACrC,MAAM,KAAK,GAAI,qBAAqB,CAAC;QACrC,MAAM,MAAM,GAAG,qBAAqB,CAAC;QACrC,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QAClD,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;QACxC,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACxC,iCAAiC;QACjC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;QAC5B,iCAAiC;QACjC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;QAC3C,mCAAmC;QACnC,MAAM,aAAa,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,eAAe,CAAC,CAAC,MAAM,CAAC;QACtE,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wangchuan",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "忘川 · AI 记忆同步系统 — 智能体记忆永不遗失",
|
|
5
5
|
"bin": {
|
|
6
6
|
"wangchuan": "./dist/bin/wangchuan.js"
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"postbuild": "chmod +x dist/bin/wangchuan.js",
|
|
18
18
|
"prepublishOnly": "npm run build",
|
|
19
19
|
"dev": "tsx bin/wangchuan.ts",
|
|
20
|
-
"test": "node --import tsx/esm --test test/crypto.test.ts test/json-field.test.ts test/sync.test.ts test/sync-history.test.ts",
|
|
20
|
+
"test": "node --import tsx/esm --test test/crypto.test.ts test/json-field.test.ts test/sync.test.ts test/sync-history.test.ts test/merge.test.ts",
|
|
21
21
|
"typecheck": "tsc --noEmit"
|
|
22
22
|
},
|
|
23
23
|
"keywords": [
|
package/skill/SKILL.md
CHANGED
|
@@ -7,17 +7,20 @@ OpenClaw Skill wrapper for the Wangchuan AI memory sync system. Invoke directly
|
|
|
7
7
|
## Command Reference
|
|
8
8
|
|
|
9
9
|
```
|
|
10
|
-
wangchuan init [--repo <url>] [--key <path>] One-time setup
|
|
10
|
+
wangchuan init [--repo <url>] [--key <path>] One-time setup — auto-detects agents, offers gh repo create, runs first sync
|
|
11
11
|
wangchuan sync [-a, --agent <name>] [-n, --dry-run] Smart bidirectional sync (THE daily command)
|
|
12
|
+
[-o, --only <patterns...>] Filter: only sync files matching patterns
|
|
13
|
+
[-x, --exclude <patterns...>] Filter: exclude files matching patterns
|
|
12
14
|
wangchuan status [-v, --verbose] One-screen summary + health score
|
|
13
15
|
wangchuan watch [-i, --interval <min>] Background daemon for continuous sync
|
|
14
16
|
wangchuan doctor [--key-export|--key-rotate|--setup] Diagnose + auto-fix everything
|
|
15
17
|
wangchuan memory list|show|copy|broadcast Browse/copy memories between agents
|
|
16
18
|
wangchuan env list|create|switch|current|delete Multi-environment management
|
|
19
|
+
wangchuan snapshot save|list|restore|delete [name] Manage sync snapshots
|
|
17
20
|
wangchuan lang [zh|en] Switch CLI display language
|
|
18
21
|
```
|
|
19
22
|
|
|
20
|
-
Aliases: `sync` → `s`, `status` → `st`
|
|
23
|
+
Aliases: `sync` → `s`, `status` → `st`, `snapshot` → `snap`
|
|
21
24
|
|
|
22
25
|
## Invocation Examples
|
|
23
26
|
|
|
@@ -47,6 +50,10 @@ Aliases: `sync` → `s`, `status` → `st`
|
|
|
47
50
|
|
|
48
51
|
> Broadcast a memory to all agents
|
|
49
52
|
|
|
53
|
+
> Save a snapshot before making changes
|
|
54
|
+
|
|
55
|
+
> Restore the last snapshot
|
|
56
|
+
|
|
50
57
|
> Switch to English output
|
|
51
58
|
|
|
52
59
|
## Output Guide
|
|
@@ -67,6 +74,13 @@ Aliases: `sync` → `s`, `status` → `st`
|
|
|
67
74
|
- Auto-creates safety snapshot before syncing
|
|
68
75
|
- Pulls remote changes if any, then pushes local changes
|
|
69
76
|
- Shows compact summary with files synced count
|
|
77
|
+
- `--only` / `--exclude` for fine-grained file filtering (stale detection auto-skipped when filters active)
|
|
78
|
+
|
|
79
|
+
### snapshot
|
|
80
|
+
- `save [name]` — save a named snapshot (auto-named if omitted)
|
|
81
|
+
- `list` — show all saved snapshots with timestamps
|
|
82
|
+
- `restore <name>` — roll back to a previous snapshot
|
|
83
|
+
- `delete <name>` — remove a snapshot
|
|
70
84
|
|
|
71
85
|
### watch
|
|
72
86
|
- Runs as a background daemon with configurable interval
|
|
@@ -82,7 +96,7 @@ Aliases: `sync` → `s`, `status` → `st`
|
|
|
82
96
|
|
|
83
97
|
### memory
|
|
84
98
|
- `list` — show all agent memories with summaries
|
|
85
|
-
- `show <agent>` —
|
|
99
|
+
- `show <agent>` — list all files when no filename given; fuzzy/substring matching with suggestions on mismatch
|
|
86
100
|
- `copy <from> <to>` — copy memory between agents
|
|
87
101
|
- `broadcast <agent>` — distribute memory to all agents
|
|
88
102
|
|
|
@@ -106,6 +120,39 @@ When omitted, operates on all enabled agents plus the shared tier (skills/MCP/cu
|
|
|
106
120
|
|
|
107
121
|
Custom sub-agents defined in the `agents/` directory of any supported agent (Claude, Cursor, CodeBuddy, WorkBuddy) are automatically synced across all agents via the shared tier (`shared/agents/`). The same deletion confirmation logic as skills applies — a custom agent is pruned from the repo only when all local agents have removed it.
|
|
108
122
|
|
|
123
|
+
## Dynamic Agent Registration
|
|
124
|
+
|
|
125
|
+
Custom agents can be registered at runtime via the `customAgents` field in `config.json`, without recompilation. Custom agents participate in sync identically to built-in agents and support all three entry types (`syncFiles`, `syncDirs`, `jsonFields`).
|
|
126
|
+
|
|
127
|
+
## Sync Protocol for AI Agents (IMPORTANT — all agents must follow)
|
|
128
|
+
|
|
129
|
+
When this skill is loaded by an AI agent, the agent MUST follow these rules:
|
|
130
|
+
|
|
131
|
+
### After modifying skills or custom agents
|
|
132
|
+
If you (the AI agent) create, modify, or delete any file under your `skills/` or `agents/` directory, you MUST immediately run:
|
|
133
|
+
```bash
|
|
134
|
+
wangchuan sync
|
|
135
|
+
```
|
|
136
|
+
This triggers cross-agent distribution with user confirmation — the user chooses which other agents receive the change.
|
|
137
|
+
|
|
138
|
+
### After modifying memory or config
|
|
139
|
+
If you update MEMORY.md, CLAUDE.md, settings.json, or any synced config file, run `wangchuan sync` to push changes to the cloud.
|
|
140
|
+
|
|
141
|
+
### On session start
|
|
142
|
+
Check if the watch daemon is running. If not, suggest starting it:
|
|
143
|
+
```bash
|
|
144
|
+
wangchuan watch
|
|
145
|
+
```
|
|
146
|
+
The watch daemon auto-detects file changes and triggers sync, serving as a safety net when the agent forgets to sync manually.
|
|
147
|
+
|
|
148
|
+
### Rule summary
|
|
149
|
+
| Event | Action |
|
|
150
|
+
|-------|--------|
|
|
151
|
+
| Created/modified/deleted a skill | Run `wangchuan sync` immediately |
|
|
152
|
+
| Created/modified/deleted a custom agent | Run `wangchuan sync` immediately |
|
|
153
|
+
| Updated memory or config | Run `wangchuan sync` |
|
|
154
|
+
| Session start | Check `wangchuan status`, suggest `wangchuan watch` if not running |
|
|
155
|
+
|
|
109
156
|
## Prerequisites
|
|
110
157
|
|
|
111
158
|
1. Node.js ≥ 18
|