ntn-skills 2.0.0 → 2.0.1
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/dist/bin.js +366 -96
- 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/dist/bin.js
CHANGED
|
@@ -2980,13 +2980,92 @@ function parseGitHubRepo(repoUrl) {
|
|
|
2980
2980
|
}
|
|
2981
2981
|
return null;
|
|
2982
2982
|
}
|
|
2983
|
+
var DEFAULT_INTERNAL_NO_PROXY = ".ts.net,.local,.lan,.internal,.home.arpa,localhost,127.0.0.1,::1";
|
|
2984
|
+
function extractHostForProxyCheck(rawUrl) {
|
|
2985
|
+
const trimmed = rawUrl.trim();
|
|
2986
|
+
if (!trimmed)
|
|
2987
|
+
return null;
|
|
2988
|
+
try {
|
|
2989
|
+
if (/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//.test(trimmed)) {
|
|
2990
|
+
const u = new URL(trimmed);
|
|
2991
|
+
return u.hostname.replace(/^\[|\]$/g, "").toLowerCase();
|
|
2992
|
+
}
|
|
2993
|
+
} catch {}
|
|
2994
|
+
const scpMatch = trimmed.match(/^(?:[^@\s]+@)?([^:/\s]+):/);
|
|
2995
|
+
if (scpMatch?.[1]) {
|
|
2996
|
+
return scpMatch[1].replace(/^\[|\]$/g, "").toLowerCase();
|
|
2997
|
+
}
|
|
2998
|
+
return null;
|
|
2999
|
+
}
|
|
3000
|
+
function shouldBypassProxyForUrl(rawUrl) {
|
|
3001
|
+
const host = extractHostForProxyCheck(rawUrl);
|
|
3002
|
+
if (!host)
|
|
3003
|
+
return false;
|
|
3004
|
+
if (host === "localhost" || host === "127.0.0.1" || host === "::1" || host === "0.0.0.0" || !host.includes(".")) {
|
|
3005
|
+
return true;
|
|
3006
|
+
}
|
|
3007
|
+
if (host.endsWith(".ts.net") || host.endsWith(".local") || host.endsWith(".lan") || host.endsWith(".internal") || host.endsWith(".home.arpa")) {
|
|
3008
|
+
return true;
|
|
3009
|
+
}
|
|
3010
|
+
const ipv4 = host.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/);
|
|
3011
|
+
if (ipv4) {
|
|
3012
|
+
const a = Number(ipv4[1]);
|
|
3013
|
+
const b = Number(ipv4[2]);
|
|
3014
|
+
if (a === 10 || a === 127)
|
|
3015
|
+
return true;
|
|
3016
|
+
if (a === 192 && b === 168)
|
|
3017
|
+
return true;
|
|
3018
|
+
if (a === 172 && b >= 16 && b <= 31)
|
|
3019
|
+
return true;
|
|
3020
|
+
if (a === 100 && b >= 64 && b <= 127)
|
|
3021
|
+
return true;
|
|
3022
|
+
}
|
|
3023
|
+
return false;
|
|
3024
|
+
}
|
|
3025
|
+
function buildSubprocessEnv(bypassProxy) {
|
|
3026
|
+
const env = { ...process.env, GIT_TERMINAL_PROMPT: "0" };
|
|
3027
|
+
const existingNoProxy = env.NO_PROXY || env.no_proxy || "";
|
|
3028
|
+
const mergedNoProxy = Array.from(new Set(`${existingNoProxy},${DEFAULT_INTERNAL_NO_PROXY}`.split(",").map((s) => s.trim()).filter(Boolean))).join(",");
|
|
3029
|
+
env.NO_PROXY = mergedNoProxy;
|
|
3030
|
+
env.no_proxy = mergedNoProxy;
|
|
3031
|
+
if (bypassProxy) {
|
|
3032
|
+
for (const k of [
|
|
3033
|
+
"HTTP_PROXY",
|
|
3034
|
+
"HTTPS_PROXY",
|
|
3035
|
+
"ALL_PROXY",
|
|
3036
|
+
"http_proxy",
|
|
3037
|
+
"https_proxy",
|
|
3038
|
+
"all_proxy"
|
|
3039
|
+
]) {
|
|
3040
|
+
Reflect.deleteProperty(env, k);
|
|
3041
|
+
}
|
|
3042
|
+
}
|
|
3043
|
+
return env;
|
|
3044
|
+
}
|
|
3045
|
+
var repoGitLocks = new Map;
|
|
3046
|
+
async function withRepoGitLock(key, fn) {
|
|
3047
|
+
const prev = repoGitLocks.get(key) ?? Promise.resolve();
|
|
3048
|
+
const next = prev.catch(() => {
|
|
3049
|
+
return;
|
|
3050
|
+
}).then(fn);
|
|
3051
|
+
repoGitLocks.set(key, next);
|
|
3052
|
+
try {
|
|
3053
|
+
return await next;
|
|
3054
|
+
} finally {
|
|
3055
|
+
if (repoGitLocks.get(key) === next) {
|
|
3056
|
+
repoGitLocks.delete(key);
|
|
3057
|
+
}
|
|
3058
|
+
}
|
|
3059
|
+
}
|
|
2983
3060
|
async function runCmd(bin, args, opts) {
|
|
2984
3061
|
const timeoutMs = opts?.timeoutMs ?? 60000;
|
|
3062
|
+
const bypassProxy = Boolean(opts?.bypassProxy);
|
|
3063
|
+
const finalArgs = bypassProxy && bin === "git" ? ["-c", "http.proxy=", "-c", "https.proxy=", ...args] : [...args];
|
|
2985
3064
|
return new Promise((resolve, reject) => {
|
|
2986
|
-
const child = spawn3(bin,
|
|
3065
|
+
const child = spawn3(bin, finalArgs, {
|
|
2987
3066
|
cwd: opts?.cwd,
|
|
2988
3067
|
stdio: ["ignore", "pipe", "pipe"],
|
|
2989
|
-
env:
|
|
3068
|
+
env: buildSubprocessEnv(bypassProxy)
|
|
2990
3069
|
});
|
|
2991
3070
|
let stdout = "";
|
|
2992
3071
|
let stderr = "";
|
|
@@ -3056,8 +3135,19 @@ async function readAllTreeFiles(rootDir, currentRel = "") {
|
|
|
3056
3135
|
}
|
|
3057
3136
|
var UpstreamLiveLayer = Layer3.effect(UpstreamPort, Effect3.gen(function* () {
|
|
3058
3137
|
const store = yield* StorePort;
|
|
3059
|
-
const
|
|
3138
|
+
const fullTreeInFlight = new Map;
|
|
3139
|
+
const ensureFullCommitTree = (repoUrl, commitSha) => {
|
|
3060
3140
|
const treeKey = sha256Hex(`${repoUrl.trim()}@${commitSha.trim()}`).slice(0, 24);
|
|
3141
|
+
const existingFlight = fullTreeInFlight.get(treeKey);
|
|
3142
|
+
if (existingFlight)
|
|
3143
|
+
return existingFlight;
|
|
3144
|
+
const p = ensureFullCommitTreeImpl(repoUrl, commitSha, treeKey).finally(() => {
|
|
3145
|
+
fullTreeInFlight.delete(treeKey);
|
|
3146
|
+
});
|
|
3147
|
+
fullTreeInFlight.set(treeKey, p);
|
|
3148
|
+
return p;
|
|
3149
|
+
};
|
|
3150
|
+
const ensureFullCommitTreeImpl = async (repoUrl, commitSha, treeKey) => {
|
|
3061
3151
|
const cachedTreeDir = nodePath4.join(store.paths.reposRoot, "trees", treeKey);
|
|
3062
3152
|
const marker = nodePath4.join(cachedTreeDir, ".ntn-tree-ready");
|
|
3063
3153
|
if (await fsp4.stat(marker).then(() => true).catch(() => false)) {
|
|
@@ -3104,51 +3194,56 @@ var UpstreamLiveLayer = Layer3.effect(UpstreamPort, Effect3.gen(function* () {
|
|
|
3104
3194
|
} catch {}
|
|
3105
3195
|
}
|
|
3106
3196
|
if (!extractedRoot) {
|
|
3107
|
-
const
|
|
3108
|
-
|
|
3109
|
-
const
|
|
3110
|
-
|
|
3111
|
-
await
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
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()}`
|
|
3197
|
+
const bypassProxy = shouldBypassProxyForUrl(repoUrl);
|
|
3198
|
+
const repoLockKey = sha256Hex(repoUrl.trim()).slice(0, 16);
|
|
3199
|
+
const gitCacheDir = nodePath4.join(store.paths.reposRoot, "git", repoLockKey);
|
|
3200
|
+
extractedRoot = await withRepoGitLock(repoLockKey, async () => {
|
|
3201
|
+
await fsp4.mkdir(gitCacheDir, { recursive: true });
|
|
3202
|
+
const hasHead = await fsp4.stat(nodePath4.join(gitCacheDir, "HEAD")).then(() => true).catch(() => false);
|
|
3203
|
+
if (!hasHead) {
|
|
3204
|
+
await runCmd("git", ["init", "--bare"], { cwd: gitCacheDir });
|
|
3205
|
+
}
|
|
3206
|
+
await runCmd("git", ["config", "remote.origin.url", repoUrl], { cwd: gitCacheDir });
|
|
3207
|
+
await runCmd("git", ["config", "--unset", "remote.origin.promisor"], {
|
|
3208
|
+
cwd: gitCacheDir
|
|
3209
|
+
}).catch(() => {
|
|
3210
|
+
return;
|
|
3132
3211
|
});
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
throw new UpstreamError({
|
|
3138
|
-
url: repoUrl,
|
|
3139
|
-
message: `Failed archiving ${repoUrl}@${commitSha}: ${archRes.stderr.trim()}`
|
|
3212
|
+
await runCmd("git", ["config", "--unset", "remote.origin.partialclonefilter"], {
|
|
3213
|
+
cwd: gitCacheDir
|
|
3214
|
+
}).catch(() => {
|
|
3215
|
+
return;
|
|
3140
3216
|
});
|
|
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()}`
|
|
3217
|
+
const fetchRes = await runCmd("git", ["fetch", "--depth", "1", "origin", commitSha], {
|
|
3218
|
+
cwd: gitCacheDir,
|
|
3219
|
+
timeoutMs: 120000,
|
|
3220
|
+
bypassProxy
|
|
3149
3221
|
});
|
|
3150
|
-
|
|
3151
|
-
|
|
3222
|
+
if (fetchRes.code !== 0) {
|
|
3223
|
+
throw new UpstreamError({
|
|
3224
|
+
url: repoUrl,
|
|
3225
|
+
message: `Failed fetching ${repoUrl}@${commitSha}: ${fetchRes.stderr.trim()}`
|
|
3226
|
+
});
|
|
3227
|
+
}
|
|
3228
|
+
const tarPath = nodePath4.join(tmpBase, "git-archive.tar");
|
|
3229
|
+
const archRes = await runCmd("git", ["archive", "--format=tar", "-o", tarPath, "FETCH_HEAD"], { cwd: gitCacheDir, timeoutMs: 120000 });
|
|
3230
|
+
if (archRes.code !== 0) {
|
|
3231
|
+
throw new UpstreamError({
|
|
3232
|
+
url: repoUrl,
|
|
3233
|
+
message: `Failed archiving ${repoUrl}@${commitSha}: ${archRes.stderr.trim()}`
|
|
3234
|
+
});
|
|
3235
|
+
}
|
|
3236
|
+
const subOut = nodePath4.join(unpackDir, "git-tree");
|
|
3237
|
+
await fsp4.mkdir(subOut, { recursive: true });
|
|
3238
|
+
const untar = await runCmd("tar", ["-xf", tarPath, "-C", subOut]);
|
|
3239
|
+
if (untar.code !== 0) {
|
|
3240
|
+
throw new UpstreamError({
|
|
3241
|
+
url: repoUrl,
|
|
3242
|
+
message: `Failed unpacking archive for ${repoUrl}@${commitSha}: ${untar.stderr.trim()}`
|
|
3243
|
+
});
|
|
3244
|
+
}
|
|
3245
|
+
return subOut;
|
|
3246
|
+
});
|
|
3152
3247
|
}
|
|
3153
3248
|
await fsp4.writeFile(nodePath4.join(extractedRoot, ".ntn-tree-ready"), `${commitSha}
|
|
3154
3249
|
`, "utf8");
|
|
@@ -3189,7 +3284,10 @@ var UpstreamLiveLayer = Layer3.effect(UpstreamPort, Effect3.gen(function* () {
|
|
|
3189
3284
|
}
|
|
3190
3285
|
}
|
|
3191
3286
|
}
|
|
3192
|
-
const ls = await runCmd("git", ["ls-remote", repoUrl, ref], {
|
|
3287
|
+
const ls = await runCmd("git", ["ls-remote", repoUrl, ref], {
|
|
3288
|
+
timeoutMs: 30000,
|
|
3289
|
+
bypassProxy: shouldBypassProxyForUrl(repoUrl)
|
|
3290
|
+
});
|
|
3193
3291
|
if (ls.code !== 0 || !ls.stdout.trim()) {
|
|
3194
3292
|
throw new UpstreamError({
|
|
3195
3293
|
url: repoUrl,
|
|
@@ -3290,27 +3388,35 @@ var UpstreamLiveLayer = Layer3.effect(UpstreamPort, Effect3.gen(function* () {
|
|
|
3290
3388
|
}
|
|
3291
3389
|
} catch {}
|
|
3292
3390
|
}
|
|
3293
|
-
const
|
|
3294
|
-
|
|
3295
|
-
const
|
|
3296
|
-
|
|
3297
|
-
await
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3391
|
+
const bypassProxy = shouldBypassProxyForUrl(repoUrl);
|
|
3392
|
+
const repoLockKey = sha256Hex(repoUrl.trim()).slice(0, 16);
|
|
3393
|
+
const gitCacheDir = nodePath4.join(store.paths.reposRoot, "git", repoLockKey);
|
|
3394
|
+
const sparseArchive = await withRepoGitLock(repoLockKey, async () => {
|
|
3395
|
+
await fsp4.mkdir(gitCacheDir, { recursive: true });
|
|
3396
|
+
const hasHead = await fsp4.stat(nodePath4.join(gitCacheDir, "HEAD")).then(() => true).catch(() => false);
|
|
3397
|
+
if (!hasHead) {
|
|
3398
|
+
await runCmd("git", ["init", "--bare"], { cwd: gitCacheDir });
|
|
3399
|
+
}
|
|
3400
|
+
await runCmd("git", ["config", "remote.origin.url", repoUrl], { cwd: gitCacheDir });
|
|
3401
|
+
await runCmd("git", ["config", "remote.origin.promisor", "true"], {
|
|
3402
|
+
cwd: gitCacheDir
|
|
3403
|
+
});
|
|
3404
|
+
await runCmd("git", ["config", "remote.origin.partialclonefilter", "blob:none"], {
|
|
3405
|
+
cwd: gitCacheDir
|
|
3406
|
+
});
|
|
3407
|
+
const fetchRes = await runCmd("git", ["fetch", "--depth", "1", "--filter=blob:none", "origin", commitSha], { cwd: gitCacheDir, timeoutMs: 60000, bypassProxy });
|
|
3408
|
+
if (fetchRes.code !== 0)
|
|
3409
|
+
return null;
|
|
3308
3410
|
const tmpSub = nodePath4.join(store.paths.reposRoot, ".tmp", `gsub-${process.pid}-${randomUUID3()}`);
|
|
3309
3411
|
await fsp4.mkdir(tmpSub, { recursive: true });
|
|
3412
|
+
const tarPath = nodePath4.join(tmpSub, "sub.tar");
|
|
3413
|
+
const archRes = await runCmd("git", ["archive", "--format=tar", "-o", tarPath, "FETCH_HEAD", "--", cleanSub], { cwd: gitCacheDir, timeoutMs: 45000 });
|
|
3414
|
+
return { tmpSub, tarPath, archCode: archRes.code };
|
|
3415
|
+
});
|
|
3416
|
+
if (sparseArchive) {
|
|
3417
|
+
const { tmpSub, tarPath, archCode } = sparseArchive;
|
|
3310
3418
|
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) {
|
|
3419
|
+
if (archCode === 0) {
|
|
3314
3420
|
const unpackSub = nodePath4.join(tmpSub, "unpack");
|
|
3315
3421
|
await fsp4.mkdir(unpackSub, { recursive: true });
|
|
3316
3422
|
const untar = await runCmd("tar", ["-xf", tarPath, "-C", unpackSub]);
|
|
@@ -3530,6 +3636,21 @@ var UpstreamLiveLayer = Layer3.effect(UpstreamPort, Effect3.gen(function* () {
|
|
|
3530
3636
|
headers.Authorization = `Bearer ${token}`;
|
|
3531
3637
|
}
|
|
3532
3638
|
}
|
|
3639
|
+
if (shouldBypassProxyForUrl(url)) {
|
|
3640
|
+
const tmpAsset = nodePath4.join(store.paths.reposRoot, ".tmp", `asset-${process.pid}-${randomUUID3()}`);
|
|
3641
|
+
await fsp4.mkdir(nodePath4.dirname(tmpAsset), { recursive: true });
|
|
3642
|
+
try {
|
|
3643
|
+
const dl = await runCmd("curl", ["-fsSL", "--noproxy", "*", "--max-time", "30", "-o", tmpAsset, url], { timeoutMs: 35000, bypassProxy: true });
|
|
3644
|
+
if (dl.code === 0) {
|
|
3645
|
+
const buf = await fsp4.readFile(tmpAsset);
|
|
3646
|
+
return new Uint8Array(buf);
|
|
3647
|
+
}
|
|
3648
|
+
} finally {
|
|
3649
|
+
await moveToSystemTrash(tmpAsset).catch(() => {
|
|
3650
|
+
return;
|
|
3651
|
+
});
|
|
3652
|
+
}
|
|
3653
|
+
}
|
|
3533
3654
|
let res = await fetch(url, {
|
|
3534
3655
|
headers,
|
|
3535
3656
|
redirect: "follow",
|
|
@@ -4365,7 +4486,31 @@ function syncCommand(options = {}) {
|
|
|
4365
4486
|
warnings.push(w);
|
|
4366
4487
|
skillWarnings.set(sid, [...skillWarnings.get(sid) ?? [], w]);
|
|
4367
4488
|
}
|
|
4489
|
+
const emitSyncProgress = (msg) => {
|
|
4490
|
+
if (process.env.NTN_SKILLS_TEST_ONLY === "1" || process.env.NTN_SKILLS_QUIET === "1") {
|
|
4491
|
+
return;
|
|
4492
|
+
}
|
|
4493
|
+
process.stderr.write(`[ntn-skills] ${msg}
|
|
4494
|
+
`);
|
|
4495
|
+
};
|
|
4496
|
+
const saveIntermediateCheckpoint = (mainCacheSnapshot, fileCacheSnapshot) => store.writeCatalog({
|
|
4497
|
+
version: 2,
|
|
4498
|
+
updatedAt: currentCatalog.updatedAt || syncStartIso,
|
|
4499
|
+
libraries: {
|
|
4500
|
+
...currentCatalog.libraries,
|
|
4501
|
+
[libraryId]: {
|
|
4502
|
+
...workingLibState,
|
|
4503
|
+
watermark: prevLib.watermark,
|
|
4504
|
+
lastSyncedAt: prevLib.lastSyncedAt,
|
|
4505
|
+
mainHashCache: { ...mainCacheSnapshot },
|
|
4506
|
+
fileBodyCache: { ...fileCacheSnapshot }
|
|
4507
|
+
}
|
|
4508
|
+
},
|
|
4509
|
+
entries: currentCatalog.entries
|
|
4510
|
+
}).pipe(Effect4.catch(() => Effect4.void));
|
|
4368
4511
|
const currentNowMs = options.nowMs ?? Date.now();
|
|
4512
|
+
const hasPriorWatermark = Boolean(prevLib.watermark);
|
|
4513
|
+
const bodyCheckTasks = [];
|
|
4369
4514
|
for (const sk of effectiveSkills) {
|
|
4370
4515
|
const cached = workingLibState.mainHashCache[sk.id];
|
|
4371
4516
|
const inCurrentDelta = deltaSkillIds.has(sk.id);
|
|
@@ -4375,30 +4520,51 @@ function syncCommand(options = {}) {
|
|
|
4375
4520
|
const prevSk = prevLib.skills[sk.id];
|
|
4376
4521
|
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
4522
|
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);
|
|
4523
|
+
const needsBodyCheck = !sk.originSourceId || sk.customMain ? staleOrUnsettled && (isHotOrDefault || !isFull && hasPriorWatermark && inCurrentDelta) : Boolean(sk.previewHash && !isFull && hasPriorWatermark && inCurrentDelta && staleOrUnsettled && suspectedWebEdit);
|
|
4379
4524
|
if (needsBodyCheck) {
|
|
4525
|
+
bodyCheckTasks.push({ sk, settled: isMinuteSettled });
|
|
4526
|
+
}
|
|
4527
|
+
}
|
|
4528
|
+
const mutableMainCache = {
|
|
4529
|
+
...workingLibState.mainHashCache
|
|
4530
|
+
};
|
|
4531
|
+
const mutableFileBodyCache = { ...workingLibState.fileBodyCache };
|
|
4532
|
+
if (bodyCheckTasks.length > 0) {
|
|
4533
|
+
if (bodyCheckTasks.length >= 20) {
|
|
4534
|
+
emitSyncProgress(`Fetching ${bodyCheckTasks.length} Notion skill page(s)...`);
|
|
4535
|
+
}
|
|
4536
|
+
let fetchedBodies = 0;
|
|
4537
|
+
yield* Effect4.forEach(bodyCheckTasks, ({ sk, settled }) => Effect4.gen(function* () {
|
|
4380
4538
|
const body = yield* notion.readSkillBody(sk.id);
|
|
4381
4539
|
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
|
-
}
|
|
4540
|
+
mutableMainCache[sk.id] = {
|
|
4541
|
+
lastEditedTime: sk.lastEditedTime,
|
|
4542
|
+
settled,
|
|
4543
|
+
rawBody: body.rawMarkdown,
|
|
4544
|
+
rawBodySha256: rawHash,
|
|
4545
|
+
upstreamFilesPageId: body.upstreamFilesPageId
|
|
4394
4546
|
};
|
|
4395
|
-
|
|
4547
|
+
fetchedBodies++;
|
|
4548
|
+
if (fetchedBodies % 30 === 0) {
|
|
4549
|
+
if (bodyCheckTasks.length >= 20) {
|
|
4550
|
+
emitSyncProgress(`Fetched ${fetchedBodies}/${bodyCheckTasks.length} Notion skill page(s)...`);
|
|
4551
|
+
}
|
|
4552
|
+
yield* saveIntermediateCheckpoint(mutableMainCache, mutableFileBodyCache);
|
|
4553
|
+
}
|
|
4554
|
+
}), { concurrency: 4 });
|
|
4555
|
+
workingLibState = {
|
|
4556
|
+
...workingLibState,
|
|
4557
|
+
mainHashCache: { ...mutableMainCache }
|
|
4558
|
+
};
|
|
4559
|
+
yield* saveIntermediateCheckpoint(mutableMainCache, mutableFileBodyCache);
|
|
4560
|
+
}
|
|
4561
|
+
for (const sk of effectiveSkills) {
|
|
4396
4562
|
if (sk.originSourceId && !sk.customMain && sk.previewHash) {
|
|
4397
4563
|
const latestBodyHash = workingLibState.mainHashCache[sk.id]?.rawBodySha256;
|
|
4398
4564
|
if (latestBodyHash && latestBodyHash !== sk.previewHash) {
|
|
4399
4565
|
const msg = `Skill '${sk.name}': 网页预览存在未进入消费的修改(Custom Main=false),请勾选 Custom Main 或执行 'ntn-skills detach ${sk.name}'。`;
|
|
4400
4566
|
warnings.push(msg);
|
|
4401
|
-
skillWarnings.set(sk.id, [msg]);
|
|
4567
|
+
skillWarnings.set(sk.id, [...skillWarnings.get(sk.id) ?? [], msg]);
|
|
4402
4568
|
}
|
|
4403
4569
|
}
|
|
4404
4570
|
}
|
|
@@ -4415,6 +4581,7 @@ function syncCommand(options = {}) {
|
|
|
4415
4581
|
}
|
|
4416
4582
|
}
|
|
4417
4583
|
const resolvedCommits = new Map;
|
|
4584
|
+
const failedSourceHeadErrors = new Map;
|
|
4418
4585
|
for (const sk of effectiveSkills) {
|
|
4419
4586
|
if (!sk.originSourceId)
|
|
4420
4587
|
continue;
|
|
@@ -4425,10 +4592,15 @@ function syncCommand(options = {}) {
|
|
|
4425
4592
|
resolvedCommits.set(src.id, src.pinnedCommit);
|
|
4426
4593
|
} else if (cachedSourceCommits.has(src.id)) {
|
|
4427
4594
|
resolvedCommits.set(src.id, cachedSourceCommits.get(src.id));
|
|
4428
|
-
} else if (!resolvedCommits.has(src.id)) {
|
|
4595
|
+
} else if (!resolvedCommits.has(src.id) && !failedSourceHeadErrors.has(src.id)) {
|
|
4429
4596
|
if (sk.visibility === "always" || config.prefetch === "discoverable" && sk.visibility === "discoverable" || config.prefetch === "all-profiles") {
|
|
4430
|
-
const
|
|
4431
|
-
|
|
4597
|
+
const shaOrErr = yield* upstream.resolveHeadCommit(src.repoUrl, src.ref).pipe(Effect4.result);
|
|
4598
|
+
if (shaOrErr._tag === "Success") {
|
|
4599
|
+
resolvedCommits.set(src.id, shaOrErr.success);
|
|
4600
|
+
} else {
|
|
4601
|
+
failedSourceHeadErrors.set(src.id, shaOrErr.failure.message);
|
|
4602
|
+
resolvedCommits.set(src.id, `ref:${src.ref}`);
|
|
4603
|
+
}
|
|
4432
4604
|
} else {
|
|
4433
4605
|
resolvedCommits.set(src.id, `ref:${src.ref}`);
|
|
4434
4606
|
}
|
|
@@ -4469,30 +4641,89 @@ function syncCommand(options = {}) {
|
|
|
4469
4641
|
revMemo.set(skillId, rev);
|
|
4470
4642
|
return rev;
|
|
4471
4643
|
};
|
|
4644
|
+
const prevEntryById = new Map(currentCatalog.entries.filter((e) => e.libraryId === libraryId).map((e) => [e.skillId, e]));
|
|
4472
4645
|
const materializedPaths = new Map;
|
|
4473
4646
|
let materializedCount = 0;
|
|
4474
|
-
|
|
4647
|
+
const closureList = [...closureIds];
|
|
4648
|
+
if (closureList.length >= 20) {
|
|
4649
|
+
emitSyncProgress(`Materializing ${closureList.length} skill snapshot(s)...`);
|
|
4650
|
+
}
|
|
4651
|
+
let finishedMat = 0;
|
|
4652
|
+
yield* Effect4.forEach(closureList, (sid) => Effect4.gen(function* () {
|
|
4475
4653
|
const sk = effectiveById.get(sid);
|
|
4476
4654
|
const src = sk.originSourceId ? sourcesById.get(sk.originSourceId) ?? null : null;
|
|
4655
|
+
if (src && failedSourceHeadErrors.has(src.id)) {
|
|
4656
|
+
const errText = failedSourceHeadErrors.get(src.id);
|
|
4657
|
+
const warnMsg = `Skill '${sk.name}' skipped materialization due to unreachable upstream '${src.name}': ${errText}`;
|
|
4658
|
+
warnings.push(warnMsg);
|
|
4659
|
+
skillWarnings.set(sid, [...skillWarnings.get(sid) ?? [], warnMsg]);
|
|
4660
|
+
const fallbackPath = prevEntryById.get(sid)?.materializedPath;
|
|
4661
|
+
if (fallbackPath) {
|
|
4662
|
+
const exists = yield* Effect4.tryPromise(() => fsp5.stat(fallbackPath).then((s) => s.isDirectory()).catch(() => false)).pipe(Effect4.catch(() => Effect4.succeed(false)));
|
|
4663
|
+
if (exists)
|
|
4664
|
+
materializedPaths.set(sid, fallbackPath);
|
|
4665
|
+
}
|
|
4666
|
+
return;
|
|
4667
|
+
}
|
|
4477
4668
|
if (src && !src.pinnedCommit && (resolvedCommits.get(src.id) ?? "").startsWith("ref:")) {
|
|
4478
|
-
const
|
|
4479
|
-
|
|
4669
|
+
const headRes = yield* upstream.resolveHeadCommit(src.repoUrl, src.ref).pipe(Effect4.result);
|
|
4670
|
+
if (headRes._tag === "Failure") {
|
|
4671
|
+
const warnMsg = `Skill '${sk.name}' skipped materialization due to unreachable upstream '${src.name}': ${headRes.failure.message}`;
|
|
4672
|
+
warnings.push(warnMsg);
|
|
4673
|
+
skillWarnings.set(sid, [...skillWarnings.get(sid) ?? [], warnMsg]);
|
|
4674
|
+
return;
|
|
4675
|
+
}
|
|
4676
|
+
resolvedCommits.set(src.id, headRes.success);
|
|
4480
4677
|
revMemo.delete(sid);
|
|
4481
4678
|
}
|
|
4482
4679
|
const rev = getEffectiveRevFor(sid);
|
|
4483
|
-
const
|
|
4680
|
+
const matRes = yield* materializeOneSkill({
|
|
4484
4681
|
libraryId,
|
|
4485
4682
|
libState: workingLibState,
|
|
4486
4683
|
skill: sk,
|
|
4487
|
-
source: src ? {
|
|
4684
|
+
source: src ? {
|
|
4685
|
+
...src,
|
|
4686
|
+
pinnedCommit: src.pinnedCommit || (resolvedCommits.get(src.id) ?? "")
|
|
4687
|
+
} : null,
|
|
4488
4688
|
overlayFiles: filesBySkillId.get(sid) ?? [],
|
|
4489
4689
|
effectiveRev: rev
|
|
4490
|
-
});
|
|
4491
|
-
|
|
4690
|
+
}).pipe(Effect4.map((ok) => ({ ok: true, value: ok })), Effect4.catchTag("UpstreamError", (err) => Effect4.succeed({ ok: false, err })));
|
|
4691
|
+
if (!matRes.ok) {
|
|
4692
|
+
const warnMsg = `Skill '${sk.name}' skipped materialization due to upstream fetch error: ${matRes.err.message}`;
|
|
4693
|
+
warnings.push(warnMsg);
|
|
4694
|
+
skillWarnings.set(sid, [...skillWarnings.get(sid) ?? [], warnMsg]);
|
|
4695
|
+
const fallbackPath = prevEntryById.get(sid)?.materializedPath;
|
|
4696
|
+
if (fallbackPath) {
|
|
4697
|
+
const exists = yield* Effect4.tryPromise(() => fsp5.stat(fallbackPath).then((s) => s.isDirectory()).catch(() => false)).pipe(Effect4.catch(() => Effect4.succeed(false)));
|
|
4698
|
+
if (exists)
|
|
4699
|
+
materializedPaths.set(sid, fallbackPath);
|
|
4700
|
+
}
|
|
4701
|
+
return;
|
|
4702
|
+
}
|
|
4703
|
+
const mat = matRes.value;
|
|
4704
|
+
const mEntry = mat.updatedLibState.mainHashCache[sid];
|
|
4705
|
+
if (mEntry)
|
|
4706
|
+
mutableMainCache[sid] = mEntry;
|
|
4707
|
+
for (const ov of filesBySkillId.get(sid) ?? []) {
|
|
4708
|
+
const fEntry = mat.updatedLibState.fileBodyCache[ov.id];
|
|
4709
|
+
if (fEntry)
|
|
4710
|
+
mutableFileBodyCache[ov.id] = fEntry;
|
|
4711
|
+
}
|
|
4492
4712
|
materializedPaths.set(sid, mat.storeDir);
|
|
4493
4713
|
materializedCount++;
|
|
4494
|
-
|
|
4495
|
-
|
|
4714
|
+
finishedMat++;
|
|
4715
|
+
if (finishedMat % 25 === 0) {
|
|
4716
|
+
if (closureList.length >= 20) {
|
|
4717
|
+
emitSyncProgress(`Materialized ${finishedMat}/${closureList.length} skill snapshot(s)...`);
|
|
4718
|
+
}
|
|
4719
|
+
yield* saveIntermediateCheckpoint(mutableMainCache, mutableFileBodyCache);
|
|
4720
|
+
}
|
|
4721
|
+
}), { concurrency: 4 });
|
|
4722
|
+
workingLibState = {
|
|
4723
|
+
...workingLibState,
|
|
4724
|
+
mainHashCache: { ...mutableMainCache },
|
|
4725
|
+
fileBodyCache: { ...mutableFileBodyCache }
|
|
4726
|
+
};
|
|
4496
4727
|
const nextLibEntries = [];
|
|
4497
4728
|
for (const sk of catalogSkills) {
|
|
4498
4729
|
const src = sk.originSourceId ? sourcesById.get(sk.originSourceId) ?? null : null;
|
|
@@ -4551,7 +4782,7 @@ function syncCommand(options = {}) {
|
|
|
4551
4782
|
const manifestExports = [];
|
|
4552
4783
|
for (const exp of config.exports) {
|
|
4553
4784
|
const selectedSkills = selectExportSkills(catalogSkills, exp);
|
|
4554
|
-
const selectedEntries = selectedSkills.map((s) => entryMapById.get(s.id)).filter((e) => Boolean(e));
|
|
4785
|
+
const selectedEntries = selectedSkills.map((s) => entryMapById.get(s.id)).filter((e) => Boolean(e?.materializedPath));
|
|
4555
4786
|
const directNameSet = new Set(selectedEntries.map((e) => e.name.toLowerCase()));
|
|
4556
4787
|
const discoverableEntries = selectDiscoverableSkills(catalogSkills, exp).map((s) => entryMapById.get(s.id)).filter((e) => Boolean(e) && !directNameSet.has(e.name.toLowerCase()));
|
|
4557
4788
|
let routerEntry = null;
|
|
@@ -5091,6 +5322,45 @@ function loadSyncedLibrary(explicitLibraryId) {
|
|
|
5091
5322
|
return { config, libraryId, binding, catalog, libState: catalog.libraries[libraryId] };
|
|
5092
5323
|
});
|
|
5093
5324
|
}
|
|
5325
|
+
function loadTableMetadataLibrary(explicitLibraryId) {
|
|
5326
|
+
return Effect5.gen(function* () {
|
|
5327
|
+
const store = yield* StorePort;
|
|
5328
|
+
const notion = yield* NotionPort;
|
|
5329
|
+
const { config, libraryId, binding } = yield* loadResolvedLibrary(explicitLibraryId);
|
|
5330
|
+
const catalog = yield* store.readCatalog();
|
|
5331
|
+
const prevLib = catalog.libraries[libraryId] ?? {
|
|
5332
|
+
watermark: null,
|
|
5333
|
+
lastSyncedAt: null,
|
|
5334
|
+
sources: {},
|
|
5335
|
+
skills: {},
|
|
5336
|
+
files: {},
|
|
5337
|
+
mainHashCache: {},
|
|
5338
|
+
fileBodyCache: {}
|
|
5339
|
+
};
|
|
5340
|
+
const isFull = !prevLib.watermark;
|
|
5341
|
+
const delta = yield* notion.queryDelta({
|
|
5342
|
+
libraryId,
|
|
5343
|
+
binding,
|
|
5344
|
+
watermarkIso: isFull ? null : prevLib.watermark
|
|
5345
|
+
});
|
|
5346
|
+
const sources = isFull ? {} : { ...prevLib.sources };
|
|
5347
|
+
for (const s of delta.sources)
|
|
5348
|
+
sources[s.id] = s;
|
|
5349
|
+
const skills = isFull ? {} : { ...prevLib.skills };
|
|
5350
|
+
for (const sk of delta.skills)
|
|
5351
|
+
skills[sk.id] = sk;
|
|
5352
|
+
const files = isFull ? {} : { ...prevLib.files };
|
|
5353
|
+
for (const f of delta.files)
|
|
5354
|
+
files[f.id] = f;
|
|
5355
|
+
const libState = {
|
|
5356
|
+
...prevLib,
|
|
5357
|
+
sources,
|
|
5358
|
+
skills,
|
|
5359
|
+
files
|
|
5360
|
+
};
|
|
5361
|
+
return { config, libraryId, binding, catalog, libState };
|
|
5362
|
+
});
|
|
5363
|
+
}
|
|
5094
5364
|
function findSkillOrFail(libState, name) {
|
|
5095
5365
|
const needle = name.trim().toLowerCase();
|
|
5096
5366
|
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 +6320,7 @@ function removeSkillCommand(args) {
|
|
|
6050
6320
|
});
|
|
6051
6321
|
}
|
|
6052
6322
|
function listSourcesCommand(args) {
|
|
6053
|
-
return
|
|
6323
|
+
return loadTableMetadataLibrary(args?.libraryId).pipe(Effect5.map(({ libState }) => Object.values(libState.sources).sort((a, b) => a.name.localeCompare(b.name))));
|
|
6054
6324
|
}
|
|
6055
6325
|
function addSourceCommand(args) {
|
|
6056
6326
|
return Effect5.gen(function* () {
|
|
@@ -6162,7 +6432,7 @@ function findSourceOrFail(libState, sourceQuery) {
|
|
|
6162
6432
|
function setSourceMetaCommand(args) {
|
|
6163
6433
|
return Effect5.gen(function* () {
|
|
6164
6434
|
const notion = yield* NotionPort;
|
|
6165
|
-
const { libraryId, libState } = yield*
|
|
6435
|
+
const { libraryId, libState } = yield* loadTableMetadataLibrary(args.libraryId);
|
|
6166
6436
|
const src = yield* findSourceOrFail(libState, args.sourceQuery);
|
|
6167
6437
|
yield* notion.updateSourceProps({
|
|
6168
6438
|
libraryId,
|
|
@@ -6183,7 +6453,7 @@ function syncSourceSkillsCommand(args) {
|
|
|
6183
6453
|
return Effect5.gen(function* () {
|
|
6184
6454
|
const notion = yield* NotionPort;
|
|
6185
6455
|
const upstream = yield* UpstreamPort;
|
|
6186
|
-
const { libraryId, binding, libState } = yield*
|
|
6456
|
+
const { libraryId, binding, libState } = yield* loadTableMetadataLibrary(args.libraryId);
|
|
6187
6457
|
const src = yield* findSourceOrFail(libState, args.sourceQuery);
|
|
6188
6458
|
if (!src.enabled) {
|
|
6189
6459
|
return yield* Effect5.fail(new NotFoundError({
|
|
@@ -6328,7 +6598,7 @@ function upstreamCheckOrApplyCommand(args) {
|
|
|
6328
6598
|
const startedAt = new Date(startedMs).toISOString();
|
|
6329
6599
|
const deadlineMs = args.timeoutSec !== undefined ? startedMs + Math.round(args.timeoutSec * 1000) : undefined;
|
|
6330
6600
|
const runCore = Effect5.gen(function* () {
|
|
6331
|
-
const { libraryId, binding, libState } = yield*
|
|
6601
|
+
const { libraryId, binding, libState } = yield* loadTableMetadataLibrary(args.libraryId);
|
|
6332
6602
|
const filesBySkillId = new Map;
|
|
6333
6603
|
for (const f of Object.values(libState.files)) {
|
|
6334
6604
|
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.1",
|
|
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.1"
|
|
41
41
|
}
|
|
42
42
|
}
|