@dadado/agent-kit-cli 6.22.1 → 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 (69) 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-YVDIFP4N.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-GT5R7W66.js → chunk-2XLI7XEY.js} +1 -1
  10. package/dist/chunk-6M6UKECW.js +176 -0
  11. package/dist/{chunk-YRBRYTM5.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-4SEQ76BQ.js → chunk-C7SV7UP5.js} +7 -4
  15. package/dist/{chunk-WS6OX2IG.js → chunk-CGXLR77R.js} +4 -0
  16. package/dist/{chunk-XZQM55BK.js → chunk-CIV42JGT.js} +7 -5
  17. package/dist/{chunk-CQHD6UKB.js → chunk-CXE6ASSX.js} +1 -0
  18. package/dist/{chunk-2FKAKFMH.js → chunk-EO5NGAYV.js} +1 -1
  19. package/dist/{chunk-GV4VKIPO.js → chunk-G5MQRP6M.js} +32 -14
  20. package/dist/chunk-GMG7ZH4E.js +357 -0
  21. package/dist/{chunk-5EBT3V7G.js → chunk-GQSSXDDK.js} +1 -1
  22. package/dist/{chunk-EYNSSL6B.js → chunk-H7RAFRRZ.js} +47 -251
  23. package/dist/{chunk-IESSMKOV.js → chunk-HSIHZWFF.js} +4 -4
  24. package/dist/{chunk-W3ZJVBNY.js → chunk-IFBIO7VT.js} +449 -418
  25. package/dist/{chunk-QWTBYXHN.js → chunk-JFS4GKP7.js} +1 -1
  26. package/dist/{chunk-LDZAK5DU.js → chunk-JG3CNGQM.js} +78 -170
  27. package/dist/{chunk-SDJIMC5S.js → chunk-JGG574RK.js} +3 -3
  28. package/dist/{chunk-SGTTC2JP.js → chunk-KWYF7QNH.js} +1 -1
  29. package/dist/{chunk-5HH3HSUR.js → chunk-M4UL422I.js} +80 -15
  30. package/dist/{chunk-DTSL2RH7.js → chunk-MFKHIWEL.js} +5 -3
  31. package/dist/{chunk-MGIPA6SD.js → chunk-NJ2SUSWX.js} +1 -1
  32. package/dist/{chunk-BCU54M2P.js → chunk-PIMGV3E5.js} +1 -1
  33. package/dist/{chunk-HJWSOZXS.js → chunk-QACMV46U.js} +10 -10
  34. package/dist/{chunk-WHBGJ7IJ.js → chunk-QLTGHJB3.js} +26 -7
  35. package/dist/{chunk-ZJDJCMQO.js → chunk-QX55T4UX.js} +23 -1
  36. package/dist/chunk-SAQ3EE5R.js +138 -0
  37. package/dist/{chunk-C4LCOOL4.js → chunk-TOSAAQ5A.js} +1 -1
  38. package/dist/chunk-WKFE3RUC.js +433 -0
  39. package/dist/{chunk-BGL5DRK2.js → chunk-XGZOU4DS.js} +1 -1
  40. package/dist/{commands-LEBG6DMD.js → commands-UW2C2ZN4.js} +5 -5
  41. package/dist/{conflicts-FJD3IVPQ.js → conflicts-RING6AHV.js} +22 -12
  42. package/dist/{contribute-XPAR2JER.js → contribute-LSY75JZH.js} +6 -5
  43. package/dist/{countdown-25E5C7AR.js → countdown-SZ2P4XHB.js} +267 -23
  44. package/dist/{diff-KFID4SX3.js → diff-NZVBVQSK.js} +14 -6
  45. package/dist/{doctor-J2GJFTSE.js → doctor-TJSXBVGV.js} +104 -18
  46. package/dist/{ground-control-IDCXN5FK.js → ground-control-ZJXPUIQN.js} +3 -3
  47. package/dist/{guard-RJZEEKSL.js → guard-ZO4Z3LLB.js} +47 -9
  48. package/dist/{handoff-5AGE2D3T.js → handoff-2OZSWGTE.js} +2 -0
  49. package/dist/{hook-HV6U3ANI.js → hook-3VPKNSOO.js} +14 -12
  50. package/dist/index.js +27 -26
  51. package/dist/{init-47WA2SCG.js → init-UW2BJBO2.js} +22 -16
  52. package/dist/install-RQSI4CHG.js +41 -0
  53. package/dist/installs-7TR4H4QH.js +222 -0
  54. package/dist/{mission-control-CRMCRZUU.js → mission-control-VSU6NT43.js} +1 -1
  55. package/dist/{queue-OJHKFKK3.js → queue-JHYILLMX.js} +10 -10
  56. package/dist/{run-Z2GHNVBO.js → run-CQF5RM5X.js} +29 -29
  57. package/dist/{run-plan-XA7MYOQ3.js → run-plan-BEOCOJCF.js} +13 -13
  58. package/dist/{scan-K3T5RQLC.js → scan-7D3RMO34.js} +2 -1
  59. package/dist/{session-start-PEVTDMOZ.js → session-start-QV7CEFRX.js} +18 -12
  60. package/dist/{sessions-6IGVH467.js → sessions-AWAAO3DU.js} +3 -3
  61. package/dist/{setup-global-KBJL7QRD.js → setup-global-ST4TT427.js} +9 -8
  62. package/dist/{status-3UGVDIO6.js → status-HUBPBGUU.js} +14 -11
  63. package/dist/update-DD5UZPGG.js +31 -0
  64. package/dist/update-all-YYUTXHGR.js +695 -0
  65. package/package.json +1 -1
  66. package/dist/chunk-HAFRAXGV.js +0 -17
  67. package/dist/chunk-ZNY32NK2.js +0 -52
  68. package/dist/install-Y63HEM4G.js +0 -38
  69. package/dist/update-4UQHGENC.js +0 -283
@@ -1,12 +1,20 @@
1
+ import {
2
+ logger
3
+ } from "./chunk-ZB43YMHW.js";
1
4
  import {
2
5
  compareSemver,
3
6
  normalizeSemver,
4
7
  readLocalKitVersion
5
- } from "./chunk-5HH3HSUR.js";
8
+ } from "./chunk-M4UL422I.js";
9
+ import {
10
+ isRetiredSkillId,
11
+ retireManagedFiles
12
+ } from "./chunk-SAQ3EE5R.js";
6
13
  import {
7
14
  L0_ARTIFACTS
8
- } from "./chunk-WS6OX2IG.js";
15
+ } from "./chunk-CGXLR77R.js";
9
16
  import {
17
+ UnknownPackError,
10
18
  copyRegistryFile,
11
19
  emptyStats,
12
20
  installPack,
@@ -15,11 +23,11 @@ import {
15
23
  mergeStats,
16
24
  recordOutcome,
17
25
  resolveProtectedGlobs
18
- } from "./chunk-LDZAK5DU.js";
26
+ } from "./chunk-JG3CNGQM.js";
19
27
  import {
20
28
  loadManagedHashLedger,
21
29
  saveManagedHashLedger
22
- } from "./chunk-ZJDJCMQO.js";
30
+ } from "./chunk-QX55T4UX.js";
23
31
  import {
24
32
  KIT_PACKAGE_SPEC,
25
33
  KIT_VERSION
@@ -137,6 +145,10 @@ async function installL0(registryRoot, projectRoot, protectedGlobs, ledger) {
137
145
  );
138
146
  recordOutcome(stats, artifact.target, outcome);
139
147
  }
148
+ for (const retired of await retireManagedFiles(projectRoot, protectedGlobs, managedHashes)) {
149
+ if (retired.outcome === "removed") stats.removed.push(retired.path);
150
+ else if (retired.outcome === "preserved-customized") stats.collisions.push(retired.path);
151
+ }
140
152
  if (!ledger) await saveManagedHashLedger(projectRoot, managedHashes);
141
153
  const migration = await migrateLegacyOnboardCommand(projectRoot);
142
154
  if (migration === "removed-managed") {
@@ -146,7 +158,8 @@ async function installL0(registryRoot, projectRoot, protectedGlobs, ledger) {
146
158
  }
147
159
  return stats;
148
160
  }
149
- async function syncFromManifest(registryRoot, projectRoot, manifest) {
161
+ async function syncFromManifest(registryRoot, projectRoot, manifest, options = {}) {
162
+ const onWarning = options.onWarning ?? ((message) => logger.warn(message));
150
163
  const protectedGlobs = resolveProtectedGlobs(manifest);
151
164
  const stats = emptyStats();
152
165
  const managedHashes = await loadManagedHashLedger(projectRoot);
@@ -154,9 +167,15 @@ async function syncFromManifest(registryRoot, projectRoot, manifest) {
154
167
  try {
155
168
  mergeStats(stats, await installL0(registryRoot, projectRoot, protectedGlobs, managedHashes));
156
169
  for (const packId of manifest.packs ?? []) {
157
- mergeStats(stats, await installPack(registryRoot, projectRoot, packId, installOpts));
170
+ try {
171
+ mergeStats(stats, await installPack(registryRoot, projectRoot, packId, installOpts));
172
+ } catch (err) {
173
+ if (!(err instanceof UnknownPackError)) throw err;
174
+ onWarning(err.message);
175
+ stats.missing.push(`pack:${packId}`);
176
+ }
158
177
  }
159
- const skillIds = manifest.skills ?? [];
178
+ const skillIds = (manifest.skills ?? []).filter((id) => !isRetiredSkillId(id));
160
179
  if (skillIds.length > 0) {
161
180
  await loadRegistry(registryRoot);
162
181
  mergeStats(stats, await installSkillsByIds(registryRoot, projectRoot, skillIds, installOpts));
@@ -475,7 +475,28 @@ var KNOWN_SHIPPED_OVERLAY_HASHES = /* @__PURE__ */ new Set([
475
475
  "b2fb21604ca3cdc4f42a48a6f29873a41ca7decad7133419c982a4a340f733b3",
476
476
  "48b3aae36a8baf10d5dcc5a9de441c93782835ce8b87c7e09e0971101c6f1614",
477
477
  "82e65afe6d183e9dcad0fbc6c60d381eee4e854e7ddffff56d1996b0f86886bd",
478
- "9b3e6543d8b3cda4a9a5fe39f3d205b9d466fa7f9a466fd51c0cccf354065a7e"
478
+ "9b3e6543d8b3cda4a9a5fe39f3d205b9d466fa7f9a466fd51c0cccf354065a7e",
479
+ "8aab3f979b9b1fac22b3090dbe82ed5a89466c599d9e2ad6a29447c9d5ad594b",
480
+ "29ad8ea146cfb47ce60644ecd26957d3dbc2009e8aa901f3c8e0d6bdebdddec3",
481
+ "483720b9181196ef45a79a838eecd9a0385c85656b3ca594a84e2b68c48f8795",
482
+ "6def70dacb187587ae81f8ea664cc69233f783084faad7f7eff0d9e7f2afc42a",
483
+ "796c04f23baf2029f2f0d450eb6c6a8f512b97a51894cd19b5992828e13ea58d",
484
+ "8b2be16fd45331efea075058ff63eb50f0a0742e36a28babae6e0f2ec53c6f2f",
485
+ "f7b48efcec313ea4a3962ddb8a0eecf819af9906be79e97692379b0fc701d792",
486
+ "3d29d3d2ac1f38cd69ecf83e4c50de7419b07e853ae865318682a13480542ece",
487
+ "6b48f8ada97dc27288723408d8a9f262ae0d22bba6c2fb08fbd12fa28b22f51a",
488
+ "a137cebc4d7c6a14ed56029c3d11571e73e4eb870984a7f901c0880a0980e70f",
489
+ "e154da7c04f7e634898a49a1c3b573ad314293ee652a05de6c1d559b1fecde66",
490
+ "9241867256f047eceb37b6f86623feef80ddeba9bf492da4f81a06084bd5bb97",
491
+ "670c05a2d888c9702da525febea29b624af8e0d6f0b0bd0bd7ba947a5fac2c6f",
492
+ "6bbca9f7b50a7e904d523a7e1318ddcc54f02bf811928ecae4e82cb80956be1c",
493
+ "82916f566f132583c9a70f661b9675f6204e4fddd6f624add6e7075d19cbf071",
494
+ "9c5a10086431050bee393060acc94d6383a22af627dec13483abbbffa452736c",
495
+ "dc6156f15b94e0b7dbd6b59e4d16dee932763fbcb5169e3a1119fc1b63cecfbf",
496
+ "ec8b8f4b3a12813a6cba9c5a417f5f1ef8ed34e27ea0c1cdc7d2987ce32e0d00",
497
+ "f0555c4a43c3cfd5e6c9fdc9ce14922aaf927d1251d98465f8bc50e6a992d547",
498
+ "9d419d86204df507806fb96dc9e2ba14335b11a1d1a584fbefb1bd31799f1edb",
499
+ "cb7dc49acdf3d4bcce0fc6df938fe6f7867ee548147049cae840d92759a7e665"
479
500
  ]);
480
501
 
481
502
  // src/lifecycle/paths.ts
@@ -619,6 +640,7 @@ export {
619
640
  assertRealParentContained,
620
641
  isRealWriteTargetContained,
621
642
  toPosixRel,
643
+ MANAGED_HASHES_REL,
622
644
  isConsumerOverlayPath,
623
645
  contentHash,
624
646
  loadManagedHashLedger,
@@ -0,0 +1,138 @@
1
+ import {
2
+ L0_ARTIFACTS
3
+ } from "./chunk-CGXLR77R.js";
4
+ import {
5
+ UnknownPackError,
6
+ allSkills,
7
+ isProtectedPath,
8
+ loadPackManifest,
9
+ loadRegistry,
10
+ packMemberFileTargets,
11
+ skillFileTargets
12
+ } from "./chunk-JG3CNGQM.js";
13
+ import {
14
+ contentHash,
15
+ resolveContained
16
+ } from "./chunk-QX55T4UX.js";
17
+ import {
18
+ MANIFEST_RELATIVE_PATH
19
+ } from "./chunk-6M6UKECW.js";
20
+
21
+ // src/lifecycle/retired.ts
22
+ import { lstat, readFile, rmdir, unlink } from "fs/promises";
23
+ import path from "path";
24
+ var RETIRED_SKILL_IDS = ["cursor-skills-groovy"];
25
+ var RETIRED_MANAGED_FILES = [
26
+ {
27
+ path: ".cursor/rules/cursor-skills-groovy.mdc",
28
+ hashes: /* @__PURE__ */ new Set([
29
+ "4bee84cedc08822a3c7ec61804574054031206ab0c66286b1adc81d2fd330f86",
30
+ "87eddaddb927069fd161845d514df56fdb395c3e8b893324c135020e2c0285a4"
31
+ ])
32
+ },
33
+ {
34
+ path: ".cursor/skills/community/cursor-skills-groovy/SKILL.md",
35
+ hashes: /* @__PURE__ */ new Set(["ac2f1f7d9e68f9c98fc4fe5ca348b1a90cf484141bbd116db871d63bdcc3c7c3"])
36
+ }
37
+ ];
38
+ function isRetiredSkillId(id) {
39
+ return RETIRED_SKILL_IDS.includes(id);
40
+ }
41
+ function dropRetiredSkillIds(skills) {
42
+ if (!skills) return { skills: void 0, dropped: [] };
43
+ const dropped = skills.filter(isRetiredSkillId);
44
+ return { skills: skills.filter((id) => !isRetiredSkillId(id)), dropped };
45
+ }
46
+ function formatRetiredSkillDrop(id) {
47
+ return `Skill '${id}' was retired from the registry and removed from "skills" in ${MANIFEST_RELATIVE_PATH} (ADR 2026-11-26 third-party skill license policy).`;
48
+ }
49
+ async function retireManagedFiles(projectRoot, protectedGlobs, ledger, files = RETIRED_MANAGED_FILES) {
50
+ const results = [];
51
+ for (const file of files) {
52
+ const abs = resolveContained(projectRoot, file.path);
53
+ let info;
54
+ try {
55
+ info = await lstat(abs);
56
+ } catch {
57
+ results.push({ path: file.path, outcome: "absent" });
58
+ continue;
59
+ }
60
+ if (isProtectedPath(file.path, protectedGlobs)) {
61
+ results.push({ path: file.path, outcome: "skipped-protected" });
62
+ continue;
63
+ }
64
+ if (info.isSymbolicLink() || !info.isFile()) {
65
+ results.push({ path: file.path, outcome: "skipped-symlink" });
66
+ continue;
67
+ }
68
+ const hash = contentHash(await readFile(abs, "utf8"));
69
+ const recorded = ledger?.hashes[file.path];
70
+ if (!file.hashes.has(hash) && hash !== recorded) {
71
+ results.push({ path: file.path, outcome: "preserved-customized" });
72
+ continue;
73
+ }
74
+ await unlink(abs);
75
+ if (ledger) delete ledger.hashes[file.path];
76
+ try {
77
+ await rmdir(path.dirname(abs));
78
+ } catch {
79
+ }
80
+ results.push({ path: file.path, outcome: "removed" });
81
+ }
82
+ return results;
83
+ }
84
+
85
+ // src/lifecycle/targets.ts
86
+ import path2 from "path";
87
+ var toPosix = (rel) => rel.split(path2.sep).join("/");
88
+ async function managedPairs(registryRoot, manifest, index) {
89
+ const pairs = [];
90
+ const missingSkills = [];
91
+ const missingPacks = [];
92
+ const push = (sourceRel, targetRel, origin) => {
93
+ pairs.push({ sourceRel: toPosix(sourceRel), targetRel: toPosix(targetRel), origin });
94
+ };
95
+ for (const a of L0_ARTIFACTS) push(a.source, a.target, "l0");
96
+ for (const packId of manifest.packs ?? []) {
97
+ let pack;
98
+ try {
99
+ pack = await loadPackManifest(registryRoot, packId);
100
+ } catch (err) {
101
+ if (!(err instanceof UnknownPackError)) throw err;
102
+ missingPacks.push(packId);
103
+ continue;
104
+ }
105
+ for (const member of pack.members) {
106
+ for (const { sourceRel, targetRel } of await packMemberFileTargets(registryRoot, member)) {
107
+ push(sourceRel, targetRel, "pack");
108
+ }
109
+ }
110
+ }
111
+ if ((manifest.skills ?? []).length > 0) {
112
+ const pool = allSkills(index ?? await loadRegistry(registryRoot));
113
+ for (const id of manifest.skills ?? []) {
114
+ if (isRetiredSkillId(id)) continue;
115
+ const skill = pool.find((s) => s.id === id);
116
+ if (!skill) {
117
+ missingSkills.push(id);
118
+ continue;
119
+ }
120
+ for (const { sourceRel, targetRel } of await skillFileTargets(
121
+ registryRoot,
122
+ skill.path,
123
+ skill.id
124
+ )) {
125
+ push(sourceRel, targetRel, "skill");
126
+ }
127
+ }
128
+ }
129
+ return { pairs, missingSkills, missingPacks };
130
+ }
131
+
132
+ export {
133
+ isRetiredSkillId,
134
+ dropRetiredSkillIds,
135
+ formatRetiredSkillDrop,
136
+ retireManagedFiles,
137
+ managedPairs
138
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  whichBinary
3
- } from "./chunk-W3ZJVBNY.js";
3
+ } from "./chunk-IFBIO7VT.js";
4
4
 
5
5
  // src/plan-loop/detect.ts
6
6
  var DETECT_ORDER = ["cursor-agent", "claude"];
@@ -0,0 +1,433 @@
1
+ import {
2
+ MANIFEST_RELATIVE_PATH,
3
+ acquireDirLock
4
+ } from "./chunk-6M6UKECW.js";
5
+ import {
6
+ KIT_VERSION
7
+ } from "./chunk-7HDQEK6T.js";
8
+ import {
9
+ fileExists
10
+ } from "./chunk-5B4DVO6C.js";
11
+
12
+ // src/installs/inspect.ts
13
+ import { execFile } from "child_process";
14
+ import { readFile, realpath } from "fs/promises";
15
+ import { homedir, tmpdir } from "os";
16
+ import path from "path";
17
+ import { promisify } from "util";
18
+ var execFileAsync = promisify(execFile);
19
+ var FACTORY_REMOTE_MARKERS = ["agent-kit-dev"];
20
+ var FACTORY_CLI_PACKAGES = /* @__PURE__ */ new Set(["@dadado/agent-kit-cli", "@missionkit/cli"]);
21
+ var FIXTURE_SEGMENTS = /* @__PURE__ */ new Set([
22
+ "fixtures",
23
+ "__fixtures__",
24
+ "test-fixtures",
25
+ "testdata",
26
+ "__tests__"
27
+ ]);
28
+ function sanitizeRemote(url) {
29
+ if (!url) return null;
30
+ const trimmed = url.trim();
31
+ if (!trimmed) return null;
32
+ try {
33
+ const parsed = new URL(trimmed);
34
+ if (parsed.username || parsed.password) {
35
+ parsed.username = "";
36
+ parsed.password = "";
37
+ return parsed.toString();
38
+ }
39
+ return trimmed;
40
+ } catch {
41
+ return trimmed;
42
+ }
43
+ }
44
+ function isUnder(child, parent) {
45
+ const rel = path.relative(parent, child);
46
+ return rel === "" || !rel.startsWith("..") && !path.isAbsolute(rel);
47
+ }
48
+ function isFactoryInstall(facts) {
49
+ const origin = facts.origin?.toLowerCase() ?? "";
50
+ if (FACTORY_REMOTE_MARKERS.some((m) => origin.includes(m))) return true;
51
+ return facts.cliPackageName !== null && FACTORY_CLI_PACKAGES.has(facts.cliPackageName);
52
+ }
53
+ function classifyInstall(facts) {
54
+ if (facts.path === facts.home) return "home";
55
+ if (facts.tmpRoots.some((root) => isUnder(facts.path, root))) return "fixture";
56
+ const rel = path.relative(facts.home, facts.path);
57
+ const segments = (isUnder(facts.path, facts.home) ? rel : facts.path).split(path.sep);
58
+ if (segments.some((s) => FIXTURE_SEGMENTS.has(s))) return "fixture";
59
+ if (facts.git && facts.git.toplevel !== facts.path) return "fixture";
60
+ if (isFactoryInstall(facts)) return "factory";
61
+ if (facts.git && facts.git.gitDir !== facts.git.commonDir) return "worktree";
62
+ return "repo";
63
+ }
64
+ function gitEnv() {
65
+ const env = { ...process.env };
66
+ for (const key of [
67
+ "GIT_DIR",
68
+ "GIT_WORK_TREE",
69
+ "GIT_COMMON_DIR",
70
+ "GIT_INDEX_FILE",
71
+ "GIT_OBJECT_DIRECTORY",
72
+ "GIT_ALTERNATE_OBJECT_DIRECTORIES",
73
+ "GIT_CEILING_DIRECTORIES"
74
+ ]) {
75
+ delete env[key];
76
+ }
77
+ return env;
78
+ }
79
+ async function safeRealpath(p) {
80
+ try {
81
+ return await realpath(p);
82
+ } catch {
83
+ return path.resolve(p);
84
+ }
85
+ }
86
+ async function readGitFacts(dir) {
87
+ try {
88
+ const { stdout } = await execFileAsync(
89
+ "git",
90
+ ["rev-parse", "--path-format=absolute", "--show-toplevel", "--git-dir", "--git-common-dir"],
91
+ { cwd: dir, env: gitEnv(), encoding: "utf8", timeout: 5e3 }
92
+ );
93
+ const [toplevel, gitDir, commonDir] = stdout.trim().split("\n");
94
+ if (!toplevel || !gitDir || !commonDir) return null;
95
+ return {
96
+ toplevel: await safeRealpath(toplevel),
97
+ gitDir: await safeRealpath(gitDir),
98
+ commonDir: await safeRealpath(commonDir)
99
+ };
100
+ } catch {
101
+ return null;
102
+ }
103
+ }
104
+ async function readOrigin(dir) {
105
+ try {
106
+ const { stdout } = await execFileAsync("git", ["remote", "get-url", "origin"], {
107
+ cwd: dir,
108
+ env: gitEnv(),
109
+ encoding: "utf8",
110
+ timeout: 5e3
111
+ });
112
+ return stdout.trim() || null;
113
+ } catch {
114
+ return null;
115
+ }
116
+ }
117
+ async function readCliPackageName(dir) {
118
+ try {
119
+ const raw = await readFile(path.join(dir, "packages", "cli", "package.json"), "utf8");
120
+ const name = JSON.parse(raw).name;
121
+ return typeof name === "string" ? name : null;
122
+ } catch {
123
+ return null;
124
+ }
125
+ }
126
+ async function readManifestVersion(dir) {
127
+ let raw;
128
+ try {
129
+ raw = await readFile(path.join(dir, MANIFEST_RELATIVE_PATH), "utf8");
130
+ } catch {
131
+ return void 0;
132
+ }
133
+ try {
134
+ const version = JSON.parse(raw).version;
135
+ return typeof version === "string" && version.trim() ? version.trim() : null;
136
+ } catch {
137
+ return null;
138
+ }
139
+ }
140
+ function hasInstallManifest(dir) {
141
+ return fileExists(path.join(dir, MANIFEST_RELATIVE_PATH));
142
+ }
143
+ async function defaultTmpRoots() {
144
+ const roots = /* @__PURE__ */ new Set([await safeRealpath(tmpdir())]);
145
+ if (process.platform !== "win32") roots.add(await safeRealpath("/tmp"));
146
+ return [...roots];
147
+ }
148
+ async function inspectInstall(dir, options = {}) {
149
+ const installPath = await safeRealpath(dir);
150
+ const kitVersion = await readManifestVersion(installPath);
151
+ if (kitVersion === void 0) return null;
152
+ const home = await safeRealpath(options.home ?? homedir());
153
+ const tmpRoots = options.tmpRoots ? await Promise.all(options.tmpRoots.map(safeRealpath)) : await defaultTmpRoots();
154
+ const git = await readGitFacts(installPath);
155
+ const origin = git && git.toplevel === installPath ? await readOrigin(installPath) : null;
156
+ const facts = {
157
+ path: installPath,
158
+ home,
159
+ tmpRoots,
160
+ git,
161
+ origin,
162
+ cliPackageName: await readCliPackageName(installPath)
163
+ };
164
+ return {
165
+ path: installPath,
166
+ remote: sanitizeRemote(origin),
167
+ kitVersion,
168
+ cliVersion: options.cliVersion ?? KIT_VERSION,
169
+ kind: classifyInstall(facts)
170
+ };
171
+ }
172
+
173
+ // src/installs/store.ts
174
+ import { randomUUID } from "crypto";
175
+ import { mkdir, readFile as readFile2, rename, rm, writeFile } from "fs/promises";
176
+ import { homedir as homedir2 } from "os";
177
+ import path2 from "path";
178
+ var INSTALLS_SCHEMA_VERSION = 1;
179
+ var INSTALLS_FILENAME = "installs.json";
180
+ var INSTALLS_FILE_ENV = "AGENT_KIT_INSTALLS_FILE";
181
+ var INSTALL_KINDS = [
182
+ "repo",
183
+ "worktree",
184
+ "fixture",
185
+ "factory",
186
+ "home"
187
+ ];
188
+ var InstallsRegistryError = class extends Error {
189
+ constructor(message, file) {
190
+ super(message);
191
+ this.file = file;
192
+ this.name = "InstallsRegistryError";
193
+ }
194
+ file;
195
+ };
196
+ function resolveInstallsFile(env = process.env, home = homedir2()) {
197
+ const override = env[INSTALLS_FILE_ENV]?.trim();
198
+ if (override) return path2.resolve(override);
199
+ const xdg = env.XDG_CONFIG_HOME?.trim();
200
+ const configDir = xdg && path2.isAbsolute(xdg) ? xdg : path2.join(home, ".config");
201
+ return path2.join(configDir, "agent-kit", INSTALLS_FILENAME);
202
+ }
203
+ function isInstallEntry(value) {
204
+ if (!value || typeof value !== "object") return false;
205
+ const e = value;
206
+ return typeof e.path === "string" && path2.isAbsolute(e.path) && (e.remote === null || typeof e.remote === "string") && (e.kitVersion === null || typeof e.kitVersion === "string") && typeof e.cliVersion === "string" && typeof e.lastSeen === "string" && INSTALL_KINDS.includes(e.kind);
207
+ }
208
+ function parseInstallsFile(raw, file) {
209
+ let parsed;
210
+ try {
211
+ parsed = JSON.parse(raw);
212
+ } catch {
213
+ throw new InstallsRegistryError(
214
+ `${file} is not valid JSON; move it aside and run \`agent-kit installs scan\` to rebuild it.`,
215
+ file
216
+ );
217
+ }
218
+ const body = parsed;
219
+ if (!body || typeof body !== "object" || !Array.isArray(body.installs)) {
220
+ throw new InstallsRegistryError(
221
+ `${file} has no installs list; move it aside and run \`agent-kit installs scan\` to rebuild it.`,
222
+ file
223
+ );
224
+ }
225
+ if (body.schemaVersion !== INSTALLS_SCHEMA_VERSION) {
226
+ throw new InstallsRegistryError(
227
+ `${file} has schemaVersion ${String(body.schemaVersion)}; this CLI understands ${INSTALLS_SCHEMA_VERSION} (newer CLI?). Left untouched.`,
228
+ file
229
+ );
230
+ }
231
+ const installs = body.installs.filter(isInstallEntry);
232
+ const unrecognized = body.installs.filter((row) => !isInstallEntry(row));
233
+ return { schemaVersion: INSTALLS_SCHEMA_VERSION, installs, unrecognized };
234
+ }
235
+ async function readInstalls(options = {}) {
236
+ const file = options.file ?? resolveInstallsFile();
237
+ let raw;
238
+ try {
239
+ raw = await readFile2(file, "utf8");
240
+ } catch (err) {
241
+ if (err.code === "ENOENT") {
242
+ return { schemaVersion: INSTALLS_SCHEMA_VERSION, installs: [] };
243
+ }
244
+ throw err;
245
+ }
246
+ return parseInstallsFile(raw, file);
247
+ }
248
+ async function listInstalls(options = {}) {
249
+ const { installs } = await readInstalls(options);
250
+ return [...installs].sort((a, b) => a.path.localeCompare(b.path));
251
+ }
252
+ async function writeInstallsFile(file, body) {
253
+ await mkdir(path2.dirname(file), { recursive: true });
254
+ const tmp = `${file}.${process.pid}.${randomUUID()}.tmp`;
255
+ const known = new Set(body.installs.map((e) => e.path));
256
+ const kept = (body.unrecognized ?? []).filter((row) => {
257
+ const rowPath = row?.path;
258
+ return !(typeof rowPath === "string" && known.has(rowPath));
259
+ });
260
+ const sorted = {
261
+ schemaVersion: INSTALLS_SCHEMA_VERSION,
262
+ installs: [...[...body.installs].sort((a, b) => a.path.localeCompare(b.path)), ...kept]
263
+ };
264
+ try {
265
+ await writeFile(tmp, `${JSON.stringify(sorted, null, 2)}
266
+ `, "utf8");
267
+ await rename(tmp, file);
268
+ } catch (err) {
269
+ await rm(tmp, { force: true }).catch(() => void 0);
270
+ throw err;
271
+ }
272
+ }
273
+ async function mutateInstalls(options, mutate) {
274
+ const file = options.file ?? resolveInstallsFile();
275
+ const unlock = await acquireDirLock(file, {
276
+ timeoutMs: options.lockTimeoutMs,
277
+ timeoutMessage: (target) => `Timed out waiting for the install registry lock on ${target}. Another agent-kit process may be stuck.`
278
+ });
279
+ try {
280
+ const current = await readInstalls({ file });
281
+ const { installs, result, changed } = await mutate(current.installs);
282
+ if (changed) {
283
+ await writeInstallsFile(file, {
284
+ schemaVersion: INSTALLS_SCHEMA_VERSION,
285
+ installs,
286
+ unrecognized: current.unrecognized
287
+ });
288
+ }
289
+ return result;
290
+ } finally {
291
+ await unlock();
292
+ }
293
+ }
294
+ async function upsertInstalls(records, options = {}) {
295
+ if (records.length === 0) return [];
296
+ const now = (options.now ?? (() => /* @__PURE__ */ new Date()))().toISOString();
297
+ return mutateInstalls(options, async (current) => {
298
+ const byPath = new Map(current.map((e) => [e.path, e]));
299
+ const written = [];
300
+ for (const record of records) {
301
+ if (options.stillInstalled && !await options.stillInstalled(record.path)) continue;
302
+ const entry = {
303
+ path: record.path,
304
+ remote: record.remote,
305
+ kitVersion: record.kitVersion,
306
+ cliVersion: record.cliVersion,
307
+ lastSeen: record.lastSeen ?? now,
308
+ kind: record.kind
309
+ };
310
+ if (!isInstallEntry(entry)) continue;
311
+ byPath.set(entry.path, entry);
312
+ written.push(entry);
313
+ }
314
+ return { installs: [...byPath.values()], result: written, changed: written.length > 0 };
315
+ });
316
+ }
317
+ async function pruneInstalls(options) {
318
+ return mutateInstalls(options, async (current) => {
319
+ const kept = [];
320
+ const removed = [];
321
+ for (const entry of current) {
322
+ if (await options.stillInstalled(entry.path)) kept.push(entry);
323
+ else removed.push(entry);
324
+ }
325
+ return { installs: kept, result: removed, changed: removed.length > 0 };
326
+ });
327
+ }
328
+
329
+ // src/installs/scan.ts
330
+ import { readdir, realpath as realpath2 } from "fs/promises";
331
+ import path3 from "path";
332
+ var DEFAULT_SCAN_DEPTH = 5;
333
+ var DEFAULT_SCAN_MAX_DIRS = 2e4;
334
+ var SKIP_DIRS = /* @__PURE__ */ new Set([
335
+ "node_modules",
336
+ "bower_components",
337
+ "vendor",
338
+ "dist",
339
+ "build",
340
+ "target",
341
+ "out",
342
+ "coverage",
343
+ "__pycache__",
344
+ "venv",
345
+ "Library",
346
+ "Applications",
347
+ "snap",
348
+ "AppData"
349
+ ]);
350
+ var HIDDEN_WORKTREE_HOMES = {
351
+ ".worktrees": ".worktrees",
352
+ ".claude": path3.join(".claude", "worktrees")
353
+ };
354
+ async function scanForInstalls(roots, options = {}) {
355
+ const maxDepth = options.maxDepth ?? DEFAULT_SCAN_DEPTH;
356
+ const maxDirs = options.maxDirs ?? DEFAULT_SCAN_MAX_DIRS;
357
+ const found = /* @__PURE__ */ new Set();
358
+ const seen = /* @__PURE__ */ new Set();
359
+ let visited = 0;
360
+ let truncated = false;
361
+ const queue = [];
362
+ for (const root of roots) {
363
+ try {
364
+ queue.push({ dir: await realpath2(path3.resolve(root)), depth: 0 });
365
+ } catch {
366
+ }
367
+ }
368
+ while (queue.length > 0) {
369
+ const next = queue.shift();
370
+ if (!next) break;
371
+ const { dir, depth } = next;
372
+ if (seen.has(dir)) continue;
373
+ if (visited >= maxDirs) {
374
+ truncated = true;
375
+ break;
376
+ }
377
+ seen.add(dir);
378
+ visited += 1;
379
+ if (await hasInstallManifest(dir)) found.add(dir);
380
+ if (depth >= maxDepth) continue;
381
+ let entries;
382
+ try {
383
+ entries = await readdir(dir, { withFileTypes: true });
384
+ } catch {
385
+ continue;
386
+ }
387
+ for (const entry of entries) {
388
+ if (!entry.isDirectory()) continue;
389
+ const name = entry.name;
390
+ if (name.startsWith(".")) {
391
+ const sub = HIDDEN_WORKTREE_HOMES[name];
392
+ if (sub) queue.push({ dir: path3.join(dir, sub), depth: depth + 1 });
393
+ continue;
394
+ }
395
+ if (SKIP_DIRS.has(name)) continue;
396
+ queue.push({ dir: path3.join(dir, name), depth: depth + 1 });
397
+ }
398
+ }
399
+ return { found: [...found].sort(), visited, truncated };
400
+ }
401
+
402
+ // src/installs/index.ts
403
+ async function recordInstalls(dirs, options = {}) {
404
+ const records = [];
405
+ for (const dir of dirs) {
406
+ const record = await inspectInstall(dir, options);
407
+ if (record) records.push(record);
408
+ }
409
+ return upsertInstalls(records, { ...options, stillInstalled: hasInstallManifest });
410
+ }
411
+ function pruneMissingInstalls(options = {}) {
412
+ return pruneInstalls({ ...options, stillInstalled: hasInstallManifest });
413
+ }
414
+ var FEED_LOCK_TIMEOUT_MS = 3e3;
415
+ async function feedInstallsRegistry(root) {
416
+ try {
417
+ await recordInstalls([root], { lockTimeoutMs: FEED_LOCK_TIMEOUT_MS });
418
+ } catch {
419
+ }
420
+ }
421
+
422
+ export {
423
+ inspectInstall,
424
+ InstallsRegistryError,
425
+ resolveInstallsFile,
426
+ listInstalls,
427
+ DEFAULT_SCAN_DEPTH,
428
+ DEFAULT_SCAN_MAX_DIRS,
429
+ scanForInstalls,
430
+ recordInstalls,
431
+ pruneMissingInstalls,
432
+ feedInstallsRegistry
433
+ };
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  claudeRedactions,
6
6
  redactSecrets
7
- } from "./chunk-W3ZJVBNY.js";
7
+ } from "./chunk-IFBIO7VT.js";
8
8
  import {
9
9
  findHitlGateInText
10
10
  } from "./chunk-P7732A25.js";