pi-advisor-flow 0.13.1-dev.1 → 0.13.2-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 +6 -0
- package/dist/index.js +14 -7
- package/extensions/index.ts +6 -0
- package/package.json +9 -9
- package/scripts/check-bun-version.mjs +9 -0
- package/src/attachments.ts +36 -0
- package/src/child-session.ts +1 -0
- package/src/commands/activation-preparation.ts +12 -0
- package/src/commands/activation.ts +43 -0
- package/src/commands/advisor-tools.ts +3 -0
- package/src/commands/lifecycle.ts +15 -0
- package/src/commands/manual-command.ts +19 -0
- package/src/commands/manual-consultation.ts +20 -0
- package/src/commands/manual-progress.ts +13 -0
- package/src/commands/model-commands.ts +4 -0
- package/src/commands/model-options.ts +18 -0
- package/src/commands/model-picker.ts +16 -0
- package/src/commands/outcome-stats.ts +9 -0
- package/src/commands/registration.ts +1 -0
- package/src/commands/renderers.ts +14 -0
- package/src/commands/runtime.ts +5 -0
- package/src/commands/settings-commands.ts +18 -0
- package/src/commands/settings-persistence.ts +2 -0
- package/src/commands.ts +1 -0
- package/src/config/args.ts +7 -0
- package/src/config/defaults.ts +1 -0
- package/src/config/schema.ts +1 -0
- package/src/config/state.ts +64 -1
- package/src/config/storage.ts +37 -0
- package/src/config/types.ts +9 -0
- package/src/config/validation.ts +7 -0
- package/src/config.ts +6 -0
- package/src/content-utils.ts +5 -0
- package/src/conversation.ts +39 -0
- package/src/follow-up.ts +8 -0
- package/src/git.ts +8 -0
- package/src/herdr-block.ts +7 -0
- package/src/herdr-shared.ts +23 -0
- package/src/herdr.ts +18 -0
- package/src/image-attachments.ts +24 -0
- package/src/image-validation.ts +58 -0
- package/src/images.ts +24 -0
- package/src/jev/base-url.ts +14 -0
- package/src/jev/client.ts +49 -0
- package/src/jev/decisions-client.ts +14 -0
- package/src/jev/decisions-response.ts +38 -0
- package/src/jev/endpoint-key-store.ts +18 -0
- package/src/jev/key-store.ts +28 -0
- package/src/jev/ledger.ts +30 -12
- package/src/jev/openai-key-store.ts +17 -0
- package/src/jev/questions.ts +15 -0
- package/src/jev/state.ts +5 -0
- package/src/jev/transport.ts +35 -0
- package/src/model-stream.ts +32 -0
- package/src/outcome-stats.ts +16 -0
- package/src/outcomes.ts +31 -0
- package/src/pi-settings.ts +9 -0
- package/src/preferences.ts +26 -0
- package/src/redaction.ts +8 -0
- package/src/scout-context.ts +17 -0
- package/src/scout-curation.ts +12 -0
- package/src/scout-groups.ts +47 -0
- package/src/scout-protocol.ts +17 -0
- package/src/scout-reconstruct.ts +12 -0
- package/src/scout.ts +47 -0
- package/src/session-context.ts +11 -0
- package/src/session-state.ts +73 -13
- package/src/tool-result-cap.ts +11 -0
- package/src/tools/consult-context.ts +24 -0
- package/src/tools/consultation.ts +43 -0
- package/src/tools/gate-policy.ts +18 -0
- package/src/tools/gate-protocol.ts +22 -0
- package/src/tools/jev-filter.ts +26 -0
- package/src/tools/jev-turn-gate.ts +17 -0
- package/src/tools/loop-gate.ts +25 -0
- package/src/tools/model-access.ts +12 -0
- package/src/tools/outage-notifier.ts +4 -0
- package/src/tools/prompts.ts +17 -0
- package/src/tools/register-ask-advisor.ts +44 -0
- package/src/tools/register-lifecycle.ts +32 -0
- package/src/tools/register-outcome.ts +7 -0
- package/src/tools/register-renderers.ts +14 -0
- package/src/tools/registration.ts +3 -0
- package/src/tools/render-advisor-result.ts +44 -0
- package/src/tools/render-common.ts +10 -0
- package/src/tools/scout-status.ts +34 -0
- package/src/tools/session.ts +3 -0
- package/src/tools.ts +8 -0
- package/src/ui/jev-filter-submenu.ts +21 -0
- package/src/ui/jev-provider-submenu-view.ts +22 -0
- package/src/ui/jev-provider-submenu.ts +81 -0
- package/src/ui/jev-setup-support.ts +26 -0
- package/src/ui/manual-dialog-render.ts +20 -0
- package/src/ui/manual-dialog.ts +38 -0
- package/src/ui/masked-input.ts +2 -0
- package/src/ui/searchable-model-list.ts +28 -0
- package/src/ui/settings-formatting.ts +26 -0
- package/src/ui/settings-items.ts +11 -0
- package/src/ui/settings-list-adapter.ts +13 -0
- package/src/ui/settings-mutations.ts +60 -0
- package/src/ui/settings-selector.ts +30 -0
- package/src/ui/text-setting-submenu.ts +9 -0
- package/src/ui-guard.ts +1 -0
- package/src/ui.ts +3 -0
- package/src/usage.ts +31 -0
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,12 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
|
|
|
6
6
|
|
|
7
7
|
## Unreleased
|
|
8
8
|
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
- Updated development dependencies: Pi packages to 1.2.0, Oxlint and plugins to 1.88.0, Oxfmt to 0.73.0, TypeBox to 1.3.37, and Ultracite to 8.0.1; adopted Ultracite 8's readable-spacing rule across the codebase and excluded the deliberately JSON-shaped benchmark `traps.toml` fixtures from Oxfmt's new TOML support.
|
|
12
|
+
|
|
13
|
+
## 0.13.1 - 2026-10-11
|
|
14
|
+
|
|
9
15
|
### Fixed
|
|
10
16
|
|
|
11
17
|
- Persisted `/advisor-off` across new sessions by adding a separately configurable Advisor-tools opt-out, while preserving default on-demand tool availability; successful `/advisor` activation re-enables the tools.
|
package/dist/index.js
CHANGED
|
@@ -156,7 +156,10 @@ var setAdvisorMaxCallsPerSessionRef = (value) => {
|
|
|
156
156
|
};
|
|
157
157
|
var setAdvisorModelWhitelistRef = (models) => {
|
|
158
158
|
advisorModelWhitelistRef = [
|
|
159
|
-
...new Set(models.
|
|
159
|
+
...new Set(models.flatMap((model) => {
|
|
160
|
+
const trimmed = model.trim();
|
|
161
|
+
return trimmed ? [trimmed] : [];
|
|
162
|
+
}))
|
|
160
163
|
];
|
|
161
164
|
};
|
|
162
165
|
var setAdvisorSessionSummaryRef = (enabled) => {
|
|
@@ -4830,7 +4833,7 @@ var jevCostText = (usage) => {
|
|
|
4830
4833
|
}
|
|
4831
4834
|
return `$${usage.cost.toFixed(4)}`;
|
|
4832
4835
|
};
|
|
4833
|
-
var markdownCosts = (invocations) => invocations.
|
|
4836
|
+
var markdownCosts = (invocations) => invocations.flatMap((item) => item.kind === "markdown" && item.cost !== undefined ? [item.cost] : []);
|
|
4834
4837
|
var filterLine = (filter) => {
|
|
4835
4838
|
const head = `${filter.screened} screened (${filter.allowed} allowed, ${filter.skipped} skipped${filter.repeatSkipped > 0 ? ` [${filter.repeatSkipped} repeat]` : ""})`;
|
|
4836
4839
|
const parts = [head];
|
|
@@ -4843,7 +4846,7 @@ var filterLine = (filter) => {
|
|
|
4843
4846
|
return `Jev/Decisions filter: ${parts.join(", ")}`;
|
|
4844
4847
|
};
|
|
4845
4848
|
var gateLine = (gate, invocations) => {
|
|
4846
|
-
const consultationCosts = invocations.
|
|
4849
|
+
const consultationCosts = invocations.flatMap((item) => item.trigger === "turn-gate" && item.cost !== undefined ? [item.cost] : []);
|
|
4847
4850
|
const gateSpend = consultationCosts.reduce((sum, cost) => sum + cost, 0);
|
|
4848
4851
|
return `Turn gate: ${gate.checks} check${gate.checks === 1 ? "" : "s"} (Jev/Decisions ${formatJevTokens(gate.usage)} · ${jevCostText(gate.usage)}), ${gate.consultations} consultation${gate.consultations === 1 ? "" : "s"} ($${gateSpend.toFixed(4)})`;
|
|
4849
4852
|
};
|
|
@@ -5205,10 +5208,14 @@ class AdvisorSessionState {
|
|
|
5205
5208
|
}
|
|
5206
5209
|
#decisionsLine() {
|
|
5207
5210
|
const gates = this.#usage.invocations.filter((item) => item.kind === "gate");
|
|
5208
|
-
|
|
5209
|
-
|
|
5210
|
-
gates.filter((item) => item.decision === decision).length
|
|
5211
|
-
|
|
5211
|
+
const parts = [];
|
|
5212
|
+
for (const decision of ["proceed", "revise", "blocked"]) {
|
|
5213
|
+
const count = gates.filter((item) => item.decision === decision).length;
|
|
5214
|
+
if (count > 0) {
|
|
5215
|
+
parts.push(`${count} ${decision}`);
|
|
5216
|
+
}
|
|
5217
|
+
}
|
|
5218
|
+
return parts.join(", ") || "none";
|
|
5212
5219
|
}
|
|
5213
5220
|
#countTrigger(trigger) {
|
|
5214
5221
|
return this.#usage.invocations.filter((item) => item.trigger === trigger).length;
|
package/extensions/index.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { registerAdvisorTool } from "../src/tools/registration.ts";
|
|
|
13
13
|
import { ScoutStatusManager } from "../src/tools/scout-status.ts";
|
|
14
14
|
|
|
15
15
|
export type { AdvisorConfig, GateFailureMode } from "../src/config/types.ts";
|
|
16
|
+
|
|
16
17
|
export type {
|
|
17
18
|
AdvisorConsultationResult,
|
|
18
19
|
AdvisorGateFailure,
|
|
@@ -22,12 +23,15 @@ export type {
|
|
|
22
23
|
GateDecision,
|
|
23
24
|
GateTrigger,
|
|
24
25
|
} from "../src/tools/types.ts";
|
|
26
|
+
|
|
25
27
|
export const consultAdvisor = (
|
|
26
28
|
...args: Parameters<typeof consultAdvisorImplementation>
|
|
27
29
|
) => consultAdvisorImplementation(...args);
|
|
30
|
+
|
|
28
31
|
export const parseAutomaticDecision = (
|
|
29
32
|
...args: Parameters<typeof parseAutomaticDecisionImplementation>
|
|
30
33
|
) => parseAutomaticDecisionImplementation(...args);
|
|
34
|
+
|
|
31
35
|
export const runAdvisorGate = (
|
|
32
36
|
...args: Parameters<typeof runAdvisorGateImplementation>
|
|
33
37
|
) => runAdvisorGateImplementation(...args);
|
|
@@ -36,6 +40,7 @@ export default function registerPiAdvisor(pi: ExtensionAPI) {
|
|
|
36
40
|
const sessionState = new AdvisorSessionState();
|
|
37
41
|
const scoutStatus = new ScoutStatusManager();
|
|
38
42
|
const herdrActivity = herdrAdvisorActivity.createScope();
|
|
43
|
+
|
|
39
44
|
const herdrBlock = new HerdrAdvisorBlock(
|
|
40
45
|
undefined,
|
|
41
46
|
() => getAdvisorSettings().herdrIntegration,
|
|
@@ -43,6 +48,7 @@ export default function registerPiAdvisor(pi: ExtensionAPI) {
|
|
|
43
48
|
pi.events.emit("herdr:blocked", { active, label });
|
|
44
49
|
}
|
|
45
50
|
);
|
|
51
|
+
|
|
46
52
|
registerAdvisorTool(pi, sessionState, {
|
|
47
53
|
herdrActivity,
|
|
48
54
|
herdrBlock,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-advisor-flow",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.2-dev.1",
|
|
4
4
|
"description": "Advanced Executor/Advisor flow for Pi, fully configurable and extendable.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"advisor",
|
|
@@ -54,21 +54,21 @@
|
|
|
54
54
|
"format:check": "oxfmt --check"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@earendil-works/pi-ai": "1.
|
|
58
|
-
"@earendil-works/pi-coding-agent": "1.
|
|
59
|
-
"@earendil-works/pi-tui": "1.
|
|
60
|
-
"@oxlint/plugins": "1.
|
|
57
|
+
"@earendil-works/pi-ai": "1.2.0",
|
|
58
|
+
"@earendil-works/pi-coding-agent": "1.2.0",
|
|
59
|
+
"@earendil-works/pi-tui": "1.2.0",
|
|
60
|
+
"@oxlint/plugins": "1.88.0",
|
|
61
61
|
"@types/node": "^26.6.5",
|
|
62
62
|
"@typesafe-ai/sdk": "^0.6.0",
|
|
63
63
|
"bun-types": "1.4.3",
|
|
64
64
|
"husky": "^9.1.7",
|
|
65
65
|
"knip": "6.41.0",
|
|
66
66
|
"lint-staged": "^17.6.0",
|
|
67
|
-
"oxfmt": "0.
|
|
68
|
-
"oxlint": "1.
|
|
69
|
-
"typebox": "^1.3.
|
|
67
|
+
"oxfmt": "0.73.0",
|
|
68
|
+
"oxlint": "1.88.0",
|
|
69
|
+
"typebox": "^1.3.37",
|
|
70
70
|
"typescript": "^7.0.2",
|
|
71
|
-
"ultracite": "
|
|
71
|
+
"ultracite": "8.0.1"
|
|
72
72
|
},
|
|
73
73
|
"peerDependencies": {
|
|
74
74
|
"@earendil-works/pi-ai": "^1.0.0",
|
|
@@ -3,11 +3,13 @@ import { resolve } from "node:path";
|
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
|
|
5
5
|
const projectRoot = resolve(fileURLToPath(new URL("..", import.meta.url)));
|
|
6
|
+
|
|
6
7
|
if (!existsSync(resolve(projectRoot, "bun.lock"))) {
|
|
7
8
|
process.exit(0);
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
const localPrefix = process.env.npm_config_local_prefix;
|
|
12
|
+
|
|
11
13
|
if (localPrefix && resolve(localPrefix) !== projectRoot) {
|
|
12
14
|
process.exit(0);
|
|
13
15
|
}
|
|
@@ -15,9 +17,11 @@ if (localPrefix && resolve(localPrefix) !== projectRoot) {
|
|
|
15
17
|
const packageJson = JSON.parse(
|
|
16
18
|
readFileSync(resolve(projectRoot, "package.json"), "utf-8")
|
|
17
19
|
);
|
|
20
|
+
|
|
18
21
|
const minimumVersion = /^bun@(?<version>\d+\.\d+\.\d+)$/u.exec(
|
|
19
22
|
packageJson.packageManager ?? ""
|
|
20
23
|
)?.groups?.version;
|
|
24
|
+
|
|
21
25
|
const currentVersion = /^bun\/(?<version>[^\s]+)/u.exec(
|
|
22
26
|
process.env.npm_config_user_agent ?? ""
|
|
23
27
|
)?.groups?.version;
|
|
@@ -27,10 +31,12 @@ const isAtLeast = (version, minimum) => {
|
|
|
27
31
|
/^(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)(?:-(?<prerelease>[^\s]+))?$/u.exec(
|
|
28
32
|
version
|
|
29
33
|
)?.groups;
|
|
34
|
+
|
|
30
35
|
const required =
|
|
31
36
|
/^(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)(?:-(?<prerelease>[^\s]+))?$/u.exec(
|
|
32
37
|
minimum
|
|
33
38
|
)?.groups;
|
|
39
|
+
|
|
34
40
|
if (!current || !required) {
|
|
35
41
|
return false;
|
|
36
42
|
}
|
|
@@ -38,11 +44,14 @@ const isAtLeast = (version, minimum) => {
|
|
|
38
44
|
const currentParts = [current.major, current.minor, current.patch].map(
|
|
39
45
|
Number
|
|
40
46
|
);
|
|
47
|
+
|
|
41
48
|
const requiredParts = [required.major, required.minor, required.patch].map(
|
|
42
49
|
Number
|
|
43
50
|
);
|
|
51
|
+
|
|
44
52
|
for (let index = 0; index < currentParts.length; index += 1) {
|
|
45
53
|
const difference = currentParts[index] - requiredParts[index];
|
|
54
|
+
|
|
46
55
|
if (difference !== 0) {
|
|
47
56
|
return difference > 0;
|
|
48
57
|
}
|
package/src/attachments.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { redactAndCapText } from "./redaction.ts";
|
|
|
8
8
|
|
|
9
9
|
export const ADVISOR_FILE_MAX_BYTES = 8 * 1024;
|
|
10
10
|
const ADVISOR_FILES_TOTAL_MAX_BYTES = 24 * 1024;
|
|
11
|
+
|
|
11
12
|
export interface UntrackedAttachment {
|
|
12
13
|
bytes: number;
|
|
13
14
|
path: string;
|
|
@@ -21,8 +22,10 @@ const imageExtensions = new Map([
|
|
|
21
22
|
[".gif", "image/gif"],
|
|
22
23
|
[".webp", "image/webp"],
|
|
23
24
|
]);
|
|
25
|
+
|
|
24
26
|
export const imageMime = (path: string) =>
|
|
25
27
|
imageExtensions.get(path.slice(path.lastIndexOf(".")).toLowerCase());
|
|
28
|
+
|
|
26
29
|
export const imageFileCandidate = (path: string) =>
|
|
27
30
|
Boolean(imageMime(path)) || /\.(?:avif|bmp|heic|svg|tiff?)$/iu.test(path);
|
|
28
31
|
|
|
@@ -30,8 +33,10 @@ const PATH_SEGMENTS = /[\\/]/u;
|
|
|
30
33
|
|
|
31
34
|
export const within = (root: string, candidate: string) => {
|
|
32
35
|
const path = relative(root, candidate);
|
|
36
|
+
|
|
33
37
|
return path !== "" && !path.startsWith("..") && !path.includes("../");
|
|
34
38
|
};
|
|
39
|
+
|
|
35
40
|
const normalizeRelativePath = (root: string, path: string) =>
|
|
36
41
|
relative(root, resolve(root, path));
|
|
37
42
|
|
|
@@ -44,6 +49,7 @@ export const normalizeRequestedPath = (root: string, value: string) => {
|
|
|
44
49
|
) {
|
|
45
50
|
return;
|
|
46
51
|
}
|
|
52
|
+
|
|
47
53
|
return normalizeRelativePath(root, value);
|
|
48
54
|
};
|
|
49
55
|
|
|
@@ -75,7 +81,9 @@ const untracked = (cwd: string, path: string) => {
|
|
|
75
81
|
"--",
|
|
76
82
|
path,
|
|
77
83
|
]);
|
|
84
|
+
|
|
78
85
|
const expected = normalizeRelativePath(cwd, path);
|
|
86
|
+
|
|
79
87
|
return output
|
|
80
88
|
.split("\0")
|
|
81
89
|
.filter(Boolean)
|
|
@@ -85,11 +93,14 @@ const untracked = (cwd: string, path: string) => {
|
|
|
85
93
|
const tracked = (cwd: string, path: string) => {
|
|
86
94
|
const output = git(cwd, ["ls-files", "--stage", "-z", "--", path]);
|
|
87
95
|
const expected = normalizeRelativePath(cwd, path);
|
|
96
|
+
|
|
88
97
|
return output.split("\0").some((entry) => {
|
|
89
98
|
if (!entry) {
|
|
90
99
|
return false;
|
|
91
100
|
}
|
|
101
|
+
|
|
92
102
|
const [metadata, name] = entry.split("\t");
|
|
103
|
+
|
|
93
104
|
return (
|
|
94
105
|
name &&
|
|
95
106
|
normalizeRelativePath(cwd, name) === expected &&
|
|
@@ -111,34 +122,47 @@ const readAttachment = async (
|
|
|
111
122
|
available: number
|
|
112
123
|
): Promise<UntrackedAttachment | undefined> => {
|
|
113
124
|
const absolute = resolve(root, normalizedName);
|
|
125
|
+
|
|
114
126
|
if (!(within(root, absolute) && available > 0)) {
|
|
115
127
|
return;
|
|
116
128
|
}
|
|
129
|
+
|
|
117
130
|
const stats = await lstat(absolute);
|
|
131
|
+
|
|
118
132
|
if (stats.isSymbolicLink() || !stats.isFile()) {
|
|
119
133
|
return;
|
|
120
134
|
}
|
|
135
|
+
|
|
121
136
|
const resolved = await realpath(absolute);
|
|
137
|
+
|
|
122
138
|
if (!within(root, resolved)) {
|
|
123
139
|
return;
|
|
124
140
|
}
|
|
141
|
+
|
|
125
142
|
// fs.open needs combined numeric flags for O_NOFOLLOW; O_RDONLY (0) and O_NOFOLLOW occupy disjoint bits, so + is exact.
|
|
126
143
|
const flags = constants.O_NOFOLLOW
|
|
127
144
|
? constants.O_RDONLY + constants.O_NOFOLLOW
|
|
128
145
|
: constants.O_RDONLY;
|
|
146
|
+
|
|
129
147
|
const file = await open(resolved, flags);
|
|
148
|
+
|
|
130
149
|
try {
|
|
131
150
|
const openedStats = await file.stat();
|
|
151
|
+
|
|
132
152
|
if (!openedStats.isFile()) {
|
|
133
153
|
return;
|
|
134
154
|
}
|
|
155
|
+
|
|
135
156
|
const buffer = Buffer.alloc(available + 1);
|
|
136
157
|
const { bytesRead } = await file.read(buffer, 0, buffer.length, 0);
|
|
137
158
|
const raw = buffer.subarray(0, bytesRead).toString("utf-8");
|
|
159
|
+
|
|
138
160
|
if (raw.includes("\0")) {
|
|
139
161
|
return;
|
|
140
162
|
}
|
|
163
|
+
|
|
141
164
|
const text = redactAndCapText(raw, available, redact);
|
|
165
|
+
|
|
142
166
|
return {
|
|
143
167
|
bytes: Buffer.byteLength(text, "utf-8"),
|
|
144
168
|
path: normalizedName,
|
|
@@ -161,15 +185,20 @@ const readFiles = async (
|
|
|
161
185
|
if (!(enabled && Array.isArray(requested))) {
|
|
162
186
|
return [];
|
|
163
187
|
}
|
|
188
|
+
|
|
164
189
|
const root = await repositoryRoot(cwd);
|
|
190
|
+
|
|
165
191
|
if (!root) {
|
|
166
192
|
return [];
|
|
167
193
|
}
|
|
194
|
+
|
|
168
195
|
const unique = new Set<string>();
|
|
169
196
|
const attachments: UntrackedAttachment[] = [];
|
|
170
197
|
let total = 0;
|
|
198
|
+
|
|
171
199
|
for (const name of requested) {
|
|
172
200
|
const normalizedName = normalizeRequestedPath(root, name);
|
|
201
|
+
|
|
173
202
|
if (
|
|
174
203
|
!normalizedName ||
|
|
175
204
|
unique.has(normalizedName) ||
|
|
@@ -177,15 +206,20 @@ const readFiles = async (
|
|
|
177
206
|
) {
|
|
178
207
|
continue;
|
|
179
208
|
}
|
|
209
|
+
|
|
180
210
|
unique.add(normalizedName);
|
|
211
|
+
|
|
181
212
|
try {
|
|
182
213
|
if (!isPermitted(root, normalizedName, kind)) {
|
|
183
214
|
continue;
|
|
184
215
|
}
|
|
216
|
+
|
|
185
217
|
const available = Math.min(ADVISOR_FILE_MAX_BYTES, totalLimit - total);
|
|
218
|
+
|
|
186
219
|
if (available <= 0) {
|
|
187
220
|
break;
|
|
188
221
|
}
|
|
222
|
+
|
|
189
223
|
// Sequentially enforce the aggregate disclosure budget.
|
|
190
224
|
const attachment = await readAttachment(
|
|
191
225
|
root,
|
|
@@ -193,6 +227,7 @@ const readFiles = async (
|
|
|
193
227
|
redact,
|
|
194
228
|
available
|
|
195
229
|
);
|
|
230
|
+
|
|
196
231
|
if (attachment) {
|
|
197
232
|
attachments.push(attachment);
|
|
198
233
|
total += attachment.bytes;
|
|
@@ -201,6 +236,7 @@ const readFiles = async (
|
|
|
201
236
|
/* refuse unreadable or non-git paths */
|
|
202
237
|
}
|
|
203
238
|
}
|
|
239
|
+
|
|
204
240
|
return attachments;
|
|
205
241
|
};
|
|
206
242
|
|
package/src/child-session.ts
CHANGED
|
@@ -31,6 +31,7 @@ export interface PreparedActivationModels {
|
|
|
31
31
|
export const loadCommandConfig = (ctx: ExtensionContext) => {
|
|
32
32
|
try {
|
|
33
33
|
loadConfig(ctx);
|
|
34
|
+
|
|
34
35
|
return true;
|
|
35
36
|
} catch (error) {
|
|
36
37
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -39,6 +40,7 @@ export const loadCommandConfig = (ctx: ExtensionContext) => {
|
|
|
39
40
|
`Advisor command could not load configuration: ${message} Fix advisor.json and retry.`,
|
|
40
41
|
"error"
|
|
41
42
|
);
|
|
43
|
+
|
|
42
44
|
return false;
|
|
43
45
|
}
|
|
44
46
|
};
|
|
@@ -53,6 +55,7 @@ export const prepareActivationModels = async (
|
|
|
53
55
|
const persisted = getPersistedModelRefs();
|
|
54
56
|
const availableRefs = getAvailableModelRefs(ctx);
|
|
55
57
|
const availableRefSet = availableRefs ? new Set(availableRefs) : undefined;
|
|
58
|
+
|
|
56
59
|
const explicitError =
|
|
57
60
|
getExplicitModelError(
|
|
58
61
|
ctx,
|
|
@@ -68,8 +71,10 @@ export const prepareActivationModels = async (
|
|
|
68
71
|
advisorOverride,
|
|
69
72
|
availableRefSet
|
|
70
73
|
);
|
|
74
|
+
|
|
71
75
|
if (explicitError) {
|
|
72
76
|
notify(ctx, explicitError, "error");
|
|
77
|
+
|
|
73
78
|
return;
|
|
74
79
|
}
|
|
75
80
|
|
|
@@ -83,7 +88,9 @@ export const prepareActivationModels = async (
|
|
|
83
88
|
advisorOverride,
|
|
84
89
|
availableRefSet
|
|
85
90
|
);
|
|
91
|
+
|
|
86
92
|
setExecutorRef(plan.pendingExecutor ?? executorRef);
|
|
93
|
+
|
|
87
94
|
if (!(plan.selectExecutor || plan.selectAdvisor)) {
|
|
88
95
|
return { pendingExecutor: plan.pendingExecutor, pickedModels: false };
|
|
89
96
|
}
|
|
@@ -96,8 +103,10 @@ export const prepareActivationModels = async (
|
|
|
96
103
|
"Advisor models are not configured or available. Run /advisor to choose them.",
|
|
97
104
|
"error"
|
|
98
105
|
);
|
|
106
|
+
|
|
99
107
|
return;
|
|
100
108
|
}
|
|
109
|
+
|
|
101
110
|
const selection = await selectAdvisorModels(ctx, {
|
|
102
111
|
advisor: advisorOverride || persisted.advisor ? advisorRef : "",
|
|
103
112
|
advisorEffort: advisorEffortRef,
|
|
@@ -110,13 +119,16 @@ export const prepareActivationModels = async (
|
|
|
110
119
|
selectAdvisor: plan.selectAdvisor,
|
|
111
120
|
selectExecutor: plan.selectExecutor,
|
|
112
121
|
});
|
|
122
|
+
|
|
113
123
|
if (!selection) {
|
|
114
124
|
return;
|
|
115
125
|
}
|
|
126
|
+
|
|
116
127
|
setAdvisorRef(selection.advisor);
|
|
117
128
|
setAdvisorFallbackModelRef(selection.advisorFallbackModel);
|
|
118
129
|
setAdvisorEffortRef(selection.advisorEffort);
|
|
119
130
|
setExecutorRef(selection.executor);
|
|
120
131
|
setExecutorEffortRef(selection.executorEffort);
|
|
132
|
+
|
|
121
133
|
return { pendingExecutor: plan.pendingExecutor, pickedModels: true };
|
|
122
134
|
};
|
|
@@ -44,7 +44,9 @@ const resolveActivationModels = async (
|
|
|
44
44
|
if (!canContinue()) {
|
|
45
45
|
return { cancelled: true };
|
|
46
46
|
}
|
|
47
|
+
|
|
47
48
|
const executor = findConfiguredModel(ctx, executorRef);
|
|
49
|
+
|
|
48
50
|
if (!executor) {
|
|
49
51
|
return {
|
|
50
52
|
error: executorRef
|
|
@@ -52,7 +54,9 @@ const resolveActivationModels = async (
|
|
|
52
54
|
: "Executor model not configured",
|
|
53
55
|
};
|
|
54
56
|
}
|
|
57
|
+
|
|
55
58
|
const advisor = findConfiguredModel(ctx, advisorRef);
|
|
59
|
+
|
|
56
60
|
if (!advisor) {
|
|
57
61
|
return {
|
|
58
62
|
error: advisorRef
|
|
@@ -60,16 +64,21 @@ const resolveActivationModels = async (
|
|
|
60
64
|
: "Advisor model not configured",
|
|
61
65
|
};
|
|
62
66
|
}
|
|
67
|
+
|
|
63
68
|
const advisorAuth = await ctx.modelRegistry.getApiKeyAndHeaders(advisor);
|
|
69
|
+
|
|
64
70
|
if (!canContinue()) {
|
|
65
71
|
return { cancelled: true };
|
|
66
72
|
}
|
|
73
|
+
|
|
67
74
|
if (!(advisorAuth.ok && advisorAuth.apiKey)) {
|
|
68
75
|
return { error: `No API key for Advisor ${advisorRef}` };
|
|
69
76
|
}
|
|
77
|
+
|
|
70
78
|
if (!isMarkedSubagent() && !(await runtime.setExecutorModel(executor))) {
|
|
71
79
|
return { error: `No API key for Executor ${executorRef}` };
|
|
72
80
|
}
|
|
81
|
+
|
|
73
82
|
return {};
|
|
74
83
|
};
|
|
75
84
|
|
|
@@ -99,19 +108,25 @@ const persistSuccessfulActivation = (
|
|
|
99
108
|
if (!shouldSave) {
|
|
100
109
|
return true;
|
|
101
110
|
}
|
|
111
|
+
|
|
102
112
|
try {
|
|
103
113
|
saveConfig(ctx, { persistAdvisor: true, persistExecutor: true });
|
|
104
114
|
} catch (saveError) {
|
|
105
115
|
if (!reenableTools) {
|
|
106
116
|
throw saveError;
|
|
107
117
|
}
|
|
118
|
+
|
|
108
119
|
setAdvisorToolsEnabledRef(false);
|
|
109
120
|
restoreRefs();
|
|
121
|
+
|
|
110
122
|
const message =
|
|
111
123
|
saveError instanceof Error ? saveError.message : String(saveError);
|
|
124
|
+
|
|
112
125
|
notify(ctx, `Could not save Advisor activation: ${message}`, "error");
|
|
126
|
+
|
|
113
127
|
return false;
|
|
114
128
|
}
|
|
129
|
+
|
|
115
130
|
return true;
|
|
116
131
|
};
|
|
117
132
|
|
|
@@ -124,9 +139,12 @@ export const activateAdvisor = async (
|
|
|
124
139
|
if (!loadCommandConfig(ctx)) {
|
|
125
140
|
return;
|
|
126
141
|
}
|
|
142
|
+
|
|
127
143
|
const { toolAvailabilityRevision } = runtime;
|
|
144
|
+
|
|
128
145
|
const canContinue = () =>
|
|
129
146
|
runtime.toolAvailabilityRevision === toolAvailabilityRevision;
|
|
147
|
+
|
|
130
148
|
const previous = {
|
|
131
149
|
advisor: advisorRef,
|
|
132
150
|
advisorEffort: advisorEffortRef,
|
|
@@ -134,34 +152,43 @@ export const activateAdvisor = async (
|
|
|
134
152
|
executor: executorRef,
|
|
135
153
|
executorEffort: executorEffortRef,
|
|
136
154
|
};
|
|
155
|
+
|
|
137
156
|
const liveSnapshot = liveRefSnapshot;
|
|
157
|
+
|
|
138
158
|
// Restores only refs this activation still owns. A concurrent settings
|
|
139
159
|
// save that replaced a ref keeps its newer value.
|
|
140
160
|
const restoreRefs = (attempted: ReturnType<typeof liveSnapshot>) => {
|
|
141
161
|
if (advisorRef === attempted.advisor) {
|
|
142
162
|
setAdvisorRef(previous.advisor);
|
|
143
163
|
}
|
|
164
|
+
|
|
144
165
|
if (advisorEffortRef === attempted.advisorEffort) {
|
|
145
166
|
setAdvisorEffortRef(previous.advisorEffort);
|
|
146
167
|
}
|
|
168
|
+
|
|
147
169
|
if (contextMaxCharsRef === attempted.contextMaxChars) {
|
|
148
170
|
setContextMaxCharsRef(previous.contextMaxChars);
|
|
149
171
|
}
|
|
172
|
+
|
|
150
173
|
if (executorRef === attempted.executor) {
|
|
151
174
|
setExecutorRef(previous.executor);
|
|
152
175
|
}
|
|
176
|
+
|
|
153
177
|
if (executorEffortRef === attempted.executorEffort) {
|
|
154
178
|
setExecutorEffortRef(previous.executorEffort);
|
|
155
179
|
}
|
|
156
180
|
};
|
|
181
|
+
|
|
157
182
|
let attempted = liveRefSnapshot();
|
|
158
183
|
const executorOverride = hasExecutorOverride(args);
|
|
159
184
|
const advisorOverride = hasAdvisorOverride(args);
|
|
160
185
|
const argumentError = parseArgs(args);
|
|
186
|
+
|
|
161
187
|
if (argumentError) {
|
|
162
188
|
attempted = liveRefSnapshot();
|
|
163
189
|
restoreRefs(attempted);
|
|
164
190
|
notify(ctx, argumentError, "error");
|
|
191
|
+
|
|
165
192
|
return;
|
|
166
193
|
}
|
|
167
194
|
|
|
@@ -172,37 +199,47 @@ export const activateAdvisor = async (
|
|
|
172
199
|
executorOverride,
|
|
173
200
|
advisorOverride
|
|
174
201
|
);
|
|
202
|
+
|
|
175
203
|
if (!prepared) {
|
|
176
204
|
attempted = liveRefSnapshot();
|
|
177
205
|
restoreActivationRefsIfCurrent(canContinue, () => restoreRefs(attempted));
|
|
206
|
+
|
|
178
207
|
return;
|
|
179
208
|
}
|
|
209
|
+
|
|
180
210
|
const { cancelled, error } = await resolveActivationModels(
|
|
181
211
|
runtime,
|
|
182
212
|
ctx,
|
|
183
213
|
canContinue
|
|
184
214
|
);
|
|
215
|
+
|
|
185
216
|
if (cancelled || !canContinue()) {
|
|
186
217
|
return;
|
|
187
218
|
}
|
|
219
|
+
|
|
188
220
|
if (error) {
|
|
189
221
|
restoreRefs(attempted);
|
|
190
222
|
notify(ctx, error, "error");
|
|
223
|
+
|
|
191
224
|
return;
|
|
192
225
|
}
|
|
226
|
+
|
|
193
227
|
// parseArgs, model picking, and an inactive `/model` selection only mutate
|
|
194
228
|
// in-memory refs. Persist them once both models are known and authenticated,
|
|
195
229
|
// so an unusable model reference is never written to the configuration.
|
|
196
230
|
const reenableTools = !advisorToolsEnabledRef;
|
|
231
|
+
|
|
197
232
|
if (reenableTools) {
|
|
198
233
|
setAdvisorToolsEnabledRef(true);
|
|
199
234
|
}
|
|
235
|
+
|
|
200
236
|
const shouldSave = Boolean(
|
|
201
237
|
args.trim() ||
|
|
202
238
|
prepared.pickedModels ||
|
|
203
239
|
prepared.pendingExecutor ||
|
|
204
240
|
reenableTools
|
|
205
241
|
);
|
|
242
|
+
|
|
206
243
|
if (
|
|
207
244
|
!persistSuccessfulActivation(ctx, shouldSave, reenableTools, () =>
|
|
208
245
|
restoreRefs(liveRefSnapshot())
|
|
@@ -210,19 +247,25 @@ export const activateAdvisor = async (
|
|
|
210
247
|
) {
|
|
211
248
|
return;
|
|
212
249
|
}
|
|
250
|
+
|
|
213
251
|
// A successful activation has committed the effective Executor. Do not let
|
|
214
252
|
// an older inactive selection override an explicit activation argument on a
|
|
215
253
|
// later attempt.
|
|
216
254
|
runtime.pendingExecutorModelRef = undefined;
|
|
255
|
+
|
|
217
256
|
if (executorEffortRef && !isMarkedSubagent()) {
|
|
218
257
|
// SAFETY: executorEffortRef is operator-configured and trusted to name a ThinkingLevel.
|
|
219
258
|
runtime.pi.setThinkingLevel(executorEffortRef as ThinkingLevel);
|
|
220
259
|
}
|
|
260
|
+
|
|
221
261
|
setAdvisorToolsActive(runtime.pi, true);
|
|
262
|
+
|
|
222
263
|
const activeModel = isMarkedSubagent()
|
|
223
264
|
? ctx.model
|
|
224
265
|
: findConfiguredModel(ctx, executorRef);
|
|
266
|
+
|
|
225
267
|
runtime.updateSameModelNotice(ctx, activeModel);
|
|
268
|
+
|
|
226
269
|
if (announce) {
|
|
227
270
|
const activeExecutorRef = effectiveExecutorRef(ctx);
|
|
228
271
|
const activeExecutorEffort = effectiveExecutorEffort(ctx);
|
|
@@ -7,9 +7,11 @@ export const setAdvisorToolsActive = (
|
|
|
7
7
|
enabled: boolean
|
|
8
8
|
) => {
|
|
9
9
|
const current = pi.getActiveTools();
|
|
10
|
+
|
|
10
11
|
const next = current.filter(
|
|
11
12
|
(name) => enabled || !ADVISOR_TOOL_NAMES.has(name)
|
|
12
13
|
);
|
|
14
|
+
|
|
13
15
|
if (enabled) {
|
|
14
16
|
for (const name of ADVISOR_TOOL_NAMES) {
|
|
15
17
|
if (!next.includes(name)) {
|
|
@@ -17,6 +19,7 @@ export const setAdvisorToolsActive = (
|
|
|
17
19
|
}
|
|
18
20
|
}
|
|
19
21
|
}
|
|
22
|
+
|
|
20
23
|
if (
|
|
21
24
|
next.length !== current.length ||
|
|
22
25
|
next.some((name, index) => name !== current[index])
|