@llblab/pi-kit 0.38.2 → 0.38.3

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 (36) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/README.md +2 -2
  3. package/node_modules/@llblab/pi-state-flow/AGENTS.md +1 -1
  4. package/node_modules/@llblab/pi-state-flow/BACKLOG.md +11 -673
  5. package/node_modules/@llblab/pi-state-flow/CHANGELOG.md +18 -0
  6. package/node_modules/@llblab/pi-state-flow/README.md +8 -8
  7. package/node_modules/@llblab/pi-state-flow/dist/lib/extension.js +3 -6
  8. package/node_modules/@llblab/pi-state-flow/dist/lib/model-interface.js +2 -3
  9. package/node_modules/@llblab/pi-state-flow/dist/lib/semantic-module.d.ts +1 -1
  10. package/node_modules/@llblab/pi-state-flow/dist/lib/telegram.js +2 -6
  11. package/node_modules/@llblab/pi-state-flow/dist/package.json +2 -1
  12. package/node_modules/@llblab/pi-state-flow/dist/skills/state-flow-guide/SKILL.md +5 -5
  13. package/node_modules/@llblab/pi-state-flow/dist/skills/state-flow-memory/SKILL.md +1 -1
  14. package/node_modules/@llblab/pi-state-flow/docs/README.md +7 -7
  15. package/node_modules/@llblab/pi-state-flow/docs/architecture.md +11 -15
  16. package/node_modules/@llblab/pi-state-flow/docs/compatibility.md +12 -10
  17. package/node_modules/@llblab/pi-state-flow/docs/fork-contract.md +18 -16
  18. package/node_modules/@llblab/pi-state-flow/docs/lazy-state.md +13 -15
  19. package/node_modules/@llblab/pi-state-flow/docs/protocol-composition-decision.md +2 -2
  20. package/node_modules/@llblab/pi-state-flow/docs/public-module-contract.md +16 -6
  21. package/node_modules/@llblab/pi-state-flow/docs/scope-selection-contract.md +25 -23
  22. package/node_modules/@llblab/pi-state-flow/docs/semantic-compatibility-decision.md +14 -12
  23. package/node_modules/@llblab/pi-state-flow/docs/semantic-extensibility-decision.md +2 -2
  24. package/node_modules/@llblab/pi-state-flow/docs/semantic-handoff-contract.md +133 -15
  25. package/node_modules/@llblab/pi-state-flow/docs/semantic-memory-evaluation.md +5 -5
  26. package/node_modules/@llblab/pi-state-flow/docs/semantic-module-contract.md +5 -5
  27. package/node_modules/@llblab/pi-state-flow/docs/single-scope-interface-contract.md +2 -2
  28. package/node_modules/@llblab/pi-state-flow/docs/usage.md +33 -23
  29. package/node_modules/@llblab/pi-state-flow/lib/extension.ts +3 -7
  30. package/node_modules/@llblab/pi-state-flow/lib/model-interface.ts +2 -3
  31. package/node_modules/@llblab/pi-state-flow/lib/semantic-module.ts +1 -1
  32. package/node_modules/@llblab/pi-state-flow/lib/telegram.ts +2 -6
  33. package/node_modules/@llblab/pi-state-flow/package.json +2 -1
  34. package/node_modules/@llblab/pi-state-flow/skills/state-flow-guide/SKILL.md +5 -5
  35. package/node_modules/@llblab/pi-state-flow/skills/state-flow-memory/SKILL.md +1 -1
  36. package/package.json +2 -2
@@ -4,34 +4,34 @@
4
4
 
5
5
  ## Contract
6
6
 
7
- A physical Pi fork creates a fresh child session from its direct parent's **current** canonical session memory. State Flow does not depend on the Pi step the fork starts from:
7
+ A physical Pi fork creates a fresh child identity and inherits the source branch's captured mode and scopes. When Session participates and private acquisition is admitted, it copies its direct parent's **current** canonical Session memory. Off or Session-excluded forks defer private acquisition. State Flow does not depend on the Pi step the fork starts from:
8
8
 
9
9
  ```text
10
- child.global = current live global
11
- child.cwd = current live CWD
12
- child.session = parent session current head
10
+ selected child.global/cwd = current live selected shared owners
11
+ admitted child.session = direct-parent Session current head
12
+ excluded child.session = no hidden private semantic stream
13
13
  ```
14
14
 
15
- The adapter reads Pi's persisted direct-parent header, requires matching CWD and session identity, reads the parent's current memory and uses its head as the copied boundary. It never consults Git, a storage receipt or an older checkpoint revision.
15
+ At private acquisition, the adapter reads Pi's persisted direct-parent header, requires matching CWD and session identity, and admits the parent's current private stream. A Session-excluded child instead accepts selected shared access and child-owned deferred lifecycle proof without reading the parent header/private store. It never consults Git, a storage receipt or an older checkpoint revision.
16
16
 
17
17
  The child receives:
18
18
 
19
19
  - its own UUID, native session key, runtime metadata, and fresh lineage origin;
20
- - the parent's current session materialization and matching artifact provenance;
21
- - current live global/CWD values and provenance without rewinding them;
22
- - selected `mode` and bootstrap lifecycle state, with step reset to zero and no inherited unfinished specification or validation diagnostic.
20
+ - the parent's current Session materialization, matching artifact provenance and retained module descriptors when private copying is admitted;
21
+ - current live selected Global/CWD values and provenance without rewinding them;
22
+ - captured `mode` and `scopes`, with fresh step-zero/bootstrap lifecycle and no inherited unfinished specification or validation diagnostic. A later deferred private copy preserves the child's already accepted lifecycle fields.
23
23
 
24
24
  **What stays unchanged:**
25
25
 
26
26
  - The parent's private files and native trace remain unchanged. Later child session writes cannot modify the parent's private layer.
27
- - Applying a smaller configured `historyLimit` may fold excess shared tails during child acceptance under file-cohort CAS, without changing current shared materialization or provenance. Without retention reduction, the shared files remain unchanged too.
27
+ - Applying a smaller configured `historyLimit` may fold excess selected shared tails during child acceptance under file-cohort CAS, without changing current shared materialization or provenance. Without retention reduction, the shared files remain unchanged too.
28
28
  - Forking semantic memory does not clone or roll back project files or tool effects.
29
29
 
30
30
  **Artifact evidence is current-only, not a historical registry.** Because the child copies the parent's current head, current artifact semantics and their current provenance stay together; shared provenance remains live.
31
31
 
32
32
  ## Lifecycle and failure
33
33
 
34
- **Copying and acceptance.** `TemporalRuntime.withForkTransaction(source, lifecycle, action, signal?)`:
34
+ **All-owner library copying and acceptance.** The supported `TemporalRuntime.withForkTransaction(source, lifecycle, action, signal?)` contract remains:
35
35
 
36
36
  1. Pins source identity and the parent's current head boundary before waiting.
37
37
  2. Selects exact parent authority plus an unoccupied child under one awaited exclusion.
@@ -43,10 +43,10 @@ Cancellation or rejection cannot initialize an empty child. Failure after accept
43
43
  **Forking while Off:**
44
44
 
45
45
  - Parent-header acquisition and canonical copying are deferred. Only a child-owned pending-fork marker is appended to the native trace; it carries no semantic authority.
46
- - The marker survives cold extension reload and permits later explicit Passive/Active acquisition, which copies the parent's then-current memory subject to the same identity and occupied-child checks.
46
+ - The marker survives cold extension reload and permits later admitted Session acquisition under explicit Passive/Active policy, copying the parent's then-current private memory subject to the same identity and occupied-target checks. Shared-only enablement retains deferral rather than consuming private-copy authority.
47
47
  - Accepted initialization resets the marker.
48
48
 
49
- Memory-enabled native fork adoption and Start's fork retry use this transaction inside the extension's owned restoration lifetime. It publishes the fresh child origin before any runtime-only lifecycle write. Native evidence holds a publisher across fork adoption; it does not certify idle native Abort.
49
+ The native adapter composes the selected-scope ports below inside its owned restoration lifetime, rather than routing every fork through the all-owner library transaction. Fresh shared-only deferral publishes child lifecycle plus selected shared access without private copying; eager/deferred private acceptance validates its corresponding source and target before installing memory. Neither route grants idle native Abort a signal the host does not supply.
50
50
 
51
51
  **Retry and cancellation:**
52
52
 
@@ -64,7 +64,7 @@ Memory-enabled native fork adoption and Start's fork retry use this transaction
64
64
  - Navigating to an inherited parent step keeps current child-owned memory; it neither rewinds nor recopies parent data.
65
65
  - Child-owned checkpoints use ordinary current-memory reload/resume without rereading the parent header.
66
66
 
67
- **Before the first child-owned checkpoint:** cold recovery requires the explicit Off-deferred pending marker. Missing child files alone never authorize a parent recopy.
67
+ **Before private acquisition:** cold recovery requires child-owned pending-fork authority; an accepted shared-only child additionally retains its validated deferred lifecycle proof. Missing child files alone never authorize a parent copy or recopy.
68
68
 
69
69
  **Mode and projection:**
70
70
 
@@ -75,13 +75,15 @@ Memory-enabled native fork adoption and Start's fork retry use this transaction
75
75
 
76
76
  ## Internal selected-scope copy boundary
77
77
 
78
- The [selected-scope contract](scope-selection-contract.md#selected-parent-current-private-copy) now implements shared-only child deferral and eager/deferred private copy over selected streams. The native adapter must validate persisted direct-parent identity before exclusion and recheck current in-memory child/parent/policy ownership after waiting. The storage owner verifies only parent-current private files/lineage/provenance plus selected live shared inputs, never recursive ancestry or unrelated disabled owners. Parent bytes stay read-only; occupied, malformed, lost-acquired or already-acquired child evidence cannot become empty memory or authorize recopy.
78
+ The native [selected-scope contract](scope-selection-contract.md#selected-parent-current-private-copy), shipped in 0.27.0, implements shared-only child deferral and eager/deferred private copy over selected streams. The native adapter must validate persisted direct-parent identity before exclusion and recheck current in-memory child/parent/policy ownership after waiting. The storage owner verifies only parent-current private files/lineage/provenance plus selected live shared inputs, never recursive ancestry or unrelated disabled owners. Parent bytes stay read-only; occupied, malformed, lost-acquired or already-acquired child evidence cannot become empty memory or authorize recopy.
79
79
 
80
- These internal APIs return file receipts/sticky authority facts and install the [accepted selected cache](scope-selection-contract.md#accepted-selected-runtime-cache-and-reads) after durable acceptance. They do not yet replace the native all-owner `withForkTransaction` route described above, expose scope settings, or implement native pending-marker/selection-epoch attachment. Isolated selected-copy fixtures are local backend proof, not completed native selected-fork delivery.
80
+ Native `withSelectedDeferredForkTransaction` and `withSelectedForkCopyTransaction` compose the existing origin/current acceptance owner. They return file receipts/sticky authority facts and install the [accepted selected cache](scope-selection-contract.md#accepted-selected-runtime-cache-and-reads) only after durable acceptance; child classification precedes any parent lookup. Public mode-command scope overrides and native pending-marker/selection-lifetime attachment are implemented. The [M2 functional boundary](scope-selection-contract.md#m2-functional-acceptance-boundary) records actual native seven-selection/fork delivery separately from lower backend fixtures.
81
+
82
+ Copying uses the parent-current materialization and starts one fresh child aligned origin. Retained per-owner tail records may still be copied subject to `historyLimit`; they do not create earlier aligned child materializations. Current-only copying is not a claim that every historical patch byte is absent from child storage.
81
83
 
82
84
  ## Support boundary
83
85
 
84
- Supported copying requires a persisted regular parent session file, matching header UUID/CWD, current canonical scope/runtime files, and an available retained boundary. Arbitrary session search, UUID aliases, cross-CWD imports, in-memory-only parent locators, conversion of unsupported storage formats, unlimited history, and Git recovery are unsupported.
86
+ Private copying requires a persisted regular direct-parent session file, matching header UUID/CWD, current canonical private/runtime evidence, and an unoccupied child semantic target. A deferred lifecycle-only child must prove its own admitted pending authority; an acquired child uses child-current memory and never recopies. Arbitrary session search, UUID aliases, cross-CWD imports, in-memory-only parent locators, conversion of unsupported storage formats, unlimited history, and Git recovery are unsupported.
85
87
 
86
88
  ## Evidence
87
89
 
@@ -4,9 +4,9 @@ This document describes the implemented lazy-state contract. [BACKLOG.md](../BAC
4
4
 
5
5
  ## Thesis
6
6
 
7
- State Flow provides `lazy` as an object-root semantic plane in every scope's runtime view.
7
+ State Flow supports the optional object-root `lazy` plane in every participating scope.
8
8
 
9
- - It may be absent from stored state. Reads then use `{}` or values inherited through the effective overlay, without rewriting storage.
9
+ - It may be absent from stored state. Exact reads preserve that absence; an absent top-level lazy value returns `null`, while effective reads can inherit a selected broader owner's value. Only default-bearing internal/library compatibility views supply `{}`; no read rewrites storage.
10
10
  - Nested lazy values are ordinary JSON. They are durable and versioned with the same causal lineage as hot state, but excluded from ordinary baseline hydration.
11
11
 
12
12
  The model-facing surface remains small:
@@ -37,7 +37,7 @@ The model-facing surface remains small:
37
37
 
38
38
  ## Semantic model
39
39
 
40
- Runtime views select present documented semantic planes in intent-first order, omitting absent fields, empty responses and unknown fields:
40
+ Runtime views select present built-in planes in intent-first order, plus metadata v4-declared external roots under the [public module contract](public-module-contract.md), omitting absent fields and empty responses. The built-ins are:
41
41
 
42
42
  ```text
43
43
  global | CWD | session
@@ -45,14 +45,14 @@ global | CWD | session
45
45
  ├── strategy
46
46
  ├── tactics
47
47
  ├── artifacts
48
- ├── response (session-owned; empty structural slot in Global/CWD)
48
+ ├── response (new answers are Session-owned; optional on disk)
49
49
  └── lazy
50
50
  ```
51
51
 
52
52
  Hot planes:
53
53
 
54
- - `intents`, `strategy`, `tactics` and `artifacts` stay hot in every scope.
55
- - Session-owned `response` is also hot. New Global and CWD states use an empty structural slot, and stored scopes may omit it. Effective uses the highest-priority present response, and each newly accepted answer is written only in Session.
54
+ - Present `intents`, `strategy`, `tactics` and `artifacts` contribute hot memory from selected available owners.
55
+ - Active projects the highest-priority present nonempty `response`; Passive omits it automatically. New answers are written only in Active participating Session. No stored structural slot is required, and readable legacy Global/CWD answers do not grant new shared authorship.
56
56
  - `intents` may keep compact active direction while referring to large supporting detail in `lazy`.
57
57
 
58
58
  `lazy` differs only in projection policy:
@@ -138,7 +138,7 @@ Ownership evaluates canonical references after model anchoring. A sole-CWD model
138
138
  - missing targets;
139
139
  - keys outside the `read_state` key grammar `[A-Za-z_$][A-Za-z0-9_$-]*`, for example keys with spaces, dots or non-Latin letters.
140
140
 
141
- **Receipt.** `state_updates.cascaded` lists all owner-scoped targets cleared in the intermediate ownership phase, even if later authored writes recreate them, for example `["session.lazy.plans.x", "session.tactics.draft"]`. Paths only, never lazy bodies or deleted values. The list is deterministic (Global, CWD, Session, then each scope's cascade order), absent when no target cascaded, and never omitted as a predictable write. Nested lazy deletions are reported even when the top-level `lazy_navigation` catalog is unchanged.
141
+ **Receipt.** `state_updates.cascaded` lists targets cleared in the intermediate ownership phase, even if later authored writes recreate them. With multiple wanted owners paths stay scoped, for example `["session.lazy.plans.x", "session.tactics.draft"]`; with exactly one wanted owner they are relative, for example `["lazy.plans.x", "tactics.draft"]`. Canonical ownership and result details remain scoped. Paths only, never lazy bodies or deleted values. The list is deterministic (Global, CWD, Session, then each scope's cascade order), absent when no target cascaded, and never omitted as a predictable write. Nested lazy deletions are reported even when the top-level `lazy_navigation` catalog is unchanged.
142
142
 
143
143
  **Edge cases:**
144
144
 
@@ -151,7 +151,7 @@ Ownership evaluates canonical references after model anchoring. A sole-CWD model
151
151
 
152
152
  The explicit `effective.lazy` path recursively overlays `global.lazy → cwd.lazy → session.lazy` using the existing scope precedence and conflict semantics. It is read-only as an effective view and is not inserted into ordinary hot baseline state.
153
153
 
154
- Explicit paths such as `global.lazy`, `cwd.lazy`, and `session.lazy` preserve direct ownership access. Deleting a key from an upper scope reveals a lower-scope value exactly as ordinary scope-local deletion does. Hiding an inherited value without changing its owner is not a separate lazy feature.
154
+ Explicit paths such as `global.lazy`, `cwd.lazy`, and `session.lazy` preserve direct ownership access only for wanted, available owners; excluded-owner access rejects without widening selection. Deleting a key from an upper scope reveals a lower-scope value exactly as ordinary scope-local deletion does. Hiding an inherited value without changing its owner is not a separate lazy feature.
155
155
 
156
156
  Active obligations, current constraints, unresolved next actions, and facts required for the next correct action remain hot.
157
157
 
@@ -295,8 +295,7 @@ A multi-path value response is positional:
295
295
  {
296
296
  "meta": {
297
297
  "type": "object",
298
- "size": 3,
299
- "sources": ["global", "cwd"]
298
+ "size": 3
300
299
  },
301
300
  "keys": {
302
301
  "memory": "array",
@@ -306,7 +305,7 @@ A multi-path value response is positional:
306
305
  }
307
306
  ```
308
307
 
309
- For an explicitly scoped object, redundant ownership is omitted:
308
+ An explicitly scoped object uses the same structural-only metadata shape:
310
309
 
311
310
  ```json
312
311
  {
@@ -359,7 +358,6 @@ The read-level `meta` object is intentionally narrow and unrelated to persisted
359
358
  - `type` always.
360
359
  - `size` for objects, meaning immediate named-key count.
361
360
  - `length` for arrays and strings.
362
- - `sources` only when an effective view actually combines or resolves scope ownership.
363
361
 
364
362
  It never exposes temporal boundaries, runtime identity, revisions, publication state, provenance registries, timestamps, encoded sizes, cache/index details, diagnostics, or arbitrary copied fields from `meta.json`. Adding a metadata field requires evidence that it changes the agent's next read decision; diagnostic convenience alone is insufficient.
365
363
 
@@ -520,7 +518,7 @@ Lazy mutations inherit existing guarantees:
520
518
  - One lock/CAS publication cohort.
521
519
  - Atomic hot-plus-lazy multi-scope changes.
522
520
  - Scope-local deletion and effective revelation semantics.
523
- - Exact retained-boundary selection on restore and branch navigation.
521
+ - Exact retained boundaries for explicit historical reads; reload/resume/tree attach current same-session memory rather than rewinding it.
524
522
  - Read-only discovery with no commit, timestamp update, or transition.
525
523
 
526
524
  Lazy trees are co-located in canonical scope checkpoints/tails and use the same bounded lineage as hot state. The [performance guide](performance.md) owns current synthetic workloads and measurement limits. No separate lazy index or sharded authority exists; any future layout change requires measured need and must preserve canonical semantics, ownership, and one causal lineage.
@@ -536,7 +534,7 @@ Lazy trees are co-located in canonical scope checkpoints/tails and use the same
536
534
 
537
535
  ## Normative invariants
538
536
 
539
- 1. **Object root, ordinary JSON children**: Every runtime scope view has a lazy object, defaulting to `{}` when absent from stored semantics. Its nested values contain domain semantics, never mandatory State Flow record wrappers.
537
+ 1. **Object root, ordinary JSON children**: Present lazy content is an object with ordinary domain JSON children, never mandatory State Flow record wrappers. Sparse semantic/read views preserve absence; `{}` defaults belong only to internal/library compatibility views.
540
538
  2. **Semantic snapshots**: `value` contains only the selected state snapshot and `patch` only the selected semantic patch; `keys` alone adds closed structural `meta` before `keys`.
541
539
  3. **Exact success**: A successful read returns everything requested; it never truncates or paginates silently.
542
540
  4. **Runtime-owned concurrency**: Revisions, locks, and CAS remain internal unless explicitly needed for diagnostics.
@@ -566,7 +564,7 @@ Before release, implementation evidence must prove:
566
564
  - `effective.lazy` follows global → CWD → session overlay while explicit scope paths preserve ownership.
567
565
  - Reads create no semantic transition, Git commit, publication, freshness update, or future activation.
568
566
  - Whole-array replacement and indexed scalar, array, object, nested, multi-index, and stale-basis patches remain atomic.
569
- - Restore and fork select lazy state from the same retained canonical boundary as the rest of the owning session scope.
567
+ - Reload/resume/tree attach current lazy state with the rest of the owning scope; a supported fork copies parent-current lazy content only when private acquisition is admitted. Historical reads select the same retained causal boundary as other planes.
570
568
  - Malformed canonical lazy data fails closed without rewriting the store; rejected queries and patches preserve accepted hot state.
571
569
  - Unsupported store formats and `read_state` inputs fail actionably without rewriting retained bytes.
572
570
 
@@ -2,9 +2,9 @@
2
2
 
3
3
  ## Scope and accepted decision
4
4
 
5
- The subsequent explicit request for a general internal module API is implemented separately in the [internal semantic-module contract](semantic-module-contract.md). It supersedes this checkpoint's no-extraction disposition only for that bounded internal contract. The historical review/evidence below is not retroactively upgraded, and protocol trust/order and public-loader deferral remain applicable.
5
+ The subsequent explicit request for a general internal module API is implemented separately in the [internal semantic-module contract](semantic-module-contract.md). Together with the later [public registration contract](public-module-contract.md), shipped in 0.27.0, it supersedes this checkpoint's no-extraction disposition only within those bounded module responsibilities. The historical review/evidence below is not retroactively upgraded; protocol trust/order and dynamic-loader deferral remain applicable. All M4 milestone statuses and validation counts below describe that historical checkpoint, not current implementation prerequisites.
6
6
 
7
- M4 is an earned-composition investigation, not a requirement to ship descriptors. **Retain the existing plain render functions and shared trusted snippets; do not extract another semantic module layer now.** No source, public API, emitted protocol, storage format, schema, runtime hook or lifecycle change is proposed. The complete actual terminal follow-up review is **APPROVE — R1 verified; retain implementation/defer further extraction**. [BACKLOG](../BACKLOG.md#12-ordered-implementation-backlog) alone owns subsequent work; M5 and gated quality evidence are not approved by this decision.
7
+ M4 is an earned-composition investigation, not a requirement to ship descriptors. **Retain the existing plain render functions and shared trusted snippets; do not extract another semantic module layer now.** No source, public API, emitted protocol, storage format, schema, runtime hook or lifecycle change is proposed. The complete actual terminal follow-up review is **APPROVE — R1 verified; retain implementation/defer further extraction**. [BACKLOG](../BACKLOG.md) alone owns subsequent work; M5 and gated quality evidence are not approved by this decision.
8
8
 
9
9
  The question is whether a further Core/Intents/Strategy/Tactics decomposition solves observed duplication, conflicting ownership or maintenance friction. It is not whether all code can be represented as a descriptor array. The accepted [M3 functional checkpoint](single-scope-interface-contract.md#deterministic-m3-checkpoint) already supplies actual scope-free required arguments and typed outputs; M4 must not reopen its admission/source/private contracts or infer model quality from a different source layout.
10
10
 
@@ -2,13 +2,15 @@
2
2
 
3
3
  ## Status
4
4
 
5
- Candidate public API v1. Native-host registration and retirement have local supported-Node validation and bounded independent acceptance; **Metadata4 codec/opaque retention has bounded independent acceptance. The local candidate now binds registered mutable external roots to the existing read/patch tools and atomic descriptor admission; this new activation slice is not independently accepted. Public input/context execution is now implemented in the local candidate; Active asynchronous producers now propose complete replacements through that same selected publisher. Local end-to-end acceptance is complete: the ordinary public-only consumer also proves current-only forks and opaque current/history retention through folding, incompatible or absent definitions, reload and re-registration, in SOURCE and the built SDK/package entry. Per the later user instruction, activation implementation and final audit were performed inline without actors; no new independent activation approval or real-model quality result is claimed.** [BACKLOG](../BACKLOG.md#12-ordered-implementation-backlog) alone owns unfinished implementation and acceptance. This is an unpublished local candidate, not a released compatibility promise.
5
+ Public API v1 is published through `@llblab/pi-state-flow/modules` since **0.27.0** and remains supported in **0.27.1**. It includes native-host registration/disposal, metadata v4 descriptors and opaque retention, external-root read/patch tools, captured Active/Passive context, and cohort-atomic Active producer replacements. The package export and source types in `api/modules.ts` and `lib/semantic-module.ts` define the executable surface; this document owns its integration and trust contract.
6
+
7
+ Registration and codec/retention received bounded independent acceptance during development. Later activation implementation and final audit were performed inline under the owner's instruction; publication does not retroactively grant independent approval to those subphases. Scripted native-SDK and built-package consumer checks are deterministic integration evidence, not live-model quality or installed-client certification. See [compatibility](compatibility.md) for evidence limits and [BACKLOG](../BACKLOG.md) for outstanding work.
6
8
 
7
9
  Pi loads ordinary companion extensions. StateFlow provides a thin public registration membrane; it does not discover or load plugin code. The [internal evaluators](semantic-module-contract.md) remain separate from native/source admission and atomic publication.
8
10
 
9
11
  ## Public entry and lifecycle
10
12
 
11
- Import `registerStateFlowModule` and its types from `@llblab/pi-state-flow/modules`. Local source consumers may import `api/modules.ts`; compiled consumers use `dist/api/modules.js`. These membranes do not import the extension composition root.
13
+ Import the runtime function `registerStateFlowModule` from `@llblab/pi-state-flow/modules`. The same entry exports types `StateFlowModule`, `StateFlowModuleSource`, `StateFlowModuleFrame`, `StateFlowModuleInput`, `ModuleContextContribution`, `JsonObject` and `JsonValue`; there is no exported loader or publisher. Local source consumers may import `api/modules.ts`; compiled consumers use `dist/api/modules.js`. These membranes do not import the extension composition root.
12
14
 
13
15
  Register synchronously in the consumer's `session_start` handler, with StateFlow loaded first. Pass `ctx.sessionManager` only as the native-host identity key, not raw runtime context. Host absence, competing ownership of the same manager, duplicate IDs and incompatible API versions fail explicitly. Two different SDK managers in one process have independent catalogs. A retained native identity check also fences manager reuse for another session/address.
14
16
 
@@ -40,7 +42,7 @@ export default function (pi: ExtensionAPI) {
40
42
  }
41
43
  ```
42
44
 
43
- With this companion registered, a sole participating owner can persist `{"x_acme_notes":{"entries":["accepted"]}}` through `patch_state` and read `x_acme_notes` through `read_state`. Multiple participating owners retain explicit scope wrappers. The context callback now executes on admitted Active/Passive provider contexts; its data is transported as fallible user-level data, not system instructions. Pi 1.0.0 uses `session_shutdown`, not `shutdown`.
45
+ With this companion registered, a sole participating owner can persist `{"x_acme_notes":{"entries":["accepted"]}}` through `patch_state` and read `x_acme_notes` through `read_state`. Multiple participating owners retain explicit scope wrappers. The context callback executes on admitted Active/Passive provider contexts; its data is transported as fallible user-level data, not system instructions. Pi 1.0.0 uses `session_shutdown`, not `shutdown`.
44
46
 
45
47
  Registration returns an idempotent disposer for that exact instance. It cannot revoke a later equal-ID registration or another host generation. Catalog changes abort old catalog signals; host retirement removes only its own binding before signaling cancellation. Snapshots capture immutable policy, callback identities and definition order. Constructor-injected services remain bound to their original instance. Trusted callbacks are not an effects sandbox, and a catalog snapshot alone is not publication authority.
46
48
 
@@ -50,7 +52,9 @@ The public `StateFlowModule<Content, Input>` has the internal identity/immutabil
50
52
 
51
53
  - **`apiVersion: 1`:** Version of callback/frame assumptions, independently of the runtime package resolved by an older companion's import.
52
54
  - **`schemaVersion`:** Positive safe integer for one exact persisted content/policy contract; not the package or host metadata version.
53
- - **`captureInput?`:** Acquire module-specific JSON input and return `{ value, assertCurrent }`. The synchronous assertion throws if that captured source is obsolete; it does not reacquire data or perform asynchronous work under exclusion.
55
+ - **`captureInput?(source, signal)`:** Optional synchronous or asynchronous acquisition of module-specific JSON input, returning `{ value, assertCurrent }`. It runs outside exclusion; the synchronous receipt throws if that captured source is obsolete and never reacquires data or performs asynchronous work under exclusion.
56
+ - **`context(content, frame)`:** Synchronous contribution computation; an asynchronous return is not admitted. Contributions are user-level data or admitted native conversation indices, never arbitrary system-prompt text.
57
+ - **`produce?(content, frame, signal)`:** Optional synchronous or asynchronous complete-replacement proposal, invoked only by an owned Active preparation. It is not a publisher or independent scheduler. Abort/currentness fences abandon stale asynchronous work even if the callback ignores its signal; trusted synchronous JavaScript is not preempted or sandboxed.
54
58
 
55
59
  External durable content is initially a JSON object. Validators admit complete resulting values, not recursive partial patches. `immutable` denies main-agent writes, not authorized producer proposals. `produce?` returns a complete replacement object or `undefined`; it never publishes itself. Constructor-injected narrow services avoid a generic capability registry or raw `ctx`.
56
60
 
@@ -58,14 +62,20 @@ Activation must pass a detached `StateFlowModuleFrame` to both context and produ
58
62
 
59
63
  Context proposals are data or exact source-message indices, not system instructions or arbitrary context mutation. Session conversation contains only the completed native segment before a uniquely anchored current user run; ambiguity withholds that segment. Shared frames carry no dialogue/prompt and cannot propose conversation replacement. At most one Session module may select completed conversation; competing selectors fail closed. A selection must preserve whole native tool-call/result units and original identities/order. The host preserves current-run and foreign frames, removes duplicate completed messages, and only alters provider context, never the native journal. Data-only contributions do not themselves remove history. Scope order then captured module order determines data placement before native conversation, after the owned core head. Off invokes none of these callbacks; metadata registration itself neither acquires nor writes memory.
60
64
 
65
+ ## Historical local acceptance
66
+
67
+ Before 0.27.0 publication, ordinary public-only SDK consumers exercised mutable/immutable current-only forks from older native points, unchanged parent semantic-file bytes, retained descriptors, a fresh child aligned origin and child reload. Pre-origin materialized reads reject; this does not claim that retained per-owner tail bytes are absent from child storage. Global/CWD/Session/all-three fixtures at history limits 0/1/7 crossed actual folding, retained every still-available current/historical opaque value through missing or incompatible definitions, refused incompatible callbacks/writes and resumed after cold re-registration.
68
+
69
+ That local checkpoint recorded **1695/1695 on Node 22/24**, **145 package files**, the same two final compiled SDK properties, earlier 16 public and seven codec properties; sets overlap and are not summed. Registration/lifetime and codec retention had their separately bounded independent approvals; activation and final audit were inline. The earlier global **REQUESTCHANGES** verdict was not retroactively upgraded by scoped remediation or publication. The [exact pre-release record](https://github.com/llblab/pi-state-flow/blob/f9128d9eaa2b94133d992f51f80f16aec0d43653/BACKLOG.md#12-ordered-implementation-backlog) retains original counts, review boundaries and superseded execution instructions. These are historical results, not fresh 0.27.2 tests, installed-client certification or model-quality evidence.
70
+
61
71
  ## Recorded compatibility decision
62
72
 
63
- The external-plane path will use owner metadata **version 4**, retaining the same checkpoint, patch-tail and metadata files. This decision preceded codec implementation. The local candidate now admits descriptors and opaque external values through the existing codec/replay/publication path; absent stream descriptors retain legacy three-key streams and v3 output. Integrated SOURCE/build/package and complete compiled-property checks pass on both supported Nodes; independent retention and acceptance reviews approved this storage slice with disclosed coverage limits. The new manual tool path adds a descriptor only with the first nonempty accepted content transition through the same selected publisher; registration, empty proposals and context-only observation cannot mint a slot. Validators receive a detached complete result, not a partial patch, and must be pure synchronous content guards (no acquisition/inference). Definition/schema/policy mismatches reject model writes before validators. Exact reads and patch history use retained descriptors without calling definitions. Current catalog revocation fences queued old calls, including equal-ID re-registration. Input and context callbacks are activated as described above; Active producer publication is now activated through the same engine. Results are complete JSON-object replacements, never recursive merges; `undefined` is no proposal and `{}` clears content without removing its descriptor or fabricating a new slot. Main-agent immutable restrictions remain intact. All applicable producer jobs compute outside exclusion using narrow constructor-injected services, not ambient runtime/storage/model tools. Before publication, the host rechecks original input, content/descriptor, captured source-scope stream, registration generation, native owner/model/selection and cancellation; model or thinking-level changes revoke the original request even after A→B→A. A fresh transaction cannot launder stale work. One invalid/stale result rejects the proposed cohort. After its own accepted publication, context receives the accepted content using the original input receipt and a lease pinned to that exact acceptance. Late cancellation/context/checkpoint failure never rolls accepted memory back.
73
+ The external-plane path uses owner metadata **version 4**, retaining the same checkpoint, patch-tail and metadata files. The recorded decision preceded codec implementation; that implementation shipped in 0.27.0. Descriptors and opaque external values use the existing codec/replay/publication path; absent stream descriptors retain legacy three-key streams and v3 output. Historical integrated SOURCE/build/package and compiled-property checks passed on both supported Nodes; independent retention and acceptance reviews approved that storage slice with disclosed coverage limits. The new manual tool path adds a descriptor only with the first nonempty accepted content transition through the same selected publisher; registration, empty proposals and context-only observation cannot mint a slot. Validators receive a detached complete result, not a partial patch, and must be pure synchronous content guards (no acquisition/inference). Definition/schema/policy mismatches reject model writes before validators. Exact reads and patch history use retained descriptors without calling definitions. Current catalog revocation fences queued old calls, including equal-ID re-registration. Input and context callbacks are activated as described above; Active producer publication is now activated through the same engine. Results are complete JSON-object replacements, never recursive merges; `undefined` is no proposal and `{}` clears content without removing its descriptor or fabricating a new slot. Main-agent immutable restrictions remain intact. All applicable producer jobs compute outside exclusion using narrow constructor-injected services, not ambient runtime/storage/model tools. Before publication, the host rechecks original input, content/descriptor, captured source-scope stream, registration generation, native owner/model/selection and cancellation; model or thinking-level changes revoke the original request even after A→B→A. A fresh transaction cannot launder stale work. One invalid/stale result rejects the proposed cohort. After its own accepted publication, context receives the accepted content using the original input receipt and a lease pinned to that exact acceptance. Late cancellation/context/checkpoint failure never rolls accepted memory back.
64
74
 
65
75
  - **Identity:** External roots match `x_[a-z][a-z0-9_]*`; use package-derived names. IDs do not authenticate package ownership. Existing built-ins and retired-root reservations remain distinct.
66
76
  - **Retained descriptors:** Owner metadata maps each written external root to `{ schemaVersion, immutable }`. Persist the descriptor in the same accepted cohort as its first write and retain it through deletion, folding and fork. Do not recycle a root for unrelated semantics.
67
77
  - **No new content envelope:** External objects remain semantic roots, not `{ immutable, content }` wrappers. Policy/version data remains outside model-patchable state. No mixed schema epochs or automatic module-schema conversion is introduced initially.
68
- - **Available:** Execute a registered definition only when its exact schema version and authoring policy match the retained descriptor. Validate complete candidate content before publication.
78
+ - **Available:** A registered new root without a retained descriptor can receive absent content and propose its first accepted value. Once a descriptor exists, execute only when schema version and authoring policy match it exactly. Registration/observation alone never mint a descriptor; complete candidate content must validate before publication.
69
79
  - **Unavailable:** Missing, disposed or incompatible definitions leave opaque retained data. Exact current/history reads may return raw data; automatic context and model writes are unavailable. Unrelated writes, pruning, folding, reload and fork must preserve current values and every still-retained historical boundary without invoking missing callbacks.
70
80
  - **Legacy:** Preserve declared v1/v2/v3 meanings and detect raw external-namespace collisions before conversion; formerly ignored roots cannot be silently adopted. Only admitted semantic acceptance may convert complete cohorts through existing backup/byte-CAS safeguards. Inspection and runtime-only policy persistence cannot migrate.
71
81
  - **Writer limit:** Version refusal is evidence for inspected old writers, not universal deployed-writer protection. Existing quiescence and unsupported-writer requirements remain. No working-store migration, live reload or release is authorized by this decision.