@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/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, signal);
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({ step: "models", status: "failed", detail: result.warning ?? "No models returned." });
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 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.");
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: "ask_expert",
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 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.",
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 !== "ask_expert"
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;
@@ -44845,6 +44890,8 @@ var ALWAYS_ASK_TOOLS = /* @__PURE__ */ new Set([
44845
44890
  * human sees the source once, and no category toggle can stand in for that.
44846
44891
  */
44847
44892
  "excel_write_macro",
44893
+ // Changes a workbook somebody has open and has not saved, with no undo this product owns.
44894
+ "excel_write_range",
44848
44895
  /*
44849
44896
  * Running a macro executes somebody else's VBA as the user: it can rewrite the workbook, write
44850
44897
  * files, or send mail. That is not something a category toggle should ever cover, and the
@@ -44910,7 +44957,7 @@ var PolicyApprovalGate = class {
44910
44957
  var CONSULT_MAX_STEPS = 5;
44911
44958
  var ALLOWED_GROUPS = /* @__PURE__ */ new Set(["read"]);
44912
44959
  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 !== "ask_expert");
44960
+ 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
44961
  }
44915
44962
  async function runConsultation(options) {
44916
44963
  const limit = options.maxSteps ?? CONSULT_MAX_STEPS;
@@ -44992,13 +45039,13 @@ function createRecallExpertTool(options) {
44992
45039
  return {
44993
45040
  name: "recall_expert_advice",
44994
45041
  group: "read",
44995
- 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.",
45042
+ 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
45043
  parametersSchema: paramsSchema4,
44997
45044
  async execute(params) {
44998
45045
  const all = options.history();
44999
45046
  if (all.length === 0) {
45000
45047
  return {
45001
- content: "The expert has not been consulted in this task yet, so there is nothing to recall. Use ask_expert if you need advice."
45048
+ 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
45049
  };
45003
45050
  }
45004
45051
  const needle = params.contains?.trim().toLowerCase();
@@ -47553,6 +47600,98 @@ function createExcelReadMacroTool(options) {
47553
47600
  }
47554
47601
  };
47555
47602
  }
47603
+ var writeRangeSchema = external_exports.object({
47604
+ workbook: external_exports.string().optional().describe("Which open workbook. Defaults to the active one."),
47605
+ sheet: external_exports.string().optional().describe("Which sheet. Defaults to the active one."),
47606
+ cell: external_exports.string().describe('The top-left cell to start writing at, such as "A1". The block extends right and down from there.'),
47607
+ 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.')
47608
+ });
47609
+ function createExcelWriteRangeTool(options) {
47610
+ return {
47611
+ name: "excel_write_range",
47612
+ group: "edit",
47613
+ 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.',
47614
+ parametersSchema: writeRangeSchema,
47615
+ async preview(params) {
47616
+ const width = params.values[0]?.length ?? 0;
47617
+ const target = `${params.values.length} row(s) x ${String(width)} column(s) from ${params.cell}`;
47618
+ const proposed = params.values.map((row) => row.map((cell) => cell === null ? "" : String(cell)).join(" | ")).join("\n");
47619
+ let existing = "Could not read the current contents of that range.";
47620
+ try {
47621
+ const current = await options.bridge.request({
47622
+ op: "excel.readRange",
47623
+ ...params.workbook !== void 0 ? { workbook: params.workbook } : {},
47624
+ ...params.sheet !== void 0 ? { sheet: params.sheet } : {},
47625
+ range: rangeFor(params.cell, params.values.length, width)
47626
+ });
47627
+ const filled = current.cells.filter((cell) => cell.value !== null && cell.value !== void 0 && String(cell.value) !== "");
47628
+ existing = filled.length === 0 ? "Those cells are all empty." : filled.map((cell) => `${cell.address}: ${String(cell.text ?? cell.value)}`).join("\n");
47629
+ } catch {
47630
+ }
47631
+ return {
47632
+ kind: "text",
47633
+ text: [
47634
+ `Write ${target} into ${params.sheet ?? "the active sheet"} of ${params.workbook ?? "the active workbook"}.`,
47635
+ "",
47636
+ "--- what is there now ---",
47637
+ existing,
47638
+ "",
47639
+ "--- what will replace it ---",
47640
+ proposed,
47641
+ "",
47642
+ "The workbook stays open and unsaved, so nothing reaches disk until the user saves it."
47643
+ ].join("\n")
47644
+ };
47645
+ },
47646
+ async execute(params) {
47647
+ try {
47648
+ const result = await options.bridge.request({ op: "excel.writeRange", ...params });
47649
+ const errors = result.cells.filter((cell) => String(cell.value).startsWith("#"));
47650
+ const sample = result.cells.slice(0, 40).map((cell) => `${cell.address}: ${cell.value === null ? "" : String(cell.value)}`).join("\n");
47651
+ return {
47652
+ content: [
47653
+ `Wrote ${String(result.written)} cell(s) to ${result.sheet}!${result.range} in ${result.workbook}.`,
47654
+ result.overwritten.length > 0 ? `Replaced ${String(result.overwritten.length)} cell(s) that had contents.` : "Every target cell was empty.",
47655
+ errors.length > 0 ? `${String(errors.length)} cell(s) evaluated to an error: ${errors.map((cell) => `${cell.address} ${String(cell.value)}`).join(", ")}` : "",
47656
+ "",
47657
+ sample,
47658
+ result.cells.length > 40 ? `...and ${String(result.cells.length - 40)} more` : "",
47659
+ "",
47660
+ "The workbook is NOT saved; tell the user to save it in Excel if they want to keep it."
47661
+ ].filter((line) => line !== "").join("\n"),
47662
+ isError: false
47663
+ };
47664
+ } catch (error51) {
47665
+ return { content: message(error51), isError: true };
47666
+ }
47667
+ }
47668
+ };
47669
+ }
47670
+ function rangeFor(cell, rows, columns) {
47671
+ const match = /^\$?([A-Za-z]+)\$?(\d+)$/.exec(cell.trim());
47672
+ if (match === null)
47673
+ return cell;
47674
+ const startColumn = columnNumber(match[1] ?? "A");
47675
+ const startRow = Number(match[2]);
47676
+ return `${match[1]?.toUpperCase() ?? "A"}${String(startRow)}:${columnLetters(startColumn + columns - 1)}${String(startRow + rows - 1)}`;
47677
+ }
47678
+ function columnNumber(letters) {
47679
+ let total = 0;
47680
+ for (const character of letters.toUpperCase()) {
47681
+ total = total * 26 + (character.charCodeAt(0) - 64);
47682
+ }
47683
+ return total;
47684
+ }
47685
+ function columnLetters(column) {
47686
+ let remaining = column;
47687
+ let letters = "";
47688
+ while (remaining > 0) {
47689
+ const remainder = (remaining - 1) % 26;
47690
+ letters = String.fromCharCode(65 + remainder) + letters;
47691
+ remaining = Math.floor((remaining - 1) / 26);
47692
+ }
47693
+ return letters;
47694
+ }
47556
47695
  var writeMacroSchema = macroSchema.extend({
47557
47696
  code: external_exports.string().describe("The complete new contents of the module. It replaces what is there.")
47558
47697
  });
@@ -48995,6 +49134,7 @@ var NEVER_AVAILABLE_TO_SCHEDULES = [
48995
49134
  // Same reasoning, and sharper unattended: installing a macro is authorising a capability, and
48996
49135
  // section 13 requires approval showing the source, which cannot happen with nobody there.
48997
49136
  "excel_write_macro",
49137
+ "excel_write_range",
48998
49138
  // And running one: unattended execution of arbitrary VBA, with nobody to read the source.
48999
49139
  "excel_run_macro",
49000
49140
  /*
@@ -58636,6 +58776,96 @@ function Invoke-ExcelSessions {\r
58636
58776
  happened, because a currency column silently losing its currency is the kind of difference\r
58637
58777
  someone should be told about rather than left to notice.\r
58638
58778
  #>\r
58779
+ # Writes a block of values or formulas into a live workbook.\r
58780
+ #\r
58781
+ # Bulk, not cell by cell. Reading 400 cells one at a time measured 315x slower than the array\r
58782
+ # property and ran past the timeout entirely; writing has exactly the same shape, so the whole\r
58783
+ # block goes in one assignment.\r
58784
+ #\r
58785
+ # \`.Formula\` rather than \`.Value2\`, so a string beginning with = becomes a real formula that\r
58786
+ # Excel calculates. A plain value assigned through Formula stays a plain value, so one property\r
58787
+ # covers both and the caller does not have to say which it meant.\r
58788
+ #\r
58789
+ # What was there is read *before* the write and returned, so the result tells the truth about what\r
58790
+ # was overwritten even if the sheet changed between the approval and the call.\r
58791
+ function Invoke-ExcelWriteRange {\r
58792
+ param($Request)\r
58793
+ \r
58794
+ $app = Get-OfficeApp -ProgId 'Excel.Application' -AttachOnly $true\r
58795
+ $wb = Get-Workbook -App $app -Name $Request.workbook\r
58796
+ $sheet = Get-Worksheet -Workbook $wb -Name $Request.sheet\r
58797
+ \r
58798
+ $rows = @($Request.values)\r
58799
+ $rowCount = $rows.Count\r
58800
+ if ($rowCount -eq 0) { throw 'No values were given to write.' }\r
58801
+ $columnCount = @($rows[0]).Count\r
58802
+ if ($columnCount -eq 0) { throw 'The first row is empty, so there is nothing to write.' }\r
58803
+ \r
58804
+ $limit = 5000\r
58805
+ if (($rowCount * $columnCount) -gt $limit) {\r
58806
+ throw "That is $($rowCount * $columnCount) cells; write at most $limit at a time."\r
58807
+ }\r
58808
+ \r
58809
+ # A ragged block would silently write nulls into the short rows, so it is refused instead.\r
58810
+ for ($r = 0; $r -lt $rowCount; $r++) {\r
58811
+ $width = @($rows[$r]).Count\r
58812
+ if ($width -ne $columnCount) {\r
58813
+ throw "Row $($r + 1) has $width value(s) but the first row has $columnCount; every row must be the same width."\r
58814
+ }\r
58815
+ }\r
58816
+ \r
58817
+ $target = $sheet.Range($Request.cell).Resize($rowCount, $columnCount)\r
58818
+ \r
58819
+ # What is being replaced, captured before anything is written.\r
58820
+ $existing = $target.Formula\r
58821
+ $before = @()\r
58822
+ for ($r = 1; $r -le $rowCount; $r++) {\r
58823
+ for ($c = 1; $c -le $columnCount; $c++) {\r
58824
+ $was = if ($rowCount -eq 1 -and $columnCount -eq 1) { $existing } else { $existing[$r, $c] }\r
58825
+ if ($null -ne $was -and "$was" -ne '') {\r
58826
+ $before += [ordered]@{\r
58827
+ address = (Get-CellAddress -Row ($target.Row + $r - 1) -Column ($target.Column + $c - 1))\r
58828
+ was = [string]$was\r
58829
+ }\r
58830
+ }\r
58831
+ }\r
58832
+ }\r
58833
+ \r
58834
+ $block = New-Object 'object[,]' $rowCount, $columnCount\r
58835
+ for ($r = 0; $r -lt $rowCount; $r++) {\r
58836
+ $row = @($rows[$r])\r
58837
+ for ($c = 0; $c -lt $columnCount; $c++) {\r
58838
+ $block[$r, $c] = $row[$c]\r
58839
+ }\r
58840
+ }\r
58841
+ \r
58842
+ $target.Formula = $block\r
58843
+ \r
58844
+ # Read back what Excel made of it. A formula that lands as #N/A or #REF! is the whole reason\r
58845
+ # this is reported rather than assumed - it would otherwise sit there unnoticed.\r
58846
+ $after = @()\r
58847
+ $computed = $target.Value2\r
58848
+ for ($r = 1; $r -le $rowCount; $r++) {\r
58849
+ for ($c = 1; $c -le $columnCount; $c++) {\r
58850
+ $value = if ($rowCount -eq 1 -and $columnCount -eq 1) { $computed } else { $computed[$r, $c] }\r
58851
+ $converted = Convert-ExcelValue -Value $value\r
58852
+ $after += [ordered]@{\r
58853
+ address = (Get-CellAddress -Row ($target.Row + $r - 1) -Column ($target.Column + $c - 1))\r
58854
+ value = $converted\r
58855
+ }\r
58856
+ }\r
58857
+ }\r
58858
+ \r
58859
+ return @{\r
58860
+ workbook = $wb.Name\r
58861
+ sheet = $sheet.Name\r
58862
+ range = $target.Address(0, 0)\r
58863
+ written = $rowCount * $columnCount\r
58864
+ overwritten = $before\r
58865
+ cells = $after\r
58866
+ }\r
58867
+ }\r
58868
+ \r
58639
58869
  function Invoke-ExcelReadRange {\r
58640
58870
  param($Request)\r
58641
58871
  \r
@@ -59755,6 +59985,7 @@ function Invoke-Request {\r
59755
59985
  'excel.sessions' { return Invoke-ExcelSessions }\r
59756
59986
  'excel.diagnose' { return Invoke-ExcelDiagnose }\r
59757
59987
  'excel.readRange' { return Invoke-ExcelReadRange -Request $Request }\r
59988
+ 'excel.writeRange' { return Invoke-ExcelWriteRange -Request $Request }\r
59758
59989
  'excel.trace' { return Invoke-ExcelTrace -Request $Request }\r
59759
59990
  'excel.listMacros' { return Invoke-ExcelListMacros -Request $Request }\r
59760
59991
  'excel.readMacro' { return Invoke-ExcelReadMacro -Request $Request }\r
@@ -61916,8 +62147,8 @@ ${preview.text}` } : {}
61916
62147
  }
61917
62148
  for (const tool of python.generatedTools())
61918
62149
  combined.register(tool, { dispatchOnly: dispatcher });
61919
- combined.register(createUpdatePlanTool(planAccess), { dispatchOnly: dispatcher });
61920
- combined.register(createPlanProgressTool(planAccess), { dispatchOnly: dispatcher });
62150
+ combined.register(createUpdatePlanTool(planAccess));
62151
+ combined.register(createPlanProgressTool(planAccess));
61921
62152
  combined.register(createReadRolePromptTool(rolePromptAccess), { dispatchOnly: dispatcher });
61922
62153
  combined.register(createUpdateRolePromptTool(rolePromptAccess), { dispatchOnly: dispatcher });
61923
62154
  combined.register(createCreateRoleTool(rolePromptAccess), { dispatchOnly: dispatcher });
@@ -62022,6 +62253,7 @@ ${preview.text}` } : {}
62022
62253
  combined.register(createExcelListMacrosTool(officeOptions));
62023
62254
  combined.register(createExcelReadMacroTool(officeOptions));
62024
62255
  combined.register(createExcelWriteMacroTool(officeOptions));
62256
+ combined.register(createExcelWriteRangeTool(officeOptions));
62025
62257
  combined.register(createExcelCheckMacroTool(officeOptions));
62026
62258
  combined.register(createExcelEvaluateTool(officeOptions));
62027
62259
  combined.register(createExcelRunMacroTool(officeOptions));
@@ -62111,7 +62343,7 @@ ${preview.text}` } : {}
62111
62343
  ...cachedAssessment === void 0 ? {} : { juniorAssessment: cachedAssessment },
62112
62344
  // `ask_expert` itself is excluded: telling the expert it can consult itself is
62113
62345
  // noise at best and a loop at worst.
62114
- promptTools: combined.promptList().filter((tool) => tool.name !== "ask_expert"),
62346
+ promptTools: combined.promptList().filter((tool) => tool.name !== ASK_CLAUDE_TOOL),
62115
62347
  dispatchOnlyTools: combined.dispatchOnlyList(),
62116
62348
  skills,
62117
62349
  retrievalAvailable: combined.get("search_docs") !== void 0
@@ -63948,11 +64180,22 @@ ${direction}` : attachMentions(text, mentions);
63948
64180
  }
63949
64181
  }
63950
64182
  async function handleRefreshMail(days) {
63951
- if (mailBusy)
64183
+ if (mailBusy) {
64184
+ mailLastResult = "A mail sync is already running \u2014 wait for it to finish, then try again.";
64185
+ await postMailStatus();
63952
64186
  return;
64187
+ }
63953
64188
  const config2 = await loadSettings();
63954
- if (cachedOffice.outlook !== true || !officeAvailable())
64189
+ if (cachedOffice.outlook !== true) {
64190
+ mailLastResult = "Outlook is switched off in Settings \u2192 Tools.";
64191
+ await postMailStatus();
64192
+ return;
64193
+ }
64194
+ if (!officeAvailable()) {
64195
+ mailLastResult = "Outlook is not available on this host.";
64196
+ await postMailStatus();
63955
64197
  return;
64198
+ }
63956
64199
  const chosen = config2.mail?.folders ?? [];
63957
64200
  if (chosen.length === 0) {
63958
64201
  mailLastResult = "No folders selected.";
@@ -66890,20 +67133,32 @@ function toolCallSummary(call, outcome) {
66890
67133
  };
66891
67134
  }
66892
67135
  function consultationFromToolCall(name, rawArguments) {
66893
- if (name === "ask_expert")
67136
+ const call = throughDispatch(name, rawArguments);
67137
+ if (call.name === ASK_CLAUDE_TOOL || call.name === LEGACY_ASK_EXPERT_TOOL)
66894
67138
  return "expert";
66895
- if (name !== "ask_agent")
67139
+ if (call.name !== "ask_agent")
66896
67140
  return void 0;
66897
- const decoded = decodeArguments(rawArguments);
67141
+ const decoded = call.args;
66898
67142
  const role = typeof decoded === "object" && decoded !== null ? decoded.role : void 0;
66899
67143
  return typeof role === "string" && role.trim().length > 0 ? role.trim().toLowerCase() : "unknown";
66900
67144
  }
66901
67145
  function chartFromToolCall(name, rawArguments) {
66902
- if (name !== "show_chart")
67146
+ const call = throughDispatch(name, rawArguments);
67147
+ if (call.name !== "show_chart")
66903
67148
  return void 0;
66904
- const parsed = chartSpecSchema.safeParse(decodeArguments(rawArguments));
67149
+ const parsed = chartSpecSchema.safeParse(call.args);
66905
67150
  return parsed.success ? { kind: "chart", chart: parsed.data } : { kind: "chartError", message: parsed.error.issues.map((issue2) => issue2.message).join("; ") };
66906
67151
  }
67152
+ function throughDispatch(name, rawArguments) {
67153
+ const decoded = decodeArguments(rawArguments);
67154
+ if (name !== CALL_TOOL_NAME || typeof decoded !== "object" || decoded === null) {
67155
+ return { name, args: decoded };
67156
+ }
67157
+ const inner = decoded;
67158
+ if (typeof inner.name !== "string" || inner.name.length === 0)
67159
+ return { name, args: decoded };
67160
+ return { name: inner.name, args: inner.arguments ?? {} };
67161
+ }
66907
67162
  function decodeArguments(raw) {
66908
67163
  try {
66909
67164
  return JSON.parse(raw.length > 0 ? raw : "{}");
@@ -69309,6 +69564,18 @@ var CONTENT_TYPES = {
69309
69564
  // through <img> cannot run script, whatever it contains.
69310
69565
  ".svg": "image/svg+xml"
69311
69566
  };
69567
+ var STREAM_PADDING_BYTES = 8192;
69568
+ var STREAM_PADDING = `: ${(() => {
69569
+ let filler = "";
69570
+ let seed = 1;
69571
+ while (filler.length < STREAM_PADDING_BYTES) {
69572
+ seed = (seed * 1103515245 + 12345) % 2147483648;
69573
+ filler += (seed % 36).toString(36);
69574
+ }
69575
+ return filler;
69576
+ })()}
69577
+
69578
+ `;
69312
69579
  async function startServer(options) {
69313
69580
  const log = options.logSink ?? ((line) => process.stderr.write(`${line}
69314
69581
  `));
@@ -69549,6 +69816,7 @@ async function startServer(options) {
69549
69816
  "Cache-Control": "no-store, no-transform",
69550
69817
  "X-Accel-Buffering": "no"
69551
69818
  });
69819
+ response.write(STREAM_PADDING);
69552
69820
  response.write(": connected\n\n");
69553
69821
  const viaAdminUrl = url2.searchParams.get("view") === "admin";
69554
69822
  if (viaAdminUrl) adminConnections.add(principal.id);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chosengeneration/light-code",
3
- "version": "0.59.1",
3
+ "version": "0.59.8",
4
4
  "description": "A minimal agentic coding assistant, served to your browser from a local Node server",
5
5
  "license": "MIT",
6
6
  "type": "module",