negotium 0.1.47 → 0.1.49
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/agent-helpers.js +4897 -4411
- package/dist/agent-helpers.js.map +30 -27
- package/dist/background-bash.js +12 -15
- package/dist/background-bash.js.map +3 -3
- package/dist/browser-runtime.js +465 -63
- package/dist/browser-runtime.js.map +9 -6
- package/dist/{chunk-x8dze1pj.js → chunk-5rpw9d1f.js} +147 -16
- package/dist/{chunk-x8dze1pj.js.map → chunk-5rpw9d1f.js.map} +3 -3
- package/dist/hosted-agent.js +156 -429
- package/dist/hosted-agent.js.map +8 -10
- package/dist/main.js +6199 -1476
- package/dist/main.js.map +61 -33
- package/dist/mcp-factories.js +4600 -3708
- package/dist/mcp-factories.js.map +39 -35
- package/dist/prompts.js +12 -15
- package/dist/prompts.js.map +3 -3
- package/dist/query-runtime.js +12 -15
- package/dist/query-runtime.js.map +3 -3
- package/dist/registry.js +116 -24
- package/dist/registry.js.map +8 -9
- package/dist/rollout.js +14 -2
- package/dist/rollout.js.map +3 -3
- package/dist/runtime/src/agents/api-topic-agent-switch.ts +3 -2
- package/dist/runtime/src/agents/claude-registry.ts +3 -1
- package/dist/runtime/src/agents/codex-registry.ts +3 -1
- package/dist/runtime/src/agents/compaction-support.ts +75 -0
- package/dist/runtime/src/agents/contracts.ts +4 -0
- package/dist/runtime/src/agents/fork.ts +2 -2
- package/dist/runtime/src/agents/index.ts +13 -10
- package/dist/runtime/src/agents/maestro-registry.ts +108 -36
- package/dist/runtime/src/agents/registry.ts +15 -4
- package/dist/runtime/src/agents/topic-agent-switch.ts +3 -3
- package/dist/runtime/src/agents/topic-cleanup.ts +2 -2
- package/dist/runtime/src/config-public.ts +2 -0
- package/dist/runtime/src/index.ts +11 -1
- package/dist/runtime/src/mcp/agent-health-server.ts +4 -305
- package/dist/runtime/src/mcp/background-bash-server.ts +2 -0
- package/dist/runtime/src/mcp/factories/agent-health.ts +391 -0
- package/dist/runtime/src/mcp/factories/index.ts +4 -0
- package/dist/runtime/src/mcp/runtime-spec.ts +114 -0
- package/dist/runtime/src/mcp/session-comm/default-host.ts +368 -0
- package/dist/runtime/src/mcp-runtime-host.ts +58 -0
- package/dist/runtime/src/node-host.ts +79 -0
- package/dist/runtime/src/platform/config.ts +16 -20
- package/dist/runtime/src/platform/mcp-config.ts +87 -32
- package/dist/runtime/src/platform/playwright/browser-processes.ts +4 -8
- package/dist/runtime/src/platform/playwright/manager.ts +61 -58
- package/dist/runtime/src/platform/playwright/vault-broker.ts +251 -0
- package/dist/runtime/src/prompts/sessions/_shared-tools.md +2 -2
- package/dist/runtime/src/runtime/inbox.ts +4 -4
- package/dist/runtime/src/runtime/turn-runner.ts +2 -2
- package/dist/runtime/src/topics/derive.ts +4 -4
- package/dist/runtime/src/topics/session.ts +11 -9
- package/dist/runtime/src/version.ts +1 -1
- package/dist/runtime-helpers.js +12 -15
- package/dist/runtime-helpers.js.map +3 -3
- package/dist/types/packages/core/src/agents/claude-registry.d.ts +2 -1
- package/dist/types/packages/core/src/agents/codex-registry.d.ts +2 -1
- package/dist/types/packages/core/src/agents/compaction-support.d.ts +4 -0
- package/dist/types/packages/core/src/agents/contracts.d.ts +3 -0
- package/dist/types/packages/core/src/agents/maestro-registry.d.ts +2 -14
- package/dist/types/packages/core/src/agents/registry.d.ts +3 -2
- package/dist/types/packages/core/src/mcp/factories/agent-health.d.ts +5 -0
- package/dist/types/packages/core/src/mcp/factories/index.d.ts +1 -0
- package/dist/types/packages/core/src/mcp/runtime-spec.d.ts +22 -0
- package/dist/types/packages/core/src/platform/config.d.ts +6 -5
- package/dist/types/packages/core/src/platform/playwright/browser-processes.d.ts +1 -1
- package/dist/types/packages/core/src/platform/playwright/manager.d.ts +0 -1
- package/dist/types/packages/core/src/platform/playwright/vault-broker.d.ts +6 -0
- package/dist/types/packages/core/src/version.d.ts +1 -1
- package/dist/vault.js +12 -15
- package/dist/vault.js.map +3 -3
- package/install-browser-rs.mjs +5 -5
- package/package.json +1 -2
- package/dist/runtime/scripts/browser-passkey-policy.mjs +0 -47
- package/dist/runtime/scripts/browser-vault-transform.mjs +0 -173
- package/dist/runtime/scripts/browser-webauthn-policy.mjs +0 -37
- package/dist/runtime/scripts/mcp-patchright-http.mjs +0 -600
package/dist/hosted-agent.js
CHANGED
|
@@ -7,22 +7,10 @@ import {
|
|
|
7
7
|
|
|
8
8
|
// ../../packages/core/src/agents/claude-provider.ts
|
|
9
9
|
import { spawn as spawn2 } from "child_process";
|
|
10
|
-
import { existsSync as
|
|
10
|
+
import { existsSync as existsSync2, readFileSync as readFileSync3 } from "fs";
|
|
11
11
|
import { query } from "@anthropic-ai/claude-agent-sdk";
|
|
12
12
|
|
|
13
|
-
// ../../packages/core/src/agents/claude-registry.ts
|
|
14
|
-
import { existsSync as existsSync3, mkdirSync as mkdirSync4, readdirSync, renameSync as renameSync2, unlinkSync as unlinkSync3 } from "fs";
|
|
15
|
-
import { homedir as homedir3 } from "os";
|
|
16
|
-
import { join as join4 } from "path";
|
|
17
|
-
|
|
18
|
-
// ../../packages/core/src/agents/rollout/claude.ts
|
|
19
|
-
import { randomUUID } from "crypto";
|
|
20
|
-
import { existsSync as existsSync2, readFileSync as readFileSync3, writeFileSync as writeFileSync3 } from "fs";
|
|
21
|
-
import { homedir as homedir2 } from "os";
|
|
22
|
-
import { join as join3 } from "path";
|
|
23
|
-
|
|
24
13
|
// ../../packages/core/src/agents/rollout/shared.ts
|
|
25
|
-
import { mkdirSync as mkdirSync2 } from "fs";
|
|
26
14
|
import { dirname as dirname2, join as join2, resolve as resolve2 } from "path";
|
|
27
15
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
28
16
|
|
|
@@ -38,6 +26,7 @@ import {
|
|
|
38
26
|
readFileSync,
|
|
39
27
|
writeFileSync
|
|
40
28
|
} from "fs";
|
|
29
|
+
import { createRequire } from "module";
|
|
41
30
|
import { homedir } from "os";
|
|
42
31
|
import { dirname, join, resolve } from "path";
|
|
43
32
|
import { fileURLToPath } from "url";
|
|
@@ -132,20 +121,8 @@ var DM_WORKSPACE_DIR = resolve(WORKSPACE_DIR, "dm");
|
|
|
132
121
|
var SESSION_WORKSPACE_DIR = resolve(WORKSPACE_DIR, "sessions");
|
|
133
122
|
var CLAUDE_EXECUTABLE_ENV = envText("NEGOTIUM_CLAUDE_EXECUTABLE");
|
|
134
123
|
var CLAUDE_EXECUTABLE = CLAUDE_EXECUTABLE_ENV ? resolve(CLAUDE_EXECUTABLE_ENV) : undefined;
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if (override) {
|
|
138
|
-
if (!/(^|\/)(mcp-patchright|mcp-patchright-http\.mjs)$/.test(override)) {
|
|
139
|
-
throw new Error("NEGOTIUM_BROWSER_MCP_BIN must point to the authenticated mcp-patchright wrapper.");
|
|
140
|
-
}
|
|
141
|
-
return override;
|
|
142
|
-
}
|
|
143
|
-
return PATCHRIGHT_MCP_BIN;
|
|
144
|
-
}
|
|
145
|
-
var PATCHRIGHT_MCP_BIN = resolve(PROJECT_ROOT, "scripts/mcp-patchright-http.mjs");
|
|
146
|
-
var PLAYWRIGHT_MCP_BIN = resolveBrowserMcpBin(envText("NEGOTIUM_BROWSER_MCP_BIN"));
|
|
147
|
-
var BROWSER_RS_VERSION = "v0.1.13";
|
|
148
|
-
var BROWSER_RS_MIN_SECURE_VERSION = "0.1.13";
|
|
124
|
+
var BROWSER_RS_VERSION = "v0.1.16";
|
|
125
|
+
var BROWSER_RS_MIN_SECURE_VERSION = "0.1.15";
|
|
149
126
|
function versionAtLeast(actualVersion, minimumVersion) {
|
|
150
127
|
const actual = actualVersion.split(".").map(Number);
|
|
151
128
|
const minimum = minimumVersion.split(".").map(Number);
|
|
@@ -188,7 +165,15 @@ function resolveBrowserRsBin(envValue) {
|
|
|
188
165
|
}
|
|
189
166
|
}
|
|
190
167
|
var BROWSER_RS_BIN = resolveBrowserRsBin(envText("NEGOTIUM_BROWSER_RS_BIN"));
|
|
168
|
+
function resolveBrowserMcpBin(envValue) {
|
|
169
|
+
const override = envValue?.trim();
|
|
170
|
+
if (override)
|
|
171
|
+
return resolve(override);
|
|
172
|
+
return BROWSER_RS_BIN ?? resolve(STATE_DIR, "bin", "browser-rs", BROWSER_RS_VERSION, "browser-rs");
|
|
173
|
+
}
|
|
174
|
+
var PLAYWRIGHT_MCP_BIN = resolveBrowserMcpBin(envText("NEGOTIUM_BROWSER_MCP_BIN"));
|
|
191
175
|
var TSX_BIN = resolveDependencyBin("tsx");
|
|
176
|
+
var TSX_LOADER = createRequire(import.meta.url).resolve("tsx");
|
|
192
177
|
var TSCONFIG_PATH = resolve(PROJECT_ROOT, "tsconfig.json");
|
|
193
178
|
var SESSION_COMM_SERVER = resolve(PROJECT_ROOT, "src/mcp/session-comm/server.ts");
|
|
194
179
|
var TASK_SERVER = resolve(PROJECT_ROOT, "src/mcp/task-server.ts");
|
|
@@ -308,160 +293,17 @@ function codexAuthFilePath() {
|
|
|
308
293
|
return process.env.NEGOTIUM_CODEX_AUTH_FILE || join(homedir(), ".codex", "auth.json");
|
|
309
294
|
}
|
|
310
295
|
|
|
311
|
-
// ../../packages/core/src/runtime/user-turn-envelope.ts
|
|
312
|
-
function renderUserPromptBatch(prompts) {
|
|
313
|
-
if (prompts.length <= 1)
|
|
314
|
-
return prompts[0] ?? "";
|
|
315
|
-
return [
|
|
316
|
-
"[Consecutive user messages received before an assistant response]",
|
|
317
|
-
"",
|
|
318
|
-
...prompts.map((prompt, index) => `${index + 1}. ${prompt}`)
|
|
319
|
-
].join(`
|
|
320
|
-
`);
|
|
321
|
-
}
|
|
322
|
-
|
|
323
296
|
// ../../packages/core/src/agents/rollout/shared.ts
|
|
324
297
|
var __dirname2 = dirname2(fileURLToPath2(import.meta.url));
|
|
325
298
|
var trustedWorkspaceRoots = [WORKSPACE_DIR, DM_WORKSPACE_DIR, TOPIC_WORKSPACE_DIR].map((root) => resolve2(root));
|
|
326
299
|
var FIXTURES_DIR = join2(__dirname2, "..", "fixtures");
|
|
327
|
-
function clone(obj) {
|
|
328
|
-
return structuredClone(obj);
|
|
329
|
-
}
|
|
330
|
-
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
331
|
-
function assertUuidLike(label, value) {
|
|
332
|
-
if (!UUID_RE.test(value)) {
|
|
333
|
-
throw new Error(`rollout: ${label} is not a UUID-shaped string: ${value}`);
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
function assertCwdInWorkspace(cwd) {
|
|
337
|
-
const abs = resolve2(cwd);
|
|
338
|
-
const ok = trustedWorkspaceRoots.some((root) => abs === root || abs.startsWith(`${root}/`));
|
|
339
|
-
if (!ok) {
|
|
340
|
-
throw new Error(`rollout: cwd outside trusted workspace roots: ${cwd} (resolved=${abs})`);
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
function ensureCwdExists(cwd) {
|
|
344
|
-
assertCwdInWorkspace(cwd);
|
|
345
|
-
try {
|
|
346
|
-
mkdirSync2(cwd, { recursive: true });
|
|
347
|
-
} catch (err) {
|
|
348
|
-
logger.warn({ err, cwd }, "rollout: ensureCwdExists failed \u2014 caller should pre-create cwd");
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
function truncate(text, n) {
|
|
352
|
-
const cps = Array.from(text);
|
|
353
|
-
return cps.length > n ? `${cps.slice(0, n).join("")}\u2026` : text;
|
|
354
|
-
}
|
|
355
|
-
function extractChatPairs(entries, opts = { includeToolAnnotations: true }) {
|
|
356
|
-
const pairs = [];
|
|
357
|
-
let pendingUsers = [];
|
|
358
|
-
let pendingBatchSize = null;
|
|
359
|
-
let pendingBatchNextIndex = 0;
|
|
360
|
-
let pendingAssistantParts = [];
|
|
361
|
-
let toolBuffer = [];
|
|
362
|
-
const flushAssistant = () => {
|
|
363
|
-
if (pendingUsers.length === 0)
|
|
364
|
-
return;
|
|
365
|
-
const tools = opts.includeToolAnnotations && toolBuffer.length > 0 ? `
|
|
366
|
-
|
|
367
|
-
${toolBuffer.join(`
|
|
368
|
-
`)}` : "";
|
|
369
|
-
const assistantText = pendingAssistantParts.join("").trim() + tools;
|
|
370
|
-
if (assistantText.trim()) {
|
|
371
|
-
pairs.push({ userText: renderUserPromptBatch(pendingUsers), assistantText });
|
|
372
|
-
}
|
|
373
|
-
pendingUsers = [];
|
|
374
|
-
pendingBatchSize = null;
|
|
375
|
-
pendingBatchNextIndex = 0;
|
|
376
|
-
pendingAssistantParts = [];
|
|
377
|
-
toolBuffer = [];
|
|
378
|
-
};
|
|
379
|
-
for (const entry of entries) {
|
|
380
|
-
const ev = entry.event;
|
|
381
|
-
switch (ev.type) {
|
|
382
|
-
case "user_message": {
|
|
383
|
-
const userEvent = ev;
|
|
384
|
-
if (pendingAssistantParts.length > 0 || toolBuffer.length > 0) {
|
|
385
|
-
flushAssistant();
|
|
386
|
-
}
|
|
387
|
-
const batchSize = userEvent.consecutiveBatchSize;
|
|
388
|
-
const batchIndex = userEvent.consecutiveBatchIndex;
|
|
389
|
-
const marked = Number.isInteger(batchSize) && Number.isInteger(batchIndex) && (batchSize ?? 0) > 1 && (batchIndex ?? -1) >= 0 && (batchIndex ?? 0) < (batchSize ?? 0);
|
|
390
|
-
if (!marked) {
|
|
391
|
-
if (pendingUsers.length > 0)
|
|
392
|
-
flushAssistant();
|
|
393
|
-
pendingUsers.push(userEvent.content);
|
|
394
|
-
pendingBatchSize = null;
|
|
395
|
-
pendingBatchNextIndex = 0;
|
|
396
|
-
break;
|
|
397
|
-
}
|
|
398
|
-
if (batchIndex === 0) {
|
|
399
|
-
if (pendingUsers.length > 0)
|
|
400
|
-
flushAssistant();
|
|
401
|
-
pendingBatchSize = batchSize ?? null;
|
|
402
|
-
pendingBatchNextIndex = 0;
|
|
403
|
-
} else if (!(pendingBatchSize !== null && (batchSize ?? 0) >= pendingBatchSize && pendingBatchNextIndex === batchIndex || pendingBatchSize === null && pendingUsers.length === batchIndex)) {
|
|
404
|
-
flushAssistant();
|
|
405
|
-
}
|
|
406
|
-
pendingUsers.push(userEvent.content);
|
|
407
|
-
pendingBatchSize = batchSize ?? null;
|
|
408
|
-
pendingBatchNextIndex = (batchIndex ?? 0) + 1;
|
|
409
|
-
break;
|
|
410
|
-
}
|
|
411
|
-
case "session":
|
|
412
|
-
if (pendingAssistantParts.length > 0 || toolBuffer.length > 0) {
|
|
413
|
-
flushAssistant();
|
|
414
|
-
}
|
|
415
|
-
break;
|
|
416
|
-
case "text": {
|
|
417
|
-
if (pendingUsers.length === 0) {
|
|
418
|
-
pendingUsers = ["(continued)"];
|
|
419
|
-
}
|
|
420
|
-
pendingAssistantParts.push(ev.content);
|
|
421
|
-
break;
|
|
422
|
-
}
|
|
423
|
-
case "result": {
|
|
424
|
-
if (pendingUsers.length === 0) {
|
|
425
|
-
pendingUsers = ["(continued)"];
|
|
426
|
-
}
|
|
427
|
-
pendingAssistantParts = [ev.content];
|
|
428
|
-
flushAssistant();
|
|
429
|
-
break;
|
|
430
|
-
}
|
|
431
|
-
case "text_delta":
|
|
432
|
-
break;
|
|
433
|
-
case "tool_use": {
|
|
434
|
-
const u = ev;
|
|
435
|
-
toolBuffer.push(`<!-- Tool: ${u.name} ${truncate(JSON.stringify(u.input), 200)} -->`);
|
|
436
|
-
break;
|
|
437
|
-
}
|
|
438
|
-
case "tool_result": {
|
|
439
|
-
const u = ev;
|
|
440
|
-
toolBuffer.push(`<!-- Tool result: ${truncate(u.content, 200)} -->`);
|
|
441
|
-
break;
|
|
442
|
-
}
|
|
443
|
-
case "error": {
|
|
444
|
-
const u = ev;
|
|
445
|
-
toolBuffer.push(`[Error: ${truncate(u.content, 200)}]`);
|
|
446
|
-
break;
|
|
447
|
-
}
|
|
448
|
-
case "tool_progress":
|
|
449
|
-
case "tool_use_summary":
|
|
450
|
-
case "file":
|
|
451
|
-
case "status":
|
|
452
|
-
break;
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
flushAssistant();
|
|
456
|
-
return pairs;
|
|
457
|
-
}
|
|
458
300
|
|
|
459
301
|
// ../../packages/core/src/platform/jsonl.ts
|
|
460
302
|
import {
|
|
461
303
|
appendFileSync,
|
|
462
304
|
closeSync,
|
|
463
305
|
fsyncSync,
|
|
464
|
-
mkdirSync as
|
|
306
|
+
mkdirSync as mkdirSync2,
|
|
465
307
|
openSync,
|
|
466
308
|
readFileSync as readFileSync2,
|
|
467
309
|
renameSync,
|
|
@@ -498,7 +340,7 @@ function parseJsonlText(raw) {
|
|
|
498
340
|
var LOCK_SLEEP = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));
|
|
499
341
|
function writeJsonlFile(filePath, entries) {
|
|
500
342
|
const dir = dirname3(filePath);
|
|
501
|
-
|
|
343
|
+
mkdirSync2(dir, { recursive: true });
|
|
502
344
|
const tmpPath = `${filePath}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
503
345
|
const payload = `${entries.map((e) => JSON.stringify(e)).join(`
|
|
504
346
|
`)}
|
|
@@ -538,122 +380,6 @@ function fsyncDirectoryBestEffort(dir) {
|
|
|
538
380
|
}
|
|
539
381
|
}
|
|
540
382
|
|
|
541
|
-
// ../../packages/core/src/agents/rollout/claude.ts
|
|
542
|
-
var _attachmentsCache = null;
|
|
543
|
-
function loadClaudeAttachments() {
|
|
544
|
-
if (_attachmentsCache)
|
|
545
|
-
return _attachmentsCache;
|
|
546
|
-
const raw = readFileSync3(join3(FIXTURES_DIR, "claude-attachments.jsonl"), "utf8");
|
|
547
|
-
const lines = parseJsonlText(raw);
|
|
548
|
-
if (lines.length < 2) {
|
|
549
|
-
throw new Error(`loadClaudeAttachments: expected >=2 entries in claude-attachments.jsonl, got ${lines.length}`);
|
|
550
|
-
}
|
|
551
|
-
_attachmentsCache = {
|
|
552
|
-
deferredToolsDelta: lines[0],
|
|
553
|
-
skillListing: lines[1]
|
|
554
|
-
};
|
|
555
|
-
return _attachmentsCache;
|
|
556
|
-
}
|
|
557
|
-
var CLAUDE_SDK_VERSION = "2.1.126";
|
|
558
|
-
var CLAUDE_DEFAULT_MODEL = "claude-sonnet-5";
|
|
559
|
-
var CLAUDE_DEFAULT_GIT_BRANCH = "HEAD";
|
|
560
|
-
function encodeClaudeCwd(cwd) {
|
|
561
|
-
const realCwd = cwd.startsWith("/tmp/") ? cwd.replace(/^\/tmp\//, "/private/tmp/") : cwd;
|
|
562
|
-
return `-${realCwd.replaceAll(/[^a-zA-Z0-9]/g, "-").replace(/^-/, "")}`;
|
|
563
|
-
}
|
|
564
|
-
function writeClaudeRollout(opts) {
|
|
565
|
-
const sessionId = opts.sessionId ?? randomUUID();
|
|
566
|
-
assertUuidLike("sessionId", sessionId);
|
|
567
|
-
ensureCwdExists(opts.cwd);
|
|
568
|
-
const pairs = opts.pairs ?? extractChatPairs(opts.entries ?? []);
|
|
569
|
-
const cwdReal = opts.cwd.startsWith("/tmp/") ? opts.cwd.replace(/^\/tmp\//, "/private/tmp/") : opts.cwd;
|
|
570
|
-
const lines = [];
|
|
571
|
-
const ts = () => new Date().toISOString();
|
|
572
|
-
let lastUuid = null;
|
|
573
|
-
lines.push({ type: "queue-operation", operation: "enqueue", timestamp: ts(), sessionId });
|
|
574
|
-
lines.push({ type: "queue-operation", operation: "dequeue", timestamp: ts(), sessionId });
|
|
575
|
-
const attachments = loadClaudeAttachments();
|
|
576
|
-
for (const pair of pairs) {
|
|
577
|
-
const userUuid = randomUUID();
|
|
578
|
-
lines.push({
|
|
579
|
-
parentUuid: lastUuid,
|
|
580
|
-
isSidechain: false,
|
|
581
|
-
promptId: randomUUID(),
|
|
582
|
-
type: "user",
|
|
583
|
-
message: { role: "user", content: [{ type: "text", text: pair.userText }] },
|
|
584
|
-
uuid: userUuid,
|
|
585
|
-
timestamp: ts(),
|
|
586
|
-
permissionMode: "bypassPermissions",
|
|
587
|
-
userType: "external",
|
|
588
|
-
entrypoint: "sdk-ts",
|
|
589
|
-
cwd: cwdReal,
|
|
590
|
-
sessionId,
|
|
591
|
-
version: CLAUDE_SDK_VERSION,
|
|
592
|
-
gitBranch: CLAUDE_DEFAULT_GIT_BRANCH
|
|
593
|
-
});
|
|
594
|
-
const att1Uuid = randomUUID();
|
|
595
|
-
const att1 = clone(attachments.deferredToolsDelta);
|
|
596
|
-
att1.parentUuid = userUuid;
|
|
597
|
-
att1.uuid = att1Uuid;
|
|
598
|
-
att1.timestamp = ts();
|
|
599
|
-
att1.sessionId = sessionId;
|
|
600
|
-
att1.cwd = cwdReal;
|
|
601
|
-
lines.push(att1);
|
|
602
|
-
const att2Uuid = randomUUID();
|
|
603
|
-
const att2 = clone(attachments.skillListing);
|
|
604
|
-
att2.parentUuid = att1Uuid;
|
|
605
|
-
att2.uuid = att2Uuid;
|
|
606
|
-
att2.timestamp = ts();
|
|
607
|
-
att2.sessionId = sessionId;
|
|
608
|
-
att2.cwd = cwdReal;
|
|
609
|
-
lines.push(att2);
|
|
610
|
-
const assistantUuid = randomUUID();
|
|
611
|
-
lines.push({
|
|
612
|
-
parentUuid: att2Uuid,
|
|
613
|
-
isSidechain: false,
|
|
614
|
-
message: {
|
|
615
|
-
model: opts.model ?? CLAUDE_DEFAULT_MODEL,
|
|
616
|
-
id: `msg_${randomUUID().replace(/-/g, "").slice(0, 24)}`,
|
|
617
|
-
type: "message",
|
|
618
|
-
role: "assistant",
|
|
619
|
-
content: [{ type: "text", text: pair.assistantText }],
|
|
620
|
-
stop_reason: "end_turn",
|
|
621
|
-
stop_sequence: null,
|
|
622
|
-
stop_details: null,
|
|
623
|
-
usage: {
|
|
624
|
-
input_tokens: 0,
|
|
625
|
-
cache_creation_input_tokens: 0,
|
|
626
|
-
cache_read_input_tokens: 0,
|
|
627
|
-
output_tokens: 0,
|
|
628
|
-
server_tool_use: { web_search_requests: 0, web_fetch_requests: 0 },
|
|
629
|
-
service_tier: "standard",
|
|
630
|
-
cache_creation: { ephemeral_1h_input_tokens: 0, ephemeral_5m_input_tokens: 0 },
|
|
631
|
-
inference_geo: "",
|
|
632
|
-
iterations: [],
|
|
633
|
-
speed: "standard"
|
|
634
|
-
},
|
|
635
|
-
diagnostics: null
|
|
636
|
-
},
|
|
637
|
-
requestId: `req_${randomUUID().replace(/-/g, "").slice(0, 22)}`,
|
|
638
|
-
type: "assistant",
|
|
639
|
-
uuid: assistantUuid,
|
|
640
|
-
timestamp: ts(),
|
|
641
|
-
userType: "external",
|
|
642
|
-
entrypoint: "sdk-ts",
|
|
643
|
-
cwd: cwdReal,
|
|
644
|
-
sessionId,
|
|
645
|
-
version: CLAUDE_SDK_VERSION,
|
|
646
|
-
gitBranch: CLAUDE_DEFAULT_GIT_BRANCH
|
|
647
|
-
});
|
|
648
|
-
lastUuid = assistantUuid;
|
|
649
|
-
}
|
|
650
|
-
const projectsDir = join3(homedir2(), ".claude", "projects", encodeClaudeCwd(opts.cwd));
|
|
651
|
-
const path = join3(projectsDir, `${sessionId}.jsonl`);
|
|
652
|
-
writeJsonlFile(path, lines);
|
|
653
|
-
logger.info({ sessionId, path, pairs: pairs.length }, "writeClaudeRollout: synthetic rollout placed");
|
|
654
|
-
return { sessionId, rolloutPath: path };
|
|
655
|
-
}
|
|
656
|
-
|
|
657
383
|
// ../../packages/core/src/agents/claude-registry.ts
|
|
658
384
|
var ALIAS_MAP = {
|
|
659
385
|
sonnet: MODEL_SONNET,
|
|
@@ -678,54 +404,6 @@ var claudeRegistry = {
|
|
|
678
404
|
},
|
|
679
405
|
footerLabel(model, effort) {
|
|
680
406
|
return effort ? `${model} \xB7 ${effort}` : model;
|
|
681
|
-
},
|
|
682
|
-
writeRollout(opts) {
|
|
683
|
-
const { sessionId, rolloutPath } = writeClaudeRollout({
|
|
684
|
-
cwd: opts.cwd,
|
|
685
|
-
entries: opts.entries,
|
|
686
|
-
model: claudeRegistry.expandModelAlias(opts.model ?? claudeRegistry.defaultModel),
|
|
687
|
-
...opts.reuseSessionId ? { sessionId: opts.reuseSessionId } : {}
|
|
688
|
-
});
|
|
689
|
-
return { sessionId, rolloutPath };
|
|
690
|
-
},
|
|
691
|
-
async forkSession({ parentSessionId, cwd, title }) {
|
|
692
|
-
const { forkSession } = await import("@anthropic-ai/claude-agent-sdk");
|
|
693
|
-
const result = await forkSession(parentSessionId, {
|
|
694
|
-
...title ? { title } : {}
|
|
695
|
-
});
|
|
696
|
-
const projectsRoot = join4(homedir3(), ".claude", "projects");
|
|
697
|
-
const destDir = join4(projectsRoot, encodeClaudeCwd(cwd));
|
|
698
|
-
const destPath = join4(destDir, `${result.sessionId}.jsonl`);
|
|
699
|
-
if (!existsSync3(destPath)) {
|
|
700
|
-
const sourcePath = readdirSync(projectsRoot).map((d) => join4(projectsRoot, d, `${result.sessionId}.jsonl`)).find((p) => existsSync3(p));
|
|
701
|
-
if (!sourcePath) {
|
|
702
|
-
throw new Error(`claude forkSession: fork rollout ${result.sessionId}.jsonl not found under ${projectsRoot}`);
|
|
703
|
-
}
|
|
704
|
-
mkdirSync4(destDir, { recursive: true });
|
|
705
|
-
renameSync2(sourcePath, destPath);
|
|
706
|
-
}
|
|
707
|
-
return {
|
|
708
|
-
forkId: result.sessionId,
|
|
709
|
-
rolloutPath: destPath
|
|
710
|
-
};
|
|
711
|
-
},
|
|
712
|
-
async cleanupRollouts({ cwd, sessionIds }) {
|
|
713
|
-
const projectsDir = join4(homedir3(), ".claude", "projects", encodeClaudeCwd(cwd));
|
|
714
|
-
const failures = [];
|
|
715
|
-
for (const sid of sessionIds) {
|
|
716
|
-
const path = join4(projectsDir, `${sid}.jsonl`);
|
|
717
|
-
try {
|
|
718
|
-
unlinkSync3(path);
|
|
719
|
-
} catch (e) {
|
|
720
|
-
if (e?.code !== "ENOENT") {
|
|
721
|
-
logger.warn({ err: e, path }, "claude cleanupRollouts: unlink failed");
|
|
722
|
-
failures.push(e);
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
if (failures.length > 0) {
|
|
727
|
-
throw new AggregateError(failures, "claude cleanupRollouts failed");
|
|
728
|
-
}
|
|
729
407
|
}
|
|
730
408
|
};
|
|
731
409
|
|
|
@@ -846,6 +524,15 @@ function issueRuntimeMcpToken(ctx) {
|
|
|
846
524
|
});
|
|
847
525
|
return `${payloadPart}.${signTokenPayload(payloadPart)}`;
|
|
848
526
|
}
|
|
527
|
+
function issueHostedMcpToken(surface, ctx) {
|
|
528
|
+
const payloadPart = encodeTokenPart({
|
|
529
|
+
v: 2,
|
|
530
|
+
exp: Date.now() + TOKEN_TTL_MS,
|
|
531
|
+
aud: surface,
|
|
532
|
+
ctx
|
|
533
|
+
});
|
|
534
|
+
return `${payloadPart}.${signTokenPayload(payloadPart)}`;
|
|
535
|
+
}
|
|
849
536
|
function buildRuntimeMcpSpec(agent, ctx) {
|
|
850
537
|
const token = issueRuntimeMcpToken(ctx);
|
|
851
538
|
const base = `http://127.0.0.1:${runtimePort}${RUNTIME_MCP_BASE_PATH}`;
|
|
@@ -858,6 +545,18 @@ function buildRuntimeMcpSpec(agent, ctx) {
|
|
|
858
545
|
timeout: CLAUDE_MCP_TOOL_TIMEOUT_MS
|
|
859
546
|
};
|
|
860
547
|
}
|
|
548
|
+
function buildHostedMcpSpec(agent, surface, ctx) {
|
|
549
|
+
const token = issueHostedMcpToken(surface, ctx);
|
|
550
|
+
const base = `http://127.0.0.1:${runtimePort}${RUNTIME_MCP_BASE_PATH}/${surface}`;
|
|
551
|
+
const query = `token=${encodeURIComponent(token)}`;
|
|
552
|
+
if (agent === "codex")
|
|
553
|
+
return { url: `${base}/mcp?${query}` };
|
|
554
|
+
return {
|
|
555
|
+
type: "sse",
|
|
556
|
+
url: `${base}/sse?${query}`,
|
|
557
|
+
timeout: CLAUDE_MCP_TOOL_TIMEOUT_MS
|
|
558
|
+
};
|
|
559
|
+
}
|
|
861
560
|
|
|
862
561
|
// ../../packages/core/src/mcp/session-comm/bridge-ipc-config.ts
|
|
863
562
|
var registrations = [];
|
|
@@ -1100,7 +799,7 @@ function buildStdioMcpServer(agent, serverFile, serverArgs, env) {
|
|
|
1100
799
|
if (agent === "codex") {
|
|
1101
800
|
return {
|
|
1102
801
|
command: "node",
|
|
1103
|
-
args: [
|
|
802
|
+
args: ["--import", TSX_LOADER, serverFile, ...serverArgs],
|
|
1104
803
|
env: { TSX_TSCONFIG_PATH: TSCONFIG_PATH, ...env }
|
|
1105
804
|
};
|
|
1106
805
|
}
|
|
@@ -1110,6 +809,28 @@ function buildStdioMcpServer(agent, serverFile, serverArgs, env) {
|
|
|
1110
809
|
...env ? { env } : {}
|
|
1111
810
|
};
|
|
1112
811
|
}
|
|
812
|
+
function useHostedBuiltinMcp() {
|
|
813
|
+
return envText("NEGOTIUM_BUILTIN_MCP_TRANSPORT") !== "stdio";
|
|
814
|
+
}
|
|
815
|
+
function buildBuiltinMcpServer(surface, ctx, stdio) {
|
|
816
|
+
if (!useHostedBuiltinMcp())
|
|
817
|
+
return stdio();
|
|
818
|
+
const agent = ctx.agent ?? FALLBACK_AGENT;
|
|
819
|
+
return buildHostedMcpSpec(agent, surface, {
|
|
820
|
+
userId: ctx.userId,
|
|
821
|
+
topicTitle: ctx.session,
|
|
822
|
+
...ctx.topicId ? { topicId: ctx.topicId } : {},
|
|
823
|
+
...ctx.queryId ? { queryId: ctx.queryId } : {},
|
|
824
|
+
...ctx.wikiTopicId ? { wikiTopicId: ctx.wikiTopicId } : {},
|
|
825
|
+
...ctx.subagentParentTopicId ? { subagentParentTopicId: ctx.subagentParentTopicId } : {},
|
|
826
|
+
cwd: ctx.cwd ?? (ctx.topicId ? resolveTopicWorkspaceDir(ctx.topicId) : process.cwd()),
|
|
827
|
+
agent,
|
|
828
|
+
...ctx.model ? { model: ctx.model } : {},
|
|
829
|
+
...ctx.depth !== undefined ? { depth: ctx.depth } : {},
|
|
830
|
+
...ctx.silent !== undefined ? { silent: ctx.silent } : {},
|
|
831
|
+
...ctx.peerBridge ? { peerBridge: ctx.peerBridge } : {}
|
|
832
|
+
});
|
|
833
|
+
}
|
|
1113
834
|
var _playwrightUnavailableNotifier;
|
|
1114
835
|
var _playwrightUnavailableLastNotifiedAt = new Map;
|
|
1115
836
|
var _PLAYWRIGHT_UNAVAILABLE_COOLDOWN_MS = 5 * 60000;
|
|
@@ -1235,13 +956,14 @@ var MCP_CATALOG = {
|
|
|
1235
956
|
},
|
|
1236
957
|
"token-stats": {
|
|
1237
958
|
...commonRuntimeMcpPolicy("token-stats"),
|
|
1238
|
-
build(
|
|
1239
|
-
return buildStdioMcpServer(agent, TOKEN_STATS_SERVER, [`--user-id=${userId}`]);
|
|
959
|
+
build(ctx) {
|
|
960
|
+
return buildBuiltinMcpServer("token-stats", ctx, () => buildStdioMcpServer(ctx.agent, TOKEN_STATS_SERVER, [`--user-id=${ctx.userId}`]));
|
|
1240
961
|
}
|
|
1241
962
|
},
|
|
1242
963
|
task: {
|
|
1243
964
|
...commonRuntimeMcpPolicy("task"),
|
|
1244
|
-
build(
|
|
965
|
+
build(ctx) {
|
|
966
|
+
const { userId, session, topicId, queryId, agent, peerBridge } = ctx;
|
|
1245
967
|
if (peerBridge) {
|
|
1246
968
|
if (!topicId || !queryId)
|
|
1247
969
|
return null;
|
|
@@ -1257,21 +979,22 @@ var MCP_CATALOG = {
|
|
|
1257
979
|
const args = [`--user-id=${userId}`, `--topic=${session}`];
|
|
1258
980
|
if (topicId)
|
|
1259
981
|
args.push(`--topic-id=${topicId}`);
|
|
1260
|
-
return buildStdioMcpServer(agent, TASK_SERVER, args);
|
|
982
|
+
return buildBuiltinMcpServer("task", ctx, () => buildStdioMcpServer(agent, TASK_SERVER, args));
|
|
1261
983
|
}
|
|
1262
984
|
},
|
|
1263
985
|
"session-comm": {
|
|
1264
986
|
...commonRuntimeMcpPolicy("session-comm"),
|
|
1265
|
-
build({
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
987
|
+
build(ctx) {
|
|
988
|
+
const {
|
|
989
|
+
userId,
|
|
990
|
+
session,
|
|
991
|
+
topicId,
|
|
992
|
+
subagentParentTopicId,
|
|
993
|
+
agent,
|
|
994
|
+
depth = 0,
|
|
995
|
+
silent,
|
|
996
|
+
peerBridge
|
|
997
|
+
} = ctx;
|
|
1275
998
|
const effectiveAgent = agent ?? FALLBACK_AGENT;
|
|
1276
999
|
const args = [
|
|
1277
1000
|
`--user-id=${userId}`,
|
|
@@ -1283,12 +1006,13 @@ var MCP_CATALOG = {
|
|
|
1283
1006
|
...silent ? ["--reply-only=true"] : [],
|
|
1284
1007
|
...peerBridge ? [`--peer-host-query-id=${peerBridge.hostQueryId}`] : []
|
|
1285
1008
|
];
|
|
1286
|
-
return buildStdioMcpServer(effectiveAgent, SESSION_COMM_SERVER, args, peerBridge ? peerSessionBridgeIpcEnv() : undefined);
|
|
1009
|
+
return buildBuiltinMcpServer("session-comm", ctx, () => buildStdioMcpServer(effectiveAgent, SESSION_COMM_SERVER, args, peerBridge ? peerSessionBridgeIpcEnv() : undefined));
|
|
1287
1010
|
}
|
|
1288
1011
|
},
|
|
1289
1012
|
wiki: {
|
|
1290
1013
|
...commonRuntimeMcpPolicy("wiki"),
|
|
1291
|
-
build(
|
|
1014
|
+
build(ctx) {
|
|
1015
|
+
const { userId, session, topicId, queryId, wikiTopicId, agent, peerBridge } = ctx;
|
|
1292
1016
|
if (peerBridge) {
|
|
1293
1017
|
if (!topicId || !queryId)
|
|
1294
1018
|
return null;
|
|
@@ -1306,22 +1030,23 @@ var MCP_CATALOG = {
|
|
|
1306
1030
|
if (resolvedWikiTopicId)
|
|
1307
1031
|
args.push(`--topic-id=${resolvedWikiTopicId}`);
|
|
1308
1032
|
args.push("--surface=wiki");
|
|
1309
|
-
return buildStdioMcpServer(agent, WIKI_SERVER, args);
|
|
1033
|
+
return buildBuiltinMcpServer("wiki", { ...ctx, wikiTopicId: resolvedWikiTopicId }, () => buildStdioMcpServer(agent, WIKI_SERVER, args));
|
|
1310
1034
|
}
|
|
1311
1035
|
},
|
|
1312
1036
|
skills: {
|
|
1313
1037
|
...commonRuntimeMcpPolicy("skills"),
|
|
1314
|
-
build(
|
|
1038
|
+
build(ctx) {
|
|
1039
|
+
const { userId, topicId, agent } = ctx;
|
|
1315
1040
|
const args = [`--user-id=${userId}`, "--surface=skills"];
|
|
1316
1041
|
if (topicId)
|
|
1317
1042
|
args.push(`--topic-id=${topicId}`);
|
|
1318
|
-
return buildStdioMcpServer(agent, WIKI_SERVER, args);
|
|
1043
|
+
return buildBuiltinMcpServer("skills", ctx, () => buildStdioMcpServer(agent, WIKI_SERVER, args));
|
|
1319
1044
|
}
|
|
1320
1045
|
},
|
|
1321
1046
|
"system-health": {
|
|
1322
1047
|
...commonRuntimeMcpPolicy("system-health"),
|
|
1323
|
-
build(
|
|
1324
|
-
return buildStdioMcpServer(agent, SYSTEM_HEALTH_SERVER, []);
|
|
1048
|
+
build(ctx) {
|
|
1049
|
+
return buildBuiltinMcpServer("system-health", ctx, () => buildStdioMcpServer(ctx.agent, SYSTEM_HEALTH_SERVER, []));
|
|
1325
1050
|
}
|
|
1326
1051
|
},
|
|
1327
1052
|
"background-bash": {
|
|
@@ -1334,18 +1059,20 @@ var MCP_CATALOG = {
|
|
|
1334
1059
|
},
|
|
1335
1060
|
"agent-health": {
|
|
1336
1061
|
...commonRuntimeMcpPolicy("agent-health"),
|
|
1337
|
-
build(
|
|
1062
|
+
build(ctx) {
|
|
1063
|
+
const { userId, agent } = ctx;
|
|
1338
1064
|
const args = [`--user-id=${userId}`];
|
|
1339
|
-
return buildStdioMcpServer(agent, AGENT_HEALTH_SERVER, args);
|
|
1065
|
+
return buildBuiltinMcpServer("agent-health", ctx, () => buildStdioMcpServer(agent, AGENT_HEALTH_SERVER, args));
|
|
1340
1066
|
}
|
|
1341
1067
|
},
|
|
1342
1068
|
vault: {
|
|
1343
1069
|
...commonRuntimeMcpPolicy("vault"),
|
|
1344
|
-
build(
|
|
1070
|
+
build(ctx) {
|
|
1071
|
+
const { userId, agent } = ctx;
|
|
1345
1072
|
const args = [`--user-id=${userId}`];
|
|
1346
1073
|
if (agent !== "codex")
|
|
1347
1074
|
args.push("--list-only=true");
|
|
1348
|
-
return buildStdioMcpServer(agent, VAULT_SERVER, args);
|
|
1075
|
+
return buildBuiltinMcpServer("vault", ctx, () => buildStdioMcpServer(agent, VAULT_SERVER, args));
|
|
1349
1076
|
}
|
|
1350
1077
|
}
|
|
1351
1078
|
};
|
|
@@ -1572,8 +1299,8 @@ function getMcpServersForQuery(opts) {
|
|
|
1572
1299
|
}
|
|
1573
1300
|
|
|
1574
1301
|
// ../../packages/core/src/storage/vault.ts
|
|
1575
|
-
import { chmodSync as chmodSync2, mkdirSync as
|
|
1576
|
-
import { join as
|
|
1302
|
+
import { chmodSync as chmodSync2, mkdirSync as mkdirSync3 } from "fs";
|
|
1303
|
+
import { join as join3 } from "path";
|
|
1577
1304
|
|
|
1578
1305
|
// ../../packages/core/src/storage/sqlite.ts
|
|
1579
1306
|
var isBun = typeof process.versions.bun === "string";
|
|
@@ -1707,8 +1434,8 @@ function initializeVaultDatabase(database) {
|
|
|
1707
1434
|
}
|
|
1708
1435
|
}
|
|
1709
1436
|
function openVaultDatabase(dataDir) {
|
|
1710
|
-
const path =
|
|
1711
|
-
|
|
1437
|
+
const path = join3(dataDir, "vault.db");
|
|
1438
|
+
mkdirSync3(dataDir, { recursive: true });
|
|
1712
1439
|
const database = new Database(path, { create: true });
|
|
1713
1440
|
chmodSync2(path, 384);
|
|
1714
1441
|
initializeVaultDatabase(database);
|
|
@@ -1966,7 +1693,7 @@ function buildClaudePrompt(opts) {
|
|
|
1966
1693
|
source: {
|
|
1967
1694
|
type: "base64",
|
|
1968
1695
|
media_type: attachment.mimeType,
|
|
1969
|
-
data:
|
|
1696
|
+
data: readFileSync3(attachment.path).toString("base64")
|
|
1970
1697
|
}
|
|
1971
1698
|
});
|
|
1972
1699
|
} catch (err) {
|
|
@@ -2095,7 +1822,7 @@ function isAbortError(err) {
|
|
|
2095
1822
|
}
|
|
2096
1823
|
async function* claudeProvider(opts) {
|
|
2097
1824
|
const claudeExecutable = hostedClaudeCodeExecutablePath();
|
|
2098
|
-
if (claudeExecutable && !
|
|
1825
|
+
if (claudeExecutable && !existsSync2(claudeExecutable)) {
|
|
2099
1826
|
yield {
|
|
2100
1827
|
type: "error",
|
|
2101
1828
|
content: `Claude CLI not found at ${claudeExecutable}. Install Claude Code or configure the executable path.`
|
|
@@ -2366,38 +2093,38 @@ async function* claudeProvider(opts) {
|
|
|
2366
2093
|
|
|
2367
2094
|
// ../../packages/core/src/agents/codex-provider.ts
|
|
2368
2095
|
import { execFileSync as execFileSync4 } from "child_process";
|
|
2369
|
-
import { existsSync as
|
|
2370
|
-
import { dirname as dirname6, isAbsolute, join as
|
|
2096
|
+
import { existsSync as existsSync5, readFileSync as readFileSync6, realpathSync as realpathSync3, statSync as statSync3 } from "fs";
|
|
2097
|
+
import { dirname as dirname6, isAbsolute, join as join6, relative, resolve as resolve5 } from "path";
|
|
2371
2098
|
import { Codex } from "@openai/codex-sdk";
|
|
2372
2099
|
|
|
2373
2100
|
// ../../packages/core/src/agents/codex-native-multi-agent.ts
|
|
2374
2101
|
import { spawn as spawn3 } from "child_process";
|
|
2375
|
-
import { randomUUID
|
|
2102
|
+
import { randomUUID } from "crypto";
|
|
2376
2103
|
import {
|
|
2377
2104
|
chmodSync as chmodSync3,
|
|
2378
2105
|
copyFileSync,
|
|
2379
|
-
existsSync as
|
|
2106
|
+
existsSync as existsSync3,
|
|
2380
2107
|
mkdtempSync,
|
|
2381
|
-
readFileSync as
|
|
2382
|
-
renameSync as
|
|
2108
|
+
readFileSync as readFileSync4,
|
|
2109
|
+
renameSync as renameSync2,
|
|
2383
2110
|
rmSync,
|
|
2384
|
-
unlinkSync as
|
|
2385
|
-
writeFileSync as
|
|
2111
|
+
unlinkSync as unlinkSync3,
|
|
2112
|
+
writeFileSync as writeFileSync3
|
|
2386
2113
|
} from "fs";
|
|
2387
|
-
import { createRequire } from "module";
|
|
2114
|
+
import { createRequire as createRequire2 } from "module";
|
|
2388
2115
|
import { tmpdir } from "os";
|
|
2389
|
-
import { dirname as dirname4, join as
|
|
2116
|
+
import { dirname as dirname4, join as join4 } from "path";
|
|
2390
2117
|
|
|
2391
2118
|
// ../../packages/core/src/version.ts
|
|
2392
|
-
var NEGOTIUM_VERSION = "0.1.
|
|
2119
|
+
var NEGOTIUM_VERSION = "0.1.49";
|
|
2393
2120
|
|
|
2394
2121
|
// ../../packages/core/src/agents/codex-native-multi-agent.ts
|
|
2395
|
-
var moduleRequire =
|
|
2122
|
+
var moduleRequire = createRequire2(import.meta.url);
|
|
2396
2123
|
var codexSdkPackagePath = moduleRequire.resolve("@openai/codex-sdk/package.json");
|
|
2397
|
-
var codexSdkRequire =
|
|
2124
|
+
var codexSdkRequire = createRequire2(codexSdkPackagePath);
|
|
2398
2125
|
var bundledCodexPackagePath = codexSdkRequire.resolve("@openai/codex/package.json");
|
|
2399
2126
|
function readPackageVersion(packageJsonPath) {
|
|
2400
|
-
const parsed = JSON.parse(
|
|
2127
|
+
const parsed = JSON.parse(readFileSync4(packageJsonPath, "utf8"));
|
|
2401
2128
|
if (typeof parsed.version !== "string" || !parsed.version.trim()) {
|
|
2402
2129
|
throw new Error(`Codex package has no valid version: ${packageJsonPath}`);
|
|
2403
2130
|
}
|
|
@@ -2408,7 +2135,7 @@ var SAFE_BUNDLED_CODEX_VERSION = BUNDLED_CODEX_VERSION.replace(/[^a-zA-Z0-9._-]/
|
|
|
2408
2135
|
var NEGOTIUM_MODEL_CACHE = `negotium-models-cache-${SAFE_BUNDLED_CODEX_VERSION}.json`;
|
|
2409
2136
|
var NEGOTIUM_MODEL_CATALOG = `negotium-model-catalog-${SAFE_BUNDLED_CODEX_VERSION}.json`;
|
|
2410
2137
|
function codexCliScriptPath() {
|
|
2411
|
-
return
|
|
2138
|
+
return join4(dirname4(bundledCodexPackagePath), "bin", "codex.js");
|
|
2412
2139
|
}
|
|
2413
2140
|
function parseCodexModelCache(contents, sourcePath) {
|
|
2414
2141
|
let parsed;
|
|
@@ -2423,7 +2150,7 @@ function parseCodexModelCache(contents, sourcePath) {
|
|
|
2423
2150
|
return parsed;
|
|
2424
2151
|
}
|
|
2425
2152
|
function readCodexModelCache(cachePath) {
|
|
2426
|
-
const contents =
|
|
2153
|
+
const contents = readFileSync4(cachePath, "utf8");
|
|
2427
2154
|
return { contents, parsed: parseCodexModelCache(contents, cachePath) };
|
|
2428
2155
|
}
|
|
2429
2156
|
function readCompatibleCodexModelCache(cachePath) {
|
|
@@ -2435,21 +2162,21 @@ function readCompatibleCodexModelCache(cachePath) {
|
|
|
2435
2162
|
return cache;
|
|
2436
2163
|
}
|
|
2437
2164
|
function writePrivateFileAtomic(path, contents) {
|
|
2438
|
-
if (
|
|
2165
|
+
if (existsSync3(path) && readFileSync4(path, "utf8") === contents)
|
|
2439
2166
|
return;
|
|
2440
|
-
const tempPath = `${path}.${process.pid}.${
|
|
2167
|
+
const tempPath = `${path}.${process.pid}.${randomUUID()}.tmp`;
|
|
2441
2168
|
try {
|
|
2442
|
-
|
|
2443
|
-
|
|
2169
|
+
writeFileSync3(tempPath, contents, { encoding: "utf8", mode: 384 });
|
|
2170
|
+
renameSync2(tempPath, path);
|
|
2444
2171
|
chmodSync3(path, 384);
|
|
2445
2172
|
} finally {
|
|
2446
2173
|
try {
|
|
2447
|
-
|
|
2174
|
+
unlinkSync3(tempPath);
|
|
2448
2175
|
} catch {}
|
|
2449
2176
|
}
|
|
2450
2177
|
}
|
|
2451
2178
|
function bundledCodexModelCachePath(authFilePath) {
|
|
2452
|
-
return
|
|
2179
|
+
return join4(dirname4(authFilePath), NEGOTIUM_MODEL_CACHE);
|
|
2453
2180
|
}
|
|
2454
2181
|
async function bootstrapCodexModelCache(codexHome, cachePath) {
|
|
2455
2182
|
const child = spawn3(process.execPath, [codexCliScriptPath(), "app-server", "--stdio"], {
|
|
@@ -2472,7 +2199,7 @@ async function bootstrapCodexModelCache(codexHome, cachePath) {
|
|
|
2472
2199
|
} catch {}
|
|
2473
2200
|
if (error)
|
|
2474
2201
|
reject(error);
|
|
2475
|
-
else if (!
|
|
2202
|
+
else if (!existsSync3(cachePath))
|
|
2476
2203
|
reject(new Error("Codex did not create its model cache"));
|
|
2477
2204
|
else
|
|
2478
2205
|
resolve4();
|
|
@@ -2535,15 +2262,15 @@ async function bootstrapCodexModelCache(codexHome, cachePath) {
|
|
|
2535
2262
|
}
|
|
2536
2263
|
async function bootstrapIsolatedCodexModelCache(authFilePath, bootstrap) {
|
|
2537
2264
|
const sourceHome = dirname4(authFilePath);
|
|
2538
|
-
const isolatedHome = mkdtempSync(
|
|
2539
|
-
const isolatedCachePath =
|
|
2265
|
+
const isolatedHome = mkdtempSync(join4(tmpdir(), "negotium-codex-models-"));
|
|
2266
|
+
const isolatedCachePath = join4(isolatedHome, "models_cache.json");
|
|
2540
2267
|
try {
|
|
2541
|
-
const isolatedAuthPath =
|
|
2268
|
+
const isolatedAuthPath = join4(isolatedHome, "auth.json");
|
|
2542
2269
|
copyFileSync(authFilePath, isolatedAuthPath);
|
|
2543
2270
|
chmodSync3(isolatedAuthPath, 384);
|
|
2544
|
-
const sourceConfigPath =
|
|
2545
|
-
if (
|
|
2546
|
-
const isolatedConfigPath =
|
|
2271
|
+
const sourceConfigPath = join4(sourceHome, "config.toml");
|
|
2272
|
+
if (existsSync3(sourceConfigPath)) {
|
|
2273
|
+
const isolatedConfigPath = join4(isolatedHome, "config.toml");
|
|
2547
2274
|
copyFileSync(sourceConfigPath, isolatedConfigPath);
|
|
2548
2275
|
chmodSync3(isolatedConfigPath, 384);
|
|
2549
2276
|
}
|
|
@@ -2557,22 +2284,22 @@ async function ensureCodexModelCache(authFilePath, bootstrap = bootstrapCodexMod
|
|
|
2557
2284
|
const codexHome = dirname4(authFilePath);
|
|
2558
2285
|
const configuredCachePath = process.env.NEGOTIUM_CODEX_MODELS_CACHE_FILE;
|
|
2559
2286
|
if (configuredCachePath) {
|
|
2560
|
-
if (!
|
|
2287
|
+
if (!existsSync3(configuredCachePath)) {
|
|
2561
2288
|
throw new Error(`Configured Codex model cache does not exist: ${configuredCachePath}`);
|
|
2562
2289
|
}
|
|
2563
2290
|
readCompatibleCodexModelCache(configuredCachePath);
|
|
2564
2291
|
return configuredCachePath;
|
|
2565
2292
|
}
|
|
2566
2293
|
const bundledCachePath = bundledCodexModelCachePath(authFilePath);
|
|
2567
|
-
const sharedCachePath =
|
|
2568
|
-
if (
|
|
2294
|
+
const sharedCachePath = join4(codexHome, "models_cache.json");
|
|
2295
|
+
if (existsSync3(sharedCachePath)) {
|
|
2569
2296
|
try {
|
|
2570
2297
|
const shared = readCompatibleCodexModelCache(sharedCachePath);
|
|
2571
2298
|
writePrivateFileAtomic(bundledCachePath, shared.contents);
|
|
2572
2299
|
return bundledCachePath;
|
|
2573
2300
|
} catch {}
|
|
2574
2301
|
}
|
|
2575
|
-
if (
|
|
2302
|
+
if (existsSync3(bundledCachePath)) {
|
|
2576
2303
|
try {
|
|
2577
2304
|
readCompatibleCodexModelCache(bundledCachePath);
|
|
2578
2305
|
return bundledCachePath;
|
|
@@ -2584,7 +2311,7 @@ async function ensureCodexModelCache(authFilePath, bootstrap = bootstrapCodexMod
|
|
|
2584
2311
|
}
|
|
2585
2312
|
function writeCodexCatalogWithNativeMultiAgentDisabled(authFilePath, sourcePath) {
|
|
2586
2313
|
const codexHome = dirname4(authFilePath);
|
|
2587
|
-
const outputPath =
|
|
2314
|
+
const outputPath = join4(codexHome, NEGOTIUM_MODEL_CATALOG);
|
|
2588
2315
|
const parsed = readCodexModelCache(sourcePath).parsed;
|
|
2589
2316
|
const models = parsed.models.map((model, index) => {
|
|
2590
2317
|
if (!model || typeof model !== "object" || Array.isArray(model)) {
|
|
@@ -2818,11 +2545,11 @@ var killCodexTrees = manager.killTrees;
|
|
|
2818
2545
|
var killOwnedCodexTreesForShutdown = manager.killOwnedTreesForShutdown;
|
|
2819
2546
|
|
|
2820
2547
|
// ../../packages/core/src/agents/rollout/codex.ts
|
|
2821
|
-
import { existsSync as
|
|
2822
|
-
import { homedir as
|
|
2823
|
-
import { basename, dirname as dirname5, join as
|
|
2548
|
+
import { existsSync as existsSync4, readFileSync as readFileSync5, realpathSync as realpathSync2, statSync as statSync2, unlinkSync as unlinkSync4 } from "fs";
|
|
2549
|
+
import { homedir as homedir2 } from "os";
|
|
2550
|
+
import { basename, dirname as dirname5, join as join5, resolve as resolve4 } from "path";
|
|
2824
2551
|
function codexSessionsDir() {
|
|
2825
|
-
return
|
|
2552
|
+
return join5(process.env.CODEX_HOME || join5(homedir2(), ".codex"), "sessions");
|
|
2826
2553
|
}
|
|
2827
2554
|
function canonicalFilePath(path) {
|
|
2828
2555
|
const absolute = resolve4(path);
|
|
@@ -2830,7 +2557,7 @@ function canonicalFilePath(path) {
|
|
|
2830
2557
|
return realpathSync2(absolute);
|
|
2831
2558
|
} catch {
|
|
2832
2559
|
try {
|
|
2833
|
-
return
|
|
2560
|
+
return join5(realpathSync2(dirname5(absolute)), basename(absolute));
|
|
2834
2561
|
} catch {
|
|
2835
2562
|
return absolute;
|
|
2836
2563
|
}
|
|
@@ -2940,7 +2667,7 @@ function readCodexPatchCallIds(threadId) {
|
|
|
2940
2667
|
if (!path)
|
|
2941
2668
|
return [];
|
|
2942
2669
|
try {
|
|
2943
|
-
return extractCodexPatchCallIds(
|
|
2670
|
+
return extractCodexPatchCallIds(readFileSync5(path, "utf8"));
|
|
2944
2671
|
} catch (error) {
|
|
2945
2672
|
logger.debug({ error, threadId }, "codex patch ids: rollout read failed");
|
|
2946
2673
|
return [];
|
|
@@ -2951,7 +2678,7 @@ function readLatestCodexPatchPreview(threadId, expectedPaths, consumedCallIds =
|
|
|
2951
2678
|
if (!path)
|
|
2952
2679
|
return;
|
|
2953
2680
|
try {
|
|
2954
|
-
return extractLatestCodexPatchPreview(
|
|
2681
|
+
return extractLatestCodexPatchPreview(readFileSync5(path, "utf8"), expectedPaths, consumedCallIds, expectedCallId);
|
|
2955
2682
|
} catch (error) {
|
|
2956
2683
|
logger.debug({ error, threadId }, "codex patch preview: rollout read failed");
|
|
2957
2684
|
return;
|
|
@@ -2979,7 +2706,7 @@ function readLatestCodexContextUsage(threadId) {
|
|
|
2979
2706
|
if (!path)
|
|
2980
2707
|
return;
|
|
2981
2708
|
try {
|
|
2982
|
-
return extractLatestCodexContextUsage(
|
|
2709
|
+
return extractLatestCodexContextUsage(readFileSync5(path, "utf8"));
|
|
2983
2710
|
} catch (error) {
|
|
2984
2711
|
logger.debug({ error, threadId }, "codex context usage: rollout read failed");
|
|
2985
2712
|
return;
|
|
@@ -2990,7 +2717,7 @@ function migrateCodexRolloutNativeMultiAgentMetadata(threadId) {
|
|
|
2990
2717
|
if (!path)
|
|
2991
2718
|
return false;
|
|
2992
2719
|
try {
|
|
2993
|
-
const entries = parseJsonlText(
|
|
2720
|
+
const entries = parseJsonlText(readFileSync5(path, "utf8"));
|
|
2994
2721
|
let changed = false;
|
|
2995
2722
|
for (const entry of entries) {
|
|
2996
2723
|
if (entry.type !== "session_meta" && entry.type !== "turn_context")
|
|
@@ -3019,19 +2746,19 @@ function latestCodexRolloutPath(threadId) {
|
|
|
3019
2746
|
try {
|
|
3020
2747
|
if (buckets) {
|
|
3021
2748
|
for (const bucket of buckets) {
|
|
3022
|
-
const dir =
|
|
3023
|
-
if (!
|
|
2749
|
+
const dir = join5(sessionsDir, bucket);
|
|
2750
|
+
if (!existsSync4(dir))
|
|
3024
2751
|
continue;
|
|
3025
2752
|
const glob = new Bun.Glob(`rollout-*-${threadId}.jsonl`);
|
|
3026
2753
|
for (const rel of glob.scanSync({ cwd: dir, onlyFiles: true })) {
|
|
3027
|
-
candidates.push(
|
|
2754
|
+
candidates.push(join5(dir, rel));
|
|
3028
2755
|
}
|
|
3029
2756
|
}
|
|
3030
2757
|
}
|
|
3031
2758
|
if (candidates.length === 0) {
|
|
3032
2759
|
const glob = new Bun.Glob(`**/rollout-*-${threadId}.jsonl`);
|
|
3033
2760
|
for (const rel of glob.scanSync({ cwd: sessionsDir, onlyFiles: true })) {
|
|
3034
|
-
candidates.push(
|
|
2761
|
+
candidates.push(join5(sessionsDir, rel));
|
|
3035
2762
|
}
|
|
3036
2763
|
}
|
|
3037
2764
|
return candidates.sort((a, b) => statSync2(b).mtimeMs - statSync2(a).mtimeMs)[0];
|
|
@@ -3169,12 +2896,12 @@ function codexMcpServerName(name) {
|
|
|
3169
2896
|
return CODEX_MCP_SERVER_NAME_OVERRIDES[name] ?? name;
|
|
3170
2897
|
}
|
|
3171
2898
|
function globalCodexMcpServerNames(authFilePath) {
|
|
3172
|
-
const configPath =
|
|
3173
|
-
if (!
|
|
2899
|
+
const configPath = join6(dirname6(authFilePath), "config.toml");
|
|
2900
|
+
if (!existsSync5(configPath))
|
|
3174
2901
|
return [];
|
|
3175
2902
|
try {
|
|
3176
2903
|
const names = new Set;
|
|
3177
|
-
for (const line of
|
|
2904
|
+
for (const line of readFileSync6(configPath, "utf8").split(`
|
|
3178
2905
|
`)) {
|
|
3179
2906
|
const match = line.match(/^\s*\[\s*mcp_servers\.((?:"(?:\\.|[^"])*")|(?:'[^']*')|[^.\]\s]+)(?:[.\]])/);
|
|
3180
2907
|
const raw = match?.[1];
|
|
@@ -3274,13 +3001,13 @@ function canonicalPath(path) {
|
|
|
3274
3001
|
}
|
|
3275
3002
|
}
|
|
3276
3003
|
function textFile(path, maxBytes = CODEX_DIFF_FILE_LIMIT) {
|
|
3277
|
-
if (!
|
|
3004
|
+
if (!existsSync5(path))
|
|
3278
3005
|
return null;
|
|
3279
3006
|
try {
|
|
3280
3007
|
const byteLimit = Math.min(CODEX_DIFF_FILE_LIMIT, Math.max(0, maxBytes));
|
|
3281
3008
|
if (statSync3(path).size > byteLimit)
|
|
3282
3009
|
return;
|
|
3283
|
-
const content =
|
|
3010
|
+
const content = readFileSync6(path);
|
|
3284
3011
|
if (content.byteLength > byteLimit || content.includes(0))
|
|
3285
3012
|
return;
|
|
3286
3013
|
return content.toString("utf8");
|
|
@@ -3487,7 +3214,7 @@ async function* codexProvider(opts) {
|
|
|
3487
3214
|
const filePreviews = new CodexFilePreviewTracker(opts.cwd);
|
|
3488
3215
|
const consumedPatchCallIds = new Set(opts.sessionId ? readCodexPatchCallIds(opts.sessionId) : []);
|
|
3489
3216
|
const codexAuthPath = hostedCodexAuthFilePath();
|
|
3490
|
-
if (!
|
|
3217
|
+
if (!existsSync5(codexAuthPath)) {
|
|
3491
3218
|
yield {
|
|
3492
3219
|
type: "error",
|
|
3493
3220
|
content: `Codex auth file not found at ${codexAuthPath}. Run \`codex login\` to authenticate.`
|
|
@@ -3526,7 +3253,7 @@ async function* codexProvider(opts) {
|
|
|
3526
3253
|
model: opts.model ?? "(sdk default)",
|
|
3527
3254
|
effort: opts.effort ?? "(off)",
|
|
3528
3255
|
cwd: opts.cwd,
|
|
3529
|
-
cwdExists:
|
|
3256
|
+
cwdExists: existsSync5(opts.cwd),
|
|
3530
3257
|
resume: Boolean(opts.sessionId),
|
|
3531
3258
|
mcpServerCount: Object.keys(codexMcpServers).length
|
|
3532
3259
|
}, "codexProvider: starting turn");
|
|
@@ -3933,18 +3660,18 @@ function maestroProvider(opts) {
|
|
|
3933
3660
|
return sdkMaestroProvider(sdkOpts);
|
|
3934
3661
|
}
|
|
3935
3662
|
// ../../packages/core/src/agents/claude-runtime-inspection.ts
|
|
3936
|
-
import { readFileSync as
|
|
3937
|
-
import { createRequire as
|
|
3938
|
-
import { dirname as dirname7, join as
|
|
3663
|
+
import { readFileSync as readFileSync7 } from "fs";
|
|
3664
|
+
import { createRequire as createRequire3 } from "module";
|
|
3665
|
+
import { dirname as dirname7, join as join7 } from "path";
|
|
3939
3666
|
var cached;
|
|
3940
3667
|
function inspectBundledClaudeRuntime() {
|
|
3941
3668
|
if (cached)
|
|
3942
3669
|
return cached;
|
|
3943
3670
|
try {
|
|
3944
|
-
const require2 =
|
|
3671
|
+
const require2 = createRequire3(import.meta.url);
|
|
3945
3672
|
const sdkDir = dirname7(require2.resolve("@anthropic-ai/claude-agent-sdk"));
|
|
3946
|
-
const sdkPackage = JSON.parse(
|
|
3947
|
-
const manifest = JSON.parse(
|
|
3673
|
+
const sdkPackage = JSON.parse(readFileSync7(join7(sdkDir, "package.json"), "utf8"));
|
|
3674
|
+
const manifest = JSON.parse(readFileSync7(join7(sdkDir, "manifest.json"), "utf8"));
|
|
3948
3675
|
const sdkVersion = typeof sdkPackage.version === "string" ? sdkPackage.version : "";
|
|
3949
3676
|
const claudeCodeVersion = typeof manifest.version === "string" ? manifest.version : "";
|
|
3950
3677
|
if (!sdkVersion || !claudeCodeVersion) {
|
|
@@ -4017,4 +3744,4 @@ export {
|
|
|
4017
3744
|
buildClaudeDisallowedTools
|
|
4018
3745
|
};
|
|
4019
3746
|
|
|
4020
|
-
//# debugId=
|
|
3747
|
+
//# debugId=91493C665ED6215F64756E2164756E21
|