@pushary/agent-hooks 1.9.6 → 1.9.8

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 (111) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +3 -3
  3. package/data/cursor-plugin/README.md +3 -7
  4. package/data/vscode-plugin/README.md +1 -1
  5. package/dist/bin/pushary-bell-hook.js +22 -23
  6. package/dist/bin/pushary-bell.js +9 -9
  7. package/dist/bin/pushary-claude.js +27 -28
  8. package/dist/bin/pushary-clean.js +98 -76
  9. package/dist/bin/pushary-codex-bridge.js +18 -18
  10. package/dist/bin/pushary-codex-hook.js +32 -33
  11. package/dist/bin/pushary-codex.js +13 -13
  12. package/dist/bin/pushary-connect.js +24 -21
  13. package/dist/bin/pushary-cowork.js +5 -5
  14. package/dist/bin/pushary-daemon.js +51 -38
  15. package/dist/bin/pushary-disconnect.js +187 -52
  16. package/dist/bin/pushary-doctor.js +68 -56
  17. package/dist/bin/pushary-elicitation-hook.js +24 -25
  18. package/dist/bin/pushary-gemini-bridge.js +13 -13
  19. package/dist/bin/pushary-gemini-hook.js +29 -30
  20. package/dist/bin/pushary-hook.js +30 -32
  21. package/dist/bin/pushary-login.js +12 -12
  22. package/dist/bin/pushary-logout.js +105 -42
  23. package/dist/bin/pushary-mcp.js +9 -9
  24. package/dist/bin/pushary-mode.js +28 -31
  25. package/dist/bin/pushary-notification-hook.js +26 -28
  26. package/dist/bin/pushary-opencode-hook.js +28 -29
  27. package/dist/bin/pushary-permission-denied-hook.js +30 -32
  28. package/dist/bin/pushary-permission-hook.js +29 -31
  29. package/dist/bin/pushary-post-hook.js +26 -28
  30. package/dist/bin/pushary-prompt-hook.js +26 -28
  31. package/dist/bin/pushary-session-end-hook.js +26 -28
  32. package/dist/bin/pushary-session-start-hook.js +31 -31
  33. package/dist/bin/pushary-setup.js +98 -106
  34. package/dist/bin/pushary-stats.js +5 -5
  35. package/dist/bin/pushary-status.js +34 -18
  36. package/dist/bin/pushary-stop-hook.js +26 -28
  37. package/dist/bin/pushary-stopfailure-hook.js +26 -28
  38. package/dist/bin/pushary-suggestions.js +19 -21
  39. package/dist/bin/pushary-transcript-register.js +18 -19
  40. package/dist/bin/pushary-transcripts.js +7 -7
  41. package/dist/bin/pushary-upgrade.js +67 -31
  42. package/dist/bin/pushary-wait.js +23 -19
  43. package/dist/bin/pushary.js +15 -14
  44. package/dist/{chunk-BSZ7VBVT.js → chunk-2A53H4S6.js} +17 -15
  45. package/dist/{chunk-D7SOOVHX.js → chunk-2QGYMY7A.js} +83 -3
  46. package/dist/{chunk-SVTHEMM3.js → chunk-2QTO5YIT.js} +6 -6
  47. package/dist/{chunk-WN6WYUCV.js → chunk-2VZAALEJ.js} +5 -9
  48. package/dist/chunk-2WXF3QJR.js +49 -0
  49. package/dist/{chunk-UKNKYTTY.js → chunk-3I6IVOZV.js} +3 -3
  50. package/dist/chunk-3Z3A37WD.js +77 -0
  51. package/dist/{chunk-2QRE6QH2.js → chunk-5QUPKDI5.js} +1 -1
  52. package/dist/chunk-6TE27XZR.js +69 -0
  53. package/dist/{chunk-L6USMDTW.js → chunk-7DVNSQWF.js} +59 -15
  54. package/dist/{chunk-SNJ3BOCP.js → chunk-7PT35RY2.js} +27 -8
  55. package/dist/{chunk-CBVDW2N6.js → chunk-B64KHETR.js} +3 -3
  56. package/dist/chunk-BEJRK4DF.js +94 -0
  57. package/dist/chunk-BXET3ALR.js +46 -0
  58. package/dist/{chunk-DJ4BB264.js → chunk-CD47ZFFZ.js} +1 -1
  59. package/dist/{chunk-FBD3QGVJ.js → chunk-CKV3UPMU.js} +2 -2
  60. package/dist/{chunk-7JTVYR5B.js → chunk-CLOSJ4ES.js} +1 -1
  61. package/dist/{chunk-DA4FTGTK.js → chunk-DKMD6AWR.js} +4 -4
  62. package/dist/{chunk-SPXBXN23.js → chunk-DL7XWKYV.js} +7 -5
  63. package/dist/{chunk-VRT3EEZN.js → chunk-DPGSLWOS.js} +8 -8
  64. package/dist/{chunk-3BUAEQCY.js → chunk-DUZVXBBU.js} +1 -1
  65. package/dist/{chunk-6GERGJHF.js → chunk-EUW7JL2K.js} +0 -32
  66. package/dist/{chunk-75CA37FZ.js → chunk-FQ2GORVG.js} +2 -2
  67. package/dist/{chunk-WUKUXICK.js → chunk-HRULIYDU.js} +2 -2
  68. package/dist/{chunk-Q4E56K4X.js → chunk-I5IJRMNV.js} +78 -8
  69. package/dist/{chunk-MKJ3RTUS.js → chunk-I6MJXLMY.js} +2 -2
  70. package/dist/{chunk-YPXUD6DW.js → chunk-IAD2RT4L.js} +14 -14
  71. package/dist/{chunk-LBLCFD5K.js → chunk-IHFDPV7C.js} +2 -2
  72. package/dist/{chunk-BVCHY4OY.js → chunk-IHO3YQAN.js} +2 -2
  73. package/dist/{chunk-RDK7FX5F.js → chunk-KF3UZLYI.js} +1 -1
  74. package/dist/chunk-KFF7G225.js +599 -0
  75. package/dist/{chunk-TE5M6GGK.js → chunk-KHNFLYJO.js} +204 -28
  76. package/dist/{chunk-CCDVL63C.js → chunk-KRCR2CRQ.js} +9 -9
  77. package/dist/{chunk-ZC3TF4LR.js → chunk-LKLVTG3V.js} +18 -9
  78. package/dist/{chunk-4QKM44N6.js → chunk-LWOO567I.js} +4 -3
  79. package/dist/{chunk-KK54WQ74.js → chunk-M6BZZFVQ.js} +1 -1
  80. package/dist/{chunk-RIC6OOJX.js → chunk-MFF3ONG5.js} +21 -1
  81. package/dist/{chunk-IMGJYFCX.js → chunk-MGRFDGWU.js} +3 -2
  82. package/dist/{chunk-ZPW4MJOV.js → chunk-MKTJEXZ3.js} +3 -3
  83. package/dist/{chunk-2I23NFVT.js → chunk-MXHTGVFZ.js} +52 -9
  84. package/dist/{chunk-5BHROGRB.js → chunk-N4QSPI3B.js} +54 -5
  85. package/dist/{chunk-DGQTJDSJ.js → chunk-NWDG3MSW.js} +1 -1
  86. package/dist/chunk-OP7IHC2I.js +24 -0
  87. package/dist/{chunk-EVFY3VE6.js → chunk-QOLITCIP.js} +1 -1
  88. package/dist/{chunk-W4Q7NFXU.js → chunk-TCQ43LSG.js} +3 -3
  89. package/dist/chunk-TCWKTUAE.js +50 -0
  90. package/dist/{chunk-EZAFBC2C.js → chunk-V5HPPF3E.js} +8 -4
  91. package/dist/{chunk-Q23MMVTD.js → chunk-WG3K4TCH.js} +1 -1
  92. package/dist/{chunk-F56SB65Y.js → chunk-WS4H76EP.js} +2 -2
  93. package/dist/{chunk-HWQNQVY6.js → chunk-WWOHTTVP.js} +2 -2
  94. package/dist/{chunk-NVGDMTX3.js → chunk-YIG2R3BJ.js} +9 -7
  95. package/dist/{chunk-HJXZJF6O.js → chunk-ZBHUHJG6.js} +4 -4
  96. package/dist/{chunk-5AXCOTIT.js → chunk-ZBK6E2OR.js} +1 -1
  97. package/dist/{chunk-5PMTC2CB.js → chunk-ZN3C6GBG.js} +84 -673
  98. package/dist/{chunk-GQHZIBAZ.js → chunk-ZSTSEBG7.js} +1 -1
  99. package/dist/{chunk-PYZC54KA.js → chunk-ZW3XZLJC.js} +61 -17
  100. package/dist/{global-upgrade-7F5RP45B.js → global-upgrade-I56HNM23.js} +6 -6
  101. package/dist/{paths-MELXIVBO.js → paths-AGY43CXS.js} +2 -2
  102. package/dist/reapply-IA5XUKWW.js +57 -0
  103. package/dist/src/index.d.ts +1 -0
  104. package/dist/src/index.js +19 -20
  105. package/dist/{upgrade-lock-AHRBA66K.js → upgrade-lock-B34TAUKV.js} +5 -3
  106. package/package.json +1 -1
  107. package/dist/chunk-HT3WMM6Q.js +0 -44
  108. package/dist/chunk-IR5FRUPQ.js +0 -197
  109. package/dist/chunk-JUFKJCZG.js +0 -38
  110. package/dist/chunk-SJN22ADZ.js +0 -86
  111. package/dist/reapply-NOB2Q6C4.js +0 -35
@@ -0,0 +1,599 @@
1
+ import {
2
+ openCodeConfigDirFrom
3
+ } from "./chunk-MFF3ONG5.js";
4
+ import {
5
+ codexHomeFrom,
6
+ resolvePathBinary
7
+ } from "./chunk-ZBHUHJG6.js";
8
+ import {
9
+ HOOK_COMPATIBLE_PROFILES
10
+ } from "./chunk-I5IJRMNV.js";
11
+
12
+ // src/hermes-config.ts
13
+ import { execFileSync } from "child_process";
14
+ import { existsSync, readFileSync, rmSync, writeFileSync } from "fs";
15
+ import { homedir, tmpdir } from "os";
16
+ import { join } from "path";
17
+ var isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
18
+ var isSnapshot = (value) => isRecord(value) && typeof value.present === "boolean" && Object.hasOwn(value, "value");
19
+ var isHermesConfigReceipt = (value) => {
20
+ if (!isRecord(value)) return false;
21
+ return ["security", "approval", "transport", "fallback", "plugins", "enabled", "agent", "disabled"].every((key) => isSnapshot(value[key])) && typeof value.pushary_enabled === "boolean" && typeof value.clarify_disabled === "boolean";
22
+ };
23
+ var HERMES_PIP_PACKAGE = "hermes-plugin-pushary";
24
+ var HERMES_PLUGIN_NAME = "pushary";
25
+ var HERMES_CONFIG_SCRIPT = String.raw`
26
+ import copy, importlib.util, json, os, sys
27
+ from hermes_cli.config import load_config, save_config
28
+
29
+ PUSHARY_TRANSPORT = "pushary"
30
+ PUSHARY_FALLBACK = "builtin"
31
+ PUSHARY_PLUGIN = "pushary"
32
+ PUSHARY_PLUGIN_MODULE = "pushary_plugin"
33
+ QUESTION_TOOLSET = "clarify"
34
+
35
+ mode = sys.argv[1]
36
+ receipt_path = sys.argv[2] if len(sys.argv) > 2 else None
37
+ c = load_config()
38
+ original = copy.deepcopy(c)
39
+
40
+ def section(obj, key):
41
+ value = obj.get(key)
42
+ return value if isinstance(value, dict) else {}
43
+
44
+ def members(obj, key):
45
+ value = obj.get(key)
46
+ return value if isinstance(value, list) else []
47
+
48
+ if mode == "status":
49
+ print(json.dumps({
50
+ "plugin_installed": importlib.util.find_spec(PUSHARY_PLUGIN_MODULE) is not None,
51
+ "plugin_enabled": PUSHARY_PLUGIN in members(section(c, "plugins"), "enabled"),
52
+ "approvals_routed": section(section(c, "security"), "approval").get("transport") == PUSHARY_TRANSPORT,
53
+ "questions_routed": QUESTION_TOOLSET in members(section(c, "agent"), "disabled_toolsets"),
54
+ }))
55
+ sys.exit(0)
56
+
57
+ def recorded(snapshot, value):
58
+ return bool(snapshot.get("present")) and snapshot.get("value") == value
59
+
60
+ def pop_if(obj, key, value):
61
+ if obj.get(key) == value:
62
+ obj.pop(key, None)
63
+
64
+ def snap(obj, key):
65
+ return {"present": key in obj, "value": obj.get(key)}
66
+
67
+ restore_conflicts = []
68
+
69
+ def restore(obj, key, before, ours):
70
+ if before.get("present") and before.get("value") == ours:
71
+ return
72
+ if before.get("present"):
73
+ if key in obj and obj.get(key) == before.get("value"):
74
+ return
75
+ elif key not in obj:
76
+ return
77
+ if obj.get(key) != ours:
78
+ restore_conflicts.append(key)
79
+ return
80
+ if before.get("present"):
81
+ obj[key] = before.get("value")
82
+ else:
83
+ obj.pop(key, None)
84
+
85
+ def restore_container(obj, key, before, current, changed):
86
+ raw = obj.get(key)
87
+ if isinstance(before.get("value"), dict):
88
+ if not isinstance(raw, dict):
89
+ if changed:
90
+ restore_conflicts.append(key)
91
+ return
92
+ if current or before.get("present"):
93
+ obj[key] = current
94
+ else:
95
+ obj.pop(key, None)
96
+ elif isinstance(raw, dict) and current:
97
+ restore_conflicts.append(key)
98
+ else:
99
+ restore(obj, key, before, {})
100
+
101
+ def restore_list_member(obj, key, before, ours, ours_before):
102
+ raw = obj.get(key)
103
+ if isinstance(before.get("value"), list):
104
+ if ours_before:
105
+ return
106
+ if not isinstance(raw, list):
107
+ restore_conflicts.append(key)
108
+ return
109
+ remaining = [item for item in raw if item != ours]
110
+ if remaining or before.get("present"):
111
+ obj[key] = remaining
112
+ else:
113
+ obj.pop(key, None)
114
+ return
115
+ if before.get("present") and raw == before.get("value"):
116
+ return
117
+ if not before.get("present") and key not in obj:
118
+ return
119
+ if not isinstance(raw, list):
120
+ restore_conflicts.append(key)
121
+ return
122
+ remaining = [item for item in raw if item != ours]
123
+ if remaining:
124
+ restore_conflicts.append(key)
125
+ else:
126
+ restore(obj, key, before, raw)
127
+
128
+ def valid_snapshot(value):
129
+ return isinstance(value, dict) and isinstance(value.get("present"), bool) and "value" in value
130
+
131
+ def valid_receipt(value):
132
+ snapshots = ["security", "approval", "transport", "fallback", "plugins", "enabled", "agent", "disabled"]
133
+ return (isinstance(value, dict)
134
+ and all(valid_snapshot(value.get(key)) for key in snapshots)
135
+ and isinstance(value.get("pushary_enabled"), bool)
136
+ and isinstance(value.get("clarify_disabled"), bool))
137
+
138
+ if mode == "setup":
139
+ security_before = snap(c, "security")
140
+ s = section(c, "security")
141
+ approval_before = snap(s, "approval")
142
+ ap = section(s, "approval")
143
+ plugins_before = snap(c, "plugins")
144
+ p = section(c, "plugins")
145
+ agent_before = snap(c, "agent")
146
+ a = section(c, "agent")
147
+ enabled = members(p, "enabled")
148
+ disabled = members(a, "disabled_toolsets")
149
+ receipt = {
150
+ "security": security_before,
151
+ "approval": approval_before,
152
+ "transport": snap(ap, "transport"),
153
+ "fallback": snap(ap, "transport_fallback"),
154
+ "plugins": plugins_before,
155
+ "enabled": snap(p, "enabled"),
156
+ "pushary_enabled": PUSHARY_PLUGIN in enabled,
157
+ "agent": agent_before,
158
+ "disabled": snap(a, "disabled_toolsets"),
159
+ "clarify_disabled": QUESTION_TOOLSET in disabled,
160
+ }
161
+ if os.path.exists(receipt_path):
162
+ with open(receipt_path, encoding="utf-8") as handle:
163
+ existing_receipt = json.load(handle)
164
+ if not valid_receipt(existing_receipt):
165
+ raise ValueError("invalid Pushary Hermes setup receipt")
166
+ else:
167
+ os.makedirs(os.path.dirname(receipt_path), exist_ok=True)
168
+ temp = receipt_path + ".tmp"
169
+ with open(temp, "x", encoding="utf-8") as handle:
170
+ json.dump(receipt, handle)
171
+ os.chmod(temp, 0o600)
172
+ os.replace(temp, receipt_path)
173
+ ap["transport"] = PUSHARY_TRANSPORT
174
+ ap["transport_fallback"] = PUSHARY_FALLBACK
175
+ s["approval"] = ap
176
+ c["security"] = s
177
+ p["enabled"] = enabled if PUSHARY_PLUGIN in enabled else enabled + [PUSHARY_PLUGIN]
178
+ c["plugins"] = p
179
+ a["disabled_toolsets"] = disabled if QUESTION_TOOLSET in disabled else disabled + [QUESTION_TOOLSET]
180
+ c["agent"] = a
181
+ else:
182
+ receipt_exists = os.path.exists(receipt_path)
183
+ try:
184
+ with open(receipt_path, encoding="utf-8") as handle:
185
+ receipt = json.load(handle)
186
+ except (OSError, ValueError):
187
+ if receipt_exists:
188
+ raise
189
+ receipt = None
190
+ s = section(c, "security")
191
+ ap = section(s, "approval")
192
+ if receipt:
193
+ if not valid_receipt(receipt):
194
+ raise ValueError("invalid Pushary Hermes setup receipt")
195
+ approval_changed = (not receipt["transport"].get("present")
196
+ or receipt["transport"].get("value") != PUSHARY_TRANSPORT
197
+ or not receipt["fallback"].get("present")
198
+ or receipt["fallback"].get("value") != PUSHARY_FALLBACK)
199
+ plugins_changed = not (isinstance(receipt["enabled"].get("value"), list)
200
+ and receipt["pushary_enabled"])
201
+ agent_changed = not (isinstance(receipt["disabled"].get("value"), list)
202
+ and receipt["clarify_disabled"])
203
+ transport_left_over = recorded(receipt["transport"], PUSHARY_TRANSPORT)
204
+ if transport_left_over:
205
+ pop_if(ap, "transport", PUSHARY_TRANSPORT)
206
+ else:
207
+ restore(ap, "transport", receipt["transport"], PUSHARY_TRANSPORT)
208
+ if transport_left_over and recorded(receipt["fallback"], PUSHARY_FALLBACK):
209
+ pop_if(ap, "transport_fallback", PUSHARY_FALLBACK)
210
+ else:
211
+ restore(ap, "transport_fallback", receipt["fallback"], PUSHARY_FALLBACK)
212
+ else:
213
+ pop_if(ap, "transport", PUSHARY_TRANSPORT)
214
+ pop_if(ap, "transport_fallback", PUSHARY_FALLBACK)
215
+ if receipt:
216
+ restore_container(s, "approval", receipt["approval"], ap, approval_changed)
217
+ restore_container(c, "security", receipt["security"], s, approval_changed)
218
+ else:
219
+ if ap: s["approval"] = ap
220
+ else: s.pop("approval", None)
221
+ if s: c["security"] = s
222
+ else: c.pop("security", None)
223
+
224
+ p = section(c, "plugins")
225
+ if receipt:
226
+ restore_list_member(p, "enabled", receipt["enabled"], PUSHARY_PLUGIN, False)
227
+ restore_container(c, "plugins", receipt["plugins"], p, plugins_changed)
228
+ else:
229
+ enabled = [item for item in members(p, "enabled") if item != PUSHARY_PLUGIN]
230
+ if enabled: p["enabled"] = enabled
231
+ else: p.pop("enabled", None)
232
+ if p: c["plugins"] = p
233
+ else: c.pop("plugins", None)
234
+
235
+ a = section(c, "agent")
236
+ if receipt:
237
+ clarify_was_users = receipt["clarify_disabled"] and not recorded(receipt["transport"], PUSHARY_TRANSPORT)
238
+ restore_list_member(a, "disabled_toolsets", receipt["disabled"], QUESTION_TOOLSET, clarify_was_users)
239
+ restore_container(c, "agent", receipt["agent"], a, agent_changed)
240
+ else:
241
+ disabled = [item for item in members(a, "disabled_toolsets") if item != QUESTION_TOOLSET]
242
+ if disabled: a["disabled_toolsets"] = disabled
243
+ else: a.pop("disabled_toolsets", None)
244
+ if a: c["agent"] = a
245
+ else: c.pop("agent", None)
246
+
247
+ if receipt and restore_conflicts:
248
+ raise ValueError("Hermes config changed after Pushary setup")
249
+
250
+ changed = c != original
251
+ if changed and mode != "clean-preview":
252
+ save_config(c)
253
+ print(json.dumps({"changed": changed}))
254
+ `;
255
+ var resolveHermesPython = () => {
256
+ const launcher = resolvePathBinary("hermes");
257
+ if (launcher && process.platform !== "win32") {
258
+ try {
259
+ const shebang = readFileSync(launcher, "utf-8").split("\n", 1)[0];
260
+ const interpreter = shebang?.startsWith("#!") ? shebang.slice(2).trim().split(/\s+/)[0] : void 0;
261
+ if (interpreter && /python/i.test(interpreter) && existsSync(interpreter)) return interpreter;
262
+ } catch {
263
+ }
264
+ }
265
+ const root = join(homedir(), ".hermes", "hermes-agent", "venv");
266
+ const candidates = process.platform === "win32" ? [join(root, "Scripts", "python.exe"), join(root, "Scripts", "python3.exe")] : [join(root, "bin", "python3"), join(root, "bin", "python")];
267
+ return candidates.find(existsSync) ?? null;
268
+ };
269
+ var HERMES_SCRIPT_TIMEOUT_MS = 15e3;
270
+ var runPythonScript = (python, script, args) => {
271
+ const path = join(tmpdir(), `pushary-hermes-${process.pid}-${Date.now()}.py`);
272
+ try {
273
+ writeFileSync(path, script, { encoding: "utf-8", mode: 384 });
274
+ return execFileSync(python, [path, ...args], {
275
+ env: { ...process.env },
276
+ encoding: "utf-8",
277
+ stdio: "pipe",
278
+ timeout: HERMES_SCRIPT_TIMEOUT_MS
279
+ });
280
+ } catch {
281
+ return null;
282
+ } finally {
283
+ try {
284
+ rmSync(path, { force: true });
285
+ } catch {
286
+ }
287
+ }
288
+ };
289
+ var lastReport = (stdout) => {
290
+ const line = stdout.trim().split("\n").at(-1) ?? "";
291
+ try {
292
+ return JSON.parse(line);
293
+ } catch {
294
+ return void 0;
295
+ }
296
+ };
297
+ var configRunFrom = (stdout) => {
298
+ const report = stdout === null ? void 0 : lastReport(stdout);
299
+ if (!isRecord(report) || typeof report.changed !== "boolean") return "failed";
300
+ return report.changed ? "changed" : "unchanged";
301
+ };
302
+ var runHermesConfigScript = (python, mode, receiptPath) => configRunFrom(runPythonScript(python, HERMES_CONFIG_SCRIPT, [mode, receiptPath]));
303
+ var HERMES_STATUS_FIELDS = ["plugin_installed", "plugin_enabled", "approvals_routed", "questions_routed"];
304
+ var isHermesStatusReport = (value) => isRecord(value) && HERMES_STATUS_FIELDS.every((field) => typeof value[field] === "boolean");
305
+ var hermesWiredByPushary = (status, setupRecorded) => setupRecorded || status.pluginEnabled || status.approvalsRouted;
306
+ var readHermesStatus = (python) => {
307
+ const stdout = runPythonScript(python, HERMES_CONFIG_SCRIPT, ["status"]);
308
+ const report = stdout === null ? void 0 : lastReport(stdout);
309
+ if (!isHermesStatusReport(report)) return null;
310
+ return {
311
+ pluginInstalled: report.plugin_installed,
312
+ pluginEnabled: report.plugin_enabled,
313
+ approvalsRouted: report.approvals_routed,
314
+ questionsRouted: report.questions_routed
315
+ };
316
+ };
317
+
318
+ // src/vscode-config.ts
319
+ import { homedir as homedir2 } from "os";
320
+ import { join as join2 } from "path";
321
+ var PLUGIN_LOCATIONS_KEY = "chat.pluginLocations";
322
+ var blankJsonComments = (text) => {
323
+ let out = "";
324
+ let i = 0;
325
+ let inString = false;
326
+ let escaped = false;
327
+ while (i < text.length) {
328
+ const ch = text[i];
329
+ if (inString) {
330
+ out += ch;
331
+ if (escaped) escaped = false;
332
+ else if (ch === "\\") escaped = true;
333
+ else if (ch === '"') inString = false;
334
+ i += 1;
335
+ continue;
336
+ }
337
+ if (ch === '"') {
338
+ inString = true;
339
+ out += ch;
340
+ i += 1;
341
+ continue;
342
+ }
343
+ if (ch === "/" && text[i + 1] === "/") {
344
+ while (i < text.length && text[i] !== "\n") {
345
+ out += " ";
346
+ i += 1;
347
+ }
348
+ continue;
349
+ }
350
+ if (ch === "/" && text[i + 1] === "*") {
351
+ const end = text.indexOf("*/", i + 2);
352
+ const stop = end === -1 ? text.length : end + 2;
353
+ while (i < stop) {
354
+ out += text[i] === "\n" ? "\n" : " ";
355
+ i += 1;
356
+ }
357
+ continue;
358
+ }
359
+ out += ch;
360
+ i += 1;
361
+ }
362
+ return out;
363
+ };
364
+ var asRecord = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
365
+ var parseJsonc = (text) => {
366
+ const blanked = blankJsonComments(text);
367
+ const withoutTrailingCommas = blanked.replace(/,(\s*[}\]])/g, "$1");
368
+ try {
369
+ return asRecord(JSON.parse(withoutTrailingCommas));
370
+ } catch {
371
+ return void 0;
372
+ }
373
+ };
374
+ var rootBraceIndex = (text) => blankJsonComments(text).indexOf("{");
375
+ var detectIndent = (text) => {
376
+ const match = /\n([ \t]+)"/.exec(text);
377
+ return match?.[1] ?? " ";
378
+ };
379
+ var freshDocument = (pluginDir, indent = " ") => `${JSON.stringify({ [PLUGIN_LOCATIONS_KEY]: { [pluginDir]: true } }, null, indent)}
380
+ `;
381
+ var registerPluginLocation = (existing, pluginDir) => {
382
+ if (existing === null || existing.trim() === "") {
383
+ return { kind: "created", content: freshDocument(pluginDir) };
384
+ }
385
+ const indent = detectIndent(existing);
386
+ try {
387
+ const parsed2 = asRecord(JSON.parse(existing));
388
+ if (parsed2) {
389
+ const locations2 = asRecord(parsed2[PLUGIN_LOCATIONS_KEY]) ?? {};
390
+ if (locations2[pluginDir] === true) return { kind: "already" };
391
+ parsed2[PLUGIN_LOCATIONS_KEY] = { ...locations2, [pluginDir]: true };
392
+ return { kind: "merged", content: `${JSON.stringify(parsed2, null, indent)}
393
+ ` };
394
+ }
395
+ } catch {
396
+ }
397
+ const parsed = parseJsonc(existing);
398
+ if (!parsed) return { kind: "manual" };
399
+ const locations = asRecord(parsed[PLUGIN_LOCATIONS_KEY]);
400
+ if (locations?.[pluginDir] === true) return { kind: "already" };
401
+ if (parsed[PLUGIN_LOCATIONS_KEY] !== void 0) return { kind: "manual" };
402
+ const brace = rootBraceIndex(existing);
403
+ if (brace === -1) return { kind: "manual" };
404
+ const needsComma = Object.keys(parsed).length > 0;
405
+ const line = `
406
+ ${indent}${JSON.stringify(PLUGIN_LOCATIONS_KEY)}: { ${JSON.stringify(pluginDir)}: true }${needsComma ? "," : ""}`;
407
+ return {
408
+ kind: "inserted",
409
+ content: `${existing.slice(0, brace + 1)}${line}${existing.slice(brace + 1)}`
410
+ };
411
+ };
412
+ var unregisterPluginLocation = (existing, pluginDir) => {
413
+ if (existing === null || existing.trim() === "") return { kind: "absent" };
414
+ const indent = detectIndent(existing);
415
+ try {
416
+ const parsed2 = asRecord(JSON.parse(existing));
417
+ if (parsed2) {
418
+ const locations2 = asRecord(parsed2[PLUGIN_LOCATIONS_KEY]);
419
+ if (!locations2 || !(pluginDir in locations2)) return { kind: "absent" };
420
+ const remaining = { ...locations2 };
421
+ delete remaining[pluginDir];
422
+ if (Object.keys(remaining).length === 0) delete parsed2[PLUGIN_LOCATIONS_KEY];
423
+ else parsed2[PLUGIN_LOCATIONS_KEY] = remaining;
424
+ return { kind: "removed", content: `${JSON.stringify(parsed2, null, indent)}
425
+ ` };
426
+ }
427
+ } catch {
428
+ }
429
+ const parsed = parseJsonc(existing);
430
+ if (!parsed) return { kind: "manual" };
431
+ const locations = asRecord(parsed[PLUGIN_LOCATIONS_KEY]);
432
+ if (!locations || !(pluginDir in locations)) return { kind: "absent" };
433
+ const line = new RegExp(
434
+ `\\n[ \\t]*${escapeRegExp(JSON.stringify(PLUGIN_LOCATIONS_KEY))}\\s*:\\s*\\{\\s*${escapeRegExp(JSON.stringify(pluginDir))}\\s*:\\s*true\\s*\\},?`
435
+ );
436
+ if (!line.test(existing)) return { kind: "manual" };
437
+ return { kind: "removed", content: existing.replace(line, "") };
438
+ };
439
+ var escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
440
+ var isPluginRegistered = (existing, pluginDir) => {
441
+ if (!existing) return false;
442
+ const parsed = parseJsonc(existing);
443
+ return asRecord(parsed?.[PLUGIN_LOCATIONS_KEY])?.[pluginDir] === true;
444
+ };
445
+ var pluginLocationSnippet = (pluginDir) => `"${PLUGIN_LOCATIONS_KEY}": {
446
+ ${JSON.stringify(pluginDir)}: true
447
+ }`;
448
+ var VSCODE_PRODUCTS = ["Code", "Code - Insiders"];
449
+ var settingsRoot = (home, platform) => {
450
+ if (platform === "darwin") return join2(home, "Library", "Application Support");
451
+ if (platform === "win32") return process.env.APPDATA?.trim() || join2(home, "AppData", "Roaming");
452
+ return process.env.XDG_CONFIG_HOME?.trim() || join2(home, ".config");
453
+ };
454
+ var vscodeSettingsCandidates = (home = homedir2(), platform = process.platform) => {
455
+ const root = settingsRoot(home, platform);
456
+ return VSCODE_PRODUCTS.map((product) => join2(root, product, "User", "settings.json"));
457
+ };
458
+ var vscodeSettingsTargets = (exists, home, platform) => {
459
+ const candidates = vscodeSettingsCandidates(home, platform);
460
+ const present = candidates.filter((path) => exists(path));
461
+ return present.length > 0 ? present : candidates.slice(0, 1);
462
+ };
463
+
464
+ // src/setup/detect.ts
465
+ import { execSync } from "child_process";
466
+ import { existsSync as existsSync2 } from "fs";
467
+ import { homedir as homedir3 } from "os";
468
+ import { dirname, join as join3 } from "path";
469
+ var whichCommand = () => process.platform === "win32" ? "where" : "which";
470
+ var binaryOnPath = (binary) => {
471
+ try {
472
+ execSync(`${whichCommand()} ${binary}`, { stdio: "ignore", timeout: 5e3 });
473
+ return true;
474
+ } catch {
475
+ return false;
476
+ }
477
+ };
478
+ var defaultDeps = { onPath: binaryOnPath, exists: existsSync2 };
479
+ var detectAgent = (probe, deps = defaultDeps) => {
480
+ const checked = [];
481
+ if (probe.binary) {
482
+ checked.push(`${whichCommand()} ${probe.binary}`);
483
+ if (deps.onPath(probe.binary)) {
484
+ return { kind: "installed", evidence: `${probe.binary} on PATH`, strong: true };
485
+ }
486
+ }
487
+ for (const path of probe.paths) {
488
+ checked.push(path);
489
+ if (deps.exists(path)) return { kind: "installed", evidence: path, strong: true };
490
+ }
491
+ for (const marker of probe.configMarkers) {
492
+ checked.push(marker);
493
+ if (deps.exists(marker)) return { kind: "installed", evidence: marker, strong: false };
494
+ }
495
+ if (probe.binary === null && probe.paths.length === 0 && probe.configMarkers.length === 0) {
496
+ return { kind: "unknown" };
497
+ }
498
+ return { kind: "not-found", checked };
499
+ };
500
+ var agentProbes = (home = homedir3()) => ({
501
+ claude_code: {
502
+ binary: "claude",
503
+ // The native installer puts it here, outside a default non-login PATH.
504
+ paths: [join3(home, ".local", "bin", "claude")],
505
+ configMarkers: [join3(home, ".claude")]
506
+ },
507
+ codex: {
508
+ binary: "codex",
509
+ paths: [],
510
+ configMarkers: [codexHomeFrom(home)]
511
+ },
512
+ gemini_cli: {
513
+ binary: "gemini",
514
+ paths: [],
515
+ configMarkers: [join3(home, ".gemini")]
516
+ },
517
+ hermes: {
518
+ binary: "hermes",
519
+ paths: [],
520
+ configMarkers: [join3(home, ".hermes")]
521
+ },
522
+ cursor: {
523
+ // GUI editor. `cursor` on PATH only exists if the user ran "Install 'cursor'
524
+ // command in PATH" from the command palette, which most never do.
525
+ binary: "cursor",
526
+ paths: process.platform === "darwin" ? ["/Applications/Cursor.app"] : process.platform === "win32" ? [join3(process.env.LOCALAPPDATA ?? join3(home, "AppData", "Local"), "Programs", "cursor")] : ["/usr/share/cursor", join3(home, ".local", "share", "cursor")],
527
+ configMarkers: [join3(home, ".cursor")]
528
+ },
529
+ vscode: {
530
+ // Like Cursor, a GUI editor: `code` on PATH only exists if the user ran
531
+ // "Shell Command: Install 'code' command in PATH", which on macOS is opt-in.
532
+ binary: "code",
533
+ paths: process.platform === "darwin" ? ["/Applications/Visual Studio Code.app"] : process.platform === "win32" ? [join3(process.env.LOCALAPPDATA ?? join3(home, "AppData", "Local"), "Programs", "Microsoft VS Code")] : ["/usr/share/code", join3(home, ".local", "share", "code")],
534
+ // The settings directory rather than ~/.vscode, because the settings
535
+ // directory is what this installer actually writes to. Insiders counts:
536
+ // someone running only Insiders still has VS Code.
537
+ configMarkers: vscodeSettingsCandidates(home).map((path) => dirname(path))
538
+ },
539
+ opencode: {
540
+ binary: "opencode",
541
+ paths: [],
542
+ // Resolved rather than spelled: OpenCode honours OPENCODE_CONFIG_DIR and then
543
+ // XDG_CONFIG_HOME, and `~/.opencode` — the obvious guess — is a path it has
544
+ // never used.
545
+ configMarkers: [openCodeConfigDirFrom(home)]
546
+ },
547
+ fx: {
548
+ binary: null,
549
+ paths: [join3(home, ".fx", "settings.json"), join3(home, ".fx", "sessions"), join3(home, ".fx", "history.jsonl")],
550
+ configMarkers: []
551
+ },
552
+ ...compatibleProbes(),
553
+ // "Other" is a set of printed instructions for any MCP or HTTP client. There is
554
+ // nothing to detect, and it must never be auto-selected.
555
+ custom: { binary: null, paths: [], configMarkers: [] }
556
+ });
557
+ var compatibleProbes = () => HOOK_COMPATIBLE_PROFILES.reduce((probes, profile) => ({
558
+ ...probes,
559
+ [profile.agentType]: {
560
+ binary: profile.binary,
561
+ paths: [],
562
+ configMarkers: []
563
+ }
564
+ }), {});
565
+ var detectAllAgents = (deps = defaultDeps, home) => {
566
+ const probes = agentProbes(home);
567
+ return Object.keys(probes).map((agent) => ({
568
+ agent,
569
+ result: detectAgent(probes[agent], deps)
570
+ }));
571
+ };
572
+ var isDetected = (result) => result.kind === "installed";
573
+ var shortenHome = (path, home = homedir3()) => home && path.startsWith(home) ? `~${path.slice(home.length)}` : path;
574
+ var describeDetection = (result, home) => {
575
+ if (result.kind !== "installed") return null;
576
+ const evidence = shortenHome(result.evidence, home);
577
+ return result.strong ? evidence : `${evidence}, config only`;
578
+ };
579
+
580
+ export {
581
+ isHermesConfigReceipt,
582
+ HERMES_PIP_PACKAGE,
583
+ HERMES_PLUGIN_NAME,
584
+ resolveHermesPython,
585
+ runHermesConfigScript,
586
+ hermesWiredByPushary,
587
+ readHermesStatus,
588
+ registerPluginLocation,
589
+ unregisterPluginLocation,
590
+ isPluginRegistered,
591
+ pluginLocationSnippet,
592
+ vscodeSettingsTargets,
593
+ detectAgent,
594
+ agentProbes,
595
+ detectAllAgents,
596
+ isDetected,
597
+ shortenHome,
598
+ describeDetection
599
+ };