kimiflare 0.53.0 → 0.54.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1948,24 +1948,40 @@ ${jsCode}
1948
1948
  }
1949
1949
  return { output: logs.join("\n"), logs, toolCalls, warnings };
1950
1950
  }
1951
+ function buildFallbackWarning(errMessage) {
1952
+ let reason;
1953
+ let fix;
1954
+ if (errMessage.includes("Cannot find module") || errMessage.includes("isolated-vm")) {
1955
+ reason = "The optional dependency `isolated-vm` is not installed.";
1956
+ fix = "Run `npm install isolated-vm` in your project (or `npm install -g isolated-vm` if KimiFlare is installed globally).";
1957
+ } else if (errMessage.includes("bindings") || errMessage.includes(".node")) {
1958
+ reason = "The `isolated-vm` native bindings are incompatible with this Node version or architecture.";
1959
+ fix = "Try `npm rebuild isolated-vm`, or switch to Node 22 LTS if you're on Apple Silicon.";
1960
+ } else {
1961
+ reason = "The secure sandbox (`isolated-vm`) could not be loaded.";
1962
+ fix = "Ensure build tools are installed, then run `npm install isolated-vm`.";
1963
+ }
1964
+ return `Code Mode is using the built-in Node.js sandbox. Tool execution works normally, but without memory limits or full process isolation. ${reason} ${fix}`;
1965
+ }
1951
1966
  async function runInSandbox(opts2) {
1952
1967
  try {
1953
1968
  return await runWithIsolatedVm(opts2);
1954
1969
  } catch (err) {
1955
1970
  const message2 = err instanceof Error ? err.message : String(err);
1956
- if (message2.includes("isolated-vm") || message2.includes("Cannot find module") || message2.includes("bindings")) {
1957
- const result2 = await runWithNodeVm(opts2);
1958
- return { ...result2, warnings: [ISOLATED_VM_FALLBACK_WARNING, ...result2.warnings ?? []] };
1959
- }
1960
1971
  const result = await runWithNodeVm(opts2);
1961
- return { ...result, warnings: [ISOLATED_VM_FALLBACK_WARNING, ...result.warnings ?? []] };
1972
+ if (!fallbackWarningShown) {
1973
+ fallbackWarningShown = true;
1974
+ const warning = buildFallbackWarning(message2);
1975
+ return { ...result, warnings: [warning, ...result.warnings ?? []] };
1976
+ }
1977
+ return result;
1962
1978
  }
1963
1979
  }
1964
- var ISOLATED_VM_FALLBACK_WARNING;
1980
+ var fallbackWarningShown;
1965
1981
  var init_sandbox = __esm({
1966
1982
  "src/code-mode/sandbox.ts"() {
1967
1983
  "use strict";
1968
- ISOLATED_VM_FALLBACK_WARNING = "\u26A0\uFE0F Code sandbox is running without memory limits or true process isolation (isolated-vm unavailable or failed to load). For a secure sandbox, install with Node 22 LTS: nvm install 22 && nvm use 22 && npm install -g kimiflare";
1984
+ fallbackWarningShown = false;
1969
1985
  }
1970
1986
  });
1971
1987
 
@@ -2774,13 +2790,15 @@ Use console.log() to return results. Only console.log output will be sent back t
2774
2790
  toolResults.push(toolResult);
2775
2791
  opts2.callbacks.onToolResult?.(toolResult);
2776
2792
  }
2777
- const warningPrefix = sandboxResult.warnings?.length ? `Warning: ${sandboxResult.warnings.join(" ")}
2778
-
2779
- ` : "";
2780
- let resultContent = sandboxResult.error ? `${warningPrefix}Error: ${sandboxResult.error}
2793
+ if (sandboxResult.warnings && sandboxResult.warnings.length > 0) {
2794
+ for (const w of sandboxResult.warnings) {
2795
+ opts2.callbacks.onWarning?.(w);
2796
+ }
2797
+ }
2798
+ let resultContent = sandboxResult.error ? `Error: ${sandboxResult.error}
2781
2799
 
2782
2800
  Output:
2783
- ${sandboxResult.output}` : `${warningPrefix}${sandboxResult.output}`;
2801
+ ${sandboxResult.output}` : sandboxResult.output;
2784
2802
  if (resultContent.length > MAX_TOOL_CONTENT_CHARS) {
2785
2803
  resultContent = resultContent.slice(0, MAX_TOOL_CONTENT_CHARS) + `
2786
2804
 
@@ -9164,6 +9182,9 @@ var init_session = __esm({
9164
9182
  onTasks: (tasks) => {
9165
9183
  this.emit({ type: "tasks.update", tasks });
9166
9184
  },
9185
+ onWarning: (msg) => {
9186
+ this.emit({ type: "warning", message: msg });
9187
+ },
9167
9188
  askPermission: async (req) => {
9168
9189
  if (mode === "auto") return "allow";
9169
9190
  if (mode === "plan") {
@@ -10739,7 +10760,8 @@ function StatusBar({ usage, sessionUsage, thinking, turnStartedAt, mode, context
10739
10760
  " \xB7 ",
10740
10761
  "\u26A0 KIMI.md stale \xB7 run /init"
10741
10762
  ] }) : null
10742
- ] })
10763
+ ] }),
10764
+ !thinking && /* @__PURE__ */ jsx7(Box6, { children: /* @__PURE__ */ jsx7(Text6, { color: theme.muted?.color ?? theme.info.color, dimColor: theme.muted?.dim, children: "tip: shift+tab cycles mode" }) })
10743
10765
  ] });
10744
10766
  }
10745
10767
  function buildRightParts(usage, contextLimit, sessionUsage, gatewayMeta, cloudMode, cloudBudget) {
@@ -18113,6 +18135,16 @@ ${wcagWarnings.join("\n")}` }
18113
18135
  const isDenied = typeof r.content === "string" && r.content.startsWith("Permission denied");
18114
18136
  updateTool(r.tool_call_id, { status: isDenied ? "rejected" : r.ok ? "done" : "error", result: r.content });
18115
18137
  },
18138
+ onWarning: (msg) => {
18139
+ setEvents((e) => [
18140
+ ...e,
18141
+ {
18142
+ kind: "info",
18143
+ key: mkKey(),
18144
+ text: msg
18145
+ }
18146
+ ]);
18147
+ },
18116
18148
  onUsage: (u) => {
18117
18149
  usageRef.current = u;
18118
18150
  setUsage(u);
@@ -20622,6 +20654,10 @@ async function runPrintMode(opts2) {
20622
20654
  onToolResult: (result) => {
20623
20655
  const snippet = result.content.length > 400 ? result.content.slice(0, 400) + "..." : result.content;
20624
20656
  process.stderr.write(`\x1B[2m[result: ${snippet.replace(/\n/g, " \u23CE ")}]\x1B[0m
20657
+ `);
20658
+ },
20659
+ onWarning: (msg) => {
20660
+ process.stderr.write(`\x1B[33mkimiflare: ${msg}\x1B[0m
20625
20661
  `);
20626
20662
  },
20627
20663
  askPermission: async ({ tool, args }) => {