pi-advisor-flow 0.13.1 → 0.13.2-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/index.js +14 -7
  3. package/extensions/index.ts +6 -0
  4. package/package.json +9 -9
  5. package/scripts/check-bun-version.mjs +9 -0
  6. package/src/attachments.ts +36 -0
  7. package/src/child-session.ts +1 -0
  8. package/src/commands/activation-preparation.ts +12 -0
  9. package/src/commands/activation.ts +43 -0
  10. package/src/commands/advisor-tools.ts +3 -0
  11. package/src/commands/lifecycle.ts +15 -0
  12. package/src/commands/manual-command.ts +19 -0
  13. package/src/commands/manual-consultation.ts +20 -0
  14. package/src/commands/manual-progress.ts +13 -0
  15. package/src/commands/model-commands.ts +4 -0
  16. package/src/commands/model-options.ts +18 -0
  17. package/src/commands/model-picker.ts +16 -0
  18. package/src/commands/outcome-stats.ts +9 -0
  19. package/src/commands/registration.ts +1 -0
  20. package/src/commands/renderers.ts +14 -0
  21. package/src/commands/runtime.ts +5 -0
  22. package/src/commands/settings-commands.ts +18 -0
  23. package/src/commands/settings-persistence.ts +2 -0
  24. package/src/commands.ts +1 -0
  25. package/src/config/args.ts +7 -0
  26. package/src/config/defaults.ts +1 -0
  27. package/src/config/schema.ts +1 -0
  28. package/src/config/state.ts +64 -1
  29. package/src/config/storage.ts +37 -0
  30. package/src/config/types.ts +9 -0
  31. package/src/config/validation.ts +7 -0
  32. package/src/config.ts +6 -0
  33. package/src/content-utils.ts +5 -0
  34. package/src/conversation.ts +39 -0
  35. package/src/follow-up.ts +8 -0
  36. package/src/git.ts +8 -0
  37. package/src/herdr-block.ts +7 -0
  38. package/src/herdr-shared.ts +23 -0
  39. package/src/herdr.ts +18 -0
  40. package/src/image-attachments.ts +24 -0
  41. package/src/image-validation.ts +58 -0
  42. package/src/images.ts +24 -0
  43. package/src/jev/base-url.ts +14 -0
  44. package/src/jev/client.ts +49 -0
  45. package/src/jev/decisions-client.ts +14 -0
  46. package/src/jev/decisions-response.ts +38 -0
  47. package/src/jev/endpoint-key-store.ts +18 -0
  48. package/src/jev/key-store.ts +28 -0
  49. package/src/jev/ledger.ts +30 -12
  50. package/src/jev/openai-key-store.ts +17 -0
  51. package/src/jev/questions.ts +15 -0
  52. package/src/jev/state.ts +5 -0
  53. package/src/jev/transport.ts +35 -0
  54. package/src/model-stream.ts +32 -0
  55. package/src/outcome-stats.ts +16 -0
  56. package/src/outcomes.ts +31 -0
  57. package/src/pi-settings.ts +9 -0
  58. package/src/preferences.ts +26 -0
  59. package/src/redaction.ts +8 -0
  60. package/src/scout-context.ts +17 -0
  61. package/src/scout-curation.ts +12 -0
  62. package/src/scout-groups.ts +47 -0
  63. package/src/scout-protocol.ts +17 -0
  64. package/src/scout-reconstruct.ts +12 -0
  65. package/src/scout.ts +47 -0
  66. package/src/session-context.ts +11 -0
  67. package/src/session-state.ts +73 -13
  68. package/src/tool-result-cap.ts +11 -0
  69. package/src/tools/consult-context.ts +24 -0
  70. package/src/tools/consultation.ts +43 -0
  71. package/src/tools/gate-policy.ts +18 -0
  72. package/src/tools/gate-protocol.ts +22 -0
  73. package/src/tools/jev-filter.ts +26 -0
  74. package/src/tools/jev-turn-gate.ts +17 -0
  75. package/src/tools/loop-gate.ts +25 -0
  76. package/src/tools/model-access.ts +12 -0
  77. package/src/tools/outage-notifier.ts +4 -0
  78. package/src/tools/prompts.ts +17 -0
  79. package/src/tools/register-ask-advisor.ts +44 -0
  80. package/src/tools/register-lifecycle.ts +32 -0
  81. package/src/tools/register-outcome.ts +7 -0
  82. package/src/tools/register-renderers.ts +14 -0
  83. package/src/tools/registration.ts +3 -0
  84. package/src/tools/render-advisor-result.ts +44 -0
  85. package/src/tools/render-common.ts +10 -0
  86. package/src/tools/scout-status.ts +34 -0
  87. package/src/tools/session.ts +3 -0
  88. package/src/tools.ts +8 -0
  89. package/src/ui/jev-filter-submenu.ts +21 -0
  90. package/src/ui/jev-provider-submenu-view.ts +22 -0
  91. package/src/ui/jev-provider-submenu.ts +81 -0
  92. package/src/ui/jev-setup-support.ts +26 -0
  93. package/src/ui/manual-dialog-render.ts +20 -0
  94. package/src/ui/manual-dialog.ts +38 -0
  95. package/src/ui/masked-input.ts +2 -0
  96. package/src/ui/searchable-model-list.ts +28 -0
  97. package/src/ui/settings-formatting.ts +26 -0
  98. package/src/ui/settings-items.ts +11 -0
  99. package/src/ui/settings-list-adapter.ts +13 -0
  100. package/src/ui/settings-mutations.ts +60 -0
  101. package/src/ui/settings-selector.ts +30 -0
  102. package/src/ui/text-setting-submenu.ts +9 -0
  103. package/src/ui-guard.ts +1 -0
  104. package/src/ui.ts +3 -0
  105. package/src/usage.ts +31 -0
@@ -26,15 +26,19 @@ export const registerCommandLifecycle = (
26
26
  runtime.pi.on("session_start", async (_event, ctx) => {
27
27
  runtime.pendingExecutorModelRef = undefined;
28
28
  runtime.resetSameModelNotice();
29
+
29
30
  // A malformed advisor.json or a provider auth failure must not reject a
30
31
  // lifecycle handler and break session startup.
31
32
  try {
32
33
  loadConfig(ctx);
34
+
33
35
  if (!advisorToolsEnabledRef) {
34
36
  setAdvisorToolsActive(runtime.pi, false);
35
37
  runtime.updateSameModelNotice(ctx);
38
+
36
39
  return;
37
40
  }
41
+
38
42
  if (alwaysOnRef) {
39
43
  setAdvisorToolsActive(runtime.pi, false);
40
44
  await activateAdvisor("", ctx, false);
@@ -52,6 +56,7 @@ export const registerCommandLifecycle = (
52
56
  if (!runtime.suppressModelSelectionSync) {
53
57
  runtime.updateSameModelNotice(ctx, event.model);
54
58
  }
59
+
55
60
  // "restore" replays a stored session model and "cycle" changes the active
56
61
  // model without an explicit `/model` choice. Neither should redefine the
57
62
  // configured Executor.
@@ -62,17 +67,23 @@ export const registerCommandLifecycle = (
62
67
  ) {
63
68
  return;
64
69
  }
70
+
65
71
  const selected = `${event.model.provider}/${event.model.id}`;
72
+
66
73
  if (!runtime.flowEnabled()) {
67
74
  // Defer persistence until `/advisor` succeeds. This keeps ordinary model
68
75
  // selection global defaults untouched when the flow is not enabled.
69
76
  runtime.pendingExecutorModelRef = selected;
77
+
70
78
  return;
71
79
  }
80
+
72
81
  runtime.pendingExecutorModelRef = undefined;
82
+
73
83
  if (selected === executorRef) {
74
84
  return;
75
85
  }
86
+
76
87
  const persisted = getPersistedModelRefs();
77
88
  setExecutorRef(selected);
78
89
  saveConfig(ctx, {
@@ -85,15 +96,19 @@ export const registerCommandLifecycle = (
85
96
  if (ctx.hasUI) {
86
97
  ctx.ui.setStatus("advisor-usage", undefined);
87
98
  }
99
+
88
100
  for (const [controller, token] of runtime.manualConsultations) {
89
101
  controller.abort();
90
102
  const timer = runtime.manualProgressTimers.get(controller);
103
+
91
104
  if (timer) {
92
105
  clearInterval(timer);
93
106
  runtime.manualProgressTimers.delete(controller);
94
107
  }
108
+
95
109
  runtime.scoutStatus.release(ctx, token);
96
110
  }
111
+
97
112
  runtime.scoutStatus.clear(ctx);
98
113
  runtime.manualConsultations.clear();
99
114
  runtime.manualProgressTimers.clear();
@@ -25,15 +25,21 @@ export const registerManualCommand = (runtime: CommandRuntime) => {
25
25
  if (!loadCommandConfig(ctx)) {
26
26
  return;
27
27
  }
28
+
28
29
  if (sameModelAdvisorDisabled(ctx)) {
29
30
  notify(ctx, sameModelAdvisorNotice, "info");
31
+
30
32
  return;
31
33
  }
34
+
32
35
  const accessReason = advisorModelAccessReason(ctx);
36
+
33
37
  if (accessReason) {
34
38
  notify(ctx, accessReason, "warning");
39
+
35
40
  return;
36
41
  }
42
+
37
43
  if (
38
44
  !(
39
45
  isSimpleMode() ||
@@ -41,11 +47,13 @@ export const registerManualCommand = (runtime: CommandRuntime) => {
41
47
  )
42
48
  ) {
43
49
  runtime.reportManualBudgetExhausted(ctx);
50
+
44
51
  return;
45
52
  }
46
53
 
47
54
  let gitContext: GitContextLevel | undefined;
48
55
  let question: string | undefined;
56
+
49
57
  if (ctx.mode === "tui") {
50
58
  const request = await ctx.ui.custom<ManualAdvisorRequest | undefined>(
51
59
  (tui, theme, keybindings, done) =>
@@ -69,9 +77,11 @@ export const registerManualCommand = (runtime: CommandRuntime) => {
69
77
  },
70
78
  }
71
79
  );
80
+
72
81
  if (!request) {
73
82
  return;
74
83
  }
84
+
75
85
  if (
76
86
  !(
77
87
  isSimpleMode() ||
@@ -81,8 +91,10 @@ export const registerManualCommand = (runtime: CommandRuntime) => {
81
91
  )
82
92
  ) {
83
93
  runtime.reportManualBudgetExhausted(ctx);
94
+
84
95
  return;
85
96
  }
97
+
86
98
  const { gitContext: selectedGitContext, message } = request;
87
99
  gitContext = selectedGitContext;
88
100
  question = resolveAdvisorRequest(message);
@@ -92,17 +104,21 @@ export const registerManualCommand = (runtime: CommandRuntime) => {
92
104
 
93
105
  if (sameModelAdvisorDisabled(ctx)) {
94
106
  notify(ctx, sameModelAdvisorNotice, "info");
107
+
95
108
  return;
96
109
  }
110
+
97
111
  if (!isSimpleMode()) {
98
112
  runtime.advisorSessionState.consumeCall();
99
113
  }
114
+
100
115
  // A single visible progress surface avoids competing consultations overwriting
101
116
  // each other's streamed state. A newer manual request replaces the previous one.
102
117
  for (const [pending, token] of runtime.manualConsultations) {
103
118
  pending.abort();
104
119
  runtime.scoutStatus.release(ctx, token);
105
120
  }
121
+
106
122
  runtime.manualConsultations.clear();
107
123
  const controller = new AbortController();
108
124
  const scoutStatusToken = Symbol("manual-scout");
@@ -112,6 +128,7 @@ export const registerManualCommand = (runtime: CommandRuntime) => {
112
128
  runtime.scoutStatus.register(scoutStatusToken);
113
129
  runtime.manualConsultations.set(controller, scoutStatusToken);
114
130
  runtime.pi.appendEntry?.("advisor-manual-call", { progressId, question });
131
+
115
132
  // Print mode tears the session down when the handler returns, so the
116
133
  // consultation must complete inside the handler to keep its ctx valid.
117
134
  if (ctx.mode === "print") {
@@ -124,8 +141,10 @@ export const registerManualCommand = (runtime: CommandRuntime) => {
124
141
  progress,
125
142
  gitContext
126
143
  );
144
+
127
145
  return;
128
146
  }
147
+
129
148
  // Intentional fire-and-forget: the consultation streams after the command
130
149
  // handler returns. A rejected consultation must not escape as an
131
150
  // unhandled rejection; its error paths already notify and record.
@@ -36,6 +36,7 @@ export const startManualConsultation = async (
36
36
  const isPrintMode = ctx.mode === "print";
37
37
  progress.phase = "preparing";
38
38
  runtime.requestManualRender(ctx);
39
+
39
40
  if (uiAvailable(ctx)) {
40
41
  const timer = setInterval(() => {
41
42
  if (
@@ -43,14 +44,19 @@ export const startManualConsultation = async (
43
44
  runtime.manualConsultations.get(controller) !== scoutStatusToken
44
45
  ) {
45
46
  clearInterval(timer);
47
+
46
48
  return;
47
49
  }
50
+
48
51
  runtime.requestManualRender(ctx);
49
52
  }, 80);
53
+
50
54
  runtime.manualProgressTimers.set(controller, timer);
51
55
  }
56
+
52
57
  const finishHerdrActivity = runtime.herdrActivity.start();
53
58
  let scoutDetails: ScoutToolDetails | undefined;
59
+
54
60
  try {
55
61
  const {
56
62
  adviceId,
@@ -68,6 +74,7 @@ export const startManualConsultation = async (
68
74
  if (controller.signal.aborted) {
69
75
  return;
70
76
  }
77
+
71
78
  progress.phase = "active";
72
79
  progress.thinking = thinking;
73
80
  progress.text = text;
@@ -88,9 +95,11 @@ export const startManualConsultation = async (
88
95
  },
89
96
  gitContext
90
97
  );
98
+
91
99
  if (controller.signal.aborted) {
92
100
  return;
93
101
  }
102
+
94
103
  progress.phase = "complete";
95
104
  runtime.advisorSessionState.resetTurnsSinceConsultation();
96
105
  runtime.advisorSessionState.recordInvocation({
@@ -102,6 +111,7 @@ export const startManualConsultation = async (
102
111
  trigger: "manual",
103
112
  usage,
104
113
  });
114
+
105
115
  if (isString(adviceId)) {
106
116
  // Registering the manual question lets an identical later ask_advisor
107
117
  // hit repeat detection instead of re-consulting.
@@ -113,7 +123,9 @@ export const startManualConsultation = async (
113
123
  normalizeScreeningQuestion(question)
114
124
  );
115
125
  }
126
+
116
127
  runtime.updateAdvisorUsageStatus(ctx);
128
+
117
129
  const details: ManualResultDetails = {
118
130
  adviceId,
119
131
  advisor: model ?? advisorRef,
@@ -123,10 +135,13 @@ export const startManualConsultation = async (
123
135
  question,
124
136
  text: markdown,
125
137
  };
138
+
126
139
  const normalizedUsage = snapshotAdvisorUsage(usage);
140
+
127
141
  if (normalizedUsage) {
128
142
  details.usage = normalizedUsage;
129
143
  }
144
+
130
145
  runtime.pi.sendMessage(
131
146
  {
132
147
  content: `Manual Advisor consultation${question ? ` (${question})` : ""} — for your awareness; no action or follow-up consultation is needed unless the user asks:\n\n${markdown}`,
@@ -147,6 +162,7 @@ export const startManualConsultation = async (
147
162
  if (controller.signal.aborted) {
148
163
  return;
149
164
  }
165
+
150
166
  progress.phase = "error";
151
167
  const message = error instanceof Error ? error.message : String(error);
152
168
  runtime.advisorSessionState.resetTurnsSinceConsultation();
@@ -174,14 +190,18 @@ export const startManualConsultation = async (
174
190
  notifyHerdrAdvisorFailure("Advisor consultation failed", message);
175
191
  } finally {
176
192
  finishHerdrActivity();
193
+
177
194
  if (controller.signal.aborted) {
178
195
  progress.phase = "cancelled";
179
196
  }
197
+
180
198
  const timer = runtime.manualProgressTimers.get(controller);
199
+
181
200
  if (timer) {
182
201
  clearInterval(timer);
183
202
  runtime.manualProgressTimers.delete(controller);
184
203
  }
204
+
185
205
  runtime.requestManualRender(ctx);
186
206
  runtime.scoutStatus.release(ctx, scoutStatusToken);
187
207
  runtime.manualConsultations.delete(controller);
@@ -33,20 +33,26 @@ export class ManualAdvisorProgressComponent implements Component {
33
33
 
34
34
  render(width: number): string[] {
35
35
  const box = renderAdvisorCallBox(this.question, this.theme);
36
+
36
37
  if (this.state.phase === "complete" || this.state.phase === "cancelled") {
37
38
  return box.render(width);
38
39
  }
39
40
 
40
41
  const { scout } = this.state;
42
+
41
43
  const scoutActive =
42
44
  scout?.status === "calling" || scout?.status === "streaming";
45
+
43
46
  if (scoutActive) {
44
47
  renderScoutDetails(box, scout, this.expanded, this.theme);
48
+
45
49
  return box.render(width);
46
50
  }
51
+
47
52
  if (scout?.status === "cancelled") {
48
53
  return box.render(width);
49
54
  }
55
+
50
56
  if (this.state.phase === "error") {
51
57
  box.addChild(
52
58
  new Text(
@@ -55,17 +61,21 @@ export class ManualAdvisorProgressComponent implements Component {
55
61
  0
56
62
  )
57
63
  );
64
+
58
65
  return box.render(width);
59
66
  }
60
67
 
61
68
  const frame =
62
69
  SPINNER_FRAMES[Math.floor(Date.now() / 80) % SPINNER_FRAMES.length];
70
+
63
71
  let status = "Working…";
72
+
64
73
  if (this.state.phase === "preparing") {
65
74
  status = "Preparing…";
66
75
  } else if (this.state.text?.trim()) {
67
76
  status = "Responding…";
68
77
  }
78
+
69
79
  box.addChild(
70
80
  new Text(
71
81
  `${this.theme.fg("warning", this.theme.bold(`◆ ADVISOR ${frame}`))} ${this.theme.fg("dim", `· ${status}`)}`,
@@ -73,11 +83,13 @@ export class ManualAdvisorProgressComponent implements Component {
73
83
  0
74
84
  )
75
85
  );
86
+
76
87
  if (this.state.thinking?.trim()) {
77
88
  box.addChild(
78
89
  renderThinkingMarkdown(this.state.thinking.slice(-200), this.theme)
79
90
  );
80
91
  }
92
+
81
93
  if (this.state.text) {
82
94
  box.addChild(
83
95
  new Markdown(
@@ -88,6 +100,7 @@ export class ManualAdvisorProgressComponent implements Component {
88
100
  )
89
101
  );
90
102
  }
103
+
91
104
  return box.render(width);
92
105
  }
93
106
 
@@ -31,10 +31,12 @@ export const registerModelCommands = (runtime: CommandRuntime) => {
31
31
  if (!(loadCommandConfig(ctx) && ctx.hasUI)) {
32
32
  return;
33
33
  }
34
+
34
35
  // When `/model` was used before activation, show that session choice as
35
36
  // the Executor's current option instead of making the persisted Executor
36
37
  // look like the active selection.
37
38
  const persisted = getPersistedModelRefs();
39
+
38
40
  const selection = await selectAdvisorModels(ctx, {
39
41
  advisor: persisted.advisor ? advisorRef : "",
40
42
  advisorEffort: advisorEffortRef,
@@ -46,6 +48,7 @@ export const registerModelCommands = (runtime: CommandRuntime) => {
46
48
  selectAdvisor: true,
47
49
  selectExecutor: true,
48
50
  });
51
+
49
52
  if (!selection) {
50
53
  return;
51
54
  }
@@ -60,6 +63,7 @@ export const registerModelCommands = (runtime: CommandRuntime) => {
60
63
  persistAdvisor: true,
61
64
  persistExecutor: true,
62
65
  });
66
+
63
67
  runtime.pendingExecutorModelRef = undefined;
64
68
  runtime.updateSameModelNotice(ctx);
65
69
  ctx.ui.notify(
@@ -6,6 +6,7 @@ import type { ContextPreset } from "../ui/types.ts";
6
6
 
7
7
  export const DEFAULT_EFFORT_LEVEL = "Default (Model Default)";
8
8
  const SELECTED_PREFIX = "✓ ";
9
+
9
10
  export const EFFORT_LEVELS = [
10
11
  DEFAULT_EFFORT_LEVEL,
11
12
  "off",
@@ -19,6 +20,7 @@ export const EFFORT_LEVELS = [
19
20
 
20
21
  export const effortChoices = (configured: string | undefined): string[] => {
21
22
  const current = configured ?? DEFAULT_EFFORT_LEVEL;
23
+
22
24
  return [
23
25
  `${SELECTED_PREFIX}${current}`,
24
26
  ...EFFORT_LEVELS.filter((level) => level !== current),
@@ -29,6 +31,7 @@ export const selectedEffort = (choice: string): string | undefined => {
29
31
  const effort = choice.startsWith(SELECTED_PREFIX)
30
32
  ? choice.slice(SELECTED_PREFIX.length)
31
33
  : choice;
34
+
32
35
  return effort === DEFAULT_EFFORT_LEVEL ? undefined : effort;
33
36
  };
34
37
 
@@ -36,17 +39,20 @@ export const ADVISOR_ACTIVATION_EXPLANATION =
36
39
  "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.";
37
40
 
38
41
  const ARGUMENT_WHITESPACE = /\s+/u;
42
+
39
43
  const hasModelOverride = (args: string, key: "advisor" | "executor") =>
40
44
  args
41
45
  .trim()
42
46
  .split(ARGUMENT_WHITESPACE)
43
47
  .some((token) => {
44
48
  const [tokenKey, value] = token.split("=");
49
+
45
50
  return tokenKey === key && Boolean(value);
46
51
  });
47
52
 
48
53
  export const hasExecutorOverride = (args: string) =>
49
54
  hasModelOverride(args, "executor");
55
+
50
56
  export const hasAdvisorOverride = (args: string) =>
51
57
  hasModelOverride(args, "advisor");
52
58
 
@@ -92,7 +98,9 @@ export const findConfiguredModel = (
92
98
  if (!ref) {
93
99
  return;
94
100
  }
101
+
95
102
  const [provider, modelId] = splitRef(ref);
103
+
96
104
  // oxlint-disable-next-line unicorn/no-array-method-this-argument -- Pi ModelRegistry.find(provider, id), not Array#find.
97
105
  return ctx.modelRegistry.find(provider, modelId);
98
106
  };
@@ -103,6 +111,7 @@ export const getAvailableModelRefs = (
103
111
  if (!ctx.modelRegistry.getAvailable) {
104
112
  return undefined;
105
113
  }
114
+
106
115
  return ctx.modelRegistry
107
116
  .getAvailable()
108
117
  .map((model) => `${model.provider}/${model.id}`);
@@ -111,6 +120,7 @@ export const getAvailableModelRefs = (
111
120
  export const getConfiguredModelRefs = (ctx: ExtensionContext): string[] => {
112
121
  const registry = ctx.modelRegistry;
113
122
  const models = registry?.getAvailable ? registry.getAvailable() : [];
123
+
114
124
  return [
115
125
  ...new Set(models.map((model) => `${model.provider}/${model.id}`)),
116
126
  ].toSorted((left, right) => left.localeCompare(right));
@@ -124,10 +134,13 @@ const isSelectableModel = (
124
134
  if (!ref) {
125
135
  return false;
126
136
  }
137
+
127
138
  if (availableRefs) {
128
139
  const [provider, modelId] = splitRef(ref);
140
+
129
141
  return availableRefs.has(`${provider}/${modelId}`);
130
142
  }
143
+
131
144
  return Boolean(findConfiguredModel(ctx, ref));
132
145
  };
133
146
 
@@ -142,9 +155,11 @@ export const getExplicitModelError = (
142
155
  if (!ref) {
143
156
  return `${label} model not configured`;
144
157
  }
158
+
145
159
  if (!findConfiguredModel(ctx, ref)) {
146
160
  return `${label} model not found: ${ref}`;
147
161
  }
162
+
148
163
  if (availableRefs && !isSelectableModel(ctx, ref, availableRefs)) {
149
164
  return `${label} model unavailable: ${ref}`;
150
165
  }
@@ -173,17 +188,20 @@ export const planActivationModels = (
173
188
  isSelectableModel(ctx, pendingExecutorRef, availableRefs)
174
189
  ? pendingExecutorRef
175
190
  : undefined;
191
+
176
192
  const executorConfigured =
177
193
  executorOverride ||
178
194
  Boolean(pendingExecutor) ||
179
195
  Boolean(
180
196
  persisted.executor && isSelectableModel(ctx, executor, availableRefs)
181
197
  );
198
+
182
199
  const advisorConfigured =
183
200
  advisorOverride ||
184
201
  Boolean(
185
202
  persisted.advisor && isSelectableModel(ctx, advisor, availableRefs)
186
203
  );
204
+
187
205
  return {
188
206
  pendingExecutor,
189
207
  selectAdvisor: !advisorConfigured,
@@ -33,14 +33,18 @@ export const selectAdvisorModels = async (
33
33
  if (!ctx.hasUI) {
34
34
  return undefined;
35
35
  }
36
+
36
37
  const refs = getAvailableModelRefs(ctx);
38
+
37
39
  if (refs && refs.length === 0) {
38
40
  ctx.ui.notify(
39
41
  "No selectable models are available. Configure a provider with /login or models.json, then retry.",
40
42
  "error"
41
43
  );
44
+
42
45
  return undefined;
43
46
  }
47
+
44
48
  const allOptions = [
45
49
  ...new Set(
46
50
  refs ??
@@ -49,6 +53,7 @@ export const selectAdvisorModels = async (
49
53
  )
50
54
  ),
51
55
  ];
56
+
52
57
  let {
53
58
  advisor,
54
59
  advisorEffort,
@@ -71,16 +76,20 @@ export const selectAdvisorModels = async (
71
76
  tui,
72
77
  })
73
78
  );
79
+
74
80
  if (!selectedExecutor) {
75
81
  return undefined;
76
82
  }
83
+
77
84
  const selectedExecutorEffort = await ctx.ui.select(
78
85
  "Select Executor Reasoning/Thinking Level",
79
86
  effortChoices(executorEffort)
80
87
  );
88
+
81
89
  if (!selectedExecutorEffort) {
82
90
  return undefined;
83
91
  }
92
+
84
93
  executor = selectedExecutor;
85
94
  executorEffort = selectedEffort(selectedExecutorEffort);
86
95
  }
@@ -99,16 +108,20 @@ export const selectAdvisorModels = async (
99
108
  tui,
100
109
  })
101
110
  );
111
+
102
112
  if (!selectedAdvisor) {
103
113
  return undefined;
104
114
  }
115
+
105
116
  const selectedAdvisorEffort = await ctx.ui.select(
106
117
  "Select Advisor Reasoning/Thinking Level",
107
118
  effortChoices(advisorEffort)
108
119
  );
120
+
109
121
  if (!selectedAdvisorEffort) {
110
122
  return undefined;
111
123
  }
124
+
112
125
  advisor = selectedAdvisor;
113
126
  advisorEffort = selectedEffort(selectedAdvisorEffort);
114
127
  }
@@ -132,9 +145,11 @@ export const selectAdvisorModels = async (
132
145
  tui,
133
146
  })
134
147
  );
148
+
135
149
  if (selectedFallback === undefined) {
136
150
  return undefined;
137
151
  }
152
+
138
153
  advisorFallbackModel =
139
154
  selectedFallback === FALLBACK_ADVISOR_MODEL_DISABLED
140
155
  ? undefined
@@ -143,6 +158,7 @@ export const selectAdvisorModels = async (
143
158
  if (!(advisor && executor)) {
144
159
  return undefined;
145
160
  }
161
+
146
162
  return {
147
163
  advisor,
148
164
  advisorEffort,
@@ -26,28 +26,36 @@ export const formatAdvisorStats = ({
26
26
  if (error) {
27
27
  return `**Could not read Advisor outcomes.**\n\n${error}`;
28
28
  }
29
+
29
30
  if (!stats || stats.total === 0) {
30
31
  const ignored = malformedLines
31
32
  ? `\n\nIgnored ${malformedLines} malformed ledger line${malformedLines === 1 ? "" : "s"}.`
32
33
  : "";
34
+
33
35
  return `**No Advisor outcomes recorded yet.**\n\nEnable outcome logging and record an outcome after an Advisor response to build this report.${ignored}`;
34
36
  }
37
+
35
38
  const { validationByAdoption } = stats;
36
39
  const { followed } = validationByAdoption;
37
40
  const notFollowed = validationByAdoption["not-followed"];
41
+
38
42
  const triggerLines = Object.entries(stats.byTrigger).map(
39
43
  ([trigger, count]) => `- ${trigger}: ${count}`
40
44
  );
45
+
41
46
  const adoptionLines = Object.entries(stats.adoption).map(
42
47
  ([adoption, count]) => `- ${adoption}: ${count}`
43
48
  );
49
+
44
50
  const validationLines = [
45
51
  `- followed: ${percent(followed.passRate)} passed (${followed.passed}/${validatedCount(followed)})`,
46
52
  `- not-followed: ${percent(notFollowed.passRate)} passed (${notFollowed.passed}/${validatedCount(notFollowed)})`,
47
53
  ];
54
+
48
55
  const ignored = malformedLines
49
56
  ? `\n\nIgnored ${malformedLines} malformed ledger line${malformedLines === 1 ? "" : "s"}.`
50
57
  : "";
58
+
51
59
  return [
52
60
  `**${stats.total} Advisor outcome${stats.total === 1 ? "" : "s"}**`,
53
61
  "",
@@ -70,6 +78,7 @@ const readAdvisorStats = async (): Promise<AdvisorStatsDetails> => {
70
78
  try {
71
79
  const log = await readOutcomeLog();
72
80
  const stats = aggregateOutcomeRecords(log.records, log.malformedLines);
81
+
73
82
  return { malformedLines: log.malformedLines, stats };
74
83
  } catch (error) {
75
84
  return {
@@ -18,6 +18,7 @@ export const registerCommands = (
18
18
  dependencies: CommandDependencies = {}
19
19
  ) => {
20
20
  const runtime = createCommandRuntime(pi, dependencies);
21
+
21
22
  const activate = (args: string, ctx: ExtensionContext, announce = true) =>
22
23
  activateAdvisor(runtime, args, ctx, announce);
23
24