@phren/cli 0.3.11 → 0.3.13
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/dist/bridge/account-usage.d.ts +124 -0
- package/dist/bridge/account-usage.js +258 -0
- package/dist/bridge/agent-hook-stores.d.ts +3 -0
- package/dist/bridge/agent-hook-stores.js +5 -0
- package/dist/bridge/agent-hooks.d.ts +162 -5
- package/dist/bridge/agent-hooks.js +682 -49
- package/dist/bridge/approval-summary.d.ts +16 -0
- package/dist/bridge/approval-summary.js +133 -0
- package/dist/bridge/authority-command.d.ts +20 -0
- package/dist/bridge/authority-command.js +120 -0
- package/dist/bridge/authority.d.ts +223 -0
- package/dist/bridge/authority.js +231 -0
- package/dist/bridge/claude-account-setup.d.ts +14 -0
- package/dist/bridge/claude-account-setup.js +69 -0
- package/dist/bridge/claude-accounts.d.ts +49 -0
- package/dist/bridge/claude-accounts.js +195 -0
- package/dist/bridge/code-routes.js +2 -2
- package/dist/bridge/codex-app-server.d.ts +144 -0
- package/dist/bridge/codex-app-server.js +319 -0
- package/dist/bridge/codex-auth-refresh.d.ts +33 -0
- package/dist/bridge/codex-auth-refresh.js +71 -0
- package/dist/bridge/codex-hook-trust.d.ts +27 -0
- package/dist/bridge/codex-hook-trust.js +237 -0
- package/dist/bridge/codex-question-reply.d.ts +16 -0
- package/dist/bridge/codex-question-reply.js +57 -0
- package/dist/bridge/codex-review-mode.d.ts +10 -0
- package/dist/bridge/codex-review-mode.js +74 -0
- package/dist/bridge/codex-servers.d.ts +217 -0
- package/dist/bridge/codex-servers.js +636 -0
- package/dist/bridge/command.js +97 -4
- package/dist/bridge/computer-identity.d.ts +75 -0
- package/dist/bridge/computer-identity.js +166 -0
- package/dist/bridge/conductor-group.d.ts +91 -8
- package/dist/bridge/conductor-group.js +105 -9
- package/dist/bridge/conductor-role.d.ts +94 -0
- package/dist/bridge/conductor-role.js +176 -0
- package/dist/bridge/conductor-sets.d.ts +20 -0
- package/dist/bridge/conductor-sets.js +59 -0
- package/dist/bridge/dispatch-command.d.ts +3 -0
- package/dist/bridge/dispatch-command.js +82 -12
- package/dist/bridge/dispatch-returns.d.ts +128 -19
- package/dist/bridge/dispatch-returns.js +371 -54
- package/dist/bridge/dispatch.d.ts +128 -3
- package/dist/bridge/dispatch.js +303 -42
- package/dist/bridge/fanouts.d.ts +7 -1
- package/dist/bridge/fanouts.js +39 -4
- package/dist/bridge/folder-trust.d.ts +56 -0
- package/dist/bridge/folder-trust.js +195 -0
- package/dist/bridge/grants.d.ts +22 -1
- package/dist/bridge/grants.js +57 -9
- package/dist/bridge/hand-off-queue.d.ts +74 -0
- package/dist/bridge/hand-off-queue.js +235 -0
- package/dist/bridge/hand-off.d.ts +30 -10
- package/dist/bridge/hand-off.js +79 -46
- package/dist/bridge/harness-status.d.ts +11 -0
- package/dist/bridge/harness-status.js +32 -0
- package/dist/bridge/harnesses.d.ts +39 -0
- package/dist/bridge/harnesses.js +65 -0
- package/dist/bridge/health.d.ts +2 -0
- package/dist/bridge/health.js +1 -1
- package/dist/bridge/herdr.d.ts +11 -2
- package/dist/bridge/herdr.js +98 -23
- package/dist/bridge/hook-fast.d.ts +4 -0
- package/dist/bridge/hook-fast.js +68 -0
- package/dist/bridge/install.d.ts +16 -1
- package/dist/bridge/install.js +102 -21
- package/dist/bridge/launch-brief.d.ts +96 -0
- package/dist/bridge/launch-brief.js +164 -0
- package/dist/bridge/model-switch.d.ts +3 -0
- package/dist/bridge/model-switch.js +17 -1
- package/dist/bridge/models.d.ts +8 -4
- package/dist/bridge/models.js +24 -8
- package/dist/bridge/mux-wire.d.ts +9 -0
- package/dist/bridge/mux-wire.js +19 -0
- package/dist/bridge/opencode-pane-server.d.ts +113 -0
- package/dist/bridge/opencode-pane-server.js +332 -0
- package/dist/bridge/opencode-panes.d.ts +111 -0
- package/dist/bridge/opencode-panes.js +295 -0
- package/dist/bridge/pane-accounts.d.ts +8 -0
- package/dist/bridge/pane-accounts.js +46 -0
- package/dist/bridge/pane-status.d.ts +12 -0
- package/dist/bridge/pane-status.js +50 -1
- package/dist/bridge/prompt-startup.d.ts +5 -0
- package/dist/bridge/prompt-startup.js +24 -0
- package/dist/bridge/protocol.d.ts +5 -0
- package/dist/bridge/protocol.js +4 -0
- package/dist/bridge/push.d.ts +11 -4
- package/dist/bridge/push.js +27 -4
- package/dist/bridge/questions.d.ts +37 -2
- package/dist/bridge/questions.js +158 -15
- package/dist/bridge/resources.d.ts +9 -3
- package/dist/bridge/resources.js +24 -8
- package/dist/bridge/schedule-format.d.ts +2 -0
- package/dist/bridge/schedule-format.js +3 -0
- package/dist/bridge/schedule-launch.d.ts +2 -1
- package/dist/bridge/schedule-launch.js +27 -53
- package/dist/bridge/schedule-watch.d.ts +24 -1
- package/dist/bridge/schedule-watch.js +89 -2
- package/dist/bridge/server-launch.d.ts +22 -5
- package/dist/bridge/server-launch.js +238 -32
- package/dist/bridge/server-overview.d.ts +10 -3
- package/dist/bridge/server-overview.js +32 -15
- package/dist/bridge/server-pane-routes.d.ts +3 -0
- package/dist/bridge/server-pane-routes.js +150 -18
- package/dist/bridge/server-routes.d.ts +11 -0
- package/dist/bridge/server-routes.js +214 -36
- package/dist/bridge/server-stream.d.ts +2 -0
- package/dist/bridge/server-stream.js +22 -8
- package/dist/bridge/server.d.ts +6 -1
- package/dist/bridge/server.js +58 -13
- package/dist/bridge/session-activity.d.ts +93 -0
- package/dist/bridge/session-activity.js +139 -0
- package/dist/bridge/session-rename.d.ts +48 -0
- package/dist/bridge/session-rename.js +190 -0
- package/dist/bridge/session-servers.js +2 -2
- package/dist/bridge/settings-switch.d.ts +60 -0
- package/dist/bridge/settings-switch.js +287 -0
- package/dist/bridge/speech-voice.d.ts +55 -0
- package/dist/bridge/speech-voice.js +132 -0
- package/dist/bridge/speech.d.ts +70 -11
- package/dist/bridge/speech.js +169 -41
- package/dist/bridge/stalls.d.ts +22 -0
- package/dist/bridge/stalls.js +57 -0
- package/dist/bridge/sudo.d.ts +209 -0
- package/dist/bridge/sudo.js +501 -0
- package/dist/bridge/terminal-herdr.js +9 -3
- package/dist/bridge/terminal-tmux.d.ts +15 -3
- package/dist/bridge/terminal-tmux.js +103 -13
- package/dist/bridge/terminal.d.ts +27 -4
- package/dist/bridge/terminal.js +8 -1
- package/dist/bridge/transcript-claude.d.ts +4 -0
- package/dist/bridge/transcript-claude.js +186 -16
- package/dist/bridge/transcript-codex.d.ts +0 -2
- package/dist/bridge/transcript-codex.js +29 -4
- package/dist/bridge/transcript-preview.d.ts +1 -0
- package/dist/bridge/transcript-preview.js +24 -4
- package/dist/bridge/transcripts.d.ts +15 -2
- package/dist/bridge/transcripts.js +47 -16
- package/dist/bridge/turn-records.d.ts +85 -0
- package/dist/bridge/turn-records.js +143 -0
- package/dist/bridge/uploads.d.ts +3 -0
- package/dist/bridge/uploads.js +14 -0
- package/dist/bridge/usage.d.ts +56 -10
- package/dist/bridge/usage.js +190 -45
- package/dist/bridge-hook.mjs +27975 -20636
- package/dist/cli/claude-unmanaged.d.ts +12 -0
- package/dist/cli/claude-unmanaged.js +105 -0
- package/dist/cli/schedules.js +2 -1
- package/dist/cli/session-start.js +10 -1
- package/dist/cli/session-stop.js +9 -1
- package/dist/cli-registry.js +31 -6
- package/dist/data/task-receipts.d.ts +19 -0
- package/dist/data/task-receipts.js +68 -0
- package/dist/data/tasks.js +4 -1
- package/dist/generated/memory-ui-graph.browser.js +63 -63
- package/dist/graph-core/model.js +24 -3
- package/dist/graph-core/types.d.ts +4 -1
- package/dist/graph-core/types.js +1 -0
- package/dist/init/init-preset.js +7 -3
- package/dist/init/init-uninstall.js +2 -11
- package/dist/init/teardown.d.ts +3 -0
- package/dist/init/teardown.js +47 -0
- package/dist/link/context.js +21 -9
- package/dist/mcp/plugin-mode.js +1 -1
- package/dist/memory-ui-graph.runtime.js +63 -63
- package/dist/modules/code-package.d.ts +1 -0
- package/dist/modules/code-package.js +36 -7
- package/dist/modules/registry.js +17 -16
- package/dist/profile-store.d.ts +6 -0
- package/dist/profile-store.js +25 -1
- package/dist/shell/graph/glyphs.js +4 -0
- package/dist/shell/graph/graph-view.js +2 -0
- package/dist/status.js +7 -1
- package/dist/sync/task-claim.js +3 -2
- package/dist/task/lifecycle.js +25 -4
- package/dist/test-global-setup.js +5 -0
- package/dist/tools/dispatch.js +52 -4
- package/dist/tools/tasks.js +10 -1
- package/package.json +1 -1
- package/plugins/opencode/phren-transcript.js +87 -4
- package/starter/global/AGENTS.md +4 -0
- package/starter/global/skills/conductor/SKILL.md +51 -4
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { lstat, readFile, realpath } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { codexHome } from "../home-paths.js";
|
|
5
|
+
import { logger } from "../logger.js";
|
|
6
|
+
import { pretrustEnabled } from "./folder-trust.js";
|
|
7
|
+
import { atomic, object, objects } from "./protocol.js";
|
|
8
|
+
/**
|
|
9
|
+
* Keeping the owner's trust in Phren's own Codex hooks when an install
|
|
10
|
+
* rewrites them.
|
|
11
|
+
*
|
|
12
|
+
* Codex 0.158+ runs a `hooks.json` handler only when `config.toml` holds a
|
|
13
|
+
* matching `trusted_hash` for it, under
|
|
14
|
+
* `[hooks.state."<hooks.json path>:<event_snake>:<group>:<handler>"]`. The
|
|
15
|
+
* hash covers the handler's command, timeout and matcher, so an install that
|
|
16
|
+
* changes Phren's timeout (3 s to 15 s) or moves its group turns a handler the
|
|
17
|
+
* owner trusted into a "modified" one: Codex skips it and every new TUI opens
|
|
18
|
+
* on "Hooks need review".
|
|
19
|
+
*
|
|
20
|
+
* The rule never grants trust the owner did not give. A Phren handler whose
|
|
21
|
+
* key has no matching hash is trusted only when a hash stored for the same
|
|
22
|
+
* event in the same hooks.json is one of:
|
|
23
|
+
*
|
|
24
|
+
* - the same command with a timeout Phren has shipped (3, 10, 15, 60 or none);
|
|
25
|
+
* - a Phren handler for that event in hooks.json as it was before this
|
|
26
|
+
* install rewrote it (a changed node path, a moved group).
|
|
27
|
+
*
|
|
28
|
+
* A hash cannot come from anything but that event and that command, so a
|
|
29
|
+
* match means the owner trusted Phren's handler there. Other handlers are
|
|
30
|
+
* never touched. `PHREN_PRETRUST=off` turns this off with folder trust.
|
|
31
|
+
*/
|
|
32
|
+
/** Timeouts Phren's Codex callbacks have carried in any release; undefined is "no timeout key". */
|
|
33
|
+
const SHIPPED_TIMEOUTS = [3, 10, 15, 60, undefined];
|
|
34
|
+
const quote = (s) => "'" + s.replace(/'/g, "'\\''") + "'";
|
|
35
|
+
/** `SessionStart` to `session_start`, the event name in Codex's trust keys. */
|
|
36
|
+
export function codexEventName(event) {
|
|
37
|
+
return event.replace(/([a-z0-9])([A-Z])/g, "$1_$2").toLowerCase();
|
|
38
|
+
}
|
|
39
|
+
/** JSON with every object's keys sorted and no whitespace: serde_json's output for Codex's identity value. */
|
|
40
|
+
function canonicalJson(value) {
|
|
41
|
+
if (Array.isArray(value))
|
|
42
|
+
return `[${value.map(canonicalJson).join(",")}]`;
|
|
43
|
+
if (value && typeof value === "object") {
|
|
44
|
+
const record = value;
|
|
45
|
+
return `{${Object.keys(record).sort().map(key => `${JSON.stringify(key)}:${canonicalJson(record[key])}`).join(",")}}`;
|
|
46
|
+
}
|
|
47
|
+
// JSON.stringify escapes strings as serde_json does: `"`, `\` and control
|
|
48
|
+
// characters only, lowercase \u00xx, non-ASCII left as UTF-8.
|
|
49
|
+
return JSON.stringify(value);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Codex's `hook_hash` for one handler in one group (codex-rs hooks
|
|
53
|
+
* discovery + config fingerprint): sha256 of the canonical JSON of
|
|
54
|
+
* `{ event_name, matcher?, hooks: [handler] }`, where the handler always
|
|
55
|
+
* carries `timeout` (default 600, at least 1) and `async` (default false).
|
|
56
|
+
*/
|
|
57
|
+
export function codexHookHash(event, group, handler) {
|
|
58
|
+
const name = codexEventName(event);
|
|
59
|
+
const shortLived = name === "session_end" || name === "interrupt";
|
|
60
|
+
const given = typeof handler.timeout === "number" ? handler.timeout : undefined;
|
|
61
|
+
const timeout = shortLived ? Math.min(3, Math.max(1, given ?? 1)) : Math.max(1, given ?? 600);
|
|
62
|
+
const hook = { type: handler.type ?? "command", command: handler.command, timeout, async: handler.async ?? false };
|
|
63
|
+
for (const key of ["statusMessage", "commandWindows", "additionalContextLimit"]) {
|
|
64
|
+
if (handler[key] !== undefined && handler[key] !== null)
|
|
65
|
+
hook[key] = handler[key];
|
|
66
|
+
}
|
|
67
|
+
const identity = { event_name: name, hooks: [hook] };
|
|
68
|
+
if (typeof group.matcher === "string")
|
|
69
|
+
identity.matcher = group.matcher;
|
|
70
|
+
return `sha256:${createHash("sha256").update(canonicalJson(identity), "utf8").digest("hex")}`;
|
|
71
|
+
}
|
|
72
|
+
/** Phren's own handlers in a Codex hooks.json text; none when it does not parse. */
|
|
73
|
+
function ownHandlers(text, program) {
|
|
74
|
+
if (text === undefined)
|
|
75
|
+
return [];
|
|
76
|
+
let parsed;
|
|
77
|
+
try {
|
|
78
|
+
parsed = JSON.parse(text);
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return [];
|
|
82
|
+
}
|
|
83
|
+
const suffix = ` ${quote(program)} hook codex`;
|
|
84
|
+
const found = [];
|
|
85
|
+
for (const [event, groups] of Object.entries(object(object(parsed).hooks))) {
|
|
86
|
+
objects(groups).forEach((group, groupIndex) => objects(group.hooks).forEach((handler, handlerIndex) => {
|
|
87
|
+
if (typeof handler.command === "string" && handler.command.endsWith(suffix))
|
|
88
|
+
found.push({ event, group, handler, groupIndex, handlerIndex });
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
return found;
|
|
92
|
+
}
|
|
93
|
+
const TABLE = /^[ \t]*\[[ \t]*hooks[ \t]*\.[ \t]*state[ \t]*\.[ \t]*("(?:[^"\\\r\n]|\\.)*"|'[^'\r\n]*')[ \t]*\][ \t]*(?:#.*)?$/;
|
|
94
|
+
const HASH_LINE = /^[ \t]*trusted_hash[ \t]*=[ \t]*"([^"\r\n]*)"/;
|
|
95
|
+
/** The `[hooks.state."<key>"]` tables of a config.toml, by line. */
|
|
96
|
+
function stateTables(lines) {
|
|
97
|
+
const tables = [];
|
|
98
|
+
let current;
|
|
99
|
+
lines.forEach((line, index) => {
|
|
100
|
+
if (/^[ \t]*\[/.test(line)) {
|
|
101
|
+
if (current)
|
|
102
|
+
current.end = index;
|
|
103
|
+
current = undefined;
|
|
104
|
+
const match = TABLE.exec(line);
|
|
105
|
+
if (!match)
|
|
106
|
+
return;
|
|
107
|
+
let key;
|
|
108
|
+
try {
|
|
109
|
+
key = match[1].startsWith("'") ? match[1].slice(1, -1) : JSON.parse(match[1]);
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
current = { key, header: index, end: lines.length };
|
|
115
|
+
tables.push(current);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const hash = current && current.hash === undefined ? HASH_LINE.exec(line) : null;
|
|
119
|
+
if (current && hash) {
|
|
120
|
+
current.hash = hash[1];
|
|
121
|
+
current.hashLine = index;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
return tables;
|
|
125
|
+
}
|
|
126
|
+
function tomlKey(value) {
|
|
127
|
+
return `"${value.replace(/[\\"\u0000-\u001f\u007f]/g, c => c === "\\" ? "\\\\" : c === "\"" ? "\\\"" : `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`)}"`;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* The config text with trust carried forward to Phren's handlers in
|
|
131
|
+
* `hooks` (the hooks.json text as it is now), or undefined when nothing
|
|
132
|
+
* changes. `before` is hooks.json as it stood before this install rewrote
|
|
133
|
+
* it, when there was a rewrite. `hooksPaths` are the names Codex may key
|
|
134
|
+
* this hooks.json by; the first is used for a new key.
|
|
135
|
+
*/
|
|
136
|
+
export function codexHookTrustText(config, hooks, program, hooksPaths, before) {
|
|
137
|
+
const own = ownHandlers(hooks, program);
|
|
138
|
+
if (!own.length)
|
|
139
|
+
return undefined;
|
|
140
|
+
const newline = config.includes("\r\n") ? "\r\n" : "\n";
|
|
141
|
+
const lines = config.split(/\r?\n/);
|
|
142
|
+
const tables = stateTables(lines);
|
|
143
|
+
const split = (key) => {
|
|
144
|
+
const match = /^(.*):([a-z_]+):(\d+):(\d+)$/.exec(key);
|
|
145
|
+
return match && hooksPaths.includes(match[1]) ? { file: match[1], event: match[2] } : undefined;
|
|
146
|
+
};
|
|
147
|
+
const stored = tables.flatMap(table => { const parts = split(table.key); return parts && table.hash ? [{ ...parts, hash: table.hash }] : []; });
|
|
148
|
+
if (!stored.length)
|
|
149
|
+
return undefined;
|
|
150
|
+
const keyPath = stored[0].file;
|
|
151
|
+
const previous = ownHandlers(before, program);
|
|
152
|
+
const edits = new Map(), appended = [], carried = [];
|
|
153
|
+
for (const entry of own) {
|
|
154
|
+
const name = codexEventName(entry.event);
|
|
155
|
+
const key = `${keyPath}:${name}:${entry.groupIndex}:${entry.handlerIndex}`;
|
|
156
|
+
const want = codexHookHash(entry.event, entry.group, entry.handler);
|
|
157
|
+
const table = tables.find(t => t.key === key);
|
|
158
|
+
if (table?.hash === want)
|
|
159
|
+
continue;
|
|
160
|
+
const accepted = new Set([
|
|
161
|
+
...SHIPPED_TIMEOUTS.map(timeout => codexHookHash(entry.event, entry.group, { ...entry.handler, timeout })),
|
|
162
|
+
...previous.filter(p => p.event === entry.event).map(p => codexHookHash(p.event, p.group, p.handler)),
|
|
163
|
+
]);
|
|
164
|
+
if (!stored.some(s => s.event === name && accepted.has(s.hash)))
|
|
165
|
+
continue;
|
|
166
|
+
const line = `trusted_hash = "${want}"`;
|
|
167
|
+
if (table?.hashLine !== undefined)
|
|
168
|
+
edits.set(table.hashLine, lines[table.hashLine].replace(/"[^"]*"/, `"${want}"`));
|
|
169
|
+
else if (table)
|
|
170
|
+
edits.set(table.header, `${lines[table.header]}${newline}${line}`);
|
|
171
|
+
else
|
|
172
|
+
appended.push(`[hooks.state.${tomlKey(key)}]${newline}${line}${newline}`);
|
|
173
|
+
carried.push(key);
|
|
174
|
+
}
|
|
175
|
+
if (!carried.length)
|
|
176
|
+
return undefined;
|
|
177
|
+
const next = lines.map((line, index) => edits.get(index) ?? line);
|
|
178
|
+
if (appended.length) {
|
|
179
|
+
// New tables go right after the last hooks.state table, next to their siblings.
|
|
180
|
+
const last = tables[tables.length - 1];
|
|
181
|
+
const insertAt = last.end;
|
|
182
|
+
const block = appended.join(newline);
|
|
183
|
+
if (insertAt < next.length)
|
|
184
|
+
next.splice(insertAt, 0, ...block.split(newline).slice(0, -1), "");
|
|
185
|
+
else {
|
|
186
|
+
const text = next.join(newline);
|
|
187
|
+
const separator = text.endsWith(newline + newline) || text === "" ? "" : text.endsWith(newline) ? newline : newline + newline;
|
|
188
|
+
return { text: text + separator + block, carried };
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return { text: next.join(newline), carried };
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Carries the owner's Codex trust forward to Phren's handlers in
|
|
195
|
+
* `$CODEX_HOME/hooks.json`. Runs after every install, update, rollback and
|
|
196
|
+
* module reconcile, whether or not hooks.json changed, so a computer an
|
|
197
|
+
* earlier install left untrusted is repaired too. Never throws.
|
|
198
|
+
*/
|
|
199
|
+
export async function carryCodexHookTrust(program, before, env = process.env) {
|
|
200
|
+
if (!pretrustEnabled(env))
|
|
201
|
+
return [];
|
|
202
|
+
try {
|
|
203
|
+
const directory = codexHome(env);
|
|
204
|
+
const hooksFile = path.join(directory, "hooks.json");
|
|
205
|
+
const hooks = await readFile(hooksFile, "utf8").catch(() => undefined);
|
|
206
|
+
if (hooks === undefined)
|
|
207
|
+
return [];
|
|
208
|
+
const hooksPaths = [...new Set([hooksFile, await realpath(hooksFile).catch(() => hooksFile)])];
|
|
209
|
+
const configured = path.join(directory, "config.toml");
|
|
210
|
+
const file = await realpath(configured).catch(() => configured);
|
|
211
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
212
|
+
const text = await readFile(file, "utf8").catch(error => {
|
|
213
|
+
if (error.code === "ENOENT")
|
|
214
|
+
return undefined;
|
|
215
|
+
throw error;
|
|
216
|
+
});
|
|
217
|
+
// No config means the owner never trusted anything.
|
|
218
|
+
if (text === undefined)
|
|
219
|
+
return [];
|
|
220
|
+
const result = codexHookTrustText(text, hooks, program, hooksPaths, before);
|
|
221
|
+
if (!result)
|
|
222
|
+
return [];
|
|
223
|
+
const metadata = await lstat(file);
|
|
224
|
+
// Codex may have rewritten the file meanwhile; start over from its text.
|
|
225
|
+
if (await readFile(file, "utf8").catch(() => "") !== text)
|
|
226
|
+
continue;
|
|
227
|
+
await atomic(file, result.text, metadata.mode & 0o777);
|
|
228
|
+
logger.info("install", `Kept Codex trust for Phren's rewritten hooks: ${result.carried.join(", ")}.`);
|
|
229
|
+
return result.carried;
|
|
230
|
+
}
|
|
231
|
+
throw new Error("config.toml kept changing while it was being updated");
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
logger.warn("install", `Could not carry Codex hook trust forward: ${error instanceof Error ? error.message.split("\n")[0] : String(error)}`);
|
|
235
|
+
return [];
|
|
236
|
+
}
|
|
237
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface QuestionReplyEntry {
|
|
2
|
+
answer: string;
|
|
3
|
+
question: string;
|
|
4
|
+
id?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function formatQuestionReply(id: string, entries: {
|
|
7
|
+
question: string;
|
|
8
|
+
answer: string;
|
|
9
|
+
}[]): string;
|
|
10
|
+
/** The entries of a question reply, or undefined for any other message.
|
|
11
|
+
* Anything after the closing tag (the files attached to the answer, which
|
|
12
|
+
* Codex joins into the same message) is not part of the entries. */
|
|
13
|
+
export declare function parseQuestionReply(text: string): QuestionReplyEntry[] | undefined;
|
|
14
|
+
/** A question reply as chat text: each question quoted, then its answer,
|
|
15
|
+
* then whatever followed the reply in the same text. */
|
|
16
|
+
export declare function readableQuestionReply(text: string): string | undefined;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { objects } from "./protocol.js";
|
|
2
|
+
/**
|
|
3
|
+
* Codex's own answer to an async question (`request_user_input_async`), the
|
|
4
|
+
* user message its TUI sends into the running turn:
|
|
5
|
+
*
|
|
6
|
+
* <send_user_message_question_reply>
|
|
7
|
+
* [{"answer":"…","question":"…","questionItemId":"[\"request_user_input_async\",\"call_…\",0]"}]
|
|
8
|
+
* </send_user_message_question_reply>
|
|
9
|
+
*
|
|
10
|
+
* The Hook sends the same message for the phone, reads it back to know which
|
|
11
|
+
* questions are answered, and shows it in chat as the question and answer.
|
|
12
|
+
*/
|
|
13
|
+
const OPEN = "<send_user_message_question_reply>", CLOSE = "</send_user_message_question_reply>";
|
|
14
|
+
export function formatQuestionReply(id, entries) {
|
|
15
|
+
return `${OPEN}\n${JSON.stringify(entries.map((entry, index) => ({ answer: entry.answer, question: entry.question,
|
|
16
|
+
questionItemId: JSON.stringify(["request_user_input_async", id, index]) })))}\n${CLOSE}`;
|
|
17
|
+
}
|
|
18
|
+
/** The entries of a question reply, or undefined for any other message.
|
|
19
|
+
* Anything after the closing tag (the files attached to the answer, which
|
|
20
|
+
* Codex joins into the same message) is not part of the entries. */
|
|
21
|
+
export function parseQuestionReply(text) {
|
|
22
|
+
const trimmed = text.trim(), end = trimmed.indexOf(CLOSE);
|
|
23
|
+
if (!trimmed.startsWith(OPEN) || end < 0)
|
|
24
|
+
return undefined;
|
|
25
|
+
let rows;
|
|
26
|
+
try {
|
|
27
|
+
rows = JSON.parse(trimmed.slice(OPEN.length, end));
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
if (!Array.isArray(rows))
|
|
33
|
+
return undefined;
|
|
34
|
+
const entries = objects(rows).flatMap(row => {
|
|
35
|
+
if (typeof row.answer !== "string" || typeof row.question !== "string")
|
|
36
|
+
return [];
|
|
37
|
+
let id;
|
|
38
|
+
try {
|
|
39
|
+
const item = JSON.parse(String(row.questionItemId));
|
|
40
|
+
if (Array.isArray(item) && typeof item[1] === "string")
|
|
41
|
+
id = item[1];
|
|
42
|
+
}
|
|
43
|
+
catch { /* An answer without a readable item id still reads as text. */ }
|
|
44
|
+
return [{ answer: row.answer, question: row.question, ...(id ? { id } : {}) }];
|
|
45
|
+
});
|
|
46
|
+
return entries.length ? entries : undefined;
|
|
47
|
+
}
|
|
48
|
+
/** A question reply as chat text: each question quoted, then its answer,
|
|
49
|
+
* then whatever followed the reply in the same text. */
|
|
50
|
+
export function readableQuestionReply(text) {
|
|
51
|
+
const entries = parseQuestionReply(text);
|
|
52
|
+
if (!entries)
|
|
53
|
+
return undefined;
|
|
54
|
+
const trimmed = text.trim(), rest = trimmed.slice(trimmed.indexOf(CLOSE) + CLOSE.length).trim();
|
|
55
|
+
const answers = entries.map(entry => entry.question.split("\n").map(line => `> ${line}`).join("\n") + "\n\n" + entry.answer).join("\n\n");
|
|
56
|
+
return rest ? `${answers}\n\n${rest}` : answers;
|
|
57
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Whether Codex's automatic reviewer, not the owner, decides this session's
|
|
2
|
+
* approval requests. Codex runs the PermissionRequest hook before its reviewer
|
|
3
|
+
* and the payload does not say which one will decide (permission_mode is
|
|
4
|
+
* "default" either way), so read the settings the session itself recorded: the
|
|
5
|
+
* latest turn_context or thread_settings_applied line in its rollout, which
|
|
6
|
+
* follows /approvals changes mid-session. Codex routes a request to the
|
|
7
|
+
* reviewer only with approvals_reviewer "auto_review" and an on-request or
|
|
8
|
+
* granular approval policy; anything else, or a rollout that can't be read,
|
|
9
|
+
* keeps the owner as the approver. */
|
|
10
|
+
export declare function codexAutoReview(transcriptPath: unknown): Promise<boolean>;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { open } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
// How far back from the end of a rollout to look for the session's settings.
|
|
4
|
+
// A long Codex session writes tens of megabytes; one turn rarely spans more.
|
|
5
|
+
const SCAN_LIMIT = 64 * 1_048_576;
|
|
6
|
+
const CHUNK = 1_048_576;
|
|
7
|
+
/** Whether Codex's automatic reviewer, not the owner, decides this session's
|
|
8
|
+
* approval requests. Codex runs the PermissionRequest hook before its reviewer
|
|
9
|
+
* and the payload does not say which one will decide (permission_mode is
|
|
10
|
+
* "default" either way), so read the settings the session itself recorded: the
|
|
11
|
+
* latest turn_context or thread_settings_applied line in its rollout, which
|
|
12
|
+
* follows /approvals changes mid-session. Codex routes a request to the
|
|
13
|
+
* reviewer only with approvals_reviewer "auto_review" and an on-request or
|
|
14
|
+
* granular approval policy; anything else, or a rollout that can't be read,
|
|
15
|
+
* keeps the owner as the approver. */
|
|
16
|
+
export async function codexAutoReview(transcriptPath) {
|
|
17
|
+
if (typeof transcriptPath !== "string" || !path.isAbsolute(transcriptPath)
|
|
18
|
+
|| !/^rollout-.*\.jsonl$/.test(path.basename(transcriptPath)))
|
|
19
|
+
return false;
|
|
20
|
+
const file = await open(transcriptPath, "r").catch(() => undefined);
|
|
21
|
+
if (!file)
|
|
22
|
+
return false;
|
|
23
|
+
try {
|
|
24
|
+
const size = (await file.stat()).size;
|
|
25
|
+
let end = size, carry = Buffer.alloc(0);
|
|
26
|
+
while (end > 0 && size - end < SCAN_LIMIT) {
|
|
27
|
+
const start = Math.max(0, end - CHUNK), buffer = Buffer.alloc(end - start);
|
|
28
|
+
await file.read(buffer, 0, buffer.length, start);
|
|
29
|
+
const bytes = Buffer.concat([buffer, carry]);
|
|
30
|
+
// Lines newest first; the bytes before the first newline may continue
|
|
31
|
+
// a line that began in an earlier chunk, so they carry over.
|
|
32
|
+
let lineEnd = bytes.length;
|
|
33
|
+
for (let at = bytes.lastIndexOf(10, lineEnd - 1); at >= 0; at = bytes.lastIndexOf(10, lineEnd - 1)) {
|
|
34
|
+
const settings = reviewSettings(bytes.subarray(at + 1, lineEnd).toString("utf8"));
|
|
35
|
+
if (settings)
|
|
36
|
+
return autoReviewed(settings);
|
|
37
|
+
lineEnd = at;
|
|
38
|
+
if (at === 0)
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
carry = bytes.subarray(0, lineEnd);
|
|
42
|
+
end = start;
|
|
43
|
+
}
|
|
44
|
+
const settings = end === 0 ? reviewSettings(carry.toString("utf8")) : undefined;
|
|
45
|
+
return !!settings && autoReviewed(settings);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
await file.close().catch(() => { });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function reviewSettings(line) {
|
|
55
|
+
if (!line.includes("\"approvals_reviewer\"")
|
|
56
|
+
|| !(line.includes("\"type\":\"turn_context\"") || line.includes("\"type\":\"thread_settings_applied\"")))
|
|
57
|
+
return undefined;
|
|
58
|
+
try {
|
|
59
|
+
const entry = JSON.parse(line);
|
|
60
|
+
const payload = entry?.payload;
|
|
61
|
+
const settings = entry?.type === "turn_context" ? payload
|
|
62
|
+
: entry?.type === "event_msg" && payload?.type === "thread_settings_applied" ? payload.thread_settings : undefined;
|
|
63
|
+
if (!settings || !("approvals_reviewer" in settings))
|
|
64
|
+
return undefined;
|
|
65
|
+
return { reviewer: settings.approvals_reviewer, policy: settings.approval_policy };
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function autoReviewed({ reviewer, policy }) {
|
|
72
|
+
return reviewer === "auto_review"
|
|
73
|
+
&& (policy === "on-request" || (!!policy && typeof policy === "object" && "granular" in policy));
|
|
74
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type AppServerRequestId, type AppServerTurnInput, connectAppServer, type PendingServerRequest, spawnAppServer } from "./codex-app-server.js";
|
|
3
|
+
import { type Json, type Target } from "./protocol.js";
|
|
4
|
+
declare const entrySchema: z.ZodObject<{
|
|
5
|
+
id: z.ZodString;
|
|
6
|
+
server: z.ZodString;
|
|
7
|
+
workspace: z.ZodString;
|
|
8
|
+
tab: z.ZodString;
|
|
9
|
+
pane: z.ZodString;
|
|
10
|
+
socket: z.ZodString;
|
|
11
|
+
pid: z.ZodNumber;
|
|
12
|
+
threadId: z.ZodOptional<z.ZodString>;
|
|
13
|
+
cwd: z.ZodString;
|
|
14
|
+
startedAt: z.ZodString;
|
|
15
|
+
dispatchId: z.ZodOptional<z.ZodString>;
|
|
16
|
+
activeTurn: z.ZodOptional<z.ZodString>;
|
|
17
|
+
lastTurn: z.ZodOptional<z.ZodObject<{
|
|
18
|
+
id: z.ZodString;
|
|
19
|
+
status: z.ZodString;
|
|
20
|
+
at: z.ZodString;
|
|
21
|
+
}, z.core.$strip>>;
|
|
22
|
+
nextTurn: z.ZodOptional<z.ZodObject<{
|
|
23
|
+
model: z.ZodOptional<z.ZodString>;
|
|
24
|
+
effort: z.ZodOptional<z.ZodString>;
|
|
25
|
+
approvalPolicy: z.ZodOptional<z.ZodEnum<{
|
|
26
|
+
never: "never";
|
|
27
|
+
"on-request": "on-request";
|
|
28
|
+
untrusted: "untrusted";
|
|
29
|
+
}>>;
|
|
30
|
+
approvalsReviewer: z.ZodOptional<z.ZodEnum<{
|
|
31
|
+
auto_review: "auto_review";
|
|
32
|
+
user: "user";
|
|
33
|
+
}>>;
|
|
34
|
+
sandboxPolicy: z.ZodOptional<z.ZodObject<{
|
|
35
|
+
type: z.ZodEnum<{
|
|
36
|
+
dangerFullAccess: "dangerFullAccess";
|
|
37
|
+
readOnly: "readOnly";
|
|
38
|
+
workspaceWrite: "workspaceWrite";
|
|
39
|
+
}>;
|
|
40
|
+
}, z.core.$strict>>;
|
|
41
|
+
collaborationMode: z.ZodOptional<z.ZodObject<{
|
|
42
|
+
mode: z.ZodEnum<{
|
|
43
|
+
default: "default";
|
|
44
|
+
plan: "plan";
|
|
45
|
+
}>;
|
|
46
|
+
}, z.core.$strict>>;
|
|
47
|
+
}, z.core.$strict>>;
|
|
48
|
+
}, z.core.$strict>;
|
|
49
|
+
export type CodexServerEntry = z.infer<typeof entrySchema>;
|
|
50
|
+
export type CodexNextTurn = NonNullable<CodexServerEntry["nextTurn"]>;
|
|
51
|
+
/** Where the Hook's approval cards come from and go: every server request of
|
|
52
|
+
* a registered thread is offered here with the function that answers it, and
|
|
53
|
+
* withdrawn once any client (the pane's TUI, or this one) answered it. */
|
|
54
|
+
export interface CodexApprovalSink {
|
|
55
|
+
request(target: Target, request: PendingServerRequest, answer: (result: Json) => void): void;
|
|
56
|
+
resolved(target: Target, requestId: AppServerRequestId): void;
|
|
57
|
+
}
|
|
58
|
+
export interface CodexServerDeps {
|
|
59
|
+
spawn: typeof spawnAppServer;
|
|
60
|
+
connect: typeof connectAppServer;
|
|
61
|
+
/** True while `pid` is a running process. */
|
|
62
|
+
alive(pid: number): boolean;
|
|
63
|
+
kill(pid: number): void;
|
|
64
|
+
}
|
|
65
|
+
/** `PHREN_CODEX_APP_SERVER=off` keeps every Codex launch on the typed path. */
|
|
66
|
+
export declare function codexAppServerEnabled(env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform): boolean;
|
|
67
|
+
/** A question on a Hook-run pane reaches the phone as a card either way, but
|
|
68
|
+
* only the blocking `request_user_input` holds the turn until someone answers:
|
|
69
|
+
* an async question (`request_user_input_async`) lets the worker carry on
|
|
70
|
+
* without the answer, and a plain-text question never becomes a card at all.
|
|
71
|
+
* Codex 0.157 offers the blocking tool outside plan mode only behind
|
|
72
|
+
* `features.default_mode_request_user_input`, and a short developer
|
|
73
|
+
* instruction steers the model to it (as T3 Code's CodexDeveloperInstructions
|
|
74
|
+
* does). `PHREN_CODEX_BLOCKING_QUESTIONS=off` leaves both out. */
|
|
75
|
+
export declare const BLOCKING_QUESTION_INSTRUCTIONS: string;
|
|
76
|
+
export declare function serverConfig(env?: NodeJS.ProcessEnv): string[];
|
|
77
|
+
/** The variable that tells a hook it runs inside the Hook's own app-server
|
|
78
|
+
* for one pane, so the pane variables it carries are that pane's. */
|
|
79
|
+
export declare const CODEX_SERVER_ENV = "PHREN_CODEX_SERVER";
|
|
80
|
+
export declare const codexServerId: z.ZodString;
|
|
81
|
+
/** The server's environment: the Hook's own, minus the variables that name
|
|
82
|
+
* the Hook's terminal, plus the pane's (so the hooks Codex runs inside the
|
|
83
|
+
* server report this pane) and the caller's. */
|
|
84
|
+
export declare function serverEnvironment(base: NodeJS.ProcessEnv, extra: Record<string, string>): NodeJS.ProcessEnv;
|
|
85
|
+
export declare function codexServersRoot(): string;
|
|
86
|
+
/** Nothing was sent: the server could not be reached. */
|
|
87
|
+
export declare class CodexServerUnavailable extends Error {
|
|
88
|
+
constructor(message: string);
|
|
89
|
+
}
|
|
90
|
+
export interface LaunchPlace {
|
|
91
|
+
server: string;
|
|
92
|
+
workspace: string;
|
|
93
|
+
tab: string;
|
|
94
|
+
pane: string;
|
|
95
|
+
}
|
|
96
|
+
export interface LaunchOptions {
|
|
97
|
+
cwd: string;
|
|
98
|
+
model?: string;
|
|
99
|
+
effort?: string;
|
|
100
|
+
/** Extra flags for a pane whose TUI starts the thread (no brief), such as a permission mode. */
|
|
101
|
+
remoteArgs?: string[];
|
|
102
|
+
/** Layered over the Hook's environment for the server and its hooks. */
|
|
103
|
+
env?: Record<string, string>;
|
|
104
|
+
dispatchId?: string;
|
|
105
|
+
}
|
|
106
|
+
export declare class CodexServers {
|
|
107
|
+
private deps;
|
|
108
|
+
private live;
|
|
109
|
+
private sink?;
|
|
110
|
+
private closed;
|
|
111
|
+
constructor(deps?: CodexServerDeps);
|
|
112
|
+
setDeps(deps: Partial<CodexServerDeps>): () => void;
|
|
113
|
+
private readonly saving;
|
|
114
|
+
setSink(sink: CodexApprovalSink | undefined): void;
|
|
115
|
+
entries(): CodexServerEntry[];
|
|
116
|
+
forPane(server: string, pane: string): CodexServerEntry | undefined;
|
|
117
|
+
forThread(threadId: string): CodexServerEntry | undefined;
|
|
118
|
+
/** The server behind a Codex target, when the target is exactly its pane and thread. */
|
|
119
|
+
forTarget(target: Target): CodexServerEntry | undefined;
|
|
120
|
+
/** A new server for a pane the Hook just created, and the arguments the
|
|
121
|
+
* pane's `codex` joins it with. With `startThread` (a launch that carries a
|
|
122
|
+
* brief) the Hook starts the thread and the pane resumes it:
|
|
123
|
+
* `codex resume <threadId> --remote unix://<socket>`. Codex cannot resume a
|
|
124
|
+
* thread with no turn yet, so without one the pane's TUI starts the thread
|
|
125
|
+
* (`codex --remote unix://<socket>`, with the model and effort as its own
|
|
126
|
+
* flags) and the Hook learns it from `thread/started` (`awaitThread`). The
|
|
127
|
+
* caller `stop`s the server if the pane cannot start. */
|
|
128
|
+
launch(place: LaunchPlace, options: LaunchOptions & {
|
|
129
|
+
startThread?: boolean;
|
|
130
|
+
}): Promise<{
|
|
131
|
+
entry: CodexServerEntry;
|
|
132
|
+
args: string[];
|
|
133
|
+
}>;
|
|
134
|
+
/** The pane's thread once its TUI has started it; undefined after `timeoutMs`. */
|
|
135
|
+
awaitThread(entry: CodexServerEntry, timeoutMs?: number): Promise<string | undefined>;
|
|
136
|
+
/** On Hook start: every registered server still running is reconnected
|
|
137
|
+
* and its thread followed again (its pending approvals are replayed to
|
|
138
|
+
* the new client); the rest are forgotten. */
|
|
139
|
+
adopt(): Promise<void>;
|
|
140
|
+
/** `turn/start` on the pane's thread; resolves with the turn id the server
|
|
141
|
+
* acknowledged. Nothing is typed into the pane. */
|
|
142
|
+
prompt(entry: CodexServerEntry, text: string): Promise<{
|
|
143
|
+
turnId: string;
|
|
144
|
+
}>;
|
|
145
|
+
/** `thread/name/set` on the pane's thread: Codex's own rename, which its TUI
|
|
146
|
+
* shows and `session_index.jsonl` keeps. Allowed while a turn runs. */
|
|
147
|
+
renameThread(entry: CodexServerEntry, name: string): Promise<void>;
|
|
148
|
+
/** Holds a model and effort for the pane's next Hook-sent turn. Nothing is
|
|
149
|
+
* typed into the TUI and a running turn is not disturbed. */
|
|
150
|
+
setNextTurn(entry: CodexServerEntry, model: string, effort?: string): void;
|
|
151
|
+
/** Holds permission and plan settings the same way, next to a pending model. */
|
|
152
|
+
holdSettings(entry: CodexServerEntry, settings: Omit<CodexNextTurn, "model" | "effort">): void;
|
|
153
|
+
/** Merges into what is pending: a later choice replaces its own fields only. */
|
|
154
|
+
private hold;
|
|
155
|
+
/** Input for the thread's running turn (`turn/steer`, as the TUI sends an
|
|
156
|
+
* async question's answer), or a new turn when none is running or the one
|
|
157
|
+
* it knew has ended. A refused steer sent nothing, so starting is safe. */
|
|
158
|
+
steer(entry: CodexServerEntry, text: string, extra?: AppServerTurnInput[]): Promise<{
|
|
159
|
+
turnId: string;
|
|
160
|
+
}>;
|
|
161
|
+
/** The thread's parked questions: `item/tool/requestUserInput` and MCP
|
|
162
|
+
* elicitations, which wait for an answer from any client. */
|
|
163
|
+
questions(entry: CodexServerEntry): PendingServerRequest[];
|
|
164
|
+
/** Answers one parked question; false when no client still waits on it. */
|
|
165
|
+
answerQuestion(entry: CodexServerEntry, requestId: AppServerRequestId, result: Json): boolean;
|
|
166
|
+
/** One proactive refresh of the shared Codex sign-in (codex-auth-refresh.ts)
|
|
167
|
+
* through Codex's own flow: on a running server's connection, or on a
|
|
168
|
+
* short-lived server when none runs. */
|
|
169
|
+
refreshAuth(): Promise<void>;
|
|
170
|
+
/** Interrupt the running turn, declining the thread's parked server
|
|
171
|
+
* requests first. False when no turn is known to be running. */
|
|
172
|
+
interrupt(entry: CodexServerEntry): Promise<boolean>;
|
|
173
|
+
/** The last finished turn of a registered thread and the running one, for
|
|
174
|
+
* the returns loop. */
|
|
175
|
+
turnState(threadId: string): {
|
|
176
|
+
activeTurn?: string;
|
|
177
|
+
lastTurn?: CodexServerEntry["lastTurn"];
|
|
178
|
+
} | undefined;
|
|
179
|
+
/** One Hook tick for `server`: forget servers whose process ended, stop
|
|
180
|
+
* servers whose pane closed (or has shown no Codex for two minutes), and
|
|
181
|
+
* reconnect a client that dropped. */
|
|
182
|
+
reap(server: string, snapshot: Json, now?: number): Promise<void>;
|
|
183
|
+
/** Servers whose terminal server is no longer running at all (a stopped
|
|
184
|
+
* Herdr session takes its panes with it): forgotten once dead, stopped
|
|
185
|
+
* after the same two minutes a pane without Codex gets. */
|
|
186
|
+
sweep(running: string[], now?: number): Promise<void>;
|
|
187
|
+
/** The pane's TUI moved to `threadId` (`/new`, `/resume`), as its
|
|
188
|
+
* SessionStart hook reports: follow it, so prompts, approvals and Escape
|
|
189
|
+
* go where the TUI is. False when the pane has no registered server. */
|
|
190
|
+
follow(server: string, pane: string, threadId: string): boolean;
|
|
191
|
+
private rebind;
|
|
192
|
+
/** Ends the server and forgets it. */
|
|
193
|
+
stop(entry: CodexServerEntry): Promise<void>;
|
|
194
|
+
/** Close every client; the servers keep running for the next Hook. */
|
|
195
|
+
close(): void;
|
|
196
|
+
/** For tests: forget everything without touching processes. */
|
|
197
|
+
reset(): void;
|
|
198
|
+
/** Resolves once every registry write started so far has finished. */
|
|
199
|
+
saved(): Promise<void>;
|
|
200
|
+
private target;
|
|
201
|
+
/** Rejoin the thread: its history is skipped, its pending server requests
|
|
202
|
+
* come again as requests. */
|
|
203
|
+
private subscribe;
|
|
204
|
+
private client;
|
|
205
|
+
private connect;
|
|
206
|
+
private listen;
|
|
207
|
+
private drop;
|
|
208
|
+
private forget;
|
|
209
|
+
private read;
|
|
210
|
+
/** One server's registry writes run in order, each with the entry as it is
|
|
211
|
+
* then, so an earlier write that finishes late never lands over a newer one. */
|
|
212
|
+
private save;
|
|
213
|
+
}
|
|
214
|
+
/** The Hook's servers: launch, prompt and keys routes, identity and the
|
|
215
|
+
* approval store all see the same registry. */
|
|
216
|
+
export declare const codexServers: CodexServers;
|
|
217
|
+
export {};
|