@lune_99/pi-subagent 0.1.0 → 0.2.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 +33 -0
- package/README.md +25 -9
- package/docs/reference.md +62 -38
- package/package.json +6 -6
- package/skills/create-lune-subagent/SKILL.md +21 -17
- package/src/auto-model.ts +46 -37
- package/src/definition-file.ts +36 -1
- package/src/definitions.ts +6 -0
- package/src/dock/dock-contribution.ts +19 -9
- package/src/index.ts +36 -10
- package/src/inspector/details.ts +9 -3
- package/src/inspector/inspector.ts +67 -43
- package/src/models.ts +24 -9
- package/src/notify/notification-box.ts +42 -15
- package/src/notify/notifier.ts +23 -6
- package/src/run/guide.ts +5 -0
- package/src/run/run-file.ts +1 -0
- package/src/run/run-manager.ts +123 -26
- package/src/run/run.ts +130 -38
- package/src/run/types.ts +12 -4
- package/src/settings/agents-menu.ts +37 -24
- package/src/settings/panel.ts +50 -8
- package/src/settings/schema.ts +5 -1
- package/src/settings/thinking-choices.ts +92 -0
- package/src/tools/format.ts +65 -43
- package/src/tools/subagent-tools.ts +95 -207
package/src/run/types.ts
CHANGED
|
@@ -79,7 +79,7 @@ export interface AutoRisk {
|
|
|
79
79
|
floor?: AutoTier;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
/** How `model: auto` resolved the run's model and
|
|
82
|
+
/** How `model: auto` resolved the run's model and thinking together. */
|
|
83
83
|
export type AutoModelChoice =
|
|
84
84
|
| {
|
|
85
85
|
by: "rating";
|
|
@@ -88,14 +88,14 @@ export type AutoModelChoice =
|
|
|
88
88
|
tier: AutoRating<AutoTier>;
|
|
89
89
|
/** The tier whose model the run got, or `main` for the main agent's model. */
|
|
90
90
|
modelFrom: AutoTier | "main";
|
|
91
|
-
/** Absent when the
|
|
91
|
+
/** Absent when the run's model supports only one level. */
|
|
92
92
|
thinking?: AutoRating<ThinkingLevel>;
|
|
93
93
|
/** Absent for a run that an earlier version started. */
|
|
94
94
|
risk?: AutoRisk;
|
|
95
95
|
}
|
|
96
96
|
/** No classifier is selected, so the run got the main agent's model. */
|
|
97
97
|
| { by: "no-classifier" }
|
|
98
|
-
/**
|
|
98
|
+
/** Recorded by earlier versions when an explicit thinking level left nothing to rate. */
|
|
99
99
|
| { by: "nothing-to-rate" }
|
|
100
100
|
/** The classifier failed, so the run got the main agent's model, and thinking if unset. */
|
|
101
101
|
| { by: "classifier-failed"; classifier: string; error: string };
|
|
@@ -105,12 +105,13 @@ export interface RunSnapshot {
|
|
|
105
105
|
runId: string;
|
|
106
106
|
/** The definition name, or `run-<n>` for an inline run. */
|
|
107
107
|
name: string;
|
|
108
|
+
title?: string;
|
|
108
109
|
/** Only for a run started from a definition. */
|
|
109
110
|
definition?: { name: string; body: string; file: string };
|
|
110
111
|
task: string;
|
|
111
112
|
/** `provider/id`. */
|
|
112
113
|
model: string;
|
|
113
|
-
/** Set when the call or
|
|
114
|
+
/** Set when the call, definition or Auto mode only asked for `auto`; `sources.model` says which. */
|
|
114
115
|
autoModel?: AutoModelChoice;
|
|
115
116
|
thinking: ThinkingLevel;
|
|
116
117
|
/** The effective SDK allowlist, `report` included. */
|
|
@@ -150,8 +151,15 @@ export interface TurnRecord {
|
|
|
150
151
|
error?: string;
|
|
151
152
|
/** The run's last text, kept when the turn ended without `report`. */
|
|
152
153
|
unreportedMessage?: string;
|
|
154
|
+
/** An idle turn without `report` whose last reply hit the token limit or left no text. */
|
|
155
|
+
cutShort?: boolean;
|
|
153
156
|
/** The user wrote to the run from the inspector during this turn. */
|
|
154
157
|
userWrote: boolean;
|
|
158
|
+
/**
|
|
159
|
+
* What the user wrote during this turn, oldest first, each message cut in the middle past a
|
|
160
|
+
* limit. Turns that earlier versions recorded have only `userWrote`.
|
|
161
|
+
*/
|
|
162
|
+
userMessages?: string[];
|
|
155
163
|
stoppedBy?: StopSource;
|
|
156
164
|
startedAt: string;
|
|
157
165
|
endedAt: string;
|
|
@@ -10,17 +10,18 @@ import {
|
|
|
10
10
|
type SettingsPanelField,
|
|
11
11
|
type SettingsPanelSchema,
|
|
12
12
|
} from "@lune_99/pi-lune-extensions-core/panel";
|
|
13
|
-
import type { SettingsScope } from "@lune_99/pi-lune-extensions-core/settings";
|
|
13
|
+
import type { DeepReadonly, SettingsScope } from "@lune_99/pi-lune-extensions-core/settings";
|
|
14
14
|
import Type from "typebox";
|
|
15
15
|
|
|
16
16
|
import type { ToolCatalog } from "../catalog.ts";
|
|
17
17
|
import { editDefinitionFile, type DefinitionField } from "../definition-file.ts";
|
|
18
18
|
import { loadDefinitions, type AgentDefinition, type LoadedDefinitions } from "../definitions.ts";
|
|
19
|
-
import { AUTO_MODEL, allowedModels, formatModelRef } from "../models.ts";
|
|
19
|
+
import { AUTO_MODEL, allowedModels, formatModelRef, type ModelRef } from "../models.ts";
|
|
20
20
|
import { definitionsDir, projectDefinitionsDir } from "../paths.ts";
|
|
21
21
|
import { REPORT_TOOL_NAME } from "../run/report-tool.ts";
|
|
22
22
|
import { ISOLATION_MODES, THINKING_LEVELS } from "../run/types.ts";
|
|
23
23
|
import type { SubagentSettings } from "./schema.ts";
|
|
24
|
+
import { defaultThinkingChoice, thinkingChoices } from "./thinking-choices.ts";
|
|
24
25
|
|
|
25
26
|
export interface AgentsMenuOptions {
|
|
26
27
|
/** The tools runs can select in the current session; undefined until it has started. */
|
|
@@ -68,7 +69,7 @@ export function agentsMenu(options: AgentsMenuOptions): SettingsMenuDefinition<S
|
|
|
68
69
|
.filter(Boolean)
|
|
69
70
|
.join(" · ");
|
|
70
71
|
},
|
|
71
|
-
open: ({ context, scope }): SettingsMenu => {
|
|
72
|
+
open: ({ context, scope, values }): SettingsMenu => {
|
|
72
73
|
const loaded = loadScope(context, scope);
|
|
73
74
|
|
|
74
75
|
return {
|
|
@@ -79,9 +80,16 @@ export function agentsMenu(options: AgentsMenuOptions): SettingsMenuDefinition<S
|
|
|
79
80
|
label: definition.name,
|
|
80
81
|
description: definition.description,
|
|
81
82
|
scopes: [scope],
|
|
82
|
-
summary: () => agentSummary(definition),
|
|
83
|
+
summary: () => agentSummary(definition, values),
|
|
83
84
|
menu: () => ({
|
|
84
|
-
fields: agentFields(
|
|
85
|
+
fields: agentFields(
|
|
86
|
+
definition,
|
|
87
|
+
loaded,
|
|
88
|
+
scope,
|
|
89
|
+
options,
|
|
90
|
+
edited,
|
|
91
|
+
values,
|
|
92
|
+
),
|
|
85
93
|
}),
|
|
86
94
|
}),
|
|
87
95
|
),
|
|
@@ -113,10 +121,13 @@ function loadScope(context: ExtensionContext, scope: SettingsScope): LoadedDefin
|
|
|
113
121
|
return loadDefinitions(scopeDir(context, scope), scope === "global" ? "user" : "project");
|
|
114
122
|
}
|
|
115
123
|
|
|
116
|
-
function agentSummary(definition: AgentDefinition): string {
|
|
124
|
+
function agentSummary(definition: AgentDefinition, values: DeepReadonly<SubagentSettings>): string {
|
|
117
125
|
return [
|
|
118
126
|
definition.model ?? "main model",
|
|
119
|
-
definition.thinking ??
|
|
127
|
+
definition.thinking ??
|
|
128
|
+
(definition.model === AUTO_MODEL && values.autoClassifier
|
|
129
|
+
? "automatic thinking"
|
|
130
|
+
: "main thinking"),
|
|
120
131
|
definition.tools ? count(definition.tools.length, "tool") : "default tools",
|
|
121
132
|
definition.isolation ?? "shared",
|
|
122
133
|
].join(" · ");
|
|
@@ -128,6 +139,7 @@ function agentFields(
|
|
|
128
139
|
scope: SettingsScope,
|
|
129
140
|
options: AgentsMenuOptions,
|
|
130
141
|
edited: (previousFile: string, definition: AgentDefinition) => void,
|
|
142
|
+
values: DeepReadonly<SubagentSettings>,
|
|
131
143
|
): SettingsPanelField[] {
|
|
132
144
|
const field = <T>(spec: {
|
|
133
145
|
id: DefinitionField;
|
|
@@ -214,31 +226,28 @@ function agentFields(
|
|
|
214
226
|
id: "model",
|
|
215
227
|
label: "Model",
|
|
216
228
|
description:
|
|
217
|
-
"A model of
|
|
218
|
-
"main agent's model.
|
|
229
|
+
"A model of the subagent allowed set, auto to route both model and thinking per " +
|
|
230
|
+
"task, or the main agent's model. Selecting auto removes any saved thinking " +
|
|
231
|
+
"level. Ctrl+R removes the model field.",
|
|
219
232
|
schema: nullable(Type.String({ minLength: 1 })),
|
|
220
233
|
editor: "select",
|
|
221
234
|
value: definition.model,
|
|
222
|
-
choiceSource: modelChoices(definition.model),
|
|
235
|
+
choiceSource: modelChoices(definition.model, values.allowedModels),
|
|
223
236
|
formatValue: (value) => value ?? "Main agent's model",
|
|
224
237
|
}),
|
|
225
238
|
field<string>({
|
|
226
239
|
id: "thinking",
|
|
227
240
|
label: "Thinking",
|
|
228
241
|
description:
|
|
229
|
-
|
|
242
|
+
definition.model === AUTO_MODEL
|
|
243
|
+
? "Model auto selects thinking for each task. Fixed levels require a fixed " +
|
|
244
|
+
"or inherited model."
|
|
245
|
+
: "Choose a supported level for the model. Ctrl+R removes the field.",
|
|
230
246
|
schema: nullable(Type.Union(THINKING_LEVELS.map((level) => Type.Literal(level)))),
|
|
231
247
|
editor: "select",
|
|
232
248
|
value: definition.thinking,
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
value: null,
|
|
236
|
-
label: "Main agent's thinking",
|
|
237
|
-
description: "Leave thinking out: runs use the main agent's level.",
|
|
238
|
-
},
|
|
239
|
-
...THINKING_LEVELS.map((level) => ({ value: level, label: level })),
|
|
240
|
-
],
|
|
241
|
-
formatValue: (value) => value ?? "Main agent's thinking",
|
|
249
|
+
choiceSource: thinkingChoices(definition.model, values, definition.thinking),
|
|
250
|
+
formatValue: (value) => value ?? defaultThinkingChoice(definition.model, values).label,
|
|
242
251
|
}),
|
|
243
252
|
field<string[]>({
|
|
244
253
|
id: "tools",
|
|
@@ -277,11 +286,14 @@ function agentFields(
|
|
|
277
286
|
];
|
|
278
287
|
}
|
|
279
288
|
|
|
280
|
-
function modelChoices(
|
|
289
|
+
function modelChoices(
|
|
290
|
+
current: string | undefined,
|
|
291
|
+
selection: readonly ModelRef[],
|
|
292
|
+
): SettingsChoiceSource<string | null> {
|
|
281
293
|
return {
|
|
282
294
|
rowLayout: "inline",
|
|
283
295
|
load: ({ context }) => {
|
|
284
|
-
const models = allowedModels(context);
|
|
296
|
+
const models = allowedModels(context, selection);
|
|
285
297
|
const refs = models.map((model) => formatModelRef(model));
|
|
286
298
|
|
|
287
299
|
return [
|
|
@@ -294,7 +306,8 @@ function modelChoices(current: string | undefined): SettingsChoiceSource<string
|
|
|
294
306
|
value: AUTO_MODEL,
|
|
295
307
|
label: AUTO_MODEL,
|
|
296
308
|
description:
|
|
297
|
-
"The classifier in the Subagents settings chooses
|
|
309
|
+
"The classifier in the Subagents settings chooses the model and thinking " +
|
|
310
|
+
"for each task. Selecting auto removes any saved thinking level.",
|
|
298
311
|
},
|
|
299
312
|
...models.map((model) => ({
|
|
300
313
|
value: formatModelRef(model),
|
|
@@ -310,7 +323,7 @@ function modelChoices(current: string | undefined): SettingsChoiceSource<string
|
|
|
310
323
|
label: current,
|
|
311
324
|
badge: "Not allowed",
|
|
312
325
|
description:
|
|
313
|
-
"Not in
|
|
326
|
+
"Not in the subagent allowed set now, so runs of this agent fail to start.",
|
|
314
327
|
},
|
|
315
328
|
]
|
|
316
329
|
: []),
|
package/src/settings/panel.ts
CHANGED
|
@@ -25,6 +25,30 @@ const classifierChoices: SettingsChoiceSource<ModelReference | null> = modelChoi
|
|
|
25
25
|
],
|
|
26
26
|
});
|
|
27
27
|
|
|
28
|
+
const allowedModelChoices = {
|
|
29
|
+
...modelChoices<"chat", ModelReference, SubagentSettings>({
|
|
30
|
+
scopes: ["scoped"],
|
|
31
|
+
emptyMessage: "No scoped models. Configure Pi's scoped models to select an override.",
|
|
32
|
+
specialChoices: ({ context, values }, models) => {
|
|
33
|
+
const scoped = new Set(models.map((model) => formatModelRef(model)));
|
|
34
|
+
const available = new Set(context.modelRegistry.getAvailable().map(formatModelRef));
|
|
35
|
+
|
|
36
|
+
return values.allowedModels
|
|
37
|
+
.filter((model) => !scoped.has(formatModelRef(model)))
|
|
38
|
+
.map((model) => ({
|
|
39
|
+
value: { provider: model.provider, id: model.id },
|
|
40
|
+
label: model.id,
|
|
41
|
+
badge: available.has(formatModelRef(model)) ? "Outside scope" : "Unavailable",
|
|
42
|
+
searchText: formatModelRef(model),
|
|
43
|
+
description: available.has(formatModelRef(model))
|
|
44
|
+
? `${formatModelRef(model)} remains allowed by this saved override. Uncheck to remove it.`
|
|
45
|
+
: `${formatModelRef(model)} is no longer available in Pi and cannot start a run. Uncheck to remove it.`,
|
|
46
|
+
}));
|
|
47
|
+
},
|
|
48
|
+
}),
|
|
49
|
+
multiple: true as const,
|
|
50
|
+
};
|
|
51
|
+
|
|
28
52
|
const TIERS: Record<AutoTier, { label: string; description: string }> = {
|
|
29
53
|
light: {
|
|
30
54
|
label: "Light",
|
|
@@ -51,7 +75,7 @@ function tierChoices(
|
|
|
51
75
|
return {
|
|
52
76
|
rowLayout: "inline",
|
|
53
77
|
load: ({ context, values }) => {
|
|
54
|
-
const models = allowedModels(context);
|
|
78
|
+
const models = allowedModels(context, values.allowedModels);
|
|
55
79
|
const allowed = new Set(models.map((model) => formatModelRef(model)));
|
|
56
80
|
const current = values.autoTiers[tier];
|
|
57
81
|
|
|
@@ -70,7 +94,7 @@ function tierChoices(
|
|
|
70
94
|
value: { provider: current.provider, id: current.id },
|
|
71
95
|
label: current.id,
|
|
72
96
|
badge: "Not allowed",
|
|
73
|
-
description: `${formatModelRef(current)} is not in
|
|
97
|
+
description: `${formatModelRef(current)} is not in the subagent allowed set now, so auto runs of this tier fail to start. Select another model.`,
|
|
74
98
|
},
|
|
75
99
|
]
|
|
76
100
|
: []),
|
|
@@ -90,16 +114,34 @@ export function createSubagentPanel(options: AgentsMenuOptions) {
|
|
|
90
114
|
id: "subagents",
|
|
91
115
|
label: "Subagents",
|
|
92
116
|
fields: (field) => [
|
|
117
|
+
field("allowedModels", {
|
|
118
|
+
label: "Allowed models",
|
|
119
|
+
description:
|
|
120
|
+
"Select models from Pi's scoped models. A nonempty selection replaces the " +
|
|
121
|
+
"session's allowed model list for new subagent runs; clear it to follow Pi's " +
|
|
122
|
+
"scope again. Space toggles, Enter saves. Inheriting the main agent's model " +
|
|
123
|
+
"is unchanged, and existing runs keep their model.",
|
|
124
|
+
formatValue: (value) =>
|
|
125
|
+
value.length > 0 ? `${value.length} selected` : "Default · Pi's model scope",
|
|
126
|
+
choiceSource: allowedModelChoices,
|
|
127
|
+
}),
|
|
93
128
|
field("autoClassifier", {
|
|
94
|
-
label: "
|
|
129
|
+
label: "Classifier model",
|
|
95
130
|
description:
|
|
96
|
-
"
|
|
97
|
-
"
|
|
98
|
-
"
|
|
131
|
+
"The Pi classifier that rates each task of a run started with model auto and " +
|
|
132
|
+
"picks both the model and thinking level. None: auto runs use the main " +
|
|
133
|
+
"session's model and thinking.",
|
|
99
134
|
formatValue: (value) =>
|
|
100
135
|
value ? `${value.provider}/${value.id}` : "None · main session model",
|
|
101
136
|
choiceSource: classifierChoices,
|
|
102
137
|
}),
|
|
138
|
+
field("autoOnly", {
|
|
139
|
+
label: "Auto mode only",
|
|
140
|
+
description:
|
|
141
|
+
"Inline runs always route both model and thinking: subagent_start has no " +
|
|
142
|
+
"model or thinking parameters, and explicit overrides fail. Custom agents " +
|
|
143
|
+
"keep their definition's model. Changes apply to the next start.",
|
|
144
|
+
}),
|
|
103
145
|
...AUTO_TIERS.map((tier) =>
|
|
104
146
|
field(["autoTiers", tier], {
|
|
105
147
|
label: TIERS[tier].label,
|
|
@@ -161,8 +203,8 @@ export function createSubagentPanel(options: AgentsMenuOptions) {
|
|
|
161
203
|
id: "tiers",
|
|
162
204
|
label: "Auto tiers",
|
|
163
205
|
description:
|
|
164
|
-
"The model for each task tier of runs started with model auto, from
|
|
165
|
-
"
|
|
206
|
+
"The model for each task tier of runs started with model auto, from the " +
|
|
207
|
+
"subagent allowed set. A tier without a model uses the next tier up that has one, " +
|
|
166
208
|
"and the main agent's model is the last step. The high-risk floor raises the " +
|
|
167
209
|
"model of tasks rated high risk.",
|
|
168
210
|
summary: ({ values }) => {
|
package/src/settings/schema.ts
CHANGED
|
@@ -14,6 +14,8 @@ const tierModel = () => Type.Union([Type.Null(), modelReference()], { default: n
|
|
|
14
14
|
|
|
15
15
|
export const subagentSchema = Type.Object(
|
|
16
16
|
{
|
|
17
|
+
allowedModels: Type.Array(modelReference(), { default: [], uniqueItems: true }),
|
|
18
|
+
autoOnly: Type.Boolean({ default: false }),
|
|
17
19
|
autoClassifier: Type.Union([Type.Null(), modelReference()], { default: null }),
|
|
18
20
|
autoTiers: Type.Object(
|
|
19
21
|
{ light: tierModel(), standard: tierModel(), complex: tierModel(), deep: tierModel() },
|
|
@@ -55,7 +57,9 @@ export const subagentSettings = defineSettings({
|
|
|
55
57
|
],
|
|
56
58
|
});
|
|
57
59
|
|
|
58
|
-
export function autoModelSettings(
|
|
60
|
+
export function autoModelSettings(
|
|
61
|
+
settings: DeepReadonly<Omit<SubagentSettings, "allowedModels" | "autoOnly">>,
|
|
62
|
+
): AutoModelSettings {
|
|
59
63
|
return {
|
|
60
64
|
classifier: settings.autoClassifier ? { ...settings.autoClassifier } : null,
|
|
61
65
|
tiers: Object.fromEntries(
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { ThinkingLevel } from "@earendil-works/pi-agent-core";
|
|
2
|
+
import { getSupportedThinkingLevels, type Api, type Model } from "@earendil-works/pi-ai";
|
|
3
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
import type { SettingsChoice, SettingsChoiceSource } from "@lune_99/pi-lune-extensions-core/panel";
|
|
5
|
+
import type { DeepReadonly } from "@lune_99/pi-lune-extensions-core/settings";
|
|
6
|
+
|
|
7
|
+
import { AUTO_MODEL, allowedModels, formatModelRef } from "../models.ts";
|
|
8
|
+
import type { SubagentSettings } from "./schema.ts";
|
|
9
|
+
|
|
10
|
+
export function defaultThinkingChoice(
|
|
11
|
+
model: string | undefined,
|
|
12
|
+
values: DeepReadonly<SubagentSettings>,
|
|
13
|
+
): SettingsChoice<ThinkingLevel | null> {
|
|
14
|
+
return model === AUTO_MODEL && values.autoClassifier
|
|
15
|
+
? {
|
|
16
|
+
value: null,
|
|
17
|
+
label: "Automatic thinking",
|
|
18
|
+
description:
|
|
19
|
+
"Leave thinking out: the classifier chooses a supported level for each task. " +
|
|
20
|
+
"If classification fails, runs use the main agent's thinking.",
|
|
21
|
+
}
|
|
22
|
+
: {
|
|
23
|
+
value: null,
|
|
24
|
+
label: "Main agent's thinking",
|
|
25
|
+
description:
|
|
26
|
+
"Leave thinking out: runs use the main agent's level within model limits.",
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function thinkingChoices(
|
|
31
|
+
model: string | undefined,
|
|
32
|
+
values: DeepReadonly<SubagentSettings>,
|
|
33
|
+
current?: ThinkingLevel,
|
|
34
|
+
): SettingsChoiceSource<ThinkingLevel | null> {
|
|
35
|
+
return {
|
|
36
|
+
load: ({ context }) => {
|
|
37
|
+
const fallback = defaultThinkingChoice(model, values);
|
|
38
|
+
|
|
39
|
+
if (model === AUTO_MODEL) {
|
|
40
|
+
return [fallback];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const levels = getSupportedThinkingLevels(thinkingModel(context, model, values));
|
|
44
|
+
|
|
45
|
+
return [
|
|
46
|
+
fallback,
|
|
47
|
+
...levels.map((level) => ({ value: level, label: level })),
|
|
48
|
+
...(current !== undefined && !levels.includes(current)
|
|
49
|
+
? [
|
|
50
|
+
{
|
|
51
|
+
value: current,
|
|
52
|
+
label: `${current} · saved, unsupported`,
|
|
53
|
+
disabled:
|
|
54
|
+
"This saved level is not supported by the current model selection. " +
|
|
55
|
+
"Choose another level or remove the override.",
|
|
56
|
+
},
|
|
57
|
+
]
|
|
58
|
+
: []),
|
|
59
|
+
];
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function thinkingModel(
|
|
65
|
+
context: ExtensionContext,
|
|
66
|
+
model: string | undefined,
|
|
67
|
+
values: DeepReadonly<SubagentSettings>,
|
|
68
|
+
): Model<Api> {
|
|
69
|
+
const allowed = (): Model<Api>[] => allowedModels(context, values.allowedModels);
|
|
70
|
+
const selected = (ref: string, models: readonly Model<Api>[]): Model<Api> => {
|
|
71
|
+
const found = models.find((each) => formatModelRef(each) === ref);
|
|
72
|
+
|
|
73
|
+
if (!found) {
|
|
74
|
+
throw new Error(
|
|
75
|
+
`The model ${ref} is unavailable or not in the subagent allowed set. ` +
|
|
76
|
+
"Select an available model before choosing thinking.",
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return found;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
if (model !== undefined && model !== AUTO_MODEL) {
|
|
84
|
+
return selected(model, allowed());
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (!context.model) {
|
|
88
|
+
throw new Error("The main agent has no current model for thinking choices.");
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return context.model;
|
|
92
|
+
}
|
package/src/tools/format.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { userMessageHeading } from "../run/guide.ts";
|
|
1
2
|
import type { Run } from "../run/run.ts";
|
|
2
3
|
import type { AutoRating, AutoRisk, RunSnapshot, RunUsage, TurnRecord } from "../run/types.ts";
|
|
3
4
|
|
|
@@ -108,56 +109,19 @@ export function riskText(risk: AutoRisk): string {
|
|
|
108
109
|
: `not high risk (${formatPercent(risk.probability)})`;
|
|
109
110
|
}
|
|
110
111
|
|
|
111
|
-
/** One entry of a `tasks` call: the run it started, or why it did not start. */
|
|
112
|
-
export type StartOutcome = { run: Run } | { error: string };
|
|
113
|
-
|
|
114
112
|
export function formatStarted(run: Run): string {
|
|
115
113
|
return [
|
|
116
114
|
startedHeading(run),
|
|
115
|
+
...titleLines(run),
|
|
117
116
|
...startValueLines(run),
|
|
118
117
|
...workspaceLines(run),
|
|
119
118
|
"The run works in the background. A message arrives when its turn ends.",
|
|
120
119
|
].join("\n");
|
|
121
120
|
}
|
|
122
121
|
|
|
123
|
-
/** A `tasks` call: a summary, then one block per entry, named by its index in `tasks`. */
|
|
124
|
-
export function formatStartedBatch(outcomes: readonly StartOutcome[]): string {
|
|
125
|
-
const started = outcomes.flatMap((outcome) => ("run" in outcome ? [outcome.run] : []));
|
|
126
|
-
const failed = outcomes.flatMap((outcome, index) =>
|
|
127
|
-
"error" in outcome ? [`tasks[${index}]`] : [],
|
|
128
|
-
);
|
|
129
|
-
const blocks = outcomes.map((outcome, index) =>
|
|
130
|
-
"error" in outcome
|
|
131
|
-
? `tasks[${index}] failed: ${outcome.error}`
|
|
132
|
-
: [
|
|
133
|
-
`tasks[${index}]: ${startedHeading(outcome.run)}`,
|
|
134
|
-
...startValueLines(outcome.run),
|
|
135
|
-
...workspaceLines(outcome.run),
|
|
136
|
-
].join("\n"),
|
|
137
|
-
);
|
|
138
|
-
|
|
139
|
-
if (started.length === 0) {
|
|
140
|
-
return ["No run started; every entry of tasks failed.", ...blocks].join("\n\n");
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const count = started.length === outcomes.length ? "" : `${started.length} of `;
|
|
144
|
-
const summary =
|
|
145
|
-
`Started ${count}${outcomes.length} run${outcomes.length === 1 ? "" : "s"}: ` +
|
|
146
|
-
`${started.map((run) => `${run.name} (${run.id})`).join(", ")}.` +
|
|
147
|
-
(failed.length > 0 ? ` Failed: ${failed.join(", ")}.` : "");
|
|
148
|
-
|
|
149
|
-
return [
|
|
150
|
-
summary,
|
|
151
|
-
...blocks,
|
|
152
|
-
started.length === 1
|
|
153
|
-
? "The run works in the background. A message arrives when its turn ends."
|
|
154
|
-
: "The runs work in the background. A message arrives when each run's turn ends.",
|
|
155
|
-
].join("\n\n");
|
|
156
|
-
}
|
|
157
|
-
|
|
158
122
|
/** One run in full: everything `subagent_status` knows, the last turn's whole report included. */
|
|
159
123
|
export function formatRunStatus(run: Run): string {
|
|
160
|
-
const lines = [heading(run)];
|
|
124
|
+
const lines = [heading(run), ...titleLines(run)];
|
|
161
125
|
|
|
162
126
|
if (run.loadError) {
|
|
163
127
|
lines.push(`The run file could not be read: ${run.loadError}`);
|
|
@@ -169,6 +133,7 @@ export function formatRunStatus(run: Run): string {
|
|
|
169
133
|
lines.push(`Turns: ${run.turns}`, `Usage: ${formatUsage(run.usage)}`);
|
|
170
134
|
lines.push(...runningLines(run));
|
|
171
135
|
lines.push(...diagnosticLines(run));
|
|
136
|
+
lines.push(...currentUserLines(run, false));
|
|
172
137
|
lines.push("", "Task:", run.snapshot?.task ?? "");
|
|
173
138
|
|
|
174
139
|
if (run.lastTurn) {
|
|
@@ -187,10 +152,12 @@ export function formatRunList(runs: readonly Run[], elsewhere: number): string {
|
|
|
187
152
|
|
|
188
153
|
return [
|
|
189
154
|
heading(run),
|
|
155
|
+
...titleLines(run),
|
|
190
156
|
...startValueLines(run).slice(0, 1),
|
|
191
157
|
...workspaceLines(run),
|
|
192
158
|
`Turns: ${run.turns} · Usage: ${formatUsage(run.usage)}`,
|
|
193
159
|
...runningLines(run),
|
|
160
|
+
...currentUserLines(run, true),
|
|
194
161
|
...diagnosticLines(run),
|
|
195
162
|
...(run.lastTurn ? turnLines(run.lastTurn, true) : []),
|
|
196
163
|
].join("\n");
|
|
@@ -259,11 +226,18 @@ export function formatPercent(value: number): string {
|
|
|
259
226
|
}
|
|
260
227
|
|
|
261
228
|
function heading(run: Run): string {
|
|
262
|
-
return `Run ${run.
|
|
229
|
+
return `Run ${run.id}: ${run.state}${run.readOnly ? ", read-only" : ""}`;
|
|
263
230
|
}
|
|
264
231
|
|
|
265
232
|
function startedHeading(run: Run): string {
|
|
266
|
-
return `Started run ${run.
|
|
233
|
+
return `Started run ${run.id}: ${run.state}.`;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** The user-facing title stays out of the handle position, so it cannot be read as a run ID. */
|
|
237
|
+
function titleLines(run: Run): string[] {
|
|
238
|
+
const title = run.snapshot?.title;
|
|
239
|
+
|
|
240
|
+
return title === undefined ? [] : [`Title: ${title}`];
|
|
267
241
|
}
|
|
268
242
|
|
|
269
243
|
function runningLines(run: Run): string[] {
|
|
@@ -285,6 +259,45 @@ function runningLines(run: Run): string[] {
|
|
|
285
259
|
return lines;
|
|
286
260
|
}
|
|
287
261
|
|
|
262
|
+
/** What the user wrote during the turn in progress, which no notice has carried yet. */
|
|
263
|
+
function currentUserLines(run: Run, preview: boolean): string[] {
|
|
264
|
+
const messages = run.turnUserMessages;
|
|
265
|
+
|
|
266
|
+
if (messages.length === 0) {
|
|
267
|
+
return [];
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
const lines = [
|
|
271
|
+
"The user wrote to the run during this turn.",
|
|
272
|
+
...userMessageLines(messages, preview),
|
|
273
|
+
];
|
|
274
|
+
|
|
275
|
+
return preview ? lines : ["", ...lines];
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** Every message in full, each after a blank line, or the last one as a preview. */
|
|
279
|
+
function userMessageLines(messages: readonly string[], preview: boolean): string[] {
|
|
280
|
+
if (!preview) {
|
|
281
|
+
return messages.flatMap((text, index) => [
|
|
282
|
+
"",
|
|
283
|
+
userMessageHeading(index, messages.length),
|
|
284
|
+
text,
|
|
285
|
+
]);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const last = messages.at(-1);
|
|
289
|
+
|
|
290
|
+
if (last === undefined) {
|
|
291
|
+
return [];
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
return [
|
|
295
|
+
messages.length === 1
|
|
296
|
+
? `User message: ${clip(last)}`
|
|
297
|
+
: `User messages: ${messages.length}, the last: ${clip(last)}`,
|
|
298
|
+
];
|
|
299
|
+
}
|
|
300
|
+
|
|
288
301
|
function diagnosticLines(run: Run): string[] {
|
|
289
302
|
const shown = run.diagnostics
|
|
290
303
|
.filter((diagnostic) => diagnostic.level !== "info")
|
|
@@ -312,7 +325,16 @@ function turnLines(turn: TurnRecord, preview: boolean): string[] {
|
|
|
312
325
|
}
|
|
313
326
|
|
|
314
327
|
if (turn.userWrote) {
|
|
315
|
-
|
|
328
|
+
const messages = turn.userMessages ?? [];
|
|
329
|
+
|
|
330
|
+
lines.push(
|
|
331
|
+
"The user wrote to the run during that turn.",
|
|
332
|
+
...userMessageLines(messages, preview),
|
|
333
|
+
);
|
|
334
|
+
|
|
335
|
+
if (!preview && messages.length > 0) {
|
|
336
|
+
lines.push("");
|
|
337
|
+
}
|
|
316
338
|
}
|
|
317
339
|
|
|
318
340
|
if (turn.error) {
|
|
@@ -356,7 +378,7 @@ function turnLines(turn: TurnRecord, preview: boolean): string[] {
|
|
|
356
378
|
} else {
|
|
357
379
|
const message = turn.unreportedMessage ?? "";
|
|
358
380
|
|
|
359
|
-
lines.push("
|
|
381
|
+
lines.push("No task status: the turn ended without a report.");
|
|
360
382
|
|
|
361
383
|
if (preview) {
|
|
362
384
|
lines.push(`Last message: ${message === "" ? "none" : clip(message)}`);
|