@atlaswork/atlascode 0.0.0-stage → 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.
Files changed (63) hide show
  1. package/README.md +124 -2
  2. package/dist/cli.js +506227 -0
  3. package/dist/web-contract/index.d.ts +727 -0
  4. package/dist/web-contract/index.js +260 -0
  5. package/dist/web-session-runtime/atlascode/web/contract.d.ts +10 -0
  6. package/dist/web-session-runtime/atlascode/web/cursorLedger.d.ts +63 -0
  7. package/dist/web-session-runtime/atlascode/web/entry.d.ts +19 -0
  8. package/dist/web-session-runtime/atlascode/web/errors.d.ts +16 -0
  9. package/dist/web-session-runtime/atlascode/web/follow.d.ts +82 -0
  10. package/dist/web-session-runtime/atlascode/web/limits.d.ts +63 -0
  11. package/dist/web-session-runtime/atlascode/web/projection.d.ts +69 -0
  12. package/dist/web-session-runtime/atlascode/web/readonlyRuntime.d.ts +156 -0
  13. package/dist/web-session-runtime/atlascode/web/runtimeDefault.d.ts +26 -0
  14. package/dist/web-session-runtime/atlascode/web/sessionStoreAdapter.d.ts +70 -0
  15. package/dist/web-session-runtime/engine/session/env.d.ts +32 -0
  16. package/dist/web-session-runtime/engine/session/firstPrompt.d.ts +21 -0
  17. package/dist/web-session-runtime/engine/session/json.d.ts +27 -0
  18. package/dist/web-session-runtime/engine/session/load.d.ts +88 -0
  19. package/dist/web-session-runtime/engine/session/paths.d.ts +25 -0
  20. package/dist/web-session-runtime/engine/session/predicates.d.ts +55 -0
  21. package/dist/web-session-runtime/engine/session/readonly.d.ts +29 -0
  22. package/dist/web-session-runtime/engine/session/scanner.d.ts +26 -0
  23. package/dist/web-session-runtime/engine/session/search.d.ts +44 -0
  24. package/dist/web-session-runtime/engine/session/types.d.ts +379 -0
  25. package/dist/web-session-runtime/index.d.ts +1 -0
  26. package/dist/web-session-runtime/index.js +2635 -0
  27. package/dist/web-session-runtime/kernel/protocol/webSessionV0.d.ts +727 -0
  28. package/dist/web-session-runtime/shared/ProductDefinition.d.ts +47 -0
  29. package/dist/web-session-runtime/shared/agentRoleTemplates.d.ts +44 -0
  30. package/dist/web-session-runtime/shared/agentSwarmsEnabled.d.ts +5 -0
  31. package/dist/web-session-runtime/shared/boundedImageRead.d.ts +31 -0
  32. package/dist/web-session-runtime/shared/circular-buffer.d.ts +42 -0
  33. package/dist/web-session-runtime/shared/configDir.d.ts +57 -0
  34. package/dist/web-session-runtime/shared/constants.d.ts +19 -0
  35. package/dist/web-session-runtime/shared/debug.d.ts +32 -0
  36. package/dist/web-session-runtime/shared/env.d.ts +38 -0
  37. package/dist/web-session-runtime/shared/errors.d.ts +56 -0
  38. package/dist/web-session-runtime/shared/feature.d.ts +25 -0
  39. package/dist/web-session-runtime/shared/format.d.ts +11 -0
  40. package/dist/web-session-runtime/shared/fs-operations.d.ts +116 -0
  41. package/dist/web-session-runtime/shared/hash.d.ts +13 -0
  42. package/dist/web-session-runtime/shared/identity.d.ts +23 -0
  43. package/dist/web-session-runtime/shared/index.d.ts +46 -0
  44. package/dist/web-session-runtime/shared/lazySchema.d.ts +12 -0
  45. package/dist/web-session-runtime/shared/log.d.ts +1 -0
  46. package/dist/web-session-runtime/shared/path.d.ts +22 -0
  47. package/dist/web-session-runtime/shared/pdfPageImages.d.ts +19 -0
  48. package/dist/web-session-runtime/shared/pdfReference.d.ts +70 -0
  49. package/dist/web-session-runtime/shared/permissionDeadline.d.ts +24 -0
  50. package/dist/web-session-runtime/shared/platform.d.ts +8 -0
  51. package/dist/web-session-runtime/shared/stringUtils.d.ts +110 -0
  52. package/dist/web-session-runtime/shared/swarmSchemaFilter.d.ts +23 -0
  53. package/dist/web-session-runtime/shared/teamFileSchema.d.ts +151 -0
  54. package/dist/web-session-runtime/shared/teamInboxSchema.d.ts +112 -0
  55. package/dist/web-session-runtime/shared/teammateContext.d.ts +89 -0
  56. package/dist/web-session-runtime/shared/tempDir.d.ts +1 -0
  57. package/dist/web-session-runtime/shared/textEncoding.d.ts +41 -0
  58. package/dist/web-session-runtime/shared/tokenEstimation.d.ts +36 -0
  59. package/dist/web-session-runtime/shared/types-session.d.ts +266 -0
  60. package/dist/web-session-runtime/shared/types.d.ts +190 -0
  61. package/dist/web-session-runtime/shared/unc.d.ts +5 -0
  62. package/dist/web-session-runtime/shared/windowsPaths.d.ts +24 -0
  63. package/package.json +116 -4
@@ -0,0 +1,260 @@
1
+ // src/kernel/protocol/webSessionV0.ts
2
+ import { z } from "zod/v4";
3
+ var WEB_SESSION_SCHEMA_VERSION = 0;
4
+ var WEB_SESSION_PROTOCOL_VERSION = "v0";
5
+ var OpaqueIdSchema = z.string().min(1).max(128);
6
+ var OpaqueTokenSchema = z.string().min(1).max(512);
7
+ var IsoDateTimeSchema = z.iso.datetime();
8
+ var RevisionSchema = z.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
9
+ var EnvelopeFields = {
10
+ schemaVersion: z.literal(WEB_SESSION_SCHEMA_VERSION),
11
+ requestId: z.uuid(),
12
+ productId: OpaqueIdSchema,
13
+ scopeId: OpaqueIdSchema
14
+ };
15
+ var EventEnvelopeFields = {
16
+ schemaVersion: z.literal(WEB_SESSION_SCHEMA_VERSION),
17
+ productId: OpaqueIdSchema,
18
+ scopeId: OpaqueIdSchema,
19
+ subscriptionId: OpaqueIdSchema,
20
+ requestId: OpaqueIdSchema.optional()
21
+ };
22
+ var PageFields = {
23
+ pageSize: z.number().int().min(1).max(200).optional(),
24
+ pageToken: OpaqueTokenSchema.optional()
25
+ };
26
+ var codePoints = (s) => [...s].length;
27
+ var ListSessionsRequestSchema = z.strictObject({
28
+ ...EnvelopeFields,
29
+ kind: z.literal("listSessions"),
30
+ ...PageFields
31
+ });
32
+ var SearchSessionsRequestSchema = z.strictObject({
33
+ ...EnvelopeFields,
34
+ kind: z.literal("searchSessions"),
35
+ query: z.string().refine((s) => codePoints(s) >= 1 && codePoints(s) <= 256),
36
+ ...PageFields
37
+ });
38
+ var ReplaySessionRequestSchema = z.strictObject({
39
+ ...EnvelopeFields,
40
+ kind: z.literal("replaySession"),
41
+ sessionId: OpaqueIdSchema
42
+ });
43
+ var FollowSessionRequestSchema = z.strictObject({
44
+ ...EnvelopeFields,
45
+ kind: z.literal("followSession"),
46
+ sessionId: OpaqueIdSchema,
47
+ resumeCursor: OpaqueTokenSchema.optional()
48
+ });
49
+ var CancelRequestSchema = z.strictObject({
50
+ ...EnvelopeFields,
51
+ kind: z.literal("cancel"),
52
+ targetRequestId: OpaqueIdSchema
53
+ });
54
+ var UnsubscribeRequestSchema = z.strictObject({
55
+ ...EnvelopeFields,
56
+ kind: z.literal("unsubscribe"),
57
+ subscriptionId: OpaqueIdSchema
58
+ });
59
+ var WebSessionRequestSchema = z.discriminatedUnion("kind", [
60
+ ListSessionsRequestSchema,
61
+ SearchSessionsRequestSchema,
62
+ ReplaySessionRequestSchema,
63
+ FollowSessionRequestSchema,
64
+ CancelRequestSchema,
65
+ UnsubscribeRequestSchema
66
+ ]);
67
+ var TextBlockSchema = z.strictObject({
68
+ kind: z.literal("text"),
69
+ text: z.string()
70
+ });
71
+ var ActivityBlockSchema = z.strictObject({
72
+ kind: z.literal("activity"),
73
+ label: z.string().min(1).max(256),
74
+ status: z.string().max(64).optional()
75
+ });
76
+ var BlockSchema = z.discriminatedUnion("kind", [TextBlockSchema, ActivityBlockSchema]);
77
+ var ProjectionMessageSchema = z.strictObject({
78
+ id: OpaqueIdSchema,
79
+ role: z.enum(["user", "assistant", "system"]),
80
+ createdAt: IsoDateTimeSchema.nullable(),
81
+ blocks: z.array(BlockSchema)
82
+ });
83
+ var ProjectionSchema = z.strictObject({
84
+ sessionId: OpaqueIdSchema,
85
+ productId: OpaqueIdSchema,
86
+ scopeId: OpaqueIdSchema,
87
+ semantics: z.literal("persisted-effective-conversation"),
88
+ messages: z.array(ProjectionMessageSchema),
89
+ truncated: z.literal(false)
90
+ });
91
+ var SessionSummarySchema = z.strictObject({
92
+ sessionId: OpaqueIdSchema,
93
+ title: z.string().max(512).nullable(),
94
+ createdAt: IsoDateTimeSchema.nullable(),
95
+ updatedAt: IsoDateTimeSchema,
96
+ messageCount: z.number().int().min(0).nullable(),
97
+ productId: OpaqueIdSchema,
98
+ scopeId: OpaqueIdSchema
99
+ });
100
+ var SearchResultSchema = z.strictObject({
101
+ sessionId: OpaqueIdSchema,
102
+ messageId: OpaqueIdSchema,
103
+ snippet: z.string().refine((s) => codePoints(s) <= 512)
104
+ });
105
+ var ErrorBodyFields = { message: z.string().max(1024) };
106
+ var errorCode = (c) => z.strictObject({ code: z.literal(c), ...ErrorBodyFields });
107
+ var UnsupportedSchemaErrorSchema = errorCode("unsupportedSchema");
108
+ var InvalidRequestErrorSchema = errorCode("invalidRequest");
109
+ var ScopeDeniedErrorSchema = errorCode("scopeDenied");
110
+ var NotFoundErrorSchema = errorCode("notFound");
111
+ var CorruptDataErrorSchema = errorCode("corruptData");
112
+ var IoUnavailableErrorSchema = z.strictObject({
113
+ code: z.literal("ioUnavailable"),
114
+ ...ErrorBodyFields,
115
+ retryable: z.boolean()
116
+ });
117
+ var CursorExpiredErrorSchema = errorCode("cursorExpired");
118
+ var ResourceLimitErrorSchema = errorCode("resourceLimit");
119
+ var CancelledErrorSchema = errorCode("cancelled");
120
+ var ClosedErrorSchema = errorCode("closed");
121
+ var WebSessionErrorSchema = z.discriminatedUnion("code", [
122
+ UnsupportedSchemaErrorSchema,
123
+ InvalidRequestErrorSchema,
124
+ ScopeDeniedErrorSchema,
125
+ NotFoundErrorSchema,
126
+ CorruptDataErrorSchema,
127
+ IoUnavailableErrorSchema,
128
+ CursorExpiredErrorSchema,
129
+ ResourceLimitErrorSchema,
130
+ CancelledErrorSchema,
131
+ ClosedErrorSchema
132
+ ]);
133
+ var ResponseEnvelopeFields = {
134
+ schemaVersion: z.literal(WEB_SESSION_SCHEMA_VERSION),
135
+ requestId: z.uuid(),
136
+ productId: OpaqueIdSchema,
137
+ scopeId: OpaqueIdSchema,
138
+ kind: z.literal("response")
139
+ };
140
+ var ListSessionsSuccessSchema = z.strictObject({
141
+ ...ResponseEnvelopeFields,
142
+ of: z.literal("listSessions"),
143
+ sessions: z.array(SessionSummarySchema),
144
+ nextPageToken: OpaqueTokenSchema.optional()
145
+ });
146
+ var SearchSessionsSuccessSchema = z.strictObject({
147
+ ...ResponseEnvelopeFields,
148
+ of: z.literal("searchSessions"),
149
+ results: z.array(SearchResultSchema),
150
+ nextPageToken: OpaqueTokenSchema.optional()
151
+ });
152
+ var ReplaySessionSuccessSchema = z.strictObject({
153
+ ...ResponseEnvelopeFields,
154
+ of: z.literal("replaySession"),
155
+ projection: ProjectionSchema
156
+ });
157
+ var FollowSessionSuccessSchema = z.strictObject({
158
+ ...ResponseEnvelopeFields,
159
+ of: z.literal("followSession"),
160
+ subscriptionId: OpaqueIdSchema,
161
+ cursor: OpaqueTokenSchema.optional()
162
+ });
163
+ var WebSessionSuccessSchema = z.discriminatedUnion("of", [
164
+ ListSessionsSuccessSchema,
165
+ SearchSessionsSuccessSchema,
166
+ ReplaySessionSuccessSchema,
167
+ FollowSessionSuccessSchema
168
+ ]);
169
+ var WebSessionErrorResponseSchema = z.strictObject({
170
+ schemaVersion: z.literal(WEB_SESSION_SCHEMA_VERSION),
171
+ requestId: z.uuid(),
172
+ productId: OpaqueIdSchema,
173
+ scopeId: OpaqueIdSchema,
174
+ kind: z.literal("error"),
175
+ error: WebSessionErrorSchema
176
+ });
177
+ var BaselineEventSchema = z.strictObject({
178
+ ...EventEnvelopeFields,
179
+ kind: z.literal("baseline"),
180
+ generation: z.uuid(),
181
+ baselineId: z.uuid(),
182
+ revision: RevisionSchema,
183
+ cursor: OpaqueTokenSchema,
184
+ projection: ProjectionSchema
185
+ });
186
+ var ReplacementEventSchema = z.strictObject({
187
+ ...EventEnvelopeFields,
188
+ kind: z.literal("replacement"),
189
+ generation: z.uuid(),
190
+ baselineId: z.uuid(),
191
+ revision: RevisionSchema,
192
+ cursor: OpaqueTokenSchema,
193
+ projection: ProjectionSchema
194
+ });
195
+ var ResetRequiredEventSchema = z.strictObject({
196
+ ...EventEnvelopeFields,
197
+ kind: z.literal("resetRequired"),
198
+ generation: z.uuid(),
199
+ reason: z.string().max(256)
200
+ });
201
+ var ErrorEventSchema = z.strictObject({
202
+ ...EventEnvelopeFields,
203
+ kind: z.literal("error"),
204
+ error: WebSessionErrorSchema
205
+ });
206
+ var ClosedEventSchema = z.strictObject({
207
+ ...EventEnvelopeFields,
208
+ kind: z.literal("closed"),
209
+ reason: z.string().max(256).optional()
210
+ });
211
+ var WebSessionEventSchema = z.discriminatedUnion("kind", [
212
+ BaselineEventSchema,
213
+ ReplacementEventSchema,
214
+ ResetRequiredEventSchema,
215
+ ErrorEventSchema,
216
+ ClosedEventSchema
217
+ ]);
218
+ export {
219
+ ActivityBlockSchema,
220
+ BaselineEventSchema,
221
+ BlockSchema,
222
+ CancelRequestSchema,
223
+ CancelledErrorSchema,
224
+ ClosedErrorSchema,
225
+ ClosedEventSchema,
226
+ CorruptDataErrorSchema,
227
+ CursorExpiredErrorSchema,
228
+ ErrorEventSchema,
229
+ FollowSessionRequestSchema,
230
+ FollowSessionSuccessSchema,
231
+ InvalidRequestErrorSchema,
232
+ IoUnavailableErrorSchema,
233
+ ListSessionsRequestSchema,
234
+ ListSessionsSuccessSchema,
235
+ NotFoundErrorSchema,
236
+ OpaqueIdSchema,
237
+ OpaqueTokenSchema,
238
+ ProjectionMessageSchema,
239
+ ProjectionSchema,
240
+ ReplacementEventSchema,
241
+ ReplaySessionRequestSchema,
242
+ ReplaySessionSuccessSchema,
243
+ ResetRequiredEventSchema,
244
+ ResourceLimitErrorSchema,
245
+ ScopeDeniedErrorSchema,
246
+ SearchResultSchema,
247
+ SearchSessionsRequestSchema,
248
+ SearchSessionsSuccessSchema,
249
+ SessionSummarySchema,
250
+ TextBlockSchema,
251
+ UnsubscribeRequestSchema,
252
+ UnsupportedSchemaErrorSchema,
253
+ WEB_SESSION_PROTOCOL_VERSION,
254
+ WEB_SESSION_SCHEMA_VERSION,
255
+ WebSessionErrorResponseSchema,
256
+ WebSessionErrorSchema,
257
+ WebSessionEventSchema,
258
+ WebSessionRequestSchema,
259
+ WebSessionSuccessSchema
260
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * AtlasWeb S0-R contract 类型闭包 shim(R-3)。
3
+ *
4
+ * 本域对 contract 公开类型的唯一类型入口:**相对路径**引用(而非
5
+ * 'src/...' 别名),使 tsc emitDeclarationOnly 产出的 d.ts 在 pack
6
+ * (dist/web-session-runtime)内相对可解析、零仓库内 specifier 泄漏
7
+ * (§4.5 加载图审计面:声明只依赖 contract 公开类型)。运行时零开销
8
+ * (纯 type re-export)。
9
+ */
10
+ export type { WebSessionEvent, WebSessionProjection, } from '../../kernel/protocol/webSessionV0.js';
@@ -0,0 +1,63 @@
1
+ /**
2
+ * AtlasWeb S0-R cursor/result snapshot 账本(工单 §4.3 / 呈批书 §7.5)。
3
+ *
4
+ * opaque 随机 token ↔ 实例内绑定 {product, scope, session, baselineId,
5
+ * generation, revision, expiry}。伪造/未知 → 'unknown'(调用方按
6
+ * resetRequired+新 baseline 或 closed 处置);跨域 → 'mismatch'
7
+ * (scopeDenied);过期 → 'expired'(resetRequired+新 baseline)。
8
+ * LRU 淘汰序:未 pin(无活跃 subscription 绑定)先淘;全 pinned 淘最旧
9
+ * pinned 并回调 onActiveEvict(显式 resetRequired,禁静默失效)。
10
+ */
11
+ export type CursorVerifyResult = {
12
+ ok: true;
13
+ binding: CursorBinding;
14
+ } | {
15
+ ok: false;
16
+ why: 'unknown' | 'expired' | 'mismatch';
17
+ message: string;
18
+ };
19
+ export interface CursorBinding {
20
+ /**
21
+ * token 内部版本化(S0-R5 呈批书 §3 @6e772c02):opaque token 不变,
22
+ * payload 结构版本字段在册(v1 = 首个携字节锚的版本;升级 wire 不
23
+ * breaking——消费侧只持 opaque token)。
24
+ */
25
+ v: 1;
26
+ productId: string;
27
+ scopeId: string;
28
+ sessionId: string;
29
+ baselineId: string;
30
+ generation: string;
31
+ revision: number;
32
+ /**
33
+ * S0-R5 加性字节锚(§12-3 机制钉):resume 续接的读取起点(完整记录
34
+ * 边界或含 pendingPartial 的 EOF)与文件身份锚。加性面,既有五字段
35
+ * 不动。
36
+ */
37
+ byteOffset: number;
38
+ ino: number;
39
+ }
40
+ export declare class CursorLedger {
41
+ private readonly capacity;
42
+ private readonly ttlMs;
43
+ private readonly maxPayloadBytes;
44
+ private readonly onActiveEvict?;
45
+ private readonly entries;
46
+ private readonly payloadBytes;
47
+ constructor(capacity: number, ttlMs: number, maxPayloadBytes: number, onActiveEvict?: ((token: string, binding: CursorBinding) => void) | undefined);
48
+ issue(binding: CursorBinding, payloadBytes?: number): string;
49
+ /** 活跃 subscription 绑定 pin(LRU 淘序:未 pin 先淘)。 */
50
+ pin(token: string): void;
51
+ unpin(token: string): void;
52
+ refreshExpiry(token: string): void;
53
+ verify(token: string, who: {
54
+ productId: string;
55
+ scopeId: string;
56
+ sessionId: string;
57
+ }): CursorVerifyResult;
58
+ totalPayloadBytes(): number;
59
+ size(): number;
60
+ private evictForInsert;
61
+ }
62
+ /** 语义化构造:账本实例共用 invalidRequest 拒面(容量/TTL 由 limits 校验)。 */
63
+ export declare function assertLedgerConfig(capacity: number, ttlMs: number): void;
@@ -0,0 +1,19 @@
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';
@@ -0,0 +1,16 @@
1
+ /**
2
+ * AtlasWeb S0-R(0.1.116 候)web 域错误单源。
3
+ *
4
+ * 工单 docs/2026-11-15-atlasweb-s0-upstream-delivery-ticket.md §4.1 /
5
+ * 呈批书 docs/2026-11-15-s0-ur-lockface-brief.md §7.3-§7.5(f4 批复
6
+ * @f1f1099d)。code 域 = contract 错误联合 10 codes
7
+ * (src/kernel/protocol/webSessionV0.ts WebSessionErrorSchema)。
8
+ * ioUnavailable 独占 retryable(契约钉死,其余 code 不携该字段)。
9
+ */
10
+ export type WebSessionErrorCode = 'unsupportedSchema' | 'invalidRequest' | 'scopeDenied' | 'notFound' | 'corruptData' | 'ioUnavailable' | 'cursorExpired' | 'resourceLimit' | 'cancelled' | 'closed';
11
+ export declare class WebSessionError extends Error {
12
+ readonly code: WebSessionErrorCode;
13
+ /** 仅 ioUnavailable 语义位(契约:其余 code 不投影该字段)。 */
14
+ readonly retryable?: boolean;
15
+ constructor(code: WebSessionErrorCode, message: string, retryable?: boolean);
16
+ }
@@ -0,0 +1,82 @@
1
+ /**
2
+ * AtlasWeb S0-R follow 订阅机(工单 §4.3 一致性/恢复 + 呈批书 §7.5
3
+ * 采样序/cursor/lease/终态优先序,f4 批复 @f1f1099d + §5.7 @98c51bd6
4
+ * 终态形态钉死:closed 恒为唯一 terminal 事件 kind——error 终态路径 =
5
+ * error{code} → closed 成对送达,终态后零数据事件)。
6
+ *
7
+ * 采样序(§4.3 先采样后 baseline,一致 snapshot):baseline 前后双采样
8
+ * 三元组全等方采纳(ino/size/mtime),不夏现有界重试(3 次)→
9
+ * ioUnavailable retryable。半行不当完整记录等下一采样;非法完整行
10
+ * corruptData 不无限等待。增量尾读 = 上次 offset 起步只解析新增字节;
11
+ * 稳定文件 repeat poll 走 O(1) stat 通道(零 read/零 parse/零事件)。
12
+ * 不连续(truncate/replace/compact,ino 变或 size < offset)→
13
+ * resetRequired + 新 generation/baseline,旧消息不再采纳。
14
+ * S0-R5 重采样兜底(呈批书 §2 @6e772c02,f4 §13 批复):同 inode
15
+ * size > offset 的 rewrite 漏过单向守卫 → 旧 offset 尾读 unparseable
16
+ * complete record 时不再硬终流,先做单次身份重采样复核(成本上界
17
+ * ≤ maxTranscriptBytes,禁循环)→ 3-way 分类:prefix 异 →
18
+ * resetRequired + 新 baseline;全量可解析且 prefix 同(瞬态撕裂/半行
19
+ * 竞态)→ 静默自愈零终态;仍 unparseable → corruptData 真损坏
20
+ * (终态收窄至此)。
21
+ * S0-R5 resumeCursor 续接(呈批书 §3):verify ok → 内部 parse
22
+ * [0, byteOffset) 重建投影态(不发 baseline 事件——零重放)→
23
+ * offset/ino 锚定进既有轮询(断连窗 append 从文件本身恢复);verify
24
+ * 三因(unknown/expired/mismatch)统一 → resetRequired 显式分态 +
25
+ * 新 baseline(分因 message 透传,禁静默 fresh);resume 起点过 ②
26
+ * 同一判定面(offset 越界/ino 错配 → resetRequired 同形)。
27
+ *
28
+ * 终态恰一(优先序 §7.5):closed(4) > error(cancelled)(3) > 其余
29
+ * error(2),高可覆低(替换队内未消费终态对);resetRequired 非终态。
30
+ * close() 加盟 worker 停止(有界 2s);订阅槽释放恰一次(worker 实停
31
+ * 才释放,杜绝 close 竞态下槽位早释的限额绕过)。
32
+ */
33
+ import type { WebSessionEvent } from './contract.js';
34
+ import type { CursorLedger } from './cursorLedger.js';
35
+ import type { SessionStoreAdapter } from './sessionStoreAdapter.js';
36
+ import { type ProjectionEngineDeps, type ProjectionSourceMessage } from './projection.js';
37
+ /** 投影消息源结构面(engine TranscriptMessage 的结构超集镜像,pack 域零引擎导入)。 */
38
+ export type FollowSourceMessage = ProjectionSourceMessage;
39
+ export interface FollowLimits {
40
+ pollingIntervalMs: number;
41
+ idleLeaseMs: number;
42
+ pendingEvents: number;
43
+ pendingBytes: number;
44
+ maxProjectionBytes: number;
45
+ maxRecordBytes: number;
46
+ /** S0-R5:重采样/续接全量读的字节上界(钉 3 成本界;超界 resourceLimit)。 */
47
+ maxTranscriptBytes: number;
48
+ }
49
+ export interface FollowDeps {
50
+ adapter: SessionStoreAdapter;
51
+ productId: string;
52
+ scopeId: string;
53
+ sessionId: string;
54
+ subscriptionId: string;
55
+ requestId?: string;
56
+ /**
57
+ * S0-R5 ③:opaque resume cursor(账本 token)。在场 → verify 续接支
58
+ * (零 baseline 事件);缺席 → 既有 fresh baseline。协议形
59
+ * webSessionV0 FollowSessionRequestSchema.resumeCursor optional。
60
+ */
61
+ resumeCursor?: string;
62
+ limits: FollowLimits;
63
+ signal?: AbortSignal;
64
+ ledger: CursorLedger;
65
+ /** 引擎 loader 全量基线面(显式 filePath;呈批书 §7.3 钉死形,注入缝)。 */
66
+ loadFull: (filePath: string) => Promise<{
67
+ messages: Map<string, ProjectionSourceMessage>;
68
+ leafUuids: Set<string>;
69
+ }>;
70
+ /** 经 adapter 校验链的显式路径解析(scope 授权 + containment)。 */
71
+ resolvePath: (scopeId: string, sessionId: string) => Promise<string>;
72
+ /** CLI 同规则链重建注入缝(projection 头注镜像义务)。 */
73
+ buildConversationChain: ProjectionEngineDeps['buildConversationChain'];
74
+ /** 订阅槽释放回调(worker 实停时恰一次)。 */
75
+ onRelease: () => void;
76
+ }
77
+ export interface FollowHandle {
78
+ [Symbol.asyncIterator](): AsyncIterator<WebSessionEvent>;
79
+ renewLease(): Promise<boolean>;
80
+ close(): Promise<void>;
81
+ }
82
+ export declare function createFollowSubscription(deps: FollowDeps): FollowHandle;
@@ -0,0 +1,63 @@
1
+ /**
2
+ * AtlasWeb S0-R web 域单一资源常量表(工单 §4.4 冻结值;呈批书 §7.4
3
+ * "常量单源 src/atlascode/web/limits.ts")。
4
+ *
5
+ * 每参数 DEFAULT 可配(不得越 HARD 硬上限,host 不可调高);R-1 先落
6
+ * runtime/adapter 首车需要的界,R-2 补齐全表(pending/lease/cursor 族)。
7
+ */
8
+ export declare const MIB: number;
9
+ export declare const DEFAULT_MAX_TRANSCRIPT_BYTES: number;
10
+ export declare const HARD_MAX_TRANSCRIPT_BYTES: number;
11
+ export declare const DEFAULT_MAX_SCAN_SESSIONS = 4096;
12
+ export declare const HARD_MAX_SCAN_SESSIONS = 16384;
13
+ export declare const DEFAULT_MAX_SCOPES_PER_RUNTIME = 32;
14
+ export declare const HARD_MAX_SCOPES_PER_RUNTIME = 128;
15
+ export declare const DEFAULT_PAGE_SIZE = 50;
16
+ export declare const HARD_MAX_PAGE_SIZE = 200;
17
+ export declare const SEARCH_QUERY_MIN_CODE_POINTS = 1;
18
+ export declare const SEARCH_QUERY_MAX_CODE_POINTS = 256;
19
+ export declare const DEFAULT_MAX_RECORD_BYTES: number;
20
+ export declare const HARD_MAX_RECORD_BYTES: number;
21
+ export declare const DEFAULT_MAX_PARSE_RECORDS = 100000;
22
+ export declare const HARD_MAX_PARSE_RECORDS = 500000;
23
+ export declare const DEFAULT_MAX_PROJECTION_BYTES: number;
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;
30
+ export declare const DEFAULT_MAX_SUBSCRIPTIONS = 16;
31
+ export declare const HARD_MAX_SUBSCRIPTIONS = 64;
32
+ export declare const DEFAULT_MAX_CONCURRENT_READS = 4;
33
+ export declare const HARD_MAX_CONCURRENT_READS = 16;
34
+ export declare const DEFAULT_MAX_PENDING_EVENTS = 8;
35
+ export declare const HARD_MAX_PENDING_EVENTS = 32;
36
+ export declare const DEFAULT_MAX_PENDING_BYTES: number;
37
+ export declare const HARD_MAX_PENDING_BYTES: number;
38
+ export declare const DEFAULT_POLLING_INTERVAL_MS = 1000;
39
+ export declare const HARD_MIN_POLLING_INTERVAL_MS = 100;
40
+ export declare const HARD_MAX_POLLING_INTERVAL_MS = 60000;
41
+ export declare const DEFAULT_REQUEST_DEADLINE_MS = 10000;
42
+ export declare const HARD_MIN_REQUEST_DEADLINE_MS = 1;
43
+ export declare const HARD_MAX_REQUEST_DEADLINE_MS = 60000;
44
+ export declare const DEFAULT_IDLE_LEASE_MS = 120000;
45
+ export declare const HARD_MIN_IDLE_LEASE_MS = 1000;
46
+ export declare const HARD_MAX_IDLE_LEASE_MS = 600000;
47
+ export declare const DEFAULT_CURSOR_TTL_MS = 600000;
48
+ export declare const HARD_MIN_CURSOR_TTL_MS = 1000;
49
+ export declare const HARD_MAX_CURSOR_TTL_MS = 3600000;
50
+ export declare const DEFAULT_CLOSE_DEADLINE_MS = 2000;
51
+ export declare const HARD_MIN_CLOSE_DEADLINE_MS = 1;
52
+ export declare const HARD_MAX_CLOSE_DEADLINE_MS = 10000;
53
+ export declare const DEFAULT_LEDGER_CAPACITY = 128;
54
+ export declare const HARD_MAX_LEDGER_CAPACITY = 1024;
55
+ export declare const DEFAULT_LEDGER_PAYLOAD_BYTES: number;
56
+ export declare const HARD_MAX_LEDGER_PAYLOAD_BYTES: number;
57
+ export declare const READ_CHUNK_SIZE: number;
58
+ export declare const PARSE_BATCH_SIZE = 256;
59
+ /**
60
+ * 有界整数校验(工单 §4.4:禁 NaN/Infinity/小数/负值;>硬上限拒)。
61
+ * value === undefined → 缺省值;不合法 → invalidRequest。
62
+ */
63
+ export declare function validateBoundedInt(name: string, value: number | undefined, defaultValue: number, hardMax: number, hardMin?: number): number;
@@ -0,0 +1,69 @@
1
+ /**
2
+ * AtlasWeb S0-R Code→中立投影(工单 §4.1 projection.ts;呈批书 §7.3
3
+ * persisted-effective-conversation 显式定义 / 必改 6 Code-neutral 词汇审计)。
4
+ *
5
+ * 输入 = loadTranscriptFull 的只读加载结果(经注入缝,本域零 engine 导入
6
+ * ——§4.5 pack 加载图审计面);输出 = contract ProjectionSchema 形
7
+ * (text/activity 两块型,无任何内部词汇)。leaf 选取 = terminal leaf 中
8
+ * timestamp 最新者(CLI 同域规则),链路 = 注入的 buildConversationChain
9
+ * (CLI 同规则 load.ts 镜像,引擎适配边界做类型焊接,见 runtimeDefault.ts);
10
+ * compact 边界行 / session 级元数据行不投影。
11
+ */
12
+ /** 投影消息源结构面(磁盘 JSONL 行的窄结构镜像;pack 域公开类型)。 */
13
+ export interface ProjectionSourceMessage {
14
+ uuid: string;
15
+ parentUuid: string | null;
16
+ type: string;
17
+ timestamp?: string | null;
18
+ message?: {
19
+ content?: unknown;
20
+ };
21
+ }
22
+ /** 注入缝:CLI 同规则链重建(load.ts buildConversationChain 镜像义务)。 */
23
+ export interface ProjectionEngineDeps {
24
+ buildConversationChain: (messages: Map<string, ProjectionSourceMessage>, leaf: ProjectionSourceMessage) => ProjectionSourceMessage[];
25
+ }
26
+ /** 投影块(contract BlockSchema 子面;label ≤256 / text 无界走 resourceLimit)。 */
27
+ export type NeutralBlock = {
28
+ kind: 'text';
29
+ text: string;
30
+ } | {
31
+ kind: 'activity';
32
+ label: string;
33
+ status?: string;
34
+ };
35
+ export interface NeutralProjectionMessage {
36
+ id: string;
37
+ role: 'user' | 'assistant' | 'system';
38
+ createdAt: string | null;
39
+ blocks: NeutralBlock[];
40
+ }
41
+ export interface NeutralProjection {
42
+ sessionId: string;
43
+ productId: string;
44
+ scopeId: string;
45
+ semantics: 'persisted-effective-conversation';
46
+ messages: NeutralProjectionMessage[];
47
+ truncated: false;
48
+ }
49
+ export interface ProjectionLoad {
50
+ messages: Map<string, ProjectionSourceMessage>;
51
+ leafUuids: Set<string>;
52
+ }
53
+ /** 事件/projection 序列化字节单一口径(replay 与 follow 共享,防兄弟路漂移)。 */
54
+ export declare function serializedProjectionBytes(p: unknown): number;
55
+ /**
56
+ * terminal leaf 集计算(load.ts:1187-1226 同规则镜像:terminal → 最近
57
+ * user/assistant 祖先;增量尾读路径复用。f4 §5.7 登记:镜像同步义务,
58
+ * 漂移守卫 = 必改5a fixture 对表 standing)。leafUuids 选 timestamp 最新者。
59
+ */
60
+ export declare function computeLeafUuids(messages: Map<string, ProjectionSourceMessage>): Set<string>;
61
+ /**
62
+ * terminal leaf 集中选 timestamp 最新者(并列取插入序末位),注入的
63
+ * CLI 同规则链重建;空载入 → 空投影。
64
+ */
65
+ export declare function projectConversation(load: ProjectionLoad, meta: {
66
+ sessionId: string;
67
+ productId: string;
68
+ scopeId: string;
69
+ }, engine: ProjectionEngineDeps): NeutralProjection;