replicas-engine 0.1.1223 → 0.1.1226
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-J6MUQPK6.js → asp-host-E47NGZRP.js} +5 -5
- package/dist/src/{chunk-PVGN5NZQ.js → chunk-47SSCZMG.js} +2 -2
- package/dist/src/{chunk-GXL65UNT.js → chunk-ATHUSFGB.js} +3 -3
- package/dist/src/{chunk-SUSXUDD3.js → chunk-K77ILXKH.js} +1 -1
- package/dist/src/{chunk-CISR2MNI.js → chunk-LE7CVJC2.js} +2 -2
- package/dist/src/{chunk-XMAORHV5.js → chunk-LF7ND553.js} +1 -1
- package/dist/src/{chunk-KQWDACDY.js → chunk-MRAUGYDC.js} +2 -2
- package/dist/src/{chunk-VJTB4BFU.js → chunk-OPV7WB6E.js} +6 -3
- package/dist/src/{chunk-BY64IPRE.js → chunk-R7MHJUBF.js} +6 -6
- package/dist/src/command-protection-hook.js +4 -4
- package/dist/src/headless-agent.js +4 -4
- package/dist/src/index.js +105 -39
- package/dist/src/post-tool-pr-hook.js +2 -2
- package/dist/src/subagent-mcp.js +1 -1
- package/package.json +1 -1
|
@@ -8,12 +8,12 @@ import {
|
|
|
8
8
|
listRunningCodexModels,
|
|
9
9
|
restartCodexAspHost,
|
|
10
10
|
restartCodexAspHostIfRunning
|
|
11
|
-
} from "./chunk-
|
|
12
|
-
import "./chunk-
|
|
13
|
-
import "./chunk-
|
|
14
|
-
import "./chunk-
|
|
11
|
+
} from "./chunk-R7MHJUBF.js";
|
|
12
|
+
import "./chunk-MRAUGYDC.js";
|
|
13
|
+
import "./chunk-ATHUSFGB.js";
|
|
14
|
+
import "./chunk-LF7ND553.js";
|
|
15
15
|
import "./chunk-UZSNFLDQ.js";
|
|
16
|
-
import "./chunk-
|
|
16
|
+
import "./chunk-OPV7WB6E.js";
|
|
17
17
|
import "./chunk-VEQXQN22.js";
|
|
18
18
|
export {
|
|
19
19
|
CODEX_ULTRAFAST_SERVICE_TIER,
|
|
@@ -5,14 +5,14 @@ import {
|
|
|
5
5
|
getOriginDefaultBranch,
|
|
6
6
|
monolithRequest,
|
|
7
7
|
runGitCommand
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-MRAUGYDC.js";
|
|
9
9
|
import {
|
|
10
10
|
extractCommandProtectionCommandText,
|
|
11
11
|
findCommandProtectionGitLookups,
|
|
12
12
|
findGitCommitSignals,
|
|
13
13
|
findPrMergeSignals,
|
|
14
14
|
parseCommandProtectionRequest
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-OPV7WB6E.js";
|
|
16
16
|
|
|
17
17
|
// src/services/command-protection-service.ts
|
|
18
18
|
import { readFile, stat } from "fs/promises";
|
|
@@ -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-LF7ND553.js";
|
|
7
7
|
import {
|
|
8
8
|
isVersionBelow
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-OPV7WB6E.js";
|
|
10
10
|
|
|
11
11
|
// src/utils/codex-agent-env.ts
|
|
12
12
|
function buildCodexAgentEnv(source = process.env) {
|
|
@@ -240,7 +240,7 @@ function getCodexModelProvider(method) {
|
|
|
240
240
|
if (method === "foundry") return "azure";
|
|
241
241
|
return method === "ollama" || method === "openai-compatible" ? "replicas_openai_compatible" : "openai";
|
|
242
242
|
}
|
|
243
|
-
var ENGINE_PACKAGE_VERSION = "0.1.
|
|
243
|
+
var ENGINE_PACKAGE_VERSION = "0.1.1226";
|
|
244
244
|
var INITIALIZE_METHOD = "initialize";
|
|
245
245
|
var INITIALIZED_NOTIFICATION = "initialized";
|
|
246
246
|
var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
|
|
@@ -3,7 +3,7 @@ import { createRequire as __createRequire } from 'node:module';
|
|
|
3
3
|
const require = __createRequire(import.meta.url);
|
|
4
4
|
import {
|
|
5
5
|
AspClient
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-ATHUSFGB.js";
|
|
7
7
|
import {
|
|
8
8
|
ASTER_BASE_URL,
|
|
9
9
|
ASTER_PROVIDER,
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
isRecord,
|
|
14
14
|
readOllamaAuthEnv,
|
|
15
15
|
readOpenAICompatibleAuthEnv
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-OPV7WB6E.js";
|
|
17
17
|
|
|
18
18
|
// src/managers/codex-asp/notification-dispatch.ts
|
|
19
19
|
var TURN_STARTED_METHOD = "turn/started";
|
|
@@ -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-OPV7WB6E.js";
|
|
7
7
|
|
|
8
8
|
// src/utils/exec.ts
|
|
9
9
|
import { exec, execFile } from "child_process";
|
|
@@ -4,7 +4,7 @@ const require = __createRequire(import.meta.url);
|
|
|
4
4
|
import {
|
|
5
5
|
SUBPROCESS_MAX_BUFFER,
|
|
6
6
|
execFileAsync
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-LF7ND553.js";
|
|
8
8
|
import {
|
|
9
9
|
isRecord as isRecord2
|
|
10
10
|
} from "./chunk-UZSNFLDQ.js";
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
isValidAgentProvider,
|
|
19
19
|
parsePosixEnvFile,
|
|
20
20
|
readReplicasRuntimeEnv
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-OPV7WB6E.js";
|
|
22
22
|
|
|
23
23
|
// src/runtime-env-loader.ts
|
|
24
24
|
import { readFileSync } from "fs";
|
|
@@ -1501,6 +1501,7 @@ var CONTEXT_USAGE_EVENT_TYPE = "context-usage";
|
|
|
1501
1501
|
// ../shared/src/engine/v1.ts
|
|
1502
1502
|
import { z as z4 } from "zod";
|
|
1503
1503
|
var MERGED_MESSAGE_SEPARATOR = "\n\n<!-- replicas:merged -->\n\n";
|
|
1504
|
+
var ENGINE_STREAM_LAST_EVENT_ID_HEADER = "Last-Event-ID";
|
|
1504
1505
|
var ENGINE_HEALTH_WAIT_HEADER = "X-Replicas-Health-Wait";
|
|
1505
1506
|
var ENGINE_HEALTH_WAIT_QUERY_PARAM = "wait_ms";
|
|
1506
1507
|
var ENGINE_HEALTH_MAX_WAIT_MS = 2e3;
|
|
@@ -2131,13 +2132,14 @@ function parseSseChunk(chunk) {
|
|
|
2131
2132
|
return null;
|
|
2132
2133
|
}
|
|
2133
2134
|
}
|
|
2134
|
-
async function* iterateSseStream(body) {
|
|
2135
|
+
async function* iterateSseStream(body, onChunk) {
|
|
2135
2136
|
const reader = body.getReader();
|
|
2136
2137
|
const decoder2 = new TextDecoder();
|
|
2137
2138
|
let buffer = "";
|
|
2138
2139
|
while (true) {
|
|
2139
2140
|
const { done, value } = await reader.read();
|
|
2140
2141
|
if (done) break;
|
|
2142
|
+
onChunk?.();
|
|
2141
2143
|
buffer += decoder2.decode(value, { stream: true });
|
|
2142
2144
|
const chunks = buffer.split("\n\n");
|
|
2143
2145
|
buffer = chunks.pop() ?? "";
|
|
@@ -2147,9 +2149,9 @@ async function* iterateSseStream(body) {
|
|
|
2147
2149
|
}
|
|
2148
2150
|
}
|
|
2149
2151
|
}
|
|
2150
|
-
async function readSseStream(body, onEvent, shouldContinue = () => true) {
|
|
2152
|
+
async function readSseStream(body, onEvent, shouldContinue = () => true, onChunk) {
|
|
2151
2153
|
if (!shouldContinue()) return;
|
|
2152
|
-
for await (const event of iterateSseStream(body)) {
|
|
2154
|
+
for await (const event of iterateSseStream(body, onChunk)) {
|
|
2153
2155
|
if (!shouldContinue()) break;
|
|
2154
2156
|
await onEvent(event);
|
|
2155
2157
|
}
|
|
@@ -10122,6 +10124,7 @@ export {
|
|
|
10122
10124
|
coerceChatGoalPayload,
|
|
10123
10125
|
CONTEXT_USAGE_EVENT_TYPE,
|
|
10124
10126
|
MERGED_MESSAGE_SEPARATOR,
|
|
10127
|
+
ENGINE_STREAM_LAST_EVENT_ID_HEADER,
|
|
10125
10128
|
ENGINE_HEALTH_WAIT_HEADER,
|
|
10126
10129
|
ENGINE_HEALTH_WAIT_QUERY_PARAM,
|
|
10127
10130
|
ENGINE_HEALTH_MAX_WAIT_MS,
|
|
@@ -10,15 +10,15 @@ import {
|
|
|
10
10
|
resolveDiffBase,
|
|
11
11
|
runGitCommand,
|
|
12
12
|
setAgentCredentialSnapshot
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-MRAUGYDC.js";
|
|
14
14
|
import {
|
|
15
15
|
AppServerProcess,
|
|
16
16
|
buildCodexAgentEnv
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-ATHUSFGB.js";
|
|
18
18
|
import {
|
|
19
19
|
SUBPROCESS_MAX_BUFFER,
|
|
20
20
|
execFileAsync
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-LF7ND553.js";
|
|
22
22
|
import {
|
|
23
23
|
isRecord
|
|
24
24
|
} from "./chunk-UZSNFLDQ.js";
|
|
@@ -55,7 +55,7 @@ import {
|
|
|
55
55
|
resolveOpenAICompatibleModelsUrl,
|
|
56
56
|
splitMothershipInstructions,
|
|
57
57
|
withTimeout
|
|
58
|
-
} from "./chunk-
|
|
58
|
+
} from "./chunk-OPV7WB6E.js";
|
|
59
59
|
|
|
60
60
|
// src/managers/codex-token-manager.ts
|
|
61
61
|
import { promises as fs } from "fs";
|
|
@@ -291,7 +291,7 @@ var CodexTokenManager = class extends BaseRefreshManager {
|
|
|
291
291
|
await this.applyCredentialUpdate(++this.credentialGeneration, async () => {
|
|
292
292
|
await this.applyCredentialsResponse(data);
|
|
293
293
|
setAgentCredentialSnapshot("codex", data);
|
|
294
|
-
const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-
|
|
294
|
+
const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-E47NGZRP.js");
|
|
295
295
|
await restartCodexAspHostIfRunning2();
|
|
296
296
|
});
|
|
297
297
|
await this.start(true);
|
|
@@ -313,7 +313,7 @@ var CodexTokenManager = class extends BaseRefreshManager {
|
|
|
313
313
|
const accountChanged = ENGINE_ENV.REPLICAS_AGENT_CREDENTIALS.codex?.credentialId !== data.credentialId;
|
|
314
314
|
await this.applyCredentialsResponse(data);
|
|
315
315
|
if (restartOnChange && (accountChanged || CODEX_AUTH_ENV_KEYS.some((key, index) => process.env[key] !== previousEnv[index]))) {
|
|
316
|
-
const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-
|
|
316
|
+
const { restartCodexAspHostIfRunning: restartCodexAspHostIfRunning2 } = await import("./asp-host-E47NGZRP.js");
|
|
317
317
|
await restartCodexAspHostIfRunning2();
|
|
318
318
|
}
|
|
319
319
|
setAgentCredentialSnapshot("codex", data);
|
|
@@ -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-47SSCZMG.js";
|
|
7
|
+
import "./chunk-MRAUGYDC.js";
|
|
8
|
+
import "./chunk-LF7ND553.js";
|
|
9
9
|
import {
|
|
10
10
|
isRecord
|
|
11
11
|
} from "./chunk-UZSNFLDQ.js";
|
|
12
|
-
import "./chunk-
|
|
12
|
+
import "./chunk-OPV7WB6E.js";
|
|
13
13
|
import "./chunk-VEQXQN22.js";
|
|
14
14
|
|
|
15
15
|
// src/command-protection-hook.ts
|
|
@@ -13,12 +13,12 @@ import {
|
|
|
13
13
|
recoverCompletedTurn,
|
|
14
14
|
spawnMuseMsp,
|
|
15
15
|
startMuseSession
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-LE7CVJC2.js";
|
|
17
17
|
import {
|
|
18
18
|
AppServerProcess,
|
|
19
19
|
buildCodexAgentEnv
|
|
20
|
-
} from "./chunk-
|
|
21
|
-
import "./chunk-
|
|
20
|
+
} from "./chunk-ATHUSFGB.js";
|
|
21
|
+
import "./chunk-LF7ND553.js";
|
|
22
22
|
import {
|
|
23
23
|
AGENT,
|
|
24
24
|
OPENCODE_GO_PROVIDER,
|
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
headlessAgentUsagePath,
|
|
29
29
|
isRecord,
|
|
30
30
|
withTimeout
|
|
31
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-OPV7WB6E.js";
|
|
32
32
|
import "./chunk-VEQXQN22.js";
|
|
33
33
|
|
|
34
34
|
// src/headless-agent.ts
|
package/dist/src/index.js
CHANGED
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
evaluateCommandProtection,
|
|
28
28
|
extractToolCommand,
|
|
29
29
|
reportCommandProtectionBlock
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-47SSCZMG.js";
|
|
31
31
|
import {
|
|
32
32
|
ACCOUNT_RATE_LIMITS_UPDATED_METHOD,
|
|
33
33
|
AGENT_MESSAGE_DELTA_METHOD,
|
|
@@ -64,10 +64,10 @@ import {
|
|
|
64
64
|
spawnMuseMsp,
|
|
65
65
|
startMuseSession,
|
|
66
66
|
uuidV7
|
|
67
|
-
} from "./chunk-
|
|
67
|
+
} from "./chunk-LE7CVJC2.js";
|
|
68
68
|
import {
|
|
69
69
|
publishedPullRequestUrls
|
|
70
|
-
} from "./chunk-
|
|
70
|
+
} from "./chunk-K77ILXKH.js";
|
|
71
71
|
import {
|
|
72
72
|
ACCOUNT_RATE_LIMITS_READ_METHOD,
|
|
73
73
|
AsyncLock,
|
|
@@ -140,7 +140,7 @@ import {
|
|
|
140
140
|
timestampFromSeconds,
|
|
141
141
|
upsertCredentialFileLines,
|
|
142
142
|
writeSecureCredentialFile
|
|
143
|
-
} from "./chunk-
|
|
143
|
+
} from "./chunk-R7MHJUBF.js";
|
|
144
144
|
import {
|
|
145
145
|
ENGINE_ENV,
|
|
146
146
|
monolithRequest,
|
|
@@ -149,15 +149,15 @@ import {
|
|
|
149
149
|
reloadEngineEnv,
|
|
150
150
|
resolveDiffBase,
|
|
151
151
|
setAgentCredentialSnapshot
|
|
152
|
-
} from "./chunk-
|
|
152
|
+
} from "./chunk-MRAUGYDC.js";
|
|
153
153
|
import {
|
|
154
154
|
getCodexModelProvider
|
|
155
|
-
} from "./chunk-
|
|
155
|
+
} from "./chunk-ATHUSFGB.js";
|
|
156
156
|
import {
|
|
157
157
|
SUBPROCESS_MAX_BUFFER,
|
|
158
158
|
execAsync,
|
|
159
159
|
execFileAsync
|
|
160
|
-
} from "./chunk-
|
|
160
|
+
} from "./chunk-LF7ND553.js";
|
|
161
161
|
import {
|
|
162
162
|
isRecord as isRecord2
|
|
163
163
|
} from "./chunk-UZSNFLDQ.js";
|
|
@@ -212,6 +212,7 @@ import {
|
|
|
212
212
|
ENGINE_HEALTH_WAIT_QUERY_PARAM,
|
|
213
213
|
ENGINE_SEND_MESSAGE_FAILED_ERROR,
|
|
214
214
|
ENGINE_SLEEP_PATH,
|
|
215
|
+
ENGINE_STREAM_LAST_EVENT_ID_HEADER,
|
|
215
216
|
ENVIRONMENT_HOOK_RUN_LOG_LIMIT,
|
|
216
217
|
GITHUB_CREDENTIAL_REFRESH_PATH,
|
|
217
218
|
GITLAB_CREDENTIAL_REFRESH_PATH,
|
|
@@ -393,7 +394,7 @@ import {
|
|
|
393
394
|
workspaceTokenRequestSchema,
|
|
394
395
|
workspaceTokenResponseSchema,
|
|
395
396
|
wrapInTag
|
|
396
|
-
} from "./chunk-
|
|
397
|
+
} from "./chunk-OPV7WB6E.js";
|
|
397
398
|
import {
|
|
398
399
|
cloneMcpConfig,
|
|
399
400
|
ensureCompatibilityImports,
|
|
@@ -10300,32 +10301,97 @@ import { mkdir as mkdir5 } from "fs/promises";
|
|
|
10300
10301
|
import { join as join6 } from "path";
|
|
10301
10302
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
10302
10303
|
var EVENTS_FILE = join6(ENGINE_DIR, "events.jsonl");
|
|
10304
|
+
var MAX_REPLAY_EVENTS = 2e3;
|
|
10305
|
+
var MAX_REPLAY_CHARS = 4 * 1024 * 1024;
|
|
10306
|
+
function partialKey(event) {
|
|
10307
|
+
if (event.type !== "chat.turn.delta") return null;
|
|
10308
|
+
const { type } = event.payload.event;
|
|
10309
|
+
if (type !== CLAUDE_PARTIAL_MESSAGE_EVENT_TYPE && type !== CODEX_ITEM_PARTIAL_EVENT_TYPE) return null;
|
|
10310
|
+
const streamId = getEventStreamId(event.payload.event);
|
|
10311
|
+
return streamId ? `${event.payload.chatId}:${type}:${streamId}` : null;
|
|
10312
|
+
}
|
|
10303
10313
|
var EventService = class {
|
|
10304
|
-
subscribers = /* @__PURE__ */ new
|
|
10314
|
+
subscribers = /* @__PURE__ */ new Set();
|
|
10305
10315
|
writer = new StreamWriter();
|
|
10316
|
+
epoch = randomUUID2();
|
|
10317
|
+
seq = 0;
|
|
10318
|
+
replay = [];
|
|
10319
|
+
replayChars = 0;
|
|
10320
|
+
// Newest seq dropped for space: a client that last saw an older seq cannot resume.
|
|
10321
|
+
replayFloor = 0;
|
|
10322
|
+
latestPartials = /* @__PURE__ */ new Map();
|
|
10306
10323
|
async initialize() {
|
|
10307
10324
|
await mkdir5(ENGINE_DIR, { recursive: true });
|
|
10308
10325
|
this.writer.open(EVENTS_FILE);
|
|
10309
10326
|
}
|
|
10310
|
-
subscribe(subscriber) {
|
|
10311
|
-
const
|
|
10312
|
-
|
|
10327
|
+
subscribe(subscriber, lastEventId) {
|
|
10328
|
+
const separator = lastEventId?.lastIndexOf(":") ?? -1;
|
|
10329
|
+
const after = lastEventId ? Number(lastEventId.slice(separator + 1)) : Number.NaN;
|
|
10330
|
+
const resumed = separator > 0 && lastEventId?.slice(0, separator) === this.epoch && Number.isSafeInteger(after) && after >= this.replayFloor && after <= this.seq;
|
|
10331
|
+
const opened = {
|
|
10332
|
+
id: randomUUID2(),
|
|
10333
|
+
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
10334
|
+
type: "engine.stream.opened",
|
|
10335
|
+
payload: { epoch: this.epoch, seq: this.seq, resumed }
|
|
10336
|
+
};
|
|
10337
|
+
subscriber(`id: ${this.epoch}:${resumed ? after : this.seq}
|
|
10338
|
+
event: ${opened.type}
|
|
10339
|
+
data: ${JSON.stringify(opened)}
|
|
10340
|
+
|
|
10341
|
+
`);
|
|
10342
|
+
if (resumed) {
|
|
10343
|
+
for (const entry of this.replay) {
|
|
10344
|
+
if (entry.seq > after) subscriber(entry.frame);
|
|
10345
|
+
}
|
|
10346
|
+
}
|
|
10347
|
+
this.subscribers.add(subscriber);
|
|
10313
10348
|
return () => {
|
|
10314
|
-
this.subscribers.delete(
|
|
10349
|
+
this.subscribers.delete(subscriber);
|
|
10315
10350
|
};
|
|
10316
10351
|
}
|
|
10317
10352
|
getSubscriberCount() {
|
|
10318
10353
|
return this.subscribers.size;
|
|
10319
10354
|
}
|
|
10320
10355
|
async publish(event) {
|
|
10321
|
-
this.
|
|
10322
|
-
|
|
10356
|
+
const seq = ++this.seq;
|
|
10357
|
+
const data = JSON.stringify({ ...event, seq });
|
|
10358
|
+
this.writer.write(data + "\n");
|
|
10359
|
+
const entry = { seq, frame: `id: ${this.epoch}:${seq}
|
|
10360
|
+
event: ${event.type}
|
|
10361
|
+
data: ${data}
|
|
10362
|
+
|
|
10363
|
+
`, partialKey: partialKey(event) };
|
|
10364
|
+
this.remember(entry);
|
|
10365
|
+
for (const subscriber of this.subscribers) {
|
|
10323
10366
|
try {
|
|
10324
|
-
subscriber(
|
|
10367
|
+
subscriber(entry.frame);
|
|
10325
10368
|
} catch {
|
|
10326
10369
|
}
|
|
10327
10370
|
}
|
|
10328
10371
|
}
|
|
10372
|
+
// A newer partial carries the whole message so far, so only the latest one per message is replayed.
|
|
10373
|
+
remember(entry) {
|
|
10374
|
+
if (entry.partialKey) {
|
|
10375
|
+
const superseded = this.latestPartials.get(entry.partialKey);
|
|
10376
|
+
if (superseded) {
|
|
10377
|
+
const index = this.replay.indexOf(superseded);
|
|
10378
|
+
if (index !== -1) {
|
|
10379
|
+
this.replay.splice(index, 1);
|
|
10380
|
+
this.replayChars -= superseded.frame.length;
|
|
10381
|
+
}
|
|
10382
|
+
}
|
|
10383
|
+
this.latestPartials.set(entry.partialKey, entry);
|
|
10384
|
+
}
|
|
10385
|
+
this.replay.push(entry);
|
|
10386
|
+
this.replayChars += entry.frame.length;
|
|
10387
|
+
while (this.replay.length > MAX_REPLAY_EVENTS || this.replayChars > MAX_REPLAY_CHARS && this.replay.length > 1) {
|
|
10388
|
+
const evicted = this.replay.shift();
|
|
10389
|
+
if (!evicted) break;
|
|
10390
|
+
this.replayChars -= evicted.frame.length;
|
|
10391
|
+
this.replayFloor = evicted.seq;
|
|
10392
|
+
if (evicted.partialKey && this.latestPartials.get(evicted.partialKey) === evicted) this.latestPartials.delete(evicted.partialKey);
|
|
10393
|
+
}
|
|
10394
|
+
}
|
|
10329
10395
|
};
|
|
10330
10396
|
var eventService = new EventService();
|
|
10331
10397
|
|
|
@@ -59214,6 +59280,7 @@ async function flushAllChatTranscripts(chatsById = /* @__PURE__ */ new Map(), ca
|
|
|
59214
59280
|
return capture ? { flushed, failed, captureSupported: true, revisions } : { flushed, failed };
|
|
59215
59281
|
}
|
|
59216
59282
|
var uploadsByChatId = /* @__PURE__ */ new Map();
|
|
59283
|
+
var lastUploadByTarget = /* @__PURE__ */ new Map();
|
|
59217
59284
|
function uploadChatTranscript(chatId, filePath, chat, capture) {
|
|
59218
59285
|
const upload = (uploadsByChatId.get(chatId) ?? Promise.resolve()).catch(() => {
|
|
59219
59286
|
}).then(() => uploadChatTranscriptNow(chatId, filePath, chat, capture));
|
|
@@ -59226,7 +59293,7 @@ function uploadChatTranscript(chatId, filePath, chat, capture) {
|
|
|
59226
59293
|
}
|
|
59227
59294
|
async function uploadChatTranscriptNow(chatId, filePath, chat, capture) {
|
|
59228
59295
|
const versionBeforeStat = chat?.currentHistoryVersion?.();
|
|
59229
|
-
const { size } = await stat4(filePath);
|
|
59296
|
+
const { size, mtimeMs } = await stat4(filePath);
|
|
59230
59297
|
if (size === 0) return null;
|
|
59231
59298
|
const historyVersion = versionBeforeStat === chat?.currentHistoryVersion?.() ? versionBeforeStat : void 0;
|
|
59232
59299
|
const metadata = chat ? {
|
|
@@ -59243,13 +59310,6 @@ async function uploadChatTranscriptNow(chatId, filePath, chat, capture) {
|
|
|
59243
59310
|
fork: chat.fork ?? null,
|
|
59244
59311
|
...historyVersion ? { historyVersion } : {}
|
|
59245
59312
|
} : {};
|
|
59246
|
-
if (capture) {
|
|
59247
|
-
const hash = createHash7("sha256");
|
|
59248
|
-
for await (const chunk of createReadStream3(filePath, { start: 0, end: size - 1 })) hash.update(chunk);
|
|
59249
|
-
metadata.captureId = capture.captureId;
|
|
59250
|
-
metadata.captureReason = capture.reason;
|
|
59251
|
-
metadata.sha256 = hash.digest("hex");
|
|
59252
|
-
}
|
|
59253
59313
|
try {
|
|
59254
59314
|
metadata.senders = parseChatMessageSendersJsonl(
|
|
59255
59315
|
await readFile15(chatMessageSendersFilePath(chatId), "utf-8")
|
|
@@ -59262,6 +59322,20 @@ async function uploadChatTranscriptNow(chatId, filePath, chat, capture) {
|
|
|
59262
59322
|
sourceSize: size,
|
|
59263
59323
|
...chat?.removedMessageIds?.length ? { removedMessageIds: chat.removedMessageIds } : {}
|
|
59264
59324
|
};
|
|
59325
|
+
const settled = Date.now() - mtimeMs > 1e3;
|
|
59326
|
+
const target = `${chatId}:${capture ? "capture" : "canonical"}`;
|
|
59327
|
+
const fingerprint = JSON.stringify({ size, mtimeMs, metadata });
|
|
59328
|
+
const last = lastUploadByTarget.get(target);
|
|
59329
|
+
if (last?.fingerprint === fingerprint) {
|
|
59330
|
+
return capture ? { ...last.artifact, metadata: { ...last.artifact.metadata, captureId: capture.captureId } } : null;
|
|
59331
|
+
}
|
|
59332
|
+
if (capture) {
|
|
59333
|
+
const hash = createHash7("sha256");
|
|
59334
|
+
for await (const chunk of createReadStream3(filePath, { start: 0, end: size - 1 })) hash.update(chunk);
|
|
59335
|
+
metadata.captureId = capture.captureId;
|
|
59336
|
+
metadata.captureReason = capture.reason;
|
|
59337
|
+
metadata.sha256 = hash.digest("hex");
|
|
59338
|
+
}
|
|
59265
59339
|
const uploadRequest = { chatId, size, metadata };
|
|
59266
59340
|
const prepareResponse = await monolithRequest("/v1/engine/chat-transcripts/upload-url", {
|
|
59267
59341
|
body: uploadRequest
|
|
@@ -59286,6 +59360,7 @@ async function uploadChatTranscriptNow(chatId, filePath, chat, capture) {
|
|
|
59286
59360
|
if (finalizeBody.artifact === null) return null;
|
|
59287
59361
|
const artifact = parseChatTranscriptArtifact(finalizeBody.artifact);
|
|
59288
59362
|
if (!artifact) throw new Error("finalize failed: invalid artifact");
|
|
59363
|
+
if (settled) lastUploadByTarget.set(target, { fingerprint, artifact });
|
|
59289
59364
|
return artifact;
|
|
59290
59365
|
}
|
|
59291
59366
|
|
|
@@ -62091,7 +62166,7 @@ import { randomUUID as randomUUID11 } from "crypto";
|
|
|
62091
62166
|
import { existsSync as existsSync17 } from "fs";
|
|
62092
62167
|
import { spawn as spawn6 } from "node-pty";
|
|
62093
62168
|
import { z as z3 } from "zod";
|
|
62094
|
-
var
|
|
62169
|
+
var MAX_REPLAY_CHARS2 = 1024 * 1024;
|
|
62095
62170
|
var MAX_TERMINAL_SESSIONS = 8;
|
|
62096
62171
|
var MAX_PENDING_INPUT = 64;
|
|
62097
62172
|
var terminalSizeSchema = z3.object({
|
|
@@ -62142,7 +62217,7 @@ var TerminalService = class {
|
|
|
62142
62217
|
};
|
|
62143
62218
|
this.sessions.set(id, session);
|
|
62144
62219
|
pty.onData((data) => {
|
|
62145
|
-
session.replay = (session.replay + data).slice(-
|
|
62220
|
+
session.replay = (session.replay + data).slice(-MAX_REPLAY_CHARS2);
|
|
62146
62221
|
for (const subscriber of session.subscribers) subscriber(data);
|
|
62147
62222
|
});
|
|
62148
62223
|
pty.onExit(({ exitCode }) => {
|
|
@@ -62151,7 +62226,7 @@ var TerminalService = class {
|
|
|
62151
62226
|
const data = `\r
|
|
62152
62227
|
\x1B[2m[Process exited with code ${exitCode}]\x1B[0m\r
|
|
62153
62228
|
`;
|
|
62154
|
-
session.replay = (session.replay + data).slice(-
|
|
62229
|
+
session.replay = (session.replay + data).slice(-MAX_REPLAY_CHARS2);
|
|
62155
62230
|
for (const subscriber of session.subscribers) subscriber(data);
|
|
62156
62231
|
});
|
|
62157
62232
|
return createSuccessResult(this.publicSession(session));
|
|
@@ -62322,8 +62397,9 @@ function createV1Routes(deps) {
|
|
|
62322
62397
|
), status);
|
|
62323
62398
|
}
|
|
62324
62399
|
};
|
|
62325
|
-
app2.get("/events", async () => {
|
|
62400
|
+
app2.get("/events", async (c) => {
|
|
62326
62401
|
const encoder2 = new TextEncoder();
|
|
62402
|
+
const lastEventId = c.req.header(ENGINE_STREAM_LAST_EVENT_ID_HEADER);
|
|
62327
62403
|
let unsubscribe = null;
|
|
62328
62404
|
let heartbeat = null;
|
|
62329
62405
|
const cleanup = () => {
|
|
@@ -62347,20 +62423,10 @@ function createV1Routes(deps) {
|
|
|
62347
62423
|
return false;
|
|
62348
62424
|
}
|
|
62349
62425
|
};
|
|
62350
|
-
|
|
62351
|
-
if (!safeEnqueue(`id: ${event.id}
|
|
62352
|
-
`)) return;
|
|
62353
|
-
if (!safeEnqueue(`event: ${event.type}
|
|
62354
|
-
`)) return;
|
|
62355
|
-
safeEnqueue(`data: ${JSON.stringify(event)}
|
|
62356
|
-
|
|
62357
|
-
`);
|
|
62358
|
-
};
|
|
62359
|
-
unsubscribe = eventService.subscribe(writeEvent);
|
|
62426
|
+
unsubscribe = eventService.subscribe(safeEnqueue, lastEventId);
|
|
62360
62427
|
heartbeat = setInterval(() => {
|
|
62361
62428
|
safeEnqueue(": ping\n\n");
|
|
62362
62429
|
}, 15e3);
|
|
62363
|
-
safeEnqueue(": connected\n\n");
|
|
62364
62430
|
},
|
|
62365
62431
|
cancel: () => {
|
|
62366
62432
|
cleanup();
|
|
@@ -3,13 +3,13 @@ import { createRequire as __createRequire } from 'node:module';
|
|
|
3
3
|
const require = __createRequire(import.meta.url);
|
|
4
4
|
import {
|
|
5
5
|
publishedPullRequestUrls
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-K77ILXKH.js";
|
|
7
7
|
import {
|
|
8
8
|
isRecord
|
|
9
9
|
} from "./chunk-UZSNFLDQ.js";
|
|
10
10
|
import {
|
|
11
11
|
shouldRefreshPullRequests
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-OPV7WB6E.js";
|
|
13
13
|
import "./chunk-VEQXQN22.js";
|
|
14
14
|
|
|
15
15
|
// src/services/post-tool-pr-notifier.ts
|
package/dist/src/subagent-mcp.js
CHANGED