@chosengeneration/light-code 0.44.0 → 0.46.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 CHANGED
@@ -39758,6 +39758,34 @@ var pythonConfigSchema = external_exports.object({
39758
39758
  })
39759
39759
  ]))
39760
39760
  }).partial();
39761
+ var agentAssignmentSchema = external_exports.object({
39762
+ /** `cli` is the Claude command line; `profile` names one of the user's provider profiles. */
39763
+ kind: external_exports.enum(["cli", "profile"]),
39764
+ profileId: external_exports.string().optional(),
39765
+ /**
39766
+ * The role's system prompt, stored only when the user has edited it.
39767
+ *
39768
+ * Absent means "use the default", which is what lets an improved default reach somebody who
39769
+ * has looked at the tab without editing anything. Storing the default verbatim would pin
39770
+ * every user to whatever it said the day they first opened it.
39771
+ */
39772
+ prompt: external_exports.string().optional()
39773
+ }).strict();
39774
+ var agentsConfigSchema = external_exports.object({
39775
+ roles: external_exports.record(external_exports.string(), agentAssignmentSchema),
39776
+ /** Whether what a consultation costs is worth managing. See `agents/team.ts`. */
39777
+ budgetMatters: external_exports.boolean(),
39778
+ /** The Agent team mode instruction, when edited. The roster is always generated. */
39779
+ teamGuidance: external_exports.string(),
39780
+ /**
39781
+ * A colour per role, for marking whose words a piece of advice is.
39782
+ *
39783
+ * Here rather than under `appearance` because it is keyed by role, and the roles are defined
39784
+ * here — splitting them would mean adding a role in one place and remembering to give it a
39785
+ * colour in another, which is the drift this project keeps paying for.
39786
+ */
39787
+ colors: external_exports.record(external_exports.string(), external_exports.string())
39788
+ }).partial();
39761
39789
  var autoApproveSchema = external_exports.object({
39762
39790
  read: external_exports.boolean(),
39763
39791
  edit: external_exports.boolean(),
@@ -40139,6 +40167,7 @@ var configSchema = external_exports.object({
40139
40167
  /** User-scope only: a workspace able to add a trusted root could enable interception. */
40140
40168
  tls: globalTlsSchema,
40141
40169
  expert: expertConfigSchema,
40170
+ agents: agentsConfigSchema,
40142
40171
  /**
40143
40172
  * User-scope only (invariant 5). A workspace able to name a cluster or repoint the
40144
40173
  * embedder would exfiltrate whatever gets indexed — sharper than the existing entries,
@@ -40795,6 +40824,11 @@ var USER_SCOPE_ONLY_KEYS = [
40795
40824
  // its choosing as soon as the panel opened — the same threat as `python.uvPath`.
40796
40825
  // `expert.enabled` is here too, so a repo cannot switch on paid API calls by itself.
40797
40826
  "expert",
40827
+ // Names provider profiles, so a workspace able to write it could route a consultation through a
40828
+ // gateway of its choosing — the same threat as `activeProfileId`. And it carries prompts, which
40829
+ // are prose injected into a model then asked to advise on this repository's own code: a hostile
40830
+ // repo could tell the reviewer what to approve.
40831
+ "agents",
40798
40832
  // Added for Phase 8b, and the sharpest entries on this list. A workspace able to name a
40799
40833
  // cluster, or repoint the embedder at a profile of its choosing, would exfiltrate
40800
40834
  // whatever gets indexed — and what gets indexed is the source code.
@@ -43293,6 +43327,38 @@ var Conversation = class {
43293
43327
  }
43294
43328
  };
43295
43329
 
43330
+ // ../../packages/core/dist/agent/plan.js
43331
+ var PLAN_LIMIT = 4e3;
43332
+ function buildPlanGuidance(plan) {
43333
+ const trimmed = plan?.trim() ?? "";
43334
+ if (trimmed.length === 0)
43335
+ return "";
43336
+ return [
43337
+ "# The plan for this conversation",
43338
+ "",
43339
+ "The user set this. It is what you are here to do:",
43340
+ "",
43341
+ trimmed,
43342
+ "",
43343
+ "## Working to it",
43344
+ "",
43345
+ "- **Before each step, check it serves the plan.** If it does not, do not take it.",
43346
+ "- **Work the plan in order** where it has an order, and say which part you are on when you",
43347
+ " start something substantial. A reader should never have to guess where you are.",
43348
+ "- **Noticing something else is useful; acting on it is not.** If you spot an unrelated bug,",
43349
+ " a refactor worth doing, or a file that could be tidied, *say so and carry on with the*",
43350
+ " *plan*. Do not fix it because you are there. The user will ask if they want it.",
43351
+ "- **If the plan turns out to be wrong**, say so and stop rather than quietly substituting a",
43352
+ " better one. A plan the user set and a plan you preferred are different things, and only",
43353
+ " one of them was agreed.",
43354
+ "- **If something the plan needs is missing or blocked**, say which part and why, finish what",
43355
+ " can be finished, and report what you left.",
43356
+ "",
43357
+ "When you finish, `attempt_completion` must account for the plan: what is done, what is not,",
43358
+ "and anything you did that the plan did not ask for."
43359
+ ].join("\n");
43360
+ }
43361
+
43296
43362
  // ../../packages/core/dist/agent/systemPrompt.js
43297
43363
  function buildSystemPrompt(workspaceRoot, options = {}) {
43298
43364
  const lines = [
@@ -43373,6 +43439,9 @@ function buildSystemPrompt(workspaceRoot, options = {}) {
43373
43439
  if (options.modeGuidance !== void 0 && options.modeGuidance.length > 0) {
43374
43440
  lines.push("", options.modeGuidance);
43375
43441
  }
43442
+ const plan = buildPlanGuidance(options.plan);
43443
+ if (plan.length > 0)
43444
+ lines.push("", plan);
43376
43445
  return lines.join("\n");
43377
43446
  }
43378
43447
 
@@ -43633,7 +43702,21 @@ function createAskExpertTool(options) {
43633
43702
  return {
43634
43703
  name: "ask_expert",
43635
43704
  group: "read",
43636
- description: "Consult a stronger expert model about a hard problem: planning a multi-file change, diagnosing a bug you have already failed to fix, or choosing between designs. Each call costs the user money, so use it for genuinely difficult questions only, and there may be a per-task budget after which it stops being available. The expert can read the workspace but cannot edit or run anything. Consultations within one task continue the same conversation, so after the first one it remembers what you already told it \u2014 a follow-up is far cheaper than a fresh explanation.",
43705
+ /*
43706
+ * The rationing is said only where somebody is counting.
43707
+ *
43708
+ * "Each call costs money, use it for genuinely difficult questions only" was unconditional,
43709
+ * and it is *advice about money* — so on a deployment where nobody is metering it, it buys
43710
+ * nothing and costs something real: a model told to hoard consultations asks fewer questions
43711
+ * than it should, which is the failure this whole feature exists to avoid. It was the right
43712
+ * default when every consultation was a metered cold start on a CLI, and it stopped being
43713
+ * right when the expert became a seat any model can sit in.
43714
+ *
43715
+ * Varying the description with a *setting* is the carve-out §12 already makes: the block stays
43716
+ * byte-stable for a whole session and changes only when the user changes their mind in
43717
+ * Settings, exactly as switching the dispatcher does.
43718
+ */
43719
+ description: "Consult a stronger expert model about a hard problem: planning a multi-file change, diagnosing a bug you have already failed to fix, or choosing between designs. " + (options.budgetMatters === true ? "Each call costs the user money, so use it for genuinely difficult questions only, and there may be a per-task budget after which it stops being available. " : "Consult it whenever another reader would genuinely change what you do. ") + "The expert can read the workspace but cannot edit or run anything. Consultations within one task continue the same conversation, so after the first one it remembers what you already told it \u2014 a follow-up is far cheaper than a fresh explanation.",
43637
43720
  parametersSchema: paramsSchema2,
43638
43721
  async preview(params) {
43639
43722
  return {
@@ -43650,7 +43733,10 @@ Suggested files: ${params.files.join(", ")}` : ""}`
43650
43733
  async execute(params, context) {
43651
43734
  const verdict = options.budget?.();
43652
43735
  if (verdict !== void 0 && !verdict.allowed) {
43653
- return { content: verdict.message ?? "The expert budget for this task is exhausted.", isError: true };
43736
+ return {
43737
+ content: verdict.message ?? "The expert budget for this task is exhausted.",
43738
+ isError: true
43739
+ };
43654
43740
  }
43655
43741
  const question = params.files !== void 0 && params.files.length > 0 ? `${params.question}
43656
43742
 
@@ -43712,46 +43798,190 @@ ${withBudget}` : withBudget;
43712
43798
  };
43713
43799
  }
43714
43800
 
43715
- // ../../packages/core/dist/tools/askProviderExpert.js
43801
+ // ../../packages/core/dist/agents/roles.js
43802
+ var AGENT_ROLES = ["expert", "programmer", "reviewer", "tester", "librarian"];
43803
+ function isAgentRole(value) {
43804
+ return AGENT_ROLES.includes(value);
43805
+ }
43806
+ var SHARED = [
43807
+ "You cannot see the workspace and cannot read files, run commands or search. Everything you",
43808
+ "have is in the question. If something essential is missing, say exactly what you need and why,",
43809
+ "then give the best answer you can without it \u2014 never refuse to answer.",
43810
+ "",
43811
+ "Your reply is advice. The assistant will check it against the real code before acting, and it",
43812
+ "is responsible for the result. Be concrete, say what you are unsure about, and say plainly when",
43813
+ "something must be verified rather than assumed.",
43814
+ "",
43815
+ "Answer in prose and short lists. No preamble about being happy to help."
43816
+ ].join("\n");
43817
+ var DEFINITIONS = {
43818
+ expert: {
43819
+ name: "Expert",
43820
+ summary: "Hard problems, architecture, and deciding what to do",
43821
+ prompt: [
43822
+ "You are a senior engineer being consulted by another AI assistant that is doing the work.",
43823
+ "",
43824
+ "It has hit something hard: a change across several files to plan, a bug it has already",
43825
+ "failed to fix, or a design choice with no obvious answer. Give it your judgement.",
43826
+ "",
43827
+ "Decide *what* should happen and why. Leave the typing to the assistant \u2014 it has the files",
43828
+ "open and you do not. Where there is a real trade-off, name both sides and then choose.",
43829
+ "",
43830
+ SHARED
43831
+ ].join("\n")
43832
+ },
43833
+ programmer: {
43834
+ name: "Programmer",
43835
+ summary: "Writes the code once the plan is settled",
43836
+ prompt: [
43837
+ "You are an experienced programmer writing code for another AI assistant to apply.",
43838
+ "",
43839
+ "You are given a requirement and the surrounding code. Produce the change, matching the",
43840
+ "conventions of what you were shown rather than your own preferences \u2014 the naming, the error",
43841
+ "handling, the comment density, the way the existing code does this sort of thing.",
43842
+ "",
43843
+ "Return the code and a short note on anything non-obvious in it. Do not narrate what you are",
43844
+ "about to do, and do not rewrite things you were not asked to change.",
43845
+ "",
43846
+ SHARED
43847
+ ].join("\n")
43848
+ },
43849
+ reviewer: {
43850
+ name: "Reviewer",
43851
+ summary: "Reads a change and says what is wrong with it",
43852
+ prompt: [
43853
+ "You are reviewing a change written by another AI assistant.",
43854
+ "",
43855
+ "Your job is to find what is wrong with it. Say so plainly when something is fine, but do",
43856
+ "not pad the review with praise \u2014 an approving review that missed a bug is worse than no",
43857
+ "review, because it was believed.",
43858
+ "",
43859
+ "Look for, in this order: does it do what was asked; does it break something that used to",
43860
+ "work; what happens at the edges \u2014 empty, missing, concurrent, already-exists, fails halfway;",
43861
+ "and does it match the conventions of the code around it.",
43862
+ "",
43863
+ "For each finding say what breaks and under what input. A concern you cannot make concrete is",
43864
+ "worth one sentence, flagged as a hunch, not a paragraph.",
43865
+ "",
43866
+ SHARED
43867
+ ].join("\n")
43868
+ },
43869
+ tester: {
43870
+ name: "Tester",
43871
+ summary: "Designs cases and finds what breaks it",
43872
+ prompt: [
43873
+ "You design tests for code written by another AI assistant.",
43874
+ "",
43875
+ "Given a change, say what should be tested and why each case earns its place. Prefer the",
43876
+ "cases that would actually fail: boundaries, empty and missing values, the error path, the",
43877
+ "second call, the concurrent one, the one that fails halfway and has to be recovered from.",
43878
+ "",
43879
+ "A test that cannot fail is worth nothing \u2014 for each case you propose, say what bug it would",
43880
+ "catch. If the change is untestable as written, say what would have to change to make it",
43881
+ "testable rather than proposing a test that only asserts the code was executed.",
43882
+ "",
43883
+ SHARED
43884
+ ].join("\n")
43885
+ },
43886
+ librarian: {
43887
+ name: "Librarian",
43888
+ summary: "Skills, internal documentation and house conventions",
43889
+ prompt: [
43890
+ "You answer questions about how things are done here: internal libraries, house conventions,",
43891
+ "the shape of existing code, and what has already been written down.",
43892
+ "",
43893
+ "You are given whatever documentation, skills and code the assistant could find. Answer from",
43894
+ "that, and be explicit about the difference between what the material actually says and what",
43895
+ "you are inferring \u2014 a convention you guessed at, stated confidently, becomes the convention.",
43896
+ "",
43897
+ "If the material does not answer the question, say so and say what would. Do not fill the gap",
43898
+ "with how it is usually done elsewhere unless you label it as exactly that.",
43899
+ "",
43900
+ SHARED
43901
+ ].join("\n")
43902
+ }
43903
+ };
43904
+ function roleInfo(role) {
43905
+ return { role, ...DEFINITIONS[role] };
43906
+ }
43907
+ function allRoles() {
43908
+ return AGENT_ROLES.map(roleInfo);
43909
+ }
43910
+ function defaultPromptFor(role) {
43911
+ return DEFINITIONS[role].prompt;
43912
+ }
43913
+ function buildAgentPrompt(options) {
43914
+ const lines = [options.prompt];
43915
+ if (options.briefing !== void 0 && options.briefing.trim().length > 0) {
43916
+ lines.push("", options.briefing);
43917
+ }
43918
+ lines.push("", "---", "", options.question);
43919
+ if (options.files !== void 0 && options.files.length > 0) {
43920
+ lines.push("", "The assistant named these files as relevant. You cannot open them \u2014 they are listed so you", "know what it is looking at:", ...options.files.map((file2) => `- ${file2}`));
43921
+ }
43922
+ return lines.join("\n");
43923
+ }
43924
+
43925
+ // ../../packages/core/dist/tools/askAgent.js
43716
43926
  var paramsSchema3 = external_exports.object({
43717
- question: external_exports.string().min(1).describe("The question, with the code and context needed to answer it. The expert cannot see this conversation and cannot read files \u2014 paste what matters."),
43718
- files: external_exports.array(external_exports.string()).optional().describe("Workspace-relative paths you are working in, so the expert knows what you are looking at.")
43927
+ role: external_exports.string().describe(`Which specialist to ask: ${AGENT_ROLES.join(", ")}. Only the ones assigned in Settings \u2192 Agents can answer.`),
43928
+ question: external_exports.string().min(1).describe("The question, with the code, error or output needed to answer it. The specialist cannot see this conversation or read files \u2014 paste what matters."),
43929
+ files: external_exports.array(external_exports.string()).optional().describe("Workspace-relative paths you are working in, so it knows what you are looking at.")
43719
43930
  });
43720
- function createAskProviderExpertTool(options) {
43931
+ function createAskAgentTool(options) {
43721
43932
  return {
43722
- name: "ask_expert",
43933
+ name: "ask_agent",
43723
43934
  group: "read",
43724
- description: "Consult a stronger expert model about a hard problem: planning a multi-file change, diagnosing a bug you have already failed to fix, or choosing between designs. The expert cannot see this conversation, cannot read files and does not remember earlier consultations \u2014 put everything it needs in the question, including the relevant code. What comes back is advice: check it against the real code before acting on it.",
43935
+ description: "Consult a specialist model about the work: plan a hard change (expert), have a finished change reviewed (reviewer), find out what would break it (tester), write a piece of code (programmer), or ask how this codebase does something (librarian). The specialist cannot see this conversation, cannot read files and does not remember earlier consultations \u2014 put everything it needs in the question, including the actual code. What comes back is advice: check it against the real code before acting on it.",
43725
43936
  parametersSchema: paramsSchema3,
43726
43937
  async preview(params) {
43938
+ const agent = find(options.agents(), params.role);
43727
43939
  return {
43728
43940
  kind: "text",
43729
- // Ground truth (invariant 8): the question that will actually be sent, in full. This
43941
+ // Ground truth (invariant 8): the question that will be sent, in full, and who to. This
43730
43942
  // puts the user's code in front of another model, which is the decision being approved.
43731
- text: `Consult the expert (${options.label}):
43943
+ text: `Ask the ${params.role}${agent === void 0 ? "" : ` (${agent.label})`}:
43732
43944
 
43733
- ${params.question}${params.files !== void 0 && params.files.length > 0 ? `
43945
+ ${params.question}` + (params.files !== void 0 && params.files.length > 0 ? `
43734
43946
 
43735
- Files named as relevant: ${params.files.join(", ")}` : ""}`
43947
+ Files named as relevant: ${params.files.join(", ")}` : "")
43736
43948
  };
43737
43949
  },
43738
43950
  async execute(params, context) {
43951
+ const team = options.agents();
43952
+ const role = params.role.trim().toLowerCase();
43953
+ if (!isAgentRole(role)) {
43954
+ return { content: unknownRole(role, team), isError: true };
43955
+ }
43956
+ const agent = find(team, role);
43957
+ if (agent === void 0) {
43958
+ return {
43959
+ content: `No ${role} is assigned. ${describeTeam(team)} Assign one in Settings \u2192 Agents, or ask a different role.`,
43960
+ isError: true
43961
+ };
43962
+ }
43963
+ if (!agent.available) {
43964
+ return {
43965
+ content: `The ${role} cannot be reached: ${agent.reason ?? "it is unavailable."}`,
43966
+ isError: true
43967
+ };
43968
+ }
43739
43969
  let result;
43740
43970
  try {
43741
- result = await options.consult({
43971
+ result = await options.consult(agent, {
43742
43972
  question: params.question,
43743
43973
  ...params.files !== void 0 ? { files: params.files } : {},
43744
43974
  ...context.signal !== void 0 ? { signal: context.signal } : {}
43745
43975
  });
43746
43976
  } catch (error51) {
43747
43977
  return {
43748
- content: `The expert could not be reached: ${error51 instanceof Error ? error51.message : String(error51)}`,
43978
+ content: `The ${role} could not be reached: ${error51 instanceof Error ? error51.message : String(error51)}`,
43749
43979
  isError: true
43750
43980
  };
43751
43981
  }
43752
43982
  if (result.advice.trim().length === 0) {
43753
43983
  return {
43754
- content: "The expert returned nothing. That usually means the profile configured as the expert answered with an empty response \u2014 check it in Settings \u2192 Expert.",
43984
+ content: `The ${role} returned nothing. Check what is assigned to it in Settings \u2192 Agents.`,
43755
43985
  isError: true
43756
43986
  };
43757
43987
  }
@@ -43761,39 +43991,248 @@ Files named as relevant: ${params.files.join(", ")}` : ""}`
43761
43991
 
43762
43992
  ---
43763
43993
 
43764
- That is advice from ${result.producedBy}, which has not seen your workspace. Check it against the actual code before acting on it, and say so if it turns out to be wrong.`
43994
+ That is the ${role}'s advice, from ${result.label}, which has not seen your workspace. Check it against the actual code before acting on it, and say so if it turns out to be wrong.`
43765
43995
  };
43766
43996
  }
43767
43997
  };
43768
43998
  }
43999
+ function find(team, role) {
44000
+ const wanted = role.trim().toLowerCase();
44001
+ return team.find((agent) => agent.role === wanted);
44002
+ }
44003
+ function unknownRole(role, team) {
44004
+ return `There is no "${role}" role. The roles are: ${AGENT_ROLES.join(", ")}. ${describeTeam(team)}`;
44005
+ }
44006
+ function describeTeam(team) {
44007
+ const usable = team.filter((agent) => agent.available).map((agent) => agent.role);
44008
+ return usable.length === 0 ? "None are assigned on this machine." : `Assigned here: ${usable.join(", ")}.`;
44009
+ }
43769
44010
 
43770
- // ../../packages/core/dist/expert/providerExpert.js
43771
- function buildExpertPrompt(request) {
43772
- const lines = [
43773
- "You are a senior engineer being consulted by another AI assistant that is doing the work.",
43774
- "",
43775
- "It has hit something hard: a multi-file change to plan, a bug it has already failed to fix,",
43776
- "or a design choice to make. Give it your judgement.",
43777
- "",
43778
- "Two things about your position here:",
44011
+ // ../../packages/core/dist/agents/team.js
44012
+ function defaultAssignment(role, context) {
44013
+ return role === "expert" && context.cliAvailable ? { kind: "cli" } : void 0;
44014
+ }
44015
+ function resolveTeam(context) {
44016
+ const resolved = [];
44017
+ for (const role of AGENT_ROLES) {
44018
+ const assignment = context.config?.roles?.[role] ?? defaultAssignment(role, context);
44019
+ if (assignment === void 0)
44020
+ continue;
44021
+ const info = roleInfo(role);
44022
+ const prompt = assignment.prompt ?? defaultPromptFor(role);
44023
+ if (assignment.kind === "cli") {
44024
+ resolved.push({
44025
+ role,
44026
+ name: info.name,
44027
+ summary: info.summary,
44028
+ kind: "cli",
44029
+ label: "Claude",
44030
+ prompt,
44031
+ available: context.cliAvailable,
44032
+ ...context.cliAvailable ? {} : { reason: "The Claude CLI is not available on this machine." }
44033
+ });
44034
+ continue;
44035
+ }
44036
+ const profile = context.profiles.find((candidate) => candidate.id === assignment.profileId);
44037
+ resolved.push({
44038
+ role,
44039
+ name: info.name,
44040
+ summary: info.summary,
44041
+ kind: "profile",
44042
+ ...assignment.profileId !== void 0 ? { profileId: assignment.profileId } : {},
44043
+ label: profile?.label ?? assignment.profileId ?? "unassigned",
44044
+ prompt,
44045
+ available: profile !== void 0,
44046
+ /*
44047
+ * A profile that has been deleted leaves the role unavailable and says so, rather than
44048
+ * falling back to the model already doing the work. A specialist that is quietly the
44049
+ * primary model gives advice with nothing to distrust about it, which is worse than none.
44050
+ */
44051
+ ...profile === void 0 ? { reason: `No profile "${assignment.profileId ?? ""}" exists any more.` } : {}
44052
+ });
44053
+ }
44054
+ return resolved;
44055
+ }
44056
+ function budgetMatters(context) {
44057
+ const stated = context.config?.budgetMatters;
44058
+ if (stated !== void 0)
44059
+ return stated;
44060
+ return resolveTeam(context).some((agent) => agent.kind === "cli" && agent.available);
44061
+ }
44062
+
44063
+ // ../../packages/core/dist/agents/guidance.js
44064
+ var BUDGET_ADVICE = [
44065
+ "",
44066
+ "## Consultations cost money here",
44067
+ "",
44068
+ "Each one is charged. Make the first count \u2014 gather what is needed and ask one full question",
44069
+ "rather than opening with something you could have settled yourself. If a per-task budget runs",
44070
+ "out the specialist stops being available, and you finish the work alone, so spend it on the",
44071
+ "parts where another reader genuinely changes what you do."
44072
+ ].join("\n");
44073
+ var DEFAULT_TEAM_GUIDANCE = [
44074
+ "You lead a small team. You do the work \u2014 reading, searching, editing, running things \u2014 and you",
44075
+ "consult specialists when another reader would genuinely change what you do.",
44076
+ "",
44077
+ "## Consult without being asked",
44078
+ "",
44079
+ "You do not need permission and you should not wait to be told. Ask when:",
44080
+ "",
44081
+ "- the task spans several files and you are not sure of the shape \u2014 ask the **expert** first,",
44082
+ " before you write anything;",
44083
+ "- you have finished a change of any substance \u2014 ask the **reviewer**, and say what you changed",
44084
+ " and why, not just what the diff looks like;",
44085
+ "- you are about to call something done that has no tests \u2014 ask the **tester** what would break",
44086
+ " it;",
44087
+ "- you are guessing at how this codebase does something \u2014 ask the **librarian** rather than",
44088
+ " inventing a convention.",
44089
+ "",
44090
+ 'The user can also ask directly ("ask the reviewer to look at this"), and then you consult that',
44091
+ "role whatever you would have chosen.",
44092
+ "",
44093
+ "## What makes a consultation worth it",
44094
+ "",
44095
+ "A specialist cannot see the workspace. It knows only what you put in the question, so **paste",
44096
+ 'the code**, the error, the failing output \u2014 the actual text. A question like "is my retry logic',
44097
+ 'right?" with nothing attached comes back as a list of things retry logic usually gets wrong,',
44098
+ "which you already knew.",
44099
+ "",
44100
+ "Ask one full question rather than three thin ones. Each consultation is a fresh reader with no",
44101
+ "memory of the last, so a follow-up has to carry its own context.",
44102
+ "",
44103
+ "## What not to do",
44104
+ "",
44105
+ "- Do not consult on something you can settle by reading a file. Read it.",
44106
+ "- Do not relay advice you have not checked. You have the code open and the specialist does not;",
44107
+ " if it is wrong, say so and say why \u2014 to the user, and in your next question.",
44108
+ "- Do not consult the same role twice with the same question hoping for a better answer."
44109
+ ].join("\n");
44110
+ function buildTeamGuidance(agents, custom2, budgetMatters2) {
44111
+ const base = custom2 !== void 0 && custom2.trim().length > 0 ? custom2 : DEFAULT_TEAM_GUIDANCE;
44112
+ const advice = budgetMatters2 === true ? `${base}
44113
+ ${BUDGET_ADVICE}` : base;
44114
+ if (agents.length === 0) {
44115
+ return [
44116
+ advice,
44117
+ "",
44118
+ "## Your team",
44119
+ "",
44120
+ "**Nobody is assigned yet.** Until somebody is, do the work yourself and tell the user that",
44121
+ "assigning a specialist in Settings \u2192 Agents would let you consult one."
44122
+ ].join("\n");
44123
+ }
44124
+ return [
44125
+ advice,
43779
44126
  "",
43780
- "- You cannot see the workspace and cannot read files, run commands or search. Everything you",
43781
- " have is below. If something essential is missing, say exactly what you need and why, then",
43782
- " give the best answer you can without it \u2014 do not refuse to answer.",
43783
- "- Your reply is advice. The assistant will check it against the real code before acting, and",
43784
- " it is responsible for the result. Be concrete, say what you are unsure about, and say when",
43785
- " a thing must be verified rather than assumed.",
44127
+ "## Your team",
43786
44128
  "",
43787
- "Answer in prose and short lists. No preamble about being happy to help.",
44129
+ "Reach any of them with `ask_agent`, naming the role:",
43788
44130
  "",
43789
- "---",
44131
+ ...agents.map((agent) => `- **${agent.role}** (${agent.label}) \u2014 ${agent.summary}`)
44132
+ ].join("\n");
44133
+ }
44134
+
44135
+ // ../../packages/core/dist/agents/briefing.js
44136
+ var DESCRIPTION_LIMIT = 110;
44137
+ function firstLine(text, limit = DESCRIPTION_LIMIT) {
44138
+ const line = text.split("\n").find((candidate) => candidate.trim().length > 0)?.trim() ?? "";
44139
+ return line.length > limit ? `${line.slice(0, limit - 1).trimEnd()}\u2026` : line;
44140
+ }
44141
+ function buildAgentBriefing(input) {
44142
+ const tools = (input.tools ?? []).filter(
44143
+ // Telling a specialist it can consult a specialist is noise at best and a loop at worst.
44144
+ (tool) => tool.name !== "ask_agent" && tool.name !== "ask_expert"
44145
+ );
44146
+ const skills = input.skills ?? [];
44147
+ if (tools.length === 0 && skills.length === 0)
44148
+ return "";
44149
+ const sections = [
44150
+ "## What the assistant can do on your behalf",
43790
44151
  "",
43791
- request.question
44152
+ "You have no tools. The assistant asking you does, and will carry out whatever you recommend.",
44153
+ "Name the tool or skill you mean rather than describing a manual procedure that duplicates it."
43792
44154
  ];
43793
- if (request.files !== void 0 && request.files.length > 0) {
43794
- lines.push("", "The assistant named these files as relevant. You cannot open them \u2014 they are listed so you", "know what it is looking at:", ...request.files.map((file2) => `- ${file2}`));
44155
+ if (tools.length > 0) {
44156
+ sections.push("", "### Tools it can call", "", ...tools.map((tool) => `- \`${tool.name}\` \u2014 ${firstLine(tool.description)}`));
44157
+ }
44158
+ if (skills.length > 0) {
44159
+ sections.push("", "### Skills written for this workspace", "", "House conventions and internal knowledge, already documented. Point at one by name rather", "than restating it; the assistant can open it.", "", ...skills.map((skill) => `- **${skill.name}** \u2014 ${firstLine(skill.description)}`));
44160
+ }
44161
+ return sections.join("\n");
44162
+ }
44163
+
44164
+ // ../../packages/core/dist/agents/consult.js
44165
+ var CONSULT_MAX_STEPS = 5;
44166
+ var ALLOWED_GROUPS = /* @__PURE__ */ new Set(["read"]);
44167
+ function toolsForConsultation(all) {
44168
+ return all.filter((tool) => ALLOWED_GROUPS.has(tool.group) && tool.name !== "ask_agent" && tool.name !== "ask_expert");
44169
+ }
44170
+ async function runConsultation(options) {
44171
+ const limit = options.maxSteps ?? CONSULT_MAX_STEPS;
44172
+ const messages = [{ role: "user", content: options.prompt }];
44173
+ const byName = new Map(options.tools.map((tool) => [tool.name, tool]));
44174
+ let steps = 0;
44175
+ for (; ; ) {
44176
+ const atCap = steps >= limit;
44177
+ let text = "";
44178
+ let call;
44179
+ for await (const chunk of options.provider.streamChat(messages, {
44180
+ ...options.signal !== void 0 ? { signal: options.signal } : {},
44181
+ /*
44182
+ * The tools are withdrawn on the final pass, not merely discouraged.
44183
+ *
44184
+ * A model asked politely to stop looking things up will sometimes look one more thing up,
44185
+ * and then there is no turn left to answer in. Removing them makes answering the only
44186
+ * available move.
44187
+ */
44188
+ ...atCap || options.definitions.length === 0 ? {} : { tools: [...options.definitions] }
44189
+ })) {
44190
+ if (chunk.type === "text")
44191
+ text += chunk.text;
44192
+ else if (chunk.type === "toolCall" && call === void 0) {
44193
+ call = {
44194
+ id: chunk.toolCall.id,
44195
+ name: chunk.toolCall.name,
44196
+ arguments: chunk.toolCall.arguments
44197
+ };
44198
+ } else if (chunk.type === "error") {
44199
+ throw new Error(chunk.error);
44200
+ }
44201
+ }
44202
+ if (call === void 0)
44203
+ return { advice: text, steps, truncated: atCap && steps > 0 };
44204
+ messages.push({ role: "assistant", content: text, toolCalls: [call] });
44205
+ options.onStep?.(call.name);
44206
+ steps += 1;
44207
+ const tool = byName.get(call.name);
44208
+ if (tool === void 0) {
44209
+ messages.push({
44210
+ role: "tool",
44211
+ toolCallId: call.id,
44212
+ content: `You have no "${call.name}". You are read-only here: ${[...byName.keys()].join(", ")}. Anything else, recommend and the assistant will do it.`
44213
+ });
44214
+ continue;
44215
+ }
44216
+ try {
44217
+ const parsed = tool.parametersSchema.safeParse(JSON.parse(call.arguments || "{}"));
44218
+ const result = parsed.success ? await tool.execute(parsed.data, options.context) : {
44219
+ content: `Those arguments are not valid: ${parsed.error.issues.map((i) => i.message).join("; ")}`
44220
+ };
44221
+ messages.push({ role: "tool", toolCallId: call.id, content: String(result.content) });
44222
+ } catch (error51) {
44223
+ messages.push({
44224
+ role: "tool",
44225
+ toolCallId: call.id,
44226
+ content: `That failed: ${error51 instanceof Error ? error51.message : String(error51)}`
44227
+ });
44228
+ }
44229
+ if (steps >= limit) {
44230
+ messages.push({
44231
+ role: "user",
44232
+ content: "That is all the looking up you can do. Answer now with what you have, and say plainly what you could not check."
44233
+ });
44234
+ }
43795
44235
  }
43796
- return lines.join("\n");
43797
44236
  }
43798
44237
 
43799
44238
  // ../../packages/core/dist/tools/recallExpert.js
@@ -43922,8 +44361,8 @@ function assessmentForBriefing(assessment) {
43922
44361
  }
43923
44362
 
43924
44363
  // ../../packages/core/dist/expert/briefing.js
43925
- var DESCRIPTION_LIMIT = 110;
43926
- function firstLine(text, limit = DESCRIPTION_LIMIT) {
44364
+ var DESCRIPTION_LIMIT2 = 110;
44365
+ function firstLine2(text, limit = DESCRIPTION_LIMIT2) {
43927
44366
  const line = text.split("\n").find((candidate) => candidate.trim().length > 0)?.trim() ?? "";
43928
44367
  return line.length > limit ? `${line.slice(0, limit - 1).trimEnd()}\u2026` : line;
43929
44368
  }
@@ -43962,7 +44401,7 @@ function buildExpertBriefing(input) {
43962
44401
  const assessed = assessmentForBriefing(input.juniorAssessment);
43963
44402
  if (assessed !== void 0)
43964
44403
  sections.push("", assessed);
43965
- const listed = (tools) => [...tools].sort((a, b) => a.name.localeCompare(b.name)).map((tool) => `- ${tool.name} \u2014 ${firstLine(tool.description)}`);
44404
+ const listed = (tools) => [...tools].sort((a, b) => a.name.localeCompare(b.name)).map((tool) => `- ${tool.name} \u2014 ${firstLine2(tool.description)}`);
43966
44405
  const dispatchOnly = input.dispatchOnlyTools ?? [];
43967
44406
  const everyTool = [...input.promptTools, ...dispatchOnly];
43968
44407
  if (everyTool.length > 0) {
@@ -43979,7 +44418,7 @@ function buildExpertBriefing(input) {
43979
44418
  const skills = input.skills ?? [];
43980
44419
  if (skills.length > 0) {
43981
44420
  sections.push("", `### Project knowledge written down for the junior (${skills.length})`, "");
43982
- sections.push(...skills.map((skill) => `- ${skill.name} \u2014 ${firstLine(skill.description)}`));
44421
+ sections.push(...skills.map((skill) => `- ${skill.name} \u2014 ${firstLine2(skill.description)}`));
43983
44422
  sections.push("", "Only the summaries are here. Ask the junior to read the full text of any that looks", "relevant \u2014 these describe how this particular team does things, and they override your", "general knowledge where the two disagree.");
43984
44423
  }
43985
44424
  return sections.join("\n");
@@ -55954,124 +56393,19 @@ var ASK_MODE = {
55954
56393
  description: "Read-only: inspect the workspace and answer questions. Cannot edit or run commands.",
55955
56394
  groups: ["read", "mcp", "always"]
55956
56395
  };
55957
- var JUNIOR_MODE = {
55958
- id: "junior",
55959
- name: "Junior",
55960
- description: "A cheap model does the work and consults Claude for the plan. Requires the expert.",
56396
+ var AGENT_TEAM_MODE = {
56397
+ id: "agent-team",
56398
+ name: "Agent team",
56399
+ description: "You lead; specialists you assign are consulted as needed. Requires at least one agent.",
55961
56400
  groups: ["read", "edit", "command", "mcp", "always"],
55962
- requiresExpert: true,
55963
- guidance: [
55964
- "# Junior mode",
55965
- "",
55966
- "You are the junior on this task. A stronger model (Claude) is available through",
55967
- "`ask_expert` and is the one that decides *what* to do; you decide *how* and carry it out.",
55968
- "You are the hands: reading, searching, editing, running commands, checking results.",
55969
- "",
55970
- "## The first consultation is expensive; the rest are cheap",
55971
- "",
55972
- "Consultations in one task continue **one conversation**. The first pays to establish it",
55973
- "and costs roughly twenty times a follow-up; every one after that is cheap and the expert",
55974
- "still remembers everything you have told it.",
55975
- "",
55976
- "Two things follow, and they matter more than any other instruction here:",
55977
- "",
55978
- "1. **Make the first consultation count.** Gather what is needed first and ask one full,",
55979
- ' well-formed question. Do not open with "hello" or a question you could answer yourself \u2014',
55980
- " you are paying the setup cost either way, so spend it on something real.",
55981
- "2. **Never repeat yourself afterwards.** The expert remembers the code you pasted, the plan",
55982
- ' it gave you and what you have tried. A follow-up is "step 3 failed with this error",',
55983
- " not the whole story again. Re-explaining throws away the entire saving.",
55984
- "",
55985
- "## Consulting is the default, not the exception",
55986
- "",
55987
- "On any request that is not trivial, **your first action is `ask_expert`** \u2014 before you plan,",
55988
- "before you edit, before you decide the task is straightforward. Do not wait to be told. If",
55989
- 'the user has to say "ask the expert", this mode has failed and is costing them the price of',
55990
- "a worse model for no benefit.",
55991
- "",
55992
- "A request is **not** trivial, and you must consult, if any of these is true:",
55993
- "",
55994
- "- it touches more than one file, or a file you have not read in this session;",
55995
- "- it asks you to design, refactor, choose an approach, or decide between options;",
55996
- "- it involves code you did not write in this conversation;",
55997
- "- you would have to guess at how something works to proceed;",
55998
- "- your first attempt failed, or a test or command reported an error;",
55999
- '- you are about to say "I think" or "probably" about anything load-bearing.',
56000
- "",
56001
- "When in doubt, consult. A consultation costs cents. Confidently doing the wrong thing costs",
56002
- "the user their afternoon.",
56003
- "",
56004
- "Ask for a concrete plan, the files involved, and the traps to avoid \u2014 **broken into",
56005
- "checkpoints**, as described below.",
56006
- "",
56007
- "**Genuinely trivial requests you simply do:** fixing a typo you can see, answering a",
56008
- "question about a file you have already read, running a command the user named. Asking about",
56009
- "those would waste the user\u2019s money on something you already know.",
56010
- "",
56011
- "## Checkpoints: implement, review, continue",
56012
- "",
56013
- "For anything larger than a single edit, ask the expert to split the plan into **checkpoints**.",
56014
- "Then work the loop: implement one checkpoint, go back to the expert with what you actually",
56015
- "did, take its feedback, and move to the next. Keep going until the work is complete.",
56016
- "",
56017
- "**This is a cost measure, not a quality ritual, and the distinction decides how you use it.**",
56018
- "The expensive failure in this arrangement is not a consultation \u2014 it is you building the",
56019
- "wrong thing for twenty turns and then needing the whole approach redone. A review after each",
56020
- "checkpoint costs about as much as one cheap follow-up and caps how far a wrong direction can",
56021
- "run before someone notices. It only pays if you keep it cheap:",
56022
- "",
56023
- "- **A checkpoint is a unit worth reviewing** \u2014 a coherent, working slice, typically a few",
56024
- " related edits. If a checkpoint is one line, the review costs more than the mistake it",
56025
- " could catch: fold it into the next one. If it is the entire feature, it is not a",
56026
- " checkpoint and defeats the point.",
56027
- '- **Report the delta, never the context.** "Checkpoint 2 done: added `retryWithBackoff` in',
56028
- " `http.ts`, wired it into `send()`, tests pass. Deviated from the plan by keeping the old",
56029
- ' signature, because three callers depend on it." The expert has the plan and remembers the',
56030
- "code \u2014 it can open anything it wants to see for itself.",
56031
- "- **Say what surprised you.** The parts worth a review are the deviations, the things that",
56032
- " did not match the plan, and anything you were unsure about. A checkpoint that went exactly",
56033
- " as planned needs a sentence, not a report.",
56034
- "- **Skip the review** when a checkpoint was mechanical and everything passed. Say so at the",
56035
- " next one instead. Two checkpoints in one review is cheaper than two reviews.",
56036
- '- **Run the tests before you report.** "Tests pass" is worth far more to the reviewer than a',
56037
- " description of the code, and finding it yourself is free where the expert finding it is not.",
56038
- "",
56039
- "If a budget is set the expert stops being available once it is reached, and you finish the",
56040
- "work alone. Spend the consultations you have on the checkpoints that carry the most risk.",
56041
- "",
56042
- "**Also consult again when:**",
56043
- "- the same step has failed twice and you do not understand why;",
56044
- "- the code contradicts the plan, so following it would be wrong;",
56045
- "- something is ambiguous in a way that changes *what* should be built, not merely how.",
56046
- "",
56047
- "## Gather the context before you ask",
56048
- "",
56049
- "The expert can open files itself, but doing so costs the user far more than it costs you.",
56050
- "So before consulting: find the relevant code, read it, and **include the actual code in",
56051
- "your question** along with what you have already tried and what happened.",
56052
- "",
56053
- "## You are its hands for tools, too",
56054
- "",
56055
- "The expert cannot call any of your tools \u2014 no MCP tool, no Python tool, no searching the",
56056
- "documentation index. It is told what you have, by name, but not the exact parameters. So",
56057
- "if it asks you to look up a tool\u2019s arguments or read a skill, do it and report back in the",
56058
- "same conversation; that round trip is cheap and stops it guessing a signature.",
56059
- "",
56060
- "## Carrying out the plan",
56061
- "",
56062
- "Follow it, but you are not a transcription service. The expert never ran anything and may",
56063
- "be wrong about the real code. If a step does not match what you find, say so and adapt \u2014",
56064
- "and if the mismatch is fundamental, that is one of the reasons to consult again.",
56065
- "",
56066
- "Tell the user which checkpoint you are on and what the expert said about the last one, so",
56067
- "they can see what they paid for and stop you if the direction is wrong. They are the only",
56068
- "reviewer whose approval actually gates anything."
56069
- ].join("\n")
56401
+ requiresExpert: true
56070
56402
  };
56071
- var BUILTIN_MODES = [CODE_MODE, ASK_MODE, JUNIOR_MODE];
56403
+ var BUILTIN_MODES = [CODE_MODE, ASK_MODE, AGENT_TEAM_MODE];
56072
56404
  var DEFAULT_MODE_ID = CODE_MODE.id;
56405
+ var RENAMED = { junior: AGENT_TEAM_MODE.id };
56073
56406
  function findMode(id) {
56074
- return BUILTIN_MODES.find((mode) => mode.id === id) ?? CODE_MODE;
56407
+ const resolved = id !== void 0 ? RENAMED[id] ?? id : id;
56408
+ return BUILTIN_MODES.find((mode) => mode.id === resolved) ?? CODE_MODE;
56075
56409
  }
56076
56410
 
56077
56411
  // ../../packages/core/dist/modes/resolve.js
@@ -59742,6 +60076,8 @@ ${preview.text}` } : {}
59742
60076
  return [skillsDir, ...extraSkillDirs].filter((dir) => dir !== void 0);
59743
60077
  }
59744
60078
  let skills = [];
60079
+ let agentBriefingTools;
60080
+ let consultationContext;
59745
60081
  let skillIssues = [];
59746
60082
  const refreshSkills = async () => {
59747
60083
  const dirs = skillSearchPath();
@@ -59911,17 +60247,21 @@ ${preview.text}` } : {}
59911
60247
  const warnedExpiries = /* @__PURE__ */ new Set();
59912
60248
  let expertCli;
59913
60249
  let expertCliPath;
60250
+ async function detectCli(configured) {
60251
+ if (expertCli !== void 0 && expertCliPath === configured)
60252
+ return expertCli;
60253
+ expertCliPath = configured;
60254
+ expertCli = await detectClaudeCli(configured);
60255
+ if (!expertCli.available)
60256
+ logger.warn("expert unavailable", expertCli.reason ?? "");
60257
+ void postAgents();
60258
+ return expertCli;
60259
+ }
59914
60260
  async function resolveExpert(config2) {
59915
60261
  if (config2.expert?.enabled !== true)
59916
60262
  return void 0;
59917
- const configured = config2.expert.path ?? "claude";
59918
- if (expertCli === void 0 || expertCliPath !== configured) {
59919
- expertCliPath = configured;
59920
- expertCli = await detectClaudeCli(configured);
59921
- if (!expertCli.available)
59922
- logger.warn("expert unavailable", expertCli.reason ?? "");
59923
- }
59924
- return expertCli.available ? expertCli : void 0;
60263
+ const detected = await detectCli(config2.expert.path ?? "claude");
60264
+ return detected.available ? detected : void 0;
59925
60265
  }
59926
60266
  let queuedMessages = [];
59927
60267
  function postQueued() {
@@ -59931,6 +60271,7 @@ ${preview.text}` } : {}
59931
60271
  let taskCheckpoint;
59932
60272
  const ACTIVE_TASK_KEY = "lightCode.activeTaskId";
59933
60273
  let activeTaskId = services.workspaceState.get(ACTIVE_TASK_KEY);
60274
+ let activePlan;
59934
60275
  let activeTaskCreatedAt = Date.now();
59935
60276
  async function setActiveTaskId(id) {
59936
60277
  activeTaskId = id;
@@ -60173,7 +60514,9 @@ ${preview.text}` } : {}
60173
60514
  }
60174
60515
  let cachedModeId;
60175
60516
  let cachedCodeGenerator;
60176
- let cachedProviderExpert;
60517
+ let cachedTeam = [];
60518
+ let cachedTeamGuidance;
60519
+ let cachedBudgetMatters = false;
60177
60520
  let cachedMentionExcludes;
60178
60521
  let cachedReportsCost;
60179
60522
  let measuringStep;
@@ -60214,7 +60557,17 @@ ${preview.text}` } : {}
60214
60557
  const { config: config2 } = await configManager.load();
60215
60558
  cachedApprovals = approvalsFrom(config2.approvals);
60216
60559
  cachedCodeGenerator = codeGeneratorFor(config2);
60217
- cachedProviderExpert = providerExpertFor(config2);
60560
+ const teamContext = {
60561
+ config: config2.agents,
60562
+ profiles: (config2.profiles ?? []).map((profile) => ({
60563
+ id: profile.id,
60564
+ label: profile.label
60565
+ })),
60566
+ cliAvailable: expertCli?.available === true
60567
+ };
60568
+ cachedTeam = resolveTeam(teamContext);
60569
+ cachedTeamGuidance = config2.agents?.teamGuidance;
60570
+ cachedBudgetMatters = budgetMatters(teamContext);
60218
60571
  cachedProgrammingProfileId = config2.programmingProfileId;
60219
60572
  cachedOffice = config2.office ?? {};
60220
60573
  cachedMail = config2.mail ?? {};
@@ -60509,18 +60862,18 @@ ${preview.text}` } : {}
60509
60862
  observer: searchLog
60510
60863
  }));
60511
60864
  }
60512
- const providerExpert = cachedProviderExpert;
60513
- if (providerExpert !== void 0) {
60514
- combined.register(createRecallExpertTool({ history: () => expertAdvice }));
60515
- combined.register(createAskProviderExpertTool({
60516
- consult: providerExpert.consult,
60517
- label: providerExpert.label,
60518
- onAdvice: (record2) => expertAdvice.push(record2)
60865
+ if (cachedTeam.some((agent) => agent.available)) {
60866
+ combined.register(createAskAgentTool({
60867
+ agents: () => cachedTeam,
60868
+ onAdvice: (record2) => expertAdvice.push(record2),
60869
+ consult: async (agent, request) => consultAgent(agent, request)
60519
60870
  }));
60520
- } else if (expert !== void 0) {
60871
+ }
60872
+ if (expert !== void 0) {
60521
60873
  combined.register(createRecallExpertTool({ history: () => expertAdvice }));
60522
60874
  combined.register(createAskExpertTool({
60523
60875
  cli: expert.cli,
60876
+ budgetMatters: cachedBudgetMatters,
60524
60877
  ...expert.model !== void 0 ? { model: expert.model } : {},
60525
60878
  onConsultation: recordConsultation,
60526
60879
  onAdvice: (record2) => expertAdvice.push(record2),
@@ -60560,6 +60913,7 @@ ${preview.text}` } : {}
60560
60913
  })
60561
60914
  }));
60562
60915
  }
60916
+ agentBriefingTools = () => combined.list();
60563
60917
  return combined;
60564
60918
  }
60565
60919
  async function syncMcpFromConfig(config2) {
@@ -60636,7 +60990,8 @@ ${preview.text}` } : {}
60636
60990
  createdAt: activeTaskCreatedAt,
60637
60991
  updatedAt: Date.now(),
60638
60992
  messages,
60639
- resultHandles: truncationStore.spilledHandles()
60993
+ resultHandles: truncationStore.spilledHandles(),
60994
+ ...activePlan !== void 0 && activePlan.trim().length > 0 ? { plan: activePlan } : {}
60640
60995
  };
60641
60996
  try {
60642
60997
  await taskStore.save(redactTask(task, await knownSecretValues()));
@@ -60664,8 +61019,10 @@ ${preview.text}` } : {}
60664
61019
  taskCheckpoint = void 0;
60665
61020
  activeTaskCreatedAt = task.createdAt;
60666
61021
  truncationStore.startTask(task.resultHandles);
61022
+ activePlan = task.plan;
60667
61023
  await setActiveTaskId(task.id);
60668
61024
  post({ type: "taskRestored", taskId: task.id, entries: toTranscript(task.messages) });
61025
+ post({ type: "plan", plan: activePlan ?? "" });
60669
61026
  await postTasks();
60670
61027
  }
60671
61028
  async function startNewTask() {
@@ -60675,8 +61032,10 @@ ${preview.text}` } : {}
60675
61032
  taskCheckpoint = void 0;
60676
61033
  activeTaskCreatedAt = Date.now();
60677
61034
  truncationStore.startTask();
61035
+ activePlan = void 0;
60678
61036
  await setActiveTaskId(void 0);
60679
61037
  post({ type: "taskRestored", taskId: void 0, entries: [] });
61038
+ post({ type: "plan", plan: "" });
60680
61039
  await postTasks();
60681
61040
  }
60682
61041
  async function deleteTask(id) {
@@ -60757,6 +61116,8 @@ ${preview.text}` } : {}
60757
61116
  ].filter((section) => section.length > 0).join("\n\n") : renderSkillsForPrompt(turnSkills),
60758
61117
  skillsSearchable,
60759
61118
  canWriteSkills: skillsDir !== void 0,
61119
+ // Last in the prompt, and the most specific thing in it — see `agent/plan.ts`.
61120
+ ...activePlan !== void 0 && activePlan.trim().length > 0 ? { plan: activePlan } : {},
60760
61121
  // Only when a pool actually exists: telling the model about a tool it has not been given
60761
61122
  // is how it comes to report that it looked somewhere it could not reach.
60762
61123
  teamSkillsAvailable: config2.embedder?.skillsAlias !== void 0,
@@ -60778,7 +61139,9 @@ ${preview.text}` } : {}
60778
61139
  */
60779
61140
  ...(() => {
60780
61141
  const parts = [];
60781
- if (activeMode.guidance !== void 0 && (activeMode.requiresExpert !== true || expertCliInfo !== void 0)) {
61142
+ if (activeMode.id === AGENT_TEAM_MODE.id) {
61143
+ parts.push(buildTeamGuidance(cachedTeam.filter((agent) => agent.available), cachedTeamGuidance, cachedBudgetMatters));
61144
+ } else if (activeMode.guidance !== void 0 && (activeMode.requiresExpert !== true || expertCliInfo !== void 0)) {
60782
61145
  parts.push(activeMode.guidance);
60783
61146
  }
60784
61147
  if (scheduledGuidance !== void 0)
@@ -60814,6 +61177,7 @@ ${preview.text}` } : {}
60814
61177
  // lives in the VSIX, so resolving it is a host concern (§4).
60815
61178
  ...ripgrepPath !== void 0 ? { ripgrepPath } : {}
60816
61179
  };
61180
+ consultationContext = () => toolContext;
60817
61181
  pythonNestedContext = toolContext;
60818
61182
  pythonNestedCallsAllowed = schedule === void 0;
60819
61183
  const mentions = await resolveMentions(text, { fs: toolContext.fs, workspaceRoot, denylist });
@@ -60855,7 +61219,7 @@ ${preview.text}` } : {}
60855
61219
  }
60856
61220
  let cumulativeText = "";
60857
61221
  let cumulativeReasoning = "";
60858
- let expertInformed = false;
61222
+ let informedBy;
60859
61223
  const fullRegistry = currentToolRegistry(
60860
61224
  expertCliInfo !== void 0 ? {
60861
61225
  cli: expertCliInfo,
@@ -60939,7 +61303,7 @@ ${preview.text}` } : {}
60939
61303
  post({
60940
61304
  type: "textChunk",
60941
61305
  text: cumulativeText,
60942
- ...expertInformed ? { expertInformed } : {}
61306
+ ...informedBy !== void 0 ? { expertInformed: true, informedBy } : {}
60943
61307
  });
60944
61308
  },
60945
61309
  onReasoningChunk: (chunk) => {
@@ -60949,22 +61313,18 @@ ${preview.text}` } : {}
60949
61313
  onToolCall: (toolCall) => {
60950
61314
  cumulativeText = "";
60951
61315
  cumulativeReasoning = "";
60952
- if (toolCall.name === "ask_expert")
60953
- expertInformed = true;
61316
+ const consulting = consultationFromToolCall(toolCall.name, toolCall.arguments);
61317
+ if (consulting !== void 0)
61318
+ informedBy = consulting;
60954
61319
  if (CONTROL_TOOLS.has(toolCall.name))
60955
61320
  return;
60956
61321
  if (chartFromToolCall(toolCall.name, toolCall.arguments) !== void 0)
60957
61322
  return;
60958
- const summary = {
60959
- id: toolCall.id,
60960
- name: toolCall.name,
60961
- arguments: formatToolArguments(toolCall.arguments),
60962
- ...toolCallReason(toolCall.arguments) === void 0 ? {} : { why: toolCallReason(toolCall.arguments) }
60963
- };
61323
+ const summary = toolCallSummary(toolCall);
60964
61324
  post({
60965
61325
  type: "toolCall",
60966
61326
  toolCall: summary,
60967
- ...expertInformed ? { expertInformed } : {}
61327
+ ...informedBy !== void 0 ? { expertInformed: true, informedBy } : {}
60968
61328
  });
60969
61329
  },
60970
61330
  onToolResult: (toolCall, result) => {
@@ -60977,22 +61337,18 @@ ${preview.text}` } : {}
60977
61337
  post(chart.kind === "chart" ? {
60978
61338
  type: "chart",
60979
61339
  chart: chart.chart,
60980
- ...expertInformed ? { expertInformed } : {}
61340
+ ...informedBy !== void 0 ? { expertInformed: true, informedBy } : {}
60981
61341
  } : { type: "chartError", message: chart.message });
60982
61342
  return;
60983
61343
  }
60984
- const summary = {
60985
- id: toolCall.id,
60986
- name: toolCall.name,
60987
- arguments: formatToolArguments(toolCall.arguments),
60988
- ...toolCallReason(toolCall.arguments) === void 0 ? {} : { why: toolCallReason(toolCall.arguments) },
61344
+ const summary = toolCallSummary(toolCall, {
60989
61345
  result: result.content,
60990
61346
  ...result.isError === true ? { isError: true } : {}
60991
- };
61347
+ });
60992
61348
  post({
60993
61349
  type: "toolResult",
60994
61350
  toolCall: summary,
60995
- ...expertInformed ? { expertInformed } : {}
61351
+ ...informedBy !== void 0 ? { expertInformed: true, informedBy } : {}
60996
61352
  });
60997
61353
  },
60998
61354
  onCheckpoint: (checkpoint) => {
@@ -61141,6 +61497,7 @@ ${preview.text}` } : {}
61141
61497
  cachedAuth = void 0;
61142
61498
  post({ type: "profileSaved" });
61143
61499
  await postProfiles();
61500
+ await postAgents();
61144
61501
  } catch (error51) {
61145
61502
  post({ type: "error", message: error51 instanceof Error ? error51.message : String(error51) });
61146
61503
  }
@@ -61194,6 +61551,7 @@ ${preview.text}` } : {}
61194
61551
  };
61195
61552
  await configManager.save("user", { profiles: [...profiles, duplicate] });
61196
61553
  await postProfiles();
61554
+ await postAgents();
61197
61555
  } catch (error51) {
61198
61556
  post({ type: "error", message: error51 instanceof Error ? error51.message : String(error51) });
61199
61557
  }
@@ -61208,6 +61566,7 @@ ${preview.text}` } : {}
61208
61566
  const activeProfileId = config2.activeProfileId === id ? remaining[0]?.id : config2.activeProfileId;
61209
61567
  await configManager.save("user", { profiles: remaining, activeProfileId });
61210
61568
  await postProfiles();
61569
+ await postAgents();
61211
61570
  } catch (error51) {
61212
61571
  post({ type: "error", message: error51 instanceof Error ? error51.message : String(error51) });
61213
61572
  }
@@ -61226,6 +61585,7 @@ ${preview.text}` } : {}
61226
61585
  await configManager.save("user", { activeProfileId: id });
61227
61586
  await postProjectSettings();
61228
61587
  await postProfiles();
61588
+ await postAgents();
61229
61589
  } catch (error51) {
61230
61590
  post({ type: "error", message: error51 instanceof Error ? error51.message : String(error51) });
61231
61591
  }
@@ -61277,26 +61637,16 @@ ${preview.text}` } : {}
61277
61637
  // The whole thing, profiles included. Passing only half of what the constructor takes is
61278
61638
  // the same mistake as having two constructors, and this failure path is where the last
61279
61639
  // one hid: it runs rarely, so a field missing here is noticed much later than elsewhere.
61280
- ...expertMessageFrom(settings, loaded?.profiles),
61640
+ ...expertMessageFrom(settings),
61281
61641
  available: false,
61282
61642
  path: settings?.path ?? expertCliPath ?? "claude",
61283
61643
  reason: `Could not check whether the Claude CLI is available: ${reason}`
61284
61644
  });
61285
61645
  }
61286
61646
  }
61287
- function expertMessageFrom(settings, profiles) {
61647
+ function expertMessageFrom(settings) {
61288
61648
  return {
61289
61649
  type: "expert",
61290
- /*
61291
- * Sent from here and nowhere else. CLAUDE.md records what happened the last time two
61292
- * `expert` messages were built separately: measured pricing reached the success path and
61293
- * not the failure path, and the panel showed a dash for something that had been measured.
61294
- */
61295
- ...services.expertMode === "profile" ? {
61296
- mode: "profile",
61297
- profiles: (profiles ?? []).map((profile) => ({ id: profile.id, label: profile.label })),
61298
- ...settings?.profileId !== void 0 ? { profileId: settings.profileId } : {}
61299
- } : {},
61300
61650
  enabled: settings?.enabled === true,
61301
61651
  available: false,
61302
61652
  path: settings?.path ?? expertCliPath ?? "claude",
@@ -61313,24 +61663,81 @@ ${preview.text}` } : {}
61313
61663
  ...expertEvents !== void 0 ? { savings: summariseSavings(expertEvents, settings?.pricing) } : {}
61314
61664
  };
61315
61665
  }
61316
- async function postExpertInner(redetect) {
61666
+ async function postAgents() {
61317
61667
  const { config: config2 } = await configManager.load();
61318
- if (services.expertMode === "profile") {
61319
- post({
61320
- ...expertMessageFrom(config2.expert, config2.profiles),
61321
- // Usable when a profile is chosen, which is the only thing availability can mean here.
61322
- available: config2.expert?.enabled === true && config2.expert.profileId !== void 0 && config2.profiles?.some((profile) => profile.id === config2.expert?.profileId) === true
61323
- });
61324
- return;
61668
+ const cli = await detectCli(config2.expert?.path ?? "claude").catch(() => void 0);
61669
+ const teamContext = {
61670
+ config: config2.agents,
61671
+ profiles: (config2.profiles ?? []).map((profile) => ({
61672
+ id: profile.id,
61673
+ label: profile.label
61674
+ })),
61675
+ cliAvailable: cli?.available === true
61676
+ };
61677
+ const assigned = new Map(resolveTeam(teamContext).map((agent) => [agent.role, agent]));
61678
+ const roles = allRoles().map((info) => {
61679
+ const agent = assigned.get(info.role);
61680
+ const prompt = config2.agents?.roles?.[info.role]?.prompt;
61681
+ return {
61682
+ role: info.role,
61683
+ name: info.name,
61684
+ summary: info.summary,
61685
+ ...agent !== void 0 ? { kind: agent.kind } : {},
61686
+ ...agent?.profileId !== void 0 ? { profileId: agent.profileId } : {},
61687
+ label: agent?.label ?? "Nobody",
61688
+ available: agent?.available ?? false,
61689
+ ...agent?.reason !== void 0 ? { reason: agent.reason } : {},
61690
+ prompt: prompt ?? defaultPromptFor(info.role),
61691
+ promptIsDefault: prompt === void 0
61692
+ };
61693
+ });
61694
+ const guidance = config2.agents?.teamGuidance;
61695
+ post({
61696
+ type: "agents",
61697
+ roles,
61698
+ profiles: teamContext.profiles,
61699
+ cliAvailable: teamContext.cliAvailable,
61700
+ ...cli?.available === false && cli.reason !== void 0 ? { cliReason: cli.reason } : {},
61701
+ budgetMatters: budgetMatters(teamContext),
61702
+ teamGuidance: guidance ?? DEFAULT_TEAM_GUIDANCE,
61703
+ defaultTeamGuidance: DEFAULT_TEAM_GUIDANCE,
61704
+ teamGuidanceIsDefault: guidance === void 0,
61705
+ colors: {
61706
+ /*
61707
+ * The expert's colour comes from the control that has always owned it.
61708
+ *
61709
+ * It predates roles and lives under `ui.expertColor`, and the Agents work briefly gave it
61710
+ * a second home under `agents.colors.expert` — two pickers for one thing, backed by two
61711
+ * settings, which is the drift this project pays for most often. An explicit per-role
61712
+ * value still wins, so nothing is taken away; it is simply no longer the *default*
61713
+ * source for a colour that already had one.
61714
+ */
61715
+ expert: config2.ui?.expertColor ?? "#D97757",
61716
+ ...config2.agents?.colors ?? {}
61717
+ }
61718
+ });
61719
+ }
61720
+ async function saveAgents(change) {
61721
+ try {
61722
+ const { config: config2 } = await configManager.load();
61723
+ await configManager.save("user", { agents: change(config2.agents ?? {}) });
61724
+ await loadSettings();
61725
+ await postAgents();
61726
+ } catch (error51) {
61727
+ post({ type: "error", message: error51 instanceof Error ? error51.message : String(error51) });
61325
61728
  }
61729
+ }
61730
+ async function postExpertInner(redetect) {
61731
+ const { config: config2 } = await configManager.load();
61326
61732
  await loadExpertEvents();
61327
61733
  const configured = config2.expert?.path ?? "claude";
61328
61734
  const detected = !redetect && expertCli !== void 0 && expertCliPath === configured ? expertCli : await detectClaudeCli(configured);
61329
61735
  expertCli = detected;
61330
61736
  expertCliPath = configured;
61737
+ void postAgents();
61331
61738
  post({
61332
61739
  // Everything from settings comes from one place, so the two paths cannot drift again.
61333
- ...expertMessageFrom(config2.expert, config2.profiles),
61740
+ ...expertMessageFrom(config2.expert),
61334
61741
  available: detected.available,
61335
61742
  path: configured,
61336
61743
  ...detected.version !== void 0 ? { version: detected.version } : {},
@@ -63311,6 +63718,7 @@ ${preview.text}` } : {}
63311
63718
  }));
63312
63719
  await configManager.save("user", { ...imported, profiles: reconciled });
63313
63720
  await postProfiles();
63721
+ await postAgents();
63314
63722
  ui.showInfo(needKeys.length > 0 ? `Config imported. Re-enter the API key for: ${needKeys.join(", ")} (exports never include secrets).` : "Config imported.");
63315
63723
  } catch (error51) {
63316
63724
  post({ type: "error", message: error51 instanceof Error ? error51.message : String(error51) });
@@ -63332,35 +63740,64 @@ ${preview.text}` } : {}
63332
63740
  post({ type: "error", message: error51 instanceof Error ? error51.message : String(error51) });
63333
63741
  }
63334
63742
  }
63335
- function providerExpertFor(config2) {
63336
- if (services.expertMode !== "profile")
63337
- return void 0;
63338
- if (config2.expert?.enabled !== true)
63339
- return void 0;
63340
- const id = config2.expert.profileId;
63341
- if (id === void 0 || id.length === 0)
63342
- return void 0;
63343
- const profile = config2.profiles?.find((candidate) => candidate.id === id);
63743
+ async function consultAgent(agent, request) {
63744
+ const prompt = buildAgentPrompt({
63745
+ prompt: agent.prompt,
63746
+ question: request.question,
63747
+ ...request.files !== void 0 ? { files: request.files } : {},
63748
+ /*
63749
+ * What exists in this workspace.
63750
+ *
63751
+ * Without it a specialist advises as though the assistant were a bare shell — proposing by
63752
+ * hand what a configured tool already does, or inventing a procedure an existing skill
63753
+ * documents. See `agents/briefing.ts` for why names are worth the tokens and schemas are not.
63754
+ */
63755
+ briefing: buildAgentBriefing({
63756
+ tools: agentBriefingTools?.() ?? [],
63757
+ skills
63758
+ })
63759
+ });
63760
+ if (agent.kind === "cli") {
63761
+ const cli = expertCli;
63762
+ if (cli === void 0 || !cli.available)
63763
+ throw new Error("The Claude CLI is not available.");
63764
+ const answer = await consultExpert(cli, {
63765
+ question: prompt,
63766
+ /*
63767
+ * The workspace, so Claude's own Read/Grep resolve against the project rather than
63768
+ * wherever this process was started. Falls back to the process directory when no folder
63769
+ * is open — the consultation is still worth having without one.
63770
+ */
63771
+ cwd: workspaceRoot ?? process.cwd(),
63772
+ ...request.signal !== void 0 ? { signal: request.signal } : {}
63773
+ });
63774
+ if (answer.isError)
63775
+ throw new Error(answer.text);
63776
+ return { advice: answer.text, label: agent.label };
63777
+ }
63778
+ const { config: config2 } = await configManager.load();
63779
+ const profile = config2.profiles?.find((candidate) => candidate.id === agent.profileId);
63344
63780
  if (profile === void 0) {
63345
- logger.warn(`the expert profile "${id}" is configured but no such profile exists; the expert is unavailable`);
63346
- return void 0;
63781
+ throw new Error(`No profile "${agent.profileId ?? ""}" exists any more.`);
63782
+ }
63783
+ const provider = createChatProvider(profile, httpClient, authStrategyFor(config2, profile), logger);
63784
+ const readOnly = toolsForConsultation(agentBriefingTools?.() ?? []);
63785
+ const context = consultationContext?.();
63786
+ const result = await runConsultation({
63787
+ provider,
63788
+ prompt,
63789
+ tools: readOnly,
63790
+ definitions: context === void 0 ? [] : toToolDefinitions(readOnly),
63791
+ // With no context there is nothing to read *with*, so it answers from the question alone
63792
+ // rather than being offered tools that would fail.
63793
+ context: context ?? {},
63794
+ ...request.signal !== void 0 ? { signal: request.signal } : {},
63795
+ onStep: (name) => logger.info(`${agent.role} looked up ${name}`)
63796
+ });
63797
+ if (result.truncated) {
63798
+ logger.info(`${agent.role} reached its lookup limit and answered with what it had`);
63347
63799
  }
63348
- return {
63349
- label: profile.label,
63350
- consult: async (request) => {
63351
- const provider = createChatProvider(profile, httpClient, authStrategyFor(config2, profile), logger);
63352
- let text = "";
63353
- for await (const chunk of provider.streamChat([{ role: "user", content: buildExpertPrompt(request) }], {
63354
- // No tools offered: it is being asked for judgement, and offering tools invites it to
63355
- // reach for one it has no way to run.
63356
- ...request.signal !== void 0 ? { signal: request.signal } : {}
63357
- })) {
63358
- if (chunk.type === "text")
63359
- text += chunk.text;
63360
- }
63361
- return { advice: text, producedBy: profile.label };
63362
- }
63363
- };
63800
+ return { advice: result.advice, label: agent.label };
63364
63801
  }
63365
63802
  function codeGeneratorFor(config2) {
63366
63803
  if (services.allowProgrammingProfile !== true)
@@ -64105,6 +64542,80 @@ ${preview.text}` } : {}
64105
64542
  void handleSaveNetwork(message3.settings);
64106
64543
  } else if (message3.type === "requestExpert") {
64107
64544
  void postExpert();
64545
+ } else if (message3.type === "setPlan") {
64546
+ const plan = message3.plan.slice(0, PLAN_LIMIT).trim();
64547
+ activePlan = plan.length > 0 ? plan : void 0;
64548
+ void persistActiveTask();
64549
+ post({ type: "plan", plan: activePlan ?? "" });
64550
+ } else if (message3.type === "requestPlan") {
64551
+ post({ type: "plan", plan: activePlan ?? "" });
64552
+ } else if (message3.type === "requestAgents") {
64553
+ void postAgents();
64554
+ } else if (message3.type === "setAgentRole") {
64555
+ const assignment = message3.assignment;
64556
+ const role = message3.role;
64557
+ if (!isAgentRole(role)) {
64558
+ post({ type: "error", message: `There is no "${role}" role.` });
64559
+ return;
64560
+ }
64561
+ void saveAgents((current) => {
64562
+ const roles = { ...current.roles ?? {} };
64563
+ if (assignment === void 0)
64564
+ delete roles[role];
64565
+ else {
64566
+ roles[role] = {
64567
+ kind: assignment.kind,
64568
+ ...assignment.profileId !== void 0 ? { profileId: assignment.profileId } : {},
64569
+ ...roles[role]?.prompt !== void 0 ? { prompt: roles[role].prompt } : {}
64570
+ };
64571
+ }
64572
+ return { ...current, roles };
64573
+ });
64574
+ } else if (message3.type === "setAgentPrompt") {
64575
+ const role = message3.role;
64576
+ const prompt = message3.prompt;
64577
+ if (!isAgentRole(role)) {
64578
+ post({ type: "error", message: `There is no "${role}" role.` });
64579
+ return;
64580
+ }
64581
+ void saveAgents((current) => {
64582
+ const roles = { ...current.roles ?? {} };
64583
+ const existing = roles[role];
64584
+ if (prompt === void 0 || prompt === defaultPromptFor(role)) {
64585
+ if (existing !== void 0) {
64586
+ const rest = { ...existing };
64587
+ delete rest.prompt;
64588
+ roles[role] = rest;
64589
+ }
64590
+ } else {
64591
+ roles[role] = { ...existing ?? { kind: "profile" }, prompt };
64592
+ }
64593
+ return { ...current, roles };
64594
+ });
64595
+ } else if (message3.type === "setAgentBudget") {
64596
+ const matters = message3.matters;
64597
+ void saveAgents((current) => ({ ...current, budgetMatters: matters }));
64598
+ } else if (message3.type === "setTeamGuidance") {
64599
+ const guidance = message3.guidance;
64600
+ void saveAgents((current) => {
64601
+ if (guidance === void 0 || guidance.trim().length === 0 || guidance === DEFAULT_TEAM_GUIDANCE) {
64602
+ const rest = { ...current };
64603
+ delete rest.teamGuidance;
64604
+ return rest;
64605
+ }
64606
+ return { ...current, teamGuidance: guidance };
64607
+ });
64608
+ } else if (message3.type === "setAgentColor") {
64609
+ const role = message3.role;
64610
+ const color = message3.color;
64611
+ if (!isAgentRole(role)) {
64612
+ post({ type: "error", message: `There is no "${role}" role.` });
64613
+ return;
64614
+ }
64615
+ void saveAgents((current) => ({
64616
+ ...current,
64617
+ colors: { ...current.colors ?? {}, [role]: color }
64618
+ }));
64108
64619
  } else if (message3.type === "setExpert") {
64109
64620
  void handleSetExpert(message3.enabled, message3.path, message3.model, {
64110
64621
  ...message3.maxSpendUsd !== void 0 ? { maxSpendUsd: message3.maxSpendUsd } : {},
@@ -64774,7 +65285,10 @@ function chartTotals(spec) {
64774
65285
  }
64775
65286
 
64776
65287
  // ../../packages/core/dist/history/transcript.js
64777
- var CONTROL_TOOLS = /* @__PURE__ */ new Set(["attempt_completion", "ask_followup_question"]);
65288
+ var CONTROL_TOOLS = /* @__PURE__ */ new Set([
65289
+ "attempt_completion",
65290
+ "ask_followup_question"
65291
+ ]);
64778
65292
  function formatToolArguments(raw) {
64779
65293
  try {
64780
65294
  const parsed = JSON.parse(raw.length > 0 ? raw : "{}");
@@ -64806,7 +65320,7 @@ function toTranscript(messages) {
64806
65320
  resultsByCallId.set(message3.toolCallId, message3.content);
64807
65321
  }
64808
65322
  const entries = [];
64809
- let expertInformed = false;
65323
+ let informedBy;
64810
65324
  for (const message3 of messages) {
64811
65325
  if (message3.role === "system" || message3.role === "tool")
64812
65326
  continue;
@@ -64815,13 +65329,22 @@ function toTranscript(messages) {
64815
65329
  continue;
64816
65330
  }
64817
65331
  if (message3.content.length > 0) {
64818
- entries.push({ kind: "text", role: "assistant", content: message3.content, ...expertInformed ? { expertInformed } : {} });
65332
+ entries.push({
65333
+ kind: "text",
65334
+ role: "assistant",
65335
+ content: message3.content,
65336
+ ...informedBy !== void 0 ? { expertInformed: true, informedBy } : {}
65337
+ });
64819
65338
  }
64820
65339
  for (const toolCall of message3.toolCalls ?? []) {
64821
65340
  const result = resultsByCallId.get(toolCall.id);
64822
65341
  const asChart = chartFromToolCall(toolCall.name, toolCall.arguments);
64823
65342
  if (asChart !== void 0) {
64824
- entries.push(asChart.kind === "chart" ? { kind: "chart", chart: asChart.chart, ...expertInformed ? { expertInformed: true } : {} } : asChart);
65343
+ entries.push(asChart.kind === "chart" ? {
65344
+ kind: "chart",
65345
+ chart: asChart.chart,
65346
+ ...informedBy !== void 0 ? { expertInformed: true, informedBy } : {}
65347
+ } : asChart);
64825
65348
  continue;
64826
65349
  }
64827
65350
  if (CONTROL_TOOLS.has(toolCall.name)) {
@@ -64829,26 +65352,46 @@ function toTranscript(messages) {
64829
65352
  entries.push({ kind: "text", role: "assistant", content: result });
64830
65353
  continue;
64831
65354
  }
64832
- if (toolCall.name === "ask_expert")
64833
- expertInformed = true;
65355
+ const consulting = consultationFromToolCall(toolCall.name, toolCall.arguments);
65356
+ if (consulting !== void 0)
65357
+ informedBy = consulting;
64834
65358
  entries.push({
64835
65359
  kind: "tool",
64836
- ...expertInformed ? { expertInformed: true } : {},
64837
- toolCall: {
64838
- id: toolCall.id,
64839
- name: toolCall.name,
64840
- arguments: formatToolArguments(toolCall.arguments),
64841
- ...toolCallReason(toolCall.arguments) === void 0 ? {} : { why: toolCallReason(toolCall.arguments) },
64842
- // A call with no matching result means the task ended mid-flight — a cancel, a
64843
- // crash, or a window closed. Leaving `result` unset renders it as unfinished,
64844
- // which is what actually happened.
64845
- ...result !== void 0 ? { result } : {}
64846
- }
65360
+ ...informedBy !== void 0 ? { expertInformed: true, informedBy } : {},
65361
+ /*
65362
+ * Built by the one builder, so a restored transcript and a live turn cannot differ about
65363
+ * what a call looked like. A call with no matching result means the task ended mid-flight
65364
+ * — a cancel, a crash, a window closed — and leaving `result` unset renders it as
65365
+ * unfinished, which is what actually happened.
65366
+ */
65367
+ toolCall: toolCallSummary(toolCall, { result })
64847
65368
  });
64848
65369
  }
64849
65370
  }
64850
65371
  return entries;
64851
65372
  }
65373
+ function toolCallSummary(call, outcome) {
65374
+ const why = toolCallReason(call.arguments);
65375
+ const consulting = consultationFromToolCall(call.name, call.arguments);
65376
+ return {
65377
+ id: call.id,
65378
+ name: call.name,
65379
+ arguments: formatToolArguments(call.arguments),
65380
+ ...why !== void 0 ? { why } : {},
65381
+ ...consulting !== void 0 ? { consultingRole: consulting } : {},
65382
+ ...outcome?.result !== void 0 ? { result: outcome.result } : {},
65383
+ ...outcome?.isError === true ? { isError: true } : {}
65384
+ };
65385
+ }
65386
+ function consultationFromToolCall(name, rawArguments) {
65387
+ if (name === "ask_expert")
65388
+ return "expert";
65389
+ if (name !== "ask_agent")
65390
+ return void 0;
65391
+ const decoded = decodeArguments(rawArguments);
65392
+ const role = typeof decoded === "object" && decoded !== null ? decoded.role : void 0;
65393
+ return typeof role === "string" && role.trim().length > 0 ? role.trim().toLowerCase() : "unknown";
65394
+ }
64852
65395
  function chartFromToolCall(name, rawArguments) {
64853
65396
  if (name !== "show_chart")
64854
65397
  return void 0;
@@ -67580,16 +68123,6 @@ async function createSession(options) {
67580
68123
  * The extension says nothing and keeps all of it — that is where the feature is used.
67581
68124
  */
67582
68125
  offersOffice: false,
67583
- /*
67584
- * The expert is a provider profile here, not the Claude CLI.
67585
- *
67586
- * Asked for directly: any configured model should be able to be the expert, and cost is no
67587
- * longer something to manage in the product. Both follow from where this runs — there is no
67588
- * `claude` binary on a server, and the gateway answering the chat already has a stronger
67589
- * model behind it. Everything about budgets, measured price and savings belongs to the CLI
67590
- * expert, which is what the extension still has.
67591
- */
67592
- expertMode: "profile",
67593
68126
  transport: options.transport,
67594
68127
  /*
67595
68128
  * A shared profile's API key belongs to the administrator and lives beside the shared config;
@@ -68174,7 +68707,7 @@ function respondJson(response, status, body) {
68174
68707
  }
68175
68708
 
68176
68709
  // src/cli.ts
68177
- var VERSION = true ? "0.44.0" : "unknown (not a packaged build)";
68710
+ var VERSION = true ? "0.46.0" : "unknown (not a packaged build)";
68178
68711
  var compat = installNodeCompat();
68179
68712
  function lastMeaningfulLine(problem) {
68180
68713
  const lines = problem.split(String.fromCharCode(10)).map((line) => line.trim()).filter((line) => line.length > 0 && !line.endsWith(":"));