@agentvault/openai-bridge 0.1.22 → 0.1.23
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/README.md +19 -4
- package/dist/avroom-mcp.d.ts +96 -0
- package/dist/avroom-stdio.d.ts +39 -0
- package/dist/avroom-stdio.js +154 -0
- package/dist/bridge.d.ts +125 -12
- package/dist/channel-config.d.ts +29 -0
- package/dist/cli.d.ts +1 -1
- package/dist/codex-version.d.ts +29 -0
- package/dist/content-send.d.ts +100 -0
- package/dist/driver.d.ts +126 -2
- package/dist/file-turn.d.ts +95 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +9337 -1621
- package/dist/owner-grant.d.ts +131 -0
- package/dist/owner-lane.d.ts +40 -0
- package/dist/runtime.d.ts +26 -1
- package/dist/sender-binding.d.ts +77 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ Connect a local OpenAI Codex login to encrypted AgentVault owner direct messages
|
|
|
6
6
|
|
|
7
7
|
## Prerequisites and login
|
|
8
8
|
|
|
9
|
-
Node.js 20 or newer, macOS or Linux, and **the native Codex CLI 0.
|
|
9
|
+
Node.js 20 or newer, macOS or Linux, and **the native Codex CLI 0.162.1 executable** on PATH are required. The supported model is fixed to `gpt-5.6-terra`. A JavaScript npm launcher that requires Node from a Homebrew/custom PATH cannot run inside the deliberately minimal child PATH; install the native Codex executable instead. Other CLI versions fail closed because the disabled-tool boundary must be measured again before upgrading.
|
|
10
10
|
|
|
11
11
|
Install it globally (`npm install -g @agentvault/openai-bridge`). Development builds can run `node dist/index.js --help`; background service installation rejects temporary package-cache entrypoints.
|
|
12
12
|
|
|
@@ -36,7 +36,7 @@ AV_AGENT_NAME=aster agentvault-openai-bridge uninstall
|
|
|
36
36
|
|
|
37
37
|
macOS uses a per-user launchd service; Linux uses user systemd. Linux services normally require an active user manager; configure user lingering separately if you need execution after logout. Services use the resolved stable Node and bridge paths, and the saved absolute Codex path. `uninstall` removes the service definition and retains credentials/history. `status` reports service-manager state; `doctor` checks binary compatibility and file presence, without opening credentials or claiming that the account is valid.
|
|
38
38
|
|
|
39
|
-
If Codex is upgraded, install the supported version again before restarting. If authentication expires, run `uninstall`, run `login` again with the same name, then run `install` again. These commands retain the agent credentials and history. For replacement enrollment, stop the existing service with `uninstall`, obtain a fresh recovery invite from the app, then run:
|
|
39
|
+
**Upgrading the bridge can need a new Codex.** Each bridge release runs with one exact Codex version; this one needs 0.162.1 (the previous one needed 0.154.0). Install that Codex FIRST, check `codex --version`, and, if the saved `config.json` pins a `binary` path, point it at the new executable — then install the new bridge and restart. A host still on the old Codex refuses every turn, text included, with "Unsupported Codex CLI". Codex sessions made by 0.154.0 resume under 0.162.1. If Codex is upgraded on its own, install the supported version again before restarting. If authentication expires, run `uninstall`, run `login` again with the same name, then run `install` again. These commands retain the agent credentials and history. For replacement enrollment, stop the existing service with `uninstall`, obtain a fresh recovery invite from the app, then run:
|
|
40
40
|
|
|
41
41
|
```sh
|
|
42
42
|
AV_AGENT_NAME=aster AV_INVITE_TOKEN='<fresh-invite>' agentvault-openai-bridge replace
|
|
@@ -52,10 +52,19 @@ Only direct messages positively attested by SecureChannel as owner 1:1 messages
|
|
|
52
52
|
|
|
53
53
|
Each agent stores its state beneath `~/.agentvault/openai/<name-slug>/`, including isolated `home`, `codex`, `work`, `tmp`, and `sessions` directories (0700). Codex auth and local conversation transcripts persist there. Encryption protects AgentVault transport; local Codex history is plaintext and relies on the host account's filesystem protections. Do not share this directory.
|
|
54
54
|
|
|
55
|
-
Codex children receive only a dedicated HOME, CODEX_HOME, TMPDIR, and a minimal PATH. The measured configuration disables shell, filesystem tools, web search,
|
|
55
|
+
Codex children receive only a dedicated HOME, CODEX_HOME, TMPDIR, and a minimal PATH. The measured configuration disables shell, filesystem tools, web search, apps/plugins, delegation, and other integrations, and turns OFF every default-on Codex feature that is not on a reviewed allowlist (read from `codex features list` at the first turn; an unreadable list, or a missing name from the hard list, refuses to run). The one MCP server is the bridge's own `avroom`, which offers exactly one tool, `send_file` (see "Sending files"). The bridge also runs the model with its own one-model catalog — the installed binary's entry for the pinned model with direct tools, no tool search and no multi-agent — so the model's catalog is the MCP resource tools (the shim answers them "not found"), `request_user_input` and `send_file` (no `apply_patch`, no Code Mode `exec`). Read-only sandboxing and approval `never` are mandatory because an unadvertised patch handler still exists; only `send_file` is approved by name. Built-in Codex system skill descriptions may appear in context, but host user skills/configuration are not inherited. Arbitrary model, provider, environment and tool configuration are intentionally unavailable.
|
|
56
56
|
|
|
57
57
|
The bridge accepts only a terminal successful assistant reply after exit 0. Because the exec stream omits message phase, it additionally verifies the current turn's `final_answer` in the bounded local Codex rollout; a prior resumed turn or commentary cannot authorize delivery. Partial, failed, malformed, oversized or timed-out turns are discarded. Disconnect and shutdown invalidate pending results. One bounded queue serializes inference and awaited sending; child process groups are killed and reaped before another turn starts. Logs contain bridge-owned status codes, without prompts, replies, tokens or provider diagnostics.
|
|
58
58
|
|
|
59
|
+
## Sending files
|
|
60
|
+
|
|
61
|
+
The agent can send one file at a time to its owner in a 1:1, and into a room when its own owner asks for it there. Codex itself still cannot read or write any file: its `send_file` tool takes the file's **name and full content** (text as UTF-8, anything else as base64), and the bridge writes the bytes itself, then sends them through the same encrypted path as every other AgentVault file. In practice that means files the model writes in the turn — reports, CSV, Markdown, code. It cannot send a file from disk, and it cannot forward a file someone sent it.
|
|
62
|
+
|
|
63
|
+
- **Where files are kept.** Staged files live in `~/.agentvault/openai/agentvault-outbox/<name>-<8 hex>/`: `dm/` for the 1:1, `rooms/<room id>/` for each room, each file in its own folder (`<uuid>/<file name>`), so the person receives the clean file name. A sent file is kept as a record; a file that did not go is removed. Each folder keeps the newest 50 files or 100 MB, whichever is smaller; older ones move to `left/`, which keeps only its newest three.
|
|
64
|
+
- **Rooms.** A file goes into a room only on a turn from the agent's own owner, with nothing from another member in it. Those turns run in a separate Codex session for that room (the "owner lane"), which never sees other members' messages; the agent is told so and offers a text reply if asked about them. A turn from anyone else, or one where another member speaks before the file goes, is refused and leaves nothing on disk. If the owner-lane session cannot be shown to hold only the owner's turns (for example its record was lost), the bridge starts a new one for it.
|
|
65
|
+
- **Never claimed unless sent.** The tool answers `File sent: …` only after the file left; every other answer starts `File NOT sent:`. A reply that claims an attachment when none went gets the note `(This reply has no attachment.)`.
|
|
66
|
+
- **How Codex reaches the tool.** Each turn gets its own private socket (`mcp-<16 hex>.sock`, mode 0600, in this agent's 0700 state folder), and Codex starts the bridge's small relay (`dist/avroom-stdio.js`) with Node's absolute path. The socket is removed when the turn ends, so a Codex process left over from a stopped turn can never send under a later turn. The folder is checked (ours, private, not a link) every time a socket is made. Frames over about 7 MB are not read; the tool answers "File NOT sent". A turn that can send a file gets 5 minutes. A send that has not finished after 2 minutes is cancelled before any frame is written, and Codex hears "File NOT sent"; a file Codex has given up on is never delivered afterwards.
|
|
67
|
+
|
|
59
68
|
## When a reply fails
|
|
60
69
|
|
|
61
70
|
When a turn fails, the bridge records it first and then tells the chat. It does not drop a failed turn without a trace.
|
|
@@ -100,4 +109,10 @@ The optional real-binary gate runs only when explicitly invoked after a build:
|
|
|
100
109
|
python3 scripts/mock-provider-gate.py --codex /absolute/path/to/native/codex
|
|
101
110
|
```
|
|
102
111
|
|
|
103
|
-
|
|
112
|
+
The file-send gate (#1762) runs the real binary against the same kind of loopback mock, through the built bridge's own socket and relay, and records whether the `send_file` call runs under approval `never`, that the tool catalog is what this README says, that a fresh Codex session carries nothing from another, and that `exec`, `spawn_agent`, `apply_patch` and resource reads never reach a file:
|
|
113
|
+
|
|
114
|
+
```sh
|
|
115
|
+
python3 scripts/live-gate-1762.py --codex /absolute/path/to/native/codex
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
The older gate binds a loopback mock provider, asserts an empty tool catalog, denies hostile execution/patching, checks exact-UUID resume, rejects commentary and timeout output, and retains fixture artifacts for inspection. It never logs into an account or reaches a real provider.
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/** X-4: the longest JSON-RPC line accepted (≈ 7.25 MiB: the base64 of 5 MB, MIME-wrapped, plus the envelope). */
|
|
2
|
+
export declare const MAX_FRAME_BYTES: number;
|
|
3
|
+
/** sockaddr_un.sun_path is 104 bytes on macOS (108 on Linux), NUL included. */
|
|
4
|
+
export declare const MAX_SOCKET_PATH_BYTES = 103;
|
|
5
|
+
/** The one tool (§2.3). Its description says nothing about any host path. */
|
|
6
|
+
export declare const SEND_FILE_TOOL: {
|
|
7
|
+
readonly name: "send_file";
|
|
8
|
+
readonly description: string;
|
|
9
|
+
readonly inputSchema: {
|
|
10
|
+
readonly type: "object";
|
|
11
|
+
readonly properties: {
|
|
12
|
+
readonly filename: {
|
|
13
|
+
readonly type: "string";
|
|
14
|
+
readonly description: "A plain file name such as report.md (no folders).";
|
|
15
|
+
};
|
|
16
|
+
readonly content: {
|
|
17
|
+
readonly type: "string";
|
|
18
|
+
readonly description: "The complete file content.";
|
|
19
|
+
};
|
|
20
|
+
readonly encoding: {
|
|
21
|
+
readonly type: "string";
|
|
22
|
+
readonly enum: readonly ["utf8", "base64"];
|
|
23
|
+
};
|
|
24
|
+
readonly caption: {
|
|
25
|
+
readonly type: "string";
|
|
26
|
+
readonly description: "Optional short message shown with the file.";
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
readonly required: readonly ["filename", "content", "encoding"];
|
|
30
|
+
readonly additionalProperties: false;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export type SendFileHandler = (args: unknown) => Promise<{
|
|
34
|
+
ok: boolean;
|
|
35
|
+
text: string;
|
|
36
|
+
}>;
|
|
37
|
+
/** Splits a byte stream into lines, dropping (never parsing) any line over `max` bytes. */
|
|
38
|
+
export declare class LineReader {
|
|
39
|
+
private readonly max;
|
|
40
|
+
private readonly onLine;
|
|
41
|
+
private readonly onDrop;
|
|
42
|
+
private parts;
|
|
43
|
+
private size;
|
|
44
|
+
private dropping;
|
|
45
|
+
/** The first bytes of the current line, kept so a dropped frame can still be answered by id. */
|
|
46
|
+
private head;
|
|
47
|
+
constructor(max: number, onLine: (line: string) => void, onDrop?: (head: string) => void);
|
|
48
|
+
push(chunk: Buffer): void;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Review #1788 item 8: the answer to a frame too large to read, from its first
|
|
52
|
+
* bytes only, so Codex is never left waiting for a reply until the turn dies.
|
|
53
|
+
* A `tools/call` gets a tool RESULT the model reads ("File NOT sent: …"); any
|
|
54
|
+
* other request gets a JSON-RPC error; a frame whose id cannot be read gets
|
|
55
|
+
* nothing (there is nothing to answer).
|
|
56
|
+
*/
|
|
57
|
+
export declare function oversizedReply(head: string): string | null;
|
|
58
|
+
export declare const TOO_LARGE_TEXT = "File NOT sent: the file is over 5 MB. Tell the person it was not sent.";
|
|
59
|
+
/** Test seam: how many lines reached `JSON.parse` (so "dropped before parse" is measured). */
|
|
60
|
+
export declare const parseSpy: {
|
|
61
|
+
count: number;
|
|
62
|
+
};
|
|
63
|
+
/** A real directory (lstat: not a link), owned by this user, with no group/other permission bits. */
|
|
64
|
+
export declare function privateDir(dir: string): boolean;
|
|
65
|
+
export declare class AvroomEndpoint {
|
|
66
|
+
private readonly handler;
|
|
67
|
+
private readonly version;
|
|
68
|
+
private readonly log;
|
|
69
|
+
private server?;
|
|
70
|
+
private readonly sockets;
|
|
71
|
+
private closed;
|
|
72
|
+
readonly socketPath: string;
|
|
73
|
+
private constructor();
|
|
74
|
+
/**
|
|
75
|
+
* Open a fresh endpoint in `dir` (the bridge's 0700 state folder). Resolves
|
|
76
|
+
* null — no MCP this turn, the model is told files are unavailable — when the
|
|
77
|
+
* path would be too long for a Unix socket or the socket cannot be made.
|
|
78
|
+
*/
|
|
79
|
+
static open(dir: string, handler: SendFileHandler, opts?: {
|
|
80
|
+
version?: string;
|
|
81
|
+
log?: (line: string) => void;
|
|
82
|
+
}): Promise<AvroomEndpoint | null>;
|
|
83
|
+
private listen;
|
|
84
|
+
private accept;
|
|
85
|
+
private onLine;
|
|
86
|
+
/** One `send_file` call. After close: refused (turn_ended), whatever is still in flight. */
|
|
87
|
+
call(args: unknown): Promise<{
|
|
88
|
+
ok: boolean;
|
|
89
|
+
text: string;
|
|
90
|
+
}>;
|
|
91
|
+
get isClosed(): boolean;
|
|
92
|
+
/** The turn ended: refuse everything from now on, cut every connection, unlink the socket. Idempotent. */
|
|
93
|
+
close(): Promise<void>;
|
|
94
|
+
}
|
|
95
|
+
export declare const TURN_ENDED_TEXT = "File NOT sent: the turn ended before the file went. Tell the person it was not sent.";
|
|
96
|
+
//# sourceMappingURL=avroom-mcp.d.ts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #1762 PR-X (design §2.3, X-4) — the stdio shim Codex starts as the `avroom`
|
|
3
|
+
* MCP server: `node dist/avroom-stdio.js <socket path>`.
|
|
4
|
+
*
|
|
5
|
+
* It relays newline-delimited JSON-RPC between Codex (stdin/stdout) and the
|
|
6
|
+
* bridge's per-turn Unix socket, and nothing else:
|
|
7
|
+
* - every line is capped BEFORE `JSON.parse`; an oversized line is dropped;
|
|
8
|
+
* - only `initialize`, `tools/list`, `tools/call` and notifications are
|
|
9
|
+
* forwarded. Any other request (`resources/list`, `resources/read`, …) is
|
|
10
|
+
* answered here with "method not found" and never reaches the bridge;
|
|
11
|
+
* - it exits on EOF from Codex, or when the socket closes.
|
|
12
|
+
* No secret is in its argv or env. It imports nothing from the bridge.
|
|
13
|
+
*/
|
|
14
|
+
import { type Socket } from "node:net";
|
|
15
|
+
/** The error answer to a (forwardable) request the shim could not queue. */
|
|
16
|
+
export declare function busyReply(line: string): string | null;
|
|
17
|
+
export interface ShimIo {
|
|
18
|
+
input: NodeJS.ReadableStream;
|
|
19
|
+
output: {
|
|
20
|
+
write(chunk: string): unknown;
|
|
21
|
+
};
|
|
22
|
+
socketPath: string;
|
|
23
|
+
/** Test seam. */
|
|
24
|
+
connect?: (path: string) => Socket;
|
|
25
|
+
}
|
|
26
|
+
/** Decide what happens to one line from Codex: forward it, answer it locally, or drop it. */
|
|
27
|
+
/** Test seam: lines from Codex that reached `JSON.parse` in the shim. */
|
|
28
|
+
export declare const shimParseSpy: {
|
|
29
|
+
count: number;
|
|
30
|
+
};
|
|
31
|
+
export declare function routeFromCodex(line: string): {
|
|
32
|
+
forward: true;
|
|
33
|
+
} | {
|
|
34
|
+
forward: false;
|
|
35
|
+
reply?: string;
|
|
36
|
+
};
|
|
37
|
+
/** Run the relay until either side ends. Resolves with the exit code. */
|
|
38
|
+
export declare function runShim(io: ShimIo): Promise<number>;
|
|
39
|
+
//# sourceMappingURL=avroom-stdio.d.ts.map
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// src/avroom-stdio.ts
|
|
2
|
+
import { createConnection } from "node:net";
|
|
3
|
+
import { realpathSync } from "node:fs";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { isAbsolute } from "node:path";
|
|
6
|
+
|
|
7
|
+
// src/avroom-mcp.ts
|
|
8
|
+
var MAX_FRAME_BYTES = 7.25 * 1024 * 1024;
|
|
9
|
+
var LineReader = class {
|
|
10
|
+
constructor(max, onLine, onDrop = () => {
|
|
11
|
+
}) {
|
|
12
|
+
this.max = max;
|
|
13
|
+
this.onLine = onLine;
|
|
14
|
+
this.onDrop = onDrop;
|
|
15
|
+
}
|
|
16
|
+
max;
|
|
17
|
+
onLine;
|
|
18
|
+
onDrop;
|
|
19
|
+
parts = [];
|
|
20
|
+
size = 0;
|
|
21
|
+
dropping = false;
|
|
22
|
+
/** The first bytes of the current line, kept so a dropped frame can still be answered by id. */
|
|
23
|
+
head = "";
|
|
24
|
+
push(chunk) {
|
|
25
|
+
let start = 0;
|
|
26
|
+
for (; ; ) {
|
|
27
|
+
const nl = chunk.indexOf(10, start);
|
|
28
|
+
const piece = nl < 0 ? chunk.subarray(start) : chunk.subarray(start, nl);
|
|
29
|
+
if (!this.dropping) {
|
|
30
|
+
if (this.head.length < HEAD_BYTES) this.head += piece.subarray(0, HEAD_BYTES - this.head.length).toString("latin1");
|
|
31
|
+
this.size += piece.length;
|
|
32
|
+
if (this.size > this.max) {
|
|
33
|
+
this.dropping = true;
|
|
34
|
+
this.parts = [];
|
|
35
|
+
this.onDrop(this.head);
|
|
36
|
+
} else if (piece.length) this.parts.push(piece);
|
|
37
|
+
}
|
|
38
|
+
if (nl < 0) return;
|
|
39
|
+
if (!this.dropping) {
|
|
40
|
+
const line = Buffer.concat(this.parts).toString("utf8");
|
|
41
|
+
this.parts = [];
|
|
42
|
+
this.size = 0;
|
|
43
|
+
if (line.trim()) this.onLine(line);
|
|
44
|
+
} else {
|
|
45
|
+
this.dropping = false;
|
|
46
|
+
this.size = 0;
|
|
47
|
+
}
|
|
48
|
+
this.head = "";
|
|
49
|
+
start = nl + 1;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var HEAD_BYTES = 256;
|
|
54
|
+
var HEAD_RE = /^\s{0,8}\{\s{0,8}"jsonrpc"\s{0,8}:\s{0,8}"2\.0"\s{0,8},\s{0,8}"id"\s{0,8}:\s{0,8}(\d{1,15}|"[A-Za-z0-9_-]{1,64}")\s{0,8},\s{0,8}"method"\s{0,8}:\s{0,8}"([a-z/]{1,40})"/;
|
|
55
|
+
function oversizedReply(head) {
|
|
56
|
+
const m = HEAD_RE.exec(head);
|
|
57
|
+
if (!m) return null;
|
|
58
|
+
const id = m[1].startsWith('"') ? m[1].slice(1, -1) : Number(m[1]);
|
|
59
|
+
if (m[2] === "tools/call") {
|
|
60
|
+
return JSON.stringify({ jsonrpc: "2.0", id, result: { content: [{ type: "text", text: TOO_LARGE_TEXT }], isError: true } });
|
|
61
|
+
}
|
|
62
|
+
return JSON.stringify({ jsonrpc: "2.0", id, error: { code: -32600, message: "Request too large" } });
|
|
63
|
+
}
|
|
64
|
+
var TOO_LARGE_TEXT = "File NOT sent: the file is over 5 MB. Tell the person it was not sent.";
|
|
65
|
+
|
|
66
|
+
// src/avroom-stdio.ts
|
|
67
|
+
var MAX_PENDING = 8;
|
|
68
|
+
function busyReply(line) {
|
|
69
|
+
try {
|
|
70
|
+
const id = JSON.parse(line).id;
|
|
71
|
+
if (typeof id !== "string" && typeof id !== "number") return null;
|
|
72
|
+
return JSON.stringify({ jsonrpc: "2.0", id, error: { code: -32603, message: "The AgentVault relay is not connected yet" } });
|
|
73
|
+
} catch {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
var FORWARD = /* @__PURE__ */ new Set(["initialize", "tools/list", "tools/call"]);
|
|
78
|
+
var shimParseSpy = { count: 0 };
|
|
79
|
+
function routeFromCodex(line) {
|
|
80
|
+
let msg;
|
|
81
|
+
try {
|
|
82
|
+
shimParseSpy.count += 1;
|
|
83
|
+
msg = JSON.parse(line);
|
|
84
|
+
} catch {
|
|
85
|
+
return { forward: false };
|
|
86
|
+
}
|
|
87
|
+
if (!msg || typeof msg !== "object" || typeof msg.method !== "string") {
|
|
88
|
+
return { forward: false };
|
|
89
|
+
}
|
|
90
|
+
const id = msg.id;
|
|
91
|
+
const isRequest = typeof id === "string" || typeof id === "number";
|
|
92
|
+
if (!isRequest) return msg.method.startsWith("notifications/") ? { forward: true } : { forward: false };
|
|
93
|
+
if (FORWARD.has(msg.method)) return { forward: true };
|
|
94
|
+
return { forward: false, reply: JSON.stringify({ jsonrpc: "2.0", id, error: { code: -32601, message: "Method not found" } }) };
|
|
95
|
+
}
|
|
96
|
+
function runShim(io) {
|
|
97
|
+
return new Promise((resolve) => {
|
|
98
|
+
if (typeof io.socketPath !== "string" || !isAbsolute(io.socketPath)) {
|
|
99
|
+
resolve(2);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
let done = false;
|
|
103
|
+
const finish = (code) => {
|
|
104
|
+
if (done) return;
|
|
105
|
+
done = true;
|
|
106
|
+
socket.destroy();
|
|
107
|
+
resolve(code);
|
|
108
|
+
};
|
|
109
|
+
const socket = (io.connect ?? createConnection)(io.socketPath);
|
|
110
|
+
const pending = [];
|
|
111
|
+
let connected = false;
|
|
112
|
+
socket.on("connect", () => {
|
|
113
|
+
connected = true;
|
|
114
|
+
for (const line of pending.splice(0)) socket.write(line + "\n");
|
|
115
|
+
});
|
|
116
|
+
socket.on("error", () => finish(3));
|
|
117
|
+
socket.on("close", () => finish(0));
|
|
118
|
+
const fromCodex = new LineReader(MAX_FRAME_BYTES, (line) => {
|
|
119
|
+
const route = routeFromCodex(line);
|
|
120
|
+
if (route.forward) {
|
|
121
|
+
if (connected) socket.write(line + "\n");
|
|
122
|
+
else if (pending.length < MAX_PENDING) pending.push(line);
|
|
123
|
+
else {
|
|
124
|
+
const reply = busyReply(line);
|
|
125
|
+
if (reply) io.output.write(reply + "\n");
|
|
126
|
+
}
|
|
127
|
+
} else if (route.reply) io.output.write(route.reply + "\n");
|
|
128
|
+
}, (head) => {
|
|
129
|
+
const reply = oversizedReply(head);
|
|
130
|
+
if (reply) io.output.write(reply + "\n");
|
|
131
|
+
});
|
|
132
|
+
const fromBridge = new LineReader(MAX_FRAME_BYTES, (line) => {
|
|
133
|
+
io.output.write(line + "\n");
|
|
134
|
+
});
|
|
135
|
+
socket.on("data", (chunk) => fromBridge.push(chunk));
|
|
136
|
+
io.input.on("data", (chunk) => fromCodex.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk));
|
|
137
|
+
io.input.on("end", () => finish(0));
|
|
138
|
+
io.input.on("error", () => finish(1));
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
var invoked = false;
|
|
142
|
+
try {
|
|
143
|
+
invoked = !!process.argv[1] && realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url));
|
|
144
|
+
} catch {
|
|
145
|
+
}
|
|
146
|
+
if (invoked) {
|
|
147
|
+
void runShim({ input: process.stdin, output: process.stdout, socketPath: process.argv[2] ?? "" }).then((code) => process.exit(code));
|
|
148
|
+
}
|
|
149
|
+
export {
|
|
150
|
+
busyReply,
|
|
151
|
+
routeFromCodex,
|
|
152
|
+
runShim,
|
|
153
|
+
shimParseSpy
|
|
154
|
+
};
|
package/dist/bridge.d.ts
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
|
-
import { type ToolSpanSink } from "@agentvault/agentvault";
|
|
2
|
-
import type
|
|
1
|
+
import { type MessageMetadata, type ToolSpanSink } from "@agentvault/agentvault";
|
|
2
|
+
import { type McpWiring, type TurnResult } from "./driver.js";
|
|
3
|
+
import { ContentStager, type ContentTarget } from "./content-send.js";
|
|
4
|
+
import { OwnerLaneTaint } from "./owner-lane.js";
|
|
5
|
+
/** #1762 PR-X (§2, content-only): the per-turn line when this turn can send a file. */
|
|
6
|
+
export declare const CONTENT_FILE_LINE = "To send a file, call send_file with its name and full content.";
|
|
7
|
+
/** #1762 PR-X: the per-turn line on a room turn that cannot share files. */
|
|
8
|
+
export declare const ROOM_NO_FILES_LINE = "Files cannot be shared in this room on this turn.";
|
|
9
|
+
/** #1762 PR-X (X-1): every owner-lane prompt says other members' words are not in it. */
|
|
10
|
+
/** #1762 PR-X (review #1788 item 8): with send_file wired, the header says it is the one tool (no "integration tools are unavailable" beside it). */
|
|
11
|
+
export declare const SEND_FILE_ONLY_LINE = "You have no shell, file or web tools; your one tool is send_file.";
|
|
12
|
+
export declare const OWNER_LANE_NOTE = "Other members' messages are hidden on turns where you can share files. If asked about them, say so and offer a text reply instead.";
|
|
13
|
+
/**
|
|
14
|
+
* #1762 PR-X (review #1788) — the clocks of one `send_file` call, all under Codex's own
|
|
15
|
+
* `tool_timeout_sec` (MCP_TOOL_TIMEOUT_SEC = 150 s):
|
|
16
|
+
* - callDeadlineMs: the bridge gives up — the upload is aborted and no frame can be written;
|
|
17
|
+
* - replyByMs: the model is answered by now whatever happens (normally with the real outcome);
|
|
18
|
+
* - holdMs: how long the call holds the turn (and, after Codex returns, bounds the wait for it).
|
|
19
|
+
*/
|
|
20
|
+
export declare const DEFAULT_CALL_TIMING: {
|
|
21
|
+
callDeadlineMs: number;
|
|
22
|
+
replyByMs: number;
|
|
23
|
+
holdMs: number;
|
|
24
|
+
};
|
|
25
|
+
/** The answer when even an aborted send has not returned in time: it neither claims nor denies. */
|
|
26
|
+
export declare const NOT_CONFIRMED_TEXT = "File NOT confirmed: it was still uploading when time ran out. Do not say it was sent, and do not say it failed; tell the person to look for it in the chat before asking again.";
|
|
3
27
|
export interface BridgeChannel {
|
|
4
28
|
on(event: string, listener: (...args: any[]) => void): unknown;
|
|
5
29
|
off(event: string, listener: (...args: any[]) => void): unknown;
|
|
@@ -12,21 +36,21 @@ export interface BridgeChannel {
|
|
|
12
36
|
displayName: string;
|
|
13
37
|
}>;
|
|
14
38
|
}>;
|
|
15
|
-
getRoomHistory?(roomId: string, max: number): Array<
|
|
16
|
-
text: string;
|
|
17
|
-
sender: string;
|
|
18
|
-
}>;
|
|
39
|
+
getRoomHistory?(roomId: string, max: number): Array<HistoryLine>;
|
|
19
40
|
/** #1560: one person's 1:1 history, scoped by the group the frame decrypted under. */
|
|
20
41
|
getConversationHistory?(id: string, max: number, opts?: {
|
|
21
42
|
groupId?: string;
|
|
22
|
-
}): Array<
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}>;
|
|
43
|
+
}): Array<HistoryLine>;
|
|
44
|
+
/** #1762: the staging folder SecureChannel shows for a target (`~/`-relative for this bridge), or null. */
|
|
45
|
+
stagingPathFor?(target: ContentTarget): string | null;
|
|
26
46
|
send(text: string, options: {
|
|
27
47
|
conversationId: string;
|
|
28
48
|
}): Promise<unknown>;
|
|
29
49
|
sendToRoom(roomId: string, text: string): Promise<unknown>;
|
|
50
|
+
/** #1820 part 2: SecureChannel's owner-list generation (absent on an older plugin). */
|
|
51
|
+
ownerDevicesGeneration?(): number;
|
|
52
|
+
/** #1820 part 2: a fail-closed re-check against a fresh owner list (absent on an older plugin). */
|
|
53
|
+
isCurrentOwnerDevice?(deviceId: string | null | undefined): Promise<boolean>;
|
|
30
54
|
/** SecureChannel's TelemetryReporter (device JWT, buffered). Optional so
|
|
31
55
|
* fixtures and a channel without telemetry keep working. */
|
|
32
56
|
telemetry?: ({
|
|
@@ -39,15 +63,56 @@ export interface BridgeChannel {
|
|
|
39
63
|
}): void;
|
|
40
64
|
} & Partial<ToolSpanSink>) | null;
|
|
41
65
|
}
|
|
66
|
+
/** A history entry; `files` (#1762 §1.5) lists files the agent sent with it. */
|
|
67
|
+
export interface HistoryLine {
|
|
68
|
+
text: string;
|
|
69
|
+
/** `"owner"`, `"agent"`, (#1800 PR B) `"unverified"` for an unbound sender's line, or
|
|
70
|
+
* (#1848 review) `"member"` for a room or 1:1 line from anyone but the bound owner. */
|
|
71
|
+
sender: string;
|
|
72
|
+
/** #1800 PR D: honoured if an entry ever carries the flag itself. */
|
|
73
|
+
unverified?: boolean;
|
|
74
|
+
files?: Array<{
|
|
75
|
+
filename: string;
|
|
76
|
+
size: number;
|
|
77
|
+
}>;
|
|
78
|
+
}
|
|
42
79
|
export interface TurnDriver {
|
|
43
80
|
run(key: string, prompt: string, signal?: AbortSignal, opts?: {
|
|
44
81
|
freshContext?: string;
|
|
82
|
+
mcp?: McpWiring;
|
|
83
|
+
startFresh?: boolean;
|
|
84
|
+
hold?: {
|
|
85
|
+
until: number;
|
|
86
|
+
};
|
|
87
|
+
budgetMs?: number;
|
|
45
88
|
}): Promise<TurnResult>;
|
|
89
|
+
/** #1762 PR-X: the Codex session stored for a key (undefined: none). Absent: the owner lane never attests. */
|
|
90
|
+
storedSession?(key: string): Promise<string | undefined>;
|
|
91
|
+
}
|
|
92
|
+
/** #1762 PR-X — what the bridge needs for file sends. Production: runtime.ts. */
|
|
93
|
+
export interface BridgeOptions {
|
|
94
|
+
/** Where the ONE turn consumer is attached (production: the TurnInbox SecureChannel calls). */
|
|
95
|
+
inbox?: {
|
|
96
|
+
attach(consumer: (text: string, metadata: MessageMetadata) => void): void;
|
|
97
|
+
};
|
|
98
|
+
/** The per-turn `avroom` MCP server: its socket folder, node and the shim. Absent: no send_file. */
|
|
99
|
+
mcp?: {
|
|
100
|
+
dir: string | (() => string);
|
|
101
|
+
command: string;
|
|
102
|
+
shim: string;
|
|
103
|
+
version?: string;
|
|
104
|
+
};
|
|
105
|
+
/** Writes the model's bytes into the turn's staging folder (default: SecureChannel's folders). */
|
|
106
|
+
stager?: ContentStager;
|
|
107
|
+
/** The owner lane's durable taint (absent: the owner lane never attests). */
|
|
108
|
+
ownerLaneTaint?: OwnerLaneTaint;
|
|
109
|
+
/** Test seam: the per-call clocks (defaults DEFAULT_CALL_TIMING). */
|
|
110
|
+
timing?: Partial<typeof DEFAULT_CALL_TIMING>;
|
|
46
111
|
}
|
|
47
112
|
/** Why a turn was dropped on purpose (#1560): logged, never shown as a failure.
|
|
48
113
|
* #1583: `shutdown` is our own stop or restart (SIGTERM, a fleet roll), the one
|
|
49
114
|
* cancel the owner is told about. Every other reason stays silent. */
|
|
50
|
-
export type CancelReason = "shutdown" | "auth_failed" | "revoked" | "channel_state" | "delivery_timeout" | "hushed" | "device_changed" | "unknown";
|
|
115
|
+
export type CancelReason = "shutdown" | "auth_failed" | "revoked" | "channel_state" | "delivery_timeout" | "hushed" | "device_changed" | "owner_revoked" | "unknown";
|
|
51
116
|
/** Serial inference AND delivery; every queued entry owns its authenticated target. */
|
|
52
117
|
export declare class OpenAIBridge {
|
|
53
118
|
private channel;
|
|
@@ -57,15 +122,21 @@ export declare class OpenAIBridge {
|
|
|
57
122
|
private maxQueue;
|
|
58
123
|
private deliveryTimeoutMs;
|
|
59
124
|
private noticeTimeoutMs;
|
|
125
|
+
private readonly files;
|
|
60
126
|
private tail;
|
|
61
127
|
private pending;
|
|
62
128
|
private generation;
|
|
63
129
|
private ready;
|
|
64
130
|
private accepting;
|
|
65
131
|
private waiting;
|
|
132
|
+
/** #1762 PR-X: the owner lane's seed — this process's own owner-lane turns only. */
|
|
133
|
+
private readonly ownerTranscript;
|
|
134
|
+
private readonly stager;
|
|
66
135
|
/** The reason each generation ended, keyed by the generation it ended (#1560). */
|
|
67
136
|
private cancelReasons;
|
|
68
137
|
private stopped;
|
|
138
|
+
/** stop() has finished: onMessage consumes nothing more (#1762 PR-X). */
|
|
139
|
+
private detached;
|
|
69
140
|
private active?;
|
|
70
141
|
private hush;
|
|
71
142
|
/** #1583: armed by stop("shutdown"): one deadline shared by every notice. */
|
|
@@ -73,8 +144,22 @@ export declare class OpenAIBridge {
|
|
|
73
144
|
/** True once that cap has run out: a notice is no longer worth starting. */
|
|
74
145
|
private capExpired;
|
|
75
146
|
private notices;
|
|
147
|
+
/** #1820 part 2: the grants of queued 1:1 turns (see owner-grant.ts). */
|
|
148
|
+
private readonly ownerGrants;
|
|
149
|
+
/** #1820 part 2: the 1:1 turn running now, so owner_devices_changed can cancel it. */
|
|
150
|
+
private activeDm?;
|
|
76
151
|
private listeners;
|
|
77
|
-
constructor(channel: BridgeChannel, driver: TurnDriver, name: string, report?: (event: string) => void, maxQueue?: number, deliveryTimeoutMs?: number, noticeTimeoutMs?: number);
|
|
152
|
+
constructor(channel: BridgeChannel, driver: TurnDriver, name: string, report?: (event: string) => void, maxQueue?: number, deliveryTimeoutMs?: number, noticeTimeoutMs?: number, files?: BridgeOptions);
|
|
153
|
+
/**
|
|
154
|
+
* #1762 PR-X — THE CLAIMANT (design §11 R3-4 a′). SecureChannel hands each
|
|
155
|
+
* inbound message to `onMessage` ONCE, with its lease; this is the only
|
|
156
|
+
* function that receives it, and it owns the lease for the whole turn:
|
|
157
|
+
* taken synchronously on the first line, then handed to the queued turn, or
|
|
158
|
+
* dropped (ended) — never left behind. Nothing here awaits.
|
|
159
|
+
*/
|
|
160
|
+
private onInbound;
|
|
161
|
+
private onDm;
|
|
162
|
+
private onRoom;
|
|
78
163
|
private listen;
|
|
79
164
|
private hushed;
|
|
80
165
|
/** Ends the current generation. Its reason is recorded BEFORE the bump, under
|
|
@@ -85,6 +170,34 @@ export declare class OpenAIBridge {
|
|
|
85
170
|
/** Recent entries as `sender: text`, without the bridge's own failure notices. */
|
|
86
171
|
private context;
|
|
87
172
|
private enqueue;
|
|
173
|
+
/** End (the turn ran) or drop (it never did) — bounded, never throws. */
|
|
174
|
+
private settle;
|
|
175
|
+
/**
|
|
176
|
+
* #1762 PR-X (§7, R3-10) — may the owner lane's next run attest? `true`:
|
|
177
|
+
* its stored session is recorded clean (or there is none, so the run starts
|
|
178
|
+
* one). `"rotate"`: the stored session is tainted or unrecorded, so the run
|
|
179
|
+
* starts a NEW session (which is clean) instead of resuming it. `false`: the
|
|
180
|
+
* lane cannot be shown clean at all (no taint store, an unreadable session
|
|
181
|
+
* record, or a Codex version whose sessions were not verified to be
|
|
182
|
+
* separate) — the turn runs, unattested.
|
|
183
|
+
*/
|
|
184
|
+
private ownerLaneReady;
|
|
185
|
+
/** Can this turn send a file at all (SecureChannel has a staging folder for its target)? */
|
|
186
|
+
private filesAvailable;
|
|
187
|
+
/**
|
|
188
|
+
* #1762 PR-X (§2.3) — one `send_file` call on THIS turn's endpoint. A room
|
|
189
|
+
* turn that is not attested is refused BEFORE anything is written (the
|
|
190
|
+
* channel refuses it on authority alone, with an empty path, so the room
|
|
191
|
+
* still gets its one bare notice). Then the arguments are validated, the
|
|
192
|
+
* bytes staged in the turn's own folder, and the normal sendFile runs.
|
|
193
|
+
*/
|
|
194
|
+
/**
|
|
195
|
+
* #1762 PR-X (review #1788 item 3): run one `send_file` call with the turn
|
|
196
|
+
* HELD open for the longest that call may take (Codex's own tool timeout
|
|
197
|
+
* plus a margin), and tracked, so the turn ends only after it settled.
|
|
198
|
+
*/
|
|
199
|
+
private heldCall;
|
|
200
|
+
private sendFileCall;
|
|
88
201
|
/** #1560: a turn that failed (not one cancelled on purpose). RECORD FIRST —
|
|
89
202
|
* the span and the log line — then post the notice, so a notice that stalls
|
|
90
203
|
* or fails cannot lose the record. Only codes and the exit status are
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #1762 PR-X — the SecureChannel configuration this bridge runs with, in one
|
|
3
|
+
* place, so a test can build the REAL channel exactly as production does and
|
|
4
|
+
* prove the production wiring hands each turn a lease (design §11 R3-4 a′).
|
|
5
|
+
* Ported from packages/claude-room-bridge/src/channel-config.ts.
|
|
6
|
+
*
|
|
7
|
+
* Two lines here are load-bearing for file sends:
|
|
8
|
+
* - `fileSend` opts in. Without it SecureChannel creates no staging folder and
|
|
9
|
+
* ends every token at mint (`turn_no_consumer`). This bridge has NO
|
|
10
|
+
* workspace (Codex writes nothing; the bridge stages the bytes itself), so
|
|
11
|
+
* the outbox sits beside the data dir:
|
|
12
|
+
* `~/.agentvault/openai/agentvault-outbox/<name>-<hash>/` (the policy case
|
|
13
|
+
* table pins this layout);
|
|
14
|
+
* - `onMessage` is the TurnInbox, the single turn consumer. Without it every
|
|
15
|
+
* token is dropped at mint and `send_file` answers `turn_no_consumer`.
|
|
16
|
+
*/
|
|
17
|
+
import type { SecureChannelConfig } from "@agentvault/agentvault";
|
|
18
|
+
import type { TurnInbox } from "./file-turn.js";
|
|
19
|
+
export interface BridgeChannelInputs {
|
|
20
|
+
inviteToken: string;
|
|
21
|
+
dataDir: string;
|
|
22
|
+
apiUrl: string;
|
|
23
|
+
agentName: string;
|
|
24
|
+
forceReEnroll: boolean;
|
|
25
|
+
/** `@agentvault/openai-bridge@<version>` (#836). */
|
|
26
|
+
clientVersion: string;
|
|
27
|
+
}
|
|
28
|
+
export declare function bridgeChannelConfig(cfg: BridgeChannelInputs, inbox: TurnInbox): SecureChannelConfig;
|
|
29
|
+
//# sourceMappingURL=channel-config.d.ts.map
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type HistoryRecoveryCommandInput } from "@agentvault/agentvault";
|
|
2
2
|
import { type Layout } from "./driver.js";
|
|
3
|
-
export declare const VERSION = "0.1.
|
|
3
|
+
export declare const VERSION = "0.1.23";
|
|
4
4
|
export interface RunConfig {
|
|
5
5
|
name: string;
|
|
6
6
|
apiUrl: string;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ONE Codex CLI version this bridge runs (#1762 PR-X, X-3: 0.154.0 →
|
|
3
|
+
* 0.162.1). The driver refuses any other `codex --version`, the rollout
|
|
4
|
+
* check refuses any other `session_meta.cli_version`, and the owner lane
|
|
5
|
+
* attests only while this version is in `CROSS_SESSION_MEMORY_VERIFIED`.
|
|
6
|
+
*
|
|
7
|
+
* Bumping it means measuring again, on the new binary, with
|
|
8
|
+
* `scripts/live-gate-1762.py`:
|
|
9
|
+
* - the default-deny feature list (`codex features list`);
|
|
10
|
+
* - that `approval_policy="never"` plus the per-tool `approval_mode` runs
|
|
11
|
+
* the `send_file` call, and `enabled_tools` holds under
|
|
12
|
+
* `--ignore-user-config`;
|
|
13
|
+
* - that a fresh session carries nothing from another session (memories,
|
|
14
|
+
* thread history) — the owner-lane taint clears on a new session only
|
|
15
|
+
* because of that;
|
|
16
|
+
* - the exec stream and rollout shapes the driver and rollout.ts accept.
|
|
17
|
+
*/
|
|
18
|
+
export declare const SUPPORTED_CODEX_VERSION = "0.162.1";
|
|
19
|
+
/**
|
|
20
|
+
* #1762 PR-X — Codex versions measured (live gate, mock provider, isolated
|
|
21
|
+
* CODEX_HOME) to carry NOTHING from one session into a fresh one with this
|
|
22
|
+
* bridge's flags: a marker sent in session A is absent from every request of
|
|
23
|
+
* a fresh session B in the same CODEX_HOME (memories disabled, no shared
|
|
24
|
+
* thread history in the model input). A version outside this set never
|
|
25
|
+
* attests an owner-lane turn: its "new session" could not be shown to be new.
|
|
26
|
+
* owner-lane.test.ts fails when SUPPORTED_CODEX_VERSION leaves this set.
|
|
27
|
+
*/
|
|
28
|
+
export declare const CROSS_SESSION_MEMORY_VERIFIED: ReadonlySet<string>;
|
|
29
|
+
//# sourceMappingURL=codex-version.d.ts.map
|