@llblab/pi-state-flow 0.23.0 → 0.25.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/AGENTS.md +7 -6
- package/BACKLOG.md +13 -5
- package/CHANGELOG.md +16 -1
- package/LICENSE +21 -0
- package/README.md +117 -35
- package/dist/lib/acquisition.d.ts +24 -1
- package/dist/lib/acquisition.js +80 -1
- package/dist/lib/compaction.d.ts +18 -1
- package/dist/lib/compaction.js +41 -1
- package/dist/lib/extension.js +346 -303
- package/dist/lib/git.d.ts +31 -2
- package/dist/lib/git.js +74 -5
- package/dist/lib/operation.d.ts +37 -0
- package/dist/lib/operation.js +59 -0
- package/dist/lib/ownership.d.ts +31 -0
- package/dist/lib/ownership.js +117 -0
- package/dist/lib/protocol.js +7 -7
- package/dist/lib/query.js +1 -1
- package/dist/lib/session.d.ts +10 -1
- package/dist/lib/session.js +60 -1
- package/dist/lib/snapshot.d.ts +6 -0
- package/dist/lib/snapshot.js +8 -5
- package/dist/lib/status.d.ts +2 -0
- package/dist/lib/status.js +28 -0
- package/dist/lib/transition.js +6 -1
- package/dist/package.json +10 -9
- package/dist/skills/state-flow-guide/SKILL.md +14 -6
- package/dist/skills/state-flow-memory/SKILL.md +2 -2
- package/docs/README.md +19 -9
- package/docs/agent-contract-relocation.md +4 -4
- package/docs/architecture.md +646 -89
- package/docs/compatibility.md +116 -37
- package/docs/filesystem-recovery.md +118 -21
- package/docs/fork-contract.md +70 -8
- package/docs/lazy-state.md +88 -14
- package/docs/performance.md +83 -66
- package/docs/temporal-acceptance.md +391 -62
- package/docs/usage.md +317 -61
- package/lib/acquisition.ts +85 -1
- package/lib/compaction.ts +49 -2
- package/lib/extension.ts +342 -301
- package/lib/git.ts +77 -5
- package/lib/operation.ts +75 -0
- package/lib/ownership.ts +120 -0
- package/lib/protocol.ts +7 -8
- package/lib/query.ts +1 -1
- package/lib/runtime.ts +1 -1
- package/lib/session.ts +52 -1
- package/lib/snapshot.ts +8 -7
- package/lib/status.ts +29 -0
- package/lib/transition.ts +5 -1
- package/package.json +10 -9
- package/skills/state-flow-guide/SKILL.md +14 -6
- package/skills/state-flow-memory/SKILL.md +2 -2
package/dist/lib/compaction.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { estimateTokens } from "@earendil-works/pi-coding-agent";
|
|
2
3
|
export const STATE_FLOW_COMPACTION_SUMMARY = "State Flow accepted the completed work before this boundary. Current memory is restored from its retained semantic boundary and projected separately; use the retained native entries for subsequent work.";
|
|
3
4
|
/** A modest margin above Pi's default 20k retained suffix absorbs estimation drift. */
|
|
4
5
|
export const STATE_FLOW_COMPACTION_MIN_CONTEXT_TOKENS = 24_000;
|
|
@@ -65,3 +66,42 @@ export function stateFlowCompactionResult(plan, marker, event) {
|
|
|
65
66
|
details: structuredClone(plan.details),
|
|
66
67
|
};
|
|
67
68
|
}
|
|
69
|
+
const STATE_FLOW_COMPACTION_MARKER_PREFIX = "state-flow-boundary:";
|
|
70
|
+
/** Completed-history compaction request state owned by one extension instance. */
|
|
71
|
+
export class StateFlowCompactionRequests {
|
|
72
|
+
#plan;
|
|
73
|
+
#marker;
|
|
74
|
+
#inFlight = false;
|
|
75
|
+
#stopped = false;
|
|
76
|
+
#prefix = `${STATE_FLOW_COMPACTION_MARKER_PREFIX}${randomUUID()}:`;
|
|
77
|
+
get inFlight() { return this.#inFlight; }
|
|
78
|
+
get stopped() { return this.#stopped; }
|
|
79
|
+
/** Permanently refuse owned requests (shutdown). */
|
|
80
|
+
stop() { this.#stopped = true; }
|
|
81
|
+
/** Drop the run-local plan; a stale callback can no longer clear a newer one. */
|
|
82
|
+
clear() {
|
|
83
|
+
this.#plan = undefined;
|
|
84
|
+
this.#inFlight = false;
|
|
85
|
+
}
|
|
86
|
+
/** Install a plan and return its unique per-request marker. */
|
|
87
|
+
begin(plan) {
|
|
88
|
+
this.#plan = plan;
|
|
89
|
+
const marker = this.#marker = `${this.#prefix}${randomUUID()}`;
|
|
90
|
+
this.#inFlight = true;
|
|
91
|
+
return marker;
|
|
92
|
+
}
|
|
93
|
+
/** Native completion clears only its own request. */
|
|
94
|
+
finish(marker) {
|
|
95
|
+
if (this.#marker === marker)
|
|
96
|
+
this.clear();
|
|
97
|
+
}
|
|
98
|
+
/** Answer session_before_compact: foreign requests pass, stale or unpermitted owned ones cancel. */
|
|
99
|
+
resolve(event, permitted) {
|
|
100
|
+
if (event.reason !== "manual" || !event.customInstructions?.startsWith(STATE_FLOW_COMPACTION_MARKER_PREFIX))
|
|
101
|
+
return undefined;
|
|
102
|
+
const marker = this.#marker;
|
|
103
|
+
if (!permitted || this.#stopped || !this.#plan || !marker || event.customInstructions !== marker)
|
|
104
|
+
return { cancel: true };
|
|
105
|
+
return stateFlowCompactionResult(this.#plan, marker, event);
|
|
106
|
+
}
|
|
107
|
+
}
|