@chosengeneration/light-code 0.59.0 → 0.59.6
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 +93 -21
- package/dist/client/client.js +37 -37
- package/dist/server.js +92 -20
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -42096,9 +42096,19 @@ async function listModels(http, profile, auth2, signal) {
|
|
|
42096
42096
|
function messageOf(error51) {
|
|
42097
42097
|
return error51 instanceof Error ? error51.message : String(error51);
|
|
42098
42098
|
}
|
|
42099
|
+
var TEST_CONNECTION_TIMEOUT_MS = 2e4;
|
|
42099
42100
|
async function testConnection(profile, context, http, signal) {
|
|
42100
42101
|
const steps = [];
|
|
42101
42102
|
const finish = () => ({ ok: steps.every((step) => step.status !== "failed"), steps });
|
|
42103
|
+
const deadline = new AbortController();
|
|
42104
|
+
const timer = setTimeout(() => deadline.abort(), TEST_CONNECTION_TIMEOUT_MS);
|
|
42105
|
+
const onOuterAbort = () => deadline.abort();
|
|
42106
|
+
signal?.addEventListener("abort", onOuterAbort);
|
|
42107
|
+
const bounded = deadline.signal;
|
|
42108
|
+
const release = () => {
|
|
42109
|
+
clearTimeout(timer);
|
|
42110
|
+
signal?.removeEventListener("abort", onOuterAbort);
|
|
42111
|
+
};
|
|
42102
42112
|
if (profile.auth.type === "apigeeMtls") {
|
|
42103
42113
|
try {
|
|
42104
42114
|
let expiryNote = "";
|
|
@@ -42115,6 +42125,7 @@ async function testConnection(profile, context, http, signal) {
|
|
|
42115
42125
|
detail: `Loaded ${loaded?.pfx !== void 0 ? "PFX bundle" : "client certificate and key"}.${expiryNote}`
|
|
42116
42126
|
});
|
|
42117
42127
|
} catch (error51) {
|
|
42128
|
+
release();
|
|
42118
42129
|
steps.push({ step: "certificates", status: "failed", detail: messageOf(error51) });
|
|
42119
42130
|
steps.push({ step: "token", status: "skipped", detail: "Not attempted \u2014 certificates failed to load." });
|
|
42120
42131
|
steps.push({ step: "models", status: "skipped", detail: "Not attempted \u2014 certificates failed to load." });
|
|
@@ -42146,16 +42157,28 @@ async function testConnection(profile, context, http, signal) {
|
|
|
42146
42157
|
detail: profile.auth.type === "tokenCommand" ? "The token command ran and returned a token." : profile.auth.type === "apiKey" && profile.auth.apiKeyRef.startsWith("env:") ? `Key read from ${profile.auth.apiKeyRef.slice("env:".length)}.` : "Credential resolved from secure storage."
|
|
42147
42158
|
});
|
|
42148
42159
|
} catch (error51) {
|
|
42160
|
+
release();
|
|
42149
42161
|
steps.push({ step: "token", status: "failed", detail: messageOf(error51) });
|
|
42150
42162
|
steps.push({ step: "models", status: "skipped", detail: "Not attempted \u2014 no credential." });
|
|
42151
42163
|
return finish();
|
|
42152
42164
|
}
|
|
42153
42165
|
}
|
|
42154
|
-
const result = await listModels(http, profile, auth2,
|
|
42166
|
+
const result = await listModels(http, profile, auth2, bounded);
|
|
42167
|
+
release();
|
|
42155
42168
|
if (result.ids.length > 0) {
|
|
42156
42169
|
steps.push({ step: "models", status: "ok", detail: `Gateway returned ${result.ids.length} model(s).` });
|
|
42170
|
+
} else if (deadline.signal.aborted && signal?.aborted !== true) {
|
|
42171
|
+
steps.push({
|
|
42172
|
+
step: "models",
|
|
42173
|
+
status: "failed",
|
|
42174
|
+
detail: `No response within ${String(Math.round(TEST_CONNECTION_TIMEOUT_MS / 1e3))}s. The address resolved and the connection was accepted, but nothing came back \u2014 check the base URL path and whether anything is filtering this route.`
|
|
42175
|
+
});
|
|
42157
42176
|
} else {
|
|
42158
|
-
steps.push({
|
|
42177
|
+
steps.push({
|
|
42178
|
+
step: "models",
|
|
42179
|
+
status: "note",
|
|
42180
|
+
detail: `${result.warning ?? "No catalogue returned."} This does not by itself mean the connection is broken \u2014 plenty of gateways serve chat completions without publishing /models. Type the model id by hand.`
|
|
42181
|
+
});
|
|
42159
42182
|
}
|
|
42160
42183
|
return finish();
|
|
42161
42184
|
}
|
|
@@ -43882,7 +43905,24 @@ function buildSystemPrompt(workspaceRoot, options = {}) {
|
|
|
43882
43905
|
' write it for them \u2014 "checking which gateway the profile points at", not "reading a file".',
|
|
43883
43906
|
"- Paths are relative to the workspace root. You cannot access anything outside it.",
|
|
43884
43907
|
"- When the task is complete, call attempt_completion with a summary of what you did.",
|
|
43885
|
-
"- If you need information only the user can provide, call ask_followup_question."
|
|
43908
|
+
"- If you need information only the user can provide, call ask_followup_question.",
|
|
43909
|
+
/*
|
|
43910
|
+
* Asked for directly, from real use with a model whose training predates the libraries in
|
|
43911
|
+
* front of it. The failure it addresses is not refusing to answer - it is answering anyway,
|
|
43912
|
+
* from a remembered version of an API, which produces code that looks right and is wrong
|
|
43913
|
+
* against the installed version. The user very often has the page open.
|
|
43914
|
+
*
|
|
43915
|
+
* Phrased as a thing to do rather than a permission, because a model that is unsure is
|
|
43916
|
+
* already reluctant to interrupt, and "you may ask" reads as "prefer not to".
|
|
43917
|
+
*/
|
|
43918
|
+
"- **If a library or API is unfamiliar, or the version here does not match what you remember,",
|
|
43919
|
+
" ask the user for documentation rather than guessing.** Say which library and what you need",
|
|
43920
|
+
" to know - a signature, which module something moved to, whether a call is still supported.",
|
|
43921
|
+
" They can paste it, point you at a file or a URL they have already fetched, or tell you the",
|
|
43922
|
+
" house convention. Recalling an API from a version you were trained on produces code that",
|
|
43923
|
+
" looks correct and fails against the one installed, which is far more expensive than asking.",
|
|
43924
|
+
"- Before asking, check what is here: the imports and existing calls in this workspace are",
|
|
43925
|
+
" evidence about the version actually installed, and a skill may already describe it."
|
|
43886
43926
|
);
|
|
43887
43927
|
if (options.skills !== void 0 && options.skills.length > 0) {
|
|
43888
43928
|
lines.push("", options.skills);
|
|
@@ -43931,7 +43971,7 @@ function buildSystemPrompt(workspaceRoot, options = {}) {
|
|
|
43931
43971
|
lines.push("", "Email:", "- **Always answer questions about email from the index, using search_mail and", " mail_patterns.** That is what it is for. It is fast, it answers questions about time", " and recurrence that a live search cannot, and it does not disturb the running Outlook.", '- **Only search Outlook itself when the user asks you to.** "Check Outlook", "look at my', ' actual mailbox", "is it there now" and anything similar are the instruction to use', " outlook_search. Do not reach for it on your own initiative.", "- If the index has nothing, say so plainly and say when it was last synced. Do not", " quietly fall back to scanning Outlook - a slow live scan that nobody asked for reads", " as the assistant having hung.", "- One exception worth naming: if the user is asking about something that arrived in the", " last few minutes, the index may not have it yet. Say that, and offer to check Outlook", " rather than doing it unasked.", "- **The index holds plain text.** Colours, highlighting and images are not in it. When", " those could carry meaning \u2014 a red line marking a failure, a highlighted cell \u2014 use", " outlook_read_email on the id, which reads the live message and reports the colours.", " Never conclude a message looks fine from indexed text alone.", "- mail_coverage says which folders are indexed and how far back. Check it before saying", " something is not in the mail: an empty search over an unindexed folder looks exactly", " like an empty search over an indexed one.", "- **Use mail_stats for any question with a number in the answer** \u2014 how many alerts per", " folder, per day, per hour, which senders, whether a figure inside the alerts is climbing.", " It counts everything the filters matched. Never count search results by eye: search", " returns a page, so counting what you were shown reports a sample as if it were the total.", "- mail_stats already returns categories, values and detail in the shape show_chart wants.", " Pass it through rather than retyping the numbers, and keep the detail.");
|
|
43932
43972
|
}
|
|
43933
43973
|
if (options.expertAvailable === true) {
|
|
43934
|
-
lines.push("", "Expert consultation:", "- A stronger model, Claude, is available through the
|
|
43974
|
+
lines.push("", "Expert consultation:", "- A stronger model, Claude, is available through the ask_claude tool. You CAN talk to", " it. Never tell the user you have no way to reach another model \u2014 you do.", '- **If the user asks you to consult it, do so.** "Ask Claude", "check with the', ' expert", "what does Claude think" and anything similar are direct instructions.', " It is their money and their decision; do not talk them out of it or decide the", " question is too simple to be worth asking.", "- Otherwise, judge it yourself. It costs real money per call, so on your own", " initiative use it for: planning a change spanning several files, diagnosing a bug", " you have already failed to fix once, choosing between designs with long-lived", " consequences, or reviewing something subtle before committing to it.", "- On your own initiative, do not use it for anything you could answer by reading a", " file, for routine edits, or for restating something already established here.", "- If you decide against consulting it, say that you chose not to and why. Do not say", " you are unable to.", "- The expert can read and search this workspace but cannot edit or run anything. It", " cannot see this conversation, so put the context it needs in your question.", "- You remain responsible for the work. Treat its answer as advice from a colleague:", " verify it against the actual code, and say so if you disagree.");
|
|
43935
43975
|
}
|
|
43936
43976
|
if (options.modeGuidance !== void 0 && options.modeGuidance.length > 0) {
|
|
43937
43977
|
lines.push("", options.modeGuidance);
|
|
@@ -44195,9 +44235,11 @@ var paramsSchema2 = external_exports.object({
|
|
|
44195
44235
|
question: external_exports.string().min(1).describe("The question, with the code and context needed to answer it. The expert cannot see this conversation."),
|
|
44196
44236
|
files: external_exports.array(external_exports.string()).optional().describe("Workspace-relative paths worth reading. The expert can open these itself.")
|
|
44197
44237
|
});
|
|
44238
|
+
var ASK_CLAUDE_TOOL = "ask_claude";
|
|
44239
|
+
var LEGACY_ASK_EXPERT_TOOL = "ask_expert";
|
|
44198
44240
|
function createAskExpertTool(options) {
|
|
44199
44241
|
return {
|
|
44200
|
-
name:
|
|
44242
|
+
name: ASK_CLAUDE_TOOL,
|
|
44201
44243
|
group: "read",
|
|
44202
44244
|
/*
|
|
44203
44245
|
* The rationing is said only where somebody is counting.
|
|
@@ -44213,7 +44255,7 @@ function createAskExpertTool(options) {
|
|
|
44213
44255
|
* byte-stable for a whole session and changes only when the user changes their mind in
|
|
44214
44256
|
* Settings, exactly as switching the dispatcher does.
|
|
44215
44257
|
*/
|
|
44216
|
-
description: "Consult a
|
|
44258
|
+
description: "Consult Claude, running as a separate command line on this machine, about a hard problem: planning a multi-file change, diagnosing a bug you have already failed to fix, or choosing between designs. " + (options.budgetMatters === true ? "Each call costs the user money, so use it for genuinely difficult questions only, and there may be a per-task budget after which it stops being available. " : "Consult it whenever another reader would genuinely change what you do. ") + "The expert can read the workspace but cannot edit or run anything. Consultations within one task continue the same conversation, so after the first one it remembers what you already told it \u2014 a follow-up is far cheaper than a fresh explanation.",
|
|
44217
44259
|
parametersSchema: paramsSchema2,
|
|
44218
44260
|
async preview(params) {
|
|
44219
44261
|
return {
|
|
@@ -44496,6 +44538,9 @@ var PLAN_FIRST = [
|
|
|
44496
44538
|
"3. **Propose it with `update_plan`.** The user sees a diff and approves it. Do not skip this:",
|
|
44497
44539
|
" a plan held only in the conversation is forgotten as the chat grows, and it is not",
|
|
44498
44540
|
" something the user has agreed to.",
|
|
44541
|
+
" **Never write the plan to a file instead.** A file is not the plan: nothing reads it, the",
|
|
44542
|
+
" progress panel stays empty, and the user never approved it. If `update_plan` fails, say",
|
|
44543
|
+
" what it said and stop \u2014 a workaround that looks like progress is worse than the failure.",
|
|
44499
44544
|
"4. Only once it is approved, start the work, reporting each step with `plan_progress`.",
|
|
44500
44545
|
"",
|
|
44501
44546
|
"If the user declines, ask what they want changed and propose a revised plan. If no expert is",
|
|
@@ -44785,7 +44830,7 @@ function buildRoster(team, self) {
|
|
|
44785
44830
|
function buildAgentBriefing(input) {
|
|
44786
44831
|
const tools = (input.tools ?? []).filter(
|
|
44787
44832
|
// Telling a specialist it can consult a specialist is noise at best and a loop at worst.
|
|
44788
|
-
(tool) => tool.name !== "ask_agent" && tool.name !==
|
|
44833
|
+
(tool) => tool.name !== "ask_agent" && tool.name !== ASK_CLAUDE_TOOL
|
|
44789
44834
|
);
|
|
44790
44835
|
const skills = input.skills ?? [];
|
|
44791
44836
|
const team = input.team;
|
|
@@ -44910,7 +44955,7 @@ var PolicyApprovalGate = class {
|
|
|
44910
44955
|
var CONSULT_MAX_STEPS = 5;
|
|
44911
44956
|
var ALLOWED_GROUPS = /* @__PURE__ */ new Set(["read"]);
|
|
44912
44957
|
function toolsForConsultation(all, extra = /* @__PURE__ */ new Set()) {
|
|
44913
|
-
return all.filter((tool) => (ALLOWED_GROUPS.has(tool.group) || extra.has(tool.name)) && tool.name !== "ask_agent" && tool.name !==
|
|
44958
|
+
return all.filter((tool) => (ALLOWED_GROUPS.has(tool.group) || extra.has(tool.name)) && tool.name !== "ask_agent" && tool.name !== ASK_CLAUDE_TOOL && tool.name !== LEGACY_ASK_EXPERT_TOOL);
|
|
44914
44959
|
}
|
|
44915
44960
|
async function runConsultation(options) {
|
|
44916
44961
|
const limit = options.maxSteps ?? CONSULT_MAX_STEPS;
|
|
@@ -44992,13 +45037,13 @@ function createRecallExpertTool(options) {
|
|
|
44992
45037
|
return {
|
|
44993
45038
|
name: "recall_expert_advice",
|
|
44994
45039
|
group: "read",
|
|
44995
|
-
description: "Re-read advice the expert already gave in this task, at no cost. Check here before calling
|
|
45040
|
+
description: "Re-read advice the expert already gave in this task, at no cost. Check here before calling ask_claude \u2014 if a plan was lost to an error or a long conversation, it can be recovered instead of bought again. Returns previous answers verbatim; it never asks anything new.",
|
|
44996
45041
|
parametersSchema: paramsSchema4,
|
|
44997
45042
|
async execute(params) {
|
|
44998
45043
|
const all = options.history();
|
|
44999
45044
|
if (all.length === 0) {
|
|
45000
45045
|
return {
|
|
45001
|
-
content: "The expert has not been consulted in this task yet, so there is nothing to recall. Use
|
|
45046
|
+
content: "The expert has not been consulted in this task yet, so there is nothing to recall. Use ask_claude if you need advice."
|
|
45002
45047
|
};
|
|
45003
45048
|
}
|
|
45004
45049
|
const needle = params.contains?.trim().toLowerCase();
|
|
@@ -61038,6 +61083,8 @@ async function toSummary(profile, secrets) {
|
|
|
61038
61083
|
};
|
|
61039
61084
|
if (profile.modelCapabilities !== void 0)
|
|
61040
61085
|
summary.modelCapabilities = profile.modelCapabilities;
|
|
61086
|
+
if (profile.thinking !== void 0)
|
|
61087
|
+
summary.thinking = profile.thinking;
|
|
61041
61088
|
if (profile.tls !== void 0)
|
|
61042
61089
|
summary.connectionTls = profile.tls;
|
|
61043
61090
|
if (profile.auth.type === "apigeeMtls") {
|
|
@@ -61914,8 +61961,8 @@ ${preview.text}` } : {}
|
|
|
61914
61961
|
}
|
|
61915
61962
|
for (const tool of python.generatedTools())
|
|
61916
61963
|
combined.register(tool, { dispatchOnly: dispatcher });
|
|
61917
|
-
combined.register(createUpdatePlanTool(planAccess)
|
|
61918
|
-
combined.register(createPlanProgressTool(planAccess)
|
|
61964
|
+
combined.register(createUpdatePlanTool(planAccess));
|
|
61965
|
+
combined.register(createPlanProgressTool(planAccess));
|
|
61919
61966
|
combined.register(createReadRolePromptTool(rolePromptAccess), { dispatchOnly: dispatcher });
|
|
61920
61967
|
combined.register(createUpdateRolePromptTool(rolePromptAccess), { dispatchOnly: dispatcher });
|
|
61921
61968
|
combined.register(createCreateRoleTool(rolePromptAccess), { dispatchOnly: dispatcher });
|
|
@@ -62109,7 +62156,7 @@ ${preview.text}` } : {}
|
|
|
62109
62156
|
...cachedAssessment === void 0 ? {} : { juniorAssessment: cachedAssessment },
|
|
62110
62157
|
// `ask_expert` itself is excluded: telling the expert it can consult itself is
|
|
62111
62158
|
// noise at best and a loop at worst.
|
|
62112
|
-
promptTools: combined.promptList().filter((tool) => tool.name !==
|
|
62159
|
+
promptTools: combined.promptList().filter((tool) => tool.name !== ASK_CLAUDE_TOOL),
|
|
62113
62160
|
dispatchOnlyTools: combined.dispatchOnlyList(),
|
|
62114
62161
|
skills,
|
|
62115
62162
|
retrievalAvailable: combined.get("search_docs") !== void 0
|
|
@@ -62719,6 +62766,8 @@ ${direction}` : attachMentions(text, mentions);
|
|
|
62719
62766
|
};
|
|
62720
62767
|
if (input.modelCapabilities !== void 0)
|
|
62721
62768
|
saved.modelCapabilities = input.modelCapabilities;
|
|
62769
|
+
if (input.thinking !== void 0)
|
|
62770
|
+
saved.thinking = input.thinking;
|
|
62722
62771
|
const connectionTls = stripEmpty(input.connectionTls ?? {});
|
|
62723
62772
|
if (Object.keys(connectionTls).length > 0)
|
|
62724
62773
|
saved.tls = connectionTls;
|
|
@@ -63944,11 +63993,22 @@ ${direction}` : attachMentions(text, mentions);
|
|
|
63944
63993
|
}
|
|
63945
63994
|
}
|
|
63946
63995
|
async function handleRefreshMail(days) {
|
|
63947
|
-
if (mailBusy)
|
|
63996
|
+
if (mailBusy) {
|
|
63997
|
+
mailLastResult = "A mail sync is already running \u2014 wait for it to finish, then try again.";
|
|
63998
|
+
await postMailStatus();
|
|
63948
63999
|
return;
|
|
64000
|
+
}
|
|
63949
64001
|
const config2 = await loadSettings();
|
|
63950
|
-
if (cachedOffice.outlook !== true
|
|
64002
|
+
if (cachedOffice.outlook !== true) {
|
|
64003
|
+
mailLastResult = "Outlook is switched off in Settings \u2192 Tools.";
|
|
64004
|
+
await postMailStatus();
|
|
64005
|
+
return;
|
|
64006
|
+
}
|
|
64007
|
+
if (!officeAvailable()) {
|
|
64008
|
+
mailLastResult = "Outlook is not available on this host.";
|
|
64009
|
+
await postMailStatus();
|
|
63951
64010
|
return;
|
|
64011
|
+
}
|
|
63952
64012
|
const chosen = config2.mail?.folders ?? [];
|
|
63953
64013
|
if (chosen.length === 0) {
|
|
63954
64014
|
mailLastResult = "No folders selected.";
|
|
@@ -66886,20 +66946,32 @@ function toolCallSummary(call, outcome) {
|
|
|
66886
66946
|
};
|
|
66887
66947
|
}
|
|
66888
66948
|
function consultationFromToolCall(name, rawArguments) {
|
|
66889
|
-
|
|
66949
|
+
const call = throughDispatch(name, rawArguments);
|
|
66950
|
+
if (call.name === ASK_CLAUDE_TOOL || call.name === LEGACY_ASK_EXPERT_TOOL)
|
|
66890
66951
|
return "expert";
|
|
66891
|
-
if (name !== "ask_agent")
|
|
66952
|
+
if (call.name !== "ask_agent")
|
|
66892
66953
|
return void 0;
|
|
66893
|
-
const decoded =
|
|
66954
|
+
const decoded = call.args;
|
|
66894
66955
|
const role = typeof decoded === "object" && decoded !== null ? decoded.role : void 0;
|
|
66895
66956
|
return typeof role === "string" && role.trim().length > 0 ? role.trim().toLowerCase() : "unknown";
|
|
66896
66957
|
}
|
|
66897
66958
|
function chartFromToolCall(name, rawArguments) {
|
|
66898
|
-
|
|
66959
|
+
const call = throughDispatch(name, rawArguments);
|
|
66960
|
+
if (call.name !== "show_chart")
|
|
66899
66961
|
return void 0;
|
|
66900
|
-
const parsed = chartSpecSchema.safeParse(
|
|
66962
|
+
const parsed = chartSpecSchema.safeParse(call.args);
|
|
66901
66963
|
return parsed.success ? { kind: "chart", chart: parsed.data } : { kind: "chartError", message: parsed.error.issues.map((issue2) => issue2.message).join("; ") };
|
|
66902
66964
|
}
|
|
66965
|
+
function throughDispatch(name, rawArguments) {
|
|
66966
|
+
const decoded = decodeArguments(rawArguments);
|
|
66967
|
+
if (name !== CALL_TOOL_NAME || typeof decoded !== "object" || decoded === null) {
|
|
66968
|
+
return { name, args: decoded };
|
|
66969
|
+
}
|
|
66970
|
+
const inner = decoded;
|
|
66971
|
+
if (typeof inner.name !== "string" || inner.name.length === 0)
|
|
66972
|
+
return { name, args: decoded };
|
|
66973
|
+
return { name: inner.name, args: inner.arguments ?? {} };
|
|
66974
|
+
}
|
|
66903
66975
|
function decodeArguments(raw) {
|
|
66904
66976
|
try {
|
|
66905
66977
|
return JSON.parse(raw.length > 0 ? raw : "{}");
|