pushary 1.8.0

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 (186) hide show
  1. package/CHANGELOG.md +1943 -0
  2. package/LICENSE +21 -0
  3. package/README.md +330 -0
  4. package/data/SKILL.md +591 -0
  5. package/data/cowork/SKILL.md +77 -0
  6. package/data/cursor-plugin/.cursor-plugin/plugin.json +25 -0
  7. package/data/cursor-plugin/CHANGELOG.md +70 -0
  8. package/data/cursor-plugin/CONTRIBUTING.md +40 -0
  9. package/data/cursor-plugin/LICENSE +21 -0
  10. package/data/cursor-plugin/README.md +113 -0
  11. package/data/cursor-plugin/SECURITY.md +33 -0
  12. package/data/cursor-plugin/assets/logo.png +0 -0
  13. package/data/cursor-plugin/commands/notify-when-done.md +14 -0
  14. package/data/cursor-plugin/commands/pushary-test.md +13 -0
  15. package/data/cursor-plugin/hooks/hooks.json +75 -0
  16. package/data/cursor-plugin/mcp.json +11 -0
  17. package/data/cursor-plugin/rules/pushary.mdc +40 -0
  18. package/data/cursor-plugin/scripts/pushary-gate.mjs +724 -0
  19. package/data/cursor-plugin/scripts/pushary-gate.test.mjs +137 -0
  20. package/data/cursor-plugin/scripts/redaction.mjs +51 -0
  21. package/data/cursor-plugin/skills/pushary/SKILL.md +584 -0
  22. package/data/vscode-plugin/.claude-plugin/plugin.json +28 -0
  23. package/data/vscode-plugin/.mcp.json +11 -0
  24. package/data/vscode-plugin/CHANGELOG.md +49 -0
  25. package/data/vscode-plugin/CONTRIBUTING.md +40 -0
  26. package/data/vscode-plugin/LICENSE +21 -0
  27. package/data/vscode-plugin/README.md +128 -0
  28. package/data/vscode-plugin/SECURITY.md +56 -0
  29. package/data/vscode-plugin/assets/logo.png +0 -0
  30. package/data/vscode-plugin/commands/notify-when-done.md +14 -0
  31. package/data/vscode-plugin/commands/pushary-test.md +13 -0
  32. package/data/vscode-plugin/hooks/hooks.json +60 -0
  33. package/data/vscode-plugin/scripts/pushary-gate.mjs +762 -0
  34. package/data/vscode-plugin/scripts/redaction.mjs +51 -0
  35. package/data/vscode-plugin/skills/pushary/SKILL.md +584 -0
  36. package/dist/bin/pushary-bell-hook.d.ts +1 -0
  37. package/dist/bin/pushary-bell-hook.js +46 -0
  38. package/dist/bin/pushary-bell.d.ts +1 -0
  39. package/dist/bin/pushary-bell.js +146 -0
  40. package/dist/bin/pushary-claude.d.ts +1 -0
  41. package/dist/bin/pushary-claude.js +1916 -0
  42. package/dist/bin/pushary-clean.d.ts +1 -0
  43. package/dist/bin/pushary-clean.js +1300 -0
  44. package/dist/bin/pushary-codex-bridge.d.ts +1 -0
  45. package/dist/bin/pushary-codex-bridge.js +599 -0
  46. package/dist/bin/pushary-codex-hook.d.ts +1 -0
  47. package/dist/bin/pushary-codex-hook.js +886 -0
  48. package/dist/bin/pushary-codex.d.ts +1 -0
  49. package/dist/bin/pushary-codex.js +125 -0
  50. package/dist/bin/pushary-connect.d.ts +1 -0
  51. package/dist/bin/pushary-connect.js +100 -0
  52. package/dist/bin/pushary-cowork.d.ts +1 -0
  53. package/dist/bin/pushary-cowork.js +36 -0
  54. package/dist/bin/pushary-daemon-supervisor.d.ts +1 -0
  55. package/dist/bin/pushary-daemon-supervisor.js +27 -0
  56. package/dist/bin/pushary-daemon.d.ts +1 -0
  57. package/dist/bin/pushary-daemon.js +878 -0
  58. package/dist/bin/pushary-disconnect.d.ts +1 -0
  59. package/dist/bin/pushary-disconnect.js +264 -0
  60. package/dist/bin/pushary-doctor.d.ts +1 -0
  61. package/dist/bin/pushary-doctor.js +1433 -0
  62. package/dist/bin/pushary-elicitation-hook.d.ts +1 -0
  63. package/dist/bin/pushary-elicitation-hook.js +149 -0
  64. package/dist/bin/pushary-gemini-bridge.d.ts +1 -0
  65. package/dist/bin/pushary-gemini-bridge.js +339 -0
  66. package/dist/bin/pushary-gemini-hook.d.ts +1 -0
  67. package/dist/bin/pushary-gemini-hook.js +381 -0
  68. package/dist/bin/pushary-hook.d.ts +1 -0
  69. package/dist/bin/pushary-hook.js +95 -0
  70. package/dist/bin/pushary-login.d.ts +1 -0
  71. package/dist/bin/pushary-login.js +198 -0
  72. package/dist/bin/pushary-logout.d.ts +1 -0
  73. package/dist/bin/pushary-logout.js +147 -0
  74. package/dist/bin/pushary-mcp.d.ts +1 -0
  75. package/dist/bin/pushary-mcp.js +114 -0
  76. package/dist/bin/pushary-mode.d.ts +1 -0
  77. package/dist/bin/pushary-mode.js +130 -0
  78. package/dist/bin/pushary-notification-hook.d.ts +1 -0
  79. package/dist/bin/pushary-notification-hook.js +56 -0
  80. package/dist/bin/pushary-opencode-hook.d.ts +1 -0
  81. package/dist/bin/pushary-opencode-hook.js +338 -0
  82. package/dist/bin/pushary-permission-denied-hook.d.ts +1 -0
  83. package/dist/bin/pushary-permission-denied-hook.js +60 -0
  84. package/dist/bin/pushary-permission-hook.d.ts +1 -0
  85. package/dist/bin/pushary-permission-hook.js +65 -0
  86. package/dist/bin/pushary-post-hook.d.ts +1 -0
  87. package/dist/bin/pushary-post-hook.js +70 -0
  88. package/dist/bin/pushary-prompt-hook.d.ts +1 -0
  89. package/dist/bin/pushary-prompt-hook.js +61 -0
  90. package/dist/bin/pushary-session-end-hook.d.ts +1 -0
  91. package/dist/bin/pushary-session-end-hook.js +59 -0
  92. package/dist/bin/pushary-session-start-hook.d.ts +1 -0
  93. package/dist/bin/pushary-session-start-hook.js +72 -0
  94. package/dist/bin/pushary-setup.d.ts +1 -0
  95. package/dist/bin/pushary-setup.js +2660 -0
  96. package/dist/bin/pushary-stats.d.ts +1 -0
  97. package/dist/bin/pushary-stats.js +44 -0
  98. package/dist/bin/pushary-status.d.ts +1 -0
  99. package/dist/bin/pushary-status.js +262 -0
  100. package/dist/bin/pushary-stop-hook.d.ts +1 -0
  101. package/dist/bin/pushary-stop-hook.js +63 -0
  102. package/dist/bin/pushary-stopfailure-hook.d.ts +1 -0
  103. package/dist/bin/pushary-stopfailure-hook.js +56 -0
  104. package/dist/bin/pushary-suggestions.d.ts +1 -0
  105. package/dist/bin/pushary-suggestions.js +100 -0
  106. package/dist/bin/pushary-transcript-register.d.ts +1 -0
  107. package/dist/bin/pushary-transcript-register.js +40 -0
  108. package/dist/bin/pushary-transcripts.d.ts +1 -0
  109. package/dist/bin/pushary-transcripts.js +77 -0
  110. package/dist/bin/pushary-upgrade.d.ts +1 -0
  111. package/dist/bin/pushary-upgrade.js +599 -0
  112. package/dist/bin/pushary-wait.d.ts +1 -0
  113. package/dist/bin/pushary-wait.js +122 -0
  114. package/dist/bin/pushary.d.ts +1 -0
  115. package/dist/bin/pushary.js +74 -0
  116. package/dist/chunk-2ABTSGFT.js +173 -0
  117. package/dist/chunk-2OY3ZZ5N.js +124 -0
  118. package/dist/chunk-3EGEA4KH.js +44 -0
  119. package/dist/chunk-3EVPNIBE.js +185 -0
  120. package/dist/chunk-5OP5MQI7.js +45 -0
  121. package/dist/chunk-6J2JC2RT.js +149 -0
  122. package/dist/chunk-7QLSKOSU.js +19 -0
  123. package/dist/chunk-7Z7Q4GGS.js +88 -0
  124. package/dist/chunk-A2A2YTMG.js +835 -0
  125. package/dist/chunk-AHV4LNB5.js +377 -0
  126. package/dist/chunk-AXPCESYO.js +197 -0
  127. package/dist/chunk-C2WCPBF7.js +86 -0
  128. package/dist/chunk-CJVVKOSR.js +73 -0
  129. package/dist/chunk-CULUZTWQ.js +2117 -0
  130. package/dist/chunk-CVQYGMSR.js +142 -0
  131. package/dist/chunk-CVWG2N3Y.js +16 -0
  132. package/dist/chunk-D2FX3EPW.js +15 -0
  133. package/dist/chunk-DB3ONZB4.js +44 -0
  134. package/dist/chunk-DE4Y6TCC.js +160 -0
  135. package/dist/chunk-E4FJTUH4.js +249 -0
  136. package/dist/chunk-EPCXUP3P.js +41 -0
  137. package/dist/chunk-EX3GAPA4.js +44 -0
  138. package/dist/chunk-EYK3GSRH.js +143 -0
  139. package/dist/chunk-GMXKITVA.js +70 -0
  140. package/dist/chunk-GPEGOGRJ.js +49 -0
  141. package/dist/chunk-GU3EJCVV.js +43 -0
  142. package/dist/chunk-HQ6G3B5R.js +59 -0
  143. package/dist/chunk-HZVVNGEW.js +22 -0
  144. package/dist/chunk-IPVKH2ST.js +231 -0
  145. package/dist/chunk-J5TIV3J6.js +238 -0
  146. package/dist/chunk-JU6W3XAU.js +64 -0
  147. package/dist/chunk-JYG4B33G.js +227 -0
  148. package/dist/chunk-JZTHGAPA.js +503 -0
  149. package/dist/chunk-KGDWDSNL.js +102 -0
  150. package/dist/chunk-KVQBWI5T.js +99 -0
  151. package/dist/chunk-KZERVKTD.js +16 -0
  152. package/dist/chunk-LXQ5FBBD.js +47 -0
  153. package/dist/chunk-M5ICYGHT.js +138 -0
  154. package/dist/chunk-M5JDZ45W.js +943 -0
  155. package/dist/chunk-MDEPU45E.js +1226 -0
  156. package/dist/chunk-MPWXGONV.js +157 -0
  157. package/dist/chunk-N6IOSZOE.js +185 -0
  158. package/dist/chunk-NGDD6TXY.js +192 -0
  159. package/dist/chunk-NQTHFF4W.js +2830 -0
  160. package/dist/chunk-OKXS7WDZ.js +68 -0
  161. package/dist/chunk-OLQRRFBX.js +21 -0
  162. package/dist/chunk-P7WQEVWA.js +307 -0
  163. package/dist/chunk-POFBE6ZY.js +12 -0
  164. package/dist/chunk-PQ4K74WL.js +30 -0
  165. package/dist/chunk-PUZZELE6.js +37 -0
  166. package/dist/chunk-Q7E4I6UA.js +767 -0
  167. package/dist/chunk-QCGNGEGE.js +15 -0
  168. package/dist/chunk-R7437YI3.js +151 -0
  169. package/dist/chunk-RHR6NARM.js +305 -0
  170. package/dist/chunk-SAXBC4AZ.js +60 -0
  171. package/dist/chunk-SGZJ5LYH.js +76 -0
  172. package/dist/chunk-SIFVFP6T.js +70 -0
  173. package/dist/chunk-SLFABHW3.js +150 -0
  174. package/dist/chunk-T7E75EKA.js +67 -0
  175. package/dist/chunk-TY4JT7W3.js +38 -0
  176. package/dist/chunk-U4TMAANR.js +111 -0
  177. package/dist/chunk-UI36QSBI.js +177 -0
  178. package/dist/chunk-VQKRG3AC.js +339 -0
  179. package/dist/chunk-WE2J62NC.js +1131 -0
  180. package/dist/chunk-XHKBHWLX.js +14 -0
  181. package/dist/chunk-ZSZSSJCV.js +275 -0
  182. package/dist/chunk-ZVSKMPBZ.js +135 -0
  183. package/dist/reapply-CW3MA66V.js +34 -0
  184. package/dist/src/index.d.ts +204 -0
  185. package/dist/src/index.js +64 -0
  186. package/package.json +108 -0
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
@@ -0,0 +1,599 @@
1
+ #!/usr/bin/env node
2
+ import "../chunk-HQ6G3B5R.js";
3
+ import {
4
+ LiveTranscriptRelay,
5
+ liveSessionSleep,
6
+ postLiveSession,
7
+ postLiveSessionUntilAccepted,
8
+ startLiveSessionHeartbeat
9
+ } from "../chunk-R7437YI3.js";
10
+ import {
11
+ SESSION_IDLE_TIMEOUT_MS,
12
+ describeIdleWindow,
13
+ idleDeadlinePassed,
14
+ startProcessOwnership,
15
+ withSpawnProcessOwnership
16
+ } from "../chunk-ZSZSSJCV.js";
17
+ import "../chunk-MPWXGONV.js";
18
+ import "../chunk-SAXBC4AZ.js";
19
+ import {
20
+ transcriptsEnabled
21
+ } from "../chunk-OLQRRFBX.js";
22
+ import {
23
+ spawnClaude
24
+ } from "../chunk-XHKBHWLX.js";
25
+ import {
26
+ isAskUserResponse,
27
+ isDecisionStopped,
28
+ isWaitForAnswerResponse,
29
+ withdrawQuestion
30
+ } from "../chunk-NGDD6TXY.js";
31
+ import {
32
+ writeDegraded
33
+ } from "../chunk-CVQYGMSR.js";
34
+ import "../chunk-POFBE6ZY.js";
35
+ import "../chunk-P7WQEVWA.js";
36
+ import {
37
+ callMcpTool
38
+ } from "../chunk-M5ICYGHT.js";
39
+ import "../chunk-2ABTSGFT.js";
40
+ import "../chunk-2OY3ZZ5N.js";
41
+ import {
42
+ getMachineId
43
+ } from "../chunk-LXQ5FBBD.js";
44
+ import "../chunk-7QLSKOSU.js";
45
+ import "../chunk-KZERVKTD.js";
46
+ import "../chunk-DB3ONZB4.js";
47
+ import {
48
+ resolveBinary
49
+ } from "../chunk-A2A2YTMG.js";
50
+ import "../chunk-T7E75EKA.js";
51
+ import {
52
+ getApiKey,
53
+ getBaseUrl
54
+ } from "../chunk-GPEGOGRJ.js";
55
+ import "../chunk-E4FJTUH4.js";
56
+ import {
57
+ elicitationContent,
58
+ parseAgentQuestion,
59
+ parseAgentQuestionAnswers,
60
+ planElicitationAsk,
61
+ readElicitationFields
62
+ } from "../chunk-NQTHFF4W.js";
63
+
64
+ // bin/pushary-codex-bridge.ts
65
+ import { existsSync } from "fs";
66
+
67
+ // src/codex-bridge.ts
68
+ import { randomUUID } from "crypto";
69
+
70
+ // src/codex-elicitation.ts
71
+ var planCodexElicitation = (params, threadId) => {
72
+ if (!threadId || params.threadId !== threadId || params.mode !== "form" || params._meta != null || typeof params.serverName !== "string" || !params.serverName.trim() || typeof params.message !== "string" || !params.message.trim()) return null;
73
+ const fields = readElicitationFields(params.requestedSchema);
74
+ if (!fields || fields.length > 3) return null;
75
+ const plan = [];
76
+ for (const [index, field] of fields.entries()) {
77
+ const question = `${params.serverName}: ${params.message} \u2014 ${field.label}`;
78
+ const ask = planElicitationAsk(question, [field]);
79
+ if (!ask || ask.kind === "questions" || question.length > 500) return null;
80
+ let labels = [];
81
+ if (ask.kind === "confirm") labels = ["Yes", "No"];
82
+ if (ask.kind === "select") labels = ask.options;
83
+ if (labels.length > 4 || labels.some((label) => label.length > 100)) return null;
84
+ plan.push({ ask, question: { id: String(index), question, isOther: false, options: labels.map((label) => ({ label })) } });
85
+ }
86
+ return plan;
87
+ };
88
+ var codexElicitationContent = (plan, answers) => {
89
+ let content = {};
90
+ for (const { ask, question } of plan) {
91
+ const values = answers[question.id]?.answers;
92
+ if (!values || values.length !== 1) return null;
93
+ const field = elicitationContent(ask, values[0]);
94
+ if (!field) return null;
95
+ content = { ...content, ...field };
96
+ }
97
+ return content;
98
+ };
99
+
100
+ // src/codex-bridge.ts
101
+ import { spawn } from "child_process";
102
+ import { basename } from "path";
103
+ var MAX_RPC_LINE = 1024 * 1024;
104
+ var STDERR_TAIL_LIMIT = 2e3;
105
+ var FAILURE_MESSAGE_MAX = 240;
106
+ var MAX_PENDING_RPC = 8;
107
+ var QUESTION_UNAVAILABLE = "Question unavailable";
108
+ var LOCAL_QUESTION_UNAVAILABLE = "Pushary handed this question to the current client, but this Codex bridge has no local question UI. Continue in an interactive Codex session, or choose a Pushary mode that permits remote questions.";
109
+ var MAX_TRANSCRIPT_TEXT = 32 * 1024;
110
+ var MAX_MESSAGE_BUFFERS = 16;
111
+ var JsonRpcClient = class {
112
+ constructor(command, cwd, timeoutMs, bridgeOptions) {
113
+ this.bridgeOptions = bridgeOptions;
114
+ this.threadId = bridgeOptions.resumeThreadId ?? null;
115
+ const options = { cwd, env: process.env, stdio: ["pipe", "pipe", "pipe"] };
116
+ this.child = process.platform === "win32" ? spawnClaude(command.command, command.args ?? [], options) : spawn(command.command, command.args ?? [], options);
117
+ this.child.stdout?.setEncoding("utf8");
118
+ this.child.stdout?.on("data", (chunk) => this.read(String(chunk)));
119
+ this.child.stderr?.setEncoding("utf8");
120
+ this.child.stderr?.on("data", (chunk) => this.keepStderrTail(String(chunk)));
121
+ this.child.once("error", (error) => this.fail(error));
122
+ this.child.once("exit", (code, signal) => this.fail(new Error(this.exitMessage(code, signal))));
123
+ this.timeoutMs = timeoutMs;
124
+ }
125
+ child;
126
+ pending = /* @__PURE__ */ new Map();
127
+ notifications = /* @__PURE__ */ new Set();
128
+ serverRequests = /* @__PURE__ */ new Map();
129
+ threadId = null;
130
+ nextId = 1;
131
+ buffer = "";
132
+ closed = false;
133
+ stderrTail = "";
134
+ failure = null;
135
+ keepStderrTail(chunk) {
136
+ this.stderrTail = (this.stderrTail + chunk).slice(-STDERR_TAIL_LIMIT);
137
+ }
138
+ exitMessage(code, signal) {
139
+ const how = signal ? `signal ${signal}` : `code ${code ?? "unknown"}`;
140
+ const tail = this.stderrTail.trim();
141
+ return tail ? `Codex app-server exited (${how}): ${tail}` : `Codex app-server exited (${how})`;
142
+ }
143
+ timeoutMs;
144
+ get isClosed() {
145
+ return this.closed;
146
+ }
147
+ get closedReason() {
148
+ return this.failure?.message ?? "Codex app-server exited";
149
+ }
150
+ onNotification(listener) {
151
+ this.notifications.add(listener);
152
+ return () => this.notifications.delete(listener);
153
+ }
154
+ bindThread(threadId) {
155
+ this.threadId = threadId;
156
+ }
157
+ notify(method) {
158
+ this.write({ method });
159
+ }
160
+ request(method, params) {
161
+ if (this.closed) return Promise.reject(new Error("Codex app-server is closed"));
162
+ if (this.pending.size >= MAX_PENDING_RPC) return Promise.reject(new Error("Codex app-server request limit reached"));
163
+ const id = this.nextId++;
164
+ return new Promise((resolve, reject) => {
165
+ const timer = setTimeout(() => {
166
+ this.pending.delete(id);
167
+ reject(new Error(`${method} timed out`));
168
+ }, this.timeoutMs);
169
+ this.pending.set(id, { resolve, reject, timer });
170
+ this.write({ id, method, params });
171
+ });
172
+ }
173
+ async close() {
174
+ if (this.closed) return;
175
+ this.closed = true;
176
+ for (const request of this.serverRequests.values()) request.abort();
177
+ this.serverRequests.clear();
178
+ this.child.stdin?.end();
179
+ if (this.child.exitCode != null) return;
180
+ await Promise.race([
181
+ new Promise((resolve) => this.child.once("exit", () => resolve())),
182
+ new Promise((resolve) => setTimeout(resolve, 1e3))
183
+ ]);
184
+ if (this.child.exitCode == null) this.child.kill();
185
+ this.rejectPending(new Error("Codex app-server closed"));
186
+ }
187
+ write(value) {
188
+ this.child.stdin?.write(`${JSON.stringify(value)}
189
+ `);
190
+ }
191
+ read(chunk) {
192
+ this.buffer += chunk;
193
+ if (this.buffer.length > MAX_RPC_LINE && !this.buffer.includes("\n")) {
194
+ this.fail(new Error("Codex app-server sent an oversized message"));
195
+ return;
196
+ }
197
+ let newline = this.buffer.indexOf("\n");
198
+ while (newline >= 0) {
199
+ const line = this.buffer.slice(0, newline);
200
+ this.buffer = this.buffer.slice(newline + 1);
201
+ if (line.length > MAX_RPC_LINE) {
202
+ this.fail(new Error("Codex app-server sent an oversized message"));
203
+ return;
204
+ }
205
+ this.handle(line);
206
+ newline = this.buffer.indexOf("\n");
207
+ }
208
+ }
209
+ handle(line) {
210
+ let message;
211
+ try {
212
+ const parsed = JSON.parse(line);
213
+ if (!isRpcMessage(parsed)) return;
214
+ message = parsed;
215
+ } catch {
216
+ return;
217
+ }
218
+ if (message.id !== void 0 && (message.method === "item/tool/requestUserInput" || message.method === "mcpServer/elicitation/request")) {
219
+ const id = message.id;
220
+ if (this.serverRequests.has(id)) return;
221
+ if (this.serverRequests.size >= MAX_PENDING_RPC) {
222
+ this.write({ id, error: { code: -32e3, message: "Too many pending user questions" } });
223
+ return;
224
+ }
225
+ const controller = new AbortController();
226
+ this.serverRequests.set(id, controller);
227
+ const signal = AbortSignal.any([controller.signal, this.bridgeOptions.signal]);
228
+ const answer = message.method === "mcpServer/elicitation/request" ? answerCodexElicitation(this.bridgeOptions, message.params ?? {}, this.threadId, signal) : answerCodexQuestions(this.bridgeOptions, message.params ?? {}, signal);
229
+ void answer.then(
230
+ (result) => {
231
+ if (!signal.aborted && !this.closed) this.write({ id, result });
232
+ },
233
+ (error) => {
234
+ if (!signal.aborted && !this.closed) this.write({ id, error: { code: -32e3, message: error instanceof Error && error.message === LOCAL_QUESTION_UNAVAILABLE ? LOCAL_QUESTION_UNAVAILABLE : "No user answer was received through Pushary" } });
235
+ }
236
+ ).finally(() => this.serverRequests.delete(id));
237
+ return;
238
+ }
239
+ if (message.id !== void 0 && message.method) {
240
+ const result = message.method === "item/commandExecution/requestApproval" || message.method === "item/fileChange/requestApproval" ? { decision: "decline" } : message.method === "applyPatchApproval" || message.method === "execCommandApproval" ? { decision: { denied: { rejection: "No interactive Codex client is attached" } } } : null;
241
+ this.write(result ? { id: message.id, result } : { id: message.id, error: { code: -32601, message: "Unsupported server request" } });
242
+ return;
243
+ }
244
+ if (typeof message.id === "number") {
245
+ const pending = this.pending.get(message.id);
246
+ if (!pending) return;
247
+ this.pending.delete(message.id);
248
+ clearTimeout(pending.timer);
249
+ if (message.error) pending.reject(new Error(message.error.message ?? "Codex app-server request failed"));
250
+ else pending.resolve(message.result);
251
+ return;
252
+ }
253
+ if (message.method === "serverRequest/resolved") {
254
+ const id = message.params?.requestId;
255
+ if (typeof id === "number" || typeof id === "string") this.serverRequests.get(id)?.abort();
256
+ }
257
+ if (message.method) {
258
+ for (const listener of this.notifications) listener(message);
259
+ }
260
+ }
261
+ fail(error) {
262
+ if (this.closed) return;
263
+ this.closed = true;
264
+ this.failure = error;
265
+ for (const request of this.serverRequests.values()) request.abort();
266
+ this.serverRequests.clear();
267
+ this.rejectPending(error);
268
+ if (this.child.exitCode == null) this.child.kill();
269
+ }
270
+ rejectPending(error) {
271
+ for (const pending of this.pending.values()) {
272
+ clearTimeout(pending.timer);
273
+ pending.reject(error);
274
+ }
275
+ this.pending.clear();
276
+ }
277
+ };
278
+ var isJsonObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
279
+ var object = (value) => isJsonObject(value) ? value : null;
280
+ var isRpcMessage = (value) => isJsonObject(value) && (value.id === void 0 || typeof value.id === "string" || typeof value.id === "number" && Number.isFinite(value.id)) && (value.method === void 0 || typeof value.method === "string") && (value.params === void 0 || isJsonObject(value.params)) && (value.error === void 0 || isJsonObject(value.error) && (value.error.message === void 0 || typeof value.error.message === "string"));
281
+ var string = (value) => typeof value === "string" && value.length > 0 ? value : null;
282
+ var input = (text) => [{ type: "text", text, text_elements: [] }];
283
+ var rpcThreadId = (result) => string(object(object(result)?.thread)?.id);
284
+ var rpcTurnId = (result) => {
285
+ const response = object(result);
286
+ return string(object(response?.turn)?.id) ?? string(response?.turnId);
287
+ };
288
+ var answerCodexQuestions = async (options, params, signal, toolName = "request_user_input") => {
289
+ if (!Array.isArray(params.questions) || !params.questions.length || params.questions.length > 3) throw new Error("Invalid questions");
290
+ const answers = /* @__PURE__ */ Object.create(null);
291
+ const deadline = Date.now() + Math.min(12e4, typeof params.autoResolutionMs === "number" ? Math.max(0, params.autoResolutionMs) : 12e4);
292
+ for (const raw of params.questions) {
293
+ if (signal.aborted || Date.now() >= deadline) throw new Error("Question expired");
294
+ const question = object(raw);
295
+ const id = string(question?.id);
296
+ const prompt = string(question?.question);
297
+ if (!id || !prompt || id in answers || question?.isSecret === true) throw new Error("Unsupported question");
298
+ const labels = Array.isArray(question?.options) ? question.options.map((option) => string(object(option)?.label)).filter((label) => !!label) : [];
299
+ const structured = labels.length >= 2 ? parseAgentQuestion({ ...question, multiSelect: false, allowOther: question?.isOther === true }) : void 0;
300
+ let correlationId = null;
301
+ let settled = false;
302
+ const call = async (name, args, timeoutMs, waitSignal = signal) => {
303
+ const result = await callMcpTool(options.apiKey, name, args, { baseUrl: options.baseUrl, signal: waitSignal, timeoutMs, maxRetries: 1 });
304
+ if (name === "wait_for_answer" && !isWaitForAnswerResponse(result)) throw new Error("Invalid wait_for_answer response");
305
+ return result;
306
+ };
307
+ try {
308
+ signal.throwIfAborted();
309
+ if (Date.now() >= deadline) throw new Error("Question expired");
310
+ let result = await call("ask_user", {
311
+ requestId: randomUUID(),
312
+ question: prompt,
313
+ type: labels.length >= 2 ? "select" : "input",
314
+ ...labels.length >= 2 ? { options: labels } : {},
315
+ ...structured ? { questions: [structured] } : {},
316
+ context: string(question?.header),
317
+ agentName: `Codex - ${basename(options.cwd)}`,
318
+ sessionId: params.threadId,
319
+ machineId: options.machineId,
320
+ toolName,
321
+ wait: false,
322
+ waitEndsAt: new Date(deadline).toISOString()
323
+ }, Math.min(1e4, deadline - Date.now()));
324
+ correlationId = string(object(result)?.correlationId);
325
+ if (!isAskUserResponse(result)) throw new Error("Invalid ask_user response");
326
+ while (!result.answered) {
327
+ if (result.status === "terminal" || result.status === "notified" || result.suppressed || result.mode === "terminal_only" || result.mode === "notify_only") {
328
+ if (correlationId) {
329
+ const withdrawn = await withdrawQuestion(options.apiKey, correlationId, {
330
+ cancelQuestion: (_key, id2, abort2) => call("cancel_question", { correlationId: id2 }, 3e3, abort2),
331
+ waitForAnswer: (_key, id2, timeoutMs, abort2) => call("wait_for_answer", { correlationId: id2, timeoutMs }, 2e3, abort2)
332
+ });
333
+ result = { ...withdrawn };
334
+ settled = withdrawn.answered || withdrawn.status === "withdrawn" || isDecisionStopped(withdrawn);
335
+ if (withdrawn.answered) break;
336
+ if (isDecisionStopped(withdrawn)) throw new Error(QUESTION_UNAVAILABLE);
337
+ }
338
+ throw new Error(LOCAL_QUESTION_UNAVAILABLE);
339
+ }
340
+ if (!correlationId || result.handoffAction === "stop" || result.noDevices || result.status && result.status !== "pending") throw new Error(QUESTION_UNAVAILABLE);
341
+ const remaining = deadline - Date.now();
342
+ if (remaining <= 0) throw new Error("Question expired");
343
+ result = await call("wait_for_answer", { correlationId, timeoutMs: Math.min(25e3, remaining) }, Math.min(27e3, remaining));
344
+ if (!result.answered) await liveSessionSleep(100, signal);
345
+ }
346
+ if (signal.aborted || Date.now() >= deadline) throw new Error("Question expired");
347
+ settled = true;
348
+ const rawValue = string(result.value);
349
+ const value = rawValue && structured ? (parseAgentQuestionAnswers([structured], rawValue) ?? parseAgentQuestionAnswers([structured], JSON.stringify({ [prompt]: rawValue })))?.[prompt] : rawValue;
350
+ if (!value || value === "defer" || labels.length && question?.isOther !== true && !labels.includes(value)) throw new Error("Invalid answer");
351
+ answers[id] = { answers: [value] };
352
+ } finally {
353
+ if (correlationId && !settled) {
354
+ await call("cancel_question", { correlationId }, 3e3, AbortSignal.timeout(3e3)).catch(() => {
355
+ });
356
+ }
357
+ }
358
+ }
359
+ return { answers };
360
+ };
361
+ var answerCodexElicitation = async (options, params, threadId, signal) => {
362
+ const plan = planCodexElicitation(params, threadId);
363
+ if (!plan) {
364
+ writeDegraded("questions", { reason: "unsupported_codex_elicitation", fallback: "no form answer submitted", event: "mcpServer/elicitation/request" });
365
+ return { action: "cancel", content: null };
366
+ }
367
+ try {
368
+ const result = await answerCodexQuestions(options, {
369
+ threadId,
370
+ questions: plan.map((field) => field.question)
371
+ }, signal, "Elicitation");
372
+ const content = codexElicitationContent(plan, result.answers);
373
+ if (!content) throw new Error("Invalid elicitation answer");
374
+ return { action: "accept", content };
375
+ } catch {
376
+ writeDegraded("questions", { reason: "codex_elicitation_unanswered", fallback: "no form answer submitted", event: "mcpServer/elicitation/request" });
377
+ return { action: "cancel", content: null };
378
+ }
379
+ };
380
+ var runCodexBridge = async (options) => {
381
+ const timeoutMs = options.requestTimeoutMs ?? 1e4;
382
+ const now = options.now ?? Date.now;
383
+ const idleTimeoutMs = options.idleTimeoutMs ?? SESSION_IDLE_TIMEOUT_MS;
384
+ const rpc = new JsonRpcClient(options.appServer, options.cwd, timeoutMs, options);
385
+ let threadId = options.resumeThreadId ?? null;
386
+ let activeTurnId = null;
387
+ let lastCompletedTurnId = null;
388
+ let idleSince = now();
389
+ let idledOut = false;
390
+ let relay = null;
391
+ let linked = false;
392
+ let stopHeartbeat = () => {
393
+ };
394
+ let ownership = null;
395
+ const messages = /* @__PURE__ */ new Map();
396
+ const idleDeadlineReached = () => activeTurnId === null && idleDeadlinePassed(idleSince, now(), idleTimeoutMs);
397
+ const reportBody = (event, action) => ({
398
+ event,
399
+ action,
400
+ agentType: "codex",
401
+ agentName: `Codex - ${basename(options.cwd)}`,
402
+ sessionId: threadId,
403
+ codexThreadId: threadId,
404
+ spawnId: options.spawnId,
405
+ machineId: options.machineId,
406
+ pid: process.pid,
407
+ cwd: options.cwd
408
+ });
409
+ const report = (event, action) => postLiveSession(options, "/api/agent/event", reportBody(event, action));
410
+ const removeNotification = rpc.onNotification((message) => {
411
+ const params = message.params ?? {};
412
+ if (message.method === "turn/started") activeTurnId = string(object(params.turn)?.id);
413
+ if (message.method === "turn/completed") {
414
+ lastCompletedTurnId = string(object(params.turn)?.id) ?? activeTurnId;
415
+ activeTurnId = null;
416
+ idleSince = now();
417
+ void report("stop", "Turn completed").catch(() => {
418
+ });
419
+ }
420
+ if (message.method === "item/agentMessage/delta") {
421
+ const itemId = string(params.itemId);
422
+ const delta = string(params.delta);
423
+ if (!itemId || !delta) return;
424
+ if (!messages.has(itemId) && messages.size === MAX_MESSAGE_BUFFERS) {
425
+ const oldest = messages.keys().next().value;
426
+ if (typeof oldest === "string") messages.delete(oldest);
427
+ }
428
+ messages.set(itemId, `${messages.get(itemId) ?? ""}${delta}`.slice(0, MAX_TRANSCRIPT_TEXT));
429
+ }
430
+ if (message.method === "item/completed") {
431
+ const itemId = string(object(params.item)?.id);
432
+ const text = itemId ? messages.get(itemId) : null;
433
+ if (!itemId || !text) return;
434
+ messages.delete(itemId);
435
+ relay?.add({ type: "assistant", uuid: itemId, message: { role: "assistant", content: text } });
436
+ }
437
+ });
438
+ try {
439
+ await rpc.request("initialize", {
440
+ clientInfo: { name: "pushary", title: "Pushary", version: "1" },
441
+ capabilities: { experimentalApi: true, requestAttestation: false }
442
+ });
443
+ rpc.notify("initialized");
444
+ const thread = options.resumeThreadId ? await rpc.request("thread/resume", { threadId: options.resumeThreadId, cwd: options.cwd, excludeTurns: true }) : await rpc.request("thread/start", { cwd: options.cwd, model: options.model ?? null });
445
+ threadId = rpcThreadId(thread);
446
+ if (threadId) rpc.bindThread(threadId);
447
+ if (!threadId) throw new Error("Codex app-server did not return a thread id");
448
+ ownership = startProcessOwnership({ sessionId: threadId, pid: process.pid, spawnId: options.spawnId });
449
+ await ownership.ready;
450
+ relay = options.transcripts === false ? null : new LiveTranscriptRelay(options, threadId);
451
+ await postLiveSessionUntilAccepted(
452
+ options,
453
+ "/api/agent/event",
454
+ reportBody("session_start", options.resumeThreadId ? "Session resumed" : "Session started")
455
+ );
456
+ linked = true;
457
+ stopHeartbeat = startLiveSessionHeartbeat(
458
+ options,
459
+ reportBody("heartbeat", "Session online"),
460
+ void 0,
461
+ () => ownership?.touch()
462
+ );
463
+ const startTurn = async (text, commandId) => {
464
+ relay?.add({ type: "user", uuid: commandId, message: { role: "user", content: text } });
465
+ const result = activeTurnId ? await rpc.request("turn/steer", {
466
+ threadId,
467
+ expectedTurnId: activeTurnId,
468
+ input: input(text),
469
+ clientUserMessageId: commandId
470
+ }) : await rpc.request("turn/start", {
471
+ threadId,
472
+ input: input(text),
473
+ cwd: options.cwd,
474
+ model: options.model ?? null,
475
+ clientUserMessageId: commandId
476
+ });
477
+ const startedTurnId = rpcTurnId(result);
478
+ if (startedTurnId && startedTurnId !== lastCompletedTurnId) activeTurnId = startedTurnId;
479
+ };
480
+ if (options.prompt) await startTurn(options.prompt, `spawn-${options.spawnId}`);
481
+ let pendingAck = null;
482
+ while (!options.signal.aborted && !rpc.isClosed) {
483
+ if (idleDeadlineReached()) {
484
+ idledOut = true;
485
+ break;
486
+ }
487
+ try {
488
+ if (pendingAck) {
489
+ const acknowledged = await postLiveSession(options, "/api/agent/command/ack", pendingAck);
490
+ if (acknowledged.ok) pendingAck = null;
491
+ }
492
+ if (pendingAck) {
493
+ await liveSessionSleep(options.pollIntervalMs ?? 2e3, options.signal);
494
+ continue;
495
+ }
496
+ const response = await postLiveSession(options, "/api/agent/command/drain", {
497
+ sessionId: threadId,
498
+ machineId: options.machineId,
499
+ ackMode: true
500
+ });
501
+ if (response.ok) {
502
+ const command = object((await response.json()).command);
503
+ const commandId = string(command?.id);
504
+ const text = string(command?.text);
505
+ if (commandId && text) {
506
+ idleSince = now();
507
+ try {
508
+ await startTurn(text, commandId);
509
+ pendingAck = {
510
+ commandId,
511
+ sessionId: threadId,
512
+ machineId: options.machineId,
513
+ state: "delivered"
514
+ };
515
+ } catch {
516
+ pendingAck = {
517
+ commandId,
518
+ sessionId: threadId,
519
+ machineId: options.machineId,
520
+ state: "failed",
521
+ failureCode: "codex_rejected"
522
+ };
523
+ }
524
+ }
525
+ }
526
+ } catch {
527
+ }
528
+ await relay?.flush();
529
+ await liveSessionSleep(options.pollIntervalMs ?? 2e3, options.signal);
530
+ }
531
+ if (rpc.isClosed && !options.signal.aborted) throw new Error(rpc.closedReason);
532
+ if (activeTurnId) {
533
+ await rpc.request("turn/interrupt", { threadId, turnId: activeTurnId }).catch(() => null);
534
+ }
535
+ await relay?.flush();
536
+ await report(
537
+ "session_closed",
538
+ idledOut ? `Session ended after ${describeIdleWindow(idleTimeoutMs)} idle` : "Session stopped"
539
+ ).catch(() => null);
540
+ return "stopped";
541
+ } catch (error) {
542
+ const message = error instanceof Error ? error.message : String(error);
543
+ if (!linked && options.claimId) {
544
+ for (let attempt = 0; attempt < 3; attempt++) {
545
+ const acknowledged = await postLiveSession(options, "/api/agent/spawn/ack", {
546
+ spawnId: options.spawnId,
547
+ claimId: options.claimId,
548
+ machineId: options.machineId,
549
+ state: "failed",
550
+ failure: {
551
+ code: "bridge_failed",
552
+ message: message.slice(0, FAILURE_MESSAGE_MAX),
553
+ retryable: false
554
+ }
555
+ }).catch(() => null);
556
+ if (acknowledged?.ok) break;
557
+ await liveSessionSleep(200 * (attempt + 1), options.signal);
558
+ }
559
+ }
560
+ await report("error", `Live bridge failed: ${message}`.slice(0, FAILURE_MESSAGE_MAX)).catch(() => null);
561
+ return "failed";
562
+ } finally {
563
+ stopHeartbeat();
564
+ ownership?.stop();
565
+ removeNotification();
566
+ await rpc.close();
567
+ }
568
+ };
569
+
570
+ // bin/pushary-codex-bridge.ts
571
+ var spawnId = process.env.PUSHARY_SPAWN_ID?.trim();
572
+ var requestedCwd = process.env.PUSHARY_BRIDGE_CWD?.trim();
573
+ if (!spawnId || !requestedCwd || !existsSync(requestedCwd)) {
574
+ process.stderr.write("[pushary] Codex bridge received an invalid launch request\n");
575
+ process.exit(1);
576
+ }
577
+ var abort = new AbortController();
578
+ var signals = process.platform === "win32" ? ["SIGINT", "SIGTERM"] : ["SIGINT", "SIGTERM", "SIGHUP"];
579
+ var stop = () => abort.abort();
580
+ for (const signal of signals) process.on(signal, stop);
581
+ var outcome = await withSpawnProcessOwnership(spawnId, () => runCodexBridge({
582
+ apiKey: getApiKey(),
583
+ baseUrl: getBaseUrl(),
584
+ machineId: getMachineId(),
585
+ spawnId,
586
+ claimId: process.env.PUSHARY_SPAWN_CLAIM_ID?.trim() || void 0,
587
+ cwd: requestedCwd,
588
+ prompt: process.env.PUSHARY_BRIDGE_PROMPT?.trim() || void 0,
589
+ model: process.env.PUSHARY_BRIDGE_MODEL?.trim() || void 0,
590
+ resumeThreadId: process.env.PUSHARY_BRIDGE_RESUME_SESSION_ID?.trim() || void 0,
591
+ appServer: {
592
+ command: process.env.PUSHARY_CODEX_COMMAND?.trim() || resolveBinary("codex") || "codex",
593
+ args: ["app-server", "--stdio"]
594
+ },
595
+ signal: abort.signal,
596
+ transcripts: transcriptsEnabled()
597
+ }));
598
+ for (const signal of signals) process.off(signal, stop);
599
+ process.exit(outcome === "stopped" ? 0 : 1);
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node