ntn-skills 2.0.1 → 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.
Files changed (3) hide show
  1. package/INSTALL.md +6 -0
  2. package/dist/bin.js +81 -22
  3. package/package.json +2 -2
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 moveToSystemTrash(staleTmp).catch(() => {
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 moveToSystemTrash(stagingDir);
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 moveToSystemTrash(targetDir);
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 moveToSystemTrash(stagingDir).catch(() => {
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 moveToSystemTrash(p).catch(() => {
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 moveToSystemTrash(v.realDir);
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 moveToSystemTrash(real);
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 moveToSystemTrash(real);
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 moveToSystemTrash(real);
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
- if (!st || nowMs - st.mtimeMs <= repoTreeGraceMs)
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 moveToSystemTrash(real);
1736
+ await removeInternalCachePath(real);
1725
1737
  pruned.push(real);
1726
1738
  }
1727
1739
  }
@@ -3042,6 +3054,30 @@ function buildSubprocessEnv(bypassProxy) {
3042
3054
  }
3043
3055
  return env;
3044
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
+ }
3045
3081
  var repoGitLocks = new Map;
3046
3082
  async function withRepoGitLock(key, fn) {
3047
3083
  const prev = repoGitLocks.get(key) ?? Promise.resolve();
@@ -3135,6 +3171,28 @@ async function readAllTreeFiles(rootDir, currentRel = "") {
3135
3171
  }
3136
3172
  var UpstreamLiveLayer = Layer3.effect(UpstreamPort, Effect3.gen(function* () {
3137
3173
  const store = yield* StorePort;
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
+ });
3138
3196
  const fullTreeInFlight = new Map;
3139
3197
  const ensureFullCommitTree = (repoUrl, commitSha) => {
3140
3198
  const treeKey = sha256Hex(`${repoUrl.trim()}@${commitSha.trim()}`).slice(0, 24);
@@ -3148,6 +3206,7 @@ var UpstreamLiveLayer = Layer3.effect(UpstreamPort, Effect3.gen(function* () {
3148
3206
  return p;
3149
3207
  };
3150
3208
  const ensureFullCommitTreeImpl = async (repoUrl, commitSha, treeKey) => {
3209
+ await ensureDeadTmpSwept();
3151
3210
  const cachedTreeDir = nodePath4.join(store.paths.reposRoot, "trees", treeKey);
3152
3211
  const marker = nodePath4.join(cachedTreeDir, ".ntn-tree-ready");
3153
3212
  if (await fsp4.stat(marker).then(() => true).catch(() => false)) {
@@ -3195,10 +3254,9 @@ var UpstreamLiveLayer = Layer3.effect(UpstreamPort, Effect3.gen(function* () {
3195
3254
  }
3196
3255
  if (!extractedRoot) {
3197
3256
  const bypassProxy = shouldBypassProxyForUrl(repoUrl);
3198
- const repoLockKey = sha256Hex(repoUrl.trim()).slice(0, 16);
3257
+ const repoLockKey = repoGitCacheKey(repoUrl);
3199
3258
  const gitCacheDir = nodePath4.join(store.paths.reposRoot, "git", repoLockKey);
3200
- extractedRoot = await withRepoGitLock(repoLockKey, async () => {
3201
- await fsp4.mkdir(gitCacheDir, { recursive: true });
3259
+ extractedRoot = await withCrossProcessRepoGitLock(repoLockKey, gitCacheDir, async () => {
3202
3260
  const hasHead = await fsp4.stat(nodePath4.join(gitCacheDir, "HEAD")).then(() => true).catch(() => false);
3203
3261
  if (!hasHead) {
3204
3262
  await runCmd("git", ["init", "--bare"], { cwd: gitCacheDir });
@@ -3256,7 +3314,7 @@ var UpstreamLiveLayer = Layer3.effect(UpstreamPort, Effect3.gen(function* () {
3256
3314
  }
3257
3315
  return cachedTreeDir;
3258
3316
  } finally {
3259
- await moveToSystemTrash(tmpBase).catch(() => {
3317
+ await removeInternalCachePath(tmpBase).catch(() => {
3260
3318
  return;
3261
3319
  });
3262
3320
  }
@@ -3380,7 +3438,7 @@ var UpstreamLiveLayer = Layer3.effect(UpstreamPort, Effect3.gen(function* () {
3380
3438
  });
3381
3439
  return (await readAllTreeFiles(subCacheDir)).filter((f) => f.path !== ".ntn-tree-ready");
3382
3440
  } finally {
3383
- await moveToSystemTrash(tmpSub).catch(() => {
3441
+ await removeInternalCachePath(tmpSub).catch(() => {
3384
3442
  return;
3385
3443
  });
3386
3444
  }
@@ -3389,15 +3447,16 @@ var UpstreamLiveLayer = Layer3.effect(UpstreamPort, Effect3.gen(function* () {
3389
3447
  } catch {}
3390
3448
  }
3391
3449
  const bypassProxy = shouldBypassProxyForUrl(repoUrl);
3392
- const repoLockKey = sha256Hex(repoUrl.trim()).slice(0, 16);
3450
+ const repoLockKey = repoGitCacheKey(repoUrl);
3393
3451
  const gitCacheDir = nodePath4.join(store.paths.reposRoot, "git", repoLockKey);
3394
- const sparseArchive = await withRepoGitLock(repoLockKey, async () => {
3395
- await fsp4.mkdir(gitCacheDir, { recursive: true });
3452
+ const sparseArchive = await withCrossProcessRepoGitLock(repoLockKey, gitCacheDir, async () => {
3396
3453
  const hasHead = await fsp4.stat(nodePath4.join(gitCacheDir, "HEAD")).then(() => true).catch(() => false);
3397
3454
  if (!hasHead) {
3398
3455
  await runCmd("git", ["init", "--bare"], { cwd: gitCacheDir });
3399
3456
  }
3400
- await runCmd("git", ["config", "remote.origin.url", repoUrl], { cwd: gitCacheDir });
3457
+ await runCmd("git", ["config", "remote.origin.url", repoUrl], {
3458
+ cwd: gitCacheDir
3459
+ });
3401
3460
  await runCmd("git", ["config", "remote.origin.promisor", "true"], {
3402
3461
  cwd: gitCacheDir
3403
3462
  });
@@ -3433,7 +3492,7 @@ var UpstreamLiveLayer = Layer3.effect(UpstreamPort, Effect3.gen(function* () {
3433
3492
  }
3434
3493
  }
3435
3494
  } finally {
3436
- await moveToSystemTrash(tmpSub).catch(() => {
3495
+ await removeInternalCachePath(tmpSub).catch(() => {
3437
3496
  return;
3438
3497
  });
3439
3498
  }
@@ -3646,7 +3705,7 @@ var UpstreamLiveLayer = Layer3.effect(UpstreamPort, Effect3.gen(function* () {
3646
3705
  return new Uint8Array(buf);
3647
3706
  }
3648
3707
  } finally {
3649
- await moveToSystemTrash(tmpAsset).catch(() => {
3708
+ await removeInternalCachePath(tmpAsset).catch(() => {
3650
3709
  return;
3651
3710
  });
3652
3711
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ntn-skills",
3
- "version": "2.0.1",
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.1"
40
+ "@ntn-skills/core": "2.0.2"
41
41
  }
42
42
  }