@llblab/pi-kit 0.15.0 → 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.
- package/CHANGELOG.md +6 -0
- package/README.md +2 -2
- package/node_modules/@llblab/pi-state-flow/AGENTS.md +9 -9
- package/node_modules/@llblab/pi-state-flow/BACKLOG.md +0 -13
- package/node_modules/@llblab/pi-state-flow/CHANGELOG.md +15 -0
- package/node_modules/@llblab/pi-state-flow/README.md +7 -6
- package/node_modules/@llblab/pi-state-flow/dist/lib/config.d.ts +5 -2
- package/node_modules/@llblab/pi-state-flow/dist/lib/config.js +17 -16
- package/node_modules/@llblab/pi-state-flow/dist/lib/context.d.ts +8 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/context.js +24 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/continuation.js +4 -3
- package/node_modules/@llblab/pi-state-flow/dist/lib/durable.d.ts +1 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/durable.js +8 -3
- package/node_modules/@llblab/pi-state-flow/dist/lib/episode.d.ts +2 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/episode.js +4 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/extension.d.ts +5 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/extension.js +93 -35
- package/node_modules/@llblab/pi-state-flow/dist/lib/git.js +20 -23
- package/node_modules/@llblab/pi-state-flow/dist/lib/history.js +8 -4
- package/node_modules/@llblab/pi-state-flow/dist/lib/json.js +29 -3
- package/node_modules/@llblab/pi-state-flow/dist/lib/migration.js +34 -18
- package/node_modules/@llblab/pi-state-flow/dist/lib/protocol.js +14 -16
- package/node_modules/@llblab/pi-state-flow/dist/lib/query.d.ts +27 -1
- package/node_modules/@llblab/pi-state-flow/dist/lib/query.js +182 -10
- package/node_modules/@llblab/pi-state-flow/dist/lib/runtime.d.ts +2 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/runtime.js +34 -5
- package/node_modules/@llblab/pi-state-flow/dist/lib/snapshot.d.ts +5 -5
- package/node_modules/@llblab/pi-state-flow/dist/lib/snapshot.js +20 -24
- package/node_modules/@llblab/pi-state-flow/dist/lib/state.d.ts +6 -3
- package/node_modules/@llblab/pi-state-flow/dist/lib/state.js +5 -3
- package/node_modules/@llblab/pi-state-flow/dist/lib/status.js +1 -1
- package/node_modules/@llblab/pi-state-flow/dist/lib/storage.d.ts +2 -0
- package/node_modules/@llblab/pi-state-flow/dist/lib/storage.js +55 -20
- package/node_modules/@llblab/pi-state-flow/dist/lib/telegram.d.ts +8 -6
- package/node_modules/@llblab/pi-state-flow/dist/lib/telegram.js +10 -3
- package/node_modules/@llblab/pi-state-flow/dist/lib/transition.js +7 -3
- package/node_modules/@llblab/pi-state-flow/dist/package.json +1 -1
- package/node_modules/@llblab/pi-state-flow/dist/skills/state-flow-memory/SKILL.md +11 -3
- package/node_modules/@llblab/pi-state-flow/docs/README.md +1 -0
- package/node_modules/@llblab/pi-state-flow/docs/architecture.md +5 -3
- package/node_modules/@llblab/pi-state-flow/docs/filesystem-recovery.md +3 -2
- package/node_modules/@llblab/pi-state-flow/docs/lazy-state.md +504 -0
- package/node_modules/@llblab/pi-state-flow/docs/usage.md +11 -8
- package/node_modules/@llblab/pi-state-flow/lib/config.ts +18 -15
- package/node_modules/@llblab/pi-state-flow/lib/context.ts +24 -0
- package/node_modules/@llblab/pi-state-flow/lib/continuation.ts +4 -3
- package/node_modules/@llblab/pi-state-flow/lib/durable.ts +8 -4
- package/node_modules/@llblab/pi-state-flow/lib/episode.ts +5 -0
- package/node_modules/@llblab/pi-state-flow/lib/extension.ts +86 -34
- package/node_modules/@llblab/pi-state-flow/lib/git.ts +23 -22
- package/node_modules/@llblab/pi-state-flow/lib/history.ts +8 -4
- package/node_modules/@llblab/pi-state-flow/lib/json.ts +31 -3
- package/node_modules/@llblab/pi-state-flow/lib/migration.ts +33 -16
- package/node_modules/@llblab/pi-state-flow/lib/protocol.ts +14 -16
- package/node_modules/@llblab/pi-state-flow/lib/query.ts +173 -9
- package/node_modules/@llblab/pi-state-flow/lib/runtime.ts +32 -4
- package/node_modules/@llblab/pi-state-flow/lib/snapshot.ts +22 -25
- package/node_modules/@llblab/pi-state-flow/lib/state.ts +11 -6
- package/node_modules/@llblab/pi-state-flow/lib/status.ts +1 -1
- package/node_modules/@llblab/pi-state-flow/lib/storage.ts +46 -18
- package/node_modules/@llblab/pi-state-flow/lib/telegram.ts +19 -6
- package/node_modules/@llblab/pi-state-flow/lib/transition.ts +7 -3
- package/node_modules/@llblab/pi-state-flow/package.json +1 -1
- package/node_modules/@llblab/pi-state-flow/skills/state-flow-memory/SKILL.md +11 -3
- package/node_modules/@llblab/pi-telegram/AGENTS.md +1 -1
- package/node_modules/@llblab/pi-telegram/BACKLOG.md +1 -0
- package/node_modules/@llblab/pi-telegram/CHANGELOG.md +7 -0
- package/node_modules/@llblab/pi-telegram/README.md +1 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/bindings.d.ts +2 -1
- package/node_modules/@llblab/pi-telegram/dist/lib/bindings.js +2 -1
- package/node_modules/@llblab/pi-telegram/dist/lib/commands.d.ts +134 -2
- package/node_modules/@llblab/pi-telegram/dist/lib/commands.js +297 -16
- package/node_modules/@llblab/pi-telegram/dist/lib/delivery.d.ts +2 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/delivery.js +11 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/extension.js +68 -8
- package/node_modules/@llblab/pi-telegram/dist/lib/menu-settings.d.ts +4 -3
- package/node_modules/@llblab/pi-telegram/dist/lib/menu-settings.js +17 -13
- package/node_modules/@llblab/pi-telegram/dist/lib/pi.d.ts +2 -1
- package/node_modules/@llblab/pi-telegram/dist/lib/pi.js +1 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/routing.d.ts +1 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/routing.js +55 -5
- package/node_modules/@llblab/pi-telegram/dist/lib/thread-display.d.ts +23 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/thread-display.js +20 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/threads.d.ts +18 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/threads.js +152 -6
- package/node_modules/@llblab/pi-telegram/dist/lib/updates.d.ts +1 -0
- package/node_modules/@llblab/pi-telegram/dist/lib/updates.js +5 -3
- package/node_modules/@llblab/pi-telegram/dist/package.json +1 -1
- package/node_modules/@llblab/pi-telegram/docs/architecture.md +3 -3
- package/node_modules/@llblab/pi-telegram/docs/callback-namespaces.md +1 -1
- package/node_modules/@llblab/pi-telegram/docs/public-api.md +4 -3
- package/node_modules/@llblab/pi-telegram/docs/sections.md +2 -2
- package/node_modules/@llblab/pi-telegram/docs/ui-style.md +2 -1
- package/node_modules/@llblab/pi-telegram/docs/updates.md +1 -1
- package/node_modules/@llblab/pi-telegram/lib/bindings.ts +3 -0
- package/node_modules/@llblab/pi-telegram/lib/commands.ts +466 -21
- package/node_modules/@llblab/pi-telegram/lib/delivery.ts +15 -0
- package/node_modules/@llblab/pi-telegram/lib/extension.ts +77 -9
- package/node_modules/@llblab/pi-telegram/lib/menu-settings.ts +25 -10
- package/node_modules/@llblab/pi-telegram/lib/pi.ts +3 -0
- package/node_modules/@llblab/pi-telegram/lib/routing.ts +84 -17
- package/node_modules/@llblab/pi-telegram/lib/thread-display.ts +30 -0
- package/node_modules/@llblab/pi-telegram/lib/threads.ts +199 -6
- package/node_modules/@llblab/pi-telegram/lib/updates.ts +5 -2
- package/node_modules/@llblab/pi-telegram/package.json +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
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
|
+
|
|
5
11
|
## 0.15.0 - 2026-09-16
|
|
6
12
|
|
|
7
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.
|
package/README.md
CHANGED
|
@@ -14,8 +14,8 @@ Package links lead to the owning repositories for usage, documentation, issues,
|
|
|
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
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.
|
|
18
|
-
| [`@llblab/pi-telegram`](https://github.com/llblab/pi-telegram) | `0.
|
|
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.
|
|
@@ -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
|
|
14
|
-
- Keep runtime configuration and provenance separate from model-patchable semantic state. Persist session `config.json` for enablement/projection settings
|
|
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 `
|
|
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`
|
|
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 `
|
|
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
|
|
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
|
|
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
|

|
|
4
4
|
|
|
5
|
-
**
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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:
|
|
1
|
+
// Domain: repository-global State Flow configuration, independent of session runtime and semantic state.
|
|
2
2
|
import { lstatSync, readFileSync } from "node:fs";
|
|
3
|
-
import {
|
|
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
|
|
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
|
|
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(["
|
|
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
|
|
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,
|
|
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. */
|
|
@@ -10,6 +10,7 @@ const STATE_FILE = "state.json";
|
|
|
10
10
|
const CHECKPOINT_FILE = "checkpoint.json";
|
|
11
11
|
const PATCHES_FILE = "patches.jsonl";
|
|
12
12
|
const META_FILE = "meta.json";
|
|
13
|
+
const RUNTIME_FILE = "runtime.json";
|
|
13
14
|
/** Semantic files contain no runtime envelope; temporal boundaries and CWD ownership live in meta.json. */
|
|
14
15
|
export function serializeScopeStream(stream, scope, cwdIdentity) {
|
|
15
16
|
validateScopeStream(stream, scope);
|
|
@@ -113,7 +114,7 @@ export function temporalScopePaths(cwd, sessionId, scope, repositoryRoot, sessio
|
|
|
113
114
|
}
|
|
114
115
|
export function sessionRuntimePaths(cwd, sessionId, repositoryRoot, sessionKey = sessionId) {
|
|
115
116
|
const directory = sessionScopePaths(cwd, sessionId, repositoryRoot, sessionKey).directory;
|
|
116
|
-
return { config: join(directory, "config.json"), meta: join(directory, META_FILE) };
|
|
117
|
+
return { config: join(directory, "config.json"), runtime: join(directory, RUNTIME_FILE), meta: join(directory, META_FILE) };
|
|
117
118
|
}
|
|
118
119
|
/** Unsupported state.json presence never becomes an anchored checkpoint. */
|
|
119
120
|
export function loadScopeStream(cwd, sessionId, scope, repositoryRoot, sessionKey = sessionId) {
|
|
@@ -128,7 +129,7 @@ export function captureTemporalFileBases(cwd, sessionId, repositoryRoot, session
|
|
|
128
129
|
const paths = ["global", "cwd", "session"].flatMap((scope) => {
|
|
129
130
|
const pair = temporalScopePaths(cwd, sessionId, scope, repositoryRoot, sessionKey);
|
|
130
131
|
const runtime = scope === "session" ? sessionRuntimePaths(cwd, sessionId, repositoryRoot, sessionKey) : undefined;
|
|
131
|
-
return [pair.checkpoint, pair.patches, join(pair.directory, STATE_FILE), ...(runtime === undefined ? [pair.meta] : [runtime.config, runtime.meta])];
|
|
132
|
+
return [pair.checkpoint, pair.patches, join(pair.directory, STATE_FILE), ...(runtime === undefined ? [pair.meta] : [runtime.config, runtime.runtime, runtime.meta])];
|
|
132
133
|
});
|
|
133
134
|
return captureOwnedFileBases(paths, repositoryRoot);
|
|
134
135
|
}
|
|
@@ -151,6 +152,10 @@ export function temporalStateFileUpdates(cwd, sessionId, view, scopes, repositor
|
|
|
151
152
|
/** Merge authoritative owned leaves while preserving forward-compatible metadata siblings. */
|
|
152
153
|
export function serializeScopeMetadata(registry, stream, scope, cwdIdentity, existingSource) {
|
|
153
154
|
const existing = parseMetadataDocument(existingSource, `State Flow metadata`);
|
|
155
|
+
if (scope === "session") {
|
|
156
|
+
for (const key of ["identity", "lineage", "step", "specification", "validation", "bootstrap", "remotePublication", "revision", "temporalRevision", "publication"])
|
|
157
|
+
delete existing[key];
|
|
158
|
+
}
|
|
154
159
|
const sources = serializeScopeStream(stream, scope, cwdIdentity);
|
|
155
160
|
const value = {
|
|
156
161
|
...existing,
|
|
@@ -276,7 +281,7 @@ export function isStateFlowOwnedPath(candidate, repositoryRoot = getDurableRepos
|
|
|
276
281
|
return cwdKey(segments[0])
|
|
277
282
|
&& sessionKey(segments[1])
|
|
278
283
|
&& (segments[2] === STATE_FILE || segments[2] === CHECKPOINT_FILE || segments[2] === PATCHES_FILE
|
|
279
|
-
|| segments[2] === "config.json" || segments[2] === META_FILE);
|
|
284
|
+
|| segments[2] === "config.json" || segments[2] === RUNTIME_FILE || segments[2] === META_FILE);
|
|
280
285
|
}
|
|
281
286
|
return false;
|
|
282
287
|
}
|
|
@@ -6,3 +6,5 @@ export declare function resumeEpisode(snapshot: Snapshot, bootstrap: boolean): S
|
|
|
6
6
|
export declare function stopEpisode(snapshot: Snapshot): Snapshot;
|
|
7
7
|
/** Apply one user-run boundary while preserving checkpoint-owned runtime state. */
|
|
8
8
|
export declare function prepareRun(snapshot: Snapshot, prompt: string): boolean;
|
|
9
|
+
/** Retain the full prompt only while its run remains recoverable and unfinished. */
|
|
10
|
+
export declare function completeRun(snapshot: Snapshot): void;
|
|
@@ -25,3 +25,7 @@ export function prepareRun(snapshot, prompt) {
|
|
|
25
25
|
snapshot.meta.validation = undefined;
|
|
26
26
|
return true;
|
|
27
27
|
}
|
|
28
|
+
/** Retain the full prompt only while its run remains recoverable and unfinished. */
|
|
29
|
+
export function completeRun(snapshot) {
|
|
30
|
+
delete snapshot.meta.specification;
|
|
31
|
+
}
|
|
@@ -11,6 +11,11 @@ export interface StateFlowExtensionOptions {
|
|
|
11
11
|
telegram?: {
|
|
12
12
|
load?: StateFlowTelegramLoader;
|
|
13
13
|
};
|
|
14
|
+
/** Test/SDK capability override; repository config remains the Pi default. */
|
|
15
|
+
passive?: {
|
|
16
|
+
bootstrap?: boolean;
|
|
17
|
+
tools?: boolean;
|
|
18
|
+
};
|
|
14
19
|
}
|
|
15
20
|
export declare const PATCH_STATE_TOOL_NAME = "patch_state";
|
|
16
21
|
export declare const READ_STATE_TOOL_NAME = "read_state";
|