@rynfar/meridian 1.68.0 → 1.69.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{cli-0zhb8ss4.js → cli-x1sv3bqf.js} +897 -504
- package/dist/{cli-sh8bzdwe.js → cli-zdbv40d5.js} +26 -7
- package/dist/cli.js +4 -4
- package/dist/meridian/index.js +252 -0
- package/dist/meridian/package.json +6 -0
- package/dist/proxy/adapter.d.ts +16 -0
- package/dist/proxy/adapter.d.ts.map +1 -1
- package/dist/proxy/adapters/claudecode.d.ts +23 -0
- package/dist/proxy/adapters/claudecode.d.ts.map +1 -1
- package/dist/proxy/adapters/passthrough.d.ts.map +1 -1
- package/dist/proxy/errors.d.ts +2 -0
- package/dist/proxy/errors.d.ts.map +1 -1
- package/dist/proxy/openaiResponses.d.ts +106 -3
- package/dist/proxy/openaiResponses.d.ts.map +1 -1
- package/dist/proxy/passthroughEarlyStop.d.ts +3 -3
- package/dist/proxy/passthroughEarlyStop.d.ts.map +1 -1
- package/dist/proxy/passthroughTools.d.ts +63 -2
- package/dist/proxy/passthroughTools.d.ts.map +1 -1
- package/dist/proxy/query.d.ts +3 -0
- package/dist/proxy/query.d.ts.map +1 -1
- package/dist/proxy/server.d.ts.map +1 -1
- package/dist/proxy/session/cache.d.ts +20 -3
- package/dist/proxy/session/cache.d.ts.map +1 -1
- package/dist/proxy/session/lineage.d.ts +56 -0
- package/dist/proxy/session/lineage.d.ts.map +1 -1
- package/dist/proxy/session/processIncarnation.d.ts +55 -0
- package/dist/proxy/session/processIncarnation.d.ts.map +1 -1
- package/dist/proxy/setup.d.ts +12 -2
- package/dist/proxy/setup.d.ts.map +1 -1
- package/dist/proxy/transforms/codex.d.ts +12 -0
- package/dist/proxy/transforms/codex.d.ts.map +1 -1
- package/dist/server.js +2 -2
- package/dist/{setup-knvctar4.js → setup-b3ymd9z8.js} +3 -1
- package/dist/telemetry/index.d.ts.map +1 -1
- package/package.json +4 -4
- package/plugin/meridian/index.js +1 -0
- package/plugin/meridian/package.json +6 -0
- package/plugin/meridian.ts +1 -1
|
@@ -77,7 +77,7 @@ import {
|
|
|
77
77
|
init_priorityAttestation,
|
|
78
78
|
notePluginlessOpenCodeRequest,
|
|
79
79
|
verifyPriorityAttestation
|
|
80
|
-
} from "./cli-
|
|
80
|
+
} from "./cli-zdbv40d5.js";
|
|
81
81
|
import {
|
|
82
82
|
__commonJS,
|
|
83
83
|
__esm,
|
|
@@ -633,7 +633,7 @@ __export(exports_pricingStore, {
|
|
|
633
633
|
getPricingOverrides: () => getPricingOverrides,
|
|
634
634
|
deletePricingOverride: () => deletePricingOverride
|
|
635
635
|
});
|
|
636
|
-
import { existsSync as existsSync2, mkdirSync, readFileSync, writeFileSync, renameSync } from "node:fs";
|
|
636
|
+
import { existsSync as existsSync2, mkdirSync, readFileSync as readFileSync2, writeFileSync, renameSync } from "node:fs";
|
|
637
637
|
import { join, dirname } from "node:path";
|
|
638
638
|
import { homedir } from "node:os";
|
|
639
639
|
function getConfigPath() {
|
|
@@ -651,7 +651,7 @@ function readOverrides() {
|
|
|
651
651
|
}
|
|
652
652
|
try {
|
|
653
653
|
if (existsSync2(path)) {
|
|
654
|
-
const raw2 = JSON.parse(
|
|
654
|
+
const raw2 = JSON.parse(readFileSync2(path, "utf-8"));
|
|
655
655
|
const result = {};
|
|
656
656
|
for (const [model, value] of Object.entries(raw2)) {
|
|
657
657
|
try {
|
|
@@ -867,7 +867,7 @@ var require_process = __commonJS((exports, module) => {
|
|
|
867
867
|
var require_filesystem = __commonJS((exports, module) => {
|
|
868
868
|
var fs = __require("fs");
|
|
869
869
|
var LDD_PATH = "/usr/bin/ldd";
|
|
870
|
-
var
|
|
870
|
+
var readFileSync4 = (path) => fs.readFileSync(path, "utf-8");
|
|
871
871
|
var readFile = (path) => new Promise((resolve3, reject) => {
|
|
872
872
|
fs.readFile(path, "utf-8", (err, data) => {
|
|
873
873
|
if (err) {
|
|
@@ -879,7 +879,7 @@ var require_filesystem = __commonJS((exports, module) => {
|
|
|
879
879
|
});
|
|
880
880
|
module.exports = {
|
|
881
881
|
LDD_PATH,
|
|
882
|
-
readFileSync:
|
|
882
|
+
readFileSync: readFileSync4,
|
|
883
883
|
readFile
|
|
884
884
|
};
|
|
885
885
|
});
|
|
@@ -888,7 +888,7 @@ var require_filesystem = __commonJS((exports, module) => {
|
|
|
888
888
|
var require_detect_libc = __commonJS((exports, module) => {
|
|
889
889
|
var childProcess = __require("child_process");
|
|
890
890
|
var { isLinux, getReport } = require_process();
|
|
891
|
-
var { LDD_PATH, readFile, readFileSync:
|
|
891
|
+
var { LDD_PATH, readFile, readFileSync: readFileSync4 } = require_filesystem();
|
|
892
892
|
var cachedFamilyFilesystem;
|
|
893
893
|
var cachedVersionFilesystem;
|
|
894
894
|
var command = "getconf GNU_LIBC_VERSION 2>&1 || true; ldd --version 2>&1 || true";
|
|
@@ -968,7 +968,7 @@ var require_detect_libc = __commonJS((exports, module) => {
|
|
|
968
968
|
}
|
|
969
969
|
cachedFamilyFilesystem = null;
|
|
970
970
|
try {
|
|
971
|
-
const lddContent =
|
|
971
|
+
const lddContent = readFileSync4(LDD_PATH);
|
|
972
972
|
cachedFamilyFilesystem = getFamilyFromLddContent(lddContent);
|
|
973
973
|
} catch (e) {}
|
|
974
974
|
return cachedFamilyFilesystem;
|
|
@@ -1023,7 +1023,7 @@ var require_detect_libc = __commonJS((exports, module) => {
|
|
|
1023
1023
|
}
|
|
1024
1024
|
cachedVersionFilesystem = null;
|
|
1025
1025
|
try {
|
|
1026
|
-
const lddContent =
|
|
1026
|
+
const lddContent = readFileSync4(LDD_PATH);
|
|
1027
1027
|
const versionMatch = lddContent.match(RE_GLIBC_VERSION);
|
|
1028
1028
|
if (versionMatch) {
|
|
1029
1029
|
cachedVersionFilesystem = versionMatch[1];
|
|
@@ -2117,7 +2117,7 @@ var init_messages = __esm(() => {
|
|
|
2117
2117
|
});
|
|
2118
2118
|
|
|
2119
2119
|
// src/proxy/session/fingerprint.ts
|
|
2120
|
-
import { createHash as
|
|
2120
|
+
import { createHash as createHash3 } from "crypto";
|
|
2121
2121
|
function extractClientCwd(body) {
|
|
2122
2122
|
let systemText = "";
|
|
2123
2123
|
if (typeof body.system === "string") {
|
|
@@ -2140,7 +2140,7 @@ function getConversationFingerprint(messages, workingDirectory) {
|
|
|
2140
2140
|
return "";
|
|
2141
2141
|
const seed = workingDirectory ? `${workingDirectory}
|
|
2142
2142
|
${text.slice(0, 2000)}` : text.slice(0, 2000);
|
|
2143
|
-
return
|
|
2143
|
+
return createHash3("sha256").update(seed).digest("hex").slice(0, 16);
|
|
2144
2144
|
}
|
|
2145
2145
|
function getPriorityAssignmentKey(sessionId, messages, workingDirectory) {
|
|
2146
2146
|
if (sessionId)
|
|
@@ -2463,6 +2463,119 @@ var init_jcode = __esm(() => {
|
|
|
2463
2463
|
};
|
|
2464
2464
|
});
|
|
2465
2465
|
|
|
2466
|
+
// src/proxy/adapters/claudecode.ts
|
|
2467
|
+
function extractClaudeCodeClientCwd(body) {
|
|
2468
|
+
let systemText = "";
|
|
2469
|
+
if (typeof body.system === "string") {
|
|
2470
|
+
systemText = body.system;
|
|
2471
|
+
} else if (Array.isArray(body.system)) {
|
|
2472
|
+
systemText = body.system.filter((b) => b.type === "text" && b.text).map((b) => b.text).join(`
|
|
2473
|
+
`);
|
|
2474
|
+
}
|
|
2475
|
+
if (!systemText)
|
|
2476
|
+
return;
|
|
2477
|
+
const match2 = systemText.match(/Primary working directory:\s*([^\n<]+)/i);
|
|
2478
|
+
return match2?.[1]?.trim() || undefined;
|
|
2479
|
+
}
|
|
2480
|
+
function extractClaudeCodeSessionIdentity(body) {
|
|
2481
|
+
if (!body || typeof body !== "object")
|
|
2482
|
+
return;
|
|
2483
|
+
const metadata = body.metadata;
|
|
2484
|
+
if (!metadata || typeof metadata !== "object")
|
|
2485
|
+
return;
|
|
2486
|
+
const rawUserId = metadata.user_id;
|
|
2487
|
+
let userMetadata = rawUserId;
|
|
2488
|
+
if (typeof rawUserId === "string") {
|
|
2489
|
+
try {
|
|
2490
|
+
userMetadata = JSON.parse(rawUserId);
|
|
2491
|
+
} catch {
|
|
2492
|
+
return;
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2495
|
+
if (!userMetadata || typeof userMetadata !== "object")
|
|
2496
|
+
return;
|
|
2497
|
+
const sessionId = userMetadata.session_id;
|
|
2498
|
+
if (typeof sessionId !== "string" || sessionId.length === 0)
|
|
2499
|
+
return;
|
|
2500
|
+
const parentSessionId = userMetadata.parent_session_id;
|
|
2501
|
+
const parent = typeof parentSessionId === "string" && parentSessionId.length > 0 && parentSessionId !== sessionId ? parentSessionId : undefined;
|
|
2502
|
+
return parent ? { sessionId, parentSessionId: parent } : { sessionId };
|
|
2503
|
+
}
|
|
2504
|
+
function extractClaudeCodeSessionId(body) {
|
|
2505
|
+
return extractClaudeCodeSessionIdentity(body)?.sessionId;
|
|
2506
|
+
}
|
|
2507
|
+
function extractClaudeCodeParentSessionId(body) {
|
|
2508
|
+
return extractClaudeCodeSessionIdentity(body)?.parentSessionId;
|
|
2509
|
+
}
|
|
2510
|
+
function isClaudeCodeClient(c) {
|
|
2511
|
+
return Boolean(c.req.header("x-claude-code-session-id"));
|
|
2512
|
+
}
|
|
2513
|
+
var claudeCodeAdapter;
|
|
2514
|
+
var init_claudecode = __esm(() => {
|
|
2515
|
+
init_fileChanges();
|
|
2516
|
+
init_messages();
|
|
2517
|
+
init_tools();
|
|
2518
|
+
init_env();
|
|
2519
|
+
claudeCodeAdapter = {
|
|
2520
|
+
name: "claude-code",
|
|
2521
|
+
clientEnvironmentMayDifferFromProxy: true,
|
|
2522
|
+
getSessionId(_c, body) {
|
|
2523
|
+
return extractClaudeCodeSessionId(body);
|
|
2524
|
+
},
|
|
2525
|
+
getParentSessionId(_c, body) {
|
|
2526
|
+
return extractClaudeCodeParentSessionId(body);
|
|
2527
|
+
},
|
|
2528
|
+
extractWorkingDirectory(_body) {
|
|
2529
|
+
return;
|
|
2530
|
+
},
|
|
2531
|
+
extractClientWorkingDirectory(body) {
|
|
2532
|
+
return extractClaudeCodeClientCwd(body);
|
|
2533
|
+
},
|
|
2534
|
+
normalizeContent(content) {
|
|
2535
|
+
return normalizeContent(content);
|
|
2536
|
+
},
|
|
2537
|
+
getBlockedBuiltinTools() {
|
|
2538
|
+
return BLOCKED_BUILTIN_TOOLS;
|
|
2539
|
+
},
|
|
2540
|
+
getAgentIncompatibleTools() {
|
|
2541
|
+
return CLAUDE_CODE_ONLY_TOOLS;
|
|
2542
|
+
},
|
|
2543
|
+
getMcpServerName() {
|
|
2544
|
+
return MCP_SERVER_NAME;
|
|
2545
|
+
},
|
|
2546
|
+
getAllowedMcpTools() {
|
|
2547
|
+
return ALLOWED_MCP_TOOLS;
|
|
2548
|
+
},
|
|
2549
|
+
getCoreToolNames() {
|
|
2550
|
+
return ["Read", "Write", "Edit", "Bash", "Glob", "Grep"];
|
|
2551
|
+
},
|
|
2552
|
+
usesPassthrough() {
|
|
2553
|
+
return resolvePassthrough(true);
|
|
2554
|
+
},
|
|
2555
|
+
supportsThinking() {
|
|
2556
|
+
return true;
|
|
2557
|
+
},
|
|
2558
|
+
shouldTrackFileChanges() {
|
|
2559
|
+
return false;
|
|
2560
|
+
},
|
|
2561
|
+
extractFileChangesFromToolUse(toolName, toolInput) {
|
|
2562
|
+
const input = toolInput;
|
|
2563
|
+
const filePath = input?.file_path ?? input?.filePath ?? input?.path;
|
|
2564
|
+
const lowerName = toolName.toLowerCase();
|
|
2565
|
+
if (lowerName === "write" && filePath) {
|
|
2566
|
+
return [{ operation: "wrote", path: String(filePath) }];
|
|
2567
|
+
}
|
|
2568
|
+
if ((lowerName === "edit" || lowerName === "multiedit") && filePath) {
|
|
2569
|
+
return [{ operation: "edited", path: String(filePath) }];
|
|
2570
|
+
}
|
|
2571
|
+
if (lowerName === "bash" && input?.command) {
|
|
2572
|
+
return extractFileChangesFromBash(String(input.command));
|
|
2573
|
+
}
|
|
2574
|
+
return [];
|
|
2575
|
+
}
|
|
2576
|
+
};
|
|
2577
|
+
});
|
|
2578
|
+
|
|
2466
2579
|
// src/proxy/transforms/droid.ts
|
|
2467
2580
|
function resolveDroidPassthrough() {
|
|
2468
2581
|
return resolvePassthrough(false);
|
|
@@ -2774,6 +2887,9 @@ var init_passthrough2 = __esm(() => {
|
|
|
2774
2887
|
getMcpServerName() {
|
|
2775
2888
|
return MCP_SERVER_NAME3;
|
|
2776
2889
|
},
|
|
2890
|
+
getPassthroughMcpName() {
|
|
2891
|
+
return MCP_SERVER_NAME3;
|
|
2892
|
+
},
|
|
2777
2893
|
getAllowedMcpTools() {
|
|
2778
2894
|
return ALLOWED_MCP_TOOLS3;
|
|
2779
2895
|
},
|
|
@@ -2795,116 +2911,6 @@ var init_passthrough2 = __esm(() => {
|
|
|
2795
2911
|
};
|
|
2796
2912
|
});
|
|
2797
2913
|
|
|
2798
|
-
// src/proxy/adapters/claudecode.ts
|
|
2799
|
-
function extractClaudeCodeClientCwd(body) {
|
|
2800
|
-
let systemText = "";
|
|
2801
|
-
if (typeof body.system === "string") {
|
|
2802
|
-
systemText = body.system;
|
|
2803
|
-
} else if (Array.isArray(body.system)) {
|
|
2804
|
-
systemText = body.system.filter((b) => b.type === "text" && b.text).map((b) => b.text).join(`
|
|
2805
|
-
`);
|
|
2806
|
-
}
|
|
2807
|
-
if (!systemText)
|
|
2808
|
-
return;
|
|
2809
|
-
const match2 = systemText.match(/Primary working directory:\s*([^\n<]+)/i);
|
|
2810
|
-
return match2?.[1]?.trim() || undefined;
|
|
2811
|
-
}
|
|
2812
|
-
function extractClaudeCodeSessionIdentity(body) {
|
|
2813
|
-
if (!body || typeof body !== "object")
|
|
2814
|
-
return;
|
|
2815
|
-
const metadata = body.metadata;
|
|
2816
|
-
if (!metadata || typeof metadata !== "object")
|
|
2817
|
-
return;
|
|
2818
|
-
const rawUserId = metadata.user_id;
|
|
2819
|
-
let userMetadata = rawUserId;
|
|
2820
|
-
if (typeof rawUserId === "string") {
|
|
2821
|
-
try {
|
|
2822
|
-
userMetadata = JSON.parse(rawUserId);
|
|
2823
|
-
} catch {
|
|
2824
|
-
return;
|
|
2825
|
-
}
|
|
2826
|
-
}
|
|
2827
|
-
if (!userMetadata || typeof userMetadata !== "object")
|
|
2828
|
-
return;
|
|
2829
|
-
const sessionId = userMetadata.session_id;
|
|
2830
|
-
if (typeof sessionId !== "string" || sessionId.length === 0)
|
|
2831
|
-
return;
|
|
2832
|
-
const parentSessionId = userMetadata.parent_session_id;
|
|
2833
|
-
const parent = typeof parentSessionId === "string" && parentSessionId.length > 0 && parentSessionId !== sessionId ? parentSessionId : undefined;
|
|
2834
|
-
return parent ? { sessionId, parentSessionId: parent } : { sessionId };
|
|
2835
|
-
}
|
|
2836
|
-
function extractClaudeCodeSessionId(body) {
|
|
2837
|
-
return extractClaudeCodeSessionIdentity(body)?.sessionId;
|
|
2838
|
-
}
|
|
2839
|
-
function extractClaudeCodeParentSessionId(body) {
|
|
2840
|
-
return extractClaudeCodeSessionIdentity(body)?.parentSessionId;
|
|
2841
|
-
}
|
|
2842
|
-
var claudeCodeAdapter;
|
|
2843
|
-
var init_claudecode = __esm(() => {
|
|
2844
|
-
init_fileChanges();
|
|
2845
|
-
init_messages();
|
|
2846
|
-
init_tools();
|
|
2847
|
-
init_env();
|
|
2848
|
-
claudeCodeAdapter = {
|
|
2849
|
-
name: "claude-code",
|
|
2850
|
-
clientEnvironmentMayDifferFromProxy: true,
|
|
2851
|
-
getSessionId(_c, body) {
|
|
2852
|
-
return extractClaudeCodeSessionId(body);
|
|
2853
|
-
},
|
|
2854
|
-
getParentSessionId(_c, body) {
|
|
2855
|
-
return extractClaudeCodeParentSessionId(body);
|
|
2856
|
-
},
|
|
2857
|
-
extractWorkingDirectory(_body) {
|
|
2858
|
-
return;
|
|
2859
|
-
},
|
|
2860
|
-
extractClientWorkingDirectory(body) {
|
|
2861
|
-
return extractClaudeCodeClientCwd(body);
|
|
2862
|
-
},
|
|
2863
|
-
normalizeContent(content) {
|
|
2864
|
-
return normalizeContent(content);
|
|
2865
|
-
},
|
|
2866
|
-
getBlockedBuiltinTools() {
|
|
2867
|
-
return BLOCKED_BUILTIN_TOOLS;
|
|
2868
|
-
},
|
|
2869
|
-
getAgentIncompatibleTools() {
|
|
2870
|
-
return CLAUDE_CODE_ONLY_TOOLS;
|
|
2871
|
-
},
|
|
2872
|
-
getMcpServerName() {
|
|
2873
|
-
return MCP_SERVER_NAME;
|
|
2874
|
-
},
|
|
2875
|
-
getAllowedMcpTools() {
|
|
2876
|
-
return ALLOWED_MCP_TOOLS;
|
|
2877
|
-
},
|
|
2878
|
-
getCoreToolNames() {
|
|
2879
|
-
return ["Read", "Write", "Edit", "Bash", "Glob", "Grep"];
|
|
2880
|
-
},
|
|
2881
|
-
usesPassthrough() {
|
|
2882
|
-
return resolvePassthrough(true);
|
|
2883
|
-
},
|
|
2884
|
-
supportsThinking() {
|
|
2885
|
-
return true;
|
|
2886
|
-
},
|
|
2887
|
-
shouldTrackFileChanges() {
|
|
2888
|
-
return false;
|
|
2889
|
-
},
|
|
2890
|
-
extractFileChangesFromToolUse(toolName, toolInput) {
|
|
2891
|
-
const input = toolInput;
|
|
2892
|
-
const filePath = input?.file_path ?? input?.filePath ?? input?.path;
|
|
2893
|
-
const lowerName = toolName.toLowerCase();
|
|
2894
|
-
if (lowerName === "write" && filePath) {
|
|
2895
|
-
return [{ operation: "wrote", path: String(filePath) }];
|
|
2896
|
-
}
|
|
2897
|
-
if ((lowerName === "edit" || lowerName === "multiedit") && filePath) {
|
|
2898
|
-
return [{ operation: "edited", path: String(filePath) }];
|
|
2899
|
-
}
|
|
2900
|
-
if (lowerName === "bash" && input?.command) {
|
|
2901
|
-
return extractFileChangesFromBash(String(input.command));
|
|
2902
|
-
}
|
|
2903
|
-
return [];
|
|
2904
|
-
}
|
|
2905
|
-
};
|
|
2906
|
-
});
|
|
2907
|
-
|
|
2908
2914
|
// src/proxy/transforms/pi.ts
|
|
2909
2915
|
function resolvePiPassthrough() {
|
|
2910
2916
|
return resolvePassthrough(true);
|
|
@@ -3333,7 +3339,7 @@ var init_cherry = __esm(() => {
|
|
|
3333
3339
|
});
|
|
3334
3340
|
|
|
3335
3341
|
// src/proxy/adapterInstances.ts
|
|
3336
|
-
import { existsSync as existsSync4, readFileSync as
|
|
3342
|
+
import { existsSync as existsSync4, readFileSync as readFileSync4 } from "node:fs";
|
|
3337
3343
|
import { join as join5 } from "node:path";
|
|
3338
3344
|
import { homedir as homedir5 } from "node:os";
|
|
3339
3345
|
function parseAdapterInstances(raw2) {
|
|
@@ -3379,7 +3385,7 @@ function loadAdapterInstances() {
|
|
|
3379
3385
|
if (diskCacheAt > 0 && Date.now() - diskCacheAt < DISK_CACHE_TTL_MS)
|
|
3380
3386
|
return diskCache;
|
|
3381
3387
|
try {
|
|
3382
|
-
diskCache = existsSync4(CONFIG_FILE) ? parseAdapterInstances(
|
|
3388
|
+
diskCache = existsSync4(CONFIG_FILE) ? parseAdapterInstances(readFileSync4(CONFIG_FILE, "utf-8")) : {};
|
|
3383
3389
|
} catch (err) {
|
|
3384
3390
|
console.warn(`[meridian] Failed to read ${CONFIG_FILE}: ${err instanceof Error ? err.message : err}`);
|
|
3385
3391
|
diskCache = {};
|
|
@@ -21704,6 +21710,9 @@ config(en_default());
|
|
|
21704
21710
|
// src/proxy/passthroughTools.ts
|
|
21705
21711
|
var PASSTHROUGH_MCP_NAME = "oc";
|
|
21706
21712
|
var PASSTHROUGH_MCP_PREFIX = `mcp__${PASSTHROUGH_MCP_NAME}__`;
|
|
21713
|
+
function passthroughMcpPrefix(serverName = PASSTHROUGH_MCP_NAME) {
|
|
21714
|
+
return `mcp__${serverName}__`;
|
|
21715
|
+
}
|
|
21707
21716
|
function repairTypeSlip(schema, value) {
|
|
21708
21717
|
if (typeof value !== "string")
|
|
21709
21718
|
return value;
|
|
@@ -21826,16 +21835,20 @@ function getAutoDeferThreshold() {
|
|
|
21826
21835
|
return DEFAULT_DEFER_THRESHOLD;
|
|
21827
21836
|
return parsed;
|
|
21828
21837
|
}
|
|
21829
|
-
function
|
|
21838
|
+
function autoDeferDecision(threshold, coreToolNames, toolCount) {
|
|
21839
|
+
return !!(threshold > 0 && coreToolNames && coreToolNames.length > 0 && toolCount > threshold);
|
|
21840
|
+
}
|
|
21841
|
+
function createPassthroughMcpServer(tools, coreToolNames, serverName = PASSTHROUGH_MCP_NAME, pinnedAutoDefer) {
|
|
21830
21842
|
const threshold = getAutoDeferThreshold();
|
|
21831
|
-
const autoDefer =
|
|
21832
|
-
const coreSet = autoDefer ? new Set(coreToolNames.map((n) => n.toLowerCase())) : undefined;
|
|
21843
|
+
const autoDefer = pinnedAutoDefer ?? autoDeferDecision(threshold, coreToolNames, tools.length);
|
|
21844
|
+
const coreSet = autoDefer && coreToolNames ? new Set(coreToolNames.map((n) => n.toLowerCase())) : undefined;
|
|
21833
21845
|
const hasDeferredTools = tools.some((t) => t.defer_loading === true) || autoDefer;
|
|
21834
21846
|
const sortedTools = [...tools].sort((a, b) => a.name.localeCompare(b.name));
|
|
21847
|
+
const aliases = buildPassthroughToolAliases(sortedTools.map((tool) => tool.name), serverName);
|
|
21835
21848
|
const definitions = sortedTools.map((passthroughTool) => {
|
|
21836
21849
|
const alwaysLoad = hasDeferredTools && shouldAlwaysLoad(passthroughTool, coreSet);
|
|
21837
21850
|
const defineTool = (shape) => ({
|
|
21838
|
-
name: passthroughTool.name,
|
|
21851
|
+
name: aliases.aliasByClientName.get(passthroughTool.name) ?? passthroughTool.name,
|
|
21839
21852
|
description: passthroughTool.description || passthroughTool.name,
|
|
21840
21853
|
inputSchema: shape,
|
|
21841
21854
|
handler: async () => ({ content: [{ type: "text", text: "passthrough" }] }),
|
|
@@ -21849,11 +21862,15 @@ function createPassthroughMcpServer(tools, coreToolNames) {
|
|
|
21849
21862
|
return defineTool(fallbackShape);
|
|
21850
21863
|
}
|
|
21851
21864
|
});
|
|
21852
|
-
const server = createSdkMcpServer({ name:
|
|
21865
|
+
const server = createSdkMcpServer({ name: serverName, tools: definitions });
|
|
21866
|
+
const prefix = passthroughMcpPrefix(serverName);
|
|
21853
21867
|
return {
|
|
21854
21868
|
server,
|
|
21855
|
-
|
|
21856
|
-
|
|
21869
|
+
serverName,
|
|
21870
|
+
prefix,
|
|
21871
|
+
toolNames: definitions.map((definition) => `${prefix}${definition.name}`),
|
|
21872
|
+
hasDeferredTools,
|
|
21873
|
+
clientNameByAlias: aliases.clientNameByAlias
|
|
21857
21874
|
};
|
|
21858
21875
|
}
|
|
21859
21876
|
function shouldAlwaysLoad(tool, coreSet) {
|
|
@@ -21883,12 +21900,48 @@ function stableStringify(value) {
|
|
|
21883
21900
|
function toolUseSignature(name, input) {
|
|
21884
21901
|
return `${name}::${stableStringify(input ?? null)}`;
|
|
21885
21902
|
}
|
|
21886
|
-
function stripMcpPrefix(toolName) {
|
|
21887
|
-
|
|
21888
|
-
|
|
21903
|
+
function stripMcpPrefix(toolName, serverName = PASSTHROUGH_MCP_NAME) {
|
|
21904
|
+
const prefix = passthroughMcpPrefix(serverName);
|
|
21905
|
+
if (toolName.startsWith(prefix)) {
|
|
21906
|
+
return toolName.slice(prefix.length);
|
|
21889
21907
|
}
|
|
21890
21908
|
return toolName;
|
|
21891
21909
|
}
|
|
21910
|
+
function buildPassthroughToolAliases(names, serverName = PASSTHROUGH_MCP_NAME) {
|
|
21911
|
+
const PREFIX = passthroughMcpPrefix(serverName);
|
|
21912
|
+
const aliasByClientName = new Map;
|
|
21913
|
+
const clientNameByAlias = new Map;
|
|
21914
|
+
const ordered = [...names].sort((a, b) => a.localeCompare(b));
|
|
21915
|
+
for (const name of ordered) {
|
|
21916
|
+
if (name.startsWith(PREFIX))
|
|
21917
|
+
continue;
|
|
21918
|
+
aliasByClientName.set(name, name);
|
|
21919
|
+
clientNameByAlias.set(name, name);
|
|
21920
|
+
}
|
|
21921
|
+
for (const name of ordered) {
|
|
21922
|
+
if (!name.startsWith(PREFIX))
|
|
21923
|
+
continue;
|
|
21924
|
+
if (aliasByClientName.has(name))
|
|
21925
|
+
continue;
|
|
21926
|
+
let base = name;
|
|
21927
|
+
while (base.startsWith(PREFIX)) {
|
|
21928
|
+
base = base.slice(PREFIX.length);
|
|
21929
|
+
}
|
|
21930
|
+
if (!base)
|
|
21931
|
+
base = "tool";
|
|
21932
|
+
let alias = base;
|
|
21933
|
+
let attempt = 2;
|
|
21934
|
+
while (clientNameByAlias.has(alias))
|
|
21935
|
+
alias = `${base}_${attempt++}`;
|
|
21936
|
+
aliasByClientName.set(name, alias);
|
|
21937
|
+
clientNameByAlias.set(alias, name);
|
|
21938
|
+
}
|
|
21939
|
+
return { aliasByClientName, clientNameByAlias };
|
|
21940
|
+
}
|
|
21941
|
+
function resolveClientToolName(sdkToolName, clientNameByAlias, serverName = PASSTHROUGH_MCP_NAME) {
|
|
21942
|
+
const alias = stripMcpPrefix(sdkToolName, serverName);
|
|
21943
|
+
return clientNameByAlias?.get(alias) ?? alias;
|
|
21944
|
+
}
|
|
21892
21945
|
function toCamelCase(s) {
|
|
21893
21946
|
return s.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
|
|
21894
21947
|
}
|
|
@@ -21922,6 +21975,313 @@ function normalizeToolInput(input, clientSchema) {
|
|
|
21922
21975
|
return repairCapturedObject(normalized, clientSchema.properties);
|
|
21923
21976
|
}
|
|
21924
21977
|
|
|
21978
|
+
// src/proxy/session/processIncarnation.ts
|
|
21979
|
+
import { spawnSync } from "node:child_process";
|
|
21980
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
21981
|
+
import { readFileSync, readlinkSync } from "node:fs";
|
|
21982
|
+
var PROCESS_INCARNATION_VERSION = 1;
|
|
21983
|
+
var UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
21984
|
+
var SHA256_PATTERN = /^[0-9a-f]{64}$/;
|
|
21985
|
+
var LINUX_START_PATTERN = /^[1-9][0-9]{0,31}$/;
|
|
21986
|
+
var WINDOWS_START_PATTERN = /^[1-9][0-9]{0,31}$/;
|
|
21987
|
+
var DARWIN_START_PATTERN = /^(Sun|Mon|Tue|Wed|Thu|Fri|Sat) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [ 0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-6][0-9] [0-9]{4}$/;
|
|
21988
|
+
var PROBE_TIMEOUT_MS = 2000;
|
|
21989
|
+
var WINDOWS_PROBE_TIMEOUT_MS = 1e4;
|
|
21990
|
+
var cachedLocalBootIdentity;
|
|
21991
|
+
var cachedCurrentProcessIncarnation;
|
|
21992
|
+
function hashIdentity(value) {
|
|
21993
|
+
return createHash2("sha256").update(value).digest("hex");
|
|
21994
|
+
}
|
|
21995
|
+
function isPositivePid(value) {
|
|
21996
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
21997
|
+
}
|
|
21998
|
+
function validStartId(kind, value) {
|
|
21999
|
+
if (typeof value !== "string")
|
|
22000
|
+
return false;
|
|
22001
|
+
if (kind === "linux-proc-start-ticks")
|
|
22002
|
+
return LINUX_START_PATTERN.test(value);
|
|
22003
|
+
if (kind === "darwin-ps-lstart")
|
|
22004
|
+
return DARWIN_START_PATTERN.test(value);
|
|
22005
|
+
if (kind === "windows-start-ticks")
|
|
22006
|
+
return WINDOWS_START_PATTERN.test(value);
|
|
22007
|
+
return false;
|
|
22008
|
+
}
|
|
22009
|
+
function parseProcessIncarnation(value) {
|
|
22010
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
22011
|
+
return;
|
|
22012
|
+
const identity = value;
|
|
22013
|
+
if (identity.version !== PROCESS_INCARNATION_VERSION || !isPositivePid(identity.pid) || typeof identity.hostId !== "string" || !SHA256_PATTERN.test(identity.hostId) || typeof identity.bootId !== "string" || !UUID_PATTERN.test(identity.bootId) || typeof identity.startId !== "string" || !validStartId(identity.startIdKind, identity.startId))
|
|
22014
|
+
return;
|
|
22015
|
+
return {
|
|
22016
|
+
version: PROCESS_INCARNATION_VERSION,
|
|
22017
|
+
pid: identity.pid,
|
|
22018
|
+
hostId: identity.hostId,
|
|
22019
|
+
bootId: identity.bootId,
|
|
22020
|
+
startId: identity.startId,
|
|
22021
|
+
startIdKind: identity.startIdKind
|
|
22022
|
+
};
|
|
22023
|
+
}
|
|
22024
|
+
function evaluateProcessIncarnation(owner, localBoot, observedStart) {
|
|
22025
|
+
const parsedOwner = parseProcessIncarnation(owner);
|
|
22026
|
+
if (!parsedOwner || !localBoot || !SHA256_PATTERN.test(localBoot.hostId) || !UUID_PATTERN.test(localBoot.bootId) || parsedOwner.hostId !== localBoot.hostId)
|
|
22027
|
+
return "indeterminate";
|
|
22028
|
+
if (parsedOwner.bootId !== localBoot.bootId)
|
|
22029
|
+
return "dead";
|
|
22030
|
+
if (!observedStart || observedStart.status === "indeterminate")
|
|
22031
|
+
return "indeterminate";
|
|
22032
|
+
if (observedStart.status === "missing")
|
|
22033
|
+
return "dead";
|
|
22034
|
+
if (!validStartId(observedStart.startIdKind, observedStart.startId) || observedStart.startIdKind !== parsedOwner.startIdKind)
|
|
22035
|
+
return "indeterminate";
|
|
22036
|
+
if (observedStart.startId !== parsedOwner.startId)
|
|
22037
|
+
return "dead";
|
|
22038
|
+
return parsedOwner.startIdKind === "linux-proc-start-ticks" ? "alive" : "indeterminate";
|
|
22039
|
+
}
|
|
22040
|
+
function normalizeUuid(raw2) {
|
|
22041
|
+
const value = raw2.trim().toLowerCase();
|
|
22042
|
+
return UUID_PATTERN.test(value) ? value : undefined;
|
|
22043
|
+
}
|
|
22044
|
+
function readFirst(paths) {
|
|
22045
|
+
for (const path of paths) {
|
|
22046
|
+
try {
|
|
22047
|
+
const value = readFileSync(path, "utf8").trim();
|
|
22048
|
+
if (value)
|
|
22049
|
+
return value;
|
|
22050
|
+
} catch {}
|
|
22051
|
+
}
|
|
22052
|
+
return;
|
|
22053
|
+
}
|
|
22054
|
+
function linuxLocalBootIdentity() {
|
|
22055
|
+
const machineId = readFirst(["/etc/machine-id", "/var/lib/dbus/machine-id"]);
|
|
22056
|
+
const bootId = normalizeUuid(readFileSync("/proc/sys/kernel/random/boot_id", "utf8"));
|
|
22057
|
+
const pidNamespace = readlinkSync("/proc/self/ns/pid");
|
|
22058
|
+
if (!machineId || !/^[0-9a-fA-F]{32}$/.test(machineId) || !bootId || !/^pid:\[[0-9]+\]$/.test(pidNamespace)) {
|
|
22059
|
+
return;
|
|
22060
|
+
}
|
|
22061
|
+
return {
|
|
22062
|
+
hostId: hashIdentity(`linux:${machineId.toLowerCase()}:${pidNamespace}`),
|
|
22063
|
+
bootId
|
|
22064
|
+
};
|
|
22065
|
+
}
|
|
22066
|
+
function runDarwin(command, args) {
|
|
22067
|
+
const result = spawnSync(command, args, {
|
|
22068
|
+
encoding: "utf8",
|
|
22069
|
+
env: { ...process.env, LC_ALL: "C", LANG: "C", TZ: "UTC0" },
|
|
22070
|
+
timeout: PROBE_TIMEOUT_MS,
|
|
22071
|
+
maxBuffer: 1024 * 1024
|
|
22072
|
+
});
|
|
22073
|
+
if (result.error || result.status !== 0 || typeof result.stdout !== "string")
|
|
22074
|
+
return;
|
|
22075
|
+
return result.stdout;
|
|
22076
|
+
}
|
|
22077
|
+
function darwinLocalBootIdentity() {
|
|
22078
|
+
const ioreg = runDarwin("/usr/sbin/ioreg", ["-rd1", "-c", "IOPlatformExpertDevice"]);
|
|
22079
|
+
const boot = runDarwin("/usr/sbin/sysctl", ["-n", "kern.bootsessionuuid"]);
|
|
22080
|
+
const machineMatch = ioreg?.match(/"IOPlatformUUID"\s*=\s*"([0-9A-Fa-f-]+)"/);
|
|
22081
|
+
const machineId = machineMatch?.[1] ? normalizeUuid(machineMatch[1]) : undefined;
|
|
22082
|
+
const bootId = boot ? normalizeUuid(boot) : undefined;
|
|
22083
|
+
if (!machineId || !bootId)
|
|
22084
|
+
return;
|
|
22085
|
+
return {
|
|
22086
|
+
hostId: hashIdentity(`darwin:${machineId}`),
|
|
22087
|
+
bootId
|
|
22088
|
+
};
|
|
22089
|
+
}
|
|
22090
|
+
function uuidFromIdentity(value) {
|
|
22091
|
+
const hex3 = createHash2("sha256").update(value).digest("hex").slice(0, 32);
|
|
22092
|
+
return `${hex3.slice(0, 8)}-${hex3.slice(8, 12)}-${hex3.slice(12, 16)}-${hex3.slice(16, 20)}-${hex3.slice(20)}`;
|
|
22093
|
+
}
|
|
22094
|
+
function runWindowsPowerShell(script) {
|
|
22095
|
+
const result = spawnSync("powershell.exe", [
|
|
22096
|
+
"-NoLogo",
|
|
22097
|
+
"-NoProfile",
|
|
22098
|
+
"-NonInteractive",
|
|
22099
|
+
"-ExecutionPolicy",
|
|
22100
|
+
"Bypass",
|
|
22101
|
+
"-Command",
|
|
22102
|
+
script
|
|
22103
|
+
], {
|
|
22104
|
+
encoding: "utf8",
|
|
22105
|
+
windowsHide: true,
|
|
22106
|
+
timeout: WINDOWS_PROBE_TIMEOUT_MS,
|
|
22107
|
+
maxBuffer: 1024 * 1024
|
|
22108
|
+
});
|
|
22109
|
+
return {
|
|
22110
|
+
status: result.error ? null : result.status,
|
|
22111
|
+
...typeof result.stdout === "string" ? { stdout: result.stdout } : {}
|
|
22112
|
+
};
|
|
22113
|
+
}
|
|
22114
|
+
function windowsLocalBootIdentity() {
|
|
22115
|
+
const result = runWindowsPowerShell(String.raw`
|
|
22116
|
+
$ErrorActionPreference = 'Stop'
|
|
22117
|
+
$machine = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Cryptography' -Name MachineGuid).MachineGuid
|
|
22118
|
+
try { $boot = (Get-CimInstance Win32_OperatingSystem).LastBootUpTime }
|
|
22119
|
+
catch { $boot = (Get-WmiObject Win32_OperatingSystem).ConvertToDateTime((Get-WmiObject Win32_OperatingSystem).LastBootUpTime) }
|
|
22120
|
+
Write-Output $machine
|
|
22121
|
+
Write-Output $boot.ToUniversalTime().Ticks
|
|
22122
|
+
`);
|
|
22123
|
+
if (result.status !== 0 || !result.stdout)
|
|
22124
|
+
return;
|
|
22125
|
+
const [machine, bootTicks] = result.stdout.trim().split(/\r?\n/).map((part) => part.trim());
|
|
22126
|
+
if (!machine || !bootTicks || !WINDOWS_START_PATTERN.test(bootTicks))
|
|
22127
|
+
return;
|
|
22128
|
+
return {
|
|
22129
|
+
hostId: hashIdentity(`windows:${machine.toLowerCase()}`),
|
|
22130
|
+
bootId: uuidFromIdentity(`windows-boot:${machine.toLowerCase()}:${bootTicks}`)
|
|
22131
|
+
};
|
|
22132
|
+
}
|
|
22133
|
+
function pinnedHostIdFor(pin) {
|
|
22134
|
+
const trimmed = pin?.trim();
|
|
22135
|
+
return trimmed ? hashIdentity(`pinned:${trimmed}`) : undefined;
|
|
22136
|
+
}
|
|
22137
|
+
function pinnedHostId() {
|
|
22138
|
+
return pinnedHostIdFor(process.env.MERIDIAN_HOST_ID);
|
|
22139
|
+
}
|
|
22140
|
+
function getLocalBootIdentity() {
|
|
22141
|
+
if (cachedLocalBootIdentity)
|
|
22142
|
+
return cachedLocalBootIdentity;
|
|
22143
|
+
try {
|
|
22144
|
+
const identity = process.platform === "linux" ? linuxLocalBootIdentity() : process.platform === "darwin" ? darwinLocalBootIdentity() : process.platform === "win32" ? windowsLocalBootIdentity() : undefined;
|
|
22145
|
+
const pinned = pinnedHostId();
|
|
22146
|
+
const resolved = identity && pinned ? { ...identity, hostId: pinned } : identity;
|
|
22147
|
+
if (resolved)
|
|
22148
|
+
cachedLocalBootIdentity = resolved;
|
|
22149
|
+
return resolved;
|
|
22150
|
+
} catch {
|
|
22151
|
+
return;
|
|
22152
|
+
}
|
|
22153
|
+
}
|
|
22154
|
+
function bootIdentityHint(platform) {
|
|
22155
|
+
if (platform === "linux") {
|
|
22156
|
+
return "no readable /etc/machine-id or /var/lib/dbus/machine-id, or /proc is not mounted. " + "Distroless, scratch, chroot and gVisor images commonly lack machine-id: " + "generate one (`dbus-uuidgen > /etc/machine-id`) or bind-mount the host's.";
|
|
22157
|
+
}
|
|
22158
|
+
if (platform === "darwin") {
|
|
22159
|
+
return "could not read the hardware UUID or boot time from the system profiler.";
|
|
22160
|
+
}
|
|
22161
|
+
if (platform === "win32") {
|
|
22162
|
+
return "could not read the machine GUID or boot time from the registry.";
|
|
22163
|
+
}
|
|
22164
|
+
return `unsupported platform "${platform}" — boot identity is implemented for linux, darwin and win32 only.`;
|
|
22165
|
+
}
|
|
22166
|
+
function describeLocalBootIdentity() {
|
|
22167
|
+
const platform = process.platform;
|
|
22168
|
+
if (getLocalBootIdentity())
|
|
22169
|
+
return { available: true, platform };
|
|
22170
|
+
return { available: false, platform, hint: bootIdentityHint(platform) };
|
|
22171
|
+
}
|
|
22172
|
+
function pidPresence(pid) {
|
|
22173
|
+
try {
|
|
22174
|
+
process.kill(pid, 0);
|
|
22175
|
+
return "present";
|
|
22176
|
+
} catch (error51) {
|
|
22177
|
+
const code = error51 instanceof Error && "code" in error51 ? error51.code : undefined;
|
|
22178
|
+
return code === "ESRCH" ? "missing" : "indeterminate";
|
|
22179
|
+
}
|
|
22180
|
+
}
|
|
22181
|
+
function parseLinuxProcStatStartId(raw2, expectedPid) {
|
|
22182
|
+
const prefix = `${expectedPid} (`;
|
|
22183
|
+
if (!raw2.startsWith(prefix))
|
|
22184
|
+
return;
|
|
22185
|
+
const commEnd = raw2.lastIndexOf(")");
|
|
22186
|
+
if (commEnd < prefix.length || raw2[commEnd + 1] !== " ")
|
|
22187
|
+
return;
|
|
22188
|
+
const fieldsFromState = raw2.slice(commEnd + 2).trim().split(/\s+/);
|
|
22189
|
+
const startId = fieldsFromState[19];
|
|
22190
|
+
return startId && LINUX_START_PATTERN.test(startId) ? startId : undefined;
|
|
22191
|
+
}
|
|
22192
|
+
function linuxProcessStart(pid) {
|
|
22193
|
+
let raw2;
|
|
22194
|
+
try {
|
|
22195
|
+
raw2 = readFileSync(`/proc/${pid}/stat`, "utf8");
|
|
22196
|
+
} catch (error51) {
|
|
22197
|
+
const code = error51 instanceof Error && "code" in error51 ? error51.code : undefined;
|
|
22198
|
+
if (code === "ENOENT" || code === "ESRCH")
|
|
22199
|
+
return { status: "missing" };
|
|
22200
|
+
return { status: "indeterminate" };
|
|
22201
|
+
}
|
|
22202
|
+
const startId = parseLinuxProcStatStartId(raw2, pid);
|
|
22203
|
+
if (startId)
|
|
22204
|
+
return { status: "found", startId, startIdKind: "linux-proc-start-ticks" };
|
|
22205
|
+
return pidPresence(pid) === "missing" ? { status: "missing" } : { status: "indeterminate" };
|
|
22206
|
+
}
|
|
22207
|
+
function darwinProcessStart(pid) {
|
|
22208
|
+
const output = runDarwin("/bin/ps", ["-p", String(pid), "-o", "lstart="]);
|
|
22209
|
+
if (output !== undefined) {
|
|
22210
|
+
const startId = output.trimEnd().trimStart();
|
|
22211
|
+
if (DARWIN_START_PATTERN.test(startId)) {
|
|
22212
|
+
return { status: "found", startId, startIdKind: "darwin-ps-lstart" };
|
|
22213
|
+
}
|
|
22214
|
+
}
|
|
22215
|
+
return pidPresence(pid) === "missing" ? { status: "missing" } : { status: "indeterminate" };
|
|
22216
|
+
}
|
|
22217
|
+
function windowsProcessStart(pid) {
|
|
22218
|
+
const result = runWindowsPowerShell(String.raw`
|
|
22219
|
+
$ErrorActionPreference = 'Stop'
|
|
22220
|
+
try {
|
|
22221
|
+
$process = Get-Process -Id ${pid} -ErrorAction Stop
|
|
22222
|
+
Write-Output $process.StartTime.ToUniversalTime().Ticks
|
|
22223
|
+
} catch [Microsoft.PowerShell.Commands.ProcessCommandException] {
|
|
22224
|
+
exit 3
|
|
22225
|
+
} catch {
|
|
22226
|
+
exit 4
|
|
22227
|
+
}
|
|
22228
|
+
`);
|
|
22229
|
+
const startId = result.stdout?.trim();
|
|
22230
|
+
if (result.status === 0 && startId && WINDOWS_START_PATTERN.test(startId)) {
|
|
22231
|
+
return { status: "found", startId, startIdKind: "windows-start-ticks" };
|
|
22232
|
+
}
|
|
22233
|
+
if (result.status === 3)
|
|
22234
|
+
return { status: "missing" };
|
|
22235
|
+
return pidPresence(pid) === "missing" ? { status: "missing" } : { status: "indeterminate" };
|
|
22236
|
+
}
|
|
22237
|
+
function observeProcessStart(pid) {
|
|
22238
|
+
if (process.platform === "linux")
|
|
22239
|
+
return linuxProcessStart(pid);
|
|
22240
|
+
if (process.platform === "darwin")
|
|
22241
|
+
return darwinProcessStart(pid);
|
|
22242
|
+
if (process.platform === "win32")
|
|
22243
|
+
return windowsProcessStart(pid);
|
|
22244
|
+
return { status: "indeterminate" };
|
|
22245
|
+
}
|
|
22246
|
+
function captureProcessIncarnation(pid = process.pid) {
|
|
22247
|
+
if (!isPositivePid(pid))
|
|
22248
|
+
return;
|
|
22249
|
+
if (pid === process.pid && cachedCurrentProcessIncarnation) {
|
|
22250
|
+
return { ...cachedCurrentProcessIncarnation };
|
|
22251
|
+
}
|
|
22252
|
+
const localBoot = getLocalBootIdentity();
|
|
22253
|
+
if (!localBoot)
|
|
22254
|
+
return;
|
|
22255
|
+
const start = observeProcessStart(pid);
|
|
22256
|
+
if (start.status !== "found")
|
|
22257
|
+
return;
|
|
22258
|
+
const identity = {
|
|
22259
|
+
version: PROCESS_INCARNATION_VERSION,
|
|
22260
|
+
pid,
|
|
22261
|
+
...localBoot,
|
|
22262
|
+
startId: start.startId,
|
|
22263
|
+
startIdKind: start.startIdKind
|
|
22264
|
+
};
|
|
22265
|
+
if (pid === process.pid)
|
|
22266
|
+
cachedCurrentProcessIncarnation = identity;
|
|
22267
|
+
return { ...identity };
|
|
22268
|
+
}
|
|
22269
|
+
function probeProcessIncarnation(owner) {
|
|
22270
|
+
const parsed = parseProcessIncarnation(owner);
|
|
22271
|
+
if (!parsed)
|
|
22272
|
+
return "indeterminate";
|
|
22273
|
+
const localBoot = getLocalBootIdentity();
|
|
22274
|
+
if (!localBoot || parsed.hostId !== localBoot.hostId)
|
|
22275
|
+
return "indeterminate";
|
|
22276
|
+
if (parsed.bootId !== localBoot.bootId) {
|
|
22277
|
+
return evaluateProcessIncarnation(parsed, localBoot, undefined);
|
|
22278
|
+
}
|
|
22279
|
+
return evaluateProcessIncarnation(parsed, localBoot, observeProcessStart(parsed.pid));
|
|
22280
|
+
}
|
|
22281
|
+
function processIncarnationIsDead(owner) {
|
|
22282
|
+
return probeProcessIncarnation(owner) === "dead";
|
|
22283
|
+
}
|
|
22284
|
+
|
|
21925
22285
|
// src/proxy/server.ts
|
|
21926
22286
|
init_tools();
|
|
21927
22287
|
|
|
@@ -21931,7 +22291,7 @@ var INTERNAL_TOOLS = new Set(["ToolSearch", "StructuredOutput"]);
|
|
|
21931
22291
|
function createEarlyStopTracker() {
|
|
21932
22292
|
return { expected: new Set, resolved: new Set, fired: false };
|
|
21933
22293
|
}
|
|
21934
|
-
function isClientForwardedToolUse(block) {
|
|
22294
|
+
function isClientForwardedToolUse(block, clientToolPrefix = CLIENT_TOOL_PREFIX) {
|
|
21935
22295
|
const b = block;
|
|
21936
22296
|
if (!b || b.type !== "tool_use")
|
|
21937
22297
|
return false;
|
|
@@ -21941,26 +22301,26 @@ function isClientForwardedToolUse(block) {
|
|
|
21941
22301
|
return false;
|
|
21942
22302
|
if (INTERNAL_TOOLS.has(b.name))
|
|
21943
22303
|
return false;
|
|
21944
|
-
if (b.name.startsWith("mcp__") && !b.name.startsWith(
|
|
22304
|
+
if (b.name.startsWith("mcp__") && !b.name.startsWith(clientToolPrefix))
|
|
21945
22305
|
return false;
|
|
21946
22306
|
return true;
|
|
21947
22307
|
}
|
|
21948
|
-
function noteAssistantContent(tracker, content) {
|
|
22308
|
+
function noteAssistantContent(tracker, content, clientToolPrefix = CLIENT_TOOL_PREFIX) {
|
|
21949
22309
|
if (!Array.isArray(content))
|
|
21950
22310
|
return;
|
|
21951
22311
|
for (const block of content) {
|
|
21952
|
-
if (isClientForwardedToolUse(block)) {
|
|
22312
|
+
if (isClientForwardedToolUse(block, clientToolPrefix)) {
|
|
21953
22313
|
tracker.expected.add(block.id);
|
|
21954
22314
|
}
|
|
21955
22315
|
}
|
|
21956
22316
|
}
|
|
21957
|
-
function noteAssistantMessage(tracker, message) {
|
|
22317
|
+
function noteAssistantMessage(tracker, message, clientToolPrefix = CLIENT_TOOL_PREFIX) {
|
|
21958
22318
|
const m = message;
|
|
21959
22319
|
if (m?.type !== "assistant")
|
|
21960
22320
|
return;
|
|
21961
22321
|
const content = m.message?.content;
|
|
21962
22322
|
const before = tracker.expected.size;
|
|
21963
|
-
noteAssistantContent(tracker, content);
|
|
22323
|
+
noteAssistantContent(tracker, content, clientToolPrefix);
|
|
21964
22324
|
if (tracker.expected.size > before) {
|
|
21965
22325
|
tracker.toolCallAssistantUuid = typeof m.uuid === "string" && m.uuid.length > 0 ? m.uuid : undefined;
|
|
21966
22326
|
}
|
|
@@ -22342,7 +22702,7 @@ class MemoryDiagnosticLogStore {
|
|
|
22342
22702
|
}
|
|
22343
22703
|
var diagnosticLog = new MemoryDiagnosticLogStore;
|
|
22344
22704
|
// src/telemetry/routes.ts
|
|
22345
|
-
import { existsSync as existsSync3, readFileSync as
|
|
22705
|
+
import { existsSync as existsSync3, readFileSync as readFileSync3 } from "node:fs";
|
|
22346
22706
|
import { resolve as resolve2, dirname as dirname2 } from "node:path";
|
|
22347
22707
|
import { fileURLToPath } from "node:url";
|
|
22348
22708
|
|
|
@@ -22765,7 +23125,7 @@ timer = setInterval(refresh, 5000);
|
|
|
22765
23125
|
|
|
22766
23126
|
// src/telemetry/routes.ts
|
|
22767
23127
|
var _iconPath = resolve2(dirname2(fileURLToPath(import.meta.url)), "..", "..", "assets", "icon.svg");
|
|
22768
|
-
var _iconSvg = existsSync3(_iconPath) ?
|
|
23128
|
+
var _iconSvg = existsSync3(_iconPath) ? readFileSync3(_iconPath, "utf-8") : null;
|
|
22769
23129
|
function createTelemetryRoutes(deps = {}) {
|
|
22770
23130
|
const routes = new Hono2;
|
|
22771
23131
|
routes.get("/", (c) => {
|
|
@@ -23159,7 +23519,9 @@ function createStores() {
|
|
|
23159
23519
|
const dbPath = env("TELEMETRY_DB") ?? getDefaultDbPath();
|
|
23160
23520
|
const retention = envInt("TELEMETRY_RETENTION_DAYS", 7);
|
|
23161
23521
|
const stores = createSqliteStores2(dbPath, retention);
|
|
23162
|
-
|
|
23522
|
+
if (!envBool("QUIET")) {
|
|
23523
|
+
console.error(`[telemetry] SQLite persistence enabled: ${dbPath} (${retention}d retention)`);
|
|
23524
|
+
}
|
|
23163
23525
|
return { telemetry: stores.telemetry, diagnostics: stores.diagnostics };
|
|
23164
23526
|
} catch {
|
|
23165
23527
|
console.warn("[telemetry] MERIDIAN_TELEMETRY_PERSIST is set but libsql is not installed. Run: npm install libsql");
|
|
@@ -23203,7 +23565,11 @@ var BILLING_SIGNALS = [
|
|
|
23203
23565
|
];
|
|
23204
23566
|
var HIT_YOUR_LIMIT = /hit your (?:[\w-]+ )?limit/;
|
|
23205
23567
|
var HIT_YOUR_SPEND_LIMIT = /^\s*(?:(?:error|api error|claude code returned an error result|subprocess stderr):\s*)*you(?:'|’)ve hit your (?:[\w'’-]+ ){0,4}(?:spend|usage) limit/m;
|
|
23206
|
-
var REACHED_YOUR_TIER_LIMIT = /^[ \t]*(?:(?:error|api error|claude code returned an error result|subprocess stderr):[ \t]*)*you(?:'|’)ve reached your (?:claude )?(?:fable|mythos|opus|sonnet|haiku)(?: \d+(?:\.\d+)*)? limit(?:(?:[.!][ \t]+|[ \t]+)(?:(?:run[ \t]+)?\/usage-credits(?:[ \t]+to[ \t]+continue)?(?:[ \t]+or[ \t]+switch[ \t]+models[ \t]+with[ \t]+\/model)?|\/model[ \t]+to[ \t]+switch[ \t]+models)\.?|[.!]?)[ \t\r]*$/m;
|
|
23568
|
+
var REACHED_YOUR_TIER_LIMIT = /^[ \t]*(?:(?:error|api error|claude code returned an error result|subprocess stderr):[ \t]*)*(?:\d{3}[ \t]+)?you(?:'|’)ve reached your (?:claude )?(?:fable|mythos|opus|sonnet|haiku)(?: \d+(?:\.\d+)*)? limit(?:(?:[.!][ \t]+|[ \t]+)(?:(?:run[ \t]+)?\/usage-credits(?:[ \t]+to[ \t]+continue)?(?:[ \t]+or[ \t]+switch[ \t]+models[ \t]+with[ \t]+\/model)?|\/model[ \t]+to[ \t]+switch[ \t]+models|switch[ \t]+to[ \t]+another[ \t]+model(?:[ \t]+to[ \t]+continue)?)\.?|[.!]?)[ \t\r]*$/m;
|
|
23569
|
+
var OUTPUT_TOKEN_MAXIMUM = /response exceeded the \d+ output token maximum/i;
|
|
23570
|
+
function isOutputTokenCapExceeded(message) {
|
|
23571
|
+
return typeof message === "string" && OUTPUT_TOKEN_MAXIMUM.test(message);
|
|
23572
|
+
}
|
|
23207
23573
|
var OUT_OF_USAGE_CREDITS = /^\s*(?:(?:error|api error|claude code returned an error result):\s*)*you(?:'|’)re out of usage credits(?:[.!]\s*)?(?:\/model to switch models\.?)?\s*$/;
|
|
23208
23574
|
var HTTP_401 = /(?:^|[^0-9a-f])401(?![0-9a-f]|:\d)/;
|
|
23209
23575
|
var HTTP_429 = /(?:^|[^0-9a-f])429(?![0-9a-f]|:\d)/;
|
|
@@ -24413,8 +24779,146 @@ function buildModelList(extendedContextIncluded, now = Math.floor(Date.now() / 1
|
|
|
24413
24779
|
|
|
24414
24780
|
// src/proxy/server.ts
|
|
24415
24781
|
init_jcode();
|
|
24782
|
+
init_claudecode();
|
|
24416
24783
|
|
|
24417
24784
|
// src/proxy/openaiResponses.ts
|
|
24785
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
24786
|
+
var PASSTHROUGH_PREFIX_LENGTH = "mcp__oc__".length;
|
|
24787
|
+
var RESPONSES_TOOL_ALIAS_MAX = 64 - PASSTHROUGH_PREFIX_LENGTH;
|
|
24788
|
+
function responsesToolAlias(namespace, name) {
|
|
24789
|
+
const raw2 = namespace ? `${namespace}__${name}` : name;
|
|
24790
|
+
const safe = raw2.replace(/[^A-Za-z0-9_-]/g, "_");
|
|
24791
|
+
if (safe.length <= RESPONSES_TOOL_ALIAS_MAX)
|
|
24792
|
+
return safe;
|
|
24793
|
+
const digest = createHash4("sha256").update(raw2).digest("hex").slice(0, 8);
|
|
24794
|
+
return `${safe.slice(0, RESPONSES_TOOL_ALIAS_MAX - digest.length - 1)}_${digest}`;
|
|
24795
|
+
}
|
|
24796
|
+
function buildResponsesToolAliases(tools) {
|
|
24797
|
+
const aliases = new Map;
|
|
24798
|
+
for (const tool of tools ?? []) {
|
|
24799
|
+
if (tool.type === "custom") {
|
|
24800
|
+
aliases.set(responsesToolAlias(undefined, tool.name), { name: tool.name, kind: "custom" });
|
|
24801
|
+
} else if (tool.type === "namespace") {
|
|
24802
|
+
for (const nested of tool.tools ?? []) {
|
|
24803
|
+
if (nested.type !== "function" && nested.type !== "custom")
|
|
24804
|
+
continue;
|
|
24805
|
+
aliases.set(responsesToolAlias(tool.name, nested.name), {
|
|
24806
|
+
namespace: tool.name,
|
|
24807
|
+
name: nested.name,
|
|
24808
|
+
kind: nested.type
|
|
24809
|
+
});
|
|
24810
|
+
}
|
|
24811
|
+
}
|
|
24812
|
+
}
|
|
24813
|
+
return aliases;
|
|
24814
|
+
}
|
|
24815
|
+
var CUSTOM_TOOL_INPUT_SCHEMA = {
|
|
24816
|
+
type: "object",
|
|
24817
|
+
properties: {
|
|
24818
|
+
input: { type: "string", description: "The complete freeform payload, exactly as the tool's format requires." }
|
|
24819
|
+
},
|
|
24820
|
+
required: ["input"],
|
|
24821
|
+
additionalProperties: false
|
|
24822
|
+
};
|
|
24823
|
+
function customToolDescription(tool) {
|
|
24824
|
+
const parts = [tool.description ?? "", "Freeform tool: put the entire payload in the `input` string; do not wrap it in JSON."];
|
|
24825
|
+
const format = tool.format && typeof tool.format === "object" ? tool.format : undefined;
|
|
24826
|
+
if (typeof format?.definition === "string") {
|
|
24827
|
+
parts.push(`Input grammar${typeof format.syntax === "string" ? ` (${format.syntax})` : ""}:
|
|
24828
|
+
${format.definition}`);
|
|
24829
|
+
}
|
|
24830
|
+
return parts.filter((s) => s.length > 0).join(`
|
|
24831
|
+
|
|
24832
|
+
`);
|
|
24833
|
+
}
|
|
24834
|
+
function translateResponsesTools(tools) {
|
|
24835
|
+
const out = [];
|
|
24836
|
+
const push = (namespace, tool) => {
|
|
24837
|
+
if (tool.type === "function") {
|
|
24838
|
+
out.push({
|
|
24839
|
+
name: namespace ? responsesToolAlias(namespace, tool.name) : tool.name,
|
|
24840
|
+
description: namespace ? `[${namespace}] ${tool.description ?? ""}`.trimEnd() : tool.description ?? "",
|
|
24841
|
+
input_schema: tool.parameters ?? { type: "object", properties: {} }
|
|
24842
|
+
});
|
|
24843
|
+
} else if (tool.type === "custom") {
|
|
24844
|
+
out.push({
|
|
24845
|
+
name: responsesToolAlias(namespace, tool.name),
|
|
24846
|
+
description: customToolDescription(tool),
|
|
24847
|
+
input_schema: CUSTOM_TOOL_INPUT_SCHEMA
|
|
24848
|
+
});
|
|
24849
|
+
}
|
|
24850
|
+
};
|
|
24851
|
+
for (const tool of tools) {
|
|
24852
|
+
if (tool.type === "namespace") {
|
|
24853
|
+
for (const nested of tool.tools ?? [])
|
|
24854
|
+
push(tool.name, nested);
|
|
24855
|
+
} else {
|
|
24856
|
+
push(undefined, tool);
|
|
24857
|
+
}
|
|
24858
|
+
}
|
|
24859
|
+
return out;
|
|
24860
|
+
}
|
|
24861
|
+
function toolCallItem(ctx, id, callId, name, argsJson, status) {
|
|
24862
|
+
const alias = ctx.toolAliases?.get(name);
|
|
24863
|
+
const namespace = alias?.namespace ? { namespace: alias.namespace } : {};
|
|
24864
|
+
if (alias?.kind === "custom") {
|
|
24865
|
+
let input = argsJson;
|
|
24866
|
+
try {
|
|
24867
|
+
const parsed = JSON.parse(argsJson || "{}");
|
|
24868
|
+
if (parsed && typeof parsed === "object" && typeof parsed.input === "string") {
|
|
24869
|
+
input = parsed.input;
|
|
24870
|
+
} else if (argsJson === "" || argsJson === "{}") {
|
|
24871
|
+
input = "";
|
|
24872
|
+
}
|
|
24873
|
+
} catch {}
|
|
24874
|
+
return { type: "custom_tool_call", id, call_id: callId, name: alias.name, ...namespace, input, status };
|
|
24875
|
+
}
|
|
24876
|
+
return { type: "function_call", id, call_id: callId, name: alias?.name ?? name, ...namespace, arguments: argsJson, status };
|
|
24877
|
+
}
|
|
24878
|
+
var CODEX_TURN_METADATA = "x-codex-turn-metadata";
|
|
24879
|
+
var CODEX_THREAD_SOURCE_MAX = 24;
|
|
24880
|
+
var CODEX_TURN_KIND = "turn";
|
|
24881
|
+
function nonEmptyString(value) {
|
|
24882
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
24883
|
+
}
|
|
24884
|
+
function codexTag(value) {
|
|
24885
|
+
const tag = value.toLowerCase().replace(/[^a-z0-9-]/g, "-").slice(0, CODEX_THREAD_SOURCE_MAX);
|
|
24886
|
+
return tag.replace(/-/g, "") ? tag : undefined;
|
|
24887
|
+
}
|
|
24888
|
+
function parseCodexTurnMetadata(value) {
|
|
24889
|
+
if (value && typeof value === "object")
|
|
24890
|
+
return value;
|
|
24891
|
+
const raw2 = nonEmptyString(value);
|
|
24892
|
+
if (!raw2)
|
|
24893
|
+
return;
|
|
24894
|
+
try {
|
|
24895
|
+
const parsed = JSON.parse(raw2);
|
|
24896
|
+
return parsed && typeof parsed === "object" ? parsed : undefined;
|
|
24897
|
+
} catch {
|
|
24898
|
+
return;
|
|
24899
|
+
}
|
|
24900
|
+
}
|
|
24901
|
+
function codexTurnMetadataFromBody(body) {
|
|
24902
|
+
const metadata = body.client_metadata;
|
|
24903
|
+
if (!metadata || typeof metadata !== "object")
|
|
24904
|
+
return;
|
|
24905
|
+
return metadata[CODEX_TURN_METADATA];
|
|
24906
|
+
}
|
|
24907
|
+
function resolveCodexThreadIdentity(body, metadataHeader) {
|
|
24908
|
+
const metadata = parseCodexTurnMetadata(metadataHeader) ?? parseCodexTurnMetadata(codexTurnMetadataFromBody(body));
|
|
24909
|
+
const identity = {};
|
|
24910
|
+
const threadKey = nonEmptyString(metadata?.thread_id) ?? nonEmptyString(body.prompt_cache_key);
|
|
24911
|
+
const kind = nonEmptyString(metadata?.request_kind);
|
|
24912
|
+
const kindTag = kind && kind !== CODEX_TURN_KIND ? codexTag(kind) : undefined;
|
|
24913
|
+
if (threadKey)
|
|
24914
|
+
identity.sessionKey = kindTag ? `${threadKey}:${kindTag}` : threadKey;
|
|
24915
|
+
const threadSource = nonEmptyString(metadata?.thread_source);
|
|
24916
|
+
const sourceTag = threadSource && threadSource !== "user" ? codexTag(threadSource) : undefined;
|
|
24917
|
+
const flow = kindTag ?? sourceTag;
|
|
24918
|
+
if (flow)
|
|
24919
|
+
identity.requestSource = `fork-codex-${flow}`;
|
|
24920
|
+
return identity;
|
|
24921
|
+
}
|
|
24418
24922
|
function itemDiscriminator(item) {
|
|
24419
24923
|
if (typeof item !== "object" || item === null)
|
|
24420
24924
|
return;
|
|
@@ -24449,6 +24953,28 @@ function partsToBlocks(content) {
|
|
|
24449
24953
|
}
|
|
24450
24954
|
return blocks;
|
|
24451
24955
|
}
|
|
24956
|
+
function toolOutputToContent(output) {
|
|
24957
|
+
if (output === undefined || output === null)
|
|
24958
|
+
return "";
|
|
24959
|
+
if (typeof output === "string")
|
|
24960
|
+
return output;
|
|
24961
|
+
if (!Array.isArray(output))
|
|
24962
|
+
return typeof output === "object" ? JSON.stringify(output) : String(output);
|
|
24963
|
+
const blocks = [];
|
|
24964
|
+
for (const part of output) {
|
|
24965
|
+
if (!part || typeof part !== "object")
|
|
24966
|
+
continue;
|
|
24967
|
+
if (typeof part.text === "string") {
|
|
24968
|
+
blocks.push({ type: "text", text: part.text });
|
|
24969
|
+
} else if (part.type === "input_image") {
|
|
24970
|
+
const image = typeof part.image_url === "string" ? parseDataUrlImage(part.image_url) : null;
|
|
24971
|
+
blocks.push(image ?? { type: "text", text: "[Unsupported input_image omitted: only data URLs are currently supported]" });
|
|
24972
|
+
} else {
|
|
24973
|
+
blocks.push({ type: "text", text: `[Unsupported ${String(part.type)} tool output part omitted]` });
|
|
24974
|
+
}
|
|
24975
|
+
}
|
|
24976
|
+
return blocks.length > 0 ? blocks : "";
|
|
24977
|
+
}
|
|
24452
24978
|
function mapToolChoice(tc) {
|
|
24453
24979
|
if (tc === "auto")
|
|
24454
24980
|
return { type: "auto" };
|
|
@@ -24476,21 +25002,36 @@ function translateResponsesToAnthropic(body) {
|
|
|
24476
25002
|
const pushBlock = (role, block) => {
|
|
24477
25003
|
const last = messages[messages.length - 1];
|
|
24478
25004
|
if (last && last.role === role && Array.isArray(last.content)) {
|
|
24479
|
-
|
|
25005
|
+
if (block.type === "tool_result") {
|
|
25006
|
+
const firstText = last.content.findIndex((b) => b.type !== "tool_result");
|
|
25007
|
+
if (firstText === -1)
|
|
25008
|
+
last.content.push(block);
|
|
25009
|
+
else
|
|
25010
|
+
last.content.splice(firstText, 0, block);
|
|
25011
|
+
} else {
|
|
25012
|
+
last.content.push(block);
|
|
25013
|
+
}
|
|
24480
25014
|
} else {
|
|
24481
25015
|
messages.push({ role, content: [block] });
|
|
24482
25016
|
}
|
|
24483
25017
|
};
|
|
25018
|
+
let conversationStarted = false;
|
|
24484
25019
|
for (const item of items) {
|
|
24485
25020
|
switch (itemDiscriminator(item)) {
|
|
24486
25021
|
case "message": {
|
|
24487
25022
|
const msg = item;
|
|
24488
25023
|
if (msg.role === "developer" || msg.role === "system") {
|
|
24489
25024
|
const t = partsToText(msg.content);
|
|
24490
|
-
if (t)
|
|
25025
|
+
if (!t)
|
|
25026
|
+
break;
|
|
25027
|
+
if (!conversationStarted) {
|
|
24491
25028
|
systemParts.push(t);
|
|
25029
|
+
break;
|
|
25030
|
+
}
|
|
25031
|
+
pushBlock("user", { type: "text", text: t });
|
|
24492
25032
|
break;
|
|
24493
25033
|
}
|
|
25034
|
+
conversationStarted = true;
|
|
24494
25035
|
const role = msg.role === "assistant" ? "assistant" : "user";
|
|
24495
25036
|
const imageBlocks = partsToBlocks(msg.content);
|
|
24496
25037
|
if (imageBlocks) {
|
|
@@ -24504,6 +25045,7 @@ function translateResponsesToAnthropic(body) {
|
|
|
24504
25045
|
break;
|
|
24505
25046
|
}
|
|
24506
25047
|
case "function_call": {
|
|
25048
|
+
conversationStarted = true;
|
|
24507
25049
|
const fc = item;
|
|
24508
25050
|
let input = {};
|
|
24509
25051
|
try {
|
|
@@ -24511,12 +25053,25 @@ function translateResponsesToAnthropic(body) {
|
|
|
24511
25053
|
} catch {
|
|
24512
25054
|
input = {};
|
|
24513
25055
|
}
|
|
24514
|
-
|
|
25056
|
+
const name = fc.namespace ? responsesToolAlias(fc.namespace, fc.name) : fc.name;
|
|
25057
|
+
pushBlock("assistant", { type: "tool_use", id: fc.call_id, name, input });
|
|
24515
25058
|
break;
|
|
24516
25059
|
}
|
|
24517
25060
|
case "function_call_output": {
|
|
25061
|
+
conversationStarted = true;
|
|
24518
25062
|
const fo = item;
|
|
24519
|
-
pushBlock("user", { type: "tool_result", tool_use_id: fo.call_id, content: fo.output });
|
|
25063
|
+
pushBlock("user", { type: "tool_result", tool_use_id: fo.call_id, content: toolOutputToContent(fo.output) });
|
|
25064
|
+
break;
|
|
25065
|
+
}
|
|
25066
|
+
case "custom_tool_call": {
|
|
25067
|
+
const ct = item;
|
|
25068
|
+
const name = responsesToolAlias(ct.namespace, ct.name);
|
|
25069
|
+
pushBlock("assistant", { type: "tool_use", id: ct.call_id, name, input: { input: ct.input ?? "" } });
|
|
25070
|
+
break;
|
|
25071
|
+
}
|
|
25072
|
+
case "custom_tool_call_output": {
|
|
25073
|
+
const co = item;
|
|
25074
|
+
pushBlock("user", { type: "tool_result", tool_use_id: co.call_id, content: toolOutputToContent(co.output) });
|
|
24520
25075
|
break;
|
|
24521
25076
|
}
|
|
24522
25077
|
case "reasoning":
|
|
@@ -24536,11 +25091,7 @@ function translateResponsesToAnthropic(body) {
|
|
|
24536
25091
|
|
|
24537
25092
|
`);
|
|
24538
25093
|
if (Array.isArray(body.tools) && body.tools.length > 0) {
|
|
24539
|
-
result.tools = body.tools
|
|
24540
|
-
name: t.name,
|
|
24541
|
-
description: t.description ?? "",
|
|
24542
|
-
input_schema: t.parameters ?? { type: "object", properties: {} }
|
|
24543
|
-
}));
|
|
25094
|
+
result.tools = translateResponsesTools(body.tools);
|
|
24544
25095
|
}
|
|
24545
25096
|
const tc = mapToolChoice(body.tool_choice);
|
|
24546
25097
|
if (tc)
|
|
@@ -24582,14 +25133,8 @@ function translateAnthropicToResponses(res, ctx) {
|
|
|
24582
25133
|
if (block.type === "text" && typeof block.text === "string") {
|
|
24583
25134
|
textParts.push({ type: "output_text", text: block.text, annotations: [] });
|
|
24584
25135
|
} else if (block.type === "tool_use") {
|
|
24585
|
-
|
|
24586
|
-
|
|
24587
|
-
id: `fc_${block.id}`,
|
|
24588
|
-
call_id: block.id,
|
|
24589
|
-
name: block.name,
|
|
24590
|
-
arguments: JSON.stringify(block.input ?? {}),
|
|
24591
|
-
status: "completed"
|
|
24592
|
-
});
|
|
25136
|
+
const callId = String(block.id);
|
|
25137
|
+
output.push(toolCallItem(ctx, `fc_${callId}`, callId, String(block.name), JSON.stringify(block.input ?? {}), "completed"));
|
|
24593
25138
|
}
|
|
24594
25139
|
}
|
|
24595
25140
|
if (textParts.length > 0) {
|
|
@@ -24686,10 +25231,13 @@ function createResponsesSseTranslator(ctx) {
|
|
|
24686
25231
|
} else if (cb.type === "tool_use") {
|
|
24687
25232
|
const oi = outputIndex++;
|
|
24688
25233
|
const itemId = `fc_${cb.id}`;
|
|
24689
|
-
|
|
25234
|
+
const callId = String(cb.id ?? "");
|
|
25235
|
+
const name = String(cb.name ?? "");
|
|
25236
|
+
const custom2 = ctx.toolAliases?.get(name)?.kind === "custom";
|
|
25237
|
+
blocks.set(idx, { kind: "tool", outputIndex: oi, itemId, text: "", args: "", callId, name, custom: custom2 });
|
|
24690
25238
|
out.push(emit("response.output_item.added", {
|
|
24691
25239
|
output_index: oi,
|
|
24692
|
-
item:
|
|
25240
|
+
item: toolCallItem(ctx, itemId, callId, name, "", "in_progress")
|
|
24693
25241
|
}));
|
|
24694
25242
|
} else {
|
|
24695
25243
|
blocks.set(idx, { kind: "skip", outputIndex: -1, itemId: "", text: "", args: "" });
|
|
@@ -24711,11 +25259,13 @@ function createResponsesSseTranslator(ctx) {
|
|
|
24711
25259
|
}));
|
|
24712
25260
|
} else if (st.kind === "tool" && event.delta?.type === "input_json_delta" && typeof event.delta.partial_json === "string") {
|
|
24713
25261
|
st.args += event.delta.partial_json;
|
|
24714
|
-
|
|
24715
|
-
|
|
24716
|
-
|
|
24717
|
-
|
|
24718
|
-
|
|
25262
|
+
if (!st.custom) {
|
|
25263
|
+
out.push(emit("response.function_call_arguments.delta", {
|
|
25264
|
+
item_id: st.itemId,
|
|
25265
|
+
output_index: st.outputIndex,
|
|
25266
|
+
delta: event.delta.partial_json
|
|
25267
|
+
}));
|
|
25268
|
+
}
|
|
24719
25269
|
}
|
|
24720
25270
|
break;
|
|
24721
25271
|
}
|
|
@@ -24747,19 +25297,14 @@ function createResponsesSseTranslator(ctx) {
|
|
|
24747
25297
|
finalOutput.push(item);
|
|
24748
25298
|
out.push(emit("response.output_item.done", { output_index: st.outputIndex, item }));
|
|
24749
25299
|
} else if (st.kind === "tool") {
|
|
24750
|
-
|
|
24751
|
-
|
|
24752
|
-
|
|
24753
|
-
|
|
24754
|
-
|
|
24755
|
-
|
|
24756
|
-
|
|
24757
|
-
|
|
24758
|
-
call_id: st.callId,
|
|
24759
|
-
name: st.name,
|
|
24760
|
-
arguments: st.args,
|
|
24761
|
-
status: "completed"
|
|
24762
|
-
};
|
|
25300
|
+
if (!st.custom) {
|
|
25301
|
+
out.push(emit("response.function_call_arguments.done", {
|
|
25302
|
+
item_id: st.itemId,
|
|
25303
|
+
output_index: st.outputIndex,
|
|
25304
|
+
arguments: st.args
|
|
25305
|
+
}));
|
|
25306
|
+
}
|
|
25307
|
+
const item = toolCallItem(ctx, st.itemId, st.callId ?? "", st.name ?? "", st.args, "completed");
|
|
24763
25308
|
finalOutput.push(item);
|
|
24764
25309
|
out.push(emit("response.output_item.done", { output_index: st.outputIndex, item }));
|
|
24765
25310
|
}
|
|
@@ -27874,7 +28419,7 @@ class LRUCache {
|
|
|
27874
28419
|
// node_modules/path-scurry/dist/esm/index.js
|
|
27875
28420
|
import { posix, win32 } from "node:path";
|
|
27876
28421
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
27877
|
-
import { lstatSync, readdir as readdirCB, readdirSync, readlinkSync, realpathSync as rps } from "fs";
|
|
28422
|
+
import { lstatSync, readdir as readdirCB, readdirSync, readlinkSync as readlinkSync2, realpathSync as rps } from "fs";
|
|
27878
28423
|
import * as actualFS from "node:fs";
|
|
27879
28424
|
import { lstat, readdir, readlink, realpath } from "node:fs/promises";
|
|
27880
28425
|
|
|
@@ -28545,7 +29090,7 @@ var defaultFS = {
|
|
|
28545
29090
|
lstatSync,
|
|
28546
29091
|
readdir: readdirCB,
|
|
28547
29092
|
readdirSync,
|
|
28548
|
-
readlinkSync,
|
|
29093
|
+
readlinkSync: readlinkSync2,
|
|
28549
29094
|
realpathSync,
|
|
28550
29095
|
promises: {
|
|
28551
29096
|
lstat,
|
|
@@ -31119,6 +31664,7 @@ function buildQueryOptions(ctx, abortController) {
|
|
|
31119
31664
|
dreaming,
|
|
31120
31665
|
sharedMemory,
|
|
31121
31666
|
maxBudgetUsd,
|
|
31667
|
+
maxOutputTokens,
|
|
31122
31668
|
fallbackModel,
|
|
31123
31669
|
sdkDebug,
|
|
31124
31670
|
additionalDirectories
|
|
@@ -31146,7 +31692,7 @@ function buildQueryOptions(ctx, abortController) {
|
|
|
31146
31692
|
disallowedTools: [...allBlockedTools],
|
|
31147
31693
|
...passthroughMcp ? {
|
|
31148
31694
|
allowedTools: [...passthroughMcp.toolNames],
|
|
31149
|
-
mcpServers: { [
|
|
31695
|
+
mcpServers: { [passthroughMcp.serverName]: passthroughMcp.server }
|
|
31150
31696
|
} : {}
|
|
31151
31697
|
} : {
|
|
31152
31698
|
disallowedTools: [...allBlockedTools],
|
|
@@ -31165,6 +31711,7 @@ function buildQueryOptions(ctx, abortController) {
|
|
|
31165
31711
|
...QUIET_SUBPROCESS_ENV,
|
|
31166
31712
|
...sharedMemory ? stripConfigDir(cleanEnv) : cleanEnv,
|
|
31167
31713
|
ENABLE_TOOL_SEARCH: hasDeferredTools ? "true" : "false",
|
|
31714
|
+
...maxOutputTokens && maxOutputTokens > 0 ? { CLAUDE_CODE_MAX_OUTPUT_TOKENS: String(Math.floor(maxOutputTokens)) } : {},
|
|
31168
31715
|
ENABLE_CLAUDEAI_MCP_SERVERS: !passthrough && ctx.claudeAiConnectors === true ? "true" : "false",
|
|
31169
31716
|
...passthrough && process.env.MERIDIAN_SUPPRESS_SCRATCHPAD !== "0" ? { CLAUDE_CODE_SESSION_KIND: "bg" } : {},
|
|
31170
31717
|
...process.getuid?.() === 0 ? { IS_SANDBOX: "1" } : {},
|
|
@@ -31313,7 +31860,7 @@ var codexTransforms = [
|
|
|
31313
31860
|
name: "codex-force-passthrough",
|
|
31314
31861
|
adapters: ["codex"],
|
|
31315
31862
|
onRequest(ctx) {
|
|
31316
|
-
return { ...ctx, passthrough: true };
|
|
31863
|
+
return { ...ctx, passthrough: true, coreToolNames: undefined };
|
|
31317
31864
|
}
|
|
31318
31865
|
}
|
|
31319
31866
|
];
|
|
@@ -31377,7 +31924,7 @@ function getAdapterTransforms(adapterName) {
|
|
|
31377
31924
|
}
|
|
31378
31925
|
|
|
31379
31926
|
// src/proxy/plugins/loader.ts
|
|
31380
|
-
import { readdirSync as readdirSync2, readFileSync as
|
|
31927
|
+
import { readdirSync as readdirSync2, readFileSync as readFileSync5, existsSync as existsSync5 } from "fs";
|
|
31381
31928
|
import { join as join7, isAbsolute as isAbsolute3, extname } from "path";
|
|
31382
31929
|
import { pathToFileURL } from "url";
|
|
31383
31930
|
|
|
@@ -31423,7 +31970,7 @@ function parsePluginConfig(configPath) {
|
|
|
31423
31970
|
if (!existsSync5(configPath))
|
|
31424
31971
|
return [];
|
|
31425
31972
|
try {
|
|
31426
|
-
const raw2 =
|
|
31973
|
+
const raw2 = readFileSync5(configPath, "utf-8");
|
|
31427
31974
|
const parsed = JSON.parse(raw2);
|
|
31428
31975
|
return Array.isArray(parsed.plugins) ? parsed.plugins : [];
|
|
31429
31976
|
} catch {
|
|
@@ -31658,7 +32205,7 @@ function formatUsageSummary(usage) {
|
|
|
31658
32205
|
|
|
31659
32206
|
// src/proxy/session/lineage.ts
|
|
31660
32207
|
init_messages();
|
|
31661
|
-
import { createHash as
|
|
32208
|
+
import { createHash as createHash5 } from "crypto";
|
|
31662
32209
|
function normalizeContextUsage(usage) {
|
|
31663
32210
|
const lastIteration = usage.iterations?.at(-1);
|
|
31664
32211
|
return lastIteration ?? usage;
|
|
@@ -31712,7 +32259,7 @@ function semanticContent(content) {
|
|
|
31712
32259
|
return hashableContentBlocks(content).map(semanticBlock);
|
|
31713
32260
|
}
|
|
31714
32261
|
function lineageDigest(domain2, value) {
|
|
31715
|
-
return
|
|
32262
|
+
return createHash5("sha256").update(JSON.stringify(["meridian-lineage-v2", domain2, value])).digest("hex").slice(0, 32);
|
|
31716
32263
|
}
|
|
31717
32264
|
function computeLineageHash(messages) {
|
|
31718
32265
|
if (!messages || messages.length === 0)
|
|
@@ -31752,13 +32299,30 @@ function describeLineageMismatch(cached2, messages, precomputedIncomingHashes) {
|
|
|
31752
32299
|
};
|
|
31753
32300
|
if (index < 0)
|
|
31754
32301
|
return base;
|
|
32302
|
+
const storedBlocks = cached2.messageBlockHashes?.[index];
|
|
32303
|
+
const incomingMessage = messages[index];
|
|
32304
|
+
const incomingBlocks = incomingMessage ? computeMessageBlockHashes([incomingMessage])[0] : undefined;
|
|
31755
32305
|
return {
|
|
31756
32306
|
...base,
|
|
31757
32307
|
storedDigest: storedHashes[index],
|
|
31758
32308
|
incomingDigest: incomingHashes[index],
|
|
31759
|
-
incomingShape:
|
|
31760
|
-
previousDigest: index > 0 ? storedHashes[index - 1] : undefined
|
|
31761
|
-
|
|
32309
|
+
incomingShape: incomingMessage ? describeShape(incomingMessage) : undefined,
|
|
32310
|
+
previousDigest: index > 0 ? storedHashes[index - 1] : undefined,
|
|
32311
|
+
storedBlockCount: storedBlocks?.length,
|
|
32312
|
+
incomingBlockCount: incomingBlocks?.length,
|
|
32313
|
+
blockChange: classifyBlockChange(storedBlocks, incomingBlocks)
|
|
32314
|
+
};
|
|
32315
|
+
}
|
|
32316
|
+
function classifyBlockChange(stored, incoming) {
|
|
32317
|
+
if (!stored || !incoming)
|
|
32318
|
+
return "unknown";
|
|
32319
|
+
const isPrefix = (short, long) => short.every((hash2, i) => long[i] === hash2);
|
|
32320
|
+
if (incoming.length > stored.length)
|
|
32321
|
+
return isPrefix(stored, incoming) ? "appended" : "rewritten";
|
|
32322
|
+
if (incoming.length < stored.length)
|
|
32323
|
+
return isPrefix(incoming, stored) ? "dropped" : "rewritten";
|
|
32324
|
+
const same = [...stored].sort().join() === [...incoming].sort().join();
|
|
32325
|
+
return same ? "reordered" : "rewritten";
|
|
31762
32326
|
}
|
|
31763
32327
|
function formatLineageMismatch(mismatch) {
|
|
31764
32328
|
if (mismatch.index < 0)
|
|
@@ -31766,7 +32330,24 @@ function formatLineageMismatch(mismatch) {
|
|
|
31766
32330
|
const short = (digest) => digest ? digest.slice(0, 12) : "—";
|
|
31767
32331
|
const trailing = mismatch.index === mismatch.storedCount - 1 ? " (trailing message only — the rest of the history matched)" : "";
|
|
31768
32332
|
const shape = mismatch.incomingShape ? `${mismatch.incomingShape.role}[${mismatch.incomingShape.blocks}] ${mismatch.incomingShape.bytes}B` : "unknown";
|
|
31769
|
-
|
|
32333
|
+
const blocks = mismatch.storedBlockCount !== undefined && mismatch.incomingBlockCount !== undefined ? `, stored ${mismatch.storedBlockCount} blocks -> incoming ${mismatch.incomingBlockCount} blocks` + (mismatch.blockChange && mismatch.blockChange !== "unknown" ? ` (${mismatch.blockChange})` : "") : ", stored block hashes unavailable (session cached before 1.61.0)";
|
|
32334
|
+
return `first mismatch at index ${mismatch.index}${trailing}: ` + `stored=${short(mismatch.storedDigest)} incoming=${short(mismatch.incomingDigest)}, ` + `incoming now ${shape}${blocks}`;
|
|
32335
|
+
}
|
|
32336
|
+
function independentRequestCause(input) {
|
|
32337
|
+
if (!input.hasSessionKey && input.forkSource)
|
|
32338
|
+
return "fork-source";
|
|
32339
|
+
if (!input.hasSessionKey && input.isSubagent)
|
|
32340
|
+
return "subagent";
|
|
32341
|
+
if (input.clientDrivenLoop)
|
|
32342
|
+
return "headerless-tool-result";
|
|
32343
|
+
if (!input.hasDurableKey)
|
|
32344
|
+
return "no-cache-identity";
|
|
32345
|
+
return;
|
|
32346
|
+
}
|
|
32347
|
+
function formatDivergence(result, cause) {
|
|
32348
|
+
if (result.type !== "diverged")
|
|
32349
|
+
return;
|
|
32350
|
+
return result.reason === "independent-request" && cause ? `${result.reason}:${cause}` : result.reason;
|
|
31770
32351
|
}
|
|
31771
32352
|
function computeMessageHashes(messages) {
|
|
31772
32353
|
if (!messages || messages.length === 0)
|
|
@@ -31941,7 +32522,7 @@ import {
|
|
|
31941
32522
|
unlinkSync,
|
|
31942
32523
|
writeFileSync as writeFileSync2
|
|
31943
32524
|
} from "node:fs";
|
|
31944
|
-
import { createHash as
|
|
32525
|
+
import { createHash as createHash7, randomUUID as randomUUID2 } from "node:crypto";
|
|
31945
32526
|
import { homedir as homedir7, hostname as hostname4 } from "node:os";
|
|
31946
32527
|
import { basename, dirname as dirname6, isAbsolute as isAbsolute4, join as join8 } from "node:path";
|
|
31947
32528
|
|
|
@@ -32007,290 +32588,8 @@ function directoryRenameWasBlockedSync(error51, destination) {
|
|
|
32007
32588
|
}
|
|
32008
32589
|
|
|
32009
32590
|
// src/proxy/session/recoveryClaim.ts
|
|
32010
|
-
import { createHash as
|
|
32591
|
+
import { createHash as createHash6, randomUUID } from "node:crypto";
|
|
32011
32592
|
import { hostname as hostname3 } from "node:os";
|
|
32012
|
-
|
|
32013
|
-
// src/proxy/session/processIncarnation.ts
|
|
32014
|
-
import { spawnSync } from "node:child_process";
|
|
32015
|
-
import { createHash as createHash4 } from "node:crypto";
|
|
32016
|
-
import { readFileSync as readFileSync5, readlinkSync as readlinkSync2 } from "node:fs";
|
|
32017
|
-
var PROCESS_INCARNATION_VERSION = 1;
|
|
32018
|
-
var UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
32019
|
-
var SHA256_PATTERN = /^[0-9a-f]{64}$/;
|
|
32020
|
-
var LINUX_START_PATTERN = /^[1-9][0-9]{0,31}$/;
|
|
32021
|
-
var WINDOWS_START_PATTERN = /^[1-9][0-9]{0,31}$/;
|
|
32022
|
-
var DARWIN_START_PATTERN = /^(Sun|Mon|Tue|Wed|Thu|Fri|Sat) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [ 0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-6][0-9] [0-9]{4}$/;
|
|
32023
|
-
var PROBE_TIMEOUT_MS = 2000;
|
|
32024
|
-
var WINDOWS_PROBE_TIMEOUT_MS = 1e4;
|
|
32025
|
-
var cachedLocalBootIdentity;
|
|
32026
|
-
var cachedCurrentProcessIncarnation;
|
|
32027
|
-
function hashIdentity(value) {
|
|
32028
|
-
return createHash4("sha256").update(value).digest("hex");
|
|
32029
|
-
}
|
|
32030
|
-
function isPositivePid(value) {
|
|
32031
|
-
return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
32032
|
-
}
|
|
32033
|
-
function validStartId(kind, value) {
|
|
32034
|
-
if (typeof value !== "string")
|
|
32035
|
-
return false;
|
|
32036
|
-
if (kind === "linux-proc-start-ticks")
|
|
32037
|
-
return LINUX_START_PATTERN.test(value);
|
|
32038
|
-
if (kind === "darwin-ps-lstart")
|
|
32039
|
-
return DARWIN_START_PATTERN.test(value);
|
|
32040
|
-
if (kind === "windows-start-ticks")
|
|
32041
|
-
return WINDOWS_START_PATTERN.test(value);
|
|
32042
|
-
return false;
|
|
32043
|
-
}
|
|
32044
|
-
function parseProcessIncarnation(value) {
|
|
32045
|
-
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
32046
|
-
return;
|
|
32047
|
-
const identity = value;
|
|
32048
|
-
if (identity.version !== PROCESS_INCARNATION_VERSION || !isPositivePid(identity.pid) || typeof identity.hostId !== "string" || !SHA256_PATTERN.test(identity.hostId) || typeof identity.bootId !== "string" || !UUID_PATTERN.test(identity.bootId) || typeof identity.startId !== "string" || !validStartId(identity.startIdKind, identity.startId))
|
|
32049
|
-
return;
|
|
32050
|
-
return {
|
|
32051
|
-
version: PROCESS_INCARNATION_VERSION,
|
|
32052
|
-
pid: identity.pid,
|
|
32053
|
-
hostId: identity.hostId,
|
|
32054
|
-
bootId: identity.bootId,
|
|
32055
|
-
startId: identity.startId,
|
|
32056
|
-
startIdKind: identity.startIdKind
|
|
32057
|
-
};
|
|
32058
|
-
}
|
|
32059
|
-
function evaluateProcessIncarnation(owner, localBoot, observedStart) {
|
|
32060
|
-
const parsedOwner = parseProcessIncarnation(owner);
|
|
32061
|
-
if (!parsedOwner || !localBoot || !SHA256_PATTERN.test(localBoot.hostId) || !UUID_PATTERN.test(localBoot.bootId) || parsedOwner.hostId !== localBoot.hostId)
|
|
32062
|
-
return "indeterminate";
|
|
32063
|
-
if (parsedOwner.bootId !== localBoot.bootId)
|
|
32064
|
-
return "dead";
|
|
32065
|
-
if (!observedStart || observedStart.status === "indeterminate")
|
|
32066
|
-
return "indeterminate";
|
|
32067
|
-
if (observedStart.status === "missing")
|
|
32068
|
-
return "dead";
|
|
32069
|
-
if (!validStartId(observedStart.startIdKind, observedStart.startId) || observedStart.startIdKind !== parsedOwner.startIdKind)
|
|
32070
|
-
return "indeterminate";
|
|
32071
|
-
if (observedStart.startId !== parsedOwner.startId)
|
|
32072
|
-
return "dead";
|
|
32073
|
-
return parsedOwner.startIdKind === "linux-proc-start-ticks" ? "alive" : "indeterminate";
|
|
32074
|
-
}
|
|
32075
|
-
function normalizeUuid(raw2) {
|
|
32076
|
-
const value = raw2.trim().toLowerCase();
|
|
32077
|
-
return UUID_PATTERN.test(value) ? value : undefined;
|
|
32078
|
-
}
|
|
32079
|
-
function readFirst(paths) {
|
|
32080
|
-
for (const path3 of paths) {
|
|
32081
|
-
try {
|
|
32082
|
-
const value = readFileSync5(path3, "utf8").trim();
|
|
32083
|
-
if (value)
|
|
32084
|
-
return value;
|
|
32085
|
-
} catch {}
|
|
32086
|
-
}
|
|
32087
|
-
return;
|
|
32088
|
-
}
|
|
32089
|
-
function linuxLocalBootIdentity() {
|
|
32090
|
-
const machineId = readFirst(["/etc/machine-id", "/var/lib/dbus/machine-id"]);
|
|
32091
|
-
const bootId = normalizeUuid(readFileSync5("/proc/sys/kernel/random/boot_id", "utf8"));
|
|
32092
|
-
const pidNamespace = readlinkSync2("/proc/self/ns/pid");
|
|
32093
|
-
if (!machineId || !/^[0-9a-fA-F]{32}$/.test(machineId) || !bootId || !/^pid:\[[0-9]+\]$/.test(pidNamespace)) {
|
|
32094
|
-
return;
|
|
32095
|
-
}
|
|
32096
|
-
return {
|
|
32097
|
-
hostId: hashIdentity(`linux:${machineId.toLowerCase()}:${pidNamespace}`),
|
|
32098
|
-
bootId
|
|
32099
|
-
};
|
|
32100
|
-
}
|
|
32101
|
-
function runDarwin(command, args) {
|
|
32102
|
-
const result = spawnSync(command, args, {
|
|
32103
|
-
encoding: "utf8",
|
|
32104
|
-
env: { ...process.env, LC_ALL: "C", LANG: "C", TZ: "UTC0" },
|
|
32105
|
-
timeout: PROBE_TIMEOUT_MS,
|
|
32106
|
-
maxBuffer: 1024 * 1024
|
|
32107
|
-
});
|
|
32108
|
-
if (result.error || result.status !== 0 || typeof result.stdout !== "string")
|
|
32109
|
-
return;
|
|
32110
|
-
return result.stdout;
|
|
32111
|
-
}
|
|
32112
|
-
function darwinLocalBootIdentity() {
|
|
32113
|
-
const ioreg = runDarwin("/usr/sbin/ioreg", ["-rd1", "-c", "IOPlatformExpertDevice"]);
|
|
32114
|
-
const boot = runDarwin("/usr/sbin/sysctl", ["-n", "kern.bootsessionuuid"]);
|
|
32115
|
-
const machineMatch = ioreg?.match(/"IOPlatformUUID"\s*=\s*"([0-9A-Fa-f-]+)"/);
|
|
32116
|
-
const machineId = machineMatch?.[1] ? normalizeUuid(machineMatch[1]) : undefined;
|
|
32117
|
-
const bootId = boot ? normalizeUuid(boot) : undefined;
|
|
32118
|
-
if (!machineId || !bootId)
|
|
32119
|
-
return;
|
|
32120
|
-
return {
|
|
32121
|
-
hostId: hashIdentity(`darwin:${machineId}`),
|
|
32122
|
-
bootId
|
|
32123
|
-
};
|
|
32124
|
-
}
|
|
32125
|
-
function uuidFromIdentity(value) {
|
|
32126
|
-
const hex3 = createHash4("sha256").update(value).digest("hex").slice(0, 32);
|
|
32127
|
-
return `${hex3.slice(0, 8)}-${hex3.slice(8, 12)}-${hex3.slice(12, 16)}-${hex3.slice(16, 20)}-${hex3.slice(20)}`;
|
|
32128
|
-
}
|
|
32129
|
-
function runWindowsPowerShell(script) {
|
|
32130
|
-
const result = spawnSync("powershell.exe", [
|
|
32131
|
-
"-NoLogo",
|
|
32132
|
-
"-NoProfile",
|
|
32133
|
-
"-NonInteractive",
|
|
32134
|
-
"-ExecutionPolicy",
|
|
32135
|
-
"Bypass",
|
|
32136
|
-
"-Command",
|
|
32137
|
-
script
|
|
32138
|
-
], {
|
|
32139
|
-
encoding: "utf8",
|
|
32140
|
-
windowsHide: true,
|
|
32141
|
-
timeout: WINDOWS_PROBE_TIMEOUT_MS,
|
|
32142
|
-
maxBuffer: 1024 * 1024
|
|
32143
|
-
});
|
|
32144
|
-
return {
|
|
32145
|
-
status: result.error ? null : result.status,
|
|
32146
|
-
...typeof result.stdout === "string" ? { stdout: result.stdout } : {}
|
|
32147
|
-
};
|
|
32148
|
-
}
|
|
32149
|
-
function windowsLocalBootIdentity() {
|
|
32150
|
-
const result = runWindowsPowerShell(String.raw`
|
|
32151
|
-
$ErrorActionPreference = 'Stop'
|
|
32152
|
-
$machine = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Cryptography' -Name MachineGuid).MachineGuid
|
|
32153
|
-
try { $boot = (Get-CimInstance Win32_OperatingSystem).LastBootUpTime }
|
|
32154
|
-
catch { $boot = (Get-WmiObject Win32_OperatingSystem).ConvertToDateTime((Get-WmiObject Win32_OperatingSystem).LastBootUpTime) }
|
|
32155
|
-
Write-Output $machine
|
|
32156
|
-
Write-Output $boot.ToUniversalTime().Ticks
|
|
32157
|
-
`);
|
|
32158
|
-
if (result.status !== 0 || !result.stdout)
|
|
32159
|
-
return;
|
|
32160
|
-
const [machine, bootTicks] = result.stdout.trim().split(/\r?\n/).map((part) => part.trim());
|
|
32161
|
-
if (!machine || !bootTicks || !WINDOWS_START_PATTERN.test(bootTicks))
|
|
32162
|
-
return;
|
|
32163
|
-
return {
|
|
32164
|
-
hostId: hashIdentity(`windows:${machine.toLowerCase()}`),
|
|
32165
|
-
bootId: uuidFromIdentity(`windows-boot:${machine.toLowerCase()}:${bootTicks}`)
|
|
32166
|
-
};
|
|
32167
|
-
}
|
|
32168
|
-
function getLocalBootIdentity() {
|
|
32169
|
-
if (cachedLocalBootIdentity)
|
|
32170
|
-
return cachedLocalBootIdentity;
|
|
32171
|
-
try {
|
|
32172
|
-
const identity = process.platform === "linux" ? linuxLocalBootIdentity() : process.platform === "darwin" ? darwinLocalBootIdentity() : process.platform === "win32" ? windowsLocalBootIdentity() : undefined;
|
|
32173
|
-
if (identity)
|
|
32174
|
-
cachedLocalBootIdentity = identity;
|
|
32175
|
-
return identity;
|
|
32176
|
-
} catch {
|
|
32177
|
-
return;
|
|
32178
|
-
}
|
|
32179
|
-
}
|
|
32180
|
-
function pidPresence(pid) {
|
|
32181
|
-
try {
|
|
32182
|
-
process.kill(pid, 0);
|
|
32183
|
-
return "present";
|
|
32184
|
-
} catch (error51) {
|
|
32185
|
-
const code = error51 instanceof Error && "code" in error51 ? error51.code : undefined;
|
|
32186
|
-
return code === "ESRCH" ? "missing" : "indeterminate";
|
|
32187
|
-
}
|
|
32188
|
-
}
|
|
32189
|
-
function parseLinuxProcStatStartId(raw2, expectedPid) {
|
|
32190
|
-
const prefix = `${expectedPid} (`;
|
|
32191
|
-
if (!raw2.startsWith(prefix))
|
|
32192
|
-
return;
|
|
32193
|
-
const commEnd = raw2.lastIndexOf(")");
|
|
32194
|
-
if (commEnd < prefix.length || raw2[commEnd + 1] !== " ")
|
|
32195
|
-
return;
|
|
32196
|
-
const fieldsFromState = raw2.slice(commEnd + 2).trim().split(/\s+/);
|
|
32197
|
-
const startId = fieldsFromState[19];
|
|
32198
|
-
return startId && LINUX_START_PATTERN.test(startId) ? startId : undefined;
|
|
32199
|
-
}
|
|
32200
|
-
function linuxProcessStart(pid) {
|
|
32201
|
-
let raw2;
|
|
32202
|
-
try {
|
|
32203
|
-
raw2 = readFileSync5(`/proc/${pid}/stat`, "utf8");
|
|
32204
|
-
} catch (error51) {
|
|
32205
|
-
const code = error51 instanceof Error && "code" in error51 ? error51.code : undefined;
|
|
32206
|
-
if (code === "ENOENT" || code === "ESRCH")
|
|
32207
|
-
return { status: "missing" };
|
|
32208
|
-
return { status: "indeterminate" };
|
|
32209
|
-
}
|
|
32210
|
-
const startId = parseLinuxProcStatStartId(raw2, pid);
|
|
32211
|
-
if (startId)
|
|
32212
|
-
return { status: "found", startId, startIdKind: "linux-proc-start-ticks" };
|
|
32213
|
-
return pidPresence(pid) === "missing" ? { status: "missing" } : { status: "indeterminate" };
|
|
32214
|
-
}
|
|
32215
|
-
function darwinProcessStart(pid) {
|
|
32216
|
-
const output = runDarwin("/bin/ps", ["-p", String(pid), "-o", "lstart="]);
|
|
32217
|
-
if (output !== undefined) {
|
|
32218
|
-
const startId = output.trimEnd().trimStart();
|
|
32219
|
-
if (DARWIN_START_PATTERN.test(startId)) {
|
|
32220
|
-
return { status: "found", startId, startIdKind: "darwin-ps-lstart" };
|
|
32221
|
-
}
|
|
32222
|
-
}
|
|
32223
|
-
return pidPresence(pid) === "missing" ? { status: "missing" } : { status: "indeterminate" };
|
|
32224
|
-
}
|
|
32225
|
-
function windowsProcessStart(pid) {
|
|
32226
|
-
const result = runWindowsPowerShell(String.raw`
|
|
32227
|
-
$ErrorActionPreference = 'Stop'
|
|
32228
|
-
try {
|
|
32229
|
-
$process = Get-Process -Id ${pid} -ErrorAction Stop
|
|
32230
|
-
Write-Output $process.StartTime.ToUniversalTime().Ticks
|
|
32231
|
-
} catch [Microsoft.PowerShell.Commands.ProcessCommandException] {
|
|
32232
|
-
exit 3
|
|
32233
|
-
} catch {
|
|
32234
|
-
exit 4
|
|
32235
|
-
}
|
|
32236
|
-
`);
|
|
32237
|
-
const startId = result.stdout?.trim();
|
|
32238
|
-
if (result.status === 0 && startId && WINDOWS_START_PATTERN.test(startId)) {
|
|
32239
|
-
return { status: "found", startId, startIdKind: "windows-start-ticks" };
|
|
32240
|
-
}
|
|
32241
|
-
if (result.status === 3)
|
|
32242
|
-
return { status: "missing" };
|
|
32243
|
-
return pidPresence(pid) === "missing" ? { status: "missing" } : { status: "indeterminate" };
|
|
32244
|
-
}
|
|
32245
|
-
function observeProcessStart(pid) {
|
|
32246
|
-
if (process.platform === "linux")
|
|
32247
|
-
return linuxProcessStart(pid);
|
|
32248
|
-
if (process.platform === "darwin")
|
|
32249
|
-
return darwinProcessStart(pid);
|
|
32250
|
-
if (process.platform === "win32")
|
|
32251
|
-
return windowsProcessStart(pid);
|
|
32252
|
-
return { status: "indeterminate" };
|
|
32253
|
-
}
|
|
32254
|
-
function captureProcessIncarnation(pid = process.pid) {
|
|
32255
|
-
if (!isPositivePid(pid))
|
|
32256
|
-
return;
|
|
32257
|
-
if (pid === process.pid && cachedCurrentProcessIncarnation) {
|
|
32258
|
-
return { ...cachedCurrentProcessIncarnation };
|
|
32259
|
-
}
|
|
32260
|
-
const localBoot = getLocalBootIdentity();
|
|
32261
|
-
if (!localBoot)
|
|
32262
|
-
return;
|
|
32263
|
-
const start = observeProcessStart(pid);
|
|
32264
|
-
if (start.status !== "found")
|
|
32265
|
-
return;
|
|
32266
|
-
const identity = {
|
|
32267
|
-
version: PROCESS_INCARNATION_VERSION,
|
|
32268
|
-
pid,
|
|
32269
|
-
...localBoot,
|
|
32270
|
-
startId: start.startId,
|
|
32271
|
-
startIdKind: start.startIdKind
|
|
32272
|
-
};
|
|
32273
|
-
if (pid === process.pid)
|
|
32274
|
-
cachedCurrentProcessIncarnation = identity;
|
|
32275
|
-
return { ...identity };
|
|
32276
|
-
}
|
|
32277
|
-
function probeProcessIncarnation(owner) {
|
|
32278
|
-
const parsed = parseProcessIncarnation(owner);
|
|
32279
|
-
if (!parsed)
|
|
32280
|
-
return "indeterminate";
|
|
32281
|
-
const localBoot = getLocalBootIdentity();
|
|
32282
|
-
if (!localBoot || parsed.hostId !== localBoot.hostId)
|
|
32283
|
-
return "indeterminate";
|
|
32284
|
-
if (parsed.bootId !== localBoot.bootId) {
|
|
32285
|
-
return evaluateProcessIncarnation(parsed, localBoot, undefined);
|
|
32286
|
-
}
|
|
32287
|
-
return evaluateProcessIncarnation(parsed, localBoot, observeProcessStart(parsed.pid));
|
|
32288
|
-
}
|
|
32289
|
-
function processIncarnationIsDead(owner) {
|
|
32290
|
-
return probeProcessIncarnation(owner) === "dead";
|
|
32291
|
-
}
|
|
32292
|
-
|
|
32293
|
-
// src/proxy/session/recoveryClaim.ts
|
|
32294
32593
|
var RECOVERY_CLAIM_VERSION = 2;
|
|
32295
32594
|
function createRecoveryClaimOwner(generation) {
|
|
32296
32595
|
if (!generation)
|
|
@@ -32336,11 +32635,11 @@ function recoveryClaimOwnerIsDead(owner, probe = processIncarnationIsDead) {
|
|
|
32336
32635
|
return probe(owner.incarnation);
|
|
32337
32636
|
}
|
|
32338
32637
|
function getRecoveryClaimPath(lockPath, generation) {
|
|
32339
|
-
const digest =
|
|
32638
|
+
const digest = createHash6("sha256").update(generation).digest("hex");
|
|
32340
32639
|
return `${lockPath}.recover-${digest}`;
|
|
32341
32640
|
}
|
|
32342
32641
|
function getRecoveryClaimTombstonePath(claimPath, claimToken) {
|
|
32343
|
-
const digest =
|
|
32642
|
+
const digest = createHash6("sha256").update(claimToken).digest("hex");
|
|
32344
32643
|
return `${claimPath}.orphan-${digest}`;
|
|
32345
32644
|
}
|
|
32346
32645
|
|
|
@@ -32349,7 +32648,7 @@ var STORE_META_KEY = "\x00meridian-session-store";
|
|
|
32349
32648
|
var STORE_META_VERSION = 1;
|
|
32350
32649
|
var PRIORITY_STORE_META_VERSION = 3;
|
|
32351
32650
|
function keyDigest(key) {
|
|
32352
|
-
return
|
|
32651
|
+
return createHash7("sha256").update(key).digest("hex");
|
|
32353
32652
|
}
|
|
32354
32653
|
function keySlot(key) {
|
|
32355
32654
|
return keyDigest(key).slice(0, 4);
|
|
@@ -32358,7 +32657,7 @@ function absenceGeneration(key, meta3) {
|
|
|
32358
32657
|
return `a:${keyDigest(key)}:${meta3.slots[keySlot(key)] ?? 0}`;
|
|
32359
32658
|
}
|
|
32360
32659
|
function getStoredSessionGeneration(session, key) {
|
|
32361
|
-
const generationId = session.generationId ?? `legacy-${
|
|
32660
|
+
const generationId = session.generationId ?? `legacy-${createHash7("sha256").update(JSON.stringify(session)).digest("hex")}`;
|
|
32362
32661
|
return `p:${keyDigest(key)}:${generationId}`;
|
|
32363
32662
|
}
|
|
32364
32663
|
function keyGeneration(key, session, meta3) {
|
|
@@ -33878,9 +34177,31 @@ function classifyLineage(state, messages, cacheKey2) {
|
|
|
33878
34177
|
${detail}` : "");
|
|
33879
34178
|
console.error(`[PROXY] ${msg}`);
|
|
33880
34179
|
diagnosticLog2.lineage(msg);
|
|
34180
|
+
} else if (result.type === "diverged") {
|
|
34181
|
+
const msg = `Session not resumable (key=${cacheKey2.slice(0, 8)}…): reason=${result.reason}, prefix overlap ${result.prefixOverlap || 0}/${state.messageCount}, incoming ${messages.length} msgs. Starting fresh replay.`;
|
|
34182
|
+
console.error(`[PROXY] ${msg}`);
|
|
34183
|
+
diagnosticLog2.lineage(msg);
|
|
33881
34184
|
}
|
|
33882
34185
|
return result;
|
|
33883
34186
|
}
|
|
34187
|
+
var warnedDegradedFingerprint = false;
|
|
34188
|
+
function warnDegradedFingerprintOnce() {
|
|
34189
|
+
if (warnedDegradedFingerprint)
|
|
34190
|
+
return;
|
|
34191
|
+
warnedDegradedFingerprint = true;
|
|
34192
|
+
const msg = "[PROXY] Session fingerprint has no working directory, so it hashes only the opening " + "user message — two conversations in different directories that start with the same text " + "will share a session. The directory is read from the <env> block of the system prompt; a " + "plugin implementing experimental.chat.system.transform (for example opencode-scrub) may " + "have removed it. Send a session header (meridian setup) to key conversations explicitly.";
|
|
34193
|
+
console.warn(msg);
|
|
34194
|
+
diagnosticLog2.lineage(msg);
|
|
34195
|
+
}
|
|
34196
|
+
var warnedHeaderlessToolLoop = false;
|
|
34197
|
+
function warnHeaderlessToolLoopOnce(adapterName) {
|
|
34198
|
+
if (warnedHeaderlessToolLoop)
|
|
34199
|
+
return;
|
|
34200
|
+
warnedHeaderlessToolLoop = true;
|
|
34201
|
+
const msg = `[PROXY] Client-driven tool loop with no session identity (adapter=${adapterName}): ` + "the request ends in a tool_result and carries no session key, so this and every " + "following tool round starts a fresh SDK session. The conversation does not resume, " + "and the model sees none of its own earlier turns. This is correct for concurrent " + "headless workflow loops, which must not share one conversation fingerprint; an " + 'interactive client should send a session header instead — see "Session identity" ' + "in docs/configuration.md.";
|
|
34202
|
+
console.warn(msg);
|
|
34203
|
+
diagnosticLog2.lineage(msg);
|
|
34204
|
+
}
|
|
33884
34205
|
function lookupSession(sessionId, messages, workingDirectory) {
|
|
33885
34206
|
if (sessionId) {
|
|
33886
34207
|
const shared = lookupSharedSessionResult(sessionId);
|
|
@@ -33901,6 +34222,8 @@ function lookupSession(sessionId, messages, workingDirectory) {
|
|
|
33901
34222
|
}
|
|
33902
34223
|
return result;
|
|
33903
34224
|
}
|
|
34225
|
+
if (!workingDirectory)
|
|
34226
|
+
warnDegradedFingerprintOnce();
|
|
33904
34227
|
const fp = getConversationFingerprint(messages, workingDirectory);
|
|
33905
34228
|
if (fp) {
|
|
33906
34229
|
const shared = lookupSharedSessionResult(fp);
|
|
@@ -34115,7 +34438,7 @@ class SessionTurnCoordinator {
|
|
|
34115
34438
|
var processSessionTurns = new SessionTurnCoordinator;
|
|
34116
34439
|
|
|
34117
34440
|
// src/proxy/session/crossProcessTurnCoordinator.ts
|
|
34118
|
-
import { createHash as
|
|
34441
|
+
import { createHash as createHash8, randomUUID as randomUUID3 } from "node:crypto";
|
|
34119
34442
|
import { hostname as hostname5 } from "node:os";
|
|
34120
34443
|
import { basename as basename2, dirname as dirname7, join as join9 } from "node:path";
|
|
34121
34444
|
import {
|
|
@@ -34167,7 +34490,7 @@ function heartbeatName(token) {
|
|
|
34167
34490
|
return `heartbeat-${token}`;
|
|
34168
34491
|
}
|
|
34169
34492
|
function lockName(key) {
|
|
34170
|
-
return `${
|
|
34493
|
+
return `${createHash8("sha256").update(key).digest("hex")}.lock`;
|
|
34171
34494
|
}
|
|
34172
34495
|
async function readOwner(lockPath) {
|
|
34173
34496
|
let raw2;
|
|
@@ -34592,7 +34915,7 @@ class CrossProcessTurnCoordinator {
|
|
|
34592
34915
|
}
|
|
34593
34916
|
|
|
34594
34917
|
// src/proxy/sessionLifecycle.ts
|
|
34595
|
-
import { createHash as
|
|
34918
|
+
import { createHash as createHash9, randomUUID as randomUUID4 } from "node:crypto";
|
|
34596
34919
|
import { spawn } from "node:child_process";
|
|
34597
34920
|
import { realpathSync as realpathSync2 } from "node:fs";
|
|
34598
34921
|
import {
|
|
@@ -34637,7 +34960,7 @@ class SessionLifecycleBacklogError extends SessionLifecycleError {
|
|
|
34637
34960
|
}
|
|
34638
34961
|
function getTranscriptResourceKey(locator) {
|
|
34639
34962
|
validateLocator(locator);
|
|
34640
|
-
return
|
|
34963
|
+
return createHash9("sha256").update(locator.configDir).update("\x00").update(locator.sessionId).digest("hex");
|
|
34641
34964
|
}
|
|
34642
34965
|
function physicalLocator(locator) {
|
|
34643
34966
|
const { lifecycleGeneration: _generation, ...physical } = locator;
|
|
@@ -36400,6 +36723,7 @@ function createProxyServer(config2 = {}) {
|
|
|
36400
36723
|
const sessionDiscoveredTools = new LRUMap(getMaxSessionsLimit());
|
|
36401
36724
|
const sessionToolCache = new LRUMap(getMaxSessionsLimit());
|
|
36402
36725
|
const sessionMcpCache = new LRUMap(getMaxSessionsLimit());
|
|
36726
|
+
const sessionDeferPin = new LRUMap(getMaxSessionsLimit());
|
|
36403
36727
|
const idleStalls = new IdleStallTracker(UPSTREAM_IDLE_MAX_CONSECUTIVE, getMaxSessionsLimit());
|
|
36404
36728
|
const RESUME_REFUSAL_MAX_RETRIES = 3;
|
|
36405
36729
|
const RESUME_REFUSAL_RETRY_DELAY_MS = parseInt(process.env.MERIDIAN_BUSY_RETRY_DELAY_MS ?? "500", 10);
|
|
@@ -37033,6 +37357,8 @@ data: ${JSON.stringify(lastError)}
|
|
|
37033
37357
|
return textPrompt;
|
|
37034
37358
|
};
|
|
37035
37359
|
const body = options.body;
|
|
37360
|
+
const rawMaxTokens = Number(body?.max_tokens);
|
|
37361
|
+
const clientMaxOutputTokens = envBool("ENFORCE_MAX_TOKENS") && Number.isFinite(rawMaxTokens) && rawMaxTokens > 0 ? Math.floor(rawMaxTokens) : undefined;
|
|
37036
37362
|
const idleRequestKey = idleStallRequestKey(body);
|
|
37037
37363
|
const markPriorityAttemptExposure = (reason) => {
|
|
37038
37364
|
const exposure = options.priorityAttemptExposure;
|
|
@@ -37361,11 +37687,19 @@ data: ${JSON.stringify(lastError)}
|
|
|
37361
37687
|
const profileScopedCwd = profile.id !== "default" ? `${clientWorkingDirectory}::profile=${profile.id}` : clientWorkingDirectory;
|
|
37362
37688
|
const lastMessage = Array.isArray(body.messages) ? body.messages[body.messages.length - 1] : undefined;
|
|
37363
37689
|
const lastIsToolResult = Array.isArray(lastMessage?.content) && lastMessage.content.some((b) => b?.type === "tool_result");
|
|
37364
|
-
const
|
|
37365
|
-
|
|
37690
|
+
const ownsToolLoopWithResume = adapterBase === "claude-code" || isClaudeCodeClient(c);
|
|
37691
|
+
const isClientDrivenLoop = !ownsToolLoopWithResume && !agentSessionId && lastIsToolResult;
|
|
37366
37692
|
const durableMappingKey = profileSessionId || getConversationFingerprint(lineageMessages, profileScopedCwd);
|
|
37367
|
-
|
|
37368
|
-
|
|
37693
|
+
const independentCause = independentRequestCause({
|
|
37694
|
+
hasSessionKey: Boolean(agentSessionId),
|
|
37695
|
+
forkSource: Boolean(requestSource?.startsWith("fork-")),
|
|
37696
|
+
isSubagent: isSubagentRequest,
|
|
37697
|
+
clientDrivenLoop: isClientDrivenLoop,
|
|
37698
|
+
hasDurableKey: Boolean(durableMappingKey)
|
|
37699
|
+
});
|
|
37700
|
+
const isIndependentSession = independentCause !== undefined;
|
|
37701
|
+
if (independentCause === "headerless-tool-result")
|
|
37702
|
+
warnHeaderlessToolLoopOnce(adapter.name);
|
|
37369
37703
|
const durableMappingAtTurn = durableMappingKey ? lookupSharedSessionResult(durableMappingKey) : { status: "missing" };
|
|
37370
37704
|
if (durableMappingAtTurn.status === "error") {
|
|
37371
37705
|
throw new Error(`Shared session store is unavailable: ${durableMappingAtTurn.error.message}`);
|
|
@@ -37525,10 +37859,11 @@ data: ${JSON.stringify(lastError)}
|
|
|
37525
37859
|
return `${m.role}[${contentTypes}]`;
|
|
37526
37860
|
}).join(" → ");
|
|
37527
37861
|
const lineageType = lineageResult.type === "diverged" && !cachedSession ? "new" : lineageResult.type;
|
|
37862
|
+
const divergedReason = formatDivergence(lineageResult, independentCause);
|
|
37528
37863
|
const msgCount = Array.isArray(body.messages) ? body.messages.length : 0;
|
|
37529
37864
|
const toolCount = body.tools?.length ?? 0;
|
|
37530
37865
|
const sdkSnapshot = sdkSemaphore.snapshot;
|
|
37531
|
-
const requestLogLine = `${requestMeta.requestId} adapter=${adapter.name}${requestSource ? ` source=${requestSource}` : ""}${profile.id !== "default" ? ` profile=${profile.id}${routingMode === "sticky" ? "(sticky)" : options.forcedProfileId ? "(priority)" : ""}` : ""} model=${model} stream=${stream3} tools=${toolCount} lineage=${lineageType} session=${resumeSessionId?.slice(0, 8) || "new"}${isUndo && undoRollbackUuid ? ` rollback=${undoRollbackUuid.slice(0, 8)}` : ""}${agentMode ? ` agent=${agentMode}` : ""} sdkActive=${sdkSnapshot.active}/${sdkSnapshot.limit} sdkQueued=${sdkSnapshot.queued} sessionWait=${requestMeta.sessionQueueWaitMs}ms msgCount=${msgCount}`;
|
|
37866
|
+
const requestLogLine = `${requestMeta.requestId} adapter=${adapter.name}${requestSource ? ` source=${requestSource}` : ""}${profile.id !== "default" ? ` profile=${profile.id}${routingMode === "sticky" ? "(sticky)" : options.forcedProfileId ? "(priority)" : ""}` : ""} model=${model} stream=${stream3} tools=${toolCount} lineage=${lineageType} session=${resumeSessionId?.slice(0, 8) || "new"}${isUndo && undoRollbackUuid ? ` rollback=${undoRollbackUuid.slice(0, 8)}` : ""}${divergedReason ? ` diverged=${divergedReason}` : ""}${agentMode ? ` agent=${agentMode}` : ""} sdkActive=${sdkSnapshot.active}/${sdkSnapshot.limit} sdkQueued=${sdkSnapshot.queued} sessionWait=${requestMeta.sessionQueueWaitMs}ms msgCount=${msgCount}`;
|
|
37532
37867
|
plog(`[PROXY] ${requestLogLine} msgs=${msgSummary}`);
|
|
37533
37868
|
diagnosticLog2.session(`${requestLogLine}`, requestMeta.requestId);
|
|
37534
37869
|
if (lineageResult.type === "diverged" && profileSessionId && !isIndependentSession) {
|
|
@@ -37775,13 +38110,22 @@ data: ${JSON.stringify(lastError)}
|
|
|
37775
38110
|
plog(`[PROXY] ${requestMeta.requestId} tools_restored: client sent 0 tools but continued branch had ${cached2.tools.length} — reusing cached tools to preserve prompt cache`);
|
|
37776
38111
|
}
|
|
37777
38112
|
}
|
|
38113
|
+
const passthroughMcpName = adapter.getPassthroughMcpName?.() ?? PASSTHROUGH_MCP_NAME;
|
|
38114
|
+
const clientToolPrefix = passthroughMcpPrefix(passthroughMcpName);
|
|
37778
38115
|
if (passthrough && requestTools.length > 0) {
|
|
37779
38116
|
const toolSetKey = computeToolSetKey(requestTools);
|
|
37780
38117
|
const cachedMcp = profileSessionId ? sessionMcpCache.get(profileSessionId) : undefined;
|
|
38118
|
+
const coreNamesForDefer = pipelineCtx.coreToolNames ? [...pipelineCtx.coreToolNames] : undefined;
|
|
38119
|
+
const pinnedDefer = profileSessionId ? sessionDeferPin.get(profileSessionId) : undefined;
|
|
38120
|
+
const liveDefer = autoDeferDecision(getAutoDeferThreshold(), coreNamesForDefer, requestTools.length);
|
|
38121
|
+
if (pinnedDefer !== undefined && pinnedDefer !== liveDefer) {
|
|
38122
|
+
plog(`[PROXY] ${requestMeta.requestId} defer_flip suppressed: session pinned autoDefer=${pinnedDefer}, live tool count ${requestTools.length} would give ${liveDefer}`);
|
|
38123
|
+
claudeLog("passthrough.defer_flip_suppressed", { pinned: pinnedDefer, live: liveDefer, toolCount: requestTools.length });
|
|
38124
|
+
}
|
|
37781
38125
|
if (cachedMcp && cachedMcp.key === toolSetKey) {
|
|
37782
38126
|
passthroughMcp = cachedMcp.mcp;
|
|
37783
38127
|
} else {
|
|
37784
|
-
passthroughMcp = createPassthroughMcpServer(requestTools,
|
|
38128
|
+
passthroughMcp = createPassthroughMcpServer(requestTools, coreNamesForDefer, passthroughMcpName, pinnedDefer);
|
|
37785
38129
|
if (profileSessionId) {
|
|
37786
38130
|
sessionMcpCache.set(profileSessionId, { key: toolSetKey, mcp: passthroughMcp });
|
|
37787
38131
|
if (cachedMcp) {
|
|
@@ -37789,6 +38133,9 @@ data: ${JSON.stringify(lastError)}
|
|
|
37789
38133
|
}
|
|
37790
38134
|
}
|
|
37791
38135
|
}
|
|
38136
|
+
if (profileSessionId && !sessionDeferPin.has(profileSessionId)) {
|
|
38137
|
+
sessionDeferPin.set(profileSessionId, passthroughMcp.hasDeferredTools);
|
|
38138
|
+
}
|
|
37792
38139
|
}
|
|
37793
38140
|
const hasDeferredTools = passthroughMcp?.hasDeferredTools ?? false;
|
|
37794
38141
|
const coreNames = pipelineCtx.coreToolNames ? [...pipelineCtx.coreToolNames] : undefined;
|
|
@@ -37821,7 +38168,7 @@ data: ${JSON.stringify(lastError)}
|
|
|
37821
38168
|
return {};
|
|
37822
38169
|
}
|
|
37823
38170
|
markPriorityAttemptExposure("tool_use");
|
|
37824
|
-
const toolName =
|
|
38171
|
+
const toolName = resolveClientToolName(input.tool_name, passthroughMcp?.clientNameByAlias, passthroughMcpName);
|
|
37825
38172
|
if (hasDeferredTools && coreSet && !coreSet.has(toolName.toLowerCase())) {
|
|
37826
38173
|
discoveredTools.add(toolName);
|
|
37827
38174
|
}
|
|
@@ -38003,6 +38350,7 @@ data: ${JSON.stringify(lastError)}
|
|
|
38003
38350
|
webFetchPreflight: sdkFeatures.webFetchPreflight,
|
|
38004
38351
|
claudeAiConnectors: sdkFeatures.claudeAiConnectors,
|
|
38005
38352
|
maxBudgetUsd: sdkFeatures.maxBudgetUsd,
|
|
38353
|
+
maxOutputTokens: clientMaxOutputTokens,
|
|
38006
38354
|
fallbackModel: sdkFeatures.fallbackModel,
|
|
38007
38355
|
sdkDebug: sdkFeatures.sdkDebug,
|
|
38008
38356
|
additionalDirectories: sdkFeatures.additionalDirectories ? sdkFeatures.additionalDirectories.split(",").map((d) => d.trim()).filter(Boolean) : undefined,
|
|
@@ -38102,6 +38450,7 @@ data: ${JSON.stringify(lastError)}
|
|
|
38102
38450
|
webFetchPreflight: sdkFeatures.webFetchPreflight,
|
|
38103
38451
|
claudeAiConnectors: sdkFeatures.claudeAiConnectors,
|
|
38104
38452
|
maxBudgetUsd: sdkFeatures.maxBudgetUsd,
|
|
38453
|
+
maxOutputTokens: clientMaxOutputTokens,
|
|
38105
38454
|
fallbackModel: sdkFeatures.fallbackModel,
|
|
38106
38455
|
sdkDebug: sdkFeatures.sdkDebug,
|
|
38107
38456
|
additionalDirectories: sdkFeatures.additionalDirectories ? sdkFeatures.additionalDirectories.split(",").map((d) => d.trim()).filter(Boolean) : undefined,
|
|
@@ -38180,6 +38529,7 @@ data: ${JSON.stringify(lastError)}
|
|
|
38180
38529
|
webFetchPreflight: sdkFeatures.webFetchPreflight,
|
|
38181
38530
|
claudeAiConnectors: sdkFeatures.claudeAiConnectors,
|
|
38182
38531
|
maxBudgetUsd: sdkFeatures.maxBudgetUsd,
|
|
38532
|
+
maxOutputTokens: clientMaxOutputTokens,
|
|
38183
38533
|
fallbackModel: sdkFeatures.fallbackModel,
|
|
38184
38534
|
sdkDebug: sdkFeatures.sdkDebug,
|
|
38185
38535
|
additionalDirectories: sdkFeatures.additionalDirectories ? sdkFeatures.additionalDirectories.split(",").map((d) => d.trim()).filter(Boolean) : undefined,
|
|
@@ -38251,7 +38601,7 @@ data: ${JSON.stringify(lastError)}
|
|
|
38251
38601
|
let assistantAddedForwardedCall = false;
|
|
38252
38602
|
if (passthrough && message.type === "assistant" && !earlyStopFired) {
|
|
38253
38603
|
const expectedBefore = earlyStop.expected.size;
|
|
38254
|
-
noteAssistantMessage(earlyStop, message);
|
|
38604
|
+
noteAssistantMessage(earlyStop, message, clientToolPrefix);
|
|
38255
38605
|
assistantAddedForwardedCall = earlyStop.expected.size > expectedBefore;
|
|
38256
38606
|
} else if (passthrough && message.type === "user" && !earlyStopFired) {
|
|
38257
38607
|
noteUserContent(earlyStop, message.message?.content);
|
|
@@ -38284,7 +38634,7 @@ data: ${JSON.stringify(lastError)}
|
|
|
38284
38634
|
turnGenerating = true;
|
|
38285
38635
|
} else if (passthrough && eventType === "content_block_start") {
|
|
38286
38636
|
const block = event.content_block;
|
|
38287
|
-
if (isClientForwardedToolUse(block))
|
|
38637
|
+
if (isClientForwardedToolUse(block, clientToolPrefix))
|
|
38288
38638
|
streamedToolUseIds.add(block.id);
|
|
38289
38639
|
}
|
|
38290
38640
|
}
|
|
@@ -38330,7 +38680,7 @@ data: ${JSON.stringify(lastError)}
|
|
|
38330
38680
|
continue;
|
|
38331
38681
|
}
|
|
38332
38682
|
if (passthrough && b.type === "tool_use" && typeof b.name === "string") {
|
|
38333
|
-
b.name =
|
|
38683
|
+
b.name = resolveClientToolName(b.name, passthroughMcp?.clientNameByAlias, passthroughMcpName);
|
|
38334
38684
|
}
|
|
38335
38685
|
contentBlocks.push(b);
|
|
38336
38686
|
}
|
|
@@ -38424,6 +38774,16 @@ Subprocess stderr: ${stderrOutput}`;
|
|
|
38424
38774
|
});
|
|
38425
38775
|
if (lastUsage)
|
|
38426
38776
|
logUsage(requestMeta.requestId, lastUsage);
|
|
38777
|
+
} else if (clientMaxOutputTokens && isOutputTokenCapExceeded(error51 instanceof Error ? error51.message : String(error51 ?? ""))) {
|
|
38778
|
+
lastStopReason = "max_tokens";
|
|
38779
|
+
claudeLog("upstream.output_cap_truncated", {
|
|
38780
|
+
mode: "non_stream",
|
|
38781
|
+
cap: clientMaxOutputTokens,
|
|
38782
|
+
blocks: contentBlocks.length
|
|
38783
|
+
});
|
|
38784
|
+
plog(`[PROXY] ${requestMeta.requestId} output capped at client max_tokens=${clientMaxOutputTokens} — reporting stop_reason=max_tokens`);
|
|
38785
|
+
if (lastUsage)
|
|
38786
|
+
logUsage(requestMeta.requestId, lastUsage);
|
|
38427
38787
|
} else if (passthrough && sdkTerm.reason === "max_turns" && hasTruncatableText(contentBlocks)) {
|
|
38428
38788
|
lastStopReason = "max_tokens";
|
|
38429
38789
|
claudeLog("passthrough.capped_turn_truncated", {
|
|
@@ -38831,6 +39191,7 @@ data: ${JSON.stringify({ type: "content_block_stop", index: idx })}
|
|
|
38831
39191
|
webFetchPreflight: sdkFeatures.webFetchPreflight,
|
|
38832
39192
|
claudeAiConnectors: sdkFeatures.claudeAiConnectors,
|
|
38833
39193
|
maxBudgetUsd: sdkFeatures.maxBudgetUsd,
|
|
39194
|
+
maxOutputTokens: clientMaxOutputTokens,
|
|
38834
39195
|
fallbackModel: sdkFeatures.fallbackModel,
|
|
38835
39196
|
sdkDebug: sdkFeatures.sdkDebug,
|
|
38836
39197
|
additionalDirectories: sdkFeatures.additionalDirectories ? sdkFeatures.additionalDirectories.split(",").map((d) => d.trim()).filter(Boolean) : undefined,
|
|
@@ -38929,6 +39290,7 @@ data: ${JSON.stringify({ type: "content_block_stop", index: idx })}
|
|
|
38929
39290
|
webFetchPreflight: sdkFeatures.webFetchPreflight,
|
|
38930
39291
|
claudeAiConnectors: sdkFeatures.claudeAiConnectors,
|
|
38931
39292
|
maxBudgetUsd: sdkFeatures.maxBudgetUsd,
|
|
39293
|
+
maxOutputTokens: clientMaxOutputTokens,
|
|
38932
39294
|
fallbackModel: sdkFeatures.fallbackModel,
|
|
38933
39295
|
sdkDebug: sdkFeatures.sdkDebug,
|
|
38934
39296
|
additionalDirectories: sdkFeatures.additionalDirectories ? sdkFeatures.additionalDirectories.split(",").map((d) => d.trim()).filter(Boolean) : undefined,
|
|
@@ -39007,6 +39369,7 @@ data: ${JSON.stringify({ type: "content_block_stop", index: idx })}
|
|
|
39007
39369
|
webFetchPreflight: sdkFeatures.webFetchPreflight,
|
|
39008
39370
|
claudeAiConnectors: sdkFeatures.claudeAiConnectors,
|
|
39009
39371
|
maxBudgetUsd: sdkFeatures.maxBudgetUsd,
|
|
39372
|
+
maxOutputTokens: clientMaxOutputTokens,
|
|
39010
39373
|
fallbackModel: sdkFeatures.fallbackModel,
|
|
39011
39374
|
sdkDebug: sdkFeatures.sdkDebug,
|
|
39012
39375
|
additionalDirectories: sdkFeatures.additionalDirectories ? sdkFeatures.additionalDirectories.split(",").map((d) => d.trim()).filter(Boolean) : undefined,
|
|
@@ -39111,7 +39474,7 @@ data: ${JSON.stringify({ type: "content_block_stop", index: idx })}
|
|
|
39111
39474
|
let assistantAddedForwardedCall = false;
|
|
39112
39475
|
if (earlyStopEnabled && message.type === "assistant" && !earlyStopFired) {
|
|
39113
39476
|
const expectedBefore = earlyStop.expected.size;
|
|
39114
|
-
noteAssistantMessage(earlyStop, message);
|
|
39477
|
+
noteAssistantMessage(earlyStop, message, clientToolPrefix);
|
|
39115
39478
|
assistantAddedForwardedCall = earlyStop.expected.size > expectedBefore;
|
|
39116
39479
|
} else if (earlyStopEnabled && message.type === "user" && !earlyStopFired) {
|
|
39117
39480
|
noteUserContent(earlyStop, message.message?.content);
|
|
@@ -39227,8 +39590,8 @@ data: ${JSON.stringify({ type: "content_block_stop", index: idx })}
|
|
|
39227
39590
|
skipBlockIndices.add(eventIndex);
|
|
39228
39591
|
continue;
|
|
39229
39592
|
}
|
|
39230
|
-
if (passthrough && block.name.startsWith(
|
|
39231
|
-
block.name =
|
|
39593
|
+
if (passthrough && block.name.startsWith(clientToolPrefix)) {
|
|
39594
|
+
block.name = resolveClientToolName(block.name, passthroughMcp?.clientNameByAlias, passthroughMcpName);
|
|
39232
39595
|
if (block.id)
|
|
39233
39596
|
streamedToolUseIds.add(block.id);
|
|
39234
39597
|
} else if (block.name.startsWith("mcp__")) {
|
|
@@ -39236,6 +39599,7 @@ data: ${JSON.stringify({ type: "content_block_stop", index: idx })}
|
|
|
39236
39599
|
skipBlockIndices.add(eventIndex);
|
|
39237
39600
|
continue;
|
|
39238
39601
|
} else if (passthrough && block.id) {
|
|
39602
|
+
block.name = resolveClientToolName(block.name, passthroughMcp?.clientNameByAlias, passthroughMcpName);
|
|
39239
39603
|
streamedToolUseIds.add(block.id);
|
|
39240
39604
|
}
|
|
39241
39605
|
if (passthrough && eventIndex !== undefined) {
|
|
@@ -39606,7 +39970,7 @@ data: ${JSON.stringify({
|
|
|
39606
39970
|
recoverySessionId = recoveryMessage.session_id;
|
|
39607
39971
|
}
|
|
39608
39972
|
if (recoveryMessage.type === "assistant") {
|
|
39609
|
-
noteAssistantMessage(recoveryEarlyStop, recoveryMessage);
|
|
39973
|
+
noteAssistantMessage(recoveryEarlyStop, recoveryMessage, clientToolPrefix);
|
|
39610
39974
|
} else if (recoveryMessage.type === "user") {
|
|
39611
39975
|
noteUserContent(recoveryEarlyStop, recoveryMessage.message?.content);
|
|
39612
39976
|
}
|
|
@@ -39619,7 +39983,7 @@ data: ${JSON.stringify({
|
|
|
39619
39983
|
releaseHeldDenies(`silent_recovery_${recoveryEvent.type}`);
|
|
39620
39984
|
if (recoveryEvent.type === "message_start")
|
|
39621
39985
|
turnGenerating = true;
|
|
39622
|
-
if (recoveryEvent.type === "content_block_start" && isClientForwardedToolUse(recoveryEvent.content_block)) {
|
|
39986
|
+
if (recoveryEvent.type === "content_block_start" && isClientForwardedToolUse(recoveryEvent.content_block, clientToolPrefix)) {
|
|
39623
39987
|
recoveryStreamedToolUseIds.add(recoveryEvent.content_block.id);
|
|
39624
39988
|
}
|
|
39625
39989
|
const lifted = recoveryLifter.lift(event.event);
|
|
@@ -40140,7 +40504,8 @@ data: {"type":"message_stop"}
|
|
|
40140
40504
|
}
|
|
40141
40505
|
return;
|
|
40142
40506
|
}
|
|
40143
|
-
|
|
40507
|
+
const outputCapTruncated = Boolean(clientMaxOutputTokens) && isOutputTokenCapExceeded(errMsg);
|
|
40508
|
+
if ((passthrough && sdkTerm.reason === "max_turns" || outputCapTruncated) && capturedToolUses.length === 0 && streamedToolUseIds.size === 0 && messageStartEmitted && (outputCapTruncated || textCharsForwarded > 0)) {
|
|
40144
40509
|
flushOpenClientBlocks("capped_turn");
|
|
40145
40510
|
diagnosticLog2.session(`${requestMeta.requestId} sdk_termination_truncated ${formatSdkTermination(sdkTerm, {
|
|
40146
40511
|
model,
|
|
@@ -40739,6 +41104,15 @@ data: ${JSON.stringify({
|
|
|
40739
41104
|
message: "Meridian is shutting down; route new requests to another instance."
|
|
40740
41105
|
}, 503);
|
|
40741
41106
|
}
|
|
41107
|
+
const bootIdentity = describeLocalBootIdentity();
|
|
41108
|
+
if (!bootIdentity.available) {
|
|
41109
|
+
return c.json({
|
|
41110
|
+
status: "unhealthy",
|
|
41111
|
+
version: serverVersion,
|
|
41112
|
+
error: "Cannot capture a process incarnation, so no request that touches a session can be served.",
|
|
41113
|
+
bootIdentity
|
|
41114
|
+
}, 503);
|
|
41115
|
+
}
|
|
40742
41116
|
try {
|
|
40743
41117
|
const healthProfile = resolveProfile(finalConfig.profiles, finalConfig.defaultProfile);
|
|
40744
41118
|
const profileEnvOverrides = Object.keys(healthProfile.env).length > 0 ? healthProfile.env : undefined;
|
|
@@ -41057,10 +41431,11 @@ data: ${JSON.stringify({
|
|
|
41057
41431
|
"Content-Type": "application/json",
|
|
41058
41432
|
"x-meridian-agent": "codex"
|
|
41059
41433
|
};
|
|
41060
|
-
const
|
|
41061
|
-
if (
|
|
41062
|
-
internalHeaders["x-codex-session"] =
|
|
41063
|
-
|
|
41434
|
+
const codexThread = resolveCodexThreadIdentity(rawBody, c.req.header("x-codex-turn-metadata"));
|
|
41435
|
+
if (codexThread.sessionKey)
|
|
41436
|
+
internalHeaders["x-codex-session"] = codexThread.sessionKey;
|
|
41437
|
+
if (codexThread.requestSource)
|
|
41438
|
+
internalHeaders["x-meridian-source"] = codexThread.requestSource;
|
|
41064
41439
|
const xApiKey = c.req.header("x-api-key");
|
|
41065
41440
|
if (xApiKey)
|
|
41066
41441
|
internalHeaders["x-api-key"] = xApiKey;
|
|
@@ -41083,7 +41458,8 @@ data: ${JSON.stringify({
|
|
|
41083
41458
|
const responseId = `resp_${randomUUID6().replace(/-/g, "")}`;
|
|
41084
41459
|
const created = Math.floor(Date.now() / 1000);
|
|
41085
41460
|
const model = typeof rawBody.model === "string" && rawBody.model ? rawBody.model : CANONICAL_SONNET_MODEL;
|
|
41086
|
-
const
|
|
41461
|
+
const toolAliases = buildResponsesToolAliases(rawBody.tools);
|
|
41462
|
+
const ctx = { responseId, model, created, reasoningRequested: reasoningRequested(rawBody), toolAliases };
|
|
41087
41463
|
if (!anthropicBody.stream) {
|
|
41088
41464
|
const anthropicRes = await internalRes.json();
|
|
41089
41465
|
return c.json(translateAnthropicToResponses(anthropicRes, ctx));
|
|
@@ -41431,6 +41807,23 @@ function installProxyProcessErrorHandlers() {
|
|
|
41431
41807
|
});
|
|
41432
41808
|
}
|
|
41433
41809
|
async function startProxyServer(config2 = {}) {
|
|
41810
|
+
let bootIdentity = describeLocalBootIdentity();
|
|
41811
|
+
for (let attempt = 1;!bootIdentity.available && attempt <= 3; attempt++) {
|
|
41812
|
+
await new Promise((resolve6) => setTimeout(resolve6, 250 * attempt));
|
|
41813
|
+
bootIdentity = describeLocalBootIdentity();
|
|
41814
|
+
if (bootIdentity.available) {
|
|
41815
|
+
console.error(`[PROXY] Boot identity captured on attempt ${attempt + 1} (the first probe failed).`);
|
|
41816
|
+
}
|
|
41817
|
+
}
|
|
41818
|
+
if (!bootIdentity.available && !envBool("ALLOW_MISSING_BOOT_IDENTITY")) {
|
|
41819
|
+
throw new Error("[PROXY] Refusing to start: cannot capture a process incarnation on this host, " + `so no request that touches a session could be served.
|
|
41820
|
+
` + ` platform: ${bootIdentity.platform}
|
|
41821
|
+
` + ` cause: ${bootIdentity.hint}
|
|
41822
|
+
` + " Set MERIDIAN_ALLOW_MISSING_BOOT_IDENTITY=1 to start anyway (requests will still fail).");
|
|
41823
|
+
}
|
|
41824
|
+
if (!bootIdentity.available) {
|
|
41825
|
+
console.error("[PROXY] Starting WITHOUT a boot identity because MERIDIAN_ALLOW_MISSING_BOOT_IDENTITY is set. " + `Requests that touch a session will fail with 500. Cause: ${bootIdentity.hint}`);
|
|
41826
|
+
}
|
|
41434
41827
|
claudeExecutable = await resolveClaudeExecutableAsync();
|
|
41435
41828
|
const {
|
|
41436
41829
|
app,
|