@khorsheed/dsh-context-lens 0.0.0-stage → 0.1.0

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 (94) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.en.md +53 -0
  3. package/README.i18n.yaml +6 -0
  4. package/README.md +52 -2
  5. package/cordis.patch.yml +13 -0
  6. package/lib/client.js +26953 -0
  7. package/lib/index.js +3943 -0
  8. package/lib/typert.host.d.ts +3 -0
  9. package/lib/typert.host.js +1569 -0
  10. package/lib/typert.remote-client.d.ts +40 -0
  11. package/lib/typert.remote-client.js +1202 -0
  12. package/lib/types/changes.d.ts +72 -0
  13. package/lib/types/changes.js +328 -0
  14. package/lib/types/client/AgentTabs.d.ts +34 -0
  15. package/lib/types/client/AgentTabs.js +89 -0
  16. package/lib/types/client/ChangeList.d.ts +28 -0
  17. package/lib/types/client/ChangeList.js +109 -0
  18. package/lib/types/client/ConfigFacts.d.ts +21 -0
  19. package/lib/types/client/ConfigFacts.js +30 -0
  20. package/lib/types/client/HeaderUtility.d.ts +12 -0
  21. package/lib/types/client/HeaderUtility.js +8 -0
  22. package/lib/types/client/InspectorPanel.d.ts +5 -0
  23. package/lib/types/client/InspectorPanel.js +486 -0
  24. package/lib/types/client/RawView.d.ts +18 -0
  25. package/lib/types/client/RawView.js +8 -0
  26. package/lib/types/client/RequestFacts.d.ts +19 -0
  27. package/lib/types/client/RequestFacts.js +39 -0
  28. package/lib/types/client/RoomDecisionsView.d.ts +24 -0
  29. package/lib/types/client/RoomDecisionsView.js +52 -0
  30. package/lib/types/client/SchemaFields.d.ts +13 -0
  31. package/lib/types/client/SchemaFields.js +96 -0
  32. package/lib/types/client/SegCtl.d.ts +32 -0
  33. package/lib/types/client/SegCtl.js +12 -0
  34. package/lib/types/client/SegmentBlocks.d.ts +28 -0
  35. package/lib/types/client/SegmentBlocks.js +225 -0
  36. package/lib/types/client/TimingView.d.ts +17 -0
  37. package/lib/types/client/TimingView.js +98 -0
  38. package/lib/types/client/TokenView.d.ts +21 -0
  39. package/lib/types/client/TokenView.js +22 -0
  40. package/lib/types/client/ToolCatalog.d.ts +9 -0
  41. package/lib/types/client/ToolCatalog.js +51 -0
  42. package/lib/types/client/Trend.d.ts +25 -0
  43. package/lib/types/client/Trend.js +100 -0
  44. package/lib/types/client/TurnAction.d.ts +14 -0
  45. package/lib/types/client/TurnAction.js +31 -0
  46. package/lib/types/client/TurnMenu.d.ts +36 -0
  47. package/lib/types/client/TurnMenu.js +50 -0
  48. package/lib/types/client/aggregate.d.ts +141 -0
  49. package/lib/types/client/aggregate.js +213 -0
  50. package/lib/types/client/contract.d.ts +58 -0
  51. package/lib/types/client/contract.js +1 -0
  52. package/lib/types/client/definition.d.ts +47 -0
  53. package/lib/types/client/definition.js +25 -0
  54. package/lib/types/client/icons-local.d.ts +19 -0
  55. package/lib/types/client/icons-local.js +3 -0
  56. package/lib/types/client/icons.d.ts +18 -0
  57. package/lib/types/client/icons.js +2 -0
  58. package/lib/types/client/index.d.ts +42 -0
  59. package/lib/types/client/index.js +139 -0
  60. package/lib/types/client/locales.d.ts +365 -0
  61. package/lib/types/client/locales.js +705 -0
  62. package/lib/types/client/preset-visibility.d.ts +99 -0
  63. package/lib/types/client/preset-visibility.js +108 -0
  64. package/lib/types/client/scroll-sync.d.ts +54 -0
  65. package/lib/types/client/scroll-sync.js +118 -0
  66. package/lib/types/client/timing.d.ts +29 -0
  67. package/lib/types/client/timing.js +117 -0
  68. package/lib/types/client/wire.d.ts +13 -0
  69. package/lib/types/client/wire.js +11 -0
  70. package/lib/types/index.d.ts +32 -0
  71. package/lib/types/index.js +25 -0
  72. package/lib/types/log-lane.d.ts +198 -0
  73. package/lib/types/log-lane.js +841 -0
  74. package/lib/types/messages.d.ts +96 -0
  75. package/lib/types/messages.js +254 -0
  76. package/lib/types/prefix-diff.d.ts +4 -0
  77. package/lib/types/prefix-diff.js +20 -0
  78. package/lib/types/remote.d.ts +45 -0
  79. package/lib/types/remote.js +99 -0
  80. package/lib/types/room.d.ts +66 -0
  81. package/lib/types/room.js +101 -0
  82. package/lib/types/segmenter.d.ts +100 -0
  83. package/lib/types/segmenter.js +184 -0
  84. package/lib/types/service.d.ts +145 -0
  85. package/lib/types/service.js +493 -0
  86. package/lib/types/store.d.ts +424 -0
  87. package/lib/types/store.js +1920 -0
  88. package/lib/types/tool-summary.d.ts +6 -0
  89. package/lib/types/tool-summary.js +7 -0
  90. package/lib/types/types.d.ts +703 -0
  91. package/lib/types/types.js +18 -0
  92. package/locale/en.json +6 -0
  93. package/locale/zh.json +6 -0
  94. package/package.json +133 -3
@@ -0,0 +1,198 @@
1
+ import type { RequestConfig } from './types.ts';
2
+ import { type StoredRequest } from './store.ts';
3
+ import { type ScopeFingerprint } from './segmenter.ts';
4
+ import { type CapturedMessage } from './messages.ts';
5
+ /** The structural minimum of one decoded session-log row (untrusted JSON). */
6
+ export interface SessionLogRow {
7
+ type: string;
8
+ seq?: number;
9
+ time?: number;
10
+ data?: unknown;
11
+ ignorable?: true;
12
+ surfaceOp?: 'append' | {
13
+ op: 'replace';
14
+ startSeq: number;
15
+ endSeq: number;
16
+ };
17
+ sourceEventSeqs?: number[];
18
+ }
19
+ /** What the lane asks of the host's persistence service (structural probe). */
20
+ export interface SessionLogHandle {
21
+ read(offset?: number, length?: number): Promise<{
22
+ events: SessionLogRow[];
23
+ }>;
24
+ close(): Promise<void>;
25
+ }
26
+ /** The `sessionPersistence` service face this lane uses. */
27
+ export interface SessionLogReader {
28
+ open(id: string, access: 'read'): Promise<SessionLogHandle>;
29
+ }
30
+ /** Structural check for the probed `sessionPersistence` service. */
31
+ export declare function isSessionLogReader(value: unknown): value is SessionLogReader;
32
+ /** A folded message plus its log position (fold order ≠ request membership). */
33
+ interface FoldedMessage {
34
+ seq: number;
35
+ message: CapturedMessage;
36
+ }
37
+ /** One delegation call correlated across tool/call → subagent/catalog → tool/result. */
38
+ export interface LogDelegation {
39
+ /** The host turn that ran the delegation, when the log scopes it. */
40
+ hostTurn?: number;
41
+ /** The delegating tool call; '' for a catalog-only child (an external agent no tool call started). */
42
+ callId: string;
43
+ name: string;
44
+ at: number;
45
+ /** The call arguments' description (the subagent_dsh convention). */
46
+ label?: string;
47
+ childId?: string;
48
+ catalogLabel?: string;
49
+ resultAt?: number;
50
+ isError?: boolean;
51
+ errorPreview?: string;
52
+ }
53
+ /** Incremental per-log fold state; survives across refreshes (child lane) or one shot (backfill). */
54
+ export interface SessionLogCursor {
55
+ /** Events consumed so far (the next read's offset). */
56
+ consumed: number;
57
+ /** The log begins at its header/event zero, so request ordinals are anchored. */
58
+ numberedFromStart: boolean;
59
+ /** Model-visible messages folded so far, in log order. */
60
+ messages: FoldedMessage[];
61
+ compactions: Map<string, {
62
+ startedAt: number;
63
+ hostTurn?: number;
64
+ request?: BuiltLogRequest;
65
+ }>;
66
+ /** The latest step/start time — the next request's dispatch proxy. */
67
+ stepStartAt: number | undefined;
68
+ /**
69
+ * The log mirrors an external agent (its descriptor names a provider that
70
+ * runs in its own process). A mirror that writes a step only once its call
71
+ * is over writes step/start and the answer together; such a request
72
+ * starts when the log's previous event happened (`stepPrevAt`).
73
+ */
74
+ external?: boolean;
75
+ /** The latest event time that marks progress (not a live-stream checkpoint). */
76
+ lastEventAt?: number;
77
+ /** The progress event before the latest step/start. */
78
+ stepPrevAt?: number;
79
+ /**
80
+ * An external agent's step that reported no usage: a mirror writes one
81
+ * model call as several steps (one per item or content block) with the
82
+ * call's usage on its last, so the step waits to join the steps after it
83
+ * as one request. Its blocks accumulate in `deferredBlocks`.
84
+ */
85
+ deferred?: {
86
+ request: BuiltLogRequest;
87
+ hostTurn: number | undefined;
88
+ blocks: CapturedMessage['content'];
89
+ };
90
+ /** The latest request/header config, when the log carries any. */
91
+ config: RequestConfig | undefined;
92
+ /** The latest request/header tool list, when the log carries any. */
93
+ tools: {
94
+ name: string;
95
+ description: string;
96
+ parameters: Record<string, unknown>;
97
+ }[] | undefined;
98
+ /** tool/call times by callId. */
99
+ callAt: Map<string, number>;
100
+ /** callId → tool name (tool-row labels). */
101
+ callNames: Map<string, string>;
102
+ /** callId → the built request whose response issued it (exec attribution). */
103
+ callOwners: Map<string, BuiltLogRequest>;
104
+ /** messageId → producing request's generation ms. */
105
+ messageDurations: Map<string, number>;
106
+ /** The previous request's diff baseline. */
107
+ previous: ScopeFingerprint | undefined;
108
+ /** Requests built so far (kept for late tool-exec closes). */
109
+ requests: BuiltLogRequest[];
110
+ /** The currently open host turn's number (turn/start … turn/end). */
111
+ turnHost: number | undefined;
112
+ /** Whether the current turn already contributed its query preview. */
113
+ turnQuerySeen: boolean;
114
+ /** Whether the current turn already named the non-human message that started it. */
115
+ turnTriggerSeen: boolean;
116
+ /** Delegation calls awaiting their catalog/result. */
117
+ pendingDelegations: Map<string, LogDelegation>;
118
+ /** Set once a read failed this cursor; the lane stops hammering a bad log. */
119
+ broken: string | undefined;
120
+ /**
121
+ * Whether a request of this host turn keeps its full segments. Every
122
+ * request carries its whole context, so materializing a long log at once
123
+ * grows with the square of its length; the backfill materializes only its
124
+ * window and records the rest as bodiless rows. Absent: materialize all.
125
+ */
126
+ materialize?: (hostTurn: number | undefined) => boolean;
127
+ /** The last request's messages when it was not materialized (the next full one diffs against them). */
128
+ previousMessages?: CapturedMessage[];
129
+ previousToolNames?: string[];
130
+ }
131
+ /** A request row built from the log, before the store assigns its sequence. */
132
+ export type BuiltLogRequest = Omit<StoredRequest, 'seq' | 'sessionId' | 'scopeId' | 'turnSeq'>;
133
+ /** Optional fold hooks beyond the request rows (the backfill driver uses them all). */
134
+ export interface FoldSink {
135
+ turnStart?(hostTurn: number, at: number | undefined, seq?: number): void;
136
+ turnEnd?(hostTurn: number, reason: {
137
+ kind: string;
138
+ error?: {
139
+ message?: string;
140
+ };
141
+ }, at: number | undefined): void;
142
+ /** The turn's first human user message (the turn list's query preview). */
143
+ queryText?(hostTurn: number | undefined, text: string, at: number | undefined): void;
144
+ /** The turn's first message from a non-human producer (the turn's trigger when no human spoke). */
145
+ triggerText?(hostTurn: number | undefined, source: string, text: string): void;
146
+ /** Each committed assistant message id; the last one of a turn is its closing message. */
147
+ closingMessage?(hostTurn: number | undefined, messageId: string): void;
148
+ /** One completed request, tagged with its host turn when the log scopes it. */
149
+ request?(hostTurn: number | undefined, request: BuiltLogRequest): void;
150
+ /** One delegation run, emitted when its tool/result lands (or at fold flush). */
151
+ delegation?(delegation: LogDelegation): void;
152
+ }
153
+ /**
154
+ * Subagent providers that run inside this host, so their requests pass
155
+ * through the live capture. Every other provider (claude-local, codex-local,
156
+ * kimi-cli, dsh-cli, …) is its own process, mirrored into its log after the
157
+ * fact.
158
+ */
159
+ export declare const IN_PROCESS_PROVIDERS: ReadonlySet<string>;
160
+ /** A fresh cursor for one log. */
161
+ export declare function openCursor(): SessionLogCursor;
162
+ /**
163
+ * Fold new log rows into the cursor. Returns the requests completed by THIS
164
+ * batch (the child-scope driver's whole output); the sink receives those plus
165
+ * the turn/delegation structure (the backfill driver). Tool exec spans can
166
+ * open and close in later batches, so pairing data lives on the cursor.
167
+ */
168
+ export declare function foldLogRows(cursor: SessionLogCursor, rows: readonly SessionLogRow[], sink?: FoldSink): BuiltLogRequest[];
169
+ /**
170
+ * One-shot reconstruction of a whole session log into turns (the main-session
171
+ * backfill). Requests group by their host turn number (step-scoped events
172
+ * carry it; a torn bracket falls back to the fold's open-turn state). Turns
173
+ * never closed by a turn/end (a crash) come out with `endReasonKind` unset.
174
+ */
175
+ export declare function reconstructSession(rows: readonly SessionLogRow[], materialize?: (hostTurn: number | undefined) => boolean): LogTurn[];
176
+ /** One reconstructed turn (the store turns this into a TurnRecord). */
177
+ export interface LogTurn {
178
+ hostTurn: number;
179
+ purpose?: string;
180
+ query: string;
181
+ /** First non-human message of the turn: who started it when no human did. */
182
+ trigger?: {
183
+ source: string;
184
+ text: string;
185
+ };
186
+ /** The `turn/start` row's seq (the chat's history-jump target). */
187
+ startSeq?: number;
188
+ startedAt: number;
189
+ endedAt?: number;
190
+ closingMessageId?: string;
191
+ /** The turn/end reason kind; absent when the log never closed the turn. */
192
+ endReasonKind?: string;
193
+ endError?: string;
194
+ requests: BuiltLogRequest[];
195
+ delegations: LogDelegation[];
196
+ }
197
+ export {};
198
+ //# sourceMappingURL=log-lane.d.ts.map