ntn-skills 2.0.0 → 2.0.2
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/CHANGELOG.md +9 -0
- package/INSTALL.md +6 -0
- package/dist/bin.js +439 -110
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to `ntn-skills` are documented in this file.
|
|
4
4
|
|
|
5
|
+
## [2.0.1] - 2026-12-03
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
- **Per-Skill Fault Isolation & Cold-Sync Checkpoint Resume**: A single unreachable or force-pushed upstream Git source no longer aborts full-library `sync`; healthy skills materialize and export normally while surfacing targeted warnings, and intermediate Notion body caches checkpoint to disk so interrupted cold syncs resume with zero duplicate requests.
|
|
9
|
+
- **Cold-Sync Pruning & Concurrency**: Initial cold sync now skips `readSkillBody` on non-prefetched `manual` skills and parallelizes Notion page reads and snapshot materializations (`concurrency: 4`).
|
|
10
|
+
- **Source & Upstream Recovery Without Full-Sync Deadlock**: `source list`, `source set`, `source sync`, and `upstream check/apply` now query table metadata directly without requiring a prior full snapshot materialization.
|
|
11
|
+
- **Automatic Proxy Bypass for Tailscale & LAN Remotes**: Upstream Git and asset fetches automatically bypass `HTTP(S)_PROXY` for `.ts.net`, `.local`, `localhost`, RFC1918 private IPs, and Tailscale CGNAT (`100.64.0.0/10`) hosts.
|
|
12
|
+
- **Release Tag Alignment in `scripts/install.sh`**: `install.sh` now defaults to the latest stable `vX.Y.Z` release tag so `ntn-skills --version` matches the published npm release.
|
|
13
|
+
|
|
5
14
|
## [2.0.0] - 2026-12-03
|
|
6
15
|
|
|
7
16
|
### Added
|
package/INSTALL.md
CHANGED
|
@@ -75,7 +75,13 @@ Once `credentials.env` is in place and the user provides `<NOTION_PAGE_URL>`, ru
|
|
|
75
75
|
|
|
76
76
|
- **Default setup** (exports to `~/.agents/skills` with `prefetch: discoverable`):
|
|
77
77
|
```bash
|
|
78
|
+
# New/small library (creates or binds 3 tables + runs initial sync):
|
|
78
79
|
ntn-skills init --root "<NOTION_PAGE_URL>" --json </dev/null
|
|
80
|
+
|
|
81
|
+
# Existing large library (100+ skills or external Git sources):
|
|
82
|
+
# Bind config immediately (<2s), then run initial cold-start sync with a generous timeout (>=600s or background job):
|
|
83
|
+
# ntn-skills init --root "<NOTION_PAGE_URL>" --no-sync --json </dev/null
|
|
84
|
+
# ntn-skills sync --json </dev/null
|
|
79
85
|
```
|
|
80
86
|
- **Custom or multi-surface export directories** (e.g., Grok Box `${HOME}/agent-data/workflows` using `copy` mode alongside `~/.agents/skills` using `symlink`, or `~/.claude/skills`):
|
|
81
87
|
```bash
|
package/dist/bin.js
CHANGED
|
@@ -1314,6 +1314,15 @@ function resolveStorePaths(overrides) {
|
|
|
1314
1314
|
locksRoot: nodePath.join(homeDir, ".locks")
|
|
1315
1315
|
};
|
|
1316
1316
|
}
|
|
1317
|
+
var DEAD_PROC_TMP_RE = /^(?:extract|sub|gsub|asset)-(\d+)-/;
|
|
1318
|
+
function repoGitCacheKey(repoUrl) {
|
|
1319
|
+
return sha256Hex(repoUrl.trim()).slice(0, 16);
|
|
1320
|
+
}
|
|
1321
|
+
async function removeInternalCachePath(absTargetPath) {
|
|
1322
|
+
const resolved = nodePath.resolve(absTargetPath);
|
|
1323
|
+
await makeTreeWritableBestEffort(resolved);
|
|
1324
|
+
await fsp.rm(resolved, { recursive: true, force: true });
|
|
1325
|
+
}
|
|
1317
1326
|
async function moveToSystemTrash(absTargetPath) {
|
|
1318
1327
|
const resolved = nodePath.resolve(absTargetPath);
|
|
1319
1328
|
await makeTreeWritableBestEffort(resolved);
|
|
@@ -1454,7 +1463,7 @@ function makeStoreService(overrides) {
|
|
|
1454
1463
|
await fsp.rename(lockDir, staleTmp).catch(() => {
|
|
1455
1464
|
return;
|
|
1456
1465
|
});
|
|
1457
|
-
await
|
|
1466
|
+
await removeInternalCachePath(staleTmp).catch(() => {
|
|
1458
1467
|
return;
|
|
1459
1468
|
});
|
|
1460
1469
|
continue;
|
|
@@ -1520,11 +1529,11 @@ function makeStoreService(overrides) {
|
|
|
1520
1529
|
const code = err?.code;
|
|
1521
1530
|
if (code === "EEXIST" || code === "ENOTEMPTY" || code === "EACCES" || code === "EPERM") {
|
|
1522
1531
|
if (await verifyStorePackageDir(targetDir, effectiveRev)) {
|
|
1523
|
-
await
|
|
1532
|
+
await removeInternalCachePath(stagingDir);
|
|
1524
1533
|
return await fsp.realpath(targetDir);
|
|
1525
1534
|
}
|
|
1526
1535
|
if (await fsp.stat(targetDir).then(() => true).catch(() => false)) {
|
|
1527
|
-
await
|
|
1536
|
+
await removeInternalCachePath(targetDir);
|
|
1528
1537
|
await fsp.rename(stagingDir, targetDir);
|
|
1529
1538
|
} else {
|
|
1530
1539
|
throw err;
|
|
@@ -1536,7 +1545,7 @@ function makeStoreService(overrides) {
|
|
|
1536
1545
|
await sealDirectoriesReadOnly(targetDir);
|
|
1537
1546
|
return await fsp.realpath(targetDir);
|
|
1538
1547
|
} catch (err) {
|
|
1539
|
-
await
|
|
1548
|
+
await removeInternalCachePath(stagingDir).catch(() => {
|
|
1540
1549
|
return;
|
|
1541
1550
|
});
|
|
1542
1551
|
throw err;
|
|
@@ -1551,7 +1560,7 @@ function makeStoreService(overrides) {
|
|
|
1551
1560
|
const bytes = await fsp.readFile(p);
|
|
1552
1561
|
if (sha256Hex(bytes) === sha256.toLowerCase())
|
|
1553
1562
|
return new Uint8Array(bytes);
|
|
1554
|
-
await
|
|
1563
|
+
await removeInternalCachePath(p).catch(() => {
|
|
1555
1564
|
return;
|
|
1556
1565
|
});
|
|
1557
1566
|
return null;
|
|
@@ -1641,7 +1650,7 @@ function makeStoreService(overrides) {
|
|
|
1641
1650
|
continue;
|
|
1642
1651
|
if (normalizedProtected.has(v.dir) || normalizedProtected.has(v.realDir))
|
|
1643
1652
|
continue;
|
|
1644
|
-
await
|
|
1653
|
+
await removeInternalCachePath(v.realDir);
|
|
1645
1654
|
pruned.push(v.realDir);
|
|
1646
1655
|
}
|
|
1647
1656
|
}
|
|
@@ -1655,6 +1664,7 @@ function makeStoreService(overrides) {
|
|
|
1655
1664
|
const commitSha = rc.commitSha.trim();
|
|
1656
1665
|
if (!repoUrl)
|
|
1657
1666
|
continue;
|
|
1667
|
+
protectedGitKeys.add(repoGitCacheKey(repoUrl));
|
|
1658
1668
|
protectedGitKeys.add(sha256Hex(repoUrl).slice(0, 20));
|
|
1659
1669
|
if (commitSha) {
|
|
1660
1670
|
protectedTreeKeys.add(sha256Hex(`${repoUrl}@${commitSha}`).slice(0, 24));
|
|
@@ -1672,7 +1682,7 @@ function makeStoreService(overrides) {
|
|
|
1672
1682
|
if (nowMs - st.mtimeMs <= repoTreeGraceMs)
|
|
1673
1683
|
continue;
|
|
1674
1684
|
const real = await fsp.realpath(full).catch(() => nodePath.resolve(full));
|
|
1675
|
-
await
|
|
1685
|
+
await removeInternalCachePath(real);
|
|
1676
1686
|
pruned.push(real);
|
|
1677
1687
|
}
|
|
1678
1688
|
const subtreesRoot = nodePath.join(paths.reposRoot, "subtrees");
|
|
@@ -1696,7 +1706,7 @@ function makeStoreService(overrides) {
|
|
|
1696
1706
|
if (nowMs - st.mtimeMs <= subRetMs)
|
|
1697
1707
|
continue;
|
|
1698
1708
|
const real = await fsp.realpath(full).catch(() => nodePath.resolve(full));
|
|
1699
|
-
await
|
|
1709
|
+
await removeInternalCachePath(real);
|
|
1700
1710
|
pruned.push(real);
|
|
1701
1711
|
}
|
|
1702
1712
|
const gitRoot = nodePath.join(paths.reposRoot, "git");
|
|
@@ -1711,17 +1721,19 @@ function makeStoreService(overrides) {
|
|
|
1711
1721
|
if (nowMs - st.mtimeMs <= gitRetMs)
|
|
1712
1722
|
continue;
|
|
1713
1723
|
const real = await fsp.realpath(full).catch(() => nodePath.resolve(full));
|
|
1714
|
-
await
|
|
1724
|
+
await removeInternalCachePath(real);
|
|
1715
1725
|
pruned.push(real);
|
|
1716
1726
|
}
|
|
1717
1727
|
const tmpRoot = nodePath.join(paths.reposRoot, ".tmp");
|
|
1718
1728
|
for (const name of await fsp.readdir(tmpRoot).catch(() => [])) {
|
|
1719
1729
|
const full = nodePath.join(tmpRoot, name);
|
|
1720
1730
|
const st = await fsp.stat(full).catch(() => null);
|
|
1721
|
-
|
|
1731
|
+
const pidMatch = name.match(DEAD_PROC_TMP_RE);
|
|
1732
|
+
const holderDead = pidMatch ? !isProcessAlive(Number(pidMatch[1])) : false;
|
|
1733
|
+
if (!st || !holderDead && nowMs - st.mtimeMs <= repoTreeGraceMs)
|
|
1722
1734
|
continue;
|
|
1723
1735
|
const real = await fsp.realpath(full).catch(() => nodePath.resolve(full));
|
|
1724
|
-
await
|
|
1736
|
+
await removeInternalCachePath(real);
|
|
1725
1737
|
pruned.push(real);
|
|
1726
1738
|
}
|
|
1727
1739
|
}
|
|
@@ -2980,13 +2992,116 @@ function parseGitHubRepo(repoUrl) {
|
|
|
2980
2992
|
}
|
|
2981
2993
|
return null;
|
|
2982
2994
|
}
|
|
2995
|
+
var DEFAULT_INTERNAL_NO_PROXY = ".ts.net,.local,.lan,.internal,.home.arpa,localhost,127.0.0.1,::1";
|
|
2996
|
+
function extractHostForProxyCheck(rawUrl) {
|
|
2997
|
+
const trimmed = rawUrl.trim();
|
|
2998
|
+
if (!trimmed)
|
|
2999
|
+
return null;
|
|
3000
|
+
try {
|
|
3001
|
+
if (/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(trimmed)) {
|
|
3002
|
+
const u = new URL(trimmed);
|
|
3003
|
+
return u.hostname.replace(/^\[|\]$/g, "").toLowerCase();
|
|
3004
|
+
}
|
|
3005
|
+
} catch {}
|
|
3006
|
+
const scpMatch = trimmed.match(/^(?:[^@\s]+@)?([^:/\s]+):/);
|
|
3007
|
+
if (scpMatch?.[1]) {
|
|
3008
|
+
return scpMatch[1].replace(/^\[|\]$/g, "").toLowerCase();
|
|
3009
|
+
}
|
|
3010
|
+
return null;
|
|
3011
|
+
}
|
|
3012
|
+
function shouldBypassProxyForUrl(rawUrl) {
|
|
3013
|
+
const host = extractHostForProxyCheck(rawUrl);
|
|
3014
|
+
if (!host)
|
|
3015
|
+
return false;
|
|
3016
|
+
if (host === "localhost" || host === "127.0.0.1" || host === "::1" || host === "0.0.0.0" || !host.includes(".")) {
|
|
3017
|
+
return true;
|
|
3018
|
+
}
|
|
3019
|
+
if (host.endsWith(".ts.net") || host.endsWith(".local") || host.endsWith(".lan") || host.endsWith(".internal") || host.endsWith(".home.arpa")) {
|
|
3020
|
+
return true;
|
|
3021
|
+
}
|
|
3022
|
+
const ipv4 = host.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);
|
|
3023
|
+
if (ipv4) {
|
|
3024
|
+
const a = Number(ipv4[1]);
|
|
3025
|
+
const b = Number(ipv4[2]);
|
|
3026
|
+
if (a === 10 || a === 127)
|
|
3027
|
+
return true;
|
|
3028
|
+
if (a === 192 && b === 168)
|
|
3029
|
+
return true;
|
|
3030
|
+
if (a === 172 && b >= 16 && b <= 31)
|
|
3031
|
+
return true;
|
|
3032
|
+
if (a === 100 && b >= 64 && b <= 127)
|
|
3033
|
+
return true;
|
|
3034
|
+
}
|
|
3035
|
+
return false;
|
|
3036
|
+
}
|
|
3037
|
+
function buildSubprocessEnv(bypassProxy) {
|
|
3038
|
+
const env = { ...process.env, GIT_TERMINAL_PROMPT: "0" };
|
|
3039
|
+
const existingNoProxy = env.NO_PROXY || env.no_proxy || "";
|
|
3040
|
+
const mergedNoProxy = Array.from(new Set(`${existingNoProxy},${DEFAULT_INTERNAL_NO_PROXY}`.split(",").map((s) => s.trim()).filter(Boolean))).join(",");
|
|
3041
|
+
env.NO_PROXY = mergedNoProxy;
|
|
3042
|
+
env.no_proxy = mergedNoProxy;
|
|
3043
|
+
if (bypassProxy) {
|
|
3044
|
+
for (const k of [
|
|
3045
|
+
"HTTP_PROXY",
|
|
3046
|
+
"HTTPS_PROXY",
|
|
3047
|
+
"ALL_PROXY",
|
|
3048
|
+
"http_proxy",
|
|
3049
|
+
"https_proxy",
|
|
3050
|
+
"all_proxy"
|
|
3051
|
+
]) {
|
|
3052
|
+
Reflect.deleteProperty(env, k);
|
|
3053
|
+
}
|
|
3054
|
+
}
|
|
3055
|
+
return env;
|
|
3056
|
+
}
|
|
3057
|
+
var STALE_GIT_LOCK_FILES = [
|
|
3058
|
+
"shallow.lock",
|
|
3059
|
+
"config.lock",
|
|
3060
|
+
"HEAD.lock",
|
|
3061
|
+
"index.lock",
|
|
3062
|
+
"packed-refs.lock"
|
|
3063
|
+
];
|
|
3064
|
+
async function cleanStaleGitRepoLocks(gitCacheDir) {
|
|
3065
|
+
await Promise.all(STALE_GIT_LOCK_FILES.map((name) => fsp4.rm(nodePath4.join(gitCacheDir, name), { force: true }).catch(() => {
|
|
3066
|
+
return;
|
|
3067
|
+
})));
|
|
3068
|
+
}
|
|
3069
|
+
async function sweepDeadProcessRepoTmpDirs(reposRoot) {
|
|
3070
|
+
const tmpRoot = nodePath4.join(reposRoot, ".tmp");
|
|
3071
|
+
const names = await fsp4.readdir(tmpRoot).catch(() => []);
|
|
3072
|
+
await Promise.all(names.map(async (name) => {
|
|
3073
|
+
const m = name.match(DEAD_PROC_TMP_RE);
|
|
3074
|
+
if (m && !isProcessAlive(Number(m[1]))) {
|
|
3075
|
+
await removeInternalCachePath(nodePath4.join(tmpRoot, name)).catch(() => {
|
|
3076
|
+
return;
|
|
3077
|
+
});
|
|
3078
|
+
}
|
|
3079
|
+
}));
|
|
3080
|
+
}
|
|
3081
|
+
var repoGitLocks = new Map;
|
|
3082
|
+
async function withRepoGitLock(key, fn) {
|
|
3083
|
+
const prev = repoGitLocks.get(key) ?? Promise.resolve();
|
|
3084
|
+
const next = prev.catch(() => {
|
|
3085
|
+
return;
|
|
3086
|
+
}).then(fn);
|
|
3087
|
+
repoGitLocks.set(key, next);
|
|
3088
|
+
try {
|
|
3089
|
+
return await next;
|
|
3090
|
+
} finally {
|
|
3091
|
+
if (repoGitLocks.get(key) === next) {
|
|
3092
|
+
repoGitLocks.delete(key);
|
|
3093
|
+
}
|
|
3094
|
+
}
|
|
3095
|
+
}
|
|
2983
3096
|
async function runCmd(bin, args, opts) {
|
|
2984
3097
|
const timeoutMs = opts?.timeoutMs ?? 60000;
|
|
3098
|
+
const bypassProxy = Boolean(opts?.bypassProxy);
|
|
3099
|
+
const finalArgs = bypassProxy && bin === "git" ? ["-c", "http.proxy=", "-c", "https.proxy=", ...args] : [...args];
|
|
2985
3100
|
return new Promise((resolve, reject) => {
|
|
2986
|
-
const child = spawn3(bin,
|
|
3101
|
+
const child = spawn3(bin, finalArgs, {
|
|
2987
3102
|
cwd: opts?.cwd,
|
|
2988
3103
|
stdio: ["ignore", "pipe", "pipe"],
|
|
2989
|
-
env:
|
|
3104
|
+
env: buildSubprocessEnv(bypassProxy)
|
|
2990
3105
|
});
|
|
2991
3106
|
let stdout = "";
|
|
2992
3107
|
let stderr = "";
|
|
@@ -3056,8 +3171,42 @@ async function readAllTreeFiles(rootDir, currentRel = "") {
|
|
|
3056
3171
|
}
|
|
3057
3172
|
var UpstreamLiveLayer = Layer3.effect(UpstreamPort, Effect3.gen(function* () {
|
|
3058
3173
|
const store = yield* StorePort;
|
|
3059
|
-
|
|
3174
|
+
let sweptDeadTmpOnce = false;
|
|
3175
|
+
const ensureDeadTmpSwept = async () => {
|
|
3176
|
+
if (sweptDeadTmpOnce)
|
|
3177
|
+
return;
|
|
3178
|
+
sweptDeadTmpOnce = true;
|
|
3179
|
+
await sweepDeadProcessRepoTmpDirs(store.paths.reposRoot);
|
|
3180
|
+
};
|
|
3181
|
+
const withCrossProcessRepoGitLock = (repoLockKey, gitCacheDir, fn) => withRepoGitLock(repoLockKey, async () => {
|
|
3182
|
+
await ensureDeadTmpSwept();
|
|
3183
|
+
await fsp4.mkdir(gitCacheDir, { recursive: true });
|
|
3184
|
+
const outcome = await Effect3.runPromise(store.withExclusiveLock(`repo-git-${repoLockKey}`, Effect3.promise(async () => {
|
|
3185
|
+
await cleanStaleGitRepoLocks(gitCacheDir);
|
|
3186
|
+
try {
|
|
3187
|
+
return { ok: true, value: await fn() };
|
|
3188
|
+
} catch (error) {
|
|
3189
|
+
return { ok: false, error };
|
|
3190
|
+
}
|
|
3191
|
+
}), 180000));
|
|
3192
|
+
if (!outcome.ok)
|
|
3193
|
+
throw outcome.error;
|
|
3194
|
+
return outcome.value;
|
|
3195
|
+
});
|
|
3196
|
+
const fullTreeInFlight = new Map;
|
|
3197
|
+
const ensureFullCommitTree = (repoUrl, commitSha) => {
|
|
3060
3198
|
const treeKey = sha256Hex(`${repoUrl.trim()}@${commitSha.trim()}`).slice(0, 24);
|
|
3199
|
+
const existingFlight = fullTreeInFlight.get(treeKey);
|
|
3200
|
+
if (existingFlight)
|
|
3201
|
+
return existingFlight;
|
|
3202
|
+
const p = ensureFullCommitTreeImpl(repoUrl, commitSha, treeKey).finally(() => {
|
|
3203
|
+
fullTreeInFlight.delete(treeKey);
|
|
3204
|
+
});
|
|
3205
|
+
fullTreeInFlight.set(treeKey, p);
|
|
3206
|
+
return p;
|
|
3207
|
+
};
|
|
3208
|
+
const ensureFullCommitTreeImpl = async (repoUrl, commitSha, treeKey) => {
|
|
3209
|
+
await ensureDeadTmpSwept();
|
|
3061
3210
|
const cachedTreeDir = nodePath4.join(store.paths.reposRoot, "trees", treeKey);
|
|
3062
3211
|
const marker = nodePath4.join(cachedTreeDir, ".ntn-tree-ready");
|
|
3063
3212
|
if (await fsp4.stat(marker).then(() => true).catch(() => false)) {
|
|
@@ -3104,51 +3253,55 @@ var UpstreamLiveLayer = Layer3.effect(UpstreamPort, Effect3.gen(function* () {
|
|
|
3104
3253
|
} catch {}
|
|
3105
3254
|
}
|
|
3106
3255
|
if (!extractedRoot) {
|
|
3107
|
-
const
|
|
3108
|
-
|
|
3109
|
-
const
|
|
3110
|
-
|
|
3111
|
-
await
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
cwd: gitCacheDir
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
cwd: gitCacheDir
|
|
3121
|
-
}).catch(() => {
|
|
3122
|
-
return;
|
|
3123
|
-
});
|
|
3124
|
-
const fetchRes = await runCmd("git", ["fetch", "--depth", "1", "origin", commitSha], {
|
|
3125
|
-
cwd: gitCacheDir,
|
|
3126
|
-
timeoutMs: 120000
|
|
3127
|
-
});
|
|
3128
|
-
if (fetchRes.code !== 0) {
|
|
3129
|
-
throw new UpstreamError({
|
|
3130
|
-
url: repoUrl,
|
|
3131
|
-
message: `Failed fetching ${repoUrl}@${commitSha}: ${fetchRes.stderr.trim()}`
|
|
3256
|
+
const bypassProxy = shouldBypassProxyForUrl(repoUrl);
|
|
3257
|
+
const repoLockKey = repoGitCacheKey(repoUrl);
|
|
3258
|
+
const gitCacheDir = nodePath4.join(store.paths.reposRoot, "git", repoLockKey);
|
|
3259
|
+
extractedRoot = await withCrossProcessRepoGitLock(repoLockKey, gitCacheDir, async () => {
|
|
3260
|
+
const hasHead = await fsp4.stat(nodePath4.join(gitCacheDir, "HEAD")).then(() => true).catch(() => false);
|
|
3261
|
+
if (!hasHead) {
|
|
3262
|
+
await runCmd("git", ["init", "--bare"], { cwd: gitCacheDir });
|
|
3263
|
+
}
|
|
3264
|
+
await runCmd("git", ["config", "remote.origin.url", repoUrl], { cwd: gitCacheDir });
|
|
3265
|
+
await runCmd("git", ["config", "--unset", "remote.origin.promisor"], {
|
|
3266
|
+
cwd: gitCacheDir
|
|
3267
|
+
}).catch(() => {
|
|
3268
|
+
return;
|
|
3132
3269
|
});
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
throw new UpstreamError({
|
|
3138
|
-
url: repoUrl,
|
|
3139
|
-
message: `Failed archiving ${repoUrl}@${commitSha}: ${archRes.stderr.trim()}`
|
|
3270
|
+
await runCmd("git", ["config", "--unset", "remote.origin.partialclonefilter"], {
|
|
3271
|
+
cwd: gitCacheDir
|
|
3272
|
+
}).catch(() => {
|
|
3273
|
+
return;
|
|
3140
3274
|
});
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
if (untar.code !== 0) {
|
|
3146
|
-
throw new UpstreamError({
|
|
3147
|
-
url: repoUrl,
|
|
3148
|
-
message: `Failed unpacking archive for ${repoUrl}@${commitSha}: ${untar.stderr.trim()}`
|
|
3275
|
+
const fetchRes = await runCmd("git", ["fetch", "--depth", "1", "origin", commitSha], {
|
|
3276
|
+
cwd: gitCacheDir,
|
|
3277
|
+
timeoutMs: 120000,
|
|
3278
|
+
bypassProxy
|
|
3149
3279
|
});
|
|
3150
|
-
|
|
3151
|
-
|
|
3280
|
+
if (fetchRes.code !== 0) {
|
|
3281
|
+
throw new UpstreamError({
|
|
3282
|
+
url: repoUrl,
|
|
3283
|
+
message: `Failed fetching ${repoUrl}@${commitSha}: ${fetchRes.stderr.trim()}`
|
|
3284
|
+
});
|
|
3285
|
+
}
|
|
3286
|
+
const tarPath = nodePath4.join(tmpBase, "git-archive.tar");
|
|
3287
|
+
const archRes = await runCmd("git", ["archive", "--format=tar", "-o", tarPath, "FETCH_HEAD"], { cwd: gitCacheDir, timeoutMs: 120000 });
|
|
3288
|
+
if (archRes.code !== 0) {
|
|
3289
|
+
throw new UpstreamError({
|
|
3290
|
+
url: repoUrl,
|
|
3291
|
+
message: `Failed archiving ${repoUrl}@${commitSha}: ${archRes.stderr.trim()}`
|
|
3292
|
+
});
|
|
3293
|
+
}
|
|
3294
|
+
const subOut = nodePath4.join(unpackDir, "git-tree");
|
|
3295
|
+
await fsp4.mkdir(subOut, { recursive: true });
|
|
3296
|
+
const untar = await runCmd("tar", ["-xf", tarPath, "-C", subOut]);
|
|
3297
|
+
if (untar.code !== 0) {
|
|
3298
|
+
throw new UpstreamError({
|
|
3299
|
+
url: repoUrl,
|
|
3300
|
+
message: `Failed unpacking archive for ${repoUrl}@${commitSha}: ${untar.stderr.trim()}`
|
|
3301
|
+
});
|
|
3302
|
+
}
|
|
3303
|
+
return subOut;
|
|
3304
|
+
});
|
|
3152
3305
|
}
|
|
3153
3306
|
await fsp4.writeFile(nodePath4.join(extractedRoot, ".ntn-tree-ready"), `${commitSha}
|
|
3154
3307
|
`, "utf8");
|
|
@@ -3161,7 +3314,7 @@ var UpstreamLiveLayer = Layer3.effect(UpstreamPort, Effect3.gen(function* () {
|
|
|
3161
3314
|
}
|
|
3162
3315
|
return cachedTreeDir;
|
|
3163
3316
|
} finally {
|
|
3164
|
-
await
|
|
3317
|
+
await removeInternalCachePath(tmpBase).catch(() => {
|
|
3165
3318
|
return;
|
|
3166
3319
|
});
|
|
3167
3320
|
}
|
|
@@ -3189,7 +3342,10 @@ var UpstreamLiveLayer = Layer3.effect(UpstreamPort, Effect3.gen(function* () {
|
|
|
3189
3342
|
}
|
|
3190
3343
|
}
|
|
3191
3344
|
}
|
|
3192
|
-
const ls = await runCmd("git", ["ls-remote", repoUrl, ref], {
|
|
3345
|
+
const ls = await runCmd("git", ["ls-remote", repoUrl, ref], {
|
|
3346
|
+
timeoutMs: 30000,
|
|
3347
|
+
bypassProxy: shouldBypassProxyForUrl(repoUrl)
|
|
3348
|
+
});
|
|
3193
3349
|
if (ls.code !== 0 || !ls.stdout.trim()) {
|
|
3194
3350
|
throw new UpstreamError({
|
|
3195
3351
|
url: repoUrl,
|
|
@@ -3282,7 +3438,7 @@ var UpstreamLiveLayer = Layer3.effect(UpstreamPort, Effect3.gen(function* () {
|
|
|
3282
3438
|
});
|
|
3283
3439
|
return (await readAllTreeFiles(subCacheDir)).filter((f) => f.path !== ".ntn-tree-ready");
|
|
3284
3440
|
} finally {
|
|
3285
|
-
await
|
|
3441
|
+
await removeInternalCachePath(tmpSub).catch(() => {
|
|
3286
3442
|
return;
|
|
3287
3443
|
});
|
|
3288
3444
|
}
|
|
@@ -3290,27 +3446,36 @@ var UpstreamLiveLayer = Layer3.effect(UpstreamPort, Effect3.gen(function* () {
|
|
|
3290
3446
|
}
|
|
3291
3447
|
} catch {}
|
|
3292
3448
|
}
|
|
3293
|
-
const
|
|
3294
|
-
|
|
3295
|
-
const
|
|
3296
|
-
|
|
3297
|
-
await
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3449
|
+
const bypassProxy = shouldBypassProxyForUrl(repoUrl);
|
|
3450
|
+
const repoLockKey = repoGitCacheKey(repoUrl);
|
|
3451
|
+
const gitCacheDir = nodePath4.join(store.paths.reposRoot, "git", repoLockKey);
|
|
3452
|
+
const sparseArchive = await withCrossProcessRepoGitLock(repoLockKey, gitCacheDir, async () => {
|
|
3453
|
+
const hasHead = await fsp4.stat(nodePath4.join(gitCacheDir, "HEAD")).then(() => true).catch(() => false);
|
|
3454
|
+
if (!hasHead) {
|
|
3455
|
+
await runCmd("git", ["init", "--bare"], { cwd: gitCacheDir });
|
|
3456
|
+
}
|
|
3457
|
+
await runCmd("git", ["config", "remote.origin.url", repoUrl], {
|
|
3458
|
+
cwd: gitCacheDir
|
|
3459
|
+
});
|
|
3460
|
+
await runCmd("git", ["config", "remote.origin.promisor", "true"], {
|
|
3461
|
+
cwd: gitCacheDir
|
|
3462
|
+
});
|
|
3463
|
+
await runCmd("git", ["config", "remote.origin.partialclonefilter", "blob:none"], {
|
|
3464
|
+
cwd: gitCacheDir
|
|
3465
|
+
});
|
|
3466
|
+
const fetchRes = await runCmd("git", ["fetch", "--depth", "1", "--filter=blob:none", "origin", commitSha], { cwd: gitCacheDir, timeoutMs: 60000, bypassProxy });
|
|
3467
|
+
if (fetchRes.code !== 0)
|
|
3468
|
+
return null;
|
|
3308
3469
|
const tmpSub = nodePath4.join(store.paths.reposRoot, ".tmp", `gsub-${process.pid}-${randomUUID3()}`);
|
|
3309
3470
|
await fsp4.mkdir(tmpSub, { recursive: true });
|
|
3471
|
+
const tarPath = nodePath4.join(tmpSub, "sub.tar");
|
|
3472
|
+
const archRes = await runCmd("git", ["archive", "--format=tar", "-o", tarPath, "FETCH_HEAD", "--", cleanSub], { cwd: gitCacheDir, timeoutMs: 45000 });
|
|
3473
|
+
return { tmpSub, tarPath, archCode: archRes.code };
|
|
3474
|
+
});
|
|
3475
|
+
if (sparseArchive) {
|
|
3476
|
+
const { tmpSub, tarPath, archCode } = sparseArchive;
|
|
3310
3477
|
try {
|
|
3311
|
-
|
|
3312
|
-
const archRes = await runCmd("git", ["archive", "--format=tar", "-o", tarPath, "FETCH_HEAD", "--", cleanSub], { cwd: gitCacheDir, timeoutMs: 45000 });
|
|
3313
|
-
if (archRes.code === 0) {
|
|
3478
|
+
if (archCode === 0) {
|
|
3314
3479
|
const unpackSub = nodePath4.join(tmpSub, "unpack");
|
|
3315
3480
|
await fsp4.mkdir(unpackSub, { recursive: true });
|
|
3316
3481
|
const untar = await runCmd("tar", ["-xf", tarPath, "-C", unpackSub]);
|
|
@@ -3327,7 +3492,7 @@ var UpstreamLiveLayer = Layer3.effect(UpstreamPort, Effect3.gen(function* () {
|
|
|
3327
3492
|
}
|
|
3328
3493
|
}
|
|
3329
3494
|
} finally {
|
|
3330
|
-
await
|
|
3495
|
+
await removeInternalCachePath(tmpSub).catch(() => {
|
|
3331
3496
|
return;
|
|
3332
3497
|
});
|
|
3333
3498
|
}
|
|
@@ -3530,6 +3695,21 @@ var UpstreamLiveLayer = Layer3.effect(UpstreamPort, Effect3.gen(function* () {
|
|
|
3530
3695
|
headers.Authorization = `Bearer ${token}`;
|
|
3531
3696
|
}
|
|
3532
3697
|
}
|
|
3698
|
+
if (shouldBypassProxyForUrl(url)) {
|
|
3699
|
+
const tmpAsset = nodePath4.join(store.paths.reposRoot, ".tmp", `asset-${process.pid}-${randomUUID3()}`);
|
|
3700
|
+
await fsp4.mkdir(nodePath4.dirname(tmpAsset), { recursive: true });
|
|
3701
|
+
try {
|
|
3702
|
+
const dl = await runCmd("curl", ["-fsSL", "--noproxy", "*", "--max-time", "30", "-o", tmpAsset, url], { timeoutMs: 35000, bypassProxy: true });
|
|
3703
|
+
if (dl.code === 0) {
|
|
3704
|
+
const buf = await fsp4.readFile(tmpAsset);
|
|
3705
|
+
return new Uint8Array(buf);
|
|
3706
|
+
}
|
|
3707
|
+
} finally {
|
|
3708
|
+
await removeInternalCachePath(tmpAsset).catch(() => {
|
|
3709
|
+
return;
|
|
3710
|
+
});
|
|
3711
|
+
}
|
|
3712
|
+
}
|
|
3533
3713
|
let res = await fetch(url, {
|
|
3534
3714
|
headers,
|
|
3535
3715
|
redirect: "follow",
|
|
@@ -4365,7 +4545,31 @@ function syncCommand(options = {}) {
|
|
|
4365
4545
|
warnings.push(w);
|
|
4366
4546
|
skillWarnings.set(sid, [...skillWarnings.get(sid) ?? [], w]);
|
|
4367
4547
|
}
|
|
4548
|
+
const emitSyncProgress = (msg) => {
|
|
4549
|
+
if (process.env.NTN_SKILLS_TEST_ONLY === "1" || process.env.NTN_SKILLS_QUIET === "1") {
|
|
4550
|
+
return;
|
|
4551
|
+
}
|
|
4552
|
+
process.stderr.write(`[ntn-skills] ${msg}
|
|
4553
|
+
`);
|
|
4554
|
+
};
|
|
4555
|
+
const saveIntermediateCheckpoint = (mainCacheSnapshot, fileCacheSnapshot) => store.writeCatalog({
|
|
4556
|
+
version: 2,
|
|
4557
|
+
updatedAt: currentCatalog.updatedAt || syncStartIso,
|
|
4558
|
+
libraries: {
|
|
4559
|
+
...currentCatalog.libraries,
|
|
4560
|
+
[libraryId]: {
|
|
4561
|
+
...workingLibState,
|
|
4562
|
+
watermark: prevLib.watermark,
|
|
4563
|
+
lastSyncedAt: prevLib.lastSyncedAt,
|
|
4564
|
+
mainHashCache: { ...mainCacheSnapshot },
|
|
4565
|
+
fileBodyCache: { ...fileCacheSnapshot }
|
|
4566
|
+
}
|
|
4567
|
+
},
|
|
4568
|
+
entries: currentCatalog.entries
|
|
4569
|
+
}).pipe(Effect4.catch(() => Effect4.void));
|
|
4368
4570
|
const currentNowMs = options.nowMs ?? Date.now();
|
|
4571
|
+
const hasPriorWatermark = Boolean(prevLib.watermark);
|
|
4572
|
+
const bodyCheckTasks = [];
|
|
4369
4573
|
for (const sk of effectiveSkills) {
|
|
4370
4574
|
const cached = workingLibState.mainHashCache[sk.id];
|
|
4371
4575
|
const inCurrentDelta = deltaSkillIds.has(sk.id);
|
|
@@ -4375,30 +4579,51 @@ function syncCommand(options = {}) {
|
|
|
4375
4579
|
const prevSk = prevLib.skills[sk.id];
|
|
4376
4580
|
const metaUnchanged = Boolean(prevSk && prevSk.name === sk.name && prevSk.description === sk.description && prevSk.enabled === sk.enabled && prevSk.visibility === sk.visibility && prevSk.kind === sk.kind && prevSk.customMain === sk.customMain && prevSk.revision === sk.revision && prevSk.previewHash === sk.previewHash && prevSk.profiles.join("\x00") === sk.profiles.join("\x00") && prevSk.scenes.join("\x00") === sk.scenes.join("\x00") && prevSk.requiresIds.join("\x00") === sk.requiresIds.join("\x00"));
|
|
4377
4581
|
const suspectedWebEdit = Boolean(metaUnchanged && prevSk && (prevSk.lastEditedTime !== sk.lastEditedTime || !isMinuteSettled));
|
|
4378
|
-
const needsBodyCheck = !sk.originSourceId || sk.customMain ? staleOrUnsettled && (isHotOrDefault || !isFull && inCurrentDelta) : Boolean(sk.previewHash && !isFull && inCurrentDelta && staleOrUnsettled && suspectedWebEdit);
|
|
4582
|
+
const needsBodyCheck = !sk.originSourceId || sk.customMain ? staleOrUnsettled && (isHotOrDefault || !isFull && hasPriorWatermark && inCurrentDelta) : Boolean(sk.previewHash && !isFull && hasPriorWatermark && inCurrentDelta && staleOrUnsettled && suspectedWebEdit);
|
|
4379
4583
|
if (needsBodyCheck) {
|
|
4584
|
+
bodyCheckTasks.push({ sk, settled: isMinuteSettled });
|
|
4585
|
+
}
|
|
4586
|
+
}
|
|
4587
|
+
const mutableMainCache = {
|
|
4588
|
+
...workingLibState.mainHashCache
|
|
4589
|
+
};
|
|
4590
|
+
const mutableFileBodyCache = { ...workingLibState.fileBodyCache };
|
|
4591
|
+
if (bodyCheckTasks.length > 0) {
|
|
4592
|
+
if (bodyCheckTasks.length >= 20) {
|
|
4593
|
+
emitSyncProgress(`Fetching ${bodyCheckTasks.length} Notion skill page(s)...`);
|
|
4594
|
+
}
|
|
4595
|
+
let fetchedBodies = 0;
|
|
4596
|
+
yield* Effect4.forEach(bodyCheckTasks, ({ sk, settled }) => Effect4.gen(function* () {
|
|
4380
4597
|
const body = yield* notion.readSkillBody(sk.id);
|
|
4381
4598
|
const rawHash = sha256Hex(body.rawMarkdown);
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
settled: isMinuteSettled,
|
|
4389
|
-
rawBody: body.rawMarkdown,
|
|
4390
|
-
rawBodySha256: rawHash,
|
|
4391
|
-
upstreamFilesPageId: body.upstreamFilesPageId
|
|
4392
|
-
}
|
|
4393
|
-
}
|
|
4599
|
+
mutableMainCache[sk.id] = {
|
|
4600
|
+
lastEditedTime: sk.lastEditedTime,
|
|
4601
|
+
settled,
|
|
4602
|
+
rawBody: body.rawMarkdown,
|
|
4603
|
+
rawBodySha256: rawHash,
|
|
4604
|
+
upstreamFilesPageId: body.upstreamFilesPageId
|
|
4394
4605
|
};
|
|
4395
|
-
|
|
4606
|
+
fetchedBodies++;
|
|
4607
|
+
if (fetchedBodies % 30 === 0) {
|
|
4608
|
+
if (bodyCheckTasks.length >= 20) {
|
|
4609
|
+
emitSyncProgress(`Fetched ${fetchedBodies}/${bodyCheckTasks.length} Notion skill page(s)...`);
|
|
4610
|
+
}
|
|
4611
|
+
yield* saveIntermediateCheckpoint(mutableMainCache, mutableFileBodyCache);
|
|
4612
|
+
}
|
|
4613
|
+
}), { concurrency: 4 });
|
|
4614
|
+
workingLibState = {
|
|
4615
|
+
...workingLibState,
|
|
4616
|
+
mainHashCache: { ...mutableMainCache }
|
|
4617
|
+
};
|
|
4618
|
+
yield* saveIntermediateCheckpoint(mutableMainCache, mutableFileBodyCache);
|
|
4619
|
+
}
|
|
4620
|
+
for (const sk of effectiveSkills) {
|
|
4396
4621
|
if (sk.originSourceId && !sk.customMain && sk.previewHash) {
|
|
4397
4622
|
const latestBodyHash = workingLibState.mainHashCache[sk.id]?.rawBodySha256;
|
|
4398
4623
|
if (latestBodyHash && latestBodyHash !== sk.previewHash) {
|
|
4399
4624
|
const msg = `Skill '${sk.name}': 网页预览存在未进入消费的修改(Custom Main=false),请勾选 Custom Main 或执行 'ntn-skills detach ${sk.name}'。`;
|
|
4400
4625
|
warnings.push(msg);
|
|
4401
|
-
skillWarnings.set(sk.id, [msg]);
|
|
4626
|
+
skillWarnings.set(sk.id, [...skillWarnings.get(sk.id) ?? [], msg]);
|
|
4402
4627
|
}
|
|
4403
4628
|
}
|
|
4404
4629
|
}
|
|
@@ -4415,6 +4640,7 @@ function syncCommand(options = {}) {
|
|
|
4415
4640
|
}
|
|
4416
4641
|
}
|
|
4417
4642
|
const resolvedCommits = new Map;
|
|
4643
|
+
const failedSourceHeadErrors = new Map;
|
|
4418
4644
|
for (const sk of effectiveSkills) {
|
|
4419
4645
|
if (!sk.originSourceId)
|
|
4420
4646
|
continue;
|
|
@@ -4425,10 +4651,15 @@ function syncCommand(options = {}) {
|
|
|
4425
4651
|
resolvedCommits.set(src.id, src.pinnedCommit);
|
|
4426
4652
|
} else if (cachedSourceCommits.has(src.id)) {
|
|
4427
4653
|
resolvedCommits.set(src.id, cachedSourceCommits.get(src.id));
|
|
4428
|
-
} else if (!resolvedCommits.has(src.id)) {
|
|
4654
|
+
} else if (!resolvedCommits.has(src.id) && !failedSourceHeadErrors.has(src.id)) {
|
|
4429
4655
|
if (sk.visibility === "always" || config.prefetch === "discoverable" && sk.visibility === "discoverable" || config.prefetch === "all-profiles") {
|
|
4430
|
-
const
|
|
4431
|
-
|
|
4656
|
+
const shaOrErr = yield* upstream.resolveHeadCommit(src.repoUrl, src.ref).pipe(Effect4.result);
|
|
4657
|
+
if (shaOrErr._tag === "Success") {
|
|
4658
|
+
resolvedCommits.set(src.id, shaOrErr.success);
|
|
4659
|
+
} else {
|
|
4660
|
+
failedSourceHeadErrors.set(src.id, shaOrErr.failure.message);
|
|
4661
|
+
resolvedCommits.set(src.id, `ref:${src.ref}`);
|
|
4662
|
+
}
|
|
4432
4663
|
} else {
|
|
4433
4664
|
resolvedCommits.set(src.id, `ref:${src.ref}`);
|
|
4434
4665
|
}
|
|
@@ -4469,30 +4700,89 @@ function syncCommand(options = {}) {
|
|
|
4469
4700
|
revMemo.set(skillId, rev);
|
|
4470
4701
|
return rev;
|
|
4471
4702
|
};
|
|
4703
|
+
const prevEntryById = new Map(currentCatalog.entries.filter((e) => e.libraryId === libraryId).map((e) => [e.skillId, e]));
|
|
4472
4704
|
const materializedPaths = new Map;
|
|
4473
4705
|
let materializedCount = 0;
|
|
4474
|
-
|
|
4706
|
+
const closureList = [...closureIds];
|
|
4707
|
+
if (closureList.length >= 20) {
|
|
4708
|
+
emitSyncProgress(`Materializing ${closureList.length} skill snapshot(s)...`);
|
|
4709
|
+
}
|
|
4710
|
+
let finishedMat = 0;
|
|
4711
|
+
yield* Effect4.forEach(closureList, (sid) => Effect4.gen(function* () {
|
|
4475
4712
|
const sk = effectiveById.get(sid);
|
|
4476
4713
|
const src = sk.originSourceId ? sourcesById.get(sk.originSourceId) ?? null : null;
|
|
4714
|
+
if (src && failedSourceHeadErrors.has(src.id)) {
|
|
4715
|
+
const errText = failedSourceHeadErrors.get(src.id);
|
|
4716
|
+
const warnMsg = `Skill '${sk.name}' skipped materialization due to unreachable upstream '${src.name}': ${errText}`;
|
|
4717
|
+
warnings.push(warnMsg);
|
|
4718
|
+
skillWarnings.set(sid, [...skillWarnings.get(sid) ?? [], warnMsg]);
|
|
4719
|
+
const fallbackPath = prevEntryById.get(sid)?.materializedPath;
|
|
4720
|
+
if (fallbackPath) {
|
|
4721
|
+
const exists = yield* Effect4.tryPromise(() => fsp5.stat(fallbackPath).then((s) => s.isDirectory()).catch(() => false)).pipe(Effect4.catch(() => Effect4.succeed(false)));
|
|
4722
|
+
if (exists)
|
|
4723
|
+
materializedPaths.set(sid, fallbackPath);
|
|
4724
|
+
}
|
|
4725
|
+
return;
|
|
4726
|
+
}
|
|
4477
4727
|
if (src && !src.pinnedCommit && (resolvedCommits.get(src.id) ?? "").startsWith("ref:")) {
|
|
4478
|
-
const
|
|
4479
|
-
|
|
4728
|
+
const headRes = yield* upstream.resolveHeadCommit(src.repoUrl, src.ref).pipe(Effect4.result);
|
|
4729
|
+
if (headRes._tag === "Failure") {
|
|
4730
|
+
const warnMsg = `Skill '${sk.name}' skipped materialization due to unreachable upstream '${src.name}': ${headRes.failure.message}`;
|
|
4731
|
+
warnings.push(warnMsg);
|
|
4732
|
+
skillWarnings.set(sid, [...skillWarnings.get(sid) ?? [], warnMsg]);
|
|
4733
|
+
return;
|
|
4734
|
+
}
|
|
4735
|
+
resolvedCommits.set(src.id, headRes.success);
|
|
4480
4736
|
revMemo.delete(sid);
|
|
4481
4737
|
}
|
|
4482
4738
|
const rev = getEffectiveRevFor(sid);
|
|
4483
|
-
const
|
|
4739
|
+
const matRes = yield* materializeOneSkill({
|
|
4484
4740
|
libraryId,
|
|
4485
4741
|
libState: workingLibState,
|
|
4486
4742
|
skill: sk,
|
|
4487
|
-
source: src ? {
|
|
4743
|
+
source: src ? {
|
|
4744
|
+
...src,
|
|
4745
|
+
pinnedCommit: src.pinnedCommit || (resolvedCommits.get(src.id) ?? "")
|
|
4746
|
+
} : null,
|
|
4488
4747
|
overlayFiles: filesBySkillId.get(sid) ?? [],
|
|
4489
4748
|
effectiveRev: rev
|
|
4490
|
-
});
|
|
4491
|
-
|
|
4749
|
+
}).pipe(Effect4.map((ok) => ({ ok: true, value: ok })), Effect4.catchTag("UpstreamError", (err) => Effect4.succeed({ ok: false, err })));
|
|
4750
|
+
if (!matRes.ok) {
|
|
4751
|
+
const warnMsg = `Skill '${sk.name}' skipped materialization due to upstream fetch error: ${matRes.err.message}`;
|
|
4752
|
+
warnings.push(warnMsg);
|
|
4753
|
+
skillWarnings.set(sid, [...skillWarnings.get(sid) ?? [], warnMsg]);
|
|
4754
|
+
const fallbackPath = prevEntryById.get(sid)?.materializedPath;
|
|
4755
|
+
if (fallbackPath) {
|
|
4756
|
+
const exists = yield* Effect4.tryPromise(() => fsp5.stat(fallbackPath).then((s) => s.isDirectory()).catch(() => false)).pipe(Effect4.catch(() => Effect4.succeed(false)));
|
|
4757
|
+
if (exists)
|
|
4758
|
+
materializedPaths.set(sid, fallbackPath);
|
|
4759
|
+
}
|
|
4760
|
+
return;
|
|
4761
|
+
}
|
|
4762
|
+
const mat = matRes.value;
|
|
4763
|
+
const mEntry = mat.updatedLibState.mainHashCache[sid];
|
|
4764
|
+
if (mEntry)
|
|
4765
|
+
mutableMainCache[sid] = mEntry;
|
|
4766
|
+
for (const ov of filesBySkillId.get(sid) ?? []) {
|
|
4767
|
+
const fEntry = mat.updatedLibState.fileBodyCache[ov.id];
|
|
4768
|
+
if (fEntry)
|
|
4769
|
+
mutableFileBodyCache[ov.id] = fEntry;
|
|
4770
|
+
}
|
|
4492
4771
|
materializedPaths.set(sid, mat.storeDir);
|
|
4493
4772
|
materializedCount++;
|
|
4494
|
-
|
|
4495
|
-
|
|
4773
|
+
finishedMat++;
|
|
4774
|
+
if (finishedMat % 25 === 0) {
|
|
4775
|
+
if (closureList.length >= 20) {
|
|
4776
|
+
emitSyncProgress(`Materialized ${finishedMat}/${closureList.length} skill snapshot(s)...`);
|
|
4777
|
+
}
|
|
4778
|
+
yield* saveIntermediateCheckpoint(mutableMainCache, mutableFileBodyCache);
|
|
4779
|
+
}
|
|
4780
|
+
}), { concurrency: 4 });
|
|
4781
|
+
workingLibState = {
|
|
4782
|
+
...workingLibState,
|
|
4783
|
+
mainHashCache: { ...mutableMainCache },
|
|
4784
|
+
fileBodyCache: { ...mutableFileBodyCache }
|
|
4785
|
+
};
|
|
4496
4786
|
const nextLibEntries = [];
|
|
4497
4787
|
for (const sk of catalogSkills) {
|
|
4498
4788
|
const src = sk.originSourceId ? sourcesById.get(sk.originSourceId) ?? null : null;
|
|
@@ -4551,7 +4841,7 @@ function syncCommand(options = {}) {
|
|
|
4551
4841
|
const manifestExports = [];
|
|
4552
4842
|
for (const exp of config.exports) {
|
|
4553
4843
|
const selectedSkills = selectExportSkills(catalogSkills, exp);
|
|
4554
|
-
const selectedEntries = selectedSkills.map((s) => entryMapById.get(s.id)).filter((e) => Boolean(e));
|
|
4844
|
+
const selectedEntries = selectedSkills.map((s) => entryMapById.get(s.id)).filter((e) => Boolean(e?.materializedPath));
|
|
4555
4845
|
const directNameSet = new Set(selectedEntries.map((e) => e.name.toLowerCase()));
|
|
4556
4846
|
const discoverableEntries = selectDiscoverableSkills(catalogSkills, exp).map((s) => entryMapById.get(s.id)).filter((e) => Boolean(e) && !directNameSet.has(e.name.toLowerCase()));
|
|
4557
4847
|
let routerEntry = null;
|
|
@@ -5091,6 +5381,45 @@ function loadSyncedLibrary(explicitLibraryId) {
|
|
|
5091
5381
|
return { config, libraryId, binding, catalog, libState: catalog.libraries[libraryId] };
|
|
5092
5382
|
});
|
|
5093
5383
|
}
|
|
5384
|
+
function loadTableMetadataLibrary(explicitLibraryId) {
|
|
5385
|
+
return Effect5.gen(function* () {
|
|
5386
|
+
const store = yield* StorePort;
|
|
5387
|
+
const notion = yield* NotionPort;
|
|
5388
|
+
const { config, libraryId, binding } = yield* loadResolvedLibrary(explicitLibraryId);
|
|
5389
|
+
const catalog = yield* store.readCatalog();
|
|
5390
|
+
const prevLib = catalog.libraries[libraryId] ?? {
|
|
5391
|
+
watermark: null,
|
|
5392
|
+
lastSyncedAt: null,
|
|
5393
|
+
sources: {},
|
|
5394
|
+
skills: {},
|
|
5395
|
+
files: {},
|
|
5396
|
+
mainHashCache: {},
|
|
5397
|
+
fileBodyCache: {}
|
|
5398
|
+
};
|
|
5399
|
+
const isFull = !prevLib.watermark;
|
|
5400
|
+
const delta = yield* notion.queryDelta({
|
|
5401
|
+
libraryId,
|
|
5402
|
+
binding,
|
|
5403
|
+
watermarkIso: isFull ? null : prevLib.watermark
|
|
5404
|
+
});
|
|
5405
|
+
const sources = isFull ? {} : { ...prevLib.sources };
|
|
5406
|
+
for (const s of delta.sources)
|
|
5407
|
+
sources[s.id] = s;
|
|
5408
|
+
const skills = isFull ? {} : { ...prevLib.skills };
|
|
5409
|
+
for (const sk of delta.skills)
|
|
5410
|
+
skills[sk.id] = sk;
|
|
5411
|
+
const files = isFull ? {} : { ...prevLib.files };
|
|
5412
|
+
for (const f of delta.files)
|
|
5413
|
+
files[f.id] = f;
|
|
5414
|
+
const libState = {
|
|
5415
|
+
...prevLib,
|
|
5416
|
+
sources,
|
|
5417
|
+
skills,
|
|
5418
|
+
files
|
|
5419
|
+
};
|
|
5420
|
+
return { config, libraryId, binding, catalog, libState };
|
|
5421
|
+
});
|
|
5422
|
+
}
|
|
5094
5423
|
function findSkillOrFail(libState, name) {
|
|
5095
5424
|
const needle = name.trim().toLowerCase();
|
|
5096
5425
|
const candidates = Object.values(libState.skills).filter((s) => s.name.toLowerCase() === needle).sort((a, b) => Number(b.enabled) - Number(a.enabled) || b.lastEditedTime.localeCompare(a.lastEditedTime));
|
|
@@ -6050,7 +6379,7 @@ function removeSkillCommand(args) {
|
|
|
6050
6379
|
});
|
|
6051
6380
|
}
|
|
6052
6381
|
function listSourcesCommand(args) {
|
|
6053
|
-
return
|
|
6382
|
+
return loadTableMetadataLibrary(args?.libraryId).pipe(Effect5.map(({ libState }) => Object.values(libState.sources).sort((a, b) => a.name.localeCompare(b.name))));
|
|
6054
6383
|
}
|
|
6055
6384
|
function addSourceCommand(args) {
|
|
6056
6385
|
return Effect5.gen(function* () {
|
|
@@ -6162,7 +6491,7 @@ function findSourceOrFail(libState, sourceQuery) {
|
|
|
6162
6491
|
function setSourceMetaCommand(args) {
|
|
6163
6492
|
return Effect5.gen(function* () {
|
|
6164
6493
|
const notion = yield* NotionPort;
|
|
6165
|
-
const { libraryId, libState } = yield*
|
|
6494
|
+
const { libraryId, libState } = yield* loadTableMetadataLibrary(args.libraryId);
|
|
6166
6495
|
const src = yield* findSourceOrFail(libState, args.sourceQuery);
|
|
6167
6496
|
yield* notion.updateSourceProps({
|
|
6168
6497
|
libraryId,
|
|
@@ -6183,7 +6512,7 @@ function syncSourceSkillsCommand(args) {
|
|
|
6183
6512
|
return Effect5.gen(function* () {
|
|
6184
6513
|
const notion = yield* NotionPort;
|
|
6185
6514
|
const upstream = yield* UpstreamPort;
|
|
6186
|
-
const { libraryId, binding, libState } = yield*
|
|
6515
|
+
const { libraryId, binding, libState } = yield* loadTableMetadataLibrary(args.libraryId);
|
|
6187
6516
|
const src = yield* findSourceOrFail(libState, args.sourceQuery);
|
|
6188
6517
|
if (!src.enabled) {
|
|
6189
6518
|
return yield* Effect5.fail(new NotFoundError({
|
|
@@ -6328,7 +6657,7 @@ function upstreamCheckOrApplyCommand(args) {
|
|
|
6328
6657
|
const startedAt = new Date(startedMs).toISOString();
|
|
6329
6658
|
const deadlineMs = args.timeoutSec !== undefined ? startedMs + Math.round(args.timeoutSec * 1000) : undefined;
|
|
6330
6659
|
const runCore = Effect5.gen(function* () {
|
|
6331
|
-
const { libraryId, binding, libState } = yield*
|
|
6660
|
+
const { libraryId, binding, libState } = yield* loadTableMetadataLibrary(args.libraryId);
|
|
6332
6661
|
const filesBySkillId = new Map;
|
|
6333
6662
|
for (const f of Object.values(libState.files)) {
|
|
6334
6663
|
const arr = filesBySkillId.get(f.skillId) ?? [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ntn-skills",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"ntn-skills": "./dist/bin.js"
|
|
@@ -37,6 +37,6 @@
|
|
|
37
37
|
"bun": ">=1.2.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@ntn-skills/core": "2.0.
|
|
40
|
+
"@ntn-skills/core": "2.0.2"
|
|
41
41
|
}
|
|
42
42
|
}
|