@ycodium-ai/agent-kimi 0.2.4343 → 0.2.4368

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.
Files changed (3) hide show
  1. package/README.md +5 -0
  2. package/dist/index.js +151 -41
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -12,6 +12,11 @@ customModels } }`; launch arguments (`acp`) and the account-directory variable (
12
12
  - Models come from the read-only `kimi provider list --json` (`src/kimiModels.ts`); the version
13
13
  from `kimi --version`. No probe session is created.
14
14
  - Sign-in is `kimi login` (device-code flow), upgrade is `kimi upgrade`.
15
+ - Runtime modes map to native permissions: auto and auto-accept-edits → auto, full-access → yolo, approval-required → default.
16
+ The auto-accept-edits mapping is an approximation and may allow more than edits. Kimi has no
17
+ edits-only automatic native mode: default asks for approvals and plan does not execute tools.
18
+ A selected native mode governs approvals. Without native modes, auto permits MCP dynamic tools
19
+ (ACP kind `other` with an MCP name); questions and plan confirmations remain user input.
15
20
  - Usage (ADR-0034), per instance, read only when the user asks. The account directory is the
16
21
  `homePath` setting, an explicit `KIMI_CODE_HOME` in the instance environment, then the process
17
22
  environment, then `~/.kimi-code`:
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ var __export = (target, all) => {
8
8
  import { definePlugin } from "@ycodium-ai/plugin-api";
9
9
 
10
10
  // ../../packages/plugin-api/src/version.ts
11
- var PLUGIN_API_VERSION = 109;
11
+ var PLUGIN_API_VERSION = 112;
12
12
 
13
13
  // src/index.ts
14
14
  import * as NodeOS6 from "node:os";
@@ -253,9 +253,11 @@ var AcpExecutorRequestError = class extends AcpExecutorError {
253
253
  }
254
254
  };
255
255
  var AcpConnectionClosedError = class extends Error {
256
+ reason;
256
257
  constructor(message = "ACP connection closed", options) {
257
- super(message, options);
258
+ super(message, options?.cause === void 0 ? void 0 : { cause: options.cause });
258
259
  this.name = "AcpConnectionClosedError";
260
+ this.reason = options?.reason ?? "closed";
259
261
  }
260
262
  };
261
263
  async function withStartupStderr(error62, stderrTail) {
@@ -265,9 +267,65 @@ async function withStartupStderr(error62, stderrTail) {
265
267
  return new AcpConnectionClosedError(`${error62.message}
266
268
  Agent stderr (last lines):
267
269
  ${tail}`, {
268
- cause: error62
270
+ cause: error62,
271
+ reason: error62.reason
269
272
  });
270
273
  }
274
+ var AGENT_EXIT_STDERR_MAX_CHARS = 800;
275
+ var AGENT_EXIT_SETTLE_MS = 500;
276
+ var AcpAgentExitedError = class extends AcpConnectionClosedError {
277
+ exitCode;
278
+ constructor(message, exitCode, cause) {
279
+ super(message, { cause, reason: "input-ended" });
280
+ this.name = "AcpAgentExitedError";
281
+ this.exitCode = exitCode;
282
+ }
283
+ };
284
+ var REDACTION_MARKERS = ["[redacted]", "[pairing-url]"];
285
+ var lastLines = (text, maxChars) => {
286
+ if (text.length <= maxChars) return text;
287
+ let start = text.length - maxChars;
288
+ if (text[start - 1] !== "\n") {
289
+ const lineEnd = text.indexOf("\n", start);
290
+ if (lineEnd !== -1 && lineEnd < text.length - 1) return text.slice(lineEnd + 1);
291
+ const code = text.charCodeAt(start);
292
+ if (code >= 56320 && code <= 57343) start += 1;
293
+ for (const marker of REDACTION_MARKERS) {
294
+ const at = text.lastIndexOf(marker, start);
295
+ if (at !== -1 && at < start && start < at + marker.length) start = at + marker.length;
296
+ }
297
+ }
298
+ return text.slice(start);
299
+ };
300
+ var settledExitCode = async (exited) => {
301
+ if (exited === void 0) return void 0;
302
+ let timer;
303
+ try {
304
+ return await Promise.race([
305
+ exited.catch(() => void 0),
306
+ new Promise((resolve4) => {
307
+ timer = setTimeout(() => resolve4(void 0), AGENT_EXIT_SETTLE_MS);
308
+ })
309
+ ]);
310
+ } finally {
311
+ clearTimeout(timer);
312
+ }
313
+ };
314
+ async function describeAgentExit(input2) {
315
+ const [exitCode, tail] = await Promise.all([
316
+ settledExitCode(input2.exited),
317
+ input2.stderrTail === void 0 ? "" : Promise.resolve().then(input2.stderrTail).catch(() => "")
318
+ ]);
319
+ const head = exitCode === void 0 ? "The agent closed its connection." : exitCode === null ? "The agent process exited without an exit code." : `The agent process exited with code ${exitCode}.`;
320
+ const excerpt = lastLines(tail.trim(), AGENT_EXIT_STDERR_MAX_CHARS);
321
+ return new AcpAgentExitedError(
322
+ excerpt.length === 0 ? head : `${head}
323
+ Agent stderr (last lines):
324
+ ${excerpt}`,
325
+ exitCode,
326
+ input2.cause
327
+ );
328
+ }
271
329
 
272
330
  // ../../packages/ycodium-acp-executor/src/event-stream.ts
273
331
  var UnboundedEventStream = class {
@@ -25202,7 +25260,8 @@ function createAcpConnection(options) {
25202
25260
  options.onInboundFailure?.(error62);
25203
25261
  void shutdown(
25204
25262
  new AcpConnectionClosedError(
25205
- `ACP inbound handling failed: ${error62 instanceof Error ? error62.message : String(error62)}`
25263
+ `ACP inbound handling failed: ${error62 instanceof Error ? error62.message : String(error62)}`,
25264
+ { reason: "inbound-failed" }
25206
25265
  )
25207
25266
  );
25208
25267
  };
@@ -25247,19 +25306,21 @@ function createAcpConnection(options) {
25247
25306
  } finally {
25248
25307
  endInboundBatch();
25249
25308
  }
25250
- await shutdown(new AcpConnectionClosedError("ACP input stream ended"));
25309
+ await shutdown(
25310
+ new AcpConnectionClosedError("ACP input stream ended", { reason: "input-ended" })
25311
+ );
25251
25312
  });
25252
25313
  };
25253
25314
  const onError = (error62) => {
25254
25315
  enqueueInbound(async () => {
25255
25316
  await shutdown(
25256
- error62 instanceof Error ? error62 : new AcpConnectionClosedError("ACP input stream error")
25317
+ error62 instanceof Error ? error62 : new AcpConnectionClosedError("ACP input stream error", { reason: "stream-error" })
25257
25318
  );
25258
25319
  });
25259
25320
  };
25260
25321
  const onWritableError = (error62) => {
25261
25322
  void shutdown(
25262
- error62 instanceof Error ? error62 : new AcpConnectionClosedError("ACP output stream error")
25323
+ error62 instanceof Error ? error62 : new AcpConnectionClosedError("ACP output stream error", { reason: "stream-error" })
25263
25324
  );
25264
25325
  };
25265
25326
  options.readable.on("data", onData);
@@ -25322,7 +25383,8 @@ function createAcpConnection(options) {
25322
25383
  awaitInboundIdle,
25323
25384
  abandonPending,
25324
25385
  close,
25325
- closed
25386
+ closed,
25387
+ closeError: () => closedError
25326
25388
  };
25327
25389
  }
25328
25390
 
@@ -25731,7 +25793,8 @@ var ACP_FAILURE_CATEGORIES = [
25731
25793
  "auth",
25732
25794
  "model-unavailable",
25733
25795
  "transport",
25734
- "unknown"
25796
+ "unknown",
25797
+ "process-exit"
25735
25798
  ];
25736
25799
  var isAcpFailureCategory = (value) => ACP_FAILURE_CATEGORIES.some((category) => category === value);
25737
25800
  var readAcpFailureCategory = (error62) => {
@@ -25741,11 +25804,14 @@ var readAcpFailureCategory = (error62) => {
25741
25804
  };
25742
25805
  var withFailureCategory = (error62, category) => category === void 0 ? error62 : Object.assign(error62, { failureCategory: category });
25743
25806
  var failureCategoryField = (category) => category === void 0 ? {} : { failureCategory: category };
25744
- var acpTransportIfEstablished = (sessionEstablished, disposed) => sessionEstablished && !disposed ? "transport" : void 0;
25807
+ var acpClosedConnectionCategory = (closeError, sessionEstablished, disposed) => {
25808
+ if (!sessionEstablished || disposed) return void 0;
25809
+ return closeError instanceof AcpConnectionClosedError && closeError.reason === "input-ended" ? "process-exit" : "transport";
25810
+ };
25745
25811
  var acpPromptFailureCategory = (error62, input2) => {
25746
25812
  const signaled = readAcpFailureCategory(error62);
25747
25813
  if (signaled !== void 0) return signaled;
25748
- return error62 instanceof AcpConnectionClosedError ? acpTransportIfEstablished(input2.sessionEstablished, input2.disposed) : void 0;
25814
+ return error62 instanceof AcpConnectionClosedError ? acpClosedConnectionCategory(error62, input2.sessionEstablished, input2.disposed) : void 0;
25749
25815
  };
25750
25816
 
25751
25817
  // ../../packages/ycodium-acp-executor/src/tool-subagents.ts
@@ -25760,7 +25826,7 @@ var sealedHidden = (entry) => ({
25760
25826
  });
25761
25827
  function toolSubagentSettlementOfTurn(state, failureCategory) {
25762
25828
  if (state === "cancelled") return "turn-interrupted";
25763
- return state === "failed" && failureCategory === "transport" ? "session-ended" : "turn-ended";
25829
+ return state === "failed" && failureCategory === "process-exit" ? "session-ended" : "turn-ended";
25764
25830
  }
25765
25831
  var sameFacts = (a, b) => a.title === b.title && a.description === b.description && a.summary === b.summary && a.role === b.role && a.model === b.model && a.effort === b.effort && a.rosterKind === b.rosterKind;
25766
25832
  function linkage(taskId, toolCallId, facts) {
@@ -26377,14 +26443,19 @@ function createExecutorPrompt({
26377
26443
  },
26378
26444
  record2
26379
26445
  );
26380
- } catch (error62) {
26446
+ } catch (caught) {
26381
26447
  if (shared.disposed) {
26382
26448
  throw new AcpExecutorDisposedError();
26383
26449
  }
26384
- const failureCategory = acpPromptFailureCategory(error62, {
26450
+ const failureCategory = acpPromptFailureCategory(caught, {
26385
26451
  sessionEstablished: shared.startResult !== void 0,
26386
26452
  disposed: shared.disposed
26387
26453
  });
26454
+ const error62 = failureCategory === "process-exit" && !interruptedTurnIds.has(turnId) ? await describeAgentExit({
26455
+ cause: caught,
26456
+ exited: options.exited,
26457
+ stderrTail: options.stderrTail
26458
+ }) : caught;
26388
26459
  if (!interruptedTurnIds.has(turnId)) {
26389
26460
  const errorMessage = error62 instanceof Error && error62.message.trim() || "ACP prompt failed";
26390
26461
  if (settle2({
@@ -27738,24 +27809,40 @@ function createExecutorUpdates({
27738
27809
  return;
27739
27810
  }
27740
27811
  };
27741
- const emitTaskEvents = (taskEvents) => {
27742
- for (const taskEvent of taskEvents ?? []) {
27812
+ const emitHookEvents = (hookEvents) => {
27813
+ for (const hookEvent of hookEvents ?? []) {
27814
+ if (hookEvent.type === "runtime.warning") {
27815
+ const message = hookEvent.payload.message.trim();
27816
+ if (message.length === 0) continue;
27817
+ emit({
27818
+ type: "runtime.warning",
27819
+ ...stamp(),
27820
+ provider: options.provider,
27821
+ threadId: options.threadId,
27822
+ ...hookEvent.turnId !== void 0 ? { turnId: hookEvent.turnId } : {},
27823
+ payload: {
27824
+ message,
27825
+ ...hookEvent.payload.detail !== void 0 ? { detail: hookEvent.payload.detail } : {}
27826
+ }
27827
+ });
27828
+ continue;
27829
+ }
27743
27830
  emit({
27744
- type: taskEvent.type,
27831
+ type: hookEvent.type,
27745
27832
  ...stamp(),
27746
27833
  provider: options.provider,
27747
27834
  threadId: options.threadId,
27748
- ...taskEvent.turnId !== void 0 ? { turnId: taskEvent.turnId } : {},
27749
- payload: taskEvent.payload
27835
+ ...hookEvent.turnId !== void 0 ? { turnId: hookEvent.turnId } : {},
27836
+ payload: hookEvent.payload
27750
27837
  });
27751
27838
  }
27752
27839
  };
27753
27840
  const toolSubagents = hooks.toolSubagents === void 0 ? void 0 : createToolSubagentTracker(hooks.toolSubagents);
27754
- const settleToolSubagents = (settlement, turnId) => emitTaskEvents(toolSubagents?.settle(settlement, turnId));
27841
+ const settleToolSubagents = (settlement, turnId) => emitHookEvents(toolSubagents?.settle(settlement, turnId));
27755
27842
  const settleSessionEnded = () => {
27756
27843
  settleToolSubagents("session-ended");
27757
- emitTaskEvents(subagentSessions?.settleSessionEnded());
27758
- emitTaskEvents(hooks.onSessionEnded?.());
27844
+ emitHookEvents(subagentSessions?.settleSessionEnded());
27845
+ emitHookEvents(hooks.onSessionEnded?.());
27759
27846
  };
27760
27847
  const observeContext = () => ({
27761
27848
  turnId: shared.activeTurnId,
@@ -27817,7 +27904,7 @@ function createExecutorUpdates({
27817
27904
  };
27818
27905
  const hookResult = call === void 0 ? void 0 : toolSubagents?.onToolCallUpdated(call) ?? hooks.onToolCallUpdated?.(call);
27819
27906
  const handledByHook = hookResult !== void 0 && "events" in hookResult && hookResult.handled === true;
27820
- emitTaskEvents(
27907
+ emitHookEvents(
27821
27908
  hookResult === void 0 ? [] : "events" in hookResult ? hookResult.events : hookResult
27822
27909
  );
27823
27910
  if (nextToolCall.status === "completed" && hookResult && "artifacts" in hookResult)
@@ -27914,7 +28001,7 @@ function createExecutorUpdates({
27914
28001
  };
27915
28002
  const receiveSessionUpdate = (params) => {
27916
28003
  const foreign = !shared.ownSessionIds.has(params.sessionId) && (shared.childSessions.has(params.sessionId) || shared.sessionOpensInFlight === 0 && shared.ownSessionIds.size > 0);
27917
- emitTaskEvents(
28004
+ emitHookEvents(
27918
28005
  subagentSessions?.observe(params, {
27919
28006
  turnId: shared.activeTurnId,
27920
28007
  foreign,
@@ -27924,7 +28011,7 @@ function createExecutorUpdates({
27924
28011
  );
27925
28012
  if (!shared.sessionLoadInFlight) {
27926
28013
  if (hooks.onSessionUpdate) {
27927
- emitTaskEvents(hooks.onSessionUpdate(params, { ...observeContext(), foreign }));
28014
+ emitHookEvents(hooks.onSessionUpdate(params, { ...observeContext(), foreign }));
27928
28015
  }
27929
28016
  }
27930
28017
  if (!foreign) handleSessionUpdate(params);
@@ -27932,7 +28019,7 @@ function createExecutorUpdates({
27932
28019
  const receiveExtensionNotification = (method, params) => {
27933
28020
  if (shared.sessionLoadInFlight || !hooks.onExtensionNotification) return;
27934
28021
  const result = hooks.onExtensionNotification(method, params, observeContext());
27935
- if (Array.isArray(result)) emitTaskEvents(result);
28022
+ if (Array.isArray(result)) emitHookEvents(result);
27936
28023
  };
27937
28024
  return {
27938
28025
  emitCompactionState,
@@ -28227,7 +28314,11 @@ function createAcpExecutor(options) {
28227
28314
  settleAllUserInputs();
28228
28315
  abortPendingSettlement(
28229
28316
  "connection closed",
28230
- acpTransportIfEstablished(shared.startResult !== void 0, shared.disposed)
28317
+ acpClosedConnectionCategory(
28318
+ connection.closeError(),
28319
+ shared.startResult !== void 0,
28320
+ shared.disposed
28321
+ )
28231
28322
  );
28232
28323
  shared.promptWaiters.splice(0).forEach((wake) => wake());
28233
28324
  },
@@ -29327,9 +29418,7 @@ async function probeKimi(input2) {
29327
29418
  return {
29328
29419
  kind: "answered",
29329
29420
  version: version2,
29330
- models: listed.models,
29331
- nativeModes: [],
29332
- currentNativeModeId: void 0
29421
+ models: listed.models
29333
29422
  };
29334
29423
  }
29335
29424
  }
@@ -29372,8 +29461,27 @@ function kimiOpenCommands(session) {
29372
29461
  };
29373
29462
  }
29374
29463
 
29464
+ // src/nativeModes.ts
29465
+ var KIMI_NATIVE_MODE_REPORT = {
29466
+ nativeModes: [
29467
+ { id: "default", name: "Default", description: "Manual approvals; tools execute normally." },
29468
+ { id: "plan", name: "Plan", description: "Read-only planning; no tool execution." },
29469
+ { id: "auto", name: "Auto", description: "Auto-approve safe operations." },
29470
+ { id: "yolo", name: "YOLO", description: "Auto-approve everything." }
29471
+ ],
29472
+ currentNativeModeId: "default",
29473
+ nativeModeByRuntimeMode: {
29474
+ auto: "auto",
29475
+ "auto-accept-edits": "auto",
29476
+ "full-access": "yolo",
29477
+ "approval-required": "default"
29478
+ }
29479
+ };
29480
+
29375
29481
  // src/runtimeModeApproval.ts
29376
- function acpRuntimeModeAutoApproves(runtimeMode, toolKind) {
29482
+ function acpRuntimeModeAutoApproves(runtimeMode, toolKind, toolName, nativeMode = false) {
29483
+ if (nativeMode) return false;
29484
+ if (runtimeMode === "auto" && toolKind === "other" && toolName?.startsWith("mcp__")) return true;
29377
29485
  switch (runtimeMode) {
29378
29486
  case "full-access":
29379
29487
  return true;
@@ -29649,11 +29757,7 @@ var createKimiInstance = (config2, host) => {
29649
29757
  readiness: "ready",
29650
29758
  auth: auth(),
29651
29759
  ...outcome.models === void 0 ? {} : { models: outcome.models },
29652
- // 清单与当前档必须同进同出:只报清单,界面在清单里找不到当前档会整个不画那一格。
29653
- ...outcome.nativeModes.length === 0 ? {} : {
29654
- nativeModes: outcome.nativeModes,
29655
- ...outcome.currentNativeModeId === void 0 ? {} : { currentNativeModeId: outcome.currentNativeModeId }
29656
- }
29760
+ ...KIMI_NATIVE_MODE_REPORT
29657
29761
  };
29658
29762
  }
29659
29763
  },
@@ -29698,14 +29802,20 @@ var createKimiInstance = (config2, host) => {
29698
29802
  ACP_EFFORT_OPTION_ID
29699
29803
  );
29700
29804
  const hooks = kimiHooks(recipe);
29701
- const autoApprove = input2.nativeModeId === void 0 ? (request) => acpRuntimeModeAutoApproves(
29702
- threads.get(input2.threadId)?.session.runtimeMode ?? input2.runtimeMode,
29703
- request.kind
29704
- ) : void 0;
29805
+ const autoApprove = (request) => {
29806
+ const session = threads.get(input2.threadId)?.session ?? input2;
29807
+ return acpRuntimeModeAutoApproves(
29808
+ session.runtimeMode,
29809
+ request.kind,
29810
+ request.toolCall?.title,
29811
+ session.nativeModeId !== void 0
29812
+ );
29813
+ };
29705
29814
  const executor = createAcpExecutor({
29706
29815
  readable,
29707
29816
  writable,
29708
29817
  stderrTail,
29818
+ exited: handle.exited,
29709
29819
  ...requestedEffort === void 0 ? {} : { requestedEffort },
29710
29820
  cwd,
29711
29821
  threadId: input2.threadId,
@@ -29723,7 +29833,7 @@ var createKimiInstance = (config2, host) => {
29723
29833
  // 握手声明了 `sessionCapabilities.resume`:续接走 session/resume,重新激活持久会话、
29724
29834
  // 不重放历史(0.31.1 真机实测上下文还在);session/load 要把整段历史重放一遍,会话越长越慢。
29725
29835
  resumeMethod: "session/resume",
29726
- ...autoApprove === void 0 ? {} : { autoApprove },
29836
+ autoApprove,
29727
29837
  // 内置编排那一条排第一,后面跟用户在插件中心配的;缺了这一栏,
29728
29838
  // `mcp__ycodium__*` 整套工具(浏览器等)在这只手的会话里都不存在。
29729
29839
  // http / sse 由执行器按握手里的 `mcpCapabilities` 再筛。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ycodium-ai/agent-kimi",
3
- "version": "0.2.4343",
3
+ "version": "0.2.4368",
4
4
  "description": "Kimi Code executor: runs `kimi acp` over Agent Client Protocol stdio.",
5
5
  "keywords": [
6
6
  "ycodium",
@@ -21,9 +21,9 @@
21
21
  "@types/node": "24.12.4",
22
22
  "esbuild": "0.28.1",
23
23
  "vite-plus": "0.2.2",
24
- "@ycodium-ai/plugin-api": "0.2.4343",
24
+ "ycodium-acp-executor": "0.2.4368",
25
25
  "ycodium-executor-testing": "0.0.0",
26
- "ycodium-acp-executor": "0.2.4343"
26
+ "@ycodium-ai/plugin-api": "0.2.4368"
27
27
  },
28
28
  "ycodium": {
29
29
  "plugin": "./dist/index.js",