pi-advisor-flow 0.13.0 → 0.13.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/README.md +1 -1
- package/dist/index.js +197 -29
- package/package.json +1 -1
- package/src/commands/activation.ts +106 -20
- package/src/commands/advisor-tools.ts +26 -0
- package/src/commands/lifecycle.ts +9 -0
- package/src/commands/runtime.ts +5 -0
- package/src/commands/settings-commands.ts +53 -14
- package/src/commands/settings-persistence.ts +2 -0
- package/src/commands/types.ts +2 -0
- package/src/config/defaults.ts +3 -0
- package/src/config/schema.ts +7 -0
- package/src/config/state.ts +5 -0
- package/src/config/types.ts +1 -0
- package/src/tools/register-lifecycle.ts +18 -0
- package/src/ui/settings-items.ts +9 -1
- package/src/ui/settings-mutations.ts +32 -7
- package/src/ui/types.ts +1 -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
|
+
## 0.13.1 - 2026-10-11
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- 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.
|
|
14
|
+
|
|
9
15
|
## 0.13.0 - 2026-10-10
|
|
10
16
|
|
|
11
17
|
### Added
|
package/README.md
CHANGED
|
@@ -141,7 +141,7 @@ Successful calls return an opaque `adviceId`. If global outcome logging is enabl
|
|
|
141
141
|
| `/advisor-models` | Choose the Executor, Advisor, and optional fallback models. |
|
|
142
142
|
| `/advisor-settings` | Configure behavior, models, context, privacy, and limits. |
|
|
143
143
|
| `/advisor-stats` | Show retained outcome adoption and validation stats. |
|
|
144
|
-
| `/advisor-off` | Disable
|
|
144
|
+
| `/advisor-off` | Disable model-facing Advisor tools across sessions and turn off persistent activation. |
|
|
145
145
|
|
|
146
146
|
In the interactive TUI, `/advisor-manual [focus]` opens a centered overlay with the focus text prefilled, a choice of permitted Git-context level, and live progress in the transcript. Canceling has no side effects.
|
|
147
147
|
|
package/dist/index.js
CHANGED
|
@@ -65,6 +65,7 @@ var advisorMaxCallsPerSessionRef;
|
|
|
65
65
|
var advisorModelWhitelistRef = [];
|
|
66
66
|
var advisorSessionSummaryRef = false;
|
|
67
67
|
var simpleModeRef = false;
|
|
68
|
+
var advisorToolsEnabledRef = true;
|
|
68
69
|
var alwaysOnRef = false;
|
|
69
70
|
var advisorFailureModeRef = "block-session";
|
|
70
71
|
var advisorHerdrIntegrationRef = true;
|
|
@@ -164,6 +165,9 @@ var setAdvisorSessionSummaryRef = (enabled) => {
|
|
|
164
165
|
var setSimpleModeRef = (enabled) => {
|
|
165
166
|
simpleModeRef = enabled;
|
|
166
167
|
};
|
|
168
|
+
var setAdvisorToolsEnabledRef = (enabled) => {
|
|
169
|
+
advisorToolsEnabledRef = enabled;
|
|
170
|
+
};
|
|
167
171
|
var setAlwaysOnRef = (enabled) => {
|
|
168
172
|
alwaysOnRef = enabled;
|
|
169
173
|
};
|
|
@@ -253,6 +257,7 @@ var setShowUsageFooterRef = (enabled) => {
|
|
|
253
257
|
showUsageFooterRef = enabled;
|
|
254
258
|
};
|
|
255
259
|
var getAdvisorSettings = () => ({
|
|
260
|
+
advisorToolsEnabled: advisorToolsEnabledRef,
|
|
256
261
|
agentsMdContext: advisorAgentsMdContextRef,
|
|
257
262
|
alwaysOn: alwaysOnRef,
|
|
258
263
|
autoLoopGate: advisorAutoLoopGateRef,
|
|
@@ -785,6 +790,12 @@ var CONFIG_SCHEMA = {
|
|
|
785
790
|
type: "number",
|
|
786
791
|
validate: isValidToolResultMaxLines
|
|
787
792
|
},
|
|
793
|
+
advisorToolsEnabled: {
|
|
794
|
+
accepted: "true or false",
|
|
795
|
+
current: () => advisorToolsEnabledRef,
|
|
796
|
+
persisted: true,
|
|
797
|
+
type: "boolean"
|
|
798
|
+
},
|
|
788
799
|
advisorTrackedFileContent: {
|
|
789
800
|
accepted: "true or false",
|
|
790
801
|
current: () => advisorTrackedFileContentRef,
|
|
@@ -947,6 +958,7 @@ var resetDefaults = () => {
|
|
|
947
958
|
setAdvisorModelWhitelistRef([]);
|
|
948
959
|
setAdvisorSessionSummaryRef(false);
|
|
949
960
|
setSimpleModeRef(false);
|
|
961
|
+
setAdvisorToolsEnabledRef(true);
|
|
950
962
|
setAlwaysOnRef(false);
|
|
951
963
|
setAdvisorFailureModeRef("block-session");
|
|
952
964
|
setAdvisorHerdrIntegrationRef(true);
|
|
@@ -1013,6 +1025,7 @@ var applyConfig = (config) => {
|
|
|
1013
1025
|
applyOptionalConfig(config, "showUsageDetails", setShowUsageDetailsRef);
|
|
1014
1026
|
applyOptionalConfig(config, "showUsageFooter", setShowUsageFooterRef);
|
|
1015
1027
|
applyOptionalConfig(config, "simpleMode", setSimpleModeRef);
|
|
1028
|
+
applyOptionalConfig(config, "advisorToolsEnabled", setAdvisorToolsEnabledRef);
|
|
1016
1029
|
applyOptionalConfig(config, "alwaysOn", setAlwaysOnRef);
|
|
1017
1030
|
applyOptionalConfig(config, "gateFailureMode", setAdvisorFailureModeRef);
|
|
1018
1031
|
applyOptionalConfig(config, "advisorHerdrIntegration", setAdvisorHerdrIntegrationRef);
|
|
@@ -5309,6 +5322,7 @@ class CommandRuntime {
|
|
|
5309
5322
|
manualProgressSequence = 0;
|
|
5310
5323
|
pendingExecutorModelRef;
|
|
5311
5324
|
suppressModelSelectionSync = false;
|
|
5325
|
+
toolAvailabilityRevision = 0;
|
|
5312
5326
|
lastSameModelDisabled;
|
|
5313
5327
|
constructor(pi, dependencies = {}) {
|
|
5314
5328
|
this.pi = pi;
|
|
@@ -5320,6 +5334,9 @@ class CommandRuntime {
|
|
|
5320
5334
|
flowEnabled() {
|
|
5321
5335
|
return this.pi.getActiveTools().includes("ask_advisor");
|
|
5322
5336
|
}
|
|
5337
|
+
noteAdvisorToolsStateChange() {
|
|
5338
|
+
this.toolAvailabilityRevision += 1;
|
|
5339
|
+
}
|
|
5323
5340
|
resetSameModelNotice() {
|
|
5324
5341
|
this.lastSameModelDisabled = undefined;
|
|
5325
5342
|
}
|
|
@@ -5402,8 +5419,28 @@ var prepareActivationModels = async (runtime, ctx, announce, executorOverride, a
|
|
|
5402
5419
|
return { pendingExecutor: plan.pendingExecutor, pickedModels: true };
|
|
5403
5420
|
};
|
|
5404
5421
|
|
|
5422
|
+
// src/commands/advisor-tools.ts
|
|
5423
|
+
var ADVISOR_TOOL_NAMES = new Set(["ask_advisor", "record_advisor_outcome"]);
|
|
5424
|
+
var setAdvisorToolsActive = (pi, enabled) => {
|
|
5425
|
+
const current = pi.getActiveTools();
|
|
5426
|
+
const next = current.filter((name) => enabled || !ADVISOR_TOOL_NAMES.has(name));
|
|
5427
|
+
if (enabled) {
|
|
5428
|
+
for (const name of ADVISOR_TOOL_NAMES) {
|
|
5429
|
+
if (!next.includes(name)) {
|
|
5430
|
+
next.push(name);
|
|
5431
|
+
}
|
|
5432
|
+
}
|
|
5433
|
+
}
|
|
5434
|
+
if (next.length !== current.length || next.some((name, index) => name !== current[index])) {
|
|
5435
|
+
pi.setActiveTools(next);
|
|
5436
|
+
}
|
|
5437
|
+
};
|
|
5438
|
+
|
|
5405
5439
|
// src/commands/activation.ts
|
|
5406
|
-
var resolveActivationModels = async (runtime, ctx) => {
|
|
5440
|
+
var resolveActivationModels = async (runtime, ctx, canContinue) => {
|
|
5441
|
+
if (!canContinue()) {
|
|
5442
|
+
return { cancelled: true };
|
|
5443
|
+
}
|
|
5407
5444
|
const executor = findConfiguredModel(ctx, executorRef);
|
|
5408
5445
|
if (!executor) {
|
|
5409
5446
|
return {
|
|
@@ -5417,6 +5454,9 @@ var resolveActivationModels = async (runtime, ctx) => {
|
|
|
5417
5454
|
};
|
|
5418
5455
|
}
|
|
5419
5456
|
const advisorAuth = await ctx.modelRegistry.getApiKeyAndHeaders(advisor);
|
|
5457
|
+
if (!canContinue()) {
|
|
5458
|
+
return { cancelled: true };
|
|
5459
|
+
}
|
|
5420
5460
|
if (!(advisorAuth.ok && advisorAuth.apiKey)) {
|
|
5421
5461
|
return { error: `No API key for Advisor ${advisorRef}` };
|
|
5422
5462
|
}
|
|
@@ -5425,10 +5465,42 @@ var resolveActivationModels = async (runtime, ctx) => {
|
|
|
5425
5465
|
}
|
|
5426
5466
|
return {};
|
|
5427
5467
|
};
|
|
5468
|
+
var restoreActivationRefsIfCurrent = (canContinue, restoreRefs) => {
|
|
5469
|
+
if (canContinue()) {
|
|
5470
|
+
restoreRefs();
|
|
5471
|
+
}
|
|
5472
|
+
};
|
|
5473
|
+
var liveRefSnapshot = () => ({
|
|
5474
|
+
advisor: advisorRef,
|
|
5475
|
+
advisorEffort: advisorEffortRef,
|
|
5476
|
+
contextMaxChars: contextMaxCharsRef,
|
|
5477
|
+
executor: executorRef,
|
|
5478
|
+
executorEffort: executorEffortRef
|
|
5479
|
+
});
|
|
5480
|
+
var persistSuccessfulActivation = (ctx, shouldSave, reenableTools, restoreRefs) => {
|
|
5481
|
+
if (!shouldSave) {
|
|
5482
|
+
return true;
|
|
5483
|
+
}
|
|
5484
|
+
try {
|
|
5485
|
+
saveConfig(ctx, { persistAdvisor: true, persistExecutor: true });
|
|
5486
|
+
} catch (saveError) {
|
|
5487
|
+
if (!reenableTools) {
|
|
5488
|
+
throw saveError;
|
|
5489
|
+
}
|
|
5490
|
+
setAdvisorToolsEnabledRef(false);
|
|
5491
|
+
restoreRefs();
|
|
5492
|
+
const message = saveError instanceof Error ? saveError.message : String(saveError);
|
|
5493
|
+
notify(ctx, `Could not save Advisor activation: ${message}`, "error");
|
|
5494
|
+
return false;
|
|
5495
|
+
}
|
|
5496
|
+
return true;
|
|
5497
|
+
};
|
|
5428
5498
|
var activateAdvisor = async (runtime, args, ctx, announce = true) => {
|
|
5429
5499
|
if (!loadCommandConfig(ctx)) {
|
|
5430
5500
|
return;
|
|
5431
5501
|
}
|
|
5502
|
+
const { toolAvailabilityRevision } = runtime;
|
|
5503
|
+
const canContinue = () => runtime.toolAvailabilityRevision === toolAvailabilityRevision;
|
|
5432
5504
|
const previous = {
|
|
5433
5505
|
advisor: advisorRef,
|
|
5434
5506
|
advisorEffort: advisorEffortRef,
|
|
@@ -5436,46 +5508,62 @@ var activateAdvisor = async (runtime, args, ctx, announce = true) => {
|
|
|
5436
5508
|
executor: executorRef,
|
|
5437
5509
|
executorEffort: executorEffortRef
|
|
5438
5510
|
};
|
|
5439
|
-
const
|
|
5440
|
-
|
|
5441
|
-
|
|
5442
|
-
|
|
5443
|
-
|
|
5444
|
-
|
|
5511
|
+
const liveSnapshot = liveRefSnapshot;
|
|
5512
|
+
const restoreRefs = (attempted) => {
|
|
5513
|
+
if (advisorRef === attempted.advisor) {
|
|
5514
|
+
setAdvisorRef(previous.advisor);
|
|
5515
|
+
}
|
|
5516
|
+
if (advisorEffortRef === attempted.advisorEffort) {
|
|
5517
|
+
setAdvisorEffortRef(previous.advisorEffort);
|
|
5518
|
+
}
|
|
5519
|
+
if (contextMaxCharsRef === attempted.contextMaxChars) {
|
|
5520
|
+
setContextMaxCharsRef(previous.contextMaxChars);
|
|
5521
|
+
}
|
|
5522
|
+
if (executorRef === attempted.executor) {
|
|
5523
|
+
setExecutorRef(previous.executor);
|
|
5524
|
+
}
|
|
5525
|
+
if (executorEffortRef === attempted.executorEffort) {
|
|
5526
|
+
setExecutorEffortRef(previous.executorEffort);
|
|
5527
|
+
}
|
|
5445
5528
|
};
|
|
5529
|
+
let attempted = liveRefSnapshot();
|
|
5446
5530
|
const executorOverride = hasExecutorOverride(args);
|
|
5447
5531
|
const advisorOverride = hasAdvisorOverride(args);
|
|
5448
5532
|
const argumentError = parseArgs(args);
|
|
5449
5533
|
if (argumentError) {
|
|
5450
|
-
|
|
5534
|
+
attempted = liveRefSnapshot();
|
|
5535
|
+
restoreRefs(attempted);
|
|
5451
5536
|
notify(ctx, argumentError, "error");
|
|
5452
5537
|
return;
|
|
5453
5538
|
}
|
|
5454
5539
|
const prepared = await prepareActivationModels(runtime, ctx, announce, executorOverride, advisorOverride);
|
|
5455
5540
|
if (!prepared) {
|
|
5456
|
-
|
|
5541
|
+
attempted = liveRefSnapshot();
|
|
5542
|
+
restoreActivationRefsIfCurrent(canContinue, () => restoreRefs(attempted));
|
|
5543
|
+
return;
|
|
5544
|
+
}
|
|
5545
|
+
const { cancelled, error } = await resolveActivationModels(runtime, ctx, canContinue);
|
|
5546
|
+
if (cancelled || !canContinue()) {
|
|
5457
5547
|
return;
|
|
5458
5548
|
}
|
|
5459
|
-
const { error } = await resolveActivationModels(runtime, ctx);
|
|
5460
5549
|
if (error) {
|
|
5461
|
-
restoreRefs();
|
|
5550
|
+
restoreRefs(attempted);
|
|
5462
5551
|
notify(ctx, error, "error");
|
|
5463
5552
|
return;
|
|
5464
5553
|
}
|
|
5465
|
-
|
|
5466
|
-
|
|
5554
|
+
const reenableTools = !advisorToolsEnabledRef;
|
|
5555
|
+
if (reenableTools) {
|
|
5556
|
+
setAdvisorToolsEnabledRef(true);
|
|
5557
|
+
}
|
|
5558
|
+
const shouldSave = Boolean(args.trim() || prepared.pickedModels || prepared.pendingExecutor || reenableTools);
|
|
5559
|
+
if (!persistSuccessfulActivation(ctx, shouldSave, reenableTools, () => restoreRefs(liveRefSnapshot()))) {
|
|
5560
|
+
return;
|
|
5467
5561
|
}
|
|
5468
5562
|
runtime.pendingExecutorModelRef = undefined;
|
|
5469
5563
|
if (executorEffortRef && !isMarkedSubagent()) {
|
|
5470
5564
|
runtime.pi.setThinkingLevel(executorEffortRef);
|
|
5471
5565
|
}
|
|
5472
|
-
|
|
5473
|
-
runtime.pi.setActiveTools([
|
|
5474
|
-
...runtime.pi.getActiveTools(),
|
|
5475
|
-
"ask_advisor",
|
|
5476
|
-
"record_advisor_outcome"
|
|
5477
|
-
]);
|
|
5478
|
-
}
|
|
5566
|
+
setAdvisorToolsActive(runtime.pi, true);
|
|
5479
5567
|
const activeModel = isMarkedSubagent() ? ctx.model : findConfiguredModel(ctx, executorRef);
|
|
5480
5568
|
runtime.updateSameModelNotice(ctx, activeModel);
|
|
5481
5569
|
if (announce) {
|
|
@@ -5494,12 +5582,19 @@ var registerCommandLifecycle = (runtime, activateAdvisor) => {
|
|
|
5494
5582
|
runtime.resetSameModelNotice();
|
|
5495
5583
|
try {
|
|
5496
5584
|
loadConfig(ctx);
|
|
5585
|
+
if (!advisorToolsEnabledRef) {
|
|
5586
|
+
setAdvisorToolsActive(runtime.pi, false);
|
|
5587
|
+
runtime.updateSameModelNotice(ctx);
|
|
5588
|
+
return;
|
|
5589
|
+
}
|
|
5497
5590
|
if (alwaysOnRef) {
|
|
5591
|
+
setAdvisorToolsActive(runtime.pi, false);
|
|
5498
5592
|
await activateAdvisor("", ctx, false);
|
|
5499
5593
|
} else {
|
|
5500
5594
|
runtime.updateSameModelNotice(ctx);
|
|
5501
5595
|
}
|
|
5502
5596
|
} catch (error) {
|
|
5597
|
+
setAdvisorToolsActive(runtime.pi, false);
|
|
5503
5598
|
const message = error instanceof Error ? error.message : String(error);
|
|
5504
5599
|
notify(ctx, `Advisor activation failed: ${message}`, "error");
|
|
5505
5600
|
}
|
|
@@ -8912,9 +9007,16 @@ var createSettingsItems = ({
|
|
|
8912
9007
|
label: "Context window",
|
|
8913
9008
|
values: presets.map((preset) => preset.label)
|
|
8914
9009
|
},
|
|
9010
|
+
{
|
|
9011
|
+
currentValue: settingValue(settings.advisorToolsEnabled, true),
|
|
9012
|
+
description: "Allow the model to call the Advisor tools; /advisor-off disables them across sessions.",
|
|
9013
|
+
id: "advisorToolsEnabled",
|
|
9014
|
+
label: "Advisor tools",
|
|
9015
|
+
values: TOGGLE_VALUES
|
|
9016
|
+
},
|
|
8915
9017
|
{
|
|
8916
9018
|
currentValue: settingValue(settings.simpleMode, false),
|
|
8917
|
-
description: "Keep
|
|
9019
|
+
description: "Keep enabled Advisor tools available on demand without automatic gates or blocks.",
|
|
8918
9020
|
id: "simpleMode",
|
|
8919
9021
|
label: "Simple mode",
|
|
8920
9022
|
values: TOGGLE_VALUES
|
|
@@ -9134,10 +9236,13 @@ var BOOLEAN_SETTING_IDS = new Set(BOOLEAN_SETTING_FIELDS);
|
|
|
9134
9236
|
var parseModelWhitelist = (value) => [
|
|
9135
9237
|
...new Set(value.split(",").map((model) => model.trim()).filter(Boolean))
|
|
9136
9238
|
];
|
|
9137
|
-
var
|
|
9239
|
+
var applyModeMutation = (settings, id, value) => {
|
|
9138
9240
|
switch (id) {
|
|
9139
|
-
case "
|
|
9140
|
-
settings.
|
|
9241
|
+
case "advisorToolsEnabled": {
|
|
9242
|
+
settings.advisorToolsEnabled = value === "On";
|
|
9243
|
+
if (!settings.advisorToolsEnabled) {
|
|
9244
|
+
settings.alwaysOn = false;
|
|
9245
|
+
}
|
|
9141
9246
|
return true;
|
|
9142
9247
|
}
|
|
9143
9248
|
case "simpleMode": {
|
|
@@ -9146,6 +9251,20 @@ var applyCoreMutation = (settings, id, value, presets) => {
|
|
|
9146
9251
|
}
|
|
9147
9252
|
case "alwaysOn": {
|
|
9148
9253
|
settings.alwaysOn = value === "On";
|
|
9254
|
+
if (settings.alwaysOn) {
|
|
9255
|
+
settings.advisorToolsEnabled = true;
|
|
9256
|
+
}
|
|
9257
|
+
return true;
|
|
9258
|
+
}
|
|
9259
|
+
default: {
|
|
9260
|
+
return false;
|
|
9261
|
+
}
|
|
9262
|
+
}
|
|
9263
|
+
};
|
|
9264
|
+
var applyCoreMutation = (settings, id, value, presets) => {
|
|
9265
|
+
switch (id) {
|
|
9266
|
+
case "context": {
|
|
9267
|
+
settings.contextMaxChars = presets.find((preset) => preset.label === value)?.value ?? settings.contextMaxChars;
|
|
9149
9268
|
return true;
|
|
9150
9269
|
}
|
|
9151
9270
|
case "fallbackModel": {
|
|
@@ -9260,6 +9379,9 @@ var applyJevMutation = (settings, id, value) => {
|
|
|
9260
9379
|
}
|
|
9261
9380
|
};
|
|
9262
9381
|
var mutateAdvisorSettings = (settings, id, value, presets) => {
|
|
9382
|
+
if (applyModeMutation(settings, id, value)) {
|
|
9383
|
+
return;
|
|
9384
|
+
}
|
|
9263
9385
|
if (applyCoreMutation(settings, id, value, presets)) {
|
|
9264
9386
|
return;
|
|
9265
9387
|
}
|
|
@@ -9467,6 +9589,7 @@ var applySessionSettings = (settings) => {
|
|
|
9467
9589
|
setShowUsageDetailsRef(settings.showUsageDetails ?? true);
|
|
9468
9590
|
setShowUsageFooterRef(settings.showUsageFooter ?? false);
|
|
9469
9591
|
setSimpleModeRef(settings.simpleMode ?? false);
|
|
9592
|
+
setAdvisorToolsEnabledRef(settings.advisorToolsEnabled ?? true);
|
|
9470
9593
|
setAlwaysOnRef(settings.alwaysOn ?? false);
|
|
9471
9594
|
setAdvisorFailureModeRef(settings.failureMode ?? "block-session");
|
|
9472
9595
|
setAdvisorHerdrIntegrationRef(settings.herdrIntegration ?? true);
|
|
@@ -9531,6 +9654,7 @@ var persistJevSettings = (ctx, settings, runtime) => {
|
|
|
9531
9654
|
return false;
|
|
9532
9655
|
}
|
|
9533
9656
|
try {
|
|
9657
|
+
setAdvisorToolsActive(runtime.pi, settings.advisorToolsEnabled ?? true);
|
|
9534
9658
|
runtime.updateSameModelNotice(ctx);
|
|
9535
9659
|
runtime.updateAdvisorUsageStatus(ctx);
|
|
9536
9660
|
} catch (error) {
|
|
@@ -9558,13 +9682,27 @@ var registerSettingsCommands = (runtime) => {
|
|
|
9558
9682
|
modelRefs: getConfiguredModelRefs(ctx),
|
|
9559
9683
|
onCancel: () => done(undefined),
|
|
9560
9684
|
onChange: (settings) => {
|
|
9685
|
+
const toolsWereEnabled = getAdvisorSettings().advisorToolsEnabled ?? true;
|
|
9686
|
+
const toolsEnabled = settings.advisorToolsEnabled ?? true;
|
|
9561
9687
|
try {
|
|
9562
9688
|
saveAdvisorSettings(ctx, settings);
|
|
9689
|
+
if (toolsWereEnabled !== toolsEnabled) {
|
|
9690
|
+
runtime.noteAdvisorToolsStateChange();
|
|
9691
|
+
}
|
|
9692
|
+
setAdvisorToolsActive(runtime.pi, toolsEnabled);
|
|
9563
9693
|
runtime.updateSameModelNotice(ctx);
|
|
9564
9694
|
runtime.updateAdvisorUsageStatus(ctx);
|
|
9565
9695
|
} catch (error) {
|
|
9696
|
+
const toolsDisabled = toolsWereEnabled && settings.advisorToolsEnabled === false;
|
|
9697
|
+
if (toolsDisabled) {
|
|
9698
|
+
runtime.noteAdvisorToolsStateChange();
|
|
9699
|
+
setAdvisorToolsEnabledRef(false);
|
|
9700
|
+
setAlwaysOnRef(false);
|
|
9701
|
+
setAdvisorToolsActive(runtime.pi, false);
|
|
9702
|
+
runtime.resetSameModelNotice();
|
|
9703
|
+
}
|
|
9566
9704
|
const message = error instanceof Error ? error.message : String(error);
|
|
9567
|
-
ctx.ui.notify(`Could not save Advisor settings: ${message}`, "error");
|
|
9705
|
+
ctx.ui.notify(toolsDisabled ? `Could not save Advisor settings; tools remain disabled for this session. ${message}` : `Could not save Advisor settings: ${message}`, "error");
|
|
9568
9706
|
}
|
|
9569
9707
|
},
|
|
9570
9708
|
onJevFilter: (_selection, settings) => persistJevSettings(ctx, settings, runtime),
|
|
@@ -9576,20 +9714,37 @@ var registerSettingsCommands = (runtime) => {
|
|
|
9576
9714
|
}
|
|
9577
9715
|
});
|
|
9578
9716
|
runtime.pi.registerCommand("advisor-off", {
|
|
9579
|
-
description: "Disable
|
|
9717
|
+
description: "Disable model-facing Advisor tools across sessions; keep the current model",
|
|
9580
9718
|
handler: (_args, ctx) => {
|
|
9581
|
-
runtime.
|
|
9719
|
+
runtime.noteAdvisorToolsStateChange();
|
|
9720
|
+
setAdvisorToolsActive(runtime.pi, false);
|
|
9582
9721
|
runtime.resetSameModelNotice();
|
|
9722
|
+
try {
|
|
9723
|
+
loadConfig(ctx);
|
|
9724
|
+
} catch (error) {
|
|
9725
|
+
setAdvisorToolsEnabledRef(false);
|
|
9726
|
+
setAlwaysOnRef(false);
|
|
9727
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
9728
|
+
notify(ctx, `Advisor tools disabled for this session, but configuration could not be reloaded: ${message}`, "error");
|
|
9729
|
+
return Promise.resolve();
|
|
9730
|
+
}
|
|
9583
9731
|
const wasAlwaysOn = alwaysOnRef;
|
|
9732
|
+
const persisted = getPersistedModelRefs();
|
|
9733
|
+
setAdvisorToolsEnabledRef(false);
|
|
9584
9734
|
if (wasAlwaysOn) {
|
|
9585
|
-
const persisted = getPersistedModelRefs();
|
|
9586
9735
|
setAlwaysOnRef(false);
|
|
9736
|
+
}
|
|
9737
|
+
try {
|
|
9587
9738
|
saveConfig(ctx, {
|
|
9588
9739
|
persistAdvisor: Boolean(persisted.advisor),
|
|
9589
9740
|
persistExecutor: Boolean(persisted.executor)
|
|
9590
9741
|
});
|
|
9742
|
+
} catch (error) {
|
|
9743
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
9744
|
+
notify(ctx, `Advisor tools disabled for this session, but the setting could not be saved: ${message}`, "error");
|
|
9745
|
+
return Promise.resolve();
|
|
9591
9746
|
}
|
|
9592
|
-
notify(ctx, `Advisor
|
|
9747
|
+
notify(ctx, `Advisor tools disabled. Current model unchanged.${wasAlwaysOn ? " Always on turned off." : ""}`, "info");
|
|
9593
9748
|
return Promise.resolve();
|
|
9594
9749
|
}
|
|
9595
9750
|
});
|
|
@@ -10445,12 +10600,25 @@ ${guidelines.map((rule) => `- ${rule}`).join(`
|
|
|
10445
10600
|
reason: session.blockedReason ?? "Advisor session is blocked."
|
|
10446
10601
|
};
|
|
10447
10602
|
}
|
|
10603
|
+
const isAdvisorTool = event.toolName === "ask_advisor" || event.toolName === "record_advisor_outcome";
|
|
10604
|
+
if (isAdvisorTool && !advisorToolsEnabledRef) {
|
|
10605
|
+
return {
|
|
10606
|
+
block: true,
|
|
10607
|
+
reason: "Advisor tools are disabled. Enable them in /advisor-settings or run /advisor."
|
|
10608
|
+
};
|
|
10609
|
+
}
|
|
10448
10610
|
if (!pi.getActiveTools().includes("ask_advisor")) {
|
|
10449
10611
|
return;
|
|
10450
10612
|
}
|
|
10451
10613
|
if (!loadConfigOrSkipGating(ctx)) {
|
|
10452
10614
|
return;
|
|
10453
10615
|
}
|
|
10616
|
+
if (isAdvisorTool && !advisorToolsEnabledRef) {
|
|
10617
|
+
return {
|
|
10618
|
+
block: true,
|
|
10619
|
+
reason: "Advisor tools are disabled. Enable them in /advisor-settings or run /advisor."
|
|
10620
|
+
};
|
|
10621
|
+
}
|
|
10454
10622
|
if (sameModelAdvisorDisabled(ctx)) {
|
|
10455
10623
|
return;
|
|
10456
10624
|
}
|
package/package.json
CHANGED
|
@@ -9,11 +9,13 @@ import { parseArgs } from "../config/args.ts";
|
|
|
9
9
|
import {
|
|
10
10
|
advisorEffortRef,
|
|
11
11
|
advisorRef,
|
|
12
|
+
advisorToolsEnabledRef,
|
|
12
13
|
contextMaxCharsRef,
|
|
13
14
|
executorEffortRef,
|
|
14
15
|
executorRef,
|
|
15
16
|
setAdvisorEffortRef,
|
|
16
17
|
setAdvisorRef,
|
|
18
|
+
setAdvisorToolsEnabledRef,
|
|
17
19
|
setContextMaxCharsRef,
|
|
18
20
|
setExecutorEffortRef,
|
|
19
21
|
setExecutorRef,
|
|
@@ -24,6 +26,7 @@ import {
|
|
|
24
26
|
loadCommandConfig,
|
|
25
27
|
prepareActivationModels,
|
|
26
28
|
} from "./activation-preparation.ts";
|
|
29
|
+
import { setAdvisorToolsActive } from "./advisor-tools.ts";
|
|
27
30
|
import {
|
|
28
31
|
ADVISOR_ACTIVATION_EXPLANATION,
|
|
29
32
|
findConfiguredModel,
|
|
@@ -35,8 +38,12 @@ import type { CommandRuntime, ThinkingLevel } from "./types.ts";
|
|
|
35
38
|
|
|
36
39
|
const resolveActivationModels = async (
|
|
37
40
|
runtime: CommandRuntime,
|
|
38
|
-
ctx: ExtensionContext
|
|
41
|
+
ctx: ExtensionContext,
|
|
42
|
+
canContinue: () => boolean
|
|
39
43
|
) => {
|
|
44
|
+
if (!canContinue()) {
|
|
45
|
+
return { cancelled: true };
|
|
46
|
+
}
|
|
40
47
|
const executor = findConfiguredModel(ctx, executorRef);
|
|
41
48
|
if (!executor) {
|
|
42
49
|
return {
|
|
@@ -54,6 +61,9 @@ const resolveActivationModels = async (
|
|
|
54
61
|
};
|
|
55
62
|
}
|
|
56
63
|
const advisorAuth = await ctx.modelRegistry.getApiKeyAndHeaders(advisor);
|
|
64
|
+
if (!canContinue()) {
|
|
65
|
+
return { cancelled: true };
|
|
66
|
+
}
|
|
57
67
|
if (!(advisorAuth.ok && advisorAuth.apiKey)) {
|
|
58
68
|
return { error: `No API key for Advisor ${advisorRef}` };
|
|
59
69
|
}
|
|
@@ -63,6 +73,48 @@ const resolveActivationModels = async (
|
|
|
63
73
|
return {};
|
|
64
74
|
};
|
|
65
75
|
|
|
76
|
+
const restoreActivationRefsIfCurrent = (
|
|
77
|
+
canContinue: () => boolean,
|
|
78
|
+
restoreRefs: () => void
|
|
79
|
+
) => {
|
|
80
|
+
if (canContinue()) {
|
|
81
|
+
restoreRefs();
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const liveRefSnapshot = () => ({
|
|
86
|
+
advisor: advisorRef,
|
|
87
|
+
advisorEffort: advisorEffortRef,
|
|
88
|
+
contextMaxChars: contextMaxCharsRef,
|
|
89
|
+
executor: executorRef,
|
|
90
|
+
executorEffort: executorEffortRef,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const persistSuccessfulActivation = (
|
|
94
|
+
ctx: ExtensionContext,
|
|
95
|
+
shouldSave: boolean,
|
|
96
|
+
reenableTools: boolean,
|
|
97
|
+
restoreRefs: () => void
|
|
98
|
+
) => {
|
|
99
|
+
if (!shouldSave) {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
saveConfig(ctx, { persistAdvisor: true, persistExecutor: true });
|
|
104
|
+
} catch (saveError) {
|
|
105
|
+
if (!reenableTools) {
|
|
106
|
+
throw saveError;
|
|
107
|
+
}
|
|
108
|
+
setAdvisorToolsEnabledRef(false);
|
|
109
|
+
restoreRefs();
|
|
110
|
+
const message =
|
|
111
|
+
saveError instanceof Error ? saveError.message : String(saveError);
|
|
112
|
+
notify(ctx, `Could not save Advisor activation: ${message}`, "error");
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
return true;
|
|
116
|
+
};
|
|
117
|
+
|
|
66
118
|
export const activateAdvisor = async (
|
|
67
119
|
runtime: CommandRuntime,
|
|
68
120
|
args: string,
|
|
@@ -72,6 +124,9 @@ export const activateAdvisor = async (
|
|
|
72
124
|
if (!loadCommandConfig(ctx)) {
|
|
73
125
|
return;
|
|
74
126
|
}
|
|
127
|
+
const { toolAvailabilityRevision } = runtime;
|
|
128
|
+
const canContinue = () =>
|
|
129
|
+
runtime.toolAvailabilityRevision === toolAvailabilityRevision;
|
|
75
130
|
const previous = {
|
|
76
131
|
advisor: advisorRef,
|
|
77
132
|
advisorEffort: advisorEffortRef,
|
|
@@ -79,18 +134,33 @@ export const activateAdvisor = async (
|
|
|
79
134
|
executor: executorRef,
|
|
80
135
|
executorEffort: executorEffortRef,
|
|
81
136
|
};
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
137
|
+
const liveSnapshot = liveRefSnapshot;
|
|
138
|
+
// Restores only refs this activation still owns. A concurrent settings
|
|
139
|
+
// save that replaced a ref keeps its newer value.
|
|
140
|
+
const restoreRefs = (attempted: ReturnType<typeof liveSnapshot>) => {
|
|
141
|
+
if (advisorRef === attempted.advisor) {
|
|
142
|
+
setAdvisorRef(previous.advisor);
|
|
143
|
+
}
|
|
144
|
+
if (advisorEffortRef === attempted.advisorEffort) {
|
|
145
|
+
setAdvisorEffortRef(previous.advisorEffort);
|
|
146
|
+
}
|
|
147
|
+
if (contextMaxCharsRef === attempted.contextMaxChars) {
|
|
148
|
+
setContextMaxCharsRef(previous.contextMaxChars);
|
|
149
|
+
}
|
|
150
|
+
if (executorRef === attempted.executor) {
|
|
151
|
+
setExecutorRef(previous.executor);
|
|
152
|
+
}
|
|
153
|
+
if (executorEffortRef === attempted.executorEffort) {
|
|
154
|
+
setExecutorEffortRef(previous.executorEffort);
|
|
155
|
+
}
|
|
88
156
|
};
|
|
157
|
+
let attempted = liveRefSnapshot();
|
|
89
158
|
const executorOverride = hasExecutorOverride(args);
|
|
90
159
|
const advisorOverride = hasAdvisorOverride(args);
|
|
91
160
|
const argumentError = parseArgs(args);
|
|
92
161
|
if (argumentError) {
|
|
93
|
-
|
|
162
|
+
attempted = liveRefSnapshot();
|
|
163
|
+
restoreRefs(attempted);
|
|
94
164
|
notify(ctx, argumentError, "error");
|
|
95
165
|
return;
|
|
96
166
|
}
|
|
@@ -103,20 +173,42 @@ export const activateAdvisor = async (
|
|
|
103
173
|
advisorOverride
|
|
104
174
|
);
|
|
105
175
|
if (!prepared) {
|
|
106
|
-
|
|
176
|
+
attempted = liveRefSnapshot();
|
|
177
|
+
restoreActivationRefsIfCurrent(canContinue, () => restoreRefs(attempted));
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
const { cancelled, error } = await resolveActivationModels(
|
|
181
|
+
runtime,
|
|
182
|
+
ctx,
|
|
183
|
+
canContinue
|
|
184
|
+
);
|
|
185
|
+
if (cancelled || !canContinue()) {
|
|
107
186
|
return;
|
|
108
187
|
}
|
|
109
|
-
const { error } = await resolveActivationModels(runtime, ctx);
|
|
110
188
|
if (error) {
|
|
111
|
-
restoreRefs();
|
|
189
|
+
restoreRefs(attempted);
|
|
112
190
|
notify(ctx, error, "error");
|
|
113
191
|
return;
|
|
114
192
|
}
|
|
115
193
|
// parseArgs, model picking, and an inactive `/model` selection only mutate
|
|
116
194
|
// in-memory refs. Persist them once both models are known and authenticated,
|
|
117
195
|
// so an unusable model reference is never written to the configuration.
|
|
118
|
-
|
|
119
|
-
|
|
196
|
+
const reenableTools = !advisorToolsEnabledRef;
|
|
197
|
+
if (reenableTools) {
|
|
198
|
+
setAdvisorToolsEnabledRef(true);
|
|
199
|
+
}
|
|
200
|
+
const shouldSave = Boolean(
|
|
201
|
+
args.trim() ||
|
|
202
|
+
prepared.pickedModels ||
|
|
203
|
+
prepared.pendingExecutor ||
|
|
204
|
+
reenableTools
|
|
205
|
+
);
|
|
206
|
+
if (
|
|
207
|
+
!persistSuccessfulActivation(ctx, shouldSave, reenableTools, () =>
|
|
208
|
+
restoreRefs(liveRefSnapshot())
|
|
209
|
+
)
|
|
210
|
+
) {
|
|
211
|
+
return;
|
|
120
212
|
}
|
|
121
213
|
// A successful activation has committed the effective Executor. Do not let
|
|
122
214
|
// an older inactive selection override an explicit activation argument on a
|
|
@@ -126,13 +218,7 @@ export const activateAdvisor = async (
|
|
|
126
218
|
// SAFETY: executorEffortRef is operator-configured and trusted to name a ThinkingLevel.
|
|
127
219
|
runtime.pi.setThinkingLevel(executorEffortRef as ThinkingLevel);
|
|
128
220
|
}
|
|
129
|
-
|
|
130
|
-
runtime.pi.setActiveTools([
|
|
131
|
-
...runtime.pi.getActiveTools(),
|
|
132
|
-
"ask_advisor",
|
|
133
|
-
"record_advisor_outcome",
|
|
134
|
-
]);
|
|
135
|
-
}
|
|
221
|
+
setAdvisorToolsActive(runtime.pi, true);
|
|
136
222
|
const activeModel = isMarkedSubagent()
|
|
137
223
|
? ctx.model
|
|
138
224
|
: findConfiguredModel(ctx, executorRef);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
|
|
3
|
+
const ADVISOR_TOOL_NAMES = new Set(["ask_advisor", "record_advisor_outcome"]);
|
|
4
|
+
|
|
5
|
+
export const setAdvisorToolsActive = (
|
|
6
|
+
pi: Pick<ExtensionAPI, "getActiveTools" | "setActiveTools">,
|
|
7
|
+
enabled: boolean
|
|
8
|
+
) => {
|
|
9
|
+
const current = pi.getActiveTools();
|
|
10
|
+
const next = current.filter(
|
|
11
|
+
(name) => enabled || !ADVISOR_TOOL_NAMES.has(name)
|
|
12
|
+
);
|
|
13
|
+
if (enabled) {
|
|
14
|
+
for (const name of ADVISOR_TOOL_NAMES) {
|
|
15
|
+
if (!next.includes(name)) {
|
|
16
|
+
next.push(name);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (
|
|
21
|
+
next.length !== current.length ||
|
|
22
|
+
next.some((name, index) => name !== current[index])
|
|
23
|
+
) {
|
|
24
|
+
pi.setActiveTools(next);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
@@ -2,12 +2,14 @@ import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
|
2
2
|
|
|
3
3
|
import { isMarkedSubagent } from "../child-session.ts";
|
|
4
4
|
import {
|
|
5
|
+
advisorToolsEnabledRef,
|
|
5
6
|
alwaysOnRef,
|
|
6
7
|
executorRef,
|
|
7
8
|
getPersistedModelRefs,
|
|
8
9
|
setExecutorRef,
|
|
9
10
|
} from "../config/state.ts";
|
|
10
11
|
import { loadConfig, saveConfig } from "../config/storage.ts";
|
|
12
|
+
import { setAdvisorToolsActive } from "./advisor-tools.ts";
|
|
11
13
|
import { notify } from "./runtime.ts";
|
|
12
14
|
import type { CommandRuntime } from "./types.ts";
|
|
13
15
|
|
|
@@ -28,12 +30,19 @@ export const registerCommandLifecycle = (
|
|
|
28
30
|
// lifecycle handler and break session startup.
|
|
29
31
|
try {
|
|
30
32
|
loadConfig(ctx);
|
|
33
|
+
if (!advisorToolsEnabledRef) {
|
|
34
|
+
setAdvisorToolsActive(runtime.pi, false);
|
|
35
|
+
runtime.updateSameModelNotice(ctx);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
31
38
|
if (alwaysOnRef) {
|
|
39
|
+
setAdvisorToolsActive(runtime.pi, false);
|
|
32
40
|
await activateAdvisor("", ctx, false);
|
|
33
41
|
} else {
|
|
34
42
|
runtime.updateSameModelNotice(ctx);
|
|
35
43
|
}
|
|
36
44
|
} catch (error) {
|
|
45
|
+
setAdvisorToolsActive(runtime.pi, false);
|
|
37
46
|
const message = error instanceof Error ? error.message : String(error);
|
|
38
47
|
notify(ctx, `Advisor activation failed: ${message}`, "error");
|
|
39
48
|
}
|
package/src/commands/runtime.ts
CHANGED
|
@@ -56,6 +56,7 @@ class CommandRuntime implements CommandRuntimeContract {
|
|
|
56
56
|
manualProgressSequence = 0;
|
|
57
57
|
pendingExecutorModelRef: string | undefined;
|
|
58
58
|
suppressModelSelectionSync = false;
|
|
59
|
+
toolAvailabilityRevision = 0;
|
|
59
60
|
private lastSameModelDisabled: boolean | undefined;
|
|
60
61
|
|
|
61
62
|
constructor(pi: ExtensionAPI, dependencies: CommandDependencies = {}) {
|
|
@@ -93,6 +94,10 @@ class CommandRuntime implements CommandRuntimeContract {
|
|
|
93
94
|
return this.pi.getActiveTools().includes("ask_advisor");
|
|
94
95
|
}
|
|
95
96
|
|
|
97
|
+
noteAdvisorToolsStateChange() {
|
|
98
|
+
this.toolAvailabilityRevision += 1;
|
|
99
|
+
}
|
|
100
|
+
|
|
96
101
|
resetSameModelNotice() {
|
|
97
102
|
this.lastSameModelDisabled = undefined;
|
|
98
103
|
}
|
|
@@ -4,9 +4,10 @@ import {
|
|
|
4
4
|
alwaysOnRef,
|
|
5
5
|
getAdvisorSettings,
|
|
6
6
|
getPersistedModelRefs,
|
|
7
|
+
setAdvisorToolsEnabledRef,
|
|
7
8
|
setAlwaysOnRef,
|
|
8
9
|
} from "../config/state.ts";
|
|
9
|
-
import { saveConfig } from "../config/storage.ts";
|
|
10
|
+
import { loadConfig, saveConfig } from "../config/storage.ts";
|
|
10
11
|
import {
|
|
11
12
|
resolveJevTransport,
|
|
12
13
|
resolveJevTransportFor,
|
|
@@ -15,6 +16,7 @@ import {
|
|
|
15
16
|
import { AdvisorSettingsSelector } from "../ui/settings-selector.ts";
|
|
16
17
|
import type { AdvisorSettings } from "../ui/types.ts";
|
|
17
18
|
import { loadCommandConfig } from "./activation-preparation.ts";
|
|
19
|
+
import { setAdvisorToolsActive } from "./advisor-tools.ts";
|
|
18
20
|
import {
|
|
19
21
|
CONTEXT_PRESETS,
|
|
20
22
|
EFFORT_LEVELS,
|
|
@@ -37,6 +39,7 @@ const persistJevSettings = (
|
|
|
37
39
|
return false;
|
|
38
40
|
}
|
|
39
41
|
try {
|
|
42
|
+
setAdvisorToolsActive(runtime.pi, settings.advisorToolsEnabled ?? true);
|
|
40
43
|
runtime.updateSameModelNotice(ctx);
|
|
41
44
|
runtime.updateAdvisorUsageStatus(ctx);
|
|
42
45
|
} catch (error) {
|
|
@@ -75,15 +78,33 @@ export const registerSettingsCommands = (runtime: CommandRuntime) => {
|
|
|
75
78
|
modelRefs: getConfiguredModelRefs(ctx),
|
|
76
79
|
onCancel: () => done(undefined),
|
|
77
80
|
onChange: (settings) => {
|
|
81
|
+
const toolsWereEnabled =
|
|
82
|
+
getAdvisorSettings().advisorToolsEnabled ?? true;
|
|
83
|
+
const toolsEnabled = settings.advisorToolsEnabled ?? true;
|
|
78
84
|
try {
|
|
79
85
|
saveAdvisorSettings(ctx, settings);
|
|
86
|
+
if (toolsWereEnabled !== toolsEnabled) {
|
|
87
|
+
runtime.noteAdvisorToolsStateChange();
|
|
88
|
+
}
|
|
89
|
+
setAdvisorToolsActive(runtime.pi, toolsEnabled);
|
|
80
90
|
runtime.updateSameModelNotice(ctx);
|
|
81
91
|
runtime.updateAdvisorUsageStatus(ctx);
|
|
82
92
|
} catch (error) {
|
|
93
|
+
const toolsDisabled =
|
|
94
|
+
toolsWereEnabled && settings.advisorToolsEnabled === false;
|
|
95
|
+
if (toolsDisabled) {
|
|
96
|
+
runtime.noteAdvisorToolsStateChange();
|
|
97
|
+
setAdvisorToolsEnabledRef(false);
|
|
98
|
+
setAlwaysOnRef(false);
|
|
99
|
+
setAdvisorToolsActive(runtime.pi, false);
|
|
100
|
+
runtime.resetSameModelNotice();
|
|
101
|
+
}
|
|
83
102
|
const message =
|
|
84
103
|
error instanceof Error ? error.message : String(error);
|
|
85
104
|
ctx.ui.notify(
|
|
86
|
-
|
|
105
|
+
toolsDisabled
|
|
106
|
+
? `Could not save Advisor settings; tools remain disabled for this session. ${message}`
|
|
107
|
+
: `Could not save Advisor settings: ${message}`,
|
|
87
108
|
"error"
|
|
88
109
|
);
|
|
89
110
|
}
|
|
@@ -101,30 +122,48 @@ export const registerSettingsCommands = (runtime: CommandRuntime) => {
|
|
|
101
122
|
});
|
|
102
123
|
|
|
103
124
|
runtime.pi.registerCommand("advisor-off", {
|
|
104
|
-
description:
|
|
125
|
+
description:
|
|
126
|
+
"Disable model-facing Advisor tools across sessions; keep the current model",
|
|
105
127
|
handler: (_args, ctx) => {
|
|
106
|
-
runtime.
|
|
107
|
-
|
|
108
|
-
.getActiveTools()
|
|
109
|
-
.filter(
|
|
110
|
-
(name) =>
|
|
111
|
-
name !== "ask_advisor" && name !== "record_advisor_outcome"
|
|
112
|
-
)
|
|
113
|
-
);
|
|
128
|
+
runtime.noteAdvisorToolsStateChange();
|
|
129
|
+
setAdvisorToolsActive(runtime.pi, false);
|
|
114
130
|
runtime.resetSameModelNotice();
|
|
115
|
-
|
|
131
|
+
try {
|
|
132
|
+
loadConfig(ctx);
|
|
133
|
+
} catch (error) {
|
|
134
|
+
setAdvisorToolsEnabledRef(false);
|
|
135
|
+
setAlwaysOnRef(false);
|
|
136
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
137
|
+
notify(
|
|
138
|
+
ctx,
|
|
139
|
+
`Advisor tools disabled for this session, but configuration could not be reloaded: ${message}`,
|
|
140
|
+
"error"
|
|
141
|
+
);
|
|
142
|
+
return Promise.resolve();
|
|
143
|
+
}
|
|
116
144
|
const wasAlwaysOn = alwaysOnRef;
|
|
145
|
+
const persisted = getPersistedModelRefs();
|
|
146
|
+
setAdvisorToolsEnabledRef(false);
|
|
117
147
|
if (wasAlwaysOn) {
|
|
118
|
-
const persisted = getPersistedModelRefs();
|
|
119
148
|
setAlwaysOnRef(false);
|
|
149
|
+
}
|
|
150
|
+
try {
|
|
120
151
|
saveConfig(ctx, {
|
|
121
152
|
persistAdvisor: Boolean(persisted.advisor),
|
|
122
153
|
persistExecutor: Boolean(persisted.executor),
|
|
123
154
|
});
|
|
155
|
+
} catch (error) {
|
|
156
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
157
|
+
notify(
|
|
158
|
+
ctx,
|
|
159
|
+
`Advisor tools disabled for this session, but the setting could not be saved: ${message}`,
|
|
160
|
+
"error"
|
|
161
|
+
);
|
|
162
|
+
return Promise.resolve();
|
|
124
163
|
}
|
|
125
164
|
notify(
|
|
126
165
|
ctx,
|
|
127
|
-
`Advisor
|
|
166
|
+
`Advisor tools disabled. Current model unchanged.${wasAlwaysOn ? " Always on turned off." : ""}`,
|
|
128
167
|
"info"
|
|
129
168
|
);
|
|
130
169
|
return Promise.resolve();
|
|
@@ -44,6 +44,7 @@ import {
|
|
|
44
44
|
setAdvisorToolResultMaxLinesRef,
|
|
45
45
|
setAdvisorTrackedFileContentRef,
|
|
46
46
|
setAdvisorUntrackedContentRef,
|
|
47
|
+
setAdvisorToolsEnabledRef,
|
|
47
48
|
setAlwaysOnRef,
|
|
48
49
|
setContextMaxCharsRef,
|
|
49
50
|
setShowUsageDetailsRef,
|
|
@@ -91,6 +92,7 @@ const applySessionSettings = (settings: AdvisorSettings) => {
|
|
|
91
92
|
setShowUsageDetailsRef(settings.showUsageDetails ?? true);
|
|
92
93
|
setShowUsageFooterRef(settings.showUsageFooter ?? false);
|
|
93
94
|
setSimpleModeRef(settings.simpleMode ?? false);
|
|
95
|
+
setAdvisorToolsEnabledRef(settings.advisorToolsEnabled ?? true);
|
|
94
96
|
setAlwaysOnRef(settings.alwaysOn ?? false);
|
|
95
97
|
setAdvisorFailureModeRef(settings.failureMode ?? "block-session");
|
|
96
98
|
setAdvisorHerdrIntegrationRef(settings.herdrIntegration ?? true);
|
package/src/commands/types.ts
CHANGED
|
@@ -56,6 +56,8 @@ export interface CommandRuntime {
|
|
|
56
56
|
readonly advisorSessionState: AdvisorSessionState;
|
|
57
57
|
readonly herdrActivity: HerdrAdvisorActivityScope;
|
|
58
58
|
flowEnabled: () => boolean;
|
|
59
|
+
toolAvailabilityRevision: number;
|
|
60
|
+
noteAdvisorToolsStateChange: () => void;
|
|
59
61
|
readonly manualConsultations: Map<AbortController, symbol>;
|
|
60
62
|
readonly manualProgress: Map<string, ManualAdvisorProgressState>;
|
|
61
63
|
manualProgressSequence: number;
|
package/src/config/defaults.ts
CHANGED
|
@@ -49,6 +49,7 @@ import {
|
|
|
49
49
|
setShowUsageDetailsRef,
|
|
50
50
|
setShowUsageFooterRef,
|
|
51
51
|
setSimpleModeRef,
|
|
52
|
+
setAdvisorToolsEnabledRef,
|
|
52
53
|
} from "./state.ts";
|
|
53
54
|
import type { AdvisorConfig } from "./types.ts";
|
|
54
55
|
import {
|
|
@@ -91,6 +92,7 @@ export const resetDefaults = () => {
|
|
|
91
92
|
setAdvisorModelWhitelistRef([]);
|
|
92
93
|
setAdvisorSessionSummaryRef(false);
|
|
93
94
|
setSimpleModeRef(false);
|
|
95
|
+
setAdvisorToolsEnabledRef(true);
|
|
94
96
|
setAlwaysOnRef(false);
|
|
95
97
|
setAdvisorFailureModeRef("block-session");
|
|
96
98
|
setAdvisorHerdrIntegrationRef(true);
|
|
@@ -214,6 +216,7 @@ export const applyConfig = (config: AdvisorConfig) => {
|
|
|
214
216
|
applyOptionalConfig(config, "showUsageDetails", setShowUsageDetailsRef);
|
|
215
217
|
applyOptionalConfig(config, "showUsageFooter", setShowUsageFooterRef);
|
|
216
218
|
applyOptionalConfig(config, "simpleMode", setSimpleModeRef);
|
|
219
|
+
applyOptionalConfig(config, "advisorToolsEnabled", setAdvisorToolsEnabledRef);
|
|
217
220
|
applyOptionalConfig(config, "alwaysOn", setAlwaysOnRef);
|
|
218
221
|
applyOptionalConfig(config, "gateFailureMode", setAdvisorFailureModeRef);
|
|
219
222
|
applyOptionalConfig(
|
package/src/config/schema.ts
CHANGED
|
@@ -44,6 +44,7 @@ import {
|
|
|
44
44
|
advisorToolResultMaxBytesRef,
|
|
45
45
|
advisorToolResultMaxLinesRef,
|
|
46
46
|
advisorTrackedFileContentRef,
|
|
47
|
+
advisorToolsEnabledRef,
|
|
47
48
|
advisorUntrackedContentRef,
|
|
48
49
|
alwaysOnRef,
|
|
49
50
|
contextMaxCharsRef,
|
|
@@ -434,6 +435,12 @@ export const CONFIG_SCHEMA = {
|
|
|
434
435
|
type: "number",
|
|
435
436
|
validate: isValidToolResultMaxLines,
|
|
436
437
|
},
|
|
438
|
+
advisorToolsEnabled: {
|
|
439
|
+
accepted: "true or false",
|
|
440
|
+
current: () => advisorToolsEnabledRef,
|
|
441
|
+
persisted: true,
|
|
442
|
+
type: "boolean",
|
|
443
|
+
},
|
|
437
444
|
advisorTrackedFileContent: {
|
|
438
445
|
accepted: "true or false",
|
|
439
446
|
current: () => advisorTrackedFileContentRef,
|
package/src/config/state.ts
CHANGED
|
@@ -45,6 +45,7 @@ export let advisorMaxCallsPerSessionRef: number | undefined;
|
|
|
45
45
|
export let advisorModelWhitelistRef: string[] = [];
|
|
46
46
|
export let advisorSessionSummaryRef = false;
|
|
47
47
|
export let simpleModeRef = false;
|
|
48
|
+
export let advisorToolsEnabledRef = true;
|
|
48
49
|
export let alwaysOnRef = false;
|
|
49
50
|
export let advisorFailureModeRef: GateFailureMode = "block-session";
|
|
50
51
|
export let advisorHerdrIntegrationRef = true;
|
|
@@ -155,6 +156,9 @@ export const setAdvisorSessionSummaryRef = (enabled: boolean) => {
|
|
|
155
156
|
export const setSimpleModeRef = (enabled: boolean) => {
|
|
156
157
|
simpleModeRef = enabled;
|
|
157
158
|
};
|
|
159
|
+
export const setAdvisorToolsEnabledRef = (enabled: boolean) => {
|
|
160
|
+
advisorToolsEnabledRef = enabled;
|
|
161
|
+
};
|
|
158
162
|
export const setAlwaysOnRef = (enabled: boolean) => {
|
|
159
163
|
alwaysOnRef = enabled;
|
|
160
164
|
};
|
|
@@ -250,6 +254,7 @@ export const setShowUsageFooterRef = (enabled: boolean) => {
|
|
|
250
254
|
* imported mutable bindings, which can be snapshotted by extension loaders.
|
|
251
255
|
*/
|
|
252
256
|
export const getAdvisorSettings = () => ({
|
|
257
|
+
advisorToolsEnabled: advisorToolsEnabledRef,
|
|
253
258
|
agentsMdContext: advisorAgentsMdContextRef,
|
|
254
259
|
alwaysOn: alwaysOnRef,
|
|
255
260
|
autoLoopGate: advisorAutoLoopGateRef,
|
package/src/config/types.ts
CHANGED
|
@@ -106,6 +106,7 @@ export interface AdvisorConfig {
|
|
|
106
106
|
advisorToolResultMaxBytes?: number;
|
|
107
107
|
advisorToolResultMaxLines?: number;
|
|
108
108
|
advisorTrackedFileContent?: boolean;
|
|
109
|
+
advisorToolsEnabled?: boolean;
|
|
109
110
|
advisorUntrackedContent?: boolean;
|
|
110
111
|
alwaysOn?: boolean;
|
|
111
112
|
contextMaxChars?: number;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
advisorSessionSummaryRef,
|
|
3
|
+
advisorToolsEnabledRef,
|
|
3
4
|
getAdvisorMaxCallsPerSession,
|
|
4
5
|
isSimpleMode,
|
|
5
6
|
} from "../config/state.ts";
|
|
@@ -116,6 +117,16 @@ export const registerToolLifecycle = ({
|
|
|
116
117
|
reason: session.blockedReason ?? "Advisor session is blocked.",
|
|
117
118
|
};
|
|
118
119
|
}
|
|
120
|
+
const isAdvisorTool =
|
|
121
|
+
event.toolName === "ask_advisor" ||
|
|
122
|
+
event.toolName === "record_advisor_outcome";
|
|
123
|
+
if (isAdvisorTool && !advisorToolsEnabledRef) {
|
|
124
|
+
return {
|
|
125
|
+
block: true,
|
|
126
|
+
reason:
|
|
127
|
+
"Advisor tools are disabled. Enable them in /advisor-settings or run /advisor.",
|
|
128
|
+
};
|
|
129
|
+
}
|
|
119
130
|
if (!pi.getActiveTools().includes("ask_advisor")) {
|
|
120
131
|
return;
|
|
121
132
|
}
|
|
@@ -124,6 +135,13 @@ export const registerToolLifecycle = ({
|
|
|
124
135
|
// tool errors; every other tool must proceed without Advisor gating.
|
|
125
136
|
return;
|
|
126
137
|
}
|
|
138
|
+
if (isAdvisorTool && !advisorToolsEnabledRef) {
|
|
139
|
+
return {
|
|
140
|
+
block: true,
|
|
141
|
+
reason:
|
|
142
|
+
"Advisor tools are disabled. Enable them in /advisor-settings or run /advisor.",
|
|
143
|
+
};
|
|
144
|
+
}
|
|
127
145
|
if (sameModelAdvisorDisabled(ctx)) {
|
|
128
146
|
return;
|
|
129
147
|
}
|
package/src/ui/settings-items.ts
CHANGED
|
@@ -348,10 +348,18 @@ export const createSettingsItems = ({
|
|
|
348
348
|
label: "Context window",
|
|
349
349
|
values: presets.map((preset) => preset.label),
|
|
350
350
|
},
|
|
351
|
+
{
|
|
352
|
+
currentValue: settingValue(settings.advisorToolsEnabled, true),
|
|
353
|
+
description:
|
|
354
|
+
"Allow the model to call the Advisor tools; /advisor-off disables them across sessions.",
|
|
355
|
+
id: "advisorToolsEnabled",
|
|
356
|
+
label: "Advisor tools",
|
|
357
|
+
values: TOGGLE_VALUES,
|
|
358
|
+
},
|
|
351
359
|
{
|
|
352
360
|
currentValue: settingValue(settings.simpleMode, false),
|
|
353
361
|
description:
|
|
354
|
-
"Keep
|
|
362
|
+
"Keep enabled Advisor tools available on demand without automatic gates or blocks.",
|
|
355
363
|
id: "simpleMode",
|
|
356
364
|
label: "Simple mode",
|
|
357
365
|
values: TOGGLE_VALUES,
|
|
@@ -35,17 +35,17 @@ const parseModelWhitelist = (value: string) => [
|
|
|
35
35
|
),
|
|
36
36
|
];
|
|
37
37
|
|
|
38
|
-
const
|
|
38
|
+
const applyModeMutation = (
|
|
39
39
|
settings: AdvisorSettings,
|
|
40
40
|
id: string,
|
|
41
|
-
value: string
|
|
42
|
-
presets: ContextPreset[]
|
|
41
|
+
value: string
|
|
43
42
|
): boolean => {
|
|
44
43
|
switch (id) {
|
|
45
|
-
case "
|
|
46
|
-
settings.
|
|
47
|
-
|
|
48
|
-
settings.
|
|
44
|
+
case "advisorToolsEnabled": {
|
|
45
|
+
settings.advisorToolsEnabled = value === "On";
|
|
46
|
+
if (!settings.advisorToolsEnabled) {
|
|
47
|
+
settings.alwaysOn = false;
|
|
48
|
+
}
|
|
49
49
|
return true;
|
|
50
50
|
}
|
|
51
51
|
case "simpleMode": {
|
|
@@ -54,6 +54,28 @@ const applyCoreMutation = (
|
|
|
54
54
|
}
|
|
55
55
|
case "alwaysOn": {
|
|
56
56
|
settings.alwaysOn = value === "On";
|
|
57
|
+
if (settings.alwaysOn) {
|
|
58
|
+
settings.advisorToolsEnabled = true;
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
default: {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const applyCoreMutation = (
|
|
69
|
+
settings: AdvisorSettings,
|
|
70
|
+
id: string,
|
|
71
|
+
value: string,
|
|
72
|
+
presets: ContextPreset[]
|
|
73
|
+
): boolean => {
|
|
74
|
+
switch (id) {
|
|
75
|
+
case "context": {
|
|
76
|
+
settings.contextMaxChars =
|
|
77
|
+
presets.find((preset) => preset.label === value)?.value ??
|
|
78
|
+
settings.contextMaxChars;
|
|
57
79
|
return true;
|
|
58
80
|
}
|
|
59
81
|
case "fallbackModel": {
|
|
@@ -195,6 +217,9 @@ export const mutateAdvisorSettings = (
|
|
|
195
217
|
value: string,
|
|
196
218
|
presets: ContextPreset[]
|
|
197
219
|
): void => {
|
|
220
|
+
if (applyModeMutation(settings, id, value)) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
198
223
|
if (applyCoreMutation(settings, id, value, presets)) {
|
|
199
224
|
return;
|
|
200
225
|
}
|
package/src/ui/types.ts
CHANGED
|
@@ -75,6 +75,7 @@ export interface ContextPreset {
|
|
|
75
75
|
export const FALLBACK_ADVISOR_MODEL_DISABLED = "Disabled (no fallback)";
|
|
76
76
|
|
|
77
77
|
export interface AdvisorSettings {
|
|
78
|
+
advisorToolsEnabled?: boolean;
|
|
78
79
|
agentsMdContext?: boolean;
|
|
79
80
|
fallbackModel?: string;
|
|
80
81
|
alwaysOn?: boolean;
|