@ycodium-ai/agent-kimi 0.2.5634 → 0.2.5751

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 (2) hide show
  1. package/dist/index.js +238 -583
  2. package/package.json +4 -6
package/dist/index.js CHANGED
@@ -8,136 +8,18 @@ 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 = 178;
11
+ var PLUGIN_API_VERSION = 180;
12
12
 
13
13
  // src/index.ts
14
- import * as NodeOS7 from "node:os";
15
- import * as NodePath10 from "node:path";
16
-
17
- // ../../packages/ycodium-instance-config/src/homePath.ts
18
- import * as NodeCrypto from "node:crypto";
19
- import * as NodeOS from "node:os";
20
- import * as NodePath from "node:path";
14
+ import * as NodeOS6 from "node:os";
15
+ import * as NodePath8 from "node:path";
21
16
  import {
22
- EXECUTOR_EFFECTIVE_PAYLOAD_SCHEMA,
23
- executorHomeEffectiveValue,
24
- readExecutorEffectiveRequest,
25
- mergeLaunchEnv
26
- } from "@ycodium-ai/plugin-api/executor";
27
- function instanceAccountDirectory(pluginDataDir, instanceId) {
28
- return NodePath.join(
29
- pluginDataDir,
30
- "profiles",
31
- NodeCrypto.createHash("sha256").update(instanceId).digest("hex")
32
- );
33
- }
34
- function privateHomeFor(config2, env, variable, dataDir, id) {
35
- if (config2.privateAccount !== true || typeof config2.homePath === "string" && config2.homePath.trim() || env[variable]?.trim() || !id)
36
- return void 0;
37
- if (!dataDir) throw new Error("Executor plugin data directory unavailable");
38
- return instanceAccountDirectory(dataDir, id);
39
- }
40
- function applyPrivateAccountHome(recipe, settings, variable, dataDir, id, credentialVariables) {
41
- const home = privateHomeFor(
42
- { ...settings, homePath: recipe.homePath },
43
- recipe.environment,
44
- variable,
45
- dataDir,
46
- id
47
- );
48
- if (!home) return { recipe, home };
49
- const environment = { ...recipe.environment, [variable]: home };
50
- for (const key of credentialVariables) environment[key] ??= "";
51
- return { recipe: { ...recipe, homePath: home, environment }, home };
52
- }
53
- function expandHomePath(value) {
54
- if (value === "~") return NodeOS.homedir();
55
- if (value.startsWith("~/") || value.startsWith("~\\")) {
56
- return NodePath.join(NodeOS.homedir(), value.slice(2));
57
- }
58
- return value;
59
- }
60
- function homeLaunchEnv(recipe, configuredHomePath) {
61
- const homePath = configuredHomePath.trim();
62
- const homeEnvVar = recipe.homeEnvVar.trim();
63
- const homeInjection = homePath.length > 0 && homeEnvVar.length > 0 ? { [homeEnvVar]: expandHomePath(homePath) } : {};
64
- return mergeLaunchEnv({ accountHome: homeInjection, instanceTable: recipe.environment });
65
- }
66
- function homeContinuationKey(kind, recipe) {
67
- const homePath = recipe.homePath.trim();
68
- const resolvedHomePath = homePath.length > 0 ? NodePath.resolve(expandHomePath(homePath)) : "";
69
- return `${kind}:home:${recipe.binaryPath.trim()}\0${resolvedHomePath}`;
70
- }
71
- function registerEffectiveHomeCommand(ctx, homeEnvVar, resolve5, profileDataDir2) {
72
- ctx.command({
73
- name: "effectiveConfig",
74
- description: "Settings form: the account directory an empty path resolves to on this machine.",
75
- scope: "read",
76
- payloadSchema: EXECUTOR_EFFECTIVE_PAYLOAD_SCHEMA,
77
- handle: async (payload) => {
78
- const req = readExecutorEffectiveRequest(payload);
79
- if (profileDataDir2 && req.config.privateAccount === true && !req.instanceId && !req.environment[homeEnvVar]?.trim() && !req.config.homePath)
80
- return {};
81
- const home = profileDataDir2 && privateHomeFor(req.config, req.environment, homeEnvVar, profileDataDir2, req.instanceId);
82
- return {
83
- homePath: home ? { value: home, detailKey: "form.effective.default" } : executorHomeEffectiveValue(homeEnvVar, req, process.env, resolve5)
84
- };
85
- }
86
- });
87
- }
88
-
89
- // ../../packages/ycodium-instance-config/src/programHomeSchema.ts
90
- var executorEnvelopeFields = {
91
- enabled: { type: "boolean" },
92
- customModels: { type: "array" },
93
- driver: { type: "string" },
94
- config: { type: "object" },
95
- environment: { type: "array" }
96
- };
97
- function executorProgramField(name, options = {}) {
98
- return {
99
- type: "string",
100
- "x-ycodium-form": {
101
- titleKey: `form.${name}.title`,
102
- ...options.description === false ? {} : { descriptionKey: `form.${name}.description` },
103
- ...options.placeholder === false ? {} : { placeholderKey: `form.${name}.placeholder` },
104
- ...name === "binaryPath" ? { control: options.control ?? "executable-path" } : {},
105
- ...name === "homePath" || options.machineLocal ? { machineLocal: true } : {}
106
- }
107
- };
108
- }
109
- function programAndHomeConfigSchema(binaryPath) {
110
- return {
111
- type: "object",
112
- ...binaryPath.privateAccountOption ? { "x-ycodium-new-instance-defaults": { privateAccount: true } } : {},
113
- "x-ycodium-form-order": [
114
- "binaryPath",
115
- "homePath",
116
- ...binaryPath.privateAccountOption ? ["privateAccount"] : []
117
- ],
118
- properties: {
119
- ...executorEnvelopeFields,
120
- binaryPath: executorProgramField("binaryPath", {
121
- control: binaryPath.control,
122
- machineLocal: binaryPath.machineLocal === true
123
- }),
124
- homePath: executorProgramField("homePath"),
125
- ...binaryPath.privateAccountOption ? {
126
- privateAccount: {
127
- type: "boolean",
128
- default: false,
129
- "x-ycodium-form": {
130
- titleKey: "form.privateAccount.title",
131
- descriptionKey: "form.privateAccount.description"
132
- }
133
- }
134
- } : {}
135
- },
136
- additionalProperties: true
137
- };
138
- }
17
+ expandHomePath as expandHomePath2,
18
+ registerEffectiveHomeCommand
19
+ } from "@ycodium-ai/plugin-api/instance-config";
139
20
 
140
21
  // src/card.ts
22
+ import { programAndHomeConfigSchema } from "@ycodium-ai/plugin-api/instance-config";
141
23
  var KIMI_DRIVER_KIND = "kimiCode";
142
24
  var KIMI_CARD = {
143
25
  driverKind: KIMI_DRIVER_KIND,
@@ -202,108 +84,24 @@ var KIMI_CARD = {
202
84
  }
203
85
  };
204
86
 
205
- // ../../packages/ycodium-instance-config/src/instanceConfig.ts
206
- import { modelSelectionStringOption } from "@ycodium-ai/plugin-api/executor";
207
- function isRecord(value) {
208
- return typeof value === "object" && value !== null && !Array.isArray(value);
209
- }
210
- function readString(value) {
211
- return typeof value === "string" ? value : "";
212
- }
213
- function readTrimmed(value) {
214
- return readString(value).trim();
215
- }
216
- function modelIdFromSelection(selection) {
217
- if (!isRecord(selection)) return void 0;
218
- const model = selection["model"];
219
- return typeof model === "string" ? model.trim() || void 0 : void 0;
220
- }
221
- function readTurnSelection(selection, effortOptionId) {
222
- const requestedModelId = modelIdFromSelection(selection);
223
- const requestedEffort = modelSelectionStringOption(selection, effortOptionId);
224
- return {
225
- ...requestedModelId === void 0 ? {} : { requestedModelId },
226
- ...requestedEffort === void 0 ? {} : { requestedEffort }
227
- };
228
- }
229
- function readEnvironment(value) {
230
- if (!Array.isArray(value)) return {};
231
- const entries = [];
232
- for (const entry of value) {
233
- if (!isRecord(entry)) continue;
234
- const name = readTrimmed(entry["name"]);
235
- if (name.length === 0) continue;
236
- entries.push([name, readString(entry["value"])]);
237
- }
238
- return Object.fromEntries(entries);
239
- }
240
- function instanceSettings(config2) {
241
- if (!isRecord(config2)) return {};
242
- return isRecord(config2["config"]) ? config2["config"] : config2;
243
- }
244
- function readInstanceEnvelope(config2) {
245
- const envelope = isRecord(config2) ? config2 : {};
246
- const settings = instanceSettings(config2);
247
- return {
248
- settings,
249
- settingOrEnvelope: (key) => readTrimmed(settings[key]) || readTrimmed(envelope[key]),
250
- environment: readEnvironment(envelope["environment"]),
251
- envelopeDriver: readTrimmed(envelope["driver"]) || void 0
252
- };
253
- }
254
- function readLaunchInstanceRecipe(config2, defaultLaunchArgs = "") {
255
- const envelope = readInstanceEnvelope(config2);
256
- return {
257
- binaryPath: readTrimmed(envelope.settings["binaryPath"]),
258
- launchArgs: readString(envelope.settings["launchArgs"]) || defaultLaunchArgs,
259
- homePath: envelope.settingOrEnvelope("homePath"),
260
- homeEnvVar: envelope.settingOrEnvelope("homeEnvVar"),
261
- environment: envelope.environment,
262
- envelopeDriver: envelope.envelopeDriver
263
- };
264
- }
265
-
266
- // ../../packages/ycodium-jsonl-stream/src/sessionTranscript.ts
267
- var SESSION_IMPORT_ACTIVITY_TEXT_LIMIT = 32e3;
268
- function bounded(value, tail = false) {
269
- if (value.length <= SESSION_IMPORT_ACTIVITY_TEXT_LIMIT) return { text: value, truncated: false };
270
- const offset = tail ? value.length - SESSION_IMPORT_ACTIVITY_TEXT_LIMIT : SESSION_IMPORT_ACTIVITY_TEXT_LIMIT;
271
- const character = value.charCodeAt(offset);
272
- const previous = value.charCodeAt(offset - 1);
273
- const splitPair = character >= 56320 && character <= 57343 && previous >= 55296 && previous <= 56319;
274
- return {
275
- text: tail ? value.slice(offset + (splitPair ? 1 : 0)) : value.slice(0, offset - (splitPair ? 1 : 0)),
276
- truncated: true
277
- };
278
- }
279
- function inputPayload(input2) {
280
- if (input2 === void 0) return {};
281
- const result = bounded(input2);
282
- return { input: result.text, ...result.truncated ? { inputTruncated: true } : {} };
283
- }
284
- function outputPayload(output2) {
285
- if (output2 === void 0) return {};
286
- const result = bounded(output2, true);
287
- return { output: result.text, ...result.truncated ? { outputTruncated: true } : {} };
288
- }
289
- function sessionReadFromImport(nativeSessionId, imported) {
290
- return {
291
- nativeSessionId,
292
- model: imported.model,
293
- resumeCursor: imported.resumeCursor,
294
- messages: imported.messages.map(({ role, text: text2, createdAt }) => ({
295
- role,
296
- text: text2,
297
- createdAt: Date.parse(createdAt)
298
- }))
299
- };
300
- }
301
-
302
87
  // src/kimiInstance.ts
303
- import { raceAbort as raceAbort2 } from "@ycodium-ai/plugin-api/executor";
88
+ import {
89
+ applyPrivateAccountHome,
90
+ readInstanceEnvelope,
91
+ tokenizeShellWords,
92
+ expandHomePath,
93
+ homeContinuationKey,
94
+ homeLaunchEnv,
95
+ modelIdFromSelection,
96
+ readTurnSelection
97
+ } from "@ycodium-ai/plugin-api/instance-config";
98
+ import { sessionReadFromImport } from "@ycodium-ai/plugin-api/session-history";
99
+ import {
100
+ raceAbort as raceAbort2
101
+ } from "@ycodium-ai/plugin-api/executor";
304
102
 
305
103
  // ../../packages/ycodium-acp-executor/src/executor.ts
306
- import * as NodeCrypto2 from "node:crypto";
104
+ import * as NodeCrypto from "node:crypto";
307
105
 
308
106
  // ../../packages/ycodium-acp-executor/src/approvals.ts
309
107
  function createApprovalGate(input2) {
@@ -417,8 +215,8 @@ var UnboundedEventStream = class {
417
215
  iterators.subscribers.delete(subscriber);
418
216
  return { value: void 0, done: true };
419
217
  }
420
- await new Promise((resolve5) => {
421
- subscriber.wake = resolve5;
218
+ await new Promise((resolve3) => {
219
+ subscriber.wake = resolve3;
422
220
  });
423
221
  }
424
222
  },
@@ -439,7 +237,7 @@ var UnboundedEventStream = class {
439
237
  };
440
238
 
441
239
  // ../../packages/ycodium-acp-executor/src/config-options.ts
442
- function isRecord2(value) {
240
+ function isRecord(value) {
443
241
  return typeof value === "object" && value !== null && !Array.isArray(value);
444
242
  }
445
243
  function asString(value) {
@@ -458,7 +256,7 @@ function flattenChoices(rawOptions, currentValue) {
458
256
  const out = [];
459
257
  const seen = /* @__PURE__ */ new Set();
460
258
  const push = (entry) => {
461
- if (!isRecord2(entry)) return;
259
+ if (!isRecord(entry)) return;
462
260
  const value = asString(entry["value"]);
463
261
  if (value === void 0 || seen.has(value)) return;
464
262
  seen.add(value);
@@ -473,7 +271,7 @@ function flattenChoices(rawOptions, currentValue) {
473
271
  });
474
272
  };
475
273
  for (const entry of rawOptions) {
476
- if (isRecord2(entry) && Array.isArray(entry["options"])) {
274
+ if (isRecord(entry) && Array.isArray(entry["options"])) {
477
275
  for (const nested of entry["options"]) push(nested);
478
276
  continue;
479
277
  }
@@ -482,7 +280,7 @@ function flattenChoices(rawOptions, currentValue) {
482
280
  return out;
483
281
  }
484
282
  function isConfigOption(entry, configId) {
485
- return isRecord2(entry) && asString(entry["id"])?.trim() === configId.trim();
283
+ return isRecord(entry) && asString(entry["id"])?.trim() === configId.trim();
486
284
  }
487
285
  function findConfigOptionEntry(configOptions, configId) {
488
286
  return Array.isArray(configOptions) && configId.trim() !== "" ? configOptions.find(
@@ -497,7 +295,7 @@ function withConfigOptionValue(configOptions, configId, value) {
497
295
  }
498
296
  function pickEffortOption(configOptions) {
499
297
  if (!Array.isArray(configOptions)) return void 0;
500
- const candidates = configOptions.filter(isRecord2).filter((option) => normalizedField(option, "type") === "select").filter(looksLikeEffortOption);
298
+ const candidates = configOptions.filter(isRecord).filter((option) => normalizedField(option, "type") === "select").filter(looksLikeEffortOption);
501
299
  return candidates.find((option) => normalizedField(option, "category") === "model_option") ?? candidates.find((option) => normalizedField(option, "id") === "effort") ?? candidates.find((option) => normalizedField(option, "category") === "thought_level") ?? candidates[0];
502
300
  }
503
301
  function findAcpEffortConfig(configOptions) {
@@ -644,8 +442,8 @@ var settledExitCode = async (exited) => {
644
442
  try {
645
443
  return await Promise.race([
646
444
  exited.catch(() => void 0),
647
- new Promise((resolve5) => {
648
- timer = setTimeout(() => resolve5(void 0), AGENT_EXIT_SETTLE_MS);
445
+ new Promise((resolve3) => {
446
+ timer = setTimeout(() => resolve3(void 0), AGENT_EXIT_SETTLE_MS);
649
447
  })
650
448
  ]);
651
449
  } finally {
@@ -669,7 +467,7 @@ ${excerpt}`,
669
467
  }
670
468
 
671
469
  // ../../packages/ycodium-acp-executor/src/util.ts
672
- function isRecord3(value) {
470
+ function isRecord2(value) {
673
471
  return typeof value === "object" && value !== null && !Array.isArray(value);
674
472
  }
675
473
  function asTrimmedString(value) {
@@ -690,7 +488,7 @@ var selectPromptTurnId = (input2, activeTurnId, freshTurnId) => {
690
488
  };
691
489
 
692
490
  // ../../packages/ycodium-executor-common/src/toolPresentation.ts
693
- function isRecord4(value) {
491
+ function isRecord3(value) {
694
492
  return typeof value === "object" && value !== null && !Array.isArray(value);
695
493
  }
696
494
  function asTrimmedString2(value) {
@@ -732,11 +530,11 @@ function extractCommandFromTitle(title) {
732
530
  return backtickMatch?.[1]?.trim() || void 0;
733
531
  }
734
532
  function extractToolCommand(data, title) {
735
- const item = isRecord4(data?.["item"]) ? data["item"] : void 0;
736
- const itemInput = item && isRecord4(item["input"]) ? item["input"] : void 0;
737
- const itemResult = item && isRecord4(item["result"]) ? item["result"] : void 0;
738
- const rawInput = isRecord4(data?.["rawInput"]) ? data["rawInput"] : void 0;
739
- const dataInput = isRecord4(data?.["input"]) ? data["input"] : void 0;
533
+ const item = isRecord3(data?.["item"]) ? data["item"] : void 0;
534
+ const itemInput = item && isRecord3(item["input"]) ? item["input"] : void 0;
535
+ const itemResult = item && isRecord3(item["result"]) ? item["result"] : void 0;
536
+ const rawInput = isRecord3(data?.["rawInput"]) ? data["rawInput"] : void 0;
537
+ const dataInput = isRecord3(data?.["input"]) ? data["input"] : void 0;
740
538
  const candidates = [
741
539
  normalizeCommandValue(item?.["command"]),
742
540
  normalizeCommandValue(itemInput?.["command"]),
@@ -781,7 +579,7 @@ function collectPaths(value, paths, seen, depth) {
781
579
  }
782
580
  return;
783
581
  }
784
- if (!isRecord4(value)) {
582
+ if (!isRecord3(value)) {
785
583
  return;
786
584
  }
787
585
  for (const key of ["path", "filePath", "relativePath", "filename", "newPath", "oldPath"]) {
@@ -844,7 +642,7 @@ function deriveToolActivityPresentation(input2) {
844
642
  const title = asTrimmedString2(input2.title);
845
643
  const detail = stripTrailingExitCode(asTrimmedString2(input2.detail));
846
644
  const fallbackSummary = asTrimmedString2(input2.fallbackSummary) ?? "Tool";
847
- const data = isRecord4(input2.data) ? input2.data : void 0;
645
+ const data = isRecord3(input2.data) ? input2.data : void 0;
848
646
  const command = extractToolCommand(data, title);
849
647
  const primaryPath = extractPrimaryPath(data);
850
648
  const action = classifyToolAction({
@@ -876,7 +674,7 @@ function deriveToolActivityPresentation(input2) {
876
674
  };
877
675
  }
878
676
  if (action === "search") {
879
- const rawInput = isRecord4(data?.["rawInput"]) ? data["rawInput"] : void 0;
677
+ const rawInput = isRecord3(data?.["rawInput"]) ? data["rawInput"] : void 0;
880
678
  const query = asTrimmedString2(rawInput?.["query"]) ?? asTrimmedString2(rawInput?.["pattern"]) ?? asTrimmedString2(rawInput?.["searchTerm"]);
881
679
  return {
882
680
  summary: "Searched files",
@@ -953,7 +751,7 @@ function extractCommandFromTitle2(title) {
953
751
  return match?.[1]?.trim() || void 0;
954
752
  }
955
753
  function extractToolCallCommand(rawInput, title) {
956
- if (isRecord3(rawInput)) {
754
+ if (isRecord2(rawInput)) {
957
755
  const directCommand = normalizeCommandValue2(rawInput["command"]);
958
756
  if (directCommand) {
959
757
  return directCommand;
@@ -981,19 +779,19 @@ function boundTailText(text2, limit = TOOL_CALL_CONTENT_MAX_CHARS) {
981
779
  var boundToolCallOutputText = (text2) => boundTailText(text2);
982
780
  var RAW_OUTPUT_TEXT_FIELDS = ["content", "stdout", "stderr", "output"];
983
781
  function boundToolCallRawOutput(rawOutput) {
984
- if (!isRecord3(rawOutput)) {
782
+ if (!isRecord2(rawOutput)) {
985
783
  return rawOutput;
986
784
  }
987
785
  let changed = false;
988
- const bounded2 = { ...rawOutput };
786
+ const bounded = { ...rawOutput };
989
787
  for (const field of RAW_OUTPUT_TEXT_FIELDS) {
990
788
  const value = rawOutput[field];
991
789
  if (typeof value === "string" && value.length > TOOL_CALL_CONTENT_MAX_CHARS) {
992
- bounded2[field] = boundToolCallOutputText(value);
790
+ bounded[field] = boundToolCallOutputText(value);
993
791
  changed = true;
994
792
  }
995
793
  }
996
- return changed ? bounded2 : rawOutput;
794
+ return changed ? bounded : rawOutput;
997
795
  }
998
796
  function toolCallContentText(entry) {
999
797
  if (entry.type !== "content" || entry.content?.type !== "text") {
@@ -1020,7 +818,7 @@ function extractTextContentFromToolCallContent(content) {
1020
818
  if (joined.length <= TOOL_CALL_CONTENT_MAX_CHARS) {
1021
819
  return { text: joined, content: typed };
1022
820
  }
1023
- const bounded2 = boundToolCallOutputText(joined);
821
+ const bounded = boundToolCallOutputText(joined);
1024
822
  const lastContributingTextIndex = typed.reduce(
1025
823
  (lastIndex, entry, index) => toolCallContentText(entry)?.trim() ? index : lastIndex,
1026
824
  -1
@@ -1032,9 +830,9 @@ function extractTextContentFromToolCallContent(content) {
1032
830
  if (index !== lastContributingTextIndex) {
1033
831
  return [];
1034
832
  }
1035
- return [{ type: "content", content: { type: "text", text: bounded2 } }];
833
+ return [{ type: "content", content: { type: "text", text: bounded } }];
1036
834
  });
1037
- return { text: bounded2, content: boundedContent };
835
+ return { text: bounded, content: boundedContent };
1038
836
  }
1039
837
  function normalizeToolKind(kind) {
1040
838
  return typeof kind === "string" && kind.trim().length > 0 ? kind.trim() : void 0;
@@ -1197,11 +995,11 @@ function collectSessionConfigOptionValues(configOption) {
1197
995
  );
1198
996
  }
1199
997
  function collectSessionModelIds(models) {
1200
- if (!isRecord3(models) || !Array.isArray(models["availableModels"])) {
998
+ if (!isRecord2(models) || !Array.isArray(models["availableModels"])) {
1201
999
  return [];
1202
1000
  }
1203
1001
  return models["availableModels"].flatMap(
1204
- (model) => isRecord3(model) && typeof model["modelId"] === "string" ? [model["modelId"]] : []
1002
+ (model) => isRecord2(model) && typeof model["modelId"] === "string" ? [model["modelId"]] : []
1205
1003
  );
1206
1004
  }
1207
1005
  function parseSessionModeState(sessionResponse) {
@@ -1249,7 +1047,7 @@ function parseAvailableCommandsUpdate(params) {
1249
1047
  }
1250
1048
  const commands = [];
1251
1049
  for (const command of availableCommands) {
1252
- if (!isRecord3(command)) {
1050
+ if (!isRecord2(command)) {
1253
1051
  continue;
1254
1052
  }
1255
1053
  const name = typeof command["name"] === "string" ? command["name"].trim() : "";
@@ -1257,7 +1055,7 @@ function parseAvailableCommandsUpdate(params) {
1257
1055
  continue;
1258
1056
  }
1259
1057
  const description = typeof command["description"] === "string" ? command["description"].trim() || void 0 : void 0;
1260
- const input2 = isRecord3(command["input"]) ? command["input"] : void 0;
1058
+ const input2 = isRecord2(command["input"]) ? command["input"] : void 0;
1261
1059
  const inputHint = typeof input2?.["hint"] === "string" ? input2["hint"].trim() || void 0 : void 0;
1262
1060
  commands.push({
1263
1061
  name,
@@ -1287,7 +1085,7 @@ function parsePermissionRequest(params, known) {
1287
1085
  const kind = toolCall?.kind ?? "unknown";
1288
1086
  const content = toolCall?.data["content"];
1289
1087
  const firstText = Array.isArray(content) ? content.flatMap((entry) => {
1290
- if (!isRecord3(entry) || entry["type"] !== "content" || !isRecord3(entry["content"]))
1088
+ if (!isRecord2(entry) || entry["type"] !== "content" || !isRecord2(entry["content"]))
1291
1089
  return [];
1292
1090
  const block = entry["content"];
1293
1091
  return block["type"] === "text" && typeof block["text"] === "string" && block["text"].trim() ? [block["text"]] : [];
@@ -1319,7 +1117,7 @@ function boundToolCallRawPayload(params, update, toolCall) {
1319
1117
  }
1320
1118
  function textFromContentBlocks(blocks) {
1321
1119
  const parts = blocks.flatMap(
1322
- (block) => isRecord3(block) && block["type"] === "text" && typeof block["text"] === "string" ? [block["text"]] : []
1120
+ (block) => isRecord2(block) && block["type"] === "text" && typeof block["text"] === "string" ? [block["text"]] : []
1323
1121
  );
1324
1122
  const joined = parts.join("");
1325
1123
  return joined.trim().length > 0 ? joined : void 0;
@@ -1344,7 +1142,7 @@ function parseSessionUpdateEvent(params) {
1344
1142
  const entries = Array.isArray(upd["entries"]) ? upd["entries"] : [];
1345
1143
  const plan = entries.map((entry, index) => ({
1346
1144
  step: readAcpText(entry, "content") ?? `Step ${index + 1}`,
1347
- status: normalizePlanStepStatus(isRecord3(entry) ? entry["status"] : void 0)
1145
+ status: normalizePlanStepStatus(isRecord2(entry) ? entry["status"] : void 0)
1348
1146
  }));
1349
1147
  if (plan.length > 0) {
1350
1148
  events.push({
@@ -1384,7 +1182,7 @@ function parseSessionUpdateEvent(params) {
1384
1182
  }
1385
1183
  case "agent_message_chunk":
1386
1184
  case "agent_thought_chunk": {
1387
- const content = isRecord3(upd["content"]) ? upd["content"] : void 0;
1185
+ const content = isRecord2(upd["content"]) ? upd["content"] : void 0;
1388
1186
  const contentType = content?.["type"];
1389
1187
  const streamKind = kind === "agent_thought_chunk" ? "reasoning_text" : "assistant_text";
1390
1188
  if (contentType === "text") {
@@ -1432,7 +1230,7 @@ function parseSessionUpdateEvent(params) {
1432
1230
  }
1433
1231
  case "compaction_summary_chunk": {
1434
1232
  const compactionId = readAcpText(upd, "compactionId");
1435
- const content = isRecord3(upd["content"]) ? upd["content"] : void 0;
1233
+ const content = isRecord2(upd["content"]) ? upd["content"] : void 0;
1436
1234
  const text2 = content?.["type"] === "text" ? content["text"] : void 0;
1437
1235
  if (compactionId === void 0 || typeof text2 !== "string" || text2.length === 0) break;
1438
1236
  events.push({ _tag: "CompactionSummaryChunk", compactionId, text: text2 });
@@ -3611,18 +3409,18 @@ var validateAsync = async (schema, value, _ctx) => {
3611
3409
  return result.issues.length === 0;
3612
3410
  };
3613
3411
  var _encode = (_Err) => {
3614
- const parse4 = _parse(_Err);
3412
+ const parse3 = _parse(_Err);
3615
3413
  const fn = (schema, value, _ctx, _params) => {
3616
3414
  const ctx = _ctx ? { ..._ctx, direction: "backward" } : { direction: "backward" };
3617
- return parse4(schema, value, ctx, finalizeParams(fn, _params));
3415
+ return parse3(schema, value, ctx, finalizeParams(fn, _params));
3618
3416
  };
3619
3417
  return fn;
3620
3418
  };
3621
3419
  var encode = /* @__PURE__ */ _encode($ZodRealError);
3622
3420
  var _decode = (_Err) => {
3623
- const parse4 = _parse(_Err);
3421
+ const parse3 = _parse(_Err);
3624
3422
  const fn = (schema, value, _ctx, _params) => {
3625
- return parse4(schema, value, _ctx, finalizeParams(fn, _params));
3423
+ return parse3(schema, value, _ctx, finalizeParams(fn, _params));
3626
3424
  };
3627
3425
  return fn;
3628
3426
  };
@@ -6792,7 +6590,7 @@ var recursive = /* @__PURE__ */ new WeakMap();
6792
6590
  var NONE = 0;
6793
6591
  var ASSUMED = 1;
6794
6592
  var PROVEN = 2;
6795
- function isRecursive(inst, stack, resolve5) {
6593
+ function isRecursive(inst, stack, resolve3) {
6796
6594
  const cached2 = recursive.get(inst);
6797
6595
  if (cached2 !== void 0)
6798
6596
  return cached2 ? PROVEN : NONE;
@@ -6802,7 +6600,7 @@ function isRecursive(inst, stack, resolve5) {
6802
6600
  let result = NONE;
6803
6601
  const check2 = (child) => {
6804
6602
  if (result !== PROVEN && child?._zod) {
6805
- const answer = isRecursive(child, stack, resolve5);
6603
+ const answer = isRecursive(child, stack, resolve3);
6806
6604
  if (answer > result)
6807
6605
  result = answer;
6808
6606
  }
@@ -6813,7 +6611,7 @@ function isRecursive(inst, stack, resolve5) {
6813
6611
  const desc = Object.getOwnPropertyDescriptor(sh, key);
6814
6612
  if (spread && !desc.enumerable)
6815
6613
  continue;
6816
- const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve5) : NONE;
6614
+ const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve3) : NONE;
6817
6615
  if (child > answer)
6818
6616
  answer = child;
6819
6617
  }
@@ -6877,7 +6675,7 @@ function isRecursive(inst, stack, resolve5) {
6877
6675
  break;
6878
6676
  // `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
6879
6677
  case "lazy": {
6880
- const inner = def._cachedInner ?? (resolve5 ? inst._zod.innerType : void 0);
6678
+ const inner = def._cachedInner ?? (resolve3 ? inst._zod.innerType : void 0);
6881
6679
  merge2(inner ? isRecursive(inner, stack, false) : ASSUMED);
6882
6680
  break;
6883
6681
  }
@@ -23127,17 +22925,17 @@ function isResponseMessage(value) {
23127
22925
  function isNotificationMessage(value) {
23128
22926
  return isJsonRpcEnvelope(value) && !("id" in value) && typeof value["method"] === "string";
23129
22927
  }
23130
- function isRecord5(value) {
22928
+ function isRecord4(value) {
23131
22929
  return typeof value === "object" && value !== null;
23132
22930
  }
23133
22931
  function isJsonRpcEnvelope(value) {
23134
- return isRecord5(value) && value["jsonrpc"] === "2.0";
22932
+ return isRecord4(value) && value["jsonrpc"] === "2.0";
23135
22933
  }
23136
22934
  function isJsonRpcId(value) {
23137
22935
  return value === null || typeof value === "string" || typeof value === "number" && Number.isFinite(value);
23138
22936
  }
23139
22937
  function isResponseShapedMessage(value) {
23140
- return isRecord5(value) && !("method" in value) && ("id" in value || "result" in value || "error" in value);
22938
+ return isRecord4(value) && !("method" in value) && ("id" in value || "result" in value || "error" in value);
23141
22939
  }
23142
22940
  function isResponseBatch(batch) {
23143
22941
  let hasValidCall = false;
@@ -23147,7 +22945,7 @@ function isResponseBatch(batch) {
23147
22945
  for (const entry of batch) {
23148
22946
  hasValidCall ||= isRequestMessage(entry) || isNotificationMessage(entry);
23149
22947
  hasValidResponse ||= isResponseMessage(entry);
23150
- if (!isRecord5(entry)) {
22948
+ if (!isRecord4(entry)) {
23151
22949
  continue;
23152
22950
  }
23153
22951
  hasCallShape ||= "method" in entry;
@@ -23162,13 +22960,13 @@ function isResponseBatch(batch) {
23162
22960
  return hasResponseShape && !hasCallShape;
23163
22961
  }
23164
22962
  function cancelRequestId(params) {
23165
- if (!isRecord5(params) || !isJsonRpcId(params["requestId"])) {
22963
+ if (!isRecord4(params) || !isJsonRpcId(params["requestId"])) {
23166
22964
  return void 0;
23167
22965
  }
23168
22966
  return params["requestId"];
23169
22967
  }
23170
22968
  function isErrorResponse(value) {
23171
- return isRecord5(value) && typeof value["code"] === "number" && Number.isInteger(value["code"]) && typeof value["message"] === "string";
22969
+ return isRecord4(value) && typeof value["code"] === "number" && Number.isInteger(value["code"]) && typeof value["message"] === "string";
23172
22970
  }
23173
22971
  var Handled = {
23174
22972
  /**
@@ -23541,11 +23339,11 @@ var Connection = class {
23541
23339
  const id = this.nextRequestId++;
23542
23340
  let cancel = () => {
23543
23341
  };
23544
- const response = new Promise((resolve5, reject) => {
23342
+ const response = new Promise((resolve3, reject) => {
23545
23343
  const pendingResponse = {
23546
23344
  resolve: (value) => {
23547
23345
  try {
23548
- resolve5(mapResponse ? mapResponse(value) : value);
23346
+ resolve3(mapResponse ? mapResponse(value) : value);
23549
23347
  } catch (error62) {
23550
23348
  reject(error62);
23551
23349
  }
@@ -23602,8 +23400,8 @@ var Connection = class {
23602
23400
  this.stream = stream;
23603
23401
  this.staticHandlers = handlers;
23604
23402
  this.allowBatches = options?.allowBatches ?? true;
23605
- this.closedPromise = new Promise((resolve5) => {
23606
- this.abortController.signal.addEventListener("abort", () => resolve5());
23403
+ this.closedPromise = new Promise((resolve3) => {
23404
+ this.abortController.signal.addEventListener("abort", () => resolve3());
23607
23405
  });
23608
23406
  void this.receive();
23609
23407
  }
@@ -23713,7 +23511,7 @@ var Connection = class {
23713
23511
  if (this.abortController.signal.aborted) {
23714
23512
  return Promise.resolve();
23715
23513
  }
23716
- if (!isRecord5(message)) {
23514
+ if (!isRecord4(message)) {
23717
23515
  console.error("Invalid message", { message });
23718
23516
  return Promise.resolve();
23719
23517
  }
@@ -23894,13 +23692,13 @@ var ConnectionBuilder = class {
23894
23692
  /**
23895
23693
  * Adds a typed request handler for one method.
23896
23694
  */
23897
- onReceiveRequest(method, parse4, handler) {
23695
+ onReceiveRequest(method, parse3, handler) {
23898
23696
  return this.withHandler({
23899
23697
  handleMessage: async (message, cx) => {
23900
23698
  if (message.kind !== "request" || message.method !== method) {
23901
23699
  return Handled.no(message);
23902
23700
  }
23903
- const request = parse4(message.params);
23701
+ const request = parse3(message.params);
23904
23702
  return await handler(request, message.responder, cx) ?? Handled.yes();
23905
23703
  },
23906
23704
  describe: () => `${this.connectionName ?? "request"}:${method}`
@@ -23909,13 +23707,13 @@ var ConnectionBuilder = class {
23909
23707
  /**
23910
23708
  * Adds a typed notification handler for one method.
23911
23709
  */
23912
- onReceiveNotification(method, parse4, handler) {
23710
+ onReceiveNotification(method, parse3, handler) {
23913
23711
  return this.withHandler({
23914
23712
  handleMessage: async (message, cx) => {
23915
23713
  if (message.kind !== "notification" || message.method !== method) {
23916
23714
  return Handled.no(message);
23917
23715
  }
23918
- const notification = parse4(message.params);
23716
+ const notification = parse3(message.params);
23919
23717
  return await handler(notification, cx) ?? Handled.yes();
23920
23718
  },
23921
23719
  describe: () => `${this.connectionName ?? "notification"}:${method}`
@@ -24116,7 +23914,7 @@ function ndJsonStream(output2, input2) {
24116
23914
  await writeJson(protocolErrorResponse(RequestError.parseError()));
24117
23915
  return;
24118
23916
  }
24119
- if (isRecord5(message) || Array.isArray(message)) {
23917
+ if (isRecord4(message) || Array.isArray(message)) {
24120
23918
  controller.enqueue(message);
24121
23919
  } else {
24122
23920
  await writeJson(protocolErrorResponse(RequestError.invalidRequest(message)));
@@ -24497,8 +24295,8 @@ var AsyncQueue = class {
24497
24295
  if (this.failed) {
24498
24296
  return Promise.reject(this.failure);
24499
24297
  }
24500
- return new Promise((resolve5, reject) => {
24501
- this.waiters.push({ resolve: resolve5, reject });
24298
+ return new Promise((resolve3, reject) => {
24299
+ this.waiters.push({ resolve: resolve3, reject });
24502
24300
  });
24503
24301
  }
24504
24302
  };
@@ -25103,14 +24901,14 @@ var legacyClientNotificationMethods = /* @__PURE__ */ new Set([
25103
24901
  import * as NodeStream from "node:stream";
25104
24902
 
25105
24903
  // ../../packages/ycodium-acp-executor/src/jsonrpc.ts
25106
- function isRecord6(value) {
24904
+ function isRecord5(value) {
25107
24905
  return typeof value === "object" && value !== null;
25108
24906
  }
25109
24907
  function isJsonRpcId2(value) {
25110
24908
  return typeof value === "string" || typeof value === "number" && Number.isFinite(value);
25111
24909
  }
25112
24910
  function isJsonRpcEnvelope2(value) {
25113
- return isRecord6(value) && value["jsonrpc"] === "2.0";
24911
+ return isRecord5(value) && value["jsonrpc"] === "2.0";
25114
24912
  }
25115
24913
  function isRequestMessage2(value) {
25116
24914
  return isJsonRpcEnvelope2(value) && "id" in value && typeof value["method"] === "string" && isJsonRpcId2(value["id"]);
@@ -25130,7 +24928,7 @@ function isNotificationMessage2(value) {
25130
24928
  return isJsonRpcEnvelope2(value) && !("id" in value) && typeof value["method"] === "string";
25131
24929
  }
25132
24930
  function readJsonRpcError(value) {
25133
- if (!isRecord6(value) || typeof value["code"] !== "number" || typeof value["message"] !== "string") {
24931
+ if (!isRecord5(value) || typeof value["code"] !== "number" || typeof value["message"] !== "string") {
25134
24932
  return void 0;
25135
24933
  }
25136
24934
  return {
@@ -25203,11 +25001,11 @@ var KNOWN_SESSION_UPDATES = /* @__PURE__ */ new Set([
25203
25001
  "compaction_summary_chunk"
25204
25002
  ]);
25205
25003
  function isSessionUpdateEnvelope(payload) {
25206
- if (!isRecord6(payload) || typeof payload["sessionId"] !== "string") {
25004
+ if (!isRecord5(payload) || typeof payload["sessionId"] !== "string") {
25207
25005
  return false;
25208
25006
  }
25209
25007
  const update = payload["update"];
25210
- return isRecord6(update) && typeof update["sessionUpdate"] === "string";
25008
+ return isRecord5(update) && typeof update["sessionUpdate"] === "string";
25211
25009
  }
25212
25010
  function hasKnownVariantShape(update) {
25213
25011
  const kind = update["sessionUpdate"];
@@ -25215,7 +25013,7 @@ function hasKnownVariantShape(update) {
25215
25013
  return false;
25216
25014
  }
25217
25015
  if (kind === "user_message_chunk" || kind === "agent_message_chunk" || kind === "agent_thought_chunk") {
25218
- return isRecord6(update["content"]);
25016
+ return isRecord5(update["content"]);
25219
25017
  }
25220
25018
  return true;
25221
25019
  }
@@ -25545,12 +25343,12 @@ function createAcpConnection(options) {
25545
25343
  failIfClosed();
25546
25344
  const id = nextRequestId;
25547
25345
  nextRequestId += 1;
25548
- const { promise: promise2, resolve: resolve5, reject } = Promise.withResolvers();
25346
+ const { promise: promise2, resolve: resolve3, reject } = Promise.withResolvers();
25549
25347
  pending.set(String(id), {
25550
25348
  method,
25551
25349
  ...promptId === void 0 ? {} : { promptId },
25552
25350
  ...onArrival === void 0 ? {} : { onArrival },
25553
- resolve: resolve5,
25351
+ resolve: resolve3,
25554
25352
  reject
25555
25353
  });
25556
25354
  const message = params === void 0 ? { jsonrpc: "2.0", id, method } : { jsonrpc: "2.0", id, method, params };
@@ -25579,8 +25377,8 @@ function createAcpConnection(options) {
25579
25377
  if (inboundBatches === 0) {
25580
25378
  return;
25581
25379
  }
25582
- await new Promise((resolve5) => {
25583
- idleWaiters.push(resolve5);
25380
+ await new Promise((resolve3) => {
25381
+ idleWaiters.push(resolve3);
25584
25382
  if (inboundBatches === 0) {
25585
25383
  releaseIdleWaiters();
25586
25384
  }
@@ -25625,7 +25423,7 @@ function forgetConfigOptionValue(state, configId) {
25625
25423
  const forgetsModel = configId === void 0 || configId === state.modelConfigId;
25626
25424
  const { currentModelReported: _forgottenReport, ...withoutReport } = state;
25627
25425
  const configOptions = configId !== void 0 && Array.isArray(state.configOptions) ? state.configOptions.map((option) => {
25628
- if (!isRecord3(option) || option["id"] !== configId) return option;
25426
+ if (!isRecord2(option) || option["id"] !== configId) return option;
25629
25427
  const { currentValue: _forgotten, ...rest } = option;
25630
25428
  return rest;
25631
25429
  }) : state.configOptions;
@@ -25636,7 +25434,7 @@ function forgetConfigOptionValue(state, configId) {
25636
25434
  };
25637
25435
  }
25638
25436
  function modelSelectionStateFromSetup(setup) {
25639
- const sessionModels = isRecord3(setup.models) ? setup.models : void 0;
25437
+ const sessionModels = isRecord2(setup.models) ? setup.models : void 0;
25640
25438
  const modelConfigId = extractModelConfigId(setup);
25641
25439
  const strategy = modelConfigId !== void 0 ? "config-option" : "session/set_model";
25642
25440
  const modelConfigOption = modelConfigId === void 0 ? void 0 : findSessionConfigOption(setup.configOptions, modelConfigId);
@@ -25666,8 +25464,8 @@ var Mutex = class {
25666
25464
  this.locked = true;
25667
25465
  return Promise.resolve();
25668
25466
  }
25669
- return new Promise((resolve5) => {
25670
- this.waiters.push(resolve5);
25467
+ return new Promise((resolve3) => {
25468
+ this.waiters.push(resolve3);
25671
25469
  });
25672
25470
  }
25673
25471
  tryAcquire() {
@@ -25868,9 +25666,9 @@ function createExecutorLifecycle({
25868
25666
  let timer;
25869
25667
  await Promise.race([
25870
25668
  connection.closed.catch(() => void 0),
25871
- new Promise((resolve5) => {
25669
+ new Promise((resolve3) => {
25872
25670
  timer = setTimeout(
25873
- resolve5,
25671
+ resolve3,
25874
25672
  options.resultDrainTimeoutMs ?? DEFAULT_RESULT_DRAIN_TIMEOUT_MS
25875
25673
  );
25876
25674
  })
@@ -26043,7 +25841,7 @@ function toolSubagentSettlementOfTurn(state, failureCategory) {
26043
25841
  if (state === "cancelled") return "turn-interrupted";
26044
25842
  return state === "failed" && failureCategory === "process-exit" ? "session-ended" : "turn-ended";
26045
25843
  }
26046
- 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;
25844
+ 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.nativeSessionId === b.nativeSessionId && a.rosterKind === b.rosterKind;
26047
25845
  function linkage(taskId, toolCallId, facts) {
26048
25846
  return {
26049
25847
  taskId,
@@ -26053,6 +25851,7 @@ function linkage(taskId, toolCallId, facts) {
26053
25851
  ...facts.role === void 0 ? {} : { role: facts.role },
26054
25852
  ...facts.model === void 0 ? {} : { model: facts.model },
26055
25853
  ...facts.effort === void 0 ? {} : { effort: facts.effort },
25854
+ ...facts.nativeSessionId === void 0 ? {} : { nativeSessionId: facts.nativeSessionId },
26056
25855
  ...facts.rosterKind === void 0 ? {} : { rosterKind: facts.rosterKind }
26057
25856
  };
26058
25857
  }
@@ -26747,12 +26546,12 @@ function createPromptResults({
26747
26546
  }) {
26748
26547
  const prompts = /* @__PURE__ */ new Map();
26749
26548
  const add = (identity, finish) => {
26750
- const { promise: done, resolve: resolve5 } = Promise.withResolvers();
26549
+ const { promise: done, resolve: resolve3 } = Promise.withResolvers();
26751
26550
  const record3 = {
26752
26551
  ...identity,
26753
26552
  finish,
26754
26553
  done,
26755
- resolve: resolve5,
26554
+ resolve: resolve3,
26756
26555
  rejected: false,
26757
26556
  interrupted: false,
26758
26557
  finished: false
@@ -26800,9 +26599,9 @@ function createPromptResults({
26800
26599
  try {
26801
26600
  const drained = await Promise.race([
26802
26601
  Promise.all(claimed.map((record3) => record3.done)).then(() => true),
26803
- new Promise((resolve5) => {
26602
+ new Promise((resolve3) => {
26804
26603
  timer = setTimeout(
26805
- () => resolve5(false),
26604
+ () => resolve3(false),
26806
26605
  options.resultDrainTimeoutMs ?? DEFAULT_RESULT_DRAIN_TIMEOUT_MS
26807
26606
  );
26808
26607
  })
@@ -26831,7 +26630,7 @@ function createPromptResults({
26831
26630
  // ../../packages/ycodium-acp-executor/src/permission-statement.ts
26832
26631
  function defaultPermissionStatement(request) {
26833
26632
  const rawInput = request.toolCall?.data["rawInput"];
26834
- const input2 = isRecord3(rawInput) ? rawInput : {};
26633
+ const input2 = isRecord2(rawInput) ? rawInput : {};
26835
26634
  const coveredArgs = [];
26836
26635
  const text2 = (name) => {
26837
26636
  const value = input2[name];
@@ -27001,14 +26800,14 @@ function createExecutorRequests({
27001
26800
  const statement = hooks.permissionStatement?.(permissionContext) ?? defaultPermissionStatement(permissionRequest);
27002
26801
  const fileChanges = hooks.permissionFileChanges?.(permissionContext) ?? fileChangesFromAcpPermission(permissionRequest);
27003
26802
  const requestId = randomId();
27004
- const outcome = await new Promise((resolve5) => {
26803
+ const outcome = await new Promise((resolve3) => {
27005
26804
  const pending = {
27006
26805
  requestId,
27007
26806
  request: params,
27008
26807
  permissionRequest,
27009
26808
  turnId: shared.activeTurnId,
27010
26809
  settled: false,
27011
- resolve: resolve5
26810
+ resolve: resolve3
27012
26811
  };
27013
26812
  approvals.add(pending);
27014
26813
  emit(
@@ -27077,7 +26876,7 @@ function createExecutorRequests({
27077
26876
  pendingUserInputs.delete(requestId);
27078
26877
  pending.resolve({
27079
26878
  kind: "answered",
27080
- answers: isRecord3(answers) ? answers : {}
26879
+ answers: isRecord2(answers) ? answers : {}
27081
26880
  });
27082
26881
  };
27083
26882
  return {
@@ -27091,7 +26890,7 @@ function createExecutorRequests({
27091
26890
  }
27092
26891
 
27093
26892
  // ../../packages/ycodium-acp-executor/src/artifacts.ts
27094
- import * as NodePath2 from "node:path";
26893
+ import * as NodePath from "node:path";
27095
26894
  import * as NodeURL from "node:url";
27096
26895
  function resourceLinkArtifacts(content) {
27097
26896
  if (content["type"] !== "resource_link" || typeof content["uri"] !== "string") return [];
@@ -27102,7 +26901,7 @@ function resourceLinkArtifacts(content) {
27102
26901
  } catch {
27103
26902
  return [];
27104
26903
  }
27105
- if (!NodePath2.isAbsolute(path)) return [];
26904
+ if (!NodePath.isAbsolute(path)) return [];
27106
26905
  const name = typeof content["name"] === "string" ? content["name"].trim() : "";
27107
26906
  const mimeType = typeof content["mimeType"] === "string" ? content["mimeType"].trim() : "";
27108
26907
  return [
@@ -27225,14 +27024,14 @@ function createExecutorRuntime({
27225
27024
  if (!promptMutex.isLocked) {
27226
27025
  return true;
27227
27026
  }
27228
- return await new Promise((resolve5) => {
27027
+ return await new Promise((resolve3) => {
27229
27028
  const timer = setTimeout(() => {
27230
27029
  shared.promptWaiters = shared.promptWaiters.filter((waiter) => waiter !== onSettle);
27231
- resolve5(false);
27030
+ resolve3(false);
27232
27031
  }, timeoutMs);
27233
27032
  const onSettle = () => {
27234
27033
  clearTimeout(timer);
27235
- resolve5(true);
27034
+ resolve3(true);
27236
27035
  };
27237
27036
  shared.promptWaiters.push(onSettle);
27238
27037
  });
@@ -27374,18 +27173,18 @@ function modelRefreshFailedError(requestedModelId, error62) {
27374
27173
  }
27375
27174
 
27376
27175
  // ../../packages/ycodium-acp-executor/src/runtime-mode.ts
27377
- function isRecord7(value) {
27176
+ function isRecord6(value) {
27378
27177
  return typeof value === "object" && value !== null && !Array.isArray(value);
27379
27178
  }
27380
27179
  function asString2(value) {
27381
27180
  return typeof value === "string" ? value : void 0;
27382
27181
  }
27383
27182
  function acpModeConfigId(setup) {
27384
- if (!isRecord7(setup)) return void 0;
27183
+ if (!isRecord6(setup)) return void 0;
27385
27184
  const configOptions = setup["configOptions"];
27386
27185
  if (!Array.isArray(configOptions)) return void 0;
27387
27186
  for (const option of configOptions) {
27388
- if (!isRecord7(option)) continue;
27187
+ if (!isRecord6(option)) continue;
27389
27188
  if (asString2(option["category"])?.trim().toLowerCase() !== "mode") continue;
27390
27189
  const id = asString2(option["id"])?.trim();
27391
27190
  if (id) return id;
@@ -27393,16 +27192,16 @@ function acpModeConfigId(setup) {
27393
27192
  return void 0;
27394
27193
  }
27395
27194
  function acpCurrentModeId(setup) {
27396
- if (!isRecord7(setup)) return void 0;
27195
+ if (!isRecord6(setup)) return void 0;
27397
27196
  const modes = setup["modes"];
27398
- if (isRecord7(modes)) {
27197
+ if (isRecord6(modes)) {
27399
27198
  const current = asString2(modes["currentModeId"])?.trim();
27400
27199
  if (current) return current;
27401
27200
  }
27402
27201
  const configOptions = setup["configOptions"];
27403
27202
  if (Array.isArray(configOptions)) {
27404
27203
  for (const option of configOptions) {
27405
- if (!isRecord7(option)) continue;
27204
+ if (!isRecord6(option)) continue;
27406
27205
  if (asString2(option["category"])?.trim().toLowerCase() !== "mode") continue;
27407
27206
  const current = asString2(option["currentValue"])?.trim();
27408
27207
  if (current) return current;
@@ -27601,10 +27400,27 @@ function createExecutorSession({
27601
27400
  throw new AcpExecutorDisposedError();
27602
27401
  }
27603
27402
  }
27403
+ const mcpCapabilities = initialized.agentCapabilities?.mcpCapabilities ?? hooks.mcpCapabilities;
27404
+ const requestedMcpServers = options.mcpServers ?? [];
27604
27405
  const mcpServers = filterMcpServersByAgentCapabilities(
27605
- options.mcpServers ?? [],
27606
- initialized.agentCapabilities
27406
+ requestedMcpServers,
27407
+ mcpCapabilities === void 0 ? initialized.agentCapabilities : { mcpCapabilities }
27607
27408
  );
27409
+ if (mcpServers.length < requestedMcpServers.length) {
27410
+ const kept = new Set(mcpServers);
27411
+ const dropped = requestedMcpServers.filter((server) => !kept.has(server)).map((server) => ({
27412
+ ...typeof server["name"] === "string" ? { name: server["name"] } : {},
27413
+ ...typeof server.type === "string" ? { type: server.type } : {}
27414
+ }));
27415
+ options.log?.warn?.(
27416
+ "acp session dropped MCP servers whose transport was not advertised in initialize.agentCapabilities.mcpCapabilities; set hooks.mcpCapabilities if the agent supports the transport without reporting it",
27417
+ {
27418
+ threadId: options.threadId,
27419
+ dropped,
27420
+ advertisedMcpCapabilities: initialized.agentCapabilities?.mcpCapabilities ?? null
27421
+ }
27422
+ );
27423
+ }
27608
27424
  const additionalDirectories = options.additionalDirectories !== void 0 && options.additionalDirectories.length > 0 ? { additionalDirectories: options.additionalDirectories } : {};
27609
27425
  let setup;
27610
27426
  let nextSessionId;
@@ -27851,14 +27667,14 @@ function createExecutorSettlement({
27851
27667
 
27852
27668
  // ../../packages/ycodium-acp-executor/src/executor/subagent-sessions.ts
27853
27669
  function parseState(raw) {
27854
- if (!isRecord3(raw)) return { status: void 0, error: void 0 };
27670
+ if (!isRecord2(raw)) return { status: void 0, error: void 0 };
27855
27671
  const state = raw["state"];
27856
27672
  if (state === "running") return { status: "running", error: void 0 };
27857
27673
  if (state === "requires_action") return { status: "waiting", error: void 0 };
27858
27674
  if (state !== "idle") return { status: void 0, error: void 0 };
27859
27675
  const stopReason = raw["stopReason"];
27860
- const error62 = isRecord3(raw["error"]) ? asTrimmedString(raw["error"]["message"]) : void 0;
27861
- if (stopReason === "error" || isRecord3(raw["error"])) return { status: "failed", error: error62 };
27676
+ const error62 = isRecord2(raw["error"]) ? asTrimmedString(raw["error"]["message"]) : void 0;
27677
+ if (stopReason === "error" || isRecord2(raw["error"])) return { status: "failed", error: error62 };
27862
27678
  if (stopReason === "cancelled") return { status: "cancelled", error: void 0 };
27863
27679
  return { status: "idle", error: void 0 };
27864
27680
  }
@@ -27874,7 +27690,7 @@ function childLinkage(childId, record3) {
27874
27690
  function createSubagentSessionTracker(registry2) {
27875
27691
  const observe = (notification, ctx) => {
27876
27692
  const update = notification.update;
27877
- if (!isRecord3(update) || update["sessionUpdate"] !== "subagent_update") return [];
27693
+ if (!isRecord2(update) || update["sessionUpdate"] !== "subagent_update") return [];
27878
27694
  const childId = asTrimmedString(update["sessionId"]);
27879
27695
  if (childId === void 0 || ctx.ownSessionIds.has(childId)) return [];
27880
27696
  const outerId = notification.sessionId;
@@ -28327,8 +28143,8 @@ function readOpenToolCalls(toolCalls, turnId) {
28327
28143
 
28328
28144
  // ../../packages/ycodium-acp-executor/src/protocol-log.ts
28329
28145
  import * as NodeFS from "node:fs";
28330
- import * as NodeOS2 from "node:os";
28331
- import * as NodePath3 from "node:path";
28146
+ import * as NodeOS from "node:os";
28147
+ import * as NodePath2 from "node:path";
28332
28148
  var DEFAULT_MAX_BYTES = 8 * 1024 * 1024;
28333
28149
  var UNSAFE_FILE_CHARS = /[^A-Za-z0-9._-]+/gu;
28334
28150
  function safeFileName(value) {
@@ -28337,7 +28153,7 @@ function safeFileName(value) {
28337
28153
  function createAcpProtocolLogFile(input2) {
28338
28154
  const maxBytes = input2.maxBytes ?? DEFAULT_MAX_BYTES;
28339
28155
  NodeFS.mkdirSync(input2.directory, { recursive: true });
28340
- const filePath = NodePath3.join(
28156
+ const filePath = NodePath2.join(
28341
28157
  input2.directory,
28342
28158
  `${safeFileName(input2.provider)}-${safeFileName(input2.threadId)}-${Date.now().toString(36)}.ndjson`
28343
28159
  );
@@ -28393,7 +28209,7 @@ function createAcpProtocolLogFromEnv(input2) {
28393
28209
  const flag = process.env.YCODIUM_ACP_PROTOCOL_LOG;
28394
28210
  if (flag !== "1" && flag?.toLowerCase() !== "true") return void 0;
28395
28211
  const configured = process.env.YCODIUM_ACP_PROTOCOL_LOG_DIR?.trim();
28396
- const directory = configured && configured.length > 0 ? configured : NodePath3.join(NodeOS2.tmpdir(), "ycodium-acp-protocol");
28212
+ const directory = configured && configured.length > 0 ? configured : NodePath2.join(NodeOS.tmpdir(), "ycodium-acp-protocol");
28397
28213
  try {
28398
28214
  const sink = createAcpProtocolLogFile({
28399
28215
  directory,
@@ -28417,7 +28233,7 @@ function defaultNowIso() {
28417
28233
  return (/* @__PURE__ */ new Date()).toISOString();
28418
28234
  }
28419
28235
  function defaultRandomId() {
28420
- return NodeCrypto2.randomUUID();
28236
+ return NodeCrypto.randomUUID();
28421
28237
  }
28422
28238
  function createAcpExecutor(options) {
28423
28239
  const hooks = { ...defaultVendorHooks, ...options.hooks };
@@ -28835,13 +28651,13 @@ function acpNativeSessionProcessMatcher(program, args) {
28835
28651
 
28836
28652
  // ../../packages/ycodium-acp-executor/src/prompt-dispatch.ts
28837
28653
  var dispatchAcpPrompt = (executor, input2) => {
28838
- const { promise: dispatched, resolve: resolve5 } = Promise.withResolvers();
28654
+ const { promise: dispatched, resolve: resolve3 } = Promise.withResolvers();
28839
28655
  let written = false;
28840
28656
  const finished = executor.prompt({
28841
28657
  ...input2,
28842
28658
  onDispatched: (turnId) => {
28843
28659
  written = true;
28844
- resolve5(turnId);
28660
+ resolve3(turnId);
28845
28661
  }
28846
28662
  });
28847
28663
  return Promise.race([
@@ -28856,8 +28672,8 @@ var dispatchAcpPrompt = (executor, input2) => {
28856
28672
  };
28857
28673
 
28858
28674
  // ../../packages/ycodium-acp-executor/src/thread-operations.ts
28859
- var yieldTick = () => new Promise((resolve5) => {
28860
- setImmediate(resolve5);
28675
+ var yieldTick = () => new Promise((resolve3) => {
28676
+ setImmediate(resolve3);
28861
28677
  });
28862
28678
  var nowIso = () => (/* @__PURE__ */ new Date()).toISOString();
28863
28679
  function createAcpThreadOperations(options) {
@@ -28933,7 +28749,7 @@ function createAcpThreadOperations(options) {
28933
28749
  }
28934
28750
 
28935
28751
  // ../../packages/ycodium-executor-common/src/modelSelection.ts
28936
- function modelSelectionStringOption2(selection, optionId) {
28752
+ function modelSelectionStringOption(selection, optionId) {
28937
28753
  if (typeof selection !== "object" || selection === null || Array.isArray(selection)) {
28938
28754
  return void 0;
28939
28755
  }
@@ -28950,7 +28766,7 @@ function modelSelectionStringOption2(selection, optionId) {
28950
28766
  }
28951
28767
 
28952
28768
  // ../../packages/ycodium-executor-common/src/nodeStreams.ts
28953
- import * as NodeOS3 from "node:os";
28769
+ import * as NodeOS2 from "node:os";
28954
28770
  import * as NodeStream2 from "node:stream";
28955
28771
  var PEER_CLOSED_STDIN_CODES = /* @__PURE__ */ new Set([
28956
28772
  "EPIPE",
@@ -29018,7 +28834,7 @@ var API_KEY_HEADER_PATTERN = /\bx-api-key:\s*\S+/gi;
29018
28834
  var SECRET_TOKEN_PATTERN = /\b(?:sk-[A-Za-z0-9][A-Za-z0-9-]{7,}|ghp_[A-Za-z0-9]+|xox[a-zA-Z]-[A-Za-z0-9-]+)\b/g;
29019
28835
  function redactStderrExcerpt(text2, environment = process.env) {
29020
28836
  let result = text2.replaceAll("\0", "");
29021
- const homes = [environment["HOME"], environment["USERPROFILE"], NodeOS3.homedir()].filter(
28837
+ const homes = [environment["HOME"], environment["USERPROFILE"], NodeOS2.homedir()].filter(
29022
28838
  (value) => typeof value === "string" && value.length > 1
29023
28839
  );
29024
28840
  for (const home of new Set(homes)) {
@@ -29039,8 +28855,8 @@ function drainStderrTail(stderr) {
29039
28855
  let timer;
29040
28856
  await Promise.race([
29041
28857
  drained,
29042
- new Promise((resolve5) => {
29043
- timer = setTimeout(resolve5, STDERR_SETTLE_MS);
28858
+ new Promise((resolve3) => {
28859
+ timer = setTimeout(resolve3, STDERR_SETTLE_MS);
29044
28860
  })
29045
28861
  ]);
29046
28862
  clearTimeout(timer);
@@ -29054,11 +28870,11 @@ function nodeStreamsFromHandle(handle, errors = ownErrors) {
29054
28870
  for await (const chunk of handle.stdout) {
29055
28871
  if (!readable.writable) return;
29056
28872
  if (!readable.write(chunk)) {
29057
- await new Promise((resolve5) => {
28873
+ await new Promise((resolve3) => {
29058
28874
  const onDone = () => {
29059
28875
  readable.off("drain", onDone);
29060
28876
  readable.off("close", onDone);
29061
- resolve5();
28877
+ resolve3();
29062
28878
  };
29063
28879
  readable.once("drain", onDone);
29064
28880
  readable.once("close", onDone);
@@ -29115,8 +28931,8 @@ async function raceStartAbort(promise2, signal) {
29115
28931
  }
29116
28932
 
29117
28933
  // ../../packages/ycodium-acp-executor/src/instance-kit.ts
29118
- var yieldTick2 = () => new Promise((resolve5) => {
29119
- setImmediate(resolve5);
28934
+ var yieldTick2 = () => new Promise((resolve3) => {
28935
+ setImmediate(resolve3);
29120
28936
  });
29121
28937
  var nowIso2 = () => (/* @__PURE__ */ new Date()).toISOString();
29122
28938
  function createAcpThreadTable(log, beforeStopAll) {
@@ -29180,7 +28996,7 @@ function acpLaunchFromHandle(input2) {
29180
28996
  const { readable, writable, stderrTail } = nodeStreamsFromHandle(input2.handle);
29181
28997
  const resume = acpResumeFrom(input2.start, input2.resumeSchemaVersion);
29182
28998
  const requestedModelId = input2.modelIdFromSelection(input2.modelSelection);
29183
- const requestedEffort = modelSelectionStringOption2(input2.modelSelection, input2.effortOptionId);
28999
+ const requestedEffort = modelSelectionStringOption(input2.modelSelection, input2.effortOptionId);
29184
29000
  return { readable, writable, stderrTail, resume, requestedModelId, requestedEffort };
29185
29001
  }
29186
29002
  async function stopExistingAcpThread(table, threadId, isDisposed, signal) {
@@ -29334,63 +29150,13 @@ function parseCliVersion(output2) {
29334
29150
  }
29335
29151
  var MAX_VERSION_OUTPUT_BYTES = 64 * 1024;
29336
29152
 
29337
- // ../../packages/ycodium-instance-config/src/launchArgs.ts
29338
- function tokenizeShellWords(value) {
29339
- const input2 = value.trim();
29340
- if (!input2) return [];
29341
- const tokens = [];
29342
- let current = "";
29343
- let quote;
29344
- let quoted = false;
29345
- for (let index = 0; index < input2.length; index++) {
29346
- const char = input2[index];
29347
- if (char === void 0) continue;
29348
- if (quote) {
29349
- if (char === quote) {
29350
- quote = void 0;
29351
- quoted = true;
29352
- } else if (char === "\\" && quote === '"') {
29353
- const next = input2[index + 1];
29354
- if (next !== void 0 && ['"', "\\", "$", "`"].includes(next)) {
29355
- current += next;
29356
- index++;
29357
- } else {
29358
- current += char;
29359
- }
29360
- } else {
29361
- current += char;
29362
- }
29363
- continue;
29364
- }
29365
- if (char === "'" || char === '"') {
29366
- quote = char;
29367
- quoted = true;
29368
- } else if (/\s/.test(char)) {
29369
- if (current || quoted) {
29370
- tokens.push(current);
29371
- current = "";
29372
- quoted = false;
29373
- }
29374
- } else if (char === "\\") {
29375
- const next = input2[index + 1];
29376
- if (next !== void 0 && /\s/.test(next)) {
29377
- current += next;
29378
- index++;
29379
- } else {
29380
- current += char;
29381
- }
29382
- } else {
29383
- current += char;
29384
- }
29385
- }
29386
- if (current || quoted) tokens.push(current);
29387
- return tokens;
29388
- }
29389
-
29390
29153
  // src/kimiInstance.ts
29391
29154
  import { createCliDeviceSignIn } from "@ycodium-ai/plugin-api/runtime-maintenance";
29392
29155
 
29393
29156
  // src/config.ts
29157
+ import {
29158
+ readLaunchInstanceRecipe
29159
+ } from "@ycodium-ai/plugin-api/instance-config";
29394
29160
  function parseKimiInstanceConfig(config2) {
29395
29161
  return {
29396
29162
  ...readLaunchInstanceRecipe(config2, KIMI_CARD.launchArgs),
@@ -29403,21 +29169,21 @@ import * as NodeFS3 from "node:fs";
29403
29169
 
29404
29170
  // src/kimi.ts
29405
29171
  import * as NodeFS2 from "node:fs";
29406
- import * as NodePath4 from "node:path";
29172
+ import * as NodePath3 from "node:path";
29407
29173
  var KIMI_USER_INPUT_TITLES = /* @__PURE__ */ new Set(["AskUserQuestion", "ExitPlanMode"]);
29408
29174
  var KIMI_PLAN_ACTIONS = {
29409
29175
  plan_approve: "approve",
29410
29176
  plan_revise: "revise",
29411
29177
  plan_reject_and_exit: "stop"
29412
29178
  };
29413
- var isRecord8 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
29179
+ var isRecord7 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
29414
29180
  function questionTextFromContent(content) {
29415
29181
  if (!Array.isArray(content)) return "";
29416
29182
  const parts = [];
29417
29183
  for (const entry of content) {
29418
- if (!isRecord8(entry) || entry["type"] !== "content") continue;
29184
+ if (!isRecord7(entry) || entry["type"] !== "content") continue;
29419
29185
  const inner = entry["content"];
29420
- if (!isRecord8(inner) || inner["type"] !== "text") continue;
29186
+ if (!isRecord7(inner) || inner["type"] !== "text") continue;
29421
29187
  const text2 = inner["text"];
29422
29188
  if (typeof text2 === "string") parts.push(text2);
29423
29189
  }
@@ -29469,7 +29235,7 @@ function parseKimiContextWindow(contents) {
29469
29235
  } catch {
29470
29236
  continue;
29471
29237
  }
29472
- if (!isRecord8(record3)) continue;
29238
+ if (!isRecord7(record3)) continue;
29473
29239
  const type = record3["type"];
29474
29240
  if (type === "token_counting.turn_recorded" || type === "token_counting.measured") {
29475
29241
  usedTokens = positiveInt(record3["tokens"]) ?? usedTokens;
@@ -29506,7 +29272,7 @@ function readTail(filePath) {
29506
29272
  function findKimiSessionWireLog(input2) {
29507
29273
  if (!input2.acpSessionId || /[\\/:]/u.test(input2.acpSessionId) || [".", ".."].includes(input2.acpSessionId))
29508
29274
  return void 0;
29509
- const sessionsRoot = NodePath4.join(input2.homePath, SESSIONS_DIR);
29275
+ const sessionsRoot = NodePath3.join(input2.homePath, SESSIONS_DIR);
29510
29276
  let workspaces;
29511
29277
  try {
29512
29278
  workspaces = NodeFS2.readdirSync(sessionsRoot);
@@ -29514,7 +29280,7 @@ function findKimiSessionWireLog(input2) {
29514
29280
  return void 0;
29515
29281
  }
29516
29282
  for (const workspace of workspaces) {
29517
- const candidate = NodePath4.join(
29283
+ const candidate = NodePath3.join(
29518
29284
  sessionsRoot,
29519
29285
  workspace,
29520
29286
  input2.acpSessionId,
@@ -29607,13 +29373,13 @@ function observeKimiPromptFailure(homePath, acpSessionId) {
29607
29373
  if (first !== "pending") return first;
29608
29374
  const path = original ?? find();
29609
29375
  if (!path) return void 0;
29610
- return new Promise((resolve5) => {
29376
+ return new Promise((resolve3) => {
29611
29377
  let watcher;
29612
29378
  const finish = (failure2) => {
29613
29379
  clearTimeout(deadline);
29614
29380
  signal.removeEventListener("abort", abort);
29615
29381
  watcher?.close();
29616
- resolve5(failure2);
29382
+ resolve3(failure2);
29617
29383
  };
29618
29384
  const abort = () => finish();
29619
29385
  const check2 = () => {
@@ -29635,92 +29401,28 @@ function observeKimiPromptFailure(homePath, acpSessionId) {
29635
29401
 
29636
29402
  // src/kimiQuota.ts
29637
29403
  import * as NodeFS5 from "node:fs";
29638
- import * as NodeOS5 from "node:os";
29639
- import * as NodePath6 from "node:path";
29640
-
29641
- // ../../packages/ycodium-instance-config/src/tomlScalar.ts
29642
- function readTomlScalar(raw) {
29643
- const quoted = /^(["'])(.*?)\1/.exec(raw.trim());
29644
- if (quoted?.[2] !== void 0) return quoted[2];
29645
- const [beforeComment = ""] = raw.split("#");
29646
- return beforeComment.trim();
29647
- }
29648
-
29649
- // src/kimiQuota.ts
29404
+ import * as NodeOS4 from "node:os";
29405
+ import * as NodePath5 from "node:path";
29406
+ import { readTomlScalar } from "@ycodium-ai/plugin-api/instance-config";
29650
29407
  import "@ycodium-ai/plugin-api/usage";
29651
-
29652
- // ../../packages/ycodium-credential-account/src/quotaRequest.ts
29653
- import { parseRetryAfterMs } from "@ycodium-ai/plugin-api/usage";
29654
-
29655
- // ../../packages/ycodium-credential-account/src/credentialAccount.ts
29656
- var isRecord9 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
29657
-
29658
- // ../../packages/ycodium-credential-account/src/quotaRequest.ts
29659
- async function requestQuotaJsonValue(input2) {
29660
- let response;
29661
- try {
29662
- response = await input2.fetch(input2.url, {
29663
- headers: input2.headers,
29664
- ...input2.method === void 0 ? {} : { method: input2.method },
29665
- ...input2.body === void 0 ? {} : { body: input2.body },
29666
- ...input2.redirect === void 0 ? {} : { redirect: input2.redirect },
29667
- signal: AbortSignal.any([
29668
- ...input2.signal === void 0 ? [] : [input2.signal],
29669
- AbortSignal.timeout(input2.timeoutMs)
29670
- ])
29671
- });
29672
- } catch (cause) {
29673
- if (input2.propagateCallerAbort && input2.signal?.aborted) throw cause;
29674
- return { status: "unavailable", reason: "unreachable" };
29675
- }
29676
- if (!response.ok) {
29677
- void response.body?.cancel().catch(() => void 0);
29678
- if (response.status === 429) {
29679
- const retryAfterMs = parseRetryAfterMs(response.headers.get("retry-after"), input2.now());
29680
- return {
29681
- status: "unavailable",
29682
- reason: "rateLimited",
29683
- ...retryAfterMs === null ? {} : { retryAfterMs }
29684
- };
29685
- }
29686
- const reason = input2.statusReasons?.[response.status] ?? (response.status === 401 || response.status === 403 ? "authRejected" : "unreachable");
29687
- return { status: "unavailable", reason };
29688
- }
29689
- try {
29690
- return { body: JSON.parse(await response.text()) };
29691
- } catch (cause) {
29692
- if (input2.propagateCallerAbort && input2.signal?.aborted) throw cause;
29693
- return { status: "unavailable", reason: "unreachable" };
29694
- }
29695
- }
29696
- async function requestQuotaJson(input2) {
29697
- const answer = await requestQuotaJsonValue(input2);
29698
- if (!("body" in answer)) return answer;
29699
- return isRecord9(answer.body) ? { body: answer.body } : { status: "unavailable", reason: "unreachable" };
29700
- }
29701
-
29702
- // ../../packages/ycodium-credential-account/src/quotaJson.ts
29703
- var asObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
29704
- var asString3 = (value) => typeof value === "string" && value.length > 0 ? value : null;
29705
- var asNumber = (value) => typeof value === "number" && Number.isFinite(value) ? value : null;
29706
- var parseJson = (raw) => {
29707
- try {
29708
- return JSON.parse(raw);
29709
- } catch {
29710
- return null;
29711
- }
29712
- };
29713
- var clampPercent = (value) => Math.min(100, Math.max(0, value));
29408
+ import {
29409
+ requestQuotaJson,
29410
+ clampPercent,
29411
+ asNumber,
29412
+ asObject,
29413
+ asString as asString3,
29414
+ parseJson
29415
+ } from "@ycodium-ai/plugin-api/credential-account";
29714
29416
 
29715
29417
  // src/kimiAccount.ts
29716
29418
  import * as NodeFS4 from "node:fs";
29717
- import * as NodeOS4 from "node:os";
29718
- import * as NodePath5 from "node:path";
29419
+ import * as NodeOS3 from "node:os";
29420
+ import * as NodePath4 from "node:path";
29719
29421
  function kimiAccountHome(resolvedHomePath) {
29720
- return resolvedHomePath.trim().length > 0 ? resolvedHomePath : NodePath5.join(NodeOS4.homedir(), ".kimi-code");
29422
+ return resolvedHomePath.trim().length > 0 ? resolvedHomePath : NodePath4.join(NodeOS3.homedir(), ".kimi-code");
29721
29423
  }
29722
29424
  function kimiCredentialsPath(resolvedHomePath) {
29723
- return NodePath5.join(kimiAccountHome(resolvedHomePath), "credentials", "kimi-code.json");
29425
+ return NodePath4.join(kimiAccountHome(resolvedHomePath), "credentials", "kimi-code.json");
29724
29426
  }
29725
29427
  var nonEmptyString = (value) => typeof value === "string" && value.length > 0;
29726
29428
  function readKimiAuthState(resolvedHomePath) {
@@ -29874,12 +29576,12 @@ var kimiEffectiveHome = (resolvedHomePath, processEnvHome) => {
29874
29576
  var createKimiUsage = (input2) => {
29875
29577
  const now = input2.now ?? Date.now;
29876
29578
  const processEnv = input2.processEnv ?? process.env;
29877
- const home = input2.homePath.trim().length > 0 ? input2.homePath : NodePath6.join(NodeOS5.homedir(), ".kimi-code");
29579
+ const home = input2.homePath.trim().length > 0 ? input2.homePath : NodePath5.join(NodeOS4.homedir(), ".kimi-code");
29878
29580
  const credentialsPath = kimiCredentialsPath(input2.homePath);
29879
29581
  const readQuota = async (request) => {
29880
29582
  let configToml = null;
29881
29583
  try {
29882
- configToml = NodeFS5.readFileSync(NodePath6.join(home, "config.toml"), "utf8");
29584
+ configToml = NodeFS5.readFileSync(NodePath5.join(home, "config.toml"), "utf8");
29883
29585
  } catch (error62) {
29884
29586
  if (error62.code !== "ENOENT") {
29885
29587
  return { status: "unavailable", reason: "unreachable" };
@@ -29921,11 +29623,11 @@ var createKimiUsage = (input2) => {
29921
29623
 
29922
29624
  // src/kimiTokens.ts
29923
29625
  import * as NodeFS6 from "node:fs";
29924
- import * as NodeOS6 from "node:os";
29925
- import * as NodePath7 from "node:path";
29626
+ import * as NodeOS5 from "node:os";
29627
+ import * as NodePath6 from "node:path";
29926
29628
  var MTIME_SLACK_MS = 36 * 60 * 60 * 1e3;
29927
29629
  var GUARD_LENGTH = 64;
29928
- var isRecord10 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
29630
+ var isRecord8 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
29929
29631
  var count = (value) => typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.trunc(value) : 0;
29930
29632
  var parseKimiUsageLine = (line) => {
29931
29633
  if (!line.includes('"usage.record"')) return void 0;
@@ -29935,11 +29637,11 @@ var parseKimiUsageLine = (line) => {
29935
29637
  } catch {
29936
29638
  return "malformed";
29937
29639
  }
29938
- if (!isRecord10(parsed) || parsed["type"] !== "usage.record") return void 0;
29640
+ if (!isRecord8(parsed) || parsed["type"] !== "usage.record") return void 0;
29939
29641
  const usage = parsed["usage"];
29940
29642
  const model = typeof parsed["model"] === "string" ? parsed["model"].trim() : "";
29941
29643
  const timeMs = parsed["time"];
29942
- if (!isRecord10(usage) || model.length === 0 || typeof timeMs !== "number" || !Number.isFinite(timeMs)) {
29644
+ if (!isRecord8(usage) || model.length === 0 || typeof timeMs !== "number" || !Number.isFinite(timeMs)) {
29943
29645
  return "malformed";
29944
29646
  }
29945
29647
  const totals = {
@@ -29967,10 +29669,10 @@ var readDirs = (dir) => {
29967
29669
  var listWireLogs = (sessionsRoot) => {
29968
29670
  const found = [];
29969
29671
  for (const workspace of readDirs(sessionsRoot)) {
29970
- for (const session of readDirs(NodePath7.join(sessionsRoot, workspace))) {
29971
- const agentsDir = NodePath7.join(sessionsRoot, workspace, session, "agents");
29672
+ for (const session of readDirs(NodePath6.join(sessionsRoot, workspace))) {
29673
+ const agentsDir = NodePath6.join(sessionsRoot, workspace, session, "agents");
29972
29674
  for (const agent of readDirs(agentsDir)) {
29973
- found.push({ file: NodePath7.join(agentsDir, agent, "wire.jsonl"), sessionId: session });
29675
+ found.push({ file: NodePath6.join(agentsDir, agent, "wire.jsonl"), sessionId: session });
29974
29676
  }
29975
29677
  }
29976
29678
  }
@@ -29994,8 +29696,8 @@ var readRange = (file2, from, to) => {
29994
29696
  };
29995
29697
  var guardOf = (file2, size) => readRange(file2, 0, Math.min(size, GUARD_LENGTH)).toString("base64");
29996
29698
  var createKimiTokenReader = (input2) => {
29997
- const home = input2.homePath.trim().length > 0 ? NodePath7.resolve(input2.homePath) : NodePath7.join(NodeOS6.homedir(), ".kimi-code");
29998
- const sessionsRoot = NodePath7.join(home, "sessions");
29699
+ const home = input2.homePath.trim().length > 0 ? NodePath6.resolve(input2.homePath) : NodePath6.join(NodeOS5.homedir(), ".kimi-code");
29700
+ const sessionsRoot = NodePath6.join(home, "sessions");
29999
29701
  const memos = /* @__PURE__ */ new Map();
30000
29702
  const refresh = (file2, size) => {
30001
29703
  const guard = guardOf(file2, size);
@@ -30086,44 +29788,16 @@ var createKimiTokenReader = (input2) => {
30086
29788
  return { readTokenUsage };
30087
29789
  };
30088
29790
 
30089
- // ../../packages/ycodium-instance-config/src/probeProcess.ts
30090
- import {
30091
- describeExecutorSpawnFailure,
30092
- ExecutorSpawnAbortedError,
30093
- ExecutorSpawnRefusedError
30094
- } from "@ycodium-ai/plugin-api/executor";
30095
- import {
30096
- isOperationCleanupError,
30097
- runProcessOperation
30098
- } from "@ycodium-ai/plugin-api/process-operation";
30099
- async function readCliVersionCommand(host, input2) {
30100
- try {
30101
- const run = await runProcessOperation(host, {
30102
- program: input2.program,
30103
- args: ["--version"],
30104
- owner: { bindingId: host.bindingId },
30105
- ...Object.keys(input2.env).length > 0 ? { env: input2.env } : {},
30106
- signal: input2.signal,
30107
- timeoutMs: input2.timeoutMs,
30108
- maxOutputBytes: 64 * 1024
30109
- });
30110
- if (run.exitCode !== 0 && !input2.acceptNonzeroExit) return null;
30111
- return input2.parse(run.stdout) ?? input2.parse(run.stderr);
30112
- } catch (error62) {
30113
- if (isOperationCleanupError(error62) || input2.signal?.aborted) throw error62;
30114
- return null;
30115
- }
30116
- }
30117
-
30118
29791
  // src/kimiModels.ts
29792
+ import { readCliVersionCommand } from "@ycodium-ai/plugin-api/instance-config";
30119
29793
  import {
30120
- runProcessOperation as runProcessOperation2,
30121
- isOperationCleanupError as isOperationCleanupError2
29794
+ runProcessOperation,
29795
+ isOperationCleanupError
30122
29796
  } from "@ycodium-ai/plugin-api/process-operation";
30123
29797
  import {
30124
- describeExecutorSpawnFailure as describeExecutorSpawnFailure2,
30125
- ExecutorSpawnAbortedError as ExecutorSpawnAbortedError2,
30126
- ExecutorSpawnRefusedError as ExecutorSpawnRefusedError2,
29798
+ describeExecutorSpawnFailure,
29799
+ ExecutorSpawnAbortedError,
29800
+ ExecutorSpawnRefusedError,
30127
29801
  REASONING_OPTION_LABEL,
30128
29802
  reasoningEffortShortLabel
30129
29803
  } from "@ycodium-ai/plugin-api/executor";
@@ -30135,7 +29809,7 @@ var ACP_EFFORT_OPTION_ID = "reasoning";
30135
29809
  var PROBE_TIMEOUT_MS = 15e3;
30136
29810
  var MAX_OUTPUT_BYTES = 1024 * 1024;
30137
29811
  var KIMI_MODEL_LIST_ARGS = ["provider", "list", "--json"];
30138
- function isRecord11(value) {
29812
+ function isRecord9(value) {
30139
29813
  return typeof value === "object" && value !== null && !Array.isArray(value);
30140
29814
  }
30141
29815
  function asString4(value) {
@@ -30173,13 +29847,13 @@ function kimiProbeModels(stdout) {
30173
29847
  } catch {
30174
29848
  return void 0;
30175
29849
  }
30176
- if (!isRecord11(parsed)) return void 0;
29850
+ if (!isRecord9(parsed)) return void 0;
30177
29851
  const models = parsed["models"];
30178
- if (!isRecord11(models)) return void 0;
29852
+ if (!isRecord9(models)) return void 0;
30179
29853
  const out = [];
30180
29854
  for (const [slug, entry] of Object.entries(models)) {
30181
29855
  const trimmed2 = slug.trim();
30182
- if (trimmed2.length === 0 || !isRecord11(entry)) continue;
29856
+ if (trimmed2.length === 0 || !isRecord9(entry)) continue;
30183
29857
  const name = asString4(entry["displayName"]);
30184
29858
  const contextWindow = positiveInt2(entry["maxContextSize"]);
30185
29859
  const effort = kimiEffortDescriptor(entry);
@@ -30196,7 +29870,7 @@ async function probeKimiModels(input2) {
30196
29870
  const { recipe, host, env } = input2;
30197
29871
  let spawned = false;
30198
29872
  try {
30199
- const run = await runProcessOperation2(
29873
+ const run = await runProcessOperation(
30200
29874
  {
30201
29875
  ...host,
30202
29876
  process: {
@@ -30231,9 +29905,9 @@ async function probeKimiModels(input2) {
30231
29905
  models: run.stdout === void 0 ? void 0 : kimiProbeModels(run.stdout)
30232
29906
  };
30233
29907
  } catch (error62) {
30234
- if (error62 instanceof ExecutorSpawnRefusedError2 || error62 instanceof ExecutorSpawnAbortedError2 || isOperationCleanupError2(error62) || input2.signal?.aborted)
29908
+ if (error62 instanceof ExecutorSpawnRefusedError || error62 instanceof ExecutorSpawnAbortedError || isOperationCleanupError(error62) || input2.signal?.aborted)
30235
29909
  throw error62;
30236
- if (!spawned) return { kind: "not-started", ...describeExecutorSpawnFailure2(error62) };
29910
+ if (!spawned) return { kind: "not-started", ...describeExecutorSpawnFailure(error62) };
30237
29911
  return { kind: "failed", detail: acpProbeFailureDetail(error62) };
30238
29912
  }
30239
29913
  }
@@ -30348,7 +30022,7 @@ var FOREGROUND_ENDED_DESCRIPTION = "Turn ended before Kimi reported this agent's
30348
30022
  var BACKGROUND_ENDED_DESCRIPTION = "Running in the background. Kimi does not report when it finishes.";
30349
30023
  var SINGLE_TITLE = /^Launching (background )?(\S+) agent: ([\s\S]*)$/u;
30350
30024
  var SWARM_TITLE_PREFIX = "Launching agent swarm: ";
30351
- var isRecord12 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
30025
+ var isRecord10 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
30352
30026
  var trimmed = (value) => typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
30353
30027
  function classify(input2) {
30354
30028
  if (input2.kind !== void 0 && input2.kind !== "other") return void 0;
@@ -30362,7 +30036,7 @@ function requestedModel(value) {
30362
30036
  return model === "primary" ? void 0 : model;
30363
30037
  }
30364
30038
  function describe3(kind, input2, previous) {
30365
- const raw = isRecord12(input2.rawInput) ? input2.rawInput : {};
30039
+ const raw = isRecord10(input2.rawInput) ? input2.rawInput : {};
30366
30040
  if (kind === "swarm") {
30367
30041
  const fromTitle = input2.title?.startsWith(SWARM_TITLE_PREFIX) ? trimmed(input2.title.slice(SWARM_TITLE_PREFIX.length)) : void 0;
30368
30042
  return {
@@ -30463,7 +30137,7 @@ var kimiToolSubagents = {
30463
30137
  announce: "started",
30464
30138
  resolve: (call, kind) => resolveOutcome(call, asKind(kind)),
30465
30139
  resumes: (call, kind) => {
30466
- if (asKind(kind) !== "subagent" || !isRecord12(call.rawInput)) return void 0;
30140
+ if (asKind(kind) !== "subagent" || !isRecord10(call.rawInput)) return void 0;
30467
30141
  return trimmed(call.rawInput["resume"]);
30468
30142
  },
30469
30143
  endNote: ({ background }) => background ? { description: BACKGROUND_ENDED_DESCRIPTION, timelineBypass: true } : { description: FOREGROUND_ENDED_DESCRIPTION }
@@ -30495,37 +30169,18 @@ var kimiPermissionStatement = ({
30495
30169
  };
30496
30170
 
30497
30171
  // src/nativeSessions.ts
30498
- import * as NodeFS8 from "node:fs";
30172
+ import * as NodeFS7 from "node:fs";
30499
30173
  import * as NodeFSP from "node:fs/promises";
30500
- import * as NodePath9 from "node:path";
30174
+ import * as NodePath7 from "node:path";
30501
30175
  import * as NodeReadline from "node:readline";
30502
-
30503
- // ../../packages/ycodium-jsonl-stream/src/sessionDirectory.ts
30504
- import * as NodeFS7 from "node:fs";
30505
- import * as NodePath8 from "node:path";
30506
- function readableStoragePath(home) {
30507
- try {
30508
- return NodeFS7.realpathSync.native(home);
30509
- } catch {
30510
- return home;
30511
- }
30512
- }
30513
- function isAbsoluteDirectory(path) {
30514
- if (!NodePath8.isAbsolute(path)) return false;
30515
- if (NodePath8.sep !== "\\") return true;
30516
- const { root } = NodePath8.parse(path);
30517
- return root.length > 1;
30518
- }
30519
- var directoryKey = (directory) => {
30520
- const resolved = NodePath8.resolve(directory);
30521
- return NodePath8.sep === "\\" ? resolved.toLowerCase() : resolved;
30522
- };
30523
- function matchesSessionDirectory(rootKey, cwd, mode) {
30524
- const relative2 = NodePath8.relative(rootKey, directoryKey(cwd));
30525
- return relative2 === "" || mode === "scan" && relative2 !== ".." && !relative2.startsWith(`..${NodePath8.sep}`) && !NodePath8.isAbsolute(relative2);
30526
- }
30527
-
30528
- // src/nativeSessions.ts
30176
+ import {
30177
+ directoryKey,
30178
+ isAbsoluteDirectory,
30179
+ matchesSessionDirectory,
30180
+ readableStoragePath,
30181
+ inputPayload as inputPayload2,
30182
+ outputPayload as outputPayload2
30183
+ } from "@ycodium-ai/plugin-api/session-history";
30529
30184
  var sessionIdPattern = /^[a-zA-Z0-9_-]+$/u;
30530
30185
  function record2(value) {
30531
30186
  return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
@@ -30553,16 +30208,16 @@ async function findSessions(home, cwd, signal, nativeSessionId) {
30553
30208
  signal?.throwIfAborted();
30554
30209
  const expectedCwd = directoryKey(cwd);
30555
30210
  const result = [];
30556
- const root = NodePath9.join(home, "sessions");
30211
+ const root = NodePath7.join(home, "sessions");
30557
30212
  for (const workspace of await directories(root)) {
30558
30213
  if (workspace.startsWith(".")) continue;
30559
- const workspacePath = NodePath9.join(root, workspace);
30214
+ const workspacePath = NodePath7.join(root, workspace);
30560
30215
  for (const id of await directories(workspacePath)) {
30561
30216
  signal?.throwIfAborted();
30562
30217
  if (!sessionIdPattern.test(id) || nativeSessionId !== void 0 && nativeSessionId !== id)
30563
30218
  continue;
30564
- const sessionPath = NodePath9.join(workspacePath, id);
30565
- const statePath = NodePath9.join(sessionPath, "state.json");
30219
+ const sessionPath = NodePath7.join(workspacePath, id);
30220
+ const statePath = NodePath7.join(sessionPath, "state.json");
30566
30221
  try {
30567
30222
  if (!(await NodeFSP.lstat(statePath)).isFile()) continue;
30568
30223
  const state = parseRecord(await NodeFSP.readFile(statePath, { encoding: "utf8", signal }));
@@ -30574,8 +30229,8 @@ async function findSessions(home, cwd, signal, nativeSessionId) {
30574
30229
  nativeSessionId === void 0 ? "scan" : "read"
30575
30230
  ))
30576
30231
  continue;
30577
- const wire = NodePath9.join(sessionPath, "agents", "main", "wire.jsonl");
30578
- if (!(await NodeFSP.lstat(NodePath9.join(sessionPath, "agents"))).isDirectory() || !(await NodeFSP.lstat(NodePath9.dirname(wire))).isDirectory() || !(await NodeFSP.lstat(wire)).isFile())
30232
+ const wire = NodePath7.join(sessionPath, "agents", "main", "wire.jsonl");
30233
+ if (!(await NodeFSP.lstat(NodePath7.join(sessionPath, "agents"))).isDirectory() || !(await NodeFSP.lstat(NodePath7.dirname(wire))).isDirectory() || !(await NodeFSP.lstat(wire)).isFile())
30579
30234
  continue;
30580
30235
  result.push({
30581
30236
  id,
@@ -30594,7 +30249,7 @@ async function findSessions(home, cwd, signal, nativeSessionId) {
30594
30249
  return result;
30595
30250
  }
30596
30251
  async function readTranscript(session, signal, summaryOnly = false) {
30597
- const stream = NodeFS8.createReadStream(session.wire, { signal });
30252
+ const stream = NodeFS7.createReadStream(session.wire, { signal });
30598
30253
  const lines = NodeReadline.createInterface({ input: stream, crlfDelay: Infinity });
30599
30254
  const messages = [];
30600
30255
  const activities = [];
@@ -30668,7 +30323,7 @@ async function readTranscript(session, signal, summaryOnly = false) {
30668
30323
  toolName: name,
30669
30324
  itemType: record2(event2.display)?.kind === "command" ? "command_execution" : "dynamic_tool_call",
30670
30325
  startedAt: createdAt,
30671
- ...inputPayload(input2)
30326
+ ...inputPayload2(input2)
30672
30327
  }
30673
30328
  };
30674
30329
  activities.push(activity);
@@ -30689,7 +30344,7 @@ async function readTranscript(session, signal, summaryOnly = false) {
30689
30344
  payload: {
30690
30345
  ...start.payload,
30691
30346
  status,
30692
- ...outputPayload(output2)
30347
+ ...outputPayload2(output2)
30693
30348
  }
30694
30349
  });
30695
30350
  }
@@ -31065,7 +30720,7 @@ var index_default = definePlugin({
31065
30720
  registerEffectiveHomeCommand(
31066
30721
  ctx,
31067
30722
  KIMI_CARD.homeEnvVar,
31068
- (value) => value === void 0 ? NodePath10.join(NodeOS7.homedir(), ".kimi-code") : NodePath10.resolve(expandHomePath(value)),
30723
+ (value) => value === void 0 ? NodePath8.join(NodeOS6.homedir(), ".kimi-code") : NodePath8.resolve(expandHomePath2(value)),
31069
30724
  profileDataDir
31070
30725
  );
31071
30726
  ctx.log.info("Kimi Code executor ready");