@llblab/pi-state-flow 0.13.1 → 0.13.2
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 +5 -0
- package/dist/lib/compaction.d.ts +7 -0
- package/dist/lib/compaction.js +17 -0
- package/dist/lib/extension.js +5 -2
- package/dist/package.json +1 -1
- package/lib/compaction.ts +17 -1
- package/lib/extension.ts +4 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
## Unreleased
|
|
6
6
|
|
|
7
|
+
## 0.13.2: Benign compaction readiness
|
|
8
|
+
|
|
9
|
+
- `Benign compaction readiness`: Automatic State Flow compaction now requires enough persisted message history as well as high total context usage, so a short session enlarged only by its system prompt remains a quiet non-action instead of surfacing Pi's native `Nothing to compact` failure.
|
|
10
|
+
- `Release automation`: The publish job now builds the compiled distribution before capturing its script-free local package inventory, so post-publication comparison uses the same manifest shape as the npm artifact.
|
|
11
|
+
|
|
7
12
|
## 0.13.1: Compiled package release verification
|
|
8
13
|
|
|
9
14
|
- `Release verification`: Public npm verification now checks the compiled Pi entrypoint and packaged Skill introduced in 0.13.0 instead of requiring the retired source entrypoint, with an invariant preventing the workflow from drifting back to source-package assumptions.
|
package/dist/lib/compaction.d.ts
CHANGED
|
@@ -20,11 +20,18 @@ type ActiveEntry = {
|
|
|
20
20
|
message?: {
|
|
21
21
|
role?: unknown;
|
|
22
22
|
stopReason?: unknown;
|
|
23
|
+
content?: unknown;
|
|
23
24
|
};
|
|
24
25
|
};
|
|
25
26
|
export declare function shouldRequestStateFlowCompaction(usage: {
|
|
26
27
|
tokens: number | null;
|
|
27
28
|
} | undefined): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Pi's public usage includes the system prompt, while native compaction can only
|
|
31
|
+
* shorten persisted messages. Avoid requesting a visibly failing manual
|
|
32
|
+
* compaction when that transcript is still below the useful-history floor.
|
|
33
|
+
*/
|
|
34
|
+
export declare function hasCompactionSizedTranscript(entries: readonly ActiveEntry[]): boolean;
|
|
28
35
|
/** Retain the complete latest accepted user iteration without hiding foreign extension context. */
|
|
29
36
|
export declare function planStateFlowCompaction(entries: readonly ActiveEntry[], revision: string, step: number): StateFlowCompactionPlan | undefined;
|
|
30
37
|
/** Customize only the extension-owned manual request and only while its planned leaf remains selected. */
|
package/dist/lib/compaction.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { estimateTokens } from "@earendil-works/pi-agent-core";
|
|
1
2
|
export const STATE_FLOW_COMPACTION_SUMMARY = "State Flow accepted the completed work before this boundary. Current memory is restored from its durable revision and projected separately; use the retained native entries for subsequent work.";
|
|
2
3
|
/** A modest margin above Pi's default 20k retained suffix absorbs estimation drift. */
|
|
3
4
|
export const STATE_FLOW_COMPACTION_MIN_CONTEXT_TOKENS = 24_000;
|
|
@@ -11,6 +12,22 @@ export function shouldRequestStateFlowCompaction(usage) {
|
|
|
11
12
|
&& Number.isFinite(usage.tokens)
|
|
12
13
|
&& usage.tokens >= STATE_FLOW_COMPACTION_MIN_CONTEXT_TOKENS;
|
|
13
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Pi's public usage includes the system prompt, while native compaction can only
|
|
17
|
+
* shorten persisted messages. Avoid requesting a visibly failing manual
|
|
18
|
+
* compaction when that transcript is still below the useful-history floor.
|
|
19
|
+
*/
|
|
20
|
+
export function hasCompactionSizedTranscript(entries) {
|
|
21
|
+
let tokens = 0;
|
|
22
|
+
for (const entry of entries) {
|
|
23
|
+
if (entry.type !== "message" || typeof entry.message?.role !== "string")
|
|
24
|
+
continue;
|
|
25
|
+
tokens += estimateTokens(entry.message);
|
|
26
|
+
if (tokens >= STATE_FLOW_COMPACTION_MIN_CONTEXT_TOKENS)
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
14
31
|
/** Retain the complete latest accepted user iteration without hiding foreign extension context. */
|
|
15
32
|
export function planStateFlowCompaction(entries, revision, step) {
|
|
16
33
|
if (!/^[0-9a-f]{40,64}$/.test(revision) && !/^file:[0-9a-f]{64}$/.test(revision))
|
package/dist/lib/extension.js
CHANGED
|
@@ -30,7 +30,7 @@ import { projectRecentTransitionsWithLimit, RECENT_TRANSITION_LIMIT } from "./hi
|
|
|
30
30
|
import { appendStateFlowDiagnostic, projectDiagnosticContent, stateFlowLogPath } from "./logging.js";
|
|
31
31
|
import { isGitCommitAncestor, pushGitCommit, pushGitTarget, resolveGitPushDestination } from "./git.js";
|
|
32
32
|
import { ORDINARY_ARTIFACT_COMPILER, planArtifactInvalidation, } from "./artifact.js";
|
|
33
|
-
import { planStateFlowCompaction, shouldRequestStateFlowCompaction, stateFlowCompactionResult } from "./compaction.js";
|
|
33
|
+
import { hasCompactionSizedTranscript, planStateFlowCompaction, shouldRequestStateFlowCompaction, stateFlowCompactionResult } from "./compaction.js";
|
|
34
34
|
export const PATCH_STATE_TOOL_NAME = "patch_state";
|
|
35
35
|
export const READ_STATE_TOOL_NAME = "read_state";
|
|
36
36
|
export const MAX_FALLBACK_ATTEMPTS = 2;
|
|
@@ -1227,7 +1227,10 @@ export default function stateFlowExtension(pi, options = {}) {
|
|
|
1227
1227
|
|| !shouldRequestStateFlowCompaction(ctx.getContextUsage()))
|
|
1228
1228
|
return;
|
|
1229
1229
|
completedRunAccepted = false;
|
|
1230
|
-
const
|
|
1230
|
+
const entries = ctx.sessionManager.buildContextEntries();
|
|
1231
|
+
if (!hasCompactionSizedTranscript(entries))
|
|
1232
|
+
return;
|
|
1233
|
+
const plan = planStateFlowCompaction(entries, snapshot.meta.durableBase, snapshot.meta.step);
|
|
1231
1234
|
if (!plan)
|
|
1232
1235
|
return;
|
|
1233
1236
|
compactionPlan = plan;
|
package/dist/package.json
CHANGED
package/lib/compaction.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { estimateTokens, type AgentMessage } from "@earendil-works/pi-agent-core";
|
|
1
2
|
import type { CompactionResult } from "@earendil-works/pi-coding-agent";
|
|
2
3
|
|
|
3
4
|
export const STATE_FLOW_COMPACTION_SUMMARY = "State Flow accepted the completed work before this boundary. Current memory is restored from its durable revision and projected separately; use the retained native entries for subsequent work.";
|
|
@@ -21,7 +22,7 @@ type ActiveEntry = {
|
|
|
21
22
|
id?: unknown;
|
|
22
23
|
type?: unknown;
|
|
23
24
|
customType?: unknown;
|
|
24
|
-
message?: { role?: unknown; stopReason?: unknown };
|
|
25
|
+
message?: { role?: unknown; stopReason?: unknown; content?: unknown };
|
|
25
26
|
};
|
|
26
27
|
|
|
27
28
|
function stateFlowEntry(entry: ActiveEntry): boolean {
|
|
@@ -36,6 +37,21 @@ export function shouldRequestStateFlowCompaction(usage: { tokens: number | null
|
|
|
36
37
|
&& usage.tokens >= STATE_FLOW_COMPACTION_MIN_CONTEXT_TOKENS;
|
|
37
38
|
}
|
|
38
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Pi's public usage includes the system prompt, while native compaction can only
|
|
42
|
+
* shorten persisted messages. Avoid requesting a visibly failing manual
|
|
43
|
+
* compaction when that transcript is still below the useful-history floor.
|
|
44
|
+
*/
|
|
45
|
+
export function hasCompactionSizedTranscript(entries: readonly ActiveEntry[]): boolean {
|
|
46
|
+
let tokens = 0;
|
|
47
|
+
for (const entry of entries) {
|
|
48
|
+
if (entry.type !== "message" || typeof entry.message?.role !== "string") continue;
|
|
49
|
+
tokens += estimateTokens(entry.message as unknown as AgentMessage);
|
|
50
|
+
if (tokens >= STATE_FLOW_COMPACTION_MIN_CONTEXT_TOKENS) return true;
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
|
|
39
55
|
/** Retain the complete latest accepted user iteration without hiding foreign extension context. */
|
|
40
56
|
export function planStateFlowCompaction(
|
|
41
57
|
entries: readonly ActiveEntry[],
|
package/lib/extension.ts
CHANGED
|
@@ -42,7 +42,7 @@ import {
|
|
|
42
42
|
planArtifactInvalidation,
|
|
43
43
|
type ArtifactInvalidationRequest,
|
|
44
44
|
} from "./artifact.ts";
|
|
45
|
-
import { planStateFlowCompaction, shouldRequestStateFlowCompaction, stateFlowCompactionResult, type StateFlowCompactionPlan } from "./compaction.ts";
|
|
45
|
+
import { hasCompactionSizedTranscript, planStateFlowCompaction, shouldRequestStateFlowCompaction, stateFlowCompactionResult, type StateFlowCompactionPlan } from "./compaction.ts";
|
|
46
46
|
|
|
47
47
|
export interface StateFlowExtensionOptions {
|
|
48
48
|
agentDir?: string;
|
|
@@ -1245,7 +1245,9 @@ export default function stateFlowExtension(pi: ExtensionAPI, options: StateFlowE
|
|
|
1245
1245
|
|| compactionInFlight || !ctx.isIdle() || ctx.hasPendingMessages() || !snapshot.meta.durableBase
|
|
1246
1246
|
|| !shouldRequestStateFlowCompaction(ctx.getContextUsage())) return;
|
|
1247
1247
|
completedRunAccepted = false;
|
|
1248
|
-
const
|
|
1248
|
+
const entries = ctx.sessionManager.buildContextEntries();
|
|
1249
|
+
if (!hasCompactionSizedTranscript(entries)) return;
|
|
1250
|
+
const plan = planStateFlowCompaction(entries, snapshot.meta.durableBase, snapshot.meta.step);
|
|
1249
1251
|
if (!plan) return;
|
|
1250
1252
|
compactionPlan = plan;
|
|
1251
1253
|
compactionInFlight = true;
|