@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 +803 -270
- package/dist/client/client.js +61 -56
- package/dist/client/guide/expert-dark.svg +1 -1
- package/dist/client/guide/expert-light.svg +1 -1
- package/dist/server.js +802 -269
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -39652,6 +39652,34 @@ var pythonConfigSchema = external_exports.object({
|
|
|
39652
39652
|
})
|
|
39653
39653
|
]))
|
|
39654
39654
|
}).partial();
|
|
39655
|
+
var agentAssignmentSchema = external_exports.object({
|
|
39656
|
+
/** `cli` is the Claude command line; `profile` names one of the user's provider profiles. */
|
|
39657
|
+
kind: external_exports.enum(["cli", "profile"]),
|
|
39658
|
+
profileId: external_exports.string().optional(),
|
|
39659
|
+
/**
|
|
39660
|
+
* The role's system prompt, stored only when the user has edited it.
|
|
39661
|
+
*
|
|
39662
|
+
* Absent means "use the default", which is what lets an improved default reach somebody who
|
|
39663
|
+
* has looked at the tab without editing anything. Storing the default verbatim would pin
|
|
39664
|
+
* every user to whatever it said the day they first opened it.
|
|
39665
|
+
*/
|
|
39666
|
+
prompt: external_exports.string().optional()
|
|
39667
|
+
}).strict();
|
|
39668
|
+
var agentsConfigSchema = external_exports.object({
|
|
39669
|
+
roles: external_exports.record(external_exports.string(), agentAssignmentSchema),
|
|
39670
|
+
/** Whether what a consultation costs is worth managing. See `agents/team.ts`. */
|
|
39671
|
+
budgetMatters: external_exports.boolean(),
|
|
39672
|
+
/** The Agent team mode instruction, when edited. The roster is always generated. */
|
|
39673
|
+
teamGuidance: external_exports.string(),
|
|
39674
|
+
/**
|
|
39675
|
+
* A colour per role, for marking whose words a piece of advice is.
|
|
39676
|
+
*
|
|
39677
|
+
* Here rather than under `appearance` because it is keyed by role, and the roles are defined
|
|
39678
|
+
* here — splitting them would mean adding a role in one place and remembering to give it a
|
|
39679
|
+
* colour in another, which is the drift this project keeps paying for.
|
|
39680
|
+
*/
|
|
39681
|
+
colors: external_exports.record(external_exports.string(), external_exports.string())
|
|
39682
|
+
}).partial();
|
|
39655
39683
|
var autoApproveSchema = external_exports.object({
|
|
39656
39684
|
read: external_exports.boolean(),
|
|
39657
39685
|
edit: external_exports.boolean(),
|
|
@@ -40033,6 +40061,7 @@ var configSchema = external_exports.object({
|
|
|
40033
40061
|
/** User-scope only: a workspace able to add a trusted root could enable interception. */
|
|
40034
40062
|
tls: globalTlsSchema,
|
|
40035
40063
|
expert: expertConfigSchema,
|
|
40064
|
+
agents: agentsConfigSchema,
|
|
40036
40065
|
/**
|
|
40037
40066
|
* User-scope only (invariant 5). A workspace able to name a cluster or repoint the
|
|
40038
40067
|
* embedder would exfiltrate whatever gets indexed — sharper than the existing entries,
|
|
@@ -40689,6 +40718,11 @@ var USER_SCOPE_ONLY_KEYS = [
|
|
|
40689
40718
|
// its choosing as soon as the panel opened — the same threat as `python.uvPath`.
|
|
40690
40719
|
// `expert.enabled` is here too, so a repo cannot switch on paid API calls by itself.
|
|
40691
40720
|
"expert",
|
|
40721
|
+
// Names provider profiles, so a workspace able to write it could route a consultation through a
|
|
40722
|
+
// gateway of its choosing — the same threat as `activeProfileId`. And it carries prompts, which
|
|
40723
|
+
// are prose injected into a model then asked to advise on this repository's own code: a hostile
|
|
40724
|
+
// repo could tell the reviewer what to approve.
|
|
40725
|
+
"agents",
|
|
40692
40726
|
// Added for Phase 8b, and the sharpest entries on this list. A workspace able to name a
|
|
40693
40727
|
// cluster, or repoint the embedder at a profile of its choosing, would exfiltrate
|
|
40694
40728
|
// whatever gets indexed — and what gets indexed is the source code.
|
|
@@ -43194,6 +43228,38 @@ var Conversation = class {
|
|
|
43194
43228
|
}
|
|
43195
43229
|
};
|
|
43196
43230
|
|
|
43231
|
+
// ../../packages/core/dist/agent/plan.js
|
|
43232
|
+
var PLAN_LIMIT = 4e3;
|
|
43233
|
+
function buildPlanGuidance(plan) {
|
|
43234
|
+
const trimmed = plan?.trim() ?? "";
|
|
43235
|
+
if (trimmed.length === 0)
|
|
43236
|
+
return "";
|
|
43237
|
+
return [
|
|
43238
|
+
"# The plan for this conversation",
|
|
43239
|
+
"",
|
|
43240
|
+
"The user set this. It is what you are here to do:",
|
|
43241
|
+
"",
|
|
43242
|
+
trimmed,
|
|
43243
|
+
"",
|
|
43244
|
+
"## Working to it",
|
|
43245
|
+
"",
|
|
43246
|
+
"- **Before each step, check it serves the plan.** If it does not, do not take it.",
|
|
43247
|
+
"- **Work the plan in order** where it has an order, and say which part you are on when you",
|
|
43248
|
+
" start something substantial. A reader should never have to guess where you are.",
|
|
43249
|
+
"- **Noticing something else is useful; acting on it is not.** If you spot an unrelated bug,",
|
|
43250
|
+
" a refactor worth doing, or a file that could be tidied, *say so and carry on with the*",
|
|
43251
|
+
" *plan*. Do not fix it because you are there. The user will ask if they want it.",
|
|
43252
|
+
"- **If the plan turns out to be wrong**, say so and stop rather than quietly substituting a",
|
|
43253
|
+
" better one. A plan the user set and a plan you preferred are different things, and only",
|
|
43254
|
+
" one of them was agreed.",
|
|
43255
|
+
"- **If something the plan needs is missing or blocked**, say which part and why, finish what",
|
|
43256
|
+
" can be finished, and report what you left.",
|
|
43257
|
+
"",
|
|
43258
|
+
"When you finish, `attempt_completion` must account for the plan: what is done, what is not,",
|
|
43259
|
+
"and anything you did that the plan did not ask for."
|
|
43260
|
+
].join("\n");
|
|
43261
|
+
}
|
|
43262
|
+
|
|
43197
43263
|
// ../../packages/core/dist/agent/systemPrompt.js
|
|
43198
43264
|
function buildSystemPrompt(workspaceRoot, options = {}) {
|
|
43199
43265
|
const lines = [
|
|
@@ -43274,6 +43340,9 @@ function buildSystemPrompt(workspaceRoot, options = {}) {
|
|
|
43274
43340
|
if (options.modeGuidance !== void 0 && options.modeGuidance.length > 0) {
|
|
43275
43341
|
lines.push("", options.modeGuidance);
|
|
43276
43342
|
}
|
|
43343
|
+
const plan = buildPlanGuidance(options.plan);
|
|
43344
|
+
if (plan.length > 0)
|
|
43345
|
+
lines.push("", plan);
|
|
43277
43346
|
return lines.join("\n");
|
|
43278
43347
|
}
|
|
43279
43348
|
|
|
@@ -43534,7 +43603,21 @@ function createAskExpertTool(options) {
|
|
|
43534
43603
|
return {
|
|
43535
43604
|
name: "ask_expert",
|
|
43536
43605
|
group: "read",
|
|
43537
|
-
|
|
43606
|
+
/*
|
|
43607
|
+
* The rationing is said only where somebody is counting.
|
|
43608
|
+
*
|
|
43609
|
+
* "Each call costs money, use it for genuinely difficult questions only" was unconditional,
|
|
43610
|
+
* and it is *advice about money* — so on a deployment where nobody is metering it, it buys
|
|
43611
|
+
* nothing and costs something real: a model told to hoard consultations asks fewer questions
|
|
43612
|
+
* than it should, which is the failure this whole feature exists to avoid. It was the right
|
|
43613
|
+
* default when every consultation was a metered cold start on a CLI, and it stopped being
|
|
43614
|
+
* right when the expert became a seat any model can sit in.
|
|
43615
|
+
*
|
|
43616
|
+
* Varying the description with a *setting* is the carve-out §12 already makes: the block stays
|
|
43617
|
+
* byte-stable for a whole session and changes only when the user changes their mind in
|
|
43618
|
+
* Settings, exactly as switching the dispatcher does.
|
|
43619
|
+
*/
|
|
43620
|
+
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.",
|
|
43538
43621
|
parametersSchema: paramsSchema2,
|
|
43539
43622
|
async preview(params) {
|
|
43540
43623
|
return {
|
|
@@ -43551,7 +43634,10 @@ Suggested files: ${params.files.join(", ")}` : ""}`
|
|
|
43551
43634
|
async execute(params, context) {
|
|
43552
43635
|
const verdict = options.budget?.();
|
|
43553
43636
|
if (verdict !== void 0 && !verdict.allowed) {
|
|
43554
|
-
return {
|
|
43637
|
+
return {
|
|
43638
|
+
content: verdict.message ?? "The expert budget for this task is exhausted.",
|
|
43639
|
+
isError: true
|
|
43640
|
+
};
|
|
43555
43641
|
}
|
|
43556
43642
|
const question = params.files !== void 0 && params.files.length > 0 ? `${params.question}
|
|
43557
43643
|
|
|
@@ -43613,46 +43699,190 @@ ${withBudget}` : withBudget;
|
|
|
43613
43699
|
};
|
|
43614
43700
|
}
|
|
43615
43701
|
|
|
43616
|
-
// ../../packages/core/dist/
|
|
43702
|
+
// ../../packages/core/dist/agents/roles.js
|
|
43703
|
+
var AGENT_ROLES = ["expert", "programmer", "reviewer", "tester", "librarian"];
|
|
43704
|
+
function isAgentRole(value) {
|
|
43705
|
+
return AGENT_ROLES.includes(value);
|
|
43706
|
+
}
|
|
43707
|
+
var SHARED = [
|
|
43708
|
+
"You cannot see the workspace and cannot read files, run commands or search. Everything you",
|
|
43709
|
+
"have is in the question. If something essential is missing, say exactly what you need and why,",
|
|
43710
|
+
"then give the best answer you can without it \u2014 never refuse to answer.",
|
|
43711
|
+
"",
|
|
43712
|
+
"Your reply is advice. The assistant will check it against the real code before acting, and it",
|
|
43713
|
+
"is responsible for the result. Be concrete, say what you are unsure about, and say plainly when",
|
|
43714
|
+
"something must be verified rather than assumed.",
|
|
43715
|
+
"",
|
|
43716
|
+
"Answer in prose and short lists. No preamble about being happy to help."
|
|
43717
|
+
].join("\n");
|
|
43718
|
+
var DEFINITIONS = {
|
|
43719
|
+
expert: {
|
|
43720
|
+
name: "Expert",
|
|
43721
|
+
summary: "Hard problems, architecture, and deciding what to do",
|
|
43722
|
+
prompt: [
|
|
43723
|
+
"You are a senior engineer being consulted by another AI assistant that is doing the work.",
|
|
43724
|
+
"",
|
|
43725
|
+
"It has hit something hard: a change across several files to plan, a bug it has already",
|
|
43726
|
+
"failed to fix, or a design choice with no obvious answer. Give it your judgement.",
|
|
43727
|
+
"",
|
|
43728
|
+
"Decide *what* should happen and why. Leave the typing to the assistant \u2014 it has the files",
|
|
43729
|
+
"open and you do not. Where there is a real trade-off, name both sides and then choose.",
|
|
43730
|
+
"",
|
|
43731
|
+
SHARED
|
|
43732
|
+
].join("\n")
|
|
43733
|
+
},
|
|
43734
|
+
programmer: {
|
|
43735
|
+
name: "Programmer",
|
|
43736
|
+
summary: "Writes the code once the plan is settled",
|
|
43737
|
+
prompt: [
|
|
43738
|
+
"You are an experienced programmer writing code for another AI assistant to apply.",
|
|
43739
|
+
"",
|
|
43740
|
+
"You are given a requirement and the surrounding code. Produce the change, matching the",
|
|
43741
|
+
"conventions of what you were shown rather than your own preferences \u2014 the naming, the error",
|
|
43742
|
+
"handling, the comment density, the way the existing code does this sort of thing.",
|
|
43743
|
+
"",
|
|
43744
|
+
"Return the code and a short note on anything non-obvious in it. Do not narrate what you are",
|
|
43745
|
+
"about to do, and do not rewrite things you were not asked to change.",
|
|
43746
|
+
"",
|
|
43747
|
+
SHARED
|
|
43748
|
+
].join("\n")
|
|
43749
|
+
},
|
|
43750
|
+
reviewer: {
|
|
43751
|
+
name: "Reviewer",
|
|
43752
|
+
summary: "Reads a change and says what is wrong with it",
|
|
43753
|
+
prompt: [
|
|
43754
|
+
"You are reviewing a change written by another AI assistant.",
|
|
43755
|
+
"",
|
|
43756
|
+
"Your job is to find what is wrong with it. Say so plainly when something is fine, but do",
|
|
43757
|
+
"not pad the review with praise \u2014 an approving review that missed a bug is worse than no",
|
|
43758
|
+
"review, because it was believed.",
|
|
43759
|
+
"",
|
|
43760
|
+
"Look for, in this order: does it do what was asked; does it break something that used to",
|
|
43761
|
+
"work; what happens at the edges \u2014 empty, missing, concurrent, already-exists, fails halfway;",
|
|
43762
|
+
"and does it match the conventions of the code around it.",
|
|
43763
|
+
"",
|
|
43764
|
+
"For each finding say what breaks and under what input. A concern you cannot make concrete is",
|
|
43765
|
+
"worth one sentence, flagged as a hunch, not a paragraph.",
|
|
43766
|
+
"",
|
|
43767
|
+
SHARED
|
|
43768
|
+
].join("\n")
|
|
43769
|
+
},
|
|
43770
|
+
tester: {
|
|
43771
|
+
name: "Tester",
|
|
43772
|
+
summary: "Designs cases and finds what breaks it",
|
|
43773
|
+
prompt: [
|
|
43774
|
+
"You design tests for code written by another AI assistant.",
|
|
43775
|
+
"",
|
|
43776
|
+
"Given a change, say what should be tested and why each case earns its place. Prefer the",
|
|
43777
|
+
"cases that would actually fail: boundaries, empty and missing values, the error path, the",
|
|
43778
|
+
"second call, the concurrent one, the one that fails halfway and has to be recovered from.",
|
|
43779
|
+
"",
|
|
43780
|
+
"A test that cannot fail is worth nothing \u2014 for each case you propose, say what bug it would",
|
|
43781
|
+
"catch. If the change is untestable as written, say what would have to change to make it",
|
|
43782
|
+
"testable rather than proposing a test that only asserts the code was executed.",
|
|
43783
|
+
"",
|
|
43784
|
+
SHARED
|
|
43785
|
+
].join("\n")
|
|
43786
|
+
},
|
|
43787
|
+
librarian: {
|
|
43788
|
+
name: "Librarian",
|
|
43789
|
+
summary: "Skills, internal documentation and house conventions",
|
|
43790
|
+
prompt: [
|
|
43791
|
+
"You answer questions about how things are done here: internal libraries, house conventions,",
|
|
43792
|
+
"the shape of existing code, and what has already been written down.",
|
|
43793
|
+
"",
|
|
43794
|
+
"You are given whatever documentation, skills and code the assistant could find. Answer from",
|
|
43795
|
+
"that, and be explicit about the difference between what the material actually says and what",
|
|
43796
|
+
"you are inferring \u2014 a convention you guessed at, stated confidently, becomes the convention.",
|
|
43797
|
+
"",
|
|
43798
|
+
"If the material does not answer the question, say so and say what would. Do not fill the gap",
|
|
43799
|
+
"with how it is usually done elsewhere unless you label it as exactly that.",
|
|
43800
|
+
"",
|
|
43801
|
+
SHARED
|
|
43802
|
+
].join("\n")
|
|
43803
|
+
}
|
|
43804
|
+
};
|
|
43805
|
+
function roleInfo(role) {
|
|
43806
|
+
return { role, ...DEFINITIONS[role] };
|
|
43807
|
+
}
|
|
43808
|
+
function allRoles() {
|
|
43809
|
+
return AGENT_ROLES.map(roleInfo);
|
|
43810
|
+
}
|
|
43811
|
+
function defaultPromptFor(role) {
|
|
43812
|
+
return DEFINITIONS[role].prompt;
|
|
43813
|
+
}
|
|
43814
|
+
function buildAgentPrompt(options) {
|
|
43815
|
+
const lines = [options.prompt];
|
|
43816
|
+
if (options.briefing !== void 0 && options.briefing.trim().length > 0) {
|
|
43817
|
+
lines.push("", options.briefing);
|
|
43818
|
+
}
|
|
43819
|
+
lines.push("", "---", "", options.question);
|
|
43820
|
+
if (options.files !== void 0 && options.files.length > 0) {
|
|
43821
|
+
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}`));
|
|
43822
|
+
}
|
|
43823
|
+
return lines.join("\n");
|
|
43824
|
+
}
|
|
43825
|
+
|
|
43826
|
+
// ../../packages/core/dist/tools/askAgent.js
|
|
43617
43827
|
var paramsSchema3 = external_exports.object({
|
|
43618
|
-
|
|
43619
|
-
|
|
43828
|
+
role: external_exports.string().describe(`Which specialist to ask: ${AGENT_ROLES.join(", ")}. Only the ones assigned in Settings \u2192 Agents can answer.`),
|
|
43829
|
+
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."),
|
|
43830
|
+
files: external_exports.array(external_exports.string()).optional().describe("Workspace-relative paths you are working in, so it knows what you are looking at.")
|
|
43620
43831
|
});
|
|
43621
|
-
function
|
|
43832
|
+
function createAskAgentTool(options) {
|
|
43622
43833
|
return {
|
|
43623
|
-
name: "
|
|
43834
|
+
name: "ask_agent",
|
|
43624
43835
|
group: "read",
|
|
43625
|
-
description: "Consult a
|
|
43836
|
+
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.",
|
|
43626
43837
|
parametersSchema: paramsSchema3,
|
|
43627
43838
|
async preview(params) {
|
|
43839
|
+
const agent = find(options.agents(), params.role);
|
|
43628
43840
|
return {
|
|
43629
43841
|
kind: "text",
|
|
43630
|
-
// Ground truth (invariant 8): the question that will
|
|
43842
|
+
// Ground truth (invariant 8): the question that will be sent, in full, and who to. This
|
|
43631
43843
|
// puts the user's code in front of another model, which is the decision being approved.
|
|
43632
|
-
text: `
|
|
43844
|
+
text: `Ask the ${params.role}${agent === void 0 ? "" : ` (${agent.label})`}:
|
|
43633
43845
|
|
|
43634
|
-
${params.question}
|
|
43846
|
+
${params.question}` + (params.files !== void 0 && params.files.length > 0 ? `
|
|
43635
43847
|
|
|
43636
|
-
Files named as relevant: ${params.files.join(", ")}` : ""
|
|
43848
|
+
Files named as relevant: ${params.files.join(", ")}` : "")
|
|
43637
43849
|
};
|
|
43638
43850
|
},
|
|
43639
43851
|
async execute(params, context) {
|
|
43852
|
+
const team = options.agents();
|
|
43853
|
+
const role = params.role.trim().toLowerCase();
|
|
43854
|
+
if (!isAgentRole(role)) {
|
|
43855
|
+
return { content: unknownRole(role, team), isError: true };
|
|
43856
|
+
}
|
|
43857
|
+
const agent = find(team, role);
|
|
43858
|
+
if (agent === void 0) {
|
|
43859
|
+
return {
|
|
43860
|
+
content: `No ${role} is assigned. ${describeTeam(team)} Assign one in Settings \u2192 Agents, or ask a different role.`,
|
|
43861
|
+
isError: true
|
|
43862
|
+
};
|
|
43863
|
+
}
|
|
43864
|
+
if (!agent.available) {
|
|
43865
|
+
return {
|
|
43866
|
+
content: `The ${role} cannot be reached: ${agent.reason ?? "it is unavailable."}`,
|
|
43867
|
+
isError: true
|
|
43868
|
+
};
|
|
43869
|
+
}
|
|
43640
43870
|
let result;
|
|
43641
43871
|
try {
|
|
43642
|
-
result = await options.consult({
|
|
43872
|
+
result = await options.consult(agent, {
|
|
43643
43873
|
question: params.question,
|
|
43644
43874
|
...params.files !== void 0 ? { files: params.files } : {},
|
|
43645
43875
|
...context.signal !== void 0 ? { signal: context.signal } : {}
|
|
43646
43876
|
});
|
|
43647
43877
|
} catch (error51) {
|
|
43648
43878
|
return {
|
|
43649
|
-
content: `The
|
|
43879
|
+
content: `The ${role} could not be reached: ${error51 instanceof Error ? error51.message : String(error51)}`,
|
|
43650
43880
|
isError: true
|
|
43651
43881
|
};
|
|
43652
43882
|
}
|
|
43653
43883
|
if (result.advice.trim().length === 0) {
|
|
43654
43884
|
return {
|
|
43655
|
-
content:
|
|
43885
|
+
content: `The ${role} returned nothing. Check what is assigned to it in Settings \u2192 Agents.`,
|
|
43656
43886
|
isError: true
|
|
43657
43887
|
};
|
|
43658
43888
|
}
|
|
@@ -43662,39 +43892,248 @@ Files named as relevant: ${params.files.join(", ")}` : ""}`
|
|
|
43662
43892
|
|
|
43663
43893
|
---
|
|
43664
43894
|
|
|
43665
|
-
That is advice from ${result.
|
|
43895
|
+
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.`
|
|
43666
43896
|
};
|
|
43667
43897
|
}
|
|
43668
43898
|
};
|
|
43669
43899
|
}
|
|
43900
|
+
function find(team, role) {
|
|
43901
|
+
const wanted = role.trim().toLowerCase();
|
|
43902
|
+
return team.find((agent) => agent.role === wanted);
|
|
43903
|
+
}
|
|
43904
|
+
function unknownRole(role, team) {
|
|
43905
|
+
return `There is no "${role}" role. The roles are: ${AGENT_ROLES.join(", ")}. ${describeTeam(team)}`;
|
|
43906
|
+
}
|
|
43907
|
+
function describeTeam(team) {
|
|
43908
|
+
const usable = team.filter((agent) => agent.available).map((agent) => agent.role);
|
|
43909
|
+
return usable.length === 0 ? "None are assigned on this machine." : `Assigned here: ${usable.join(", ")}.`;
|
|
43910
|
+
}
|
|
43670
43911
|
|
|
43671
|
-
// ../../packages/core/dist/
|
|
43672
|
-
function
|
|
43673
|
-
|
|
43674
|
-
|
|
43675
|
-
|
|
43676
|
-
|
|
43677
|
-
|
|
43678
|
-
|
|
43679
|
-
|
|
43912
|
+
// ../../packages/core/dist/agents/team.js
|
|
43913
|
+
function defaultAssignment(role, context) {
|
|
43914
|
+
return role === "expert" && context.cliAvailable ? { kind: "cli" } : void 0;
|
|
43915
|
+
}
|
|
43916
|
+
function resolveTeam(context) {
|
|
43917
|
+
const resolved = [];
|
|
43918
|
+
for (const role of AGENT_ROLES) {
|
|
43919
|
+
const assignment = context.config?.roles?.[role] ?? defaultAssignment(role, context);
|
|
43920
|
+
if (assignment === void 0)
|
|
43921
|
+
continue;
|
|
43922
|
+
const info = roleInfo(role);
|
|
43923
|
+
const prompt = assignment.prompt ?? defaultPromptFor(role);
|
|
43924
|
+
if (assignment.kind === "cli") {
|
|
43925
|
+
resolved.push({
|
|
43926
|
+
role,
|
|
43927
|
+
name: info.name,
|
|
43928
|
+
summary: info.summary,
|
|
43929
|
+
kind: "cli",
|
|
43930
|
+
label: "Claude",
|
|
43931
|
+
prompt,
|
|
43932
|
+
available: context.cliAvailable,
|
|
43933
|
+
...context.cliAvailable ? {} : { reason: "The Claude CLI is not available on this machine." }
|
|
43934
|
+
});
|
|
43935
|
+
continue;
|
|
43936
|
+
}
|
|
43937
|
+
const profile = context.profiles.find((candidate) => candidate.id === assignment.profileId);
|
|
43938
|
+
resolved.push({
|
|
43939
|
+
role,
|
|
43940
|
+
name: info.name,
|
|
43941
|
+
summary: info.summary,
|
|
43942
|
+
kind: "profile",
|
|
43943
|
+
...assignment.profileId !== void 0 ? { profileId: assignment.profileId } : {},
|
|
43944
|
+
label: profile?.label ?? assignment.profileId ?? "unassigned",
|
|
43945
|
+
prompt,
|
|
43946
|
+
available: profile !== void 0,
|
|
43947
|
+
/*
|
|
43948
|
+
* A profile that has been deleted leaves the role unavailable and says so, rather than
|
|
43949
|
+
* falling back to the model already doing the work. A specialist that is quietly the
|
|
43950
|
+
* primary model gives advice with nothing to distrust about it, which is worse than none.
|
|
43951
|
+
*/
|
|
43952
|
+
...profile === void 0 ? { reason: `No profile "${assignment.profileId ?? ""}" exists any more.` } : {}
|
|
43953
|
+
});
|
|
43954
|
+
}
|
|
43955
|
+
return resolved;
|
|
43956
|
+
}
|
|
43957
|
+
function budgetMatters(context) {
|
|
43958
|
+
const stated = context.config?.budgetMatters;
|
|
43959
|
+
if (stated !== void 0)
|
|
43960
|
+
return stated;
|
|
43961
|
+
return resolveTeam(context).some((agent) => agent.kind === "cli" && agent.available);
|
|
43962
|
+
}
|
|
43963
|
+
|
|
43964
|
+
// ../../packages/core/dist/agents/guidance.js
|
|
43965
|
+
var BUDGET_ADVICE = [
|
|
43966
|
+
"",
|
|
43967
|
+
"## Consultations cost money here",
|
|
43968
|
+
"",
|
|
43969
|
+
"Each one is charged. Make the first count \u2014 gather what is needed and ask one full question",
|
|
43970
|
+
"rather than opening with something you could have settled yourself. If a per-task budget runs",
|
|
43971
|
+
"out the specialist stops being available, and you finish the work alone, so spend it on the",
|
|
43972
|
+
"parts where another reader genuinely changes what you do."
|
|
43973
|
+
].join("\n");
|
|
43974
|
+
var DEFAULT_TEAM_GUIDANCE = [
|
|
43975
|
+
"You lead a small team. You do the work \u2014 reading, searching, editing, running things \u2014 and you",
|
|
43976
|
+
"consult specialists when another reader would genuinely change what you do.",
|
|
43977
|
+
"",
|
|
43978
|
+
"## Consult without being asked",
|
|
43979
|
+
"",
|
|
43980
|
+
"You do not need permission and you should not wait to be told. Ask when:",
|
|
43981
|
+
"",
|
|
43982
|
+
"- the task spans several files and you are not sure of the shape \u2014 ask the **expert** first,",
|
|
43983
|
+
" before you write anything;",
|
|
43984
|
+
"- you have finished a change of any substance \u2014 ask the **reviewer**, and say what you changed",
|
|
43985
|
+
" and why, not just what the diff looks like;",
|
|
43986
|
+
"- you are about to call something done that has no tests \u2014 ask the **tester** what would break",
|
|
43987
|
+
" it;",
|
|
43988
|
+
"- you are guessing at how this codebase does something \u2014 ask the **librarian** rather than",
|
|
43989
|
+
" inventing a convention.",
|
|
43990
|
+
"",
|
|
43991
|
+
'The user can also ask directly ("ask the reviewer to look at this"), and then you consult that',
|
|
43992
|
+
"role whatever you would have chosen.",
|
|
43993
|
+
"",
|
|
43994
|
+
"## What makes a consultation worth it",
|
|
43995
|
+
"",
|
|
43996
|
+
"A specialist cannot see the workspace. It knows only what you put in the question, so **paste",
|
|
43997
|
+
'the code**, the error, the failing output \u2014 the actual text. A question like "is my retry logic',
|
|
43998
|
+
'right?" with nothing attached comes back as a list of things retry logic usually gets wrong,',
|
|
43999
|
+
"which you already knew.",
|
|
44000
|
+
"",
|
|
44001
|
+
"Ask one full question rather than three thin ones. Each consultation is a fresh reader with no",
|
|
44002
|
+
"memory of the last, so a follow-up has to carry its own context.",
|
|
44003
|
+
"",
|
|
44004
|
+
"## What not to do",
|
|
44005
|
+
"",
|
|
44006
|
+
"- Do not consult on something you can settle by reading a file. Read it.",
|
|
44007
|
+
"- Do not relay advice you have not checked. You have the code open and the specialist does not;",
|
|
44008
|
+
" if it is wrong, say so and say why \u2014 to the user, and in your next question.",
|
|
44009
|
+
"- Do not consult the same role twice with the same question hoping for a better answer."
|
|
44010
|
+
].join("\n");
|
|
44011
|
+
function buildTeamGuidance(agents, custom2, budgetMatters2) {
|
|
44012
|
+
const base = custom2 !== void 0 && custom2.trim().length > 0 ? custom2 : DEFAULT_TEAM_GUIDANCE;
|
|
44013
|
+
const advice = budgetMatters2 === true ? `${base}
|
|
44014
|
+
${BUDGET_ADVICE}` : base;
|
|
44015
|
+
if (agents.length === 0) {
|
|
44016
|
+
return [
|
|
44017
|
+
advice,
|
|
44018
|
+
"",
|
|
44019
|
+
"## Your team",
|
|
44020
|
+
"",
|
|
44021
|
+
"**Nobody is assigned yet.** Until somebody is, do the work yourself and tell the user that",
|
|
44022
|
+
"assigning a specialist in Settings \u2192 Agents would let you consult one."
|
|
44023
|
+
].join("\n");
|
|
44024
|
+
}
|
|
44025
|
+
return [
|
|
44026
|
+
advice,
|
|
43680
44027
|
"",
|
|
43681
|
-
"
|
|
43682
|
-
" have is below. If something essential is missing, say exactly what you need and why, then",
|
|
43683
|
-
" give the best answer you can without it \u2014 do not refuse to answer.",
|
|
43684
|
-
"- Your reply is advice. The assistant will check it against the real code before acting, and",
|
|
43685
|
-
" it is responsible for the result. Be concrete, say what you are unsure about, and say when",
|
|
43686
|
-
" a thing must be verified rather than assumed.",
|
|
44028
|
+
"## Your team",
|
|
43687
44029
|
"",
|
|
43688
|
-
"
|
|
44030
|
+
"Reach any of them with `ask_agent`, naming the role:",
|
|
43689
44031
|
"",
|
|
43690
|
-
|
|
44032
|
+
...agents.map((agent) => `- **${agent.role}** (${agent.label}) \u2014 ${agent.summary}`)
|
|
44033
|
+
].join("\n");
|
|
44034
|
+
}
|
|
44035
|
+
|
|
44036
|
+
// ../../packages/core/dist/agents/briefing.js
|
|
44037
|
+
var DESCRIPTION_LIMIT = 110;
|
|
44038
|
+
function firstLine(text, limit = DESCRIPTION_LIMIT) {
|
|
44039
|
+
const line = text.split("\n").find((candidate) => candidate.trim().length > 0)?.trim() ?? "";
|
|
44040
|
+
return line.length > limit ? `${line.slice(0, limit - 1).trimEnd()}\u2026` : line;
|
|
44041
|
+
}
|
|
44042
|
+
function buildAgentBriefing(input) {
|
|
44043
|
+
const tools = (input.tools ?? []).filter(
|
|
44044
|
+
// Telling a specialist it can consult a specialist is noise at best and a loop at worst.
|
|
44045
|
+
(tool) => tool.name !== "ask_agent" && tool.name !== "ask_expert"
|
|
44046
|
+
);
|
|
44047
|
+
const skills = input.skills ?? [];
|
|
44048
|
+
if (tools.length === 0 && skills.length === 0)
|
|
44049
|
+
return "";
|
|
44050
|
+
const sections = [
|
|
44051
|
+
"## What the assistant can do on your behalf",
|
|
43691
44052
|
"",
|
|
43692
|
-
|
|
44053
|
+
"You have no tools. The assistant asking you does, and will carry out whatever you recommend.",
|
|
44054
|
+
"Name the tool or skill you mean rather than describing a manual procedure that duplicates it."
|
|
43693
44055
|
];
|
|
43694
|
-
if (
|
|
43695
|
-
|
|
44056
|
+
if (tools.length > 0) {
|
|
44057
|
+
sections.push("", "### Tools it can call", "", ...tools.map((tool) => `- \`${tool.name}\` \u2014 ${firstLine(tool.description)}`));
|
|
44058
|
+
}
|
|
44059
|
+
if (skills.length > 0) {
|
|
44060
|
+
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)}`));
|
|
44061
|
+
}
|
|
44062
|
+
return sections.join("\n");
|
|
44063
|
+
}
|
|
44064
|
+
|
|
44065
|
+
// ../../packages/core/dist/agents/consult.js
|
|
44066
|
+
var CONSULT_MAX_STEPS = 5;
|
|
44067
|
+
var ALLOWED_GROUPS = /* @__PURE__ */ new Set(["read"]);
|
|
44068
|
+
function toolsForConsultation(all) {
|
|
44069
|
+
return all.filter((tool) => ALLOWED_GROUPS.has(tool.group) && tool.name !== "ask_agent" && tool.name !== "ask_expert");
|
|
44070
|
+
}
|
|
44071
|
+
async function runConsultation(options) {
|
|
44072
|
+
const limit = options.maxSteps ?? CONSULT_MAX_STEPS;
|
|
44073
|
+
const messages = [{ role: "user", content: options.prompt }];
|
|
44074
|
+
const byName = new Map(options.tools.map((tool) => [tool.name, tool]));
|
|
44075
|
+
let steps = 0;
|
|
44076
|
+
for (; ; ) {
|
|
44077
|
+
const atCap = steps >= limit;
|
|
44078
|
+
let text = "";
|
|
44079
|
+
let call;
|
|
44080
|
+
for await (const chunk of options.provider.streamChat(messages, {
|
|
44081
|
+
...options.signal !== void 0 ? { signal: options.signal } : {},
|
|
44082
|
+
/*
|
|
44083
|
+
* The tools are withdrawn on the final pass, not merely discouraged.
|
|
44084
|
+
*
|
|
44085
|
+
* A model asked politely to stop looking things up will sometimes look one more thing up,
|
|
44086
|
+
* and then there is no turn left to answer in. Removing them makes answering the only
|
|
44087
|
+
* available move.
|
|
44088
|
+
*/
|
|
44089
|
+
...atCap || options.definitions.length === 0 ? {} : { tools: [...options.definitions] }
|
|
44090
|
+
})) {
|
|
44091
|
+
if (chunk.type === "text")
|
|
44092
|
+
text += chunk.text;
|
|
44093
|
+
else if (chunk.type === "toolCall" && call === void 0) {
|
|
44094
|
+
call = {
|
|
44095
|
+
id: chunk.toolCall.id,
|
|
44096
|
+
name: chunk.toolCall.name,
|
|
44097
|
+
arguments: chunk.toolCall.arguments
|
|
44098
|
+
};
|
|
44099
|
+
} else if (chunk.type === "error") {
|
|
44100
|
+
throw new Error(chunk.error);
|
|
44101
|
+
}
|
|
44102
|
+
}
|
|
44103
|
+
if (call === void 0)
|
|
44104
|
+
return { advice: text, steps, truncated: atCap && steps > 0 };
|
|
44105
|
+
messages.push({ role: "assistant", content: text, toolCalls: [call] });
|
|
44106
|
+
options.onStep?.(call.name);
|
|
44107
|
+
steps += 1;
|
|
44108
|
+
const tool = byName.get(call.name);
|
|
44109
|
+
if (tool === void 0) {
|
|
44110
|
+
messages.push({
|
|
44111
|
+
role: "tool",
|
|
44112
|
+
toolCallId: call.id,
|
|
44113
|
+
content: `You have no "${call.name}". You are read-only here: ${[...byName.keys()].join(", ")}. Anything else, recommend and the assistant will do it.`
|
|
44114
|
+
});
|
|
44115
|
+
continue;
|
|
44116
|
+
}
|
|
44117
|
+
try {
|
|
44118
|
+
const parsed = tool.parametersSchema.safeParse(JSON.parse(call.arguments || "{}"));
|
|
44119
|
+
const result = parsed.success ? await tool.execute(parsed.data, options.context) : {
|
|
44120
|
+
content: `Those arguments are not valid: ${parsed.error.issues.map((i) => i.message).join("; ")}`
|
|
44121
|
+
};
|
|
44122
|
+
messages.push({ role: "tool", toolCallId: call.id, content: String(result.content) });
|
|
44123
|
+
} catch (error51) {
|
|
44124
|
+
messages.push({
|
|
44125
|
+
role: "tool",
|
|
44126
|
+
toolCallId: call.id,
|
|
44127
|
+
content: `That failed: ${error51 instanceof Error ? error51.message : String(error51)}`
|
|
44128
|
+
});
|
|
44129
|
+
}
|
|
44130
|
+
if (steps >= limit) {
|
|
44131
|
+
messages.push({
|
|
44132
|
+
role: "user",
|
|
44133
|
+
content: "That is all the looking up you can do. Answer now with what you have, and say plainly what you could not check."
|
|
44134
|
+
});
|
|
44135
|
+
}
|
|
43696
44136
|
}
|
|
43697
|
-
return lines.join("\n");
|
|
43698
44137
|
}
|
|
43699
44138
|
|
|
43700
44139
|
// ../../packages/core/dist/tools/recallExpert.js
|
|
@@ -43823,8 +44262,8 @@ function assessmentForBriefing(assessment) {
|
|
|
43823
44262
|
}
|
|
43824
44263
|
|
|
43825
44264
|
// ../../packages/core/dist/expert/briefing.js
|
|
43826
|
-
var
|
|
43827
|
-
function
|
|
44265
|
+
var DESCRIPTION_LIMIT2 = 110;
|
|
44266
|
+
function firstLine2(text, limit = DESCRIPTION_LIMIT2) {
|
|
43828
44267
|
const line = text.split("\n").find((candidate) => candidate.trim().length > 0)?.trim() ?? "";
|
|
43829
44268
|
return line.length > limit ? `${line.slice(0, limit - 1).trimEnd()}\u2026` : line;
|
|
43830
44269
|
}
|
|
@@ -43863,7 +44302,7 @@ function buildExpertBriefing(input) {
|
|
|
43863
44302
|
const assessed = assessmentForBriefing(input.juniorAssessment);
|
|
43864
44303
|
if (assessed !== void 0)
|
|
43865
44304
|
sections.push("", assessed);
|
|
43866
|
-
const listed = (tools) => [...tools].sort((a, b) => a.name.localeCompare(b.name)).map((tool) => `- ${tool.name} \u2014 ${
|
|
44305
|
+
const listed = (tools) => [...tools].sort((a, b) => a.name.localeCompare(b.name)).map((tool) => `- ${tool.name} \u2014 ${firstLine2(tool.description)}`);
|
|
43867
44306
|
const dispatchOnly = input.dispatchOnlyTools ?? [];
|
|
43868
44307
|
const everyTool = [...input.promptTools, ...dispatchOnly];
|
|
43869
44308
|
if (everyTool.length > 0) {
|
|
@@ -43880,7 +44319,7 @@ function buildExpertBriefing(input) {
|
|
|
43880
44319
|
const skills = input.skills ?? [];
|
|
43881
44320
|
if (skills.length > 0) {
|
|
43882
44321
|
sections.push("", `### Project knowledge written down for the junior (${skills.length})`, "");
|
|
43883
|
-
sections.push(...skills.map((skill) => `- ${skill.name} \u2014 ${
|
|
44322
|
+
sections.push(...skills.map((skill) => `- ${skill.name} \u2014 ${firstLine2(skill.description)}`));
|
|
43884
44323
|
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.");
|
|
43885
44324
|
}
|
|
43886
44325
|
return sections.join("\n");
|
|
@@ -55855,124 +56294,19 @@ var ASK_MODE = {
|
|
|
55855
56294
|
description: "Read-only: inspect the workspace and answer questions. Cannot edit or run commands.",
|
|
55856
56295
|
groups: ["read", "mcp", "always"]
|
|
55857
56296
|
};
|
|
55858
|
-
var
|
|
55859
|
-
id: "
|
|
55860
|
-
name: "
|
|
55861
|
-
description: "
|
|
56297
|
+
var AGENT_TEAM_MODE = {
|
|
56298
|
+
id: "agent-team",
|
|
56299
|
+
name: "Agent team",
|
|
56300
|
+
description: "You lead; specialists you assign are consulted as needed. Requires at least one agent.",
|
|
55862
56301
|
groups: ["read", "edit", "command", "mcp", "always"],
|
|
55863
|
-
requiresExpert: true
|
|
55864
|
-
guidance: [
|
|
55865
|
-
"# Junior mode",
|
|
55866
|
-
"",
|
|
55867
|
-
"You are the junior on this task. A stronger model (Claude) is available through",
|
|
55868
|
-
"`ask_expert` and is the one that decides *what* to do; you decide *how* and carry it out.",
|
|
55869
|
-
"You are the hands: reading, searching, editing, running commands, checking results.",
|
|
55870
|
-
"",
|
|
55871
|
-
"## The first consultation is expensive; the rest are cheap",
|
|
55872
|
-
"",
|
|
55873
|
-
"Consultations in one task continue **one conversation**. The first pays to establish it",
|
|
55874
|
-
"and costs roughly twenty times a follow-up; every one after that is cheap and the expert",
|
|
55875
|
-
"still remembers everything you have told it.",
|
|
55876
|
-
"",
|
|
55877
|
-
"Two things follow, and they matter more than any other instruction here:",
|
|
55878
|
-
"",
|
|
55879
|
-
"1. **Make the first consultation count.** Gather what is needed first and ask one full,",
|
|
55880
|
-
' well-formed question. Do not open with "hello" or a question you could answer yourself \u2014',
|
|
55881
|
-
" you are paying the setup cost either way, so spend it on something real.",
|
|
55882
|
-
"2. **Never repeat yourself afterwards.** The expert remembers the code you pasted, the plan",
|
|
55883
|
-
' it gave you and what you have tried. A follow-up is "step 3 failed with this error",',
|
|
55884
|
-
" not the whole story again. Re-explaining throws away the entire saving.",
|
|
55885
|
-
"",
|
|
55886
|
-
"## Consulting is the default, not the exception",
|
|
55887
|
-
"",
|
|
55888
|
-
"On any request that is not trivial, **your first action is `ask_expert`** \u2014 before you plan,",
|
|
55889
|
-
"before you edit, before you decide the task is straightforward. Do not wait to be told. If",
|
|
55890
|
-
'the user has to say "ask the expert", this mode has failed and is costing them the price of',
|
|
55891
|
-
"a worse model for no benefit.",
|
|
55892
|
-
"",
|
|
55893
|
-
"A request is **not** trivial, and you must consult, if any of these is true:",
|
|
55894
|
-
"",
|
|
55895
|
-
"- it touches more than one file, or a file you have not read in this session;",
|
|
55896
|
-
"- it asks you to design, refactor, choose an approach, or decide between options;",
|
|
55897
|
-
"- it involves code you did not write in this conversation;",
|
|
55898
|
-
"- you would have to guess at how something works to proceed;",
|
|
55899
|
-
"- your first attempt failed, or a test or command reported an error;",
|
|
55900
|
-
'- you are about to say "I think" or "probably" about anything load-bearing.',
|
|
55901
|
-
"",
|
|
55902
|
-
"When in doubt, consult. A consultation costs cents. Confidently doing the wrong thing costs",
|
|
55903
|
-
"the user their afternoon.",
|
|
55904
|
-
"",
|
|
55905
|
-
"Ask for a concrete plan, the files involved, and the traps to avoid \u2014 **broken into",
|
|
55906
|
-
"checkpoints**, as described below.",
|
|
55907
|
-
"",
|
|
55908
|
-
"**Genuinely trivial requests you simply do:** fixing a typo you can see, answering a",
|
|
55909
|
-
"question about a file you have already read, running a command the user named. Asking about",
|
|
55910
|
-
"those would waste the user\u2019s money on something you already know.",
|
|
55911
|
-
"",
|
|
55912
|
-
"## Checkpoints: implement, review, continue",
|
|
55913
|
-
"",
|
|
55914
|
-
"For anything larger than a single edit, ask the expert to split the plan into **checkpoints**.",
|
|
55915
|
-
"Then work the loop: implement one checkpoint, go back to the expert with what you actually",
|
|
55916
|
-
"did, take its feedback, and move to the next. Keep going until the work is complete.",
|
|
55917
|
-
"",
|
|
55918
|
-
"**This is a cost measure, not a quality ritual, and the distinction decides how you use it.**",
|
|
55919
|
-
"The expensive failure in this arrangement is not a consultation \u2014 it is you building the",
|
|
55920
|
-
"wrong thing for twenty turns and then needing the whole approach redone. A review after each",
|
|
55921
|
-
"checkpoint costs about as much as one cheap follow-up and caps how far a wrong direction can",
|
|
55922
|
-
"run before someone notices. It only pays if you keep it cheap:",
|
|
55923
|
-
"",
|
|
55924
|
-
"- **A checkpoint is a unit worth reviewing** \u2014 a coherent, working slice, typically a few",
|
|
55925
|
-
" related edits. If a checkpoint is one line, the review costs more than the mistake it",
|
|
55926
|
-
" could catch: fold it into the next one. If it is the entire feature, it is not a",
|
|
55927
|
-
" checkpoint and defeats the point.",
|
|
55928
|
-
'- **Report the delta, never the context.** "Checkpoint 2 done: added `retryWithBackoff` in',
|
|
55929
|
-
" `http.ts`, wired it into `send()`, tests pass. Deviated from the plan by keeping the old",
|
|
55930
|
-
' signature, because three callers depend on it." The expert has the plan and remembers the',
|
|
55931
|
-
"code \u2014 it can open anything it wants to see for itself.",
|
|
55932
|
-
"- **Say what surprised you.** The parts worth a review are the deviations, the things that",
|
|
55933
|
-
" did not match the plan, and anything you were unsure about. A checkpoint that went exactly",
|
|
55934
|
-
" as planned needs a sentence, not a report.",
|
|
55935
|
-
"- **Skip the review** when a checkpoint was mechanical and everything passed. Say so at the",
|
|
55936
|
-
" next one instead. Two checkpoints in one review is cheaper than two reviews.",
|
|
55937
|
-
'- **Run the tests before you report.** "Tests pass" is worth far more to the reviewer than a',
|
|
55938
|
-
" description of the code, and finding it yourself is free where the expert finding it is not.",
|
|
55939
|
-
"",
|
|
55940
|
-
"If a budget is set the expert stops being available once it is reached, and you finish the",
|
|
55941
|
-
"work alone. Spend the consultations you have on the checkpoints that carry the most risk.",
|
|
55942
|
-
"",
|
|
55943
|
-
"**Also consult again when:**",
|
|
55944
|
-
"- the same step has failed twice and you do not understand why;",
|
|
55945
|
-
"- the code contradicts the plan, so following it would be wrong;",
|
|
55946
|
-
"- something is ambiguous in a way that changes *what* should be built, not merely how.",
|
|
55947
|
-
"",
|
|
55948
|
-
"## Gather the context before you ask",
|
|
55949
|
-
"",
|
|
55950
|
-
"The expert can open files itself, but doing so costs the user far more than it costs you.",
|
|
55951
|
-
"So before consulting: find the relevant code, read it, and **include the actual code in",
|
|
55952
|
-
"your question** along with what you have already tried and what happened.",
|
|
55953
|
-
"",
|
|
55954
|
-
"## You are its hands for tools, too",
|
|
55955
|
-
"",
|
|
55956
|
-
"The expert cannot call any of your tools \u2014 no MCP tool, no Python tool, no searching the",
|
|
55957
|
-
"documentation index. It is told what you have, by name, but not the exact parameters. So",
|
|
55958
|
-
"if it asks you to look up a tool\u2019s arguments or read a skill, do it and report back in the",
|
|
55959
|
-
"same conversation; that round trip is cheap and stops it guessing a signature.",
|
|
55960
|
-
"",
|
|
55961
|
-
"## Carrying out the plan",
|
|
55962
|
-
"",
|
|
55963
|
-
"Follow it, but you are not a transcription service. The expert never ran anything and may",
|
|
55964
|
-
"be wrong about the real code. If a step does not match what you find, say so and adapt \u2014",
|
|
55965
|
-
"and if the mismatch is fundamental, that is one of the reasons to consult again.",
|
|
55966
|
-
"",
|
|
55967
|
-
"Tell the user which checkpoint you are on and what the expert said about the last one, so",
|
|
55968
|
-
"they can see what they paid for and stop you if the direction is wrong. They are the only",
|
|
55969
|
-
"reviewer whose approval actually gates anything."
|
|
55970
|
-
].join("\n")
|
|
56302
|
+
requiresExpert: true
|
|
55971
56303
|
};
|
|
55972
|
-
var BUILTIN_MODES = [CODE_MODE, ASK_MODE,
|
|
56304
|
+
var BUILTIN_MODES = [CODE_MODE, ASK_MODE, AGENT_TEAM_MODE];
|
|
55973
56305
|
var DEFAULT_MODE_ID = CODE_MODE.id;
|
|
56306
|
+
var RENAMED = { junior: AGENT_TEAM_MODE.id };
|
|
55974
56307
|
function findMode(id) {
|
|
55975
|
-
|
|
56308
|
+
const resolved = id !== void 0 ? RENAMED[id] ?? id : id;
|
|
56309
|
+
return BUILTIN_MODES.find((mode) => mode.id === resolved) ?? CODE_MODE;
|
|
55976
56310
|
}
|
|
55977
56311
|
|
|
55978
56312
|
// ../../packages/core/dist/modes/resolve.js
|
|
@@ -59643,6 +59977,8 @@ ${preview.text}` } : {}
|
|
|
59643
59977
|
return [skillsDir, ...extraSkillDirs].filter((dir) => dir !== void 0);
|
|
59644
59978
|
}
|
|
59645
59979
|
let skills = [];
|
|
59980
|
+
let agentBriefingTools;
|
|
59981
|
+
let consultationContext;
|
|
59646
59982
|
let skillIssues = [];
|
|
59647
59983
|
const refreshSkills = async () => {
|
|
59648
59984
|
const dirs = skillSearchPath();
|
|
@@ -59812,17 +60148,21 @@ ${preview.text}` } : {}
|
|
|
59812
60148
|
const warnedExpiries = /* @__PURE__ */ new Set();
|
|
59813
60149
|
let expertCli;
|
|
59814
60150
|
let expertCliPath;
|
|
60151
|
+
async function detectCli(configured) {
|
|
60152
|
+
if (expertCli !== void 0 && expertCliPath === configured)
|
|
60153
|
+
return expertCli;
|
|
60154
|
+
expertCliPath = configured;
|
|
60155
|
+
expertCli = await detectClaudeCli(configured);
|
|
60156
|
+
if (!expertCli.available)
|
|
60157
|
+
logger.warn("expert unavailable", expertCli.reason ?? "");
|
|
60158
|
+
void postAgents();
|
|
60159
|
+
return expertCli;
|
|
60160
|
+
}
|
|
59815
60161
|
async function resolveExpert(config2) {
|
|
59816
60162
|
if (config2.expert?.enabled !== true)
|
|
59817
60163
|
return void 0;
|
|
59818
|
-
const
|
|
59819
|
-
|
|
59820
|
-
expertCliPath = configured;
|
|
59821
|
-
expertCli = await detectClaudeCli(configured);
|
|
59822
|
-
if (!expertCli.available)
|
|
59823
|
-
logger.warn("expert unavailable", expertCli.reason ?? "");
|
|
59824
|
-
}
|
|
59825
|
-
return expertCli.available ? expertCli : void 0;
|
|
60164
|
+
const detected = await detectCli(config2.expert.path ?? "claude");
|
|
60165
|
+
return detected.available ? detected : void 0;
|
|
59826
60166
|
}
|
|
59827
60167
|
let queuedMessages = [];
|
|
59828
60168
|
function postQueued() {
|
|
@@ -59832,6 +60172,7 @@ ${preview.text}` } : {}
|
|
|
59832
60172
|
let taskCheckpoint;
|
|
59833
60173
|
const ACTIVE_TASK_KEY = "lightCode.activeTaskId";
|
|
59834
60174
|
let activeTaskId = services.workspaceState.get(ACTIVE_TASK_KEY);
|
|
60175
|
+
let activePlan;
|
|
59835
60176
|
let activeTaskCreatedAt = Date.now();
|
|
59836
60177
|
async function setActiveTaskId(id) {
|
|
59837
60178
|
activeTaskId = id;
|
|
@@ -60074,7 +60415,9 @@ ${preview.text}` } : {}
|
|
|
60074
60415
|
}
|
|
60075
60416
|
let cachedModeId;
|
|
60076
60417
|
let cachedCodeGenerator;
|
|
60077
|
-
let
|
|
60418
|
+
let cachedTeam = [];
|
|
60419
|
+
let cachedTeamGuidance;
|
|
60420
|
+
let cachedBudgetMatters = false;
|
|
60078
60421
|
let cachedMentionExcludes;
|
|
60079
60422
|
let cachedReportsCost;
|
|
60080
60423
|
let measuringStep;
|
|
@@ -60115,7 +60458,17 @@ ${preview.text}` } : {}
|
|
|
60115
60458
|
const { config: config2 } = await configManager.load();
|
|
60116
60459
|
cachedApprovals = approvalsFrom(config2.approvals);
|
|
60117
60460
|
cachedCodeGenerator = codeGeneratorFor(config2);
|
|
60118
|
-
|
|
60461
|
+
const teamContext = {
|
|
60462
|
+
config: config2.agents,
|
|
60463
|
+
profiles: (config2.profiles ?? []).map((profile) => ({
|
|
60464
|
+
id: profile.id,
|
|
60465
|
+
label: profile.label
|
|
60466
|
+
})),
|
|
60467
|
+
cliAvailable: expertCli?.available === true
|
|
60468
|
+
};
|
|
60469
|
+
cachedTeam = resolveTeam(teamContext);
|
|
60470
|
+
cachedTeamGuidance = config2.agents?.teamGuidance;
|
|
60471
|
+
cachedBudgetMatters = budgetMatters(teamContext);
|
|
60119
60472
|
cachedProgrammingProfileId = config2.programmingProfileId;
|
|
60120
60473
|
cachedOffice = config2.office ?? {};
|
|
60121
60474
|
cachedMail = config2.mail ?? {};
|
|
@@ -60410,18 +60763,18 @@ ${preview.text}` } : {}
|
|
|
60410
60763
|
observer: searchLog
|
|
60411
60764
|
}));
|
|
60412
60765
|
}
|
|
60413
|
-
|
|
60414
|
-
|
|
60415
|
-
|
|
60416
|
-
|
|
60417
|
-
consult:
|
|
60418
|
-
label: providerExpert.label,
|
|
60419
|
-
onAdvice: (record2) => expertAdvice.push(record2)
|
|
60766
|
+
if (cachedTeam.some((agent) => agent.available)) {
|
|
60767
|
+
combined.register(createAskAgentTool({
|
|
60768
|
+
agents: () => cachedTeam,
|
|
60769
|
+
onAdvice: (record2) => expertAdvice.push(record2),
|
|
60770
|
+
consult: async (agent, request) => consultAgent(agent, request)
|
|
60420
60771
|
}));
|
|
60421
|
-
}
|
|
60772
|
+
}
|
|
60773
|
+
if (expert !== void 0) {
|
|
60422
60774
|
combined.register(createRecallExpertTool({ history: () => expertAdvice }));
|
|
60423
60775
|
combined.register(createAskExpertTool({
|
|
60424
60776
|
cli: expert.cli,
|
|
60777
|
+
budgetMatters: cachedBudgetMatters,
|
|
60425
60778
|
...expert.model !== void 0 ? { model: expert.model } : {},
|
|
60426
60779
|
onConsultation: recordConsultation,
|
|
60427
60780
|
onAdvice: (record2) => expertAdvice.push(record2),
|
|
@@ -60461,6 +60814,7 @@ ${preview.text}` } : {}
|
|
|
60461
60814
|
})
|
|
60462
60815
|
}));
|
|
60463
60816
|
}
|
|
60817
|
+
agentBriefingTools = () => combined.list();
|
|
60464
60818
|
return combined;
|
|
60465
60819
|
}
|
|
60466
60820
|
async function syncMcpFromConfig(config2) {
|
|
@@ -60537,7 +60891,8 @@ ${preview.text}` } : {}
|
|
|
60537
60891
|
createdAt: activeTaskCreatedAt,
|
|
60538
60892
|
updatedAt: Date.now(),
|
|
60539
60893
|
messages,
|
|
60540
|
-
resultHandles: truncationStore.spilledHandles()
|
|
60894
|
+
resultHandles: truncationStore.spilledHandles(),
|
|
60895
|
+
...activePlan !== void 0 && activePlan.trim().length > 0 ? { plan: activePlan } : {}
|
|
60541
60896
|
};
|
|
60542
60897
|
try {
|
|
60543
60898
|
await taskStore.save(redactTask(task, await knownSecretValues()));
|
|
@@ -60565,8 +60920,10 @@ ${preview.text}` } : {}
|
|
|
60565
60920
|
taskCheckpoint = void 0;
|
|
60566
60921
|
activeTaskCreatedAt = task.createdAt;
|
|
60567
60922
|
truncationStore.startTask(task.resultHandles);
|
|
60923
|
+
activePlan = task.plan;
|
|
60568
60924
|
await setActiveTaskId(task.id);
|
|
60569
60925
|
post({ type: "taskRestored", taskId: task.id, entries: toTranscript(task.messages) });
|
|
60926
|
+
post({ type: "plan", plan: activePlan ?? "" });
|
|
60570
60927
|
await postTasks();
|
|
60571
60928
|
}
|
|
60572
60929
|
async function startNewTask() {
|
|
@@ -60576,8 +60933,10 @@ ${preview.text}` } : {}
|
|
|
60576
60933
|
taskCheckpoint = void 0;
|
|
60577
60934
|
activeTaskCreatedAt = Date.now();
|
|
60578
60935
|
truncationStore.startTask();
|
|
60936
|
+
activePlan = void 0;
|
|
60579
60937
|
await setActiveTaskId(void 0);
|
|
60580
60938
|
post({ type: "taskRestored", taskId: void 0, entries: [] });
|
|
60939
|
+
post({ type: "plan", plan: "" });
|
|
60581
60940
|
await postTasks();
|
|
60582
60941
|
}
|
|
60583
60942
|
async function deleteTask(id) {
|
|
@@ -60658,6 +61017,8 @@ ${preview.text}` } : {}
|
|
|
60658
61017
|
].filter((section) => section.length > 0).join("\n\n") : renderSkillsForPrompt(turnSkills),
|
|
60659
61018
|
skillsSearchable,
|
|
60660
61019
|
canWriteSkills: skillsDir !== void 0,
|
|
61020
|
+
// Last in the prompt, and the most specific thing in it — see `agent/plan.ts`.
|
|
61021
|
+
...activePlan !== void 0 && activePlan.trim().length > 0 ? { plan: activePlan } : {},
|
|
60661
61022
|
// Only when a pool actually exists: telling the model about a tool it has not been given
|
|
60662
61023
|
// is how it comes to report that it looked somewhere it could not reach.
|
|
60663
61024
|
teamSkillsAvailable: config2.embedder?.skillsAlias !== void 0,
|
|
@@ -60679,7 +61040,9 @@ ${preview.text}` } : {}
|
|
|
60679
61040
|
*/
|
|
60680
61041
|
...(() => {
|
|
60681
61042
|
const parts = [];
|
|
60682
|
-
if (activeMode.
|
|
61043
|
+
if (activeMode.id === AGENT_TEAM_MODE.id) {
|
|
61044
|
+
parts.push(buildTeamGuidance(cachedTeam.filter((agent) => agent.available), cachedTeamGuidance, cachedBudgetMatters));
|
|
61045
|
+
} else if (activeMode.guidance !== void 0 && (activeMode.requiresExpert !== true || expertCliInfo !== void 0)) {
|
|
60683
61046
|
parts.push(activeMode.guidance);
|
|
60684
61047
|
}
|
|
60685
61048
|
if (scheduledGuidance !== void 0)
|
|
@@ -60715,6 +61078,7 @@ ${preview.text}` } : {}
|
|
|
60715
61078
|
// lives in the VSIX, so resolving it is a host concern (§4).
|
|
60716
61079
|
...ripgrepPath !== void 0 ? { ripgrepPath } : {}
|
|
60717
61080
|
};
|
|
61081
|
+
consultationContext = () => toolContext;
|
|
60718
61082
|
pythonNestedContext = toolContext;
|
|
60719
61083
|
pythonNestedCallsAllowed = schedule === void 0;
|
|
60720
61084
|
const mentions = await resolveMentions(text, { fs: toolContext.fs, workspaceRoot, denylist });
|
|
@@ -60756,7 +61120,7 @@ ${preview.text}` } : {}
|
|
|
60756
61120
|
}
|
|
60757
61121
|
let cumulativeText = "";
|
|
60758
61122
|
let cumulativeReasoning = "";
|
|
60759
|
-
let
|
|
61123
|
+
let informedBy;
|
|
60760
61124
|
const fullRegistry = currentToolRegistry(
|
|
60761
61125
|
expertCliInfo !== void 0 ? {
|
|
60762
61126
|
cli: expertCliInfo,
|
|
@@ -60840,7 +61204,7 @@ ${preview.text}` } : {}
|
|
|
60840
61204
|
post({
|
|
60841
61205
|
type: "textChunk",
|
|
60842
61206
|
text: cumulativeText,
|
|
60843
|
-
...
|
|
61207
|
+
...informedBy !== void 0 ? { expertInformed: true, informedBy } : {}
|
|
60844
61208
|
});
|
|
60845
61209
|
},
|
|
60846
61210
|
onReasoningChunk: (chunk) => {
|
|
@@ -60850,22 +61214,18 @@ ${preview.text}` } : {}
|
|
|
60850
61214
|
onToolCall: (toolCall) => {
|
|
60851
61215
|
cumulativeText = "";
|
|
60852
61216
|
cumulativeReasoning = "";
|
|
60853
|
-
|
|
60854
|
-
|
|
61217
|
+
const consulting = consultationFromToolCall(toolCall.name, toolCall.arguments);
|
|
61218
|
+
if (consulting !== void 0)
|
|
61219
|
+
informedBy = consulting;
|
|
60855
61220
|
if (CONTROL_TOOLS.has(toolCall.name))
|
|
60856
61221
|
return;
|
|
60857
61222
|
if (chartFromToolCall(toolCall.name, toolCall.arguments) !== void 0)
|
|
60858
61223
|
return;
|
|
60859
|
-
const summary =
|
|
60860
|
-
id: toolCall.id,
|
|
60861
|
-
name: toolCall.name,
|
|
60862
|
-
arguments: formatToolArguments(toolCall.arguments),
|
|
60863
|
-
...toolCallReason(toolCall.arguments) === void 0 ? {} : { why: toolCallReason(toolCall.arguments) }
|
|
60864
|
-
};
|
|
61224
|
+
const summary = toolCallSummary(toolCall);
|
|
60865
61225
|
post({
|
|
60866
61226
|
type: "toolCall",
|
|
60867
61227
|
toolCall: summary,
|
|
60868
|
-
...
|
|
61228
|
+
...informedBy !== void 0 ? { expertInformed: true, informedBy } : {}
|
|
60869
61229
|
});
|
|
60870
61230
|
},
|
|
60871
61231
|
onToolResult: (toolCall, result) => {
|
|
@@ -60878,22 +61238,18 @@ ${preview.text}` } : {}
|
|
|
60878
61238
|
post(chart.kind === "chart" ? {
|
|
60879
61239
|
type: "chart",
|
|
60880
61240
|
chart: chart.chart,
|
|
60881
|
-
...
|
|
61241
|
+
...informedBy !== void 0 ? { expertInformed: true, informedBy } : {}
|
|
60882
61242
|
} : { type: "chartError", message: chart.message });
|
|
60883
61243
|
return;
|
|
60884
61244
|
}
|
|
60885
|
-
const summary = {
|
|
60886
|
-
id: toolCall.id,
|
|
60887
|
-
name: toolCall.name,
|
|
60888
|
-
arguments: formatToolArguments(toolCall.arguments),
|
|
60889
|
-
...toolCallReason(toolCall.arguments) === void 0 ? {} : { why: toolCallReason(toolCall.arguments) },
|
|
61245
|
+
const summary = toolCallSummary(toolCall, {
|
|
60890
61246
|
result: result.content,
|
|
60891
61247
|
...result.isError === true ? { isError: true } : {}
|
|
60892
|
-
};
|
|
61248
|
+
});
|
|
60893
61249
|
post({
|
|
60894
61250
|
type: "toolResult",
|
|
60895
61251
|
toolCall: summary,
|
|
60896
|
-
...
|
|
61252
|
+
...informedBy !== void 0 ? { expertInformed: true, informedBy } : {}
|
|
60897
61253
|
});
|
|
60898
61254
|
},
|
|
60899
61255
|
onCheckpoint: (checkpoint) => {
|
|
@@ -61042,6 +61398,7 @@ ${preview.text}` } : {}
|
|
|
61042
61398
|
cachedAuth = void 0;
|
|
61043
61399
|
post({ type: "profileSaved" });
|
|
61044
61400
|
await postProfiles();
|
|
61401
|
+
await postAgents();
|
|
61045
61402
|
} catch (error51) {
|
|
61046
61403
|
post({ type: "error", message: error51 instanceof Error ? error51.message : String(error51) });
|
|
61047
61404
|
}
|
|
@@ -61095,6 +61452,7 @@ ${preview.text}` } : {}
|
|
|
61095
61452
|
};
|
|
61096
61453
|
await configManager.save("user", { profiles: [...profiles, duplicate] });
|
|
61097
61454
|
await postProfiles();
|
|
61455
|
+
await postAgents();
|
|
61098
61456
|
} catch (error51) {
|
|
61099
61457
|
post({ type: "error", message: error51 instanceof Error ? error51.message : String(error51) });
|
|
61100
61458
|
}
|
|
@@ -61109,6 +61467,7 @@ ${preview.text}` } : {}
|
|
|
61109
61467
|
const activeProfileId = config2.activeProfileId === id ? remaining[0]?.id : config2.activeProfileId;
|
|
61110
61468
|
await configManager.save("user", { profiles: remaining, activeProfileId });
|
|
61111
61469
|
await postProfiles();
|
|
61470
|
+
await postAgents();
|
|
61112
61471
|
} catch (error51) {
|
|
61113
61472
|
post({ type: "error", message: error51 instanceof Error ? error51.message : String(error51) });
|
|
61114
61473
|
}
|
|
@@ -61127,6 +61486,7 @@ ${preview.text}` } : {}
|
|
|
61127
61486
|
await configManager.save("user", { activeProfileId: id });
|
|
61128
61487
|
await postProjectSettings();
|
|
61129
61488
|
await postProfiles();
|
|
61489
|
+
await postAgents();
|
|
61130
61490
|
} catch (error51) {
|
|
61131
61491
|
post({ type: "error", message: error51 instanceof Error ? error51.message : String(error51) });
|
|
61132
61492
|
}
|
|
@@ -61178,26 +61538,16 @@ ${preview.text}` } : {}
|
|
|
61178
61538
|
// The whole thing, profiles included. Passing only half of what the constructor takes is
|
|
61179
61539
|
// the same mistake as having two constructors, and this failure path is where the last
|
|
61180
61540
|
// one hid: it runs rarely, so a field missing here is noticed much later than elsewhere.
|
|
61181
|
-
...expertMessageFrom(settings
|
|
61541
|
+
...expertMessageFrom(settings),
|
|
61182
61542
|
available: false,
|
|
61183
61543
|
path: settings?.path ?? expertCliPath ?? "claude",
|
|
61184
61544
|
reason: `Could not check whether the Claude CLI is available: ${reason}`
|
|
61185
61545
|
});
|
|
61186
61546
|
}
|
|
61187
61547
|
}
|
|
61188
|
-
function expertMessageFrom(settings
|
|
61548
|
+
function expertMessageFrom(settings) {
|
|
61189
61549
|
return {
|
|
61190
61550
|
type: "expert",
|
|
61191
|
-
/*
|
|
61192
|
-
* Sent from here and nowhere else. CLAUDE.md records what happened the last time two
|
|
61193
|
-
* `expert` messages were built separately: measured pricing reached the success path and
|
|
61194
|
-
* not the failure path, and the panel showed a dash for something that had been measured.
|
|
61195
|
-
*/
|
|
61196
|
-
...services.expertMode === "profile" ? {
|
|
61197
|
-
mode: "profile",
|
|
61198
|
-
profiles: (profiles ?? []).map((profile) => ({ id: profile.id, label: profile.label })),
|
|
61199
|
-
...settings?.profileId !== void 0 ? { profileId: settings.profileId } : {}
|
|
61200
|
-
} : {},
|
|
61201
61551
|
enabled: settings?.enabled === true,
|
|
61202
61552
|
available: false,
|
|
61203
61553
|
path: settings?.path ?? expertCliPath ?? "claude",
|
|
@@ -61214,24 +61564,81 @@ ${preview.text}` } : {}
|
|
|
61214
61564
|
...expertEvents !== void 0 ? { savings: summariseSavings(expertEvents, settings?.pricing) } : {}
|
|
61215
61565
|
};
|
|
61216
61566
|
}
|
|
61217
|
-
async function
|
|
61567
|
+
async function postAgents() {
|
|
61218
61568
|
const { config: config2 } = await configManager.load();
|
|
61219
|
-
|
|
61220
|
-
|
|
61221
|
-
|
|
61222
|
-
|
|
61223
|
-
|
|
61224
|
-
|
|
61225
|
-
|
|
61569
|
+
const cli = await detectCli(config2.expert?.path ?? "claude").catch(() => void 0);
|
|
61570
|
+
const teamContext = {
|
|
61571
|
+
config: config2.agents,
|
|
61572
|
+
profiles: (config2.profiles ?? []).map((profile) => ({
|
|
61573
|
+
id: profile.id,
|
|
61574
|
+
label: profile.label
|
|
61575
|
+
})),
|
|
61576
|
+
cliAvailable: cli?.available === true
|
|
61577
|
+
};
|
|
61578
|
+
const assigned = new Map(resolveTeam(teamContext).map((agent) => [agent.role, agent]));
|
|
61579
|
+
const roles = allRoles().map((info) => {
|
|
61580
|
+
const agent = assigned.get(info.role);
|
|
61581
|
+
const prompt = config2.agents?.roles?.[info.role]?.prompt;
|
|
61582
|
+
return {
|
|
61583
|
+
role: info.role,
|
|
61584
|
+
name: info.name,
|
|
61585
|
+
summary: info.summary,
|
|
61586
|
+
...agent !== void 0 ? { kind: agent.kind } : {},
|
|
61587
|
+
...agent?.profileId !== void 0 ? { profileId: agent.profileId } : {},
|
|
61588
|
+
label: agent?.label ?? "Nobody",
|
|
61589
|
+
available: agent?.available ?? false,
|
|
61590
|
+
...agent?.reason !== void 0 ? { reason: agent.reason } : {},
|
|
61591
|
+
prompt: prompt ?? defaultPromptFor(info.role),
|
|
61592
|
+
promptIsDefault: prompt === void 0
|
|
61593
|
+
};
|
|
61594
|
+
});
|
|
61595
|
+
const guidance = config2.agents?.teamGuidance;
|
|
61596
|
+
post({
|
|
61597
|
+
type: "agents",
|
|
61598
|
+
roles,
|
|
61599
|
+
profiles: teamContext.profiles,
|
|
61600
|
+
cliAvailable: teamContext.cliAvailable,
|
|
61601
|
+
...cli?.available === false && cli.reason !== void 0 ? { cliReason: cli.reason } : {},
|
|
61602
|
+
budgetMatters: budgetMatters(teamContext),
|
|
61603
|
+
teamGuidance: guidance ?? DEFAULT_TEAM_GUIDANCE,
|
|
61604
|
+
defaultTeamGuidance: DEFAULT_TEAM_GUIDANCE,
|
|
61605
|
+
teamGuidanceIsDefault: guidance === void 0,
|
|
61606
|
+
colors: {
|
|
61607
|
+
/*
|
|
61608
|
+
* The expert's colour comes from the control that has always owned it.
|
|
61609
|
+
*
|
|
61610
|
+
* It predates roles and lives under `ui.expertColor`, and the Agents work briefly gave it
|
|
61611
|
+
* a second home under `agents.colors.expert` — two pickers for one thing, backed by two
|
|
61612
|
+
* settings, which is the drift this project pays for most often. An explicit per-role
|
|
61613
|
+
* value still wins, so nothing is taken away; it is simply no longer the *default*
|
|
61614
|
+
* source for a colour that already had one.
|
|
61615
|
+
*/
|
|
61616
|
+
expert: config2.ui?.expertColor ?? "#D97757",
|
|
61617
|
+
...config2.agents?.colors ?? {}
|
|
61618
|
+
}
|
|
61619
|
+
});
|
|
61620
|
+
}
|
|
61621
|
+
async function saveAgents(change) {
|
|
61622
|
+
try {
|
|
61623
|
+
const { config: config2 } = await configManager.load();
|
|
61624
|
+
await configManager.save("user", { agents: change(config2.agents ?? {}) });
|
|
61625
|
+
await loadSettings();
|
|
61626
|
+
await postAgents();
|
|
61627
|
+
} catch (error51) {
|
|
61628
|
+
post({ type: "error", message: error51 instanceof Error ? error51.message : String(error51) });
|
|
61226
61629
|
}
|
|
61630
|
+
}
|
|
61631
|
+
async function postExpertInner(redetect) {
|
|
61632
|
+
const { config: config2 } = await configManager.load();
|
|
61227
61633
|
await loadExpertEvents();
|
|
61228
61634
|
const configured = config2.expert?.path ?? "claude";
|
|
61229
61635
|
const detected = !redetect && expertCli !== void 0 && expertCliPath === configured ? expertCli : await detectClaudeCli(configured);
|
|
61230
61636
|
expertCli = detected;
|
|
61231
61637
|
expertCliPath = configured;
|
|
61638
|
+
void postAgents();
|
|
61232
61639
|
post({
|
|
61233
61640
|
// Everything from settings comes from one place, so the two paths cannot drift again.
|
|
61234
|
-
...expertMessageFrom(config2.expert
|
|
61641
|
+
...expertMessageFrom(config2.expert),
|
|
61235
61642
|
available: detected.available,
|
|
61236
61643
|
path: configured,
|
|
61237
61644
|
...detected.version !== void 0 ? { version: detected.version } : {},
|
|
@@ -63212,6 +63619,7 @@ ${preview.text}` } : {}
|
|
|
63212
63619
|
}));
|
|
63213
63620
|
await configManager.save("user", { ...imported, profiles: reconciled });
|
|
63214
63621
|
await postProfiles();
|
|
63622
|
+
await postAgents();
|
|
63215
63623
|
ui.showInfo(needKeys.length > 0 ? `Config imported. Re-enter the API key for: ${needKeys.join(", ")} (exports never include secrets).` : "Config imported.");
|
|
63216
63624
|
} catch (error51) {
|
|
63217
63625
|
post({ type: "error", message: error51 instanceof Error ? error51.message : String(error51) });
|
|
@@ -63233,35 +63641,64 @@ ${preview.text}` } : {}
|
|
|
63233
63641
|
post({ type: "error", message: error51 instanceof Error ? error51.message : String(error51) });
|
|
63234
63642
|
}
|
|
63235
63643
|
}
|
|
63236
|
-
function
|
|
63237
|
-
|
|
63238
|
-
|
|
63239
|
-
|
|
63240
|
-
|
|
63241
|
-
|
|
63242
|
-
|
|
63243
|
-
|
|
63244
|
-
|
|
63644
|
+
async function consultAgent(agent, request) {
|
|
63645
|
+
const prompt = buildAgentPrompt({
|
|
63646
|
+
prompt: agent.prompt,
|
|
63647
|
+
question: request.question,
|
|
63648
|
+
...request.files !== void 0 ? { files: request.files } : {},
|
|
63649
|
+
/*
|
|
63650
|
+
* What exists in this workspace.
|
|
63651
|
+
*
|
|
63652
|
+
* Without it a specialist advises as though the assistant were a bare shell — proposing by
|
|
63653
|
+
* hand what a configured tool already does, or inventing a procedure an existing skill
|
|
63654
|
+
* documents. See `agents/briefing.ts` for why names are worth the tokens and schemas are not.
|
|
63655
|
+
*/
|
|
63656
|
+
briefing: buildAgentBriefing({
|
|
63657
|
+
tools: agentBriefingTools?.() ?? [],
|
|
63658
|
+
skills
|
|
63659
|
+
})
|
|
63660
|
+
});
|
|
63661
|
+
if (agent.kind === "cli") {
|
|
63662
|
+
const cli = expertCli;
|
|
63663
|
+
if (cli === void 0 || !cli.available)
|
|
63664
|
+
throw new Error("The Claude CLI is not available.");
|
|
63665
|
+
const answer = await consultExpert(cli, {
|
|
63666
|
+
question: prompt,
|
|
63667
|
+
/*
|
|
63668
|
+
* The workspace, so Claude's own Read/Grep resolve against the project rather than
|
|
63669
|
+
* wherever this process was started. Falls back to the process directory when no folder
|
|
63670
|
+
* is open — the consultation is still worth having without one.
|
|
63671
|
+
*/
|
|
63672
|
+
cwd: workspaceRoot ?? process.cwd(),
|
|
63673
|
+
...request.signal !== void 0 ? { signal: request.signal } : {}
|
|
63674
|
+
});
|
|
63675
|
+
if (answer.isError)
|
|
63676
|
+
throw new Error(answer.text);
|
|
63677
|
+
return { advice: answer.text, label: agent.label };
|
|
63678
|
+
}
|
|
63679
|
+
const { config: config2 } = await configManager.load();
|
|
63680
|
+
const profile = config2.profiles?.find((candidate) => candidate.id === agent.profileId);
|
|
63245
63681
|
if (profile === void 0) {
|
|
63246
|
-
|
|
63247
|
-
|
|
63682
|
+
throw new Error(`No profile "${agent.profileId ?? ""}" exists any more.`);
|
|
63683
|
+
}
|
|
63684
|
+
const provider = createChatProvider(profile, httpClient, authStrategyFor(config2, profile), logger);
|
|
63685
|
+
const readOnly = toolsForConsultation(agentBriefingTools?.() ?? []);
|
|
63686
|
+
const context = consultationContext?.();
|
|
63687
|
+
const result = await runConsultation({
|
|
63688
|
+
provider,
|
|
63689
|
+
prompt,
|
|
63690
|
+
tools: readOnly,
|
|
63691
|
+
definitions: context === void 0 ? [] : toToolDefinitions(readOnly),
|
|
63692
|
+
// With no context there is nothing to read *with*, so it answers from the question alone
|
|
63693
|
+
// rather than being offered tools that would fail.
|
|
63694
|
+
context: context ?? {},
|
|
63695
|
+
...request.signal !== void 0 ? { signal: request.signal } : {},
|
|
63696
|
+
onStep: (name) => logger.info(`${agent.role} looked up ${name}`)
|
|
63697
|
+
});
|
|
63698
|
+
if (result.truncated) {
|
|
63699
|
+
logger.info(`${agent.role} reached its lookup limit and answered with what it had`);
|
|
63248
63700
|
}
|
|
63249
|
-
return {
|
|
63250
|
-
label: profile.label,
|
|
63251
|
-
consult: async (request) => {
|
|
63252
|
-
const provider = createChatProvider(profile, httpClient, authStrategyFor(config2, profile), logger);
|
|
63253
|
-
let text = "";
|
|
63254
|
-
for await (const chunk of provider.streamChat([{ role: "user", content: buildExpertPrompt(request) }], {
|
|
63255
|
-
// No tools offered: it is being asked for judgement, and offering tools invites it to
|
|
63256
|
-
// reach for one it has no way to run.
|
|
63257
|
-
...request.signal !== void 0 ? { signal: request.signal } : {}
|
|
63258
|
-
})) {
|
|
63259
|
-
if (chunk.type === "text")
|
|
63260
|
-
text += chunk.text;
|
|
63261
|
-
}
|
|
63262
|
-
return { advice: text, producedBy: profile.label };
|
|
63263
|
-
}
|
|
63264
|
-
};
|
|
63701
|
+
return { advice: result.advice, label: agent.label };
|
|
63265
63702
|
}
|
|
63266
63703
|
function codeGeneratorFor(config2) {
|
|
63267
63704
|
if (services.allowProgrammingProfile !== true)
|
|
@@ -64006,6 +64443,80 @@ ${preview.text}` } : {}
|
|
|
64006
64443
|
void handleSaveNetwork(message3.settings);
|
|
64007
64444
|
} else if (message3.type === "requestExpert") {
|
|
64008
64445
|
void postExpert();
|
|
64446
|
+
} else if (message3.type === "setPlan") {
|
|
64447
|
+
const plan = message3.plan.slice(0, PLAN_LIMIT).trim();
|
|
64448
|
+
activePlan = plan.length > 0 ? plan : void 0;
|
|
64449
|
+
void persistActiveTask();
|
|
64450
|
+
post({ type: "plan", plan: activePlan ?? "" });
|
|
64451
|
+
} else if (message3.type === "requestPlan") {
|
|
64452
|
+
post({ type: "plan", plan: activePlan ?? "" });
|
|
64453
|
+
} else if (message3.type === "requestAgents") {
|
|
64454
|
+
void postAgents();
|
|
64455
|
+
} else if (message3.type === "setAgentRole") {
|
|
64456
|
+
const assignment = message3.assignment;
|
|
64457
|
+
const role = message3.role;
|
|
64458
|
+
if (!isAgentRole(role)) {
|
|
64459
|
+
post({ type: "error", message: `There is no "${role}" role.` });
|
|
64460
|
+
return;
|
|
64461
|
+
}
|
|
64462
|
+
void saveAgents((current) => {
|
|
64463
|
+
const roles = { ...current.roles ?? {} };
|
|
64464
|
+
if (assignment === void 0)
|
|
64465
|
+
delete roles[role];
|
|
64466
|
+
else {
|
|
64467
|
+
roles[role] = {
|
|
64468
|
+
kind: assignment.kind,
|
|
64469
|
+
...assignment.profileId !== void 0 ? { profileId: assignment.profileId } : {},
|
|
64470
|
+
...roles[role]?.prompt !== void 0 ? { prompt: roles[role].prompt } : {}
|
|
64471
|
+
};
|
|
64472
|
+
}
|
|
64473
|
+
return { ...current, roles };
|
|
64474
|
+
});
|
|
64475
|
+
} else if (message3.type === "setAgentPrompt") {
|
|
64476
|
+
const role = message3.role;
|
|
64477
|
+
const prompt = message3.prompt;
|
|
64478
|
+
if (!isAgentRole(role)) {
|
|
64479
|
+
post({ type: "error", message: `There is no "${role}" role.` });
|
|
64480
|
+
return;
|
|
64481
|
+
}
|
|
64482
|
+
void saveAgents((current) => {
|
|
64483
|
+
const roles = { ...current.roles ?? {} };
|
|
64484
|
+
const existing = roles[role];
|
|
64485
|
+
if (prompt === void 0 || prompt === defaultPromptFor(role)) {
|
|
64486
|
+
if (existing !== void 0) {
|
|
64487
|
+
const rest = { ...existing };
|
|
64488
|
+
delete rest.prompt;
|
|
64489
|
+
roles[role] = rest;
|
|
64490
|
+
}
|
|
64491
|
+
} else {
|
|
64492
|
+
roles[role] = { ...existing ?? { kind: "profile" }, prompt };
|
|
64493
|
+
}
|
|
64494
|
+
return { ...current, roles };
|
|
64495
|
+
});
|
|
64496
|
+
} else if (message3.type === "setAgentBudget") {
|
|
64497
|
+
const matters = message3.matters;
|
|
64498
|
+
void saveAgents((current) => ({ ...current, budgetMatters: matters }));
|
|
64499
|
+
} else if (message3.type === "setTeamGuidance") {
|
|
64500
|
+
const guidance = message3.guidance;
|
|
64501
|
+
void saveAgents((current) => {
|
|
64502
|
+
if (guidance === void 0 || guidance.trim().length === 0 || guidance === DEFAULT_TEAM_GUIDANCE) {
|
|
64503
|
+
const rest = { ...current };
|
|
64504
|
+
delete rest.teamGuidance;
|
|
64505
|
+
return rest;
|
|
64506
|
+
}
|
|
64507
|
+
return { ...current, teamGuidance: guidance };
|
|
64508
|
+
});
|
|
64509
|
+
} else if (message3.type === "setAgentColor") {
|
|
64510
|
+
const role = message3.role;
|
|
64511
|
+
const color = message3.color;
|
|
64512
|
+
if (!isAgentRole(role)) {
|
|
64513
|
+
post({ type: "error", message: `There is no "${role}" role.` });
|
|
64514
|
+
return;
|
|
64515
|
+
}
|
|
64516
|
+
void saveAgents((current) => ({
|
|
64517
|
+
...current,
|
|
64518
|
+
colors: { ...current.colors ?? {}, [role]: color }
|
|
64519
|
+
}));
|
|
64009
64520
|
} else if (message3.type === "setExpert") {
|
|
64010
64521
|
void handleSetExpert(message3.enabled, message3.path, message3.model, {
|
|
64011
64522
|
...message3.maxSpendUsd !== void 0 ? { maxSpendUsd: message3.maxSpendUsd } : {},
|
|
@@ -64675,7 +65186,10 @@ function chartTotals(spec) {
|
|
|
64675
65186
|
}
|
|
64676
65187
|
|
|
64677
65188
|
// ../../packages/core/dist/history/transcript.js
|
|
64678
|
-
var CONTROL_TOOLS = /* @__PURE__ */ new Set([
|
|
65189
|
+
var CONTROL_TOOLS = /* @__PURE__ */ new Set([
|
|
65190
|
+
"attempt_completion",
|
|
65191
|
+
"ask_followup_question"
|
|
65192
|
+
]);
|
|
64679
65193
|
function formatToolArguments(raw) {
|
|
64680
65194
|
try {
|
|
64681
65195
|
const parsed = JSON.parse(raw.length > 0 ? raw : "{}");
|
|
@@ -64707,7 +65221,7 @@ function toTranscript(messages) {
|
|
|
64707
65221
|
resultsByCallId.set(message3.toolCallId, message3.content);
|
|
64708
65222
|
}
|
|
64709
65223
|
const entries = [];
|
|
64710
|
-
let
|
|
65224
|
+
let informedBy;
|
|
64711
65225
|
for (const message3 of messages) {
|
|
64712
65226
|
if (message3.role === "system" || message3.role === "tool")
|
|
64713
65227
|
continue;
|
|
@@ -64716,13 +65230,22 @@ function toTranscript(messages) {
|
|
|
64716
65230
|
continue;
|
|
64717
65231
|
}
|
|
64718
65232
|
if (message3.content.length > 0) {
|
|
64719
|
-
entries.push({
|
|
65233
|
+
entries.push({
|
|
65234
|
+
kind: "text",
|
|
65235
|
+
role: "assistant",
|
|
65236
|
+
content: message3.content,
|
|
65237
|
+
...informedBy !== void 0 ? { expertInformed: true, informedBy } : {}
|
|
65238
|
+
});
|
|
64720
65239
|
}
|
|
64721
65240
|
for (const toolCall of message3.toolCalls ?? []) {
|
|
64722
65241
|
const result = resultsByCallId.get(toolCall.id);
|
|
64723
65242
|
const asChart = chartFromToolCall(toolCall.name, toolCall.arguments);
|
|
64724
65243
|
if (asChart !== void 0) {
|
|
64725
|
-
entries.push(asChart.kind === "chart" ? {
|
|
65244
|
+
entries.push(asChart.kind === "chart" ? {
|
|
65245
|
+
kind: "chart",
|
|
65246
|
+
chart: asChart.chart,
|
|
65247
|
+
...informedBy !== void 0 ? { expertInformed: true, informedBy } : {}
|
|
65248
|
+
} : asChart);
|
|
64726
65249
|
continue;
|
|
64727
65250
|
}
|
|
64728
65251
|
if (CONTROL_TOOLS.has(toolCall.name)) {
|
|
@@ -64730,26 +65253,46 @@ function toTranscript(messages) {
|
|
|
64730
65253
|
entries.push({ kind: "text", role: "assistant", content: result });
|
|
64731
65254
|
continue;
|
|
64732
65255
|
}
|
|
64733
|
-
|
|
64734
|
-
|
|
65256
|
+
const consulting = consultationFromToolCall(toolCall.name, toolCall.arguments);
|
|
65257
|
+
if (consulting !== void 0)
|
|
65258
|
+
informedBy = consulting;
|
|
64735
65259
|
entries.push({
|
|
64736
65260
|
kind: "tool",
|
|
64737
|
-
...
|
|
64738
|
-
|
|
64739
|
-
|
|
64740
|
-
|
|
64741
|
-
|
|
64742
|
-
|
|
64743
|
-
|
|
64744
|
-
|
|
64745
|
-
// which is what actually happened.
|
|
64746
|
-
...result !== void 0 ? { result } : {}
|
|
64747
|
-
}
|
|
65261
|
+
...informedBy !== void 0 ? { expertInformed: true, informedBy } : {},
|
|
65262
|
+
/*
|
|
65263
|
+
* Built by the one builder, so a restored transcript and a live turn cannot differ about
|
|
65264
|
+
* what a call looked like. A call with no matching result means the task ended mid-flight
|
|
65265
|
+
* — a cancel, a crash, a window closed — and leaving `result` unset renders it as
|
|
65266
|
+
* unfinished, which is what actually happened.
|
|
65267
|
+
*/
|
|
65268
|
+
toolCall: toolCallSummary(toolCall, { result })
|
|
64748
65269
|
});
|
|
64749
65270
|
}
|
|
64750
65271
|
}
|
|
64751
65272
|
return entries;
|
|
64752
65273
|
}
|
|
65274
|
+
function toolCallSummary(call, outcome) {
|
|
65275
|
+
const why = toolCallReason(call.arguments);
|
|
65276
|
+
const consulting = consultationFromToolCall(call.name, call.arguments);
|
|
65277
|
+
return {
|
|
65278
|
+
id: call.id,
|
|
65279
|
+
name: call.name,
|
|
65280
|
+
arguments: formatToolArguments(call.arguments),
|
|
65281
|
+
...why !== void 0 ? { why } : {},
|
|
65282
|
+
...consulting !== void 0 ? { consultingRole: consulting } : {},
|
|
65283
|
+
...outcome?.result !== void 0 ? { result: outcome.result } : {},
|
|
65284
|
+
...outcome?.isError === true ? { isError: true } : {}
|
|
65285
|
+
};
|
|
65286
|
+
}
|
|
65287
|
+
function consultationFromToolCall(name, rawArguments) {
|
|
65288
|
+
if (name === "ask_expert")
|
|
65289
|
+
return "expert";
|
|
65290
|
+
if (name !== "ask_agent")
|
|
65291
|
+
return void 0;
|
|
65292
|
+
const decoded = decodeArguments(rawArguments);
|
|
65293
|
+
const role = typeof decoded === "object" && decoded !== null ? decoded.role : void 0;
|
|
65294
|
+
return typeof role === "string" && role.trim().length > 0 ? role.trim().toLowerCase() : "unknown";
|
|
65295
|
+
}
|
|
64753
65296
|
function chartFromToolCall(name, rawArguments) {
|
|
64754
65297
|
if (name !== "show_chart")
|
|
64755
65298
|
return void 0;
|
|
@@ -67063,16 +67606,6 @@ async function createSession(options) {
|
|
|
67063
67606
|
* The extension says nothing and keeps all of it — that is where the feature is used.
|
|
67064
67607
|
*/
|
|
67065
67608
|
offersOffice: false,
|
|
67066
|
-
/*
|
|
67067
|
-
* The expert is a provider profile here, not the Claude CLI.
|
|
67068
|
-
*
|
|
67069
|
-
* Asked for directly: any configured model should be able to be the expert, and cost is no
|
|
67070
|
-
* longer something to manage in the product. Both follow from where this runs — there is no
|
|
67071
|
-
* `claude` binary on a server, and the gateway answering the chat already has a stronger
|
|
67072
|
-
* model behind it. Everything about budgets, measured price and savings belongs to the CLI
|
|
67073
|
-
* expert, which is what the extension still has.
|
|
67074
|
-
*/
|
|
67075
|
-
expertMode: "profile",
|
|
67076
67609
|
transport: options.transport,
|
|
67077
67610
|
/*
|
|
67078
67611
|
* A shared profile's API key belongs to the administrator and lives beside the shared config;
|