@atlaswork/atlascode 0.1.124 → 0.1.125

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.
@@ -22,6 +22,11 @@ export declare const DEFAULT_MAX_PARSE_RECORDS = 100000;
22
22
  export declare const HARD_MAX_PARSE_RECORDS = 500000;
23
23
  export declare const DEFAULT_MAX_PROJECTION_BYTES: number;
24
24
  export declare const HARD_MAX_PROJECTION_BYTES: number;
25
+ export declare const TITLE_HEAD_BYTES: number;
26
+ /** wire 契约 title ≤512 code points(SessionSummarySchema)——钳制上限。 */
27
+ export declare const TITLE_MAX_CODE_POINTS = 512;
28
+ /** 首条 user 消息派生标题的展示截断点(≤契约 512)。 */
29
+ export declare const TITLE_USER_MESSAGE_CODE_POINTS = 120;
25
30
  export declare const DEFAULT_MAX_SUBSCRIPTIONS = 16;
26
31
  export declare const HARD_MAX_SUBSCRIPTIONS = 64;
27
32
  export declare const DEFAULT_MAX_CONCURRENT_READS = 4;
@@ -33,6 +33,12 @@ export interface TranscriptTail {
33
33
  sizeBytes: number;
34
34
  ino: number;
35
35
  }
36
+ /** 有界头读结果(G-D):bytes.length ≤ maxBytes;sizeBytes = 文件全尺寸。 */
37
+ export interface TranscriptHead {
38
+ bytes: Uint8Array;
39
+ sizeBytes: number;
40
+ ino: number;
41
+ }
36
42
  export interface SessionStoreAdapter {
37
43
  start(): Promise<void>;
38
44
  listSessionFiles(scopeId: string): Promise<SessionFileEntry[]>;
@@ -41,6 +47,12 @@ export interface SessionStoreAdapter {
41
47
  statTranscript(scopeId: string, sessionId: string): Promise<TranscriptStat | null>;
42
48
  /** 增量尾读:offset 起步只取新增字节(§7.5 零重解析判据)。 */
43
49
  readTranscriptTail(scopeId: string, sessionId: string, offset: number, signal?: AbortSignal): Promise<TranscriptTail>;
50
+ /**
51
+ * 有界头读(G-D,2026-11-20):[0, maxBytes) 窗读取(list 面 title
52
+ * 提取源)。可选缝——缺省 adapter 不实现时 runtime 诚实降级 title
53
+ * null;Node fs 默认载体实有。同一安全读链(openValidated + 读毕复核)。
54
+ */
55
+ readTranscriptHead?(scopeId: string, sessionId: string, maxBytes: number, signal?: AbortSignal): Promise<TranscriptHead>;
44
56
  /**
45
57
  * 显式路径解析(baseline loadFull 的 filePath 源;呈批书 §7.3 scopeId ↔
46
58
  * storageDir 显式映射):经同一校验链后返回文件路径。
@@ -1081,6 +1081,9 @@ var DEFAULT_MAX_PARSE_RECORDS = 1e5;
1081
1081
  var HARD_MAX_PARSE_RECORDS = 500000;
1082
1082
  var DEFAULT_MAX_PROJECTION_BYTES = 4 * MIB;
1083
1083
  var HARD_MAX_PROJECTION_BYTES = 16 * MIB;
1084
+ var TITLE_HEAD_BYTES = 64 * 1024;
1085
+ var TITLE_MAX_CODE_POINTS = 512;
1086
+ var TITLE_USER_MESSAGE_CODE_POINTS = 120;
1084
1087
  var DEFAULT_MAX_SUBSCRIPTIONS = 16;
1085
1088
  var HARD_MAX_SUBSCRIPTIONS = 64;
1086
1089
  var DEFAULT_MAX_CONCURRENT_READS = 4;
@@ -1991,6 +1994,27 @@ function createNodeFsSessionStoreAdapter(options) {
1991
1994
  await fh.close();
1992
1995
  }
1993
1996
  }
1997
+ async function readTranscriptHead(scopeId, sessionId, maxBytes, signal) {
1998
+ if (!Number.isInteger(maxBytes) || maxBytes <= 0) {
1999
+ throw new WebSessionError("invalidRequest", "maxBytes must be a positive integer");
2000
+ }
2001
+ const { fh, st } = await openValidated(scopeId, sessionId);
2002
+ try {
2003
+ const want = Math.min(st.size, maxBytes);
2004
+ const chunks = await readFromFd(fh, want, 0, signal);
2005
+ const st2 = await fh.stat();
2006
+ if (st2.ino !== st.ino || st2.size !== st.size) {
2007
+ throw new WebSessionError("ioUnavailable", "file changed during head read (not a stable snapshot)", true);
2008
+ }
2009
+ return {
2010
+ bytes: new Uint8Array(Buffer.concat(chunks)),
2011
+ sizeBytes: st.size,
2012
+ ino: st.ino
2013
+ };
2014
+ } finally {
2015
+ await fh.close();
2016
+ }
2017
+ }
1994
2018
  return {
1995
2019
  async start() {
1996
2020
  if (options.productId !== "atlascode") {
@@ -2056,6 +2080,7 @@ function createNodeFsSessionStoreAdapter(options) {
2056
2080
  readTranscript,
2057
2081
  statTranscript,
2058
2082
  readTranscriptTail,
2083
+ readTranscriptHead,
2059
2084
  async resolveTranscriptPath(scopeId, sessionId) {
2060
2085
  const { fh } = await openValidated(scopeId, sessionId);
2061
2086
  await fh.close();
@@ -2225,6 +2250,72 @@ function toSummary(entry, productId, scopeId) {
2225
2250
  scopeId
2226
2251
  };
2227
2252
  }
2253
+ function userMessageText(message) {
2254
+ if (typeof message !== "object" || message === null)
2255
+ return null;
2256
+ const content = message.content;
2257
+ if (typeof content === "string")
2258
+ return content;
2259
+ if (!Array.isArray(content))
2260
+ return null;
2261
+ const parts = [];
2262
+ for (const block of content) {
2263
+ if (typeof block === "object" && block !== null && block.type === "text" && typeof block.text === "string") {
2264
+ parts.push(block.text);
2265
+ }
2266
+ }
2267
+ return parts.length > 0 ? parts.join(" ") : null;
2268
+ }
2269
+ function clampCodePoints(text, max, ellipsis = false) {
2270
+ const points = Array.from(text);
2271
+ if (points.length <= max)
2272
+ return text;
2273
+ const keep = ellipsis ? max - 1 : max;
2274
+ return `${points.slice(0, keep).join("")}…`;
2275
+ }
2276
+ function extractListFace(bytes, fullRead) {
2277
+ const text = new TextDecoder("utf-8", { fatal: false }).decode(bytes);
2278
+ const lines = text.split(`
2279
+ `);
2280
+ lines.pop();
2281
+ let customTitle = null;
2282
+ let summaryText = null;
2283
+ let firstUserText = null;
2284
+ let messageCount = fullRead ? 0 : null;
2285
+ for (const line of lines) {
2286
+ if (line.length === 0)
2287
+ continue;
2288
+ let entry;
2289
+ try {
2290
+ entry = JSON.parse(line);
2291
+ } catch {
2292
+ continue;
2293
+ }
2294
+ const type = entry.type;
2295
+ if (type === "custom-title" && typeof entry.customTitle === "string" && customTitle === null) {
2296
+ customTitle = entry.customTitle;
2297
+ } else if (type === "summary" && typeof entry.summary === "string" && summaryText === null) {
2298
+ summaryText = entry.summary;
2299
+ } else if (type === "user" || type === "assistant") {
2300
+ if (messageCount !== null)
2301
+ messageCount++;
2302
+ if (type === "user" && firstUserText === null) {
2303
+ const text2 = userMessageText(entry.message);
2304
+ if (text2 !== null && text2.trim().length > 0)
2305
+ firstUserText = text2;
2306
+ }
2307
+ }
2308
+ }
2309
+ const raw = customTitle ?? summaryText ?? firstUserText;
2310
+ let title = null;
2311
+ if (raw !== null) {
2312
+ const collapsed = raw.replace(/\s+/gu, " ").trim();
2313
+ if (collapsed.length > 0) {
2314
+ title = clampCodePoints(collapsed, raw === firstUserText && customTitle === null && summaryText === null ? TITLE_USER_MESSAGE_CODE_POINTS : TITLE_MAX_CODE_POINTS, true);
2315
+ }
2316
+ }
2317
+ return { title, messageCount };
2318
+ }
2228
2319
  function createReadonlySessionRuntime(options) {
2229
2320
  const epoch = randomUUID2();
2230
2321
  const adapter = options.adapter ?? createNodeFsSessionStoreAdapter({
@@ -2363,9 +2454,19 @@ function createReadonlySessionRuntime(options) {
2363
2454
  if (entries.length > L.maxScanSessions) {
2364
2455
  throw new WebSessionError("resourceLimit", `scope ${req.scopeId} exceeds scan limit (${entries.length} > ${L.maxScanSessions})`);
2365
2456
  }
2366
- return {
2367
- sessions: entries.map((e) => toSummary(e, options.productId, req.scopeId))
2368
- };
2457
+ const sessions = await Promise.all(entries.map(async (e) => {
2458
+ const summary = toSummary(e, options.productId, req.scopeId);
2459
+ try {
2460
+ const head = await adapter.readTranscriptHead?.(req.scopeId, e.sessionId, TITLE_HEAD_BYTES, signal);
2461
+ if (head !== undefined) {
2462
+ const face = extractListFace(head.bytes, head.sizeBytes <= TITLE_HEAD_BYTES);
2463
+ summary.title = face.title;
2464
+ summary.messageCount = face.messageCount;
2465
+ }
2466
+ } catch {}
2467
+ return summary;
2468
+ }));
2469
+ return { sessions };
2369
2470
  },
2370
2471
  async searchSessions(req, signal) {
2371
2472
  assertStarted("search sessions");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaswork/atlascode",
3
- "version": "0.1.124",
3
+ "version": "0.1.125",
4
4
  "description": "AtlasCode — Coding Agent for the domestic computing ecosystem (Ascend NPU + domestic LLM backends)",
5
5
  "homepage": "https://www.atlaswork.cn/",
6
6
  "bin": {