@pushary/agent-hooks 1.5.0 → 1.6.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.
- package/CHANGELOG.md +22 -0
- package/README.md +2 -1
- package/dist/bin/pushary-bell-hook.js +18 -18
- package/dist/bin/pushary-bell.js +6 -6
- package/dist/bin/pushary-claude.js +18 -18
- package/dist/bin/pushary-clean.js +19 -19
- package/dist/bin/pushary-codex-bridge.js +10 -10
- package/dist/bin/pushary-codex-hook.js +23 -23
- package/dist/bin/pushary-codex.js +6 -6
- package/dist/bin/pushary-connect.js +6 -6
- package/dist/bin/pushary-cowork.js +3 -3
- package/dist/bin/pushary-daemon.js +23 -22
- package/dist/bin/pushary-disconnect.js +10 -10
- package/dist/bin/pushary-doctor.js +52 -24
- package/dist/bin/pushary-elicitation-hook.js +17 -17
- package/dist/bin/pushary-gemini-bridge.js +9 -9
- package/dist/bin/pushary-gemini-hook.js +20 -20
- package/dist/bin/pushary-hook.js +23 -23
- package/dist/bin/pushary-login.js +7 -7
- package/dist/bin/pushary-logout.js +4 -4
- package/dist/bin/pushary-mode.js +3 -3
- package/dist/bin/pushary-notification-hook.js +20 -20
- package/dist/bin/pushary-opencode-hook.js +19 -19
- package/dist/bin/pushary-permission-denied-hook.js +24 -24
- package/dist/bin/pushary-permission-hook.js +23 -23
- package/dist/bin/pushary-post-hook.js +20 -20
- package/dist/bin/pushary-prompt-hook.js +20 -20
- package/dist/bin/pushary-session-end-hook.js +20 -20
- package/dist/bin/pushary-session-start-hook.js +24 -23
- package/dist/bin/pushary-setup.js +63 -62
- package/dist/bin/pushary-stats.js +2 -2
- package/dist/bin/pushary-status.js +10 -10
- package/dist/bin/pushary-stop-hook.js +20 -20
- package/dist/bin/pushary-stopfailure-hook.js +20 -20
- package/dist/bin/pushary-transcript-register.js +16 -16
- package/dist/bin/pushary-transcripts.js +4 -4
- package/dist/bin/pushary-upgrade.js +80 -32
- package/dist/bin/pushary-wait.js +3 -3
- package/dist/{chunk-KEOLNHR3.js → chunk-5MH5P366.js} +2 -2
- package/dist/{chunk-HVBF35GT.js → chunk-5QCZYSYR.js} +1 -1
- package/dist/{chunk-IYTQ4B5I.js → chunk-644CGYOB.js} +66 -12
- package/dist/{chunk-FDHMNT24.js → chunk-66BIMA62.js} +6 -5
- package/dist/{chunk-UQHUUZ5H.js → chunk-7JSE6JTZ.js} +1 -1
- package/dist/{chunk-NFKVRMTM.js → chunk-A2GS2ENL.js} +6 -6
- package/dist/{chunk-TFKBFQCE.js → chunk-A5URWZTP.js} +1 -1
- package/dist/{chunk-MYP4UUFH.js → chunk-ALG3IBLB.js} +1 -1
- package/dist/{chunk-TUXFIVOH.js → chunk-B6TYEKJR.js} +1 -1
- package/dist/{chunk-CQYHOHOK.js → chunk-BE4P7ERZ.js} +3 -3
- package/dist/{chunk-EADZPVYW.js → chunk-BK5F3FGE.js} +3 -3
- package/dist/{chunk-F57RGL7K.js → chunk-BW3Y2D24.js} +4 -4
- package/dist/chunk-BY2CRWBO.js +38 -0
- package/dist/{chunk-43LJSM4F.js → chunk-CSW6A2EW.js} +1 -1
- package/dist/{chunk-7XT76LWT.js → chunk-DZ75BJ7V.js} +3 -3
- package/dist/{chunk-DTQNDR7C.js → chunk-E7MJBWSR.js} +1 -1
- package/dist/{chunk-DYHXOXUF.js → chunk-F2OPOBRO.js} +7 -21
- package/dist/{chunk-43ZDACBO.js → chunk-F4KRNFDE.js} +1 -1
- package/dist/{chunk-ORLJNJEO.js → chunk-FDF72XHK.js} +2 -2
- package/dist/{chunk-JF736N4C.js → chunk-FI3LQCUH.js} +5 -5
- package/dist/{chunk-DLJN5XEU.js → chunk-G5LENVCZ.js} +3 -3
- package/dist/{chunk-K3QVDAZW.js → chunk-GDXSCXQC.js} +1 -1
- package/dist/{chunk-5HYNICS7.js → chunk-GOXINLDU.js} +1 -1
- package/dist/{chunk-2QT3GCU4.js → chunk-GP6SFVEN.js} +1 -1
- package/dist/{chunk-J4J45VPZ.js → chunk-HWG7X3VI.js} +3 -3
- package/dist/{chunk-PCGZXWGQ.js → chunk-KZBGITM4.js} +4 -4
- package/dist/{chunk-NTQSICPJ.js → chunk-MOQOJOMD.js} +3 -3
- package/dist/{chunk-3NBODGQS.js → chunk-NDS27FXU.js} +1 -1
- package/dist/{chunk-H5LHTC5X.js → chunk-NYD7W7AT.js} +1 -1
- package/dist/{chunk-PNNBMH4E.js → chunk-OP7HFIWE.js} +28 -12
- package/dist/{chunk-SOCEY746.js → chunk-OR3A3RLH.js} +1 -1
- package/dist/{chunk-XWEONSLV.js → chunk-PCVVCS4A.js} +1 -1
- package/dist/{chunk-KJRALILH.js → chunk-PRZXYILJ.js} +2 -2
- package/dist/{chunk-OSSDK5RS.js → chunk-RBPJO4KG.js} +6 -2
- package/dist/{chunk-TIWURSLS.js → chunk-SFNRAEEW.js} +1 -1
- package/dist/{chunk-USQDVBEV.js → chunk-TDKE3V6W.js} +1 -1
- package/dist/{chunk-HU5LSYL2.js → chunk-VMNI33F5.js} +1 -1
- package/dist/{chunk-UYDTFCHW.js → chunk-VZANUMIF.js} +1 -1
- package/dist/{chunk-3ZSGKLSO.js → chunk-XGL5JC6U.js} +2 -2
- package/dist/chunk-XQOT4CCK.js +305 -0
- package/dist/{chunk-T4QY64OR.js → chunk-YFD7CRIZ.js} +376 -10
- package/dist/{reapply-D2TFN6XK.js → reapply-RRDVJATI.js} +12 -8
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +12 -12
- package/package.json +1 -1
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import {
|
|
2
|
+
spawnClaude
|
|
3
|
+
} from "./chunk-XHKBHWLX.js";
|
|
4
|
+
import {
|
|
5
|
+
codexHome,
|
|
6
|
+
codexHooksJsonIn,
|
|
7
|
+
isPusharyCodexCommand,
|
|
8
|
+
resolvePathBinary
|
|
9
|
+
} from "./chunk-F2OPOBRO.js";
|
|
10
|
+
import {
|
|
11
|
+
getPackageVersion
|
|
12
|
+
} from "./chunk-HWJW3CPO.js";
|
|
13
|
+
|
|
14
|
+
// src/codex-app-server.ts
|
|
15
|
+
import { existsSync, realpathSync } from "fs";
|
|
16
|
+
import { join } from "path";
|
|
17
|
+
var CODEX_HOOK_STATUS = {
|
|
18
|
+
trusted: "trusted",
|
|
19
|
+
untrusted: "untrusted",
|
|
20
|
+
modified: "modified",
|
|
21
|
+
managed: "managed",
|
|
22
|
+
disabled: "disabled",
|
|
23
|
+
notListed: "not listed"
|
|
24
|
+
};
|
|
25
|
+
var CODEX_APP_SERVER_ARGS = ["app-server"];
|
|
26
|
+
var CODEX_APP_SERVER_TIMEOUT_MS = 1e4;
|
|
27
|
+
var TERMINATE_GRACE_MS = 1e3;
|
|
28
|
+
var MAX_RPC_LINE = 4 * 1024 * 1024;
|
|
29
|
+
var STDERR_TAIL_LIMIT = 400;
|
|
30
|
+
var PUSHARY_CLIENT_NAME = "pushary";
|
|
31
|
+
var METHOD_INITIALIZE = "initialize";
|
|
32
|
+
var METHOD_INITIALIZED = "initialized";
|
|
33
|
+
var METHOD_HOOKS_LIST = "hooks/list";
|
|
34
|
+
var METHOD_CONFIG_BATCH_WRITE = "config/batchWrite";
|
|
35
|
+
var HOOKS_STATE_KEY_PATH = "hooks.state";
|
|
36
|
+
var CODEX_INSTALLATION_ID_FILE = "installation_id";
|
|
37
|
+
var CODEX_NOT_ASKED = {
|
|
38
|
+
notInteractive: "Pushary only starts Codex when you run setup, upgrade or doctor yourself at a terminal",
|
|
39
|
+
noCodexOnPath: "there is no codex command on PATH",
|
|
40
|
+
neverOpened: "Codex has not been opened on this machine yet",
|
|
41
|
+
insideAnApp: "the codex command resolves inside an app bundle, which Pushary does not run"
|
|
42
|
+
};
|
|
43
|
+
var UNRECOGNISED_LISTING = "Codex answered hooks/list in a shape Pushary does not recognise";
|
|
44
|
+
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
45
|
+
var isCodexListedHook = (value) => isRecord(value) && typeof value.key === "string" && typeof value.eventName === "string" && typeof value.command === "string" && typeof value.sourcePath === "string" && typeof value.enabled === "boolean" && typeof value.isManaged === "boolean" && typeof value.currentHash === "string" && typeof value.trustStatus === "string";
|
|
46
|
+
var listedHookFields = (hook) => ({
|
|
47
|
+
key: hook.key,
|
|
48
|
+
eventName: hook.eventName,
|
|
49
|
+
command: hook.command,
|
|
50
|
+
sourcePath: hook.sourcePath,
|
|
51
|
+
enabled: hook.enabled,
|
|
52
|
+
isManaged: hook.isManaged,
|
|
53
|
+
currentHash: hook.currentHash,
|
|
54
|
+
trustStatus: hook.trustStatus
|
|
55
|
+
});
|
|
56
|
+
var diagnosticMessages = (value) => {
|
|
57
|
+
if (!Array.isArray(value)) return [];
|
|
58
|
+
return value.flatMap((entry) => {
|
|
59
|
+
if (typeof entry === "string") return [entry];
|
|
60
|
+
if (isRecord(entry) && typeof entry.message === "string") return [entry.message];
|
|
61
|
+
return [];
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
var hooksListingOf = (result) => {
|
|
65
|
+
if (!isRecord(result) || !Array.isArray(result.data)) return null;
|
|
66
|
+
const hooks = [];
|
|
67
|
+
const warnings = [];
|
|
68
|
+
for (const layer of result.data) {
|
|
69
|
+
if (!isRecord(layer) || !Array.isArray(layer.hooks)) return null;
|
|
70
|
+
hooks.push(...layer.hooks.filter(isCodexListedHook).map(listedHookFields));
|
|
71
|
+
warnings.push(...diagnosticMessages(layer.warnings), ...diagnosticMessages(layer.errors));
|
|
72
|
+
}
|
|
73
|
+
return { hooks, warnings };
|
|
74
|
+
};
|
|
75
|
+
var isPusharyHookIn = (hooksJsonPath, hook) => hook.sourcePath === hooksJsonPath && isPusharyCodexCommand(hook.command);
|
|
76
|
+
var isTrustableByPushary = (hook) => hook.enabled && !hook.isManaged && hook.trustStatus !== CODEX_HOOK_STATUS.managed;
|
|
77
|
+
var pusharyHooksIn = (hooks, hooksJsonPath) => hooks.filter((hook) => isPusharyHookIn(hooksJsonPath, hook));
|
|
78
|
+
var selectPusharyCodexHooks = (hooks, hooksJsonPath) => pusharyHooksIn(hooks, hooksJsonPath).filter(isTrustableByPushary);
|
|
79
|
+
var codexTrustVerdict = (hooks, hooksJsonPath) => {
|
|
80
|
+
if (pusharyHooksIn(hooks, hooksJsonPath).length === 0) return { kind: "unlisted" };
|
|
81
|
+
const untrusted = selectPusharyCodexHooks(hooks, hooksJsonPath).filter((hook) => hook.trustStatus !== CODEX_HOOK_STATUS.trusted);
|
|
82
|
+
return untrusted.length === 0 ? { kind: "trusted" } : { kind: "untrusted", hooks: untrusted };
|
|
83
|
+
};
|
|
84
|
+
var codexTrustEdit = (hooks) => ({
|
|
85
|
+
edits: [{
|
|
86
|
+
keyPath: HOOKS_STATE_KEY_PATH,
|
|
87
|
+
mergeStrategy: "upsert",
|
|
88
|
+
value: Object.fromEntries(hooks.map((hook) => [hook.key, { trusted_hash: hook.currentHash }]))
|
|
89
|
+
}],
|
|
90
|
+
reloadUserConfig: true
|
|
91
|
+
});
|
|
92
|
+
var initializeParams = (clientVersion) => ({
|
|
93
|
+
clientInfo: { name: PUSHARY_CLIENT_NAME, title: null, version: clientVersion }
|
|
94
|
+
});
|
|
95
|
+
var hooksListParams = (cwd) => ({ cwds: [cwd] });
|
|
96
|
+
var hookEventOf = (eventName) => eventName.charAt(0).toUpperCase() + eventName.slice(1);
|
|
97
|
+
var readingOf = (hook) => ({
|
|
98
|
+
event: hookEventOf(hook.eventName),
|
|
99
|
+
status: hook.enabled ? hook.trustStatus : CODEX_HOOK_STATUS.disabled
|
|
100
|
+
});
|
|
101
|
+
var codexHookTrustByEvent = (events, hooks) => events.map((event) => hooks.map(readingOf).find((reading) => reading.event === event) ?? { event, status: CODEX_HOOK_STATUS.notListed });
|
|
102
|
+
var CODEX_TRUST_FAILURES = /* @__PURE__ */ new Set([CODEX_HOOK_STATUS.untrusted, CODEX_HOOK_STATUS.modified]);
|
|
103
|
+
var isCodexTrustFailure = (reading) => CODEX_TRUST_FAILURES.has(reading.status);
|
|
104
|
+
var eventsWithStatus = (readings, status) => readings.filter((reading) => reading.status === status).map((reading) => reading.event);
|
|
105
|
+
var assessCodexHookTrust = (events, hooks) => {
|
|
106
|
+
const readings = codexHookTrustByEvent(events, hooks);
|
|
107
|
+
const notListed = eventsWithStatus(readings, CODEX_HOOK_STATUS.notListed);
|
|
108
|
+
if (readings.length > 0 && notListed.length === readings.length) return { kind: "unlisted" };
|
|
109
|
+
const disabled = eventsWithStatus(readings, CODEX_HOOK_STATUS.disabled);
|
|
110
|
+
const failures = readings.filter(isCodexTrustFailure);
|
|
111
|
+
if (failures.length > 0) return { kind: "untrusted", failures, notListed, disabled };
|
|
112
|
+
const trusted = eventsWithStatus(readings, CODEX_HOOK_STATUS.trusted).length;
|
|
113
|
+
return { kind: "trusted", trusted, total: readings.length, notListed, disabled };
|
|
114
|
+
};
|
|
115
|
+
var mayAskCodex = (conditions) => {
|
|
116
|
+
if (!conditions.interactive) return { kind: "skipped", reason: CODEX_NOT_ASKED.notInteractive };
|
|
117
|
+
if (!conditions.codexOnPath) return { kind: "skipped", reason: CODEX_NOT_ASKED.noCodexOnPath };
|
|
118
|
+
if (!conditions.codexOpenedBefore) return { kind: "skipped", reason: CODEX_NOT_ASKED.neverOpened };
|
|
119
|
+
if (conditions.codexOnPath.split(/[\\/]/).some((part) => part.toLowerCase().endsWith(".app"))) {
|
|
120
|
+
return { kind: "skipped", reason: CODEX_NOT_ASKED.insideAnApp };
|
|
121
|
+
}
|
|
122
|
+
return { kind: "ask", binary: conditions.codexOnPath };
|
|
123
|
+
};
|
|
124
|
+
var canonicalPath = (path) => {
|
|
125
|
+
try {
|
|
126
|
+
return realpathSync(path);
|
|
127
|
+
} catch {
|
|
128
|
+
return path;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
var withCanonicalSources = (hooks) => hooks.map((hook) => ({ ...hook, sourcePath: canonicalPath(hook.sourcePath) }));
|
|
132
|
+
var hasExited = (child) => child.exitCode !== null || child.signalCode !== null;
|
|
133
|
+
var waitForExit = (child, ms) => new Promise((resolve) => {
|
|
134
|
+
if (hasExited(child)) return resolve(true);
|
|
135
|
+
const timer = setTimeout(() => resolve(false), ms);
|
|
136
|
+
child.once("exit", () => {
|
|
137
|
+
clearTimeout(timer);
|
|
138
|
+
resolve(true);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
var terminate = async (child) => {
|
|
142
|
+
if (child.pid === void 0 || hasExited(child)) return;
|
|
143
|
+
child.stdin?.end();
|
|
144
|
+
child.kill("SIGTERM");
|
|
145
|
+
if (await waitForExit(child, TERMINATE_GRACE_MS)) return;
|
|
146
|
+
child.kill("SIGKILL");
|
|
147
|
+
await waitForExit(child, TERMINATE_GRACE_MS);
|
|
148
|
+
};
|
|
149
|
+
var rpcErrorMessage = (error) => isRecord(error) && typeof error.message === "string" ? error.message : "Codex returned an error";
|
|
150
|
+
var describeExit = (code, signal, stderr) => {
|
|
151
|
+
const how = signal ? `signal ${signal}` : `code ${code ?? "unknown"}`;
|
|
152
|
+
const tail = stderr.trim();
|
|
153
|
+
return tail ? `Codex app-server exited (${how}): ${tail}` : `Codex app-server exited (${how})`;
|
|
154
|
+
};
|
|
155
|
+
var runCodexAppServer = (launch, conversation) => {
|
|
156
|
+
const child = spawnClaude(launch.binary, CODEX_APP_SERVER_ARGS, {
|
|
157
|
+
cwd: launch.codexHome,
|
|
158
|
+
env: { ...process.env, CODEX_HOME: launch.codexHome },
|
|
159
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
160
|
+
windowsHide: true
|
|
161
|
+
});
|
|
162
|
+
const pending = /* @__PURE__ */ new Map();
|
|
163
|
+
let nextId = 1;
|
|
164
|
+
let buffer = "";
|
|
165
|
+
let stderrTail = "";
|
|
166
|
+
let stoppedReason = null;
|
|
167
|
+
let stop = () => {
|
|
168
|
+
};
|
|
169
|
+
const stopped = new Promise((resolve) => {
|
|
170
|
+
stop = (reason) => {
|
|
171
|
+
if (stoppedReason !== null) return;
|
|
172
|
+
stoppedReason = reason;
|
|
173
|
+
for (const settle of pending.values()) settle({ kind: "error", message: reason });
|
|
174
|
+
pending.clear();
|
|
175
|
+
resolve({ kind: "unavailable", reason });
|
|
176
|
+
};
|
|
177
|
+
});
|
|
178
|
+
const write = (message) => {
|
|
179
|
+
if (stoppedReason === null) child.stdin?.write(`${JSON.stringify(message)}
|
|
180
|
+
`);
|
|
181
|
+
};
|
|
182
|
+
const handleLine = (line) => {
|
|
183
|
+
let message;
|
|
184
|
+
try {
|
|
185
|
+
message = JSON.parse(line);
|
|
186
|
+
} catch {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (!isRecord(message) || typeof message.id !== "number" || "method" in message) return;
|
|
190
|
+
const settle = pending.get(message.id);
|
|
191
|
+
if (!settle) return;
|
|
192
|
+
pending.delete(message.id);
|
|
193
|
+
settle("error" in message && message.error !== void 0 && message.error !== null ? { kind: "error", message: rpcErrorMessage(message.error) } : { kind: "result", value: message.result });
|
|
194
|
+
};
|
|
195
|
+
child.stdin?.on("error", () => {
|
|
196
|
+
});
|
|
197
|
+
child.stdout?.setEncoding("utf8");
|
|
198
|
+
child.stdout?.on("data", (chunk) => {
|
|
199
|
+
buffer += chunk;
|
|
200
|
+
let newline = buffer.indexOf("\n");
|
|
201
|
+
while (newline >= 0) {
|
|
202
|
+
handleLine(buffer.slice(0, newline));
|
|
203
|
+
buffer = buffer.slice(newline + 1);
|
|
204
|
+
newline = buffer.indexOf("\n");
|
|
205
|
+
}
|
|
206
|
+
if (buffer.length > MAX_RPC_LINE) stop("Codex app-server sent an oversized message");
|
|
207
|
+
});
|
|
208
|
+
child.stderr?.setEncoding("utf8");
|
|
209
|
+
child.stderr?.on("data", (chunk) => {
|
|
210
|
+
stderrTail = (stderrTail + chunk).slice(-STDERR_TAIL_LIMIT);
|
|
211
|
+
});
|
|
212
|
+
child.once("error", (error) => stop(`could not start ${launch.binary}: ${error.message}`));
|
|
213
|
+
child.once("close", (code, signal) => stop(describeExit(code, signal, stderrTail)));
|
|
214
|
+
const timer = setTimeout(
|
|
215
|
+
() => stop(`Codex app-server did not answer within ${launch.timeoutMs / 1e3}s`),
|
|
216
|
+
launch.timeoutMs
|
|
217
|
+
);
|
|
218
|
+
const session = {
|
|
219
|
+
request: (method, params) => {
|
|
220
|
+
if (stoppedReason !== null) return Promise.resolve({ kind: "error", message: stoppedReason });
|
|
221
|
+
const id = nextId++;
|
|
222
|
+
return new Promise((resolve) => {
|
|
223
|
+
pending.set(id, resolve);
|
|
224
|
+
write({ id, method, params });
|
|
225
|
+
});
|
|
226
|
+
},
|
|
227
|
+
notify: (method) => write({ method })
|
|
228
|
+
};
|
|
229
|
+
const conversed = conversation(session).catch((error) => ({
|
|
230
|
+
kind: "unavailable",
|
|
231
|
+
reason: error instanceof Error ? error.message : String(error)
|
|
232
|
+
}));
|
|
233
|
+
return Promise.race([conversed, stopped]).finally(async () => {
|
|
234
|
+
clearTimeout(timer);
|
|
235
|
+
await terminate(child);
|
|
236
|
+
});
|
|
237
|
+
};
|
|
238
|
+
var launchOf = (options) => {
|
|
239
|
+
const home = options.codexHome ?? codexHome();
|
|
240
|
+
const binary = options.codexOnPath === void 0 ? resolvePathBinary("codex") ?? null : options.codexOnPath;
|
|
241
|
+
const decision = mayAskCodex({
|
|
242
|
+
interactive: options.interactive ?? process.stdout.isTTY === true,
|
|
243
|
+
codexOnPath: binary ? canonicalPath(binary) : null,
|
|
244
|
+
codexOpenedBefore: existsSync(join(home, CODEX_INSTALLATION_ID_FILE))
|
|
245
|
+
});
|
|
246
|
+
if (decision.kind === "skipped") return decision;
|
|
247
|
+
return { binary: decision.binary, codexHome: home, timeoutMs: options.timeoutMs ?? CODEX_APP_SERVER_TIMEOUT_MS };
|
|
248
|
+
};
|
|
249
|
+
var isSkipped = (value) => "kind" in value && value.kind === "skipped";
|
|
250
|
+
var openSession = async (session) => {
|
|
251
|
+
const initialized = await session.request(METHOD_INITIALIZE, initializeParams(getPackageVersion()));
|
|
252
|
+
if (initialized.kind === "error") return { kind: "unavailable", reason: `Codex refused initialize: ${initialized.message}` };
|
|
253
|
+
session.notify(METHOD_INITIALIZED);
|
|
254
|
+
return null;
|
|
255
|
+
};
|
|
256
|
+
var listHooks = async (session, launch) => {
|
|
257
|
+
const listed = await session.request(METHOD_HOOKS_LIST, hooksListParams(launch.codexHome));
|
|
258
|
+
if (listed.kind === "error") return { kind: "unavailable", reason: `Codex could not list hooks: ${listed.message}` };
|
|
259
|
+
const listing = hooksListingOf(listed.value);
|
|
260
|
+
if (!listing) return { kind: "unavailable", reason: UNRECOGNISED_LISTING };
|
|
261
|
+
return { hooks: withCanonicalSources(listing.hooks), warnings: listing.warnings };
|
|
262
|
+
};
|
|
263
|
+
var isListing = (value) => !("kind" in value);
|
|
264
|
+
var confirmationAfterWrite = (listing, hooksJsonPath, writeError) => {
|
|
265
|
+
const verdict = codexTrustVerdict(listing.hooks, hooksJsonPath);
|
|
266
|
+
if (verdict.kind === "trusted") return { kind: "verified", wrote: true };
|
|
267
|
+
if (verdict.kind === "unlisted") return { kind: "unlisted", warnings: listing.warnings };
|
|
268
|
+
return { kind: "refused", hooks: verdict.hooks.map(readingOf), writeError };
|
|
269
|
+
};
|
|
270
|
+
var trustConversation = (launch, hooksJsonPath) => async (session) => {
|
|
271
|
+
const unavailable = await openSession(session);
|
|
272
|
+
if (unavailable) return unavailable;
|
|
273
|
+
const before = await listHooks(session, launch);
|
|
274
|
+
if (!isListing(before)) return before;
|
|
275
|
+
const verdict = codexTrustVerdict(before.hooks, hooksJsonPath);
|
|
276
|
+
if (verdict.kind === "trusted") return { kind: "verified", wrote: false };
|
|
277
|
+
if (verdict.kind === "unlisted") return { kind: "unlisted", warnings: before.warnings };
|
|
278
|
+
const written = await session.request(METHOD_CONFIG_BATCH_WRITE, codexTrustEdit(verdict.hooks));
|
|
279
|
+
const after = await listHooks(session, launch);
|
|
280
|
+
if (!isListing(after)) return after;
|
|
281
|
+
return confirmationAfterWrite(after, hooksJsonPath, written.kind === "error" ? written.message : null);
|
|
282
|
+
};
|
|
283
|
+
var listingConversation = (launch, hooksJsonPath) => async (session) => {
|
|
284
|
+
const unavailable = await openSession(session);
|
|
285
|
+
if (unavailable) return unavailable;
|
|
286
|
+
const listing = await listHooks(session, launch);
|
|
287
|
+
if (!isListing(listing)) return listing;
|
|
288
|
+
return { kind: "listed", hooks: pusharyHooksIn(listing.hooks, hooksJsonPath) };
|
|
289
|
+
};
|
|
290
|
+
var ensureCodexTrustsPusharyHooks = async (options = {}) => {
|
|
291
|
+
const launch = launchOf(options);
|
|
292
|
+
if (isSkipped(launch)) return launch;
|
|
293
|
+
return runCodexAppServer(launch, trustConversation(launch, canonicalPath(codexHooksJsonIn(launch.codexHome))));
|
|
294
|
+
};
|
|
295
|
+
var readCodexTrustForPusharyHooks = async (options = {}) => {
|
|
296
|
+
const launch = launchOf(options);
|
|
297
|
+
if (isSkipped(launch)) return launch;
|
|
298
|
+
return runCodexAppServer(launch, listingConversation(launch, canonicalPath(codexHooksJsonIn(launch.codexHome))));
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
export {
|
|
302
|
+
assessCodexHookTrust,
|
|
303
|
+
ensureCodexTrustsPusharyHooks,
|
|
304
|
+
readCodexTrustForPusharyHooks
|
|
305
|
+
};
|