@scotthuang/agent-knock-knock 0.13.11 → 0.13.12
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/CHANGELOG.md +11 -0
- package/README.md +8 -9
- package/dist/src/codex-app-server-interaction-client.d.ts +72 -0
- package/dist/src/codex-app-server-interaction-client.js +310 -0
- package/dist/src/codex-app-server-interaction-client.js.map +1 -0
- package/dist/src/codex-app-server-questionnaire.d.ts +73 -0
- package/dist/src/codex-app-server-questionnaire.js +366 -0
- package/dist/src/codex-app-server-questionnaire.js.map +1 -0
- package/dist/src/codex-app-server-read-client.d.ts +118 -0
- package/dist/src/codex-app-server-read-client.js +300 -0
- package/dist/src/codex-app-server-read-client.js.map +1 -0
- package/dist/src/codex-app-server-transport.d.ts +11 -0
- package/dist/src/codex-app-server-transport.js +47 -0
- package/dist/src/codex-app-server-transport.js.map +1 -0
- package/dist/src/codex-async-question-adapter.d.ts +5 -0
- package/dist/src/codex-async-question-adapter.js +58 -17
- package/dist/src/codex-async-question-adapter.js.map +1 -1
- package/dist/src/codex-fullscreen-composer-proof.d.ts +23 -0
- package/dist/src/codex-fullscreen-composer-proof.js +124 -0
- package/dist/src/codex-fullscreen-composer-proof.js.map +1 -0
- package/dist/src/codex-lifecycle-compatibility.d.ts +2 -0
- package/dist/src/codex-lifecycle-compatibility.js +8 -1
- package/dist/src/codex-lifecycle-compatibility.js.map +1 -1
- package/dist/src/codex-paginated-answer-proof.d.ts +25 -0
- package/dist/src/codex-paginated-answer-proof.js +189 -0
- package/dist/src/codex-paginated-answer-proof.js.map +1 -0
- package/dist/src/codex-paginated-async-answer.d.ts +36 -0
- package/dist/src/codex-paginated-async-answer.js +321 -0
- package/dist/src/codex-paginated-async-answer.js.map +1 -0
- package/dist/src/codex-paginated-async-response.d.ts +21 -0
- package/dist/src/codex-paginated-async-response.js +116 -0
- package/dist/src/codex-paginated-async-response.js.map +1 -0
- package/dist/src/codex-paginated-observation.d.ts +30 -0
- package/dist/src/codex-paginated-observation.js +139 -0
- package/dist/src/codex-paginated-observation.js.map +1 -0
- package/dist/src/codex-paginated-questionnaire-runtime.d.ts +33 -0
- package/dist/src/codex-paginated-questionnaire-runtime.js +157 -0
- package/dist/src/codex-paginated-questionnaire-runtime.js.map +1 -0
- package/dist/src/codex-paginated-task.d.ts +77 -0
- package/dist/src/codex-paginated-task.js +440 -0
- package/dist/src/codex-paginated-task.js.map +1 -0
- package/dist/src/codex-paginated-thread-binding.d.ts +18 -0
- package/dist/src/codex-paginated-thread-binding.js +55 -0
- package/dist/src/codex-paginated-thread-binding.js.map +1 -0
- package/dist/src/codex-paginated-thread-facts.d.ts +10 -0
- package/dist/src/codex-paginated-thread-facts.js +2 -0
- package/dist/src/codex-paginated-thread-facts.js.map +1 -0
- package/dist/src/codex-paginated-watch.d.ts +29 -0
- package/dist/src/codex-paginated-watch.js +107 -0
- package/dist/src/codex-paginated-watch.js.map +1 -0
- package/dist/src/codex-terminal-agent-adapter.js +7 -6
- package/dist/src/codex-terminal-agent-adapter.js.map +1 -1
- package/dist/src/store.d.ts +1 -1
- package/dist/src/store.js +2 -2
- package/dist/src/store.js.map +1 -1
- package/dist/src/terminal-agent-adapter.d.ts +3 -0
- package/dist/src/terminal-agent-adapter.js.map +1 -1
- package/dist/src/terminal-agent-bridge.d.ts +13 -5
- package/dist/src/terminal-agent-bridge.js +27 -103
- package/dist/src/terminal-agent-bridge.js.map +1 -1
- package/dist/src/terminal-approval-fingerprint.d.ts +7 -0
- package/dist/src/terminal-approval-fingerprint.js +107 -0
- package/dist/src/terminal-approval-fingerprint.js.map +1 -0
- package/dist/src/terminal-command-cli-ports.d.ts +1 -0
- package/dist/src/terminal-composer-classifier.js +38 -1
- package/dist/src/terminal-composer-classifier.js.map +1 -1
- package/dist/src/terminal-control-provider.d.ts +6 -2
- package/dist/src/terminal-control-provider.js +4 -4
- package/dist/src/terminal-control-provider.js.map +1 -1
- package/dist/src/terminal-human-explicit-send-cli-adapter.js +22 -15
- package/dist/src/terminal-human-explicit-send-cli-adapter.js.map +1 -1
- package/dist/src/terminal-interaction-core.js +2 -1
- package/dist/src/terminal-interaction-core.js.map +1 -1
- package/dist/src/terminal-interaction-response-bridge.d.ts +21 -1
- package/dist/src/terminal-interaction-response-bridge.js +147 -3
- package/dist/src/terminal-interaction-response-bridge.js.map +1 -1
- package/dist/src/terminal-list-cli-adapter.js +4 -4
- package/dist/src/terminal-list-cli-adapter.js.map +1 -1
- package/dist/src/terminal-list-facts.d.ts +1 -1
- package/dist/src/terminal-list-facts.js +1 -1
- package/dist/src/terminal-list-facts.js.map +1 -1
- package/dist/src/terminal-managed-send-cli-adapter.d.ts +1 -1
- package/dist/src/terminal-managed-send-cli-adapter.js +27 -0
- package/dist/src/terminal-managed-send-cli-adapter.js.map +1 -1
- package/dist/src/terminal-model-control-bridge.d.ts +1 -1
- package/dist/src/terminal-model-control-bridge.js +1 -1
- package/dist/src/terminal-model-control-bridge.js.map +1 -1
- package/dist/src/terminal-model-control-profile.d.ts +2 -1
- package/dist/src/terminal-model-control-profile.js +24 -1
- package/dist/src/terminal-model-control-profile.js.map +1 -1
- package/dist/src/terminal-model-control.js +61 -21
- package/dist/src/terminal-model-control.js.map +1 -1
- package/dist/src/terminal-native-inspection-bridge.d.ts +6 -1
- package/dist/src/terminal-native-inspection-bridge.js +116 -79
- package/dist/src/terminal-native-inspection-bridge.js.map +1 -1
- package/dist/src/terminal-questionnaire-adapter.js +19 -16
- package/dist/src/terminal-questionnaire-adapter.js.map +1 -1
- package/dist/src/terminal-runtime-cli-adapter.js +16 -0
- package/dist/src/terminal-runtime-cli-adapter.js.map +1 -1
- package/dist/src/terminal-send-watch-policy.d.ts +38 -0
- package/dist/src/terminal-send-watch-policy.js +77 -0
- package/dist/src/terminal-send-watch-policy.js.map +1 -0
- package/dist/src/terminal-submission-facts.d.ts +1 -1
- package/dist/src/terminal-submission-facts.js +11 -9
- package/dist/src/terminal-submission-facts.js.map +1 -1
- package/dist/src/terminal-watch-cli-adapter.d.ts +9 -1
- package/dist/src/terminal-watch-cli-adapter.js +198 -210
- package/dist/src/terminal-watch-cli-adapter.js.map +1 -1
- package/dist/src/terminal-watch-codec.js +23 -1
- package/dist/src/terminal-watch-codec.js.map +1 -1
- package/dist/src/terminal-watch-interaction-runtime.js +27 -6
- package/dist/src/terminal-watch-interaction-runtime.js.map +1 -1
- package/dist/src/terminal-watch-presentation.d.ts +4 -0
- package/dist/src/terminal-watch-presentation.js +153 -0
- package/dist/src/terminal-watch-presentation.js.map +1 -0
- package/dist/src/terminal-watch-record.d.ts +4 -2
- package/dist/src/terminal-watch-record.js +15 -10
- package/dist/src/terminal-watch-record.js.map +1 -1
- package/dist/src/terminal-watch-service.js +13 -1
- package/dist/src/terminal-watch-service.js.map +1 -1
- package/docs/codex-0.158.0-compatibility.md +129 -0
- package/docs/quickstart-herdr.md +3 -3
- package/docs/quickstart-tmux.md +4 -4
- package/package.json +6 -3
- package/templates/openclaw-skills/agent-knock-knock/SKILL.md +14 -12
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { connectCodexUnixWebSocket } from "./codex-app-server-transport.js";
|
|
4
|
+
const MAX_MESSAGE_BYTES = 8 * 1024 * 1024;
|
|
5
|
+
const MAX_PENDING_REQUESTS = 16;
|
|
6
|
+
const DEFAULT_TIMEOUT_MS = 5_000;
|
|
7
|
+
const TURN_STATUSES = new Set(["completed", "interrupted", "failed", "inProgress"]);
|
|
8
|
+
export class CodexAppServerReadError extends Error {
|
|
9
|
+
code;
|
|
10
|
+
rpcCode;
|
|
11
|
+
rpcMessage;
|
|
12
|
+
constructor(code, message, rpcCode, rpcMessage) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.rpcCode = rpcCode;
|
|
16
|
+
this.rpcMessage = rpcMessage;
|
|
17
|
+
this.name = "CodexAppServerReadError";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export class CodexAppServerReadClient {
|
|
21
|
+
transport;
|
|
22
|
+
timeoutMs;
|
|
23
|
+
metadata;
|
|
24
|
+
pending = new Map();
|
|
25
|
+
unsubscribe;
|
|
26
|
+
nextRequestId = 1;
|
|
27
|
+
closed = false;
|
|
28
|
+
constructor(transport, timeoutMs, metadata) {
|
|
29
|
+
this.transport = transport;
|
|
30
|
+
this.timeoutMs = timeoutMs;
|
|
31
|
+
this.metadata = metadata;
|
|
32
|
+
this.unsubscribe = [
|
|
33
|
+
transport.onMessage((message) => this.receive(message)),
|
|
34
|
+
transport.onDisconnect((error) => this.finish(error))
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
static async connect(options) {
|
|
38
|
+
if (!path.isAbsolute(options.codexHome))
|
|
39
|
+
throw new Error("Codex home must be absolute");
|
|
40
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
41
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 30_000) {
|
|
42
|
+
throw new Error("Codex app-server timeout must be between 1 and 30000 milliseconds");
|
|
43
|
+
}
|
|
44
|
+
const socketPath = path.join(options.codexHome, "app-server-control", "app-server-control.sock");
|
|
45
|
+
const transport = await (options.transportFactory ?? connectCodexUnixWebSocket)({ socketPath, timeoutMs });
|
|
46
|
+
const metadata = { socketPath, serverVersion: "", codexHome: "", platformFamily: "", platformOs: "" };
|
|
47
|
+
const client = new CodexAppServerReadClient(transport, timeoutMs, metadata);
|
|
48
|
+
try {
|
|
49
|
+
const result = await client.request("initialize", {
|
|
50
|
+
clientInfo: { name: "agent-knock-knock-read", title: "AKK read-only history", version: "1" },
|
|
51
|
+
capabilities: { experimentalApi: true }
|
|
52
|
+
});
|
|
53
|
+
Object.assign(metadata, parseCodexAppServerMetadata(result, options, socketPath));
|
|
54
|
+
transport.send(JSON.stringify({ method: "initialized" }));
|
|
55
|
+
return client;
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
client.close();
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async readThread(threadId) {
|
|
63
|
+
const result = record(await this.request("thread/read", { threadId: identifier(threadId), includeTurns: false }));
|
|
64
|
+
const thread = record(result.thread);
|
|
65
|
+
if (thread.id !== threadId)
|
|
66
|
+
invalid("Codex app-server returned a different thread");
|
|
67
|
+
identifier(thread.sessionId);
|
|
68
|
+
if (typeof thread.cwd !== "string" || !path.isAbsolute(thread.cwd))
|
|
69
|
+
invalid("Invalid thread cwd");
|
|
70
|
+
if (thread.historyMode !== "legacy" && thread.historyMode !== "paginated")
|
|
71
|
+
invalid("Unknown thread history mode");
|
|
72
|
+
if (typeof thread.cliVersion !== "string")
|
|
73
|
+
invalid("Invalid thread CLI version");
|
|
74
|
+
validateThreadStatus(thread.status);
|
|
75
|
+
if (!Array.isArray(thread.turns))
|
|
76
|
+
invalid("Invalid thread turns");
|
|
77
|
+
thread.turns.forEach(validateTurn);
|
|
78
|
+
return thread;
|
|
79
|
+
}
|
|
80
|
+
async listTurns(options) {
|
|
81
|
+
if (options.itemsView && !["notLoaded", "summary", "full"].includes(options.itemsView)) {
|
|
82
|
+
throw new Error("Invalid Codex turn items view");
|
|
83
|
+
}
|
|
84
|
+
const result = await this.request("thread/turns/list", {
|
|
85
|
+
...listParams(options), itemsView: options.itemsView ?? "notLoaded"
|
|
86
|
+
});
|
|
87
|
+
return parsePage(result, validateTurn);
|
|
88
|
+
}
|
|
89
|
+
async listItems(options) {
|
|
90
|
+
const params = listParams(options);
|
|
91
|
+
if (options.turnId !== undefined)
|
|
92
|
+
params.turnId = identifier(options.turnId);
|
|
93
|
+
const page = parsePage(await this.request("thread/items/list", params), validateItemEntry);
|
|
94
|
+
if (options.turnId && page.data.some((entry) => entry.turnId !== options.turnId)) {
|
|
95
|
+
invalid("Codex app-server returned items from a different turn");
|
|
96
|
+
}
|
|
97
|
+
return page;
|
|
98
|
+
}
|
|
99
|
+
close() {
|
|
100
|
+
if (!this.closed) {
|
|
101
|
+
this.finish(new CodexAppServerReadError("closed", "Codex app-server read connection closed"));
|
|
102
|
+
}
|
|
103
|
+
this.transport.close();
|
|
104
|
+
}
|
|
105
|
+
request(method, params) {
|
|
106
|
+
if (this.closed)
|
|
107
|
+
return Promise.reject(new CodexAppServerReadError("closed", "Codex app-server read connection closed"));
|
|
108
|
+
if (this.pending.size >= MAX_PENDING_REQUESTS)
|
|
109
|
+
return Promise.reject(new Error("Too many Codex app-server reads"));
|
|
110
|
+
const id = `akk-read-${this.nextRequestId++}`;
|
|
111
|
+
return new Promise((resolve, reject) => {
|
|
112
|
+
const timer = setTimeout(() => {
|
|
113
|
+
this.pending.delete(id);
|
|
114
|
+
reject(new CodexAppServerReadError("timeout", `Codex app-server ${method} timed out`));
|
|
115
|
+
}, this.timeoutMs);
|
|
116
|
+
this.pending.set(id, { resolve, reject, timer });
|
|
117
|
+
try {
|
|
118
|
+
this.transport.send(JSON.stringify({ id, method, params }));
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
clearTimeout(timer);
|
|
122
|
+
this.pending.delete(id);
|
|
123
|
+
reject(error);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
receive(message) {
|
|
128
|
+
try {
|
|
129
|
+
if (Buffer.byteLength(message) > MAX_MESSAGE_BYTES)
|
|
130
|
+
invalid("Codex app-server message exceeded its bound");
|
|
131
|
+
const response = record(JSON.parse(message));
|
|
132
|
+
// Never respond to server requests: doing so could answer another client's question.
|
|
133
|
+
if (response.method !== undefined || typeof response.id !== "string")
|
|
134
|
+
return;
|
|
135
|
+
const pending = this.pending.get(response.id);
|
|
136
|
+
if (!pending)
|
|
137
|
+
return;
|
|
138
|
+
clearTimeout(pending.timer);
|
|
139
|
+
this.pending.delete(response.id);
|
|
140
|
+
if (response.error !== undefined) {
|
|
141
|
+
const error = record(response.error);
|
|
142
|
+
pending.reject(new CodexAppServerReadError("rpc_error", "Codex app-server read was rejected", Number.isInteger(error.code) ? error.code : undefined, typeof error.message === "string" ? error.message.slice(0, 1024) : undefined));
|
|
143
|
+
}
|
|
144
|
+
else if (Object.hasOwn(response, "result")) {
|
|
145
|
+
pending.resolve(response.result);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
pending.reject(new CodexAppServerReadError("invalid_response", "Codex app-server response omitted result"));
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
this.finish(error instanceof Error ? error : new Error("Invalid Codex app-server response"));
|
|
153
|
+
this.transport.close();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
finish(error) {
|
|
157
|
+
this.closed = true;
|
|
158
|
+
for (const pending of this.pending.values()) {
|
|
159
|
+
clearTimeout(pending.timer);
|
|
160
|
+
pending.reject(error);
|
|
161
|
+
}
|
|
162
|
+
this.pending.clear();
|
|
163
|
+
this.unsubscribe.forEach((unsubscribe) => unsubscribe());
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
export const connectCodexAppServerReadClient = CodexAppServerReadClient.connect;
|
|
167
|
+
// Official app-server emits this only for an existing, loaded thread before its first input.
|
|
168
|
+
// Callers must separately verify the selected thread's paginated/idle metadata before
|
|
169
|
+
// interpreting this as an empty submission baseline.
|
|
170
|
+
export function isCodexUnmaterializedThreadError(error, threadId) {
|
|
171
|
+
return error instanceof CodexAppServerReadError
|
|
172
|
+
&& error.code === "rpc_error"
|
|
173
|
+
&& error.rpcCode === -32600
|
|
174
|
+
&& error.rpcMessage === `thread ${threadId} is not materialized yet; thread/turns/list is unavailable before first user message`;
|
|
175
|
+
}
|
|
176
|
+
export function parseCodexAppServerMetadata(value, options, socketPath) {
|
|
177
|
+
const result = record(value);
|
|
178
|
+
const version = typeof result.userAgent === "string" ? /^[^/]+\/([^\s]+)(?:\s|$)/u.exec(result.userAgent)?.[1] : undefined;
|
|
179
|
+
if (version !== options.expectedServerVersion) {
|
|
180
|
+
throw new CodexAppServerReadError("incompatible_server", "Codex app-server backend version does not match the required version");
|
|
181
|
+
}
|
|
182
|
+
if (typeof result.codexHome !== "string" || !path.isAbsolute(result.codexHome) || !sameHome(result.codexHome, options.codexHome)) {
|
|
183
|
+
throw new CodexAppServerReadError("incompatible_server", "Codex app-server backend home does not match the selected home");
|
|
184
|
+
}
|
|
185
|
+
if (typeof result.platformFamily !== "string" || typeof result.platformOs !== "string")
|
|
186
|
+
invalid("Missing Codex app-server platform metadata");
|
|
187
|
+
return { serverVersion: version, codexHome: result.codexHome, socketPath, platformFamily: result.platformFamily, platformOs: result.platformOs };
|
|
188
|
+
}
|
|
189
|
+
function sameHome(left, right) {
|
|
190
|
+
if (path.resolve(left) === path.resolve(right))
|
|
191
|
+
return true;
|
|
192
|
+
try {
|
|
193
|
+
return fs.realpathSync(left) === fs.realpathSync(right);
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function listParams(options) {
|
|
200
|
+
const params = { threadId: identifier(options.threadId), limit: options.limit ?? 100 };
|
|
201
|
+
if (!Number.isSafeInteger(params.limit) || params.limit < 1 || params.limit > 100)
|
|
202
|
+
throw new Error("Codex history page limit must be between 1 and 100");
|
|
203
|
+
if (options.cursor !== undefined)
|
|
204
|
+
params.cursor = identifier(options.cursor, 4096);
|
|
205
|
+
if (options.sortDirection !== undefined) {
|
|
206
|
+
if (options.sortDirection !== "asc" && options.sortDirection !== "desc")
|
|
207
|
+
throw new Error("Invalid Codex history sort direction");
|
|
208
|
+
params.sortDirection = options.sortDirection;
|
|
209
|
+
}
|
|
210
|
+
return params;
|
|
211
|
+
}
|
|
212
|
+
function parsePage(value, validate) {
|
|
213
|
+
const page = record(value);
|
|
214
|
+
if (!Array.isArray(page.data) || page.data.length > 100)
|
|
215
|
+
invalid("Invalid bounded Codex history page");
|
|
216
|
+
const cursor = (value) => value == null ? null : identifier(value, 4096);
|
|
217
|
+
return { data: page.data.map(validate), nextCursor: cursor(page.nextCursor), backwardsCursor: cursor(page.backwardsCursor) };
|
|
218
|
+
}
|
|
219
|
+
function validateThreadStatus(value) {
|
|
220
|
+
const status = record(value);
|
|
221
|
+
if (["notLoaded", "idle", "systemError"].includes(status.type))
|
|
222
|
+
return;
|
|
223
|
+
if (status.type !== "active" || !Array.isArray(status.activeFlags) || status.activeFlags.some((flag) => flag !== "waitingOnApproval" && flag !== "waitingOnUserInput"))
|
|
224
|
+
invalid("Unknown Codex thread status");
|
|
225
|
+
}
|
|
226
|
+
function validateTurn(value) {
|
|
227
|
+
const turn = record(value);
|
|
228
|
+
identifier(turn.id);
|
|
229
|
+
if (!TURN_STATUSES.has(turn.status))
|
|
230
|
+
invalid("Unknown Codex turn status");
|
|
231
|
+
if (!Array.isArray(turn.items))
|
|
232
|
+
invalid("Invalid Codex turn items");
|
|
233
|
+
turn.items.forEach(validateItem);
|
|
234
|
+
if (!["notLoaded", "summary", "full"].includes(turn.itemsView))
|
|
235
|
+
invalid("Unknown Codex turn items view");
|
|
236
|
+
for (const field of ["startedAt", "completedAt", "durationMs"])
|
|
237
|
+
nullableNumber(turn[field]);
|
|
238
|
+
if (turn.error !== null && (typeof record(turn.error).message !== "string"))
|
|
239
|
+
invalid("Invalid Codex turn error");
|
|
240
|
+
return turn;
|
|
241
|
+
}
|
|
242
|
+
function validateItemEntry(value) {
|
|
243
|
+
const entry = record(value);
|
|
244
|
+
identifier(entry.turnId);
|
|
245
|
+
validateItem(entry.item);
|
|
246
|
+
nullableNumber(entry.startedAtMs);
|
|
247
|
+
nullableNumber(entry.completedAtMs);
|
|
248
|
+
return entry;
|
|
249
|
+
}
|
|
250
|
+
function validateItem(value) {
|
|
251
|
+
const item = record(value);
|
|
252
|
+
identifier(item.id);
|
|
253
|
+
identifier(item.type);
|
|
254
|
+
if (item.type === "userMessage") {
|
|
255
|
+
if (!Array.isArray(item.content))
|
|
256
|
+
invalid("Invalid Codex user message content");
|
|
257
|
+
for (const input of item.content) {
|
|
258
|
+
const content = record(input);
|
|
259
|
+
identifier(content.type);
|
|
260
|
+
if (content.type === "text" && typeof content.text !== "string")
|
|
261
|
+
invalid("Invalid Codex user message text");
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
if (item.type === "agentMessage") {
|
|
265
|
+
if (typeof item.text !== "string")
|
|
266
|
+
invalid("Invalid Codex agent message text");
|
|
267
|
+
if (item.delivery != null && item.delivery !== "async")
|
|
268
|
+
invalid("Unknown Codex agent message delivery");
|
|
269
|
+
if (item.questions != null) {
|
|
270
|
+
if (!Array.isArray(item.questions))
|
|
271
|
+
invalid("Invalid Codex async questions");
|
|
272
|
+
for (const value of item.questions) {
|
|
273
|
+
const question = record(value);
|
|
274
|
+
if (typeof question.title !== "string" || (question.options !== null && (!Array.isArray(question.options) || question.options.some((option) => typeof option !== "string"))))
|
|
275
|
+
invalid("Invalid Codex async question");
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
if (item.type === "plan" && typeof item.text !== "string")
|
|
280
|
+
invalid("Invalid Codex proposed plan text");
|
|
281
|
+
return item;
|
|
282
|
+
}
|
|
283
|
+
function nullableNumber(value) {
|
|
284
|
+
if (value !== null && (typeof value !== "number" || !Number.isSafeInteger(value)))
|
|
285
|
+
invalid("Invalid Codex history timestamp");
|
|
286
|
+
}
|
|
287
|
+
function record(value) {
|
|
288
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
289
|
+
invalid("Invalid Codex app-server object");
|
|
290
|
+
return value;
|
|
291
|
+
}
|
|
292
|
+
function identifier(value, limit = 512) {
|
|
293
|
+
if (typeof value !== "string" || value.length === 0 || value.length > limit || /[\u0000-\u001f\u007f]/u.test(value))
|
|
294
|
+
invalid("Invalid Codex app-server identifier");
|
|
295
|
+
return value;
|
|
296
|
+
}
|
|
297
|
+
function invalid(message) {
|
|
298
|
+
throw new CodexAppServerReadError("invalid_response", message);
|
|
299
|
+
}
|
|
300
|
+
//# sourceMappingURL=codex-app-server-read-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codex-app-server-read-client.js","sourceRoot":"","sources":["../../src/codex-app-server-read-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EACL,yBAAyB,EAE1B,MAAM,iCAAiC,CAAC;AAGzC,MAAM,iBAAiB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AAC1C,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAChC,MAAM,kBAAkB,GAAG,KAAK,CAAC;AACjC,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,aAAa,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC;AA+EpF,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAE9B,IAAI;IAEJ,OAAO;IACP,UAAU;IAJ5B,YACkB,IAAqF,EACrG,OAAe,EACC,OAAgB,EAChB,UAAmB;QAEnC,KAAK,CAAC,OAAO,CAAC,CAAC;oBALC,IAAI;uBAEJ,OAAO;0BACP,UAAU;QAG1B,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF;AAQD,MAAM,OAAO,wBAAwB;IAQhB,SAAS;IACT,SAAS;IARnB,QAAQ,CAAyB;IACzB,OAAO,GAAG,IAAI,GAAG,EAA0B,CAAC;IAC5C,WAAW,CAAiB;IACrC,aAAa,GAAG,CAAC,CAAC;IAClB,MAAM,GAAG,KAAK,CAAC;IAEvB,YACmB,SAAsC,EACtC,SAAiB,EAClC,QAAgC;yBAFf,SAAS;yBACT,SAAS;QAG1B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,WAAW,GAAG;YACjB,SAAS,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;Y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AAC;AAED,SAAS,cAAc,CAAC,KAAc;IACpC,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAAE,OAAO,CAAC,iCAAiC,CAAC,CAAC;AAChI,CAAC;AAED,SAAS,MAAM,CAAC,KAAc;IAC5B,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,CAAC,iCAAiC,CAAC,CAAC;IAC5G,OAAO,KAAgC,CAAC;AAC1C,CAAC;AAED,SAAS,UAAU,CAAC,KAAc,EAAE,KAAK,GAAG,GAAG;IAC7C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,KAAK,IAAI,wBAAwB,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,CAAC,qCAAqC,CAAC,CAAC;IACpK,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,OAAO,CAAC,OAAe;IAC9B,MAAM,IAAI,uBAAuB,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAAC;AACjE,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Internal transport; public read and interaction clients each restrict its methods. */
|
|
2
|
+
export interface CodexAppServerReadTransport {
|
|
3
|
+
send(message: string): void;
|
|
4
|
+
onMessage(listener: (message: string) => void): () => void;
|
|
5
|
+
onDisconnect(listener: (error: Error) => void): () => void;
|
|
6
|
+
close(): void;
|
|
7
|
+
}
|
|
8
|
+
export declare function connectCodexUnixWebSocket(options: {
|
|
9
|
+
socketPath: string;
|
|
10
|
+
timeoutMs: number;
|
|
11
|
+
}): Promise<CodexAppServerReadTransport>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import net from "node:net";
|
|
3
|
+
const MAX_MESSAGE_BYTES = 8 * 1024 * 1024;
|
|
4
|
+
export async function connectCodexUnixWebSocket(options) {
|
|
5
|
+
const stat = fs.statSync(options.socketPath);
|
|
6
|
+
if (!stat.isSocket() || (stat.mode & 0o077) !== 0 || (process.getuid && stat.uid !== process.getuid())) {
|
|
7
|
+
throw new Error("Codex app-server control socket is not private to the current user");
|
|
8
|
+
}
|
|
9
|
+
const WebSocketClient = (await import("ws")).default;
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
const socket = new WebSocketClient("ws://localhost/", {
|
|
12
|
+
createConnection: () => net.createConnection({ path: options.socketPath }),
|
|
13
|
+
handshakeTimeout: options.timeoutMs,
|
|
14
|
+
maxPayload: MAX_MESSAGE_BYTES,
|
|
15
|
+
perMessageDeflate: false,
|
|
16
|
+
followRedirects: false
|
|
17
|
+
});
|
|
18
|
+
const failed = (error) => { socket.terminate(); reject(error); };
|
|
19
|
+
socket.once("error", failed);
|
|
20
|
+
socket.once("open", () => {
|
|
21
|
+
socket.removeListener("error", failed);
|
|
22
|
+
socket.on("error", () => { });
|
|
23
|
+
resolve({
|
|
24
|
+
send: (message) => socket.send(message),
|
|
25
|
+
close: () => socket.terminate(),
|
|
26
|
+
onMessage: (listener) => {
|
|
27
|
+
const receive = (data, binary) => {
|
|
28
|
+
if (binary) {
|
|
29
|
+
socket.terminate();
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
listener(data.toString());
|
|
33
|
+
};
|
|
34
|
+
socket.on("message", receive);
|
|
35
|
+
return () => socket.removeListener("message", receive);
|
|
36
|
+
},
|
|
37
|
+
onDisconnect: (listener) => {
|
|
38
|
+
const closed = () => listener(new Error("Codex app-server disconnected"));
|
|
39
|
+
socket.on("error", listener);
|
|
40
|
+
socket.on("close", closed);
|
|
41
|
+
return () => { socket.removeListener("error", listener); socket.removeListener("close", closed); };
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=codex-app-server-transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codex-app-server-transport.js","sourceRoot":"","sources":["../../src/codex-app-server-transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,GAAG,MAAM,UAAU,CAAC;AAG3B,MAAM,iBAAiB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AAU1C,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAAC,OAG/C;IACC,MAAM,IAAI,GAAG,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAC7C,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,GAAG,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC;QACvG,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAC;IACxF,CAAC;IACD,MAAM,eAAe,GAAG,CAAC,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;IACrD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,iBAAiB,EAAE;YACpD,gBAAgB,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,gBAAgB,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC;YAC1E,gBAAgB,EAAE,OAAO,CAAC,SAAS;YACnC,UAAU,EAAE,iBAAiB;YAC7B,iBAAiB,EAAE,KAAK;YACxB,eAAe,EAAE,KAAK;SACvB,CAAC,CAAC;QACH,MAAM,MAAM,GAAG,CAAC,KAAY,EAAE,EAAE,GAAG,MAAM,CAAC,SAAS,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MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;gBACrG,CAAC;aACF,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -52,6 +52,8 @@ export interface CodexAsyncQuestionMatch {
|
|
|
52
52
|
readonly source_question_index: number;
|
|
53
53
|
readonly question: CodexAsyncQuestionSemanticQuestion;
|
|
54
54
|
readonly selected_option_id?: string;
|
|
55
|
+
/** Exact 0.158 durable AnsweredQuestion tuple, never a public identifier. */
|
|
56
|
+
readonly native_question_id?: string;
|
|
55
57
|
}
|
|
56
58
|
export interface CodexAsyncQuestionPromptEvidence {
|
|
57
59
|
readonly profile: string;
|
|
@@ -83,6 +85,9 @@ export type CodexAsyncQuestionOwnerPrivateActionPlan = {
|
|
|
83
85
|
readonly max_characters: number;
|
|
84
86
|
};
|
|
85
87
|
readonly delivery: Readonly<Record<CodexAsyncQuestionDeliveryMode, "submit" | "queue">>;
|
|
88
|
+
/** Only a fully visible 0.158 empty editor may authorize this navigation. */
|
|
89
|
+
readonly prompt_stack_back?: "shift_right" | "alt_down";
|
|
90
|
+
readonly prompt_stack_forward?: "shift_left" | "alt_up";
|
|
86
91
|
readonly expected_region_sha256: string;
|
|
87
92
|
};
|
|
88
93
|
export type CodexAsyncQuestionInspection = {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
+
import { captureCodexFullscreenComposerFrame } from "./codex-fullscreen-composer-proof.js";
|
|
2
3
|
/**
|
|
3
4
|
* This adapter is deliberately version-bound. Later Codex releases gained
|
|
4
5
|
* different durable answer identities; callers must not silently reuse this
|
|
@@ -6,7 +7,8 @@ import { createHash } from "node:crypto";
|
|
|
6
7
|
*/
|
|
7
8
|
export const CODEX_ASYNC_QUESTION_PROFILES = Object.freeze({
|
|
8
9
|
"0.154.0": "codex/0.154.0/request-user-input-async-v1",
|
|
9
|
-
"0.155.1": "codex/0.155.1/request-user-input-async-v1"
|
|
10
|
+
"0.155.1": "codex/0.155.1/request-user-input-async-v1",
|
|
11
|
+
"0.158.0": "codex/0.158.0/request-user-input-async-v2"
|
|
10
12
|
});
|
|
11
13
|
export const CODEX_ASYNC_QUESTION_LIMITS = Object.freeze({
|
|
12
14
|
maxRecords: 4_096,
|
|
@@ -19,7 +21,7 @@ export const CODEX_ASYNC_QUESTION_LIMITS = Object.freeze({
|
|
|
19
21
|
maxScreenCharacters: 128 * 1024,
|
|
20
22
|
maxScreenLines: 160
|
|
21
23
|
});
|
|
22
|
-
const ANSI_SEQUENCE_PATTERN = /[\u001B\u009B](?:(?:\[[0-?]*[ -/]*[@-~])|(?:\][^\u0007]*(?:\u0007|\u001B\\))|.)/gu;
|
|
24
|
+
const ANSI_SEQUENCE_PATTERN = /[\u001B\u009B](?:(?:\[[0-?]*[ -/]*[@-~])|(?:\][^\u0007\u001B]*(?:\u0007|\u001B\\))|.)/gu;
|
|
23
25
|
const UNSAFE_CONTROL_PATTERN = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F-\u009F]/u;
|
|
24
26
|
const IDENTIFIER_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:-]*$/u;
|
|
25
27
|
export function codexAsyncQuestionProfile(version) {
|
|
@@ -85,7 +87,7 @@ export function inspectCodexAsyncQuestion(input) {
|
|
|
85
87
|
if (!normalizedEvidence) {
|
|
86
88
|
return { state: "ambiguous", reason: "invalid_durable_evidence", profile };
|
|
87
89
|
}
|
|
88
|
-
const collapsed = parseCollapsed(captured.lines);
|
|
90
|
+
const collapsed = parseCollapsed(captured.lines, profile);
|
|
89
91
|
const expandedMarker = hasExpandedMarker(captured.lines);
|
|
90
92
|
if (collapsed.status === "exact" && !expandedMarker) {
|
|
91
93
|
return inspectCollapsedQuestion(collapsed, normalizedEvidence, profile);
|
|
@@ -157,6 +159,10 @@ export function codexAsyncQuestionMainComposerVisible(input) {
|
|
|
157
159
|
return false;
|
|
158
160
|
}
|
|
159
161
|
const footer = captured.lines.at(-1)?.trim() ?? "";
|
|
162
|
+
if (input.version === "0.158.0") {
|
|
163
|
+
return captureCodexFullscreenComposerFrame(input.screen, input.version)
|
|
164
|
+
?.hasShortcutFooter === true;
|
|
165
|
+
}
|
|
160
166
|
return /^(?:gpt-[\w.-]+(?:\s+\S+)?|[-\w.]+ default)\s+·\s+\S.*$/u
|
|
161
167
|
.test(footer) && captured.lines.slice(0, -1).some((line) => /^[›»](?:\s|$)/u.test(line));
|
|
162
168
|
}
|
|
@@ -241,6 +247,12 @@ function inspectExpandedQuestion(expanded, profile) {
|
|
|
241
247
|
steer_current_turn: "submit",
|
|
242
248
|
queue_next_turn: "queue"
|
|
243
249
|
},
|
|
250
|
+
...(expanded.promptStackBack === undefined
|
|
251
|
+
? {}
|
|
252
|
+
: { prompt_stack_back: expanded.promptStackBack }),
|
|
253
|
+
...(expanded.promptStackForward === undefined
|
|
254
|
+
? {}
|
|
255
|
+
: { prompt_stack_forward: expanded.promptStackForward }),
|
|
244
256
|
expected_region_sha256: exactDigest
|
|
245
257
|
}
|
|
246
258
|
};
|
|
@@ -277,7 +289,12 @@ function normalizeEvidenceEntry(value, profile) {
|
|
|
277
289
|
const normalized = normalizeQuestion(question, sourceId, index);
|
|
278
290
|
if (!normalized)
|
|
279
291
|
return undefined;
|
|
280
|
-
questions.push(
|
|
292
|
+
questions.push({
|
|
293
|
+
...normalized,
|
|
294
|
+
...(isFullscreenProfile(profile)
|
|
295
|
+
? { nativeQuestionId: JSON.stringify(["request_user_input_async", itemId, index]) }
|
|
296
|
+
: {})
|
|
297
|
+
});
|
|
281
298
|
}
|
|
282
299
|
return {
|
|
283
300
|
itemId,
|
|
@@ -372,7 +389,10 @@ function collapsedMatch(evidence, pendingCount, profile) {
|
|
|
372
389
|
return {
|
|
373
390
|
source_id: current.entry.sourceId,
|
|
374
391
|
source_question_index: current.question.sourceIndex,
|
|
375
|
-
question: current.question.semantic
|
|
392
|
+
question: current.question.semantic,
|
|
393
|
+
...(current.question.nativeQuestionId === undefined
|
|
394
|
+
? {}
|
|
395
|
+
: { native_question_id: current.question.nativeQuestionId })
|
|
376
396
|
};
|
|
377
397
|
}
|
|
378
398
|
function captureLines(screen) {
|
|
@@ -392,7 +412,7 @@ function captureLines(screen) {
|
|
|
392
412
|
lines.pop();
|
|
393
413
|
return { status: "ok", lines };
|
|
394
414
|
}
|
|
395
|
-
function parseCollapsed(lines) {
|
|
415
|
+
function parseCollapsed(lines, profile) {
|
|
396
416
|
let header = -1;
|
|
397
417
|
for (let index = lines.length - 1; index >= 0; index -= 1) {
|
|
398
418
|
if (lines[index] === "• Queued follow-up inputs") {
|
|
@@ -427,12 +447,7 @@ function parseCollapsed(lines) {
|
|
|
427
447
|
let hint = summary + 1;
|
|
428
448
|
while (hint < lines.length && lines[hint].trim().length === 0)
|
|
429
449
|
hint += 1;
|
|
430
|
-
const
|
|
431
|
-
const binding = hintLine === " shift + ← to answer"
|
|
432
|
-
? "shift_left"
|
|
433
|
-
: hintLine === " ⌥ + ↑ to answer"
|
|
434
|
-
? "alt_up"
|
|
435
|
-
: undefined;
|
|
450
|
+
const binding = collapsedOpenBinding(lines[hint] ?? "", profile);
|
|
436
451
|
if (!binding)
|
|
437
452
|
return { status: "partial" };
|
|
438
453
|
return {
|
|
@@ -445,6 +460,14 @@ function parseCollapsed(lines) {
|
|
|
445
460
|
exactLines: lines.slice(header, hint + 1)
|
|
446
461
|
};
|
|
447
462
|
}
|
|
463
|
+
function collapsedOpenBinding(line, profile) {
|
|
464
|
+
const compact = isFullscreenProfile(profile);
|
|
465
|
+
if (line === (compact ? " shift+← to answer" : " shift + ← to answer")) {
|
|
466
|
+
return "shift_left";
|
|
467
|
+
}
|
|
468
|
+
return line === (compact ? " ⌥+↑ to answer" : " ⌥ + ↑ to answer")
|
|
469
|
+
? "alt_up" : undefined;
|
|
470
|
+
}
|
|
448
471
|
function hasExpandedMarker(lines) {
|
|
449
472
|
return lines.some((line) => /^ {2}enter submit\b/u.test(line) ||
|
|
450
473
|
/^ {2}\d+ of(?: \d+)?/u.test(line) ||
|
|
@@ -472,8 +495,9 @@ function parseExpanded(lines, evidence, profile) {
|
|
|
472
495
|
lines.slice(Math.max(0, footerStart - 5), footerStart).some((line) => normalizeText(line) === "Expand terminal to read the entire option")) {
|
|
473
496
|
return { status: "ambiguous", reason: "clipped_question" };
|
|
474
497
|
}
|
|
475
|
-
|
|
476
|
-
|
|
498
|
+
const compactFooter = /^enter submit ctrl\+\] skip (shift\+→|⌥\+↓) (main prompt|prev question)(?: (⌥\+↑|shift\+←) (next question|queued messages))?$/u.exec(footer);
|
|
499
|
+
if (isFullscreenProfile(profile) ? !compactFooter :
|
|
500
|
+
!/^enter submit ctrl \+ \] skip ⌥ \+ ↓ (?:main prompt|prev question)(?: (?:⌥ \+ ↑|shift \+ ←) (?:next question|queued messages))?$/u.test(footer)) {
|
|
477
501
|
return { status: "ambiguous", reason: "unsupported_keymap" };
|
|
478
502
|
}
|
|
479
503
|
if (evidence.length === 0) {
|
|
@@ -508,13 +532,24 @@ function parseExpanded(lines, evidence, profile) {
|
|
|
508
532
|
return { status: "ambiguous", reason: "question_match_ambiguous" };
|
|
509
533
|
}
|
|
510
534
|
const exact = unique[0];
|
|
511
|
-
|
|
535
|
+
if (compactFooter &&
|
|
536
|
+
(exact.currentStep === 1) !== (compactFooter[2] === "main prompt")) {
|
|
537
|
+
return { status: "ambiguous", reason: "partial_or_unknown_surface" };
|
|
538
|
+
}
|
|
512
539
|
return {
|
|
513
540
|
status: "exact",
|
|
514
541
|
currentStep: exact.currentStep,
|
|
515
542
|
totalSteps: exact.totalSteps,
|
|
516
543
|
match: exact.match,
|
|
517
|
-
exactLines: lines.slice(exact.start, lines.length)
|
|
544
|
+
exactLines: lines.slice(exact.start, lines.length),
|
|
545
|
+
...(isFullscreenProfile(profile) && compactFooter
|
|
546
|
+
? { promptStackBack: compactFooter[1] === "shift+→"
|
|
547
|
+
? "shift_right" : "alt_down" }
|
|
548
|
+
: {}),
|
|
549
|
+
...(isFullscreenProfile(profile) && compactFooter?.[4] === "next question"
|
|
550
|
+
? { promptStackForward: compactFooter[3] === "shift+←"
|
|
551
|
+
? "shift_left" : "alt_up" }
|
|
552
|
+
: {})
|
|
518
553
|
};
|
|
519
554
|
}
|
|
520
555
|
function parseQuestionBody(lines, bodyStart, question, source, questionStart, footerStart, maximumPending) {
|
|
@@ -537,7 +572,10 @@ function parseAnswerRegion(lines, question, source) {
|
|
|
537
572
|
const match = {
|
|
538
573
|
source_id: source.sourceId,
|
|
539
574
|
source_question_index: question.sourceIndex,
|
|
540
|
-
question: question.semantic
|
|
575
|
+
question: question.semantic,
|
|
576
|
+
...(question.nativeQuestionId === undefined
|
|
577
|
+
? {}
|
|
578
|
+
: { native_question_id: question.nativeQuestionId })
|
|
541
579
|
};
|
|
542
580
|
if (question.modelOptions.length === 0) {
|
|
543
581
|
return normalizeText(lines[0] ?? "") === "Type your answer" &&
|
|
@@ -753,4 +791,7 @@ function stableJson(value) {
|
|
|
753
791
|
function isRecord(value) {
|
|
754
792
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
755
793
|
}
|
|
794
|
+
function isFullscreenProfile(profile) {
|
|
795
|
+
return profile === CODEX_ASYNC_QUESTION_PROFILES["0.158.0"];
|
|
796
|
+
}
|
|
756
797
|
//# sourceMappingURL=codex-async-question-adapter.js.map
|