@chosengeneration/light-code 0.59.1 → 0.59.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -42195,9 +42195,19 @@ async function listModels(http, profile, auth2, signal) {
42195
42195
  function messageOf(error51) {
42196
42196
  return error51 instanceof Error ? error51.message : String(error51);
42197
42197
  }
42198
+ var TEST_CONNECTION_TIMEOUT_MS = 2e4;
42198
42199
  async function testConnection(profile, context, http, signal) {
42199
42200
  const steps = [];
42200
42201
  const finish = () => ({ ok: steps.every((step) => step.status !== "failed"), steps });
42202
+ const deadline = new AbortController();
42203
+ const timer = setTimeout(() => deadline.abort(), TEST_CONNECTION_TIMEOUT_MS);
42204
+ const onOuterAbort = () => deadline.abort();
42205
+ signal?.addEventListener("abort", onOuterAbort);
42206
+ const bounded = deadline.signal;
42207
+ const release = () => {
42208
+ clearTimeout(timer);
42209
+ signal?.removeEventListener("abort", onOuterAbort);
42210
+ };
42201
42211
  if (profile.auth.type === "apigeeMtls") {
42202
42212
  try {
42203
42213
  let expiryNote = "";
@@ -42214,6 +42224,7 @@ async function testConnection(profile, context, http, signal) {
42214
42224
  detail: `Loaded ${loaded?.pfx !== void 0 ? "PFX bundle" : "client certificate and key"}.${expiryNote}`
42215
42225
  });
42216
42226
  } catch (error51) {
42227
+ release();
42217
42228
  steps.push({ step: "certificates", status: "failed", detail: messageOf(error51) });
42218
42229
  steps.push({ step: "token", status: "skipped", detail: "Not attempted \u2014 certificates failed to load." });
42219
42230
  steps.push({ step: "models", status: "skipped", detail: "Not attempted \u2014 certificates failed to load." });
@@ -42245,16 +42256,28 @@ async function testConnection(profile, context, http, signal) {
42245
42256
  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."
42246
42257
  });
42247
42258
  } catch (error51) {
42259
+ release();
42248
42260
  steps.push({ step: "token", status: "failed", detail: messageOf(error51) });
42249
42261
  steps.push({ step: "models", status: "skipped", detail: "Not attempted \u2014 no credential." });
42250
42262
  return finish();
42251
42263
  }
42252
42264
  }
42253
- const result = await listModels(http, profile, auth2, signal);
42265
+ const result = await listModels(http, profile, auth2, bounded);
42266
+ release();
42254
42267
  if (result.ids.length > 0) {
42255
42268
  steps.push({ step: "models", status: "ok", detail: `Gateway returned ${result.ids.length} model(s).` });
42269
+ } else if (deadline.signal.aborted && signal?.aborted !== true) {
42270
+ steps.push({
42271
+ step: "models",
42272
+ status: "failed",
42273
+ 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.`
42274
+ });
42256
42275
  } else {
42257
- steps.push({ step: "models", status: "failed", detail: result.warning ?? "No models returned." });
42276
+ steps.push({
42277
+ step: "models",
42278
+ status: "note",
42279
+ 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.`
42280
+ });
42258
42281
  }
42259
42282
  return finish();
42260
42283
  }
@@ -43981,7 +44004,24 @@ function buildSystemPrompt(workspaceRoot, options = {}) {
43981
44004
  ' write it for them \u2014 "checking which gateway the profile points at", not "reading a file".',
43982
44005
  "- Paths are relative to the workspace root. You cannot access anything outside it.",
43983
44006
  "- When the task is complete, call attempt_completion with a summary of what you did.",
43984
- "- If you need information only the user can provide, call ask_followup_question."
44007
+ "- If you need information only the user can provide, call ask_followup_question.",
44008
+ /*
44009
+ * Asked for directly, from real use with a model whose training predates the libraries in
44010
+ * front of it. The failure it addresses is not refusing to answer - it is answering anyway,
44011
+ * from a remembered version of an API, which produces code that looks right and is wrong
44012
+ * against the installed version. The user very often has the page open.
44013
+ *
44014
+ * Phrased as a thing to do rather than a permission, because a model that is unsure is
44015
+ * already reluctant to interrupt, and "you may ask" reads as "prefer not to".
44016
+ */
44017
+ "- **If a library or API is unfamiliar, or the version here does not match what you remember,",
44018
+ " ask the user for documentation rather than guessing.** Say which library and what you need",
44019
+ " to know - a signature, which module something moved to, whether a call is still supported.",
44020
+ " They can paste it, point you at a file or a URL they have already fetched, or tell you the",
44021
+ " house convention. Recalling an API from a version you were trained on produces code that",
44022
+ " looks correct and fails against the one installed, which is far more expensive than asking.",
44023
+ "- Before asking, check what is here: the imports and existing calls in this workspace are",
44024
+ " evidence about the version actually installed, and a skill may already describe it."
43985
44025
  );
43986
44026
  if (options.skills !== void 0 && options.skills.length > 0) {
43987
44027
  lines.push("", options.skills);
@@ -44030,7 +44070,7 @@ function buildSystemPrompt(workspaceRoot, options = {}) {
44030
44070
  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.");
44031
44071
  }
44032
44072
  if (options.expertAvailable === true) {
44033
- lines.push("", "Expert consultation:", "- A stronger model, Claude, is available through the ask_expert 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.");
44073
+ 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.");
44034
44074
  }
44035
44075
  if (options.modeGuidance !== void 0 && options.modeGuidance.length > 0) {
44036
44076
  lines.push("", options.modeGuidance);
@@ -44294,9 +44334,11 @@ var paramsSchema2 = external_exports.object({
44294
44334
  question: external_exports.string().min(1).describe("The question, with the code and context needed to answer it. The expert cannot see this conversation."),
44295
44335
  files: external_exports.array(external_exports.string()).optional().describe("Workspace-relative paths worth reading. The expert can open these itself.")
44296
44336
  });
44337
+ var ASK_CLAUDE_TOOL = "ask_claude";
44338
+ var LEGACY_ASK_EXPERT_TOOL = "ask_expert";
44297
44339
  function createAskExpertTool(options) {
44298
44340
  return {
44299
- name: "ask_expert",
44341
+ name: ASK_CLAUDE_TOOL,
44300
44342
  group: "read",
44301
44343
  /*
44302
44344
  * The rationing is said only where somebody is counting.
@@ -44312,7 +44354,7 @@ function createAskExpertTool(options) {
44312
44354
  * byte-stable for a whole session and changes only when the user changes their mind in
44313
44355
  * Settings, exactly as switching the dispatcher does.
44314
44356
  */
44315
- description: "Consult a stronger expert model about a hard problem: planning a multi-file change, diagnosing a bug you have already failed to fix, or choosing between designs. " + (options.budgetMatters === true ? "Each call costs the user money, so use it for genuinely difficult questions only, and there may be a per-task budget after which it stops being available. " : "Consult it whenever another reader would genuinely change what you do. ") + "The expert can read the workspace but cannot edit or run anything. Consultations within one task continue the same conversation, so after the first one it remembers what you already told it \u2014 a follow-up is far cheaper than a fresh explanation.",
44357
+ 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.",
44316
44358
  parametersSchema: paramsSchema2,
44317
44359
  async preview(params) {
44318
44360
  return {
@@ -44595,6 +44637,9 @@ var PLAN_FIRST = [
44595
44637
  "3. **Propose it with `update_plan`.** The user sees a diff and approves it. Do not skip this:",
44596
44638
  " a plan held only in the conversation is forgotten as the chat grows, and it is not",
44597
44639
  " something the user has agreed to.",
44640
+ " **Never write the plan to a file instead.** A file is not the plan: nothing reads it, the",
44641
+ " progress panel stays empty, and the user never approved it. If `update_plan` fails, say",
44642
+ " what it said and stop \u2014 a workaround that looks like progress is worse than the failure.",
44598
44643
  "4. Only once it is approved, start the work, reporting each step with `plan_progress`.",
44599
44644
  "",
44600
44645
  "If the user declines, ask what they want changed and propose a revised plan. If no expert is",
@@ -44884,7 +44929,7 @@ function buildRoster(team, self) {
44884
44929
  function buildAgentBriefing(input) {
44885
44930
  const tools = (input.tools ?? []).filter(
44886
44931
  // Telling a specialist it can consult a specialist is noise at best and a loop at worst.
44887
- (tool) => tool.name !== "ask_agent" && tool.name !== "ask_expert"
44932
+ (tool) => tool.name !== "ask_agent" && tool.name !== ASK_CLAUDE_TOOL
44888
44933
  );
44889
44934
  const skills = input.skills ?? [];
44890
44935
  const team = input.team;
@@ -44944,6 +44989,8 @@ var ALWAYS_ASK_TOOLS = /* @__PURE__ */ new Set([
44944
44989
  * human sees the source once, and no category toggle can stand in for that.
44945
44990
  */
44946
44991
  "excel_write_macro",
44992
+ // Changes a workbook somebody has open and has not saved, with no undo this product owns.
44993
+ "excel_write_range",
44947
44994
  /*
44948
44995
  * Running a macro executes somebody else's VBA as the user: it can rewrite the workbook, write
44949
44996
  * files, or send mail. That is not something a category toggle should ever cover, and the
@@ -45009,7 +45056,7 @@ var PolicyApprovalGate = class {
45009
45056
  var CONSULT_MAX_STEPS = 5;
45010
45057
  var ALLOWED_GROUPS = /* @__PURE__ */ new Set(["read"]);
45011
45058
  function toolsForConsultation(all, extra = /* @__PURE__ */ new Set()) {
45012
- return all.filter((tool) => (ALLOWED_GROUPS.has(tool.group) || extra.has(tool.name)) && tool.name !== "ask_agent" && tool.name !== "ask_expert");
45059
+ 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);
45013
45060
  }
45014
45061
  async function runConsultation(options) {
45015
45062
  const limit = options.maxSteps ?? CONSULT_MAX_STEPS;
@@ -45091,13 +45138,13 @@ function createRecallExpertTool(options) {
45091
45138
  return {
45092
45139
  name: "recall_expert_advice",
45093
45140
  group: "read",
45094
- description: "Re-read advice the expert already gave in this task, at no cost. Check here before calling ask_expert \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.",
45141
+ 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.",
45095
45142
  parametersSchema: paramsSchema4,
45096
45143
  async execute(params) {
45097
45144
  const all = options.history();
45098
45145
  if (all.length === 0) {
45099
45146
  return {
45100
- content: "The expert has not been consulted in this task yet, so there is nothing to recall. Use ask_expert if you need advice."
45147
+ content: "The expert has not been consulted in this task yet, so there is nothing to recall. Use ask_claude if you need advice."
45101
45148
  };
45102
45149
  }
45103
45150
  const needle = params.contains?.trim().toLowerCase();
@@ -47652,6 +47699,98 @@ function createExcelReadMacroTool(options) {
47652
47699
  }
47653
47700
  };
47654
47701
  }
47702
+ var writeRangeSchema = external_exports.object({
47703
+ workbook: external_exports.string().optional().describe("Which open workbook. Defaults to the active one."),
47704
+ sheet: external_exports.string().optional().describe("Which sheet. Defaults to the active one."),
47705
+ cell: external_exports.string().describe('The top-left cell to start writing at, such as "A1". The block extends right and down from there.'),
47706
+ values: external_exports.array(external_exports.array(external_exports.union([external_exports.string(), external_exports.number(), external_exports.boolean(), external_exports.null()]))).min(1).describe('Rows of cell contents, every row the same width. A string starting with "=" is written as a formula and Excel calculates it; anything else is written as a plain value.')
47707
+ });
47708
+ function createExcelWriteRangeTool(options) {
47709
+ return {
47710
+ name: "excel_write_range",
47711
+ group: "edit",
47712
+ description: 'Write a block of values or formulas into an open workbook, starting at a cell. Rows of equal width; a string beginning with "=" becomes a formula Excel calculates. The workbook is left unsaved so the user can look at the result before keeping it.',
47713
+ parametersSchema: writeRangeSchema,
47714
+ async preview(params) {
47715
+ const width = params.values[0]?.length ?? 0;
47716
+ const target = `${params.values.length} row(s) x ${String(width)} column(s) from ${params.cell}`;
47717
+ const proposed = params.values.map((row) => row.map((cell) => cell === null ? "" : String(cell)).join(" | ")).join("\n");
47718
+ let existing = "Could not read the current contents of that range.";
47719
+ try {
47720
+ const current = await options.bridge.request({
47721
+ op: "excel.readRange",
47722
+ ...params.workbook !== void 0 ? { workbook: params.workbook } : {},
47723
+ ...params.sheet !== void 0 ? { sheet: params.sheet } : {},
47724
+ range: rangeFor(params.cell, params.values.length, width)
47725
+ });
47726
+ const filled = current.cells.filter((cell) => cell.value !== null && cell.value !== void 0 && String(cell.value) !== "");
47727
+ existing = filled.length === 0 ? "Those cells are all empty." : filled.map((cell) => `${cell.address}: ${String(cell.text ?? cell.value)}`).join("\n");
47728
+ } catch {
47729
+ }
47730
+ return {
47731
+ kind: "text",
47732
+ text: [
47733
+ `Write ${target} into ${params.sheet ?? "the active sheet"} of ${params.workbook ?? "the active workbook"}.`,
47734
+ "",
47735
+ "--- what is there now ---",
47736
+ existing,
47737
+ "",
47738
+ "--- what will replace it ---",
47739
+ proposed,
47740
+ "",
47741
+ "The workbook stays open and unsaved, so nothing reaches disk until the user saves it."
47742
+ ].join("\n")
47743
+ };
47744
+ },
47745
+ async execute(params) {
47746
+ try {
47747
+ const result = await options.bridge.request({ op: "excel.writeRange", ...params });
47748
+ const errors = result.cells.filter((cell) => String(cell.value).startsWith("#"));
47749
+ const sample = result.cells.slice(0, 40).map((cell) => `${cell.address}: ${cell.value === null ? "" : String(cell.value)}`).join("\n");
47750
+ return {
47751
+ content: [
47752
+ `Wrote ${String(result.written)} cell(s) to ${result.sheet}!${result.range} in ${result.workbook}.`,
47753
+ result.overwritten.length > 0 ? `Replaced ${String(result.overwritten.length)} cell(s) that had contents.` : "Every target cell was empty.",
47754
+ errors.length > 0 ? `${String(errors.length)} cell(s) evaluated to an error: ${errors.map((cell) => `${cell.address} ${String(cell.value)}`).join(", ")}` : "",
47755
+ "",
47756
+ sample,
47757
+ result.cells.length > 40 ? `...and ${String(result.cells.length - 40)} more` : "",
47758
+ "",
47759
+ "The workbook is NOT saved; tell the user to save it in Excel if they want to keep it."
47760
+ ].filter((line) => line !== "").join("\n"),
47761
+ isError: false
47762
+ };
47763
+ } catch (error51) {
47764
+ return { content: message(error51), isError: true };
47765
+ }
47766
+ }
47767
+ };
47768
+ }
47769
+ function rangeFor(cell, rows, columns) {
47770
+ const match = /^\$?([A-Za-z]+)\$?(\d+)$/.exec(cell.trim());
47771
+ if (match === null)
47772
+ return cell;
47773
+ const startColumn = columnNumber(match[1] ?? "A");
47774
+ const startRow = Number(match[2]);
47775
+ return `${match[1]?.toUpperCase() ?? "A"}${String(startRow)}:${columnLetters(startColumn + columns - 1)}${String(startRow + rows - 1)}`;
47776
+ }
47777
+ function columnNumber(letters) {
47778
+ let total = 0;
47779
+ for (const character of letters.toUpperCase()) {
47780
+ total = total * 26 + (character.charCodeAt(0) - 64);
47781
+ }
47782
+ return total;
47783
+ }
47784
+ function columnLetters(column) {
47785
+ let remaining = column;
47786
+ let letters = "";
47787
+ while (remaining > 0) {
47788
+ const remainder = (remaining - 1) % 26;
47789
+ letters = String.fromCharCode(65 + remainder) + letters;
47790
+ remaining = Math.floor((remaining - 1) / 26);
47791
+ }
47792
+ return letters;
47793
+ }
47655
47794
  var writeMacroSchema = macroSchema.extend({
47656
47795
  code: external_exports.string().describe("The complete new contents of the module. It replaces what is there.")
47657
47796
  });
@@ -49094,6 +49233,7 @@ var NEVER_AVAILABLE_TO_SCHEDULES = [
49094
49233
  // Same reasoning, and sharper unattended: installing a macro is authorising a capability, and
49095
49234
  // section 13 requires approval showing the source, which cannot happen with nobody there.
49096
49235
  "excel_write_macro",
49236
+ "excel_write_range",
49097
49237
  // And running one: unattended execution of arbitrary VBA, with nobody to read the source.
49098
49238
  "excel_run_macro",
49099
49239
  /*
@@ -58735,6 +58875,96 @@ function Invoke-ExcelSessions {\r
58735
58875
  happened, because a currency column silently losing its currency is the kind of difference\r
58736
58876
  someone should be told about rather than left to notice.\r
58737
58877
  #>\r
58878
+ # Writes a block of values or formulas into a live workbook.\r
58879
+ #\r
58880
+ # Bulk, not cell by cell. Reading 400 cells one at a time measured 315x slower than the array\r
58881
+ # property and ran past the timeout entirely; writing has exactly the same shape, so the whole\r
58882
+ # block goes in one assignment.\r
58883
+ #\r
58884
+ # \`.Formula\` rather than \`.Value2\`, so a string beginning with = becomes a real formula that\r
58885
+ # Excel calculates. A plain value assigned through Formula stays a plain value, so one property\r
58886
+ # covers both and the caller does not have to say which it meant.\r
58887
+ #\r
58888
+ # What was there is read *before* the write and returned, so the result tells the truth about what\r
58889
+ # was overwritten even if the sheet changed between the approval and the call.\r
58890
+ function Invoke-ExcelWriteRange {\r
58891
+ param($Request)\r
58892
+ \r
58893
+ $app = Get-OfficeApp -ProgId 'Excel.Application' -AttachOnly $true\r
58894
+ $wb = Get-Workbook -App $app -Name $Request.workbook\r
58895
+ $sheet = Get-Worksheet -Workbook $wb -Name $Request.sheet\r
58896
+ \r
58897
+ $rows = @($Request.values)\r
58898
+ $rowCount = $rows.Count\r
58899
+ if ($rowCount -eq 0) { throw 'No values were given to write.' }\r
58900
+ $columnCount = @($rows[0]).Count\r
58901
+ if ($columnCount -eq 0) { throw 'The first row is empty, so there is nothing to write.' }\r
58902
+ \r
58903
+ $limit = 5000\r
58904
+ if (($rowCount * $columnCount) -gt $limit) {\r
58905
+ throw "That is $($rowCount * $columnCount) cells; write at most $limit at a time."\r
58906
+ }\r
58907
+ \r
58908
+ # A ragged block would silently write nulls into the short rows, so it is refused instead.\r
58909
+ for ($r = 0; $r -lt $rowCount; $r++) {\r
58910
+ $width = @($rows[$r]).Count\r
58911
+ if ($width -ne $columnCount) {\r
58912
+ throw "Row $($r + 1) has $width value(s) but the first row has $columnCount; every row must be the same width."\r
58913
+ }\r
58914
+ }\r
58915
+ \r
58916
+ $target = $sheet.Range($Request.cell).Resize($rowCount, $columnCount)\r
58917
+ \r
58918
+ # What is being replaced, captured before anything is written.\r
58919
+ $existing = $target.Formula\r
58920
+ $before = @()\r
58921
+ for ($r = 1; $r -le $rowCount; $r++) {\r
58922
+ for ($c = 1; $c -le $columnCount; $c++) {\r
58923
+ $was = if ($rowCount -eq 1 -and $columnCount -eq 1) { $existing } else { $existing[$r, $c] }\r
58924
+ if ($null -ne $was -and "$was" -ne '') {\r
58925
+ $before += [ordered]@{\r
58926
+ address = (Get-CellAddress -Row ($target.Row + $r - 1) -Column ($target.Column + $c - 1))\r
58927
+ was = [string]$was\r
58928
+ }\r
58929
+ }\r
58930
+ }\r
58931
+ }\r
58932
+ \r
58933
+ $block = New-Object 'object[,]' $rowCount, $columnCount\r
58934
+ for ($r = 0; $r -lt $rowCount; $r++) {\r
58935
+ $row = @($rows[$r])\r
58936
+ for ($c = 0; $c -lt $columnCount; $c++) {\r
58937
+ $block[$r, $c] = $row[$c]\r
58938
+ }\r
58939
+ }\r
58940
+ \r
58941
+ $target.Formula = $block\r
58942
+ \r
58943
+ # Read back what Excel made of it. A formula that lands as #N/A or #REF! is the whole reason\r
58944
+ # this is reported rather than assumed - it would otherwise sit there unnoticed.\r
58945
+ $after = @()\r
58946
+ $computed = $target.Value2\r
58947
+ for ($r = 1; $r -le $rowCount; $r++) {\r
58948
+ for ($c = 1; $c -le $columnCount; $c++) {\r
58949
+ $value = if ($rowCount -eq 1 -and $columnCount -eq 1) { $computed } else { $computed[$r, $c] }\r
58950
+ $converted = Convert-ExcelValue -Value $value\r
58951
+ $after += [ordered]@{\r
58952
+ address = (Get-CellAddress -Row ($target.Row + $r - 1) -Column ($target.Column + $c - 1))\r
58953
+ value = $converted\r
58954
+ }\r
58955
+ }\r
58956
+ }\r
58957
+ \r
58958
+ return @{\r
58959
+ workbook = $wb.Name\r
58960
+ sheet = $sheet.Name\r
58961
+ range = $target.Address(0, 0)\r
58962
+ written = $rowCount * $columnCount\r
58963
+ overwritten = $before\r
58964
+ cells = $after\r
58965
+ }\r
58966
+ }\r
58967
+ \r
58738
58968
  function Invoke-ExcelReadRange {\r
58739
58969
  param($Request)\r
58740
58970
  \r
@@ -59854,6 +60084,7 @@ function Invoke-Request {\r
59854
60084
  'excel.sessions' { return Invoke-ExcelSessions }\r
59855
60085
  'excel.diagnose' { return Invoke-ExcelDiagnose }\r
59856
60086
  'excel.readRange' { return Invoke-ExcelReadRange -Request $Request }\r
60087
+ 'excel.writeRange' { return Invoke-ExcelWriteRange -Request $Request }\r
59857
60088
  'excel.trace' { return Invoke-ExcelTrace -Request $Request }\r
59858
60089
  'excel.listMacros' { return Invoke-ExcelListMacros -Request $Request }\r
59859
60090
  'excel.readMacro' { return Invoke-ExcelReadMacro -Request $Request }\r
@@ -62015,8 +62246,8 @@ ${preview.text}` } : {}
62015
62246
  }
62016
62247
  for (const tool of python.generatedTools())
62017
62248
  combined.register(tool, { dispatchOnly: dispatcher });
62018
- combined.register(createUpdatePlanTool(planAccess), { dispatchOnly: dispatcher });
62019
- combined.register(createPlanProgressTool(planAccess), { dispatchOnly: dispatcher });
62249
+ combined.register(createUpdatePlanTool(planAccess));
62250
+ combined.register(createPlanProgressTool(planAccess));
62020
62251
  combined.register(createReadRolePromptTool(rolePromptAccess), { dispatchOnly: dispatcher });
62021
62252
  combined.register(createUpdateRolePromptTool(rolePromptAccess), { dispatchOnly: dispatcher });
62022
62253
  combined.register(createCreateRoleTool(rolePromptAccess), { dispatchOnly: dispatcher });
@@ -62121,6 +62352,7 @@ ${preview.text}` } : {}
62121
62352
  combined.register(createExcelListMacrosTool(officeOptions));
62122
62353
  combined.register(createExcelReadMacroTool(officeOptions));
62123
62354
  combined.register(createExcelWriteMacroTool(officeOptions));
62355
+ combined.register(createExcelWriteRangeTool(officeOptions));
62124
62356
  combined.register(createExcelCheckMacroTool(officeOptions));
62125
62357
  combined.register(createExcelEvaluateTool(officeOptions));
62126
62358
  combined.register(createExcelRunMacroTool(officeOptions));
@@ -62210,7 +62442,7 @@ ${preview.text}` } : {}
62210
62442
  ...cachedAssessment === void 0 ? {} : { juniorAssessment: cachedAssessment },
62211
62443
  // `ask_expert` itself is excluded: telling the expert it can consult itself is
62212
62444
  // noise at best and a loop at worst.
62213
- promptTools: combined.promptList().filter((tool) => tool.name !== "ask_expert"),
62445
+ promptTools: combined.promptList().filter((tool) => tool.name !== ASK_CLAUDE_TOOL),
62214
62446
  dispatchOnlyTools: combined.dispatchOnlyList(),
62215
62447
  skills,
62216
62448
  retrievalAvailable: combined.get("search_docs") !== void 0
@@ -64047,11 +64279,22 @@ ${direction}` : attachMentions(text, mentions);
64047
64279
  }
64048
64280
  }
64049
64281
  async function handleRefreshMail(days) {
64050
- if (mailBusy)
64282
+ if (mailBusy) {
64283
+ mailLastResult = "A mail sync is already running \u2014 wait for it to finish, then try again.";
64284
+ await postMailStatus();
64051
64285
  return;
64286
+ }
64052
64287
  const config2 = await loadSettings();
64053
- if (cachedOffice.outlook !== true || !officeAvailable())
64288
+ if (cachedOffice.outlook !== true) {
64289
+ mailLastResult = "Outlook is switched off in Settings \u2192 Tools.";
64290
+ await postMailStatus();
64291
+ return;
64292
+ }
64293
+ if (!officeAvailable()) {
64294
+ mailLastResult = "Outlook is not available on this host.";
64295
+ await postMailStatus();
64054
64296
  return;
64297
+ }
64055
64298
  const chosen = config2.mail?.folders ?? [];
64056
64299
  if (chosen.length === 0) {
64057
64300
  mailLastResult = "No folders selected.";
@@ -66989,20 +67232,32 @@ function toolCallSummary(call, outcome) {
66989
67232
  };
66990
67233
  }
66991
67234
  function consultationFromToolCall(name, rawArguments) {
66992
- if (name === "ask_expert")
67235
+ const call = throughDispatch(name, rawArguments);
67236
+ if (call.name === ASK_CLAUDE_TOOL || call.name === LEGACY_ASK_EXPERT_TOOL)
66993
67237
  return "expert";
66994
- if (name !== "ask_agent")
67238
+ if (call.name !== "ask_agent")
66995
67239
  return void 0;
66996
- const decoded = decodeArguments(rawArguments);
67240
+ const decoded = call.args;
66997
67241
  const role = typeof decoded === "object" && decoded !== null ? decoded.role : void 0;
66998
67242
  return typeof role === "string" && role.trim().length > 0 ? role.trim().toLowerCase() : "unknown";
66999
67243
  }
67000
67244
  function chartFromToolCall(name, rawArguments) {
67001
- if (name !== "show_chart")
67245
+ const call = throughDispatch(name, rawArguments);
67246
+ if (call.name !== "show_chart")
67002
67247
  return void 0;
67003
- const parsed = chartSpecSchema.safeParse(decodeArguments(rawArguments));
67248
+ const parsed = chartSpecSchema.safeParse(call.args);
67004
67249
  return parsed.success ? { kind: "chart", chart: parsed.data } : { kind: "chartError", message: parsed.error.issues.map((issue2) => issue2.message).join("; ") };
67005
67250
  }
67251
+ function throughDispatch(name, rawArguments) {
67252
+ const decoded = decodeArguments(rawArguments);
67253
+ if (name !== CALL_TOOL_NAME || typeof decoded !== "object" || decoded === null) {
67254
+ return { name, args: decoded };
67255
+ }
67256
+ const inner = decoded;
67257
+ if (typeof inner.name !== "string" || inner.name.length === 0)
67258
+ return { name, args: decoded };
67259
+ return { name: inner.name, args: inner.arguments ?? {} };
67260
+ }
67006
67261
  function decodeArguments(raw) {
67007
67262
  try {
67008
67263
  return JSON.parse(raw.length > 0 ? raw : "{}");
@@ -69826,6 +70081,18 @@ var CONTENT_TYPES = {
69826
70081
  // through <img> cannot run script, whatever it contains.
69827
70082
  ".svg": "image/svg+xml"
69828
70083
  };
70084
+ var STREAM_PADDING_BYTES = 8192;
70085
+ var STREAM_PADDING = `: ${(() => {
70086
+ let filler = "";
70087
+ let seed = 1;
70088
+ while (filler.length < STREAM_PADDING_BYTES) {
70089
+ seed = (seed * 1103515245 + 12345) % 2147483648;
70090
+ filler += (seed % 36).toString(36);
70091
+ }
70092
+ return filler;
70093
+ })()}
70094
+
70095
+ `;
69829
70096
  async function startServer(options) {
69830
70097
  const log = options.logSink ?? ((line) => process.stderr.write(`${line}
69831
70098
  `));
@@ -70066,6 +70333,7 @@ async function startServer(options) {
70066
70333
  "Cache-Control": "no-store, no-transform",
70067
70334
  "X-Accel-Buffering": "no"
70068
70335
  });
70336
+ response.write(STREAM_PADDING);
70069
70337
  response.write(": connected\n\n");
70070
70338
  const viaAdminUrl = url2.searchParams.get("view") === "admin";
70071
70339
  if (viaAdminUrl) adminConnections.add(principal.id);
@@ -70312,7 +70580,7 @@ function respondJson(response, status, body) {
70312
70580
  }
70313
70581
 
70314
70582
  // src/cli.ts
70315
- var VERSION = true ? "0.59.1" : "unknown (not a packaged build)";
70583
+ var VERSION = true ? "0.59.8" : "unknown (not a packaged build)";
70316
70584
  var compat = installNodeCompat();
70317
70585
  function lastMeaningfulLine(problem) {
70318
70586
  const lines = problem.split(String.fromCharCode(10)).map((line) => line.trim()).filter((line) => line.length > 0 && !line.endsWith(":"));