@atlaswork/atlascode 0.1.126 → 0.1.128
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/atlasweb-carrier.json +3 -3
- package/dist/cli.js +31 -7
- package/dist/web-contract/index.d.ts +8 -0
- package/dist/web-contract/index.js +5 -2
- package/dist/web-session-runtime/atlascode/web/limits.d.ts +2 -0
- package/dist/web-session-runtime/atlascode/web/projection.d.ts +6 -0
- package/dist/web-session-runtime/atlascode/web/readonlyRuntime.d.ts +24 -0
- package/dist/web-session-runtime/atlascode/web/replayPaging.d.ts +27 -0
- package/dist/web-session-runtime/engine/session/load.d.ts +47 -0
- package/dist/web-session-runtime/engine/session/predicates.d.ts +1 -1
- package/dist/web-session-runtime/engine/session/readonly.d.ts +2 -0
- package/dist/web-session-runtime/engine/session/replayScan.d.ts +45 -0
- package/dist/web-session-runtime/engine/session/types.d.ts +1 -1
- package/dist/web-session-runtime/index.js +373 -4
- package/dist/web-session-runtime/kernel/protocol/webSessionV0.d.ts +8 -0
- package/dist/web-session-runtime/shared/index.d.ts +1 -1
- package/dist/web-session-runtime-execution/atlascode/web/entry.d.ts +2 -0
- package/dist/web-session-runtime-execution/atlascode/web/limits.d.ts +2 -0
- package/dist/web-session-runtime-execution/atlascode/web/projection.d.ts +6 -0
- package/dist/web-session-runtime-execution/atlascode/web/readonlyRuntime.d.ts +24 -0
- package/dist/web-session-runtime-execution/atlascode/web/replayPaging.d.ts +27 -0
- package/dist/web-session-runtime-execution/engine/session/load.d.ts +47 -0
- package/dist/web-session-runtime-execution/engine/session/predicates.d.ts +1 -1
- package/dist/web-session-runtime-execution/engine/session/readonly.d.ts +2 -0
- package/dist/web-session-runtime-execution/engine/session/replayScan.d.ts +45 -0
- package/dist/web-session-runtime-execution/engine/session/types.d.ts +1 -1
- package/dist/web-session-runtime-execution/index.js +662 -8
- package/dist/web-session-runtime-execution/kernel/execution/executionComposition.d.ts +18 -0
- package/dist/web-session-runtime-execution/kernel/execution/executionKernel.d.ts +77 -0
- package/dist/web-session-runtime-execution/kernel/protocol/webSessionV0.d.ts +8 -0
- package/dist/web-session-runtime-execution/shared/index.d.ts +1 -1
- package/package.json +2 -2
- package/dist/web-session-runtime/atlascode/web/entry.d.ts +0 -21
- package/dist/web-session-runtime/atlascode/web/executionOutlet.d.ts +0 -60
- package/dist/web-session-runtime/kernel/execution/executionOutlet.d.ts +0 -60
- package/dist/web-session-runtime/kernel/protocol/webExecutionV0.d.ts +0 -542
|
@@ -950,6 +950,175 @@ async function loadTranscriptFile(filePath, opts) {
|
|
|
950
950
|
leafUuids
|
|
951
951
|
};
|
|
952
952
|
}
|
|
953
|
+
// src/engine/session/replayScan.ts
|
|
954
|
+
import { constants as fsConstants2 } from "node:fs";
|
|
955
|
+
import { open as open2 } from "fs/promises";
|
|
956
|
+
function stripContent(content) {
|
|
957
|
+
if (typeof content === "string") {
|
|
958
|
+
return content.length > 0 ? "\x00" : "";
|
|
959
|
+
}
|
|
960
|
+
if (!Array.isArray(content))
|
|
961
|
+
return;
|
|
962
|
+
return content.map((item) => {
|
|
963
|
+
if (!item || typeof item !== "object")
|
|
964
|
+
return item;
|
|
965
|
+
const rec = item;
|
|
966
|
+
switch (rec.type) {
|
|
967
|
+
case "text":
|
|
968
|
+
return {
|
|
969
|
+
type: "text",
|
|
970
|
+
text: typeof rec.text === "string" && rec.text.length > 0 ? "\x00" : ""
|
|
971
|
+
};
|
|
972
|
+
case "tool_use":
|
|
973
|
+
return { type: "tool_use", id: rec.id };
|
|
974
|
+
case "tool_result":
|
|
975
|
+
return { type: "tool_result", tool_use_id: rec.tool_use_id };
|
|
976
|
+
default:
|
|
977
|
+
return { type: rec.type };
|
|
978
|
+
}
|
|
979
|
+
});
|
|
980
|
+
}
|
|
981
|
+
function stripToSkeleton(entry) {
|
|
982
|
+
const type = entry.type;
|
|
983
|
+
if (type !== "user" && type !== "assistant" && type !== "attachment" && type !== "system") {
|
|
984
|
+
return;
|
|
985
|
+
}
|
|
986
|
+
const message = entry.message;
|
|
987
|
+
const skeleton = {
|
|
988
|
+
uuid: entry.uuid,
|
|
989
|
+
parentUuid: entry.parentUuid ?? null,
|
|
990
|
+
type,
|
|
991
|
+
timestamp: entry.timestamp ?? null
|
|
992
|
+
};
|
|
993
|
+
if (typeof entry.isSidechain === "boolean")
|
|
994
|
+
skeleton.isSidechain = entry.isSidechain;
|
|
995
|
+
if (entry.compactMetadata !== undefined)
|
|
996
|
+
skeleton.compactMetadata = entry.compactMetadata;
|
|
997
|
+
if (typeof entry.subtype === "string")
|
|
998
|
+
skeleton.subtype = entry.subtype;
|
|
999
|
+
if (entry.snipMetadata !== undefined)
|
|
1000
|
+
skeleton.snipMetadata = entry.snipMetadata;
|
|
1001
|
+
if (message && typeof message === "object") {
|
|
1002
|
+
const m = message;
|
|
1003
|
+
const out = {};
|
|
1004
|
+
if (typeof m.id === "string")
|
|
1005
|
+
out.id = m.id;
|
|
1006
|
+
const content = stripContent(m.content);
|
|
1007
|
+
if (content !== undefined)
|
|
1008
|
+
out.content = content;
|
|
1009
|
+
skeleton.message = out;
|
|
1010
|
+
}
|
|
1011
|
+
return skeleton;
|
|
1012
|
+
}
|
|
1013
|
+
async function openReplayPageReader(filePath, opts) {
|
|
1014
|
+
const noFollow = fsConstants2.O_NOFOLLOW ?? 0;
|
|
1015
|
+
const fd = await open2(filePath, fsConstants2.O_RDONLY | noFollow);
|
|
1016
|
+
try {
|
|
1017
|
+
const fst = await fd.stat();
|
|
1018
|
+
if (opts?.expectIno !== undefined && fst.ino !== opts.expectIno) {
|
|
1019
|
+
throw new TranscriptChangedDuringReadError;
|
|
1020
|
+
}
|
|
1021
|
+
if (opts?.maxBytes !== undefined && fst.size > opts.maxBytes) {
|
|
1022
|
+
throw new TranscriptTooLargeError(fst.size, opts.maxBytes);
|
|
1023
|
+
}
|
|
1024
|
+
const skeletons = new Map;
|
|
1025
|
+
const ranges = new Map;
|
|
1026
|
+
const progressBridge = new Map;
|
|
1027
|
+
const buf = Buffer.allocUnsafe(TRANSCRIPT_READ_CHUNK_SIZE);
|
|
1028
|
+
let carry = Buffer.alloc(0);
|
|
1029
|
+
let carryFileStart = 0;
|
|
1030
|
+
let readPos = 0;
|
|
1031
|
+
let firstChunk = true;
|
|
1032
|
+
const processLine = (line, fileOffset) => {
|
|
1033
|
+
const text = line.toString("utf8").trim();
|
|
1034
|
+
if (!text)
|
|
1035
|
+
return;
|
|
1036
|
+
let entry;
|
|
1037
|
+
try {
|
|
1038
|
+
entry = JSON.parse(text);
|
|
1039
|
+
} catch {
|
|
1040
|
+
return;
|
|
1041
|
+
}
|
|
1042
|
+
if (!entry || typeof entry !== "object")
|
|
1043
|
+
return;
|
|
1044
|
+
const rec = entry;
|
|
1045
|
+
if (isLegacyProgressEntry(entry)) {
|
|
1046
|
+
const parent = rec.parentUuid;
|
|
1047
|
+
progressBridge.set(rec.uuid, parent && progressBridge.has(parent) ? progressBridge.get(parent) ?? null : parent);
|
|
1048
|
+
return;
|
|
1049
|
+
}
|
|
1050
|
+
const skeleton = stripToSkeleton(rec);
|
|
1051
|
+
if (!skeleton)
|
|
1052
|
+
return;
|
|
1053
|
+
if (skeleton.parentUuid && progressBridge.has(skeleton.parentUuid)) {
|
|
1054
|
+
skeleton.parentUuid = progressBridge.get(skeleton.parentUuid) ?? null;
|
|
1055
|
+
}
|
|
1056
|
+
skeletons.set(skeleton.uuid, skeleton);
|
|
1057
|
+
ranges.set(skeleton.uuid, { offset: fileOffset, length: line.length });
|
|
1058
|
+
};
|
|
1059
|
+
for (;; ) {
|
|
1060
|
+
const { bytesRead } = await fd.read(buf, 0, buf.length, readPos);
|
|
1061
|
+
if (bytesRead <= 0)
|
|
1062
|
+
break;
|
|
1063
|
+
const chunkFileStart = readPos;
|
|
1064
|
+
readPos += bytesRead;
|
|
1065
|
+
let chunk = buf.subarray(0, bytesRead);
|
|
1066
|
+
let contentSkip = 0;
|
|
1067
|
+
if (firstChunk) {
|
|
1068
|
+
firstChunk = false;
|
|
1069
|
+
if (bytesRead >= 3 && buf[0] === 239 && buf[1] === 187 && buf[2] === 191) {
|
|
1070
|
+
contentSkip = 3;
|
|
1071
|
+
chunk = chunk.subarray(3);
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
const data = carry.length > 0 ? Buffer.concat([carry, chunk]) : Buffer.from(chunk);
|
|
1075
|
+
const dataFileStart = chunkFileStart + contentSkip - carry.length;
|
|
1076
|
+
let lineStart = 0;
|
|
1077
|
+
for (;; ) {
|
|
1078
|
+
const nl = data.indexOf(10, lineStart);
|
|
1079
|
+
if (nl < 0)
|
|
1080
|
+
break;
|
|
1081
|
+
processLine(data.subarray(lineStart, nl), dataFileStart + lineStart);
|
|
1082
|
+
lineStart = nl + 1;
|
|
1083
|
+
}
|
|
1084
|
+
carry = Buffer.from(data.subarray(lineStart));
|
|
1085
|
+
carryFileStart = dataFileStart + lineStart;
|
|
1086
|
+
}
|
|
1087
|
+
if (carry.length > 0) {
|
|
1088
|
+
processLine(carry, carryFileStart);
|
|
1089
|
+
}
|
|
1090
|
+
const asTranscriptMap = skeletons;
|
|
1091
|
+
applyPreservedSegmentRelinks(asTranscriptMap);
|
|
1092
|
+
applySnipRemovals(asTranscriptMap);
|
|
1093
|
+
return {
|
|
1094
|
+
skeletons,
|
|
1095
|
+
ranges,
|
|
1096
|
+
ino: fst.ino,
|
|
1097
|
+
size: fst.size,
|
|
1098
|
+
readRanges: async (list) => {
|
|
1099
|
+
const out = [];
|
|
1100
|
+
for (const r of list) {
|
|
1101
|
+
const b = Buffer.alloc(r.length);
|
|
1102
|
+
let filled = 0;
|
|
1103
|
+
while (filled < r.length) {
|
|
1104
|
+
const { bytesRead: n } = await fd.read(b, filled, r.length - filled, r.offset + filled);
|
|
1105
|
+
if (n <= 0)
|
|
1106
|
+
throw new TranscriptChangedDuringReadError;
|
|
1107
|
+
filled += n;
|
|
1108
|
+
}
|
|
1109
|
+
out.push(b);
|
|
1110
|
+
}
|
|
1111
|
+
return out;
|
|
1112
|
+
},
|
|
1113
|
+
close: async () => {
|
|
1114
|
+
await fd.close();
|
|
1115
|
+
}
|
|
1116
|
+
};
|
|
1117
|
+
} catch (e) {
|
|
1118
|
+
await fd.close().catch(() => {});
|
|
1119
|
+
throw e;
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
953
1122
|
|
|
954
1123
|
// src/engine/session/readonly.ts
|
|
955
1124
|
async function loadTranscriptFull(filePath, opts) {
|
|
@@ -1075,6 +1244,8 @@ var HARD_MAX_SCAN_SESSIONS = 16384;
|
|
|
1075
1244
|
var HARD_MAX_SCOPES_PER_RUNTIME = 128;
|
|
1076
1245
|
var DEFAULT_PAGE_SIZE = 50;
|
|
1077
1246
|
var HARD_MAX_PAGE_SIZE = 200;
|
|
1247
|
+
var DEFAULT_MAX_REPLAY_PAGE_BYTES = 4 * MIB;
|
|
1248
|
+
var HARD_MAX_REPLAY_PAGE_BYTES = 16 * MIB;
|
|
1078
1249
|
var DEFAULT_MAX_RECORD_BYTES = MIB;
|
|
1079
1250
|
var HARD_MAX_RECORD_BYTES = 8 * MIB;
|
|
1080
1251
|
var DEFAULT_MAX_PARSE_RECORDS = 1e5;
|
|
@@ -1844,9 +2015,179 @@ function createFollowSubscription(deps) {
|
|
|
1844
2015
|
};
|
|
1845
2016
|
}
|
|
1846
2017
|
|
|
2018
|
+
// src/atlascode/web/replayPaging.ts
|
|
2019
|
+
import { createHash } from "node:crypto";
|
|
2020
|
+
function encodePageToken(t) {
|
|
2021
|
+
return Buffer.from(JSON.stringify(t), "utf8").toString("base64url");
|
|
2022
|
+
}
|
|
2023
|
+
function decodePageToken(token) {
|
|
2024
|
+
const invalid = () => new WebSessionError("invalidRequest", "malformed replay pageToken");
|
|
2025
|
+
let raw;
|
|
2026
|
+
try {
|
|
2027
|
+
raw = Buffer.from(token, "base64url").toString("utf8");
|
|
2028
|
+
} catch {
|
|
2029
|
+
throw invalid();
|
|
2030
|
+
}
|
|
2031
|
+
let parsed;
|
|
2032
|
+
try {
|
|
2033
|
+
parsed = JSON.parse(raw);
|
|
2034
|
+
} catch {
|
|
2035
|
+
throw invalid();
|
|
2036
|
+
}
|
|
2037
|
+
if (!parsed || typeof parsed !== "object")
|
|
2038
|
+
throw invalid();
|
|
2039
|
+
const t = parsed;
|
|
2040
|
+
if (t.v !== 1 || typeof t.scopeId !== "string" || typeof t.sessionId !== "string" || typeof t.offset !== "number" || !Number.isInteger(t.offset) || t.offset < 0 || typeof t.anchor !== "string" || !/^[0-9a-f]{16}$/.test(t.anchor)) {
|
|
2041
|
+
throw invalid();
|
|
2042
|
+
}
|
|
2043
|
+
return t;
|
|
2044
|
+
}
|
|
2045
|
+
function chainPrefixFingerprint(uuids) {
|
|
2046
|
+
return createHash("sha256").update(uuids.join(`
|
|
2047
|
+
`), "utf8").digest("hex").slice(0, 16);
|
|
2048
|
+
}
|
|
2049
|
+
function renderRecord(raw) {
|
|
2050
|
+
let entry;
|
|
2051
|
+
try {
|
|
2052
|
+
entry = JSON.parse(Buffer.from(raw).toString("utf8"));
|
|
2053
|
+
} catch {
|
|
2054
|
+
throw new WebSessionError("ioUnavailable", "paged record unreadable (snapshot inconsistency)", true);
|
|
2055
|
+
}
|
|
2056
|
+
const source = {
|
|
2057
|
+
uuid: entry.uuid,
|
|
2058
|
+
parentUuid: entry.parentUuid ?? null,
|
|
2059
|
+
type: entry.type,
|
|
2060
|
+
timestamp: entry.timestamp ?? null,
|
|
2061
|
+
...entry.message !== undefined ? { message: entry.message } : {}
|
|
2062
|
+
};
|
|
2063
|
+
return {
|
|
2064
|
+
id: source.uuid,
|
|
2065
|
+
role: source.type,
|
|
2066
|
+
createdAt: source.timestamp ?? null,
|
|
2067
|
+
blocks: projectBlocks(source)
|
|
2068
|
+
};
|
|
2069
|
+
}
|
|
2070
|
+
async function loadReplayPage(deps, scopeId, sessionId, req, signal) {
|
|
2071
|
+
const { adapter, engine, limits: L } = deps;
|
|
2072
|
+
let tok;
|
|
2073
|
+
if (req.pageToken !== undefined) {
|
|
2074
|
+
tok = decodePageToken(req.pageToken);
|
|
2075
|
+
if (tok.scopeId !== scopeId || tok.sessionId !== sessionId) {
|
|
2076
|
+
throw new WebSessionError("invalidRequest", "replay pageToken domain mismatch (scopeId/sessionId bound)");
|
|
2077
|
+
}
|
|
2078
|
+
}
|
|
2079
|
+
const pageSize = Math.max(1, Math.min(req.pageSize ?? L.pageSize, L.pageSize));
|
|
2080
|
+
const stPre = await adapter.statTranscript(scopeId, sessionId);
|
|
2081
|
+
if (!stPre) {
|
|
2082
|
+
throw new WebSessionError("notFound", `session not found: ${sessionId}`);
|
|
2083
|
+
}
|
|
2084
|
+
const entries = await adapter.listSessionFiles(scopeId);
|
|
2085
|
+
const entry = entries.find((e) => e.sessionId === sessionId);
|
|
2086
|
+
if (!entry) {
|
|
2087
|
+
throw new WebSessionError("ioUnavailable", `session listed at stat but missing at scan: ${sessionId}`, true);
|
|
2088
|
+
}
|
|
2089
|
+
const filePath = entry.filePath;
|
|
2090
|
+
let reader;
|
|
2091
|
+
try {
|
|
2092
|
+
reader = await engine.openReplayPageReader(filePath, {
|
|
2093
|
+
maxBytes: HARD_MAX_TRANSCRIPT_BYTES,
|
|
2094
|
+
expectIno: stPre.ino
|
|
2095
|
+
});
|
|
2096
|
+
} catch (e) {
|
|
2097
|
+
if (e instanceof TranscriptTooLargeError) {
|
|
2098
|
+
throw new WebSessionError("resourceLimit", `transcript exceeds limit (${e.size} > ${e.maxBytes} bytes)`);
|
|
2099
|
+
}
|
|
2100
|
+
if (e instanceof TranscriptChangedDuringReadError) {
|
|
2101
|
+
throw new WebSessionError("ioUnavailable", e.message, true);
|
|
2102
|
+
}
|
|
2103
|
+
throw e;
|
|
2104
|
+
}
|
|
2105
|
+
try {
|
|
2106
|
+
const skeletons = reader.skeletons;
|
|
2107
|
+
const leafUuids = computeLeafUuids(skeletons);
|
|
2108
|
+
let leaf;
|
|
2109
|
+
for (const uuid of leafUuids) {
|
|
2110
|
+
const m = skeletons.get(uuid);
|
|
2111
|
+
if (!m)
|
|
2112
|
+
continue;
|
|
2113
|
+
if (!leaf || (m.timestamp ?? "") >= (leaf.timestamp ?? "")) {
|
|
2114
|
+
leaf = m;
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
const chain = leaf ? engine.buildConversationChain(skeletons, leaf) : [];
|
|
2118
|
+
const effective = chain.filter((m) => (m.type === "user" || m.type === "assistant") && projectBlocks(m).length > 0);
|
|
2119
|
+
const offset = tok?.offset ?? 0;
|
|
2120
|
+
if (offset > effective.length) {
|
|
2121
|
+
throw new WebSessionError("cursorExpired", `replay pageToken offset ${offset} beyond effective chain length ${effective.length}`);
|
|
2122
|
+
}
|
|
2123
|
+
if (tok) {
|
|
2124
|
+
const anchor = chainPrefixFingerprint(effective.slice(0, offset).map((m) => m.uuid));
|
|
2125
|
+
if (anchor !== tok.anchor) {
|
|
2126
|
+
throw new WebSessionError("cursorExpired", "replay pageToken anchor drift (chain rewritten or compacted)");
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
2129
|
+
const messages = [];
|
|
2130
|
+
let bytesSum = 0;
|
|
2131
|
+
let count = 0;
|
|
2132
|
+
let i = offset;
|
|
2133
|
+
for (;i < effective.length && count < pageSize; i++) {
|
|
2134
|
+
if (signal?.aborted) {
|
|
2135
|
+
throw new WebSessionError("cancelled", "operation aborted");
|
|
2136
|
+
}
|
|
2137
|
+
const range = reader.ranges.get(effective[i].uuid);
|
|
2138
|
+
if (!range) {
|
|
2139
|
+
throw new WebSessionError("ioUnavailable", "paged chain member has no byte range (snapshot inconsistency)", true);
|
|
2140
|
+
}
|
|
2141
|
+
const [raw] = await reader.readRanges([range]);
|
|
2142
|
+
const msg = renderRecord(raw);
|
|
2143
|
+
const b = Buffer.byteLength(JSON.stringify(msg));
|
|
2144
|
+
const projected = 2 + bytesSum + b + count;
|
|
2145
|
+
if (projected > L.maxReplayPageBytes) {
|
|
2146
|
+
if (count === 0) {
|
|
2147
|
+
throw new WebSessionError("resourceLimit", `single record exceeds replay page limit (${projected} > ${L.maxReplayPageBytes} bytes)`);
|
|
2148
|
+
}
|
|
2149
|
+
break;
|
|
2150
|
+
}
|
|
2151
|
+
messages.push(msg);
|
|
2152
|
+
bytesSum += b;
|
|
2153
|
+
count++;
|
|
2154
|
+
}
|
|
2155
|
+
const nextOffset = offset + count;
|
|
2156
|
+
const hasMore = nextOffset < effective.length;
|
|
2157
|
+
let nextPageToken;
|
|
2158
|
+
if (hasMore) {
|
|
2159
|
+
nextPageToken = encodePageToken({
|
|
2160
|
+
v: 1,
|
|
2161
|
+
scopeId,
|
|
2162
|
+
sessionId,
|
|
2163
|
+
offset: nextOffset,
|
|
2164
|
+
anchor: chainPrefixFingerprint(effective.slice(0, nextOffset).map((m) => m.uuid))
|
|
2165
|
+
});
|
|
2166
|
+
}
|
|
2167
|
+
const stPost = await adapter.statTranscript(scopeId, sessionId);
|
|
2168
|
+
if (!stPost || stPost.ino !== stPre.ino || stPost.sizeBytes !== stPre.sizeBytes || stPost.mtimeMs !== stPre.mtimeMs) {
|
|
2169
|
+
throw new WebSessionError("ioUnavailable", "transcript changed during replay page (snapshot inconsistency)", true);
|
|
2170
|
+
}
|
|
2171
|
+
return {
|
|
2172
|
+
projection: {
|
|
2173
|
+
sessionId,
|
|
2174
|
+
productId: deps.productId,
|
|
2175
|
+
scopeId,
|
|
2176
|
+
semantics: "persisted-effective-conversation",
|
|
2177
|
+
messages,
|
|
2178
|
+
truncated: false
|
|
2179
|
+
},
|
|
2180
|
+
hasMore,
|
|
2181
|
+
...nextPageToken !== undefined ? { nextPageToken } : {}
|
|
2182
|
+
};
|
|
2183
|
+
} finally {
|
|
2184
|
+
await reader.close().catch(() => {});
|
|
2185
|
+
}
|
|
2186
|
+
}
|
|
2187
|
+
|
|
1847
2188
|
// src/atlascode/web/sessionStoreAdapter.ts
|
|
1848
|
-
import { constants as
|
|
1849
|
-
import { lstat, open as
|
|
2189
|
+
import { constants as fsConstants3 } from "node:fs";
|
|
2190
|
+
import { lstat, open as open3, readdir, realpath, stat as stat2 } from "node:fs/promises";
|
|
1850
2191
|
import { isAbsolute, join, resolve, sep } from "node:path";
|
|
1851
2192
|
var SESSION_ID_RE = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/;
|
|
1852
2193
|
function assertSessionIdShape(sessionId) {
|
|
@@ -1900,7 +2241,7 @@ function createNodeFsSessionStoreAdapter(options) {
|
|
|
1900
2241
|
}
|
|
1901
2242
|
let fh;
|
|
1902
2243
|
try {
|
|
1903
|
-
fh = await
|
|
2244
|
+
fh = await open3(filePath, fsConstants3.O_RDONLY | fsConstants3.O_NOFOLLOW);
|
|
1904
2245
|
} catch (e) {
|
|
1905
2246
|
mapFsError(e, "transcript open");
|
|
1906
2247
|
}
|
|
@@ -2330,6 +2671,7 @@ function createReadonlySessionRuntime(options) {
|
|
|
2330
2671
|
maxRecordBytes: validateBoundedInt("maxRecordBytes", options.limits?.maxRecordBytes, DEFAULT_MAX_RECORD_BYTES, HARD_MAX_RECORD_BYTES),
|
|
2331
2672
|
maxParseRecords: validateBoundedInt("maxParseRecords", options.limits?.maxParseRecords, DEFAULT_MAX_PARSE_RECORDS, HARD_MAX_PARSE_RECORDS),
|
|
2332
2673
|
maxProjectionBytes: validateBoundedInt("maxProjectionBytes", options.limits?.maxProjectionBytes, DEFAULT_MAX_PROJECTION_BYTES, HARD_MAX_PROJECTION_BYTES),
|
|
2674
|
+
maxReplayPageBytes: validateBoundedInt("maxReplayPageBytes", options.limits?.maxReplayPageBytes, DEFAULT_MAX_REPLAY_PAGE_BYTES, HARD_MAX_REPLAY_PAGE_BYTES),
|
|
2333
2675
|
maxSubscriptions: validateBoundedInt("maxSubscriptions", options.limits?.maxSubscriptions, DEFAULT_MAX_SUBSCRIPTIONS, HARD_MAX_SUBSCRIPTIONS),
|
|
2334
2676
|
maxConcurrentReads: validateBoundedInt("maxConcurrentReads", options.limits?.maxConcurrentReads, DEFAULT_MAX_CONCURRENT_READS, HARD_MAX_CONCURRENT_READS),
|
|
2335
2677
|
maxPendingEvents: validateBoundedInt("maxPendingEvents", options.limits?.maxPendingEvents, DEFAULT_MAX_PENDING_EVENTS, HARD_MAX_PENDING_EVENTS),
|
|
@@ -2558,6 +2900,32 @@ function createReadonlySessionRuntime(options) {
|
|
|
2558
2900
|
async replaySession(req, signal) {
|
|
2559
2901
|
assertStarted("replay session");
|
|
2560
2902
|
assertScope(req.scopeId);
|
|
2903
|
+
if ("pageSize" in req || "pageToken" in req) {
|
|
2904
|
+
const open = options.engine.openReplayPageReader;
|
|
2905
|
+
if (!open) {
|
|
2906
|
+
throw new WebSessionError("invalidRequest", "replay paging not supported by injected engine");
|
|
2907
|
+
}
|
|
2908
|
+
acquireRead();
|
|
2909
|
+
try {
|
|
2910
|
+
const paged = await loadReplayPage({
|
|
2911
|
+
adapter,
|
|
2912
|
+
engine: {
|
|
2913
|
+
openReplayPageReader: open,
|
|
2914
|
+
buildConversationChain: options.engine.buildConversationChain
|
|
2915
|
+
},
|
|
2916
|
+
limits: L,
|
|
2917
|
+
productId: options.productId
|
|
2918
|
+
}, req.scopeId, req.sessionId, req, signal);
|
|
2919
|
+
return {
|
|
2920
|
+
of: "replaySession",
|
|
2921
|
+
projection: paged.projection,
|
|
2922
|
+
hasMore: paged.hasMore,
|
|
2923
|
+
...paged.nextPageToken !== undefined ? { nextPageToken: paged.nextPageToken } : {}
|
|
2924
|
+
};
|
|
2925
|
+
} finally {
|
|
2926
|
+
releaseRead();
|
|
2927
|
+
}
|
|
2928
|
+
}
|
|
2561
2929
|
const projection = await loadProjection(req.scopeId, req.sessionId, signal);
|
|
2562
2930
|
return { of: "replaySession", projection };
|
|
2563
2931
|
},
|
|
@@ -2622,7 +2990,8 @@ function atlasWebSessionEngine() {
|
|
|
2622
2990
|
leafUuids: loaded.leafUuids
|
|
2623
2991
|
};
|
|
2624
2992
|
},
|
|
2625
|
-
buildConversationChain: (messages, leaf) => buildConversationChain(messages, leaf)
|
|
2993
|
+
buildConversationChain: (messages, leaf) => buildConversationChain(messages, leaf),
|
|
2994
|
+
openReplayPageReader: (filePath, opts) => openReplayPageReader(filePath, opts)
|
|
2626
2995
|
};
|
|
2627
2996
|
}
|
|
2628
2997
|
function createDefaultReadonlySessionRuntime(options) {
|
|
@@ -45,6 +45,8 @@ export declare const SearchSessionsRequestSchema: z.ZodObject<{
|
|
|
45
45
|
scopeId: z.ZodString;
|
|
46
46
|
}, z.core.$strict>;
|
|
47
47
|
export declare const ReplaySessionRequestSchema: z.ZodObject<{
|
|
48
|
+
pageSize: z.ZodOptional<z.ZodNumber>;
|
|
49
|
+
pageToken: z.ZodOptional<z.ZodString>;
|
|
48
50
|
kind: z.ZodLiteral<"replaySession">;
|
|
49
51
|
sessionId: z.ZodString;
|
|
50
52
|
schemaVersion: z.ZodLiteral<0>;
|
|
@@ -96,6 +98,8 @@ export declare const WebSessionRequestSchema: z.ZodDiscriminatedUnion<[z.ZodObje
|
|
|
96
98
|
productId: z.ZodString;
|
|
97
99
|
scopeId: z.ZodString;
|
|
98
100
|
}, z.core.$strict>, z.ZodObject<{
|
|
101
|
+
pageSize: z.ZodOptional<z.ZodNumber>;
|
|
102
|
+
pageToken: z.ZodOptional<z.ZodString>;
|
|
99
103
|
kind: z.ZodLiteral<"replaySession">;
|
|
100
104
|
sessionId: z.ZodString;
|
|
101
105
|
schemaVersion: z.ZodLiteral<0>;
|
|
@@ -329,6 +333,8 @@ export declare const ReplaySessionSuccessSchema: z.ZodObject<{
|
|
|
329
333
|
}, z.core.$strict>>;
|
|
330
334
|
truncated: z.ZodLiteral<false>;
|
|
331
335
|
}, z.core.$strict>;
|
|
336
|
+
hasMore: z.ZodOptional<z.ZodBoolean>;
|
|
337
|
+
nextPageToken: z.ZodOptional<z.ZodString>;
|
|
332
338
|
schemaVersion: z.ZodLiteral<0>;
|
|
333
339
|
requestId: z.ZodUUID;
|
|
334
340
|
productId: z.ZodString;
|
|
@@ -401,6 +407,8 @@ export declare const WebSessionSuccessSchema: z.ZodDiscriminatedUnion<[z.ZodObje
|
|
|
401
407
|
}, z.core.$strict>>;
|
|
402
408
|
truncated: z.ZodLiteral<false>;
|
|
403
409
|
}, z.core.$strict>;
|
|
410
|
+
hasMore: z.ZodOptional<z.ZodBoolean>;
|
|
411
|
+
nextPageToken: z.ZodOptional<z.ZodString>;
|
|
404
412
|
schemaVersion: z.ZodLiteral<0>;
|
|
405
413
|
requestId: z.ZodUUID;
|
|
406
414
|
productId: z.ZodString;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* shared 模块唯一公共出口(STR-1 门面规则)。
|
|
3
3
|
*
|
|
4
|
-
* 外部模块只许 `import { ... } from "../shared.js"`(或 "src/shared"),
|
|
4
|
+
* 外部模块只许 `import { ... } from "../shared/index.js"`(或 "src/shared"),
|
|
5
5
|
* 不许 reach 内部文件(entry-point lint 拦截)。
|
|
6
6
|
*
|
|
7
7
|
* re-export: feature(A 波已实现)/ types / types-session /
|
|
@@ -21,4 +21,6 @@ export type { SessionStoreAdapter, SessionStoreScopes, SessionFileEntry, Transcr
|
|
|
21
21
|
export type { NeutralProjection, NeutralProjectionMessage, NeutralBlock, ProjectionSourceMessage, ProjectionEngineDeps, ProjectionLoad, } from './projection.js';
|
|
22
22
|
export { WebSessionError, type WebSessionErrorCode } from './errors.js';
|
|
23
23
|
export { createExecutionOutlet, type ExecutionOutlet, type ExecutionOutletOptions, type ExecutionDispatchResult, type WebExecutionProbeResult, } from '../../kernel/execution/executionOutlet.js';
|
|
24
|
+
export { createExecutionComposition, type ExecutionComposition, type ExecutionCompositionOptions, } from '../../kernel/execution/executionComposition.js';
|
|
25
|
+
export type { ExecutionTurnRunner, ExecutionTurnRunnerDeps, ExecutionTurnOutcome, ExecutionApprovalDecision, } from '../../kernel/execution/executionKernel.js';
|
|
24
26
|
export { EXECUTION_SCHEMA_VERSION, EXECUTION_PROTOCOL_VERSION, EXECUTION_CAPABILITY_DISABLED_CODE, WebExecutionCommandSchema, WebExecutionEventSchema, WebExecutionErrorSchema, ExecutionBindSchema, type ExecutionBind, type ExecutionReplay, type WebExecutionCommand, type WebExecutionEvent, type WebExecutionError, } from '../../kernel/protocol/webExecutionV0.js';
|
|
@@ -14,6 +14,8 @@ export declare const DEFAULT_MAX_SCOPES_PER_RUNTIME = 32;
|
|
|
14
14
|
export declare const HARD_MAX_SCOPES_PER_RUNTIME = 128;
|
|
15
15
|
export declare const DEFAULT_PAGE_SIZE = 50;
|
|
16
16
|
export declare const HARD_MAX_PAGE_SIZE = 200;
|
|
17
|
+
export declare const DEFAULT_MAX_REPLAY_PAGE_BYTES: number;
|
|
18
|
+
export declare const HARD_MAX_REPLAY_PAGE_BYTES: number;
|
|
17
19
|
export declare const SEARCH_QUERY_MIN_CODE_POINTS = 1;
|
|
18
20
|
export declare const SEARCH_QUERY_MAX_CODE_POINTS = 256;
|
|
19
21
|
export declare const DEFAULT_MAX_RECORD_BYTES: number;
|
|
@@ -52,6 +52,12 @@ export interface ProjectionLoad {
|
|
|
52
52
|
}
|
|
53
53
|
/** 事件/projection 序列化字节单一口径(replay 与 follow 共享,防兄弟路漂移)。 */
|
|
54
54
|
export declare function serializedProjectionBytes(p: unknown): number;
|
|
55
|
+
/**
|
|
56
|
+
* F6-PAGE S1 加性导出:分页装窗路径(replayPaging.ts)对 skeleton(内容
|
|
57
|
+
* 剥除面)与 pass2 全量记录(原文面)复用同一块投影判定——可渲染性单源。
|
|
58
|
+
* 全量路径零行为变更(纯 export 添加)。
|
|
59
|
+
*/
|
|
60
|
+
export declare function projectBlocks(msg: ProjectionSourceMessage): NeutralBlock[];
|
|
55
61
|
/**
|
|
56
62
|
* terminal leaf 集计算(load.ts:1187-1226 同规则镜像:terminal → 最近
|
|
57
63
|
* user/assistant 祖先;增量尾读路径复用。f4 §5.7 登记:镜像同步义务,
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* revision/issued cursors/subscriptions/timers 实例字段,零全局槽)。
|
|
15
15
|
*/
|
|
16
16
|
import type { WebSessionProjection } from './contract.js';
|
|
17
|
+
import type { ReplayPageReader } from '../../engine/session/readonly.js';
|
|
17
18
|
import { type FollowHandle } from './follow.js';
|
|
18
19
|
import { type ProjectionEngineDeps, type ProjectionSourceMessage } from './projection.js';
|
|
19
20
|
import type { SessionStoreAdapter } from './sessionStoreAdapter.js';
|
|
@@ -28,6 +29,8 @@ export interface ReadonlySessionLimits {
|
|
|
28
29
|
maxRecordBytes?: number;
|
|
29
30
|
maxParseRecords?: number;
|
|
30
31
|
maxProjectionBytes?: number;
|
|
32
|
+
/** F6-PAGE 必改③:replay 分页单页序列化字节界(DEFAULT 4MiB / HARD 16MiB)。 */
|
|
33
|
+
maxReplayPageBytes?: number;
|
|
31
34
|
maxSubscriptions?: number;
|
|
32
35
|
maxConcurrentReads?: number;
|
|
33
36
|
maxPendingEvents?: number;
|
|
@@ -56,6 +59,15 @@ export interface ReadonlySessionEngine {
|
|
|
56
59
|
}>;
|
|
57
60
|
/** CLI 同规则链重建(projection 头注镜像义务)。 */
|
|
58
61
|
buildConversationChain: ProjectionEngineDeps['buildConversationChain'];
|
|
62
|
+
/**
|
|
63
|
+
* F6-PAGE S1 加性缝:replay 分页 skeleton 扫描(真体 =
|
|
64
|
+
* engine/session/replayScan.ts,runtimeDefault 焊接;测试 fake 可缺席
|
|
65
|
+
* ——分页请求遇缺席 → invalidRequest fail-closed)。
|
|
66
|
+
*/
|
|
67
|
+
openReplayPageReader?: (filePath: string, opts?: {
|
|
68
|
+
maxBytes?: number;
|
|
69
|
+
expectIno?: number;
|
|
70
|
+
}) => Promise<ReplayPageReader>;
|
|
59
71
|
}
|
|
60
72
|
export interface ReadonlySessionRuntimeOptions {
|
|
61
73
|
/** 静态产品标识(ProductDefinition 单源,'atlascode')。 */
|
|
@@ -85,10 +97,21 @@ export interface ListSessionsResult {
|
|
|
85
97
|
export interface ReplaySessionRequest {
|
|
86
98
|
scopeId: string;
|
|
87
99
|
sessionId: string;
|
|
100
|
+
/**
|
|
101
|
+
* F6-PAGE S1 加性分页参(wire 契约 PageFields 同形;schemaVersion=0
|
|
102
|
+
* optional 不破版)。任一在场 → 分页装窗路径;双缺省 = 旧全量 replay
|
|
103
|
+
* 逐字节不变(A1 对表腿)。
|
|
104
|
+
*/
|
|
105
|
+
pageSize?: number;
|
|
106
|
+
pageToken?: string;
|
|
88
107
|
}
|
|
89
108
|
export interface ReplaySessionResult {
|
|
90
109
|
of: 'replaySession';
|
|
91
110
|
projection: WebSessionProjection;
|
|
111
|
+
/** F6-PAGE S1 加性(分页请求恒发;全量请求零新键)。 */
|
|
112
|
+
hasMore?: boolean;
|
|
113
|
+
/** 仅 hasMore=true 时在场(opaque token,replayPaging.ts 编解码单源)。 */
|
|
114
|
+
nextPageToken?: string;
|
|
92
115
|
}
|
|
93
116
|
export interface FollowSessionRequest {
|
|
94
117
|
scopeId: string;
|
|
@@ -129,6 +152,7 @@ export interface ResolvedLimits {
|
|
|
129
152
|
maxRecordBytes: number;
|
|
130
153
|
maxParseRecords: number;
|
|
131
154
|
maxProjectionBytes: number;
|
|
155
|
+
maxReplayPageBytes: number;
|
|
132
156
|
maxSubscriptions: number;
|
|
133
157
|
maxConcurrentReads: number;
|
|
134
158
|
maxPendingEvents: number;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ReplayPageReader } from '../../engine/session/readonly.js';
|
|
2
|
+
import type { WebSessionProjection } from '../../kernel/protocol/webSessionV0.js';
|
|
3
|
+
import type { ResolvedLimits } from './readonlyRuntime.js';
|
|
4
|
+
import { type ProjectionSourceMessage } from './projection.js';
|
|
5
|
+
import type { SessionStoreAdapter } from './sessionStoreAdapter.js';
|
|
6
|
+
export interface ReplayPagedRequest {
|
|
7
|
+
pageSize?: number;
|
|
8
|
+
pageToken?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ReplayPageDeps {
|
|
11
|
+
adapter: SessionStoreAdapter;
|
|
12
|
+
engine: {
|
|
13
|
+
openReplayPageReader: (filePath: string, opts?: {
|
|
14
|
+
maxBytes?: number;
|
|
15
|
+
expectIno?: number;
|
|
16
|
+
}) => Promise<ReplayPageReader>;
|
|
17
|
+
buildConversationChain: (messages: Map<string, ProjectionSourceMessage>, leaf: ProjectionSourceMessage) => ProjectionSourceMessage[];
|
|
18
|
+
};
|
|
19
|
+
limits: ResolvedLimits;
|
|
20
|
+
productId: string;
|
|
21
|
+
}
|
|
22
|
+
export interface ReplayPageResult {
|
|
23
|
+
projection: WebSessionProjection;
|
|
24
|
+
hasMore: boolean;
|
|
25
|
+
nextPageToken?: string;
|
|
26
|
+
}
|
|
27
|
+
export declare function loadReplayPage(deps: ReplayPageDeps, scopeId: string, sessionId: string, req: ReplayPagedRequest, signal?: AbortSignal): Promise<ReplayPageResult>;
|
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
import type { ContentReplacementRecord, LogOption, PersistedWorktreeSession, SerializedMessage, TranscriptMessage } from './types.js';
|
|
2
2
|
/** 旧 L1825 逐字。 */
|
|
3
3
|
export declare function removeExtraFields(transcript: TranscriptMessage[]): SerializedMessage[];
|
|
4
|
+
/**
|
|
5
|
+
* Splice the preserved segment back into the chain after compaction.(旧
|
|
6
|
+
* L1850 逐字)
|
|
7
|
+
*
|
|
8
|
+
* Preserved messages exist in the JSONL with their ORIGINAL pre-compact
|
|
9
|
+
* parentUuids (recordTranscript dedup-skipped them — can't rewrite).
|
|
10
|
+
* The internal chain (keep[i+1]→keep[i]) is intact; only endpoints need
|
|
11
|
+
* patching: head→anchor, and anchor's other children→tail. Anchor is the
|
|
12
|
+
* last summary for suffix-preserving, boundary itself for prefix-preserving.
|
|
13
|
+
*
|
|
14
|
+
* Only the LAST seg-boundary is relinked — earlier segs were summarized
|
|
15
|
+
* into it. Everything physically before the absolute-last boundary (except
|
|
16
|
+
* preservedUuids) is deleted, which handles all multi-boundary shapes
|
|
17
|
+
* without special-casing.
|
|
18
|
+
*
|
|
19
|
+
* Mutates the Map in place.
|
|
20
|
+
*
|
|
21
|
+
* F6-PAGE S1 加性导出:replay 分页装窗读路径(engine/session/replayScan.ts)
|
|
22
|
+
* 在 skeleton Map 上复用本变换——零逻辑复刻(链图语义单源),全量路径
|
|
23
|
+
* 零行为变更(纯 export 添加)。
|
|
24
|
+
*/
|
|
25
|
+
export declare function applyPreservedSegmentRelinks(messages: Map<string, TranscriptMessage>): void;
|
|
26
|
+
/**
|
|
27
|
+
* Delete messages that Snip executions removed from the in-memory array,
|
|
28
|
+
* and relink parentUuid across the gaps.(旧 L1986 逐字)
|
|
29
|
+
*
|
|
30
|
+
* Unlike compact_boundary which truncates a prefix, snip removes
|
|
31
|
+
* middle ranges. The JSONL is append-only, so removed messages stay on disk
|
|
32
|
+
* and the surviving messages' parentUuid chains walk through them. Without
|
|
33
|
+
* this filter, buildConversationChain reconstructs the full unsnipped history
|
|
34
|
+
* and resume immediately PTLs (adamr-20260320-165831: 397K displayed → 1.65M
|
|
35
|
+
* actual).
|
|
36
|
+
*
|
|
37
|
+
* Deleting alone is not enough: the surviving message AFTER a removed range
|
|
38
|
+
* has parentUuid pointing INTO the gap. buildConversationChain would hit
|
|
39
|
+
* messages.get(undefined) and stop, orphaning everything before the gap. So
|
|
40
|
+
* after delete we relink: for each survivor with a dangling parentUuid, walk
|
|
41
|
+
* backward through the removed region's own parent links to the first
|
|
42
|
+
* non-removed ancestor.
|
|
43
|
+
*
|
|
44
|
+
* The boundary records removedUuids at execution time so we can replay the
|
|
45
|
+
* exact removal on load. Older boundaries without removedUuids are skipped —
|
|
46
|
+
* resume loads their pre-snip history (the pre-fix behavior).
|
|
47
|
+
*
|
|
48
|
+
* Mutates the Map in place.
|
|
49
|
+
*/
|
|
50
|
+
export declare function applySnipRemovals(messages: Map<string, TranscriptMessage>): void;
|
|
4
51
|
/**
|
|
5
52
|
* Builds a conversation chain from a leaf message to root(旧 L2069 逐字)
|
|
6
53
|
* @param messages Map of all messages
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* 前向补裁。
|
|
12
12
|
*/
|
|
13
13
|
import type { Message, Entry, TranscriptMessage, SystemCompactBoundaryMessage } from './types.js';
|
|
14
|
-
import type { Message as SharedMessage } from '../../shared.js';
|
|
14
|
+
import type { Message as SharedMessage } from '../../shared/index.js';
|
|
15
15
|
/**
|
|
16
16
|
* 旧 L134 逐字。Type guard to check if an entry is a transcript message.
|
|
17
17
|
* Transcript messages include user, assistant, attachment, and system
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
import { loadTranscriptFile } from './load.js';
|
|
15
15
|
export { buildConversationChain, TranscriptChangedDuringReadError, TranscriptTooLargeError, } from './load.js';
|
|
16
16
|
export type { TranscriptMessage } from './types.js';
|
|
17
|
+
export { openReplayPageReader } from './replayScan.js';
|
|
18
|
+
export type { ReplayPageReader, ReplayByteRange } from './replayScan.js';
|
|
17
19
|
export type ReadonlyTranscriptLoad = Awaited<ReturnType<typeof loadTranscriptFile>>;
|
|
18
20
|
/** 全量只读加载(force-full,零截断;只读 runtime 专用)。 */
|
|
19
21
|
export declare function loadTranscriptFull(filePath: string,
|