pi-advisor-flow 0.14.0 → 0.14.1-dev.1
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 +4 -0
- package/README.md +4 -0
- package/dist/index.js +45 -6
- package/package.json +1 -1
- package/src/tools/budget-feedback.ts +69 -0
- package/src/tools/register-lifecycle.ts +10 -7
- package/src/tools/registration.ts +10 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,10 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
|
|
|
6
6
|
|
|
7
7
|
## Unreleased
|
|
8
8
|
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- Preserve the Executor's cached prompt prefix when Advisor call budgets change, including providers that collapse mid-conversation system messages. Current allowances are appended as hidden conversation messages at run start and after consultation turns, with explicit unlimited and Simple mode reports.
|
|
12
|
+
|
|
9
13
|
## 0.14.0 - 2026-10-16
|
|
10
14
|
|
|
11
15
|
### Added
|
package/README.md
CHANGED
|
@@ -122,6 +122,10 @@ Draft text is explicit disclosure: it does **not** inherit the policies of the t
|
|
|
122
122
|
|
|
123
123
|
## Usage and accounting
|
|
124
124
|
|
|
125
|
+
The Executor receives the current Advisor call allowance in hidden conversation messages at the start of each run and after turns that change it. Invocation rules stay in a stable system-prompt section, so spending budget does not rewrite the leading prompt, including on providers with `supportsMidConvoSystemMessages: false`. The latest budget report already accounts for consumed and reserved calls; unlimited budgets and Simple mode are reported explicitly. Programmatic limits still enforce the shared allowance across consultations and gates.
|
|
126
|
+
|
|
127
|
+
When using an older pi-advisor version, a model-level `"compat": { "supportsMidConvoSystemMessages": true }` in Pi's `models.json` can avoid this budget-related prefix rewrite if the endpoint has been verified to support mid-conversation developer/system messages. Refresh the model catalog and reselect the model, or restart Pi, after changing it. The current budget feedback does not require this workaround. Other prompt/tool changes, routing, and cache expiry can still cause cache misses.
|
|
128
|
+
|
|
125
129
|
Advisor responses show provider-reported input, output, cache, and cost details when available. Successful `ask_advisor` calls also carry normalized usage into Pi's built-in `/cost` totals. Manual consultations and automatic gates keep their own session-local accounting instead, so nothing is double-counted. Missing or partial provider usage is shown as unavailable rather than fabricated as zero. `/advisor-settings` controls both the per-response details and the optional cumulative footer independently. Configure `advisorFallbackModel` or choose **Fallback Advisor model** in the model/settings pickers to retry one failed primary request; the final response is labelled with the model that answered, and both failures are shown together.
|
|
126
130
|
|
|
127
131
|
Classifier token usage and catalog-priced input cost appear in the local Jev session summary. Pi's catalog input/cache rates are authoritative; JEV output tokens are always free and native classifier usage is normalized to zero output cost even when a catalog carries an output rate. During `ask_advisor` screening, classifier usage is combined with Advisor usage once in the tool result and included in Pi cost totals (under the generic tools bucket). Manual and turn-gate classifier calls remain local-only for Pi totals because Pi exposes no supported lifecycle usage-attribution API.
|
package/dist/index.js
CHANGED
|
@@ -8758,6 +8758,43 @@ var registerCommands = (pi, dependencies = {}) => {
|
|
|
8758
8758
|
registerSettingsCommands(runtime);
|
|
8759
8759
|
};
|
|
8760
8760
|
|
|
8761
|
+
// src/tools/budget-feedback.ts
|
|
8762
|
+
var advisorBudgetMessage = (session) => {
|
|
8763
|
+
const simple = isSimpleMode();
|
|
8764
|
+
const remaining = simple ? undefined : session.remainingCalls(getAdvisorMaxCallsPerSession());
|
|
8765
|
+
return {
|
|
8766
|
+
content: [
|
|
8767
|
+
`Advisor calls remaining this session: ${remaining ?? "unlimited"}.`,
|
|
8768
|
+
simple ? "Call budgets are disabled in Simple mode." : undefined,
|
|
8769
|
+
"This is the current available allowance after consumed and reserved calls. Do not subtract earlier consultations again; this report supersedes earlier budget reports."
|
|
8770
|
+
].filter(Boolean).join(`
|
|
8771
|
+
`),
|
|
8772
|
+
customType: "advisor-budget",
|
|
8773
|
+
display: false
|
|
8774
|
+
};
|
|
8775
|
+
};
|
|
8776
|
+
var advisorBudgetUpdate = (event, ctx, pi, session) => {
|
|
8777
|
+
if (!pi.getActiveTools().includes("ask_advisor")) {
|
|
8778
|
+
return;
|
|
8779
|
+
}
|
|
8780
|
+
try {
|
|
8781
|
+
loadConfig(ctx);
|
|
8782
|
+
} catch {
|
|
8783
|
+
return;
|
|
8784
|
+
}
|
|
8785
|
+
if (!advisorToolsEnabledRef || !advisorModelIsAllowed(ctx)) {
|
|
8786
|
+
return;
|
|
8787
|
+
}
|
|
8788
|
+
const message = advisorBudgetMessage(session);
|
|
8789
|
+
const previous = event.context?.contextMessages.findLast((entry) => entry.role === "custom" && entry.customType === "advisor-budget");
|
|
8790
|
+
if (previous?.role === "custom" && previous.content === message.content) {
|
|
8791
|
+
return;
|
|
8792
|
+
}
|
|
8793
|
+
return {
|
|
8794
|
+
entries: [{ ...message, type: "custom_message" }]
|
|
8795
|
+
};
|
|
8796
|
+
};
|
|
8797
|
+
|
|
8761
8798
|
// src/tools/gate-policy.ts
|
|
8762
8799
|
var updateAdvisorUsageStatus = (ctx, session) => {
|
|
8763
8800
|
if (ctx.hasUI) {
|
|
@@ -9576,20 +9613,19 @@ var registerToolLifecycle = ({
|
|
|
9576
9613
|
return;
|
|
9577
9614
|
}
|
|
9578
9615
|
loadConfig(ctx);
|
|
9579
|
-
if (!advisorModelAccess(ctx).allowed || sameModelAdvisorDisabled(ctx)) {
|
|
9616
|
+
if (!advisorToolsEnabledRef || !advisorModelAccess(ctx).allowed || sameModelAdvisorDisabled(ctx)) {
|
|
9580
9617
|
return;
|
|
9581
9618
|
}
|
|
9582
9619
|
const guidelines = advisorInvocationGuidelines();
|
|
9583
|
-
|
|
9584
|
-
|
|
9585
|
-
guidelines.push(`Advisor calls remaining this session: ${budget}.
|
|
9586
|
-
Reserve calls for material decisions, repeated failures, or final review.`);
|
|
9620
|
+
if (!isSimpleMode()) {
|
|
9621
|
+
guidelines.push("Use the latest advisor-budget message for the current call allowance. Reserve calls for material decisions, repeated failures, or final review.");
|
|
9587
9622
|
}
|
|
9588
9623
|
if (guidelines.length > 0) {
|
|
9589
9624
|
sections.advisor_invocation_settings = `Advisor invocation settings:
|
|
9590
9625
|
${guidelines.map((rule) => `- ${rule}`).join(`
|
|
9591
9626
|
`)}`;
|
|
9592
9627
|
}
|
|
9628
|
+
return { message: advisorBudgetMessage(session) };
|
|
9593
9629
|
});
|
|
9594
9630
|
pi.on("input", () => {
|
|
9595
9631
|
session.clearFollowUps();
|
|
@@ -9828,7 +9864,10 @@ var registerAdvisorTool = (pi, session = sessionStateFor(pi), dependencies = {})
|
|
|
9828
9864
|
if (dependencies.turnGateDeps) {
|
|
9829
9865
|
turnGate.deps = dependencies.turnGateDeps;
|
|
9830
9866
|
}
|
|
9831
|
-
registerJevTurnGate((event, handler) => pi.on(event,
|
|
9867
|
+
registerJevTurnGate((event, handler) => pi.on(event, async (turn, ctx) => {
|
|
9868
|
+
await handler(turn, ctx);
|
|
9869
|
+
return advisorBudgetUpdate(turn, ctx, pi, session);
|
|
9870
|
+
}), turnGate);
|
|
9832
9871
|
};
|
|
9833
9872
|
|
|
9834
9873
|
// extensions/index.ts
|
package/package.json
CHANGED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ExtensionAPI,
|
|
3
|
+
ExtensionContext,
|
|
4
|
+
TurnEndEvent,
|
|
5
|
+
} from "@earendil-works/pi-coding-agent";
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
advisorToolsEnabledRef,
|
|
9
|
+
getAdvisorMaxCallsPerSession,
|
|
10
|
+
isSimpleMode,
|
|
11
|
+
} from "../config/state.ts";
|
|
12
|
+
import { loadConfig } from "../config/storage.ts";
|
|
13
|
+
import type { AdvisorSessionState } from "../session-state.ts";
|
|
14
|
+
import { advisorModelIsAllowed } from "./model-access.ts";
|
|
15
|
+
|
|
16
|
+
export const advisorBudgetMessage = (session: AdvisorSessionState) => {
|
|
17
|
+
const simple = isSimpleMode();
|
|
18
|
+
|
|
19
|
+
const remaining = simple
|
|
20
|
+
? undefined
|
|
21
|
+
: session.remainingCalls(getAdvisorMaxCallsPerSession());
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
content: [
|
|
25
|
+
`Advisor calls remaining this session: ${remaining ?? "unlimited"}.`,
|
|
26
|
+
simple ? "Call budgets are disabled in Simple mode." : undefined,
|
|
27
|
+
"This is the current available allowance after consumed and reserved calls. Do not subtract earlier consultations again; this report supersedes earlier budget reports.",
|
|
28
|
+
]
|
|
29
|
+
.filter(Boolean)
|
|
30
|
+
.join("\n"),
|
|
31
|
+
customType: "advisor-budget",
|
|
32
|
+
display: false,
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const advisorBudgetUpdate = (
|
|
37
|
+
event: TurnEndEvent,
|
|
38
|
+
ctx: ExtensionContext,
|
|
39
|
+
pi: ExtensionAPI,
|
|
40
|
+
session: AdvisorSessionState
|
|
41
|
+
) => {
|
|
42
|
+
if (!pi.getActiveTools().includes("ask_advisor")) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
loadConfig(ctx);
|
|
48
|
+
} catch {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (!advisorToolsEnabledRef || !advisorModelIsAllowed(ctx)) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const message = advisorBudgetMessage(session);
|
|
57
|
+
|
|
58
|
+
const previous = event.context?.contextMessages.findLast(
|
|
59
|
+
(entry) => entry.role === "custom" && entry.customType === "advisor-budget"
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
if (previous?.role === "custom" && previous.content === message.content) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
entries: [{ ...message, type: "custom_message" as const }],
|
|
68
|
+
};
|
|
69
|
+
};
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
isSimpleMode,
|
|
6
6
|
} from "../config/state.ts";
|
|
7
7
|
import { loadConfig } from "../config/storage.ts";
|
|
8
|
+
import { advisorBudgetMessage } from "./budget-feedback.ts";
|
|
8
9
|
import { reserveAdvisorCall } from "./gate-policy.ts";
|
|
9
10
|
import { handleAutomaticGate } from "./loop-gate.ts";
|
|
10
11
|
import {
|
|
@@ -96,25 +97,27 @@ export const registerToolLifecycle = ({
|
|
|
96
97
|
|
|
97
98
|
loadConfig(ctx);
|
|
98
99
|
|
|
99
|
-
if (
|
|
100
|
+
if (
|
|
101
|
+
!advisorToolsEnabledRef ||
|
|
102
|
+
!advisorModelAccess(ctx).allowed ||
|
|
103
|
+
sameModelAdvisorDisabled(ctx)
|
|
104
|
+
) {
|
|
100
105
|
return;
|
|
101
106
|
}
|
|
102
107
|
|
|
103
108
|
const guidelines = advisorInvocationGuidelines();
|
|
104
109
|
|
|
105
|
-
|
|
106
|
-
? undefined
|
|
107
|
-
: session.remainingCalls(getAdvisorMaxCallsPerSession());
|
|
108
|
-
|
|
109
|
-
if (budget !== undefined) {
|
|
110
|
+
if (!isSimpleMode()) {
|
|
110
111
|
guidelines.push(
|
|
111
|
-
|
|
112
|
+
"Use the latest advisor-budget message for the current call allowance. Reserve calls for material decisions, repeated failures, or final review."
|
|
112
113
|
);
|
|
113
114
|
}
|
|
114
115
|
|
|
115
116
|
if (guidelines.length > 0) {
|
|
116
117
|
sections.advisor_invocation_settings = `Advisor invocation settings:\n${guidelines.map((rule) => `- ${rule}`).join("\n")}`;
|
|
117
118
|
}
|
|
119
|
+
|
|
120
|
+
return { message: advisorBudgetMessage(session) };
|
|
118
121
|
});
|
|
119
122
|
|
|
120
123
|
pi.on("input", () => {
|
|
@@ -3,6 +3,7 @@ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
|
3
3
|
import { herdrAdvisorActivity, herdrAdvisorBlock } from "../herdr.ts";
|
|
4
4
|
import { appendOutcome } from "../outcomes.ts";
|
|
5
5
|
import type { AdvisorSessionState } from "../session-state.ts";
|
|
6
|
+
import { advisorBudgetUpdate } from "./budget-feedback.ts";
|
|
6
7
|
import { consultAdvisor, runAdvisorGate } from "./consultation.ts";
|
|
7
8
|
import { screenConsultation } from "./jev-filter.ts";
|
|
8
9
|
import { registerJevTurnGate } from "./jev-turn-gate.ts";
|
|
@@ -53,5 +54,13 @@ export const registerAdvisorTool = (
|
|
|
53
54
|
turnGate.deps = dependencies.turnGateDeps;
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
registerJevTurnGate(
|
|
57
|
+
registerJevTurnGate(
|
|
58
|
+
(event, handler) =>
|
|
59
|
+
pi.on(event, async (turn, ctx) => {
|
|
60
|
+
await handler(turn, ctx);
|
|
61
|
+
|
|
62
|
+
return advisorBudgetUpdate(turn, ctx, pi, session);
|
|
63
|
+
}),
|
|
64
|
+
turnGate
|
|
65
|
+
);
|
|
57
66
|
};
|