pi-advisor-flow 0.16.1-dev.1 → 0.17.0
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 +7 -0
- package/README.md +16 -8
- package/dist/index.js +328 -96
- package/docs/configuration.md +10 -9
- package/locales/de.json +6 -1
- package/locales/en.json +6 -1
- package/locales/fr.json +6 -1
- package/package.json +1 -1
- 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 +70 -13
- 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-command.ts +4 -3
- package/src/commands/manual-consultation.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 +33 -1
- package/src/config/defaults.ts +3 -0
- package/src/config/schema.ts +14 -1
- package/src/config/session-overrides.ts +109 -0
- package/src/config/state.ts +7 -0
- package/src/config/storage.ts +15 -1
- package/src/config/types.ts +3 -0
- package/src/session-state.ts +2 -0
- package/src/tools/budget-feedback.ts +2 -2
- 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 +27 -6
- package/src/ui/settings-mutations.ts +7 -0
- package/src/ui/settings-selector.ts +1 -0
- package/src/ui/types.ts +6 -1
package/dist/index.js
CHANGED
|
@@ -64,6 +64,7 @@ var advisorSessionSummaryRef = false;
|
|
|
64
64
|
var advisorLogFeedbackRef = false;
|
|
65
65
|
var simpleModeRef = false;
|
|
66
66
|
var advisorToolsEnabledRef = true;
|
|
67
|
+
var advisorActivationRef = "persistent";
|
|
67
68
|
var alwaysOnRef = false;
|
|
68
69
|
var advisorFailureModeRef = "block-session";
|
|
69
70
|
var advisorHerdrIntegrationRef = true;
|
|
@@ -174,6 +175,9 @@ var setSimpleModeRef = (enabled) => {
|
|
|
174
175
|
var setAdvisorToolsEnabledRef = (enabled) => {
|
|
175
176
|
advisorToolsEnabledRef = enabled;
|
|
176
177
|
};
|
|
178
|
+
var setAdvisorActivationRef = (activation) => {
|
|
179
|
+
advisorActivationRef = activation;
|
|
180
|
+
};
|
|
177
181
|
var setAlwaysOnRef = (enabled) => {
|
|
178
182
|
alwaysOnRef = enabled;
|
|
179
183
|
};
|
|
@@ -267,6 +271,7 @@ var setShowUsageFooterRef = (enabled) => {
|
|
|
267
271
|
showUsageFooterRef = enabled;
|
|
268
272
|
};
|
|
269
273
|
var getAdvisorSettings = () => ({
|
|
274
|
+
advisorActivation: advisorActivationRef,
|
|
270
275
|
advisorToolsEnabled: advisorToolsEnabledRef,
|
|
271
276
|
agentsMdContext: advisorAgentsMdContextRef,
|
|
272
277
|
alwaysOn: alwaysOnRef,
|
|
@@ -556,6 +561,13 @@ var CONFIG_SCHEMA = {
|
|
|
556
561
|
persisted: true,
|
|
557
562
|
type: "string"
|
|
558
563
|
},
|
|
564
|
+
advisorActivation: {
|
|
565
|
+
accepted: "persistent or session",
|
|
566
|
+
current: () => advisorActivationRef,
|
|
567
|
+
persisted: true,
|
|
568
|
+
type: "enum",
|
|
569
|
+
validate: (value) => value === "persistent" || value === "session"
|
|
570
|
+
},
|
|
559
571
|
advisorAgentsMdContext: {
|
|
560
572
|
accepted: "true or false",
|
|
561
573
|
current: () => advisorAgentsMdContextRef,
|
|
@@ -957,6 +969,70 @@ var parseArgs = (args) => {
|
|
|
957
969
|
setContextMaxCharsRef(nextContextMaxChars);
|
|
958
970
|
};
|
|
959
971
|
|
|
972
|
+
// src/config/session-overrides.ts
|
|
973
|
+
var SESSION_ACTIVATION_KEYS = [
|
|
974
|
+
"advisor",
|
|
975
|
+
"advisorEffort",
|
|
976
|
+
"advisorFallbackModel",
|
|
977
|
+
"contextMaxChars",
|
|
978
|
+
"executor",
|
|
979
|
+
"executorEffort"
|
|
980
|
+
];
|
|
981
|
+
var overrides = new WeakMap;
|
|
982
|
+
var sessionKey = (ctx) => ctx.sessionManager ?? ctx;
|
|
983
|
+
var getSessionActivationOverrides = (ctx) => overrides.get(sessionKey(ctx));
|
|
984
|
+
var applySessionActivationOverrides = (ctx) => {
|
|
985
|
+
const values = getSessionActivationOverrides(ctx);
|
|
986
|
+
if (!values) {
|
|
987
|
+
return;
|
|
988
|
+
}
|
|
989
|
+
if (Object.hasOwn(values, "advisor")) {
|
|
990
|
+
setAdvisorRef(values.advisor ?? "");
|
|
991
|
+
}
|
|
992
|
+
if (Object.hasOwn(values, "advisorEffort")) {
|
|
993
|
+
setAdvisorEffortRef(values.advisorEffort);
|
|
994
|
+
}
|
|
995
|
+
if (Object.hasOwn(values, "advisorFallbackModel")) {
|
|
996
|
+
setAdvisorFallbackModelRef(values.advisorFallbackModel);
|
|
997
|
+
}
|
|
998
|
+
if (values.contextMaxChars !== undefined) {
|
|
999
|
+
setContextMaxCharsRef(values.contextMaxChars);
|
|
1000
|
+
}
|
|
1001
|
+
if (Object.hasOwn(values, "executor")) {
|
|
1002
|
+
setExecutorRef(values.executor ?? "");
|
|
1003
|
+
}
|
|
1004
|
+
if (Object.hasOwn(values, "executorEffort")) {
|
|
1005
|
+
setExecutorEffortRef(values.executorEffort);
|
|
1006
|
+
}
|
|
1007
|
+
};
|
|
1008
|
+
var rememberSessionActivationOverrides = (ctx, previous, current) => {
|
|
1009
|
+
const next = { ...getSessionActivationOverrides(ctx) };
|
|
1010
|
+
for (const key of SESSION_ACTIVATION_KEYS) {
|
|
1011
|
+
if (previous[key] !== current[key]) {
|
|
1012
|
+
Object.assign(next, { [key]: current[key] });
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
if (Object.keys(next).length > 0) {
|
|
1016
|
+
overrides.set(sessionKey(ctx), next);
|
|
1017
|
+
}
|
|
1018
|
+
};
|
|
1019
|
+
var clearSessionActivationOverrides = (ctx, keys = SESSION_ACTIVATION_KEYS) => {
|
|
1020
|
+
const key = sessionKey(ctx);
|
|
1021
|
+
const existing = overrides.get(key);
|
|
1022
|
+
if (!existing) {
|
|
1023
|
+
return;
|
|
1024
|
+
}
|
|
1025
|
+
const remaining = { ...existing };
|
|
1026
|
+
for (const name of keys) {
|
|
1027
|
+
Reflect.deleteProperty(remaining, name);
|
|
1028
|
+
}
|
|
1029
|
+
if (Object.keys(remaining).length === 0) {
|
|
1030
|
+
overrides.delete(key);
|
|
1031
|
+
} else {
|
|
1032
|
+
overrides.set(key, remaining);
|
|
1033
|
+
}
|
|
1034
|
+
};
|
|
1035
|
+
|
|
960
1036
|
// src/config/storage.ts
|
|
961
1037
|
import { randomUUID } from "node:crypto";
|
|
962
1038
|
import {
|
|
@@ -1008,6 +1084,7 @@ var resetDefaults = () => {
|
|
|
1008
1084
|
setAdvisorSessionSummaryRef(false);
|
|
1009
1085
|
setAdvisorLogFeedbackRef(false);
|
|
1010
1086
|
setSimpleModeRef(false);
|
|
1087
|
+
setAdvisorActivationRef("persistent");
|
|
1011
1088
|
setAdvisorToolsEnabledRef(true);
|
|
1012
1089
|
setAlwaysOnRef(false);
|
|
1013
1090
|
setAdvisorFailureModeRef("block-session");
|
|
@@ -1077,6 +1154,7 @@ var applyConfig = (config) => {
|
|
|
1077
1154
|
applyOptionalConfig(config, "showUsageDetails", setShowUsageDetailsRef);
|
|
1078
1155
|
applyOptionalConfig(config, "showUsageFooter", setShowUsageFooterRef);
|
|
1079
1156
|
applyOptionalConfig(config, "simpleMode", setSimpleModeRef);
|
|
1157
|
+
applyOptionalConfig(config, "advisorActivation", setAdvisorActivationRef);
|
|
1080
1158
|
applyOptionalConfig(config, "advisorToolsEnabled", setAdvisorToolsEnabledRef);
|
|
1081
1159
|
applyOptionalConfig(config, "alwaysOn", setAlwaysOnRef);
|
|
1082
1160
|
applyOptionalConfig(config, "gateFailureMode", setAdvisorFailureModeRef);
|
|
@@ -1209,6 +1287,11 @@ var loadConfig = (_ctx) => {
|
|
|
1209
1287
|
warnedUnknownConfigIdentities.add(warningIdentity);
|
|
1210
1288
|
}
|
|
1211
1289
|
}
|
|
1290
|
+
if (advisorActivationRef === "session") {
|
|
1291
|
+
applySessionActivationOverrides(_ctx);
|
|
1292
|
+
} else {
|
|
1293
|
+
clearSessionActivationOverrides(_ctx);
|
|
1294
|
+
}
|
|
1212
1295
|
setAdvisorOutcomeLoggingRef(globalConfig?.advisorOutcomeLogging === true);
|
|
1213
1296
|
loadedConfigState = currentConfigState();
|
|
1214
1297
|
loadedConfigPath = global;
|
|
@@ -1224,7 +1307,8 @@ var saveConfig = (_ctx, options = {}) => {
|
|
|
1224
1307
|
const persistExecutor = options.persistExecutor ?? true;
|
|
1225
1308
|
const current = currentConfigState();
|
|
1226
1309
|
const baseline = loadedConfigPath === path ? loadedConfigState : undefined;
|
|
1227
|
-
const
|
|
1310
|
+
const forcedKeys = new Set(options.forceKeys);
|
|
1311
|
+
const changedKeys = baseline ? SAVED_CONFIG_KEYS.filter((key) => forcedKeys.has(key) || !sameConfigValue(current[key], baseline[key])) : [...SAVED_CONFIG_KEYS];
|
|
1228
1312
|
if (changedKeys.length === 0) {
|
|
1229
1313
|
return path;
|
|
1230
1314
|
}
|
|
@@ -1676,8 +1760,10 @@ var FALLBACK_ADVISOR_MODEL_DISABLED = "Disabled (no fallback)";
|
|
|
1676
1760
|
var EXECUTOR_FOLLOWS_SESSION_MODEL = "Current session model (no override)";
|
|
1677
1761
|
|
|
1678
1762
|
// src/commands/model-picker.ts
|
|
1763
|
+
var isCurrentChoice = (choice, canContinue) => Boolean(choice) && canContinue();
|
|
1679
1764
|
var selectAdvisorModels = async (ctx, options) => {
|
|
1680
|
-
|
|
1765
|
+
const canContinue = () => options.canContinue?.() ?? true;
|
|
1766
|
+
if (!canContinue() || !ctx.hasUI) {
|
|
1681
1767
|
return;
|
|
1682
1768
|
}
|
|
1683
1769
|
const refs = getAvailableModelRefs(ctx);
|
|
@@ -1706,11 +1792,11 @@ var selectAdvisorModels = async (ctx, options) => {
|
|
|
1706
1792
|
title: t("modelPicker.selectExecutor", "Select Executor Model"),
|
|
1707
1793
|
tui
|
|
1708
1794
|
}));
|
|
1709
|
-
if (!selectedExecutor) {
|
|
1795
|
+
if (!isCurrentChoice(selectedExecutor, canContinue)) {
|
|
1710
1796
|
return;
|
|
1711
1797
|
}
|
|
1712
1798
|
const selectedExecutorEffort = await ctx.ui.select(t("modelPicker.executorEffort", "Select Executor Reasoning/Thinking Level"), effortChoices(executorEffort));
|
|
1713
|
-
if (!selectedExecutorEffort) {
|
|
1799
|
+
if (!isCurrentChoice(selectedExecutorEffort, canContinue)) {
|
|
1714
1800
|
return;
|
|
1715
1801
|
}
|
|
1716
1802
|
executor = selectedExecutor === EXECUTOR_FOLLOWS_SESSION_MODEL ? "" : selectedExecutor;
|
|
@@ -1727,11 +1813,11 @@ var selectAdvisorModels = async (ctx, options) => {
|
|
|
1727
1813
|
title: t("modelPicker.selectAdvisor", "Select Advisor Model"),
|
|
1728
1814
|
tui
|
|
1729
1815
|
}));
|
|
1730
|
-
if (!selectedAdvisor) {
|
|
1816
|
+
if (!isCurrentChoice(selectedAdvisor, canContinue)) {
|
|
1731
1817
|
return;
|
|
1732
1818
|
}
|
|
1733
1819
|
const selectedAdvisorEffort = await ctx.ui.select(t("modelPicker.advisorEffort", "Select Advisor Reasoning/Thinking Level"), effortChoices(advisorEffort));
|
|
1734
|
-
if (!selectedAdvisorEffort) {
|
|
1820
|
+
if (!isCurrentChoice(selectedAdvisorEffort, canContinue)) {
|
|
1735
1821
|
return;
|
|
1736
1822
|
}
|
|
1737
1823
|
advisor = selectedAdvisor;
|
|
@@ -1753,7 +1839,7 @@ var selectAdvisorModels = async (ctx, options) => {
|
|
|
1753
1839
|
title: t("modelPicker.selectFallbackAdvisor", "Select Fallback Advisor Model (optional)"),
|
|
1754
1840
|
tui
|
|
1755
1841
|
}));
|
|
1756
|
-
if (selectedFallback === undefined) {
|
|
1842
|
+
if (selectedFallback === undefined || !canContinue()) {
|
|
1757
1843
|
return;
|
|
1758
1844
|
}
|
|
1759
1845
|
advisorFallbackModel = selectedFallback === FALLBACK_ADVISOR_MODEL_DISABLED ? undefined : selectedFallback;
|
|
@@ -5241,10 +5327,12 @@ class AdvisorSessionState {
|
|
|
5241
5327
|
#followUps;
|
|
5242
5328
|
#sessionTurnOrdinal = 0;
|
|
5243
5329
|
#turnsSinceConsultation = 0;
|
|
5330
|
+
sessionToolsEnabled = false;
|
|
5244
5331
|
constructor(now) {
|
|
5245
5332
|
this.#followUps = new AdvisorFollowUpCache(now);
|
|
5246
5333
|
}
|
|
5247
5334
|
resetTask() {
|
|
5335
|
+
this.sessionToolsEnabled = false;
|
|
5248
5336
|
this.#repetition = freshRepetition();
|
|
5249
5337
|
this.#blockedReason = undefined;
|
|
5250
5338
|
this.#ledger = freshAdviceLedger();
|
|
@@ -5600,8 +5688,13 @@ var loadCommandConfig = (ctx) => {
|
|
|
5600
5688
|
return false;
|
|
5601
5689
|
}
|
|
5602
5690
|
};
|
|
5603
|
-
var prepareActivationModels = async (runtime, ctx, announce, executorOverride, advisorOverride) => {
|
|
5604
|
-
const
|
|
5691
|
+
var prepareActivationModels = async (runtime, ctx, announce, executorOverride, advisorOverride, canContinue) => {
|
|
5692
|
+
const saved = getPersistedModelRefs();
|
|
5693
|
+
const overrides = advisorActivationRef === "session" ? getSessionActivationOverrides(ctx) : undefined;
|
|
5694
|
+
const persisted = {
|
|
5695
|
+
advisor: overrides && Object.hasOwn(overrides, "advisor") ? advisorRef || undefined : saved.advisor,
|
|
5696
|
+
executor: overrides && Object.hasOwn(overrides, "executor") ? executorRef || undefined : saved.executor
|
|
5697
|
+
};
|
|
5605
5698
|
const availableRefs = getAvailableModelRefs(ctx);
|
|
5606
5699
|
const availableRefSet = availableRefs ? new Set(availableRefs) : undefined;
|
|
5607
5700
|
const explicitError = getExplicitModelError(ctx, executorRef, "Executor", executorOverride, availableRefSet) ?? getExplicitModelError(ctx, advisorRef, "Advisor", advisorOverride, availableRefSet);
|
|
@@ -5618,6 +5711,7 @@ var prepareActivationModels = async (runtime, ctx, announce, executorOverride, a
|
|
|
5618
5711
|
return;
|
|
5619
5712
|
}
|
|
5620
5713
|
const selection = await selectAdvisorModels(ctx, {
|
|
5714
|
+
canContinue,
|
|
5621
5715
|
advisor: advisorOverride || persisted.advisor ? advisorRef : "",
|
|
5622
5716
|
advisorEffort: advisorEffortRef,
|
|
5623
5717
|
advisorFallbackModel: advisorFallbackModelRef,
|
|
@@ -5625,8 +5719,13 @@ var prepareActivationModels = async (runtime, ctx, announce, executorOverride, a
|
|
|
5625
5719
|
executorEffort: executorEffortRef,
|
|
5626
5720
|
selectAdvisor: plan.selectAdvisor,
|
|
5627
5721
|
selectExecutor: plan.selectExecutor
|
|
5722
|
+
}).catch((error) => {
|
|
5723
|
+
if (!canContinue()) {
|
|
5724
|
+
return;
|
|
5725
|
+
}
|
|
5726
|
+
throw error;
|
|
5628
5727
|
});
|
|
5629
|
-
if (!selection) {
|
|
5728
|
+
if (!selection || !canContinue()) {
|
|
5630
5729
|
return;
|
|
5631
5730
|
}
|
|
5632
5731
|
setAdvisorRef(selection.advisor);
|
|
@@ -5639,11 +5738,16 @@ var prepareActivationModels = async (runtime, ctx, announce, executorOverride, a
|
|
|
5639
5738
|
|
|
5640
5739
|
// src/commands/advisor-tools.ts
|
|
5641
5740
|
var ADVISOR_TOOL_NAMES = new Set(["ask_advisor", "record_advisor_outcome"]);
|
|
5642
|
-
var
|
|
5741
|
+
var ALL_ADVISOR_TOOL_NAMES = new Set([
|
|
5742
|
+
...ADVISOR_TOOL_NAMES,
|
|
5743
|
+
"advisor_config"
|
|
5744
|
+
]);
|
|
5745
|
+
var CONFIGURATION_TOOL_NAME = new Set(["advisor_config"]);
|
|
5746
|
+
var setToolsActive = (pi, enabled, names) => {
|
|
5643
5747
|
const current = pi.getActiveTools();
|
|
5644
|
-
const next = current.filter((name) => enabled || !
|
|
5748
|
+
const next = current.filter((name) => enabled || !names.has(name));
|
|
5645
5749
|
if (enabled) {
|
|
5646
|
-
for (const name of
|
|
5750
|
+
for (const name of names) {
|
|
5647
5751
|
if (!next.includes(name)) {
|
|
5648
5752
|
next.push(name);
|
|
5649
5753
|
}
|
|
@@ -5653,6 +5757,8 @@ var setAdvisorToolsActive = (pi, enabled) => {
|
|
|
5653
5757
|
pi.setActiveTools(next);
|
|
5654
5758
|
}
|
|
5655
5759
|
};
|
|
5760
|
+
var setAdvisorToolsActive = (pi, enabled, includeConfiguration = false) => setToolsActive(pi, enabled, includeConfiguration ? ALL_ADVISOR_TOOL_NAMES : ADVISOR_TOOL_NAMES);
|
|
5761
|
+
var enableAdvisorConfigurationTool = (pi) => setToolsActive(pi, true, CONFIGURATION_TOOL_NAME);
|
|
5656
5762
|
|
|
5657
5763
|
// src/commands/activation.ts
|
|
5658
5764
|
var resolveActivationModels = async (runtime, ctx, canContinue) => {
|
|
@@ -5697,10 +5803,31 @@ var restoreActivationRefsIfCurrent = (canContinue, restoreRefs) => {
|
|
|
5697
5803
|
var liveRefSnapshot = () => ({
|
|
5698
5804
|
advisor: advisorRef,
|
|
5699
5805
|
advisorEffort: advisorEffortRef,
|
|
5806
|
+
advisorFallbackModel: advisorFallbackModelRef,
|
|
5700
5807
|
contextMaxChars: contextMaxCharsRef,
|
|
5701
5808
|
executor: executorRef,
|
|
5702
5809
|
executorEffort: executorEffortRef
|
|
5703
5810
|
});
|
|
5811
|
+
var restoreActivationRefs = (previous, attempted) => {
|
|
5812
|
+
if (advisorRef === attempted.advisor) {
|
|
5813
|
+
setAdvisorRef(previous.advisor);
|
|
5814
|
+
}
|
|
5815
|
+
if (advisorEffortRef === attempted.advisorEffort) {
|
|
5816
|
+
setAdvisorEffortRef(previous.advisorEffort);
|
|
5817
|
+
}
|
|
5818
|
+
if (advisorFallbackModelRef === attempted.advisorFallbackModel) {
|
|
5819
|
+
setAdvisorFallbackModelRef(previous.advisorFallbackModel);
|
|
5820
|
+
}
|
|
5821
|
+
if (contextMaxCharsRef === attempted.contextMaxChars) {
|
|
5822
|
+
setContextMaxCharsRef(previous.contextMaxChars);
|
|
5823
|
+
}
|
|
5824
|
+
if (executorRef === attempted.executor) {
|
|
5825
|
+
setExecutorRef(previous.executor);
|
|
5826
|
+
}
|
|
5827
|
+
if (executorEffortRef === attempted.executorEffort) {
|
|
5828
|
+
setExecutorEffortRef(previous.executorEffort);
|
|
5829
|
+
}
|
|
5830
|
+
};
|
|
5704
5831
|
var persistSuccessfulActivation = (ctx, shouldSave, reenableTools, restoreRefs) => {
|
|
5705
5832
|
if (!shouldSave) {
|
|
5706
5833
|
return true;
|
|
@@ -5719,37 +5846,21 @@ var persistSuccessfulActivation = (ctx, shouldSave, reenableTools, restoreRefs)
|
|
|
5719
5846
|
}
|
|
5720
5847
|
return true;
|
|
5721
5848
|
};
|
|
5849
|
+
var announceActivation = (ctx, activeModel) => {
|
|
5850
|
+
const activeExecutorRef = effectiveExecutorRef(ctx);
|
|
5851
|
+
const activeExecutorEffort = effectiveExecutorEffort(ctx);
|
|
5852
|
+
notify(ctx, `${t("activation.explanation", "The Advisor is a second-opinion model that reviews the Executor's context and returns risks, alternatives, and verification steps without changing files or running tools.")}
|
|
5853
|
+
|
|
5854
|
+
${t("activation.flow", "Advisor flow")} ${sameModelAdvisorDisabled(ctx, activeModel) ? t("activation.flowConfigured", "configured") : t("activation.flowReady", "ready")} — Executor: ${activeExecutorRef} (thinking: ${activeExecutorEffort || "default"}) · Advisor: ${advisorRef} (thinking: ${advisorEffortRef || "default"})`, "info");
|
|
5855
|
+
};
|
|
5722
5856
|
var activateAdvisor = async (runtime, args, ctx, announce = true) => {
|
|
5723
5857
|
if (!loadCommandConfig(ctx)) {
|
|
5724
5858
|
return;
|
|
5725
5859
|
}
|
|
5726
5860
|
const { toolAvailabilityRevision } = runtime;
|
|
5727
5861
|
const canContinue = () => runtime.toolAvailabilityRevision === toolAvailabilityRevision;
|
|
5728
|
-
const previous =
|
|
5729
|
-
|
|
5730
|
-
advisorEffort: advisorEffortRef,
|
|
5731
|
-
contextMaxChars: contextMaxCharsRef,
|
|
5732
|
-
executor: executorRef,
|
|
5733
|
-
executorEffort: executorEffortRef
|
|
5734
|
-
};
|
|
5735
|
-
const liveSnapshot = liveRefSnapshot;
|
|
5736
|
-
const restoreRefs = (attempted) => {
|
|
5737
|
-
if (advisorRef === attempted.advisor) {
|
|
5738
|
-
setAdvisorRef(previous.advisor);
|
|
5739
|
-
}
|
|
5740
|
-
if (advisorEffortRef === attempted.advisorEffort) {
|
|
5741
|
-
setAdvisorEffortRef(previous.advisorEffort);
|
|
5742
|
-
}
|
|
5743
|
-
if (contextMaxCharsRef === attempted.contextMaxChars) {
|
|
5744
|
-
setContextMaxCharsRef(previous.contextMaxChars);
|
|
5745
|
-
}
|
|
5746
|
-
if (executorRef === attempted.executor) {
|
|
5747
|
-
setExecutorRef(previous.executor);
|
|
5748
|
-
}
|
|
5749
|
-
if (executorEffortRef === attempted.executorEffort) {
|
|
5750
|
-
setExecutorEffortRef(previous.executorEffort);
|
|
5751
|
-
}
|
|
5752
|
-
};
|
|
5862
|
+
const previous = liveRefSnapshot();
|
|
5863
|
+
const restoreRefs = (attempted) => restoreActivationRefs(previous, attempted);
|
|
5753
5864
|
let attempted = liveRefSnapshot();
|
|
5754
5865
|
const executorOverride = hasExecutorOverride(args);
|
|
5755
5866
|
const advisorOverride = hasAdvisorOverride(args);
|
|
@@ -5760,7 +5871,7 @@ var activateAdvisor = async (runtime, args, ctx, announce = true) => {
|
|
|
5760
5871
|
notify(ctx, argumentError, "error");
|
|
5761
5872
|
return;
|
|
5762
5873
|
}
|
|
5763
|
-
const prepared = await prepareActivationModels(runtime, ctx, announce, executorOverride, advisorOverride);
|
|
5874
|
+
const prepared = await prepareActivationModels(runtime, ctx, announce, executorOverride, advisorOverride, canContinue);
|
|
5764
5875
|
if (!prepared) {
|
|
5765
5876
|
attempted = liveRefSnapshot();
|
|
5766
5877
|
restoreActivationRefsIfCurrent(canContinue, () => restoreRefs(attempted));
|
|
@@ -5775,26 +5886,28 @@ var activateAdvisor = async (runtime, args, ctx, announce = true) => {
|
|
|
5775
5886
|
notify(ctx, error, "error");
|
|
5776
5887
|
return;
|
|
5777
5888
|
}
|
|
5778
|
-
const
|
|
5889
|
+
const sessionScoped = advisorActivationRef === "session";
|
|
5890
|
+
const reenableTools = !sessionScoped && !advisorToolsEnabledRef;
|
|
5779
5891
|
if (reenableTools) {
|
|
5780
5892
|
setAdvisorToolsEnabledRef(true);
|
|
5781
5893
|
}
|
|
5782
|
-
const shouldSave = Boolean(args.trim() || prepared.pickedModels || reenableTools);
|
|
5894
|
+
const shouldSave = !sessionScoped && Boolean(args.trim() || prepared.pickedModels || reenableTools);
|
|
5783
5895
|
if (!persistSuccessfulActivation(ctx, shouldSave, reenableTools, () => restoreRefs(liveRefSnapshot()))) {
|
|
5784
5896
|
return;
|
|
5785
5897
|
}
|
|
5786
5898
|
if (executorEffortRef && !isMarkedSubagent()) {
|
|
5787
5899
|
runtime.pi.setThinkingLevel(executorEffortRef);
|
|
5788
5900
|
}
|
|
5789
|
-
|
|
5901
|
+
if (sessionScoped) {
|
|
5902
|
+
rememberSessionActivationOverrides(ctx, previous, liveRefSnapshot());
|
|
5903
|
+
rebaseConfigBaseline();
|
|
5904
|
+
runtime.advisorSessionState.sessionToolsEnabled = true;
|
|
5905
|
+
}
|
|
5906
|
+
setAdvisorToolsActive(runtime.pi, true, sessionScoped);
|
|
5790
5907
|
const activeModel = followsSessionExecutor() ? ctx.model : findConfiguredModel(ctx, executorRef);
|
|
5791
5908
|
runtime.updateSameModelNotice(ctx, activeModel);
|
|
5792
5909
|
if (announce) {
|
|
5793
|
-
|
|
5794
|
-
const activeExecutorEffort = effectiveExecutorEffort(ctx);
|
|
5795
|
-
notify(ctx, `${t("activation.explanation", "The Advisor is a second-opinion model that reviews the Executor's context and returns risks, alternatives, and verification steps without changing files or running tools.")}
|
|
5796
|
-
|
|
5797
|
-
${t("activation.flow", "Advisor flow")} ${sameModelAdvisorDisabled(ctx, activeModel) ? t("activation.flowConfigured", "configured") : t("activation.flowReady", "ready")} — Executor: ${activeExecutorRef} (thinking: ${activeExecutorEffort || "default"}) · Advisor: ${advisorRef} (thinking: ${advisorEffortRef || "default"})`, "info");
|
|
5910
|
+
announceActivation(ctx, activeModel);
|
|
5798
5911
|
}
|
|
5799
5912
|
};
|
|
5800
5913
|
|
|
@@ -5937,16 +6050,42 @@ var summarizeAdvisorConfigPatch = (changes, before, persisted) => configKeys.fil
|
|
|
5937
6050
|
return `- ${key}: ${previous} → ${next}`;
|
|
5938
6051
|
}).join(`
|
|
5939
6052
|
`);
|
|
5940
|
-
var
|
|
6053
|
+
var enabledToolsRiskNote = (sessionScoped, alwaysOn, enabledByAlwaysOn) => {
|
|
6054
|
+
if (sessionScoped && enabledByAlwaysOn) {
|
|
6055
|
+
return "The saved tool preference changes; enabling Always on does not activate this session.";
|
|
6056
|
+
}
|
|
6057
|
+
if (sessionScoped) {
|
|
6058
|
+
return "Advisor tools become available in this session; later session starts remain inactive.";
|
|
6059
|
+
}
|
|
6060
|
+
if (alwaysOn) {
|
|
6061
|
+
return "Advisor tools become available, and saved Always on will activate the flow in future sessions.";
|
|
6062
|
+
}
|
|
6063
|
+
return "Advisor tools become available; this does not activate Always on.";
|
|
6064
|
+
};
|
|
6065
|
+
var activationRiskNotes = (changes, before) => {
|
|
5941
6066
|
const notes = [];
|
|
5942
|
-
|
|
5943
|
-
|
|
6067
|
+
const sessionScoped = changes.advisorActivation === "session" || changes.advisorActivation === undefined && before.advisorActivation === "session";
|
|
6068
|
+
if (changes.advisorActivation === "session") {
|
|
6069
|
+
notes.push("The current Advisor on/off state is kept; advisor_config follows it. Every session start, including /reload, starts inactive even when Always on is saved.");
|
|
6070
|
+
}
|
|
6071
|
+
if (changes.advisorActivation === "persistent" || changes.advisorActivation === null) {
|
|
6072
|
+
notes.push("Persistent mode applies the saved Advisor tools preference immediately and makes advisor_config available.");
|
|
5944
6073
|
}
|
|
5945
6074
|
if (changes.advisorToolsEnabled === false) {
|
|
5946
|
-
notes.push("Advisor tools will be disabled immediately. advisor_config remains available to re-enable them.");
|
|
6075
|
+
notes.push(sessionScoped ? "Advisor tools, including advisor_config, will be disabled immediately; use /advisor to enable them for this session." : "Advisor tools will be disabled immediately. advisor_config remains available to re-enable them.");
|
|
5947
6076
|
}
|
|
5948
6077
|
if (changes.alwaysOn === true) {
|
|
5949
|
-
notes.push("Always on enables automatic activation for future sessions.");
|
|
6078
|
+
notes.push(sessionScoped ? "Always on is saved, but session activation starts inactive." : "Always on enables automatic activation for future sessions.");
|
|
6079
|
+
}
|
|
6080
|
+
if (changes.advisorToolsEnabled === true) {
|
|
6081
|
+
notes.push(enabledToolsRiskNote(sessionScoped, before.alwaysOn === true || changes.alwaysOn === true, changes.alwaysOn === true && before.advisorToolsEnabled === false));
|
|
6082
|
+
}
|
|
6083
|
+
return notes;
|
|
6084
|
+
};
|
|
6085
|
+
var automationRiskNotes = (changes, before) => {
|
|
6086
|
+
const notes = activationRiskNotes(changes, before);
|
|
6087
|
+
if (changes.simpleMode === true) {
|
|
6088
|
+
notes.push("Simple mode disables automatic gates, gate blocking, and configured call budgets; voluntary Advisor calls remain available.");
|
|
5950
6089
|
}
|
|
5951
6090
|
if (changes.advisorPlanGate === true || changes.advisorFailureGate === true || changes.advisorCompletionGate === true || changes.advisorAutoLoopGate === true) {
|
|
5952
6091
|
notes.push("Automatic gates may request extra Advisor calls; loop-gate failures can block a tool or session under the selected failure policy.");
|
|
@@ -5954,9 +6093,6 @@ var automationRiskNotes = (changes, before) => {
|
|
|
5954
6093
|
if (changes.gateFailureMode === "block-session" || changes.advisorBlockOnBlocked === true) {
|
|
5955
6094
|
notes.push("A blocked gate may stop the current session.");
|
|
5956
6095
|
}
|
|
5957
|
-
if (changes.advisorToolsEnabled === true) {
|
|
5958
|
-
notes.push(before.alwaysOn === true || changes.alwaysOn === true ? "Advisor tools become available, and saved Always on will activate the flow in future sessions." : "Advisor tools become available; this does not activate Always on.");
|
|
5959
|
-
}
|
|
5960
6096
|
return notes;
|
|
5961
6097
|
};
|
|
5962
6098
|
var disclosureRiskNotes = (changes) => {
|
|
@@ -6074,21 +6210,45 @@ var resolveModelChanges = async (ctx, changes, before, persisted, selectModels =
|
|
|
6074
6210
|
return selectedModelChanges(changes, selection, persisted);
|
|
6075
6211
|
};
|
|
6076
6212
|
|
|
6077
|
-
// src/commands/
|
|
6078
|
-
var
|
|
6213
|
+
// src/commands/activation-settings.ts
|
|
6214
|
+
var reconcileAdvisorToolsAfterSettings = (runtime, ctx, previous, refreshPersistentTools = true) => {
|
|
6079
6215
|
const next = getAdvisorSettings();
|
|
6080
|
-
const
|
|
6081
|
-
const
|
|
6082
|
-
|
|
6216
|
+
const modeChanged = previous.advisorActivation !== next.advisorActivation;
|
|
6217
|
+
const preferenceChanged = previous.advisorToolsEnabled !== next.advisorToolsEnabled;
|
|
6218
|
+
const sessionScoped = next.advisorActivation === "session";
|
|
6219
|
+
const enabledByAlwaysOn = !previous.alwaysOn && next.alwaysOn && !previous.advisorToolsEnabled && next.advisorToolsEnabled;
|
|
6220
|
+
const persistentOutOfSync = !sessionScoped && runtime.flowEnabled() !== next.advisorToolsEnabled;
|
|
6221
|
+
if (modeChanged || preferenceChanged || !refreshPersistentTools && persistentOutOfSync) {
|
|
6083
6222
|
runtime.noteAdvisorToolsStateChange();
|
|
6084
|
-
|
|
6085
|
-
|
|
6086
|
-
|
|
6223
|
+
}
|
|
6224
|
+
let enabled = next.advisorToolsEnabled;
|
|
6225
|
+
if (sessionScoped) {
|
|
6226
|
+
if (modeChanged) {
|
|
6227
|
+
runtime.advisorSessionState.sessionToolsEnabled = runtime.flowEnabled();
|
|
6228
|
+
} else if (preferenceChanged && !enabledByAlwaysOn) {
|
|
6229
|
+
runtime.advisorSessionState.sessionToolsEnabled = enabled;
|
|
6087
6230
|
}
|
|
6231
|
+
enabled = runtime.advisorSessionState.sessionToolsEnabled;
|
|
6232
|
+
setAdvisorToolsActive(runtime.pi, enabled, true);
|
|
6233
|
+
} else {
|
|
6234
|
+
if (modeChanged) {
|
|
6235
|
+
enableAdvisorConfigurationTool(runtime.pi);
|
|
6236
|
+
}
|
|
6237
|
+
if (refreshPersistentTools || modeChanged || preferenceChanged || persistentOutOfSync) {
|
|
6238
|
+
setAdvisorToolsActive(runtime.pi, enabled);
|
|
6239
|
+
}
|
|
6240
|
+
}
|
|
6241
|
+
if (!enabled) {
|
|
6242
|
+
runtime.resetSameModelNotice();
|
|
6088
6243
|
}
|
|
6089
6244
|
runtime.updateSameModelNotice(ctx);
|
|
6090
6245
|
runtime.updateAdvisorUsageStatus(ctx);
|
|
6091
6246
|
};
|
|
6247
|
+
|
|
6248
|
+
// src/commands/configuration-tool-runtime.ts
|
|
6249
|
+
var applyAdvisorConfigRuntimeSettings = (runtime, ctx, previous) => {
|
|
6250
|
+
reconcileAdvisorToolsAfterSettings(runtime, ctx, previous, false);
|
|
6251
|
+
};
|
|
6092
6252
|
var cancelledAdvisorConfigResult = (message) => ({
|
|
6093
6253
|
content: [{ text: message, type: "text" }],
|
|
6094
6254
|
details: { action: "update", applied: false, cancelled: true }
|
|
@@ -6171,8 +6331,9 @@ var prepareAdvisorConfigUpdate = async (ctx, input, selectModels) => {
|
|
|
6171
6331
|
};
|
|
6172
6332
|
var appliedAdvisorConfigResult = (prepared, savedPath) => {
|
|
6173
6333
|
const notices = [];
|
|
6334
|
+
const sessionScoped = prepared.proposed.advisorActivation === "session" || prepared.proposed.advisorActivation === undefined && prepared.beforeSettings.advisorActivation === "session";
|
|
6174
6335
|
if (Object.hasOwn(prepared.proposed, "alwaysOn") && prepared.proposed.alwaysOn === true) {
|
|
6175
|
-
notices.push("Always on applies to future sessions; this did not start an Advisor call.");
|
|
6336
|
+
notices.push(sessionScoped ? "Always on is saved but session activation starts inactive; this did not start an Advisor call." : "Always on applies to future sessions; this did not start an Advisor call.");
|
|
6176
6337
|
}
|
|
6177
6338
|
if (Object.hasOwn(prepared.proposed, "executor")) {
|
|
6178
6339
|
notices.push(prepared.proposed.executor === null ? "The Executor pin was removed; it now follows the current Pi session model." : "Executor model selection is saved; run /advisor to activate it in this session.");
|
|
@@ -6213,6 +6374,11 @@ var savedButNotAppliedResult = (prepared, savedPath, message) => ({
|
|
|
6213
6374
|
});
|
|
6214
6375
|
var applyAdvisorConfigUpdate = (runtime, ctx, prepared, savedPath) => {
|
|
6215
6376
|
try {
|
|
6377
|
+
if (Object.hasOwn(prepared.proposed, "advisorActivation")) {
|
|
6378
|
+
clearSessionActivationOverrides(ctx);
|
|
6379
|
+
} else {
|
|
6380
|
+
clearSessionActivationOverrides(ctx, SESSION_ACTIVATION_KEYS.filter((key) => Object.hasOwn(prepared.proposed, key)));
|
|
6381
|
+
}
|
|
6216
6382
|
loadConfig(ctx);
|
|
6217
6383
|
if (!Object.hasOwn(prepared.proposed, "contextMaxChars") && prepared.before.contextMaxChars !== undefined) {
|
|
6218
6384
|
setContextMaxCharsRef(prepared.before.contextMaxChars);
|
|
@@ -6307,9 +6473,16 @@ var registerAdvisorConfigurationTool = (runtime, dependencies = {}) => {
|
|
|
6307
6473
|
// src/commands/lifecycle.ts
|
|
6308
6474
|
var registerCommandLifecycle = (runtime, activateAdvisor) => {
|
|
6309
6475
|
runtime.pi.on("session_start", async (_event, ctx) => {
|
|
6476
|
+
runtime.noteAdvisorToolsStateChange();
|
|
6477
|
+
runtime.advisorSessionState.sessionToolsEnabled = false;
|
|
6478
|
+
clearSessionActivationOverrides(ctx);
|
|
6310
6479
|
runtime.resetSameModelNotice();
|
|
6311
6480
|
try {
|
|
6312
6481
|
loadConfig(ctx);
|
|
6482
|
+
if (advisorActivationRef === "session") {
|
|
6483
|
+
setAdvisorToolsActive(runtime.pi, false, true);
|
|
6484
|
+
return;
|
|
6485
|
+
}
|
|
6313
6486
|
if (!advisorToolsEnabledRef) {
|
|
6314
6487
|
setAdvisorToolsActive(runtime.pi, false);
|
|
6315
6488
|
runtime.updateSameModelNotice(ctx);
|
|
@@ -6327,12 +6500,21 @@ var registerCommandLifecycle = (runtime, activateAdvisor) => {
|
|
|
6327
6500
|
notify(ctx, `${t("notify.activationFailed.prefix", "Advisor activation failed:")} ${message}`, "error");
|
|
6328
6501
|
}
|
|
6329
6502
|
});
|
|
6503
|
+
runtime.pi.on("session_tree", (_event, ctx) => {
|
|
6504
|
+
if (advisorActivationRef === "session") {
|
|
6505
|
+
runtime.noteAdvisorToolsStateChange();
|
|
6506
|
+
setAdvisorToolsActive(runtime.pi, runtime.advisorSessionState.sessionToolsEnabled, true);
|
|
6507
|
+
runtime.updateSameModelNotice(ctx);
|
|
6508
|
+
}
|
|
6509
|
+
});
|
|
6330
6510
|
runtime.pi.on("model_select", (event, ctx) => {
|
|
6331
6511
|
if (!runtime.suppressModelSelectionSync) {
|
|
6332
6512
|
runtime.updateSameModelNotice(ctx, event.model);
|
|
6333
6513
|
}
|
|
6334
6514
|
});
|
|
6335
6515
|
runtime.pi.on("session_shutdown", (_event, ctx) => {
|
|
6516
|
+
runtime.noteAdvisorToolsStateChange();
|
|
6517
|
+
clearSessionActivationOverrides(ctx);
|
|
6336
6518
|
if (ctx.hasUI) {
|
|
6337
6519
|
ctx.ui.setStatus("advisor-usage", undefined);
|
|
6338
6520
|
}
|
|
@@ -7218,7 +7400,7 @@ var screeningSkipText = (outcome) => outcome.kind === "repeat" && outcome.reatta
|
|
|
7218
7400
|
|
|
7219
7401
|
// src/commands/manual-consultation.ts
|
|
7220
7402
|
var startManualConsultation = async (runtime, ctx, question, controller, scoutStatusToken, progress, gitContext) => {
|
|
7221
|
-
const
|
|
7403
|
+
const isOneShot = ctx.mode === "print" || ctx.mode === "json";
|
|
7222
7404
|
progress.phase = "preparing";
|
|
7223
7405
|
runtime.requestManualRender(ctx);
|
|
7224
7406
|
if (uiAvailable(ctx)) {
|
|
@@ -7299,7 +7481,7 @@ ${markdown}`,
|
|
|
7299
7481
|
display: true
|
|
7300
7482
|
}, {
|
|
7301
7483
|
deliverAs: "steer",
|
|
7302
|
-
triggerTurn: !
|
|
7484
|
+
triggerTurn: !isOneShot
|
|
7303
7485
|
});
|
|
7304
7486
|
} catch (error) {
|
|
7305
7487
|
if (controller.signal.aborted) {
|
|
@@ -7324,7 +7506,7 @@ ${markdown}`,
|
|
|
7324
7506
|
text: `**Advisor consultation failed:** ${message}`
|
|
7325
7507
|
},
|
|
7326
7508
|
display: true
|
|
7327
|
-
}, { deliverAs: "steer", triggerTurn: !
|
|
7509
|
+
}, { deliverAs: "steer", triggerTurn: !isOneShot });
|
|
7328
7510
|
notify(ctx, `${t("manualCmd.consultFailed.prefix", "Advisor consultation failed:")} ${message}`, "error");
|
|
7329
7511
|
notifyHerdrAdvisorFailure("Advisor consultation failed", message);
|
|
7330
7512
|
} finally {
|
|
@@ -7418,7 +7600,7 @@ var registerManualCommand = (runtime) => {
|
|
|
7418
7600
|
runtime.scoutStatus.register(scoutStatusToken);
|
|
7419
7601
|
runtime.manualConsultations.set(controller, scoutStatusToken);
|
|
7420
7602
|
runtime.pi.appendEntry?.("advisor-manual-call", { progressId, question });
|
|
7421
|
-
if (ctx.mode === "print") {
|
|
7603
|
+
if (ctx.mode === "print" || ctx.mode === "json") {
|
|
7422
7604
|
await startManualConsultation(runtime, ctx, question, controller, scoutStatusToken, progress, gitContext);
|
|
7423
7605
|
return;
|
|
7424
7606
|
}
|
|
@@ -7432,6 +7614,13 @@ var registerManualCommand = (runtime) => {
|
|
|
7432
7614
|
};
|
|
7433
7615
|
|
|
7434
7616
|
// src/commands/model-commands.ts
|
|
7617
|
+
var MODEL_SETTINGS = [
|
|
7618
|
+
"advisor",
|
|
7619
|
+
"advisorEffort",
|
|
7620
|
+
"advisorFallbackModel",
|
|
7621
|
+
"executor",
|
|
7622
|
+
"executorEffort"
|
|
7623
|
+
];
|
|
7435
7624
|
var registerModelCommands = (runtime) => {
|
|
7436
7625
|
runtime.pi.registerCommand("advisor", {
|
|
7437
7626
|
description: "Enable the Executor/Advisor flow and switch to the configured or explicitly selected Executor model; accepts contextMaxChars=N",
|
|
@@ -7461,10 +7650,15 @@ var registerModelCommands = (runtime) => {
|
|
|
7461
7650
|
setAdvisorFallbackModelRef(selection.advisorFallbackModel);
|
|
7462
7651
|
setExecutorEffortRef(selection.executorEffort);
|
|
7463
7652
|
setAdvisorEffortRef(selection.advisorEffort);
|
|
7653
|
+
const sessionScoped = advisorActivationRef === "session";
|
|
7464
7654
|
const path = saveConfig(ctx, {
|
|
7655
|
+
forceKeys: sessionScoped ? MODEL_SETTINGS : undefined,
|
|
7465
7656
|
persistAdvisor: true,
|
|
7466
7657
|
persistExecutor: true
|
|
7467
7658
|
});
|
|
7659
|
+
if (sessionScoped) {
|
|
7660
|
+
clearSessionActivationOverrides(ctx, MODEL_SETTINGS);
|
|
7661
|
+
}
|
|
7468
7662
|
runtime.updateSameModelNotice(ctx);
|
|
7469
7663
|
ctx.ui.notify(`${t("notify.modelsSaved.prefix", "Saved Executor + Advisor configurations to")} ${path}`, "info");
|
|
7470
7664
|
}
|
|
@@ -8660,6 +8854,13 @@ var advisorModelWhitelistItem = (settings, modelRefs, keybindings, theme, tui) =
|
|
|
8660
8854
|
tui
|
|
8661
8855
|
})
|
|
8662
8856
|
});
|
|
8857
|
+
var advisorToolsItem = (settings) => ({
|
|
8858
|
+
currentValue: settingValue(settings.advisorToolsEnabled, true),
|
|
8859
|
+
description: settings.advisorActivation === "session" ? t("settings.advisorToolsEnabled.sessionDesc", "Saved preference for persistent mode. Changing it also toggles this session’s Advisor tools.") : t("settings.advisorToolsEnabled.desc", "Allow the model to call the Advisor tools; activation scope determines how long they stay enabled."),
|
|
8860
|
+
id: "advisorToolsEnabled",
|
|
8861
|
+
label: settings.advisorActivation === "session" ? t("settings.advisorToolsEnabled.savedLabel", "Advisor tools (saved)") : t("settings.advisorToolsEnabled.label", "Advisor tools"),
|
|
8862
|
+
values: TOGGLE_VALUES
|
|
8863
|
+
});
|
|
8663
8864
|
var createSettingsItems = ({
|
|
8664
8865
|
effortLevels,
|
|
8665
8866
|
fallbackModel,
|
|
@@ -8682,12 +8883,13 @@ var createSettingsItems = ({
|
|
|
8682
8883
|
values: presets.map((preset) => preset.label)
|
|
8683
8884
|
},
|
|
8684
8885
|
{
|
|
8685
|
-
currentValue:
|
|
8686
|
-
description: t("settings.
|
|
8687
|
-
id: "
|
|
8688
|
-
label: t("settings.
|
|
8689
|
-
values:
|
|
8886
|
+
currentValue: settings.advisorActivation ?? "persistent",
|
|
8887
|
+
description: t("settings.advisorActivation.desc", "Choose persistent activation or start inactive at each session start, including /reload."),
|
|
8888
|
+
id: "advisorActivation",
|
|
8889
|
+
label: t("settings.advisorActivation.label", "Advisor activation"),
|
|
8890
|
+
values: ["persistent", "session"]
|
|
8690
8891
|
},
|
|
8892
|
+
advisorToolsItem(settings),
|
|
8691
8893
|
{
|
|
8692
8894
|
currentValue: settingValue(settings.simpleMode, false),
|
|
8693
8895
|
description: t("settings.simpleMode.desc", "Keep enabled Advisor tools available on demand without automatic gates or blocks."),
|
|
@@ -8920,6 +9122,10 @@ var parseModelWhitelist = (value) => [
|
|
|
8920
9122
|
];
|
|
8921
9123
|
var applyModeMutation = (settings, id, value) => {
|
|
8922
9124
|
switch (id) {
|
|
9125
|
+
case "advisorActivation": {
|
|
9126
|
+
settings.advisorActivation = value === "session" ? "session" : "persistent";
|
|
9127
|
+
return true;
|
|
9128
|
+
}
|
|
8923
9129
|
case "advisorToolsEnabled": {
|
|
8924
9130
|
settings.advisorToolsEnabled = value === "On";
|
|
8925
9131
|
if (!settings.advisorToolsEnabled) {
|
|
@@ -9242,7 +9448,7 @@ class AdvisorSettingsSelector {
|
|
|
9242
9448
|
showUsageDetails: this.settings.showUsageDetails ?? true,
|
|
9243
9449
|
toolPolicies: { ...this.settings.toolPolicies }
|
|
9244
9450
|
});
|
|
9245
|
-
if (id === "context" || id === "simpleMode" || id === "customRule" || id === "modelWhitelist" || id === "toolPolicies") {
|
|
9451
|
+
if (id === "context" || id === "advisorActivation" || id === "simpleMode" || id === "customRule" || id === "modelWhitelist" || id === "toolPolicies") {
|
|
9246
9452
|
this.settingsList = this.createSettingsList(id);
|
|
9247
9453
|
}
|
|
9248
9454
|
}
|
|
@@ -9271,6 +9477,7 @@ var applySessionSettings = (settings) => {
|
|
|
9271
9477
|
setShowUsageDetailsRef(settings.showUsageDetails ?? true);
|
|
9272
9478
|
setShowUsageFooterRef(settings.showUsageFooter ?? false);
|
|
9273
9479
|
setSimpleModeRef(settings.simpleMode ?? false);
|
|
9480
|
+
setAdvisorActivationRef(settings.advisorActivation ?? "persistent");
|
|
9274
9481
|
setAdvisorToolsEnabledRef(settings.advisorToolsEnabled ?? true);
|
|
9275
9482
|
setAlwaysOnRef(settings.alwaysOn ?? false);
|
|
9276
9483
|
setAdvisorFailureModeRef(settings.failureMode ?? "block-session");
|
|
@@ -9316,6 +9523,25 @@ var saveAdvisorSettings = (ctx, settings, options = {}) => {
|
|
|
9316
9523
|
if (!options.skipOutcomeLogging) {
|
|
9317
9524
|
saveGlobalOutcomeLogging(settings.outcomeLogging ?? false);
|
|
9318
9525
|
}
|
|
9526
|
+
if (previous.advisorActivation === "session") {
|
|
9527
|
+
const next = getAdvisorSettings();
|
|
9528
|
+
const changed = [];
|
|
9529
|
+
if (previous.contextMaxChars !== next.contextMaxChars) {
|
|
9530
|
+
changed.push("contextMaxChars");
|
|
9531
|
+
}
|
|
9532
|
+
if (previous.effort !== next.effort) {
|
|
9533
|
+
changed.push("advisorEffort");
|
|
9534
|
+
}
|
|
9535
|
+
if (previous.fallbackModel !== next.fallbackModel) {
|
|
9536
|
+
changed.push("advisorFallbackModel");
|
|
9537
|
+
}
|
|
9538
|
+
if (next.advisorActivation === "persistent") {
|
|
9539
|
+
clearSessionActivationOverrides(ctx);
|
|
9540
|
+
loadConfig(ctx);
|
|
9541
|
+
} else {
|
|
9542
|
+
clearSessionActivationOverrides(ctx, changed);
|
|
9543
|
+
}
|
|
9544
|
+
}
|
|
9319
9545
|
} catch (error) {
|
|
9320
9546
|
applyAdvisorSettings(previous);
|
|
9321
9547
|
throw error;
|
|
@@ -9324,6 +9550,7 @@ var saveAdvisorSettings = (ctx, settings, options = {}) => {
|
|
|
9324
9550
|
|
|
9325
9551
|
// src/commands/settings-commands.ts
|
|
9326
9552
|
var persistJevSettings = (ctx, settings, runtime) => {
|
|
9553
|
+
const previous = getAdvisorSettings();
|
|
9327
9554
|
try {
|
|
9328
9555
|
saveAdvisorSettings(ctx, settings, { skipOutcomeLogging: true });
|
|
9329
9556
|
} catch (error) {
|
|
@@ -9332,9 +9559,7 @@ var persistJevSettings = (ctx, settings, runtime) => {
|
|
|
9332
9559
|
return false;
|
|
9333
9560
|
}
|
|
9334
9561
|
try {
|
|
9335
|
-
|
|
9336
|
-
runtime.updateSameModelNotice(ctx);
|
|
9337
|
-
runtime.updateAdvisorUsageStatus(ctx);
|
|
9562
|
+
reconcileAdvisorToolsAfterSettings(runtime, ctx, previous);
|
|
9338
9563
|
} catch (error) {
|
|
9339
9564
|
const message = error instanceof Error ? error.message : String(error);
|
|
9340
9565
|
ctx.ui.notify(`${t("settingsCmd.refreshFailed.prefix", "Advisor settings were saved, but the status refresh failed:")} ${message}`, "warning");
|
|
@@ -9362,23 +9587,18 @@ var registerSettingsCommands = (runtime) => {
|
|
|
9362
9587
|
modelRefs: getConfiguredModelRefs(ctx),
|
|
9363
9588
|
onCancel: () => done(undefined),
|
|
9364
9589
|
onChange: (settings) => {
|
|
9365
|
-
const
|
|
9366
|
-
const toolsEnabled = settings.advisorToolsEnabled ?? true;
|
|
9590
|
+
const previous = getAdvisorSettings();
|
|
9367
9591
|
try {
|
|
9368
9592
|
saveAdvisorSettings(ctx, settings);
|
|
9369
|
-
|
|
9370
|
-
runtime.noteAdvisorToolsStateChange();
|
|
9371
|
-
}
|
|
9372
|
-
setAdvisorToolsActive(runtime.pi, toolsEnabled);
|
|
9373
|
-
runtime.updateSameModelNotice(ctx);
|
|
9374
|
-
runtime.updateAdvisorUsageStatus(ctx);
|
|
9593
|
+
reconcileAdvisorToolsAfterSettings(runtime, ctx, previous);
|
|
9375
9594
|
} catch (error) {
|
|
9376
|
-
const toolsDisabled =
|
|
9595
|
+
const toolsDisabled = previous.advisorToolsEnabled && settings.advisorToolsEnabled === false;
|
|
9377
9596
|
if (toolsDisabled) {
|
|
9378
9597
|
runtime.noteAdvisorToolsStateChange();
|
|
9379
9598
|
setAdvisorToolsEnabledRef(false);
|
|
9380
9599
|
setAlwaysOnRef(false);
|
|
9381
|
-
|
|
9600
|
+
runtime.advisorSessionState.sessionToolsEnabled = false;
|
|
9601
|
+
setAdvisorToolsActive(runtime.pi, false, previous.advisorActivation === "session");
|
|
9382
9602
|
runtime.resetSameModelNotice();
|
|
9383
9603
|
}
|
|
9384
9604
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -9394,10 +9614,11 @@ var registerSettingsCommands = (runtime) => {
|
|
|
9394
9614
|
}
|
|
9395
9615
|
});
|
|
9396
9616
|
runtime.pi.registerCommand("advisor-off", {
|
|
9397
|
-
description: "Disable
|
|
9617
|
+
description: "Disable Advisor tools; keep the current model",
|
|
9398
9618
|
handler: (_args, ctx) => {
|
|
9399
9619
|
runtime.noteAdvisorToolsStateChange();
|
|
9400
|
-
|
|
9620
|
+
runtime.advisorSessionState.sessionToolsEnabled = false;
|
|
9621
|
+
setAdvisorToolsActive(runtime.pi, false, advisorActivationRef === "session");
|
|
9401
9622
|
runtime.resetSameModelNotice();
|
|
9402
9623
|
try {
|
|
9403
9624
|
loadConfig(ctx);
|
|
@@ -9408,6 +9629,11 @@ var registerSettingsCommands = (runtime) => {
|
|
|
9408
9629
|
notify(ctx, `${t("settingsCmd.offReloadFailed.prefix", "Advisor tools disabled for this session, but configuration could not be reloaded:")} ${message}`, "error");
|
|
9409
9630
|
return Promise.resolve();
|
|
9410
9631
|
}
|
|
9632
|
+
if (advisorActivationRef === "session") {
|
|
9633
|
+
setAdvisorToolsActive(runtime.pi, false, true);
|
|
9634
|
+
notify(ctx, t("settingsCmd.off.session", "Advisor tools disabled for this session. Current model unchanged."), "info");
|
|
9635
|
+
return Promise.resolve();
|
|
9636
|
+
}
|
|
9411
9637
|
const wasAlwaysOn = alwaysOnRef;
|
|
9412
9638
|
const persisted = getPersistedModelRefs();
|
|
9413
9639
|
setAdvisorToolsEnabledRef(false);
|
|
@@ -9443,6 +9669,9 @@ var registerCommands = (pi, dependencies = {}) => {
|
|
|
9443
9669
|
registerAdvisorConfigurationTool(runtime);
|
|
9444
9670
|
};
|
|
9445
9671
|
|
|
9672
|
+
// src/tools/session-availability.ts
|
|
9673
|
+
var advisorToolsAllowed = (session) => advisorActivationRef === "session" ? session.sessionToolsEnabled : advisorToolsEnabledRef;
|
|
9674
|
+
|
|
9446
9675
|
// src/tools/budget-feedback.ts
|
|
9447
9676
|
var advisorBudgetMessage = (session) => {
|
|
9448
9677
|
const simple = isSimpleMode();
|
|
@@ -9467,7 +9696,7 @@ var advisorBudgetUpdate = (event, ctx, pi, session) => {
|
|
|
9467
9696
|
} catch {
|
|
9468
9697
|
return;
|
|
9469
9698
|
}
|
|
9470
|
-
if (!
|
|
9699
|
+
if (!advisorToolsAllowed(session) || !advisorModelIsAllowed(ctx)) {
|
|
9471
9700
|
return;
|
|
9472
9701
|
}
|
|
9473
9702
|
const message = advisorBudgetMessage(session);
|
|
@@ -10299,7 +10528,7 @@ var registerToolLifecycle = ({
|
|
|
10299
10528
|
return;
|
|
10300
10529
|
}
|
|
10301
10530
|
loadConfig(ctx);
|
|
10302
|
-
if (!
|
|
10531
|
+
if (!advisorToolsAllowed(session) || !advisorModelAccess(ctx).allowed || sameModelAdvisorDisabled(ctx)) {
|
|
10303
10532
|
return;
|
|
10304
10533
|
}
|
|
10305
10534
|
const guidelines = advisorInvocationGuidelines();
|
|
@@ -10333,20 +10562,20 @@ ${guidelines.map((rule) => `- ${rule}`).join(`
|
|
|
10333
10562
|
reason: session.blockedReason ?? "Advisor session is blocked."
|
|
10334
10563
|
};
|
|
10335
10564
|
}
|
|
10336
|
-
const isAdvisorTool = event.toolName === "ask_advisor" || event.toolName === "record_advisor_outcome";
|
|
10337
|
-
if (isAdvisorTool && !
|
|
10565
|
+
const isAdvisorTool = event.toolName === "ask_advisor" || event.toolName === "record_advisor_outcome" || event.toolName === "advisor_config" && advisorActivationRef === "session";
|
|
10566
|
+
if (isAdvisorTool && !advisorToolsAllowed(session)) {
|
|
10338
10567
|
return {
|
|
10339
10568
|
block: true,
|
|
10340
10569
|
reason: "Advisor tools are disabled. Enable them in /advisor-settings or run /advisor."
|
|
10341
10570
|
};
|
|
10342
10571
|
}
|
|
10343
|
-
if (!pi.getActiveTools().includes("ask_advisor")) {
|
|
10572
|
+
if (!pi.getActiveTools().includes("ask_advisor") || advisorActivationRef === "session" && !session.sessionToolsEnabled) {
|
|
10344
10573
|
return;
|
|
10345
10574
|
}
|
|
10346
10575
|
if (!loadConfigOrSkipGating(ctx)) {
|
|
10347
10576
|
return;
|
|
10348
10577
|
}
|
|
10349
|
-
if (isAdvisorTool && !
|
|
10578
|
+
if (isAdvisorTool && !advisorToolsAllowed(session)) {
|
|
10350
10579
|
return {
|
|
10351
10580
|
block: true,
|
|
10352
10581
|
reason: "Advisor tools are disabled. Enable them in /advisor-settings or run /advisor."
|
|
@@ -10546,7 +10775,10 @@ var registerAdvisorTool = (pi, session = sessionStateFor(pi), dependencies = {})
|
|
|
10546
10775
|
registerAskAdvisorTool(registration);
|
|
10547
10776
|
registerOutcomeTool(registration);
|
|
10548
10777
|
const turnGate = {
|
|
10549
|
-
activeTools: () =>
|
|
10778
|
+
activeTools: () => {
|
|
10779
|
+
const active = pi.getActiveTools();
|
|
10780
|
+
return advisorActivationRef === "session" && !session.sessionToolsEnabled ? active.filter((name) => name !== "ask_advisor") : active;
|
|
10781
|
+
},
|
|
10550
10782
|
consult: registration.consult,
|
|
10551
10783
|
herdrActivity: registration.herdrActivity,
|
|
10552
10784
|
send: (message) => pi.sendMessage(message, { deliverAs: "steer" }),
|