replicas-engine 0.1.815 → 0.1.817
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/src/{asp-host-LHDELXWM.js → asp-host-JUVXZCRV.js} +4 -4
- package/dist/src/{chunk-I3CLB5FS.js → chunk-6FLPUBVF.js} +2 -2
- package/dist/src/{chunk-MEPQJE5J.js → chunk-C52ENUG3.js} +1 -1
- package/dist/src/{chunk-UUQYVSQY.js → chunk-EOYBI3PV.js} +2 -2
- package/dist/src/{chunk-WRUZSBSF.js → chunk-FN67CYNX.js} +4 -4
- package/dist/src/chunk-JA23HN6S.js +46 -0
- package/dist/src/{chunk-3XXPWKPE.js → chunk-JAITEGC4.js} +1 -1
- package/dist/src/{chunk-JTAIM2QE.js → chunk-OCQQ6AO3.js} +8 -4
- package/dist/src/command-protection-hook.js +3 -3
- package/dist/src/deepseek-command-protection-plugin.js +4 -4
- package/dist/src/headless-agent.js +2 -2
- package/dist/src/index.js +274 -275
- package/dist/src/post-tool-pr-hook.js +2 -2
- package/dist/src/relay-mcp.js +10 -5
- package/package.json +1 -1
package/dist/src/index.js
CHANGED
|
@@ -91,7 +91,7 @@ import {
|
|
|
91
91
|
evaluateCommandProtection,
|
|
92
92
|
extractToolCommand,
|
|
93
93
|
reportCommandProtectionBlock
|
|
94
|
-
} from "./chunk-
|
|
94
|
+
} from "./chunk-6FLPUBVF.js";
|
|
95
95
|
import {
|
|
96
96
|
ACCOUNT_RATE_LIMITS_UPDATED_METHOD,
|
|
97
97
|
AGENT_MESSAGE_DELTA_METHOD,
|
|
@@ -114,6 +114,13 @@ import {
|
|
|
114
114
|
putPresignedFile,
|
|
115
115
|
recoverCompletedTurn
|
|
116
116
|
} from "./chunk-FLDA7BX3.js";
|
|
117
|
+
import {
|
|
118
|
+
RELAY_MCP_SERVER_NAME,
|
|
119
|
+
RELAY_MCP_TOOL_NAMES,
|
|
120
|
+
RELAY_MCP_TOOL_TIMEOUT_MS,
|
|
121
|
+
relayCodexMcpConfig,
|
|
122
|
+
relayMcpProcessConfig
|
|
123
|
+
} from "./chunk-JA23HN6S.js";
|
|
117
124
|
import {
|
|
118
125
|
BaseRefreshManager,
|
|
119
126
|
CodexAspAuthMethodChangedError,
|
|
@@ -124,20 +131,20 @@ import {
|
|
|
124
131
|
recordCredentialFallback,
|
|
125
132
|
recordExhaustedCredential,
|
|
126
133
|
restartCodexAspHost
|
|
127
|
-
} from "./chunk-
|
|
134
|
+
} from "./chunk-FN67CYNX.js";
|
|
128
135
|
import {
|
|
129
136
|
ENGINE_ENV,
|
|
130
137
|
IS_WARMING_MODE,
|
|
131
138
|
monolithRequest,
|
|
132
139
|
monolithService,
|
|
133
140
|
setAgentCredentialSnapshot
|
|
134
|
-
} from "./chunk-
|
|
141
|
+
} from "./chunk-JAITEGC4.js";
|
|
135
142
|
import {
|
|
136
143
|
AspClient,
|
|
137
144
|
SUBPROCESS_MAX_BUFFER,
|
|
138
145
|
execAsync,
|
|
139
146
|
execFileAsync
|
|
140
|
-
} from "./chunk-
|
|
147
|
+
} from "./chunk-EOYBI3PV.js";
|
|
141
148
|
import {
|
|
142
149
|
isRecord as isRecord2
|
|
143
150
|
} from "./chunk-UZSNFLDQ.js";
|
|
@@ -343,7 +350,7 @@ import {
|
|
|
343
350
|
spawnRelaySubagentRequestSchema,
|
|
344
351
|
stripAgentDiagnosticErrors,
|
|
345
352
|
withTimeout
|
|
346
|
-
} from "./chunk-
|
|
353
|
+
} from "./chunk-OCQQ6AO3.js";
|
|
347
354
|
import {
|
|
348
355
|
__commonJS,
|
|
349
356
|
__export,
|
|
@@ -8535,7 +8542,7 @@ var require_dist2 = __commonJS({
|
|
|
8535
8542
|
// src/index.ts
|
|
8536
8543
|
import { serve } from "@hono/node-server";
|
|
8537
8544
|
import { Hono as Hono2 } from "hono";
|
|
8538
|
-
import { existsSync as
|
|
8545
|
+
import { existsSync as existsSync20 } from "fs";
|
|
8539
8546
|
import { randomUUID as randomUUID15 } from "crypto";
|
|
8540
8547
|
import { connect } from "net";
|
|
8541
8548
|
|
|
@@ -10679,7 +10686,7 @@ async function registerDesktopPreview() {
|
|
|
10679
10686
|
|
|
10680
10687
|
// src/services/chat/chat-service.ts
|
|
10681
10688
|
import { appendFile as appendFile5, copyFile as copyFile2, mkdir as mkdir21, readFile as readFile22, rename as rename4, rm as rm4 } from "fs/promises";
|
|
10682
|
-
import { join as
|
|
10689
|
+
import { join as join36 } from "path";
|
|
10683
10690
|
import { randomUUID as randomUUID13 } from "crypto";
|
|
10684
10691
|
|
|
10685
10692
|
// ../shared/src/workspace-chat.ts
|
|
@@ -10856,7 +10863,7 @@ import {
|
|
|
10856
10863
|
query
|
|
10857
10864
|
} from "@anthropic-ai/claude-agent-sdk";
|
|
10858
10865
|
import { randomUUID as randomUUID5 } from "crypto";
|
|
10859
|
-
import { dirname as
|
|
10866
|
+
import { dirname as dirname4, join as join16 } from "path";
|
|
10860
10867
|
import { mkdir as mkdir10 } from "fs/promises";
|
|
10861
10868
|
import { homedir as homedir11 } from "os";
|
|
10862
10869
|
|
|
@@ -12581,40 +12588,6 @@ var ClaudeBackgroundTasks = class {
|
|
|
12581
12588
|
}
|
|
12582
12589
|
};
|
|
12583
12590
|
|
|
12584
|
-
// src/managers/relay-mcp-config.ts
|
|
12585
|
-
import { existsSync as existsSync7 } from "fs";
|
|
12586
|
-
import { dirname as dirname4, join as join16 } from "path";
|
|
12587
|
-
import { fileURLToPath } from "url";
|
|
12588
|
-
import { createRequire } from "module";
|
|
12589
|
-
var RELAY_MCP_TOOL_NAMES = ["get_providers", "spawn_agent", "message_agent", "delete_agent"];
|
|
12590
|
-
var RELAY_MCP_TOOL_TIMEOUT_MS = 24 * 60 * 60 * 1e3 + 6e4;
|
|
12591
|
-
function relayMcpProcessConfig(parentChatId) {
|
|
12592
|
-
const directory = dirname4(fileURLToPath(import.meta.url));
|
|
12593
|
-
const builtEntry = join16(directory, "relay-mcp.js");
|
|
12594
|
-
const sourceEntry = join16(directory, "..", "relay-mcp.ts");
|
|
12595
|
-
const entry = existsSync7(builtEntry) ? builtEntry : sourceEntry;
|
|
12596
|
-
return {
|
|
12597
|
-
command: process.execPath,
|
|
12598
|
-
args: [
|
|
12599
|
-
...entry.endsWith(".ts") ? ["--import", createRequire(import.meta.url).resolve("tsx/esm")] : [],
|
|
12600
|
-
entry,
|
|
12601
|
-
"--parent",
|
|
12602
|
-
parentChatId
|
|
12603
|
-
]
|
|
12604
|
-
};
|
|
12605
|
-
}
|
|
12606
|
-
function relayCodexMcpConfig(parentChatId) {
|
|
12607
|
-
return {
|
|
12608
|
-
...relayMcpProcessConfig(parentChatId),
|
|
12609
|
-
env_vars: ["REPLICAS_ENGINE_PORT", "REPLICAS_ENGINE_SECRET"],
|
|
12610
|
-
enabled_tools: [...RELAY_MCP_TOOL_NAMES],
|
|
12611
|
-
required: true,
|
|
12612
|
-
default_tools_approval_mode: "approve",
|
|
12613
|
-
startup_timeout_sec: 10,
|
|
12614
|
-
tool_timeout_sec: Math.ceil(RELAY_MCP_TOOL_TIMEOUT_MS / 1e3)
|
|
12615
|
-
};
|
|
12616
|
-
}
|
|
12617
|
-
|
|
12618
12591
|
// src/managers/claude-manager.ts
|
|
12619
12592
|
var PromptStream = class {
|
|
12620
12593
|
queue = [];
|
|
@@ -12878,7 +12851,7 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
|
|
|
12878
12851
|
authRetrying = false;
|
|
12879
12852
|
constructor(options) {
|
|
12880
12853
|
super({ ...options, provider: AGENT.CLAUDE });
|
|
12881
|
-
this.historyFilePath = options.historyFilePath ??
|
|
12854
|
+
this.historyFilePath = options.historyFilePath ?? join16(homedir11(), ".replicas", "claude", "history.jsonl");
|
|
12882
12855
|
this.historyFile = new CodexHistoryFile(this.historyFilePath);
|
|
12883
12856
|
this.initializeManager(this.processMessageInternal.bind(this));
|
|
12884
12857
|
}
|
|
@@ -13422,7 +13395,7 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
|
|
|
13422
13395
|
const interactiveAllowed = enableInteractiveTools && resolvedPermissionMode === "plan";
|
|
13423
13396
|
const allowedTools = [
|
|
13424
13397
|
...ALWAYS_ALLOWED_TOOLS.filter((tool) => !this.isRelay || tool !== "Agent"),
|
|
13425
|
-
...this.isRelay ? RELAY_MCP_TOOL_NAMES.map((tool) => `
|
|
13398
|
+
...this.isRelay ? RELAY_MCP_TOOL_NAMES.map((tool) => `mcp__${RELAY_MCP_SERVER_NAME}__${tool}`) : [],
|
|
13426
13399
|
...interactiveAllowed ? INTERACTIVE_TOOL_NAMES : []
|
|
13427
13400
|
];
|
|
13428
13401
|
const disallowedTools = [
|
|
@@ -13443,7 +13416,7 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
|
|
|
13443
13416
|
...disallowedTools.length > 0 ? { disallowedTools } : {},
|
|
13444
13417
|
settingSources: ["user", "project", "local"],
|
|
13445
13418
|
systemPrompt,
|
|
13446
|
-
...this.relayParentChatId ? { mcpServers: {
|
|
13419
|
+
...this.relayParentChatId ? { mcpServers: { [RELAY_MCP_SERVER_NAME]: { type: "stdio", alwaysLoad: true, ...relayMcpProcessConfig(this.relayParentChatId) } } } : {},
|
|
13447
13420
|
...shared.plugins.length > 0 ? { plugins: shared.plugins } : {},
|
|
13448
13421
|
...shared.enableAllSkills ? { skills: "all" } : {},
|
|
13449
13422
|
env: shared.env,
|
|
@@ -13991,7 +13964,7 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
|
|
|
13991
13964
|
}
|
|
13992
13965
|
}
|
|
13993
13966
|
async initialize() {
|
|
13994
|
-
await mkdir10(
|
|
13967
|
+
await mkdir10(dirname4(this.historyFilePath), { recursive: true });
|
|
13995
13968
|
if (this.initialSessionId) {
|
|
13996
13969
|
this.sessionId = this.initialSessionId;
|
|
13997
13970
|
console.log(`[ClaudeManager] Restored session ID from persisted state: ${this.sessionId}`);
|
|
@@ -14040,7 +14013,7 @@ var ClaudeManager = class _ClaudeManager extends CodingAgentManager {
|
|
|
14040
14013
|
|
|
14041
14014
|
// src/managers/codex-asp/codex-asp-manager.ts
|
|
14042
14015
|
import { readdir as readdir4 } from "fs/promises";
|
|
14043
|
-
import { join as
|
|
14016
|
+
import { join as join18 } from "path";
|
|
14044
14017
|
|
|
14045
14018
|
// src/utils/codex-quota.ts
|
|
14046
14019
|
function buildCodexRateLimitsSnapshot(fields) {
|
|
@@ -14104,7 +14077,7 @@ var CodexQuotaStatusTracker = class {
|
|
|
14104
14077
|
};
|
|
14105
14078
|
|
|
14106
14079
|
// src/managers/codex-asp/mappers.ts
|
|
14107
|
-
import { existsSync as
|
|
14080
|
+
import { existsSync as existsSync7, readFileSync as readFileSync3 } from "fs";
|
|
14108
14081
|
var localImageCache = /* @__PURE__ */ new Map();
|
|
14109
14082
|
var DEFAULT_MODEL = DEFAULT_CODEX_MODEL;
|
|
14110
14083
|
var THREAD_START_METHOD = "thread/start";
|
|
@@ -14228,7 +14201,7 @@ function transcriptItemsForTurn(turn) {
|
|
|
14228
14201
|
function userImageForLocalPath(path7) {
|
|
14229
14202
|
const cached = localImageCache.get(path7);
|
|
14230
14203
|
if (cached) return cached;
|
|
14231
|
-
if (!
|
|
14204
|
+
if (!existsSync7(path7)) return null;
|
|
14232
14205
|
const image = {
|
|
14233
14206
|
type: "image",
|
|
14234
14207
|
mediaType: inferMediaType(path7),
|
|
@@ -14607,7 +14580,7 @@ async function buildThreadStartParams(workingDirectory, request, developerInstru
|
|
|
14607
14580
|
model_reasoning_summary: "auto",
|
|
14608
14581
|
...relayParentChatId ? {
|
|
14609
14582
|
features: { multi_agent: false },
|
|
14610
|
-
|
|
14583
|
+
[`mcp_servers.${RELAY_MCP_SERVER_NAME}`]: relayCodexMcpConfig(relayParentChatId)
|
|
14611
14584
|
} : {}
|
|
14612
14585
|
},
|
|
14613
14586
|
experimentalRawEvents: false
|
|
@@ -14629,7 +14602,7 @@ async function buildThreadResumeParams(workingDirectory, threadId, request, deve
|
|
|
14629
14602
|
model_reasoning_summary: "auto",
|
|
14630
14603
|
...relayParentChatId ? {
|
|
14631
14604
|
features: { multi_agent: false },
|
|
14632
|
-
|
|
14605
|
+
[`mcp_servers.${RELAY_MCP_SERVER_NAME}`]: relayCodexMcpConfig(relayParentChatId)
|
|
14633
14606
|
} : {}
|
|
14634
14607
|
},
|
|
14635
14608
|
excludeTurns: false
|
|
@@ -14738,20 +14711,20 @@ var TranscriptUpdateCoalescer = class {
|
|
|
14738
14711
|
|
|
14739
14712
|
// src/services/chat/history-paths.ts
|
|
14740
14713
|
import { homedir as homedir12 } from "os";
|
|
14741
|
-
import { join as
|
|
14742
|
-
var ENGINE_DIR2 =
|
|
14743
|
-
var CHATS_FILE =
|
|
14744
|
-
var CLAUDE_HISTORY_DIR =
|
|
14745
|
-
var RELAY_HISTORY_DIR =
|
|
14746
|
-
var CODEX_HISTORY_DIR =
|
|
14747
|
-
var CURSOR_HISTORY_DIR =
|
|
14748
|
-
var OPENCODE_HISTORY_DIR =
|
|
14749
|
-
var PI_HISTORY_DIR =
|
|
14750
|
-
var DEEPSEEK_HISTORY_DIR =
|
|
14751
|
-
var FX_HISTORY_DIR =
|
|
14752
|
-
var KIMI_HISTORY_DIR =
|
|
14753
|
-
var MUSE_HISTORY_DIR =
|
|
14754
|
-
var FORKS_DIR =
|
|
14714
|
+
import { join as join17 } from "path";
|
|
14715
|
+
var ENGINE_DIR2 = join17(homedir12(), ".replicas", "engine");
|
|
14716
|
+
var CHATS_FILE = join17(ENGINE_DIR2, "chats.json");
|
|
14717
|
+
var CLAUDE_HISTORY_DIR = join17(ENGINE_DIR2, "claude-histories");
|
|
14718
|
+
var RELAY_HISTORY_DIR = join17(ENGINE_DIR2, "relay-histories");
|
|
14719
|
+
var CODEX_HISTORY_DIR = join17(ENGINE_DIR2, "codex-histories");
|
|
14720
|
+
var CURSOR_HISTORY_DIR = join17(ENGINE_DIR2, "cursor-histories");
|
|
14721
|
+
var OPENCODE_HISTORY_DIR = join17(ENGINE_DIR2, "opencode-histories");
|
|
14722
|
+
var PI_HISTORY_DIR = join17(ENGINE_DIR2, "pi-histories");
|
|
14723
|
+
var DEEPSEEK_HISTORY_DIR = join17(ENGINE_DIR2, "deepseek-histories");
|
|
14724
|
+
var FX_HISTORY_DIR = join17(ENGINE_DIR2, "fx-histories");
|
|
14725
|
+
var KIMI_HISTORY_DIR = join17(ENGINE_DIR2, "kimi-histories");
|
|
14726
|
+
var MUSE_HISTORY_DIR = join17(ENGINE_DIR2, "muse-histories");
|
|
14727
|
+
var FORKS_DIR = join17(ENGINE_DIR2, "forks");
|
|
14755
14728
|
var HISTORY_DIR_BY_PROVIDER = {
|
|
14756
14729
|
claude: CLAUDE_HISTORY_DIR,
|
|
14757
14730
|
relay: RELAY_HISTORY_DIR,
|
|
@@ -14824,7 +14797,7 @@ async function readCodexAspThreadHistory(threadId) {
|
|
|
14824
14797
|
}
|
|
14825
14798
|
for (const entry of entries) {
|
|
14826
14799
|
if (!entry.isFile() || !entry.name.endsWith(".jsonl") || entry.name.endsWith(".pages.jsonl")) continue;
|
|
14827
|
-
const history = await new CodexHistoryFile(
|
|
14800
|
+
const history = await new CodexHistoryFile(join18(CODEX_HISTORY_DIR, entry.name)).load();
|
|
14828
14801
|
const transcript = history.transcriptsByThreadId.get(threadId);
|
|
14829
14802
|
if (transcript) {
|
|
14830
14803
|
return {
|
|
@@ -15004,6 +14977,7 @@ var CodexAspManager = class extends CodingAgentManager {
|
|
|
15004
14977
|
}
|
|
15005
14978
|
async getHistory(page2 = {}) {
|
|
15006
14979
|
await this.initialized;
|
|
14980
|
+
this.transcriptUpdateCoalescer.flushPending();
|
|
15007
14981
|
await this.historyFile?.flush();
|
|
15008
14982
|
const transcript = await this.ensureTranscriptHistory();
|
|
15009
14983
|
const events = await this.historyFile?.loadEventsPage(page2) ?? { events: [], beforeCursor: null };
|
|
@@ -16230,24 +16204,24 @@ var CodexAspManager = class extends CodingAgentManager {
|
|
|
16230
16204
|
|
|
16231
16205
|
// src/managers/cursor-manager.ts
|
|
16232
16206
|
import { mkdir as mkdir12, readFile as readFile12, readdir as readdir5 } from "fs/promises";
|
|
16233
|
-
import { basename as basename2, dirname as
|
|
16207
|
+
import { basename as basename2, dirname as dirname6, extname, join as join20 } from "path";
|
|
16234
16208
|
import { parse as parseYaml } from "yaml";
|
|
16235
16209
|
import { Agent as CursorAgent2 } from "@cursor/sdk";
|
|
16236
16210
|
|
|
16237
16211
|
// src/services/native-command-protection-hooks.ts
|
|
16238
|
-
import { existsSync as
|
|
16212
|
+
import { existsSync as existsSync8 } from "fs";
|
|
16239
16213
|
import { mkdir as mkdir11, readFile as readFile11, writeFile as writeFile6 } from "fs/promises";
|
|
16240
|
-
import { basename, dirname as
|
|
16241
|
-
import { fileURLToPath
|
|
16242
|
-
var moduleDirectory =
|
|
16214
|
+
import { basename, dirname as dirname5, join as join19 } from "path";
|
|
16215
|
+
import { fileURLToPath } from "url";
|
|
16216
|
+
var moduleDirectory = dirname5(fileURLToPath(import.meta.url));
|
|
16243
16217
|
var hookPath = [
|
|
16244
|
-
|
|
16245
|
-
|
|
16246
|
-
].find(
|
|
16218
|
+
join19(moduleDirectory, "command-protection-hook.js"),
|
|
16219
|
+
join19(moduleDirectory, "..", "command-protection-hook.ts")
|
|
16220
|
+
].find(existsSync8);
|
|
16247
16221
|
var postToolHookPath = [
|
|
16248
|
-
|
|
16249
|
-
|
|
16250
|
-
].find(
|
|
16222
|
+
join19(moduleDirectory, "post-tool-pr-hook.js"),
|
|
16223
|
+
join19(moduleDirectory, "..", "post-tool-pr-hook.ts")
|
|
16224
|
+
].find(existsSync8);
|
|
16251
16225
|
function shellCommand(path7, provider) {
|
|
16252
16226
|
if (!path7) throw new Error("Replicas hook executable is missing.");
|
|
16253
16227
|
const args = [
|
|
@@ -16267,7 +16241,7 @@ function getPostToolPrHookPath() {
|
|
|
16267
16241
|
return postToolHookPath;
|
|
16268
16242
|
}
|
|
16269
16243
|
async function ensureCursorCommandProtectionHook() {
|
|
16270
|
-
const path7 =
|
|
16244
|
+
const path7 = join19(ENGINE_ENV.HOME_DIR, ".cursor", "hooks.json");
|
|
16271
16245
|
let config = {};
|
|
16272
16246
|
try {
|
|
16273
16247
|
const parsed = JSON.parse(await readFile11(path7, "utf8"));
|
|
@@ -16287,12 +16261,12 @@ async function ensureCursorCommandProtectionHook() {
|
|
|
16287
16261
|
...existingPost.filter((entry) => !isRecord2(entry) || typeof entry.command !== "string" || !entry.command.includes("post-tool-pr-hook")),
|
|
16288
16262
|
{ command: shellCommand(postToolHookPath) }
|
|
16289
16263
|
];
|
|
16290
|
-
await mkdir11(
|
|
16264
|
+
await mkdir11(dirname5(path7), { recursive: true });
|
|
16291
16265
|
await writeFile6(path7, `${JSON.stringify({ ...config, version: 1, hooks }, null, 2)}
|
|
16292
16266
|
`, "utf8");
|
|
16293
16267
|
}
|
|
16294
16268
|
async function ensureKimiCommandProtectionHook() {
|
|
16295
|
-
const path7 =
|
|
16269
|
+
const path7 = join19(ENGINE_ENV.HOME_DIR, ".kimi-code", "config.toml");
|
|
16296
16270
|
const start = "# Replicas command protection hook";
|
|
16297
16271
|
const end = "# End Replicas command protection hook";
|
|
16298
16272
|
let config = "";
|
|
@@ -16316,7 +16290,7 @@ ${end}`;
|
|
|
16316
16290
|
const markerEnd = config.indexOf(end, markerStart + start.length);
|
|
16317
16291
|
config = markerStart >= 0 && markerEnd >= 0 ? `${config.slice(0, markerStart)}${block}${config.slice(markerEnd + end.length)}` : `${config.trimEnd()}${config.trim() ? "\n\n" : ""}${block}
|
|
16318
16292
|
`;
|
|
16319
|
-
await mkdir11(
|
|
16293
|
+
await mkdir11(dirname5(path7), { recursive: true });
|
|
16320
16294
|
await writeFile6(path7, config, "utf8");
|
|
16321
16295
|
}
|
|
16322
16296
|
|
|
@@ -16401,7 +16375,7 @@ async function listCursorCommandsInDirectory(directory) {
|
|
|
16401
16375
|
const name = basename2(entry.name, ".md");
|
|
16402
16376
|
let description;
|
|
16403
16377
|
try {
|
|
16404
|
-
description = extractCursorCommandDescription(await readFile12(
|
|
16378
|
+
description = extractCursorCommandDescription(await readFile12(join20(directory, entry.name), "utf8"));
|
|
16405
16379
|
} catch (error) {
|
|
16406
16380
|
console.warn("[CursorManager] Failed to read slash command file:", error);
|
|
16407
16381
|
}
|
|
@@ -16423,12 +16397,12 @@ var CursorManager = class extends CodingAgentManager {
|
|
|
16423
16397
|
slashCommandsRequest = null;
|
|
16424
16398
|
constructor(options) {
|
|
16425
16399
|
super(options);
|
|
16426
|
-
this.historyFilePath = options.historyFilePath ??
|
|
16400
|
+
this.historyFilePath = options.historyFilePath ?? join20(ENGINE_ENV.HOME_DIR, ".replicas", "cursor", "history.jsonl");
|
|
16427
16401
|
this.historyFile = new CodexHistoryFile(this.historyFilePath);
|
|
16428
16402
|
this.initializeManager(this.processMessageInternal.bind(this));
|
|
16429
16403
|
}
|
|
16430
16404
|
async initialize() {
|
|
16431
|
-
await mkdir12(
|
|
16405
|
+
await mkdir12(dirname6(this.historyFilePath), { recursive: true });
|
|
16432
16406
|
await ensureCursorCommandProtectionHook();
|
|
16433
16407
|
}
|
|
16434
16408
|
getHistorySink() {
|
|
@@ -16498,7 +16472,7 @@ var CursorManager = class extends CodingAgentManager {
|
|
|
16498
16472
|
this.slashCommandsRequest ??= (async () => {
|
|
16499
16473
|
try {
|
|
16500
16474
|
const repoDirectories = await getAgentAdditionalDirectories();
|
|
16501
|
-
const commandDirectories = [this.workingDirectory, ...repoDirectories, ENGINE_ENV.HOME_DIR].map((directory) =>
|
|
16475
|
+
const commandDirectories = [this.workingDirectory, ...repoDirectories, ENGINE_ENV.HOME_DIR].map((directory) => join20(directory, ".cursor", "commands"));
|
|
16502
16476
|
const commands = mergeSlashCommands(
|
|
16503
16477
|
...await Promise.all(commandDirectories.map(listCursorCommandsInDirectory))
|
|
16504
16478
|
);
|
|
@@ -16778,10 +16752,10 @@ ${instructions}
|
|
|
16778
16752
|
// src/managers/deepseek-manager.ts
|
|
16779
16753
|
import { spawn as spawn3 } from "child_process";
|
|
16780
16754
|
import { createHash as createHash2, randomUUID as randomUUID6 } from "crypto";
|
|
16781
|
-
import { createRequire
|
|
16782
|
-
import { basename as basename3, dirname as
|
|
16783
|
-
import { fileURLToPath as
|
|
16784
|
-
import { existsSync as
|
|
16755
|
+
import { createRequire } from "module";
|
|
16756
|
+
import { basename as basename3, dirname as dirname7, join as join21 } from "path";
|
|
16757
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
16758
|
+
import { existsSync as existsSync9 } from "fs";
|
|
16785
16759
|
import { mkdir as mkdir13, readFile as readFile13, rename as rename2, writeFile as writeFile7 } from "fs/promises";
|
|
16786
16760
|
import { z as z2 } from "zod";
|
|
16787
16761
|
import WebSocket from "ws";
|
|
@@ -16793,18 +16767,18 @@ var questionSelectionSchema = z2.record(z2.string(), z2.object({
|
|
|
16793
16767
|
options: z2.array(z2.string()).optional(),
|
|
16794
16768
|
custom: z2.string().optional()
|
|
16795
16769
|
}));
|
|
16796
|
-
var require2 =
|
|
16797
|
-
var DSH_BIN =
|
|
16798
|
-
var MANAGER_DIR =
|
|
16770
|
+
var require2 = createRequire(import.meta.url);
|
|
16771
|
+
var DSH_BIN = join21(dirname7(require2.resolve("@deepseek-ai/dsh/package.json")), "lib", "bin.js");
|
|
16772
|
+
var MANAGER_DIR = dirname7(fileURLToPath2(import.meta.url));
|
|
16799
16773
|
var DSH_PATCH = [
|
|
16800
|
-
|
|
16801
|
-
|
|
16802
|
-
].find(
|
|
16774
|
+
join21(MANAGER_DIR, "..", "..", "scripts", "deepseek", "replicas.cordis.patch.yml"),
|
|
16775
|
+
join21(MANAGER_DIR, "..", "..", "..", "scripts", "deepseek", "replicas.cordis.patch.yml")
|
|
16776
|
+
].find(existsSync9) ?? "";
|
|
16803
16777
|
var DSH_COMMAND_PROTECTION_PLUGIN = [
|
|
16804
|
-
|
|
16805
|
-
|
|
16806
|
-
].find(
|
|
16807
|
-
var DEEPSEEK_HOME =
|
|
16778
|
+
join21(MANAGER_DIR, "deepseek-command-protection-plugin.js"),
|
|
16779
|
+
join21(MANAGER_DIR, "..", "deepseek-command-protection-plugin.ts")
|
|
16780
|
+
].find(existsSync9) ?? "";
|
|
16781
|
+
var DEEPSEEK_HOME = join21(ENGINE_ENV.HOME_DIR, ".replicas", "deepseek");
|
|
16808
16782
|
function relayPresetContent(content, instructions, mcp) {
|
|
16809
16783
|
const personaMarker = " text: >-\n";
|
|
16810
16784
|
const personaStart = content.indexOf(personaMarker);
|
|
@@ -16821,10 +16795,10 @@ ${indentedInstructions}${content.slice(personaEnd)}`.replace(delegationMarker, `
|
|
|
16821
16795
|
if (!mcp) return relayContent;
|
|
16822
16796
|
return `${relayContent}
|
|
16823
16797
|
|
|
16824
|
-
- id:
|
|
16798
|
+
- id: subagent-relay-mcp
|
|
16825
16799
|
name: '@deepseek-ai/dsh-mcp-client'
|
|
16826
16800
|
config:
|
|
16827
|
-
serverName:
|
|
16801
|
+
serverName: ${RELAY_MCP_SERVER_NAME}
|
|
16828
16802
|
transport: stdio
|
|
16829
16803
|
command: ${JSON.stringify(mcp.command)}
|
|
16830
16804
|
args: ${JSON.stringify(mcp.args)}
|
|
@@ -16949,13 +16923,13 @@ var DeepseekManager = class extends CodingAgentManager {
|
|
|
16949
16923
|
constructor(options) {
|
|
16950
16924
|
super(options);
|
|
16951
16925
|
this.sessionId = options.initialSessionId ? sessionIdSchema.parse(options.initialSessionId) : null;
|
|
16952
|
-
this.historyFilePath = options.historyFilePath ??
|
|
16953
|
-
this.deepseekHome = this.isRelay ?
|
|
16926
|
+
this.historyFilePath = options.historyFilePath ?? join21(ENGINE_ENV.HOME_DIR, ".replicas", "deepseek", "history.jsonl");
|
|
16927
|
+
this.deepseekHome = this.isRelay ? join21(ENGINE_ENV.HOME_DIR, ".replicas", "deepseek-relay", basename3(this.historyFilePath, ".jsonl")) : DEEPSEEK_HOME;
|
|
16954
16928
|
this.historyFile = new CodexHistoryFile(this.historyFilePath);
|
|
16955
16929
|
this.initializeManager(this.processMessageInternal.bind(this));
|
|
16956
16930
|
}
|
|
16957
16931
|
async initialize() {
|
|
16958
|
-
await mkdir13(
|
|
16932
|
+
await mkdir13(dirname7(this.historyFilePath), { recursive: true });
|
|
16959
16933
|
}
|
|
16960
16934
|
getHistorySink() {
|
|
16961
16935
|
return this.historyFile;
|
|
@@ -17029,8 +17003,8 @@ var DeepseekManager = class extends CodingAgentManager {
|
|
|
17029
17003
|
async ensureClient() {
|
|
17030
17004
|
if (this.client) return this.client;
|
|
17031
17005
|
if (!DSH_PATCH || !DSH_COMMAND_PROTECTION_PLUGIN) throw new Error("DeepSeek Harness configuration is missing from the engine package.");
|
|
17032
|
-
const runtimePatch =
|
|
17033
|
-
await mkdir13(
|
|
17006
|
+
const runtimePatch = join21(this.deepseekHome, "replicas.cordis.patch.yml");
|
|
17007
|
+
await mkdir13(dirname7(runtimePatch), { recursive: true });
|
|
17034
17008
|
await writeFile7(runtimePatch, (await readFile13(DSH_PATCH, "utf8")).replace(
|
|
17035
17009
|
"__REPLICAS_DSH_COMMAND_PROTECTION_PLUGIN__",
|
|
17036
17010
|
JSON.stringify(DSH_COMMAND_PROTECTION_PLUGIN)
|
|
@@ -17104,10 +17078,10 @@ var DeepseekManager = class extends CodingAgentManager {
|
|
|
17104
17078
|
if (!roster.some((preset) => preset.id === agentPreset)) {
|
|
17105
17079
|
const stage = `relay-stage-${randomUUID6().replaceAll("-", "")}`;
|
|
17106
17080
|
unwrap(await client2.agentPresets.copy({ from: "standard", agentPreset: stage, name: "Relay" }));
|
|
17107
|
-
const stageDirectory =
|
|
17081
|
+
const stageDirectory = join21(this.deepseekHome, ".agent-presets", stage);
|
|
17108
17082
|
try {
|
|
17109
|
-
await writeFile7(
|
|
17110
|
-
await rename2(stageDirectory,
|
|
17083
|
+
await writeFile7(join21(stageDirectory, "agent.cordis.yml"), content, "utf8");
|
|
17084
|
+
await rename2(stageDirectory, join21(this.deepseekHome, ".agent-presets", agentPreset));
|
|
17111
17085
|
} catch (error) {
|
|
17112
17086
|
unwrap(await client2.agentPresets.remove({ agentPreset: stage }));
|
|
17113
17087
|
if (!unwrap(await client2.agentPresets.list({})).presets.some((preset) => preset.id === agentPreset)) throw error;
|
|
@@ -17288,7 +17262,7 @@ import { spawn as spawn5 } from "child_process";
|
|
|
17288
17262
|
import { spawn as spawn4 } from "child_process";
|
|
17289
17263
|
import { randomUUID as randomUUID7 } from "crypto";
|
|
17290
17264
|
import { mkdir as mkdir14, readFile as readFile14, writeFile as writeFile8 } from "fs/promises";
|
|
17291
|
-
import { dirname as
|
|
17265
|
+
import { dirname as dirname8 } from "path";
|
|
17292
17266
|
import { Writable } from "stream";
|
|
17293
17267
|
import {
|
|
17294
17268
|
PROTOCOL_VERSION,
|
|
@@ -17328,7 +17302,7 @@ var AcpManager = class extends CodingAgentManager {
|
|
|
17328
17302
|
this.initializeManager(this.processMessageInternal.bind(this));
|
|
17329
17303
|
}
|
|
17330
17304
|
async initialize() {
|
|
17331
|
-
await mkdir14(
|
|
17305
|
+
await mkdir14(dirname8(this.historyFilePath), { recursive: true });
|
|
17332
17306
|
await this.acp.prepare?.();
|
|
17333
17307
|
}
|
|
17334
17308
|
getHistorySink() {
|
|
@@ -17823,7 +17797,7 @@ var KimiManager = class extends AcpManager {
|
|
|
17823
17797
|
import { spawn as spawn6 } from "child_process";
|
|
17824
17798
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
17825
17799
|
import { mkdir as mkdir15 } from "fs/promises";
|
|
17826
|
-
import { dirname as
|
|
17800
|
+
import { dirname as dirname9 } from "path";
|
|
17827
17801
|
var MuseQuotaError = class extends Error {
|
|
17828
17802
|
};
|
|
17829
17803
|
function uuidV7() {
|
|
@@ -17864,7 +17838,7 @@ var MuseManager = class extends CodingAgentManager {
|
|
|
17864
17838
|
this.initializeManager(this.processMessageInternal.bind(this));
|
|
17865
17839
|
}
|
|
17866
17840
|
async initialize() {
|
|
17867
|
-
await mkdir15(
|
|
17841
|
+
await mkdir15(dirname9(this.historyFilePath), { recursive: true });
|
|
17868
17842
|
}
|
|
17869
17843
|
getHistorySink() {
|
|
17870
17844
|
return this.historyFile;
|
|
@@ -18333,11 +18307,11 @@ ${pending}
|
|
|
18333
18307
|
};
|
|
18334
18308
|
|
|
18335
18309
|
// src/managers/opencode-manager.ts
|
|
18336
|
-
import { existsSync as
|
|
18310
|
+
import { existsSync as existsSync10 } from "fs";
|
|
18337
18311
|
import { copyFile, mkdir as mkdir16, readFile as readFile16, rm as rm2 } from "fs/promises";
|
|
18338
|
-
import { delimiter, dirname as
|
|
18312
|
+
import { delimiter, dirname as dirname10, join as join22 } from "path";
|
|
18339
18313
|
import { randomBytes as randomBytes3 } from "crypto";
|
|
18340
|
-
import { fileURLToPath as
|
|
18314
|
+
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
18341
18315
|
import { Agent } from "undici";
|
|
18342
18316
|
import { z as z3 } from "zod";
|
|
18343
18317
|
import {
|
|
@@ -18363,11 +18337,11 @@ async function getAllowedOpenRouterModels() {
|
|
|
18363
18337
|
}
|
|
18364
18338
|
|
|
18365
18339
|
// src/managers/opencode-manager.ts
|
|
18366
|
-
var OPENCODE_SHIM_DIR =
|
|
18367
|
-
var OPENCODE_COMMAND_PROTECTION_PLUGIN_SOURCE =
|
|
18368
|
-
var OPENCODE_COMMAND_PROTECTION_PLUGIN_PATH =
|
|
18369
|
-
var OPENCODE_LEGACY_COMMAND_PROTECTION_PLUGIN_PATH =
|
|
18370
|
-
var OPENCODE_CONFIG_PATH =
|
|
18340
|
+
var OPENCODE_SHIM_DIR = dirname10(fileURLToPath3(new URL("../../scripts/opencode", import.meta.url)));
|
|
18341
|
+
var OPENCODE_COMMAND_PROTECTION_PLUGIN_SOURCE = join22(OPENCODE_SHIM_DIR, "opencode-command-protection-plugin.ts");
|
|
18342
|
+
var OPENCODE_COMMAND_PROTECTION_PLUGIN_PATH = join22(ENGINE_ENV.HOME_DIR, ".config", "opencode", "plugins", "replicas-command-protection.ts");
|
|
18343
|
+
var OPENCODE_LEGACY_COMMAND_PROTECTION_PLUGIN_PATH = join22(ENGINE_ENV.HOME_DIR, ".config", "opencode", "plugins", "replicas-command-protection.mjs");
|
|
18344
|
+
var OPENCODE_CONFIG_PATH = join22(ENGINE_ENV.HOME_DIR, ".config", "opencode", "opencode.json");
|
|
18371
18345
|
var OPENCODE_FETCH_DISPATCHER = new Agent({ headersTimeout: 0, bodyTimeout: 0 });
|
|
18372
18346
|
var OPENCODE_SERVER_STARTUP_TIMEOUT_MS = 3e4;
|
|
18373
18347
|
var OPENCODE_WORKSPACE_PERMISSION = "allow";
|
|
@@ -18386,7 +18360,7 @@ var opencodeAuthSchema = z3.record(z3.string(), z3.object({
|
|
|
18386
18360
|
key: z3.string().optional()
|
|
18387
18361
|
}));
|
|
18388
18362
|
async function hasOpencodeCredentials(provider) {
|
|
18389
|
-
if (!
|
|
18363
|
+
if (!existsSync10(OPENCODE_AUTH_PATH)) return false;
|
|
18390
18364
|
try {
|
|
18391
18365
|
const auth2 = opencodeAuthSchema.safeParse(JSON.parse(await readFile16(OPENCODE_AUTH_PATH, "utf8")));
|
|
18392
18366
|
return auth2.success && auth2.data[provider]?.type === "api" && Boolean(auth2.data[provider]?.key);
|
|
@@ -18579,12 +18553,12 @@ var OpencodeManager = class extends CodingAgentManager {
|
|
|
18579
18553
|
constructor(options) {
|
|
18580
18554
|
super({ ...options, provider: "opencode" });
|
|
18581
18555
|
this.sessionId = options.initialSessionId;
|
|
18582
|
-
this.historyFilePath = options.historyFilePath ??
|
|
18556
|
+
this.historyFilePath = options.historyFilePath ?? join22(ENGINE_ENV.HOME_DIR, ".replicas", "opencode", "history.jsonl");
|
|
18583
18557
|
this.historyFile = new CodexHistoryFile(this.historyFilePath);
|
|
18584
18558
|
this.initializeManager(this.processMessageInternal.bind(this));
|
|
18585
18559
|
}
|
|
18586
18560
|
async initialize() {
|
|
18587
|
-
await mkdir16(
|
|
18561
|
+
await mkdir16(dirname10(this.historyFilePath), { recursive: true });
|
|
18588
18562
|
}
|
|
18589
18563
|
getHistorySink() {
|
|
18590
18564
|
return this.historyFile;
|
|
@@ -18681,10 +18655,10 @@ var OpencodeManager = class extends CodingAgentManager {
|
|
|
18681
18655
|
if (!await hasOpencodeCredentials(providerId)) {
|
|
18682
18656
|
throw new Error("OpenCode Go, Aster, or OpenRouter credentials are not configured for Opencode in this workspace.");
|
|
18683
18657
|
}
|
|
18684
|
-
if (!
|
|
18658
|
+
if (!existsSync10(OPENCODE_COMMAND_PROTECTION_PLUGIN_SOURCE)) {
|
|
18685
18659
|
throw new Error("Opencode command protection plugin is missing from the engine package.");
|
|
18686
18660
|
}
|
|
18687
|
-
await mkdir16(
|
|
18661
|
+
await mkdir16(dirname10(OPENCODE_COMMAND_PROTECTION_PLUGIN_PATH), { recursive: true });
|
|
18688
18662
|
await copyFile(OPENCODE_COMMAND_PROTECTION_PLUGIN_SOURCE, OPENCODE_COMMAND_PROTECTION_PLUGIN_PATH);
|
|
18689
18663
|
await rm2(OPENCODE_LEGACY_COMMAND_PROTECTION_PLUGIN_PATH, { force: true });
|
|
18690
18664
|
process.env.REPLICAS_COMMAND_PROTECTION_HOOK_PATH = getCommandProtectionHookPath();
|
|
@@ -18705,7 +18679,7 @@ var OpencodeManager = class extends CodingAgentManager {
|
|
|
18705
18679
|
const relay = relayMcpProcessConfig(this.relayParentChatId);
|
|
18706
18680
|
config.mcp = {
|
|
18707
18681
|
...config.mcp,
|
|
18708
|
-
|
|
18682
|
+
[RELAY_MCP_SERVER_NAME]: {
|
|
18709
18683
|
type: "local",
|
|
18710
18684
|
command: [relay.command, ...relay.args],
|
|
18711
18685
|
enabled: true,
|
|
@@ -19000,7 +18974,7 @@ var OpencodeManager = class extends CodingAgentManager {
|
|
|
19000
18974
|
|
|
19001
18975
|
// src/managers/pi-manager.ts
|
|
19002
18976
|
import { mkdir as mkdir18, readFile as readFile17 } from "fs/promises";
|
|
19003
|
-
import { dirname as
|
|
18977
|
+
import { dirname as dirname18, join as join29 } from "path";
|
|
19004
18978
|
import {
|
|
19005
18979
|
createAgentSession,
|
|
19006
18980
|
ModelRegistry,
|
|
@@ -23598,7 +23572,7 @@ __export(typebox_exports, {
|
|
|
23598
23572
|
});
|
|
23599
23573
|
|
|
23600
23574
|
// ../node_modules/.bun/pi-mcp-adapter@2.32.1+04b0d7b0bc944965/node_modules/pi-mcp-adapter/init.ts
|
|
23601
|
-
import { existsSync as
|
|
23575
|
+
import { existsSync as existsSync13 } from "fs";
|
|
23602
23576
|
|
|
23603
23577
|
// ../node_modules/.bun/pi-mcp-adapter@2.32.1+04b0d7b0bc944965/node_modules/pi-mcp-adapter/errors.ts
|
|
23604
23578
|
var McpUiError = class extends Error {
|
|
@@ -41538,8 +41512,8 @@ async function probeMcpEndpoint(url3) {
|
|
|
41538
41512
|
}
|
|
41539
41513
|
|
|
41540
41514
|
// ../node_modules/.bun/pi-mcp-adapter@2.32.1+04b0d7b0bc944965/node_modules/pi-mcp-adapter/npx-resolver.ts
|
|
41541
|
-
import { existsSync as
|
|
41542
|
-
import { join as
|
|
41515
|
+
import { existsSync as existsSync11, readFileSync as readFileSync4, realpathSync, readdirSync, statSync, writeFileSync, renameSync, mkdirSync, openSync, readSync, closeSync, unlinkSync } from "fs";
|
|
41516
|
+
import { join as join23, dirname as dirname11, extname as extname2, resolve as resolve2, sep } from "path";
|
|
41543
41517
|
|
|
41544
41518
|
// ../node_modules/.bun/pi-mcp-adapter@2.32.1+04b0d7b0bc944965/node_modules/pi-mcp-adapter/abort.ts
|
|
41545
41519
|
function throwIfAborted(signal) {
|
|
@@ -41589,7 +41563,7 @@ async function resolveNpxBinary(command, args, signal) {
|
|
|
41589
41563
|
const cacheKey = JSON.stringify([command, parsed.packageSpec, parsed.binName ?? ""]);
|
|
41590
41564
|
const cache2 = loadCache();
|
|
41591
41565
|
const cached = cache2?.entries?.[cacheKey];
|
|
41592
|
-
if (cached && Date.now() - cached.resolvedAt < CACHE_TTL_MS &&
|
|
41566
|
+
if (cached && Date.now() - cached.resolvedAt < CACHE_TTL_MS && existsSync11(cached.resolvedBin) && (!packageSpec?.exactVersion || cached.packageVersion === packageSpec.exactVersion)) {
|
|
41593
41567
|
return { binPath: cached.resolvedBin, extraArgs: parsed.extraArgs, isJs: cached.isJs };
|
|
41594
41568
|
}
|
|
41595
41569
|
const resolved = resolveFromNpmCache(parsed.packageSpec, parsed.binName);
|
|
@@ -41696,8 +41670,8 @@ function resolveFromNpmCache(packageSpec, binName) {
|
|
|
41696
41670
|
const { packageName, exactVersion } = parsedSpec;
|
|
41697
41671
|
const packageDir = findCachedPackageDir(cacheDir, packageName, exactVersion);
|
|
41698
41672
|
if (!packageDir) return null;
|
|
41699
|
-
const packageJsonPath =
|
|
41700
|
-
if (!
|
|
41673
|
+
const packageJsonPath = join23(packageDir, "package.json");
|
|
41674
|
+
if (!existsSync11(packageJsonPath)) return null;
|
|
41701
41675
|
let pkg = null;
|
|
41702
41676
|
try {
|
|
41703
41677
|
pkg = JSON.parse(readFileSync4(packageJsonPath, "utf-8"));
|
|
@@ -41730,11 +41704,11 @@ function resolveFromNpmCache(packageSpec, binName) {
|
|
|
41730
41704
|
}
|
|
41731
41705
|
if (!binRel) return null;
|
|
41732
41706
|
const nodeModulesDir = findNodeModulesDir(packageDir);
|
|
41733
|
-
const binLink = chosenBinName ?
|
|
41734
|
-
let resolvedBin = binLink &&
|
|
41707
|
+
const binLink = chosenBinName ? join23(nodeModulesDir, ".bin", chosenBinName) : null;
|
|
41708
|
+
let resolvedBin = binLink && existsSync11(binLink) ? safeRealpath(binLink) : "";
|
|
41735
41709
|
if (!resolvedBin) {
|
|
41736
41710
|
resolvedBin = resolve2(packageDir, binRel);
|
|
41737
|
-
if (!
|
|
41711
|
+
if (!existsSync11(resolvedBin)) return null;
|
|
41738
41712
|
}
|
|
41739
41713
|
const isJs = detectJsBinary(resolvedBin);
|
|
41740
41714
|
return {
|
|
@@ -41832,18 +41806,18 @@ function defaultBinName(packageName) {
|
|
|
41832
41806
|
return packageName;
|
|
41833
41807
|
}
|
|
41834
41808
|
function findCachedPackageDir(cacheDir, packageName, exactVersion) {
|
|
41835
|
-
const npxDir =
|
|
41836
|
-
if (!
|
|
41809
|
+
const npxDir = join23(cacheDir, "_npx");
|
|
41810
|
+
if (!existsSync11(npxDir)) return null;
|
|
41837
41811
|
const packagePathParts = packageName.startsWith("@") ? packageName.split("/") : [packageName];
|
|
41838
41812
|
const candidates = readdirSync(npxDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => {
|
|
41839
|
-
const full =
|
|
41813
|
+
const full = join23(npxDir, entry.name);
|
|
41840
41814
|
const mtime = safeStatMtime(full);
|
|
41841
41815
|
return { name: entry.name, mtime };
|
|
41842
41816
|
}).sort((a, b) => b.mtime - a.mtime);
|
|
41843
41817
|
for (const entry of candidates) {
|
|
41844
|
-
const pkgDir =
|
|
41845
|
-
const packageJsonPath =
|
|
41846
|
-
if (!
|
|
41818
|
+
const pkgDir = join23(npxDir, entry.name, "node_modules", ...packagePathParts);
|
|
41819
|
+
const packageJsonPath = join23(pkgDir, "package.json");
|
|
41820
|
+
if (!existsSync11(packageJsonPath)) continue;
|
|
41847
41821
|
if (exactVersion) {
|
|
41848
41822
|
try {
|
|
41849
41823
|
const pkg = JSON.parse(readFileSync4(packageJsonPath, "utf-8"));
|
|
@@ -41862,7 +41836,7 @@ function findNodeModulesDir(packageDir) {
|
|
|
41862
41836
|
if (idx >= 0) {
|
|
41863
41837
|
return parts.slice(0, idx + 1).join(sep);
|
|
41864
41838
|
}
|
|
41865
|
-
return
|
|
41839
|
+
return join23(packageDir, "..");
|
|
41866
41840
|
}
|
|
41867
41841
|
function detectJsBinary(binPath) {
|
|
41868
41842
|
const ext = extname2(binPath).toLowerCase();
|
|
@@ -41906,7 +41880,7 @@ function getNpxCachePath() {
|
|
|
41906
41880
|
return getAgentPath("mcp-npx-cache.json");
|
|
41907
41881
|
}
|
|
41908
41882
|
function readNpxCachePayload(cachePath) {
|
|
41909
|
-
if (!
|
|
41883
|
+
if (!existsSync11(cachePath)) return null;
|
|
41910
41884
|
try {
|
|
41911
41885
|
return JSON.parse(readFileSync4(cachePath, "utf-8"));
|
|
41912
41886
|
} catch {
|
|
@@ -41967,7 +41941,7 @@ function loadCache() {
|
|
|
41967
41941
|
function saveCacheEntry(key, entry) {
|
|
41968
41942
|
try {
|
|
41969
41943
|
const cachePath = getNpxCachePath();
|
|
41970
|
-
const dir =
|
|
41944
|
+
const dir = dirname11(cachePath);
|
|
41971
41945
|
mkdirSync(dir, { recursive: true });
|
|
41972
41946
|
const existing = toNpxCache(readNpxCachePayload(cachePath));
|
|
41973
41947
|
const entries = createCacheEntries();
|
|
@@ -42052,11 +42026,11 @@ function createJsonSchemaValidator() {
|
|
|
42052
42026
|
// ../node_modules/.bun/pi-mcp-adapter@2.32.1+04b0d7b0bc944965/node_modules/pi-mcp-adapter/mcp-auth.ts
|
|
42053
42027
|
import { spawnSync } from "child_process";
|
|
42054
42028
|
import { createHash as createHash3 } from "crypto";
|
|
42055
|
-
import { createRequire as
|
|
42056
|
-
import { readFileSync as readFileSync5, existsSync as
|
|
42057
|
-
import { dirname as
|
|
42058
|
-
import { fileURLToPath as
|
|
42059
|
-
var require3 =
|
|
42029
|
+
import { createRequire as createRequire2 } from "module";
|
|
42030
|
+
import { readFileSync as readFileSync5, existsSync as existsSync12, rmSync } from "fs";
|
|
42031
|
+
import { dirname as dirname12, join as join24 } from "path";
|
|
42032
|
+
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
42033
|
+
var require3 = createRequire2(import.meta.url);
|
|
42060
42034
|
var AUTH_SECRET_SERVICE = "pi-mcp-adapter.oauth";
|
|
42061
42035
|
var TEST_AUTH_STORE_ENV = "PI_MCP_ADAPTER_TEST_AUTH_STORE";
|
|
42062
42036
|
var AUTH_SECRET_CHUNK_SIZE = 1e3;
|
|
@@ -42210,7 +42184,7 @@ function loadKeyringNativeBindingFallback(keyringRequire, platform3, arch2) {
|
|
|
42210
42184
|
for (const target of targets) {
|
|
42211
42185
|
try {
|
|
42212
42186
|
const packageJsonPath = keyringRequire.resolve(`${target.packageName}/package.json`);
|
|
42213
|
-
return keyringRequire(
|
|
42187
|
+
return keyringRequire(join24(dirname12(packageJsonPath), target.bindingFile));
|
|
42214
42188
|
} catch (error) {
|
|
42215
42189
|
lastError = error;
|
|
42216
42190
|
}
|
|
@@ -42255,7 +42229,7 @@ function shouldAttemptLinuxKeyringRecovery(error) {
|
|
|
42255
42229
|
function runLinuxKeyringRecoveryOperation(operation, account, payload) {
|
|
42256
42230
|
const keyctl = process.env[KEYRING_RECOVERY_KEYCTL_ENV]?.trim() || "keyctl";
|
|
42257
42231
|
const node = process.env[KEYRING_RECOVERY_NODE_ENV]?.trim() || "node";
|
|
42258
|
-
const helper = process.env[KEYRING_RECOVERY_HELPER_ENV]?.trim() ||
|
|
42232
|
+
const helper = process.env[KEYRING_RECOVERY_HELPER_ENV]?.trim() || fileURLToPath4(new URL("./mcp-keyring-helper.cjs", import.meta.url));
|
|
42259
42233
|
const request = JSON.stringify({ operation, service: AUTH_SECRET_SERVICE, account, payload });
|
|
42260
42234
|
const result = spawnSync(keyctl, ["session", "-", node, helper], {
|
|
42261
42235
|
input: `${request}
|
|
@@ -42315,7 +42289,7 @@ function getServerDir(serverName, options) {
|
|
|
42315
42289
|
throw new Error(`Invalid MCP server name: ${JSON.stringify(serverName)}`);
|
|
42316
42290
|
}
|
|
42317
42291
|
const storageKey = getAuthEntryAccount(serverName);
|
|
42318
|
-
return
|
|
42292
|
+
return join24(getAuthBaseDir(options), storageKey);
|
|
42319
42293
|
}
|
|
42320
42294
|
function getAuthEntryAccount(serverName) {
|
|
42321
42295
|
if (typeof serverName !== "string") {
|
|
@@ -42324,7 +42298,7 @@ function getAuthEntryAccount(serverName) {
|
|
|
42324
42298
|
return `sha256-${createHash3("sha256").update(serverName, "utf8").digest("hex")}`;
|
|
42325
42299
|
}
|
|
42326
42300
|
function getAuthEntryFilePath(serverName, options) {
|
|
42327
|
-
return
|
|
42301
|
+
return join24(getServerDir(serverName, options), "tokens.json");
|
|
42328
42302
|
}
|
|
42329
42303
|
function parseJsonPayload(serverName, payload, source) {
|
|
42330
42304
|
try {
|
|
@@ -42473,13 +42447,13 @@ function readChunkedAuthEntry(store, serverName, account, manifest) {
|
|
|
42473
42447
|
}
|
|
42474
42448
|
function readLegacyAuthEntry(serverName, options) {
|
|
42475
42449
|
const filePath = getAuthEntryFilePath(serverName, options);
|
|
42476
|
-
if (!
|
|
42450
|
+
if (!existsSync12(filePath)) return void 0;
|
|
42477
42451
|
const data = readFileSync5(filePath, "utf-8");
|
|
42478
42452
|
return parseAuthEntryPayload(serverName, data, filePath);
|
|
42479
42453
|
}
|
|
42480
42454
|
function removeLegacyAuthEntry(serverName, options) {
|
|
42481
42455
|
const filePath = getAuthEntryFilePath(serverName, options);
|
|
42482
|
-
if (!
|
|
42456
|
+
if (!existsSync12(filePath)) return;
|
|
42483
42457
|
try {
|
|
42484
42458
|
rmSync(filePath, { force: true });
|
|
42485
42459
|
} catch (error) {
|
|
@@ -43249,7 +43223,7 @@ var McpOAuthProvider = class {
|
|
|
43249
43223
|
import process9 from "process";
|
|
43250
43224
|
import { Buffer as Buffer2 } from "buffer";
|
|
43251
43225
|
import path5 from "path";
|
|
43252
|
-
import { fileURLToPath as
|
|
43226
|
+
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
43253
43227
|
import { promisify as promisify5 } from "util";
|
|
43254
43228
|
import childProcess from "child_process";
|
|
43255
43229
|
import fs6, { constants as fsConstants2 } from "fs/promises";
|
|
@@ -43506,7 +43480,7 @@ async function defaultBrowser2() {
|
|
|
43506
43480
|
|
|
43507
43481
|
// ../node_modules/.bun/open@10.2.0/node_modules/open/index.js
|
|
43508
43482
|
var execFile5 = promisify5(childProcess.execFile);
|
|
43509
|
-
var __dirname = path5.dirname(
|
|
43483
|
+
var __dirname = path5.dirname(fileURLToPath5(import.meta.url));
|
|
43510
43484
|
var localXdgOpenPath = path5.join(__dirname, "xdg-open");
|
|
43511
43485
|
var { platform, arch } = process9;
|
|
43512
43486
|
async function getWindowsDefaultBrowserFromWsl() {
|
|
@@ -44926,9 +44900,9 @@ async function shutdownOAuth(runtime = legacyRuntime) {
|
|
|
44926
44900
|
|
|
44927
44901
|
// ../node_modules/.bun/pi-mcp-adapter@2.32.1+04b0d7b0bc944965/node_modules/pi-mcp-adapter/mcp-bearer-store.ts
|
|
44928
44902
|
import { createHash as createHash4 } from "crypto";
|
|
44929
|
-
import { createRequire as
|
|
44930
|
-
import { dirname as
|
|
44931
|
-
var require4 =
|
|
44903
|
+
import { createRequire as createRequire3 } from "module";
|
|
44904
|
+
import { dirname as dirname13, join as join25 } from "path";
|
|
44905
|
+
var require4 = createRequire3(import.meta.url);
|
|
44932
44906
|
var BEARER_SECRET_SERVICE = "pi-mcp-adapter.bearer";
|
|
44933
44907
|
var TEST_AUTH_STORE_ENV2 = "PI_MCP_ADAPTER_TEST_AUTH_STORE";
|
|
44934
44908
|
var BEARER_SECRET_VALUE_LIMIT = 1280;
|
|
@@ -45029,7 +45003,7 @@ function loadKeyringNativeBindingFallback2(keyringRequire, platform3, arch2) {
|
|
|
45029
45003
|
for (const target of targets) {
|
|
45030
45004
|
try {
|
|
45031
45005
|
const packageJsonPath = keyringRequire.resolve(`${target.packageName}/package.json`);
|
|
45032
|
-
return keyringRequire(
|
|
45006
|
+
return keyringRequire(join25(dirname13(packageJsonPath), target.bindingFile));
|
|
45033
45007
|
} catch (error) {
|
|
45034
45008
|
lastError = error;
|
|
45035
45009
|
}
|
|
@@ -45643,7 +45617,7 @@ function humanizeName(name) {
|
|
|
45643
45617
|
// ../node_modules/.bun/pi-mcp-adapter@2.32.1+04b0d7b0bc944965/node_modules/pi-mcp-adapter/mcp-trace.ts
|
|
45644
45618
|
import { appendFile as appendFile3, mkdir as mkdir17, writeFile as writeFile9 } from "fs/promises";
|
|
45645
45619
|
import { Buffer as Buffer3 } from "buffer";
|
|
45646
|
-
import { dirname as
|
|
45620
|
+
import { dirname as dirname14, isAbsolute as isAbsolute2, resolve as resolve3 } from "path";
|
|
45647
45621
|
var MCP_TRACE_SCHEMA_VERSION = 1;
|
|
45648
45622
|
var DEFAULT_MCP_TRACE_MAX_BYTES = 256 * 1024;
|
|
45649
45623
|
var DEFAULT_MCP_TRACE_MAX_EVENTS = 1e4;
|
|
@@ -45716,7 +45690,7 @@ var McpTraceWriter = class {
|
|
|
45716
45690
|
await mkdir17(path7, { recursive: true });
|
|
45717
45691
|
return void 0;
|
|
45718
45692
|
});
|
|
45719
|
-
this.fileReady = this.makeDirectory(
|
|
45693
|
+
this.fileReady = this.makeDirectory(dirname14(this.options.filePath), { recursive: true }).then(() => this.resetFile(this.options.filePath, "", { encoding: "utf8" })).catch(() => {
|
|
45720
45694
|
this.initializationFailed = true;
|
|
45721
45695
|
this.disabled = true;
|
|
45722
45696
|
});
|
|
@@ -48450,7 +48424,7 @@ async function initializeMcp(pi, ctx, owner = createMcpRuntimeOwner(), options =
|
|
|
48450
48424
|
const idleSetting = typeof config.settings?.idleTimeout === "number" ? config.settings.idleTimeout : 10;
|
|
48451
48425
|
lifecycle.setGlobalIdleTimeout(idleSetting);
|
|
48452
48426
|
const cachePath = getMetadataCachePath();
|
|
48453
|
-
const cacheFileExists =
|
|
48427
|
+
const cacheFileExists = existsSync13(cachePath);
|
|
48454
48428
|
let cache2 = loadMetadataCache();
|
|
48455
48429
|
let bootstrapAll = false;
|
|
48456
48430
|
if (!cacheFileExists) {
|
|
@@ -48841,8 +48815,8 @@ function getEffectiveIdleTimeoutMinutes(state, serverName) {
|
|
|
48841
48815
|
}
|
|
48842
48816
|
|
|
48843
48817
|
// ../node_modules/.bun/pi-mcp-adapter@2.32.1+04b0d7b0bc944965/node_modules/pi-mcp-adapter/onboarding-state.ts
|
|
48844
|
-
import { existsSync as
|
|
48845
|
-
import { dirname as
|
|
48818
|
+
import { existsSync as existsSync14, mkdirSync as mkdirSync3, readFileSync as readFileSync6, writeFileSync as writeFileSync2, renameSync as renameSync2 } from "fs";
|
|
48819
|
+
import { dirname as dirname15 } from "path";
|
|
48846
48820
|
var DEFAULT_STATE2 = {
|
|
48847
48821
|
version: 1,
|
|
48848
48822
|
sharedConfigHintShown: false,
|
|
@@ -48853,7 +48827,7 @@ function getOnboardingStatePath() {
|
|
|
48853
48827
|
}
|
|
48854
48828
|
function loadOnboardingState() {
|
|
48855
48829
|
const path7 = getOnboardingStatePath();
|
|
48856
|
-
if (!
|
|
48830
|
+
if (!existsSync14(path7)) return { ...DEFAULT_STATE2 };
|
|
48857
48831
|
try {
|
|
48858
48832
|
const raw = JSON.parse(readFileSync6(path7, "utf-8"));
|
|
48859
48833
|
if (!raw || typeof raw !== "object") return { ...DEFAULT_STATE2 };
|
|
@@ -48869,7 +48843,7 @@ function loadOnboardingState() {
|
|
|
48869
48843
|
}
|
|
48870
48844
|
function saveOnboardingState(state) {
|
|
48871
48845
|
const path7 = getOnboardingStatePath();
|
|
48872
|
-
mkdirSync3(
|
|
48846
|
+
mkdirSync3(dirname15(path7), { recursive: true });
|
|
48873
48847
|
const tmpPath = `${path7}.${process.pid}.tmp`;
|
|
48874
48848
|
writeFileSync2(tmpPath, `${JSON.stringify(state, null, 2)}
|
|
48875
48849
|
`, "utf-8");
|
|
@@ -49496,7 +49470,7 @@ async function openMcpAuthPanel(state, pi, ctx, configOverridePath) {
|
|
|
49496
49470
|
// ../node_modules/.bun/pi-mcp-adapter@2.32.1+04b0d7b0bc944965/node_modules/pi-mcp-adapter/tool-registrar.ts
|
|
49497
49471
|
import { mkdtempSync, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
49498
49472
|
import { tmpdir } from "os";
|
|
49499
|
-
import { join as
|
|
49473
|
+
import { join as join26 } from "path";
|
|
49500
49474
|
var MAX_BINARY_RESOURCE_BYTES = 10 * 1024 * 1024;
|
|
49501
49475
|
var MAX_SESSION_RESOURCE_BYTES = 100 * 1024 * 1024;
|
|
49502
49476
|
var MAX_SESSION_RESOURCE_FILES = 1e4;
|
|
@@ -49603,11 +49577,11 @@ function materializeBinaryResource(resource, scope) {
|
|
|
49603
49577
|
return omitBinaryResource(resource, "session resource limit reached");
|
|
49604
49578
|
}
|
|
49605
49579
|
try {
|
|
49606
|
-
session.directory ??= mkdtempSync(
|
|
49580
|
+
session.directory ??= mkdtempSync(join26(tmpdir(), "pi-mcp-resource-"));
|
|
49607
49581
|
} catch {
|
|
49608
49582
|
return omitBinaryResource(resource, "could not be saved");
|
|
49609
49583
|
}
|
|
49610
|
-
const filePath =
|
|
49584
|
+
const filePath = join26(session.directory, `resource-${++session.sequence}.bin`);
|
|
49611
49585
|
session.bytes += decodedBytes;
|
|
49612
49586
|
session.files += 1;
|
|
49613
49587
|
try {
|
|
@@ -49700,7 +49674,7 @@ function stringifyStructuredContent(value) {
|
|
|
49700
49674
|
import { randomBytes as randomBytes4 } from "crypto";
|
|
49701
49675
|
import { mkdtemp, rm as rm3, writeFile as writeFile10 } from "fs/promises";
|
|
49702
49676
|
import { tmpdir as tmpdir2 } from "os";
|
|
49703
|
-
import { dirname as
|
|
49677
|
+
import { dirname as dirname16, join as join27 } from "path";
|
|
49704
49678
|
var DEFAULT_MCP_OUTPUT_MAX_BYTES = 50 * 1024;
|
|
49705
49679
|
var DEFAULT_MCP_OUTPUT_MAX_LINES = 2e3;
|
|
49706
49680
|
var DEFAULT_MCP_DETAILS_MAX_BYTES = 16 * 1024;
|
|
@@ -50008,8 +49982,8 @@ function serializedObjectEntryBytes(key, value, hasPrevious) {
|
|
|
50008
49982
|
}
|
|
50009
49983
|
async function saveArtifact(kind, text) {
|
|
50010
49984
|
try {
|
|
50011
|
-
const dir = await mkdtemp(
|
|
50012
|
-
const path7 =
|
|
49985
|
+
const dir = await mkdtemp(join27(tmpdir2(), "pi-mcp-output-"));
|
|
49986
|
+
const path7 = join27(dir, `${kind}-${randomBytes4(4).toString("hex")}.txt`);
|
|
50013
49987
|
await writeFile10(path7, text, { encoding: "utf8", mode: 384 });
|
|
50014
49988
|
return { path: path7 };
|
|
50015
49989
|
} catch (error) {
|
|
@@ -50018,7 +49992,7 @@ async function saveArtifact(kind, text) {
|
|
|
50018
49992
|
}
|
|
50019
49993
|
async function discardArtifact(path7) {
|
|
50020
49994
|
try {
|
|
50021
|
-
await rm3(
|
|
49995
|
+
await rm3(dirname16(path7), { recursive: true, force: true });
|
|
50022
49996
|
} catch {
|
|
50023
49997
|
}
|
|
50024
49998
|
}
|
|
@@ -51654,11 +51628,11 @@ function sendText(res, status, text) {
|
|
|
51654
51628
|
}
|
|
51655
51629
|
|
|
51656
51630
|
// ../node_modules/.bun/pi-mcp-adapter@2.32.1+04b0d7b0bc944965/node_modules/pi-mcp-adapter/glimpse-ui.ts
|
|
51657
|
-
import { existsSync as
|
|
51631
|
+
import { existsSync as existsSync15 } from "fs";
|
|
51658
51632
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
51659
|
-
import { join as
|
|
51633
|
+
import { join as join28, dirname as dirname17 } from "path";
|
|
51660
51634
|
import { platform as platform2 } from "os";
|
|
51661
|
-
import { createRequire as
|
|
51635
|
+
import { createRequire as createRequire4 } from "module";
|
|
51662
51636
|
var glimpseAvailable = null;
|
|
51663
51637
|
var resolvedBinaryPath = null;
|
|
51664
51638
|
function isGlimpseAvailable() {
|
|
@@ -51672,26 +51646,26 @@ function isGlimpseAvailable() {
|
|
|
51672
51646
|
return glimpseAvailable;
|
|
51673
51647
|
}
|
|
51674
51648
|
function getGlimpseBinaryPath() {
|
|
51675
|
-
if (process.env.GLIMPSE_BINARY &&
|
|
51649
|
+
if (process.env.GLIMPSE_BINARY && existsSync15(process.env.GLIMPSE_BINARY)) {
|
|
51676
51650
|
return process.env.GLIMPSE_BINARY;
|
|
51677
51651
|
}
|
|
51678
51652
|
try {
|
|
51679
|
-
const require7 =
|
|
51653
|
+
const require7 = createRequire4(import.meta.url);
|
|
51680
51654
|
const glimpseuiPath = require7.resolve("glimpseui");
|
|
51681
|
-
const binaryPath =
|
|
51682
|
-
if (
|
|
51655
|
+
const binaryPath = join28(dirname17(glimpseuiPath), "glimpse");
|
|
51656
|
+
if (existsSync15(binaryPath)) return binaryPath;
|
|
51683
51657
|
} catch {
|
|
51684
51658
|
}
|
|
51685
51659
|
try {
|
|
51686
51660
|
const globalRoot = execFileSync2("npm", ["root", "-g"], { encoding: "utf-8" }).trim();
|
|
51687
|
-
const binaryPath =
|
|
51688
|
-
if (
|
|
51661
|
+
const binaryPath = join28(globalRoot, "glimpseui", "src", "glimpse");
|
|
51662
|
+
if (existsSync15(binaryPath)) return binaryPath;
|
|
51689
51663
|
} catch {
|
|
51690
51664
|
}
|
|
51691
51665
|
return null;
|
|
51692
51666
|
}
|
|
51693
51667
|
async function openGlimpseWindow(html, options) {
|
|
51694
|
-
const modulePath = resolvedBinaryPath ?
|
|
51668
|
+
const modulePath = resolvedBinaryPath ? join28(dirname17(resolvedBinaryPath), "glimpse.mjs") : "glimpseui";
|
|
51695
51669
|
const glimpse = await import(modulePath);
|
|
51696
51670
|
let active = true;
|
|
51697
51671
|
const win = glimpse.open(html, {
|
|
@@ -56087,7 +56061,7 @@ function buildCommandDescription(metadata) {
|
|
|
56087
56061
|
}
|
|
56088
56062
|
|
|
56089
56063
|
// ../node_modules/.bun/pi-mcp-adapter@2.32.1+04b0d7b0bc944965/node_modules/pi-mcp-adapter/proxy-modes.ts
|
|
56090
|
-
import { createRequire as
|
|
56064
|
+
import { createRequire as createRequire5 } from "module";
|
|
56091
56065
|
|
|
56092
56066
|
// ../node_modules/.bun/pi-mcp-adapter@2.32.1+04b0d7b0bc944965/node_modules/pi-mcp-adapter/ts-shape.ts
|
|
56093
56067
|
var UNSUPPORTED_KEYWORDS = ["if", "then", "else", "allOf", "not", "patternProperties", "additionalProperties"];
|
|
@@ -56407,7 +56381,7 @@ function rankSuggestions(state, name, limit) {
|
|
|
56407
56381
|
}
|
|
56408
56382
|
|
|
56409
56383
|
// ../node_modules/.bun/pi-mcp-adapter@2.32.1+04b0d7b0bc944965/node_modules/pi-mcp-adapter/proxy-modes.ts
|
|
56410
|
-
var require5 =
|
|
56384
|
+
var require5 = createRequire5(import.meta.url);
|
|
56411
56385
|
var MAX_REGEX_SEARCH_QUERY_LENGTH = 256;
|
|
56412
56386
|
var INSTRUCTIONS_PREVIEW_LENGTH = 300;
|
|
56413
56387
|
var REGEX_SAFETY_CHECK_PARAMS = {
|
|
@@ -59603,12 +59577,12 @@ var PiManager = class extends CodingAgentManager {
|
|
|
59603
59577
|
modelRuntime = null;
|
|
59604
59578
|
constructor(options) {
|
|
59605
59579
|
super(options);
|
|
59606
|
-
this.historyFilePath = options.historyFilePath ??
|
|
59580
|
+
this.historyFilePath = options.historyFilePath ?? join29(PI_HISTORY_DIR, `${Date.now()}.jsonl`);
|
|
59607
59581
|
this.historyFile = new CodexHistoryFile(this.historyFilePath);
|
|
59608
59582
|
this.initializeManager(this.processMessageInternal.bind(this));
|
|
59609
59583
|
}
|
|
59610
59584
|
async initialize() {
|
|
59611
|
-
await mkdir18(
|
|
59585
|
+
await mkdir18(dirname18(this.historyFilePath), { recursive: true });
|
|
59612
59586
|
}
|
|
59613
59587
|
getHistorySink() {
|
|
59614
59588
|
return this.historyFile;
|
|
@@ -59715,7 +59689,7 @@ var PiManager = class extends CodingAgentManager {
|
|
|
59715
59689
|
const sessionManager = this.initialSessionId ? SessionManager.open(this.initialSessionId, PI_HISTORY_DIR, this.workingDirectory) : SessionManager.create(this.workingDirectory, PI_HISTORY_DIR);
|
|
59716
59690
|
const mcpServers = await getManagedPiMcpServers();
|
|
59717
59691
|
if (this.relayParentChatId) {
|
|
59718
|
-
mcpServers[
|
|
59692
|
+
mcpServers[RELAY_MCP_SERVER_NAME] = {
|
|
59719
59693
|
...relayMcpProcessConfig(this.relayParentChatId),
|
|
59720
59694
|
lifecycle: "lazy",
|
|
59721
59695
|
idleTimeout: 1,
|
|
@@ -59739,7 +59713,7 @@ var PiManager = class extends CodingAgentManager {
|
|
|
59739
59713
|
}
|
|
59740
59714
|
const resourceLoader = new DefaultResourceLoader({
|
|
59741
59715
|
cwd: this.workingDirectory,
|
|
59742
|
-
agentDir:
|
|
59716
|
+
agentDir: join29(ENGINE_ENV.HOME_DIR, ".pi", "agent"),
|
|
59743
59717
|
extensionFactories,
|
|
59744
59718
|
appendSystemPrompt: [this.buildCombinedInstructions() ?? ""]
|
|
59745
59719
|
});
|
|
@@ -59816,7 +59790,15 @@ Go straight to the point. Lead with outcomes and decisions, keep updates concise
|
|
|
59816
59790
|
|
|
59817
59791
|
Your primary constraint is context. Work directly when the task is small, tightly coupled to context you already hold, or cheaper to complete than explain. Delegate independent work that would consume substantial context, including broad investigation, multi-file implementation, iterative debugging, test-and-fix loops, and unbiased review or verification. Do not delegate trivial work or work whose full context would cost more to transfer than doing it yourself.
|
|
59818
59792
|
|
|
59819
|
-
Use the
|
|
59793
|
+
Use the \`${RELAY_MCP_SERVER_NAME}\` MCP server exclusively for delegation; never use terminal commands or the base harness's native agent-spawning, delegation, or collaboration tools. It exposes \`get_providers\`, \`spawn_agent\`, \`message_agent\`, and \`delete_agent\`; your harness may show them with an MCP server prefix. In Pi, call them through the \`mcp\` gateway for the \`${RELAY_MCP_SERVER_NAME}\` server if direct tools are not yet visible. Check \`get_providers\` before the first delegation instead of guessing. The default timeout is 10 minutes; increase it only when the task reasonably needs longer.
|
|
59794
|
+
|
|
59795
|
+
Choose how much parent context each child inherits with \`spawn_agent.fork_turns\`:
|
|
59796
|
+
|
|
59797
|
+
- \`"all"\` (default): inherit the conversation as an extension of yourself when the task depends on prior decisions and constraints.
|
|
59798
|
+
- \`"none"\`: start with only the task prompt to reduce input tokens or get an independent assessment without your prior reasoning. Include all necessary requirements, paths, constraints, and evidence in the prompt; the child cannot infer omitted context.
|
|
59799
|
+
- A positive integer string such as \`"3"\`: inherit only the latest N user-led turns when recent context is enough. A turn includes a user message and the agent activity that follows it, including the current unfinished turn.
|
|
59800
|
+
|
|
59801
|
+
Give every child a concrete task, clear scope, and definition of done, even when it inherits the conversation. The child should use inherited history as background and focus on its assigned task.
|
|
59820
59802
|
|
|
59821
59803
|
Run truly independent child agents concurrently. Because child agents share the workspace, run modifying work sequentially unless file ownership cannot overlap. Keep dependent work sequential when one result defines another task's contract, such as schema before queries, API before its client, or implementation before its focused verification. Review child results, follow up when they are incomplete, and verify the integrated outcome yourself. Do not delete child chats unless the user asks.
|
|
59822
59804
|
|
|
@@ -59858,8 +59840,8 @@ import {
|
|
|
59858
59840
|
rename as rename3,
|
|
59859
59841
|
unlink as unlink3
|
|
59860
59842
|
} from "fs/promises";
|
|
59861
|
-
import { existsSync as
|
|
59862
|
-
import { join as
|
|
59843
|
+
import { existsSync as existsSync16, readFileSync as readFileSync7, readdirSync as readdirSync2 } from "fs";
|
|
59844
|
+
import { join as join30 } from "path";
|
|
59863
59845
|
var MAX_FAILED_RECORDS = 500;
|
|
59864
59846
|
var FLUSH_DEBOUNCE_MS = 15e3;
|
|
59865
59847
|
var MAX_UPLOADED_SEGMENTS = 50;
|
|
@@ -59871,7 +59853,7 @@ var AnalyticsRecordBuffer = class {
|
|
|
59871
59853
|
options.storageName,
|
|
59872
59854
|
...options.legacyStorageNames ?? []
|
|
59873
59855
|
];
|
|
59874
|
-
this.liveFile =
|
|
59856
|
+
this.liveFile = join30(ENGINE_DIR2, `${options.storageName}.jsonl`);
|
|
59875
59857
|
this.segmentFilePatterns = this.storageNames.map(
|
|
59876
59858
|
(storageName) => new RegExp(`^${storageName}\\.(\\d+)\\.jsonl$`)
|
|
59877
59859
|
);
|
|
@@ -59906,10 +59888,10 @@ var AnalyticsRecordBuffer = class {
|
|
|
59906
59888
|
void pending.finally(() => this.pendingAppends.delete(pending));
|
|
59907
59889
|
}
|
|
59908
59890
|
readStoredRecords() {
|
|
59909
|
-
if (!
|
|
59891
|
+
if (!existsSync16(ENGINE_DIR2)) return [];
|
|
59910
59892
|
return readdirSync2(ENGINE_DIR2, { withFileTypes: true }).filter((entry) => entry.isFile() && this.storageNames.some(
|
|
59911
59893
|
(storageName) => entry.name === `${storageName}.jsonl` || entry.name.startsWith(`${storageName}.`) && (entry.name.endsWith(".jsonl") || entry.name.endsWith(`.jsonl${UPLOADED_SUFFIX}`))
|
|
59912
|
-
)).map(({ name }) => name).sort().flatMap((name) => this.parseRecords(readFileSync7(
|
|
59894
|
+
)).map(({ name }) => name).sort().flatMap((name) => this.parseRecords(readFileSync7(join30(ENGINE_DIR2, name), "utf-8"))).map((record3) => {
|
|
59913
59895
|
const recordId = this.options.getRecordId?.(record3);
|
|
59914
59896
|
if (recordId) this.recordIds.add(recordId);
|
|
59915
59897
|
return record3;
|
|
@@ -59944,8 +59926,8 @@ var AnalyticsRecordBuffer = class {
|
|
|
59944
59926
|
}
|
|
59945
59927
|
for (const storageName of this.storageNames) {
|
|
59946
59928
|
await rename3(
|
|
59947
|
-
|
|
59948
|
-
|
|
59929
|
+
join30(ENGINE_DIR2, `${storageName}.jsonl`),
|
|
59930
|
+
join30(ENGINE_DIR2, `${storageName}.${Date.now()}.jsonl`)
|
|
59949
59931
|
).catch(() => {
|
|
59950
59932
|
});
|
|
59951
59933
|
}
|
|
@@ -59955,7 +59937,7 @@ var AnalyticsRecordBuffer = class {
|
|
|
59955
59937
|
for (const entry of entries) {
|
|
59956
59938
|
if (!this.segmentFilePatterns.some((pattern) => pattern.test(entry))) continue;
|
|
59957
59939
|
try {
|
|
59958
|
-
await this.uploadSegment(
|
|
59940
|
+
await this.uploadSegment(join30(ENGINE_DIR2, entry));
|
|
59959
59941
|
flushed++;
|
|
59960
59942
|
} catch (error) {
|
|
59961
59943
|
failed++;
|
|
@@ -59984,7 +59966,7 @@ var AnalyticsRecordBuffer = class {
|
|
|
59984
59966
|
(storageName) => entry.startsWith(`${storageName}.`)
|
|
59985
59967
|
) && entry.endsWith(UPLOADED_SUFFIX)).sort();
|
|
59986
59968
|
for (const entry of uploaded.slice(0, -MAX_UPLOADED_SEGMENTS)) {
|
|
59987
|
-
await unlink3(
|
|
59969
|
+
await unlink3(join30(ENGINE_DIR2, entry)).catch(() => {
|
|
59988
59970
|
});
|
|
59989
59971
|
}
|
|
59990
59972
|
}
|
|
@@ -60803,7 +60785,7 @@ var keepAliveService = new KeepAliveService();
|
|
|
60803
60785
|
// src/services/canvas-service.ts
|
|
60804
60786
|
import { readdir as readdir7, readFile as readFile20, stat as stat4 } from "fs/promises";
|
|
60805
60787
|
import { homedir as homedir13 } from "os";
|
|
60806
|
-
import { join as
|
|
60788
|
+
import { join as join31 } from "path";
|
|
60807
60789
|
|
|
60808
60790
|
// src/utils/contained-file.ts
|
|
60809
60791
|
import { realpath, stat as stat3 } from "fs/promises";
|
|
@@ -60845,15 +60827,15 @@ async function writeRevisionedTextFile(filePath, content, expectedRevision) {
|
|
|
60845
60827
|
|
|
60846
60828
|
// src/services/canvas-service.ts
|
|
60847
60829
|
var GLOBAL_CANVAS_DIRECTORIES = [
|
|
60848
|
-
|
|
60849
|
-
|
|
60850
|
-
|
|
60830
|
+
join31(homedir13(), ".claude", "plans"),
|
|
60831
|
+
join31(process.env.XDG_DATA_HOME ?? join31(homedir13(), ".local", "share"), "opencode", "plans"),
|
|
60832
|
+
join31(homedir13(), ".replicas", "canvas")
|
|
60851
60833
|
];
|
|
60852
60834
|
async function canvasDirectories() {
|
|
60853
60835
|
const repositories = await gitService.listRepositories().catch(() => []);
|
|
60854
60836
|
return [
|
|
60855
60837
|
...GLOBAL_CANVAS_DIRECTORIES,
|
|
60856
|
-
...repositories.map((repository) =>
|
|
60838
|
+
...repositories.map((repository) => join31(repository.path, ".opencode", "plans"))
|
|
60857
60839
|
];
|
|
60858
60840
|
}
|
|
60859
60841
|
var CanvasService = class {
|
|
@@ -60878,7 +60860,7 @@ var CanvasService = class {
|
|
|
60878
60860
|
for (const entry of entries) {
|
|
60879
60861
|
if (entry.name.startsWith(".")) continue;
|
|
60880
60862
|
const filename = current.relativePath ? `${current.relativePath}/${entry.name}` : entry.name;
|
|
60881
|
-
const filePath =
|
|
60863
|
+
const filePath = join31(current.directory, entry.name);
|
|
60882
60864
|
if (entry.isDirectory()) {
|
|
60883
60865
|
pending.push({ directory: filePath, relativePath: filename });
|
|
60884
60866
|
continue;
|
|
@@ -60903,7 +60885,7 @@ var CanvasService = class {
|
|
|
60903
60885
|
if (!safe) return null;
|
|
60904
60886
|
const { kind, mimeType } = classifyCanvasFilename(safe);
|
|
60905
60887
|
for (const directory of await this.directories()) {
|
|
60906
|
-
const filePath =
|
|
60888
|
+
const filePath = join31(directory, safe);
|
|
60907
60889
|
let sizeBytes = 0;
|
|
60908
60890
|
let updatedAt = "";
|
|
60909
60891
|
try {
|
|
@@ -61087,13 +61069,13 @@ async function reconcileCanvasItems(filenames) {
|
|
|
61087
61069
|
import { createReadStream } from "fs";
|
|
61088
61070
|
import { createHash as createHash8 } from "crypto";
|
|
61089
61071
|
import { readFile as readFile21, readdir as readdir8, stat as stat5 } from "fs/promises";
|
|
61090
|
-
import { basename as basename4, join as
|
|
61072
|
+
import { basename as basename4, join as join33 } from "path";
|
|
61091
61073
|
|
|
61092
61074
|
// src/services/chat/chat-senders.ts
|
|
61093
|
-
import { join as
|
|
61094
|
-
var CHAT_SENDERS_DIR =
|
|
61075
|
+
import { join as join32 } from "path";
|
|
61076
|
+
var CHAT_SENDERS_DIR = join32(ENGINE_DIR2, "chat-senders");
|
|
61095
61077
|
function chatMessageSendersFilePath(chatId) {
|
|
61096
|
-
return
|
|
61078
|
+
return join32(CHAT_SENDERS_DIR, `${chatId}.jsonl`);
|
|
61097
61079
|
}
|
|
61098
61080
|
function parseChatMessageSendersJsonl(content) {
|
|
61099
61081
|
return content.split("\n").flatMap((line) => {
|
|
@@ -61136,7 +61118,7 @@ async function flushAllChatTranscripts(chatsById = /* @__PURE__ */ new Map(), ca
|
|
|
61136
61118
|
const chat = chatsById.get(chatId);
|
|
61137
61119
|
if (!shouldFlushChatTranscript(dir, chat, chatsById)) continue;
|
|
61138
61120
|
tasks.push(
|
|
61139
|
-
uploadChatTranscript(chatId,
|
|
61121
|
+
uploadChatTranscript(chatId, join33(dir, entry), chat, capture).then((artifact) => {
|
|
61140
61122
|
flushed++;
|
|
61141
61123
|
if (artifact && capture) revisions.push(artifact);
|
|
61142
61124
|
}).catch((err) => {
|
|
@@ -61225,7 +61207,7 @@ async function uploadChatTranscript(chatId, filePath, chat, capture) {
|
|
|
61225
61207
|
// src/services/upload-engine-logs.ts
|
|
61226
61208
|
import { createReadStream as createReadStream2 } from "fs";
|
|
61227
61209
|
import { readdir as readdir9, stat as stat6 } from "fs/promises";
|
|
61228
|
-
import { join as
|
|
61210
|
+
import { join as join34 } from "path";
|
|
61229
61211
|
var MAX_ENGINE_LOG_FLUSH_SESSIONS = 10;
|
|
61230
61212
|
var MAX_ENGINE_LOG_FLUSH_BYTES = 5 * 1024 * 1024;
|
|
61231
61213
|
var ENGINE_LOG_FLUSH_TIMEOUT_MS = 2e4;
|
|
@@ -61254,7 +61236,7 @@ async function flushAllEngineLogs() {
|
|
|
61254
61236
|
const candidates = (await Promise.all(filenames.slice(0, MAX_ENGINE_LOG_FLUSH_SESSIONS).map(async (filename) => {
|
|
61255
61237
|
try {
|
|
61256
61238
|
const sessionId = filename.slice(0, -".log".length);
|
|
61257
|
-
const filePath =
|
|
61239
|
+
const filePath = join34(LOG_DIR, filename);
|
|
61258
61240
|
const fileStat = await runBeforeDeadline(() => stat6(filePath), deadline);
|
|
61259
61241
|
if (!fileStat.isFile()) {
|
|
61260
61242
|
skipped++;
|
|
@@ -61351,7 +61333,7 @@ async function uploadEngineLog(input, timeoutMs) {
|
|
|
61351
61333
|
|
|
61352
61334
|
// src/services/chat/fork-handoff.ts
|
|
61353
61335
|
import { mkdir as mkdir20, open as open3, writeFile as writeFile11 } from "fs/promises";
|
|
61354
|
-
import { join as
|
|
61336
|
+
import { join as join35 } from "path";
|
|
61355
61337
|
var EXCERPT_MAX_CHARS = 24e3;
|
|
61356
61338
|
var MAX_SANITIZED_SOURCE_BYTES = 32 * 1024 * 1024;
|
|
61357
61339
|
function unansweredRequest(blocks) {
|
|
@@ -61386,13 +61368,18 @@ function tailBlocks(blocks, maxChars) {
|
|
|
61386
61368
|
return { excerpt, truncated: start > 0 };
|
|
61387
61369
|
}
|
|
61388
61370
|
async function buildForkHandoff(input) {
|
|
61389
|
-
const rawHistoryPath =
|
|
61371
|
+
const rawHistoryPath = join35(HISTORY_DIR_BY_PROVIDER[input.sourceProvider], `${input.sourceChatId}.jsonl`);
|
|
61390
61372
|
const { content, truncated: sourceTruncated } = await readHistoryTail(rawHistoryPath, MAX_SANITIZED_SOURCE_BYTES);
|
|
61391
|
-
|
|
61392
|
-
|
|
61373
|
+
let blocks = canonicalizeChatTranscriptBlocks(content, input.executionProvider, input.senders);
|
|
61374
|
+
if (input.turnLimit !== void 0) {
|
|
61375
|
+
let turns = 0;
|
|
61376
|
+
const start = blocks.findLastIndex((block) => block.startsWith("## User") && ++turns === input.turnLimit);
|
|
61377
|
+
blocks = blocks.slice(Math.max(0, start));
|
|
61378
|
+
}
|
|
61379
|
+
const forkDir = join35(FORKS_DIR, input.targetChatId);
|
|
61393
61380
|
await mkdir20(forkDir, { recursive: true });
|
|
61394
|
-
const transcriptPath =
|
|
61395
|
-
const header = sourceTruncated ? `_This file
|
|
61381
|
+
const transcriptPath = join35(forkDir, "source-transcript.md");
|
|
61382
|
+
const header = sourceTruncated ? `_This file was generated from only the most recent ${MAX_SANITIZED_SOURCE_BYTES / 1024 / 1024} MB of the source chat.${input.turnLimit === void 0 ? ` The complete raw event log is at ${rawHistoryPath}; grep it for anything earlier.` : ""}_
|
|
61396
61383
|
|
|
61397
61384
|
` : "";
|
|
61398
61385
|
await writeFile11(transcriptPath, `${header}${blocks.join("\n\n")}
|
|
@@ -61404,7 +61391,7 @@ async function buildForkHandoff(input) {
|
|
|
61404
61391
|
sourceTruncated,
|
|
61405
61392
|
resumeRequest: unansweredRequest(blocks),
|
|
61406
61393
|
transcriptPath,
|
|
61407
|
-
rawHistoryPath
|
|
61394
|
+
rawHistoryPath: input.turnLimit === void 0 ? rawHistoryPath : void 0
|
|
61408
61395
|
};
|
|
61409
61396
|
}
|
|
61410
61397
|
|
|
@@ -61683,8 +61670,19 @@ var ChatService = class {
|
|
|
61683
61670
|
parentChatId
|
|
61684
61671
|
});
|
|
61685
61672
|
try {
|
|
61673
|
+
let message = request.prompt;
|
|
61674
|
+
if (request.forkTurns !== "none") {
|
|
61675
|
+
const parent = this.requireChat(parentChatId).persisted;
|
|
61676
|
+
message = await this.createForkHandoffMessage(chat.id, {
|
|
61677
|
+
source: { chatId: parentChatId, provider: parent.provider, title: parent.title },
|
|
61678
|
+
trigger: "manual",
|
|
61679
|
+
subagent: true,
|
|
61680
|
+
turnLimit: request.forkTurns && request.forkTurns !== "all" ? Number(request.forkTurns) : void 0,
|
|
61681
|
+
message: request.prompt
|
|
61682
|
+
});
|
|
61683
|
+
}
|
|
61686
61684
|
await this.sendMessage(chat.id, {
|
|
61687
|
-
message
|
|
61685
|
+
message,
|
|
61688
61686
|
...request.model ? { model: request.model } : {},
|
|
61689
61687
|
...request.thinkingLevel ? { thinkingLevel: request.thinkingLevel } : {}
|
|
61690
61688
|
});
|
|
@@ -62122,14 +62120,14 @@ var ChatService = class {
|
|
|
62122
62120
|
return descendants;
|
|
62123
62121
|
}
|
|
62124
62122
|
async deleteHistoryFile(persisted) {
|
|
62125
|
-
const historyPath =
|
|
62123
|
+
const historyPath = join36(HISTORY_DIR_BY_PROVIDER[persisted.provider], `${persisted.id}.jsonl`);
|
|
62126
62124
|
await Promise.all([
|
|
62127
62125
|
historyPath,
|
|
62128
62126
|
`${historyPath}.pages.jsonl`,
|
|
62129
62127
|
`${historyPath}.pages.index.json`
|
|
62130
62128
|
].map((path7) => rm4(path7, { force: true })));
|
|
62131
62129
|
await rm4(chatMessageSendersFilePath(persisted.id), { force: true });
|
|
62132
|
-
await rm4(
|
|
62130
|
+
await rm4(join36(FORKS_DIR, persisted.id), { recursive: true, force: true });
|
|
62133
62131
|
}
|
|
62134
62132
|
/** Resolves once the target chat exists; the handoff and its first turn run in the background. */
|
|
62135
62133
|
async forkChat(sourceChatId, request, trigger = "manual", reason) {
|
|
@@ -62159,33 +62157,34 @@ var ChatService = class {
|
|
|
62159
62157
|
});
|
|
62160
62158
|
return target;
|
|
62161
62159
|
}
|
|
62160
|
+
async createForkHandoffMessage(targetChatId, options) {
|
|
62161
|
+
const source = this.requireChat(options.source.chatId);
|
|
62162
|
+
await source.provider.getHistory({ limit: 1 });
|
|
62163
|
+
const handoff = await buildForkHandoff({
|
|
62164
|
+
sourceChatId: options.source.chatId,
|
|
62165
|
+
sourceProvider: options.source.provider,
|
|
62166
|
+
executionProvider: getChatExecutionProvider(source.persisted),
|
|
62167
|
+
targetChatId,
|
|
62168
|
+
senders: await this.readSenders(options.source.chatId),
|
|
62169
|
+
turnLimit: options.turnLimit
|
|
62170
|
+
});
|
|
62171
|
+
return formatChatForkHandoffMessage({ ...handoff, ...options });
|
|
62172
|
+
}
|
|
62162
62173
|
async runFork(targetId, request) {
|
|
62163
62174
|
const target = this.chats.get(targetId);
|
|
62164
62175
|
const fork = target?.persisted.fork;
|
|
62165
62176
|
if (!target || !fork) return;
|
|
62166
62177
|
try {
|
|
62167
62178
|
if (!isAgentAvailable(getChatExecutionProvider(target.persisted))) throw new ChatProviderUnavailableError(request.provider);
|
|
62168
|
-
const
|
|
62169
|
-
|
|
62170
|
-
|
|
62171
|
-
|
|
62172
|
-
|
|
62173
|
-
senders: await this.readSenders(fork.source.chatId)
|
|
62179
|
+
const message = await this.createForkHandoffMessage(targetId, {
|
|
62180
|
+
source: fork.source,
|
|
62181
|
+
trigger: fork.trigger,
|
|
62182
|
+
reason: fork.reason,
|
|
62183
|
+
message: request.message
|
|
62174
62184
|
});
|
|
62175
62185
|
if (target.persisted.deletedAt) return;
|
|
62176
62186
|
await this.sendMessage(targetId, {
|
|
62177
|
-
message
|
|
62178
|
-
source: fork.source,
|
|
62179
|
-
trigger: fork.trigger,
|
|
62180
|
-
...fork.reason ? { reason: fork.reason } : {},
|
|
62181
|
-
excerpt: handoff.excerpt,
|
|
62182
|
-
excerptTruncated: handoff.excerptTruncated,
|
|
62183
|
-
sourceTruncated: handoff.sourceTruncated,
|
|
62184
|
-
transcriptPath: handoff.transcriptPath,
|
|
62185
|
-
rawHistoryPath: handoff.rawHistoryPath,
|
|
62186
|
-
resumeRequest: handoff.resumeRequest,
|
|
62187
|
-
message: request.message
|
|
62188
|
-
}),
|
|
62187
|
+
message,
|
|
62189
62188
|
model: request.model,
|
|
62190
62189
|
thinkingLevel: request.thinkingLevel,
|
|
62191
62190
|
enableInteractiveTools: request.enableInteractiveTools,
|
|
@@ -62382,7 +62381,7 @@ var ChatService = class {
|
|
|
62382
62381
|
}
|
|
62383
62382
|
const baseProvider = getChatExecutionProvider(persisted);
|
|
62384
62383
|
const additionalInstructions = persisted.provider === "relay" ? buildRelayInstructions(this.workingDirectory) : void 0;
|
|
62385
|
-
const historyFilePath =
|
|
62384
|
+
const historyFilePath = join36(HISTORY_DIR_BY_PROVIDER[persisted.provider], `${persisted.id}.jsonl`);
|
|
62386
62385
|
const managerOptions = {
|
|
62387
62386
|
provider: baseProvider,
|
|
62388
62387
|
workingDirectory: this.workingDirectory,
|
|
@@ -62632,7 +62631,7 @@ var ChatService = class {
|
|
|
62632
62631
|
});
|
|
62633
62632
|
uploadChatTranscript(
|
|
62634
62633
|
chatId,
|
|
62635
|
-
|
|
62634
|
+
join36(HISTORY_DIR_BY_PROVIDER[chat.persisted.provider], `${chatId}.jsonl`),
|
|
62636
62635
|
this.toSummary(chat)
|
|
62637
62636
|
).catch((err) => {
|
|
62638
62637
|
console.error("[ChatService] Failed to upload chat transcript:", { chatId, err });
|
|
@@ -62765,13 +62764,13 @@ import { extname as extname3 } from "path";
|
|
|
62765
62764
|
|
|
62766
62765
|
// src/services/language-server-service.ts
|
|
62767
62766
|
import { spawn as spawn9 } from "child_process";
|
|
62768
|
-
import { existsSync as
|
|
62769
|
-
import { createRequire as
|
|
62770
|
-
import { delimiter as delimiter2, dirname as
|
|
62767
|
+
import { existsSync as existsSync17, readFileSync as readFileSync8 } from "fs";
|
|
62768
|
+
import { createRequire as createRequire6 } from "module";
|
|
62769
|
+
import { delimiter as delimiter2, dirname as dirname19, join as join37, relative as relative2 } from "path";
|
|
62771
62770
|
import { setTimeout as setTimeout2 } from "timers/promises";
|
|
62772
|
-
import { fileURLToPath as
|
|
62771
|
+
import { fileURLToPath as fileURLToPath6, pathToFileURL } from "url";
|
|
62773
62772
|
import { createMessageConnection, StreamMessageReader, StreamMessageWriter } from "vscode-jsonrpc/node.js";
|
|
62774
|
-
var require6 =
|
|
62773
|
+
var require6 = createRequire6(import.meta.url);
|
|
62775
62774
|
var SERVER_TIMEOUT_MS = 1e4;
|
|
62776
62775
|
var LANGUAGE_SERVERS = {
|
|
62777
62776
|
typescript: { package: "typescript-language-server", bin: "typescript-language-server", args: ["--stdio"] },
|
|
@@ -62808,7 +62807,7 @@ function packageBin(packageName, binName) {
|
|
|
62808
62807
|
const packageJson = JSON.parse(readFileSync8(packageJsonPath, "utf8"));
|
|
62809
62808
|
const bin = typeof packageJson.bin === "string" ? packageJson.bin : packageJson.bin[binName];
|
|
62810
62809
|
if (!bin) throw new Error(`Missing ${binName} binary`);
|
|
62811
|
-
return `${
|
|
62810
|
+
return `${dirname19(packageJsonPath)}/${bin}`;
|
|
62812
62811
|
}
|
|
62813
62812
|
function markdownText(value) {
|
|
62814
62813
|
if (typeof value === "string") return value;
|
|
@@ -62886,7 +62885,7 @@ var LanguageServerService = class {
|
|
|
62886
62885
|
if (config.package && config.bin) command = process.execPath;
|
|
62887
62886
|
else if (config.command) {
|
|
62888
62887
|
const commandName = config.command;
|
|
62889
|
-
command = process.env.PATH?.split(delimiter2).map((directory) =>
|
|
62888
|
+
command = process.env.PATH?.split(delimiter2).map((directory) => join37(directory, commandName)).find(existsSync17);
|
|
62890
62889
|
}
|
|
62891
62890
|
const args = config.package && config.bin ? [packageBin(config.package, config.bin), ...config.args] : config.args;
|
|
62892
62891
|
if (!command) return null;
|
|
@@ -62906,7 +62905,7 @@ var LanguageServerService = class {
|
|
|
62906
62905
|
const locations = rawLocations.flatMap((location) => {
|
|
62907
62906
|
const uri = "targetUri" in location ? location.targetUri : location.uri;
|
|
62908
62907
|
const range = "targetSelectionRange" in location ? location.targetSelectionRange : location.range;
|
|
62909
|
-
const absolutePath =
|
|
62908
|
+
const absolutePath = fileURLToPath6(uri);
|
|
62910
62909
|
const path7 = relative2(repoPath, absolutePath);
|
|
62911
62910
|
if (path7.startsWith("..")) return [];
|
|
62912
62911
|
const preview = readFileSync8(absolutePath, "utf8").split("\n")[range.start.line]?.trim() ?? "";
|
|
@@ -63228,20 +63227,20 @@ var RepoFileService = class {
|
|
|
63228
63227
|
import { Hono } from "hono";
|
|
63229
63228
|
import { z as z6 } from "zod";
|
|
63230
63229
|
import { readdir as readdir11, stat as stat7, readFile as readFile26 } from "fs/promises";
|
|
63231
|
-
import { join as
|
|
63230
|
+
import { join as join40, resolve as resolve5 } from "path";
|
|
63232
63231
|
|
|
63233
63232
|
// src/services/warm-hooks-service.ts
|
|
63234
63233
|
import { spawn as spawn10 } from "child_process";
|
|
63235
63234
|
import { readFile as readFile25 } from "fs/promises";
|
|
63236
|
-
import { existsSync as
|
|
63237
|
-
import { join as
|
|
63235
|
+
import { existsSync as existsSync18 } from "fs";
|
|
63236
|
+
import { join as join39 } from "path";
|
|
63238
63237
|
|
|
63239
63238
|
// src/services/warm-hook-logs-service.ts
|
|
63240
63239
|
import { mkdir as mkdir22, readFile as readFile24, writeFile as writeFile12, readdir as readdir10, appendFile as appendFile6, unlink as unlink4 } from "fs/promises";
|
|
63241
63240
|
import { homedir as homedir14 } from "os";
|
|
63242
|
-
import { join as
|
|
63243
|
-
var LOGS_DIR2 =
|
|
63244
|
-
var CURRENT_RUN_LOG =
|
|
63241
|
+
import { join as join38 } from "path";
|
|
63242
|
+
var LOGS_DIR2 = join38(homedir14(), ".replicas", "warm-hook-logs");
|
|
63243
|
+
var CURRENT_RUN_LOG = join38(LOGS_DIR2, "current-run.log");
|
|
63245
63244
|
var GLOBAL_FILENAME = "global.json";
|
|
63246
63245
|
function withPreview2(stored) {
|
|
63247
63246
|
const preview = buildHookOutputPreview(stored.output);
|
|
@@ -63258,7 +63257,7 @@ var WarmHookLogsService = class {
|
|
|
63258
63257
|
hookName: "organization",
|
|
63259
63258
|
...entry
|
|
63260
63259
|
};
|
|
63261
|
-
await writeFile12(
|
|
63260
|
+
await writeFile12(join38(LOGS_DIR2, GLOBAL_FILENAME), `${JSON.stringify(log, null, 2)}
|
|
63262
63261
|
`, "utf-8");
|
|
63263
63262
|
}
|
|
63264
63263
|
async saveEnvironmentHookLog(entry) {
|
|
@@ -63268,7 +63267,7 @@ var WarmHookLogsService = class {
|
|
|
63268
63267
|
hookName: "environment",
|
|
63269
63268
|
...entry
|
|
63270
63269
|
};
|
|
63271
|
-
await writeFile12(
|
|
63270
|
+
await writeFile12(join38(LOGS_DIR2, ENVIRONMENT_HOOK_LOG_FILENAME), `${JSON.stringify(log, null, 2)}
|
|
63272
63271
|
`, "utf-8");
|
|
63273
63272
|
}
|
|
63274
63273
|
async saveRepoHookLog(repoName, entry) {
|
|
@@ -63278,7 +63277,7 @@ var WarmHookLogsService = class {
|
|
|
63278
63277
|
hookName: repoName,
|
|
63279
63278
|
...entry
|
|
63280
63279
|
};
|
|
63281
|
-
await writeFile12(
|
|
63280
|
+
await writeFile12(join38(LOGS_DIR2, repoHookLogFilename(repoName)), `${JSON.stringify(log, null, 2)}
|
|
63282
63281
|
`, "utf-8");
|
|
63283
63282
|
}
|
|
63284
63283
|
async getAllLogs() {
|
|
@@ -63297,7 +63296,7 @@ var WarmHookLogsService = class {
|
|
|
63297
63296
|
continue;
|
|
63298
63297
|
}
|
|
63299
63298
|
try {
|
|
63300
|
-
const raw = await readFile24(
|
|
63299
|
+
const raw = await readFile24(join38(LOGS_DIR2, file), "utf-8");
|
|
63301
63300
|
const stored = JSON.parse(raw);
|
|
63302
63301
|
logs.push(withPreview2(stored));
|
|
63303
63302
|
} catch {
|
|
@@ -63335,7 +63334,7 @@ var WarmHookLogsService = class {
|
|
|
63335
63334
|
async getFullOutput(hookType, hookName) {
|
|
63336
63335
|
const filename = hookType === "global" ? GLOBAL_FILENAME : hookType === "environment" ? ENVIRONMENT_HOOK_LOG_FILENAME : repoHookLogFilename(hookName);
|
|
63337
63336
|
try {
|
|
63338
|
-
const raw = await readFile24(
|
|
63337
|
+
const raw = await readFile24(join38(LOGS_DIR2, filename), "utf-8");
|
|
63339
63338
|
const stored = JSON.parse(raw);
|
|
63340
63339
|
if (stored.hookType !== hookType || stored.hookName !== hookName) {
|
|
63341
63340
|
return null;
|
|
@@ -63354,8 +63353,8 @@ var warmHookLogsService = new WarmHookLogsService();
|
|
|
63354
63353
|
// src/services/warm-hooks-service.ts
|
|
63355
63354
|
async function readRepoWarmHook(repoPath) {
|
|
63356
63355
|
for (const filename of REPLICAS_CONFIG_FILENAMES) {
|
|
63357
|
-
const configPath =
|
|
63358
|
-
if (!
|
|
63356
|
+
const configPath = join39(repoPath, filename);
|
|
63357
|
+
if (!existsSync18(configPath)) {
|
|
63359
63358
|
continue;
|
|
63360
63359
|
}
|
|
63361
63360
|
try {
|
|
@@ -63616,7 +63615,7 @@ ${combinedScript}` : combinedScript;
|
|
|
63616
63615
|
|
|
63617
63616
|
// src/services/terminal-service.ts
|
|
63618
63617
|
import { randomUUID as randomUUID14 } from "crypto";
|
|
63619
|
-
import { existsSync as
|
|
63618
|
+
import { existsSync as existsSync19 } from "fs";
|
|
63620
63619
|
import { spawn as spawn11 } from "node-pty";
|
|
63621
63620
|
var MAX_REPLAY_CHARS = 1024 * 1024;
|
|
63622
63621
|
var MAX_TERMINAL_SESSIONS = 8;
|
|
@@ -63635,7 +63634,7 @@ var TerminalService = class {
|
|
|
63635
63634
|
});
|
|
63636
63635
|
}
|
|
63637
63636
|
const id = randomUUID14();
|
|
63638
|
-
const shell = process.env.SHELL &&
|
|
63637
|
+
const shell = process.env.SHELL && existsSync19(process.env.SHELL) ? process.env.SHELL : "/bin/bash";
|
|
63639
63638
|
const pty = spawn11(shell, ["-l"], {
|
|
63640
63639
|
name: "xterm-256color",
|
|
63641
63640
|
cols,
|
|
@@ -64677,7 +64676,7 @@ data: ${JSON.stringify("Terminal session not found")}
|
|
|
64677
64676
|
const logFiles = files.filter((f) => f.endsWith(".log"));
|
|
64678
64677
|
const sessions = await Promise.all(
|
|
64679
64678
|
logFiles.map(async (filename) => {
|
|
64680
|
-
const filePath =
|
|
64679
|
+
const filePath = join40(LOG_DIR, filename);
|
|
64681
64680
|
const fileStat = await stat7(filePath);
|
|
64682
64681
|
const sessionId = filename.replace(/\.log$/, "");
|
|
64683
64682
|
return {
|
|
@@ -64784,10 +64783,10 @@ var heartbeatService = new HeartbeatService();
|
|
|
64784
64783
|
|
|
64785
64784
|
// src/services/workspace-sdk-service.ts
|
|
64786
64785
|
import { cp, mkdir as mkdir23 } from "fs/promises";
|
|
64787
|
-
import { dirname as
|
|
64788
|
-
import { fileURLToPath as
|
|
64786
|
+
import { dirname as dirname20, resolve as resolve6 } from "path";
|
|
64787
|
+
import { fileURLToPath as fileURLToPath7 } from "url";
|
|
64789
64788
|
async function installWorkspaceSdk() {
|
|
64790
|
-
const source = resolve6(
|
|
64789
|
+
const source = resolve6(dirname20(fileURLToPath7(import.meta.url)), "../../workspace-sdk");
|
|
64791
64790
|
const targets = [
|
|
64792
64791
|
resolve6(ENGINE_ENV.HOME_DIR, "node_modules/@replicas/sdk"),
|
|
64793
64792
|
"/tmp/node_modules/@replicas/sdk"
|
|
@@ -64821,7 +64820,7 @@ async function timeStartupStep(name, fn) {
|
|
|
64821
64820
|
async function waitForInitializationGate() {
|
|
64822
64821
|
if (!ENGINE_ENV.REPLICAS_ENGINE_DEFER_INITIALIZATION) return;
|
|
64823
64822
|
const deadline = Date.now() + ENGINE_INIT_GATE_TIMEOUT_MS;
|
|
64824
|
-
while (!
|
|
64823
|
+
while (!existsSync20(SANDBOX_PATHS.ENGINE_INIT_GATE)) {
|
|
64825
64824
|
if (Date.now() >= deadline) {
|
|
64826
64825
|
throw new Error("Timed out waiting for deferred engine initialization gate");
|
|
64827
64826
|
}
|