@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,593 +0,0 @@
1
- import {
2
- compatibleConfigFile
3
- } from "./chunk-4I4HAPT5.js";
4
- import {
5
- hookOwnerOf,
6
- hookOwnerOfCommands
7
- } from "./chunk-BMR66K6T.js";
8
- import {
9
- AGENT_CHOICES
10
- } from "./chunk-6UGVZTRA.js";
11
- import {
12
- OPENCODE_INSTRUCTIONS_LABEL,
13
- bridgeStub,
14
- claudeSettings,
15
- codexHooksJson,
16
- cursorUserHooks,
17
- geminiSettings,
18
- guardedArgv,
19
- liveBridgeProbe,
20
- renderAgentInstructions,
21
- resolveBridgeStub,
22
- vscodePluginDir,
23
- windowsNodeLauncherFor
24
- } from "./chunk-MH4O453X.js";
25
- import {
26
- readJsonSafe
27
- } from "./chunk-TODDEIYG.js";
28
- import {
29
- HOOK_BUDGETS,
30
- HOOK_COMPATIBLE_PROFILES,
31
- OPENCODE_APPROVAL_EVENT,
32
- hookCompatibleProfile,
33
- isRecord
34
- } from "./chunk-KB7YWU7A.js";
35
-
36
- // src/opencode-plugin.ts
37
- var OPENCODE_PLUGIN_MARKER = "pushary-opencode-plugin w1";
38
- var OPENCODE_PLUGIN_PLACEHOLDER = "__PUSHARY_COMMAND__";
39
- var OPENCODE_APPROVAL_EVENTS_PLACEHOLDER = "__PUSHARY_APPROVAL_EVENTS__";
40
- var OPENCODE_PLUGIN_FILE = "pushary.js";
41
- var OPENCODE_PLUGIN_DIR = "plugins";
42
- var OPENCODE_PLUGIN_SIBLING = "package.json";
43
- var OPENCODE_PLUGIN_SIBLING_CONTENTS = `${JSON.stringify({ type: "module" }, null, 2)}
44
- `;
45
- var OPENCODE_ASKED_EVENTS = ["permission.asked", "permission.updated"];
46
- var OPENCODE_REPLIED_EVENT = "permission.replied";
47
- var OPENCODE_IDLE_EVENT = "session.idle";
48
- var approvalTimeoutMs = () => (HOOK_BUDGETS.opencode.budgetSeconds - HOOK_BUDGETS.opencode.guardSeconds) * 1e3;
49
- var openCodePluginSource = () => `// Pushary for OpenCode. Generated by @pushary/agent-hooks \u2014 do not edit.
50
- // ${OPENCODE_PLUGIN_MARKER}
51
- //
52
- // OpenCode finds a plugin by globbing {plugin,plugins}/*.{ts,js} under its config
53
- // directory and importing it, so this file is the whole install.
54
- //
55
- // It decides nothing. Each hook builds the payload OpenCode handed it, writes it
56
- // to the Pushary hook command on stdin, and reads a verdict back. The policy
57
- // engine, the phone, the wait and the settlement all live behind that command.
58
- //
59
- // Approvals ride the event stream rather than the "permission.ask" hook, which is
60
- // declared in @opencode-ai/plugin and called by nothing. Permission.ask publishes
61
- // "permission.asked" and blocks on a Deferred that only a reply resolves, so this
62
- // answers that reply on the person's behalf when Pushary has a verdict.
63
- //
64
- // Failure is silence. A missing command, a crash, a timeout, unreadable bytes and
65
- // an unparseable reply all leave OpenCode's own prompt exactly as it was. The
66
- // worst this file may do to somebody is nothing at all.
67
-
68
- import { spawn } from "node:child_process"
69
-
70
- const COMMAND = ${OPENCODE_PLUGIN_PLACEHOLDER}
71
- const APPROVAL_TIMEOUT_MS = ${approvalTimeoutMs()}
72
- const TELEMETRY_TIMEOUT_MS = 10000
73
- const MAX_REPLY_BYTES = 65536
74
- // One entry per call in flight. Bounded because a long session must not grow them
75
- // without limit, and evicted oldest-first because whatever is still waiting on an
76
- // answer is the newest thing in here, never the oldest.
77
- const MAX_TRACKED = 256
78
-
79
- const text = (value) => (typeof value === "string" && value.length > 0 ? value : undefined)
80
-
81
- const remember = (map, key, value) => {
82
- if (!key || value === undefined) return
83
- if (map.size >= MAX_TRACKED) map.delete(map.keys().next().value)
84
- map.set(key, value)
85
- }
86
-
87
- const run = (payload, timeoutMs, onSpawn) =>
88
- new Promise((resolve) => {
89
- let settled = false
90
- const finish = (value) => {
91
- if (settled) return
92
- settled = true
93
- clearTimeout(timer)
94
- resolve(value)
95
- }
96
-
97
- let child
98
- try {
99
- child = spawn(COMMAND[0], COMMAND.slice(1), { stdio: ["pipe", "pipe", "ignore"] })
100
- } catch {
101
- return finish(null)
102
- }
103
- if (onSpawn) onSpawn(child)
104
-
105
- const timer = setTimeout(() => {
106
- try {
107
- child.kill("SIGKILL")
108
- } catch {}
109
- finish(null)
110
- }, timeoutMs)
111
- if (typeof timer.unref === "function") timer.unref()
112
-
113
- let out = ""
114
- child.stdout.on("data", (chunk) => {
115
- if (out.length < MAX_REPLY_BYTES) out += chunk
116
- })
117
- child.on("error", () => finish(null))
118
- child.on("close", () => {
119
- const body = out.trim()
120
- if (!body) return finish(null)
121
- try {
122
- finish(JSON.parse(body))
123
- } catch {
124
- finish(null)
125
- }
126
- })
127
-
128
- try {
129
- child.stdin.on("error", () => {})
130
- child.stdin.end(JSON.stringify(payload))
131
- } catch {
132
- finish(null)
133
- }
134
- })
135
-
136
- // Telemetry is fire and forget: the agent has already acted and is only being
137
- // observed, so nothing here may hold up the next turn.
138
- const tell = (payload) => {
139
- void run(payload, TELEMETRY_TIMEOUT_MS)
140
- }
141
-
142
- // What OpenCode gates on, and what it hands over with it. Verified against its own
143
- // tools: bash asks with { command }, write and edit both ask under "edit" with
144
- // { filepath, diff }, webfetch with { url }, and a shell command reaching outside
145
- // the worktree asks a second time under "external_directory".
146
- const inputFrom = (permission, metadata, resources) => {
147
- const meta = metadata && typeof metadata === "object" ? metadata : {}
148
- if (permission === "read" && resources?.length === 1) return { file_path: resources[0] }
149
- const command = text(meta.command)
150
- if (command) return { command }
151
- const preview = Array.isArray(meta.files) && meta.files.length === 1 ? meta.files[0] : undefined
152
- const filepath = text(preview?.file) ?? text(meta.filepath) ?? text(meta.file_path) ?? text(meta.path)
153
- // The diff rides along, because it is what the person is actually approving.
154
- // OpenCode computes it before raising the permission and hands it over; without
155
- // it the phone shows a filename and nothing to judge.
156
- const diff = text(preview?.patch) ?? text(meta.diff)
157
- if (filepath) return { file_path: filepath, ...(diff ? { diff } : {}) }
158
- const url = text(meta.url)
159
- if (url) return { url }
160
- return { permission, ...(resources?.length ? { resources } : {}) }
161
- }
162
-
163
- // Two spellings of one request: the runtime publishes PermissionV1.Request
164
- // ({ permission, patterns }), the generated SDK types say Permission ({ type,
165
- // pattern }). Whichever arrives, the id and the session are what we need.
166
- const askedFrom = (properties) => {
167
- if (!properties || typeof properties !== "object") return null
168
- const id = text(properties.id)
169
- const sessionID = text(properties.sessionID)
170
- if (!id || !sessionID) return null
171
- return {
172
- id,
173
- sessionID,
174
- permission: text(properties.action) ?? text(properties.permission) ?? text(properties.type) ?? "unknown",
175
- metadata: properties.metadata,
176
- resources: Array.isArray(properties.resources) ? properties.resources.filter((item) => typeof item === "string") : undefined,
177
- title: text(properties.title) ?? text(properties.message),
178
- callID: text(properties.source && properties.source.id) ?? text(properties.callID) ?? text(properties.tool && properties.tool.callID),
179
- }
180
- }
181
-
182
- const repliedID = (properties) => {
183
- if (!properties || typeof properties !== "object") return undefined
184
- return text(properties.requestID) ?? text(properties.permissionID) ?? text(properties.id)
185
- }
186
-
187
- const PusharyPlugin = async ({ client, directory, worktree, replyPermission }) => {
188
- const cwd = directory || worktree || process.cwd()
189
- // OpenCode raises a permission under a coarse key \u2014 "edit" covers both write and
190
- // edit \u2014 and names the actual tool only on tool.execute.before. Keeping the
191
- // pairing is what lets a rule written for Write mean Write here too.
192
- const tools = new Map()
193
- // Every gate still waiting. Held so a person answering in the terminal can end
194
- // ours: whoever answers first wins, and the loser stops asking.
195
- const waiting = new Map()
196
-
197
- const base = (sessionID) => ({ session_id: sessionID ?? "", cwd })
198
-
199
- // Replying is the whole approval. Two shapes, because the client handed to a
200
- // plugin is generated: v1 exposes postSessionIdPermissionsPermissionId against
201
- // /session/{id}/permissions/{permissionID}, v2 exposes permission.reply against
202
- // /permission/{requestID}/reply. Both routes are live in the server today.
203
- const respond = async (asked, allow) => {
204
- if (replyPermission) {
205
- try {
206
- await replyPermission({ sessionID: asked.sessionID, requestID: asked.id, decision: allow ? "once" : "reject" })
207
- } catch {}
208
- return
209
- }
210
- const legacy = client && typeof client.postSessionIdPermissionsPermissionId === "function"
211
- ? () => client.postSessionIdPermissionsPermissionId({
212
- path: { id: asked.sessionID, permissionID: asked.id },
213
- body: { response: allow ? "once" : "reject" },
214
- })
215
- : null
216
- const current = client && client.permission && typeof client.permission.reply === "function"
217
- ? () => client.permission.reply({
218
- // Current v2 uses flat parameters; older generated clients read path/body.
219
- requestID: asked.id, reply: allow ? "once" : "reject",
220
- path: { requestID: asked.id },
221
- body: { reply: allow ? "once" : "reject" },
222
- }, { throwOnError: true })
223
- : null
224
-
225
- for (const attempt of [legacy, current]) {
226
- if (!attempt) continue
227
- try {
228
- const result = await attempt()
229
- if (result && result.error) continue
230
- return
231
- } catch {
232
- // The person answered first, or this client does not serve that route.
233
- // Either way the next shape is the only thing left to try.
234
- }
235
- }
236
- }
237
-
238
- const gate = async (asked) => {
239
- if (asked.permission === "external_directory") return
240
- if (replyPermission && !["shell", "read", "edit", "webfetch"].includes(asked.permission)) return
241
- if (Array.isArray(asked.metadata?.files) && asked.metadata.files.length > 1) return
242
- if (["read", "edit"].includes(asked.permission) && asked.resources?.length > 1) return
243
- const tool = tools.get(asked.callID)
244
- if (["shell", "bash"].includes(tool?.name) && text(tool.input?.workdir) && tool.input.workdir !== cwd) return
245
- const reply = await run({
246
- ...base(asked.sessionID),
247
- hook_event_name: "${OPENCODE_APPROVAL_EVENT}",
248
- tool_name: tool?.name ?? asked.permission,
249
- tool_input: inputFrom(asked.permission, { ...tool?.input, ...asked.metadata }, asked.resources),
250
- permission_id: asked.id,
251
- permission_type: asked.permission,
252
- title: asked.title,
253
- }, APPROVAL_TIMEOUT_MS, (child) => remember(waiting, asked.id, child))
254
-
255
- // Gone means the terminal already answered while we were asking. Replying now
256
- // would be answering a question nobody is holding open any more.
257
- if (!waiting.delete(asked.id)) return
258
-
259
- const status = reply && typeof reply === "object" ? reply.status : undefined
260
- if (status !== "allow" && status !== "deny") return
261
- await respond(asked, status === "allow")
262
- }
263
-
264
- const withdraw = (id) => {
265
- const child = id && waiting.get(id)
266
- if (!child) return
267
- waiting.delete(id)
268
- // SIGTERM rather than SIGKILL: the hook cancels its outstanding question on
269
- // the way out, so the phone stops showing a decision the terminal has taken.
270
- try {
271
- child.kill("SIGTERM")
272
- } catch {}
273
- }
274
-
275
- return {
276
- "tool.execute.before": async (input) => {
277
- remember(tools, input && input.callID, { name: input?.tool, input: input?.args })
278
- },
279
-
280
- "tool.execute.after": async (input, output) => {
281
- const call = input && input.callID
282
- if (call) tools.delete(call)
283
- tell({
284
- ...base(input && input.sessionID),
285
- hook_event_name: "tool.execute.after",
286
- tool_name: text(input && input.tool) ?? "unknown",
287
- tool_input: input && input.args && typeof input.args === "object" ? input.args : {},
288
- tool_result: output?.error ? { error: output.error } : { title: text(output && output.title), output: text(output && output.output) },
289
- })
290
- },
291
-
292
- "chat.message": async (input, output) => {
293
- const parts = output && Array.isArray(output.parts) ? output.parts : []
294
- const prompt = parts
295
- .filter((part) => part && part.type === "text" && typeof part.text === "string")
296
- .map((part) => part.text)
297
- .join("\\n")
298
- .trim()
299
- if (!prompt) return
300
- tell({ ...base(input && input.sessionID), hook_event_name: "chat.message", prompt })
301
- },
302
-
303
- event: async ({ event }) => {
304
- // Never allowed to throw: the host calls this hook without awaiting it, so a
305
- // rejection here is an unhandled rejection in somebody's editor.
306
- try {
307
- const type = event && event.type
308
- const properties = event && event.properties
309
- if (${OPENCODE_APPROVAL_EVENTS_PLACEHOLDER}.includes(type)) {
310
- const asked = askedFrom(properties)
311
- if (asked && !waiting.has(asked.id)) void gate(asked)
312
- return
313
- }
314
- if (type === ${JSON.stringify(OPENCODE_REPLIED_EVENT)}) {
315
- withdraw(repliedID(properties))
316
- return
317
- }
318
- // session.idle is the turn boundary \u2014 OpenCode's equivalent of Claude's
319
- // Stop, not of its SessionEnd. Nothing else on the stream is relayed: the
320
- // receipts already arrive through the hooks above, and reporting the same
321
- // moment twice would double every row on the account.
322
- if (type === ${JSON.stringify(OPENCODE_IDLE_EVENT)}) {
323
- tell({
324
- ...base(properties && properties.sessionID),
325
- hook_event_name: ${JSON.stringify(OPENCODE_IDLE_EVENT)},
326
- })
327
- }
328
- } catch {}
329
- },
330
-
331
- dispose: async () => {
332
- for (const id of Array.from(waiting.keys())) withdraw(id)
333
- tools.clear()
334
- },
335
- }
336
- }
337
-
338
- export default {
339
- id: "pushary",
340
- server: PusharyPlugin,
341
- async setup(ctx) {
342
- const hooks = await PusharyPlugin({
343
- directory: ctx.location.directory,
344
- replyPermission: (request) => ctx.permission.reply(request),
345
- })
346
- await ctx.tool.hook("execute.before", (event) => hooks["tool.execute.before"]({
347
- callID: event.id, tool: event.tool, sessionID: event.sessionID, args: event.input,
348
- }))
349
- await ctx.tool.hook("execute.after", (event) => hooks["tool.execute.after"]({
350
- callID: event.id, tool: event.tool, sessionID: event.sessionID, args: event.input,
351
- }, { output: event.status === "completed" && Array.isArray(event.result.content)
352
- ? event.result.content.filter((part) => part.type === "text").map((part) => part.text).join("\\n")
353
- : undefined, error: event.status === "error" ? event.error.message : undefined }))
354
- await ctx.session.hook("prompt", (event) => hooks["chat.message"]({ sessionID: event.sessionID }, {
355
- parts: [{ type: "text", text: event.prompt.text }],
356
- }))
357
- const controller = new AbortController()
358
- const consume = async () => {
359
- try {
360
- for await (const event of ctx.event.subscribe({ signal: controller.signal })) {
361
- if (controller.signal.aborted) break
362
- if (event.location && (event.location.directory !== ctx.location.directory || event.location.workspaceID !== ctx.location.workspaceID)) continue
363
- const type = event.type === "session.execution.succeeded" ? "session.idle" : event.type
364
- await hooks.event({ event: { type, properties: event.data } })
365
- }
366
- } catch {
367
- if (!controller.signal.aborted) console.error("Pushary event subscription stopped; native prompts remain available.")
368
- } finally {
369
- await hooks.dispose()
370
- }
371
- }
372
- const events = consume()
373
- return async () => {
374
- controller.abort()
375
- await hooks.dispose()
376
- await events
377
- }
378
- },
379
- }
380
- `;
381
- var openCodePluginModule = () => ({
382
- marker: OPENCODE_PLUGIN_MARKER,
383
- source: openCodePluginSource(),
384
- placeholder: OPENCODE_PLUGIN_PLACEHOLDER,
385
- approvalEvents: {
386
- placeholder: OPENCODE_APPROVAL_EVENTS_PLACEHOLDER,
387
- events: OPENCODE_ASKED_EVENTS
388
- },
389
- sibling: {
390
- path: OPENCODE_PLUGIN_SIBLING,
391
- contents: OPENCODE_PLUGIN_SIBLING_CONTENTS
392
- }
393
- });
394
- var renderOpenCodePlugin = (module, argv, holdsApprovals = true) => module.source.replace(module.placeholder, JSON.stringify(argv)).replace(module.approvalEvents.placeholder, JSON.stringify(holdsApprovals ? module.approvalEvents.events : []));
395
- var COMMAND_LINE = /^const COMMAND = (.*)$/m;
396
- var isArgv = (value) => Array.isArray(value) && value.every((item) => typeof item === "string");
397
- var openCodePluginArgv = (contents) => {
398
- if (!isOpenCodePluginOurs(contents)) return null;
399
- const line = contents.match(COMMAND_LINE)?.[1];
400
- if (line === void 0) return null;
401
- try {
402
- const parsed = JSON.parse(line);
403
- return isArgv(parsed) ? parsed : null;
404
- } catch {
405
- return null;
406
- }
407
- };
408
- var isOpenCodePluginOurs = (contents) => contents.includes(OPENCODE_PLUGIN_MARKER);
409
-
410
- // src/opencode-config.ts
411
- import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "fs";
412
- import { homedir } from "os";
413
- import { join } from "path";
414
- var OPENCODE_HOOK_BINARY = "pushary-opencode-hook";
415
- var OPENCODE_HOOK_ARGS = ["--source", "opencode"];
416
- var openCodeHookArgv = (resolvedBinary, platform = process.platform) => guardedArgv({ kind: "binary", path: resolvedBinary ?? OPENCODE_HOOK_BINARY, runtime: "node" }, OPENCODE_HOOK_ARGS, platform, windowsNodeLauncherFor(platform));
417
- var openCodeConfigDirFrom = (home, env = process.env) => env.OPENCODE_CONFIG_DIR?.trim() || join(env.XDG_CONFIG_HOME?.trim() || join(home, ".config"), "opencode");
418
- var openCodeConfigDir = () => openCodeConfigDirFrom(homedir());
419
- var OPENCODE_PLUGIN_PATH = `${OPENCODE_PLUGIN_DIR}/${OPENCODE_PLUGIN_FILE}`;
420
- var openCodePluginDir = () => join(openCodeConfigDir(), OPENCODE_PLUGIN_DIR);
421
- var openCodePluginFile = () => join(openCodePluginDir(), OPENCODE_PLUGIN_FILE);
422
- var OPENCODE_HOOK_EVENTS = [
423
- { event: OPENCODE_APPROVAL_EVENT, delivery: "approval", timeout: HOOK_BUDGETS.opencode.budgetSeconds },
424
- { event: "tool.execute.after", delivery: "telemetry", timeout: 10 },
425
- { event: "chat.message", delivery: "telemetry", timeout: 10 },
426
- { event: OPENCODE_IDLE_EVENT, delivery: "telemetry", timeout: 10 }
427
- ];
428
- var hasForeignPlugins = (entries) => entries.some((entry) => entry !== OPENCODE_PLUGIN_FILE && /\.(ts|js)$/.test(entry));
429
- var installOpenCodePlugin = (argv, dir = openCodePluginDir()) => {
430
- mkdirSync(dir, { recursive: true });
431
- const plugin = join(dir, OPENCODE_PLUGIN_FILE);
432
- writeFileSync(plugin, renderOpenCodePlugin(openCodePluginModule(), argv), "utf-8");
433
- const sibling = join(dir, OPENCODE_PLUGIN_SIBLING);
434
- if (existsSync(sibling)) return { plugin, wroteSibling: false };
435
- writeFileSync(sibling, OPENCODE_PLUGIN_SIBLING_CONTENTS, "utf-8");
436
- return { plugin, wroteSibling: true };
437
- };
438
- var openCodeWired = (dir = openCodePluginDir()) => {
439
- try {
440
- return isOpenCodePluginOurs(readFileSync(join(dir, OPENCODE_PLUGIN_FILE), "utf-8"));
441
- } catch {
442
- return false;
443
- }
444
- };
445
- var OPENCODE_MCP_URL = "https://pushary.com/api/mcp/mcp";
446
- var OPENCODE_CONFIG_FILE = "opencode.json";
447
- var openCodeConfigFile = () => join(openCodeConfigDir(), OPENCODE_CONFIG_FILE);
448
- var OPENCODE_INSTRUCTIONS_FILE = "AGENTS.md";
449
- var openCodeInstructionsFile = () => join(openCodeConfigDir(), OPENCODE_INSTRUCTIONS_FILE);
450
- var OPENCODE_QUESTION_TOOL = "question";
451
- var OPENCODE_QUESTION_NOTE = `In OpenCode, this replaces the guidance above to ask in the terminal while the user is there: ask every question through the Pushary \`ask_user\` tool, even while the user is at this terminal, and not through OpenCode's own \`${OPENCODE_QUESTION_TOOL}\` tool. When Pushary's tools are listed under Code Mode, call them inside \`execute\`, for example \`await tools.pushary.ask_user({ ... })\` and \`await tools.pushary.wait_for_answer({ ... })\`. Otherwise OpenCode lists them as direct tools such as \`pushary_ask_user\`. That includes a question the user asks you to put to them, such as "ask me a multiple choice question": use \`ask_user\` with type "select". Ask one question at a time and wait for its answer before asking the next. OpenCode's question prompt cannot reach the phone or the Mac notch, so a question asked there waits unseen once the user steps away. Ask in your reply or with the \`${OPENCODE_QUESTION_TOOL}\` tool instead only when a Pushary handoffAction tells you to ask here, or when Pushary's tools are listed under neither name or \`ask_user\` fails without a handoffAction.`;
452
- var openCodeInstructionsBody = () => `${renderAgentInstructions(OPENCODE_INSTRUCTIONS_LABEL)}
453
-
454
- ${OPENCODE_QUESTION_NOTE}`;
455
- var asRecord = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
456
- var addOpenCodeMcpServer = (config, apiKey) => {
457
- const servers = asRecord(config.mcp) ?? {};
458
- servers.pushary = {
459
- type: "remote",
460
- url: OPENCODE_MCP_URL,
461
- enabled: true,
462
- headers: { Authorization: `Bearer ${apiKey}` }
463
- };
464
- config.mcp = servers;
465
- };
466
- var OPENCODE_ASKED_PERMISSIONS = ["bash", "edit", "webfetch"];
467
- var PERMISSION_KEY = "permission";
468
- var TOOLS_KEY = "tools";
469
- var ASK_ACTION = "ask";
470
- var ALLOW_ACTION = "allow";
471
- var DENY_ACTION = "deny";
472
- var ALL_PATTERNS = "*";
473
- var OPENCODE_ACTION_NAMES = {
474
- bash: ["bash", "shell"],
475
- edit: ["edit", "write", "patch"],
476
- webfetch: ["webfetch"]
477
- };
478
- var escapedForPattern = (text) => text.replace(/[.+^${}()|[\]\\]/g, "\\$&").replaceAll("?", ".");
479
- var keyMatches = (key, name) => new RegExp(`^${key.split(ALL_PATTERNS).map(escapedForPattern).join(".*")}$`).test(name);
480
- var ruleNamesPermission = (permission) => ([key]) => OPENCODE_ACTION_NAMES[permission].some((name) => keyMatches(key, name));
481
- var toolRules = (config) => Object.entries(asRecord(config[TOOLS_KEY]) ?? {}).filter(([, enabled]) => typeof enabled === "boolean").map(([key, enabled]) => [key, enabled ? ALLOW_ACTION : DENY_ACTION]);
482
- var permissionRules = (config) => {
483
- const permission = config[PERMISSION_KEY];
484
- if (permission === void 0) return [];
485
- const rules = asRecord(permission);
486
- return rules ? Object.entries(rules) : [[ALL_PATTERNS, permission]];
487
- };
488
- var rulesInOrder = (config) => [...toolRules(config), ...permissionRules(config)];
489
- var actionOfRule = (value) => {
490
- const patterns = asRecord(value);
491
- return patterns ? patterns[ALL_PATTERNS] : value;
492
- };
493
- var holdsTheCall = (action) => action === ASK_ACTION || action === DENY_ACTION;
494
- var withOpenCodeAskRules = (config) => {
495
- const permission = config[PERMISSION_KEY];
496
- const rules = asRecord(permission);
497
- if (permission !== void 0 && !rules) return { config, change: { kind: "person-setting-kept" } };
498
- const personRules = rulesInOrder(config);
499
- const added = OPENCODE_ASKED_PERMISSIONS.filter((name) => !personRules.some(ruleNamesPermission(name)));
500
- if (added.length === 0) return { config, change: { kind: "present" } };
501
- const asks = Object.fromEntries(added.map((name) => [name, ASK_ACTION]));
502
- return { config: { ...config, [PERMISSION_KEY]: { ...asks, ...rules } }, change: { kind: "added", added } };
503
- };
504
- var openCodePermissionsLeftOpen = (config) => {
505
- const rules = rulesInOrder(asRecord(config) ?? {});
506
- return OPENCODE_ASKED_PERMISSIONS.filter((name) => !holdsTheCall(
507
- rules.filter(ruleNamesPermission(name)).map(([, value]) => actionOfRule(value)).filter((action) => action !== void 0).at(-1)
508
- ));
509
- };
510
- var openCodeAskCheck = (config) => {
511
- if (config.kind === "unreadable" || config.kind === "unparseable") return { kind: "unreadable" };
512
- const value = config.kind === "ok" ? asRecord(config.value) ?? {} : {};
513
- const open = openCodePermissionsLeftOpen(value);
514
- if (open.length === 0) return { kind: "asks" };
515
- const personRules = rulesInOrder(value);
516
- const namedByPerson = (name) => personRules.some(ruleNamesPermission(name));
517
- return { kind: "open", unset: open.filter((name) => !namedByPerson(name)), allowedByPerson: open.filter(namedByPerson) };
518
- };
519
- var removeOpenCodeMcpServer = (config) => {
520
- const servers = asRecord(config.mcp);
521
- if (!servers || !("pushary" in servers)) return false;
522
- delete servers.pushary;
523
- if (Object.keys(servers).length === 0) delete config.mcp;
524
- return true;
525
- };
526
-
527
- // src/setup/agent-hook-owner.ts
528
- import { readFileSync as readFileSync2 } from "fs";
529
- import { join as join2 } from "path";
530
- var COMPATIBLE_HOOK_FILES = Object.fromEntries(
531
- HOOK_COMPATIBLE_PROFILES.map((profile) => [profile.agentType, () => compatibleConfigFile(profile)])
532
- );
533
- var HOOK_FILES = {
534
- claude_code: claudeSettings,
535
- codex: codexHooksJson,
536
- gemini_cli: geminiSettings,
537
- cursor: cursorUserHooks,
538
- vscode: () => join2(vscodePluginDir(), "hooks", "hooks.json"),
539
- ...COMPATIBLE_HOOK_FILES
540
- };
541
- var agentHookFile = (agent) => HOOK_FILES[agent]?.() ?? null;
542
- var agentHooksKeyPath = (agent) => hookCompatibleProfile(agent)?.hooksKeyPath;
543
- var readTextOrNull = (path) => {
544
- try {
545
- return readFileSync2(path, "utf-8");
546
- } catch {
547
- return null;
548
- }
549
- };
550
- var openCodePluginOwner = (appAvailable) => {
551
- const contents = readTextOrNull(openCodePluginFile());
552
- return hookOwnerOfCommands(contents === null ? [] : openCodePluginArgv(contents) ?? [], appAvailable);
553
- };
554
- var agentHookOwner = (agent, appAvailable) => {
555
- if (agent === "opencode") return openCodePluginOwner(appAvailable);
556
- const file = agentHookFile(agent);
557
- if (!file) return "none";
558
- const document = readJsonSafe(file);
559
- return hookOwnerOf(document.kind === "ok" && isRecord(document.value) ? document.value : null, appAvailable, agentHooksKeyPath(agent));
560
- };
561
- var cliOwnsAnyAgentHooks = (appAvailable) => AGENT_CHOICES.some((agent) => agentHookOwner(agent, appAvailable) === "cli");
562
- var macAppBridgeAvailable = () => resolveBridgeStub(bridgeStub(), liveBridgeProbe()).kind === "bundle";
563
-
564
- export {
565
- OPENCODE_PLUGIN_PLACEHOLDER,
566
- OPENCODE_PLUGIN_SIBLING,
567
- OPENCODE_PLUGIN_SIBLING_CONTENTS,
568
- openCodePluginArgv,
569
- isOpenCodePluginOurs,
570
- OPENCODE_HOOK_BINARY,
571
- openCodeHookArgv,
572
- openCodeConfigDirFrom,
573
- openCodeConfigDir,
574
- openCodePluginDir,
575
- openCodePluginFile,
576
- hasForeignPlugins,
577
- installOpenCodePlugin,
578
- openCodeWired,
579
- openCodeConfigFile,
580
- openCodeInstructionsFile,
581
- openCodeInstructionsBody,
582
- addOpenCodeMcpServer,
583
- OPENCODE_ASKED_PERMISSIONS,
584
- withOpenCodeAskRules,
585
- openCodePermissionsLeftOpen,
586
- openCodeAskCheck,
587
- removeOpenCodeMcpServer,
588
- agentHookFile,
589
- agentHooksKeyPath,
590
- agentHookOwner,
591
- cliOwnsAnyAgentHooks,
592
- macAppBridgeAvailable
593
- };
@@ -1,68 +0,0 @@
1
- import {
2
- ensureCodexTrustAfterReapply,
3
- inspectConfiguredManagedProviders,
4
- reapplyAllAgents,
5
- reapplyClaudeForVersion,
6
- reapplyClaudeSettings,
7
- reapplyClineSettings,
8
- reapplyCodexSettings,
9
- reapplyCompatibleHooks,
10
- reapplyCursorPlugin,
11
- reapplyGeminiSettings,
12
- reapplyOpenCodePlugin,
13
- reapplyVsCodePlugin,
14
- repairCodexHolds
15
- } from "./chunk-C74JHUD3.js";
16
- import "./chunk-T3LSBTWU.js";
17
- import "./chunk-UAYNQ2IG.js";
18
- import "./chunk-HXX4EFK3.js";
19
- import "./chunk-S6DJAYQW.js";
20
- import "./chunk-2N23JFER.js";
21
- import "./chunk-DDSMTD4W.js";
22
- import "./chunk-BO4HRAY7.js";
23
- import "./chunk-MEUAK5BK.js";
24
- import "./chunk-CYTPQDQY.js";
25
- import "./chunk-4I4HAPT5.js";
26
- import "./chunk-BMR66K6T.js";
27
- import "./chunk-QBDCKECQ.js";
28
- import "./chunk-2SHPCEH6.js";
29
- import "./chunk-6UGVZTRA.js";
30
- import "./chunk-6NRFAP45.js";
31
- import "./chunk-YPY4YCIZ.js";
32
- import "./chunk-UJJ2OXFA.js";
33
- import "./chunk-ICHKAH5Q.js";
34
- import "./chunk-POFBE6ZY.js";
35
- import "./chunk-MOX7IOGL.js";
36
- import "./chunk-C4K4KYOY.js";
37
- import "./chunk-E2KAAKWU.js";
38
- import "./chunk-H6CL3T2S.js";
39
- import "./chunk-QONYKXWP.js";
40
- import "./chunk-TWOSBIAW.js";
41
- import "./chunk-4RSJZOKB.js";
42
- import "./chunk-YU2EUD7O.js";
43
- import "./chunk-2LTRA6NA.js";
44
- import "./chunk-ELF4NIIM.js";
45
- import "./chunk-MH4O453X.js";
46
- import "./chunk-PMEDJ4WM.js";
47
- import "./chunk-ANL74IBU.js";
48
- import "./chunk-BG4HHB7E.js";
49
- import "./chunk-TODDEIYG.js";
50
- import "./chunk-P5JV6YZW.js";
51
- import "./chunk-WIIMW5YO.js";
52
- import "./chunk-KB7YWU7A.js";
53
- import "./chunk-MLKGABMK.js";
54
- export {
55
- ensureCodexTrustAfterReapply,
56
- inspectConfiguredManagedProviders,
57
- reapplyAllAgents,
58
- reapplyClaudeForVersion,
59
- reapplyClaudeSettings,
60
- reapplyClineSettings,
61
- reapplyCodexSettings,
62
- reapplyCompatibleHooks,
63
- reapplyCursorPlugin,
64
- reapplyGeminiSettings,
65
- reapplyOpenCodePlugin,
66
- reapplyVsCodePlugin,
67
- repairCodexHolds
68
- };
@@ -1,11 +0,0 @@
1
- import {
2
- exitOnHelpFlag
3
- } from "./chunk-MGT2V2AB.js";
4
- import "./chunk-BG4HHB7E.js";
5
- import "./chunk-P5JV6YZW.js";
6
- import "./chunk-WIIMW5YO.js";
7
- import "./chunk-KB7YWU7A.js";
8
- import "./chunk-MLKGABMK.js";
9
- export {
10
- exitOnHelpFlag
11
- };