@sjawhar/codex-envoy 0.0.0-stage → 5.0.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/.codex-plugin/plugin.json +89 -0
- package/README.md +23 -2
- package/dist/THIRD_PARTY_NOTICES +786 -0
- package/dist/codex-hook.js +30553 -0
- package/dist/codex-tool-hook.js +135 -0
- package/dist/dispatch.js +32230 -0
- package/dist/envoy-channel.js +67186 -0
- package/dist/session-hook.js +30806 -0
- package/dist/session-title-hook.js +373 -0
- package/hooks/hooks.json +48 -0
- package/package.json +16 -4
- package/skills/agent-secrets/SKILL.md +106 -0
- package/skills/agent-secrets/references/store-a-secret.md +9 -0
- package/skills/approval-review/SKILL.md +35 -0
- package/skills/approval-review/references/never-decide.md +154 -0
- package/skills/asd-ste100/LICENSE +21 -0
- package/skills/asd-ste100/SKILL.md +81 -0
- package/skills/asd-ste100/examples/before-after.md +57 -0
- package/skills/dispatch/SKILL.md +92 -0
- package/skills/dispatch-first/SKILL.md +48 -0
- package/skills/dispatch-writing-specs/SKILL.md +77 -0
- package/skills/envoy/SKILL.md +93 -0
- package/skills/envoy/references/check-settlement.md +45 -0
- package/skills/envoy/references/deliveries.md +28 -0
- package/skills/envoy/references/legion.md +17 -0
- package/skills/envoy/references/roles.md +14 -0
- package/skills/envoy/references/sources.md +33 -0
- package/skills/outside-message/SKILL.md +45 -0
- package/skills/plain-words/SKILL.md +54 -0
- package/skills/thermonuclear-code-quality/LICENSE +21 -0
- package/skills/thermonuclear-code-quality/SKILL.md +59 -0
- package/skills/thermonuclear-code-quality/agents/openai.yaml +5 -0
- package/skills/thermonuclear-deep-review/LICENSE +21 -0
- package/skills/thermonuclear-deep-review/SKILL.md +76 -0
- package/skills/thermonuclear-deep-review/agents/openai.yaml +5 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/codex/codex-inbox.ts
|
|
3
|
+
import { randomBytes } from "crypto";
|
|
4
|
+
import { mkdir, readdir, readFile, rename, rm, writeFile } from "fs/promises";
|
|
5
|
+
import { join } from "path";
|
|
6
|
+
var TAKEN_DIRECTORY = { hook: "taken", server: "queued" };
|
|
7
|
+
function codexInboxDirectory(stateDirectory, sessionId) {
|
|
8
|
+
return join(stateDirectory, "codex-inbox", encodeURIComponent(sessionId));
|
|
9
|
+
}
|
|
10
|
+
var lastOrder = 0;
|
|
11
|
+
function inboxItemName() {
|
|
12
|
+
const order = Math.max(Date.now(), lastOrder + 1);
|
|
13
|
+
lastOrder = order;
|
|
14
|
+
return `${String(order).padStart(15, "0")}-${randomBytes(4).toString("hex")}.json`;
|
|
15
|
+
}
|
|
16
|
+
async function putInbox(directory, item, name = inboxItemName()) {
|
|
17
|
+
const waiting = join(directory, "waiting");
|
|
18
|
+
await mkdir(waiting, { recursive: true, mode: 448 });
|
|
19
|
+
const temporary = join(directory, `.${name}.tmp`);
|
|
20
|
+
await writeFile(temporary, JSON.stringify(item), { mode: 384 });
|
|
21
|
+
await rename(temporary, join(waiting, name));
|
|
22
|
+
return name;
|
|
23
|
+
}
|
|
24
|
+
async function takenBy(directory, name) {
|
|
25
|
+
for (const taker of ["hook", "server"]) {
|
|
26
|
+
try {
|
|
27
|
+
await readFile(join(directory, TAKEN_DIRECTORY[taker], name));
|
|
28
|
+
return taker;
|
|
29
|
+
} catch {}
|
|
30
|
+
}
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
async function withdrawWaiting(directory, name) {
|
|
34
|
+
try {
|
|
35
|
+
await rm(join(directory, "waiting", name));
|
|
36
|
+
return true;
|
|
37
|
+
} catch {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async function discardWaiting(directory, keep = () => false) {
|
|
42
|
+
const waiting = join(directory, "waiting");
|
|
43
|
+
let names;
|
|
44
|
+
try {
|
|
45
|
+
names = await readdir(waiting);
|
|
46
|
+
} catch {
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
let removed = 0;
|
|
50
|
+
for (const name of names) {
|
|
51
|
+
if (!name.endsWith(".json") || keep(name))
|
|
52
|
+
continue;
|
|
53
|
+
try {
|
|
54
|
+
await rm(join(waiting, name));
|
|
55
|
+
removed++;
|
|
56
|
+
} catch {}
|
|
57
|
+
}
|
|
58
|
+
return removed;
|
|
59
|
+
}
|
|
60
|
+
var HOOK_CONTEXT_MAX_BYTES = 8000;
|
|
61
|
+
async function takeInbox(directory, taker, maxContextBytes) {
|
|
62
|
+
const waiting = join(directory, "waiting");
|
|
63
|
+
let names;
|
|
64
|
+
try {
|
|
65
|
+
names = (await readdir(waiting)).filter((name) => name.endsWith(".json")).sort();
|
|
66
|
+
} catch {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
if (names.length === 0)
|
|
70
|
+
return [];
|
|
71
|
+
const destination = join(directory, TAKEN_DIRECTORY[taker]);
|
|
72
|
+
await mkdir(destination, { recursive: true, mode: 448 });
|
|
73
|
+
const taken = [];
|
|
74
|
+
for (const name of names) {
|
|
75
|
+
if (maxContextBytes !== undefined) {
|
|
76
|
+
let waitingItem;
|
|
77
|
+
try {
|
|
78
|
+
waitingItem = JSON.parse(await readFile(join(waiting, name), "utf8"));
|
|
79
|
+
} catch {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (typeof waitingItem?.content !== "string")
|
|
83
|
+
continue;
|
|
84
|
+
const items = [...taken.map(({ item }) => item), waitingItem];
|
|
85
|
+
if (Buffer.byteLength(inboxContext(items)) > maxContextBytes)
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
await rename(join(waiting, name), join(destination, name));
|
|
90
|
+
} catch {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
const parsed = JSON.parse(await readFile(join(destination, name), "utf8"));
|
|
95
|
+
if (typeof parsed === "object" && parsed !== null && typeof parsed.content === "string") {
|
|
96
|
+
taken.push({ item: parsed, name });
|
|
97
|
+
}
|
|
98
|
+
} catch {}
|
|
99
|
+
}
|
|
100
|
+
return taken;
|
|
101
|
+
}
|
|
102
|
+
function inboxContext(items) {
|
|
103
|
+
return [
|
|
104
|
+
"Messages delivered to this session while it worked (Envoy, through the Envoy plugin):",
|
|
105
|
+
...items.map((item) => item.dispatchMessageId === undefined ? item.content : `A person wrote to you from Dispatch (message ${item.dispatchMessageId}):
|
|
106
|
+
${item.content}`)
|
|
107
|
+
].join(`
|
|
108
|
+
|
|
109
|
+
`);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// hooks/codex-tool-hook.ts
|
|
113
|
+
async function postToolUse(text) {
|
|
114
|
+
const input = JSON.parse(text);
|
|
115
|
+
const sessionId = typeof input === "object" && input !== null ? input.session_id : undefined;
|
|
116
|
+
const pluginData = process.env["PLUGIN_DATA"] || process.env["CLAUDE_PLUGIN_DATA"];
|
|
117
|
+
if (typeof sessionId !== "string" || sessionId === "" || !pluginData)
|
|
118
|
+
return;
|
|
119
|
+
const taken = await takeInbox(codexInboxDirectory(pluginData, sessionId), "hook", HOOK_CONTEXT_MAX_BYTES);
|
|
120
|
+
if (taken.length === 0)
|
|
121
|
+
return;
|
|
122
|
+
process.stdout.write(JSON.stringify({
|
|
123
|
+
hookSpecificOutput: {
|
|
124
|
+
additionalContext: inboxContext(taken.map(({ item }) => item)),
|
|
125
|
+
hookEventName: "PostToolUse"
|
|
126
|
+
}
|
|
127
|
+
}));
|
|
128
|
+
}
|
|
129
|
+
try {
|
|
130
|
+
await postToolUse(await Bun.stdin.text());
|
|
131
|
+
} catch (error) {
|
|
132
|
+
process.stderr.write(`envoy: codex-tool-hook: ${error instanceof Error ? error.message : String(error)}
|
|
133
|
+
`);
|
|
134
|
+
}
|
|
135
|
+
process.exit(0);
|