replicas-engine 0.1.1725 → 0.1.1730
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-7DGBCD52.js → asp-host-K3ISVMG6.js} +6 -6
- package/dist/src/{chunk-DHAQM6LA.js → chunk-2HQP6MMR.js} +1 -1
- package/dist/src/{chunk-ZYRAETMX.js → chunk-BUJZF6CI.js} +2 -2
- package/dist/src/{chunk-ESENYL7M.js → chunk-ITJRSUSN.js} +1 -1
- package/dist/src/{chunk-YNHFXBHT.js → chunk-J6MIIMDU.js} +421 -227
- package/dist/src/{chunk-3SJP6X3P.js → chunk-KBE3MXTD.js} +86 -43
- package/dist/src/{chunk-EZWCNWX2.js → chunk-LIX74B2Y.js} +2 -2
- package/dist/src/{chunk-APCSKPLU.js → chunk-O2BDFDEA.js} +1 -1
- package/dist/src/{chunk-UDR2HT74.js → chunk-OW37FXFJ.js} +2 -2
- package/dist/src/{chunk-LIXZEE44.js → chunk-PIZ63O3B.js} +3 -3
- package/dist/src/{chunk-4YQ4UWFY.js → chunk-VHY4DMEA.js} +65 -8
- package/dist/src/{chunk-7ZDAVYTV.js → chunk-XCFPXSY4.js} +4 -0
- package/dist/src/codemode-mcp.js +4 -4
- package/dist/src/command-protection-hook.js +17 -6
- package/dist/src/headless-agent.js +48 -5
- package/dist/src/index.js +755 -192
- package/dist/src/post-tool-pr-hook.js +4 -3
- package/dist/src/subagent-mcp.js +1 -1
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@ import { createRequire as __createRequire } from 'node:module';
|
|
|
3
3
|
const require = __createRequire(import.meta.url);
|
|
4
4
|
import {
|
|
5
5
|
subagentCodexMcpConfig
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-2HQP6MMR.js";
|
|
7
7
|
import {
|
|
8
8
|
ENGINE_ENV,
|
|
9
9
|
UNQUOTED_PATHS_CONFIG,
|
|
@@ -15,15 +15,15 @@ import {
|
|
|
15
15
|
resolveDiffBase,
|
|
16
16
|
runGitCommand,
|
|
17
17
|
setAgentCredentialSnapshot
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-BUJZF6CI.js";
|
|
19
19
|
import {
|
|
20
20
|
AppServerProcess,
|
|
21
21
|
buildCodexAgentEnv
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-PIZ63O3B.js";
|
|
23
23
|
import {
|
|
24
24
|
SUBPROCESS_MAX_BUFFER,
|
|
25
25
|
execFileAsync
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-O2BDFDEA.js";
|
|
27
27
|
import {
|
|
28
28
|
isRecord
|
|
29
29
|
} from "./chunk-UZSNFLDQ.js";
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
CODEX_AUTH_ENV_KEYS,
|
|
32
32
|
CODEX_AUTH_ENV_KEYS_BY_METHOD,
|
|
33
33
|
CODEX_QUOTA_STATUS_EVENT_TYPE,
|
|
34
|
+
CREDENTIAL_SCOPE,
|
|
34
35
|
DEFAULT_CODEX_MODEL,
|
|
35
36
|
DEFAULT_HOOK_OUTPUT_PREVIEW_CHARS,
|
|
36
37
|
GIT_CREDENTIAL_HELPER_FILENAME,
|
|
@@ -49,7 +50,9 @@ import {
|
|
|
49
50
|
createSuccessResult,
|
|
50
51
|
decodePathSegments,
|
|
51
52
|
detectAgentQuotaLimit,
|
|
53
|
+
engineCredentialRefreshFailureSchema,
|
|
52
54
|
exhaustedUntil,
|
|
55
|
+
extractJsonObject,
|
|
53
56
|
fileContentDiff,
|
|
54
57
|
isGitHubUrl,
|
|
55
58
|
isSameCredential,
|
|
@@ -58,12 +61,14 @@ import {
|
|
|
58
61
|
normalizeCodexAspTranscriptStatus,
|
|
59
62
|
parseCodeHostPrUrl,
|
|
60
63
|
parseGitRemote,
|
|
64
|
+
parsePosixEnv,
|
|
61
65
|
readOllamaAuthEnv,
|
|
62
66
|
resolveOpenAICompatibleModelsUrl,
|
|
67
|
+
serializePosixEnvFile,
|
|
63
68
|
shrunkImageSize,
|
|
64
69
|
splitManagerInstructions,
|
|
65
70
|
withTimeout
|
|
66
|
-
} from "./chunk-
|
|
71
|
+
} from "./chunk-J6MIIMDU.js";
|
|
67
72
|
|
|
68
73
|
// src/managers/codex-token-manager.ts
|
|
69
74
|
import { promises as fs } from "fs";
|
|
@@ -146,6 +151,10 @@ function credentialSwapError(error) {
|
|
|
146
151
|
code: message.includes('"code":"no_credentials"') ? "no_credentials" : "refresh_failed"
|
|
147
152
|
});
|
|
148
153
|
}
|
|
154
|
+
function refreshRevocation(error) {
|
|
155
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
156
|
+
return engineCredentialRefreshFailureSchema.safeParse(extractJsonObject(message)).data?.revoke;
|
|
157
|
+
}
|
|
149
158
|
function refreshDelayMs(expiresAtMs, maxMs = 5 * 60 * 1e3) {
|
|
150
159
|
const ttlMs = expiresAtMs - Date.now();
|
|
151
160
|
return Number.isFinite(ttlMs) ? Math.max(1e3, Math.min(maxMs, Math.floor(ttlMs * 0.8))) : maxMs;
|
|
@@ -309,6 +318,32 @@ var BaseRefreshManager = class {
|
|
|
309
318
|
}
|
|
310
319
|
};
|
|
311
320
|
|
|
321
|
+
// src/services/agent-logins.ts
|
|
322
|
+
import { readFileSync, writeFileSync } from "fs";
|
|
323
|
+
import { rm } from "fs/promises";
|
|
324
|
+
import { homedir } from "os";
|
|
325
|
+
import { join } from "path";
|
|
326
|
+
async function withdrawAgentLogin(provider, { envKeys, files }) {
|
|
327
|
+
if (ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS[provider]?.scope === CREDENTIAL_SCOPE.USER) return false;
|
|
328
|
+
for (const key of envKeys) {
|
|
329
|
+
Reflect.deleteProperty(ENGINE_ENV, key);
|
|
330
|
+
delete process.env[key];
|
|
331
|
+
}
|
|
332
|
+
const { [provider]: _withdrawn, ...remaining } = ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS;
|
|
333
|
+
ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS = remaining;
|
|
334
|
+
process.env.REPLICAS_AGENT_CREDENTIALS = JSON.stringify(remaining);
|
|
335
|
+
await Promise.all(files.map((file) => rm(file, { force: true })));
|
|
336
|
+
const path2 = join(homedir(), ".replicas", "runtime-env.sh");
|
|
337
|
+
const persisted = parsePosixEnv(readFileSync(path2, "utf-8"));
|
|
338
|
+
for (const key of envKeys) delete persisted.values[key];
|
|
339
|
+
writeFileSync(path2, serializePosixEnvFile(
|
|
340
|
+
{ ...persisted.values, REPLICAS_AGENT_CREDENTIALS: JSON.stringify(remaining) },
|
|
341
|
+
/* @__PURE__ */ new Set([...persisted.unsetKeys, ...envKeys])
|
|
342
|
+
));
|
|
343
|
+
if (provider === "codex") await (await import("./asp-host-K3ISVMG6.js")).restartCodexAspHostIfRunning();
|
|
344
|
+
return true;
|
|
345
|
+
}
|
|
346
|
+
|
|
312
347
|
// src/utils/transcript-secrets.ts
|
|
313
348
|
var BACKSLASH = 92;
|
|
314
349
|
var FILLER = 42;
|
|
@@ -463,7 +498,7 @@ var CodexTokenManager = class extends BaseRefreshManager {
|
|
|
463
498
|
await this.applyCredentialUpdate(++this.credentialGeneration, async () => {
|
|
464
499
|
await this.applyCredentialsResponse(data);
|
|
465
500
|
setAgentCredentialSnapshot("codex", data);
|
|
466
|
-
const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-
|
|
501
|
+
const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-K3ISVMG6.js");
|
|
467
502
|
await restartCodexAspHostIfRunning2();
|
|
468
503
|
});
|
|
469
504
|
await this.start(true);
|
|
@@ -477,15 +512,19 @@ var CodexTokenManager = class extends BaseRefreshManager {
|
|
|
477
512
|
signal: AbortSignal.timeout(12e4)
|
|
478
513
|
});
|
|
479
514
|
if (!response.ok) {
|
|
480
|
-
const
|
|
481
|
-
|
|
515
|
+
const error = new Error(`Credentials refresh failed: ${response.status} ${await response.text()}`);
|
|
516
|
+
const revocation = refreshRevocation(error);
|
|
517
|
+
if (revocation) await this.applyCredentialUpdate(generation, async () => {
|
|
518
|
+
await withdrawAgentLogin("codex", revocation);
|
|
519
|
+
});
|
|
520
|
+
throw error;
|
|
482
521
|
}
|
|
483
522
|
const data = await response.json();
|
|
484
523
|
await this.applyCredentialUpdate(generation, async () => {
|
|
485
524
|
const accountChanged = ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS.codex?.credentialId !== data.credentialId;
|
|
486
525
|
await this.applyCredentialsResponse(data);
|
|
487
526
|
if (restartOnChange && (accountChanged || CODEX_AUTH_ENV_KEYS.some((key, index) => process.env[key] !== previousEnv[index]))) {
|
|
488
|
-
const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-
|
|
527
|
+
const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-K3ISVMG6.js");
|
|
489
528
|
await restartCodexAspHostIfRunning2();
|
|
490
529
|
}
|
|
491
530
|
setAgentCredentialSnapshot("codex", data);
|
|
@@ -598,33 +637,35 @@ var CodexTokenManager = class extends BaseRefreshManager {
|
|
|
598
637
|
var codexTokenManager = new CodexTokenManager();
|
|
599
638
|
|
|
600
639
|
// src/managers/codex-asp/mappers.ts
|
|
601
|
-
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
640
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
602
641
|
|
|
603
642
|
// src/git/service.ts
|
|
604
643
|
import { readdir, readFile as readFile3, realpath, stat } from "fs/promises";
|
|
605
644
|
import { spawn } from "child_process";
|
|
606
|
-
import { isAbsolute, join as
|
|
645
|
+
import { isAbsolute, join as join5 } from "path";
|
|
607
646
|
|
|
608
647
|
// src/utils/state.ts
|
|
609
648
|
import { readFile as readFile2, mkdir as mkdir2 } from "fs/promises";
|
|
610
649
|
import { existsSync } from "fs";
|
|
611
|
-
import { join as
|
|
650
|
+
import { join as join4 } from "path";
|
|
612
651
|
|
|
613
652
|
// src/services/chat/history-paths.ts
|
|
614
|
-
import { join } from "path";
|
|
615
|
-
var ENGINE_DIR =
|
|
616
|
-
var CHATS_FILE =
|
|
617
|
-
var CLAUDE_HISTORY_DIR =
|
|
618
|
-
var CODEX_HISTORY_DIR =
|
|
619
|
-
var CURSOR_HISTORY_DIR =
|
|
620
|
-
var OPENCODE_HISTORY_DIR =
|
|
621
|
-
var PI_HISTORY_DIR =
|
|
622
|
-
var
|
|
623
|
-
var
|
|
653
|
+
import { join as join2 } from "path";
|
|
654
|
+
var ENGINE_DIR = join2(process.env.REPLICAS_ENGINE_STATE_DIR ?? "/var/lib/replicas", "engine");
|
|
655
|
+
var CHATS_FILE = join2(ENGINE_DIR, "chats.json");
|
|
656
|
+
var CLAUDE_HISTORY_DIR = join2(ENGINE_DIR, "claude-histories");
|
|
657
|
+
var CODEX_HISTORY_DIR = join2(ENGINE_DIR, "codex-histories");
|
|
658
|
+
var CURSOR_HISTORY_DIR = join2(ENGINE_DIR, "cursor-histories");
|
|
659
|
+
var OPENCODE_HISTORY_DIR = join2(ENGINE_DIR, "opencode-histories");
|
|
660
|
+
var PI_HISTORY_DIR = join2(ENGINE_DIR, "pi-histories");
|
|
661
|
+
var GEMINI_HISTORY_DIR = join2(ENGINE_DIR, "gemini-histories");
|
|
662
|
+
var MUSE_HISTORY_DIR = join2(ENGINE_DIR, "muse-histories");
|
|
663
|
+
var FORKS_DIR = join2(ENGINE_DIR, "forks");
|
|
624
664
|
var HISTORY_DIR_BY_PROVIDER = {
|
|
625
665
|
claude: CLAUDE_HISTORY_DIR,
|
|
626
666
|
codex: CODEX_HISTORY_DIR,
|
|
627
667
|
cursor: CURSOR_HISTORY_DIR,
|
|
668
|
+
gemini: GEMINI_HISTORY_DIR,
|
|
628
669
|
muse: MUSE_HISTORY_DIR,
|
|
629
670
|
opencode: OPENCODE_HISTORY_DIR,
|
|
630
671
|
pi: PI_HISTORY_DIR
|
|
@@ -633,7 +674,7 @@ var HISTORY_DIR_BY_PROVIDER = {
|
|
|
633
674
|
// src/utils/file.ts
|
|
634
675
|
import { randomUUID } from "crypto";
|
|
635
676
|
import { mkdir, readFile, rename, unlink, writeFile } from "fs/promises";
|
|
636
|
-
import { dirname, join as
|
|
677
|
+
import { dirname, join as join3 } from "path";
|
|
637
678
|
|
|
638
679
|
// src/utils/async-lock.ts
|
|
639
680
|
var AsyncLock = class {
|
|
@@ -667,8 +708,8 @@ async function writeSecureCredentialFile(filePath, content, options) {
|
|
|
667
708
|
await atomicWriteFile(filePath, content, { mode: 384 });
|
|
668
709
|
}
|
|
669
710
|
async function configureManagedGitCredentialHelper(homeDir) {
|
|
670
|
-
const credentialsPath =
|
|
671
|
-
const helperPath =
|
|
711
|
+
const credentialsPath = join3(homeDir, ".git-credentials");
|
|
712
|
+
const helperPath = join3(homeDir, GIT_CREDENTIAL_HELPER_FILENAME);
|
|
672
713
|
await atomicWriteFile(helperPath, buildGitCredentialHelperScript(credentialsPath), { mode: 448 });
|
|
673
714
|
await execFileAsync("git", ["config", "--global", "--replace-all", "credential.helper", helperPath], {
|
|
674
715
|
env: { ...process.env, HOME: homeDir }
|
|
@@ -704,7 +745,7 @@ function removeCredentialFileLines(filePath, shouldRemove) {
|
|
|
704
745
|
}
|
|
705
746
|
|
|
706
747
|
// src/utils/state.ts
|
|
707
|
-
var STATE_FILE =
|
|
748
|
+
var STATE_FILE = join4(ENGINE_DIR, "engine-state.json");
|
|
708
749
|
var DEFAULT_STATE = {
|
|
709
750
|
repos: {},
|
|
710
751
|
removedRepos: {}
|
|
@@ -851,13 +892,13 @@ var GitService = class {
|
|
|
851
892
|
const repos = [];
|
|
852
893
|
let complete = true;
|
|
853
894
|
for (const entry of entries) {
|
|
854
|
-
const fullPath =
|
|
895
|
+
const fullPath = join5(root, entry);
|
|
855
896
|
try {
|
|
856
897
|
const entryStat = await stat(fullPath);
|
|
857
898
|
if (!entryStat.isDirectory()) {
|
|
858
899
|
continue;
|
|
859
900
|
}
|
|
860
|
-
const hasGit = Boolean(await this.safeStat(
|
|
901
|
+
const hasGit = Boolean(await this.safeStat(join5(fullPath, ".git")));
|
|
861
902
|
if (!hasGit) {
|
|
862
903
|
continue;
|
|
863
904
|
}
|
|
@@ -878,8 +919,8 @@ var GitService = class {
|
|
|
878
919
|
const removed = new Map(Object.entries(state.removedRepos));
|
|
879
920
|
for (const repo of Object.values(state.repos)) {
|
|
880
921
|
if (!isAbsolute(repo.name)) continue;
|
|
881
|
-
const exists = Boolean(await this.safeStat(
|
|
882
|
-
const origin = exists ? (await readFile3(
|
|
922
|
+
const exists = Boolean(await this.safeStat(join5(repo.path, ".git")));
|
|
923
|
+
const origin = exists ? (await readFile3(join5(repo.path, ".git", "config"), "utf-8").catch(() => "")).match(/\[remote "origin"\][^[]*?\burl\s*=\s*(\S+)/)?.[1] ?? null : null;
|
|
883
924
|
const known = this.trackedCloneOrigins.has(repo.path) ? this.trackedCloneOrigins.get(repo.path) : origin;
|
|
884
925
|
if (exists && origin === known) {
|
|
885
926
|
this.trackedCloneOrigins.set(repo.path, origin);
|
|
@@ -903,7 +944,7 @@ var GitService = class {
|
|
|
903
944
|
const commonDir = await runGitCommand(["rev-parse", "--path-format=absolute", "--git-common-dir"], worktree).catch(() => null);
|
|
904
945
|
if (!commonDir) return false;
|
|
905
946
|
const { repos } = await this.listTrackedRepositories();
|
|
906
|
-
if (repos.some((repo) => repo.path === worktree ||
|
|
947
|
+
if (repos.some((repo) => repo.path === worktree || join5(repo.path, ".git") === commonDir)) return false;
|
|
907
948
|
const defaultBranch = await this.resolveDefaultBranch(worktree);
|
|
908
949
|
await saveRepoState(worktree, {}, {
|
|
909
950
|
name: worktree,
|
|
@@ -1053,7 +1094,7 @@ var GitService = class {
|
|
|
1053
1094
|
for (let i = 0; i < paths.length; i += UNTRACKED_STAT_CONCURRENCY) {
|
|
1054
1095
|
const batch = await Promise.all(paths.slice(i, i + UNTRACKED_STAT_CONCURRENCY).map(async (path2) => {
|
|
1055
1096
|
try {
|
|
1056
|
-
return { path: path2, size: (await stat(
|
|
1097
|
+
return { path: path2, size: (await stat(join5(repoPath, path2))).size };
|
|
1057
1098
|
} catch {
|
|
1058
1099
|
return null;
|
|
1059
1100
|
}
|
|
@@ -1133,7 +1174,7 @@ Binary files /dev/null and ${quote(`b/${path2}`)} differ
|
|
|
1133
1174
|
for (const { path: path2, tooLarge } of files) {
|
|
1134
1175
|
if (tooLarge) continue;
|
|
1135
1176
|
try {
|
|
1136
|
-
const contents = await readFile3(
|
|
1177
|
+
const contents = await readFile3(join5(repoPath, path2));
|
|
1137
1178
|
if (contents.length === 0 || contents.includes(0)) {
|
|
1138
1179
|
continue;
|
|
1139
1180
|
}
|
|
@@ -1330,7 +1371,7 @@ Binary files /dev/null and ${quote(`b/${path2}`)} differ
|
|
|
1330
1371
|
}
|
|
1331
1372
|
async getGitLabAccessToken(host) {
|
|
1332
1373
|
try {
|
|
1333
|
-
const credentials = await readFile3(
|
|
1374
|
+
const credentials = await readFile3(join5(ENGINE_ENV.HOME_DIR, ".git-credentials"), "utf-8");
|
|
1334
1375
|
for (const line of credentials.split("\n")) {
|
|
1335
1376
|
const trimmed = line.trim();
|
|
1336
1377
|
if (!trimmed) continue;
|
|
@@ -1414,8 +1455,8 @@ async function getAgentAdditionalDirectories() {
|
|
|
1414
1455
|
// src/utils/image-utils.ts
|
|
1415
1456
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
1416
1457
|
import { mkdir as mkdir3, unlink as unlink2, writeFile as writeFile2 } from "fs/promises";
|
|
1417
|
-
import { homedir } from "os";
|
|
1418
|
-
import { join as
|
|
1458
|
+
import { homedir as homedir2 } from "os";
|
|
1459
|
+
import { join as join6 } from "path";
|
|
1419
1460
|
import { createRequire } from "module";
|
|
1420
1461
|
import { MessageChannel, Worker } from "worker_threads";
|
|
1421
1462
|
function isImageMediaType(value) {
|
|
@@ -1509,14 +1550,14 @@ async function normalizeImages(images) {
|
|
|
1509
1550
|
}
|
|
1510
1551
|
return normalized;
|
|
1511
1552
|
}
|
|
1512
|
-
async function saveNormalizedImagesToTempFiles(images, tempImageDir =
|
|
1553
|
+
async function saveNormalizedImagesToTempFiles(images, tempImageDir = join6(homedir2(), ".replicas", "codex", "temp-images")) {
|
|
1513
1554
|
await mkdir3(tempImageDir, { recursive: true });
|
|
1514
1555
|
const tempPaths = [];
|
|
1515
1556
|
try {
|
|
1516
1557
|
for (const image of images) {
|
|
1517
1558
|
const ext = image.source.media_type.split("/")[1] || "png";
|
|
1518
1559
|
const filename = `img_${randomUUID2()}.${ext}`;
|
|
1519
|
-
const filepath =
|
|
1560
|
+
const filepath = join6(tempImageDir, filename);
|
|
1520
1561
|
await writeFile2(filepath, Buffer.from(image.source.data, "base64"));
|
|
1521
1562
|
tempPaths.push(filepath);
|
|
1522
1563
|
}
|
|
@@ -1724,7 +1765,7 @@ function userImageForLocalPath(path2) {
|
|
|
1724
1765
|
const image = {
|
|
1725
1766
|
type: "image",
|
|
1726
1767
|
mediaType: inferMediaType(path2),
|
|
1727
|
-
data:
|
|
1768
|
+
data: readFileSync2(path2).toString("base64")
|
|
1728
1769
|
};
|
|
1729
1770
|
if (image.data.length > 0) localImageCache.set(path2, image);
|
|
1730
1771
|
return image;
|
|
@@ -2067,9 +2108,9 @@ async function buildTurnStartParams(threadId, request, serviceTier, unreadReques
|
|
|
2067
2108
|
// src/managers/codex-asp/openai-compatible-model-catalog.ts
|
|
2068
2109
|
import { writeFile as writeFile3 } from "fs/promises";
|
|
2069
2110
|
import { tmpdir } from "os";
|
|
2070
|
-
import { join as
|
|
2111
|
+
import { join as join7 } from "path";
|
|
2071
2112
|
var CATALOG_TTL_MS = 6e4;
|
|
2072
|
-
var CODEX_MODEL_CATALOG_PATH =
|
|
2113
|
+
var CODEX_MODEL_CATALOG_PATH = join7(tmpdir(), "replicas-openai-compatible-model-catalog.json");
|
|
2073
2114
|
var cachedCatalog = null;
|
|
2074
2115
|
async function writeCodexModelCatalog(modelsUrl) {
|
|
2075
2116
|
const ollama = ENGINE_ENV.REPLICAS_CODEX_AUTH_METHOD === "ollama" ? readOllamaAuthEnv("codex", process.env) : null;
|
|
@@ -2254,6 +2295,7 @@ export {
|
|
|
2254
2295
|
routineRefreshRequest,
|
|
2255
2296
|
forgetExhaustedCredentials,
|
|
2256
2297
|
recordExhaustedCredential,
|
|
2298
|
+
refreshRevocation,
|
|
2257
2299
|
refreshDelayMs,
|
|
2258
2300
|
BaseRefreshManager,
|
|
2259
2301
|
AsyncLock,
|
|
@@ -2278,6 +2320,8 @@ export {
|
|
|
2278
2320
|
saveRepoState,
|
|
2279
2321
|
gitService,
|
|
2280
2322
|
applyAuthEnvTransition,
|
|
2323
|
+
CodexAspAuthMethodChangedError,
|
|
2324
|
+
codexTokenManager,
|
|
2281
2325
|
getAgentAdditionalDirectories,
|
|
2282
2326
|
normalizeImages,
|
|
2283
2327
|
removeTempImageFiles,
|
|
@@ -2321,6 +2365,5 @@ export {
|
|
|
2321
2365
|
restartCodexAspHostIfRunning,
|
|
2322
2366
|
listCodexModels,
|
|
2323
2367
|
listCodexModelsForDetails,
|
|
2324
|
-
|
|
2325
|
-
codexTokenManager
|
|
2368
|
+
withdrawAgentLogin
|
|
2326
2369
|
};
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
ENGINE_ENV,
|
|
6
6
|
monolithRequest,
|
|
7
7
|
runGitCommand
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-BUJZF6CI.js";
|
|
9
9
|
import {
|
|
10
10
|
COMMAND_PROTECTION_MAX_MESSAGE_FILE_BYTES,
|
|
11
11
|
COMMAND_PROTECTION_REPO_GIT_ARGS,
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
parseCommandProtectionRequest,
|
|
19
19
|
toCommandProtectionRepoState,
|
|
20
20
|
withRetry
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-J6MIIMDU.js";
|
|
22
22
|
|
|
23
23
|
// src/services/command-protection-service.ts
|
|
24
24
|
import { readFile, stat } from "fs/promises";
|
|
@@ -3,7 +3,7 @@ import { createRequire as __createRequire } from 'node:module';
|
|
|
3
3
|
const require = __createRequire(import.meta.url);
|
|
4
4
|
import {
|
|
5
5
|
HOOK_EXEC_MAX_BUFFER_BYTES
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-J6MIIMDU.js";
|
|
7
7
|
|
|
8
8
|
// src/utils/exec.ts
|
|
9
9
|
import { exec, execFile } from "child_process";
|
|
@@ -3,10 +3,10 @@ import { createRequire as __createRequire } from 'node:module';
|
|
|
3
3
|
const require = __createRequire(import.meta.url);
|
|
4
4
|
import {
|
|
5
5
|
PI_MCP_CONFIG_PATH
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-XCFPXSY4.js";
|
|
7
7
|
import {
|
|
8
8
|
engineScriptProcess
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-2HQP6MMR.js";
|
|
10
10
|
import {
|
|
11
11
|
isRecord
|
|
12
12
|
} from "./chunk-UZSNFLDQ.js";
|
|
@@ -3,10 +3,10 @@ import { createRequire as __createRequire } from 'node:module';
|
|
|
3
3
|
const require = __createRequire(import.meta.url);
|
|
4
4
|
import {
|
|
5
5
|
execFileAsync
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-O2BDFDEA.js";
|
|
7
7
|
import {
|
|
8
8
|
isVersionBelow
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-J6MIIMDU.js";
|
|
10
10
|
|
|
11
11
|
// src/utils/codex-agent-env.ts
|
|
12
12
|
function buildCodexAgentEnv(source = process.env) {
|
|
@@ -244,7 +244,7 @@ function getCodexModelProvider(method) {
|
|
|
244
244
|
if (method === "foundry") return "azure";
|
|
245
245
|
return method === "ollama" || method === "openai-compatible" ? "replicas_openai_compatible" : "openai";
|
|
246
246
|
}
|
|
247
|
-
var ENGINE_PACKAGE_VERSION = "0.1.
|
|
247
|
+
var ENGINE_PACKAGE_VERSION = "0.1.1730";
|
|
248
248
|
var INITIALIZE_METHOD = "initialize";
|
|
249
249
|
var INITIALIZED_NOTIFICATION = "initialized";
|
|
250
250
|
var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
|
|
@@ -3,10 +3,10 @@ import { createRequire as __createRequire } from 'node:module';
|
|
|
3
3
|
const require = __createRequire(import.meta.url);
|
|
4
4
|
import {
|
|
5
5
|
OPENCODE_AUTH_PATH
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-XCFPXSY4.js";
|
|
7
7
|
import {
|
|
8
8
|
AspClient
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-PIZ63O3B.js";
|
|
10
10
|
import {
|
|
11
11
|
ASTER_BASE_URL,
|
|
12
12
|
ASTER_PROVIDER,
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
isRecord,
|
|
19
19
|
readOllamaAuthEnv,
|
|
20
20
|
readOpenAICompatibleAuthEnv
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-J6MIIMDU.js";
|
|
22
22
|
|
|
23
23
|
// src/managers/codex-asp/notification-dispatch.ts
|
|
24
24
|
var TURN_STARTED_METHOD = "turn/started";
|
|
@@ -63,9 +63,9 @@ function recoverCompletedTurn(turn, completedItems, agentMessageDeltas) {
|
|
|
63
63
|
import { existsSync } from "fs";
|
|
64
64
|
import { readFile } from "fs/promises";
|
|
65
65
|
import { z } from "zod";
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
var
|
|
66
|
+
|
|
67
|
+
// src/utils/thinking-variant.ts
|
|
68
|
+
var VARIANT_CANDIDATES_BY_THINKING_LEVEL = {
|
|
69
69
|
low: ["low"],
|
|
70
70
|
medium: ["medium"],
|
|
71
71
|
high: ["high"],
|
|
@@ -74,13 +74,20 @@ var OPENCODE_VARIANT_CANDIDATES_BY_THINKING_LEVEL = {
|
|
|
74
74
|
ultra: ["max", "xhigh", "high"],
|
|
75
75
|
ultracode: ["max", "xhigh", "high"]
|
|
76
76
|
};
|
|
77
|
+
function thinkingVariant(supported, thinkingLevel) {
|
|
78
|
+
return thinkingLevel ? VARIANT_CANDIDATES_BY_THINKING_LEVEL[thinkingLevel].find((variant) => supported?.has(variant)) : void 0;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// src/managers/opencode-config.ts
|
|
82
|
+
var OPENCODE_WORKSPACE_PERMISSION = "allow";
|
|
83
|
+
var OPENROUTER_IGNORED_PROVIDERS = ["baseten"];
|
|
77
84
|
async function fetchOpencodeModelVariants(client, directory, provider) {
|
|
78
85
|
const result = await client.config.providers({ directory }, { throwOnError: true });
|
|
79
86
|
const models = result.data.providers.find((candidate) => candidate.id === provider)?.models ?? {};
|
|
80
87
|
return new Map(Object.entries(models).map(([id, model]) => [id, new Set(Object.keys(model.variants ?? {}))]));
|
|
81
88
|
}
|
|
82
89
|
function opencodeThinkingVariant(variants, thinkingLevel) {
|
|
83
|
-
return
|
|
90
|
+
return thinkingVariant(variants, thinkingLevel);
|
|
84
91
|
}
|
|
85
92
|
var opencodeAuthSchema = z.record(z.string(), z.object({
|
|
86
93
|
type: z.string().optional(),
|
|
@@ -209,6 +216,50 @@ function museTurnStartParams(sessionId, input, thinkingLevel) {
|
|
|
209
216
|
return { commandId: uuidV7(), sessionId, input, reasoningEffort: codexReasoningEffortForThinkingLevel(thinkingLevel) };
|
|
210
217
|
}
|
|
211
218
|
|
|
219
|
+
// src/managers/gemini-acp.ts
|
|
220
|
+
import { spawn as spawn2 } from "child_process";
|
|
221
|
+
function spawnGeminiAcp(workingDirectory, env) {
|
|
222
|
+
const child = spawn2("agy", ["acp", "--dangerously-skip-permissions", "--disable-telemetry"], {
|
|
223
|
+
cwd: workingDirectory,
|
|
224
|
+
env: { ...process.env, AGY_CLI_DISABLE_AUTO_UPDATE: "1", NO_COLOR: "1", ...env },
|
|
225
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
226
|
+
});
|
|
227
|
+
return { child, client: new AspClient({ stdin: child.stdin, stdout: child.stdout, jsonRpcVersion: "2.0" }) };
|
|
228
|
+
}
|
|
229
|
+
async function initializeGeminiAcp(client, timeoutMs) {
|
|
230
|
+
await client.request("initialize", {
|
|
231
|
+
protocolVersion: 1,
|
|
232
|
+
clientCapabilities: { fs: { readTextFile: false, writeTextFile: false }, terminal: false },
|
|
233
|
+
clientInfo: { name: "replicas", title: "Replicas", version: "1" }
|
|
234
|
+
}, { timeoutMs });
|
|
235
|
+
}
|
|
236
|
+
async function startGeminiSession(client, params, timeoutMs) {
|
|
237
|
+
const request = {
|
|
238
|
+
cwd: params.cwd,
|
|
239
|
+
mcpServers: [],
|
|
240
|
+
...params.systemPrompt ? { _meta: { antigravity: { systemPrompt: { append: params.systemPrompt } } } } : {}
|
|
241
|
+
};
|
|
242
|
+
const result = params.resumeSessionId ? await client.request("session/resume", { ...request, sessionId: params.resumeSessionId }, { timeoutMs }) : await client.request("session/new", request, { timeoutMs });
|
|
243
|
+
const sessionId = params.resumeSessionId ?? (isRecord(result) ? result.sessionId : void 0);
|
|
244
|
+
if (typeof sessionId !== "string") throw new Error("Antigravity did not return a session id.");
|
|
245
|
+
return { sessionId, configOptions: isRecord(result) && Array.isArray(result.configOptions) ? result.configOptions : [] };
|
|
246
|
+
}
|
|
247
|
+
function geminiSelectOption(configOptions, category) {
|
|
248
|
+
const option = configOptions.find((candidate) => isRecord(candidate) && (candidate.category === category || candidate.id === category));
|
|
249
|
+
if (!isRecord(option) || option.type !== "select" || typeof option.id !== "string" || !Array.isArray(option.options)) return null;
|
|
250
|
+
const values = option.options.flatMap((entry) => isRecord(entry) && Array.isArray(entry.options) ? entry.options : [entry]).flatMap((entry) => isRecord(entry) && typeof entry.value === "string" ? [entry.value] : []);
|
|
251
|
+
return { id: option.id, currentValue: typeof option.currentValue === "string" ? option.currentValue : null, values };
|
|
252
|
+
}
|
|
253
|
+
async function selectGeminiModel(client, session, model, timeoutMs) {
|
|
254
|
+
const option = geminiSelectOption(session.configOptions, "model");
|
|
255
|
+
if (!option || option.currentValue === model) return;
|
|
256
|
+
if (!option.values.includes(model)) {
|
|
257
|
+
throw new Error(`${model} is not available for this Google account. Available models: ${option.values.join(", ")}.`);
|
|
258
|
+
}
|
|
259
|
+
const result = await client.request("session/set_config_option", { sessionId: session.sessionId, configId: option.id, value: model }, { timeoutMs });
|
|
260
|
+
if (isRecord(result) && Array.isArray(result.configOptions)) session.configOptions = result.configOptions;
|
|
261
|
+
}
|
|
262
|
+
|
|
212
263
|
export {
|
|
213
264
|
TURN_STARTED_METHOD,
|
|
214
265
|
TURN_COMPLETED_METHOD,
|
|
@@ -230,6 +281,7 @@ export {
|
|
|
230
281
|
THREAD_STATUS_CHANGED_METHOD,
|
|
231
282
|
dispatchAspNotification,
|
|
232
283
|
recoverCompletedTurn,
|
|
284
|
+
thinkingVariant,
|
|
233
285
|
fetchOpencodeModelVariants,
|
|
234
286
|
opencodeThinkingVariant,
|
|
235
287
|
hasOpencodeCredentials,
|
|
@@ -241,5 +293,10 @@ export {
|
|
|
241
293
|
spawnMuseMsp,
|
|
242
294
|
initializeMuse,
|
|
243
295
|
startMuseSession,
|
|
244
|
-
museTurnStartParams
|
|
296
|
+
museTurnStartParams,
|
|
297
|
+
spawnGeminiAcp,
|
|
298
|
+
initializeGeminiAcp,
|
|
299
|
+
startGeminiSession,
|
|
300
|
+
geminiSelectOption,
|
|
301
|
+
selectGeminiModel
|
|
245
302
|
};
|
|
@@ -8,11 +8,15 @@ import { join } from "path";
|
|
|
8
8
|
var OPENCODE_AUTH_PATH = join(homedir(), ".local", "share", "opencode", "auth.json");
|
|
9
9
|
var PI_AUTH_PATH = join(homedir(), ".pi", "agent", "auth.json");
|
|
10
10
|
var PI_MCP_CONFIG_PATH = join(homedir(), ".pi", "agent", "mcp.json");
|
|
11
|
+
var GEMINI_CLI_PATH = "/usr/local/bin/agy";
|
|
12
|
+
var GEMINI_AUTH_PATH = join(homedir(), ".gemini", "antigravity-cli", "antigravity-oauth-token");
|
|
11
13
|
var MUSE_AUTH_PATH = join(homedir(), ".config", "muse", "auth.json");
|
|
12
14
|
|
|
13
15
|
export {
|
|
14
16
|
OPENCODE_AUTH_PATH,
|
|
15
17
|
PI_AUTH_PATH,
|
|
16
18
|
PI_MCP_CONFIG_PATH,
|
|
19
|
+
GEMINI_CLI_PATH,
|
|
20
|
+
GEMINI_AUTH_PATH,
|
|
17
21
|
MUSE_AUTH_PATH
|
|
18
22
|
};
|
package/dist/src/codemode-mcp.js
CHANGED
|
@@ -4,15 +4,15 @@ const require = __createRequire(import.meta.url);
|
|
|
4
4
|
import {
|
|
5
5
|
getManagedPiMcpServers,
|
|
6
6
|
managedMcpServerProcess
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-OW37FXFJ.js";
|
|
8
|
+
import "./chunk-XCFPXSY4.js";
|
|
9
|
+
import "./chunk-2HQP6MMR.js";
|
|
10
10
|
import {
|
|
11
11
|
isRecord
|
|
12
12
|
} from "./chunk-UZSNFLDQ.js";
|
|
13
13
|
import {
|
|
14
14
|
rankToolsByQuery
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-J6MIIMDU.js";
|
|
16
16
|
import "./chunk-VEQXQN22.js";
|
|
17
17
|
|
|
18
18
|
// src/codemode-mcp.ts
|
|
@@ -3,13 +3,13 @@ import { createRequire as __createRequire } from 'node:module';
|
|
|
3
3
|
const require = __createRequire(import.meta.url);
|
|
4
4
|
import {
|
|
5
5
|
evaluateCommandProtection
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
8
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-LIX74B2Y.js";
|
|
7
|
+
import "./chunk-BUJZF6CI.js";
|
|
8
|
+
import "./chunk-O2BDFDEA.js";
|
|
9
9
|
import {
|
|
10
10
|
isRecord
|
|
11
11
|
} from "./chunk-UZSNFLDQ.js";
|
|
12
|
-
import "./chunk-
|
|
12
|
+
import "./chunk-J6MIIMDU.js";
|
|
13
13
|
import "./chunk-VEQXQN22.js";
|
|
14
14
|
|
|
15
15
|
// src/command-protection-hook.ts
|
|
@@ -23,20 +23,31 @@ function writeResult(allowed, reason) {
|
|
|
23
23
|
process.stdout.write(JSON.stringify({ allowed, reason }));
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
|
+
if (provider === "gemini") {
|
|
27
|
+
process.stdout.write(JSON.stringify(allowed ? { decision: "allow" } : { decision: "deny", reason }));
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
26
30
|
if (!allowed) {
|
|
27
31
|
process.stderr.write(reason ?? "Blocked by Replicas command protection.");
|
|
28
32
|
process.exitCode = 2;
|
|
29
33
|
}
|
|
30
34
|
}
|
|
31
35
|
async function main() {
|
|
32
|
-
if (provider !== "cursor" && provider !== "opencode") {
|
|
36
|
+
if (provider !== "cursor" && provider !== "opencode" && provider !== "gemini") {
|
|
33
37
|
throw new Error("Unknown command protection hook provider.");
|
|
34
38
|
}
|
|
35
39
|
let body = "";
|
|
36
40
|
for await (const chunk of process.stdin) body += chunk;
|
|
37
41
|
const input = JSON.parse(body);
|
|
38
42
|
if (!isRecord(input)) throw new Error("Invalid command protection hook input.");
|
|
39
|
-
const
|
|
43
|
+
const geminiCall = isRecord(input.toolCall) ? input.toolCall : null;
|
|
44
|
+
const payload = geminiCall ? {
|
|
45
|
+
name: geminiCall.name,
|
|
46
|
+
// The shell parser reads `command`, so run_command's `CommandLine` must reach it under that name.
|
|
47
|
+
arguments: isRecord(geminiCall.args) && typeof geminiCall.args.CommandLine === "string" ? { ...geminiCall.args, command: geminiCall.args.CommandLine } : geminiCall.args,
|
|
48
|
+
cwd: isRecord(geminiCall.args) && geminiCall.args.Cwd ? geminiCall.args.Cwd : input.cwd,
|
|
49
|
+
call_id: geminiCall.id
|
|
50
|
+
} : input;
|
|
40
51
|
const toolName = typeof payload.tool_name === "string" ? payload.tool_name : typeof payload.name === "string" ? payload.name : "tool";
|
|
41
52
|
const toolInput = payload.tool_input ?? payload.arguments ?? payload;
|
|
42
53
|
const request = {
|