flyspace-cli 0.1.16 → 0.1.19

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.
@@ -2,6 +2,7 @@
2
2
  import {
3
3
  AGENT_AUTHOR,
4
4
  SYNCED_BOT_AUTHOR,
5
+ databaseReachable,
5
6
  ensureDirs,
6
7
  getProfile,
7
8
  getR2Bucket,
@@ -10,19 +11,20 @@ import {
10
11
  paths,
11
12
  postToDashboardChannel,
12
13
  runWithProfile,
14
+ setSupabaseClientFactory,
13
15
  sweepScratchDir,
14
16
  syncPostToDashboard
15
- } from "./chunk-ZBMYF5LX.js";
17
+ } from "./chunk-GYHCSGMJ.js";
16
18
 
17
19
  // src/index.ts
18
20
  import { execFile, spawn as spawn4 } from "child_process";
19
21
 
20
- // src/config.ts
22
+ // ../api/src/config.ts
21
23
  import dotenv from "dotenv";
22
24
  import { existsSync } from "fs";
23
25
  import { resolve } from "path";
24
26
 
25
- // src/effort.ts
27
+ // ../api/src/effort.ts
26
28
  var EFFORT_LEVELS = ["low", "medium", "high", "max"];
27
29
  function isEffort(value) {
28
30
  return EFFORT_LEVELS.includes(value);
@@ -46,7 +48,7 @@ function resolveCodexEffort(effort) {
46
48
  return CODEX_EFFORT[effort];
47
49
  }
48
50
 
49
- // src/config.ts
51
+ // ../api/src/config.ts
50
52
  var DEFAULT_CODEX_MODEL = "";
51
53
  function mcpStrictConfigEnabled() {
52
54
  return process.env["MCP_STRICT_CONFIG"]?.trim() === "true";
@@ -120,7 +122,7 @@ function loadConfig() {
120
122
  };
121
123
  }
122
124
 
123
- // src/automations/store.ts
125
+ // ../api/src/automations/store.ts
124
126
  function toAutomationType(kind) {
125
127
  return kind === "mention-trigger" ? "mention_trigger" : kind;
126
128
  }
@@ -262,7 +264,7 @@ function stopAutomationRegistryPolling() {
262
264
  }
263
265
  }
264
266
 
265
- // src/channels.ts
267
+ // ../api/src/channels.ts
266
268
  import { existsSync as existsSync2, mkdirSync, realpathSync, statSync } from "fs";
267
269
  import { homedir } from "os";
268
270
  import { isAbsolute, resolve as resolve2, sep } from "path";
@@ -709,27 +711,12 @@ async function ensureMemberDmChannel(a, b) {
709
711
  }
710
712
  }
711
713
 
712
- // src/automations/config.ts
713
- import { readFileSync, existsSync as existsSync3 } from "fs";
714
- import yaml from "js-yaml";
714
+ // ../api/src/automations/config.ts
715
715
  import cron from "node-cron";
716
716
  var DEFAULT_TIMEZONE = "Australia/Sydney";
717
- var EMPTY_CONFIG = { schedules: [], triggers: [], mention_triggers: [] };
718
717
  function loadAutomations() {
719
718
  return getStoredAutomations();
720
719
  }
721
- function loadAutomationsFile() {
722
- const filePath = paths.AUTOMATIONS_FILE;
723
- if (!existsSync3(filePath)) return { ...EMPTY_CONFIG };
724
- const raw = readFileSync(filePath, "utf-8");
725
- if (!raw.trim()) return { ...EMPTY_CONFIG };
726
- const parsed = yaml.load(raw);
727
- return {
728
- schedules: parsed?.schedules ?? [],
729
- triggers: parsed?.triggers ?? [],
730
- mention_triggers: parsed?.mention_triggers ?? []
731
- };
732
- }
733
720
  function validateSchedule(s, opts = {}) {
734
721
  const errors = [];
735
722
  if (!s.name) errors.push("name is required");
@@ -811,7 +798,7 @@ function loadEffectiveAutomations() {
811
798
 
812
799
  // src/claude/agent.ts
813
800
  import { spawn } from "child_process";
814
- import { existsSync as existsSync8, readFileSync as readFileSync3, statSync as statSync3 } from "fs";
801
+ import { existsSync as existsSync7, readFileSync as readFileSync2, statSync as statSync3 } from "fs";
815
802
  import { resolve as resolve4, resolve as resolvePath } from "path";
816
803
  import { homedir as homedir3 } from "os";
817
804
  import { randomUUID } from "crypto";
@@ -819,11 +806,11 @@ import { randomUUID } from "crypto";
819
806
  // src/claude/container.ts
820
807
  import { execFileSync } from "child_process";
821
808
  import { createHash } from "crypto";
822
- import { existsSync as existsSync5, mkdirSync as mkdirSync3 } from "fs";
809
+ import { existsSync as existsSync4, mkdirSync as mkdirSync3 } from "fs";
823
810
  import { join as join2 } from "path";
824
811
 
825
812
  // src/claude/mounts.ts
826
- import { existsSync as existsSync4, lstatSync, mkdirSync as mkdirSync2, readlinkSync, symlinkSync, unlinkSync } from "fs";
813
+ import { existsSync as existsSync3, lstatSync, mkdirSync as mkdirSync2, readlinkSync, symlinkSync, unlinkSync } from "fs";
827
814
  import { basename, join } from "path";
828
815
  var MOUNTS_DIR = "mounts";
829
816
  function resolveMounts(paths2) {
@@ -852,7 +839,7 @@ function materialiseMountLinks(cwd, mounts) {
852
839
  for (const repo of mounts) {
853
840
  const link = join(root, repo.name);
854
841
  try {
855
- if (existsSync4(link) || isBrokenSymlink(link)) {
842
+ if (existsSync3(link) || isBrokenSymlink(link)) {
856
843
  if (!lstatSync(link).isSymbolicLink()) {
857
844
  problems.push(`${link} exists and is not a symlink \u2014 leaving it alone`);
858
845
  continue;
@@ -942,7 +929,7 @@ function rewriteArgsForContainer(args) {
942
929
  function buildContainerSpawn(input) {
943
930
  const home = containerHomeFor(input.cwd);
944
931
  for (const dir of [home, paths.SCRATCH_DIR]) {
945
- if (!existsSync5(dir)) mkdirSync3(dir, { recursive: true });
932
+ if (!existsSync4(dir)) mkdirSync3(dir, { recursive: true });
946
933
  }
947
934
  const containerName = `flyspace-agent-${input.runId}`;
948
935
  const env = buildContainerEnv(input.hostEnv);
@@ -1039,7 +1026,7 @@ function userFlags() {
1039
1026
  // src/claude/sandbox.ts
1040
1027
  import { execFileSync as execFileSync2 } from "child_process";
1041
1028
  import { createHash as createHash2 } from "crypto";
1042
- import { existsSync as existsSync6, mkdirSync as mkdirSync4, writeFileSync } from "fs";
1029
+ import { existsSync as existsSync5, mkdirSync as mkdirSync4, writeFileSync } from "fs";
1043
1030
  import { join as join3 } from "path";
1044
1031
  function sandboxRuntimeEntrypoint() {
1045
1032
  return join3(paths.PACKAGE_ROOT, "node_modules/@anthropic-ai/sandbox-runtime/dist/cli.js");
@@ -1052,7 +1039,7 @@ function sandboxHomeFor(cwd) {
1052
1039
  function buildSandboxSpawn(input) {
1053
1040
  const home = sandboxHomeFor(input.cwd);
1054
1041
  for (const dir of [home, paths.SCRATCH_DIR]) {
1055
- if (!existsSync6(dir)) mkdirSync4(dir, { recursive: true });
1042
+ if (!existsSync5(dir)) mkdirSync4(dir, { recursive: true });
1056
1043
  }
1057
1044
  const claudeBin = process.env["FLYSPACE_CLAUDE_BIN"]?.trim() || execFileSync2("which", ["claude"]).toString().trim();
1058
1045
  const allowRead = [input.cwd, home, paths.SCRATCH_DIR, join3(paths.PACKAGE_ROOT, "node_modules")];
@@ -1097,7 +1084,7 @@ function buildSandboxSpawn(input) {
1097
1084
  };
1098
1085
  }
1099
1086
  function sandboxRuntimeStatus() {
1100
- if (existsSync6(sandboxRuntimeEntrypoint())) return { ok: true };
1087
+ if (existsSync5(sandboxRuntimeEntrypoint())) return { ok: true };
1101
1088
  return {
1102
1089
  ok: false,
1103
1090
  message: `This channel runs its agent in a sandbox, but \`@anthropic-ai/sandbox-runtime\` is not installed.
@@ -1113,7 +1100,7 @@ function resolveModelAlias(model) {
1113
1100
  return MODEL_ALIASES[model.toLowerCase()] ?? model;
1114
1101
  }
1115
1102
 
1116
- // src/utils/mise-env.ts
1103
+ // ../api/src/utils/mise-env.ts
1117
1104
  import { execFileSync as execFileSync3 } from "child_process";
1118
1105
  function resolveMiseEnv(cwd) {
1119
1106
  try {
@@ -1130,8 +1117,8 @@ function resolveMiseEnv(cwd) {
1130
1117
  }
1131
1118
  }
1132
1119
 
1133
- // src/store/output-styles-store.ts
1134
- import { existsSync as existsSync7, mkdirSync as mkdirSync5, readdirSync, readFileSync as readFileSync2, renameSync, rmSync, statSync as statSync2, writeFileSync as writeFileSync2 } from "fs";
1120
+ // ../api/src/store/output-styles-store.ts
1121
+ import { existsSync as existsSync6, mkdirSync as mkdirSync5, readdirSync, readFileSync, renameSync, rmSync, statSync as statSync2, writeFileSync as writeFileSync2 } from "fs";
1135
1122
  import { homedir as homedir2 } from "os";
1136
1123
  import { join as join4, resolve as resolve3, sep as sep2 } from "path";
1137
1124
  var BUILT_IN_OUTPUT_STYLES = [
@@ -1203,9 +1190,9 @@ function atomicWrite(file, content) {
1203
1190
  }
1204
1191
  function readStyle(claudeConfigDir, id) {
1205
1192
  const file = styleFile(claudeConfigDir, id);
1206
- if (!file || !existsSync7(file)) return null;
1193
+ if (!file || !existsSync6(file)) return null;
1207
1194
  const stat = statSync2(file);
1208
- const p = parseStyle(readFileSync2(file, "utf8"), id);
1195
+ const p = parseStyle(readFileSync(file, "utf8"), id);
1209
1196
  return {
1210
1197
  id,
1211
1198
  name: p.name,
@@ -1217,7 +1204,7 @@ function readStyle(claudeConfigDir, id) {
1217
1204
  }
1218
1205
  function listOutputStyles(claudeConfigDir) {
1219
1206
  const dir = stylesDir(claudeConfigDir);
1220
- if (!existsSync7(dir)) return [];
1207
+ if (!existsSync6(dir)) return [];
1221
1208
  return readdirSync(dir).filter((f) => f.endsWith(".md")).map((f) => readStyle(claudeConfigDir, f.slice(0, -3))).filter((s) => !!s).sort((a, b) => a.name.localeCompare(b.name));
1222
1209
  }
1223
1210
  function assertNameFree(claudeConfigDir, name, exceptId) {
@@ -1230,7 +1217,7 @@ function createOutputStyle(claudeConfigDir, params) {
1230
1217
  if (!id) throw new Error("name must contain letters or digits");
1231
1218
  assertNameFree(claudeConfigDir, params.name);
1232
1219
  const file = styleFile(claudeConfigDir, id);
1233
- if (existsSync7(file) || BUILT_IN_OUTPUT_STYLES.some((s) => s.slug === id)) {
1220
+ if (existsSync6(file) || BUILT_IN_OUTPUT_STYLES.some((s) => s.slug === id)) {
1234
1221
  throw new OutputStyleConflictError(`an output style named "${params.name}" already exists`);
1235
1222
  }
1236
1223
  atomicWrite(file, serialize({ ...params, extra: [] }));
@@ -1238,8 +1225,8 @@ function createOutputStyle(claudeConfigDir, params) {
1238
1225
  }
1239
1226
  function updateOutputStyle(claudeConfigDir, id, patch) {
1240
1227
  const file = styleFile(claudeConfigDir, id);
1241
- if (!file || !existsSync7(file)) return null;
1242
- const current = parseStyle(readFileSync2(file, "utf8"), id);
1228
+ if (!file || !existsSync6(file)) return null;
1229
+ const current = parseStyle(readFileSync(file, "utf8"), id);
1243
1230
  if (patch.name !== void 0 && patch.name !== current.name) assertNameFree(claudeConfigDir, patch.name, id);
1244
1231
  const next = { ...current, ...patch };
1245
1232
  atomicWrite(file, serialize(next));
@@ -1250,8 +1237,8 @@ function updateOutputStyle(claudeConfigDir, id, patch) {
1250
1237
  }
1251
1238
  function deleteOutputStyle(claudeConfigDir, id) {
1252
1239
  const file = styleFile(claudeConfigDir, id);
1253
- if (!file || !existsSync7(file)) return false;
1254
- const name = parseStyle(readFileSync2(file, "utf8"), id).name;
1240
+ if (!file || !existsSync6(file)) return false;
1241
+ const name = parseStyle(readFileSync(file, "utf8"), id).name;
1255
1242
  rmSync(file);
1256
1243
  if (readSettings(claudeConfigDir)["outputStyle"] === name) writeDefaultName(claudeConfigDir, void 0);
1257
1244
  return true;
@@ -1261,8 +1248,8 @@ function settingsFile(claudeConfigDir) {
1261
1248
  }
1262
1249
  function readSettings(claudeConfigDir) {
1263
1250
  const file = settingsFile(claudeConfigDir);
1264
- if (!existsSync7(file)) return {};
1265
- const parsed = JSON.parse(readFileSync2(file, "utf8"));
1251
+ if (!existsSync6(file)) return {};
1252
+ const parsed = JSON.parse(readFileSync(file, "utf8"));
1266
1253
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
1267
1254
  throw new Error(`${file} is not a JSON object`);
1268
1255
  }
@@ -1305,7 +1292,7 @@ function setOutputStyleDefault(claudeConfigDir, id) {
1305
1292
  return true;
1306
1293
  }
1307
1294
 
1308
- // src/claude/models.ts
1295
+ // ../api/src/claude/models.ts
1309
1296
  var MODEL_OPTIONS = [
1310
1297
  { value: "opus", label: "Opus", provider: "claude" },
1311
1298
  { value: "sonnet", label: "Sonnet", provider: "claude" },
@@ -1377,7 +1364,7 @@ function modelLabel(value) {
1377
1364
  return longContext ? `${label} \xB7 1M context` : label;
1378
1365
  }
1379
1366
 
1380
- // src/agents/usage-limit.ts
1367
+ // ../api/src/agents/usage-limit.ts
1381
1368
  var USAGE_LIMIT_PATTERNS = [
1382
1369
  /usage limit reached/i,
1383
1370
  /\d+\s*-?\s*hour limit reached/i,
@@ -1429,7 +1416,7 @@ function usageLimitMessage(rawText, agent, model, now = Date.now()) {
1429
1416
  ].filter(Boolean).join("\n");
1430
1417
  }
1431
1418
 
1432
- // src/agents/usage-limit-state.ts
1419
+ // ../api/src/agents/usage-limit-state.ts
1433
1420
  var ALL_MODELS = "*";
1434
1421
  var limitedUntilByKey = /* @__PURE__ */ new Map();
1435
1422
  function stateKey(profile, agent, model) {
@@ -1477,7 +1464,7 @@ function usageLimitedModels(agent) {
1477
1464
  return limited;
1478
1465
  }
1479
1466
 
1480
- // src/agents/auth-failure-state.ts
1467
+ // ../api/src/agents/auth-failure-state.ts
1481
1468
  var failedProfiles = /* @__PURE__ */ new Set();
1482
1469
  function markClaudeAuthFailed() {
1483
1470
  failedProfiles.add(getProfile());
@@ -1489,7 +1476,7 @@ function claudeAuthFailed() {
1489
1476
  return failedProfiles.has(getProfile());
1490
1477
  }
1491
1478
 
1492
- // src/agents/usage-recorder.ts
1479
+ // ../api/src/agents/usage-recorder.ts
1493
1480
  var recorder;
1494
1481
  function setUsageRecorder(next) {
1495
1482
  recorder = next;
@@ -1591,12 +1578,24 @@ var CONTEXT_TOO_LONG_PATTERNS = [
1591
1578
  function isContextTooLongError(text) {
1592
1579
  return CONTEXT_TOO_LONG_PATTERNS.some((p) => p.test(text));
1593
1580
  }
1594
- var AUTH_ERROR_PATTERNS = [/failed to authenticate/i, /oauth session expired/i, /invalid api key/i];
1581
+ var AUTH_ERROR_PATTERNS = [
1582
+ /failed to authenticate/i,
1583
+ /oauth session expired/i,
1584
+ /invalid api key/i,
1585
+ /not logged in/i
1586
+ ];
1595
1587
  function isAuthError(text) {
1596
1588
  return AUTH_ERROR_PATTERNS.some((p) => p.test(text));
1597
1589
  }
1598
- function authErrorMessage(raw) {
1599
- return `The agent can't sign in to Claude right now (the Host's login expired and could not be refreshed).
1590
+ function authErrorMessage(raw, usingSetupToken = false) {
1591
+ const tokenHint = usingSetupToken ? `This profile's config.env sets CLAUDE_CODE_OAUTH_TOKEN, which overrides \`claude auth login\`. Use Sign in or Paste a token in Settings \u2192 Agent \u2192 Providers, or run \`claude setup-token\` and replace it in ~/.config/flyspace/profiles/<name>/config.env (not a launchd plist: the dashboard only reads config.env).
1592
+ ` : "";
1593
+ if (usingSetupToken)
1594
+ console.warn(
1595
+ "[agent] auth failed while CLAUDE_CODE_OAUTH_TOKEN is set: the token overrides the CLI login"
1596
+ );
1597
+ return `The agent can't sign in to Claude right now (the Host's Claude login is missing or expired).
1598
+ ` + tokenHint + `A long-lived token must live in the profile's config.env (~/.config/flyspace/profiles/<name>/config.env), not in a launchd plist or shell: the dashboard only reads config.env. Restart the dashboard service after editing. Run \`flyspace doctor\` to see which profile is broken.
1600
1599
  To fix it, a workspace admin can open Settings \u2192 Agent \u2192 Providers and click Sign in next to Claude Code.
1601
1600
 
1602
1601
  > Original error: ${raw}`;
@@ -1640,23 +1639,29 @@ function extractUsage(result) {
1640
1639
  };
1641
1640
  }
1642
1641
  function budgetExceededMessage(maxBudgetUsd, resumable = false) {
1643
- const cap = maxBudgetUsd ? `$${maxBudgetUsd}` : "\u82B1\u8CBB\u4E0A\u9650";
1642
+ const cap = maxBudgetUsd ? `$${maxBudgetUsd}` : "spend limit";
1644
1643
  if (resumable) {
1645
- return `\u9019\u6B21\u4EFB\u52D9\u82B1\u5230\u4E86 ${cap} \u7684\u55AE\u6B21\u4E0A\u9650\uFF0C\u6211\u5148\u628A\u5B83\u66AB\u505C\u4E86 \u23F8\uFE0F
1646
- \u9019\u4E0D\u662F\u5931\u6557 \u2014 \u9032\u5EA6\u548C\u4E0A\u4E0B\u6587\u90FD\u9084\u7559\u8457\u3002\u6309\u300C\u7E7C\u7E8C\u300D\u6703\u5F9E\u4E2D\u65B7\u7684\u5730\u65B9\u63A5\u8457\u505A\u5B8C\uFF08\u91CD\u65B0\u8A08\u4E00\u4EFD\u984D\u5EA6\uFF09\u3002
1647
- \u5982\u679C\u89BA\u5F97\u9019\u984C\u672C\u4F86\u5C31\u592A\u91CD\uFF0C\u4E5F\u53EF\u4EE5\u6539\u7528\u6458\u8981 fork \u5230\u65B0 thread\uFF0Ccontext \u8B8A\u8F15\u3001\u6210\u672C\u66F4\u4F4E\u3002`;
1644
+ return `This task hit the ${cap} per-run limit, so I paused it \u23F8\uFE0F
1645
+ This isn't a failure. Progress and context are kept. Press Continue to pick up where it stopped (with a fresh budget).
1646
+ If the task is just too heavy, you can also fork a summary into a new thread for a lighter context and lower cost.`;
1648
1647
  }
1649
- return `\u9019\u6B21\u4EFB\u52D9\u8D85\u904E\u4E86 ${cap} \u7684\u55AE\u6B21\u82B1\u8CBB\u4E0A\u9650\u88AB\u4E2D\u6B62\uFF0C\u6C92\u6709\u7522\u51FA\u7D50\u679C\uFF0C\u4E5F\u6C92\u6709\u53EF\u4EE5\u63A5\u7E8C\u7684\u9032\u5EA6\u3002
1650
- \u901A\u5E38\u662F\u55AE\u4E00\u8ACB\u6C42\u505A\u592A\u591A\u4E8B\uFF08\u4F8B\u5982\u4E00\u6B21 spawn \u591A\u500B\u8F03\u8CB4\u7684\u5B50 agent\uFF09\u3002
1651
- \u53EF\u4EE5\u7528\u4E0B\u9762\u7684\u6309\u9215\u628A\u76EE\u524D\u8A0E\u8AD6\u6458\u8981\u5F8C fork \u5230\u65B0 thread \u7E7C\u7E8C\uFF08context \u8B8A\u8F15\u3001\u6210\u672C\u964D\u4F4E\uFF09\uFF0C\u6216\u628A\u4EFB\u52D9\u62C6\u5C0F\u518D\u8A66\u3002`;
1648
+ return `This task went over the ${cap} per-run spend limit and was stopped. There is no result and no progress to resume.
1649
+ This usually means one request did too much (for example, spawning several expensive sub-agents at once).
1650
+ Use the button below to fork a summary of this discussion into a new thread (lighter context, lower cost), or split the task into smaller pieces and try again.`;
1652
1651
  }
1653
- function interpretCliResult(result, resumeSessionId, maxBudgetUsd, requestedModel) {
1652
+ function interpretCliResult(result, resumeSessionId, maxBudgetUsd, requestedModel, usingSetupToken = false) {
1654
1653
  const model = requestedModel ?? primaryModel(result.modelUsage);
1655
- const response = interpretCliOutcome(result, resumeSessionId, maxBudgetUsd, model);
1654
+ const response = interpretCliOutcome(
1655
+ result,
1656
+ resumeSessionId,
1657
+ maxBudgetUsd,
1658
+ model,
1659
+ usingSetupToken
1660
+ );
1656
1661
  const usage = extractUsage(result);
1657
1662
  return usage ? { ...response, usage } : response;
1658
1663
  }
1659
- function interpretCliOutcome(result, resumeSessionId, maxBudgetUsd, model) {
1664
+ function interpretCliOutcome(result, resumeSessionId, maxBudgetUsd, model, usingSetupToken = false) {
1660
1665
  const sessionId = result.session_id ?? resumeSessionId ?? "";
1661
1666
  if (result.is_error) {
1662
1667
  if (result.subtype === "error_max_budget_usd") {
@@ -1679,7 +1684,7 @@ function interpretCliOutcome(result, resumeSessionId, maxBudgetUsd, model) {
1679
1684
  }
1680
1685
  if (isAuthError(text)) {
1681
1686
  markClaudeAuthFailed();
1682
- return { sessionId, text: authErrorMessage(text), isError: true };
1687
+ return { sessionId, text: authErrorMessage(text, usingSetupToken), isError: true };
1683
1688
  }
1684
1689
  const contextTooLong = isContextTooLongError(text);
1685
1690
  const crashedMidExecution = result.subtype === "error_during_execution";
@@ -1729,13 +1734,13 @@ function getMaxDurationMs(streaming) {
1729
1734
  function loadSystemPrompt() {
1730
1735
  const customPath = paths.PROMPT_FILE;
1731
1736
  const defaultPath = resolve4(paths.PACKAGE_ROOT, "system.default.md");
1732
- const filePath = existsSync8(customPath) ? customPath : defaultPath;
1733
- return readFileSync3(filePath, "utf-8").trim();
1737
+ const filePath = existsSync7(customPath) ? customPath : defaultPath;
1738
+ return readFileSync2(filePath, "utf-8").trim();
1734
1739
  }
1735
1740
  function loadCapabilities() {
1736
1741
  const capabilitiesPath = resolve4(paths.PACKAGE_ROOT, "system.capabilities.md");
1737
- if (!existsSync8(capabilitiesPath)) return "";
1738
- return readFileSync3(capabilitiesPath, "utf-8").trim();
1742
+ if (!existsSync7(capabilitiesPath)) return "";
1743
+ return readFileSync2(capabilitiesPath, "utf-8").trim();
1739
1744
  }
1740
1745
  function buildSystemPrompt(botName, agentPersona, channelPrompt, outputStyle) {
1741
1746
  const prompt = loadSystemPrompt().replaceAll("{{botName}}", botName);
@@ -1837,7 +1842,10 @@ function buildArgs(prompt, botName, options, resumeSessionId, isolatedStyle) {
1837
1842
  "--setting-sources",
1838
1843
  options.runtime === "container" || options.runtime === "sandbox" ? "project,local" : "user,project,local",
1839
1844
  "--settings",
1840
- buildHookSettings(options.runtime ?? "host", isolatedStyle?.builtIn ? isolatedStyle.name : void 0)
1845
+ buildHookSettings(
1846
+ options.runtime ?? "host",
1847
+ isolatedStyle?.builtIn ? isolatedStyle.name : void 0
1848
+ )
1841
1849
  ];
1842
1850
  if (mcpStrictConfigEnabled()) {
1843
1851
  args.push("--strict-mcp-config");
@@ -2058,7 +2066,8 @@ function runCli(prompt, cwd, botName, options, claudeConfigDir, resumeSessionId,
2058
2066
  result,
2059
2067
  resumeSessionId,
2060
2068
  options.maxBudgetUsd,
2061
- options.model
2069
+ options.model,
2070
+ !!claudeCodeOauthToken
2062
2071
  );
2063
2072
  recordUsage2(response, options);
2064
2073
  resolve7(response);
@@ -2070,7 +2079,7 @@ function runCli(prompt, cwd, botName, options, claudeConfigDir, resumeSessionId,
2070
2079
  });
2071
2080
  }
2072
2081
  async function askClaude(prompt, cwd, botName, options, claudeConfigDir, resumeSessionId, claudeCodeOauthToken) {
2073
- if (!existsSync8(cwd) || !statSync3(cwd).isDirectory()) {
2082
+ if (!existsSync7(cwd) || !statSync3(cwd).isDirectory()) {
2074
2083
  console.error(`[agent] working directory does not exist: ${cwd}`);
2075
2084
  return {
2076
2085
  sessionId: resumeSessionId ?? "",
@@ -2140,7 +2149,7 @@ Fix the channel's working directory in its settings (or recreate the directory),
2140
2149
  }
2141
2150
  }
2142
2151
 
2143
- // src/feature-flags.ts
2152
+ // ../api/src/feature-flags.ts
2144
2153
  var featureFlags = {
2145
2154
  "ai-cost": {
2146
2155
  title: "AI cost",
@@ -2190,7 +2199,7 @@ function resolveFeatureFlags(enabledIds, devHost) {
2190
2199
  return out;
2191
2200
  }
2192
2201
 
2193
- // src/store/feature-flag-store.ts
2202
+ // ../api/src/store/feature-flag-store.ts
2194
2203
  async function listEnabledFeatureFlags(workspaceId) {
2195
2204
  const { data, error } = await getSupabaseClient().from("feature_flags").select("flag_id").eq("workspace_id", workspaceId);
2196
2205
  if (error) throw new Error(`listEnabledFeatureFlags(${workspaceId}): ${error.message}`);
@@ -2213,7 +2222,7 @@ async function disableFeatureFlag(workspaceId, flagId) {
2213
2222
  if (error) throw new Error(`disableFeatureFlag(${workspaceId}, ${flagId}): ${error.message}`);
2214
2223
  }
2215
2224
 
2216
- // src/store/memory-store.ts
2225
+ // ../api/src/store/memory-store.ts
2217
2226
  var MEMORY_TYPES = ["preference", "decision", "fact", "reference"];
2218
2227
  var channelTarget = (channelId) => ({ scope: "channel", channelId });
2219
2228
  var NAME_RE = /^[a-z0-9]+(-[a-z0-9]+)*$/;
@@ -2534,7 +2543,7 @@ function formatMemoryPrompt(channelId, memories, extras = {}) {
2534
2543
  ].join("\n");
2535
2544
  }
2536
2545
 
2537
- // src/store/workspace-store.ts
2546
+ // ../api/src/store/workspace-store.ts
2538
2547
  function rowToMembership(row) {
2539
2548
  return {
2540
2549
  id: row["id"],
@@ -2619,9 +2628,6 @@ async function setWorkspaceStripeSubscription(workspaceId, fields) {
2619
2628
  }).eq("id", workspaceId);
2620
2629
  if (error) throw new Error(`setWorkspaceStripeSubscription(${workspaceId}): ${error.message}`);
2621
2630
  }
2622
- async function markWorkspaceAgentConnected(workspaceId) {
2623
- await stampOnce(workspaceId, "agent_connected_at");
2624
- }
2625
2631
  async function markWorkspaceProjectsSetup(workspaceId) {
2626
2632
  await stampOnce(workspaceId, "projects_setup_at");
2627
2633
  }
@@ -2860,11 +2866,11 @@ async function buildPrompt(profile, channelId, opts) {
2860
2866
  return formatMemoryPrompt(channelId, channel, extras);
2861
2867
  }
2862
2868
 
2863
- // src/dashboard/settings.ts
2864
- import { readFileSync as readFileSync4, writeFileSync as writeFileSync3, existsSync as existsSync9, mkdirSync as mkdirSync6, rmSync as rmSync2 } from "fs";
2865
- import { dirname, resolve as resolve5 } from "path";
2869
+ // src/dashboard/settings-host.ts
2870
+ import { writeFileSync as writeFileSync3, existsSync as existsSync9, mkdirSync as mkdirSync6, readFileSync as readFileSync4, rmSync as rmSync2 } from "fs";
2871
+ import { dirname } from "path";
2866
2872
 
2867
- // src/dashboard/auto-title.ts
2873
+ // ../api/src/dashboard/auto-title.ts
2868
2874
  var GROQ_API_URL = "https://api.groq.com/openai/v1/chat/completions";
2869
2875
  var TITLE_MODEL = "openai/gpt-oss-20b";
2870
2876
  var TIMEOUT_MS = 4e3;
@@ -2951,7 +2957,11 @@ ${input.body.slice(0, MAX_BODY_CHARS)}`
2951
2957
  }
2952
2958
  }
2953
2959
 
2954
- // src/store/workspace-settings-store.ts
2960
+ // ../api/src/dashboard/settings.ts
2961
+ import { readFileSync as readFileSync3, existsSync as existsSync8 } from "fs";
2962
+ import { resolve as resolve5 } from "path";
2963
+
2964
+ // ../api/src/store/workspace-settings-store.ts
2955
2965
  var BRANDING_DEFAULTS = {
2956
2966
  theme: "default",
2957
2967
  font: "default",
@@ -3023,7 +3033,7 @@ async function upsertWorkspaceBranding(profile, patch) {
3023
3033
  return next;
3024
3034
  }
3025
3035
 
3026
- // src/dashboard/settings.ts
3036
+ // ../api/src/dashboard/settings.ts
3027
3037
  var VALID_THEMES = [
3028
3038
  "default",
3029
3039
  "classic",
@@ -3043,20 +3053,12 @@ var VALID_FONTS = [
3043
3053
  "playfair",
3044
3054
  "inter"
3045
3055
  ];
3046
- var LEGACY_AGENT_TO_MODEL = {
3047
- claude: "sonnet",
3048
- codex: "gpt-5.6-sol"
3049
- };
3050
3056
  var GA_MEASUREMENT_ID = /^G-[A-Z0-9]{4,24}$/;
3051
3057
  function parseGaMeasurementId(raw) {
3052
3058
  if (typeof raw !== "string") return void 0;
3053
3059
  const id = raw.trim().toUpperCase();
3054
3060
  return GA_MEASUREMENT_ID.test(id) ? id : void 0;
3055
3061
  }
3056
- var KNOWN_RUNNERS = ["claude", "codex"];
3057
- function firstModelFor(runner) {
3058
- return modelOptionsFor(runner)[0].value;
3059
- }
3060
3062
  var LOCAL_DEFAULTS = { agent: "sonnet" };
3061
3063
  function localDefaults() {
3062
3064
  return {
@@ -3064,6 +3066,97 @@ function localDefaults() {
3064
3066
  providers: [{ runner: "claude", model: LOCAL_DEFAULTS.agent }, { runner: "codex" }]
3065
3067
  };
3066
3068
  }
3069
+ var AUTO_TITLE_PROMPT_MAX = 2e3;
3070
+ function readSettingsFile() {
3071
+ if (!existsSync8(paths.DASHBOARD_SETTINGS_FILE)) return null;
3072
+ try {
3073
+ const raw = JSON.parse(readFileSync3(paths.DASHBOARD_SETTINGS_FILE, "utf-8"));
3074
+ return raw && typeof raw === "object" ? raw : null;
3075
+ } catch {
3076
+ return null;
3077
+ }
3078
+ }
3079
+ function brandingToSettings(branding) {
3080
+ return {
3081
+ theme: branding.theme,
3082
+ font: branding.font,
3083
+ logo: branding.logo ?? void 0,
3084
+ displayName: branding.displayName ?? void 0,
3085
+ gaMeasurementId: branding.gaMeasurementId ?? void 0,
3086
+ autoTitleEnabled: branding.autoTitleEnabled,
3087
+ autoTitlePrompt: branding.autoTitlePrompt ?? void 0
3088
+ };
3089
+ }
3090
+ function legacyBranding(raw) {
3091
+ return {
3092
+ theme: typeof raw["theme"] === "string" && VALID_THEMES.includes(raw["theme"]) ? raw["theme"] : BRANDING_DEFAULTS.theme,
3093
+ font: typeof raw["font"] === "string" && VALID_FONTS.includes(raw["font"]) ? raw["font"] : BRANDING_DEFAULTS.font,
3094
+ logo: typeof raw["logo"] === "string" ? raw["logo"] : null,
3095
+ displayName: typeof raw["displayName"] === "string" ? raw["displayName"].trim() || null : null,
3096
+ gaMeasurementId: parseGaMeasurementId(raw["gaMeasurementId"]) ?? null
3097
+ };
3098
+ }
3099
+ async function loadWorkspaceBranding(profile = getProfile()) {
3100
+ const stored = await getWorkspaceBranding(profile);
3101
+ if (stored) return brandingToSettings(stored);
3102
+ const legacy = runWithProfile(profile, () => readSettingsFile());
3103
+ if (!legacy) return brandingToSettings(BRANDING_DEFAULTS);
3104
+ return brandingToSettings(await upsertWorkspaceBranding(profile, legacyBranding(legacy)));
3105
+ }
3106
+ async function saveWorkspaceBranding(patch, profile = getProfile()) {
3107
+ const current = await loadWorkspaceBranding(profile);
3108
+ const next = {
3109
+ theme: patch.theme && VALID_THEMES.includes(patch.theme) ? patch.theme : current.theme,
3110
+ font: patch.font && VALID_FONTS.includes(patch.font) ? patch.font : current.font,
3111
+ logo: patch.logo === null ? null : typeof patch.logo === "string" ? patch.logo : void 0,
3112
+ displayName: patch.displayName === null || patch.displayName === "" ? null : typeof patch.displayName === "string" ? patch.displayName.trim() : void 0,
3113
+ gaMeasurementId: patch.gaMeasurementId === null || patch.gaMeasurementId === "" ? null : typeof patch.gaMeasurementId === "string" ? parseGaMeasurementId(patch.gaMeasurementId) : void 0,
3114
+ autoTitleEnabled: typeof patch.autoTitleEnabled === "boolean" ? patch.autoTitleEnabled : void 0,
3115
+ autoTitlePrompt: patch.autoTitlePrompt === null || patch.autoTitlePrompt === "" ? null : typeof patch.autoTitlePrompt === "string" ? patch.autoTitlePrompt.trim().slice(0, AUTO_TITLE_PROMPT_MAX) || null : void 0
3116
+ };
3117
+ return brandingToSettings(await upsertWorkspaceBranding(profile, next));
3118
+ }
3119
+ function defaultPromptPath() {
3120
+ return resolve5(paths.PACKAGE_ROOT, "system.default.md");
3121
+ }
3122
+ function readDefaultPrompt() {
3123
+ const path = defaultPromptPath();
3124
+ return existsSync8(path) ? readFileSync3(path, "utf-8").trim() : "";
3125
+ }
3126
+ function loadWorkspacePrompt() {
3127
+ const defaultPrompt = readDefaultPrompt();
3128
+ const custom = existsSync8(paths.PROMPT_FILE);
3129
+ return {
3130
+ prompt: custom ? readFileSync3(paths.PROMPT_FILE, "utf-8").trim() : defaultPrompt,
3131
+ defaultPrompt,
3132
+ custom
3133
+ };
3134
+ }
3135
+ var BOT_PROFILE_KEY = "bot";
3136
+ async function loadBotIdentity(profile = getProfile()) {
3137
+ const branding = await getWorkspaceBranding(profile);
3138
+ return {
3139
+ displayName: branding?.botName ?? void 0,
3140
+ avatar: branding?.botAvatar ?? void 0
3141
+ };
3142
+ }
3143
+ async function saveBotIdentity(patch, profile = getProfile()) {
3144
+ const next = await upsertWorkspaceBranding(profile, {
3145
+ botName: patch.displayName === void 0 ? void 0 : patch.displayName?.trim() || null,
3146
+ botAvatar: patch.avatar
3147
+ });
3148
+ return { displayName: next.botName ?? void 0, avatar: next.botAvatar ?? void 0 };
3149
+ }
3150
+
3151
+ // src/dashboard/settings-host.ts
3152
+ var LEGACY_AGENT_TO_MODEL = {
3153
+ claude: "sonnet",
3154
+ codex: "gpt-5.6-sol"
3155
+ };
3156
+ var KNOWN_RUNNERS = ["claude", "codex"];
3157
+ function firstModelFor(runner) {
3158
+ return modelOptionsFor(runner)[0].value;
3159
+ }
3067
3160
  function normalizeDefaultModel(raw, fallback) {
3068
3161
  if (typeof raw !== "string") return fallback;
3069
3162
  if (raw in LEGACY_AGENT_TO_MODEL) return LEGACY_AGENT_TO_MODEL[raw];
@@ -3123,7 +3216,7 @@ function loadDashboardSettings() {
3123
3216
  try {
3124
3217
  const raw = JSON.parse(readFileSync4(paths.DASHBOARD_SETTINGS_FILE, "utf-8"));
3125
3218
  const providers = parseProviders(raw.providers, {
3126
- agent: normalizeDefaultModel(raw.agent, LOCAL_DEFAULTS.agent),
3219
+ agent: normalizeDefaultModel(raw.agent, localDefaults().agent),
3127
3220
  fallbackModel: typeof raw.fallbackModel === "string" && isAllowedModel(raw.fallbackModel) ? raw.fallbackModel : void 0
3128
3221
  });
3129
3222
  return {
@@ -3135,7 +3228,6 @@ function loadDashboardSettings() {
3135
3228
  return localDefaults();
3136
3229
  }
3137
3230
  }
3138
- var AUTO_TITLE_PROMPT_MAX = 2e3;
3139
3231
  function withDefaultModel(providers, model) {
3140
3232
  const runner = runnerForModel(model);
3141
3233
  const rest = providers.filter((p) => p.runner !== runner);
@@ -3148,15 +3240,6 @@ function withFallbackModel(providers, model) {
3148
3240
  if (runner === cleared[0].runner) return cleared;
3149
3241
  return [cleared[0], { runner, model }, ...cleared.slice(1).filter((p) => p.runner !== runner)];
3150
3242
  }
3151
- function readSettingsFile() {
3152
- if (!existsSync9(paths.DASHBOARD_SETTINGS_FILE)) return null;
3153
- try {
3154
- const raw = JSON.parse(readFileSync4(paths.DASHBOARD_SETTINGS_FILE, "utf-8"));
3155
- return raw && typeof raw === "object" ? raw : null;
3156
- } catch {
3157
- return null;
3158
- }
3159
- }
3160
3243
  function writeSettings(next) {
3161
3244
  mkdirSync6(dirname(paths.DASHBOARD_SETTINGS_FILE), { recursive: true });
3162
3245
  const merged = { ...readSettingsFile() ?? {}, ...next };
@@ -3184,46 +3267,6 @@ function saveDashboardSettings(patch) {
3184
3267
  agentProfiles: current.agentProfiles
3185
3268
  });
3186
3269
  }
3187
- function brandingToSettings(branding) {
3188
- return {
3189
- theme: branding.theme,
3190
- font: branding.font,
3191
- logo: branding.logo ?? void 0,
3192
- displayName: branding.displayName ?? void 0,
3193
- gaMeasurementId: branding.gaMeasurementId ?? void 0,
3194
- autoTitleEnabled: branding.autoTitleEnabled,
3195
- autoTitlePrompt: branding.autoTitlePrompt ?? void 0
3196
- };
3197
- }
3198
- function legacyBranding(raw) {
3199
- return {
3200
- theme: typeof raw["theme"] === "string" && VALID_THEMES.includes(raw["theme"]) ? raw["theme"] : BRANDING_DEFAULTS.theme,
3201
- font: typeof raw["font"] === "string" && VALID_FONTS.includes(raw["font"]) ? raw["font"] : BRANDING_DEFAULTS.font,
3202
- logo: typeof raw["logo"] === "string" ? raw["logo"] : null,
3203
- displayName: typeof raw["displayName"] === "string" ? raw["displayName"].trim() || null : null,
3204
- gaMeasurementId: parseGaMeasurementId(raw["gaMeasurementId"]) ?? null
3205
- };
3206
- }
3207
- async function loadWorkspaceBranding(profile = getProfile()) {
3208
- const stored = await getWorkspaceBranding(profile);
3209
- if (stored) return brandingToSettings(stored);
3210
- const legacy = runWithProfile(profile, () => readSettingsFile());
3211
- if (!legacy) return brandingToSettings(BRANDING_DEFAULTS);
3212
- return brandingToSettings(await upsertWorkspaceBranding(profile, legacyBranding(legacy)));
3213
- }
3214
- async function saveWorkspaceBranding(patch, profile = getProfile()) {
3215
- const current = await loadWorkspaceBranding(profile);
3216
- const next = {
3217
- theme: patch.theme && VALID_THEMES.includes(patch.theme) ? patch.theme : current.theme,
3218
- font: patch.font && VALID_FONTS.includes(patch.font) ? patch.font : current.font,
3219
- logo: patch.logo === null ? null : typeof patch.logo === "string" ? patch.logo : void 0,
3220
- displayName: patch.displayName === null || patch.displayName === "" ? null : typeof patch.displayName === "string" ? patch.displayName.trim() : void 0,
3221
- gaMeasurementId: patch.gaMeasurementId === null || patch.gaMeasurementId === "" ? null : typeof patch.gaMeasurementId === "string" ? parseGaMeasurementId(patch.gaMeasurementId) : void 0,
3222
- autoTitleEnabled: typeof patch.autoTitleEnabled === "boolean" ? patch.autoTitleEnabled : void 0,
3223
- autoTitlePrompt: patch.autoTitlePrompt === null || patch.autoTitlePrompt === "" ? null : typeof patch.autoTitlePrompt === "string" ? patch.autoTitlePrompt.trim().slice(0, AUTO_TITLE_PROMPT_MAX) || null : void 0
3224
- };
3225
- return brandingToSettings(await upsertWorkspaceBranding(profile, next));
3226
- }
3227
3270
  async function loadFullDashboardSettings(profile = getProfile()) {
3228
3271
  return {
3229
3272
  ...await loadWorkspaceBranding(profile),
@@ -3231,25 +3274,9 @@ async function loadFullDashboardSettings(profile = getProfile()) {
3231
3274
  autoTitleDefaultPrompt: DEFAULT_TITLE_RULES
3232
3275
  };
3233
3276
  }
3234
- function defaultPromptPath() {
3235
- return resolve5(paths.PACKAGE_ROOT, "system.default.md");
3236
- }
3237
- function readDefaultPrompt() {
3238
- const path = defaultPromptPath();
3239
- return existsSync9(path) ? readFileSync4(path, "utf-8").trim() : "";
3240
- }
3241
- function loadWorkspacePrompt() {
3242
- const defaultPrompt = readDefaultPrompt();
3243
- const custom = existsSync9(paths.PROMPT_FILE);
3244
- return {
3245
- prompt: custom ? readFileSync4(paths.PROMPT_FILE, "utf-8").trim() : defaultPrompt,
3246
- defaultPrompt,
3247
- custom
3248
- };
3249
- }
3250
3277
  function saveWorkspacePrompt(prompt) {
3251
3278
  const trimmed = prompt.trim();
3252
- if (!trimmed || trimmed === readDefaultPrompt()) return resetWorkspacePrompt();
3279
+ if (!trimmed || trimmed === loadWorkspacePrompt().defaultPrompt) return resetWorkspacePrompt();
3253
3280
  mkdirSync6(dirname(paths.PROMPT_FILE), { recursive: true });
3254
3281
  writeFileSync3(paths.PROMPT_FILE, `${trimmed}
3255
3282
  `, "utf-8");
@@ -3278,23 +3305,8 @@ function saveAgentProfile(name, patch) {
3278
3305
  agentProfiles: Object.keys(agentProfiles).length > 0 ? agentProfiles : void 0
3279
3306
  });
3280
3307
  }
3281
- var BOT_PROFILE_KEY = "bot";
3282
- async function loadBotIdentity(profile = getProfile()) {
3283
- const branding = await getWorkspaceBranding(profile);
3284
- return {
3285
- displayName: branding?.botName ?? void 0,
3286
- avatar: branding?.botAvatar ?? void 0
3287
- };
3288
- }
3289
- async function saveBotIdentity(patch, profile = getProfile()) {
3290
- const next = await upsertWorkspaceBranding(profile, {
3291
- botName: patch.displayName === void 0 ? void 0 : patch.displayName?.trim() || null,
3292
- botAvatar: patch.avatar
3293
- });
3294
- return { displayName: next.botName ?? void 0, avatar: next.botAvatar ?? void 0 };
3295
- }
3296
3308
 
3297
- // src/codex/agent.ts
3309
+ // ../api/src/codex/agent.ts
3298
3310
  import { spawn as spawn2 } from "child_process";
3299
3311
  import { existsSync as existsSync10, mkdtempSync, readFileSync as readFileSync5, rmSync as rmSync3, statSync as statSync4 } from "fs";
3300
3312
  import { tmpdir } from "os";
@@ -4340,7 +4352,7 @@ function runScriptAutomation(opts) {
4340
4352
  });
4341
4353
  }
4342
4354
 
4343
- // src/automations/manager.ts
4355
+ // ../api/src/automations/manager.ts
4344
4356
  function findInChannels(name) {
4345
4357
  for (const channel of getProfileChannelRegistry()) {
4346
4358
  const a = channel.automations;
@@ -5514,7 +5526,7 @@ async function ownIdentityFor(client) {
5514
5526
  return own;
5515
5527
  }
5516
5528
  async function mirrorIncomingMessage(client, msg) {
5517
- if (!process.env["SUPABASE_URL"] || !process.env["SUPABASE_SECRET_KEY"]) return;
5529
+ if (!databaseReachable()) return;
5518
5530
  if (msg.subtype && SKIP_SUBTYPES.has(msg.subtype)) return;
5519
5531
  if (msg.subtype === "message_changed" || msg.subtype === "message_deleted") return;
5520
5532
  try {
@@ -5633,13 +5645,13 @@ async function summariseThreadTranscript(transcript, opts, deps = {}) {
5633
5645
  return res.text;
5634
5646
  }
5635
5647
 
5636
- // src/claude/skills.ts
5648
+ // ../api/src/claude/skills.ts
5637
5649
  import { existsSync as existsSync13, readdirSync as readdirSync3, readFileSync as readFileSync8, statSync as statSync6 } from "fs";
5638
5650
  import { homedir as homedir5 } from "os";
5639
5651
  import { basename as basename2, dirname as dirname2, join as join9 } from "path";
5640
- import yaml3 from "js-yaml";
5652
+ import yaml2 from "js-yaml";
5641
5653
 
5642
- // src/claude/skill-files.ts
5654
+ // ../api/src/claude/skill-files.ts
5643
5655
  import {
5644
5656
  existsSync as existsSync12,
5645
5657
  mkdirSync as mkdirSync8,
@@ -5651,7 +5663,7 @@ import {
5651
5663
  } from "fs";
5652
5664
  import { homedir as homedir4 } from "os";
5653
5665
  import { join as join8, resolve as resolve6, sep as sep3 } from "path";
5654
- import yaml2 from "js-yaml";
5666
+ import yaml from "js-yaml";
5655
5667
  var MAX_SKILL_BYTES = 2 * 1024 * 1024;
5656
5668
  var SKILL_NAME = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
5657
5669
  function expandHome(p) {
@@ -5679,7 +5691,7 @@ function splitFrontmatter(raw) {
5679
5691
  if (!match) return { fm: {}, body: raw };
5680
5692
  let fm = {};
5681
5693
  try {
5682
- fm = yaml2.load(match[1]) ?? {};
5694
+ fm = yaml.load(match[1]) ?? {};
5683
5695
  } catch {
5684
5696
  fm = {};
5685
5697
  }
@@ -5688,7 +5700,7 @@ function splitFrontmatter(raw) {
5688
5700
  function buildSkillFile(fm, body) {
5689
5701
  const { name, description, ...rest } = fm;
5690
5702
  const ordered = { name, description, ...rest };
5691
- const front = yaml2.dump(ordered, { lineWidth: -1 }).trimEnd();
5703
+ const front = yaml.dump(ordered, { lineWidth: -1 }).trimEnd();
5692
5704
  return `---
5693
5705
  ${front}
5694
5706
  ---
@@ -5801,7 +5813,7 @@ function deleteSkillFile(dir, name) {
5801
5813
  return { status: "ok" };
5802
5814
  }
5803
5815
 
5804
- // src/claude/skills.ts
5816
+ // ../api/src/claude/skills.ts
5805
5817
  function defaultConfigDir() {
5806
5818
  return join9(homedir5(), ".claude");
5807
5819
  }
@@ -5820,7 +5832,7 @@ function parseFrontmatter(file) {
5820
5832
  const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
5821
5833
  if (!match) return {};
5822
5834
  try {
5823
- const fm = yaml3.load(match[1]);
5835
+ const fm = yaml2.load(match[1]);
5824
5836
  const name = typeof fm?.["name"] === "string" ? fm["name"] : void 0;
5825
5837
  const description = typeof fm?.["description"] === "string" ? fm["description"] : void 0;
5826
5838
  return { name, description };
@@ -6379,12 +6391,12 @@ ${trimmedDetail.slice(0, 1500)}
6379
6391
  threadTs,
6380
6392
  reactTs
6381
6393
  });
6382
- const text = "\u9019\u500B\u4EFB\u52D9\u8DD1\u5F97\u6709\u9EDE\u4E45\uFF0C\u6211\u5148\u628A\u5B83\u66AB\u505C\u4E86 \u23F8\uFE0F\n\u9019\u4E0D\u662F\u5931\u6557 \u2014 \u9032\u5EA6\u548C\u4E0A\u4E0B\u6587\u90FD\u9084\u7559\u8457\u3002\u8981\u6211\u63A5\u8457\u505A\u5B8C\u55CE\uFF1F";
6394
+ const text = "This task is taking a while, so I paused it \u23F8\uFE0F\nThis isn't a failure. Progress and context are kept. Want me to finish it?";
6383
6395
  await say({
6384
6396
  text,
6385
6397
  blocks: [
6386
6398
  { type: "section", text: { type: "mrkdwn", text } },
6387
- buildRetryBlock(retryId, "\u25B6\uFE0F \u7E7C\u7E8C")
6399
+ buildRetryBlock(retryId, "\u25B6\uFE0F Continue")
6388
6400
  ],
6389
6401
  ...threadTs ? { thread_ts: threadTs } : {}
6390
6402
  });
@@ -6404,7 +6416,7 @@ ${trimmedDetail.slice(0, 1500)}
6404
6416
  });
6405
6417
  const blocks = [
6406
6418
  { type: "section", text: { type: "mrkdwn", text: message } },
6407
- buildRetryBlock(retryId, "\u25B6\uFE0F \u7E7C\u7E8C")
6419
+ buildRetryBlock(retryId, "\u25B6\uFE0F Continue")
6408
6420
  ];
6409
6421
  if (threadTs) {
6410
6422
  blocks.push(
@@ -6701,7 +6713,7 @@ retry: ${retryDetail}`);
6701
6713
  }
6702
6714
  await clearReaction();
6703
6715
  await say({
6704
- text: "\u9019\u500B\u4EFB\u52D9\u8DD1\u5F97\u6709\u9EDE\u4E45\uFF0C\u88AB\u6211\u66AB\u505C\u4E86 \u23F8\uFE0F \u9019\u6B21\u6C92\u6709\u53EF\u4EE5\u63A5\u7E8C\u7684\u9032\u5EA6\uFF0C\u9EBB\u7169\u4F60\u518D\u50B3\u4E00\u6B21\uFF0C\u6216\u628A\u8981\u505A\u7684\u4E8B\u62C6\u5C0F\u4E00\u9EDE\u3002",
6716
+ text: "This task took too long and I paused it \u23F8\uFE0F There is no progress to resume, so please send it again, or split the work into smaller pieces.",
6705
6717
  ...threadTs ? { thread_ts: threadTs } : {}
6706
6718
  });
6707
6719
  return;
@@ -7083,12 +7095,12 @@ ${matched.prompt}`,
7083
7095
  await client.chat.update({
7084
7096
  channel: channelId,
7085
7097
  ts: message.ts,
7086
- text: message.text ?? "\u91CD\u8A66\u5DF2\u903E\u6642",
7098
+ text: message.text ?? "Retry expired",
7087
7099
  blocks: [
7088
7100
  ...remainingBlocks,
7089
7101
  {
7090
7102
  type: "context",
7091
- elements: [{ type: "mrkdwn", text: "\u231B \u9019\u500B\u91CD\u8A66\u5DF2\u903E\u6642\uFF0C\u8ACB\u76F4\u63A5\u91CD\u65B0\u50B3\u4E00\u6B21\u8A0A\u606F\u3002" }]
7103
+ elements: [{ type: "mrkdwn", text: "\u231B This retry has expired. Please send your message again." }]
7092
7104
  }
7093
7105
  ]
7094
7106
  });
@@ -7155,12 +7167,12 @@ ${matched.prompt}`,
7155
7167
  await client.chat.update({
7156
7168
  channel: channelId,
7157
7169
  ts: message.ts,
7158
- text: message.text ?? "fork \u5DF2\u903E\u6642",
7170
+ text: message.text ?? "Fork expired",
7159
7171
  blocks: [
7160
7172
  ...remainingBlocks,
7161
7173
  {
7162
7174
  type: "context",
7163
- elements: [{ type: "mrkdwn", text: "\u231B \u9019\u500B fork \u5DF2\u903E\u6642\uFF0C\u8ACB\u91CD\u65B0\u89F8\u767C\u4E00\u6B21\u3002" }]
7175
+ elements: [{ type: "mrkdwn", text: "\u231B This fork has expired. Please trigger it again." }]
7164
7176
  }
7165
7177
  ]
7166
7178
  });
@@ -7570,7 +7582,7 @@ var AutomationRunStore = class {
7570
7582
  }
7571
7583
  };
7572
7584
 
7573
- // src/store/automation-run-sync.ts
7585
+ // ../api/src/store/automation-run-sync.ts
7574
7586
  var BATCH_SIZE = 500;
7575
7587
  var SYNC_INTERVAL_MS = 6e4;
7576
7588
  function toRecord(row, workspace) {
@@ -7817,7 +7829,7 @@ var SessionStore = class {
7817
7829
  import { randomUUID as randomUUID3 } from "crypto";
7818
7830
  import Database4 from "better-sqlite3";
7819
7831
 
7820
- // src/store/rate-cards.ts
7832
+ // ../api/src/store/rate-cards.ts
7821
7833
  var EPOCH = "1970-01-01";
7822
7834
  var RATE_CARDS = [
7823
7835
  {
@@ -8544,7 +8556,7 @@ function startUsageSync(store, workspace, options = {}) {
8544
8556
 
8545
8557
  // src/store/usage-recording.ts
8546
8558
  function installUsageRecording(dbPath, options = {}) {
8547
- const { sync = Boolean(process.env["SUPABASE_URL"] && process.env["SUPABASE_SECRET_KEY"]) } = options;
8559
+ const { sync = databaseReachable() } = options;
8548
8560
  const stores = /* @__PURE__ */ new Map();
8549
8561
  const stopSyncs = [];
8550
8562
  const storeFor = (profile) => {
@@ -8613,6 +8625,55 @@ var ReactionStore = class {
8613
8625
  }
8614
8626
  };
8615
8627
 
8628
+ // ../api/src/store/supabase-direct.ts
8629
+ import { createClient } from "@supabase/supabase-js";
8630
+ var REQUEST_TIMEOUT_MS = 15e3;
8631
+ function createDirectSupabaseClient() {
8632
+ const url = process.env["SUPABASE_URL"];
8633
+ const key = process.env["SUPABASE_SECRET_KEY"];
8634
+ if (!url || !key) {
8635
+ throw new Error("SUPABASE_URL / SUPABASE_SECRET_KEY not set \u2014 check .env");
8636
+ }
8637
+ return createClient(url, key, {
8638
+ auth: { persistSession: false },
8639
+ global: {
8640
+ fetch: (input, init) => fetch(input, { ...init, signal: init?.signal ?? AbortSignal.timeout(REQUEST_TIMEOUT_MS) })
8641
+ }
8642
+ });
8643
+ }
8644
+ function useDirectSupabase() {
8645
+ setSupabaseClientFactory(createDirectSupabaseClient);
8646
+ }
8647
+
8648
+ // ../api/src/store/local-cache.ts
8649
+ var EMPTY = {
8650
+ listActiveUsers: () => [],
8651
+ listUsersWithAvatars: () => [],
8652
+ displayNameFor: (id) => id,
8653
+ lookupChannelById: () => void 0,
8654
+ openUsageStore: () => null,
8655
+ openAutomationRunStore: () => null
8656
+ };
8657
+ var cache2 = EMPTY;
8658
+ function registerLocalCache(implementation) {
8659
+ cache2 = implementation;
8660
+ }
8661
+ function getLocalCache() {
8662
+ return cache2;
8663
+ }
8664
+
8665
+ // src/store/local-cache.ts
8666
+ function useLocalCache() {
8667
+ registerLocalCache({
8668
+ listActiveUsers,
8669
+ listUsersWithAvatars,
8670
+ displayNameFor,
8671
+ lookupChannelById: lookupById,
8672
+ openUsageStore: (file) => new UsageStore(file),
8673
+ openAutomationRunStore: (file) => new AutomationRunStore(file)
8674
+ });
8675
+ }
8676
+
8616
8677
  // src/health/watchdog.ts
8617
8678
  import { lookup } from "dns/promises";
8618
8679
  var ts = () => (/* @__PURE__ */ new Date()).toISOString();
@@ -8796,6 +8857,8 @@ async function startSlack(app, store, reactionStore, config, automations) {
8796
8857
  return { listeners, watchdog };
8797
8858
  }
8798
8859
  async function startServer() {
8860
+ useDirectSupabase();
8861
+ useLocalCache();
8799
8862
  ensureDirs();
8800
8863
  const sweptScratch = sweepScratchDir();
8801
8864
  if (sweptScratch > 0) console.log(`[flyspace] swept ${sweptScratch} stale scratch file(s)`);
@@ -8804,10 +8867,7 @@ async function startServer() {
8804
8867
  const store = new SessionStore(paths.DB_FILE);
8805
8868
  const runStore = new AutomationRunStore(paths.DB_FILE);
8806
8869
  installUsageRecording();
8807
- const hasSupabaseCreds = Boolean(
8808
- process.env["SUPABASE_URL"] && process.env["SUPABASE_SECRET_KEY"]
8809
- );
8810
- const stopRunSync = hasSupabaseCreds ? startAutomationRunSync(runStore, getProfile(), {
8870
+ const stopRunSync = databaseReachable() ? startAutomationRunSync(runStore, getProfile(), {
8811
8871
  onError: (error) => console.error(`[${ts2()}] [flyspace] automation run sync:`, error)
8812
8872
  }) : void 0;
8813
8873
  const reactionStore = new ReactionStore(paths.DB_FILE);
@@ -8853,6 +8913,18 @@ async function startServer() {
8853
8913
  }
8854
8914
 
8855
8915
  export {
8916
+ useDirectSupabase,
8917
+ getLocalCache,
8918
+ listMemberChannels,
8919
+ refreshCache,
8920
+ resolveChannelId,
8921
+ UsageStore,
8922
+ listActiveUsers,
8923
+ displayNameFor,
8924
+ refreshUserCache,
8925
+ resolveUserId,
8926
+ ensureUsersCached,
8927
+ useLocalCache,
8856
8928
  isEffort,
8857
8929
  DEFAULT_CODEX_MODEL,
8858
8930
  mcpStrictConfigEnabled,
@@ -8872,7 +8944,6 @@ export {
8872
8944
  getChannelRegistry,
8873
8945
  getProfileChannelRegistry,
8874
8946
  findChannelById,
8875
- findChannelByAgentName,
8876
8947
  findChannel,
8877
8948
  startChannelRegistryPolling,
8878
8949
  isCwdUsable,
@@ -8890,7 +8961,6 @@ export {
8890
8961
  ensureMemberDmChannel,
8891
8962
  DEFAULT_TIMEZONE,
8892
8963
  loadAutomations,
8893
- loadAutomationsFile,
8894
8964
  loadEffectiveAutomations,
8895
8965
  BUILT_IN_OUTPUT_STYLES,
8896
8966
  OutputStyleConflictError,
@@ -8949,7 +9019,6 @@ export {
8949
9019
  createWorkspace,
8950
9020
  deleteWorkspace,
8951
9021
  setWorkspaceStripeSubscription,
8952
- markWorkspaceAgentConnected,
8953
9022
  markWorkspaceProjectsSetup,
8954
9023
  markWorkspaceGreeted,
8955
9024
  getWorkspaceGreetedAt,
@@ -8979,41 +9048,30 @@ export {
8979
9048
  getAgentPaused,
8980
9049
  setAgentPaused,
8981
9050
  loadAgentMemory,
8982
- DEFAULT_TITLE_RULES,
8983
9051
  extractCategories,
8984
9052
  buildAutoTitle,
8985
9053
  BRANDING_DEFAULTS,
8986
9054
  getWorkspaceBranding,
8987
- localDefaults,
8988
- loadDashboardSettings,
8989
- saveDashboardSettings,
9055
+ upsertWorkspaceBranding,
8990
9056
  loadWorkspaceBranding,
8991
9057
  saveWorkspaceBranding,
8992
- loadFullDashboardSettings,
8993
9058
  loadWorkspacePrompt,
8994
- saveWorkspacePrompt,
8995
- resetWorkspacePrompt,
8996
- saveAgentProfile,
8997
9059
  BOT_PROFILE_KEY,
8998
9060
  loadBotIdentity,
8999
9061
  saveBotIdentity,
9062
+ loadDashboardSettings,
9063
+ saveDashboardSettings,
9064
+ loadFullDashboardSettings,
9065
+ saveWorkspacePrompt,
9066
+ resetWorkspacePrompt,
9067
+ saveAgentProfile,
9000
9068
  codexAuthAvailable,
9001
9069
  askCodex,
9002
9070
  markdownToBlocks,
9003
9071
  blockToFallbackText,
9004
- lookupById,
9005
- listMemberChannels,
9006
- refreshCache,
9007
- resolveChannelId,
9008
9072
  runAutomation,
9009
9073
  runScriptAutomation,
9010
9074
  AutomationManager,
9011
- listActiveUsers,
9012
- listUsersWithAvatars,
9013
- displayNameFor,
9014
- refreshUserCache,
9015
- resolveUserId,
9016
- ensureUsersCached,
9017
9075
  MessageQueue,
9018
9076
  mimetypeSizeLimit,
9019
9077
  buildFilesPromptSection,
@@ -9033,11 +9091,9 @@ export {
9033
9091
  listSkills,
9034
9092
  listPluginSkillDetails,
9035
9093
  findSkillDetail,
9036
- AutomationRunStore,
9037
9094
  recentRunsForWorkspace,
9038
9095
  lastRunsForWorkspace,
9039
9096
  SessionStore,
9040
- UsageStore,
9041
9097
  installUsageRecording,
9042
9098
  startServer
9043
9099
  };