@llblab/pi-kit 0.14.1 → 0.16.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 (119) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +3 -3
  3. package/node_modules/@llblab/pi-codex-usage/CHANGELOG.md +5 -0
  4. package/node_modules/@llblab/pi-codex-usage/README.md +6 -0
  5. package/node_modules/@llblab/pi-codex-usage/index.ts +81 -7
  6. package/node_modules/@llblab/pi-codex-usage/package.json +1 -1
  7. package/node_modules/@llblab/pi-state-flow/AGENTS.md +9 -9
  8. package/node_modules/@llblab/pi-state-flow/BACKLOG.md +0 -13
  9. package/node_modules/@llblab/pi-state-flow/CHANGELOG.md +15 -0
  10. package/node_modules/@llblab/pi-state-flow/README.md +7 -6
  11. package/node_modules/@llblab/pi-state-flow/dist/lib/config.d.ts +5 -2
  12. package/node_modules/@llblab/pi-state-flow/dist/lib/config.js +17 -16
  13. package/node_modules/@llblab/pi-state-flow/dist/lib/context.d.ts +8 -0
  14. package/node_modules/@llblab/pi-state-flow/dist/lib/context.js +24 -0
  15. package/node_modules/@llblab/pi-state-flow/dist/lib/continuation.js +4 -3
  16. package/node_modules/@llblab/pi-state-flow/dist/lib/durable.d.ts +1 -0
  17. package/node_modules/@llblab/pi-state-flow/dist/lib/durable.js +8 -3
  18. package/node_modules/@llblab/pi-state-flow/dist/lib/episode.d.ts +2 -0
  19. package/node_modules/@llblab/pi-state-flow/dist/lib/episode.js +4 -0
  20. package/node_modules/@llblab/pi-state-flow/dist/lib/extension.d.ts +5 -0
  21. package/node_modules/@llblab/pi-state-flow/dist/lib/extension.js +93 -35
  22. package/node_modules/@llblab/pi-state-flow/dist/lib/git.js +20 -23
  23. package/node_modules/@llblab/pi-state-flow/dist/lib/history.js +8 -4
  24. package/node_modules/@llblab/pi-state-flow/dist/lib/json.js +29 -3
  25. package/node_modules/@llblab/pi-state-flow/dist/lib/migration.js +34 -18
  26. package/node_modules/@llblab/pi-state-flow/dist/lib/protocol.js +14 -16
  27. package/node_modules/@llblab/pi-state-flow/dist/lib/query.d.ts +27 -1
  28. package/node_modules/@llblab/pi-state-flow/dist/lib/query.js +182 -10
  29. package/node_modules/@llblab/pi-state-flow/dist/lib/runtime.d.ts +2 -0
  30. package/node_modules/@llblab/pi-state-flow/dist/lib/runtime.js +34 -5
  31. package/node_modules/@llblab/pi-state-flow/dist/lib/snapshot.d.ts +5 -5
  32. package/node_modules/@llblab/pi-state-flow/dist/lib/snapshot.js +20 -24
  33. package/node_modules/@llblab/pi-state-flow/dist/lib/state.d.ts +6 -3
  34. package/node_modules/@llblab/pi-state-flow/dist/lib/state.js +5 -3
  35. package/node_modules/@llblab/pi-state-flow/dist/lib/status.js +1 -1
  36. package/node_modules/@llblab/pi-state-flow/dist/lib/storage.d.ts +2 -0
  37. package/node_modules/@llblab/pi-state-flow/dist/lib/storage.js +55 -20
  38. package/node_modules/@llblab/pi-state-flow/dist/lib/telegram.d.ts +8 -6
  39. package/node_modules/@llblab/pi-state-flow/dist/lib/telegram.js +10 -3
  40. package/node_modules/@llblab/pi-state-flow/dist/lib/transition.js +7 -3
  41. package/node_modules/@llblab/pi-state-flow/dist/package.json +1 -1
  42. package/node_modules/@llblab/pi-state-flow/dist/skills/state-flow-memory/SKILL.md +11 -3
  43. package/node_modules/@llblab/pi-state-flow/docs/README.md +1 -0
  44. package/node_modules/@llblab/pi-state-flow/docs/architecture.md +5 -3
  45. package/node_modules/@llblab/pi-state-flow/docs/filesystem-recovery.md +3 -2
  46. package/node_modules/@llblab/pi-state-flow/docs/lazy-state.md +504 -0
  47. package/node_modules/@llblab/pi-state-flow/docs/usage.md +11 -8
  48. package/node_modules/@llblab/pi-state-flow/lib/config.ts +18 -15
  49. package/node_modules/@llblab/pi-state-flow/lib/context.ts +24 -0
  50. package/node_modules/@llblab/pi-state-flow/lib/continuation.ts +4 -3
  51. package/node_modules/@llblab/pi-state-flow/lib/durable.ts +8 -4
  52. package/node_modules/@llblab/pi-state-flow/lib/episode.ts +5 -0
  53. package/node_modules/@llblab/pi-state-flow/lib/extension.ts +86 -34
  54. package/node_modules/@llblab/pi-state-flow/lib/git.ts +23 -22
  55. package/node_modules/@llblab/pi-state-flow/lib/history.ts +8 -4
  56. package/node_modules/@llblab/pi-state-flow/lib/json.ts +31 -3
  57. package/node_modules/@llblab/pi-state-flow/lib/migration.ts +33 -16
  58. package/node_modules/@llblab/pi-state-flow/lib/protocol.ts +14 -16
  59. package/node_modules/@llblab/pi-state-flow/lib/query.ts +173 -9
  60. package/node_modules/@llblab/pi-state-flow/lib/runtime.ts +32 -4
  61. package/node_modules/@llblab/pi-state-flow/lib/snapshot.ts +22 -25
  62. package/node_modules/@llblab/pi-state-flow/lib/state.ts +11 -6
  63. package/node_modules/@llblab/pi-state-flow/lib/status.ts +1 -1
  64. package/node_modules/@llblab/pi-state-flow/lib/storage.ts +46 -18
  65. package/node_modules/@llblab/pi-state-flow/lib/telegram.ts +19 -6
  66. package/node_modules/@llblab/pi-state-flow/lib/transition.ts +7 -3
  67. package/node_modules/@llblab/pi-state-flow/package.json +1 -1
  68. package/node_modules/@llblab/pi-state-flow/skills/state-flow-memory/SKILL.md +11 -3
  69. package/node_modules/@llblab/pi-telegram/AGENTS.md +1 -1
  70. package/node_modules/@llblab/pi-telegram/BACKLOG.md +1 -0
  71. package/node_modules/@llblab/pi-telegram/CHANGELOG.md +12 -0
  72. package/node_modules/@llblab/pi-telegram/README.md +1 -0
  73. package/node_modules/@llblab/pi-telegram/dist/lib/activity.d.ts +2 -0
  74. package/node_modules/@llblab/pi-telegram/dist/lib/activity.js +12 -0
  75. package/node_modules/@llblab/pi-telegram/dist/lib/bindings.d.ts +3 -2
  76. package/node_modules/@llblab/pi-telegram/dist/lib/bindings.js +7 -2
  77. package/node_modules/@llblab/pi-telegram/dist/lib/commands.d.ts +134 -2
  78. package/node_modules/@llblab/pi-telegram/dist/lib/commands.js +297 -16
  79. package/node_modules/@llblab/pi-telegram/dist/lib/delivery.d.ts +2 -0
  80. package/node_modules/@llblab/pi-telegram/dist/lib/delivery.js +11 -0
  81. package/node_modules/@llblab/pi-telegram/dist/lib/extension.js +68 -8
  82. package/node_modules/@llblab/pi-telegram/dist/lib/menu-settings.d.ts +4 -3
  83. package/node_modules/@llblab/pi-telegram/dist/lib/menu-settings.js +17 -13
  84. package/node_modules/@llblab/pi-telegram/dist/lib/pi.d.ts +2 -1
  85. package/node_modules/@llblab/pi-telegram/dist/lib/pi.js +1 -0
  86. package/node_modules/@llblab/pi-telegram/dist/lib/queue.d.ts +2 -0
  87. package/node_modules/@llblab/pi-telegram/dist/lib/queue.js +5 -1
  88. package/node_modules/@llblab/pi-telegram/dist/lib/replies.d.ts +1 -0
  89. package/node_modules/@llblab/pi-telegram/dist/lib/replies.js +1 -0
  90. package/node_modules/@llblab/pi-telegram/dist/lib/routing.d.ts +1 -0
  91. package/node_modules/@llblab/pi-telegram/dist/lib/routing.js +59 -7
  92. package/node_modules/@llblab/pi-telegram/dist/lib/thread-display.d.ts +23 -0
  93. package/node_modules/@llblab/pi-telegram/dist/lib/thread-display.js +20 -0
  94. package/node_modules/@llblab/pi-telegram/dist/lib/threads.d.ts +18 -0
  95. package/node_modules/@llblab/pi-telegram/dist/lib/threads.js +152 -6
  96. package/node_modules/@llblab/pi-telegram/dist/lib/updates.d.ts +1 -0
  97. package/node_modules/@llblab/pi-telegram/dist/lib/updates.js +5 -3
  98. package/node_modules/@llblab/pi-telegram/dist/package.json +1 -1
  99. package/node_modules/@llblab/pi-telegram/docs/architecture.md +3 -3
  100. package/node_modules/@llblab/pi-telegram/docs/callback-namespaces.md +1 -1
  101. package/node_modules/@llblab/pi-telegram/docs/public-api.md +4 -3
  102. package/node_modules/@llblab/pi-telegram/docs/sections.md +2 -2
  103. package/node_modules/@llblab/pi-telegram/docs/ui-style.md +2 -1
  104. package/node_modules/@llblab/pi-telegram/docs/updates.md +1 -1
  105. package/node_modules/@llblab/pi-telegram/lib/activity.ts +14 -0
  106. package/node_modules/@llblab/pi-telegram/lib/bindings.ts +10 -2
  107. package/node_modules/@llblab/pi-telegram/lib/commands.ts +466 -21
  108. package/node_modules/@llblab/pi-telegram/lib/delivery.ts +15 -0
  109. package/node_modules/@llblab/pi-telegram/lib/extension.ts +77 -9
  110. package/node_modules/@llblab/pi-telegram/lib/menu-settings.ts +25 -10
  111. package/node_modules/@llblab/pi-telegram/lib/pi.ts +3 -0
  112. package/node_modules/@llblab/pi-telegram/lib/queue.ts +7 -1
  113. package/node_modules/@llblab/pi-telegram/lib/replies.ts +2 -0
  114. package/node_modules/@llblab/pi-telegram/lib/routing.ts +90 -19
  115. package/node_modules/@llblab/pi-telegram/lib/thread-display.ts +30 -0
  116. package/node_modules/@llblab/pi-telegram/lib/threads.ts +199 -6
  117. package/node_modules/@llblab/pi-telegram/lib/updates.ts +5 -2
  118. package/node_modules/@llblab/pi-telegram/package.json +1 -1
  119. package/package.json +4 -4
package/CHANGELOG.md CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  All notable changes to `@llblab/pi-kit` are documented here.
4
4
 
5
+ ## 0.16.0 - 2026-09-17
6
+
7
+ - `Canonical Knowledge Memory`: Advances the exact State Flow pin to `0.14.0`, making Global Lazy the sole canonical Knowledge store and removing the former Markdown Knowledge layer while preserving scoped semantic compilation and recovery.
8
+ - `Telegram Fresh Sessions`: Advances the exact Telegram pin to `0.49.0`, adding lifecycle-safe `/new` session replacement with durable update settlement, same-chat or same-Thread continuity, and terminal result notifications.
9
+ - `Package Cohort`: Confirms every other bundled package already matches its latest published npm version; the package set, resource inventory, and explicit load order remain unchanged.
10
+
11
+ ## 0.15.0 - 2026-09-16
12
+
13
+ - `Business Credit Usage`: Advances the exact Codex Usage pin to `0.10.0`, adding Business-account credit usage with normalized display, precise reset countdown updates, and cache reuse.
14
+ - `State Flow Recovery Delivery`: Advances the exact Telegram pin to `0.48.3`, suppressing duplicate preserved-answer recovery only when matching intermediate text was admitted in the same Telegram turn while preserving equal answers in later turns. Thread restore and reclaim also use the current Workspace display title.
15
+
5
16
  ## 0.14.1 - 2026-09-16
6
17
 
7
18
  - `State Flow Telegram Discovery Hotfix`: Advances the exact State Flow pin to `0.13.3`, restoring its Telegram main-menu control when Pi loads the compiled sibling extension layout while retaining package-export discovery and optional fail-open behavior. The package set and explicit load order remain unchanged.
package/README.md CHANGED
@@ -12,10 +12,10 @@ Package links lead to the owning repositories for usage, documentation, issues,
12
12
  | --- | ---: | --- |
13
13
  | [`@llblab/pi-actors`](https://github.com/llblab/pi-actors) | `0.53.0` | Inspectable local Runs, reusable Recipes, persistent tools, and delegation Skills |
14
14
  | [`@llblab/pi-clean-room`](https://github.com/llblab/pi-clean-room) | `0.1.1` | Isolated nested Pi TUI with explicitly selected extensions |
15
- | [`@llblab/pi-codex-usage`](https://github.com/llblab/pi-codex-usage) | `0.9.4` | Compact Codex/Spark subscription-limit status |
15
+ | [`@llblab/pi-codex-usage`](https://github.com/llblab/pi-codex-usage) | `0.10.0` | Compact Codex/Spark subscription-limit and Business credit-usage status |
16
16
  | [`@llblab/pi-grow-loop`](https://github.com/llblab/pi-grow-loop) | `0.8.1` | Visible continuation scheduling and bounded worker Skills |
17
- | [`@llblab/pi-state-flow`](https://github.com/llblab/pi-state-flow) | `0.13.3` | Incremental scoped state, context, and memory with semantic storage, compiled runtime delivery, safe compaction, exact publication, and reliable Telegram section discovery |
18
- | [`@llblab/pi-telegram`](https://github.com/llblab/pi-telegram) | `0.48.2` | Telegram companion with built runtime delivery, resilient follower promotion, truthful terminal queue counts, adaptive Thread display, exact queues, files, voice, controls, and Generative Apps guidance |
17
+ | [`@llblab/pi-state-flow`](https://github.com/llblab/pi-state-flow) | `0.14.0` | Incremental scoped state/context/memory compiler with Global Lazy as the canonical Knowledge store, compiled runtime delivery, safe compaction, and exact publication |
18
+ | [`@llblab/pi-telegram`](https://github.com/llblab/pi-telegram) | `0.49.0` | Telegram companion with native fresh-session replacement, adaptive Thread continuity, exact queues, files, voice, controls, and Generative Apps guidance |
19
19
  | [`@llblab/skills`](https://github.com/llblab/skills) | `1.15.0` | Portable workflows for engineering, review, design, context maintenance, and other focused tasks |
20
20
 
21
21
  Versions are exact by design. An upstream release does not change an installed kit until this repository explicitly advances the dependency and publishes a new kit version. Runtime defects and package-specific feature requests belong in the linked repository; package selection and kit installation issues belong here.
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.10.0: Business Credit Usage
4
+
5
+ - Added Business-account credit usage support for responses that do not expose Codex rate-limit windows. Impact: the statusline now shows rounded remaining credit percentage and an optional reset countdown while preserving existing rate-limit displays when both forms are available.
6
+ - Scheduled credit reset countdown redraws at their exact display boundaries and retained credits-only reports in the active cache. Impact: credit status remains locally responsive between API refreshes without displacing model-specific quota windows.
7
+
3
8
  ## 0.9.4: Responsive Quota Polling
4
9
 
5
10
  - Increased the automatic Codex quota refresh interval from 30 to 60 seconds. Impact: status values remain responsive down to the locally rendered seconds countdown while reducing repeated OpenAI requests, especially when several Pi instances are open.
@@ -68,6 +68,12 @@ Before the first usable report for the active quota bucket arrives, two half-hei
68
68
 
69
69
  When the weekly reset time is available, it follows either the single-window percentage or the dual-window bar. More than a day remains is shown in 144-minute day-tenth steps such as `7d`, `6.9d`, `6.6d`, `5.1d`, `5d`, `3.7d`, `3d`, `2d`, `1.9d`, `1.5d`, and `1.1d`, rounded upward to the next tenth. At 24 hours and below it switches to upward-rounded 6-minute hour-tenth steps such as `24h`, `23.7h`, `20.1h`, `20h`, `19.9h`, `1.4h`, `1.3h`, `1.2h`, `1.1h`, and `1h`. Under an hour it switches to floored minutes, and under a minute to seconds. After the reset timestamp passes, `0s` is held until the next successful quota refresh reports the new weekly window.
70
70
 
71
+ Business accounts that return credits instead of Codex rate-limit windows show the rounded remaining percentage. When the response includes a credit reset cycle, its countdown is shown after the percentage:
72
+
73
+ ```text
74
+ codex 81% 2.8d
75
+ ```
76
+
71
77
  When the 5-hour window is exhausted and exposes its own reset time, the statusline adds the 5-hour reset before the weekly reset:
72
78
 
73
79
  ```text
@@ -90,6 +90,12 @@ export type UsageQueryError = {
90
90
 
91
91
  export type CodexUsageReport = {
92
92
  snapshots: NormalizedRateLimitSnapshot[];
93
+ credits?: NormalizedCreditUsage;
94
+ };
95
+
96
+ export type NormalizedCreditUsage = {
97
+ remainingPercent: number;
98
+ resetAt?: number;
93
99
  };
94
100
 
95
101
  export type NormalizedRateLimitSnapshot = {
@@ -106,6 +112,8 @@ export type NormalizedRateLimitWindow = {
106
112
  type RateLimitStatusPayload = {
107
113
  rate_limit?: unknown;
108
114
  additional_rate_limits?: unknown;
115
+ credits?: unknown;
116
+ spend_control?: unknown;
109
117
  };
110
118
 
111
119
  type BackendAdditionalRateLimit = {
@@ -593,7 +601,10 @@ async function queryUsage(
593
601
  source === "pi-auth"
594
602
  ? await queryViaPiAuth(ctx, options.timeoutMs)
595
603
  : await queryViaCodexAppServer(options.timeoutMs);
596
- if (selectUsageSnapshot(report, activeUsageLimitId(model))) {
604
+ if (
605
+ selectUsageSnapshot(report, activeUsageLimitId(model)) ||
606
+ report.credits
607
+ ) {
597
608
  return { ok: true, report };
598
609
  }
599
610
  errors.push({
@@ -920,12 +931,56 @@ export function normalizeBackendPayload(
920
931
  }
921
932
  }
922
933
 
923
- if (snapshots.length === 0) {
934
+ const credits = normalizeBackendCredits(payload, _capturedAt);
935
+ if (snapshots.length === 0 && !credits) {
924
936
  throw new Error(
925
- "Codex usage endpoint returned no displayable rate-limit windows.",
937
+ "Codex usage endpoint returned no displayable rate-limit windows or credits.",
926
938
  );
927
939
  }
928
- return { snapshots };
940
+ return credits ? { snapshots, credits } : { snapshots };
941
+ }
942
+
943
+ function normalizeBackendCredits(
944
+ payload: RateLimitStatusPayload,
945
+ capturedAt: number,
946
+ ): NormalizedCreditUsage | undefined {
947
+ const spendControl = payload.spend_control as
948
+ | Record<string, unknown>
949
+ | undefined;
950
+ const individualLimit = spendControl?.individual_limit as
951
+ | Record<string, unknown>
952
+ | undefined;
953
+ const credits = payload.credits as Record<string, unknown> | undefined;
954
+ const limit = asNumber(individualLimit?.limit);
955
+ const used = asNumber(individualLimit?.used);
956
+ const remaining = asNumber(individualLimit?.remaining);
957
+ const resetAt = asResetTime(
958
+ [
959
+ individualLimit?.reset_at,
960
+ individualLimit?.resets_at,
961
+ individualLimit?.reset_time,
962
+ spendControl?.reset_at,
963
+ spendControl?.resets_at,
964
+ credits?.reset_at,
965
+ credits?.resets_at,
966
+ ],
967
+ individualLimit?.reset_after_seconds ?? spendControl?.reset_after_seconds,
968
+ capturedAt,
969
+ );
970
+ if (
971
+ limit === undefined ||
972
+ used === undefined ||
973
+ remaining === undefined ||
974
+ limit <= 0
975
+ )
976
+ return undefined;
977
+ const remainingPercent = Math.min(
978
+ 100,
979
+ Math.max(0, (remaining / limit) * 100),
980
+ );
981
+ return resetAt === undefined
982
+ ? { remainingPercent }
983
+ : { remainingPercent, resetAt };
929
984
  }
930
985
 
931
986
  function backendAdditionalLimitId(limit: BackendAdditionalRateLimit): string {
@@ -1103,7 +1158,9 @@ export function formatCodexUsageStatusValue(
1103
1158
  const model = typeof modelOrNow === "number" ? undefined : modelOrNow;
1104
1159
  const capturedNow = typeof modelOrNow === "number" ? modelOrNow : now;
1105
1160
  const snapshot = selectActiveUsageSnapshot(report, model);
1106
- if (!snapshot || (!snapshot.primary && !snapshot.secondary)) return undefined;
1161
+ if (!snapshot || (!snapshot.primary && !snapshot.secondary)) {
1162
+ return formatCreditUsage(report.credits, capturedNow);
1163
+ }
1107
1164
  if (!snapshot.primary || !snapshot.secondary) {
1108
1165
  const window = snapshot.primary ?? snapshot.secondary;
1109
1166
  if (!window) return undefined;
@@ -1130,6 +1187,17 @@ export function formatCodexUsageStatusValue(
1130
1187
  return countdown ? `${bar} ${countdown}` : bar;
1131
1188
  }
1132
1189
 
1190
+ function formatCreditUsage(
1191
+ credits: NormalizedCreditUsage | undefined,
1192
+ now: number,
1193
+ ): string | undefined {
1194
+ if (!credits) return undefined;
1195
+ const percentage = `${Math.round(credits.remainingPercent)}%`;
1196
+ return credits.resetAt
1197
+ ? `${percentage} ${formatResetCountdown(credits.resetAt, now)}`
1198
+ : percentage;
1199
+ }
1200
+
1133
1201
  export function formatWeeklyResetCountdown(
1134
1202
  report: CodexUsageReport,
1135
1203
  modelOrNow?: CodexUsageModel | number,
@@ -1167,7 +1235,10 @@ export function nextResetCountdownDelayMs(
1167
1235
  model?: CodexUsageModel,
1168
1236
  ): number | undefined {
1169
1237
  const snapshot = selectActiveUsageSnapshot(report, model);
1170
- const resetTimes = [weeklyWindow(snapshot)?.resetAt];
1238
+ const hasRateLimitWindow = Boolean(snapshot?.primary || snapshot?.secondary);
1239
+ const resetTimes = [
1240
+ hasRateLimitWindow ? weeklyWindow(snapshot)?.resetAt : report.credits?.resetAt,
1241
+ ];
1171
1242
  if (snapshot?.secondary && isQuotaWindowExhausted(snapshot.primary)) {
1172
1243
  resetTimes.push(snapshot.primary?.resetAt);
1173
1244
  }
@@ -1391,7 +1462,10 @@ export function canReuseCachedReport(
1391
1462
  report: CodexUsageReport,
1392
1463
  model: CodexUsageModel | undefined,
1393
1464
  ): boolean {
1394
- return selectActiveUsageSnapshot(report, model) !== undefined;
1465
+ return (
1466
+ selectActiveUsageSnapshot(report, model) !== undefined ||
1467
+ report.credits !== undefined
1468
+ );
1395
1469
  }
1396
1470
 
1397
1471
  export function isFullyAvailableReport(
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@llblab/pi-codex-usage",
3
- "version": "0.9.4",
3
+ "version": "0.10.0",
4
4
  "private": false,
5
5
  "description": "Minimal Pi extension that shows primary Codex ChatGPT subscription usage limits",
6
6
  "keywords": [
@@ -10,16 +10,16 @@
10
10
  - Correlate successful exact-path reads with the current ordinary global invalidation plan. Require each acquired stale source to have a compact compiler output at the same path in a global transition, reject model-authored provenance fields, and record the runtime-observed source hash plus current ordinary compiler revision in the global provenance registry. Compile routing descriptions by default, never raw Markdown or a full-file summary; preserve uncertainty and reserve richer compilations for reusable operational semantics.
11
11
  - Apply one materialized-first acquisition policy to every source: read only for a concrete relevant gap not covered by a sufficient compilation, an exact-source operation including edits, evidenced invalidation, contradiction/failure reconciliation, explicit request, or selection by bounded maintenance. New sessions, routine recall or activation, reassurance, and an index or description alone are not reasons to read. Changed hashes require rereading; prefer the smallest sufficient read.
12
12
  - Keep artifact maintenance opt-in, low-frequency, and side-effect free until a selected source is acquired. Select only otherwise-fresh artifacts old enough for maintenance, rank missing/unparseable `compiled_at` first then oldest timestamp and path, and enforce strict per-cycle read-count and source-byte ceilings. Treat source bytes as the conservative source-token upper bound. Never let maintenance displace correctness invalidation; use explicit invalidation refresh for full rebuilds and never mutate source files.
13
- - Load optional agent-level `state-flow.json` once per extension load/reload. Its `directory` selects the state store, `autoStart` defaults false for genuinely new sessions, `showSuccessfulPatches` defaults true for interactive successful-call JSON rendering, and `remotePublication` selects `off`, `turn-end`, or compatibility `transition`. State Flow always owns durable memory while enabled and global semantic memory is always available; these are invariants, not configuration switches. Keep runtime configuration and provenance outside model-patchable semantic state.
14
- - Keep runtime configuration and provenance separate from model-patchable semantic state. Persist session `config.json` for enablement/projection settings and `meta.json` for lineage, counters, branch identity, durable base, publication, migration metadata, and session-scope artifact provenance; global and CWD scopes own their artifact provenance in scope `meta.json`. Neither participates in scope overlay. New Pi checkpoints contain only a durable revision pointer, or `{disabled:true}` when no durable runtime exists on that branch. Preserve exact Git hashes for Git-backed revisions and give file-only current-cohort references an unambiguous distinct identity; file references use `file:<64 lowercase hex>`, bind the store root and complete scoped/runtime cohort, and must not pretend to provide arbitrary cold or branch history. Operationally unavailable references (including expired file cohorts, missing Git, and publication exclusion) retain selection rather than falling through to older disabled markers; malformed immutable targets remain a distinct recovery case; they are not a parallel authoritative semantic or config/meta store. Emit a disabled marker only from proven pre-runtime branch provenance; missing/invalid revisions and failed restoration do not establish that permission. Predecessor checkpoint/tail envelopes are read-only migration input, recognized only by their complete exact structure and converted explicitly through the normal lock/CAS publication path. Validate immutable pointer targets before acquiring the live publication basis; transient publication failures preserve the selected retry reference rather than choosing older semantic state. In Git mode, runtime `revision: "self"` resolves to the commit owning the config/meta pair, not an unrelated later repository commit. File publication uses explicit `publication: "files"` provenance and resolves the exact complete live cohort instead of claiming a Git owner. Use a distinct `meta.temporalRevision` when a runtime-only write selects older semantic scopes; restore their artifact provenance from that same revision and preserve live shared checkpoints, tails, and provenance during session config/meta writes. Persist publication intent as unconfirmed before pushing; reconcile that exact existing commit after restart rather than embedding an impossible self-hash or inventing semantic history.
13
+ - Load optional repository-global `config.json` from the canonical `<agentDir>/state-flow/` root once per extension load/reload. `autoStart` defaults false for genuinely new sessions, `passiveBootstrap` and `passiveTools` default true and remain independent of episode lifecycle, `showSuccessfulPatches` defaults true for interactive successful-call JSON rendering, and `remotePublication` selects `off`, `turn-end`, or compatibility `transition`; SDK embeddings may explicitly override the repository. State Flow always owns durable memory while enabled and global semantic memory is always available; these are invariants, not configuration switches. Keep global operator configuration, runtime configuration, and provenance outside model-patchable semantic state.
14
+ - Keep runtime configuration and provenance separate from model-patchable semantic state. Persist session `config.json` for enablement/projection settings, session `runtime.json` for lineage, counters, branch identity, durable base, publication, and migration metadata, and every scope's adjacent `meta.json` for temporal boundaries, ownership where applicable, and artifact provenance. None participates in scope overlay. Read the predecessor combined session `meta.json` only as migration input; the next normal CAS publication must write `runtime.json` and clean known runtime fields from semantic metadata. New Pi checkpoints contain only a durable revision pointer, or `{disabled:true}` when no durable runtime exists on that branch. Preserve exact Git hashes for Git-backed revisions and give file-only current-cohort references an unambiguous distinct identity; file references use `file:<64 lowercase hex>`, bind the store root and complete scoped/runtime cohort, and must not pretend to provide arbitrary cold or branch history. Operationally unavailable references (including expired file cohorts, missing Git, and publication exclusion) retain selection rather than falling through to older disabled markers; malformed immutable targets remain a distinct recovery case; they are not a parallel authoritative semantic or config/meta store. Emit a disabled marker only from proven pre-runtime branch provenance; missing/invalid revisions and failed restoration do not establish that permission. Predecessor checkpoint/tail envelopes are read-only migration input, recognized only by their complete exact structure and converted explicitly through the normal lock/CAS publication path. Validate immutable pointer targets before acquiring the live publication basis; transient publication failures preserve the selected retry reference rather than choosing older semantic state. In Git mode, runtime `revision: "self"` resolves to the commit owning the config/meta pair, not an unrelated later repository commit. File publication uses explicit `publication: "files"` provenance and resolves the exact complete live cohort instead of claiming a Git owner. Use a distinct `meta.temporalRevision` when a runtime-only write selects older semantic scopes; restore their artifact provenance from that same revision and preserve live shared checkpoints, tails, and provenance during session config/meta writes. Persist publication intent as unconfirmed before pushing; reconcile that exact existing commit after restart rather than embedding an impossible self-hash or inventing semantic history.
15
15
  - Overlay materialized state recursively in `global → cwd → session` order. Scope-local deletion removes only that scope's key so a lower-scope value becomes visible again; scope never changes instruction authority. Route branch/run-local continuation to session, project-local reusable state and Skill artifacts to CWD, and cross-project reusable state to global.
16
16
  - Reserve `state` for the runtime materialized semantic view. `checkpoint.json` contains only the canonical materialized semantic state, each nonblank `patches.jsonl` line contains only one semantic patch, and adjacent `meta.json` owns their checkpoint/tail boundaries plus CWD identity. For each scope, current state is exactly `materialize(checkpoint.json, patches.jsonl, meta.json)`: an older anchored checkpoint plus its ordered tail of at most seven materially effective semantic patches. On overflow, apply the oldest patch into the checkpoint, advance its `through` boundary, remove it, and append the new patch. Never truncate unapplied replay records or replay patches over an already-current snapshot.
17
17
  - Give every accepted semantic transition one opaque identity shared by all affected scope records, with explicit active causal lineage. A branch-local position can order identities but never acts as a global counter, substitutes for identity, or merges forks. Unchanged scopes contribute no record and remain unchanged at that boundary. Adopt revision-proven inherited streams at a new session origin without rewriting their checkpoints/tails; pre-origin coordinates are not one shared clock. A restored branch adopts current proven live shared streams it does not modify at a fresh origin while preserving its selected session layer; a shared scope the accepted transition actually changes must still match its selected basis or fail closed naming that scope. Reconciliation adoption is not a fabricated semantic transition, parent link, or retry loop. True semantic no-ops and origin adoption do not advance semantic history.
18
- - Define `state[n]` and `state.global[n]`, `state.cwd[n]`, `state.session[n]` at the same nth previous accepted transition boundary in the active lineage, never the nth local patch of each scope. Guarantee offsets zero through seven once the lineage has seven proven transitions; report earlier-than-origin history as unavailable for new/migrated lineages and reject offsets beyond seven on the hot interface. Reconstruct scopes at one target before overlaying them.
19
- - Keep historical reads lazy through the smallest runtime/model read interface. Normal inference gets only current effective state and useful bounded compact transition context, never eight full snapshots. `patch_state` is the sole semantic mutation tool. `read_state` resolves current-as-index-zero aliases for effective/scoped materializations and scope-local retained accepted patches; materialization indices share the composed causal lineage while `patches[n]` walks the selected scope's retained patch tail. The prior offset/scope form remains a compatibility input and cannot combine with `path`. Reads return the exact boundary and never publish, append a checkpoint, or advance history. Both tools follow branch enablement and host tool restrictions; the patch barrier blocks reader siblings too. Live/cached checkpoint plus tails own the hot path; use Git for branch restoration and explicit cold inspection, not to rebuild current state on every inference.
20
- - Store runtime state in its own directory with optional Git durability, defaulting to `state-flow/` beneath Pi's configured agent directory (`~/.pi/agent/state-flow/` normally), independently from the Knowledge Markdown source root. Use exactly these owned paths: `checkpoint.json`, `patches.jsonl`, and `meta.json` for global; `<cwd-key>/checkpoint.json`, `<cwd-key>/patches.jsonl`, and `<cwd-key>/meta.json` for CWD; `<cwd-key>/<session-key>/checkpoint.json`, `patches.jsonl`, `config.json`, and `meta.json` for session. Do not create `.state-flow`, `scopes`, or another storage/history namespace. Mirror Pi's native CWD session-directory encoding and JSONL-basename session key (deriving `<header timestamp>_<UUID>` for in-memory sessions), while retaining separately verifiable canonical identity provenance in owned state. Keep the UUID authoritative, reject unsafe segments and mismatches rather than selecting another scope, and use CWD `meta.json` ownership to fail closed on Pi-name collisions.
18
+ - Define `effective[n]`, `global[n]`, `cwd[n]`, and `session[n]` at the same nth previous accepted transition boundary in the active lineage, never the nth local patch of each scope. Guarantee offsets zero through seven once the lineage has seven proven transitions; report earlier-than-origin history as unavailable for new/migrated lineages and reject offsets beyond seven on the hot interface. Reconstruct scopes at one target before overlaying them.
19
+ - Keep historical reads lazy through the smallest runtime/model read interface. Normal inference gets only current effective state and useful bounded compact transition context, never eight full snapshots. `patch_state` is the sole semantic mutation tool. `read_state` treats unscoped semantic paths as current effective aliases, accepts explicit effective/scoped materializations and scope-local retained accepted patches, and rejects the retired top-level `state` segment; materialization indices share the composed causal lineage while `patches[n]` walks the selected scope's retained patch tail. The public reader accepts only `path` or `paths`; temporal offsets and scope selection are expressed in path syntax. Reads return the exact boundary and never publish, append a checkpoint, or advance history. Both tools follow branch enablement and host tool restrictions; the patch barrier blocks reader siblings too. Live/cached checkpoint plus tails own the hot path; use Git for branch restoration and explicit cold inspection, not to rebuild current state on every inference.
20
+ - Store runtime state in its own directory with optional Git durability, defaulting to `state-flow/` beneath Pi's configured agent directory (`~/.pi/agent/state-flow/` normally), independently from the Knowledge Markdown source root. Use exactly these owned paths: `checkpoint.json`, `patches.jsonl`, and `meta.json` for global; `<cwd-key>/checkpoint.json`, `<cwd-key>/patches.jsonl`, and `<cwd-key>/meta.json` for CWD; `<cwd-key>/<session-key>/checkpoint.json`, `patches.jsonl`, `meta.json`, `config.json`, and `runtime.json` for session. Do not create `.state-flow`, `scopes`, or another storage/history namespace. Mirror Pi's native CWD session-directory encoding and JSONL-basename session key (deriving `<header timestamp>_<UUID>` for in-memory sessions), while retaining separately verifiable canonical identity provenance in owned state. Keep the UUID authoritative, reject unsafe segments and mismatches rather than selecting another scope, and use CWD `meta.json` ownership to fail closed on Pi-name collisions.
21
21
  - Classify every filesystem cohort before recovery: complete valid evidence is usable; total absence is recoverable only from an explicit semantic default or exact surviving authority; partial, malformed, contradictory, or authority-losing evidence fails closed at the smallest dependent capability. A wholly absent untouched global/CWD checkpoint-tail pair is current empty shared reality and must not resurrect selected cold values; a patch targeting that disappeared scope is stale and must fail for reinference. Missing provenance means unavailable freshness, not semantic corruption. Perform every repair through normal locked/CAS publication, never ad-hoc writes.
22
- - Support exactly one storage migration: complete predecessor checkpoint/tail envelopes across every owner-proven session in the configured store convert into semantic-only checkpoint/tail files plus temporal `meta.json` through one normal locked/CAS publication. Replace a Git-backed store's history with one new root commit for the complete migrated tree; apply the same cohort without Git in file-only mode. `state.json`, pre-0.4 hashed layouts, and semantic Pi checkpoint envelopes are unsupported and never become recovery authority. Exercise migrations in temporary repositories rather than modifying the user's active data during development.
22
+ - Support the release-owned storage migration chain through the migration domain: complete predecessor checkpoint/tail envelopes convert into semantic-only checkpoint/tail files plus temporal `meta.json`, and the 0.13 → 0.14 step splits every owner-proven session's combined `meta.json` into scope-only `meta.json` plus branch/run `runtime.json`. Execute the applicable steps through one normal locked/CAS publication. Replace a Git-backed semantic-envelope store's history with one new root commit for the complete migrated tree; apply the same cohort without Git in file-only mode. `state.json`, pre-0.4 hashed layouts, and semantic Pi checkpoint envelopes are unsupported and never become recovery authority. Exercise migrations in temporary repositories rather than modifying the user's active data during development.
23
23
  - Read and write only regular non-symlink State Flow-owned files at those exact paths, publish each file by same-directory atomic rename, preserve arbitrary repository contents, and classify ownership exactly. Git acceptance follows the complete-delta isolated-index contract below. Retain opaque source bytes for file identity and rollback, not decoded-text reconstructions. Use validated structural JSON equality for in-process semantic comparisons; reserve cryptographic hashes for compact identities that cross inference, persistence, process, or source-freshness boundaries. Serialize cooperating Git publications through a common-Git-directory publication lock; low-level file helpers require caller exclusion. Recheck prepared bases before each replacement/deletion and restore only bytes still matching the publisher's own output. Preserve detected concurrent changes and report unresolved rollback conflicts; do not claim kernel-atomic multi-file CAS against nonparticipating writers. Markdown discovery uses its independently configured source root, defaulting to `knowledge/` beneath Pi's agent directory; a storage-root override must not redirect source discovery.
24
24
  - At instance initialization resolve the repository, CWD key, and session key; load each scope's anchored checkpoint and tail, materialize at the selected temporal boundary, then overlay `global → cwd → session`. Install cached view and publication basis atomically only after successful restoration/initialization; unavailable publication is an error, not a semantic no-op. Branch recovery may reuse one owner-bound, single-use inspection of the exact selected immutable Git revision, with a detached inspection snapshot and a freshly acquired live publication basis at installation. Revalidate mutable file cohorts, legacy snapshot fallbacks, and redirected runtime owners; never turn inspection into a long-lived revision or publication-basis cache. Preserve the selected revision across transient restore failure so an explicit start can retry it. A genuinely new session gets an empty session layer and inherits only global/CWD values; it must never reuse another same-CWD session layer. Explicit native fork adoption instead follows the [session-copy contract](docs/fork-contract.md): copy the proven source session checkpoint/tail and provenance into a distinct owner over current shared streams, without pruning shared provenance or modifying the parent. Use a fresh origin, preserve copied replay records, reject occupied live/HEAD targets, and publish/checkpoint the child only after CAS acceptance. Inherited parent pointers never authorize an empty reset; fence parent passive Stop projection across child reload.
25
25
  - Bind every loaded scope and active Pi branch/checkpoint to the corresponding State Flow Git revision. Resume and tree restoration must recover branch-correct runtime config and semantic layers from that revision without blindly importing Git `HEAD`; reading an older revision must use object-level Git reads and never reset or check out the shared repository worktree.
@@ -37,17 +37,17 @@
37
37
  - Agent-level opt-in `logging` appends local JSONL diagnostics for rejected `patch_state` attempts and preserved drafts plus fallback turns while turn resolution remains pending. Every rejected call retains its exact attempted arguments plus the precise error and, when available, tool identity, call id, resolution attempt, and terminal-eligibility state; successful patches are never logged. Preserve exact text blocks only where useful, reduce other blocks to structural identity, never duplicate reasoning bodies, and keep logging outside semantic state, scope metadata, checkpoints, and publication. Logging failure emits at most one warning and never changes resolution, enablement, or accepted state.
38
38
  - Recursively materialize patches immediately; empty objects preserve, nested object-key `null` deletes, and `null` anywhere in semantic state including arrays is invalid. This prohibition does not apply to runtime envelopes such as an origin's null parent. Persist runtime-normalized replay patches that exactly reproduce accepted state, including complete artifact replacement; runtime-owned provenance is stored in scope `meta.json` and is not part of semantic replay.
39
39
  - Do not impose project schemas, state or patch byte caps, dynamic growth pressure, observation envelopes, action authorization, action ledgers, or state-size limits.
40
- - Rotate the turn-stable specification on every user-initiated run, while runtime-triggered turn-resolution continuation remains inside that same run. Keep user-controlled specification text at user authority: never interpolate it into the system prompt; repeat it only in synthetic user runtime context. Treat materialized state in that message as fallible assistant-produced data whose transport role does not elevate it into user instructions.
40
+ - Rotate the turn-stable specification on every user-initiated run, while runtime-triggered turn-resolution continuation remains inside that same run. Persist the full specification only while that run is unfinished, then remove it atomically with accepted terminal response reconciliation. Keep user-controlled specification text at user authority: never interpolate it into the system prompt; repeat it only in synthetic user runtime context. Treat materialized state in that message as fallible assistant-produced data whose transport role does not elevate it into user instructions.
41
41
  - When enabled inside an existing session, retain Pi's active context for exactly one complete bootstrap run and require its `patch_state` resolution to migrate all future-relevant context.
42
42
  - Restore extension state from the active Pi session branch's checkpoint and recorded State Flow revision, not the full session entry list or current Git `HEAD`, on both startup and successful in-session tree navigation.
43
43
  - Render compact status as accent `state-flow` plus dim `#<step>`. `/state-flow-status` must distinguish session config/meta from semantic temporal materialization; show the CWD and session keys, step, active temporal head and State Flow revision, available hot-history depth, per-scope artifact/tail counts, discovered global Markdown stale reasons, and pending publication; and render only the effective global → CWD → session materialization as semantic JSON, without reading or dumping source bodies beyond path/hash discovery needed for freshness diagnostics. Distinguish selected retained tail counts from active history depth; inherited tails may predate the origin. When temporal materialization is unavailable, report unknown counts/freshness and unavailable state rather than inventing empty projections.
44
44
  - Explicit `/state-flow-start` creates the State Flow directory when missing and returns after locally usable runtime acceptance for normal `turn-end`/`off` policy. If Git is installed, initialize an exact-root Git repository when needed, including a populated file-only store, preserving all existing bytes and unrelated files; an ancestor repository is not a valid substitute. Skip full predecessor-format migration planning only when all exact legacy snapshot names are absent, and defer Markdown freshness discovery until before the next enabled inference. If Git is absent, use file persistence. Manual-mode startup/status/restore do not initialize Git; configured automatic start of a genuinely new session uses the same initialization as explicit start. Never create external accounts, remote repositories, credentials, or remote configuration; those remain operator-owned. Never auto-import, delete, or reset files/history in a previous Knowledge-backed store; old branch revisions require their original Git history to remain available in the selected store. `/state-flow-start` must initialize missing global, CWD, and current-session checkpoint/tail pairs plus session config/meta through compare-and-swap publication when required, enable only the current session branch, and bootstrap prior conversation when needed. Explicit start on a proven pre-runtime branch (no checkpoint or an ordinary-disabled marker) establishes an empty session origin rather than importing a later same-session layer; validate existing runtime identity, retain shared streams unchanged, and preserve later branch data in cold Git history. Ordinary new sessions remain manual unless agent-level `autoStart` is true; CWD materialization alone grants no automatic activation. Configured new sessions may initialize missing CWD state and receive distinct empty session layers while inheriting global/CWD values. Resumed and tree-selected branches restore their own config and temporal lineage, regardless of the global flag.
45
- - `/state-flow-stop` must persist only the current session/branch's `config.enabled = false` and necessary runtime provenance, preserving all semantic checkpoints/tails and creating no semantic transition. Retain a frozen handoff plus the active user-run trajectory (including later tool results), post-stop conversation, and foreign context-bearing custom messages across same-physical-session reload/resume/tree. Exclude completed pre-run conversation and private State Flow validation feedback; idle Stop does not retain the completed run. Active restart replaces passive mode but uses that bounded boundary for its one migration run; new and forked physical sessions inherit neither projection. It does not rewrite agent-level `autoStart` or change its policy for future new sessions.
45
+ - `/state-flow-stop` returns to the configured passive bootstrap/tool combination and must persist only the current session/branch's `config.enabled = false` and necessary runtime provenance, preserving all semantic checkpoints/tails and creating no semantic transition. Retain a frozen handoff plus the active user-run trajectory (including later tool results), post-stop conversation, and foreign context-bearing custom messages across same-physical-session reload/resume/tree. Exclude completed pre-run conversation and private State Flow validation feedback; idle Stop does not retain the completed run. Active restart replaces passive mode but uses that bounded boundary for its one migration run; new and forked physical sessions inherit neither projection. It does not rewrite agent-level `autoStart` or change its policy for future new sessions.
46
46
  - After an accepted non-bootstrap run settles with no pending input, State Flow may request native manual compaction under a generation-private marker only when public `getContextUsage()` reports at least 24,000 tokens. Keep the complete latest accepted user iteration, store only revision/step identity in details, and never duplicate state in the summary. Unknown or smaller usage skips compaction; a benign native refusal releases the attempt for later work. Skip prefixes containing foreign custom context. Never customize user manual or native threshold/overflow compaction, discard unfinished pre-patch work, create a State Flow origin, or rewrite Pi's append-only JSONL/tree.
47
47
  - Keep the injected runtime protocol compact and normative; put rationale and extended explanation in README rather than the model prompt. Never parse or strip State Flow HTML comments; they are ordinary historical text, while foreign comment handling remains owned by other extensions.
48
48
  - Do not claim strict boundedness for state, the current run trajectory, the turn specification, or the external full trace.
49
49
  - Remain extension-agnostic in core semantics, storage, and inference: core modules never import, name, special-case, or encode policy for another extension or transport. One optional leaf presentation adapter (`lib/telegram.ts`) may import public `pi-telegram` membranes to mirror the live status on exactly one main-menu section button and expose the same start/stop affordances already owned by `state-flow-start` and `state-flow-stop`; it must fail open when the transport is absent or its registry is unready and must never alter core behavior.
50
- - Activate State Flow model tools only while enabled on the selected branch; preserve every unrelated active tool when toggling them. Keep mutation confined to `patch_state` and historical observation read-only.
50
+ - Activate State Flow model tools while an episode is enabled or passive tools are configured; preserve every unrelated active tool when toggling them. Passive reads never initialize storage, while an explicit passive patch may initialize or migrate storage without enabling episode barriers, continuation, or compaction. Keep mutation confined to `patch_state` and historical observation read-only.
51
51
  - Keep `.github/workflows/release.yml` as the sole version-tag release owner: it validates immutable tag identity, publishes through npm Trusted Publisher with provenance, verifies the public package, and only then creates the GitHub Release. Keep package, lockfile, tag, and changelog versions aligned; never add a long-lived npm token fallback.
52
52
  - Keep opt-in performance executables and workers in top-level `benchmarks/`; their correctness regressions stay in `tests/`. Benchmark workloads may reuse synthetic test fixtures, remain excluded from runtime packaging, and retain source-bound measurement identities across relocations.
53
53
  - Run `npm run validate` after retained code changes, then run the canonical ABCd context validator after context edits.
@@ -1,16 +1,3 @@
1
1
  # BACKLOG
2
2
 
3
3
  Completed release work belongs in [CHANGELOG.md](CHANGELOG.md).
4
-
5
- ## Candidate evolution
6
-
7
- - [ ] `Default passive memory access`: Separate memory availability from the active State Flow episode lifecycle. A normal installation defaults to both passive state bootstrap and `read_state`/`patch_state` tools, while automatic terminal compaction, iteration continuation, and active episode semantics remain gated behind `/state-flow-start`.
8
- - Configuration: control passive bootstrap and passive tools independently, yielding all four supported combinations: both off, bootstrap only, tools only, or both on (default). Fully off must add no state projection or tools to model context.
9
- - Passive bootstrap: project existing effective durable state without creating scopes, migrating storage, publishing changes, starting an episode, or promising automatic continuation. Name this separately from active episode/bootstrap semantics.
10
- - Passive tools: `read_state` remains read-only; an explicit `patch_state` may initialize or migrate the required durable runtime and publish only the requested semantic change, but must not activate terminal compaction or future automatic iterations.
11
- - Lifecycle: `/state-flow-start` promotes passive access into the existing active episode behavior. `/state-flow-stop` returns to the configured passive combination rather than overriding it globally.
12
- - Acceptance: cover all four configuration combinations, fresh and existing stores, explicit passive patch publication, unsupported-storage failure, start/stop transitions, tool/context visibility, and proof that passive turns never run terminal compaction.
13
- - Status: accepted direction, not implemented. Requires a dedicated release contract.
14
- - [ ] `Pi Telegram submenu state analyzer`: Extend the State Flow Telegram section with a read-only analyzer view over the same diagnostics `/state-flow-status` already reports (branch mode, temporal head and hot depth, scope keys, retained tails, artifact freshness, publication). The operator deliberately deferred this beyond the 0.9.0 control surface.
15
- - Boundary: presentation only. Reuse existing status diagnostics; no new semantic mode, and never mutate state from the analyzer view.
16
- - Status: candidate, not scheduled. Do not start without a dedicated release contract.
@@ -4,6 +4,21 @@
4
4
 
5
5
  ## Unreleased
6
6
 
7
+ ## 0.14.0: Passive and progressive memory
8
+
9
+ - `Default passive memory`: Repository-root configuration now adds independently configurable passive bootstrap and `read_state`/`patch_state` access, both enabled by default. Passive reads project durable memory without mutation; explicit patches may materialize storage while episode barriers, continuation, response reconciliation, and compaction remain inactive. Start promotes to active semantics and Stop returns to passive mode.
10
+ - `Bounded array ranges`: Added strict half-open `[start:end]` selectors to `read_state` value and patch paths, with `[start..end]` accepted as a forgiving fallback spelling. Ranges are zero-based, must fit fully within the selected array, preserve ordered batch semantics, and never truncate silently.
11
+ - `Direct read paths`: Removed the redundant top-level `state` segment and legacy public `offset`/`scope` inputs. `read_state` now accepts only `path` or `paths`; unscoped semantic paths read the current effective overlay, while `effective`, `global`, `cwd`, and `session` select overlay or ownership. The injected model protocol is 25% shorter while retaining its normative contract.
12
+ - `Lazy semantic plane`: Added scope-local ordinary-JSON `lazy` state under the existing atomic temporal lineage. Ordinary projections omit lazy bodies but expose a bounded root hint; explicit scoped, effective, historical, value, and keys reads resolve lazy data through `read_state`. Telegram inspection now exposes `lazy` and represents the state step with native rich-text code rather than visible Markdown delimiters.
13
+ - `Lazy durability`: Preserved lazy values through predecessor-envelope migration, exact Git and file-only restoration, and native session forks. Invalid lazy state and stale-basis hot-plus-lazy publication now fail before changing retained hot or lazy semantics. Local incompressible-payload measurements found roughly linear current-layout growth and sub-0.5-second publication/restoration through 1 MiB, so this release keeps lazy data co-located with canonical scope semantics rather than adding speculative sharding.
14
+ - `Indexed array patches`: Extended recursive `patch_state` semantics so canonical `"[N]"` selectors update existing array elements, including nested object and array elements, while invalid indices or indexed deletion reject the complete atomic cohort.
15
+ - `Progressive historical reads`: Extended `read_state` with arbitrary path-intersected semantic `patch` projection, including ordered all-or-error batches and effective-state change projection without exposing temporal metadata.
16
+ - `Session storage ownership`: Split branch/run recovery into session `runtime.json`, leaving every scope's `meta.json` symmetric around temporal boundaries and artifact provenance. The migration domain now explicitly detects and atomically upgrades every owner-proven 0.13 session to the 0.14 contract through normal CAS publication; full specifications are removed after accepted terminal reconciliation.
17
+
18
+ ## 0.13.4: Concurrent publication hotfix
19
+
20
+ - `Publication contention`: A publisher now waits briefly for a cooperating live State Flow process to release the storage or shared Git lock, preventing transient concurrent `patch_state` calls from failing while preserving explicit errors for interrupted, malformed, reentrant, or prolonged lock ownership.
21
+
7
22
  ## 0.13.3: Telegram section discovery hotfix
8
23
 
9
24
  - `Telegram section discovery`: The compiled extension now resolves the sibling pi-telegram public sections membrane from its compiled layout as well as the package export, restoring the State Flow control in the Telegram main menu without making Telegram a core dependency.
@@ -2,9 +2,9 @@
2
2
 
3
3
  ![pi-state-flow banner](https://raw.githubusercontent.com/llblab/pi-state-flow/main/banner.jpg)
4
4
 
5
- **Working memory for Pi, carried with the session.**
5
+ **Incremental scoped context/memory compiler for Pi.**
6
6
 
7
- Keep decisions, constraints, verified findings, and next steps without sending every completed tool exchange back to the model. State Flow lets the agent maintain explicit state; Pi still owns the conversation, the native tool loop, and the complete inspectable trace.
7
+ Keep decisions, constraints, verified findings, and next steps without sending every completed tool exchange back to the model. State Flow compiles curated context and memory into explicit state; Pi still owns the conversation, the native tool loop, and the complete inspectable trace.
8
8
 
9
9
  > Inspired by [SKILL.state](https://arxiv.org/html/2608.26263v2).
10
10
 
@@ -51,22 +51,23 @@ Continue working normally. The agent receives the state protocol and uses `patch
51
51
  - `/state-flow-status`: Inspect the selected state, history, artifact freshness, and publication status.
52
52
  - `/state-flow-stop`: Disable updates on this branch without deleting retained state.
53
53
 
54
- State Flow is **opt-in**. Starting in an existing conversation keeps its active context for one migration run. To enable genuinely new sessions automatically, set `"autoStart": true` in the optional [configuration](docs/usage.md#configuration).
54
+ Active State Flow episodes remain **opt-in**, while passive durable memory bootstrap and tools are available by default. Passive turns never require `final:true`, continue automatically, or trigger State Flow compaction. Starting an active episode in an existing conversation keeps its context for one migration run; set `"autoStart": true` to promote genuinely new sessions automatically. See [configuration](docs/usage.md#configuration).
55
55
 
56
56
  ## What carries forward
57
57
 
58
- The same four fields exist at every scope:
58
+ The same semantic planes exist at every scope:
59
59
 
60
60
  - `contract`: Requirements, decisions, constraints, and interface commitments.
61
61
  - `working`: Observations, results, unresolved questions, and what to do next.
62
62
  - `artifacts`: Source-addressed descriptions and reusable compiled knowledge.
63
63
  - `response`: The latest complete answer, captured by the runtime.
64
+ - `lazy`: Durable, versioned memory omitted from ordinary context until explicitly read.
64
65
 
65
- Memory overlays **global → project CWD → session**. Put reusable cross-project knowledge in global, project knowledge in CWD, and private task continuation in session.
66
+ Memory overlays **global → project CWD → session**. Put reusable cross-project knowledge in global, project knowledge in CWD, and private task continuation in session. Hot planes carry what must matter now; `lazy` retains what may matter later without hydrating its body into every prompt.
66
67
 
67
68
  **Resuming an existing Pi session restores its selected State Flow state and enablement.** A genuinely new session starts with an empty session layer and inherits only shared global/CWD memory; it does not resume another session's private work. Tree navigation follows the selected branch, not whichever state happens to be at Git `HEAD`.
68
69
 
69
- The agent can inspect `state`/`state[0]` through `state[7]`: now and up to seven prior accepted transitions. Scoped paths such as `state.cwd[1]` use the same causal boundary; `state.global.patches[0]` reads the latest retained accepted patch for that scope. Git-backed stores retain older committed history separately.
70
+ The agent uses `read_state` for exact current or historical paths. Unscoped paths read the effective overlay; `global`, `cwd`, and `session` address ownership directly; `[n]` selects one of up to seven prior accepted transition boundaries. Bounded array ranges and `value`, `keys`, or `patch` projections support progressive reads without hydrating whole lazy collections. Git-backed stores retain older committed history separately.
70
71
 
71
72
  ## Boundaries worth knowing
72
73
 
@@ -1,11 +1,14 @@
1
1
  export interface StateFlowConfig {
2
+ /** Canonical State Flow repository. SDK callers may still override it explicitly. */
2
3
  directory: string;
3
4
  autoStart: boolean;
5
+ passiveBootstrap: boolean;
6
+ passiveTools: boolean;
4
7
  /** Opt-in local capture of rejected patch attempts and unresolved terminal drafts. */
5
8
  logging: boolean;
6
9
  /** Show successful patch_state arguments in the interactive tool row. */
7
10
  showSuccessfulPatches: boolean;
8
11
  remotePublication?: "off" | "turn-end" | "transition";
9
12
  }
10
- /** Read once at extension load/reload. Missing config uses defaults; invalid config never falls back. */
11
- export declare function loadStateFlowConfig(agentDir?: string): StateFlowConfig;
13
+ /** Read the repository-global config once at extension load/reload. Missing config uses defaults; invalid config never falls back. */
14
+ export declare function loadStateFlowConfig(agentDir?: string, repositoryRoot?: string): StateFlowConfig;
@@ -1,16 +1,18 @@
1
- // Domain: agent-level State Flow configuration, independent of session runtime and semantic state.
1
+ // Domain: repository-global State Flow configuration, independent of session runtime and semantic state.
2
2
  import { lstatSync, readFileSync } from "node:fs";
3
- import { homedir } from "node:os";
4
- import { dirname, resolve } from "node:path";
3
+ import { join } from "node:path";
5
4
  import { getAgentDir } from "@earendil-works/pi-coding-agent";
6
5
  import { getDurableRepositoryRoot } from "./durable.js";
7
6
  import { isObject } from "./json.js";
8
- /** Read once at extension load/reload. Missing config uses defaults; invalid config never falls back. */
9
- export function loadStateFlowConfig(agentDir = getAgentDir()) {
10
- const path = resolve(agentDir, "state-flow.json");
7
+ /** Read the repository-global config once at extension load/reload. Missing config uses defaults; invalid config never falls back. */
8
+ export function loadStateFlowConfig(agentDir = getAgentDir(), repositoryRoot = getDurableRepositoryRoot(agentDir)) {
9
+ const directory = repositoryRoot;
10
+ const path = join(directory, "config.json");
11
11
  const defaults = {
12
- directory: getDurableRepositoryRoot(agentDir),
12
+ directory,
13
13
  autoStart: false,
14
+ passiveBootstrap: true,
15
+ passiveTools: true,
14
16
  logging: false,
15
17
  showSuccessfulPatches: true,
16
18
  };
@@ -23,12 +25,16 @@ export function loadStateFlowConfig(agentDir = getAgentDir()) {
23
25
  catch (error) {
24
26
  throw new Error(`Cannot read State Flow configuration: ${path}`, { cause: error });
25
27
  }
26
- const allowed = new Set(["directory", "autoStart", "logging", "showSuccessfulPatches", "remotePublication"]);
28
+ const allowed = new Set(["autoStart", "passiveBootstrap", "passiveTools", "logging", "showSuccessfulPatches", "remotePublication"]);
27
29
  if (!isObject(value) || Object.keys(value).some((key) => !allowed.has(key))) {
28
30
  throw new Error(`State Flow configuration contains unknown settings: ${path}`);
29
31
  }
30
32
  if (Object.hasOwn(value, "autoStart") && typeof value.autoStart !== "boolean")
31
33
  throw new Error(`State Flow autoStart must be a boolean: ${path}`);
34
+ if (Object.hasOwn(value, "passiveBootstrap") && typeof value.passiveBootstrap !== "boolean")
35
+ throw new Error(`State Flow passiveBootstrap must be a boolean: ${path}`);
36
+ if (Object.hasOwn(value, "passiveTools") && typeof value.passiveTools !== "boolean")
37
+ throw new Error(`State Flow passiveTools must be a boolean: ${path}`);
32
38
  if (Object.hasOwn(value, "logging") && typeof value.logging !== "boolean")
33
39
  throw new Error(`State Flow logging must be a boolean: ${path}`);
34
40
  if (Object.hasOwn(value, "showSuccessfulPatches") && typeof value.showSuccessfulPatches !== "boolean")
@@ -36,16 +42,11 @@ export function loadStateFlowConfig(agentDir = getAgentDir()) {
36
42
  if (Object.hasOwn(value, "remotePublication") && value.remotePublication !== "off" && value.remotePublication !== "turn-end" && value.remotePublication !== "transition") {
37
43
  throw new Error(`State Flow remotePublication must be off, turn-end, or transition: ${path}`);
38
44
  }
39
- if (Object.hasOwn(value, "directory") && (typeof value.directory !== "string" || !value.directory.trim() || value.directory.includes("\0"))) {
40
- throw new Error(`State Flow directory must be a non-empty path: ${path}`);
41
- }
42
- const directory = value.directory;
43
- if (directory?.startsWith("~") && directory !== "~" && !directory.startsWith("~/"))
44
- throw new Error(`State Flow directory supports ~ or ~/ paths, not named-user expansion: ${path}`);
45
- const expanded = directory === "~" ? homedir() : directory?.startsWith("~/") ? resolve(homedir(), directory.slice(2)) : directory;
46
45
  return {
47
- directory: expanded === undefined ? defaults.directory : resolve(dirname(path), expanded),
46
+ directory,
48
47
  autoStart: value.autoStart === true,
48
+ passiveBootstrap: value.passiveBootstrap !== false,
49
+ passiveTools: value.passiveTools !== false,
49
50
  logging: value.logging === true,
50
51
  showSuccessfulPatches: value.showSuccessfulPatches !== false,
51
52
  ...(value.remotePublication === undefined ? {} : { remotePublication: value.remotePublication }),
@@ -5,6 +5,13 @@ import type { Snapshot } from "./snapshot.ts";
5
5
  import type { RehydrationPhase } from "./rehydration.ts";
6
6
  import { type MaterializedState } from "./state.ts";
7
7
  export declare const VALIDATION_MESSAGE_TYPE = "state-flow-validation";
8
+ type LazyValueKind = "array" | "boolean" | "null" | "number" | "object" | "string";
9
+ /** Fixed-budget navigation only: never place lazy bodies or partial key catalogs in baseline context. */
10
+ export declare function lazyNavigationHint(state: MaterializedState): {
11
+ available: boolean;
12
+ path: string;
13
+ keys?: Record<string, LazyValueKind>;
14
+ };
8
15
  /** Bounded context retained after semantic State Flow is stopped in this physical session. */
9
16
  export interface PassiveContinuation {
10
17
  startedAt: number;
@@ -21,3 +28,4 @@ export declare function currentRunTrajectory(messages: AgentMessage[], specifica
21
28
  messages: AgentMessage[];
22
29
  anchorTimestamp?: number;
23
30
  };
31
+ export {};
@@ -2,6 +2,29 @@ import { projectArtifactForModel } from "./artifact.js";
2
2
  import { canonicalJson } from "./json.js";
3
3
  import { projectStateForModel } from "./state.js";
4
4
  export const VALIDATION_MESSAGE_TYPE = "state-flow-validation";
5
+ const LAZY_HINT_PATH = "effective.lazy";
6
+ const LAZY_HINT_MAX_KEYS = 32;
7
+ const LAZY_HINT_MAX_JSON_CHARS = 1024;
8
+ function lazyValueKind(value) {
9
+ if (value === null)
10
+ return "null";
11
+ if (Array.isArray(value))
12
+ return "array";
13
+ if (typeof value === "object")
14
+ return "object";
15
+ return typeof value;
16
+ }
17
+ /** Fixed-budget navigation only: never place lazy bodies or partial key catalogs in baseline context. */
18
+ export function lazyNavigationHint(state) {
19
+ const base = { available: Object.hasOwn(state, "lazy"), path: LAZY_HINT_PATH };
20
+ if (!base.available || typeof state.lazy !== "object" || state.lazy === null || Array.isArray(state.lazy))
21
+ return base;
22
+ const entries = Object.entries(state.lazy);
23
+ if (entries.length > LAZY_HINT_MAX_KEYS)
24
+ return base;
25
+ const keys = Object.fromEntries(entries.map(([key, value]) => [key, lazyValueKind(value)]));
26
+ return JSON.stringify(keys).length <= LAZY_HINT_MAX_JSON_CHARS ? { ...base, keys } : base;
27
+ }
5
28
  export function syntheticUser(text) {
6
29
  return { role: "user", content: [{ type: "text", text }], timestamp: Date.now() };
7
30
  }
@@ -63,6 +86,7 @@ export function runtimeContextMessage(snapshot, state, recentTransitions = [], a
63
86
  const context = {
64
87
  specification: snapshot.meta.specification,
65
88
  state: projectStateForModel(state),
89
+ lazy_navigation: lazyNavigationHint(state),
66
90
  ...(rehydrationPhase === undefined ? {} : { knowledge_rehydration: { phase: rehydrationPhase } }),
67
91
  ...(artifactInvalidations.length === 0 ? {} : { artifact_invalidations: artifactInvalidations.map(({ path, reason }) => ({ path, reason })) }),
68
92
  ...(recentTransitions.length === 0 ? {} : { recent_transitions: projectRecentForModel(recentTransitions) }),
@@ -138,11 +138,12 @@ export function inspectStateFlowContinuationProvenance(header, repositoryRoot) {
138
138
  const paths = sessionRuntimePaths(header.cwd, header.id, repositoryRoot, sessionKey);
139
139
  try {
140
140
  const config = readRegular(paths.config);
141
+ const runtimeSource = readRegular(paths.runtime);
141
142
  const meta = readRegular(paths.meta);
142
- if (config === undefined && meta === undefined) {
143
+ if (config === undefined && runtimeSource === undefined && meta === undefined) {
143
144
  return { stateFlow: { enabled: false, restorable: true }, reason: "no State Flow session runtime" };
144
145
  }
145
- const runtime = parseSessionRuntime(config, meta, header.cwd, header.id);
146
+ const runtime = parseSessionRuntime(config, runtimeSource, header.cwd, header.id, meta);
146
147
  if (!runtime)
147
148
  return { stateFlow: { enabled: false, restorable: true }, reason: "no State Flow session runtime" };
148
149
  if (!runtime.config.enabled)
@@ -156,7 +157,7 @@ export function inspectStateFlowContinuationProvenance(header, repositoryRoot) {
156
157
  validateTemporalState({ lineage: runtime.meta.lineage, scopes: { global, cwd, session } });
157
158
  return { stateFlow: { enabled: true, restorable: true }, reason: "exact file-only runtime cohort is restorable" };
158
159
  }
159
- const runtimePath = relative(resolve(repositoryRoot), paths.meta);
160
+ const runtimePath = relative(resolve(repositoryRoot), runtimeSource === undefined ? paths.meta : paths.runtime);
160
161
  if (runtimePath.startsWith(".."))
161
162
  throw new Error("runtime provenance escapes repository");
162
163
  const owner = execFileSync("git", ["-C", repositoryRoot, "log", "-1", "--format=%H", "--", runtimePath], { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
@@ -37,6 +37,7 @@ export interface TemporalScopePaths {
37
37
  export declare function temporalScopePaths(cwd: string, sessionId: string, scope: StateScope, repositoryRoot: string, sessionKey?: string): TemporalScopePaths;
38
38
  export declare function sessionRuntimePaths(cwd: string, sessionId: string, repositoryRoot: string, sessionKey?: string): {
39
39
  config: string;
40
+ runtime: string;
40
41
  meta: string;
41
42
  };
42
43
  /** Unsupported state.json presence never becomes an anchored checkpoint. */