sidekick-shared 0.24.5 → 0.25.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 (76) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +159 -52
  3. package/dist/accountChangeSignal.d.ts +3 -0
  4. package/dist/accountChangeSignal.js +19 -0
  5. package/dist/accountChanges.d.ts +21 -0
  6. package/dist/accountChanges.js +151 -0
  7. package/dist/accountRegistry.d.ts +3 -1
  8. package/dist/accountRegistry.js +5 -0
  9. package/dist/browser.d.ts +8 -3
  10. package/dist/browser.js +15 -1
  11. package/dist/codexQuotaWatcher.d.ts +6 -0
  12. package/dist/codexQuotaWatcher.js +101 -47
  13. package/dist/index.d.ts +23 -13
  14. package/dist/index.js +34 -10
  15. package/dist/modelAliases.d.ts +13 -0
  16. package/dist/modelAliases.js +58 -0
  17. package/dist/modelCatalog.d.ts +32 -0
  18. package/dist/modelCatalog.js +145 -0
  19. package/dist/modelContext.d.ts +36 -3
  20. package/dist/modelContext.js +109 -34
  21. package/dist/modelInfo.d.ts +30 -1
  22. package/dist/modelInfo.js +116 -26
  23. package/dist/multiProviderQuotaService.d.ts +8 -0
  24. package/dist/multiProviderQuotaService.js +64 -3
  25. package/dist/node.d.ts +4 -4
  26. package/dist/node.js +4 -1
  27. package/dist/observedSessionCollector.d.ts +75 -4
  28. package/dist/observedSessionCollector.js +452 -42
  29. package/dist/parsers/codexHistory.d.ts +4 -2
  30. package/dist/parsers/codexHistory.js +9 -2
  31. package/dist/parsers/sessionActivityDetector.d.ts +6 -0
  32. package/dist/parsers/sessionActivityDetector.js +17 -0
  33. package/dist/providerIds.d.ts +11 -0
  34. package/dist/providerIds.js +9 -0
  35. package/dist/providerQuota.d.ts +3 -1
  36. package/dist/providerQuota.js +3 -0
  37. package/dist/providers/claudeCode.d.ts +10 -1
  38. package/dist/providers/claudeCode.js +204 -39
  39. package/dist/providers/codex.d.ts +18 -1
  40. package/dist/providers/codex.js +269 -40
  41. package/dist/providers/codexDatabase.d.ts +9 -0
  42. package/dist/providers/codexDatabase.js +107 -2
  43. package/dist/providers/diagnostics.d.ts +13 -0
  44. package/dist/providers/diagnostics.js +88 -0
  45. package/dist/providers/factory.d.ts +14 -0
  46. package/dist/providers/factory.js +57 -0
  47. package/dist/providers/openCode.d.ts +20 -1
  48. package/dist/providers/openCode.js +361 -11
  49. package/dist/providers/openCodeDatabase.d.ts +10 -0
  50. package/dist/providers/openCodeDatabase.js +69 -0
  51. package/dist/providers/types.d.ts +52 -2
  52. package/dist/providers/types.js +4 -0
  53. package/dist/quota.d.ts +4 -1
  54. package/dist/quota.js +3 -7
  55. package/dist/quotaHistory.d.ts +2 -1
  56. package/dist/quotaPoller.d.ts +13 -1
  57. package/dist/quotaPoller.js +65 -3
  58. package/dist/schemas/accountManager.d.ts +2 -2
  59. package/dist/schemas/accountManager.js +2 -4
  60. package/dist/schemas/accountStatus.d.ts +3 -0
  61. package/dist/schemas/accountStatus.js +1 -0
  62. package/dist/schemas/index.d.ts +1 -0
  63. package/dist/schemas/index.js +7 -2
  64. package/dist/schemas/observedSessionV1.d.ts +27 -26
  65. package/dist/schemas/observedSessionV1.js +6 -4
  66. package/dist/schemas/quota.d.ts +2 -2
  67. package/dist/schemas/quota.js +3 -6
  68. package/dist/schemas/quotaHistory.d.ts +2 -2
  69. package/dist/schemas/tokenEstimation.d.ts +1 -1
  70. package/dist/sessionMonitor.d.ts +15 -0
  71. package/dist/sessionMonitor.js +142 -0
  72. package/dist/sessionPreviews.d.ts +26 -1
  73. package/dist/sessionPreviews.js +319 -4
  74. package/dist/types/observedSessionV1.d.ts +6 -2
  75. package/dist/types/observedSessionV1.js +14 -8
  76. package/package.json +22 -1
@@ -8,8 +8,8 @@ export declare const sessionEvidenceRefV1Schema: z.ZodObject<{
8
8
  schemaVersion: z.ZodLiteral<1>;
9
9
  provider: z.ZodEnum<{
10
10
  "claude-code": "claude-code";
11
- codex: "codex";
12
11
  opencode: "opencode";
12
+ codex: "codex";
13
13
  }>;
14
14
  sessionId: z.ZodString;
15
15
  sourcePath: z.ZodOptional<z.ZodString>;
@@ -29,8 +29,8 @@ export declare const observedValueV1Schema: <T extends z.ZodType>(value: T) => z
29
29
  schemaVersion: z.ZodLiteral<1>;
30
30
  provider: z.ZodEnum<{
31
31
  "claude-code": "claude-code";
32
- codex: "codex";
33
32
  opencode: "opencode";
33
+ codex: "codex";
34
34
  }>;
35
35
  sessionId: z.ZodString;
36
36
  sourcePath: z.ZodOptional<z.ZodString>;
@@ -44,8 +44,8 @@ export declare const pendingUserRequestV1Schema: z.ZodObject<{
44
44
  id: z.ZodString;
45
45
  provider: z.ZodEnum<{
46
46
  "claude-code": "claude-code";
47
- codex: "codex";
48
47
  opencode: "opencode";
48
+ codex: "codex";
49
49
  }>;
50
50
  sessionId: z.ZodString;
51
51
  kind: z.ZodObject<{
@@ -64,8 +64,8 @@ export declare const pendingUserRequestV1Schema: z.ZodObject<{
64
64
  schemaVersion: z.ZodLiteral<1>;
65
65
  provider: z.ZodEnum<{
66
66
  "claude-code": "claude-code";
67
- codex: "codex";
68
67
  opencode: "opencode";
68
+ codex: "codex";
69
69
  }>;
70
70
  sessionId: z.ZodString;
71
71
  sourcePath: z.ZodOptional<z.ZodString>;
@@ -86,8 +86,8 @@ export declare const pendingUserRequestV1Schema: z.ZodObject<{
86
86
  schemaVersion: z.ZodLiteral<1>;
87
87
  provider: z.ZodEnum<{
88
88
  "claude-code": "claude-code";
89
- codex: "codex";
90
89
  opencode: "opencode";
90
+ codex: "codex";
91
91
  }>;
92
92
  sessionId: z.ZodString;
93
93
  sourcePath: z.ZodOptional<z.ZodString>;
@@ -108,8 +108,8 @@ export declare const pendingUserRequestV1Schema: z.ZodObject<{
108
108
  schemaVersion: z.ZodLiteral<1>;
109
109
  provider: z.ZodEnum<{
110
110
  "claude-code": "claude-code";
111
- codex: "codex";
112
111
  opencode: "opencode";
112
+ codex: "codex";
113
113
  }>;
114
114
  sessionId: z.ZodString;
115
115
  sourcePath: z.ZodOptional<z.ZodString>;
@@ -124,8 +124,8 @@ export declare const observedAgentSessionV1Schema: z.ZodObject<{
124
124
  identity: z.ZodObject<{
125
125
  provider: z.ZodEnum<{
126
126
  "claude-code": "claude-code";
127
- codex: "codex";
128
127
  opencode: "opencode";
128
+ codex: "codex";
129
129
  }>;
130
130
  sessionId: z.ZodString;
131
131
  sourcePath: z.ZodString;
@@ -142,8 +142,8 @@ export declare const observedAgentSessionV1Schema: z.ZodObject<{
142
142
  schemaVersion: z.ZodLiteral<1>;
143
143
  provider: z.ZodEnum<{
144
144
  "claude-code": "claude-code";
145
- codex: "codex";
146
145
  opencode: "opencode";
146
+ codex: "codex";
147
147
  }>;
148
148
  sessionId: z.ZodString;
149
149
  sourcePath: z.ZodOptional<z.ZodString>;
@@ -164,8 +164,8 @@ export declare const observedAgentSessionV1Schema: z.ZodObject<{
164
164
  schemaVersion: z.ZodLiteral<1>;
165
165
  provider: z.ZodEnum<{
166
166
  "claude-code": "claude-code";
167
- codex: "codex";
168
167
  opencode: "opencode";
168
+ codex: "codex";
169
169
  }>;
170
170
  sessionId: z.ZodString;
171
171
  sourcePath: z.ZodOptional<z.ZodString>;
@@ -178,8 +178,8 @@ export declare const observedAgentSessionV1Schema: z.ZodObject<{
178
178
  value: z.ZodEnum<{
179
179
  unknown: "unknown";
180
180
  active: "active";
181
- idle: "idle";
182
181
  ended: "ended";
182
+ idle: "idle";
183
183
  }>;
184
184
  provenance: z.ZodEnum<{
185
185
  reported: "reported";
@@ -191,8 +191,8 @@ export declare const observedAgentSessionV1Schema: z.ZodObject<{
191
191
  schemaVersion: z.ZodLiteral<1>;
192
192
  provider: z.ZodEnum<{
193
193
  "claude-code": "claude-code";
194
- codex: "codex";
195
194
  opencode: "opencode";
195
+ codex: "codex";
196
196
  }>;
197
197
  sessionId: z.ZodString;
198
198
  sourcePath: z.ZodOptional<z.ZodString>;
@@ -214,8 +214,8 @@ export declare const observedAgentSessionV1Schema: z.ZodObject<{
214
214
  schemaVersion: z.ZodLiteral<1>;
215
215
  provider: z.ZodEnum<{
216
216
  "claude-code": "claude-code";
217
- codex: "codex";
218
217
  opencode: "opencode";
218
+ codex: "codex";
219
219
  }>;
220
220
  sessionId: z.ZodString;
221
221
  sourcePath: z.ZodOptional<z.ZodString>;
@@ -236,8 +236,8 @@ export declare const observedAgentSessionV1Schema: z.ZodObject<{
236
236
  schemaVersion: z.ZodLiteral<1>;
237
237
  provider: z.ZodEnum<{
238
238
  "claude-code": "claude-code";
239
- codex: "codex";
240
239
  opencode: "opencode";
240
+ codex: "codex";
241
241
  }>;
242
242
  sessionId: z.ZodString;
243
243
  sourcePath: z.ZodOptional<z.ZodString>;
@@ -258,8 +258,8 @@ export declare const observedAgentSessionV1Schema: z.ZodObject<{
258
258
  schemaVersion: z.ZodLiteral<1>;
259
259
  provider: z.ZodEnum<{
260
260
  "claude-code": "claude-code";
261
- codex: "codex";
262
261
  opencode: "opencode";
262
+ codex: "codex";
263
263
  }>;
264
264
  sessionId: z.ZodString;
265
265
  sourcePath: z.ZodOptional<z.ZodString>;
@@ -280,8 +280,8 @@ export declare const observedAgentSessionV1Schema: z.ZodObject<{
280
280
  schemaVersion: z.ZodLiteral<1>;
281
281
  provider: z.ZodEnum<{
282
282
  "claude-code": "claude-code";
283
- codex: "codex";
284
283
  opencode: "opencode";
284
+ codex: "codex";
285
285
  }>;
286
286
  sessionId: z.ZodString;
287
287
  sourcePath: z.ZodOptional<z.ZodString>;
@@ -311,8 +311,8 @@ export declare const observedAgentSessionV1Schema: z.ZodObject<{
311
311
  schemaVersion: z.ZodLiteral<1>;
312
312
  provider: z.ZodEnum<{
313
313
  "claude-code": "claude-code";
314
- codex: "codex";
315
314
  opencode: "opencode";
315
+ codex: "codex";
316
316
  }>;
317
317
  sessionId: z.ZodString;
318
318
  sourcePath: z.ZodOptional<z.ZodString>;
@@ -333,8 +333,8 @@ export declare const observedAgentSessionV1Schema: z.ZodObject<{
333
333
  schemaVersion: z.ZodLiteral<1>;
334
334
  provider: z.ZodEnum<{
335
335
  "claude-code": "claude-code";
336
- codex: "codex";
337
336
  opencode: "opencode";
337
+ codex: "codex";
338
338
  }>;
339
339
  sessionId: z.ZodString;
340
340
  sourcePath: z.ZodOptional<z.ZodString>;
@@ -349,8 +349,8 @@ export declare const observedAgentSessionV1Schema: z.ZodObject<{
349
349
  id: z.ZodString;
350
350
  provider: z.ZodEnum<{
351
351
  "claude-code": "claude-code";
352
- codex: "codex";
353
352
  opencode: "opencode";
353
+ codex: "codex";
354
354
  }>;
355
355
  sessionId: z.ZodString;
356
356
  kind: z.ZodObject<{
@@ -369,8 +369,8 @@ export declare const observedAgentSessionV1Schema: z.ZodObject<{
369
369
  schemaVersion: z.ZodLiteral<1>;
370
370
  provider: z.ZodEnum<{
371
371
  "claude-code": "claude-code";
372
- codex: "codex";
373
372
  opencode: "opencode";
373
+ codex: "codex";
374
374
  }>;
375
375
  sessionId: z.ZodString;
376
376
  sourcePath: z.ZodOptional<z.ZodString>;
@@ -391,8 +391,8 @@ export declare const observedAgentSessionV1Schema: z.ZodObject<{
391
391
  schemaVersion: z.ZodLiteral<1>;
392
392
  provider: z.ZodEnum<{
393
393
  "claude-code": "claude-code";
394
- codex: "codex";
395
394
  opencode: "opencode";
395
+ codex: "codex";
396
396
  }>;
397
397
  sessionId: z.ZodString;
398
398
  sourcePath: z.ZodOptional<z.ZodString>;
@@ -413,8 +413,8 @@ export declare const observedAgentSessionV1Schema: z.ZodObject<{
413
413
  schemaVersion: z.ZodLiteral<1>;
414
414
  provider: z.ZodEnum<{
415
415
  "claude-code": "claude-code";
416
- codex: "codex";
417
416
  opencode: "opencode";
417
+ codex: "codex";
418
418
  }>;
419
419
  sessionId: z.ZodString;
420
420
  sourcePath: z.ZodOptional<z.ZodString>;
@@ -424,14 +424,15 @@ export declare const observedAgentSessionV1Schema: z.ZodObject<{
424
424
  }, z.core.$strip>>;
425
425
  }, z.core.$strip>;
426
426
  }, z.core.$strip>>;
427
+ contentObservedAt: z.ZodOptional<z.ZodString>;
427
428
  observedAt: z.ZodString;
428
429
  }, z.core.$strip>;
429
430
  export declare const providerCapabilitiesV1Schema: z.ZodObject<{
430
431
  schemaVersion: z.ZodLiteral<1>;
431
432
  provider: z.ZodEnum<{
432
433
  "claude-code": "claude-code";
433
- codex: "codex";
434
434
  opencode: "opencode";
435
+ codex: "codex";
435
436
  }>;
436
437
  resume: z.ZodObject<{
437
438
  value: z.ZodBoolean;
@@ -445,8 +446,8 @@ export declare const providerCapabilitiesV1Schema: z.ZodObject<{
445
446
  schemaVersion: z.ZodLiteral<1>;
446
447
  provider: z.ZodEnum<{
447
448
  "claude-code": "claude-code";
448
- codex: "codex";
449
449
  opencode: "opencode";
450
+ codex: "codex";
450
451
  }>;
451
452
  sessionId: z.ZodString;
452
453
  sourcePath: z.ZodOptional<z.ZodString>;
@@ -467,8 +468,8 @@ export declare const providerCapabilitiesV1Schema: z.ZodObject<{
467
468
  schemaVersion: z.ZodLiteral<1>;
468
469
  provider: z.ZodEnum<{
469
470
  "claude-code": "claude-code";
470
- codex: "codex";
471
471
  opencode: "opencode";
472
+ codex: "codex";
472
473
  }>;
473
474
  sessionId: z.ZodString;
474
475
  sourcePath: z.ZodOptional<z.ZodString>;
@@ -494,8 +495,8 @@ export declare const providerCapabilitiesV1Schema: z.ZodObject<{
494
495
  schemaVersion: z.ZodLiteral<1>;
495
496
  provider: z.ZodEnum<{
496
497
  "claude-code": "claude-code";
497
- codex: "codex";
498
498
  opencode: "opencode";
499
+ codex: "codex";
499
500
  }>;
500
501
  sessionId: z.ZodString;
501
502
  sourcePath: z.ZodOptional<z.ZodString>;
@@ -516,8 +517,8 @@ export declare const providerCapabilitiesV1Schema: z.ZodObject<{
516
517
  schemaVersion: z.ZodLiteral<1>;
517
518
  provider: z.ZodEnum<{
518
519
  "claude-code": "claude-code";
519
- codex: "codex";
520
520
  opencode: "opencode";
521
+ codex: "codex";
521
522
  }>;
522
523
  sessionId: z.ZodString;
523
524
  sourcePath: z.ZodOptional<z.ZodString>;
@@ -2,10 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.providerSessionAdapterV1Schema = exports.providerCapabilitiesV1Schema = exports.observedAgentSessionV1Schema = exports.pendingUserRequestV1Schema = exports.observedValueV1Schema = exports.sessionEvidenceRefV1Schema = exports.observationProvenanceV1Schema = void 0;
4
4
  const zod_1 = require("zod");
5
+ const providerIds_1 = require("../providerIds");
5
6
  exports.observationProvenanceV1Schema = zod_1.z.enum(['reported', 'estimated', 'inferred']);
6
7
  exports.sessionEvidenceRefV1Schema = zod_1.z.object({
7
8
  schemaVersion: zod_1.z.literal(1),
8
- provider: zod_1.z.enum(['claude-code', 'opencode', 'codex']),
9
+ provider: zod_1.z.enum(providerIds_1.SESSION_PROVIDER_IDS),
9
10
  sessionId: zod_1.z.string().min(1),
10
11
  sourcePath: zod_1.z.string().optional(),
11
12
  eventIndex: zod_1.z.number().int().nonnegative().optional(),
@@ -22,7 +23,7 @@ exports.observedValueV1Schema = observedValueV1Schema;
22
23
  exports.pendingUserRequestV1Schema = zod_1.z.object({
23
24
  schemaVersion: zod_1.z.literal(1),
24
25
  id: zod_1.z.string().min(1),
25
- provider: zod_1.z.enum(['claude-code', 'opencode', 'codex']),
26
+ provider: zod_1.z.enum(providerIds_1.SESSION_PROVIDER_IDS),
26
27
  sessionId: zod_1.z.string().min(1),
27
28
  kind: (0, exports.observedValueV1Schema)(zod_1.z.enum(['prompt_response', 'tool_approval', 'question'])),
28
29
  requestedAt: (0, exports.observedValueV1Schema)(zod_1.z.string()),
@@ -31,7 +32,7 @@ exports.pendingUserRequestV1Schema = zod_1.z.object({
31
32
  exports.observedAgentSessionV1Schema = zod_1.z.object({
32
33
  schemaVersion: zod_1.z.literal(1),
33
34
  identity: zod_1.z.object({
34
- provider: zod_1.z.enum(['claude-code', 'opencode', 'codex']),
35
+ provider: zod_1.z.enum(providerIds_1.SESSION_PROVIDER_IDS),
35
36
  sessionId: zod_1.z.string().min(1),
36
37
  sourcePath: zod_1.z.string(),
37
38
  }),
@@ -56,11 +57,12 @@ exports.observedAgentSessionV1Schema = zod_1.z.object({
56
57
  costUsd: (0, exports.observedValueV1Schema)(zod_1.z.number().nonnegative().nullable()),
57
58
  }),
58
59
  pendingUserRequest: exports.pendingUserRequestV1Schema.nullable(),
60
+ contentObservedAt: zod_1.z.string().optional(),
59
61
  observedAt: zod_1.z.string(),
60
62
  });
61
63
  exports.providerCapabilitiesV1Schema = zod_1.z.object({
62
64
  schemaVersion: zod_1.z.literal(1),
63
- provider: zod_1.z.enum(['claude-code', 'opencode', 'codex']),
65
+ provider: zod_1.z.enum(providerIds_1.SESSION_PROVIDER_IDS),
64
66
  resume: (0, exports.observedValueV1Schema)(zod_1.z.boolean()),
65
67
  forkLineage: (0, exports.observedValueV1Schema)(zod_1.z.boolean()),
66
68
  quotaSource: (0, exports.observedValueV1Schema)(zod_1.z.enum(['api', 'session', 'mixed', 'none'])),
@@ -146,8 +146,8 @@ export declare const quotaFailureDescriptorSchema: z.ZodObject<{
146
146
  }, z.core.$strip>;
147
147
  export declare const runtimeQuotaProviderSchema: z.ZodEnum<{
148
148
  codex: "codex";
149
- claude: "claude";
150
149
  zai: "zai";
150
+ claude: "claude";
151
151
  }>;
152
152
  export declare const providerQuotaStateSchema: z.ZodObject<{
153
153
  fiveHour: z.ZodObject<{
@@ -243,8 +243,8 @@ export declare const providerQuotaStateSchema: z.ZodObject<{
243
243
  }, z.core.$strip>>>;
244
244
  runtimeProvider: z.ZodEnum<{
245
245
  codex: "codex";
246
- claude: "claude";
247
246
  zai: "zai";
247
+ claude: "claude";
248
248
  }>;
249
249
  }, z.core.$strip>;
250
250
  export declare const claudeProviderQuotaStateSchema: z.ZodObject<{
@@ -12,6 +12,7 @@
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.providerQuotaMapSchema = exports.zaiProviderQuotaStateSchema = exports.codexProviderQuotaStateSchema = exports.claudeProviderQuotaStateSchema = exports.providerQuotaStateSchema = exports.runtimeQuotaProviderSchema = exports.quotaFailureDescriptorSchema = exports.peakHoursStateSchema = exports.quotaStateSchema = exports.codexResetCreditsSnapshotSchema = exports.codexResetCreditSchema = exports.quotaSourceSchema = exports.quotaProviderIdSchema = exports.quotaFailureKindSchema = exports.quotaWindowSchema = void 0;
14
14
  const zod_1 = require("zod");
15
+ const providerIds_1 = require("../providerIds");
15
16
  // ── QuotaWindow ──
16
17
  exports.quotaWindowSchema = zod_1.z.object({
17
18
  utilization: zod_1.z.number(),
@@ -25,7 +26,7 @@ exports.quotaFailureKindSchema = zod_1.z.enum([
25
26
  'server',
26
27
  'unknown',
27
28
  ]);
28
- exports.quotaProviderIdSchema = zod_1.z.enum(['claude-code', 'codex', 'zai']);
29
+ exports.quotaProviderIdSchema = zod_1.z.enum(providerIds_1.QUOTA_PROVIDER_IDS);
29
30
  exports.quotaSourceSchema = zod_1.z.enum(['api', 'session', 'cache']);
30
31
  exports.codexResetCreditSchema = zod_1.z.object({
31
32
  title: zod_1.z.string().optional(),
@@ -88,11 +89,7 @@ exports.quotaFailureDescriptorSchema = zod_1.z.object({
88
89
  isRetryable: zod_1.z.boolean(),
89
90
  });
90
91
  // ── ProviderQuotaState / ProviderQuotaMap ──
91
- exports.runtimeQuotaProviderSchema = zod_1.z.enum([
92
- 'claude',
93
- 'codex',
94
- 'zai',
95
- ]);
92
+ exports.runtimeQuotaProviderSchema = zod_1.z.enum(providerIds_1.RUNTIME_QUOTA_PROVIDER_IDS);
96
93
  /** Fields ProviderQuotaState adds on top of QuotaState, minus the provider tag. */
97
94
  const providerQuotaExtensionShape = {
98
95
  accountLabel: zod_1.z.string().optional(),
@@ -11,15 +11,15 @@
11
11
  import { z } from 'zod';
12
12
  export declare const quotaHistoryRuntimeProviderSchema: z.ZodEnum<{
13
13
  codex: "codex";
14
- claude: "claude";
15
14
  zai: "zai";
15
+ claude: "claude";
16
16
  }>;
17
17
  export declare const quotaHistorySampleSchema: z.ZodObject<{
18
18
  timestamp: z.ZodString;
19
19
  runtimeProvider: z.ZodEnum<{
20
20
  codex: "codex";
21
- claude: "claude";
22
21
  zai: "zai";
22
+ claude: "claude";
23
23
  }>;
24
24
  providerId: z.ZodString;
25
25
  workspaceId: z.ZodString;
@@ -6,9 +6,9 @@ export declare const tokenEstimateSchema: z.ZodObject<{
6
6
  "sidekick-fallback-v1": "sidekick-fallback-v1";
7
7
  }>;
8
8
  confidence: z.ZodEnum<{
9
+ exact: "exact";
9
10
  low: "low";
10
11
  medium: "medium";
11
- exact: "exact";
12
12
  }>;
13
13
  provenance: z.ZodString;
14
14
  }, z.core.$strip>;
@@ -1,9 +1,15 @@
1
1
  import type { AggregatedMetrics, EventAggregatorOptions } from './aggregation/types';
2
2
  import type { SessionProviderBase } from './providers/types';
3
3
  import type { SessionEvent } from './types/sessionEvent';
4
+ import type { ObservedSessionChangeBatch } from './observedSessionCollector';
4
5
  export interface SessionMonitorOptions extends EventAggregatorOptions {
5
6
  replayOnAttach?: boolean;
6
7
  }
8
+ export interface SessionMonitorSubscribeOptions {
9
+ debounceMs?: number;
10
+ pollIntervalMs?: number;
11
+ onChange?: (batch: ObservedSessionChangeBatch) => void;
12
+ }
7
13
  /**
8
14
  * UI-independent session monitor for library consumers. It owns one provider
9
15
  * reader and the canonical aggregator; hosts decide how often to call `poll()`.
@@ -14,6 +20,7 @@ export declare class SessionMonitor {
14
20
  private reader;
15
21
  private sessionPath;
16
22
  private readonly listeners;
23
+ private readonly subscriptions;
17
24
  private readonly replayOnAttach;
18
25
  constructor(provider: SessionProviderBase, options?: SessionMonitorOptions);
19
26
  attach(sessionPath: string, replay?: boolean): AggregatedMetrics;
@@ -21,6 +28,14 @@ export declare class SessionMonitor {
21
28
  poll(): SessionEvent[];
22
29
  process(event: SessionEvent): void;
23
30
  onEvent(listener: (event: SessionEvent) => void): () => void;
31
+ /**
32
+ * Watches the attached session with debouncing and catch-up polling. Matching
33
+ * fingerprint changes automatically call poll(); parsed events still flow
34
+ * through onEvent.
35
+ */
36
+ subscribe(options?: SessionMonitorSubscribeOptions): {
37
+ dispose(): void;
38
+ };
24
39
  getMetrics(): AggregatedMetrics;
25
40
  getSessionPath(): string | null;
26
41
  reset(): void;
@@ -1,7 +1,42 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  exports.SessionMonitor = void 0;
37
+ const fs = __importStar(require("node:fs"));
4
38
  const EventAggregator_1 = require("./aggregation/EventAggregator");
39
+ const observedSessionCollector_1 = require("./observedSessionCollector");
5
40
  /**
6
41
  * UI-independent session monitor for library consumers. It owns one provider
7
42
  * reader and the canonical aggregator; hosts decide how often to call `poll()`.
@@ -12,6 +47,7 @@ class SessionMonitor {
12
47
  reader = null;
13
48
  sessionPath = null;
14
49
  listeners = new Set();
50
+ subscriptions = new Set();
15
51
  replayOnAttach;
16
52
  constructor(provider, options = {}) {
17
53
  this.provider = provider;
@@ -48,6 +84,110 @@ class SessionMonitor {
48
84
  this.listeners.add(listener);
49
85
  return () => this.listeners.delete(listener);
50
86
  }
87
+ /**
88
+ * Watches the attached session with debouncing and catch-up polling. Matching
89
+ * fingerprint changes automatically call poll(); parsed events still flow
90
+ * through onEvent.
91
+ */
92
+ subscribe(options = {}) {
93
+ const source = {
94
+ providerId: this.provider.id,
95
+ discover: async () => {
96
+ if (!this.sessionPath)
97
+ return [];
98
+ let parts = (0, observedSessionCollector_1.fileFingerprintParts)(this.sessionPath);
99
+ if (!parts) {
100
+ try {
101
+ const metadata = this.provider.getSessionMetadataAsync
102
+ ? await this.provider.getSessionMetadataAsync(this.sessionPath)
103
+ : this.provider.getSessionMetadata?.(this.sessionPath);
104
+ parts = metadata ? { sizeBytes: 0, mtimeMs: metadata.mtime.getTime() } : null;
105
+ }
106
+ catch {
107
+ parts = null;
108
+ }
109
+ }
110
+ if (!parts)
111
+ return [];
112
+ return [
113
+ {
114
+ sessionId: this.provider.getSessionId(this.sessionPath),
115
+ sourceKey: this.sessionPath,
116
+ fingerprintHint: `${parts.sizeBytes}:${parts.mtimeMs}`,
117
+ fingerprintParts: parts,
118
+ },
119
+ ];
120
+ },
121
+ read: () => null,
122
+ subscribe: (listener, sourceOptions) => {
123
+ const watchers = new Set();
124
+ let pollTimer = null;
125
+ let roots;
126
+ try {
127
+ roots = this.provider.getWatchRoots?.() ?? [this.provider.getProjectsBaseDir()];
128
+ }
129
+ catch {
130
+ roots = [];
131
+ }
132
+ for (const root of new Set(roots)) {
133
+ try {
134
+ const watcher = fs.watch(root, { persistent: false, recursive: true }, listener);
135
+ watchers.add(watcher);
136
+ watcher.on('error', () => {
137
+ watchers.delete(watcher);
138
+ try {
139
+ watcher.close();
140
+ }
141
+ catch {
142
+ // Collector catch-up polling remains active.
143
+ }
144
+ });
145
+ }
146
+ catch {
147
+ // Collector catch-up polling remains active.
148
+ }
149
+ }
150
+ const pollIntervalMs = sourceOptions?.pollIntervalMs ?? 0;
151
+ if (pollIntervalMs > 0) {
152
+ pollTimer = setInterval(listener, pollIntervalMs);
153
+ pollTimer.unref?.();
154
+ }
155
+ return {
156
+ dispose: () => {
157
+ for (const watcher of watchers)
158
+ watcher.close();
159
+ watchers.clear();
160
+ if (pollTimer)
161
+ clearInterval(pollTimer);
162
+ },
163
+ };
164
+ },
165
+ };
166
+ const collector = new observedSessionCollector_1.ObservedSessionCollector({ sources: [source] });
167
+ const changeSubscription = collector.subscribe((batch) => {
168
+ if (batch.changes.some((change) => change.reference.sourceKey === this.sessionPath)) {
169
+ this.poll();
170
+ }
171
+ try {
172
+ options.onChange?.(batch);
173
+ }
174
+ catch {
175
+ // Change callbacks are observational.
176
+ }
177
+ }, {
178
+ debounceMs: options.debounceMs,
179
+ pollIntervalMs: options.pollIntervalMs,
180
+ });
181
+ const disposable = {
182
+ dispose: () => {
183
+ changeSubscription.dispose();
184
+ collector.dispose();
185
+ this.subscriptions.delete(disposable);
186
+ },
187
+ };
188
+ this.subscriptions.add(disposable);
189
+ return disposable;
190
+ }
51
191
  getMetrics() {
52
192
  return this.aggregator.getMetrics();
53
193
  }
@@ -59,6 +199,8 @@ class SessionMonitor {
59
199
  this.aggregator.reset();
60
200
  }
61
201
  dispose() {
202
+ for (const subscription of [...this.subscriptions])
203
+ subscription.dispose();
62
204
  this.listeners.clear();
63
205
  this.reader = null;
64
206
  this.provider.dispose();
@@ -17,7 +17,7 @@
17
17
  *
18
18
  * @module sessionPreviews
19
19
  */
20
- import type { ProviderId, SessionProviderBase } from './providers/types';
20
+ import type { ProviderId, SessionProviderBase, SessionProviderDiagnostic } from './providers/types';
21
21
  export interface SessionPreview {
22
22
  provider: ProviderId;
23
23
  sessionId: string;
@@ -47,14 +47,39 @@ export interface ListSessionPreviewsOptions extends ReadSessionPreviewOptions {
47
47
  /** Skip files whose mtime is not strictly newer than this — cheap incremental refresh. */
48
48
  since?: Date | string;
49
49
  }
50
+ export interface AsyncSessionPreviewOptions {
51
+ /** Maximum concurrent stat/read units (default 4, hard-capped at 16). */
52
+ concurrency?: number;
53
+ /** Cooperative scheduler hook; defaults to setImmediate. */
54
+ yieldBetweenReads?: () => Promise<void> | void;
55
+ }
56
+ export interface ReadSessionPreviewAsyncOptions extends ReadSessionPreviewOptions, AsyncSessionPreviewOptions {
57
+ }
58
+ export interface ListSessionPreviewsAsyncOptions extends ListSessionPreviewsOptions, AsyncSessionPreviewOptions {
59
+ }
60
+ export interface SessionPreviewReadResult {
61
+ preview: SessionPreview | null;
62
+ diagnostics: SessionProviderDiagnostic[];
63
+ }
64
+ export interface SessionPreviewListResult {
65
+ previews: SessionPreview[];
66
+ diagnostics: SessionProviderDiagnostic[];
67
+ }
50
68
  /**
51
69
  * Reads a bounded preview of one session file. Returns `null` when the file is
52
70
  * missing or unreadable; malformed content degrades to `null` fields instead
53
71
  * of throwing.
54
72
  */
55
73
  export declare function readSessionPreview(provider: SessionProviderBase, sessionPath: string, options?: ReadSessionPreviewOptions): SessionPreview | null;
74
+ /** Event-loop-safe counterpart to readSessionPreview with per-call degradation status. */
75
+ export declare function readSessionPreviewAsync(provider: SessionProviderBase, sessionPath: string, options?: ReadSessionPreviewAsyncOptions): Promise<SessionPreviewReadResult>;
56
76
  /**
57
77
  * Lists previews across providers, newest first. Enumeration is stat-only;
58
78
  * content is read only for the post-`limit` survivors.
59
79
  */
60
80
  export declare function listSessionPreviews(providers: SessionProviderBase[], options?: ListSessionPreviewsOptions): SessionPreview[];
81
+ /**
82
+ * Lists previews without blocking the caller loop on corpus-wide synchronous
83
+ * work. SQLite-backed providers perform at most one subprocess per call.
84
+ */
85
+ export declare function listSessionPreviewsAsync(providers: SessionProviderBase[], options?: ListSessionPreviewsAsyncOptions): Promise<SessionPreviewListResult>;