@ycodium-ai/agent-kimi 0.2.5448 → 0.2.5503
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/index.js +586 -259
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -8,11 +8,11 @@ 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 =
|
|
11
|
+
var PLUGIN_API_VERSION = 173;
|
|
12
12
|
|
|
13
13
|
// src/index.ts
|
|
14
14
|
import * as NodeOS7 from "node:os";
|
|
15
|
-
import * as
|
|
15
|
+
import * as NodePath9 from "node:path";
|
|
16
16
|
import {
|
|
17
17
|
EXECUTOR_EFFECTIVE_PAYLOAD_SCHEMA,
|
|
18
18
|
executorHomeEffectiveValue,
|
|
@@ -255,8 +255,8 @@ var UnboundedEventStream = class {
|
|
|
255
255
|
iterators.subscribers.delete(subscriber);
|
|
256
256
|
return { value: void 0, done: true };
|
|
257
257
|
}
|
|
258
|
-
await new Promise((
|
|
259
|
-
subscriber.wake =
|
|
258
|
+
await new Promise((resolve5) => {
|
|
259
|
+
subscriber.wake = resolve5;
|
|
260
260
|
});
|
|
261
261
|
}
|
|
262
262
|
},
|
|
@@ -356,20 +356,20 @@ function findAcpEffortConfig(configOptions) {
|
|
|
356
356
|
|
|
357
357
|
// ../../packages/ycodium-executor-common/src/stderrTail.ts
|
|
358
358
|
var REDACTION_MARKERS = ["[redacted]", "[pairing-url]"];
|
|
359
|
-
function lastStderrTail(
|
|
360
|
-
if (
|
|
361
|
-
let start =
|
|
362
|
-
if (
|
|
363
|
-
const lineEnd =
|
|
364
|
-
if (lineEnd !== -1 && lineEnd <
|
|
365
|
-
const code =
|
|
359
|
+
function lastStderrTail(text2, maxChars) {
|
|
360
|
+
if (text2.length <= maxChars) return text2;
|
|
361
|
+
let start = text2.length - maxChars;
|
|
362
|
+
if (text2[start - 1] !== "\n") {
|
|
363
|
+
const lineEnd = text2.indexOf("\n", start);
|
|
364
|
+
if (lineEnd !== -1 && lineEnd < text2.length - 1) return text2.slice(lineEnd + 1);
|
|
365
|
+
const code = text2.charCodeAt(start);
|
|
366
366
|
if (code >= 56320 && code <= 57343) start += 1;
|
|
367
367
|
for (const marker of REDACTION_MARKERS) {
|
|
368
|
-
const at =
|
|
368
|
+
const at = text2.lastIndexOf(marker, start);
|
|
369
369
|
if (at !== -1 && at < start && start < at + marker.length) start = at + marker.length;
|
|
370
370
|
}
|
|
371
371
|
}
|
|
372
|
-
return
|
|
372
|
+
return text2.slice(start);
|
|
373
373
|
}
|
|
374
374
|
|
|
375
375
|
// ../../packages/ycodium-acp-executor/src/errors.ts
|
|
@@ -482,8 +482,8 @@ var settledExitCode = async (exited) => {
|
|
|
482
482
|
try {
|
|
483
483
|
return await Promise.race([
|
|
484
484
|
exited.catch(() => void 0),
|
|
485
|
-
new Promise((
|
|
486
|
-
timer = setTimeout(() =>
|
|
485
|
+
new Promise((resolve5) => {
|
|
486
|
+
timer = setTimeout(() => resolve5(void 0), AGENT_EXIT_SETTLE_MS);
|
|
487
487
|
})
|
|
488
488
|
]);
|
|
489
489
|
} finally {
|
|
@@ -809,29 +809,29 @@ function extractToolCallCommand(rawInput, title) {
|
|
|
809
809
|
}
|
|
810
810
|
var TOOL_CALL_CONTENT_MAX_CHARS = 8e3;
|
|
811
811
|
var TOOL_CALL_CONTENT_TRUNCATION_MARKER = "[Earlier output truncated]\n\n";
|
|
812
|
-
function boundTailText(
|
|
813
|
-
if (
|
|
814
|
-
return
|
|
812
|
+
function boundTailText(text2, limit = TOOL_CALL_CONTENT_MAX_CHARS) {
|
|
813
|
+
if (text2.length <= limit) {
|
|
814
|
+
return text2;
|
|
815
815
|
}
|
|
816
|
-
const tail =
|
|
816
|
+
const tail = text2.slice(text2.length - limit);
|
|
817
817
|
return `${TOOL_CALL_CONTENT_TRUNCATION_MARKER}${tail}`;
|
|
818
818
|
}
|
|
819
|
-
var boundToolCallOutputText = (
|
|
819
|
+
var boundToolCallOutputText = (text2) => boundTailText(text2);
|
|
820
820
|
var RAW_OUTPUT_TEXT_FIELDS = ["content", "stdout", "stderr", "output"];
|
|
821
821
|
function boundToolCallRawOutput(rawOutput) {
|
|
822
822
|
if (!isRecord2(rawOutput)) {
|
|
823
823
|
return rawOutput;
|
|
824
824
|
}
|
|
825
825
|
let changed = false;
|
|
826
|
-
const
|
|
826
|
+
const bounded2 = { ...rawOutput };
|
|
827
827
|
for (const field of RAW_OUTPUT_TEXT_FIELDS) {
|
|
828
828
|
const value = rawOutput[field];
|
|
829
829
|
if (typeof value === "string" && value.length > TOOL_CALL_CONTENT_MAX_CHARS) {
|
|
830
|
-
|
|
830
|
+
bounded2[field] = boundToolCallOutputText(value);
|
|
831
831
|
changed = true;
|
|
832
832
|
}
|
|
833
833
|
}
|
|
834
|
-
return changed ?
|
|
834
|
+
return changed ? bounded2 : rawOutput;
|
|
835
835
|
}
|
|
836
836
|
function toolCallContentText(entry) {
|
|
837
837
|
if (entry.type !== "content" || entry.content?.type !== "text") {
|
|
@@ -846,9 +846,9 @@ function extractTextContentFromToolCallContent(content) {
|
|
|
846
846
|
const typed = content;
|
|
847
847
|
const chunks = [];
|
|
848
848
|
for (const entry of typed) {
|
|
849
|
-
const
|
|
850
|
-
if (
|
|
851
|
-
chunks.push(
|
|
849
|
+
const text2 = toolCallContentText(entry)?.trim();
|
|
850
|
+
if (text2) {
|
|
851
|
+
chunks.push(text2);
|
|
852
852
|
}
|
|
853
853
|
}
|
|
854
854
|
if (chunks.length === 0) {
|
|
@@ -858,7 +858,7 @@ function extractTextContentFromToolCallContent(content) {
|
|
|
858
858
|
if (joined.length <= TOOL_CALL_CONTENT_MAX_CHARS) {
|
|
859
859
|
return { text: joined, content: typed };
|
|
860
860
|
}
|
|
861
|
-
const
|
|
861
|
+
const bounded2 = boundToolCallOutputText(joined);
|
|
862
862
|
const lastContributingTextIndex = typed.reduce(
|
|
863
863
|
(lastIndex, entry, index) => toolCallContentText(entry)?.trim() ? index : lastIndex,
|
|
864
864
|
-1
|
|
@@ -870,9 +870,9 @@ function extractTextContentFromToolCallContent(content) {
|
|
|
870
870
|
if (index !== lastContributingTextIndex) {
|
|
871
871
|
return [];
|
|
872
872
|
}
|
|
873
|
-
return [{ type: "content", content: { type: "text", text:
|
|
873
|
+
return [{ type: "content", content: { type: "text", text: bounded2 } }];
|
|
874
874
|
});
|
|
875
|
-
return { text:
|
|
875
|
+
return { text: bounded2, content: boundedContent };
|
|
876
876
|
}
|
|
877
877
|
function normalizeToolKind(kind) {
|
|
878
878
|
return typeof kind === "string" && kind.trim().length > 0 ? kind.trim() : void 0;
|
|
@@ -1226,11 +1226,11 @@ function parseSessionUpdateEvent(params) {
|
|
|
1226
1226
|
const contentType = content?.["type"];
|
|
1227
1227
|
const streamKind = kind === "agent_thought_chunk" ? "reasoning_text" : "assistant_text";
|
|
1228
1228
|
if (contentType === "text") {
|
|
1229
|
-
const
|
|
1230
|
-
if (
|
|
1229
|
+
const text2 = typeof content?.["text"] === "string" ? content["text"] : "";
|
|
1230
|
+
if (text2.length > 0) {
|
|
1231
1231
|
events.push({
|
|
1232
1232
|
_tag: "ContentDelta",
|
|
1233
|
-
text,
|
|
1233
|
+
text: text2,
|
|
1234
1234
|
streamKind,
|
|
1235
1235
|
rawPayload: params
|
|
1236
1236
|
});
|
|
@@ -1263,9 +1263,9 @@ function parseSessionUpdateEvent(params) {
|
|
|
1263
1263
|
case "compaction_summary_chunk": {
|
|
1264
1264
|
const compactionId = readAcpText(upd, "compactionId");
|
|
1265
1265
|
const content = isRecord2(upd["content"]) ? upd["content"] : void 0;
|
|
1266
|
-
const
|
|
1267
|
-
if (compactionId === void 0 || typeof
|
|
1268
|
-
events.push({ _tag: "CompactionSummaryChunk", compactionId, text });
|
|
1266
|
+
const text2 = content?.["type"] === "text" ? content["text"] : void 0;
|
|
1267
|
+
if (compactionId === void 0 || typeof text2 !== "string" || text2.length === 0) break;
|
|
1268
|
+
events.push({ _tag: "CompactionSummaryChunk", compactionId, text: text2 });
|
|
1269
1269
|
break;
|
|
1270
1270
|
}
|
|
1271
1271
|
default:
|
|
@@ -1503,10 +1503,10 @@ function createChildSessionRegistry(limit = CHILD_LIMIT) {
|
|
|
1503
1503
|
const records = /* @__PURE__ */ new Map();
|
|
1504
1504
|
const evictOne = (keep) => {
|
|
1505
1505
|
const protectedIds = /* @__PURE__ */ new Set();
|
|
1506
|
-
for (const [id,
|
|
1507
|
-
if (!active(
|
|
1506
|
+
for (const [id, record3] of records) {
|
|
1507
|
+
if (!active(record3.observed)) continue;
|
|
1508
1508
|
protectedIds.add(id);
|
|
1509
|
-
let parent =
|
|
1509
|
+
let parent = record3.parentAgentId;
|
|
1510
1510
|
while (parent !== void 0 && !protectedIds.has(parent)) {
|
|
1511
1511
|
protectedIds.add(parent);
|
|
1512
1512
|
parent = records.get(parent)?.parentAgentId;
|
|
@@ -1518,8 +1518,8 @@ function createChildSessionRegistry(limit = CHILD_LIMIT) {
|
|
|
1518
1518
|
return;
|
|
1519
1519
|
}
|
|
1520
1520
|
};
|
|
1521
|
-
const add = (sessionId,
|
|
1522
|
-
records.set(sessionId,
|
|
1521
|
+
const add = (sessionId, record3) => {
|
|
1522
|
+
records.set(sessionId, record3);
|
|
1523
1523
|
if (records.size > limit) evictOne(sessionId);
|
|
1524
1524
|
};
|
|
1525
1525
|
return {
|
|
@@ -3441,18 +3441,18 @@ var validateAsync = async (schema, value, _ctx) => {
|
|
|
3441
3441
|
return result.issues.length === 0;
|
|
3442
3442
|
};
|
|
3443
3443
|
var _encode = (_Err) => {
|
|
3444
|
-
const
|
|
3444
|
+
const parse4 = _parse(_Err);
|
|
3445
3445
|
const fn = (schema, value, _ctx, _params) => {
|
|
3446
3446
|
const ctx = _ctx ? { ..._ctx, direction: "backward" } : { direction: "backward" };
|
|
3447
|
-
return
|
|
3447
|
+
return parse4(schema, value, ctx, finalizeParams(fn, _params));
|
|
3448
3448
|
};
|
|
3449
3449
|
return fn;
|
|
3450
3450
|
};
|
|
3451
3451
|
var encode = /* @__PURE__ */ _encode($ZodRealError);
|
|
3452
3452
|
var _decode = (_Err) => {
|
|
3453
|
-
const
|
|
3453
|
+
const parse4 = _parse(_Err);
|
|
3454
3454
|
const fn = (schema, value, _ctx, _params) => {
|
|
3455
|
-
return
|
|
3455
|
+
return parse4(schema, value, _ctx, finalizeParams(fn, _params));
|
|
3456
3456
|
};
|
|
3457
3457
|
return fn;
|
|
3458
3458
|
};
|
|
@@ -6622,7 +6622,7 @@ var recursive = /* @__PURE__ */ new WeakMap();
|
|
|
6622
6622
|
var NONE = 0;
|
|
6623
6623
|
var ASSUMED = 1;
|
|
6624
6624
|
var PROVEN = 2;
|
|
6625
|
-
function isRecursive(inst, stack,
|
|
6625
|
+
function isRecursive(inst, stack, resolve5) {
|
|
6626
6626
|
const cached2 = recursive.get(inst);
|
|
6627
6627
|
if (cached2 !== void 0)
|
|
6628
6628
|
return cached2 ? PROVEN : NONE;
|
|
@@ -6632,7 +6632,7 @@ function isRecursive(inst, stack, resolve4) {
|
|
|
6632
6632
|
let result = NONE;
|
|
6633
6633
|
const check2 = (child) => {
|
|
6634
6634
|
if (result !== PROVEN && child?._zod) {
|
|
6635
|
-
const answer = isRecursive(child, stack,
|
|
6635
|
+
const answer = isRecursive(child, stack, resolve5);
|
|
6636
6636
|
if (answer > result)
|
|
6637
6637
|
result = answer;
|
|
6638
6638
|
}
|
|
@@ -6643,7 +6643,7 @@ function isRecursive(inst, stack, resolve4) {
|
|
|
6643
6643
|
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
6644
6644
|
if (spread && !desc.enumerable)
|
|
6645
6645
|
continue;
|
|
6646
|
-
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack,
|
|
6646
|
+
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve5) : NONE;
|
|
6647
6647
|
if (child > answer)
|
|
6648
6648
|
answer = child;
|
|
6649
6649
|
}
|
|
@@ -6707,7 +6707,7 @@ function isRecursive(inst, stack, resolve4) {
|
|
|
6707
6707
|
break;
|
|
6708
6708
|
// `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
|
|
6709
6709
|
case "lazy": {
|
|
6710
|
-
const inner = def._cachedInner ?? (
|
|
6710
|
+
const inner = def._cachedInner ?? (resolve5 ? inst._zod.innerType : void 0);
|
|
6711
6711
|
merge2(inner ? isRecursive(inner, stack, false) : ASSUMED);
|
|
6712
6712
|
break;
|
|
6713
6713
|
}
|
|
@@ -10905,8 +10905,8 @@ function ko_default() {
|
|
|
10905
10905
|
}
|
|
10906
10906
|
|
|
10907
10907
|
// ../../node_modules/.pnpm/zod@4.6.5/node_modules/zod/v4/locales/lt.js
|
|
10908
|
-
var capitalizeFirstCharacter = (
|
|
10909
|
-
return
|
|
10908
|
+
var capitalizeFirstCharacter = (text2) => {
|
|
10909
|
+
return text2.charAt(0).toUpperCase() + text2.slice(1);
|
|
10910
10910
|
};
|
|
10911
10911
|
function getUnitTypeFromNumber(number4) {
|
|
10912
10912
|
const abs = Math.abs(number4);
|
|
@@ -18200,8 +18200,8 @@ function rewriteKeyNames(ctx) {
|
|
|
18200
18200
|
bySchema.set(entry.schema, entry);
|
|
18201
18201
|
}
|
|
18202
18202
|
const rewrites = /* @__PURE__ */ new Map();
|
|
18203
|
-
for (const
|
|
18204
|
-
const seen = ctx.seen.get(
|
|
18203
|
+
for (const record3 of pendingRecords.get(ctx) ?? []) {
|
|
18204
|
+
const seen = ctx.seen.get(record3);
|
|
18205
18205
|
const names = (seen?.def ?? seen?.schema)?.propertyNames;
|
|
18206
18206
|
if (!names || names === true || rewrites.has(names))
|
|
18207
18207
|
continue;
|
|
@@ -23371,11 +23371,11 @@ var Connection = class {
|
|
|
23371
23371
|
const id = this.nextRequestId++;
|
|
23372
23372
|
let cancel = () => {
|
|
23373
23373
|
};
|
|
23374
|
-
const response = new Promise((
|
|
23374
|
+
const response = new Promise((resolve5, reject) => {
|
|
23375
23375
|
const pendingResponse = {
|
|
23376
23376
|
resolve: (value) => {
|
|
23377
23377
|
try {
|
|
23378
|
-
|
|
23378
|
+
resolve5(mapResponse ? mapResponse(value) : value);
|
|
23379
23379
|
} catch (error62) {
|
|
23380
23380
|
reject(error62);
|
|
23381
23381
|
}
|
|
@@ -23432,8 +23432,8 @@ var Connection = class {
|
|
|
23432
23432
|
this.stream = stream;
|
|
23433
23433
|
this.staticHandlers = handlers;
|
|
23434
23434
|
this.allowBatches = options?.allowBatches ?? true;
|
|
23435
|
-
this.closedPromise = new Promise((
|
|
23436
|
-
this.abortController.signal.addEventListener("abort", () =>
|
|
23435
|
+
this.closedPromise = new Promise((resolve5) => {
|
|
23436
|
+
this.abortController.signal.addEventListener("abort", () => resolve5());
|
|
23437
23437
|
});
|
|
23438
23438
|
void this.receive();
|
|
23439
23439
|
}
|
|
@@ -23724,13 +23724,13 @@ var ConnectionBuilder = class {
|
|
|
23724
23724
|
/**
|
|
23725
23725
|
* Adds a typed request handler for one method.
|
|
23726
23726
|
*/
|
|
23727
|
-
onReceiveRequest(method,
|
|
23727
|
+
onReceiveRequest(method, parse4, handler) {
|
|
23728
23728
|
return this.withHandler({
|
|
23729
23729
|
handleMessage: async (message, cx) => {
|
|
23730
23730
|
if (message.kind !== "request" || message.method !== method) {
|
|
23731
23731
|
return Handled.no(message);
|
|
23732
23732
|
}
|
|
23733
|
-
const request =
|
|
23733
|
+
const request = parse4(message.params);
|
|
23734
23734
|
return await handler(request, message.responder, cx) ?? Handled.yes();
|
|
23735
23735
|
},
|
|
23736
23736
|
describe: () => `${this.connectionName ?? "request"}:${method}`
|
|
@@ -23739,13 +23739,13 @@ var ConnectionBuilder = class {
|
|
|
23739
23739
|
/**
|
|
23740
23740
|
* Adds a typed notification handler for one method.
|
|
23741
23741
|
*/
|
|
23742
|
-
onReceiveNotification(method,
|
|
23742
|
+
onReceiveNotification(method, parse4, handler) {
|
|
23743
23743
|
return this.withHandler({
|
|
23744
23744
|
handleMessage: async (message, cx) => {
|
|
23745
23745
|
if (message.kind !== "notification" || message.method !== method) {
|
|
23746
23746
|
return Handled.no(message);
|
|
23747
23747
|
}
|
|
23748
|
-
const notification =
|
|
23748
|
+
const notification = parse4(message.params);
|
|
23749
23749
|
return await handler(notification, cx) ?? Handled.yes();
|
|
23750
23750
|
},
|
|
23751
23751
|
describe: () => `${this.connectionName ?? "notification"}:${method}`
|
|
@@ -24327,8 +24327,8 @@ var AsyncQueue = class {
|
|
|
24327
24327
|
if (this.failed) {
|
|
24328
24328
|
return Promise.reject(this.failure);
|
|
24329
24329
|
}
|
|
24330
|
-
return new Promise((
|
|
24331
|
-
this.waiters.push({ resolve:
|
|
24330
|
+
return new Promise((resolve5, reject) => {
|
|
24331
|
+
this.waiters.push({ resolve: resolve5, reject });
|
|
24332
24332
|
});
|
|
24333
24333
|
}
|
|
24334
24334
|
};
|
|
@@ -25375,12 +25375,12 @@ function createAcpConnection(options) {
|
|
|
25375
25375
|
failIfClosed();
|
|
25376
25376
|
const id = nextRequestId;
|
|
25377
25377
|
nextRequestId += 1;
|
|
25378
|
-
const { promise: promise2, resolve:
|
|
25378
|
+
const { promise: promise2, resolve: resolve5, reject } = Promise.withResolvers();
|
|
25379
25379
|
pending.set(String(id), {
|
|
25380
25380
|
method,
|
|
25381
25381
|
...promptId === void 0 ? {} : { promptId },
|
|
25382
25382
|
...onArrival === void 0 ? {} : { onArrival },
|
|
25383
|
-
resolve:
|
|
25383
|
+
resolve: resolve5,
|
|
25384
25384
|
reject
|
|
25385
25385
|
});
|
|
25386
25386
|
const message = params === void 0 ? { jsonrpc: "2.0", id, method } : { jsonrpc: "2.0", id, method, params };
|
|
@@ -25409,8 +25409,8 @@ function createAcpConnection(options) {
|
|
|
25409
25409
|
if (inboundBatches === 0) {
|
|
25410
25410
|
return;
|
|
25411
25411
|
}
|
|
25412
|
-
await new Promise((
|
|
25413
|
-
idleWaiters.push(
|
|
25412
|
+
await new Promise((resolve5) => {
|
|
25413
|
+
idleWaiters.push(resolve5);
|
|
25414
25414
|
if (inboundBatches === 0) {
|
|
25415
25415
|
releaseIdleWaiters();
|
|
25416
25416
|
}
|
|
@@ -25496,8 +25496,8 @@ var Mutex = class {
|
|
|
25496
25496
|
this.locked = true;
|
|
25497
25497
|
return Promise.resolve();
|
|
25498
25498
|
}
|
|
25499
|
-
return new Promise((
|
|
25500
|
-
this.waiters.push(
|
|
25499
|
+
return new Promise((resolve5) => {
|
|
25500
|
+
this.waiters.push(resolve5);
|
|
25501
25501
|
});
|
|
25502
25502
|
}
|
|
25503
25503
|
tryAcquire() {
|
|
@@ -25637,7 +25637,7 @@ function createExecutorLifecycle({
|
|
|
25637
25637
|
"Cannot compact while a turn or another compaction is running"
|
|
25638
25638
|
);
|
|
25639
25639
|
}
|
|
25640
|
-
const
|
|
25640
|
+
const record3 = {
|
|
25641
25641
|
snapshotId: randomId(),
|
|
25642
25642
|
trigger: "manual",
|
|
25643
25643
|
startedAtMs: nowMs(),
|
|
@@ -25647,7 +25647,7 @@ function createExecutorLifecycle({
|
|
|
25647
25647
|
adopted: false
|
|
25648
25648
|
};
|
|
25649
25649
|
await promptMutex.acquire();
|
|
25650
|
-
shared.manualCompaction =
|
|
25650
|
+
shared.manualCompaction = record3;
|
|
25651
25651
|
const emitSessionState = (state) => {
|
|
25652
25652
|
emit({
|
|
25653
25653
|
type: "session.state.changed",
|
|
@@ -25660,7 +25660,7 @@ function createExecutorLifecycle({
|
|
|
25660
25660
|
try {
|
|
25661
25661
|
failIfDisposed();
|
|
25662
25662
|
emitSessionState("compacting");
|
|
25663
|
-
emitCompactionState(
|
|
25663
|
+
emitCompactionState(record3, "compacting");
|
|
25664
25664
|
let response;
|
|
25665
25665
|
try {
|
|
25666
25666
|
response = await sendPromptRpc(started.sessionId, [
|
|
@@ -25674,13 +25674,13 @@ function createExecutorLifecycle({
|
|
|
25674
25674
|
if (response.stopReason === "cancelled") {
|
|
25675
25675
|
return;
|
|
25676
25676
|
}
|
|
25677
|
-
if (!
|
|
25678
|
-
|
|
25679
|
-
emitCompactionState(
|
|
25677
|
+
if (!record3.finished) {
|
|
25678
|
+
record3.finished = true;
|
|
25679
|
+
emitCompactionState(record3, "compacted");
|
|
25680
25680
|
}
|
|
25681
25681
|
} finally {
|
|
25682
25682
|
for (const [agentId, tracked] of compactions) {
|
|
25683
|
-
if (tracked ===
|
|
25683
|
+
if (tracked === record3) compactions.delete(agentId);
|
|
25684
25684
|
}
|
|
25685
25685
|
shared.manualCompaction = void 0;
|
|
25686
25686
|
promptMutex.release();
|
|
@@ -25698,9 +25698,9 @@ function createExecutorLifecycle({
|
|
|
25698
25698
|
let timer;
|
|
25699
25699
|
await Promise.race([
|
|
25700
25700
|
connection.closed.catch(() => void 0),
|
|
25701
|
-
new Promise((
|
|
25701
|
+
new Promise((resolve5) => {
|
|
25702
25702
|
timer = setTimeout(
|
|
25703
|
-
|
|
25703
|
+
resolve5,
|
|
25704
25704
|
options.resultDrainTimeoutMs ?? DEFAULT_RESULT_DRAIN_TIMEOUT_MS
|
|
25705
25705
|
);
|
|
25706
25706
|
})
|
|
@@ -25769,10 +25769,10 @@ function selectAutoApprovedAcpPermissionOption(request) {
|
|
|
25769
25769
|
}
|
|
25770
25770
|
function parseAcpResumeCursor(raw, schemaVersion) {
|
|
25771
25771
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) return void 0;
|
|
25772
|
-
const
|
|
25773
|
-
if (
|
|
25774
|
-
if (typeof
|
|
25775
|
-
return { sessionId:
|
|
25772
|
+
const record3 = raw;
|
|
25773
|
+
if (record3["schemaVersion"] !== schemaVersion) return void 0;
|
|
25774
|
+
if (typeof record3["sessionId"] !== "string" || !record3["sessionId"].trim()) return void 0;
|
|
25775
|
+
return { sessionId: record3["sessionId"].trim() };
|
|
25776
25776
|
}
|
|
25777
25777
|
function acpPromptSettlementBelongsToContext(input2) {
|
|
25778
25778
|
return input2.liveAcpSessionId === input2.expectedAcpSessionId && (input2.liveActiveTurnId === input2.turnId || input2.liveSessionActiveTurnId === input2.turnId);
|
|
@@ -25781,18 +25781,18 @@ function isAcpRequestPermissionParams(value) {
|
|
|
25781
25781
|
if (typeof value !== "object" || value === null) {
|
|
25782
25782
|
return false;
|
|
25783
25783
|
}
|
|
25784
|
-
const
|
|
25785
|
-
if (typeof
|
|
25784
|
+
const record3 = value;
|
|
25785
|
+
if (typeof record3["sessionId"] !== "string") {
|
|
25786
25786
|
return false;
|
|
25787
25787
|
}
|
|
25788
|
-
const toolCall =
|
|
25788
|
+
const toolCall = record3["toolCall"];
|
|
25789
25789
|
if (typeof toolCall !== "object" || toolCall === null) {
|
|
25790
25790
|
return false;
|
|
25791
25791
|
}
|
|
25792
25792
|
if (typeof toolCall["toolCallId"] !== "string") {
|
|
25793
25793
|
return false;
|
|
25794
25794
|
}
|
|
25795
|
-
return Array.isArray(
|
|
25795
|
+
return Array.isArray(record3["options"]);
|
|
25796
25796
|
}
|
|
25797
25797
|
|
|
25798
25798
|
// ../../packages/ycodium-acp-executor/src/apply-effort.ts
|
|
@@ -26233,7 +26233,7 @@ function createExecutorPrompt({
|
|
|
26233
26233
|
promptResults.forget(input2.turnId);
|
|
26234
26234
|
return true;
|
|
26235
26235
|
};
|
|
26236
|
-
const sendPromptRpc = async (sessionId, promptParts, onWritten,
|
|
26236
|
+
const sendPromptRpc = async (sessionId, promptParts, onWritten, record3) => {
|
|
26237
26237
|
const settlementHooks = hooks.promptSettlement;
|
|
26238
26238
|
const promptKey = settlementHooks === void 0 ? void 0 : randomId();
|
|
26239
26239
|
const pending = connection.begin(
|
|
@@ -26243,7 +26243,7 @@ function createExecutorPrompt({
|
|
|
26243
26243
|
prompt: promptParts,
|
|
26244
26244
|
...settlementHooks !== void 0 && promptKey !== void 0 ? settlementHooks.requestFields(promptKey) : {}
|
|
26245
26245
|
},
|
|
26246
|
-
|
|
26246
|
+
record3?.promptId
|
|
26247
26247
|
);
|
|
26248
26248
|
void pending.written.then(onWritten, () => void 0);
|
|
26249
26249
|
const promptRpc = pending.response;
|
|
@@ -26255,10 +26255,10 @@ function createExecutorPrompt({
|
|
|
26255
26255
|
promptKey,
|
|
26256
26256
|
sessionId,
|
|
26257
26257
|
settle: settleEarly,
|
|
26258
|
-
...
|
|
26259
|
-
onResponse: (response) => promptResults.receive(
|
|
26260
|
-
onError: () => promptResults.reject(
|
|
26261
|
-
hasResult: () =>
|
|
26258
|
+
...record3 === void 0 ? {} : {
|
|
26259
|
+
onResponse: (response) => promptResults.receive(record3.promptId, response),
|
|
26260
|
+
onError: () => promptResults.reject(record3.promptId),
|
|
26261
|
+
hasResult: () => record3.response !== void 0
|
|
26262
26262
|
}
|
|
26263
26263
|
});
|
|
26264
26264
|
try {
|
|
@@ -26352,11 +26352,11 @@ function createExecutorPrompt({
|
|
|
26352
26352
|
failIfPromptUnavailable();
|
|
26353
26353
|
const started = requireStarted();
|
|
26354
26354
|
const sessionId = started.sessionId;
|
|
26355
|
-
let
|
|
26355
|
+
let record3;
|
|
26356
26356
|
const settle2 = (rest) => settleTurn({
|
|
26357
26357
|
expectedGeneration: started.generation,
|
|
26358
26358
|
expectedSessionId: sessionId,
|
|
26359
|
-
record:
|
|
26359
|
+
record: record3,
|
|
26360
26360
|
...rest
|
|
26361
26361
|
});
|
|
26362
26362
|
let turnId;
|
|
@@ -26369,7 +26369,7 @@ function createExecutorPrompt({
|
|
|
26369
26369
|
randomId
|
|
26370
26370
|
);
|
|
26371
26371
|
shared.promptsInFlight += 1;
|
|
26372
|
-
|
|
26372
|
+
record3 = promptResults.add(
|
|
26373
26373
|
{
|
|
26374
26374
|
promptId: randomId(),
|
|
26375
26375
|
sessionId: started.sessionId,
|
|
@@ -26398,9 +26398,9 @@ function createExecutorPrompt({
|
|
|
26398
26398
|
const promptParts = input2.prompt ?? (input2.text !== void 0 ? [{ type: "text", text: input2.text }] : [{ type: "text", text: "" }]);
|
|
26399
26399
|
let contextWindow;
|
|
26400
26400
|
const finishPrompt = () => {
|
|
26401
|
-
if (!isLive(started.generation) ||
|
|
26402
|
-
const response2 =
|
|
26403
|
-
if (
|
|
26401
|
+
if (!isLive(started.generation) || record3.finished) throw new AcpExecutorDisposedError();
|
|
26402
|
+
const response2 = record3.response;
|
|
26403
|
+
if (record3.interrupted || response2 === void 0) {
|
|
26404
26404
|
settle2({ turnId, stopReason: "cancelled", state: "cancelled" });
|
|
26405
26405
|
return { threadId: options.threadId, turnId, stopReason: "cancelled" };
|
|
26406
26406
|
}
|
|
@@ -26487,7 +26487,7 @@ function createExecutorPrompt({
|
|
|
26487
26487
|
written = true;
|
|
26488
26488
|
input2.onDispatched?.(turnId);
|
|
26489
26489
|
},
|
|
26490
|
-
|
|
26490
|
+
record3
|
|
26491
26491
|
);
|
|
26492
26492
|
if (readFailure && response.stopReason === "end_turn" && isLive(started.generation) && !isStale()) {
|
|
26493
26493
|
const controller = new AbortController();
|
|
@@ -26542,7 +26542,7 @@ function createExecutorPrompt({
|
|
|
26542
26542
|
if (turnId === void 0) {
|
|
26543
26543
|
throw new AcpExecutorError("internal", "ACP prompt settled without a turn id");
|
|
26544
26544
|
}
|
|
26545
|
-
if (
|
|
26545
|
+
if (record3.finished) throw new AcpExecutorDisposedError();
|
|
26546
26546
|
if (hooks.readContextWindow !== void 0) {
|
|
26547
26547
|
try {
|
|
26548
26548
|
contextWindow = await hooks.readContextWindow({
|
|
@@ -26577,81 +26577,81 @@ function createPromptResults({
|
|
|
26577
26577
|
}) {
|
|
26578
26578
|
const prompts = /* @__PURE__ */ new Map();
|
|
26579
26579
|
const add = (identity, finish) => {
|
|
26580
|
-
const { promise: done, resolve:
|
|
26581
|
-
const
|
|
26580
|
+
const { promise: done, resolve: resolve5 } = Promise.withResolvers();
|
|
26581
|
+
const record3 = {
|
|
26582
26582
|
...identity,
|
|
26583
26583
|
finish,
|
|
26584
26584
|
done,
|
|
26585
|
-
resolve:
|
|
26585
|
+
resolve: resolve5,
|
|
26586
26586
|
rejected: false,
|
|
26587
26587
|
interrupted: false,
|
|
26588
26588
|
finished: false
|
|
26589
26589
|
};
|
|
26590
|
-
prompts.set(
|
|
26591
|
-
return
|
|
26590
|
+
prompts.set(record3.promptId, record3);
|
|
26591
|
+
return record3;
|
|
26592
26592
|
};
|
|
26593
26593
|
const receive = (promptId, response) => {
|
|
26594
|
-
const
|
|
26595
|
-
if (!
|
|
26596
|
-
if (shared.disposed || shared.generation !==
|
|
26594
|
+
const record3 = prompts.get(promptId);
|
|
26595
|
+
if (!record3 || record3.finished || record3.rejected || record3.response !== void 0) return;
|
|
26596
|
+
if (shared.disposed || shared.generation !== record3.generation || shared.sessionId !== record3.sessionId)
|
|
26597
26597
|
return;
|
|
26598
|
-
|
|
26598
|
+
record3.response = response;
|
|
26599
26599
|
};
|
|
26600
26600
|
const reject = (promptId) => {
|
|
26601
|
-
const
|
|
26602
|
-
if (
|
|
26601
|
+
const record3 = prompts.get(promptId);
|
|
26602
|
+
if (record3 && record3.response === void 0) record3.rejected = true;
|
|
26603
26603
|
};
|
|
26604
26604
|
const stop = (turnId) => {
|
|
26605
|
-
for (const
|
|
26606
|
-
if (!
|
|
26607
|
-
|
|
26605
|
+
for (const record3 of prompts.values()) {
|
|
26606
|
+
if (!record3.finished && (turnId === void 0 || record3.turnId === turnId) && record3.response === void 0) {
|
|
26607
|
+
record3.interrupted = true;
|
|
26608
26608
|
}
|
|
26609
26609
|
}
|
|
26610
26610
|
};
|
|
26611
|
-
const complete = (
|
|
26612
|
-
|
|
26613
|
-
|
|
26611
|
+
const complete = (record3) => {
|
|
26612
|
+
record3.finished = true;
|
|
26613
|
+
record3.resolve();
|
|
26614
26614
|
};
|
|
26615
|
-
const hasInterrupted = (turnId) => [...prompts.values()].some((
|
|
26615
|
+
const hasInterrupted = (turnId) => [...prompts.values()].some((record3) => record3.turnId === turnId && record3.interrupted);
|
|
26616
26616
|
const forget = (turnId) => {
|
|
26617
|
-
for (const [id,
|
|
26618
|
-
if (
|
|
26619
|
-
complete(
|
|
26617
|
+
for (const [id, record3] of prompts) {
|
|
26618
|
+
if (record3.turnId === turnId) {
|
|
26619
|
+
complete(record3);
|
|
26620
26620
|
prompts.delete(id);
|
|
26621
26621
|
}
|
|
26622
26622
|
}
|
|
26623
26623
|
};
|
|
26624
26624
|
const wait = async (turnId, includeUnreceived = false) => {
|
|
26625
26625
|
const claimed = [...prompts.values()].filter(
|
|
26626
|
-
(
|
|
26626
|
+
(record3) => !record3.finished && (includeUnreceived || record3.response !== void 0) && (turnId === void 0 || record3.turnId === turnId)
|
|
26627
26627
|
);
|
|
26628
26628
|
if (claimed.length === 0) return;
|
|
26629
26629
|
let timer;
|
|
26630
26630
|
try {
|
|
26631
26631
|
const drained = await Promise.race([
|
|
26632
|
-
Promise.all(claimed.map((
|
|
26633
|
-
new Promise((
|
|
26632
|
+
Promise.all(claimed.map((record3) => record3.done)).then(() => true),
|
|
26633
|
+
new Promise((resolve5) => {
|
|
26634
26634
|
timer = setTimeout(
|
|
26635
|
-
() =>
|
|
26635
|
+
() => resolve5(false),
|
|
26636
26636
|
options.resultDrainTimeoutMs ?? DEFAULT_RESULT_DRAIN_TIMEOUT_MS
|
|
26637
26637
|
);
|
|
26638
26638
|
})
|
|
26639
26639
|
]);
|
|
26640
26640
|
if (drained) return;
|
|
26641
26641
|
options.log?.warn?.("ACP result settlement timed out", { threadId: options.threadId });
|
|
26642
|
-
for (const
|
|
26642
|
+
for (const record3 of claimed) if (!record3.finished) record3.finish();
|
|
26643
26643
|
} finally {
|
|
26644
26644
|
clearTimeout(timer);
|
|
26645
26645
|
}
|
|
26646
26646
|
};
|
|
26647
26647
|
const finishUnreceived = () => {
|
|
26648
26648
|
const claimedTurns = new Set(
|
|
26649
|
-
[...prompts.values()].filter((
|
|
26649
|
+
[...prompts.values()].filter((record3) => !record3.finished && record3.response !== void 0).map((record3) => record3.turnId)
|
|
26650
26650
|
);
|
|
26651
|
-
for (const
|
|
26652
|
-
if (!
|
|
26653
|
-
if (claimedTurns.has(
|
|
26654
|
-
else complete(
|
|
26651
|
+
for (const record3 of prompts.values()) {
|
|
26652
|
+
if (!record3.finished && record3.response === void 0) {
|
|
26653
|
+
if (claimedTurns.has(record3.turnId)) record3.finish();
|
|
26654
|
+
else complete(record3);
|
|
26655
26655
|
}
|
|
26656
26656
|
}
|
|
26657
26657
|
};
|
|
@@ -26663,15 +26663,15 @@ function defaultPermissionStatement(request) {
|
|
|
26663
26663
|
const rawInput = request.toolCall?.data["rawInput"];
|
|
26664
26664
|
const input2 = isRecord2(rawInput) ? rawInput : {};
|
|
26665
26665
|
const coveredArgs = [];
|
|
26666
|
-
const
|
|
26666
|
+
const text2 = (name) => {
|
|
26667
26667
|
const value = input2[name];
|
|
26668
26668
|
if (typeof value !== "string" || value.trim().length === 0) return void 0;
|
|
26669
26669
|
coveredArgs.push(name);
|
|
26670
26670
|
return value;
|
|
26671
26671
|
};
|
|
26672
|
-
const description =
|
|
26673
|
-
const justification =
|
|
26674
|
-
const command = request.kind === "execute" ?
|
|
26672
|
+
const description = text2("description");
|
|
26673
|
+
const justification = text2("justification") ?? text2("reason");
|
|
26674
|
+
const command = request.kind === "execute" ? text2("command") ?? text2("cmd") ?? request.toolCall?.command : void 0;
|
|
26675
26675
|
let outsideSandbox = false;
|
|
26676
26676
|
for (const name of ["sandbox_permissions", "sandboxPermissions", "dangerouslyDisableSandbox"]) {
|
|
26677
26677
|
const value = input2[name];
|
|
@@ -26831,14 +26831,14 @@ function createExecutorRequests({
|
|
|
26831
26831
|
const statement = hooks.permissionStatement?.(permissionContext) ?? defaultPermissionStatement(permissionRequest);
|
|
26832
26832
|
const fileChanges = hooks.permissionFileChanges?.(permissionContext) ?? fileChangesFromAcpPermission(permissionRequest);
|
|
26833
26833
|
const requestId = randomId();
|
|
26834
|
-
const outcome = await new Promise((
|
|
26834
|
+
const outcome = await new Promise((resolve5) => {
|
|
26835
26835
|
const pending = {
|
|
26836
26836
|
requestId,
|
|
26837
26837
|
request: params,
|
|
26838
26838
|
permissionRequest,
|
|
26839
26839
|
turnId: shared.activeTurnId,
|
|
26840
26840
|
settled: false,
|
|
26841
|
-
resolve:
|
|
26841
|
+
resolve: resolve5
|
|
26842
26842
|
};
|
|
26843
26843
|
approvals.add(pending);
|
|
26844
26844
|
emit(
|
|
@@ -27055,14 +27055,14 @@ function createExecutorRuntime({
|
|
|
27055
27055
|
if (!promptMutex.isLocked) {
|
|
27056
27056
|
return true;
|
|
27057
27057
|
}
|
|
27058
|
-
return await new Promise((
|
|
27058
|
+
return await new Promise((resolve5) => {
|
|
27059
27059
|
const timer = setTimeout(() => {
|
|
27060
27060
|
shared.promptWaiters = shared.promptWaiters.filter((waiter) => waiter !== onSettle);
|
|
27061
|
-
|
|
27061
|
+
resolve5(false);
|
|
27062
27062
|
}, timeoutMs);
|
|
27063
27063
|
const onSettle = () => {
|
|
27064
27064
|
clearTimeout(timer);
|
|
27065
|
-
|
|
27065
|
+
resolve5(true);
|
|
27066
27066
|
};
|
|
27067
27067
|
shared.promptWaiters.push(onSettle);
|
|
27068
27068
|
});
|
|
@@ -27692,13 +27692,13 @@ function parseState(raw) {
|
|
|
27692
27692
|
if (stopReason === "cancelled") return { status: "cancelled", error: void 0 };
|
|
27693
27693
|
return { status: "idle", error: void 0 };
|
|
27694
27694
|
}
|
|
27695
|
-
function childLinkage(childId,
|
|
27695
|
+
function childLinkage(childId, record3) {
|
|
27696
27696
|
return {
|
|
27697
27697
|
taskType: "subagent",
|
|
27698
27698
|
rosterKind: "subagent",
|
|
27699
27699
|
nativeSessionId: childId,
|
|
27700
27700
|
timelineBypass: true,
|
|
27701
|
-
...
|
|
27701
|
+
...record3.title === void 0 ? {} : { title: record3.title }
|
|
27702
27702
|
};
|
|
27703
27703
|
}
|
|
27704
27704
|
function createSubagentSessionTracker(registry2) {
|
|
@@ -27714,9 +27714,9 @@ function createSubagentSessionTracker(registry2) {
|
|
|
27714
27714
|
const title = asTrimmedString(update["title"]);
|
|
27715
27715
|
const description = asTrimmedString(update["description"]);
|
|
27716
27716
|
const state = parseState(update["state"]);
|
|
27717
|
-
let
|
|
27718
|
-
if (
|
|
27719
|
-
|
|
27717
|
+
let record3 = registry2.get(childId);
|
|
27718
|
+
if (record3 === void 0) {
|
|
27719
|
+
record3 = {
|
|
27720
27720
|
turnId: ctx.turnId,
|
|
27721
27721
|
title,
|
|
27722
27722
|
description,
|
|
@@ -27728,40 +27728,40 @@ function createSubagentSessionTracker(registry2) {
|
|
|
27728
27728
|
announced: ctx.silent,
|
|
27729
27729
|
pendingMetadata: false
|
|
27730
27730
|
};
|
|
27731
|
-
registry2.add(childId,
|
|
27731
|
+
registry2.add(childId, record3);
|
|
27732
27732
|
}
|
|
27733
|
-
|
|
27733
|
+
record3.turnId ??= ctx.turnId;
|
|
27734
27734
|
if (!ctx.silent) {
|
|
27735
|
-
if (title !== void 0 && title !==
|
|
27736
|
-
|
|
27735
|
+
if (title !== void 0 && title !== record3.title || description !== void 0 && description !== record3.description) {
|
|
27736
|
+
record3.pendingMetadata = true;
|
|
27737
27737
|
}
|
|
27738
27738
|
}
|
|
27739
|
-
if (title !== void 0)
|
|
27740
|
-
if (description !== void 0)
|
|
27741
|
-
if (state.status !== void 0)
|
|
27739
|
+
if (title !== void 0) record3.title = title;
|
|
27740
|
+
if (description !== void 0) record3.description = description;
|
|
27741
|
+
if (state.status !== void 0) record3.observed = state.status;
|
|
27742
27742
|
if (ctx.silent) return [];
|
|
27743
|
-
const linkage2 = childLinkage(childId,
|
|
27744
|
-
const turn =
|
|
27743
|
+
const linkage2 = childLinkage(childId, record3);
|
|
27744
|
+
const turn = record3.turnId === void 0 ? {} : { turnId: record3.turnId };
|
|
27745
27745
|
const events = [];
|
|
27746
|
-
if (!
|
|
27747
|
-
if (!
|
|
27748
|
-
|
|
27749
|
-
|
|
27746
|
+
if (!record3.announced && state.status === void 0) return events;
|
|
27747
|
+
if (!record3.announced) {
|
|
27748
|
+
record3.announced = true;
|
|
27749
|
+
record3.pendingMetadata = false;
|
|
27750
27750
|
events.push({
|
|
27751
27751
|
type: "task.started",
|
|
27752
27752
|
...turn,
|
|
27753
27753
|
payload: {
|
|
27754
27754
|
taskId: childId,
|
|
27755
27755
|
...linkage2,
|
|
27756
|
-
...
|
|
27756
|
+
...record3.description === void 0 ? {} : { description: record3.description }
|
|
27757
27757
|
}
|
|
27758
27758
|
});
|
|
27759
27759
|
}
|
|
27760
|
-
const statusChanged = state.status !== void 0 && (state.status !==
|
|
27760
|
+
const statusChanged = state.status !== void 0 && (state.status !== record3.reported || record3.pendingMetadata || state.error !== void 0 && state.error !== record3.reportedError);
|
|
27761
27761
|
if (statusChanged) {
|
|
27762
|
-
|
|
27763
|
-
|
|
27764
|
-
|
|
27762
|
+
record3.pendingMetadata = false;
|
|
27763
|
+
record3.reported = state.status;
|
|
27764
|
+
record3.reportedError = state.status === "failed" ? state.error ?? record3.reportedError : void 0;
|
|
27765
27765
|
events.push({
|
|
27766
27766
|
type: "task.updated",
|
|
27767
27767
|
...turn,
|
|
@@ -27769,7 +27769,7 @@ function createSubagentSessionTracker(registry2) {
|
|
|
27769
27769
|
taskId: childId,
|
|
27770
27770
|
status: state.status,
|
|
27771
27771
|
...state.error === void 0 ? {} : { error: state.error },
|
|
27772
|
-
...
|
|
27772
|
+
...record3.description === void 0 ? {} : { description: record3.description },
|
|
27773
27773
|
...linkage2
|
|
27774
27774
|
}
|
|
27775
27775
|
});
|
|
@@ -27778,20 +27778,20 @@ function createSubagentSessionTracker(registry2) {
|
|
|
27778
27778
|
};
|
|
27779
27779
|
const settleSessionEnded = () => {
|
|
27780
27780
|
const events = [];
|
|
27781
|
-
for (const [childId,
|
|
27782
|
-
const last =
|
|
27783
|
-
if (!
|
|
27784
|
-
|
|
27785
|
-
|
|
27781
|
+
for (const [childId, record3] of registry2.entries()) {
|
|
27782
|
+
const last = record3.reported ?? record3.observed;
|
|
27783
|
+
if (!record3.announced || last !== "running" && last !== "waiting") continue;
|
|
27784
|
+
record3.reported = "idle";
|
|
27785
|
+
record3.observed = "idle";
|
|
27786
27786
|
events.push({
|
|
27787
27787
|
type: "task.updated",
|
|
27788
|
-
...
|
|
27788
|
+
...record3.turnId === void 0 ? {} : { turnId: record3.turnId },
|
|
27789
27789
|
payload: {
|
|
27790
27790
|
taskId: childId,
|
|
27791
27791
|
status: "idle",
|
|
27792
27792
|
outcomeUnknown: true,
|
|
27793
|
-
...
|
|
27794
|
-
...childLinkage(childId,
|
|
27793
|
+
...record3.description === void 0 ? {} : { description: record3.description },
|
|
27794
|
+
...childLinkage(childId, record3)
|
|
27795
27795
|
}
|
|
27796
27796
|
});
|
|
27797
27797
|
}
|
|
@@ -27820,8 +27820,8 @@ function createExecutorUpdates({
|
|
|
27820
27820
|
const shownToolCallIds = /* @__PURE__ */ new Set();
|
|
27821
27821
|
const markChildSession = shared.childSessions.mark;
|
|
27822
27822
|
const subagentSessions = options.subagentSessions === true ? createSubagentSessionTracker(shared.childSessions) : void 0;
|
|
27823
|
-
const emitCompactionState = (
|
|
27824
|
-
const summary =
|
|
27823
|
+
const emitCompactionState = (record3, state) => {
|
|
27824
|
+
const summary = record3.summary?.trim() ?? "";
|
|
27825
27825
|
const truncated = summary.length > COMPACTION_SUMMARY_MAX_CHARS;
|
|
27826
27826
|
emit({
|
|
27827
27827
|
type: "thread.state.changed",
|
|
@@ -27832,9 +27832,9 @@ function createExecutorUpdates({
|
|
|
27832
27832
|
payload: {
|
|
27833
27833
|
state,
|
|
27834
27834
|
compaction: {
|
|
27835
|
-
compactionId:
|
|
27836
|
-
trigger:
|
|
27837
|
-
...state === "compacted" ? { durationMs: Math.max(0, nowMs() -
|
|
27835
|
+
compactionId: record3.snapshotId,
|
|
27836
|
+
trigger: record3.trigger,
|
|
27837
|
+
...state === "compacted" ? { durationMs: Math.max(0, nowMs() - record3.startedAtMs) } : {},
|
|
27838
27838
|
...summary.length > 0 ? {
|
|
27839
27839
|
summary: truncated ? summary.slice(0, COMPACTION_SUMMARY_MAX_CHARS) : summary,
|
|
27840
27840
|
...truncated ? { summaryTruncated: true } : {}
|
|
@@ -27844,13 +27844,13 @@ function createExecutorUpdates({
|
|
|
27844
27844
|
});
|
|
27845
27845
|
};
|
|
27846
27846
|
const applyCompactionUpdate = (event2) => {
|
|
27847
|
-
let
|
|
27848
|
-
if (
|
|
27847
|
+
let record3 = compactions.get(event2.compactionId);
|
|
27848
|
+
if (record3 === void 0) {
|
|
27849
27849
|
if (shared.manualCompaction !== void 0 && !shared.manualCompaction.adopted) {
|
|
27850
27850
|
shared.manualCompaction.adopted = true;
|
|
27851
|
-
|
|
27851
|
+
record3 = shared.manualCompaction;
|
|
27852
27852
|
} else {
|
|
27853
|
-
|
|
27853
|
+
record3 = {
|
|
27854
27854
|
snapshotId: randomId(),
|
|
27855
27855
|
trigger: "automatic",
|
|
27856
27856
|
startedAtMs: nowMs(),
|
|
@@ -27860,25 +27860,25 @@ function createExecutorUpdates({
|
|
|
27860
27860
|
adopted: false
|
|
27861
27861
|
};
|
|
27862
27862
|
}
|
|
27863
|
-
compactions.set(event2.compactionId,
|
|
27863
|
+
compactions.set(event2.compactionId, record3);
|
|
27864
27864
|
}
|
|
27865
|
-
if (event2.summary !== void 0)
|
|
27865
|
+
if (event2.summary !== void 0) record3.summary = event2.summary ?? void 0;
|
|
27866
27866
|
switch (event2.status) {
|
|
27867
27867
|
case "in_progress":
|
|
27868
|
-
if (!
|
|
27869
|
-
|
|
27870
|
-
emitCompactionState(
|
|
27868
|
+
if (!record3.announced) {
|
|
27869
|
+
record3.announced = true;
|
|
27870
|
+
emitCompactionState(record3, "compacting");
|
|
27871
27871
|
}
|
|
27872
27872
|
return;
|
|
27873
27873
|
case "completed":
|
|
27874
|
-
|
|
27875
|
-
|
|
27874
|
+
record3.announced = true;
|
|
27875
|
+
record3.finished = true;
|
|
27876
27876
|
compactions.delete(event2.compactionId);
|
|
27877
|
-
emitCompactionState(
|
|
27877
|
+
emitCompactionState(record3, "compacted");
|
|
27878
27878
|
return;
|
|
27879
27879
|
case "failed":
|
|
27880
27880
|
case "cancelled":
|
|
27881
|
-
|
|
27881
|
+
record3.finished = true;
|
|
27882
27882
|
compactions.delete(event2.compactionId);
|
|
27883
27883
|
emit({
|
|
27884
27884
|
type: "runtime.warning",
|
|
@@ -28034,9 +28034,9 @@ function createExecutorUpdates({
|
|
|
28034
28034
|
continue;
|
|
28035
28035
|
}
|
|
28036
28036
|
if (event2._tag === "CompactionSummaryChunk") {
|
|
28037
|
-
const
|
|
28038
|
-
if (
|
|
28039
|
-
|
|
28037
|
+
const record3 = compactions.get(event2.compactionId);
|
|
28038
|
+
if (record3 !== void 0 && !record3.finished) {
|
|
28039
|
+
record3.summary = (record3.summary ?? "") + event2.text;
|
|
28040
28040
|
}
|
|
28041
28041
|
continue;
|
|
28042
28042
|
}
|
|
@@ -28654,13 +28654,13 @@ function acpNativeSessionProcessMatcher(program, args) {
|
|
|
28654
28654
|
|
|
28655
28655
|
// ../../packages/ycodium-acp-executor/src/prompt-dispatch.ts
|
|
28656
28656
|
var dispatchAcpPrompt = (executor, input2) => {
|
|
28657
|
-
const { promise: dispatched, resolve:
|
|
28657
|
+
const { promise: dispatched, resolve: resolve5 } = Promise.withResolvers();
|
|
28658
28658
|
let written = false;
|
|
28659
28659
|
const finished = executor.prompt({
|
|
28660
28660
|
...input2,
|
|
28661
28661
|
onDispatched: (turnId) => {
|
|
28662
28662
|
written = true;
|
|
28663
|
-
|
|
28663
|
+
resolve5(turnId);
|
|
28664
28664
|
}
|
|
28665
28665
|
});
|
|
28666
28666
|
return Promise.race([
|
|
@@ -28675,8 +28675,8 @@ var dispatchAcpPrompt = (executor, input2) => {
|
|
|
28675
28675
|
};
|
|
28676
28676
|
|
|
28677
28677
|
// ../../packages/ycodium-acp-executor/src/thread-operations.ts
|
|
28678
|
-
var yieldTick = () => new Promise((
|
|
28679
|
-
setImmediate(
|
|
28678
|
+
var yieldTick = () => new Promise((resolve5) => {
|
|
28679
|
+
setImmediate(resolve5);
|
|
28680
28680
|
});
|
|
28681
28681
|
var nowIso = () => (/* @__PURE__ */ new Date()).toISOString();
|
|
28682
28682
|
function createAcpThreadOperations(options) {
|
|
@@ -28760,9 +28760,9 @@ function modelSelectionStringOption(selection, optionId) {
|
|
|
28760
28760
|
if (!Array.isArray(options)) return void 0;
|
|
28761
28761
|
for (const entry of options) {
|
|
28762
28762
|
if (typeof entry !== "object" || entry === null || Array.isArray(entry)) continue;
|
|
28763
|
-
const
|
|
28764
|
-
if (
|
|
28765
|
-
const value =
|
|
28763
|
+
const record3 = entry;
|
|
28764
|
+
if (record3["id"] !== optionId) continue;
|
|
28765
|
+
const value = record3["value"];
|
|
28766
28766
|
return typeof value === "string" ? value.trim() || void 0 : void 0;
|
|
28767
28767
|
}
|
|
28768
28768
|
return void 0;
|
|
@@ -28835,8 +28835,8 @@ var BEARER_TOKEN_PATTERN = /\bBearer\s+[A-Za-z0-9._\-+=/]+/gi;
|
|
|
28835
28835
|
var BASIC_AUTH_PATTERN = /\bAuthorization:\s*Basic\s+\S+/gi;
|
|
28836
28836
|
var API_KEY_HEADER_PATTERN = /\bx-api-key:\s*\S+/gi;
|
|
28837
28837
|
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;
|
|
28838
|
-
function redactStderrExcerpt(
|
|
28839
|
-
let result =
|
|
28838
|
+
function redactStderrExcerpt(text2, environment = process.env) {
|
|
28839
|
+
let result = text2.replaceAll("\0", "");
|
|
28840
28840
|
const homes = [environment["HOME"], environment["USERPROFILE"], NodeOS3.homedir()].filter(
|
|
28841
28841
|
(value) => typeof value === "string" && value.length > 1
|
|
28842
28842
|
);
|
|
@@ -28858,8 +28858,8 @@ function drainStderrTail(stderr) {
|
|
|
28858
28858
|
let timer;
|
|
28859
28859
|
await Promise.race([
|
|
28860
28860
|
drained,
|
|
28861
|
-
new Promise((
|
|
28862
|
-
timer = setTimeout(
|
|
28861
|
+
new Promise((resolve5) => {
|
|
28862
|
+
timer = setTimeout(resolve5, STDERR_SETTLE_MS);
|
|
28863
28863
|
})
|
|
28864
28864
|
]);
|
|
28865
28865
|
clearTimeout(timer);
|
|
@@ -28873,11 +28873,11 @@ function nodeStreamsFromHandle(handle, errors = ownErrors) {
|
|
|
28873
28873
|
for await (const chunk of handle.stdout) {
|
|
28874
28874
|
if (!readable.writable) return;
|
|
28875
28875
|
if (!readable.write(chunk)) {
|
|
28876
|
-
await new Promise((
|
|
28876
|
+
await new Promise((resolve5) => {
|
|
28877
28877
|
const onDone = () => {
|
|
28878
28878
|
readable.off("drain", onDone);
|
|
28879
28879
|
readable.off("close", onDone);
|
|
28880
|
-
|
|
28880
|
+
resolve5();
|
|
28881
28881
|
};
|
|
28882
28882
|
readable.once("drain", onDone);
|
|
28883
28883
|
readable.once("close", onDone);
|
|
@@ -28934,8 +28934,8 @@ async function raceStartAbort(promise2, signal) {
|
|
|
28934
28934
|
}
|
|
28935
28935
|
|
|
28936
28936
|
// ../../packages/ycodium-acp-executor/src/instance-kit.ts
|
|
28937
|
-
var yieldTick2 = () => new Promise((
|
|
28938
|
-
setImmediate(
|
|
28937
|
+
var yieldTick2 = () => new Promise((resolve5) => {
|
|
28938
|
+
setImmediate(resolve5);
|
|
28939
28939
|
});
|
|
28940
28940
|
var nowIso2 = () => (/* @__PURE__ */ new Date()).toISOString();
|
|
28941
28941
|
function createAcpThreadTable(log, beforeStopAll) {
|
|
@@ -29153,6 +29153,30 @@ function parseCliVersion(output2) {
|
|
|
29153
29153
|
}
|
|
29154
29154
|
var MAX_VERSION_OUTPUT_BYTES = 64 * 1024;
|
|
29155
29155
|
|
|
29156
|
+
// ../../packages/ycodium-jsonl-stream/src/sessionTranscript.ts
|
|
29157
|
+
var SESSION_IMPORT_ACTIVITY_TEXT_LIMIT = 32e3;
|
|
29158
|
+
function bounded(value, tail = false) {
|
|
29159
|
+
if (value.length <= SESSION_IMPORT_ACTIVITY_TEXT_LIMIT) return { text: value, truncated: false };
|
|
29160
|
+
const offset = tail ? value.length - SESSION_IMPORT_ACTIVITY_TEXT_LIMIT : SESSION_IMPORT_ACTIVITY_TEXT_LIMIT;
|
|
29161
|
+
const character = value.charCodeAt(offset);
|
|
29162
|
+
const previous = value.charCodeAt(offset - 1);
|
|
29163
|
+
const splitPair = character >= 56320 && character <= 57343 && previous >= 55296 && previous <= 56319;
|
|
29164
|
+
return {
|
|
29165
|
+
text: tail ? value.slice(offset + (splitPair ? 1 : 0)) : value.slice(0, offset - (splitPair ? 1 : 0)),
|
|
29166
|
+
truncated: true
|
|
29167
|
+
};
|
|
29168
|
+
}
|
|
29169
|
+
function inputPayload(input2) {
|
|
29170
|
+
if (input2 === void 0) return {};
|
|
29171
|
+
const result = bounded(input2);
|
|
29172
|
+
return { input: result.text, ...result.truncated ? { inputTruncated: true } : {} };
|
|
29173
|
+
}
|
|
29174
|
+
function outputPayload(output2) {
|
|
29175
|
+
if (output2 === void 0) return {};
|
|
29176
|
+
const result = bounded(output2, true);
|
|
29177
|
+
return { output: result.text, ...result.truncated ? { outputTruncated: true } : {} };
|
|
29178
|
+
}
|
|
29179
|
+
|
|
29156
29180
|
// ../../packages/ycodium-instance-config/src/launchArgs.ts
|
|
29157
29181
|
function tokenizeShellWords(value) {
|
|
29158
29182
|
const input2 = value.trim();
|
|
@@ -29295,8 +29319,8 @@ function questionTextFromContent(content) {
|
|
|
29295
29319
|
if (!isRecord8(entry) || entry["type"] !== "content") continue;
|
|
29296
29320
|
const inner = entry["content"];
|
|
29297
29321
|
if (!isRecord8(inner) || inner["type"] !== "text") continue;
|
|
29298
|
-
const
|
|
29299
|
-
if (typeof
|
|
29322
|
+
const text2 = inner["text"];
|
|
29323
|
+
if (typeof text2 === "string") parts.push(text2);
|
|
29300
29324
|
}
|
|
29301
29325
|
return parts.join("\n\n").trim();
|
|
29302
29326
|
}
|
|
@@ -29340,20 +29364,20 @@ function parseKimiContextWindow(contents) {
|
|
|
29340
29364
|
for (const line of contents.split("\n")) {
|
|
29341
29365
|
const trimmed2 = line.trim();
|
|
29342
29366
|
if (trimmed2.length === 0) continue;
|
|
29343
|
-
let
|
|
29367
|
+
let record3;
|
|
29344
29368
|
try {
|
|
29345
|
-
|
|
29369
|
+
record3 = JSON.parse(trimmed2);
|
|
29346
29370
|
} catch {
|
|
29347
29371
|
continue;
|
|
29348
29372
|
}
|
|
29349
|
-
if (!isRecord8(
|
|
29350
|
-
const type =
|
|
29373
|
+
if (!isRecord8(record3)) continue;
|
|
29374
|
+
const type = record3["type"];
|
|
29351
29375
|
if (type === "token_counting.turn_recorded" || type === "token_counting.measured") {
|
|
29352
|
-
usedTokens = positiveInt(
|
|
29376
|
+
usedTokens = positiveInt(record3["tokens"]) ?? usedTokens;
|
|
29353
29377
|
continue;
|
|
29354
29378
|
}
|
|
29355
29379
|
if (type === "llm.request") {
|
|
29356
|
-
maxTokens = positiveInt(
|
|
29380
|
+
maxTokens = positiveInt(record3["maxTokens"]) ?? maxTokens;
|
|
29357
29381
|
}
|
|
29358
29382
|
}
|
|
29359
29383
|
if (usedTokens === void 0) return void 0;
|
|
@@ -29484,13 +29508,13 @@ function observeKimiPromptFailure(homePath, acpSessionId) {
|
|
|
29484
29508
|
if (first !== "pending") return first;
|
|
29485
29509
|
const path = original ?? find();
|
|
29486
29510
|
if (!path) return void 0;
|
|
29487
|
-
return new Promise((
|
|
29511
|
+
return new Promise((resolve5) => {
|
|
29488
29512
|
let watcher;
|
|
29489
29513
|
const finish = (failure2) => {
|
|
29490
29514
|
clearTimeout(deadline);
|
|
29491
29515
|
signal.removeEventListener("abort", abort);
|
|
29492
29516
|
watcher?.close();
|
|
29493
|
-
|
|
29517
|
+
resolve5(failure2);
|
|
29494
29518
|
};
|
|
29495
29519
|
const abort = () => finish();
|
|
29496
29520
|
const check2 = () => {
|
|
@@ -29605,8 +29629,8 @@ function readKimiAuthState(resolvedHomePath) {
|
|
|
29605
29629
|
return "unreadable";
|
|
29606
29630
|
}
|
|
29607
29631
|
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return "unreadable";
|
|
29608
|
-
const
|
|
29609
|
-
return nonEmptyString(
|
|
29632
|
+
const record3 = parsed;
|
|
29633
|
+
return nonEmptyString(record3["refresh_token"]) || nonEmptyString(record3["access_token"]) ? "signed-in" : "signed-out";
|
|
29610
29634
|
}
|
|
29611
29635
|
|
|
29612
29636
|
// src/kimiQuota.ts
|
|
@@ -29618,9 +29642,9 @@ var TOKEN_EXPIRY_SKEW_MS = 3e4;
|
|
|
29618
29642
|
var asCount = (value) => {
|
|
29619
29643
|
const direct = asNumber(value);
|
|
29620
29644
|
if (direct !== null) return direct;
|
|
29621
|
-
const
|
|
29622
|
-
if (
|
|
29623
|
-
const parsed = Number(
|
|
29645
|
+
const text2 = asString3(value);
|
|
29646
|
+
if (text2 === null) return null;
|
|
29647
|
+
const parsed = Number(text2);
|
|
29624
29648
|
return Number.isFinite(parsed) ? parsed : null;
|
|
29625
29649
|
};
|
|
29626
29650
|
var clampPercent = (value) => Math.min(100, Math.max(0, value));
|
|
@@ -29630,11 +29654,11 @@ var expiryMs = (value) => {
|
|
|
29630
29654
|
return raw > 1e12 ? raw : raw * 1e3;
|
|
29631
29655
|
};
|
|
29632
29656
|
var extractKimiToken = (auth, nowMs) => {
|
|
29633
|
-
const
|
|
29634
|
-
if (
|
|
29635
|
-
const token = asString3(
|
|
29657
|
+
const record3 = asObject(auth);
|
|
29658
|
+
if (record3 === null) return null;
|
|
29659
|
+
const token = asString3(record3["access_token"]);
|
|
29636
29660
|
if (token === null) return null;
|
|
29637
|
-
const expiresAtMs = expiryMs(
|
|
29661
|
+
const expiresAtMs = expiryMs(record3["expires_at"]);
|
|
29638
29662
|
if (expiresAtMs === null) return token;
|
|
29639
29663
|
return expiresAtMs - nowMs < TOKEN_EXPIRY_SKEW_MS ? null : token;
|
|
29640
29664
|
};
|
|
@@ -29678,10 +29702,10 @@ var TIME_UNIT_MINUTES = {
|
|
|
29678
29702
|
TIME_UNIT_WEEK: 10080
|
|
29679
29703
|
};
|
|
29680
29704
|
var kimiWindowSpan = (window) => {
|
|
29681
|
-
const
|
|
29682
|
-
if (
|
|
29683
|
-
const duration3 = asCount(
|
|
29684
|
-
const unit = asString3(
|
|
29705
|
+
const record3 = asObject(window);
|
|
29706
|
+
if (record3 === null) return null;
|
|
29707
|
+
const duration3 = asCount(record3["duration"]);
|
|
29708
|
+
const unit = asString3(record3["timeUnit"]);
|
|
29685
29709
|
const minutesPerUnit = unit === null ? void 0 : TIME_UNIT_MINUTES[unit];
|
|
29686
29710
|
if (duration3 === null || duration3 <= 0 || minutesPerUnit === void 0) return null;
|
|
29687
29711
|
const minutes = duration3 * minutesPerUnit;
|
|
@@ -29689,18 +29713,18 @@ var kimiWindowSpan = (window) => {
|
|
|
29689
29713
|
return { label, windowMs: minutes * 6e4 };
|
|
29690
29714
|
};
|
|
29691
29715
|
var windowFrom = (id, label, detail, windowMs) => {
|
|
29692
|
-
const
|
|
29693
|
-
if (
|
|
29694
|
-
const limit = asCount(
|
|
29716
|
+
const record3 = asObject(detail);
|
|
29717
|
+
if (record3 === null) return null;
|
|
29718
|
+
const limit = asCount(record3["limit"]);
|
|
29695
29719
|
if (limit === null || limit <= 0) return null;
|
|
29696
|
-
const remaining = asCount(
|
|
29697
|
-
const used = asCount(
|
|
29720
|
+
const remaining = asCount(record3["remaining"]);
|
|
29721
|
+
const used = asCount(record3["used"]) ?? (remaining === null ? null : limit - remaining);
|
|
29698
29722
|
if (used === null) return null;
|
|
29699
29723
|
return {
|
|
29700
29724
|
id,
|
|
29701
29725
|
label,
|
|
29702
29726
|
usedPercent: clampPercent(used / limit * 100),
|
|
29703
|
-
resetsAt: asString3(
|
|
29727
|
+
resetsAt: asString3(record3["resetTime"]),
|
|
29704
29728
|
...windowMs === void 0 ? {} : { windowMs }
|
|
29705
29729
|
};
|
|
29706
29730
|
};
|
|
@@ -29928,15 +29952,15 @@ var createKimiTokenReader = (input2) => {
|
|
|
29928
29952
|
}
|
|
29929
29953
|
scannedFiles += 1;
|
|
29930
29954
|
malformedRecords += memo2.malformed;
|
|
29931
|
-
for (const
|
|
29932
|
-
if (
|
|
29933
|
-
if (!hasTokens(
|
|
29934
|
-
seen.add(
|
|
29955
|
+
for (const record3 of memo2.records) {
|
|
29956
|
+
if (record3.timeMs < sinceMs || record3.timeMs >= untilMs) continue;
|
|
29957
|
+
if (!hasTokens(record3.totals) || seen.has(record3.key)) continue;
|
|
29958
|
+
seen.add(record3.key);
|
|
29935
29959
|
records.push({
|
|
29936
|
-
at: new Date(
|
|
29937
|
-
model:
|
|
29960
|
+
at: new Date(record3.timeMs).toISOString(),
|
|
29961
|
+
model: record3.model,
|
|
29938
29962
|
sessionId,
|
|
29939
|
-
totals:
|
|
29963
|
+
totals: record3.totals
|
|
29940
29964
|
});
|
|
29941
29965
|
}
|
|
29942
29966
|
}
|
|
@@ -30230,8 +30254,8 @@ function describe3(kind, input2, previous) {
|
|
|
30230
30254
|
...model === void 0 ? {} : { model }
|
|
30231
30255
|
};
|
|
30232
30256
|
}
|
|
30233
|
-
function splitResult(
|
|
30234
|
-
const lines =
|
|
30257
|
+
function splitResult(text2) {
|
|
30258
|
+
const lines = text2.split(/\r?\n/u);
|
|
30235
30259
|
const header = /* @__PURE__ */ new Map();
|
|
30236
30260
|
let index = 0;
|
|
30237
30261
|
for (; index < lines.length; index += 1) {
|
|
@@ -30245,15 +30269,15 @@ function stripTrailingHints(body) {
|
|
|
30245
30269
|
const cuts = ["\nresume_hint: ", "\nnext_step: "].map((marker) => body.lastIndexOf(marker)).filter((position) => position >= 0);
|
|
30246
30270
|
return (cuts.length === 0 ? body : body.slice(0, Math.min(...cuts))).trim();
|
|
30247
30271
|
}
|
|
30248
|
-
function parseAgentResult(
|
|
30249
|
-
if (
|
|
30272
|
+
function parseAgentResult(text2, isError) {
|
|
30273
|
+
if (text2 === void 0)
|
|
30250
30274
|
return {
|
|
30251
30275
|
kind: isError ? "failed" : "completed",
|
|
30252
30276
|
summary: void 0,
|
|
30253
30277
|
role: void 0,
|
|
30254
30278
|
agentId: void 0
|
|
30255
30279
|
};
|
|
30256
|
-
const { header, body } = splitResult(
|
|
30280
|
+
const { header, body } = splitResult(text2);
|
|
30257
30281
|
const role = trimmed(header.get("actual_subagent_type"));
|
|
30258
30282
|
const agentId = trimmed(header.get("agent_id"));
|
|
30259
30283
|
const status = header.get("status");
|
|
@@ -30263,7 +30287,7 @@ function parseAgentResult(text, isError) {
|
|
|
30263
30287
|
if (isError || status === "failed") {
|
|
30264
30288
|
return {
|
|
30265
30289
|
kind: header.get("stop_reason") === "cancelled" ? "cancelled" : "failed",
|
|
30266
|
-
summary: trimmed(stripTrailingHints(body)) ?? trimmed(
|
|
30290
|
+
summary: trimmed(stripTrailingHints(body)) ?? trimmed(text2),
|
|
30267
30291
|
role,
|
|
30268
30292
|
agentId
|
|
30269
30293
|
};
|
|
@@ -30275,21 +30299,21 @@ function parseAgentResult(text, isError) {
|
|
|
30275
30299
|
const summary = [notice === void 0 ? void 0 : `notice: ${notice}`, answer].filter((part) => part !== void 0).join("\n\n");
|
|
30276
30300
|
return { kind: "completed", summary: trimmed(summary), role, agentId };
|
|
30277
30301
|
}
|
|
30278
|
-
function parseSwarmResult(
|
|
30279
|
-
const inner =
|
|
30302
|
+
function parseSwarmResult(text2, isError) {
|
|
30303
|
+
const inner = text2 === void 0 ? void 0 : /<summary>([\s\S]*?)<\/summary>/u.exec(text2)?.[1];
|
|
30280
30304
|
return {
|
|
30281
30305
|
kind: isError ? "failed" : "completed",
|
|
30282
|
-
summary: trimmed(inner) ?? trimmed(
|
|
30306
|
+
summary: trimmed(inner) ?? trimmed(text2),
|
|
30283
30307
|
role: void 0,
|
|
30284
30308
|
agentId: void 0
|
|
30285
30309
|
};
|
|
30286
30310
|
}
|
|
30287
30311
|
function resolveOutcome(call, kind) {
|
|
30288
30312
|
if (call.status !== "completed" && call.status !== "failed") return void 0;
|
|
30289
|
-
const
|
|
30313
|
+
const text2 = typeof call.rawOutput === "string" ? trimmed(call.rawOutput) : void 0;
|
|
30290
30314
|
const isError = call.status === "failed";
|
|
30291
|
-
if (
|
|
30292
|
-
const outcome = kind === "swarm" ? parseSwarmResult(
|
|
30315
|
+
if (text2 === void 0 && !isError) return void 0;
|
|
30316
|
+
const outcome = kind === "swarm" ? parseSwarmResult(text2, isError) : parseAgentResult(text2, isError);
|
|
30293
30317
|
const ids = {
|
|
30294
30318
|
...outcome.role === void 0 ? {} : { role: outcome.role },
|
|
30295
30319
|
...outcome.agentId === void 0 ? {} : { agentRef: outcome.agentId }
|
|
@@ -30328,11 +30352,11 @@ var kimiPermissionStatement = ({
|
|
|
30328
30352
|
if (permissionRequest.kind !== "execute" || request.toolCall.rawInput !== void 0 || statement.command !== void 0)
|
|
30329
30353
|
return statement;
|
|
30330
30354
|
const texts = [permissionRequest.toolCall?.contentText, previousToolCall?.contentText];
|
|
30331
|
-
for (const
|
|
30332
|
-
if (!
|
|
30355
|
+
for (const text2 of texts) {
|
|
30356
|
+
if (!text2) continue;
|
|
30333
30357
|
let input2;
|
|
30334
30358
|
try {
|
|
30335
|
-
input2 = JSON.parse(
|
|
30359
|
+
input2 = JSON.parse(text2);
|
|
30336
30360
|
} catch {
|
|
30337
30361
|
continue;
|
|
30338
30362
|
}
|
|
@@ -30343,6 +30367,287 @@ var kimiPermissionStatement = ({
|
|
|
30343
30367
|
return statement;
|
|
30344
30368
|
};
|
|
30345
30369
|
|
|
30370
|
+
// src/nativeSessions.ts
|
|
30371
|
+
import * as NodeFS7 from "node:fs";
|
|
30372
|
+
import * as NodeFSP from "node:fs/promises";
|
|
30373
|
+
import * as NodePath8 from "node:path";
|
|
30374
|
+
import * as NodeReadline from "node:readline";
|
|
30375
|
+
var sessionIdPattern = /^[a-zA-Z0-9_-]+$/u;
|
|
30376
|
+
function record2(value) {
|
|
30377
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
30378
|
+
}
|
|
30379
|
+
var text = (value) => typeof value === "string" && value.trim().length > 0 ? value : void 0;
|
|
30380
|
+
function parseRecord(raw) {
|
|
30381
|
+
try {
|
|
30382
|
+
return record2(JSON.parse(raw));
|
|
30383
|
+
} catch {
|
|
30384
|
+
return void 0;
|
|
30385
|
+
}
|
|
30386
|
+
}
|
|
30387
|
+
function missingFile(error62) {
|
|
30388
|
+
return error62.code === "ENOENT";
|
|
30389
|
+
}
|
|
30390
|
+
async function directories(path) {
|
|
30391
|
+
try {
|
|
30392
|
+
return (await NodeFSP.readdir(path, { withFileTypes: true })).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
|
|
30393
|
+
} catch (error62) {
|
|
30394
|
+
if (missingFile(error62)) return [];
|
|
30395
|
+
throw error62;
|
|
30396
|
+
}
|
|
30397
|
+
}
|
|
30398
|
+
function readableStoragePath(home) {
|
|
30399
|
+
try {
|
|
30400
|
+
return NodeFS7.realpathSync.native(home);
|
|
30401
|
+
} catch {
|
|
30402
|
+
return home;
|
|
30403
|
+
}
|
|
30404
|
+
}
|
|
30405
|
+
function isAbsoluteDirectory(path) {
|
|
30406
|
+
if (!NodePath8.isAbsolute(path)) return false;
|
|
30407
|
+
if (NodePath8.sep !== "\\") return true;
|
|
30408
|
+
const { root } = NodePath8.parse(path);
|
|
30409
|
+
return root.length > 1;
|
|
30410
|
+
}
|
|
30411
|
+
var directoryKey = (directory) => {
|
|
30412
|
+
const resolved = NodePath8.resolve(directory);
|
|
30413
|
+
return NodePath8.sep === "\\" ? resolved.toLowerCase() : resolved;
|
|
30414
|
+
};
|
|
30415
|
+
async function findSessions(home, cwd, signal, nativeSessionId) {
|
|
30416
|
+
signal?.throwIfAborted();
|
|
30417
|
+
const expectedCwd = directoryKey(cwd);
|
|
30418
|
+
const result = [];
|
|
30419
|
+
const root = NodePath8.join(home, "sessions");
|
|
30420
|
+
for (const workspace of await directories(root)) {
|
|
30421
|
+
if (workspace.startsWith(".")) continue;
|
|
30422
|
+
const workspacePath = NodePath8.join(root, workspace);
|
|
30423
|
+
for (const id of await directories(workspacePath)) {
|
|
30424
|
+
signal?.throwIfAborted();
|
|
30425
|
+
if (!sessionIdPattern.test(id) || nativeSessionId !== void 0 && nativeSessionId !== id)
|
|
30426
|
+
continue;
|
|
30427
|
+
const sessionPath = NodePath8.join(workspacePath, id);
|
|
30428
|
+
const statePath = NodePath8.join(sessionPath, "state.json");
|
|
30429
|
+
try {
|
|
30430
|
+
if (!(await NodeFSP.lstat(statePath)).isFile()) continue;
|
|
30431
|
+
const state = parseRecord(await NodeFSP.readFile(statePath, { encoding: "utf8", signal }));
|
|
30432
|
+
if (state?.id !== id || typeof state.cwd !== "string" || !isAbsoluteDirectory(state.cwd))
|
|
30433
|
+
continue;
|
|
30434
|
+
const relative2 = NodePath8.relative(expectedCwd, directoryKey(state.cwd));
|
|
30435
|
+
if (relative2 !== "" && (nativeSessionId !== void 0 || relative2 === ".." || relative2.startsWith(`..${NodePath8.sep}`) || NodePath8.isAbsolute(relative2)))
|
|
30436
|
+
continue;
|
|
30437
|
+
const wire = NodePath8.join(sessionPath, "agents", "main", "wire.jsonl");
|
|
30438
|
+
if (!(await NodeFSP.lstat(NodePath8.join(sessionPath, "agents"))).isDirectory() || !(await NodeFSP.lstat(NodePath8.dirname(wire))).isDirectory() || !(await NodeFSP.lstat(wire)).isFile())
|
|
30439
|
+
continue;
|
|
30440
|
+
result.push({
|
|
30441
|
+
id,
|
|
30442
|
+
cwd: state.cwd,
|
|
30443
|
+
title: text(state.title) ?? text(record2(state.custom)?.title) ?? null,
|
|
30444
|
+
updatedAt: typeof state.updatedAt === "number" && Number.isFinite(state.updatedAt) ? state.updatedAt : 0,
|
|
30445
|
+
archived: state.archived === true,
|
|
30446
|
+
wire
|
|
30447
|
+
});
|
|
30448
|
+
} catch (error62) {
|
|
30449
|
+
if (!missingFile(error62)) throw error62;
|
|
30450
|
+
}
|
|
30451
|
+
}
|
|
30452
|
+
}
|
|
30453
|
+
signal?.throwIfAborted();
|
|
30454
|
+
return result;
|
|
30455
|
+
}
|
|
30456
|
+
async function readTranscript(session, signal, summaryOnly = false) {
|
|
30457
|
+
const stream = NodeFS7.createReadStream(session.wire, { signal });
|
|
30458
|
+
const lines = NodeReadline.createInterface({ input: stream, crlfDelay: Infinity });
|
|
30459
|
+
const messages = [];
|
|
30460
|
+
const activities = [];
|
|
30461
|
+
const tools = /* @__PURE__ */ new Map();
|
|
30462
|
+
let model;
|
|
30463
|
+
let turnCount = 0;
|
|
30464
|
+
let hasMessages = false;
|
|
30465
|
+
let preview = null;
|
|
30466
|
+
let nativeTurnId;
|
|
30467
|
+
let sourceOrder = 0;
|
|
30468
|
+
const parts = /* @__PURE__ */ new Map();
|
|
30469
|
+
try {
|
|
30470
|
+
for await (const line of lines) {
|
|
30471
|
+
signal?.throwIfAborted();
|
|
30472
|
+
sourceOrder += 1;
|
|
30473
|
+
const row = parseRecord(line);
|
|
30474
|
+
if (!row || row.agentId !== "main") continue;
|
|
30475
|
+
const timestamp = typeof row.time === "number" && Math.abs(row.time) <= 864e13 ? row.time : 0;
|
|
30476
|
+
const createdAt = new Date(timestamp).toISOString();
|
|
30477
|
+
if (row.type === "profile.bind") {
|
|
30478
|
+
model = text(row.modelAlias) ?? model;
|
|
30479
|
+
} else if (row.type === "turn.prompt" && typeof row.turnId === "number") {
|
|
30480
|
+
nativeTurnId = String(row.turnId);
|
|
30481
|
+
const sourceId = text(row.promptId);
|
|
30482
|
+
if (sourceId === void 0 || record2(row.origin)?.kind !== "user") continue;
|
|
30483
|
+
const content = Array.isArray(row.input) ? row.input.flatMap((part) => {
|
|
30484
|
+
const block = record2(part);
|
|
30485
|
+
return block?.type === "text" && typeof block.text === "string" ? [block.text] : [];
|
|
30486
|
+
}).join("\n\n") : "";
|
|
30487
|
+
turnCount += 1;
|
|
30488
|
+
if (content.trim().length === 0) continue;
|
|
30489
|
+
hasMessages = true;
|
|
30490
|
+
preview ??= content.slice(0, 240);
|
|
30491
|
+
if (!summaryOnly)
|
|
30492
|
+
messages.push({
|
|
30493
|
+
sourceId,
|
|
30494
|
+
sourceOrder,
|
|
30495
|
+
role: "user",
|
|
30496
|
+
text: content,
|
|
30497
|
+
createdAt,
|
|
30498
|
+
nativeTurnId
|
|
30499
|
+
});
|
|
30500
|
+
} else if (row.type === "context.append_loop_event") {
|
|
30501
|
+
const event2 = record2(row.event);
|
|
30502
|
+
const part = record2(event2?.part);
|
|
30503
|
+
const stepId = text(event2?.stepUuid);
|
|
30504
|
+
const isTextPart = event2?.type === "content.part" && part?.type === "text" && stepId !== void 0 && typeof part.text === "string";
|
|
30505
|
+
if (isTextPart) hasMessages = true;
|
|
30506
|
+
if (summaryOnly) continue;
|
|
30507
|
+
const identity = {
|
|
30508
|
+
sourceOrder,
|
|
30509
|
+
createdAt,
|
|
30510
|
+
...nativeTurnId === void 0 ? {} : { nativeTurnId },
|
|
30511
|
+
...model === void 0 ? {} : { model }
|
|
30512
|
+
};
|
|
30513
|
+
const toolCallId = text(event2?.toolCallId);
|
|
30514
|
+
if (toolCallId !== void 0 && event2?.type === "tool.call") {
|
|
30515
|
+
const sourceId2 = text(event2.uuid);
|
|
30516
|
+
if (sourceId2 === void 0) continue;
|
|
30517
|
+
const name = text(event2.name) ?? "Tool";
|
|
30518
|
+
const command = text(record2(event2.args)?.command);
|
|
30519
|
+
const input2 = command ?? (event2.args === void 0 ? void 0 : JSON.stringify(event2.args));
|
|
30520
|
+
const activity = {
|
|
30521
|
+
...identity,
|
|
30522
|
+
sourceId: `tool:${sourceId2}`,
|
|
30523
|
+
kind: "tool.started",
|
|
30524
|
+
tone: "tool",
|
|
30525
|
+
summary: name,
|
|
30526
|
+
payload: {
|
|
30527
|
+
toolCallId,
|
|
30528
|
+
toolName: name,
|
|
30529
|
+
itemType: record2(event2.display)?.kind === "command" ? "command_execution" : "dynamic_tool_call",
|
|
30530
|
+
startedAt: createdAt,
|
|
30531
|
+
...inputPayload(input2)
|
|
30532
|
+
}
|
|
30533
|
+
};
|
|
30534
|
+
activities.push(activity);
|
|
30535
|
+
tools.set(sourceId2, activity);
|
|
30536
|
+
} else if (toolCallId !== void 0 && event2?.type === "tool.result") {
|
|
30537
|
+
const parent = text(event2.parentUuid);
|
|
30538
|
+
const start = parent === void 0 ? void 0 : tools.get(parent);
|
|
30539
|
+
if (!start) continue;
|
|
30540
|
+
const result = record2(event2.result);
|
|
30541
|
+
const status = result?.isError === true ? "failed" : "completed";
|
|
30542
|
+
const output2 = text(result?.output);
|
|
30543
|
+
activities.push({
|
|
30544
|
+
...identity,
|
|
30545
|
+
sourceId: `${start.sourceId}:result`,
|
|
30546
|
+
kind: "tool.completed",
|
|
30547
|
+
tone: status === "failed" ? "error" : "tool",
|
|
30548
|
+
summary: start.summary,
|
|
30549
|
+
payload: {
|
|
30550
|
+
...start.payload,
|
|
30551
|
+
status,
|
|
30552
|
+
...outputPayload(output2)
|
|
30553
|
+
}
|
|
30554
|
+
});
|
|
30555
|
+
}
|
|
30556
|
+
if (event2?.type !== "content.part" || part?.type !== "text" || stepId === void 0 || typeof part.text !== "string")
|
|
30557
|
+
continue;
|
|
30558
|
+
const sourceId = `step:${stepId}`;
|
|
30559
|
+
const previous = parts.get(sourceId);
|
|
30560
|
+
if (previous) previous.text += part.text;
|
|
30561
|
+
else {
|
|
30562
|
+
const message = {
|
|
30563
|
+
role: "assistant",
|
|
30564
|
+
sourceId,
|
|
30565
|
+
sourceOrder,
|
|
30566
|
+
text: part.text,
|
|
30567
|
+
createdAt,
|
|
30568
|
+
...nativeTurnId === void 0 ? {} : { nativeTurnId },
|
|
30569
|
+
...model === void 0 ? {} : { model }
|
|
30570
|
+
};
|
|
30571
|
+
messages.push(message);
|
|
30572
|
+
parts.set(sourceId, message);
|
|
30573
|
+
}
|
|
30574
|
+
}
|
|
30575
|
+
}
|
|
30576
|
+
signal?.throwIfAborted();
|
|
30577
|
+
} finally {
|
|
30578
|
+
lines.close();
|
|
30579
|
+
stream.destroy();
|
|
30580
|
+
}
|
|
30581
|
+
return { messages, activities, turnCount, hasMessages, preview, model: model ?? null };
|
|
30582
|
+
}
|
|
30583
|
+
function createKimiNativeSessions(home, resumeSchemaVersion) {
|
|
30584
|
+
const storageKey = isAbsoluteDirectory(home) ? "kimi:" + directoryKey(readableStoragePath(home)) : void 0;
|
|
30585
|
+
const importHome = () => {
|
|
30586
|
+
if (!storageKey)
|
|
30587
|
+
throw new Error("Kimi terminal import requires an absolute account directory.");
|
|
30588
|
+
return home;
|
|
30589
|
+
};
|
|
30590
|
+
return {
|
|
30591
|
+
...storageKey === void 0 ? {} : { storageKey },
|
|
30592
|
+
scan: async ({
|
|
30593
|
+
directory,
|
|
30594
|
+
signal
|
|
30595
|
+
}) => {
|
|
30596
|
+
const sessions = (await findSessions(importHome(), directory, signal)).filter((session) => !session.archived).sort((left, right) => right.updatedAt - left.updatedAt);
|
|
30597
|
+
const candidates = [];
|
|
30598
|
+
for (const session of sessions) {
|
|
30599
|
+
try {
|
|
30600
|
+
const {
|
|
30601
|
+
hasMessages,
|
|
30602
|
+
preview: prompt,
|
|
30603
|
+
model,
|
|
30604
|
+
turnCount
|
|
30605
|
+
} = await readTranscript(session, signal, true);
|
|
30606
|
+
if (!hasMessages) continue;
|
|
30607
|
+
candidates.push({
|
|
30608
|
+
nativeSessionId: session.id,
|
|
30609
|
+
cwd: session.cwd,
|
|
30610
|
+
title: session.title ?? prompt?.slice(0, 160) ?? null,
|
|
30611
|
+
preview: prompt?.slice(0, 240) ?? null,
|
|
30612
|
+
model,
|
|
30613
|
+
turnCount,
|
|
30614
|
+
updatedAt: session.updatedAt,
|
|
30615
|
+
availability: "importable",
|
|
30616
|
+
openElsewhere: false
|
|
30617
|
+
});
|
|
30618
|
+
} catch (error62) {
|
|
30619
|
+
if (!missingFile(error62)) throw error62;
|
|
30620
|
+
}
|
|
30621
|
+
}
|
|
30622
|
+
return { candidates };
|
|
30623
|
+
},
|
|
30624
|
+
readImport: async ({
|
|
30625
|
+
nativeSessionId,
|
|
30626
|
+
cwd,
|
|
30627
|
+
signal
|
|
30628
|
+
}) => {
|
|
30629
|
+
signal?.throwIfAborted();
|
|
30630
|
+
if (cwd === void 0 || !isAbsoluteDirectory(cwd)) {
|
|
30631
|
+
throw new Error("Kimi session import requires an absolute working directory.");
|
|
30632
|
+
}
|
|
30633
|
+
const matches = await findSessions(importHome(), cwd, signal, nativeSessionId);
|
|
30634
|
+
const session = matches[0];
|
|
30635
|
+
if (matches.length !== 1 || session === void 0)
|
|
30636
|
+
throw new Error("Kimi session was not found uniquely in the requested working directory.");
|
|
30637
|
+
const { messages, activities, model } = await readTranscript(session, signal);
|
|
30638
|
+
return {
|
|
30639
|
+
resumeCursor: { schemaVersion: resumeSchemaVersion, sessionId: session.id },
|
|
30640
|
+
title: session.title ?? messages.find((message) => message.role === "user")?.text.slice(0, 160) ?? null,
|
|
30641
|
+
model,
|
|
30642
|
+
messages,
|
|
30643
|
+
activities,
|
|
30644
|
+
availableMessages: messages.length,
|
|
30645
|
+
availableActivities: activities.length
|
|
30646
|
+
};
|
|
30647
|
+
}
|
|
30648
|
+
};
|
|
30649
|
+
}
|
|
30650
|
+
|
|
30346
30651
|
// src/kimiInstance.ts
|
|
30347
30652
|
var RESUME_SCHEMA_VERSION = 1;
|
|
30348
30653
|
var CLIENT_INFO = { name: "ycodium-agent-kimi", version: "0.1.0" };
|
|
@@ -30375,7 +30680,29 @@ var createKimiInstance = (config2, host) => {
|
|
|
30375
30680
|
turnSelection: (selection) => readTurnSelection(selection, ACP_EFFORT_OPTION_ID)
|
|
30376
30681
|
});
|
|
30377
30682
|
const usageHome = kimiEffectiveHome(resolveHomePath(recipe), process.env[recipe.homeEnvVar]);
|
|
30683
|
+
const sessionHome = homeLaunchEnv(recipe, recipe.homePath).KIMI_CODE_HOME ?? process.env.KIMI_CODE_HOME;
|
|
30684
|
+
const sessions = createKimiNativeSessions(
|
|
30685
|
+
kimiAccountHome(sessionHome?.trim() ?? ""),
|
|
30686
|
+
RESUME_SCHEMA_VERSION
|
|
30687
|
+
);
|
|
30378
30688
|
const instance = {
|
|
30689
|
+
sessions: {
|
|
30690
|
+
...sessions,
|
|
30691
|
+
scan: ({ projectId, directory, signal }) => sessions.scan({ directory: directory ?? host.workspacePath(projectId), signal }),
|
|
30692
|
+
read: async (input2) => {
|
|
30693
|
+
const imported = await sessions.readImport(input2);
|
|
30694
|
+
return {
|
|
30695
|
+
nativeSessionId: input2.nativeSessionId,
|
|
30696
|
+
model: imported.model,
|
|
30697
|
+
resumeCursor: imported.resumeCursor,
|
|
30698
|
+
messages: imported.messages.map(({ role, text: text2, createdAt }) => ({
|
|
30699
|
+
role,
|
|
30700
|
+
text: text2,
|
|
30701
|
+
createdAt: Date.parse(createdAt)
|
|
30702
|
+
}))
|
|
30703
|
+
};
|
|
30704
|
+
}
|
|
30705
|
+
},
|
|
30379
30706
|
probe: async (signal) => {
|
|
30380
30707
|
if (recipe.binaryPath.length === 0) {
|
|
30381
30708
|
return acpProgramNotConfigured("Kimi Code program path is not configured");
|
|
@@ -30591,7 +30918,7 @@ var index_default = definePlugin({
|
|
|
30591
30918
|
"KIMI_CODE_HOME",
|
|
30592
30919
|
request,
|
|
30593
30920
|
process.env,
|
|
30594
|
-
(value) => value === void 0 ?
|
|
30921
|
+
(value) => value === void 0 ? NodePath9.join(NodeOS7.homedir(), ".kimi-code") : NodePath9.resolve(expandHomePath(value))
|
|
30595
30922
|
)
|
|
30596
30923
|
};
|
|
30597
30924
|
}
|