@byok-sdk/client 0.1.0 → 0.1.1

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.
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import { execFile, spawn, spawnSync } from 'child_process';
3
3
  import { randomUUID, createHash, randomBytes, timingSafeEqual, createPrivateKey, generateKeyPairSync, sign, createHmac } from 'crypto';
4
- import { readFileSync, promises, linkSync, fstatSync, lstatSync, unlinkSync, constants, readSync, openSync, writeFileSync, fchmodSync, fsyncSync, closeSync, opendirSync, existsSync, realpathSync, mkdirSync, renameSync, chmodSync, statSync, readdirSync } from 'fs';
5
- import path20, { join, isAbsolute } from 'path';
4
+ import { readFileSync, promises, linkSync, fstatSync, lstatSync, unlinkSync, constants, readSync, openSync, writeFileSync, fchmodSync, fsyncSync, closeSync, opendirSync, realpathSync, mkdirSync, existsSync, renameSync, chmodSync, statSync, readdirSync } from 'fs';
5
+ import path19, { join, isAbsolute } from 'path';
6
6
  import os from 'os';
7
7
  import { TASK_STATES, partitionAgentEvents, TASK_TRANSITIONS, encodeEnvelope, createEnvelope, MAX_MESSAGES_PER_BATCH, RuntimeIdSchema, PROTOCOL_VERSION, decodeEnvelope, MessagesSendResponseSchema, parseMessage, UnknownMessageTypeError } from '@byok-sdk/protocol';
8
8
  import { promisify } from 'util';
@@ -72,7 +72,7 @@ function gitEnvironment(readOnly) {
72
72
  return env;
73
73
  }
74
74
  function stableGitWorkspaceOwnerId(storeDir, productId) {
75
- const identity = `${path20.resolve(storeDir)}\\0${productId}`;
75
+ const identity = `${path19.resolve(storeDir)}\\0${productId}`;
76
76
  return `store-product:${createHash("sha256").update(identity).digest("hex")}`;
77
77
  }
78
78
  var GUIDANCE = [
@@ -84,11 +84,11 @@ var GUIDANCE = [
84
84
  "Leave incomplete work visible for recovery."
85
85
  ].join("\n");
86
86
  function canonical(value) {
87
- return path20.resolve(value);
87
+ return path19.resolve(value);
88
88
  }
89
89
  function isContained(root, candidate) {
90
- const relative = path20.relative(root, candidate);
91
- return relative === "" || !relative.startsWith(`..${path20.sep}`) && !path20.isAbsolute(relative);
90
+ const relative = path19.relative(root, candidate);
91
+ return relative === "" || !relative.startsWith(`..${path19.sep}`) && !path19.isAbsolute(relative);
92
92
  }
93
93
  function bounded(value, max) {
94
94
  return Buffer.byteLength(value, "utf8") <= max ? value : value.slice(0, max);
@@ -193,7 +193,7 @@ var GitWorkspaceManager = class {
193
193
  await this.ensureOwnerMarker();
194
194
  }
195
195
  async ensureOwnerMarker() {
196
- const markerPath = path20.join(this.workspaceRoot, OWNER_MARKER);
196
+ const markerPath = path19.join(this.workspaceRoot, OWNER_MARKER);
197
197
  let existing;
198
198
  try {
199
199
  existing = JSON.parse(await promises.readFile(markerPath, "utf8"));
@@ -352,7 +352,7 @@ ${instruction}`;
352
352
  if (error instanceof GitWorkspaceError || code !== "ENOENT" && code !== "ENOTDIR") {
353
353
  throw new GitWorkspaceError("workspace-root-invalid", "workspace directory is invalid");
354
354
  }
355
- const parent = path20.dirname(current);
355
+ const parent = path19.dirname(current);
356
356
  if (parent === current) {
357
357
  throw new GitWorkspaceError("workspace-root-invalid", "workspace directory is invalid");
358
358
  }
@@ -410,7 +410,7 @@ async function atomicWriteFile(filePath, data, options = {}) {
410
410
  await target.close();
411
411
  }
412
412
  if (process.platform !== "win32") {
413
- const directory = await promises.open(path20.dirname(filePath), "r");
413
+ const directory = await promises.open(path19.dirname(filePath), "r");
414
414
  try {
415
415
  await directory.sync();
416
416
  } finally {
@@ -571,7 +571,7 @@ function isProtected(record) {
571
571
  var GitWorkspaceStore = class {
572
572
  constructor(storeDir, options = {}) {
573
573
  this.storeDir = storeDir;
574
- this.filePath = path20.join(storeDir, FILE_NAME);
574
+ this.filePath = path19.join(storeDir, FILE_NAME);
575
575
  this.maxRecords = Math.max(1, Math.floor(options.maxRecords ?? MAX_RECORDS));
576
576
  }
577
577
  storeDir;
@@ -701,39 +701,13 @@ var GitWorkspaceStore = class {
701
701
  await atomicWriteFile(this.filePath, JSON.stringify(ledger, null, 2), { mode: 384 });
702
702
  }
703
703
  };
704
- var PI_PACKAGE_NAME = "@earendil-works/pi-coding-agent";
705
- function readPackageJson(dir) {
706
- const candidate = path20.join(dir, "package.json");
707
- if (!existsSync(candidate)) return void 0;
708
- try {
709
- return JSON.parse(readFileSync(candidate, "utf8"));
710
- } catch {
711
- return void 0;
712
- }
713
- }
704
+
705
+ // src/adapters/pi/resolve-bin.ts
714
706
  function resolvePiBin() {
715
707
  const override = process.env.BYOK_PI_BIN;
716
708
  if (override) {
717
709
  return { command: override, source: "path" };
718
710
  }
719
- try {
720
- const mainEntryUrl = import.meta.resolve(PI_PACKAGE_NAME);
721
- let dir = path20.dirname(fileURLToPath(mainEntryUrl));
722
- for (let depth = 0; depth < 6; depth++) {
723
- const pkg = readPackageJson(dir);
724
- if (pkg?.name === PI_PACKAGE_NAME) {
725
- const binRel = typeof pkg.bin === "string" ? pkg.bin : pkg.bin?.pi;
726
- if (binRel) {
727
- return { command: path20.join(dir, binRel), source: "package" };
728
- }
729
- break;
730
- }
731
- const parent = path20.dirname(dir);
732
- if (parent === dir) break;
733
- dir = parent;
734
- }
735
- } catch {
736
- }
737
711
  return { command: "pi", source: "path" };
738
712
  }
739
713
 
@@ -1286,7 +1260,7 @@ function resolveApprovalMcpBin() {
1286
1260
  if (override) {
1287
1261
  return { command: override, args: [], source: "env" };
1288
1262
  }
1289
- const distBin = path20.join(path20.dirname(fileURLToPath(import.meta.url)), "bin", "byok-approval-mcp.js");
1263
+ const distBin = path19.join(path19.dirname(fileURLToPath(import.meta.url)), "bin", "byok-approval-mcp.js");
1290
1264
  return { command: process.execPath, args: [distBin], source: "dist" };
1291
1265
  }
1292
1266
 
@@ -1366,7 +1340,7 @@ var EXTENSION_CONTENT_TYPES = {
1366
1340
  ".yml": "application/yaml"
1367
1341
  };
1368
1342
  function guessContentType(filePath) {
1369
- const ext = path20.extname(filePath).toLowerCase();
1343
+ const ext = path19.extname(filePath).toLowerCase();
1370
1344
  return EXTENSION_CONTENT_TYPES[ext] ?? "application/octet-stream";
1371
1345
  }
1372
1346
  function mapAssistant(msg, correlation) {
@@ -1438,11 +1412,11 @@ function tryBuildArtifactEvent(msg, workspaceDir) {
1438
1412
  const filePath = toolUseResult && typeof toolUseResult.filePath === "string" ? toolUseResult.filePath : void 0;
1439
1413
  if (!filePath) return void 0;
1440
1414
  const realWorkspaceDir = tryRealpath(workspaceDir) ?? workspaceDir;
1441
- const fileDir = path20.dirname(filePath);
1415
+ const fileDir = path19.dirname(filePath);
1442
1416
  const realFileDir = tryRealpath(fileDir) ?? fileDir;
1443
- const realFilePath = path20.join(realFileDir, path20.basename(filePath));
1444
- const relative = path20.relative(realWorkspaceDir, realFilePath);
1445
- if (relative === "" || relative.startsWith("..") || path20.isAbsolute(relative)) {
1417
+ const realFilePath = path19.join(realFileDir, path19.basename(filePath));
1418
+ const relative = path19.relative(realWorkspaceDir, realFilePath);
1419
+ if (relative === "" || relative.startsWith("..") || path19.isAbsolute(relative)) {
1446
1420
  return void 0;
1447
1421
  }
1448
1422
  return { type: "artifact", name: relative, contentType: guessContentType(filePath) };
@@ -1741,10 +1715,10 @@ var ClaudeAdapter = class {
1741
1715
  );
1742
1716
  }
1743
1717
  const approvalMcpBin = (this.options.resolveApprovalMcpBin ?? resolveApprovalMcpBin)();
1744
- approvalMcpConfigDir = await promises.mkdtemp(path20.join(os.tmpdir(), "byok-approval-mcp-"));
1718
+ approvalMcpConfigDir = await promises.mkdtemp(path19.join(os.tmpdir(), "byok-approval-mcp-"));
1745
1719
  await promises.chmod(approvalMcpConfigDir, 448).catch(() => {
1746
1720
  });
1747
- const mcpConfigPath = path20.join(approvalMcpConfigDir, "mcp-config.json");
1721
+ const mcpConfigPath = path19.join(approvalMcpConfigDir, "mcp-config.json");
1748
1722
  const mcpConfig = {
1749
1723
  mcpServers: {
1750
1724
  [APPROVAL_MCP_SERVER_NAME]: {
@@ -2091,8 +2065,8 @@ function extractArtifactEvents(changes, workspaceDir) {
2091
2065
  const absolutePath = typeof change.path === "string" ? change.path : void 0;
2092
2066
  const kind = typeof change.kind === "string" ? change.kind : void 0;
2093
2067
  if (!absolutePath || kind === "delete") continue;
2094
- const relative = path20.relative(workspaceDir, absolutePath);
2095
- if (relative.length === 0 || relative.startsWith("..") || path20.isAbsolute(relative)) continue;
2068
+ const relative = path19.relative(workspaceDir, absolutePath);
2069
+ if (relative.length === 0 || relative.startsWith("..") || path19.isAbsolute(relative)) continue;
2096
2070
  events.push({ type: "artifact", name: relative, contentType: guessContentType2(relative) });
2097
2071
  }
2098
2072
  return events;
@@ -2113,7 +2087,7 @@ var CONTENT_TYPE_BY_EXTENSION = {
2113
2087
  ".csv": "text/csv"
2114
2088
  };
2115
2089
  function guessContentType2(relativePath) {
2116
- return CONTENT_TYPE_BY_EXTENSION[path20.extname(relativePath).toLowerCase()] ?? "application/octet-stream";
2090
+ return CONTENT_TYPE_BY_EXTENSION[path19.extname(relativePath).toLowerCase()] ?? "application/octet-stream";
2117
2091
  }
2118
2092
  function extractErrorMessage(rawError) {
2119
2093
  if (typeof rawError === "string") return rawError;
@@ -2719,12 +2693,12 @@ var DeviceStore = class _DeviceStore {
2719
2693
  */
2720
2694
  constructor(storeDir, secureDirOptions) {
2721
2695
  this.secureDirOptions = secureDirOptions;
2722
- this.filePath = path20.join(storeDir, "device.json");
2696
+ this.filePath = path19.join(storeDir, "device.json");
2723
2697
  }
2724
2698
  secureDirOptions;
2725
2699
  filePath;
2726
2700
  static defaultDir(productId) {
2727
- return path20.join(os.homedir(), ".byok", productId);
2701
+ return path19.join(os.homedir(), ".byok", productId);
2728
2702
  }
2729
2703
  /**
2730
2704
  * Resolve the one store pathname every daemon/CLI component must share.
@@ -2733,7 +2707,7 @@ var DeviceStore = class _DeviceStore {
2733
2707
  * cwd to pin a quarantine directory inode.
2734
2708
  */
2735
2709
  static resolveDir(productId, configured) {
2736
- return path20.resolve(configured ?? _DeviceStore.defaultDir(productId));
2710
+ return path19.resolve(configured ?? _DeviceStore.defaultDir(productId));
2737
2711
  }
2738
2712
  async load() {
2739
2713
  const opened = await this.openBounded();
@@ -2774,7 +2748,7 @@ var DeviceStore = class _DeviceStore {
2774
2748
  }
2775
2749
  }
2776
2750
  async save(record) {
2777
- const storeDir = path20.dirname(this.filePath);
2751
+ const storeDir = path19.dirname(this.filePath);
2778
2752
  await ensureSecureDir(storeDir, this.secureDirOptions);
2779
2753
  await atomicWriteFile(this.filePath, JSON.stringify(record, null, 2), { mode: 384 });
2780
2754
  }
@@ -3208,19 +3182,19 @@ function shortHash(input) {
3208
3182
  return createHash("sha256").update(input, "utf8").digest("hex").slice(0, 16);
3209
3183
  }
3210
3184
  function controlSocketPath(storeDir) {
3211
- const candidate = path20.join(storeDir, "control.sock");
3185
+ const candidate = path19.join(storeDir, "control.sock");
3212
3186
  if (Buffer.byteLength(candidate, "utf8") <= UNIX_SOCKET_PATH_SOFT_LIMIT) return candidate;
3213
- return path20.join(os.tmpdir(), `byok-${shortHash(storeDir)}`, "sock");
3187
+ return path19.join(os.tmpdir(), `byok-${shortHash(storeDir)}`, "sock");
3214
3188
  }
3215
3189
  function controlPipeName(productId, storeDir) {
3216
- const id = shortHash(`${productId}|${path20.resolve(storeDir)}`);
3190
+ const id = shortHash(`${productId}|${path19.resolve(storeDir)}`);
3217
3191
  return `\\\\.\\pipe\\byok-${id}`;
3218
3192
  }
3219
3193
  function controlEndpointPath(productId, storeDir, platform = process.platform) {
3220
3194
  return platform === "win32" ? controlPipeName(productId, storeDir) : controlSocketPath(storeDir);
3221
3195
  }
3222
3196
  function controlTokenPath(storeDir) {
3223
- return path20.join(storeDir, "control.token");
3197
+ return path19.join(storeDir, "control.token");
3224
3198
  }
3225
3199
  var SERVER_PROOF_LABEL = "byok-control-server|";
3226
3200
  var CLIENT_AUTH_LABEL = "byok-control-client|";
@@ -3377,7 +3351,7 @@ async function assertOwnedPrivateDir(dir) {
3377
3351
  }
3378
3352
  async function bindControlEndpoint(server, endpoint) {
3379
3353
  if (process.platform !== "win32") {
3380
- const endpointDir = path20.dirname(endpoint);
3354
+ const endpointDir = path19.dirname(endpoint);
3381
3355
  await promises.mkdir(endpointDir, { recursive: true, mode: 448 });
3382
3356
  await promises.chmod(endpointDir, 448).catch(() => {
3383
3357
  });
@@ -4658,7 +4632,7 @@ function sameFileState2(left, right) {
4658
4632
  return left.dev === right.dev && left.ino === right.ino && left.size === right.size && left.mtimeNs === right.mtimeNs && left.ctimeNs === right.ctimeNs;
4659
4633
  }
4660
4634
  async function openOperationalHealthFile(storeDir) {
4661
- const filePath = path20.join(storeDir, OPERATIONAL_HEALTH_FILENAME);
4635
+ const filePath = path19.join(storeDir, OPERATIONAL_HEALTH_FILENAME);
4662
4636
  let namedBefore;
4663
4637
  try {
4664
4638
  namedBefore = await promises.lstat(filePath, { bigint: true });
@@ -4700,7 +4674,7 @@ var OperationalHealthTracker = class {
4700
4674
  #writeTail = Promise.resolve();
4701
4675
  #started = false;
4702
4676
  constructor(storeDir, options = {}) {
4703
- this.#filePath = path20.join(storeDir, OPERATIONAL_HEALTH_FILENAME);
4677
+ this.#filePath = path19.join(storeDir, OPERATIONAL_HEALTH_FILENAME);
4704
4678
  this.#windowMs = options.windowMs ?? 6e4;
4705
4679
  this.#failureThreshold = options.failureThreshold ?? 3;
4706
4680
  this.#maxFailures = options.maxFailures ?? 128;
@@ -4787,7 +4761,7 @@ var OperationalHealthTracker = class {
4787
4761
  async #load() {
4788
4762
  let opened;
4789
4763
  try {
4790
- opened = await openOperationalHealthFile(path20.dirname(this.#filePath));
4764
+ opened = await openOperationalHealthFile(path19.dirname(this.#filePath));
4791
4765
  } catch (err) {
4792
4766
  throw new Error("operational health state could not be read");
4793
4767
  }
@@ -4823,7 +4797,7 @@ var OperationalHealthTracker = class {
4823
4797
  if (!this.#state) return;
4824
4798
  const body = JSON.stringify(this.#state, null, 2);
4825
4799
  this.#writeTail = this.#writeTail.then(async () => {
4826
- await ensureSecureDir(path20.dirname(this.#filePath));
4800
+ await ensureSecureDir(path19.dirname(this.#filePath));
4827
4801
  await atomicWriteFile(this.#filePath, body, { mode: 384, fsync: true });
4828
4802
  });
4829
4803
  try {
@@ -5179,8 +5153,8 @@ async function acquireDaemonOwner(storeDir, role, clock = () => /* @__PURE__ */
5179
5153
  await mutex.close().catch(() => void 0);
5180
5154
  throw err;
5181
5155
  }
5182
- const ownerPath = path20.join(storeDir, DAEMON_OWNER_FILENAME);
5183
- const reclaimPath = path20.join(storeDir, RECLAIM_FILENAME);
5156
+ const ownerPath = path19.join(storeDir, DAEMON_OWNER_FILENAME);
5157
+ const reclaimPath = path19.join(storeDir, RECLAIM_FILENAME);
5184
5158
  const record = {
5185
5159
  version: 2,
5186
5160
  pid: process.pid,
@@ -5257,7 +5231,7 @@ var CursorStore = class {
5257
5231
  storeDir;
5258
5232
  fileFor(serverUrl, deviceId) {
5259
5233
  const key = createHash("sha256").update(`${serverUrl}::${deviceId}`).digest("hex").slice(0, 32);
5260
- return path20.join(this.storeDir, `cursor-${key}.json`);
5234
+ return path19.join(this.storeDir, `cursor-${key}.json`);
5261
5235
  }
5262
5236
  async load(serverUrl, deviceId) {
5263
5237
  let raw;
@@ -5277,7 +5251,7 @@ var CursorStore = class {
5277
5251
  }
5278
5252
  async save(serverUrl, deviceId, cursor) {
5279
5253
  const file = this.fileFor(serverUrl, deviceId);
5280
- await promises.mkdir(path20.dirname(file), { recursive: true, mode: 448 });
5254
+ await promises.mkdir(path19.dirname(file), { recursive: true, mode: 448 });
5281
5255
  await atomicWriteFile(file, JSON.stringify({ cursor }));
5282
5256
  }
5283
5257
  /** Remove any persisted cursor for (serverUrl, deviceId) — a no-op if none exists. Called from `pair()` (finding F5) so a device that's about to be replaced never leaves a cursor a future, unrelated device could somehow inherit. */
@@ -5573,7 +5547,7 @@ var SessionWorkspaceStore = class {
5573
5547
  */
5574
5548
  queue = Promise.resolve();
5575
5549
  constructor(storeDir) {
5576
- this.filePath = path20.join(storeDir, "session-workspaces.json");
5550
+ this.filePath = path19.join(storeDir, "session-workspaces.json");
5577
5551
  }
5578
5552
  async get(sessionRef) {
5579
5553
  return this.enqueue(async () => {
@@ -5631,7 +5605,7 @@ var SessionWorkspaceStore = class {
5631
5605
  }
5632
5606
  }
5633
5607
  async save(all) {
5634
- const dir = path20.dirname(this.filePath);
5608
+ const dir = path19.dirname(this.filePath);
5635
5609
  await promises.mkdir(dir, { recursive: true, mode: 448 });
5636
5610
  const tmpPath = `${this.filePath}.${process.pid}-${tmpSeq2++}.tmp`;
5637
5611
  try {
@@ -5736,9 +5710,9 @@ function isSqliteAvailable() {
5736
5710
  }
5737
5711
  }
5738
5712
  var SECURE_FILE_MODE = 384;
5739
- function openJournalDatabase(path25, busyTimeoutMs, faults) {
5713
+ function openJournalDatabase(path24, busyTimeoutMs, faults) {
5740
5714
  const { DatabaseSync } = loadSqliteModule();
5741
- const db = new DatabaseSync(path25, { timeout: busyTimeoutMs });
5715
+ const db = new DatabaseSync(path24, { timeout: busyTimeoutMs });
5742
5716
  try {
5743
5717
  faults?.onStep?.("after-open");
5744
5718
  db.exec("PRAGMA auto_vacuum = INCREMENTAL;");
@@ -5881,9 +5855,9 @@ var RECEIVED_STATE = "received";
5881
5855
  function byteLength(value) {
5882
5856
  return Buffer.byteLength(value, "utf8");
5883
5857
  }
5884
- function fileBytes(path25) {
5858
+ function fileBytes(path24) {
5885
5859
  try {
5886
- return statSync(path25).size;
5860
+ return statSync(path24).size;
5887
5861
  } catch {
5888
5862
  return 0;
5889
5863
  }
@@ -7134,8 +7108,8 @@ function estimateEventBytes(event) {
7134
7108
  }
7135
7109
  async function openArtifact(workspaceDir, name) {
7136
7110
  const realWorkspaceDir = await promises.realpath(workspaceDir).catch(() => workspaceDir);
7137
- const candidate = path20.resolve(realWorkspaceDir, name);
7138
- const prefix = realWorkspaceDir.endsWith(path20.sep) ? realWorkspaceDir : realWorkspaceDir + path20.sep;
7111
+ const candidate = path19.resolve(realWorkspaceDir, name);
7112
+ const prefix = realWorkspaceDir.endsWith(path19.sep) ? realWorkspaceDir : realWorkspaceDir + path19.sep;
7139
7113
  if (candidate !== realWorkspaceDir && !candidate.startsWith(prefix)) {
7140
7114
  return { ok: false, reason: `artifact name "${name}" resolves outside the task workspace \u2014 rejected` };
7141
7115
  }
@@ -7533,7 +7507,7 @@ var TaskRunner = class {
7533
7507
  const sameProtocolTask = ledger?.taskId === taskId;
7534
7508
  const interruptedOldTask = ledger?.phase === "interrupted" && sameProtocolTask;
7535
7509
  const activeDifferentTask = ledger !== void 0 && ledger.taskId !== taskId && (ledger.phase === "preparing" || ledger.phase === "active");
7536
- if (!known || known.workspaceKind !== "git" || !known.gitWorkspaceId || !ledger || ledger.workspaceId !== known.gitWorkspaceId || ledger.sessionRef !== payload.sessionRef || path20.resolve(ledger.workspaceDir) !== path20.resolve(known.workspaceDir) || interruptedOldTask || activeDifferentTask) {
7510
+ if (!known || known.workspaceKind !== "git" || !known.gitWorkspaceId || !ledger || ledger.workspaceId !== known.gitWorkspaceId || ledger.sessionRef !== payload.sessionRef || path19.resolve(ledger.workspaceDir) !== path19.resolve(known.workspaceDir) || interruptedOldTask || activeDifferentTask) {
7537
7511
  this.decline(taskId, "session is incompatible with Git workspace mode", true);
7538
7512
  return;
7539
7513
  }
@@ -7548,7 +7522,7 @@ var TaskRunner = class {
7548
7522
  return;
7549
7523
  }
7550
7524
  } else {
7551
- workspaceDir = path20.join(this.deps.workspaceRoot, taskId);
7525
+ workspaceDir = path19.join(this.deps.workspaceRoot, taskId);
7552
7526
  }
7553
7527
  try {
7554
7528
  gitLease = await gitManager.acquireLease(workspaceDir, payload.sessionRef);
@@ -7558,7 +7532,7 @@ var TaskRunner = class {
7558
7532
  }
7559
7533
  } else if (!this.deps.gitWorkspaceManager && !this.deps.gitWorkspaceStore) {
7560
7534
  known = payload.sessionRef ? await this.deps.sessionWorkspaces.get(payload.sessionRef) : void 0;
7561
- workspaceDir = known?.workspaceDir ?? path20.join(this.deps.workspaceRoot, taskId);
7535
+ workspaceDir = known?.workspaceDir ?? path19.join(this.deps.workspaceRoot, taskId);
7562
7536
  plainWorkspaceNeedsResolve = true;
7563
7537
  } else {
7564
7538
  this.decline(taskId, "workspace mode is unavailable", true);
@@ -8430,7 +8404,7 @@ var TaskRunner = class {
8430
8404
  }
8431
8405
  /** `reuseDir`, when set (a known sessionRef's recorded workspace), is used verbatim instead of a fresh `workspaceRoot/<taskId>` directory — `mkdir recursive` is idempotent either way, so ensuring-exists is safe to do unconditionally. */
8432
8406
  async resolveWorkspaceDir(taskId, reuseDir) {
8433
- const dir = reuseDir ?? path20.join(this.deps.workspaceRoot, taskId);
8407
+ const dir = reuseDir ?? path19.join(this.deps.workspaceRoot, taskId);
8434
8408
  await promises.mkdir(dir, { recursive: true });
8435
8409
  return dir;
8436
8410
  }
@@ -9286,8 +9260,8 @@ function generateLaunchdPlist(def) {
9286
9260
  const { label, program, logDir } = def;
9287
9261
  const args = [program.command, ...program.args];
9288
9262
  const cwd = program.cwd ?? os.homedir();
9289
- const outLog = path20.join(logDir, `${label}.out.log`);
9290
- const errLog = path20.join(logDir, `${label}.err.log`);
9263
+ const outLog = path19.join(logDir, `${label}.out.log`);
9264
+ const errLog = path19.join(logDir, `${label}.err.log`);
9291
9265
  return `<?xml version="1.0" encoding="UTF-8"?>
9292
9266
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
9293
9267
  <plist version="1.0">
@@ -9328,7 +9302,7 @@ function createLaunchdLifecycle(def, deps = {}) {
9328
9302
  return process.getuid();
9329
9303
  });
9330
9304
  const label = sanitizeServiceName(def.name);
9331
- const plistPath = () => path20.join(homedir(), "Library", "LaunchAgents", `${label}.plist`);
9305
+ const plistPath = () => path19.join(homedir(), "Library", "LaunchAgents", `${label}.plist`);
9332
9306
  const domainTarget = () => `gui/${getuid()}`;
9333
9307
  const serviceTarget = () => `${domainTarget()}/${label}`;
9334
9308
  async function fileExists(p) {
@@ -9341,7 +9315,7 @@ function createLaunchdLifecycle(def, deps = {}) {
9341
9315
  }
9342
9316
  async function writePlist(program) {
9343
9317
  const xml = generateLaunchdPlist({ label, program, logDir: def.logDir });
9344
- await fs19.mkdir(path20.dirname(plistPath()), { recursive: true });
9318
+ await fs19.mkdir(path19.dirname(plistPath()), { recursive: true });
9345
9319
  await fs19.mkdir(def.logDir, { recursive: true });
9346
9320
  await fs19.writeFile(plistPath(), xml, "utf8");
9347
9321
  }
@@ -9415,8 +9389,8 @@ function generateSystemdUnit(def) {
9415
9389
  assertNoControlChars(displayName, "displayName");
9416
9390
  const cwd = program.cwd ?? os.homedir();
9417
9391
  assertNoControlChars(cwd, "program.cwd");
9418
- const outLog = path20.join(logDir, `${name}.out.log`);
9419
- const errLog = path20.join(logDir, `${name}.err.log`);
9392
+ const outLog = path19.join(logDir, `${name}.out.log`);
9393
+ const errLog = path19.join(logDir, `${name}.err.log`);
9420
9394
  assertNoControlChars(outLog, "logDir");
9421
9395
  assertNoControlChars(errLog, "logDir");
9422
9396
  const execStart = [program.command, ...program.args].map(quoteSystemdArg).join(" ");
@@ -9442,7 +9416,7 @@ function createSystemdLifecycle(def, deps = {}) {
9442
9416
  const homedir = deps.homedir ?? (() => os.homedir());
9443
9417
  const name = sanitizeServiceName(def.name);
9444
9418
  const unitName = `${name}.service`;
9445
- const unitPath = () => path20.join(homedir(), ".config", "systemd", "user", unitName);
9419
+ const unitPath = () => path19.join(homedir(), ".config", "systemd", "user", unitName);
9446
9420
  async function fileExists(p) {
9447
9421
  try {
9448
9422
  await fs19.stat(p);
@@ -9453,7 +9427,7 @@ function createSystemdLifecycle(def, deps = {}) {
9453
9427
  }
9454
9428
  async function writeUnit(program) {
9455
9429
  const unit = generateSystemdUnit({ name, displayName: def.displayName ?? def.name, program, logDir: def.logDir });
9456
- await fs19.mkdir(path20.dirname(unitPath()), { recursive: true });
9430
+ await fs19.mkdir(path19.dirname(unitPath()), { recursive: true });
9457
9431
  await fs19.mkdir(def.logDir, { recursive: true });
9458
9432
  await fs19.writeFile(unitPath(), unit, "utf8");
9459
9433
  }
@@ -9535,8 +9509,8 @@ function createWinswLifecycle(def, deps = {}) {
9535
9509
  const winswBin = windows.winswBin;
9536
9510
  const id = sanitizeServiceName(def.name);
9537
9511
  const installDir = windows.installDir ?? def.logDir;
9538
- const exePath = path20.join(installDir, `${id}.exe`);
9539
- const xmlPath = path20.join(installDir, `${id}.xml`);
9512
+ const exePath = path19.join(installDir, `${id}.exe`);
9513
+ const xmlPath = path19.join(installDir, `${id}.xml`);
9540
9514
  async function fileExists(p) {
9541
9515
  try {
9542
9516
  await fs19.stat(p);
@@ -10310,7 +10284,7 @@ function safeProtocol(serverUrl) {
10310
10284
  }
10311
10285
  }
10312
10286
  async function inspectDevice(storeDir) {
10313
- const filePath = path20.join(storeDir, "device.json");
10287
+ const filePath = path19.join(storeDir, "device.json");
10314
10288
  let pathStat;
10315
10289
  try {
10316
10290
  pathStat = await promises.lstat(filePath);
@@ -10390,11 +10364,11 @@ async function copyOpenFileBounded(source, expected, destinationPath) {
10390
10364
  }
10391
10365
  }
10392
10366
  async function inspectJournal(storeDir) {
10393
- const journalPath = path20.join(storeDir, JOURNAL_DB_FILENAME);
10367
+ const journalPath = path19.join(storeDir, JOURNAL_DB_FILENAME);
10394
10368
  try {
10395
10369
  const mainIdentity = await regularFileIdentity(journalPath);
10396
10370
  if (mainIdentity === void 0) return { status: "missing" };
10397
- const walIdentity = await regularFileIdentity(path20.join(storeDir, `${JOURNAL_DB_FILENAME}-wal`));
10371
+ const walIdentity = await regularFileIdentity(path19.join(storeDir, `${JOURNAL_DB_FILENAME}-wal`));
10398
10372
  let sizeBytes = Number(mainIdentity.size);
10399
10373
  let walBytes = walIdentity === void 0 ? void 0 : Number(walIdentity.size);
10400
10374
  if (!isSqliteAvailable()) {
@@ -10402,7 +10376,7 @@ async function inspectJournal(storeDir) {
10402
10376
  }
10403
10377
  const componentNames = [JOURNAL_DB_FILENAME, `${JOURNAL_DB_FILENAME}-wal`, `${JOURNAL_DB_FILENAME}-shm`];
10404
10378
  const initial = /* @__PURE__ */ new Map();
10405
- for (const name of componentNames) initial.set(name, await regularFileIdentity(path20.join(storeDir, name)));
10379
+ for (const name of componentNames) initial.set(name, await regularFileIdentity(path19.join(storeDir, name)));
10406
10380
  const snapshotMain = initial.get(JOURNAL_DB_FILENAME);
10407
10381
  if (!snapshotMain) return { status: "unavailable", reason: "journal changed during diagnostics snapshot" };
10408
10382
  sizeBytes = Number(snapshotMain.size);
@@ -10414,7 +10388,7 @@ async function inspectJournal(storeDir) {
10414
10388
  let handle;
10415
10389
  try {
10416
10390
  handle = await promises.open(
10417
- path20.join(storeDir, name),
10391
+ path19.join(storeDir, name),
10418
10392
  constants.O_RDONLY | constants.O_NONBLOCK | (constants.O_NOFOLLOW ?? 0)
10419
10393
  );
10420
10394
  } catch (err) {
@@ -10443,28 +10417,28 @@ async function inspectJournal(storeDir) {
10443
10417
  reason: "journal exceeds the bounded diagnostics copy limit"
10444
10418
  };
10445
10419
  }
10446
- const tempDir = await promises.mkdtemp(path20.join(os.tmpdir(), "byok-journal-inspect-"));
10420
+ const tempDir = await promises.mkdtemp(path19.join(os.tmpdir(), "byok-journal-inspect-"));
10447
10421
  const { DatabaseSync } = loadSqliteModule();
10448
10422
  let db;
10449
10423
  try {
10450
10424
  for (const name of componentNames) {
10451
10425
  const component = opened.get(name);
10452
- if (component && !await copyOpenFileBounded(component.handle, component.identity, path20.join(tempDir, name))) {
10426
+ if (component && !await copyOpenFileBounded(component.handle, component.identity, path19.join(tempDir, name))) {
10453
10427
  return { status: "unavailable", sizeBytes, ...walBytes === void 0 ? {} : { walBytes }, reason: "journal changed during diagnostics snapshot" };
10454
10428
  }
10455
10429
  }
10456
10430
  for (const [name, component] of opened) {
10457
- if (!sameIdentity(component.identity, identityFromBigIntStat(await component.handle.stat({ bigint: true }))) || !sameIdentity(component.identity, await regularFileIdentity(path20.join(storeDir, name)))) {
10431
+ if (!sameIdentity(component.identity, identityFromBigIntStat(await component.handle.stat({ bigint: true }))) || !sameIdentity(component.identity, await regularFileIdentity(path19.join(storeDir, name)))) {
10458
10432
  return { status: "unavailable", sizeBytes, ...walBytes === void 0 ? {} : { walBytes }, reason: "journal changed during diagnostics snapshot" };
10459
10433
  }
10460
10434
  }
10461
10435
  for (const name of componentNames) {
10462
- if (!opened.has(name) && await regularFileIdentity(path20.join(storeDir, name)) !== void 0) {
10436
+ if (!opened.has(name) && await regularFileIdentity(path19.join(storeDir, name)) !== void 0) {
10463
10437
  return { status: "unavailable", sizeBytes, ...walBytes === void 0 ? {} : { walBytes }, reason: "journal changed during diagnostics snapshot" };
10464
10438
  }
10465
10439
  }
10466
10440
  const header = Buffer.alloc(16);
10467
- const copiedHandle = await promises.open(path20.join(tempDir, JOURNAL_DB_FILENAME), "r");
10441
+ const copiedHandle = await promises.open(path19.join(tempDir, JOURNAL_DB_FILENAME), "r");
10468
10442
  try {
10469
10443
  const { bytesRead } = await copiedHandle.read(header, 0, header.length, 0);
10470
10444
  if (bytesRead !== 16 || header.toString("binary") !== "SQLite format 3\0") {
@@ -10473,7 +10447,7 @@ async function inspectJournal(storeDir) {
10473
10447
  } finally {
10474
10448
  await copiedHandle.close();
10475
10449
  }
10476
- db = new DatabaseSync(path20.join(tempDir, JOURNAL_DB_FILENAME), { readOnly: true });
10450
+ db = new DatabaseSync(path19.join(tempDir, JOURNAL_DB_FILENAME), { readOnly: true });
10477
10451
  const result = db.prepare("PRAGMA quick_check(1)").get();
10478
10452
  if (result?.quick_check !== "ok") {
10479
10453
  return { status: "corrupt", sizeBytes, ...walBytes === void 0 ? {} : { walBytes }, reason: "journal quick_check failed" };
@@ -10508,7 +10482,7 @@ async function inspectWorkspace(workspaceRoot) {
10508
10482
  }
10509
10483
  }
10510
10484
  function readPinnedQuarantineFile(name, maxBytes, includeBytes, budget) {
10511
- if (path20.basename(name) !== name || name === "." || name === "..") {
10485
+ if (path19.basename(name) !== name || name === "." || name === "..") {
10512
10486
  throw new Error("quarantine manifest contains an invalid evidence name");
10513
10487
  }
10514
10488
  const namedBefore = lstatSync(name, { bigint: true });
@@ -10612,10 +10586,10 @@ function inspectQuarantinePinned(dir, expectedDirectory) {
10612
10586
  if (isJournalQuarantineManifest(parsed)) {
10613
10587
  const manifestBase = manifestName.slice(0, -".manifest.json".length);
10614
10588
  const boundNames = parsed.files.map((file) => {
10615
- if (path20.dirname(path20.resolve(file)) !== path20.resolve(".")) {
10589
+ if (path19.dirname(path19.resolve(file)) !== path19.resolve(".")) {
10616
10590
  throw new Error("journal quarantine manifest points outside quarantine");
10617
10591
  }
10618
- return path20.basename(file);
10592
+ return path19.basename(file);
10619
10593
  });
10620
10594
  if (!boundNames.includes(manifestBase)) {
10621
10595
  throw new Error("journal quarantine manifest is not bound to its primary database evidence");
@@ -10655,7 +10629,7 @@ function inspectQuarantinePinned(dir, expectedDirectory) {
10655
10629
  }
10656
10630
  }
10657
10631
  async function inspectQuarantine(storeDir) {
10658
- const dir = path20.join(storeDir, JOURNAL_QUARANTINE_DIRNAME);
10632
+ const dir = path19.join(storeDir, JOURNAL_QUARANTINE_DIRNAME);
10659
10633
  let directory;
10660
10634
  try {
10661
10635
  directory = await promises.lstat(dir, { bigint: true });
@@ -10726,7 +10700,7 @@ function checksFor(snapshot) {
10726
10700
  ];
10727
10701
  }
10728
10702
  async function collectDiagnostics(config, storeDir, options = {}) {
10729
- const resolvedStoreDir = path20.resolve(storeDir);
10703
+ const resolvedStoreDir = path19.resolve(storeDir);
10730
10704
  const adapters = options.adapters ?? defaultRuntimeAdapters(config.runtimeAllowlist);
10731
10705
  const connectControl = options.connectControl ?? connectControlClient;
10732
10706
  const [device, probedRuntimes, health, journal, workspace, quarantine, controlConnection] = await Promise.all([
@@ -10901,7 +10875,7 @@ function publishQuarantineEvidencePinned(quarantineDir, expectedDirectory, sourc
10901
10875
  unlinkSync(sourcePath);
10902
10876
  sourceRemoved = true;
10903
10877
  if (process.platform !== "win32") {
10904
- const directoryFd = openSync(path20.dirname(sourcePath), constants.O_RDONLY);
10878
+ const directoryFd = openSync(path19.dirname(sourcePath), constants.O_RDONLY);
10905
10879
  try {
10906
10880
  fsyncSync(directoryFd);
10907
10881
  } finally {
@@ -10940,10 +10914,10 @@ function publishQuarantineEvidencePinned(quarantineDir, expectedDirectory, sourc
10940
10914
  }
10941
10915
  }
10942
10916
  async function quarantineCorruptOperationalHealth(storeDir, options = {}) {
10943
- const resolvedStoreDir = path20.resolve(storeDir);
10917
+ const resolvedStoreDir = path19.resolve(storeDir);
10944
10918
  const owner = await acquireDaemonOwner(resolvedStoreDir, "doctor", options.clock);
10945
10919
  try {
10946
- const sourcePath = path20.join(resolvedStoreDir, OPERATIONAL_HEALTH_FILENAME);
10920
+ const sourcePath = path19.join(resolvedStoreDir, OPERATIONAL_HEALTH_FILENAME);
10947
10921
  let opened;
10948
10922
  try {
10949
10923
  opened = await openOperationalHealthFile(resolvedStoreDir);
@@ -10960,7 +10934,7 @@ async function quarantineCorruptOperationalHealth(storeDir, options = {}) {
10960
10934
  }
10961
10935
  const sourceStat = await source.stat({ bigint: true });
10962
10936
  if (!sourceStat.isFile()) throw new Error("operational health state is not a regular file; refusing quarantine");
10963
- const quarantineDir = path20.join(resolvedStoreDir, JOURNAL_QUARANTINE_DIRNAME);
10937
+ const quarantineDir = path19.join(resolvedStoreDir, JOURNAL_QUARANTINE_DIRNAME);
10964
10938
  try {
10965
10939
  const existing = await promises.lstat(quarantineDir);
10966
10940
  if (!existing.isDirectory() || existing.isSymbolicLink()) {
@@ -11061,8 +11035,8 @@ function buildServiceDefinition(config, configPath, rest) {
11061
11035
  const name = argValue(rest, "--name") ?? config.productId;
11062
11036
  const agentBin = argValue(rest, "--agent-bin") ?? process.argv[1] ?? "byok-agent";
11063
11037
  const nodeBin = argValue(rest, "--node-bin") ?? process.execPath;
11064
- const absoluteConfigPath = path20.resolve(configPath);
11065
- const logDir = path20.join(resolveStoreDir(config), "service-logs");
11038
+ const absoluteConfigPath = path19.resolve(configPath);
11039
+ const logDir = path19.join(resolveStoreDir(config), "service-logs");
11066
11040
  const definition = {
11067
11041
  name,
11068
11042
  displayName: config.branding?.displayName ?? config.productName,
@@ -11116,7 +11090,7 @@ async function runServiceStatusCommand(config, configPath, rest, deps = {}) {
11116
11090
  log(`detail: ${status.detail.trim() || "(none)"}`);
11117
11091
  }
11118
11092
  function auditLogPath(storeDir) {
11119
- return path20.join(storeDir, "audit.jsonl");
11093
+ return path19.join(storeDir, "audit.jsonl");
11120
11094
  }
11121
11095
  var AUDIT_LOG_MODE = 384;
11122
11096
  var AUDIT_STORE_DIR_MODE = 448;
@@ -11938,11 +11912,11 @@ async function createSupportBundle(config, storeDir, options = {}) {
11938
11912
  };
11939
11913
  }
11940
11914
  async function writeSupportBundle(outputPath, bundle, secureFileOptions = {}) {
11941
- const dir = path20.dirname(outputPath);
11915
+ const dir = path19.dirname(outputPath);
11942
11916
  const parentStat = await promises.stat(dir);
11943
11917
  if (!parentStat.isDirectory()) throw new Error("support bundle output parent is not a directory");
11944
- const privateDir = path20.join(dir, `.${path20.basename(outputPath)}.${process.pid}.${randomUUID()}.private`);
11945
- const tempPath = path20.join(privateDir, "bundle.tmp");
11918
+ const privateDir = path19.join(dir, `.${path19.basename(outputPath)}.${process.pid}.${randomUUID()}.private`);
11919
+ const tempPath = path19.join(privateDir, "bundle.tmp");
11946
11920
  try {
11947
11921
  await promises.mkdir(privateDir, { mode: 448 });
11948
11922
  await ensureSecureDir(privateDir, secureFileOptions);
@@ -11972,7 +11946,7 @@ async function writeSupportBundle(outputPath, bundle, secureFileOptions = {}) {
11972
11946
  // src/bin/commands/support-bundle.ts
11973
11947
  async function runSupportBundleCommand(config, options) {
11974
11948
  if (!options.outputPath) throw new Error("support-bundle requires --output <path>");
11975
- const outputPath = path20.resolve(options.outputPath);
11949
+ const outputPath = path19.resolve(options.outputPath);
11976
11950
  const bundle = await createSupportBundle(config, resolveStoreDir(config), options);
11977
11951
  await writeSupportBundle(outputPath, bundle);
11978
11952
  const log = options.log ?? ((line) => console.log(line));
@@ -12008,8 +11982,8 @@ async function runTasksFollowCommand(config, deps) {
12008
11982
  });
12009
11983
  return;
12010
11984
  }
12011
- const path25 = auditLogPath(storeDir);
12012
- await followAuditLog(path25, (event) => log(formatDaemonEventLine(event)), {
11985
+ const path24 = auditLogPath(storeDir);
11986
+ await followAuditLog(path24, (event) => log(formatDaemonEventLine(event)), {
12013
11987
  signal: deps.signal,
12014
11988
  pollIntervalMs: deps.pollIntervalMs,
12015
11989
  fromEnd: true