@blockrun/clawrouter 0.12.314 → 0.12.316

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
@@ -855,6 +855,12 @@ interface SpendRecord {
855
855
  amount: number;
856
856
  model?: string;
857
857
  action?: string;
858
+ /**
859
+ * Unique per record, so ledgers written by separate processes sharing one
860
+ * spending.json can be merged without double-counting. Absent on records
861
+ * written before it existed; those merge on their content.
862
+ */
863
+ id?: string;
858
864
  }
859
865
  interface SpendingStatus {
860
866
  limits: SpendLimits;
@@ -904,7 +910,7 @@ interface SpendControlStorage {
904
910
  }
905
911
  declare class FileSpendControlStorage implements SpendControlStorage {
906
912
  private readonly spendingFile;
907
- constructor();
913
+ constructor(spendingFile?: string);
908
914
  load(): {
909
915
  limits: SpendLimits;
910
916
  history: SpendRecord[];
@@ -958,6 +964,8 @@ declare class SpendControl {
958
964
  private diskLimits;
959
965
  /** Set when spending.json held an unusable policy list: refuse every payment. */
960
966
  private policyFileBroken?;
967
+ /** Whether persisted history loaded successfully; when false, recovery from an initial failure restores history. */
968
+ private initialHistoryLoaded;
961
969
  private readonly storage;
962
970
  private readonly now;
963
971
  constructor(options?: SpendControlOptions);
@@ -1042,6 +1050,22 @@ declare class SpendControl {
1042
1050
  * windows are deliberately untouched.
1043
1051
  */
1044
1052
  resetSession(): void;
1053
+ /**
1054
+ * Fold in spend that other processes recorded to the same spending.json.
1055
+ *
1056
+ * The hourly and daily windows are per wallet, not per process, but each
1057
+ * process used to read the file once at startup and then trust its own copy:
1058
+ * N proxies started on one wallet each let the full window through, and the
1059
+ * last writer's history replaced the others' on disk (GHSA-9xv2-9567-rxrw).
1060
+ * Re-reading before every amount check and every write closes that for
1061
+ * anything not signed in the same instant. Two processes checking within
1062
+ * one signing round trip of each other can still both pass; reservations
1063
+ * are per process by design (see reserve()).
1064
+ *
1065
+ * A read failure keeps the ledger this instance already has: a file we
1066
+ * cannot read is no reason to forget spend we know about.
1067
+ */
1068
+ private syncHistory;
1045
1069
  private cleanup;
1046
1070
  private save;
1047
1071
  private load;