@chosengeneration/light-code 0.46.0 → 0.56.1
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 +1479 -274
- package/dist/client/client.js +68 -68
- package/dist/server.js +1478 -273
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -39663,10 +39663,54 @@ var agentAssignmentSchema = external_exports.object({
|
|
|
39663
39663
|
* has looked at the tab without editing anything. Storing the default verbatim would pin
|
|
39664
39664
|
* every user to whatever it said the day they first opened it.
|
|
39665
39665
|
*/
|
|
39666
|
-
prompt: external_exports.string().optional()
|
|
39666
|
+
prompt: external_exports.string().optional(),
|
|
39667
|
+
/**
|
|
39668
|
+
* Whether this specialist may read and search the workspace, overriding the role's default.
|
|
39669
|
+
*
|
|
39670
|
+
* On the assignment rather than the role because it depends on *who* is answering: a small
|
|
39671
|
+
* local model given five lookups can spend them all and answer worse, where a strong one
|
|
39672
|
+
* uses them well. Absent means the role's own default.
|
|
39673
|
+
*/
|
|
39674
|
+
tools: external_exports.boolean().optional(),
|
|
39675
|
+
/**
|
|
39676
|
+
* Whether this specialist may change things, each change through the approval gate.
|
|
39677
|
+
*
|
|
39678
|
+
* Off by default everywhere. §12b's rule is that a consultant is read-only; this is the
|
|
39679
|
+
* deliberate exception, and it is per role because "the programmer may edit" and "the tester
|
|
39680
|
+
* may edit" are quite different decisions.
|
|
39681
|
+
*/
|
|
39682
|
+
write: external_exports.boolean().optional(),
|
|
39683
|
+
/**
|
|
39684
|
+
* Whether this role is in play at all.
|
|
39685
|
+
*
|
|
39686
|
+
* Distinct from unassigning it, which is why both exist: unassigning forgets *who* answered,
|
|
39687
|
+
* and somebody switching a specialist off for one job does not want to lose the model, the
|
|
39688
|
+
* prompt and the flags they set up. Absent means on, so nothing changes for a config written
|
|
39689
|
+
* before this.
|
|
39690
|
+
*/
|
|
39691
|
+
enabled: external_exports.boolean().optional()
|
|
39667
39692
|
}).strict();
|
|
39693
|
+
var customRoleSchema = external_exports.object({
|
|
39694
|
+
id: external_exports.string().min(1),
|
|
39695
|
+
name: external_exports.string().min(1),
|
|
39696
|
+
summary: external_exports.string(),
|
|
39697
|
+
prompt: external_exports.string()
|
|
39698
|
+
});
|
|
39668
39699
|
var agentsConfigSchema = external_exports.object({
|
|
39669
39700
|
roles: external_exports.record(external_exports.string(), agentAssignmentSchema),
|
|
39701
|
+
/**
|
|
39702
|
+
* Roles the user invented, beyond the five built in.
|
|
39703
|
+
*
|
|
39704
|
+
* A role *is* its prompt, and the ones people ask for next are nearly always a reviewer with
|
|
39705
|
+
* a different one — security, performance, accessibility. Defining them here answers that
|
|
39706
|
+
* whole family without a code change each time, and without growing the fixed roster the
|
|
39707
|
+
* expert has to allocate from.
|
|
39708
|
+
*
|
|
39709
|
+
* Covered by the same user-scope rule as the rest of this block, and it is the sharpest part
|
|
39710
|
+
* of it: this is prose injected into a model that is then asked to advise on this
|
|
39711
|
+
* repository, so a workspace able to write it could define a reviewer that approves anything.
|
|
39712
|
+
*/
|
|
39713
|
+
definitions: external_exports.array(customRoleSchema),
|
|
39670
39714
|
/** Whether what a consultation costs is worth managing. See `agents/team.ts`. */
|
|
39671
39715
|
budgetMatters: external_exports.boolean(),
|
|
39672
39716
|
/** The Agent team mode instruction, when edited. The roster is always generated. */
|
|
@@ -43228,18 +43272,401 @@ var Conversation = class {
|
|
|
43228
43272
|
}
|
|
43229
43273
|
};
|
|
43230
43274
|
|
|
43275
|
+
// ../../packages/core/dist/agents/roles.js
|
|
43276
|
+
var AGENT_ROLES = ["expert", "programmer", "reviewer", "tester", "librarian"];
|
|
43277
|
+
var CUSTOM_ROLE_LIMIT = 5;
|
|
43278
|
+
var ROLE_ID = /^[a-z][a-z0-9-]{1,23}$/;
|
|
43279
|
+
function isValidRoleId(id) {
|
|
43280
|
+
return ROLE_ID.test(id) && !AGENT_ROLES.includes(id);
|
|
43281
|
+
}
|
|
43282
|
+
function isAgentRole(value, custom2 = []) {
|
|
43283
|
+
return AGENT_ROLES.includes(value) || custom2.some((role) => role.id === value);
|
|
43284
|
+
}
|
|
43285
|
+
function knownRoles(custom2 = []) {
|
|
43286
|
+
return [...AGENT_ROLES, ...custom2.map((role) => role.id)];
|
|
43287
|
+
}
|
|
43288
|
+
var SHARED_TAIL = [
|
|
43289
|
+
"Your reply is advice. The assistant will check it against the real code before acting, and it",
|
|
43290
|
+
"is responsible for the result. Be concrete, say what you are unsure about, and say plainly when",
|
|
43291
|
+
"something must be verified rather than assumed.",
|
|
43292
|
+
"",
|
|
43293
|
+
"Answer in prose and short lists. No preamble about being happy to help."
|
|
43294
|
+
];
|
|
43295
|
+
var MAY_WRITE = [
|
|
43296
|
+
"",
|
|
43297
|
+
"You can also change this workspace: edit files, and record a skill. Every such change is shown",
|
|
43298
|
+
"to the user and approved by them before it happens, so make each one small enough to read and",
|
|
43299
|
+
"say what it is for. Prefer telling the assistant what to change where the change is large or",
|
|
43300
|
+
"spans files \u2014 it has the whole picture and you have only what you asked for."
|
|
43301
|
+
].join("\n");
|
|
43302
|
+
var SHARED_WITH_TOOLS = [
|
|
43303
|
+
"You can read this workspace: open files, list them, and search. Use that rather than guessing,",
|
|
43304
|
+
"and rather than asking the assistant for something you can fetch yourself. You have a small",
|
|
43305
|
+
"budget of lookups, so go for what actually settles the question.",
|
|
43306
|
+
"",
|
|
43307
|
+
"You cannot edit anything, run anything, or reach the network. If something needs changing, say",
|
|
43308
|
+
"what and why \u2014 the assistant makes the change and is responsible for it.",
|
|
43309
|
+
"",
|
|
43310
|
+
...SHARED_TAIL
|
|
43311
|
+
].join("\n");
|
|
43312
|
+
var SHARED_BLIND = [
|
|
43313
|
+
"You have no tools and cannot see the workspace. Everything you have is in the question. If",
|
|
43314
|
+
"something essential is missing, say exactly what you need and why, then give the best answer you",
|
|
43315
|
+
"can without it \u2014 never refuse to answer.",
|
|
43316
|
+
"",
|
|
43317
|
+
...SHARED_TAIL
|
|
43318
|
+
].join("\n");
|
|
43319
|
+
function specialistPreamble(usesTools, canWrite = false) {
|
|
43320
|
+
const base = usesTools ? SHARED_WITH_TOOLS : SHARED_BLIND;
|
|
43321
|
+
return canWrite ? `${base}${MAY_WRITE}` : base;
|
|
43322
|
+
}
|
|
43323
|
+
var DEFINITIONS = {
|
|
43324
|
+
expert: {
|
|
43325
|
+
name: "Expert",
|
|
43326
|
+
summary: "Hard problems, architecture, and deciding what to do",
|
|
43327
|
+
/* Planning a change means knowing what is already there, and it spans files the asker
|
|
43328
|
+
* cannot paste all of. */
|
|
43329
|
+
usesTools: true,
|
|
43330
|
+
canWrite: false,
|
|
43331
|
+
prompt: [
|
|
43332
|
+
"You are a senior engineer being consulted by another AI assistant that is doing the work.",
|
|
43333
|
+
"",
|
|
43334
|
+
"It has hit something hard: a change across several files to plan, a bug it has already",
|
|
43335
|
+
"failed to fix, or a design choice with no obvious answer. Give it your judgement.",
|
|
43336
|
+
"",
|
|
43337
|
+
"Decide *what* should happen and why. Leave the typing to the assistant \u2014 it is the one",
|
|
43338
|
+
"making the change and answering for it. Where there is a real trade-off, name both sides",
|
|
43339
|
+
"and then choose."
|
|
43340
|
+
].join("\n")
|
|
43341
|
+
},
|
|
43342
|
+
programmer: {
|
|
43343
|
+
name: "Programmer",
|
|
43344
|
+
summary: "Writes the code once the plan is settled",
|
|
43345
|
+
/* It is handed a spec and the surrounding code and asked to write. Looking around buys
|
|
43346
|
+
* a slower answer that is no better. */
|
|
43347
|
+
usesTools: false,
|
|
43348
|
+
canWrite: false,
|
|
43349
|
+
prompt: [
|
|
43350
|
+
"You are an experienced programmer writing code for another AI assistant to apply.",
|
|
43351
|
+
"",
|
|
43352
|
+
"You are given a requirement and the surrounding code. Produce the change, matching the",
|
|
43353
|
+
"conventions of what you were shown rather than your own preferences \u2014 the naming, the error",
|
|
43354
|
+
"handling, the comment density, the way the existing code does this sort of thing.",
|
|
43355
|
+
"",
|
|
43356
|
+
"Return the code and a short note on anything non-obvious in it. Do not narrate what you are",
|
|
43357
|
+
"about to do, and do not rewrite things you were not asked to change.",
|
|
43358
|
+
"",
|
|
43359
|
+
/*
|
|
43360
|
+
* The programmer is the role that gets its own work handed back, so it is the one that has
|
|
43361
|
+
* to be told what to do with a review — including that it may disagree. Requested in those
|
|
43362
|
+
* terms: it is classified as the programmer, so fixing it is its job, and it should be able
|
|
43363
|
+
* to challenge a reviewer rather than obey one.
|
|
43364
|
+
*/
|
|
43365
|
+
"You may be given a review of code you wrote. Fix what is genuinely wrong and return the",
|
|
43366
|
+
"corrected code the same way. **Where the review is wrong, say so and say why** \u2014 a finding",
|
|
43367
|
+
"can be about a path that cannot happen, a convention this codebase does not follow, or a",
|
|
43368
|
+
"misreading of a fragment. Do not rewrite working code to satisfy an objection you think is",
|
|
43369
|
+
"mistaken; the assistant has the real file and will settle it. Changing something you believe",
|
|
43370
|
+
"is right, because you were told to, is the worse failure: it looks like agreement."
|
|
43371
|
+
].join("\n")
|
|
43372
|
+
},
|
|
43373
|
+
reviewer: {
|
|
43374
|
+
name: "Reviewer",
|
|
43375
|
+
summary: "Reads a change and says what is wrong with it",
|
|
43376
|
+
/* Most of what a review turns on is *around* the diff — the callers, the neighbouring
|
|
43377
|
+
* function, whether this convention is really the convention. */
|
|
43378
|
+
usesTools: true,
|
|
43379
|
+
canWrite: false,
|
|
43380
|
+
prompt: [
|
|
43381
|
+
"You are reviewing a change written by another AI assistant.",
|
|
43382
|
+
"",
|
|
43383
|
+
"Your job is to find what is wrong with it. Say so plainly when something is fine, but do",
|
|
43384
|
+
"not pad the review with praise \u2014 an approving review that missed a bug is worse than no",
|
|
43385
|
+
"review, because it was believed.",
|
|
43386
|
+
"",
|
|
43387
|
+
"Look for, in this order: does it do what was asked; does it break something that used to",
|
|
43388
|
+
"work; what happens at the edges \u2014 empty, missing, concurrent, already-exists, fails halfway;",
|
|
43389
|
+
"and does it match the conventions of the code around it.",
|
|
43390
|
+
"",
|
|
43391
|
+
"For each finding say what breaks and under what input. A concern you cannot make concrete is",
|
|
43392
|
+
"worth one sentence, flagged as a hunch, not a paragraph.",
|
|
43393
|
+
"",
|
|
43394
|
+
// Findings go back to whoever wrote the code, which may disagree. Concrete ones can be
|
|
43395
|
+
// settled against the file; vague ones turn into an argument nobody can end.
|
|
43396
|
+
"Your findings may be put to the person who wrote the code, who can disagree with them. That",
|
|
43397
|
+
"is why each one needs an input and an outcome: a finding stated concretely can be checked",
|
|
43398
|
+
"against the real file and settled, and one stated as a preference cannot."
|
|
43399
|
+
].join("\n")
|
|
43400
|
+
},
|
|
43401
|
+
tester: {
|
|
43402
|
+
name: "Tester",
|
|
43403
|
+
summary: "Designs cases and finds what breaks it",
|
|
43404
|
+
/* The change is in front of it and the cases come from reasoning about it, not from
|
|
43405
|
+
* reading more of the codebase. */
|
|
43406
|
+
usesTools: false,
|
|
43407
|
+
canWrite: false,
|
|
43408
|
+
prompt: [
|
|
43409
|
+
"You design tests for code written by another AI assistant.",
|
|
43410
|
+
"",
|
|
43411
|
+
"Given a change, say what should be tested and why each case earns its place. Prefer the",
|
|
43412
|
+
"cases that would actually fail: boundaries, empty and missing values, the error path, the",
|
|
43413
|
+
"second call, the concurrent one, the one that fails halfway and has to be recovered from.",
|
|
43414
|
+
"",
|
|
43415
|
+
"A test that cannot fail is worth nothing \u2014 for each case you propose, say what bug it would",
|
|
43416
|
+
"catch. If the change is untestable as written, say what would have to change to make it",
|
|
43417
|
+
"testable rather than proposing a test that only asserts the code was executed."
|
|
43418
|
+
].join("\n")
|
|
43419
|
+
},
|
|
43420
|
+
librarian: {
|
|
43421
|
+
name: "Librarian",
|
|
43422
|
+
summary: "Skills, internal documentation and house conventions",
|
|
43423
|
+
/* Its whole job is what has been written down here, so being unable to go and read it
|
|
43424
|
+
* left it answering from whatever happened to be pasted in. This is the role the flag
|
|
43425
|
+
* exists for. */
|
|
43426
|
+
usesTools: true,
|
|
43427
|
+
canWrite: false,
|
|
43428
|
+
prompt: [
|
|
43429
|
+
"You answer questions about how things are done here: internal libraries, house conventions,",
|
|
43430
|
+
"the shape of existing code, and what has already been written down.",
|
|
43431
|
+
"",
|
|
43432
|
+
"You are given whatever documentation, skills and code the assistant could find. Answer from",
|
|
43433
|
+
"that, and be explicit about the difference between what the material actually says and what",
|
|
43434
|
+
"you are inferring \u2014 a convention you guessed at, stated confidently, becomes the convention.",
|
|
43435
|
+
"",
|
|
43436
|
+
"If the material does not answer the question, say so and say what would. Do not fill the gap",
|
|
43437
|
+
"with how it is usually done elsewhere unless you label it as exactly that.",
|
|
43438
|
+
"",
|
|
43439
|
+
/*
|
|
43440
|
+
* The one specialist that may write, and only this one thing.
|
|
43441
|
+
*
|
|
43442
|
+
* The objection was never that the librarian should not record what it knows — it is the
|
|
43443
|
+
* role that can see the gap. It was that a consultation asks nobody, so a skill written
|
|
43444
|
+
* there would be prose injected into every later prompt that no human had read (§13's
|
|
43445
|
+
* persistent prompt-injection vector). That was answered by making this path *ask*:
|
|
43446
|
+
* `runConsultation` routes anything in ALWAYS_ASK_TOOLS through the same approval gate the
|
|
43447
|
+
* agent loop uses, so the user sees the source exactly as they would for any other write.
|
|
43448
|
+
*
|
|
43449
|
+
* Everything else stays read-only. `consultBoundary.test.ts` holds that line, and pins the
|
|
43450
|
+
* rule that any name allowed past the group filter must be one the gate will stop on.
|
|
43451
|
+
*/
|
|
43452
|
+
"When the answer is something worth writing down \u2014 a convention you had to piece together,",
|
|
43453
|
+
"a gotcha that will catch the next person, a procedure that is currently only in somebody's",
|
|
43454
|
+
"head \u2014 say so and **write it with `write_skill`**. The user is shown the text and",
|
|
43455
|
+
"approves it before anything is recorded, so write it as it should stand rather than",
|
|
43456
|
+
"describing what it would say. If they decline, say what you would have written and why.",
|
|
43457
|
+
"",
|
|
43458
|
+
"Say plainly when something already written down is **wrong or out of date**. A stale skill",
|
|
43459
|
+
"is worse than a missing one, because it is believed."
|
|
43460
|
+
].join("\n")
|
|
43461
|
+
}
|
|
43462
|
+
};
|
|
43463
|
+
function roleInfo(role, custom2 = []) {
|
|
43464
|
+
const builtIn = DEFINITIONS[role];
|
|
43465
|
+
if (builtIn !== void 0)
|
|
43466
|
+
return { role, ...builtIn };
|
|
43467
|
+
const defined = custom2.find((candidate) => candidate.id === role);
|
|
43468
|
+
if (defined !== void 0) {
|
|
43469
|
+
return {
|
|
43470
|
+
role,
|
|
43471
|
+
name: defined.name,
|
|
43472
|
+
summary: defined.summary,
|
|
43473
|
+
prompt: defined.prompt.trim(),
|
|
43474
|
+
/*
|
|
43475
|
+
* Custom roles get tools by default.
|
|
43476
|
+
*
|
|
43477
|
+
* They are overwhelmingly reviewers of some particular kind — security, performance,
|
|
43478
|
+
* accessibility — and those all turn on code the asker did not think to paste. The flag is
|
|
43479
|
+
* there to turn it off for the ones that are really "write this to spec".
|
|
43480
|
+
*/
|
|
43481
|
+
usesTools: defined.usesTools !== false,
|
|
43482
|
+
// Off unless asked for: a role invented in a hurry should not be able to edit the
|
|
43483
|
+
// repository because nobody thought about the box.
|
|
43484
|
+
canWrite: defined.canWrite === true
|
|
43485
|
+
};
|
|
43486
|
+
}
|
|
43487
|
+
return {
|
|
43488
|
+
role,
|
|
43489
|
+
name: role,
|
|
43490
|
+
summary: "This role is no longer defined.",
|
|
43491
|
+
prompt: "",
|
|
43492
|
+
usesTools: false,
|
|
43493
|
+
canWrite: false
|
|
43494
|
+
};
|
|
43495
|
+
}
|
|
43496
|
+
function allRoles(custom2 = []) {
|
|
43497
|
+
return knownRoles(custom2).map((role) => roleInfo(role, custom2));
|
|
43498
|
+
}
|
|
43499
|
+
function defaultPromptFor(role, custom2 = []) {
|
|
43500
|
+
return roleInfo(role, custom2).prompt;
|
|
43501
|
+
}
|
|
43502
|
+
function buildAgentPrompt(options) {
|
|
43503
|
+
const lines = [
|
|
43504
|
+
options.prompt.trim(),
|
|
43505
|
+
"",
|
|
43506
|
+
specialistPreamble(options.usesTools, options.canWrite === true)
|
|
43507
|
+
];
|
|
43508
|
+
if (options.briefing !== void 0 && options.briefing.trim().length > 0) {
|
|
43509
|
+
lines.push("", options.briefing);
|
|
43510
|
+
}
|
|
43511
|
+
lines.push("", "---", "", options.question);
|
|
43512
|
+
if (options.files !== void 0 && options.files.length > 0) {
|
|
43513
|
+
lines.push("", options.usesTools ? "The assistant named these files as relevant. Start there \u2014 you can open them yourself:" : "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}`));
|
|
43514
|
+
}
|
|
43515
|
+
return lines.join("\n");
|
|
43516
|
+
}
|
|
43517
|
+
|
|
43518
|
+
// ../../packages/core/dist/agent/checkpoints.js
|
|
43519
|
+
var MAX_CHECKPOINTS = 50;
|
|
43520
|
+
var LIST_ITEM = /^(\s*)(?:([-*•])|(\d+)[.)])\s+(.+)$/;
|
|
43521
|
+
function idFor(text) {
|
|
43522
|
+
let hash2 = 2166136261;
|
|
43523
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
43524
|
+
hash2 ^= text.charCodeAt(index);
|
|
43525
|
+
hash2 = Math.imul(hash2, 16777619) >>> 0;
|
|
43526
|
+
}
|
|
43527
|
+
return hash2.toString(36);
|
|
43528
|
+
}
|
|
43529
|
+
function normalise(text) {
|
|
43530
|
+
return text.trim().toLowerCase().replace(/\s+/g, " ").replace(/[.;,:]+$/, "");
|
|
43531
|
+
}
|
|
43532
|
+
function parseCheckpoints(plan) {
|
|
43533
|
+
const lines = (plan ?? "").split(/\r?\n/);
|
|
43534
|
+
const items = [];
|
|
43535
|
+
lines.forEach((line, index) => {
|
|
43536
|
+
const match = LIST_ITEM.exec(line);
|
|
43537
|
+
if (match === null)
|
|
43538
|
+
return;
|
|
43539
|
+
const text = match[4]?.trim() ?? "";
|
|
43540
|
+
if (text.length === 0)
|
|
43541
|
+
return;
|
|
43542
|
+
items.push({
|
|
43543
|
+
indent: (match[1] ?? "").replace(/\t/g, " ").length,
|
|
43544
|
+
ordered: match[3] !== void 0,
|
|
43545
|
+
text,
|
|
43546
|
+
line: index
|
|
43547
|
+
});
|
|
43548
|
+
});
|
|
43549
|
+
const ordered = items.filter((item) => item.ordered);
|
|
43550
|
+
const candidates = ordered.length > 0 ? ordered : items;
|
|
43551
|
+
const shallowest = candidates.reduce((least, item) => Math.min(least, item.indent), Number.POSITIVE_INFINITY);
|
|
43552
|
+
const steps = candidates.filter((item) => item.indent === shallowest);
|
|
43553
|
+
const texts = steps.length > 0 ? steps : (
|
|
43554
|
+
// No list at all: plenty of people write a plan as bare lines, and a progress view that
|
|
43555
|
+
// only worked for bullet-point authors would read as broken.
|
|
43556
|
+
lines.map((line, index) => ({ indent: 0, ordered: false, text: line.trim(), line: index })).filter((item) => item.text.length > 0)
|
|
43557
|
+
);
|
|
43558
|
+
const chosen = texts.slice(0, MAX_CHECKPOINTS);
|
|
43559
|
+
const seen = /* @__PURE__ */ new Map();
|
|
43560
|
+
return chosen.map((item, position) => {
|
|
43561
|
+
const key = normalise(item.text);
|
|
43562
|
+
const occurrence = (seen.get(key) ?? 0) + 1;
|
|
43563
|
+
seen.set(key, occurrence);
|
|
43564
|
+
const until = chosen[position + 1]?.line ?? lines.length;
|
|
43565
|
+
return {
|
|
43566
|
+
id: occurrence === 1 ? idFor(key) : `${idFor(key)}-${String(occurrence)}`,
|
|
43567
|
+
index: position + 1,
|
|
43568
|
+
text: item.text,
|
|
43569
|
+
/*
|
|
43570
|
+
* Who the plan says should be involved, read from the step *and everything under it* —
|
|
43571
|
+
* which is where the allocation actually lives, since a specialist is usually named on a
|
|
43572
|
+
* continuation line ("Owner: reviewer") or inside a sub-point rather than in the heading.
|
|
43573
|
+
*/
|
|
43574
|
+
plannedRoles: rolesMentionedIn(lines.slice(item.line, until).join(" "))
|
|
43575
|
+
};
|
|
43576
|
+
});
|
|
43577
|
+
}
|
|
43578
|
+
function rolesMentionedIn(text) {
|
|
43579
|
+
const haystack = text.toLowerCase();
|
|
43580
|
+
return AGENT_ROLES.filter((role) => new RegExp(`\\b${role}\\b`).test(haystack));
|
|
43581
|
+
}
|
|
43582
|
+
function checkpointViews(plan, progress) {
|
|
43583
|
+
return parseCheckpoints(plan).map((checkpoint) => {
|
|
43584
|
+
const recorded = progress?.[checkpoint.id];
|
|
43585
|
+
return {
|
|
43586
|
+
...checkpoint,
|
|
43587
|
+
status: recorded?.status ?? "todo",
|
|
43588
|
+
roles: recorded?.roles ?? []
|
|
43589
|
+
};
|
|
43590
|
+
});
|
|
43591
|
+
}
|
|
43592
|
+
function pruneProgress(plan, progress) {
|
|
43593
|
+
if (progress === void 0)
|
|
43594
|
+
return {};
|
|
43595
|
+
const live = new Set(parseCheckpoints(plan).map((checkpoint) => checkpoint.id));
|
|
43596
|
+
const kept = {};
|
|
43597
|
+
for (const [id, entry] of Object.entries(progress))
|
|
43598
|
+
if (live.has(id))
|
|
43599
|
+
kept[id] = entry;
|
|
43600
|
+
return kept;
|
|
43601
|
+
}
|
|
43602
|
+
function markCheckpoint(plan, progress, index, status) {
|
|
43603
|
+
const checkpoint = parseCheckpoints(plan).find((candidate) => candidate.index === index);
|
|
43604
|
+
if (checkpoint === void 0)
|
|
43605
|
+
return void 0;
|
|
43606
|
+
const existing = progress[checkpoint.id];
|
|
43607
|
+
return {
|
|
43608
|
+
...progress,
|
|
43609
|
+
[checkpoint.id]: {
|
|
43610
|
+
status,
|
|
43611
|
+
// Kept across a start→done transition: the specialists consulted while the step was being
|
|
43612
|
+
// worked are exactly the ones that contributed to finishing it.
|
|
43613
|
+
roles: existing?.roles ?? [],
|
|
43614
|
+
at: Date.now()
|
|
43615
|
+
}
|
|
43616
|
+
};
|
|
43617
|
+
}
|
|
43618
|
+
function attributeConsultation(progress, role) {
|
|
43619
|
+
const entry = Object.entries(progress).find(([, value2]) => value2.status === "active");
|
|
43620
|
+
if (entry === void 0)
|
|
43621
|
+
return progress;
|
|
43622
|
+
const [id, value] = entry;
|
|
43623
|
+
if (value.roles.includes(role))
|
|
43624
|
+
return progress;
|
|
43625
|
+
return { ...progress, [id]: { ...value, roles: [...value.roles, role] } };
|
|
43626
|
+
}
|
|
43627
|
+
function progressSummary(views) {
|
|
43628
|
+
const done = views.filter((view) => view.status === "done").length;
|
|
43629
|
+
return `${String(done)}/${String(views.length)}`;
|
|
43630
|
+
}
|
|
43631
|
+
|
|
43231
43632
|
// ../../packages/core/dist/agent/plan.js
|
|
43232
43633
|
var PLAN_LIMIT = 4e3;
|
|
43233
43634
|
function buildPlanGuidance(plan) {
|
|
43234
43635
|
const trimmed = plan?.trim() ?? "";
|
|
43235
43636
|
if (trimmed.length === 0)
|
|
43236
43637
|
return "";
|
|
43638
|
+
const checkpoints = parseCheckpoints(trimmed);
|
|
43639
|
+
const numbered = checkpoints.length > 0 ? [
|
|
43640
|
+
"",
|
|
43641
|
+
"Its steps are numbered as follows. These numbers are what `plan_progress` takes, and",
|
|
43642
|
+
"they are what the user sees:",
|
|
43643
|
+
"",
|
|
43644
|
+
...checkpoints.map((checkpoint) => `${String(checkpoint.index)}. ${checkpoint.text}`)
|
|
43645
|
+
] : [];
|
|
43237
43646
|
return [
|
|
43238
43647
|
"# The plan for this conversation",
|
|
43239
43648
|
"",
|
|
43240
43649
|
"The user set this. It is what you are here to do:",
|
|
43241
43650
|
"",
|
|
43242
43651
|
trimmed,
|
|
43652
|
+
...numbered,
|
|
43653
|
+
"",
|
|
43654
|
+
"## Reporting where you are",
|
|
43655
|
+
"",
|
|
43656
|
+
"- **Call `plan_progress` with `active` when you start a step**, and with `done` when it is",
|
|
43657
|
+
" actually finished. The user watches this rather than reading the whole transcript, so a",
|
|
43658
|
+
" step marked done that is not done is worse than one never marked at all.",
|
|
43659
|
+
"- Work one step at a time. Marking three done at the end tells the user nothing while it",
|
|
43660
|
+
" matters, which is the only time it is useful.",
|
|
43661
|
+
"",
|
|
43662
|
+
"## Changing the plan",
|
|
43663
|
+
"",
|
|
43664
|
+
"- **You may propose a different plan with `update_plan`, and the user must approve it.**",
|
|
43665
|
+
" They are shown a diff of the plan they have against the one you are proposing. This is",
|
|
43666
|
+
" the only way the plan changes on your side \u2014 never act on a plan the user has not agreed.",
|
|
43667
|
+
"- Use it when you have worked out a better plan, including one a specialist drafted for you.",
|
|
43668
|
+
" Put the whole plan in it: it replaces what is there rather than adding to it.",
|
|
43669
|
+
"- If they decline, the existing plan still stands and you carry on with it.",
|
|
43243
43670
|
"",
|
|
43244
43671
|
"## Working to it",
|
|
43245
43672
|
"",
|
|
@@ -43306,6 +43733,7 @@ function buildSystemPrompt(workspaceRoot, options = {}) {
|
|
|
43306
43733
|
} else if (options.pythonToolsAvailable === true) {
|
|
43307
43734
|
lines.push("", "Python tools:", "- `create_python_tool` makes a real, registered, callable tool. Use it whenever the user", ' asks for a "tool", even if writing a script would be easier.', "- Writing a .py file with `write_to_file` does NOT create a tool. It is just a file, and", " nothing can call it. Never describe that as having created a tool.", "- `update_python_tool` edits one, `delete_python_tool` removes one.");
|
|
43308
43735
|
}
|
|
43736
|
+
lines.push("", "Specialist roles:", "- The team of specialists is configurable, and you can change it. `read_role_prompt` shows", " what a role is told it is (no argument lists them all); `update_role` changes that, or a", " custom role's name, summary and workspace access.", "- `create_role` invents one \u2014 a security reviewer, say \u2014 and `delete_role` removes a custom", " one. The user approves each of these, seeing the whole role or a diff of it.", '- So "make the reviewer stricter" or "add a role that reviews SQL" is something to do, not', " something to explain how to do by hand.");
|
|
43309
43737
|
if (options.skills !== void 0 || options.skillsSearchable === true) {
|
|
43310
43738
|
lines.push("", "Skills, before anything else:", "- Check the skills for this workspace before you plan or answer. They record how *this*", " project works, and they exist because someone was tired of explaining it.", "- A skill that applies overrides your general knowledge. Do not restate a convention it", " contradicts.", ...options.teamSkillsAvailable === true ? [
|
|
43311
43739
|
"- `search_team_skills` searches what OTHER people have taught their assistants. Use it",
|
|
@@ -43699,130 +44127,6 @@ ${withBudget}` : withBudget;
|
|
|
43699
44127
|
};
|
|
43700
44128
|
}
|
|
43701
44129
|
|
|
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
44130
|
// ../../packages/core/dist/tools/askAgent.js
|
|
43827
44131
|
var paramsSchema3 = external_exports.object({
|
|
43828
44132
|
role: external_exports.string().describe(`Which specialist to ask: ${AGENT_ROLES.join(", ")}. Only the ones assigned in Settings \u2192 Agents can answer.`),
|
|
@@ -43892,7 +44196,7 @@ Files named as relevant: ${params.files.join(", ")}` : "")
|
|
|
43892
44196
|
|
|
43893
44197
|
---
|
|
43894
44198
|
|
|
43895
|
-
|
|
44199
|
+
${trailerFor(agent, team)}`
|
|
43896
44200
|
};
|
|
43897
44201
|
}
|
|
43898
44202
|
};
|
|
@@ -43908,6 +44212,22 @@ function describeTeam(team) {
|
|
|
43908
44212
|
const usable = team.filter((agent) => agent.available).map((agent) => agent.role);
|
|
43909
44213
|
return usable.length === 0 ? "None are assigned on this machine." : `Assigned here: ${usable.join(", ")}.`;
|
|
43910
44214
|
}
|
|
44215
|
+
function trailerFor(agent, team) {
|
|
44216
|
+
const lines = [
|
|
44217
|
+
`That is the ${agent.role}'s advice, from ${agent.label}. ` + (agent.usesTools ? "It could read this workspace but cannot change anything in it." : "It has not seen your workspace \u2014 it answered from what you pasted.") + " Check it against the actual code before acting on it, and say so if it turns out to be wrong."
|
|
44218
|
+
];
|
|
44219
|
+
const programmer = team.find((candidate) => candidate.role === "programmer" && candidate.available);
|
|
44220
|
+
if (agent.role === "reviewer" && programmer !== void 0) {
|
|
44221
|
+
lines.push("", "If the programmer wrote this code, take the findings back to it rather than fixing them yourself: paste the code as it stands, the findings in full, and anything you have already checked. It may disagree, and a disagreement is an answer \u2014 you have the real file and neither of them does, so you settle it and say which way you went. Re-review only if the fix was substantial enough that this review no longer describes the code.");
|
|
44222
|
+
}
|
|
44223
|
+
if (agent.role === "librarian") {
|
|
44224
|
+
lines.push("", "It can record a skill itself, and the user will have approved the text before it was written \u2014 so if it says it wrote one, that is done and not something to repeat. If it said something already written down is wrong or out of date, act on that: a stale skill is worse than a missing one, because it is believed.");
|
|
44225
|
+
}
|
|
44226
|
+
if (agent.role === "programmer") {
|
|
44227
|
+
lines.push("", "Check this against the real file before applying it \u2014 it was written from what you pasted, so it can miss a convention or a caller it was never shown.");
|
|
44228
|
+
}
|
|
44229
|
+
return lines.join("\n");
|
|
44230
|
+
}
|
|
43911
44231
|
|
|
43912
44232
|
// ../../packages/core/dist/agents/team.js
|
|
43913
44233
|
function defaultAssignment(role, context) {
|
|
@@ -43915,12 +44235,17 @@ function defaultAssignment(role, context) {
|
|
|
43915
44235
|
}
|
|
43916
44236
|
function resolveTeam(context) {
|
|
43917
44237
|
const resolved = [];
|
|
43918
|
-
|
|
44238
|
+
const custom2 = context.config?.definitions ?? [];
|
|
44239
|
+
for (const role of knownRoles(custom2)) {
|
|
43919
44240
|
const assignment = context.config?.roles?.[role] ?? defaultAssignment(role, context);
|
|
43920
44241
|
if (assignment === void 0)
|
|
43921
44242
|
continue;
|
|
43922
|
-
|
|
43923
|
-
|
|
44243
|
+
if (assignment.enabled === false)
|
|
44244
|
+
continue;
|
|
44245
|
+
const info = roleInfo(role, custom2);
|
|
44246
|
+
const prompt = assignment.prompt ?? defaultPromptFor(role, custom2);
|
|
44247
|
+
const usesTools = assignment.tools ?? info.usesTools;
|
|
44248
|
+
const canWrite = assignment.write ?? info.canWrite;
|
|
43924
44249
|
if (assignment.kind === "cli") {
|
|
43925
44250
|
resolved.push({
|
|
43926
44251
|
role,
|
|
@@ -43929,11 +44254,15 @@ function resolveTeam(context) {
|
|
|
43929
44254
|
kind: "cli",
|
|
43930
44255
|
label: "Claude",
|
|
43931
44256
|
prompt,
|
|
44257
|
+
usesTools,
|
|
44258
|
+
canWrite,
|
|
43932
44259
|
available: context.cliAvailable,
|
|
43933
44260
|
...context.cliAvailable ? {} : { reason: "The Claude CLI is not available on this machine." }
|
|
43934
44261
|
});
|
|
43935
44262
|
continue;
|
|
43936
44263
|
}
|
|
44264
|
+
if (assignment.profileId === void 0)
|
|
44265
|
+
continue;
|
|
43937
44266
|
const profile = context.profiles.find((candidate) => candidate.id === assignment.profileId);
|
|
43938
44267
|
resolved.push({
|
|
43939
44268
|
role,
|
|
@@ -43943,6 +44272,8 @@ function resolveTeam(context) {
|
|
|
43943
44272
|
...assignment.profileId !== void 0 ? { profileId: assignment.profileId } : {},
|
|
43944
44273
|
label: profile?.label ?? assignment.profileId ?? "unassigned",
|
|
43945
44274
|
prompt,
|
|
44275
|
+
usesTools,
|
|
44276
|
+
canWrite,
|
|
43946
44277
|
available: profile !== void 0,
|
|
43947
44278
|
/*
|
|
43948
44279
|
* A profile that has been deleted leaves the role unavailable and says so, rather than
|
|
@@ -43964,12 +44295,52 @@ function budgetMatters(context) {
|
|
|
43964
44295
|
// ../../packages/core/dist/agents/guidance.js
|
|
43965
44296
|
var BUDGET_ADVICE = [
|
|
43966
44297
|
"",
|
|
43967
|
-
"## Consultations cost money here",
|
|
44298
|
+
"## Consultations cost money here",
|
|
44299
|
+
"",
|
|
44300
|
+
"Each one is charged. Make the first count \u2014 gather what is needed and ask one full question",
|
|
44301
|
+
"rather than opening with something you could have settled yourself. If a per-task budget runs",
|
|
44302
|
+
"out the specialist stops being available, and you finish the work alone, so spend it on the",
|
|
44303
|
+
"parts where another reader genuinely changes what you do."
|
|
44304
|
+
].join("\n");
|
|
44305
|
+
var PLAN_FIRST = [
|
|
44306
|
+
"",
|
|
44307
|
+
"## Start by planning. This comes before everything else.",
|
|
44308
|
+
"",
|
|
44309
|
+
"**This conversation has no plan yet, so making one is your first job.** Before reading widely,",
|
|
44310
|
+
"before editing anything, before running anything:",
|
|
44311
|
+
"",
|
|
44312
|
+
"1. **Look at almost nothing first.** One `list_files` of the workspace root is usually the",
|
|
44313
|
+
" whole of it, plus any file the user actually named. That is enough to ask a good question.",
|
|
44314
|
+
" Do **not** survey the codebase, search the documentation index, hunt for skills, or read",
|
|
44315
|
+
" files to get a feel for the style \u2014 not yet. The specialist cannot see any of it anyway,",
|
|
44316
|
+
" and if it needs something specific it will say so and you can fetch it and ask again.",
|
|
44317
|
+
' Announcing that you are "getting a sense of the workspace before proposing anything" is',
|
|
44318
|
+
" this instruction being broken, however reasonable it sounds.",
|
|
44319
|
+
"2. **Ask the expert for the plan** \u2014 give the task, the little you found and the constraints,",
|
|
44320
|
+
" and ask for numbered steps. A plan is the one thing worth asking for before the work rather",
|
|
44321
|
+
" than after it, and it is what the expert is for. An expert asked early enough to change the",
|
|
44322
|
+
" shape of the work is worth several times one asked to bless a direction already taken.",
|
|
44323
|
+
" **Ask it to say which specialist should be involved in which step**, from the team it is",
|
|
44324
|
+
" given. It knows who is available; it will not volunteer the allocation unless asked.",
|
|
44325
|
+
"3. **Propose it with `update_plan`.** The user sees a diff and approves it. Do not skip this:",
|
|
44326
|
+
" a plan held only in the conversation is forgotten as the chat grows, and it is not",
|
|
44327
|
+
" something the user has agreed to.",
|
|
44328
|
+
"4. Only once it is approved, start the work, reporting each step with `plan_progress`.",
|
|
44329
|
+
"",
|
|
44330
|
+
"If the user declines, ask what they want changed and propose a revised plan. If no expert is",
|
|
44331
|
+
"assigned, draft it yourself and propose it the same way \u2014 and say that is what you did, so",
|
|
44332
|
+
"nobody believes it was reviewed by somebody else.",
|
|
44333
|
+
"",
|
|
44334
|
+
"The exception is a question rather than a job. If the user asked something you can simply",
|
|
44335
|
+
"answer, answer it \u2014 do not plan a conversation."
|
|
44336
|
+
].join("\n");
|
|
44337
|
+
var PLAN_IN_PLACE = [
|
|
44338
|
+
"",
|
|
44339
|
+
"## This conversation already has a plan",
|
|
43968
44340
|
"",
|
|
43969
|
-
"
|
|
43970
|
-
"
|
|
43971
|
-
"
|
|
43972
|
-
"parts where another reader genuinely changes what you do."
|
|
44341
|
+
"It is above, with its steps numbered. Work it, report each step with `plan_progress`, and if it",
|
|
44342
|
+
"turns out to be wrong, consult the expert and propose a replacement with `update_plan` rather",
|
|
44343
|
+
"than quietly working to a different one."
|
|
43973
44344
|
].join("\n");
|
|
43974
44345
|
var DEFAULT_TEAM_GUIDANCE = [
|
|
43975
44346
|
"You lead a small team. You do the work \u2014 reading, searching, editing, running things \u2014 and you",
|
|
@@ -43986,17 +44357,39 @@ var DEFAULT_TEAM_GUIDANCE = [
|
|
|
43986
44357
|
"- you are about to call something done that has no tests \u2014 ask the **tester** what would break",
|
|
43987
44358
|
" it;",
|
|
43988
44359
|
"- you are guessing at how this codebase does something \u2014 ask the **librarian** rather than",
|
|
43989
|
-
" inventing a convention
|
|
44360
|
+
" inventing a convention;",
|
|
44361
|
+
/*
|
|
44362
|
+
* The programmer was missing from this list entirely, which is most of why it never got used.
|
|
44363
|
+
*
|
|
44364
|
+
* Every other bullet describes somebody *reading* what you have, and writing code is the one
|
|
44365
|
+
* thing the assistant can already do — so with no bullet of its own the role simply never came
|
|
44366
|
+
* up, and a plan drafted by the expert never allocated it either (the same omission, in the
|
|
44367
|
+
* briefing). Bounded deliberately: "hand everything to the programmer" would add a round trip
|
|
44368
|
+
* to every edit and put a second model's conventions into the file.
|
|
44369
|
+
*/
|
|
44370
|
+
"- a step is a self-contained piece of code with a clear spec \u2014 a parser, a schema, a set of",
|
|
44371
|
+
" pure functions \u2014 hand it to the **programmer** rather than writing it yourself out of habit,",
|
|
44372
|
+
" then check what comes back against the real file before applying it. Not for a two-line",
|
|
44373
|
+
" change, and not where the spec is still moving.",
|
|
43990
44374
|
"",
|
|
43991
44375
|
'The user can also ask directly ("ask the reviewer to look at this"), and then you consult that',
|
|
43992
44376
|
"role whatever you would have chosen.",
|
|
43993
44377
|
"",
|
|
43994
44378
|
"## What makes a consultation worth it",
|
|
43995
44379
|
"",
|
|
43996
|
-
|
|
43997
|
-
|
|
43998
|
-
|
|
43999
|
-
|
|
44380
|
+
/*
|
|
44381
|
+
* The last place still saying every specialist is blind.
|
|
44382
|
+
*
|
|
44383
|
+
* Some can read and search for themselves; the roster above marks which. But the advice does
|
|
44384
|
+
* not change much, because even one that can look things up starts from what you gave it — and
|
|
44385
|
+
* a question with nothing attached spends its whole lookup budget finding the file you already
|
|
44386
|
+
* had open.
|
|
44387
|
+
*/
|
|
44388
|
+
"**Paste the code**, the error, the failing output \u2014 the actual text. Some of them can read the",
|
|
44389
|
+
"workspace and some cannot, and the roster says which; but even the ones that can start from",
|
|
44390
|
+
"what you give them, and a question with nothing attached spends their whole lookup budget",
|
|
44391
|
+
'finding what you already had open. A question like "is my retry logic right?" with nothing',
|
|
44392
|
+
"attached comes back as a list of things retry logic usually gets wrong, which you already knew.",
|
|
44000
44393
|
"",
|
|
44001
44394
|
"Ask one full question rather than three thin ones. Each consultation is a fresh reader with no",
|
|
44002
44395
|
"memory of the last, so a follow-up has to carry its own context.",
|
|
@@ -44006,30 +44399,86 @@ var DEFAULT_TEAM_GUIDANCE = [
|
|
|
44006
44399
|
"- Do not consult on something you can settle by reading a file. Read it.",
|
|
44007
44400
|
"- Do not relay advice you have not checked. You have the code open and the specialist does not;",
|
|
44008
44401
|
" 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."
|
|
44402
|
+
"- Do not consult the same role twice with the same question hoping for a better answer.",
|
|
44403
|
+
"",
|
|
44404
|
+
"## When a review finds something in code the programmer wrote",
|
|
44405
|
+
"",
|
|
44406
|
+
"**Take it back to the programmer.** It wrote the code, it is the role picked for writing, and",
|
|
44407
|
+
"the fix is its job rather than yours \u2014 you are the one holding the files, not the one whose",
|
|
44408
|
+
"judgement was hired for this. Fixing it silently yourself wastes the specialist and hides the",
|
|
44409
|
+
"exchange from the user.",
|
|
44410
|
+
"",
|
|
44411
|
+
"A consultation remembers nothing, so the question has to carry everything: **the code as it",
|
|
44412
|
+
"stands, the finding in the reviewer's own words, and what you have checked yourself.** A",
|
|
44413
|
+
'programmer told only "the reviewer says this is wrong" will guess at which line and rewrite',
|
|
44414
|
+
"more than it should.",
|
|
44415
|
+
"",
|
|
44416
|
+
"**It may push back, and that is a real answer, not an obstacle.** Reviews are wrong often",
|
|
44417
|
+
"enough to matter \u2014 a finding can be about a path that cannot happen, a convention this",
|
|
44418
|
+
"codebase deliberately does not follow, or a misreading of code the reviewer only saw a fragment",
|
|
44419
|
+
"of. When the programmer disagrees, you settle it: you have the actual file and neither of them",
|
|
44420
|
+
"does. Say which way you went and why, in your reply, so the user sees the disagreement rather",
|
|
44421
|
+
"than only its outcome.",
|
|
44422
|
+
"",
|
|
44423
|
+
"**One lap, not a loop.** Review, fix, and re-review only when the fix was substantial enough",
|
|
44424
|
+
"that the first review no longer describes the code. If the two still disagree after that, stop",
|
|
44425
|
+
"and put it to the expert with both positions, or decide it yourself and say so. Ping-ponging a",
|
|
44426
|
+
"disagreement between two models that cannot see the file is how a turn is spent without",
|
|
44427
|
+
"anything being decided.",
|
|
44428
|
+
"",
|
|
44429
|
+
"## When the plan names a specialist",
|
|
44430
|
+
"",
|
|
44431
|
+
"Consult them **while that step is the active one**, not at the end in a batch. Two reasons, and",
|
|
44432
|
+
"the second is the one people notice: advice arriving after the work is done is a review nobody",
|
|
44433
|
+
"can act on without redoing it, and the progress panel attributes a consultation to whichever",
|
|
44434
|
+
"step was open when it happened \u2014 so a step worked in silence shows as nobody having helped with",
|
|
44435
|
+
"it, whatever you say afterwards.",
|
|
44436
|
+
"",
|
|
44437
|
+
"If a step names somebody and you decide against consulting them, say so and say why. A plan the",
|
|
44438
|
+
"user approved said that step would get another reader."
|
|
44010
44439
|
].join("\n");
|
|
44011
|
-
function buildTeamGuidance(agents, custom2, budgetMatters2) {
|
|
44440
|
+
function buildTeamGuidance(agents, custom2, budgetMatters2, hasPlan) {
|
|
44012
44441
|
const base = custom2 !== void 0 && custom2.trim().length > 0 ? custom2 : DEFAULT_TEAM_GUIDANCE;
|
|
44013
44442
|
const advice = budgetMatters2 === true ? `${base}
|
|
44014
44443
|
${BUDGET_ADVICE}` : base;
|
|
44015
|
-
|
|
44444
|
+
const planning = hasPlan === true ? PLAN_IN_PLACE : PLAN_FIRST;
|
|
44445
|
+
const usable = agents.filter((agent) => agent.available);
|
|
44446
|
+
const unusable = AGENT_ROLES.filter((role) => !usable.some((agent) => agent.role === role)).map((role) => {
|
|
44447
|
+
const assigned = agents.find((agent) => agent.role === role);
|
|
44448
|
+
return assigned === void 0 ? `- **${role}** \u2014 nobody assigned.` : `- **${role}** \u2014 ${assigned.reason ?? "assigned, but cannot be reached."}`;
|
|
44449
|
+
});
|
|
44450
|
+
const missing = unusable.length === 0 ? [] : [
|
|
44451
|
+
"",
|
|
44452
|
+
"**Not available, so do not ask for them and do not plan work for them:**",
|
|
44453
|
+
"",
|
|
44454
|
+
...unusable,
|
|
44455
|
+
"",
|
|
44456
|
+
"If something genuinely needs one of these, say so and say that assigning it in",
|
|
44457
|
+
"Settings \u2192 Agents would let you consult it \u2014 then carry on without it rather than",
|
|
44458
|
+
"leaving that part of the job unaccounted for."
|
|
44459
|
+
];
|
|
44460
|
+
if (usable.length === 0) {
|
|
44016
44461
|
return [
|
|
44017
44462
|
advice,
|
|
44463
|
+
planning,
|
|
44018
44464
|
"",
|
|
44019
44465
|
"## Your team",
|
|
44020
44466
|
"",
|
|
44021
44467
|
"**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."
|
|
44468
|
+
"assigning a specialist in Settings \u2192 Agents would let you consult one.",
|
|
44469
|
+
...missing
|
|
44023
44470
|
].join("\n");
|
|
44024
44471
|
}
|
|
44025
44472
|
return [
|
|
44026
44473
|
advice,
|
|
44474
|
+
planning,
|
|
44027
44475
|
"",
|
|
44028
44476
|
"## Your team",
|
|
44029
44477
|
"",
|
|
44030
|
-
"Reach any of them with `ask_agent`, naming the role:",
|
|
44478
|
+
"Reach any of them with `ask_agent`, naming the role. These are the only ones that exist:",
|
|
44031
44479
|
"",
|
|
44032
|
-
...
|
|
44480
|
+
...usable.map((agent) => `- **${agent.role}** (${agent.label}) \u2014 ${agent.summary}`),
|
|
44481
|
+
...missing
|
|
44033
44482
|
].join("\n");
|
|
44034
44483
|
}
|
|
44035
44484
|
|
|
@@ -44039,20 +44488,146 @@ function firstLine(text, limit = DESCRIPTION_LIMIT) {
|
|
|
44039
44488
|
const line = text.split("\n").find((candidate) => candidate.trim().length > 0)?.trim() ?? "";
|
|
44040
44489
|
return line.length > limit ? `${line.slice(0, limit - 1).trimEnd()}\u2026` : line;
|
|
44041
44490
|
}
|
|
44491
|
+
function buildRoster(team, self) {
|
|
44492
|
+
const others = team.filter((agent) => agent.role !== self);
|
|
44493
|
+
const usable = others.filter((agent) => agent.available);
|
|
44494
|
+
const assigned = new Set(team.map((agent) => agent.role));
|
|
44495
|
+
const missing = [];
|
|
44496
|
+
for (const role of AGENT_ROLES) {
|
|
44497
|
+
if (role === self)
|
|
44498
|
+
continue;
|
|
44499
|
+
if (!assigned.has(role)) {
|
|
44500
|
+
missing.push(`- **${role}** \u2014 nobody is assigned to this role.`);
|
|
44501
|
+
continue;
|
|
44502
|
+
}
|
|
44503
|
+
const agent = others.find((candidate) => candidate.role === role);
|
|
44504
|
+
if (agent !== void 0 && !agent.available) {
|
|
44505
|
+
missing.push(`- **${role}** \u2014 ${agent.reason ?? "assigned, but cannot be reached."}`);
|
|
44506
|
+
}
|
|
44507
|
+
}
|
|
44508
|
+
const sections = ["## The rest of the team", ""];
|
|
44509
|
+
if (self !== void 0)
|
|
44510
|
+
sections.push(`You are the **${self}**.`, "");
|
|
44511
|
+
sections.push(usable.length > 0 ? "The assistant can also consult these specialists, and only these:" : "The assistant has **no other specialists available**. Whatever you propose, it does alone.");
|
|
44512
|
+
if (usable.length > 0) {
|
|
44513
|
+
sections.push(
|
|
44514
|
+
"",
|
|
44515
|
+
/*
|
|
44516
|
+
* What the others can actually do — and this was wrong once, in the expensive direction.
|
|
44517
|
+
*
|
|
44518
|
+
* It first said "None of them can see the workspace", written to stop the expert giving the
|
|
44519
|
+
* librarian a lookup job. That was false: `agents/consult.ts` gives a specialist the read
|
|
44520
|
+
* tool group, and the CLI expert holds Claude's own Read/Grep/Glob. The instruction was
|
|
44521
|
+
* therefore telling the expert *not* to allocate the librarian the one kind of work the
|
|
44522
|
+
* librarian is equipped for, which made the weakest role weaker.
|
|
44523
|
+
*
|
|
44524
|
+
* The real distinction is per role and the user controls it, so it is rendered from the
|
|
44525
|
+
* team rather than asserted about all of them — and it sits *above* the list, because it is
|
|
44526
|
+
* how to read the marks in it.
|
|
44527
|
+
*/
|
|
44528
|
+
"**None of them can edit anything or run anything.** They read and advise; the assistant",
|
|
44529
|
+
"makes every change, and it is the one answerable for the result. Some can look things up",
|
|
44530
|
+
"for themselves, marked below; the rest know only what is in the question, so give those",
|
|
44531
|
+
"everything they need.",
|
|
44532
|
+
"",
|
|
44533
|
+
...usable.map((agent) => `- **${agent.role}** (${agent.label}) \u2014 ${agent.summary}` + // Marked per role because it decides what is worth asking them: one that can read
|
|
44534
|
+
// needs pointing at a file, one that cannot needs the file pasted in.
|
|
44535
|
+
(agent.usesTools ? " *(can read and search the workspace)*" : "")),
|
|
44536
|
+
"",
|
|
44537
|
+
/*
|
|
44538
|
+
* Knowing who exists is not the same as being asked to use them.
|
|
44539
|
+
*
|
|
44540
|
+
* Reported with a plan that allocated nobody, on a machine where all four other roles were
|
|
44541
|
+
* assigned. The briefing told the expert who was available and told it not to name anyone
|
|
44542
|
+
* who was not — and it dutifully named nobody at all, writing a plan for the assistant
|
|
44543
|
+
* working alone, down to "I'll show you the code before moving on" where a reviewer was
|
|
44544
|
+
* sitting right there. An instruction that only says what *not* to do gets obeyed by doing
|
|
44545
|
+
* nothing.
|
|
44546
|
+
*
|
|
44547
|
+
* Deliberately not "use every specialist": that is four extra round trips on a task that
|
|
44548
|
+
* may not want any, and a plan routing every step through the whole team is worse than one
|
|
44549
|
+
* routing none — it reads as ceremony and people stop reading it.
|
|
44550
|
+
*/
|
|
44551
|
+
"**If you are asked for a plan, say who should be involved in which step.** Name the role in",
|
|
44552
|
+
'the step itself \u2014 "have the tester say what would break this", "get the reviewer onto the',
|
|
44553
|
+
'callback wiring", "hand the parser to the programmer" \u2014 so the assistant knows when to',
|
|
44554
|
+
"consult and the user can see who is doing what.",
|
|
44555
|
+
"",
|
|
44556
|
+
/*
|
|
44557
|
+
* Two kinds of specialist, said separately, because the first version only described one.
|
|
44558
|
+
*
|
|
44559
|
+
* It asked for allocation "where another reader would genuinely change the outcome" and
|
|
44560
|
+
* called it "another pair of eyes" — review framing throughout, with a reviewer and a
|
|
44561
|
+
* tester as the examples. The programmer does not read, it produces, so a plan written to
|
|
44562
|
+
* that instruction correctly never mentions it. Reported exactly that way: reviewer and
|
|
44563
|
+
* tester allocated across four steps, programmer nowhere, on a machine where it was
|
|
44564
|
+
* assigned. An instruction that names one mode of use gets obeyed in one mode.
|
|
44565
|
+
*/
|
|
44566
|
+
"They divide into two kinds, and both are worth allocating:",
|
|
44567
|
+
"",
|
|
44568
|
+
"- **Readers** \u2014 the reviewer, the tester, the librarian. Worth a step where another pair of",
|
|
44569
|
+
" eyes changes what happens: risky or fiddly code, a step that finishes something, a",
|
|
44570
|
+
" convention you would otherwise be guessing at.",
|
|
44571
|
+
'- **The librarian writes down what should be written down.** A step like "record how this',
|
|
44572
|
+
' is set up" is a good one to allocate: it reads what already exists and records the skill',
|
|
44573
|
+
" itself. The user approves the text before it is saved, so word the step as recording.",
|
|
44574
|
+
"- **The programmer writes.** Where a step is a self-contained piece of code with a spec",
|
|
44575
|
+
" clear enough to hand over \u2014 a parser, a schema, a set of pure functions \u2014 say so and give",
|
|
44576
|
+
" it to the programmer. The assistant checks what comes back against the real file and",
|
|
44577
|
+
" applies it, so this is delegation rather than trust.",
|
|
44578
|
+
"",
|
|
44579
|
+
/*
|
|
44580
|
+
* A role invented by the user, which no fixed description can cover.
|
|
44581
|
+
*
|
|
44582
|
+
* The two bullets above name the built-in five, and a plan written only from them would
|
|
44583
|
+
* quietly skip a `db-reviewer` the user went to the trouble of creating — the same failure
|
|
44584
|
+
* as never allocating the programmer, arriving from the other direction. The summary is the
|
|
44585
|
+
* only thing that can describe it, so the instruction is to read it.
|
|
44586
|
+
*/
|
|
44587
|
+
"- **A role you do not recognise is described by its summary above.** The user invented it",
|
|
44588
|
+
" and wrote that line, so treat it as the authority on what the role is for and allocate it",
|
|
44589
|
+
" where the summary says it helps.",
|
|
44590
|
+
"",
|
|
44591
|
+
"Only where it genuinely changes the outcome: a plan that routes every step through all of",
|
|
44592
|
+
"them is ceremony, and one that routes none wastes a team that is sitting there."
|
|
44593
|
+
);
|
|
44594
|
+
}
|
|
44595
|
+
if (missing.length > 0) {
|
|
44596
|
+
sections.push(
|
|
44597
|
+
"",
|
|
44598
|
+
// "Not set up" would be wrong for a role that *is* assigned and whose profile has since
|
|
44599
|
+
// gone: the user did set it up, and telling them otherwise sends them to fix the wrong
|
|
44600
|
+
// thing. "Not available" is true of both, and the reason beside each says which it is.
|
|
44601
|
+
"**Not available, so the assistant cannot use them:**",
|
|
44602
|
+
"",
|
|
44603
|
+
...missing,
|
|
44604
|
+
"",
|
|
44605
|
+
"Do not give any of these work. Do not put them in a plan, a checklist or a next step \u2014 a",
|
|
44606
|
+
"plan naming a specialist who does not exist is a plan with a hole in it, and the user will",
|
|
44607
|
+
"have approved it without knowing. If a task genuinely needs one, say so in a sentence and",
|
|
44608
|
+
"say the user would have to assign it in Settings \u2192 Agents; then give the best advice you",
|
|
44609
|
+
"can for doing it without that role."
|
|
44610
|
+
);
|
|
44611
|
+
}
|
|
44612
|
+
return sections;
|
|
44613
|
+
}
|
|
44042
44614
|
function buildAgentBriefing(input) {
|
|
44043
44615
|
const tools = (input.tools ?? []).filter(
|
|
44044
44616
|
// Telling a specialist it can consult a specialist is noise at best and a loop at worst.
|
|
44045
44617
|
(tool) => tool.name !== "ask_agent" && tool.name !== "ask_expert"
|
|
44046
44618
|
);
|
|
44047
44619
|
const skills = input.skills ?? [];
|
|
44048
|
-
|
|
44620
|
+
const team = input.team;
|
|
44621
|
+
if (tools.length === 0 && skills.length === 0 && team === void 0)
|
|
44049
44622
|
return "";
|
|
44050
|
-
const sections = [
|
|
44051
|
-
|
|
44052
|
-
|
|
44053
|
-
|
|
44054
|
-
|
|
44055
|
-
|
|
44623
|
+
const sections = [];
|
|
44624
|
+
if (team !== void 0)
|
|
44625
|
+
sections.push(...buildRoster(team, input.self));
|
|
44626
|
+
if (tools.length > 0 || skills.length > 0) {
|
|
44627
|
+
if (sections.length > 0)
|
|
44628
|
+
sections.push("");
|
|
44629
|
+
sections.push("## What the assistant can do on your behalf", "", "You have no tools. The assistant asking you does, and will carry out whatever you recommend.", "Name the tool or skill you mean rather than describing a manual procedure that duplicates it.");
|
|
44630
|
+
}
|
|
44056
44631
|
if (tools.length > 0) {
|
|
44057
44632
|
sections.push("", "### Tools it can call", "", ...tools.map((tool) => `- \`${tool.name}\` \u2014 ${firstLine(tool.description)}`));
|
|
44058
44633
|
}
|
|
@@ -44062,11 +44637,109 @@ function buildAgentBriefing(input) {
|
|
|
44062
44637
|
return sections.join("\n");
|
|
44063
44638
|
}
|
|
44064
44639
|
|
|
44640
|
+
// ../../packages/core/dist/approval/commands.js
|
|
44641
|
+
function isCommandAllowlisted(command, allowlist) {
|
|
44642
|
+
return allowlist.includes(command);
|
|
44643
|
+
}
|
|
44644
|
+
function addToAllowlist(command, allowlist) {
|
|
44645
|
+
return allowlist.includes(command) ? [...allowlist] : [...allowlist, command];
|
|
44646
|
+
}
|
|
44647
|
+
function removeFromAllowlist(command, allowlist) {
|
|
44648
|
+
return allowlist.filter((entry) => entry !== command);
|
|
44649
|
+
}
|
|
44650
|
+
|
|
44651
|
+
// ../../packages/core/dist/approval/types.js
|
|
44652
|
+
function requiresApproval(group) {
|
|
44653
|
+
return group !== "always";
|
|
44654
|
+
}
|
|
44655
|
+
|
|
44656
|
+
// ../../packages/core/dist/approval/policy.js
|
|
44657
|
+
function isApprovableGroup(group) {
|
|
44658
|
+
return group === "read" || group === "edit" || group === "command" || group === "mcp";
|
|
44659
|
+
}
|
|
44660
|
+
function categoryEnabled(group, settings) {
|
|
44661
|
+
if (settings === void 0 || !isApprovableGroup(group))
|
|
44662
|
+
return false;
|
|
44663
|
+
return settings[group] === true;
|
|
44664
|
+
}
|
|
44665
|
+
var ALWAYS_ASK_TOOLS = /* @__PURE__ */ new Set([
|
|
44666
|
+
"create_python_tool",
|
|
44667
|
+
"update_python_tool",
|
|
44668
|
+
"delete_python_tool",
|
|
44669
|
+
"write_skill",
|
|
44670
|
+
"delete_skill",
|
|
44671
|
+
/*
|
|
44672
|
+
* VBA installed into a workbook runs on this machine as this user, and nobody reviews a macro
|
|
44673
|
+
* afterwards. That is the same act as creating a Python tool, so it gets the same rule: a
|
|
44674
|
+
* human sees the source once, and no category toggle can stand in for that.
|
|
44675
|
+
*/
|
|
44676
|
+
"excel_write_macro",
|
|
44677
|
+
/*
|
|
44678
|
+
* Running a macro executes somebody else's VBA as the user: it can rewrite the workbook, write
|
|
44679
|
+
* files, or send mail. That is not something a category toggle should ever cover, and the
|
|
44680
|
+
* approval showing the actual source is the only thing standing between "run DoTheThing" and
|
|
44681
|
+
* whatever DoTheThing does.
|
|
44682
|
+
*/
|
|
44683
|
+
"excel_run_macro",
|
|
44684
|
+
/*
|
|
44685
|
+
* The plan is what holds the assistant to work the user agreed, so a category toggle must
|
|
44686
|
+
* never stand in for reading the change. Auto-approving this would mean an agent could widen
|
|
44687
|
+
* its own instructions and then point at them as authority — and both the panel and the
|
|
44688
|
+
* prompt would look right afterwards, because both would be reading the new plan.
|
|
44689
|
+
*/
|
|
44690
|
+
"update_plan",
|
|
44691
|
+
/*
|
|
44692
|
+
* A role's prompt is prose injected into a model that then advises on this repository's code —
|
|
44693
|
+
* the reason `agents` is user-scope only. Softening a reviewer does not error; it approves
|
|
44694
|
+
* things, in the same tone as before. A category toggle must never stand in for reading that
|
|
44695
|
+
* diff.
|
|
44696
|
+
*/
|
|
44697
|
+
"update_role",
|
|
44698
|
+
// Inventing one is the same act as rewriting one: a prompt that will advise on this code.
|
|
44699
|
+
"create_role",
|
|
44700
|
+
// And removing one takes a prompt somebody wrote with it.
|
|
44701
|
+
"delete_role"
|
|
44702
|
+
]);
|
|
44703
|
+
function decideFromPolicy(request, approvals) {
|
|
44704
|
+
if (!requiresApproval(request.group))
|
|
44705
|
+
return "approve";
|
|
44706
|
+
if (ALWAYS_ASK_TOOLS.has(request.toolName))
|
|
44707
|
+
return void 0;
|
|
44708
|
+
if (approvals === void 0)
|
|
44709
|
+
return void 0;
|
|
44710
|
+
if (approvals.allowedTools?.includes(request.toolName) === true)
|
|
44711
|
+
return "approve";
|
|
44712
|
+
if (request.group === "command") {
|
|
44713
|
+
const command = commandFromPreview(request.preview);
|
|
44714
|
+
if (command !== void 0 && isCommandAllowlisted(command, approvals.allowedCommands ?? [])) {
|
|
44715
|
+
return "approve";
|
|
44716
|
+
}
|
|
44717
|
+
}
|
|
44718
|
+
return categoryEnabled(request.group, approvals.autoApprove) ? "approve" : void 0;
|
|
44719
|
+
}
|
|
44720
|
+
function commandFromPreview(preview) {
|
|
44721
|
+
return preview.kind === "command" ? preview.command : void 0;
|
|
44722
|
+
}
|
|
44723
|
+
var PolicyApprovalGate = class {
|
|
44724
|
+
inner;
|
|
44725
|
+
getApprovals;
|
|
44726
|
+
constructor(inner, getApprovals) {
|
|
44727
|
+
this.inner = inner;
|
|
44728
|
+
this.getApprovals = getApprovals;
|
|
44729
|
+
}
|
|
44730
|
+
async requestApproval(request) {
|
|
44731
|
+
const decided = decideFromPolicy(request, this.getApprovals());
|
|
44732
|
+
if (decided !== void 0)
|
|
44733
|
+
return decided;
|
|
44734
|
+
return this.inner.requestApproval(request);
|
|
44735
|
+
}
|
|
44736
|
+
};
|
|
44737
|
+
|
|
44065
44738
|
// ../../packages/core/dist/agents/consult.js
|
|
44066
44739
|
var CONSULT_MAX_STEPS = 5;
|
|
44067
44740
|
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");
|
|
44741
|
+
function toolsForConsultation(all, extra = /* @__PURE__ */ new Set()) {
|
|
44742
|
+
return all.filter((tool) => (ALLOWED_GROUPS.has(tool.group) || extra.has(tool.name)) && tool.name !== "ask_agent" && tool.name !== "ask_expert");
|
|
44070
44743
|
}
|
|
44071
44744
|
async function runConsultation(options) {
|
|
44072
44745
|
const limit = options.maxSteps ?? CONSULT_MAX_STEPS;
|
|
@@ -44116,7 +44789,10 @@ async function runConsultation(options) {
|
|
|
44116
44789
|
}
|
|
44117
44790
|
try {
|
|
44118
44791
|
const parsed = tool.parametersSchema.safeParse(JSON.parse(call.arguments || "{}"));
|
|
44119
|
-
const
|
|
44792
|
+
const permitted = tool.group === "read" && !ALWAYS_ASK_TOOLS.has(tool.name) || options.approve !== void 0 && await options.approve(tool, parsed.data);
|
|
44793
|
+
const result = !permitted ? {
|
|
44794
|
+
content: `The user did not approve ${tool.name}. Say what you would have written and why, and let the assistant put it to them instead.`
|
|
44795
|
+
} : parsed.success ? await tool.execute(parsed.data, options.context) : {
|
|
44120
44796
|
content: `Those arguments are not valid: ${parsed.error.issues.map((i) => i.message).join("; ")}`
|
|
44121
44797
|
};
|
|
44122
44798
|
messages.push({ role: "tool", toolCallId: call.id, content: String(result.content) });
|
|
@@ -48097,18 +48773,28 @@ var NEVER_AVAILABLE_TO_SCHEDULES = [
|
|
|
48097
48773
|
// section 13 requires approval showing the source, which cannot happen with nobody there.
|
|
48098
48774
|
"excel_write_macro",
|
|
48099
48775
|
// And running one: unattended execution of arbitrary VBA, with nobody to read the source.
|
|
48100
|
-
"excel_run_macro"
|
|
48776
|
+
"excel_run_macro",
|
|
48777
|
+
/*
|
|
48778
|
+
* Rewriting the plan it is being held to, with nobody there to approve the diff. Same ladder
|
|
48779
|
+
* as `schedule_prompt`: a run that can change its own instructions is bounded by nothing.
|
|
48780
|
+
*/
|
|
48781
|
+
"update_plan",
|
|
48782
|
+
// Rewriting what a specialist is, unattended. The same ladder: a run that can redefine its own
|
|
48783
|
+
// reviewer can arrange to be reviewed favourably by the next one.
|
|
48784
|
+
"update_role",
|
|
48785
|
+
"create_role",
|
|
48786
|
+
"delete_role"
|
|
48101
48787
|
];
|
|
48102
48788
|
function scheduleAppliesHere(schedule, workspaceRoot) {
|
|
48103
48789
|
if (schedule.workspaceRoot === void 0)
|
|
48104
48790
|
return true;
|
|
48105
48791
|
if (workspaceRoot === void 0)
|
|
48106
48792
|
return false;
|
|
48107
|
-
const
|
|
48793
|
+
const normalise2 = (value) => {
|
|
48108
48794
|
const resolved = nodePath.resolve(value);
|
|
48109
48795
|
return process.platform === "win32" ? resolved.toLowerCase() : resolved;
|
|
48110
48796
|
};
|
|
48111
|
-
return
|
|
48797
|
+
return normalise2(schedule.workspaceRoot) === normalise2(workspaceRoot);
|
|
48112
48798
|
}
|
|
48113
48799
|
function filterToolsForSchedule(all, schedule) {
|
|
48114
48800
|
const named = new Set(schedule.allowedTools);
|
|
@@ -49269,86 +49955,6 @@ async function indexWorkspace(options) {
|
|
|
49269
49955
|
};
|
|
49270
49956
|
}
|
|
49271
49957
|
|
|
49272
|
-
// ../../packages/core/dist/approval/types.js
|
|
49273
|
-
function requiresApproval(group) {
|
|
49274
|
-
return group !== "always";
|
|
49275
|
-
}
|
|
49276
|
-
|
|
49277
|
-
// ../../packages/core/dist/approval/commands.js
|
|
49278
|
-
function isCommandAllowlisted(command, allowlist) {
|
|
49279
|
-
return allowlist.includes(command);
|
|
49280
|
-
}
|
|
49281
|
-
function addToAllowlist(command, allowlist) {
|
|
49282
|
-
return allowlist.includes(command) ? [...allowlist] : [...allowlist, command];
|
|
49283
|
-
}
|
|
49284
|
-
function removeFromAllowlist(command, allowlist) {
|
|
49285
|
-
return allowlist.filter((entry) => entry !== command);
|
|
49286
|
-
}
|
|
49287
|
-
|
|
49288
|
-
// ../../packages/core/dist/approval/policy.js
|
|
49289
|
-
function isApprovableGroup(group) {
|
|
49290
|
-
return group === "read" || group === "edit" || group === "command" || group === "mcp";
|
|
49291
|
-
}
|
|
49292
|
-
function categoryEnabled(group, settings) {
|
|
49293
|
-
if (settings === void 0 || !isApprovableGroup(group))
|
|
49294
|
-
return false;
|
|
49295
|
-
return settings[group] === true;
|
|
49296
|
-
}
|
|
49297
|
-
var ALWAYS_ASK_TOOLS = /* @__PURE__ */ new Set([
|
|
49298
|
-
"create_python_tool",
|
|
49299
|
-
"update_python_tool",
|
|
49300
|
-
"delete_python_tool",
|
|
49301
|
-
"write_skill",
|
|
49302
|
-
"delete_skill",
|
|
49303
|
-
/*
|
|
49304
|
-
* VBA installed into a workbook runs on this machine as this user, and nobody reviews a macro
|
|
49305
|
-
* afterwards. That is the same act as creating a Python tool, so it gets the same rule: a
|
|
49306
|
-
* human sees the source once, and no category toggle can stand in for that.
|
|
49307
|
-
*/
|
|
49308
|
-
"excel_write_macro",
|
|
49309
|
-
/*
|
|
49310
|
-
* Running a macro executes somebody else's VBA as the user: it can rewrite the workbook, write
|
|
49311
|
-
* files, or send mail. That is not something a category toggle should ever cover, and the
|
|
49312
|
-
* approval showing the actual source is the only thing standing between "run DoTheThing" and
|
|
49313
|
-
* whatever DoTheThing does.
|
|
49314
|
-
*/
|
|
49315
|
-
"excel_run_macro"
|
|
49316
|
-
]);
|
|
49317
|
-
function decideFromPolicy(request, approvals) {
|
|
49318
|
-
if (!requiresApproval(request.group))
|
|
49319
|
-
return "approve";
|
|
49320
|
-
if (ALWAYS_ASK_TOOLS.has(request.toolName))
|
|
49321
|
-
return void 0;
|
|
49322
|
-
if (approvals === void 0)
|
|
49323
|
-
return void 0;
|
|
49324
|
-
if (approvals.allowedTools?.includes(request.toolName) === true)
|
|
49325
|
-
return "approve";
|
|
49326
|
-
if (request.group === "command") {
|
|
49327
|
-
const command = commandFromPreview(request.preview);
|
|
49328
|
-
if (command !== void 0 && isCommandAllowlisted(command, approvals.allowedCommands ?? [])) {
|
|
49329
|
-
return "approve";
|
|
49330
|
-
}
|
|
49331
|
-
}
|
|
49332
|
-
return categoryEnabled(request.group, approvals.autoApprove) ? "approve" : void 0;
|
|
49333
|
-
}
|
|
49334
|
-
function commandFromPreview(preview) {
|
|
49335
|
-
return preview.kind === "command" ? preview.command : void 0;
|
|
49336
|
-
}
|
|
49337
|
-
var PolicyApprovalGate = class {
|
|
49338
|
-
inner;
|
|
49339
|
-
getApprovals;
|
|
49340
|
-
constructor(inner, getApprovals) {
|
|
49341
|
-
this.inner = inner;
|
|
49342
|
-
this.getApprovals = getApprovals;
|
|
49343
|
-
}
|
|
49344
|
-
async requestApproval(request) {
|
|
49345
|
-
const decided = decideFromPolicy(request, this.getApprovals());
|
|
49346
|
-
if (decided !== void 0)
|
|
49347
|
-
return decided;
|
|
49348
|
-
return this.inner.requestApproval(request);
|
|
49349
|
-
}
|
|
49350
|
-
};
|
|
49351
|
-
|
|
49352
49958
|
// ../../packages/core/dist/checkpoints/shadowGit.js
|
|
49353
49959
|
import { execFile as execFile2 } from "node:child_process";
|
|
49354
49960
|
import fs7 from "node:fs/promises";
|
|
@@ -49414,18 +50020,77 @@ var ShadowGit = class {
|
|
|
49414
50020
|
if (restore.code !== 0) {
|
|
49415
50021
|
throw new Error(`Could not roll back to checkpoint: ${restore.stderr || restore.stdout}`);
|
|
49416
50022
|
}
|
|
49417
|
-
await runGit(this.gitArgs(["clean", "-fd"]), this.workspaceRoot);
|
|
49418
|
-
}
|
|
49419
|
-
/** Whether `git` is on PATH at all — checkpoints degrade to unavailable, not to a crash. */
|
|
49420
|
-
static async isGitAvailable() {
|
|
49421
|
-
try {
|
|
49422
|
-
const result = await runGit(["--version"], process.cwd());
|
|
49423
|
-
return result.code === 0;
|
|
49424
|
-
} catch {
|
|
49425
|
-
return false;
|
|
50023
|
+
await runGit(this.gitArgs(["clean", "-fd"]), this.workspaceRoot);
|
|
50024
|
+
}
|
|
50025
|
+
/** Whether `git` is on PATH at all — checkpoints degrade to unavailable, not to a crash. */
|
|
50026
|
+
static async isGitAvailable() {
|
|
50027
|
+
try {
|
|
50028
|
+
const result = await runGit(["--version"], process.cwd());
|
|
50029
|
+
return result.code === 0;
|
|
50030
|
+
} catch {
|
|
50031
|
+
return false;
|
|
50032
|
+
}
|
|
50033
|
+
}
|
|
50034
|
+
};
|
|
50035
|
+
|
|
50036
|
+
// ../../packages/core/dist/tools/planTools.js
|
|
50037
|
+
var updateParams = external_exports.object({
|
|
50038
|
+
plan: external_exports.string().describe("The complete new plan, as numbered steps. This replaces the whole plan rather than being added to it, so include the steps that are staying."),
|
|
50039
|
+
reason: external_exports.string().optional().describe("One line on why the plan should change, shown to the user with the diff.")
|
|
50040
|
+
});
|
|
50041
|
+
function createUpdatePlanTool(access) {
|
|
50042
|
+
return {
|
|
50043
|
+
name: "update_plan",
|
|
50044
|
+
group: "edit",
|
|
50045
|
+
description: "Propose a new plan for this conversation, replacing the current one. The user is shown a diff and must approve it before anything changes. Use this after working out a plan \u2014 for example one a specialist drafted \u2014 rather than carrying it only in the conversation, which is forgotten as the chat grows. Give the whole plan as numbered steps; each step becomes a checkpoint the user can watch you complete.",
|
|
50046
|
+
parametersSchema: updateParams,
|
|
50047
|
+
async preview(params) {
|
|
50048
|
+
const before = access.current() ?? "";
|
|
50049
|
+
return {
|
|
50050
|
+
kind: "diff",
|
|
50051
|
+
// Not a file. The approval UI labels the diff with this, and naming it for what it is
|
|
50052
|
+
// beats a made-up path that implies something on disk is about to change.
|
|
50053
|
+
path: "the plan for this conversation",
|
|
50054
|
+
before,
|
|
50055
|
+
after: params.plan.slice(0, PLAN_LIMIT).trim(),
|
|
50056
|
+
...params.reason !== void 0 && params.reason.trim().length > 0 ? { note: params.reason.trim() } : {}
|
|
50057
|
+
};
|
|
50058
|
+
},
|
|
50059
|
+
async execute(params) {
|
|
50060
|
+
const next = params.plan.slice(0, PLAN_LIMIT).trim();
|
|
50061
|
+
if (next.length === 0) {
|
|
50062
|
+
return { content: "A plan cannot be empty. To remove the plan, ask the user to clear it." };
|
|
50063
|
+
}
|
|
50064
|
+
await access.save(next);
|
|
50065
|
+
return {
|
|
50066
|
+
content: "The plan is updated and the user approved it. It is now in front of you for the rest of this conversation, and its steps are the checkpoints to report against."
|
|
50067
|
+
};
|
|
50068
|
+
}
|
|
50069
|
+
};
|
|
50070
|
+
}
|
|
50071
|
+
var progressParams = external_exports.object({
|
|
50072
|
+
checkpoint: external_exports.number().int().describe("The step number, as numbered in the plan you were given."),
|
|
50073
|
+
status: external_exports.enum(["active", "done"]).describe("`active` when you start the step, `done` when it is genuinely finished.")
|
|
50074
|
+
});
|
|
50075
|
+
function createPlanProgressTool(access) {
|
|
50076
|
+
return {
|
|
50077
|
+
name: "plan_progress",
|
|
50078
|
+
/*
|
|
50079
|
+
* Control flow, not an action: it records where you are and touches nothing else. Gating it
|
|
50080
|
+
* would mean an approval prompt between every step of every planned task, which nobody would
|
|
50081
|
+
* keep switched on for long.
|
|
50082
|
+
*/
|
|
50083
|
+
group: "always",
|
|
50084
|
+
description: "Say which step of the plan you are on. Call it with `active` when you start a step and `done` when it is finished, so the user can watch progress without reading the whole transcript. Mark `done` only when the step is actually complete \u2014 a step you gave up on or half did should be reported in your reply instead.",
|
|
50085
|
+
parametersSchema: progressParams,
|
|
50086
|
+
async execute(params) {
|
|
50087
|
+
const outcome = await access.mark(params.checkpoint, params.status);
|
|
50088
|
+
if (!outcome.ok)
|
|
50089
|
+
return { content: outcome.reason, isError: true };
|
|
50090
|
+
return { content: outcome.summary };
|
|
49426
50091
|
}
|
|
49427
|
-
}
|
|
49428
|
-
}
|
|
50092
|
+
};
|
|
50093
|
+
}
|
|
49429
50094
|
|
|
49430
50095
|
// ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1_ed45788dfbfe808cc09dd7daea6bd385/node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-compat.js
|
|
49431
50096
|
function isZ4Schema(s) {
|
|
@@ -56584,6 +57249,29 @@ function looksUnfinished(text) {
|
|
|
56584
57249
|
var CONTINUE_PROMPT = "You described what you were about to do but did not call a tool, so nothing happened. If you meant to act, call the tool now. If you were already finished, call attempt_completion with a summary instead.";
|
|
56585
57250
|
var MAX_CONTINUE_NUDGES = 1;
|
|
56586
57251
|
|
|
57252
|
+
// ../../packages/core/dist/agent/repairHistory.js
|
|
57253
|
+
var UNANSWERED = "This tool call never reported a result \u2014 the turn ended before it did. Nothing can be assumed about whether it ran or what it changed. If it still matters, call it again; otherwise carry on.";
|
|
57254
|
+
function repairUnansweredToolCalls(messages) {
|
|
57255
|
+
const answered = /* @__PURE__ */ new Set();
|
|
57256
|
+
for (const message3 of messages) {
|
|
57257
|
+
if (message3.role === "tool" && message3.toolCallId !== void 0)
|
|
57258
|
+
answered.add(message3.toolCallId);
|
|
57259
|
+
}
|
|
57260
|
+
const repaired = [];
|
|
57261
|
+
for (const message3 of messages) {
|
|
57262
|
+
repaired.push(message3);
|
|
57263
|
+
if (message3.role !== "assistant" || message3.toolCalls === void 0)
|
|
57264
|
+
continue;
|
|
57265
|
+
for (const call of message3.toolCalls) {
|
|
57266
|
+
if (answered.has(call.id))
|
|
57267
|
+
continue;
|
|
57268
|
+
repaired.push({ role: "tool", toolCallId: call.id, content: UNANSWERED });
|
|
57269
|
+
answered.add(call.id);
|
|
57270
|
+
}
|
|
57271
|
+
}
|
|
57272
|
+
return repaired;
|
|
57273
|
+
}
|
|
57274
|
+
|
|
56587
57275
|
// ../../packages/core/dist/agent/truncate.js
|
|
56588
57276
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
56589
57277
|
import fs14 from "node:fs/promises";
|
|
@@ -56676,10 +57364,12 @@ async function truncateToolResult(content, store, maxChars = DEFAULT_MAX_CHARS)
|
|
|
56676
57364
|
|
|
56677
57365
|
// ../../packages/core/dist/agent/loop.js
|
|
56678
57366
|
var DEFAULT_MAX_ITERATIONS = 25;
|
|
57367
|
+
var BOOKKEEPING_TOOLS = /* @__PURE__ */ new Set(["plan_progress"]);
|
|
57368
|
+
var MAX_REFUNDED_STEPS = 20;
|
|
56679
57369
|
var MAX_CONSECUTIVE_MISTAKES = 3;
|
|
56680
57370
|
async function prepareModelMessages(conversation, provider, tools, options, events) {
|
|
56681
57371
|
const contextWindow = options.contextWindow ?? 0;
|
|
56682
|
-
let messages = conversation.toModelMessages();
|
|
57372
|
+
let messages = repairUnansweredToolCalls(conversation.toModelMessages());
|
|
56683
57373
|
if (options.compactionEnabled !== false && contextWindow > 0) {
|
|
56684
57374
|
const estimated = computeBreakdown(messages, tools, contextWindow).total;
|
|
56685
57375
|
if (shouldCompact(messages, estimated, contextWindow, options.compaction ?? {})) {
|
|
@@ -56689,7 +57379,7 @@ async function prepareModelMessages(conversation, provider, tools, options, even
|
|
|
56689
57379
|
if (summary !== void 0) {
|
|
56690
57380
|
conversation.applyCompaction(summary, conversation.compactedCount() + result.summarisedCount);
|
|
56691
57381
|
events.onCompacted?.(result.summarisedCount);
|
|
56692
|
-
messages = conversation.toModelMessages();
|
|
57382
|
+
messages = repairUnansweredToolCalls(conversation.toModelMessages());
|
|
56693
57383
|
}
|
|
56694
57384
|
}
|
|
56695
57385
|
}
|
|
@@ -56857,6 +57547,7 @@ async function runWithTimeout(tool, params, context, options) {
|
|
|
56857
57547
|
async function runAgentTurn(provider, conversation, userMessage, toolRegistry, toolContext, events, options = {}) {
|
|
56858
57548
|
conversation.addUserMessage(userMessage, options.images);
|
|
56859
57549
|
const maxIterations = options.maxIterations ?? DEFAULT_MAX_ITERATIONS;
|
|
57550
|
+
let refunded = 0;
|
|
56860
57551
|
const mistakeCounts = /* @__PURE__ */ new Map();
|
|
56861
57552
|
let continueNudges = 0;
|
|
56862
57553
|
const mode = options.mode ?? CODE_MODE;
|
|
@@ -56908,12 +57599,20 @@ async function runAgentTurn(provider, conversation, userMessage, toolRegistry, t
|
|
|
56908
57599
|
}
|
|
56909
57600
|
conversation.addAssistantMessage(assistantText, [toolCall]);
|
|
56910
57601
|
events.onToolCall(toolCall);
|
|
56911
|
-
|
|
56912
|
-
|
|
56913
|
-
|
|
56914
|
-
|
|
56915
|
-
|
|
56916
|
-
|
|
57602
|
+
let result;
|
|
57603
|
+
try {
|
|
57604
|
+
result = await runOneToolCall(toolCall, toolRegistry, toolContext, options, events, {
|
|
57605
|
+
hasCheckpoint: () => checkpointTaken,
|
|
57606
|
+
markCheckpointTaken: () => {
|
|
57607
|
+
checkpointTaken = true;
|
|
57608
|
+
}
|
|
57609
|
+
}, mode);
|
|
57610
|
+
} catch (error51) {
|
|
57611
|
+
result = {
|
|
57612
|
+
content: `"${toolCall.name}" failed: ${error51 instanceof Error ? error51.message : String(error51)}`,
|
|
57613
|
+
isError: true
|
|
57614
|
+
};
|
|
57615
|
+
}
|
|
56917
57616
|
const forModel = options.truncationStore !== void 0 ? (await truncateToolResult(result.content, options.truncationStore)).content : result.content;
|
|
56918
57617
|
conversation.addToolResultMessage(toolCall.id, forModel);
|
|
56919
57618
|
events.onToolResult(toolCall, result);
|
|
@@ -56926,6 +57625,10 @@ async function runAgentTurn(provider, conversation, userMessage, toolRegistry, t
|
|
|
56926
57625
|
events.onDone();
|
|
56927
57626
|
return;
|
|
56928
57627
|
}
|
|
57628
|
+
if (BOOKKEEPING_TOOLS.has(toolCall.name) && refunded < MAX_REFUNDED_STEPS) {
|
|
57629
|
+
refunded += 1;
|
|
57630
|
+
iteration -= 1;
|
|
57631
|
+
}
|
|
56929
57632
|
if (result.path !== void 0) {
|
|
56930
57633
|
if (result.isError === true) {
|
|
56931
57634
|
const count = (mistakeCounts.get(result.path) ?? 0) + 1;
|
|
@@ -58993,6 +59696,232 @@ var OfficeBridge = class {
|
|
|
58993
59696
|
}
|
|
58994
59697
|
};
|
|
58995
59698
|
|
|
59699
|
+
// ../../packages/core/dist/tools/roleTools.js
|
|
59700
|
+
var readParams = external_exports.object({
|
|
59701
|
+
role: external_exports.string().describe("Which role to read \u2014 one of the roles configured here. Omit to list them all.").optional()
|
|
59702
|
+
});
|
|
59703
|
+
function createReadRolePromptTool(access) {
|
|
59704
|
+
return {
|
|
59705
|
+
name: "read_role_prompt",
|
|
59706
|
+
group: "read",
|
|
59707
|
+
description: "Read a specialist role's current system prompt \u2014 what it is told it is. Call this before changing one, so the change is an edit to what the user wrote rather than a replacement for it. With no role, lists the roles that exist here.",
|
|
59708
|
+
parametersSchema: readParams,
|
|
59709
|
+
async execute(params) {
|
|
59710
|
+
const roles = access.list();
|
|
59711
|
+
if (params.role === void 0) {
|
|
59712
|
+
if (roles.length === 0)
|
|
59713
|
+
return { content: "No roles are configured." };
|
|
59714
|
+
return {
|
|
59715
|
+
content: roles.map((entry) => `- ${entry.role} (${entry.name})` + (entry.assigned ? "" : " \u2014 nobody assigned") + (entry.edited ? " \u2014 prompt edited" : " \u2014 default prompt")).join("\n")
|
|
59716
|
+
};
|
|
59717
|
+
}
|
|
59718
|
+
const role = params.role.trim().toLowerCase();
|
|
59719
|
+
const prompt = access.current(role);
|
|
59720
|
+
if (prompt === void 0) {
|
|
59721
|
+
return {
|
|
59722
|
+
content: `There is no "${role}" role. The roles here are: ${roles.map((entry) => entry.role).join(", ")}.`,
|
|
59723
|
+
isError: true
|
|
59724
|
+
};
|
|
59725
|
+
}
|
|
59726
|
+
const edited = roles.find((entry) => entry.role === role)?.edited === true;
|
|
59727
|
+
return {
|
|
59728
|
+
content: `The ${role}'s prompt${edited ? " (edited by the user)" : " (the default)"}:
|
|
59729
|
+
|
|
59730
|
+
${prompt}`
|
|
59731
|
+
};
|
|
59732
|
+
}
|
|
59733
|
+
};
|
|
59734
|
+
}
|
|
59735
|
+
var updateParams2 = external_exports.object({
|
|
59736
|
+
role: external_exports.string().describe("Which role to change."),
|
|
59737
|
+
prompt: external_exports.string().optional().describe("The complete new prompt. It replaces the current one rather than being added to it, so include what is staying. An empty string resets the role to its default prompt; omit it entirely to leave the prompt alone."),
|
|
59738
|
+
/*
|
|
59739
|
+
* Name and summary are editable for the same reason the prompt is: they are how the role
|
|
59740
|
+
* presents itself. The summary especially — it is the line every other specialist sees and the
|
|
59741
|
+
* one the expert allocates from, so a role whose summary is wrong gets used for the wrong work.
|
|
59742
|
+
* Only a user-defined role can change them; a built-in one is what it is.
|
|
59743
|
+
*/
|
|
59744
|
+
name: external_exports.string().optional().describe("A new display name. Custom roles only."),
|
|
59745
|
+
summary: external_exports.string().optional().describe("A new one-line summary of what it is for. Custom roles only. This is what the expert allocates from, so it matters more than the name."),
|
|
59746
|
+
usesTools: external_exports.boolean().optional().describe("Whether it may read and search the workspace. Omit to leave unchanged."),
|
|
59747
|
+
reason: external_exports.string().optional().describe("One line on what is changing and why, shown to the user above the diff.")
|
|
59748
|
+
});
|
|
59749
|
+
function createUpdateRolePromptTool(access) {
|
|
59750
|
+
return {
|
|
59751
|
+
name: "update_role",
|
|
59752
|
+
/*
|
|
59753
|
+
* `edit`, and deliberately not `always`: `decideFromPolicy` approves the `always` group
|
|
59754
|
+
* *before* it consults ALWAYS_ASK_TOOLS, so putting it there would silently auto-approve the
|
|
59755
|
+
* one thing this must always ask about. The same trap `update_plan` nearly fell into.
|
|
59756
|
+
*/
|
|
59757
|
+
group: "edit",
|
|
59758
|
+
description: 'Change a specialist role: its system prompt, and for a role the user invented, its name, its summary, or whether it may read the workspace. Use it when the user says a specialist should behave differently ("make the reviewer stricter about error handling"). Read the role first and edit what is there rather than writing a new prompt from scratch. Only what you pass is changed. The user is shown a diff and must approve it, and it applies to every future consultation of that role.',
|
|
59759
|
+
parametersSchema: updateParams2,
|
|
59760
|
+
async preview(params) {
|
|
59761
|
+
const role = params.role.trim().toLowerCase();
|
|
59762
|
+
const details = access.details(role);
|
|
59763
|
+
const before = describeRole(details, access.current(role) ?? "");
|
|
59764
|
+
const nextPrompt = params.prompt === void 0 ? access.current(role) ?? "" : (
|
|
59765
|
+
// Empty means reset, so the diff shows what the default actually says — otherwise the
|
|
59766
|
+
// approval reads as "delete this prompt" rather than "go back to the built-in one".
|
|
59767
|
+
params.prompt.trim().length === 0 ? access.fallback(role) ?? "" : params.prompt.trim()
|
|
59768
|
+
);
|
|
59769
|
+
const after = describeRole(details === void 0 ? void 0 : {
|
|
59770
|
+
...details,
|
|
59771
|
+
...params.name !== void 0 ? { name: params.name.trim() } : {},
|
|
59772
|
+
...params.summary !== void 0 ? { summary: params.summary.trim() } : {},
|
|
59773
|
+
...params.usesTools !== void 0 ? { usesTools: params.usesTools } : {}
|
|
59774
|
+
}, nextPrompt);
|
|
59775
|
+
return {
|
|
59776
|
+
kind: "diff",
|
|
59777
|
+
path: `the ${role} role`,
|
|
59778
|
+
before,
|
|
59779
|
+
after,
|
|
59780
|
+
...params.reason !== void 0 && params.reason.trim().length > 0 ? { note: params.reason.trim() } : {}
|
|
59781
|
+
};
|
|
59782
|
+
},
|
|
59783
|
+
async execute(params) {
|
|
59784
|
+
const role = params.role.trim().toLowerCase();
|
|
59785
|
+
if (access.current(role) === void 0) {
|
|
59786
|
+
return {
|
|
59787
|
+
content: `There is no "${role}" role. The roles here are: ${access.list().map((entry) => entry.role).join(", ")}.`,
|
|
59788
|
+
isError: true
|
|
59789
|
+
};
|
|
59790
|
+
}
|
|
59791
|
+
const details = access.details(role);
|
|
59792
|
+
const changingIdentity = params.name !== void 0 || params.summary !== void 0 || params.usesTools !== void 0;
|
|
59793
|
+
if (changingIdentity && details?.custom !== true) {
|
|
59794
|
+
return {
|
|
59795
|
+
content: `Only the prompt can be changed on a built-in role. "${role}" is built in, so its name, summary and workspace access are fixed. Create a role of your own if you need a different one.`,
|
|
59796
|
+
isError: true
|
|
59797
|
+
};
|
|
59798
|
+
}
|
|
59799
|
+
if (changingIdentity && details !== void 0) {
|
|
59800
|
+
await access.create({
|
|
59801
|
+
id: details.id,
|
|
59802
|
+
name: params.name?.trim() ?? details.name,
|
|
59803
|
+
summary: params.summary?.trim() ?? details.summary,
|
|
59804
|
+
// Carried over rather than re-sent: this path is about identity, and the prompt has its
|
|
59805
|
+
// own store. Passing the old one back keeps the two from disagreeing.
|
|
59806
|
+
prompt: details.prompt,
|
|
59807
|
+
usesTools: params.usesTools ?? details.usesTools
|
|
59808
|
+
});
|
|
59809
|
+
}
|
|
59810
|
+
if (params.prompt !== void 0) {
|
|
59811
|
+
const next = params.prompt.trim();
|
|
59812
|
+
await access.save(role, next.length === 0 ? void 0 : next);
|
|
59813
|
+
}
|
|
59814
|
+
return {
|
|
59815
|
+
content: `The ${role} is updated and the user approved it. Every consultation of that role from now on uses it.`
|
|
59816
|
+
};
|
|
59817
|
+
}
|
|
59818
|
+
};
|
|
59819
|
+
}
|
|
59820
|
+
var createParams2 = external_exports.object({
|
|
59821
|
+
id: external_exports.string().describe('Short id the assistant will use to reach it, e.g. "security". Lowercase letters, digits and hyphens. It cannot be changed afterwards.'),
|
|
59822
|
+
name: external_exports.string().describe('What to call it in the settings panel, e.g. "Security reviewer".'),
|
|
59823
|
+
summary: external_exports.string().describe("One line on what it is for. Every other specialist sees this, and the expert allocates from it when writing a plan \u2014 so say what it is good for, not what it is."),
|
|
59824
|
+
prompt: external_exports.string().describe("Its system prompt: what it is told it is and how to answer. What it may and may not do is added automatically, so do not write rules about tools or permissions."),
|
|
59825
|
+
usesTools: external_exports.boolean().describe("Whether it may read and search the workspace. True where the answer depends on code the asker cannot paste; false where the question carries everything it needs.")
|
|
59826
|
+
});
|
|
59827
|
+
function createCreateRoleTool(access) {
|
|
59828
|
+
return {
|
|
59829
|
+
name: "create_role",
|
|
59830
|
+
// `edit`, never `always` — see the note on `update_role_prompt`.
|
|
59831
|
+
group: "edit",
|
|
59832
|
+
description: "Create a new specialist role beyond the built-in ones, when the user wants a kind of reviewer or helper the team does not have \u2014 a security reviewer, a performance reviewer, one that knows a particular part of this codebase. A role is its prompt, so write that carefully. The user is shown the whole role and must approve it, and then assigns a model to it in Settings \u2192 Agents before it can answer.",
|
|
59833
|
+
parametersSchema: createParams2,
|
|
59834
|
+
async preview(params) {
|
|
59835
|
+
const { used, limit } = access.capacity();
|
|
59836
|
+
return {
|
|
59837
|
+
kind: "text",
|
|
59838
|
+
text: [
|
|
59839
|
+
`Create the role "${params.id.trim().toLowerCase()}" (${used + 1} of ${limit}).`,
|
|
59840
|
+
"",
|
|
59841
|
+
`Name: ${params.name}`,
|
|
59842
|
+
`For: ${params.summary}`,
|
|
59843
|
+
`Reads: ${params.usesTools ? "yes \u2014 it can read and search the workspace" : "no \u2014 it answers from the question alone"}`,
|
|
59844
|
+
"",
|
|
59845
|
+
"What it is told:",
|
|
59846
|
+
"",
|
|
59847
|
+
params.prompt.trim()
|
|
59848
|
+
].join("\n")
|
|
59849
|
+
};
|
|
59850
|
+
},
|
|
59851
|
+
async execute(params) {
|
|
59852
|
+
const id = params.id.trim().toLowerCase();
|
|
59853
|
+
if (access.current(id) !== void 0) {
|
|
59854
|
+
return {
|
|
59855
|
+
content: `There is already a "${id}" role. Change it with update_role_prompt rather than creating it again.`,
|
|
59856
|
+
isError: true
|
|
59857
|
+
};
|
|
59858
|
+
}
|
|
59859
|
+
try {
|
|
59860
|
+
await access.create({ ...params, id });
|
|
59861
|
+
} catch (error51) {
|
|
59862
|
+
return {
|
|
59863
|
+
content: error51 instanceof Error ? error51.message : String(error51),
|
|
59864
|
+
isError: true
|
|
59865
|
+
};
|
|
59866
|
+
}
|
|
59867
|
+
return {
|
|
59868
|
+
content: `The ${id} role exists and the user approved it. Nobody answers it yet \u2014 it needs a model assigned in Settings \u2192 Agents before it can be consulted. Tell the user that.`
|
|
59869
|
+
};
|
|
59870
|
+
}
|
|
59871
|
+
};
|
|
59872
|
+
}
|
|
59873
|
+
function describeRole(details, prompt) {
|
|
59874
|
+
if (details === void 0)
|
|
59875
|
+
return prompt;
|
|
59876
|
+
return [
|
|
59877
|
+
`Name: ${details.name}`,
|
|
59878
|
+
`For: ${details.summary}`,
|
|
59879
|
+
`Reads: ${details.usesTools ? "yes" : "no"}`,
|
|
59880
|
+
"",
|
|
59881
|
+
prompt
|
|
59882
|
+
].join("\n");
|
|
59883
|
+
}
|
|
59884
|
+
var deleteParams3 = external_exports.object({
|
|
59885
|
+
role: external_exports.string().describe("Which custom role to remove. Built-in roles cannot be deleted.")
|
|
59886
|
+
});
|
|
59887
|
+
function createDeleteRoleTool(access) {
|
|
59888
|
+
return {
|
|
59889
|
+
name: "delete_role",
|
|
59890
|
+
group: "edit",
|
|
59891
|
+
description: "Remove a role the user invented, along with whatever model was assigned to it. Built-in roles cannot be removed. The user is shown the role, including its prompt, and must approve. Nothing else refers to it afterwards, so any plan step naming it should be revised in the same turn.",
|
|
59892
|
+
parametersSchema: deleteParams3,
|
|
59893
|
+
async preview(params) {
|
|
59894
|
+
const role = params.role.trim().toLowerCase();
|
|
59895
|
+
const details = access.details(role);
|
|
59896
|
+
return {
|
|
59897
|
+
kind: "text",
|
|
59898
|
+
text: details === void 0 ? `There is no "${role}" role to delete.` : [
|
|
59899
|
+
`Delete the "${details.id}" role and its assignment.`,
|
|
59900
|
+
"",
|
|
59901
|
+
describeRole(details, details.prompt),
|
|
59902
|
+
"",
|
|
59903
|
+
"The prompt above is removed with it."
|
|
59904
|
+
].join("\n")
|
|
59905
|
+
};
|
|
59906
|
+
},
|
|
59907
|
+
async execute(params) {
|
|
59908
|
+
const role = params.role.trim().toLowerCase();
|
|
59909
|
+
const details = access.details(role);
|
|
59910
|
+
if (details === void 0) {
|
|
59911
|
+
return { content: `There is no "${role}" role.`, isError: true };
|
|
59912
|
+
}
|
|
59913
|
+
if (!details.custom) {
|
|
59914
|
+
return {
|
|
59915
|
+
content: `"${role}" is one of the built-in roles and cannot be deleted. Leave it unassigned if it should not be used.`,
|
|
59916
|
+
isError: true
|
|
59917
|
+
};
|
|
59918
|
+
}
|
|
59919
|
+
await access.remove(role);
|
|
59920
|
+
return { content: `The ${role} role is gone, and so is its assignment.` };
|
|
59921
|
+
}
|
|
59922
|
+
};
|
|
59923
|
+
}
|
|
59924
|
+
|
|
58996
59925
|
// ../../packages/core/dist/office/vbaCheck.js
|
|
58997
59926
|
function splitLine(line) {
|
|
58998
59927
|
let bare = "";
|
|
@@ -60173,7 +61102,94 @@ ${preview.text}` } : {}
|
|
|
60173
61102
|
const ACTIVE_TASK_KEY = "lightCode.activeTaskId";
|
|
60174
61103
|
let activeTaskId = services.workspaceState.get(ACTIVE_TASK_KEY);
|
|
60175
61104
|
let activePlan;
|
|
61105
|
+
let activePlanProgress = {};
|
|
60176
61106
|
let activeTaskCreatedAt = Date.now();
|
|
61107
|
+
function planViews() {
|
|
61108
|
+
return checkpointViews(activePlan, activePlanProgress);
|
|
61109
|
+
}
|
|
61110
|
+
function postPlanProgress() {
|
|
61111
|
+
post({ type: "planProgress", checkpoints: planViews() });
|
|
61112
|
+
}
|
|
61113
|
+
async function applyPlan(next) {
|
|
61114
|
+
const trimmed = next?.slice(0, PLAN_LIMIT).trim();
|
|
61115
|
+
activePlan = trimmed !== void 0 && trimmed.length > 0 ? trimmed : void 0;
|
|
61116
|
+
activePlanProgress = pruneProgress(activePlan, activePlanProgress);
|
|
61117
|
+
await persistActiveTask();
|
|
61118
|
+
post({ type: "plan", plan: activePlan ?? "" });
|
|
61119
|
+
postPlanProgress();
|
|
61120
|
+
}
|
|
61121
|
+
const rolePromptAccess = {
|
|
61122
|
+
list: () => knownRoles(cachedAgentDefinitions).map((role) => ({
|
|
61123
|
+
role,
|
|
61124
|
+
name: roleInfo(role, cachedAgentDefinitions).name,
|
|
61125
|
+
assigned: cachedTeam.some((agent) => agent.role === role),
|
|
61126
|
+
edited: cachedAgentRoles?.[role]?.prompt !== void 0
|
|
61127
|
+
})),
|
|
61128
|
+
current: (role) => {
|
|
61129
|
+
if (!isAgentRole(role, cachedAgentDefinitions))
|
|
61130
|
+
return void 0;
|
|
61131
|
+
return cachedAgentRoles?.[role]?.prompt ?? defaultPromptFor(role, cachedAgentDefinitions);
|
|
61132
|
+
},
|
|
61133
|
+
fallback: (role) => isAgentRole(role, cachedAgentDefinitions) ? defaultPromptFor(role, cachedAgentDefinitions) : void 0,
|
|
61134
|
+
details: (role) => {
|
|
61135
|
+
if (!isAgentRole(role, cachedAgentDefinitions))
|
|
61136
|
+
return void 0;
|
|
61137
|
+
const info = roleInfo(role, cachedAgentDefinitions);
|
|
61138
|
+
return {
|
|
61139
|
+
id: role,
|
|
61140
|
+
name: info.name,
|
|
61141
|
+
summary: info.summary,
|
|
61142
|
+
prompt: cachedAgentRoles?.[role]?.prompt ?? info.prompt,
|
|
61143
|
+
usesTools: cachedAgentRoles?.[role]?.tools ?? info.usesTools,
|
|
61144
|
+
custom: cachedAgentDefinitions.some((definition) => definition.id === role)
|
|
61145
|
+
};
|
|
61146
|
+
},
|
|
61147
|
+
remove: async (role) => {
|
|
61148
|
+
await handleDeleteCustomRole(role);
|
|
61149
|
+
},
|
|
61150
|
+
create: async (role) => {
|
|
61151
|
+
await handleSaveCustomRole(role);
|
|
61152
|
+
},
|
|
61153
|
+
capacity: () => ({ used: cachedAgentDefinitions.length, limit: CUSTOM_ROLE_LIMIT }),
|
|
61154
|
+
save: async (role, prompt) => {
|
|
61155
|
+
await saveAgents((current) => {
|
|
61156
|
+
const roles = { ...current.roles ?? {} };
|
|
61157
|
+
const existing = roles[role] ?? { kind: "profile" };
|
|
61158
|
+
if (prompt === void 0) {
|
|
61159
|
+
const rest = { ...existing };
|
|
61160
|
+
delete rest.prompt;
|
|
61161
|
+
roles[role] = rest;
|
|
61162
|
+
} else {
|
|
61163
|
+
roles[role] = { ...existing, prompt };
|
|
61164
|
+
}
|
|
61165
|
+
return { ...current, roles };
|
|
61166
|
+
});
|
|
61167
|
+
}
|
|
61168
|
+
};
|
|
61169
|
+
const planAccess = {
|
|
61170
|
+
current: () => activePlan,
|
|
61171
|
+
save: async (nextPlan) => {
|
|
61172
|
+
await applyPlan(nextPlan);
|
|
61173
|
+
},
|
|
61174
|
+
mark: async (index, status) => {
|
|
61175
|
+
const updated = markCheckpoint(activePlan, activePlanProgress, index, status);
|
|
61176
|
+
if (updated === void 0) {
|
|
61177
|
+
const total = planViews().length;
|
|
61178
|
+
return {
|
|
61179
|
+
ok: false,
|
|
61180
|
+
reason: total === 0 ? "There is no plan set for this conversation, so there is nothing to report against." : `There is no step ${String(index)}. The plan has ${String(total)} steps, numbered 1 to ${String(total)}.`
|
|
61181
|
+
};
|
|
61182
|
+
}
|
|
61183
|
+
activePlanProgress = updated;
|
|
61184
|
+
await persistActiveTask();
|
|
61185
|
+
postPlanProgress();
|
|
61186
|
+
const views = planViews();
|
|
61187
|
+
return {
|
|
61188
|
+
ok: true,
|
|
61189
|
+
summary: `Step ${String(index)} is now ${status}. ${progressSummary(views)} steps complete.`
|
|
61190
|
+
};
|
|
61191
|
+
}
|
|
61192
|
+
};
|
|
60177
61193
|
async function setActiveTaskId(id) {
|
|
60178
61194
|
activeTaskId = id;
|
|
60179
61195
|
await services.workspaceState.set(ACTIVE_TASK_KEY, id);
|
|
@@ -60417,6 +61433,8 @@ ${preview.text}` } : {}
|
|
|
60417
61433
|
let cachedCodeGenerator;
|
|
60418
61434
|
let cachedTeam = [];
|
|
60419
61435
|
let cachedTeamGuidance;
|
|
61436
|
+
let cachedAgentRoles;
|
|
61437
|
+
let cachedAgentDefinitions = [];
|
|
60420
61438
|
let cachedBudgetMatters = false;
|
|
60421
61439
|
let cachedMentionExcludes;
|
|
60422
61440
|
let cachedReportsCost;
|
|
@@ -60467,6 +61485,8 @@ ${preview.text}` } : {}
|
|
|
60467
61485
|
cliAvailable: expertCli?.available === true
|
|
60468
61486
|
};
|
|
60469
61487
|
cachedTeam = resolveTeam(teamContext);
|
|
61488
|
+
cachedAgentRoles = config2.agents?.roles;
|
|
61489
|
+
cachedAgentDefinitions = config2.agents?.definitions ?? [];
|
|
60470
61490
|
cachedTeamGuidance = config2.agents?.teamGuidance;
|
|
60471
61491
|
cachedBudgetMatters = budgetMatters(teamContext);
|
|
60472
61492
|
cachedProgrammingProfileId = config2.programmingProfileId;
|
|
@@ -60618,6 +61638,12 @@ ${preview.text}` } : {}
|
|
|
60618
61638
|
}
|
|
60619
61639
|
for (const tool of python.generatedTools())
|
|
60620
61640
|
combined.register(tool, { dispatchOnly: dispatcher });
|
|
61641
|
+
combined.register(createUpdatePlanTool(planAccess), { dispatchOnly: dispatcher });
|
|
61642
|
+
combined.register(createPlanProgressTool(planAccess), { dispatchOnly: dispatcher });
|
|
61643
|
+
combined.register(createReadRolePromptTool(rolePromptAccess), { dispatchOnly: dispatcher });
|
|
61644
|
+
combined.register(createUpdateRolePromptTool(rolePromptAccess), { dispatchOnly: dispatcher });
|
|
61645
|
+
combined.register(createCreateRoleTool(rolePromptAccess), { dispatchOnly: dispatcher });
|
|
61646
|
+
combined.register(createDeleteRoleTool(rolePromptAccess), { dispatchOnly: dispatcher });
|
|
60621
61647
|
combined.register(createNotifyTool({
|
|
60622
61648
|
notify: (message3, level, details) => {
|
|
60623
61649
|
if (details !== void 0) {
|
|
@@ -60892,7 +61918,8 @@ ${preview.text}` } : {}
|
|
|
60892
61918
|
updatedAt: Date.now(),
|
|
60893
61919
|
messages,
|
|
60894
61920
|
resultHandles: truncationStore.spilledHandles(),
|
|
60895
|
-
...activePlan !== void 0 && activePlan.trim().length > 0 ? { plan: activePlan } : {}
|
|
61921
|
+
...activePlan !== void 0 && activePlan.trim().length > 0 ? { plan: activePlan } : {},
|
|
61922
|
+
...Object.keys(activePlanProgress).length > 0 ? { planProgress: activePlanProgress } : {}
|
|
60896
61923
|
};
|
|
60897
61924
|
try {
|
|
60898
61925
|
await taskStore.save(redactTask(task, await knownSecretValues()));
|
|
@@ -60921,9 +61948,11 @@ ${preview.text}` } : {}
|
|
|
60921
61948
|
activeTaskCreatedAt = task.createdAt;
|
|
60922
61949
|
truncationStore.startTask(task.resultHandles);
|
|
60923
61950
|
activePlan = task.plan;
|
|
61951
|
+
activePlanProgress = pruneProgress(activePlan, task.planProgress);
|
|
60924
61952
|
await setActiveTaskId(task.id);
|
|
60925
61953
|
post({ type: "taskRestored", taskId: task.id, entries: toTranscript(task.messages) });
|
|
60926
61954
|
post({ type: "plan", plan: activePlan ?? "" });
|
|
61955
|
+
postPlanProgress();
|
|
60927
61956
|
await postTasks();
|
|
60928
61957
|
}
|
|
60929
61958
|
async function startNewTask() {
|
|
@@ -60934,9 +61963,11 @@ ${preview.text}` } : {}
|
|
|
60934
61963
|
activeTaskCreatedAt = Date.now();
|
|
60935
61964
|
truncationStore.startTask();
|
|
60936
61965
|
activePlan = void 0;
|
|
61966
|
+
activePlanProgress = {};
|
|
60937
61967
|
await setActiveTaskId(void 0);
|
|
60938
61968
|
post({ type: "taskRestored", taskId: void 0, entries: [] });
|
|
60939
61969
|
post({ type: "plan", plan: "" });
|
|
61970
|
+
postPlanProgress();
|
|
60940
61971
|
await postTasks();
|
|
60941
61972
|
}
|
|
60942
61973
|
async function deleteTask(id) {
|
|
@@ -61041,7 +62072,20 @@ ${preview.text}` } : {}
|
|
|
61041
62072
|
...(() => {
|
|
61042
62073
|
const parts = [];
|
|
61043
62074
|
if (activeMode.id === AGENT_TEAM_MODE.id) {
|
|
61044
|
-
parts.push(buildTeamGuidance(
|
|
62075
|
+
parts.push(buildTeamGuidance(
|
|
62076
|
+
// The whole team, not only the available ones: the roster names what is missing
|
|
62077
|
+
// as well as what is there, and it cannot do that from a pre-filtered list.
|
|
62078
|
+
cachedTeam,
|
|
62079
|
+
cachedTeamGuidance,
|
|
62080
|
+
cachedBudgetMatters,
|
|
62081
|
+
/*
|
|
62082
|
+
* Whether a plan already exists, which decides whether this mode is told to go
|
|
62083
|
+
* and make one. Passed rather than inferred from the prompt: the plan section is
|
|
62084
|
+
* assembled separately, and a mode guessing at whether it is there would be a
|
|
62085
|
+
* second reading of the same fact.
|
|
62086
|
+
*/
|
|
62087
|
+
activePlan !== void 0 && activePlan.trim().length > 0
|
|
62088
|
+
));
|
|
61045
62089
|
} else if (activeMode.guidance !== void 0 && (activeMode.requiresExpert !== true || expertCliInfo !== void 0)) {
|
|
61046
62090
|
parts.push(activeMode.guidance);
|
|
61047
62091
|
}
|
|
@@ -61215,8 +62259,14 @@ ${preview.text}` } : {}
|
|
|
61215
62259
|
cumulativeText = "";
|
|
61216
62260
|
cumulativeReasoning = "";
|
|
61217
62261
|
const consulting = consultationFromToolCall(toolCall.name, toolCall.arguments);
|
|
61218
|
-
if (consulting !== void 0)
|
|
62262
|
+
if (consulting !== void 0) {
|
|
61219
62263
|
informedBy = consulting;
|
|
62264
|
+
const attributed = attributeConsultation(activePlanProgress, consulting);
|
|
62265
|
+
if (attributed !== activePlanProgress) {
|
|
62266
|
+
activePlanProgress = attributed;
|
|
62267
|
+
postPlanProgress();
|
|
62268
|
+
}
|
|
62269
|
+
}
|
|
61220
62270
|
if (CONTROL_TOOLS.has(toolCall.name))
|
|
61221
62271
|
return;
|
|
61222
62272
|
if (chartFromToolCall(toolCall.name, toolCall.arguments) !== void 0)
|
|
@@ -61338,7 +62388,7 @@ ${preview.text}` } : {}
|
|
|
61338
62388
|
}
|
|
61339
62389
|
if (input.authType === "none")
|
|
61340
62390
|
return { type: "none" };
|
|
61341
|
-
const typed = input.apiKey.trim();
|
|
62391
|
+
const typed = (input.apiKey ?? "").trim();
|
|
61342
62392
|
if (describeSecretRef(typed).kind === "env") {
|
|
61343
62393
|
await secrets.delete(apiKeyRefFor(id));
|
|
61344
62394
|
return { type: "apiKey", apiKeyRef: typed };
|
|
@@ -61492,6 +62542,19 @@ ${preview.text}` } : {}
|
|
|
61492
62542
|
}
|
|
61493
62543
|
}
|
|
61494
62544
|
async function profileFromForm(input) {
|
|
62545
|
+
const fieldErrors = validateProviderForm({
|
|
62546
|
+
label: input.label,
|
|
62547
|
+
wireFormat: input.wireFormat,
|
|
62548
|
+
baseUrl: input.baseUrl,
|
|
62549
|
+
model: input.model
|
|
62550
|
+
});
|
|
62551
|
+
if (fieldErrors.length > 0) {
|
|
62552
|
+
post({
|
|
62553
|
+
type: "error",
|
|
62554
|
+
message: fieldErrors.map((issue2) => `${issue2.path}: ${issue2.message}`).join("; ")
|
|
62555
|
+
});
|
|
62556
|
+
return void 0;
|
|
62557
|
+
}
|
|
61495
62558
|
const baseUrl = input.baseUrl.trim();
|
|
61496
62559
|
if (baseUrl.length === 0) {
|
|
61497
62560
|
post({ type: "error", message: "Enter a base URL first." });
|
|
@@ -61576,7 +62639,9 @@ ${preview.text}` } : {}
|
|
|
61576
62639
|
cliAvailable: cli?.available === true
|
|
61577
62640
|
};
|
|
61578
62641
|
const assigned = new Map(resolveTeam(teamContext).map((agent) => [agent.role, agent]));
|
|
61579
|
-
const
|
|
62642
|
+
const definitions = config2.agents?.definitions ?? [];
|
|
62643
|
+
const customIds = new Set(definitions.map((definition) => definition.id));
|
|
62644
|
+
const roles = allRoles(definitions).map((info) => {
|
|
61580
62645
|
const agent = assigned.get(info.role);
|
|
61581
62646
|
const prompt = config2.agents?.roles?.[info.role]?.prompt;
|
|
61582
62647
|
return {
|
|
@@ -61588,8 +62653,14 @@ ${preview.text}` } : {}
|
|
|
61588
62653
|
label: agent?.label ?? "Nobody",
|
|
61589
62654
|
available: agent?.available ?? false,
|
|
61590
62655
|
...agent?.reason !== void 0 ? { reason: agent.reason } : {},
|
|
61591
|
-
prompt: prompt ?? defaultPromptFor(info.role),
|
|
61592
|
-
promptIsDefault: prompt === void 0
|
|
62656
|
+
prompt: prompt ?? defaultPromptFor(info.role, definitions),
|
|
62657
|
+
promptIsDefault: prompt === void 0,
|
|
62658
|
+
...customIds.has(info.role) ? { custom: true } : {},
|
|
62659
|
+
// The assignment's override where there is one, else the role's own default — the same
|
|
62660
|
+
// resolution `resolveTeam` does, so the switch in the tab shows what will actually happen.
|
|
62661
|
+
usesTools: config2.agents?.roles?.[info.role]?.tools ?? info.usesTools,
|
|
62662
|
+
canWrite: config2.agents?.roles?.[info.role]?.write ?? info.canWrite,
|
|
62663
|
+
enabled: config2.agents?.roles?.[info.role]?.enabled !== false
|
|
61593
62664
|
};
|
|
61594
62665
|
});
|
|
61595
62666
|
const guidance = config2.agents?.teamGuidance;
|
|
@@ -61618,6 +62689,51 @@ ${preview.text}` } : {}
|
|
|
61618
62689
|
}
|
|
61619
62690
|
});
|
|
61620
62691
|
}
|
|
62692
|
+
async function handleSaveCustomRole(role) {
|
|
62693
|
+
const id = role.id.trim().toLowerCase();
|
|
62694
|
+
if (!isValidRoleId(id)) {
|
|
62695
|
+
post({
|
|
62696
|
+
type: "error",
|
|
62697
|
+
message: `"${id}" is not a usable role id. Use lowercase letters, digits and hyphens, starting with a letter, and not the name of a built-in role.`
|
|
62698
|
+
});
|
|
62699
|
+
return;
|
|
62700
|
+
}
|
|
62701
|
+
if (role.name.trim().length === 0) {
|
|
62702
|
+
post({ type: "error", message: "A role needs a name." });
|
|
62703
|
+
return;
|
|
62704
|
+
}
|
|
62705
|
+
await saveAgents((current) => {
|
|
62706
|
+
const definitions = [...current.definitions ?? []];
|
|
62707
|
+
const at = definitions.findIndex((candidate) => candidate.id === id);
|
|
62708
|
+
const next = {
|
|
62709
|
+
id,
|
|
62710
|
+
name: role.name.trim(),
|
|
62711
|
+
summary: role.summary.trim(),
|
|
62712
|
+
prompt: role.prompt.trim(),
|
|
62713
|
+
usesTools: role.usesTools,
|
|
62714
|
+
canWrite: role.canWrite === true
|
|
62715
|
+
};
|
|
62716
|
+
if (at === -1) {
|
|
62717
|
+
if (definitions.length >= CUSTOM_ROLE_LIMIT) {
|
|
62718
|
+
throw new Error(`That would be ${String(definitions.length + 1)} custom roles. The limit is ${String(CUSTOM_ROLE_LIMIT)}: the expert allocates from this list, and its judgement is what a longer one costs.`);
|
|
62719
|
+
}
|
|
62720
|
+
definitions.push(next);
|
|
62721
|
+
} else
|
|
62722
|
+
definitions[at] = next;
|
|
62723
|
+
return { ...current, definitions };
|
|
62724
|
+
});
|
|
62725
|
+
}
|
|
62726
|
+
async function handleDeleteCustomRole(id) {
|
|
62727
|
+
await saveAgents((current) => {
|
|
62728
|
+
const roles = { ...current.roles ?? {} };
|
|
62729
|
+
delete roles[id];
|
|
62730
|
+
return {
|
|
62731
|
+
...current,
|
|
62732
|
+
roles,
|
|
62733
|
+
definitions: (current.definitions ?? []).filter((candidate) => candidate.id !== id)
|
|
62734
|
+
};
|
|
62735
|
+
});
|
|
62736
|
+
}
|
|
61621
62737
|
async function saveAgents(change) {
|
|
61622
62738
|
try {
|
|
61623
62739
|
const { config: config2 } = await configManager.load();
|
|
@@ -63645,6 +64761,11 @@ ${preview.text}` } : {}
|
|
|
63645
64761
|
const prompt = buildAgentPrompt({
|
|
63646
64762
|
prompt: agent.prompt,
|
|
63647
64763
|
question: request.question,
|
|
64764
|
+
// Decides the preamble as well as whether tools are offered below, so the two can never
|
|
64765
|
+
// disagree — a specialist told it can read, and then given nothing to read with, wastes a
|
|
64766
|
+
// step discovering that.
|
|
64767
|
+
usesTools: agent.usesTools,
|
|
64768
|
+
canWrite: agent.canWrite,
|
|
63648
64769
|
...request.files !== void 0 ? { files: request.files } : {},
|
|
63649
64770
|
/*
|
|
63650
64771
|
* What exists in this workspace.
|
|
@@ -63655,13 +64776,29 @@ ${preview.text}` } : {}
|
|
|
63655
64776
|
*/
|
|
63656
64777
|
briefing: buildAgentBriefing({
|
|
63657
64778
|
tools: agentBriefingTools?.() ?? [],
|
|
63658
|
-
skills
|
|
64779
|
+
skills,
|
|
64780
|
+
/*
|
|
64781
|
+
* Who else exists, so a plan cannot name a specialist nobody set up.
|
|
64782
|
+
*
|
|
64783
|
+
* Built here, above the `kind` branch, which is the point: the Claude CLI expert and a
|
|
64784
|
+
* provider-profile expert are given byte-identical briefings, so making a different model
|
|
64785
|
+
* the expert cannot change what it knows about the team. `briefing.test.ts` pins that,
|
|
64786
|
+
* because the two paths diverging is invisible until somebody switches expert and gets a
|
|
64787
|
+
* worse plan for no reason they could name.
|
|
64788
|
+
*/
|
|
64789
|
+
team: cachedTeam,
|
|
64790
|
+
self: agent.role
|
|
63659
64791
|
})
|
|
63660
64792
|
});
|
|
63661
64793
|
if (agent.kind === "cli") {
|
|
63662
64794
|
const cli = expertCli;
|
|
63663
64795
|
if (cli === void 0 || !cli.available)
|
|
63664
64796
|
throw new Error("The Claude CLI is not available.");
|
|
64797
|
+
if (cachedBudgetMatters) {
|
|
64798
|
+
const verdict = checkExpertBudget(expertSpend, effectiveExpertLimits());
|
|
64799
|
+
if (!verdict.allowed)
|
|
64800
|
+
throw new Error(verdict.message);
|
|
64801
|
+
}
|
|
63665
64802
|
const answer = await consultExpert(cli, {
|
|
63666
64803
|
question: prompt,
|
|
63667
64804
|
/*
|
|
@@ -63672,6 +64809,10 @@ ${preview.text}` } : {}
|
|
|
63672
64809
|
cwd: workspaceRoot ?? process.cwd(),
|
|
63673
64810
|
...request.signal !== void 0 ? { signal: request.signal } : {}
|
|
63674
64811
|
});
|
|
64812
|
+
recordConsultation({
|
|
64813
|
+
isError: answer.isError,
|
|
64814
|
+
...answer.costUsd !== void 0 ? { costUsd: answer.costUsd } : {}
|
|
64815
|
+
});
|
|
63675
64816
|
if (answer.isError)
|
|
63676
64817
|
throw new Error(answer.text);
|
|
63677
64818
|
return { advice: answer.text, label: agent.label };
|
|
@@ -63682,7 +64823,13 @@ ${preview.text}` } : {}
|
|
|
63682
64823
|
throw new Error(`No profile "${agent.profileId ?? ""}" exists any more.`);
|
|
63683
64824
|
}
|
|
63684
64825
|
const provider = createChatProvider(profile, httpClient, authStrategyFor(config2, profile), logger);
|
|
63685
|
-
const
|
|
64826
|
+
const extraTools = new Set(agent.role === "librarian" ? ["write_skill"] : []);
|
|
64827
|
+
if (agent.canWrite) {
|
|
64828
|
+
extraTools.add("write_to_file");
|
|
64829
|
+
extraTools.add("apply_diff");
|
|
64830
|
+
extraTools.add("write_skill");
|
|
64831
|
+
}
|
|
64832
|
+
const readOnly = agent.usesTools ? toolsForConsultation(agentBriefingTools?.() ?? [], extraTools) : [];
|
|
63686
64833
|
const context = consultationContext?.();
|
|
63687
64834
|
const result = await runConsultation({
|
|
63688
64835
|
provider,
|
|
@@ -63692,6 +64839,24 @@ ${preview.text}` } : {}
|
|
|
63692
64839
|
// With no context there is nothing to read *with*, so it answers from the question alone
|
|
63693
64840
|
// rather than being offered tools that would fail.
|
|
63694
64841
|
context: context ?? {},
|
|
64842
|
+
/*
|
|
64843
|
+
* The same gate the agent loop uses, so an approval raised by a specialist is
|
|
64844
|
+
* indistinguishable from one raised by the assistant — same prompt, same ground truth, same
|
|
64845
|
+
* always-ask rule. A second approval path would be a second place for the rule to be wrong.
|
|
64846
|
+
*/
|
|
64847
|
+
approve: async (tool, args) => {
|
|
64848
|
+
const preview = await tool.preview?.(args, context ?? {}).catch(() => void 0);
|
|
64849
|
+
const decision = await approvalGate.requestApproval({
|
|
64850
|
+
id: `agent-${agent.role}-${String(Date.now())}-${tool.name}`,
|
|
64851
|
+
toolName: tool.name,
|
|
64852
|
+
group: tool.group,
|
|
64853
|
+
preview: preview ?? {
|
|
64854
|
+
kind: "text",
|
|
64855
|
+
text: `The ${agent.role} wants to run ${tool.name}.`
|
|
64856
|
+
}
|
|
64857
|
+
});
|
|
64858
|
+
return decision === "approve";
|
|
64859
|
+
},
|
|
63695
64860
|
...request.signal !== void 0 ? { signal: request.signal } : {},
|
|
63696
64861
|
onStep: (name) => logger.info(`${agent.role} looked up ${name}`)
|
|
63697
64862
|
});
|
|
@@ -64444,18 +65609,18 @@ ${preview.text}` } : {}
|
|
|
64444
65609
|
} else if (message3.type === "requestExpert") {
|
|
64445
65610
|
void postExpert();
|
|
64446
65611
|
} else if (message3.type === "setPlan") {
|
|
64447
|
-
|
|
64448
|
-
activePlan = plan.length > 0 ? plan : void 0;
|
|
64449
|
-
void persistActiveTask();
|
|
64450
|
-
post({ type: "plan", plan: activePlan ?? "" });
|
|
65612
|
+
void applyPlan(message3.plan);
|
|
64451
65613
|
} else if (message3.type === "requestPlan") {
|
|
64452
65614
|
post({ type: "plan", plan: activePlan ?? "" });
|
|
65615
|
+
postPlanProgress();
|
|
65616
|
+
} else if (message3.type === "requestPlanProgress") {
|
|
65617
|
+
postPlanProgress();
|
|
64453
65618
|
} else if (message3.type === "requestAgents") {
|
|
64454
65619
|
void postAgents();
|
|
64455
65620
|
} else if (message3.type === "setAgentRole") {
|
|
64456
65621
|
const assignment = message3.assignment;
|
|
64457
65622
|
const role = message3.role;
|
|
64458
|
-
if (!isAgentRole(role)) {
|
|
65623
|
+
if (!isAgentRole(role, cachedAgentDefinitions)) {
|
|
64459
65624
|
post({ type: "error", message: `There is no "${role}" role.` });
|
|
64460
65625
|
return;
|
|
64461
65626
|
}
|
|
@@ -64475,7 +65640,7 @@ ${preview.text}` } : {}
|
|
|
64475
65640
|
} else if (message3.type === "setAgentPrompt") {
|
|
64476
65641
|
const role = message3.role;
|
|
64477
65642
|
const prompt = message3.prompt;
|
|
64478
|
-
if (!isAgentRole(role)) {
|
|
65643
|
+
if (!isAgentRole(role, cachedAgentDefinitions)) {
|
|
64479
65644
|
post({ type: "error", message: `There is no "${role}" role.` });
|
|
64480
65645
|
return;
|
|
64481
65646
|
}
|
|
@@ -64506,10 +65671,50 @@ ${preview.text}` } : {}
|
|
|
64506
65671
|
}
|
|
64507
65672
|
return { ...current, teamGuidance: guidance };
|
|
64508
65673
|
});
|
|
65674
|
+
} else if (message3.type === "saveCustomRole") {
|
|
65675
|
+
void handleSaveCustomRole(message3);
|
|
65676
|
+
} else if (message3.type === "deleteCustomRole") {
|
|
65677
|
+
void handleDeleteCustomRole(message3.id);
|
|
65678
|
+
} else if (message3.type === "setRoleEnabled") {
|
|
65679
|
+
const role = message3.role;
|
|
65680
|
+
if (!isAgentRole(role, cachedAgentDefinitions)) {
|
|
65681
|
+
post({ type: "error", message: `There is no "${role}" role.` });
|
|
65682
|
+
return;
|
|
65683
|
+
}
|
|
65684
|
+
void saveAgents((current) => {
|
|
65685
|
+
const roles = { ...current.roles ?? {} };
|
|
65686
|
+
roles[role] = {
|
|
65687
|
+
...roles[role] ?? { kind: "profile" },
|
|
65688
|
+
enabled: message3.enabled
|
|
65689
|
+
};
|
|
65690
|
+
return { ...current, roles };
|
|
65691
|
+
});
|
|
65692
|
+
} else if (message3.type === "setRoleWrite") {
|
|
65693
|
+
const role = message3.role;
|
|
65694
|
+
if (!isAgentRole(role, cachedAgentDefinitions)) {
|
|
65695
|
+
post({ type: "error", message: `There is no "${role}" role.` });
|
|
65696
|
+
return;
|
|
65697
|
+
}
|
|
65698
|
+
void saveAgents((current) => {
|
|
65699
|
+
const roles = { ...current.roles ?? {} };
|
|
65700
|
+
roles[role] = { ...roles[role] ?? { kind: "profile" }, write: message3.canWrite };
|
|
65701
|
+
return { ...current, roles };
|
|
65702
|
+
});
|
|
65703
|
+
} else if (message3.type === "setRoleTools") {
|
|
65704
|
+
const role = message3.role;
|
|
65705
|
+
if (!isAgentRole(role, cachedAgentDefinitions)) {
|
|
65706
|
+
post({ type: "error", message: `There is no "${role}" role.` });
|
|
65707
|
+
return;
|
|
65708
|
+
}
|
|
65709
|
+
void saveAgents((current) => {
|
|
65710
|
+
const roles = { ...current.roles ?? {} };
|
|
65711
|
+
roles[role] = { ...roles[role] ?? { kind: "profile" }, tools: message3.usesTools };
|
|
65712
|
+
return { ...current, roles };
|
|
65713
|
+
});
|
|
64509
65714
|
} else if (message3.type === "setAgentColor") {
|
|
64510
65715
|
const role = message3.role;
|
|
64511
65716
|
const color = message3.color;
|
|
64512
|
-
if (!isAgentRole(role)) {
|
|
65717
|
+
if (!isAgentRole(role, cachedAgentDefinitions)) {
|
|
64513
65718
|
post({ type: "error", message: `There is no "${role}" role.` });
|
|
64514
65719
|
return;
|
|
64515
65720
|
}
|