@llblab/pi-state-flow 0.13.1 → 0.13.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.
- package/CHANGELOG.md +9 -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/lib/telegram.d.ts +2 -0
- package/dist/lib/telegram.js +8 -5
- package/dist/package.json +1 -1
- package/lib/compaction.ts +17 -1
- package/lib/extension.ts +4 -2
- package/lib/telegram.ts +9 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
## Unreleased
|
|
6
6
|
|
|
7
|
+
## 0.13.3: Telegram section discovery hotfix
|
|
8
|
+
|
|
9
|
+
- `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.
|
|
10
|
+
|
|
11
|
+
## 0.13.2: Benign compaction readiness
|
|
12
|
+
|
|
13
|
+
- `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.
|
|
14
|
+
- `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.
|
|
15
|
+
|
|
7
16
|
## 0.13.1: Compiled package release verification
|
|
8
17
|
|
|
9
18
|
- `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/lib/telegram.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export declare const STATE_FLOW_TELEGRAM_ID = "@llblab/pi-state-flow";
|
|
2
|
+
/** Resolve the package export or the compiled sibling-extension layout used in local development. */
|
|
3
|
+
export declare function stateFlowTelegramSectionSpecifiers(moduleUrl?: string): string[];
|
|
2
4
|
export interface StateFlowTelegramSnapshot {
|
|
3
5
|
enabled: boolean;
|
|
4
6
|
step: number;
|
package/dist/lib/telegram.js
CHANGED
|
@@ -11,10 +11,13 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
|
|
|
11
11
|
return path;
|
|
12
12
|
};
|
|
13
13
|
export const STATE_FLOW_TELEGRAM_ID = "@llblab/pi-state-flow";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
/** Resolve the package export or the compiled sibling-extension layout used in local development. */
|
|
15
|
+
export function stateFlowTelegramSectionSpecifiers(moduleUrl = import.meta.url) {
|
|
16
|
+
return [
|
|
17
|
+
"@llblab/pi-telegram/sections",
|
|
18
|
+
new URL("../../../pi-telegram/dist/api/sections.js", moduleUrl).href,
|
|
19
|
+
];
|
|
20
|
+
}
|
|
18
21
|
/** Main-menu section label doubles as the live status value: the spiral identity is constant, the value is not. */
|
|
19
22
|
export function formatStateFlowSectionLabel(snapshot) {
|
|
20
23
|
return `🌀 State Flow: ${stateFlowLabelValue(snapshot)}`;
|
|
@@ -168,7 +171,7 @@ async function importTelegramModule(specifiers, guard) {
|
|
|
168
171
|
}
|
|
169
172
|
/** Default loader; injectable so tests and embedded hosts can control transport presence. */
|
|
170
173
|
export async function loadStateFlowTelegramModules() {
|
|
171
|
-
const sections = await importTelegramModule(
|
|
174
|
+
const sections = await importTelegramModule(stateFlowTelegramSectionSpecifiers(), (module) => typeof module?.registerTelegramSection === "function");
|
|
172
175
|
return { ...(sections === undefined ? {} : { sections }) };
|
|
173
176
|
}
|
|
174
177
|
export function createStateFlowTelegramAdapter(options) {
|
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;
|
package/lib/telegram.ts
CHANGED
|
@@ -4,10 +4,14 @@
|
|
|
4
4
|
// pi-telegram is absent or its registry is not ready, registration fails open and retries.
|
|
5
5
|
|
|
6
6
|
export const STATE_FLOW_TELEGRAM_ID = "@llblab/pi-state-flow";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
|
|
8
|
+
/** Resolve the package export or the compiled sibling-extension layout used in local development. */
|
|
9
|
+
export function stateFlowTelegramSectionSpecifiers(moduleUrl = import.meta.url): string[] {
|
|
10
|
+
return [
|
|
11
|
+
"@llblab/pi-telegram/sections",
|
|
12
|
+
new URL("../../../pi-telegram/dist/api/sections.js", moduleUrl).href,
|
|
13
|
+
];
|
|
14
|
+
}
|
|
11
15
|
|
|
12
16
|
export interface StateFlowTelegramSnapshot {
|
|
13
17
|
enabled: boolean;
|
|
@@ -259,7 +263,7 @@ async function importTelegramModule<TModule>(
|
|
|
259
263
|
/** Default loader; injectable so tests and embedded hosts can control transport presence. */
|
|
260
264
|
export async function loadStateFlowTelegramModules(): Promise<StateFlowTelegramModules> {
|
|
261
265
|
const sections = await importTelegramModule<StateFlowTelegramSectionModule>(
|
|
262
|
-
|
|
266
|
+
stateFlowTelegramSectionSpecifiers(),
|
|
263
267
|
(module): module is StateFlowTelegramSectionModule =>
|
|
264
268
|
typeof (module as StateFlowTelegramSectionModule | undefined)?.registerTelegramSection === "function",
|
|
265
269
|
);
|