@chosengeneration/light-code 0.50.0 → 0.59.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/dist/cli.js +1140 -173
- package/dist/client/client.js +69 -69
- package/dist/server.js +1139 -172
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -39569,6 +39569,33 @@ var providerProfileSchema = external_exports.object({
|
|
|
39569
39569
|
* a working fallback in the adapter rather than being mandatory here.
|
|
39570
39570
|
*/
|
|
39571
39571
|
maxTokens: external_exports.number().int().positive().optional(),
|
|
39572
|
+
/**
|
|
39573
|
+
* Sampling, sent only when set.
|
|
39574
|
+
*
|
|
39575
|
+
* Absent means the server's default, which is what every request used before this existed. That
|
|
39576
|
+
* default is frequently 1.0, and on a mid-size model a high temperature is felt most sharply in
|
|
39577
|
+
* the one place it is least wanted: tool calls. A model that has to emit exactly
|
|
39578
|
+
* `{"path":"src/a.ts"}` and is sampling freely produces a plausible-looking argument that is
|
|
39579
|
+
* subtly wrong, and the failure surfaces as a tool error rather than as anything pointing at
|
|
39580
|
+
* sampling. Large models absorb this; smaller ones do not.
|
|
39581
|
+
*
|
|
39582
|
+
* Not given a default here, because a default would apply to every profile including the ones
|
|
39583
|
+
* that are fine, and silently changing how somebody's working model behaves is worse than
|
|
39584
|
+
* leaving a setting unset.
|
|
39585
|
+
*/
|
|
39586
|
+
temperature: external_exports.number().min(0).max(2).optional(),
|
|
39587
|
+
topP: external_exports.number().min(0).max(1).optional(),
|
|
39588
|
+
/**
|
|
39589
|
+
* How hard this model should think, translated per wire format by `providers/thinking.ts`.
|
|
39590
|
+
*
|
|
39591
|
+
* Absent sends nothing, which is what every request did before this existed and the only
|
|
39592
|
+
* setting that cannot break a gateway nobody has tested against.
|
|
39593
|
+
*/
|
|
39594
|
+
thinking: external_exports.object({
|
|
39595
|
+
level: external_exports.enum(["off", "low", "medium", "high"]),
|
|
39596
|
+
/** Only consulted for the OpenAI wire format, where the parameter is genuinely ambiguous. */
|
|
39597
|
+
style: external_exports.enum(["effort", "qwen"]).optional()
|
|
39598
|
+
}).optional(),
|
|
39572
39599
|
/**
|
|
39573
39600
|
* Per-profile corrections to the local capability table (§9). Needed because gateway
|
|
39574
39601
|
* aliases hide the underlying model, so the table cannot recognise them.
|
|
@@ -39663,7 +39690,41 @@ var agentAssignmentSchema = external_exports.object({
|
|
|
39663
39690
|
* has looked at the tab without editing anything. Storing the default verbatim would pin
|
|
39664
39691
|
* every user to whatever it said the day they first opened it.
|
|
39665
39692
|
*/
|
|
39666
|
-
prompt: external_exports.string().optional()
|
|
39693
|
+
prompt: external_exports.string().optional(),
|
|
39694
|
+
/**
|
|
39695
|
+
* Whether this specialist may read and search the workspace, overriding the role's default.
|
|
39696
|
+
*
|
|
39697
|
+
* On the assignment rather than the role because it depends on *who* is answering: a small
|
|
39698
|
+
* local model given five lookups can spend them all and answer worse, where a strong one
|
|
39699
|
+
* uses them well. Absent means the role's own default.
|
|
39700
|
+
*/
|
|
39701
|
+
tools: external_exports.boolean().optional(),
|
|
39702
|
+
/**
|
|
39703
|
+
* Whether this specialist may change things, each change through the approval gate.
|
|
39704
|
+
*
|
|
39705
|
+
* Off by default everywhere. §12b's rule is that a consultant is read-only; this is the
|
|
39706
|
+
* deliberate exception, and it is per role because "the programmer may edit" and "the tester
|
|
39707
|
+
* may edit" are quite different decisions.
|
|
39708
|
+
*/
|
|
39709
|
+
write: external_exports.boolean().optional(),
|
|
39710
|
+
/**
|
|
39711
|
+
* Whether this role is in play at all.
|
|
39712
|
+
*
|
|
39713
|
+
* Distinct from unassigning it, which is why both exist: unassigning forgets *who* answered,
|
|
39714
|
+
* and somebody switching a specialist off for one job does not want to lose the model, the
|
|
39715
|
+
* prompt and the flags they set up. Absent means on, so nothing changes for a config written
|
|
39716
|
+
* before this.
|
|
39717
|
+
*/
|
|
39718
|
+
enabled: external_exports.boolean().optional(),
|
|
39719
|
+
/**
|
|
39720
|
+
* How hard this seat should think, overriding whatever its profile says.
|
|
39721
|
+
*
|
|
39722
|
+
* On the assignment because it belongs to the *job*, not to the model: the same Qwen is worth
|
|
39723
|
+
* thinking hard as the expert, where it is planning a change across files, and worth answering
|
|
39724
|
+
* quickly as the librarian, where it is reading back what is written down. One profile, two
|
|
39725
|
+
* seats, two settings.
|
|
39726
|
+
*/
|
|
39727
|
+
thinking: external_exports.enum(["off", "low", "medium", "high"]).optional()
|
|
39667
39728
|
}).strict();
|
|
39668
39729
|
var customRoleSchema = external_exports.object({
|
|
39669
39730
|
id: external_exports.string().min(1),
|
|
@@ -39711,6 +39772,20 @@ var workspaceApprovalsSchema = external_exports.object({
|
|
|
39711
39772
|
/** Exact command strings — never patterns. See approval/commands.ts and §8. */
|
|
39712
39773
|
allowedCommands: external_exports.array(external_exports.string())
|
|
39713
39774
|
}).partial();
|
|
39775
|
+
var juniorAssessmentSchema = external_exports.object({
|
|
39776
|
+
model: external_exports.string(),
|
|
39777
|
+
profileLabel: external_exports.string(),
|
|
39778
|
+
assessedAt: external_exports.number(),
|
|
39779
|
+
verdict: external_exports.string(),
|
|
39780
|
+
costUsd: external_exports.number().optional(),
|
|
39781
|
+
probes: external_exports.array(external_exports.object({
|
|
39782
|
+
id: external_exports.string(),
|
|
39783
|
+
measures: external_exports.string(),
|
|
39784
|
+
prompt: external_exports.string(),
|
|
39785
|
+
answer: external_exports.string(),
|
|
39786
|
+
error: external_exports.string().optional()
|
|
39787
|
+
}))
|
|
39788
|
+
});
|
|
39714
39789
|
var expertConfigSchema = external_exports.object({
|
|
39715
39790
|
/** Off unless explicitly enabled. Nothing is spawned or spent without this. */
|
|
39716
39791
|
enabled: external_exports.boolean(),
|
|
@@ -39743,20 +39818,16 @@ var expertConfigSchema = external_exports.object({
|
|
|
39743
39818
|
* there is one, for the model that was assessed, and it records which that was so a stale
|
|
39744
39819
|
* one is recognisable rather than silently applied to a different model.
|
|
39745
39820
|
*/
|
|
39746
|
-
assessment:
|
|
39747
|
-
|
|
39748
|
-
|
|
39749
|
-
|
|
39750
|
-
|
|
39751
|
-
|
|
39752
|
-
|
|
39753
|
-
|
|
39754
|
-
|
|
39755
|
-
|
|
39756
|
-
answer: external_exports.string(),
|
|
39757
|
-
error: external_exports.string().optional()
|
|
39758
|
-
}))
|
|
39759
|
-
}).optional(),
|
|
39821
|
+
assessment: juniorAssessmentSchema.optional(),
|
|
39822
|
+
/**
|
|
39823
|
+
* Every model assessed, so several can be compared.
|
|
39824
|
+
*
|
|
39825
|
+
* One slot answers "is this model any good"; deciding which of four models reviews and which
|
|
39826
|
+
* writes needs them side by side, and assessing the second used to destroy the evidence about
|
|
39827
|
+
* the first. Read through `expert/assessments.ts`, never directly, so this and the single
|
|
39828
|
+
* `assessment` above cannot come apart.
|
|
39829
|
+
*/
|
|
39830
|
+
assessments: external_exports.array(juniorAssessmentSchema).optional(),
|
|
39760
39831
|
/**
|
|
39761
39832
|
* Consultations allowed within one task. 0 means no limit.
|
|
39762
39833
|
*
|
|
@@ -42180,6 +42251,98 @@ function normalizeObjectSchema(parameters) {
|
|
|
42180
42251
|
return normalized;
|
|
42181
42252
|
}
|
|
42182
42253
|
|
|
42254
|
+
// ../../packages/core/dist/providers/thinking.js
|
|
42255
|
+
var BUDGETS = {
|
|
42256
|
+
low: 2048,
|
|
42257
|
+
medium: 8192,
|
|
42258
|
+
high: 24576
|
|
42259
|
+
};
|
|
42260
|
+
function applyThinking(body, wireFormat, settings, maxTokens) {
|
|
42261
|
+
if (settings === void 0)
|
|
42262
|
+
return;
|
|
42263
|
+
if (wireFormat === "anthropic") {
|
|
42264
|
+
if (settings.level === "off")
|
|
42265
|
+
return;
|
|
42266
|
+
const ceiling = maxTokens !== void 0 ? Math.max(1024, maxTokens - 1024) : Infinity;
|
|
42267
|
+
body.thinking = {
|
|
42268
|
+
type: "enabled",
|
|
42269
|
+
budget_tokens: Math.min(BUDGETS[settings.level], ceiling)
|
|
42270
|
+
};
|
|
42271
|
+
return;
|
|
42272
|
+
}
|
|
42273
|
+
if (wireFormat === "gemini") {
|
|
42274
|
+
body.thinkingConfig = {
|
|
42275
|
+
thinkingBudget: settings.level === "off" ? 0 : BUDGETS[settings.level]
|
|
42276
|
+
};
|
|
42277
|
+
return;
|
|
42278
|
+
}
|
|
42279
|
+
if (settings.style === "qwen") {
|
|
42280
|
+
body.chat_template_kwargs = { enable_thinking: settings.level !== "off" };
|
|
42281
|
+
return;
|
|
42282
|
+
}
|
|
42283
|
+
if (settings.level === "off")
|
|
42284
|
+
return;
|
|
42285
|
+
body.reasoning_effort = settings.level;
|
|
42286
|
+
}
|
|
42287
|
+
|
|
42288
|
+
// ../../packages/core/dist/providers/thinkTags.js
|
|
42289
|
+
var OPEN = "<think>";
|
|
42290
|
+
var CLOSE = "</think>";
|
|
42291
|
+
var ThinkTagSplitter = class {
|
|
42292
|
+
inside = false;
|
|
42293
|
+
/** A partial tag held back until the next chunk says what it is. */
|
|
42294
|
+
pending = "";
|
|
42295
|
+
push(chunk) {
|
|
42296
|
+
let text = "";
|
|
42297
|
+
let reasoning = "";
|
|
42298
|
+
let buffer = this.pending + chunk;
|
|
42299
|
+
this.pending = "";
|
|
42300
|
+
for (; ; ) {
|
|
42301
|
+
const marker = this.inside ? CLOSE : OPEN;
|
|
42302
|
+
const at = buffer.indexOf(marker);
|
|
42303
|
+
if (at !== -1) {
|
|
42304
|
+
const before = buffer.slice(0, at);
|
|
42305
|
+
if (this.inside)
|
|
42306
|
+
reasoning += before;
|
|
42307
|
+
else
|
|
42308
|
+
text += before;
|
|
42309
|
+
this.inside = !this.inside;
|
|
42310
|
+
buffer = buffer.slice(at + marker.length);
|
|
42311
|
+
continue;
|
|
42312
|
+
}
|
|
42313
|
+
const keep = partialMarkerLength(buffer, marker);
|
|
42314
|
+
const usable = buffer.slice(0, buffer.length - keep);
|
|
42315
|
+
this.pending = buffer.slice(buffer.length - keep);
|
|
42316
|
+
if (this.inside)
|
|
42317
|
+
reasoning += usable;
|
|
42318
|
+
else
|
|
42319
|
+
text += usable;
|
|
42320
|
+
break;
|
|
42321
|
+
}
|
|
42322
|
+
return { text, reasoning };
|
|
42323
|
+
}
|
|
42324
|
+
/**
|
|
42325
|
+
* Whatever is still held back when the stream ends.
|
|
42326
|
+
*
|
|
42327
|
+
* A truncated stream can leave a partial tag, or an unclosed `<think>`. Emitting the remainder
|
|
42328
|
+
* rather than dropping it means a cut-off reply still shows what there was — losing the end of
|
|
42329
|
+
* an answer to a tag that never closed would be a worse failure than showing a stray `<`.
|
|
42330
|
+
*/
|
|
42331
|
+
flush() {
|
|
42332
|
+
const rest = this.pending;
|
|
42333
|
+
this.pending = "";
|
|
42334
|
+
return this.inside ? { text: "", reasoning: rest } : { text: rest, reasoning: "" };
|
|
42335
|
+
}
|
|
42336
|
+
};
|
|
42337
|
+
function partialMarkerLength(buffer, marker) {
|
|
42338
|
+
const most = Math.min(marker.length - 1, buffer.length);
|
|
42339
|
+
for (let length = most; length > 0; length -= 1) {
|
|
42340
|
+
if (marker.startsWith(buffer.slice(buffer.length - length)))
|
|
42341
|
+
return length;
|
|
42342
|
+
}
|
|
42343
|
+
return 0;
|
|
42344
|
+
}
|
|
42345
|
+
|
|
42183
42346
|
// ../../packages/core/dist/providers/openai.js
|
|
42184
42347
|
function describeRequestError(error51, url2) {
|
|
42185
42348
|
return `Could not reach ${url2}: ${describeTlsError(error51)}`;
|
|
@@ -42234,6 +42397,11 @@ var OpenAIProvider = class {
|
|
|
42234
42397
|
body.tools = toOpenAITools(options.tools);
|
|
42235
42398
|
body.tool_choice = "auto";
|
|
42236
42399
|
}
|
|
42400
|
+
if (this.profile.temperature !== void 0)
|
|
42401
|
+
body.temperature = this.profile.temperature;
|
|
42402
|
+
if (this.profile.topP !== void 0)
|
|
42403
|
+
body.top_p = this.profile.topP;
|
|
42404
|
+
applyThinking(body, "openai", this.profile.thinking, this.profile.maxTokens);
|
|
42237
42405
|
let response;
|
|
42238
42406
|
try {
|
|
42239
42407
|
await this.auth.ensureTokenForStream?.();
|
|
@@ -42318,6 +42486,7 @@ async function* parseSseStream(body, url2, signal, logger) {
|
|
|
42318
42486
|
const reader = body.getReader();
|
|
42319
42487
|
const decoder = new TextDecoder();
|
|
42320
42488
|
let buffer = "";
|
|
42489
|
+
const thinking = new ThinkTagSplitter();
|
|
42321
42490
|
const toolCallAccumulators = /* @__PURE__ */ new Map();
|
|
42322
42491
|
try {
|
|
42323
42492
|
while (true) {
|
|
@@ -42348,7 +42517,11 @@ async function* parseSseStream(body, url2, signal, logger) {
|
|
|
42348
42517
|
yield { type: "reasoning", text: reasoning };
|
|
42349
42518
|
}
|
|
42350
42519
|
if (typeof choice.delta.content === "string" && choice.delta.content.length > 0) {
|
|
42351
|
-
|
|
42520
|
+
const split = thinking.push(choice.delta.content);
|
|
42521
|
+
if (split.reasoning.length > 0)
|
|
42522
|
+
yield { type: "reasoning", text: split.reasoning };
|
|
42523
|
+
if (split.text.length > 0)
|
|
42524
|
+
yield { type: "text", text: split.text };
|
|
42352
42525
|
}
|
|
42353
42526
|
accumulateToolCallDeltas(toolCallAccumulators, choice.delta.tool_calls);
|
|
42354
42527
|
if (choice.finishReason === "tool_calls") {
|
|
@@ -42400,6 +42573,11 @@ var AnthropicProvider = class {
|
|
|
42400
42573
|
};
|
|
42401
42574
|
if (system !== void 0)
|
|
42402
42575
|
body.system = system;
|
|
42576
|
+
if (this.profile.temperature !== void 0)
|
|
42577
|
+
body.temperature = this.profile.temperature;
|
|
42578
|
+
if (this.profile.topP !== void 0)
|
|
42579
|
+
body.top_p = this.profile.topP;
|
|
42580
|
+
applyThinking(body, "anthropic", this.profile.thinking, this.profile.maxTokens ?? DEFAULT_MAX_TOKENS);
|
|
42403
42581
|
if (options.tools !== void 0 && options.tools.length > 0) {
|
|
42404
42582
|
body.tools = toAnthropicTools(options.tools);
|
|
42405
42583
|
}
|
|
@@ -42625,6 +42803,21 @@ var GeminiProvider = class {
|
|
|
42625
42803
|
if (this.profile.maxTokens !== void 0) {
|
|
42626
42804
|
body.generationConfig = { maxOutputTokens: this.profile.maxTokens };
|
|
42627
42805
|
}
|
|
42806
|
+
if (this.profile.temperature !== void 0 || this.profile.topP !== void 0) {
|
|
42807
|
+
body.generationConfig = {
|
|
42808
|
+
...body.generationConfig ?? {},
|
|
42809
|
+
...this.profile.temperature !== void 0 ? { temperature: this.profile.temperature } : {},
|
|
42810
|
+
...this.profile.topP !== void 0 ? { topP: this.profile.topP } : {}
|
|
42811
|
+
};
|
|
42812
|
+
}
|
|
42813
|
+
applyThinking(body, "gemini", this.profile.thinking, this.profile.maxTokens);
|
|
42814
|
+
if (body.thinkingConfig !== void 0) {
|
|
42815
|
+
body.generationConfig = {
|
|
42816
|
+
...body.generationConfig ?? {},
|
|
42817
|
+
thinkingConfig: body.thinkingConfig
|
|
42818
|
+
};
|
|
42819
|
+
delete body.thinkingConfig;
|
|
42820
|
+
}
|
|
42628
42821
|
let response;
|
|
42629
42822
|
try {
|
|
42630
42823
|
await this.auth.ensureTokenForStream?.();
|
|
@@ -43249,6 +43442,11 @@ var Conversation = class {
|
|
|
43249
43442
|
|
|
43250
43443
|
// ../../packages/core/dist/agents/roles.js
|
|
43251
43444
|
var AGENT_ROLES = ["expert", "programmer", "reviewer", "tester", "librarian"];
|
|
43445
|
+
var CUSTOM_ROLE_LIMIT = 5;
|
|
43446
|
+
var ROLE_ID = /^[a-z][a-z0-9-]{1,23}$/;
|
|
43447
|
+
function isValidRoleId(id) {
|
|
43448
|
+
return ROLE_ID.test(id) && !AGENT_ROLES.includes(id);
|
|
43449
|
+
}
|
|
43252
43450
|
function isAgentRole(value, custom2 = []) {
|
|
43253
43451
|
return AGENT_ROLES.includes(value) || custom2.some((role) => role.id === value);
|
|
43254
43452
|
}
|
|
@@ -43262,6 +43460,13 @@ var SHARED_TAIL = [
|
|
|
43262
43460
|
"",
|
|
43263
43461
|
"Answer in prose and short lists. No preamble about being happy to help."
|
|
43264
43462
|
];
|
|
43463
|
+
var MAY_WRITE = [
|
|
43464
|
+
"",
|
|
43465
|
+
"You can also change this workspace: edit files, and record a skill. Every such change is shown",
|
|
43466
|
+
"to the user and approved by them before it happens, so make each one small enough to read and",
|
|
43467
|
+
"say what it is for. Prefer telling the assistant what to change where the change is large or",
|
|
43468
|
+
"spans files \u2014 it has the whole picture and you have only what you asked for."
|
|
43469
|
+
].join("\n");
|
|
43265
43470
|
var SHARED_WITH_TOOLS = [
|
|
43266
43471
|
"You can read this workspace: open files, list them, and search. Use that rather than guessing,",
|
|
43267
43472
|
"and rather than asking the assistant for something you can fetch yourself. You have a small",
|
|
@@ -43279,8 +43484,9 @@ var SHARED_BLIND = [
|
|
|
43279
43484
|
"",
|
|
43280
43485
|
...SHARED_TAIL
|
|
43281
43486
|
].join("\n");
|
|
43282
|
-
function specialistPreamble(usesTools) {
|
|
43283
|
-
|
|
43487
|
+
function specialistPreamble(usesTools, canWrite = false) {
|
|
43488
|
+
const base = usesTools ? SHARED_WITH_TOOLS : SHARED_BLIND;
|
|
43489
|
+
return canWrite ? `${base}${MAY_WRITE}` : base;
|
|
43284
43490
|
}
|
|
43285
43491
|
var DEFINITIONS = {
|
|
43286
43492
|
expert: {
|
|
@@ -43289,6 +43495,7 @@ var DEFINITIONS = {
|
|
|
43289
43495
|
/* Planning a change means knowing what is already there, and it spans files the asker
|
|
43290
43496
|
* cannot paste all of. */
|
|
43291
43497
|
usesTools: true,
|
|
43498
|
+
canWrite: false,
|
|
43292
43499
|
prompt: [
|
|
43293
43500
|
"You are a senior engineer being consulted by another AI assistant that is doing the work.",
|
|
43294
43501
|
"",
|
|
@@ -43306,6 +43513,7 @@ var DEFINITIONS = {
|
|
|
43306
43513
|
/* It is handed a spec and the surrounding code and asked to write. Looking around buys
|
|
43307
43514
|
* a slower answer that is no better. */
|
|
43308
43515
|
usesTools: false,
|
|
43516
|
+
canWrite: false,
|
|
43309
43517
|
prompt: [
|
|
43310
43518
|
"You are an experienced programmer writing code for another AI assistant to apply.",
|
|
43311
43519
|
"",
|
|
@@ -43336,6 +43544,7 @@ var DEFINITIONS = {
|
|
|
43336
43544
|
/* Most of what a review turns on is *around* the diff — the callers, the neighbouring
|
|
43337
43545
|
* function, whether this convention is really the convention. */
|
|
43338
43546
|
usesTools: true,
|
|
43547
|
+
canWrite: false,
|
|
43339
43548
|
prompt: [
|
|
43340
43549
|
"You are reviewing a change written by another AI assistant.",
|
|
43341
43550
|
"",
|
|
@@ -43363,6 +43572,7 @@ var DEFINITIONS = {
|
|
|
43363
43572
|
/* The change is in front of it and the cases come from reasoning about it, not from
|
|
43364
43573
|
* reading more of the codebase. */
|
|
43365
43574
|
usesTools: false,
|
|
43575
|
+
canWrite: false,
|
|
43366
43576
|
prompt: [
|
|
43367
43577
|
"You design tests for code written by another AI assistant.",
|
|
43368
43578
|
"",
|
|
@@ -43382,6 +43592,7 @@ var DEFINITIONS = {
|
|
|
43382
43592
|
* left it answering from whatever happened to be pasted in. This is the role the flag
|
|
43383
43593
|
* exists for. */
|
|
43384
43594
|
usesTools: true,
|
|
43595
|
+
canWrite: false,
|
|
43385
43596
|
prompt: [
|
|
43386
43597
|
"You answer questions about how things are done here: internal libraries, house conventions,",
|
|
43387
43598
|
"the shape of existing code, and what has already been written down.",
|
|
@@ -43391,7 +43602,29 @@ var DEFINITIONS = {
|
|
|
43391
43602
|
"you are inferring \u2014 a convention you guessed at, stated confidently, becomes the convention.",
|
|
43392
43603
|
"",
|
|
43393
43604
|
"If the material does not answer the question, say so and say what would. Do not fill the gap",
|
|
43394
|
-
"with how it is usually done elsewhere unless you label it as exactly that."
|
|
43605
|
+
"with how it is usually done elsewhere unless you label it as exactly that.",
|
|
43606
|
+
"",
|
|
43607
|
+
/*
|
|
43608
|
+
* The one specialist that may write, and only this one thing.
|
|
43609
|
+
*
|
|
43610
|
+
* The objection was never that the librarian should not record what it knows — it is the
|
|
43611
|
+
* role that can see the gap. It was that a consultation asks nobody, so a skill written
|
|
43612
|
+
* there would be prose injected into every later prompt that no human had read (§13's
|
|
43613
|
+
* persistent prompt-injection vector). That was answered by making this path *ask*:
|
|
43614
|
+
* `runConsultation` routes anything in ALWAYS_ASK_TOOLS through the same approval gate the
|
|
43615
|
+
* agent loop uses, so the user sees the source exactly as they would for any other write.
|
|
43616
|
+
*
|
|
43617
|
+
* Everything else stays read-only. `consultBoundary.test.ts` holds that line, and pins the
|
|
43618
|
+
* rule that any name allowed past the group filter must be one the gate will stop on.
|
|
43619
|
+
*/
|
|
43620
|
+
"When the answer is something worth writing down \u2014 a convention you had to piece together,",
|
|
43621
|
+
"a gotcha that will catch the next person, a procedure that is currently only in somebody's",
|
|
43622
|
+
"head \u2014 say so and **write it with `write_skill`**. The user is shown the text and",
|
|
43623
|
+
"approves it before anything is recorded, so write it as it should stand rather than",
|
|
43624
|
+
"describing what it would say. If they decline, say what you would have written and why.",
|
|
43625
|
+
"",
|
|
43626
|
+
"Say plainly when something already written down is **wrong or out of date**. A stale skill",
|
|
43627
|
+
"is worse than a missing one, because it is believed."
|
|
43395
43628
|
].join("\n")
|
|
43396
43629
|
}
|
|
43397
43630
|
};
|
|
@@ -43413,7 +43646,10 @@ function roleInfo(role, custom2 = []) {
|
|
|
43413
43646
|
* accessibility — and those all turn on code the asker did not think to paste. The flag is
|
|
43414
43647
|
* there to turn it off for the ones that are really "write this to spec".
|
|
43415
43648
|
*/
|
|
43416
|
-
usesTools: defined.usesTools !== false
|
|
43649
|
+
usesTools: defined.usesTools !== false,
|
|
43650
|
+
// Off unless asked for: a role invented in a hurry should not be able to edit the
|
|
43651
|
+
// repository because nobody thought about the box.
|
|
43652
|
+
canWrite: defined.canWrite === true
|
|
43417
43653
|
};
|
|
43418
43654
|
}
|
|
43419
43655
|
return {
|
|
@@ -43421,7 +43657,8 @@ function roleInfo(role, custom2 = []) {
|
|
|
43421
43657
|
name: role,
|
|
43422
43658
|
summary: "This role is no longer defined.",
|
|
43423
43659
|
prompt: "",
|
|
43424
|
-
usesTools: false
|
|
43660
|
+
usesTools: false,
|
|
43661
|
+
canWrite: false
|
|
43425
43662
|
};
|
|
43426
43663
|
}
|
|
43427
43664
|
function allRoles(custom2 = []) {
|
|
@@ -43431,7 +43668,11 @@ function defaultPromptFor(role, custom2 = []) {
|
|
|
43431
43668
|
return roleInfo(role, custom2).prompt;
|
|
43432
43669
|
}
|
|
43433
43670
|
function buildAgentPrompt(options) {
|
|
43434
|
-
const lines = [
|
|
43671
|
+
const lines = [
|
|
43672
|
+
options.prompt.trim(),
|
|
43673
|
+
"",
|
|
43674
|
+
specialistPreamble(options.usesTools, options.canWrite === true)
|
|
43675
|
+
];
|
|
43435
43676
|
if (options.briefing !== void 0 && options.briefing.trim().length > 0) {
|
|
43436
43677
|
lines.push("", options.briefing);
|
|
43437
43678
|
}
|
|
@@ -43660,6 +43901,7 @@ function buildSystemPrompt(workspaceRoot, options = {}) {
|
|
|
43660
43901
|
} else if (options.pythonToolsAvailable === true) {
|
|
43661
43902
|
lines.push("", "Python tools:", "- `create_python_tool` makes a real, registered, callable tool. Use it whenever the user", ' asks for a "tool", even if writing a script would be easier.', "- Writing a .py file with `write_to_file` does NOT create a tool. It is just a file, and", " nothing can call it. Never describe that as having created a tool.", "- `update_python_tool` edits one, `delete_python_tool` removes one.");
|
|
43662
43903
|
}
|
|
43904
|
+
lines.push("", "Specialist roles:", "- The team of specialists is configurable, and you can change it. `read_role_prompt` shows", " what a role is told it is (no argument lists them all); `update_role` changes that, or a", " custom role's name, summary and workspace access.", "- `create_role` invents one \u2014 a security reviewer, say \u2014 and `delete_role` removes a custom", " one. The user approves each of these, seeing the whole role or a diff of it.", '- So "make the reviewer stricter" or "add a role that reviews SQL" is something to do, not', " something to explain how to do by hand.");
|
|
43663
43905
|
if (options.skills !== void 0 || options.skillsSearchable === true) {
|
|
43664
43906
|
lines.push("", "Skills, before anything else:", "- Check the skills for this workspace before you plan or answer. They record how *this*", " project works, and they exist because someone was tired of explaining it.", "- A skill that applies overrides your general knowledge. Do not restate a convention it", " contradicts.", ...options.teamSkillsAvailable === true ? [
|
|
43665
43907
|
"- `search_team_skills` searches what OTHER people have taught their assistants. Use it",
|
|
@@ -44146,6 +44388,9 @@ function trailerFor(agent, team) {
|
|
|
44146
44388
|
if (agent.role === "reviewer" && programmer !== void 0) {
|
|
44147
44389
|
lines.push("", "If the programmer wrote this code, take the findings back to it rather than fixing them yourself: paste the code as it stands, the findings in full, and anything you have already checked. It may disagree, and a disagreement is an answer \u2014 you have the real file and neither of them does, so you settle it and say which way you went. Re-review only if the fix was substantial enough that this review no longer describes the code.");
|
|
44148
44390
|
}
|
|
44391
|
+
if (agent.role === "librarian") {
|
|
44392
|
+
lines.push("", "It can record a skill itself, and the user will have approved the text before it was written \u2014 so if it says it wrote one, that is done and not something to repeat. If it said something already written down is wrong or out of date, act on that: a stale skill is worse than a missing one, because it is believed.");
|
|
44393
|
+
}
|
|
44149
44394
|
if (agent.role === "programmer") {
|
|
44150
44395
|
lines.push("", "Check this against the real file before applying it \u2014 it was written from what you pasted, so it can miss a convention or a caller it was never shown.");
|
|
44151
44396
|
}
|
|
@@ -44163,9 +44408,13 @@ function resolveTeam(context) {
|
|
|
44163
44408
|
const assignment = context.config?.roles?.[role] ?? defaultAssignment(role, context);
|
|
44164
44409
|
if (assignment === void 0)
|
|
44165
44410
|
continue;
|
|
44411
|
+
if (assignment.enabled === false)
|
|
44412
|
+
continue;
|
|
44166
44413
|
const info = roleInfo(role, custom2);
|
|
44167
44414
|
const prompt = assignment.prompt ?? defaultPromptFor(role, custom2);
|
|
44168
44415
|
const usesTools = assignment.tools ?? info.usesTools;
|
|
44416
|
+
const canWrite = assignment.write ?? info.canWrite;
|
|
44417
|
+
const thinking = assignment.thinking;
|
|
44169
44418
|
if (assignment.kind === "cli") {
|
|
44170
44419
|
resolved.push({
|
|
44171
44420
|
role,
|
|
@@ -44175,11 +44424,15 @@ function resolveTeam(context) {
|
|
|
44175
44424
|
label: "Claude",
|
|
44176
44425
|
prompt,
|
|
44177
44426
|
usesTools,
|
|
44427
|
+
canWrite,
|
|
44428
|
+
...thinking !== void 0 ? { thinking } : {},
|
|
44178
44429
|
available: context.cliAvailable,
|
|
44179
44430
|
...context.cliAvailable ? {} : { reason: "The Claude CLI is not available on this machine." }
|
|
44180
44431
|
});
|
|
44181
44432
|
continue;
|
|
44182
44433
|
}
|
|
44434
|
+
if (assignment.profileId === void 0)
|
|
44435
|
+
continue;
|
|
44183
44436
|
const profile = context.profiles.find((candidate) => candidate.id === assignment.profileId);
|
|
44184
44437
|
resolved.push({
|
|
44185
44438
|
role,
|
|
@@ -44190,6 +44443,8 @@ function resolveTeam(context) {
|
|
|
44190
44443
|
label: profile?.label ?? assignment.profileId ?? "unassigned",
|
|
44191
44444
|
prompt,
|
|
44192
44445
|
usesTools,
|
|
44446
|
+
canWrite,
|
|
44447
|
+
...thinking !== void 0 ? { thinking } : {},
|
|
44193
44448
|
available: profile !== void 0,
|
|
44194
44449
|
/*
|
|
44195
44450
|
* A profile that has been deleted leaves the role unavailable and says so, rather than
|
|
@@ -44484,11 +44739,26 @@ function buildRoster(team, self) {
|
|
|
44484
44739
|
"- **Readers** \u2014 the reviewer, the tester, the librarian. Worth a step where another pair of",
|
|
44485
44740
|
" eyes changes what happens: risky or fiddly code, a step that finishes something, a",
|
|
44486
44741
|
" convention you would otherwise be guessing at.",
|
|
44742
|
+
'- **The librarian writes down what should be written down.** A step like "record how this',
|
|
44743
|
+
' is set up" is a good one to allocate: it reads what already exists and records the skill',
|
|
44744
|
+
" itself. The user approves the text before it is saved, so word the step as recording.",
|
|
44487
44745
|
"- **The programmer writes.** Where a step is a self-contained piece of code with a spec",
|
|
44488
44746
|
" clear enough to hand over \u2014 a parser, a schema, a set of pure functions \u2014 say so and give",
|
|
44489
44747
|
" it to the programmer. The assistant checks what comes back against the real file and",
|
|
44490
44748
|
" applies it, so this is delegation rather than trust.",
|
|
44491
44749
|
"",
|
|
44750
|
+
/*
|
|
44751
|
+
* A role invented by the user, which no fixed description can cover.
|
|
44752
|
+
*
|
|
44753
|
+
* The two bullets above name the built-in five, and a plan written only from them would
|
|
44754
|
+
* quietly skip a `db-reviewer` the user went to the trouble of creating — the same failure
|
|
44755
|
+
* as never allocating the programmer, arriving from the other direction. The summary is the
|
|
44756
|
+
* only thing that can describe it, so the instruction is to read it.
|
|
44757
|
+
*/
|
|
44758
|
+
"- **A role you do not recognise is described by its summary above.** The user invented it",
|
|
44759
|
+
" and wrote that line, so treat it as the authority on what the role is for and allocate it",
|
|
44760
|
+
" where the summary says it helps.",
|
|
44761
|
+
"",
|
|
44492
44762
|
"Only where it genuinely changes the outcome: a plan that routes every step through all of",
|
|
44493
44763
|
"them is ceremony, and one that routes none wastes a team that is sitting there."
|
|
44494
44764
|
);
|
|
@@ -44538,11 +44808,109 @@ function buildAgentBriefing(input) {
|
|
|
44538
44808
|
return sections.join("\n");
|
|
44539
44809
|
}
|
|
44540
44810
|
|
|
44811
|
+
// ../../packages/core/dist/approval/commands.js
|
|
44812
|
+
function isCommandAllowlisted(command, allowlist) {
|
|
44813
|
+
return allowlist.includes(command);
|
|
44814
|
+
}
|
|
44815
|
+
function addToAllowlist(command, allowlist) {
|
|
44816
|
+
return allowlist.includes(command) ? [...allowlist] : [...allowlist, command];
|
|
44817
|
+
}
|
|
44818
|
+
function removeFromAllowlist(command, allowlist) {
|
|
44819
|
+
return allowlist.filter((entry) => entry !== command);
|
|
44820
|
+
}
|
|
44821
|
+
|
|
44822
|
+
// ../../packages/core/dist/approval/types.js
|
|
44823
|
+
function requiresApproval(group) {
|
|
44824
|
+
return group !== "always";
|
|
44825
|
+
}
|
|
44826
|
+
|
|
44827
|
+
// ../../packages/core/dist/approval/policy.js
|
|
44828
|
+
function isApprovableGroup(group) {
|
|
44829
|
+
return group === "read" || group === "edit" || group === "command" || group === "mcp";
|
|
44830
|
+
}
|
|
44831
|
+
function categoryEnabled(group, settings) {
|
|
44832
|
+
if (settings === void 0 || !isApprovableGroup(group))
|
|
44833
|
+
return false;
|
|
44834
|
+
return settings[group] === true;
|
|
44835
|
+
}
|
|
44836
|
+
var ALWAYS_ASK_TOOLS = /* @__PURE__ */ new Set([
|
|
44837
|
+
"create_python_tool",
|
|
44838
|
+
"update_python_tool",
|
|
44839
|
+
"delete_python_tool",
|
|
44840
|
+
"write_skill",
|
|
44841
|
+
"delete_skill",
|
|
44842
|
+
/*
|
|
44843
|
+
* VBA installed into a workbook runs on this machine as this user, and nobody reviews a macro
|
|
44844
|
+
* afterwards. That is the same act as creating a Python tool, so it gets the same rule: a
|
|
44845
|
+
* human sees the source once, and no category toggle can stand in for that.
|
|
44846
|
+
*/
|
|
44847
|
+
"excel_write_macro",
|
|
44848
|
+
/*
|
|
44849
|
+
* Running a macro executes somebody else's VBA as the user: it can rewrite the workbook, write
|
|
44850
|
+
* files, or send mail. That is not something a category toggle should ever cover, and the
|
|
44851
|
+
* approval showing the actual source is the only thing standing between "run DoTheThing" and
|
|
44852
|
+
* whatever DoTheThing does.
|
|
44853
|
+
*/
|
|
44854
|
+
"excel_run_macro",
|
|
44855
|
+
/*
|
|
44856
|
+
* The plan is what holds the assistant to work the user agreed, so a category toggle must
|
|
44857
|
+
* never stand in for reading the change. Auto-approving this would mean an agent could widen
|
|
44858
|
+
* its own instructions and then point at them as authority — and both the panel and the
|
|
44859
|
+
* prompt would look right afterwards, because both would be reading the new plan.
|
|
44860
|
+
*/
|
|
44861
|
+
"update_plan",
|
|
44862
|
+
/*
|
|
44863
|
+
* A role's prompt is prose injected into a model that then advises on this repository's code —
|
|
44864
|
+
* the reason `agents` is user-scope only. Softening a reviewer does not error; it approves
|
|
44865
|
+
* things, in the same tone as before. A category toggle must never stand in for reading that
|
|
44866
|
+
* diff.
|
|
44867
|
+
*/
|
|
44868
|
+
"update_role",
|
|
44869
|
+
// Inventing one is the same act as rewriting one: a prompt that will advise on this code.
|
|
44870
|
+
"create_role",
|
|
44871
|
+
// And removing one takes a prompt somebody wrote with it.
|
|
44872
|
+
"delete_role"
|
|
44873
|
+
]);
|
|
44874
|
+
function decideFromPolicy(request, approvals) {
|
|
44875
|
+
if (!requiresApproval(request.group))
|
|
44876
|
+
return "approve";
|
|
44877
|
+
if (ALWAYS_ASK_TOOLS.has(request.toolName))
|
|
44878
|
+
return void 0;
|
|
44879
|
+
if (approvals === void 0)
|
|
44880
|
+
return void 0;
|
|
44881
|
+
if (approvals.allowedTools?.includes(request.toolName) === true)
|
|
44882
|
+
return "approve";
|
|
44883
|
+
if (request.group === "command") {
|
|
44884
|
+
const command = commandFromPreview(request.preview);
|
|
44885
|
+
if (command !== void 0 && isCommandAllowlisted(command, approvals.allowedCommands ?? [])) {
|
|
44886
|
+
return "approve";
|
|
44887
|
+
}
|
|
44888
|
+
}
|
|
44889
|
+
return categoryEnabled(request.group, approvals.autoApprove) ? "approve" : void 0;
|
|
44890
|
+
}
|
|
44891
|
+
function commandFromPreview(preview) {
|
|
44892
|
+
return preview.kind === "command" ? preview.command : void 0;
|
|
44893
|
+
}
|
|
44894
|
+
var PolicyApprovalGate = class {
|
|
44895
|
+
inner;
|
|
44896
|
+
getApprovals;
|
|
44897
|
+
constructor(inner, getApprovals) {
|
|
44898
|
+
this.inner = inner;
|
|
44899
|
+
this.getApprovals = getApprovals;
|
|
44900
|
+
}
|
|
44901
|
+
async requestApproval(request) {
|
|
44902
|
+
const decided = decideFromPolicy(request, this.getApprovals());
|
|
44903
|
+
if (decided !== void 0)
|
|
44904
|
+
return decided;
|
|
44905
|
+
return this.inner.requestApproval(request);
|
|
44906
|
+
}
|
|
44907
|
+
};
|
|
44908
|
+
|
|
44541
44909
|
// ../../packages/core/dist/agents/consult.js
|
|
44542
44910
|
var CONSULT_MAX_STEPS = 5;
|
|
44543
44911
|
var ALLOWED_GROUPS = /* @__PURE__ */ new Set(["read"]);
|
|
44544
|
-
function toolsForConsultation(all) {
|
|
44545
|
-
return all.filter((tool) => ALLOWED_GROUPS.has(tool.group) && tool.name !== "ask_agent" && tool.name !== "ask_expert");
|
|
44912
|
+
function toolsForConsultation(all, extra = /* @__PURE__ */ new Set()) {
|
|
44913
|
+
return all.filter((tool) => (ALLOWED_GROUPS.has(tool.group) || extra.has(tool.name)) && tool.name !== "ask_agent" && tool.name !== "ask_expert");
|
|
44546
44914
|
}
|
|
44547
44915
|
async function runConsultation(options) {
|
|
44548
44916
|
const limit = options.maxSteps ?? CONSULT_MAX_STEPS;
|
|
@@ -44592,7 +44960,10 @@ async function runConsultation(options) {
|
|
|
44592
44960
|
}
|
|
44593
44961
|
try {
|
|
44594
44962
|
const parsed = tool.parametersSchema.safeParse(JSON.parse(call.arguments || "{}"));
|
|
44595
|
-
const
|
|
44963
|
+
const permitted = tool.group === "read" && !ALWAYS_ASK_TOOLS.has(tool.name) || options.approve !== void 0 && await options.approve(tool, parsed.data);
|
|
44964
|
+
const result = !permitted ? {
|
|
44965
|
+
content: `The user did not approve ${tool.name}. Say what you would have written and why, and let the assistant put it to them instead.`
|
|
44966
|
+
} : parsed.success ? await tool.execute(parsed.data, options.context) : {
|
|
44596
44967
|
content: `Those arguments are not valid: ${parsed.error.issues.map((i) => i.message).join("; ")}`
|
|
44597
44968
|
};
|
|
44598
44969
|
messages.push({ role: "tool", toolCallId: call.id, content: String(result.content) });
|
|
@@ -44801,6 +45172,58 @@ function buildExpertBriefing(input) {
|
|
|
44801
45172
|
return sections.join("\n");
|
|
44802
45173
|
}
|
|
44803
45174
|
|
|
45175
|
+
// ../../packages/core/dist/expert/assessments.js
|
|
45176
|
+
function allAssessments(expert) {
|
|
45177
|
+
const list = [...expert.assessments ?? []];
|
|
45178
|
+
const legacy = expert.assessment;
|
|
45179
|
+
if (legacy !== void 0 && !list.some((entry) => sameSubject(entry, legacy))) {
|
|
45180
|
+
list.push(legacy);
|
|
45181
|
+
}
|
|
45182
|
+
return list.sort((a, b) => b.assessedAt - a.assessedAt);
|
|
45183
|
+
}
|
|
45184
|
+
function assessmentFor(all, model, profileLabel) {
|
|
45185
|
+
if (model.length === 0)
|
|
45186
|
+
return void 0;
|
|
45187
|
+
const exact = profileLabel === void 0 ? void 0 : all.find((entry) => entry.model === model && entry.profileLabel === profileLabel);
|
|
45188
|
+
return exact ?? all.find((entry) => entry.model === model);
|
|
45189
|
+
}
|
|
45190
|
+
function recordAssessment(all, entry, limit = MAX_ASSESSMENTS) {
|
|
45191
|
+
const kept = all.filter((existing) => !sameSubject(existing, entry));
|
|
45192
|
+
return [entry, ...kept].sort((a, b) => b.assessedAt - a.assessedAt).slice(0, limit);
|
|
45193
|
+
}
|
|
45194
|
+
function forgetAssessment(all, model, profileLabel) {
|
|
45195
|
+
return all.filter((entry) => !(entry.model === model && entry.profileLabel === profileLabel));
|
|
45196
|
+
}
|
|
45197
|
+
var MAX_ASSESSMENTS = 12;
|
|
45198
|
+
function sameSubject(a, b) {
|
|
45199
|
+
return a.model === b.model && a.profileLabel === b.profileLabel;
|
|
45200
|
+
}
|
|
45201
|
+
|
|
45202
|
+
// ../../packages/core/dist/agents/seats.js
|
|
45203
|
+
var SEAT_FITS = [
|
|
45204
|
+
{
|
|
45205
|
+
role: "programmer",
|
|
45206
|
+
probes: ["code", "instruction-following"],
|
|
45207
|
+
lookFor: "Code that is correct and *only* code \u2014 no preamble, no explanation you did not ask for, no rewriting of things it was not asked to change. A model that cannot hold an output format will produce diffs you have to unpick before you can apply them."
|
|
45208
|
+
},
|
|
45209
|
+
{
|
|
45210
|
+
role: "reviewer",
|
|
45211
|
+
probes: ["debugging", "instruction-conflict"],
|
|
45212
|
+
lookFor: "Finding the actual fault rather than the first plausible one, and saying when two instructions contradict instead of quietly obeying one. A model that agrees easily makes an approving reviewer, which is worse than none because it gets believed."
|
|
45213
|
+
},
|
|
45214
|
+
{
|
|
45215
|
+
role: "tester",
|
|
45216
|
+
probes: ["instruction-conflict", "debugging"],
|
|
45217
|
+
lookFor: "Noticing what does not add up. The tester earns its place by thinking of the case you did not, which is the same instinct as spotting a contradiction."
|
|
45218
|
+
},
|
|
45219
|
+
{
|
|
45220
|
+
role: "librarian",
|
|
45221
|
+
probes: ["honesty"],
|
|
45222
|
+
lookFor: "Admitting it does not know. This is the one seat where inventing is worse than silence \u2014 a convention guessed at and stated confidently becomes the convention."
|
|
45223
|
+
}
|
|
45224
|
+
];
|
|
45225
|
+
var EXPERT_GUIDANCE = "Planning across files is the whole of what the expert does, and no short probe stands in for it. Give the seat the model you would trust with an unfamiliar codebase, turn its thinking up, and judge it on whether its first plan survives contact with the work.";
|
|
45226
|
+
|
|
44804
45227
|
// ../../packages/core/dist/expert/budget.js
|
|
44805
45228
|
function money2(value) {
|
|
44806
45229
|
return `$${value.toFixed(value < 1 ? 4 : 2)}`;
|
|
@@ -48578,7 +49001,12 @@ var NEVER_AVAILABLE_TO_SCHEDULES = [
|
|
|
48578
49001
|
* Rewriting the plan it is being held to, with nobody there to approve the diff. Same ladder
|
|
48579
49002
|
* as `schedule_prompt`: a run that can change its own instructions is bounded by nothing.
|
|
48580
49003
|
*/
|
|
48581
|
-
"update_plan"
|
|
49004
|
+
"update_plan",
|
|
49005
|
+
// Rewriting what a specialist is, unattended. The same ladder: a run that can redefine its own
|
|
49006
|
+
// reviewer can arrange to be reviewed favourably by the next one.
|
|
49007
|
+
"update_role",
|
|
49008
|
+
"create_role",
|
|
49009
|
+
"delete_role"
|
|
48582
49010
|
];
|
|
48583
49011
|
function scheduleAppliesHere(schedule, workspaceRoot) {
|
|
48584
49012
|
if (schedule.workspaceRoot === void 0)
|
|
@@ -49750,107 +50178,20 @@ async function indexWorkspace(options) {
|
|
|
49750
50178
|
};
|
|
49751
50179
|
}
|
|
49752
50180
|
|
|
49753
|
-
// ../../packages/core/dist/
|
|
49754
|
-
|
|
49755
|
-
|
|
49756
|
-
|
|
49757
|
-
|
|
49758
|
-
|
|
49759
|
-
|
|
49760
|
-
|
|
49761
|
-
|
|
49762
|
-
|
|
49763
|
-
|
|
49764
|
-
}
|
|
49765
|
-
|
|
49766
|
-
|
|
49767
|
-
}
|
|
49768
|
-
|
|
49769
|
-
// ../../packages/core/dist/approval/policy.js
|
|
49770
|
-
function isApprovableGroup(group) {
|
|
49771
|
-
return group === "read" || group === "edit" || group === "command" || group === "mcp";
|
|
49772
|
-
}
|
|
49773
|
-
function categoryEnabled(group, settings) {
|
|
49774
|
-
if (settings === void 0 || !isApprovableGroup(group))
|
|
49775
|
-
return false;
|
|
49776
|
-
return settings[group] === true;
|
|
49777
|
-
}
|
|
49778
|
-
var ALWAYS_ASK_TOOLS = /* @__PURE__ */ new Set([
|
|
49779
|
-
"create_python_tool",
|
|
49780
|
-
"update_python_tool",
|
|
49781
|
-
"delete_python_tool",
|
|
49782
|
-
"write_skill",
|
|
49783
|
-
"delete_skill",
|
|
49784
|
-
/*
|
|
49785
|
-
* VBA installed into a workbook runs on this machine as this user, and nobody reviews a macro
|
|
49786
|
-
* afterwards. That is the same act as creating a Python tool, so it gets the same rule: a
|
|
49787
|
-
* human sees the source once, and no category toggle can stand in for that.
|
|
49788
|
-
*/
|
|
49789
|
-
"excel_write_macro",
|
|
49790
|
-
/*
|
|
49791
|
-
* Running a macro executes somebody else's VBA as the user: it can rewrite the workbook, write
|
|
49792
|
-
* files, or send mail. That is not something a category toggle should ever cover, and the
|
|
49793
|
-
* approval showing the actual source is the only thing standing between "run DoTheThing" and
|
|
49794
|
-
* whatever DoTheThing does.
|
|
49795
|
-
*/
|
|
49796
|
-
"excel_run_macro",
|
|
49797
|
-
/*
|
|
49798
|
-
* The plan is what holds the assistant to work the user agreed, so a category toggle must
|
|
49799
|
-
* never stand in for reading the change. Auto-approving this would mean an agent could widen
|
|
49800
|
-
* its own instructions and then point at them as authority — and both the panel and the
|
|
49801
|
-
* prompt would look right afterwards, because both would be reading the new plan.
|
|
49802
|
-
*/
|
|
49803
|
-
"update_plan"
|
|
49804
|
-
]);
|
|
49805
|
-
function decideFromPolicy(request, approvals) {
|
|
49806
|
-
if (!requiresApproval(request.group))
|
|
49807
|
-
return "approve";
|
|
49808
|
-
if (ALWAYS_ASK_TOOLS.has(request.toolName))
|
|
49809
|
-
return void 0;
|
|
49810
|
-
if (approvals === void 0)
|
|
49811
|
-
return void 0;
|
|
49812
|
-
if (approvals.allowedTools?.includes(request.toolName) === true)
|
|
49813
|
-
return "approve";
|
|
49814
|
-
if (request.group === "command") {
|
|
49815
|
-
const command = commandFromPreview(request.preview);
|
|
49816
|
-
if (command !== void 0 && isCommandAllowlisted(command, approvals.allowedCommands ?? [])) {
|
|
49817
|
-
return "approve";
|
|
49818
|
-
}
|
|
49819
|
-
}
|
|
49820
|
-
return categoryEnabled(request.group, approvals.autoApprove) ? "approve" : void 0;
|
|
49821
|
-
}
|
|
49822
|
-
function commandFromPreview(preview) {
|
|
49823
|
-
return preview.kind === "command" ? preview.command : void 0;
|
|
49824
|
-
}
|
|
49825
|
-
var PolicyApprovalGate = class {
|
|
49826
|
-
inner;
|
|
49827
|
-
getApprovals;
|
|
49828
|
-
constructor(inner, getApprovals) {
|
|
49829
|
-
this.inner = inner;
|
|
49830
|
-
this.getApprovals = getApprovals;
|
|
49831
|
-
}
|
|
49832
|
-
async requestApproval(request) {
|
|
49833
|
-
const decided = decideFromPolicy(request, this.getApprovals());
|
|
49834
|
-
if (decided !== void 0)
|
|
49835
|
-
return decided;
|
|
49836
|
-
return this.inner.requestApproval(request);
|
|
49837
|
-
}
|
|
49838
|
-
};
|
|
49839
|
-
|
|
49840
|
-
// ../../packages/core/dist/checkpoints/shadowGit.js
|
|
49841
|
-
import { execFile as execFile2 } from "node:child_process";
|
|
49842
|
-
import fs7 from "node:fs/promises";
|
|
49843
|
-
import path13 from "node:path";
|
|
49844
|
-
function runGit(args, cwd) {
|
|
49845
|
-
return new Promise((resolve, reject2) => {
|
|
49846
|
-
execFile2("git", args, { cwd, maxBuffer: 32 * 1024 * 1024 }, (error51, stdout, stderr) => {
|
|
49847
|
-
if (error51 && typeof error51.code !== "number") {
|
|
49848
|
-
reject2(error51);
|
|
49849
|
-
return;
|
|
49850
|
-
}
|
|
49851
|
-
resolve({ stdout, stderr, code: error51?.code ?? 0 });
|
|
49852
|
-
});
|
|
49853
|
-
});
|
|
50181
|
+
// ../../packages/core/dist/checkpoints/shadowGit.js
|
|
50182
|
+
import { execFile as execFile2 } from "node:child_process";
|
|
50183
|
+
import fs7 from "node:fs/promises";
|
|
50184
|
+
import path13 from "node:path";
|
|
50185
|
+
function runGit(args, cwd) {
|
|
50186
|
+
return new Promise((resolve, reject2) => {
|
|
50187
|
+
execFile2("git", args, { cwd, maxBuffer: 32 * 1024 * 1024 }, (error51, stdout, stderr) => {
|
|
50188
|
+
if (error51 && typeof error51.code !== "number") {
|
|
50189
|
+
reject2(error51);
|
|
50190
|
+
return;
|
|
50191
|
+
}
|
|
50192
|
+
resolve({ stdout, stderr, code: error51?.code ?? 0 });
|
|
50193
|
+
});
|
|
50194
|
+
});
|
|
49854
50195
|
}
|
|
49855
50196
|
var ShadowGit = class {
|
|
49856
50197
|
workspaceRoot;
|
|
@@ -57131,6 +57472,29 @@ function looksUnfinished(text) {
|
|
|
57131
57472
|
var CONTINUE_PROMPT = "You described what you were about to do but did not call a tool, so nothing happened. If you meant to act, call the tool now. If you were already finished, call attempt_completion with a summary instead.";
|
|
57132
57473
|
var MAX_CONTINUE_NUDGES = 1;
|
|
57133
57474
|
|
|
57475
|
+
// ../../packages/core/dist/agent/repairHistory.js
|
|
57476
|
+
var UNANSWERED = "This tool call never reported a result \u2014 the turn ended before it did. Nothing can be assumed about whether it ran or what it changed. If it still matters, call it again; otherwise carry on.";
|
|
57477
|
+
function repairUnansweredToolCalls(messages) {
|
|
57478
|
+
const answered = /* @__PURE__ */ new Set();
|
|
57479
|
+
for (const message3 of messages) {
|
|
57480
|
+
if (message3.role === "tool" && message3.toolCallId !== void 0)
|
|
57481
|
+
answered.add(message3.toolCallId);
|
|
57482
|
+
}
|
|
57483
|
+
const repaired = [];
|
|
57484
|
+
for (const message3 of messages) {
|
|
57485
|
+
repaired.push(message3);
|
|
57486
|
+
if (message3.role !== "assistant" || message3.toolCalls === void 0)
|
|
57487
|
+
continue;
|
|
57488
|
+
for (const call of message3.toolCalls) {
|
|
57489
|
+
if (answered.has(call.id))
|
|
57490
|
+
continue;
|
|
57491
|
+
repaired.push({ role: "tool", toolCallId: call.id, content: UNANSWERED });
|
|
57492
|
+
answered.add(call.id);
|
|
57493
|
+
}
|
|
57494
|
+
}
|
|
57495
|
+
return repaired;
|
|
57496
|
+
}
|
|
57497
|
+
|
|
57134
57498
|
// ../../packages/core/dist/agent/truncate.js
|
|
57135
57499
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
57136
57500
|
import fs14 from "node:fs/promises";
|
|
@@ -57228,7 +57592,7 @@ var MAX_REFUNDED_STEPS = 20;
|
|
|
57228
57592
|
var MAX_CONSECUTIVE_MISTAKES = 3;
|
|
57229
57593
|
async function prepareModelMessages(conversation, provider, tools, options, events) {
|
|
57230
57594
|
const contextWindow = options.contextWindow ?? 0;
|
|
57231
|
-
let messages = conversation.toModelMessages();
|
|
57595
|
+
let messages = repairUnansweredToolCalls(conversation.toModelMessages());
|
|
57232
57596
|
if (options.compactionEnabled !== false && contextWindow > 0) {
|
|
57233
57597
|
const estimated = computeBreakdown(messages, tools, contextWindow).total;
|
|
57234
57598
|
if (shouldCompact(messages, estimated, contextWindow, options.compaction ?? {})) {
|
|
@@ -57238,7 +57602,7 @@ async function prepareModelMessages(conversation, provider, tools, options, even
|
|
|
57238
57602
|
if (summary !== void 0) {
|
|
57239
57603
|
conversation.applyCompaction(summary, conversation.compactedCount() + result.summarisedCount);
|
|
57240
57604
|
events.onCompacted?.(result.summarisedCount);
|
|
57241
|
-
messages = conversation.toModelMessages();
|
|
57605
|
+
messages = repairUnansweredToolCalls(conversation.toModelMessages());
|
|
57242
57606
|
}
|
|
57243
57607
|
}
|
|
57244
57608
|
}
|
|
@@ -57458,12 +57822,20 @@ async function runAgentTurn(provider, conversation, userMessage, toolRegistry, t
|
|
|
57458
57822
|
}
|
|
57459
57823
|
conversation.addAssistantMessage(assistantText, [toolCall]);
|
|
57460
57824
|
events.onToolCall(toolCall);
|
|
57461
|
-
|
|
57462
|
-
|
|
57463
|
-
|
|
57464
|
-
|
|
57465
|
-
|
|
57466
|
-
|
|
57825
|
+
let result;
|
|
57826
|
+
try {
|
|
57827
|
+
result = await runOneToolCall(toolCall, toolRegistry, toolContext, options, events, {
|
|
57828
|
+
hasCheckpoint: () => checkpointTaken,
|
|
57829
|
+
markCheckpointTaken: () => {
|
|
57830
|
+
checkpointTaken = true;
|
|
57831
|
+
}
|
|
57832
|
+
}, mode);
|
|
57833
|
+
} catch (error51) {
|
|
57834
|
+
result = {
|
|
57835
|
+
content: `"${toolCall.name}" failed: ${error51 instanceof Error ? error51.message : String(error51)}`,
|
|
57836
|
+
isError: true
|
|
57837
|
+
};
|
|
57838
|
+
}
|
|
57467
57839
|
const forModel = options.truncationStore !== void 0 ? (await truncateToolResult(result.content, options.truncationStore)).content : result.content;
|
|
57468
57840
|
conversation.addToolResultMessage(toolCall.id, forModel);
|
|
57469
57841
|
events.onToolResult(toolCall, result);
|
|
@@ -59547,6 +59919,275 @@ var OfficeBridge = class {
|
|
|
59547
59919
|
}
|
|
59548
59920
|
};
|
|
59549
59921
|
|
|
59922
|
+
// ../../packages/core/dist/agents/direct.js
|
|
59923
|
+
var DIRECTED = /(?:^|\s)#([a-z][a-z0-9-]{1,23})\b/g;
|
|
59924
|
+
function findDirectedRoles(text, team) {
|
|
59925
|
+
const usable = new Set(team.filter((agent) => agent.available).map((agent) => agent.role));
|
|
59926
|
+
const addressed = [];
|
|
59927
|
+
const unknown2 = [];
|
|
59928
|
+
for (const match of text.matchAll(DIRECTED)) {
|
|
59929
|
+
const name = match[1];
|
|
59930
|
+
if (name === void 0)
|
|
59931
|
+
continue;
|
|
59932
|
+
if (usable.has(name)) {
|
|
59933
|
+
if (!addressed.includes(name))
|
|
59934
|
+
addressed.push(name);
|
|
59935
|
+
continue;
|
|
59936
|
+
}
|
|
59937
|
+
if (team.some((agent) => agent.role === name) && !unknown2.includes(name))
|
|
59938
|
+
unknown2.push(name);
|
|
59939
|
+
}
|
|
59940
|
+
return { addressed, unknown: unknown2 };
|
|
59941
|
+
}
|
|
59942
|
+
function describeDirectedRoles(directed, team) {
|
|
59943
|
+
const lines = [];
|
|
59944
|
+
if (directed.addressed.length > 0) {
|
|
59945
|
+
const names = directed.addressed.map((role) => `\`${role}\``).join(", ");
|
|
59946
|
+
lines.push(`The user addressed ${names} directly with #. Consult ${directed.addressed.length > 1 ? "each of them" : "it"} with \`ask_agent\` before you answer \u2014 this is not a judgement call about whether a consultation is worth it, they asked. Put the code, error or output they are referring to in the question, and say plainly in your reply what came back and whether you agree.`);
|
|
59947
|
+
}
|
|
59948
|
+
if (directed.unknown.length > 0) {
|
|
59949
|
+
const usable = team.filter((agent) => agent.available).map((agent) => agent.role);
|
|
59950
|
+
lines.push(`The user wrote ${directed.unknown.map((role) => `#${role}`).join(", ")}, which ${directed.unknown.length > 1 ? "are not roles" : "is not a role"} that can answer here. ${usable.length > 0 ? `Available: ${usable.join(", ")}. Say so and carry on with the request.` : "No specialists are assigned. Say so, mention Settings \u2192 Agents, and carry on."}`);
|
|
59951
|
+
}
|
|
59952
|
+
return lines.join("\n\n");
|
|
59953
|
+
}
|
|
59954
|
+
|
|
59955
|
+
// ../../packages/core/dist/tools/roleTools.js
|
|
59956
|
+
var readParams = external_exports.object({
|
|
59957
|
+
role: external_exports.string().describe("Which role to read \u2014 one of the roles configured here. Omit to list them all.").optional()
|
|
59958
|
+
});
|
|
59959
|
+
function createReadRolePromptTool(access) {
|
|
59960
|
+
return {
|
|
59961
|
+
name: "read_role_prompt",
|
|
59962
|
+
group: "read",
|
|
59963
|
+
description: "Read a specialist role's current system prompt \u2014 what it is told it is. Call this before changing one, so the change is an edit to what the user wrote rather than a replacement for it. With no role, lists the roles that exist here.",
|
|
59964
|
+
parametersSchema: readParams,
|
|
59965
|
+
async execute(params) {
|
|
59966
|
+
const roles = access.list();
|
|
59967
|
+
if (params.role === void 0) {
|
|
59968
|
+
if (roles.length === 0)
|
|
59969
|
+
return { content: "No roles are configured." };
|
|
59970
|
+
return {
|
|
59971
|
+
content: roles.map((entry) => `- ${entry.role} (${entry.name})` + (entry.assigned ? "" : " \u2014 nobody assigned") + (entry.edited ? " \u2014 prompt edited" : " \u2014 default prompt")).join("\n")
|
|
59972
|
+
};
|
|
59973
|
+
}
|
|
59974
|
+
const role = params.role.trim().toLowerCase();
|
|
59975
|
+
const prompt = access.current(role);
|
|
59976
|
+
if (prompt === void 0) {
|
|
59977
|
+
return {
|
|
59978
|
+
content: `There is no "${role}" role. The roles here are: ${roles.map((entry) => entry.role).join(", ")}.`,
|
|
59979
|
+
isError: true
|
|
59980
|
+
};
|
|
59981
|
+
}
|
|
59982
|
+
const edited = roles.find((entry) => entry.role === role)?.edited === true;
|
|
59983
|
+
return {
|
|
59984
|
+
content: `The ${role}'s prompt${edited ? " (edited by the user)" : " (the default)"}:
|
|
59985
|
+
|
|
59986
|
+
${prompt}`
|
|
59987
|
+
};
|
|
59988
|
+
}
|
|
59989
|
+
};
|
|
59990
|
+
}
|
|
59991
|
+
var updateParams2 = external_exports.object({
|
|
59992
|
+
role: external_exports.string().describe("Which role to change."),
|
|
59993
|
+
prompt: external_exports.string().optional().describe("The complete new prompt. It replaces the current one rather than being added to it, so include what is staying. An empty string resets the role to its default prompt; omit it entirely to leave the prompt alone."),
|
|
59994
|
+
/*
|
|
59995
|
+
* Name and summary are editable for the same reason the prompt is: they are how the role
|
|
59996
|
+
* presents itself. The summary especially — it is the line every other specialist sees and the
|
|
59997
|
+
* one the expert allocates from, so a role whose summary is wrong gets used for the wrong work.
|
|
59998
|
+
* Only a user-defined role can change them; a built-in one is what it is.
|
|
59999
|
+
*/
|
|
60000
|
+
name: external_exports.string().optional().describe("A new display name. Custom roles only."),
|
|
60001
|
+
summary: external_exports.string().optional().describe("A new one-line summary of what it is for. Custom roles only. This is what the expert allocates from, so it matters more than the name."),
|
|
60002
|
+
usesTools: external_exports.boolean().optional().describe("Whether it may read and search the workspace. Omit to leave unchanged."),
|
|
60003
|
+
reason: external_exports.string().optional().describe("One line on what is changing and why, shown to the user above the diff.")
|
|
60004
|
+
});
|
|
60005
|
+
function createUpdateRolePromptTool(access) {
|
|
60006
|
+
return {
|
|
60007
|
+
name: "update_role",
|
|
60008
|
+
/*
|
|
60009
|
+
* `edit`, and deliberately not `always`: `decideFromPolicy` approves the `always` group
|
|
60010
|
+
* *before* it consults ALWAYS_ASK_TOOLS, so putting it there would silently auto-approve the
|
|
60011
|
+
* one thing this must always ask about. The same trap `update_plan` nearly fell into.
|
|
60012
|
+
*/
|
|
60013
|
+
group: "edit",
|
|
60014
|
+
description: 'Change a specialist role: its system prompt, and for a role the user invented, its name, its summary, or whether it may read the workspace. Use it when the user says a specialist should behave differently ("make the reviewer stricter about error handling"). Read the role first and edit what is there rather than writing a new prompt from scratch. Only what you pass is changed. The user is shown a diff and must approve it, and it applies to every future consultation of that role.',
|
|
60015
|
+
parametersSchema: updateParams2,
|
|
60016
|
+
async preview(params) {
|
|
60017
|
+
const role = params.role.trim().toLowerCase();
|
|
60018
|
+
const details = access.details(role);
|
|
60019
|
+
const before = describeRole(details, access.current(role) ?? "");
|
|
60020
|
+
const nextPrompt = params.prompt === void 0 ? access.current(role) ?? "" : (
|
|
60021
|
+
// Empty means reset, so the diff shows what the default actually says — otherwise the
|
|
60022
|
+
// approval reads as "delete this prompt" rather than "go back to the built-in one".
|
|
60023
|
+
params.prompt.trim().length === 0 ? access.fallback(role) ?? "" : params.prompt.trim()
|
|
60024
|
+
);
|
|
60025
|
+
const after = describeRole(details === void 0 ? void 0 : {
|
|
60026
|
+
...details,
|
|
60027
|
+
...params.name !== void 0 ? { name: params.name.trim() } : {},
|
|
60028
|
+
...params.summary !== void 0 ? { summary: params.summary.trim() } : {},
|
|
60029
|
+
...params.usesTools !== void 0 ? { usesTools: params.usesTools } : {}
|
|
60030
|
+
}, nextPrompt);
|
|
60031
|
+
return {
|
|
60032
|
+
kind: "diff",
|
|
60033
|
+
path: `the ${role} role`,
|
|
60034
|
+
before,
|
|
60035
|
+
after,
|
|
60036
|
+
...params.reason !== void 0 && params.reason.trim().length > 0 ? { note: params.reason.trim() } : {}
|
|
60037
|
+
};
|
|
60038
|
+
},
|
|
60039
|
+
async execute(params) {
|
|
60040
|
+
const role = params.role.trim().toLowerCase();
|
|
60041
|
+
if (access.current(role) === void 0) {
|
|
60042
|
+
return {
|
|
60043
|
+
content: `There is no "${role}" role. The roles here are: ${access.list().map((entry) => entry.role).join(", ")}.`,
|
|
60044
|
+
isError: true
|
|
60045
|
+
};
|
|
60046
|
+
}
|
|
60047
|
+
const details = access.details(role);
|
|
60048
|
+
const changingIdentity = params.name !== void 0 || params.summary !== void 0 || params.usesTools !== void 0;
|
|
60049
|
+
if (changingIdentity && details?.custom !== true) {
|
|
60050
|
+
return {
|
|
60051
|
+
content: `Only the prompt can be changed on a built-in role. "${role}" is built in, so its name, summary and workspace access are fixed. Create a role of your own if you need a different one.`,
|
|
60052
|
+
isError: true
|
|
60053
|
+
};
|
|
60054
|
+
}
|
|
60055
|
+
if (changingIdentity && details !== void 0) {
|
|
60056
|
+
await access.create({
|
|
60057
|
+
id: details.id,
|
|
60058
|
+
name: params.name?.trim() ?? details.name,
|
|
60059
|
+
summary: params.summary?.trim() ?? details.summary,
|
|
60060
|
+
/*
|
|
60061
|
+
* The **original**, not the one in force.
|
|
60062
|
+
*
|
|
60063
|
+
* This path rewrites the role's definition, and for a custom role the definition's
|
|
60064
|
+
* prompt is what "reset to default" restores. Passing the effective prompt here would
|
|
60065
|
+
* quietly bake an edit into the definition: rename a role whose prompt had been changed,
|
|
60066
|
+
* and resetting it afterwards would hand back the edit, with the text it was created
|
|
60067
|
+
* with gone for good and nothing having reported a loss.
|
|
60068
|
+
*
|
|
60069
|
+
* An edit lives in its own store and is untouched by this, which is the point — the two
|
|
60070
|
+
* are separate so that one can be undone.
|
|
60071
|
+
*/
|
|
60072
|
+
prompt: details.originalPrompt,
|
|
60073
|
+
usesTools: params.usesTools ?? details.usesTools
|
|
60074
|
+
});
|
|
60075
|
+
}
|
|
60076
|
+
if (params.prompt !== void 0) {
|
|
60077
|
+
const next = params.prompt.trim();
|
|
60078
|
+
await access.save(role, next.length === 0 ? void 0 : next);
|
|
60079
|
+
}
|
|
60080
|
+
return {
|
|
60081
|
+
content: `The ${role} is updated and the user approved it. Every consultation of that role from now on uses it.`
|
|
60082
|
+
};
|
|
60083
|
+
}
|
|
60084
|
+
};
|
|
60085
|
+
}
|
|
60086
|
+
var createParams2 = external_exports.object({
|
|
60087
|
+
id: external_exports.string().describe('Short id the assistant will use to reach it, e.g. "security". Lowercase letters, digits and hyphens. It cannot be changed afterwards.'),
|
|
60088
|
+
name: external_exports.string().describe('What to call it in the settings panel, e.g. "Security reviewer".'),
|
|
60089
|
+
summary: external_exports.string().describe("One line on what it is for. Every other specialist sees this, and the expert allocates from it when writing a plan \u2014 so say what it is good for, not what it is."),
|
|
60090
|
+
prompt: external_exports.string().describe("Its system prompt: what it is told it is and how to answer. What it may and may not do is added automatically, so do not write rules about tools or permissions."),
|
|
60091
|
+
usesTools: external_exports.boolean().describe("Whether it may read and search the workspace. True where the answer depends on code the asker cannot paste; false where the question carries everything it needs.")
|
|
60092
|
+
});
|
|
60093
|
+
function createCreateRoleTool(access) {
|
|
60094
|
+
return {
|
|
60095
|
+
name: "create_role",
|
|
60096
|
+
// `edit`, never `always` — see the note on `update_role_prompt`.
|
|
60097
|
+
group: "edit",
|
|
60098
|
+
description: "Create a new specialist role beyond the built-in ones, when the user wants a kind of reviewer or helper the team does not have \u2014 a security reviewer, a performance reviewer, one that knows a particular part of this codebase. A role is its prompt, so write that carefully. The user is shown the whole role and must approve it, and then assigns a model to it in Settings \u2192 Agents before it can answer.",
|
|
60099
|
+
parametersSchema: createParams2,
|
|
60100
|
+
async preview(params) {
|
|
60101
|
+
const { used, limit } = access.capacity();
|
|
60102
|
+
return {
|
|
60103
|
+
kind: "text",
|
|
60104
|
+
text: [
|
|
60105
|
+
`Create the role "${params.id.trim().toLowerCase()}" (${used + 1} of ${limit}).`,
|
|
60106
|
+
"",
|
|
60107
|
+
`Name: ${params.name}`,
|
|
60108
|
+
`For: ${params.summary}`,
|
|
60109
|
+
`Reads: ${params.usesTools ? "yes \u2014 it can read and search the workspace" : "no \u2014 it answers from the question alone"}`,
|
|
60110
|
+
"",
|
|
60111
|
+
"What it is told:",
|
|
60112
|
+
"",
|
|
60113
|
+
params.prompt.trim()
|
|
60114
|
+
].join("\n")
|
|
60115
|
+
};
|
|
60116
|
+
},
|
|
60117
|
+
async execute(params) {
|
|
60118
|
+
const id = params.id.trim().toLowerCase();
|
|
60119
|
+
if (access.current(id) !== void 0) {
|
|
60120
|
+
return {
|
|
60121
|
+
content: `There is already a "${id}" role. Change it with update_role_prompt rather than creating it again.`,
|
|
60122
|
+
isError: true
|
|
60123
|
+
};
|
|
60124
|
+
}
|
|
60125
|
+
try {
|
|
60126
|
+
await access.create({ ...params, id });
|
|
60127
|
+
} catch (error51) {
|
|
60128
|
+
return {
|
|
60129
|
+
content: error51 instanceof Error ? error51.message : String(error51),
|
|
60130
|
+
isError: true
|
|
60131
|
+
};
|
|
60132
|
+
}
|
|
60133
|
+
return {
|
|
60134
|
+
content: `The ${id} role exists and the user approved it. Nobody answers it yet \u2014 it needs a model assigned in Settings \u2192 Agents before it can be consulted. Tell the user that.`
|
|
60135
|
+
};
|
|
60136
|
+
}
|
|
60137
|
+
};
|
|
60138
|
+
}
|
|
60139
|
+
function describeRole(details, prompt) {
|
|
60140
|
+
if (details === void 0)
|
|
60141
|
+
return prompt;
|
|
60142
|
+
return [
|
|
60143
|
+
`Name: ${details.name}`,
|
|
60144
|
+
`For: ${details.summary}`,
|
|
60145
|
+
`Reads: ${details.usesTools ? "yes" : "no"}`,
|
|
60146
|
+
"",
|
|
60147
|
+
prompt
|
|
60148
|
+
].join("\n");
|
|
60149
|
+
}
|
|
60150
|
+
var deleteParams3 = external_exports.object({
|
|
60151
|
+
role: external_exports.string().describe("Which custom role to remove. Built-in roles cannot be deleted.")
|
|
60152
|
+
});
|
|
60153
|
+
function createDeleteRoleTool(access) {
|
|
60154
|
+
return {
|
|
60155
|
+
name: "delete_role",
|
|
60156
|
+
group: "edit",
|
|
60157
|
+
description: "Remove a role the user invented, along with whatever model was assigned to it. Built-in roles cannot be removed. The user is shown the role, including its prompt, and must approve. Nothing else refers to it afterwards, so any plan step naming it should be revised in the same turn.",
|
|
60158
|
+
parametersSchema: deleteParams3,
|
|
60159
|
+
async preview(params) {
|
|
60160
|
+
const role = params.role.trim().toLowerCase();
|
|
60161
|
+
const details = access.details(role);
|
|
60162
|
+
return {
|
|
60163
|
+
kind: "text",
|
|
60164
|
+
text: details === void 0 ? `There is no "${role}" role to delete.` : [
|
|
60165
|
+
`Delete the "${details.id}" role and its assignment.`,
|
|
60166
|
+
"",
|
|
60167
|
+
describeRole(details, details.prompt),
|
|
60168
|
+
"",
|
|
60169
|
+
"The prompt above is removed with it."
|
|
60170
|
+
].join("\n")
|
|
60171
|
+
};
|
|
60172
|
+
},
|
|
60173
|
+
async execute(params) {
|
|
60174
|
+
const role = params.role.trim().toLowerCase();
|
|
60175
|
+
const details = access.details(role);
|
|
60176
|
+
if (details === void 0) {
|
|
60177
|
+
return { content: `There is no "${role}" role.`, isError: true };
|
|
60178
|
+
}
|
|
60179
|
+
if (!details.custom) {
|
|
60180
|
+
return {
|
|
60181
|
+
content: `"${role}" is one of the built-in roles and cannot be deleted. Leave it unassigned if it should not be used.`,
|
|
60182
|
+
isError: true
|
|
60183
|
+
};
|
|
60184
|
+
}
|
|
60185
|
+
await access.remove(role);
|
|
60186
|
+
return { content: `The ${role} role is gone, and so is its assignment.` };
|
|
60187
|
+
}
|
|
60188
|
+
};
|
|
60189
|
+
}
|
|
60190
|
+
|
|
59550
60191
|
// ../../packages/core/dist/office/vbaCheck.js
|
|
59551
60192
|
function splitLine(line) {
|
|
59552
60193
|
let bare = "";
|
|
@@ -60743,6 +61384,57 @@ ${preview.text}` } : {}
|
|
|
60743
61384
|
post({ type: "plan", plan: activePlan ?? "" });
|
|
60744
61385
|
postPlanProgress();
|
|
60745
61386
|
}
|
|
61387
|
+
const rolePromptAccess = {
|
|
61388
|
+
list: () => knownRoles(cachedAgentDefinitions).map((role) => ({
|
|
61389
|
+
role,
|
|
61390
|
+
name: roleInfo(role, cachedAgentDefinitions).name,
|
|
61391
|
+
assigned: cachedTeam.some((agent) => agent.role === role),
|
|
61392
|
+
edited: cachedAgentRoles?.[role]?.prompt !== void 0
|
|
61393
|
+
})),
|
|
61394
|
+
current: (role) => {
|
|
61395
|
+
if (!isAgentRole(role, cachedAgentDefinitions))
|
|
61396
|
+
return void 0;
|
|
61397
|
+
return cachedAgentRoles?.[role]?.prompt ?? defaultPromptFor(role, cachedAgentDefinitions);
|
|
61398
|
+
},
|
|
61399
|
+
fallback: (role) => isAgentRole(role, cachedAgentDefinitions) ? defaultPromptFor(role, cachedAgentDefinitions) : void 0,
|
|
61400
|
+
details: (role) => {
|
|
61401
|
+
if (!isAgentRole(role, cachedAgentDefinitions))
|
|
61402
|
+
return void 0;
|
|
61403
|
+
const info = roleInfo(role, cachedAgentDefinitions);
|
|
61404
|
+
return {
|
|
61405
|
+
id: role,
|
|
61406
|
+
name: info.name,
|
|
61407
|
+
summary: info.summary,
|
|
61408
|
+
prompt: cachedAgentRoles?.[role]?.prompt ?? info.prompt,
|
|
61409
|
+
// What a reset restores. `info.prompt` is the definition's for a custom role and the
|
|
61410
|
+
// shipped text for a built-in one, in both cases ignoring any edit on top.
|
|
61411
|
+
originalPrompt: info.prompt,
|
|
61412
|
+
usesTools: cachedAgentRoles?.[role]?.tools ?? info.usesTools,
|
|
61413
|
+
custom: cachedAgentDefinitions.some((definition) => definition.id === role)
|
|
61414
|
+
};
|
|
61415
|
+
},
|
|
61416
|
+
remove: async (role) => {
|
|
61417
|
+
await handleDeleteCustomRole(role);
|
|
61418
|
+
},
|
|
61419
|
+
create: async (role) => {
|
|
61420
|
+
await handleSaveCustomRole(role);
|
|
61421
|
+
},
|
|
61422
|
+
capacity: () => ({ used: cachedAgentDefinitions.length, limit: CUSTOM_ROLE_LIMIT }),
|
|
61423
|
+
save: async (role, prompt) => {
|
|
61424
|
+
await saveAgents((current) => {
|
|
61425
|
+
const roles = { ...current.roles ?? {} };
|
|
61426
|
+
const existing = roles[role] ?? { kind: "profile" };
|
|
61427
|
+
if (prompt === void 0) {
|
|
61428
|
+
const rest = { ...existing };
|
|
61429
|
+
delete rest.prompt;
|
|
61430
|
+
roles[role] = rest;
|
|
61431
|
+
} else {
|
|
61432
|
+
roles[role] = { ...existing, prompt };
|
|
61433
|
+
}
|
|
61434
|
+
return { ...current, roles };
|
|
61435
|
+
});
|
|
61436
|
+
}
|
|
61437
|
+
};
|
|
60746
61438
|
const planAccess = {
|
|
60747
61439
|
current: () => activePlan,
|
|
60748
61440
|
save: async (nextPlan) => {
|
|
@@ -61010,6 +61702,8 @@ ${preview.text}` } : {}
|
|
|
61010
61702
|
let cachedCodeGenerator;
|
|
61011
61703
|
let cachedTeam = [];
|
|
61012
61704
|
let cachedTeamGuidance;
|
|
61705
|
+
let cachedAgentRoles;
|
|
61706
|
+
let cachedAgentDefinitions = [];
|
|
61013
61707
|
let cachedBudgetMatters = false;
|
|
61014
61708
|
let cachedMentionExcludes;
|
|
61015
61709
|
let cachedReportsCost;
|
|
@@ -61060,6 +61754,8 @@ ${preview.text}` } : {}
|
|
|
61060
61754
|
cliAvailable: expertCli?.available === true
|
|
61061
61755
|
};
|
|
61062
61756
|
cachedTeam = resolveTeam(teamContext);
|
|
61757
|
+
cachedAgentRoles = config2.agents?.roles;
|
|
61758
|
+
cachedAgentDefinitions = config2.agents?.definitions ?? [];
|
|
61063
61759
|
cachedTeamGuidance = config2.agents?.teamGuidance;
|
|
61064
61760
|
cachedBudgetMatters = budgetMatters(teamContext);
|
|
61065
61761
|
cachedProgrammingProfileId = config2.programmingProfileId;
|
|
@@ -61078,7 +61774,14 @@ ${preview.text}` } : {}
|
|
|
61078
61774
|
cachedToolTimeoutSeconds = config2.tools?.timeoutSeconds;
|
|
61079
61775
|
cachedToolTimeouts = config2.tools?.timeouts;
|
|
61080
61776
|
cachedExpertColor = config2.ui?.expertColor ?? "#D97757";
|
|
61081
|
-
|
|
61777
|
+
const junior = (() => {
|
|
61778
|
+
try {
|
|
61779
|
+
return resolveActiveProfile(config2);
|
|
61780
|
+
} catch {
|
|
61781
|
+
return void 0;
|
|
61782
|
+
}
|
|
61783
|
+
})();
|
|
61784
|
+
cachedAssessment = junior === void 0 ? void 0 : assessmentFor(allAssessments(config2.expert ?? {}), junior.model, junior.label ?? junior.model);
|
|
61082
61785
|
cachedReportsCost = config2.expert?.reportsCost;
|
|
61083
61786
|
cachedPricing = config2.expert?.pricing;
|
|
61084
61787
|
cachedKeepAlive = config2.expert?.keepAlive === true;
|
|
@@ -61213,6 +61916,10 @@ ${preview.text}` } : {}
|
|
|
61213
61916
|
combined.register(tool, { dispatchOnly: dispatcher });
|
|
61214
61917
|
combined.register(createUpdatePlanTool(planAccess), { dispatchOnly: dispatcher });
|
|
61215
61918
|
combined.register(createPlanProgressTool(planAccess), { dispatchOnly: dispatcher });
|
|
61919
|
+
combined.register(createReadRolePromptTool(rolePromptAccess), { dispatchOnly: dispatcher });
|
|
61920
|
+
combined.register(createUpdateRolePromptTool(rolePromptAccess), { dispatchOnly: dispatcher });
|
|
61921
|
+
combined.register(createCreateRoleTool(rolePromptAccess), { dispatchOnly: dispatcher });
|
|
61922
|
+
combined.register(createDeleteRoleTool(rolePromptAccess), { dispatchOnly: dispatcher });
|
|
61216
61923
|
combined.register(createNotifyTool({
|
|
61217
61924
|
notify: (message3, level, details) => {
|
|
61218
61925
|
if (details !== void 0) {
|
|
@@ -61695,7 +62402,11 @@ ${preview.text}` } : {}
|
|
|
61695
62402
|
pythonNestedContext = toolContext;
|
|
61696
62403
|
pythonNestedCallsAllowed = schedule === void 0;
|
|
61697
62404
|
const mentions = await resolveMentions(text, { fs: toolContext.fs, workspaceRoot, denylist });
|
|
61698
|
-
const
|
|
62405
|
+
const directed = findDirectedRoles(text, cachedTeam);
|
|
62406
|
+
const direction = describeDirectedRoles(directed, cachedTeam);
|
|
62407
|
+
const messageText = direction.length > 0 ? `${attachMentions(text, mentions)}
|
|
62408
|
+
|
|
62409
|
+
${direction}` : attachMentions(text, mentions);
|
|
61699
62410
|
const turnOptions = {
|
|
61700
62411
|
signal: activeAbortController.signal,
|
|
61701
62412
|
truncationStore,
|
|
@@ -61957,7 +62668,7 @@ ${preview.text}` } : {}
|
|
|
61957
62668
|
}
|
|
61958
62669
|
if (input.authType === "none")
|
|
61959
62670
|
return { type: "none" };
|
|
61960
|
-
const typed = input.apiKey.trim();
|
|
62671
|
+
const typed = (input.apiKey ?? "").trim();
|
|
61961
62672
|
if (describeSecretRef(typed).kind === "env") {
|
|
61962
62673
|
await secrets.delete(apiKeyRefFor(id));
|
|
61963
62674
|
return { type: "apiKey", apiKeyRef: typed };
|
|
@@ -62111,6 +62822,19 @@ ${preview.text}` } : {}
|
|
|
62111
62822
|
}
|
|
62112
62823
|
}
|
|
62113
62824
|
async function profileFromForm(input) {
|
|
62825
|
+
const fieldErrors = validateProviderForm({
|
|
62826
|
+
label: input.label,
|
|
62827
|
+
wireFormat: input.wireFormat,
|
|
62828
|
+
baseUrl: input.baseUrl,
|
|
62829
|
+
model: input.model
|
|
62830
|
+
});
|
|
62831
|
+
if (fieldErrors.length > 0) {
|
|
62832
|
+
post({
|
|
62833
|
+
type: "error",
|
|
62834
|
+
message: fieldErrors.map((issue2) => `${issue2.path}: ${issue2.message}`).join("; ")
|
|
62835
|
+
});
|
|
62836
|
+
return void 0;
|
|
62837
|
+
}
|
|
62114
62838
|
const baseUrl = input.baseUrl.trim();
|
|
62115
62839
|
if (baseUrl.length === 0) {
|
|
62116
62840
|
post({ type: "error", message: "Enter a base URL first." });
|
|
@@ -62174,7 +62898,25 @@ ${preview.text}` } : {}
|
|
|
62174
62898
|
maxConsultations: settings?.maxConsultations ?? 0,
|
|
62175
62899
|
keepAlive: settings?.keepAlive === true,
|
|
62176
62900
|
...settings?.model !== void 0 ? { model: settings.model } : {},
|
|
62177
|
-
|
|
62901
|
+
// The one that applies to the active junior, chosen through the module that owns both
|
|
62902
|
+
// config shapes - not `settings.assessment`, which is only the legacy slot.
|
|
62903
|
+
...cachedAssessment !== void 0 ? { assessment: cachedAssessment } : {},
|
|
62904
|
+
assessments: allAssessments(settings ?? {}),
|
|
62905
|
+
/*
|
|
62906
|
+
* What the probes predict about each seat, and who grades them.
|
|
62907
|
+
*
|
|
62908
|
+
* Sent rather than duplicated in the UI: the mapping is reasoned about beside the probes,
|
|
62909
|
+
* in `agents/seats.ts`, and a copy in a React component is the second declaration of one
|
|
62910
|
+
* fact that this repository keeps paying for.
|
|
62911
|
+
*/
|
|
62912
|
+
seatFits: SEAT_FITS.map((fit) => ({
|
|
62913
|
+
role: fit.role,
|
|
62914
|
+
name: roleInfo(fit.role, cachedAgentDefinitions).name,
|
|
62915
|
+
probes: [...fit.probes],
|
|
62916
|
+
lookFor: fit.lookFor
|
|
62917
|
+
})),
|
|
62918
|
+
expertGuidance: EXPERT_GUIDANCE,
|
|
62919
|
+
assessor: describeAssessor(),
|
|
62178
62920
|
...settings?.reportsCost !== void 0 ? { reportsCost: settings.reportsCost } : {},
|
|
62179
62921
|
...settings?.pricing !== void 0 ? { pricing: settings.pricing } : {},
|
|
62180
62922
|
...measuringStep !== void 0 ? { measuringStep } : {},
|
|
@@ -62195,7 +62937,9 @@ ${preview.text}` } : {}
|
|
|
62195
62937
|
cliAvailable: cli?.available === true
|
|
62196
62938
|
};
|
|
62197
62939
|
const assigned = new Map(resolveTeam(teamContext).map((agent) => [agent.role, agent]));
|
|
62198
|
-
const
|
|
62940
|
+
const definitions = config2.agents?.definitions ?? [];
|
|
62941
|
+
const customIds = new Set(definitions.map((definition) => definition.id));
|
|
62942
|
+
const roles = allRoles(definitions).map((info) => {
|
|
62199
62943
|
const agent = assigned.get(info.role);
|
|
62200
62944
|
const prompt = config2.agents?.roles?.[info.role]?.prompt;
|
|
62201
62945
|
return {
|
|
@@ -62207,8 +62951,18 @@ ${preview.text}` } : {}
|
|
|
62207
62951
|
label: agent?.label ?? "Nobody",
|
|
62208
62952
|
available: agent?.available ?? false,
|
|
62209
62953
|
...agent?.reason !== void 0 ? { reason: agent.reason } : {},
|
|
62210
|
-
prompt: prompt ?? defaultPromptFor(info.role),
|
|
62211
|
-
promptIsDefault: prompt === void 0
|
|
62954
|
+
prompt: prompt ?? defaultPromptFor(info.role, definitions),
|
|
62955
|
+
promptIsDefault: prompt === void 0,
|
|
62956
|
+
...customIds.has(info.role) ? { custom: true } : {},
|
|
62957
|
+
// The assignment's override where there is one, else the role's own default — the same
|
|
62958
|
+
// resolution `resolveTeam` does, so the switch in the tab shows what will actually happen.
|
|
62959
|
+
usesTools: config2.agents?.roles?.[info.role]?.tools ?? info.usesTools,
|
|
62960
|
+
canWrite: config2.agents?.roles?.[info.role]?.write ?? info.canWrite,
|
|
62961
|
+
enabled: config2.agents?.roles?.[info.role]?.enabled !== false,
|
|
62962
|
+
...(() => {
|
|
62963
|
+
const level = config2.agents?.roles?.[info.role]?.thinking;
|
|
62964
|
+
return level !== void 0 ? { thinking: level } : {};
|
|
62965
|
+
})()
|
|
62212
62966
|
};
|
|
62213
62967
|
});
|
|
62214
62968
|
const guidance = config2.agents?.teamGuidance;
|
|
@@ -62219,6 +62973,14 @@ ${preview.text}` } : {}
|
|
|
62219
62973
|
cliAvailable: teamContext.cliAvailable,
|
|
62220
62974
|
...cli?.available === false && cli.reason !== void 0 ? { cliReason: cli.reason } : {},
|
|
62221
62975
|
budgetMatters: budgetMatters(teamContext),
|
|
62976
|
+
/*
|
|
62977
|
+
* Assigned, rather than assigned *and* detected.
|
|
62978
|
+
*
|
|
62979
|
+
* Somebody who put Claude in a seat on a machine where it is momentarily missing has still
|
|
62980
|
+
* said they intend to spend money there, and taking the budget controls away from them
|
|
62981
|
+
* because a probe failed would be the panel arguing with the user.
|
|
62982
|
+
*/
|
|
62983
|
+
claudeSeated: [...assigned.values()].some((agent) => agent.kind === "cli"),
|
|
62222
62984
|
teamGuidance: guidance ?? DEFAULT_TEAM_GUIDANCE,
|
|
62223
62985
|
defaultTeamGuidance: DEFAULT_TEAM_GUIDANCE,
|
|
62224
62986
|
teamGuidanceIsDefault: guidance === void 0,
|
|
@@ -62237,6 +62999,51 @@ ${preview.text}` } : {}
|
|
|
62237
62999
|
}
|
|
62238
63000
|
});
|
|
62239
63001
|
}
|
|
63002
|
+
async function handleSaveCustomRole(role) {
|
|
63003
|
+
const id = role.id.trim().toLowerCase();
|
|
63004
|
+
if (!isValidRoleId(id)) {
|
|
63005
|
+
post({
|
|
63006
|
+
type: "error",
|
|
63007
|
+
message: `"${id}" is not a usable role id. Use lowercase letters, digits and hyphens, starting with a letter, and not the name of a built-in role.`
|
|
63008
|
+
});
|
|
63009
|
+
return;
|
|
63010
|
+
}
|
|
63011
|
+
if (role.name.trim().length === 0) {
|
|
63012
|
+
post({ type: "error", message: "A role needs a name." });
|
|
63013
|
+
return;
|
|
63014
|
+
}
|
|
63015
|
+
await saveAgents((current) => {
|
|
63016
|
+
const definitions = [...current.definitions ?? []];
|
|
63017
|
+
const at = definitions.findIndex((candidate) => candidate.id === id);
|
|
63018
|
+
const next = {
|
|
63019
|
+
id,
|
|
63020
|
+
name: role.name.trim(),
|
|
63021
|
+
summary: role.summary.trim(),
|
|
63022
|
+
prompt: role.prompt.trim(),
|
|
63023
|
+
usesTools: role.usesTools,
|
|
63024
|
+
canWrite: role.canWrite === true
|
|
63025
|
+
};
|
|
63026
|
+
if (at === -1) {
|
|
63027
|
+
if (definitions.length >= CUSTOM_ROLE_LIMIT) {
|
|
63028
|
+
throw new Error(`That would be ${String(definitions.length + 1)} custom roles. The limit is ${String(CUSTOM_ROLE_LIMIT)}: the expert allocates from this list, and its judgement is what a longer one costs.`);
|
|
63029
|
+
}
|
|
63030
|
+
definitions.push(next);
|
|
63031
|
+
} else
|
|
63032
|
+
definitions[at] = next;
|
|
63033
|
+
return { ...current, definitions };
|
|
63034
|
+
});
|
|
63035
|
+
}
|
|
63036
|
+
async function handleDeleteCustomRole(id) {
|
|
63037
|
+
await saveAgents((current) => {
|
|
63038
|
+
const roles = { ...current.roles ?? {} };
|
|
63039
|
+
delete roles[id];
|
|
63040
|
+
return {
|
|
63041
|
+
...current,
|
|
63042
|
+
roles,
|
|
63043
|
+
definitions: (current.definitions ?? []).filter((candidate) => candidate.id !== id)
|
|
63044
|
+
};
|
|
63045
|
+
});
|
|
63046
|
+
}
|
|
62240
63047
|
async function saveAgents(change) {
|
|
62241
63048
|
try {
|
|
62242
63049
|
const { config: config2 } = await configManager.load();
|
|
@@ -62399,24 +63206,89 @@ ${preview.text}` } : {}
|
|
|
62399
63206
|
await postExpert({ redetect: false });
|
|
62400
63207
|
}
|
|
62401
63208
|
}
|
|
62402
|
-
|
|
63209
|
+
function describeAssessor() {
|
|
63210
|
+
const expert = cachedTeam.find((agent) => agent.role === "expert");
|
|
63211
|
+
if (expert === void 0) {
|
|
63212
|
+
return { label: "Nobody is in the expert seat", available: false };
|
|
63213
|
+
}
|
|
63214
|
+
return { label: expert.label, available: expert.available };
|
|
63215
|
+
}
|
|
63216
|
+
async function askExpertSeat(question, config2, expert) {
|
|
63217
|
+
if (expert.kind === "cli") {
|
|
63218
|
+
const cli = await detectCli(config2.expert?.path ?? "claude");
|
|
63219
|
+
if (!cli.available)
|
|
63220
|
+
throw new Error("The Claude CLI is not available.");
|
|
63221
|
+
const graded = await consultExpert(cli, {
|
|
63222
|
+
question,
|
|
63223
|
+
cwd: workspaceRoot ?? process.cwd(),
|
|
63224
|
+
...config2.expert?.model !== void 0 ? { model: config2.expert.model } : {}
|
|
63225
|
+
});
|
|
63226
|
+
recordConsultation({
|
|
63227
|
+
isError: graded.isError,
|
|
63228
|
+
...graded.costUsd !== void 0 ? { costUsd: graded.costUsd } : {}
|
|
63229
|
+
});
|
|
63230
|
+
if (graded.isError)
|
|
63231
|
+
throw new Error(graded.text);
|
|
63232
|
+
return {
|
|
63233
|
+
text: graded.text,
|
|
63234
|
+
...graded.costUsd !== void 0 ? { costUsd: graded.costUsd } : {}
|
|
63235
|
+
};
|
|
63236
|
+
}
|
|
63237
|
+
const profile = config2.profiles?.find((candidate) => candidate.id === expert.profileId);
|
|
63238
|
+
if (profile === void 0) {
|
|
63239
|
+
throw new Error(`No profile "${expert.profileId ?? ""}" exists any more.`);
|
|
63240
|
+
}
|
|
63241
|
+
const seatProfile = expert.thinking === void 0 ? profile : {
|
|
63242
|
+
...profile,
|
|
63243
|
+
thinking: {
|
|
63244
|
+
...profile.thinking ?? { level: expert.thinking },
|
|
63245
|
+
level: expert.thinking
|
|
63246
|
+
}
|
|
63247
|
+
};
|
|
63248
|
+
const provider = createChatProvider(seatProfile, httpClient, authStrategyFor(config2, profile), logger);
|
|
63249
|
+
let text = "";
|
|
63250
|
+
for await (const chunk of provider.streamChat([
|
|
63251
|
+
{ role: "system", content: expert.prompt },
|
|
63252
|
+
{ role: "user", content: question }
|
|
63253
|
+
])) {
|
|
63254
|
+
if (chunk.type === "text")
|
|
63255
|
+
text += chunk.text;
|
|
63256
|
+
if (chunk.type === "error")
|
|
63257
|
+
throw new Error(chunk.error);
|
|
63258
|
+
}
|
|
63259
|
+
if (text.trim().length === 0)
|
|
63260
|
+
throw new Error("The expert replied with nothing.");
|
|
63261
|
+
return { text };
|
|
63262
|
+
}
|
|
63263
|
+
async function handleAssessJunior(profileId) {
|
|
62403
63264
|
if (assessmentStep !== void 0)
|
|
62404
63265
|
return;
|
|
62405
63266
|
try {
|
|
62406
63267
|
const { config: config2 } = await configManager.load();
|
|
62407
|
-
const cli = await
|
|
62408
|
-
|
|
63268
|
+
const cli = await detectCli(config2.expert?.path ?? "claude").catch(() => void 0);
|
|
63269
|
+
const team = resolveTeam({
|
|
63270
|
+
config: config2.agents,
|
|
63271
|
+
profiles: (config2.profiles ?? []).map((entry) => ({ id: entry.id, label: entry.label })),
|
|
63272
|
+
cliAvailable: cli?.available === true
|
|
63273
|
+
});
|
|
63274
|
+
const expert = team.find((agent) => agent.role === "expert" && agent.available);
|
|
63275
|
+
if (expert === void 0) {
|
|
62409
63276
|
post({
|
|
62410
63277
|
type: "error",
|
|
62411
|
-
message: "
|
|
63278
|
+
message: "Nothing is in the expert seat. Assign one in the Agents tab - the assessment is its judgement, not ours."
|
|
62412
63279
|
});
|
|
62413
63280
|
return;
|
|
62414
63281
|
}
|
|
62415
|
-
const
|
|
63282
|
+
const chosen = profileId === void 0 ? void 0 : config2.profiles?.find((candidate) => candidate.id === profileId);
|
|
63283
|
+
if (profileId !== void 0 && chosen === void 0) {
|
|
63284
|
+
post({ type: "error", message: "That profile no longer exists." });
|
|
63285
|
+
return;
|
|
63286
|
+
}
|
|
63287
|
+
const profile = chosen ?? resolveActiveProfile(config2);
|
|
62416
63288
|
const provider = createChatProvider(profile, httpClient, authStrategyFor(config2, profile), logger);
|
|
62417
63289
|
const results = [];
|
|
62418
63290
|
for (const [index, probe2] of ASSESSMENT_PROBES.entries()) {
|
|
62419
|
-
assessmentStep = `Asking
|
|
63291
|
+
assessmentStep = `Asking ${profile.label ?? profile.model}: ${probe2.measures} (${String(index + 1)}/${String(ASSESSMENT_PROBES.length)})`;
|
|
62420
63292
|
await postExpert({ redetect: false });
|
|
62421
63293
|
let answer = "";
|
|
62422
63294
|
try {
|
|
@@ -62439,21 +63311,9 @@ ${preview.text}` } : {}
|
|
|
62439
63311
|
});
|
|
62440
63312
|
}
|
|
62441
63313
|
}
|
|
62442
|
-
assessmentStep =
|
|
63314
|
+
assessmentStep = `Asking ${expert.label} to grade the answers`;
|
|
62443
63315
|
await postExpert({ redetect: false });
|
|
62444
|
-
const graded = await
|
|
62445
|
-
question: buildAssessmentQuestion(profile.model, results),
|
|
62446
|
-
cwd: workspaceRoot ?? process.cwd(),
|
|
62447
|
-
...config2.expert?.model !== void 0 ? { model: config2.expert.model } : {}
|
|
62448
|
-
});
|
|
62449
|
-
recordConsultation({
|
|
62450
|
-
isError: graded.isError,
|
|
62451
|
-
...graded.costUsd !== void 0 ? { costUsd: graded.costUsd } : {}
|
|
62452
|
-
});
|
|
62453
|
-
if (graded.isError) {
|
|
62454
|
-
post({ type: "error", message: `The expert could not assess the junior: ${graded.text}` });
|
|
62455
|
-
return;
|
|
62456
|
-
}
|
|
63316
|
+
const graded = await askExpertSeat(buildAssessmentQuestion(profile.model, results), config2, expert);
|
|
62457
63317
|
const assessment = {
|
|
62458
63318
|
model: profile.model,
|
|
62459
63319
|
profileLabel: profile.label ?? profile.model,
|
|
@@ -62463,7 +63323,12 @@ ${preview.text}` } : {}
|
|
|
62463
63323
|
...graded.costUsd !== void 0 ? { costUsd: graded.costUsd } : {}
|
|
62464
63324
|
};
|
|
62465
63325
|
const latest = (await configManager.load()).config;
|
|
62466
|
-
await configManager.save("user", {
|
|
63326
|
+
await configManager.save("user", {
|
|
63327
|
+
expert: {
|
|
63328
|
+
...latest.expert,
|
|
63329
|
+
assessments: recordAssessment(allAssessments(latest.expert ?? {}), assessment)
|
|
63330
|
+
}
|
|
63331
|
+
});
|
|
62467
63332
|
} catch (error51) {
|
|
62468
63333
|
post({ type: "error", message: error51 instanceof Error ? error51.message : String(error51) });
|
|
62469
63334
|
} finally {
|
|
@@ -62471,10 +63336,16 @@ ${preview.text}` } : {}
|
|
|
62471
63336
|
await postExpert({ redetect: false });
|
|
62472
63337
|
}
|
|
62473
63338
|
}
|
|
62474
|
-
async function handleClearAssessment() {
|
|
63339
|
+
async function handleClearAssessment(model, profileLabel) {
|
|
62475
63340
|
const { config: config2 } = await configManager.load();
|
|
62476
63341
|
const expert = { ...config2.expert };
|
|
62477
|
-
|
|
63342
|
+
if (model === void 0 || profileLabel === void 0) {
|
|
63343
|
+
delete expert.assessment;
|
|
63344
|
+
delete expert.assessments;
|
|
63345
|
+
} else {
|
|
63346
|
+
expert.assessments = forgetAssessment(allAssessments(expert), model, profileLabel);
|
|
63347
|
+
delete expert.assessment;
|
|
63348
|
+
}
|
|
62478
63349
|
await configManager.save("user", { expert });
|
|
62479
63350
|
await postExpert();
|
|
62480
63351
|
}
|
|
@@ -64268,6 +65139,7 @@ ${preview.text}` } : {}
|
|
|
64268
65139
|
// disagree — a specialist told it can read, and then given nothing to read with, wastes a
|
|
64269
65140
|
// step discovering that.
|
|
64270
65141
|
usesTools: agent.usesTools,
|
|
65142
|
+
canWrite: agent.canWrite,
|
|
64271
65143
|
...request.files !== void 0 ? { files: request.files } : {},
|
|
64272
65144
|
/*
|
|
64273
65145
|
* What exists in this workspace.
|
|
@@ -64296,6 +65168,11 @@ ${preview.text}` } : {}
|
|
|
64296
65168
|
const cli = expertCli;
|
|
64297
65169
|
if (cli === void 0 || !cli.available)
|
|
64298
65170
|
throw new Error("The Claude CLI is not available.");
|
|
65171
|
+
if (cachedBudgetMatters) {
|
|
65172
|
+
const verdict = checkExpertBudget(expertSpend, effectiveExpertLimits());
|
|
65173
|
+
if (!verdict.allowed)
|
|
65174
|
+
throw new Error(verdict.message);
|
|
65175
|
+
}
|
|
64299
65176
|
const answer = await consultExpert(cli, {
|
|
64300
65177
|
question: prompt,
|
|
64301
65178
|
/*
|
|
@@ -64306,6 +65183,10 @@ ${preview.text}` } : {}
|
|
|
64306
65183
|
cwd: workspaceRoot ?? process.cwd(),
|
|
64307
65184
|
...request.signal !== void 0 ? { signal: request.signal } : {}
|
|
64308
65185
|
});
|
|
65186
|
+
recordConsultation({
|
|
65187
|
+
isError: answer.isError,
|
|
65188
|
+
...answer.costUsd !== void 0 ? { costUsd: answer.costUsd } : {}
|
|
65189
|
+
});
|
|
64309
65190
|
if (answer.isError)
|
|
64310
65191
|
throw new Error(answer.text);
|
|
64311
65192
|
return { advice: answer.text, label: agent.label };
|
|
@@ -64315,8 +65196,18 @@ ${preview.text}` } : {}
|
|
|
64315
65196
|
if (profile === void 0) {
|
|
64316
65197
|
throw new Error(`No profile "${agent.profileId ?? ""}" exists any more.`);
|
|
64317
65198
|
}
|
|
64318
|
-
const
|
|
64319
|
-
|
|
65199
|
+
const seatProfile = agent.thinking === void 0 ? profile : {
|
|
65200
|
+
...profile,
|
|
65201
|
+
thinking: { ...profile.thinking ?? { level: agent.thinking }, level: agent.thinking }
|
|
65202
|
+
};
|
|
65203
|
+
const provider = createChatProvider(seatProfile, httpClient, authStrategyFor(config2, profile), logger);
|
|
65204
|
+
const extraTools = new Set(agent.role === "librarian" ? ["write_skill"] : []);
|
|
65205
|
+
if (agent.canWrite) {
|
|
65206
|
+
extraTools.add("write_to_file");
|
|
65207
|
+
extraTools.add("apply_diff");
|
|
65208
|
+
extraTools.add("write_skill");
|
|
65209
|
+
}
|
|
65210
|
+
const readOnly = agent.usesTools ? toolsForConsultation(agentBriefingTools?.() ?? [], extraTools) : [];
|
|
64320
65211
|
const context = consultationContext?.();
|
|
64321
65212
|
const result = await runConsultation({
|
|
64322
65213
|
provider,
|
|
@@ -64326,6 +65217,24 @@ ${preview.text}` } : {}
|
|
|
64326
65217
|
// With no context there is nothing to read *with*, so it answers from the question alone
|
|
64327
65218
|
// rather than being offered tools that would fail.
|
|
64328
65219
|
context: context ?? {},
|
|
65220
|
+
/*
|
|
65221
|
+
* The same gate the agent loop uses, so an approval raised by a specialist is
|
|
65222
|
+
* indistinguishable from one raised by the assistant — same prompt, same ground truth, same
|
|
65223
|
+
* always-ask rule. A second approval path would be a second place for the rule to be wrong.
|
|
65224
|
+
*/
|
|
65225
|
+
approve: async (tool, args) => {
|
|
65226
|
+
const preview = await tool.preview?.(args, context ?? {}).catch(() => void 0);
|
|
65227
|
+
const decision = await approvalGate.requestApproval({
|
|
65228
|
+
id: `agent-${agent.role}-${String(Date.now())}-${tool.name}`,
|
|
65229
|
+
toolName: tool.name,
|
|
65230
|
+
group: tool.group,
|
|
65231
|
+
preview: preview ?? {
|
|
65232
|
+
kind: "text",
|
|
65233
|
+
text: `The ${agent.role} wants to run ${tool.name}.`
|
|
65234
|
+
}
|
|
65235
|
+
});
|
|
65236
|
+
return decision === "approve";
|
|
65237
|
+
},
|
|
64329
65238
|
...request.signal !== void 0 ? { signal: request.signal } : {},
|
|
64330
65239
|
onStep: (name) => logger.info(`${agent.role} looked up ${name}`)
|
|
64331
65240
|
});
|
|
@@ -65035,9 +65944,9 @@ ${preview.text}` } : {}
|
|
|
65035
65944
|
await postExpert({ redetect: false });
|
|
65036
65945
|
}).catch((error51) => post({ type: "error", message: String(error51) }));
|
|
65037
65946
|
} else if (message3.type === "assessJunior") {
|
|
65038
|
-
void handleAssessJunior();
|
|
65947
|
+
void handleAssessJunior(message3.profileId);
|
|
65039
65948
|
} else if (message3.type === "clearAssessment") {
|
|
65040
|
-
void handleClearAssessment();
|
|
65949
|
+
void handleClearAssessment(message3.model, message3.profileLabel);
|
|
65041
65950
|
} else if (message3.type === "restartScheduler") {
|
|
65042
65951
|
restartScheduleTimer();
|
|
65043
65952
|
logger.info("schedule timer restarted by the user");
|
|
@@ -65089,7 +65998,7 @@ ${preview.text}` } : {}
|
|
|
65089
65998
|
} else if (message3.type === "setAgentRole") {
|
|
65090
65999
|
const assignment = message3.assignment;
|
|
65091
66000
|
const role = message3.role;
|
|
65092
|
-
if (!isAgentRole(role)) {
|
|
66001
|
+
if (!isAgentRole(role, cachedAgentDefinitions)) {
|
|
65093
66002
|
post({ type: "error", message: `There is no "${role}" role.` });
|
|
65094
66003
|
return;
|
|
65095
66004
|
}
|
|
@@ -65109,7 +66018,7 @@ ${preview.text}` } : {}
|
|
|
65109
66018
|
} else if (message3.type === "setAgentPrompt") {
|
|
65110
66019
|
const role = message3.role;
|
|
65111
66020
|
const prompt = message3.prompt;
|
|
65112
|
-
if (!isAgentRole(role)) {
|
|
66021
|
+
if (!isAgentRole(role, cachedAgentDefinitions)) {
|
|
65113
66022
|
post({ type: "error", message: `There is no "${role}" role.` });
|
|
65114
66023
|
return;
|
|
65115
66024
|
}
|
|
@@ -65140,10 +66049,68 @@ ${preview.text}` } : {}
|
|
|
65140
66049
|
}
|
|
65141
66050
|
return { ...current, teamGuidance: guidance };
|
|
65142
66051
|
});
|
|
66052
|
+
} else if (message3.type === "saveCustomRole") {
|
|
66053
|
+
void handleSaveCustomRole(message3);
|
|
66054
|
+
} else if (message3.type === "deleteCustomRole") {
|
|
66055
|
+
void handleDeleteCustomRole(message3.id);
|
|
66056
|
+
} else if (message3.type === "setRoleThinking") {
|
|
66057
|
+
const role = message3.role;
|
|
66058
|
+
if (!isAgentRole(role, cachedAgentDefinitions)) {
|
|
66059
|
+
post({ type: "error", message: `There is no "${role}" role.` });
|
|
66060
|
+
return;
|
|
66061
|
+
}
|
|
66062
|
+
void saveAgents((current) => {
|
|
66063
|
+
const roles = { ...current.roles ?? {} };
|
|
66064
|
+
const existing = roles[role] ?? { kind: "profile" };
|
|
66065
|
+
if (message3.level === void 0) {
|
|
66066
|
+
const rest = { ...existing };
|
|
66067
|
+
delete rest.thinking;
|
|
66068
|
+
roles[role] = rest;
|
|
66069
|
+
} else {
|
|
66070
|
+
roles[role] = { ...existing, thinking: message3.level };
|
|
66071
|
+
}
|
|
66072
|
+
return { ...current, roles };
|
|
66073
|
+
});
|
|
66074
|
+
} else if (message3.type === "setRoleEnabled") {
|
|
66075
|
+
const role = message3.role;
|
|
66076
|
+
if (!isAgentRole(role, cachedAgentDefinitions)) {
|
|
66077
|
+
post({ type: "error", message: `There is no "${role}" role.` });
|
|
66078
|
+
return;
|
|
66079
|
+
}
|
|
66080
|
+
void saveAgents((current) => {
|
|
66081
|
+
const roles = { ...current.roles ?? {} };
|
|
66082
|
+
roles[role] = {
|
|
66083
|
+
...roles[role] ?? { kind: "profile" },
|
|
66084
|
+
enabled: message3.enabled
|
|
66085
|
+
};
|
|
66086
|
+
return { ...current, roles };
|
|
66087
|
+
});
|
|
66088
|
+
} else if (message3.type === "setRoleWrite") {
|
|
66089
|
+
const role = message3.role;
|
|
66090
|
+
if (!isAgentRole(role, cachedAgentDefinitions)) {
|
|
66091
|
+
post({ type: "error", message: `There is no "${role}" role.` });
|
|
66092
|
+
return;
|
|
66093
|
+
}
|
|
66094
|
+
void saveAgents((current) => {
|
|
66095
|
+
const roles = { ...current.roles ?? {} };
|
|
66096
|
+
roles[role] = { ...roles[role] ?? { kind: "profile" }, write: message3.canWrite };
|
|
66097
|
+
return { ...current, roles };
|
|
66098
|
+
});
|
|
66099
|
+
} else if (message3.type === "setRoleTools") {
|
|
66100
|
+
const role = message3.role;
|
|
66101
|
+
if (!isAgentRole(role, cachedAgentDefinitions)) {
|
|
66102
|
+
post({ type: "error", message: `There is no "${role}" role.` });
|
|
66103
|
+
return;
|
|
66104
|
+
}
|
|
66105
|
+
void saveAgents((current) => {
|
|
66106
|
+
const roles = { ...current.roles ?? {} };
|
|
66107
|
+
roles[role] = { ...roles[role] ?? { kind: "profile" }, tools: message3.usesTools };
|
|
66108
|
+
return { ...current, roles };
|
|
66109
|
+
});
|
|
65143
66110
|
} else if (message3.type === "setAgentColor") {
|
|
65144
66111
|
const role = message3.role;
|
|
65145
66112
|
const color = message3.color;
|
|
65146
|
-
if (!isAgentRole(role)) {
|
|
66113
|
+
if (!isAgentRole(role, cachedAgentDefinitions)) {
|
|
65147
66114
|
post({ type: "error", message: `There is no "${role}" role.` });
|
|
65148
66115
|
return;
|
|
65149
66116
|
}
|