kodorun-cli 0.1.124 → 0.1.126
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai/acp.d.ts +1 -0
- package/dist/ai/acp.js +62 -11
- package/dist/ai/codex.d.ts +3 -0
- package/dist/ai/codex.js +31 -11
- package/dist/index.js +50 -23
- package/package.json +1 -1
package/dist/ai/acp.d.ts
CHANGED
package/dist/ai/acp.js
CHANGED
|
@@ -118,14 +118,22 @@ export class AcpProvider {
|
|
|
118
118
|
const exitDetail = lastStderr ? `${this.config.displayName} exited (${code}): ${lastStderr.slice(0, 200)}` : `${this.config.displayName} exited (${code})`;
|
|
119
119
|
for (const [key, req] of this.pending) {
|
|
120
120
|
clearTimeout(req.timer);
|
|
121
|
+
if (req.maxTimer)
|
|
122
|
+
clearTimeout(req.maxTimer);
|
|
121
123
|
req.reject(new Error(exitDetail));
|
|
122
124
|
this.pending.delete(key);
|
|
123
125
|
}
|
|
124
126
|
if (!wasShuttingDown) {
|
|
125
127
|
for (const [sid, status] of this.activeStatusBySession) {
|
|
126
128
|
if (status === "running") {
|
|
129
|
+
this.activeTurnBySession.delete(sid);
|
|
127
130
|
this.activeStatusBySession.set(sid, "idle");
|
|
128
|
-
|
|
131
|
+
if (code && code !== 0) {
|
|
132
|
+
this.emitter?.({ type: "session.error", properties: { sessionID: sid, error: exitDetail } });
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
this.emitter?.({ type: "session.idle", properties: { sessionID: sid } });
|
|
136
|
+
}
|
|
129
137
|
}
|
|
130
138
|
}
|
|
131
139
|
}
|
|
@@ -166,27 +174,69 @@ export class AcpProvider {
|
|
|
166
174
|
}
|
|
167
175
|
this.proc.stdin.write(JSON.stringify(payload) + "\n");
|
|
168
176
|
}
|
|
169
|
-
call(method, params, timeoutMs = 180_000) {
|
|
177
|
+
call(method, params, timeoutMs = 180_000, activityOptions) {
|
|
170
178
|
return new Promise((resolve, reject) => {
|
|
171
179
|
const id = this.nextId++;
|
|
172
180
|
const key = String(id);
|
|
173
|
-
const
|
|
174
|
-
if (
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
181
|
+
const cleanupTimers = (entry) => {
|
|
182
|
+
if (!entry)
|
|
183
|
+
return;
|
|
184
|
+
clearTimeout(entry.timer);
|
|
185
|
+
if (entry.maxTimer)
|
|
186
|
+
clearTimeout(entry.maxTimer);
|
|
187
|
+
};
|
|
188
|
+
const onInactivityTimeout = () => {
|
|
189
|
+
const entry = this.pending.get(key);
|
|
190
|
+
if (!entry)
|
|
191
|
+
return;
|
|
192
|
+
cleanupTimers(entry);
|
|
193
|
+
this.pending.delete(key);
|
|
194
|
+
reject(new Error(`${this.config.displayName} RPC timeout: ${method}`));
|
|
195
|
+
};
|
|
196
|
+
const entry = {
|
|
197
|
+
resolve: (value) => {
|
|
198
|
+
cleanupTimers(entry);
|
|
199
|
+
resolve(value);
|
|
200
|
+
},
|
|
201
|
+
reject: (err) => {
|
|
202
|
+
cleanupTimers(entry);
|
|
203
|
+
reject(err);
|
|
204
|
+
},
|
|
205
|
+
timer: setTimeout(onInactivityTimeout, timeoutMs),
|
|
206
|
+
sessionId: activityOptions?.sessionId,
|
|
207
|
+
};
|
|
208
|
+
if (activityOptions?.sessionId) {
|
|
209
|
+
entry.resetInactivity = () => {
|
|
210
|
+
clearTimeout(entry.timer);
|
|
211
|
+
entry.timer = setTimeout(onInactivityTimeout, timeoutMs);
|
|
212
|
+
};
|
|
213
|
+
const maxTimeoutMs = activityOptions.maxTimeoutMs ?? 45 * 60_000;
|
|
214
|
+
entry.maxTimer = setTimeout(() => {
|
|
215
|
+
if (this.pending.has(key)) {
|
|
216
|
+
cleanupTimers(entry);
|
|
217
|
+
this.pending.delete(key);
|
|
218
|
+
reject(new Error(`${this.config.displayName} exceeded max turn duration (${method})`));
|
|
219
|
+
}
|
|
220
|
+
}, maxTimeoutMs);
|
|
221
|
+
}
|
|
222
|
+
this.pending.set(key, entry);
|
|
180
223
|
try {
|
|
181
224
|
this.sendJson({ jsonrpc: "2.0", id, method, params });
|
|
182
225
|
}
|
|
183
226
|
catch (err) {
|
|
184
|
-
|
|
227
|
+
cleanupTimers(entry);
|
|
185
228
|
this.pending.delete(key);
|
|
186
229
|
reject(err);
|
|
187
230
|
}
|
|
188
231
|
});
|
|
189
232
|
}
|
|
233
|
+
touchSessionActivity(sessionId) {
|
|
234
|
+
for (const req of this.pending.values()) {
|
|
235
|
+
if (req.sessionId === sessionId && req.resetInactivity) {
|
|
236
|
+
req.resetInactivity();
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
190
240
|
notify(method, params) {
|
|
191
241
|
this.sendJson({ jsonrpc: "2.0", method, params });
|
|
192
242
|
}
|
|
@@ -291,6 +341,7 @@ export class AcpProvider {
|
|
|
291
341
|
const sessionId = this.resolveLocalSessionId(readString(params.sessionId));
|
|
292
342
|
if (!sessionId)
|
|
293
343
|
return;
|
|
344
|
+
this.touchSessionActivity(sessionId);
|
|
294
345
|
const update = asRecord(params.update);
|
|
295
346
|
const kind = readString(update.sessionUpdate);
|
|
296
347
|
if (!kind)
|
|
@@ -642,7 +693,7 @@ export class AcpProvider {
|
|
|
642
693
|
}
|
|
643
694
|
}
|
|
644
695
|
}
|
|
645
|
-
await this.call("session/prompt", { sessionId: remoteId, prompt: promptBlocks }, 300_000);
|
|
696
|
+
await this.call("session/prompt", { sessionId: remoteId, prompt: promptBlocks }, 300_000, { sessionId, maxTimeoutMs: 45 * 60_000 });
|
|
646
697
|
const finishPart = {
|
|
647
698
|
id: `${assistantMsgId}:finish`,
|
|
648
699
|
sessionID: sessionId,
|
package/dist/ai/codex.d.ts
CHANGED
|
@@ -40,6 +40,9 @@ export declare class CodexProvider implements AIProvider {
|
|
|
40
40
|
getMessages(sessionId: string): Promise<{
|
|
41
41
|
messages: MessageInfo[];
|
|
42
42
|
}>;
|
|
43
|
+
statuses(): Promise<{
|
|
44
|
+
statuses: Record<string, unknown>;
|
|
45
|
+
}>;
|
|
43
46
|
prompt(sessionId: string, text: string, model?: ModelSelector, agent?: string, files?: FileAttachment[], codexOptions?: CodexPromptOptions): Promise<{
|
|
44
47
|
ack: true;
|
|
45
48
|
}>;
|
package/dist/ai/codex.js
CHANGED
|
@@ -7,6 +7,7 @@ import * as os from "os";
|
|
|
7
7
|
import * as path from "path";
|
|
8
8
|
import { spawn } from "child_process";
|
|
9
9
|
import { createInterface } from "readline";
|
|
10
|
+
import { resolveExecutable, spawnCliBinary } from "./session-store.js";
|
|
10
11
|
const THREAD_LIST_SOURCE_KINDS = ["cli", "vscode", "appServer", "exec", "unknown"];
|
|
11
12
|
const CODEX_AGENTS = [
|
|
12
13
|
{
|
|
@@ -70,8 +71,9 @@ export class CodexProvider {
|
|
|
70
71
|
resolveCodexExecutable() {
|
|
71
72
|
const envPath = process.env.CODEX_CLI_PATH?.trim();
|
|
72
73
|
if (envPath && fs.existsSync(envPath)) {
|
|
73
|
-
return
|
|
74
|
+
return envPath;
|
|
74
75
|
}
|
|
76
|
+
const extraPaths = [];
|
|
75
77
|
if (process.platform === "win32") {
|
|
76
78
|
try {
|
|
77
79
|
const configPath = path.join(os.homedir(), ".codex", "config.toml");
|
|
@@ -80,26 +82,32 @@ export class CodexProvider {
|
|
|
80
82
|
const match = raw.match(/CODEX_CLI_PATH\s*=\s*['"]([^'"]+codex\.exe)['"]/i);
|
|
81
83
|
const candidate = match?.[1]?.trim();
|
|
82
84
|
if (candidate && fs.existsSync(candidate)) {
|
|
83
|
-
|
|
85
|
+
extraPaths.push(candidate);
|
|
84
86
|
}
|
|
85
87
|
}
|
|
86
88
|
}
|
|
87
89
|
catch {
|
|
88
90
|
// Fallback to PATH lookup below.
|
|
89
91
|
}
|
|
90
|
-
return { command: "codex", useShell: true };
|
|
91
92
|
}
|
|
92
|
-
return
|
|
93
|
+
return resolveExecutable(["codex"], extraPaths) ?? "codex";
|
|
93
94
|
}
|
|
94
95
|
async init() {
|
|
95
96
|
if (DEBUG_MODE)
|
|
96
97
|
console.log("Starting Codex app-server...");
|
|
97
|
-
const
|
|
98
|
-
this.debugLog("Spawning codex app-server", { command
|
|
99
|
-
this.proc =
|
|
100
|
-
|
|
98
|
+
const command = this.resolveCodexExecutable();
|
|
99
|
+
this.debugLog("Spawning codex app-server", { command });
|
|
100
|
+
this.proc = spawnCliBinary(command, ["app-server"], {
|
|
101
|
+
cwd: process.cwd(),
|
|
101
102
|
env: process.env,
|
|
102
|
-
|
|
103
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
104
|
+
});
|
|
105
|
+
const stderrRl = createInterface({ input: this.proc.stderr });
|
|
106
|
+
stderrRl.on("line", (line) => {
|
|
107
|
+
const trimmed = line.trim();
|
|
108
|
+
if (trimmed) {
|
|
109
|
+
this.debugLog("stderr", { line: trimmed.slice(0, 400) });
|
|
110
|
+
}
|
|
103
111
|
});
|
|
104
112
|
const rl = createInterface({ input: this.proc.stdout });
|
|
105
113
|
rl.on("line", (line) => this.handleLine(line));
|
|
@@ -337,6 +345,15 @@ export class CodexProvider {
|
|
|
337
345
|
}
|
|
338
346
|
return { messages: session.messages };
|
|
339
347
|
}
|
|
348
|
+
async statuses() {
|
|
349
|
+
const out = {};
|
|
350
|
+
for (const session of this.sessions.values()) {
|
|
351
|
+
out[session.id] = session.activeTurnId
|
|
352
|
+
? { type: "running", turnId: session.activeTurnId }
|
|
353
|
+
: { type: "idle" };
|
|
354
|
+
}
|
|
355
|
+
return { statuses: out };
|
|
356
|
+
}
|
|
340
357
|
async prompt(sessionId, text, model, agent, files = [], codexOptions) {
|
|
341
358
|
const session = this.ensureLocalSession(sessionId);
|
|
342
359
|
session.updatedAt = Date.now();
|
|
@@ -522,7 +539,10 @@ export class CodexProvider {
|
|
|
522
539
|
return;
|
|
523
540
|
this.proc.stdin.write(JSON.stringify(req) + "\n");
|
|
524
541
|
}
|
|
525
|
-
call(method, params) {
|
|
542
|
+
call(method, params, timeoutMs = 120_000) {
|
|
543
|
+
if (!this.proc?.stdin?.writable) {
|
|
544
|
+
return Promise.reject(new Error(`Codex app-server is not running (${method})`));
|
|
545
|
+
}
|
|
526
546
|
return new Promise((resolve, reject) => {
|
|
527
547
|
const id = this.nextId++;
|
|
528
548
|
const key = String(id);
|
|
@@ -531,7 +551,7 @@ export class CodexProvider {
|
|
|
531
551
|
this.pending.delete(key);
|
|
532
552
|
reject(new Error(`Codex RPC timeout: ${method} (id=${id})`));
|
|
533
553
|
}
|
|
534
|
-
},
|
|
554
|
+
}, timeoutMs);
|
|
535
555
|
this.pending.set(key, { resolve, reject, timer });
|
|
536
556
|
this.send({ jsonrpc: "2.0", id, method, params });
|
|
537
557
|
});
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { WebSocket } from "ws";
|
|
|
3
3
|
import qrcode from "qrcode-terminal";
|
|
4
4
|
import shell from "shelljs";
|
|
5
5
|
import { createAiManager, ALL_AI_BACKENDS } from "./ai/index.js";
|
|
6
|
+
import { resolveExecutable } from "./ai/session-store.js";
|
|
6
7
|
import { V2SessionTransport } from "./transport/v2.js";
|
|
7
8
|
import Ignore from "ignore";
|
|
8
9
|
const ignore = Ignore.default;
|
|
@@ -137,7 +138,12 @@ Environment:
|
|
|
137
138
|
`);
|
|
138
139
|
}
|
|
139
140
|
const activeTunnels = new Map();
|
|
140
|
-
const PORT_SYNC_INTERVAL_MS =
|
|
141
|
+
const PORT_SYNC_INTERVAL_MS = 5_000;
|
|
142
|
+
const COMMON_DEV_PORTS = [
|
|
143
|
+
3000, 3001, 3002, 3003, 3008, 4000, 4173, 4200, 4321, 4500,
|
|
144
|
+
5000, 5001, 5173, 5174, 5175, 5500, 5555, 8000, 8001, 8080,
|
|
145
|
+
8081, 8088, 8443, 8787, 8888, 9000, 9090,
|
|
146
|
+
];
|
|
141
147
|
const CLI_LOCAL_TCP_CONNECT_TIMEOUT_MS = 2_500;
|
|
142
148
|
const PROXY_WS_CONNECT_TIMEOUT_MS = 12_000;
|
|
143
149
|
const TUNNEL_SETUP_BUDGET_MS = 18_000;
|
|
@@ -234,7 +240,7 @@ function parseExtraPortsFromArgs(args) {
|
|
|
234
240
|
}
|
|
235
241
|
const EXTRA_PORTS = parseExtraPortsFromArgs(CLI_ARGS);
|
|
236
242
|
const FORCE_NEW_CODE = hasAnyFlag(CLI_ARGS, "--new", "-n");
|
|
237
|
-
const trackedProxyPorts = new Set(EXTRA_PORTS);
|
|
243
|
+
const trackedProxyPorts = new Set([...COMMON_DEV_PORTS, ...EXTRA_PORTS]);
|
|
238
244
|
function samePortSet(a, b) {
|
|
239
245
|
if (a.length !== b.length)
|
|
240
246
|
return false;
|
|
@@ -3167,8 +3173,34 @@ function normalizeGatewayUrl(input) {
|
|
|
3167
3173
|
const path = parsed.pathname === "/" ? "" : parsed.pathname.replace(/\/+$/, "");
|
|
3168
3174
|
return `${parsed.protocol}//${parsed.host}${path}`;
|
|
3169
3175
|
}
|
|
3176
|
+
async function fetchManagerWithRetry(url, init = {}, attempts = 3) {
|
|
3177
|
+
let lastErr;
|
|
3178
|
+
for (let i = 0; i < attempts; i++) {
|
|
3179
|
+
try {
|
|
3180
|
+
const response = await fetch(url, {
|
|
3181
|
+
...init,
|
|
3182
|
+
signal: AbortSignal.timeout(15_000),
|
|
3183
|
+
});
|
|
3184
|
+
if (response.status >= 500 && i < attempts - 1) {
|
|
3185
|
+
await new Promise((r) => setTimeout(r, 400 * (i + 1)));
|
|
3186
|
+
continue;
|
|
3187
|
+
}
|
|
3188
|
+
return response;
|
|
3189
|
+
}
|
|
3190
|
+
catch (err) {
|
|
3191
|
+
lastErr = err;
|
|
3192
|
+
if (i < attempts - 1) {
|
|
3193
|
+
await new Promise((r) => setTimeout(r, 400 * (i + 1)));
|
|
3194
|
+
}
|
|
3195
|
+
}
|
|
3196
|
+
}
|
|
3197
|
+
const causeMsg = lastErr?.cause?.message;
|
|
3198
|
+
const baseMsg = lastErr instanceof Error ? lastErr.message : String(lastErr);
|
|
3199
|
+
const detail = causeMsg && !baseMsg.includes(causeMsg) ? `${baseMsg} (${causeMsg})` : baseMsg;
|
|
3200
|
+
throw new Error(`Unable to reach KodoRun manager (${MANAGER_URL}): ${detail}`);
|
|
3201
|
+
}
|
|
3170
3202
|
async function createQrCode() {
|
|
3171
|
-
const response = await
|
|
3203
|
+
const response = await fetchManagerWithRetry(`${MANAGER_URL}/v2/qr`);
|
|
3172
3204
|
if (!response.ok) {
|
|
3173
3205
|
throw new Error(`Failed to create QR code from manager: ${response.status}`);
|
|
3174
3206
|
}
|
|
@@ -3221,7 +3253,7 @@ async function assembleWithCode(code) {
|
|
|
3221
3253
|
async function getAssignedProxyUrl(password) {
|
|
3222
3254
|
const url = new URL("/v2/proxy", MANAGER_URL);
|
|
3223
3255
|
url.searchParams.set("password", password);
|
|
3224
|
-
const response = await
|
|
3256
|
+
const response = await fetchManagerWithRetry(url);
|
|
3225
3257
|
if (!response.ok) {
|
|
3226
3258
|
let message = `Failed to get proxy from manager: ${response.status}`;
|
|
3227
3259
|
try {
|
|
@@ -3245,14 +3277,13 @@ async function getAssignedProxyUrl(password) {
|
|
|
3245
3277
|
return normalizeGatewayUrl(payload.proxyUrl);
|
|
3246
3278
|
}
|
|
3247
3279
|
async function claimReattach(password) {
|
|
3248
|
-
const response = await
|
|
3280
|
+
const response = await fetchManagerWithRetry(new URL("/v2/reattach/claim", MANAGER_URL), {
|
|
3249
3281
|
method: "POST",
|
|
3250
3282
|
headers: { "Content-Type": "application/json" },
|
|
3251
3283
|
body: JSON.stringify({
|
|
3252
3284
|
password,
|
|
3253
3285
|
role: "cli",
|
|
3254
3286
|
}),
|
|
3255
|
-
signal: AbortSignal.timeout(15_000),
|
|
3256
3287
|
});
|
|
3257
3288
|
if (!response.ok) {
|
|
3258
3289
|
let message = `Failed to claim reattach from manager: ${response.status}`;
|
|
@@ -3287,11 +3318,10 @@ async function claimReattach(password) {
|
|
|
3287
3318
|
};
|
|
3288
3319
|
}
|
|
3289
3320
|
async function revokePassword(password, reason = "revoked by cli --new") {
|
|
3290
|
-
const response = await
|
|
3321
|
+
const response = await fetchManagerWithRetry(new URL("/v2/revoke", MANAGER_URL), {
|
|
3291
3322
|
method: "POST",
|
|
3292
3323
|
headers: { "Content-Type": "application/json" },
|
|
3293
3324
|
body: JSON.stringify({ password, reason }),
|
|
3294
|
-
signal: AbortSignal.timeout(15_000),
|
|
3295
3325
|
});
|
|
3296
3326
|
if (response.ok || response.status === 404) {
|
|
3297
3327
|
return;
|
|
@@ -3387,15 +3417,7 @@ function displaySavedSessionNotice() {
|
|
|
3387
3417
|
], "amber");
|
|
3388
3418
|
}
|
|
3389
3419
|
function isCommandAvailable(command) {
|
|
3390
|
-
|
|
3391
|
-
stdio: "ignore",
|
|
3392
|
-
shell: process.platform === "win32",
|
|
3393
|
-
});
|
|
3394
|
-
const err = probe.error;
|
|
3395
|
-
if (err && (err.code === "ENOENT" || err.code === "ENOTDIR")) {
|
|
3396
|
-
return false;
|
|
3397
|
-
}
|
|
3398
|
-
return !err;
|
|
3420
|
+
return resolveExecutable([command]) !== null;
|
|
3399
3421
|
}
|
|
3400
3422
|
function askYesNo(question, defaultValue = false) {
|
|
3401
3423
|
if (!process.stdin.isTTY || !process.stdout.isTTY)
|
|
@@ -3415,12 +3437,17 @@ function askYesNo(question, defaultValue = false) {
|
|
|
3415
3437
|
});
|
|
3416
3438
|
}
|
|
3417
3439
|
function installLatestNpmPackage(pkg) {
|
|
3418
|
-
const
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3440
|
+
const result = process.platform === "win32"
|
|
3441
|
+
? spawnSync(process.env.COMSPEC || "cmd.exe", ["/d", "/s", "/c", "npm", "install", "-g", `${pkg}@latest`], {
|
|
3442
|
+
stdio: "inherit",
|
|
3443
|
+
shell: false,
|
|
3444
|
+
env: process.env,
|
|
3445
|
+
})
|
|
3446
|
+
: spawnSync("npm", ["install", "-g", `${pkg}@latest`], {
|
|
3447
|
+
stdio: "inherit",
|
|
3448
|
+
shell: false,
|
|
3449
|
+
env: process.env,
|
|
3450
|
+
});
|
|
3424
3451
|
return !result.error && result.status === 0;
|
|
3425
3452
|
}
|
|
3426
3453
|
async function ensureAiCliRuntimes() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kodorun-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.126",
|
|
4
4
|
"description": "Encrypted Host CLI bridge for KodoRun — pair your local workstation repository, AI coding agents, Git, and 24fps Rust PTY terminal with your phone.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kodorun",
|