@agentknight/sdk 0.9.69 → 0.9.72

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/dist/chunks/{acp-adapter-VJ2OUSBS.js → acp-adapter-PCNN2NAJ.js} +7 -7
  2. package/dist/chunks/{chunk-LA6A4TUM.js → chunk-23BKGY5J.js} +4 -4
  3. package/dist/chunks/{chunk-J63A5OLO.js → chunk-2UHBY25U.js} +1 -1
  4. package/dist/chunks/{chunk-IRYEOV62.js → chunk-36KL4FSH.js} +2 -2
  5. package/dist/chunks/{chunk-2D34UDII.js → chunk-5BDFZ3AS.js} +4 -4
  6. package/dist/chunks/{chunk-F5YCEWE4.js → chunk-5FJJZCP6.js} +680 -629
  7. package/dist/chunks/{chunk-ES2N66EH.js → chunk-DXHAKWGO.js} +2 -2
  8. package/dist/chunks/{chunk-35OF2ZNS.js → chunk-E5VHBC55.js} +14 -0
  9. package/dist/chunks/{chunk-Q5NNNSU2.js → chunk-FQ26TSDG.js} +2 -2
  10. package/dist/chunks/{chunk-MH7FDSTY.js → chunk-GRUDMHEJ.js} +1 -1
  11. package/dist/chunks/{chunk-5QYL6NKJ.js → chunk-I42IONUU.js} +1 -1
  12. package/dist/chunks/{chunk-WAPJZKUK.js → chunk-KPHWVNKP.js} +1 -1
  13. package/dist/chunks/{chunk-LU73CEHE.js → chunk-PAJZL5ST.js} +7 -2
  14. package/dist/chunks/{chunk-ZAU2MYQI.js → chunk-TFUSRA2B.js} +2 -2
  15. package/dist/chunks/chunk-VEJLENEQ.js +174 -0
  16. package/dist/chunks/{chunk-MB34W52S.js → chunk-VOR4AECB.js} +3 -3
  17. package/dist/chunks/{claude-adapter-FZNLF5XN.js → claude-adapter-A4LPYQ2Z.js} +71 -211
  18. package/dist/chunks/{codex-adapter-5ZVOAT6O.js → codex-adapter-AFGS7MPX.js} +7 -7
  19. package/dist/chunks/{copilot-adapter-V6RAQ4WK.js → copilot-adapter-NXJTI2HY.js} +24 -68
  20. package/dist/chunks/{managed-agent-adapter-THUSTKRW.js → managed-agent-adapter-4C2PWD4V.js} +6 -6
  21. package/dist/chunks/{pi-adapter-EHCSR5I2.js → pi-adapter-EZOIK5RA.js} +6 -6
  22. package/dist/configuration.js +4 -4
  23. package/dist/index.d.ts +138 -0
  24. package/dist/index.js +163 -50
  25. package/dist/runtime.js +2 -2
  26. package/dist/session-analytics-worker.js +6 -6
  27. package/package.json +4 -5
  28. package/dist/chunks/chunk-T6226JFS.js +0 -55
@@ -1,39 +1,40 @@
1
1
  import {
2
- hasClaudeProviderConfiguration
3
- } from "./chunk-T6226JFS.js";
2
+ hasClaudeProviderConfiguration,
3
+ resolveClaudeExecutable
4
+ } from "./chunk-VEJLENEQ.js";
4
5
  import {
5
6
  prepareNativePrompt,
6
7
  projectNativeImage
7
- } from "./chunk-MB34W52S.js";
8
+ } from "./chunk-VOR4AECB.js";
8
9
  import "./chunk-UTF7KLMJ.js";
9
- import "./chunk-ES2N66EH.js";
10
- import "./chunk-35OF2ZNS.js";
10
+ import "./chunk-DXHAKWGO.js";
11
+ import "./chunk-E5VHBC55.js";
11
12
  import {
12
13
  latestPreviewItems,
13
14
  splitTimelineImages
14
- } from "./chunk-WAPJZKUK.js";
15
+ } from "./chunk-KPHWVNKP.js";
15
16
  import {
16
17
  SessionDeletionRejectedError,
17
18
  UnsupportedAgentOperationError,
18
19
  validateSessionName
19
- } from "./chunk-IRYEOV62.js";
20
- import "./chunk-J63A5OLO.js";
20
+ } from "./chunk-36KL4FSH.js";
21
+ import "./chunk-2UHBY25U.js";
21
22
  import {
22
23
  ConversationItemSchema,
23
24
  InteractionRequestSchema,
24
25
  InteractionResponseSchema,
25
26
  SESSION_TIMELINE_PAGE_SIZE,
26
27
  SessionSummarySchema
27
- } from "./chunk-F5YCEWE4.js";
28
+ } from "./chunk-5FJJZCP6.js";
28
29
 
29
30
  // src/claude-adapter.ts
30
- import { execFile as execFile2 } from "node:child_process";
31
+ import { execFile } from "node:child_process";
31
32
  import { randomUUID as randomUUID2 } from "node:crypto";
32
- import { mkdir, readFile as readFile2, readdir, rename, rm, writeFile } from "node:fs/promises";
33
- import { homedir as homedir2 } from "node:os";
34
- import { isAbsolute as isAbsolute2, join as join2, resolve } from "node:path";
33
+ import { mkdir, readFile, readdir, rename, rm, writeFile } from "node:fs/promises";
34
+ import { homedir } from "node:os";
35
+ import { isAbsolute, join, resolve } from "node:path";
35
36
  import { promisify } from "node:util";
36
- import { z as z5 } from "zod";
37
+ import { z as z4 } from "zod";
37
38
 
38
39
  // src/adapters/claude/input.ts
39
40
  var ClaudeInput = class {
@@ -515,182 +516,41 @@ var ClaudeProcess = class {
515
516
  }
516
517
  };
517
518
 
518
- // src/adapters/claude/runtime.ts
519
- import { execFile } from "node:child_process";
520
- import { constants } from "node:fs";
521
- import { access, open, readFile, realpath, stat } from "node:fs/promises";
522
- import { createRequire } from "node:module";
523
- import { homedir } from "node:os";
524
- import { delimiter, dirname, extname, isAbsolute, join, relative, sep } from "node:path";
525
- import { z as z4 } from "zod";
526
- var packageName = "@anthropic-ai/claude-agent-sdk";
527
- var require2 = createRequire(import.meta.url);
528
- var metadataSchema = z4.object({ claudeCodeVersion: z4.string().regex(/^\d+\.\d+\.\d+$/) });
529
- var configurationHint = "Set AGENTKNIGHT_CLAUDE_COMMAND (SDK: command / managed claudeCommand) to an absolute native executable.";
530
- function missing(error) {
531
- return error instanceof Error && "code" in error && ["ENOENT", "ENOTDIR", "MODULE_NOT_FOUND"].includes(String(error.code));
532
- }
533
- function absolute(path) {
534
- return !path.includes("\0") && isAbsolute(path) && (process.platform !== "win32" || /^(?:[a-z]:[\\/]|\\\\[^\\/]+[\\/][^\\/]+[\\/])/i.test(path));
535
- }
536
- async function executable(path) {
537
- try {
538
- await access(path, process.platform === "win32" ? constants.F_OK : constants.X_OK);
539
- return (await stat(path)).isFile();
540
- } catch (error) {
541
- if (missing(error)) return false;
542
- throw error;
543
- }
544
- }
545
- async function nativeExecutable(path) {
546
- if (process.platform === "win32" && extname(path).toLowerCase() !== ".exe") return false;
547
- if (!await executable(path)) return false;
548
- const file = await open(path, "r");
549
- try {
550
- const header = Buffer.alloc(4);
551
- const { bytesRead } = await file.read(header, 0, header.length, 0);
552
- if (bytesRead !== 4) return false;
553
- if (process.platform === "win32") return header.subarray(0, 2).toString() === "MZ";
554
- return [
555
- "7f454c46",
556
- "feedface",
557
- "cefaedfe",
558
- "feedfacf",
559
- "cffaedfe",
560
- "cafebabe",
561
- "bebafeca",
562
- "cafebabf",
563
- "bfbafeca"
564
- ].includes(header.toString("hex"));
565
- } finally {
566
- await file.close();
567
- }
568
- }
569
- async function bundledExecutable(entry) {
570
- const sdkRequire = createRequire(entry);
571
- const platform = process.platform;
572
- let platforms = [`${platform}-${process.arch}`];
573
- if (platform === "linux") {
574
- const report = process.report?.getReport();
575
- const glibc = z4.object({ header: z4.object({ glibcVersionRuntime: z4.string().optional() }) }).safeParse(report);
576
- const base = `linux-${process.arch}`;
577
- platforms = glibc.success && glibc.data.header.glibcVersionRuntime !== void 0 ? [base, `${base}-musl`] : [`${base}-musl`, base];
578
- } else if (platform === "android") {
579
- platforms = [`linux-${process.arch}-android`];
580
- }
581
- for (const target of platforms) {
582
- try {
583
- if (await executable(sdkRequire.resolve(`${packageName}-${target}/claude${platform === "win32" ? ".exe" : ""}`))) return true;
584
- } catch (error) {
585
- if (!missing(error)) throw error;
586
- }
587
- }
588
- return false;
589
- }
590
- function inside(directory, path) {
591
- const child = relative(directory, path);
592
- return child === "" || !isAbsolute(child) && child !== ".." && !child.startsWith(`..${sep}`);
593
- }
594
- async function findExternal(environment) {
595
- const name = process.platform === "win32" ? "claude.exe" : "claude";
596
- try {
597
- const installed = await realpath(join(homedir(), ".local", "bin", name));
598
- if (await nativeExecutable(installed)) return installed;
599
- } catch (error) {
600
- if (!missing(error)) throw error;
601
- }
602
- const cwd = await realpath(process.cwd());
603
- for (const directory of (environment.PATH ?? "").split(delimiter)) {
604
- if (!absolute(directory) || inside(cwd, directory)) continue;
605
- try {
606
- const path = await realpath(join(directory, name));
607
- if (!inside(cwd, path) && await nativeExecutable(path)) return path;
608
- } catch (error) {
609
- if (!missing(error)) throw error;
610
- }
611
- }
612
- return void 0;
613
- }
614
- async function version(path, environment) {
615
- return new Promise((resolve2, reject) => {
616
- const child = execFile(path, ["--version"], {
617
- env: environment,
618
- shell: false,
619
- windowsHide: true,
620
- timeout: 5e3,
621
- maxBuffer: 4096,
622
- killSignal: "SIGKILL"
623
- }, (error, stdout) => {
624
- if (error) reject(new Error(`Claude --version failed. ${configurationHint}`, { cause: error }));
625
- else resolve2(stdout.trim());
626
- });
627
- child.stdin?.end();
628
- });
629
- }
630
- async function resolveClaudeExecutable(command, environment = process.env) {
631
- let entry;
632
- let expected;
633
- try {
634
- entry = require2.resolve(packageName);
635
- const raw = JSON.parse(await readFile(join(dirname(entry), "package.json"), "utf8"));
636
- expected = metadataSchema.parse(raw).claudeCodeVersion;
637
- } catch (error) {
638
- throw new Error("Claude SDK installation is missing or invalid. Reinstall AgentKnight with optional dependencies enabled.", { cause: error });
639
- }
640
- if (command === void 0 && await bundledExecutable(entry)) return void 0;
641
- let path;
642
- if (command !== void 0) {
643
- if (!absolute(command)) throw new Error(configurationHint);
644
- path = await realpath(command).catch((error) => {
645
- throw new Error(`Claude executable is unavailable. ${configurationHint}`, { cause: error });
646
- });
647
- if (!await nativeExecutable(path)) throw new Error(`Claude requires a native executable, not a script or shell shim. ${configurationHint}`);
648
- } else {
649
- path = await findExternal(environment);
650
- }
651
- if (path === void 0) throw new Error(`Claude Code ${expected} is not installed. ${configurationHint}`);
652
- const actual = await version(path, environment);
653
- if (actual !== `${expected} (Claude Code)`) {
654
- throw new Error(`This SDK requires Claude Code ${expected}; the local CLI is incompatible or unrecognized. ${configurationHint}`);
655
- }
656
- return path;
657
- }
658
-
659
519
  // src/claude-adapter.ts
660
520
  var CLAUDE_DEFAULT_MODEL_ID = "claude:agent-default";
661
- var UuidSchema = z5.custom((value) => z5.uuid().safeParse(value).success);
662
- var ReceiptSchema = z5.object({
521
+ var UuidSchema = z4.custom((value) => z4.uuid().safeParse(value).success);
522
+ var ReceiptSchema = z4.object({
663
523
  id: UuidSchema,
664
- prompt: z5.string().max(1e5),
665
- mode: z5.enum(["enqueue", "immediate"]),
666
- submittedAt: z5.iso.datetime(),
667
- operationId: z5.string().min(1).max(256).optional(),
668
- state: z5.enum(["queued", "submitted", "confirmed", "completed", "cancelled", "failed"])
524
+ prompt: z4.string().max(1e5),
525
+ mode: z4.enum(["enqueue", "immediate"]),
526
+ submittedAt: z4.iso.datetime(),
527
+ operationId: z4.string().min(1).max(256).optional(),
528
+ state: z4.enum(["queued", "submitted", "confirmed", "completed", "cancelled", "failed"])
669
529
  });
670
- var modelCatalog = z5.array(z5.object({ value: z5.string().min(1).max(240), displayName: z5.string().min(1).max(260) })).max(250);
530
+ var modelCatalog = z4.array(z4.object({ value: z4.string().min(1).max(240), displayName: z4.string().min(1).max(260) })).max(250);
671
531
  var defaultModel = { id: CLAUDE_DEFAULT_MODEL_ID, name: "Claude agent default", isDefault: true };
672
- var StoredSchema = z5.object({
673
- version: z5.literal(1),
532
+ var StoredSchema = z4.object({
533
+ version: z4.literal(1),
674
534
  summary: SessionSummarySchema,
675
535
  nativeId: UuidSchema.optional(),
676
- modelId: z5.string().min(1).max(256),
677
- nativeDirectory: z5.string().min(1).optional(),
678
- items: z5.array(ConversationItemSchema),
679
- receipts: z5.array(ReceiptSchema),
680
- unsafe: z5.boolean()
536
+ modelId: z4.string().min(1).max(256),
537
+ nativeDirectory: z4.string().min(1).optional(),
538
+ items: z4.array(ConversationItemSchema),
539
+ receipts: z4.array(ReceiptSchema),
540
+ unsafe: z4.boolean()
681
541
  }).refine((stored) => stored.nativeDirectory === void 0 || stored.nativeId !== void 0 && stored.summary.sessionId === `claude:native:${stored.nativeId}`, {
682
542
  message: "Invalid Claude native session identity"
683
543
  });
684
- var MessageSchema = z5.object({
685
- type: z5.string(),
686
- subtype: z5.string().optional(),
687
- uuid: z5.string().optional(),
688
- session_id: z5.string().optional(),
689
- state: z5.string().optional(),
690
- user_message_uuid: z5.string().optional(),
691
- user_message_uuids: z5.array(z5.string()).optional(),
692
- parent_tool_use_id: z5.string().nullable().optional(),
693
- is_error: z5.boolean().optional()
544
+ var MessageSchema = z4.object({
545
+ type: z4.string(),
546
+ subtype: z4.string().optional(),
547
+ uuid: z4.string().optional(),
548
+ session_id: z4.string().optional(),
549
+ state: z4.string().optional(),
550
+ user_message_uuid: z4.string().optional(),
551
+ user_message_uuids: z4.array(z4.string()).optional(),
552
+ parent_tool_use_id: z4.string().nullable().optional(),
553
+ is_error: z4.boolean().optional()
694
554
  }).passthrough();
695
555
  var ClaudeCodingAgentAdapter = class {
696
556
  agentId = "claude";
@@ -729,7 +589,7 @@ var ClaudeCodingAgentAdapter = class {
729
589
  if (options.nativeSessionOwner !== void 0) {
730
590
  SessionSummarySchema.pick({ userId: true, machineId: true }).parse(options.nativeSessionOwner);
731
591
  }
732
- this.#directory = join2(resolve(options.dataDirectory), "claude");
592
+ this.#directory = join(resolve(options.dataDirectory), "claude");
733
593
  this.#interactions = new ClaudeInteractions(() => this.#callbacks, timeout);
734
594
  }
735
595
  setSessionCallbacks(callbacks) {
@@ -742,10 +602,10 @@ var ClaudeCodingAgentAdapter = class {
742
602
  }
743
603
  async #start() {
744
604
  await mkdir(this.#directory, { recursive: true, mode: 448 });
745
- await mkdir(join2(this.#directory, "native"), { recursive: true, mode: 448 });
605
+ await mkdir(join(this.#directory, "native"), { recursive: true, mode: 448 });
746
606
  for (const file of await readdir(this.#directory)) {
747
607
  if (!/^[a-f0-9]{64}\.json$/.test(file)) continue;
748
- const raw = JSON.parse(await readFile2(join2(this.#directory, file), "utf8"));
608
+ const raw = JSON.parse(await readFile(join(this.#directory, file), "utf8"));
749
609
  const stored = StoredSchema.parse(raw);
750
610
  if (!stored.summary.sessionId.startsWith("claude:") || `${identity(stored.summary.sessionId)}.json` !== file) {
751
611
  throw new Error("Invalid Claude session ownership record");
@@ -824,13 +684,13 @@ var ClaudeCodingAgentAdapter = class {
824
684
  }
825
685
  async #scanNative(owner) {
826
686
  const sdk = await this.#nativeSessions();
827
- const sessions = z5.array(z5.object({
687
+ const sessions = z4.array(z4.object({
828
688
  sessionId: UuidSchema,
829
- summary: z5.string(),
830
- customTitle: z5.string().optional(),
831
- lastModified: z5.number(),
832
- createdAt: z5.number().optional(),
833
- cwd: z5.string().optional()
689
+ summary: z4.string(),
690
+ customTitle: z4.string().optional(),
691
+ lastModified: z4.number(),
692
+ createdAt: z4.number().optional(),
693
+ cwd: z4.string().optional()
834
694
  })).parse(await sdk.listSessions({ includeProgrammatic: true }));
835
695
  this.#ready();
836
696
  const next = /* @__PURE__ */ new Map();
@@ -863,7 +723,7 @@ var ClaudeCodingAgentAdapter = class {
863
723
  version: 1,
864
724
  summary,
865
725
  nativeId: native.sessionId,
866
- nativeDirectory: resolve(env.CLAUDE_CONFIG_DIR || join2(homedir2(), ".claude")),
726
+ nativeDirectory: resolve(env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude")),
867
727
  modelId: CLAUDE_DEFAULT_MODEL_ID,
868
728
  items: [],
869
729
  receipts: [],
@@ -883,7 +743,7 @@ var ClaudeCodingAgentAdapter = class {
883
743
  if (session.work || session.operations || session.cancellations || session.aborting || session.stored.unsafe || session.error) continue;
884
744
  this.#sessions.delete(id);
885
745
  this.#retiredSessions.add(id);
886
- await rm(join2(this.#directory, `${identity(id)}.json`));
746
+ await rm(join(this.#directory, `${identity(id)}.json`));
887
747
  }
888
748
  }
889
749
  }
@@ -908,7 +768,7 @@ var ClaudeCodingAgentAdapter = class {
908
768
  const owned = new ClaudeProcess();
909
769
  let query;
910
770
  try {
911
- const cwd = join2(this.#directory, "native");
771
+ const cwd = join(this.#directory, "native");
912
772
  const env = prepareClaudeEnvironment(this.#options.env ?? process.env, cwd);
913
773
  const sdk = await import("@anthropic-ai/claude-agent-sdk");
914
774
  this.#ready();
@@ -920,7 +780,7 @@ var ClaudeCodingAgentAdapter = class {
920
780
  options: {
921
781
  cwd,
922
782
  env,
923
- ...path === void 0 ? {} : { pathToClaudeCodeExecutable: path },
783
+ pathToClaudeCodeExecutable: path,
924
784
  spawnClaudeCodeProcess: owned.spawn,
925
785
  abortController: controller,
926
786
  persistSession: false,
@@ -1002,10 +862,10 @@ var ClaudeCodingAgentAdapter = class {
1002
862
  }
1003
863
  this.#known(id);
1004
864
  if (nativeId && dir) {
1005
- const config = join2(this.#directory, "native");
865
+ const config = join(this.#directory, "native");
1006
866
  const injected = this.#options.nativeSessions?.deleteOwnedSession;
1007
867
  if (injected) await injected(nativeId, dir, config);
1008
- else await promisify(execFile2)(process.execPath, [
868
+ else await promisify(execFile)(process.execPath, [
1009
869
  "--input-type=module",
1010
870
  "-e",
1011
871
  "const [sdk, id, dir] = process.argv.slice(1); await (await import(sdk)).deleteSession(id, {dir});",
@@ -1019,7 +879,7 @@ var ClaudeCodingAgentAdapter = class {
1019
879
  });
1020
880
  }
1021
881
  await session.saving;
1022
- await rm(join2(this.#directory, `${identity(id)}.json`));
882
+ await rm(join(this.#directory, `${identity(id)}.json`));
1023
883
  this.#sessions.delete(id);
1024
884
  this.#retiredSessions.add(id);
1025
885
  this.#callbacks?.onSessionInventoryChanged(id);
@@ -1055,7 +915,7 @@ var ClaudeCodingAgentAdapter = class {
1055
915
  async createSession(options) {
1056
916
  this.#ready();
1057
917
  this.#validate(options);
1058
- if (!isAbsolute2(options.workingDirectory)) throw new Error("Claude working directory must be absolute");
918
+ if (!isAbsolute(options.workingDirectory)) throw new Error("Claude working directory must be absolute");
1059
919
  await resolveClaudeExecutable(this.#options.command, this.#options.env);
1060
920
  this.#ready();
1061
921
  const now = (/* @__PURE__ */ new Date()).toISOString();
@@ -1154,14 +1014,14 @@ var ClaudeCodingAgentAdapter = class {
1154
1014
  const sdk = await this.#nativeSessions();
1155
1015
  const nativeId = UuidSchema.parse(session.stored.nativeId);
1156
1016
  const raw = await sdk.getSessionMessages(nativeId, this.#nativeReadOptions(session));
1157
- const messages = z5.array(z5.object({
1158
- type: z5.enum(["user", "assistant", "system"]),
1159
- uuid: z5.string(),
1017
+ const messages = z4.array(z4.object({
1018
+ type: z4.enum(["user", "assistant", "system"]),
1019
+ uuid: z4.string(),
1160
1020
  session_id: UuidSchema,
1161
- message: z5.unknown(),
1162
- timestamp: z5.iso.datetime().optional(),
1163
- parent_tool_use_id: z5.string().nullable(),
1164
- parent_agent_id: z5.string().nullable()
1021
+ message: z4.unknown(),
1022
+ timestamp: z4.iso.datetime().optional(),
1023
+ parent_tool_use_id: z4.string().nullable(),
1024
+ parent_agent_id: z4.string().nullable()
1165
1025
  }).passthrough()).parse(raw);
1166
1026
  this.#known(session.stored.summary.sessionId);
1167
1027
  const items = [];
@@ -1171,8 +1031,8 @@ var ClaudeCodingAgentAdapter = class {
1171
1031
  if (message.session_id !== nativeId) throw new Error("Claude returned history for another native session");
1172
1032
  if (message.parent_agent_id || message.parent_tool_use_id) continue;
1173
1033
  if (message.type === "user") {
1174
- const body = z5.object({ content: z5.unknown() }).parse(message.message);
1175
- 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;
1034
+ const body = z4.object({ content: z4.unknown() }).parse(message.message);
1035
+ if (typeof body.content === "string" || Array.isArray(body.content) && body.content.some((block) => z4.object({ type: z4.literal("text") }).safeParse(block).success)) turnId = message.uuid;
1176
1036
  }
1177
1037
  timeline.project({ ...message, timestamp: message.timestamp ?? session.stored.summary.createdAt }, turnId);
1178
1038
  }
@@ -1210,7 +1070,7 @@ var ClaudeCodingAgentAdapter = class {
1210
1070
  if (session.stored.nativeDirectory) {
1211
1071
  this.#environment(session);
1212
1072
  const directory = session.stored.summary.workingDirectory;
1213
- if (!directory || !isAbsolute2(directory)) throw new Error("Claude native session working directory is unavailable; open it in the CLI first");
1073
+ if (!directory || !isAbsolute(directory)) throw new Error("Claude native session working directory is unavailable; open it in the CLI first");
1214
1074
  }
1215
1075
  const duplicate = operationId === void 0 ? void 0 : session.stored.receipts.find((entry) => entry.operationId === operationId);
1216
1076
  if (duplicate) {
@@ -1292,7 +1152,7 @@ var ClaudeCodingAgentAdapter = class {
1292
1152
  #environment(session) {
1293
1153
  return prepareClaudeEnvironment(
1294
1154
  this.#options.env ?? process.env,
1295
- session.stored.nativeDirectory ?? join2(this.#directory, "native")
1155
+ session.stored.nativeDirectory ?? join(this.#directory, "native")
1296
1156
  );
1297
1157
  }
1298
1158
  async #consume(session, epoch) {
@@ -1352,7 +1212,7 @@ var ClaudeCodingAgentAdapter = class {
1352
1212
  for (const receiptId of confirmations) this.#confirm(session, receiptId);
1353
1213
  session.timeline.project(raw, turnId);
1354
1214
  if (message.type === "result") {
1355
- const isError = z5.boolean().parse(message.is_error);
1215
+ const isError = z4.boolean().parse(message.is_error);
1356
1216
  session.resultSeen = true;
1357
1217
  if (session.active) session.active.state = isError ? "failed" : "completed";
1358
1218
  if (isError) {
@@ -1361,7 +1221,7 @@ var ClaudeCodingAgentAdapter = class {
1361
1221
  }
1362
1222
  }
1363
1223
  if (message.type === "system" && message.subtype === "background_tasks_changed") {
1364
- const background = z5.object({ tasks: z5.array(z5.unknown()) }).safeParse(message);
1224
+ const background = z4.object({ tasks: z4.array(z4.unknown()) }).safeParse(message);
1365
1225
  session.background = !background.success || background.data.tasks.length > 0;
1366
1226
  }
1367
1227
  if (message.type === "system" && message.subtype === "session_state_changed" && (message.state === "running" || message.state === "requires_action")) {
@@ -1548,7 +1408,7 @@ var ClaudeCodingAgentAdapter = class {
1548
1408
  #save(session) {
1549
1409
  if (!this.#sessions.has(session.stored.summary.sessionId)) return Promise.resolve();
1550
1410
  const data = JSON.stringify(StoredSchema.parse(session.stored));
1551
- const file = join2(this.#directory, `${identity(session.stored.summary.sessionId)}.json`);
1411
+ const file = join(this.#directory, `${identity(session.stored.summary.sessionId)}.json`);
1552
1412
  session.saves++;
1553
1413
  const work = session.saving.then(async () => {
1554
1414
  const temporary = `${file}.${randomUUID2()}.tmp`;
@@ -2,28 +2,28 @@ import {
2
2
  prepareNativePrompt,
3
3
  projectNativeImage,
4
4
  projectNativeImageUrl
5
- } from "./chunk-MB34W52S.js";
5
+ } from "./chunk-VOR4AECB.js";
6
6
  import {
7
7
  PromptPreparationError
8
8
  } from "./chunk-UTF7KLMJ.js";
9
- import "./chunk-ES2N66EH.js";
10
- import "./chunk-35OF2ZNS.js";
9
+ import "./chunk-DXHAKWGO.js";
10
+ import "./chunk-E5VHBC55.js";
11
11
  import {
12
12
  latestPreviewItems,
13
13
  splitTimelineImages
14
- } from "./chunk-WAPJZKUK.js";
14
+ } from "./chunk-KPHWVNKP.js";
15
15
  import {
16
16
  SessionDeletionRejectedError,
17
17
  UnsupportedAgentOperationError,
18
18
  validateSessionName
19
- } from "./chunk-IRYEOV62.js";
20
- import "./chunk-J63A5OLO.js";
19
+ } from "./chunk-36KL4FSH.js";
20
+ import "./chunk-2UHBY25U.js";
21
21
  import {
22
22
  ConversationItemSchema,
23
23
  InteractionRequestSchema,
24
24
  SESSION_TIMELINE_PAGE_SIZE,
25
25
  SessionSummarySchema
26
- } from "./chunk-F5YCEWE4.js";
26
+ } from "./chunk-5FJJZCP6.js";
27
27
 
28
28
  // src/codex-adapter.ts
29
29
  import { randomUUID } from "node:crypto";
@@ -17,27 +17,27 @@ import {
17
17
  recordTimelineSyncDiagnostic,
18
18
  resolveGitProjectIdentity,
19
19
  sanitizeGitRemoteUrl
20
- } from "./chunk-2D34UDII.js";
20
+ } from "./chunk-5BDFZ3AS.js";
21
21
  import "./chunk-IJPJQF7S.js";
22
22
  import {
23
23
  AnalyticsIndexResultSchema,
24
24
  AnalyticsReplySchema,
25
25
  openSessionEventLog,
26
26
  readSessionUpdatePage
27
- } from "./chunk-LA6A4TUM.js";
27
+ } from "./chunk-23BKGY5J.js";
28
28
  import {
29
29
  ConversationNormalizer,
30
30
  isDisplayableHumanMessage
31
- } from "./chunk-LU73CEHE.js";
31
+ } from "./chunk-PAJZL5ST.js";
32
32
  import {
33
33
  assertMainSessionId,
34
34
  isResearchSessionId
35
- } from "./chunk-5QYL6NKJ.js";
35
+ } from "./chunk-I42IONUU.js";
36
36
  import {
37
37
  GroupChatError,
38
38
  GroupChatMessageSchema,
39
39
  GroupChatRuntime
40
- } from "./chunk-Q5NNNSU2.js";
40
+ } from "./chunk-FQ26TSDG.js";
41
41
  import {
42
42
  PromptPreparationError
43
43
  } from "./chunk-UTF7KLMJ.js";
@@ -45,21 +45,22 @@ import {
45
45
  deletePromptAttachments,
46
46
  stagePromptAttachments,
47
47
  validatePromptAttachments
48
- } from "./chunk-ES2N66EH.js";
48
+ } from "./chunk-DXHAKWGO.js";
49
49
  import {
50
50
  CopilotSessionCompatibilityClient,
51
+ copilotRuntimeOptions,
51
52
  resolveCopilotSessionDirectory,
52
53
  resumeWithCopilotSessionCompatibility
53
- } from "./chunk-35OF2ZNS.js";
54
- import "./chunk-WAPJZKUK.js";
54
+ } from "./chunk-E5VHBC55.js";
55
+ import "./chunk-KPHWVNKP.js";
55
56
  import {
56
57
  AgentSessionRenameError,
57
58
  TimelinePageBudgetError,
58
59
  validateSessionName
59
- } from "./chunk-IRYEOV62.js";
60
+ } from "./chunk-36KL4FSH.js";
60
61
  import {
61
62
  SessionOperationError
62
- } from "./chunk-J63A5OLO.js";
63
+ } from "./chunk-2UHBY25U.js";
63
64
  import {
64
65
  ConversationItemSchema,
65
66
  CopilotModelOptionSchema,
@@ -81,14 +82,14 @@ import {
81
82
  WorkbenchScheduleProposalSchema,
82
83
  WorkbenchScheduleSnapshotSchema,
83
84
  WorkbenchTelemetrySchema
84
- } from "./chunk-F5YCEWE4.js";
85
+ } from "./chunk-5FJJZCP6.js";
85
86
 
86
87
  // src/copilot-adapter.ts
87
88
  import { createHash as createHash3, randomUUID as randomUUID5 } from "node:crypto";
88
- import { existsSync, statSync } from "node:fs";
89
+ import { readFileSync } from "node:fs";
89
90
  import { readFile as readFile2, realpath, stat } from "node:fs/promises";
90
- import { createRequire } from "node:module";
91
- import { basename, dirname, extname, isAbsolute, join as join2, relative, resolve } from "node:path";
91
+ import { findPackageJSON } from "node:module";
92
+ import { basename, extname, isAbsolute, relative, resolve } from "node:path";
92
93
 
93
94
  // src/adapters/copilot/runtime/client-runtime.ts
94
95
  var CopilotClientRuntime = class {
@@ -1665,8 +1666,7 @@ var TimelineHistory = class {
1665
1666
  // src/copilot-adapter.ts
1666
1667
  import {
1667
1668
  CopilotClient,
1668
- defineTool as defineTool2,
1669
- RuntimeConnection
1669
+ defineTool as defineTool2
1670
1670
  } from "@github/copilot-sdk";
1671
1671
  import { z as z5 } from "zod";
1672
1672
 
@@ -3643,59 +3643,16 @@ var NativeCopilotModelOptionSchema = CopilotModelOptionSchema.extend({
3643
3643
  var GIT_REMOTE_CACHE_TTL_MS = 5 * 60 * 1e3;
3644
3644
  var GIT_REMOTE_FAILURE_CACHE_TTL_MS = 30 * 1e3;
3645
3645
  var GIT_REMOTE_FAILURE_CACHE_LIMIT = 256;
3646
- var require2 = createRequire(import.meta.url);
3647
- function resolveCopilotRuntimePath(environment = process.env) {
3648
- return environment["COPILOT_CLI_PATH"] ?? require2.resolve("@github/copilot/npm-loader.js");
3649
- }
3650
- function assertCopilotInProcessRuntime() {
3651
- try {
3652
- const entrypoint = process.env["COPILOT_CLI_PATH"];
3653
- let platform = process.platform;
3654
- if (platform === "linux") {
3655
- const report = process.report?.getReport();
3656
- const header = z5.object({ header: z5.object({ glibcVersionRuntime: z5.string().optional() }) }).safeParse(report);
3657
- const musl = entrypoint?.includes(`copilot-linuxmusl-${process.arch}`) || !entrypoint?.includes(`copilot-linux-${process.arch}`) && (!header.success || header.data.header.glibcVersionRuntime === void 0);
3658
- if (musl) platform = "linuxmusl";
3659
- }
3660
- const target = `${platform}-${process.arch}`;
3661
- const files = [];
3662
- if (entrypoint) {
3663
- const directory = dirname(resolve(entrypoint));
3664
- const adjacent = join2(directory, "runtime.node");
3665
- files.push(existsSync(adjacent) ? adjacent : join2(directory, "prebuilds", target, "runtime.node"));
3666
- } else {
3667
- const sdkRequire = createRequire(require2.resolve("@github/copilot-sdk"));
3668
- const directory = dirname(sdkRequire.resolve(`@github/copilot-sdk-${target}/package.json`));
3669
- const prebuild = join2(directory, "prebuilds", target);
3670
- files.push(
3671
- join2(prebuild, "runtime.node"),
3672
- join2(prebuild, process.platform === "win32" ? "copilot-runtime.exe" : "copilot-runtime")
3673
- );
3674
- }
3675
- for (const path of files) {
3676
- const file = statSync(path);
3677
- if (!file.isFile() || file.size === 0) throw new Error(`Missing Copilot native runtime file: ${path}`);
3678
- }
3679
- } catch (error) {
3680
- throw new Error(
3681
- "Copilot inprocess runtime is unavailable. Unset COPILOT_SDK_DEFAULT_CONNECTION or set it to stdio to use the bundled CLI; inprocess requires a full SDK installation with its platform runtime, or COPILOT_CLI_PATH with an adjacent native runtime.",
3682
- { cause: error }
3683
- );
3684
- }
3646
+ function copilotSdkVersion() {
3647
+ const manifest = findPackageJSON("@github/copilot-sdk", import.meta.url);
3648
+ if (manifest === void 0) throw new Error("Cannot locate the installed Copilot SDK manifest");
3649
+ return z5.object({ version: z5.string().min(1) }).parse(JSON.parse(readFileSync(manifest, "utf8"))).version;
3685
3650
  }
3686
3651
  function createCopilotClient() {
3687
- const defaultConnection = process.env["COPILOT_SDK_DEFAULT_CONNECTION"]?.toLowerCase() || void 0;
3688
- if (defaultConnection === "inprocess") assertCopilotInProcessRuntime();
3689
- const client = defaultConnection !== void 0 && defaultConnection !== "stdio" ? new CopilotClient({ mode: "copilot-cli" }) : new CopilotClient({
3690
- mode: "copilot-cli",
3691
- connection: RuntimeConnection.forStdio({
3692
- path: resolveCopilotRuntimePath()
3693
- })
3694
- });
3695
- return Object.assign(client, {
3652
+ return Object.assign(new CopilotClient({ mode: "copilot-cli", ...copilotRuntimeOptions() }), {
3696
3653
  supportsFileAttachments: true,
3697
- supportsLocalSubmissionTime: process.env["COPILOT_CLI_PATH"] === void 0,
3698
- supportsAttachmentPreservingQueueEdits: (defaultConnection === void 0 || defaultConnection === "stdio") && process.env["COPILOT_CLI_PATH"] === void 0
3654
+ supportsLocalSubmissionTime: true,
3655
+ supportsAttachmentPreservingQueueEdits: process.env["COPILOT_SDK_DEFAULT_CONNECTION"]?.toLowerCase() !== "inprocess"
3699
3656
  });
3700
3657
  }
3701
3658
  var MAX_HTML_PREVIEW_BYTES = 512 * 1024;
@@ -3949,7 +3906,7 @@ var GithubCopilotAdapter = class {
3949
3906
  resolveImages: (sessionId, session, normalizer, readOnly) => this.#images.resolveTimelineImageAssets(sessionId, session, normalizer, readOnly)
3950
3907
  });
3951
3908
  agentId = "copilot";
3952
- sdkVersion = "1.0.26";
3909
+ sdkVersion = copilotSdkVersion();
3953
3910
  agentModes = ["interactive", "plan", "autopilot"];
3954
3911
  supportsReasoningEffort = true;
3955
3912
  supportsContextTier = true;
@@ -5160,6 +5117,5 @@ export {
5160
5117
  GithubCopilotAdapter,
5161
5118
  mapSessionMetadata,
5162
5119
  openExternalUrl,
5163
- resolveCopilotRuntimePath,
5164
5120
  sanitizeGitRemoteUrl
5165
5121
  };