@atlaswork/atlascode 0.1.127 → 0.1.129
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 +271 -110
- 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/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 +387 -10
- package/dist/web-session-runtime-execution/kernel/execution/executionKernel.d.ts +9 -2
- 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 +1 -1
- 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
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** skeleton 记录 = 链/恢复 pass 所需字段的窄结构面(内容已剥除)。 */
|
|
2
|
+
export interface ReplaySkeletonRecord {
|
|
3
|
+
uuid: string;
|
|
4
|
+
parentUuid: string | null;
|
|
5
|
+
type: string;
|
|
6
|
+
timestamp?: string | null;
|
|
7
|
+
isSidechain?: boolean;
|
|
8
|
+
compactMetadata?: unknown;
|
|
9
|
+
subtype?: string;
|
|
10
|
+
snipMetadata?: unknown;
|
|
11
|
+
message?: {
|
|
12
|
+
id?: string;
|
|
13
|
+
content?: unknown;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/** 行字节范围(文件绝对坐标;length 不含换行)。 */
|
|
17
|
+
export interface ReplayByteRange {
|
|
18
|
+
offset: number;
|
|
19
|
+
length: number;
|
|
20
|
+
}
|
|
21
|
+
export interface ReplayPageReader {
|
|
22
|
+
/** skeleton Map(last-wins;relink/snip 已施加)。 */
|
|
23
|
+
skeletons: Map<string, ReplaySkeletonRecord>;
|
|
24
|
+
/** uuid → 行字节范围(与 skeletons 同键集;被 relink/snip 剪枝的残键无害)。 */
|
|
25
|
+
ranges: Map<string, ReplayByteRange>;
|
|
26
|
+
/** open 后 fstat 身份(web 层 adapter stPost 三元组对表的 ino 侧)。 */
|
|
27
|
+
ino: number;
|
|
28
|
+
size: number;
|
|
29
|
+
/** pass2:按字节范围读页内记录原文(返回序 = 入参序;公共面用
|
|
30
|
+
* Uint8Array——S0-R 打包出口 d.ts 消费 tsconfig 无 node types,
|
|
31
|
+
* Buffer 类型名不入 .d.ts,实现体仍可用 Buffer)。 */
|
|
32
|
+
readRanges(ranges: ReadonlyArray<ReplayByteRange>): Promise<Uint8Array[]>;
|
|
33
|
+
close(): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 打开 replay 分页读取器:open(O_NOFOLLOW 旗标,POSIX;Windows 守卫跳过
|
|
37
|
+
* ——load.ts S0-R4 F1 同形)→ fstat 身份/尺寸检查点 → 流式逐行 skeleton
|
|
38
|
+
* 扫描 → 装载期图变换(relink/snip)。fd 保持打开供 pass2 readRanges;
|
|
39
|
+
* close 恒由调用方 finally 触达(成功路径 fd 移交 reader,失败路径此处
|
|
40
|
+
* 关闭)。
|
|
41
|
+
*/
|
|
42
|
+
export declare function openReplayPageReader(filePath: string, opts?: {
|
|
43
|
+
maxBytes?: number;
|
|
44
|
+
expectIno?: number;
|
|
45
|
+
}): Promise<ReplayPageReader>;
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
* sourceToolAssistantUUID/attachment):旧仓 `(m as any).message.id` 类
|
|
34
34
|
* cast 在域扩展型下直接可访,逐字块内按需去 cast(语义逐字不变)。
|
|
35
35
|
*/
|
|
36
|
-
import type { ContentBlock, Message as BaseMessage, Usage } from '../../shared.js';
|
|
36
|
+
import type { ContentBlock, Message as BaseMessage, Usage } from '../../shared/types.js';
|
|
37
37
|
export type UUID = string;
|
|
38
38
|
/** 旧 types/ids brand → string(残余 ② 口径)。 */
|
|
39
39
|
export type AgentId = string;
|
|
@@ -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) {
|
|
@@ -5591,7 +5960,7 @@ function bucketFor(state, inst) {
|
|
|
5591
5960
|
return bucket;
|
|
5592
5961
|
}
|
|
5593
5962
|
var handoff;
|
|
5594
|
-
var
|
|
5963
|
+
var open4 = [];
|
|
5595
5964
|
var memo = {
|
|
5596
5965
|
alloc(_inst, payload, empty) {
|
|
5597
5966
|
const bucket = handoff;
|
|
@@ -5600,7 +5969,7 @@ var memo = {
|
|
|
5600
5969
|
handoff = undefined;
|
|
5601
5970
|
const entry = { value: empty, issues: null };
|
|
5602
5971
|
bucket.set(payload.value, entry);
|
|
5603
|
-
|
|
5972
|
+
open4.push(entry);
|
|
5604
5973
|
return empty;
|
|
5605
5974
|
},
|
|
5606
5975
|
guard(inst) {
|
|
@@ -5671,10 +6040,10 @@ var memo = {
|
|
|
5671
6040
|
return payload;
|
|
5672
6041
|
}
|
|
5673
6042
|
handoff = bucket;
|
|
5674
|
-
const depth =
|
|
6043
|
+
const depth = open4.length;
|
|
5675
6044
|
const result = base(payload, ctx);
|
|
5676
6045
|
handoff = undefined;
|
|
5677
|
-
const entry =
|
|
6046
|
+
const entry = open4.length > depth ? open4.pop() : undefined;
|
|
5678
6047
|
if (result instanceof Promise) {
|
|
5679
6048
|
return result.then((r) => {
|
|
5680
6049
|
if (entry)
|
|
@@ -8512,7 +8881,7 @@ function createExecutionKernel(options) {
|
|
|
8512
8881
|
}
|
|
8513
8882
|
emit(st, { workspaceId: ws, sessionId: s, turnId: turn.turnId }, "turn.delta", { text });
|
|
8514
8883
|
},
|
|
8515
|
-
requestApproval: () => {
|
|
8884
|
+
requestApproval: (req) => {
|
|
8516
8885
|
const approvalId = `appr-${++approvalCounter}`;
|
|
8517
8886
|
return new Promise((resolve) => {
|
|
8518
8887
|
const approval = {
|
|
@@ -8526,7 +8895,15 @@ function createExecutionKernel(options) {
|
|
|
8526
8895
|
resolve
|
|
8527
8896
|
};
|
|
8528
8897
|
approvals.set(approvalId, approval);
|
|
8529
|
-
emit(st, { workspaceId: ws, sessionId: s, turnId: turn.turnId }, "approval.requested", {
|
|
8898
|
+
emit(st, { workspaceId: ws, sessionId: s, turnId: turn.turnId }, "approval.requested", {
|
|
8899
|
+
approvalId,
|
|
8900
|
+
toolName: req?.toolName ?? "unknown",
|
|
8901
|
+
actionDigest: req?.actionDigest ?? {},
|
|
8902
|
+
workspaceId: ws,
|
|
8903
|
+
turnId: turn.turnId,
|
|
8904
|
+
requestedAt: approval.requestedAt,
|
|
8905
|
+
sourceLane: "execution-upstream"
|
|
8906
|
+
});
|
|
8530
8907
|
approval.timer = setTimeout(() => {
|
|
8531
8908
|
settleApproval(approval, "expired");
|
|
8532
8909
|
}, approvalTimeoutMs);
|
|
@@ -33,8 +33,15 @@ export type ExecutionTurnRunnerDeps = {
|
|
|
33
33
|
};
|
|
34
34
|
text: string;
|
|
35
35
|
signal: AbortSignal;
|
|
36
|
-
/**
|
|
37
|
-
|
|
36
|
+
/**
|
|
37
|
+
* 注册待批操作:resolve 于 decide / 300s expired / turn 取消(voidedByCancel)。
|
|
38
|
+
* 0.1.129 C2-a(呈批书 §1,批复 @af5684e9):参数加性 optional(既有零参
|
|
39
|
+
* 调用点零破坏)——req 载入 approval.requested 七字段事件(C2-b)。
|
|
40
|
+
*/
|
|
41
|
+
requestApproval: (req?: {
|
|
42
|
+
toolName?: string;
|
|
43
|
+
actionDigest?: Record<string, unknown>;
|
|
44
|
+
}) => Promise<ExecutionApprovalDecision>;
|
|
38
45
|
/**
|
|
39
46
|
* 回合流增量发射(B1 前置件形 1,f4 附条件采认 @2026-11-21):经 kernel
|
|
40
47
|
* 既有 emit 权威落 `turn.delta`(cursor 单调/bind 三元组/缓冲上限同执法,
|
|
@@ -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 /
|
package/package.json
CHANGED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AtlasWeb S0-R `./web-session-runtime` pack 出口(工单 §4.5)。
|
|
3
|
-
*
|
|
4
|
-
* 纯 re-export 面:零副作用(禁入口导入就跑 CLI)、零 TUI/private TSX
|
|
5
|
-
* 泄漏(加载图审计);声明只依赖 contract 公开类型(经 ./contract 相对
|
|
6
|
-
* shim)。
|
|
7
|
-
* S0-R2 形 A(lock-face @25cb7454 §1/§2,f4 批复工单 §7 @351c74c4):本出口
|
|
8
|
-
* 扩具名导出 `createDefaultReadonlySessionRuntime`(engine 真体随 bundle,
|
|
9
|
-
* pack 格重形 = engine/session 只读闭包允许);注入缝
|
|
10
|
-
* (createReadonlySessionRuntime options.engine)保留不动(预答不变量)。
|
|
11
|
-
* 内部面不入出口:atlasWebSessionEngine / buildConversationChain /
|
|
12
|
-
* TranscriptMessage(d.ts 泄漏面钉②)。
|
|
13
|
-
*/
|
|
14
|
-
export { createReadonlySessionRuntime, type ReadonlySessionRuntime, type ReadonlySessionRuntimeOptions, type ReadonlySessionEngine, type ReadonlySessionScopes, type ReadonlySessionLimits, type ResolvedLimits, type ListSessionsRequest, type ListSessionsResult, type ReplaySessionRequest, type ReplaySessionResult, type FollowSessionRequest, type FollowSubscription, type SearchSessionsRequest, type SearchSessionsResult, } from './readonlyRuntime.js';
|
|
15
|
-
export { createDefaultReadonlySessionRuntime, type AtlasWebSessionRuntimeOptions, } from './runtimeDefault.js';
|
|
16
|
-
export type { FollowHandle } from './follow.js';
|
|
17
|
-
export type { SessionStoreAdapter, SessionStoreScopes, SessionFileEntry, TranscriptStat, TranscriptTail, } from './sessionStoreAdapter.js';
|
|
18
|
-
export type { NeutralProjection, NeutralProjectionMessage, NeutralBlock, ProjectionSourceMessage, ProjectionEngineDeps, ProjectionLoad, } from './projection.js';
|
|
19
|
-
export { WebSessionError, type WebSessionErrorCode } from './errors.js';
|
|
20
|
-
export { createExecutionOutlet, type ExecutionOutlet, type ExecutionOutletOptions, type ExecutionDispatchResult, type WebExecutionProbeResult, } from '../../kernel/execution/executionOutlet.js';
|
|
21
|
-
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';
|