uxnan-bridge 0.0.1-alpha.20260621
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 +150 -0
- package/dist/src/account-status.d.ts +13 -0
- package/dist/src/account-status.js +78 -0
- package/dist/src/account-status.js.map +1 -0
- package/dist/src/adapters/base-adapter.d.ts +18 -0
- package/dist/src/adapters/base-adapter.js +15 -0
- package/dist/src/adapters/base-adapter.js.map +1 -0
- package/dist/src/adapters/claude-adapter.d.ts +102 -0
- package/dist/src/adapters/claude-adapter.js +486 -0
- package/dist/src/adapters/claude-adapter.js.map +1 -0
- package/dist/src/adapters/claude-tools.d.ts +25 -0
- package/dist/src/adapters/claude-tools.js +146 -0
- package/dist/src/adapters/claude-tools.js.map +1 -0
- package/dist/src/adapters/codex-adapter.d.ts +116 -0
- package/dist/src/adapters/codex-adapter.js +912 -0
- package/dist/src/adapters/codex-adapter.js.map +1 -0
- package/dist/src/adapters/codex-app-server.d.ts +74 -0
- package/dist/src/adapters/codex-app-server.js +225 -0
- package/dist/src/adapters/codex-app-server.js.map +1 -0
- package/dist/src/adapters/codex-approval.d.ts +88 -0
- package/dist/src/adapters/codex-approval.js +160 -0
- package/dist/src/adapters/codex-approval.js.map +1 -0
- package/dist/src/adapters/codex-tools.d.ts +18 -0
- package/dist/src/adapters/codex-tools.js +106 -0
- package/dist/src/adapters/codex-tools.js.map +1 -0
- package/dist/src/adapters/content-blocks.d.ts +68 -0
- package/dist/src/adapters/content-blocks.js +205 -0
- package/dist/src/adapters/content-blocks.js.map +1 -0
- package/dist/src/adapters/echo-agent-adapter.d.ts +23 -0
- package/dist/src/adapters/echo-agent-adapter.js +72 -0
- package/dist/src/adapters/echo-agent-adapter.js.map +1 -0
- package/dist/src/adapters/gemini-adapter.d.ts +87 -0
- package/dist/src/adapters/gemini-adapter.js +594 -0
- package/dist/src/adapters/gemini-adapter.js.map +1 -0
- package/dist/src/adapters/gemini-tools.d.ts +4 -0
- package/dist/src/adapters/gemini-tools.js +48 -0
- package/dist/src/adapters/gemini-tools.js.map +1 -0
- package/dist/src/adapters/opencode-adapter.d.ts +74 -0
- package/dist/src/adapters/opencode-adapter.js +418 -0
- package/dist/src/adapters/opencode-adapter.js.map +1 -0
- package/dist/src/adapters/opencode-tools.d.ts +2 -0
- package/dist/src/adapters/opencode-tools.js +41 -0
- package/dist/src/adapters/opencode-tools.js.map +1 -0
- package/dist/src/adapters/pi-adapter.d.ts +92 -0
- package/dist/src/adapters/pi-adapter.js +467 -0
- package/dist/src/adapters/pi-adapter.js.map +1 -0
- package/dist/src/adapters/pi-tools.d.ts +10 -0
- package/dist/src/adapters/pi-tools.js +72 -0
- package/dist/src/adapters/pi-tools.js.map +1 -0
- package/dist/src/adapters/process-agent-adapter.d.ts +24 -0
- package/dist/src/adapters/process-agent-adapter.js +111 -0
- package/dist/src/adapters/process-agent-adapter.js.map +1 -0
- package/dist/src/adapters/resolve-claude.d.ts +13 -0
- package/dist/src/adapters/resolve-claude.js +57 -0
- package/dist/src/adapters/resolve-claude.js.map +1 -0
- package/dist/src/adapters/resolve-codex.d.ts +13 -0
- package/dist/src/adapters/resolve-codex.js +48 -0
- package/dist/src/adapters/resolve-codex.js.map +1 -0
- package/dist/src/adapters/resolve-gemini.d.ts +13 -0
- package/dist/src/adapters/resolve-gemini.js +47 -0
- package/dist/src/adapters/resolve-gemini.js.map +1 -0
- package/dist/src/adapters/resolve-opencode.d.ts +11 -0
- package/dist/src/adapters/resolve-opencode.js +49 -0
- package/dist/src/adapters/resolve-opencode.js.map +1 -0
- package/dist/src/adapters/resolve-pi.d.ts +13 -0
- package/dist/src/adapters/resolve-pi.js +46 -0
- package/dist/src/adapters/resolve-pi.js.map +1 -0
- package/dist/src/adapters/run-options.d.ts +22 -0
- package/dist/src/adapters/run-options.js +48 -0
- package/dist/src/adapters/run-options.js.map +1 -0
- package/dist/src/adapters/spawn.d.ts +20 -0
- package/dist/src/adapters/spawn.js +16 -0
- package/dist/src/adapters/spawn.js.map +1 -0
- package/dist/src/agents/agent-manager.d.ts +98 -0
- package/dist/src/agents/agent-manager.js +433 -0
- package/dist/src/agents/agent-manager.js.map +1 -0
- package/dist/src/agents/attachments.d.ts +28 -0
- package/dist/src/agents/attachments.js +121 -0
- package/dist/src/agents/attachments.js.map +1 -0
- package/dist/src/bridge-context.d.ts +45 -0
- package/dist/src/bridge-context.js +2 -0
- package/dist/src/bridge-context.js.map +1 -0
- package/dist/src/bridge-status.d.ts +12 -0
- package/dist/src/bridge-status.js +17 -0
- package/dist/src/bridge-status.js.map +1 -0
- package/dist/src/bridge.d.ts +37 -0
- package/dist/src/bridge.js +446 -0
- package/dist/src/bridge.js.map +1 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +194 -0
- package/dist/src/cli.js.map +1 -0
- package/dist/src/conversation/session-history.d.ts +27 -0
- package/dist/src/conversation/session-history.js +1082 -0
- package/dist/src/conversation/session-history.js.map +1 -0
- package/dist/src/conversation/thread-store.d.ts +74 -0
- package/dist/src/conversation/thread-store.js +366 -0
- package/dist/src/conversation/thread-store.js.map +1 -0
- package/dist/src/daemon-config.d.ts +123 -0
- package/dist/src/daemon-config.js +64 -0
- package/dist/src/daemon-config.js.map +1 -0
- package/dist/src/daemon-state.d.ts +27 -0
- package/dist/src/daemon-state.js +76 -0
- package/dist/src/daemon-state.js.map +1 -0
- package/dist/src/git/git-runner.d.ts +24 -0
- package/dist/src/git/git-runner.js +63 -0
- package/dist/src/git/git-runner.js.map +1 -0
- package/dist/src/git/git-service.d.ts +76 -0
- package/dist/src/git/git-service.js +435 -0
- package/dist/src/git/git-service.js.map +1 -0
- package/dist/src/handler-router.d.ts +34 -0
- package/dist/src/handler-router.js +67 -0
- package/dist/src/handler-router.js.map +1 -0
- package/dist/src/handlers/account-handler.d.ts +4 -0
- package/dist/src/handlers/account-handler.js +27 -0
- package/dist/src/handlers/account-handler.js.map +1 -0
- package/dist/src/handlers/agent-handler.d.ts +2 -0
- package/dist/src/handlers/agent-handler.js +8 -0
- package/dist/src/handlers/agent-handler.js.map +1 -0
- package/dist/src/handlers/bridge-control-handler.d.ts +2 -0
- package/dist/src/handlers/bridge-control-handler.js +64 -0
- package/dist/src/handlers/bridge-control-handler.js.map +1 -0
- package/dist/src/handlers/desktop-handler.d.ts +12 -0
- package/dist/src/handlers/desktop-handler.js +5 -0
- package/dist/src/handlers/desktop-handler.js.map +1 -0
- package/dist/src/handlers/git-handler.d.ts +2 -0
- package/dist/src/handlers/git-handler.js +82 -0
- package/dist/src/handlers/git-handler.js.map +1 -0
- package/dist/src/handlers/index.d.ts +8 -0
- package/dist/src/handlers/index.js +22 -0
- package/dist/src/handlers/index.js.map +1 -0
- package/dist/src/handlers/not-implemented.d.ts +10 -0
- package/dist/src/handlers/not-implemented.js +21 -0
- package/dist/src/handlers/not-implemented.js.map +1 -0
- package/dist/src/handlers/notifications-handler.d.ts +2 -0
- package/dist/src/handlers/notifications-handler.js +62 -0
- package/dist/src/handlers/notifications-handler.js.map +1 -0
- package/dist/src/handlers/params.d.ts +11 -0
- package/dist/src/handlers/params.js +72 -0
- package/dist/src/handlers/params.js.map +1 -0
- package/dist/src/handlers/project-handler.d.ts +2 -0
- package/dist/src/handlers/project-handler.js +6 -0
- package/dist/src/handlers/project-handler.js.map +1 -0
- package/dist/src/handlers/thread-context-handler.d.ts +2 -0
- package/dist/src/handlers/thread-context-handler.js +211 -0
- package/dist/src/handlers/thread-context-handler.js.map +1 -0
- package/dist/src/handlers/workspace-handler.d.ts +2 -0
- package/dist/src/handlers/workspace-handler.js +101 -0
- package/dist/src/handlers/workspace-handler.js.map +1 -0
- package/dist/src/hooks/claude-approval-hook.d.ts +7 -0
- package/dist/src/hooks/claude-approval-hook.js +95 -0
- package/dist/src/hooks/claude-approval-hook.js.map +1 -0
- package/dist/src/hooks/gemini-approval-hook.d.ts +7 -0
- package/dist/src/hooks/gemini-approval-hook.js +113 -0
- package/dist/src/hooks/gemini-approval-hook.js.map +1 -0
- package/dist/src/index.d.ts +62 -0
- package/dist/src/index.js +65 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/keyring-secret-store.d.ts +36 -0
- package/dist/src/keyring-secret-store.js +70 -0
- package/dist/src/keyring-secret-store.js.map +1 -0
- package/dist/src/lock-file.d.ts +18 -0
- package/dist/src/lock-file.js +60 -0
- package/dist/src/lock-file.js.map +1 -0
- package/dist/src/logger.d.ts +28 -0
- package/dist/src/logger.js +99 -0
- package/dist/src/logger.js.map +1 -0
- package/dist/src/pairing/pairing-code-service.d.ts +45 -0
- package/dist/src/pairing/pairing-code-service.js +183 -0
- package/dist/src/pairing/pairing-code-service.js.map +1 -0
- package/dist/src/projects/project-registry.d.ts +14 -0
- package/dist/src/projects/project-registry.js +60 -0
- package/dist/src/projects/project-registry.js.map +1 -0
- package/dist/src/push/push-sender.d.ts +21 -0
- package/dist/src/push/push-sender.js +96 -0
- package/dist/src/push/push-sender.js.map +1 -0
- package/dist/src/push/push-service.d.ts +122 -0
- package/dist/src/push/push-service.js +260 -0
- package/dist/src/push/push-service.js.map +1 -0
- package/dist/src/qr.d.ts +17 -0
- package/dist/src/qr.js +31 -0
- package/dist/src/qr.js.map +1 -0
- package/dist/src/secret-store.d.ts +23 -0
- package/dist/src/secret-store.js +27 -0
- package/dist/src/secret-store.js.map +1 -0
- package/dist/src/secure-device-state.d.ts +16 -0
- package/dist/src/secure-device-state.js +63 -0
- package/dist/src/secure-device-state.js.map +1 -0
- package/dist/src/service-installer.d.ts +57 -0
- package/dist/src/service-installer.js +254 -0
- package/dist/src/service-installer.js.map +1 -0
- package/dist/src/session-state.d.ts +14 -0
- package/dist/src/session-state.js +19 -0
- package/dist/src/session-state.js.map +1 -0
- package/dist/src/transport/crypto.d.ts +43 -0
- package/dist/src/transport/crypto.js +78 -0
- package/dist/src/transport/crypto.js.map +1 -0
- package/dist/src/transport/lan-server.d.ts +33 -0
- package/dist/src/transport/lan-server.js +105 -0
- package/dist/src/transport/lan-server.js.map +1 -0
- package/dist/src/transport/local-hosts.d.ts +17 -0
- package/dist/src/transport/local-hosts.js +30 -0
- package/dist/src/transport/local-hosts.js.map +1 -0
- package/dist/src/transport/mdns-advertiser.d.ts +83 -0
- package/dist/src/transport/mdns-advertiser.js +282 -0
- package/dist/src/transport/mdns-advertiser.js.map +1 -0
- package/dist/src/transport/message-io.d.ts +33 -0
- package/dist/src/transport/message-io.js +87 -0
- package/dist/src/transport/message-io.js.map +1 -0
- package/dist/src/transport/outbound-log.d.ts +24 -0
- package/dist/src/transport/outbound-log.js +78 -0
- package/dist/src/transport/outbound-log.js.map +1 -0
- package/dist/src/transport/relay-client.d.ts +19 -0
- package/dist/src/transport/relay-client.js +27 -0
- package/dist/src/transport/relay-client.js.map +1 -0
- package/dist/src/transport/secure-channel.d.ts +33 -0
- package/dist/src/transport/secure-channel.js +81 -0
- package/dist/src/transport/secure-channel.js.map +1 -0
- package/dist/src/transport/server-handshake.d.ts +49 -0
- package/dist/src/transport/server-handshake.js +137 -0
- package/dist/src/transport/server-handshake.js.map +1 -0
- package/dist/src/transport/session-handler.d.ts +19 -0
- package/dist/src/transport/session-handler.js +134 -0
- package/dist/src/transport/session-handler.js.map +1 -0
- package/dist/src/transport/session-registry.d.ts +58 -0
- package/dist/src/transport/session-registry.js +91 -0
- package/dist/src/transport/session-registry.js.map +1 -0
- package/dist/src/transport/trust-store.d.ts +23 -0
- package/dist/src/transport/trust-store.js +33 -0
- package/dist/src/transport/trust-store.js.map +1 -0
- package/dist/src/transport/ws-adapter.d.ts +7 -0
- package/dist/src/transport/ws-adapter.js +16 -0
- package/dist/src/transport/ws-adapter.js.map +1 -0
- package/dist/src/version.d.ts +1 -0
- package/dist/src/version.js +13 -0
- package/dist/src/version.js.map +1 -0
- package/dist/src/workspace/browse-service.d.ts +10 -0
- package/dist/src/workspace/browse-service.js +97 -0
- package/dist/src/workspace/browse-service.js.map +1 -0
- package/dist/src/workspace/checkpoint-service.d.ts +21 -0
- package/dist/src/workspace/checkpoint-service.js +219 -0
- package/dist/src/workspace/checkpoint-service.js.map +1 -0
- package/dist/src/workspace/path-guard.d.ts +7 -0
- package/dist/src/workspace/path-guard.js +51 -0
- package/dist/src/workspace/path-guard.js.map +1 -0
- package/dist/src/workspace/workspace-service.d.ts +8 -0
- package/dist/src/workspace/workspace-service.js +111 -0
- package/dist/src/workspace/workspace-service.js.map +1 -0
- package/package.json +46 -0
- package/scripts/extract-gemini-hook.mjs +16 -0
- package/scripts/fake-approval-bridge.mjs +23 -0
- package/scripts/install-service-linux.sh +38 -0
- package/scripts/install-service-macos.sh +38 -0
- package/scripts/install-service-windows.ps1 +26 -0
- package/scripts/test-gemini-hook-e2e.mjs +168 -0
- package/scripts/write-gemini-settings.mjs +31 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maps Claude Code `tool_use` / `tool_result` stream-json blocks onto the
|
|
3
|
+
* bridge's structured MessageContent JSON (`command_execution` / `diff` /
|
|
4
|
+
* `tool`) the phone renders in the Work log and Changed files sections.
|
|
5
|
+
*
|
|
6
|
+
* Tool inputs are taken from the (complete) `assistant` message's `tool_use`
|
|
7
|
+
* blocks; outputs from the matching `tool_result` block in the following `user`
|
|
8
|
+
* message (paired by `tool_use_id`). Verified against `claude` 2.x stream-json.
|
|
9
|
+
*/
|
|
10
|
+
import { extractPlanSteps, planBlock } from './content-blocks.js';
|
|
11
|
+
/** Cap tool output carried on the wire so a big Read/Grep doesn't bloat it. */
|
|
12
|
+
const MAX_OUTPUT = 4000;
|
|
13
|
+
function isRecord(value) {
|
|
14
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
15
|
+
}
|
|
16
|
+
function str(value) {
|
|
17
|
+
return typeof value === 'string' ? value : '';
|
|
18
|
+
}
|
|
19
|
+
function truncate(text) {
|
|
20
|
+
return text.length > MAX_OUTPUT ? `${text.slice(0, MAX_OUTPUT)}\n… (truncated)` : text;
|
|
21
|
+
}
|
|
22
|
+
/** The tool names whose edits become a `diff` block. */
|
|
23
|
+
const EDIT_TOOLS = new Set(['Edit', 'MultiEdit', 'Write', 'NotebookEdit']);
|
|
24
|
+
/** Extracts the `tool_use` blocks from an `assistant` message's content. */
|
|
25
|
+
export function extractToolUses(content) {
|
|
26
|
+
if (!Array.isArray(content))
|
|
27
|
+
return [];
|
|
28
|
+
const uses = [];
|
|
29
|
+
for (const block of content) {
|
|
30
|
+
if (isRecord(block) &&
|
|
31
|
+
block['type'] === 'tool_use' &&
|
|
32
|
+
typeof block['id'] === 'string' &&
|
|
33
|
+
typeof block['name'] === 'string') {
|
|
34
|
+
uses.push({
|
|
35
|
+
id: block['id'],
|
|
36
|
+
name: block['name'],
|
|
37
|
+
input: isRecord(block['input']) ? block['input'] : {},
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return uses;
|
|
42
|
+
}
|
|
43
|
+
/** Extracts the `tool_result` blocks from a `user` message's content. */
|
|
44
|
+
export function extractToolResults(content) {
|
|
45
|
+
if (!Array.isArray(content))
|
|
46
|
+
return [];
|
|
47
|
+
const results = [];
|
|
48
|
+
for (const block of content) {
|
|
49
|
+
if (isRecord(block) &&
|
|
50
|
+
block['type'] === 'tool_result' &&
|
|
51
|
+
typeof block['tool_use_id'] === 'string') {
|
|
52
|
+
results.push({
|
|
53
|
+
toolUseId: block['tool_use_id'],
|
|
54
|
+
text: extractResultText(block['content']),
|
|
55
|
+
isError: block['is_error'] === true,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return results;
|
|
60
|
+
}
|
|
61
|
+
/** A tool_result's content is a string or an array of `{type:'text', text}`. */
|
|
62
|
+
export function extractResultText(content) {
|
|
63
|
+
if (typeof content === 'string')
|
|
64
|
+
return content;
|
|
65
|
+
if (Array.isArray(content)) {
|
|
66
|
+
let text = '';
|
|
67
|
+
for (const block of content) {
|
|
68
|
+
if (isRecord(block) && block['type'] === 'text' && typeof block['text'] === 'string') {
|
|
69
|
+
text += block['text'];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return text;
|
|
73
|
+
}
|
|
74
|
+
return '';
|
|
75
|
+
}
|
|
76
|
+
/** Lines as additions (`+`) for a whole-file Write. */
|
|
77
|
+
function additions(text) {
|
|
78
|
+
return text.length > 0 ? text.split('\n') : [];
|
|
79
|
+
}
|
|
80
|
+
/** Builds a `diff` MessageContent from an edit/write tool's input. */
|
|
81
|
+
function diffBlock(name, input) {
|
|
82
|
+
const filename = str(input['file_path']);
|
|
83
|
+
if (name === 'Write' || name === 'NotebookEdit') {
|
|
84
|
+
const lines = additions(str(input['content']) || str(input['new_source']));
|
|
85
|
+
return {
|
|
86
|
+
type: 'diff',
|
|
87
|
+
filename,
|
|
88
|
+
diff: lines.map((line) => `+${line}`).join('\n'),
|
|
89
|
+
additions: lines.length,
|
|
90
|
+
deletions: 0,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
// Edit / MultiEdit: render old→new as -/+ hunks.
|
|
94
|
+
const edits = name === 'MultiEdit' && Array.isArray(input['edits']) ? input['edits'] : [input];
|
|
95
|
+
const parts = [];
|
|
96
|
+
let added = 0;
|
|
97
|
+
let removed = 0;
|
|
98
|
+
for (const edit of edits) {
|
|
99
|
+
if (!isRecord(edit))
|
|
100
|
+
continue;
|
|
101
|
+
const oldLines = additions(str(edit['old_string']));
|
|
102
|
+
const newLines = additions(str(edit['new_string']));
|
|
103
|
+
removed += oldLines.length;
|
|
104
|
+
added += newLines.length;
|
|
105
|
+
parts.push(...oldLines.map((line) => `-${line}`), ...newLines.map((line) => `+${line}`));
|
|
106
|
+
}
|
|
107
|
+
return { type: 'diff', filename, diff: parts.join('\n'), additions: added, deletions: removed };
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Maps a paired tool_use + tool_result onto a MessageContent block:
|
|
111
|
+
* Bash → `command_execution`, edit/write tools → `diff`, everything else →
|
|
112
|
+
* a generic `tool` block. Returns the JSON the phone decodes via
|
|
113
|
+
* `MessageContent.fromJson`.
|
|
114
|
+
*/
|
|
115
|
+
export function toolUseToBlock(tool, result) {
|
|
116
|
+
if (tool.name === 'Bash') {
|
|
117
|
+
const output = truncate(result.text);
|
|
118
|
+
return {
|
|
119
|
+
type: 'command_execution',
|
|
120
|
+
command: str(tool.input['command']),
|
|
121
|
+
status: result.isError ? 'error' : 'completed',
|
|
122
|
+
...(output ? { output } : {}),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
if (EDIT_TOOLS.has(tool.name)) {
|
|
126
|
+
return diffBlock(tool.name, tool.input);
|
|
127
|
+
}
|
|
128
|
+
// Claude's TodoWrite tool carries the plan/to-do list: `{ todos: [{ content,
|
|
129
|
+
// status, activeForm }] }`. Surface it as a `plan` block (the phone renders a
|
|
130
|
+
// checklist); fall through to a generic tool block if it has no parseable steps.
|
|
131
|
+
if (tool.name === 'TodoWrite') {
|
|
132
|
+
const steps = extractPlanSteps(tool.input);
|
|
133
|
+
if (steps.length > 0)
|
|
134
|
+
return planBlock(steps);
|
|
135
|
+
}
|
|
136
|
+
const output = truncate(result.text);
|
|
137
|
+
return {
|
|
138
|
+
type: 'tool',
|
|
139
|
+
toolName: tool.name,
|
|
140
|
+
toolId: tool.id,
|
|
141
|
+
input: tool.input,
|
|
142
|
+
...(output ? { output } : {}),
|
|
143
|
+
isError: result.isError,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=claude-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude-tools.js","sourceRoot":"","sources":["../../../src/adapters/claude-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAgBlE,+EAA+E;AAC/E,MAAM,UAAU,GAAG,IAAI,CAAC;AAExB,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IA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1C,CAAC;IACD,6EAA6E;IAC7E,8EAA8E;IAC9E,iFAAiF;IACjF,IAAI,IAAI,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;QAC9B,MAAM,KAAK,GAAG,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC3C,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC;IAChD,CAAC;IACD,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACrC,OAAO;QACL,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI,CAAC,IAAI;QACnB,MAAM,EAAE,IAAI,CAAC,EAAE;QACf,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7B,OAAO,EAAE,MAAM,CAAC,OAAO;KACxB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { Readable, Writable } from 'node:stream';
|
|
2
|
+
import type { AgentCapabilities, AgentConfig, AgentId, AgentModel, AgentModelOption, ApprovalDecision, SendTurnOptions } from '@uxnan/shared';
|
|
3
|
+
import { BaseAgentAdapter } from './base-adapter.js';
|
|
4
|
+
import { type CodexFileChange } from './codex-tools.js';
|
|
5
|
+
/**
|
|
6
|
+
* Headless sandbox + approval posture for the Codex app-server (v2 protocol).
|
|
7
|
+
* Mirrors the bridge's other agent adapters:
|
|
8
|
+
* - `default` → reads only; commands/writes denied by the sandbox.
|
|
9
|
+
* - `acceptEdits` → workspace writes allowed; no prompts.
|
|
10
|
+
* - `bypassPermissions` → danger full access; no prompts.
|
|
11
|
+
* - `interactive` → workspace writes allowed; the user is asked (this
|
|
12
|
+
* is the recommended default for production use).
|
|
13
|
+
*/
|
|
14
|
+
export type CodexPermissionMode = 'default' | 'acceptEdits' | 'bypassPermissions' | 'interactive';
|
|
15
|
+
export interface CodexAdapterOptions {
|
|
16
|
+
/** Resolved binary entry (see resolve-codex.ts). */
|
|
17
|
+
binaryPath?: string;
|
|
18
|
+
/** Args prepended before the adapter args (e.g. `[codex.js]` when running via node). */
|
|
19
|
+
prependArgs?: string[];
|
|
20
|
+
/** Default model when the thread/turn doesn't pick one. */
|
|
21
|
+
defaultModel?: string;
|
|
22
|
+
/** Sandbox + approval posture (default `interactive`; see {@link CodexPermissionMode}). */
|
|
23
|
+
permissionMode?: CodexPermissionMode;
|
|
24
|
+
/**
|
|
25
|
+
* Callback that surfaces a Codex app-server approval to the bridge so the
|
|
26
|
+
* phone can decide. Returns the user's `ApprovalDecision` (or
|
|
27
|
+
* `'reject'` after the 5-min timeout). Wired by the bridge during adapter
|
|
28
|
+
* registration. Optional in tests.
|
|
29
|
+
*/
|
|
30
|
+
onApprovalRequest?: (threadId: string, info: {
|
|
31
|
+
toolName: string;
|
|
32
|
+
input: Record<string, unknown>;
|
|
33
|
+
}) => Promise<ApprovalDecision>;
|
|
34
|
+
/**
|
|
35
|
+
* Injected `app-server` spawner (tests). Should return the child's stdin
|
|
36
|
+
* (writable), stdout (readable) and an `onClose` callback the adapter
|
|
37
|
+
* registers with. The default spawns the configured `binaryPath` with
|
|
38
|
+
* `app-server` appended, with stdin/stdout piped.
|
|
39
|
+
*/
|
|
40
|
+
spawnAppServer?: () => SpawnedAppServer;
|
|
41
|
+
}
|
|
42
|
+
/** Streams + lifecycle surface a `spawnAppServer` implementation returns. */
|
|
43
|
+
export interface SpawnedAppServer {
|
|
44
|
+
stdin: Writable;
|
|
45
|
+
stdout: Readable;
|
|
46
|
+
onClose: (cb: (code: number | null) => void) => void;
|
|
47
|
+
kill: () => void;
|
|
48
|
+
}
|
|
49
|
+
/** A normalized Codex event extracted from one app-server notification line. */
|
|
50
|
+
export interface CodexEvent {
|
|
51
|
+
kind: 'thread' | 'message' | 'thinking' | 'block' | 'file_change' | 'completed' | 'error' | 'other';
|
|
52
|
+
threadId?: string;
|
|
53
|
+
text?: string;
|
|
54
|
+
/** Only set for `completed`: context-occupying token count, if reported. */
|
|
55
|
+
tokens?: number;
|
|
56
|
+
/** Only set for `block`: the structured content block(s) for this item. */
|
|
57
|
+
blocks?: Record<string, unknown>[];
|
|
58
|
+
/** Only set for `file_change`: the changed paths the adapter reads to diff. */
|
|
59
|
+
changes?: CodexFileChange[];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Sum the context-occupying tokens from a Codex `turn.completed.usage` object
|
|
63
|
+
* (`{ input_tokens, cached_input_tokens, output_tokens, reasoning_output_tokens }`
|
|
64
|
+
* — `cached_input_tokens` is a subset of `input_tokens`, so it isn't added).
|
|
65
|
+
*/
|
|
66
|
+
export declare function codexUsageTokens(usage: unknown): number | undefined;
|
|
67
|
+
export declare class CodexAdapter extends BaseAgentAdapter {
|
|
68
|
+
#private;
|
|
69
|
+
readonly agentId: AgentId;
|
|
70
|
+
readonly capabilities: AgentCapabilities;
|
|
71
|
+
/** Native Codex thread id for a thread (on-disk history-fallback locator). */
|
|
72
|
+
nativeSessionId(threadId: string): string | undefined;
|
|
73
|
+
constructor(options?: CodexAdapterOptions);
|
|
74
|
+
get defaultModel(): string | undefined;
|
|
75
|
+
start(config: AgentConfig): Promise<void>;
|
|
76
|
+
stop(): Promise<void>;
|
|
77
|
+
sendTurn(options: SendTurnOptions): Promise<void>;
|
|
78
|
+
cancelTurn(_threadId: string, turnId: string): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* List the models the account can use, account-aware (free vs paid changes
|
|
81
|
+
* the set). The app-server has no enumerate command in a turn session, so we
|
|
82
|
+
* drive a short-lived `codex app-server` process just to run the
|
|
83
|
+
* `initialize` → `model/list` JSON-RPC handshake (the desktop app's source).
|
|
84
|
+
* Falls back to `~/.codex/config.toml` (`model` + the
|
|
85
|
+
* `[tui.model_availability_nux]` table) if the app-server is unavailable.
|
|
86
|
+
*
|
|
87
|
+
* The short-lived process is independent of the long-lived one used for
|
|
88
|
+
* turns (so model listing always works even if a turn crashed the main
|
|
89
|
+
* process).
|
|
90
|
+
*/
|
|
91
|
+
listModels(): Promise<AgentModel[]>;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Parse `~/.codex/models_cache.json` into a model-slug → context-window map.
|
|
95
|
+
* The file is `{ models: [{ slug, context_window, … }] }`; entries without a
|
|
96
|
+
* positive `context_window` are skipped.
|
|
97
|
+
*/
|
|
98
|
+
export declare function parseCodexModelWindows(raw: string): Map<string, number>;
|
|
99
|
+
/**
|
|
100
|
+
* Map the app-server `model/list` → `result.data` array into {@link AgentModel}s,
|
|
101
|
+
* skipping models hidden from the default picker.
|
|
102
|
+
*/
|
|
103
|
+
export declare function parseCodexModelList(data: unknown): AgentModel[];
|
|
104
|
+
/**
|
|
105
|
+
* Build the per-model reasoning knob from the app-server's
|
|
106
|
+
* `supportedReasoningEfforts` (`[{ reasoningEffort, description }]`) and
|
|
107
|
+
* `defaultReasoningEffort`. Returns `[]` when the model reports no efforts.
|
|
108
|
+
*/
|
|
109
|
+
export declare function parseCodexReasoning(raw: unknown, defaultEffort: unknown): AgentModelOption[];
|
|
110
|
+
/**
|
|
111
|
+
* Fallback parse of `~/.codex/config.toml`: the top-level `model` plus the keys
|
|
112
|
+
* of the `[tui.model_availability_nux]` table (models the account has seen).
|
|
113
|
+
* The configured `model` is flagged `isDefault`. Minimal hand-rolled scan — no
|
|
114
|
+
* TOML dependency — tolerant of comments and quoting.
|
|
115
|
+
*/
|
|
116
|
+
export declare function parseCodexConfigModels(toml: string): AgentModel[];
|