@threadbase-sh/streamer 1.54.1 → 1.55.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.cjs CHANGED
@@ -3608,7 +3608,7 @@ var require_thread_stream = __commonJS({
3608
3608
  var { version: version2 } = require_package();
3609
3609
  var { EventEmitter: EventEmitter5 } = require("events");
3610
3610
  var { Worker } = require("worker_threads");
3611
- var { join: join35 } = require("path");
3611
+ var { join: join36 } = require("path");
3612
3612
  var { pathToFileURL } = require("url");
3613
3613
  var { wait } = require_wait();
3614
3614
  var {
@@ -3659,7 +3659,7 @@ var require_thread_stream = __commonJS({
3659
3659
  function createWorker(stream, opts) {
3660
3660
  const { filename, workerData } = opts;
3661
3661
  const bundlerOverrides = "__bundlerPathsOverrides" in globalThis ? globalThis.__bundlerPathsOverrides : {};
3662
- const toExecute = bundlerOverrides["thread-stream-worker"] || join35(__dirname, "lib", "worker.js");
3662
+ const toExecute = bundlerOverrides["thread-stream-worker"] || join36(__dirname, "lib", "worker.js");
3663
3663
  const worker = new Worker(toExecute, {
3664
3664
  ...opts.workerOpts,
3665
3665
  name: opts.workerOpts?.name || "thread-stream",
@@ -4127,7 +4127,7 @@ var require_transport = __commonJS({
4127
4127
  var { createRequire } = require("module");
4128
4128
  var { existsSync: existsSync21 } = require("fs");
4129
4129
  var getCallers = require_caller();
4130
- var { join: join35, isAbsolute: isAbsolute2, sep: sep3 } = require("path");
4130
+ var { join: join36, isAbsolute: isAbsolute2, sep: sep3 } = require("path");
4131
4131
  var { fileURLToPath: fileURLToPath3 } = require("url");
4132
4132
  var sleep = require_atomic_sleep();
4133
4133
  var onExit = require_on_exit_leak_free();
@@ -4280,7 +4280,7 @@ var require_transport = __commonJS({
4280
4280
  throw new Error("only one of target or targets can be specified");
4281
4281
  }
4282
4282
  if (targets) {
4283
- target = bundlerOverrides["pino-worker"] || join35(__dirname, "worker.js");
4283
+ target = bundlerOverrides["pino-worker"] || join36(__dirname, "worker.js");
4284
4284
  options.targets = targets.filter((dest) => dest.target).map((dest) => {
4285
4285
  return {
4286
4286
  ...dest,
@@ -4298,7 +4298,7 @@ var require_transport = __commonJS({
4298
4298
  });
4299
4299
  });
4300
4300
  } else if (pipeline2) {
4301
- target = bundlerOverrides["pino-worker"] || join35(__dirname, "worker.js");
4301
+ target = bundlerOverrides["pino-worker"] || join36(__dirname, "worker.js");
4302
4302
  options.pipelines = [pipeline2.map((dest) => {
4303
4303
  return {
4304
4304
  ...dest,
@@ -4321,7 +4321,7 @@ var require_transport = __commonJS({
4321
4321
  return origin;
4322
4322
  }
4323
4323
  if (origin === "pino/file") {
4324
- return join35(__dirname, "..", "file.js");
4324
+ return join36(__dirname, "..", "file.js");
4325
4325
  }
4326
4326
  let fixTarget2;
4327
4327
  for (const filePath of callers) {
@@ -5302,7 +5302,7 @@ var require_safe_stable_stringify = __commonJS({
5302
5302
  return circularValue;
5303
5303
  }
5304
5304
  let res = "";
5305
- let join35 = ",";
5305
+ let join36 = ",";
5306
5306
  const originalIndentation = indentation;
5307
5307
  if (Array.isArray(value)) {
5308
5308
  if (value.length === 0) {
@@ -5316,7 +5316,7 @@ var require_safe_stable_stringify = __commonJS({
5316
5316
  indentation += spacer;
5317
5317
  res += `
5318
5318
  ${indentation}`;
5319
- join35 = `,
5319
+ join36 = `,
5320
5320
  ${indentation}`;
5321
5321
  }
5322
5322
  const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
@@ -5324,13 +5324,13 @@ ${indentation}`;
5324
5324
  for (; i < maximumValuesToStringify - 1; i++) {
5325
5325
  const tmp2 = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation);
5326
5326
  res += tmp2 !== void 0 ? tmp2 : "null";
5327
- res += join35;
5327
+ res += join36;
5328
5328
  }
5329
5329
  const tmp = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation);
5330
5330
  res += tmp !== void 0 ? tmp : "null";
5331
5331
  if (value.length - 1 > maximumBreadth) {
5332
5332
  const removedKeys = value.length - maximumBreadth - 1;
5333
- res += `${join35}"... ${getItemCount(removedKeys)} not stringified"`;
5333
+ res += `${join36}"... ${getItemCount(removedKeys)} not stringified"`;
5334
5334
  }
5335
5335
  if (spacer !== "") {
5336
5336
  res += `
@@ -5351,7 +5351,7 @@ ${originalIndentation}`;
5351
5351
  let separator = "";
5352
5352
  if (spacer !== "") {
5353
5353
  indentation += spacer;
5354
- join35 = `,
5354
+ join36 = `,
5355
5355
  ${indentation}`;
5356
5356
  whitespace = " ";
5357
5357
  }
@@ -5365,13 +5365,13 @@ ${indentation}`;
5365
5365
  const tmp = stringifyFnReplacer(key2, value, stack, replacer, spacer, indentation);
5366
5366
  if (tmp !== void 0) {
5367
5367
  res += `${separator}${strEscape(key2)}:${whitespace}${tmp}`;
5368
- separator = join35;
5368
+ separator = join36;
5369
5369
  }
5370
5370
  }
5371
5371
  if (keyLength > maximumBreadth) {
5372
5372
  const removedKeys = keyLength - maximumBreadth;
5373
5373
  res += `${separator}"...":${whitespace}"${getItemCount(removedKeys)} not stringified"`;
5374
- separator = join35;
5374
+ separator = join36;
5375
5375
  }
5376
5376
  if (spacer !== "" && separator.length > 1) {
5377
5377
  res = `
@@ -5412,7 +5412,7 @@ ${originalIndentation}`;
5412
5412
  }
5413
5413
  const originalIndentation = indentation;
5414
5414
  let res = "";
5415
- let join35 = ",";
5415
+ let join36 = ",";
5416
5416
  if (Array.isArray(value)) {
5417
5417
  if (value.length === 0) {
5418
5418
  return "[]";
@@ -5425,7 +5425,7 @@ ${originalIndentation}`;
5425
5425
  indentation += spacer;
5426
5426
  res += `
5427
5427
  ${indentation}`;
5428
- join35 = `,
5428
+ join36 = `,
5429
5429
  ${indentation}`;
5430
5430
  }
5431
5431
  const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
@@ -5433,13 +5433,13 @@ ${indentation}`;
5433
5433
  for (; i < maximumValuesToStringify - 1; i++) {
5434
5434
  const tmp2 = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation);
5435
5435
  res += tmp2 !== void 0 ? tmp2 : "null";
5436
- res += join35;
5436
+ res += join36;
5437
5437
  }
5438
5438
  const tmp = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation);
5439
5439
  res += tmp !== void 0 ? tmp : "null";
5440
5440
  if (value.length - 1 > maximumBreadth) {
5441
5441
  const removedKeys = value.length - maximumBreadth - 1;
5442
- res += `${join35}"... ${getItemCount(removedKeys)} not stringified"`;
5442
+ res += `${join36}"... ${getItemCount(removedKeys)} not stringified"`;
5443
5443
  }
5444
5444
  if (spacer !== "") {
5445
5445
  res += `
@@ -5452,7 +5452,7 @@ ${originalIndentation}`;
5452
5452
  let whitespace = "";
5453
5453
  if (spacer !== "") {
5454
5454
  indentation += spacer;
5455
- join35 = `,
5455
+ join36 = `,
5456
5456
  ${indentation}`;
5457
5457
  whitespace = " ";
5458
5458
  }
@@ -5461,7 +5461,7 @@ ${indentation}`;
5461
5461
  const tmp = stringifyArrayReplacer(key2, value[key2], stack, replacer, spacer, indentation);
5462
5462
  if (tmp !== void 0) {
5463
5463
  res += `${separator}${strEscape(key2)}:${whitespace}${tmp}`;
5464
- separator = join35;
5464
+ separator = join36;
5465
5465
  }
5466
5466
  }
5467
5467
  if (spacer !== "" && separator.length > 1) {
@@ -5519,20 +5519,20 @@ ${originalIndentation}`;
5519
5519
  indentation += spacer;
5520
5520
  let res2 = `
5521
5521
  ${indentation}`;
5522
- const join36 = `,
5522
+ const join37 = `,
5523
5523
  ${indentation}`;
5524
5524
  const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
5525
5525
  let i = 0;
5526
5526
  for (; i < maximumValuesToStringify - 1; i++) {
5527
5527
  const tmp2 = stringifyIndent(String(i), value[i], stack, spacer, indentation);
5528
5528
  res2 += tmp2 !== void 0 ? tmp2 : "null";
5529
- res2 += join36;
5529
+ res2 += join37;
5530
5530
  }
5531
5531
  const tmp = stringifyIndent(String(i), value[i], stack, spacer, indentation);
5532
5532
  res2 += tmp !== void 0 ? tmp : "null";
5533
5533
  if (value.length - 1 > maximumBreadth) {
5534
5534
  const removedKeys = value.length - maximumBreadth - 1;
5535
- res2 += `${join36}"... ${getItemCount(removedKeys)} not stringified"`;
5535
+ res2 += `${join37}"... ${getItemCount(removedKeys)} not stringified"`;
5536
5536
  }
5537
5537
  res2 += `
5538
5538
  ${originalIndentation}`;
@@ -5548,16 +5548,16 @@ ${originalIndentation}`;
5548
5548
  return '"[Object]"';
5549
5549
  }
5550
5550
  indentation += spacer;
5551
- const join35 = `,
5551
+ const join36 = `,
5552
5552
  ${indentation}`;
5553
5553
  let res = "";
5554
5554
  let separator = "";
5555
5555
  let maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth);
5556
5556
  if (isTypedArrayWithEntries(value)) {
5557
- res += stringifyTypedArray(value, join35, maximumBreadth);
5557
+ res += stringifyTypedArray(value, join36, maximumBreadth);
5558
5558
  keys = keys.slice(value.length);
5559
5559
  maximumPropertiesToStringify -= value.length;
5560
- separator = join35;
5560
+ separator = join36;
5561
5561
  }
5562
5562
  if (deterministic) {
5563
5563
  keys = sort(keys, comparator);
@@ -5568,13 +5568,13 @@ ${indentation}`;
5568
5568
  const tmp = stringifyIndent(key2, value[key2], stack, spacer, indentation);
5569
5569
  if (tmp !== void 0) {
5570
5570
  res += `${separator}${strEscape(key2)}: ${tmp}`;
5571
- separator = join35;
5571
+ separator = join36;
5572
5572
  }
5573
5573
  }
5574
5574
  if (keyLength > maximumBreadth) {
5575
5575
  const removedKeys = keyLength - maximumBreadth;
5576
5576
  res += `${separator}"...": "${getItemCount(removedKeys)} not stringified"`;
5577
- separator = join35;
5577
+ separator = join36;
5578
5578
  }
5579
5579
  if (separator !== "") {
5580
5580
  res = `
@@ -103103,17 +103103,17 @@ var init_query_timing = __esm({
103103
103103
  // src/db/sqlite-migrate.ts
103104
103104
  function getMigrationsDir() {
103105
103105
  if (typeof import_meta2 !== "undefined" && import_meta2.url) {
103106
- return (0, import_path14.dirname)((0, import_url6.fileURLToPath)(import_meta2.url));
103106
+ return (0, import_path15.dirname)((0, import_url6.fileURLToPath)(import_meta2.url));
103107
103107
  }
103108
103108
  return __dirname;
103109
103109
  }
103110
103110
  function resolveMigrationsDir(name = "migrations") {
103111
- return (0, import_path14.join)(getMigrationsDir(), name);
103111
+ return (0, import_path15.join)(getMigrationsDir(), name);
103112
103112
  }
103113
103113
  function runSqliteMigrations(db, migrationsDir) {
103114
103114
  db.exec(SCHEMA_MIGRATIONS_SQL);
103115
103115
  const dir = migrationsDir ?? resolveMigrationsDir();
103116
- const files = (0, import_fs15.readdirSync)(dir).filter((f2) => f2.endsWith(".sql")).sort();
103116
+ const files = (0, import_fs16.readdirSync)(dir).filter((f2) => f2.endsWith(".sql")).sort();
103117
103117
  const appliedRows = db.prepare("SELECT id FROM schema_migrations").all();
103118
103118
  const appliedSet = new Set(appliedRows.map((r) => r.id));
103119
103119
  const recordApplied = db.prepare("INSERT INTO schema_migrations (id, applied_at) VALUES (?, ?)");
@@ -103124,7 +103124,7 @@ function runSqliteMigrations(db, migrationsDir) {
103124
103124
  skipped.push(file2);
103125
103125
  continue;
103126
103126
  }
103127
- const sql = (0, import_fs15.readFileSync)((0, import_path14.join)(dir, file2), "utf-8");
103127
+ const sql = (0, import_fs16.readFileSync)((0, import_path15.join)(dir, file2), "utf-8");
103128
103128
  const tx = db.transaction(() => {
103129
103129
  db.exec(sql);
103130
103130
  recordApplied.run(file2, (/* @__PURE__ */ new Date()).toISOString());
@@ -103134,12 +103134,12 @@ function runSqliteMigrations(db, migrationsDir) {
103134
103134
  }
103135
103135
  return { applied, skipped };
103136
103136
  }
103137
- var import_fs15, import_path14, import_url6, import_meta2, SCHEMA_MIGRATIONS_SQL;
103137
+ var import_fs16, import_path15, import_url6, import_meta2, SCHEMA_MIGRATIONS_SQL;
103138
103138
  var init_sqlite_migrate = __esm({
103139
103139
  "src/db/sqlite-migrate.ts"() {
103140
103140
  "use strict";
103141
- import_fs15 = require("fs");
103142
- import_path14 = require("path");
103141
+ import_fs16 = require("fs");
103142
+ import_path15 = require("path");
103143
103143
  import_url6 = require("url");
103144
103144
  import_meta2 = {};
103145
103145
  SCHEMA_MIGRATIONS_SQL = `
@@ -115259,15 +115259,15 @@ __export(runtime_store_exports, {
115259
115259
  resolveRuntimeDbPath: () => resolveRuntimeDbPath
115260
115260
  });
115261
115261
  function resolveRuntimeDbPath(override) {
115262
- return override ?? process.env.THREADBASE_RUNTIME_DB ?? (0, import_path23.join)(process.env.THREADBASE_CONFIG_DIR ?? (0, import_path23.join)((0, import_os9.homedir)(), ".threadbase"), "runtime.db");
115262
+ return override ?? process.env.THREADBASE_RUNTIME_DB ?? (0, import_path24.join)(process.env.THREADBASE_CONFIG_DIR ?? (0, import_path24.join)((0, import_os10.homedir)(), ".threadbase"), "runtime.db");
115263
115263
  }
115264
- var import_better_sqlite33, import_os9, import_path23, RuntimeStore;
115264
+ var import_better_sqlite33, import_os10, import_path24, RuntimeStore;
115265
115265
  var init_runtime_store = __esm({
115266
115266
  "src/db/runtime-store.ts"() {
115267
115267
  "use strict";
115268
115268
  import_better_sqlite33 = __toESM(require("better-sqlite3"), 1);
115269
- import_os9 = require("os");
115270
- import_path23 = require("path");
115269
+ import_os10 = require("os");
115270
+ import_path24 = require("path");
115271
115271
  init_query_timing();
115272
115272
  init_sqlite_migrate();
115273
115273
  RuntimeStore = class _RuntimeStore {
@@ -120449,12 +120449,12 @@ var init_pty_shared = __esm({
120449
120449
 
120450
120450
  // src/services/questions/codexGateAnswers.ts
120451
120451
  function gateAnswersPath() {
120452
- const dir = process.env.THREADBASE_CONFIG_DIR ?? (0, import_path24.join)((0, import_os10.homedir)(), ".threadbase");
120453
- return (0, import_path24.join)(dir, "gate-answers.json");
120452
+ const dir = process.env.THREADBASE_CONFIG_DIR ?? (0, import_path25.join)((0, import_os11.homedir)(), ".threadbase");
120453
+ return (0, import_path25.join)(dir, "gate-answers.json");
120454
120454
  }
120455
120455
  function loadGateAnswers() {
120456
120456
  try {
120457
- const parsed = JSON.parse((0, import_fs24.readFileSync)(gateAnswersPath(), "utf-8"));
120457
+ const parsed = JSON.parse((0, import_fs25.readFileSync)(gateAnswersPath(), "utf-8"));
120458
120458
  return parsed && typeof parsed === "object" ? parsed : {};
120459
120459
  } catch {
120460
120460
  return {};
@@ -120462,8 +120462,8 @@ function loadGateAnswers() {
120462
120462
  }
120463
120463
  function saveGateAnswer(key, value) {
120464
120464
  const path2 = gateAnswersPath();
120465
- (0, import_fs24.mkdirSync)((0, import_path24.dirname)(path2), { recursive: true });
120466
- (0, import_fs24.writeFileSync)(path2, `${JSON.stringify({ ...loadGateAnswers(), [key]: value }, null, 2)}
120465
+ (0, import_fs25.mkdirSync)((0, import_path25.dirname)(path2), { recursive: true });
120466
+ (0, import_fs25.writeFileSync)(path2, `${JSON.stringify({ ...loadGateAnswers(), [key]: value }, null, 2)}
120467
120467
  `);
120468
120468
  }
120469
120469
  function rememberedGateDigit(gate) {
@@ -120475,13 +120475,13 @@ function rememberedGateDigit(gate) {
120475
120475
  }
120476
120476
  return answers.codexTrustGate === "yes" ? "1" : null;
120477
120477
  }
120478
- var import_fs24, import_os10, import_path24;
120478
+ var import_fs25, import_os11, import_path25;
120479
120479
  var init_codexGateAnswers = __esm({
120480
120480
  "src/services/questions/codexGateAnswers.ts"() {
120481
120481
  "use strict";
120482
- import_fs24 = require("fs");
120483
- import_os10 = require("os");
120484
- import_path24 = require("path");
120482
+ import_fs25 = require("fs");
120483
+ import_os11 = require("os");
120484
+ import_path25 = require("path");
120485
120485
  }
120486
120486
  });
120487
120487
 
@@ -120567,13 +120567,13 @@ function toPublicSession(s3) {
120567
120567
  subStatus: s3.subStatus ?? null
120568
120568
  };
120569
120569
  }
120570
- var import_crypto9, import_fs25, import_path25, OUTPUT_BUFFER_MAX, INPUT_HISTORY_MAX, QUIET_DETECT_MS, CODEX_READY_FALLBACK_MS, SUBMIT_BYTES, CODEX_SUBMIT_DELAY_MS, CODEX_SUBMIT_MAX_WAIT_MS, CODEX_SUBMIT_STALE_MS, CodexPtyRunner;
120570
+ var import_crypto10, import_fs26, import_path26, OUTPUT_BUFFER_MAX, INPUT_HISTORY_MAX, QUIET_DETECT_MS, CODEX_READY_FALLBACK_MS, SUBMIT_BYTES, CODEX_SUBMIT_DELAY_MS, CODEX_SUBMIT_MAX_WAIT_MS, CODEX_SUBMIT_STALE_MS, CodexPtyRunner;
120571
120571
  var init_codex_pty_runner = __esm({
120572
120572
  "src/codex-pty-runner.ts"() {
120573
120573
  "use strict";
120574
- import_crypto9 = require("crypto");
120575
- import_fs25 = require("fs");
120576
- import_path25 = require("path");
120574
+ import_crypto10 = require("crypto");
120575
+ import_fs26 = require("fs");
120576
+ import_path26 = require("path");
120577
120577
  init_logger();
120578
120578
  init_platform();
120579
120579
  init_providers();
@@ -120677,7 +120677,7 @@ var init_codex_pty_runner = __esm({
120677
120677
  // resume, fresh and fork is argv.
120678
120678
  async launch(sessionId, args, options) {
120679
120679
  const nodePty = await loadPty();
120680
- const projectName = options.projectName ?? (0, import_path25.basename)(options.projectPath);
120680
+ const projectName = options.projectName ?? (0, import_path26.basename)(options.projectPath);
120681
120681
  let proc;
120682
120682
  try {
120683
120683
  proc = nodePty.spawn(resolveCodexExe(), args, {
@@ -120726,7 +120726,7 @@ var init_codex_pty_runner = __esm({
120726
120726
  // binding logic). This runner generates a local placeholder id for the
120727
120727
  // ManagedSession handle only.
120728
120728
  async startFresh(options) {
120729
- const sessionId = (0, import_crypto9.randomUUID)();
120729
+ const sessionId = (0, import_crypto10.randomUUID)();
120730
120730
  const args = ["--cd", options.projectPath, "--no-alt-screen"];
120731
120731
  if (options.systemPrompt) {
120732
120732
  args.push(options.systemPrompt);
@@ -120745,7 +120745,7 @@ var init_codex_pty_runner = __esm({
120745
120745
  * until watchForCodexRollout binds the real id.
120746
120746
  */
120747
120747
  async startFork(options) {
120748
- const sessionId = (0, import_crypto9.randomUUID)();
120748
+ const sessionId = (0, import_crypto10.randomUUID)();
120749
120749
  return this.launch(
120750
120750
  sessionId,
120751
120751
  ["fork", options.forkFromId, "--cd", options.projectPath, "--no-alt-screen"],
@@ -121408,7 +121408,7 @@ var init_codex_pty_runner = __esm({
121408
121408
  session.statusUpdatedAt = /* @__PURE__ */ new Date();
121409
121409
  const elapsedMs = session.completedAt.getTime() - session.startedAt.getTime();
121410
121410
  if (exitCode !== 0 && elapsedMs < 2e3 && session.lastOutput === "") {
121411
- if (!(0, import_fs25.existsSync)(session.projectPath)) {
121411
+ if (!(0, import_fs26.existsSync)(session.projectPath)) {
121412
121412
  session.failureReason = `Project directory not found: ${session.projectPath}`;
121413
121413
  } else {
121414
121414
  session.failureReason = `Codex process exited immediately (code ${exitCode}).`;
@@ -121945,13 +121945,13 @@ function toPublicSession2(s3) {
121945
121945
  subStatus: s3.subStatus ?? null
121946
121946
  };
121947
121947
  }
121948
- var import_crypto10, import_fs26, import_path26, OUTPUT_BUFFER_MAX2, INPUT_HISTORY_MAX2, CLAUDE_PROMPT_MARKERS, QUIET_DETECT_MS2, OSC_TAIL_CHARS, SCRAPE_THROTTLE_MS, CLAUDE_READY_FALLBACK_MS, SUBMIT_BYTES2, SUBMIT_DELAY_MS, SUBMIT_MAX_WAIT_MS, PTYManager;
121948
+ var import_crypto11, import_fs27, import_path27, OUTPUT_BUFFER_MAX2, INPUT_HISTORY_MAX2, CLAUDE_PROMPT_MARKERS, QUIET_DETECT_MS2, OSC_TAIL_CHARS, SCRAPE_THROTTLE_MS, CLAUDE_READY_FALLBACK_MS, SUBMIT_BYTES2, SUBMIT_DELAY_MS, SUBMIT_MAX_WAIT_MS, PTYManager;
121949
121949
  var init_pty_manager = __esm({
121950
121950
  "src/pty-manager.ts"() {
121951
121951
  "use strict";
121952
- import_crypto10 = require("crypto");
121953
- import_fs26 = require("fs");
121954
- import_path26 = require("path");
121952
+ import_crypto11 = require("crypto");
121953
+ import_fs27 = require("fs");
121954
+ import_path27 = require("path");
121955
121955
  init_claude_flags();
121956
121956
  init_logger();
121957
121957
  init_platform();
@@ -122076,7 +122076,7 @@ var init_pty_manager = __esm({
122076
122076
  }
122077
122077
  async doStart(sessionId, options) {
122078
122078
  const nodePty = await loadPty();
122079
- const projectName = options.projectName ?? (0, import_path26.basename)(options.projectPath);
122079
+ const projectName = options.projectName ?? (0, import_path27.basename)(options.projectPath);
122080
122080
  const permissionMode = options.permissionMode ?? "acceptEdits";
122081
122081
  const args = [
122082
122082
  "--permission-mode",
@@ -122139,8 +122139,8 @@ var init_pty_manager = __esm({
122139
122139
  // onReady fires once Claude reaches its first prompt (waiting_input).
122140
122140
  async startFresh(options) {
122141
122141
  const nodePty = await loadPty();
122142
- const sessionId = (0, import_crypto10.randomUUID)();
122143
- const projectName = options.projectName ?? (0, import_path26.basename)(options.projectPath);
122142
+ const sessionId = (0, import_crypto11.randomUUID)();
122143
+ const projectName = options.projectName ?? (0, import_path27.basename)(options.projectPath);
122144
122144
  const permissionMode = options.permissionMode ?? "acceptEdits";
122145
122145
  const args = [
122146
122146
  "--permission-mode",
@@ -122739,7 +122739,7 @@ var init_pty_manager = __esm({
122739
122739
  session.statusUpdatedAt = /* @__PURE__ */ new Date();
122740
122740
  const elapsedMs = session.completedAt.getTime() - session.startedAt.getTime();
122741
122741
  if (exitCode !== 0 && elapsedMs < 2e3 && session.lastOutput === "") {
122742
- if (!(0, import_fs26.existsSync)(session.projectPath)) {
122742
+ if (!(0, import_fs27.existsSync)(session.projectPath)) {
122743
122743
  session.failureReason = `Project directory not found: ${session.projectPath}`;
122744
122744
  } else {
122745
122745
  session.failureReason = `Process exited immediately (code ${exitCode}). Check that the Claude binary is installed and accessible.`;
@@ -122765,11 +122765,11 @@ var init_pty_manager = __esm({
122765
122765
  });
122766
122766
 
122767
122767
  // src/live-session-manager.ts
122768
- var import_path27, LiveSessionManager;
122768
+ var import_path28, LiveSessionManager;
122769
122769
  var init_live_session_manager = __esm({
122770
122770
  "src/live-session-manager.ts"() {
122771
122771
  "use strict";
122772
- import_path27 = require("path");
122772
+ import_path28 = require("path");
122773
122773
  init_codex_pty_runner();
122774
122774
  init_providers();
122775
122775
  init_remote_session_runner();
@@ -122912,7 +122912,7 @@ var init_live_session_manager = __esm({
122912
122912
  const runner = this.runners.get(provider);
122913
122913
  if (runner) return runner;
122914
122914
  const err = new Error(
122915
- `Live ${provider} sessions are not implemented yet for ${(0, import_path27.basename)(projectPath)}`
122915
+ `Live ${provider} sessions are not implemented yet for ${(0, import_path28.basename)(projectPath)}`
122916
122916
  );
122917
122917
  err.statusCode = 501;
122918
122918
  throw err;
@@ -123053,9 +123053,9 @@ async function probePtyHostStatus(socketPath, timeoutMs = 1e3) {
123053
123053
  }
123054
123054
  async function listenForStreamers(socketPath, handlers) {
123055
123055
  if (process.platform !== "win32") {
123056
- const { mkdirSync: mkdirSync16, rmSync: rmSync6 } = await import("fs");
123057
- const { dirname: dirname17 } = await import("path");
123058
- mkdirSync16(dirname17(socketPath), { recursive: true });
123056
+ const { mkdirSync: mkdirSync17, rmSync: rmSync6 } = await import("fs");
123057
+ const { dirname: dirname18 } = await import("path");
123058
+ mkdirSync17(dirname18(socketPath), { recursive: true });
123059
123059
  try {
123060
123060
  const probe = await connectToHost(socketPath);
123061
123061
  probe.close();
@@ -132027,13 +132027,13 @@ Content-Length: 0\r
132027
132027
 
132028
132028
  // src/server.ts
132029
132029
  var import_client = __toESM(require_lib3(), 1);
132030
- var import_crypto13 = require("crypto");
132030
+ var import_crypto14 = require("crypto");
132031
132031
  var import_events2 = require("events");
132032
- var import_fs38 = require("fs");
132032
+ var import_fs39 = require("fs");
132033
132033
  var import_promises16 = require("fs/promises");
132034
132034
  var import_http = require("http");
132035
- var import_os16 = require("os");
132036
- var import_path34 = require("path");
132035
+ var import_os17 = require("os");
132036
+ var import_path35 = require("path");
132037
132037
 
132038
132038
  // src/agent/agent-client.ts
132039
132039
  var userInputSignal = { type: "signal", name: "userInput" };
@@ -135179,7 +135179,7 @@ function createLogsRoutes() {
135179
135179
  // src/api/routes/misc.routes.ts
135180
135180
  var import_node_child_process2 = require("child_process");
135181
135181
  var import_node_crypto2 = require("crypto");
135182
- var import_os5 = require("os");
135182
+ var import_os6 = require("os");
135183
135183
 
135184
135184
  // src/db/repositories/push.repository.ts
135185
135185
  var FAILURE_STREAK_LIMIT = 5;
@@ -135438,6 +135438,67 @@ var PushRepository = class {
135438
135438
  // src/api/routes/misc.routes.ts
135439
135439
  init_logger();
135440
135440
 
135441
+ // src/server-identity.ts
135442
+ var import_crypto4 = require("crypto");
135443
+ var import_fs4 = require("fs");
135444
+ var import_os5 = require("os");
135445
+ var import_path3 = require("path");
135446
+ init_logger();
135447
+ var IDENTITY_FILE_VERSION = 1;
135448
+ function serverIdentityKeyPath() {
135449
+ const dir = process.env.THREADBASE_CONFIG_DIR ?? (0, import_path3.join)((0, import_os5.homedir)(), ".threadbase");
135450
+ return (0, import_path3.join)(dir, "keys", "server-identity.key");
135451
+ }
135452
+ function loadOrCreateServerIdentity() {
135453
+ const path2 = serverIdentityKeyPath();
135454
+ let raw2;
135455
+ try {
135456
+ raw2 = (0, import_fs4.readFileSync)(path2, "utf-8");
135457
+ } catch (err) {
135458
+ if (err.code !== "ENOENT") throw err;
135459
+ return generateIdentity(path2);
135460
+ }
135461
+ let privateKey;
135462
+ try {
135463
+ privateKey = (0, import_crypto4.createPrivateKey)({ key: JSON.parse(raw2).key, format: "jwk" });
135464
+ } catch {
135465
+ throw new Error(
135466
+ `Server identity key at ${path2} could not be read. Refusing to generate a new one \u2014 that would invalidate every paired device. Repair or delete the file deliberately.`
135467
+ );
135468
+ }
135469
+ return { publicKey: publicKeyOf(privateKey), privateKey };
135470
+ }
135471
+ function serverIdentityPublicKey() {
135472
+ return loadOrCreateServerIdentity().publicKey;
135473
+ }
135474
+ function generateIdentity(path2) {
135475
+ const { privateKey } = (0, import_crypto4.generateKeyPairSync)("x25519");
135476
+ const file2 = {
135477
+ v: IDENTITY_FILE_VERSION,
135478
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
135479
+ key: privateKey.export({ format: "jwk" })
135480
+ };
135481
+ (0, import_fs4.mkdirSync)((0, import_path3.dirname)(path2), { recursive: true, mode: 448 });
135482
+ const tmp = `${path2}.tmp`;
135483
+ (0, import_fs4.writeFileSync)(tmp, `${JSON.stringify(file2)}
135484
+ `, { encoding: "utf-8", mode: 384 });
135485
+ (0, import_fs4.chmodSync)(tmp, 384);
135486
+ (0, import_fs4.renameSync)(tmp, path2);
135487
+ const publicKey = publicKeyOf(privateKey);
135488
+ getLogger("identity").info(`Generated server identity key ${publicKey}`, {
135489
+ event: "identity.key_generated",
135490
+ path: path2
135491
+ });
135492
+ return { publicKey, privateKey };
135493
+ }
135494
+ function publicKeyOf(privateKey) {
135495
+ const jwk = (0, import_crypto4.createPublicKey)(privateKey).export({ format: "jwk" });
135496
+ if (jwk.crv !== "X25519" || typeof jwk.x !== "string") {
135497
+ throw new Error(`Server identity key at ${serverIdentityKeyPath()} is not an X25519 key`);
135498
+ }
135499
+ return jwk.x;
135500
+ }
135501
+
135441
135502
  // src/services/push/apnsClient.ts
135442
135503
  var import_node_crypto = require("crypto");
135443
135504
  var import_node_http2 = require("http2");
@@ -135647,6 +135708,21 @@ function describePushCapability(liveActivityEnabled, env = process.env) {
135647
135708
  liveActivityReason: describeMissingApnsCredentials(env) ?? "APNs credentials are set but the push token store is unavailable, so Live Activity push is disabled."
135648
135709
  };
135649
135710
  }
135711
+ var identityKeyFailureLogged = false;
135712
+ function describeServerIdentityKey() {
135713
+ try {
135714
+ return serverIdentityPublicKey();
135715
+ } catch (err) {
135716
+ if (!identityKeyFailureLogged) {
135717
+ identityKeyFailureLogged = true;
135718
+ getLogger("identity").error(
135719
+ `Server identity key unavailable, so /api/info will omit it: ${err instanceof Error ? err.message : String(err)}`,
135720
+ { event: "identity.unavailable" }
135721
+ );
135722
+ }
135723
+ return void 0;
135724
+ }
135725
+ }
135650
135726
  var clientLog = getLogger("client");
135651
135727
  var createMiscRoutes = (deps) => {
135652
135728
  const app = new Hono2();
@@ -135654,7 +135730,7 @@ var createMiscRoutes = (deps) => {
135654
135730
  const ptyIds = deps.ptyAttachedIds();
135655
135731
  return c.json({
135656
135732
  version: getVersion(),
135657
- machineName: (0, import_os5.hostname)(),
135733
+ machineName: (0, import_os6.hostname)(),
135658
135734
  platform: process.platform,
135659
135735
  activeSessions: deps.sessionStore.list(ptyIds).filter((s3) => s3.status === "running").length,
135660
135736
  publicUrl: deps.publicUrl,
@@ -135680,7 +135756,13 @@ var createMiscRoutes = (deps) => {
135680
135756
  // actually send a push, so mobile can hide an affordance instead of
135681
135757
  // registering tokens nothing will ever send to. Absent on older servers,
135682
135758
  // which a client should read as "unknown", not "unavailable".
135683
- push: describePushCapability(deps.liveActivityPushEnabled())
135759
+ push: describePushCapability(deps.liveActivityPushEnabled()),
135760
+ // This server's long-term X25519 public key, base64url. The same value the
135761
+ // pair QR carries as `spk`, served here so an already-paired client can
135762
+ // learn it without re-scanning. Additive: absent means a server with no
135763
+ // readable identity key, which a client must read as "cannot verify this
135764
+ // server" — never as a reason to fail the rest of this response.
135765
+ serverIdentityKey: describeServerIdentityKey()
135684
135766
  });
135685
135767
  });
135686
135768
  app.get("/api/profiles", (c) => c.json([]));
@@ -136319,8 +136401,8 @@ var createHonoApp = (deps, upgradeWebSocket) => {
136319
136401
  };
136320
136402
 
136321
136403
  // node_modules/@threadbase-sh/scanner/dist/index.js
136322
- var import_fs4 = require("fs");
136323
- var import_path3 = require("path");
136404
+ var import_fs5 = require("fs");
136405
+ var import_path4 = require("path");
136324
136406
  var import_pino2 = __toESM(require_pino(), 1);
136325
136407
 
136326
136408
  // node_modules/flexsearch/dist/flexsearch.bundle.module.min.mjs
@@ -138580,42 +138662,42 @@ function Z(a, c) {
138580
138662
  var flexsearch_bundle_module_min_default = { Index: T, Charset: va, Encoder: ka, Document: Na, Worker: La, Resolver: X, IndexedDB: Eb, Language: {} };
138581
138663
 
138582
138664
  // node_modules/@threadbase-sh/scanner/dist/index.js
138583
- var import_fs5 = require("fs");
138584
- var import_path4 = require("path");
138585
- var import_readline = require("readline");
138586
- var import_path5 = require("path");
138587
138665
  var import_fs6 = require("fs");
138588
- var import_promises5 = require("fs/promises");
138589
- var import_os6 = require("os");
138666
+ var import_path5 = require("path");
138667
+ var import_readline = require("readline");
138590
138668
  var import_path6 = require("path");
138591
- var import_fast_glob = __toESM(require_out4(), 1);
138592
138669
  var import_fs7 = require("fs");
138593
- var import_promises6 = require("fs/promises");
138670
+ var import_promises5 = require("fs/promises");
138671
+ var import_os7 = require("os");
138594
138672
  var import_path7 = require("path");
138595
- var import_readline2 = require("readline");
138673
+ var import_fast_glob = __toESM(require_out4(), 1);
138674
+ var import_fs8 = require("fs");
138675
+ var import_promises6 = require("fs/promises");
138596
138676
  var import_path8 = require("path");
138677
+ var import_readline2 = require("readline");
138678
+ var import_path9 = require("path");
138597
138679
  var import_fast_glob2 = __toESM(require_out4(), 1);
138598
138680
  var import_promises7 = require("fs/promises");
138599
138681
  var import_events = require("events");
138600
- var import_fs8 = require("fs");
138601
- var import_os7 = require("os");
138602
- var import_path9 = require("path");
138603
- var import_path10 = require("path");
138604
138682
  var import_fs9 = require("fs");
138605
- var import_promises8 = require("timers/promises");
138683
+ var import_os8 = require("os");
138684
+ var import_path10 = require("path");
138685
+ var import_path11 = require("path");
138606
138686
  var import_fs10 = require("fs");
138607
- var import_promises9 = require("timers/promises");
138608
- var import_crypto4 = require("crypto");
138687
+ var import_promises8 = require("timers/promises");
138609
138688
  var import_fs11 = require("fs");
138689
+ var import_promises9 = require("timers/promises");
138690
+ var import_crypto5 = require("crypto");
138610
138691
  var import_fs12 = require("fs");
138611
138692
  var import_fs13 = require("fs");
138693
+ var import_fs14 = require("fs");
138612
138694
  var import_readline3 = require("readline");
138613
138695
  var import_better_sqlite3 = __toESM(require("better-sqlite3"), 1);
138614
- var import_fs14 = require("fs");
138615
- var import_path11 = require("path");
138616
- var import_promises10 = require("fs/promises");
138696
+ var import_fs15 = require("fs");
138617
138697
  var import_path12 = require("path");
138698
+ var import_promises10 = require("fs/promises");
138618
138699
  var import_path13 = require("path");
138700
+ var import_path14 = require("path");
138619
138701
 
138620
138702
  // node_modules/chokidar/index.js
138621
138703
  var import_node_events2 = require("events");
@@ -139362,9 +139444,9 @@ var NodeFsHandler = class {
139362
139444
  if (this.fsw.closed) {
139363
139445
  return;
139364
139446
  }
139365
- const dirname17 = sp.dirname(file2);
139447
+ const dirname18 = sp.dirname(file2);
139366
139448
  const basename12 = sp.basename(file2);
139367
- const parent = this.fsw._getWatchedDir(dirname17);
139449
+ const parent = this.fsw._getWatchedDir(dirname18);
139368
139450
  let prevStats = stats;
139369
139451
  if (parent.has(basename12))
139370
139452
  return;
@@ -139391,7 +139473,7 @@ var NodeFsHandler = class {
139391
139473
  prevStats = newStats2;
139392
139474
  }
139393
139475
  } catch (error51) {
139394
- this.fsw._remove(dirname17, basename12);
139476
+ this.fsw._remove(dirname18, basename12);
139395
139477
  }
139396
139478
  } else if (parent.has(basename12)) {
139397
139479
  const at2 = newStats.atimeMs;
@@ -140451,9 +140533,9 @@ function readGitBranch(projectPath) {
140451
140533
  let dir = projectPath;
140452
140534
  let depth = 0;
140453
140535
  while (depth < MAX_DEPTH) {
140454
- const headPath = (0, import_path3.join)(dir, ".git", "HEAD");
140536
+ const headPath = (0, import_path4.join)(dir, ".git", "HEAD");
140455
140537
  try {
140456
- const content = (0, import_fs4.readFileSync)(headPath, "utf-8").trim();
140538
+ const content = (0, import_fs5.readFileSync)(headPath, "utf-8").trim();
140457
140539
  if (content.startsWith(REF_PREFIX)) {
140458
140540
  const branch = content.slice(REF_PREFIX.length);
140459
140541
  log15.trace({ projectPath, dir, branch }, "git: branch resolved");
@@ -140466,7 +140548,7 @@ function readGitBranch(projectPath) {
140466
140548
  return null;
140467
140549
  } catch {
140468
140550
  }
140469
- const parent = (0, import_path3.dirname)(dir);
140551
+ const parent = (0, import_path4.dirname)(dir);
140470
140552
  if (parent === dir) return null;
140471
140553
  dir = parent;
140472
140554
  depth++;
@@ -140699,15 +140781,15 @@ function finalizeMeta(state, filePath, account, tier) {
140699
140781
  const isSubagent = filePath.includes("/subagents/");
140700
140782
  let parentSessionId = null;
140701
140783
  if (isSubagent) {
140702
- const uuidDir = (0, import_path5.dirname)((0, import_path5.dirname)(filePath));
140703
- parentSessionId = (0, import_path5.join)((0, import_path5.dirname)(uuidDir), `${(0, import_path5.basename)(uuidDir)}.jsonl`);
140784
+ const uuidDir = (0, import_path6.dirname)((0, import_path6.dirname)(filePath));
140785
+ parentSessionId = (0, import_path6.join)((0, import_path6.dirname)(uuidDir), `${(0, import_path6.basename)(uuidDir)}.jsonl`);
140704
140786
  }
140705
140787
  const projectPath = state.cwd;
140706
140788
  return {
140707
140789
  id: filePath,
140708
140790
  filePath,
140709
140791
  provider: CLAUDE_CODE_PROVIDER2,
140710
- sessionId: state.sessionId || (0, import_path5.basename)(filePath, ".jsonl"),
140792
+ sessionId: state.sessionId || (0, import_path6.basename)(filePath, ".jsonl"),
140711
140793
  sessionName: state.sessionName || deriveSessionNameFromFirstMessage(state.firstMessage),
140712
140794
  projectPath,
140713
140795
  projectName: getShortProjectName(projectPath),
@@ -140767,7 +140849,7 @@ async function parseMeta(filePath, account, tier) {
140767
140849
  const log15 = getLogger2();
140768
140850
  log15.trace({ filePath, account, tier: tier.name }, "parseMeta: start");
140769
140851
  const state = initialReducerState();
140770
- const fileStream = (0, import_fs5.createReadStream)(filePath);
140852
+ const fileStream = (0, import_fs6.createReadStream)(filePath);
140771
140853
  const rl = (0, import_readline.createInterface)({ input: fileStream, crlfDelay: Infinity });
140772
140854
  try {
140773
140855
  for await (const line of rl) {
@@ -140803,7 +140885,7 @@ async function parseConversation(filePath, account) {
140803
140885
  const textParts = [];
140804
140886
  const turnDurations = [];
140805
140887
  const state = initialConvState();
140806
- const fileStream = (0, import_fs5.createReadStream)(filePath);
140888
+ const fileStream = (0, import_fs6.createReadStream)(filePath);
140807
140889
  const rl = (0, import_readline.createInterface)({ input: fileStream, crlfDelay: Infinity });
140808
140890
  try {
140809
140891
  for await (const line of rl) {
@@ -140847,7 +140929,7 @@ async function parseConversation(filePath, account) {
140847
140929
  filePath,
140848
140930
  projectPath: state.cwd,
140849
140931
  projectName: getShortProjectName2(state.cwd),
140850
- sessionId: state.sessionId || (0, import_path4.basename)(filePath, ".jsonl"),
140932
+ sessionId: state.sessionId || (0, import_path5.basename)(filePath, ".jsonl"),
140851
140933
  sessionName: state.sessionName || deriveSessionNameFromFirstMessage(messages.find((m2) => m2.role === "user" && m2.text) ?? null),
140852
140934
  messages,
140853
140935
  fullText: textParts.join(" "),
@@ -141083,23 +141165,23 @@ function buildSidecar(meta3, cursor, updatedAt) {
141083
141165
  }
141084
141166
  function writeSidecar(jsonlPath, sidecar) {
141085
141167
  try {
141086
- (0, import_fs6.writeFileSync)(sidecarPath(jsonlPath), JSON.stringify(sidecar, null, 2));
141168
+ (0, import_fs7.writeFileSync)(sidecarPath(jsonlPath), JSON.stringify(sidecar, null, 2));
141087
141169
  } catch (err) {
141088
141170
  getLogger2().warn({ jsonlPath, err }, "sidecar: write failed");
141089
141171
  }
141090
141172
  }
141091
141173
  var PROFILES_FILE = "profiles.json";
141092
141174
  function resolveConfigDir(configDir2) {
141093
- return configDir2.replace(/^~/, (0, import_os6.homedir)());
141175
+ return configDir2.replace(/^~/, (0, import_os7.homedir)());
141094
141176
  }
141095
141177
  function getProjectsDir(profile) {
141096
- return (0, import_path6.join)(resolveConfigDir(profile.configDir), "projects");
141178
+ return (0, import_path7.join)(resolveConfigDir(profile.configDir), "projects");
141097
141179
  }
141098
141180
  async function detectDefaultProfile() {
141099
141181
  return {
141100
141182
  id: "default",
141101
141183
  label: "Default",
141102
- configDir: (0, import_path6.join)((0, import_os6.homedir)(), ".claude"),
141184
+ configDir: (0, import_path7.join)((0, import_os7.homedir)(), ".claude"),
141103
141185
  enabled: true,
141104
141186
  emoji: "\u{1F916}"
141105
141187
  };
@@ -141108,7 +141190,7 @@ async function loadProfiles(configPath) {
141108
141190
  const log15 = getLogger2();
141109
141191
  try {
141110
141192
  const resolved = resolveConfigDir(configPath);
141111
- const data = await (0, import_promises5.readFile)((0, import_path6.join)(resolved, PROFILES_FILE), "utf-8");
141193
+ const data = await (0, import_promises5.readFile)((0, import_path7.join)(resolved, PROFILES_FILE), "utf-8");
141112
141194
  const profiles = JSON.parse(data);
141113
141195
  log15.debug({ configPath, count: profiles.length }, "profiles: loaded");
141114
141196
  return profiles;
@@ -141119,7 +141201,7 @@ async function loadProfiles(configPath) {
141119
141201
  }
141120
141202
  }
141121
141203
  function canonicalPath(p2) {
141122
- return import_path8.sep === "\\" ? p2.replace(/\//g, "\\") : p2;
141204
+ return import_path9.sep === "\\" ? p2.replace(/\//g, "\\") : p2;
141123
141205
  }
141124
141206
  var CodexCliProvider = class {
141125
141207
  name = CODEX_CLI_PROVIDER2;
@@ -141253,7 +141335,7 @@ function reduceCodexEntry(acc, entry, tier) {
141253
141335
  }
141254
141336
  function finalizeCodexMeta(acc, filePath, account, tier) {
141255
141337
  if (acc.messageCount === 0) return null;
141256
- const sessionId = acc.sessionId || (0, import_path7.basename)(filePath, ".jsonl");
141338
+ const sessionId = acc.sessionId || (0, import_path8.basename)(filePath, ".jsonl");
141257
141339
  const projectPath = acc.cwd;
141258
141340
  const kind = acc.lastAssistant === null && acc.toolNames.length > 0 ? "task" : "conversation";
141259
141341
  return {
@@ -141295,7 +141377,7 @@ async function parseCodexConversation(filePath, account) {
141295
141377
  let cwd = "";
141296
141378
  let latestTimestamp = "";
141297
141379
  let lastUserText = "";
141298
- const rl = (0, import_readline2.createInterface)({ input: (0, import_fs7.createReadStream)(filePath), crlfDelay: Infinity });
141380
+ const rl = (0, import_readline2.createInterface)({ input: (0, import_fs8.createReadStream)(filePath), crlfDelay: Infinity });
141299
141381
  try {
141300
141382
  for await (const line of rl) {
141301
141383
  if (!line.trim()) continue;
@@ -141333,7 +141415,7 @@ async function parseCodexConversation(filePath, account) {
141333
141415
  filePath,
141334
141416
  projectPath: cwd,
141335
141417
  projectName: getShortProjectName3(cwd),
141336
- sessionId: sessionId || (0, import_path7.basename)(filePath, ".jsonl"),
141418
+ sessionId: sessionId || (0, import_path8.basename)(filePath, ".jsonl"),
141337
141419
  sessionName: "",
141338
141420
  messages,
141339
141421
  fullText: textParts.join(" "),
@@ -141475,7 +141557,7 @@ var LRUCache = class {
141475
141557
  };
141476
141558
  var YIELD_EVERY_LINES = 500;
141477
141559
  async function tailReduce(filePath, startOffset, startLine, state, tier) {
141478
- const stream = (0, import_fs10.createReadStream)(filePath, { start: startOffset, encoding: "utf8" });
141560
+ const stream = (0, import_fs11.createReadStream)(filePath, { start: startOffset, encoding: "utf8" });
141479
141561
  let buffer = "";
141480
141562
  let offset = startOffset;
141481
141563
  let line = startLine;
@@ -141508,7 +141590,7 @@ async function tailReduce(filePath, startOffset, startLine, state, tier) {
141508
141590
  }
141509
141591
  var CHECKPOINT_INTERVAL = 500;
141510
141592
  async function streamMessages(filePath, startOffset, startLine, state, onMessage, onEntry) {
141511
- const stream = (0, import_fs9.createReadStream)(filePath, { start: startOffset, encoding: "utf8" });
141593
+ const stream = (0, import_fs10.createReadStream)(filePath, { start: startOffset, encoding: "utf8" });
141512
141594
  let buffer = "";
141513
141595
  let offset = startOffset;
141514
141596
  let line = startLine;
@@ -141618,7 +141700,7 @@ function assemble(filePath, account, messages, fullText, turnDurations, state) {
141618
141700
  filePath,
141619
141701
  projectPath: state.cwd,
141620
141702
  projectName: getShortProjectName2(state.cwd),
141621
- sessionId: state.sessionId || (0, import_path10.basename)(filePath, ".jsonl"),
141703
+ sessionId: state.sessionId || (0, import_path11.basename)(filePath, ".jsonl"),
141622
141704
  sessionName: state.sessionName || deriveSessionNameFromFirstMessage(messages.find((m2) => m2.role === "user" && m2.text) ?? null),
141623
141705
  messages,
141624
141706
  fullText,
@@ -141662,30 +141744,30 @@ async function extendConversation(previous, resume, filePath, account) {
141662
141744
  }
141663
141745
  var FP_BYTES = 4096;
141664
141746
  function fingerprint(filePath, size) {
141665
- const hash2 = (0, import_crypto4.createHash)("sha1");
141747
+ const hash2 = (0, import_crypto5.createHash)("sha1");
141666
141748
  hash2.update(String(size));
141667
- const fd = (0, import_fs11.openSync)(filePath, "r");
141749
+ const fd = (0, import_fs12.openSync)(filePath, "r");
141668
141750
  try {
141669
141751
  const head = Buffer.alloc(Math.min(FP_BYTES, size));
141670
141752
  if (head.length > 0) {
141671
- (0, import_fs11.readSync)(fd, head, 0, head.length, 0);
141753
+ (0, import_fs12.readSync)(fd, head, 0, head.length, 0);
141672
141754
  hash2.update(head);
141673
141755
  }
141674
141756
  if (size > FP_BYTES) {
141675
141757
  const tailLen = Math.min(FP_BYTES, size);
141676
141758
  const tail = Buffer.alloc(tailLen);
141677
- (0, import_fs11.readSync)(fd, tail, 0, tailLen, size - tailLen);
141759
+ (0, import_fs12.readSync)(fd, tail, 0, tailLen, size - tailLen);
141678
141760
  hash2.update(tail);
141679
141761
  }
141680
141762
  } finally {
141681
- (0, import_fs11.closeSync)(fd);
141763
+ (0, import_fs12.closeSync)(fd);
141682
141764
  }
141683
141765
  return hash2.digest("hex");
141684
141766
  }
141685
141767
  function classify(filePath, existing) {
141686
141768
  let stat42;
141687
141769
  try {
141688
- const s3 = (0, import_fs11.statSync)(filePath);
141770
+ const s3 = (0, import_fs12.statSync)(filePath);
141689
141771
  stat42 = { size: s3.size, mtimeMs: s3.mtimeMs };
141690
141772
  } catch {
141691
141773
  return { change: "vanished" };
@@ -141715,7 +141797,7 @@ async function parseMetaWithProvider(provider, filePath, account, tier) {
141715
141797
  const log15 = getLogger2();
141716
141798
  const acc = provider.createEmptyAccumulator();
141717
141799
  const rl = (0, import_readline3.createInterface)({
141718
- input: (0, import_fs13.createReadStream)(filePath),
141800
+ input: (0, import_fs14.createReadStream)(filePath),
141719
141801
  crlfDelay: Infinity
141720
141802
  });
141721
141803
  try {
@@ -141938,7 +142020,7 @@ function hasColumn(db, table, column) {
141938
142020
  }
141939
142021
  function openDatabase(dbPath) {
141940
142022
  if (dbPath !== ":memory:") {
141941
- (0, import_fs14.mkdirSync)((0, import_path11.dirname)(dbPath), { recursive: true });
142023
+ (0, import_fs15.mkdirSync)((0, import_path12.dirname)(dbPath), { recursive: true });
141942
142024
  }
141943
142025
  const db = new import_better_sqlite3.default(dbPath);
141944
142026
  db.pragma("journal_mode = WAL");
@@ -142019,10 +142101,10 @@ async function resolveProjectDirs(projectsDir, scannedDirs) {
142019
142101
  return { entries, commitRoot: { mtimeMs: rootStat.mtimeMs } };
142020
142102
  }
142021
142103
  function dirnameOf(filePath) {
142022
- return (0, import_path12.dirname)(filePath);
142104
+ return (0, import_path13.dirname)(filePath);
142023
142105
  }
142024
142106
  function joinPath(dir, name) {
142025
- return (0, import_path12.join)(dir, name);
142107
+ return (0, import_path13.join)(dir, name);
142026
142108
  }
142027
142109
  var CheckpointsRepo = class {
142028
142110
  constructor(db) {
@@ -142120,7 +142202,7 @@ var ConversationFilesRepo = class {
142120
142202
  const info = this.db.prepare(
142121
142203
  `INSERT INTO conversation_files (absolute_path, parent_dir, file_name, account)
142122
142204
  VALUES (?, ?, ?, ?)`
142123
- ).run(canonical, (0, import_path13.dirname)(canonical), (0, import_path13.basename)(canonical), account);
142205
+ ).run(canonical, (0, import_path14.dirname)(canonical), (0, import_path14.basename)(canonical), account);
142124
142206
  return Number(info.lastInsertRowid);
142125
142207
  }
142126
142208
  // Advance the cursor + persisted reducer state after a successful index pass.
@@ -142758,7 +142840,7 @@ var PersistentEngine = class {
142758
142840
  let floor = this.checkpoints.floor(filePath, fromIndex);
142759
142841
  if (floor) {
142760
142842
  try {
142761
- if (floor.byteOffset > (0, import_fs12.statSync)(filePath).size) floor = null;
142843
+ if (floor.byteOffset > (0, import_fs13.statSync)(filePath).size) floor = null;
142762
142844
  } catch {
142763
142845
  }
142764
142846
  }
@@ -142880,7 +142962,7 @@ var IndexQueue = class {
142880
142962
  var BATCH_SIZE2 = 12;
142881
142963
  var DEFAULT_CONFIG_PATH2 = "~/.config/threadbase-scanner";
142882
142964
  function defaultDbPath() {
142883
- return process.env.TB_SCANNER_DB ?? (0, import_path9.join)((0, import_os7.homedir)(), ".config", "threadbase-scanner", "index.db");
142965
+ return process.env.TB_SCANNER_DB ?? (0, import_path10.join)((0, import_os8.homedir)(), ".config", "threadbase-scanner", "index.db");
142884
142966
  }
142885
142967
  var ConversationScanner = class {
142886
142968
  metadataCache = /* @__PURE__ */ new Map();
@@ -143051,7 +143133,7 @@ var ConversationScanner = class {
143051
143133
  const cached4 = statCache.get(filePath);
143052
143134
  if (cached4) {
143053
143135
  try {
143054
- const s3 = (0, import_fs8.statSync)(filePath);
143136
+ const s3 = (0, import_fs9.statSync)(filePath);
143055
143137
  if (s3.mtimeMs === cached4.stat.mtimeMs && s3.size === cached4.stat.size) {
143056
143138
  return cached4.meta;
143057
143139
  }
@@ -143551,13 +143633,13 @@ var ConversationScanner = class {
143551
143633
  if (previous?.provider) return void 0;
143552
143634
  let sample = "";
143553
143635
  try {
143554
- const fd = (0, import_fs8.openSync)(filePath, "r");
143636
+ const fd = (0, import_fs9.openSync)(filePath, "r");
143555
143637
  try {
143556
143638
  const buf = Buffer.alloc(8192);
143557
- const n = (0, import_fs8.readSync)(fd, buf, 0, buf.length, 0);
143639
+ const n = (0, import_fs9.readSync)(fd, buf, 0, buf.length, 0);
143558
143640
  sample = buf.subarray(0, n).toString("utf8");
143559
143641
  } finally {
143560
- (0, import_fs8.closeSync)(fd);
143642
+ (0, import_fs9.closeSync)(fd);
143561
143643
  }
143562
143644
  } catch {
143563
143645
  return void 0;
@@ -143651,15 +143733,15 @@ async function search(query, options, scanner) {
143651
143733
  }
143652
143734
 
143653
143735
  // src/api/handlers/conversations.handlers.ts
143654
- var import_fs19 = require("fs");
143655
- var import_path17 = require("path");
143736
+ var import_fs20 = require("fs");
143737
+ var import_path18 = require("path");
143656
143738
  var import_readline4 = require("readline");
143657
143739
 
143658
143740
  // src/conversation-cache.ts
143659
143741
  var import_better_sqlite32 = __toESM(require("better-sqlite3"), 1);
143660
- var import_fs17 = require("fs");
143742
+ var import_fs18 = require("fs");
143661
143743
  var import_promises11 = require("fs/promises");
143662
- var import_path16 = require("path");
143744
+ var import_path17 = require("path");
143663
143745
  var import_promises12 = require("timers/promises");
143664
143746
  init_query_timing();
143665
143747
  init_sqlite_migrate();
@@ -143667,7 +143749,7 @@ init_logger();
143667
143749
  init_providers();
143668
143750
 
143669
143751
  // src/services/conversations/isAgentConversation.ts
143670
- var import_fs16 = require("fs");
143752
+ var import_fs17 = require("fs");
143671
143753
  var DEFAULT_AGENT_ENTRYPOINTS = /* @__PURE__ */ new Set(["sdk-cli", "claude-vscode"]);
143672
143754
  var CHUNK_BYTES = 64 * 1024;
143673
143755
  var ENTRYPOINT_PROBE = `"entrypoint":`;
@@ -143689,12 +143771,12 @@ function isAgentFile(filePath, entrypoints = DEFAULT_AGENT_ENTRYPOINTS) {
143689
143771
  if (cached4 !== void 0) return cached4;
143690
143772
  let fd;
143691
143773
  try {
143692
- fd = (0, import_fs16.openSync)(filePath, "r");
143774
+ fd = (0, import_fs17.openSync)(filePath, "r");
143693
143775
  } catch {
143694
143776
  return false;
143695
143777
  }
143696
143778
  try {
143697
- const fileSize = (0, import_fs16.statSync)(filePath).size;
143779
+ const fileSize = (0, import_fs17.statSync)(filePath).size;
143698
143780
  if (fileSize === 0) {
143699
143781
  fileDecisionCache.set(key, false);
143700
143782
  return false;
@@ -143705,7 +143787,7 @@ function isAgentFile(filePath, entrypoints = DEFAULT_AGENT_ENTRYPOINTS) {
143705
143787
  let carry = "";
143706
143788
  while (offset < fileSize) {
143707
143789
  const toRead = Math.min(CHUNK_BYTES, fileSize - offset);
143708
- const got = (0, import_fs16.readSync)(fd, buf, 0, toRead, offset);
143790
+ const got = (0, import_fs17.readSync)(fd, buf, 0, toRead, offset);
143709
143791
  if (got <= 0) break;
143710
143792
  const chunk = carry + buf.toString("utf8", 0, got);
143711
143793
  for (const marker of markers) {
@@ -143726,7 +143808,7 @@ function isAgentFile(filePath, entrypoints = DEFAULT_AGENT_ENTRYPOINTS) {
143726
143808
  } catch {
143727
143809
  return false;
143728
143810
  } finally {
143729
- (0, import_fs16.closeSync)(fd);
143811
+ (0, import_fs17.closeSync)(fd);
143730
143812
  }
143731
143813
  }
143732
143814
  function parseAgentEntrypointsEnv(raw2) {
@@ -143736,12 +143818,12 @@ function parseAgentEntrypointsEnv(raw2) {
143736
143818
  }
143737
143819
 
143738
143820
  // src/utils/canonicalizeFilePath.ts
143739
- var import_path15 = require("path");
143821
+ var import_path16 = require("path");
143740
143822
  function canonicalizeFilePath(filePath) {
143741
143823
  return filePath.trim().replace(/\\/g, "/");
143742
143824
  }
143743
143825
  function toNativeFilePath(filePath) {
143744
- return (0, import_path15.normalize)(filePath.trim());
143826
+ return (0, import_path16.normalize)(filePath.trim());
143745
143827
  }
143746
143828
  function canonicalLivePathSet(metas) {
143747
143829
  const live = /* @__PURE__ */ new Set();
@@ -143761,11 +143843,11 @@ function joinStatCacheByNativePath(metas, canonicalStats) {
143761
143843
  }
143762
143844
 
143763
143845
  // src/utils/fileIdentity.ts
143764
- var import_crypto5 = require("crypto");
143846
+ var import_crypto6 = require("crypto");
143765
143847
  function fileIdentity(stat7, headBytes) {
143766
143848
  if (stat7.ino && stat7.ino > 0) return `inode:${stat7.dev}:${stat7.ino}`;
143767
143849
  const head = headBytes ?? Buffer.alloc(0);
143768
- return `fp:${(0, import_crypto5.createHash)("sha1").update(head).digest("hex")}`;
143850
+ return `fp:${(0, import_crypto6.createHash)("sha1").update(head).digest("hex")}`;
143769
143851
  }
143770
143852
  function splitCompleteLines(buf, baseOffset) {
143771
143853
  const spans = [];
@@ -144332,7 +144414,7 @@ var ConversationCache = class _ConversationCache {
144332
144414
  if (!fileState) return null;
144333
144415
  let stat7;
144334
144416
  try {
144335
- stat7 = (0, import_fs17.statSync)(filePath);
144417
+ stat7 = (0, import_fs18.statSync)(filePath);
144336
144418
  } catch {
144337
144419
  return null;
144338
144420
  }
@@ -144353,17 +144435,17 @@ var ConversationCache = class _ConversationCache {
144353
144435
  );
144354
144436
  if (rows.length === 0) return { messages: [], total, fromIndex: from };
144355
144437
  const messages = [];
144356
- const fd = (0, import_fs17.openSync)(filePath, "r");
144438
+ const fd = (0, import_fs18.openSync)(filePath, "r");
144357
144439
  try {
144358
144440
  const state = initialConvState();
144359
144441
  for (const row of rows) {
144360
144442
  const buf = Buffer.alloc(row.byte_length);
144361
- (0, import_fs17.readSync)(fd, buf, 0, row.byte_length, row.byte_offset);
144443
+ (0, import_fs18.readSync)(fd, buf, 0, row.byte_length, row.byte_offset);
144362
144444
  const msg = parseJsonlLine(buf.toString("utf-8"), state);
144363
144445
  if (msg) messages.push(msg);
144364
144446
  }
144365
144447
  } finally {
144366
- (0, import_fs17.closeSync)(fd);
144448
+ (0, import_fs18.closeSync)(fd);
144367
144449
  }
144368
144450
  return { messages, total, fromIndex: from };
144369
144451
  }
@@ -144391,14 +144473,14 @@ var ConversationCache = class _ConversationCache {
144391
144473
  isAgentFileCached(filePath) {
144392
144474
  let s3;
144393
144475
  try {
144394
- s3 = (0, import_fs17.statSync)(filePath);
144476
+ s3 = (0, import_fs18.statSync)(filePath);
144395
144477
  } catch {
144396
144478
  return false;
144397
144479
  }
144398
144480
  return this.classifyAgentFile(filePath, s3.mtimeMs, s3.size);
144399
144481
  }
144400
144482
  static open(dbPath, tailSize = 10, migrationsDir, options) {
144401
- (0, import_fs17.mkdirSync)((0, import_path16.dirname)(dbPath), { recursive: true });
144483
+ (0, import_fs18.mkdirSync)((0, import_path17.dirname)(dbPath), { recursive: true });
144402
144484
  const db = instrumentDatabase(new import_better_sqlite32.default(dbPath));
144403
144485
  db.pragma("journal_mode = WAL");
144404
144486
  db.pragma("foreign_keys = ON");
@@ -144602,7 +144684,7 @@ var ConversationCache = class _ConversationCache {
144602
144684
  let mtimeMs = null;
144603
144685
  let fileSize = null;
144604
144686
  try {
144605
- const s3 = (0, import_fs17.statSync)(m2.filePath);
144687
+ const s3 = (0, import_fs18.statSync)(m2.filePath);
144606
144688
  mtimeMs = s3.mtimeMs;
144607
144689
  fileSize = s3.size;
144608
144690
  } catch {
@@ -144662,8 +144744,8 @@ var ConversationCache = class _ConversationCache {
144662
144744
  let fileSize;
144663
144745
  let fd;
144664
144746
  try {
144665
- fileSize = (0, import_fs17.statSync)(filePath).size;
144666
- fd = (0, import_fs17.openSync)(filePath, "r");
144747
+ fileSize = (0, import_fs18.statSync)(filePath).size;
144748
+ fd = (0, import_fs18.openSync)(filePath, "r");
144667
144749
  } catch {
144668
144750
  return false;
144669
144751
  }
@@ -144676,7 +144758,7 @@ var ConversationCache = class _ConversationCache {
144676
144758
  while (pos > 0 && lines.length < this.tailSize * 4) {
144677
144759
  const toRead = Math.min(CHUNK, pos);
144678
144760
  pos -= toRead;
144679
- (0, import_fs17.readSync)(fd, buf, 0, toRead, pos);
144761
+ (0, import_fs18.readSync)(fd, buf, 0, toRead, pos);
144680
144762
  const chunk = buf.subarray(0, toRead).toString("utf8");
144681
144763
  const combined = chunk + partial2;
144682
144764
  const parts = combined.split("\n");
@@ -144687,7 +144769,7 @@ var ConversationCache = class _ConversationCache {
144687
144769
  }
144688
144770
  if (partial2) lines.push(partial2);
144689
144771
  } finally {
144690
- (0, import_fs17.closeSync)(fd);
144772
+ (0, import_fs18.closeSync)(fd);
144691
144773
  }
144692
144774
  const msgs = [];
144693
144775
  for (let i = 0; i < lines.length && msgs.length < this.tailSize; i++) {
@@ -144900,7 +144982,7 @@ var ConversationCache = class _ConversationCache {
144900
144982
  * `handleGetConversation` can still serve the cached tail even when the
144901
144983
  * JSONL has been deleted.
144902
144984
  */
144903
- pruneGhostFiles(exists = import_fs17.existsSync) {
144985
+ pruneGhostFiles(exists = import_fs18.existsSync) {
144904
144986
  const rows = this.stmts.allFilePaths.all();
144905
144987
  const ghosts = [];
144906
144988
  const prune = this.db.transaction((ids) => {
@@ -144955,7 +145037,7 @@ var ConversationCache = class _ConversationCache {
144955
145037
  * Returns the removed IDs.
144956
145038
  */
144957
145039
  reconcileDeletions(livePaths, opts) {
144958
- const exists = opts?.exists ?? import_fs17.existsSync;
145040
+ const exists = opts?.exists ?? import_fs18.existsSync;
144959
145041
  const rows = this.stmts.allFilePaths.all();
144960
145042
  const removed = [];
144961
145043
  const drop = this.db.transaction((ids) => {
@@ -144990,7 +145072,7 @@ var ConversationCache = class _ConversationCache {
144990
145072
  * reports drift for the CacheIntegrityMonitor to classify. `tailed` flags
144991
145073
  * rows that still have cached history (which pruneGhostFiles would keep).
144992
145074
  */
144993
- listMissingFiles(exists = import_fs17.existsSync) {
145075
+ listMissingFiles(exists = import_fs18.existsSync) {
144994
145076
  const rows = this.stmts.allFilePathsWithTitle.all();
144995
145077
  const missing = [];
144996
145078
  for (const row of rows) {
@@ -145335,11 +145417,11 @@ function createScanProgressThrottle() {
145335
145417
  }
145336
145418
 
145337
145419
  // src/api/handlers/http-helpers.ts
145338
- var import_fs18 = require("fs");
145420
+ var import_fs19 = require("fs");
145339
145421
  init_providers();
145340
145422
  function classifyResumability(cwd) {
145341
145423
  if (!cwd) return { resumable: true };
145342
- if ((0, import_fs18.existsSync)(cwd)) return { resumable: true };
145424
+ if ((0, import_fs19.existsSync)(cwd)) return { resumable: true };
145343
145425
  const ranInWorktree = /\/\.worktrees\//.test(cwd) || /\/\.claude\/worktrees\//.test(cwd);
145344
145426
  return {
145345
145427
  resumable: false,
@@ -145694,15 +145776,15 @@ var ConversationHandlers = class {
145694
145776
  findJsonlPath(uuid3) {
145695
145777
  const filename = `${uuid3}.jsonl`;
145696
145778
  for (const projectsDir of this.scannerManager.projectsDirs()) {
145697
- if (!(0, import_fs19.existsSync)(projectsDir)) continue;
145698
- for (const dir of (0, import_fs19.readdirSync)(projectsDir)) {
145699
- const fp = (0, import_path17.join)(projectsDir, dir, filename);
145700
- if ((0, import_fs19.existsSync)(fp)) return fp;
145701
- const projectDir = (0, import_path17.join)(projectsDir, dir);
145779
+ if (!(0, import_fs20.existsSync)(projectsDir)) continue;
145780
+ for (const dir of (0, import_fs20.readdirSync)(projectsDir)) {
145781
+ const fp = (0, import_path18.join)(projectsDir, dir, filename);
145782
+ if ((0, import_fs20.existsSync)(fp)) return fp;
145783
+ const projectDir = (0, import_path18.join)(projectsDir, dir);
145702
145784
  try {
145703
- for (const sub of (0, import_fs19.readdirSync)(projectDir)) {
145704
- const subagentPath = (0, import_path17.join)(projectDir, sub, "subagents", filename);
145705
- if ((0, import_fs19.existsSync)(subagentPath)) return subagentPath;
145785
+ for (const sub of (0, import_fs20.readdirSync)(projectDir)) {
145786
+ const subagentPath = (0, import_path18.join)(projectDir, sub, "subagents", filename);
145787
+ if ((0, import_fs20.existsSync)(subagentPath)) return subagentPath;
145706
145788
  }
145707
145789
  } catch {
145708
145790
  }
@@ -145712,7 +145794,7 @@ var ConversationHandlers = class {
145712
145794
  }
145713
145795
  async readCwdFromJsonl(filePath) {
145714
145796
  return new Promise((resolve4) => {
145715
- const rl = (0, import_readline4.createInterface)({ input: (0, import_fs19.createReadStream)(filePath), crlfDelay: Infinity });
145797
+ const rl = (0, import_readline4.createInterface)({ input: (0, import_fs20.createReadStream)(filePath), crlfDelay: Infinity });
145716
145798
  let found = false;
145717
145799
  rl.on("line", (line) => {
145718
145800
  if (found) return;
@@ -146175,11 +146257,11 @@ var ConversationHandlers = class {
146175
146257
  };
146176
146258
 
146177
146259
  // src/api/handlers/sessions.handlers.ts
146178
- var import_fs21 = require("fs");
146179
- var import_path21 = require("path");
146260
+ var import_fs22 = require("fs");
146261
+ var import_path22 = require("path");
146180
146262
 
146181
146263
  // node_modules/nanoid/index.js
146182
- var import_crypto6 = __toESM(require("crypto"), 1);
146264
+ var import_crypto7 = __toESM(require("crypto"), 1);
146183
146265
 
146184
146266
  // node_modules/nanoid/url-alphabet/index.js
146185
146267
  var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
@@ -146193,10 +146275,10 @@ var fillPool = (bytes) => {
146193
146275
  try {
146194
146276
  if (!pool || pool.length < bytes) {
146195
146277
  pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
146196
- import_crypto6.default.randomFillSync(pool);
146278
+ import_crypto7.default.randomFillSync(pool);
146197
146279
  poolOffset = 0;
146198
146280
  } else if (poolOffset + bytes > pool.length) {
146199
- import_crypto6.default.randomFillSync(pool);
146281
+ import_crypto7.default.randomFillSync(pool);
146200
146282
  poolOffset = 0;
146201
146283
  }
146202
146284
  } catch (e) {
@@ -146439,7 +146521,7 @@ async function handleStartAgentSession(body, deps) {
146439
146521
 
146440
146522
  // src/browse.ts
146441
146523
  var import_promises13 = require("fs/promises");
146442
- var import_path18 = require("path");
146524
+ var import_path19 = require("path");
146443
146525
  var BrowsePathNotFoundError = class extends Error {
146444
146526
  constructor(message) {
146445
146527
  super(message);
@@ -146447,15 +146529,15 @@ var BrowsePathNotFoundError = class extends Error {
146447
146529
  }
146448
146530
  };
146449
146531
  async function resolveBrowsePath(browseRoot, relativePath) {
146450
- const normalizedRoot = (0, import_path18.resolve)(browseRoot);
146532
+ const normalizedRoot = (0, import_path19.resolve)(browseRoot);
146451
146533
  let sanitized;
146452
146534
  if (process.platform !== "win32" && relativePath.startsWith("/") && relativePath.length > 1 && relativePath.includes("/", 1)) {
146453
146535
  sanitized = relativePath;
146454
146536
  } else {
146455
146537
  sanitized = relativePath.replace(/^[/\\]+/, "");
146456
146538
  }
146457
- const target = sanitized ? (0, import_path18.resolve)(normalizedRoot, sanitized) : normalizedRoot;
146458
- const rootPrefix = normalizedRoot.endsWith(import_path18.sep) ? normalizedRoot : `${normalizedRoot}${import_path18.sep}`;
146539
+ const target = sanitized ? (0, import_path19.resolve)(normalizedRoot, sanitized) : normalizedRoot;
146540
+ const rootPrefix = normalizedRoot.endsWith(import_path19.sep) ? normalizedRoot : `${normalizedRoot}${import_path19.sep}`;
146459
146541
  if (!target.startsWith(rootPrefix) && target !== normalizedRoot) {
146460
146542
  throw new Error("Path outside browse root");
146461
146543
  }
@@ -146481,7 +146563,7 @@ async function createDirectory(parentAbsolutePath, name) {
146481
146563
  if (name.includes("/") || name.includes("\\") || name === ".." || name === ".") {
146482
146564
  throw new Error("Invalid directory name");
146483
146565
  }
146484
- const target = (0, import_path18.join)(parentAbsolutePath, name);
146566
+ const target = (0, import_path19.join)(parentAbsolutePath, name);
146485
146567
  try {
146486
146568
  const s3 = await (0, import_promises13.stat)(target);
146487
146569
  if (s3.isDirectory()) throw new Error("Directory already exists");
@@ -146513,11 +146595,11 @@ async function recordUpload(pool2, instanceId, row) {
146513
146595
 
146514
146596
  // src/process-discovery.ts
146515
146597
  var import_child_process3 = require("child_process");
146516
- var import_os8 = require("os");
146517
- var import_path19 = require("path");
146598
+ var import_os9 = require("os");
146599
+ var import_path20 = require("path");
146518
146600
  init_platform();
146519
146601
  async function discoverClaudeProcesses() {
146520
- if ((0, import_os8.platform)() === "win32") return discoverWindows();
146602
+ if ((0, import_os9.platform)() === "win32") return discoverWindows();
146521
146603
  return discoverUnix();
146522
146604
  }
146523
146605
  var CLAUDE_CLI_SCRIPT = /claude-code[\\/](?:cli|index)\.(?:js|mjs|cjs)$/i;
@@ -146572,7 +146654,7 @@ async function discoverUnix() {
146572
146654
  return {
146573
146655
  pid,
146574
146656
  projectPath: cwd,
146575
- projectName: (0, import_path19.basename)(cwd),
146657
+ projectName: (0, import_path20.basename)(cwd),
146576
146658
  branch: await readGitBranch2(cwd),
146577
146659
  conversationId,
146578
146660
  startedAt
@@ -146596,7 +146678,7 @@ async function discoverWindows() {
146596
146678
  return {
146597
146679
  pid,
146598
146680
  projectPath: info.cwd,
146599
- projectName: (0, import_path19.basename)(info.cwd),
146681
+ projectName: (0, import_path20.basename)(info.cwd),
146600
146682
  branch: await readGitBranch2(info.cwd),
146601
146683
  conversationId: extractResumeId(info.args),
146602
146684
  startedAt: info.startedAt
@@ -146657,7 +146739,7 @@ async function getProcessArgsUnix(pid) {
146657
146739
  async function getProcessArgs(pid) {
146658
146740
  if (!Number.isInteger(pid) || pid < 1) return "";
146659
146741
  try {
146660
- if ((0, import_os8.platform)() === "win32") {
146742
+ if ((0, import_os9.platform)() === "win32") {
146661
146743
  const info = await getProcessInfoWindows(pid);
146662
146744
  return info?.args ?? "";
146663
146745
  }
@@ -146754,7 +146836,7 @@ async function getProcessInfoWindows(pid) {
146754
146836
  const startedAt = /* @__PURE__ */ new Date(`${year}-${month}-${day}T${hour}:${min}:${sec}`);
146755
146837
  if (Number.isNaN(startedAt.getTime())) return null;
146756
146838
  const exePath = parts[3] ?? "";
146757
- const cwd = exePath ? (0, import_path19.dirname)(exePath) : "";
146839
+ const cwd = exePath ? (0, import_path20.dirname)(exePath) : "";
146758
146840
  return { cwd, args, startedAt };
146759
146841
  } catch {
146760
146842
  return null;
@@ -146916,7 +146998,7 @@ async function findRolloutOwner(rolloutPath, options = {}) {
146916
146998
  }
146917
146999
 
146918
147000
  // src/services/sessions/conversationBusy.ts
146919
- var import_fs20 = require("fs");
147001
+ var import_fs21 = require("fs");
146920
147002
 
146921
147003
  // src/utils/canonicalizeProjectPath.ts
146922
147004
  function canonicalizeProjectPath(projectPath) {
@@ -146940,7 +147022,7 @@ function conversationBusy(input) {
146940
147022
  let lastActivityMs = null;
146941
147023
  if (input.jsonlPath) {
146942
147024
  try {
146943
- const mtimeMs = (0, import_fs20.statSync)(input.jsonlPath).mtimeMs;
147025
+ const mtimeMs = (0, import_fs21.statSync)(input.jsonlPath).mtimeMs;
146944
147026
  const age = now - mtimeMs;
146945
147027
  lastActivityMs = Math.max(0, age);
146946
147028
  const isSelfEcho = input.selfPtyEndedAt != null && mtimeMs <= input.selfPtyEndedAt + SELF_ACTIVITY_SKEW_MS;
@@ -147025,10 +147107,10 @@ function readIdempotencyKey(body) {
147025
147107
  }
147026
147108
 
147027
147109
  // src/uploads.ts
147028
- var import_crypto7 = require("crypto");
147110
+ var import_crypto8 = require("crypto");
147029
147111
  var import_promises14 = require("fs/promises");
147030
147112
  var import_heic_convert = __toESM(require_heic_convert(), 1);
147031
- var import_path20 = require("path");
147113
+ var import_path21 = require("path");
147032
147114
  var UPLOAD_DIR_NAME = ".threadbase-uploads";
147033
147115
  var MAX_BYTES = 25 * 1024 * 1024;
147034
147116
  var HEIC_MIMES = /* @__PURE__ */ new Set(["image/heic", "image/heif"]);
@@ -147059,11 +147141,11 @@ async function saveUploadFile(input) {
147059
147141
  mimeType = "image/jpeg";
147060
147142
  originalName = originalName.replace(/\.(heic|heif)$/i, ".jpg");
147061
147143
  }
147062
- const id = `up_${(0, import_crypto7.randomBytes)(8).toString("hex")}`;
147144
+ const id = `up_${(0, import_crypto8.randomBytes)(8).toString("hex")}`;
147063
147145
  const safeName = sanitizeFilename(originalName) || `file${MIME_TO_EXT[mimeType] ?? ""}`;
147064
- const dir = (0, import_path20.join)(input.projectPath, UPLOAD_DIR_NAME, input.sessionId);
147146
+ const dir = (0, import_path21.join)(input.projectPath, UPLOAD_DIR_NAME, input.sessionId);
147065
147147
  await (0, import_promises14.mkdir)(dir, { recursive: true });
147066
- const filePath = (0, import_path20.join)(dir, `${Date.now()}-${id}-${safeName}`);
147148
+ const filePath = (0, import_path21.join)(dir, `${Date.now()}-${id}-${safeName}`);
147067
147149
  await (0, import_promises14.writeFile)(filePath, buffer);
147068
147150
  return {
147069
147151
  id,
@@ -147295,7 +147377,7 @@ var SessionHandlers = class {
147295
147377
  const reconciled = this.deps.withReconciledLifecycle([base])[0];
147296
147378
  const session = {
147297
147379
  ...base,
147298
- ...(0, import_fs21.existsSync)(base.projectPath) ? {} : { failureReason: `Project directory not found: ${base.projectPath}` },
147380
+ ...(0, import_fs22.existsSync)(base.projectPath) ? {} : { failureReason: `Project directory not found: ${base.projectPath}` },
147299
147381
  lifecycle: reconciled.lifecycle,
147300
147382
  lifecycleSource: reconciled.lifecycleSource
147301
147383
  };
@@ -147907,7 +147989,7 @@ var SessionHandlers = class {
147907
147989
  const jsonlCwd = jsonlPath ? await this.deps.readCwdFromJsonl(jsonlPath) : null;
147908
147990
  if (jsonlCwd) {
147909
147991
  projectPath = jsonlCwd;
147910
- projectName = projectName || (0, import_path21.basename)(jsonlCwd);
147992
+ projectName = projectName || (0, import_path22.basename)(jsonlCwd);
147911
147993
  }
147912
147994
  }
147913
147995
  if (!projectPath) {
@@ -147984,7 +148066,7 @@ var SessionHandlers = class {
147984
148066
  sessionStore: this.sessionStore,
147985
148067
  // biome-ignore lint/style/noNonNullAssertion: agentClient is set when agentConfig.enabled is true
147986
148068
  agentClient: this.agentClient,
147987
- conversationsDir: this.cacheDir ? (0, import_path21.join)((0, import_path21.dirname)(this.cacheDir), "conversations") : "",
148069
+ conversationsDir: this.cacheDir ? (0, import_path22.join)((0, import_path22.dirname)(this.cacheDir), "conversations") : "",
147988
148070
  agentConfig: this.agentConfig
147989
148071
  });
147990
148072
  json2(res, result.status, result.body);
@@ -148127,13 +148209,13 @@ function getDbConfig() {
148127
148209
  }
148128
148210
 
148129
148211
  // src/db/migrations.ts
148130
- var import_fs22 = require("fs");
148131
- var import_path22 = require("path");
148212
+ var import_fs23 = require("fs");
148213
+ var import_path23 = require("path");
148132
148214
  var import_url7 = require("url");
148133
148215
  var import_meta3 = {};
148134
148216
  function getMigrationsDir2() {
148135
148217
  if (import_meta3.url) {
148136
- return (0, import_path22.dirname)((0, import_url7.fileURLToPath)(import_meta3.url));
148218
+ return (0, import_path23.dirname)((0, import_url7.fileURLToPath)(import_meta3.url));
148137
148219
  }
148138
148220
  return __dirname;
148139
148221
  }
@@ -148149,11 +148231,11 @@ async function runMigrations2(pool2, migrationsDir) {
148149
148231
  "SELECT name FROM _migrations ORDER BY name"
148150
148232
  );
148151
148233
  const appliedSet = new Set(applied.map((r) => r.name));
148152
- const dir = migrationsDir ?? (0, import_path22.join)(getMigrationsDir2(), "pg-migrations");
148153
- const files = (0, import_fs22.readdirSync)(dir).filter((f2) => f2.endsWith(".sql")).sort();
148234
+ const dir = migrationsDir ?? (0, import_path23.join)(getMigrationsDir2(), "pg-migrations");
148235
+ const files = (0, import_fs23.readdirSync)(dir).filter((f2) => f2.endsWith(".sql")).sort();
148154
148236
  for (const file2 of files) {
148155
148237
  if (appliedSet.has(file2)) continue;
148156
- const sql = (0, import_fs22.readFileSync)((0, import_path22.join)(dir, file2), "utf-8");
148238
+ const sql = (0, import_fs23.readFileSync)((0, import_path23.join)(dir, file2), "utf-8");
148157
148239
  await pool2.query(sql);
148158
148240
  await pool2.query("INSERT INTO _migrations (name) VALUES ($1)", [file2]);
148159
148241
  }
@@ -148436,7 +148518,7 @@ var ManagedSessionsRepository = class {
148436
148518
  };
148437
148519
 
148438
148520
  // src/db/repositories/projects.repository.ts
148439
- var import_crypto8 = require("crypto");
148521
+ var import_crypto9 = require("crypto");
148440
148522
  function rowToProject(row) {
148441
148523
  return {
148442
148524
  id: row.id,
@@ -148521,7 +148603,7 @@ var ProjectsRepository = class {
148521
148603
  });
148522
148604
  return rowToProject(this.getById.get(existing.id));
148523
148605
  }
148524
- const id = (0, import_crypto8.randomUUID)();
148606
+ const id = (0, import_crypto9.randomUUID)();
148525
148607
  this.insert.run({
148526
148608
  id,
148527
148609
  path: path2,
@@ -148560,7 +148642,7 @@ var SessionsRepository = class {
148560
148642
  init_runtime_store();
148561
148643
 
148562
148644
  // src/external-tails.ts
148563
- var import_fs23 = require("fs");
148645
+ var import_fs24 = require("fs");
148564
148646
  init_logger();
148565
148647
  var EXTERNAL_TAIL_RECENCY_MS = RESUME_BUSY_WINDOW_MS;
148566
148648
  var EXTERNAL_TAIL_MAX = 32;
@@ -148594,7 +148676,7 @@ var ExternalTailManager = class {
148594
148676
  if (this.isManagedTailPath(key)) return;
148595
148677
  let mtimeMs;
148596
148678
  try {
148597
- mtimeMs = (0, import_fs23.statSync)(filePath).mtimeMs;
148679
+ mtimeMs = (0, import_fs24.statSync)(filePath).mtimeMs;
148598
148680
  } catch {
148599
148681
  return;
148600
148682
  }
@@ -148736,7 +148818,7 @@ init_live_session_manager();
148736
148818
  init_logger();
148737
148819
 
148738
148820
  // src/pair-store.ts
148739
- var import_crypto11 = require("crypto");
148821
+ var import_crypto12 = require("crypto");
148740
148822
  var DEFAULT_TTL_SECONDS = 180;
148741
148823
  var SWEEP_INTERVAL_MS = 6e4;
148742
148824
  var PairTokenStore = class {
@@ -148751,7 +148833,7 @@ var PairTokenStore = class {
148751
148833
  }
148752
148834
  }
148753
148835
  mint() {
148754
- const token = `pt_${(0, import_crypto11.randomBytes)(16).toString("hex")}`;
148836
+ const token = `pt_${(0, import_crypto12.randomBytes)(16).toString("hex")}`;
148755
148837
  const expiresAt = Date.now() + this.ttlMs;
148756
148838
  this.current = { token, expiresAt, used: false };
148757
148839
  return {
@@ -148829,9 +148911,9 @@ function spawnDetachedHost(socketPath, entryPoint) {
148829
148911
  }
148830
148912
 
148831
148913
  // src/scanner-manager.ts
148832
- var import_fs28 = require("fs");
148833
- var import_os12 = require("os");
148834
- var import_path29 = require("path");
148914
+ var import_fs29 = require("fs");
148915
+ var import_os13 = require("os");
148916
+ var import_path30 = require("path");
148835
148917
  init_logger();
148836
148918
  init_providers();
148837
148919
 
@@ -149152,22 +149234,22 @@ function refreshConversationCache(deps) {
149152
149234
  }
149153
149235
 
149154
149236
  // src/services/conversations/shouldRefreshProjectsFromHdd.ts
149155
- var import_fs27 = require("fs");
149156
- var import_os11 = require("os");
149157
- var import_path28 = require("path");
149158
- var DEFAULT_PROJECTS_DIR = (0, import_path28.join)((0, import_os11.homedir)(), ".claude", "projects");
149237
+ var import_fs28 = require("fs");
149238
+ var import_os12 = require("os");
149239
+ var import_path29 = require("path");
149240
+ var DEFAULT_PROJECTS_DIR = (0, import_path29.join)((0, import_os12.homedir)(), ".claude", "projects");
149159
149241
  function maxProjectsTreeMtimeMs(projectsDir) {
149160
149242
  let maxMs;
149161
149243
  try {
149162
- maxMs = (0, import_fs27.statSync)(projectsDir).mtimeMs;
149244
+ maxMs = (0, import_fs28.statSync)(projectsDir).mtimeMs;
149163
149245
  } catch {
149164
149246
  return null;
149165
149247
  }
149166
149248
  try {
149167
- for (const ent of (0, import_fs27.readdirSync)(projectsDir, { withFileTypes: true })) {
149249
+ for (const ent of (0, import_fs28.readdirSync)(projectsDir, { withFileTypes: true })) {
149168
149250
  if (!ent.isDirectory()) continue;
149169
149251
  try {
149170
- const childMs = (0, import_fs27.statSync)((0, import_path28.join)(projectsDir, ent.name)).mtimeMs;
149252
+ const childMs = (0, import_fs28.statSync)((0, import_path29.join)(projectsDir, ent.name)).mtimeMs;
149171
149253
  if (childMs > maxMs) maxMs = childMs;
149172
149254
  } catch {
149173
149255
  }
@@ -149342,9 +149424,9 @@ var ScannerManager = class {
149342
149424
  projectsDirs() {
149343
149425
  const profiles = this.deps.scanProfiles;
149344
149426
  if (profiles && profiles.length > 0) {
149345
- return profiles.filter((p2) => p2.enabled).map((p2) => (0, import_path29.join)(p2.configDir, "projects"));
149427
+ return profiles.filter((p2) => p2.enabled).map((p2) => (0, import_path30.join)(p2.configDir, "projects"));
149346
149428
  }
149347
- return [(0, import_path29.join)((0, import_os12.homedir)(), ".claude", "projects")];
149429
+ return [(0, import_path30.join)((0, import_os13.homedir)(), ".claude", "projects")];
149348
149430
  }
149349
149431
  // ─── staleness ────────────────────────────────────────────────────
149350
149432
  // Drain the stale set and disarm the flag together. The caller owns the
@@ -149382,7 +149464,7 @@ var ScannerManager = class {
149382
149464
  if (!conv.filePath) return false;
149383
149465
  let mtimeMs = null;
149384
149466
  try {
149385
- mtimeMs = (0, import_fs28.statSync)(conv.filePath).mtimeMs;
149467
+ mtimeMs = (0, import_fs29.statSync)(conv.filePath).mtimeMs;
149386
149468
  } catch {
149387
149469
  return false;
149388
149470
  }
@@ -149621,27 +149703,27 @@ function seal(plaintext, recipientPublicKeyBase64) {
149621
149703
  }
149622
149704
 
149623
149705
  // src/server-wiring.ts
149624
- var import_fs30 = require("fs");
149706
+ var import_fs31 = require("fs");
149625
149707
 
149626
149708
  // src/handlers/handleListProjects.ts
149627
- var import_fs29 = require("fs");
149628
- var import_os13 = require("os");
149629
- var import_path30 = require("path");
149709
+ var import_fs30 = require("fs");
149710
+ var import_os14 = require("os");
149711
+ var import_path31 = require("path");
149630
149712
  var HEAD_BYTES = 64 * 1024;
149631
149713
  var MAX_FILES_PROBED = 3;
149632
149714
  function readRecordedCwd(dir) {
149633
149715
  let files;
149634
149716
  try {
149635
- files = (0, import_fs29.readdirSync)(dir).filter((f2) => f2.endsWith(".jsonl"));
149717
+ files = (0, import_fs30.readdirSync)(dir).filter((f2) => f2.endsWith(".jsonl"));
149636
149718
  } catch {
149637
149719
  return null;
149638
149720
  }
149639
149721
  for (const file2 of files.slice(0, MAX_FILES_PROBED)) {
149640
149722
  let fd;
149641
149723
  try {
149642
- fd = (0, import_fs29.openSync)((0, import_path30.join)(dir, file2), "r");
149724
+ fd = (0, import_fs30.openSync)((0, import_path31.join)(dir, file2), "r");
149643
149725
  const buf = Buffer.alloc(HEAD_BYTES);
149644
- const bytes = (0, import_fs29.readSync)(fd, buf, 0, HEAD_BYTES, 0);
149726
+ const bytes = (0, import_fs30.readSync)(fd, buf, 0, HEAD_BYTES, 0);
149645
149727
  for (const line of buf.subarray(0, bytes).toString("utf8").split("\n")) {
149646
149728
  if (!line.includes('"cwd"')) continue;
149647
149729
  try {
@@ -149652,7 +149734,7 @@ function readRecordedCwd(dir) {
149652
149734
  }
149653
149735
  } catch {
149654
149736
  } finally {
149655
- if (fd !== void 0) (0, import_fs29.closeSync)(fd);
149737
+ if (fd !== void 0) (0, import_fs30.closeSync)(fd);
149656
149738
  }
149657
149739
  }
149658
149740
  return null;
@@ -149663,14 +149745,14 @@ function decodeProjectPath(dirName) {
149663
149745
  function handleListProjects(url2, res) {
149664
149746
  const limit = Math.max(1, parseInt(url2.searchParams.get("limit") ?? "50", 10) || 50);
149665
149747
  const offset = Math.max(0, parseInt(url2.searchParams.get("offset") ?? "0", 10) || 0);
149666
- const projectsDir = (0, import_path30.join)((0, import_os13.homedir)(), ".claude", "projects");
149748
+ const projectsDir = (0, import_path31.join)((0, import_os14.homedir)(), ".claude", "projects");
149667
149749
  let entries;
149668
149750
  try {
149669
- entries = (0, import_fs29.readdirSync)(projectsDir).map((dirName) => {
149670
- const fullPath = (0, import_path30.join)(projectsDir, dirName);
149751
+ entries = (0, import_fs30.readdirSync)(projectsDir).map((dirName) => {
149752
+ const fullPath = (0, import_path31.join)(projectsDir, dirName);
149671
149753
  let mtime = 0;
149672
149754
  try {
149673
- mtime = (0, import_fs29.statSync)(fullPath).mtimeMs;
149755
+ mtime = (0, import_fs30.statSync)(fullPath).mtimeMs;
149674
149756
  } catch {
149675
149757
  }
149676
149758
  return { dirName: String(dirName), mtime };
@@ -149682,7 +149764,7 @@ function handleListProjects(url2, res) {
149682
149764
  }
149683
149765
  const total = entries.length;
149684
149766
  const page = entries.slice(offset, offset + limit).map(({ dirName }) => {
149685
- const path2 = readRecordedCwd((0, import_path30.join)(projectsDir, dirName)) ?? decodeProjectPath(String(dirName));
149767
+ const path2 = readRecordedCwd((0, import_path31.join)(projectsDir, dirName)) ?? decodeProjectPath(String(dirName));
149686
149768
  const name = path2.split(/[\\/]/).filter(Boolean).pop() ?? dirName;
149687
149769
  return { name, path: path2, dirName };
149688
149770
  });
@@ -149706,7 +149788,7 @@ function createConversationWatcherEvents(deps) {
149706
149788
  const seqs = cache.extendMessageIndex(
149707
149789
  filePath,
149708
149790
  spans,
149709
- (0, import_fs30.statSync)(filePath),
149791
+ (0, import_fs31.statSync)(filePath),
149710
149792
  readFrom,
149711
149793
  endOffset
149712
149794
  );
@@ -149753,7 +149835,7 @@ function createConversationWatcherEvents(deps) {
149753
149835
  },
149754
149836
  onConversationChanged: (filePath) => {
149755
149837
  try {
149756
- (0, import_fs30.statSync)(filePath);
149838
+ (0, import_fs31.statSync)(filePath);
149757
149839
  } catch {
149758
149840
  deps.externalTailManager().handleJsonlDeleted(filePath);
149759
149841
  return;
@@ -150082,20 +150164,20 @@ function createApiDeps(deps) {
150082
150164
  }
150083
150165
 
150084
150166
  // src/services/cache-integrity/cacheIntegrityMonitor.ts
150085
- var import_crypto12 = require("crypto");
150086
- var import_fs33 = require("fs");
150167
+ var import_crypto13 = require("crypto");
150168
+ var import_fs34 = require("fs");
150087
150169
 
150088
150170
  // src/services/cache-integrity/alertStore.ts
150089
- var import_fs31 = require("fs");
150090
- var import_os14 = require("os");
150091
- var import_path31 = require("path");
150171
+ var import_fs32 = require("fs");
150172
+ var import_os15 = require("os");
150173
+ var import_path32 = require("path");
150092
150174
  function alertStatePath() {
150093
- const dir = process.env.THREADBASE_CONFIG_DIR ?? (0, import_path31.join)((0, import_os14.homedir)(), ".threadbase");
150094
- return (0, import_path31.join)(dir, "cache-alert.json");
150175
+ const dir = process.env.THREADBASE_CONFIG_DIR ?? (0, import_path32.join)((0, import_os15.homedir)(), ".threadbase");
150176
+ return (0, import_path32.join)(dir, "cache-alert.json");
150095
150177
  }
150096
150178
  function loadAlertState() {
150097
150179
  try {
150098
- const parsed = JSON.parse((0, import_fs31.readFileSync)(alertStatePath(), "utf-8"));
150180
+ const parsed = JSON.parse((0, import_fs32.readFileSync)(alertStatePath(), "utf-8"));
150099
150181
  return parsed && typeof parsed === "object" ? parsed : {};
150100
150182
  } catch {
150101
150183
  return {};
@@ -150103,14 +150185,14 @@ function loadAlertState() {
150103
150185
  }
150104
150186
  function saveAlertState(state) {
150105
150187
  const path2 = alertStatePath();
150106
- (0, import_fs31.mkdirSync)((0, import_path31.dirname)(path2), { recursive: true });
150107
- (0, import_fs31.writeFileSync)(path2, `${JSON.stringify(state, null, 2)}
150188
+ (0, import_fs32.mkdirSync)((0, import_path32.dirname)(path2), { recursive: true });
150189
+ (0, import_fs32.writeFileSync)(path2, `${JSON.stringify(state, null, 2)}
150108
150190
  `);
150109
150191
  }
150110
150192
 
150111
150193
  // src/services/cache-integrity/backup.ts
150112
- var import_fs32 = require("fs");
150113
- var import_path32 = require("path");
150194
+ var import_fs33 = require("fs");
150195
+ var import_path33 = require("path");
150114
150196
  var DEFAULT_RETAIN = 3;
150115
150197
  function retainCount() {
150116
150198
  const parsed = Number.parseInt(process.env.THREADBASE_CACHE_BACKUP_RETAIN ?? "", 10);
@@ -150121,17 +150203,17 @@ function timestamp(d) {
150121
150203
  return `${d.getFullYear()}${p2(d.getMonth() + 1)}${p2(d.getDate())}-${p2(d.getHours())}${p2(d.getMinutes())}${p2(d.getSeconds())}`;
150122
150204
  }
150123
150205
  async function backupCacheDb(db, cacheDir) {
150124
- const backupsDir = (0, import_path32.join)(cacheDir, "backups");
150125
- (0, import_fs32.mkdirSync)(backupsDir, { recursive: true });
150126
- const destPath = (0, import_path32.join)(backupsDir, `cache-${timestamp(/* @__PURE__ */ new Date())}.db`);
150206
+ const backupsDir = (0, import_path33.join)(cacheDir, "backups");
150207
+ (0, import_fs33.mkdirSync)(backupsDir, { recursive: true });
150208
+ const destPath = (0, import_path33.join)(backupsDir, `cache-${timestamp(/* @__PURE__ */ new Date())}.db`);
150127
150209
  await db.backup(destPath);
150128
150210
  const retain = retainCount();
150129
- const backups = (0, import_fs32.readdirSync)(backupsDir).filter((f2) => f2.startsWith("cache-") && f2.endsWith(".db")).map((f2) => {
150130
- const full = (0, import_path32.join)(backupsDir, f2);
150131
- return { full, mtime: (0, import_fs32.statSync)(full).mtimeMs };
150211
+ const backups = (0, import_fs33.readdirSync)(backupsDir).filter((f2) => f2.startsWith("cache-") && f2.endsWith(".db")).map((f2) => {
150212
+ const full = (0, import_path33.join)(backupsDir, f2);
150213
+ return { full, mtime: (0, import_fs33.statSync)(full).mtimeMs };
150132
150214
  }).sort((a, b2) => b2.mtime - a.mtime);
150133
150215
  for (const stale of backups.slice(retain)) {
150134
- if ((0, import_fs32.existsSync)(stale.full)) (0, import_fs32.unlinkSync)(stale.full);
150216
+ if ((0, import_fs33.existsSync)(stale.full)) (0, import_fs33.unlinkSync)(stale.full);
150135
150217
  }
150136
150218
  return destPath;
150137
150219
  }
@@ -150147,7 +150229,7 @@ function envInt(name, fallback) {
150147
150229
  }
150148
150230
  function fingerprintOf(ids) {
150149
150231
  const sorted = [...ids].sort();
150150
- return `sha256:${(0, import_crypto12.createHash)("sha256").update(sorted.join("\n")).digest("hex")}`;
150232
+ return `sha256:${(0, import_crypto13.createHash)("sha256").update(sorted.join("\n")).digest("hex")}`;
150151
150233
  }
150152
150234
  var CacheIntegrityMonitor = class {
150153
150235
  constructor(cache, wsHub, log15, cacheDir, rescan, runDuringReset) {
@@ -150228,7 +150310,7 @@ var CacheIntegrityMonitor = class {
150228
150310
  * the pending record, back up on high severity, and broadcast the alert.
150229
150311
  */
150230
150312
  async runDetection(detectedAt = (/* @__PURE__ */ new Date()).toISOString()) {
150231
- const all = this.cache.listMissingFiles(import_fs33.existsSync);
150313
+ const all = this.cache.listMissingFiles(import_fs34.existsSync);
150232
150314
  const missing = all.filter((m2) => !this.ignoredIds.has(m2.id));
150233
150315
  if (missing.length === 0) {
150234
150316
  if (this._pending) {
@@ -150332,7 +150414,7 @@ var CacheIntegrityMonitor = class {
150332
150414
  case "prune_all": {
150333
150415
  await this.ensureBackup(pending);
150334
150416
  const backupPath = pending.backupPath;
150335
- const stillMissing = pending.missing.filter((m2) => !(0, import_fs33.existsSync)(m2.filePath)).map((m2) => m2.id);
150417
+ const stillMissing = pending.missing.filter((m2) => !(0, import_fs34.existsSync)(m2.filePath)).map((m2) => m2.id);
150336
150418
  const pruned = this.cache.dropRowsById(stillMissing);
150337
150419
  this.applyDeferredUnlinks();
150338
150420
  this.clearPending();
@@ -150393,7 +150475,7 @@ var CacheIntegrityMonitor = class {
150393
150475
  };
150394
150476
 
150395
150477
  // src/services/conversations/conversationWatcher.ts
150396
- var import_fs34 = require("fs");
150478
+ var import_fs35 = require("fs");
150397
150479
  var import_promises15 = require("fs/promises");
150398
150480
  var ConversationWatcher = class {
150399
150481
  files = /* @__PURE__ */ new Map();
@@ -150419,7 +150501,7 @@ var ConversationWatcher = class {
150419
150501
  if (this.files.has(key)) return;
150420
150502
  let offset;
150421
150503
  try {
150422
- offset = (0, import_fs34.statSync)(filePath).size;
150504
+ offset = (0, import_fs35.statSync)(filePath).size;
150423
150505
  } catch {
150424
150506
  offset = 0;
150425
150507
  }
@@ -150577,14 +150659,14 @@ var ConversationWatcher = class {
150577
150659
  };
150578
150660
 
150579
150661
  // src/services/conversations/pruneAgentConversations.ts
150580
- var import_fs35 = require("fs");
150662
+ var import_fs36 = require("fs");
150581
150663
  function pruneAgentConversations(cache) {
150582
150664
  const db = cache.getDatabase();
150583
150665
  const rows = db.prepare("SELECT id, file_path FROM conversation_meta").all();
150584
150666
  let pruned = 0;
150585
150667
  let missing = 0;
150586
150668
  for (const row of rows) {
150587
- if (!(0, import_fs35.existsSync)(row.file_path)) {
150669
+ if (!(0, import_fs36.existsSync)(row.file_path)) {
150588
150670
  missing += 1;
150589
150671
  continue;
150590
150672
  }
@@ -151302,7 +151384,7 @@ function shouldBroadcastQuestion(args) {
151302
151384
  }
151303
151385
 
151304
151386
  // src/session-registry-boot.ts
151305
- var import_fs36 = require("fs");
151387
+ var import_fs37 = require("fs");
151306
151388
 
151307
151389
  // src/lifecycle/process-liveness.ts
151308
151390
  function isPidAlive(pid) {
@@ -151551,7 +151633,7 @@ var SessionRegistryBoot = class {
151551
151633
  const skippedBy = {};
151552
151634
  for (const row of candidates) {
151553
151635
  if (this.sessionStore.getManaged(row.session_id)) continue;
151554
- const skip = rehydrateSkipReason(row, { now, projectExists: import_fs36.existsSync });
151636
+ const skip = rehydrateSkipReason(row, { now, projectExists: import_fs37.existsSync });
151555
151637
  if (skip) {
151556
151638
  skippedBy[skip] = (skippedBy[skip] ?? 0) + 1;
151557
151639
  this.log.info(`[rehydrate] skipped ${row.session_id}: ${skip}`, {
@@ -151593,7 +151675,7 @@ var SessionRegistryBoot = class {
151593
151675
  async autoResumePreviousSessions(rows) {
151594
151676
  if (!this.autoResumeOnBoot) return;
151595
151677
  const now = Date.now();
151596
- const baseOptions = { now, projectExists: import_fs36.existsSync, historyExists: () => true };
151678
+ const baseOptions = { now, projectExists: import_fs37.existsSync, historyExists: () => true };
151597
151679
  const historyExists = /* @__PURE__ */ new Map();
151598
151680
  const preflights = /* @__PURE__ */ new Set();
151599
151681
  for (const row of rows) {
@@ -152138,9 +152220,9 @@ function discoveredToResponse(d, conversationId) {
152138
152220
  }
152139
152221
 
152140
152222
  // src/session-watchers.ts
152141
- var import_fs37 = require("fs");
152142
- var import_os15 = require("os");
152143
- var import_path33 = require("path");
152223
+ var import_fs38 = require("fs");
152224
+ var import_os16 = require("os");
152225
+ var import_path34 = require("path");
152144
152226
  init_logger();
152145
152227
  var SessionWatchers = class {
152146
152228
  constructor(deps) {
@@ -152207,7 +152289,7 @@ var SessionWatchers = class {
152207
152289
  // file isn't slurped in full.
152208
152290
  readFirstLineSessionId(filePath) {
152209
152291
  try {
152210
- const content = (0, import_fs37.readFileSync)(filePath, "utf8");
152292
+ const content = (0, import_fs38.readFileSync)(filePath, "utf8");
152211
152293
  const nl = content.indexOf("\n");
152212
152294
  const firstLine = nl === -1 ? content : content.slice(0, nl);
152213
152295
  if (!firstLine.trim()) return null;
@@ -152222,9 +152304,9 @@ var SessionWatchers = class {
152222
152304
  // was passed to Claude via --session-id so the filename matches from the start.
152223
152305
  watchForJsonl(sessionId, projectPath) {
152224
152306
  const encoded = projectPath.replace(/[/\\:.]/g, "-");
152225
- const projectsDir = (0, import_path33.join)((0, import_os15.homedir)(), ".claude", "projects", encoded);
152307
+ const projectsDir = (0, import_path34.join)((0, import_os16.homedir)(), ".claude", "projects", encoded);
152226
152308
  const expectedFile = `${sessionId}.jsonl`;
152227
- const filePath = (0, import_path33.join)(projectsDir, expectedFile);
152309
+ const filePath = (0, import_path34.join)(projectsDir, expectedFile);
152228
152310
  const deadline = Date.now() + 12e4;
152229
152311
  let watcher = null;
152230
152312
  const cleanup = () => {
@@ -152242,14 +152324,14 @@ var SessionWatchers = class {
152242
152324
  cleanup();
152243
152325
  return;
152244
152326
  }
152245
- let resolvedFilePath = (0, import_fs37.existsSync)(filePath) ? filePath : null;
152246
- if (!resolvedFilePath && (0, import_fs37.existsSync)(projectsDir)) {
152327
+ let resolvedFilePath = (0, import_fs38.existsSync)(filePath) ? filePath : null;
152328
+ if (!resolvedFilePath && (0, import_fs38.existsSync)(projectsDir)) {
152247
152329
  try {
152248
152330
  const now = Date.now();
152249
- const match2 = (0, import_fs37.readdirSync)(projectsDir).filter((f2) => f2.endsWith(".jsonl")).map((f2) => ({ f: f2, mtime: (0, import_fs37.statSync)((0, import_path33.join)(projectsDir, f2)).mtimeMs })).filter(({ mtime }) => now - mtime < 5e3).filter(
152250
- ({ f: f2 }) => (0, import_path33.basename)(f2, ".jsonl") === sessionId || this.readFirstLineSessionId((0, import_path33.join)(projectsDir, f2)) === sessionId
152331
+ const match2 = (0, import_fs38.readdirSync)(projectsDir).filter((f2) => f2.endsWith(".jsonl")).map((f2) => ({ f: f2, mtime: (0, import_fs38.statSync)((0, import_path34.join)(projectsDir, f2)).mtimeMs })).filter(({ mtime }) => now - mtime < 5e3).filter(
152332
+ ({ f: f2 }) => (0, import_path34.basename)(f2, ".jsonl") === sessionId || this.readFirstLineSessionId((0, import_path34.join)(projectsDir, f2)) === sessionId
152251
152333
  ).sort((a, b2) => b2.mtime - a.mtime)[0];
152252
- if (match2) resolvedFilePath = (0, import_path33.join)(projectsDir, match2.f);
152334
+ if (match2) resolvedFilePath = (0, import_path34.join)(projectsDir, match2.f);
152253
152335
  } catch {
152254
152336
  }
152255
152337
  }
@@ -152257,7 +152339,7 @@ var SessionWatchers = class {
152257
152339
  cleanup();
152258
152340
  this.deps.sessionFileMap.set(sessionId, resolvedFilePath);
152259
152341
  try {
152260
- const existing = (0, import_fs37.readFileSync)(resolvedFilePath, "utf8").split("\n").filter(Boolean);
152342
+ const existing = (0, import_fs38.readFileSync)(resolvedFilePath, "utf8").split("\n").filter(Boolean);
152261
152343
  if (existing.length > 0) {
152262
152344
  this.deps.broadcastConversationLines(sessionId, existing);
152263
152345
  }
@@ -152277,7 +152359,7 @@ var SessionWatchers = class {
152277
152359
  if (this.deps.sessionFileMap.has(sessionId)) return;
152278
152360
  try {
152279
152361
  require("fs").mkdirSync(projectsDir, { recursive: true });
152280
- watcher = (0, import_fs37.watch)(projectsDir, tryWire);
152362
+ watcher = (0, import_fs38.watch)(projectsDir, tryWire);
152281
152363
  watcher.on("error", cleanup);
152282
152364
  } catch {
152283
152365
  }
@@ -152293,7 +152375,7 @@ var SessionWatchers = class {
152293
152375
  watchForCodexRollout(sessionId, projectPath) {
152294
152376
  const deadline = Date.now() + 12e4;
152295
152377
  const now = /* @__PURE__ */ new Date();
152296
- const dateDir = (0, import_path33.join)(
152378
+ const dateDir = (0, import_path34.join)(
152297
152379
  String(now.getFullYear()),
152298
152380
  String(now.getMonth() + 1).padStart(2, "0"),
152299
152381
  String(now.getDate()).padStart(2, "0")
@@ -152306,7 +152388,7 @@ var SessionWatchers = class {
152306
152388
  };
152307
152389
  const matchesProjectPath = (candidatePath) => {
152308
152390
  try {
152309
- const firstLine = (0, import_fs37.readFileSync)(candidatePath, "utf8").split("\n", 1)[0];
152391
+ const firstLine = (0, import_fs38.readFileSync)(candidatePath, "utf8").split("\n", 1)[0];
152310
152392
  if (!firstLine) return null;
152311
152393
  const parsed = JSON.parse(firstLine);
152312
152394
  if (parsed?.type !== "session_meta") return null;
@@ -152334,18 +152416,18 @@ var SessionWatchers = class {
152334
152416
  this.deps.sessionStore.listManaged().filter((s3) => s3.id !== sessionId && s3.boundConversationId != null).map((s3) => s3.boundConversationId)
152335
152417
  );
152336
152418
  for (const root of this.deps.codexRoots) {
152337
- const sessionsDir = (0, import_path33.join)(root, dateDir);
152338
- if (!(0, import_fs37.existsSync)(sessionsDir)) continue;
152419
+ const sessionsDir = (0, import_path34.join)(root, dateDir);
152420
+ if (!(0, import_fs38.existsSync)(sessionsDir)) continue;
152339
152421
  let candidateFiles;
152340
152422
  try {
152341
- candidateFiles = (0, import_fs37.readdirSync)(sessionsDir).filter((f2) => f2.endsWith(".jsonl"));
152423
+ candidateFiles = (0, import_fs38.readdirSync)(sessionsDir).filter((f2) => f2.endsWith(".jsonl"));
152342
152424
  } catch {
152343
152425
  continue;
152344
152426
  }
152345
152427
  const nowMs = Date.now();
152346
- const recentCandidates = candidateFiles.map((f2) => ({ f: f2, mtime: (0, import_fs37.statSync)((0, import_path33.join)(sessionsDir, f2)).mtimeMs })).filter(({ mtime }) => nowMs - mtime < 1e4).sort((a, b2) => b2.mtime - a.mtime);
152428
+ const recentCandidates = candidateFiles.map((f2) => ({ f: f2, mtime: (0, import_fs38.statSync)((0, import_path34.join)(sessionsDir, f2)).mtimeMs })).filter(({ mtime }) => nowMs - mtime < 1e4).sort((a, b2) => b2.mtime - a.mtime);
152347
152429
  for (const { f: f2 } of recentCandidates) {
152348
- const candidatePath = (0, import_path33.join)(sessionsDir, f2);
152430
+ const candidatePath = (0, import_path34.join)(sessionsDir, f2);
152349
152431
  const match2 = matchesProjectPath(candidatePath);
152350
152432
  if (!match2) continue;
152351
152433
  if (boundElsewhere.has(match2.id)) continue;
@@ -152366,7 +152448,7 @@ var SessionWatchers = class {
152366
152448
  this.deps.sessionFileMap.set(sessionId, candidatePath);
152367
152449
  this.deps.fileWatcher.watch(candidatePath);
152368
152450
  try {
152369
- const existing = (0, import_fs37.readFileSync)(candidatePath, "utf8").split("\n").filter(Boolean);
152451
+ const existing = (0, import_fs38.readFileSync)(candidatePath, "utf8").split("\n").filter(Boolean);
152370
152452
  if (existing.length > 0) {
152371
152453
  this.deps.broadcastConversationLines(sessionId, existing);
152372
152454
  }
@@ -152697,7 +152779,7 @@ var StreamerServer = class {
152697
152779
  runtimeStore = null;
152698
152780
  // Identifies this streamer run. A registry row carrying a different id is a
152699
152781
  // session that outlived the process that started it.
152700
- streamerInstanceId = (0, import_crypto13.randomUUID)();
152782
+ streamerInstanceId = (0, import_crypto14.randomUUID)();
152701
152783
  cacheMetadataRepo = null;
152702
152784
  // Push registration + delivery state (C7). Null when the cache DB failed to
152703
152785
  // open — registration then degrades to a no-op rather than 500ing.
@@ -152749,7 +152831,7 @@ var StreamerServer = class {
152749
152831
  this.skipStartupWarmup = config2.skipStartupWarmup ?? false;
152750
152832
  this.autoResumeOnBoot = config2.autoResumeOnBoot ?? false;
152751
152833
  this.scanProfiles = config2.scanProfiles;
152752
- this.codexRoots = config2.codexRoots ?? [(0, import_path34.join)((0, import_os16.homedir)(), ".codex", "sessions")];
152834
+ this.codexRoots = config2.codexRoots ?? [(0, import_path35.join)((0, import_os17.homedir)(), ".codex", "sessions")];
152753
152835
  this.ptyGracePeriodMs = config2.ptyGracePeriodMs ?? DEFAULT_PTY_GRACE_PERIOD_MS;
152754
152836
  this.defaultSystemPrompt = config2.defaultSystemPrompt ?? DEFAULT_SYSTEM_PROMPT;
152755
152837
  const flagResolution = resolveFeatureFlags({
@@ -152766,7 +152848,7 @@ var StreamerServer = class {
152766
152848
  this.claudeFlagsPersistable = config2.claudeFlags === void 0;
152767
152849
  this.claudeFlags = config2.claudeFlags ?? loadClaudeFlags();
152768
152850
  this.claudeExtraArgs = config2.claudeExtraArgs ?? loadClaudeExtraArgs();
152769
- this.cacheDir = config2.cacheDir ?? loadCacheDir() ?? (0, import_path34.join)((0, import_os16.homedir)(), ".threadbase", "cache");
152851
+ this.cacheDir = config2.cacheDir ?? loadCacheDir() ?? (0, import_path35.join)((0, import_os17.homedir)(), ".threadbase", "cache");
152770
152852
  this.runtimeDbPath = resolveRuntimeDbPath(config2.runtimeDbPath);
152771
152853
  this.tailSize = config2.tailSize ?? loadTailSize() ?? 10;
152772
152854
  this.directoryDebounceMs = parseDirScanDebounceEnv(process.env.THREADBASE_DIR_SCAN_DEBOUNCE_MS) ?? config2.directoryScanDebounceMs ?? 1e3;
@@ -152943,7 +153025,7 @@ var StreamerServer = class {
152943
153025
  temporalClient,
152944
153026
  taskQueue: agentConfig.temporal.taskQueue
152945
153027
  });
152946
- const conversationsBaseDir = agentConfig.conversationsDir || (0, import_path34.join)((0, import_path34.dirname)(this.cacheDir), "conversations");
153028
+ const conversationsBaseDir = agentConfig.conversationsDir || (0, import_path35.join)((0, import_path35.dirname)(this.cacheDir), "conversations");
152947
153029
  conversationWriter = createConversationWriter({
152948
153030
  baseDir: conversationsBaseDir
152949
153031
  });
@@ -153195,14 +153277,14 @@ var StreamerServer = class {
153195
153277
  }
153196
153278
  this.apnsClient = new ApnsClient(creds);
153197
153279
  const sender = new LiveActivitySender(this.apnsClient, pushRepo);
153198
- const serverId = process.env.THREADBASE_INSTANCE_ID ?? (0, import_os16.hostname)();
153199
- this.liveActivityNotifier = new LiveActivityNotifier(sender, serverId, (0, import_os16.hostname)());
153280
+ const serverId = process.env.THREADBASE_INSTANCE_ID ?? (0, import_os17.hostname)();
153281
+ this.liveActivityNotifier = new LiveActivityNotifier(sender, serverId, (0, import_os17.hostname)());
153200
153282
  this.liveActivityRenewal = new LiveActivityRenewalScheduler({
153201
153283
  repo: pushRepo,
153202
153284
  sender,
153203
153285
  sessionStore: this.sessionStore,
153204
153286
  serverId,
153205
- serverLabel: (0, import_os16.hostname)()
153287
+ serverLabel: (0, import_os17.hostname)()
153206
153288
  });
153207
153289
  this.liveActivityRenewal.start();
153208
153290
  this.log.info("Live Activity push enabled", {
@@ -153222,7 +153304,7 @@ var StreamerServer = class {
153222
153304
  */
153223
153305
  initWaitingInputPush(pushRepo) {
153224
153306
  const sender = new ExpoPushSender(pushRepo, process.env.THREADBASE_EXPO_ACCESS_TOKEN);
153225
- const serverId = process.env.THREADBASE_INSTANCE_ID ?? (0, import_os16.hostname)();
153307
+ const serverId = process.env.THREADBASE_INSTANCE_ID ?? (0, import_os17.hostname)();
153226
153308
  this.waitingInputNotifier = new WaitingInputNotifier(
153227
153309
  sender,
153228
153310
  serverId,
@@ -153359,7 +153441,7 @@ var StreamerServer = class {
153359
153441
  let sessions = null;
153360
153442
  for (let attempt = 0; attempt < 2; attempt += 1) {
153361
153443
  const transport = await connectOrSpawnHost({
153362
- instanceId: process.env.THREADBASE_INSTANCE_ID ?? (0, import_os16.hostname)()
153444
+ instanceId: process.env.THREADBASE_INSTANCE_ID ?? (0, import_os17.hostname)()
153363
153445
  });
153364
153446
  try {
153365
153447
  sessions = await this.ptyManager.useRemoteRunner(transport);
@@ -153436,7 +153518,7 @@ var StreamerServer = class {
153436
153518
  }
153437
153519
  try {
153438
153520
  this.cache = ConversationCache.open(
153439
- (0, import_path34.join)(this.cacheDir, "cache.db"),
153521
+ (0, import_path35.join)(this.cacheDir, "cache.db"),
153440
153522
  this.tailSize,
153441
153523
  void 0,
153442
153524
  {
@@ -153520,7 +153602,7 @@ var StreamerServer = class {
153520
153602
  this.fileWatcher.watchDirectory(dir);
153521
153603
  }
153522
153604
  for (const dir of this.codexRoots) {
153523
- if (!(0, import_fs38.existsSync)(dir)) continue;
153605
+ if (!(0, import_fs39.existsSync)(dir)) continue;
153524
153606
  this.fileWatcher.watchDirectory(dir);
153525
153607
  }
153526
153608
  } catch (err) {
@@ -153824,7 +153906,7 @@ var StreamerServer = class {
153824
153906
  nonce: sealed.nonce,
153825
153907
  ephemeralPublicKey: sealed.ephemeralPublicKey,
153826
153908
  publicUrl: this.publicUrl,
153827
- machineName: (0, import_os16.hostname)(),
153909
+ machineName: (0, import_os17.hostname)(),
153828
153910
  ...device && {
153829
153911
  deviceId: device.deviceId,
153830
153912
  deviceToken: device.deviceToken,
@@ -154033,7 +154115,7 @@ var StreamerServer = class {
154033
154115
  }
154034
154116
  const cachedConvMeta = this.cache?.getMetaById(historyId);
154035
154117
  const cachedPath = cachedConvMeta?.filePath ? toNativeFilePath(cachedConvMeta.filePath) : null;
154036
- const cachedCodexPath = (registryProvider === CODEX_CLI_PROVIDER || cachedConvMeta?.provider === CODEX_CLI_PROVIDER) && cachedPath != null && (0, import_fs38.existsSync)(cachedPath) ? cachedPath : null;
154118
+ const cachedCodexPath = (registryProvider === CODEX_CLI_PROVIDER || cachedConvMeta?.provider === CODEX_CLI_PROVIDER) && cachedPath != null && (0, import_fs39.existsSync)(cachedPath) ? cachedPath : null;
154037
154119
  const jsonlCwd = jsonlPath ? await this.conversationHandlers.readCwdFromJsonl(jsonlPath) : null;
154038
154120
  const projectPath = jsonlCwd ?? conv?.projectPath ?? (cachedCodexPath ? cachedConvMeta?.projectPath : null);
154039
154121
  if (!projectPath) {
@@ -154885,13 +154967,13 @@ var import_node_fs19 = require("fs");
154885
154967
 
154886
154968
  // node_modules/tar/dist/esm/index.min.js
154887
154969
  var import_events3 = __toESM(require("events"), 1);
154888
- var import_fs39 = __toESM(require("fs"), 1);
154970
+ var import_fs40 = __toESM(require("fs"), 1);
154889
154971
  var import_node_events3 = require("events");
154890
154972
  var import_node_stream2 = __toESM(require("stream"), 1);
154891
154973
  var import_node_string_decoder = require("string_decoder");
154892
154974
  var import_node_path15 = __toESM(require("path"), 1);
154893
154975
  var import_node_fs13 = __toESM(require("fs"), 1);
154894
- var import_path35 = require("path");
154976
+ var import_path36 = require("path");
154895
154977
  var import_events4 = require("events");
154896
154978
  var import_assert = __toESM(require("assert"), 1);
154897
154979
  var import_buffer2 = require("buffer");
@@ -154899,17 +154981,17 @@ var Ps = __toESM(require("zlib"), 1);
154899
154981
  var import_zlib = __toESM(require("zlib"), 1);
154900
154982
  var import_node_path16 = require("path");
154901
154983
  var import_node_path17 = require("path");
154902
- var import_fs40 = __toESM(require("fs"), 1);
154903
154984
  var import_fs41 = __toESM(require("fs"), 1);
154904
- var import_path36 = __toESM(require("path"), 1);
154905
- var import_node_path18 = require("path");
154985
+ var import_fs42 = __toESM(require("fs"), 1);
154906
154986
  var import_path37 = __toESM(require("path"), 1);
154987
+ var import_node_path18 = require("path");
154988
+ var import_path38 = __toESM(require("path"), 1);
154907
154989
  var import_node_fs14 = __toESM(require("fs"), 1);
154908
154990
  var import_node_assert = __toESM(require("assert"), 1);
154909
154991
  var import_node_crypto6 = require("crypto");
154910
154992
  var import_node_fs15 = __toESM(require("fs"), 1);
154911
154993
  var import_node_path19 = __toESM(require("path"), 1);
154912
- var import_fs42 = __toESM(require("fs"), 1);
154994
+ var import_fs43 = __toESM(require("fs"), 1);
154913
154995
  var import_node_fs16 = __toESM(require("fs"), 1);
154914
154996
  var import_node_path20 = __toESM(require("path"), 1);
154915
154997
  var import_node_fs17 = __toESM(require("fs"), 1);
@@ -155261,7 +155343,7 @@ var A = class extends import_node_events3.EventEmitter {
155261
155343
  return Wr;
155262
155344
  }
155263
155345
  };
155264
- var Jr = import_fs39.default.writev;
155346
+ var Jr = import_fs40.default.writev;
155265
155347
  var ht = /* @__PURE__ */ Symbol("_autoClose");
155266
155348
  var H2 = /* @__PURE__ */ Symbol("_close");
155267
155349
  var te = /* @__PURE__ */ Symbol("_ended");
@@ -155316,7 +155398,7 @@ var _t = class extends A {
155316
155398
  throw new TypeError("this is a readable stream");
155317
155399
  }
155318
155400
  [at]() {
155319
- import_fs39.default.open(this[U], "r", (t, e) => this[Ht](t, e));
155401
+ import_fs40.default.open(this[U], "r", (t, e) => this[Ht](t, e));
155320
155402
  }
155321
155403
  [Ht](t, e) {
155322
155404
  t ? this[Ut](t) : (this[m] = e, this.emit("open", e), this[zt]());
@@ -155329,7 +155411,7 @@ var _t = class extends A {
155329
155411
  this[j] = true;
155330
155412
  let t = this[vi]();
155331
155413
  if (t.length === 0) return process.nextTick(() => this[Ii](null, 0, t));
155332
- import_fs39.default.read(this[m], t, 0, t.length, null, (e, i, r) => this[Ii](e, i, r));
155414
+ import_fs40.default.read(this[m], t, 0, t.length, null, (e, i, r) => this[Ii](e, i, r));
155333
155415
  }
155334
155416
  }
155335
155417
  [Ii](t, e, i) {
@@ -155338,7 +155420,7 @@ var _t = class extends A {
155338
155420
  [H2]() {
155339
155421
  if (this[ht] && typeof this[m] == "number") {
155340
155422
  let t = this[m];
155341
- this[m] = void 0, import_fs39.default.close(t, (e) => e ? this.emit("error", e) : this.emit("close"));
155423
+ this[m] = void 0, import_fs40.default.close(t, (e) => e ? this.emit("error", e) : this.emit("close"));
155342
155424
  }
155343
155425
  }
155344
155426
  [Ut](t) {
@@ -155366,7 +155448,7 @@ var Be = class extends _t {
155366
155448
  [at]() {
155367
155449
  let t = true;
155368
155450
  try {
155369
- this[Ht](null, import_fs39.default.openSync(this[U], "r")), t = false;
155451
+ this[Ht](null, import_fs40.default.openSync(this[U], "r")), t = false;
155370
155452
  } finally {
155371
155453
  t && this[H2]();
155372
155454
  }
@@ -155377,7 +155459,7 @@ var Be = class extends _t {
155377
155459
  if (!this[j]) {
155378
155460
  this[j] = true;
155379
155461
  do {
155380
- let e = this[vi](), i = e.length === 0 ? 0 : import_fs39.default.readSync(this[m], e, 0, e.length, null);
155462
+ let e = this[vi](), i = e.length === 0 ? 0 : import_fs40.default.readSync(this[m], e, 0, e.length, null);
155381
155463
  if (!this[ki](i, e)) break;
155382
155464
  } while (true);
155383
155465
  this[j] = false;
@@ -155390,7 +155472,7 @@ var Be = class extends _t {
155390
155472
  [H2]() {
155391
155473
  if (this[ht] && typeof this[m] == "number") {
155392
155474
  let t = this[m];
155393
- this[m] = void 0, import_fs39.default.closeSync(t), this.emit("close");
155475
+ this[m] = void 0, import_fs40.default.closeSync(t), this.emit("close");
155394
155476
  }
155395
155477
  }
155396
155478
  };
@@ -155432,7 +155514,7 @@ var et = class extends import_events3.default {
155432
155514
  this[H2](), this[gt] = true, this.emit("error", t);
155433
155515
  }
155434
155516
  [at]() {
155435
- import_fs39.default.open(this[U], this[tt], this[ie], (t, e) => this[Ht](t, e));
155517
+ import_fs40.default.open(this[U], this[tt], this[ie], (t, e) => this[Ht](t, e));
155436
155518
  }
155437
155519
  [Ht](t, e) {
155438
155520
  this[Me] && this[tt] === "r+" && t && t.code === "ENOENT" ? (this[tt] = "w", this[at]()) : t ? this[Ut](t) : (this[m] = e, this.emit("open", e), this[gt] || this[Ai]());
@@ -155444,7 +155526,7 @@ var et = class extends import_events3.default {
155444
155526
  return typeof t == "string" && (t = Buffer.from(t, e)), this[te] ? (this.emit("error", new Error("write() after end()")), false) : this[m] === void 0 || this[gt] || this[Y2].length ? (this[Y2].push(t), this[ke] = true, false) : (this[gt] = true, this[ve](t), true);
155445
155527
  }
155446
155528
  [ve](t) {
155447
- import_fs39.default.write(this[m], t, 0, t.length, this[ot], (e, i) => this[Pt](e, i));
155529
+ import_fs40.default.write(this[m], t, 0, t.length, this[ot], (e, i) => this[Pt](e, i));
155448
155530
  }
155449
155531
  [Pt](t, e) {
155450
155532
  t ? this[Ut](t) : (this[ot] !== void 0 && typeof e == "number" && (this[ot] += e), this[Y2].length ? this[Ai]() : (this[gt] = false, this[te] && !this[Ni] ? (this[Ni] = true, this[H2](), this.emit("finish")) : this[ke] && (this[ke] = false, this.emit("drain"))));
@@ -155460,7 +155542,7 @@ var et = class extends import_events3.default {
155460
155542
  [H2]() {
155461
155543
  if (this[ht] && typeof this[m] == "number") {
155462
155544
  let t = this[m];
155463
- this[m] = void 0, import_fs39.default.close(t, (e) => e ? this.emit("error", e) : this.emit("close"));
155545
+ this[m] = void 0, import_fs40.default.close(t, (e) => e ? this.emit("error", e) : this.emit("close"));
155464
155546
  }
155465
155547
  }
155466
155548
  };
@@ -155468,24 +155550,24 @@ var Wt = class extends et {
155468
155550
  [at]() {
155469
155551
  let t;
155470
155552
  if (this[Me] && this[tt] === "r+") try {
155471
- t = import_fs39.default.openSync(this[U], this[tt], this[ie]);
155553
+ t = import_fs40.default.openSync(this[U], this[tt], this[ie]);
155472
155554
  } catch (e) {
155473
155555
  if (e?.code === "ENOENT") return this[tt] = "w", this[at]();
155474
155556
  throw e;
155475
155557
  }
155476
- else t = import_fs39.default.openSync(this[U], this[tt], this[ie]);
155558
+ else t = import_fs40.default.openSync(this[U], this[tt], this[ie]);
155477
155559
  this[Ht](null, t);
155478
155560
  }
155479
155561
  [H2]() {
155480
155562
  if (this[ht] && typeof this[m] == "number") {
155481
155563
  let t = this[m];
155482
- this[m] = void 0, import_fs39.default.closeSync(t), this.emit("close");
155564
+ this[m] = void 0, import_fs40.default.closeSync(t), this.emit("close");
155483
155565
  }
155484
155566
  }
155485
155567
  [ve](t) {
155486
155568
  let e = true;
155487
155569
  try {
155488
- this[Pt](null, import_fs39.default.writeSync(this[m], t, 0, t.length, this[ot])), e = false;
155570
+ this[Pt](null, import_fs40.default.writeSync(this[m], t, 0, t.length, this[ot])), e = false;
155489
155571
  } finally {
155490
155572
  if (e) try {
155491
155573
  this[H2]();
@@ -156275,11 +156357,11 @@ var vn = (s3) => {
156275
156357
  var Qi = (s3, t) => {
156276
156358
  let e = new Map(t.map((o) => [mt(o), true])), i = s3.filter, r = 100, n = (o, h = "", a = 0) => {
156277
156359
  if (a >= r) return e.set(o, false), false;
156278
- let l = h || (0, import_path35.parse)(o).root || ".", c;
156360
+ let l = h || (0, import_path36.parse)(o).root || ".", c;
156279
156361
  if (o === l) c = false;
156280
156362
  else {
156281
156363
  let d = e.get(o);
156282
- c = d !== void 0 ? d : n((0, import_path35.dirname)(o), l, a + 1);
156364
+ c = d !== void 0 ? d : n((0, import_path36.dirname)(o), l, a + 1);
156283
156365
  }
156284
156366
  return e.set(o, c), c;
156285
156367
  };
@@ -156399,7 +156481,7 @@ var de = class extends A {
156399
156481
  let [o, h] = ce(this.path);
156400
156482
  o && typeof h == "string" && (this.path = h, r = o);
156401
156483
  }
156402
- this.win32 = !!i.win32 || process.platform === "win32", this.win32 && (this.path = Qs(this.path.replaceAll(/\\/g, "/")), t = t.replaceAll(/\\/g, "/")), this.absolute = f(i.absolute || import_path36.default.resolve(this.cwd, t)), this.path === "" && (this.path = "./"), r && this.warn("TAR_ENTRY_INFO", `stripping ${r} from absolute path`, { entry: this, path: r + this.path });
156484
+ this.win32 = !!i.win32 || process.platform === "win32", this.win32 && (this.path = Qs(this.path.replaceAll(/\\/g, "/")), t = t.replaceAll(/\\/g, "/")), this.absolute = f(i.absolute || import_path37.default.resolve(this.cwd, t)), this.path === "" && (this.path = "./"), r && this.warn("TAR_ENTRY_INFO", `stripping ${r} from absolute path`, { entry: this, path: r + this.path });
156403
156485
  let n = this.statCache.get(this.absolute);
156404
156486
  n ? this[si](n) : this[ss]();
156405
156487
  }
@@ -156410,7 +156492,7 @@ var de = class extends A {
156410
156492
  return t === "error" && (this.#t = true), super.emit(t, ...e);
156411
156493
  }
156412
156494
  [ss]() {
156413
- import_fs41.default.lstat(this.absolute, (t, e) => {
156495
+ import_fs42.default.lstat(this.absolute, (t, e) => {
156414
156496
  if (t) return this.emit("error", t);
156415
156497
  this[si](e);
156416
156498
  });
@@ -156448,7 +156530,7 @@ var de = class extends A {
156448
156530
  this.path.slice(-1) !== "/" && (this.path += "/"), this.stat.size = 0, this[fe](), this.end();
156449
156531
  }
156450
156532
  [is]() {
156451
- import_fs41.default.readlink(this.absolute, (t, e) => {
156533
+ import_fs42.default.readlink(this.absolute, (t, e) => {
156452
156534
  if (t) return this.emit("error", t);
156453
156535
  this[ns](e);
156454
156536
  });
@@ -156458,7 +156540,7 @@ var de = class extends A {
156458
156540
  }
156459
156541
  [sr](t) {
156460
156542
  if (!this.stat) throw new Error("cannot create link entry without stat");
156461
- this.type = "Link", this.linkpath = f(import_path36.default.relative(this.cwd, t)), this.stat.size = 0, this[fe](), this.end();
156543
+ this.type = "Link", this.linkpath = f(import_path37.default.relative(this.cwd, t)), this.stat.size = 0, this[fe](), this.end();
156462
156544
  }
156463
156545
  [er]() {
156464
156546
  if (!this.stat) throw new Error("cannot create file entry without stat");
@@ -156471,7 +156553,7 @@ var de = class extends A {
156471
156553
  this[os2]();
156472
156554
  }
156473
156555
  [os2]() {
156474
- import_fs41.default.open(this.absolute, "r", (t, e) => {
156556
+ import_fs42.default.open(this.absolute, "r", (t, e) => {
156475
156557
  if (t) return this.emit("error", t);
156476
156558
  this[hs](e);
156477
156559
  });
@@ -156486,14 +156568,14 @@ var de = class extends A {
156486
156568
  [ii]() {
156487
156569
  let { fd: t, buf: e, offset: i, length: r, pos: n } = this;
156488
156570
  if (t === void 0 || e === void 0) throw new Error("cannot read file without first opening");
156489
- import_fs41.default.read(t, e, i, r, n, (o, h) => {
156571
+ import_fs42.default.read(t, e, i, r, n, (o, h) => {
156490
156572
  if (o) return this[pt](() => this.emit("error", o));
156491
156573
  this[rs](h);
156492
156574
  });
156493
156575
  }
156494
156576
  [pt](t = () => {
156495
156577
  }) {
156496
- this.fd !== void 0 && import_fs41.default.close(this.fd, t);
156578
+ this.fd !== void 0 && import_fs42.default.close(this.fd, t);
156497
156579
  }
156498
156580
  [rs](t) {
156499
156581
  if (t <= 0 && this.remain > 0) {
@@ -156528,20 +156610,20 @@ var de = class extends A {
156528
156610
  var ni = class extends de {
156529
156611
  sync = true;
156530
156612
  [ss]() {
156531
- this[si](import_fs41.default.lstatSync(this.absolute));
156613
+ this[si](import_fs42.default.lstatSync(this.absolute));
156532
156614
  }
156533
156615
  [is]() {
156534
- this[ns](import_fs41.default.readlinkSync(this.absolute));
156616
+ this[ns](import_fs42.default.readlinkSync(this.absolute));
156535
156617
  }
156536
156618
  [os2]() {
156537
- this[hs](import_fs41.default.openSync(this.absolute, "r"));
156619
+ this[hs](import_fs42.default.openSync(this.absolute, "r"));
156538
156620
  }
156539
156621
  [ii]() {
156540
156622
  let t = true;
156541
156623
  try {
156542
156624
  let { fd: e, buf: i, offset: r, length: n, pos: o } = this;
156543
156625
  if (e === void 0 || i === void 0) throw new Error("fd and buf must be set in READ method");
156544
- let h = import_fs41.default.readSync(e, i, r, n, o);
156626
+ let h = import_fs42.default.readSync(e, i, r, n, o);
156545
156627
  this[rs](h), t = false;
156546
156628
  } finally {
156547
156629
  if (t) try {
@@ -156556,7 +156638,7 @@ var ni = class extends de {
156556
156638
  }
156557
156639
  [pt](t = () => {
156558
156640
  }) {
156559
- this.fd !== void 0 && import_fs41.default.closeSync(this.fd), t();
156641
+ this.fd !== void 0 && import_fs42.default.closeSync(this.fd), t();
156560
156642
  }
156561
156643
  };
156562
156644
  var oi = class extends A {
@@ -156872,7 +156954,7 @@ var wt = class extends A {
156872
156954
  return typeof t == "string" ? this[ci](t) : this[or](t), this.flowing;
156873
156955
  }
156874
156956
  [or](t) {
156875
- let e = f(import_path37.default.resolve(this.cwd, t.path));
156957
+ let e = f(import_path38.default.resolve(this.cwd, t.path));
156876
156958
  if (!this.filter(t.path, t)) t.resume();
156877
156959
  else {
156878
156960
  let i = new pi(t.path, e);
@@ -156881,13 +156963,13 @@ var wt = class extends A {
156881
156963
  this[Ft]();
156882
156964
  }
156883
156965
  [ci](t) {
156884
- let e = f(import_path37.default.resolve(this.cwd, t));
156966
+ let e = f(import_path38.default.resolve(this.cwd, t));
156885
156967
  this[W2].push(new pi(t, e)), this[Ft]();
156886
156968
  }
156887
156969
  [ds](t) {
156888
156970
  t.pending = true, this[G] += 1;
156889
156971
  let e = this.follow ? "stat" : "lstat";
156890
- import_fs40.default[e](t.absolute, (i, r) => {
156972
+ import_fs41.default[e](t.absolute, (i, r) => {
156891
156973
  t.pending = false, this[G] -= 1, i ? this.emit("error", i) : this[li](t, r);
156892
156974
  });
156893
156975
  }
@@ -156901,7 +156983,7 @@ var wt = class extends A {
156901
156983
  this[Ft]();
156902
156984
  }
156903
156985
  [us](t) {
156904
- t.pending = true, this[G] += 1, import_fs40.default.readdir(t.absolute, (e, i) => {
156986
+ t.pending = true, this[G] += 1, import_fs41.default.readdir(t.absolute, (e, i) => {
156905
156987
  if (t.pending = false, this[G] -= 1, e) return this.emit("error", e);
156906
156988
  this[fi](t, i);
156907
156989
  });
@@ -157002,10 +157084,10 @@ var kt = class extends wt {
157002
157084
  }
157003
157085
  [ds](t) {
157004
157086
  let e = this.follow ? "statSync" : "lstatSync";
157005
- this[li](t, import_fs40.default[e](t.absolute));
157087
+ this[li](t, import_fs41.default[e](t.absolute));
157006
157088
  }
157007
157089
  [us](t) {
157008
- this[fi](t, import_fs40.default.readdirSync(t.absolute));
157090
+ this[fi](t, import_fs41.default.readdirSync(t.absolute));
157009
157091
  }
157010
157092
  [di](t) {
157011
157093
  let e = t.entry, i = this.zip;
@@ -157056,8 +157138,8 @@ var Qn = K(Vn, $n, Xn, qn, (s3, t) => {
157056
157138
  });
157057
157139
  var Jn = process.env.__FAKE_PLATFORM__ || process.platform;
157058
157140
  var Er = Jn === "win32";
157059
- var { O_CREAT: wr, O_NOFOLLOW: ur, O_TRUNC: Sr, O_WRONLY: yr } = import_fs42.default.constants;
157060
- var Rr = Number(process.env.__FAKE_FS_O_FILENAME__) || import_fs42.default.constants.UV_FS_O_FILEMAP || 0;
157141
+ var { O_CREAT: wr, O_NOFOLLOW: ur, O_TRUNC: Sr, O_WRONLY: yr } = import_fs43.default.constants;
157142
+ var Rr = Number(process.env.__FAKE_FS_O_FILENAME__) || import_fs43.default.constants.UV_FS_O_FILEMAP || 0;
157061
157143
  var jn = Er && !!Rr;
157062
157144
  var to = 512 * 1024;
157063
157145
  var eo = Rr | Sr | wr | yr;
@@ -158536,8 +158618,8 @@ program2.command("cache").description("Manage the local SQLite conversation cach
158536
158618
  `${process.env.HOME}/.threadbase/cache`
158537
158619
  ).action((opts) => {
158538
158620
  const { rmSync: rmSync6, existsSync: existsSync21 } = require("fs");
158539
- const { join: join35 } = require("path");
158540
- const dbPath = join35(opts.cacheDir, "cache.db");
158621
+ const { join: join36 } = require("path");
158622
+ const dbPath = join36(opts.cacheDir, "cache.db");
158541
158623
  for (const suffix of ["", "-shm", "-wal"]) {
158542
158624
  const f2 = dbPath + suffix;
158543
158625
  if (existsSync21(f2)) {
@@ -158824,7 +158906,7 @@ async function printServerBanner({
158824
158906
  }
158825
158907
  const { token, expiresAt, expiresInSeconds } = await res.json();
158826
158908
  const expSeconds = Math.floor(expiresAt / 1e3);
158827
- const payload = `threadbase://pair?url=${encodeURIComponent(url2)}&token=${token}&exp=${expSeconds}`;
158909
+ const payload = `threadbase://pair?url=${encodeURIComponent(url2)}&token=${token}&exp=${expSeconds}&spk=${serverIdentityPublicKey()}&v=1`;
158828
158910
  const qr2 = await generateQr(payload);
158829
158911
  log14.info(printUrlBanner({ url: url2, qr: qr2, expiresAt }), void 0, "console");
158830
158912
  log14.info(`Pair URL: ${payload}`, void 0, "console");