@llblab/pi-state-flow 0.3.0 → 0.5.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/lib/episode.ts CHANGED
@@ -1,29 +1,41 @@
1
- import { emptyState } from "./state.ts";
2
- import type { Snapshot } from "./snapshot.ts";
1
+ import { emptySnapshot, type Snapshot } from "./snapshot.ts";
3
2
 
4
3
  export function startEpisode(bootstrap: boolean): Snapshot {
5
- return { enabled: true, state: emptyState(), step: 0, bootstrap };
4
+ const snapshot = emptySnapshot(true);
5
+ if (bootstrap) snapshot.meta.bootstrap = true;
6
+ return snapshot;
6
7
  }
7
8
 
8
- export function stopEpisode(): Snapshot {
9
- return { enabled: false, state: emptyState(), step: 0 };
9
+ /** Re-enable a branch checkpoint without discarding its runtime config or provenance. */
10
+ export function resumeEpisode(snapshot: Snapshot, bootstrap: boolean): Snapshot {
11
+ const next = structuredClone(snapshot);
12
+ next.config.enabled = true;
13
+ if (bootstrap) next.meta.bootstrap = true;
14
+ return next;
10
15
  }
11
16
 
12
- /** Apply one user-run boundary while preserving the materialized state. */
17
+ /** Disable only this branch; durable defaults and session history remain intact. */
18
+ export function stopEpisode(snapshot: Snapshot): Snapshot {
19
+ const next = structuredClone(snapshot);
20
+ next.config.enabled = false;
21
+ return next;
22
+ }
23
+
24
+ /** Apply one user-run boundary while preserving checkpoint-owned runtime state. */
13
25
  export function prepareRun(snapshot: Snapshot, prompt: string, isRetry: boolean): boolean {
14
- if (snapshot.specification === undefined) {
15
- snapshot.specification = prompt;
26
+ if (snapshot.meta.specification === undefined) {
27
+ snapshot.meta.specification = prompt;
16
28
  return true;
17
29
  }
18
30
  if (isRetry) return false;
19
- snapshot.specification = prompt;
20
- snapshot.validation = undefined;
31
+ snapshot.meta.specification = prompt;
32
+ snapshot.meta.validation = undefined;
21
33
  return true;
22
34
  }
23
35
 
24
36
  /** Clear only transient validation metadata; never disable or reset the episode. */
25
37
  export function abandonValidation(snapshot: Snapshot): boolean {
26
- if (snapshot.validation === undefined) return false;
27
- snapshot.validation = undefined;
38
+ if (snapshot.meta.validation === undefined) return false;
39
+ snapshot.meta.validation = undefined;
28
40
  return true;
29
41
  }