kimiflare 0.95.0 → 0.96.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 +52 -23
- package/dist/index.js.map +1 -1
- package/dist/sdk/index.d.ts +1 -0
- package/dist/sdk/index.js +4865 -4863
- package/dist/sdk/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -40,6 +40,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
40
40
|
// src/config.ts
|
|
41
41
|
var config_exports = {};
|
|
42
42
|
__export(config_exports, {
|
|
43
|
+
DEFAULT_CLOUD_MODEL: () => DEFAULT_CLOUD_MODEL,
|
|
43
44
|
DEFAULT_MODEL: () => DEFAULT_MODEL,
|
|
44
45
|
DEFAULT_REASONING_EFFORT: () => DEFAULT_REASONING_EFFORT,
|
|
45
46
|
EFFORTS: () => EFFORTS,
|
|
@@ -388,12 +389,13 @@ async function saveConfig(cfg) {
|
|
|
388
389
|
await chmod(p, 384);
|
|
389
390
|
return p;
|
|
390
391
|
}
|
|
391
|
-
var EFFORTS, DEFAULT_MODEL, DEFAULT_REASONING_EFFORT;
|
|
392
|
+
var EFFORTS, DEFAULT_MODEL, DEFAULT_CLOUD_MODEL, DEFAULT_REASONING_EFFORT;
|
|
392
393
|
var init_config = __esm({
|
|
393
394
|
"src/config.ts"() {
|
|
394
395
|
"use strict";
|
|
395
396
|
EFFORTS = ["low", "medium", "high"];
|
|
396
397
|
DEFAULT_MODEL = "@cf/moonshotai/kimi-k2.6";
|
|
398
|
+
DEFAULT_CLOUD_MODEL = "@cf/moonshotai/kimi-k2.7-code";
|
|
397
399
|
DEFAULT_REASONING_EFFORT = "medium";
|
|
398
400
|
}
|
|
399
401
|
});
|
|
@@ -2240,7 +2242,7 @@ async function* runKimi(opts2) {
|
|
|
2240
2242
|
`Your stored ${modelProvider} key is likely invalid or expired. Fix:`,
|
|
2241
2243
|
` /keys set ${modelProvider} <new-key> replace the stored key`,
|
|
2242
2244
|
` /keys clear ${modelProvider} remove it and reopen the picker to paste fresh`,
|
|
2243
|
-
` /model
|
|
2245
|
+
` /model ${opts2.cloudMode ? DEFAULT_CLOUD_MODEL : DEFAULT_MODEL} switch back to Workers AI (no key needed)`
|
|
2244
2246
|
].join("\n") : msg;
|
|
2245
2247
|
const apiErr = new KimiApiError(`kimiflare: ${wrappedMsg}`, err?.code, res.status);
|
|
2246
2248
|
if (isRetryable(apiErr, attempt)) {
|
|
@@ -2320,7 +2322,7 @@ function validateModelId(model) {
|
|
|
2320
2322
|
if (/^[a-zA-Z0-9_-]+\/[a-zA-Z0-9._-]+$/.test(model)) return;
|
|
2321
2323
|
throw new KimiApiError(`Invalid model ID: ${model}`, 400);
|
|
2322
2324
|
}
|
|
2323
|
-
function missingKeyMessage(model, provider, unifiedAvailable) {
|
|
2325
|
+
function missingKeyMessage(model, provider, unifiedAvailable, cloudMode) {
|
|
2324
2326
|
const doc = PROVIDER_DOC[provider] ?? { name: "your provider", where: "your provider's dashboard" };
|
|
2325
2327
|
const lines = [
|
|
2326
2328
|
`kimiflare: ${model} needs a ${doc.name} API key.`,
|
|
@@ -2331,7 +2333,8 @@ function missingKeyMessage(model, provider, unifiedAvailable) {
|
|
|
2331
2333
|
if (unifiedAvailable) {
|
|
2332
2334
|
lines.push(` 2. Enable Cloudflare Unified Billing for this gateway in the CF dashboard, then run: /keys unified on`);
|
|
2333
2335
|
}
|
|
2334
|
-
|
|
2336
|
+
const fallbackModel = cloudMode ? DEFAULT_CLOUD_MODEL : DEFAULT_MODEL;
|
|
2337
|
+
lines.push(` ${unifiedAvailable ? "3" : "2"}. Switch back to a Workers AI model: /model ${fallbackModel}`);
|
|
2335
2338
|
return lines.join("\n");
|
|
2336
2339
|
}
|
|
2337
2340
|
function gatewayHeadersFor(opts2) {
|
|
@@ -2394,7 +2397,7 @@ function buildKimiRequestTarget(opts2) {
|
|
|
2394
2397
|
headers["cf-aig-authorization"] = `Bearer ${providerKey}`;
|
|
2395
2398
|
} else {
|
|
2396
2399
|
throw new KimiApiError(
|
|
2397
|
-
missingKeyMessage(opts2.model, entry.provider, entry.billingMode === "unified"),
|
|
2400
|
+
missingKeyMessage(opts2.model, entry.provider, entry.billingMode === "unified", opts2.cloudMode),
|
|
2398
2401
|
void 0,
|
|
2399
2402
|
401
|
|
2400
2403
|
);
|
|
@@ -2573,6 +2576,7 @@ var init_client = __esm({
|
|
|
2573
2576
|
init_log_sink();
|
|
2574
2577
|
init_llm_dump();
|
|
2575
2578
|
init_registry();
|
|
2579
|
+
init_config();
|
|
2576
2580
|
RETRYABLE_CODES = /* @__PURE__ */ new Set([3040]);
|
|
2577
2581
|
MAX_ATTEMPTS = 5;
|
|
2578
2582
|
PROVIDER_DOC = {
|
|
@@ -7844,7 +7848,7 @@ var init_spawn_worker = __esm({
|
|
|
7844
7848
|
},
|
|
7845
7849
|
model: {
|
|
7846
7850
|
type: "string",
|
|
7847
|
-
description:
|
|
7851
|
+
description: `Model to use for the worker. Defaults to ${DEFAULT_MODEL} (or ${DEFAULT_CLOUD_MODEL} in cloud mode).`
|
|
7848
7852
|
},
|
|
7849
7853
|
branchName: {
|
|
7850
7854
|
type: "string",
|
|
@@ -7882,6 +7886,7 @@ var init_spawn_worker = __esm({
|
|
|
7882
7886
|
const timeoutMs = readNumberEnv2("KIMIFLARE_WORKER_TIMEOUT_MS") ?? DEFAULT_WORKER_TIMEOUT_MS;
|
|
7883
7887
|
const cfg = await loadConfig().catch(() => null);
|
|
7884
7888
|
const budgetUsd = resolveWorkerBudgetUsd(cfg);
|
|
7889
|
+
const defaultModel = cfg?.cloudMode ? DEFAULT_CLOUD_MODEL : DEFAULT_MODEL;
|
|
7885
7890
|
const payload = {
|
|
7886
7891
|
mode: args.mode,
|
|
7887
7892
|
task: args.task,
|
|
@@ -7889,7 +7894,7 @@ var init_spawn_worker = __esm({
|
|
|
7889
7894
|
budget: { maxCostUsd: budgetUsd },
|
|
7890
7895
|
outputFormat: args.outputFormat ?? "structured",
|
|
7891
7896
|
tools: args.tools ?? (args.mode === "plan" ? "read-only" : "all"),
|
|
7892
|
-
model: args.model ??
|
|
7897
|
+
model: args.model ?? defaultModel,
|
|
7893
7898
|
...args.mode === "execute" ? {
|
|
7894
7899
|
branchName: args.branchName,
|
|
7895
7900
|
baseBranch: args.baseBranch ?? "main",
|
|
@@ -10868,7 +10873,7 @@ function setupRoutes(config2) {
|
|
|
10868
10873
|
if (pathname === "/prompt" && method === "POST") {
|
|
10869
10874
|
const body = await readBody(req);
|
|
10870
10875
|
const prompt = typeof body.prompt === "string" ? body.prompt : "";
|
|
10871
|
-
const model = typeof body.model === "string" ? body.model : config2.model ??
|
|
10876
|
+
const model = typeof body.model === "string" ? body.model : config2.model ?? (config2.cloudMode ? DEFAULT_CLOUD_MODEL : DEFAULT_MODEL);
|
|
10872
10877
|
const cwd = typeof body.cwd === "string" ? body.cwd : process.cwd();
|
|
10873
10878
|
const title = typeof body.title === "string" ? body.title : void 0;
|
|
10874
10879
|
const files = Array.isArray(body.files) ? body.files.filter((f) => typeof f === "string") : [];
|
|
@@ -11043,6 +11048,7 @@ var activeSessions;
|
|
|
11043
11048
|
var init_routes = __esm({
|
|
11044
11049
|
"src/server/routes.ts"() {
|
|
11045
11050
|
"use strict";
|
|
11051
|
+
init_config();
|
|
11046
11052
|
init_loop();
|
|
11047
11053
|
init_system_prompt();
|
|
11048
11054
|
init_executor();
|
|
@@ -11827,6 +11833,7 @@ var init_manager2 = __esm({
|
|
|
11827
11833
|
init_schema();
|
|
11828
11834
|
init_db2();
|
|
11829
11835
|
init_embeddings();
|
|
11836
|
+
init_config();
|
|
11830
11837
|
init_retrieval();
|
|
11831
11838
|
init_cleanup();
|
|
11832
11839
|
SECRET_PATTERNS = [
|
|
@@ -11877,7 +11884,7 @@ Return a JSON array of strings. Example:
|
|
|
11877
11884
|
return {
|
|
11878
11885
|
accountId: this.opts.accountId,
|
|
11879
11886
|
apiToken: this.opts.apiToken,
|
|
11880
|
-
model: this.opts.model ??
|
|
11887
|
+
model: this.opts.model ?? (this.opts.cloudMode ? DEFAULT_CLOUD_MODEL : DEFAULT_MODEL),
|
|
11881
11888
|
gateway: this.opts.gateway
|
|
11882
11889
|
};
|
|
11883
11890
|
}
|
|
@@ -13717,7 +13724,8 @@ async function createAgentSession(opts2) {
|
|
|
13717
13724
|
extractionModel: config2.memoryExtractionModel,
|
|
13718
13725
|
embeddingModel: config2.memoryEmbeddingModel,
|
|
13719
13726
|
maxAgeDays: config2.memoryMaxAgeDays,
|
|
13720
|
-
maxEntries: config2.memoryMaxEntries
|
|
13727
|
+
maxEntries: config2.memoryMaxEntries,
|
|
13728
|
+
cloudMode: config2.cloudMode
|
|
13721
13729
|
});
|
|
13722
13730
|
memoryManager.open();
|
|
13723
13731
|
}
|
|
@@ -14849,6 +14857,7 @@ var init_supervisor = __esm({
|
|
|
14849
14857
|
logger.warn("supervisor:mcp_export_failed", { error: err.message });
|
|
14850
14858
|
}
|
|
14851
14859
|
}
|
|
14860
|
+
const defaultWorkerModel = cfg?.cloudMode ? DEFAULT_CLOUD_MODEL : DEFAULT_MODEL;
|
|
14852
14861
|
const payload = {
|
|
14853
14862
|
mode: w.mode,
|
|
14854
14863
|
task: w.task,
|
|
@@ -14858,7 +14867,7 @@ ${w.context ?? ""}` : w.context ?? "",
|
|
|
14858
14867
|
budget: { maxCostUsd },
|
|
14859
14868
|
outputFormat: "structured",
|
|
14860
14869
|
tools: w.mode === "plan" ? "read-only" : "all",
|
|
14861
|
-
model: w.model ??
|
|
14870
|
+
model: w.model ?? defaultWorkerModel,
|
|
14862
14871
|
// Sandbox-driven worker needs the repo to clone:
|
|
14863
14872
|
githubToken: repo.token,
|
|
14864
14873
|
owner: repo.owner,
|
|
@@ -28871,7 +28880,7 @@ function executeFreshStart(ctx, planText, overrideMode, opts2 = {}) {
|
|
|
28871
28880
|
rebuildSystemPromptForMode(
|
|
28872
28881
|
ctx.messagesRef.current,
|
|
28873
28882
|
ctx.cacheStableRef.current,
|
|
28874
|
-
ctx.cfg?.model ??
|
|
28883
|
+
ctx.cfg?.model ?? (ctx.cfg?.cloudMode ? DEFAULT_CLOUD_MODEL : DEFAULT_MODEL),
|
|
28875
28884
|
overrideMode ?? ctx.mode,
|
|
28876
28885
|
[...ALL_TOOLS, ...ctx.mcpToolsRef.current, ...ctx.lspToolsRef.current],
|
|
28877
28886
|
ctx.cfg?.preferPullRequests
|
|
@@ -31509,7 +31518,8 @@ function runStartupTasks(deps) {
|
|
|
31509
31518
|
embeddingModel: cfg.memoryEmbeddingModel,
|
|
31510
31519
|
gateway: gatewayFromConfig(cfg),
|
|
31511
31520
|
maxAgeDays: cfg.memoryMaxAgeDays ?? RETENTION.memoryMaxAgeDays,
|
|
31512
|
-
maxEntries: cfg.memoryMaxEntries ?? RETENTION.memoryMaxEntries
|
|
31521
|
+
maxEntries: cfg.memoryMaxEntries ?? RETENTION.memoryMaxEntries,
|
|
31522
|
+
cloudMode: cfg.cloudMode
|
|
31513
31523
|
});
|
|
31514
31524
|
manager.open();
|
|
31515
31525
|
memoryManagerRef.current = manager;
|
|
@@ -34985,6 +34995,7 @@ init_errors();
|
|
|
34985
34995
|
init_lsp_config();
|
|
34986
34996
|
init_update_check();
|
|
34987
34997
|
init_version();
|
|
34998
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
34988
34999
|
import { Command as Command2 } from "commander";
|
|
34989
35000
|
|
|
34990
35001
|
// src/remote/cli.ts
|
|
@@ -35111,11 +35122,12 @@ var LOGO_ART = `\x1B[49m \x1B[m
|
|
|
35111
35122
|
\x1B[49m \x1B[m
|
|
35112
35123
|
`;
|
|
35113
35124
|
var LOGO_WIDTH = 48;
|
|
35114
|
-
function buildTextLines(version) {
|
|
35125
|
+
function buildTextLines(version, cloudMode) {
|
|
35115
35126
|
const accent = "\x1B[38;2;255;153;0m";
|
|
35116
35127
|
const dim = "\x1B[2m";
|
|
35117
35128
|
const reset = "\x1B[0m";
|
|
35118
35129
|
const bold = "\x1B[1m";
|
|
35130
|
+
const modelLabel = cloudMode ? "Kimi-K2.7" : "Kimi-K2.6";
|
|
35119
35131
|
return [
|
|
35120
35132
|
"",
|
|
35121
35133
|
"",
|
|
@@ -35126,7 +35138,7 @@ function buildTextLines(version) {
|
|
|
35126
35138
|
` ${bold}${accent}Kimiflare${reset}`,
|
|
35127
35139
|
"",
|
|
35128
35140
|
` ${dim}Terminal coding agent${reset}`,
|
|
35129
|
-
` ${dim}powered by
|
|
35141
|
+
` ${dim}powered by ${modelLabel}${reset}`,
|
|
35130
35142
|
"",
|
|
35131
35143
|
` ${dim}v${version}${reset}`,
|
|
35132
35144
|
"",
|
|
@@ -35150,9 +35162,9 @@ function padVisual(str, width) {
|
|
|
35150
35162
|
const visualLen = stripAnsi(str).length;
|
|
35151
35163
|
return str + " ".repeat(Math.max(0, width - visualLen));
|
|
35152
35164
|
}
|
|
35153
|
-
function renderLogo(version) {
|
|
35165
|
+
function renderLogo(version, cloudMode) {
|
|
35154
35166
|
const logoLines = LOGO_ART.split("\n");
|
|
35155
|
-
const textLines = buildTextLines(version);
|
|
35167
|
+
const textLines = buildTextLines(version, cloudMode);
|
|
35156
35168
|
const out = [];
|
|
35157
35169
|
for (let i = 0; i < logoLines.length; i++) {
|
|
35158
35170
|
const logoLine = padVisual(logoLines[i], LOGO_WIDTH);
|
|
@@ -35509,8 +35521,20 @@ async function runPrintMode(opts2) {
|
|
|
35509
35521
|
}
|
|
35510
35522
|
|
|
35511
35523
|
// src/index.tsx
|
|
35524
|
+
function isCloudModeConfigured() {
|
|
35525
|
+
if (process.env.KIMIFLARE_CLOUD === "1" || process.env.KIMIFLARE_CLOUD === "true") return true;
|
|
35526
|
+
try {
|
|
35527
|
+
const raw = readFileSync5(configPath(), "utf8");
|
|
35528
|
+
const parsed = JSON.parse(raw);
|
|
35529
|
+
return parsed.cloudMode === true;
|
|
35530
|
+
} catch {
|
|
35531
|
+
return false;
|
|
35532
|
+
}
|
|
35533
|
+
}
|
|
35534
|
+
var helpDefaultModel = isCloudModeConfigured() ? DEFAULT_CLOUD_MODEL : DEFAULT_MODEL;
|
|
35535
|
+
var helpModelName = helpDefaultModel === DEFAULT_CLOUD_MODEL ? "Kimi-K2.7" : "Kimi-K2.6";
|
|
35512
35536
|
var program = new Command2();
|
|
35513
|
-
program.name("kimiflare").description(
|
|
35537
|
+
program.name("kimiflare").description(`Terminal coding agent powered by ${helpModelName} on Cloudflare Workers AI.`).version(getAppVersion()).option("-p, --print <prompt>", "one-shot mode: send prompt, stream reply to stdout, exit").option("-m, --model <id>", `model id (defaults to ${helpDefaultModel})`).option("--cloud", "use Kimiflare Cloud (api.kimiflare.com) instead of direct Workers AI").option("--dangerously-allow-all", "auto-approve every permission prompt (print mode only)").option("--reasoning", "include reasoning in stdout (print mode only)").option("--thinking", "alias for --reasoning").option("--continue-on-limit", "reset tool-call counter and continue when the 200-call limit is hit (print mode only)").option("--max-input-tokens <n>", "cumulative prompt token budget; exits 42 when exhausted (print mode only)", (v) => parseInt(v, 10)).option("--emit-events", "emit Camouflage NDJSON events to stdout; requires -p (for initial prompt)").option("--multi-turn", "with --emit-events: keep reading stdin for UserInputSubmitted follow-ups after the initial turn").option("--ui <name>", "render UI with React Ink (the only supported engine). This flag and KIMIFLARE_UI are currently ignored.").option("--mode <mode>", "run mode: interactive (default), print, rpc").option("-c, --continue", "continue the most recent session in the current working directory (print mode only)").option("-S, --session <id>", "resume a specific session by id (print mode only)").option("-f, --file <path>", "attach file(s) to the prompt; repeatable, supports globs (print mode only)", (v, prev) => (prev ?? []).concat(v)).option("--format <mode>", "output format for print mode: text (default), json, stream-json").option("--dir <path>", "run in the specified directory instead of the current one (print mode only)").option("--title <title>", "override the auto-generated session title (print mode only)").option("--attach <url>", "attach to a running kimiflare serve instance (print mode only)");
|
|
35514
35538
|
program.command("cost").description("Show cost attribution by task type (requires costAttribution enabled)").option("-w, --week", "last 7 days (default)").option("-m, --month", "last 30 days").option("-d, --day", "today only").option("-s, --session <id>", "single session detail").option("-c, --category <name>", "filter by category").option("--json", "machine-readable output").option("--reclassify", "re-run classification on all sessions").option("--local-only", "skip Cloudflare reconciliation").action(async (cmdOpts) => {
|
|
35515
35539
|
const cfg = await loadConfig();
|
|
35516
35540
|
const enabled = cfg?.costAttribution ?? false;
|
|
@@ -35682,7 +35706,7 @@ async function main() {
|
|
|
35682
35706
|
}
|
|
35683
35707
|
}
|
|
35684
35708
|
cfg = {
|
|
35685
|
-
...cfg ?? { accountId: "", apiToken: "", model:
|
|
35709
|
+
...cfg ?? { accountId: "", apiToken: "", model: DEFAULT_CLOUD_MODEL, memoryEnabled: false },
|
|
35686
35710
|
cloudMode: true
|
|
35687
35711
|
};
|
|
35688
35712
|
}
|
|
@@ -35702,7 +35726,7 @@ async function main() {
|
|
|
35702
35726
|
console.error("kimiflare: --emit-events requires credentials.");
|
|
35703
35727
|
process.exit(2);
|
|
35704
35728
|
}
|
|
35705
|
-
const model = opts.model ?? cfg.model ?? DEFAULT_MODEL;
|
|
35729
|
+
const model = opts.model ?? cfg.model ?? (cloudMode ? DEFAULT_CLOUD_MODEL : DEFAULT_MODEL);
|
|
35706
35730
|
const { runEmitMode: runEmitMode2 } = await Promise.resolve().then(() => (init_emit_mode(), emit_mode_exports));
|
|
35707
35731
|
await runEmitMode2({
|
|
35708
35732
|
accountId: cfg.accountId,
|
|
@@ -35721,13 +35745,18 @@ async function main() {
|
|
|
35721
35745
|
return;
|
|
35722
35746
|
}
|
|
35723
35747
|
if (opts.print !== void 0) {
|
|
35748
|
+
const exampleModel = cloudMode ? DEFAULT_CLOUD_MODEL : DEFAULT_MODEL;
|
|
35724
35749
|
if (!cfg) {
|
|
35725
35750
|
console.error(
|
|
35726
|
-
|
|
35751
|
+
`kimiflare: missing credentials.
|
|
35752
|
+
Set CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_TOKEN, or write them to
|
|
35753
|
+
~/.config/kimiflare/config.json (chmod 600)
|
|
35754
|
+
{ "accountId": "...", "apiToken": "...", "model": "${exampleModel}" }
|
|
35755
|
+
Or use cloud mode: kimiflare --cloud -p "..."`
|
|
35727
35756
|
);
|
|
35728
35757
|
process.exit(2);
|
|
35729
35758
|
}
|
|
35730
|
-
const model = opts.model ?? cfg.model ?? DEFAULT_MODEL;
|
|
35759
|
+
const model = opts.model ?? cfg.model ?? (cloudMode ? DEFAULT_CLOUD_MODEL : DEFAULT_MODEL);
|
|
35731
35760
|
const format = opts.format ?? "text";
|
|
35732
35761
|
if (format !== "text" && format !== "json" && format !== "stream-json") {
|
|
35733
35762
|
console.error(`kimiflare: invalid --format "${format}". Use: text, json, stream-json`);
|
|
@@ -35775,7 +35804,7 @@ async function main() {
|
|
|
35775
35804
|
);
|
|
35776
35805
|
process.exit(2);
|
|
35777
35806
|
}
|
|
35778
|
-
const logoText = renderLogo(getAppVersion());
|
|
35807
|
+
const logoText = renderLogo(getAppVersion(), cloudMode);
|
|
35779
35808
|
const uiEngine = "ink";
|
|
35780
35809
|
console.log(logoText);
|
|
35781
35810
|
const { renderApp: renderApp2 } = await Promise.resolve().then(() => (init_app(), app_exports));
|