@ycodium-ai/agent-kimi 0.2.5407 → 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 +6 -0
- package/dist/index.js +768 -319
- package/package.json +6 -5
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,
|
|
@@ -204,7 +204,7 @@ function approvalOutcomeForDecision(decision, optionId) {
|
|
|
204
204
|
var UnboundedEventStream = class {
|
|
205
205
|
subscribers = /* @__PURE__ */ new Set();
|
|
206
206
|
closed = false;
|
|
207
|
-
publish(
|
|
207
|
+
publish(event2) {
|
|
208
208
|
if (this.closed) {
|
|
209
209
|
return;
|
|
210
210
|
}
|
|
@@ -212,7 +212,7 @@ var UnboundedEventStream = class {
|
|
|
212
212
|
if (subscriber.closed) {
|
|
213
213
|
continue;
|
|
214
214
|
}
|
|
215
|
-
subscriber.queue.push(
|
|
215
|
+
subscriber.queue.push(event2);
|
|
216
216
|
const wake = subscriber.wake;
|
|
217
217
|
if (wake) {
|
|
218
218
|
subscriber.wake = void 0;
|
|
@@ -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
|
};
|
|
@@ -25126,8 +25126,8 @@ function createAcpConnection(options) {
|
|
|
25126
25126
|
releaseIdleWaiters();
|
|
25127
25127
|
}
|
|
25128
25128
|
};
|
|
25129
|
-
const log = (
|
|
25130
|
-
options.logger?.(
|
|
25129
|
+
const log = (event2) => {
|
|
25130
|
+
options.logger?.(event2);
|
|
25131
25131
|
};
|
|
25132
25132
|
const writeMessage = async (message) => {
|
|
25133
25133
|
log({ direction: "outgoing", stage: "decoded", payload: message });
|
|
@@ -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() {
|
|
@@ -25578,9 +25578,9 @@ function createExecutorLifecycle({
|
|
|
25578
25578
|
if (targetTurnId !== void 0) {
|
|
25579
25579
|
interruptedTurnIds.add(targetTurnId);
|
|
25580
25580
|
}
|
|
25581
|
-
const
|
|
25582
|
-
if (
|
|
25583
|
-
|
|
25581
|
+
const waiting = shared.localPromptWait;
|
|
25582
|
+
if (waiting !== void 0 && (targetTurnId === void 0 || waiting.turnId === targetTurnId)) {
|
|
25583
|
+
waiting.stop();
|
|
25584
25584
|
}
|
|
25585
25585
|
settleAllApprovals("cancel");
|
|
25586
25586
|
settleAllUserInputs();
|
|
@@ -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();
|
|
@@ -25693,13 +25693,14 @@ function createExecutorLifecycle({
|
|
|
25693
25693
|
if (disposing) return disposing;
|
|
25694
25694
|
shared.disposing = true;
|
|
25695
25695
|
disposing = (async () => {
|
|
25696
|
+
shared.localPromptWait?.stop();
|
|
25696
25697
|
if (exitCode !== void 0) {
|
|
25697
25698
|
let timer;
|
|
25698
25699
|
await Promise.race([
|
|
25699
25700
|
connection.closed.catch(() => void 0),
|
|
25700
|
-
new Promise((
|
|
25701
|
+
new Promise((resolve5) => {
|
|
25701
25702
|
timer = setTimeout(
|
|
25702
|
-
|
|
25703
|
+
resolve5,
|
|
25703
25704
|
options.resultDrainTimeoutMs ?? DEFAULT_RESULT_DRAIN_TIMEOUT_MS
|
|
25704
25705
|
);
|
|
25705
25706
|
})
|
|
@@ -25768,10 +25769,10 @@ function selectAutoApprovedAcpPermissionOption(request) {
|
|
|
25768
25769
|
}
|
|
25769
25770
|
function parseAcpResumeCursor(raw, schemaVersion) {
|
|
25770
25771
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) return void 0;
|
|
25771
|
-
const
|
|
25772
|
-
if (
|
|
25773
|
-
if (typeof
|
|
25774
|
-
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() };
|
|
25775
25776
|
}
|
|
25776
25777
|
function acpPromptSettlementBelongsToContext(input2) {
|
|
25777
25778
|
return input2.liveAcpSessionId === input2.expectedAcpSessionId && (input2.liveActiveTurnId === input2.turnId || input2.liveSessionActiveTurnId === input2.turnId);
|
|
@@ -25780,18 +25781,18 @@ function isAcpRequestPermissionParams(value) {
|
|
|
25780
25781
|
if (typeof value !== "object" || value === null) {
|
|
25781
25782
|
return false;
|
|
25782
25783
|
}
|
|
25783
|
-
const
|
|
25784
|
-
if (typeof
|
|
25784
|
+
const record3 = value;
|
|
25785
|
+
if (typeof record3["sessionId"] !== "string") {
|
|
25785
25786
|
return false;
|
|
25786
25787
|
}
|
|
25787
|
-
const toolCall =
|
|
25788
|
+
const toolCall = record3["toolCall"];
|
|
25788
25789
|
if (typeof toolCall !== "object" || toolCall === null) {
|
|
25789
25790
|
return false;
|
|
25790
25791
|
}
|
|
25791
25792
|
if (typeof toolCall["toolCallId"] !== "string") {
|
|
25792
25793
|
return false;
|
|
25793
25794
|
}
|
|
25794
|
-
return Array.isArray(
|
|
25795
|
+
return Array.isArray(record3["options"]);
|
|
25795
25796
|
}
|
|
25796
25797
|
|
|
25797
25798
|
// ../../packages/ycodium-acp-executor/src/apply-effort.ts
|
|
@@ -26232,7 +26233,7 @@ function createExecutorPrompt({
|
|
|
26232
26233
|
promptResults.forget(input2.turnId);
|
|
26233
26234
|
return true;
|
|
26234
26235
|
};
|
|
26235
|
-
const sendPromptRpc = async (sessionId, promptParts, onWritten,
|
|
26236
|
+
const sendPromptRpc = async (sessionId, promptParts, onWritten, record3) => {
|
|
26236
26237
|
const settlementHooks = hooks.promptSettlement;
|
|
26237
26238
|
const promptKey = settlementHooks === void 0 ? void 0 : randomId();
|
|
26238
26239
|
const pending = connection.begin(
|
|
@@ -26242,7 +26243,7 @@ function createExecutorPrompt({
|
|
|
26242
26243
|
prompt: promptParts,
|
|
26243
26244
|
...settlementHooks !== void 0 && promptKey !== void 0 ? settlementHooks.requestFields(promptKey) : {}
|
|
26244
26245
|
},
|
|
26245
|
-
|
|
26246
|
+
record3?.promptId
|
|
26246
26247
|
);
|
|
26247
26248
|
void pending.written.then(onWritten, () => void 0);
|
|
26248
26249
|
const promptRpc = pending.response;
|
|
@@ -26254,10 +26255,10 @@ function createExecutorPrompt({
|
|
|
26254
26255
|
promptKey,
|
|
26255
26256
|
sessionId,
|
|
26256
26257
|
settle: settleEarly,
|
|
26257
|
-
...
|
|
26258
|
-
onResponse: (response) => promptResults.receive(
|
|
26259
|
-
onError: () => promptResults.reject(
|
|
26260
|
-
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
|
|
26261
26262
|
}
|
|
26262
26263
|
});
|
|
26263
26264
|
try {
|
|
@@ -26351,11 +26352,11 @@ function createExecutorPrompt({
|
|
|
26351
26352
|
failIfPromptUnavailable();
|
|
26352
26353
|
const started = requireStarted();
|
|
26353
26354
|
const sessionId = started.sessionId;
|
|
26354
|
-
let
|
|
26355
|
+
let record3;
|
|
26355
26356
|
const settle2 = (rest) => settleTurn({
|
|
26356
26357
|
expectedGeneration: started.generation,
|
|
26357
26358
|
expectedSessionId: sessionId,
|
|
26358
|
-
record:
|
|
26359
|
+
record: record3,
|
|
26359
26360
|
...rest
|
|
26360
26361
|
});
|
|
26361
26362
|
let turnId;
|
|
@@ -26368,7 +26369,7 @@ function createExecutorPrompt({
|
|
|
26368
26369
|
randomId
|
|
26369
26370
|
);
|
|
26370
26371
|
shared.promptsInFlight += 1;
|
|
26371
|
-
|
|
26372
|
+
record3 = promptResults.add(
|
|
26372
26373
|
{
|
|
26373
26374
|
promptId: randomId(),
|
|
26374
26375
|
sessionId: started.sessionId,
|
|
@@ -26397,9 +26398,9 @@ function createExecutorPrompt({
|
|
|
26397
26398
|
const promptParts = input2.prompt ?? (input2.text !== void 0 ? [{ type: "text", text: input2.text }] : [{ type: "text", text: "" }]);
|
|
26398
26399
|
let contextWindow;
|
|
26399
26400
|
const finishPrompt = () => {
|
|
26400
|
-
if (!isLive(started.generation) ||
|
|
26401
|
-
const response2 =
|
|
26402
|
-
if (
|
|
26401
|
+
if (!isLive(started.generation) || record3.finished) throw new AcpExecutorDisposedError();
|
|
26402
|
+
const response2 = record3.response;
|
|
26403
|
+
if (record3.interrupted || response2 === void 0) {
|
|
26403
26404
|
settle2({ turnId, stopReason: "cancelled", state: "cancelled" });
|
|
26404
26405
|
return { threadId: options.threadId, turnId, stopReason: "cancelled" };
|
|
26405
26406
|
}
|
|
@@ -26442,7 +26443,7 @@ function createExecutorPrompt({
|
|
|
26442
26443
|
const isStale = () => interruptedTurnIds.has(queuedTurnId) || input2.expectedActiveTurnId !== void 0 && shared.activeTurnId !== queuedTurnId;
|
|
26443
26444
|
if (!isStale() && input2.expectedActiveTurnId === void 0) {
|
|
26444
26445
|
const optionWrites = new AbortController();
|
|
26445
|
-
shared.
|
|
26446
|
+
shared.localPromptWait = { turnId, stop: () => optionWrites.abort() };
|
|
26446
26447
|
try {
|
|
26447
26448
|
await alignTurnOptions(
|
|
26448
26449
|
input2,
|
|
@@ -26467,7 +26468,7 @@ function createExecutorPrompt({
|
|
|
26467
26468
|
});
|
|
26468
26469
|
throw error62 instanceof Error ? withFailureCategory(error62, failureCategory) : error62;
|
|
26469
26470
|
} finally {
|
|
26470
|
-
shared.
|
|
26471
|
+
shared.localPromptWait = void 0;
|
|
26471
26472
|
}
|
|
26472
26473
|
}
|
|
26473
26474
|
failIfDisposed();
|
|
@@ -26478,6 +26479,7 @@ function createExecutorPrompt({
|
|
|
26478
26479
|
closeActiveAssistantSegment(turnId);
|
|
26479
26480
|
let written = false;
|
|
26480
26481
|
try {
|
|
26482
|
+
const readFailure = hooks.observePromptFailure?.(sessionId);
|
|
26481
26483
|
response = await sendPromptRpc(
|
|
26482
26484
|
sessionId,
|
|
26483
26485
|
promptParts,
|
|
@@ -26485,8 +26487,18 @@ function createExecutorPrompt({
|
|
|
26485
26487
|
written = true;
|
|
26486
26488
|
input2.onDispatched?.(turnId);
|
|
26487
26489
|
},
|
|
26488
|
-
|
|
26490
|
+
record3
|
|
26489
26491
|
);
|
|
26492
|
+
if (readFailure && response.stopReason === "end_turn" && isLive(started.generation) && !isStale()) {
|
|
26493
|
+
const controller = new AbortController();
|
|
26494
|
+
shared.localPromptWait = { turnId, stop: () => controller.abort() };
|
|
26495
|
+
try {
|
|
26496
|
+
const failure2 = await readFailure(controller.signal);
|
|
26497
|
+
if (failure2 && !isStale() && !controller.signal.aborted) throw failure2;
|
|
26498
|
+
} finally {
|
|
26499
|
+
shared.localPromptWait = void 0;
|
|
26500
|
+
}
|
|
26501
|
+
}
|
|
26490
26502
|
} catch (caught) {
|
|
26491
26503
|
if (shared.disposed) {
|
|
26492
26504
|
throw new AcpExecutorDisposedError();
|
|
@@ -26530,7 +26542,7 @@ function createExecutorPrompt({
|
|
|
26530
26542
|
if (turnId === void 0) {
|
|
26531
26543
|
throw new AcpExecutorError("internal", "ACP prompt settled without a turn id");
|
|
26532
26544
|
}
|
|
26533
|
-
if (
|
|
26545
|
+
if (record3.finished) throw new AcpExecutorDisposedError();
|
|
26534
26546
|
if (hooks.readContextWindow !== void 0) {
|
|
26535
26547
|
try {
|
|
26536
26548
|
contextWindow = await hooks.readContextWindow({
|
|
@@ -26565,81 +26577,81 @@ function createPromptResults({
|
|
|
26565
26577
|
}) {
|
|
26566
26578
|
const prompts = /* @__PURE__ */ new Map();
|
|
26567
26579
|
const add = (identity, finish) => {
|
|
26568
|
-
const { promise: done, resolve:
|
|
26569
|
-
const
|
|
26580
|
+
const { promise: done, resolve: resolve5 } = Promise.withResolvers();
|
|
26581
|
+
const record3 = {
|
|
26570
26582
|
...identity,
|
|
26571
26583
|
finish,
|
|
26572
26584
|
done,
|
|
26573
|
-
resolve:
|
|
26585
|
+
resolve: resolve5,
|
|
26574
26586
|
rejected: false,
|
|
26575
26587
|
interrupted: false,
|
|
26576
26588
|
finished: false
|
|
26577
26589
|
};
|
|
26578
|
-
prompts.set(
|
|
26579
|
-
return
|
|
26590
|
+
prompts.set(record3.promptId, record3);
|
|
26591
|
+
return record3;
|
|
26580
26592
|
};
|
|
26581
26593
|
const receive = (promptId, response) => {
|
|
26582
|
-
const
|
|
26583
|
-
if (!
|
|
26584
|
-
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)
|
|
26585
26597
|
return;
|
|
26586
|
-
|
|
26598
|
+
record3.response = response;
|
|
26587
26599
|
};
|
|
26588
26600
|
const reject = (promptId) => {
|
|
26589
|
-
const
|
|
26590
|
-
if (
|
|
26601
|
+
const record3 = prompts.get(promptId);
|
|
26602
|
+
if (record3 && record3.response === void 0) record3.rejected = true;
|
|
26591
26603
|
};
|
|
26592
26604
|
const stop = (turnId) => {
|
|
26593
|
-
for (const
|
|
26594
|
-
if (!
|
|
26595
|
-
|
|
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;
|
|
26596
26608
|
}
|
|
26597
26609
|
}
|
|
26598
26610
|
};
|
|
26599
|
-
const complete = (
|
|
26600
|
-
|
|
26601
|
-
|
|
26611
|
+
const complete = (record3) => {
|
|
26612
|
+
record3.finished = true;
|
|
26613
|
+
record3.resolve();
|
|
26602
26614
|
};
|
|
26603
|
-
const hasInterrupted = (turnId) => [...prompts.values()].some((
|
|
26615
|
+
const hasInterrupted = (turnId) => [...prompts.values()].some((record3) => record3.turnId === turnId && record3.interrupted);
|
|
26604
26616
|
const forget = (turnId) => {
|
|
26605
|
-
for (const [id,
|
|
26606
|
-
if (
|
|
26607
|
-
complete(
|
|
26617
|
+
for (const [id, record3] of prompts) {
|
|
26618
|
+
if (record3.turnId === turnId) {
|
|
26619
|
+
complete(record3);
|
|
26608
26620
|
prompts.delete(id);
|
|
26609
26621
|
}
|
|
26610
26622
|
}
|
|
26611
26623
|
};
|
|
26612
26624
|
const wait = async (turnId, includeUnreceived = false) => {
|
|
26613
26625
|
const claimed = [...prompts.values()].filter(
|
|
26614
|
-
(
|
|
26626
|
+
(record3) => !record3.finished && (includeUnreceived || record3.response !== void 0) && (turnId === void 0 || record3.turnId === turnId)
|
|
26615
26627
|
);
|
|
26616
26628
|
if (claimed.length === 0) return;
|
|
26617
26629
|
let timer;
|
|
26618
26630
|
try {
|
|
26619
26631
|
const drained = await Promise.race([
|
|
26620
|
-
Promise.all(claimed.map((
|
|
26621
|
-
new Promise((
|
|
26632
|
+
Promise.all(claimed.map((record3) => record3.done)).then(() => true),
|
|
26633
|
+
new Promise((resolve5) => {
|
|
26622
26634
|
timer = setTimeout(
|
|
26623
|
-
() =>
|
|
26635
|
+
() => resolve5(false),
|
|
26624
26636
|
options.resultDrainTimeoutMs ?? DEFAULT_RESULT_DRAIN_TIMEOUT_MS
|
|
26625
26637
|
);
|
|
26626
26638
|
})
|
|
26627
26639
|
]);
|
|
26628
26640
|
if (drained) return;
|
|
26629
26641
|
options.log?.warn?.("ACP result settlement timed out", { threadId: options.threadId });
|
|
26630
|
-
for (const
|
|
26642
|
+
for (const record3 of claimed) if (!record3.finished) record3.finish();
|
|
26631
26643
|
} finally {
|
|
26632
26644
|
clearTimeout(timer);
|
|
26633
26645
|
}
|
|
26634
26646
|
};
|
|
26635
26647
|
const finishUnreceived = () => {
|
|
26636
26648
|
const claimedTurns = new Set(
|
|
26637
|
-
[...prompts.values()].filter((
|
|
26649
|
+
[...prompts.values()].filter((record3) => !record3.finished && record3.response !== void 0).map((record3) => record3.turnId)
|
|
26638
26650
|
);
|
|
26639
|
-
for (const
|
|
26640
|
-
if (!
|
|
26641
|
-
if (claimedTurns.has(
|
|
26642
|
-
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);
|
|
26643
26655
|
}
|
|
26644
26656
|
}
|
|
26645
26657
|
};
|
|
@@ -26651,15 +26663,15 @@ function defaultPermissionStatement(request) {
|
|
|
26651
26663
|
const rawInput = request.toolCall?.data["rawInput"];
|
|
26652
26664
|
const input2 = isRecord2(rawInput) ? rawInput : {};
|
|
26653
26665
|
const coveredArgs = [];
|
|
26654
|
-
const
|
|
26666
|
+
const text2 = (name) => {
|
|
26655
26667
|
const value = input2[name];
|
|
26656
26668
|
if (typeof value !== "string" || value.trim().length === 0) return void 0;
|
|
26657
26669
|
coveredArgs.push(name);
|
|
26658
26670
|
return value;
|
|
26659
26671
|
};
|
|
26660
|
-
const description =
|
|
26661
|
-
const justification =
|
|
26662
|
-
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;
|
|
26663
26675
|
let outsideSandbox = false;
|
|
26664
26676
|
for (const name of ["sandbox_permissions", "sandboxPermissions", "dangerouslyDisableSandbox"]) {
|
|
26665
26677
|
const value = input2[name];
|
|
@@ -26819,14 +26831,14 @@ function createExecutorRequests({
|
|
|
26819
26831
|
const statement = hooks.permissionStatement?.(permissionContext) ?? defaultPermissionStatement(permissionRequest);
|
|
26820
26832
|
const fileChanges = hooks.permissionFileChanges?.(permissionContext) ?? fileChangesFromAcpPermission(permissionRequest);
|
|
26821
26833
|
const requestId = randomId();
|
|
26822
|
-
const outcome = await new Promise((
|
|
26834
|
+
const outcome = await new Promise((resolve5) => {
|
|
26823
26835
|
const pending = {
|
|
26824
26836
|
requestId,
|
|
26825
26837
|
request: params,
|
|
26826
26838
|
permissionRequest,
|
|
26827
26839
|
turnId: shared.activeTurnId,
|
|
26828
26840
|
settled: false,
|
|
26829
|
-
resolve:
|
|
26841
|
+
resolve: resolve5
|
|
26830
26842
|
};
|
|
26831
26843
|
approvals.add(pending);
|
|
26832
26844
|
emit(
|
|
@@ -26948,7 +26960,7 @@ function acpArtifactEvent(input2) {
|
|
|
26948
26960
|
function makeArtifactEmitter(input2) {
|
|
26949
26961
|
return (artifacts, toolCallId) => {
|
|
26950
26962
|
const turnId = input2.turnId();
|
|
26951
|
-
const
|
|
26963
|
+
const event2 = acpArtifactEvent({
|
|
26952
26964
|
artifacts,
|
|
26953
26965
|
toolCallId,
|
|
26954
26966
|
base: {
|
|
@@ -26958,7 +26970,7 @@ function makeArtifactEmitter(input2) {
|
|
|
26958
26970
|
...turnId === void 0 ? {} : { turnId }
|
|
26959
26971
|
}
|
|
26960
26972
|
});
|
|
26961
|
-
if (
|
|
26973
|
+
if (event2 !== void 0) input2.emit(event2);
|
|
26962
26974
|
};
|
|
26963
26975
|
}
|
|
26964
26976
|
|
|
@@ -26977,11 +26989,11 @@ function createExecutorRuntime({
|
|
|
26977
26989
|
createdAt: nowIso3()
|
|
26978
26990
|
});
|
|
26979
26991
|
const isLive = (expectedGeneration) => !shared.disposed && shared.generation === expectedGeneration;
|
|
26980
|
-
const publish = (
|
|
26992
|
+
const publish = (event2) => {
|
|
26981
26993
|
if (shared.disposed) {
|
|
26982
26994
|
return;
|
|
26983
26995
|
}
|
|
26984
|
-
eventStream.publish(
|
|
26996
|
+
eventStream.publish(event2);
|
|
26985
26997
|
};
|
|
26986
26998
|
const emit = publish;
|
|
26987
26999
|
const emitArtifacts = makeArtifactEmitter({
|
|
@@ -27043,14 +27055,14 @@ function createExecutorRuntime({
|
|
|
27043
27055
|
if (!promptMutex.isLocked) {
|
|
27044
27056
|
return true;
|
|
27045
27057
|
}
|
|
27046
|
-
return await new Promise((
|
|
27058
|
+
return await new Promise((resolve5) => {
|
|
27047
27059
|
const timer = setTimeout(() => {
|
|
27048
27060
|
shared.promptWaiters = shared.promptWaiters.filter((waiter) => waiter !== onSettle);
|
|
27049
|
-
|
|
27061
|
+
resolve5(false);
|
|
27050
27062
|
}, timeoutMs);
|
|
27051
27063
|
const onSettle = () => {
|
|
27052
27064
|
clearTimeout(timer);
|
|
27053
|
-
|
|
27065
|
+
resolve5(true);
|
|
27054
27066
|
};
|
|
27055
27067
|
shared.promptWaiters.push(onSettle);
|
|
27056
27068
|
});
|
|
@@ -27680,13 +27692,13 @@ function parseState(raw) {
|
|
|
27680
27692
|
if (stopReason === "cancelled") return { status: "cancelled", error: void 0 };
|
|
27681
27693
|
return { status: "idle", error: void 0 };
|
|
27682
27694
|
}
|
|
27683
|
-
function childLinkage(childId,
|
|
27695
|
+
function childLinkage(childId, record3) {
|
|
27684
27696
|
return {
|
|
27685
27697
|
taskType: "subagent",
|
|
27686
27698
|
rosterKind: "subagent",
|
|
27687
27699
|
nativeSessionId: childId,
|
|
27688
27700
|
timelineBypass: true,
|
|
27689
|
-
...
|
|
27701
|
+
...record3.title === void 0 ? {} : { title: record3.title }
|
|
27690
27702
|
};
|
|
27691
27703
|
}
|
|
27692
27704
|
function createSubagentSessionTracker(registry2) {
|
|
@@ -27702,9 +27714,9 @@ function createSubagentSessionTracker(registry2) {
|
|
|
27702
27714
|
const title = asTrimmedString(update["title"]);
|
|
27703
27715
|
const description = asTrimmedString(update["description"]);
|
|
27704
27716
|
const state = parseState(update["state"]);
|
|
27705
|
-
let
|
|
27706
|
-
if (
|
|
27707
|
-
|
|
27717
|
+
let record3 = registry2.get(childId);
|
|
27718
|
+
if (record3 === void 0) {
|
|
27719
|
+
record3 = {
|
|
27708
27720
|
turnId: ctx.turnId,
|
|
27709
27721
|
title,
|
|
27710
27722
|
description,
|
|
@@ -27716,40 +27728,40 @@ function createSubagentSessionTracker(registry2) {
|
|
|
27716
27728
|
announced: ctx.silent,
|
|
27717
27729
|
pendingMetadata: false
|
|
27718
27730
|
};
|
|
27719
|
-
registry2.add(childId,
|
|
27731
|
+
registry2.add(childId, record3);
|
|
27720
27732
|
}
|
|
27721
|
-
|
|
27733
|
+
record3.turnId ??= ctx.turnId;
|
|
27722
27734
|
if (!ctx.silent) {
|
|
27723
|
-
if (title !== void 0 && title !==
|
|
27724
|
-
|
|
27735
|
+
if (title !== void 0 && title !== record3.title || description !== void 0 && description !== record3.description) {
|
|
27736
|
+
record3.pendingMetadata = true;
|
|
27725
27737
|
}
|
|
27726
27738
|
}
|
|
27727
|
-
if (title !== void 0)
|
|
27728
|
-
if (description !== void 0)
|
|
27729
|
-
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;
|
|
27730
27742
|
if (ctx.silent) return [];
|
|
27731
|
-
const linkage2 = childLinkage(childId,
|
|
27732
|
-
const turn =
|
|
27743
|
+
const linkage2 = childLinkage(childId, record3);
|
|
27744
|
+
const turn = record3.turnId === void 0 ? {} : { turnId: record3.turnId };
|
|
27733
27745
|
const events = [];
|
|
27734
|
-
if (!
|
|
27735
|
-
if (!
|
|
27736
|
-
|
|
27737
|
-
|
|
27746
|
+
if (!record3.announced && state.status === void 0) return events;
|
|
27747
|
+
if (!record3.announced) {
|
|
27748
|
+
record3.announced = true;
|
|
27749
|
+
record3.pendingMetadata = false;
|
|
27738
27750
|
events.push({
|
|
27739
27751
|
type: "task.started",
|
|
27740
27752
|
...turn,
|
|
27741
27753
|
payload: {
|
|
27742
27754
|
taskId: childId,
|
|
27743
27755
|
...linkage2,
|
|
27744
|
-
...
|
|
27756
|
+
...record3.description === void 0 ? {} : { description: record3.description }
|
|
27745
27757
|
}
|
|
27746
27758
|
});
|
|
27747
27759
|
}
|
|
27748
|
-
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);
|
|
27749
27761
|
if (statusChanged) {
|
|
27750
|
-
|
|
27751
|
-
|
|
27752
|
-
|
|
27762
|
+
record3.pendingMetadata = false;
|
|
27763
|
+
record3.reported = state.status;
|
|
27764
|
+
record3.reportedError = state.status === "failed" ? state.error ?? record3.reportedError : void 0;
|
|
27753
27765
|
events.push({
|
|
27754
27766
|
type: "task.updated",
|
|
27755
27767
|
...turn,
|
|
@@ -27757,7 +27769,7 @@ function createSubagentSessionTracker(registry2) {
|
|
|
27757
27769
|
taskId: childId,
|
|
27758
27770
|
status: state.status,
|
|
27759
27771
|
...state.error === void 0 ? {} : { error: state.error },
|
|
27760
|
-
...
|
|
27772
|
+
...record3.description === void 0 ? {} : { description: record3.description },
|
|
27761
27773
|
...linkage2
|
|
27762
27774
|
}
|
|
27763
27775
|
});
|
|
@@ -27766,20 +27778,20 @@ function createSubagentSessionTracker(registry2) {
|
|
|
27766
27778
|
};
|
|
27767
27779
|
const settleSessionEnded = () => {
|
|
27768
27780
|
const events = [];
|
|
27769
|
-
for (const [childId,
|
|
27770
|
-
const last =
|
|
27771
|
-
if (!
|
|
27772
|
-
|
|
27773
|
-
|
|
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";
|
|
27774
27786
|
events.push({
|
|
27775
27787
|
type: "task.updated",
|
|
27776
|
-
...
|
|
27788
|
+
...record3.turnId === void 0 ? {} : { turnId: record3.turnId },
|
|
27777
27789
|
payload: {
|
|
27778
27790
|
taskId: childId,
|
|
27779
27791
|
status: "idle",
|
|
27780
27792
|
outcomeUnknown: true,
|
|
27781
|
-
...
|
|
27782
|
-
...childLinkage(childId,
|
|
27793
|
+
...record3.description === void 0 ? {} : { description: record3.description },
|
|
27794
|
+
...childLinkage(childId, record3)
|
|
27783
27795
|
}
|
|
27784
27796
|
});
|
|
27785
27797
|
}
|
|
@@ -27808,8 +27820,8 @@ function createExecutorUpdates({
|
|
|
27808
27820
|
const shownToolCallIds = /* @__PURE__ */ new Set();
|
|
27809
27821
|
const markChildSession = shared.childSessions.mark;
|
|
27810
27822
|
const subagentSessions = options.subagentSessions === true ? createSubagentSessionTracker(shared.childSessions) : void 0;
|
|
27811
|
-
const emitCompactionState = (
|
|
27812
|
-
const summary =
|
|
27823
|
+
const emitCompactionState = (record3, state) => {
|
|
27824
|
+
const summary = record3.summary?.trim() ?? "";
|
|
27813
27825
|
const truncated = summary.length > COMPACTION_SUMMARY_MAX_CHARS;
|
|
27814
27826
|
emit({
|
|
27815
27827
|
type: "thread.state.changed",
|
|
@@ -27820,9 +27832,9 @@ function createExecutorUpdates({
|
|
|
27820
27832
|
payload: {
|
|
27821
27833
|
state,
|
|
27822
27834
|
compaction: {
|
|
27823
|
-
compactionId:
|
|
27824
|
-
trigger:
|
|
27825
|
-
...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) } : {},
|
|
27826
27838
|
...summary.length > 0 ? {
|
|
27827
27839
|
summary: truncated ? summary.slice(0, COMPACTION_SUMMARY_MAX_CHARS) : summary,
|
|
27828
27840
|
...truncated ? { summaryTruncated: true } : {}
|
|
@@ -27831,14 +27843,14 @@ function createExecutorUpdates({
|
|
|
27831
27843
|
}
|
|
27832
27844
|
});
|
|
27833
27845
|
};
|
|
27834
|
-
const applyCompactionUpdate = (
|
|
27835
|
-
let
|
|
27836
|
-
if (
|
|
27846
|
+
const applyCompactionUpdate = (event2) => {
|
|
27847
|
+
let record3 = compactions.get(event2.compactionId);
|
|
27848
|
+
if (record3 === void 0) {
|
|
27837
27849
|
if (shared.manualCompaction !== void 0 && !shared.manualCompaction.adopted) {
|
|
27838
27850
|
shared.manualCompaction.adopted = true;
|
|
27839
|
-
|
|
27851
|
+
record3 = shared.manualCompaction;
|
|
27840
27852
|
} else {
|
|
27841
|
-
|
|
27853
|
+
record3 = {
|
|
27842
27854
|
snapshotId: randomId(),
|
|
27843
27855
|
trigger: "automatic",
|
|
27844
27856
|
startedAtMs: nowMs(),
|
|
@@ -27848,26 +27860,26 @@ function createExecutorUpdates({
|
|
|
27848
27860
|
adopted: false
|
|
27849
27861
|
};
|
|
27850
27862
|
}
|
|
27851
|
-
compactions.set(
|
|
27863
|
+
compactions.set(event2.compactionId, record3);
|
|
27852
27864
|
}
|
|
27853
|
-
if (
|
|
27854
|
-
switch (
|
|
27865
|
+
if (event2.summary !== void 0) record3.summary = event2.summary ?? void 0;
|
|
27866
|
+
switch (event2.status) {
|
|
27855
27867
|
case "in_progress":
|
|
27856
|
-
if (!
|
|
27857
|
-
|
|
27858
|
-
emitCompactionState(
|
|
27868
|
+
if (!record3.announced) {
|
|
27869
|
+
record3.announced = true;
|
|
27870
|
+
emitCompactionState(record3, "compacting");
|
|
27859
27871
|
}
|
|
27860
27872
|
return;
|
|
27861
27873
|
case "completed":
|
|
27862
|
-
|
|
27863
|
-
|
|
27864
|
-
compactions.delete(
|
|
27865
|
-
emitCompactionState(
|
|
27874
|
+
record3.announced = true;
|
|
27875
|
+
record3.finished = true;
|
|
27876
|
+
compactions.delete(event2.compactionId);
|
|
27877
|
+
emitCompactionState(record3, "compacted");
|
|
27866
27878
|
return;
|
|
27867
27879
|
case "failed":
|
|
27868
27880
|
case "cancelled":
|
|
27869
|
-
|
|
27870
|
-
compactions.delete(
|
|
27881
|
+
record3.finished = true;
|
|
27882
|
+
compactions.delete(event2.compactionId);
|
|
27871
27883
|
emit({
|
|
27872
27884
|
type: "runtime.warning",
|
|
27873
27885
|
...stamp(),
|
|
@@ -27875,8 +27887,8 @@ function createExecutorUpdates({
|
|
|
27875
27887
|
threadId: options.threadId,
|
|
27876
27888
|
...shared.activeTurnId !== void 0 ? { turnId: shared.activeTurnId } : {},
|
|
27877
27889
|
payload: {
|
|
27878
|
-
message:
|
|
27879
|
-
detail: { code: `context-compaction-${
|
|
27890
|
+
message: event2.error ?? `Context compaction ${event2.status}`,
|
|
27891
|
+
detail: { code: `context-compaction-${event2.status}` }
|
|
27880
27892
|
}
|
|
27881
27893
|
});
|
|
27882
27894
|
return;
|
|
@@ -27963,13 +27975,13 @@ function createExecutorUpdates({
|
|
|
27963
27975
|
}
|
|
27964
27976
|
if (shared.sessionLoadInFlight) {
|
|
27965
27977
|
shared.droppedReplayUpdates += parsed.events.filter(
|
|
27966
|
-
(
|
|
27978
|
+
(event2) => event2._tag !== "ModeChanged"
|
|
27967
27979
|
).length;
|
|
27968
27980
|
return;
|
|
27969
27981
|
}
|
|
27970
|
-
for (const
|
|
27971
|
-
if (
|
|
27972
|
-
const { nextToolCall, decision } = retainToolCallUpdate(toolCalls,
|
|
27982
|
+
for (const event2 of parsed.events) {
|
|
27983
|
+
if (event2._tag === "ToolCallUpdated") {
|
|
27984
|
+
const { nextToolCall, decision } = retainToolCallUpdate(toolCalls, event2.toolCall, {
|
|
27973
27985
|
turnId: shared.activeTurnId,
|
|
27974
27986
|
rawTitle: params.update.title,
|
|
27975
27987
|
nowMs
|
|
@@ -28008,32 +28020,32 @@ function createExecutorUpdates({
|
|
|
28008
28020
|
threadId: options.threadId,
|
|
28009
28021
|
turnId: toolTurnId,
|
|
28010
28022
|
toolCall: nextToolCall,
|
|
28011
|
-
rawPayload:
|
|
28023
|
+
rawPayload: event2.rawPayload
|
|
28012
28024
|
})
|
|
28013
28025
|
);
|
|
28014
28026
|
continue;
|
|
28015
28027
|
}
|
|
28016
|
-
if (
|
|
28017
|
-
emitArtifacts(resourceLinkArtifacts(
|
|
28028
|
+
if (event2._tag === "AssistantContentBlock") {
|
|
28029
|
+
emitArtifacts(resourceLinkArtifacts(event2.content));
|
|
28018
28030
|
continue;
|
|
28019
28031
|
}
|
|
28020
|
-
if (
|
|
28021
|
-
applyCompactionUpdate(
|
|
28032
|
+
if (event2._tag === "CompactionUpdated") {
|
|
28033
|
+
applyCompactionUpdate(event2);
|
|
28022
28034
|
continue;
|
|
28023
28035
|
}
|
|
28024
|
-
if (
|
|
28025
|
-
const
|
|
28026
|
-
if (
|
|
28027
|
-
|
|
28036
|
+
if (event2._tag === "CompactionSummaryChunk") {
|
|
28037
|
+
const record3 = compactions.get(event2.compactionId);
|
|
28038
|
+
if (record3 !== void 0 && !record3.finished) {
|
|
28039
|
+
record3.summary = (record3.summary ?? "") + event2.text;
|
|
28028
28040
|
}
|
|
28029
28041
|
continue;
|
|
28030
28042
|
}
|
|
28031
|
-
if (
|
|
28043
|
+
if (event2._tag === "ContentDelta") {
|
|
28032
28044
|
if (shared.manualCompaction !== void 0) {
|
|
28033
28045
|
continue;
|
|
28034
28046
|
}
|
|
28035
|
-
if (
|
|
28036
|
-
if (
|
|
28047
|
+
if (event2.streamKind === "reasoning_text") {
|
|
28048
|
+
if (event2.text.trim().length === 0) {
|
|
28037
28049
|
continue;
|
|
28038
28050
|
}
|
|
28039
28051
|
emit(
|
|
@@ -28042,14 +28054,14 @@ function createExecutorUpdates({
|
|
|
28042
28054
|
provider: options.provider,
|
|
28043
28055
|
threadId: options.threadId,
|
|
28044
28056
|
turnId: shared.activeTurnId,
|
|
28045
|
-
text:
|
|
28057
|
+
text: event2.text,
|
|
28046
28058
|
streamKind: "reasoning_text",
|
|
28047
|
-
rawPayload:
|
|
28059
|
+
rawPayload: event2.rawPayload
|
|
28048
28060
|
})
|
|
28049
28061
|
);
|
|
28050
28062
|
continue;
|
|
28051
28063
|
}
|
|
28052
|
-
if (
|
|
28064
|
+
if (event2.text.trim().length === 0 && !shared.assistantSegment.activeItemId) {
|
|
28053
28065
|
continue;
|
|
28054
28066
|
}
|
|
28055
28067
|
const itemId = shared.sessionId ? ensureActiveAssistantSegment(shared.sessionId, shared.activeTurnId) : void 0;
|
|
@@ -28060,24 +28072,24 @@ function createExecutorUpdates({
|
|
|
28060
28072
|
threadId: options.threadId,
|
|
28061
28073
|
turnId: shared.activeTurnId,
|
|
28062
28074
|
...itemId ? { itemId } : {},
|
|
28063
|
-
text:
|
|
28075
|
+
text: event2.text,
|
|
28064
28076
|
streamKind: "assistant_text",
|
|
28065
|
-
rawPayload:
|
|
28077
|
+
rawPayload: event2.rawPayload
|
|
28066
28078
|
})
|
|
28067
28079
|
);
|
|
28068
28080
|
continue;
|
|
28069
28081
|
}
|
|
28070
|
-
if (
|
|
28082
|
+
if (event2._tag === "PlanUpdated") {
|
|
28071
28083
|
emit(
|
|
28072
28084
|
makeAcpPlanUpdatedEvent({
|
|
28073
28085
|
stamp: stamp(),
|
|
28074
28086
|
provider: options.provider,
|
|
28075
28087
|
threadId: options.threadId,
|
|
28076
28088
|
turnId: shared.activeTurnId,
|
|
28077
|
-
payload:
|
|
28089
|
+
payload: event2.payload,
|
|
28078
28090
|
source: "acp.jsonrpc",
|
|
28079
28091
|
method: "session/update",
|
|
28080
|
-
rawPayload:
|
|
28092
|
+
rawPayload: event2.rawPayload
|
|
28081
28093
|
})
|
|
28082
28094
|
);
|
|
28083
28095
|
}
|
|
@@ -28181,11 +28193,11 @@ function createAcpProtocolLogFile(input2) {
|
|
|
28181
28193
|
};
|
|
28182
28194
|
return {
|
|
28183
28195
|
path: filePath,
|
|
28184
|
-
write: (
|
|
28196
|
+
write: (event2) => writeLine({
|
|
28185
28197
|
at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
28186
|
-
direction:
|
|
28187
|
-
stage:
|
|
28188
|
-
payload:
|
|
28198
|
+
direction: event2.direction,
|
|
28199
|
+
stage: event2.stage,
|
|
28200
|
+
payload: event2.payload
|
|
28189
28201
|
}),
|
|
28190
28202
|
close: async () => {
|
|
28191
28203
|
if (closing) return closed.promise;
|
|
@@ -28266,7 +28278,7 @@ function createAcpExecutor(options) {
|
|
|
28266
28278
|
childSessions: createChildSessionRegistry(),
|
|
28267
28279
|
sessionOpensInFlight: 0,
|
|
28268
28280
|
configOptionUpdates: /* @__PURE__ */ new Map(),
|
|
28269
|
-
|
|
28281
|
+
localPromptWait: void 0,
|
|
28270
28282
|
configUpdateSeq: 0
|
|
28271
28283
|
};
|
|
28272
28284
|
const interruptedTurnIds = /* @__PURE__ */ new Set();
|
|
@@ -28642,13 +28654,13 @@ function acpNativeSessionProcessMatcher(program, args) {
|
|
|
28642
28654
|
|
|
28643
28655
|
// ../../packages/ycodium-acp-executor/src/prompt-dispatch.ts
|
|
28644
28656
|
var dispatchAcpPrompt = (executor, input2) => {
|
|
28645
|
-
const { promise: dispatched, resolve:
|
|
28657
|
+
const { promise: dispatched, resolve: resolve5 } = Promise.withResolvers();
|
|
28646
28658
|
let written = false;
|
|
28647
28659
|
const finished = executor.prompt({
|
|
28648
28660
|
...input2,
|
|
28649
28661
|
onDispatched: (turnId) => {
|
|
28650
28662
|
written = true;
|
|
28651
|
-
|
|
28663
|
+
resolve5(turnId);
|
|
28652
28664
|
}
|
|
28653
28665
|
});
|
|
28654
28666
|
return Promise.race([
|
|
@@ -28663,8 +28675,8 @@ var dispatchAcpPrompt = (executor, input2) => {
|
|
|
28663
28675
|
};
|
|
28664
28676
|
|
|
28665
28677
|
// ../../packages/ycodium-acp-executor/src/thread-operations.ts
|
|
28666
|
-
var yieldTick = () => new Promise((
|
|
28667
|
-
setImmediate(
|
|
28678
|
+
var yieldTick = () => new Promise((resolve5) => {
|
|
28679
|
+
setImmediate(resolve5);
|
|
28668
28680
|
});
|
|
28669
28681
|
var nowIso = () => (/* @__PURE__ */ new Date()).toISOString();
|
|
28670
28682
|
function createAcpThreadOperations(options) {
|
|
@@ -28748,9 +28760,9 @@ function modelSelectionStringOption(selection, optionId) {
|
|
|
28748
28760
|
if (!Array.isArray(options)) return void 0;
|
|
28749
28761
|
for (const entry of options) {
|
|
28750
28762
|
if (typeof entry !== "object" || entry === null || Array.isArray(entry)) continue;
|
|
28751
|
-
const
|
|
28752
|
-
if (
|
|
28753
|
-
const value =
|
|
28763
|
+
const record3 = entry;
|
|
28764
|
+
if (record3["id"] !== optionId) continue;
|
|
28765
|
+
const value = record3["value"];
|
|
28754
28766
|
return typeof value === "string" ? value.trim() || void 0 : void 0;
|
|
28755
28767
|
}
|
|
28756
28768
|
return void 0;
|
|
@@ -28823,8 +28835,8 @@ var BEARER_TOKEN_PATTERN = /\bBearer\s+[A-Za-z0-9._\-+=/]+/gi;
|
|
|
28823
28835
|
var BASIC_AUTH_PATTERN = /\bAuthorization:\s*Basic\s+\S+/gi;
|
|
28824
28836
|
var API_KEY_HEADER_PATTERN = /\bx-api-key:\s*\S+/gi;
|
|
28825
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;
|
|
28826
|
-
function redactStderrExcerpt(
|
|
28827
|
-
let result =
|
|
28838
|
+
function redactStderrExcerpt(text2, environment = process.env) {
|
|
28839
|
+
let result = text2.replaceAll("\0", "");
|
|
28828
28840
|
const homes = [environment["HOME"], environment["USERPROFILE"], NodeOS3.homedir()].filter(
|
|
28829
28841
|
(value) => typeof value === "string" && value.length > 1
|
|
28830
28842
|
);
|
|
@@ -28846,8 +28858,8 @@ function drainStderrTail(stderr) {
|
|
|
28846
28858
|
let timer;
|
|
28847
28859
|
await Promise.race([
|
|
28848
28860
|
drained,
|
|
28849
|
-
new Promise((
|
|
28850
|
-
timer = setTimeout(
|
|
28861
|
+
new Promise((resolve5) => {
|
|
28862
|
+
timer = setTimeout(resolve5, STDERR_SETTLE_MS);
|
|
28851
28863
|
})
|
|
28852
28864
|
]);
|
|
28853
28865
|
clearTimeout(timer);
|
|
@@ -28861,11 +28873,11 @@ function nodeStreamsFromHandle(handle, errors = ownErrors) {
|
|
|
28861
28873
|
for await (const chunk of handle.stdout) {
|
|
28862
28874
|
if (!readable.writable) return;
|
|
28863
28875
|
if (!readable.write(chunk)) {
|
|
28864
|
-
await new Promise((
|
|
28876
|
+
await new Promise((resolve5) => {
|
|
28865
28877
|
const onDone = () => {
|
|
28866
28878
|
readable.off("drain", onDone);
|
|
28867
28879
|
readable.off("close", onDone);
|
|
28868
|
-
|
|
28880
|
+
resolve5();
|
|
28869
28881
|
};
|
|
28870
28882
|
readable.once("drain", onDone);
|
|
28871
28883
|
readable.once("close", onDone);
|
|
@@ -28922,8 +28934,8 @@ async function raceStartAbort(promise2, signal) {
|
|
|
28922
28934
|
}
|
|
28923
28935
|
|
|
28924
28936
|
// ../../packages/ycodium-acp-executor/src/instance-kit.ts
|
|
28925
|
-
var yieldTick2 = () => new Promise((
|
|
28926
|
-
setImmediate(
|
|
28937
|
+
var yieldTick2 = () => new Promise((resolve5) => {
|
|
28938
|
+
setImmediate(resolve5);
|
|
28927
28939
|
});
|
|
28928
28940
|
var nowIso2 = () => (/* @__PURE__ */ new Date()).toISOString();
|
|
28929
28941
|
function createAcpThreadTable(log, beforeStopAll) {
|
|
@@ -29024,8 +29036,8 @@ function acpStartedSession(input2, started) {
|
|
|
29024
29036
|
async function openAcpThread(input2) {
|
|
29025
29037
|
const { executor, handle, signal, threadId } = input2;
|
|
29026
29038
|
const forwarding = (async () => {
|
|
29027
|
-
for await (const
|
|
29028
|
-
const forwarded = input2.forward(
|
|
29039
|
+
for await (const event2 of executor.events) {
|
|
29040
|
+
const forwarded = input2.forward(event2);
|
|
29029
29041
|
if (forwarded !== void 0) await forwarded;
|
|
29030
29042
|
}
|
|
29031
29043
|
})();
|
|
@@ -29141,6 +29153,30 @@ function parseCliVersion(output2) {
|
|
|
29141
29153
|
}
|
|
29142
29154
|
var MAX_VERSION_OUTPUT_BYTES = 64 * 1024;
|
|
29143
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
|
+
|
|
29144
29180
|
// ../../packages/ycodium-instance-config/src/launchArgs.ts
|
|
29145
29181
|
function tokenizeShellWords(value) {
|
|
29146
29182
|
const input2 = value.trim();
|
|
@@ -29263,6 +29299,9 @@ function parseKimiInstanceConfig(config2) {
|
|
|
29263
29299
|
};
|
|
29264
29300
|
}
|
|
29265
29301
|
|
|
29302
|
+
// src/kimiPromptFailure.ts
|
|
29303
|
+
import * as NodeFS3 from "node:fs";
|
|
29304
|
+
|
|
29266
29305
|
// src/kimi.ts
|
|
29267
29306
|
import * as NodeFS2 from "node:fs";
|
|
29268
29307
|
import * as NodePath4 from "node:path";
|
|
@@ -29280,8 +29319,8 @@ function questionTextFromContent(content) {
|
|
|
29280
29319
|
if (!isRecord8(entry) || entry["type"] !== "content") continue;
|
|
29281
29320
|
const inner = entry["content"];
|
|
29282
29321
|
if (!isRecord8(inner) || inner["type"] !== "text") continue;
|
|
29283
|
-
const
|
|
29284
|
-
if (typeof
|
|
29322
|
+
const text2 = inner["text"];
|
|
29323
|
+
if (typeof text2 === "string") parts.push(text2);
|
|
29285
29324
|
}
|
|
29286
29325
|
return parts.join("\n\n").trim();
|
|
29287
29326
|
}
|
|
@@ -29325,20 +29364,20 @@ function parseKimiContextWindow(contents) {
|
|
|
29325
29364
|
for (const line of contents.split("\n")) {
|
|
29326
29365
|
const trimmed2 = line.trim();
|
|
29327
29366
|
if (trimmed2.length === 0) continue;
|
|
29328
|
-
let
|
|
29367
|
+
let record3;
|
|
29329
29368
|
try {
|
|
29330
|
-
|
|
29369
|
+
record3 = JSON.parse(trimmed2);
|
|
29331
29370
|
} catch {
|
|
29332
29371
|
continue;
|
|
29333
29372
|
}
|
|
29334
|
-
if (!isRecord8(
|
|
29335
|
-
const type =
|
|
29373
|
+
if (!isRecord8(record3)) continue;
|
|
29374
|
+
const type = record3["type"];
|
|
29336
29375
|
if (type === "token_counting.turn_recorded" || type === "token_counting.measured") {
|
|
29337
|
-
usedTokens = positiveInt(
|
|
29376
|
+
usedTokens = positiveInt(record3["tokens"]) ?? usedTokens;
|
|
29338
29377
|
continue;
|
|
29339
29378
|
}
|
|
29340
29379
|
if (type === "llm.request") {
|
|
29341
|
-
maxTokens = positiveInt(
|
|
29380
|
+
maxTokens = positiveInt(record3["maxTokens"]) ?? maxTokens;
|
|
29342
29381
|
}
|
|
29343
29382
|
}
|
|
29344
29383
|
if (usedTokens === void 0) return void 0;
|
|
@@ -29366,6 +29405,8 @@ function readTail(filePath) {
|
|
|
29366
29405
|
}
|
|
29367
29406
|
}
|
|
29368
29407
|
function findKimiSessionWireLog(input2) {
|
|
29408
|
+
if (!input2.acpSessionId || /[\\/:]/u.test(input2.acpSessionId) || [".", ".."].includes(input2.acpSessionId))
|
|
29409
|
+
return void 0;
|
|
29369
29410
|
const sessionsRoot = NodePath4.join(input2.homePath, SESSIONS_DIR);
|
|
29370
29411
|
let workspaces;
|
|
29371
29412
|
try {
|
|
@@ -29392,8 +29433,109 @@ function readKimiContextWindow(input2) {
|
|
|
29392
29433
|
return contents === void 0 ? void 0 : parseKimiContextWindow(contents);
|
|
29393
29434
|
}
|
|
29394
29435
|
|
|
29436
|
+
// src/kimiPromptFailure.ts
|
|
29437
|
+
var END_BYTES = 64 * 1024;
|
|
29438
|
+
var START_BYTES = 512 * 1024;
|
|
29439
|
+
function readWindow(fd, start, end) {
|
|
29440
|
+
const buffer = Buffer.alloc(end - start);
|
|
29441
|
+
const bytes = NodeFS3.readSync(fd, buffer, 0, buffer.length, start);
|
|
29442
|
+
return buffer.toString("utf8", 0, bytes).split("\n");
|
|
29443
|
+
}
|
|
29444
|
+
function event(line, type) {
|
|
29445
|
+
if (!line.includes(`"${type}"`)) return void 0;
|
|
29446
|
+
try {
|
|
29447
|
+
const value = JSON.parse(line);
|
|
29448
|
+
if (value?.type === type && value.agentId === "main") return value;
|
|
29449
|
+
} catch {
|
|
29450
|
+
}
|
|
29451
|
+
return void 0;
|
|
29452
|
+
}
|
|
29453
|
+
function observeKimiPromptFailure(homePath, acpSessionId) {
|
|
29454
|
+
const startedAt = Date.now();
|
|
29455
|
+
const find = () => findKimiSessionWireLog({ homePath, acpSessionId });
|
|
29456
|
+
const original = find();
|
|
29457
|
+
let before;
|
|
29458
|
+
try {
|
|
29459
|
+
if (original) before = NodeFS3.statSync(original);
|
|
29460
|
+
} catch {
|
|
29461
|
+
return void 0;
|
|
29462
|
+
}
|
|
29463
|
+
const inspect = () => {
|
|
29464
|
+
const path = original ?? find();
|
|
29465
|
+
if (!path) return void 0;
|
|
29466
|
+
let fd;
|
|
29467
|
+
try {
|
|
29468
|
+
fd = NodeFS3.openSync(path, "r");
|
|
29469
|
+
const after = NodeFS3.fstatSync(fd);
|
|
29470
|
+
const start = before?.size ?? 0;
|
|
29471
|
+
if (after.size < start || before && (before.dev !== after.dev || before.ino !== after.ino))
|
|
29472
|
+
return void 0;
|
|
29473
|
+
if (after.size === start) return "pending";
|
|
29474
|
+
const tailStart = Math.max(start, after.size - END_BYTES);
|
|
29475
|
+
const tail = readWindow(fd, tailStart, after.size);
|
|
29476
|
+
let ended;
|
|
29477
|
+
for (let i = tail.length - 1; i >= 0; i--) {
|
|
29478
|
+
const line = tail[i];
|
|
29479
|
+
if (event(line, "turn.prompt")) return "pending";
|
|
29480
|
+
ended = event(line, "turn.ended");
|
|
29481
|
+
if (ended) break;
|
|
29482
|
+
}
|
|
29483
|
+
if (!ended) return "pending";
|
|
29484
|
+
if (ended.reason !== "failed" || typeof ended.turnId !== "number") return void 0;
|
|
29485
|
+
const turnId = ended.turnId;
|
|
29486
|
+
const promptLines = tailStart === start ? tail : readWindow(fd, start, Math.min(after.size, start + START_BYTES));
|
|
29487
|
+
let prompt;
|
|
29488
|
+
for (const line of promptLines) {
|
|
29489
|
+
prompt = event(line, "turn.prompt");
|
|
29490
|
+
if (prompt) break;
|
|
29491
|
+
}
|
|
29492
|
+
if (!prompt || prompt.turnId !== turnId || before === void 0 && (typeof prompt.time !== "number" || prompt.time < startedAt))
|
|
29493
|
+
return void 0;
|
|
29494
|
+
const error62 = ended.error;
|
|
29495
|
+
if (typeof error62 !== "object" || !error62 || !("message" in error62) || typeof error62.message !== "string" || !error62.message.trim())
|
|
29496
|
+
return new Error("Kimi reported that the turn failed.");
|
|
29497
|
+
const failure2 = new Error(error62.message);
|
|
29498
|
+
return "name" in error62 && error62.name === "APIProviderQuotaExhaustedError" ? Object.assign(failure2, { failureCategory: "quota" }) : failure2;
|
|
29499
|
+
} catch {
|
|
29500
|
+
return void 0;
|
|
29501
|
+
} finally {
|
|
29502
|
+
if (fd !== void 0) NodeFS3.closeSync(fd);
|
|
29503
|
+
}
|
|
29504
|
+
};
|
|
29505
|
+
return async (signal) => {
|
|
29506
|
+
if (signal.aborted) return void 0;
|
|
29507
|
+
const first = inspect();
|
|
29508
|
+
if (first !== "pending") return first;
|
|
29509
|
+
const path = original ?? find();
|
|
29510
|
+
if (!path) return void 0;
|
|
29511
|
+
return new Promise((resolve5) => {
|
|
29512
|
+
let watcher;
|
|
29513
|
+
const finish = (failure2) => {
|
|
29514
|
+
clearTimeout(deadline);
|
|
29515
|
+
signal.removeEventListener("abort", abort);
|
|
29516
|
+
watcher?.close();
|
|
29517
|
+
resolve5(failure2);
|
|
29518
|
+
};
|
|
29519
|
+
const abort = () => finish();
|
|
29520
|
+
const check2 = () => {
|
|
29521
|
+
const result = inspect();
|
|
29522
|
+
if (result !== "pending") finish(result);
|
|
29523
|
+
};
|
|
29524
|
+
const deadline = setTimeout(abort, 1e3);
|
|
29525
|
+
try {
|
|
29526
|
+
watcher = NodeFS3.watch(path, check2);
|
|
29527
|
+
watcher.on("error", abort);
|
|
29528
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
29529
|
+
check2();
|
|
29530
|
+
} catch {
|
|
29531
|
+
finish();
|
|
29532
|
+
}
|
|
29533
|
+
});
|
|
29534
|
+
};
|
|
29535
|
+
}
|
|
29536
|
+
|
|
29395
29537
|
// src/kimiQuota.ts
|
|
29396
|
-
import * as
|
|
29538
|
+
import * as NodeFS5 from "node:fs";
|
|
29397
29539
|
import * as NodeOS5 from "node:os";
|
|
29398
29540
|
import * as NodePath6 from "node:path";
|
|
29399
29541
|
|
|
@@ -29463,18 +29605,20 @@ var parseJson = (raw) => {
|
|
|
29463
29605
|
};
|
|
29464
29606
|
|
|
29465
29607
|
// src/kimiAccount.ts
|
|
29466
|
-
import * as
|
|
29608
|
+
import * as NodeFS4 from "node:fs";
|
|
29467
29609
|
import * as NodeOS4 from "node:os";
|
|
29468
29610
|
import * as NodePath5 from "node:path";
|
|
29611
|
+
function kimiAccountHome(resolvedHomePath) {
|
|
29612
|
+
return resolvedHomePath.trim().length > 0 ? resolvedHomePath : NodePath5.join(NodeOS4.homedir(), ".kimi-code");
|
|
29613
|
+
}
|
|
29469
29614
|
function kimiCredentialsPath(resolvedHomePath) {
|
|
29470
|
-
|
|
29471
|
-
return NodePath5.join(home, "credentials", "kimi-code.json");
|
|
29615
|
+
return NodePath5.join(kimiAccountHome(resolvedHomePath), "credentials", "kimi-code.json");
|
|
29472
29616
|
}
|
|
29473
29617
|
var nonEmptyString = (value) => typeof value === "string" && value.length > 0;
|
|
29474
29618
|
function readKimiAuthState(resolvedHomePath) {
|
|
29475
29619
|
let raw;
|
|
29476
29620
|
try {
|
|
29477
|
-
raw =
|
|
29621
|
+
raw = NodeFS4.readFileSync(kimiCredentialsPath(resolvedHomePath), "utf8");
|
|
29478
29622
|
} catch (error62) {
|
|
29479
29623
|
return error62.code === "ENOENT" ? "signed-out" : "unreadable";
|
|
29480
29624
|
}
|
|
@@ -29485,8 +29629,8 @@ function readKimiAuthState(resolvedHomePath) {
|
|
|
29485
29629
|
return "unreadable";
|
|
29486
29630
|
}
|
|
29487
29631
|
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return "unreadable";
|
|
29488
|
-
const
|
|
29489
|
-
return nonEmptyString(
|
|
29632
|
+
const record3 = parsed;
|
|
29633
|
+
return nonEmptyString(record3["refresh_token"]) || nonEmptyString(record3["access_token"]) ? "signed-in" : "signed-out";
|
|
29490
29634
|
}
|
|
29491
29635
|
|
|
29492
29636
|
// src/kimiQuota.ts
|
|
@@ -29498,9 +29642,9 @@ var TOKEN_EXPIRY_SKEW_MS = 3e4;
|
|
|
29498
29642
|
var asCount = (value) => {
|
|
29499
29643
|
const direct = asNumber(value);
|
|
29500
29644
|
if (direct !== null) return direct;
|
|
29501
|
-
const
|
|
29502
|
-
if (
|
|
29503
|
-
const parsed = Number(
|
|
29645
|
+
const text2 = asString3(value);
|
|
29646
|
+
if (text2 === null) return null;
|
|
29647
|
+
const parsed = Number(text2);
|
|
29504
29648
|
return Number.isFinite(parsed) ? parsed : null;
|
|
29505
29649
|
};
|
|
29506
29650
|
var clampPercent = (value) => Math.min(100, Math.max(0, value));
|
|
@@ -29510,11 +29654,11 @@ var expiryMs = (value) => {
|
|
|
29510
29654
|
return raw > 1e12 ? raw : raw * 1e3;
|
|
29511
29655
|
};
|
|
29512
29656
|
var extractKimiToken = (auth, nowMs) => {
|
|
29513
|
-
const
|
|
29514
|
-
if (
|
|
29515
|
-
const token = asString3(
|
|
29657
|
+
const record3 = asObject(auth);
|
|
29658
|
+
if (record3 === null) return null;
|
|
29659
|
+
const token = asString3(record3["access_token"]);
|
|
29516
29660
|
if (token === null) return null;
|
|
29517
|
-
const expiresAtMs = expiryMs(
|
|
29661
|
+
const expiresAtMs = expiryMs(record3["expires_at"]);
|
|
29518
29662
|
if (expiresAtMs === null) return token;
|
|
29519
29663
|
return expiresAtMs - nowMs < TOKEN_EXPIRY_SKEW_MS ? null : token;
|
|
29520
29664
|
};
|
|
@@ -29558,10 +29702,10 @@ var TIME_UNIT_MINUTES = {
|
|
|
29558
29702
|
TIME_UNIT_WEEK: 10080
|
|
29559
29703
|
};
|
|
29560
29704
|
var kimiWindowSpan = (window) => {
|
|
29561
|
-
const
|
|
29562
|
-
if (
|
|
29563
|
-
const duration3 = asCount(
|
|
29564
|
-
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"]);
|
|
29565
29709
|
const minutesPerUnit = unit === null ? void 0 : TIME_UNIT_MINUTES[unit];
|
|
29566
29710
|
if (duration3 === null || duration3 <= 0 || minutesPerUnit === void 0) return null;
|
|
29567
29711
|
const minutes = duration3 * minutesPerUnit;
|
|
@@ -29569,18 +29713,18 @@ var kimiWindowSpan = (window) => {
|
|
|
29569
29713
|
return { label, windowMs: minutes * 6e4 };
|
|
29570
29714
|
};
|
|
29571
29715
|
var windowFrom = (id, label, detail, windowMs) => {
|
|
29572
|
-
const
|
|
29573
|
-
if (
|
|
29574
|
-
const limit = asCount(
|
|
29716
|
+
const record3 = asObject(detail);
|
|
29717
|
+
if (record3 === null) return null;
|
|
29718
|
+
const limit = asCount(record3["limit"]);
|
|
29575
29719
|
if (limit === null || limit <= 0) return null;
|
|
29576
|
-
const remaining = asCount(
|
|
29577
|
-
const used = asCount(
|
|
29720
|
+
const remaining = asCount(record3["remaining"]);
|
|
29721
|
+
const used = asCount(record3["used"]) ?? (remaining === null ? null : limit - remaining);
|
|
29578
29722
|
if (used === null) return null;
|
|
29579
29723
|
return {
|
|
29580
29724
|
id,
|
|
29581
29725
|
label,
|
|
29582
29726
|
usedPercent: clampPercent(used / limit * 100),
|
|
29583
|
-
resetsAt: asString3(
|
|
29727
|
+
resetsAt: asString3(record3["resetTime"]),
|
|
29584
29728
|
...windowMs === void 0 ? {} : { windowMs }
|
|
29585
29729
|
};
|
|
29586
29730
|
};
|
|
@@ -29628,7 +29772,7 @@ var createKimiUsage = (input2) => {
|
|
|
29628
29772
|
const readQuota = async (request) => {
|
|
29629
29773
|
let configToml = null;
|
|
29630
29774
|
try {
|
|
29631
|
-
configToml =
|
|
29775
|
+
configToml = NodeFS5.readFileSync(NodePath6.join(home, "config.toml"), "utf8");
|
|
29632
29776
|
} catch (error62) {
|
|
29633
29777
|
if (error62.code !== "ENOENT") {
|
|
29634
29778
|
return { status: "unavailable", reason: "unreachable" };
|
|
@@ -29641,7 +29785,7 @@ var createKimiUsage = (input2) => {
|
|
|
29641
29785
|
if ("custom" in endpoint) return { status: "unavailable", reason: "customEndpoint" };
|
|
29642
29786
|
let token = null;
|
|
29643
29787
|
try {
|
|
29644
|
-
token = extractKimiToken(parseJson(
|
|
29788
|
+
token = extractKimiToken(parseJson(NodeFS5.readFileSync(credentialsPath, "utf8")), now());
|
|
29645
29789
|
} catch {
|
|
29646
29790
|
token = null;
|
|
29647
29791
|
}
|
|
@@ -29669,7 +29813,7 @@ var createKimiUsage = (input2) => {
|
|
|
29669
29813
|
};
|
|
29670
29814
|
|
|
29671
29815
|
// src/kimiTokens.ts
|
|
29672
|
-
import * as
|
|
29816
|
+
import * as NodeFS6 from "node:fs";
|
|
29673
29817
|
import * as NodeOS6 from "node:os";
|
|
29674
29818
|
import * as NodePath7 from "node:path";
|
|
29675
29819
|
var MTIME_SLACK_MS = 36 * 60 * 60 * 1e3;
|
|
@@ -29708,7 +29852,7 @@ var parseKimiUsageLine = (line) => {
|
|
|
29708
29852
|
var hasTokens = (totals) => totals.uncachedInputTokens > 0 || totals.cachedInputTokens > 0 || totals.cacheCreationTokens > 0 || totals.outputTokens > 0;
|
|
29709
29853
|
var readDirs = (dir) => {
|
|
29710
29854
|
try {
|
|
29711
|
-
return
|
|
29855
|
+
return NodeFS6.readdirSync(dir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
|
|
29712
29856
|
} catch {
|
|
29713
29857
|
return [];
|
|
29714
29858
|
}
|
|
@@ -29728,17 +29872,17 @@ var listWireLogs = (sessionsRoot) => {
|
|
|
29728
29872
|
var readRange = (file2, from, to) => {
|
|
29729
29873
|
const length = Math.max(0, to - from);
|
|
29730
29874
|
const buffer = Buffer.alloc(length);
|
|
29731
|
-
const fd =
|
|
29875
|
+
const fd = NodeFS6.openSync(file2, "r");
|
|
29732
29876
|
try {
|
|
29733
29877
|
let read = 0;
|
|
29734
29878
|
while (read < length) {
|
|
29735
|
-
const n =
|
|
29879
|
+
const n = NodeFS6.readSync(fd, buffer, read, length - read, from + read);
|
|
29736
29880
|
if (n === 0) break;
|
|
29737
29881
|
read += n;
|
|
29738
29882
|
}
|
|
29739
29883
|
return read === length ? buffer : buffer.subarray(0, read);
|
|
29740
29884
|
} finally {
|
|
29741
|
-
|
|
29885
|
+
NodeFS6.closeSync(fd);
|
|
29742
29886
|
}
|
|
29743
29887
|
};
|
|
29744
29888
|
var guardOf = (file2, size) => readRange(file2, 0, Math.min(size, GUARD_LENGTH)).toString("base64");
|
|
@@ -29769,7 +29913,7 @@ var createKimiTokenReader = (input2) => {
|
|
|
29769
29913
|
const readTokenUsage = async (request) => {
|
|
29770
29914
|
const sinceMs = Date.parse(request.since);
|
|
29771
29915
|
const untilMs = Date.parse(request.until);
|
|
29772
|
-
if (!
|
|
29916
|
+
if (!NodeFS6.existsSync(sessionsRoot)) {
|
|
29773
29917
|
return {
|
|
29774
29918
|
records: [],
|
|
29775
29919
|
source: {
|
|
@@ -29790,7 +29934,7 @@ var createKimiTokenReader = (input2) => {
|
|
|
29790
29934
|
for (const { file: file2, sessionId } of listWireLogs(sessionsRoot)) {
|
|
29791
29935
|
let size;
|
|
29792
29936
|
try {
|
|
29793
|
-
const stat =
|
|
29937
|
+
const stat = NodeFS6.statSync(file2);
|
|
29794
29938
|
if (stat.mtimeMs < sinceMs - MTIME_SLACK_MS) {
|
|
29795
29939
|
skippedFiles += 1;
|
|
29796
29940
|
continue;
|
|
@@ -29808,15 +29952,15 @@ var createKimiTokenReader = (input2) => {
|
|
|
29808
29952
|
}
|
|
29809
29953
|
scannedFiles += 1;
|
|
29810
29954
|
malformedRecords += memo2.malformed;
|
|
29811
|
-
for (const
|
|
29812
|
-
if (
|
|
29813
|
-
if (!hasTokens(
|
|
29814
|
-
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);
|
|
29815
29959
|
records.push({
|
|
29816
|
-
at: new Date(
|
|
29817
|
-
model:
|
|
29960
|
+
at: new Date(record3.timeMs).toISOString(),
|
|
29961
|
+
model: record3.model,
|
|
29818
29962
|
sessionId,
|
|
29819
|
-
totals:
|
|
29963
|
+
totals: record3.totals
|
|
29820
29964
|
});
|
|
29821
29965
|
}
|
|
29822
29966
|
}
|
|
@@ -30110,8 +30254,8 @@ function describe3(kind, input2, previous) {
|
|
|
30110
30254
|
...model === void 0 ? {} : { model }
|
|
30111
30255
|
};
|
|
30112
30256
|
}
|
|
30113
|
-
function splitResult(
|
|
30114
|
-
const lines =
|
|
30257
|
+
function splitResult(text2) {
|
|
30258
|
+
const lines = text2.split(/\r?\n/u);
|
|
30115
30259
|
const header = /* @__PURE__ */ new Map();
|
|
30116
30260
|
let index = 0;
|
|
30117
30261
|
for (; index < lines.length; index += 1) {
|
|
@@ -30125,15 +30269,15 @@ function stripTrailingHints(body) {
|
|
|
30125
30269
|
const cuts = ["\nresume_hint: ", "\nnext_step: "].map((marker) => body.lastIndexOf(marker)).filter((position) => position >= 0);
|
|
30126
30270
|
return (cuts.length === 0 ? body : body.slice(0, Math.min(...cuts))).trim();
|
|
30127
30271
|
}
|
|
30128
|
-
function parseAgentResult(
|
|
30129
|
-
if (
|
|
30272
|
+
function parseAgentResult(text2, isError) {
|
|
30273
|
+
if (text2 === void 0)
|
|
30130
30274
|
return {
|
|
30131
30275
|
kind: isError ? "failed" : "completed",
|
|
30132
30276
|
summary: void 0,
|
|
30133
30277
|
role: void 0,
|
|
30134
30278
|
agentId: void 0
|
|
30135
30279
|
};
|
|
30136
|
-
const { header, body } = splitResult(
|
|
30280
|
+
const { header, body } = splitResult(text2);
|
|
30137
30281
|
const role = trimmed(header.get("actual_subagent_type"));
|
|
30138
30282
|
const agentId = trimmed(header.get("agent_id"));
|
|
30139
30283
|
const status = header.get("status");
|
|
@@ -30143,7 +30287,7 @@ function parseAgentResult(text, isError) {
|
|
|
30143
30287
|
if (isError || status === "failed") {
|
|
30144
30288
|
return {
|
|
30145
30289
|
kind: header.get("stop_reason") === "cancelled" ? "cancelled" : "failed",
|
|
30146
|
-
summary: trimmed(stripTrailingHints(body)) ?? trimmed(
|
|
30290
|
+
summary: trimmed(stripTrailingHints(body)) ?? trimmed(text2),
|
|
30147
30291
|
role,
|
|
30148
30292
|
agentId
|
|
30149
30293
|
};
|
|
@@ -30155,21 +30299,21 @@ function parseAgentResult(text, isError) {
|
|
|
30155
30299
|
const summary = [notice === void 0 ? void 0 : `notice: ${notice}`, answer].filter((part) => part !== void 0).join("\n\n");
|
|
30156
30300
|
return { kind: "completed", summary: trimmed(summary), role, agentId };
|
|
30157
30301
|
}
|
|
30158
|
-
function parseSwarmResult(
|
|
30159
|
-
const inner =
|
|
30302
|
+
function parseSwarmResult(text2, isError) {
|
|
30303
|
+
const inner = text2 === void 0 ? void 0 : /<summary>([\s\S]*?)<\/summary>/u.exec(text2)?.[1];
|
|
30160
30304
|
return {
|
|
30161
30305
|
kind: isError ? "failed" : "completed",
|
|
30162
|
-
summary: trimmed(inner) ?? trimmed(
|
|
30306
|
+
summary: trimmed(inner) ?? trimmed(text2),
|
|
30163
30307
|
role: void 0,
|
|
30164
30308
|
agentId: void 0
|
|
30165
30309
|
};
|
|
30166
30310
|
}
|
|
30167
30311
|
function resolveOutcome(call, kind) {
|
|
30168
30312
|
if (call.status !== "completed" && call.status !== "failed") return void 0;
|
|
30169
|
-
const
|
|
30313
|
+
const text2 = typeof call.rawOutput === "string" ? trimmed(call.rawOutput) : void 0;
|
|
30170
30314
|
const isError = call.status === "failed";
|
|
30171
|
-
if (
|
|
30172
|
-
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);
|
|
30173
30317
|
const ids = {
|
|
30174
30318
|
...outcome.role === void 0 ? {} : { role: outcome.role },
|
|
30175
30319
|
...outcome.agentId === void 0 ? {} : { agentRef: outcome.agentId }
|
|
@@ -30208,11 +30352,11 @@ var kimiPermissionStatement = ({
|
|
|
30208
30352
|
if (permissionRequest.kind !== "execute" || request.toolCall.rawInput !== void 0 || statement.command !== void 0)
|
|
30209
30353
|
return statement;
|
|
30210
30354
|
const texts = [permissionRequest.toolCall?.contentText, previousToolCall?.contentText];
|
|
30211
|
-
for (const
|
|
30212
|
-
if (!
|
|
30355
|
+
for (const text2 of texts) {
|
|
30356
|
+
if (!text2) continue;
|
|
30213
30357
|
let input2;
|
|
30214
30358
|
try {
|
|
30215
|
-
input2 = JSON.parse(
|
|
30359
|
+
input2 = JSON.parse(text2);
|
|
30216
30360
|
} catch {
|
|
30217
30361
|
continue;
|
|
30218
30362
|
}
|
|
@@ -30223,6 +30367,287 @@ var kimiPermissionStatement = ({
|
|
|
30223
30367
|
return statement;
|
|
30224
30368
|
};
|
|
30225
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
|
+
|
|
30226
30651
|
// src/kimiInstance.ts
|
|
30227
30652
|
var RESUME_SCHEMA_VERSION = 1;
|
|
30228
30653
|
var CLIENT_INFO = { name: "ycodium-agent-kimi", version: "0.1.0" };
|
|
@@ -30237,7 +30662,9 @@ function resolveHomePath(recipe) {
|
|
|
30237
30662
|
}
|
|
30238
30663
|
function kimiHooks(recipe) {
|
|
30239
30664
|
const homePath = resolveHomePath(recipe);
|
|
30665
|
+
const wireHome = kimiAccountHome(kimiEffectiveHome(homePath, process.env[recipe.homeEnvVar]));
|
|
30240
30666
|
return {
|
|
30667
|
+
observePromptFailure: (sessionId) => observeKimiPromptFailure(wireHome, sessionId),
|
|
30241
30668
|
permissionUserInput: kimiPermissionUserInput,
|
|
30242
30669
|
permissionStatement: kimiPermissionStatement,
|
|
30243
30670
|
toolSubagents: kimiToolSubagents,
|
|
@@ -30253,7 +30680,29 @@ var createKimiInstance = (config2, host) => {
|
|
|
30253
30680
|
turnSelection: (selection) => readTurnSelection(selection, ACP_EFFORT_OPTION_ID)
|
|
30254
30681
|
});
|
|
30255
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
|
+
);
|
|
30256
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
|
+
},
|
|
30257
30706
|
probe: async (signal) => {
|
|
30258
30707
|
if (recipe.binaryPath.length === 0) {
|
|
30259
30708
|
return acpProgramNotConfigured("Kimi Code program path is not configured");
|
|
@@ -30391,7 +30840,7 @@ var createKimiInstance = (config2, host) => {
|
|
|
30391
30840
|
handle,
|
|
30392
30841
|
signal,
|
|
30393
30842
|
log: host.log,
|
|
30394
|
-
emit: (
|
|
30843
|
+
emit: (event2) => input2.events.emit(event2),
|
|
30395
30844
|
requestedNativeModeId: input2.nativeModeId,
|
|
30396
30845
|
resumed: resume !== void 0,
|
|
30397
30846
|
session: {
|
|
@@ -30469,7 +30918,7 @@ var index_default = definePlugin({
|
|
|
30469
30918
|
"KIMI_CODE_HOME",
|
|
30470
30919
|
request,
|
|
30471
30920
|
process.env,
|
|
30472
|
-
(value) => value === void 0 ?
|
|
30921
|
+
(value) => value === void 0 ? NodePath9.join(NodeOS7.homedir(), ".kimi-code") : NodePath9.resolve(expandHomePath(value))
|
|
30473
30922
|
)
|
|
30474
30923
|
};
|
|
30475
30924
|
}
|