kfc-code-cli 0.0.1-alpha.24 → 0.0.1-alpha.25
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/main.mjs +311 -132
- package/package.json +2 -2
package/dist/main.mjs
CHANGED
|
@@ -963,6 +963,19 @@ var ContextOverflowError = class extends KimiError {
|
|
|
963
963
|
this.name = "ContextOverflowError";
|
|
964
964
|
}
|
|
965
965
|
};
|
|
966
|
+
/**
|
|
967
|
+
* Thrown when an underlying LLM provider call fails.
|
|
968
|
+
*
|
|
969
|
+
* No default code: callers must pass a `provider.*` code (rate_limit,
|
|
970
|
+
* auth_error, api_error, connection_error) -- the specific failure mode
|
|
971
|
+
* is part of the throw site's knowledge.
|
|
972
|
+
*/
|
|
973
|
+
var ProviderError = class extends KimiError {
|
|
974
|
+
constructor(message, options) {
|
|
975
|
+
super(message, options);
|
|
976
|
+
this.name = "ProviderError";
|
|
977
|
+
}
|
|
978
|
+
};
|
|
966
979
|
//#endregion
|
|
967
980
|
//#region ../../packages/kosong/src/message.ts
|
|
968
981
|
/** Check if a streamed part is a ContentPart (text, think, image_url, audio_url, video_url). */
|
|
@@ -52839,7 +52852,7 @@ function makeErrorPayload(code, message, options) {
|
|
|
52839
52852
|
code,
|
|
52840
52853
|
message,
|
|
52841
52854
|
name: options?.name,
|
|
52842
|
-
details: options?.details,
|
|
52855
|
+
details: sanitizeErrorDetails(options?.details),
|
|
52843
52856
|
retryable: KIMI_ERROR_INFO[code].retryable
|
|
52844
52857
|
};
|
|
52845
52858
|
}
|
|
@@ -52861,7 +52874,7 @@ function toKimiErrorPayload(error) {
|
|
|
52861
52874
|
code: error.code,
|
|
52862
52875
|
message: error.message,
|
|
52863
52876
|
name: error.name,
|
|
52864
|
-
details: error.details,
|
|
52877
|
+
details: sanitizeErrorDetails(error.details),
|
|
52865
52878
|
retryable: KIMI_ERROR_INFO[error.code].retryable
|
|
52866
52879
|
};
|
|
52867
52880
|
if (error instanceof APIStatusError) {
|
|
@@ -52870,10 +52883,10 @@ function toKimiErrorPayload(error) {
|
|
|
52870
52883
|
code,
|
|
52871
52884
|
message: error.message,
|
|
52872
52885
|
name: error.name,
|
|
52873
|
-
details: {
|
|
52886
|
+
details: sanitizeErrorDetails({
|
|
52874
52887
|
statusCode: error.statusCode,
|
|
52875
52888
|
requestId: error.requestId
|
|
52876
|
-
},
|
|
52889
|
+
}),
|
|
52877
52890
|
retryable: KIMI_ERROR_INFO[code].retryable
|
|
52878
52891
|
};
|
|
52879
52892
|
}
|
|
@@ -52908,6 +52921,26 @@ function toKimiErrorPayload(error) {
|
|
|
52908
52921
|
};
|
|
52909
52922
|
}
|
|
52910
52923
|
/**
|
|
52924
|
+
* Rehydrate a KimiErrorPayload into a KimiError. Used by SDK boundary code
|
|
52925
|
+
* receiving errors over RPC to re-surface them with a real class so
|
|
52926
|
+
* in-process consumers can still use `instanceof`.
|
|
52927
|
+
*
|
|
52928
|
+
* Returns `ProviderError` for `provider.*` codes; otherwise plain
|
|
52929
|
+
* `KimiError`. We deliberately do not reconstruct the full subclass tree
|
|
52930
|
+
* because the boundary already lost class identity and the SDK only needs
|
|
52931
|
+
* one stable wrapper payload.
|
|
52932
|
+
*/
|
|
52933
|
+
function fromKimiErrorPayload(payload) {
|
|
52934
|
+
if (payload.code.startsWith("provider.")) return new ProviderError(payload.message, {
|
|
52935
|
+
code: payload.code,
|
|
52936
|
+
details: payload.details
|
|
52937
|
+
});
|
|
52938
|
+
return new KimiError(payload.message, {
|
|
52939
|
+
code: payload.code,
|
|
52940
|
+
details: payload.details
|
|
52941
|
+
});
|
|
52942
|
+
}
|
|
52943
|
+
/**
|
|
52911
52944
|
* Heuristic: kosong's `createProvider` throws plain `Error("Model not set")`
|
|
52912
52945
|
* / `Error("Provider not set")` when the runtime provider config is missing.
|
|
52913
52946
|
* Detect by message until upstream surfaces a typed error.
|
|
@@ -52916,6 +52949,51 @@ function isLlmNotSetError(error) {
|
|
|
52916
52949
|
if (!(error instanceof Error)) return false;
|
|
52917
52950
|
return error.message === "Model not set" || error.message === "Provider not set";
|
|
52918
52951
|
}
|
|
52952
|
+
function sanitizeErrorDetails(details) {
|
|
52953
|
+
if (details === void 0) return void 0;
|
|
52954
|
+
const sanitized = sanitizeJsonValue(details, /* @__PURE__ */ new WeakSet());
|
|
52955
|
+
if (sanitized === void 0 || sanitized === null || typeof sanitized !== "object") return;
|
|
52956
|
+
if (Array.isArray(sanitized)) return void 0;
|
|
52957
|
+
return Object.keys(sanitized).length === 0 ? void 0 : sanitized;
|
|
52958
|
+
}
|
|
52959
|
+
function sanitizeJsonValue(value, seen) {
|
|
52960
|
+
if (value === null) return null;
|
|
52961
|
+
switch (typeof value) {
|
|
52962
|
+
case "string":
|
|
52963
|
+
case "boolean": return value;
|
|
52964
|
+
case "number": return Number.isFinite(value) ? value : null;
|
|
52965
|
+
case "bigint": return value.toString();
|
|
52966
|
+
case "undefined":
|
|
52967
|
+
case "function":
|
|
52968
|
+
case "symbol": return;
|
|
52969
|
+
}
|
|
52970
|
+
if (value instanceof Date) return Number.isNaN(value.valueOf()) ? value.toString() : value.toISOString();
|
|
52971
|
+
if (value instanceof Error) return {
|
|
52972
|
+
name: value.name,
|
|
52973
|
+
message: value.message
|
|
52974
|
+
};
|
|
52975
|
+
if (seen.has(value)) return "[Circular]";
|
|
52976
|
+
seen.add(value);
|
|
52977
|
+
if (Array.isArray(value)) {
|
|
52978
|
+
const result = value.map((item) => sanitizeJsonValue(item, seen) ?? null);
|
|
52979
|
+
seen.delete(value);
|
|
52980
|
+
return result;
|
|
52981
|
+
}
|
|
52982
|
+
const result = {};
|
|
52983
|
+
for (const key of Object.keys(value)) {
|
|
52984
|
+
let rawItem;
|
|
52985
|
+
try {
|
|
52986
|
+
rawItem = value[key];
|
|
52987
|
+
} catch (error) {
|
|
52988
|
+
result[key] = error instanceof Error ? error.message : String(error);
|
|
52989
|
+
continue;
|
|
52990
|
+
}
|
|
52991
|
+
const item = sanitizeJsonValue(rawItem, seen);
|
|
52992
|
+
if (item !== void 0) result[key] = item;
|
|
52993
|
+
}
|
|
52994
|
+
seen.delete(value);
|
|
52995
|
+
return result;
|
|
52996
|
+
}
|
|
52919
52997
|
//#endregion
|
|
52920
52998
|
//#region ../../packages/kimi-core/src/profile/types.ts
|
|
52921
52999
|
const RawSubagentProfileSchema = z.object({ description: z.string().optional() });
|
|
@@ -60467,6 +60545,7 @@ var BackgroundProcessManager = class {
|
|
|
60467
60545
|
terminalCallbacks = [];
|
|
60468
60546
|
constructor(options = {}) {
|
|
60469
60547
|
this.options = options;
|
|
60548
|
+
this.sessionDir = options.sessionDir;
|
|
60470
60549
|
}
|
|
60471
60550
|
/**
|
|
60472
60551
|
* Register a callback that fires when any task reaches a terminal
|
|
@@ -60559,14 +60638,12 @@ var BackgroundProcessManager = class {
|
|
|
60559
60638
|
});
|
|
60560
60639
|
}
|
|
60561
60640
|
this.persistLive(entry);
|
|
60562
|
-
entry.lifecyclePromise = proc.wait().then((exitCode) => {
|
|
60563
|
-
this.settleProcessExit(entry, exitCode);
|
|
60564
|
-
}).catch((_err) => {
|
|
60641
|
+
entry.lifecyclePromise = proc.wait().then((exitCode) => this.settleProcessExit(entry, exitCode)).catch(async (_err) => {
|
|
60565
60642
|
if (!TERMINAL_STATUSES.has(entry.status)) {
|
|
60566
60643
|
entry.status = "failed";
|
|
60567
60644
|
entry.endedAt = Date.now();
|
|
60568
60645
|
}
|
|
60569
|
-
this.persistLive(entry);
|
|
60646
|
+
await this.persistLive(entry);
|
|
60570
60647
|
this.fireTerminalCallbacks(entry);
|
|
60571
60648
|
this.resolveWaiters(entry);
|
|
60572
60649
|
});
|
|
@@ -60634,7 +60711,10 @@ var BackgroundProcessManager = class {
|
|
|
60634
60711
|
async stop(taskId, reason) {
|
|
60635
60712
|
const entry = this.processes.get(taskId);
|
|
60636
60713
|
if (!entry) return void 0;
|
|
60637
|
-
if (TERMINAL_STATUSES.has(entry.status))
|
|
60714
|
+
if (TERMINAL_STATUSES.has(entry.status)) {
|
|
60715
|
+
await entry.persistWriteQueue;
|
|
60716
|
+
return this.toInfo(entry);
|
|
60717
|
+
}
|
|
60638
60718
|
entry.status = "killed";
|
|
60639
60719
|
entry.approvalReason = void 0;
|
|
60640
60720
|
entry.stopReason = reason;
|
|
@@ -60649,7 +60729,7 @@ var BackgroundProcessManager = class {
|
|
|
60649
60729
|
await entry.proc.kill("SIGKILL");
|
|
60650
60730
|
} catch {}
|
|
60651
60731
|
entry.endedAt ??= Date.now();
|
|
60652
|
-
this.persistLive(entry);
|
|
60732
|
+
await this.persistLive(entry);
|
|
60653
60733
|
this.fireTerminalCallbacks(entry);
|
|
60654
60734
|
this.resolveWaiters(entry);
|
|
60655
60735
|
return this.toInfo(entry);
|
|
@@ -60661,7 +60741,10 @@ var BackgroundProcessManager = class {
|
|
|
60661
60741
|
async wait(taskId, timeoutMs = 3e4) {
|
|
60662
60742
|
const entry = this.processes.get(taskId);
|
|
60663
60743
|
if (!entry) return void 0;
|
|
60664
|
-
if (TERMINAL_STATUSES.has(entry.status))
|
|
60744
|
+
if (TERMINAL_STATUSES.has(entry.status)) {
|
|
60745
|
+
await entry.persistWriteQueue;
|
|
60746
|
+
return this.toInfo(entry);
|
|
60747
|
+
}
|
|
60665
60748
|
let terminalWaiter;
|
|
60666
60749
|
let timeout;
|
|
60667
60750
|
try {
|
|
@@ -60678,6 +60761,7 @@ var BackgroundProcessManager = class {
|
|
|
60678
60761
|
if (index !== -1) entry.waiters.splice(index, 1);
|
|
60679
60762
|
}
|
|
60680
60763
|
}
|
|
60764
|
+
if (TERMINAL_STATUSES.has(entry.status)) await entry.persistWriteQueue;
|
|
60681
60765
|
return this.toInfo(entry);
|
|
60682
60766
|
}
|
|
60683
60767
|
/**
|
|
@@ -60741,6 +60825,12 @@ var BackgroundProcessManager = class {
|
|
|
60741
60825
|
resolve(deadlineTimeout);
|
|
60742
60826
|
}, opts.timeoutMs);
|
|
60743
60827
|
}));
|
|
60828
|
+
const finalizeLifecycle = async () => {
|
|
60829
|
+
if (deadlineTimer !== void 0) clearTimeout(deadlineTimer);
|
|
60830
|
+
await this.persistLive(entry);
|
|
60831
|
+
this.fireTerminalCallbacks(entry);
|
|
60832
|
+
this.resolveWaiters(entry);
|
|
60833
|
+
};
|
|
60744
60834
|
entry.lifecyclePromise = Promise.race(raceInputs).then((outcome) => {
|
|
60745
60835
|
if (outcome === deadlineTimeout) {
|
|
60746
60836
|
if (TERMINAL_STATUSES.has(entry.status)) return;
|
|
@@ -60768,12 +60858,9 @@ var BackgroundProcessManager = class {
|
|
|
60768
60858
|
entry.status = "failed";
|
|
60769
60859
|
entry.exitCode = 1;
|
|
60770
60860
|
entry.endedAt = Date.now();
|
|
60771
|
-
}).
|
|
60772
|
-
|
|
60773
|
-
|
|
60774
|
-
this.fireTerminalCallbacks(entry);
|
|
60775
|
-
this.resolveWaiters(entry);
|
|
60776
|
-
});
|
|
60861
|
+
}).then(finalizeLifecycle, (error) => finalizeLifecycle().then(() => {
|
|
60862
|
+
throw error;
|
|
60863
|
+
}));
|
|
60777
60864
|
entry.lifecyclePromise;
|
|
60778
60865
|
return taskId;
|
|
60779
60866
|
}
|
|
@@ -60818,10 +60905,14 @@ var BackgroundProcessManager = class {
|
|
|
60818
60905
|
async waitForTerminal(taskId) {
|
|
60819
60906
|
const entry = this.processes.get(taskId);
|
|
60820
60907
|
if (entry === void 0) return this.ghosts.get(taskId);
|
|
60821
|
-
if (TERMINAL_STATUSES.has(entry.status))
|
|
60908
|
+
if (TERMINAL_STATUSES.has(entry.status)) {
|
|
60909
|
+
await entry.persistWriteQueue;
|
|
60910
|
+
return this.toInfo(entry);
|
|
60911
|
+
}
|
|
60822
60912
|
await new Promise((resolve) => {
|
|
60823
60913
|
entry.waiters.push(resolve);
|
|
60824
60914
|
});
|
|
60915
|
+
await entry.persistWriteQueue;
|
|
60825
60916
|
return this.toInfo(entry);
|
|
60826
60917
|
}
|
|
60827
60918
|
/** Reset internal state (for testing). */
|
|
@@ -60896,7 +60987,7 @@ var BackgroundProcessManager = class {
|
|
|
60896
60987
|
* `register()` and the lifecycle finally block. No-op unless attached.
|
|
60897
60988
|
*/
|
|
60898
60989
|
persistLive(entry) {
|
|
60899
|
-
if (this.sessionDir === void 0) return;
|
|
60990
|
+
if (this.sessionDir === void 0) return Promise.resolve();
|
|
60900
60991
|
const sessionDir = this.sessionDir;
|
|
60901
60992
|
const task = {
|
|
60902
60993
|
task_id: entry.taskId,
|
|
@@ -60912,6 +61003,7 @@ var BackgroundProcessManager = class {
|
|
|
60912
61003
|
stop_reason: entry.stopReason
|
|
60913
61004
|
};
|
|
60914
61005
|
entry.persistWriteQueue = entry.persistWriteQueue.then(() => writeTask(sessionDir, task)).catch(() => {});
|
|
61006
|
+
return entry.persistWriteQueue;
|
|
60915
61007
|
}
|
|
60916
61008
|
appendOutput(entry, chunk) {
|
|
60917
61009
|
entry.outputChunks.push(chunk);
|
|
@@ -60925,12 +61017,12 @@ var BackgroundProcessManager = class {
|
|
|
60925
61017
|
if (outputSessionDir === void 0) return;
|
|
60926
61018
|
entry.outputWriteQueue = entry.outputWriteQueue.then(() => appendTaskOutput(outputSessionDir, entry.taskId, chunk)).catch(() => {});
|
|
60927
61019
|
}
|
|
60928
|
-
settleProcessExit(entry, exitCode) {
|
|
61020
|
+
async settleProcessExit(entry, exitCode) {
|
|
60929
61021
|
if (entry.exitCode !== null && entry.endedAt !== null && TERMINAL_STATUSES.has(entry.status)) return;
|
|
60930
61022
|
if (entry.status !== "killed") entry.status = exitCode === 0 ? "completed" : "failed";
|
|
60931
61023
|
entry.exitCode = exitCode;
|
|
60932
61024
|
entry.endedAt = Date.now();
|
|
60933
|
-
this.persistLive(entry);
|
|
61025
|
+
await this.persistLive(entry);
|
|
60934
61026
|
this.fireTerminalCallbacks(entry);
|
|
60935
61027
|
this.resolveWaiters(entry);
|
|
60936
61028
|
}
|
|
@@ -72324,7 +72416,7 @@ function stripLeadingDotSlash(value) {
|
|
|
72324
72416
|
* Mode overlay:
|
|
72325
72417
|
* - `yolo`: deny rules still win; everything else is allow.
|
|
72326
72418
|
* - `manual`: rule walk drives the decision; unmatched → ask.
|
|
72327
|
-
* - `auto`:
|
|
72419
|
+
* - `auto`: deny rules still win; everything else is allow.
|
|
72328
72420
|
* - Default auto-allow tools are allowed after deny rules — these
|
|
72329
72421
|
* are built-ins that do not call `Approval.request()`.
|
|
72330
72422
|
*/
|
|
@@ -72351,8 +72443,9 @@ var PermissionManager = class {
|
|
|
72351
72443
|
mode = "manual";
|
|
72352
72444
|
rules = [];
|
|
72353
72445
|
sessionApprovedActions = /* @__PURE__ */ new Set();
|
|
72354
|
-
constructor(agent) {
|
|
72446
|
+
constructor(agent, initialRules = []) {
|
|
72355
72447
|
this.agent = agent;
|
|
72448
|
+
this.rules = [...initialRules];
|
|
72356
72449
|
}
|
|
72357
72450
|
data() {
|
|
72358
72451
|
return {
|
|
@@ -72397,6 +72490,11 @@ var PermissionManager = class {
|
|
|
72397
72490
|
const id = context.toolCall.id;
|
|
72398
72491
|
const name = context.toolCall.function.name;
|
|
72399
72492
|
const args = context.args;
|
|
72493
|
+
const { decision, matchedRule } = checkRules(this.rules, name, args, this.mode);
|
|
72494
|
+
if (decision === "deny") return {
|
|
72495
|
+
block: true,
|
|
72496
|
+
reason: this.formatMessage(name, matchedRule?.reason)
|
|
72497
|
+
};
|
|
72400
72498
|
if (name === "EnterPlanMode") return void 0;
|
|
72401
72499
|
if (this.mode === "auto") {
|
|
72402
72500
|
if (name === "AskUserQuestion") return {
|
|
@@ -72412,11 +72510,6 @@ var PermissionManager = class {
|
|
|
72412
72510
|
detail: args
|
|
72413
72511
|
};
|
|
72414
72512
|
const action = describeApprovalAction(name, args, display);
|
|
72415
|
-
const { decision, matchedRule } = checkRules(this.rules, name, args, this.mode);
|
|
72416
|
-
if (decision === "deny") return {
|
|
72417
|
-
block: true,
|
|
72418
|
-
reason: this.formatMessage(name, matchedRule?.reason)
|
|
72419
|
-
};
|
|
72420
72513
|
if (this.sessionApprovedActions.has(action)) return;
|
|
72421
72514
|
if (decision === "allow") return;
|
|
72422
72515
|
const result = await this.agent.rpc.requestApproval({
|
|
@@ -73985,7 +74078,7 @@ function createChatStreamingCallbacks(deps) {
|
|
|
73985
74078
|
* enforcement, usage aggregation, optional continuation after non-tool stops,
|
|
73986
74079
|
* and final `TurnResult` mapping. One-step execution lives in `turn-step.ts`.
|
|
73987
74080
|
*/
|
|
73988
|
-
const DEFAULT_MAX_STEPS =
|
|
74081
|
+
const DEFAULT_MAX_STEPS = 1e3;
|
|
73989
74082
|
async function runTurn(input) {
|
|
73990
74083
|
const { turnId, signal, llm, buildMessages, dispatchEvent, tools, hooks, maxSteps = DEFAULT_MAX_STEPS, maxRetryAttempts } = input;
|
|
73991
74084
|
let usage = emptyUsage();
|
|
@@ -74345,6 +74438,7 @@ var TurnFlow = class {
|
|
|
74345
74438
|
const model = this.agent.config.model;
|
|
74346
74439
|
const provider = this.agent.config.provider.withThinking(this.agent.config.thinkingLevel);
|
|
74347
74440
|
const modelAlias = this.agent.config.modelAlias;
|
|
74441
|
+
const loopControl = this.agent.providerManager?.config.loopControl;
|
|
74348
74442
|
const resolveAuth = modelAlias === void 0 ? void 0 : this.agent.providerManager?.createAuthResolverForModel(modelAlias);
|
|
74349
74443
|
try {
|
|
74350
74444
|
return (await runTurn({
|
|
@@ -74361,7 +74455,8 @@ var TurnFlow = class {
|
|
|
74361
74455
|
buildMessages: () => this.agent.context.messages,
|
|
74362
74456
|
dispatchEvent: this.buildDispatchEvent(turnId),
|
|
74363
74457
|
tools: this.agent.tools.loopTools,
|
|
74364
|
-
|
|
74458
|
+
maxSteps: loopControl?.maxStepsPerTurn,
|
|
74459
|
+
maxRetryAttempts: loopControl?.maxRetriesPerStep,
|
|
74365
74460
|
hooks: {
|
|
74366
74461
|
beforeStep: async ({ signal: stepSignal }) => {
|
|
74367
74462
|
this.flushSteerBuffer();
|
|
@@ -74600,11 +74695,14 @@ var Agent = class {
|
|
|
74600
74695
|
this.config = new ConfigState(this);
|
|
74601
74696
|
this.turn = new TurnFlow(this);
|
|
74602
74697
|
this.injection = new InjectionManager(this);
|
|
74603
|
-
this.permission = new PermissionManager(this);
|
|
74698
|
+
this.permission = new PermissionManager(this, config.permissionRules);
|
|
74604
74699
|
this.planMode = new PlanMode(this);
|
|
74605
74700
|
this.usage = new UsageRecorder(this);
|
|
74606
74701
|
this.tools = new ToolManager(this);
|
|
74607
|
-
this.background = new BackgroundManager(this, {
|
|
74702
|
+
this.background = new BackgroundManager(this, {
|
|
74703
|
+
maxRunningTasks: config.backgroundMaxRunningTasks,
|
|
74704
|
+
sessionDir: config.backgroundSessionDir
|
|
74705
|
+
});
|
|
74608
74706
|
this.replayBuilder = new ReplayBuilder(this);
|
|
74609
74707
|
}
|
|
74610
74708
|
useProfile(profile, context) {
|
|
@@ -74807,7 +74905,7 @@ var SessionSubagentHost = class {
|
|
|
74807
74905
|
text: request.prompt
|
|
74808
74906
|
}], request.origin);
|
|
74809
74907
|
const turnEnded = await child.turn.waitForCurrentTurn(request.signal);
|
|
74810
|
-
if (turnEnded.reason !== "completed") throw new Error(turnEnded.error
|
|
74908
|
+
if (turnEnded.reason !== "completed") throw new Error(turnEnded.error === void 0 ? `Subagent turn ${turnEnded.reason}` : `[${turnEnded.error.code}] ${turnEnded.error.message}`);
|
|
74811
74909
|
const result = lastAssistantText(child);
|
|
74812
74910
|
const usage = child.usage.data().total;
|
|
74813
74911
|
parent.emitEvent({
|
|
@@ -74904,9 +75002,10 @@ var Session$1 = class {
|
|
|
74904
75002
|
rpc: proxyWithExtraPayload(this.rpc, { agentId: id }),
|
|
74905
75003
|
providerManager: this.config.providerManager,
|
|
74906
75004
|
subagentHost: new SessionSubagentHost(this, id, this.backgroundTaskTimeoutMs()),
|
|
74907
|
-
backgroundMaxRunningTasks: this.config.background?.maxRunningTasks
|
|
75005
|
+
backgroundMaxRunningTasks: this.config.background?.maxRunningTasks,
|
|
75006
|
+
backgroundSessionDir: config.homedir,
|
|
75007
|
+
permissionRules: this.config.permissionRules
|
|
74908
75008
|
});
|
|
74909
|
-
if (config.homedir !== void 0) agent.background.attachSessionDir(config.homedir);
|
|
74910
75009
|
this.agents.set(id, agent);
|
|
74911
75010
|
await agent.resume();
|
|
74912
75011
|
await agent.background.loadFromDisk();
|
|
@@ -74926,9 +75025,10 @@ var Session$1 = class {
|
|
|
74926
75025
|
rpc: proxyWithExtraPayload(this.rpc, { agentId: id }),
|
|
74927
75026
|
providerManager: this.config.providerManager,
|
|
74928
75027
|
subagentHost: config.subagentHost ?? new SessionSubagentHost(this, id, this.backgroundTaskTimeoutMs()),
|
|
74929
|
-
backgroundMaxRunningTasks: this.config.background?.maxRunningTasks
|
|
75028
|
+
backgroundMaxRunningTasks: this.config.background?.maxRunningTasks,
|
|
75029
|
+
backgroundSessionDir: homedir,
|
|
75030
|
+
permissionRules: this.config.permissionRules
|
|
74930
75031
|
});
|
|
74931
|
-
agent.background.attachSessionDir(homedir);
|
|
74932
75032
|
if (this.config.cwd !== void 0) agent.config.update({ cwd: this.config.cwd });
|
|
74933
75033
|
if (profile) {
|
|
74934
75034
|
const context = await prepareSystemPromptContext(this.config.runtime.kaos, agent.config.cwd);
|
|
@@ -74938,7 +75038,7 @@ var Session$1 = class {
|
|
|
74938
75038
|
this.metadata.agents[id] = {
|
|
74939
75039
|
homedir,
|
|
74940
75040
|
type,
|
|
74941
|
-
parentAgentId
|
|
75041
|
+
parentAgentId: parentAgentId ?? null
|
|
74942
75042
|
};
|
|
74943
75043
|
this.writeMetadata();
|
|
74944
75044
|
return {
|
|
@@ -75072,7 +75172,22 @@ function createRPC() {
|
|
|
75072
75172
|
const signal = options?.signal;
|
|
75073
75173
|
const rpcPayload = await simulateNetwork(payload);
|
|
75074
75174
|
signal?.throwIfAborted();
|
|
75075
|
-
|
|
75175
|
+
let response;
|
|
75176
|
+
try {
|
|
75177
|
+
response = {
|
|
75178
|
+
ok: true,
|
|
75179
|
+
value: await abortableRpc(Promise.resolve(fn(rpcPayload)), signal)
|
|
75180
|
+
};
|
|
75181
|
+
} catch (error) {
|
|
75182
|
+
signal?.throwIfAborted();
|
|
75183
|
+
response = {
|
|
75184
|
+
ok: false,
|
|
75185
|
+
error: toKimiErrorPayload(error)
|
|
75186
|
+
};
|
|
75187
|
+
}
|
|
75188
|
+
const remoteResponse = await simulateNetwork(response);
|
|
75189
|
+
if (remoteResponse.ok) return remoteResponse.value;
|
|
75190
|
+
throw fromKimiErrorPayload(remoteResponse.error);
|
|
75076
75191
|
};
|
|
75077
75192
|
}
|
|
75078
75193
|
function bindAllFunctions(obj) {
|
|
@@ -75142,6 +75257,24 @@ const PermissionModeSchema = z.enum([
|
|
|
75142
75257
|
"manual",
|
|
75143
75258
|
"auto"
|
|
75144
75259
|
]);
|
|
75260
|
+
const PermissionRuleDecisionSchema = z.enum([
|
|
75261
|
+
"allow",
|
|
75262
|
+
"deny",
|
|
75263
|
+
"ask"
|
|
75264
|
+
]);
|
|
75265
|
+
const PermissionRuleScopeSchema = z.enum([
|
|
75266
|
+
"turn-override",
|
|
75267
|
+
"session-runtime",
|
|
75268
|
+
"project",
|
|
75269
|
+
"user"
|
|
75270
|
+
]);
|
|
75271
|
+
const PermissionRuleSchema = z.object({
|
|
75272
|
+
decision: PermissionRuleDecisionSchema,
|
|
75273
|
+
scope: PermissionRuleScopeSchema.default("user"),
|
|
75274
|
+
pattern: z.string().min(1).refine(isValidPermissionPattern, { message: "Invalid permission rule pattern" }),
|
|
75275
|
+
reason: z.string().optional()
|
|
75276
|
+
});
|
|
75277
|
+
const PermissionConfigSchema = z.object({ rules: z.array(PermissionRuleSchema).optional() });
|
|
75145
75278
|
const LoopControlSchema = z.object({
|
|
75146
75279
|
maxStepsPerTurn: z.number().int().min(1).optional(),
|
|
75147
75280
|
maxRetriesPerStep: z.number().int().min(0).optional(),
|
|
@@ -75178,6 +75311,7 @@ const KimiConfigSchema = z.object({
|
|
|
75178
75311
|
defaultThinking: z.boolean().optional(),
|
|
75179
75312
|
defaultPermissionMode: PermissionModeSchema.optional(),
|
|
75180
75313
|
defaultPlanMode: z.boolean().optional(),
|
|
75314
|
+
permission: PermissionConfigSchema.optional(),
|
|
75181
75315
|
hooks: z.array(z.unknown()).optional(),
|
|
75182
75316
|
services: ServicesConfigSchema.optional(),
|
|
75183
75317
|
mergeAllAvailableSkills: z.boolean().optional(),
|
|
@@ -75191,6 +75325,7 @@ const KimiConfigSchema = z.object({
|
|
|
75191
75325
|
const ProviderConfigPatchSchema = ProviderConfigSchema.partial();
|
|
75192
75326
|
const ModelAliasPatchSchema = ModelAliasSchema.partial();
|
|
75193
75327
|
const ThinkingConfigPatchSchema = ThinkingConfigSchema.partial();
|
|
75328
|
+
const PermissionConfigPatchSchema = PermissionConfigSchema.partial();
|
|
75194
75329
|
const LoopControlPatchSchema = LoopControlSchema.partial();
|
|
75195
75330
|
const BackgroundConfigPatchSchema = BackgroundConfigSchema.partial();
|
|
75196
75331
|
const MoonshotServiceConfigPatchSchema = MoonshotServiceConfigSchema.partial();
|
|
@@ -75210,6 +75345,7 @@ const KimiConfigPatchSchema = z.object({
|
|
|
75210
75345
|
defaultThinking: z.boolean().optional(),
|
|
75211
75346
|
defaultPermissionMode: PermissionModeSchema.optional(),
|
|
75212
75347
|
defaultPlanMode: z.boolean().optional(),
|
|
75348
|
+
permission: PermissionConfigPatchSchema.optional(),
|
|
75213
75349
|
hooks: z.array(z.unknown()).optional(),
|
|
75214
75350
|
services: ServicesConfigPatchSchema.optional(),
|
|
75215
75351
|
mergeAllAvailableSkills: z.boolean().optional(),
|
|
@@ -75241,6 +75377,14 @@ function missingModelContextSizeMessage(error) {
|
|
|
75241
75377
|
if (section === "models" && typeof modelName === "string" && field === "maxContextSize") return `Model "${modelName}" must define a positive max_context_size in config.toml.`;
|
|
75242
75378
|
}
|
|
75243
75379
|
}
|
|
75380
|
+
function isValidPermissionPattern(pattern) {
|
|
75381
|
+
try {
|
|
75382
|
+
parsePattern(pattern);
|
|
75383
|
+
return true;
|
|
75384
|
+
} catch {
|
|
75385
|
+
return false;
|
|
75386
|
+
}
|
|
75387
|
+
}
|
|
75244
75388
|
//#endregion
|
|
75245
75389
|
//#region ../../packages/kimi-core/src/harness/configs/merge.ts
|
|
75246
75390
|
function mergeConfigPatch(config, patch) {
|
|
@@ -75326,6 +75470,7 @@ function transformTomlData(data) {
|
|
|
75326
75470
|
if (targetKey === "providers" && isPlainObject(value)) result[targetKey] = transformRecord(value, transformProviderData);
|
|
75327
75471
|
else if (targetKey === "models" && isPlainObject(value)) result[targetKey] = transformRecord(value, transformModelData);
|
|
75328
75472
|
else if (targetKey === "thinking" && isPlainObject(value)) result[targetKey] = transformPlainObject(value);
|
|
75473
|
+
else if (targetKey === "permission" && isPlainObject(value)) result[targetKey] = transformPermissionData(value);
|
|
75329
75474
|
else if (targetKey === "services" && isPlainObject(value)) result[targetKey] = transformRecord(value, transformServiceData, snakeToCamel);
|
|
75330
75475
|
else if (targetKey === "loopControl" && isPlainObject(value)) result[targetKey] = transformLoopControlData(value);
|
|
75331
75476
|
else if (targetKey === "background" && isPlainObject(value)) result[targetKey] = transformPlainObject(value);
|
|
@@ -75357,6 +75502,39 @@ function transformProviderData(data) {
|
|
|
75357
75502
|
function transformModelData(data) {
|
|
75358
75503
|
return transformPlainObject(data);
|
|
75359
75504
|
}
|
|
75505
|
+
function transformPermissionData(data) {
|
|
75506
|
+
const raw = transformPlainObject(data);
|
|
75507
|
+
const out = {};
|
|
75508
|
+
const rules = [];
|
|
75509
|
+
appendPermissionRules(rules, raw["rules"]);
|
|
75510
|
+
appendPermissionRules(rules, raw["deny"], "deny");
|
|
75511
|
+
appendPermissionRules(rules, raw["allow"], "allow");
|
|
75512
|
+
appendPermissionRules(rules, raw["ask"], "ask");
|
|
75513
|
+
if (rules.length > 0) out["rules"] = rules;
|
|
75514
|
+
return out;
|
|
75515
|
+
}
|
|
75516
|
+
function appendPermissionRules(target, value, decision) {
|
|
75517
|
+
if (value === void 0) return;
|
|
75518
|
+
const entries = Array.isArray(value) ? value : [value];
|
|
75519
|
+
for (const entry of entries) target.push(transformPermissionRule(entry, decision));
|
|
75520
|
+
}
|
|
75521
|
+
function transformPermissionRule(value, decision) {
|
|
75522
|
+
if (!isPlainObject(value)) return value;
|
|
75523
|
+
const rule = transformPlainObject(value);
|
|
75524
|
+
const tool = rule["tool"];
|
|
75525
|
+
const match = rule["match"];
|
|
75526
|
+
const pattern = rule["pattern"];
|
|
75527
|
+
const out = {};
|
|
75528
|
+
if (decision !== void 0) out["decision"] = decision;
|
|
75529
|
+
else out["decision"] = rule["decision"];
|
|
75530
|
+
out["scope"] = rule["scope"];
|
|
75531
|
+
out["reason"] = rule["reason"];
|
|
75532
|
+
if (typeof tool === "string") {
|
|
75533
|
+
const argPattern = typeof match === "string" ? match : pattern;
|
|
75534
|
+
out["pattern"] = typeof argPattern === "string" ? `${tool}(${argPattern})` : tool;
|
|
75535
|
+
} else out["pattern"] = pattern;
|
|
75536
|
+
return out;
|
|
75537
|
+
}
|
|
75360
75538
|
function transformServiceData(data) {
|
|
75361
75539
|
const out = {};
|
|
75362
75540
|
for (const [key, value] of Object.entries(data)) {
|
|
@@ -75415,6 +75593,7 @@ function configToTomlData(config) {
|
|
|
75415
75593
|
setSection(out, "loop_control", config.loopControl, loopControlToToml);
|
|
75416
75594
|
setSection(out, "background", config.background, backgroundToToml);
|
|
75417
75595
|
setSection(out, "mcp", config.mcp, mcpToToml);
|
|
75596
|
+
setSection(out, "permission", config.permission, permissionToToml);
|
|
75418
75597
|
return out;
|
|
75419
75598
|
}
|
|
75420
75599
|
function setRecordSection(out, snakeKey, value, toToml) {
|
|
@@ -75455,6 +75634,20 @@ function thinkingToToml(thinking, rawThinking) {
|
|
|
75455
75634
|
for (const [key, value] of Object.entries(thinking)) setDefined(out, camelToSnake(key), value);
|
|
75456
75635
|
return out;
|
|
75457
75636
|
}
|
|
75637
|
+
function permissionToToml(permission, rawPermission) {
|
|
75638
|
+
const out = cloneRecord(rawPermission);
|
|
75639
|
+
delete out["deny"];
|
|
75640
|
+
delete out["allow"];
|
|
75641
|
+
delete out["ask"];
|
|
75642
|
+
if (permission.rules !== void 0) out["rules"] = permission.rules.map(permissionRuleToToml);
|
|
75643
|
+
else delete out["rules"];
|
|
75644
|
+
return out;
|
|
75645
|
+
}
|
|
75646
|
+
function permissionRuleToToml(rule) {
|
|
75647
|
+
const out = {};
|
|
75648
|
+
for (const [key, value] of Object.entries(rule)) setDefined(out, camelToSnake(key), value);
|
|
75649
|
+
return out;
|
|
75650
|
+
}
|
|
75458
75651
|
function servicesToToml(services, rawServices) {
|
|
75459
75652
|
const out = cloneRecord(rawServices);
|
|
75460
75653
|
if (services.moonshotSearch !== void 0) out["moonshot_search"] = serviceToToml(services.moonshotSearch);
|
|
@@ -89701,6 +89894,7 @@ var HarnessAPI = class {
|
|
|
89701
89894
|
cwd: workDir,
|
|
89702
89895
|
providerManager: this.providerManager,
|
|
89703
89896
|
background: config.background,
|
|
89897
|
+
permissionRules: config.permission?.rules,
|
|
89704
89898
|
skills: this.resolveSessionSkillConfig(config)
|
|
89705
89899
|
});
|
|
89706
89900
|
session.metadata = {
|
|
@@ -89740,6 +89934,7 @@ var HarnessAPI = class {
|
|
|
89740
89934
|
cwd: summary.workDir,
|
|
89741
89935
|
providerManager: this.providerManager,
|
|
89742
89936
|
background: config.background,
|
|
89937
|
+
permissionRules: config.permission?.rules,
|
|
89743
89938
|
skills: this.resolveSessionSkillConfig(config),
|
|
89744
89939
|
initializeMainAgent: false
|
|
89745
89940
|
});
|
|
@@ -94387,7 +94582,7 @@ function detectFdPath() {
|
|
|
94387
94582
|
}
|
|
94388
94583
|
//#endregion
|
|
94389
94584
|
//#region src/tui/constant/symbols.ts
|
|
94390
|
-
const STATUS_BULLET = "
|
|
94585
|
+
const STATUS_BULLET = "● ";
|
|
94391
94586
|
const USER_MESSAGE_BULLET = "✨ ";
|
|
94392
94587
|
const FAILURE_MARK = "✗ ";
|
|
94393
94588
|
//#endregion
|
|
@@ -96196,6 +96391,58 @@ function formatActivityLine(verb, toolName, args, workspaceDir) {
|
|
|
96196
96391
|
return keyArg ? `${verb} ${toolName} (${keyArg})` : `${verb} ${toolName}`;
|
|
96197
96392
|
}
|
|
96198
96393
|
//#endregion
|
|
96394
|
+
//#region src/tui/utils/event-payload.ts
|
|
96395
|
+
function unescapeJsonString(s) {
|
|
96396
|
+
return s.replaceAll(/\\(["\\/bfnrt])/g, (_, ch) => {
|
|
96397
|
+
switch (ch) {
|
|
96398
|
+
case "n": return "\n";
|
|
96399
|
+
case "t": return " ";
|
|
96400
|
+
case "r": return "\r";
|
|
96401
|
+
case "b": return "\b";
|
|
96402
|
+
case "f": return "\f";
|
|
96403
|
+
case "\"": return "\"";
|
|
96404
|
+
case "\\": return "\\";
|
|
96405
|
+
case "/": return "/";
|
|
96406
|
+
default: return ch;
|
|
96407
|
+
}
|
|
96408
|
+
});
|
|
96409
|
+
}
|
|
96410
|
+
function parseStreamingArgs(argumentsText) {
|
|
96411
|
+
if (argumentsText.trim().length === 0) return {};
|
|
96412
|
+
if (argumentsText.trimEnd().endsWith("}")) try {
|
|
96413
|
+
const parsed = JSON.parse(argumentsText);
|
|
96414
|
+
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) return parsed;
|
|
96415
|
+
} catch {}
|
|
96416
|
+
const result = {};
|
|
96417
|
+
for (const match of argumentsText.matchAll(STREAMING_ARGS_FIELD_RE)) {
|
|
96418
|
+
const key = match[1];
|
|
96419
|
+
const rawValue = match[2];
|
|
96420
|
+
if (key === void 0 || rawValue === void 0) continue;
|
|
96421
|
+
if (!(key in result)) result[key] = unescapeJsonString(rawValue);
|
|
96422
|
+
}
|
|
96423
|
+
return result;
|
|
96424
|
+
}
|
|
96425
|
+
function argsRecord(args) {
|
|
96426
|
+
return typeof args === "object" && args !== null && !Array.isArray(args) ? args : {};
|
|
96427
|
+
}
|
|
96428
|
+
function serializeToolResultOutput(output) {
|
|
96429
|
+
if (typeof output === "string") return output;
|
|
96430
|
+
return JSON.stringify(output, null, 2);
|
|
96431
|
+
}
|
|
96432
|
+
function isTodoItemShape(value) {
|
|
96433
|
+
if (typeof value !== "object" || value === null) return false;
|
|
96434
|
+
const rec = value;
|
|
96435
|
+
if (typeof rec.title !== "string" || rec.title.length === 0) return false;
|
|
96436
|
+
return rec.status === "pending" || rec.status === "in_progress" || rec.status === "done";
|
|
96437
|
+
}
|
|
96438
|
+
function formatErrorMessage$1(error) {
|
|
96439
|
+
if (isKimiError(error)) return `[${error.code}] ${error.message}`;
|
|
96440
|
+
return error instanceof Error ? error.message : String(error);
|
|
96441
|
+
}
|
|
96442
|
+
function stringValue(value) {
|
|
96443
|
+
return typeof value === "string" ? value : void 0;
|
|
96444
|
+
}
|
|
96445
|
+
//#endregion
|
|
96199
96446
|
//#region src/tui/utils/media-url.ts
|
|
96200
96447
|
function mediaUrlPartToText(kind, url) {
|
|
96201
96448
|
const summary = summarizeDataUrl(url);
|
|
@@ -96260,7 +96507,7 @@ async function hydrateTranscriptFromReplay(state, hooks, session) {
|
|
|
96260
96507
|
hooks.setAppState(appStateFromResumeAgent(main));
|
|
96261
96508
|
return true;
|
|
96262
96509
|
} catch (error) {
|
|
96263
|
-
const message =
|
|
96510
|
+
const message = formatErrorMessage$1(error);
|
|
96264
96511
|
hooks.emitError(`Failed to replay session history: ${message}`);
|
|
96265
96512
|
return false;
|
|
96266
96513
|
} finally {
|
|
@@ -100830,69 +101077,6 @@ function hasDispose(value) {
|
|
|
100830
101077
|
return typeof value === "object" && value !== null && "dispose" in value && typeof value.dispose === "function";
|
|
100831
101078
|
}
|
|
100832
101079
|
//#endregion
|
|
100833
|
-
//#region src/tui/utils/event-payload.ts
|
|
100834
|
-
function unescapeJsonString(s) {
|
|
100835
|
-
return s.replaceAll(/\\(["\\/bfnrt])/g, (_, ch) => {
|
|
100836
|
-
switch (ch) {
|
|
100837
|
-
case "n": return "\n";
|
|
100838
|
-
case "t": return " ";
|
|
100839
|
-
case "r": return "\r";
|
|
100840
|
-
case "b": return "\b";
|
|
100841
|
-
case "f": return "\f";
|
|
100842
|
-
case "\"": return "\"";
|
|
100843
|
-
case "\\": return "\\";
|
|
100844
|
-
case "/": return "/";
|
|
100845
|
-
default: return ch;
|
|
100846
|
-
}
|
|
100847
|
-
});
|
|
100848
|
-
}
|
|
100849
|
-
function parseStreamingArgs(argumentsText) {
|
|
100850
|
-
if (argumentsText.trim().length === 0) return {};
|
|
100851
|
-
if (argumentsText.trimEnd().endsWith("}")) try {
|
|
100852
|
-
const parsed = JSON.parse(argumentsText);
|
|
100853
|
-
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) return parsed;
|
|
100854
|
-
} catch {}
|
|
100855
|
-
const result = {};
|
|
100856
|
-
for (const match of argumentsText.matchAll(STREAMING_ARGS_FIELD_RE)) {
|
|
100857
|
-
const key = match[1];
|
|
100858
|
-
const rawValue = match[2];
|
|
100859
|
-
if (key === void 0 || rawValue === void 0) continue;
|
|
100860
|
-
if (!(key in result)) result[key] = unescapeJsonString(rawValue);
|
|
100861
|
-
}
|
|
100862
|
-
return result;
|
|
100863
|
-
}
|
|
100864
|
-
function argsRecord(args) {
|
|
100865
|
-
return typeof args === "object" && args !== null && !Array.isArray(args) ? args : {};
|
|
100866
|
-
}
|
|
100867
|
-
function serializeToolResultOutput(output) {
|
|
100868
|
-
if (typeof output === "string") return output;
|
|
100869
|
-
return JSON.stringify(output, null, 2);
|
|
100870
|
-
}
|
|
100871
|
-
function isTodoItemShape(value) {
|
|
100872
|
-
if (typeof value !== "object" || value === null) return false;
|
|
100873
|
-
const rec = value;
|
|
100874
|
-
if (typeof rec.title !== "string" || rec.title.length === 0) return false;
|
|
100875
|
-
return rec.status === "pending" || rec.status === "in_progress" || rec.status === "done";
|
|
100876
|
-
}
|
|
100877
|
-
function sessionErrorTitle(code) {
|
|
100878
|
-
switch (code) {
|
|
100879
|
-
case "auth.login_required": return "Login required";
|
|
100880
|
-
case "provider.auth_error": return "Authentication error";
|
|
100881
|
-
case "provider.api_error": return "API error";
|
|
100882
|
-
case "provider.rate_limit": return "Rate limit";
|
|
100883
|
-
case "provider.connection_error": return "Connection error";
|
|
100884
|
-
case "context.overflow": return "Context overflow";
|
|
100885
|
-
case "loop.max_steps_exceeded": return "Max steps exceeded";
|
|
100886
|
-
case "tool_error": return "Tool error";
|
|
100887
|
-
case "internal": return "Internal error";
|
|
100888
|
-
case void 0: return "Error";
|
|
100889
|
-
default: return "Error";
|
|
100890
|
-
}
|
|
100891
|
-
}
|
|
100892
|
-
function stringValue(value) {
|
|
100893
|
-
return typeof value === "string" ? value : void 0;
|
|
100894
|
-
}
|
|
100895
|
-
//#endregion
|
|
100896
101080
|
//#region src/tui/utils/errors.ts
|
|
100897
101081
|
function isAbortMessage(message) {
|
|
100898
101082
|
return message === "Aborted" || message.endsWith(": Aborted");
|
|
@@ -101798,7 +101982,7 @@ var KimiTUI = class {
|
|
|
101798
101982
|
const result = await editInExternalEditor(seed, cmd);
|
|
101799
101983
|
if (result !== void 0) this.state.editor.setText(result.replaceAll("\r\n", "\n").replace(/\n$/, ""));
|
|
101800
101984
|
} catch (error) {
|
|
101801
|
-
const msg =
|
|
101985
|
+
const msg = formatErrorMessage$1(error);
|
|
101802
101986
|
this.showError(`External editor failed: ${msg}`);
|
|
101803
101987
|
} finally {
|
|
101804
101988
|
if (typeof process.stdin.pause === "function") process.stdin.pause();
|
|
@@ -101859,7 +102043,7 @@ var KimiTUI = class {
|
|
|
101859
102043
|
try {
|
|
101860
102044
|
await this.handleBuiltInSlashCommand(intent.name, intent.args);
|
|
101861
102045
|
} catch (error) {
|
|
101862
|
-
this.showError(
|
|
102046
|
+
this.showError(formatErrorMessage$1(error));
|
|
101863
102047
|
}
|
|
101864
102048
|
return;
|
|
101865
102049
|
}
|
|
@@ -102042,14 +102226,14 @@ var KimiTUI = class {
|
|
|
102042
102226
|
this.beginSessionRequest();
|
|
102043
102227
|
const sdkInput = options?.parts ?? input;
|
|
102044
102228
|
session.prompt(sdkInput).catch((error) => {
|
|
102045
|
-
const message =
|
|
102229
|
+
const message = formatErrorMessage$1(error);
|
|
102046
102230
|
this.failSessionRequest(`Failed to send: ${message}`);
|
|
102047
102231
|
});
|
|
102048
102232
|
}
|
|
102049
102233
|
sendSkillActivation(session, skillName, skillArgs) {
|
|
102050
102234
|
this.beginSessionRequest();
|
|
102051
102235
|
session.activateSkill(skillName, skillArgs).catch((error) => {
|
|
102052
|
-
const message =
|
|
102236
|
+
const message = formatErrorMessage$1(error);
|
|
102053
102237
|
this.failSessionRequest(`Skill "${skillName}" failed: ${message}`);
|
|
102054
102238
|
});
|
|
102055
102239
|
}
|
|
@@ -102077,7 +102261,7 @@ var KimiTUI = class {
|
|
|
102077
102261
|
content: part
|
|
102078
102262
|
});
|
|
102079
102263
|
session.steer(input.join("\n\n")).catch((error) => {
|
|
102080
|
-
const message =
|
|
102264
|
+
const message = formatErrorMessage$1(error);
|
|
102081
102265
|
this.showError(`Failed to steer: ${message}`);
|
|
102082
102266
|
});
|
|
102083
102267
|
}
|
|
@@ -102090,7 +102274,7 @@ var KimiTUI = class {
|
|
|
102090
102274
|
const session = this.session;
|
|
102091
102275
|
if (session === void 0) return;
|
|
102092
102276
|
session.cancelCompaction().catch((error) => {
|
|
102093
|
-
const message =
|
|
102277
|
+
const message = formatErrorMessage$1(error);
|
|
102094
102278
|
this.showError(`Failed to cancel compaction: ${message}`);
|
|
102095
102279
|
});
|
|
102096
102280
|
}
|
|
@@ -102295,7 +102479,7 @@ var KimiTUI = class {
|
|
|
102295
102479
|
try {
|
|
102296
102480
|
session = await this.harness.resumeSession({ id: targetSessionId });
|
|
102297
102481
|
} catch (error) {
|
|
102298
|
-
const msg =
|
|
102482
|
+
const msg = formatErrorMessage$1(error);
|
|
102299
102483
|
this.showError(`Failed to resume session ${targetSessionId}: ${msg}`);
|
|
102300
102484
|
return false;
|
|
102301
102485
|
}
|
|
@@ -102314,7 +102498,7 @@ var KimiTUI = class {
|
|
|
102314
102498
|
try {
|
|
102315
102499
|
await hydrateTranscriptFromReplay(this.state, this.replayHydrationHooks(), session);
|
|
102316
102500
|
} catch (error) {
|
|
102317
|
-
const msg =
|
|
102501
|
+
const msg = formatErrorMessage$1(error);
|
|
102318
102502
|
this.showError(`Failed to replay session history: ${msg}`);
|
|
102319
102503
|
} finally {
|
|
102320
102504
|
this.startSessionEventSubscription();
|
|
@@ -102330,7 +102514,7 @@ var KimiTUI = class {
|
|
|
102330
102514
|
try {
|
|
102331
102515
|
session = await this.createSessionFromCurrentState();
|
|
102332
102516
|
} catch (error) {
|
|
102333
|
-
const msg =
|
|
102517
|
+
const msg = formatErrorMessage$1(error);
|
|
102334
102518
|
this.showError(`Failed to start a new session: ${msg}`);
|
|
102335
102519
|
return;
|
|
102336
102520
|
}
|
|
@@ -102343,7 +102527,7 @@ var KimiTUI = class {
|
|
|
102343
102527
|
try {
|
|
102344
102528
|
await this.activateRuntime();
|
|
102345
102529
|
} catch (error) {
|
|
102346
|
-
const msg =
|
|
102530
|
+
const msg = formatErrorMessage$1(error);
|
|
102347
102531
|
this.showError(`Post-create setup failed: ${msg}`);
|
|
102348
102532
|
return;
|
|
102349
102533
|
}
|
|
@@ -102670,12 +102854,7 @@ var KimiTUI = class {
|
|
|
102670
102854
|
handleSessionError(event) {
|
|
102671
102855
|
this.resetLiveToolUiState();
|
|
102672
102856
|
this.finalizeLiveTextBuffers("idle");
|
|
102673
|
-
|
|
102674
|
-
this.showError(event.message);
|
|
102675
|
-
return;
|
|
102676
|
-
}
|
|
102677
|
-
const title = sessionErrorTitle(event.code);
|
|
102678
|
-
this.showError(`${title}: ${event.message}`);
|
|
102857
|
+
this.showError(`[${event.code}] ${event.message}`);
|
|
102679
102858
|
}
|
|
102680
102859
|
handleSkillActivated(event) {
|
|
102681
102860
|
if (this.state.renderedSkillActivationIds.has(event.activationId)) return;
|
|
@@ -103395,7 +103574,7 @@ var KimiTUI = class {
|
|
|
103395
103574
|
notifications: this.state.appState.notifications
|
|
103396
103575
|
});
|
|
103397
103576
|
} catch (error) {
|
|
103398
|
-
this.showStatus(`Failed to save editor: ${
|
|
103577
|
+
this.showStatus(`Failed to save editor: ${formatErrorMessage$1(error)}`, this.state.theme.colors.error);
|
|
103399
103578
|
return;
|
|
103400
103579
|
}
|
|
103401
103580
|
this.setAppState({ editorCommand });
|
|
@@ -103467,7 +103646,7 @@ var KimiTUI = class {
|
|
|
103467
103646
|
});
|
|
103468
103647
|
this.showStatus(`Switched to ${alias} with thinking ${level}.`, this.state.theme.colors.success);
|
|
103469
103648
|
} catch (error) {
|
|
103470
|
-
const msg =
|
|
103649
|
+
const msg = formatErrorMessage$1(error);
|
|
103471
103650
|
this.showError(`Failed to switch model: ${msg}`);
|
|
103472
103651
|
}
|
|
103473
103652
|
}
|
|
@@ -103536,7 +103715,7 @@ var KimiTUI = class {
|
|
|
103536
103715
|
try {
|
|
103537
103716
|
await this.requireSession().setPermission(mode);
|
|
103538
103717
|
} catch (error) {
|
|
103539
|
-
const msg =
|
|
103718
|
+
const msg = formatErrorMessage$1(error);
|
|
103540
103719
|
this.showError(`Failed to set permission mode: ${msg}`);
|
|
103541
103720
|
return;
|
|
103542
103721
|
}
|
|
@@ -103559,7 +103738,7 @@ var KimiTUI = class {
|
|
|
103559
103738
|
notifications: this.state.appState.notifications
|
|
103560
103739
|
});
|
|
103561
103740
|
} catch (error) {
|
|
103562
|
-
this.showStatus(`Failed to save theme: ${
|
|
103741
|
+
this.showStatus(`Failed to save theme: ${formatErrorMessage$1(error)}`, this.state.theme.colors.error);
|
|
103563
103742
|
return;
|
|
103564
103743
|
}
|
|
103565
103744
|
const resolved = theme === "auto" ? this.state.theme.resolvedTheme : theme;
|
|
@@ -103613,7 +103792,7 @@ var KimiTUI = class {
|
|
|
103613
103792
|
try {
|
|
103614
103793
|
return { usage: await this.requireSession().getUsage() };
|
|
103615
103794
|
} catch (error) {
|
|
103616
|
-
return { error:
|
|
103795
|
+
return { error: formatErrorMessage$1(error) };
|
|
103617
103796
|
}
|
|
103618
103797
|
}
|
|
103619
103798
|
async loadRuntimeStatusReport() {
|
|
@@ -103631,7 +103810,7 @@ var KimiTUI = class {
|
|
|
103631
103810
|
try {
|
|
103632
103811
|
res = await this.harness.auth.getManagedUsage(providerKey);
|
|
103633
103812
|
} catch (error) {
|
|
103634
|
-
return { error:
|
|
103813
|
+
return { error: formatErrorMessage$1(error) };
|
|
103635
103814
|
}
|
|
103636
103815
|
if (res.kind === "error") return { error: res.message };
|
|
103637
103816
|
return { usage: {
|
|
@@ -103680,7 +103859,7 @@ var KimiTUI = class {
|
|
|
103680
103859
|
}
|
|
103681
103860
|
this.showNotice("Plan mode: OFF");
|
|
103682
103861
|
} catch (error) {
|
|
103683
|
-
const msg =
|
|
103862
|
+
const msg = formatErrorMessage$1(error);
|
|
103684
103863
|
this.showError(`Failed to set plan mode: ${msg}`);
|
|
103685
103864
|
}
|
|
103686
103865
|
}
|
|
@@ -103735,7 +103914,7 @@ var KimiTUI = class {
|
|
|
103735
103914
|
title: newTitle
|
|
103736
103915
|
});
|
|
103737
103916
|
} catch (error) {
|
|
103738
|
-
const msg =
|
|
103917
|
+
const msg = formatErrorMessage$1(error);
|
|
103739
103918
|
this.showError(`Failed to set title: ${msg}`);
|
|
103740
103919
|
return;
|
|
103741
103920
|
}
|
|
@@ -103755,14 +103934,14 @@ var KimiTUI = class {
|
|
|
103755
103934
|
title: `Fork: ${sourceTitle}`
|
|
103756
103935
|
});
|
|
103757
103936
|
} catch (error) {
|
|
103758
|
-
const msg =
|
|
103937
|
+
const msg = formatErrorMessage$1(error);
|
|
103759
103938
|
this.showError(`Failed to fork session: ${msg}`);
|
|
103760
103939
|
return;
|
|
103761
103940
|
}
|
|
103762
103941
|
try {
|
|
103763
103942
|
await this.switchToSession(forked, `Session forked (${forked.id}).`);
|
|
103764
103943
|
} catch (error) {
|
|
103765
|
-
const msg =
|
|
103944
|
+
const msg = formatErrorMessage$1(error);
|
|
103766
103945
|
this.showError(`Failed to switch to forked session: ${msg}`);
|
|
103767
103946
|
}
|
|
103768
103947
|
}
|
|
@@ -103875,7 +104054,7 @@ var KimiTUI = class {
|
|
|
103875
104054
|
try {
|
|
103876
104055
|
await this.refreshConfigAfterLogin();
|
|
103877
104056
|
} catch (refreshError) {
|
|
103878
|
-
const message =
|
|
104057
|
+
const message = formatErrorMessage$1(refreshError);
|
|
103879
104058
|
this.showError(`Authentication successful, but failed to refresh config: ${message}`);
|
|
103880
104059
|
return;
|
|
103881
104060
|
}
|
|
@@ -103888,7 +104067,7 @@ var KimiTUI = class {
|
|
|
103888
104067
|
});
|
|
103889
104068
|
spinner = void 0;
|
|
103890
104069
|
if (cancelled) return;
|
|
103891
|
-
const message =
|
|
104070
|
+
const message = formatErrorMessage$1(error);
|
|
103892
104071
|
this.showError(`Login failed: ${message}`);
|
|
103893
104072
|
} finally {
|
|
103894
104073
|
if (this.cancelInFlight === cancelLogin) this.cancelInFlight = void 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kfc-code-cli",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.25",
|
|
4
4
|
"description": "KFC crazy ",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"@types/semver": "^7.7.0",
|
|
38
38
|
"@types/yazl": "^2.4.6",
|
|
39
39
|
"tsx": "^4.21.0",
|
|
40
|
-
"@moonshot-ai/kimi-telemetry": "^0.1.0",
|
|
41
40
|
"@moonshot-ai/kimi-oauth": "^0.1.0",
|
|
41
|
+
"@moonshot-ai/kimi-telemetry": "^0.1.0",
|
|
42
42
|
"@moonshot-ai/sdk": "^0.1.0"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|