@pushary/agent-hooks 1.9.10 → 1.9.11

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 (102) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +1 -1
  3. package/dist/bin/pushary-bell-hook.js +25 -21
  4. package/dist/bin/pushary-bell.js +9 -9
  5. package/dist/bin/pushary-claude.js +31 -34
  6. package/dist/bin/pushary-clean.js +35 -37
  7. package/dist/bin/pushary-codex-bridge.js +20 -22
  8. package/dist/bin/pushary-codex-hook.js +33 -36
  9. package/dist/bin/pushary-codex.js +12 -14
  10. package/dist/bin/pushary-connect.js +25 -27
  11. package/dist/bin/pushary-cowork.js +5 -5
  12. package/dist/bin/pushary-daemon.js +31 -33
  13. package/dist/bin/pushary-disconnect.js +29 -29
  14. package/dist/bin/pushary-doctor.js +39 -41
  15. package/dist/bin/pushary-elicitation-hook.js +26 -26
  16. package/dist/bin/pushary-gemini-bridge.js +13 -13
  17. package/dist/bin/pushary-gemini-hook.js +30 -33
  18. package/dist/bin/pushary-hook.js +31 -33
  19. package/dist/bin/pushary-login.js +12 -12
  20. package/dist/bin/pushary-logout.js +10 -10
  21. package/dist/bin/pushary-mcp.js +9 -9
  22. package/dist/bin/pushary-mode.js +12 -12
  23. package/dist/bin/pushary-notification-hook.js +24 -26
  24. package/dist/bin/pushary-opencode-hook.js +29 -32
  25. package/dist/bin/pushary-permission-denied-hook.js +29 -31
  26. package/dist/bin/pushary-permission-hook.js +28 -30
  27. package/dist/bin/pushary-post-hook.js +24 -26
  28. package/dist/bin/pushary-prompt-hook.js +24 -26
  29. package/dist/bin/pushary-session-end-hook.js +24 -26
  30. package/dist/bin/pushary-session-start-hook.js +28 -30
  31. package/dist/bin/pushary-setup.js +47 -44
  32. package/dist/bin/pushary-stats.js +5 -5
  33. package/dist/bin/pushary-status.js +27 -29
  34. package/dist/bin/pushary-stop-hook.js +24 -26
  35. package/dist/bin/pushary-stopfailure-hook.js +24 -26
  36. package/dist/bin/pushary-suggestions.js +12 -12
  37. package/dist/bin/pushary-transcript-register.js +17 -17
  38. package/dist/bin/pushary-transcripts.js +7 -7
  39. package/dist/bin/pushary-upgrade.js +30 -32
  40. package/dist/bin/pushary-wait.js +12 -12
  41. package/dist/bin/pushary.js +6 -6
  42. package/dist/{chunk-IIVZZMSO.js → chunk-2AQ4VZSA.js} +1 -1
  43. package/dist/{chunk-APP43AW7.js → chunk-2GG77ADC.js} +1 -1
  44. package/dist/{chunk-H4F5O3RE.js → chunk-2NAQRPZQ.js} +1 -1
  45. package/dist/{chunk-UJZ7AGSC.js → chunk-4FWWHCYM.js} +4 -4
  46. package/dist/{chunk-ZGADIZDS.js → chunk-4HR2ICME.js} +1 -1
  47. package/dist/{chunk-BOSXFI7L.js → chunk-4RENRBSB.js} +4 -4
  48. package/dist/{chunk-BTFUSQFB.js → chunk-5WAYSUWV.js} +2 -2
  49. package/dist/{chunk-SIHYBIEN.js → chunk-7RWQZQV2.js} +5 -5
  50. package/dist/{chunk-LDQGURCF.js → chunk-A6J5Z2HO.js} +514 -313
  51. package/dist/{chunk-C6QTMWJZ.js → chunk-AIWZRRSK.js} +2 -2
  52. package/dist/{chunk-OL2Z7WI4.js → chunk-BDRXDO25.js} +2 -2
  53. package/dist/{chunk-S2DAKKQQ.js → chunk-BMP2BLIR.js} +3 -3
  54. package/dist/{chunk-QGRENWJL.js → chunk-BZI7EBTB.js} +1 -1
  55. package/dist/{chunk-2HFSKYLN.js → chunk-C6QM5SJR.js} +2 -2
  56. package/dist/{chunk-Q3UMWSE4.js → chunk-CBDJ2X5P.js} +2 -2
  57. package/dist/{chunk-DWO4RLYK.js → chunk-CHDAH4HP.js} +8 -8
  58. package/dist/{chunk-PR2VDVCP.js → chunk-CZYMYM7X.js} +3 -3
  59. package/dist/{chunk-MD4SVNT6.js → chunk-E6YQW43K.js} +1 -1
  60. package/dist/{chunk-UM5WXBKN.js → chunk-EJVYEOKC.js} +3 -3
  61. package/dist/{chunk-5MQYA3YL.js → chunk-ERXY2SIW.js} +19 -16
  62. package/dist/{chunk-2M52CFVO.js → chunk-FJCOOFT7.js} +1 -1
  63. package/dist/{chunk-Y7JM47CI.js → chunk-GA4J6YFN.js} +2 -2
  64. package/dist/{chunk-ZSGJYSF2.js → chunk-GUNZHSTL.js} +136 -8
  65. package/dist/{chunk-T6ZN4TEF.js → chunk-HX5TI6DP.js} +1 -1
  66. package/dist/{chunk-XXLCYKVS.js → chunk-I4I4UH62.js} +3 -3
  67. package/dist/{chunk-I3W7GJ5R.js → chunk-KBN3UP2R.js} +3 -3
  68. package/dist/{chunk-7HGR5GNY.js → chunk-KEV2MOJH.js} +46 -21
  69. package/dist/{chunk-QAGWWDXQ.js → chunk-KIVFWGG6.js} +5 -5
  70. package/dist/{chunk-AKPHYSEL.js → chunk-LBAMPNDM.js} +4 -4
  71. package/dist/{chunk-BVSIM4EF.js → chunk-LUHNNZSH.js} +2 -2
  72. package/dist/{chunk-Z2Q2VH43.js → chunk-LX6EWNRK.js} +15 -3
  73. package/dist/{chunk-TCXL5FQQ.js → chunk-M54ATCOZ.js} +1 -1
  74. package/dist/{chunk-2HXG2QDI.js → chunk-MHHXR7DT.js} +4 -4
  75. package/dist/{chunk-2S34OPHS.js → chunk-MITMDERZ.js} +1 -1
  76. package/dist/{chunk-BVPPYR7B.js → chunk-MJLTABWF.js} +3 -3
  77. package/dist/{chunk-XKMGHVXW.js → chunk-MX3LPP3K.js} +6 -6
  78. package/dist/{chunk-EVC765EO.js → chunk-N6GEI3PK.js} +2 -2
  79. package/dist/{chunk-MISUKJGW.js → chunk-N7HXP4PZ.js} +1 -1
  80. package/dist/{chunk-LXA236ZQ.js → chunk-OKSU74QH.js} +2 -2
  81. package/dist/{chunk-DL6QHS7V.js → chunk-P2EJN7UB.js} +1 -1
  82. package/dist/{chunk-YUQHUGTH.js → chunk-P7N7FJ7W.js} +1 -1
  83. package/dist/{chunk-DAOQT4WK.js → chunk-PRJNUNCV.js} +2 -2
  84. package/dist/{chunk-RPQLZLKC.js → chunk-PTGUJZSD.js} +5 -5
  85. package/dist/{chunk-6KNC6KLL.js → chunk-STUJXZC2.js} +4 -4
  86. package/dist/{chunk-GQYX24UC.js → chunk-TVVUJTUW.js} +1 -1
  87. package/dist/{chunk-5OP5MQI7.js → chunk-V6IW5WMK.js} +1 -1
  88. package/dist/{chunk-5RGA636G.js → chunk-VOP5U2VX.js} +145 -9
  89. package/dist/{chunk-U5FP5JIS.js → chunk-WCELLK4P.js} +2 -2
  90. package/dist/{chunk-SJDMULE7.js → chunk-WHRYW4P2.js} +5 -5
  91. package/dist/{chunk-SMVMLWCD.js → chunk-XYCTS3WP.js} +1 -1
  92. package/dist/{chunk-PNC5ZQFS.js → chunk-YETKAI5Q.js} +6 -6
  93. package/dist/{chunk-GTZ4HIHU.js → chunk-Z4AOR6RZ.js} +2 -2
  94. package/dist/{chunk-CJYM4ZHV.js → chunk-ZTSMQYST.js} +3 -5
  95. package/dist/{global-upgrade-PUM44JUH.js → global-upgrade-VT2JS7DR.js} +6 -6
  96. package/dist/{paths-U2MJGNBT.js → paths-WRBEUNEY.js} +2 -2
  97. package/dist/{reapply-PRKV4EO7.js → reapply-BCR6U7HO.js} +20 -22
  98. package/dist/src/index.js +19 -21
  99. package/dist/{upgrade-lock-QZSVLEM7.js → upgrade-lock-VRYMTPZQ.js} +3 -3
  100. package/package.json +1 -1
  101. package/dist/chunk-N6IOSZOE.js +0 -185
  102. package/dist/chunk-NQ67AF3V.js +0 -142
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  pusharyDir
3
- } from "./chunk-UJZ7AGSC.js";
3
+ } from "./chunk-4FWWHCYM.js";
4
4
  import {
5
5
  readJsonSafe,
6
6
  writeFileAtomic
@@ -13,7 +13,7 @@ import {
13
13
  serializeDeclinedAgents,
14
14
  withDeclinedAgent,
15
15
  withoutDeclinedAgent
16
- } from "./chunk-5RGA636G.js";
16
+ } from "./chunk-VOP5U2VX.js";
17
17
 
18
18
  // src/declined-agents-file.ts
19
19
  import { join } from "path";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  parseSseMessages
3
- } from "./chunk-I3W7GJ5R.js";
3
+ } from "./chunk-KBN3UP2R.js";
4
4
  import {
5
5
  NPX_LATEST_COMMAND
6
- } from "./chunk-TCXL5FQQ.js";
6
+ } from "./chunk-M54ATCOZ.js";
7
7
 
8
8
  // src/mcp-stdio-bridge.ts
9
9
  var MCP_BRIDGE_BINARY = "pushary-mcp";
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  openCodeConfigDirFrom
3
- } from "./chunk-QAGWWDXQ.js";
3
+ } from "./chunk-KIVFWGG6.js";
4
4
  import {
5
5
  codexHomeFrom,
6
6
  resolvePathBinary
7
- } from "./chunk-UJZ7AGSC.js";
7
+ } from "./chunk-4FWWHCYM.js";
8
8
  import {
9
9
  HOOK_COMPATIBLE_PROFILES
10
- } from "./chunk-5RGA636G.js";
10
+ } from "./chunk-VOP5U2VX.js";
11
11
 
12
12
  // src/hermes-config.ts
13
13
  import { execFileSync } from "child_process";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  readTranscriptPreference
3
- } from "./chunk-GTZ4HIHU.js";
3
+ } from "./chunk-Z4AOR6RZ.js";
4
4
 
5
5
  // src/transcript-setting.ts
6
6
  var transcriptEnvironmentPreference = () => {
@@ -3,10 +3,10 @@ import {
3
3
  } from "./chunk-KZERVKTD.js";
4
4
  import {
5
5
  renderCommandHelp
6
- } from "./chunk-TCXL5FQQ.js";
6
+ } from "./chunk-M54ATCOZ.js";
7
7
  import {
8
8
  getPackageVersion
9
- } from "./chunk-5RGA636G.js";
9
+ } from "./chunk-VOP5U2VX.js";
10
10
 
11
11
  // src/cli/usage.ts
12
12
  var exitOnHelpFlag = (command) => {
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  configFilePath
3
- } from "./chunk-2M52CFVO.js";
3
+ } from "./chunk-FJCOOFT7.js";
4
4
  import {
5
5
  normalizeInstallSource
6
- } from "./chunk-5RGA636G.js";
6
+ } from "./chunk-VOP5U2VX.js";
7
7
 
8
8
  // src/install-source.ts
9
9
  import { readFileSync } from "fs";
@@ -6,38 +6,38 @@ import {
6
6
  } from "./chunk-SGZJ5LYH.js";
7
7
  import {
8
8
  ensureDaemonRunning
9
- } from "./chunk-RPQLZLKC.js";
9
+ } from "./chunk-PTGUJZSD.js";
10
10
  import {
11
11
  buildTranscriptRecords,
12
12
  decodePublicKey,
13
13
  generateSessionKey,
14
14
  wrapSessionKey
15
- } from "./chunk-APP43AW7.js";
15
+ } from "./chunk-2GG77ADC.js";
16
16
  import {
17
17
  fetchTranscriptRecipients,
18
18
  uploadTranscriptRecords
19
- } from "./chunk-MISUKJGW.js";
19
+ } from "./chunk-N7HXP4PZ.js";
20
20
  import {
21
21
  transcriptEnvironmentPreference,
22
22
  transcriptsEnabled
23
- } from "./chunk-QGRENWJL.js";
23
+ } from "./chunk-BZI7EBTB.js";
24
24
  import {
25
25
  hookOwnerOf
26
- } from "./chunk-SIHYBIEN.js";
26
+ } from "./chunk-7RWQZQV2.js";
27
27
  import {
28
28
  readTranscriptPreference
29
- } from "./chunk-GTZ4HIHU.js";
29
+ } from "./chunk-Z4AOR6RZ.js";
30
30
  import {
31
31
  codexHome,
32
32
  pusharyDir
33
- } from "./chunk-UJZ7AGSC.js";
33
+ } from "./chunk-4FWWHCYM.js";
34
34
  import {
35
35
  writeJsonAtomic
36
36
  } from "./chunk-T7E75EKA.js";
37
37
  import {
38
38
  getApiKey,
39
39
  getBaseUrl
40
- } from "./chunk-2M52CFVO.js";
40
+ } from "./chunk-FJCOOFT7.js";
41
41
 
42
42
  // src/transcript-registration.ts
43
43
  import { createHash } from "crypto";
@@ -5,16 +5,16 @@ import {
5
5
  import {
6
6
  NOTIFICATION_MATCHED_TYPES,
7
7
  POSTTOOLUSE_MIRRORED_TOOLS
8
- } from "./chunk-MD4SVNT6.js";
8
+ } from "./chunk-E6YQW43K.js";
9
9
  import {
10
10
  isProtectedByScope,
11
11
  registerHookEntry
12
- } from "./chunk-UJZ7AGSC.js";
12
+ } from "./chunk-4FWWHCYM.js";
13
13
  import {
14
14
  CLAUDE_PRETOOLUSE_MATCHER,
15
15
  HOOK_BUDGETS,
16
16
  HOOK_LOCATOR_BINARY
17
- } from "./chunk-5RGA636G.js";
17
+ } from "./chunk-VOP5U2VX.js";
18
18
 
19
19
  // src/gemini-config.ts
20
20
  var GEMINI_HOOK_BINARY = "pushary-gemini-hook";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  PRETOOLUSE_GATED_TOOLS
3
- } from "./chunk-5RGA636G.js";
3
+ } from "./chunk-VOP5U2VX.js";
4
4
 
5
5
  // src/claude-tools.ts
6
6
  var POSTTOOLUSE_MIRROR_ONLY_TOOLS = ["TodoWrite", "Task", "WebFetch", "WebSearch"];
@@ -1,16 +1,16 @@
1
1
  import {
2
2
  readExistingMachineId
3
- } from "./chunk-H4F5O3RE.js";
3
+ } from "./chunk-2NAQRPZQ.js";
4
4
  import {
5
5
  NetworkError
6
6
  } from "./chunk-7QLSKOSU.js";
7
7
  import {
8
8
  getBaseUrl
9
- } from "./chunk-2M52CFVO.js";
9
+ } from "./chunk-FJCOOFT7.js";
10
10
  import {
11
11
  clientContextHeaders,
12
12
  getPackageVersion
13
- } from "./chunk-5RGA636G.js";
13
+ } from "./chunk-VOP5U2VX.js";
14
14
 
15
15
  // src/cli/net.ts
16
16
  import { createRequire } from "module";
@@ -1,22 +1,23 @@
1
1
  import {
2
2
  defersToNativeMode,
3
3
  reportMachineDenial
4
- } from "./chunk-CJYM4ZHV.js";
4
+ } from "./chunk-ZTSMQYST.js";
5
5
  import {
6
6
  isGatingMoment,
7
7
  recordKeylessMoment
8
- } from "./chunk-IIVZZMSO.js";
8
+ } from "./chunk-2AQ4VZSA.js";
9
9
  import {
10
10
  announceSubscriptionRequired,
11
11
  denyReasonFrom,
12
12
  isDeferAnswer,
13
13
  oncePerSession
14
- } from "./chunk-5OP5MQI7.js";
14
+ } from "./chunk-V6IW5WMK.js";
15
15
  import {
16
16
  activeHookSource,
17
17
  activeIdentity
18
- } from "./chunk-7HGR5GNY.js";
18
+ } from "./chunk-KEV2MOJH.js";
19
19
  import {
20
+ DEFAULT_SESSION,
20
21
  UNNAMED_ACTION,
21
22
  approvalAwaitingRetry,
22
23
  blockedActionFingerprint,
@@ -39,10 +40,7 @@ import {
39
40
  reportEvent,
40
41
  scopePathFor,
41
42
  settleQuestionsForToolUse
42
- } from "./chunk-LDQGURCF.js";
43
- import {
44
- DEFAULT_SESSION
45
- } from "./chunk-N6IOSZOE.js";
43
+ } from "./chunk-A6J5Z2HO.js";
46
44
  import {
47
45
  askUser,
48
46
  cancelQuestion,
@@ -53,20 +51,20 @@ import {
53
51
  requestGate,
54
52
  sendNotification,
55
53
  waitForQuestion
56
- } from "./chunk-ZSGJYSF2.js";
54
+ } from "./chunk-GUNZHSTL.js";
57
55
  import {
58
56
  SubscriptionRequiredError
59
- } from "./chunk-I3W7GJ5R.js";
57
+ } from "./chunk-KBN3UP2R.js";
60
58
  import {
61
59
  getMachineId
62
- } from "./chunk-H4F5O3RE.js";
60
+ } from "./chunk-2NAQRPZQ.js";
63
61
  import {
64
62
  getApiKey,
65
63
  getBaseUrl
66
- } from "./chunk-2M52CFVO.js";
64
+ } from "./chunk-FJCOOFT7.js";
67
65
  import {
68
66
  NPX_LATEST_COMMAND
69
- } from "./chunk-TCXL5FQQ.js";
67
+ } from "./chunk-M54ATCOZ.js";
70
68
  import {
71
69
  AGENT_QUESTION_STRATEGY,
72
70
  DECISION_STOP_REASON,
@@ -88,6 +86,7 @@ import {
88
86
  claudeStoppedPreToolUseOutput,
89
87
  editGoesToTheAgentsPrompt,
90
88
  effectiveWaitSeconds,
89
+ hasNativeApprovalPrompt,
91
90
  hookHoldWindowMs,
92
91
  hookWaitClamped,
93
92
  hookWaitDeadline,
@@ -99,7 +98,7 @@ import {
99
98
  parseAgentQuestions,
100
99
  questionHandedToTheTerminal,
101
100
  resolveGate
102
- } from "./chunk-5RGA636G.js";
101
+ } from "./chunk-VOP5U2VX.js";
103
102
 
104
103
  // src/claude-permission-rules.ts
105
104
  import { readFileSync, statSync } from "fs";
@@ -350,10 +349,14 @@ var dispatchModeHandler = async (apiKey, input, toolPolicy, machineId, trainingC
350
349
  }
351
350
  return result;
352
351
  };
352
+ var handsUnansweredToTheTerminal = (source) => source === null || hasNativeApprovalPrompt(source, "PreToolUse");
353
+ var phoneWaitHandoff = (source, waitSeconds) => {
354
+ if (waitSeconds <= 0) return "Waiting for your answer.";
355
+ return handsUnansweredToTheTerminal(source) ? `Waiting ${waitSeconds}s, then this terminal takes over.` : `Waiting ${waitSeconds}s. If nobody answers, it does not run.`;
356
+ };
353
357
  var announceWait = (waitSeconds, answerUrl, sessionId) => {
354
358
  try {
355
- const handoff = waitSeconds > 0 ? `Waiting ${waitSeconds}s, then this terminal takes over.` : "Waiting for your answer.";
356
- process.stderr.write(`[pushary] Sent to your phone. ${handoff}
359
+ process.stderr.write(`[pushary] Sent to your phone. ${phoneWaitHandoff(ACTIVE_SOURCE, waitSeconds)}
357
360
  `);
358
361
  if (answerUrl && oncePerSession("answerurl", sessionId)) {
359
362
  process.stderr.write(` Answer here instead: ${answerUrl}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  NPX_LATEST_COMMAND
3
- } from "./chunk-TCXL5FQQ.js";
3
+ } from "./chunk-M54ATCOZ.js";
4
4
 
5
5
  // src/config.ts
6
6
  import { readFileSync } from "fs";
@@ -8,10 +8,10 @@ import {
8
8
  codexHooksJsonIn,
9
9
  isPusharyCodexCommand,
10
10
  resolvePathBinary
11
- } from "./chunk-UJZ7AGSC.js";
11
+ } from "./chunk-4FWWHCYM.js";
12
12
  import {
13
13
  getPackageVersion
14
- } from "./chunk-5RGA636G.js";
14
+ } from "./chunk-VOP5U2VX.js";
15
15
 
16
16
  // src/codex-app-server.ts
17
17
  import { existsSync, realpathSync } from "fs";
@@ -1,23 +1,147 @@
1
+ import {
2
+ CLIENT_REPORT_DISABLE_ENV,
3
+ isDisabledByEnv
4
+ } from "./chunk-POFBE6ZY.js";
1
5
  import {
2
6
  SubscriptionRequiredError,
3
7
  callMcpTool
4
- } from "./chunk-I3W7GJ5R.js";
8
+ } from "./chunk-KBN3UP2R.js";
5
9
  import {
6
- clientErrorKindOf,
7
- reportClientError
8
- } from "./chunk-NQ67AF3V.js";
10
+ installNetworkDefaults,
11
+ isNetworkFailure
12
+ } from "./chunk-EJVYEOKC.js";
9
13
  import {
10
- installNetworkDefaults
11
- } from "./chunk-UM5WXBKN.js";
14
+ clientReportClaims
15
+ } from "./chunk-4FWWHCYM.js";
12
16
  import {
17
+ getApiKey,
13
18
  getBaseUrl
14
- } from "./chunk-2M52CFVO.js";
19
+ } from "./chunk-FJCOOFT7.js";
15
20
  import {
16
21
  ASK_AGENT_NAME_MAX,
17
22
  ASK_QUESTION_MAX,
23
+ CLIENT_REPORT_PATH,
18
24
  DECISION_LINE_MAX,
25
+ degradedLine,
19
26
  truncateLine
20
- } from "./chunk-5RGA636G.js";
27
+ } from "./chunk-VOP5U2VX.js";
28
+
29
+ // src/client-report-claim.ts
30
+ import { createHash } from "crypto";
31
+ import { closeSync, mkdirSync, openSync, readdirSync, unlinkSync } from "fs";
32
+ import { join } from "path";
33
+ var CLIENT_REPORT_WINDOW_MS = 6e4;
34
+ var CLAIM_DIRECTORY_MODE = 448;
35
+ var CLAIM_FILE_MODE = 384;
36
+ var CLAIM_KEY_HASH_LENGTH = 16;
37
+ var CLAIM_FILE_PATTERN = /^[0-9a-f]{16}-(\d+)$/;
38
+ var EXCLUSIVE_CREATE = "wx";
39
+ var ALREADY_EXISTS = "EEXIST";
40
+ var WINDOWS_KEPT_BEHIND = 1;
41
+ var reportWindowOf = (now) => Math.floor(now / CLIENT_REPORT_WINDOW_MS);
42
+ var claimFileName = (key, window) => `${createHash("sha256").update(key).digest("hex").slice(0, CLAIM_KEY_HASH_LENGTH)}-${window}`;
43
+ var errorCodeOf = (error) => typeof error === "object" && error !== null && "code" in error && typeof error.code === "string" ? error.code : null;
44
+ var claimWindowOf = (fileName) => {
45
+ const match = CLAIM_FILE_PATTERN.exec(fileName);
46
+ return match ? Number(match[1]) : null;
47
+ };
48
+ var isStaleClaim = (fileName, window) => {
49
+ const claimedWindow = claimWindowOf(fileName);
50
+ return claimedWindow !== null && claimedWindow < window - WINDOWS_KEPT_BEHIND;
51
+ };
52
+ var removeQuietly = (filePath) => {
53
+ try {
54
+ unlinkSync(filePath);
55
+ } catch {
56
+ return;
57
+ }
58
+ };
59
+ var removeStaleClaims = (claimsDir, window) => {
60
+ try {
61
+ for (const fileName of readdirSync(claimsDir)) {
62
+ if (isStaleClaim(fileName, window)) removeQuietly(join(claimsDir, fileName));
63
+ }
64
+ } catch {
65
+ return;
66
+ }
67
+ };
68
+ var claimReportWindow = (claimsDir, key, now) => {
69
+ const window = reportWindowOf(now);
70
+ try {
71
+ mkdirSync(claimsDir, { recursive: true, mode: CLAIM_DIRECTORY_MODE });
72
+ closeSync(openSync(join(claimsDir, claimFileName(key, window)), EXCLUSIVE_CREATE, CLAIM_FILE_MODE));
73
+ } catch (error) {
74
+ return errorCodeOf(error) === ALREADY_EXISTS ? "already_claimed" : "unavailable";
75
+ }
76
+ removeStaleClaims(claimsDir, window);
77
+ return "claimed";
78
+ };
79
+
80
+ // src/client-report.ts
81
+ var CLIENT_REPORT_TIMEOUT_MS = 1e3;
82
+ var readApiKey = () => {
83
+ try {
84
+ return getApiKey();
85
+ } catch {
86
+ return null;
87
+ }
88
+ };
89
+ var defaultDeps = () => ({
90
+ disabled: () => isDisabledByEnv(process.env, CLIENT_REPORT_DISABLE_ENV),
91
+ fetchImpl: fetch,
92
+ apiKey: readApiKey,
93
+ baseUrl: getBaseUrl,
94
+ now: Date.now,
95
+ claimsDir: clientReportClaims()
96
+ });
97
+ var reportKey = (event) => `${event.kind}:${event.code}`;
98
+ var createClientErrorReporter = (deps) => {
99
+ const windowClaimedInProcess = /* @__PURE__ */ new Map();
100
+ const claimInProcess = (key, now) => {
101
+ if (windowClaimedInProcess.get(key) === reportWindowOf(now)) return false;
102
+ windowClaimedInProcess.set(key, reportWindowOf(now));
103
+ return true;
104
+ };
105
+ const claimReport = (key, now) => {
106
+ const claim = claimReportWindow(deps.claimsDir, key, now);
107
+ return claim === "unavailable" ? claimInProcess(key, now) : claim === "claimed";
108
+ };
109
+ return async (event) => {
110
+ try {
111
+ if (deps.disabled()) return;
112
+ const apiKey = deps.apiKey();
113
+ const now = deps.now();
114
+ if (!apiKey || !claimReport(reportKey(event), now)) return;
115
+ await deps.fetchImpl(`${deps.baseUrl()}${CLIENT_REPORT_PATH}`, {
116
+ method: "POST",
117
+ headers: { "Authorization": `Bearer ${apiKey}`, "Content-Type": "application/json" },
118
+ body: JSON.stringify({ ...event, occurredAt: new Date(now).toISOString() }),
119
+ signal: AbortSignal.timeout(CLIENT_REPORT_TIMEOUT_MS)
120
+ });
121
+ } catch {
122
+ return;
123
+ }
124
+ };
125
+ };
126
+ var processReporter = null;
127
+ var inFlightReports = /* @__PURE__ */ new Set();
128
+ var reportClientError = (event) => {
129
+ processReporter ??= createClientErrorReporter(defaultDeps());
130
+ const report = processReporter(event);
131
+ inFlightReports.add(report);
132
+ void report.finally(() => inFlightReports.delete(report));
133
+ return report;
134
+ };
135
+ var exitAfterClientReports = async (code) => {
136
+ await Promise.all(inFlightReports);
137
+ return process.exit(code);
138
+ };
139
+ var clientErrorKindOf = (error) => isNetworkFailure(error) ? "network" : "unexpected";
140
+ var writeDegraded = (subsystem, report) => {
141
+ process.stderr.write(`${degradedLine(subsystem, report)}
142
+ `);
143
+ void reportClientError({ kind: "degraded", code: `${subsystem}:${report.reason}` });
144
+ };
21
145
 
22
146
  // src/api.ts
23
147
  import { randomUUID } from "crypto";
@@ -169,6 +293,10 @@ var claimBlockedAction = async (apiKey, request, timeoutMs) => {
169
293
  };
170
294
 
171
295
  export {
296
+ reportClientError,
297
+ exitAfterClientReports,
298
+ clientErrorKindOf,
299
+ writeDegraded,
172
300
  isPolicyConfig,
173
301
  isAskUserResponse,
174
302
  isWaitForAnswerResponse,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  HOOK_HOLD_BUDGET_ENV,
3
3
  hookHoldBudgetProof
4
- } from "./chunk-5RGA636G.js";
4
+ } from "./chunk-VOP5U2VX.js";
5
5
 
6
6
  // src/hold-budget.ts
7
7
  var takeHookHoldBudget = (args = process.argv.slice(2), env = process.env) => {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  pusharyFetch
3
- } from "./chunk-UM5WXBKN.js";
3
+ } from "./chunk-EJVYEOKC.js";
4
4
  import {
5
5
  NetworkError
6
6
  } from "./chunk-7QLSKOSU.js";
@@ -9,11 +9,11 @@ import {
9
9
  } from "./chunk-KZERVKTD.js";
10
10
  import {
11
11
  getBaseUrl
12
- } from "./chunk-2M52CFVO.js";
12
+ } from "./chunk-FJCOOFT7.js";
13
13
  import {
14
14
  isValidApiKey,
15
15
  normalizeKeyScope
16
- } from "./chunk-5RGA636G.js";
16
+ } from "./chunk-VOP5U2VX.js";
17
17
 
18
18
  // src/session.ts
19
19
  var samePusharyAccount = (left, right) => left.kind === "ok" && right.kind === "ok" && left.identity.workspaceId !== "" && left.identity.workspaceId === right.identity.workspaceId && left.identity.siteId === right.identity.siteId;
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  keyCheckFromResponse
3
- } from "./chunk-XXLCYKVS.js";
3
+ } from "./chunk-I4I4UH62.js";
4
4
  import {
5
5
  installNetworkDefaults
6
- } from "./chunk-UM5WXBKN.js";
6
+ } from "./chunk-EJVYEOKC.js";
7
7
  import {
8
8
  getBaseUrl
9
- } from "./chunk-2M52CFVO.js";
9
+ } from "./chunk-FJCOOFT7.js";
10
10
 
11
11
  // src/retry.ts
12
12
  var isRetryable = (err) => {