pi-advisor-flow 0.16.1-dev.2 → 0.17.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 +14 -0
- package/README.md +17 -9
- package/dist/index.js +396 -106
- package/docs/configuration.md +21 -10
- package/docs/privacy.md +2 -2
- package/locales/de.json +8 -1
- package/locales/en.json +8 -1
- package/locales/fr.json +8 -1
- package/package.json +11 -11
- package/src/commands/activation-preparation.ts +30 -3
- package/src/commands/activation-settings.ts +73 -0
- package/src/commands/activation.ts +75 -56
- package/src/commands/advisor-tools.ts +27 -6
- package/src/commands/configuration-tool-preview.ts +107 -15
- package/src/commands/configuration-tool-runtime.ts +3 -20
- package/src/commands/configuration-tool-update.ts +23 -1
- package/src/commands/lifecycle.ts +30 -1
- package/src/commands/manual-progress.ts +5 -5
- package/src/commands/model-commands.ts +17 -0
- package/src/commands/model-picker.ts +14 -6
- package/src/commands/settings-commands.ts +36 -20
- package/src/commands/settings-persistence.ts +37 -1
- package/src/config/defaults.ts +10 -0
- package/src/config/schema-validators.ts +10 -0
- package/src/config/schema.ts +24 -1
- package/src/config/session-overrides.ts +109 -0
- package/src/config/state.ts +19 -0
- package/src/config/storage.ts +15 -1
- package/src/config/types.ts +11 -0
- package/src/session-state.ts +2 -0
- package/src/tools/budget-feedback.ts +2 -2
- package/src/tools/prompts.ts +18 -0
- package/src/tools/register-ask-advisor.ts +10 -4
- package/src/tools/register-lifecycle.ts +12 -6
- package/src/tools/registration.ts +8 -1
- package/src/tools/session-availability.ts +10 -0
- package/src/ui/settings-items.ts +43 -6
- package/src/ui/settings-list-adapter.ts +1 -1
- package/src/ui/settings-mutations.ts +14 -0
- package/src/ui/settings-selector.ts +1 -0
- package/src/ui/types.ts +8 -1
package/src/config/defaults.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
setAdvisorActivationRef,
|
|
2
3
|
setAdvisorAgentsMdContextRef,
|
|
3
4
|
setAdvisorAutoLoopGateRef,
|
|
4
5
|
setAdvisorBlockOnBlockedRef,
|
|
@@ -43,6 +44,7 @@ import {
|
|
|
43
44
|
setAdvisorToolResultMaxLinesRef,
|
|
44
45
|
setAdvisorToolsEnabledRef,
|
|
45
46
|
setAdvisorTrackedFileContentRef,
|
|
47
|
+
setAdvisorTrackedFileHandoffRef,
|
|
46
48
|
setAdvisorUntrackedContentRef,
|
|
47
49
|
setAlwaysOnRef,
|
|
48
50
|
setContextMaxCharsRef,
|
|
@@ -95,6 +97,7 @@ export const resetDefaults = () => {
|
|
|
95
97
|
setAdvisorSessionSummaryRef(false);
|
|
96
98
|
setAdvisorLogFeedbackRef(false);
|
|
97
99
|
setSimpleModeRef(false);
|
|
100
|
+
setAdvisorActivationRef("persistent");
|
|
98
101
|
setAdvisorToolsEnabledRef(true);
|
|
99
102
|
setAlwaysOnRef(false);
|
|
100
103
|
setAdvisorFailureModeRef("block-session");
|
|
@@ -122,6 +125,7 @@ export const resetDefaults = () => {
|
|
|
122
125
|
setAdvisorOutcomeLoggingRef(false);
|
|
123
126
|
setAdvisorUntrackedContentRef(false);
|
|
124
127
|
setAdvisorTrackedFileContentRef(false);
|
|
128
|
+
setAdvisorTrackedFileHandoffRef("advisor-named");
|
|
125
129
|
setAdvisorScoutEnabledRef(false);
|
|
126
130
|
setAdvisorScoutTimeoutMsRef(DEFAULT_SCOUT_TIMEOUT_MS);
|
|
127
131
|
setShowUsageDetailsRef(true);
|
|
@@ -222,6 +226,7 @@ export const applyConfig = (config: AdvisorConfig) => {
|
|
|
222
226
|
applyOptionalConfig(config, "showUsageDetails", setShowUsageDetailsRef);
|
|
223
227
|
applyOptionalConfig(config, "showUsageFooter", setShowUsageFooterRef);
|
|
224
228
|
applyOptionalConfig(config, "simpleMode", setSimpleModeRef);
|
|
229
|
+
applyOptionalConfig(config, "advisorActivation", setAdvisorActivationRef);
|
|
225
230
|
applyOptionalConfig(config, "advisorToolsEnabled", setAdvisorToolsEnabledRef);
|
|
226
231
|
applyOptionalConfig(config, "alwaysOn", setAlwaysOnRef);
|
|
227
232
|
applyOptionalConfig(config, "gateFailureMode", setAdvisorFailureModeRef);
|
|
@@ -316,6 +321,11 @@ export const applyConfig = (config: AdvisorConfig) => {
|
|
|
316
321
|
"advisorTrackedFileContent",
|
|
317
322
|
setAdvisorTrackedFileContentRef
|
|
318
323
|
);
|
|
324
|
+
applyOptionalConfig(
|
|
325
|
+
config,
|
|
326
|
+
"advisorTrackedFileHandoff",
|
|
327
|
+
setAdvisorTrackedFileHandoffRef
|
|
328
|
+
);
|
|
319
329
|
applyOptionalConfig(
|
|
320
330
|
config,
|
|
321
331
|
"advisorOutcomeLogging",
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
JEV_TRANSPORTS,
|
|
7
7
|
MAX_CONTEXT_MAX_CHARS,
|
|
8
8
|
MAX_SCOUT_TIMEOUT_MS,
|
|
9
|
+
TRACKED_FILE_HANDOFF_MODES,
|
|
9
10
|
} from "./types.ts";
|
|
10
11
|
import type { JevTransport } from "./types.ts";
|
|
11
12
|
|
|
@@ -57,6 +58,15 @@ export const isValidGateFailureMode = (
|
|
|
57
58
|
): value is (typeof GATE_FAILURE_MODES)[number] =>
|
|
58
59
|
isString(value) && GATE_FAILURE_MODE_NAMES.has(value);
|
|
59
60
|
|
|
61
|
+
const TRACKED_FILE_HANDOFF_MODE_NAMES = new Set<string>(
|
|
62
|
+
TRACKED_FILE_HANDOFF_MODES
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
export const isValidTrackedFileHandoffMode = (
|
|
66
|
+
value: unknown
|
|
67
|
+
): value is (typeof TRACKED_FILE_HANDOFF_MODES)[number] =>
|
|
68
|
+
isString(value) && TRACKED_FILE_HANDOFF_MODE_NAMES.has(value);
|
|
69
|
+
|
|
60
70
|
export const isValidToolResultMaxLines = (value: unknown): value is number =>
|
|
61
71
|
isValidNonNegativeSafeInteger(value);
|
|
62
72
|
|
package/src/config/schema.ts
CHANGED
|
@@ -20,8 +20,10 @@ import {
|
|
|
20
20
|
isValidScoutTimeoutMs,
|
|
21
21
|
isValidToolResultMaxBytes,
|
|
22
22
|
isValidToolResultMaxLines,
|
|
23
|
+
isValidTrackedFileHandoffMode,
|
|
23
24
|
} from "./schema-validators.ts";
|
|
24
25
|
import {
|
|
26
|
+
advisorActivationRef,
|
|
25
27
|
advisorAgentsMdContextRef,
|
|
26
28
|
advisorAutoLoopGateRef,
|
|
27
29
|
advisorBlockOnBlockedRef,
|
|
@@ -66,6 +68,7 @@ import {
|
|
|
66
68
|
advisorToolResultMaxLinesRef,
|
|
67
69
|
advisorToolsEnabledRef,
|
|
68
70
|
advisorTrackedFileContentRef,
|
|
71
|
+
advisorTrackedFileHandoffRef,
|
|
69
72
|
advisorUntrackedContentRef,
|
|
70
73
|
alwaysOnRef,
|
|
71
74
|
contextMaxCharsRef,
|
|
@@ -75,12 +78,17 @@ import {
|
|
|
75
78
|
showUsageFooterRef,
|
|
76
79
|
simpleModeRef,
|
|
77
80
|
} from "./state.ts";
|
|
78
|
-
import type {
|
|
81
|
+
import type {
|
|
82
|
+
AdvisorActivation,
|
|
83
|
+
AdvisorConfig,
|
|
84
|
+
AdvisorConfigValue,
|
|
85
|
+
} from "./types.ts";
|
|
79
86
|
import {
|
|
80
87
|
GATE_FAILURE_MODES,
|
|
81
88
|
JEV_TRANSPORTS,
|
|
82
89
|
MAX_CONTEXT_MAX_CHARS,
|
|
83
90
|
MAX_SCOUT_TIMEOUT_MS,
|
|
91
|
+
TRACKED_FILE_HANDOFF_MODES,
|
|
84
92
|
} from "./types.ts";
|
|
85
93
|
|
|
86
94
|
export {
|
|
@@ -121,6 +129,14 @@ export const CONFIG_SCHEMA = {
|
|
|
121
129
|
persisted: true,
|
|
122
130
|
type: "string",
|
|
123
131
|
},
|
|
132
|
+
advisorActivation: {
|
|
133
|
+
accepted: "persistent or session",
|
|
134
|
+
current: () => advisorActivationRef,
|
|
135
|
+
persisted: true,
|
|
136
|
+
type: "enum",
|
|
137
|
+
validate: (value: unknown): value is AdvisorActivation =>
|
|
138
|
+
value === "persistent" || value === "session",
|
|
139
|
+
},
|
|
124
140
|
advisorAgentsMdContext: {
|
|
125
141
|
accepted: "true or false",
|
|
126
142
|
current: () => advisorAgentsMdContextRef,
|
|
@@ -398,6 +414,13 @@ export const CONFIG_SCHEMA = {
|
|
|
398
414
|
persisted: true,
|
|
399
415
|
type: "boolean",
|
|
400
416
|
},
|
|
417
|
+
advisorTrackedFileHandoff: {
|
|
418
|
+
accepted: TRACKED_FILE_HANDOFF_MODES.join(", "),
|
|
419
|
+
current: () => advisorTrackedFileHandoffRef,
|
|
420
|
+
persisted: true,
|
|
421
|
+
type: "enum",
|
|
422
|
+
validate: isValidTrackedFileHandoffMode,
|
|
423
|
+
},
|
|
401
424
|
advisorUntrackedContent: {
|
|
402
425
|
accepted: "true or false",
|
|
403
426
|
current: () => advisorUntrackedContentRef,
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
setAdvisorEffortRef,
|
|
5
|
+
setAdvisorFallbackModelRef,
|
|
6
|
+
setAdvisorRef,
|
|
7
|
+
setContextMaxCharsRef,
|
|
8
|
+
setExecutorEffortRef,
|
|
9
|
+
setExecutorRef,
|
|
10
|
+
} from "./state.ts";
|
|
11
|
+
|
|
12
|
+
export interface SessionActivationValues {
|
|
13
|
+
advisor: string;
|
|
14
|
+
advisorEffort: string | undefined;
|
|
15
|
+
advisorFallbackModel: string | undefined;
|
|
16
|
+
contextMaxChars: number;
|
|
17
|
+
executor: string;
|
|
18
|
+
executorEffort: string | undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const SESSION_ACTIVATION_KEYS = [
|
|
22
|
+
"advisor",
|
|
23
|
+
"advisorEffort",
|
|
24
|
+
"advisorFallbackModel",
|
|
25
|
+
"contextMaxChars",
|
|
26
|
+
"executor",
|
|
27
|
+
"executorEffort",
|
|
28
|
+
] as const satisfies readonly (keyof SessionActivationValues)[];
|
|
29
|
+
|
|
30
|
+
const overrides = new WeakMap<object, Partial<SessionActivationValues>>();
|
|
31
|
+
|
|
32
|
+
const sessionKey = (ctx: ExtensionContext): object => ctx.sessionManager ?? ctx;
|
|
33
|
+
|
|
34
|
+
export const getSessionActivationOverrides = (ctx: ExtensionContext) =>
|
|
35
|
+
overrides.get(sessionKey(ctx));
|
|
36
|
+
|
|
37
|
+
export const applySessionActivationOverrides = (ctx: ExtensionContext) => {
|
|
38
|
+
const values = getSessionActivationOverrides(ctx);
|
|
39
|
+
|
|
40
|
+
if (!values) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (Object.hasOwn(values, "advisor")) {
|
|
45
|
+
setAdvisorRef(values.advisor ?? "");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (Object.hasOwn(values, "advisorEffort")) {
|
|
49
|
+
setAdvisorEffortRef(values.advisorEffort);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (Object.hasOwn(values, "advisorFallbackModel")) {
|
|
53
|
+
setAdvisorFallbackModelRef(values.advisorFallbackModel);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (values.contextMaxChars !== undefined) {
|
|
57
|
+
setContextMaxCharsRef(values.contextMaxChars);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (Object.hasOwn(values, "executor")) {
|
|
61
|
+
setExecutorRef(values.executor ?? "");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (Object.hasOwn(values, "executorEffort")) {
|
|
65
|
+
setExecutorEffortRef(values.executorEffort);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export const rememberSessionActivationOverrides = (
|
|
70
|
+
ctx: ExtensionContext,
|
|
71
|
+
previous: SessionActivationValues,
|
|
72
|
+
current: SessionActivationValues
|
|
73
|
+
) => {
|
|
74
|
+
const next = { ...getSessionActivationOverrides(ctx) };
|
|
75
|
+
|
|
76
|
+
for (const key of SESSION_ACTIVATION_KEYS) {
|
|
77
|
+
if (previous[key] !== current[key]) {
|
|
78
|
+
Object.assign(next, { [key]: current[key] });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (Object.keys(next).length > 0) {
|
|
83
|
+
overrides.set(sessionKey(ctx), next);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export const clearSessionActivationOverrides = (
|
|
88
|
+
ctx: ExtensionContext,
|
|
89
|
+
keys: readonly (keyof SessionActivationValues)[] = SESSION_ACTIVATION_KEYS
|
|
90
|
+
) => {
|
|
91
|
+
const key = sessionKey(ctx);
|
|
92
|
+
const existing = overrides.get(key);
|
|
93
|
+
|
|
94
|
+
if (!existing) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const remaining = { ...existing };
|
|
99
|
+
|
|
100
|
+
for (const name of keys) {
|
|
101
|
+
Reflect.deleteProperty(remaining, name);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (Object.keys(remaining).length === 0) {
|
|
105
|
+
overrides.delete(key);
|
|
106
|
+
} else {
|
|
107
|
+
overrides.set(key, remaining);
|
|
108
|
+
}
|
|
109
|
+
};
|
package/src/config/state.ts
CHANGED
|
@@ -17,9 +17,11 @@ import {
|
|
|
17
17
|
DEFAULT_SCOUT_TIMEOUT_MS,
|
|
18
18
|
} from "./types.ts";
|
|
19
19
|
import type {
|
|
20
|
+
AdvisorActivation,
|
|
20
21
|
AdvisorToolPolicies,
|
|
21
22
|
GateFailureMode,
|
|
22
23
|
JevTransport,
|
|
24
|
+
TrackedFileHandoffMode,
|
|
23
25
|
} from "./types.ts";
|
|
24
26
|
|
|
25
27
|
// An empty ref means no model has been selected yet.
|
|
@@ -47,6 +49,7 @@ export let advisorSessionSummaryRef = false;
|
|
|
47
49
|
export let advisorLogFeedbackRef = false;
|
|
48
50
|
export let simpleModeRef = false;
|
|
49
51
|
export let advisorToolsEnabledRef = true;
|
|
52
|
+
export let advisorActivationRef: AdvisorActivation = "persistent";
|
|
50
53
|
export let alwaysOnRef = false;
|
|
51
54
|
export let advisorFailureModeRef: GateFailureMode = "block-session";
|
|
52
55
|
export let advisorHerdrIntegrationRef = true;
|
|
@@ -83,6 +86,10 @@ export let advisorToolPoliciesRef: AdvisorToolPolicies = {};
|
|
|
83
86
|
export let advisorOutcomeLoggingRef = false;
|
|
84
87
|
export let advisorUntrackedContentRef = false;
|
|
85
88
|
export let advisorTrackedFileContentRef = false;
|
|
89
|
+
|
|
90
|
+
export let advisorTrackedFileHandoffRef: TrackedFileHandoffMode =
|
|
91
|
+
"advisor-named";
|
|
92
|
+
|
|
86
93
|
export let advisorScoutEnabledRef = false;
|
|
87
94
|
export let advisorScoutTimeoutMsRef = DEFAULT_SCOUT_TIMEOUT_MS;
|
|
88
95
|
export let showUsageDetailsRef = true;
|
|
@@ -199,6 +206,10 @@ export const setAdvisorToolsEnabledRef = (enabled: boolean) => {
|
|
|
199
206
|
advisorToolsEnabledRef = enabled;
|
|
200
207
|
};
|
|
201
208
|
|
|
209
|
+
export const setAdvisorActivationRef = (activation: AdvisorActivation) => {
|
|
210
|
+
advisorActivationRef = activation;
|
|
211
|
+
};
|
|
212
|
+
|
|
202
213
|
export const setAlwaysOnRef = (enabled: boolean) => {
|
|
203
214
|
alwaysOnRef = enabled;
|
|
204
215
|
};
|
|
@@ -308,6 +319,12 @@ export const setAdvisorTrackedFileContentRef = (enabled: boolean) => {
|
|
|
308
319
|
advisorTrackedFileContentRef = enabled;
|
|
309
320
|
};
|
|
310
321
|
|
|
322
|
+
export const setAdvisorTrackedFileHandoffRef = (
|
|
323
|
+
mode: TrackedFileHandoffMode
|
|
324
|
+
) => {
|
|
325
|
+
advisorTrackedFileHandoffRef = mode;
|
|
326
|
+
};
|
|
327
|
+
|
|
311
328
|
export const setAdvisorScoutEnabledRef = (enabled: boolean) => {
|
|
312
329
|
advisorScoutEnabledRef = enabled;
|
|
313
330
|
};
|
|
@@ -329,6 +346,7 @@ export const setShowUsageFooterRef = (enabled: boolean) => {
|
|
|
329
346
|
* imported mutable bindings, which can be snapshotted by extension loaders.
|
|
330
347
|
*/
|
|
331
348
|
export const getAdvisorSettings = () => ({
|
|
349
|
+
advisorActivation: advisorActivationRef,
|
|
332
350
|
advisorToolsEnabled: advisorToolsEnabledRef,
|
|
333
351
|
agentsMdContext: advisorAgentsMdContextRef,
|
|
334
352
|
alwaysOn: alwaysOnRef,
|
|
@@ -377,6 +395,7 @@ export const getAdvisorSettings = () => ({
|
|
|
377
395
|
toolResultMaxBytes: advisorToolResultMaxBytesRef,
|
|
378
396
|
toolResultMaxLines: advisorToolResultMaxLinesRef,
|
|
379
397
|
trackedFileContent: advisorTrackedFileContentRef,
|
|
398
|
+
trackedFileHandoff: advisorTrackedFileHandoffRef,
|
|
380
399
|
untrackedContent: advisorUntrackedContentRef,
|
|
381
400
|
});
|
|
382
401
|
|
package/src/config/storage.ts
CHANGED
|
@@ -26,6 +26,11 @@ import {
|
|
|
26
26
|
} from "./schema.ts";
|
|
27
27
|
import type { PersistedConfigKey } from "./schema.ts";
|
|
28
28
|
import {
|
|
29
|
+
applySessionActivationOverrides,
|
|
30
|
+
clearSessionActivationOverrides,
|
|
31
|
+
} from "./session-overrides.ts";
|
|
32
|
+
import {
|
|
33
|
+
advisorActivationRef,
|
|
29
34
|
advisorJevClassifierRef,
|
|
30
35
|
advisorJevFilterEnabledRef,
|
|
31
36
|
setAdvisorOutcomeLoggingRef,
|
|
@@ -260,6 +265,12 @@ export const loadConfig = (_ctx: ExtensionContext) => {
|
|
|
260
265
|
// Repository-controlled project configuration is never applied. Models,
|
|
261
266
|
// prompts, gates, budgets, disclosure, redaction, integrations, and consent
|
|
262
267
|
// remain under the user's global Pi configuration.
|
|
268
|
+
if (advisorActivationRef === "session") {
|
|
269
|
+
applySessionActivationOverrides(_ctx);
|
|
270
|
+
} else {
|
|
271
|
+
clearSessionActivationOverrides(_ctx);
|
|
272
|
+
}
|
|
273
|
+
|
|
263
274
|
setAdvisorOutcomeLoggingRef(globalConfig?.advisorOutcomeLogging === true);
|
|
264
275
|
loadedConfigState = currentConfigState();
|
|
265
276
|
loadedConfigPath = global;
|
|
@@ -274,6 +285,7 @@ export const loadConfig = (_ctx: ExtensionContext) => {
|
|
|
274
285
|
* external edit to advisor.json coexist with a later settings or model save.
|
|
275
286
|
*/
|
|
276
287
|
export interface SaveConfigOptions {
|
|
288
|
+
forceKeys?: readonly PersistedConfigKey[];
|
|
277
289
|
persistAdvisor?: boolean;
|
|
278
290
|
persistExecutor?: boolean;
|
|
279
291
|
}
|
|
@@ -293,10 +305,12 @@ export const saveConfig = (
|
|
|
293
305
|
const persistExecutor = options.persistExecutor ?? true;
|
|
294
306
|
const current = currentConfigState();
|
|
295
307
|
const baseline = loadedConfigPath === path ? loadedConfigState : undefined;
|
|
308
|
+
const forcedKeys = new Set(options.forceKeys);
|
|
296
309
|
|
|
297
310
|
const changedKeys = baseline
|
|
298
311
|
? SAVED_CONFIG_KEYS.filter(
|
|
299
|
-
(key) =>
|
|
312
|
+
(key) =>
|
|
313
|
+
forcedKeys.has(key) || !sameConfigValue(current[key], baseline[key])
|
|
300
314
|
)
|
|
301
315
|
: [...SAVED_CONFIG_KEYS];
|
|
302
316
|
|
package/src/config/types.ts
CHANGED
|
@@ -68,8 +68,18 @@ export const GATE_FAILURE_MODES: GateFailureMode[] = [
|
|
|
68
68
|
"warn-and-continue",
|
|
69
69
|
];
|
|
70
70
|
|
|
71
|
+
export type TrackedFileHandoffMode = "advisor-named" | "executor";
|
|
72
|
+
|
|
73
|
+
export const TRACKED_FILE_HANDOFF_MODES: TrackedFileHandoffMode[] = [
|
|
74
|
+
"advisor-named",
|
|
75
|
+
"executor",
|
|
76
|
+
];
|
|
77
|
+
|
|
78
|
+
export type AdvisorActivation = "persistent" | "session";
|
|
79
|
+
|
|
71
80
|
export interface AdvisorConfig {
|
|
72
81
|
advisor?: string;
|
|
82
|
+
advisorActivation?: AdvisorActivation;
|
|
73
83
|
advisorFallbackModel?: string;
|
|
74
84
|
advisorAgentsMdContext?: boolean;
|
|
75
85
|
advisorAutoLoopGate?: boolean;
|
|
@@ -111,6 +121,7 @@ export interface AdvisorConfig {
|
|
|
111
121
|
advisorToolResultMaxBytes?: number;
|
|
112
122
|
advisorToolResultMaxLines?: number;
|
|
113
123
|
advisorTrackedFileContent?: boolean;
|
|
124
|
+
advisorTrackedFileHandoff?: TrackedFileHandoffMode;
|
|
114
125
|
advisorToolsEnabled?: boolean;
|
|
115
126
|
advisorUntrackedContent?: boolean;
|
|
116
127
|
alwaysOn?: boolean;
|
package/src/session-state.ts
CHANGED
|
@@ -100,12 +100,14 @@ export class AdvisorSessionState {
|
|
|
100
100
|
readonly #followUps: AdvisorFollowUpCache;
|
|
101
101
|
#sessionTurnOrdinal = 0;
|
|
102
102
|
#turnsSinceConsultation = 0;
|
|
103
|
+
sessionToolsEnabled = false;
|
|
103
104
|
|
|
104
105
|
constructor(now?: () => number) {
|
|
105
106
|
this.#followUps = new AdvisorFollowUpCache(now);
|
|
106
107
|
}
|
|
107
108
|
|
|
108
109
|
resetTask() {
|
|
110
|
+
this.sessionToolsEnabled = false;
|
|
109
111
|
this.#repetition = freshRepetition();
|
|
110
112
|
this.#blockedReason = undefined;
|
|
111
113
|
this.#ledger = freshAdviceLedger();
|
|
@@ -6,13 +6,13 @@ import type {
|
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
8
|
advisorLogFeedbackRef,
|
|
9
|
-
advisorToolsEnabledRef,
|
|
10
9
|
getAdvisorMaxCallsPerSession,
|
|
11
10
|
isSimpleMode,
|
|
12
11
|
} from "../config/state.ts";
|
|
13
12
|
import { loadConfig } from "../config/storage.ts";
|
|
14
13
|
import type { AdvisorSessionState } from "../session-state.ts";
|
|
15
14
|
import { advisorModelIsAllowed } from "./model-access.ts";
|
|
15
|
+
import { advisorToolsAllowed } from "./session-availability.ts";
|
|
16
16
|
|
|
17
17
|
export const advisorBudgetMessage = (session: AdvisorSessionState) => {
|
|
18
18
|
const simple = isSimpleMode();
|
|
@@ -50,7 +50,7 @@ export const advisorBudgetUpdate = (
|
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
if (!
|
|
53
|
+
if (!advisorToolsAllowed(session) || !advisorModelIsAllowed(ctx)) {
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
56
|
|
package/src/tools/prompts.ts
CHANGED
|
@@ -5,6 +5,8 @@ import {
|
|
|
5
5
|
advisorCustomInvocationRef,
|
|
6
6
|
advisorFailureGateRef,
|
|
7
7
|
advisorPlanGateRef,
|
|
8
|
+
advisorTrackedFileContentRef,
|
|
9
|
+
advisorTrackedFileHandoffRef,
|
|
8
10
|
contextMaxCharsRef,
|
|
9
11
|
isSimpleMode,
|
|
10
12
|
} from "../config/state.ts";
|
|
@@ -148,10 +150,24 @@ export const advisorRequestConversation = (
|
|
|
148
150
|
imageNonce
|
|
149
151
|
);
|
|
150
152
|
|
|
153
|
+
// Without tracked-file consent the Executor cannot attach files, so it is not told to.
|
|
154
|
+
const trackedFileHandoffGuidelines = (): string[] => {
|
|
155
|
+
if (!advisorTrackedFileContentRef) {
|
|
156
|
+
return [];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return [
|
|
160
|
+
advisorTrackedFileHandoffRef === "executor"
|
|
161
|
+
? "Tracked files may be attached before the Advisor names them. When your question or draft depends on specific repository documents, attach them with `includeTrackedFiles` on the first consultation. Prefer a few key files within the size limits."
|
|
162
|
+
: "Attach tracked files with `includeTrackedFiles` only after the Advisor names them.",
|
|
163
|
+
];
|
|
164
|
+
};
|
|
165
|
+
|
|
151
166
|
export const advisorInvocationGuidelines = () => {
|
|
152
167
|
if (isSimpleMode()) {
|
|
153
168
|
return [
|
|
154
169
|
"When uncertain and normal available tools cannot resolve it, call ask_advisor for a second opinion.",
|
|
170
|
+
...trackedFileHandoffGuidelines(),
|
|
155
171
|
];
|
|
156
172
|
}
|
|
157
173
|
|
|
@@ -185,6 +201,8 @@ export const advisorInvocationGuidelines = () => {
|
|
|
185
201
|
);
|
|
186
202
|
}
|
|
187
203
|
|
|
204
|
+
guidelines.push(...trackedFileHandoffGuidelines());
|
|
205
|
+
|
|
188
206
|
return guidelines;
|
|
189
207
|
};
|
|
190
208
|
|
|
@@ -128,12 +128,18 @@ const claimTrackedHandoff = (
|
|
|
128
128
|
return;
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
|
|
131
|
+
const settings = getAdvisorSettings();
|
|
132
|
+
|
|
133
|
+
if (!settings.trackedFileContent) {
|
|
132
134
|
throw new Error(
|
|
133
135
|
"Tracked file attachments are disabled: enable the global advisorTrackedFileContent setting (Tracked file content in /advisor-settings) and retry."
|
|
134
136
|
);
|
|
135
137
|
}
|
|
136
138
|
|
|
139
|
+
if (settings.trackedFileHandoff === "executor") {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
137
143
|
if (!session.claimTrackedFiles(includeTrackedFiles)) {
|
|
138
144
|
throw new Error(
|
|
139
145
|
"Tracked file handoff requires a prior Advisor response that explicitly names every requested path and is consumed once."
|
|
@@ -151,7 +157,7 @@ export const registerAskAdvisorTool = ({
|
|
|
151
157
|
}: ToolRegistrationContext): void => {
|
|
152
158
|
pi.registerTool({
|
|
153
159
|
description:
|
|
154
|
-
"Consult the on-demand Advisor model for strategic guidance. Call with an empty object for a contextual review; attach an optional draft for concrete plan or completion review. Use followUpTo with a new question to continue one cached consultation without rebuilding its redacted context.
|
|
160
|
+
"Consult the on-demand Advisor model for strategic guidance. Call with an empty object for a contextual review; attach an optional draft for concrete plan or completion review. Use followUpTo with a new question to continue one cached consultation without rebuilding its redacted context. Attach tracked files with includeTrackedFiles only after the Advisor names them, unless the Advisor invocation settings explicitly allow attaching them earlier; it requires global advisorTrackedFileContent consent and sends file contents as untrusted data. In Pi Codemode, gather and filter deterministic tool results first, then call tools.ask_advisor. Nested results are not automatically reconstructed: pass only permitted, concise summaries in draft (untrusted, capped at 8 KiB, not independently verified). Draft does not inherit source-tool disclosure policies; use gitContext for patches within the user's allowance.",
|
|
155
161
|
async execute(_id, params, signal, onUpdate, ctx) {
|
|
156
162
|
let followUp:
|
|
157
163
|
{ adviceId: string; payload: AdvisorFollowUpPayload } | undefined;
|
|
@@ -480,7 +486,7 @@ export const registerAskAdvisorTool = ({
|
|
|
480
486
|
Type.Array(
|
|
481
487
|
Type.String({
|
|
482
488
|
description:
|
|
483
|
-
"Exact tracked repository-relative files to attach
|
|
489
|
+
"Exact tracked repository-relative files to attach. By default only files the latest Advisor answer names are accepted, unless the Advisor invocation settings explicitly allow earlier attachment. Requires global advisorTrackedFileContent consent; current working-tree contents are sent as untrusted data.",
|
|
484
490
|
})
|
|
485
491
|
)
|
|
486
492
|
),
|
|
@@ -500,7 +506,7 @@ export const registerAskAdvisorTool = ({
|
|
|
500
506
|
),
|
|
501
507
|
}),
|
|
502
508
|
promptGuidelines: [
|
|
503
|
-
"Call ask_advisor with an empty object for general consultation. For a plan or completion review, include a concise draft naming work, validation, and remaining risks; its claims are not evidence. To drill into an existing answer, pass its adviceId as followUpTo with a new question and no draft, Git context, or attachments.
|
|
509
|
+
"Call ask_advisor with an empty object for general consultation. For a plan or completion review, include a concise draft naming work, validation, and remaining risks; its claims are not evidence. To drill into an existing answer, pass its adviceId as followUpTo with a new question and no draft, Git context, or attachments. Attach tracked files with includeTrackedFiles only after the Advisor names them, unless the Advisor invocation settings explicitly allow attaching them earlier; use exact repository-relative paths that are relevant and permitted, and do not guess paths.",
|
|
504
510
|
],
|
|
505
511
|
promptSnippet:
|
|
506
512
|
"Consult the Advisor using its existing context; attach a draft for plan or completion review",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
+
advisorActivationRef,
|
|
2
3
|
advisorLogFeedbackRef,
|
|
3
4
|
advisorSessionSummaryRef,
|
|
4
|
-
advisorToolsEnabledRef,
|
|
5
5
|
getAdvisorMaxCallsPerSession,
|
|
6
6
|
isSimpleMode,
|
|
7
7
|
} from "../config/state.ts";
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
sameModelAdvisorDisabled,
|
|
16
16
|
} from "./model-access.ts";
|
|
17
17
|
import { advisorInvocationGuidelines } from "./prompts.ts";
|
|
18
|
+
import { advisorToolsAllowed } from "./session-availability.ts";
|
|
18
19
|
import type { ToolRegistrationContext } from "./types.ts";
|
|
19
20
|
|
|
20
21
|
const modelAccessBlock = (
|
|
@@ -103,7 +104,7 @@ export const registerToolLifecycle = ({
|
|
|
103
104
|
loadConfig(ctx);
|
|
104
105
|
|
|
105
106
|
if (
|
|
106
|
-
!
|
|
107
|
+
!advisorToolsAllowed(session) ||
|
|
107
108
|
!advisorModelAccess(ctx).allowed ||
|
|
108
109
|
sameModelAdvisorDisabled(ctx)
|
|
109
110
|
) {
|
|
@@ -153,9 +154,11 @@ export const registerToolLifecycle = ({
|
|
|
153
154
|
|
|
154
155
|
const isAdvisorTool =
|
|
155
156
|
event.toolName === "ask_advisor" ||
|
|
156
|
-
event.toolName === "record_advisor_outcome"
|
|
157
|
+
event.toolName === "record_advisor_outcome" ||
|
|
158
|
+
(event.toolName === "advisor_config" &&
|
|
159
|
+
advisorActivationRef === "session");
|
|
157
160
|
|
|
158
|
-
if (isAdvisorTool && !
|
|
161
|
+
if (isAdvisorTool && !advisorToolsAllowed(session)) {
|
|
159
162
|
return {
|
|
160
163
|
block: true,
|
|
161
164
|
reason:
|
|
@@ -163,7 +166,10 @@ export const registerToolLifecycle = ({
|
|
|
163
166
|
};
|
|
164
167
|
}
|
|
165
168
|
|
|
166
|
-
if (
|
|
169
|
+
if (
|
|
170
|
+
!pi.getActiveTools().includes("ask_advisor") ||
|
|
171
|
+
(advisorActivationRef === "session" && !session.sessionToolsEnabled)
|
|
172
|
+
) {
|
|
167
173
|
return;
|
|
168
174
|
}
|
|
169
175
|
|
|
@@ -173,7 +179,7 @@ export const registerToolLifecycle = ({
|
|
|
173
179
|
return;
|
|
174
180
|
}
|
|
175
181
|
|
|
176
|
-
if (isAdvisorTool && !
|
|
182
|
+
if (isAdvisorTool && !advisorToolsAllowed(session)) {
|
|
177
183
|
return {
|
|
178
184
|
block: true,
|
|
179
185
|
reason:
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
|
|
3
|
+
import { advisorActivationRef } from "../config/state.ts";
|
|
3
4
|
import { herdrAdvisorActivity, herdrAdvisorBlock } from "../herdr.ts";
|
|
4
5
|
import { appendOutcome } from "../outcomes.ts";
|
|
5
6
|
import type { AdvisorSessionState } from "../session-state.ts";
|
|
@@ -43,7 +44,13 @@ export const registerAdvisorTool = (
|
|
|
43
44
|
registerOutcomeTool(registration);
|
|
44
45
|
|
|
45
46
|
const turnGate: JevTurnGateRegistration = {
|
|
46
|
-
activeTools: () =>
|
|
47
|
+
activeTools: () => {
|
|
48
|
+
const active = pi.getActiveTools();
|
|
49
|
+
|
|
50
|
+
return advisorActivationRef === "session" && !session.sessionToolsEnabled
|
|
51
|
+
? active.filter((name) => name !== "ask_advisor")
|
|
52
|
+
: active;
|
|
53
|
+
},
|
|
47
54
|
consult: registration.consult,
|
|
48
55
|
herdrActivity: registration.herdrActivity,
|
|
49
56
|
send: (message) => pi.sendMessage(message, { deliverAs: "steer" }),
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
advisorActivationRef,
|
|
3
|
+
advisorToolsEnabledRef,
|
|
4
|
+
} from "../config/state.ts";
|
|
5
|
+
import type { AdvisorSessionState } from "../session-state.ts";
|
|
6
|
+
|
|
7
|
+
export const advisorToolsAllowed = (session: AdvisorSessionState) =>
|
|
8
|
+
advisorActivationRef === "session"
|
|
9
|
+
? session.sessionToolsEnabled
|
|
10
|
+
: advisorToolsEnabledRef;
|