@basou/core 0.8.0 → 0.9.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.
package/dist/index.d.ts CHANGED
@@ -149,6 +149,10 @@ declare const SessionInnerImportSchema: z.ZodObject<{
149
149
  active_time_method: z.ZodOptional<z.ZodString>;
150
150
  machine_active_time_ms: z.ZodOptional<z.ZodNumber>;
151
151
  }, z.core.$strip>>;
152
+ integrity: z.ZodOptional<z.ZodObject<{
153
+ head_hash: z.ZodString;
154
+ event_count: z.ZodNumber;
155
+ }, z.core.$strict>>;
152
156
  }, z.core.$strict>;
153
157
  /**
154
158
  * Schema for the round-trip JSON payload accepted by `basou session import
@@ -210,6 +214,10 @@ declare const SessionImportPayloadSchema: z.ZodObject<{
210
214
  active_time_method: z.ZodOptional<z.ZodString>;
211
215
  machine_active_time_ms: z.ZodOptional<z.ZodNumber>;
212
216
  }, z.core.$strip>>;
217
+ integrity: z.ZodOptional<z.ZodObject<{
218
+ head_hash: z.ZodString;
219
+ event_count: z.ZodNumber;
220
+ }, z.core.$strict>>;
213
221
  }, z.core.$strict>;
214
222
  events: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
215
223
  schema_version: z.ZodLiteral<"0.1.0">;
@@ -217,6 +225,7 @@ declare const SessionImportPayloadSchema: z.ZodObject<{
217
225
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
218
226
  occurred_at: z.ZodString;
219
227
  source: z.ZodString;
228
+ prev_hash: z.ZodOptional<z.ZodString>;
220
229
  type: z.ZodLiteral<"session_started">;
221
230
  }, z.core.$strip>, z.ZodObject<{
222
231
  schema_version: z.ZodLiteral<"0.1.0">;
@@ -224,6 +233,7 @@ declare const SessionImportPayloadSchema: z.ZodObject<{
224
233
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
225
234
  occurred_at: z.ZodString;
226
235
  source: z.ZodString;
236
+ prev_hash: z.ZodOptional<z.ZodString>;
227
237
  type: z.ZodLiteral<"session_ended">;
228
238
  exit_code: z.ZodOptional<z.ZodNumber>;
229
239
  }, z.core.$strip>, z.ZodObject<{
@@ -232,6 +242,7 @@ declare const SessionImportPayloadSchema: z.ZodObject<{
232
242
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
233
243
  occurred_at: z.ZodString;
234
244
  source: z.ZodString;
245
+ prev_hash: z.ZodOptional<z.ZodString>;
235
246
  type: z.ZodLiteral<"session_status_changed">;
236
247
  from: z.ZodString;
237
248
  to: z.ZodString;
@@ -241,6 +252,7 @@ declare const SessionImportPayloadSchema: z.ZodObject<{
241
252
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
242
253
  occurred_at: z.ZodString;
243
254
  source: z.ZodString;
255
+ prev_hash: z.ZodOptional<z.ZodString>;
244
256
  type: z.ZodLiteral<"approval_requested">;
245
257
  approval_id: z.ZodString & z.ZodType<`appr_${string}`, string, z.core.$ZodTypeInternals<`appr_${string}`, string>>;
246
258
  expires_at: z.ZodDefault<z.ZodNullable<z.ZodString>>;
@@ -261,6 +273,7 @@ declare const SessionImportPayloadSchema: z.ZodObject<{
261
273
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
262
274
  occurred_at: z.ZodString;
263
275
  source: z.ZodString;
276
+ prev_hash: z.ZodOptional<z.ZodString>;
264
277
  type: z.ZodLiteral<"approval_approved">;
265
278
  approval_id: z.ZodString & z.ZodType<`appr_${string}`, string, z.core.$ZodTypeInternals<`appr_${string}`, string>>;
266
279
  resolver: z.ZodOptional<z.ZodString>;
@@ -271,6 +284,7 @@ declare const SessionImportPayloadSchema: z.ZodObject<{
271
284
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
272
285
  occurred_at: z.ZodString;
273
286
  source: z.ZodString;
287
+ prev_hash: z.ZodOptional<z.ZodString>;
274
288
  type: z.ZodLiteral<"approval_rejected">;
275
289
  approval_id: z.ZodString & z.ZodType<`appr_${string}`, string, z.core.$ZodTypeInternals<`appr_${string}`, string>>;
276
290
  resolver: z.ZodOptional<z.ZodString>;
@@ -281,6 +295,7 @@ declare const SessionImportPayloadSchema: z.ZodObject<{
281
295
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
282
296
  occurred_at: z.ZodString;
283
297
  source: z.ZodString;
298
+ prev_hash: z.ZodOptional<z.ZodString>;
284
299
  type: z.ZodLiteral<"approval_expired">;
285
300
  approval_id: z.ZodString & z.ZodType<`appr_${string}`, string, z.core.$ZodTypeInternals<`appr_${string}`, string>>;
286
301
  }, z.core.$strip>, z.ZodObject<{
@@ -289,6 +304,7 @@ declare const SessionImportPayloadSchema: z.ZodObject<{
289
304
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
290
305
  occurred_at: z.ZodString;
291
306
  source: z.ZodString;
307
+ prev_hash: z.ZodOptional<z.ZodString>;
292
308
  type: z.ZodLiteral<"command_executed">;
293
309
  command: z.ZodString;
294
310
  args: z.ZodArray<z.ZodString>;
@@ -303,6 +319,7 @@ declare const SessionImportPayloadSchema: z.ZodObject<{
303
319
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
304
320
  occurred_at: z.ZodString;
305
321
  source: z.ZodString;
322
+ prev_hash: z.ZodOptional<z.ZodString>;
306
323
  type: z.ZodLiteral<"git_snapshot">;
307
324
  head: z.ZodString;
308
325
  branch: z.ZodString;
@@ -318,6 +335,7 @@ declare const SessionImportPayloadSchema: z.ZodObject<{
318
335
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
319
336
  occurred_at: z.ZodString;
320
337
  source: z.ZodString;
338
+ prev_hash: z.ZodOptional<z.ZodString>;
321
339
  type: z.ZodLiteral<"file_changed">;
322
340
  path: z.ZodString;
323
341
  change_type: z.ZodEnum<{
@@ -333,6 +351,7 @@ declare const SessionImportPayloadSchema: z.ZodObject<{
333
351
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
334
352
  occurred_at: z.ZodString;
335
353
  source: z.ZodString;
354
+ prev_hash: z.ZodOptional<z.ZodString>;
336
355
  type: z.ZodLiteral<"decision_recorded">;
337
356
  decision_id: z.ZodString & z.ZodType<`decision_${string}`, string, z.core.$ZodTypeInternals<`decision_${string}`, string>>;
338
357
  title: z.ZodString;
@@ -347,6 +366,7 @@ declare const SessionImportPayloadSchema: z.ZodObject<{
347
366
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
348
367
  occurred_at: z.ZodString;
349
368
  source: z.ZodString;
369
+ prev_hash: z.ZodOptional<z.ZodString>;
350
370
  type: z.ZodLiteral<"task_created">;
351
371
  task_id: z.ZodString & z.ZodType<`task_${string}`, string, z.core.$ZodTypeInternals<`task_${string}`, string>>;
352
372
  title: z.ZodString;
@@ -356,6 +376,7 @@ declare const SessionImportPayloadSchema: z.ZodObject<{
356
376
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
357
377
  occurred_at: z.ZodString;
358
378
  source: z.ZodString;
379
+ prev_hash: z.ZodOptional<z.ZodString>;
359
380
  type: z.ZodLiteral<"task_status_changed">;
360
381
  task_id: z.ZodString & z.ZodType<`task_${string}`, string, z.core.$ZodTypeInternals<`task_${string}`, string>>;
361
382
  from: z.ZodString;
@@ -366,6 +387,7 @@ declare const SessionImportPayloadSchema: z.ZodObject<{
366
387
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
367
388
  occurred_at: z.ZodString;
368
389
  source: z.ZodString;
390
+ prev_hash: z.ZodOptional<z.ZodString>;
369
391
  type: z.ZodLiteral<"task_reconciled">;
370
392
  task_id: z.ZodString & z.ZodType<`task_${string}`, string, z.core.$ZodTypeInternals<`task_${string}`, string>>;
371
393
  removed_created_in_session: z.ZodDefault<z.ZodNullable<z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>>>;
@@ -377,6 +399,7 @@ declare const SessionImportPayloadSchema: z.ZodObject<{
377
399
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
378
400
  occurred_at: z.ZodString;
379
401
  source: z.ZodString;
402
+ prev_hash: z.ZodOptional<z.ZodString>;
380
403
  type: z.ZodLiteral<"task_linkage_refreshed">;
381
404
  task_id: z.ZodString & z.ZodType<`task_${string}`, string, z.core.$ZodTypeInternals<`task_${string}`, string>>;
382
405
  added_linked_sessions: z.ZodDefault<z.ZodArray<z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>>>;
@@ -388,6 +411,7 @@ declare const SessionImportPayloadSchema: z.ZodObject<{
388
411
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
389
412
  occurred_at: z.ZodString;
390
413
  source: z.ZodString;
414
+ prev_hash: z.ZodOptional<z.ZodString>;
391
415
  type: z.ZodLiteral<"task_deleted">;
392
416
  task_id: z.ZodString & z.ZodType<`task_${string}`, string, z.core.$ZodTypeInternals<`task_${string}`, string>>;
393
417
  title: z.ZodString;
@@ -397,6 +421,7 @@ declare const SessionImportPayloadSchema: z.ZodObject<{
397
421
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
398
422
  occurred_at: z.ZodString;
399
423
  source: z.ZodString;
424
+ prev_hash: z.ZodOptional<z.ZodString>;
400
425
  type: z.ZodLiteral<"task_archived">;
401
426
  task_id: z.ZodString & z.ZodType<`task_${string}`, string, z.core.$ZodTypeInternals<`task_${string}`, string>>;
402
427
  title: z.ZodString;
@@ -406,6 +431,7 @@ declare const SessionImportPayloadSchema: z.ZodObject<{
406
431
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
407
432
  occurred_at: z.ZodString;
408
433
  source: z.ZodString;
434
+ prev_hash: z.ZodOptional<z.ZodString>;
409
435
  type: z.ZodLiteral<"note_added">;
410
436
  body: z.ZodString;
411
437
  }, z.core.$strip>, z.ZodObject<{
@@ -414,6 +440,7 @@ declare const SessionImportPayloadSchema: z.ZodObject<{
414
440
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
415
441
  occurred_at: z.ZodString;
416
442
  source: z.ZodString;
443
+ prev_hash: z.ZodOptional<z.ZodString>;
417
444
  type: z.ZodLiteral<"adapter_output">;
418
445
  stream: z.ZodEnum<{
419
446
  stdout: "stdout";
@@ -728,6 +755,7 @@ declare const SessionStartedEventSchema: z.ZodObject<{
728
755
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
729
756
  occurred_at: z.ZodString;
730
757
  source: z.ZodString;
758
+ prev_hash: z.ZodOptional<z.ZodString>;
731
759
  type: z.ZodLiteral<"session_started">;
732
760
  }, z.core.$strip>;
733
761
  declare const SessionEndedEventSchema: z.ZodObject<{
@@ -736,6 +764,7 @@ declare const SessionEndedEventSchema: z.ZodObject<{
736
764
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
737
765
  occurred_at: z.ZodString;
738
766
  source: z.ZodString;
767
+ prev_hash: z.ZodOptional<z.ZodString>;
739
768
  type: z.ZodLiteral<"session_ended">;
740
769
  exit_code: z.ZodOptional<z.ZodNumber>;
741
770
  }, z.core.$strip>;
@@ -745,6 +774,7 @@ declare const SessionStatusChangedEventSchema: z.ZodObject<{
745
774
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
746
775
  occurred_at: z.ZodString;
747
776
  source: z.ZodString;
777
+ prev_hash: z.ZodOptional<z.ZodString>;
748
778
  type: z.ZodLiteral<"session_status_changed">;
749
779
  from: z.ZodString;
750
780
  to: z.ZodString;
@@ -755,6 +785,7 @@ declare const ApprovalRequestedEventSchema: z.ZodObject<{
755
785
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
756
786
  occurred_at: z.ZodString;
757
787
  source: z.ZodString;
788
+ prev_hash: z.ZodOptional<z.ZodString>;
758
789
  type: z.ZodLiteral<"approval_requested">;
759
790
  approval_id: z.ZodString & z.ZodType<`appr_${string}`, string, z.core.$ZodTypeInternals<`appr_${string}`, string>>;
760
791
  expires_at: z.ZodDefault<z.ZodNullable<z.ZodString>>;
@@ -776,6 +807,7 @@ declare const ApprovalApprovedEventSchema: z.ZodObject<{
776
807
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
777
808
  occurred_at: z.ZodString;
778
809
  source: z.ZodString;
810
+ prev_hash: z.ZodOptional<z.ZodString>;
779
811
  type: z.ZodLiteral<"approval_approved">;
780
812
  approval_id: z.ZodString & z.ZodType<`appr_${string}`, string, z.core.$ZodTypeInternals<`appr_${string}`, string>>;
781
813
  resolver: z.ZodOptional<z.ZodString>;
@@ -787,6 +819,7 @@ declare const ApprovalRejectedEventSchema: z.ZodObject<{
787
819
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
788
820
  occurred_at: z.ZodString;
789
821
  source: z.ZodString;
822
+ prev_hash: z.ZodOptional<z.ZodString>;
790
823
  type: z.ZodLiteral<"approval_rejected">;
791
824
  approval_id: z.ZodString & z.ZodType<`appr_${string}`, string, z.core.$ZodTypeInternals<`appr_${string}`, string>>;
792
825
  resolver: z.ZodOptional<z.ZodString>;
@@ -798,6 +831,7 @@ declare const ApprovalExpiredEventSchema: z.ZodObject<{
798
831
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
799
832
  occurred_at: z.ZodString;
800
833
  source: z.ZodString;
834
+ prev_hash: z.ZodOptional<z.ZodString>;
801
835
  type: z.ZodLiteral<"approval_expired">;
802
836
  approval_id: z.ZodString & z.ZodType<`appr_${string}`, string, z.core.$ZodTypeInternals<`appr_${string}`, string>>;
803
837
  }, z.core.$strip>;
@@ -807,6 +841,7 @@ declare const CommandExecutedEventSchema: z.ZodObject<{
807
841
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
808
842
  occurred_at: z.ZodString;
809
843
  source: z.ZodString;
844
+ prev_hash: z.ZodOptional<z.ZodString>;
810
845
  type: z.ZodLiteral<"command_executed">;
811
846
  command: z.ZodString;
812
847
  args: z.ZodArray<z.ZodString>;
@@ -822,6 +857,7 @@ declare const GitSnapshotEventSchema: z.ZodObject<{
822
857
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
823
858
  occurred_at: z.ZodString;
824
859
  source: z.ZodString;
860
+ prev_hash: z.ZodOptional<z.ZodString>;
825
861
  type: z.ZodLiteral<"git_snapshot">;
826
862
  head: z.ZodString;
827
863
  branch: z.ZodString;
@@ -838,6 +874,7 @@ declare const FileChangedEventSchema: z.ZodObject<{
838
874
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
839
875
  occurred_at: z.ZodString;
840
876
  source: z.ZodString;
877
+ prev_hash: z.ZodOptional<z.ZodString>;
841
878
  type: z.ZodLiteral<"file_changed">;
842
879
  path: z.ZodString;
843
880
  change_type: z.ZodEnum<{
@@ -854,6 +891,7 @@ declare const DecisionRecordedEventSchema: z.ZodObject<{
854
891
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
855
892
  occurred_at: z.ZodString;
856
893
  source: z.ZodString;
894
+ prev_hash: z.ZodOptional<z.ZodString>;
857
895
  type: z.ZodLiteral<"decision_recorded">;
858
896
  decision_id: z.ZodString & z.ZodType<`decision_${string}`, string, z.core.$ZodTypeInternals<`decision_${string}`, string>>;
859
897
  title: z.ZodString;
@@ -869,6 +907,7 @@ declare const TaskCreatedEventSchema: z.ZodObject<{
869
907
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
870
908
  occurred_at: z.ZodString;
871
909
  source: z.ZodString;
910
+ prev_hash: z.ZodOptional<z.ZodString>;
872
911
  type: z.ZodLiteral<"task_created">;
873
912
  task_id: z.ZodString & z.ZodType<`task_${string}`, string, z.core.$ZodTypeInternals<`task_${string}`, string>>;
874
913
  title: z.ZodString;
@@ -879,6 +918,7 @@ declare const TaskStatusChangedEventSchema: z.ZodObject<{
879
918
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
880
919
  occurred_at: z.ZodString;
881
920
  source: z.ZodString;
921
+ prev_hash: z.ZodOptional<z.ZodString>;
882
922
  type: z.ZodLiteral<"task_status_changed">;
883
923
  task_id: z.ZodString & z.ZodType<`task_${string}`, string, z.core.$ZodTypeInternals<`task_${string}`, string>>;
884
924
  from: z.ZodString;
@@ -890,6 +930,7 @@ declare const TaskReconciledEventSchema: z.ZodObject<{
890
930
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
891
931
  occurred_at: z.ZodString;
892
932
  source: z.ZodString;
933
+ prev_hash: z.ZodOptional<z.ZodString>;
893
934
  type: z.ZodLiteral<"task_reconciled">;
894
935
  task_id: z.ZodString & z.ZodType<`task_${string}`, string, z.core.$ZodTypeInternals<`task_${string}`, string>>;
895
936
  removed_created_in_session: z.ZodDefault<z.ZodNullable<z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>>>;
@@ -902,6 +943,7 @@ declare const TaskLinkageRefreshedEventSchema: z.ZodObject<{
902
943
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
903
944
  occurred_at: z.ZodString;
904
945
  source: z.ZodString;
946
+ prev_hash: z.ZodOptional<z.ZodString>;
905
947
  type: z.ZodLiteral<"task_linkage_refreshed">;
906
948
  task_id: z.ZodString & z.ZodType<`task_${string}`, string, z.core.$ZodTypeInternals<`task_${string}`, string>>;
907
949
  added_linked_sessions: z.ZodDefault<z.ZodArray<z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>>>;
@@ -914,6 +956,7 @@ declare const TaskDeletedEventSchema: z.ZodObject<{
914
956
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
915
957
  occurred_at: z.ZodString;
916
958
  source: z.ZodString;
959
+ prev_hash: z.ZodOptional<z.ZodString>;
917
960
  type: z.ZodLiteral<"task_deleted">;
918
961
  task_id: z.ZodString & z.ZodType<`task_${string}`, string, z.core.$ZodTypeInternals<`task_${string}`, string>>;
919
962
  title: z.ZodString;
@@ -924,6 +967,7 @@ declare const TaskArchivedEventSchema: z.ZodObject<{
924
967
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
925
968
  occurred_at: z.ZodString;
926
969
  source: z.ZodString;
970
+ prev_hash: z.ZodOptional<z.ZodString>;
927
971
  type: z.ZodLiteral<"task_archived">;
928
972
  task_id: z.ZodString & z.ZodType<`task_${string}`, string, z.core.$ZodTypeInternals<`task_${string}`, string>>;
929
973
  title: z.ZodString;
@@ -934,6 +978,7 @@ declare const NoteAddedEventSchema: z.ZodObject<{
934
978
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
935
979
  occurred_at: z.ZodString;
936
980
  source: z.ZodString;
981
+ prev_hash: z.ZodOptional<z.ZodString>;
937
982
  type: z.ZodLiteral<"note_added">;
938
983
  body: z.ZodString;
939
984
  }, z.core.$strip>;
@@ -943,6 +988,7 @@ declare const AdapterOutputEventSchema: z.ZodObject<{
943
988
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
944
989
  occurred_at: z.ZodString;
945
990
  source: z.ZodString;
991
+ prev_hash: z.ZodOptional<z.ZodString>;
946
992
  type: z.ZodLiteral<"adapter_output">;
947
993
  stream: z.ZodEnum<{
948
994
  stdout: "stdout";
@@ -963,6 +1009,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
963
1009
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
964
1010
  occurred_at: z.ZodString;
965
1011
  source: z.ZodString;
1012
+ prev_hash: z.ZodOptional<z.ZodString>;
966
1013
  type: z.ZodLiteral<"session_started">;
967
1014
  }, z.core.$strip>, z.ZodObject<{
968
1015
  schema_version: z.ZodLiteral<"0.1.0">;
@@ -970,6 +1017,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
970
1017
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
971
1018
  occurred_at: z.ZodString;
972
1019
  source: z.ZodString;
1020
+ prev_hash: z.ZodOptional<z.ZodString>;
973
1021
  type: z.ZodLiteral<"session_ended">;
974
1022
  exit_code: z.ZodOptional<z.ZodNumber>;
975
1023
  }, z.core.$strip>, z.ZodObject<{
@@ -978,6 +1026,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
978
1026
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
979
1027
  occurred_at: z.ZodString;
980
1028
  source: z.ZodString;
1029
+ prev_hash: z.ZodOptional<z.ZodString>;
981
1030
  type: z.ZodLiteral<"session_status_changed">;
982
1031
  from: z.ZodString;
983
1032
  to: z.ZodString;
@@ -987,6 +1036,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
987
1036
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
988
1037
  occurred_at: z.ZodString;
989
1038
  source: z.ZodString;
1039
+ prev_hash: z.ZodOptional<z.ZodString>;
990
1040
  type: z.ZodLiteral<"approval_requested">;
991
1041
  approval_id: z.ZodString & z.ZodType<`appr_${string}`, string, z.core.$ZodTypeInternals<`appr_${string}`, string>>;
992
1042
  expires_at: z.ZodDefault<z.ZodNullable<z.ZodString>>;
@@ -1007,6 +1057,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1007
1057
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
1008
1058
  occurred_at: z.ZodString;
1009
1059
  source: z.ZodString;
1060
+ prev_hash: z.ZodOptional<z.ZodString>;
1010
1061
  type: z.ZodLiteral<"approval_approved">;
1011
1062
  approval_id: z.ZodString & z.ZodType<`appr_${string}`, string, z.core.$ZodTypeInternals<`appr_${string}`, string>>;
1012
1063
  resolver: z.ZodOptional<z.ZodString>;
@@ -1017,6 +1068,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1017
1068
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
1018
1069
  occurred_at: z.ZodString;
1019
1070
  source: z.ZodString;
1071
+ prev_hash: z.ZodOptional<z.ZodString>;
1020
1072
  type: z.ZodLiteral<"approval_rejected">;
1021
1073
  approval_id: z.ZodString & z.ZodType<`appr_${string}`, string, z.core.$ZodTypeInternals<`appr_${string}`, string>>;
1022
1074
  resolver: z.ZodOptional<z.ZodString>;
@@ -1027,6 +1079,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1027
1079
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
1028
1080
  occurred_at: z.ZodString;
1029
1081
  source: z.ZodString;
1082
+ prev_hash: z.ZodOptional<z.ZodString>;
1030
1083
  type: z.ZodLiteral<"approval_expired">;
1031
1084
  approval_id: z.ZodString & z.ZodType<`appr_${string}`, string, z.core.$ZodTypeInternals<`appr_${string}`, string>>;
1032
1085
  }, z.core.$strip>, z.ZodObject<{
@@ -1035,6 +1088,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1035
1088
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
1036
1089
  occurred_at: z.ZodString;
1037
1090
  source: z.ZodString;
1091
+ prev_hash: z.ZodOptional<z.ZodString>;
1038
1092
  type: z.ZodLiteral<"command_executed">;
1039
1093
  command: z.ZodString;
1040
1094
  args: z.ZodArray<z.ZodString>;
@@ -1049,6 +1103,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1049
1103
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
1050
1104
  occurred_at: z.ZodString;
1051
1105
  source: z.ZodString;
1106
+ prev_hash: z.ZodOptional<z.ZodString>;
1052
1107
  type: z.ZodLiteral<"git_snapshot">;
1053
1108
  head: z.ZodString;
1054
1109
  branch: z.ZodString;
@@ -1064,6 +1119,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1064
1119
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
1065
1120
  occurred_at: z.ZodString;
1066
1121
  source: z.ZodString;
1122
+ prev_hash: z.ZodOptional<z.ZodString>;
1067
1123
  type: z.ZodLiteral<"file_changed">;
1068
1124
  path: z.ZodString;
1069
1125
  change_type: z.ZodEnum<{
@@ -1079,6 +1135,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1079
1135
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
1080
1136
  occurred_at: z.ZodString;
1081
1137
  source: z.ZodString;
1138
+ prev_hash: z.ZodOptional<z.ZodString>;
1082
1139
  type: z.ZodLiteral<"decision_recorded">;
1083
1140
  decision_id: z.ZodString & z.ZodType<`decision_${string}`, string, z.core.$ZodTypeInternals<`decision_${string}`, string>>;
1084
1141
  title: z.ZodString;
@@ -1093,6 +1150,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1093
1150
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
1094
1151
  occurred_at: z.ZodString;
1095
1152
  source: z.ZodString;
1153
+ prev_hash: z.ZodOptional<z.ZodString>;
1096
1154
  type: z.ZodLiteral<"task_created">;
1097
1155
  task_id: z.ZodString & z.ZodType<`task_${string}`, string, z.core.$ZodTypeInternals<`task_${string}`, string>>;
1098
1156
  title: z.ZodString;
@@ -1102,6 +1160,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1102
1160
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
1103
1161
  occurred_at: z.ZodString;
1104
1162
  source: z.ZodString;
1163
+ prev_hash: z.ZodOptional<z.ZodString>;
1105
1164
  type: z.ZodLiteral<"task_status_changed">;
1106
1165
  task_id: z.ZodString & z.ZodType<`task_${string}`, string, z.core.$ZodTypeInternals<`task_${string}`, string>>;
1107
1166
  from: z.ZodString;
@@ -1112,6 +1171,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1112
1171
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
1113
1172
  occurred_at: z.ZodString;
1114
1173
  source: z.ZodString;
1174
+ prev_hash: z.ZodOptional<z.ZodString>;
1115
1175
  type: z.ZodLiteral<"task_reconciled">;
1116
1176
  task_id: z.ZodString & z.ZodType<`task_${string}`, string, z.core.$ZodTypeInternals<`task_${string}`, string>>;
1117
1177
  removed_created_in_session: z.ZodDefault<z.ZodNullable<z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>>>;
@@ -1123,6 +1183,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1123
1183
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
1124
1184
  occurred_at: z.ZodString;
1125
1185
  source: z.ZodString;
1186
+ prev_hash: z.ZodOptional<z.ZodString>;
1126
1187
  type: z.ZodLiteral<"task_linkage_refreshed">;
1127
1188
  task_id: z.ZodString & z.ZodType<`task_${string}`, string, z.core.$ZodTypeInternals<`task_${string}`, string>>;
1128
1189
  added_linked_sessions: z.ZodDefault<z.ZodArray<z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>>>;
@@ -1134,6 +1195,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1134
1195
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
1135
1196
  occurred_at: z.ZodString;
1136
1197
  source: z.ZodString;
1198
+ prev_hash: z.ZodOptional<z.ZodString>;
1137
1199
  type: z.ZodLiteral<"task_deleted">;
1138
1200
  task_id: z.ZodString & z.ZodType<`task_${string}`, string, z.core.$ZodTypeInternals<`task_${string}`, string>>;
1139
1201
  title: z.ZodString;
@@ -1143,6 +1205,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1143
1205
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
1144
1206
  occurred_at: z.ZodString;
1145
1207
  source: z.ZodString;
1208
+ prev_hash: z.ZodOptional<z.ZodString>;
1146
1209
  type: z.ZodLiteral<"task_archived">;
1147
1210
  task_id: z.ZodString & z.ZodType<`task_${string}`, string, z.core.$ZodTypeInternals<`task_${string}`, string>>;
1148
1211
  title: z.ZodString;
@@ -1152,6 +1215,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1152
1215
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
1153
1216
  occurred_at: z.ZodString;
1154
1217
  source: z.ZodString;
1218
+ prev_hash: z.ZodOptional<z.ZodString>;
1155
1219
  type: z.ZodLiteral<"note_added">;
1156
1220
  body: z.ZodString;
1157
1221
  }, z.core.$strip>, z.ZodObject<{
@@ -1160,6 +1224,7 @@ declare const EventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
1160
1224
  session_id: z.ZodString & z.ZodType<`ses_${string}`, string, z.core.$ZodTypeInternals<`ses_${string}`, string>>;
1161
1225
  occurred_at: z.ZodString;
1162
1226
  source: z.ZodString;
1227
+ prev_hash: z.ZodOptional<z.ZodString>;
1163
1228
  type: z.ZodLiteral<"adapter_output">;
1164
1229
  stream: z.ZodEnum<{
1165
1230
  stdout: "stdout";
@@ -1345,6 +1410,20 @@ declare const SessionMetricsSchema: z.ZodObject<{
1345
1410
  }, z.core.$strip>;
1346
1411
  /** Inferred runtime type for {@link SessionMetricsSchema}. */
1347
1412
  type SessionMetrics = z.infer<typeof SessionMetricsSchema>;
1413
+ /**
1414
+ * Tamper-evidence head anchor for sessions whose `events.jsonl` was written
1415
+ * with hash chaining (import / in-place re-import): `head_hash` is the hex
1416
+ * sha-256 of the last written event line (excluding the trailing newline),
1417
+ * `event_count` the number of chained lines. Absent on live / ad-hoc /
1418
+ * pre-feature sessions. Additive optional => no schema_version bump.
1419
+ * `.strict()` because the import writer fully owns the shape.
1420
+ */
1421
+ declare const SessionIntegritySchema: z.ZodObject<{
1422
+ head_hash: z.ZodString;
1423
+ event_count: z.ZodNumber;
1424
+ }, z.core.$strict>;
1425
+ /** Inferred runtime type for {@link SessionIntegritySchema}. */
1426
+ type SessionIntegrity = z.infer<typeof SessionIntegritySchema>;
1348
1427
  /**
1349
1428
  * Schema for `.basou/sessions/<session_id>/session.yaml`. The minimal
1350
1429
  * session document carries the actual fields nested under the outer
@@ -1405,6 +1484,10 @@ declare const SessionSchema: z.ZodObject<{
1405
1484
  active_time_method: z.ZodOptional<z.ZodString>;
1406
1485
  machine_active_time_ms: z.ZodOptional<z.ZodNumber>;
1407
1486
  }, z.core.$strip>>;
1487
+ integrity: z.ZodOptional<z.ZodObject<{
1488
+ head_hash: z.ZodString;
1489
+ event_count: z.ZodNumber;
1490
+ }, z.core.$strict>>;
1408
1491
  }, z.core.$strip>;
1409
1492
  }, z.core.$strip>;
1410
1493
  /** Inferred runtime type for {@link SessionSchema}. */
@@ -1539,6 +1622,64 @@ type DecisionsRendererResult = {
1539
1622
  */
1540
1623
  declare function renderDecisions(input: DecisionsRendererInput): Promise<DecisionsRendererResult>;
1541
1624
 
1625
+ /**
1626
+ * Session-bound genesis hash: the `prev_hash` carried by the FIRST event line
1627
+ * of a chained `events.jsonl`. Binding the genesis to the session id means a
1628
+ * chain copied verbatim from another session fails verification at line 1
1629
+ * even though its internal back-pointers are intact.
1630
+ */
1631
+ declare function genesisHash(sessionId: string): string;
1632
+ /**
1633
+ * Hex sha-256 of one event line's written bytes (EXCLUDING the trailing
1634
+ * `\n`). The hash covers the literal serialized bytes — no canonical JSON
1635
+ * form. Writers pass the line string (always valid UTF-8, so its UTF-8
1636
+ * encoding IS the written bytes); the verifier passes the RAW BYTES it read,
1637
+ * so a byte-level mutation that decodes to the same string (e.g. an invalid
1638
+ * UTF-8 sequence collapsing to U+FFFD) still breaks the chain.
1639
+ */
1640
+ declare function lineHash(rawLine: string | Buffer): string;
1641
+ /**
1642
+ * The single serializer for event lines. Every writer (bulk and append) MUST
1643
+ * go through this function so the bytes a chain hashes can never diverge from
1644
+ * the bytes another code path would write.
1645
+ */
1646
+ declare function serializeEventLine(event: Event): string;
1647
+ /** Result of {@link chainEvents}: the serialized lines plus the head anchor inputs. */
1648
+ type ChainedEvents = {
1649
+ /** Serialized event lines (no trailing newline on the entries). */
1650
+ lines: string[];
1651
+ /**
1652
+ * Hex sha-256 of the LAST line — the value `session.yaml.integrity.head_hash`
1653
+ * anchors. For an empty batch this is the genesis hash and no anchor is
1654
+ * written.
1655
+ */
1656
+ headHash: string;
1657
+ /** Number of chained lines (= `integrity.event_count`). */
1658
+ count: number;
1659
+ };
1660
+ /**
1661
+ * Thread a `prev_hash` back-pointer through `events` and serialize them:
1662
+ * line 0 carries `genesisHash(sessionId)`, line N carries the hash of line
1663
+ * N-1's written bytes. Any `prev_hash` already present on an incoming event
1664
+ * (e.g. a round-trip import payload) is discarded and recomputed — chains are
1665
+ * never trusted from input, only derived at write time.
1666
+ */
1667
+ declare function chainEvents(events: ReadonlyArray<Event>, sessionId: string): ChainedEvents;
1668
+ /**
1669
+ * Chain PRE-EXISTING serialized event lines WITHOUT re-serializing them
1670
+ * through the schema layer: each original line is JSON-parsed, given a
1671
+ * `prev_hash`, and stringified again. Because `JSON.parse`/`JSON.stringify`
1672
+ * round-trips key insertion order and every value verbatim, the output line
1673
+ * is the original line with only the `prev_hash` member appended — no zod
1674
+ * key-stripping or default materialization can occur. Used by the in-place
1675
+ * rechain migration of pre-chaining imported sessions.
1676
+ *
1677
+ * Callers MUST gate validity first (non-empty, JSON-parseable,
1678
+ * schema-valid, byte-identical JSON round-trip); this helper assumes
1679
+ * parseable lines and throws raw on a parse failure.
1680
+ */
1681
+ declare function chainRawJsonLines(rawLines: ReadonlyArray<string>, sessionId: string): ChainedEvents;
1682
+
1542
1683
  /**
1543
1684
  * Append a single Basou event to `<sessionDir>/events.jsonl`.
1544
1685
  *
@@ -1547,6 +1688,11 @@ declare function renderDecisions(input: DecisionsRendererInput): Promise<Decisio
1547
1688
  * Validation enforces the per-variant contract (required fields, source
1548
1689
  * vocabulary, strict variants such as `adapter_output`).
1549
1690
  *
1691
+ * Appended lines are NOT hash-chained: chaining is exclusive to the bulk
1692
+ * import writers ({@link writeEventsBulk} with `chain: true`), and imported
1693
+ * sessions reject every append path, so a chained file never receives an
1694
+ * unchained appended line.
1695
+ *
1550
1696
  * Atomicity: writes go through `appendFile` which uses `O_APPEND`. Lines up
1551
1697
  * to `PIPE_BUF` bytes (Linux 4096 / macOS 512) are written atomically by the
1552
1698
  * kernel; longer lines may interleave with concurrent writers and are not
@@ -1560,6 +1706,23 @@ declare function renderDecisions(input: DecisionsRendererInput): Promise<Decisio
1560
1706
  * @param event unknown payload to validate and append
1561
1707
  */
1562
1708
  declare function appendEvent(sessionDir: string, event: unknown): Promise<void>;
1709
+ /** Options for {@link writeEventsBulk}. */
1710
+ type WriteEventsBulkOptions = {
1711
+ /**
1712
+ * Thread a per-line `prev_hash` hash chain through the batch and return the
1713
+ * head anchor inputs. Used ONLY by the import writers (fresh import and
1714
+ * in-place re-import); defaults to false so the live / ad-hoc writers keep
1715
+ * producing plain unchained lines.
1716
+ */
1717
+ chain?: boolean;
1718
+ };
1719
+ /** Head anchor inputs returned by a chained {@link writeEventsBulk}. */
1720
+ type BulkChainResult = {
1721
+ /** Hex sha-256 of the last written line (excluding the trailing `\n`). */
1722
+ headHash: string;
1723
+ /** Number of chained lines written. */
1724
+ count: number;
1725
+ };
1563
1726
  /**
1564
1727
  * Write `events.jsonl` in one atomic tmp+rename pass via {@link atomicReplace},
1565
1728
  * validating every event against {@link EventSchema} before any disk I/O so
@@ -1570,12 +1733,100 @@ declare function appendEvent(sessionDir: string, event: unknown): Promise<void>;
1570
1733
  * of events must land together or not at all. Zero events produces a
1571
1734
  * zero-byte file so the session_yaml `events_log` pointer remains valid.
1572
1735
  *
1736
+ * With `options.chain` set, each line is written with a `prev_hash`
1737
+ * back-pointer (any incoming `prev_hash` is discarded and recomputed; the
1738
+ * chain's genesis is bound to `basename(sessionDir)` = the session id) and
1739
+ * the head anchor inputs are returned so the caller can persist
1740
+ * `session.yaml.integrity`. An empty chained batch writes a zero-byte file
1741
+ * and returns null — no anchor. Without `chain` the return value is null and
1742
+ * the written bytes are identical to the previous unchained format.
1743
+ *
1573
1744
  * Throws `"Invalid Basou event payload"` (same fixed message as
1574
1745
  * {@link appendEvent}) on validation failure, or `"Failed to write
1575
1746
  * events.jsonl"` on a disk I/O failure. The original native error is attached
1576
1747
  * as `cause`.
1577
1748
  */
1578
- declare function writeEventsBulk(sessionDir: string, events: Event[]): Promise<void>;
1749
+ declare function writeEventsBulk(sessionDir: string, events: Event[], options?: WriteEventsBulkOptions): Promise<BulkChainResult | null>;
1750
+
1751
+ /**
1752
+ * Verification outcome for one session's `events.jsonl`.
1753
+ *
1754
+ * - `unchained` — no event line carries `prev_hash` (live / ad-hoc / legacy
1755
+ * session) and `session.yaml` carries no integrity anchor. Informational.
1756
+ * - `empty` — zero events and no integrity anchor. Informational.
1757
+ * - `incomplete` — the log is chained but `session.yaml` is ENTIRELY absent
1758
+ * (an import crashed between the events write and the yaml write, or the
1759
+ * yaml was deleted out of band). Benign: a re-import / `--force` repairs it.
1760
+ * - `tampered` — a real integrity break (see {@link ChainBreakReason}).
1761
+ * - `verified` — every back-pointer, genesis, session-id and line-discipline
1762
+ * check passed AND the head anchor matches the on-disk log.
1763
+ */
1764
+ type ChainVerdictStatus = "verified" | "unchained" | "empty" | "incomplete" | "tampered";
1765
+ /** Machine-readable detail for a `tampered` (or `incomplete`) verdict. */
1766
+ type ChainBreakReason =
1767
+ /** The file does not end with `\n`; chained writers always terminate the last line. */
1768
+ "torn_tail"
1769
+ /** A blank line inside a chained log; chained writers never emit one. */
1770
+ | "blank_line"
1771
+ /** A line of a chained log failed JSON parsing; writers only emit valid JSON. */
1772
+ | "malformed_line"
1773
+ /** A chained log has a line without `prev_hash`; chained writers chain every line. */
1774
+ | "missing_prev_hash"
1775
+ /** Line 1's `prev_hash` is not this session's genesis hash (edit or cross-session copy). */
1776
+ | "genesis_mismatch"
1777
+ /** A line's `prev_hash` does not hash-match the previous line (edit / insert / delete / reorder). */
1778
+ | "broken_link"
1779
+ /** A line's `session_id` is not this session's id (cross-session copied line). */
1780
+ | "session_id_mismatch"
1781
+ /** `session.yaml` exists but its `integrity` anchor is missing (anchor stripped). */
1782
+ | "anchor_missing"
1783
+ /** The anchor's `head_hash` / `event_count` disagree with the on-disk log (edit or truncation). */
1784
+ | "anchor_mismatch"
1785
+ /** An integrity anchor exists but the log is unchained, empty, or missing (chain stripped). */
1786
+ | "anchor_without_chain"
1787
+ /** `session.yaml` exists but could not be parsed / validated, so the anchor is unreadable. */
1788
+ | "yaml_unreadable"
1789
+ /** `incomplete` only: `session.yaml` is entirely absent. */
1790
+ | "yaml_missing";
1791
+ /** Result of {@link verifyEventsChain}. */
1792
+ type ChainVerdict = {
1793
+ status: ChainVerdictStatus;
1794
+ /** Complete (newline-terminated) event lines found on disk. */
1795
+ eventCount: number;
1796
+ /** Detail for `tampered` / `incomplete`; absent otherwise. */
1797
+ reason?: ChainBreakReason;
1798
+ /** 1-based line number of the first break, when one specific line broke. */
1799
+ line?: number;
1800
+ };
1801
+ /**
1802
+ * Verify the tamper-evidence hash chain of `<sessions>/<sessionId>/events.jsonl`
1803
+ * against the head anchor in `session.yaml.integrity`. READ-ONLY.
1804
+ *
1805
+ * The verifier reads the RAW line BYTES (not the schema-filtering replay
1806
+ * reader, which silently drops bad lines; and not a decoded string, which
1807
+ * would collapse invalid UTF-8 sequences into U+FFFD and let a byte-level
1808
+ * substitution survive re-hashing) and hashes exactly the bytes it read.
1809
+ * The verdict is decided on the events first, then the anchor:
1810
+ *
1811
+ * - No line carries `prev_hash` (or there are zero lines / no file): the log
1812
+ * is unchained. If `session.yaml` nevertheless carries an integrity anchor,
1813
+ * the chain was stripped out of band => `tampered` (`anchor_without_chain`);
1814
+ * otherwise `unchained` / `empty`.
1815
+ * - At least one line carries `prev_hash`: the log claims to be chained, and
1816
+ * every check applies — line discipline (terminating `\n`, no blank lines,
1817
+ * valid JSON), genesis binding, per-line back-pointers, per-line session id,
1818
+ * and finally the head anchor (`incomplete` when `session.yaml` is entirely
1819
+ * absent; `tampered` when it is present without a matching anchor).
1820
+ *
1821
+ * NON-CRYPTOGRAPHIC: the anchor lives in `session.yaml`, which is itself
1822
+ * editable; an attacker rewriting BOTH files consistently is not detected.
1823
+ * Signing is a follow-up.
1824
+ *
1825
+ * Throws `Error("Failed to read events.jsonl")` only for non-ENOENT I/O
1826
+ * failures (EACCES etc.) — an unreadable file is an environment problem, not
1827
+ * a verdict.
1828
+ */
1829
+ declare function verifyEventsChain(paths: BasouPaths, sessionId: string): Promise<ChainVerdict>;
1579
1830
 
1580
1831
  /**
1581
1832
  * Status classification used by the `file_changed` event schema. Limited to
@@ -3139,6 +3390,9 @@ type LockHandle = {
3139
3390
  *
3140
3391
  * Acquisition strategy:
3141
3392
  * 1. {@link atomicCreate} the lockfile (POSIX link(2) + EEXIST).
3393
+ * On ENOENT (a workspace from before `.basou/locks/` existed), create
3394
+ * the directory and retry once; a retry failure throws the pathless
3395
+ * `"Failed to acquire lock"`.
3142
3396
  * 2. On EEXIST, probe the existing lockfile via {@link isStaleLock}.
3143
3397
  * - If stale (= holder pid is dead or lock is older than
3144
3398
  * {@link STALE_LOCK_MAX_AGE_MS}), `unlink` the stale file and retry
@@ -3344,7 +3598,7 @@ type ReimportResult = {
3344
3598
  reusedIdCount: number;
3345
3599
  } | {
3346
3600
  status: "skipped";
3347
- reason: "prior_events_unreadable" | "prior_derived_dropped";
3601
+ reason: "prior_events_unreadable" | "prior_derived_dropped" | "prior_chain_broken";
3348
3602
  };
3349
3603
  /**
3350
3604
  * Re-import a source whose native log GREW into the SAME Basou session,
@@ -3363,6 +3617,42 @@ type ReimportResult = {
3363
3617
  * ABORTED (`status: "skipped"`) rather than risk dropping data on the rewrite.
3364
3618
  */
3365
3619
  declare function reimportPreservingId(paths: BasouPaths, manifest: Manifest, priorSessionId: string, freshPayload: SessionImportPayload, options?: ReimportOptions): Promise<ReimportResult>;
3620
+ /** Options for {@link rechainSessionInPlace}. */
3621
+ type RechainOptions = {
3622
+ /**
3623
+ * Compute the outcome and write nothing. The session lock is STILL taken:
3624
+ * an unlocked read could observe a concurrent in-place re-import's
3625
+ * two-file write window (events rewritten, yaml not yet) and report a
3626
+ * state a locked run would never see.
3627
+ */
3628
+ dryRun?: boolean;
3629
+ };
3630
+ /** Result of {@link rechainSessionInPlace}. */
3631
+ type RechainResult = {
3632
+ status: "rechained";
3633
+ eventCount: number;
3634
+ } | {
3635
+ status: "skipped";
3636
+ reason: "already_chained" | "empty" | "not_imported" | "tampered" | "events_unreadable" | "session_id_mismatch" | "yaml_missing" | "yaml_unreadable";
3637
+ };
3638
+ /**
3639
+ * Add the tamper-evidence hash chain, IN PLACE, to an imported session that
3640
+ * was written before chaining existed (or whose chain was legitimately never
3641
+ * computed). Event ids, order, field sets, values and key order are all
3642
+ * preserved exactly — each original line is re-emitted with only `prev_hash`
3643
+ * appended (see {@link chainRawJsonLines}); `session.yaml` is rewritten as
3644
+ * read with only `integrity` added. Nothing else changes, so cross-session
3645
+ * references (`linked_events`) survive, unlike a `--force` re-import.
3646
+ *
3647
+ * Rechaining asserts tamper-evidence FROM NOW ON; it does not retroactively
3648
+ * prove the pre-existing content was never modified before the migration.
3649
+ *
3650
+ * Refuses anything it cannot preserve exactly or that is not the closed
3651
+ * imported corpus — see {@link RechainResult} reasons. Throws (rather than
3652
+ * returning a skip) on environment-level I/O failures, mirroring
3653
+ * `verifyEventsChain`.
3654
+ */
3655
+ declare function rechainSessionInPlace(paths: BasouPaths, sessionId: string, options?: RechainOptions): Promise<RechainResult>;
3366
3656
 
3367
3657
  /**
3368
3658
  * Walk the cause chain (up to `depth` levels) looking for an Error whose
@@ -3464,4 +3754,4 @@ declare function overwriteYamlFile(filePath: string, value: unknown): Promise<vo
3464
3754
  */
3465
3755
  declare const BASOU_CORE_VERSION = "0.1.0";
3466
3756
 
3467
- export { ACTIVE_GAP_CAP_MS, type ActiveTimeBasis, type AdapterOutputEvent, type AppendBasouGitignoreResult, type AppendEventToExistingInput, type AppendEventToExistingResult, type Approval, type ApprovalApprovedEvent, type ApprovalExpiredEvent, ApprovalIdSchema, type ApprovalLocation, type ApprovalRejectedEvent, type ApprovalRequestedEvent, ApprovalSchema, type ApprovalStatus, ApprovalStatusSchema, type ArchiveTaskInput, type ArchiveTaskResult, type AttachTaskInput, type AttachUpdateTaskStatusInput, type AttachableStatus, BASOU_CORE_VERSION, type BasouPaths, CLAUDE_IMPORT_SOURCE, CODEX_IMPORT_SOURCE, type CaptureMode, ChildProcessRunner, type ClaudeTranscriptRecord, type ClaudeTranscriptToPayloadOptions, type CodexRolloutRecord, type CodexRolloutToPayloadOptions, type CommandExecutedEvent, type CommandLookup, type CreateAdHocSessionInput, type CreateAdHocSessionResult, type CreateAdHocTaskInput, type CreateManifestInput, type CreateTaskInput, type CreateTaskResult, type DayWorkStats, DecisionIdSchema, type DecisionRecordedEvent, type DecisionsRendererInput, type DecisionsRendererResult, type DeleteTaskInput, type DeleteTaskResult, type DiffResult, type EditTaskInput, type EditTaskResult, type Event, EventIdSchema, EventSchema, EventSourceSchema, FailedToFinalizeError, type FileChange, type FileChangeStatus, type FileChangedEvent, GENERATED_END, GENERATED_START, type GitSnapshot, type GitSnapshotEvent, type HandoffRendererInput, type HandoffRendererResult, ID_PREFIXES, type IdPrefix, type ImportSessionOptions, type ImportSessionResult, IsoTimestampSchema, JSON_SCHEMA_VERSION, type JsonSchemaArtifact, type LoadSessionEntriesOptions, type LoadTaskEntriesOptions, type LoadedApproval, type LockHandle, type LockScope, type Manifest, ManifestSchema, type MarkerSection, type MeasureAvailability, type NoteAddedEvent, type PrefixedId, type ProcessRunner, type ReconcileAllResult, type ReconcileAllTasksInput, type ReconcileAllTasksOptions, type ReconcileFailure, type ReconcileResult, type ReconcileTaskInput, type RefreshLinkageInput, type RefreshLinkageResult, type ReimportOptions, type ReimportResult, type ReplayOptions, type ReplayWarning, type RiskLevel, RiskLevelSchema, type RunOptions, type RunResult, STUCK_THRESHOLD_MS, type SanitizePathOptions, type SanitizeRelatedFilesResult, SchemaVersionSchema, type Session, type SessionEndedEvent, type SessionEntry, SessionIdSchema, type SessionImportPayload, SessionImportPayloadSchema, type SessionInnerImportInput, SessionInnerImportSchema, type SessionMetrics, SessionMetricsSchema, SessionSchema, type SessionSkipReason, type SessionSourceKind, SessionSourceKindSchema, type SessionStartedEvent, type SessionStatus, type SessionStatusChangedEvent, SessionStatusSchema, type SessionWorkStats, type SourceWorkStats, type StatusCount, StatusSchema, type StatusSnapshot, type SuspectReason, type Task, type TaskArchivedEvent, type TaskCreatedEvent, type TaskDeletedEvent, type TaskDocument, TaskIdSchema, type TaskLinkageRefreshedEvent, type TaskReconciledEvent, TaskSchema, type TaskSkipReason, type TaskStatus, type TaskStatusChangedEvent, TaskStatusSchema, TaskWriteAfterEventError, type TaskWriteAfterEventPhase, type TokenTotals, type UpdateAdHocTaskStatusInput, type UpdateTaskStatusInput, type UpdateTaskStatusResult, type WorkStatsInput, type WorkStatsResult, type WorkStatsTotals, WorkspaceIdSchema, type WriteTaskFileMode, acquireLock, appendBasouGitignore, appendEvent, appendEventToExistingSession, archiveTask, assertBasouRootSafe, basouPaths, buildJsonSchemas, buildStatusSnapshot, classifySuspect, claudeCodeAdapterMetadata, claudeTranscriptToImportPayload, codexRolloutToImportPayload, computeWorkStats, createAdHocSessionWithEvent, createManifest, createTaskWithEvent, deleteTask, editTask, ensureBasouDirectory, enumerateApprovals, enumerateArchivedTaskIds, enumerateSessionDirs, enumerateTaskIds, findErrorCode, getDiff, getSnapshot, importSessionFromJson, isImportDerivedSource, isLazyExpired, isValidPrefixedId, linkYamlFile, loadApproval, loadSessionEntries, loadTaskEntries, overwriteYamlFile, parseDuration, parseMarkers, prefixedUlid, readAllEvents, readManifest, readMarkdownFile, readSessionYaml, readStatus, readTaskFile, readTaskFileWithArchiveFallback, readYamlFile, reconcileAllTasks, reconcileTask, refreshTaskLinkedSessions, reimportPreservingId, renderDecisions, renderHandoff, renderWithMarkers, replayEvents, resolveClaudeCodeCommand, resolveRepositoryRoot, resolveSessionId, resolveTaskId, sanitizePath, sanitizeRelatedFiles, sanitizeWorkingDirectory, serializeJsonSchema, sessionWorkStatsFromEvents, summarizeAdapterOutput, tryRemoteUrl, ulid, updateTaskStatusWithEvent, writeEventsBulk, writeManifest, writeMarkdownFile, writeStatus, writeTaskFile, writeYamlFile };
3757
+ export { ACTIVE_GAP_CAP_MS, type ActiveTimeBasis, type AdapterOutputEvent, type AppendBasouGitignoreResult, type AppendEventToExistingInput, type AppendEventToExistingResult, type Approval, type ApprovalApprovedEvent, type ApprovalExpiredEvent, ApprovalIdSchema, type ApprovalLocation, type ApprovalRejectedEvent, type ApprovalRequestedEvent, ApprovalSchema, type ApprovalStatus, ApprovalStatusSchema, type ArchiveTaskInput, type ArchiveTaskResult, type AttachTaskInput, type AttachUpdateTaskStatusInput, type AttachableStatus, BASOU_CORE_VERSION, type BasouPaths, type BulkChainResult, CLAUDE_IMPORT_SOURCE, CODEX_IMPORT_SOURCE, type CaptureMode, type ChainBreakReason, type ChainVerdict, type ChainVerdictStatus, type ChainedEvents, ChildProcessRunner, type ClaudeTranscriptRecord, type ClaudeTranscriptToPayloadOptions, type CodexRolloutRecord, type CodexRolloutToPayloadOptions, type CommandExecutedEvent, type CommandLookup, type CreateAdHocSessionInput, type CreateAdHocSessionResult, type CreateAdHocTaskInput, type CreateManifestInput, type CreateTaskInput, type CreateTaskResult, type DayWorkStats, DecisionIdSchema, type DecisionRecordedEvent, type DecisionsRendererInput, type DecisionsRendererResult, type DeleteTaskInput, type DeleteTaskResult, type DiffResult, type EditTaskInput, type EditTaskResult, type Event, EventIdSchema, EventSchema, EventSourceSchema, FailedToFinalizeError, type FileChange, type FileChangeStatus, type FileChangedEvent, GENERATED_END, GENERATED_START, type GitSnapshot, type GitSnapshotEvent, type HandoffRendererInput, type HandoffRendererResult, ID_PREFIXES, type IdPrefix, type ImportSessionOptions, type ImportSessionResult, IsoTimestampSchema, JSON_SCHEMA_VERSION, type JsonSchemaArtifact, type LoadSessionEntriesOptions, type LoadTaskEntriesOptions, type LoadedApproval, type LockHandle, type LockScope, type Manifest, ManifestSchema, type MarkerSection, type MeasureAvailability, type NoteAddedEvent, type PrefixedId, type ProcessRunner, type RechainOptions, type RechainResult, type ReconcileAllResult, type ReconcileAllTasksInput, type ReconcileAllTasksOptions, type ReconcileFailure, type ReconcileResult, type ReconcileTaskInput, type RefreshLinkageInput, type RefreshLinkageResult, type ReimportOptions, type ReimportResult, type ReplayOptions, type ReplayWarning, type RiskLevel, RiskLevelSchema, type RunOptions, type RunResult, STUCK_THRESHOLD_MS, type SanitizePathOptions, type SanitizeRelatedFilesResult, SchemaVersionSchema, type Session, type SessionEndedEvent, type SessionEntry, SessionIdSchema, type SessionImportPayload, SessionImportPayloadSchema, type SessionInnerImportInput, SessionInnerImportSchema, type SessionIntegrity, SessionIntegritySchema, type SessionMetrics, SessionMetricsSchema, SessionSchema, type SessionSkipReason, type SessionSourceKind, SessionSourceKindSchema, type SessionStartedEvent, type SessionStatus, type SessionStatusChangedEvent, SessionStatusSchema, type SessionWorkStats, type SourceWorkStats, type StatusCount, StatusSchema, type StatusSnapshot, type SuspectReason, type Task, type TaskArchivedEvent, type TaskCreatedEvent, type TaskDeletedEvent, type TaskDocument, TaskIdSchema, type TaskLinkageRefreshedEvent, type TaskReconciledEvent, TaskSchema, type TaskSkipReason, type TaskStatus, type TaskStatusChangedEvent, TaskStatusSchema, TaskWriteAfterEventError, type TaskWriteAfterEventPhase, type TokenTotals, type UpdateAdHocTaskStatusInput, type UpdateTaskStatusInput, type UpdateTaskStatusResult, type WorkStatsInput, type WorkStatsResult, type WorkStatsTotals, WorkspaceIdSchema, type WriteEventsBulkOptions, type WriteTaskFileMode, acquireLock, appendBasouGitignore, appendEvent, appendEventToExistingSession, archiveTask, assertBasouRootSafe, basouPaths, buildJsonSchemas, buildStatusSnapshot, chainEvents, chainRawJsonLines, classifySuspect, claudeCodeAdapterMetadata, claudeTranscriptToImportPayload, codexRolloutToImportPayload, computeWorkStats, createAdHocSessionWithEvent, createManifest, createTaskWithEvent, deleteTask, editTask, ensureBasouDirectory, enumerateApprovals, enumerateArchivedTaskIds, enumerateSessionDirs, enumerateTaskIds, findErrorCode, genesisHash, getDiff, getSnapshot, importSessionFromJson, isImportDerivedSource, isLazyExpired, isValidPrefixedId, lineHash, linkYamlFile, loadApproval, loadSessionEntries, loadTaskEntries, overwriteYamlFile, parseDuration, parseMarkers, prefixedUlid, readAllEvents, readManifest, readMarkdownFile, readSessionYaml, readStatus, readTaskFile, readTaskFileWithArchiveFallback, readYamlFile, rechainSessionInPlace, reconcileAllTasks, reconcileTask, refreshTaskLinkedSessions, reimportPreservingId, renderDecisions, renderHandoff, renderWithMarkers, replayEvents, resolveClaudeCodeCommand, resolveRepositoryRoot, resolveSessionId, resolveTaskId, sanitizePath, sanitizeRelatedFiles, sanitizeWorkingDirectory, serializeEventLine, serializeJsonSchema, sessionWorkStatsFromEvents, summarizeAdapterOutput, tryRemoteUrl, ulid, updateTaskStatusWithEvent, verifyEventsChain, writeEventsBulk, writeManifest, writeMarkdownFile, writeStatus, writeTaskFile, writeYamlFile };