flyspace-cli 0.1.57 → 0.1.58
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/{chunk-3KXMQCGD.js → chunk-TAUF3WGB.js} +819 -485
- package/dist/cli.js +266 -498
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
getR2Bucket,
|
|
26
26
|
getR2Client,
|
|
27
27
|
getSupabaseClient,
|
|
28
|
+
hasSupabaseCredentials,
|
|
28
29
|
isChannelAccessAllowed,
|
|
29
30
|
isEffort,
|
|
30
31
|
isHumanAuthor,
|
|
@@ -44,6 +45,7 @@ import {
|
|
|
44
45
|
resolveModel,
|
|
45
46
|
resolveOwnPersona,
|
|
46
47
|
runWithProfile,
|
|
48
|
+
setSupabaseClient,
|
|
47
49
|
setSupabaseClientFactory,
|
|
48
50
|
startChannelRegistryPolling,
|
|
49
51
|
sweepScratchDir,
|
|
@@ -9284,7 +9286,7 @@ var require_sign = __commonJS({
|
|
|
9284
9286
|
"../../node_modules/.pnpm/math-intrinsics@1.1.0/node_modules/math-intrinsics/sign.js"(exports, module) {
|
|
9285
9287
|
"use strict";
|
|
9286
9288
|
var $isNaN = require_isNaN();
|
|
9287
|
-
module.exports = function
|
|
9289
|
+
module.exports = function sign2(number) {
|
|
9288
9290
|
if ($isNaN(number) || number === 0) {
|
|
9289
9291
|
return number;
|
|
9290
9292
|
}
|
|
@@ -9648,7 +9650,7 @@ var require_get_intrinsic = __commonJS({
|
|
|
9648
9650
|
var min = require_min();
|
|
9649
9651
|
var pow = require_pow();
|
|
9650
9652
|
var round = require_round();
|
|
9651
|
-
var
|
|
9653
|
+
var sign2 = require_sign();
|
|
9652
9654
|
var $Function = Function;
|
|
9653
9655
|
var getEvalledConstructor = function(expressionSyntax) {
|
|
9654
9656
|
try {
|
|
@@ -9762,7 +9764,7 @@ var require_get_intrinsic = __commonJS({
|
|
|
9762
9764
|
"%Math.min%": min,
|
|
9763
9765
|
"%Math.pow%": pow,
|
|
9764
9766
|
"%Math.round%": round,
|
|
9765
|
-
"%Math.sign%":
|
|
9767
|
+
"%Math.sign%": sign2,
|
|
9766
9768
|
"%Reflect.getPrototypeOf%": $ReflectGPO
|
|
9767
9769
|
};
|
|
9768
9770
|
if (getProto) {
|
|
@@ -10952,7 +10954,7 @@ var require_supports_color = __commonJS({
|
|
|
10952
10954
|
return 1;
|
|
10953
10955
|
}
|
|
10954
10956
|
if ("CI" in env) {
|
|
10955
|
-
if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE", "DRONE"].some((
|
|
10957
|
+
if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE", "DRONE"].some((sign2) => sign2 in env) || env.CI_NAME === "codeship") {
|
|
10956
10958
|
return 1;
|
|
10957
10959
|
}
|
|
10958
10960
|
return min;
|
|
@@ -20926,6 +20928,555 @@ async function runCompanion(config, userId, slot) {
|
|
|
20926
20928
|
}
|
|
20927
20929
|
}
|
|
20928
20930
|
|
|
20931
|
+
// src/commands/persona.ts
|
|
20932
|
+
import { execFileSync as execFileSync5 } from "child_process";
|
|
20933
|
+
import { createHash as createHash3 } from "crypto";
|
|
20934
|
+
import { existsSync as existsSync9, mkdtempSync as mkdtempSync2, readdirSync as readdirSync2, readFileSync as readFileSync6, renameSync as renameSync2, rmSync as rmSync5, writeFileSync as writeFileSync5 } from "fs";
|
|
20935
|
+
import { homedir as homedir3 } from "os";
|
|
20936
|
+
import { basename as basename2, join as join8 } from "path";
|
|
20937
|
+
import sharp from "sharp";
|
|
20938
|
+
|
|
20939
|
+
// src/auth/device-auth.ts
|
|
20940
|
+
import { createPrivateKey, createPublicKey, generateKeyPairSync, sign } from "crypto";
|
|
20941
|
+
import { existsSync as existsSync8, mkdirSync as mkdirSync5, readFileSync as readFileSync4, rmSync as rmSync3, writeFileSync as writeFileSync3 } from "fs";
|
|
20942
|
+
import { dirname, join as join6 } from "path";
|
|
20943
|
+
var DEFAULT_API_URL = "https://app.flyspace.ai";
|
|
20944
|
+
var EXPIRY_SKEW_MS = 6e4;
|
|
20945
|
+
var AuthApiError = class extends Error {
|
|
20946
|
+
constructor(message, status) {
|
|
20947
|
+
super(message);
|
|
20948
|
+
this.status = status;
|
|
20949
|
+
this.name = "AuthApiError";
|
|
20950
|
+
}
|
|
20951
|
+
};
|
|
20952
|
+
function apiUrl() {
|
|
20953
|
+
return (process.env["FLYSPACE_API_URL"] || DEFAULT_API_URL).replace(/\/+$/, "");
|
|
20954
|
+
}
|
|
20955
|
+
function deviceKeyPath() {
|
|
20956
|
+
return join6(paths.BASE_CONFIG_DIR, "device.key");
|
|
20957
|
+
}
|
|
20958
|
+
function credentialsPath() {
|
|
20959
|
+
return join6(paths.BASE_CONFIG_DIR, "credentials.json");
|
|
20960
|
+
}
|
|
20961
|
+
function ensureDeviceKey(path = deviceKeyPath()) {
|
|
20962
|
+
let created = false;
|
|
20963
|
+
if (!existsSync8(path)) {
|
|
20964
|
+
const { privateKey: privateKey2 } = generateKeyPairSync("ed25519");
|
|
20965
|
+
mkdirSync5(dirname(path), { recursive: true });
|
|
20966
|
+
writeFileSync3(path, privateKey2.export({ type: "pkcs8", format: "pem" }), { mode: 384 });
|
|
20967
|
+
created = true;
|
|
20968
|
+
}
|
|
20969
|
+
const privateKey = createPrivateKey(readFileSync4(path, "utf8"));
|
|
20970
|
+
const publicKeyBase64 = createPublicKey(privateKey).export({ type: "spki", format: "der" }).toString(
|
|
20971
|
+
"base64"
|
|
20972
|
+
);
|
|
20973
|
+
return { privateKey, publicKeyBase64, created };
|
|
20974
|
+
}
|
|
20975
|
+
function loadCredentials(path = credentialsPath()) {
|
|
20976
|
+
if (!existsSync8(path)) return null;
|
|
20977
|
+
try {
|
|
20978
|
+
return JSON.parse(readFileSync4(path, "utf8"));
|
|
20979
|
+
} catch {
|
|
20980
|
+
return null;
|
|
20981
|
+
}
|
|
20982
|
+
}
|
|
20983
|
+
function saveCredentials(creds, path = credentialsPath()) {
|
|
20984
|
+
mkdirSync5(dirname(path), { recursive: true });
|
|
20985
|
+
writeFileSync3(path, `${JSON.stringify(creds, null, 2)}
|
|
20986
|
+
`, { mode: 384 });
|
|
20987
|
+
}
|
|
20988
|
+
function clearLocalAuth() {
|
|
20989
|
+
rmSync3(credentialsPath(), { force: true });
|
|
20990
|
+
rmSync3(deviceKeyPath(), { force: true });
|
|
20991
|
+
}
|
|
20992
|
+
async function post(base, path, body, token) {
|
|
20993
|
+
return fetch(`${base}${path}`, {
|
|
20994
|
+
method: "POST",
|
|
20995
|
+
headers: {
|
|
20996
|
+
"content-type": "application/json",
|
|
20997
|
+
...token ? { authorization: `Bearer ${token}` } : {}
|
|
20998
|
+
},
|
|
20999
|
+
body: JSON.stringify(body)
|
|
21000
|
+
});
|
|
21001
|
+
}
|
|
21002
|
+
async function readJson(res) {
|
|
21003
|
+
try {
|
|
21004
|
+
return await res.json();
|
|
21005
|
+
} catch {
|
|
21006
|
+
return {};
|
|
21007
|
+
}
|
|
21008
|
+
}
|
|
21009
|
+
async function expectOk(res, what) {
|
|
21010
|
+
const json = await readJson(res);
|
|
21011
|
+
if (!res.ok) {
|
|
21012
|
+
const reason = typeof json["error"] === "string" ? json["error"] : res.statusText;
|
|
21013
|
+
throw new AuthApiError(`${what} failed (${res.status}): ${reason}`, res.status);
|
|
21014
|
+
}
|
|
21015
|
+
return json;
|
|
21016
|
+
}
|
|
21017
|
+
function toSlugs(value) {
|
|
21018
|
+
return Array.isArray(value) ? value.filter((v) => typeof v === "string") : [];
|
|
21019
|
+
}
|
|
21020
|
+
function toGrant(json) {
|
|
21021
|
+
const user = json["user"] ?? {};
|
|
21022
|
+
return {
|
|
21023
|
+
accessToken: String(json["access_token"]),
|
|
21024
|
+
expiresIn: Number(json["expires_in"]),
|
|
21025
|
+
deviceId: String(json["device_id"]),
|
|
21026
|
+
userEmail: String(user["email"] ?? ""),
|
|
21027
|
+
workspaces: toSlugs(json["workspaces"])
|
|
21028
|
+
};
|
|
21029
|
+
}
|
|
21030
|
+
async function requestDeviceCode(base, input) {
|
|
21031
|
+
const res = await post(base, "/api/auth/device/code", {
|
|
21032
|
+
public_key: input.publicKey,
|
|
21033
|
+
name: input.name,
|
|
21034
|
+
platform: input.platform
|
|
21035
|
+
});
|
|
21036
|
+
const json = await expectOk(res, "Requesting a device code");
|
|
21037
|
+
return {
|
|
21038
|
+
deviceCode: String(json["device_code"]),
|
|
21039
|
+
userCode: String(json["user_code"]),
|
|
21040
|
+
verificationUri: String(json["verification_uri"]),
|
|
21041
|
+
expiresIn: Number(json["expires_in"]),
|
|
21042
|
+
interval: Number(json["interval"] ?? 5)
|
|
21043
|
+
};
|
|
21044
|
+
}
|
|
21045
|
+
async function pollDeviceToken(base, deviceCode) {
|
|
21046
|
+
const res = await post(base, "/api/auth/device/token", { device_code: deviceCode });
|
|
21047
|
+
const json = await readJson(res);
|
|
21048
|
+
if (res.ok) return { status: "approved", grant: toGrant(json) };
|
|
21049
|
+
switch (json["error"]) {
|
|
21050
|
+
case "authorization_pending":
|
|
21051
|
+
return { status: "pending" };
|
|
21052
|
+
case "slow_down":
|
|
21053
|
+
return { status: "slow_down" };
|
|
21054
|
+
case "access_denied":
|
|
21055
|
+
return { status: "denied" };
|
|
21056
|
+
case "expired_token":
|
|
21057
|
+
return { status: "expired" };
|
|
21058
|
+
default:
|
|
21059
|
+
throw new AuthApiError(`Polling for approval failed (${res.status}): ${String(json["error"] ?? res.statusText)}`, res.status);
|
|
21060
|
+
}
|
|
21061
|
+
}
|
|
21062
|
+
async function refreshAccessToken(creds, privateKey) {
|
|
21063
|
+
const challenge = await expectOk(
|
|
21064
|
+
await post(creds.apiUrl, "/api/auth/device/challenge", { device_id: creds.deviceId }),
|
|
21065
|
+
"Requesting a refresh challenge"
|
|
21066
|
+
);
|
|
21067
|
+
const nonce = String(challenge["nonce"]);
|
|
21068
|
+
const signature = sign(null, Buffer.from(nonce), privateKey).toString("base64");
|
|
21069
|
+
const json = await expectOk(
|
|
21070
|
+
await post(creds.apiUrl, "/api/auth/device/refresh", { device_id: creds.deviceId, nonce, signature }),
|
|
21071
|
+
"Refreshing the access token"
|
|
21072
|
+
);
|
|
21073
|
+
return {
|
|
21074
|
+
...creds,
|
|
21075
|
+
accessToken: String(json["access_token"]),
|
|
21076
|
+
accessTokenExpiresAt: Date.now() + Number(json["expires_in"]) * 1e3
|
|
21077
|
+
};
|
|
21078
|
+
}
|
|
21079
|
+
async function fetchWhoAmI(base, token) {
|
|
21080
|
+
const res = await fetch(`${base}/api/auth/device/me`, { headers: { authorization: `Bearer ${token}` } });
|
|
21081
|
+
const json = await expectOk(res, "Checking the session");
|
|
21082
|
+
const user = json["user"] ?? {};
|
|
21083
|
+
const device = json["device"] ?? {};
|
|
21084
|
+
return {
|
|
21085
|
+
userEmail: String(user["email"] ?? ""),
|
|
21086
|
+
deviceId: String(device["id"] ?? ""),
|
|
21087
|
+
deviceName: String(device["name"] ?? ""),
|
|
21088
|
+
workspaces: toSlugs(json["workspaces"])
|
|
21089
|
+
};
|
|
21090
|
+
}
|
|
21091
|
+
async function boundWorkspaces() {
|
|
21092
|
+
const creds = loadCredentials();
|
|
21093
|
+
if (!creds) return null;
|
|
21094
|
+
try {
|
|
21095
|
+
const me = await fetchWhoAmI(creds.apiUrl, await getAccessToken());
|
|
21096
|
+
saveCredentials({ ...loadCredentials() ?? creds, workspaces: me.workspaces });
|
|
21097
|
+
return { workspaces: me.workspaces, fresh: true };
|
|
21098
|
+
} catch {
|
|
21099
|
+
return { workspaces: creds.workspaces ?? [], fresh: false };
|
|
21100
|
+
}
|
|
21101
|
+
}
|
|
21102
|
+
async function revokeDevice(base, token) {
|
|
21103
|
+
await expectOk(await post(base, "/api/auth/device/revoke", {}, token), "Revoking this device");
|
|
21104
|
+
}
|
|
21105
|
+
async function getAccessToken() {
|
|
21106
|
+
const fromEnv = process.env["FLYSPACE_TOKEN"];
|
|
21107
|
+
if (fromEnv) return fromEnv;
|
|
21108
|
+
const creds = loadCredentials();
|
|
21109
|
+
if (!creds) return null;
|
|
21110
|
+
if (creds.accessTokenExpiresAt - EXPIRY_SKEW_MS > Date.now()) return creds.accessToken;
|
|
21111
|
+
const { privateKey } = ensureDeviceKey();
|
|
21112
|
+
const refreshed = await refreshAccessToken(creds, privateKey);
|
|
21113
|
+
saveCredentials(refreshed);
|
|
21114
|
+
return refreshed.accessToken;
|
|
21115
|
+
}
|
|
21116
|
+
|
|
21117
|
+
// src/dashboard/host-db-client.ts
|
|
21118
|
+
import { createClient } from "@supabase/supabase-js";
|
|
21119
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
21120
|
+
|
|
21121
|
+
// src/dashboard/host-lock.ts
|
|
21122
|
+
import { execFileSync as execFileSync4 } from "child_process";
|
|
21123
|
+
import { randomBytes } from "crypto";
|
|
21124
|
+
import { mkdirSync as mkdirSync6, readFileSync as readFileSync5, rmSync as rmSync4, writeFileSync as writeFileSync4 } from "fs";
|
|
21125
|
+
import { join as join7 } from "path";
|
|
21126
|
+
function hostLockPath() {
|
|
21127
|
+
return join7(paths.BASE_DATA_DIR, "host.lock");
|
|
21128
|
+
}
|
|
21129
|
+
function isLiveFlyspace(pid) {
|
|
21130
|
+
try {
|
|
21131
|
+
process.kill(pid, 0);
|
|
21132
|
+
const command = execFileSync4("ps", ["-p", String(pid), "-o", "command="], {
|
|
21133
|
+
encoding: "utf8"
|
|
21134
|
+
});
|
|
21135
|
+
return command.includes("flyspace") || command.includes("host-server");
|
|
21136
|
+
} catch {
|
|
21137
|
+
return false;
|
|
21138
|
+
}
|
|
21139
|
+
}
|
|
21140
|
+
function readLockPid(path) {
|
|
21141
|
+
try {
|
|
21142
|
+
const pid = Number(JSON.parse(readFileSync5(path, "utf8")).pid);
|
|
21143
|
+
return Number.isInteger(pid) && pid > 0 ? pid : null;
|
|
21144
|
+
} catch {
|
|
21145
|
+
return null;
|
|
21146
|
+
}
|
|
21147
|
+
}
|
|
21148
|
+
function acquireHostLock() {
|
|
21149
|
+
const path = hostLockPath();
|
|
21150
|
+
mkdirSync6(paths.BASE_DATA_DIR, { recursive: true });
|
|
21151
|
+
const body = JSON.stringify({
|
|
21152
|
+
pid: process.pid,
|
|
21153
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
21154
|
+
execPath: process.argv[1] ?? ""
|
|
21155
|
+
});
|
|
21156
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
21157
|
+
try {
|
|
21158
|
+
writeFileSync4(path, body, { flag: "wx", mode: 384 });
|
|
21159
|
+
const release = () => {
|
|
21160
|
+
if (readLockPid(path) === process.pid) rmSync4(path, { force: true });
|
|
21161
|
+
};
|
|
21162
|
+
process.once("exit", release);
|
|
21163
|
+
return release;
|
|
21164
|
+
} catch (err) {
|
|
21165
|
+
if (err.code !== "EEXIST") throw err;
|
|
21166
|
+
const holder = readLockPid(path);
|
|
21167
|
+
if (holder === process.pid) return () => {
|
|
21168
|
+
};
|
|
21169
|
+
if (holder && isLiveFlyspace(holder)) {
|
|
21170
|
+
throw new Error(
|
|
21171
|
+
`Another Flyspace Host is already running on this machine (pid ${holder}). Stop it first, or check for a second CLI install (\`which -a flyspace\`). Two Hosts overwrite each other's skill mirror.`
|
|
21172
|
+
);
|
|
21173
|
+
}
|
|
21174
|
+
rmSync4(path, { force: true });
|
|
21175
|
+
}
|
|
21176
|
+
}
|
|
21177
|
+
throw new Error(`Could not take the Host lock at ${path}`);
|
|
21178
|
+
}
|
|
21179
|
+
function publishHostEndpoint(port) {
|
|
21180
|
+
const path = hostLockPath();
|
|
21181
|
+
if (readLockPid(path) !== process.pid) return null;
|
|
21182
|
+
const token = randomBytes(32).toString("hex");
|
|
21183
|
+
const lock = JSON.parse(readFileSync5(path, "utf8"));
|
|
21184
|
+
writeFileSync4(path, JSON.stringify({ ...lock, port, token }), { mode: 384 });
|
|
21185
|
+
return token;
|
|
21186
|
+
}
|
|
21187
|
+
function readHostEndpoint() {
|
|
21188
|
+
try {
|
|
21189
|
+
const { pid, port, token } = JSON.parse(readFileSync5(hostLockPath(), "utf8"));
|
|
21190
|
+
if (pid === process.pid || !Number.isInteger(port) || typeof token !== "string") return null;
|
|
21191
|
+
return { port, token };
|
|
21192
|
+
} catch {
|
|
21193
|
+
return null;
|
|
21194
|
+
}
|
|
21195
|
+
}
|
|
21196
|
+
|
|
21197
|
+
// src/dashboard/host-db-client.ts
|
|
21198
|
+
var REQUEST_TIMEOUT_MS2 = 3e4;
|
|
21199
|
+
var pending = /* @__PURE__ */ new Map();
|
|
21200
|
+
var sender = null;
|
|
21201
|
+
var onSender = [];
|
|
21202
|
+
function setHostDbSender(fn) {
|
|
21203
|
+
sender = fn;
|
|
21204
|
+
if (!fn) return;
|
|
21205
|
+
const waiting = onSender;
|
|
21206
|
+
onSender = [];
|
|
21207
|
+
for (const wake of waiting) wake();
|
|
21208
|
+
}
|
|
21209
|
+
function sendAgentFailure(report) {
|
|
21210
|
+
sender?.({ type: "agent-failure", ...report });
|
|
21211
|
+
}
|
|
21212
|
+
function handleHostDbResult(id, res) {
|
|
21213
|
+
const p = pending.get(id);
|
|
21214
|
+
if (!p) return;
|
|
21215
|
+
pending.delete(id);
|
|
21216
|
+
clearTimeout(p.timer);
|
|
21217
|
+
p.resolve(res);
|
|
21218
|
+
}
|
|
21219
|
+
function whenConnected() {
|
|
21220
|
+
if (sender) return Promise.resolve(sender);
|
|
21221
|
+
return new Promise((resolve8, reject) => {
|
|
21222
|
+
const timer = setTimeout(() => {
|
|
21223
|
+
onSender = onSender.filter((w) => w !== wake);
|
|
21224
|
+
reject(new Error("Host is not connected to the Data API"));
|
|
21225
|
+
}, REQUEST_TIMEOUT_MS2);
|
|
21226
|
+
const wake = () => {
|
|
21227
|
+
clearTimeout(timer);
|
|
21228
|
+
resolve8(sender);
|
|
21229
|
+
};
|
|
21230
|
+
onSender.push(wake);
|
|
21231
|
+
});
|
|
21232
|
+
}
|
|
21233
|
+
async function requestHostDb(req) {
|
|
21234
|
+
const send = await whenConnected();
|
|
21235
|
+
const id = randomUUID2();
|
|
21236
|
+
return new Promise((resolve8, reject) => {
|
|
21237
|
+
const timer = setTimeout(() => {
|
|
21238
|
+
pending.delete(id);
|
|
21239
|
+
reject(new Error("Data API did not answer in time"));
|
|
21240
|
+
}, REQUEST_TIMEOUT_MS2);
|
|
21241
|
+
pending.set(id, { resolve: resolve8, reject, timer });
|
|
21242
|
+
send({ type: "db", id, req });
|
|
21243
|
+
});
|
|
21244
|
+
}
|
|
21245
|
+
var pendingUrls = /* @__PURE__ */ new Map();
|
|
21246
|
+
function handleAttachmentUrlResult(id, url) {
|
|
21247
|
+
pendingUrls.get(id)?.(url);
|
|
21248
|
+
pendingUrls.delete(id);
|
|
21249
|
+
}
|
|
21250
|
+
async function requestAttachmentUrl(key) {
|
|
21251
|
+
const send = await whenConnected();
|
|
21252
|
+
const id = randomUUID2();
|
|
21253
|
+
return new Promise((resolve8, reject) => {
|
|
21254
|
+
const timer = setTimeout(() => {
|
|
21255
|
+
pendingUrls.delete(id);
|
|
21256
|
+
reject(new Error("Data API did not answer in time"));
|
|
21257
|
+
}, REQUEST_TIMEOUT_MS2);
|
|
21258
|
+
pendingUrls.set(id, (url) => {
|
|
21259
|
+
clearTimeout(timer);
|
|
21260
|
+
resolve8(url);
|
|
21261
|
+
});
|
|
21262
|
+
send({ type: "attachment-url", id, key });
|
|
21263
|
+
});
|
|
21264
|
+
}
|
|
21265
|
+
var pendingRespond = /* @__PURE__ */ new Map();
|
|
21266
|
+
function handleShouldRespondResult(id, respond) {
|
|
21267
|
+
pendingRespond.get(id)?.(respond);
|
|
21268
|
+
pendingRespond.delete(id);
|
|
21269
|
+
}
|
|
21270
|
+
async function requestShouldRespond(transcript) {
|
|
21271
|
+
const send = await whenConnected().catch(() => null);
|
|
21272
|
+
if (!send) return false;
|
|
21273
|
+
const id = randomUUID2();
|
|
21274
|
+
return new Promise((resolve8) => {
|
|
21275
|
+
const timer = setTimeout(() => {
|
|
21276
|
+
pendingRespond.delete(id);
|
|
21277
|
+
resolve8(false);
|
|
21278
|
+
}, REQUEST_TIMEOUT_MS2);
|
|
21279
|
+
pendingRespond.set(id, (respond) => {
|
|
21280
|
+
clearTimeout(timer);
|
|
21281
|
+
resolve8(respond);
|
|
21282
|
+
});
|
|
21283
|
+
send({ type: "should-respond", id, transcript });
|
|
21284
|
+
});
|
|
21285
|
+
}
|
|
21286
|
+
var BODYLESS_STATUS = /* @__PURE__ */ new Set([101, 204, 205, 304]);
|
|
21287
|
+
function dbFetch(send) {
|
|
21288
|
+
return async (input, init) => {
|
|
21289
|
+
const req = new Request(input, init);
|
|
21290
|
+
const url = new URL(req.url);
|
|
21291
|
+
const method = req.method.toUpperCase();
|
|
21292
|
+
const res = await send({
|
|
21293
|
+
method,
|
|
21294
|
+
path: `${url.pathname}${url.search}`,
|
|
21295
|
+
headers: Object.fromEntries(req.headers.entries()),
|
|
21296
|
+
body: method === "GET" || method === "HEAD" ? void 0 : await req.text()
|
|
21297
|
+
});
|
|
21298
|
+
const noBody = method === "HEAD" || BODYLESS_STATUS.has(res.status);
|
|
21299
|
+
return new Response(noBody ? null : res.body, { status: res.status, headers: res.headers });
|
|
21300
|
+
};
|
|
21301
|
+
}
|
|
21302
|
+
var hostDbFetch = dbFetch(requestHostDb);
|
|
21303
|
+
var LOCAL_DB_PATH = "/internal/db";
|
|
21304
|
+
async function requestViaLocalHost(req) {
|
|
21305
|
+
const deadline = Date.now() + REQUEST_TIMEOUT_MS2;
|
|
21306
|
+
let endpoint = readHostEndpoint();
|
|
21307
|
+
while (!endpoint && Date.now() < deadline) {
|
|
21308
|
+
await new Promise((r) => setTimeout(r, 1e3));
|
|
21309
|
+
endpoint = readHostEndpoint();
|
|
21310
|
+
}
|
|
21311
|
+
if (!endpoint) throw new Error("No local Host to reach the Data API through");
|
|
21312
|
+
const res = await fetch(`http://127.0.0.1:${endpoint.port}${LOCAL_DB_PATH}`, {
|
|
21313
|
+
method: "POST",
|
|
21314
|
+
headers: { authorization: `Bearer ${endpoint.token}`, "content-type": "application/json" },
|
|
21315
|
+
body: JSON.stringify(req),
|
|
21316
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS2 + 5e3)
|
|
21317
|
+
});
|
|
21318
|
+
if (!res.ok) throw new Error(`Local Host DB relay answered ${res.status}`);
|
|
21319
|
+
return await res.json();
|
|
21320
|
+
}
|
|
21321
|
+
function relayChannel(topic) {
|
|
21322
|
+
const channel = {
|
|
21323
|
+
on: () => channel,
|
|
21324
|
+
subscribe: (callback) => {
|
|
21325
|
+
queueMicrotask(() => callback?.("SUBSCRIBED"));
|
|
21326
|
+
return channel;
|
|
21327
|
+
},
|
|
21328
|
+
send: async (msg) => {
|
|
21329
|
+
if (msg.type !== "broadcast" || !sender) return "error";
|
|
21330
|
+
sender({ type: "db-broadcast", topic, event: msg.event, payload: msg.payload ?? {} });
|
|
21331
|
+
return "ok";
|
|
21332
|
+
},
|
|
21333
|
+
unsubscribe: async () => "ok"
|
|
21334
|
+
};
|
|
21335
|
+
return channel;
|
|
21336
|
+
}
|
|
21337
|
+
function createHostDbClient(via = "socket") {
|
|
21338
|
+
const client = createClient("https://host-db.invalid", "host-device", {
|
|
21339
|
+
auth: { persistSession: false, autoRefreshToken: false },
|
|
21340
|
+
global: { fetch: via === "socket" ? hostDbFetch : dbFetch(requestViaLocalHost) }
|
|
21341
|
+
});
|
|
21342
|
+
return new Proxy(client, {
|
|
21343
|
+
get(target, prop) {
|
|
21344
|
+
if (prop === "channel") return relayChannel;
|
|
21345
|
+
if (prop === "removeChannel") return async () => "ok";
|
|
21346
|
+
const value = Reflect.get(target, prop, target);
|
|
21347
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
21348
|
+
}
|
|
21349
|
+
});
|
|
21350
|
+
}
|
|
21351
|
+
|
|
21352
|
+
// src/commands/supabase-via-host.ts
|
|
21353
|
+
function useHostDbWithoutCredentials() {
|
|
21354
|
+
const viaHost = !!loadCredentials() && (!hasSupabaseCredentials() || !!readHostEndpoint());
|
|
21355
|
+
if (viaHost) setSupabaseClient(createHostDbClient("local-host"));
|
|
21356
|
+
return viaHost;
|
|
21357
|
+
}
|
|
21358
|
+
|
|
21359
|
+
// src/commands/persona.ts
|
|
21360
|
+
var USAGE = `
|
|
21361
|
+
Usage: flyspace persona avatars [--character <id>] [--clear]
|
|
21362
|
+
|
|
21363
|
+
Use a claudecafe persona-panel character's faces (claudecafe.dev) as the
|
|
21364
|
+
workspace bot's avatars: a reply ending in her mood marker shows the matching
|
|
21365
|
+
face, and "neutral" becomes the bot's default avatar.
|
|
21366
|
+
|
|
21367
|
+
--character <id> Character folder under ~/.config/claudecafe/characters
|
|
21368
|
+
(default: "character" in its config.json, else kotone)
|
|
21369
|
+
--clear Remove the per-expression avatars
|
|
21370
|
+
`;
|
|
21371
|
+
var AVATAR_SIZE = 96;
|
|
21372
|
+
var PACKS = {
|
|
21373
|
+
kotone: {
|
|
21374
|
+
version: "1.4.0",
|
|
21375
|
+
url: "https://github.com/minipai/claudecafe/releases/download/kotone-characters-v1.4.0/ClaudeCafe-Kotone-characters-v1.4.0.zip",
|
|
21376
|
+
sha256: "7a0d8d9b7e52104feaff94be2745ad4179367325b2eb69432b94fc689a29f041"
|
|
21377
|
+
},
|
|
21378
|
+
kurumi: {
|
|
21379
|
+
version: "1.4.0",
|
|
21380
|
+
url: "https://github.com/minipai/claudecafe/releases/download/kurumi-characters-v1.4.0/ClaudeCafe-Kurumi-characters-v1.4.0.zip",
|
|
21381
|
+
sha256: "1f028c4189a0e605517d85089a19f8662789c1f8068ccdb9dba6069b6b8aa17b"
|
|
21382
|
+
},
|
|
21383
|
+
kokona: {
|
|
21384
|
+
version: "1.4.0",
|
|
21385
|
+
url: "https://github.com/minipai/claudecafe/releases/download/kokona-characters-v1.4.0/ClaudeCafe-Kokona-characters-v1.4.0.zip",
|
|
21386
|
+
sha256: "2151f12a2c8569bdab5c8d4df86c91da200c40946318a75e7c1c883604dbb9fb"
|
|
21387
|
+
}
|
|
21388
|
+
};
|
|
21389
|
+
function pluginInstalled() {
|
|
21390
|
+
const claudeDir = process.env["CLAUDE_CONFIG_DIR"] || join8(homedir3(), ".claude");
|
|
21391
|
+
return existsSync9(join8(claudeDir, "plugins", "cache", "claudecafe", "persona-panel"));
|
|
21392
|
+
}
|
|
21393
|
+
function installPack(root, character) {
|
|
21394
|
+
const pack = PACKS[character];
|
|
21395
|
+
if (!pack) throw new Error(`No published pack for "${character}".`);
|
|
21396
|
+
const charactersDir = join8(root, "characters");
|
|
21397
|
+
execFileSync5("mkdir", ["-p", charactersDir]);
|
|
21398
|
+
const staging = mkdtempSync2(join8(charactersDir, `.${character}-`));
|
|
21399
|
+
try {
|
|
21400
|
+
const zip = join8(staging, "pack.zip");
|
|
21401
|
+
execFileSync5("curl", ["-fsSL", "--max-time", "60", "-o", zip, pack.url]);
|
|
21402
|
+
const digest = createHash3("sha256").update(readFileSync6(zip)).digest("hex");
|
|
21403
|
+
if (digest !== pack.sha256) throw new Error(`${character} pack SHA-256 mismatch`);
|
|
21404
|
+
execFileSync5("unzip", ["-q", zip, "-d", staging]);
|
|
21405
|
+
const folder = join8(charactersDir, character);
|
|
21406
|
+
if (existsSync9(folder)) renameSync2(folder, join8(staging, "previous"));
|
|
21407
|
+
renameSync2(join8(staging, character), folder);
|
|
21408
|
+
} finally {
|
|
21409
|
+
rmSync5(staging, { recursive: true, force: true });
|
|
21410
|
+
}
|
|
21411
|
+
}
|
|
21412
|
+
function cafeRoot() {
|
|
21413
|
+
return join8(process.env["XDG_CONFIG_HOME"] || join8(homedir3(), ".config"), "claudecafe");
|
|
21414
|
+
}
|
|
21415
|
+
function configuredCharacter(root) {
|
|
21416
|
+
try {
|
|
21417
|
+
const config = JSON.parse(readFileSync6(join8(root, "config.json"), "utf8"));
|
|
21418
|
+
if (config.character && config.character !== "none") return config.character;
|
|
21419
|
+
} catch {
|
|
21420
|
+
}
|
|
21421
|
+
return "kotone";
|
|
21422
|
+
}
|
|
21423
|
+
async function runPersonaCmd(args) {
|
|
21424
|
+
if (args[0] !== "avatars") {
|
|
21425
|
+
console.log(USAGE);
|
|
21426
|
+
return;
|
|
21427
|
+
}
|
|
21428
|
+
loadEnvFiles();
|
|
21429
|
+
useHostDbWithoutCredentials();
|
|
21430
|
+
const profile = getProfile();
|
|
21431
|
+
if (args.includes("--clear")) {
|
|
21432
|
+
await upsertWorkspaceBranding(profile, { botExpressionAvatars: null });
|
|
21433
|
+
console.log("Cleared the per-expression bot avatars.");
|
|
21434
|
+
return;
|
|
21435
|
+
}
|
|
21436
|
+
const idx = args.indexOf("--character");
|
|
21437
|
+
const { character, count } = await syncPersonaAvatars(profile, idx !== -1 && args[idx + 1] || void 0);
|
|
21438
|
+
console.log(`Saved ${count} ${character} avatars.`);
|
|
21439
|
+
}
|
|
21440
|
+
var DEFAULT_BOT_NAMES = /* @__PURE__ */ new Set(["Bot", "Workspace Agent"]);
|
|
21441
|
+
async function syncPersonaAvatars(profile, requested) {
|
|
21442
|
+
const root = cafeRoot();
|
|
21443
|
+
const character = requested || configuredCharacter(root);
|
|
21444
|
+
const dir = join8(root, "characters", character, "avatars");
|
|
21445
|
+
if (!existsSync9(dir)) installPack(root, character);
|
|
21446
|
+
const avatars = {};
|
|
21447
|
+
for (const file of readdirSync2(dir).filter((f) => f.endsWith(".webp"))) {
|
|
21448
|
+
const image = await sharp(join8(dir, file)).resize({ width: AVATAR_SIZE, height: AVATAR_SIZE, fit: "cover", position: "top" }).webp({ quality: 80 }).toBuffer();
|
|
21449
|
+
avatars[basename2(file, ".webp")] = `data:image/webp;base64,${image.toString("base64")}`;
|
|
21450
|
+
}
|
|
21451
|
+
if (!Object.keys(avatars).length) throw new Error(`No .webp avatars in ${dir}.`);
|
|
21452
|
+
const current = (await getWorkspaceBranding(profile))?.botName?.trim();
|
|
21453
|
+
const keepName = current && !DEFAULT_BOT_NAMES.has(current);
|
|
21454
|
+
await upsertWorkspaceBranding(profile, {
|
|
21455
|
+
botExpressionAvatars: avatars,
|
|
21456
|
+
...keepName ? {} : { botName: character.charAt(0).toUpperCase() + character.slice(1) },
|
|
21457
|
+
...avatars["neutral"] ? { botAvatar: avatars["neutral"] } : {}
|
|
21458
|
+
});
|
|
21459
|
+
return { character, count: Object.keys(avatars).length };
|
|
21460
|
+
}
|
|
21461
|
+
async function autoSyncPersonaAvatars(profile) {
|
|
21462
|
+
if (!pluginInstalled() || !resolveOwnPersona(void 0)) return;
|
|
21463
|
+
const root = cafeRoot();
|
|
21464
|
+
const character = configuredCharacter(root);
|
|
21465
|
+
const stamp = `${character}@${PACKS[character]?.version ?? "local"}`;
|
|
21466
|
+
const marker = join8(root, `.flyspace-avatars-${profile}`);
|
|
21467
|
+
try {
|
|
21468
|
+
if (readFileSync6(marker, "utf8") === stamp) return;
|
|
21469
|
+
} catch {
|
|
21470
|
+
}
|
|
21471
|
+
try {
|
|
21472
|
+
const { count } = await syncPersonaAvatars(profile, character);
|
|
21473
|
+
writeFileSync5(marker, stamp);
|
|
21474
|
+
console.log(`[persona] synced ${count} ${character} avatars`);
|
|
21475
|
+
} catch (err) {
|
|
21476
|
+
console.warn(`[persona] avatar sync skipped: ${err.message}`);
|
|
21477
|
+
}
|
|
21478
|
+
}
|
|
21479
|
+
|
|
20929
21480
|
// ../api/src/feature-flags.ts
|
|
20930
21481
|
var featureFlags = {
|
|
20931
21482
|
"ai-cost": {
|
|
@@ -21392,8 +21943,8 @@ async function buildPrompt(profile, channelId, opts) {
|
|
|
21392
21943
|
}
|
|
21393
21944
|
|
|
21394
21945
|
// src/dashboard/settings-host.ts
|
|
21395
|
-
import { writeFileSync as
|
|
21396
|
-
import { dirname } from "path";
|
|
21946
|
+
import { writeFileSync as writeFileSync6, existsSync as existsSync10, mkdirSync as mkdirSync7, readFileSync as readFileSync7, rmSync as rmSync6 } from "fs";
|
|
21947
|
+
import { dirname as dirname2 } from "path";
|
|
21397
21948
|
|
|
21398
21949
|
// ../api/src/dashboard/auto-title.ts
|
|
21399
21950
|
var GROQ_API_URL = "https://api.groq.com/openai/v1/chat/completions";
|
|
@@ -21554,9 +22105,9 @@ function parseAgentProfiles(raw) {
|
|
|
21554
22105
|
return entries2.length > 0 ? Object.fromEntries(entries2) : void 0;
|
|
21555
22106
|
}
|
|
21556
22107
|
function loadDashboardSettings() {
|
|
21557
|
-
if (!
|
|
22108
|
+
if (!existsSync10(paths.DASHBOARD_SETTINGS_FILE)) return localDefaults();
|
|
21558
22109
|
try {
|
|
21559
|
-
const raw = JSON.parse(
|
|
22110
|
+
const raw = JSON.parse(readFileSync7(paths.DASHBOARD_SETTINGS_FILE, "utf-8"));
|
|
21560
22111
|
const providers = parseProviders(raw.providers, {
|
|
21561
22112
|
agent: normalizeDefaultModel(raw.agent, localDefaults().agent),
|
|
21562
22113
|
fallbackModel: typeof raw.fallbackModel === "string" && isAllowedModel(raw.fallbackModel) ? raw.fallbackModel : void 0
|
|
@@ -21583,9 +22134,9 @@ function withFallbackModel(providers, model) {
|
|
|
21583
22134
|
return [cleared[0], { runner, model }, ...cleared.slice(1).filter((p) => p.runner !== runner)];
|
|
21584
22135
|
}
|
|
21585
22136
|
function writeSettings(next) {
|
|
21586
|
-
|
|
22137
|
+
mkdirSync7(dirname2(paths.DASHBOARD_SETTINGS_FILE), { recursive: true });
|
|
21587
22138
|
const merged = { ...readSettingsFile() ?? {}, ...next };
|
|
21588
|
-
|
|
22139
|
+
writeFileSync6(paths.DASHBOARD_SETTINGS_FILE, JSON.stringify(merged, null, 2), "utf-8");
|
|
21589
22140
|
return next;
|
|
21590
22141
|
}
|
|
21591
22142
|
function saveDashboardSettings(patch) {
|
|
@@ -21619,13 +22170,13 @@ async function loadFullDashboardSettings(profile = getProfile()) {
|
|
|
21619
22170
|
function saveWorkspacePrompt(prompt) {
|
|
21620
22171
|
const trimmed = prompt.trim();
|
|
21621
22172
|
if (!trimmed || trimmed === loadWorkspacePrompt().defaultPrompt) return resetWorkspacePrompt();
|
|
21622
|
-
|
|
21623
|
-
|
|
22173
|
+
mkdirSync7(dirname2(paths.PROMPT_FILE), { recursive: true });
|
|
22174
|
+
writeFileSync6(paths.PROMPT_FILE, `${trimmed}
|
|
21624
22175
|
`, "utf-8");
|
|
21625
22176
|
return loadWorkspacePrompt();
|
|
21626
22177
|
}
|
|
21627
22178
|
function resetWorkspacePrompt() {
|
|
21628
|
-
|
|
22179
|
+
rmSync6(paths.PROMPT_FILE, { force: true });
|
|
21629
22180
|
return loadWorkspacePrompt();
|
|
21630
22181
|
}
|
|
21631
22182
|
function saveAgentProfile(name, patch) {
|
|
@@ -21650,9 +22201,9 @@ function saveAgentProfile(name, patch) {
|
|
|
21650
22201
|
|
|
21651
22202
|
// ../api/src/codex/agent.ts
|
|
21652
22203
|
import { spawn as spawn2 } from "child_process";
|
|
21653
|
-
import { existsSync as
|
|
22204
|
+
import { existsSync as existsSync11, mkdtempSync as mkdtempSync3, readFileSync as readFileSync8, rmSync as rmSync7, statSync as statSync3 } from "fs";
|
|
21654
22205
|
import { tmpdir as tmpdir2 } from "os";
|
|
21655
|
-
import { join as
|
|
22206
|
+
import { join as join9 } from "path";
|
|
21656
22207
|
var AUTH_ERROR_PATTERNS2 = [
|
|
21657
22208
|
/401 unauthorized/i,
|
|
21658
22209
|
/missing bearer or basic authentication/i,
|
|
@@ -21783,8 +22334,8 @@ function getMaxDurationMs2() {
|
|
|
21783
22334
|
}
|
|
21784
22335
|
function codexAuthAvailable(env = process.env) {
|
|
21785
22336
|
if (env["OPENAI_API_KEY"]?.trim()) return true;
|
|
21786
|
-
const home = env["CODEX_HOME"]?.trim() ||
|
|
21787
|
-
return
|
|
22337
|
+
const home = env["CODEX_HOME"]?.trim() || join9(env["HOME"] ?? "", ".codex");
|
|
22338
|
+
return existsSync11(join9(home, "auth.json"));
|
|
21788
22339
|
}
|
|
21789
22340
|
function applySystemPrompt(prompt, options, resumeSessionId) {
|
|
21790
22341
|
if (resumeSessionId || !options.systemPrompt?.trim()) return prompt;
|
|
@@ -21838,8 +22389,8 @@ function runCodexCli(prompt, cwd, options, resumeSessionId) {
|
|
|
21838
22389
|
recordCodexUsage(response, options);
|
|
21839
22390
|
resolve8(response);
|
|
21840
22391
|
};
|
|
21841
|
-
const scratch =
|
|
21842
|
-
const lastMessageFile =
|
|
22392
|
+
const scratch = mkdtempSync3(join9(tmpdir2(), "flyspace-codex-"));
|
|
22393
|
+
const lastMessageFile = join9(scratch, "last-message.txt");
|
|
21843
22394
|
const args = buildArgs2(prompt, options, lastMessageFile, resumeSessionId);
|
|
21844
22395
|
console.log(`[codex] spawning codex CLI in ${cwd}`);
|
|
21845
22396
|
console.log(`[codex] args: ${args.slice(0, -1).join(" ")}`);
|
|
@@ -21909,7 +22460,7 @@ function runCodexCli(prompt, cwd, options, resumeSessionId) {
|
|
|
21909
22460
|
const cleanup = () => {
|
|
21910
22461
|
clearTimeout(timeoutHandle);
|
|
21911
22462
|
if (signal) signal.removeEventListener("abort", onAbort);
|
|
21912
|
-
|
|
22463
|
+
rmSync7(scratch, { recursive: true, force: true });
|
|
21913
22464
|
};
|
|
21914
22465
|
child.stdout.setEncoding("utf8");
|
|
21915
22466
|
child.stderr.setEncoding("utf8");
|
|
@@ -21938,7 +22489,7 @@ function runCodexCli(prompt, cwd, options, resumeSessionId) {
|
|
|
21938
22489
|
child.on("close", (code, signal2) => {
|
|
21939
22490
|
let lastMessage = "";
|
|
21940
22491
|
try {
|
|
21941
|
-
lastMessage =
|
|
22492
|
+
lastMessage = readFileSync8(lastMessageFile, "utf8").trim();
|
|
21942
22493
|
} catch {
|
|
21943
22494
|
lastMessage = "";
|
|
21944
22495
|
}
|
|
@@ -21992,7 +22543,7 @@ function runCodexCli(prompt, cwd, options, resumeSessionId) {
|
|
|
21992
22543
|
});
|
|
21993
22544
|
}
|
|
21994
22545
|
async function askCodex(prompt, cwd, options = {}, resumeSessionId) {
|
|
21995
|
-
if (!
|
|
22546
|
+
if (!existsSync11(cwd) || !statSync3(cwd).isDirectory()) {
|
|
21996
22547
|
console.error(`[codex] working directory does not exist: ${cwd}`);
|
|
21997
22548
|
return {
|
|
21998
22549
|
sessionId: resumeSessionId ?? "",
|
|
@@ -22445,7 +22996,7 @@ function renderAsciiTable(t) {
|
|
|
22445
22996
|
}
|
|
22446
22997
|
|
|
22447
22998
|
// src/store/channel-cache.ts
|
|
22448
|
-
import { mkdirSync as
|
|
22999
|
+
import { mkdirSync as mkdirSync8 } from "fs";
|
|
22449
23000
|
|
|
22450
23001
|
// src/store/sqlite.ts
|
|
22451
23002
|
import Database from "better-sqlite3";
|
|
@@ -22469,7 +23020,7 @@ function getDb() {
|
|
|
22469
23020
|
const file = paths.DB_FILE;
|
|
22470
23021
|
const existing = dbs.get(file);
|
|
22471
23022
|
if (existing) return existing;
|
|
22472
|
-
|
|
23023
|
+
mkdirSync8(paths.DATA_DIR, { recursive: true });
|
|
22473
23024
|
const db = openLocalDatabase(file);
|
|
22474
23025
|
if (!db) return null;
|
|
22475
23026
|
db.exec(`
|
|
@@ -22985,17 +23536,17 @@ var TriggerEngine = class {
|
|
|
22985
23536
|
};
|
|
22986
23537
|
|
|
22987
23538
|
// src/store/user-cache.ts
|
|
22988
|
-
import { existsSync as
|
|
22989
|
-
import { join as
|
|
23539
|
+
import { existsSync as existsSync12, readFileSync as readFileSync9 } from "fs";
|
|
23540
|
+
import { join as join10 } from "path";
|
|
22990
23541
|
function jsonUserCachePath() {
|
|
22991
|
-
const file =
|
|
22992
|
-
return
|
|
23542
|
+
const file = join10(paths.CONFIG_DIR, "slack_users.json");
|
|
23543
|
+
return existsSync12(file) ? file : void 0;
|
|
22993
23544
|
}
|
|
22994
23545
|
function readJsonUserCache() {
|
|
22995
23546
|
const file = jsonUserCachePath();
|
|
22996
23547
|
if (!file) return void 0;
|
|
22997
23548
|
try {
|
|
22998
|
-
const parsed = JSON.parse(
|
|
23549
|
+
const parsed = JSON.parse(readFileSync9(file, "utf8"));
|
|
22999
23550
|
return parsed.users;
|
|
23000
23551
|
} catch {
|
|
23001
23552
|
return void 0;
|
|
@@ -23402,7 +23953,7 @@ var MessageQueue = class {
|
|
|
23402
23953
|
|
|
23403
23954
|
// src/slack/file-downloader.ts
|
|
23404
23955
|
import { writeFile } from "fs/promises";
|
|
23405
|
-
import { join as
|
|
23956
|
+
import { join as join11, extname } from "path";
|
|
23406
23957
|
var debug3 = process.env["DEBUG"] === "true";
|
|
23407
23958
|
var SUPPORTED_IMAGE_MIMETYPES = /* @__PURE__ */ new Set([
|
|
23408
23959
|
"image/png",
|
|
@@ -23502,7 +24053,7 @@ async function downloadOne(file, botToken) {
|
|
|
23502
24053
|
const ext = extname(originalName) || `.${file.filetype ?? "bin"}`;
|
|
23503
24054
|
const safeName = sanitizeFilename(originalName.replace(ext, ""));
|
|
23504
24055
|
const filename = `${Date.now()}-${file.id ?? "unnamed"}-${safeName}${ext}`;
|
|
23505
|
-
const localPath =
|
|
24056
|
+
const localPath = join11(paths.UPLOADS_DIR, filename);
|
|
23506
24057
|
await writeFile(localPath, buffer);
|
|
23507
24058
|
if (debug3)
|
|
23508
24059
|
console.log(`[file-downloader] saved ${file.id} -> ${localPath} (${buffer.length} bytes)`);
|
|
@@ -23672,9 +24223,9 @@ function identityHandleFor(slackUserId) {
|
|
|
23672
24223
|
}
|
|
23673
24224
|
|
|
23674
24225
|
// src/store/slack-avatar-sync.ts
|
|
23675
|
-
import
|
|
24226
|
+
import sharp2 from "sharp";
|
|
23676
24227
|
import { PutObjectCommand } from "@aws-sdk/client-s3";
|
|
23677
|
-
var
|
|
24228
|
+
var AVATAR_SIZE2 = 192;
|
|
23678
24229
|
function r2Configured() {
|
|
23679
24230
|
return Boolean(
|
|
23680
24231
|
process.env["CLOUDFLARE_R2_ACCOUNT_ID"] && process.env["CLOUDFLARE_R2_ACCESS_KEY_ID"] && process.env["CLOUDFLARE_R2_SECRET_ACCESS_KEY"] && process.env["CLOUDFLARE_R2_BUCKET_NAME"]
|
|
@@ -23696,7 +24247,7 @@ async function syncSlackAvatars(ids) {
|
|
|
23696
24247
|
const res = await fetch(row.image_url);
|
|
23697
24248
|
if (!res.ok) throw new Error(`fetch ${res.status}`);
|
|
23698
24249
|
const original = Buffer.from(await res.arrayBuffer());
|
|
23699
|
-
const resized = await
|
|
24250
|
+
const resized = await sharp2(original).resize({ width: AVATAR_SIZE2, height: AVATAR_SIZE2, fit: "cover" }).png().toBuffer();
|
|
23700
24251
|
const key = `avatar/slack/${getProfile()}/${id}.png`;
|
|
23701
24252
|
await getR2Client().send(
|
|
23702
24253
|
new PutObjectCommand({
|
|
@@ -23950,16 +24501,16 @@ async function summariseThreadTranscript(transcript, opts, deps = {}) {
|
|
|
23950
24501
|
}
|
|
23951
24502
|
|
|
23952
24503
|
// src/dashboard/chat-agent.ts
|
|
23953
|
-
import { homedir as
|
|
24504
|
+
import { homedir as homedir8 } from "os";
|
|
23954
24505
|
import { stripVTControlCharacters } from "util";
|
|
23955
24506
|
|
|
23956
24507
|
// src/mcp/config.ts
|
|
23957
|
-
import { mkdtempSync as
|
|
24508
|
+
import { mkdtempSync as mkdtempSync4, rmSync as rmSync8, writeFileSync as writeFileSync7 } from "fs";
|
|
23958
24509
|
import { tmpdir as tmpdir3 } from "os";
|
|
23959
|
-
import { join as
|
|
24510
|
+
import { join as join12 } from "path";
|
|
23960
24511
|
|
|
23961
24512
|
// ../api/src/mcp/crypto.ts
|
|
23962
|
-
import { createCipheriv, createDecipheriv, randomBytes, timingSafeEqual } from "crypto";
|
|
24513
|
+
import { createCipheriv, createDecipheriv, randomBytes as randomBytes2, timingSafeEqual } from "crypto";
|
|
23963
24514
|
var ALGORITHM = "aes-256-gcm";
|
|
23964
24515
|
var KEY_BYTES = 32;
|
|
23965
24516
|
var IV_BYTES = 12;
|
|
@@ -23992,7 +24543,7 @@ function currentKeyVersion() {
|
|
|
23992
24543
|
);
|
|
23993
24544
|
}
|
|
23994
24545
|
function encrypt(key, purpose, plaintext) {
|
|
23995
|
-
const iv =
|
|
24546
|
+
const iv = randomBytes2(IV_BYTES);
|
|
23996
24547
|
const cipher = createCipheriv(ALGORITHM, key, iv);
|
|
23997
24548
|
cipher.setAAD(Buffer.from(purpose, "utf8"));
|
|
23998
24549
|
const ciphertext = Buffer.concat([cipher.update(plaintext, "utf8"), cipher.final()]);
|
|
@@ -24012,7 +24563,7 @@ function decrypt(key, purpose, blob) {
|
|
|
24012
24563
|
}
|
|
24013
24564
|
function createEnvelope() {
|
|
24014
24565
|
const keyVersion = currentKeyVersion();
|
|
24015
|
-
const key =
|
|
24566
|
+
const key = randomBytes2(KEY_BYTES);
|
|
24016
24567
|
const wrappedDek = encrypt(
|
|
24017
24568
|
readMasterKey(keyVersion),
|
|
24018
24569
|
purposeForDek(keyVersion),
|
|
@@ -24078,7 +24629,7 @@ function secretsMatch(a, b) {
|
|
|
24078
24629
|
}
|
|
24079
24630
|
|
|
24080
24631
|
// ../api/src/mcp/oauth.ts
|
|
24081
|
-
import { createHash as
|
|
24632
|
+
import { createHash as createHash4, randomBytes as randomBytes3 } from "crypto";
|
|
24082
24633
|
var RESERVED_AUTHORIZE_PARAMS = /* @__PURE__ */ new Set([
|
|
24083
24634
|
"client_id",
|
|
24084
24635
|
"redirect_uri",
|
|
@@ -24092,11 +24643,11 @@ function base64url(buffer) {
|
|
|
24092
24643
|
return buffer.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
24093
24644
|
}
|
|
24094
24645
|
function createStateToken() {
|
|
24095
|
-
return base64url(
|
|
24646
|
+
return base64url(randomBytes3(32));
|
|
24096
24647
|
}
|
|
24097
24648
|
function createPkcePair() {
|
|
24098
|
-
const verifier = base64url(
|
|
24099
|
-
const challenge = base64url(
|
|
24649
|
+
const verifier = base64url(randomBytes3(32));
|
|
24650
|
+
const challenge = base64url(createHash4("sha256").update(verifier).digest());
|
|
24100
24651
|
return { verifier, challenge };
|
|
24101
24652
|
}
|
|
24102
24653
|
function clientEnvName(providerSlug, suffix) {
|
|
@@ -24216,7 +24767,7 @@ async function exchangeCode(params) {
|
|
|
24216
24767
|
);
|
|
24217
24768
|
return { ...tokens, scopes: tokens.scopes.length ? tokens.scopes : provider.defaultScopes };
|
|
24218
24769
|
}
|
|
24219
|
-
async function
|
|
24770
|
+
async function refreshAccessToken2(params) {
|
|
24220
24771
|
const { provider, client, refreshToken } = params;
|
|
24221
24772
|
return requestToken(
|
|
24222
24773
|
provider,
|
|
@@ -24502,7 +25053,7 @@ async function renew(workspaceId, connection, provider, deps) {
|
|
|
24502
25053
|
}
|
|
24503
25054
|
let tokens;
|
|
24504
25055
|
try {
|
|
24505
|
-
tokens = await
|
|
25056
|
+
tokens = await refreshAccessToken2({
|
|
24506
25057
|
provider,
|
|
24507
25058
|
client: readOAuthClient(provider.slug),
|
|
24508
25059
|
refreshToken,
|
|
@@ -24642,12 +25193,12 @@ async function buildMcpConfig(profile, connectionIds) {
|
|
|
24642
25193
|
return { config, skipped };
|
|
24643
25194
|
}
|
|
24644
25195
|
function writeMcpConfigFile(config) {
|
|
24645
|
-
const dir =
|
|
24646
|
-
const path =
|
|
24647
|
-
|
|
25196
|
+
const dir = mkdtempSync4(join12(tmpdir3(), "flyspace-mcp-"));
|
|
25197
|
+
const path = join12(dir, "mcp-config.json");
|
|
25198
|
+
writeFileSync7(path, JSON.stringify(config), { mode: 384 });
|
|
24648
25199
|
return {
|
|
24649
25200
|
path,
|
|
24650
|
-
cleanup: () =>
|
|
25201
|
+
cleanup: () => rmSync8(dir, { recursive: true, force: true })
|
|
24651
25202
|
};
|
|
24652
25203
|
}
|
|
24653
25204
|
async function withMcpConfig(profile, connectionIds, fn, extraServers = {}) {
|
|
@@ -24665,8 +25216,8 @@ async function withMcpConfig(profile, connectionIds, fn, extraServers = {}) {
|
|
|
24665
25216
|
}
|
|
24666
25217
|
|
|
24667
25218
|
// ../api/src/version.ts
|
|
24668
|
-
import { readFileSync as
|
|
24669
|
-
var CLI_VERSION = true ? "0.1.
|
|
25219
|
+
import { readFileSync as readFileSync10 } from "fs";
|
|
25220
|
+
var CLI_VERSION = true ? "0.1.58" : devVersion();
|
|
24670
25221
|
function isOlderVersion(a, b) {
|
|
24671
25222
|
const parse2 = (v) => v.replace(/^v/, "").split("-")[0].split(".").map(Number);
|
|
24672
25223
|
const [pa, pb] = [parse2(a), parse2(b)];
|
|
@@ -24688,278 +25239,43 @@ async function latestCliVersion() {
|
|
|
24688
25239
|
return version;
|
|
24689
25240
|
}
|
|
24690
25241
|
|
|
24691
|
-
// src/dashboard/host-db-client.ts
|
|
24692
|
-
import { createClient } from "@supabase/supabase-js";
|
|
24693
|
-
import { randomUUID as randomUUID2 } from "crypto";
|
|
24694
|
-
|
|
24695
|
-
// src/dashboard/host-lock.ts
|
|
24696
|
-
import { execFileSync as execFileSync4 } from "child_process";
|
|
24697
|
-
import { randomBytes as randomBytes3 } from "crypto";
|
|
24698
|
-
import { mkdirSync as mkdirSync7, readFileSync as readFileSync8, rmSync as rmSync6, writeFileSync as writeFileSync5 } from "fs";
|
|
24699
|
-
import { join as join10 } from "path";
|
|
24700
|
-
function hostLockPath() {
|
|
24701
|
-
return join10(paths.BASE_DATA_DIR, "host.lock");
|
|
24702
|
-
}
|
|
24703
|
-
function isLiveFlyspace(pid) {
|
|
24704
|
-
try {
|
|
24705
|
-
process.kill(pid, 0);
|
|
24706
|
-
const command = execFileSync4("ps", ["-p", String(pid), "-o", "command="], {
|
|
24707
|
-
encoding: "utf8"
|
|
24708
|
-
});
|
|
24709
|
-
return command.includes("flyspace") || command.includes("host-server");
|
|
24710
|
-
} catch {
|
|
24711
|
-
return false;
|
|
24712
|
-
}
|
|
24713
|
-
}
|
|
24714
|
-
function readLockPid(path) {
|
|
24715
|
-
try {
|
|
24716
|
-
const pid = Number(JSON.parse(readFileSync8(path, "utf8")).pid);
|
|
24717
|
-
return Number.isInteger(pid) && pid > 0 ? pid : null;
|
|
24718
|
-
} catch {
|
|
24719
|
-
return null;
|
|
24720
|
-
}
|
|
24721
|
-
}
|
|
24722
|
-
function acquireHostLock() {
|
|
24723
|
-
const path = hostLockPath();
|
|
24724
|
-
mkdirSync7(paths.BASE_DATA_DIR, { recursive: true });
|
|
24725
|
-
const body = JSON.stringify({
|
|
24726
|
-
pid: process.pid,
|
|
24727
|
-
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
24728
|
-
execPath: process.argv[1] ?? ""
|
|
24729
|
-
});
|
|
24730
|
-
for (let attempt = 0; attempt < 2; attempt++) {
|
|
24731
|
-
try {
|
|
24732
|
-
writeFileSync5(path, body, { flag: "wx", mode: 384 });
|
|
24733
|
-
const release = () => {
|
|
24734
|
-
if (readLockPid(path) === process.pid) rmSync6(path, { force: true });
|
|
24735
|
-
};
|
|
24736
|
-
process.once("exit", release);
|
|
24737
|
-
return release;
|
|
24738
|
-
} catch (err) {
|
|
24739
|
-
if (err.code !== "EEXIST") throw err;
|
|
24740
|
-
const holder = readLockPid(path);
|
|
24741
|
-
if (holder === process.pid) return () => {
|
|
24742
|
-
};
|
|
24743
|
-
if (holder && isLiveFlyspace(holder)) {
|
|
24744
|
-
throw new Error(
|
|
24745
|
-
`Another Flyspace Host is already running on this machine (pid ${holder}). Stop it first, or check for a second CLI install (\`which -a flyspace\`). Two Hosts overwrite each other's skill mirror.`
|
|
24746
|
-
);
|
|
24747
|
-
}
|
|
24748
|
-
rmSync6(path, { force: true });
|
|
24749
|
-
}
|
|
24750
|
-
}
|
|
24751
|
-
throw new Error(`Could not take the Host lock at ${path}`);
|
|
24752
|
-
}
|
|
24753
|
-
function publishHostEndpoint(port) {
|
|
24754
|
-
const path = hostLockPath();
|
|
24755
|
-
if (readLockPid(path) !== process.pid) return null;
|
|
24756
|
-
const token = randomBytes3(32).toString("hex");
|
|
24757
|
-
const lock = JSON.parse(readFileSync8(path, "utf8"));
|
|
24758
|
-
writeFileSync5(path, JSON.stringify({ ...lock, port, token }), { mode: 384 });
|
|
24759
|
-
return token;
|
|
24760
|
-
}
|
|
24761
|
-
function readHostEndpoint() {
|
|
24762
|
-
try {
|
|
24763
|
-
const { pid, port, token } = JSON.parse(readFileSync8(hostLockPath(), "utf8"));
|
|
24764
|
-
if (pid === process.pid || !Number.isInteger(port) || typeof token !== "string") return null;
|
|
24765
|
-
return { port, token };
|
|
24766
|
-
} catch {
|
|
24767
|
-
return null;
|
|
24768
|
-
}
|
|
24769
|
-
}
|
|
24770
|
-
|
|
24771
|
-
// src/dashboard/host-db-client.ts
|
|
24772
|
-
var REQUEST_TIMEOUT_MS2 = 3e4;
|
|
24773
|
-
var pending = /* @__PURE__ */ new Map();
|
|
24774
|
-
var sender = null;
|
|
24775
|
-
var onSender = [];
|
|
24776
|
-
function setHostDbSender(fn) {
|
|
24777
|
-
sender = fn;
|
|
24778
|
-
if (!fn) return;
|
|
24779
|
-
const waiting = onSender;
|
|
24780
|
-
onSender = [];
|
|
24781
|
-
for (const wake of waiting) wake();
|
|
24782
|
-
}
|
|
24783
|
-
function sendAgentFailure(report) {
|
|
24784
|
-
sender?.({ type: "agent-failure", ...report });
|
|
24785
|
-
}
|
|
24786
|
-
function handleHostDbResult(id, res) {
|
|
24787
|
-
const p = pending.get(id);
|
|
24788
|
-
if (!p) return;
|
|
24789
|
-
pending.delete(id);
|
|
24790
|
-
clearTimeout(p.timer);
|
|
24791
|
-
p.resolve(res);
|
|
24792
|
-
}
|
|
24793
|
-
function whenConnected() {
|
|
24794
|
-
if (sender) return Promise.resolve(sender);
|
|
24795
|
-
return new Promise((resolve8, reject) => {
|
|
24796
|
-
const timer = setTimeout(() => {
|
|
24797
|
-
onSender = onSender.filter((w) => w !== wake);
|
|
24798
|
-
reject(new Error("Host is not connected to the Data API"));
|
|
24799
|
-
}, REQUEST_TIMEOUT_MS2);
|
|
24800
|
-
const wake = () => {
|
|
24801
|
-
clearTimeout(timer);
|
|
24802
|
-
resolve8(sender);
|
|
24803
|
-
};
|
|
24804
|
-
onSender.push(wake);
|
|
24805
|
-
});
|
|
24806
|
-
}
|
|
24807
|
-
async function requestHostDb(req) {
|
|
24808
|
-
const send = await whenConnected();
|
|
24809
|
-
const id = randomUUID2();
|
|
24810
|
-
return new Promise((resolve8, reject) => {
|
|
24811
|
-
const timer = setTimeout(() => {
|
|
24812
|
-
pending.delete(id);
|
|
24813
|
-
reject(new Error("Data API did not answer in time"));
|
|
24814
|
-
}, REQUEST_TIMEOUT_MS2);
|
|
24815
|
-
pending.set(id, { resolve: resolve8, reject, timer });
|
|
24816
|
-
send({ type: "db", id, req });
|
|
24817
|
-
});
|
|
24818
|
-
}
|
|
24819
|
-
var pendingUrls = /* @__PURE__ */ new Map();
|
|
24820
|
-
function handleAttachmentUrlResult(id, url) {
|
|
24821
|
-
pendingUrls.get(id)?.(url);
|
|
24822
|
-
pendingUrls.delete(id);
|
|
24823
|
-
}
|
|
24824
|
-
async function requestAttachmentUrl(key) {
|
|
24825
|
-
const send = await whenConnected();
|
|
24826
|
-
const id = randomUUID2();
|
|
24827
|
-
return new Promise((resolve8, reject) => {
|
|
24828
|
-
const timer = setTimeout(() => {
|
|
24829
|
-
pendingUrls.delete(id);
|
|
24830
|
-
reject(new Error("Data API did not answer in time"));
|
|
24831
|
-
}, REQUEST_TIMEOUT_MS2);
|
|
24832
|
-
pendingUrls.set(id, (url) => {
|
|
24833
|
-
clearTimeout(timer);
|
|
24834
|
-
resolve8(url);
|
|
24835
|
-
});
|
|
24836
|
-
send({ type: "attachment-url", id, key });
|
|
24837
|
-
});
|
|
24838
|
-
}
|
|
24839
|
-
var pendingRespond = /* @__PURE__ */ new Map();
|
|
24840
|
-
function handleShouldRespondResult(id, respond) {
|
|
24841
|
-
pendingRespond.get(id)?.(respond);
|
|
24842
|
-
pendingRespond.delete(id);
|
|
24843
|
-
}
|
|
24844
|
-
async function requestShouldRespond(transcript) {
|
|
24845
|
-
const send = await whenConnected().catch(() => null);
|
|
24846
|
-
if (!send) return false;
|
|
24847
|
-
const id = randomUUID2();
|
|
24848
|
-
return new Promise((resolve8) => {
|
|
24849
|
-
const timer = setTimeout(() => {
|
|
24850
|
-
pendingRespond.delete(id);
|
|
24851
|
-
resolve8(false);
|
|
24852
|
-
}, REQUEST_TIMEOUT_MS2);
|
|
24853
|
-
pendingRespond.set(id, (respond) => {
|
|
24854
|
-
clearTimeout(timer);
|
|
24855
|
-
resolve8(respond);
|
|
24856
|
-
});
|
|
24857
|
-
send({ type: "should-respond", id, transcript });
|
|
24858
|
-
});
|
|
24859
|
-
}
|
|
24860
|
-
var BODYLESS_STATUS = /* @__PURE__ */ new Set([101, 204, 205, 304]);
|
|
24861
|
-
function dbFetch(send) {
|
|
24862
|
-
return async (input, init) => {
|
|
24863
|
-
const req = new Request(input, init);
|
|
24864
|
-
const url = new URL(req.url);
|
|
24865
|
-
const method = req.method.toUpperCase();
|
|
24866
|
-
const res = await send({
|
|
24867
|
-
method,
|
|
24868
|
-
path: `${url.pathname}${url.search}`,
|
|
24869
|
-
headers: Object.fromEntries(req.headers.entries()),
|
|
24870
|
-
body: method === "GET" || method === "HEAD" ? void 0 : await req.text()
|
|
24871
|
-
});
|
|
24872
|
-
const noBody = method === "HEAD" || BODYLESS_STATUS.has(res.status);
|
|
24873
|
-
return new Response(noBody ? null : res.body, { status: res.status, headers: res.headers });
|
|
24874
|
-
};
|
|
24875
|
-
}
|
|
24876
|
-
var hostDbFetch = dbFetch(requestHostDb);
|
|
24877
|
-
var LOCAL_DB_PATH = "/internal/db";
|
|
24878
|
-
async function requestViaLocalHost(req) {
|
|
24879
|
-
const deadline = Date.now() + REQUEST_TIMEOUT_MS2;
|
|
24880
|
-
let endpoint = readHostEndpoint();
|
|
24881
|
-
while (!endpoint && Date.now() < deadline) {
|
|
24882
|
-
await new Promise((r) => setTimeout(r, 1e3));
|
|
24883
|
-
endpoint = readHostEndpoint();
|
|
24884
|
-
}
|
|
24885
|
-
if (!endpoint) throw new Error("No local Host to reach the Data API through");
|
|
24886
|
-
const res = await fetch(`http://127.0.0.1:${endpoint.port}${LOCAL_DB_PATH}`, {
|
|
24887
|
-
method: "POST",
|
|
24888
|
-
headers: { authorization: `Bearer ${endpoint.token}`, "content-type": "application/json" },
|
|
24889
|
-
body: JSON.stringify(req),
|
|
24890
|
-
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS2 + 5e3)
|
|
24891
|
-
});
|
|
24892
|
-
if (!res.ok) throw new Error(`Local Host DB relay answered ${res.status}`);
|
|
24893
|
-
return await res.json();
|
|
24894
|
-
}
|
|
24895
|
-
function relayChannel(topic) {
|
|
24896
|
-
const channel = {
|
|
24897
|
-
on: () => channel,
|
|
24898
|
-
subscribe: (callback) => {
|
|
24899
|
-
queueMicrotask(() => callback?.("SUBSCRIBED"));
|
|
24900
|
-
return channel;
|
|
24901
|
-
},
|
|
24902
|
-
send: async (msg) => {
|
|
24903
|
-
if (msg.type !== "broadcast" || !sender) return "error";
|
|
24904
|
-
sender({ type: "db-broadcast", topic, event: msg.event, payload: msg.payload ?? {} });
|
|
24905
|
-
return "ok";
|
|
24906
|
-
},
|
|
24907
|
-
unsubscribe: async () => "ok"
|
|
24908
|
-
};
|
|
24909
|
-
return channel;
|
|
24910
|
-
}
|
|
24911
|
-
function createHostDbClient(via = "socket") {
|
|
24912
|
-
const client = createClient("https://host-db.invalid", "host-device", {
|
|
24913
|
-
auth: { persistSession: false, autoRefreshToken: false },
|
|
24914
|
-
global: { fetch: via === "socket" ? hostDbFetch : dbFetch(requestViaLocalHost) }
|
|
24915
|
-
});
|
|
24916
|
-
return new Proxy(client, {
|
|
24917
|
-
get(target, prop) {
|
|
24918
|
-
if (prop === "channel") return relayChannel;
|
|
24919
|
-
if (prop === "removeChannel") return async () => "ok";
|
|
24920
|
-
const value = Reflect.get(target, prop, target);
|
|
24921
|
-
return typeof value === "function" ? value.bind(target) : value;
|
|
24922
|
-
}
|
|
24923
|
-
});
|
|
24924
|
-
}
|
|
24925
|
-
|
|
24926
25242
|
// src/claude/agents.ts
|
|
24927
|
-
import { existsSync as
|
|
24928
|
-
import { homedir as
|
|
24929
|
-
import { basename as
|
|
25243
|
+
import { existsSync as existsSync15, readdirSync as readdirSync5, readFileSync as readFileSync13 } from "fs";
|
|
25244
|
+
import { homedir as homedir6 } from "os";
|
|
25245
|
+
import { basename as basename4, join as join15 } from "path";
|
|
24930
25246
|
import yaml3 from "js-yaml";
|
|
24931
25247
|
|
|
24932
25248
|
// ../api/src/claude/skills.ts
|
|
24933
|
-
import { existsSync as
|
|
24934
|
-
import { homedir as
|
|
24935
|
-
import { basename as
|
|
25249
|
+
import { existsSync as existsSync14, readdirSync as readdirSync4, readFileSync as readFileSync12, statSync as statSync5 } from "fs";
|
|
25250
|
+
import { homedir as homedir5 } from "os";
|
|
25251
|
+
import { basename as basename3, dirname as dirname3, join as join14 } from "path";
|
|
24936
25252
|
import yaml2 from "js-yaml";
|
|
24937
25253
|
|
|
24938
25254
|
// ../api/src/claude/skill-files.ts
|
|
24939
25255
|
import {
|
|
24940
|
-
existsSync as
|
|
24941
|
-
mkdirSync as
|
|
24942
|
-
readFileSync as
|
|
24943
|
-
readdirSync as
|
|
24944
|
-
rmSync as
|
|
25256
|
+
existsSync as existsSync13,
|
|
25257
|
+
mkdirSync as mkdirSync9,
|
|
25258
|
+
readFileSync as readFileSync11,
|
|
25259
|
+
readdirSync as readdirSync3,
|
|
25260
|
+
rmSync as rmSync9,
|
|
24945
25261
|
statSync as statSync4,
|
|
24946
|
-
writeFileSync as
|
|
25262
|
+
writeFileSync as writeFileSync8
|
|
24947
25263
|
} from "fs";
|
|
24948
|
-
import { homedir as
|
|
24949
|
-
import { join as
|
|
25264
|
+
import { homedir as homedir4 } from "os";
|
|
25265
|
+
import { join as join13, resolve as resolve5, sep as sep2 } from "path";
|
|
24950
25266
|
import yaml from "js-yaml";
|
|
24951
25267
|
var MAX_SKILL_BYTES = 2 * 1024 * 1024;
|
|
24952
25268
|
var SKILL_NAME = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
|
|
24953
25269
|
function expandHome(p) {
|
|
24954
|
-
if (p === "~") return
|
|
24955
|
-
if (p.startsWith("~/")) return
|
|
25270
|
+
if (p === "~") return homedir4();
|
|
25271
|
+
if (p.startsWith("~/")) return join13(homedir4(), p.slice(2));
|
|
24956
25272
|
return p;
|
|
24957
25273
|
}
|
|
24958
25274
|
function workspaceSkillsDir(configDir) {
|
|
24959
|
-
return
|
|
25275
|
+
return join13(configDir ? expandHome(configDir) : join13(homedir4(), ".claude"), "skills");
|
|
24960
25276
|
}
|
|
24961
25277
|
function channelSkillsDir(cwd) {
|
|
24962
|
-
return
|
|
25278
|
+
return join13(cwd, ".claude", "skills");
|
|
24963
25279
|
}
|
|
24964
25280
|
function isValidSkillName(name) {
|
|
24965
25281
|
return SKILL_NAME.test(name);
|
|
@@ -24994,7 +25310,7 @@ ${body.replace(/^\n+/, "").trimEnd()}
|
|
|
24994
25310
|
}
|
|
24995
25311
|
function readMeta(abs) {
|
|
24996
25312
|
try {
|
|
24997
|
-
const { fm } = splitFrontmatter(
|
|
25313
|
+
const { fm } = splitFrontmatter(readFileSync11(abs, "utf-8"));
|
|
24998
25314
|
return {
|
|
24999
25315
|
name: typeof fm["name"] === "string" ? fm["name"] : void 0,
|
|
25000
25316
|
description: typeof fm["description"] === "string" ? fm["description"] : void 0
|
|
@@ -25004,17 +25320,17 @@ function readMeta(abs) {
|
|
|
25004
25320
|
}
|
|
25005
25321
|
}
|
|
25006
25322
|
function listSkillFiles(dir) {
|
|
25007
|
-
if (!
|
|
25323
|
+
if (!existsSync13(dir)) return [];
|
|
25008
25324
|
let entries2;
|
|
25009
25325
|
try {
|
|
25010
|
-
entries2 =
|
|
25326
|
+
entries2 = readdirSync3(dir);
|
|
25011
25327
|
} catch {
|
|
25012
25328
|
return [];
|
|
25013
25329
|
}
|
|
25014
25330
|
const rows2 = [];
|
|
25015
25331
|
for (const entry of entries2) {
|
|
25016
25332
|
if (!isValidSkillName(entry)) continue;
|
|
25017
|
-
const abs =
|
|
25333
|
+
const abs = join13(dir, entry, "SKILL.md");
|
|
25018
25334
|
let stat;
|
|
25019
25335
|
try {
|
|
25020
25336
|
stat = statSync4(abs);
|
|
@@ -25043,7 +25359,7 @@ function readSkillFile(dir, name) {
|
|
|
25043
25359
|
return null;
|
|
25044
25360
|
}
|
|
25045
25361
|
if (!stat.isFile() || stat.size > MAX_SKILL_BYTES) return null;
|
|
25046
|
-
const { fm, body } = splitFrontmatter(
|
|
25362
|
+
const { fm, body } = splitFrontmatter(readFileSync11(abs, "utf-8"));
|
|
25047
25363
|
return {
|
|
25048
25364
|
name,
|
|
25049
25365
|
description: typeof fm["description"] === "string" ? fm["description"].trim() : "",
|
|
@@ -25065,18 +25381,18 @@ function writeSkillFile(dir, name, patch, baseMtime) {
|
|
|
25065
25381
|
if (baseMtime && stat.mtime.toISOString() !== baseMtime) {
|
|
25066
25382
|
return { status: "conflict", mtime: stat.mtime.toISOString() };
|
|
25067
25383
|
}
|
|
25068
|
-
const { fm } = splitFrontmatter(
|
|
25384
|
+
const { fm } = splitFrontmatter(readFileSync11(abs, "utf-8"));
|
|
25069
25385
|
const content = buildSkillFile({ ...fm, name, description: patch.description }, patch.body);
|
|
25070
25386
|
if (Buffer.byteLength(content, "utf8") > MAX_SKILL_BYTES) return { status: "too-large" };
|
|
25071
|
-
|
|
25387
|
+
writeFileSync8(abs, content, "utf8");
|
|
25072
25388
|
return { status: "ok", mtime: statSync4(abs).mtime.toISOString() };
|
|
25073
25389
|
}
|
|
25074
25390
|
function createSkillFile(dir, name, description) {
|
|
25075
25391
|
const abs = resolveSkillPath(dir, name);
|
|
25076
25392
|
if (!abs) return { status: "bad-name" };
|
|
25077
|
-
if (
|
|
25078
|
-
|
|
25079
|
-
|
|
25393
|
+
if (existsSync13(abs)) return { status: "exists" };
|
|
25394
|
+
mkdirSync9(join13(dir, name), { recursive: true });
|
|
25395
|
+
writeFileSync8(
|
|
25080
25396
|
abs,
|
|
25081
25397
|
buildSkillFile(
|
|
25082
25398
|
{ name, description },
|
|
@@ -25092,24 +25408,24 @@ Describe what this skill does and when to use it.
|
|
|
25092
25408
|
}
|
|
25093
25409
|
function deleteSkillFile(dir, name) {
|
|
25094
25410
|
const abs = resolveSkillPath(dir, name);
|
|
25095
|
-
if (!abs || !
|
|
25096
|
-
|
|
25411
|
+
if (!abs || !existsSync13(abs)) return { status: "not-found" };
|
|
25412
|
+
rmSync9(join13(dir, name), { recursive: true, force: true });
|
|
25097
25413
|
return { status: "ok" };
|
|
25098
25414
|
}
|
|
25099
25415
|
|
|
25100
25416
|
// ../api/src/claude/skills.ts
|
|
25101
25417
|
function defaultConfigDir() {
|
|
25102
|
-
return
|
|
25418
|
+
return join14(homedir5(), ".claude");
|
|
25103
25419
|
}
|
|
25104
25420
|
function expandHome2(p) {
|
|
25105
|
-
if (p === "~") return
|
|
25106
|
-
if (p.startsWith("~/")) return
|
|
25421
|
+
if (p === "~") return homedir5();
|
|
25422
|
+
if (p.startsWith("~/")) return join14(homedir5(), p.slice(2));
|
|
25107
25423
|
return p;
|
|
25108
25424
|
}
|
|
25109
25425
|
function parseFrontmatter(file) {
|
|
25110
25426
|
let content;
|
|
25111
25427
|
try {
|
|
25112
|
-
content =
|
|
25428
|
+
content = readFileSync12(file, "utf-8");
|
|
25113
25429
|
} catch {
|
|
25114
25430
|
return {};
|
|
25115
25431
|
}
|
|
@@ -25127,39 +25443,39 @@ function parseFrontmatter(file) {
|
|
|
25127
25443
|
function isSymlinkedDir(root, entry) {
|
|
25128
25444
|
if (!entry.isSymbolicLink()) return false;
|
|
25129
25445
|
try {
|
|
25130
|
-
return statSync5(
|
|
25446
|
+
return statSync5(join14(root, entry.name)).isDirectory();
|
|
25131
25447
|
} catch {
|
|
25132
25448
|
return false;
|
|
25133
25449
|
}
|
|
25134
25450
|
}
|
|
25135
25451
|
function findSkillFiles(root, maxDepth, out) {
|
|
25136
|
-
if (maxDepth < 0 || !
|
|
25452
|
+
if (maxDepth < 0 || !existsSync14(root)) return;
|
|
25137
25453
|
let entries2;
|
|
25138
25454
|
try {
|
|
25139
|
-
entries2 =
|
|
25455
|
+
entries2 = readdirSync4(root, { withFileTypes: true });
|
|
25140
25456
|
} catch {
|
|
25141
25457
|
return;
|
|
25142
25458
|
}
|
|
25143
25459
|
for (const entry of entries2) {
|
|
25144
25460
|
if (entry.isFile()) {
|
|
25145
|
-
if (entry.name === "SKILL.md") out.push(
|
|
25461
|
+
if (entry.name === "SKILL.md") out.push(join14(root, entry.name));
|
|
25146
25462
|
} else if (entry.isDirectory() || isSymlinkedDir(root, entry)) {
|
|
25147
25463
|
if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
|
|
25148
|
-
findSkillFiles(
|
|
25464
|
+
findSkillFiles(join14(root, entry.name), maxDepth - 1, out);
|
|
25149
25465
|
}
|
|
25150
25466
|
}
|
|
25151
25467
|
}
|
|
25152
25468
|
function pluginNameFor(file, root) {
|
|
25153
|
-
let dir =
|
|
25154
|
-
while (dir.startsWith(root) && dir !==
|
|
25469
|
+
let dir = dirname3(file);
|
|
25470
|
+
while (dir.startsWith(root) && dir !== dirname3(dir)) {
|
|
25155
25471
|
try {
|
|
25156
25472
|
const manifest = JSON.parse(
|
|
25157
|
-
|
|
25473
|
+
readFileSync12(join14(dir, ".claude-plugin", "plugin.json"), "utf-8")
|
|
25158
25474
|
);
|
|
25159
25475
|
if (typeof manifest.name === "string" && manifest.name.trim()) return manifest.name.trim();
|
|
25160
25476
|
} catch {
|
|
25161
25477
|
}
|
|
25162
|
-
dir =
|
|
25478
|
+
dir = dirname3(dir);
|
|
25163
25479
|
}
|
|
25164
25480
|
return void 0;
|
|
25165
25481
|
}
|
|
@@ -25169,29 +25485,29 @@ function findPluginMarkdown(pluginsRoot, dirName, maxDepth = 8) {
|
|
|
25169
25485
|
if (depth < 0) return;
|
|
25170
25486
|
let entries2;
|
|
25171
25487
|
try {
|
|
25172
|
-
entries2 =
|
|
25488
|
+
entries2 = readdirSync4(dir, { withFileTypes: true });
|
|
25173
25489
|
} catch {
|
|
25174
25490
|
return;
|
|
25175
25491
|
}
|
|
25176
25492
|
for (const entry of entries2) {
|
|
25177
25493
|
if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
|
|
25178
25494
|
if (!entry.isDirectory() && !isSymlinkedDir(dir, entry)) continue;
|
|
25179
|
-
const child =
|
|
25495
|
+
const child = join14(dir, entry.name);
|
|
25180
25496
|
if (entry.name === dirName) {
|
|
25181
25497
|
for (const f of readdirSafe(child)) {
|
|
25182
|
-
if (f.endsWith(".md")) out.push({ file:
|
|
25498
|
+
if (f.endsWith(".md")) out.push({ file: join14(child, f), plugin: pluginNameFor(join14(child, f), pluginsRoot) });
|
|
25183
25499
|
}
|
|
25184
25500
|
} else {
|
|
25185
25501
|
walk(child, depth - 1);
|
|
25186
25502
|
}
|
|
25187
25503
|
}
|
|
25188
25504
|
};
|
|
25189
|
-
if (
|
|
25505
|
+
if (existsSync14(pluginsRoot)) walk(pluginsRoot, maxDepth);
|
|
25190
25506
|
return out;
|
|
25191
25507
|
}
|
|
25192
25508
|
function readdirSafe(dir) {
|
|
25193
25509
|
try {
|
|
25194
|
-
return
|
|
25510
|
+
return readdirSync4(dir);
|
|
25195
25511
|
} catch {
|
|
25196
25512
|
return [];
|
|
25197
25513
|
}
|
|
@@ -25199,16 +25515,16 @@ function readdirSafe(dir) {
|
|
|
25199
25515
|
function listCommands(configDir, cwd) {
|
|
25200
25516
|
const base = configDir ? expandHome2(configDir) : defaultConfigDir();
|
|
25201
25517
|
const local = (dir, source) => readdirSafe(dir).filter((f) => f.endsWith(".md")).map((f) => ({
|
|
25202
|
-
name:
|
|
25203
|
-
description: (parseFrontmatter(
|
|
25518
|
+
name: basename3(f, ".md"),
|
|
25519
|
+
description: (parseFrontmatter(join14(dir, f)).description ?? "").trim(),
|
|
25204
25520
|
source,
|
|
25205
25521
|
kind: "command"
|
|
25206
25522
|
}));
|
|
25207
25523
|
const collected = [
|
|
25208
|
-
...local(
|
|
25209
|
-
...local(
|
|
25210
|
-
...findPluginMarkdown(
|
|
25211
|
-
name: plugin ? `${plugin}:${
|
|
25524
|
+
...local(join14(cwd, ".claude", "commands"), "project"),
|
|
25525
|
+
...local(join14(base, "commands"), "user"),
|
|
25526
|
+
...findPluginMarkdown(join14(base, "plugins"), "commands").map(({ file, plugin }) => ({
|
|
25527
|
+
name: plugin ? `${plugin}:${basename3(file, ".md")}` : basename3(file, ".md"),
|
|
25212
25528
|
description: (parseFrontmatter(file).description ?? "").trim(),
|
|
25213
25529
|
source: "plugin",
|
|
25214
25530
|
...plugin && { plugin },
|
|
@@ -25229,7 +25545,7 @@ function collectFrom(root, source, maxDepth, namePrefix) {
|
|
|
25229
25545
|
findSkillFiles(root, maxDepth, files);
|
|
25230
25546
|
return files.map((file) => {
|
|
25231
25547
|
const fm = parseFrontmatter(file);
|
|
25232
|
-
const name = fm.name?.trim() ||
|
|
25548
|
+
const name = fm.name?.trim() || basename3(dirname3(file));
|
|
25233
25549
|
const plugin = source === "plugin" ? pluginNameFor(file, root) : void 0;
|
|
25234
25550
|
const prefix = namePrefix ?? plugin;
|
|
25235
25551
|
return {
|
|
@@ -25245,10 +25561,10 @@ function collectFrom(root, source, maxDepth, namePrefix) {
|
|
|
25245
25561
|
function collectAll(configDir, cwd) {
|
|
25246
25562
|
const base = configDir ? expandHome2(configDir) : defaultConfigDir();
|
|
25247
25563
|
const collected = [
|
|
25248
|
-
...collectFrom(
|
|
25564
|
+
...collectFrom(join14(cwd, ".claude", "skills"), "project", 2),
|
|
25249
25565
|
...nestedProjectRoots(cwd).flatMap(({ dir, prefix }) => collectFrom(dir, "project", 2, prefix)),
|
|
25250
|
-
...collectFrom(
|
|
25251
|
-
...collectFrom(
|
|
25566
|
+
...collectFrom(join14(base, "skills"), "user", 2),
|
|
25567
|
+
...collectFrom(join14(base, "plugins"), "plugin", 8)
|
|
25252
25568
|
];
|
|
25253
25569
|
const byName = /* @__PURE__ */ new Map();
|
|
25254
25570
|
for (const skill of collected) {
|
|
@@ -25259,7 +25575,7 @@ function collectAll(configDir, cwd) {
|
|
|
25259
25575
|
function nestedProjectRoots(cwd) {
|
|
25260
25576
|
let entries2;
|
|
25261
25577
|
try {
|
|
25262
|
-
entries2 =
|
|
25578
|
+
entries2 = readdirSync4(cwd, { withFileTypes: true });
|
|
25263
25579
|
} catch {
|
|
25264
25580
|
return [];
|
|
25265
25581
|
}
|
|
@@ -25267,8 +25583,8 @@ function nestedProjectRoots(cwd) {
|
|
|
25267
25583
|
for (const entry of entries2) {
|
|
25268
25584
|
if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
|
|
25269
25585
|
if (!entry.isDirectory() && !isSymlinkedDir(cwd, entry)) continue;
|
|
25270
|
-
const skillsDir =
|
|
25271
|
-
if (
|
|
25586
|
+
const skillsDir = join14(cwd, entry.name, ".claude", "skills");
|
|
25587
|
+
if (existsSync14(skillsDir)) roots.push({ dir: skillsDir, prefix: entry.name });
|
|
25272
25588
|
}
|
|
25273
25589
|
return roots;
|
|
25274
25590
|
}
|
|
@@ -25280,7 +25596,7 @@ function listPluginSkillDetails(configDir, cwd) {
|
|
|
25280
25596
|
for (const { file, ...skill } of collectAll(configDir, cwd)) {
|
|
25281
25597
|
if (skill.source !== "plugin") continue;
|
|
25282
25598
|
try {
|
|
25283
|
-
const { body } = splitFrontmatter(
|
|
25599
|
+
const { body } = splitFrontmatter(readFileSync12(file, "utf-8"));
|
|
25284
25600
|
details.push({ ...skill, body, path: file, mtime: statSync5(file).mtime.toISOString() });
|
|
25285
25601
|
} catch {
|
|
25286
25602
|
}
|
|
@@ -25290,15 +25606,15 @@ function listPluginSkillDetails(configDir, cwd) {
|
|
|
25290
25606
|
function findSkillDetail(configDir, cwd, name, sources) {
|
|
25291
25607
|
const base = configDir ? expandHome2(configDir) : defaultConfigDir();
|
|
25292
25608
|
const roots = [
|
|
25293
|
-
[
|
|
25609
|
+
[join14(cwd, ".claude", "skills"), "project", 2],
|
|
25294
25610
|
...nestedProjectRoots(cwd).map(({ dir, prefix }) => [
|
|
25295
25611
|
dir,
|
|
25296
25612
|
"project",
|
|
25297
25613
|
2,
|
|
25298
25614
|
prefix
|
|
25299
25615
|
]),
|
|
25300
|
-
[
|
|
25301
|
-
[
|
|
25616
|
+
[join14(base, "skills"), "user", 2],
|
|
25617
|
+
[join14(base, "plugins"), "plugin", 8]
|
|
25302
25618
|
];
|
|
25303
25619
|
for (const [root, source, maxDepth, namePrefix] of roots) {
|
|
25304
25620
|
if (!sources.includes(source)) continue;
|
|
@@ -25306,7 +25622,7 @@ function findSkillDetail(configDir, cwd, name, sources) {
|
|
|
25306
25622
|
findSkillFiles(root, maxDepth, files);
|
|
25307
25623
|
for (const file of files) {
|
|
25308
25624
|
const fm = parseFrontmatter(file);
|
|
25309
|
-
const rawName = fm.name?.trim() ||
|
|
25625
|
+
const rawName = fm.name?.trim() || basename3(dirname3(file));
|
|
25310
25626
|
const plugin = source === "plugin" ? pluginNameFor(file, root) : void 0;
|
|
25311
25627
|
const prefix = namePrefix ?? plugin;
|
|
25312
25628
|
const skillName = prefix ? `${prefix}:${rawName}` : rawName;
|
|
@@ -25314,7 +25630,7 @@ function findSkillDetail(configDir, cwd, name, sources) {
|
|
|
25314
25630
|
let raw;
|
|
25315
25631
|
let mtime;
|
|
25316
25632
|
try {
|
|
25317
|
-
raw =
|
|
25633
|
+
raw = readFileSync12(file, "utf-8");
|
|
25318
25634
|
mtime = statSync5(file).mtime.toISOString();
|
|
25319
25635
|
} catch {
|
|
25320
25636
|
continue;
|
|
@@ -25342,24 +25658,24 @@ function expandSkillCommand(configDir, cwd, text) {
|
|
|
25342
25658
|
const body = skill.body.includes("$ARGUMENTS") ? skill.body.replaceAll("$ARGUMENTS", args) : skill.body + (args ? `
|
|
25343
25659
|
|
|
25344
25660
|
ARGUMENTS: ${args}` : "");
|
|
25345
|
-
return `[the user ran the /${skill.name} skill; its instructions follow. Base directory for this skill: ${
|
|
25661
|
+
return `[the user ran the /${skill.name} skill; its instructions follow. Base directory for this skill: ${dirname3(skill.path)}]
|
|
25346
25662
|
|
|
25347
25663
|
${body.trim()}`;
|
|
25348
25664
|
}
|
|
25349
25665
|
|
|
25350
25666
|
// src/claude/agents.ts
|
|
25351
25667
|
function defaultConfigDir2() {
|
|
25352
|
-
return
|
|
25668
|
+
return join15(homedir6(), ".claude");
|
|
25353
25669
|
}
|
|
25354
25670
|
function expandHome3(p) {
|
|
25355
|
-
if (p === "~") return
|
|
25356
|
-
if (p.startsWith("~/")) return
|
|
25671
|
+
if (p === "~") return homedir6();
|
|
25672
|
+
if (p.startsWith("~/")) return join15(homedir6(), p.slice(2));
|
|
25357
25673
|
return p;
|
|
25358
25674
|
}
|
|
25359
25675
|
function parseFrontmatter2(file) {
|
|
25360
25676
|
let content;
|
|
25361
25677
|
try {
|
|
25362
|
-
content =
|
|
25678
|
+
content = readFileSync13(file, "utf-8");
|
|
25363
25679
|
} catch {
|
|
25364
25680
|
return {};
|
|
25365
25681
|
}
|
|
@@ -25375,29 +25691,29 @@ function parseFrontmatter2(file) {
|
|
|
25375
25691
|
}
|
|
25376
25692
|
}
|
|
25377
25693
|
function collectFrom2(root, source) {
|
|
25378
|
-
if (!
|
|
25694
|
+
if (!existsSync15(root)) return [];
|
|
25379
25695
|
let entries2;
|
|
25380
25696
|
try {
|
|
25381
|
-
entries2 =
|
|
25697
|
+
entries2 = readdirSync5(root).filter((f) => f.endsWith(".md"));
|
|
25382
25698
|
} catch {
|
|
25383
25699
|
return [];
|
|
25384
25700
|
}
|
|
25385
25701
|
return entries2.map((file) => {
|
|
25386
|
-
const path =
|
|
25702
|
+
const path = join15(root, file);
|
|
25387
25703
|
const fm = parseFrontmatter2(path);
|
|
25388
|
-
const name = fm.name?.trim() ||
|
|
25704
|
+
const name = fm.name?.trim() || basename4(file, ".md");
|
|
25389
25705
|
return { name, description: (fm.description ?? "").trim(), source, path };
|
|
25390
25706
|
});
|
|
25391
25707
|
}
|
|
25392
25708
|
function listAgents(configDir, cwd) {
|
|
25393
25709
|
const base = configDir ? expandHome3(configDir) : defaultConfigDir2();
|
|
25394
25710
|
const collected = [
|
|
25395
|
-
...collectFrom2(
|
|
25396
|
-
...collectFrom2(
|
|
25711
|
+
...collectFrom2(join15(cwd, ".claude", "agents"), "project"),
|
|
25712
|
+
...collectFrom2(join15(base, "agents"), "user"),
|
|
25397
25713
|
// Plugin agents, namespaced `plugin:agent` the way the CLI lists them.
|
|
25398
|
-
...findPluginMarkdown(
|
|
25714
|
+
...findPluginMarkdown(join15(base, "plugins"), "agents").map(({ file, plugin }) => {
|
|
25399
25715
|
const fm = parseFrontmatter2(file);
|
|
25400
|
-
const name = fm.name?.trim() ||
|
|
25716
|
+
const name = fm.name?.trim() || basename4(file, ".md");
|
|
25401
25717
|
return {
|
|
25402
25718
|
name: plugin ? `${plugin}:${name}` : name,
|
|
25403
25719
|
description: (fm.description ?? "").trim(),
|
|
@@ -25416,7 +25732,7 @@ function readAgentPersona(configDir, cwd, name) {
|
|
|
25416
25732
|
const agent = listAgents(configDir, cwd).find((a) => a.name === name);
|
|
25417
25733
|
if (!agent) return void 0;
|
|
25418
25734
|
try {
|
|
25419
|
-
const content =
|
|
25735
|
+
const content = readFileSync13(agent.path, "utf-8");
|
|
25420
25736
|
return content.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/, "").trim();
|
|
25421
25737
|
} catch {
|
|
25422
25738
|
return void 0;
|
|
@@ -25425,13 +25741,13 @@ function readAgentPersona(configDir, cwd, name) {
|
|
|
25425
25741
|
|
|
25426
25742
|
// src/dashboard/memory-extraction-runner.ts
|
|
25427
25743
|
import { spawn as spawn4 } from "child_process";
|
|
25428
|
-
import { existsSync as
|
|
25744
|
+
import { existsSync as existsSync16, mkdtempSync as mkdtempSync5, readFileSync as readFileSync14, rmSync as rmSync10 } from "fs";
|
|
25429
25745
|
import { tmpdir as tmpdir4 } from "os";
|
|
25430
|
-
import { join as
|
|
25746
|
+
import { join as join17 } from "path";
|
|
25431
25747
|
|
|
25432
25748
|
// ../api/src/dashboard/profile-config.ts
|
|
25433
|
-
import { homedir as
|
|
25434
|
-
import { join as
|
|
25749
|
+
import { homedir as homedir7 } from "os";
|
|
25750
|
+
import { join as join16, parse, resolve as resolve6 } from "path";
|
|
25435
25751
|
|
|
25436
25752
|
// ../api/src/dashboard/profile-config-cache.ts
|
|
25437
25753
|
var cache3 = /* @__PURE__ */ new Map();
|
|
@@ -25450,7 +25766,7 @@ function profileEnv(key) {
|
|
|
25450
25766
|
function profileClaudeConfigDir() {
|
|
25451
25767
|
const config = cachedProfileConfig();
|
|
25452
25768
|
if (!config) return process.env["CLAUDE_CONFIG_DIR"] || void 0;
|
|
25453
|
-
return config.env["CLAUDE_CONFIG_DIR"]?.trim() ||
|
|
25769
|
+
return config.env["CLAUDE_CONFIG_DIR"]?.trim() || join16(homedir7(), ".claude");
|
|
25454
25770
|
}
|
|
25455
25771
|
function profileOauthToken() {
|
|
25456
25772
|
const env = cachedProfileConfig()?.env ?? {};
|
|
@@ -25460,7 +25776,7 @@ function profileOauthToken() {
|
|
|
25460
25776
|
}
|
|
25461
25777
|
function isUnsafeCwd(cwd) {
|
|
25462
25778
|
const p = resolve6(cwd);
|
|
25463
|
-
return p === parse(p).root || p === resolve6(
|
|
25779
|
+
return p === parse(p).root || p === resolve6(homedir7());
|
|
25464
25780
|
}
|
|
25465
25781
|
function defaultClaudeCwd() {
|
|
25466
25782
|
return profileEnv("CLAUDE_CWD") ?? process.cwd();
|
|
@@ -25511,7 +25827,7 @@ var SUGGEST_TOOLS = "Read,Glob,Grep";
|
|
|
25511
25827
|
function buildInvocation(runner, req, dir, auth, baseEnv = process.env, tools = "") {
|
|
25512
25828
|
const env = { ...baseEnv, CLAUDE_CODE_DISABLE_AUTO_MEMORY: "1" };
|
|
25513
25829
|
if (runner === "codex") {
|
|
25514
|
-
const outputFile =
|
|
25830
|
+
const outputFile = join17(dir, "last-message.txt");
|
|
25515
25831
|
return {
|
|
25516
25832
|
command: "codex",
|
|
25517
25833
|
args: [
|
|
@@ -25567,7 +25883,7 @@ ${req.user}`,
|
|
|
25567
25883
|
}
|
|
25568
25884
|
function run(inv, cwd) {
|
|
25569
25885
|
return new Promise((resolve8) => {
|
|
25570
|
-
if (!
|
|
25886
|
+
if (!existsSync16(cwd)) {
|
|
25571
25887
|
resolve8({ ok: false, error: `the channel folder ${cwd} does not exist on this Host` });
|
|
25572
25888
|
return;
|
|
25573
25889
|
}
|
|
@@ -25600,7 +25916,7 @@ function run(inv, cwd) {
|
|
|
25600
25916
|
let raw = stdout;
|
|
25601
25917
|
if (inv.outputFile) {
|
|
25602
25918
|
try {
|
|
25603
|
-
raw =
|
|
25919
|
+
raw = readFileSync14(inv.outputFile, "utf-8");
|
|
25604
25920
|
} catch {
|
|
25605
25921
|
raw = "";
|
|
25606
25922
|
}
|
|
@@ -25613,7 +25929,7 @@ function run(inv, cwd) {
|
|
|
25613
25929
|
async function complete(req, tools = "", cwd) {
|
|
25614
25930
|
const runner = runnerForModel(loadDashboardSettings().agent);
|
|
25615
25931
|
const config = resolveChannelConfig(req.channelId);
|
|
25616
|
-
const dir =
|
|
25932
|
+
const dir = mkdtempSync5(join17(tmpdir4(), "flyspace-memory-"));
|
|
25617
25933
|
try {
|
|
25618
25934
|
const inv = buildInvocation(
|
|
25619
25935
|
runner,
|
|
@@ -25628,7 +25944,7 @@ async function complete(req, tools = "", cwd) {
|
|
|
25628
25944
|
);
|
|
25629
25945
|
return await run(inv, cwd ?? dir);
|
|
25630
25946
|
} finally {
|
|
25631
|
-
|
|
25947
|
+
rmSync10(dir, { recursive: true, force: true });
|
|
25632
25948
|
}
|
|
25633
25949
|
}
|
|
25634
25950
|
function completeMemoryExtraction(req) {
|
|
@@ -26328,9 +26644,9 @@ var UsageStore = class {
|
|
|
26328
26644
|
|
|
26329
26645
|
// src/dashboard/rollover-summary.ts
|
|
26330
26646
|
import { spawn as spawn5 } from "child_process";
|
|
26331
|
-
import { existsSync as
|
|
26647
|
+
import { existsSync as existsSync17, mkdtempSync as mkdtempSync6, readFileSync as readFileSync15, rmSync as rmSync11 } from "fs";
|
|
26332
26648
|
import { tmpdir as tmpdir5 } from "os";
|
|
26333
|
-
import { join as
|
|
26649
|
+
import { join as join18 } from "path";
|
|
26334
26650
|
var HAIKU_MODEL = "haiku";
|
|
26335
26651
|
var CJK_PATTERN = /[ -〿-ヿ㐀-䶿一-鿿豈--]/;
|
|
26336
26652
|
function estimateTokens(text) {
|
|
@@ -26393,8 +26709,8 @@ function runSummaryPrint(input, options) {
|
|
|
26393
26709
|
return runPrint("claude", args, env).then((out) => out.trim());
|
|
26394
26710
|
}
|
|
26395
26711
|
async function runCodexSummary(input) {
|
|
26396
|
-
const dir =
|
|
26397
|
-
const lastMessageFile =
|
|
26712
|
+
const dir = mkdtempSync6(join18(tmpdir5(), "rollover-"));
|
|
26713
|
+
const lastMessageFile = join18(dir, "last-message.txt");
|
|
26398
26714
|
try {
|
|
26399
26715
|
await runPrint(
|
|
26400
26716
|
"codex",
|
|
@@ -26417,9 +26733,9 @@ ${input}`
|
|
|
26417
26733
|
],
|
|
26418
26734
|
{ ...process.env }
|
|
26419
26735
|
);
|
|
26420
|
-
return
|
|
26736
|
+
return existsSync17(lastMessageFile) ? readFileSync15(lastMessageFile, "utf8").trim() : "";
|
|
26421
26737
|
} finally {
|
|
26422
|
-
|
|
26738
|
+
rmSync11(dir, { recursive: true, force: true });
|
|
26423
26739
|
}
|
|
26424
26740
|
}
|
|
26425
26741
|
function runPrint(command, args, env) {
|
|
@@ -26659,7 +26975,7 @@ async function scanBackgroundTasks() {
|
|
|
26659
26975
|
|
|
26660
26976
|
// src/dashboard/attachment-downloader.ts
|
|
26661
26977
|
import { writeFile as writeFile2 } from "fs/promises";
|
|
26662
|
-
import { join as
|
|
26978
|
+
import { join as join19 } from "path";
|
|
26663
26979
|
import { GetObjectCommand } from "@aws-sdk/client-s3";
|
|
26664
26980
|
var debug4 = process.env["DEBUG"] === "true";
|
|
26665
26981
|
var ATTACHMENT_LINK = /\]\((?:https:\/\/[a-z0-9-]+\.flyspace\.ai)?\/api\/attachments\/([^)?\s]+)(?:\?[^)\s]*)?\)/g;
|
|
@@ -26726,7 +27042,7 @@ async function downloadOne2(key) {
|
|
|
26726
27042
|
if (bytes.length > sizeLimit) {
|
|
26727
27043
|
return { kind: "skip", skipped: { name, mimetype, reason: "too_large" } };
|
|
26728
27044
|
}
|
|
26729
|
-
const localPath =
|
|
27045
|
+
const localPath = join19(paths.UPLOADS_DIR, lastSegment);
|
|
26730
27046
|
await writeFile2(localPath, bytes);
|
|
26731
27047
|
if (debug4)
|
|
26732
27048
|
console.log(`[attachment-downloader] saved ${key} -> ${localPath} (${bytes.length} bytes)`);
|
|
@@ -26751,27 +27067,27 @@ async function downloadChatAttachments(body) {
|
|
|
26751
27067
|
}
|
|
26752
27068
|
|
|
26753
27069
|
// src/dashboard/doc-mention-guard.ts
|
|
26754
|
-
import { existsSync as
|
|
27070
|
+
import { existsSync as existsSync22, statSync as statSync8 } from "fs";
|
|
26755
27071
|
|
|
26756
27072
|
// src/dashboard/docs-routes.ts
|
|
26757
27073
|
import {
|
|
26758
27074
|
closeSync,
|
|
26759
27075
|
createReadStream,
|
|
26760
|
-
existsSync as
|
|
27076
|
+
existsSync as existsSync21,
|
|
26761
27077
|
lstatSync as lstatSync2,
|
|
26762
|
-
mkdirSync as
|
|
27078
|
+
mkdirSync as mkdirSync10,
|
|
26763
27079
|
openSync,
|
|
26764
27080
|
readSync,
|
|
26765
|
-
readdirSync as
|
|
26766
|
-
readFileSync as
|
|
27081
|
+
readdirSync as readdirSync6,
|
|
27082
|
+
readFileSync as readFileSync19,
|
|
26767
27083
|
realpathSync,
|
|
26768
|
-
renameSync as
|
|
26769
|
-
rmSync as
|
|
27084
|
+
renameSync as renameSync3,
|
|
27085
|
+
rmSync as rmSync12,
|
|
26770
27086
|
statSync as statSync7,
|
|
26771
|
-
writeFileSync as
|
|
27087
|
+
writeFileSync as writeFileSync9
|
|
26772
27088
|
} from "fs";
|
|
26773
27089
|
import { Readable } from "stream";
|
|
26774
|
-
import { basename as
|
|
27090
|
+
import { basename as basename6, dirname as dirname4, extname as extname2, join as join23, relative, resolve as resolve7, sep as sep3 } from "path";
|
|
26775
27091
|
import { Hono as Hono4 } from "hono";
|
|
26776
27092
|
import { streamSSE } from "hono/streaming";
|
|
26777
27093
|
|
|
@@ -26883,8 +27199,8 @@ var requireDocsAccess = async (c, next) => {
|
|
|
26883
27199
|
};
|
|
26884
27200
|
|
|
26885
27201
|
// src/dashboard/docs-watcher.ts
|
|
26886
|
-
import { existsSync as
|
|
26887
|
-
import { basename as
|
|
27202
|
+
import { existsSync as existsSync18, watch } from "fs";
|
|
27203
|
+
import { basename as basename5, join as join20 } from "path";
|
|
26888
27204
|
var DEBOUNCE_MS = 200;
|
|
26889
27205
|
var MAX_PENDING = 200;
|
|
26890
27206
|
var IGNORED_SEGMENTS = /* @__PURE__ */ new Set([
|
|
@@ -26920,12 +27236,12 @@ function flush(cwd) {
|
|
|
26920
27236
|
function watchDocs(cwd, listener) {
|
|
26921
27237
|
let entry = entries.get(cwd);
|
|
26922
27238
|
if (!entry) {
|
|
26923
|
-
const root =
|
|
27239
|
+
const root = basename5(cwd);
|
|
26924
27240
|
const watcher = watch(cwd, { recursive: true, persistent: false }, (_event, filename) => {
|
|
26925
27241
|
const current = entries.get(cwd);
|
|
26926
27242
|
if (!current || filename === null) return;
|
|
26927
27243
|
const rel = filename.split("\\").join("/");
|
|
26928
|
-
if (rel === root && !
|
|
27244
|
+
if (rel === root && !existsSync18(join20(cwd, rel))) return;
|
|
26929
27245
|
if (isIgnoredDocPath(rel)) return;
|
|
26930
27246
|
if (current.pending.size < MAX_PENDING) current.pending.add(rel);
|
|
26931
27247
|
if (current.timer === null) current.timer = setTimeout(() => flush(cwd), DEBOUNCE_MS);
|
|
@@ -26979,7 +27295,7 @@ async function putDocTranslation(input) {
|
|
|
26979
27295
|
}
|
|
26980
27296
|
|
|
26981
27297
|
// ../api/src/dashboard/share-translate.ts
|
|
26982
|
-
import { createHash as
|
|
27298
|
+
import { createHash as createHash5 } from "crypto";
|
|
26983
27299
|
|
|
26984
27300
|
// ../api/src/store/doc-share-store.ts
|
|
26985
27301
|
function rowToKind(value) {
|
|
@@ -27289,7 +27605,7 @@ function languageName(lang) {
|
|
|
27289
27605
|
return BY_CODE.get(lang)?.name ?? null;
|
|
27290
27606
|
}
|
|
27291
27607
|
function translationHash(title, content) {
|
|
27292
|
-
return
|
|
27608
|
+
return createHash5("sha256").update(`${RECIPE_VERSION}
|
|
27293
27609
|
${title}
|
|
27294
27610
|
${content}`).digest("hex");
|
|
27295
27611
|
}
|
|
@@ -27524,7 +27840,7 @@ async function clearStaleDocAudios(channelId, sourcePath, lang, exceptHash) {
|
|
|
27524
27840
|
}
|
|
27525
27841
|
|
|
27526
27842
|
// ../api/src/dashboard/share-audio.ts
|
|
27527
|
-
import { createHash as
|
|
27843
|
+
import { createHash as createHash6 } from "crypto";
|
|
27528
27844
|
import { DeleteObjectCommand, PutObjectCommand as PutObjectCommand2 } from "@aws-sdk/client-s3";
|
|
27529
27845
|
|
|
27530
27846
|
// ../api/src/dashboard/tts-routes.ts
|
|
@@ -27723,7 +28039,7 @@ Pacing \u2014 the engine has NO pause control, so rhythm has to be built into th
|
|
|
27723
28039
|
Output plain text ONLY. No tags of any kind, no angle brackets, no Markdown, no quotation wrapping. Any tag you emit will be deleted before synthesis, so it buys nothing and costs meaning.`;
|
|
27724
28040
|
}
|
|
27725
28041
|
function articleAudioHash(title, content) {
|
|
27726
|
-
return
|
|
28042
|
+
return createHash6("sha256").update(`v${RECIPE_VERSION2}
|
|
27727
28043
|
${title}
|
|
27728
28044
|
|
|
27729
28045
|
${content}`).digest("hex").slice(0, 32);
|
|
@@ -27950,7 +28266,7 @@ function queueShareAudio(share) {
|
|
|
27950
28266
|
var PENDING_STALE_MS = 30 * 60 * 1e3;
|
|
27951
28267
|
var FAILED_RETRY_MS = 10 * 60 * 1e3;
|
|
27952
28268
|
function langAudioHash(title, content, lang) {
|
|
27953
|
-
return
|
|
28269
|
+
return createHash6("sha256").update(`v${RECIPE_VERSION2}
|
|
27954
28270
|
${lang}
|
|
27955
28271
|
${translationHash(title, content)}`).digest("hex").slice(0, 32);
|
|
27956
28272
|
}
|
|
@@ -28237,8 +28553,8 @@ function createFeatureFlagsRouter() {
|
|
|
28237
28553
|
}
|
|
28238
28554
|
|
|
28239
28555
|
// ../api/src/dashboard/public-share-routes.ts
|
|
28240
|
-
import { existsSync as
|
|
28241
|
-
import { join as
|
|
28556
|
+
import { existsSync as existsSync20, readFileSync as readFileSync17, statSync as statSync6 } from "fs";
|
|
28557
|
+
import { join as join22 } from "path";
|
|
28242
28558
|
import { Hono as Hono3 } from "hono";
|
|
28243
28559
|
import { GetObjectCommand as GetObjectCommand3 } from "@aws-sdk/client-s3";
|
|
28244
28560
|
import { getSignedUrl as getSignedUrl2 } from "@aws-sdk/s3-request-presigner";
|
|
@@ -28444,14 +28760,14 @@ function injectShareHead(html, head) {
|
|
|
28444
28760
|
}
|
|
28445
28761
|
|
|
28446
28762
|
// ../api/src/dashboard/app-icon.ts
|
|
28447
|
-
import { createHash as
|
|
28448
|
-
import { existsSync as
|
|
28449
|
-
import { join as
|
|
28450
|
-
import
|
|
28763
|
+
import { createHash as createHash7 } from "crypto";
|
|
28764
|
+
import { existsSync as existsSync19, readFileSync as readFileSync16 } from "fs";
|
|
28765
|
+
import { join as join21 } from "path";
|
|
28766
|
+
import sharp3 from "sharp";
|
|
28451
28767
|
var PLATE = "#0A0A0F";
|
|
28452
|
-
var BRAND_DIR =
|
|
28453
|
-
var MARK_FILE =
|
|
28454
|
-
var MARK_SVG_FILE =
|
|
28768
|
+
var BRAND_DIR = existsSync19(join21(paths.WEB_ROOT, "public")) ? join21(paths.WEB_ROOT, "public") : join21(paths.PACKAGE_ROOT, "dist", "brand");
|
|
28769
|
+
var MARK_FILE = join21(BRAND_DIR, "icons", "icon-512.png");
|
|
28770
|
+
var MARK_SVG_FILE = join21(BRAND_DIR, "favicon.svg");
|
|
28455
28771
|
var LAYOUT = {
|
|
28456
28772
|
standard: { logo: 0.7, logoCx: 0.5, logoCy: 0.48, badge: 0.27, badgeCx: 0.22, badgeCy: 0.76 },
|
|
28457
28773
|
maskable: { logo: 0.56, logoCx: 0.5, logoCy: 0.48, badge: 0.23, badgeCx: 0.33, badgeCy: 0.66 }
|
|
@@ -28474,11 +28790,11 @@ function roundedPlate(size, fill = PLATE) {
|
|
|
28474
28790
|
}
|
|
28475
28791
|
async function renderBadge(box) {
|
|
28476
28792
|
const transparent = { r: 0, g: 0, b: 0, alpha: 0 };
|
|
28477
|
-
const raster = await
|
|
28478
|
-
return
|
|
28793
|
+
const raster = await sharp3(readFileSync16(MARK_SVG_FILE)).resize(512, 512, { fit: "contain", background: transparent }).png().toBuffer();
|
|
28794
|
+
return sharp3(raster).trim().resize(box, box, { fit: "contain", background: transparent }).png().toBuffer();
|
|
28479
28795
|
}
|
|
28480
28796
|
async function sampleBackground(logo) {
|
|
28481
|
-
const { data, info } = await
|
|
28797
|
+
const { data, info } = await sharp3(logo).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
28482
28798
|
const { width: w, height: h, channels } = info;
|
|
28483
28799
|
const edge = 1;
|
|
28484
28800
|
const samples = [
|
|
@@ -28523,13 +28839,13 @@ async function renderAppIcon({
|
|
|
28523
28839
|
size,
|
|
28524
28840
|
maskable ? "maskable" : "std",
|
|
28525
28841
|
plain ? "plain" : "badged",
|
|
28526
|
-
logo ?
|
|
28842
|
+
logo ? createHash7("sha1").update(logo).digest("hex").slice(0, 12) : transparent ? "stock-transparent" : "stock"
|
|
28527
28843
|
].join(":");
|
|
28528
28844
|
const hit = cache4.get(key);
|
|
28529
28845
|
if (hit) return hit;
|
|
28530
28846
|
const out = logo && await composeIcon(logo, size, maskable, plain).catch(() => null) || // No workspace logo to lead with — the stock mark is still the best icon,
|
|
28531
28847
|
// either on its usual dark plate or, for a favicon, trimmed and bare.
|
|
28532
|
-
(transparent ? await renderBadge(size) : await
|
|
28848
|
+
(transparent ? await renderBadge(size) : await sharp3(readFileSync16(MARK_FILE)).resize(size, size, { fit: "cover" }).png().toBuffer());
|
|
28533
28849
|
cache4.set(key, out);
|
|
28534
28850
|
return out;
|
|
28535
28851
|
}
|
|
@@ -28538,8 +28854,8 @@ async function composeIcon(logo, size, maskable, plain) {
|
|
|
28538
28854
|
const plate = await sampleBackground(logo) ?? PLATE;
|
|
28539
28855
|
const logoBox = Math.round(size * (plain ? PLAIN_LOGO : layout.logo));
|
|
28540
28856
|
const badgeBox = Math.round(size * layout.badge);
|
|
28541
|
-
const logoLayer = await
|
|
28542
|
-
const composed = await
|
|
28857
|
+
const logoLayer = await sharp3(logo).resize(logoBox, logoBox, { fit: "contain", background: { r: 0, g: 0, b: 0, alpha: 0 } }).png().toBuffer();
|
|
28858
|
+
const composed = await sharp3(roundedPlate(size, plate)).composite([
|
|
28543
28859
|
// Badge-less, the logo has the canvas to itself and sits dead centre;
|
|
28544
28860
|
// otherwise it's nudged up to leave the badge its corner.
|
|
28545
28861
|
{ input: logoLayer, ...place(size, logoBox, layout.logoCx, plain ? 0.5 : layout.logoCy) },
|
|
@@ -28550,12 +28866,12 @@ async function composeIcon(logo, size, maskable, plain) {
|
|
|
28550
28866
|
}
|
|
28551
28867
|
]
|
|
28552
28868
|
]).png().toBuffer();
|
|
28553
|
-
return
|
|
28869
|
+
return sharp3(composed).composite([{ input: roundedPlate(size), blend: "dest-in" }]).png().toBuffer();
|
|
28554
28870
|
}
|
|
28555
28871
|
|
|
28556
28872
|
// ../api/src/dashboard/share-og.ts
|
|
28557
|
-
import { createHash as
|
|
28558
|
-
import
|
|
28873
|
+
import { createHash as createHash8 } from "crypto";
|
|
28874
|
+
import sharp4 from "sharp";
|
|
28559
28875
|
var WIDTH = 1200;
|
|
28560
28876
|
var HEIGHT = 630;
|
|
28561
28877
|
var PAD = 80;
|
|
@@ -28688,7 +29004,7 @@ function roundedMask(size, radius) {
|
|
|
28688
29004
|
async function renderLogoChip(logo) {
|
|
28689
29005
|
if (!logo) return null;
|
|
28690
29006
|
try {
|
|
28691
|
-
return await
|
|
29007
|
+
return await sharp4(logo).resize(LOGO_BOX, LOGO_BOX, { fit: "cover" }).composite([{ input: roundedMask(LOGO_BOX, LOGO_RADIUS), blend: "dest-in" }]).png().toBuffer();
|
|
28692
29008
|
} catch {
|
|
28693
29009
|
return null;
|
|
28694
29010
|
}
|
|
@@ -28732,14 +29048,14 @@ function cacheKey(input) {
|
|
|
28732
29048
|
input.logo ?? "",
|
|
28733
29049
|
input.theme ?? ""
|
|
28734
29050
|
];
|
|
28735
|
-
return
|
|
29051
|
+
return createHash8("sha1").update(parts.join("\0")).digest("hex");
|
|
28736
29052
|
}
|
|
28737
29053
|
async function renderShareOgImage(input) {
|
|
28738
29054
|
const key = cacheKey(input);
|
|
28739
29055
|
const hit = cache5.get(key);
|
|
28740
29056
|
if (hit) return hit;
|
|
28741
29057
|
const chip = input.workspaceName?.trim() ? await renderLogoChip(decodeLogo(input.logo)) : null;
|
|
28742
|
-
const composed =
|
|
29058
|
+
const composed = sharp4(backdrop(input, !!chip));
|
|
28743
29059
|
const out = await (chip ? composed.composite([{ input: chip, left: PAD, top: LOGO_TOP }]) : composed).png({ compressionLevel: 9 }).toBuffer();
|
|
28744
29060
|
if (cache5.size >= CACHE_MAX) cache5.delete(cache5.keys().next().value);
|
|
28745
29061
|
cache5.set(key, out);
|
|
@@ -28747,7 +29063,7 @@ async function renderShareOgImage(input) {
|
|
|
28747
29063
|
}
|
|
28748
29064
|
|
|
28749
29065
|
// ../api/src/dashboard/share-ask.ts
|
|
28750
|
-
import { createHash as
|
|
29066
|
+
import { createHash as createHash9 } from "crypto";
|
|
28751
29067
|
var MAX_ARTICLE_CHARS3 = 24e3;
|
|
28752
29068
|
var MAX_QUESTION_CHARS = 500;
|
|
28753
29069
|
var SUGGESTION_COUNT = 4;
|
|
@@ -28812,7 +29128,7 @@ function parseSuggestions(raw) {
|
|
|
28812
29128
|
var CACHE_LIMIT = 200;
|
|
28813
29129
|
var suggestionCache = /* @__PURE__ */ new Map();
|
|
28814
29130
|
function articleHash(title, content, lang) {
|
|
28815
|
-
return
|
|
29131
|
+
return createHash9("sha256").update(`${lang ?? ""}
|
|
28816
29132
|
${title}
|
|
28817
29133
|
|
|
28818
29134
|
${content}`).digest("hex").slice(0, 32);
|
|
@@ -29068,7 +29384,7 @@ var shellCache = null;
|
|
|
29068
29384
|
function readShell(path) {
|
|
29069
29385
|
const { mtimeMs } = statSync6(path);
|
|
29070
29386
|
if (shellCache?.mtimeMs === mtimeMs) return shellCache.html;
|
|
29071
|
-
const html =
|
|
29387
|
+
const html = readFileSync17(path, "utf8").replaceAll('"/assets/', `"${BUILD_PREFIX}/`);
|
|
29072
29388
|
shellCache = { mtimeMs, html };
|
|
29073
29389
|
return html;
|
|
29074
29390
|
}
|
|
@@ -29088,17 +29404,17 @@ function serveBuildFile(c, webDist, dir, name) {
|
|
|
29088
29404
|
if (!type || !/^[A-Za-z0-9._-]+$/.test(name) || name.includes("..")) {
|
|
29089
29405
|
return c.text("not found", 404);
|
|
29090
29406
|
}
|
|
29091
|
-
const path =
|
|
29092
|
-
if (!
|
|
29407
|
+
const path = join22(webDist, dir, name);
|
|
29408
|
+
if (!existsSync20(path)) return c.text("not found", 404);
|
|
29093
29409
|
c.header("Content-Type", type);
|
|
29094
29410
|
c.header("Cache-Control", "public, max-age=31536000, immutable");
|
|
29095
29411
|
if (ext === ".css") {
|
|
29096
|
-
return c.body(
|
|
29412
|
+
return c.body(readFileSync17(path, "utf8").replaceAll("url(/fonts/", `url(${BUILD_PREFIX}/fonts/`));
|
|
29097
29413
|
}
|
|
29098
29414
|
if (ext === ".js") {
|
|
29099
|
-
return c.body(
|
|
29415
|
+
return c.body(readFileSync17(path, "utf8").replaceAll('"/assets/', `"${BUILD_PREFIX}/`));
|
|
29100
29416
|
}
|
|
29101
|
-
return c.body(new Uint8Array(
|
|
29417
|
+
return c.body(new Uint8Array(readFileSync17(path)));
|
|
29102
29418
|
}
|
|
29103
29419
|
var HTML_SHARE_CSP = "sandbox allow-scripts allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox";
|
|
29104
29420
|
function servePublishedHtml(c, share) {
|
|
@@ -29234,8 +29550,8 @@ ${analytics}` : head);
|
|
|
29234
29550
|
const requested = c.req.param("lang");
|
|
29235
29551
|
const lang = canonicalLanguage(requested);
|
|
29236
29552
|
if (!isTranslatableLanguage(lang)) return next();
|
|
29237
|
-
const shell =
|
|
29238
|
-
if (!
|
|
29553
|
+
const shell = join22(webDist, "index.html");
|
|
29554
|
+
if (!existsSync20(shell)) return next();
|
|
29239
29555
|
const share = await getDocShare(c.req.param("id"));
|
|
29240
29556
|
if (!share) return next();
|
|
29241
29557
|
if (requested !== lang) return c.redirect(`/share/${share.id}/${lang}`, 302);
|
|
@@ -29270,8 +29586,8 @@ ${analytics}` : head);
|
|
|
29270
29586
|
const share = await getDocShare(c.req.param("id"));
|
|
29271
29587
|
if (!share) return next();
|
|
29272
29588
|
if (share.kind === "html") return servePublishedHtml(c, share);
|
|
29273
|
-
const shell =
|
|
29274
|
-
if (!
|
|
29589
|
+
const shell = join22(webDist, "index.html");
|
|
29590
|
+
if (!existsSync20(shell)) return next();
|
|
29275
29591
|
return readerPage(
|
|
29276
29592
|
c,
|
|
29277
29593
|
share,
|
|
@@ -29296,7 +29612,7 @@ ${analytics}` : head);
|
|
|
29296
29612
|
}
|
|
29297
29613
|
|
|
29298
29614
|
// src/dashboard/artifact-export.ts
|
|
29299
|
-
import { readFileSync as
|
|
29615
|
+
import { readFileSync as readFileSync18 } from "fs";
|
|
29300
29616
|
async function exportDocAsArtifact(channelId, docPath) {
|
|
29301
29617
|
const owningProfile = findOwningProfile(channelId);
|
|
29302
29618
|
const channelConfig = await runWithProfile(
|
|
@@ -29305,7 +29621,7 @@ async function exportDocAsArtifact(channelId, docPath) {
|
|
|
29305
29621
|
);
|
|
29306
29622
|
const abs = resolveDocPath(channelConfig.cwd, docPath);
|
|
29307
29623
|
if (!abs) throw new Error(`doc not found: ${docPath}`);
|
|
29308
|
-
const content =
|
|
29624
|
+
const content = readFileSync18(abs, "utf8");
|
|
29309
29625
|
const title = extractTitle(abs, "md");
|
|
29310
29626
|
const today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
29311
29627
|
const prompt = `Publish the document at \`${docPath}\` (already read below) as a Claude Artifact, then record the result as a stub file under this channel's \`docs/artifacts/\` folder (create the folder if it doesn't exist).
|
|
@@ -29523,9 +29839,9 @@ function readHead(absPath) {
|
|
|
29523
29839
|
}
|
|
29524
29840
|
}
|
|
29525
29841
|
function extractTitle(absPath, kind) {
|
|
29526
|
-
if (kind === "url" || kind === "excalidraw") return
|
|
29842
|
+
if (kind === "url" || kind === "excalidraw") return basename6(absPath);
|
|
29527
29843
|
const head = readHead(absPath);
|
|
29528
|
-
if (!head) return
|
|
29844
|
+
if (!head) return basename6(absPath);
|
|
29529
29845
|
if (kind === "md") {
|
|
29530
29846
|
const m = head.match(/^#{1,3}\s+(.+?)\s*$/m);
|
|
29531
29847
|
if (m) return m[1].replace(/[*_`]/g, "").trim();
|
|
@@ -29533,7 +29849,7 @@ function extractTitle(absPath, kind) {
|
|
|
29533
29849
|
const t = head.match(/<title[^>]*>([^<]+)<\/title>/i) ?? head.match(/<h1[^>]*>([^<]+)<\/h1>/i);
|
|
29534
29850
|
if (t) return t[1].trim();
|
|
29535
29851
|
}
|
|
29536
|
-
return
|
|
29852
|
+
return basename6(absPath);
|
|
29537
29853
|
}
|
|
29538
29854
|
function resolveDirPath(root, rel) {
|
|
29539
29855
|
if (rel.includes("\0")) return null;
|
|
@@ -29554,7 +29870,7 @@ function probeDir(absDir, showHidden) {
|
|
|
29554
29870
|
if (depth > MAX_SEARCH_DEPTH) return false;
|
|
29555
29871
|
let entries2;
|
|
29556
29872
|
try {
|
|
29557
|
-
entries2 =
|
|
29873
|
+
entries2 = readdirSync6(dir, { withFileTypes: true });
|
|
29558
29874
|
} catch {
|
|
29559
29875
|
return false;
|
|
29560
29876
|
}
|
|
@@ -29565,7 +29881,7 @@ function probeDir(absDir, showHidden) {
|
|
|
29565
29881
|
return false;
|
|
29566
29882
|
}
|
|
29567
29883
|
if (!showHidden && entry.name.startsWith(".")) continue;
|
|
29568
|
-
const abs =
|
|
29884
|
+
const abs = join23(dir, entry.name);
|
|
29569
29885
|
const kind = entryKind(entry, abs);
|
|
29570
29886
|
if (kind === "dir") {
|
|
29571
29887
|
if (SKIP_DIRS.has(entry.name)) hasOther = true;
|
|
@@ -29585,14 +29901,14 @@ function probeDir(absDir, showHidden) {
|
|
|
29585
29901
|
}
|
|
29586
29902
|
function readGitBranch(dir) {
|
|
29587
29903
|
try {
|
|
29588
|
-
let gitDir =
|
|
29904
|
+
let gitDir = join23(dir, ".git");
|
|
29589
29905
|
if (statSync7(gitDir).isFile()) {
|
|
29590
|
-
const pointer =
|
|
29906
|
+
const pointer = readFileSync19(gitDir, "utf8").trim();
|
|
29591
29907
|
const match = pointer.match(/^gitdir:\s*(.+)$/);
|
|
29592
29908
|
if (!match) return void 0;
|
|
29593
29909
|
gitDir = resolve7(dir, match[1]);
|
|
29594
29910
|
}
|
|
29595
|
-
const head =
|
|
29911
|
+
const head = readFileSync19(join23(gitDir, "HEAD"), "utf8").trim();
|
|
29596
29912
|
const branchMatch = head.match(/^ref:\s*refs\/heads\/(.+)$/);
|
|
29597
29913
|
if (branchMatch) return branchMatch[1];
|
|
29598
29914
|
return /^[0-9a-f]{7,40}$/i.test(head) ? head.slice(0, 7) : void 0;
|
|
@@ -29605,7 +29921,7 @@ function listDocLevel(root, relDir = "", sort = "newest", showHidden = false) {
|
|
|
29605
29921
|
if (absDir === null) return [];
|
|
29606
29922
|
let entries2;
|
|
29607
29923
|
try {
|
|
29608
|
-
entries2 =
|
|
29924
|
+
entries2 = readdirSync6(absDir, { withFileTypes: true });
|
|
29609
29925
|
} catch {
|
|
29610
29926
|
return [];
|
|
29611
29927
|
}
|
|
@@ -29614,14 +29930,14 @@ function listDocLevel(root, relDir = "", sort = "newest", showHidden = false) {
|
|
|
29614
29930
|
for (const entry of entries2) {
|
|
29615
29931
|
if (dirs.length + docs.length >= MAX_ENTRIES) break;
|
|
29616
29932
|
if (!showHidden && entry.name.startsWith(".")) continue;
|
|
29617
|
-
const abs =
|
|
29933
|
+
const abs = join23(absDir, entry.name);
|
|
29618
29934
|
const path = relative(root, abs).split(sep3).join("/");
|
|
29619
29935
|
const kind = entryKind(entry, abs);
|
|
29620
29936
|
if (kind === "dir") {
|
|
29621
29937
|
if (SKIP_DIRS.has(entry.name)) continue;
|
|
29622
29938
|
const probe = probeDir(abs, showHidden);
|
|
29623
29939
|
if (!probe.hasDocs && probe.hasOther) continue;
|
|
29624
|
-
const isRepo =
|
|
29940
|
+
const isRepo = existsSync21(join23(abs, ".git"));
|
|
29625
29941
|
dirs.push({
|
|
29626
29942
|
path,
|
|
29627
29943
|
name: entry.name,
|
|
@@ -29650,14 +29966,14 @@ function flatDocs(root, {
|
|
|
29650
29966
|
if (depth > MAX_SEARCH_DEPTH || hits.length >= MAX_FLAT_DOCS) return;
|
|
29651
29967
|
let entries2;
|
|
29652
29968
|
try {
|
|
29653
|
-
entries2 =
|
|
29969
|
+
entries2 = readdirSync6(dir, { withFileTypes: true });
|
|
29654
29970
|
} catch {
|
|
29655
29971
|
return;
|
|
29656
29972
|
}
|
|
29657
29973
|
for (const entry of entries2) {
|
|
29658
29974
|
if (hits.length >= MAX_FLAT_DOCS) return;
|
|
29659
29975
|
if (!showHidden && entry.name.startsWith(".")) continue;
|
|
29660
|
-
const abs =
|
|
29976
|
+
const abs = join23(dir, entry.name);
|
|
29661
29977
|
const kind = entryKind(entry, abs);
|
|
29662
29978
|
if (kind === "dir") {
|
|
29663
29979
|
if (!SKIP_DIRS.has(entry.name)) walk(abs, depth + 1);
|
|
@@ -29699,7 +30015,7 @@ function writeDocContent(root, rel, content, baseMtime) {
|
|
|
29699
30015
|
if (Buffer.byteLength(content, "utf8") > MAX_CONTENT_BYTES) {
|
|
29700
30016
|
return { status: "too-large" };
|
|
29701
30017
|
}
|
|
29702
|
-
|
|
30018
|
+
writeFileSync9(abs, content, "utf8");
|
|
29703
30019
|
return { status: "ok", mtime: statSync7(abs).mtime.toISOString() };
|
|
29704
30020
|
}
|
|
29705
30021
|
function resolveRawPath(root, rel) {
|
|
@@ -29721,7 +30037,7 @@ function resolveDownloadPath(root, rel) {
|
|
|
29721
30037
|
if (!rel || rel.includes("\0")) return null;
|
|
29722
30038
|
const abs = resolve7(root, rel);
|
|
29723
30039
|
if (abs !== root && !abs.startsWith(root + sep3)) return null;
|
|
29724
|
-
if (!isListableFile(
|
|
30040
|
+
if (!isListableFile(basename6(abs))) return null;
|
|
29725
30041
|
const contentType = MEDIA_EXTENSIONS[extname2(abs).toLowerCase()] ?? "application/octet-stream";
|
|
29726
30042
|
return { abs, contentType };
|
|
29727
30043
|
}
|
|
@@ -29737,7 +30053,7 @@ function uniqueName(absDir, name) {
|
|
|
29737
30053
|
let candidate = name;
|
|
29738
30054
|
for (let n = 1; n < 1e3; n++) {
|
|
29739
30055
|
try {
|
|
29740
|
-
statSync7(
|
|
30056
|
+
statSync7(join23(absDir, candidate));
|
|
29741
30057
|
} catch {
|
|
29742
30058
|
return candidate;
|
|
29743
30059
|
}
|
|
@@ -29759,8 +30075,8 @@ function saveUploadedFile(root, relDir, name, data) {
|
|
|
29759
30075
|
if (!(ext in DOC_EXTENSIONS) && !ASSET_LIST_EXTENSIONS.has(ext)) return { status: "bad-type" };
|
|
29760
30076
|
if (data.byteLength > MAX_UPLOAD_BYTES) return { status: "too-large" };
|
|
29761
30077
|
const final = uniqueName(absDir, safe);
|
|
29762
|
-
const abs =
|
|
29763
|
-
|
|
30078
|
+
const abs = join23(absDir, final);
|
|
30079
|
+
writeFileSync9(abs, data);
|
|
29764
30080
|
return { status: "ok", path: relative(root, abs).split(sep3).join("/"), name: final };
|
|
29765
30081
|
}
|
|
29766
30082
|
function createDocFolder(root, relDir, name) {
|
|
@@ -29773,13 +30089,13 @@ function createDocFolder(root, relDir, name) {
|
|
|
29773
30089
|
}
|
|
29774
30090
|
const safe = sanitizeUploadName(name);
|
|
29775
30091
|
if (!safe) return { status: "bad-name" };
|
|
29776
|
-
const abs =
|
|
30092
|
+
const abs = join23(absDir, safe);
|
|
29777
30093
|
try {
|
|
29778
30094
|
statSync7(abs);
|
|
29779
30095
|
return { status: "exists" };
|
|
29780
30096
|
} catch {
|
|
29781
30097
|
}
|
|
29782
|
-
|
|
30098
|
+
mkdirSync10(abs);
|
|
29783
30099
|
return { status: "ok", path: relative(root, abs).split(sep3).join("/"), name: safe };
|
|
29784
30100
|
}
|
|
29785
30101
|
function createDocFile(root, relDir, name, content) {
|
|
@@ -29796,9 +30112,9 @@ function createDocFile(root, relDir, name, content) {
|
|
|
29796
30112
|
if (!(ext in DOC_EXTENSIONS) && !(ext in CODE_EXTENSIONS)) return { status: "bad-name" };
|
|
29797
30113
|
if (SKIP_FILES.has(safe)) return { status: "bad-name" };
|
|
29798
30114
|
if (Buffer.byteLength(content, "utf8") > MAX_CONTENT_BYTES) return { status: "too-large" };
|
|
29799
|
-
const abs =
|
|
30115
|
+
const abs = join23(absDir, safe);
|
|
29800
30116
|
try {
|
|
29801
|
-
|
|
30117
|
+
writeFileSync9(abs, content, { encoding: "utf8", flag: "wx" });
|
|
29802
30118
|
} catch (err) {
|
|
29803
30119
|
if (err.code === "EEXIST") return { status: "exists" };
|
|
29804
30120
|
throw err;
|
|
@@ -29819,7 +30135,7 @@ function moveDocEntry(root, from, to) {
|
|
|
29819
30135
|
if (!isDir && !stat.isFile()) return { status: "not-found" };
|
|
29820
30136
|
const absTo = resolve7(root, to);
|
|
29821
30137
|
if (!absTo.startsWith(root + sep3)) return { status: "bad-target" };
|
|
29822
|
-
const name = sanitizeUploadName(
|
|
30138
|
+
const name = sanitizeUploadName(basename6(absTo));
|
|
29823
30139
|
if (!name) return { status: "bad-target" };
|
|
29824
30140
|
if (!isDir) {
|
|
29825
30141
|
const ext = extname2(name).toLowerCase();
|
|
@@ -29827,14 +30143,14 @@ function moveDocEntry(root, from, to) {
|
|
|
29827
30143
|
return { status: "bad-target" };
|
|
29828
30144
|
}
|
|
29829
30145
|
}
|
|
29830
|
-
const absToDir =
|
|
30146
|
+
const absToDir = dirname4(absTo);
|
|
29831
30147
|
if (resolveDirPath(root, relative(root, absToDir)) === null) return { status: "bad-target" };
|
|
29832
30148
|
try {
|
|
29833
30149
|
if (!statSync7(absToDir).isDirectory()) return { status: "bad-target" };
|
|
29834
30150
|
} catch {
|
|
29835
30151
|
return { status: "bad-target" };
|
|
29836
30152
|
}
|
|
29837
|
-
const finalAbs =
|
|
30153
|
+
const finalAbs = join23(absToDir, name);
|
|
29838
30154
|
if (isDir && (finalAbs === absFrom || finalAbs.startsWith(absFrom + sep3))) {
|
|
29839
30155
|
return { status: "into-self" };
|
|
29840
30156
|
}
|
|
@@ -29842,7 +30158,7 @@ function moveDocEntry(root, from, to) {
|
|
|
29842
30158
|
if (realpathSync(finalAbs) !== realpathSync(absFrom)) return { status: "exists" };
|
|
29843
30159
|
} catch {
|
|
29844
30160
|
}
|
|
29845
|
-
|
|
30161
|
+
renameSync3(absFrom, finalAbs);
|
|
29846
30162
|
return { status: "ok", path: relative(root, finalAbs).split(sep3).join("/"), name };
|
|
29847
30163
|
}
|
|
29848
30164
|
function deleteDocEntry(root, path) {
|
|
@@ -29857,7 +30173,7 @@ function deleteDocEntry(root, path) {
|
|
|
29857
30173
|
}
|
|
29858
30174
|
const isDir = stat.isDirectory();
|
|
29859
30175
|
if (!isDir && !stat.isFile() && !stat.isSymbolicLink()) return { status: "not-found" };
|
|
29860
|
-
|
|
30176
|
+
rmSync12(abs, { recursive: isDir });
|
|
29861
30177
|
return {
|
|
29862
30178
|
status: "ok",
|
|
29863
30179
|
path: relative(root, abs).split(sep3).join("/"),
|
|
@@ -29896,7 +30212,7 @@ function createDocsRouter({ gate = requireDocsAccess } = {}) {
|
|
|
29896
30212
|
}
|
|
29897
30213
|
if (!stat.isFile()) return c.json({ error: "not found" }, 404);
|
|
29898
30214
|
if (stat.size > MAX_RAW_BYTES) return c.json({ error: "file too large" }, 413);
|
|
29899
|
-
const name =
|
|
30215
|
+
const name = basename6(resolved2.abs);
|
|
29900
30216
|
const asciiName = name.replace(/[^\x20-\x7e]/g, "_").replace(/["\\]/g, "_");
|
|
29901
30217
|
const disposition = download ? "attachment" : "inline";
|
|
29902
30218
|
const stream = Readable.toWeb(createReadStream(resolved2.abs));
|
|
@@ -29918,7 +30234,7 @@ function createDocsRouter({ gate = requireDocsAccess } = {}) {
|
|
|
29918
30234
|
}
|
|
29919
30235
|
if (!stat.isFile()) return c.json({ error: "not found" }, 404);
|
|
29920
30236
|
if (stat.size > MAX_RAW_BYTES) return c.json({ error: "file too large" }, 413);
|
|
29921
|
-
return c.body(withDocLinkBridge(
|
|
30237
|
+
return c.body(withDocLinkBridge(readFileSync19(abs, "utf8")), 200, {
|
|
29922
30238
|
"Content-Type": "text/html; charset=utf-8",
|
|
29923
30239
|
"Content-Security-Policy": HTML_SHARE_CSP,
|
|
29924
30240
|
"X-Content-Type-Options": "nosniff",
|
|
@@ -30100,10 +30416,10 @@ function createDocsRouter({ gate = requireDocsAccess } = {}) {
|
|
|
30100
30416
|
// by; only docs get a parsed title.
|
|
30101
30417
|
kind: kind ?? "code",
|
|
30102
30418
|
lang: kind ? void 0 : CODE_EXTENSIONS[ext],
|
|
30103
|
-
title: kind ? extractTitle(abs, kind) :
|
|
30419
|
+
title: kind ? extractTitle(abs, kind) : basename6(abs),
|
|
30104
30420
|
mtime: stat.mtime.toISOString(),
|
|
30105
30421
|
tooLarge: tooLarge || void 0,
|
|
30106
|
-
content: tooLarge ? "" :
|
|
30422
|
+
content: tooLarge ? "" : readFileSync19(abs, "utf8")
|
|
30107
30423
|
});
|
|
30108
30424
|
});
|
|
30109
30425
|
app.put("/:id/docs/content", async (c) => {
|
|
@@ -30146,7 +30462,7 @@ function createDocsRouter({ gate = requireDocsAccess } = {}) {
|
|
|
30146
30462
|
channel,
|
|
30147
30463
|
rel,
|
|
30148
30464
|
title: extractTitle(abs, "md"),
|
|
30149
|
-
content:
|
|
30465
|
+
content: readFileSync19(abs, "utf8")
|
|
30150
30466
|
};
|
|
30151
30467
|
};
|
|
30152
30468
|
app.get("/:id/docs/translation/:lang", async (c) => {
|
|
@@ -30204,7 +30520,7 @@ function withDocLinkBridge(html) {
|
|
|
30204
30520
|
var DOC_MENTION_RE = /(?<![\w@/`])@((?:[\w.-]+\/)+[\w.-]+\.[A-Za-z0-9]{1,6})(?::(\d+))?(?![\w-])/g;
|
|
30205
30521
|
function isRealDoc(root, rel) {
|
|
30206
30522
|
const abs = resolveDocPath(root, rel);
|
|
30207
|
-
if (!abs || !
|
|
30523
|
+
if (!abs || !existsSync22(abs)) return false;
|
|
30208
30524
|
try {
|
|
30209
30525
|
return statSync8(abs).isFile();
|
|
30210
30526
|
} catch {
|
|
@@ -30645,7 +30961,7 @@ var BACKGROUND_CHECK_IN_MS = 30 * 6e4;
|
|
|
30645
30961
|
var MISSED_MESSAGE_WINDOW_MS = 24 * 60 * 60 * 1e3;
|
|
30646
30962
|
var MISSED_MESSAGE_THREAD_LIMIT = 100;
|
|
30647
30963
|
var delay = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
30648
|
-
function stripPathPrefixes(label, roots, home =
|
|
30964
|
+
function stripPathPrefixes(label, roots, home = homedir8()) {
|
|
30649
30965
|
let out = label;
|
|
30650
30966
|
for (const root of roots) {
|
|
30651
30967
|
if (root) out = out.replaceAll(`${root.replace(/\/+$/, "")}/`, "");
|
|
@@ -34200,6 +34516,7 @@ async function startServer() {
|
|
|
34200
34516
|
const reactionStore = new ReactionStore(paths.DB_FILE);
|
|
34201
34517
|
const slack = config.slackBotToken ? createSlackApp(config) : void 0;
|
|
34202
34518
|
await refreshChannelRegistry();
|
|
34519
|
+
void autoSyncPersonaAvatars(getProfile());
|
|
34203
34520
|
warnOnBrokenChannelCwds();
|
|
34204
34521
|
const stopChannelPolling = startChannelRegistryPolling();
|
|
34205
34522
|
await refreshAutomationRegistry();
|
|
@@ -34348,6 +34665,33 @@ export {
|
|
|
34348
34665
|
DEFAULT_TIMEZONE,
|
|
34349
34666
|
loadAutomations,
|
|
34350
34667
|
loadEffectiveAutomations,
|
|
34668
|
+
DEFAULT_API_URL,
|
|
34669
|
+
AuthApiError,
|
|
34670
|
+
apiUrl,
|
|
34671
|
+
deviceKeyPath,
|
|
34672
|
+
credentialsPath,
|
|
34673
|
+
ensureDeviceKey,
|
|
34674
|
+
loadCredentials,
|
|
34675
|
+
saveCredentials,
|
|
34676
|
+
clearLocalAuth,
|
|
34677
|
+
requestDeviceCode,
|
|
34678
|
+
pollDeviceToken,
|
|
34679
|
+
fetchWhoAmI,
|
|
34680
|
+
boundWorkspaces,
|
|
34681
|
+
revokeDevice,
|
|
34682
|
+
getAccessToken,
|
|
34683
|
+
acquireHostLock,
|
|
34684
|
+
publishHostEndpoint,
|
|
34685
|
+
readHostEndpoint,
|
|
34686
|
+
setHostDbSender,
|
|
34687
|
+
handleHostDbResult,
|
|
34688
|
+
requestHostDb,
|
|
34689
|
+
handleAttachmentUrlResult,
|
|
34690
|
+
handleShouldRespondResult,
|
|
34691
|
+
LOCAL_DB_PATH,
|
|
34692
|
+
createHostDbClient,
|
|
34693
|
+
useHostDbWithoutCredentials,
|
|
34694
|
+
runPersonaCmd,
|
|
34351
34695
|
MEMORY_TYPES,
|
|
34352
34696
|
isMemoryType,
|
|
34353
34697
|
validateMemoryInput,
|
|
@@ -34413,16 +34757,6 @@ export {
|
|
|
34413
34757
|
CLI_VERSION,
|
|
34414
34758
|
isOlderVersion,
|
|
34415
34759
|
latestCliVersion,
|
|
34416
|
-
acquireHostLock,
|
|
34417
|
-
publishHostEndpoint,
|
|
34418
|
-
readHostEndpoint,
|
|
34419
|
-
setHostDbSender,
|
|
34420
|
-
handleHostDbResult,
|
|
34421
|
-
requestHostDb,
|
|
34422
|
-
handleAttachmentUrlResult,
|
|
34423
|
-
handleShouldRespondResult,
|
|
34424
|
-
LOCAL_DB_PATH,
|
|
34425
|
-
createHostDbClient,
|
|
34426
34760
|
workspaceSkillsDir,
|
|
34427
34761
|
channelSkillsDir,
|
|
34428
34762
|
isValidSkillName,
|