@llblab/pi-kit 0.19.2 → 0.21.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 (102) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +3 -3
  3. package/node_modules/@llblab/pi-state-flow/AGENTS.md +6 -6
  4. package/node_modules/@llblab/pi-state-flow/CHANGELOG.md +9 -0
  5. package/node_modules/@llblab/pi-state-flow/README.md +4 -4
  6. package/node_modules/@llblab/pi-state-flow/dist/index.d.ts +2 -2
  7. package/node_modules/@llblab/pi-state-flow/dist/index.js +2 -2
  8. package/node_modules/@llblab/pi-state-flow/dist/lib/durable.d.ts +1 -0
  9. package/node_modules/@llblab/pi-state-flow/dist/lib/durable.js +7 -3
  10. package/node_modules/@llblab/pi-state-flow/dist/lib/extension.js +41 -11
  11. package/node_modules/@llblab/pi-state-flow/dist/lib/git.d.ts +6 -0
  12. package/node_modules/@llblab/pi-state-flow/dist/lib/git.js +94 -1
  13. package/node_modules/@llblab/pi-state-flow/dist/lib/protocol.js +2 -5
  14. package/node_modules/@llblab/pi-state-flow/dist/lib/runtime.d.ts +2 -0
  15. package/node_modules/@llblab/pi-state-flow/dist/lib/runtime.js +11 -0
  16. package/node_modules/@llblab/pi-state-flow/dist/lib/status.d.ts +4 -2
  17. package/node_modules/@llblab/pi-state-flow/dist/lib/status.js +8 -2
  18. package/node_modules/@llblab/pi-state-flow/dist/lib/telegram.d.ts +6 -1
  19. package/node_modules/@llblab/pi-state-flow/dist/lib/telegram.js +19 -6
  20. package/node_modules/@llblab/pi-state-flow/dist/lib/temporal.d.ts +5 -0
  21. package/node_modules/@llblab/pi-state-flow/dist/lib/temporal.js +27 -3
  22. package/node_modules/@llblab/pi-state-flow/dist/lib/transition.js +2 -2
  23. package/node_modules/@llblab/pi-state-flow/dist/package.json +1 -1
  24. package/node_modules/@llblab/pi-state-flow/docs/architecture.md +10 -8
  25. package/node_modules/@llblab/pi-state-flow/docs/lazy-state.md +2 -2
  26. package/node_modules/@llblab/pi-state-flow/docs/temporal-acceptance.md +4 -3
  27. package/node_modules/@llblab/pi-state-flow/docs/usage.md +5 -5
  28. package/node_modules/@llblab/pi-state-flow/index.ts +2 -2
  29. package/node_modules/@llblab/pi-state-flow/lib/durable.ts +8 -3
  30. package/node_modules/@llblab/pi-state-flow/lib/extension.ts +41 -9
  31. package/node_modules/@llblab/pi-state-flow/lib/git.ts +83 -1
  32. package/node_modules/@llblab/pi-state-flow/lib/protocol.ts +2 -4
  33. package/node_modules/@llblab/pi-state-flow/lib/runtime.ts +11 -0
  34. package/node_modules/@llblab/pi-state-flow/lib/status.ts +10 -4
  35. package/node_modules/@llblab/pi-state-flow/lib/telegram.ts +23 -6
  36. package/node_modules/@llblab/pi-state-flow/lib/temporal.ts +29 -3
  37. package/node_modules/@llblab/pi-state-flow/lib/transition.ts +2 -2
  38. package/node_modules/@llblab/pi-state-flow/package.json +1 -1
  39. package/node_modules/@llblab/pi-telegram/AGENTS.md +9 -7
  40. package/node_modules/@llblab/pi-telegram/BACKLOG.md +13 -32
  41. package/node_modules/@llblab/pi-telegram/CHANGELOG.md +11 -0
  42. package/node_modules/@llblab/pi-telegram/README.md +4 -3
  43. package/node_modules/@llblab/pi-telegram/dist/lib/bindings.d.ts +2 -2
  44. package/node_modules/@llblab/pi-telegram/dist/lib/bindings.js +3 -5
  45. package/node_modules/@llblab/pi-telegram/dist/lib/bus-follower.d.ts +1 -1
  46. package/node_modules/@llblab/pi-telegram/dist/lib/bus-follower.js +93 -9
  47. package/node_modules/@llblab/pi-telegram/dist/lib/bus-leader.d.ts +9 -3
  48. package/node_modules/@llblab/pi-telegram/dist/lib/bus-leader.js +231 -71
  49. package/node_modules/@llblab/pi-telegram/dist/lib/bus.d.ts +4 -0
  50. package/node_modules/@llblab/pi-telegram/dist/lib/bus.js +34 -7
  51. package/node_modules/@llblab/pi-telegram/dist/lib/extension.js +63 -2
  52. package/node_modules/@llblab/pi-telegram/dist/lib/journal.d.ts +3 -0
  53. package/node_modules/@llblab/pi-telegram/dist/lib/journal.js +13 -0
  54. package/node_modules/@llblab/pi-telegram/dist/lib/lifecycle.d.ts +2 -0
  55. package/node_modules/@llblab/pi-telegram/dist/lib/lifecycle.js +25 -4
  56. package/node_modules/@llblab/pi-telegram/dist/lib/locks.d.ts +1 -0
  57. package/node_modules/@llblab/pi-telegram/dist/lib/locks.js +32 -12
  58. package/node_modules/@llblab/pi-telegram/dist/lib/paths.d.ts +10 -0
  59. package/node_modules/@llblab/pi-telegram/dist/lib/paths.js +22 -1
  60. package/node_modules/@llblab/pi-telegram/dist/lib/polling.js +2 -2
  61. package/node_modules/@llblab/pi-telegram/dist/lib/queue.d.ts +1 -1
  62. package/node_modules/@llblab/pi-telegram/dist/lib/queue.js +1 -2
  63. package/node_modules/@llblab/pi-telegram/dist/lib/sync.d.ts +9 -0
  64. package/node_modules/@llblab/pi-telegram/dist/lib/sync.js +41 -1
  65. package/node_modules/@llblab/pi-telegram/dist/lib/telegram-api.d.ts +9 -1
  66. package/node_modules/@llblab/pi-telegram/dist/lib/telegram-api.js +23 -3
  67. package/node_modules/@llblab/pi-telegram/dist/lib/thread-cleanup-manager.js +7 -2
  68. package/node_modules/@llblab/pi-telegram/dist/lib/threads.d.ts +2 -0
  69. package/node_modules/@llblab/pi-telegram/dist/lib/threads.js +68 -37
  70. package/node_modules/@llblab/pi-telegram/dist/lib/updates.d.ts +6 -4
  71. package/node_modules/@llblab/pi-telegram/dist/lib/updates.js +134 -61
  72. package/node_modules/@llblab/pi-telegram/dist/lib/workspace-admission.d.ts +9 -0
  73. package/node_modules/@llblab/pi-telegram/dist/lib/workspace-admission.js +49 -3
  74. package/node_modules/@llblab/pi-telegram/dist/lib/workspace-retirement.d.ts +77 -6
  75. package/node_modules/@llblab/pi-telegram/dist/lib/workspace-retirement.js +384 -8
  76. package/node_modules/@llblab/pi-telegram/dist/lib/workspace-slots.d.ts +3 -0
  77. package/node_modules/@llblab/pi-telegram/dist/lib/workspace-slots.js +6 -0
  78. package/node_modules/@llblab/pi-telegram/dist/package.json +1 -1
  79. package/node_modules/@llblab/pi-telegram/docs/architecture.md +21 -14
  80. package/node_modules/@llblab/pi-telegram/docs/multi-instance-bus.md +31 -10
  81. package/node_modules/@llblab/pi-telegram/docs/updates.md +2 -0
  82. package/node_modules/@llblab/pi-telegram/lib/bindings.ts +5 -7
  83. package/node_modules/@llblab/pi-telegram/lib/bus-follower.ts +69 -12
  84. package/node_modules/@llblab/pi-telegram/lib/bus-leader.ts +236 -94
  85. package/node_modules/@llblab/pi-telegram/lib/bus.ts +39 -9
  86. package/node_modules/@llblab/pi-telegram/lib/extension.ts +69 -2
  87. package/node_modules/@llblab/pi-telegram/lib/journal.ts +14 -0
  88. package/node_modules/@llblab/pi-telegram/lib/lifecycle.ts +23 -4
  89. package/node_modules/@llblab/pi-telegram/lib/locks.ts +32 -13
  90. package/node_modules/@llblab/pi-telegram/lib/paths.ts +29 -1
  91. package/node_modules/@llblab/pi-telegram/lib/polling.ts +2 -2
  92. package/node_modules/@llblab/pi-telegram/lib/queue.ts +2 -3
  93. package/node_modules/@llblab/pi-telegram/lib/sync.ts +45 -1
  94. package/node_modules/@llblab/pi-telegram/lib/telegram-api.ts +30 -2
  95. package/node_modules/@llblab/pi-telegram/lib/thread-cleanup-manager.ts +11 -3
  96. package/node_modules/@llblab/pi-telegram/lib/threads.ts +73 -36
  97. package/node_modules/@llblab/pi-telegram/lib/updates.ts +145 -78
  98. package/node_modules/@llblab/pi-telegram/lib/workspace-admission.ts +67 -4
  99. package/node_modules/@llblab/pi-telegram/lib/workspace-retirement.ts +465 -7
  100. package/node_modules/@llblab/pi-telegram/lib/workspace-slots.ts +7 -0
  101. package/node_modules/@llblab/pi-telegram/package.json +1 -1
  102. package/package.json +3 -3
@@ -141,6 +141,12 @@ export type TelegramWorkspaceRetirementFence =
141
141
  phase: "deletion-issued";
142
142
  deletionIssuedAtMs: number;
143
143
  })
144
+ | (TelegramWorkspaceRetirementFenceBase & {
145
+ destructiveKind?: "pressure-retirement";
146
+ phase: "deletion-rejected";
147
+ deletionIssuedAtMs: number;
148
+ rejectionConfirmedAtMs: number;
149
+ })
144
150
  | (TelegramWorkspaceRetirementFenceBase & {
145
151
  phase: "commit-ready";
146
152
  absenceConfirmedAtMs: number;
@@ -318,6 +324,14 @@ export interface TelegramWorkspaceAdmissionLedger {
318
324
  expected: TelegramWorkspaceRetirementFence,
319
325
  ) => TelegramWorkspaceRetirementFence;
320
326
  confirmThreadCleanupAbsence: TelegramWorkspaceAdmissionLedger["confirmRetirementAbsence"];
327
+ /** Caller must have exact transport proof of rejection, never merely target presence. */
328
+ confirmRetirementRejection: (
329
+ expected: TelegramWorkspaceRetirementFence,
330
+ ) => TelegramWorkspaceRetirementFence;
331
+ /** Caller must first durably withdraw the exact rejected intent, retaining its binding. */
332
+ completeRejectedRetirementFence: (
333
+ expected: TelegramWorkspaceRetirementFence,
334
+ ) => boolean;
321
335
  releaseUnissuedRetirementFence: (
322
336
  expected: TelegramWorkspaceRetirementFence,
323
337
  ) => boolean;
@@ -491,6 +505,12 @@ function normalizeFence(
491
505
  deletionIssuedAtMs: value.deletionIssuedAtMs,
492
506
  };
493
507
  }
508
+ if (value.phase === "deletion-rejected" &&
509
+ (value.destructiveKind === undefined || value.destructiveKind === "pressure-retirement") &&
510
+ isSafeTimestamp(value.deletionIssuedAtMs) && isSafeTimestamp(value.rejectionConfirmedAtMs)) {
511
+ return { ...base, destructiveKind: value.destructiveKind, phase: "deletion-rejected",
512
+ deletionIssuedAtMs: value.deletionIssuedAtMs, rejectionConfirmedAtMs: value.rejectionConfirmedAtMs };
513
+ }
494
514
  if (
495
515
  value.phase === "commit-ready" &&
496
516
  isSafeTimestamp(value.absenceConfirmedAtMs) &&
@@ -768,6 +788,10 @@ function areFencesEqual(
768
788
  ) {
769
789
  return left.deletionIssuedAtMs === right.deletionIssuedAtMs;
770
790
  }
791
+ if (left.phase === "deletion-rejected" && right.phase === "deletion-rejected") {
792
+ return left.deletionIssuedAtMs === right.deletionIssuedAtMs &&
793
+ left.rejectionConfirmedAtMs === right.rejectionConfirmedAtMs;
794
+ }
771
795
  return (
772
796
  left.phase === "commit-ready" &&
773
797
  right.phase === "commit-ready" &&
@@ -1519,6 +1543,9 @@ export function createTelegramWorkspaceAdmissionLedger(
1519
1543
  if (!areOwnersEqual(expected.owner, options.owner)) {
1520
1544
  authorityChanged("Telegram Workspace absence confirmation requires fence owner authority.");
1521
1545
  }
1546
+ if (expected.phase === "deletion-rejected") {
1547
+ authorityChanged("Rejected Telegram Workspace deletion cannot confirm absence.");
1548
+ }
1522
1549
  return transact((state) => {
1523
1550
  if (!state.fence || !isTelegramWorkspaceRetirementFence(state.fence)) {
1524
1551
  authorityChanged("Telegram Workspace retirement fence is absent or has another kind.");
@@ -1571,9 +1598,10 @@ export function createTelegramWorkspaceAdmissionLedger(
1571
1598
  });
1572
1599
  }
1573
1600
 
1574
- function completeRetirementFence(
1601
+ function completeDestructiveFence(
1575
1602
  expected: TelegramWorkspaceRetirementFence,
1576
- expectedKind: TelegramWorkspaceDeletionFenceKind = "pressure-retirement",
1603
+ expectedKind: TelegramWorkspaceDeletionFenceKind,
1604
+ requiredPhase: "commit-ready" | "deletion-rejected",
1577
1605
  ): boolean {
1578
1606
  validateExpectedFence(expected, options.profileKey);
1579
1607
  if (resolveTelegramWorkspaceDestructiveFenceKind(expected) !== expectedKind)
@@ -1588,14 +1616,47 @@ export function createTelegramWorkspaceAdmissionLedger(
1588
1616
  if (!areFencesEqual(state.fence, expected)) {
1589
1617
  authorityChanged("Telegram Workspace retirement fence authority changed.");
1590
1618
  }
1591
- if (state.fence.phase !== "commit-ready") {
1592
- authorityChanged("Telegram Workspace retirement commit is not ready.");
1619
+ if (state.fence.phase !== requiredPhase) {
1620
+ authorityChanged(requiredPhase === "commit-ready"
1621
+ ? "Telegram Workspace retirement commit is not ready."
1622
+ : "Telegram Workspace retirement rejection is not confirmed.");
1593
1623
  }
1594
1624
  delete state.fence;
1595
1625
  return { result: true, changed: true };
1596
1626
  });
1597
1627
  }
1598
1628
 
1629
+ function confirmRetirementRejection(expected: TelegramWorkspaceRetirementFence): TelegramWorkspaceRetirementFence {
1630
+ validateExpectedFence(expected, options.profileKey);
1631
+ if (resolveTelegramWorkspaceDestructiveFenceKind(expected) !== "pressure-retirement" ||
1632
+ !areOwnersEqual(expected.owner, options.owner) ||
1633
+ (expected.phase !== "deletion-issued" && expected.phase !== "deletion-rejected")) {
1634
+ authorityChanged("Telegram Workspace rejection requires exact issued retirement authority.");
1635
+ }
1636
+ return transact((state) => {
1637
+ const current = state.fence;
1638
+ if (!current || !isTelegramWorkspaceRetirementFence(current) || !areFenceBasesEqual(current, expected) ||
1639
+ (current.phase !== "deletion-issued" && current.phase !== "deletion-rejected") ||
1640
+ current.deletionIssuedAtMs !== expected.deletionIssuedAtMs ||
1641
+ (expected.phase === "deletion-rejected" && !areFencesEqual(current, expected))) {
1642
+ authorityChanged("Telegram Workspace retirement fence authority changed.");
1643
+ }
1644
+ if (current.phase === "deletion-rejected") return { result: cloneFence(current), changed: false };
1645
+ const rejected: TelegramWorkspaceRetirementFence = { ...current,
1646
+ destructiveKind: "pressure-retirement", phase: "deletion-rejected", rejectionConfirmedAtMs: getNowMs() };
1647
+ state.fence = rejected;
1648
+ return { result: cloneFence(rejected), changed: true };
1649
+ });
1650
+ }
1651
+
1652
+ function completeRetirementFence(expected: TelegramWorkspaceRetirementFence,
1653
+ expectedKind: TelegramWorkspaceDeletionFenceKind = "pressure-retirement") {
1654
+ return completeDestructiveFence(expected, expectedKind, "commit-ready");
1655
+ }
1656
+ function completeRejectedRetirementFence(expected: TelegramWorkspaceRetirementFence) {
1657
+ return completeDestructiveFence(expected, "pressure-retirement", "deletion-rejected");
1658
+ }
1659
+
1599
1660
  function adoptThreadCleanupFence(expected: TelegramWorkspaceRetirementFence,
1600
1661
  replacement: { owner: TelegramWorkspaceAdmissionOwner; leaderEpoch: number | string }) {
1601
1662
  return adoptRetirementFence(expected, replacement, "manual-thread-cleanup");
@@ -1635,6 +1696,8 @@ export function createTelegramWorkspaceAdmissionLedger(
1635
1696
  issueThreadCleanupDeletionPermit,
1636
1697
  confirmRetirementAbsence,
1637
1698
  confirmThreadCleanupAbsence,
1699
+ confirmRetirementRejection,
1700
+ completeRejectedRetirementFence,
1638
1701
  releaseUnissuedRetirementFence,
1639
1702
  releaseUnissuedThreadCleanupFence,
1640
1703
  completeRetirementFence,