@agentknight/sdk 0.9.57 → 0.9.61
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/dist/chunks/{acp-adapter-WYDK3PLS.js → acp-adapter-MBYKOCA2.js} +4 -4
- package/dist/chunks/{chunk-OOCAIULD.js → chunk-3AMFPDE5.js} +435 -21
- package/dist/chunks/{chunk-3LEPYV7Y.js → chunk-7CNBPLNE.js} +2 -2
- package/dist/chunks/{chunk-7ZYBES47.js → chunk-7OGTK7KB.js} +1 -1
- package/dist/chunks/{chunk-WPVH7HKC.js → chunk-A4YCCQ3I.js} +1 -1
- package/dist/chunks/{chunk-EDZPP6SJ.js → chunk-ALUQLM54.js} +2 -3
- package/dist/chunks/{chunk-USI66MEF.js → chunk-CHKNC6PD.js} +3 -2
- package/dist/chunks/{chunk-ZLKFFKAX.js → chunk-CM5LVXVL.js} +4 -3
- package/dist/chunks/{chunk-IPJWNGNK.js → chunk-H4SHMWQ6.js} +1 -1
- package/dist/chunks/{chunk-KBI5IWPR.js → chunk-P2PH5KMV.js} +842 -557
- package/dist/chunks/{chunk-DAKDVZ7X.js → chunk-SIFCCGXF.js} +7 -5
- package/dist/chunks/{chunk-LT5ULDVT.js → chunk-ZNQ2I5EF.js} +1 -1
- package/dist/chunks/{claude-adapter-GCH36EZ6.js → claude-adapter-D3JWXMNX.js} +209 -59
- package/dist/chunks/{codex-adapter-CXD4SVCE.js → codex-adapter-655KHW7H.js} +4 -4
- package/dist/chunks/{copilot-adapter-SYFGOAGE.js → copilot-adapter-EZUXHBE3.js} +155 -25
- package/dist/chunks/{managed-agent-adapter-ODCNYYO6.js → managed-agent-adapter-BOJNEJ75.js} +25 -7
- package/dist/chunks/{pi-adapter-XLY46UDL.js → pi-adapter-LAD5GOCP.js} +4 -4
- package/dist/configuration.js +4 -4
- package/dist/index.d.ts +142 -1
- package/dist/index.js +1487 -578
- package/dist/runtime.js +2 -2
- package/dist/session-analytics-worker.js +162 -51
- package/package.json +1 -1
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CODING_AGENT_IDS
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-7CNBPLNE.js";
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
BYTES_PER_KIB,
|
|
6
|
+
LEGACY_SECURE_MESSAGE_MAX_CIPHERTEXT_LENGTH
|
|
7
|
+
} from "./chunk-P2PH5KMV.js";
|
|
7
8
|
|
|
8
9
|
// src/agent-selection.ts
|
|
9
10
|
import { z } from "zod";
|
|
10
11
|
var AgentSelectionSchema = z.object({
|
|
11
12
|
agents: z.array(z.enum(CODING_AGENT_IDS)).max(CODING_AGENT_IDS.length).refine((agents) => new Set(agents).size === agents.length, "Duplicate managed agent selection")
|
|
12
13
|
}).strict();
|
|
14
|
+
var SNAPSHOT_ENVELOPE_RESERVE_BYTES = 4 * BYTES_PER_KIB;
|
|
13
15
|
function assertSelectionSnapshotFits(sessions) {
|
|
14
|
-
const bytes = Buffer.byteLength(JSON.stringify(sessions), "utf8") +
|
|
15
|
-
if (Math.ceil(bytes / 3) * 4 >
|
|
16
|
+
const bytes = Buffer.byteLength(JSON.stringify(sessions), "utf8") + SNAPSHOT_ENVELOPE_RESERVE_BYTES;
|
|
17
|
+
if (Math.ceil(bytes / 3) * 4 > LEGACY_SECURE_MESSAGE_MAX_CIPHERTEXT_LENGTH) {
|
|
16
18
|
throw new Error("Selected agent session metadata exceeds the encrypted message limit. Select fewer agents.");
|
|
17
19
|
}
|
|
18
20
|
}
|
|
@@ -3,26 +3,26 @@ import {
|
|
|
3
3
|
} from "./chunk-T6226JFS.js";
|
|
4
4
|
import {
|
|
5
5
|
latestPreviewItems
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-H4SHMWQ6.js";
|
|
7
7
|
import {
|
|
8
8
|
UnsupportedAgentOperationError,
|
|
9
9
|
validateSessionName
|
|
10
|
-
} from "./chunk-
|
|
11
|
-
import "./chunk-
|
|
10
|
+
} from "./chunk-7CNBPLNE.js";
|
|
11
|
+
import "./chunk-7OGTK7KB.js";
|
|
12
12
|
import {
|
|
13
13
|
ConversationItemSchema,
|
|
14
14
|
InteractionRequestSchema,
|
|
15
15
|
InteractionResponseSchema,
|
|
16
16
|
SESSION_TIMELINE_PAGE_SIZE,
|
|
17
17
|
SessionSummarySchema
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-P2PH5KMV.js";
|
|
19
19
|
|
|
20
20
|
// src/claude-adapter.ts
|
|
21
21
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
22
|
-
import { mkdir, readFile, readdir, rename, rm, writeFile } from "node:fs/promises";
|
|
23
|
-
import { homedir } from "node:os";
|
|
24
|
-
import { isAbsolute, join, resolve } from "node:path";
|
|
25
|
-
import { z as
|
|
22
|
+
import { mkdir, readFile as readFile2, readdir, rename, rm, writeFile } from "node:fs/promises";
|
|
23
|
+
import { homedir as homedir2 } from "node:os";
|
|
24
|
+
import { isAbsolute as isAbsolute2, join as join2, resolve } from "node:path";
|
|
25
|
+
import { z as z5 } from "zod";
|
|
26
26
|
|
|
27
27
|
// src/adapters/claude/input.ts
|
|
28
28
|
var ClaudeInput = class {
|
|
@@ -473,39 +473,180 @@ var ClaudeProcess = class {
|
|
|
473
473
|
}
|
|
474
474
|
};
|
|
475
475
|
|
|
476
|
+
// src/adapters/claude/runtime.ts
|
|
477
|
+
import { execFile } from "node:child_process";
|
|
478
|
+
import { constants } from "node:fs";
|
|
479
|
+
import { access, open, readFile, realpath, stat } from "node:fs/promises";
|
|
480
|
+
import { createRequire } from "node:module";
|
|
481
|
+
import { homedir } from "node:os";
|
|
482
|
+
import { delimiter, dirname, extname, isAbsolute, join, relative, sep } from "node:path";
|
|
483
|
+
import { z as z4 } from "zod";
|
|
484
|
+
var packageName = "@anthropic-ai/claude-agent-sdk";
|
|
485
|
+
var require2 = createRequire(import.meta.url);
|
|
486
|
+
var metadataSchema = z4.object({ claudeCodeVersion: z4.string().regex(/^\d+\.\d+\.\d+$/) });
|
|
487
|
+
var configurationHint = "Set AGENTKNIGHT_CLAUDE_COMMAND (SDK: command / managed claudeCommand) to an absolute native executable.";
|
|
488
|
+
function missing(error) {
|
|
489
|
+
return error instanceof Error && "code" in error && ["ENOENT", "ENOTDIR", "MODULE_NOT_FOUND"].includes(String(error.code));
|
|
490
|
+
}
|
|
491
|
+
function absolute(path) {
|
|
492
|
+
return !path.includes("\0") && isAbsolute(path) && (process.platform !== "win32" || /^(?:[a-z]:[\\/]|\\\\[^\\/]+[\\/][^\\/]+[\\/])/i.test(path));
|
|
493
|
+
}
|
|
494
|
+
async function executable(path) {
|
|
495
|
+
try {
|
|
496
|
+
await access(path, process.platform === "win32" ? constants.F_OK : constants.X_OK);
|
|
497
|
+
return (await stat(path)).isFile();
|
|
498
|
+
} catch (error) {
|
|
499
|
+
if (missing(error)) return false;
|
|
500
|
+
throw error;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
async function nativeExecutable(path) {
|
|
504
|
+
if (process.platform === "win32" && extname(path).toLowerCase() !== ".exe") return false;
|
|
505
|
+
if (!await executable(path)) return false;
|
|
506
|
+
const file = await open(path, "r");
|
|
507
|
+
try {
|
|
508
|
+
const header = Buffer.alloc(4);
|
|
509
|
+
const { bytesRead } = await file.read(header, 0, header.length, 0);
|
|
510
|
+
if (bytesRead !== 4) return false;
|
|
511
|
+
if (process.platform === "win32") return header.subarray(0, 2).toString() === "MZ";
|
|
512
|
+
return [
|
|
513
|
+
"7f454c46",
|
|
514
|
+
"feedface",
|
|
515
|
+
"cefaedfe",
|
|
516
|
+
"feedfacf",
|
|
517
|
+
"cffaedfe",
|
|
518
|
+
"cafebabe",
|
|
519
|
+
"bebafeca",
|
|
520
|
+
"cafebabf",
|
|
521
|
+
"bfbafeca"
|
|
522
|
+
].includes(header.toString("hex"));
|
|
523
|
+
} finally {
|
|
524
|
+
await file.close();
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
async function bundledExecutable(entry) {
|
|
528
|
+
const sdkRequire = createRequire(entry);
|
|
529
|
+
const platform = process.platform;
|
|
530
|
+
let platforms = [`${platform}-${process.arch}`];
|
|
531
|
+
if (platform === "linux") {
|
|
532
|
+
const report = process.report?.getReport();
|
|
533
|
+
const glibc = z4.object({ header: z4.object({ glibcVersionRuntime: z4.string().optional() }) }).safeParse(report);
|
|
534
|
+
const base = `linux-${process.arch}`;
|
|
535
|
+
platforms = glibc.success && glibc.data.header.glibcVersionRuntime !== void 0 ? [base, `${base}-musl`] : [`${base}-musl`, base];
|
|
536
|
+
} else if (platform === "android") {
|
|
537
|
+
platforms = [`linux-${process.arch}-android`];
|
|
538
|
+
}
|
|
539
|
+
for (const target of platforms) {
|
|
540
|
+
try {
|
|
541
|
+
if (await executable(sdkRequire.resolve(`${packageName}-${target}/claude${platform === "win32" ? ".exe" : ""}`))) return true;
|
|
542
|
+
} catch (error) {
|
|
543
|
+
if (!missing(error)) throw error;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
return false;
|
|
547
|
+
}
|
|
548
|
+
function inside(directory, path) {
|
|
549
|
+
const child = relative(directory, path);
|
|
550
|
+
return child === "" || !isAbsolute(child) && child !== ".." && !child.startsWith(`..${sep}`);
|
|
551
|
+
}
|
|
552
|
+
async function findExternal(environment) {
|
|
553
|
+
const name = process.platform === "win32" ? "claude.exe" : "claude";
|
|
554
|
+
try {
|
|
555
|
+
const installed = await realpath(join(homedir(), ".local", "bin", name));
|
|
556
|
+
if (await nativeExecutable(installed)) return installed;
|
|
557
|
+
} catch (error) {
|
|
558
|
+
if (!missing(error)) throw error;
|
|
559
|
+
}
|
|
560
|
+
const cwd = await realpath(process.cwd());
|
|
561
|
+
for (const directory of (environment.PATH ?? "").split(delimiter)) {
|
|
562
|
+
if (!absolute(directory) || inside(cwd, directory)) continue;
|
|
563
|
+
try {
|
|
564
|
+
const path = await realpath(join(directory, name));
|
|
565
|
+
if (!inside(cwd, path) && await nativeExecutable(path)) return path;
|
|
566
|
+
} catch (error) {
|
|
567
|
+
if (!missing(error)) throw error;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
return void 0;
|
|
571
|
+
}
|
|
572
|
+
async function version(path, environment) {
|
|
573
|
+
return new Promise((resolve2, reject) => {
|
|
574
|
+
const child = execFile(path, ["--version"], {
|
|
575
|
+
env: environment,
|
|
576
|
+
shell: false,
|
|
577
|
+
windowsHide: true,
|
|
578
|
+
timeout: 5e3,
|
|
579
|
+
maxBuffer: 4096,
|
|
580
|
+
killSignal: "SIGKILL"
|
|
581
|
+
}, (error, stdout) => {
|
|
582
|
+
if (error) reject(new Error(`Claude --version failed. ${configurationHint}`, { cause: error }));
|
|
583
|
+
else resolve2(stdout.trim());
|
|
584
|
+
});
|
|
585
|
+
child.stdin?.end();
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
async function resolveClaudeExecutable(command, environment = process.env) {
|
|
589
|
+
let entry;
|
|
590
|
+
let expected;
|
|
591
|
+
try {
|
|
592
|
+
entry = require2.resolve(packageName);
|
|
593
|
+
const raw = JSON.parse(await readFile(join(dirname(entry), "package.json"), "utf8"));
|
|
594
|
+
expected = metadataSchema.parse(raw).claudeCodeVersion;
|
|
595
|
+
} catch (error) {
|
|
596
|
+
throw new Error("Claude SDK installation is missing or invalid. Reinstall AgentKnight with optional dependencies enabled.", { cause: error });
|
|
597
|
+
}
|
|
598
|
+
if (command === void 0 && await bundledExecutable(entry)) return void 0;
|
|
599
|
+
let path;
|
|
600
|
+
if (command !== void 0) {
|
|
601
|
+
if (!absolute(command)) throw new Error(configurationHint);
|
|
602
|
+
path = await realpath(command).catch((error) => {
|
|
603
|
+
throw new Error(`Claude executable is unavailable. ${configurationHint}`, { cause: error });
|
|
604
|
+
});
|
|
605
|
+
if (!await nativeExecutable(path)) throw new Error(`Claude requires a native executable, not a script or shell shim. ${configurationHint}`);
|
|
606
|
+
} else {
|
|
607
|
+
path = await findExternal(environment);
|
|
608
|
+
}
|
|
609
|
+
if (path === void 0) throw new Error(`Claude Code ${expected} is not installed. ${configurationHint}`);
|
|
610
|
+
const actual = await version(path, environment);
|
|
611
|
+
if (actual !== `${expected} (Claude Code)`) {
|
|
612
|
+
throw new Error(`This SDK requires Claude Code ${expected}; the local CLI is incompatible or unrecognized. ${configurationHint}`);
|
|
613
|
+
}
|
|
614
|
+
return path;
|
|
615
|
+
}
|
|
616
|
+
|
|
476
617
|
// src/claude-adapter.ts
|
|
477
618
|
var CLAUDE_DEFAULT_MODEL_ID = "claude:agent-default";
|
|
478
|
-
var UuidSchema =
|
|
479
|
-
var ReceiptSchema =
|
|
619
|
+
var UuidSchema = z5.custom((value) => z5.uuid().safeParse(value).success);
|
|
620
|
+
var ReceiptSchema = z5.object({
|
|
480
621
|
id: UuidSchema,
|
|
481
|
-
prompt:
|
|
482
|
-
mode:
|
|
483
|
-
submittedAt:
|
|
484
|
-
operationId:
|
|
485
|
-
state:
|
|
622
|
+
prompt: z5.string().min(1).max(1e5),
|
|
623
|
+
mode: z5.enum(["enqueue", "immediate"]),
|
|
624
|
+
submittedAt: z5.iso.datetime(),
|
|
625
|
+
operationId: z5.string().min(1).max(256).optional(),
|
|
626
|
+
state: z5.enum(["queued", "submitted", "confirmed", "completed", "cancelled", "failed"])
|
|
486
627
|
});
|
|
487
|
-
var StoredSchema =
|
|
488
|
-
version:
|
|
628
|
+
var StoredSchema = z5.object({
|
|
629
|
+
version: z5.literal(1),
|
|
489
630
|
summary: SessionSummarySchema,
|
|
490
631
|
nativeId: UuidSchema.optional(),
|
|
491
|
-
modelId:
|
|
492
|
-
nativeDirectory:
|
|
493
|
-
items:
|
|
494
|
-
receipts:
|
|
495
|
-
unsafe:
|
|
632
|
+
modelId: z5.string().min(1).max(256),
|
|
633
|
+
nativeDirectory: z5.string().min(1).optional(),
|
|
634
|
+
items: z5.array(ConversationItemSchema),
|
|
635
|
+
receipts: z5.array(ReceiptSchema),
|
|
636
|
+
unsafe: z5.boolean()
|
|
496
637
|
}).refine((stored) => stored.nativeDirectory === void 0 || stored.nativeId !== void 0 && stored.summary.sessionId === `claude:native:${stored.nativeId}`, {
|
|
497
638
|
message: "Invalid Claude native session identity"
|
|
498
639
|
});
|
|
499
|
-
var MessageSchema =
|
|
500
|
-
type:
|
|
501
|
-
subtype:
|
|
502
|
-
uuid:
|
|
503
|
-
session_id:
|
|
504
|
-
state:
|
|
505
|
-
user_message_uuid:
|
|
506
|
-
user_message_uuids:
|
|
507
|
-
parent_tool_use_id:
|
|
508
|
-
is_error:
|
|
640
|
+
var MessageSchema = z5.object({
|
|
641
|
+
type: z5.string(),
|
|
642
|
+
subtype: z5.string().optional(),
|
|
643
|
+
uuid: z5.string().optional(),
|
|
644
|
+
session_id: z5.string().optional(),
|
|
645
|
+
state: z5.string().optional(),
|
|
646
|
+
user_message_uuid: z5.string().optional(),
|
|
647
|
+
user_message_uuids: z5.array(z5.string()).optional(),
|
|
648
|
+
parent_tool_use_id: z5.string().nullable().optional(),
|
|
649
|
+
is_error: z5.boolean().optional()
|
|
509
650
|
}).passthrough();
|
|
510
651
|
var ClaudeCodingAgentAdapter = class {
|
|
511
652
|
agentId = "claude";
|
|
@@ -541,7 +682,7 @@ var ClaudeCodingAgentAdapter = class {
|
|
|
541
682
|
if (options.nativeSessionOwner !== void 0) {
|
|
542
683
|
SessionSummarySchema.pick({ userId: true, machineId: true }).parse(options.nativeSessionOwner);
|
|
543
684
|
}
|
|
544
|
-
this.#directory =
|
|
685
|
+
this.#directory = join2(resolve(options.dataDirectory), "claude");
|
|
545
686
|
this.#interactions = new ClaudeInteractions(() => this.#callbacks, timeout);
|
|
546
687
|
}
|
|
547
688
|
setSessionCallbacks(callbacks) {
|
|
@@ -554,10 +695,10 @@ var ClaudeCodingAgentAdapter = class {
|
|
|
554
695
|
}
|
|
555
696
|
async #start() {
|
|
556
697
|
await mkdir(this.#directory, { recursive: true, mode: 448 });
|
|
557
|
-
await mkdir(
|
|
698
|
+
await mkdir(join2(this.#directory, "native"), { recursive: true, mode: 448 });
|
|
558
699
|
for (const file of await readdir(this.#directory)) {
|
|
559
700
|
if (!/^[a-f0-9]{64}\.json$/.test(file)) continue;
|
|
560
|
-
const raw = JSON.parse(await
|
|
701
|
+
const raw = JSON.parse(await readFile2(join2(this.#directory, file), "utf8"));
|
|
561
702
|
const stored = StoredSchema.parse(raw);
|
|
562
703
|
if (!stored.summary.sessionId.startsWith("claude:") || `${identity(stored.summary.sessionId)}.json` !== file) {
|
|
563
704
|
throw new Error("Invalid Claude session ownership record");
|
|
@@ -588,6 +729,7 @@ var ClaudeCodingAgentAdapter = class {
|
|
|
588
729
|
active: void 0,
|
|
589
730
|
input: void 0,
|
|
590
731
|
query: void 0,
|
|
732
|
+
command: void 0,
|
|
591
733
|
controller: void 0,
|
|
592
734
|
work: void 0,
|
|
593
735
|
dispatch: void 0,
|
|
@@ -635,13 +777,13 @@ var ClaudeCodingAgentAdapter = class {
|
|
|
635
777
|
}
|
|
636
778
|
async #scanNative(owner) {
|
|
637
779
|
const sdk = await this.#nativeSessions();
|
|
638
|
-
const sessions =
|
|
780
|
+
const sessions = z5.array(z5.object({
|
|
639
781
|
sessionId: UuidSchema,
|
|
640
|
-
summary:
|
|
641
|
-
customTitle:
|
|
642
|
-
lastModified:
|
|
643
|
-
createdAt:
|
|
644
|
-
cwd:
|
|
782
|
+
summary: z5.string(),
|
|
783
|
+
customTitle: z5.string().optional(),
|
|
784
|
+
lastModified: z5.number(),
|
|
785
|
+
createdAt: z5.number().optional(),
|
|
786
|
+
cwd: z5.string().optional()
|
|
645
787
|
})).parse(await sdk.listSessions({ includeProgrammatic: true }));
|
|
646
788
|
this.#ready();
|
|
647
789
|
const next = /* @__PURE__ */ new Map();
|
|
@@ -674,7 +816,7 @@ var ClaudeCodingAgentAdapter = class {
|
|
|
674
816
|
version: 1,
|
|
675
817
|
summary,
|
|
676
818
|
nativeId: native.sessionId,
|
|
677
|
-
nativeDirectory: resolve(env.CLAUDE_CONFIG_DIR ||
|
|
819
|
+
nativeDirectory: resolve(env.CLAUDE_CONFIG_DIR || join2(homedir2(), ".claude")),
|
|
678
820
|
modelId: CLAUDE_DEFAULT_MODEL_ID,
|
|
679
821
|
items: [],
|
|
680
822
|
receipts: [],
|
|
@@ -694,12 +836,13 @@ var ClaudeCodingAgentAdapter = class {
|
|
|
694
836
|
if (session.work || session.operations || session.cancellations || session.aborting || session.stored.unsafe || session.error) continue;
|
|
695
837
|
this.#sessions.delete(id);
|
|
696
838
|
this.#retiredSessions.add(id);
|
|
697
|
-
await rm(
|
|
839
|
+
await rm(join2(this.#directory, `${identity(id)}.json`));
|
|
698
840
|
}
|
|
699
841
|
}
|
|
700
842
|
}
|
|
701
843
|
async listModels() {
|
|
702
844
|
this.#ready();
|
|
845
|
+
await resolveClaudeExecutable(this.#options.command, this.#options.env);
|
|
703
846
|
return [{ id: CLAUDE_DEFAULT_MODEL_ID, name: "Claude agent default", isDefault: true }];
|
|
704
847
|
}
|
|
705
848
|
getSessionCapabilities() {
|
|
@@ -754,7 +897,9 @@ var ClaudeCodingAgentAdapter = class {
|
|
|
754
897
|
async createSession(options) {
|
|
755
898
|
this.#ready();
|
|
756
899
|
this.#validate(options);
|
|
757
|
-
if (!
|
|
900
|
+
if (!isAbsolute2(options.workingDirectory)) throw new Error("Claude working directory must be absolute");
|
|
901
|
+
await resolveClaudeExecutable(this.#options.command, this.#options.env);
|
|
902
|
+
this.#ready();
|
|
758
903
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
759
904
|
const summary = SessionSummarySchema.parse({
|
|
760
905
|
sessionId: `claude:${randomUUID2()}`,
|
|
@@ -829,14 +974,14 @@ var ClaudeCodingAgentAdapter = class {
|
|
|
829
974
|
const sdk = await this.#nativeSessions();
|
|
830
975
|
const nativeId = UuidSchema.parse(session.stored.nativeId);
|
|
831
976
|
const raw = await sdk.getSessionMessages(nativeId, this.#nativeReadOptions(session));
|
|
832
|
-
const messages =
|
|
833
|
-
type:
|
|
834
|
-
uuid:
|
|
977
|
+
const messages = z5.array(z5.object({
|
|
978
|
+
type: z5.enum(["user", "assistant", "system"]),
|
|
979
|
+
uuid: z5.string(),
|
|
835
980
|
session_id: UuidSchema,
|
|
836
|
-
message:
|
|
837
|
-
timestamp:
|
|
838
|
-
parent_tool_use_id:
|
|
839
|
-
parent_agent_id:
|
|
981
|
+
message: z5.unknown(),
|
|
982
|
+
timestamp: z5.iso.datetime().optional(),
|
|
983
|
+
parent_tool_use_id: z5.string().nullable(),
|
|
984
|
+
parent_agent_id: z5.string().nullable()
|
|
840
985
|
}).passthrough()).parse(raw);
|
|
841
986
|
this.#known(session.stored.summary.sessionId);
|
|
842
987
|
const items = [];
|
|
@@ -846,8 +991,8 @@ var ClaudeCodingAgentAdapter = class {
|
|
|
846
991
|
if (message.session_id !== nativeId) throw new Error("Claude returned history for another native session");
|
|
847
992
|
if (message.parent_agent_id || message.parent_tool_use_id) continue;
|
|
848
993
|
if (message.type === "user") {
|
|
849
|
-
const body =
|
|
850
|
-
if (typeof body.content === "string" || Array.isArray(body.content) && body.content.some((block) =>
|
|
994
|
+
const body = z5.object({ content: z5.unknown() }).parse(message.message);
|
|
995
|
+
if (typeof body.content === "string" || Array.isArray(body.content) && body.content.some((block) => z5.object({ type: z5.literal("text") }).safeParse(block).success)) turnId = message.uuid;
|
|
851
996
|
}
|
|
852
997
|
timeline.project({ ...message, timestamp: message.timestamp ?? session.stored.summary.createdAt }, turnId);
|
|
853
998
|
}
|
|
@@ -882,7 +1027,7 @@ var ClaudeCodingAgentAdapter = class {
|
|
|
882
1027
|
if (session.stored.nativeDirectory) {
|
|
883
1028
|
this.#environment(session);
|
|
884
1029
|
const directory = session.stored.summary.workingDirectory;
|
|
885
|
-
if (!directory || !
|
|
1030
|
+
if (!directory || !isAbsolute2(directory)) throw new Error("Claude native session working directory is unavailable; open it in the CLI first");
|
|
886
1031
|
}
|
|
887
1032
|
const duplicate = operationId === void 0 ? void 0 : session.stored.receipts.find((entry) => entry.operationId === operationId);
|
|
888
1033
|
if (duplicate) {
|
|
@@ -890,6 +1035,11 @@ var ClaudeCodingAgentAdapter = class {
|
|
|
890
1035
|
if (duplicate.state === "failed" || duplicate.state === "cancelled") throw new Error("Claude operation already ended; it was not retried");
|
|
891
1036
|
return { messageId: duplicate.id, deliveryState: duplicate.state === "queued" ? "queued" : "processing", submittedAt: duplicate.submittedAt };
|
|
892
1037
|
}
|
|
1038
|
+
if (!session.work || mode === "immediate" && session.busy) {
|
|
1039
|
+
session.command = await resolveClaudeExecutable(this.#options.command, this.#options.env);
|
|
1040
|
+
this.#ready();
|
|
1041
|
+
if (session.epoch !== epoch || session.aborting) throw new Error("Claude prompt cancelled before acceptance");
|
|
1042
|
+
}
|
|
893
1043
|
if (mode === "immediate" && session.busy) {
|
|
894
1044
|
await this.#cancel(session, false);
|
|
895
1045
|
if (session.aborting || this.#stopping || session.epoch !== epoch + 1) throw new Error("Claude prompt cancelled before acceptance");
|
|
@@ -954,7 +1104,7 @@ var ClaudeCodingAgentAdapter = class {
|
|
|
954
1104
|
#environment(session) {
|
|
955
1105
|
return prepareClaudeEnvironment(
|
|
956
1106
|
this.#options.env ?? process.env,
|
|
957
|
-
session.stored.nativeDirectory ??
|
|
1107
|
+
session.stored.nativeDirectory ?? join2(this.#directory, "native")
|
|
958
1108
|
);
|
|
959
1109
|
}
|
|
960
1110
|
async #consume(session, epoch) {
|
|
@@ -981,7 +1131,7 @@ var ClaudeCodingAgentAdapter = class {
|
|
|
981
1131
|
abortController: controller,
|
|
982
1132
|
spawnClaudeCodeProcess: ownedProcess.spawn,
|
|
983
1133
|
...session.stored.nativeId ? { resume: session.stored.nativeId } : {},
|
|
984
|
-
...
|
|
1134
|
+
...session.command === void 0 ? {} : { pathToClaudeCodeExecutable: session.command },
|
|
985
1135
|
canUseTool: (tool, args, context) => epoch !== session.epoch || controller.signal.aborted ? Promise.resolve({ behavior: "deny", message: "Stale Claude query" }) : this.#interactions.request(id, tool, args, context.signal)
|
|
986
1136
|
}
|
|
987
1137
|
});
|
|
@@ -1008,7 +1158,7 @@ var ClaudeCodingAgentAdapter = class {
|
|
|
1008
1158
|
for (const receiptId of confirmations) this.#confirm(session, receiptId);
|
|
1009
1159
|
session.timeline.project(raw, turnId);
|
|
1010
1160
|
if (message.type === "result") {
|
|
1011
|
-
const isError =
|
|
1161
|
+
const isError = z5.boolean().parse(message.is_error);
|
|
1012
1162
|
session.resultSeen = true;
|
|
1013
1163
|
if (session.active) session.active.state = isError ? "failed" : "completed";
|
|
1014
1164
|
if (isError) {
|
|
@@ -1017,7 +1167,7 @@ var ClaudeCodingAgentAdapter = class {
|
|
|
1017
1167
|
}
|
|
1018
1168
|
}
|
|
1019
1169
|
if (message.type === "system" && message.subtype === "background_tasks_changed") {
|
|
1020
|
-
const background =
|
|
1170
|
+
const background = z5.object({ tasks: z5.array(z5.unknown()) }).safeParse(message);
|
|
1021
1171
|
session.background = !background.success || background.data.tasks.length > 0;
|
|
1022
1172
|
}
|
|
1023
1173
|
if (message.type === "system" && message.subtype === "session_state_changed" && (message.state === "running" || message.state === "requires_action")) {
|
|
@@ -1190,7 +1340,7 @@ var ClaudeCodingAgentAdapter = class {
|
|
|
1190
1340
|
#save(session) {
|
|
1191
1341
|
if (!this.#sessions.has(session.stored.summary.sessionId)) return Promise.resolve();
|
|
1192
1342
|
const data = JSON.stringify(StoredSchema.parse(session.stored));
|
|
1193
|
-
const file =
|
|
1343
|
+
const file = join2(this.#directory, `${identity(session.stored.summary.sessionId)}.json`);
|
|
1194
1344
|
session.saves++;
|
|
1195
1345
|
const work = session.saving.then(async () => {
|
|
1196
1346
|
const temporary = `${file}.${randomUUID2()}.tmp`;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
latestPreviewItems
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-H4SHMWQ6.js";
|
|
4
4
|
import {
|
|
5
5
|
UnsupportedAgentOperationError
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-7CNBPLNE.js";
|
|
7
|
+
import "./chunk-7OGTK7KB.js";
|
|
8
8
|
import {
|
|
9
9
|
ConversationItemSchema,
|
|
10
10
|
InteractionRequestSchema,
|
|
11
11
|
SESSION_TIMELINE_PAGE_SIZE,
|
|
12
12
|
SessionSummarySchema
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-P2PH5KMV.js";
|
|
14
14
|
|
|
15
15
|
// src/codex-adapter.ts
|
|
16
16
|
import { randomUUID } from "node:crypto";
|