@codexhost/cli-linux-arm64 0.18.0 → 0.19.0
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 +1 -1
- package/app/codexhost-distribution.json +1 -1
- package/app/console-server.mjs +59 -2
- package/app/console-web.js +76 -4
- package/app/desktop-controller.mjs +274 -11
- package/app/host-runtime.mjs +12322 -2469
- package/app/plugins/antigravity/plugin.mjs +654 -216
- package/app/plugins/claude-code/plugin.mjs +138 -11
- package/app/plugins/codebuddy/plugin.mjs +152 -20
- package/app/plugins/codex-usage/plugin.mjs +59 -2
- package/app/plugins/copilot/plugin.mjs +59 -2
- package/app/plugins/cursor-cli/plugin.mjs +134 -12
- package/app/plugins/deepseek-harness/manifest.json +2 -2
- package/app/plugins/deepseek-harness/plugin.mjs +86 -7
- package/app/plugins/devin/plugin.mjs +59 -2
- package/app/plugins/grok/plugin.mjs +392 -269
- package/app/plugins/hermes/plugin.mjs +138 -14
- package/app/plugins/kimi-code/plugin.mjs +59 -2
- package/app/plugins/kiro-cli/plugin.mjs +287 -18
- package/app/plugins/omp/plugin.mjs +788 -627
- package/app/plugins/opencode/plugin.mjs +59 -2
- package/app/plugins/pi/plugin.mjs +899 -773
- package/app/plugins/qoder/plugin.mjs +61 -6
- package/app/plugins/qoder-cn/plugin.mjs +61 -6
- package/app/plugins/qwen-code/plugin.mjs +168 -94
- package/app/plugins/workbuddy/plugin.mjs +152 -20
- package/app/plugins/zcode/plugin.mjs +132 -5
- package/app/renderer-extension.js +657 -270
- package/app/web/assets/index-BNQIOOHE.css +1 -0
- package/app/web/assets/index-Feo4BkqN.js +199 -0
- package/app/web/codexhost-settings.js +76 -4
- package/app/web/index.html +2 -2
- package/app/web/plugins/deepseek-ai__dsh-api-remotes/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-api-session-controller/client.js +8 -8
- package/app/web/plugins/deepseek-ai__dsh-client-file-upload/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-locale/client.js +3 -3
- package/app/web/plugins/deepseek-ai__dsh-client-ui-attachment/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-chat/client.js +129 -8
- package/app/web/plugins/deepseek-ai__dsh-client-ui-codexhost/client.js +65 -63
- package/app/web/plugins/deepseek-ai__dsh-client-ui-conversation/client.js +95 -93
- package/app/web/plugins/deepseek-ai__dsh-client-ui-input-trigger/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-layout/client.js +2 -2
- package/app/web/plugins/deepseek-ai__dsh-client-ui-model-selection/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-settings-general/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-sidebar-documentpreview/client.excel.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-sidebar-files/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-tool/client.js +16 -16
- package/app/web/plugins/deepseek-ai__dsh-client-ui-user-questions/client.js +1 -1
- package/app/web/plugins/deepseek-ai__dsh-client-ui-workspace/client.js +11 -11
- package/app/web-modules/server.mjs +2339 -1514
- package/bin/codexhost +0 -0
- package/libexec/codexhost-shim +0 -0
- package/libexec/codexhost-updater +0 -0
- package/package.json +1 -1
- package/app/web/assets/index-C0aXz2jD.js +0 -199
- package/app/web/assets/index-C3lniEH1.css +0 -1
|
@@ -408,149 +408,6 @@ function createHarnessInstaller(environment, source) {
|
|
|
408
408
|
};
|
|
409
409
|
}
|
|
410
410
|
|
|
411
|
-
// ../../harness-adapter/dist/usage-statistics.js
|
|
412
|
-
import { createReadStream } from "node:fs";
|
|
413
|
-
import { lstat, opendir } from "node:fs/promises";
|
|
414
|
-
import path4 from "node:path";
|
|
415
|
-
import { createInterface } from "node:readline";
|
|
416
|
-
var MAX_SESSION_ID_LENGTH = 512;
|
|
417
|
-
var MAX_CWD_LENGTH = 4096;
|
|
418
|
-
var MAX_SESSION_TITLE_LENGTH = 200;
|
|
419
|
-
function usageSessionTitle(value) {
|
|
420
|
-
if (typeof value !== "string")
|
|
421
|
-
return void 0;
|
|
422
|
-
const normalized = value.replaceAll("\0", "").replaceAll(/\s+/gu, " ").trim();
|
|
423
|
-
if (!normalized)
|
|
424
|
-
return void 0;
|
|
425
|
-
if (normalized.length <= MAX_SESSION_TITLE_LENGTH)
|
|
426
|
-
return normalized;
|
|
427
|
-
let title = "";
|
|
428
|
-
for (const character of normalized) {
|
|
429
|
-
if (title.length + character.length >= MAX_SESSION_TITLE_LENGTH)
|
|
430
|
-
break;
|
|
431
|
-
title += character;
|
|
432
|
-
}
|
|
433
|
-
return `${title.trimEnd()}…`;
|
|
434
|
-
}
|
|
435
|
-
function sessionIdOk(value) {
|
|
436
|
-
return typeof value === "string" && value.length > 0 && value.length <= MAX_SESSION_ID_LENGTH;
|
|
437
|
-
}
|
|
438
|
-
function cwdOk(value) {
|
|
439
|
-
return typeof value === "string" && value.length > 0 && value.length <= MAX_CWD_LENGTH && !value.includes("\0") && (value.startsWith("/") || /^[A-Za-z]:[\\/]/u.test(value) || value.startsWith("\\\\"));
|
|
440
|
-
}
|
|
441
|
-
function withUsageSession(entry, session) {
|
|
442
|
-
const sessionId = sessionIdOk(session.sessionId) ? session.sessionId : void 0;
|
|
443
|
-
const cwd = cwdOk(session.cwd) ? session.cwd : void 0;
|
|
444
|
-
const sessionTitle = sessionId !== void 0 ? usageSessionTitle(session.title) : void 0;
|
|
445
|
-
if (sessionId === void 0 && cwd === void 0)
|
|
446
|
-
return entry;
|
|
447
|
-
return {
|
|
448
|
-
...entry,
|
|
449
|
-
...sessionId !== void 0 ? { sessionId } : {},
|
|
450
|
-
...cwd !== void 0 ? { cwd } : {},
|
|
451
|
-
...sessionTitle !== void 0 ? { sessionTitle } : {}
|
|
452
|
-
};
|
|
453
|
-
}
|
|
454
|
-
function usageEntryFromRequest(request, occurredAtMs) {
|
|
455
|
-
if (!Number.isSafeInteger(occurredAtMs) || occurredAtMs <= 0)
|
|
456
|
-
return null;
|
|
457
|
-
return {
|
|
458
|
-
id: request.requestId,
|
|
459
|
-
occurredAtMs,
|
|
460
|
-
...request.model !== void 0 ? { model: request.model } : {},
|
|
461
|
-
inputTokens: request.inputTokens,
|
|
462
|
-
...request.cachedInputTokens !== void 0 ? { cachedInputTokens: request.cachedInputTokens } : {},
|
|
463
|
-
...request.cacheWriteInputTokens !== void 0 ? { cacheWriteInputTokens: request.cacheWriteInputTokens } : {},
|
|
464
|
-
...request.cacheWrite1hInputTokens !== void 0 ? { cacheWrite1hInputTokens: request.cacheWrite1hInputTokens } : {},
|
|
465
|
-
outputTokens: request.outputTokens,
|
|
466
|
-
...request.reasoningOutputTokens !== void 0 ? { reasoningOutputTokens: request.reasoningOutputTokens } : {}
|
|
467
|
-
};
|
|
468
|
-
}
|
|
469
|
-
async function jsonlUsageSources(root, maxDepth, signal) {
|
|
470
|
-
const sources = [];
|
|
471
|
-
const visit = async (directory, depth) => {
|
|
472
|
-
signal.throwIfAborted();
|
|
473
|
-
const entries = await opendir(directory).catch((error51) => {
|
|
474
|
-
if (error51.code === "ENOENT")
|
|
475
|
-
return null;
|
|
476
|
-
throw error51;
|
|
477
|
-
});
|
|
478
|
-
if (!entries)
|
|
479
|
-
return;
|
|
480
|
-
for await (const entry of entries) {
|
|
481
|
-
signal.throwIfAborted();
|
|
482
|
-
const file2 = path4.join(directory, entry.name);
|
|
483
|
-
if (entry.isDirectory()) {
|
|
484
|
-
if (depth < maxDepth)
|
|
485
|
-
await visit(file2, depth + 1);
|
|
486
|
-
} else if (entry.isFile() && entry.name.endsWith(".jsonl")) {
|
|
487
|
-
const info = await lstat(file2).catch(() => null);
|
|
488
|
-
if (info?.isFile() && info.size > 0) {
|
|
489
|
-
sources.push({ id: file2, fingerprint: `${info.ino}:${info.size}:${info.mtimeMs}` });
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
};
|
|
494
|
-
await visit(root, 0);
|
|
495
|
-
return sources;
|
|
496
|
-
}
|
|
497
|
-
async function* jsonlRecords(file2, marker, signal) {
|
|
498
|
-
const lines = createInterface({
|
|
499
|
-
input: createReadStream(file2, { encoding: "utf8", signal }),
|
|
500
|
-
crlfDelay: Infinity
|
|
501
|
-
});
|
|
502
|
-
for await (const line of lines) {
|
|
503
|
-
if (!line.includes(marker))
|
|
504
|
-
continue;
|
|
505
|
-
let value;
|
|
506
|
-
try {
|
|
507
|
-
value = JSON.parse(line);
|
|
508
|
-
} catch {
|
|
509
|
-
continue;
|
|
510
|
-
}
|
|
511
|
-
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
512
|
-
yield value;
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
async function jsonlHeader(file2, match, signal, maxLines = 4) {
|
|
517
|
-
const stream = createReadStream(file2, { encoding: "utf8", signal });
|
|
518
|
-
const lines = createInterface({ input: stream, crlfDelay: Infinity });
|
|
519
|
-
let seen = 0;
|
|
520
|
-
try {
|
|
521
|
-
for await (const line of lines) {
|
|
522
|
-
if (++seen > maxLines)
|
|
523
|
-
break;
|
|
524
|
-
let value;
|
|
525
|
-
try {
|
|
526
|
-
value = JSON.parse(line);
|
|
527
|
-
} catch {
|
|
528
|
-
continue;
|
|
529
|
-
}
|
|
530
|
-
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
531
|
-
const record10 = value;
|
|
532
|
-
if (match(record10))
|
|
533
|
-
return record10;
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
return null;
|
|
537
|
-
} finally {
|
|
538
|
-
lines.close();
|
|
539
|
-
stream.destroy();
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
function nativeTimeMs(value) {
|
|
543
|
-
const time3 = typeof value === "number" ? value : typeof value === "string" ? Date.parse(value) : Number.NaN;
|
|
544
|
-
return Number.isFinite(time3) && time3 > 0 ? Math.floor(time3) : null;
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
// dist/pi-session-import.js
|
|
548
|
-
import { createReadStream as createReadStream2 } from "node:fs";
|
|
549
|
-
import { opendir as opendir2, realpath, stat } from "node:fs/promises";
|
|
550
|
-
import os2 from "node:os";
|
|
551
|
-
import path5 from "node:path";
|
|
552
|
-
import { createInterface as createInterface2 } from "node:readline";
|
|
553
|
-
|
|
554
411
|
// ../../../node_modules/zod/v4/classic/external.js
|
|
555
412
|
var external_exports = {};
|
|
556
413
|
__export(external_exports, {
|
|
@@ -15644,6 +15501,10 @@ var CLIENT_CHANNEL_VERSION = 1;
|
|
|
15644
15501
|
var CLIENT_REQUEST_LIMIT_BYTES = 128 * 1024 * 1024;
|
|
15645
15502
|
var clientThreadPinsSchema = external_exports.object({ threadIds: external_exports.array(external_exports.string().min(1)) }).strict();
|
|
15646
15503
|
var clientThreadPinParamsSchema = external_exports.object({ threadId: external_exports.string().min(1).max(1024), pinned: external_exports.boolean() }).strict();
|
|
15504
|
+
var clientThreadTreeReadParamsSchema = external_exports.object({}).strict();
|
|
15505
|
+
var clientThreadTreeSchema = external_exports.object({
|
|
15506
|
+
parents: external_exports.record(external_exports.string().min(1), external_exports.string().min(1))
|
|
15507
|
+
}).strict();
|
|
15647
15508
|
var clientProjectlessWorkspaceSchema = external_exports.object({
|
|
15648
15509
|
prompt: external_exports.string().max(16384).optional()
|
|
15649
15510
|
}).strict();
|
|
@@ -15660,6 +15521,11 @@ var clientChannelCursorSchema = external_exports.object({
|
|
|
15660
15521
|
sequence: external_exports.number().int().nonnegative()
|
|
15661
15522
|
});
|
|
15662
15523
|
var clientChannelEventSchema = external_exports.discriminatedUnion("type", [
|
|
15524
|
+
external_exports.object({
|
|
15525
|
+
type: external_exports.literal("skills-changed"),
|
|
15526
|
+
cursor: clientChannelCursorSchema,
|
|
15527
|
+
cwd: external_exports.string().optional()
|
|
15528
|
+
}),
|
|
15663
15529
|
external_exports.object({ type: external_exports.literal("display-settings-changed"), cursor: clientChannelCursorSchema }),
|
|
15664
15530
|
external_exports.object({
|
|
15665
15531
|
type: external_exports.literal("preferences-changed"),
|
|
@@ -15857,6 +15723,28 @@ var voiceTranscribeResultSchema = external_exports.discriminatedUnion("ok", [
|
|
|
15857
15723
|
external_exports.object({ ok: external_exports.literal(false), error: external_exports.object({ code: voiceErrorCodeSchema }).strict() }).strict()
|
|
15858
15724
|
]);
|
|
15859
15725
|
|
|
15726
|
+
// ../../shared-contracts/dist/skills.js
|
|
15727
|
+
var skillsListParamsSchema = external_exports.object({
|
|
15728
|
+
threadId: hostThreadIdSchema.optional(),
|
|
15729
|
+
cwd: external_exports.string().min(1).optional()
|
|
15730
|
+
}).strict().refine((params) => !(params.threadId && params.cwd), {
|
|
15731
|
+
message: "Specify threadId or cwd, not both"
|
|
15732
|
+
});
|
|
15733
|
+
var librarySkillSchema = external_exports.object({
|
|
15734
|
+
name: external_exports.string().min(1).regex(/^[^\s[\]]+$/u),
|
|
15735
|
+
description: external_exports.string().optional(),
|
|
15736
|
+
path: external_exports.string().min(1),
|
|
15737
|
+
scope: external_exports.enum(["project", "global"]),
|
|
15738
|
+
source: external_exports.string().min(1)
|
|
15739
|
+
}).strict();
|
|
15740
|
+
var skillsListResultSchema = external_exports.object({
|
|
15741
|
+
revision: external_exports.number().int().nonnegative(),
|
|
15742
|
+
complete: external_exports.boolean(),
|
|
15743
|
+
skills: external_exports.array(librarySkillSchema),
|
|
15744
|
+
warnings: external_exports.array(external_exports.string()).optional()
|
|
15745
|
+
}).strict();
|
|
15746
|
+
var skillsChangedParamsSchema = external_exports.object({ cwd: external_exports.string().min(1).optional() }).strict();
|
|
15747
|
+
|
|
15860
15748
|
// ../../shared-contracts/dist/web-access-tokens.js
|
|
15861
15749
|
var webNetworkAccessUrlSchema = external_exports.object({
|
|
15862
15750
|
/**
|
|
@@ -15962,8 +15850,8 @@ var REMOTE_THREAD_REPLY_MAX_BYTES = 16 * 1024 * 1024;
|
|
|
15962
15850
|
var delegationReadParamsSchema = external_exports.strictObject({
|
|
15963
15851
|
threadId: external_exports.string().min(1).max(1024),
|
|
15964
15852
|
view: external_exports.enum(["result", "messages"]),
|
|
15965
|
-
|
|
15966
|
-
|
|
15853
|
+
from: external_exports.number().int().min(1).max(Number.MAX_SAFE_INTEGER).optional(),
|
|
15854
|
+
to: external_exports.number().int().min(1).max(Number.MAX_SAFE_INTEGER).optional()
|
|
15967
15855
|
});
|
|
15968
15856
|
|
|
15969
15857
|
// ../../shared-contracts/dist/credential-imports.js
|
|
@@ -16916,6 +16804,17 @@ var updateStatusResultSchema = external_exports.strictObject({
|
|
|
16916
16804
|
status: updateStatusSchema.nullable()
|
|
16917
16805
|
});
|
|
16918
16806
|
|
|
16807
|
+
// ../../shared-contracts/dist/thread-watch-notice.js
|
|
16808
|
+
var THREAD_WATCH_NOTICE_OUTCOMES = [
|
|
16809
|
+
"completed",
|
|
16810
|
+
"failed",
|
|
16811
|
+
"interrupted",
|
|
16812
|
+
"timedOut",
|
|
16813
|
+
"unreadable",
|
|
16814
|
+
"notFound"
|
|
16815
|
+
];
|
|
16816
|
+
var ENTRY_PATTERN = new RegExp(String.raw`^- \[([^\]\n]+)\]\(thread://([^\s()<>"?#/]+)\): ` + `(${THREAD_WATCH_NOTICE_OUTCOMES.join("|")})(?:. (.+))?$`, "u");
|
|
16817
|
+
|
|
16919
16818
|
// ../../shared-contracts/dist/remote-runtime.js
|
|
16920
16819
|
var remoteUpdatePhaseSchema = external_exports.enum([
|
|
16921
16820
|
"idle",
|
|
@@ -16963,6 +16862,14 @@ var remoteSessionOperationSchema = external_exports.discriminatedUnion("kind", [
|
|
|
16963
16862
|
archived: external_exports.boolean()
|
|
16964
16863
|
}),
|
|
16965
16864
|
external_exports.strictObject({ kind: external_exports.literal("read"), ...thread }),
|
|
16865
|
+
external_exports.strictObject({
|
|
16866
|
+
kind: external_exports.literal("configure"),
|
|
16867
|
+
...thread,
|
|
16868
|
+
epoch: identity,
|
|
16869
|
+
modelId: identity.optional(),
|
|
16870
|
+
thinkingOptionId: identity.optional(),
|
|
16871
|
+
permissionModeId: identity.optional()
|
|
16872
|
+
}).refine((value) => [value.modelId, value.thinkingOptionId, value.permissionModeId].filter((v) => v !== void 0).length === 1, "Select exactly one remote setting"),
|
|
16966
16873
|
external_exports.strictObject({
|
|
16967
16874
|
kind: external_exports.literal("prompt"),
|
|
16968
16875
|
...thread,
|
|
@@ -17035,6 +16942,13 @@ var remoteConnectionsReplySchema = external_exports.union([
|
|
|
17035
16942
|
external_exports.strictObject({ error: external_exports.strictObject({ code: external_exports.number().int(), message: external_exports.string() }) })
|
|
17036
16943
|
]);
|
|
17037
16944
|
|
|
16945
|
+
// ../../shared-contracts/dist/thread-title.js
|
|
16946
|
+
var threadTitleInputSchema = external_exports.strictObject({
|
|
16947
|
+
prompt: external_exports.string().trim().min(1).max(2e3),
|
|
16948
|
+
cwd: external_exports.string().max(4096).nullable()
|
|
16949
|
+
});
|
|
16950
|
+
var threadTitleResultSchema = external_exports.string().trim().min(1).max(60).nullable();
|
|
16951
|
+
|
|
17038
16952
|
// ../../shared-contracts/dist/web-ui-extensions.js
|
|
17039
16953
|
var webUiExtensionIdSchema = external_exports.string().max(214).regex(/^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/u);
|
|
17040
16954
|
var localizedTextSchema2 = external_exports.union([
|
|
@@ -17078,468 +16992,160 @@ var webUiExtensionRemoveSchema = external_exports.object({ id: webUiExtensionIdS
|
|
|
17078
16992
|
// ../../shared-contracts/dist/index.js
|
|
17079
16993
|
var workspaceContractVersionSchema = external_exports.literal(WORKSPACE_CONTRACT_VERSION);
|
|
17080
16994
|
|
|
17081
|
-
// ../../harness-adapter/dist/
|
|
17082
|
-
|
|
17083
|
-
|
|
17084
|
-
super(message3);
|
|
17085
|
-
this.name = "SessionImportChangedError";
|
|
17086
|
-
}
|
|
17087
|
-
};
|
|
17088
|
-
function isMissingFileError(error51) {
|
|
17089
|
-
return typeof error51 === "object" && error51 !== null && "code" in error51 && error51.code === "ENOENT";
|
|
17090
|
-
}
|
|
17091
|
-
function sameFileFingerprint(left, right) {
|
|
17092
|
-
return left === null || right === null ? left === right : left.dev === right.dev && left.ino === right.ino && left.size === right.size && left.mtimeMs === right.mtimeMs && left.ctimeMs === right.ctimeMs;
|
|
17093
|
-
}
|
|
17094
|
-
function sessionImportTitle(value, maxLength = HARNESS_SESSION_IMPORT_TITLE_MAX_LENGTH) {
|
|
17095
|
-
if (typeof value !== "string")
|
|
17096
|
-
return null;
|
|
17097
|
-
const normalized = value.replaceAll("\0", "").replaceAll(/\s+/gu, " ").trim();
|
|
17098
|
-
if (!normalized)
|
|
17099
|
-
return null;
|
|
17100
|
-
if (normalized.length <= maxLength)
|
|
17101
|
-
return normalized;
|
|
17102
|
-
const characters = [...normalized];
|
|
17103
|
-
if (characters.length <= maxLength)
|
|
17104
|
-
return normalized;
|
|
17105
|
-
return `${characters.slice(0, maxLength - 1).join("").trimEnd()}…`;
|
|
17106
|
-
}
|
|
17107
|
-
function sessionImportCandidate(input) {
|
|
17108
|
-
const time3 = typeof input.updatedAt === "number" ? input.updatedAt : typeof input.updatedAt === "string" ? Date.parse(input.updatedAt) : Number.NaN;
|
|
17109
|
-
const parsed = harnessSessionImportCandidateSchema.safeParse({
|
|
17110
|
-
nativeSessionId: input.nativeSessionId,
|
|
17111
|
-
cwd: input.cwd,
|
|
17112
|
-
title: typeof input.title === "string" && input.title.trim().length > 0 ? input.title : null,
|
|
17113
|
-
updatedAt: Math.floor(time3),
|
|
17114
|
-
// Unknown must stay unknown; only an explicit boolean is a native statement.
|
|
17115
|
-
running: typeof input.running === "boolean" ? input.running : null
|
|
17116
|
-
});
|
|
17117
|
-
return parsed.success ? parsed.data : null;
|
|
16995
|
+
// ../../harness-adapter/dist/question.js
|
|
16996
|
+
function invalidRequest(message3) {
|
|
16997
|
+
return { code: "invalidRequest", message: message3, retryable: false };
|
|
17118
16998
|
}
|
|
17119
|
-
|
|
17120
|
-
|
|
17121
|
-
|
|
17122
|
-
|
|
17123
|
-
constructor(options) {
|
|
17124
|
-
this.#options = options;
|
|
16999
|
+
function validateHostQuestionResponse(interaction, response) {
|
|
17000
|
+
const questionIds = new Set(interaction.questions.map(({ id }) => id));
|
|
17001
|
+
if (response.cancelled) {
|
|
17002
|
+
return Object.keys(response.answers).length === 0 ? null : invalidRequest("Cancelled Question Response must not contain answers");
|
|
17125
17003
|
}
|
|
17126
|
-
|
|
17127
|
-
|
|
17128
|
-
|
|
17129
|
-
|
|
17130
|
-
};
|
|
17004
|
+
for (const answerId of Object.keys(response.answers)) {
|
|
17005
|
+
if (!questionIds.has(answerId)) {
|
|
17006
|
+
return invalidRequest("Question Response contains an unknown Question ID");
|
|
17007
|
+
}
|
|
17131
17008
|
}
|
|
17132
|
-
|
|
17133
|
-
const
|
|
17134
|
-
if (
|
|
17135
|
-
return
|
|
17136
|
-
let started;
|
|
17137
|
-
try {
|
|
17138
|
-
started = operation(signal);
|
|
17139
|
-
} catch (error51) {
|
|
17140
|
-
started = Promise.reject(error51 instanceof Error ? error51 : new Error("Session read failed"));
|
|
17009
|
+
for (const question of interaction.questions) {
|
|
17010
|
+
const answers = response.answers[question.id] ?? [];
|
|
17011
|
+
if (!question.optional && answers.length === 0) {
|
|
17012
|
+
return invalidRequest("Question Response omits a required answer");
|
|
17141
17013
|
}
|
|
17142
|
-
|
|
17143
|
-
|
|
17144
|
-
|
|
17145
|
-
code: "unavailable",
|
|
17146
|
-
message: this.#options.unavailableMessage,
|
|
17147
|
-
retryable: true
|
|
17014
|
+
if (question.type === "text") {
|
|
17015
|
+
if (answers.length > 1) {
|
|
17016
|
+
return invalidRequest("Text Question accepts at most one answer");
|
|
17148
17017
|
}
|
|
17149
|
-
|
|
17150
|
-
|
|
17151
|
-
|
|
17018
|
+
continue;
|
|
17019
|
+
}
|
|
17020
|
+
if (!question.multiple && answers.length > 1) {
|
|
17021
|
+
return invalidRequest("Single-choice Question accepts at most one answer");
|
|
17022
|
+
}
|
|
17023
|
+
const declared = new Set(question.options.map(({ value }) => value));
|
|
17024
|
+
if (!question.allowOther && answers.some((answer) => !declared.has(answer))) {
|
|
17025
|
+
return invalidRequest("Question Response contains an undeclared choice");
|
|
17026
|
+
}
|
|
17152
17027
|
}
|
|
17153
|
-
|
|
17154
|
-
|
|
17155
|
-
|
|
17156
|
-
|
|
17157
|
-
|
|
17158
|
-
|
|
17159
|
-
|
|
17160
|
-
|
|
17161
|
-
|
|
17162
|
-
|
|
17163
|
-
|
|
17028
|
+
return null;
|
|
17029
|
+
}
|
|
17030
|
+
|
|
17031
|
+
// ../../harness-adapter/dist/output-channel.js
|
|
17032
|
+
var HarnessOutputChannel = class {
|
|
17033
|
+
outputs;
|
|
17034
|
+
#consumerCreated = false;
|
|
17035
|
+
#ended = false;
|
|
17036
|
+
#pending = [];
|
|
17037
|
+
#values = [];
|
|
17038
|
+
constructor() {
|
|
17039
|
+
this.outputs = {
|
|
17040
|
+
[Symbol.asyncIterator]: () => {
|
|
17041
|
+
if (this.#consumerCreated) {
|
|
17042
|
+
throw new Error("Harness outputs allow only one consumer");
|
|
17043
|
+
}
|
|
17044
|
+
this.#consumerCreated = true;
|
|
17045
|
+
return {
|
|
17046
|
+
next: () => this.#next()
|
|
17047
|
+
};
|
|
17164
17048
|
}
|
|
17165
17049
|
};
|
|
17166
17050
|
}
|
|
17167
|
-
|
|
17168
|
-
|
|
17169
|
-
|
|
17170
|
-
|
|
17051
|
+
emit(value) {
|
|
17052
|
+
if (this.#ended)
|
|
17053
|
+
return false;
|
|
17054
|
+
const resolve = this.#pending.shift();
|
|
17055
|
+
if (resolve)
|
|
17056
|
+
resolve({ done: false, value });
|
|
17057
|
+
else
|
|
17058
|
+
this.#values.push(value);
|
|
17059
|
+
return true;
|
|
17060
|
+
}
|
|
17061
|
+
end() {
|
|
17062
|
+
if (this.#ended)
|
|
17063
|
+
return;
|
|
17064
|
+
this.#ended = true;
|
|
17065
|
+
if (this.#values.length !== 0)
|
|
17066
|
+
return;
|
|
17067
|
+
for (const resolve of this.#pending.splice(0))
|
|
17068
|
+
resolve({ done: true, value: void 0 });
|
|
17069
|
+
}
|
|
17070
|
+
#next() {
|
|
17071
|
+
const value = this.#values.shift();
|
|
17072
|
+
if (value !== void 0)
|
|
17073
|
+
return Promise.resolve({ done: false, value });
|
|
17074
|
+
if (this.#ended)
|
|
17075
|
+
return Promise.resolve({ done: true, value: void 0 });
|
|
17076
|
+
return new Promise((resolve) => this.#pending.push(resolve));
|
|
17171
17077
|
}
|
|
17172
17078
|
};
|
|
17173
17079
|
|
|
17174
|
-
// dist/
|
|
17175
|
-
var
|
|
17176
|
-
|
|
17177
|
-
|
|
17178
|
-
|
|
17179
|
-
|
|
17180
|
-
return
|
|
17080
|
+
// ../../harness-adapter/dist/diagnostics.js
|
|
17081
|
+
var DIAGNOSTIC_TAIL_MAX_LENGTH = 8e3;
|
|
17082
|
+
var SENSITIVE_VALUE_PATTERN = /(api[_-]?key|access[_-]?token|auth(?:orization)?|password|secret)(\s*[:=]\s*)([^\s,;]+)/giu;
|
|
17083
|
+
var BEARER_PATTERN = /\bBearer\s+[A-Za-z0-9._~+/=-]+/giu;
|
|
17084
|
+
function sanitizeDiagnosticTail(value) {
|
|
17085
|
+
const redacted = value.replace(BEARER_PATTERN, "Bearer [redacted]").replace(SENSITIVE_VALUE_PATTERN, "$1$2[redacted]");
|
|
17086
|
+
return redacted.length <= DIAGNOSTIC_TAIL_MAX_LENGTH ? redacted : redacted.slice(-DIAGNOSTIC_TAIL_MAX_LENGTH);
|
|
17181
17087
|
}
|
|
17182
|
-
|
|
17183
|
-
|
|
17184
|
-
|
|
17185
|
-
if (custom2)
|
|
17186
|
-
return { directory: expandDirectory(custom2, home), flat: true };
|
|
17187
|
-
const agent = environment.PI_CODING_AGENT_DIR;
|
|
17088
|
+
|
|
17089
|
+
// ../../harness-adapter/dist/steer.js
|
|
17090
|
+
function unsupportedSteer(harnessLabel) {
|
|
17188
17091
|
return {
|
|
17189
|
-
|
|
17190
|
-
|
|
17191
|
-
|
|
17192
|
-
}
|
|
17193
|
-
|
|
17194
|
-
const files = [];
|
|
17195
|
-
const visit = async (dir, projectLevel) => {
|
|
17196
|
-
signal.throwIfAborted();
|
|
17197
|
-
const entries = await opendir2(dir).catch((error51) => {
|
|
17198
|
-
if (isMissingFileError(error51))
|
|
17199
|
-
return null;
|
|
17200
|
-
throw error51;
|
|
17201
|
-
});
|
|
17202
|
-
if (!entries)
|
|
17203
|
-
return;
|
|
17204
|
-
for await (const entry of entries) {
|
|
17205
|
-
signal.throwIfAborted();
|
|
17206
|
-
if (projectLevel && entry.isDirectory())
|
|
17207
|
-
await visit(path5.join(dir, entry.name), false);
|
|
17208
|
-
else if (!projectLevel && entry.isFile() && entry.name.endsWith(".jsonl")) {
|
|
17209
|
-
files.push(path5.join(dir, entry.name));
|
|
17210
|
-
}
|
|
17092
|
+
ok: false,
|
|
17093
|
+
error: {
|
|
17094
|
+
code: "unsupported",
|
|
17095
|
+
message: `${harnessLabel} cannot steer an active Turn natively`,
|
|
17096
|
+
retryable: false
|
|
17211
17097
|
}
|
|
17212
17098
|
};
|
|
17213
|
-
await visit(directory, !flat);
|
|
17214
|
-
return files;
|
|
17215
17099
|
}
|
|
17216
|
-
|
|
17217
|
-
|
|
17218
|
-
|
|
17219
|
-
|
|
17220
|
-
|
|
17221
|
-
|
|
17222
|
-
|
|
17223
|
-
|
|
17224
|
-
|
|
17225
|
-
|
|
17226
|
-
|
|
17227
|
-
|
|
17228
|
-
|
|
17229
|
-
|
|
17230
|
-
|
|
17231
|
-
|
|
17232
|
-
|
|
17233
|
-
|
|
17234
|
-
|
|
17235
|
-
|
|
17236
|
-
|
|
17237
|
-
|
|
17238
|
-
|
|
17239
|
-
|
|
17240
|
-
|
|
17241
|
-
|
|
17242
|
-
|
|
17243
|
-
|
|
17244
|
-
|
|
17245
|
-
|
|
17246
|
-
|
|
17247
|
-
|
|
17248
|
-
|
|
17249
|
-
|
|
17250
|
-
|
|
17251
|
-
|
|
17252
|
-
|
|
17253
|
-
|
|
17254
|
-
|
|
17255
|
-
hasUser = entry.type === "message" && message3?.role === "user" || typeof entry.parentId === "string" && entries.get(entry.parentId) === true;
|
|
17256
|
-
entries.set(entry.id, hasUser);
|
|
17257
|
-
if (entry.type === "session_info")
|
|
17258
|
-
name = sessionImportTitle(entry.name);
|
|
17259
|
-
if (entry.type === "message" && (message3?.role === "user" || message3?.role === "assistant")) {
|
|
17260
|
-
const time3 = typeof message3.timestamp === "number" ? message3.timestamp : typeof entry.timestamp === "string" ? Date.parse(entry.timestamp) : NaN;
|
|
17261
|
-
if (Number.isFinite(time3))
|
|
17262
|
-
updatedAt = time3;
|
|
17263
|
-
}
|
|
17264
|
-
}
|
|
17265
|
-
} finally {
|
|
17266
|
-
lines.close();
|
|
17267
|
-
stream.destroy();
|
|
17268
|
-
}
|
|
17269
|
-
if (!header)
|
|
17270
|
-
return null;
|
|
17271
|
-
if (!hasUser)
|
|
17272
|
-
return null;
|
|
17273
|
-
const after = await stat(file2);
|
|
17274
|
-
if (!sameFileFingerprint(before, after))
|
|
17275
|
-
throw new SessionImportChangedError(PI_SESSION_CHANGED);
|
|
17276
|
-
const cwd = await realpath(String(header.cwd));
|
|
17277
|
-
if (!(await stat(cwd)).isDirectory())
|
|
17278
|
-
return null;
|
|
17279
|
-
const nativeRef = nativeSessionRefSchema.safeParse({
|
|
17280
|
-
harnessId: "pi",
|
|
17281
|
-
nativeSessionId: header.id,
|
|
17282
|
-
locator: { sessionFile: await realpath(file2) },
|
|
17283
|
-
formatVersion: 1
|
|
17284
|
-
});
|
|
17285
|
-
const candidate = sessionImportCandidate({
|
|
17286
|
-
nativeSessionId: header.id,
|
|
17287
|
-
cwd,
|
|
17288
|
-
title: name ?? firstMessage,
|
|
17289
|
-
updatedAt
|
|
17290
|
-
});
|
|
17291
|
-
return candidate && nativeRef.success ? { candidate, nativeRef: nativeRef.data } : null;
|
|
17100
|
+
|
|
17101
|
+
// ../../harness-adapter/dist/usage.js
|
|
17102
|
+
var tokenFields = [
|
|
17103
|
+
"inputTokens",
|
|
17104
|
+
"cachedInputTokens",
|
|
17105
|
+
"cacheWriteInputTokens",
|
|
17106
|
+
"outputTokens",
|
|
17107
|
+
"reasoningOutputTokens",
|
|
17108
|
+
"totalTokens",
|
|
17109
|
+
"contextWindowTokens",
|
|
17110
|
+
"contextUsedTokens"
|
|
17111
|
+
];
|
|
17112
|
+
var safeIntegerFields = [
|
|
17113
|
+
"planFiveHourResetsAtUnix",
|
|
17114
|
+
"planSevenDayResetsAtUnix",
|
|
17115
|
+
"timeToFirstOutputMs"
|
|
17116
|
+
];
|
|
17117
|
+
var percentFields = [
|
|
17118
|
+
"cacheHitRatePercent",
|
|
17119
|
+
"sessionCacheHitRatePercent",
|
|
17120
|
+
"planFiveHourUsedPercent",
|
|
17121
|
+
"planSevenDayUsedPercent"
|
|
17122
|
+
];
|
|
17123
|
+
var usageFields = /* @__PURE__ */ new Set([
|
|
17124
|
+
...tokenFields,
|
|
17125
|
+
...safeIntegerFields,
|
|
17126
|
+
...percentFields,
|
|
17127
|
+
"sessionCacheUsage",
|
|
17128
|
+
"composerIndicators",
|
|
17129
|
+
"totalCostUsd",
|
|
17130
|
+
"totalCredits",
|
|
17131
|
+
"contextUsagePercent",
|
|
17132
|
+
"outputTokensPerSecond",
|
|
17133
|
+
"apiOutputTokensPerSecond",
|
|
17134
|
+
"costSource",
|
|
17135
|
+
"unpricedModels"
|
|
17136
|
+
]);
|
|
17137
|
+
function isRecord(value) {
|
|
17138
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17292
17139
|
}
|
|
17293
|
-
|
|
17294
|
-
|
|
17295
|
-
|
|
17296
|
-
|
|
17297
|
-
|
|
17298
|
-
|
|
17299
|
-
|
|
17300
|
-
|
|
17301
|
-
|
|
17302
|
-
try {
|
|
17303
|
-
header = JSON.parse(line);
|
|
17304
|
-
} catch {
|
|
17305
|
-
return null;
|
|
17306
|
-
}
|
|
17307
|
-
return isRecord(header) && header.type === "session" && header.version === 3 && typeof header.id === "string" ? header.id : null;
|
|
17308
|
-
}
|
|
17309
|
-
return null;
|
|
17310
|
-
} finally {
|
|
17311
|
-
lines.close();
|
|
17312
|
-
stream.destroy();
|
|
17313
|
-
}
|
|
17314
|
-
}
|
|
17315
|
-
var PiSessionImportIndex = class {
|
|
17316
|
-
#location;
|
|
17317
|
-
#cache = /* @__PURE__ */ new Map();
|
|
17318
|
-
#listing;
|
|
17319
|
-
constructor(environment) {
|
|
17320
|
-
this.#location = piSessionImportDirectory(environment);
|
|
17321
|
-
}
|
|
17322
|
-
list(signal) {
|
|
17323
|
-
this.#listing ??= this.#scan(signal).finally(() => {
|
|
17324
|
-
this.#listing = void 0;
|
|
17325
|
-
});
|
|
17326
|
-
return this.#listing;
|
|
17327
|
-
}
|
|
17328
|
-
async #scan(signal) {
|
|
17329
|
-
const { directory, flat } = this.#location;
|
|
17330
|
-
const files = await sessionFiles(directory, flat, signal);
|
|
17331
|
-
const next = /* @__PURE__ */ new Map();
|
|
17332
|
-
const identities = /* @__PURE__ */ new Set();
|
|
17333
|
-
const sources = [];
|
|
17334
|
-
for (const file2 of files) {
|
|
17335
|
-
signal.throwIfAborted();
|
|
17336
|
-
try {
|
|
17337
|
-
const fingerprint = await stat(file2);
|
|
17338
|
-
const cached2 = this.#cache.get(file2);
|
|
17339
|
-
const source = cached2 && sameFileFingerprint(cached2.fingerprint, fingerprint) ? cached2.source : await readCandidate(file2, signal);
|
|
17340
|
-
if (!source)
|
|
17341
|
-
continue;
|
|
17342
|
-
if (!(await stat(source.candidate.cwd)).isDirectory())
|
|
17343
|
-
continue;
|
|
17344
|
-
if (identities.has(source.nativeRef.nativeSessionId))
|
|
17345
|
-
throw new Error("Pi Session identity is ambiguous across files");
|
|
17346
|
-
identities.add(source.nativeRef.nativeSessionId);
|
|
17347
|
-
next.set(file2, { fingerprint, source });
|
|
17348
|
-
sources.push(source);
|
|
17349
|
-
} catch (error51) {
|
|
17350
|
-
if (!isMissingFileError(error51) && !(error51 instanceof SessionImportChangedError))
|
|
17351
|
-
throw error51;
|
|
17352
|
-
}
|
|
17353
|
-
}
|
|
17354
|
-
this.#cache = next;
|
|
17355
|
-
return structuredClone(sources.sort((left, right) => right.candidate.updatedAt - left.candidate.updatedAt));
|
|
17356
|
-
}
|
|
17357
|
-
async resolve(nativeSessionId, signal) {
|
|
17358
|
-
const { directory, flat } = this.#location;
|
|
17359
|
-
let selected;
|
|
17360
|
-
for (const file2 of await sessionFiles(directory, flat, signal)) {
|
|
17361
|
-
signal.throwIfAborted();
|
|
17362
|
-
try {
|
|
17363
|
-
const fingerprint = await stat(file2);
|
|
17364
|
-
const cached2 = this.#cache.get(file2);
|
|
17365
|
-
const id = cached2 && sameFileFingerprint(cached2.fingerprint, fingerprint) ? cached2.source.nativeRef.nativeSessionId : await readIdentity(file2, signal);
|
|
17366
|
-
if (id !== nativeSessionId)
|
|
17367
|
-
continue;
|
|
17368
|
-
if (selected)
|
|
17369
|
-
throw new Error("Pi Session identity is ambiguous across files");
|
|
17370
|
-
selected = file2;
|
|
17371
|
-
} catch (error51) {
|
|
17372
|
-
if (!isMissingFileError(error51))
|
|
17373
|
-
throw error51;
|
|
17374
|
-
}
|
|
17375
|
-
}
|
|
17376
|
-
if (!selected)
|
|
17377
|
-
return null;
|
|
17378
|
-
try {
|
|
17379
|
-
const source = await readCandidate(selected, signal);
|
|
17380
|
-
return source?.nativeRef.nativeSessionId === nativeSessionId ? source : null;
|
|
17381
|
-
} catch (error51) {
|
|
17382
|
-
if (isMissingFileError(error51))
|
|
17383
|
-
return null;
|
|
17384
|
-
throw error51;
|
|
17385
|
-
}
|
|
17386
|
-
}
|
|
17387
|
-
};
|
|
17388
|
-
|
|
17389
|
-
// ../../harness-adapter/dist/question.js
|
|
17390
|
-
function invalidRequest(message3) {
|
|
17391
|
-
return { code: "invalidRequest", message: message3, retryable: false };
|
|
17392
|
-
}
|
|
17393
|
-
function validateHostQuestionResponse(interaction, response) {
|
|
17394
|
-
const questionIds = new Set(interaction.questions.map(({ id }) => id));
|
|
17395
|
-
if (response.cancelled) {
|
|
17396
|
-
return Object.keys(response.answers).length === 0 ? null : invalidRequest("Cancelled Question Response must not contain answers");
|
|
17397
|
-
}
|
|
17398
|
-
for (const answerId of Object.keys(response.answers)) {
|
|
17399
|
-
if (!questionIds.has(answerId)) {
|
|
17400
|
-
return invalidRequest("Question Response contains an unknown Question ID");
|
|
17401
|
-
}
|
|
17402
|
-
}
|
|
17403
|
-
for (const question of interaction.questions) {
|
|
17404
|
-
const answers = response.answers[question.id] ?? [];
|
|
17405
|
-
if (!question.optional && answers.length === 0) {
|
|
17406
|
-
return invalidRequest("Question Response omits a required answer");
|
|
17407
|
-
}
|
|
17408
|
-
if (question.type === "text") {
|
|
17409
|
-
if (answers.length > 1) {
|
|
17410
|
-
return invalidRequest("Text Question accepts at most one answer");
|
|
17411
|
-
}
|
|
17412
|
-
continue;
|
|
17413
|
-
}
|
|
17414
|
-
if (!question.multiple && answers.length > 1) {
|
|
17415
|
-
return invalidRequest("Single-choice Question accepts at most one answer");
|
|
17416
|
-
}
|
|
17417
|
-
const declared = new Set(question.options.map(({ value }) => value));
|
|
17418
|
-
if (!question.allowOther && answers.some((answer) => !declared.has(answer))) {
|
|
17419
|
-
return invalidRequest("Question Response contains an undeclared choice");
|
|
17420
|
-
}
|
|
17421
|
-
}
|
|
17422
|
-
return null;
|
|
17423
|
-
}
|
|
17424
|
-
|
|
17425
|
-
// ../../harness-adapter/dist/output-channel.js
|
|
17426
|
-
var HarnessOutputChannel = class {
|
|
17427
|
-
outputs;
|
|
17428
|
-
#consumerCreated = false;
|
|
17429
|
-
#ended = false;
|
|
17430
|
-
#pending = [];
|
|
17431
|
-
#values = [];
|
|
17432
|
-
constructor() {
|
|
17433
|
-
this.outputs = {
|
|
17434
|
-
[Symbol.asyncIterator]: () => {
|
|
17435
|
-
if (this.#consumerCreated) {
|
|
17436
|
-
throw new Error("Harness outputs allow only one consumer");
|
|
17437
|
-
}
|
|
17438
|
-
this.#consumerCreated = true;
|
|
17439
|
-
return {
|
|
17440
|
-
next: () => this.#next()
|
|
17441
|
-
};
|
|
17442
|
-
}
|
|
17443
|
-
};
|
|
17444
|
-
}
|
|
17445
|
-
emit(value) {
|
|
17446
|
-
if (this.#ended)
|
|
17447
|
-
return false;
|
|
17448
|
-
const resolve = this.#pending.shift();
|
|
17449
|
-
if (resolve)
|
|
17450
|
-
resolve({ done: false, value });
|
|
17451
|
-
else
|
|
17452
|
-
this.#values.push(value);
|
|
17453
|
-
return true;
|
|
17454
|
-
}
|
|
17455
|
-
end() {
|
|
17456
|
-
if (this.#ended)
|
|
17457
|
-
return;
|
|
17458
|
-
this.#ended = true;
|
|
17459
|
-
if (this.#values.length !== 0)
|
|
17460
|
-
return;
|
|
17461
|
-
for (const resolve of this.#pending.splice(0))
|
|
17462
|
-
resolve({ done: true, value: void 0 });
|
|
17463
|
-
}
|
|
17464
|
-
#next() {
|
|
17465
|
-
const value = this.#values.shift();
|
|
17466
|
-
if (value !== void 0)
|
|
17467
|
-
return Promise.resolve({ done: false, value });
|
|
17468
|
-
if (this.#ended)
|
|
17469
|
-
return Promise.resolve({ done: true, value: void 0 });
|
|
17470
|
-
return new Promise((resolve) => this.#pending.push(resolve));
|
|
17471
|
-
}
|
|
17472
|
-
};
|
|
17473
|
-
|
|
17474
|
-
// ../../harness-adapter/dist/diagnostics.js
|
|
17475
|
-
var DIAGNOSTIC_TAIL_MAX_LENGTH = 8e3;
|
|
17476
|
-
var SENSITIVE_VALUE_PATTERN = /(api[_-]?key|access[_-]?token|auth(?:orization)?|password|secret)(\s*[:=]\s*)([^\s,;]+)/giu;
|
|
17477
|
-
var BEARER_PATTERN = /\bBearer\s+[A-Za-z0-9._~+/=-]+/giu;
|
|
17478
|
-
function sanitizeDiagnosticTail(value) {
|
|
17479
|
-
const redacted = value.replace(BEARER_PATTERN, "Bearer [redacted]").replace(SENSITIVE_VALUE_PATTERN, "$1$2[redacted]");
|
|
17480
|
-
return redacted.length <= DIAGNOSTIC_TAIL_MAX_LENGTH ? redacted : redacted.slice(-DIAGNOSTIC_TAIL_MAX_LENGTH);
|
|
17481
|
-
}
|
|
17482
|
-
|
|
17483
|
-
// ../../harness-adapter/dist/steer.js
|
|
17484
|
-
function unsupportedSteer(harnessLabel) {
|
|
17485
|
-
return {
|
|
17486
|
-
ok: false,
|
|
17487
|
-
error: {
|
|
17488
|
-
code: "unsupported",
|
|
17489
|
-
message: `${harnessLabel} cannot steer an active Turn natively`,
|
|
17490
|
-
retryable: false
|
|
17491
|
-
}
|
|
17492
|
-
};
|
|
17493
|
-
}
|
|
17494
|
-
|
|
17495
|
-
// ../../harness-adapter/dist/usage.js
|
|
17496
|
-
var tokenFields = [
|
|
17497
|
-
"inputTokens",
|
|
17498
|
-
"cachedInputTokens",
|
|
17499
|
-
"cacheWriteInputTokens",
|
|
17500
|
-
"outputTokens",
|
|
17501
|
-
"reasoningOutputTokens",
|
|
17502
|
-
"totalTokens",
|
|
17503
|
-
"contextWindowTokens",
|
|
17504
|
-
"contextUsedTokens"
|
|
17505
|
-
];
|
|
17506
|
-
var safeIntegerFields = [
|
|
17507
|
-
"planFiveHourResetsAtUnix",
|
|
17508
|
-
"planSevenDayResetsAtUnix",
|
|
17509
|
-
"timeToFirstOutputMs"
|
|
17510
|
-
];
|
|
17511
|
-
var percentFields = [
|
|
17512
|
-
"cacheHitRatePercent",
|
|
17513
|
-
"sessionCacheHitRatePercent",
|
|
17514
|
-
"planFiveHourUsedPercent",
|
|
17515
|
-
"planSevenDayUsedPercent"
|
|
17516
|
-
];
|
|
17517
|
-
var usageFields = /* @__PURE__ */ new Set([
|
|
17518
|
-
...tokenFields,
|
|
17519
|
-
...safeIntegerFields,
|
|
17520
|
-
...percentFields,
|
|
17521
|
-
"sessionCacheUsage",
|
|
17522
|
-
"composerIndicators",
|
|
17523
|
-
"totalCostUsd",
|
|
17524
|
-
"totalCredits",
|
|
17525
|
-
"contextUsagePercent",
|
|
17526
|
-
"outputTokensPerSecond",
|
|
17527
|
-
"apiOutputTokensPerSecond",
|
|
17528
|
-
"costSource",
|
|
17529
|
-
"unpricedModels"
|
|
17530
|
-
]);
|
|
17531
|
-
function isRecord2(value) {
|
|
17532
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17533
|
-
}
|
|
17534
|
-
function parseHostUsage(value) {
|
|
17535
|
-
if (!isRecord2(value))
|
|
17536
|
-
throw new Error("Harness Usage must be an object");
|
|
17537
|
-
const keys = Object.keys(value);
|
|
17538
|
-
if (keys.length === 0)
|
|
17539
|
-
throw new Error("Harness Usage must contain a reliable field");
|
|
17540
|
-
for (const key of keys) {
|
|
17541
|
-
if (!usageFields.has(key)) {
|
|
17542
|
-
throw new Error(`Harness Usage contains unknown field '${key}'`);
|
|
17140
|
+
function parseHostUsage(value) {
|
|
17141
|
+
if (!isRecord(value))
|
|
17142
|
+
throw new Error("Harness Usage must be an object");
|
|
17143
|
+
const keys = Object.keys(value);
|
|
17144
|
+
if (keys.length === 0)
|
|
17145
|
+
throw new Error("Harness Usage must contain a reliable field");
|
|
17146
|
+
for (const key of keys) {
|
|
17147
|
+
if (!usageFields.has(key)) {
|
|
17148
|
+
throw new Error(`Harness Usage contains unknown field '${key}'`);
|
|
17543
17149
|
}
|
|
17544
17150
|
}
|
|
17545
17151
|
const indicators = value.composerIndicators === void 0 ? {} : { composerIndicators: composerIndicatorsSchema.parse(value.composerIndicators) };
|
|
@@ -17579,7 +17185,7 @@ function parseHostUsage(value) {
|
|
|
17579
17185
|
}
|
|
17580
17186
|
if (value.sessionCacheUsage !== void 0) {
|
|
17581
17187
|
const totals2 = value.sessionCacheUsage;
|
|
17582
|
-
if (!
|
|
17188
|
+
if (!isRecord(totals2) || Object.keys(totals2).some((key) => key !== "inputTokens" && key !== "cachedInputTokens") || typeof totals2.inputTokens !== "number" || !Number.isSafeInteger(totals2.inputTokens) || totals2.inputTokens < 0 || typeof totals2.cachedInputTokens !== "number" || !Number.isSafeInteger(totals2.cachedInputTokens) || totals2.cachedInputTokens < 0 || totals2.cachedInputTokens > totals2.inputTokens) {
|
|
17583
17189
|
throw new Error("Harness Usage 'sessionCacheUsage' must contain complete bounded token totals");
|
|
17584
17190
|
}
|
|
17585
17191
|
}
|
|
@@ -17613,192 +17219,694 @@ function parseHostUsage(value) {
|
|
|
17613
17219
|
if (value.costSource !== "publicPrice") {
|
|
17614
17220
|
throw new Error("Harness Usage 'unpricedModels' must be provided with a 'publicPrice' cost");
|
|
17615
17221
|
}
|
|
17616
|
-
return { ...value, ...indicators, unpricedModels: [...models] };
|
|
17222
|
+
return { ...value, ...indicators, unpricedModels: [...models] };
|
|
17223
|
+
}
|
|
17224
|
+
return { ...value, ...indicators };
|
|
17225
|
+
}
|
|
17226
|
+
var requestTokenFields = [
|
|
17227
|
+
"inputTokens",
|
|
17228
|
+
"cachedInputTokens",
|
|
17229
|
+
"cacheWriteInputTokens",
|
|
17230
|
+
"cacheWrite1hInputTokens",
|
|
17231
|
+
"outputTokens",
|
|
17232
|
+
"reasoningOutputTokens",
|
|
17233
|
+
"startedAtMs",
|
|
17234
|
+
"completedAtMs"
|
|
17235
|
+
];
|
|
17236
|
+
var requestFields = /* @__PURE__ */ new Set([
|
|
17237
|
+
...requestTokenFields,
|
|
17238
|
+
"requestId",
|
|
17239
|
+
"historical",
|
|
17240
|
+
"model",
|
|
17241
|
+
"provider"
|
|
17242
|
+
]);
|
|
17243
|
+
function parseHostUsageRequest(value) {
|
|
17244
|
+
if (!isRecord(value))
|
|
17245
|
+
throw new Error("Harness Usage request must be an object");
|
|
17246
|
+
for (const key of Object.keys(value)) {
|
|
17247
|
+
if (!requestFields.has(key)) {
|
|
17248
|
+
throw new Error(`Harness Usage request contains unknown field '${key}'`);
|
|
17249
|
+
}
|
|
17250
|
+
}
|
|
17251
|
+
if (typeof value.requestId !== "string" || value.requestId.length === 0) {
|
|
17252
|
+
throw new Error("Harness Usage request 'requestId' must be a non-empty string");
|
|
17253
|
+
}
|
|
17254
|
+
for (const field2 of ["model", "provider"]) {
|
|
17255
|
+
const candidate = value[field2];
|
|
17256
|
+
if (candidate !== void 0 && (typeof candidate !== "string" || candidate.length === 0)) {
|
|
17257
|
+
throw new Error(`Harness Usage request '${field2}' must be a non-empty string`);
|
|
17258
|
+
}
|
|
17259
|
+
}
|
|
17260
|
+
if (value.historical !== void 0 && typeof value.historical !== "boolean") {
|
|
17261
|
+
throw new Error("Harness Usage request 'historical' must be a boolean");
|
|
17262
|
+
}
|
|
17263
|
+
for (const field2 of requestTokenFields) {
|
|
17264
|
+
const candidate = value[field2];
|
|
17265
|
+
if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isSafeInteger(candidate) || candidate < 0)) {
|
|
17266
|
+
throw new Error(`Harness Usage request '${field2}' must be a non-negative safe integer`);
|
|
17267
|
+
}
|
|
17268
|
+
}
|
|
17269
|
+
if (value.inputTokens === void 0 || value.outputTokens === void 0) {
|
|
17270
|
+
throw new Error("Harness Usage request must contain 'inputTokens' and 'outputTokens'");
|
|
17271
|
+
}
|
|
17272
|
+
const request = value;
|
|
17273
|
+
if ((request.cachedInputTokens ?? 0) + (request.cacheWriteInputTokens ?? 0) > request.inputTokens) {
|
|
17274
|
+
throw new Error("Harness Usage request cache Tokens must not exceed 'inputTokens'");
|
|
17275
|
+
}
|
|
17276
|
+
if ((request.reasoningOutputTokens ?? 0) > request.outputTokens) {
|
|
17277
|
+
throw new Error("Harness Usage request 'reasoningOutputTokens' must not exceed 'outputTokens'");
|
|
17278
|
+
}
|
|
17279
|
+
if (request.cacheWrite1hInputTokens !== void 0 && request.cacheWrite1hInputTokens > (request.cacheWriteInputTokens ?? -1)) {
|
|
17280
|
+
throw new Error("Harness Usage request 'cacheWrite1hInputTokens' must not exceed 'cacheWriteInputTokens'");
|
|
17281
|
+
}
|
|
17282
|
+
if (request.startedAtMs === void 0 !== (request.completedAtMs === void 0)) {
|
|
17283
|
+
throw new Error("Harness Usage request timing fields must be provided together");
|
|
17284
|
+
}
|
|
17285
|
+
if (request.startedAtMs !== void 0 && request.completedAtMs !== void 0 && request.completedAtMs < request.startedAtMs) {
|
|
17286
|
+
throw new Error("Harness Usage request 'completedAtMs' must not precede 'startedAtMs'");
|
|
17287
|
+
}
|
|
17288
|
+
return { ...request };
|
|
17289
|
+
}
|
|
17290
|
+
|
|
17291
|
+
// ../../harness-adapter/dist/live-command-catalog.js
|
|
17292
|
+
var COMMON_EXCLUDED_LIVE_COMMANDS = /* @__PURE__ */ new Set([
|
|
17293
|
+
// Session lifecycle
|
|
17294
|
+
"branch",
|
|
17295
|
+
"clear",
|
|
17296
|
+
"exit",
|
|
17297
|
+
"fork",
|
|
17298
|
+
"fresh",
|
|
17299
|
+
"new",
|
|
17300
|
+
"quit",
|
|
17301
|
+
"rename",
|
|
17302
|
+
"rename-chat",
|
|
17303
|
+
"reset",
|
|
17304
|
+
"resume",
|
|
17305
|
+
"rewind",
|
|
17306
|
+
"session",
|
|
17307
|
+
"sessions",
|
|
17308
|
+
// Desktop-owned configuration
|
|
17309
|
+
"autocompact",
|
|
17310
|
+
"color",
|
|
17311
|
+
"config",
|
|
17312
|
+
"effort",
|
|
17313
|
+
"fast",
|
|
17314
|
+
"keybindings",
|
|
17315
|
+
"model",
|
|
17316
|
+
"models",
|
|
17317
|
+
"output-style",
|
|
17318
|
+
"permissions",
|
|
17319
|
+
"settings",
|
|
17320
|
+
"statusline",
|
|
17321
|
+
"terminal-setup",
|
|
17322
|
+
"theme",
|
|
17323
|
+
"vim",
|
|
17324
|
+
// Trust and approval policy
|
|
17325
|
+
"always-approve",
|
|
17326
|
+
"auto-mode-setup",
|
|
17327
|
+
// Native login
|
|
17328
|
+
"login",
|
|
17329
|
+
"logout",
|
|
17330
|
+
// Work outliving the Turn
|
|
17331
|
+
"autopilot",
|
|
17332
|
+
"background",
|
|
17333
|
+
"bg",
|
|
17334
|
+
"goal",
|
|
17335
|
+
"jobs",
|
|
17336
|
+
"loop",
|
|
17337
|
+
"multitask",
|
|
17338
|
+
"queue",
|
|
17339
|
+
"remote-control",
|
|
17340
|
+
"schedule",
|
|
17341
|
+
"steer",
|
|
17342
|
+
// Native terminal UI
|
|
17343
|
+
"copy",
|
|
17344
|
+
"debug",
|
|
17345
|
+
"feedback",
|
|
17346
|
+
"heapdump",
|
|
17347
|
+
"share",
|
|
17348
|
+
"shell",
|
|
17349
|
+
// Plugin and MCP management
|
|
17350
|
+
"marketplace",
|
|
17351
|
+
"mcp",
|
|
17352
|
+
"plugins",
|
|
17353
|
+
"reload-plugins"
|
|
17354
|
+
]);
|
|
17355
|
+
var COMMON_EXCLUDED_LIVE_COMMAND_PREFIXES = ["__", "hooks-"];
|
|
17356
|
+
function isExcludedLiveCommand(name, extra = {}) {
|
|
17357
|
+
const normalized = name.trim().replace(/^\//u, "");
|
|
17358
|
+
if (new Set(extra.names ?? []).has(normalized))
|
|
17359
|
+
return true;
|
|
17360
|
+
if (extra.prefixes?.some((prefix) => normalized.startsWith(prefix)))
|
|
17361
|
+
return true;
|
|
17362
|
+
return COMMON_EXCLUDED_LIVE_COMMANDS.has(normalized) || COMMON_EXCLUDED_LIVE_COMMAND_PREFIXES.some((prefix) => normalized.startsWith(prefix));
|
|
17363
|
+
}
|
|
17364
|
+
function liveHarnessCommandPrompt(catalog, idPrefix, commandId, argumentText) {
|
|
17365
|
+
if (!commandId.startsWith(idPrefix))
|
|
17366
|
+
return null;
|
|
17367
|
+
const descriptor = catalog.commands.find(({ id }) => id === commandId);
|
|
17368
|
+
if (!descriptor)
|
|
17369
|
+
return null;
|
|
17370
|
+
const text4 = typeof argumentText === "string" ? argumentText.trim() : "";
|
|
17371
|
+
return text4 ? `${descriptor.invocation} ${text4}` : descriptor.invocation;
|
|
17372
|
+
}
|
|
17373
|
+
function mergeLiveHarnessCommands(builtIns, idPrefix, live, exclusions = {}) {
|
|
17374
|
+
if (!live)
|
|
17375
|
+
return builtIns;
|
|
17376
|
+
const invocations = new Set(builtIns.commands.map(({ invocation }) => invocation));
|
|
17377
|
+
const ids = new Set(builtIns.commands.map(({ id }) => id));
|
|
17378
|
+
const dynamic = [];
|
|
17379
|
+
for (const command of live) {
|
|
17380
|
+
const name = command.name.trim().replace(/^\//u, "");
|
|
17381
|
+
if (!name || /\s/u.test(name))
|
|
17382
|
+
continue;
|
|
17383
|
+
if (isExcludedLiveCommand(name, exclusions))
|
|
17384
|
+
continue;
|
|
17385
|
+
const invocation = `/${name}`;
|
|
17386
|
+
const id = `${idPrefix}${name.replace(/[^A-Za-z0-9._:-]/gu, "-")}`.slice(0, 128);
|
|
17387
|
+
if (invocations.has(invocation) || ids.has(id))
|
|
17388
|
+
continue;
|
|
17389
|
+
const description = command.description?.trim().slice(0, 512);
|
|
17390
|
+
const parsed = harnessCommandDescriptorSchema.safeParse({
|
|
17391
|
+
id,
|
|
17392
|
+
invocation,
|
|
17393
|
+
label: name.slice(0, 128),
|
|
17394
|
+
...description ? { description } : {},
|
|
17395
|
+
argumentMode: "text"
|
|
17396
|
+
});
|
|
17397
|
+
if (!parsed.success)
|
|
17398
|
+
continue;
|
|
17399
|
+
invocations.add(invocation);
|
|
17400
|
+
ids.add(id);
|
|
17401
|
+
dynamic.push(parsed.data);
|
|
17402
|
+
}
|
|
17403
|
+
return harnessCommandCatalogSchema.parse({ commands: [...builtIns.commands, ...dynamic] });
|
|
17404
|
+
}
|
|
17405
|
+
|
|
17406
|
+
// ../../harness-adapter/dist/subagent-configuration.js
|
|
17407
|
+
function subagentConfiguration(value) {
|
|
17408
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
17409
|
+
return {};
|
|
17410
|
+
const row = value;
|
|
17411
|
+
const text4 = (value2) => typeof value2 === "string" && value2.trim() ? value2 : void 0;
|
|
17412
|
+
const model2 = row.model === "inherit" ? void 0 : text4(row.model);
|
|
17413
|
+
const reasoningEffort = text4(row.reasoningEffort) ?? text4(row.reasoning_effort) ?? text4(row.thinking);
|
|
17414
|
+
return { ...model2 ? { model: model2 } : {}, ...reasoningEffort ? { reasoningEffort } : {} };
|
|
17415
|
+
}
|
|
17416
|
+
function inheritSubagentConfiguration(child, parent) {
|
|
17417
|
+
const native = subagentConfiguration(child);
|
|
17418
|
+
const model2 = native.model ?? parent.model;
|
|
17419
|
+
const reasoningEffort = native.reasoningEffort ?? parent.reasoningEffort;
|
|
17420
|
+
const next = { ...child };
|
|
17421
|
+
delete next.model;
|
|
17422
|
+
delete next.reasoningEffort;
|
|
17423
|
+
return { ...next, ...model2 ? { model: model2 } : {}, ...reasoningEffort ? { reasoningEffort } : {} };
|
|
17424
|
+
}
|
|
17425
|
+
function configureSubagentEvent(event, parent) {
|
|
17426
|
+
const children = (states2) => states2.map((child) => inheritSubagentConfiguration(child, parent));
|
|
17427
|
+
if (event.type === "item.started" && event.item.type === "subagentDelegation")
|
|
17428
|
+
return { ...event, item: { ...event.item, subagents: children(event.item.subagents) } };
|
|
17429
|
+
if (event.type === "item.updated" && event.update.type === "subagents.replace")
|
|
17430
|
+
return { ...event, update: { ...event.update, subagents: children(event.update.subagents) } };
|
|
17431
|
+
if (event.type === "item.completed" && event.snapshot.item.type === "subagentDelegation")
|
|
17432
|
+
return {
|
|
17433
|
+
...event,
|
|
17434
|
+
snapshot: {
|
|
17435
|
+
...event.snapshot,
|
|
17436
|
+
item: {
|
|
17437
|
+
...event.snapshot.item,
|
|
17438
|
+
subagents: children(event.snapshot.item.subagents)
|
|
17439
|
+
}
|
|
17440
|
+
}
|
|
17441
|
+
};
|
|
17442
|
+
return event;
|
|
17443
|
+
}
|
|
17444
|
+
function configureSubagentSnapshot(snapshot, parent) {
|
|
17445
|
+
return {
|
|
17446
|
+
...snapshot,
|
|
17447
|
+
turns: snapshot.turns.map((turn) => ({
|
|
17448
|
+
...turn,
|
|
17449
|
+
items: turn.items.map((entry) => entry.item.type === "subagentDelegation" ? {
|
|
17450
|
+
...entry,
|
|
17451
|
+
item: {
|
|
17452
|
+
...entry.item,
|
|
17453
|
+
subagents: entry.item.subagents.map((child) => inheritSubagentConfiguration(child, parent))
|
|
17454
|
+
}
|
|
17455
|
+
} : entry)
|
|
17456
|
+
}))
|
|
17457
|
+
};
|
|
17458
|
+
}
|
|
17459
|
+
|
|
17460
|
+
// ../../harness-adapter/dist/usage-statistics.js
|
|
17461
|
+
import { createReadStream } from "node:fs";
|
|
17462
|
+
import { lstat, opendir } from "node:fs/promises";
|
|
17463
|
+
import path4 from "node:path";
|
|
17464
|
+
import { createInterface } from "node:readline";
|
|
17465
|
+
var MAX_SESSION_ID_LENGTH = 512;
|
|
17466
|
+
var MAX_CWD_LENGTH = 4096;
|
|
17467
|
+
var MAX_SESSION_TITLE_LENGTH = 200;
|
|
17468
|
+
function usageSessionTitle(value) {
|
|
17469
|
+
if (typeof value !== "string")
|
|
17470
|
+
return void 0;
|
|
17471
|
+
const normalized = value.replaceAll("\0", "").replaceAll(/\s+/gu, " ").trim();
|
|
17472
|
+
if (!normalized)
|
|
17473
|
+
return void 0;
|
|
17474
|
+
if (normalized.length <= MAX_SESSION_TITLE_LENGTH)
|
|
17475
|
+
return normalized;
|
|
17476
|
+
let title = "";
|
|
17477
|
+
for (const character of normalized) {
|
|
17478
|
+
if (title.length + character.length >= MAX_SESSION_TITLE_LENGTH)
|
|
17479
|
+
break;
|
|
17480
|
+
title += character;
|
|
17481
|
+
}
|
|
17482
|
+
return `${title.trimEnd()}…`;
|
|
17483
|
+
}
|
|
17484
|
+
function sessionIdOk(value) {
|
|
17485
|
+
return typeof value === "string" && value.length > 0 && value.length <= MAX_SESSION_ID_LENGTH;
|
|
17486
|
+
}
|
|
17487
|
+
function cwdOk(value) {
|
|
17488
|
+
return typeof value === "string" && value.length > 0 && value.length <= MAX_CWD_LENGTH && !value.includes("\0") && (value.startsWith("/") || /^[A-Za-z]:[\\/]/u.test(value) || value.startsWith("\\\\"));
|
|
17489
|
+
}
|
|
17490
|
+
function withUsageSession(entry, session) {
|
|
17491
|
+
const sessionId = sessionIdOk(session.sessionId) ? session.sessionId : void 0;
|
|
17492
|
+
const cwd = cwdOk(session.cwd) ? session.cwd : void 0;
|
|
17493
|
+
const sessionTitle = sessionId !== void 0 ? usageSessionTitle(session.title) : void 0;
|
|
17494
|
+
if (sessionId === void 0 && cwd === void 0)
|
|
17495
|
+
return entry;
|
|
17496
|
+
return {
|
|
17497
|
+
...entry,
|
|
17498
|
+
...sessionId !== void 0 ? { sessionId } : {},
|
|
17499
|
+
...cwd !== void 0 ? { cwd } : {},
|
|
17500
|
+
...sessionTitle !== void 0 ? { sessionTitle } : {}
|
|
17501
|
+
};
|
|
17502
|
+
}
|
|
17503
|
+
function usageEntryFromRequest(request, occurredAtMs) {
|
|
17504
|
+
if (!Number.isSafeInteger(occurredAtMs) || occurredAtMs <= 0)
|
|
17505
|
+
return null;
|
|
17506
|
+
return {
|
|
17507
|
+
id: request.requestId,
|
|
17508
|
+
occurredAtMs,
|
|
17509
|
+
...request.model !== void 0 ? { model: request.model } : {},
|
|
17510
|
+
inputTokens: request.inputTokens,
|
|
17511
|
+
...request.cachedInputTokens !== void 0 ? { cachedInputTokens: request.cachedInputTokens } : {},
|
|
17512
|
+
...request.cacheWriteInputTokens !== void 0 ? { cacheWriteInputTokens: request.cacheWriteInputTokens } : {},
|
|
17513
|
+
...request.cacheWrite1hInputTokens !== void 0 ? { cacheWrite1hInputTokens: request.cacheWrite1hInputTokens } : {},
|
|
17514
|
+
outputTokens: request.outputTokens,
|
|
17515
|
+
...request.reasoningOutputTokens !== void 0 ? { reasoningOutputTokens: request.reasoningOutputTokens } : {}
|
|
17516
|
+
};
|
|
17517
|
+
}
|
|
17518
|
+
async function jsonlUsageSources(root, maxDepth, signal) {
|
|
17519
|
+
const sources = [];
|
|
17520
|
+
const visit = async (directory, depth) => {
|
|
17521
|
+
signal.throwIfAborted();
|
|
17522
|
+
const entries = await opendir(directory).catch((error51) => {
|
|
17523
|
+
if (error51.code === "ENOENT")
|
|
17524
|
+
return null;
|
|
17525
|
+
throw error51;
|
|
17526
|
+
});
|
|
17527
|
+
if (!entries)
|
|
17528
|
+
return;
|
|
17529
|
+
for await (const entry of entries) {
|
|
17530
|
+
signal.throwIfAborted();
|
|
17531
|
+
const file2 = path4.join(directory, entry.name);
|
|
17532
|
+
if (entry.isDirectory()) {
|
|
17533
|
+
if (depth < maxDepth)
|
|
17534
|
+
await visit(file2, depth + 1);
|
|
17535
|
+
} else if (entry.isFile() && entry.name.endsWith(".jsonl")) {
|
|
17536
|
+
const info = await lstat(file2).catch(() => null);
|
|
17537
|
+
if (info?.isFile() && info.size > 0) {
|
|
17538
|
+
sources.push({ id: file2, fingerprint: `${info.ino}:${info.size}:${info.mtimeMs}` });
|
|
17539
|
+
}
|
|
17540
|
+
}
|
|
17541
|
+
}
|
|
17542
|
+
};
|
|
17543
|
+
await visit(root, 0);
|
|
17544
|
+
return sources;
|
|
17545
|
+
}
|
|
17546
|
+
async function* jsonlRecords(file2, marker, signal) {
|
|
17547
|
+
const lines = createInterface({
|
|
17548
|
+
input: createReadStream(file2, { encoding: "utf8", signal }),
|
|
17549
|
+
crlfDelay: Infinity
|
|
17550
|
+
});
|
|
17551
|
+
for await (const line of lines) {
|
|
17552
|
+
if (!line.includes(marker))
|
|
17553
|
+
continue;
|
|
17554
|
+
let value;
|
|
17555
|
+
try {
|
|
17556
|
+
value = JSON.parse(line);
|
|
17557
|
+
} catch {
|
|
17558
|
+
continue;
|
|
17559
|
+
}
|
|
17560
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
17561
|
+
yield value;
|
|
17562
|
+
}
|
|
17563
|
+
}
|
|
17564
|
+
}
|
|
17565
|
+
async function jsonlHeader(file2, match, signal, maxLines = 4) {
|
|
17566
|
+
const stream = createReadStream(file2, { encoding: "utf8", signal });
|
|
17567
|
+
const lines = createInterface({ input: stream, crlfDelay: Infinity });
|
|
17568
|
+
let seen = 0;
|
|
17569
|
+
try {
|
|
17570
|
+
for await (const line of lines) {
|
|
17571
|
+
if (++seen > maxLines)
|
|
17572
|
+
break;
|
|
17573
|
+
let value;
|
|
17574
|
+
try {
|
|
17575
|
+
value = JSON.parse(line);
|
|
17576
|
+
} catch {
|
|
17577
|
+
continue;
|
|
17578
|
+
}
|
|
17579
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
17580
|
+
const record10 = value;
|
|
17581
|
+
if (match(record10))
|
|
17582
|
+
return record10;
|
|
17583
|
+
}
|
|
17584
|
+
}
|
|
17585
|
+
return null;
|
|
17586
|
+
} finally {
|
|
17587
|
+
lines.close();
|
|
17588
|
+
stream.destroy();
|
|
17589
|
+
}
|
|
17590
|
+
}
|
|
17591
|
+
function nativeTimeMs(value) {
|
|
17592
|
+
const time3 = typeof value === "number" ? value : typeof value === "string" ? Date.parse(value) : Number.NaN;
|
|
17593
|
+
return Number.isFinite(time3) && time3 > 0 ? Math.floor(time3) : null;
|
|
17594
|
+
}
|
|
17595
|
+
|
|
17596
|
+
// dist/pi-session-import.js
|
|
17597
|
+
import { createReadStream as createReadStream2 } from "node:fs";
|
|
17598
|
+
import { opendir as opendir2, realpath, stat } from "node:fs/promises";
|
|
17599
|
+
import os2 from "node:os";
|
|
17600
|
+
import path5 from "node:path";
|
|
17601
|
+
import { createInterface as createInterface2 } from "node:readline";
|
|
17602
|
+
|
|
17603
|
+
// ../../harness-adapter/dist/session-import.js
|
|
17604
|
+
var SessionImportChangedError = class extends Error {
|
|
17605
|
+
constructor(message3 = "Native Session changed during discovery; refresh and retry") {
|
|
17606
|
+
super(message3);
|
|
17607
|
+
this.name = "SessionImportChangedError";
|
|
17608
|
+
}
|
|
17609
|
+
};
|
|
17610
|
+
function isMissingFileError(error51) {
|
|
17611
|
+
return typeof error51 === "object" && error51 !== null && "code" in error51 && error51.code === "ENOENT";
|
|
17612
|
+
}
|
|
17613
|
+
function sameFileFingerprint(left, right) {
|
|
17614
|
+
return left === null || right === null ? left === right : left.dev === right.dev && left.ino === right.ino && left.size === right.size && left.mtimeMs === right.mtimeMs && left.ctimeMs === right.ctimeMs;
|
|
17615
|
+
}
|
|
17616
|
+
function sessionImportTitle(value, maxLength = HARNESS_SESSION_IMPORT_TITLE_MAX_LENGTH) {
|
|
17617
|
+
if (typeof value !== "string")
|
|
17618
|
+
return null;
|
|
17619
|
+
const normalized = value.replaceAll("\0", "").replaceAll(/\s+/gu, " ").trim();
|
|
17620
|
+
if (!normalized)
|
|
17621
|
+
return null;
|
|
17622
|
+
if (normalized.length <= maxLength)
|
|
17623
|
+
return normalized;
|
|
17624
|
+
const characters = [...normalized];
|
|
17625
|
+
if (characters.length <= maxLength)
|
|
17626
|
+
return normalized;
|
|
17627
|
+
return `${characters.slice(0, maxLength - 1).join("").trimEnd()}…`;
|
|
17628
|
+
}
|
|
17629
|
+
function sessionImportCandidate(input) {
|
|
17630
|
+
const time3 = typeof input.updatedAt === "number" ? input.updatedAt : typeof input.updatedAt === "string" ? Date.parse(input.updatedAt) : Number.NaN;
|
|
17631
|
+
const parsed = harnessSessionImportCandidateSchema.safeParse({
|
|
17632
|
+
nativeSessionId: input.nativeSessionId,
|
|
17633
|
+
cwd: input.cwd,
|
|
17634
|
+
title: typeof input.title === "string" && input.title.trim().length > 0 ? input.title : null,
|
|
17635
|
+
updatedAt: Math.floor(time3),
|
|
17636
|
+
// Unknown must stay unknown; only an explicit boolean is a native statement.
|
|
17637
|
+
running: typeof input.running === "boolean" ? input.running : null
|
|
17638
|
+
});
|
|
17639
|
+
return parsed.success ? parsed.data : null;
|
|
17640
|
+
}
|
|
17641
|
+
var SessionImportScope = class {
|
|
17642
|
+
#abort = new AbortController();
|
|
17643
|
+
#options;
|
|
17644
|
+
#pending = /* @__PURE__ */ new Set();
|
|
17645
|
+
constructor(options) {
|
|
17646
|
+
this.#options = options;
|
|
17647
|
+
}
|
|
17648
|
+
#closed() {
|
|
17649
|
+
return {
|
|
17650
|
+
ok: false,
|
|
17651
|
+
error: { code: "invalidState", message: this.#options.closedMessage, retryable: false }
|
|
17652
|
+
};
|
|
17653
|
+
}
|
|
17654
|
+
read(operation) {
|
|
17655
|
+
const signal = this.#abort.signal;
|
|
17656
|
+
if (signal.aborted)
|
|
17657
|
+
return Promise.resolve(this.#closed());
|
|
17658
|
+
let started;
|
|
17659
|
+
try {
|
|
17660
|
+
started = operation(signal);
|
|
17661
|
+
} catch (error51) {
|
|
17662
|
+
started = Promise.reject(error51 instanceof Error ? error51 : new Error("Session read failed"));
|
|
17663
|
+
}
|
|
17664
|
+
const request = started.then((value) => signal.aborted ? this.#closed() : { ok: true, value }).catch(() => signal.aborted ? this.#closed() : {
|
|
17665
|
+
ok: false,
|
|
17666
|
+
error: {
|
|
17667
|
+
code: "unavailable",
|
|
17668
|
+
message: this.#options.unavailableMessage,
|
|
17669
|
+
retryable: true
|
|
17670
|
+
}
|
|
17671
|
+
}).finally(() => this.#pending.delete(request));
|
|
17672
|
+
this.#pending.add(request);
|
|
17673
|
+
return request;
|
|
17674
|
+
}
|
|
17675
|
+
/** `read` for `resolveCandidate`: a null source is the selected Session having disappeared. */
|
|
17676
|
+
async resolve(operation) {
|
|
17677
|
+
const result = await this.read(operation);
|
|
17678
|
+
if (!result.ok)
|
|
17679
|
+
return result;
|
|
17680
|
+
return result.value ? { ok: true, value: result.value } : {
|
|
17681
|
+
ok: false,
|
|
17682
|
+
error: {
|
|
17683
|
+
code: "sessionNotFound",
|
|
17684
|
+
message: this.#options.notFoundMessage,
|
|
17685
|
+
retryable: false
|
|
17686
|
+
}
|
|
17687
|
+
};
|
|
17688
|
+
}
|
|
17689
|
+
/** Idempotent. Resolves after every started read has settled. */
|
|
17690
|
+
async close() {
|
|
17691
|
+
this.#abort.abort();
|
|
17692
|
+
await Promise.allSettled(this.#pending);
|
|
17693
|
+
}
|
|
17694
|
+
};
|
|
17695
|
+
|
|
17696
|
+
// dist/pi-session-import.js
|
|
17697
|
+
var PI_SESSION_CHANGED = "Pi Session changed during discovery; refresh and retry";
|
|
17698
|
+
function isRecord2(value) {
|
|
17699
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17700
|
+
}
|
|
17701
|
+
function expandDirectory(value, home) {
|
|
17702
|
+
return path5.resolve(value === "~" ? home : value.startsWith(`~${path5.sep}`) || value.startsWith("~/") ? path5.join(home, value.slice(2)) : value);
|
|
17703
|
+
}
|
|
17704
|
+
function piSessionImportDirectory(environment) {
|
|
17705
|
+
const home = (process.platform === "win32" ? environment.USERPROFILE : environment.HOME) || os2.homedir();
|
|
17706
|
+
const custom2 = environment.PI_CODING_AGENT_SESSION_DIR;
|
|
17707
|
+
if (custom2)
|
|
17708
|
+
return { directory: expandDirectory(custom2, home), flat: true };
|
|
17709
|
+
const agent = environment.PI_CODING_AGENT_DIR;
|
|
17710
|
+
return {
|
|
17711
|
+
directory: path5.join(agent ? expandDirectory(agent, home) : path5.join(home, ".pi", "agent"), "sessions"),
|
|
17712
|
+
flat: false
|
|
17713
|
+
};
|
|
17714
|
+
}
|
|
17715
|
+
async function sessionFiles(directory, flat, signal) {
|
|
17716
|
+
const files = [];
|
|
17717
|
+
const visit = async (dir, projectLevel) => {
|
|
17718
|
+
signal.throwIfAborted();
|
|
17719
|
+
const entries = await opendir2(dir).catch((error51) => {
|
|
17720
|
+
if (isMissingFileError(error51))
|
|
17721
|
+
return null;
|
|
17722
|
+
throw error51;
|
|
17723
|
+
});
|
|
17724
|
+
if (!entries)
|
|
17725
|
+
return;
|
|
17726
|
+
for await (const entry of entries) {
|
|
17727
|
+
signal.throwIfAborted();
|
|
17728
|
+
if (projectLevel && entry.isDirectory())
|
|
17729
|
+
await visit(path5.join(dir, entry.name), false);
|
|
17730
|
+
else if (!projectLevel && entry.isFile() && entry.name.endsWith(".jsonl")) {
|
|
17731
|
+
files.push(path5.join(dir, entry.name));
|
|
17732
|
+
}
|
|
17733
|
+
}
|
|
17734
|
+
};
|
|
17735
|
+
await visit(directory, !flat);
|
|
17736
|
+
return files;
|
|
17737
|
+
}
|
|
17738
|
+
async function readCandidate(file2, signal) {
|
|
17739
|
+
const before = await stat(file2);
|
|
17740
|
+
if (!before.isFile() || before.size === 0)
|
|
17741
|
+
return null;
|
|
17742
|
+
const stream = createReadStream2(file2, { encoding: "utf8", signal, end: before.size - 1 });
|
|
17743
|
+
const lines = createInterface2({ input: stream, crlfDelay: Infinity });
|
|
17744
|
+
let header;
|
|
17745
|
+
let name = null;
|
|
17746
|
+
let firstMessage = null;
|
|
17747
|
+
let hasUser = false;
|
|
17748
|
+
let updatedAt = before.mtimeMs;
|
|
17749
|
+
const entries = /* @__PURE__ */ new Map();
|
|
17750
|
+
try {
|
|
17751
|
+
for await (const line of lines) {
|
|
17752
|
+
signal.throwIfAborted();
|
|
17753
|
+
if (!line.trim())
|
|
17754
|
+
continue;
|
|
17755
|
+
let entry;
|
|
17756
|
+
try {
|
|
17757
|
+
entry = JSON.parse(line);
|
|
17758
|
+
} catch {
|
|
17759
|
+
return null;
|
|
17760
|
+
}
|
|
17761
|
+
if (!isRecord2(entry))
|
|
17762
|
+
return null;
|
|
17763
|
+
if (!header) {
|
|
17764
|
+
if (entry.type !== "session" || entry.version !== 3 || typeof entry.id !== "string" || typeof entry.cwd !== "string" || !path5.isAbsolute(entry.cwd))
|
|
17765
|
+
return null;
|
|
17766
|
+
header = entry;
|
|
17767
|
+
continue;
|
|
17768
|
+
}
|
|
17769
|
+
if (typeof entry.id !== "string" || entry.id.length === 0 || entries.has(entry.id) || entry.parentId !== null && (typeof entry.parentId !== "string" || !entries.has(entry.parentId)))
|
|
17770
|
+
return null;
|
|
17771
|
+
const message3 = isRecord2(entry.message) ? entry.message : null;
|
|
17772
|
+
if (!firstMessage && entry.type === "message" && message3?.role === "user") {
|
|
17773
|
+
const content = message3.content;
|
|
17774
|
+
const text4 = typeof content === "string" ? content : Array.isArray(content) ? content.filter((block) => isRecord2(block) && block.type === "text" && typeof block.text === "string").map((block) => block.text).join(" ") : "";
|
|
17775
|
+
firstMessage = sessionImportTitle(text4);
|
|
17776
|
+
}
|
|
17777
|
+
hasUser = entry.type === "message" && message3?.role === "user" || typeof entry.parentId === "string" && entries.get(entry.parentId) === true;
|
|
17778
|
+
entries.set(entry.id, hasUser);
|
|
17779
|
+
if (entry.type === "session_info")
|
|
17780
|
+
name = sessionImportTitle(entry.name);
|
|
17781
|
+
if (entry.type === "message" && (message3?.role === "user" || message3?.role === "assistant")) {
|
|
17782
|
+
const time3 = typeof message3.timestamp === "number" ? message3.timestamp : typeof entry.timestamp === "string" ? Date.parse(entry.timestamp) : NaN;
|
|
17783
|
+
if (Number.isFinite(time3))
|
|
17784
|
+
updatedAt = time3;
|
|
17785
|
+
}
|
|
17786
|
+
}
|
|
17787
|
+
} finally {
|
|
17788
|
+
lines.close();
|
|
17789
|
+
stream.destroy();
|
|
17790
|
+
}
|
|
17791
|
+
if (!header)
|
|
17792
|
+
return null;
|
|
17793
|
+
if (!hasUser)
|
|
17794
|
+
return null;
|
|
17795
|
+
const after = await stat(file2);
|
|
17796
|
+
if (!sameFileFingerprint(before, after))
|
|
17797
|
+
throw new SessionImportChangedError(PI_SESSION_CHANGED);
|
|
17798
|
+
const cwd = await realpath(String(header.cwd));
|
|
17799
|
+
if (!(await stat(cwd)).isDirectory())
|
|
17800
|
+
return null;
|
|
17801
|
+
const nativeRef = nativeSessionRefSchema.safeParse({
|
|
17802
|
+
harnessId: "pi",
|
|
17803
|
+
nativeSessionId: header.id,
|
|
17804
|
+
locator: { sessionFile: await realpath(file2) },
|
|
17805
|
+
formatVersion: 1
|
|
17806
|
+
});
|
|
17807
|
+
const candidate = sessionImportCandidate({
|
|
17808
|
+
nativeSessionId: header.id,
|
|
17809
|
+
cwd,
|
|
17810
|
+
title: name ?? firstMessage,
|
|
17811
|
+
updatedAt
|
|
17812
|
+
});
|
|
17813
|
+
return candidate && nativeRef.success ? { candidate, nativeRef: nativeRef.data } : null;
|
|
17814
|
+
}
|
|
17815
|
+
async function readIdentity(file2, signal) {
|
|
17816
|
+
const stream = createReadStream2(file2, { encoding: "utf8", signal });
|
|
17817
|
+
const lines = createInterface2({ input: stream, crlfDelay: Infinity });
|
|
17818
|
+
try {
|
|
17819
|
+
for await (const line of lines) {
|
|
17820
|
+
signal.throwIfAborted();
|
|
17821
|
+
if (!line.trim())
|
|
17822
|
+
continue;
|
|
17823
|
+
let header;
|
|
17824
|
+
try {
|
|
17825
|
+
header = JSON.parse(line);
|
|
17826
|
+
} catch {
|
|
17827
|
+
return null;
|
|
17828
|
+
}
|
|
17829
|
+
return isRecord2(header) && header.type === "session" && header.version === 3 && typeof header.id === "string" ? header.id : null;
|
|
17830
|
+
}
|
|
17831
|
+
return null;
|
|
17832
|
+
} finally {
|
|
17833
|
+
lines.close();
|
|
17834
|
+
stream.destroy();
|
|
17617
17835
|
}
|
|
17618
|
-
return { ...value, ...indicators };
|
|
17619
17836
|
}
|
|
17620
|
-
var
|
|
17621
|
-
|
|
17622
|
-
|
|
17623
|
-
|
|
17624
|
-
|
|
17625
|
-
|
|
17626
|
-
"reasoningOutputTokens",
|
|
17627
|
-
"startedAtMs",
|
|
17628
|
-
"completedAtMs"
|
|
17629
|
-
];
|
|
17630
|
-
var requestFields = /* @__PURE__ */ new Set([
|
|
17631
|
-
...requestTokenFields,
|
|
17632
|
-
"requestId",
|
|
17633
|
-
"historical",
|
|
17634
|
-
"model",
|
|
17635
|
-
"provider"
|
|
17636
|
-
]);
|
|
17637
|
-
function parseHostUsageRequest(value) {
|
|
17638
|
-
if (!isRecord2(value))
|
|
17639
|
-
throw new Error("Harness Usage request must be an object");
|
|
17640
|
-
for (const key of Object.keys(value)) {
|
|
17641
|
-
if (!requestFields.has(key)) {
|
|
17642
|
-
throw new Error(`Harness Usage request contains unknown field '${key}'`);
|
|
17643
|
-
}
|
|
17837
|
+
var PiSessionImportIndex = class {
|
|
17838
|
+
#location;
|
|
17839
|
+
#cache = /* @__PURE__ */ new Map();
|
|
17840
|
+
#listing;
|
|
17841
|
+
constructor(environment) {
|
|
17842
|
+
this.#location = piSessionImportDirectory(environment);
|
|
17644
17843
|
}
|
|
17645
|
-
|
|
17646
|
-
|
|
17844
|
+
list(signal) {
|
|
17845
|
+
this.#listing ??= this.#scan(signal).finally(() => {
|
|
17846
|
+
this.#listing = void 0;
|
|
17847
|
+
});
|
|
17848
|
+
return this.#listing;
|
|
17647
17849
|
}
|
|
17648
|
-
|
|
17649
|
-
const
|
|
17650
|
-
|
|
17651
|
-
|
|
17850
|
+
async #scan(signal) {
|
|
17851
|
+
const { directory, flat } = this.#location;
|
|
17852
|
+
const files = await sessionFiles(directory, flat, signal);
|
|
17853
|
+
const next = /* @__PURE__ */ new Map();
|
|
17854
|
+
const identities = /* @__PURE__ */ new Set();
|
|
17855
|
+
const sources = [];
|
|
17856
|
+
for (const file2 of files) {
|
|
17857
|
+
signal.throwIfAborted();
|
|
17858
|
+
try {
|
|
17859
|
+
const fingerprint = await stat(file2);
|
|
17860
|
+
const cached2 = this.#cache.get(file2);
|
|
17861
|
+
const source = cached2 && sameFileFingerprint(cached2.fingerprint, fingerprint) ? cached2.source : await readCandidate(file2, signal);
|
|
17862
|
+
if (!source)
|
|
17863
|
+
continue;
|
|
17864
|
+
if (!(await stat(source.candidate.cwd)).isDirectory())
|
|
17865
|
+
continue;
|
|
17866
|
+
if (identities.has(source.nativeRef.nativeSessionId))
|
|
17867
|
+
throw new Error("Pi Session identity is ambiguous across files");
|
|
17868
|
+
identities.add(source.nativeRef.nativeSessionId);
|
|
17869
|
+
next.set(file2, { fingerprint, source });
|
|
17870
|
+
sources.push(source);
|
|
17871
|
+
} catch (error51) {
|
|
17872
|
+
if (!isMissingFileError(error51) && !(error51 instanceof SessionImportChangedError))
|
|
17873
|
+
throw error51;
|
|
17874
|
+
}
|
|
17652
17875
|
}
|
|
17876
|
+
this.#cache = next;
|
|
17877
|
+
return structuredClone(sources.sort((left, right) => right.candidate.updatedAt - left.candidate.updatedAt));
|
|
17653
17878
|
}
|
|
17654
|
-
|
|
17655
|
-
|
|
17656
|
-
|
|
17657
|
-
|
|
17658
|
-
|
|
17659
|
-
|
|
17660
|
-
|
|
17879
|
+
async resolve(nativeSessionId, signal) {
|
|
17880
|
+
const { directory, flat } = this.#location;
|
|
17881
|
+
let selected;
|
|
17882
|
+
for (const file2 of await sessionFiles(directory, flat, signal)) {
|
|
17883
|
+
signal.throwIfAborted();
|
|
17884
|
+
try {
|
|
17885
|
+
const fingerprint = await stat(file2);
|
|
17886
|
+
const cached2 = this.#cache.get(file2);
|
|
17887
|
+
const id = cached2 && sameFileFingerprint(cached2.fingerprint, fingerprint) ? cached2.source.nativeRef.nativeSessionId : await readIdentity(file2, signal);
|
|
17888
|
+
if (id !== nativeSessionId)
|
|
17889
|
+
continue;
|
|
17890
|
+
if (selected)
|
|
17891
|
+
throw new Error("Pi Session identity is ambiguous across files");
|
|
17892
|
+
selected = file2;
|
|
17893
|
+
} catch (error51) {
|
|
17894
|
+
if (!isMissingFileError(error51))
|
|
17895
|
+
throw error51;
|
|
17896
|
+
}
|
|
17897
|
+
}
|
|
17898
|
+
if (!selected)
|
|
17899
|
+
return null;
|
|
17900
|
+
try {
|
|
17901
|
+
const source = await readCandidate(selected, signal);
|
|
17902
|
+
return source?.nativeRef.nativeSessionId === nativeSessionId ? source : null;
|
|
17903
|
+
} catch (error51) {
|
|
17904
|
+
if (isMissingFileError(error51))
|
|
17905
|
+
return null;
|
|
17906
|
+
throw error51;
|
|
17661
17907
|
}
|
|
17662
17908
|
}
|
|
17663
|
-
|
|
17664
|
-
throw new Error("Harness Usage request must contain 'inputTokens' and 'outputTokens'");
|
|
17665
|
-
}
|
|
17666
|
-
const request = value;
|
|
17667
|
-
if ((request.cachedInputTokens ?? 0) + (request.cacheWriteInputTokens ?? 0) > request.inputTokens) {
|
|
17668
|
-
throw new Error("Harness Usage request cache Tokens must not exceed 'inputTokens'");
|
|
17669
|
-
}
|
|
17670
|
-
if ((request.reasoningOutputTokens ?? 0) > request.outputTokens) {
|
|
17671
|
-
throw new Error("Harness Usage request 'reasoningOutputTokens' must not exceed 'outputTokens'");
|
|
17672
|
-
}
|
|
17673
|
-
if (request.cacheWrite1hInputTokens !== void 0 && request.cacheWrite1hInputTokens > (request.cacheWriteInputTokens ?? -1)) {
|
|
17674
|
-
throw new Error("Harness Usage request 'cacheWrite1hInputTokens' must not exceed 'cacheWriteInputTokens'");
|
|
17675
|
-
}
|
|
17676
|
-
if (request.startedAtMs === void 0 !== (request.completedAtMs === void 0)) {
|
|
17677
|
-
throw new Error("Harness Usage request timing fields must be provided together");
|
|
17678
|
-
}
|
|
17679
|
-
if (request.startedAtMs !== void 0 && request.completedAtMs !== void 0 && request.completedAtMs < request.startedAtMs) {
|
|
17680
|
-
throw new Error("Harness Usage request 'completedAtMs' must not precede 'startedAtMs'");
|
|
17681
|
-
}
|
|
17682
|
-
return { ...request };
|
|
17683
|
-
}
|
|
17684
|
-
|
|
17685
|
-
// ../../harness-adapter/dist/live-command-catalog.js
|
|
17686
|
-
var COMMON_EXCLUDED_LIVE_COMMANDS = /* @__PURE__ */ new Set([
|
|
17687
|
-
// Session lifecycle
|
|
17688
|
-
"branch",
|
|
17689
|
-
"clear",
|
|
17690
|
-
"exit",
|
|
17691
|
-
"fork",
|
|
17692
|
-
"fresh",
|
|
17693
|
-
"new",
|
|
17694
|
-
"quit",
|
|
17695
|
-
"rename",
|
|
17696
|
-
"rename-chat",
|
|
17697
|
-
"reset",
|
|
17698
|
-
"resume",
|
|
17699
|
-
"rewind",
|
|
17700
|
-
"session",
|
|
17701
|
-
"sessions",
|
|
17702
|
-
// Desktop-owned configuration
|
|
17703
|
-
"autocompact",
|
|
17704
|
-
"color",
|
|
17705
|
-
"config",
|
|
17706
|
-
"effort",
|
|
17707
|
-
"fast",
|
|
17708
|
-
"keybindings",
|
|
17709
|
-
"model",
|
|
17710
|
-
"models",
|
|
17711
|
-
"output-style",
|
|
17712
|
-
"permissions",
|
|
17713
|
-
"settings",
|
|
17714
|
-
"statusline",
|
|
17715
|
-
"terminal-setup",
|
|
17716
|
-
"theme",
|
|
17717
|
-
"vim",
|
|
17718
|
-
// Trust and approval policy
|
|
17719
|
-
"always-approve",
|
|
17720
|
-
"auto-mode-setup",
|
|
17721
|
-
// Native login
|
|
17722
|
-
"login",
|
|
17723
|
-
"logout",
|
|
17724
|
-
// Work outliving the Turn
|
|
17725
|
-
"autopilot",
|
|
17726
|
-
"background",
|
|
17727
|
-
"bg",
|
|
17728
|
-
"goal",
|
|
17729
|
-
"jobs",
|
|
17730
|
-
"loop",
|
|
17731
|
-
"multitask",
|
|
17732
|
-
"queue",
|
|
17733
|
-
"remote-control",
|
|
17734
|
-
"schedule",
|
|
17735
|
-
"steer",
|
|
17736
|
-
// Native terminal UI
|
|
17737
|
-
"copy",
|
|
17738
|
-
"debug",
|
|
17739
|
-
"feedback",
|
|
17740
|
-
"heapdump",
|
|
17741
|
-
"share",
|
|
17742
|
-
"shell",
|
|
17743
|
-
// Plugin and MCP management
|
|
17744
|
-
"marketplace",
|
|
17745
|
-
"mcp",
|
|
17746
|
-
"plugins",
|
|
17747
|
-
"reload-plugins"
|
|
17748
|
-
]);
|
|
17749
|
-
var COMMON_EXCLUDED_LIVE_COMMAND_PREFIXES = ["__", "hooks-"];
|
|
17750
|
-
function isExcludedLiveCommand(name, kind, extra = {}) {
|
|
17751
|
-
const normalized = name.trim().replace(/^\//u, "");
|
|
17752
|
-
if (new Set(extra.names ?? []).has(normalized))
|
|
17753
|
-
return true;
|
|
17754
|
-
if (extra.prefixes?.some((prefix) => normalized.startsWith(prefix)))
|
|
17755
|
-
return true;
|
|
17756
|
-
if (kind === "skill")
|
|
17757
|
-
return false;
|
|
17758
|
-
return COMMON_EXCLUDED_LIVE_COMMANDS.has(normalized) || COMMON_EXCLUDED_LIVE_COMMAND_PREFIXES.some((prefix) => normalized.startsWith(prefix));
|
|
17759
|
-
}
|
|
17760
|
-
function liveHarnessCommandPrompt(catalog, idPrefix, commandId, argumentText) {
|
|
17761
|
-
if (!commandId.startsWith(idPrefix))
|
|
17762
|
-
return null;
|
|
17763
|
-
const descriptor = catalog.commands.find(({ id }) => id === commandId);
|
|
17764
|
-
if (!descriptor)
|
|
17765
|
-
return null;
|
|
17766
|
-
const text4 = typeof argumentText === "string" ? argumentText.trim() : "";
|
|
17767
|
-
return text4 ? `${descriptor.invocation} ${text4}` : descriptor.invocation;
|
|
17768
|
-
}
|
|
17769
|
-
function mergeLiveHarnessCommands(builtIns, idPrefix, live, exclusions = {}) {
|
|
17770
|
-
if (!live)
|
|
17771
|
-
return builtIns;
|
|
17772
|
-
const invocations = new Set(builtIns.commands.map(({ invocation }) => invocation));
|
|
17773
|
-
const ids = new Set(builtIns.commands.map(({ id }) => id));
|
|
17774
|
-
const dynamic = [];
|
|
17775
|
-
for (const command of live) {
|
|
17776
|
-
const name = command.name.trim().replace(/^\//u, "");
|
|
17777
|
-
if (!name || /\s/u.test(name))
|
|
17778
|
-
continue;
|
|
17779
|
-
if (isExcludedLiveCommand(name, command.kind, exclusions))
|
|
17780
|
-
continue;
|
|
17781
|
-
const invocation = `/${name}`;
|
|
17782
|
-
const id = `${idPrefix}${name.replace(/[^A-Za-z0-9._:-]/gu, "-")}`.slice(0, 128);
|
|
17783
|
-
if (invocations.has(invocation) || ids.has(id))
|
|
17784
|
-
continue;
|
|
17785
|
-
const description = command.description?.trim().slice(0, 512);
|
|
17786
|
-
const parsed = harnessCommandDescriptorSchema.safeParse({
|
|
17787
|
-
id,
|
|
17788
|
-
invocation,
|
|
17789
|
-
label: name.slice(0, 128),
|
|
17790
|
-
...description ? { description } : {},
|
|
17791
|
-
argumentMode: "text",
|
|
17792
|
-
kind: command.kind
|
|
17793
|
-
});
|
|
17794
|
-
if (!parsed.success)
|
|
17795
|
-
continue;
|
|
17796
|
-
invocations.add(invocation);
|
|
17797
|
-
ids.add(id);
|
|
17798
|
-
dynamic.push(parsed.data);
|
|
17799
|
-
}
|
|
17800
|
-
return harnessCommandCatalogSchema.parse({ commands: [...builtIns.commands, ...dynamic] });
|
|
17801
|
-
}
|
|
17909
|
+
};
|
|
17802
17910
|
|
|
17803
17911
|
// ../../../node_modules/diff/libesm/diff/base.js
|
|
17804
17912
|
var Diff = class {
|
|
@@ -18727,6 +18835,7 @@ function gotgenesRecord(value) {
|
|
|
18727
18835
|
role: value.type,
|
|
18728
18836
|
status,
|
|
18729
18837
|
background: value.isBackground === true,
|
|
18838
|
+
...subagentConfiguration(value),
|
|
18730
18839
|
...text(value.modelName) ? { model: value.modelName } : {},
|
|
18731
18840
|
...result ? { resultSummary: result.slice(0, 2048) } : {}
|
|
18732
18841
|
},
|
|
@@ -18854,7 +18963,7 @@ var GotgenesSubagents = class {
|
|
|
18854
18963
|
this.observe([
|
|
18855
18964
|
{
|
|
18856
18965
|
...prior,
|
|
18857
|
-
child: { ...prior.child, ...parsed.child
|
|
18966
|
+
child: { ...prior.child, ...subagentConfiguration(parsed.child) }
|
|
18858
18967
|
}
|
|
18859
18968
|
]);
|
|
18860
18969
|
}
|
|
@@ -19017,6 +19126,7 @@ function node(value, depth, budget) {
|
|
|
19017
19126
|
kind: value.kind,
|
|
19018
19127
|
label: value.label,
|
|
19019
19128
|
state: value.state,
|
|
19129
|
+
...subagentConfiguration(value),
|
|
19020
19130
|
...children.length ? { children } : {}
|
|
19021
19131
|
};
|
|
19022
19132
|
}
|
|
@@ -19075,6 +19185,7 @@ function states(run) {
|
|
|
19075
19185
|
subagentId: id,
|
|
19076
19186
|
nativeSubagentId: id,
|
|
19077
19187
|
description: entry.label,
|
|
19188
|
+
...subagentConfiguration(entry),
|
|
19078
19189
|
background: true,
|
|
19079
19190
|
status: statuses[entry.state] ?? "running"
|
|
19080
19191
|
});
|
|
@@ -19121,7 +19232,7 @@ var PiSubagents = class {
|
|
|
19121
19232
|
const observed = states(run);
|
|
19122
19233
|
const retained = this.#children.get(run.id) ?? /* @__PURE__ */ new Map();
|
|
19123
19234
|
for (const child of observed)
|
|
19124
|
-
retained.set(child.subagentId, child);
|
|
19235
|
+
retained.set(child.subagentId, { ...retained.get(child.subagentId), ...child });
|
|
19125
19236
|
this.#children.set(run.id, retained);
|
|
19126
19237
|
const children = [...retained.values()];
|
|
19127
19238
|
if (!publish)
|
|
@@ -21207,10 +21318,9 @@ function parsePiNativeCommands(response) {
|
|
|
21207
21318
|
});
|
|
21208
21319
|
}
|
|
21209
21320
|
function piLiveCommandCatalog(builtIns, native) {
|
|
21210
|
-
return mergeLiveHarnessCommands(builtIns, DYNAMIC_ID_PREFIX, native?.map((command) => ({
|
|
21321
|
+
return mergeLiveHarnessCommands(builtIns, DYNAMIC_ID_PREFIX, native?.filter((command) => command.source !== "skill").map((command) => ({
|
|
21211
21322
|
name: command.name,
|
|
21212
|
-
...command.description ? { description: command.description } : {}
|
|
21213
|
-
kind: command.source === "skill" ? "skill" : "command"
|
|
21323
|
+
...command.description ? { description: command.description } : {}
|
|
21214
21324
|
})) ?? null, { names: PI_EXCLUDED_COMMANDS });
|
|
21215
21325
|
}
|
|
21216
21326
|
function piDynamicCommandPrompt(catalog, commandId, argumentText) {
|
|
@@ -21906,6 +22016,9 @@ var PiRpcSession = class {
|
|
|
21906
22016
|
child.stderr.on("data", (chunk) => {
|
|
21907
22017
|
this.#stderrTail = sanitizeDiagnosticTail(`${this.#stderrTail}${chunk.toString()}`);
|
|
21908
22018
|
});
|
|
22019
|
+
child.stdin.on("error", (error51) => {
|
|
22020
|
+
this.#fail(new PiRpcFaultError("processExited", `Pi RPC stdin closed: ${error51.message}`, this.stderrTail));
|
|
22021
|
+
});
|
|
21909
22022
|
child.once("error", (error51) => {
|
|
21910
22023
|
const kind = isRecord9(error51) && error51.code === "ENOENT" ? "notInstalled" : "unavailable";
|
|
21911
22024
|
this.#fail(new PiRpcFaultError(kind, `Pi RPC failed to start: ${error51.message}`, this.stderrTail));
|
|
@@ -23284,7 +23397,19 @@ var PiHarnessSession = class {
|
|
|
23284
23397
|
handleTransportFault(error51) {
|
|
23285
23398
|
queueMicrotask(() => this.#fault(error51));
|
|
23286
23399
|
}
|
|
23400
|
+
#subagentConfiguration() {
|
|
23401
|
+
const state2 = this.#state;
|
|
23402
|
+
const model2 = state2.effectiveModel ? decodePiModelRef(state2.effectiveModel).id : void 0;
|
|
23403
|
+
return {
|
|
23404
|
+
...model2 ? { model: model2 } : {},
|
|
23405
|
+
...state2.effectiveThinkingOptionId ? { reasoningEffort: state2.effectiveThinkingOptionId } : {}
|
|
23406
|
+
};
|
|
23407
|
+
}
|
|
23287
23408
|
async readSnapshot() {
|
|
23409
|
+
const result = await this.#readSnapshot();
|
|
23410
|
+
return result.ok ? { ok: true, value: configureSubagentSnapshot(result.value, this.#subagentConfiguration()) } : result;
|
|
23411
|
+
}
|
|
23412
|
+
async #readSnapshot() {
|
|
23288
23413
|
if (this.#phase !== "open") {
|
|
23289
23414
|
return { ok: false, error: invalidState("Pi Session is not open") };
|
|
23290
23415
|
}
|
|
@@ -24589,6 +24714,7 @@ var PiHarnessSession = class {
|
|
|
24589
24714
|
}
|
|
24590
24715
|
}
|
|
24591
24716
|
#event(event) {
|
|
24717
|
+
event = configureSubagentEvent(event, this.#subagentConfiguration());
|
|
24592
24718
|
this.#channel.emit({ kind: "event", event });
|
|
24593
24719
|
}
|
|
24594
24720
|
#newItemId() {
|