@pushary/agent-hooks 1.9.157 → 1.9.161

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 (147) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +1 -0
  3. package/dist/{api-3C62HQDC.js → api-WHTSBK74.js} +15 -13
  4. package/dist/bin/pushary-audit.js +7 -7
  5. package/dist/bin/pushary-bell-hook.js +31 -31
  6. package/dist/bin/pushary-bell.js +16 -16
  7. package/dist/bin/pushary-calls.d.ts +1 -0
  8. package/dist/bin/pushary-calls.js +287 -0
  9. package/dist/bin/pushary-claude.js +37 -37
  10. package/dist/bin/pushary-clean.js +47 -45
  11. package/dist/bin/pushary-codex-bridge.js +27 -27
  12. package/dist/bin/pushary-codex-hook.js +61 -51
  13. package/dist/bin/pushary-codex-session.js +8 -8
  14. package/dist/bin/pushary-codex.js +19 -19
  15. package/dist/bin/pushary-connect.js +41 -40
  16. package/dist/bin/pushary-cowork.js +6 -6
  17. package/dist/bin/pushary-daemon.js +52 -51
  18. package/dist/bin/pushary-disconnect.js +39 -37
  19. package/dist/bin/pushary-display-hook.js +20 -1
  20. package/dist/bin/pushary-doctor.js +61 -59
  21. package/dist/bin/pushary-elicitation-hook.js +32 -32
  22. package/dist/bin/pushary-gemini-bridge.js +19 -19
  23. package/dist/bin/pushary-gemini-hook.js +36 -36
  24. package/dist/bin/pushary-hook.js +39 -38
  25. package/dist/bin/pushary-login.js +28 -28
  26. package/dist/bin/pushary-logout.js +34 -33
  27. package/dist/bin/pushary-mcp.js +15 -15
  28. package/dist/bin/pushary-mode.js +21 -21
  29. package/dist/bin/pushary-notification-hook.js +30 -30
  30. package/dist/bin/pushary-opencode-hook.js +399 -45
  31. package/dist/bin/pushary-permission-denied-hook.js +39 -38
  32. package/dist/bin/pushary-permission-hook.js +39 -38
  33. package/dist/bin/pushary-post-hook.js +31 -31
  34. package/dist/bin/pushary-prompt-hook.js +30 -30
  35. package/dist/bin/pushary-session-end-hook.js +30 -30
  36. package/dist/bin/pushary-session-start-hook.js +41 -40
  37. package/dist/bin/pushary-setup.js +73 -72
  38. package/dist/bin/pushary-stats.js +6 -6
  39. package/dist/bin/pushary-status.js +40 -39
  40. package/dist/bin/pushary-stop-hook.js +30 -30
  41. package/dist/bin/pushary-stopfailure-hook.js +30 -30
  42. package/dist/bin/pushary-suggestions.js +21 -21
  43. package/dist/bin/pushary-transcript-register.js +21 -21
  44. package/dist/bin/pushary-transcripts.js +32 -32
  45. package/dist/bin/pushary-upgrade.js +50 -49
  46. package/dist/bin/pushary-wait.js +23 -23
  47. package/dist/bin/pushary.js +10 -9
  48. package/dist/{chunk-2SHPCEH6.js → chunk-26GVUJMR.js} +5 -2
  49. package/dist/{chunk-UAYNQ2IG.js → chunk-2ABUBECK.js} +6 -6
  50. package/dist/{chunk-6NRFAP45.js → chunk-2PY5DJTC.js} +1 -1
  51. package/dist/{chunk-RF7HGOBC.js → chunk-3F6HE5AK.js} +3 -3
  52. package/dist/{chunk-5MWNWCCI.js → chunk-4ZNZS6FM.js} +8 -5
  53. package/dist/{chunk-KB7YWU7A.js → chunk-55AHQF63.js} +110 -0
  54. package/dist/{chunk-3XTH6EKH.js → chunk-5S66DHJS.js} +3 -3
  55. package/dist/{chunk-CHI57HS3.js → chunk-5UBV26GO.js} +3 -3
  56. package/dist/{chunk-V4OIPLSC.js → chunk-6NWESDKK.js} +4 -4
  57. package/dist/{chunk-RF35YTIF.js → chunk-6OSE2IRG.js} +2 -2
  58. package/dist/{chunk-G6SQOGSD.js → chunk-7AQTKVA6.js} +12 -7
  59. package/dist/{chunk-ANL74IBU.js → chunk-7IHVTLHK.js} +1 -1
  60. package/dist/{chunk-3EF7G5EV.js → chunk-7VXHWU7A.js} +4 -4
  61. package/dist/{chunk-MH4O453X.js → chunk-7WLKE7QN.js} +4 -3
  62. package/dist/{chunk-3UYTCDDY.js → chunk-ANYLSZN3.js} +24 -9
  63. package/dist/{chunk-GA5T3WEB.js → chunk-AT5ZLKMQ.js} +5 -5
  64. package/dist/{chunk-HXX4EFK3.js → chunk-ATI5XO3E.js} +4 -4
  65. package/dist/{chunk-TIOQ55VZ.js → chunk-AVGYUZVK.js} +6 -6
  66. package/dist/{chunk-6UGVZTRA.js → chunk-AVRRD6AY.js} +1 -1
  67. package/dist/{chunk-WCVANKUD.js → chunk-BGU56XCS.js} +1 -1
  68. package/dist/{chunk-DDSMTD4W.js → chunk-BTYHDCAP.js} +3 -3
  69. package/dist/{chunk-IQWMRFKD.js → chunk-DHUWAUVL.js} +1 -1
  70. package/dist/{chunk-W2GOSAFI.js → chunk-DHX5JZSH.js} +4 -4
  71. package/dist/{chunk-KOBIBSE6.js → chunk-DLZ6RK2P.js} +3 -3
  72. package/dist/{chunk-TWOSBIAW.js → chunk-DWMQZM52.js} +1 -1
  73. package/dist/{chunk-WDU4LEEW.js → chunk-E7K6YCWY.js} +6 -6
  74. package/dist/{chunk-7JAEIKBV.js → chunk-EGEZKJHX.js} +5 -5
  75. package/dist/{chunk-VRLYEBDN.js → chunk-F5NJUDGA.js} +78 -50
  76. package/dist/{chunk-ELF4NIIM.js → chunk-FZCEPG6J.js} +2 -2
  77. package/dist/{chunk-KURQ4KMV.js → chunk-G44FOBHN.js} +4 -4
  78. package/dist/{chunk-S6DJAYQW.js → chunk-GJA3KQ3T.js} +5 -5
  79. package/dist/{chunk-WIOLCW7W.js → chunk-GNHXDRO6.js} +1 -1
  80. package/dist/{chunk-C3HYWUZE.js → chunk-HHNC6FWO.js} +1 -1
  81. package/dist/{chunk-E2KAAKWU.js → chunk-HKCJZGAJ.js} +6 -6
  82. package/dist/{chunk-7HDQUTRK.js → chunk-HKI4RMZF.js} +8 -7
  83. package/dist/{chunk-C4K4KYOY.js → chunk-I5HXAELM.js} +5 -5
  84. package/dist/{chunk-MGT2V2AB.js → chunk-IGSSDODQ.js} +2 -2
  85. package/dist/{chunk-ICHKAH5Q.js → chunk-IHYKSPWH.js} +85 -8
  86. package/dist/chunk-J36DDPJV.js +18 -0
  87. package/dist/{chunk-QONYKXWP.js → chunk-KDHLOPSO.js} +1 -1
  88. package/dist/{chunk-O3NAHPCR.js → chunk-KKDKPWGM.js} +1 -1
  89. package/dist/{chunk-REUFDG7O.js → chunk-L2ADRR62.js} +5 -5
  90. package/dist/{chunk-F6ZBXV4G.js → chunk-LRTRIDOC.js} +1 -1
  91. package/dist/{chunk-4I4HAPT5.js → chunk-LVGRSC44.js} +5 -5
  92. package/dist/{chunk-UH5NAPWL.js → chunk-MGOBIHXH.js} +10 -10
  93. package/dist/{chunk-CV6G4IDZ.js → chunk-MPYQW4IV.js} +2 -2
  94. package/dist/{chunk-QBDCKECQ.js → chunk-N4OKAE65.js} +120 -32
  95. package/dist/{chunk-EQF6SSQL.js → chunk-ONMAG5BF.js} +2 -2
  96. package/dist/{chunk-CAZ5FMWP.js → chunk-OOODAKCC.js} +6 -6
  97. package/dist/chunk-OQAIMSHQ.js +885 -0
  98. package/dist/{chunk-MOX7IOGL.js → chunk-OSCZ4MNE.js} +7 -7
  99. package/dist/{chunk-6W6MZ53D.js → chunk-OXZ75E2Y.js} +4 -4
  100. package/dist/{chunk-O2DJWDVK.js → chunk-OZK75SFS.js} +11 -9
  101. package/dist/{chunk-WSPDIT2B.js → chunk-PXLWR4TG.js} +2 -2
  102. package/dist/{chunk-UJJ2OXFA.js → chunk-QLEFFGCN.js} +1 -1
  103. package/dist/{chunk-T3LSBTWU.js → chunk-R7NAG65X.js} +4 -4
  104. package/dist/{chunk-WDCS3RGI.js → chunk-R7RN3Z2T.js} +2 -2
  105. package/dist/{chunk-P5JV6YZW.js → chunk-RZBCXPOV.js} +14 -3
  106. package/dist/{chunk-JBF6A2X5.js → chunk-S6ARXVVZ.js} +1 -1
  107. package/dist/{chunk-R4DMHIOK.js → chunk-TYB2QGJD.js} +6 -6
  108. package/dist/{chunk-C74JHUD3.js → chunk-U36COV3Z.js} +11 -11
  109. package/dist/{chunk-PKU3WFT5.js → chunk-U3FVVMB3.js} +1 -1
  110. package/dist/{chunk-3FQJYA76.js → chunk-UH7GJHOO.js} +3 -3
  111. package/dist/chunk-UJT32RSQ.js +242 -0
  112. package/dist/{chunk-WIIMW5YO.js → chunk-UQTQ6HPO.js} +2 -0
  113. package/dist/{chunk-WWDWEVGT.js → chunk-UZTGEACF.js} +5 -5
  114. package/dist/{chunk-4RSJZOKB.js → chunk-VIS3EVRH.js} +1 -1
  115. package/dist/{chunk-5HMVXNFU.js → chunk-VYNC7EYV.js} +2 -2
  116. package/dist/{chunk-MEUAK5BK.js → chunk-W6FCSBTM.js} +2 -2
  117. package/dist/{chunk-PMEDJ4WM.js → chunk-WAFJGQSE.js} +39 -8
  118. package/dist/{chunk-25PVMWSM.js → chunk-WCXVPYSD.js} +1 -1
  119. package/dist/{chunk-5TCLBCUO.js → chunk-WNIDBPT2.js} +8 -8
  120. package/dist/{chunk-2NSPZZBJ.js → chunk-WTWBHE2Y.js} +42 -34
  121. package/dist/{chunk-UOVTXOSS.js → chunk-XWCLKWKP.js} +1 -1
  122. package/dist/{chunk-2LTRA6NA.js → chunk-Y23YO46U.js} +3 -3
  123. package/dist/{chunk-2N23JFER.js → chunk-Y553AEQU.js} +3 -3
  124. package/dist/{chunk-H6CL3T2S.js → chunk-Y6ILCLKE.js} +1 -1
  125. package/dist/{chunk-AKUYCHJU.js → chunk-YD45WNVQ.js} +1 -1
  126. package/dist/{chunk-44FDCO7M.js → chunk-YEB7YWW7.js} +13 -13
  127. package/dist/{chunk-BMR66K6T.js → chunk-YGHHDDIM.js} +4 -4
  128. package/dist/{chunk-KRI7BOND.js → chunk-Z5DOTAFI.js} +3 -3
  129. package/dist/{chunk-XHPTW6WL.js → chunk-ZIKSHD5M.js} +5 -3
  130. package/dist/{codex-app-cards-switch-MQIEZLSU.js → codex-app-cards-switch-DPCGWQSX.js} +14 -14
  131. package/dist/{codex-card-routing-UTWTJ6YQ.js → codex-card-routing-NFIEH66Q.js} +2 -2
  132. package/dist/{codex-desktop-launch-A6GX6F54.js → codex-desktop-launch-MARNBY23.js} +1 -1
  133. package/dist/{codex-session-launch-AVEFGOT7.js → codex-session-launch-LSNU7CUV.js} +23 -23
  134. package/dist/{config-YGUXX5GB.js → config-5D34OAYM.js} +4 -4
  135. package/dist/{global-upgrade-HLXPTFDU.js → global-upgrade-5XBO6FYU.js} +11 -11
  136. package/dist/{identity-CAC763RQ.js → identity-6QEFK7PW.js} +5 -5
  137. package/dist/{live-capabilities-WRI22INV.js → live-capabilities-6KOGY6KM.js} +5 -5
  138. package/dist/{paths-DNXBDJJH.js → paths-7M6V62NO.js} +4 -4
  139. package/dist/reapply-ZECM5JRX.js +69 -0
  140. package/dist/src/index.d.ts +6 -1
  141. package/dist/src/index.js +39 -38
  142. package/dist/{upgrade-lock-CRW26OIW.js → upgrade-lock-DI4JY2CU.js} +5 -5
  143. package/dist/usage-X4BIHYR5.js +11 -0
  144. package/package.json +2 -1
  145. package/dist/chunk-BO4HRAY7.js +0 -593
  146. package/dist/reapply-5ZNMLEKV.js +0 -68
  147. package/dist/usage-AWWCZ7H7.js +0 -11
@@ -1,39 +1,56 @@
1
1
  #!/usr/bin/env node
2
+ import {
3
+ launcherIsGone
4
+ } from "../chunk-U4P4NDVB.js";
5
+ import {
6
+ OPENCODE_FAILED_EVENT,
7
+ OPENCODE_QUESTION_ANSWERED,
8
+ OPENCODE_QUESTION_CANCELLED,
9
+ OPENCODE_QUESTION_EVENT,
10
+ OPENCODE_QUESTION_UNDELIVERED_EVENT,
11
+ OPENCODE_QUESTION_UNREACHABLE_EVENT,
12
+ OPENCODE_SUBAGENT_IDLE_EVENT
13
+ } from "../chunk-OQAIMSHQ.js";
2
14
  import {
3
15
  parseOpenCodeHookInput,
4
16
  pushQuestionAndWait,
5
17
  scopeQuestionOf
6
- } from "../chunk-5MWNWCCI.js";
18
+ } from "../chunk-4ZNZS6FM.js";
19
+ import {
20
+ askAgentQuestionWhileOpen
21
+ } from "../chunk-WTWBHE2Y.js";
7
22
  import {
8
23
  reportMachineDenial
9
- } from "../chunk-3XTH6EKH.js";
24
+ } from "../chunk-5S66DHJS.js";
10
25
  import {
11
26
  isGatingMoment,
12
27
  recordKeylessMoment
13
- } from "../chunk-C3HYWUZE.js";
28
+ } from "../chunk-HHNC6FWO.js";
14
29
  import {
15
30
  readHookInput
16
- } from "../chunk-7JAEIKBV.js";
17
- import "../chunk-3EF7G5EV.js";
31
+ } from "../chunk-EGEZKJHX.js";
32
+ import "../chunk-7VXHWU7A.js";
18
33
  import {
19
34
  announceSubscriptionRequired,
20
35
  isDeferAnswer
21
- } from "../chunk-IQWMRFKD.js";
22
- import "../chunk-UH5NAPWL.js";
36
+ } from "../chunk-DHUWAUVL.js";
37
+ import "../chunk-MGOBIHXH.js";
23
38
  import "../chunk-WHB622LP.js";
24
- import "../chunk-4I4HAPT5.js";
25
- import "../chunk-5TCLBCUO.js";
26
- import "../chunk-BMR66K6T.js";
39
+ import "../chunk-LVGRSC44.js";
40
+ import "../chunk-WNIDBPT2.js";
41
+ import "../chunk-YGHHDDIM.js";
27
42
  import {
28
43
  DEFAULT_SESSION,
29
44
  fetchModeState,
30
45
  getPolicy,
31
46
  handlePostToolUse,
32
47
  handleStop,
48
+ handleStopFailure,
49
+ handleSubagentStop,
33
50
  handleUserPrompt,
34
51
  policyRequestFor,
35
52
  readLastPrompt
36
- } from "../chunk-QBDCKECQ.js";
53
+ } from "../chunk-N4OKAE65.js";
37
54
  import {
38
55
  HOOK_FALLBACK_MAX,
39
56
  OPENCODE_TOOL_NAMES,
@@ -43,50 +60,56 @@ import {
43
60
  deriveToolTarget,
44
61
  describeToolCall,
45
62
  scopePathFor
46
- } from "../chunk-2SHPCEH6.js";
47
- import "../chunk-6UGVZTRA.js";
48
- import "../chunk-6NRFAP45.js";
63
+ } from "../chunk-26GVUJMR.js";
64
+ import "../chunk-AVRRD6AY.js";
65
+ import "../chunk-2PY5DJTC.js";
49
66
  import "../chunk-YPY4YCIZ.js";
50
- import "../chunk-CHI57HS3.js";
67
+ import "../chunk-5UBV26GO.js";
51
68
  import "../chunk-352FIVVH.js";
52
- import "../chunk-AKUYCHJU.js";
69
+ import "../chunk-YD45WNVQ.js";
70
+ import "../chunk-Y6ILCLKE.js";
53
71
  import {
54
72
  repoKeyFor
55
- } from "../chunk-UJJ2OXFA.js";
73
+ } from "../chunk-QLEFFGCN.js";
56
74
  import {
75
+ askingProcessWaits,
57
76
  cancelQuestion,
58
77
  exitAfterClientReports,
59
78
  isDecisionStopped,
60
79
  isQuestionLimitRefusal,
61
80
  sendNotification
62
- } from "../chunk-ICHKAH5Q.js";
81
+ } from "../chunk-IHYKSPWH.js";
82
+ import "../chunk-KDHLOPSO.js";
63
83
  import "../chunk-POFBE6ZY.js";
64
84
  import {
65
85
  SubscriptionRequiredError
66
- } from "../chunk-MOX7IOGL.js";
67
- import "../chunk-C4K4KYOY.js";
68
- import "../chunk-E2KAAKWU.js";
69
- import "../chunk-H6CL3T2S.js";
70
- import "../chunk-QONYKXWP.js";
71
- import "../chunk-TWOSBIAW.js";
86
+ } from "../chunk-OSCZ4MNE.js";
87
+ import "../chunk-DWMQZM52.js";
88
+ import "../chunk-I5HXAELM.js";
89
+ import "../chunk-HKCJZGAJ.js";
72
90
  import {
73
91
  getMachineId
74
- } from "../chunk-4RSJZOKB.js";
75
- import "../chunk-YU2EUD7O.js";
76
- import "../chunk-2LTRA6NA.js";
77
- import "../chunk-ELF4NIIM.js";
78
- import "../chunk-MH4O453X.js";
79
- import "../chunk-PMEDJ4WM.js";
92
+ } from "../chunk-VIS3EVRH.js";
93
+ import "../chunk-Y23YO46U.js";
94
+ import "../chunk-FZCEPG6J.js";
95
+ import "../chunk-7WLKE7QN.js";
96
+ import "../chunk-WAFJGQSE.js";
80
97
  import {
81
98
  getApiKey
82
- } from "../chunk-ANL74IBU.js";
99
+ } from "../chunk-7IHVTLHK.js";
100
+ import "../chunk-YU2EUD7O.js";
101
+ import "../chunk-TODDEIYG.js";
83
102
  import {
84
103
  EXIT
85
104
  } from "../chunk-BG4HHB7E.js";
86
- import "../chunk-TODDEIYG.js";
87
- import "../chunk-P5JV6YZW.js";
88
- import "../chunk-WIIMW5YO.js";
105
+ import "../chunk-RZBCXPOV.js";
106
+ import "../chunk-UQTQ6HPO.js";
89
107
  import {
108
+ AGENT_QUESTION_DESCRIPTION_MAX,
109
+ AGENT_QUESTION_HEADER_MAX,
110
+ AGENT_QUESTION_OPTION_MAX,
111
+ AGENT_QUESTION_TOOL,
112
+ ASK_QUESTION_MAX,
90
113
  DECISION_STOP_REASON,
91
114
  HOOK_BUDGETS,
92
115
  KILL_REASON,
@@ -96,17 +119,141 @@ import {
96
119
  effectiveWaitSeconds,
97
120
  gateOutputFor,
98
121
  hookMaxWaitSeconds,
122
+ isAgentQuestionSet,
123
+ isRecord,
124
+ questionHandedToTheTerminal,
99
125
  questionLimitHandBack,
100
126
  redactSecrets,
101
127
  refusesWhenUnanswered,
102
128
  resolveGate,
129
+ standingDenyOfSubagentAlias,
103
130
  unapprovedScopeReason
104
- } from "../chunk-KB7YWU7A.js";
131
+ } from "../chunk-55AHQF63.js";
105
132
  import "../chunk-MLKGABMK.js";
106
133
 
107
134
  // bin/pushary-opencode-hook.ts
108
135
  import { basename } from "path";
109
136
 
137
+ // src/opencode-question.ts
138
+ var OPENCODE_BOOLEAN_YES = "Yes";
139
+ var OPENCODE_BOOLEAN_NO = "No";
140
+ var STRING_CONSTRAINTS = ["format", "pattern", "minLength", "maxLength"];
141
+ var textOf = (value) => typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
142
+ var formOptionOf = (raw) => {
143
+ if (!isRecord(raw) || typeof raw.value !== "string" || typeof raw.label !== "string" || raw.label.length === 0) return null;
144
+ return {
145
+ value: raw.value,
146
+ label: raw.label,
147
+ ...typeof raw.description === "string" && raw.description.length > 0 ? { description: raw.description } : {}
148
+ };
149
+ };
150
+ var formOptionsOf = (raw) => {
151
+ if (raw === void 0) return [];
152
+ if (!Array.isArray(raw)) return null;
153
+ const options = raw.map(formOptionOf);
154
+ return options.every((option) => option !== null) ? options : null;
155
+ };
156
+ var fitsThePhone = (option) => option.label.length <= AGENT_QUESTION_OPTION_MAX;
157
+ var phoneOptionOf = (option) => ({
158
+ label: option.label,
159
+ ...option.description ? { description: option.description.slice(0, AGENT_QUESTION_DESCRIPTION_MAX) } : {}
160
+ });
161
+ var questionTextOf = (field, formTitle) => (textOf(field.description) ?? textOf(field.title) ?? formTitle)?.slice(0, ASK_QUESTION_MAX);
162
+ var headerOf = (field, question) => {
163
+ const title = textOf(field.title);
164
+ return title && title !== question ? title.slice(0, AGENT_QUESTION_HEADER_MAX) : void 0;
165
+ };
166
+ var hasStringConstraints = (field) => STRING_CONSTRAINTS.some((constraint) => field[constraint] !== void 0);
167
+ var limitsHowManyArePicked = (field) => field.maxItems !== void 0 || typeof field.minItems === "number" && field.minItems > 1;
168
+ var BOOLEAN_OPTIONS = [
169
+ { value: OPENCODE_BOOLEAN_YES, label: OPENCODE_BOOLEAN_YES },
170
+ { value: OPENCODE_BOOLEAN_NO, label: OPENCODE_BOOLEAN_NO }
171
+ ];
172
+ var stringShapeOf = (field, options) => {
173
+ if (options.length > 0) return { kind: "select", options, allowOther: field.custom === true };
174
+ return hasStringConstraints(field) ? null : { kind: "input", options, allowOther: true };
175
+ };
176
+ var fieldShapeOf = (field) => {
177
+ const options = formOptionsOf(field.options);
178
+ if (options === null || !options.every(fitsThePhone)) return null;
179
+ switch (field.type) {
180
+ case "string":
181
+ return stringShapeOf(field, options);
182
+ case "multiselect":
183
+ return options.length > 0 && !limitsHowManyArePicked(field) ? { kind: "multiselect", options, allowOther: field.custom === true } : null;
184
+ case "boolean":
185
+ return { kind: "boolean", options: BOOLEAN_OPTIONS, allowOther: false };
186
+ default:
187
+ return null;
188
+ }
189
+ };
190
+ var labelValues = (options) => new Map(options.map((option) => [option.label, option.value]));
191
+ var onlyFieldOf = (form) => {
192
+ const fields = form.fields;
193
+ if (!Array.isArray(fields) || fields.length !== 1) return null;
194
+ const [field] = fields;
195
+ if (!isRecord(field) || typeof field.key !== "string" || field.key.length === 0 || field.hidden === true) return null;
196
+ return { key: field.key, field };
197
+ };
198
+ var openCodeQuestionOf = (form) => {
199
+ if (!isRecord(form)) return null;
200
+ const only = onlyFieldOf(form);
201
+ if (!only) return null;
202
+ const { key, field } = only;
203
+ const shape = fieldShapeOf(field);
204
+ const text = questionTextOf(field, textOf(form.title));
205
+ if (!shape || !text) return null;
206
+ const header = headerOf(field, text);
207
+ const question = {
208
+ question: text,
209
+ ...header ? { header } : {},
210
+ multiSelect: shape.kind === "multiselect",
211
+ allowOther: shape.allowOther,
212
+ options: shape.options.map(phoneOptionOf)
213
+ };
214
+ const valueOfLabel = labelValues(shape.options);
215
+ if (valueOfLabel.size !== shape.options.length || !isAgentQuestionSet([question])) return null;
216
+ return { fieldKey: key, kind: shape.kind, question, valueOfLabel };
217
+ };
218
+ var pickedLabelsOf = (answer) => {
219
+ try {
220
+ const parsed = JSON.parse(answer);
221
+ return Array.isArray(parsed) && parsed.every((label) => typeof label === "string") ? parsed : null;
222
+ } catch {
223
+ return null;
224
+ }
225
+ };
226
+ var optionValueOrTyped = (asked, answer) => asked.valueOfLabel.get(answer) ?? (asked.question.allowOther ? answer : null);
227
+ var multiselectValueOf = (asked, answer) => {
228
+ const labels = pickedLabelsOf(answer);
229
+ if (!labels) return asked.question.allowOther ? [answer] : null;
230
+ const values = labels.map((label) => asked.valueOfLabel.get(label));
231
+ return values.length > 0 && values.every((value) => value !== void 0) ? values : null;
232
+ };
233
+ var booleanValueOf = (answer) => {
234
+ if (answer === OPENCODE_BOOLEAN_YES) return true;
235
+ if (answer === OPENCODE_BOOLEAN_NO) return false;
236
+ return null;
237
+ };
238
+ var formValueOf = (asked, answer) => {
239
+ switch (asked.kind) {
240
+ case "select":
241
+ return optionValueOrTyped(asked, answer);
242
+ case "multiselect":
243
+ return multiselectValueOf(asked, answer);
244
+ case "input":
245
+ return answer;
246
+ case "boolean":
247
+ return booleanValueOf(answer);
248
+ }
249
+ };
250
+ var openCodeFormAnswerOf = (asked, answers) => {
251
+ const answer = answers[asked.question.question];
252
+ if (typeof answer !== "string" || answer.trim().length === 0) return null;
253
+ const value = formValueOf(asked, answer);
254
+ return value === null ? null : { [asked.fieldKey]: value };
255
+ };
256
+
110
257
  // src/opencode-adapter.ts
111
258
  var OPENCODE_AGENT = { type: "opencode", label: "OpenCode" };
112
259
  var toOpenCodePolicyLookup = (toolName, toolInput) => ({
@@ -135,11 +282,37 @@ var toOpenCodeWire = (decision) => {
135
282
  );
136
283
  return output ?? null;
137
284
  };
285
+ var openCodeQuestionPass = () => ({ kind: "pass" });
286
+ var openCodeQuestionCancel = (reason) => ({ kind: "cancelled", reason });
287
+ var openCodeQuestionAnswered = (answer) => answer ? { kind: "answered", answer } : openCodeQuestionPass();
288
+ var openCodeQuestionDecisionOf = (asked, outcome) => {
289
+ switch (outcome.kind) {
290
+ case "answered":
291
+ return openCodeQuestionAnswered(openCodeFormAnswerOf(asked, outcome.answers));
292
+ case "stopped":
293
+ return openCodeQuestionCancel(DECISION_STOP_REASON);
294
+ case "unavailable":
295
+ case "unanswered":
296
+ return openCodeQuestionPass();
297
+ }
298
+ };
299
+ var toOpenCodeQuestionWire = (decision) => {
300
+ switch (decision.kind) {
301
+ case "answered":
302
+ return { status: OPENCODE_QUESTION_ANSWERED, answer: decision.answer };
303
+ case "cancelled":
304
+ return { status: OPENCODE_QUESTION_CANCELLED, reason: decision.reason };
305
+ case "pass":
306
+ return null;
307
+ }
308
+ };
138
309
 
139
310
  // bin/pushary-opencode-hook.ts
140
311
  var START_MS = Date.now();
141
312
  var outstanding;
142
- var agentNameFor = (input) => `${OPENCODE_AGENT.label} - ${basename(input.cwd ?? process.cwd())}`;
313
+ var questionBeingAsked;
314
+ var projectNameFor = (input) => basename(input.project_dir ?? input.cwd ?? process.cwd());
315
+ var agentNameFor = (input) => `${OPENCODE_AGENT.label} - ${projectNameFor(input)}`;
143
316
  var describeFor = (input, lookup) => {
144
317
  if (lookup.tool) return describeToolCall(lookup.tool, lookup.input, "hook");
145
318
  return redactSecrets(input.title ?? "").trim().slice(0, HOOK_FALLBACK_MAX) || UNNAMED_ACTION;
@@ -148,7 +321,7 @@ var pushQuestion = async (apiKey, input, lookup, waitSeconds, mode, scope, pollI
148
321
  const description = describeFor(input, lookup);
149
322
  const pushed = await pushQuestionAndWait(apiKey, {
150
323
  description,
151
- projectName: basename(input.cwd ?? process.cwd()),
324
+ projectName: projectNameFor(input),
152
325
  agentName: agentNameFor(input),
153
326
  sessionId: input.session_id,
154
327
  toolName: lookup.tool,
@@ -248,7 +421,7 @@ var decidePermission = async (input) => {
248
421
  recordKeylessMoment({
249
422
  ts: Date.now(),
250
423
  tool: lookup.tool,
251
- project: basename(input.cwd ?? process.cwd()),
424
+ project: projectNameFor(input),
252
425
  sessionId: input.session_id
253
426
  });
254
427
  }
@@ -268,16 +441,18 @@ var decidePermission = async (input) => {
268
441
  input.session_id
269
442
  );
270
443
  const scopePath = modeState.scope ? scopePathFor(lookup.tool, lookup.input, input.cwd) : void 0;
271
- const verdict = resolveGate({
444
+ const gateInputFor = (toolName) => ({
272
445
  modeState,
273
446
  config,
274
- toolName: lookup.tool,
447
+ toolName,
275
448
  toolInputs: [lookup.input],
276
449
  scopePaths: scopePath ? [scopePath] : [],
277
450
  cwd: input.cwd,
278
451
  repoKey: repoKeyFor(input.cwd),
279
452
  sessionId: input.session_id
280
453
  });
454
+ const asCalled = resolveGate(gateInputFor(lookup.tool));
455
+ const verdict = asCalled.kind === "kill" || asCalled.kind === "deny" ? asCalled : standingDenyOfSubagentAlias(lookup.tool, (toolName) => resolveGate(gateInputFor(toolName))) ?? asCalled;
281
456
  if (verdict.kind === "kill" || verdict.kind === "deny") {
282
457
  await reportMachineDenial({ ...input, tool_name: lookup.tool, tool_input: lookup.input }, verdict, OPENCODE_AGENT);
283
458
  return openCodeDeny(verdict.kind === "kill" ? KILL_REASON : verdict.reason);
@@ -305,6 +480,154 @@ var decidePermission = async (input) => {
305
480
  return openCodePass();
306
481
  }
307
482
  };
483
+ var OPENCODE_QUESTION_NOTIFY_TITLE = "Agent has a question";
484
+ var questionToolInput = (asked) => ({ questions: [asked.question] });
485
+ var recordKeylessQuestion = (input) => {
486
+ try {
487
+ recordKeylessMoment({
488
+ ts: Date.now(),
489
+ tool: AGENT_QUESTION_TOOL,
490
+ project: projectNameFor(input),
491
+ sessionId: input.session_id
492
+ });
493
+ } catch {
494
+ }
495
+ };
496
+ var notifyQuestion = async (apiKey, input, asked) => {
497
+ try {
498
+ await sendNotification(apiKey, {
499
+ title: OPENCODE_QUESTION_NOTIFY_TITLE,
500
+ body: redactSecrets(asked.question.question).trim().slice(0, HOOK_FALLBACK_MAX),
501
+ agentName: agentNameFor(input),
502
+ sessionId: input.session_id,
503
+ machineId: getMachineId()
504
+ });
505
+ } catch {
506
+ }
507
+ };
508
+ var ASKING_PROCESS = process.ppid;
509
+ var openCodeStillAsks = () => askingProcessWaits(ASKING_PROCESS, process.ppid, launcherIsGone);
510
+ var killIsOn = async (apiKey, sessionId) => {
511
+ try {
512
+ return (await fetchModeState(apiKey, sessionId)).kill === true;
513
+ } catch {
514
+ return false;
515
+ }
516
+ };
517
+ var endedWithoutTheirAnswer = (outcome) => outcome.kind === "unanswered" || outcome.kind === "unavailable";
518
+ var askQuestionOnThePhone = async (apiKey, input, asked) => {
519
+ let questionCreated = () => {
520
+ };
521
+ questionBeingAsked = { apiKey, created: new Promise((resolve) => {
522
+ questionCreated = resolve;
523
+ }) };
524
+ const outcome = await askAgentQuestionWhileOpen(apiKey, {
525
+ toolName: AGENT_QUESTION_TOOL,
526
+ agentName: agentNameFor(input),
527
+ projectName: projectNameFor(input),
528
+ sessionId: input.session_id,
529
+ toolUseId: input.form_id,
530
+ onQuestionCreated: (correlationId) => {
531
+ outstanding = { apiKey, correlationId };
532
+ questionCreated(correlationId);
533
+ }
534
+ }, asked.question, openCodeStillAsks);
535
+ questionCreated(null);
536
+ questionBeingAsked = void 0;
537
+ outstanding = void 0;
538
+ if (endedWithoutTheirAnswer(outcome) && await killIsOn(apiKey, input.session_id)) return openCodeQuestionCancel(KILL_REASON);
539
+ return openCodeQuestionDecisionOf(asked, outcome);
540
+ };
541
+ var OPENCODE_ANSWER_UNDELIVERED_TITLE = "Answer this in OpenCode";
542
+ var OPENCODE_ANSWER_UNDELIVERED_NOTE = "OpenCode did not take the answer from your phone.";
543
+ var notifyUndeliveredAnswer = async (input) => {
544
+ const asked = openCodeQuestionOf(input.form);
545
+ if (!asked) return;
546
+ try {
547
+ await sendNotification(getApiKey(), {
548
+ title: OPENCODE_ANSWER_UNDELIVERED_TITLE,
549
+ body: `${redactSecrets(asked.question.question).trim().slice(0, HOOK_FALLBACK_MAX)} ${OPENCODE_ANSWER_UNDELIVERED_NOTE}`,
550
+ agentName: agentNameFor(input),
551
+ sessionId: input.session_id,
552
+ machineId: getMachineId()
553
+ });
554
+ } catch {
555
+ }
556
+ };
557
+ var questionGateOf = async (apiKey, input, asked) => {
558
+ const modeState = await fetchModeState(apiKey, input.session_id);
559
+ const policyRequest = policyRequestFor(OPENCODE_AGENT.type);
560
+ const config = await getPolicy(
561
+ apiKey,
562
+ modeState.policyVersion,
563
+ policyRequest.agent,
564
+ policyRequest.repoAware,
565
+ input.session_id
566
+ );
567
+ const toolInput = questionToolInput(asked);
568
+ const verdict = resolveGate({
569
+ modeState,
570
+ config,
571
+ toolName: AGENT_QUESTION_TOOL,
572
+ toolInputs: [toolInput],
573
+ scopePaths: [],
574
+ cwd: input.cwd,
575
+ repoKey: repoKeyFor(input.cwd),
576
+ sessionId: input.session_id
577
+ });
578
+ return { modeState, toolInput, verdict };
579
+ };
580
+ var questionReachesThePerson = (verdict, modeState) => verdict.kind === "gate" && !questionHandedToTheTerminal(AGENT_QUESTION_TOOL, modeState) && verdict.policy.mode !== "terminal_only";
581
+ var OPENCODE_QUESTION_UNREACHABLE_TITLE = "OpenCode is asking";
582
+ var SENTENCE_END = /[.?!]$/;
583
+ var asSentence = (text) => SENTENCE_END.test(text) ? text : `${text}.`;
584
+ var notifyUnreachableQuestion = async (input) => {
585
+ const asked = openCodeQuestionOf(input.form);
586
+ if (!asked) return;
587
+ try {
588
+ const apiKey = getApiKey();
589
+ const { modeState, verdict } = await questionGateOf(apiKey, input, asked);
590
+ if (!questionReachesThePerson(verdict, modeState)) return;
591
+ await sendNotification(apiKey, {
592
+ title: OPENCODE_QUESTION_UNREACHABLE_TITLE,
593
+ body: `OpenCode is asking: ${asSentence(redactSecrets(asked.question.question).trim().slice(0, HOOK_FALLBACK_MAX))} Answer it in OpenCode.`,
594
+ agentName: agentNameFor(input),
595
+ sessionId: input.session_id,
596
+ machineId: getMachineId()
597
+ });
598
+ } catch {
599
+ }
600
+ };
601
+ var decideQuestion = async (input) => {
602
+ const asked = openCodeQuestionOf(input.form);
603
+ if (!asked) return openCodeQuestionPass();
604
+ let apiKey;
605
+ try {
606
+ apiKey = getApiKey();
607
+ } catch {
608
+ recordKeylessQuestion(input);
609
+ return openCodeQuestionPass();
610
+ }
611
+ try {
612
+ const { modeState, toolInput, verdict } = await questionGateOf(apiKey, input, asked);
613
+ if (verdict.kind === "kill" || verdict.kind === "deny") {
614
+ await reportMachineDenial({ ...input, tool_name: AGENT_QUESTION_TOOL, tool_input: toolInput }, verdict, OPENCODE_AGENT);
615
+ return openCodeQuestionCancel(verdict.kind === "kill" ? KILL_REASON : verdict.reason);
616
+ }
617
+ if (verdict.kind !== "gate" || questionHandedToTheTerminal(AGENT_QUESTION_TOOL, modeState)) return openCodeQuestionPass();
618
+ switch (verdict.policy.mode) {
619
+ case "terminal_only":
620
+ return openCodeQuestionPass();
621
+ case "notify_only":
622
+ await notifyQuestion(apiKey, input, asked);
623
+ return openCodeQuestionPass();
624
+ default:
625
+ return await askQuestionOnThePhone(apiKey, input, asked);
626
+ }
627
+ } catch {
628
+ return openCodeQuestionPass();
629
+ }
630
+ };
308
631
  var withdrawn = false;
309
632
  var emit = (wire) => {
310
633
  if (!wire || withdrawn) return;
@@ -313,16 +636,24 @@ var emit = (wire) => {
313
636
  } catch {
314
637
  }
315
638
  };
639
+ var WITHDRAW_TIMEOUT_MS = 3e3;
640
+ var ASK_IN_FLIGHT_GRACE_MS = 6e4;
641
+ var createdWithin = (created, ms) => Promise.race([created, new Promise((resolve) => setTimeout(() => resolve(null), ms).unref())]);
642
+ var questionToWithdraw = async () => {
643
+ if (outstanding) return outstanding;
644
+ const asking = questionBeingAsked;
645
+ if (!asking) return void 0;
646
+ const correlationId = await createdWithin(asking.created, ASK_IN_FLIGHT_GRACE_MS);
647
+ return correlationId ? { apiKey: asking.apiKey, correlationId } : void 0;
648
+ };
316
649
  var withdrawAndExit = () => {
317
650
  withdrawn = true;
318
- const pending = outstanding;
319
- outstanding = void 0;
320
- if (!pending) {
651
+ if (!outstanding && !questionBeingAsked) {
321
652
  process.exit(0);
322
653
  }
323
- cancelQuestion(pending.apiKey, pending.correlationId).catch(() => {
654
+ void questionToWithdraw().then((pending) => pending ? cancelQuestion(pending.apiKey, pending.correlationId) : void 0).catch(() => {
324
655
  }).finally(() => process.exit(0));
325
- setTimeout(() => process.exit(0), 3e3).unref();
656
+ setTimeout(() => process.exit(0), (questionBeingAsked ? ASK_IN_FLIGHT_GRACE_MS : 0) + WITHDRAW_TIMEOUT_MS).unref();
326
657
  };
327
658
  var main = async () => {
328
659
  process.on("SIGTERM", withdrawAndExit);
@@ -335,6 +666,15 @@ var main = async () => {
335
666
  case OPENCODE_APPROVAL_EVENT:
336
667
  emit(toOpenCodeWire(await decidePermission(input)));
337
668
  break;
669
+ case OPENCODE_QUESTION_EVENT:
670
+ emit(toOpenCodeQuestionWire(await decideQuestion(input)));
671
+ break;
672
+ case OPENCODE_QUESTION_UNDELIVERED_EVENT:
673
+ await notifyUndeliveredAnswer(input);
674
+ break;
675
+ case OPENCODE_QUESTION_UNREACHABLE_EVENT:
676
+ await notifyUnreachableQuestion(input);
677
+ break;
338
678
  case "tool.execute.after": {
339
679
  const lookup = toOpenCodePolicyLookup(input.tool_name ?? "", input.tool_input ?? {});
340
680
  await handlePostToolUse({
@@ -359,6 +699,20 @@ var main = async () => {
359
699
  session_id: input.session_id
360
700
  }, OPENCODE_AGENT);
361
701
  break;
702
+ case OPENCODE_SUBAGENT_IDLE_EVENT:
703
+ await handleSubagentStop({
704
+ cwd: input.cwd,
705
+ session_id: input.session_id,
706
+ agent_id: input.agent_id
707
+ }, OPENCODE_AGENT);
708
+ break;
709
+ case OPENCODE_FAILED_EVENT:
710
+ await handleStopFailure({
711
+ cwd: input.cwd,
712
+ session_id: input.session_id,
713
+ error: input.error
714
+ }, OPENCODE_AGENT);
715
+ break;
362
716
  default:
363
717
  break;
364
718
  }
@@ -1,54 +1,55 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  handlePermissionDenied
4
- } from "../chunk-VRLYEBDN.js";
5
- import "../chunk-5HMVXNFU.js";
6
- import "../chunk-WSPDIT2B.js";
4
+ } from "../chunk-F5NJUDGA.js";
5
+ import "../chunk-VYNC7EYV.js";
6
+ import "../chunk-PXLWR4TG.js";
7
7
  import {
8
8
  takeHookHoldBudget
9
- } from "../chunk-25PVMWSM.js";
10
- import "../chunk-2NSPZZBJ.js";
11
- import "../chunk-3XTH6EKH.js";
12
- import "../chunk-C3HYWUZE.js";
9
+ } from "../chunk-WCXVPYSD.js";
10
+ import "../chunk-J36DDPJV.js";
11
+ import "../chunk-WTWBHE2Y.js";
12
+ import "../chunk-5S66DHJS.js";
13
+ import "../chunk-HHNC6FWO.js";
13
14
  import {
14
15
  readHookInput
15
- } from "../chunk-7JAEIKBV.js";
16
- import "../chunk-3EF7G5EV.js";
17
- import "../chunk-IQWMRFKD.js";
18
- import "../chunk-UH5NAPWL.js";
16
+ } from "../chunk-EGEZKJHX.js";
17
+ import "../chunk-7VXHWU7A.js";
18
+ import "../chunk-DHUWAUVL.js";
19
+ import "../chunk-MGOBIHXH.js";
19
20
  import "../chunk-WHB622LP.js";
20
- import "../chunk-4I4HAPT5.js";
21
- import "../chunk-5TCLBCUO.js";
22
- import "../chunk-BMR66K6T.js";
23
- import "../chunk-QBDCKECQ.js";
24
- import "../chunk-2SHPCEH6.js";
25
- import "../chunk-6UGVZTRA.js";
26
- import "../chunk-6NRFAP45.js";
21
+ import "../chunk-LVGRSC44.js";
22
+ import "../chunk-WNIDBPT2.js";
23
+ import "../chunk-YGHHDDIM.js";
24
+ import "../chunk-N4OKAE65.js";
25
+ import "../chunk-26GVUJMR.js";
26
+ import "../chunk-AVRRD6AY.js";
27
+ import "../chunk-2PY5DJTC.js";
27
28
  import "../chunk-YPY4YCIZ.js";
28
- import "../chunk-CHI57HS3.js";
29
+ import "../chunk-5UBV26GO.js";
29
30
  import "../chunk-352FIVVH.js";
30
- import "../chunk-AKUYCHJU.js";
31
- import "../chunk-UJJ2OXFA.js";
32
- import "../chunk-ICHKAH5Q.js";
31
+ import "../chunk-YD45WNVQ.js";
32
+ import "../chunk-Y6ILCLKE.js";
33
+ import "../chunk-QLEFFGCN.js";
34
+ import "../chunk-IHYKSPWH.js";
35
+ import "../chunk-KDHLOPSO.js";
33
36
  import "../chunk-POFBE6ZY.js";
34
- import "../chunk-MOX7IOGL.js";
35
- import "../chunk-C4K4KYOY.js";
36
- import "../chunk-E2KAAKWU.js";
37
- import "../chunk-H6CL3T2S.js";
38
- import "../chunk-QONYKXWP.js";
39
- import "../chunk-TWOSBIAW.js";
40
- import "../chunk-4RSJZOKB.js";
37
+ import "../chunk-OSCZ4MNE.js";
38
+ import "../chunk-DWMQZM52.js";
39
+ import "../chunk-I5HXAELM.js";
40
+ import "../chunk-HKCJZGAJ.js";
41
+ import "../chunk-VIS3EVRH.js";
42
+ import "../chunk-Y23YO46U.js";
43
+ import "../chunk-FZCEPG6J.js";
44
+ import "../chunk-7WLKE7QN.js";
45
+ import "../chunk-WAFJGQSE.js";
46
+ import "../chunk-7IHVTLHK.js";
41
47
  import "../chunk-YU2EUD7O.js";
42
- import "../chunk-2LTRA6NA.js";
43
- import "../chunk-ELF4NIIM.js";
44
- import "../chunk-MH4O453X.js";
45
- import "../chunk-PMEDJ4WM.js";
46
- import "../chunk-ANL74IBU.js";
47
- import "../chunk-BG4HHB7E.js";
48
48
  import "../chunk-TODDEIYG.js";
49
- import "../chunk-P5JV6YZW.js";
50
- import "../chunk-WIIMW5YO.js";
51
- import "../chunk-KB7YWU7A.js";
49
+ import "../chunk-BG4HHB7E.js";
50
+ import "../chunk-RZBCXPOV.js";
51
+ import "../chunk-UQTQ6HPO.js";
52
+ import "../chunk-55AHQF63.js";
52
53
  import "../chunk-MLKGABMK.js";
53
54
 
54
55
  // bin/pushary-permission-denied-hook.ts