@dadado/agent-kit-cli 6.23.0 → 6.25.0

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 (65) hide show
  1. package/README.md +1 -0
  2. package/dashboard/dashboard-data.mjs +126 -5
  3. package/dashboard/dashboard.html +45 -4
  4. package/dashboard/lib/live-refresh.mjs +1 -0
  5. package/dist/{add-RKZQX6ZK.js → add-OYLOMCM6.js} +14 -6
  6. package/dist/chunk-2F6NMQOA.js +519 -0
  7. package/dist/chunk-2QYWMSI5.js +193 -0
  8. package/dist/{chunk-B3VR5YBQ.js → chunk-2TW7ENWC.js} +12 -11
  9. package/dist/{chunk-2IP4OO6R.js → chunk-2XLI7XEY.js} +1 -1
  10. package/dist/chunk-6M6UKECW.js +176 -0
  11. package/dist/{chunk-UJCATSYO.js → chunk-7Y74KO7U.js} +45 -16
  12. package/dist/{chunk-DZCLMIAS.js → chunk-AQLBEEPD.js} +236 -2
  13. package/dist/{chunk-R4DUO5DA.js → chunk-AXQMVQ6O.js} +61 -237
  14. package/dist/{chunk-7TYA3GMI.js → chunk-C7SV7UP5.js} +7 -4
  15. package/dist/{chunk-F7YAAKYP.js → chunk-CIV42JGT.js} +7 -5
  16. package/dist/{chunk-CQHD6UKB.js → chunk-CXE6ASSX.js} +1 -0
  17. package/dist/{chunk-6BEFGKCU.js → chunk-EO5NGAYV.js} +1 -1
  18. package/dist/{chunk-MJJBIOSY.js → chunk-G5MQRP6M.js} +31 -13
  19. package/dist/chunk-GMG7ZH4E.js +357 -0
  20. package/dist/{chunk-5EBT3V7G.js → chunk-GQSSXDDK.js} +1 -1
  21. package/dist/{chunk-5LNHRL5E.js → chunk-H7RAFRRZ.js} +41 -245
  22. package/dist/{chunk-IESSMKOV.js → chunk-HSIHZWFF.js} +4 -4
  23. package/dist/{chunk-W3ZJVBNY.js → chunk-IFBIO7VT.js} +449 -418
  24. package/dist/{chunk-V2H57TFD.js → chunk-JG3CNGQM.js} +78 -170
  25. package/dist/{chunk-KDJ4ML7I.js → chunk-JGG574RK.js} +3 -3
  26. package/dist/{chunk-SGTTC2JP.js → chunk-KWYF7QNH.js} +1 -1
  27. package/dist/{chunk-CVZNSRXV.js → chunk-M4UL422I.js} +80 -15
  28. package/dist/{chunk-AWQ6KRFV.js → chunk-NJ2SUSWX.js} +1 -1
  29. package/dist/{chunk-DRZFWIBN.js → chunk-PIMGV3E5.js} +1 -1
  30. package/dist/{chunk-QNISTPPZ.js → chunk-QACMV46U.js} +3 -3
  31. package/dist/{chunk-5PSV76CQ.js → chunk-QLTGHJB3.js} +25 -6
  32. package/dist/{chunk-OYFCBYMP.js → chunk-QX55T4UX.js} +13 -1
  33. package/dist/chunk-SAQ3EE5R.js +138 -0
  34. package/dist/{chunk-C4LCOOL4.js → chunk-TOSAAQ5A.js} +1 -1
  35. package/dist/chunk-WKFE3RUC.js +433 -0
  36. package/dist/{chunk-BGL5DRK2.js → chunk-XGZOU4DS.js} +1 -1
  37. package/dist/{commands-SAQEEE6V.js → commands-UW2C2ZN4.js} +4 -4
  38. package/dist/{conflicts-5JOP4GX2.js → conflicts-RING6AHV.js} +6 -6
  39. package/dist/{contribute-BQKRT5GN.js → contribute-LSY75JZH.js} +5 -4
  40. package/dist/{countdown-25E5C7AR.js → countdown-SZ2P4XHB.js} +267 -23
  41. package/dist/{diff-6JSXBVSX.js → diff-NZVBVQSK.js} +13 -5
  42. package/dist/{doctor-I3MTHS7F.js → doctor-TJSXBVGV.js} +103 -17
  43. package/dist/{ground-control-IDCXN5FK.js → ground-control-ZJXPUIQN.js} +3 -3
  44. package/dist/{guard-RJZEEKSL.js → guard-ZO4Z3LLB.js} +47 -9
  45. package/dist/{handoff-5AGE2D3T.js → handoff-2OZSWGTE.js} +2 -0
  46. package/dist/{hook-WNA42CXE.js → hook-3VPKNSOO.js} +12 -10
  47. package/dist/index.js +27 -26
  48. package/dist/{init-FZ2UFPO7.js → init-UW2BJBO2.js} +21 -15
  49. package/dist/{install-CTLT3TSI.js → install-RQSI4CHG.js} +18 -15
  50. package/dist/installs-7TR4H4QH.js +222 -0
  51. package/dist/{mission-control-CRMCRZUU.js → mission-control-VSU6NT43.js} +1 -1
  52. package/dist/{queue-JW4VR33H.js → queue-JHYILLMX.js} +9 -9
  53. package/dist/{run-X2WOONTB.js → run-CQF5RM5X.js} +21 -21
  54. package/dist/{run-plan-4MOLLIES.js → run-plan-BEOCOJCF.js} +13 -13
  55. package/dist/{scan-K3T5RQLC.js → scan-7D3RMO34.js} +2 -1
  56. package/dist/{session-start-MV7A4263.js → session-start-QV7CEFRX.js} +16 -10
  57. package/dist/{sessions-UPFDWDMB.js → sessions-AWAAO3DU.js} +1 -1
  58. package/dist/{setup-global-VNADNTQ2.js → setup-global-ST4TT427.js} +8 -7
  59. package/dist/{status-SXA3OK5E.js → status-HUBPBGUU.js} +13 -10
  60. package/dist/update-DD5UZPGG.js +31 -0
  61. package/dist/update-all-YYUTXHGR.js +695 -0
  62. package/package.json +1 -1
  63. package/dist/chunk-4MR4QXMF.js +0 -52
  64. package/dist/chunk-HAFRAXGV.js +0 -17
  65. package/dist/update-RMAWXMCV.js +0 -304
@@ -0,0 +1,519 @@
1
+ import {
2
+ listInstalls,
3
+ resolveInstallsFile
4
+ } from "./chunk-WKFE3RUC.js";
5
+ import {
6
+ CLI_NPM_PACKAGES,
7
+ compareSemver,
8
+ fetchLatestCliNpmVersion,
9
+ isFactoryOrDevRegistry,
10
+ normalizeSemver,
11
+ updateCheckAllowed
12
+ } from "./chunk-M4UL422I.js";
13
+ import {
14
+ loadContextConfig
15
+ } from "./chunk-PFEUZXVT.js";
16
+ import {
17
+ KIT_VERSION
18
+ } from "./chunk-7HDQEK6T.js";
19
+ import {
20
+ writeJson
21
+ } from "./chunk-5B4DVO6C.js";
22
+
23
+ // src/readiness/install-health.ts
24
+ import { access, readFile, realpath } from "fs/promises";
25
+ import { homedir } from "os";
26
+ import path from "path";
27
+ var INSTALL_HEALTH_SNAPSHOT_RELATIVE_PATH = ".cursor/context/install-health.json";
28
+ function miseToolEntry(packageName) {
29
+ return `"npm:${packageName}" = { version = "latest", allow_low_downloads = true, minimum_release_age = "0s" }`;
30
+ }
31
+ var LABELS = {
32
+ "global-cli": "Global CLI vs npm latest",
33
+ "node-manager": "Node version manager",
34
+ "home-install": "Home-level install",
35
+ "registry-pin": "Registry pin"
36
+ };
37
+ function check(id, severity, detail, fix = null, fixKind = null) {
38
+ return { id, label: LABELS[id], severity, detail, fix, fixKind: fix ? fixKind : null };
39
+ }
40
+ function homeRelative(p, homeDir) {
41
+ if (!homeDir) return p;
42
+ const norm = (s) => s.replace(/\\/g, "/").replace(/\/+$/, "");
43
+ const home = norm(homeDir);
44
+ const target = norm(p);
45
+ if (target === home) return "~";
46
+ if (target.startsWith(`${home}/`)) return `~${target.slice(home.length)}`;
47
+ return p;
48
+ }
49
+ function packageForBin(binName) {
50
+ const base = (binName ?? "").replace(/\.(cmd|exe|bat|ps1)$/i, "");
51
+ return CLI_NPM_PACKAGES.find((pkg) => pkg.bin === base)?.name ?? CLI_NPM_PACKAGES[0].name;
52
+ }
53
+ function assessGlobalCli(input) {
54
+ if (!input.binPath) {
55
+ const names = CLI_NPM_PACKAGES.map((pkg) => pkg.bin).join(" or ");
56
+ return check("global-cli", "info", `No ${names} binary on PATH (npx-only use is fine)`);
57
+ }
58
+ const where = homeRelative(input.binPath, input.homeDir);
59
+ const installed = input.binVersion ? normalizeSemver(input.binVersion) : null;
60
+ if (!installed) {
61
+ return check("global-cli", "info", `Could not read the version of ${where}`);
62
+ }
63
+ if (!input.latestChecked) {
64
+ return check(
65
+ "global-cli",
66
+ "info",
67
+ `v${installed} at ${where}; npm latest not checked (CI or updateCheck.enabled: false)`
68
+ );
69
+ }
70
+ if (!input.latest) {
71
+ return check(
72
+ "global-cli",
73
+ "info",
74
+ `v${installed} at ${where}; npm registry did not answer, not compared`
75
+ );
76
+ }
77
+ const { version: latest, packageName } = input.latest;
78
+ if (compareSemver(installed, latest) < 0) {
79
+ return check(
80
+ "global-cli",
81
+ "warning",
82
+ `v${installed} at ${where} is behind npm latest v${latest} (${packageName})`,
83
+ `npm i -g ${packageName}@${latest}`,
84
+ "command"
85
+ );
86
+ }
87
+ return check(
88
+ "global-cli",
89
+ "ok",
90
+ compareSemver(installed, latest) === 0 ? `v${installed} at ${where} matches npm latest` : `v${installed} at ${where} is ahead of npm latest v${latest} (dev build)`
91
+ );
92
+ }
93
+ var PER_VERSION_MANAGERS = /* @__PURE__ */ new Set([
94
+ "mise",
95
+ "nvm",
96
+ "nvm-windows",
97
+ "fnm"
98
+ ]);
99
+ function classifyNodeManagerPath(p, platform) {
100
+ const win = platform === "win32";
101
+ const norm = p.replace(/\\/g, "/");
102
+ const s = win ? norm.toLowerCase() : norm;
103
+ const version = (re) => {
104
+ const m = re.exec(s);
105
+ return m?.[1] ?? null;
106
+ };
107
+ const mise = version(/\/mise\/installs\/node\/([^/]+)\//);
108
+ if (mise) return { manager: "mise", nodeVersion: mise };
109
+ if (/\/mise\/shims\//.test(s)) return { manager: "mise-shim", nodeVersion: null };
110
+ const nvm = version(/\/\.?nvm\/versions\/node\/(v?\d[^/]*)\//);
111
+ if (nvm) return { manager: "nvm", nodeVersion: nvm };
112
+ const fnm = version(/\/\.?fnm\/node-versions\/([^/]+)\/installation\//);
113
+ if (fnm) return { manager: "fnm", nodeVersion: fnm };
114
+ if (win) {
115
+ const nvmWin = version(/\/nvm\/(v\d+\.\d+\.\d+[^/]*)\//);
116
+ if (nvmWin) return { manager: "nvm-windows", nodeVersion: nvmWin };
117
+ }
118
+ if (/\/\.?volta\//.test(s)) return { manager: "volta", nodeVersion: null };
119
+ if (/^\/opt\/homebrew\/|^\/usr\/local\/cellar\/|\/\.linuxbrew\//i.test(norm)) {
120
+ return { manager: "homebrew", nodeVersion: null };
121
+ }
122
+ return { manager: "other", nodeVersion: null };
123
+ }
124
+ function nodeManagerFix(manager, packageName, oldVersion, newVersion) {
125
+ const known = Boolean(newVersion && newVersion !== oldVersion);
126
+ const target = known ? newVersion : "<new>";
127
+ const kind = known ? "command" : "template";
128
+ switch (manager) {
129
+ case "mise":
130
+ return { fix: miseToolEntry(packageName), fixKind: "config-line" };
131
+ case "nvm":
132
+ return {
133
+ fix: `nvm install ${target} --reinstall-packages-from=${oldVersion}`,
134
+ fixKind: kind,
135
+ also: `or install under a fixed prefix outside nvm: npm i -g --prefix ~/.local ${packageName} (with ~/.local/bin on PATH)`
136
+ };
137
+ case "nvm-windows":
138
+ return { fix: `nvm use ${target} && npm i -g ${packageName}`, fixKind: kind };
139
+ default:
140
+ return { fix: `fnm use ${target} && npm i -g ${packageName}`, fixKind: kind };
141
+ }
142
+ }
143
+ function assessNodeManager(input) {
144
+ if (!input.binPath) {
145
+ return check("node-manager", "ok", "No global CLI on PATH; nothing tied to a node version");
146
+ }
147
+ const candidates = [input.binRealPath, input.binPath].filter((p) => Boolean(p));
148
+ let match = { manager: "other", nodeVersion: null };
149
+ for (const candidate of candidates) {
150
+ const found = classifyNodeManagerPath(candidate, input.platform);
151
+ if (PER_VERSION_MANAGERS.has(found.manager)) {
152
+ match = found;
153
+ break;
154
+ }
155
+ if (match.manager === "other") match = found;
156
+ }
157
+ const where = homeRelative(input.binPath, input.homeDir);
158
+ if (!PER_VERSION_MANAGERS.has(match.manager) || !match.nodeVersion) {
159
+ const kind = match.manager === "volta" ? "Volta" : match.manager === "homebrew" ? "Homebrew node" : match.manager === "mise-shim" ? "a mise shim (not classified)" : "a node install that keeps globals";
160
+ return check("node-manager", "ok", `${where} comes from ${kind}`);
161
+ }
162
+ const running = input.nodeExecPath ? classifyNodeManagerPath(input.nodeExecPath, input.platform) : null;
163
+ const runningVersion = running && running.manager === match.manager ? running.nodeVersion : null;
164
+ const packageName = packageForBin(path.basename(input.binPath));
165
+ const remedy = nodeManagerFix(match.manager, packageName, match.nodeVersion, runningVersion);
166
+ const drift = runningVersion && runningVersion !== match.nodeVersion ? `; node now resolves to ${runningVersion}, so this copy is already orphaned` : "";
167
+ const where2 = match.manager === "mise" ? "; add the fix line under [tools] in ~/.config/mise/config.toml" : remedy.also ? `; ${remedy.also}` : "";
168
+ return check(
169
+ "node-manager",
170
+ "warning",
171
+ `${where} lives in ${match.manager} node ${match.nodeVersion}: npm globals vanish on the next node switch or patch${drift}${where2}`,
172
+ remedy.fix,
173
+ remedy.fixKind
174
+ );
175
+ }
176
+ var HOME_INSTALL_RELS = [
177
+ ".cursor/agent-kit.json",
178
+ ".cursor/rules",
179
+ ".cursor/hooks.json",
180
+ ".cursor/commands"
181
+ ];
182
+ function assessHomeInstall(input) {
183
+ if (path.resolve(input.cwd) === path.resolve(input.homeDir)) {
184
+ return check("home-install", "ok", "Running in the home directory: this is the home install");
185
+ }
186
+ if (!input.homeManifestVersion) {
187
+ return check("home-install", "ok", "No home-level install (~/.cursor/agent-kit.json absent)");
188
+ }
189
+ const home = normalizeSemver(input.homeManifestVersion);
190
+ const reference = normalizeSemver(input.repoVersion ?? input.cliVersion);
191
+ const against = input.repoVersion ? "this repo's kit" : "the running CLI";
192
+ if (!home || !reference) {
193
+ return check(
194
+ "home-install",
195
+ "info",
196
+ `Home-level install v${input.homeManifestVersion} under ~/.cursor; version not comparable`
197
+ );
198
+ }
199
+ if (compareSemver(home, reference) >= 0) {
200
+ return check("home-install", "ok", `Home-level install v${home} is current with ${against}`);
201
+ }
202
+ const paths = input.presentRels.map((rel) => `~/${rel}${rel.endsWith(".json") ? "" : "/"}`).join(", ");
203
+ return check(
204
+ "home-install",
205
+ "warning",
206
+ `Home-level install v${home} is older than ${against} v${reference}; its rules and hooks still apply in every workspace: ${paths}. Nothing was moved`
207
+ );
208
+ }
209
+ function assessRegistryPin(input) {
210
+ if (!input.hasManifest) {
211
+ return check("registry-pin", "ok", "No .cursor/agent-kit.json in this repo");
212
+ }
213
+ if (!input.registryRef) {
214
+ return check("registry-pin", "ok", "No registry.ref pin");
215
+ }
216
+ if (isFactoryOrDevRegistry(input.registryUrl, input.registryRef)) {
217
+ return check("registry-pin", "ok", `Factory/dev registry (${input.registryRef}); not checked`);
218
+ }
219
+ const pin = normalizeSemver(input.registryRef);
220
+ if (!pin) {
221
+ return check("registry-pin", "ok", `registry.ref ${input.registryRef} is a branch, not a pin`);
222
+ }
223
+ const versions = [input.installedVersion, input.cliVersion].map((v) => v ? normalizeSemver(v) : null).filter((v) => Boolean(v));
224
+ const newest = versions.reduce(
225
+ (best, v) => !best || compareSemver(v, best) > 0 ? v : best,
226
+ null
227
+ );
228
+ if (!newest || compareSemver(pin, newest) >= 0) {
229
+ return check("registry-pin", "ok", `registry.ref ${input.registryRef} is current`);
230
+ }
231
+ return check(
232
+ "registry-pin",
233
+ "warning",
234
+ `registry.ref ${input.registryRef} in .cursor/agent-kit.json is older than v${newest}; update would re-apply the v${pin} tree`,
235
+ `agent-kit update --ref v${newest}`,
236
+ "command"
237
+ );
238
+ }
239
+ function summarizeInstallHealth(checks) {
240
+ return {
241
+ status: checks.some((c) => c.severity === "warning") ? "warning" : "ok",
242
+ checks
243
+ };
244
+ }
245
+ async function defaultExists(p) {
246
+ try {
247
+ await access(p);
248
+ return true;
249
+ } catch {
250
+ return false;
251
+ }
252
+ }
253
+ async function assessInstallHealth(options) {
254
+ const platform = options.platform ?? process.platform;
255
+ const homeDir = options.homeDir ?? homedir();
256
+ const realpathImpl = options.realpathImpl ?? realpath;
257
+ const readFileImpl = options.readFileImpl ?? ((p) => readFile(p, "utf8"));
258
+ const existsImpl = options.existsImpl ?? defaultExists;
259
+ let binRealPath = null;
260
+ if (options.binPath) {
261
+ binRealPath = await realpathImpl(options.binPath).catch(() => null);
262
+ }
263
+ let homeManifestVersion = null;
264
+ try {
265
+ const raw = JSON.parse(await readFileImpl(path.join(homeDir, ".cursor", "agent-kit.json")));
266
+ if (typeof raw.version === "string" && raw.version) homeManifestVersion = raw.version;
267
+ } catch {
268
+ }
269
+ const presentRels = [];
270
+ if (homeManifestVersion) {
271
+ for (const rel of HOME_INSTALL_RELS) {
272
+ if (await existsImpl(path.join(homeDir, rel)).catch(() => false)) presentRels.push(rel);
273
+ }
274
+ }
275
+ const checks = [
276
+ assessGlobalCli({
277
+ binPath: options.binPath,
278
+ binVersion: options.binVersion,
279
+ latestChecked: options.npm.checked,
280
+ latest: options.npm.latest,
281
+ homeDir
282
+ }),
283
+ assessNodeManager({
284
+ binPath: options.binPath,
285
+ binRealPath,
286
+ nodeExecPath: options.nodeExecPath ?? process.execPath,
287
+ platform,
288
+ homeDir
289
+ }),
290
+ assessHomeInstall({
291
+ homeDir,
292
+ cwd: options.cwd,
293
+ homeManifestVersion,
294
+ presentRels,
295
+ repoVersion: options.manifest?.version ?? null,
296
+ cliVersion: options.cliVersion
297
+ }),
298
+ assessRegistryPin({
299
+ hasManifest: options.manifest != null,
300
+ installedVersion: options.manifest?.version ?? null,
301
+ registryUrl: options.manifest?.registryUrl ?? null,
302
+ registryRef: options.manifest?.registryRef ?? null,
303
+ cliVersion: options.cliVersion
304
+ })
305
+ ];
306
+ const [globalCli, nodeManager] = checks;
307
+ if (globalCli?.severity === "warning" && nodeManager?.severity === "warning" && nodeManager.fix) {
308
+ checks[0] = {
309
+ ...globalCli,
310
+ detail: `${globalCli.detail}; use the ${nodeManager.label} fix so the upgrade survives the next node switch`,
311
+ fix: null,
312
+ fixKind: null
313
+ };
314
+ }
315
+ return summarizeInstallHealth(checks);
316
+ }
317
+ function npmLatestCheckAllowed(env, config) {
318
+ return updateCheckAllowed(env, config);
319
+ }
320
+ async function writeInstallHealthSnapshot(rootDir, report, generatedAt = (/* @__PURE__ */ new Date()).toISOString()) {
321
+ const snapshotPath = path.join(rootDir, INSTALL_HEALTH_SNAPSHOT_RELATIVE_PATH);
322
+ await writeJson(snapshotPath, { version: 1, generatedAt, ...report });
323
+ return snapshotPath;
324
+ }
325
+
326
+ // src/lifecycle/update-notice.ts
327
+ import { randomUUID } from "crypto";
328
+ import { mkdir, readFile as readFile2, realpath as realpath2, rename, rm, writeFile } from "fs/promises";
329
+ import { homedir as homedir2 } from "os";
330
+ import path2 from "path";
331
+ var UPDATE_NOTICE_FILENAME = "update-notice.json";
332
+ var UPDATE_NOTICE_SCHEMA_VERSION = 1;
333
+ var UPDATE_NOTICE_TTL_MS = 24 * 60 * 60 * 1e3;
334
+ var UPDATE_NOTICE_SESSION_FETCH_TIMEOUT_MS = 1500;
335
+ var UPDATE_NOTICE_KINDS = /* @__PURE__ */ new Set(["repo", "home"]);
336
+ function resolveUpdateNoticeFile(env = process.env, home = homedir2()) {
337
+ return path2.join(path2.dirname(resolveInstallsFile(env, home)), UPDATE_NOTICE_FILENAME);
338
+ }
339
+ function isCliNpmLatest(value) {
340
+ if (!value || typeof value !== "object") return false;
341
+ const v = value;
342
+ return typeof v.version === "string" && normalizeSemver(v.version) !== null && CLI_NPM_PACKAGES.some((pkg) => pkg.name === v.packageName);
343
+ }
344
+ async function readUpdateNoticeCache(file) {
345
+ try {
346
+ const raw = JSON.parse(await readFile2(file, "utf8"));
347
+ if (!raw || raw.schemaVersion !== UPDATE_NOTICE_SCHEMA_VERSION) return null;
348
+ if (typeof raw.checkedAt !== "string" || Number.isNaN(Date.parse(raw.checkedAt))) return null;
349
+ return {
350
+ schemaVersion: UPDATE_NOTICE_SCHEMA_VERSION,
351
+ checkedAt: raw.checkedAt,
352
+ npm: isCliNpmLatest(raw.npm) ? { packageName: raw.npm.packageName, version: raw.npm.version } : null,
353
+ notice: raw.notice ?? null
354
+ };
355
+ } catch {
356
+ return null;
357
+ }
358
+ }
359
+ async function writeUpdateNoticeCache(file, cache) {
360
+ const tmp = `${file}.${process.pid}.${randomUUID()}.tmp`;
361
+ try {
362
+ await mkdir(path2.dirname(file), { recursive: true });
363
+ await writeFile(tmp, `${JSON.stringify(cache, null, 2)}
364
+ `, "utf8");
365
+ await rename(tmp, file);
366
+ } catch {
367
+ await rm(tmp, { force: true }).catch(() => {
368
+ });
369
+ }
370
+ }
371
+ function updateNoticeCacheFresh(checkedAt, now) {
372
+ const at = Date.parse(checkedAt);
373
+ if (Number.isNaN(at)) return false;
374
+ const age = now.getTime() - at;
375
+ return age >= 0 && age < UPDATE_NOTICE_TTL_MS;
376
+ }
377
+ async function cachedCliNpmLatest(options = {}) {
378
+ const file = options.file ?? resolveUpdateNoticeFile();
379
+ const now = options.now ?? /* @__PURE__ */ new Date();
380
+ const cache = await readUpdateNoticeCache(file);
381
+ if (cache && updateNoticeCacheFresh(cache.checkedAt, now)) return cache.npm;
382
+ let npm = null;
383
+ try {
384
+ npm = await fetchLatestCliNpmVersion(options.fetchImpl, options.timeoutMs);
385
+ } catch {
386
+ npm = null;
387
+ }
388
+ await writeUpdateNoticeCache(file, {
389
+ schemaVersion: UPDATE_NOTICE_SCHEMA_VERSION,
390
+ checkedAt: now.toISOString(),
391
+ npm,
392
+ notice: cache?.notice ?? null
393
+ });
394
+ return npm;
395
+ }
396
+ function homeRelative2(p, home) {
397
+ const rel = path2.relative(home, p);
398
+ if (rel === "") return "~";
399
+ if (!rel.startsWith("..") && !path2.isAbsolute(rel)) return `~/${rel.split(path2.sep).join("/")}`;
400
+ return p;
401
+ }
402
+ function semverLess(a, b) {
403
+ try {
404
+ return compareSemver(a, b) < 0;
405
+ } catch {
406
+ return false;
407
+ }
408
+ }
409
+ function summarizeUpdateNotice(input) {
410
+ const cli = normalizeSemver(input.cliVersion) ?? input.cliVersion;
411
+ const npm = input.npmLatest;
412
+ const cliBehind = npm ? semverLess(cli, npm.version) : false;
413
+ let installsBehind = 0;
414
+ let oldest = null;
415
+ for (const entry of input.installs) {
416
+ if (!UPDATE_NOTICE_KINDS.has(entry.kind) || !entry.kitVersion) continue;
417
+ if (!semverLess(entry.kitVersion, cli)) continue;
418
+ installsBehind += 1;
419
+ if (!oldest || semverLess(entry.kitVersion, oldest.kitVersion) || !semverLess(oldest.kitVersion, entry.kitVersion) && entry.path.localeCompare(oldest.path) < 0) {
420
+ oldest = entry;
421
+ }
422
+ }
423
+ const cliCommand = cliBehind && npm ? input.cliInNodeManager ? "agent-kit doctor" : `npm i -g ${npm.packageName}@latest` : null;
424
+ const oldestOut = oldest ? {
425
+ path: homeRelative2(oldest.path, input.homeDir),
426
+ kitVersion: normalizeSemver(oldest.kitVersion) ?? oldest.kitVersion
427
+ } : null;
428
+ const parts = [];
429
+ if (cliBehind && npm) {
430
+ const hint = input.cliInNodeManager ? "`agent-kit doctor` shows the install that survives a node switch" : `\`${cliCommand}\``;
431
+ parts.push(`CLI ${cli} < npm ${npm.version} (${hint})`);
432
+ }
433
+ if (installsBehind > 0 && oldestOut) {
434
+ const noun = installsBehind === 1 ? "install" : "installs";
435
+ const behind = cliBehind ? "behind" : `behind CLI ${cli}`;
436
+ parts.push(
437
+ `${installsBehind} ${noun} ${behind}, oldest v${oldestOut.kitVersion} at ${oldestOut.path} (\`agent-kit update --all\`)`
438
+ );
439
+ }
440
+ return {
441
+ generatedAt: input.now.toISOString(),
442
+ cliVersion: cli,
443
+ npmLatest: npm,
444
+ cliBehind,
445
+ installsBehind,
446
+ oldest: oldestOut,
447
+ cliCommand,
448
+ line: parts.length ? `Agent Kit: ${parts.join("; ")}.` : null
449
+ };
450
+ }
451
+ function cliPathInNodeManager(cliPath, platform) {
452
+ if (!cliPath) return false;
453
+ return PER_VERSION_MANAGERS.has(classifyNodeManagerPath(cliPath, platform).manager);
454
+ }
455
+ async function computeUpdateNotice(cwd, options = {}) {
456
+ try {
457
+ const env = options.env ?? process.env;
458
+ const config = await loadContextConfig(cwd).catch(() => null);
459
+ if (!updateCheckAllowed(env, config)) return null;
460
+ const homeDir = options.homeDir ?? homedir2();
461
+ const now = options.now ?? /* @__PURE__ */ new Date();
462
+ const file = options.file ?? resolveUpdateNoticeFile(env, homeDir);
463
+ const npmLatest = await cachedCliNpmLatest({
464
+ file,
465
+ now,
466
+ fetchImpl: options.fetchImpl,
467
+ timeoutMs: options.timeoutMs
468
+ });
469
+ const installs = await listInstalls({
470
+ file: options.installsFile ?? resolveInstallsFile(env, homeDir)
471
+ }).catch(() => []);
472
+ let cliPath = options.cliPath;
473
+ if (cliPath === void 0) {
474
+ cliPath = process.argv[1] ? await realpath2(process.argv[1]).catch(() => null) : null;
475
+ }
476
+ const summary = summarizeUpdateNotice({
477
+ cliVersion: options.cliVersion ?? KIT_VERSION,
478
+ npmLatest,
479
+ installs,
480
+ homeDir,
481
+ now,
482
+ cliInNodeManager: cliPathInNodeManager(cliPath, options.platform ?? process.platform)
483
+ });
484
+ await persistNotice(file, summary.line ? summary : null);
485
+ return summary;
486
+ } catch {
487
+ return null;
488
+ }
489
+ }
490
+ function sameNotice(a, b) {
491
+ const strip = (n) => n ? { ...n, generatedAt: "" } : null;
492
+ return JSON.stringify(strip(a)) === JSON.stringify(strip(b));
493
+ }
494
+ async function persistNotice(file, notice) {
495
+ const cache = await readUpdateNoticeCache(file);
496
+ if (!cache) return;
497
+ if (sameNotice(cache.notice ?? null, notice)) return;
498
+ await writeUpdateNoticeCache(file, { ...cache, notice });
499
+ }
500
+
501
+ // src/scanner/snapshot.ts
502
+ import path3 from "path";
503
+ var READINESS_SNAPSHOT_RELATIVE_PATH = ".cursor/context/readiness.json";
504
+ async function writeReadinessSnapshot(rootDir, report) {
505
+ const snapshotPath = path3.join(rootDir, READINESS_SNAPSHOT_RELATIVE_PATH);
506
+ await writeJson(snapshotPath, report);
507
+ return snapshotPath;
508
+ }
509
+
510
+ export {
511
+ assessInstallHealth,
512
+ npmLatestCheckAllowed,
513
+ writeInstallHealthSnapshot,
514
+ UPDATE_NOTICE_SESSION_FETCH_TIMEOUT_MS,
515
+ cachedCliNpmLatest,
516
+ computeUpdateNotice,
517
+ READINESS_SNAPSHOT_RELATIVE_PATH,
518
+ writeReadinessSnapshot
519
+ };