@nookplot/cli 0.6.8 → 0.6.11

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.
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Non-blocking CLI update checker.
3
+ *
4
+ * Checks npm registry for newer @nookplot/cli version and prints
5
+ * a notice to stderr if one is available. Never blocks the CLI —
6
+ * network fetch fires asynchronously with a short timeout.
7
+ *
8
+ * Cache: ~/.nookplot/update-check.json (24hr TTL)
9
+ *
10
+ * @module utils/updateCheck
11
+ */
12
+ /**
13
+ * Compare two semver strings. Returns true if `a` < `b`.
14
+ * Only handles MAJOR.MINOR.PATCH — no prerelease/build metadata.
15
+ */
16
+ export declare function isNewer(current: string, latest: string): boolean;
17
+ /**
18
+ * Check for updates and print a notice if a newer version is available.
19
+ *
20
+ * This function is synchronous from the caller's perspective — it reads
21
+ * the cache synchronously and fires a background fetch if needed. It
22
+ * NEVER blocks the CLI and NEVER throws.
23
+ */
24
+ export declare function checkForUpdate(currentVersion: string): void;
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Non-blocking CLI update checker.
3
+ *
4
+ * Checks npm registry for newer @nookplot/cli version and prints
5
+ * a notice to stderr if one is available. Never blocks the CLI —
6
+ * network fetch fires asynchronously with a short timeout.
7
+ *
8
+ * Cache: ~/.nookplot/update-check.json (24hr TTL)
9
+ *
10
+ * @module utils/updateCheck
11
+ */
12
+ import fs from "fs";
13
+ import path from "path";
14
+ import os from "os";
15
+ const CACHE_DIR = path.join(os.homedir(), ".nookplot");
16
+ const CACHE_FILE = path.join(CACHE_DIR, "update-check.json");
17
+ const CACHE_TTL_MS = 24 * 60 * 60 * 1000; // 24 hours
18
+ const FETCH_TIMEOUT_MS = 3000;
19
+ const REGISTRY_URL = "https://registry.npmjs.org/@nookplot/cli/latest";
20
+ /**
21
+ * Compare two semver strings. Returns true if `a` < `b`.
22
+ * Only handles MAJOR.MINOR.PATCH — no prerelease/build metadata.
23
+ */
24
+ export function isNewer(current, latest) {
25
+ const parse = (v) => {
26
+ const parts = v.replace(/^v/, "").split(".");
27
+ return {
28
+ major: parseInt(parts[0], 10) || 0,
29
+ minor: parseInt(parts[1], 10) || 0,
30
+ patch: parseInt(parts[2], 10) || 0,
31
+ };
32
+ };
33
+ const c = parse(current);
34
+ const l = parse(latest);
35
+ if (l.major !== c.major)
36
+ return l.major > c.major;
37
+ if (l.minor !== c.minor)
38
+ return l.minor > c.minor;
39
+ return l.patch > c.patch;
40
+ }
41
+ /** Read the cached version data, if valid and not expired. */
42
+ function readCache() {
43
+ try {
44
+ const raw = fs.readFileSync(CACHE_FILE, "utf-8");
45
+ const data = JSON.parse(raw);
46
+ if (typeof data.latestVersion === "string" &&
47
+ typeof data.checkedAt === "number" &&
48
+ Date.now() - data.checkedAt < CACHE_TTL_MS) {
49
+ return data;
50
+ }
51
+ }
52
+ catch {
53
+ // Cache doesn't exist or is invalid
54
+ }
55
+ return null;
56
+ }
57
+ /** Write version data to cache. */
58
+ function writeCache(latestVersion) {
59
+ try {
60
+ if (!fs.existsSync(CACHE_DIR)) {
61
+ fs.mkdirSync(CACHE_DIR, { recursive: true });
62
+ }
63
+ fs.writeFileSync(CACHE_FILE, JSON.stringify({ latestVersion, checkedAt: Date.now() }));
64
+ }
65
+ catch {
66
+ // Non-critical — cache write failure is fine
67
+ }
68
+ }
69
+ /**
70
+ * Check for updates and print a notice if a newer version is available.
71
+ *
72
+ * This function is synchronous from the caller's perspective — it reads
73
+ * the cache synchronously and fires a background fetch if needed. It
74
+ * NEVER blocks the CLI and NEVER throws.
75
+ */
76
+ export function checkForUpdate(currentVersion) {
77
+ try {
78
+ const cached = readCache();
79
+ if (cached) {
80
+ // Show notice if cached version is newer
81
+ if (isNewer(currentVersion, cached.latestVersion)) {
82
+ process.stderr.write(`\nUpdate available: @nookplot/cli ${currentVersion} → ${cached.latestVersion}\n` +
83
+ `Run: npm update -g @nookplot/cli\n\n`);
84
+ }
85
+ return; // Cache is fresh, no network call needed
86
+ }
87
+ // Cache is stale or missing — fire background fetch (never await)
88
+ const controller = new AbortController();
89
+ const timeout = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
90
+ fetch(REGISTRY_URL, {
91
+ signal: controller.signal,
92
+ headers: { Accept: "application/json" },
93
+ })
94
+ .then((res) => {
95
+ clearTimeout(timeout);
96
+ if (!res.ok)
97
+ return;
98
+ return res.json();
99
+ })
100
+ .then((data) => {
101
+ if (data?.version) {
102
+ writeCache(data.version);
103
+ // Don't show notice on first fetch — show on next invocation
104
+ }
105
+ })
106
+ .catch(() => {
107
+ clearTimeout(timeout);
108
+ // Network error — silently ignore
109
+ });
110
+ }
111
+ catch {
112
+ // Never crash the CLI
113
+ }
114
+ }
115
+ //# sourceMappingURL=updateCheck.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updateCheck.js","sourceRoot":"","sources":["../../src/utils/updateCheck.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,CAAC,CAAC;AACvD,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC;AAC7D,MAAM,YAAY,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,WAAW;AACrD,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAC9B,MAAM,YAAY,GAAG,iDAAiD,CAAC;AAOvE;;;GAGG;AACH,MAAM,UAAU,OAAO,CAAC,OAAe,EAAE,MAAc;IACrD,MAAM,KAAK,GAAG,CAAC,CAAS,EAAE,EAAE;QAC1B,MAAM,KAAK,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,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EAAE;gBAAE,OAAO;YACpB,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC;QACpB,CAAC,CAAC;aACD,IAAI,CAAC,CAAC,IAAsC,EAAE,EAAE;YAC/C,IAAI,IAAI,EAAE,OAAO,EAAE,CAAC;gBAClB,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBACzB,6DAA6D;YAC/D,CAAC;QACH,CAAC,CAAC;aACD,KAAK,CAAC,GAAG,EAAE;YACV,YAAY,CAAC,OAAO,CAAC,CAAC;YACtB,kCAAkC;QACpC,CAAC,CAAC,CAAC;IACP,CAAC;IAAC,MAAM,CAAC;QACP,sBAAsB;IACxB,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nookplot/cli",
3
- "version": "0.6.8",
3
+ "version": "0.6.11",
4
4
  "description": "CLI toolkit for NookPlot agent developers — scaffold, register, sync, and monitor agents",
5
5
  "author": "nookplot",
6
6
  "type": "module",
@@ -20,10 +20,11 @@
20
20
  "build": "tsc",
21
21
  "clean": "rm -rf dist",
22
22
  "dev": "tsx src/index.ts",
23
+ "test": "vitest run",
23
24
  "postinstall": "node dist/postinstall.js 2>/dev/null || true"
24
25
  },
25
26
  "dependencies": {
26
- "@nookplot/runtime": "^0.2.16",
27
+ "@nookplot/runtime": "file:../runtime",
27
28
  "chalk": "5.6.2",
28
29
  "commander": "12.1.0",
29
30
  "dotenv": "16.6.1",
@@ -37,7 +38,8 @@
37
38
  "@types/inquirer": "^9.0.7",
38
39
  "@types/js-yaml": "^4.0.9",
39
40
  "@types/node": "20.14.10",
40
- "typescript": "5.5.4"
41
+ "typescript": "5.5.4",
42
+ "vitest": "3.0.5"
41
43
  },
42
44
  "engines": {
43
45
  "node": ">=18.0.0"