@agentvault/openai-bridge 0.1.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/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # AgentVault OpenAI Bridge
2
+
3
+ Connect a local OpenAI Codex login to encrypted AgentVault owner direct messages and rooms. This is the `openai` framework under the existing `harness` runtime. It does not use an OpenAI API key or the archived Codex channel runtime.
4
+
5
+ **Release status:** initial release. The app offers installation only after registry installation and an owner-authenticated live messaging check pass. Tests alone do not establish account access, billing eligibility, or production delivery.
6
+
7
+ ## Prerequisites and login
8
+
9
+ Node.js 20 or newer, macOS or Linux, and **the native Codex CLI 0.154.0 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
+
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
+
13
+ Choose one agent name and use it for every command:
14
+
15
+ ```sh
16
+ AV_AGENT_NAME=aster agentvault-openai-bridge login
17
+ AV_AGENT_NAME=aster agentvault-openai-bridge doctor
18
+ AV_AGENT_NAME=aster AV_INVITE_TOKEN='<invite>' agentvault-openai-bridge run
19
+ ```
20
+
21
+ `login` explicitly runs the official Codex device-auth login. It uses this agent's dedicated auth directory and does not reuse your normal Codex login or configuration. Complete the browser instructions printed by Codex. No login or provider call happens during package installation, help, version, or tests.
22
+
23
+ The invite remains in a mode-0600 `pending-invite` file until the encrypted channel becomes ready after approval. A restart loads existing AgentVault credentials. Keep the same `AV_AGENT_NAME`; another name selects separate auth, device credentials and history.
24
+
25
+ ## Background service
26
+
27
+ After explicit login and global installation:
28
+
29
+ ```sh
30
+ AV_AGENT_NAME=aster AV_INVITE_TOKEN='<invite>' agentvault-openai-bridge install
31
+ AV_AGENT_NAME=aster agentvault-openai-bridge status
32
+ AV_AGENT_NAME=aster agentvault-openai-bridge logs
33
+ AV_AGENT_NAME=aster agentvault-openai-bridge restart
34
+ AV_AGENT_NAME=aster agentvault-openai-bridge uninstall
35
+ ```
36
+
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
+
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:
40
+
41
+ ```sh
42
+ AV_AGENT_NAME=aster AV_INVITE_TOKEN='<fresh-invite>' agentvault-openai-bridge replace
43
+ ```
44
+
45
+ Replacement acquires the agent lock before archiving prior AgentVault credentials under the private `replacement-recovery/<uuid>/` directory and forcing enrollment. Codex login and history are retained. Existing credentials are never silently reused for this explicit command. If enrollment fails, the archive remains for deliberate operator recovery; normal restarts do not restore it automatically. After approval, stop the foreground process and install the service again. Do not copy another agent's credentials into this state directory.
46
+
47
+ The shared SecureChannel currently persists new enrollment keys only after activation. A crash before approval can leave the invite consumed without recoverable local keys. Retaining `pending-invite` does not solve that gap: obtain a fresh recovery invite if the interrupted enrollment cannot resume.
48
+
49
+ ## Conversation and privacy boundaries
50
+
51
+ Only direct messages positively attested by SecureChannel as owner 1:1 messages can dispatch a private turn. Rooms answer according to AgentVault's shared mention policy, evaluated on the typed caption, and remain silent while hushed. Recent context comes only from the addressed room. Replies are bound to the original conversation ID or room ID. Device ID, conversation kind, and conversation ID jointly select a separate persistent Codex session UUID; the bridge never resumes “last”.
52
+
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
+
55
+ Codex children receive only a dedicated HOME, CODEX_HOME, TMPDIR, and a minimal PATH. The measured configuration disables shell, filesystem tools, web search, MCP/apps/plugins, delegation, and other integrations. Read-only sandboxing and approval `never` are mandatory because an unadvertised patch handler still exists. 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
+
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
+
59
+ ## Local checks
60
+
61
+ ```sh
62
+ npm test
63
+ npm run typecheck
64
+ npm run build
65
+ node dist/index.js --help
66
+ npm pack --dry-run --ignore-scripts
67
+ ```
68
+
69
+ Tests use disposable fixture roots, fake executables, fake encrypted channels, and injected service commands. They never run launchctl/systemctl, log into an account, contact AgentVault, or call a real provider. The build bundles the freshly built local SecureChannel artifact and checks required enrollment/sender fields.
70
+
71
+ The optional real-binary gate runs only when explicitly invoked after a build:
72
+
73
+ ```sh
74
+ python3 scripts/mock-provider-gate.py --codex /absolute/path/to/native/codex
75
+ ```
76
+
77
+ It 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,53 @@
1
+ import type { TurnResult } from "./driver.js";
2
+ export interface BridgeChannel {
3
+ on(event: string, listener: (...args: any[]) => void): unknown;
4
+ off(event: string, listener: (...args: any[]) => void): unknown;
5
+ deviceId: string | null;
6
+ ownDisplayName?: string;
7
+ getRooms?(): Array<{
8
+ roomId: string;
9
+ members: Array<{
10
+ deviceId: string;
11
+ displayName: string;
12
+ }>;
13
+ }>;
14
+ getRoomHistory?(roomId: string, max: number): Array<{
15
+ text: string;
16
+ sender: string;
17
+ }>;
18
+ send(text: string, options: {
19
+ conversationId: string;
20
+ }): Promise<unknown>;
21
+ sendToRoom(roomId: string, text: string): Promise<unknown>;
22
+ }
23
+ export interface TurnDriver {
24
+ run(key: string, prompt: string, signal?: AbortSignal): Promise<TurnResult>;
25
+ }
26
+ /** Serial inference AND delivery; every queued entry owns its authenticated target. */
27
+ export declare class OpenAIBridge {
28
+ private channel;
29
+ private driver;
30
+ private name;
31
+ private report;
32
+ private maxQueue;
33
+ private deliveryTimeoutMs;
34
+ private tail;
35
+ private pending;
36
+ private generation;
37
+ private ready;
38
+ private accepting;
39
+ private waiting;
40
+ private stopped;
41
+ private active?;
42
+ private hush;
43
+ private listeners;
44
+ constructor(channel: BridgeChannel, driver: TurnDriver, name: string, report?: (event: string) => void, maxQueue?: number, deliveryTimeoutMs?: number);
45
+ private listen;
46
+ private hushed;
47
+ private invalidate;
48
+ private enqueue;
49
+ private deliver;
50
+ idle(): Promise<void>;
51
+ stop(): Promise<void>;
52
+ }
53
+ //# sourceMappingURL=bridge.d.ts.map
package/dist/cli.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ import { type Layout } from "./driver.js";
2
+ export declare const VERSION = "0.1.0";
3
+ export interface RunConfig {
4
+ name: string;
5
+ apiUrl: string;
6
+ binary: string;
7
+ layout: Layout;
8
+ inviteToken: string;
9
+ forceReEnroll?: boolean;
10
+ }
11
+ export interface CommandOptions {
12
+ env?: NodeJS.ProcessEnv;
13
+ cwd?: string;
14
+ interactive?: boolean;
15
+ }
16
+ export interface CliDependencies {
17
+ env: NodeJS.ProcessEnv;
18
+ platform: string;
19
+ uid: number;
20
+ node: string;
21
+ entrypoint: string;
22
+ resolveBinary(): Promise<string>;
23
+ checkBinary(binary: string, layout: Layout): Promise<void>;
24
+ command(binary: string, args: string[], options?: CommandOptions): Promise<{
25
+ code: number;
26
+ stdout: string;
27
+ }>;
28
+ start(config: RunConfig): Promise<void>;
29
+ output(text: string): void;
30
+ }
31
+ export declare function agentSlug(name: string): string;
32
+ export declare function agentStateRoot(env: NodeJS.ProcessEnv): string;
33
+ export declare function serviceDefinition(platform: string, config: RunConfig, deps: Pick<CliDependencies, "env" | "node" | "entrypoint" | "uid">): {
34
+ path: string;
35
+ label: string;
36
+ contents: string;
37
+ };
38
+ export declare function runCli(args: string[], deps: CliDependencies): Promise<number>;
39
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1,42 @@
1
+ export declare const SUPPORTED_CODEX_VERSION = "0.154.0";
2
+ export declare const CODE_MODE_WARNING = "Code Mode is unavailable because code-mode host is disabled. Code mode will fail closed; enable `features.code_mode_host` and install `codex-code-mode-host`.";
3
+ export interface Layout {
4
+ root: string;
5
+ home: string;
6
+ codex: string;
7
+ tmp: string;
8
+ work: string;
9
+ sessions: string;
10
+ }
11
+ export declare function createLayout(root: string): Promise<Layout>;
12
+ export declare function atomicPrivateWrite(path: string, value: string): Promise<void>;
13
+ export declare function childEnvironment(layout: Layout): NodeJS.ProcessEnv;
14
+ export declare function buildInvocation(layout: Layout, sessionId?: string): {
15
+ args: string[];
16
+ env: NodeJS.ProcessEnv;
17
+ cwd: string;
18
+ };
19
+ export declare function resolveCodex(path?: string): Promise<string>;
20
+ export declare function checkVersion(binary: string, layout: Layout): Promise<void>;
21
+ export interface TurnResult {
22
+ text: string;
23
+ sessionId: string;
24
+ }
25
+ export interface DriverOptions {
26
+ binary: string;
27
+ layout: Layout;
28
+ timeoutMs?: number;
29
+ killGraceMs?: number;
30
+ maxLineBytes?: number;
31
+ maxOutputBytes?: number;
32
+ }
33
+ /** One caller at a time. The bridge serializes delivery as well as inference. */
34
+ export declare class CodexDriver {
35
+ private readonly options;
36
+ private busy;
37
+ private poisoned;
38
+ constructor(options: DriverOptions);
39
+ run(key: string, prompt: string, signal?: AbortSignal): Promise<TurnResult>;
40
+ private execute;
41
+ }
42
+ //# sourceMappingURL=driver.d.ts.map
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ export { runCli } from "./cli.js";
3
+ export { CodexDriver, buildInvocation, createLayout } from "./driver.js";
4
+ export { OpenAIBridge } from "./bridge.js";
5
+ export declare function main(args?: string[]): Promise<number>;
6
+ //# sourceMappingURL=index.d.ts.map