@chosengeneration/light-code 0.56.1 → 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/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.
@@ -39688,7 +39715,16 @@ var agentAssignmentSchema = external_exports.object({
39688
39715
  * prompt and the flags they set up. Absent means on, so nothing changes for a config written
39689
39716
  * before this.
39690
39717
  */
39691
- enabled: external_exports.boolean().optional()
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()
39692
39728
  }).strict();
39693
39729
  var customRoleSchema = external_exports.object({
39694
39730
  id: external_exports.string().min(1),
@@ -39736,6 +39772,20 @@ var workspaceApprovalsSchema = external_exports.object({
39736
39772
  /** Exact command strings — never patterns. See approval/commands.ts and §8. */
39737
39773
  allowedCommands: external_exports.array(external_exports.string())
39738
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
+ });
39739
39789
  var expertConfigSchema = external_exports.object({
39740
39790
  /** Off unless explicitly enabled. Nothing is spawned or spent without this. */
39741
39791
  enabled: external_exports.boolean(),
@@ -39768,20 +39818,16 @@ var expertConfigSchema = external_exports.object({
39768
39818
  * there is one, for the model that was assessed, and it records which that was so a stale
39769
39819
  * one is recognisable rather than silently applied to a different model.
39770
39820
  */
39771
- assessment: external_exports.object({
39772
- model: external_exports.string(),
39773
- profileLabel: external_exports.string(),
39774
- assessedAt: external_exports.number(),
39775
- verdict: external_exports.string(),
39776
- costUsd: external_exports.number().optional(),
39777
- probes: external_exports.array(external_exports.object({
39778
- id: external_exports.string(),
39779
- measures: external_exports.string(),
39780
- prompt: external_exports.string(),
39781
- answer: external_exports.string(),
39782
- error: external_exports.string().optional()
39783
- }))
39784
- }).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(),
39785
39831
  /**
39786
39832
  * Consultations allowed within one task. 0 means no limit.
39787
39833
  *
@@ -42205,6 +42251,98 @@ function normalizeObjectSchema(parameters) {
42205
42251
  return normalized;
42206
42252
  }
42207
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
+
42208
42346
  // ../../packages/core/dist/providers/openai.js
42209
42347
  function describeRequestError(error51, url2) {
42210
42348
  return `Could not reach ${url2}: ${describeTlsError(error51)}`;
@@ -42259,6 +42397,11 @@ var OpenAIProvider = class {
42259
42397
  body.tools = toOpenAITools(options.tools);
42260
42398
  body.tool_choice = "auto";
42261
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);
42262
42405
  let response;
42263
42406
  try {
42264
42407
  await this.auth.ensureTokenForStream?.();
@@ -42343,6 +42486,7 @@ async function* parseSseStream(body, url2, signal, logger) {
42343
42486
  const reader = body.getReader();
42344
42487
  const decoder = new TextDecoder();
42345
42488
  let buffer = "";
42489
+ const thinking = new ThinkTagSplitter();
42346
42490
  const toolCallAccumulators = /* @__PURE__ */ new Map();
42347
42491
  try {
42348
42492
  while (true) {
@@ -42373,7 +42517,11 @@ async function* parseSseStream(body, url2, signal, logger) {
42373
42517
  yield { type: "reasoning", text: reasoning };
42374
42518
  }
42375
42519
  if (typeof choice.delta.content === "string" && choice.delta.content.length > 0) {
42376
- yield { type: "text", text: choice.delta.content };
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 };
42377
42525
  }
42378
42526
  accumulateToolCallDeltas(toolCallAccumulators, choice.delta.tool_calls);
42379
42527
  if (choice.finishReason === "tool_calls") {
@@ -42425,6 +42573,11 @@ var AnthropicProvider = class {
42425
42573
  };
42426
42574
  if (system !== void 0)
42427
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);
42428
42581
  if (options.tools !== void 0 && options.tools.length > 0) {
42429
42582
  body.tools = toAnthropicTools(options.tools);
42430
42583
  }
@@ -42650,6 +42803,21 @@ var GeminiProvider = class {
42650
42803
  if (this.profile.maxTokens !== void 0) {
42651
42804
  body.generationConfig = { maxOutputTokens: this.profile.maxTokens };
42652
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
+ }
42653
42821
  let response;
42654
42822
  try {
42655
42823
  await this.auth.ensureTokenForStream?.();
@@ -44246,6 +44414,7 @@ function resolveTeam(context) {
44246
44414
  const prompt = assignment.prompt ?? defaultPromptFor(role, custom2);
44247
44415
  const usesTools = assignment.tools ?? info.usesTools;
44248
44416
  const canWrite = assignment.write ?? info.canWrite;
44417
+ const thinking = assignment.thinking;
44249
44418
  if (assignment.kind === "cli") {
44250
44419
  resolved.push({
44251
44420
  role,
@@ -44256,6 +44425,7 @@ function resolveTeam(context) {
44256
44425
  prompt,
44257
44426
  usesTools,
44258
44427
  canWrite,
44428
+ ...thinking !== void 0 ? { thinking } : {},
44259
44429
  available: context.cliAvailable,
44260
44430
  ...context.cliAvailable ? {} : { reason: "The Claude CLI is not available on this machine." }
44261
44431
  });
@@ -44274,6 +44444,7 @@ function resolveTeam(context) {
44274
44444
  prompt,
44275
44445
  usesTools,
44276
44446
  canWrite,
44447
+ ...thinking !== void 0 ? { thinking } : {},
44277
44448
  available: profile !== void 0,
44278
44449
  /*
44279
44450
  * A profile that has been deleted leaves the role unavailable and says so, rather than
@@ -45001,6 +45172,58 @@ function buildExpertBriefing(input) {
45001
45172
  return sections.join("\n");
45002
45173
  }
45003
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
+
45004
45227
  // ../../packages/core/dist/expert/budget.js
45005
45228
  function money2(value) {
45006
45229
  return `$${value.toFixed(value < 1 ? 4 : 2)}`;
@@ -59696,6 +59919,39 @@ var OfficeBridge = class {
59696
59919
  }
59697
59920
  };
59698
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
+
59699
59955
  // ../../packages/core/dist/tools/roleTools.js
59700
59956
  var readParams = external_exports.object({
59701
59957
  role: external_exports.string().describe("Which role to read \u2014 one of the roles configured here. Omit to list them all.").optional()
@@ -59801,9 +60057,19 @@ function createUpdateRolePromptTool(access) {
59801
60057
  id: details.id,
59802
60058
  name: params.name?.trim() ?? details.name,
59803
60059
  summary: params.summary?.trim() ?? details.summary,
59804
- // Carried over rather than re-sent: this path is about identity, and the prompt has its
59805
- // own store. Passing the old one back keeps the two from disagreeing.
59806
- prompt: details.prompt,
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,
59807
60073
  usesTools: params.usesTools ?? details.usesTools
59808
60074
  });
59809
60075
  }
@@ -61140,6 +61406,9 @@ ${preview.text}` } : {}
61140
61406
  name: info.name,
61141
61407
  summary: info.summary,
61142
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,
61143
61412
  usesTools: cachedAgentRoles?.[role]?.tools ?? info.usesTools,
61144
61413
  custom: cachedAgentDefinitions.some((definition) => definition.id === role)
61145
61414
  };
@@ -61505,7 +61774,14 @@ ${preview.text}` } : {}
61505
61774
  cachedToolTimeoutSeconds = config2.tools?.timeoutSeconds;
61506
61775
  cachedToolTimeouts = config2.tools?.timeouts;
61507
61776
  cachedExpertColor = config2.ui?.expertColor ?? "#D97757";
61508
- cachedAssessment = config2.expert?.assessment;
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);
61509
61785
  cachedReportsCost = config2.expert?.reportsCost;
61510
61786
  cachedPricing = config2.expert?.pricing;
61511
61787
  cachedKeepAlive = config2.expert?.keepAlive === true;
@@ -62126,7 +62402,11 @@ ${preview.text}` } : {}
62126
62402
  pythonNestedContext = toolContext;
62127
62403
  pythonNestedCallsAllowed = schedule === void 0;
62128
62404
  const mentions = await resolveMentions(text, { fs: toolContext.fs, workspaceRoot, denylist });
62129
- const messageText = attachMentions(text, mentions);
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);
62130
62410
  const turnOptions = {
62131
62411
  signal: activeAbortController.signal,
62132
62412
  truncationStore,
@@ -62618,7 +62898,25 @@ ${preview.text}` } : {}
62618
62898
  maxConsultations: settings?.maxConsultations ?? 0,
62619
62899
  keepAlive: settings?.keepAlive === true,
62620
62900
  ...settings?.model !== void 0 ? { model: settings.model } : {},
62621
- ...settings?.assessment !== void 0 ? { assessment: settings.assessment } : {},
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(),
62622
62920
  ...settings?.reportsCost !== void 0 ? { reportsCost: settings.reportsCost } : {},
62623
62921
  ...settings?.pricing !== void 0 ? { pricing: settings.pricing } : {},
62624
62922
  ...measuringStep !== void 0 ? { measuringStep } : {},
@@ -62660,7 +62958,11 @@ ${preview.text}` } : {}
62660
62958
  // resolution `resolveTeam` does, so the switch in the tab shows what will actually happen.
62661
62959
  usesTools: config2.agents?.roles?.[info.role]?.tools ?? info.usesTools,
62662
62960
  canWrite: config2.agents?.roles?.[info.role]?.write ?? info.canWrite,
62663
- enabled: config2.agents?.roles?.[info.role]?.enabled !== false
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
+ })()
62664
62966
  };
62665
62967
  });
62666
62968
  const guidance = config2.agents?.teamGuidance;
@@ -62671,6 +62973,14 @@ ${preview.text}` } : {}
62671
62973
  cliAvailable: teamContext.cliAvailable,
62672
62974
  ...cli?.available === false && cli.reason !== void 0 ? { cliReason: cli.reason } : {},
62673
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"),
62674
62984
  teamGuidance: guidance ?? DEFAULT_TEAM_GUIDANCE,
62675
62985
  defaultTeamGuidance: DEFAULT_TEAM_GUIDANCE,
62676
62986
  teamGuidanceIsDefault: guidance === void 0,
@@ -62896,24 +63206,89 @@ ${preview.text}` } : {}
62896
63206
  await postExpert({ redetect: false });
62897
63207
  }
62898
63208
  }
62899
- async function handleAssessJunior() {
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) {
62900
63264
  if (assessmentStep !== void 0)
62901
63265
  return;
62902
63266
  try {
62903
63267
  const { config: config2 } = await configManager.load();
62904
- const cli = await resolveExpert(config2);
62905
- if (cli === void 0) {
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) {
62906
63276
  post({
62907
63277
  type: "error",
62908
- message: "Enable the expert first \u2014 the assessment is its judgement, not ours."
63278
+ message: "Nothing is in the expert seat. Assign one in the Agents tab - the assessment is its judgement, not ours."
62909
63279
  });
62910
63280
  return;
62911
63281
  }
62912
- const profile = resolveActiveProfile(config2);
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);
62913
63288
  const provider = createChatProvider(profile, httpClient, authStrategyFor(config2, profile), logger);
62914
63289
  const results = [];
62915
63290
  for (const [index, probe2] of ASSESSMENT_PROBES.entries()) {
62916
- assessmentStep = `Asking the junior: ${probe2.measures} (${String(index + 1)}/${String(ASSESSMENT_PROBES.length)})`;
63291
+ assessmentStep = `Asking ${profile.label ?? profile.model}: ${probe2.measures} (${String(index + 1)}/${String(ASSESSMENT_PROBES.length)})`;
62917
63292
  await postExpert({ redetect: false });
62918
63293
  let answer = "";
62919
63294
  try {
@@ -62936,21 +63311,9 @@ ${preview.text}` } : {}
62936
63311
  });
62937
63312
  }
62938
63313
  }
62939
- assessmentStep = "Asking the expert to grade the answers";
63314
+ assessmentStep = `Asking ${expert.label} to grade the answers`;
62940
63315
  await postExpert({ redetect: false });
62941
- const graded = await consultExpert(cli, {
62942
- question: buildAssessmentQuestion(profile.model, results),
62943
- cwd: workspaceRoot ?? process.cwd(),
62944
- ...config2.expert?.model !== void 0 ? { model: config2.expert.model } : {}
62945
- });
62946
- recordConsultation({
62947
- isError: graded.isError,
62948
- ...graded.costUsd !== void 0 ? { costUsd: graded.costUsd } : {}
62949
- });
62950
- if (graded.isError) {
62951
- post({ type: "error", message: `The expert could not assess the junior: ${graded.text}` });
62952
- return;
62953
- }
63316
+ const graded = await askExpertSeat(buildAssessmentQuestion(profile.model, results), config2, expert);
62954
63317
  const assessment = {
62955
63318
  model: profile.model,
62956
63319
  profileLabel: profile.label ?? profile.model,
@@ -62960,7 +63323,12 @@ ${preview.text}` } : {}
62960
63323
  ...graded.costUsd !== void 0 ? { costUsd: graded.costUsd } : {}
62961
63324
  };
62962
63325
  const latest = (await configManager.load()).config;
62963
- await configManager.save("user", { expert: { ...latest.expert, assessment } });
63326
+ await configManager.save("user", {
63327
+ expert: {
63328
+ ...latest.expert,
63329
+ assessments: recordAssessment(allAssessments(latest.expert ?? {}), assessment)
63330
+ }
63331
+ });
62964
63332
  } catch (error51) {
62965
63333
  post({ type: "error", message: error51 instanceof Error ? error51.message : String(error51) });
62966
63334
  } finally {
@@ -62968,10 +63336,16 @@ ${preview.text}` } : {}
62968
63336
  await postExpert({ redetect: false });
62969
63337
  }
62970
63338
  }
62971
- async function handleClearAssessment() {
63339
+ async function handleClearAssessment(model, profileLabel) {
62972
63340
  const { config: config2 } = await configManager.load();
62973
63341
  const expert = { ...config2.expert };
62974
- delete expert.assessment;
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
+ }
62975
63349
  await configManager.save("user", { expert });
62976
63350
  await postExpert();
62977
63351
  }
@@ -64822,7 +65196,11 @@ ${preview.text}` } : {}
64822
65196
  if (profile === void 0) {
64823
65197
  throw new Error(`No profile "${agent.profileId ?? ""}" exists any more.`);
64824
65198
  }
64825
- const provider = createChatProvider(profile, httpClient, authStrategyFor(config2, profile), logger);
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);
64826
65204
  const extraTools = new Set(agent.role === "librarian" ? ["write_skill"] : []);
64827
65205
  if (agent.canWrite) {
64828
65206
  extraTools.add("write_to_file");
@@ -65566,9 +65944,9 @@ ${preview.text}` } : {}
65566
65944
  await postExpert({ redetect: false });
65567
65945
  }).catch((error51) => post({ type: "error", message: String(error51) }));
65568
65946
  } else if (message3.type === "assessJunior") {
65569
- void handleAssessJunior();
65947
+ void handleAssessJunior(message3.profileId);
65570
65948
  } else if (message3.type === "clearAssessment") {
65571
- void handleClearAssessment();
65949
+ void handleClearAssessment(message3.model, message3.profileLabel);
65572
65950
  } else if (message3.type === "restartScheduler") {
65573
65951
  restartScheduleTimer();
65574
65952
  logger.info("schedule timer restarted by the user");
@@ -65675,6 +66053,24 @@ ${preview.text}` } : {}
65675
66053
  void handleSaveCustomRole(message3);
65676
66054
  } else if (message3.type === "deleteCustomRole") {
65677
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
+ });
65678
66074
  } else if (message3.type === "setRoleEnabled") {
65679
66075
  const role = message3.role;
65680
66076
  if (!isAgentRole(role, cachedAgentDefinitions)) {