@newtype-ai/nit 0.4.1 → 0.4.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 (2) hide show
  1. package/dist/cli.js +79 -0
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -17,6 +17,71 @@ import {
17
17
  status
18
18
  } from "./chunk-BC7OEIFR.js";
19
19
 
20
+ // src/update-check.ts
21
+ import { homedir } from "os";
22
+ import { join } from "path";
23
+ import { readFile, writeFile } from "fs/promises";
24
+ var CACHE_PATH = join(homedir(), ".nit-update-cache.json");
25
+ var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
26
+ var FETCH_TIMEOUT_MS = 3e3;
27
+ var REGISTRY_URL = "https://registry.npmjs.org/@newtype-ai/nit/latest";
28
+ function getCurrentVersion() {
29
+ try {
30
+ return "0.4.2";
31
+ } catch {
32
+ return "0.0.0";
33
+ }
34
+ }
35
+ var version = getCurrentVersion();
36
+ function isNewer(latest, current) {
37
+ const a = latest.split(".").map(Number);
38
+ const b = current.split(".").map(Number);
39
+ for (let i = 0; i < 3; i++) {
40
+ if ((a[i] ?? 0) > (b[i] ?? 0)) return true;
41
+ if ((a[i] ?? 0) < (b[i] ?? 0)) return false;
42
+ }
43
+ return false;
44
+ }
45
+ async function readCache() {
46
+ try {
47
+ const raw = await readFile(CACHE_PATH, "utf-8");
48
+ return JSON.parse(raw);
49
+ } catch {
50
+ return null;
51
+ }
52
+ }
53
+ async function writeCache(cache) {
54
+ try {
55
+ await writeFile(CACHE_PATH, JSON.stringify(cache), "utf-8");
56
+ } catch {
57
+ }
58
+ }
59
+ async function checkForUpdate() {
60
+ const current = getCurrentVersion();
61
+ const cache = await readCache();
62
+ if (cache && Date.now() - cache.lastChecked < CHECK_INTERVAL_MS) {
63
+ return isNewer(cache.latestVersion, current) ? { current, latest: cache.latestVersion } : null;
64
+ }
65
+ const controller = new AbortController();
66
+ const timeout = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
67
+ try {
68
+ const res = await fetch(REGISTRY_URL, {
69
+ signal: controller.signal,
70
+ headers: { Accept: "application/json" }
71
+ });
72
+ if (!res.ok) return null;
73
+ const data = await res.json();
74
+ const latest = data.version;
75
+ if (!latest) return null;
76
+ await writeCache({ lastChecked: Date.now(), latestVersion: latest });
77
+ return isNewer(latest, current) ? { current, latest } : null;
78
+ } catch {
79
+ return null;
80
+ } finally {
81
+ clearTimeout(timeout);
82
+ }
83
+ }
84
+
20
85
  // src/cli.ts
21
86
  var bold = (s) => `\x1B[1m${s}\x1B[0m`;
22
87
  var green = (s) => `\x1B[32m${s}\x1B[0m`;
@@ -63,6 +128,10 @@ async function main() {
63
128
  case void 0:
64
129
  printUsage();
65
130
  break;
131
+ case "--version":
132
+ case "-v":
133
+ break;
134
+ // version printed below via update check
66
135
  default:
67
136
  console.error(`nit: '${command}' is not a nit command. See 'nit help'.`);
68
137
  process.exit(1);
@@ -72,6 +141,16 @@ async function main() {
72
141
  console.error(red(`error: ${msg}`));
73
142
  process.exit(1);
74
143
  }
144
+ if (command === "--version" || command === "-v") {
145
+ console.log(`nit ${version}`);
146
+ }
147
+ const update = await checkForUpdate().catch(() => null);
148
+ if (update) {
149
+ console.error(yellow(`
150
+ Update available: ${update.current} \u2192 ${update.latest}`));
151
+ console.error(yellow(` Run: npm install -g @newtype-ai/nit
152
+ `));
153
+ }
75
154
  }
76
155
  async function cmdInit() {
77
156
  const result = await init();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newtype-ai/nit",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "Version control for agent cards",
5
5
  "type": "module",
6
6
  "bin": {