@pushary/agent-hooks 1.9.169 → 1.9.171

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 (138) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +15 -0
  3. package/dist/{api-2NP643KP.js → api-WOLCBFMV.js} +11 -11
  4. package/dist/bin/pushary-audit.js +3 -3
  5. package/dist/bin/pushary-bell-hook.js +28 -28
  6. package/dist/bin/pushary-bell.js +12 -12
  7. package/dist/bin/pushary-calls.js +16 -16
  8. package/dist/bin/pushary-claude.js +29 -29
  9. package/dist/bin/pushary-clean.js +44 -42
  10. package/dist/bin/pushary-codex-bridge.js +24 -24
  11. package/dist/bin/pushary-codex-hook.js +33 -33
  12. package/dist/bin/pushary-codex-session.js +8 -8
  13. package/dist/bin/pushary-codex.js +13 -13
  14. package/dist/bin/pushary-connect.js +31 -31
  15. package/dist/bin/pushary-cowork.js +6 -6
  16. package/dist/bin/pushary-daemon.js +47 -47
  17. package/dist/bin/pushary-disconnect.js +26 -26
  18. package/dist/bin/pushary-display-hook.js +32 -26
  19. package/dist/bin/pushary-doctor.js +51 -50
  20. package/dist/bin/pushary-elicitation-hook.js +28 -28
  21. package/dist/bin/pushary-gemini-bridge.js +18 -18
  22. package/dist/bin/pushary-gemini-hook.js +31 -31
  23. package/dist/bin/pushary-hook.js +34 -34
  24. package/dist/bin/pushary-login.js +31 -25
  25. package/dist/bin/pushary-logout.js +36 -28
  26. package/dist/bin/pushary-mcp.js +12 -12
  27. package/dist/bin/pushary-mode.js +16 -16
  28. package/dist/bin/pushary-notification-hook.js +27 -27
  29. package/dist/bin/pushary-opencode-hook.js +31 -31
  30. package/dist/bin/pushary-permission-denied-hook.js +33 -33
  31. package/dist/bin/pushary-permission-hook.js +33 -33
  32. package/dist/bin/pushary-post-hook.js +28 -28
  33. package/dist/bin/pushary-prompt-hook.js +27 -27
  34. package/dist/bin/pushary-session-end-hook.js +29 -29
  35. package/dist/bin/pushary-session-start-hook.js +38 -38
  36. package/dist/bin/pushary-sessions.d.ts +1 -0
  37. package/dist/bin/pushary-sessions.js +81 -0
  38. package/dist/bin/pushary-setup.js +69 -60
  39. package/dist/bin/pushary-stats.js +3 -3
  40. package/dist/bin/pushary-status.js +33 -33
  41. package/dist/bin/pushary-stop-hook.js +27 -27
  42. package/dist/bin/pushary-stopfailure-hook.js +27 -27
  43. package/dist/bin/pushary-suggestions.js +16 -16
  44. package/dist/bin/pushary-transcript-register.js +20 -20
  45. package/dist/bin/pushary-transcripts.js +28 -28
  46. package/dist/bin/pushary-upgrade.js +42 -42
  47. package/dist/bin/pushary-wait.js +16 -16
  48. package/dist/bin/pushary.js +9 -8
  49. package/dist/{chunk-QMVUDNQR.js → chunk-2RN7D6VI.js} +4 -4
  50. package/dist/{chunk-OI5OOFUY.js → chunk-2XEZJK7G.js} +5 -5
  51. package/dist/{chunk-6B2YKVX3.js → chunk-3GIVPZIS.js} +2 -2
  52. package/dist/{chunk-K24RAOIO.js → chunk-3I3RUJRD.js} +1 -1
  53. package/dist/{chunk-XWLSZNXW.js → chunk-3PQWVDW5.js} +8 -8
  54. package/dist/{chunk-352FIVVH.js → chunk-55L4JSPA.js} +1 -1
  55. package/dist/{chunk-OBUKF3WP.js → chunk-5EU7V5CT.js} +3 -3
  56. package/dist/{chunk-5N7MRVM3.js → chunk-5GUZJIEL.js} +4 -4
  57. package/dist/{chunk-TGIWLQOV.js → chunk-5HT352IV.js} +4 -4
  58. package/dist/{chunk-752NWYBD.js → chunk-7L3MVK44.js} +5 -5
  59. package/dist/{chunk-LGQUJFVZ.js → chunk-7ODDR6FA.js} +2 -2
  60. package/dist/{chunk-DYZ26IPH.js → chunk-7XSZK4DH.js} +223 -74
  61. package/dist/{chunk-LVF5IBS6.js → chunk-A2DVMIX4.js} +1 -1
  62. package/dist/{chunk-TGYM6UQJ.js → chunk-A3JTWB74.js} +2 -2
  63. package/dist/{chunk-7GMTA5NR.js → chunk-AUF4BMGA.js} +9 -9
  64. package/dist/{chunk-6IZVL42W.js → chunk-AVN4A4A6.js} +1 -1
  65. package/dist/{chunk-KEC67NZF.js → chunk-BKVQKWLY.js} +4 -4
  66. package/dist/{chunk-YPY4YCIZ.js → chunk-BZIBNSQE.js} +1 -1
  67. package/dist/{chunk-YU2EUD7O.js → chunk-CINBAX5G.js} +2 -0
  68. package/dist/{chunk-CCQZGWSR.js → chunk-CJODSIXH.js} +4 -4
  69. package/dist/{chunk-AIUFZQAA.js → chunk-CLT4J5N5.js} +2 -2
  70. package/dist/{chunk-66VZIS6R.js → chunk-CUWHBFBB.js} +1 -1
  71. package/dist/{chunk-NOHOCNY6.js → chunk-D3TNLVVL.js} +3 -3
  72. package/dist/{chunk-AO4CKFQA.js → chunk-D6OCHPLT.js} +1 -1
  73. package/dist/{chunk-NRXFFCNG.js → chunk-DCYRV2BJ.js} +3 -3
  74. package/dist/{chunk-X7RPRBZE.js → chunk-DRRFOQGF.js} +2 -2
  75. package/dist/{chunk-LEDGOYZV.js → chunk-E7ATFUXV.js} +3 -3
  76. package/dist/{chunk-6PDBRLIH.js → chunk-EGDFXMFK.js} +3 -3
  77. package/dist/{chunk-ZKMXHG5G.js → chunk-EQQOEDQZ.js} +6 -6
  78. package/dist/{chunk-OJUW7QW2.js → chunk-FAMKGTCF.js} +1 -1
  79. package/dist/{chunk-UN36O6U6.js → chunk-FCNYCY6G.js} +2 -2
  80. package/dist/{chunk-TTTMOX73.js → chunk-FFJX6YOQ.js} +1 -1
  81. package/dist/{chunk-PG5N3FL5.js → chunk-FIJPDZIR.js} +8 -8
  82. package/dist/{chunk-HFI6SU27.js → chunk-FJF2D32S.js} +3 -3
  83. package/dist/{chunk-ZYH4KTY5.js → chunk-FP4W2EI6.js} +11 -11
  84. package/dist/{chunk-AVIQZSCU.js → chunk-G7U5TFPY.js} +1 -1
  85. package/dist/{chunk-LOUSA3NO.js → chunk-GTB4MBMU.js} +6 -6
  86. package/dist/{chunk-4HLSCBES.js → chunk-GZZ7XGL5.js} +12 -2
  87. package/dist/{chunk-LZU7ZDY7.js → chunk-HBJLJHZF.js} +2 -2
  88. package/dist/{chunk-7DEAVAAS.js → chunk-HRUKMGRH.js} +3 -3
  89. package/dist/{chunk-IWWKO4MP.js → chunk-I72TVBOG.js} +3 -3
  90. package/dist/{chunk-ORTEANZH.js → chunk-IHNII3GT.js} +4 -4
  91. package/dist/{chunk-WDLBF3PM.js → chunk-IV7WDCKS.js} +6 -0
  92. package/dist/{chunk-GV3ZGKMK.js → chunk-IYTTLDB5.js} +3 -3
  93. package/dist/{chunk-KX4Q4CKZ.js → chunk-J2CRP5GN.js} +3 -3
  94. package/dist/{chunk-MRTJ54MC.js → chunk-JE6NVEOE.js} +1 -1
  95. package/dist/{chunk-FUK2DC53.js → chunk-JNVUOEKM.js} +3 -3
  96. package/dist/{chunk-LDUK7D2I.js → chunk-JUE347Z7.js} +7 -7
  97. package/dist/{chunk-SD5K34T2.js → chunk-KMKU2INV.js} +1 -1
  98. package/dist/{chunk-VY22KT5X.js → chunk-KNFZORNH.js} +4 -3
  99. package/dist/{chunk-X7RR2ZQH.js → chunk-KQXKDF4N.js} +5 -5
  100. package/dist/{chunk-EDCDODWA.js → chunk-LABBFTYJ.js} +4 -4
  101. package/dist/{chunk-WK6TE6U7.js → chunk-LEAACRFN.js} +2 -2
  102. package/dist/{chunk-MOQUKAVU.js → chunk-MJMRJ5ZF.js} +2 -2
  103. package/dist/{chunk-CRTNHB6F.js → chunk-MV7NJYJX.js} +3 -3
  104. package/dist/{chunk-UCW24KPU.js → chunk-NJNK3ZUC.js} +2 -2
  105. package/dist/{chunk-XGNOM3XC.js → chunk-NWHMER6L.js} +1 -1
  106. package/dist/{chunk-TODDEIYG.js → chunk-PM2NRK6Y.js} +12 -2
  107. package/dist/{chunk-VWVYDYCV.js → chunk-PQEX64YL.js} +4 -4
  108. package/dist/{chunk-QCQADUHN.js → chunk-RPMVO2RJ.js} +3 -3
  109. package/dist/{chunk-F7N6LYGG.js → chunk-SJDYK47V.js} +6 -6
  110. package/dist/{chunk-ZXRBGLTI.js → chunk-SM65Z6CM.js} +5 -5
  111. package/dist/{chunk-FAORXDJ4.js → chunk-SQCW64C2.js} +5 -5
  112. package/dist/{chunk-CYTPQDQY.js → chunk-TCE3J44Z.js} +1 -1
  113. package/dist/{chunk-RY5EPLCY.js → chunk-U2XCKXBH.js} +5 -5
  114. package/dist/{chunk-3M4ZOSR3.js → chunk-UB5G7ZZN.js} +1 -1
  115. package/dist/{chunk-ZXZEETHT.js → chunk-UHKYKZQ5.js} +14 -14
  116. package/dist/{chunk-XR27HPYC.js → chunk-UOPOVQ2P.js} +2 -1
  117. package/dist/{chunk-MK7T7MNB.js → chunk-V762IZHX.js} +1 -1
  118. package/dist/{chunk-Y6ILCLKE.js → chunk-VRNGMRJA.js} +1 -1
  119. package/dist/{chunk-WTUURSCO.js → chunk-W46HI6T3.js} +3 -3
  120. package/dist/{chunk-BIEJHRZG.js → chunk-WKRKTQLA.js} +2 -2
  121. package/dist/{chunk-OU7PO32D.js → chunk-XHUR62AQ.js} +2 -2
  122. package/dist/{chunk-WIOC6L6Y.js → chunk-Y54VMOE5.js} +2 -2
  123. package/dist/{chunk-HV7KTGWF.js → chunk-YG3KWXGC.js} +5 -5
  124. package/dist/{chunk-LL4TMEDG.js → chunk-ZHO263F6.js} +4 -4
  125. package/dist/{chunk-5Q2UDUR6.js → chunk-ZLMWP6X4.js} +3 -3
  126. package/dist/{codex-app-cards-switch-C6OKN3RA.js → codex-app-cards-switch-TRZKDOVK.js} +12 -12
  127. package/dist/{codex-desktop-launch-5ISZYYGG.js → codex-desktop-launch-AI5J526F.js} +1 -1
  128. package/dist/{codex-session-launch-JWT76ONU.js → codex-session-launch-UWD7U2LW.js} +21 -21
  129. package/dist/{config-PWEPWMNF.js → config-QIHLQCEV.js} +2 -2
  130. package/dist/{global-upgrade-ZAPGSH66.js → global-upgrade-4K5SGI7Q.js} +10 -10
  131. package/dist/{identity-O57FDCPL.js → identity-MRXHTKAC.js} +4 -4
  132. package/dist/{live-capabilities-FVRWXQAC.js → live-capabilities-PO5JOGZJ.js} +5 -5
  133. package/dist/{paths-LCARWI3S.js → paths-AXIBD5XG.js} +3 -3
  134. package/dist/{reapply-T5JXYBH2.js → reapply-7FJNSGUM.js} +30 -30
  135. package/dist/src/index.js +33 -33
  136. package/dist/{upgrade-lock-3P3VK6KQ.js → upgrade-lock-G3RQPHYM.js} +4 -4
  137. package/dist/{usage-BKT5P2P3.js → usage-GDUDYZSV.js} +2 -2
  138. package/package.json +2 -1
@@ -1,15 +1,16 @@
1
1
  import {
2
2
  resolveInstallSourceFor
3
- } from "./chunk-K24RAOIO.js";
3
+ } from "./chunk-3I3RUJRD.js";
4
4
  import {
5
5
  configFilePath
6
- } from "./chunk-LVF5IBS6.js";
6
+ } from "./chunk-A2DVMIX4.js";
7
7
  import {
8
8
  backupFile,
9
+ backupFileInto,
9
10
  readJsonSafe,
10
11
  writeFileAtomic,
11
12
  writeJsonAtomic
12
- } from "./chunk-TODDEIYG.js";
13
+ } from "./chunk-PM2NRK6Y.js";
13
14
  import {
14
15
  API_KEY_PREFIX_PATTERN,
15
16
  isRecord,
@@ -98,9 +99,9 @@ var removeClaudeAlias = () => {
98
99
  };
99
100
 
100
101
  // src/keystore.ts
101
- import { chmodSync, existsSync as existsSync2, readFileSync as readFileSync2, realpathSync, writeFileSync as writeFileSync2 } from "fs";
102
+ import { chmodSync, constants as fsConstants, copyFileSync, existsSync as existsSync2, lstatSync, mkdirSync, readdirSync, readFileSync as readFileSync2, realpathSync, rmSync, statSync, writeFileSync as writeFileSync2 } from "fs";
102
103
  import { homedir as homedir2 } from "os";
103
- import { join as join2 } from "path";
104
+ import { basename, dirname, isAbsolute, join as join2, relative } from "path";
104
105
  var KEY_FILE_MODE = 384;
105
106
  var FALLBACK_RCS = [".zshrc", ".zprofile", ".bashrc", ".bash_profile"];
106
107
  var OUR_EXPORT = /^[ \t]*export[ \t]+PUSHARY_API_KEY=(['"]?)(pk_[a-f0-9]+\.[a-f0-9]+)\1[ \t]*$/;
@@ -108,12 +109,155 @@ var MENTIONS_KEY = /PUSHARY_API_KEY/;
108
109
  var isComment = (line) => line.trimStart().startsWith("#");
109
110
  var exportLine = (apiKey) => `export PUSHARY_API_KEY='${apiKey}'`;
110
111
  var LOGOUT_MARK = "# removed by pushary logout";
111
- var disabledExportLine = (line) => `# ${line.trim()} ${LOGOUT_MARK}`;
112
112
  var isDisabledExport = (line) => {
113
113
  const trimmed = line.trim();
114
114
  if (!isComment(trimmed) || !trimmed.endsWith(LOGOUT_MARK)) return false;
115
115
  return OUR_EXPORT.test(trimmed.slice(1, -LOGOUT_MARK.length).trim());
116
116
  };
117
+ var KEY_ENV_FILE_NAME = "env";
118
+ var RC_BACKUP_DIRECTORY_NAME = "backups";
119
+ var PATH_SAFE_IN_DOUBLE_QUOTES = /^[A-Za-z0-9._\/-]+$/;
120
+ var OUR_KEY_LOADER = /^[ \t]*if \[ -f ("\$HOME\/[A-Za-z0-9._\/-]+"|'(?:[^']|'\\'')+') \]; then \. \1; fi[ \t]*$/;
121
+ var OLD_RC_BACKUP_MARK = ".pushary-backup-";
122
+ var INDENTATION = /^[ \t]*/;
123
+ var BLOCK_OPENER = /(?:^|[\s;])(?:then|else|do|\{|\()$/;
124
+ var TRAILING_SHELL_COMMENT = /[ \t]+#.*$/;
125
+ var SHELL_NO_OP = ":";
126
+ var MAX_BACKUP_NAME_ATTEMPTS = 100;
127
+ var keyEnvFilePath = () => join2(dirname(configFilePath()), KEY_ENV_FILE_NAME);
128
+ var rcBackupDirectory = () => join2(dirname(configFilePath()), RC_BACKUP_DIRECTORY_NAME);
129
+ var singleQuoted = (value) => `'${value.replaceAll("'", `'\\''`)}'`;
130
+ var homeRelativePathOf = (path, home) => {
131
+ const inHome = relative(home, path);
132
+ return inHome !== "" && !inHome.startsWith("..") && !isAbsolute(inHome) && PATH_SAFE_IN_DOUBLE_QUOTES.test(inHome) ? inHome : null;
133
+ };
134
+ var shellPathOf = (path, home) => {
135
+ const inHome = homeRelativePathOf(path, home);
136
+ return inHome === null ? singleQuoted(path) : `"$HOME/${inHome}"`;
137
+ };
138
+ var keyLoaderLine = (envFile = keyEnvFilePath(), home = homedir2()) => {
139
+ const path = shellPathOf(envFile, home);
140
+ return `if [ -f ${path} ]; then . ${path}; fi`;
141
+ };
142
+ var isKeyLoaderLine = (line) => OUR_KEY_LOADER.test(line);
143
+ var isActiveKeyExport = (line) => OUR_EXPORT.test(line);
144
+ var isPusharyKeyLine = (line) => isActiveKeyExport(line) || isDisabledExport(line);
145
+ var indentationOf = (line) => INDENTATION.exec(line)?.[0] ?? "";
146
+ var exportedKeyIn = (line) => {
147
+ const key = OUR_EXPORT.exec(line)?.[2];
148
+ return key === void 0 ? [] : [key];
149
+ };
150
+ var replaceKeyLinesWithLoader = (lines, loader, isReplacedLine = isPusharyKeyLine) => {
151
+ const next = lines.map((line) => isReplacedLine(line) ? `${indentationOf(line)}${loader}` : line);
152
+ return {
153
+ lines: next,
154
+ exportedKeys: lines.flatMap(exportedKeyIn),
155
+ replacedLineCount: lines.filter(isReplacedLine).length,
156
+ loaderPresent: next.some((line) => line.trim() === loader)
157
+ };
158
+ };
159
+ var opensABlock = (line) => line !== void 0 && [line, line.replace(TRAILING_SHELL_COMMENT, "")].some((candidate) => BLOCK_OPENER.test(candidate.trimEnd()));
160
+ var isMeaningfulShellLine = (line) => line.trim() !== "" && !isComment(line);
161
+ var isShellNoOp = (line) => line?.trim() === SHELL_NO_OP;
162
+ var needsABodyInPlaceOf = (removed, lastMeaningful) => !isShellNoOp(lastMeaningful) && (indentationOf(removed) !== "" || opensABlock(lastMeaningful));
163
+ var withoutKeyLines = (lines, isKeyLine) => {
164
+ const kept = [];
165
+ let lastMeaningful;
166
+ for (const line of lines) {
167
+ if (!isKeyLine(line)) {
168
+ kept.push(line);
169
+ if (isMeaningfulShellLine(line)) lastMeaningful = line;
170
+ } else if (needsABodyInPlaceOf(line, lastMeaningful)) {
171
+ lastMeaningful = `${indentationOf(line)}${SHELL_NO_OP}`;
172
+ kept.push(lastMeaningful);
173
+ }
174
+ }
175
+ return kept;
176
+ };
177
+ var keyLinesWereReplaced = (before, edit) => before.length !== edit.lines.length || before.some((line, index) => line !== edit.lines[index]);
178
+ var errorMessageOf = (err) => err instanceof Error ? err.message : String(err);
179
+ var existingModeOf = (path) => {
180
+ try {
181
+ return statSync(path).mode & 511;
182
+ } catch {
183
+ return void 0;
184
+ }
185
+ };
186
+ var writeKeyEnvFile = (apiKey, path = keyEnvFilePath()) => {
187
+ try {
188
+ writeFileAtomic(path, `${exportLine(apiKey)}
189
+ `, KEY_FILE_MODE);
190
+ return { kind: "written", path };
191
+ } catch (err) {
192
+ return { kind: "unavailable", path, detail: errorMessageOf(err) };
193
+ }
194
+ };
195
+ var removeKeyEnvFile = (path) => {
196
+ if (!existsSync2(path)) return { kind: "absent" };
197
+ try {
198
+ rmSync(path, { force: true });
199
+ return { kind: "removed" };
200
+ } catch (err) {
201
+ return { kind: "failed", detail: errorMessageOf(err) };
202
+ }
203
+ };
204
+ var isRegularFile = (path) => {
205
+ try {
206
+ return lstatSync(path).isFile();
207
+ } catch {
208
+ return false;
209
+ }
210
+ };
211
+ var holdsAPusharyKey = (file) => {
212
+ try {
213
+ return readFileSync2(file, "utf8").split(/\r?\n/).some(isPusharyKeyLine);
214
+ } catch {
215
+ return false;
216
+ }
217
+ };
218
+ var oldRcBackupsBeside = (file) => {
219
+ const prefix = `${basename(file)}${OLD_RC_BACKUP_MARK}`;
220
+ try {
221
+ return readdirSync(dirname(file)).filter((name) => name.startsWith(prefix)).map((name) => join2(dirname(file), name)).filter((path) => isRegularFile(path) && holdsAPusharyKey(path));
222
+ } catch {
223
+ return [];
224
+ }
225
+ };
226
+ var backupNameCandidates = (name) => Array.from({ length: MAX_BACKUP_NAME_ATTEMPTS }, (_, attempt) => attempt === 0 ? name : `${name}.${attempt}`);
227
+ var copiedWithoutOverwriting = (file, directory) => {
228
+ for (const candidate of backupNameCandidates(basename(file))) {
229
+ const destination = join2(directory, candidate);
230
+ try {
231
+ copyFileSync(file, destination, fsConstants.COPYFILE_EXCL);
232
+ return destination;
233
+ } catch (err) {
234
+ if (!(err instanceof Error && "code" in err && err.code === "EEXIST")) return null;
235
+ }
236
+ }
237
+ return null;
238
+ };
239
+ var movedIntoDirectory = (file, directory) => {
240
+ try {
241
+ mkdirSync(directory, { recursive: true, mode: 448 });
242
+ } catch {
243
+ return false;
244
+ }
245
+ const destination = copiedWithoutOverwriting(file, directory);
246
+ if (destination === null) return false;
247
+ try {
248
+ chmodSync(destination, KEY_FILE_MODE);
249
+ rmSync(file);
250
+ return true;
251
+ } catch {
252
+ rmSync(destination, { force: true });
253
+ return false;
254
+ }
255
+ };
256
+ var moveOldRcBackups = (rcPaths, directory) => {
257
+ const backups = [...new Map(rcPaths.flatMap(oldRcBackupsBeside).map((backup) => [realPathOf(backup), backup])).values()];
258
+ const leftInPlace = backups.filter((backup) => !movedIntoDirectory(backup, directory) && existsSync2(backup));
259
+ return { directory, moved: backups.length - leftInPlace.length, leftInPlace };
260
+ };
117
261
  var keyPrefix = (key) => key.split(".")[0] ?? key;
118
262
  var MAC_APP_KEY_PREFIX_FIELD = "macAppKeyPrefix";
119
263
  var CLI_CREATED_KEY_PREFIX_FIELD = "cliCreatedKeyPrefix";
@@ -178,6 +322,7 @@ var rcResult = (kind, over = {}) => ({
178
322
  declinedLine: null,
179
323
  backupPath: null,
180
324
  detail: null,
325
+ oldBackups: { directory: rcBackupDirectory(), moved: 0, leftInPlace: [] },
181
326
  ...over
182
327
  });
183
328
  var realPathOf = (filePath) => {
@@ -187,61 +332,52 @@ var realPathOf = (filePath) => {
187
332
  return filePath;
188
333
  }
189
334
  };
190
- var rewriteRcExport = (rcPath, apiKey, shell = null) => {
191
- const target = realPathOf(rcPath);
192
- let content = "";
335
+ var isMissingFileError = (err) => err instanceof Error && "code" in err && err.code === "ENOENT";
336
+ var readRcContents = (path) => {
193
337
  try {
194
- content = readFileSync2(target, "utf-8");
338
+ return { kind: "read", content: readFileSync2(path, "utf-8") };
195
339
  } catch (err) {
196
- const error = err;
197
- if (error.code !== "ENOENT") {
198
- return rcResult("unavailable", { path: target, shell, detail: error.message });
199
- }
340
+ return isMissingFileError(err) ? { kind: "read", content: "" } : { kind: "unavailable", detail: errorMessageOf(err) };
200
341
  }
201
- const lines = content.split("\n");
202
- const foreign = lines.findIndex((line) => !isComment(line) && MENTIONS_KEY.test(line) && !OUR_EXPORT.test(line));
342
+ };
343
+ var foreignKeyLineIndex = (lines) => lines.findIndex((line) => !isComment(line) && MENTIONS_KEY.test(line) && !OUR_EXPORT.test(line));
344
+ var keyPrefixInLine = (line) => /pk_[a-f0-9]+/.exec(line ?? "")?.[0] ?? null;
345
+ var withLineAppended = (content, line) => {
346
+ const gap = content.length === 0 || content.endsWith("\n") ? "" : "\n";
347
+ return `${content}${gap}${line}
348
+ `;
349
+ };
350
+ var lastKeyPrefixOf = (keys) => {
351
+ const last = keys.at(-1);
352
+ return last === void 0 ? null : keyPrefix(last);
353
+ };
354
+ var keyLoaderWriteOf = (target, loader, shell, backupDirectory) => {
355
+ const contents = readRcContents(target);
356
+ if (contents.kind === "unavailable") return rcResult("unavailable", { path: target, shell, detail: contents.detail });
357
+ const lines = contents.content.split("\n");
358
+ const foreign = foreignKeyLineIndex(lines);
203
359
  if (foreign >= 0) {
204
- const match = /pk_[a-f0-9]+/.exec(lines[foreign] ?? "");
205
- return rcResult("declined", {
206
- path: target,
207
- shell,
208
- declinedLine: foreign + 1,
209
- previousKeyPrefix: match?.[0] ?? null
210
- });
360
+ return rcResult("declined", { path: target, shell, declinedLine: foreign + 1, previousKeyPrefix: keyPrefixInLine(lines[foreign]) });
211
361
  }
212
- const ours = lines.map((line, index) => ({ line, index })).filter((entry) => OUR_EXPORT.test(entry.line));
213
- if (ours.length > 0) {
214
- const previous = OUR_EXPORT.exec(ours[ours.length - 1].line)?.[2] ?? null;
215
- if (ours.every((entry) => OUR_EXPORT.exec(entry.line)?.[2] === apiKey)) {
216
- return rcResult("unchanged", {
217
- path: target,
218
- shell,
219
- previousKeyPrefix: previous ? keyPrefix(previous) : null
220
- });
221
- }
222
- const next = [...lines];
223
- for (const entry of ours) next[entry.index] = exportLine(apiKey);
224
- try {
225
- const backupPath = backupFile(target);
226
- writeFileAtomic(target, next.join("\n"), KEY_FILE_MODE);
227
- return rcResult("updated", {
228
- path: target,
229
- shell,
230
- previousKeyPrefix: previous ? keyPrefix(previous) : null,
231
- backupPath
232
- });
233
- } catch (err) {
234
- return rcResult("unavailable", { path: target, shell, detail: err.message });
235
- }
236
- }
237
- const gap = content.length === 0 ? "" : content.endsWith("\n") ? "" : "\n";
362
+ const edit = replaceKeyLinesWithLoader(lines, loader);
363
+ const mode = existingModeOf(target);
238
364
  try {
239
- writeFileAtomic(target, `${content}${gap}${exportLine(apiKey)}
240
- `, KEY_FILE_MODE);
365
+ if (keyLinesWereReplaced(lines, edit)) {
366
+ const backupPath = backupFileInto(target, backupDirectory);
367
+ writeFileAtomic(target, edit.lines.join("\n"), mode);
368
+ return rcResult("updated", { path: target, shell, previousKeyPrefix: lastKeyPrefixOf(edit.exportedKeys), backupPath });
369
+ }
370
+ if (edit.loaderPresent) return rcResult("unchanged", { path: target, shell });
371
+ writeFileAtomic(target, withLineAppended(contents.content, loader), mode);
372
+ return rcResult("written", { path: target, shell });
241
373
  } catch (err) {
242
- return rcResult("unavailable", { path: target, shell, detail: err.message });
374
+ return rcResult("unavailable", { path: target, shell, detail: errorMessageOf(err) });
243
375
  }
244
- return rcResult("written", { path: target, shell });
376
+ };
377
+ var writeKeyLoader = (rcPath, loader, shell = null, backupDirectory = rcBackupDirectory()) => {
378
+ const target = realPathOf(rcPath);
379
+ const result = keyLoaderWriteOf(target, loader, shell, backupDirectory);
380
+ return { ...result, oldBackups: moveOldRcBackups([target, rcPath], backupDirectory) };
245
381
  };
246
382
  var resolveRcTarget = () => {
247
383
  const resolved = resolveShellRc();
@@ -249,6 +385,11 @@ var resolveRcTarget = () => {
249
385
  const fallback = FALLBACK_RCS.map((name) => join2(homedir2(), name)).find(existsSync2);
250
386
  return fallback ? { path: fallback, shell: null } : null;
251
387
  };
388
+ var keyLoaderWriteFor = (envFile, target) => {
389
+ const loaderWrite = target ? writeKeyLoader(target.path, keyLoaderLine(envFile.path), target.shell) : rcResult("no-rc");
390
+ if (envFile.kind === "written" || loaderWrite.kind === "declined") return loaderWrite;
391
+ return { ...loaderWrite, kind: "unavailable", path: envFile.path, detail: envFile.detail };
392
+ };
252
393
  var writeKey = (apiKey, origin, options = {}) => {
253
394
  const configPath = configFilePath();
254
395
  const keyInForce = readKeySource().key;
@@ -278,12 +419,24 @@ var writeKey = (apiKey, origin, options = {}) => {
278
419
  KEY_FILE_MODE
279
420
  );
280
421
  restrictFile(configPath);
422
+ const envFile = writeKeyEnvFile(apiKey);
281
423
  const target = (options.resolveRc ?? resolveRcTarget)();
282
- const rc = target ? rewriteRcExport(target.path, apiKey, target.shell) : rcResult("no-rc");
424
+ const rc = keyLoaderWriteFor(envFile, target);
283
425
  const replacedKey = replacedKeyRecordWasHonoured ? null : replacedKeyToRecord(keyInForce, apiKey, rc, process.platform);
284
426
  if (replacedKey !== null) recordReplacedKey(configPath, replacedKey);
285
427
  process.env.PUSHARY_API_KEY = apiKey;
286
- return { configPath, rc, configBackupPath };
428
+ return { configPath, envFilePath: envFile.path, rc, configBackupPath };
429
+ };
430
+ var disableKeyLinesIn = (rcPath, loader, isReplacedLine) => {
431
+ try {
432
+ const real = realpathSync(rcPath);
433
+ const lines = readFileSync2(real, "utf8").split("\n");
434
+ const edit = replaceKeyLinesWithLoader(lines, loader, isReplacedLine);
435
+ if (keyLinesWereReplaced(lines, edit)) writeFileSync2(real, edit.lines.join("\n"));
436
+ return edit.replacedLineCount;
437
+ } catch {
438
+ return 0;
439
+ }
287
440
  };
288
441
  var clearKey = (options = {}) => {
289
442
  const configPath = configFilePath();
@@ -295,28 +448,20 @@ var clearKey = (options = {}) => {
295
448
  restrictFile(configPath);
296
449
  removedFromConfig = true;
297
450
  }
451
+ const envFilePath = keyEnvFilePath();
452
+ const envFileRemoval = removeKeyEnvFile(envFilePath);
298
453
  const target = (options.resolveRc ?? resolveRcTarget)();
299
- let rcLinesDisabled = 0;
300
- if (target) {
301
- try {
302
- const real = realpathSync(target.path);
303
- const lines = readFileSync2(real, "utf8").split("\n");
304
- const next = lines.map((line) => {
305
- if (!OUR_EXPORT.test(line)) return line;
306
- rcLinesDisabled += 1;
307
- return disabledExportLine(line);
308
- });
309
- if (rcLinesDisabled > 0) writeFileSync2(real, next.join("\n"));
310
- } catch {
311
- rcLinesDisabled = 0;
312
- }
313
- }
454
+ const keyLinesToReplace = envFileRemoval.kind === "failed" ? isActiveKeyExport : isPusharyKeyLine;
455
+ const rcLinesDisabled = target ? disableKeyLinesIn(target.path, keyLoaderLine(envFilePath), keyLinesToReplace) : 0;
314
456
  delete process.env.PUSHARY_API_KEY;
315
457
  return {
316
458
  removedFromConfig,
317
459
  configPath,
318
460
  rcPath: target?.path ?? null,
319
- rcLinesDisabled
461
+ rcLinesDisabled,
462
+ envFilePath,
463
+ removedEnvFile: envFileRemoval.kind === "removed",
464
+ envFileRemovalError: envFileRemoval.kind === "failed" ? envFileRemoval.detail : null
320
465
  };
321
466
  };
322
467
  var restrictFile = (filePath) => {
@@ -398,8 +543,9 @@ var exportedKeyLineIn = (path) => {
398
543
  const found = contents === null ? null : findKeyExport(contents);
399
544
  return found ? [{ path, ...found }] : [];
400
545
  };
401
- var findExportedKeyLines = (profiles = shellProfileCandidates()) => profiles.flatMap(exportedKeyLineIn);
402
- var findExportedKeyLine = (profiles = shellProfileCandidates()) => findExportedKeyLines(profiles)[0] ?? null;
546
+ var exportedKeyFiles = () => [keyEnvFilePath(), ...shellProfileCandidates()];
547
+ var findExportedKeyLines = (profiles = exportedKeyFiles()) => profiles.flatMap(exportedKeyLineIn);
548
+ var findExportedKeyLine = (profiles = exportedKeyFiles()) => findExportedKeyLines(profiles)[0] ?? null;
403
549
 
404
550
  export {
405
551
  CANDIDATE_RCS,
@@ -408,6 +554,9 @@ export {
408
554
  removeClaudeAlias,
409
555
  KEY_FILE_MODE,
410
556
  isDisabledExport,
557
+ keyEnvFilePath,
558
+ isKeyLoaderLine,
559
+ withoutKeyLines,
411
560
  keyPrefix,
412
561
  isCliCreatedKey,
413
562
  shellKeyWasReplaced,
@@ -426,7 +575,7 @@ export {
426
575
  readReplacedKeyPrefix,
427
576
  replacedKeyRecordIsHonoured,
428
577
  recordMacAppKeyPrefix,
429
- shellProfileCandidates,
578
+ exportedKeyFiles,
430
579
  findExportedKeyLines,
431
580
  findExportedKeyLine
432
581
  };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  NPX_LATEST_COMMAND
3
- } from "./chunk-WDLBF3PM.js";
3
+ } from "./chunk-IV7WDCKS.js";
4
4
 
5
5
  // src/config.ts
6
6
  import { readFileSync } from "fs";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  findNativeClaudeInstall
3
- } from "./chunk-CYTPQDQY.js";
3
+ } from "./chunk-TCE3J44Z.js";
4
4
  import {
5
5
  isFile
6
- } from "./chunk-TODDEIYG.js";
6
+ } from "./chunk-PM2NRK6Y.js";
7
7
 
8
8
  // src/wrapper/claudeBinary.ts
9
9
  import { homedir } from "os";
@@ -3,10 +3,10 @@ import {
3
3
  } from "./chunk-WHB622LP.js";
4
4
  import {
5
5
  ensureDaemonRunning
6
- } from "./chunk-LDUK7D2I.js";
6
+ } from "./chunk-JUE347Z7.js";
7
7
  import {
8
8
  hookOwnerOf
9
- } from "./chunk-OBUKF3WP.js";
9
+ } from "./chunk-5EU7V5CT.js";
10
10
  import {
11
11
  hookMeaning
12
12
  } from "./chunk-CFZUESTS.js";
@@ -24,35 +24,35 @@ import {
24
24
  uploadTranscriptRecords,
25
25
  verifyAnchoredRecipients,
26
26
  wrapSessionKey
27
- } from "./chunk-7DEAVAAS.js";
27
+ } from "./chunk-HRUKMGRH.js";
28
28
  import {
29
29
  external_exports,
30
30
  ownedOnlyByThisUser,
31
31
  savedTranscriptReadPositions
32
- } from "./chunk-352FIVVH.js";
32
+ } from "./chunk-55L4JSPA.js";
33
33
  import {
34
34
  transcriptEnvironmentPreference,
35
35
  transcriptsEnabled
36
- } from "./chunk-3M4ZOSR3.js";
36
+ } from "./chunk-UB5G7ZZN.js";
37
37
  import {
38
38
  fetchAsCredential
39
39
  } from "./chunk-SSKNRWWS.js";
40
40
  import {
41
41
  readTranscriptPreference
42
- } from "./chunk-DYZ26IPH.js";
42
+ } from "./chunk-7XSZK4DH.js";
43
43
  import {
44
44
  claudeConfigDir,
45
45
  codexHome,
46
46
  pusharyDir
47
- } from "./chunk-X7RPRBZE.js";
47
+ } from "./chunk-DRRFOQGF.js";
48
48
  import {
49
49
  getApiKey,
50
50
  getBaseUrl
51
- } from "./chunk-LVF5IBS6.js";
51
+ } from "./chunk-A2DVMIX4.js";
52
52
  import {
53
53
  writeJsonAtomic,
54
54
  writeJsonAtomicDurable
55
- } from "./chunk-TODDEIYG.js";
55
+ } from "./chunk-PM2NRK6Y.js";
56
56
  import {
57
57
  PENDING_COMMAND_PREFIX,
58
58
  SESSION_HISTORY_BACKFILL_LIMIT_BYTES,
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-BG4HHB7E.js";
4
4
  import {
5
5
  renderCommandHelp
6
- } from "./chunk-WDLBF3PM.js";
6
+ } from "./chunk-IV7WDCKS.js";
7
7
  import {
8
8
  getPackageVersion
9
9
  } from "./chunk-UQTQ6HPO.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  announceSubscriptionRequired,
3
3
  isDeferAnswer
4
- } from "./chunk-66VZIS6R.js";
4
+ } from "./chunk-CUWHBFBB.js";
5
5
  import {
6
6
  askUser,
7
7
  isDecisionStopped,
@@ -9,13 +9,13 @@ import {
9
9
  isThePersonsStop,
10
10
  waitForOpenQuestion,
11
11
  waitForQuestion
12
- } from "./chunk-VWVYDYCV.js";
12
+ } from "./chunk-PQEX64YL.js";
13
13
  import {
14
14
  SubscriptionRequiredError
15
- } from "./chunk-6PDBRLIH.js";
15
+ } from "./chunk-EGDFXMFK.js";
16
16
  import {
17
17
  getMachineId
18
- } from "./chunk-MOQUKAVU.js";
18
+ } from "./chunk-MJMRJ5ZF.js";
19
19
  import {
20
20
  ASK_CONTEXT_MAX,
21
21
  agentQuestionContext,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  UsageError
3
- } from "./chunk-YU2EUD7O.js";
3
+ } from "./chunk-CINBAX5G.js";
4
4
 
5
5
  // src/cli/flags.ts
6
6
  var normalize = (raw) => raw.replace(/^--?/, "");
@@ -52,7 +52,9 @@ var messageFor = (err) => {
52
52
 
53
53
  export {
54
54
  UsageError,
55
+ UserError,
55
56
  NetworkError,
57
+ AuthError,
56
58
  exitCodeFor,
57
59
  messageFor
58
60
  };
@@ -14,7 +14,7 @@ import {
14
14
  reachVerdict,
15
15
  reachesYou,
16
16
  verifyDelivery
17
- } from "./chunk-ZXRBGLTI.js";
17
+ } from "./chunk-SM65Z6CM.js";
18
18
  import {
19
19
  describeRevokeAttempt,
20
20
  keyNoLongerAccepted,
@@ -32,13 +32,13 @@ import {
32
32
  } from "./chunk-DXUPOVJP.js";
33
33
  import {
34
34
  checkApiKey
35
- } from "./chunk-GV3ZGKMK.js";
35
+ } from "./chunk-IYTTLDB5.js";
36
36
  import {
37
37
  reportedInstallSource
38
- } from "./chunk-K24RAOIO.js";
38
+ } from "./chunk-3I3RUJRD.js";
39
39
  import {
40
40
  NPX_LATEST_COMMAND
41
- } from "./chunk-WDLBF3PM.js";
41
+ } from "./chunk-IV7WDCKS.js";
42
42
  import {
43
43
  NO_PAIRING_COMPUTER,
44
44
  PAIR_TTL_SECONDS
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  parseFlags
3
- } from "./chunk-YPY4YCIZ.js";
3
+ } from "./chunk-BZIBNSQE.js";
4
4
  import {
5
5
  UsageError
6
- } from "./chunk-YU2EUD7O.js";
6
+ } from "./chunk-CINBAX5G.js";
7
7
  import {
8
8
  SETUP_AGENT_CHOICES,
9
9
  isSetupConnectMode,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  DEFAULT_SESSION
3
- } from "./chunk-PG5N3FL5.js";
3
+ } from "./chunk-FIJPDZIR.js";
4
4
 
5
5
  // src/answer.ts
6
6
  var isDeferAnswer = (value) => value === "defer";
@@ -484,9 +484,9 @@ var installGlobally = (options) => {
484
484
  }
485
485
  const started = (async () => {
486
486
  if (!npmIsOnPath()) throw new NpmMissingError();
487
- const { withUpgradeLock } = await import("./global-upgrade-ZAPGSH66.js");
488
- const { installWithUpgradeLock, ownsUpgradeLock } = await import("./upgrade-lock-3P3VK6KQ.js");
489
- const { autoUpdateLock } = await import("./paths-LCARWI3S.js");
487
+ const { withUpgradeLock } = await import("./global-upgrade-4K5SGI7Q.js");
488
+ const { installWithUpgradeLock, ownsUpgradeLock } = await import("./upgrade-lock-G3RQPHYM.js");
489
+ const { autoUpdateLock } = await import("./paths-AXIBD5XG.js");
490
490
  let result = "skipped";
491
491
  const install = async () => {
492
492
  const platform = process.platform;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  absoluteUrl
3
- } from "./chunk-GV3ZGKMK.js";
3
+ } from "./chunk-IYTTLDB5.js";
4
4
  import {
5
5
  KEY_SCOPE
6
6
  } from "./chunk-L77OIGRB.js";
@@ -1,16 +1,16 @@
1
1
  import {
2
2
  spawnClaude
3
- } from "./chunk-Y6ILCLKE.js";
3
+ } from "./chunk-VRNGMRJA.js";
4
4
  import {
5
5
  CODEX_HOOK_EVENTS,
6
6
  CODEX_REQUIRED_APPROVAL_EVENTS,
7
7
  codexHome,
8
8
  codexHooksJsonIn,
9
9
  isPusharyCodexCommand
10
- } from "./chunk-X7RPRBZE.js";
10
+ } from "./chunk-DRRFOQGF.js";
11
11
  import {
12
12
  resolvePathBinary
13
- } from "./chunk-NOHOCNY6.js";
13
+ } from "./chunk-D3TNLVVL.js";
14
14
  import {
15
15
  getPackageVersion
16
16
  } from "./chunk-UQTQ6HPO.js";
@@ -3,10 +3,10 @@ import {
3
3
  formatVersion,
4
4
  quoteIfNeeded,
5
5
  shellDoubleQuoted
6
- } from "./chunk-NOHOCNY6.js";
6
+ } from "./chunk-D3TNLVVL.js";
7
7
  import {
8
8
  writeFileAtomic
9
- } from "./chunk-TODDEIYG.js";
9
+ } from "./chunk-PM2NRK6Y.js";
10
10
  import {
11
11
  cmdShimScriptOf
12
12
  } from "./chunk-UQTQ6HPO.js";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  realpath
3
- } from "./chunk-LGQUJFVZ.js";
3
+ } from "./chunk-7ODDR6FA.js";
4
4
  import {
5
5
  findNativeClaudeInstall
6
- } from "./chunk-CYTPQDQY.js";
6
+ } from "./chunk-TCE3J44Z.js";
7
7
  import {
8
8
  readGlobalPrefixAsync,
9
9
  resolveGlobalBinary,
@@ -12,7 +12,7 @@ import {
12
12
  resolvePackageVersionFromBinary,
13
13
  resolvePathBinary,
14
14
  resolvePathBinaryAsync
15
- } from "./chunk-NOHOCNY6.js";
15
+ } from "./chunk-D3TNLVVL.js";
16
16
  import {
17
17
  CLAUDE_BRIDGE_CAPABILITY,
18
18
  CLAUDE_RESUME_CAPABILITY,