flyspace-cli 0.1.57 → 0.1.59

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.js CHANGED
@@ -2,6 +2,7 @@
2
2
  import { createRequire as __flyspaceCreateRequire } from 'node:module';
3
3
  const require = __flyspaceCreateRequire(import.meta.url);
4
4
  import {
5
+ AuthApiError,
5
6
  AutomationManager,
6
7
  BOT_DM_KEY,
7
8
  BOT_LABEL,
@@ -10,6 +11,7 @@ import {
10
11
  BUILT_IN_OUTPUT_STYLES,
11
12
  CLI_VERSION,
12
13
  ChatAgent,
14
+ DEFAULT_API_URL,
13
15
  DEFAULT_TIMEZONE,
14
16
  DocShareSlugTakenError,
15
17
  HANDLE_PATTERN,
@@ -28,9 +30,11 @@ import {
28
30
  UsageStore,
29
31
  acquireHostLock,
30
32
  agentViewer,
33
+ apiUrl,
31
34
  authorFor,
32
35
  blockToFallbackText,
33
36
  bodyTextFor,
37
+ boundWorkspaces,
34
38
  buildAuthorizeUrl,
35
39
  buildAutoTitle,
36
40
  cachedProfileConfig,
@@ -38,6 +42,7 @@ import {
38
42
  channelSkillsDir,
39
43
  claudeAuthFailed,
40
44
  clearClaudeAuthFailed,
45
+ clearLocalAuth,
41
46
  clientKey,
42
47
  codexAuthAvailable,
43
48
  consumeOAuthState,
@@ -57,6 +62,7 @@ import {
57
62
  createStateToken,
58
63
  createTtsRouter,
59
64
  createWorkspace,
65
+ credentialsPath,
60
66
  crossOriginShell,
61
67
  defaultClaudeCwd,
62
68
  defaultEffort,
@@ -72,21 +78,25 @@ import {
72
78
  deleteWorkspaceDomain,
73
79
  deriveConnectionSlug,
74
80
  detectSourceLanguage,
81
+ deviceKeyPath,
75
82
  displayNameFor,
76
83
  dropShareAudio,
77
84
  dropShareLangAudioKeys,
78
85
  effectiveModel,
86
+ ensureDeviceKey,
79
87
  ensureUsersCached,
80
88
  escalateToHuman,
81
89
  exchangeCode,
82
90
  explainCost,
83
91
  extractCategories,
84
92
  extractTitle,
93
+ fetchWhoAmI,
85
94
  filterReadableDocsChannels,
86
95
  findDocShareBySource,
87
96
  findOwningProfile,
88
97
  findSkillDetail,
89
98
  flatDocs,
99
+ getAccessToken,
90
100
  getAgentPaused,
91
101
  getAllowGuestAccess,
92
102
  getChannelDocsMemberAccess,
@@ -111,6 +121,7 @@ import {
111
121
  getWorkspacePlanStatus,
112
122
  handleAttachmentUrlResult,
113
123
  handleHostDbResult,
124
+ handlePluginSvgResult,
114
125
  handleShouldRespondResult,
115
126
  handleSupportMention,
116
127
  highlightLanguageOf,
@@ -156,6 +167,7 @@ import {
156
167
  loadBotIdentity,
157
168
  loadChatAgentConfig,
158
169
  loadConfig,
170
+ loadCredentials,
159
171
  loadDashboardSettings,
160
172
  loadEffectiveAutomations,
161
173
  loadEnvFiles,
@@ -170,6 +182,7 @@ import {
170
182
  mentionedUserIds,
171
183
  onboardingPending,
172
184
  pinnedClaudeConfigDir,
185
+ pollDeviceToken,
173
186
  profileClaudeConfigDir,
174
187
  profileEnv,
175
188
  profileFromHost,
@@ -186,6 +199,7 @@ import {
186
199
  refreshUserCache,
187
200
  removeChannelMember,
188
201
  renderAppIcon,
202
+ requestDeviceCode,
189
203
  requestHostDb,
190
204
  requireDocsAccess,
191
205
  requireSlackBotToken,
@@ -199,15 +213,18 @@ import {
199
213
  resolveRateCard,
200
214
  resolveRawPath,
201
215
  resolveUserId,
216
+ revokeDevice,
202
217
  revokeDocShare,
203
218
  rowToMemory,
204
219
  runAutomation,
220
+ runPersonaCmd,
205
221
  runScriptAutomation,
206
222
  runnerForModel,
207
223
  safeRedirectPath,
208
224
  saveAgentProfile,
209
225
  saveBotIdentity,
210
226
  saveChannelMemory,
227
+ saveCredentials,
211
228
  saveDashboardSettings,
212
229
  saveMemory,
213
230
  saveWorkspaceBranding,
@@ -257,12 +274,13 @@ import {
257
274
  usageLimitedModels,
258
275
  usageLimitedUntil,
259
276
  useDirectSupabase,
277
+ useHostDbWithoutCredentials,
260
278
  useLocalCache,
261
279
  validateMemoryInput,
262
280
  workspaceHostname,
263
281
  workspaceSkillsDir,
264
282
  writeSkillFile
265
- } from "./chunk-3KXMQCGD.js";
283
+ } from "./chunk-7W5FEG63.js";
266
284
  import {
267
285
  canReadThread,
268
286
  firstReplyBody,
@@ -297,7 +315,6 @@ import {
297
315
  getR2Bucket,
298
316
  getR2Client,
299
317
  getSupabaseClient,
300
- hasSupabaseCredentials,
301
318
  isCwdUsable,
302
319
  isEffort,
303
320
  isHumanAuthor,
@@ -444,191 +461,6 @@ async function preflight(opts = {}) {
444
461
  exit(1);
445
462
  }
446
463
 
447
- // src/auth/device-auth.ts
448
- import { createPrivateKey, createPublicKey, generateKeyPairSync, sign } from "crypto";
449
- import { existsSync, mkdirSync as mkdirSync2, readFileSync as readFileSync2, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "fs";
450
- import { dirname as dirname2, join as join2 } from "path";
451
- var DEFAULT_API_URL = "https://app.flyspace.ai";
452
- var EXPIRY_SKEW_MS = 6e4;
453
- var AuthApiError = class extends Error {
454
- constructor(message, status) {
455
- super(message);
456
- this.status = status;
457
- this.name = "AuthApiError";
458
- }
459
- };
460
- function apiUrl() {
461
- return (process.env["FLYSPACE_API_URL"] || DEFAULT_API_URL).replace(/\/+$/, "");
462
- }
463
- function deviceKeyPath() {
464
- return join2(paths.BASE_CONFIG_DIR, "device.key");
465
- }
466
- function credentialsPath() {
467
- return join2(paths.BASE_CONFIG_DIR, "credentials.json");
468
- }
469
- function ensureDeviceKey(path = deviceKeyPath()) {
470
- let created = false;
471
- if (!existsSync(path)) {
472
- const { privateKey: privateKey2 } = generateKeyPairSync("ed25519");
473
- mkdirSync2(dirname2(path), { recursive: true });
474
- writeFileSync2(path, privateKey2.export({ type: "pkcs8", format: "pem" }), { mode: 384 });
475
- created = true;
476
- }
477
- const privateKey = createPrivateKey(readFileSync2(path, "utf8"));
478
- const publicKeyBase64 = createPublicKey(privateKey).export({ type: "spki", format: "der" }).toString(
479
- "base64"
480
- );
481
- return { privateKey, publicKeyBase64, created };
482
- }
483
- function loadCredentials(path = credentialsPath()) {
484
- if (!existsSync(path)) return null;
485
- try {
486
- return JSON.parse(readFileSync2(path, "utf8"));
487
- } catch {
488
- return null;
489
- }
490
- }
491
- function saveCredentials(creds, path = credentialsPath()) {
492
- mkdirSync2(dirname2(path), { recursive: true });
493
- writeFileSync2(path, `${JSON.stringify(creds, null, 2)}
494
- `, { mode: 384 });
495
- }
496
- function clearLocalAuth() {
497
- rmSync2(credentialsPath(), { force: true });
498
- rmSync2(deviceKeyPath(), { force: true });
499
- }
500
- async function post(base, path, body, token) {
501
- return fetch(`${base}${path}`, {
502
- method: "POST",
503
- headers: {
504
- "content-type": "application/json",
505
- ...token ? { authorization: `Bearer ${token}` } : {}
506
- },
507
- body: JSON.stringify(body)
508
- });
509
- }
510
- async function readJson(res) {
511
- try {
512
- return await res.json();
513
- } catch {
514
- return {};
515
- }
516
- }
517
- async function expectOk(res, what) {
518
- const json = await readJson(res);
519
- if (!res.ok) {
520
- const reason = typeof json["error"] === "string" ? json["error"] : res.statusText;
521
- throw new AuthApiError(`${what} failed (${res.status}): ${reason}`, res.status);
522
- }
523
- return json;
524
- }
525
- function toSlugs(value) {
526
- return Array.isArray(value) ? value.filter((v) => typeof v === "string") : [];
527
- }
528
- function toGrant(json) {
529
- const user = json["user"] ?? {};
530
- return {
531
- accessToken: String(json["access_token"]),
532
- expiresIn: Number(json["expires_in"]),
533
- deviceId: String(json["device_id"]),
534
- userEmail: String(user["email"] ?? ""),
535
- workspaces: toSlugs(json["workspaces"])
536
- };
537
- }
538
- async function requestDeviceCode(base, input2) {
539
- const res = await post(base, "/api/auth/device/code", {
540
- public_key: input2.publicKey,
541
- name: input2.name,
542
- platform: input2.platform
543
- });
544
- const json = await expectOk(res, "Requesting a device code");
545
- return {
546
- deviceCode: String(json["device_code"]),
547
- userCode: String(json["user_code"]),
548
- verificationUri: String(json["verification_uri"]),
549
- expiresIn: Number(json["expires_in"]),
550
- interval: Number(json["interval"] ?? 5)
551
- };
552
- }
553
- async function pollDeviceToken(base, deviceCode) {
554
- const res = await post(base, "/api/auth/device/token", { device_code: deviceCode });
555
- const json = await readJson(res);
556
- if (res.ok) return { status: "approved", grant: toGrant(json) };
557
- switch (json["error"]) {
558
- case "authorization_pending":
559
- return { status: "pending" };
560
- case "slow_down":
561
- return { status: "slow_down" };
562
- case "access_denied":
563
- return { status: "denied" };
564
- case "expired_token":
565
- return { status: "expired" };
566
- default:
567
- throw new AuthApiError(`Polling for approval failed (${res.status}): ${String(json["error"] ?? res.statusText)}`, res.status);
568
- }
569
- }
570
- async function refreshAccessToken(creds, privateKey) {
571
- const challenge = await expectOk(
572
- await post(creds.apiUrl, "/api/auth/device/challenge", { device_id: creds.deviceId }),
573
- "Requesting a refresh challenge"
574
- );
575
- const nonce = String(challenge["nonce"]);
576
- const signature = sign(null, Buffer.from(nonce), privateKey).toString("base64");
577
- const json = await expectOk(
578
- await post(creds.apiUrl, "/api/auth/device/refresh", { device_id: creds.deviceId, nonce, signature }),
579
- "Refreshing the access token"
580
- );
581
- return {
582
- ...creds,
583
- accessToken: String(json["access_token"]),
584
- accessTokenExpiresAt: Date.now() + Number(json["expires_in"]) * 1e3
585
- };
586
- }
587
- async function fetchWhoAmI(base, token) {
588
- const res = await fetch(`${base}/api/auth/device/me`, { headers: { authorization: `Bearer ${token}` } });
589
- const json = await expectOk(res, "Checking the session");
590
- const user = json["user"] ?? {};
591
- const device = json["device"] ?? {};
592
- return {
593
- userEmail: String(user["email"] ?? ""),
594
- deviceId: String(device["id"] ?? ""),
595
- deviceName: String(device["name"] ?? ""),
596
- workspaces: toSlugs(json["workspaces"])
597
- };
598
- }
599
- async function boundWorkspaces() {
600
- const creds = loadCredentials();
601
- if (!creds) return null;
602
- try {
603
- const me = await fetchWhoAmI(creds.apiUrl, await getAccessToken());
604
- saveCredentials({ ...loadCredentials() ?? creds, workspaces: me.workspaces });
605
- return { workspaces: me.workspaces, fresh: true };
606
- } catch {
607
- return { workspaces: creds.workspaces ?? [], fresh: false };
608
- }
609
- }
610
- async function revokeDevice(base, token) {
611
- await expectOk(await post(base, "/api/auth/device/revoke", {}, token), "Revoking this device");
612
- }
613
- async function getAccessToken() {
614
- const fromEnv = process.env["FLYSPACE_TOKEN"];
615
- if (fromEnv) return fromEnv;
616
- const creds = loadCredentials();
617
- if (!creds) return null;
618
- if (creds.accessTokenExpiresAt - EXPIRY_SKEW_MS > Date.now()) return creds.accessToken;
619
- const { privateKey } = ensureDeviceKey();
620
- const refreshed = await refreshAccessToken(creds, privateKey);
621
- saveCredentials(refreshed);
622
- return refreshed.accessToken;
623
- }
624
-
625
- // src/commands/supabase-via-host.ts
626
- function useHostDbWithoutCredentials() {
627
- const viaHost = !!loadCredentials() && (!hasSupabaseCredentials() || !!readHostEndpoint());
628
- if (viaHost) setSupabaseClient(createHostDbClient("local-host"));
629
- return viaHost;
630
- }
631
-
632
464
  // src/commands/start.ts
633
465
  async function runStart() {
634
466
  loadEnvFiles();
@@ -638,7 +470,7 @@ async function runStart() {
638
470
  }
639
471
 
640
472
  // src/commands/config.ts
641
- import { existsSync as existsSync2, readFileSync as readFileSync3, writeFileSync as writeFileSync3 } from "fs";
473
+ import { existsSync, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
642
474
  import { spawn } from "child_process";
643
475
  import { resolve } from "path";
644
476
  function maskToken(value) {
@@ -656,12 +488,12 @@ function printConfig() {
656
488
  console.log("\n Paths:");
657
489
  console.log(` Config dir: ${paths.CONFIG_DIR}`);
658
490
  console.log(` Data dir: ${paths.DATA_DIR}`);
659
- console.log(` Config file: ${paths.CONFIG_FILE} ${existsSync2(paths.CONFIG_FILE) ? "(exists)" : "(not found)"}`);
660
- console.log(` Prompt file: ${paths.PROMPT_FILE} ${existsSync2(paths.PROMPT_FILE) ? "(exists)" : "(not found)"}`);
661
- console.log(` Database: ${paths.DB_FILE} ${existsSync2(paths.DB_FILE) ? "(exists)" : "(not found)"}`);
491
+ console.log(` Config file: ${paths.CONFIG_FILE} ${existsSync(paths.CONFIG_FILE) ? "(exists)" : "(not found)"}`);
492
+ console.log(` Prompt file: ${paths.PROMPT_FILE} ${existsSync(paths.PROMPT_FILE) ? "(exists)" : "(not found)"}`);
493
+ console.log(` Database: ${paths.DB_FILE} ${existsSync(paths.DB_FILE) ? "(exists)" : "(not found)"}`);
662
494
  console.log(` Log dir: ${paths.LOG_DIR}`);
663
495
  const repoEnv = resolve(process.cwd(), ".env");
664
- console.log(` Repo .env: ${repoEnv} ${existsSync2(repoEnv) ? "(exists)" : "(not found)"}`);
496
+ console.log(` Repo .env: ${repoEnv} ${existsSync(repoEnv) ? "(exists)" : "(not found)"}`);
665
497
  const envKeys = [
666
498
  "SLACK_BOT_TOKEN",
667
499
  "SLACK_APP_TOKEN",
@@ -685,13 +517,13 @@ function printConfig() {
685
517
  }
686
518
  function editConfig() {
687
519
  ensureDirs();
688
- if (!existsSync2(paths.CONFIG_FILE)) {
520
+ if (!existsSync(paths.CONFIG_FILE)) {
689
521
  const defaultEnv = resolve(paths.PACKAGE_ROOT, ".env.example");
690
- if (existsSync2(defaultEnv)) {
691
- const content = readFileSync3(defaultEnv, "utf-8");
692
- writeFileSync3(paths.CONFIG_FILE, content);
522
+ if (existsSync(defaultEnv)) {
523
+ const content = readFileSync2(defaultEnv, "utf-8");
524
+ writeFileSync2(paths.CONFIG_FILE, content);
693
525
  } else {
694
- writeFileSync3(paths.CONFIG_FILE, "");
526
+ writeFileSync2(paths.CONFIG_FILE, "");
695
527
  }
696
528
  console.log(`[flyspace] Created ${paths.CONFIG_FILE}`);
697
529
  }
@@ -725,14 +557,14 @@ async function runConfig(args) {
725
557
 
726
558
  // src/commands/setup.ts
727
559
  import { execFileSync as execFileSync2, execSync as execSync4 } from "child_process";
728
- import { mkdirSync as mkdirSync5 } from "fs";
729
- import { join as join7 } from "path";
560
+ import { mkdirSync as mkdirSync4 } from "fs";
561
+ import { join as join6 } from "path";
730
562
  import { confirm as confirm2 } from "@inquirer/prompts";
731
563
 
732
564
  // ../api/src/service.ts
733
565
  import { execSync } from "child_process";
734
- import { existsSync as existsSync3, readFileSync as readFileSync4, realpathSync } from "fs";
735
- import { basename, dirname as dirname3, join as join3 } from "path";
566
+ import { existsSync as existsSync2, readFileSync as readFileSync3, realpathSync } from "fs";
567
+ import { basename, dirname as dirname2, join as join2 } from "path";
736
568
  import { homedir, platform } from "os";
737
569
  function flyspaceHome(entry = process.argv[1]) {
738
570
  let cliPath;
@@ -745,8 +577,8 @@ function flyspaceHome(entry = process.argv[1]) {
745
577
  if (at <= 0) return void 0;
746
578
  const npmPrefix = cliPath.slice(0, at);
747
579
  if (basename(npmPrefix) !== "cli") return void 0;
748
- const home2 = dirname3(npmPrefix);
749
- return existsSync3(join3(home2, "bin", "flyspace")) && existsSync3(join3(home2, "node", "bin", "node")) ? home2 : void 0;
580
+ const home2 = dirname2(npmPrefix);
581
+ return existsSync2(join2(home2, "bin", "flyspace")) && existsSync2(join2(home2, "node", "bin", "node")) ? home2 : void 0;
750
582
  }
751
583
  function serviceLabel(profile) {
752
584
  return profile === DEFAULT_PROFILE ? "ai.flyspace" : `ai.flyspace.${profile}`;
@@ -755,33 +587,33 @@ function plistName(profile) {
755
587
  return `${serviceLabel(profile)}.plist`;
756
588
  }
757
589
  function plistPath(profile) {
758
- return join3(homedir(), "Library", "LaunchAgents", plistName(profile));
590
+ return join2(homedir(), "Library", "LaunchAgents", plistName(profile));
759
591
  }
760
592
  function legacyServiceLabel(profile) {
761
593
  return profile === DEFAULT_PROFILE ? "io.flycoder.flyspace" : `io.flycoder.flyspace.${profile}`;
762
594
  }
763
595
  function legacyPlistPath(profile) {
764
- return join3(homedir(), "Library", "LaunchAgents", `${legacyServiceLabel(profile)}.plist`);
596
+ return join2(homedir(), "Library", "LaunchAgents", `${legacyServiceLabel(profile)}.plist`);
765
597
  }
766
598
  function systemdUnitName(profile) {
767
599
  return profile === DEFAULT_PROFILE ? "flyspace" : `flyspace-${profile}`;
768
600
  }
769
601
  function systemdUnitPath(profile) {
770
- return join3(homedir(), ".config", "systemd", "user", `${systemdUnitName(profile)}.service`);
602
+ return join2(homedir(), ".config", "systemd", "user", `${systemdUnitName(profile)}.service`);
771
603
  }
772
604
  function isServiceInstalled(profile) {
773
- if (platform() === "darwin") return existsSync3(plistPath(profile));
774
- if (platform() === "linux") return existsSync3(systemdUnitPath(profile));
605
+ if (platform() === "darwin") return existsSync2(plistPath(profile));
606
+ if (platform() === "linux") return existsSync2(systemdUnitPath(profile));
775
607
  return false;
776
608
  }
777
609
  function serviceBinaryMissing(file) {
778
610
  const bin = serviceBinary(file);
779
- return !!bin && !existsSync3(bin);
611
+ return !!bin && !existsSync2(bin);
780
612
  }
781
613
  function serviceBinary(file) {
782
614
  let text;
783
615
  try {
784
- text = readFileSync4(file, "utf-8");
616
+ text = readFileSync3(file, "utf-8");
785
617
  } catch {
786
618
  return void 0;
787
619
  }
@@ -791,7 +623,7 @@ function profileServiceFile(profile) {
791
623
  return platform() === "darwin" ? plistPath(profile) : systemdUnitPath(profile);
792
624
  }
793
625
  function hostServiceFile() {
794
- return platform() === "darwin" ? hostPlistPath() : join3(homedir(), ".config", "systemd", "user", `${HOST_SYSTEMD_UNIT}.service`);
626
+ return platform() === "darwin" ? hostPlistPath() : join2(homedir(), ".config", "systemd", "user", `${HOST_SYSTEMD_UNIT}.service`);
795
627
  }
796
628
  function restartService(profile) {
797
629
  const os = platform();
@@ -821,10 +653,10 @@ function restartService(profile) {
821
653
  var HOST_SERVICE_LABEL = "ai.flyspace.dashboard";
822
654
  var HOST_SYSTEMD_UNIT = "flyspace-host";
823
655
  function hostPlistPath() {
824
- return join3(homedir(), "Library", "LaunchAgents", `${HOST_SERVICE_LABEL}.plist`);
656
+ return join2(homedir(), "Library", "LaunchAgents", `${HOST_SERVICE_LABEL}.plist`);
825
657
  }
826
658
  function isHostServiceInstalled() {
827
- if (platform() === "darwin" || platform() === "linux") return existsSync3(hostServiceFile());
659
+ if (platform() === "darwin" || platform() === "linux") return existsSync2(hostServiceFile());
828
660
  return false;
829
661
  }
830
662
  function restartHostService() {
@@ -864,9 +696,9 @@ function isHostServiceRunning() {
864
696
  }
865
697
 
866
698
  // src/commands/install.ts
867
- import { existsSync as existsSync4, mkdirSync as mkdirSync3, readFileSync as readFileSync5, writeFileSync as writeFileSync4, unlinkSync } from "fs";
699
+ import { existsSync as existsSync3, mkdirSync as mkdirSync2, readFileSync as readFileSync4, writeFileSync as writeFileSync3, unlinkSync } from "fs";
868
700
  import { execSync as execSync2 } from "child_process";
869
- import { dirname as dirname4, join as join4, resolve as resolve2 } from "path";
701
+ import { dirname as dirname3, join as join3, resolve as resolve2 } from "path";
870
702
  import { homedir as homedir2, platform as platform2 } from "os";
871
703
  function log(msg) {
872
704
  console.log(`
@@ -889,7 +721,7 @@ function detectAgentBinDirs() {
889
721
  for (const cli of ["claude", "codex"]) {
890
722
  try {
891
723
  const p = execSync2(`which ${cli}`, { encoding: "utf-8", stdio: "pipe" }).trim();
892
- if (p) dirs.add(dirname4(p));
724
+ if (p) dirs.add(dirname3(p));
893
725
  } catch {
894
726
  }
895
727
  }
@@ -897,16 +729,16 @@ function detectAgentBinDirs() {
897
729
  }
898
730
  function detectNodeBinDir() {
899
731
  const home2 = flyspaceHome();
900
- return home2 ? join4(home2, "node", "bin") : dirname4(process.execPath);
732
+ return home2 ? join3(home2, "node", "bin") : dirname3(process.execPath);
901
733
  }
902
734
  function nodeShimDirs() {
903
- return [join4(homedir2(), ".local", "share", "mise", "shims"), join4(homedir2(), ".asdf", "shims")].filter(
904
- (d) => existsSync4(d)
735
+ return [join3(homedir2(), ".local", "share", "mise", "shims"), join3(homedir2(), ".asdf", "shims")].filter(
736
+ (d) => existsSync3(d)
905
737
  );
906
738
  }
907
739
  function detectCustieBin() {
908
740
  const home2 = flyspaceHome();
909
- if (home2) return join4(home2, "bin", "flyspace");
741
+ if (home2) return join3(home2, "bin", "flyspace");
910
742
  const argv1 = process.argv[1];
911
743
  if (argv1) {
912
744
  return resolve2(argv1);
@@ -918,9 +750,9 @@ function detectCustieBin() {
918
750
  }
919
751
  }
920
752
  function readEnvFile() {
921
- if (!existsSync4(paths.CONFIG_FILE)) return {};
753
+ if (!existsSync3(paths.CONFIG_FILE)) return {};
922
754
  const vars = {};
923
- for (const line of readFileSync5(paths.CONFIG_FILE, "utf-8").split("\n")) {
755
+ for (const line of readFileSync4(paths.CONFIG_FILE, "utf-8").split("\n")) {
924
756
  const trimmed = line.trim();
925
757
  if (!trimmed || trimmed.startsWith("#")) continue;
926
758
  const eq = trimmed.indexOf("=");
@@ -964,9 +796,9 @@ async function installMacOS(spec) {
964
796
  const custieBin = detectCustieBin();
965
797
  const agentBinDirs = detectAgentBinDirs();
966
798
  const logDir = paths.LOG_DIR;
967
- mkdirSync3(logDir, { recursive: true });
799
+ mkdirSync2(logDir, { recursive: true });
968
800
  const envVars = spec.env;
969
- const homebrewBin = existsSync4("/opt/homebrew/bin") ? "/opt/homebrew/bin" : void 0;
801
+ const homebrewBin = existsSync3("/opt/homebrew/bin") ? "/opt/homebrew/bin" : void 0;
970
802
  const pathParts = [
971
803
  detectNodeBinDir(),
972
804
  ...agentBinDirs,
@@ -1005,14 +837,14 @@ ${Object.entries(envVars).map(([k, v]) => ` <key>${k}</key>
1005
837
  <true/>
1006
838
 
1007
839
  <key>StandardOutPath</key>
1008
- <string>${join4(logDir, `${spec.logName}.log`)}</string>
840
+ <string>${join3(logDir, `${spec.logName}.log`)}</string>
1009
841
 
1010
842
  <key>StandardErrorPath</key>
1011
- <string>${join4(logDir, `${spec.logName}-error.log`)}</string>
843
+ <string>${join3(logDir, `${spec.logName}-error.log`)}</string>
1012
844
  </dict>
1013
845
  </plist>`;
1014
846
  const agentPlistPath = spec.plistPath;
1015
- mkdirSync3(dirname4(agentPlistPath), { recursive: true });
847
+ mkdirSync2(dirname3(agentPlistPath), { recursive: true });
1016
848
  try {
1017
849
  run(`launchctl unload "${agentPlistPath}"`, { silent: true });
1018
850
  } catch {
@@ -1021,7 +853,7 @@ ${Object.entries(envVars).map(([k, v]) => ` <key>${k}</key>
1021
853
  unlinkSync(agentPlistPath);
1022
854
  } catch {
1023
855
  }
1024
- writeFileSync4(agentPlistPath, plist);
856
+ writeFileSync3(agentPlistPath, plist);
1025
857
  run(`launchctl load "${agentPlistPath}"`, { silent: true });
1026
858
  success(`LaunchAgent installed and loaded (${spec.label}).`);
1027
859
  console.log(` Logs: ${logDir}`);
@@ -1032,9 +864,9 @@ async function installLinux(spec) {
1032
864
  const custieBin = detectCustieBin();
1033
865
  const agentBinDirs = detectAgentBinDirs();
1034
866
  const logDir = paths.LOG_DIR;
1035
- mkdirSync3(logDir, { recursive: true });
867
+ mkdirSync2(logDir, { recursive: true });
1036
868
  const envLines = Object.entries(spec.env).map(([k, v]) => `Environment="${k}=${v}"`).join("\n");
1037
- const linuxbrewBin = existsSync4("/home/linuxbrew/.linuxbrew/bin") ? "/home/linuxbrew/.linuxbrew/bin" : void 0;
869
+ const linuxbrewBin = existsSync3("/home/linuxbrew/.linuxbrew/bin") ? "/home/linuxbrew/.linuxbrew/bin" : void 0;
1038
870
  const pathParts = [
1039
871
  detectNodeBinDir(),
1040
872
  ...agentBinDirs,
@@ -1058,16 +890,16 @@ RestartSec=5
1058
890
  ${envLines}
1059
891
  Environment="PATH=${pathParts.join(":")}"
1060
892
 
1061
- StandardOutput=append:${join4(logDir, `${spec.logName}.log`)}
1062
- StandardError=append:${join4(logDir, `${spec.logName}-error.log`)}
893
+ StandardOutput=append:${join3(logDir, `${spec.logName}.log`)}
894
+ StandardError=append:${join3(logDir, `${spec.logName}-error.log`)}
1063
895
 
1064
896
  [Install]
1065
897
  WantedBy=default.target
1066
898
  `;
1067
899
  const unitName = spec.unitName;
1068
- const unitDir = join4(homedir2(), ".config", "systemd", "user");
1069
- mkdirSync3(unitDir, { recursive: true });
1070
- writeFileSync4(join4(unitDir, `${unitName}.service`), unit);
900
+ const unitDir = join3(homedir2(), ".config", "systemd", "user");
901
+ mkdirSync2(unitDir, { recursive: true });
902
+ writeFileSync3(join3(unitDir, `${unitName}.service`), unit);
1071
903
  run("systemctl --user daemon-reload", { silent: true });
1072
904
  run(`systemctl --user enable --now ${unitName}`, { silent: true });
1073
905
  success(`systemd user service installed and started (${unitName}).`);
@@ -1094,16 +926,16 @@ async function installHostService() {
1094
926
  }
1095
927
 
1096
928
  // ../api/src/commands/profiles.ts
1097
- import { existsSync as existsSync5, readdirSync, statSync } from "fs";
929
+ import { existsSync as existsSync4, readdirSync, statSync } from "fs";
1098
930
  import { execSync as execSync3 } from "child_process";
1099
- import { join as join5 } from "path";
931
+ import { join as join4 } from "path";
1100
932
  import { platform as platform3 } from "os";
1101
933
  function listProfiles() {
1102
934
  const profiles = [];
1103
- if (existsSync5(paths.PROFILES_DIR)) {
935
+ if (existsSync4(paths.PROFILES_DIR)) {
1104
936
  for (const entry of readdirSync(paths.PROFILES_DIR)) {
1105
937
  try {
1106
- if (statSync(join5(paths.PROFILES_DIR, entry)).isDirectory()) {
938
+ if (statSync(join4(paths.PROFILES_DIR, entry)).isDirectory()) {
1107
939
  profiles.push(entry);
1108
940
  }
1109
941
  } catch {
@@ -1132,23 +964,23 @@ import { execFileSync } from "child_process";
1132
964
  import {
1133
965
  closeSync,
1134
966
  cpSync,
1135
- existsSync as existsSync6,
967
+ existsSync as existsSync5,
1136
968
  lstatSync,
1137
- mkdirSync as mkdirSync4,
969
+ mkdirSync as mkdirSync3,
1138
970
  openSync,
1139
971
  readdirSync as readdirSync2,
1140
- readFileSync as readFileSync6,
972
+ readFileSync as readFileSync5,
1141
973
  readSync,
1142
974
  realpathSync as realpathSync2,
1143
975
  statSync as statSync2,
1144
976
  symlinkSync
1145
977
  } from "fs";
1146
978
  import { homedir as homedir3 } from "os";
1147
- import { basename as basename2, join as join6, resolve as resolve3 } from "path";
979
+ import { basename as basename2, join as join5, resolve as resolve3 } from "path";
1148
980
  var MAX_JSONL_HEAD_BYTES = 64 * 1024;
1149
981
  var GIT_SCAN_ROOTS = ["Workspaces", "Projects", "code"];
1150
982
  function flyspaceRoot() {
1151
- return process.env["FLYSPACE_ROOT"] || join6(homedir3(), "Flyspace");
983
+ return process.env["FLYSPACE_ROOT"] || join5(homedir3(), "Flyspace");
1152
984
  }
1153
985
  function onPath(cmd) {
1154
986
  try {
@@ -1159,16 +991,16 @@ function onPath(cmd) {
1159
991
  }
1160
992
  }
1161
993
  function claudeDir() {
1162
- return process.env["CLAUDE_CONFIG_DIR"] || join6(homedir3(), ".claude");
994
+ return process.env["CLAUDE_CONFIG_DIR"] || join5(homedir3(), ".claude");
1163
995
  }
1164
996
  function codexDir() {
1165
- return process.env["CODEX_HOME"] || join6(homedir3(), ".codex");
997
+ return process.env["CODEX_HOME"] || join5(homedir3(), ".codex");
1166
998
  }
1167
999
  function claudeLoggedIn() {
1168
1000
  if (["ANTHROPIC_API_KEY", "ANTHROPIC_AUTH_TOKEN", "CLAUDE_CODE_OAUTH_TOKEN"].some((k) => process.env[k])) return true;
1169
- if (existsSync6(join6(claudeDir(), ".credentials.json"))) return true;
1001
+ if (existsSync5(join5(claudeDir(), ".credentials.json"))) return true;
1170
1002
  try {
1171
- const raw = JSON.parse(readFileSync6(join6(homedir3(), ".claude.json"), "utf-8"));
1003
+ const raw = JSON.parse(readFileSync5(join5(homedir3(), ".claude.json"), "utf-8"));
1172
1004
  if (raw.oauthAccount) return true;
1173
1005
  } catch {
1174
1006
  }
@@ -1183,7 +1015,7 @@ function claudeLoggedIn() {
1183
1015
  }
1184
1016
  }
1185
1017
  function codexLoggedIn() {
1186
- return !!process.env["OPENAI_API_KEY"] || existsSync6(join6(codexDir(), "auth.json"));
1018
+ return !!process.env["OPENAI_API_KEY"] || existsSync5(join5(codexDir(), "auth.json"));
1187
1019
  }
1188
1020
  function jsonlFiles(dir, depth) {
1189
1021
  const out = [];
@@ -1194,7 +1026,7 @@ function jsonlFiles(dir, depth) {
1194
1026
  return out;
1195
1027
  }
1196
1028
  for (const e of entries) {
1197
- const full = join6(dir, e.name);
1029
+ const full = join5(dir, e.name);
1198
1030
  if (e.isDirectory()) {
1199
1031
  if (depth > 0) out.push(...jsonlFiles(full, depth - 1));
1200
1032
  } else if (e.name.endsWith(".jsonl")) {
@@ -1231,7 +1063,7 @@ function cwdFromTranscript(file) {
1231
1063
  }
1232
1064
  function codexTrustedPaths() {
1233
1065
  try {
1234
- const toml = readFileSync6(join6(codexDir(), "config.toml"), "utf-8");
1066
+ const toml = readFileSync5(join5(codexDir(), "config.toml"), "utf-8");
1235
1067
  return [...toml.matchAll(/^\[projects\.(?:"([^"]+)"|'([^']+)')\]/gm)].map((m) => m[1] ?? m[2]);
1236
1068
  } catch {
1237
1069
  return [];
@@ -1254,7 +1086,7 @@ function gitRepos() {
1254
1086
  const home2 = homedir3();
1255
1087
  const found = [];
1256
1088
  for (const rootName of GIT_SCAN_ROOTS) {
1257
- const root = join6(home2, rootName);
1089
+ const root = join5(home2, rootName);
1258
1090
  let entries;
1259
1091
  try {
1260
1092
  entries = readdirSync2(root, { withFileTypes: true });
@@ -1262,7 +1094,7 @@ function gitRepos() {
1262
1094
  continue;
1263
1095
  }
1264
1096
  for (const e of entries) {
1265
- if (e.isDirectory() && existsSync6(join6(root, e.name, ".git"))) found.push(join6(root, e.name));
1097
+ if (e.isDirectory() && existsSync5(join5(root, e.name, ".git"))) found.push(join5(root, e.name));
1266
1098
  }
1267
1099
  }
1268
1100
  return found;
@@ -1286,12 +1118,12 @@ function detectRunners(history = { claude: false, codex: false }) {
1286
1118
  function linkedTargets(slug) {
1287
1119
  const out = /* @__PURE__ */ new Map();
1288
1120
  if (!SLUG_RE.test(slug)) return out;
1289
- const dir = join6(flyspaceRoot(), slug);
1121
+ const dir = join5(flyspaceRoot(), slug);
1290
1122
  try {
1291
1123
  for (const e of readdirSync2(dir, { withFileTypes: true })) {
1292
1124
  if (!e.isSymbolicLink()) continue;
1293
1125
  try {
1294
- out.set(realpathSync2(join6(dir, e.name)), e.name);
1126
+ out.set(realpathSync2(join5(dir, e.name)), e.name);
1295
1127
  } catch {
1296
1128
  }
1297
1129
  }
@@ -1322,11 +1154,11 @@ function scanOnboarding(slug) {
1322
1154
  });
1323
1155
  }
1324
1156
  };
1325
- const claudeProjects = join6(claudeDir(), "projects");
1157
+ const claudeProjects = join5(claudeDir(), "projects");
1326
1158
  try {
1327
1159
  for (const e of readdirSync2(claudeProjects, { withFileTypes: true })) {
1328
1160
  if (!e.isDirectory()) continue;
1329
- const files = jsonlFiles(join6(claudeProjects, e.name), 0);
1161
+ const files = jsonlFiles(join5(claudeProjects, e.name), 0);
1330
1162
  if (!files.length) continue;
1331
1163
  history.claude = true;
1332
1164
  files.sort((a, b) => b.mtime - a.mtime);
@@ -1339,7 +1171,7 @@ function scanOnboarding(slug) {
1339
1171
  }
1340
1172
  } catch {
1341
1173
  }
1342
- const codexSessions = jsonlFiles(join6(codexDir(), "sessions"), 4);
1174
+ const codexSessions = jsonlFiles(join5(codexDir(), "sessions"), 4);
1343
1175
  if (codexSessions.length) history.codex = true;
1344
1176
  const perCwd = /* @__PURE__ */ new Map();
1345
1177
  for (const f of codexSessions) {
@@ -1388,15 +1220,15 @@ function scanOnboarding(slug) {
1388
1220
  fromGitScan
1389
1221
  };
1390
1222
  }
1391
- var GENERAL_TEMPLATE_DIR = join6(paths.PACKAGE_ROOT, "templates", "general");
1223
+ var GENERAL_TEMPLATE_DIR = join5(paths.PACKAGE_ROOT, "templates", "general");
1392
1224
  function makeLink(target, linkPath) {
1393
1225
  symlinkSync(target, linkPath, process.platform === "win32" ? "junction" : "dir");
1394
1226
  }
1395
1227
  var SLUG_RE = /^[a-z0-9][a-z0-9-]*$/;
1396
1228
  function assertLinkable(target) {
1397
- const home2 = existsSync6(homedir3()) ? realpathSync2(homedir3()) : homedir3();
1398
- const root = existsSync6(flyspaceRoot()) ? realpathSync2(flyspaceRoot()) : flyspaceRoot();
1399
- const denied = [join6(home2, ".ssh"), join6(home2, "Library"), join6(home2, ".config"), join6(home2, ".gnupg")];
1229
+ const home2 = existsSync5(homedir3()) ? realpathSync2(homedir3()) : homedir3();
1230
+ const root = existsSync5(flyspaceRoot()) ? realpathSync2(flyspaceRoot()) : flyspaceRoot();
1231
+ const denied = [join5(home2, ".ssh"), join5(home2, "Library"), join5(home2, ".config"), join5(home2, ".gnupg")];
1400
1232
  if (target === home2 || target === "/" || target === root || target.startsWith(`${root}/`)) {
1401
1233
  throw new Error(`cannot link ${target}`);
1402
1234
  }
@@ -1404,12 +1236,12 @@ function assertLinkable(target) {
1404
1236
  }
1405
1237
  function linkProjectFolders(slug, items2) {
1406
1238
  if (!SLUG_RE.test(slug)) throw new Error(`invalid workspace slug: ${slug}`);
1407
- const dir = join6(flyspaceRoot(), slug);
1408
- mkdirSync4(dir, { recursive: true });
1239
+ const dir = join5(flyspaceRoot(), slug);
1240
+ mkdirSync3(dir, { recursive: true });
1409
1241
  const results = [];
1410
1242
  for (const item of items2) {
1411
1243
  if (!SLUG_RE.test(item.name)) throw new Error(`invalid channel name: ${item.name}`);
1412
- const dest = join6(dir, item.name);
1244
+ const dest = join5(dir, item.name);
1413
1245
  let exists = true;
1414
1246
  try {
1415
1247
  lstatSync(dest);
@@ -1436,7 +1268,7 @@ function linkProjectFolders(slug, items2) {
1436
1268
  assertLinkable(realpathSync2(target));
1437
1269
  makeLink(target, dest);
1438
1270
  } else {
1439
- mkdirSync4(dest, { recursive: true });
1271
+ mkdirSync3(dest, { recursive: true });
1440
1272
  if (item.name === "general") cpSync(GENERAL_TEMPLATE_DIR, dest, { recursive: true });
1441
1273
  }
1442
1274
  }
@@ -1870,8 +1702,8 @@ ${BOLD2}Flyspace Setup${RESET2}
1870
1702
  const anyReady = runners.some((r) => r.installed && r.loggedIn);
1871
1703
  for (const slug of workspaces) {
1872
1704
  if (!/^[a-z0-9][a-z0-9-]*$/.test(slug)) continue;
1873
- const dir = join7(flyspaceRoot(), slug);
1874
- mkdirSync5(dir, { recursive: true });
1705
+ const dir = join6(flyspaceRoot(), slug);
1706
+ mkdirSync4(dir, { recursive: true });
1875
1707
  ok(`Folder ${tilde2(dir)}`);
1876
1708
  }
1877
1709
  let hostRunning = false;
@@ -1910,8 +1742,8 @@ ${BOLD2}Flyspace Setup${RESET2}
1910
1742
 
1911
1743
  // src/commands/doctor.ts
1912
1744
  import { execFile } from "child_process";
1913
- import { existsSync as existsSync7, readFileSync as readFileSync7 } from "fs";
1914
- import { join as join8 } from "path";
1745
+ import { existsSync as existsSync6, readFileSync as readFileSync6 } from "fs";
1746
+ import { join as join7 } from "path";
1915
1747
  import { parse as parseEnv } from "dotenv";
1916
1748
  import { tmpdir } from "os";
1917
1749
  import { promisify } from "util";
@@ -1978,12 +1810,12 @@ async function probe(id) {
1978
1810
  }
1979
1811
  async function probeProfilesClaude(workspaces) {
1980
1812
  for (const name of workspaces) {
1981
- const file = join8(paths.PROFILES_DIR, name, "config.env");
1982
- const env = existsSync7(file) ? parseEnv(readFileSync7(file, "utf-8")) : {};
1813
+ const file = join7(paths.PROFILES_DIR, name, "config.env");
1814
+ const env = existsSync6(file) ? parseEnv(readFileSync6(file, "utf-8")) : {};
1983
1815
  const token = env["CLAUDE_CODE_OAUTH_TOKEN"];
1984
1816
  const configDir2 = env["CLAUDE_CONFIG_DIR"];
1985
1817
  const plist = profileServiceFile(name);
1986
- if (!token && existsSync7(plist) && readFileSync7(plist, "utf-8").includes("CLAUDE_CODE_OAUTH_TOKEN"))
1818
+ if (!token && existsSync6(plist) && readFileSync6(plist, "utf-8").includes("CLAUDE_CODE_OAUTH_TOKEN"))
1987
1819
  bad2(
1988
1820
  `${name}: CLAUDE_CODE_OAUTH_TOKEN is set in ${tilde3(plist)} but not in ${tilde3(file)}; the dashboard ignores the plist`,
1989
1821
  `move the token into ${tilde3(file)}, then restart the dashboard service`
@@ -2086,10 +1918,10 @@ ${BOLD3}Flyspace Doctor${RESET3}
2086
1918
  }
2087
1919
 
2088
1920
  // src/commands/uninstall.ts
2089
- import { existsSync as existsSync8, mkdirSync as mkdirSync6, readFileSync as readFileSync8, rmSync as rmSync3, unlinkSync as unlinkSync2, writeFileSync as writeFileSync5 } from "fs";
1921
+ import { existsSync as existsSync7, mkdirSync as mkdirSync5, readFileSync as readFileSync7, rmSync as rmSync2, unlinkSync as unlinkSync2, writeFileSync as writeFileSync4 } from "fs";
2090
1922
  import { confirm as confirm3 } from "@inquirer/prompts";
2091
1923
  import { execSync as execSync5 } from "child_process";
2092
- import { basename as basename3, join as join9 } from "path";
1924
+ import { basename as basename3, join as join8 } from "path";
2093
1925
  import { homedir as homedir4, platform as platform5 } from "os";
2094
1926
  function log2(msg) {
2095
1927
  console.log(`
@@ -2110,7 +1942,7 @@ async function runServiceUninstall(profile = getProfile()) {
2110
1942
  if (os === "darwin") {
2111
1943
  const removed = [];
2112
1944
  for (const plist of [plistPath(profile), legacyPlistPath(profile)]) {
2113
- if (!existsSync8(plist)) continue;
1945
+ if (!existsSync7(plist)) continue;
2114
1946
  try {
2115
1947
  run2(`launchctl unload "${plist}"`);
2116
1948
  } catch {
@@ -2132,7 +1964,7 @@ async function runServiceUninstall(profile = getProfile()) {
2132
1964
  run2(`systemctl --user disable --now ${unitName}`);
2133
1965
  } catch {
2134
1966
  }
2135
- const unitPath = join9(homedir4(), ".config", "systemd", "user", `${unitName}.service`);
1967
+ const unitPath = join8(homedir4(), ".config", "systemd", "user", `${unitName}.service`);
2136
1968
  try {
2137
1969
  unlinkSync2(unitPath);
2138
1970
  } catch {
@@ -2147,13 +1979,13 @@ async function runServiceUninstall(profile = getProfile()) {
2147
1979
  }
2148
1980
  }
2149
1981
  async function runUninstall(args = []) {
2150
- const prefix = process.env["FLYSPACE_PREFIX"] || join9(homedir4(), ".flyspace");
2151
- const targets = [paths.BASE_CONFIG_DIR, paths.BASE_DATA_DIR, prefix].filter(existsSync8);
1982
+ const prefix = process.env["FLYSPACE_PREFIX"] || join8(homedir4(), ".flyspace");
1983
+ const targets = [paths.BASE_CONFIG_DIR, paths.BASE_DATA_DIR, prefix].filter(existsSync7);
2152
1984
  console.log("\n This removes Flyspace from this machine:");
2153
1985
  console.log(" - revokes this device and removes every background service");
2154
1986
  for (const t of targets) console.log(` - deletes ${t}`);
2155
1987
  console.log(" Your channel folders (~/Flyspace) are kept.\n");
2156
- const backupSources = [paths.BASE_CONFIG_DIR, paths.BASE_DATA_DIR].filter(existsSync8);
1988
+ const backupSources = [paths.BASE_CONFIG_DIR, paths.BASE_DATA_DIR].filter(existsSync7);
2157
1989
  const interactive = !args.includes("--yes") && !args.includes("-y");
2158
1990
  let backup = !args.includes("--no-backup") && backupSources.length > 0;
2159
1991
  if (interactive) {
@@ -2165,10 +1997,10 @@ async function runUninstall(args = []) {
2165
1997
  }
2166
1998
  let backupFile;
2167
1999
  if (backup) {
2168
- const dir = join9(homedir4(), "Flyspace", ".uninstall-backups");
2169
- mkdirSync6(dir, { recursive: true });
2000
+ const dir = join8(homedir4(), "Flyspace", ".uninstall-backups");
2001
+ mkdirSync5(dir, { recursive: true });
2170
2002
  const stamp2 = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
2171
- backupFile = join9(dir, `flyspace-${stamp2}.tar.gz`);
2003
+ backupFile = join8(dir, `flyspace-${stamp2}.tar.gz`);
2172
2004
  const rel = backupSources.map((s) => `"${s.replace(/^\//, "")}"`).join(" ");
2173
2005
  try {
2174
2006
  run2(`tar -czf "${backupFile}" -C / ${rel}`);
@@ -2192,18 +2024,18 @@ async function runUninstall(args = []) {
2192
2024
  await runServiceUninstall(profile);
2193
2025
  }
2194
2026
  for (const t of targets) {
2195
- rmSync3(t, { recursive: true, force: true });
2027
+ rmSync2(t, { recursive: true, force: true });
2196
2028
  success2(`Deleted ${t}`);
2197
2029
  }
2198
- for (const rc of [".zshrc", ".bashrc", ".profile"].map((f) => join9(homedir4(), f))) {
2199
- if (!existsSync8(rc)) continue;
2200
- const before = readFileSync8(rc, "utf-8");
2030
+ for (const rc of [".zshrc", ".bashrc", ".profile"].map((f) => join8(homedir4(), f))) {
2031
+ if (!existsSync7(rc)) continue;
2032
+ const before = readFileSync7(rc, "utf-8");
2201
2033
  const after = before.replace(
2202
2034
  /\n# Flyspace CLI\nexport PATH="[^"\n]*\.flyspace\/bin:\$PATH"\n?/g,
2203
2035
  "\n"
2204
2036
  );
2205
2037
  if (after !== before) {
2206
- writeFileSync5(rc, after);
2038
+ writeFileSync4(rc, after);
2207
2039
  success2(`Removed PATH entry from ${rc}`);
2208
2040
  }
2209
2041
  }
@@ -2218,7 +2050,7 @@ async function runUninstall(args = []) {
2218
2050
  }
2219
2051
 
2220
2052
  // src/commands/profiles-cmd.ts
2221
- import { rmSync as rmSync4 } from "fs";
2053
+ import { rmSync as rmSync3 } from "fs";
2222
2054
  var USAGE = `
2223
2055
  Usage: flyspace profiles [list]
2224
2056
  flyspace profiles remove <name>
@@ -2275,7 +2107,7 @@ async function removeCmd(name) {
2275
2107
  }
2276
2108
  const { configDir: configDir2, dataDir } = runWithProfile(name, () => ({ configDir: paths.CONFIG_DIR, dataDir: paths.DATA_DIR }));
2277
2109
  if (isServiceInstalled(name)) await runWithProfile(name, runUninstall);
2278
- rmSync4(configDir2, { recursive: true, force: true });
2110
+ rmSync3(configDir2, { recursive: true, force: true });
2279
2111
  console.log(`\x1B[32m+\x1B[0m Local config removed: ${configDir2}`);
2280
2112
  console.log(`
2281
2113
  Kept: ${dataDir} (sessions, logs) and any ~/Flyspace/${name}/ channel folders.`);
@@ -2292,8 +2124,8 @@ async function runProfiles(args = []) {
2292
2124
 
2293
2125
  // src/commands/upgrade.ts
2294
2126
  import { execSync as execSync6 } from "child_process";
2295
- import { existsSync as existsSync9, readFileSync as readFileSync9, realpathSync as realpathSync3 } from "fs";
2296
- import { dirname as dirname5, join as join10 } from "path";
2127
+ import { existsSync as existsSync8, readFileSync as readFileSync8, realpathSync as realpathSync3 } from "fs";
2128
+ import { dirname as dirname4, join as join9 } from "path";
2297
2129
  function restartInstalledProfiles() {
2298
2130
  if (isHostServiceInstalled()) {
2299
2131
  console.log(restartHostService() ? "\nHost restarted." : "\nHost restart failed; run: flyspace setup --start-host --restart");
@@ -2314,19 +2146,19 @@ Restarting ${installed.length} instance(s)...`);
2314
2146
  }
2315
2147
  }
2316
2148
  function installTarget(entry) {
2317
- const home2 = flyspaceHome(entry) ?? (entry.endsWith("/bin/flyspace") ? dirname5(dirname5(entry)) : void 0);
2318
- if (home2 && existsSync9(join10(home2, "cli", "lib", "node_modules", "flyspace-cli"))) {
2319
- return { prefix: join10(home2, "cli"), nodeBin: join10(home2, "node", "bin") };
2149
+ const home2 = flyspaceHome(entry) ?? (entry.endsWith("/bin/flyspace") ? dirname4(dirname4(entry)) : void 0);
2150
+ if (home2 && existsSync8(join9(home2, "cli", "lib", "node_modules", "flyspace-cli"))) {
2151
+ return { prefix: join9(home2, "cli"), nodeBin: join9(home2, "node", "bin") };
2320
2152
  }
2321
2153
  try {
2322
2154
  const real = realpathSync3(entry);
2323
2155
  const at = real.indexOf(`/lib/node_modules/${"flyspace-cli"}/`);
2324
- if (at > 0) return { prefix: real.slice(0, at), nodeBin: join10(real.slice(0, at), "bin") };
2156
+ if (at > 0) return { prefix: real.slice(0, at), nodeBin: join9(real.slice(0, at), "bin") };
2325
2157
  } catch {
2326
2158
  }
2327
- const prefix = entry.endsWith("/bin/flyspace") ? dirname5(dirname5(entry)) : void 0;
2328
- if (prefix && existsSync9(join10(prefix, "lib", "node_modules", "flyspace-cli"))) {
2329
- return { prefix, nodeBin: join10(prefix, "bin") };
2159
+ const prefix = entry.endsWith("/bin/flyspace") ? dirname4(dirname4(entry)) : void 0;
2160
+ if (prefix && existsSync8(join9(prefix, "lib", "node_modules", "flyspace-cli"))) {
2161
+ return { prefix, nodeBin: join9(prefix, "bin") };
2330
2162
  }
2331
2163
  return void 0;
2332
2164
  }
@@ -2344,8 +2176,8 @@ function installTargets() {
2344
2176
  }
2345
2177
  function installedVersion(target) {
2346
2178
  try {
2347
- const pkg = join10(target.prefix, "lib", "node_modules", "flyspace-cli", "package.json");
2348
- return JSON.parse(readFileSync9(pkg, "utf-8")).version;
2179
+ const pkg = join9(target.prefix, "lib", "node_modules", "flyspace-cli", "package.json");
2180
+ return JSON.parse(readFileSync8(pkg, "utf-8")).version;
2349
2181
  } catch {
2350
2182
  return void 0;
2351
2183
  }
@@ -2356,11 +2188,11 @@ function npmInstallCommand(target) {
2356
2188
  }
2357
2189
  function npmEnv(target) {
2358
2190
  const home2 = flyspaceHome();
2359
- const nodeBin = target?.nodeBin ?? (home2 ? join10(home2, "node", "bin") : void 0);
2191
+ const nodeBin = target?.nodeBin ?? (home2 ? join9(home2, "node", "bin") : void 0);
2360
2192
  return nodeBin ? { ...process.env, PATH: `${nodeBin}:${process.env.PATH ?? ""}` } : process.env;
2361
2193
  }
2362
2194
  async function runUpgrade() {
2363
- const current = "0.1.57";
2195
+ const current = "0.1.59";
2364
2196
  console.log(`Current version: ${current}`);
2365
2197
  console.log("Checking for updates...\n");
2366
2198
  try {
@@ -2403,13 +2235,13 @@ You can upgrade manually with: ${npmInstallCommand()}`);
2403
2235
  import { WebClient } from "@slack/web-api";
2404
2236
 
2405
2237
  // src/automations/config-file.ts
2406
- import { readFileSync as readFileSync10, existsSync as existsSync10 } from "fs";
2238
+ import { readFileSync as readFileSync9, existsSync as existsSync9 } from "fs";
2407
2239
  import yaml from "js-yaml";
2408
2240
  var EMPTY_CONFIG = { schedules: [], triggers: [], mention_triggers: [] };
2409
2241
  function loadAutomationsFile() {
2410
2242
  const filePath = paths.AUTOMATIONS_FILE;
2411
- if (!existsSync10(filePath)) return { ...EMPTY_CONFIG };
2412
- const raw = readFileSync10(filePath, "utf-8");
2243
+ if (!existsSync9(filePath)) return { ...EMPTY_CONFIG };
2244
+ const raw = readFileSync9(filePath, "utf-8");
2413
2245
  if (!raw.trim()) return { ...EMPTY_CONFIG };
2414
2246
  const parsed = yaml.load(raw);
2415
2247
  return {
@@ -2420,7 +2252,7 @@ function loadAutomationsFile() {
2420
2252
  }
2421
2253
 
2422
2254
  // src/commands/automation.ts
2423
- import { readFileSync as readFileSync11 } from "fs";
2255
+ import { readFileSync as readFileSync10 } from "fs";
2424
2256
  var USAGE2 = `
2425
2257
  Usage: flyspace automation <subcommand> [options]
2426
2258
 
@@ -2708,7 +2540,7 @@ async function handleEdit(manager, name, args) {
2708
2540
  console.error(`"${name}" runs a script, not a prompt.`);
2709
2541
  process.exit(1);
2710
2542
  }
2711
- const prompt = inline ?? readFileSync11(file, "utf8");
2543
+ const prompt = inline ?? readFileSync10(file, "utf8");
2712
2544
  if (!prompt.trim()) {
2713
2545
  console.error("Prompt must not be empty.");
2714
2546
  process.exit(1);
@@ -2820,7 +2652,7 @@ async function runAutomationCmd(args) {
2820
2652
  }
2821
2653
 
2822
2654
  // src/commands/usage.ts
2823
- import { existsSync as existsSync11 } from "fs";
2655
+ import { existsSync as existsSync10 } from "fs";
2824
2656
  var HELP4 = `
2825
2657
  Usage: flyspace usage [options]
2826
2658
 
@@ -2947,7 +2779,7 @@ async function runUsage(args) {
2947
2779
  return;
2948
2780
  }
2949
2781
  const { days, by, explain, json } = parsed;
2950
- if (!existsSync11(paths.DB_FILE)) {
2782
+ if (!existsSync10(paths.DB_FILE)) {
2951
2783
  console.log("No usage recorded yet (the database does not exist).");
2952
2784
  return;
2953
2785
  }
@@ -3062,17 +2894,17 @@ async function runRestart() {
3062
2894
 
3063
2895
  // src/commands/logs.ts
3064
2896
  import { spawn as spawn3 } from "child_process";
3065
- import { existsSync as existsSync12 } from "fs";
3066
- import { join as join11 } from "path";
2897
+ import { existsSync as existsSync11 } from "fs";
2898
+ import { join as join10 } from "path";
3067
2899
  function serviceLogFile(errors) {
3068
2900
  const suffix = errors ? "-error.log" : ".log";
3069
- const candidates = ["host", "custie"].map((name) => join11(paths.LOG_DIR, `${name}${suffix}`));
3070
- return candidates.find((file) => existsSync12(file)) ?? candidates[0];
2901
+ const candidates = ["host", "custie"].map((name) => join10(paths.LOG_DIR, `${name}${suffix}`));
2902
+ return candidates.find((file) => existsSync11(file)) ?? candidates[0];
3071
2903
  }
3072
2904
  async function runLogs(args) {
3073
2905
  const showErrors = args.includes("--error") || args.includes("-e");
3074
2906
  const logFile = serviceLogFile(showErrors);
3075
- if (!existsSync12(logFile)) {
2907
+ if (!existsSync11(logFile)) {
3076
2908
  console.error(`Log file not found: ${logFile}`);
3077
2909
  console.error("Is the service installed? Run `flyspace install` first.");
3078
2910
  process.exit(1);
@@ -3093,7 +2925,7 @@ async function runLogs(args) {
3093
2925
 
3094
2926
  // src/commands/slack.ts
3095
2927
  import { execFileSync as execFileSync3 } from "child_process";
3096
- import { existsSync as existsSync13, readFileSync as readFileSync12, writeFileSync as writeFileSync6 } from "fs";
2928
+ import { existsSync as existsSync12, readFileSync as readFileSync11, writeFileSync as writeFileSync5 } from "fs";
3097
2929
  import { resolve as resolve4 } from "path";
3098
2930
  import { tmpdir as tmpdir2, homedir as homedir5 } from "os";
3099
2931
  import { input, confirm as confirm4, select, checkbox } from "@inquirer/prompts";
@@ -5065,7 +4897,7 @@ async function threadReplies(client2, nameOrId, ts2) {
5065
4897
  async function postMessage(client2, args) {
5066
4898
  const channelArg = getArg2(args, "--channel");
5067
4899
  const textFilePath = getArg2(args, "--text-file");
5068
- const text = textFilePath ? readFileSync12(textFilePath, "utf8") : getArg2(args, "--text");
4900
+ const text = textFilePath ? readFileSync11(textFilePath, "utf8") : getArg2(args, "--text");
5069
4901
  const threadTs = getArg2(args, "--thread");
5070
4902
  const markdown = args.includes("--markdown");
5071
4903
  const broadcast = args.includes("--broadcast") && Boolean(threadTs);
@@ -5163,7 +4995,7 @@ function defaultClaudeConfigDir() {
5163
4995
  return process.env.CLAUDE_CONFIG_DIR || resolve4(homedir5(), ".claude");
5164
4996
  }
5165
4997
  function hasClaudeCredentials(configDir2) {
5166
- if (existsSync13(resolve4(configDir2, ".credentials.json"))) {
4998
+ if (existsSync12(resolve4(configDir2, ".credentials.json"))) {
5167
4999
  return true;
5168
5000
  }
5169
5001
  if (process.platform === "darwin") {
@@ -5220,7 +5052,7 @@ async function ensureClaudeCodeReady() {
5220
5052
  }
5221
5053
  function getManifestYaml(botName) {
5222
5054
  const manifestPath = resolve4(paths.PACKAGE_ROOT, "slack-app-manifest.yml");
5223
- const raw = readFileSync12(manifestPath, "utf-8");
5055
+ const raw = readFileSync11(manifestPath, "utf-8");
5224
5056
  return raw.replace(/name: Custie/g, `name: ${botName}`);
5225
5057
  }
5226
5058
  async function stepPersonalise() {
@@ -5637,7 +5469,7 @@ function writeConfigFile(config) {
5637
5469
  `OWNER_USER_ID=${config.ownerUserId}`,
5638
5470
  ``
5639
5471
  ].join("\n");
5640
- writeFileSync6(paths.CONFIG_FILE, envContent);
5472
+ writeFileSync5(paths.CONFIG_FILE, envContent);
5641
5473
  success4(`Config written to ${paths.CONFIG_FILE}`);
5642
5474
  }
5643
5475
  function printNextSteps() {
@@ -5649,11 +5481,11 @@ function printNextSteps() {
5649
5481
  console.log(" Run \x1B[1mflyspace service install\x1B[0m\n");
5650
5482
  }
5651
5483
  function copyDefaultPrompt(botName) {
5652
- if (!existsSync13(paths.PROMPT_FILE)) {
5484
+ if (!existsSync12(paths.PROMPT_FILE)) {
5653
5485
  const defaultPrompt = resolve4(paths.PACKAGE_ROOT, "system.default.md");
5654
- if (existsSync13(defaultPrompt)) {
5655
- const content = readFileSync12(defaultPrompt, "utf-8").replace(/\{\{botName\}\}/g, botName);
5656
- writeFileSync6(paths.PROMPT_FILE, content);
5486
+ if (existsSync12(defaultPrompt)) {
5487
+ const content = readFileSync11(defaultPrompt, "utf-8").replace(/\{\{botName\}\}/g, botName);
5488
+ writeFileSync5(paths.PROMPT_FILE, content);
5657
5489
  success4(`Default prompt copied to ${paths.PROMPT_FILE}`);
5658
5490
  }
5659
5491
  }
@@ -5665,7 +5497,7 @@ async function runSlackSetup(args) {
5665
5497
  const prereq = await ensureClaudeCodeReady();
5666
5498
  if (!prereq) return;
5667
5499
  const { claudeConfigDir } = prereq;
5668
- if (existsSync13(paths.CONFIG_FILE)) {
5500
+ if (existsSync12(paths.CONFIG_FILE)) {
5669
5501
  const reconfigure = await confirm4({
5670
5502
  message: `Config already exists at ${paths.CONFIG_FILE}. Reconfigure?`,
5671
5503
  default: false
@@ -6026,21 +5858,21 @@ async function runChatCmd(args) {
6026
5858
  }
6027
5859
 
6028
5860
  // src/commands/memory.ts
6029
- import { readFileSync as readFileSync14 } from "fs";
5861
+ import { readFileSync as readFileSync13 } from "fs";
6030
5862
 
6031
5863
  // src/store/claude-memory-import.ts
6032
- import { existsSync as existsSync14, readdirSync as readdirSync3, readFileSync as readFileSync13 } from "fs";
5864
+ import { existsSync as existsSync13, readdirSync as readdirSync3, readFileSync as readFileSync12 } from "fs";
6033
5865
  import { homedir as homedir6 } from "os";
6034
- import { basename as basename5, join as join12 } from "path";
5866
+ import { basename as basename5, join as join11 } from "path";
6035
5867
  import dotenv from "dotenv";
6036
5868
  function claudeMemoryDir(cwd, configDir2) {
6037
- return join12(configDir2, "projects", cwd.replaceAll(/[^a-zA-Z0-9]/g, "-"), "memory");
5869
+ return join11(configDir2, "projects", cwd.replaceAll(/[^a-zA-Z0-9]/g, "-"), "memory");
6038
5870
  }
6039
5871
  function profileClaudeConfigDirFor(profile) {
6040
- const dir = profile === "default" ? paths.BASE_CONFIG_DIR : join12(paths.PROFILES_DIR, profile);
6041
- const file = join12(dir, "config.env");
6042
- const env = existsSync14(file) ? dotenv.parse(readFileSync13(file)) : {};
6043
- return env["CLAUDE_CONFIG_DIR"]?.trim() || join12(homedir6(), ".claude");
5872
+ const dir = profile === "default" ? paths.BASE_CONFIG_DIR : join11(paths.PROFILES_DIR, profile);
5873
+ const file = join11(dir, "config.env");
5874
+ const env = existsSync13(file) ? dotenv.parse(readFileSync12(file)) : {};
5875
+ return env["CLAUDE_CONFIG_DIR"]?.trim() || join11(homedir6(), ".claude");
6044
5876
  }
6045
5877
  var TYPE_MAP = {
6046
5878
  user: "preference",
@@ -6085,11 +5917,11 @@ function parseClaudeMemory(fileName, text, channelId) {
6085
5917
  return input2;
6086
5918
  }
6087
5919
  async function importClaudeMemories(dir, channelId, opts = {}) {
6088
- if (!existsSync14(dir)) throw new Error(`No Claude memory directory at ${dir}`);
5920
+ if (!existsSync13(dir)) throw new Error(`No Claude memory directory at ${dir}`);
6089
5921
  const files = readdirSync3(dir).filter((f) => f.endsWith(".md") && f !== "MEMORY.md").sort();
6090
5922
  const results = [];
6091
5923
  for (const file of files) {
6092
- const parsed = parseClaudeMemory(file, readFileSync13(join12(dir, file), "utf-8"), channelId);
5924
+ const parsed = parseClaudeMemory(file, readFileSync12(join11(dir, file), "utf-8"), channelId);
6093
5925
  if ("skip" in parsed) {
6094
5926
  results.push({ file, outcome: "skipped", reason: parsed.skip });
6095
5927
  continue;
@@ -6201,7 +6033,7 @@ ${memory.body}`);
6201
6033
  );
6202
6034
  }
6203
6035
  if (!isMemoryType(type)) throw new Error(`--type must be one of ${MEMORY_TYPES.join(", ")}`);
6204
- const body = bodyArg === "-" ? readFileSync14(0, "utf-8") : bodyArg;
6036
+ const body = bodyArg === "-" ? readFileSync13(0, "utf-8") : bodyArg;
6205
6037
  const thread = getArg4(rest, "--thread");
6206
6038
  const { created, changed } = await saveMemory(
6207
6039
  target,
@@ -6301,12 +6133,12 @@ async function runMcpCmd(args) {
6301
6133
 
6302
6134
  // src/commands/dashboard.ts
6303
6135
  import { spawn as spawn6, spawnSync } from "child_process";
6304
- import { existsSync as existsSync28 } from "fs";
6136
+ import { existsSync as existsSync27 } from "fs";
6305
6137
  import { platform as platform7 } from "os";
6306
- import { join as join20 } from "path";
6138
+ import { join as join19 } from "path";
6307
6139
 
6308
6140
  // src/reconcile.ts
6309
- import { existsSync as existsSync15, mkdirSync as mkdirSync7, writeFileSync as writeFileSync7 } from "fs";
6141
+ import { existsSync as existsSync14, mkdirSync as mkdirSync6, writeFileSync as writeFileSync6 } from "fs";
6310
6142
  async function boundWorkspaces2() {
6311
6143
  return (await boundWorkspaces())?.workspaces ?? null;
6312
6144
  }
@@ -6317,13 +6149,13 @@ async function servedWorkspaces2() {
6317
6149
  async function reconcileProfile(profile) {
6318
6150
  return runWithProfile(profile, async () => {
6319
6151
  const log5 = [];
6320
- const hadConfigDir = existsSync15(paths.CONFIG_DIR);
6321
- const hadDataDir = existsSync15(paths.DATA_DIR);
6152
+ const hadConfigDir = existsSync14(paths.CONFIG_DIR);
6153
+ const hadDataDir = existsSync14(paths.DATA_DIR);
6322
6154
  ensureDirs();
6323
6155
  if (!hadConfigDir) log5.push(`config dir created (${paths.CONFIG_DIR})`);
6324
6156
  if (!hadDataDir) log5.push(`data dir created (${paths.DATA_DIR})`);
6325
- if (!existsSync15(paths.CONFIG_FILE)) {
6326
- writeFileSync7(paths.CONFIG_FILE, `BOT_NAME=${profile}
6157
+ if (!existsSync14(paths.CONFIG_FILE)) {
6158
+ writeFileSync6(paths.CONFIG_FILE, `BOT_NAME=${profile}
6327
6159
  `);
6328
6160
  log5.push(`config.env written (${paths.CONFIG_FILE})`);
6329
6161
  }
@@ -6332,7 +6164,7 @@ async function reconcileProfile(profile) {
6332
6164
  if (!channel.cwd) continue;
6333
6165
  const cwd = expandPath(channel.cwd);
6334
6166
  if (isCwdUsable(cwd)) continue;
6335
- mkdirSync7(cwd, { recursive: true });
6167
+ mkdirSync6(cwd, { recursive: true });
6336
6168
  log5.push(`channel "${channel.name}" cwd created (${cwd})`);
6337
6169
  }
6338
6170
  return log5;
@@ -6479,7 +6311,7 @@ async function verifyTurnstileToken(token) {
6479
6311
  import { Hono as Hono6 } from "hono";
6480
6312
 
6481
6313
  // ../api/src/store/device-store.ts
6482
- import { createHash as createHash2, createPublicKey as createPublicKey2, randomBytes as randomBytes3, randomInt } from "crypto";
6314
+ import { createHash as createHash2, createPublicKey, randomBytes as randomBytes3, randomInt } from "crypto";
6483
6315
  var DEVICE_CODE_TTL_MS = 10 * 6e4;
6484
6316
  var ACCESS_TOKEN_TTL_MS = 15 * 6e4;
6485
6317
  var CHALLENGE_TTL_MS = 2 * 6e4;
@@ -6488,7 +6320,7 @@ var sha256 = (s) => createHash2("sha256").update(s).digest("hex");
6488
6320
  function parseEd25519PublicKey(b64) {
6489
6321
  if (typeof b64 !== "string" || b64.length > 200) return null;
6490
6322
  try {
6491
- const key = createPublicKey2({ key: Buffer.from(b64, "base64"), format: "der", type: "spki" });
6323
+ const key = createPublicKey({ key: Buffer.from(b64, "base64"), format: "der", type: "spki" });
6492
6324
  return key.asymmetricKeyType === "ed25519" ? key : null;
6493
6325
  } catch {
6494
6326
  return null;
@@ -6709,23 +6541,23 @@ import { randomBytes as randomBytes4, randomUUID as randomUUID2, verify as verif
6709
6541
  import { WebSocket, WebSocketServer } from "ws";
6710
6542
 
6711
6543
  // ../api/src/dashboard/host-identity.ts
6712
- import { createPrivateKey as createPrivateKey2, createPublicKey as createPublicKey3, generateKeyPairSync as generateKeyPairSync2 } from "crypto";
6713
- import { existsSync as existsSync16, mkdirSync as mkdirSync8, readFileSync as readFileSync15, writeFileSync as writeFileSync8 } from "fs";
6714
- import { dirname as dirname6, join as join13 } from "path";
6544
+ import { createPrivateKey, createPublicKey as createPublicKey2, generateKeyPairSync } from "crypto";
6545
+ import { existsSync as existsSync15, mkdirSync as mkdirSync7, readFileSync as readFileSync14, writeFileSync as writeFileSync7 } from "fs";
6546
+ import { dirname as dirname5, join as join12 } from "path";
6715
6547
  function hostPrivateKeyPath() {
6716
- return process.env["FLYSPACE_HOST_KEY_PATH"] || join13(paths.BASE_CONFIG_DIR, "host.key");
6548
+ return process.env["FLYSPACE_HOST_KEY_PATH"] || join12(paths.BASE_CONFIG_DIR, "host.key");
6717
6549
  }
6718
6550
  function loadHostPrivateKey(path = hostPrivateKeyPath()) {
6719
- if (!existsSync16(path)) {
6551
+ if (!existsSync15(path)) {
6720
6552
  throw new Error(
6721
6553
  `No Host identity at ${path}. Run \`pnpm run generate-host-key\` on this machine, then set FLYSPACE_HOST_PUBLIC_KEY on the Data process to the printed public key.`
6722
6554
  );
6723
6555
  }
6724
- return createPrivateKey2(readFileSync15(path, "utf8"));
6556
+ return createPrivateKey(readFileSync14(path, "utf8"));
6725
6557
  }
6726
6558
 
6727
6559
  // ../api/src/dashboard/uploads-routes.ts
6728
- import { randomUUID } from "crypto";
6560
+ import { createHash as createHash3, randomUUID } from "crypto";
6729
6561
  import { Hono as Hono5 } from "hono";
6730
6562
  import sharp2 from "sharp";
6731
6563
  import { PutObjectCommand, GetObjectCommand as GetObjectCommand2 } from "@aws-sdk/client-s3";
@@ -6733,6 +6565,7 @@ import { getSignedUrl as getSignedUrl2 } from "@aws-sdk/s3-request-presigner";
6733
6565
  var MAX_FILE_BYTES = 10 * 1024 * 1024;
6734
6566
  var PRESIGN_TTL_SECONDS = 300;
6735
6567
  var KEY_PREFIX = "chat";
6568
+ var PLUGIN_UI_PREFIX = "plugin-ui";
6736
6569
  var RESIZABLE = /* @__PURE__ */ new Set(["image/jpeg", "image/png", "image/webp", "image/avif"]);
6737
6570
  var FULL_EDGE = 2560;
6738
6571
  var THUMB_EDGE = 480;
@@ -6740,7 +6573,8 @@ var WEBP_QUALITY = 80;
6740
6573
  function toWebp(input2, edge) {
6741
6574
  return sharp2(input2).rotate().resize({ width: edge, height: edge, fit: "inside", withoutEnlargement: true }).webp({ quality: WEBP_QUALITY }).toBuffer();
6742
6575
  }
6743
- var READABLE_PREFIXES = [KEY_PREFIX, SCRATCH_PREFIX];
6576
+ var READABLE_PREFIXES = [KEY_PREFIX, SCRATCH_PREFIX, PLUGIN_UI_PREFIX];
6577
+ var MAX_PLUGIN_SVG_BYTES = 1024 * 1024;
6744
6578
  function sanitizeFilename(name) {
6745
6579
  const cleaned = name.replace(/[/\\]/g, "_").replace(/\s+/g, "-").replace(/[^\w.-]/g, "").trim();
6746
6580
  return (cleaned || "file").slice(-100);
@@ -7538,7 +7372,7 @@ function createAdminRouter() {
7538
7372
  }
7539
7373
 
7540
7374
  // ../api/src/dashboard/data-api.ts
7541
- import { existsSync as existsSync18 } from "fs";
7375
+ import { existsSync as existsSync17 } from "fs";
7542
7376
  import sharp4 from "sharp";
7543
7377
 
7544
7378
  // ../api/src/dashboard/automations-routes.ts
@@ -7898,7 +7732,7 @@ function createContinuousChatRouter() {
7898
7732
  }
7899
7733
 
7900
7734
  // ../api/src/dashboard/thread-translate.ts
7901
- import { createHash as createHash3 } from "crypto";
7735
+ import { createHash as createHash4 } from "crypto";
7902
7736
 
7903
7737
  // ../api/src/store/thread-translation-store.ts
7904
7738
  var TABLES = {
@@ -7980,7 +7814,7 @@ function isTranslatableLanguage2(lang) {
7980
7814
  return BY_CODE.has(lang);
7981
7815
  }
7982
7816
  function translationHash(author, body) {
7983
- return createHash3("sha256").update(`${RECIPE_VERSION}
7817
+ return createHash4("sha256").update(`${RECIPE_VERSION}
7984
7818
  ${author}
7985
7819
  ${body}`).digest("hex");
7986
7820
  }
@@ -8092,7 +7926,7 @@ async function translateCached(lang, scope, messages, contextFor) {
8092
7926
  if (!BY_CODE.has(lang)) throw new Error(`unsupported translation language: ${lang}`);
8093
7927
  if (messages.length === 0) return [];
8094
7928
  const keyed = messages.map((m) => ({ ...m, hash: translationHash(m.author, m.body) }));
8095
- const shape = createHash3("sha256").update(keyed.map((m) => `${m.kind}:${m.id}:${m.hash}`).join("\n")).digest("hex");
7929
+ const shape = createHash4("sha256").update(keyed.map((m) => `${m.kind}:${m.id}:${m.hash}`).join("\n")).digest("hex");
8096
7930
  const key = `${lang}:${shape}`;
8097
7931
  const running2 = inFlight.get(key);
8098
7932
  if (running2) return running2;
@@ -8583,11 +8417,28 @@ function createChatRouter(agent = {}) {
8583
8417
  const limit = Number.isFinite(requestedLimit) && requestedLimit > 0 ? Math.min(requestedLimit, BOARD_PAGE_SIZE_MAX) : BOARD_PAGE_SIZE;
8584
8418
  const before = c.req.query("before");
8585
8419
  const meta = c.req.query("scope") === "all" ? await globalChannelMeta(c) : null;
8420
+ const listParam = (name) => (c.req.query(name) ?? "").split(",").filter(Boolean);
8421
+ const channelFilter = new Set(listParam("channel"));
8422
+ const authors = listParam("author").filter((a) => /^[\w.-]+$/.test(a));
8423
+ const instant = (name) => {
8424
+ const raw = c.req.query(name);
8425
+ const ms = raw ? Date.parse(raw) : NaN;
8426
+ return Number.isNaN(ms) ? void 0 : new Date(ms).toISOString();
8427
+ };
8428
+ const since2 = instant("since");
8429
+ const until = instant("until");
8430
+ const cursor = until && (!before || Date.parse(until) < Date.parse(before)) ? until : before;
8431
+ const channelIds = (meta ? [...meta.keys()] : [...ownChannelIds(c)]).filter(
8432
+ (id) => !channelFilter.size || channelFilter.has(id)
8433
+ );
8434
+ if (channelIds.length === 0) return c.json({ threads: [], nextCursor: null });
8586
8435
  const supabase = getSupabaseClient();
8587
- let query = supabase.from("threads").select("*").in("channel_id", meta ? [...meta.keys()] : [...ownChannelIds(c)]);
8436
+ let query = supabase.from("threads").select("*").in("channel_id", channelIds);
8588
8437
  query = column === NO_STATUS_COLUMN ? query.is("board_status", null) : query.eq("board_status", column);
8589
8438
  query = query.is("archived_at", null).order("updated_at", { ascending: false }).limit(limit);
8590
- if (before) query = query.lt("updated_at", before);
8439
+ if (cursor) query = query.lt("updated_at", cursor);
8440
+ if (since2) query = query.gte("updated_at", since2);
8441
+ if (authors.length) query = query.or(authors.map((a) => `author.ilike.${a}`).join(","));
8591
8442
  const { data: threads, error: error2 } = await query;
8592
8443
  if (error2) return c.json({ error: error2.message }, 500);
8593
8444
  if (!threads || threads.length === 0) return c.json({ threads: [], nextCursor: null });
@@ -8761,6 +8612,18 @@ function createChatRouter(agent = {}) {
8761
8612
  nextCursor
8762
8613
  });
8763
8614
  });
8615
+ app.get("/threads/:id/plugin-ui", async (c) => {
8616
+ const id = c.req.param("id");
8617
+ const supabase = getSupabaseClient();
8618
+ const { data: thread } = await supabase.from("threads").select("channel_id").eq("id", id).maybeSingle();
8619
+ const channelId = thread?.channel_id;
8620
+ if (!channelId || !(await globalChannelMeta(c)).has(channelId)) {
8621
+ return c.json({ error: "not found" }, 404);
8622
+ }
8623
+ const { data, error: error2 } = await supabase.from("thread_plugin_ui").select("panes, status, updated_at").eq("thread_id", id).maybeSingle();
8624
+ if (error2) return c.json({ error: error2.message }, 500);
8625
+ return c.json(data ?? { panes: [], status: null, updated_at: null });
8626
+ });
8764
8627
  app.post("/threads/:id/translation/:lang", async (c) => {
8765
8628
  const id = c.req.param("id");
8766
8629
  const lang = canonicalLanguage(c.req.param("lang"));
@@ -10283,7 +10146,7 @@ ${screenshots}` : ""}` }
10283
10146
  }
10284
10147
 
10285
10148
  // ../api/src/dashboard/avatars-routes.ts
10286
- import { createHash as createHash4, randomUUID as randomUUID3 } from "crypto";
10149
+ import { createHash as createHash5, randomUUID as randomUUID3 } from "crypto";
10287
10150
  import { Hono as Hono21 } from "hono";
10288
10151
  import sharp3 from "sharp";
10289
10152
  import { PutObjectCommand as PutObjectCommand3, DeleteObjectCommand as DeleteObjectCommand2 } from "@aws-sdk/client-s3";
@@ -10293,7 +10156,7 @@ var AVATAR_MIME_TYPES = ["image/png", "image/jpeg"];
10293
10156
  var KEY_PREFIX2 = "avatar";
10294
10157
  var GRAVATAR_TIMEOUT_MS = 5e3;
10295
10158
  async function fetchGravatar(email) {
10296
- const hash = createHash4("sha256").update(email.trim().toLowerCase()).digest("hex");
10159
+ const hash = createHash5("sha256").update(email.trim().toLowerCase()).digest("hex");
10297
10160
  const res = await fetch(`https://gravatar.com/avatar/${hash}?s=${AVATAR_SIZE}&d=404`, {
10298
10161
  signal: AbortSignal.timeout(GRAVATAR_TIMEOUT_MS)
10299
10162
  }).catch(() => null);
@@ -11450,7 +11313,7 @@ async function threadRuns(workspace, threadTs) {
11450
11313
  }
11451
11314
 
11452
11315
  // ../api/src/dashboard/usage-report.ts
11453
- import { existsSync as existsSync17 } from "fs";
11316
+ import { existsSync as existsSync16 } from "fs";
11454
11317
  function mergeByLabel(buckets) {
11455
11318
  const merged = /* @__PURE__ */ new Map();
11456
11319
  for (const bucket of buckets) {
@@ -11496,7 +11359,7 @@ function toReport(days, rows, labelChannel) {
11496
11359
  };
11497
11360
  }
11498
11361
  function fromLocalStore(days, labelChannel) {
11499
- const store = existsSync17(paths.DB_FILE) ? getLocalCache().openUsageStore(paths.DB_FILE) : null;
11362
+ const store = existsSync16(paths.DB_FILE) ? getLocalCache().openUsageStore(paths.DB_FILE) : null;
11500
11363
  if (!store) return { ...EMPTY, days };
11501
11364
  const window = days === 0 ? void 0 : days;
11502
11365
  try {
@@ -11538,7 +11401,7 @@ async function buildChannelUsageReport(channelId, days, labelChannel) {
11538
11401
  const { totals, byDay } = await channelUsageForWorkspace(workspace, aliasIds, window);
11539
11402
  return { days, totals: totals.runs > 0 ? totals : null, byDay };
11540
11403
  } catch {
11541
- const store = existsSync17(paths.DB_FILE) ? getLocalCache().openUsageStore(paths.DB_FILE) : null;
11404
+ const store = existsSync16(paths.DB_FILE) ? getLocalCache().openUsageStore(paths.DB_FILE) : null;
11542
11405
  if (!store) return { days, totals: null, byDay: [] };
11543
11406
  try {
11544
11407
  const targetLabel = labelChannel(channelId);
@@ -11571,7 +11434,7 @@ async function buildThreadUsage(threadTs) {
11571
11434
  if (totals.runs === 0) return empty;
11572
11435
  return { ...empty, totals, byModel, contextTokens: contextOf(mainRun) };
11573
11436
  } catch {
11574
- const store = existsSync17(paths.DB_FILE) ? getLocalCache().openUsageStore(paths.DB_FILE) : null;
11437
+ const store = existsSync16(paths.DB_FILE) ? getLocalCache().openUsageStore(paths.DB_FILE) : null;
11575
11438
  if (!store) return empty;
11576
11439
  try {
11577
11440
  const totals = store.threadTotals(threadTs);
@@ -12561,7 +12424,7 @@ function registerDataRoutes(api, agent = {}) {
12561
12424
  runs2.set(name, { lastRun: run4.lastRunAt.toISOString(), lastStatus: run4.lastStatus });
12562
12425
  }
12563
12426
  } catch {
12564
- const runStore = existsSync18(paths.DB_FILE) ? getLocalCache().openAutomationRunStore(paths.DB_FILE) : null;
12427
+ const runStore = existsSync17(paths.DB_FILE) ? getLocalCache().openAutomationRunStore(paths.DB_FILE) : null;
12565
12428
  if (runStore) {
12566
12429
  try {
12567
12430
  for (const run4 of runStore.listLastRuns()) {
@@ -12623,7 +12486,7 @@ function registerDataRoutes(api, agent = {}) {
12623
12486
  const runs2 = (await recentRunsForWorkspace(getProfile(), 200)).map(toResponse4);
12624
12487
  return c.json({ runs: runs2 });
12625
12488
  } catch {
12626
- const runStore = existsSync18(paths.DB_FILE) ? getLocalCache().openAutomationRunStore(paths.DB_FILE) : null;
12489
+ const runStore = existsSync17(paths.DB_FILE) ? getLocalCache().openAutomationRunStore(paths.DB_FILE) : null;
12627
12490
  if (!runStore) return c.json({ runs: [] });
12628
12491
  try {
12629
12492
  const runs2 = runStore.listRuns(200).map(toResponse4);
@@ -12810,7 +12673,7 @@ function registerDataRoutes(api, agent = {}) {
12810
12673
  } catch {
12811
12674
  latest = /* @__PURE__ */ new Map();
12812
12675
  totals = /* @__PURE__ */ new Map();
12813
- const usageStore = existsSync18(paths.DB_FILE) ? getLocalCache().openUsageStore(paths.DB_FILE) : null;
12676
+ const usageStore = existsSync17(paths.DB_FILE) ? getLocalCache().openUsageStore(paths.DB_FILE) : null;
12814
12677
  if (usageStore) {
12815
12678
  try {
12816
12679
  latest = usageStore.latestByThread(threadTsList);
@@ -13076,11 +12939,11 @@ function createDeviceAuthRouter() {
13076
12939
  }
13077
12940
 
13078
12941
  // ../api/src/dashboard/skills-routes.ts
13079
- import { dirname as dirname7 } from "path";
12942
+ import { dirname as dirname6 } from "path";
13080
12943
 
13081
12944
  // ../api/src/dashboard/skill-mirror.ts
13082
- import { createHash as createHash5 } from "crypto";
13083
- import { existsSync as existsSync19, statSync as statSync3 } from "fs";
12945
+ import { createHash as createHash6 } from "crypto";
12946
+ import { existsSync as existsSync18, statSync as statSync3 } from "fs";
13084
12947
  var SYNC_INTERVAL_MS = 6e4;
13085
12948
  var UPSERT_BATCH = 50;
13086
12949
  function mirrorScopeOf(ref) {
@@ -13088,7 +12951,7 @@ function mirrorScopeOf(ref) {
13088
12951
  }
13089
12952
  function isDir(path) {
13090
12953
  try {
13091
- return existsSync19(path) && statSync3(path).isDirectory();
12954
+ return existsSync18(path) && statSync3(path).isDirectory();
13092
12955
  } catch {
13093
12956
  return false;
13094
12957
  }
@@ -13127,7 +12990,7 @@ function snapshot(scopes) {
13127
12990
  return rows;
13128
12991
  }
13129
12992
  function hashOf(row) {
13130
- return createHash5("sha1").update(JSON.stringify([row.description, row.body, row.path, row.plugin, row.mtime])).digest("hex");
12993
+ return createHash6("sha1").update(JSON.stringify([row.description, row.body, row.path, row.plugin, row.mtime])).digest("hex");
13131
12994
  }
13132
12995
  async function pushSkillScopes(scopes) {
13133
12996
  if (!databaseReachable()) return;
@@ -13430,11 +13293,11 @@ function createGatedRouter(agent, register) {
13430
13293
  }
13431
13294
 
13432
13295
  // src/dashboard/host-api.ts
13433
- import { existsSync as existsSync24, readFileSync as readFileSync18, statSync as statSync5 } from "fs";
13296
+ import { existsSync as existsSync23, readFileSync as readFileSync17, statSync as statSync5 } from "fs";
13434
13297
  import sharp5 from "sharp";
13435
13298
 
13436
13299
  // src/dashboard/channels-routes.ts
13437
- import { existsSync as existsSync20, mkdirSync as mkdirSync9 } from "fs";
13300
+ import { existsSync as existsSync19, mkdirSync as mkdirSync8 } from "fs";
13438
13301
  import { Hono as Hono36 } from "hono";
13439
13302
  function coerceAccess(raw) {
13440
13303
  if (raw === "open" || raw === "*" || raw === "all") return raw;
@@ -13480,7 +13343,7 @@ function coerceMemberEmails(raw) {
13480
13343
  function ensureCwdDir(cwd) {
13481
13344
  const expanded = expandPath(cwd);
13482
13345
  if (isLogicalCwd(cwd) || isUnderLogicalRoot(expanded)) return;
13483
- if (!existsSync20(expanded)) mkdirSync9(expanded, { recursive: true });
13346
+ if (!existsSync19(expanded)) mkdirSync8(expanded, { recursive: true });
13484
13347
  }
13485
13348
  function toResponse3(channel) {
13486
13349
  return {
@@ -13634,8 +13497,8 @@ function createChannelWriteRouter() {
13634
13497
  }
13635
13498
 
13636
13499
  // src/dashboard/skills-routes-host.ts
13637
- import { existsSync as existsSync21, statSync as statSync4 } from "fs";
13638
- import { dirname as dirname8 } from "path";
13500
+ import { existsSync as existsSync20, statSync as statSync4 } from "fs";
13501
+ import { dirname as dirname7 } from "path";
13639
13502
  import { Hono as Hono37 } from "hono";
13640
13503
  function workspaceScope() {
13641
13504
  const claudeConfigDir = profileClaudeConfigDir();
@@ -13643,7 +13506,7 @@ function workspaceScope() {
13643
13506
  return {
13644
13507
  dir: workspaceSkillsDir(claudeConfigDir),
13645
13508
  // `~/.claude` itself, which exists wherever the CLI has ever run.
13646
- root: dirname8(workspaceSkillsDir(claudeConfigDir)),
13509
+ root: dirname7(workspaceSkillsDir(claudeConfigDir)),
13647
13510
  cwd,
13648
13511
  claudeConfigDir,
13649
13512
  // Only plugin skills. Project skills belong to a specific channel's cwd, so
@@ -13669,7 +13532,7 @@ function inheritedSkills(scope, own) {
13669
13532
  }
13670
13533
  function rootExists(dir) {
13671
13534
  try {
13672
- return existsSync21(dir) && statSync4(dir).isDirectory();
13535
+ return existsSync20(dir) && statSync4(dir).isDirectory();
13673
13536
  } catch {
13674
13537
  return false;
13675
13538
  }
@@ -13776,9 +13639,9 @@ async function resolveAgentIdentities(viewer) {
13776
13639
 
13777
13640
  // ../api/src/dashboard/providers.ts
13778
13641
  import { execFileSync as execFileSync4 } from "child_process";
13779
- import { existsSync as existsSync22, readFileSync as readFileSync16 } from "fs";
13642
+ import { existsSync as existsSync21, readFileSync as readFileSync15 } from "fs";
13780
13643
  import { homedir as homedir7 } from "os";
13781
- import { join as join14, resolve as resolve5 } from "path";
13644
+ import { join as join13, resolve as resolve5 } from "path";
13782
13645
  var PROVIDER_LABELS = {
13783
13646
  claude: "Claude Code",
13784
13647
  codex: "Codex"
@@ -13799,7 +13662,7 @@ function binaryOnPath(bin) {
13799
13662
  function claudeAuthAvailable() {
13800
13663
  if (profileEnv("CLAUDE_CODE_OAUTH_TOKEN")?.trim()) return true;
13801
13664
  const configDir2 = profileClaudeConfigDir() || resolve5(homedir7(), ".claude");
13802
- if (existsSync22(join14(configDir2, ".credentials.json"))) return true;
13665
+ if (existsSync21(join13(configDir2, ".credentials.json"))) return true;
13803
13666
  if (process.platform !== "darwin") return false;
13804
13667
  try {
13805
13668
  execFileSync4("security", ["find-generic-password", "-s", "Claude Code-credentials"], {
@@ -13843,9 +13706,9 @@ function claudeAccount() {
13843
13706
  }
13844
13707
  }
13845
13708
  function codexAccount() {
13846
- const home2 = process.env["CODEX_HOME"]?.trim() || join14(homedir7(), ".codex");
13709
+ const home2 = process.env["CODEX_HOME"]?.trim() || join13(homedir7(), ".codex");
13847
13710
  try {
13848
- const auth = JSON.parse(readFileSync16(join14(home2, "auth.json"), "utf8"));
13711
+ const auth = JSON.parse(readFileSync15(join13(home2, "auth.json"), "utf8"));
13849
13712
  const payload = auth.tokens?.id_token?.split(".")[1];
13850
13713
  if (!payload) return void 0;
13851
13714
  const claims = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
@@ -13876,9 +13739,9 @@ function providerStatuses() {
13876
13739
  // src/dashboard/provider-login-host.ts
13877
13740
  import { spawn as spawn4 } from "child_process";
13878
13741
  import { randomUUID as randomUUID4 } from "crypto";
13879
- import { chmodSync, existsSync as existsSync23, mkdirSync as mkdirSync10, readFileSync as readFileSync17, writeFileSync as writeFileSync9 } from "fs";
13742
+ import { chmodSync, existsSync as existsSync22, mkdirSync as mkdirSync9, readFileSync as readFileSync16, writeFileSync as writeFileSync8 } from "fs";
13880
13743
  import { createRequire } from "module";
13881
- import { dirname as dirname9, join as join15 } from "path";
13744
+ import { dirname as dirname8, join as join14 } from "path";
13882
13745
  import { Hono as Hono38 } from "hono";
13883
13746
  var SESSION_TTL_MS = 10 * 6e4;
13884
13747
  var URL_WAIT_MS = 3e4;
@@ -13941,10 +13804,10 @@ function waitFor(s, parse, ms) {
13941
13804
  }
13942
13805
  function loadPty() {
13943
13806
  const require2 = createRequire(import.meta.url);
13944
- const root = dirname9(require2.resolve("node-pty/package.json"));
13945
- const helper = join15(root, "prebuilds", `${process.platform}-${process.arch}`, "spawn-helper");
13807
+ const root = dirname8(require2.resolve("node-pty/package.json"));
13808
+ const helper = join14(root, "prebuilds", `${process.platform}-${process.arch}`, "spawn-helper");
13946
13809
  try {
13947
- if (existsSync23(helper)) chmodSync(helper, 493);
13810
+ if (existsSync22(helper)) chmodSync(helper, 493);
13948
13811
  } catch {
13949
13812
  }
13950
13813
  return require2("node-pty");
@@ -13984,9 +13847,9 @@ async function startClaude() {
13984
13847
  return { id, url };
13985
13848
  }
13986
13849
  function saveClaudeToken(configFile, token) {
13987
- mkdirSync10(dirname9(configFile), { recursive: true });
13988
- const current = existsSync23(configFile) ? readFileSync17(configFile, "utf-8") : "";
13989
- writeFileSync9(configFile, upsertEnvLine(current, "CLAUDE_CODE_OAUTH_TOKEN", token), { mode: 384 });
13850
+ mkdirSync9(dirname8(configFile), { recursive: true });
13851
+ const current = existsSync22(configFile) ? readFileSync16(configFile, "utf-8") : "";
13852
+ writeFileSync8(configFile, upsertEnvLine(current, "CLAUDE_CODE_OAUTH_TOKEN", token), { mode: 384 });
13990
13853
  const cached = cachedProfileConfig();
13991
13854
  if (cached) cached.env["CLAUDE_CODE_OAUTH_TOKEN"] = token;
13992
13855
  clearClaudeAuthFailed();
@@ -14209,7 +14072,7 @@ function registerHostRoutes(api) {
14209
14072
  const errors = c.req.query("error") === "true" || c.req.query("error") === "1";
14210
14073
  const limit = Math.min(Number(c.req.query("limit")) || 200, 2e3);
14211
14074
  const file = serviceLogFile(errors);
14212
- const exists = existsSync24(file);
14075
+ const exists = existsSync23(file);
14213
14076
  return c.json({
14214
14077
  file,
14215
14078
  exists,
@@ -14219,8 +14082,8 @@ function registerHostRoutes(api) {
14219
14082
  });
14220
14083
  }
14221
14084
  function tailFile(file, limit) {
14222
- if (!existsSync24(file)) return [];
14223
- const lines = readFileSync18(file, "utf-8").split("\n");
14085
+ if (!existsSync23(file)) return [];
14086
+ const lines = readFileSync17(file, "utf-8").split("\n");
14224
14087
  if (lines.at(-1) === "") lines.pop();
14225
14088
  return lines.slice(-limit);
14226
14089
  }
@@ -14238,21 +14101,21 @@ function createHostApiRouter(agent = {}) {
14238
14101
 
14239
14102
  // src/dashboard/agent-bridge-host.ts
14240
14103
  import { sign as signRaw, timingSafeEqual } from "crypto";
14241
- import { existsSync as existsSync26, readFileSync as readFileSync21 } from "fs";
14104
+ import { existsSync as existsSync25, readFileSync as readFileSync20 } from "fs";
14242
14105
  import dotenv2 from "dotenv";
14243
14106
  import { WebSocket as WebSocket2 } from "ws";
14244
14107
 
14245
14108
  // src/dashboard/session-import-host.ts
14246
14109
  import {
14247
14110
  closeSync as closeSync2,
14248
- existsSync as existsSync25,
14111
+ existsSync as existsSync24,
14249
14112
  openSync as openSync2,
14250
14113
  readdirSync as readdirSync4,
14251
- readFileSync as readFileSync19,
14114
+ readFileSync as readFileSync18,
14252
14115
  readSync as readSync2,
14253
14116
  realpathSync as realpathSync4
14254
14117
  } from "fs";
14255
- import { basename as basename6, join as join16, resolve as resolve6 } from "path";
14118
+ import { basename as basename6, join as join15, resolve as resolve6 } from "path";
14256
14119
  var MAX_AGE_MS = 30 * 24 * 60 * 60 * 1e3;
14257
14120
  var HEAD_BYTES = 64 * 1024;
14258
14121
  var TITLE_MAX = 80;
@@ -14293,7 +14156,7 @@ function blocksText(content, kinds) {
14293
14156
  return parts.length ? cleanText2(parts.join("\n\n")) : null;
14294
14157
  }
14295
14158
  function boundSessionIds() {
14296
- if (!existsSync25(paths.DB_FILE)) return /* @__PURE__ */ new Set();
14159
+ if (!existsSync24(paths.DB_FILE)) return /* @__PURE__ */ new Set();
14297
14160
  const store = new SessionStore(paths.DB_FILE);
14298
14161
  try {
14299
14162
  return new Set(store.listSessions().map((s) => s.sessionId));
@@ -14394,14 +14257,14 @@ function scanSessionFolders(slug) {
14394
14257
  ]);
14395
14258
  };
14396
14259
  if (agents.has("claude")) {
14397
- const root = join16(claudeDir(), "projects");
14260
+ const root = join15(claudeDir(), "projects");
14398
14261
  let dirs = [];
14399
14262
  try {
14400
14263
  dirs = readdirSync4(root, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name);
14401
14264
  } catch {
14402
14265
  }
14403
14266
  for (const dir of dirs) {
14404
- const files = jsonlFiles(join16(root, dir), 0).filter((f) => f.mtime >= since2);
14267
+ const files = jsonlFiles(join15(root, dir), 0).filter((f) => f.mtime >= since2);
14405
14268
  let cwd = null;
14406
14269
  for (const f of files) {
14407
14270
  cwd ??= cwdFromTranscript(f.file);
@@ -14415,7 +14278,7 @@ function scanSessionFolders(slug) {
14415
14278
  }
14416
14279
  }
14417
14280
  if (agents.has("codex")) {
14418
- for (const f of jsonlFiles(join16(codexDir(), "sessions"), 4)) {
14281
+ for (const f of jsonlFiles(join15(codexDir(), "sessions"), 4)) {
14419
14282
  if (f.mtime < since2) continue;
14420
14283
  const s = codexSummary(f.file, f.mtime);
14421
14284
  if (s) add(s.cwd, s.session);
@@ -14442,22 +14305,22 @@ function scanSessionFolders(slug) {
14442
14305
  function findTranscript(agent, sessionId) {
14443
14306
  if (!/^[A-Za-z0-9-]+$/.test(sessionId)) return null;
14444
14307
  if (agent === "claude") {
14445
- const root = join16(claudeDir(), "projects");
14308
+ const root = join15(claudeDir(), "projects");
14446
14309
  try {
14447
14310
  for (const e of readdirSync4(root, { withFileTypes: true })) {
14448
- const file = join16(root, e.name, `${sessionId}.jsonl`);
14449
- if (e.isDirectory() && existsSync25(file)) return file;
14311
+ const file = join15(root, e.name, `${sessionId}.jsonl`);
14312
+ if (e.isDirectory() && existsSync24(file)) return file;
14450
14313
  }
14451
14314
  } catch {
14452
14315
  }
14453
14316
  return null;
14454
14317
  }
14455
- return jsonlFiles(join16(codexDir(), "sessions"), 4).find((f) => f.file.endsWith(`${sessionId}.jsonl`))?.file ?? null;
14318
+ return jsonlFiles(join15(codexDir(), "sessions"), 4).find((f) => f.file.endsWith(`${sessionId}.jsonl`))?.file ?? null;
14456
14319
  }
14457
14320
  function readSessionMessages(agent, sessionId, afterUuid) {
14458
14321
  const file = findTranscript(agent, sessionId);
14459
14322
  if (!file) return null;
14460
- const lines = parseLines(readFileSync19(file, "utf-8"));
14323
+ const lines = parseLines(readFileSync18(file, "utf-8"));
14461
14324
  const messages = agent === "claude" ? claudeMessages(lines) : codexMessages(lines);
14462
14325
  if (!afterUuid) return messages;
14463
14326
  const idx = messages.findIndex((m) => m.uuid === afterUuid);
@@ -14514,7 +14377,7 @@ async function handleHostRequest(req) {
14514
14377
  }
14515
14378
 
14516
14379
  // src/dashboard/doc-share-publisher.ts
14517
- import { readFileSync as readFileSync20, statSync as statSync6 } from "fs";
14380
+ import { readFileSync as readFileSync19, statSync as statSync6 } from "fs";
14518
14381
  import { extname, posix } from "path";
14519
14382
  var MAX_ASSET_BYTES = 20 * 1024 * 1024;
14520
14383
  var MAX_CONTENT_BYTES = 2 * 1024 * 1024;
@@ -14629,7 +14492,7 @@ function readDocShareBundle({ cwd, sourcePath }) {
14629
14492
  }
14630
14493
  if (!stat.isFile()) return { status: "not-found" };
14631
14494
  if (stat.size > MAX_CONTENT_BYTES) return { status: "too-large" };
14632
- const source = readFileSync20(abs, "utf8");
14495
+ const source = readFileSync19(abs, "utf8");
14633
14496
  const title = extractTitle(abs, kind === "markdown" ? "md" : kind);
14634
14497
  if (kind === "excalidraw") {
14635
14498
  try {
@@ -14700,7 +14563,7 @@ function readDocShareBundle({ cwd, sourcePath }) {
14700
14563
  let text = null;
14701
14564
  try {
14702
14565
  const size = statSync6(docAbs).size;
14703
- if (size <= budget) text = readFileSync20(docAbs, "utf8");
14566
+ if (size <= budget) text = readFileSync19(docAbs, "utf8");
14704
14567
  } catch {
14705
14568
  continue;
14706
14569
  }
@@ -14717,7 +14580,7 @@ function readDocShareBundle({ cwd, sourcePath }) {
14717
14580
  let body;
14718
14581
  try {
14719
14582
  if (statSync6(resolved.abs).size > MAX_ASSET_BYTES) continue;
14720
- body = readFileSync20(resolved.abs);
14583
+ body = readFileSync19(resolved.abs);
14721
14584
  } catch {
14722
14585
  continue;
14723
14586
  }
@@ -14745,13 +14608,13 @@ function readDocShareBundle({ cwd, sourcePath }) {
14745
14608
 
14746
14609
  // src/dashboard/host-upgrade.ts
14747
14610
  import { spawn as spawn5 } from "child_process";
14748
- import { mkdirSync as mkdirSync11, openSync as openSync3 } from "fs";
14749
- import { join as join17 } from "path";
14611
+ import { mkdirSync as mkdirSync10, openSync as openSync3 } from "fs";
14612
+ import { join as join16 } from "path";
14750
14613
  var running = false;
14751
14614
  function startHostUpgrade() {
14752
14615
  if (running) return { started: false };
14753
- mkdirSync11(paths.LOG_DIR, { recursive: true });
14754
- const log5 = openSync3(join17(paths.LOG_DIR, "host-upgrade.log"), "a");
14616
+ mkdirSync10(paths.LOG_DIR, { recursive: true });
14617
+ const log5 = openSync3(join16(paths.LOG_DIR, "host-upgrade.log"), "a");
14755
14618
  const child = spawn5(process.execPath, [process.argv[1] ?? "", "upgrade"], {
14756
14619
  detached: true,
14757
14620
  stdio: ["ignore", log5, log5]
@@ -14844,7 +14707,7 @@ function dataSocketUrl() {
14844
14707
  return `ws://127.0.0.1:${process.env["FLYSPACE_DATA_API_PORT"] ?? DEFAULT_DATA_API_PORT}${HOST_SOCKET_PATH}`;
14845
14708
  }
14846
14709
  function listLocalSessions() {
14847
- if (!existsSync26(paths.DB_FILE)) return [];
14710
+ if (!existsSync25(paths.DB_FILE)) return [];
14848
14711
  const store = new SessionStore(paths.DB_FILE);
14849
14712
  try {
14850
14713
  return store.listSessions();
@@ -14896,10 +14759,10 @@ function buildHostConfigSnapshot() {
14896
14759
  const snapshot2 = {};
14897
14760
  for (const profile of listProfiles()) {
14898
14761
  snapshot2[profile] = runWithProfile(profile, () => ({
14899
- env: existsSync26(paths.CONFIG_FILE) ? dotenv2.parse(readFileSync21(paths.CONFIG_FILE, "utf-8")) : {},
14762
+ env: existsSync25(paths.CONFIG_FILE) ? dotenv2.parse(readFileSync20(paths.CONFIG_FILE, "utf-8")) : {},
14900
14763
  // Only a model someone actually saved: before that it is just the Claude
14901
14764
  // default, which would show the wrong agent in admin for a Codex user.
14902
- agentModel: existsSync26(paths.DASHBOARD_SETTINGS_FILE) ? loadDashboardSettings().agent : void 0
14765
+ agentModel: existsSync25(paths.DASHBOARD_SETTINGS_FILE) ? loadDashboardSettings().agent : void 0
14903
14766
  }));
14904
14767
  }
14905
14768
  return snapshot2;
@@ -14982,6 +14845,10 @@ function connectHostSocket(url, callbacks, onAuthenticated, onWorkspaces) {
14982
14845
  handleHostDbResult(msg.id, msg.res);
14983
14846
  return;
14984
14847
  }
14848
+ if (msg.type === "plugin-svg-result") {
14849
+ handlePluginSvgResult(msg.id, msg.url);
14850
+ return;
14851
+ }
14985
14852
  if (msg.type === "attachment-url-result") {
14986
14853
  handleAttachmentUrlResult(msg.id, msg.url);
14987
14854
  return;
@@ -15084,8 +14951,8 @@ function send(ws, msg) {
15084
14951
  }
15085
14952
 
15086
14953
  // src/dashboard/machine-server.ts
15087
- import { existsSync as existsSync27 } from "fs";
15088
- import { join as join18 } from "path";
14954
+ import { existsSync as existsSync26 } from "fs";
14955
+ import { join as join17 } from "path";
15089
14956
  import { serveStatic } from "@hono/node-server/serve-static";
15090
14957
 
15091
14958
  // ../api/src/dashboard/app-icon-routes.ts
@@ -15162,7 +15029,7 @@ function pngResponse(c, png) {
15162
15029
  }
15163
15030
 
15164
15031
  // src/dashboard/machine-server.ts
15165
- var WEB_DIST = join18(paths.WEB_ROOT, "dist");
15032
+ var WEB_DIST = join17(paths.WEB_ROOT, "dist");
15166
15033
  async function bootMachine() {
15167
15034
  await reconcileAll().catch(
15168
15035
  (err) => console.error("[dashboard] reconcileAll failed:", err.message)
@@ -15182,14 +15049,14 @@ async function bootMachine() {
15182
15049
  function mountSpa(app) {
15183
15050
  app.route("/share", createPublicShareAssetRouter(WEB_DIST));
15184
15051
  app.route("/", createAppIconRouter());
15185
- if (existsSync27(WEB_DIST) || existsSync27(join18(paths.WEB_ROOT, "package.json"))) {
15052
+ if (existsSync26(WEB_DIST) || existsSync26(join17(paths.WEB_ROOT, "package.json"))) {
15186
15053
  app.use("/*", serveStatic({ root: WEB_DIST }));
15187
15054
  }
15188
15055
  app.get("/assets/*", (c) => c.text("stale asset \u2014 reload for the current build", 404));
15189
- const spaFallback = serveStatic({ path: join18(WEB_DIST, "index.html") });
15056
+ const spaFallback = serveStatic({ path: join17(WEB_DIST, "index.html") });
15190
15057
  app.get("*", async (c, next) => {
15191
- if (!existsSync27(join18(WEB_DIST, "index.html"))) {
15192
- const isCheckout = existsSync27(join18(paths.WEB_ROOT, "package.json"));
15058
+ if (!existsSync26(join17(WEB_DIST, "index.html"))) {
15059
+ const isCheckout = existsSync26(join17(paths.WEB_ROOT, "package.json"));
15193
15060
  return c.text(
15194
15061
  isCheckout ? `Workspace UI build missing (${WEB_DIST}).
15195
15062
  Run \`pnpm build:web\` from the repo root.
@@ -15202,8 +15069,8 @@ The JSON API is live under /api.` : "This install has no bundled Workspace UI.\n
15202
15069
  }
15203
15070
 
15204
15071
  // src/dashboard/host-log-file.ts
15205
- import { createWriteStream, fstatSync, mkdirSync as mkdirSync12, statSync as statSync7 } from "fs";
15206
- import { join as join19 } from "path";
15072
+ import { createWriteStream, fstatSync, mkdirSync as mkdirSync11, statSync as statSync7 } from "fs";
15073
+ import { join as join18 } from "path";
15207
15074
  var STAMPED = /^\[\d{4}-\d{2}-\d{2}T/;
15208
15075
  function stamp(text) {
15209
15076
  const ts2 = (/* @__PURE__ */ new Date()).toISOString();
@@ -15232,12 +15099,12 @@ function tee(stream, fd, file) {
15232
15099
  }
15233
15100
  function ensureHostLogFiles() {
15234
15101
  try {
15235
- mkdirSync12(paths.LOG_DIR, { recursive: true });
15102
+ mkdirSync11(paths.LOG_DIR, { recursive: true });
15236
15103
  } catch {
15237
15104
  return;
15238
15105
  }
15239
- tee(process.stdout, 1, join19(paths.LOG_DIR, "host.log"));
15240
- tee(process.stderr, 2, join19(paths.LOG_DIR, "host-error.log"));
15106
+ tee(process.stdout, 1, join18(paths.LOG_DIR, "host.log"));
15107
+ tee(process.stderr, 2, join18(paths.LOG_DIR, "host-error.log"));
15241
15108
  }
15242
15109
 
15243
15110
  // src/dashboard/host-dashboard.ts
@@ -15363,8 +15230,8 @@ function openBrowser2(url) {
15363
15230
  }
15364
15231
  }
15365
15232
  function ensureWebBuild() {
15366
- if (existsSync28(join20(paths.WEB_ROOT, "dist", "index.html"))) return;
15367
- if (!existsSync28(join20(paths.WEB_ROOT, "package.json"))) return;
15233
+ if (existsSync27(join19(paths.WEB_ROOT, "dist", "index.html"))) return;
15234
+ if (!existsSync27(join19(paths.WEB_ROOT, "package.json"))) return;
15368
15235
  console.log(" packages/ui/dist missing, building the dashboard UI...");
15369
15236
  const result = spawnSync("pnpm", ["build"], {
15370
15237
  cwd: paths.WEB_ROOT,
@@ -15414,7 +15281,7 @@ async function runDashboard(args) {
15414
15281
  }
15415
15282
 
15416
15283
  // src/commands/workspace.ts
15417
- import { existsSync as existsSync29, mkdirSync as mkdirSync13, writeFileSync as writeFileSync10 } from "fs";
15284
+ import { existsSync as existsSync28, mkdirSync as mkdirSync12, writeFileSync as writeFileSync9 } from "fs";
15418
15285
  var USAGE7 = `
15419
15286
  Usage: flyspace workspace <subcommand> [options]
15420
15287
 
@@ -15500,10 +15367,10 @@ function provisionLocal(botName) {
15500
15367
  ensureDirs();
15501
15368
  console.log(` config dir ready (${paths.CONFIG_DIR})`);
15502
15369
  console.log(` data dir ready (${paths.DATA_DIR})`);
15503
- if (existsSync29(paths.CONFIG_FILE)) {
15370
+ if (existsSync28(paths.CONFIG_FILE)) {
15504
15371
  console.log(" config.env exists");
15505
15372
  } else {
15506
- writeFileSync10(paths.CONFIG_FILE, `BOT_NAME=${botName}
15373
+ writeFileSync9(paths.CONFIG_FILE, `BOT_NAME=${botName}
15507
15374
  `);
15508
15375
  console.log(` config.env written (${paths.CONFIG_FILE})`);
15509
15376
  }
@@ -15522,8 +15389,8 @@ async function provisionChannels(specs) {
15522
15389
  continue;
15523
15390
  }
15524
15391
  const cwd = expandPath(spec.cwd);
15525
- if (!existsSync29(cwd)) {
15526
- mkdirSync13(cwd, { recursive: true });
15392
+ if (!existsSync28(cwd)) {
15393
+ mkdirSync12(cwd, { recursive: true });
15527
15394
  console.log(` created cwd ${cwd}`);
15528
15395
  }
15529
15396
  await createChannel({ name: spec.name, cwd, position: index });
@@ -15623,79 +15490,16 @@ async function runDesktopCmd(args) {
15623
15490
  if (result.status !== 0) process.exit(result.status ?? 1);
15624
15491
  }
15625
15492
 
15626
- // src/commands/persona.ts
15627
- import { existsSync as existsSync30, readdirSync as readdirSync5, readFileSync as readFileSync22 } from "fs";
15628
- import { homedir as homedir9 } from "os";
15629
- import { basename as basename7, join as join21 } from "path";
15630
- import sharp6 from "sharp";
15631
- var USAGE10 = `
15632
- Usage: flyspace persona avatars [--character <id>] [--clear]
15633
-
15634
- Use a claudecafe persona-panel character's faces (claudecafe.dev) as the
15635
- workspace bot's avatars: a reply ending in her mood marker shows the matching
15636
- face, and "neutral" becomes the bot's default avatar.
15637
-
15638
- --character <id> Character folder under ~/.config/claudecafe/characters
15639
- (default: "character" in its config.json, else kotone)
15640
- --clear Remove the per-expression avatars
15641
- `;
15642
- var AVATAR_SIZE2 = 96;
15643
- function cafeRoot() {
15644
- return join21(process.env["XDG_CONFIG_HOME"] || join21(homedir9(), ".config"), "claudecafe");
15645
- }
15646
- function configuredCharacter(root) {
15647
- try {
15648
- const config = JSON.parse(readFileSync22(join21(root, "config.json"), "utf8"));
15649
- if (config.character && config.character !== "none") return config.character;
15650
- } catch {
15651
- }
15652
- return "kotone";
15653
- }
15654
- async function runPersonaCmd(args) {
15655
- if (args[0] !== "avatars") {
15656
- console.log(USAGE10);
15657
- return;
15658
- }
15659
- loadEnvFiles();
15660
- useHostDbWithoutCredentials();
15661
- const profile = getProfile();
15662
- if (args.includes("--clear")) {
15663
- await upsertWorkspaceBranding(profile, { botExpressionAvatars: null });
15664
- console.log("Cleared the per-expression bot avatars.");
15665
- return;
15666
- }
15667
- const root = cafeRoot();
15668
- const idx = args.indexOf("--character");
15669
- const character = idx !== -1 && args[idx + 1] || configuredCharacter(root);
15670
- const dir = join21(root, "characters", character, "avatars");
15671
- if (!existsSync30(dir)) {
15672
- throw new Error(
15673
- `No avatars at ${dir}. Open a Claude Code desktop session with persona-panel once so it installs the pack, or pass --character.`
15674
- );
15675
- }
15676
- const avatars = {};
15677
- for (const file of readdirSync5(dir).filter((f) => f.endsWith(".webp"))) {
15678
- const image = await sharp6(join21(dir, file)).resize({ width: AVATAR_SIZE2, height: AVATAR_SIZE2, fit: "cover", position: "top" }).webp({ quality: 80 }).toBuffer();
15679
- avatars[basename7(file, ".webp")] = `data:image/webp;base64,${image.toString("base64")}`;
15680
- }
15681
- if (!Object.keys(avatars).length) throw new Error(`No .webp avatars in ${dir}.`);
15682
- await upsertWorkspaceBranding(profile, {
15683
- botExpressionAvatars: avatars,
15684
- ...avatars["neutral"] ? { botAvatar: avatars["neutral"] } : {}
15685
- });
15686
- console.log(`Saved ${Object.keys(avatars).length} ${character} avatars: ${Object.keys(avatars).sort().join(", ")}`);
15687
- }
15688
-
15689
15493
  // src/cli.ts
15690
- import { join as join22 } from "path";
15494
+ import { join as join20 } from "path";
15691
15495
  var home = flyspaceHome();
15692
15496
  if (home) {
15693
- const bin = join22(home, "bin");
15497
+ const bin = join20(home, "bin");
15694
15498
  const path = process.env.PATH ?? "";
15695
15499
  if (!path.split(":").includes(bin)) process.env.PATH = path ? `${bin}:${path}` : bin;
15696
15500
  }
15697
15501
  var XERO_USAGE = false ? " xero Connect to Xero and expose it as an MCP server\n" : "";
15698
- var USAGE11 = `
15502
+ var USAGE10 = `
15699
15503
  Usage: flyspace <command> [options]
15700
15504
 
15701
15505
  Commands:
@@ -15836,12 +15640,12 @@ async function main() {
15836
15640
  break;
15837
15641
  case "-v":
15838
15642
  case "--version":
15839
- printRaw("0.1.57");
15643
+ printRaw("0.1.59");
15840
15644
  break;
15841
15645
  case "-h":
15842
15646
  case "--help":
15843
15647
  case void 0:
15844
- printRaw(USAGE11);
15648
+ printRaw(USAGE10);
15845
15649
  break;
15846
15650
  case "xero":
15847
15651
  if (false) {
@@ -15852,7 +15656,7 @@ async function main() {
15852
15656
  // falls through
15853
15657
  default:
15854
15658
  printRaw(`Unknown command: ${command}`);
15855
- printRaw(USAGE11);
15659
+ printRaw(USAGE10);
15856
15660
  process.exit(1);
15857
15661
  }
15858
15662
  }