flyspace-cli 0.1.56 → 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-ZUYZL7Y3.js → chunk-TAUF3WGB.js} +826 -487
- package/dist/cli.js +267 -432
- 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;
|
|
@@ -18595,6 +18597,7 @@ var BRANDING_DEFAULTS = {
|
|
|
18595
18597
|
gaMeasurementId: null,
|
|
18596
18598
|
botName: null,
|
|
18597
18599
|
botAvatar: null,
|
|
18600
|
+
botExpressionAvatars: null,
|
|
18598
18601
|
autoTitleEnabled: true,
|
|
18599
18602
|
autoTitlePrompt: null
|
|
18600
18603
|
};
|
|
@@ -18609,6 +18612,7 @@ function rowToBranding(row) {
|
|
|
18609
18612
|
gaMeasurementId: row["ga_measurement_id"] ?? null,
|
|
18610
18613
|
botName: row["bot_name"] ?? null,
|
|
18611
18614
|
botAvatar: row["bot_avatar"] ?? null,
|
|
18615
|
+
botExpressionAvatars: row["bot_expression_avatars"] ?? null,
|
|
18612
18616
|
autoTitleEnabled: row["auto_title_enabled"] !== false,
|
|
18613
18617
|
autoTitlePrompt: row["auto_title_prompt"] ?? null
|
|
18614
18618
|
};
|
|
@@ -18618,7 +18622,7 @@ var cache2 = /* @__PURE__ */ new Map();
|
|
|
18618
18622
|
async function getWorkspaceBranding(profile) {
|
|
18619
18623
|
const hit = cache2.get(profile);
|
|
18620
18624
|
if (hit && Date.now() - hit.readAt < CACHE_TTL_MS3) return hit.value;
|
|
18621
|
-
const { data, error } = await getSupabaseClient().from("workspace_settings").select("theme, font, logo, display_name, ga_measurement_id, bot_name, bot_avatar, auto_title_enabled, auto_title_prompt").eq("profile", profile).maybeSingle();
|
|
18625
|
+
const { data, error } = await getSupabaseClient().from("workspace_settings").select("theme, font, logo, display_name, ga_measurement_id, bot_name, bot_avatar, bot_expression_avatars, auto_title_enabled, auto_title_prompt").eq("profile", profile).maybeSingle();
|
|
18622
18626
|
if (error) throw new Error(`failed to read workspace settings: ${error.message}`);
|
|
18623
18627
|
const value = data ? rowToBranding(data) : null;
|
|
18624
18628
|
cache2.set(profile, { value, readAt: Date.now() });
|
|
@@ -18634,6 +18638,7 @@ async function upsertWorkspaceBranding(profile, patch) {
|
|
|
18634
18638
|
gaMeasurementId: patch.gaMeasurementId === void 0 ? current.gaMeasurementId : patch.gaMeasurementId,
|
|
18635
18639
|
botName: patch.botName === void 0 ? current.botName : patch.botName,
|
|
18636
18640
|
botAvatar: patch.botAvatar === void 0 ? current.botAvatar : patch.botAvatar,
|
|
18641
|
+
botExpressionAvatars: patch.botExpressionAvatars === void 0 ? current.botExpressionAvatars : patch.botExpressionAvatars,
|
|
18637
18642
|
autoTitleEnabled: patch.autoTitleEnabled ?? current.autoTitleEnabled,
|
|
18638
18643
|
autoTitlePrompt: patch.autoTitlePrompt === void 0 ? current.autoTitlePrompt : patch.autoTitlePrompt
|
|
18639
18644
|
};
|
|
@@ -18647,6 +18652,7 @@ async function upsertWorkspaceBranding(profile, patch) {
|
|
|
18647
18652
|
ga_measurement_id: next.gaMeasurementId,
|
|
18648
18653
|
bot_name: next.botName,
|
|
18649
18654
|
bot_avatar: next.botAvatar,
|
|
18655
|
+
bot_expression_avatars: next.botExpressionAvatars,
|
|
18650
18656
|
auto_title_enabled: next.autoTitleEnabled,
|
|
18651
18657
|
auto_title_prompt: next.autoTitlePrompt,
|
|
18652
18658
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
@@ -18762,7 +18768,8 @@ async function loadBotIdentity(profile = getProfile()) {
|
|
|
18762
18768
|
const branding = await getWorkspaceBranding(profile);
|
|
18763
18769
|
return {
|
|
18764
18770
|
displayName: branding?.botName ?? void 0,
|
|
18765
|
-
avatar: branding?.botAvatar ?? void 0
|
|
18771
|
+
avatar: branding?.botAvatar ?? void 0,
|
|
18772
|
+
expressionAvatars: branding?.botExpressionAvatars ?? void 0
|
|
18766
18773
|
};
|
|
18767
18774
|
}
|
|
18768
18775
|
async function saveBotIdentity(patch, profile = getProfile()) {
|
|
@@ -20921,6 +20928,555 @@ async function runCompanion(config, userId, slot) {
|
|
|
20921
20928
|
}
|
|
20922
20929
|
}
|
|
20923
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
|
+
|
|
20924
21480
|
// ../api/src/feature-flags.ts
|
|
20925
21481
|
var featureFlags = {
|
|
20926
21482
|
"ai-cost": {
|
|
@@ -21387,8 +21943,8 @@ async function buildPrompt(profile, channelId, opts) {
|
|
|
21387
21943
|
}
|
|
21388
21944
|
|
|
21389
21945
|
// src/dashboard/settings-host.ts
|
|
21390
|
-
import { writeFileSync as
|
|
21391
|
-
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";
|
|
21392
21948
|
|
|
21393
21949
|
// ../api/src/dashboard/auto-title.ts
|
|
21394
21950
|
var GROQ_API_URL = "https://api.groq.com/openai/v1/chat/completions";
|
|
@@ -21549,9 +22105,9 @@ function parseAgentProfiles(raw) {
|
|
|
21549
22105
|
return entries2.length > 0 ? Object.fromEntries(entries2) : void 0;
|
|
21550
22106
|
}
|
|
21551
22107
|
function loadDashboardSettings() {
|
|
21552
|
-
if (!
|
|
22108
|
+
if (!existsSync10(paths.DASHBOARD_SETTINGS_FILE)) return localDefaults();
|
|
21553
22109
|
try {
|
|
21554
|
-
const raw = JSON.parse(
|
|
22110
|
+
const raw = JSON.parse(readFileSync7(paths.DASHBOARD_SETTINGS_FILE, "utf-8"));
|
|
21555
22111
|
const providers = parseProviders(raw.providers, {
|
|
21556
22112
|
agent: normalizeDefaultModel(raw.agent, localDefaults().agent),
|
|
21557
22113
|
fallbackModel: typeof raw.fallbackModel === "string" && isAllowedModel(raw.fallbackModel) ? raw.fallbackModel : void 0
|
|
@@ -21578,9 +22134,9 @@ function withFallbackModel(providers, model) {
|
|
|
21578
22134
|
return [cleared[0], { runner, model }, ...cleared.slice(1).filter((p) => p.runner !== runner)];
|
|
21579
22135
|
}
|
|
21580
22136
|
function writeSettings(next) {
|
|
21581
|
-
|
|
22137
|
+
mkdirSync7(dirname2(paths.DASHBOARD_SETTINGS_FILE), { recursive: true });
|
|
21582
22138
|
const merged = { ...readSettingsFile() ?? {}, ...next };
|
|
21583
|
-
|
|
22139
|
+
writeFileSync6(paths.DASHBOARD_SETTINGS_FILE, JSON.stringify(merged, null, 2), "utf-8");
|
|
21584
22140
|
return next;
|
|
21585
22141
|
}
|
|
21586
22142
|
function saveDashboardSettings(patch) {
|
|
@@ -21614,13 +22170,13 @@ async function loadFullDashboardSettings(profile = getProfile()) {
|
|
|
21614
22170
|
function saveWorkspacePrompt(prompt) {
|
|
21615
22171
|
const trimmed = prompt.trim();
|
|
21616
22172
|
if (!trimmed || trimmed === loadWorkspacePrompt().defaultPrompt) return resetWorkspacePrompt();
|
|
21617
|
-
|
|
21618
|
-
|
|
22173
|
+
mkdirSync7(dirname2(paths.PROMPT_FILE), { recursive: true });
|
|
22174
|
+
writeFileSync6(paths.PROMPT_FILE, `${trimmed}
|
|
21619
22175
|
`, "utf-8");
|
|
21620
22176
|
return loadWorkspacePrompt();
|
|
21621
22177
|
}
|
|
21622
22178
|
function resetWorkspacePrompt() {
|
|
21623
|
-
|
|
22179
|
+
rmSync6(paths.PROMPT_FILE, { force: true });
|
|
21624
22180
|
return loadWorkspacePrompt();
|
|
21625
22181
|
}
|
|
21626
22182
|
function saveAgentProfile(name, patch) {
|
|
@@ -21645,9 +22201,9 @@ function saveAgentProfile(name, patch) {
|
|
|
21645
22201
|
|
|
21646
22202
|
// ../api/src/codex/agent.ts
|
|
21647
22203
|
import { spawn as spawn2 } from "child_process";
|
|
21648
|
-
import { existsSync as
|
|
22204
|
+
import { existsSync as existsSync11, mkdtempSync as mkdtempSync3, readFileSync as readFileSync8, rmSync as rmSync7, statSync as statSync3 } from "fs";
|
|
21649
22205
|
import { tmpdir as tmpdir2 } from "os";
|
|
21650
|
-
import { join as
|
|
22206
|
+
import { join as join9 } from "path";
|
|
21651
22207
|
var AUTH_ERROR_PATTERNS2 = [
|
|
21652
22208
|
/401 unauthorized/i,
|
|
21653
22209
|
/missing bearer or basic authentication/i,
|
|
@@ -21778,8 +22334,8 @@ function getMaxDurationMs2() {
|
|
|
21778
22334
|
}
|
|
21779
22335
|
function codexAuthAvailable(env = process.env) {
|
|
21780
22336
|
if (env["OPENAI_API_KEY"]?.trim()) return true;
|
|
21781
|
-
const home = env["CODEX_HOME"]?.trim() ||
|
|
21782
|
-
return
|
|
22337
|
+
const home = env["CODEX_HOME"]?.trim() || join9(env["HOME"] ?? "", ".codex");
|
|
22338
|
+
return existsSync11(join9(home, "auth.json"));
|
|
21783
22339
|
}
|
|
21784
22340
|
function applySystemPrompt(prompt, options, resumeSessionId) {
|
|
21785
22341
|
if (resumeSessionId || !options.systemPrompt?.trim()) return prompt;
|
|
@@ -21833,8 +22389,8 @@ function runCodexCli(prompt, cwd, options, resumeSessionId) {
|
|
|
21833
22389
|
recordCodexUsage(response, options);
|
|
21834
22390
|
resolve8(response);
|
|
21835
22391
|
};
|
|
21836
|
-
const scratch =
|
|
21837
|
-
const lastMessageFile =
|
|
22392
|
+
const scratch = mkdtempSync3(join9(tmpdir2(), "flyspace-codex-"));
|
|
22393
|
+
const lastMessageFile = join9(scratch, "last-message.txt");
|
|
21838
22394
|
const args = buildArgs2(prompt, options, lastMessageFile, resumeSessionId);
|
|
21839
22395
|
console.log(`[codex] spawning codex CLI in ${cwd}`);
|
|
21840
22396
|
console.log(`[codex] args: ${args.slice(0, -1).join(" ")}`);
|
|
@@ -21904,7 +22460,7 @@ function runCodexCli(prompt, cwd, options, resumeSessionId) {
|
|
|
21904
22460
|
const cleanup = () => {
|
|
21905
22461
|
clearTimeout(timeoutHandle);
|
|
21906
22462
|
if (signal) signal.removeEventListener("abort", onAbort);
|
|
21907
|
-
|
|
22463
|
+
rmSync7(scratch, { recursive: true, force: true });
|
|
21908
22464
|
};
|
|
21909
22465
|
child.stdout.setEncoding("utf8");
|
|
21910
22466
|
child.stderr.setEncoding("utf8");
|
|
@@ -21933,7 +22489,7 @@ function runCodexCli(prompt, cwd, options, resumeSessionId) {
|
|
|
21933
22489
|
child.on("close", (code, signal2) => {
|
|
21934
22490
|
let lastMessage = "";
|
|
21935
22491
|
try {
|
|
21936
|
-
lastMessage =
|
|
22492
|
+
lastMessage = readFileSync8(lastMessageFile, "utf8").trim();
|
|
21937
22493
|
} catch {
|
|
21938
22494
|
lastMessage = "";
|
|
21939
22495
|
}
|
|
@@ -21987,7 +22543,7 @@ function runCodexCli(prompt, cwd, options, resumeSessionId) {
|
|
|
21987
22543
|
});
|
|
21988
22544
|
}
|
|
21989
22545
|
async function askCodex(prompt, cwd, options = {}, resumeSessionId) {
|
|
21990
|
-
if (!
|
|
22546
|
+
if (!existsSync11(cwd) || !statSync3(cwd).isDirectory()) {
|
|
21991
22547
|
console.error(`[codex] working directory does not exist: ${cwd}`);
|
|
21992
22548
|
return {
|
|
21993
22549
|
sessionId: resumeSessionId ?? "",
|
|
@@ -22440,7 +22996,7 @@ function renderAsciiTable(t) {
|
|
|
22440
22996
|
}
|
|
22441
22997
|
|
|
22442
22998
|
// src/store/channel-cache.ts
|
|
22443
|
-
import { mkdirSync as
|
|
22999
|
+
import { mkdirSync as mkdirSync8 } from "fs";
|
|
22444
23000
|
|
|
22445
23001
|
// src/store/sqlite.ts
|
|
22446
23002
|
import Database from "better-sqlite3";
|
|
@@ -22464,7 +23020,7 @@ function getDb() {
|
|
|
22464
23020
|
const file = paths.DB_FILE;
|
|
22465
23021
|
const existing = dbs.get(file);
|
|
22466
23022
|
if (existing) return existing;
|
|
22467
|
-
|
|
23023
|
+
mkdirSync8(paths.DATA_DIR, { recursive: true });
|
|
22468
23024
|
const db = openLocalDatabase(file);
|
|
22469
23025
|
if (!db) return null;
|
|
22470
23026
|
db.exec(`
|
|
@@ -22980,17 +23536,17 @@ var TriggerEngine = class {
|
|
|
22980
23536
|
};
|
|
22981
23537
|
|
|
22982
23538
|
// src/store/user-cache.ts
|
|
22983
|
-
import { existsSync as
|
|
22984
|
-
import { join as
|
|
23539
|
+
import { existsSync as existsSync12, readFileSync as readFileSync9 } from "fs";
|
|
23540
|
+
import { join as join10 } from "path";
|
|
22985
23541
|
function jsonUserCachePath() {
|
|
22986
|
-
const file =
|
|
22987
|
-
return
|
|
23542
|
+
const file = join10(paths.CONFIG_DIR, "slack_users.json");
|
|
23543
|
+
return existsSync12(file) ? file : void 0;
|
|
22988
23544
|
}
|
|
22989
23545
|
function readJsonUserCache() {
|
|
22990
23546
|
const file = jsonUserCachePath();
|
|
22991
23547
|
if (!file) return void 0;
|
|
22992
23548
|
try {
|
|
22993
|
-
const parsed = JSON.parse(
|
|
23549
|
+
const parsed = JSON.parse(readFileSync9(file, "utf8"));
|
|
22994
23550
|
return parsed.users;
|
|
22995
23551
|
} catch {
|
|
22996
23552
|
return void 0;
|
|
@@ -23397,7 +23953,7 @@ var MessageQueue = class {
|
|
|
23397
23953
|
|
|
23398
23954
|
// src/slack/file-downloader.ts
|
|
23399
23955
|
import { writeFile } from "fs/promises";
|
|
23400
|
-
import { join as
|
|
23956
|
+
import { join as join11, extname } from "path";
|
|
23401
23957
|
var debug3 = process.env["DEBUG"] === "true";
|
|
23402
23958
|
var SUPPORTED_IMAGE_MIMETYPES = /* @__PURE__ */ new Set([
|
|
23403
23959
|
"image/png",
|
|
@@ -23497,7 +24053,7 @@ async function downloadOne(file, botToken) {
|
|
|
23497
24053
|
const ext = extname(originalName) || `.${file.filetype ?? "bin"}`;
|
|
23498
24054
|
const safeName = sanitizeFilename(originalName.replace(ext, ""));
|
|
23499
24055
|
const filename = `${Date.now()}-${file.id ?? "unnamed"}-${safeName}${ext}`;
|
|
23500
|
-
const localPath =
|
|
24056
|
+
const localPath = join11(paths.UPLOADS_DIR, filename);
|
|
23501
24057
|
await writeFile(localPath, buffer);
|
|
23502
24058
|
if (debug3)
|
|
23503
24059
|
console.log(`[file-downloader] saved ${file.id} -> ${localPath} (${buffer.length} bytes)`);
|
|
@@ -23667,9 +24223,9 @@ function identityHandleFor(slackUserId) {
|
|
|
23667
24223
|
}
|
|
23668
24224
|
|
|
23669
24225
|
// src/store/slack-avatar-sync.ts
|
|
23670
|
-
import
|
|
24226
|
+
import sharp2 from "sharp";
|
|
23671
24227
|
import { PutObjectCommand } from "@aws-sdk/client-s3";
|
|
23672
|
-
var
|
|
24228
|
+
var AVATAR_SIZE2 = 192;
|
|
23673
24229
|
function r2Configured() {
|
|
23674
24230
|
return Boolean(
|
|
23675
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"]
|
|
@@ -23691,7 +24247,7 @@ async function syncSlackAvatars(ids) {
|
|
|
23691
24247
|
const res = await fetch(row.image_url);
|
|
23692
24248
|
if (!res.ok) throw new Error(`fetch ${res.status}`);
|
|
23693
24249
|
const original = Buffer.from(await res.arrayBuffer());
|
|
23694
|
-
const resized = await
|
|
24250
|
+
const resized = await sharp2(original).resize({ width: AVATAR_SIZE2, height: AVATAR_SIZE2, fit: "cover" }).png().toBuffer();
|
|
23695
24251
|
const key = `avatar/slack/${getProfile()}/${id}.png`;
|
|
23696
24252
|
await getR2Client().send(
|
|
23697
24253
|
new PutObjectCommand({
|
|
@@ -23945,16 +24501,16 @@ async function summariseThreadTranscript(transcript, opts, deps = {}) {
|
|
|
23945
24501
|
}
|
|
23946
24502
|
|
|
23947
24503
|
// src/dashboard/chat-agent.ts
|
|
23948
|
-
import { homedir as
|
|
24504
|
+
import { homedir as homedir8 } from "os";
|
|
23949
24505
|
import { stripVTControlCharacters } from "util";
|
|
23950
24506
|
|
|
23951
24507
|
// src/mcp/config.ts
|
|
23952
|
-
import { mkdtempSync as
|
|
24508
|
+
import { mkdtempSync as mkdtempSync4, rmSync as rmSync8, writeFileSync as writeFileSync7 } from "fs";
|
|
23953
24509
|
import { tmpdir as tmpdir3 } from "os";
|
|
23954
|
-
import { join as
|
|
24510
|
+
import { join as join12 } from "path";
|
|
23955
24511
|
|
|
23956
24512
|
// ../api/src/mcp/crypto.ts
|
|
23957
|
-
import { createCipheriv, createDecipheriv, randomBytes, timingSafeEqual } from "crypto";
|
|
24513
|
+
import { createCipheriv, createDecipheriv, randomBytes as randomBytes2, timingSafeEqual } from "crypto";
|
|
23958
24514
|
var ALGORITHM = "aes-256-gcm";
|
|
23959
24515
|
var KEY_BYTES = 32;
|
|
23960
24516
|
var IV_BYTES = 12;
|
|
@@ -23987,7 +24543,7 @@ function currentKeyVersion() {
|
|
|
23987
24543
|
);
|
|
23988
24544
|
}
|
|
23989
24545
|
function encrypt(key, purpose, plaintext) {
|
|
23990
|
-
const iv =
|
|
24546
|
+
const iv = randomBytes2(IV_BYTES);
|
|
23991
24547
|
const cipher = createCipheriv(ALGORITHM, key, iv);
|
|
23992
24548
|
cipher.setAAD(Buffer.from(purpose, "utf8"));
|
|
23993
24549
|
const ciphertext = Buffer.concat([cipher.update(plaintext, "utf8"), cipher.final()]);
|
|
@@ -24007,7 +24563,7 @@ function decrypt(key, purpose, blob) {
|
|
|
24007
24563
|
}
|
|
24008
24564
|
function createEnvelope() {
|
|
24009
24565
|
const keyVersion = currentKeyVersion();
|
|
24010
|
-
const key =
|
|
24566
|
+
const key = randomBytes2(KEY_BYTES);
|
|
24011
24567
|
const wrappedDek = encrypt(
|
|
24012
24568
|
readMasterKey(keyVersion),
|
|
24013
24569
|
purposeForDek(keyVersion),
|
|
@@ -24073,7 +24629,7 @@ function secretsMatch(a, b) {
|
|
|
24073
24629
|
}
|
|
24074
24630
|
|
|
24075
24631
|
// ../api/src/mcp/oauth.ts
|
|
24076
|
-
import { createHash as
|
|
24632
|
+
import { createHash as createHash4, randomBytes as randomBytes3 } from "crypto";
|
|
24077
24633
|
var RESERVED_AUTHORIZE_PARAMS = /* @__PURE__ */ new Set([
|
|
24078
24634
|
"client_id",
|
|
24079
24635
|
"redirect_uri",
|
|
@@ -24087,11 +24643,11 @@ function base64url(buffer) {
|
|
|
24087
24643
|
return buffer.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
24088
24644
|
}
|
|
24089
24645
|
function createStateToken() {
|
|
24090
|
-
return base64url(
|
|
24646
|
+
return base64url(randomBytes3(32));
|
|
24091
24647
|
}
|
|
24092
24648
|
function createPkcePair() {
|
|
24093
|
-
const verifier = base64url(
|
|
24094
|
-
const challenge = base64url(
|
|
24649
|
+
const verifier = base64url(randomBytes3(32));
|
|
24650
|
+
const challenge = base64url(createHash4("sha256").update(verifier).digest());
|
|
24095
24651
|
return { verifier, challenge };
|
|
24096
24652
|
}
|
|
24097
24653
|
function clientEnvName(providerSlug, suffix) {
|
|
@@ -24211,7 +24767,7 @@ async function exchangeCode(params) {
|
|
|
24211
24767
|
);
|
|
24212
24768
|
return { ...tokens, scopes: tokens.scopes.length ? tokens.scopes : provider.defaultScopes };
|
|
24213
24769
|
}
|
|
24214
|
-
async function
|
|
24770
|
+
async function refreshAccessToken2(params) {
|
|
24215
24771
|
const { provider, client, refreshToken } = params;
|
|
24216
24772
|
return requestToken(
|
|
24217
24773
|
provider,
|
|
@@ -24497,7 +25053,7 @@ async function renew(workspaceId, connection, provider, deps) {
|
|
|
24497
25053
|
}
|
|
24498
25054
|
let tokens;
|
|
24499
25055
|
try {
|
|
24500
|
-
tokens = await
|
|
25056
|
+
tokens = await refreshAccessToken2({
|
|
24501
25057
|
provider,
|
|
24502
25058
|
client: readOAuthClient(provider.slug),
|
|
24503
25059
|
refreshToken,
|
|
@@ -24637,12 +25193,12 @@ async function buildMcpConfig(profile, connectionIds) {
|
|
|
24637
25193
|
return { config, skipped };
|
|
24638
25194
|
}
|
|
24639
25195
|
function writeMcpConfigFile(config) {
|
|
24640
|
-
const dir =
|
|
24641
|
-
const path =
|
|
24642
|
-
|
|
25196
|
+
const dir = mkdtempSync4(join12(tmpdir3(), "flyspace-mcp-"));
|
|
25197
|
+
const path = join12(dir, "mcp-config.json");
|
|
25198
|
+
writeFileSync7(path, JSON.stringify(config), { mode: 384 });
|
|
24643
25199
|
return {
|
|
24644
25200
|
path,
|
|
24645
|
-
cleanup: () =>
|
|
25201
|
+
cleanup: () => rmSync8(dir, { recursive: true, force: true })
|
|
24646
25202
|
};
|
|
24647
25203
|
}
|
|
24648
25204
|
async function withMcpConfig(profile, connectionIds, fn, extraServers = {}) {
|
|
@@ -24660,8 +25216,8 @@ async function withMcpConfig(profile, connectionIds, fn, extraServers = {}) {
|
|
|
24660
25216
|
}
|
|
24661
25217
|
|
|
24662
25218
|
// ../api/src/version.ts
|
|
24663
|
-
import { readFileSync as
|
|
24664
|
-
var CLI_VERSION = true ? "0.1.
|
|
25219
|
+
import { readFileSync as readFileSync10 } from "fs";
|
|
25220
|
+
var CLI_VERSION = true ? "0.1.58" : devVersion();
|
|
24665
25221
|
function isOlderVersion(a, b) {
|
|
24666
25222
|
const parse2 = (v) => v.replace(/^v/, "").split("-")[0].split(".").map(Number);
|
|
24667
25223
|
const [pa, pb] = [parse2(a), parse2(b)];
|
|
@@ -24683,278 +25239,43 @@ async function latestCliVersion() {
|
|
|
24683
25239
|
return version;
|
|
24684
25240
|
}
|
|
24685
25241
|
|
|
24686
|
-
// src/dashboard/host-db-client.ts
|
|
24687
|
-
import { createClient } from "@supabase/supabase-js";
|
|
24688
|
-
import { randomUUID as randomUUID2 } from "crypto";
|
|
24689
|
-
|
|
24690
|
-
// src/dashboard/host-lock.ts
|
|
24691
|
-
import { execFileSync as execFileSync4 } from "child_process";
|
|
24692
|
-
import { randomBytes as randomBytes3 } from "crypto";
|
|
24693
|
-
import { mkdirSync as mkdirSync7, readFileSync as readFileSync8, rmSync as rmSync6, writeFileSync as writeFileSync5 } from "fs";
|
|
24694
|
-
import { join as join10 } from "path";
|
|
24695
|
-
function hostLockPath() {
|
|
24696
|
-
return join10(paths.BASE_DATA_DIR, "host.lock");
|
|
24697
|
-
}
|
|
24698
|
-
function isLiveFlyspace(pid) {
|
|
24699
|
-
try {
|
|
24700
|
-
process.kill(pid, 0);
|
|
24701
|
-
const command = execFileSync4("ps", ["-p", String(pid), "-o", "command="], {
|
|
24702
|
-
encoding: "utf8"
|
|
24703
|
-
});
|
|
24704
|
-
return command.includes("flyspace") || command.includes("host-server");
|
|
24705
|
-
} catch {
|
|
24706
|
-
return false;
|
|
24707
|
-
}
|
|
24708
|
-
}
|
|
24709
|
-
function readLockPid(path) {
|
|
24710
|
-
try {
|
|
24711
|
-
const pid = Number(JSON.parse(readFileSync8(path, "utf8")).pid);
|
|
24712
|
-
return Number.isInteger(pid) && pid > 0 ? pid : null;
|
|
24713
|
-
} catch {
|
|
24714
|
-
return null;
|
|
24715
|
-
}
|
|
24716
|
-
}
|
|
24717
|
-
function acquireHostLock() {
|
|
24718
|
-
const path = hostLockPath();
|
|
24719
|
-
mkdirSync7(paths.BASE_DATA_DIR, { recursive: true });
|
|
24720
|
-
const body = JSON.stringify({
|
|
24721
|
-
pid: process.pid,
|
|
24722
|
-
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
24723
|
-
execPath: process.argv[1] ?? ""
|
|
24724
|
-
});
|
|
24725
|
-
for (let attempt = 0; attempt < 2; attempt++) {
|
|
24726
|
-
try {
|
|
24727
|
-
writeFileSync5(path, body, { flag: "wx", mode: 384 });
|
|
24728
|
-
const release = () => {
|
|
24729
|
-
if (readLockPid(path) === process.pid) rmSync6(path, { force: true });
|
|
24730
|
-
};
|
|
24731
|
-
process.once("exit", release);
|
|
24732
|
-
return release;
|
|
24733
|
-
} catch (err) {
|
|
24734
|
-
if (err.code !== "EEXIST") throw err;
|
|
24735
|
-
const holder = readLockPid(path);
|
|
24736
|
-
if (holder === process.pid) return () => {
|
|
24737
|
-
};
|
|
24738
|
-
if (holder && isLiveFlyspace(holder)) {
|
|
24739
|
-
throw new Error(
|
|
24740
|
-
`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.`
|
|
24741
|
-
);
|
|
24742
|
-
}
|
|
24743
|
-
rmSync6(path, { force: true });
|
|
24744
|
-
}
|
|
24745
|
-
}
|
|
24746
|
-
throw new Error(`Could not take the Host lock at ${path}`);
|
|
24747
|
-
}
|
|
24748
|
-
function publishHostEndpoint(port) {
|
|
24749
|
-
const path = hostLockPath();
|
|
24750
|
-
if (readLockPid(path) !== process.pid) return null;
|
|
24751
|
-
const token = randomBytes3(32).toString("hex");
|
|
24752
|
-
const lock = JSON.parse(readFileSync8(path, "utf8"));
|
|
24753
|
-
writeFileSync5(path, JSON.stringify({ ...lock, port, token }), { mode: 384 });
|
|
24754
|
-
return token;
|
|
24755
|
-
}
|
|
24756
|
-
function readHostEndpoint() {
|
|
24757
|
-
try {
|
|
24758
|
-
const { pid, port, token } = JSON.parse(readFileSync8(hostLockPath(), "utf8"));
|
|
24759
|
-
if (pid === process.pid || !Number.isInteger(port) || typeof token !== "string") return null;
|
|
24760
|
-
return { port, token };
|
|
24761
|
-
} catch {
|
|
24762
|
-
return null;
|
|
24763
|
-
}
|
|
24764
|
-
}
|
|
24765
|
-
|
|
24766
|
-
// src/dashboard/host-db-client.ts
|
|
24767
|
-
var REQUEST_TIMEOUT_MS2 = 3e4;
|
|
24768
|
-
var pending = /* @__PURE__ */ new Map();
|
|
24769
|
-
var sender = null;
|
|
24770
|
-
var onSender = [];
|
|
24771
|
-
function setHostDbSender(fn) {
|
|
24772
|
-
sender = fn;
|
|
24773
|
-
if (!fn) return;
|
|
24774
|
-
const waiting = onSender;
|
|
24775
|
-
onSender = [];
|
|
24776
|
-
for (const wake of waiting) wake();
|
|
24777
|
-
}
|
|
24778
|
-
function sendAgentFailure(report) {
|
|
24779
|
-
sender?.({ type: "agent-failure", ...report });
|
|
24780
|
-
}
|
|
24781
|
-
function handleHostDbResult(id, res) {
|
|
24782
|
-
const p = pending.get(id);
|
|
24783
|
-
if (!p) return;
|
|
24784
|
-
pending.delete(id);
|
|
24785
|
-
clearTimeout(p.timer);
|
|
24786
|
-
p.resolve(res);
|
|
24787
|
-
}
|
|
24788
|
-
function whenConnected() {
|
|
24789
|
-
if (sender) return Promise.resolve(sender);
|
|
24790
|
-
return new Promise((resolve8, reject) => {
|
|
24791
|
-
const timer = setTimeout(() => {
|
|
24792
|
-
onSender = onSender.filter((w) => w !== wake);
|
|
24793
|
-
reject(new Error("Host is not connected to the Data API"));
|
|
24794
|
-
}, REQUEST_TIMEOUT_MS2);
|
|
24795
|
-
const wake = () => {
|
|
24796
|
-
clearTimeout(timer);
|
|
24797
|
-
resolve8(sender);
|
|
24798
|
-
};
|
|
24799
|
-
onSender.push(wake);
|
|
24800
|
-
});
|
|
24801
|
-
}
|
|
24802
|
-
async function requestHostDb(req) {
|
|
24803
|
-
const send = await whenConnected();
|
|
24804
|
-
const id = randomUUID2();
|
|
24805
|
-
return new Promise((resolve8, reject) => {
|
|
24806
|
-
const timer = setTimeout(() => {
|
|
24807
|
-
pending.delete(id);
|
|
24808
|
-
reject(new Error("Data API did not answer in time"));
|
|
24809
|
-
}, REQUEST_TIMEOUT_MS2);
|
|
24810
|
-
pending.set(id, { resolve: resolve8, reject, timer });
|
|
24811
|
-
send({ type: "db", id, req });
|
|
24812
|
-
});
|
|
24813
|
-
}
|
|
24814
|
-
var pendingUrls = /* @__PURE__ */ new Map();
|
|
24815
|
-
function handleAttachmentUrlResult(id, url) {
|
|
24816
|
-
pendingUrls.get(id)?.(url);
|
|
24817
|
-
pendingUrls.delete(id);
|
|
24818
|
-
}
|
|
24819
|
-
async function requestAttachmentUrl(key) {
|
|
24820
|
-
const send = await whenConnected();
|
|
24821
|
-
const id = randomUUID2();
|
|
24822
|
-
return new Promise((resolve8, reject) => {
|
|
24823
|
-
const timer = setTimeout(() => {
|
|
24824
|
-
pendingUrls.delete(id);
|
|
24825
|
-
reject(new Error("Data API did not answer in time"));
|
|
24826
|
-
}, REQUEST_TIMEOUT_MS2);
|
|
24827
|
-
pendingUrls.set(id, (url) => {
|
|
24828
|
-
clearTimeout(timer);
|
|
24829
|
-
resolve8(url);
|
|
24830
|
-
});
|
|
24831
|
-
send({ type: "attachment-url", id, key });
|
|
24832
|
-
});
|
|
24833
|
-
}
|
|
24834
|
-
var pendingRespond = /* @__PURE__ */ new Map();
|
|
24835
|
-
function handleShouldRespondResult(id, respond) {
|
|
24836
|
-
pendingRespond.get(id)?.(respond);
|
|
24837
|
-
pendingRespond.delete(id);
|
|
24838
|
-
}
|
|
24839
|
-
async function requestShouldRespond(transcript) {
|
|
24840
|
-
const send = await whenConnected().catch(() => null);
|
|
24841
|
-
if (!send) return false;
|
|
24842
|
-
const id = randomUUID2();
|
|
24843
|
-
return new Promise((resolve8) => {
|
|
24844
|
-
const timer = setTimeout(() => {
|
|
24845
|
-
pendingRespond.delete(id);
|
|
24846
|
-
resolve8(false);
|
|
24847
|
-
}, REQUEST_TIMEOUT_MS2);
|
|
24848
|
-
pendingRespond.set(id, (respond) => {
|
|
24849
|
-
clearTimeout(timer);
|
|
24850
|
-
resolve8(respond);
|
|
24851
|
-
});
|
|
24852
|
-
send({ type: "should-respond", id, transcript });
|
|
24853
|
-
});
|
|
24854
|
-
}
|
|
24855
|
-
var BODYLESS_STATUS = /* @__PURE__ */ new Set([101, 204, 205, 304]);
|
|
24856
|
-
function dbFetch(send) {
|
|
24857
|
-
return async (input, init) => {
|
|
24858
|
-
const req = new Request(input, init);
|
|
24859
|
-
const url = new URL(req.url);
|
|
24860
|
-
const method = req.method.toUpperCase();
|
|
24861
|
-
const res = await send({
|
|
24862
|
-
method,
|
|
24863
|
-
path: `${url.pathname}${url.search}`,
|
|
24864
|
-
headers: Object.fromEntries(req.headers.entries()),
|
|
24865
|
-
body: method === "GET" || method === "HEAD" ? void 0 : await req.text()
|
|
24866
|
-
});
|
|
24867
|
-
const noBody = method === "HEAD" || BODYLESS_STATUS.has(res.status);
|
|
24868
|
-
return new Response(noBody ? null : res.body, { status: res.status, headers: res.headers });
|
|
24869
|
-
};
|
|
24870
|
-
}
|
|
24871
|
-
var hostDbFetch = dbFetch(requestHostDb);
|
|
24872
|
-
var LOCAL_DB_PATH = "/internal/db";
|
|
24873
|
-
async function requestViaLocalHost(req) {
|
|
24874
|
-
const deadline = Date.now() + REQUEST_TIMEOUT_MS2;
|
|
24875
|
-
let endpoint = readHostEndpoint();
|
|
24876
|
-
while (!endpoint && Date.now() < deadline) {
|
|
24877
|
-
await new Promise((r) => setTimeout(r, 1e3));
|
|
24878
|
-
endpoint = readHostEndpoint();
|
|
24879
|
-
}
|
|
24880
|
-
if (!endpoint) throw new Error("No local Host to reach the Data API through");
|
|
24881
|
-
const res = await fetch(`http://127.0.0.1:${endpoint.port}${LOCAL_DB_PATH}`, {
|
|
24882
|
-
method: "POST",
|
|
24883
|
-
headers: { authorization: `Bearer ${endpoint.token}`, "content-type": "application/json" },
|
|
24884
|
-
body: JSON.stringify(req),
|
|
24885
|
-
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS2 + 5e3)
|
|
24886
|
-
});
|
|
24887
|
-
if (!res.ok) throw new Error(`Local Host DB relay answered ${res.status}`);
|
|
24888
|
-
return await res.json();
|
|
24889
|
-
}
|
|
24890
|
-
function relayChannel(topic) {
|
|
24891
|
-
const channel = {
|
|
24892
|
-
on: () => channel,
|
|
24893
|
-
subscribe: (callback) => {
|
|
24894
|
-
queueMicrotask(() => callback?.("SUBSCRIBED"));
|
|
24895
|
-
return channel;
|
|
24896
|
-
},
|
|
24897
|
-
send: async (msg) => {
|
|
24898
|
-
if (msg.type !== "broadcast" || !sender) return "error";
|
|
24899
|
-
sender({ type: "db-broadcast", topic, event: msg.event, payload: msg.payload ?? {} });
|
|
24900
|
-
return "ok";
|
|
24901
|
-
},
|
|
24902
|
-
unsubscribe: async () => "ok"
|
|
24903
|
-
};
|
|
24904
|
-
return channel;
|
|
24905
|
-
}
|
|
24906
|
-
function createHostDbClient(via = "socket") {
|
|
24907
|
-
const client = createClient("https://host-db.invalid", "host-device", {
|
|
24908
|
-
auth: { persistSession: false, autoRefreshToken: false },
|
|
24909
|
-
global: { fetch: via === "socket" ? hostDbFetch : dbFetch(requestViaLocalHost) }
|
|
24910
|
-
});
|
|
24911
|
-
return new Proxy(client, {
|
|
24912
|
-
get(target, prop) {
|
|
24913
|
-
if (prop === "channel") return relayChannel;
|
|
24914
|
-
if (prop === "removeChannel") return async () => "ok";
|
|
24915
|
-
const value = Reflect.get(target, prop, target);
|
|
24916
|
-
return typeof value === "function" ? value.bind(target) : value;
|
|
24917
|
-
}
|
|
24918
|
-
});
|
|
24919
|
-
}
|
|
24920
|
-
|
|
24921
25242
|
// src/claude/agents.ts
|
|
24922
|
-
import { existsSync as
|
|
24923
|
-
import { homedir as
|
|
24924
|
-
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";
|
|
24925
25246
|
import yaml3 from "js-yaml";
|
|
24926
25247
|
|
|
24927
25248
|
// ../api/src/claude/skills.ts
|
|
24928
|
-
import { existsSync as
|
|
24929
|
-
import { homedir as
|
|
24930
|
-
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";
|
|
24931
25252
|
import yaml2 from "js-yaml";
|
|
24932
25253
|
|
|
24933
25254
|
// ../api/src/claude/skill-files.ts
|
|
24934
25255
|
import {
|
|
24935
|
-
existsSync as
|
|
24936
|
-
mkdirSync as
|
|
24937
|
-
readFileSync as
|
|
24938
|
-
readdirSync as
|
|
24939
|
-
rmSync as
|
|
25256
|
+
existsSync as existsSync13,
|
|
25257
|
+
mkdirSync as mkdirSync9,
|
|
25258
|
+
readFileSync as readFileSync11,
|
|
25259
|
+
readdirSync as readdirSync3,
|
|
25260
|
+
rmSync as rmSync9,
|
|
24940
25261
|
statSync as statSync4,
|
|
24941
|
-
writeFileSync as
|
|
25262
|
+
writeFileSync as writeFileSync8
|
|
24942
25263
|
} from "fs";
|
|
24943
|
-
import { homedir as
|
|
24944
|
-
import { join as
|
|
25264
|
+
import { homedir as homedir4 } from "os";
|
|
25265
|
+
import { join as join13, resolve as resolve5, sep as sep2 } from "path";
|
|
24945
25266
|
import yaml from "js-yaml";
|
|
24946
25267
|
var MAX_SKILL_BYTES = 2 * 1024 * 1024;
|
|
24947
25268
|
var SKILL_NAME = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
|
|
24948
25269
|
function expandHome(p) {
|
|
24949
|
-
if (p === "~") return
|
|
24950
|
-
if (p.startsWith("~/")) return
|
|
25270
|
+
if (p === "~") return homedir4();
|
|
25271
|
+
if (p.startsWith("~/")) return join13(homedir4(), p.slice(2));
|
|
24951
25272
|
return p;
|
|
24952
25273
|
}
|
|
24953
25274
|
function workspaceSkillsDir(configDir) {
|
|
24954
|
-
return
|
|
25275
|
+
return join13(configDir ? expandHome(configDir) : join13(homedir4(), ".claude"), "skills");
|
|
24955
25276
|
}
|
|
24956
25277
|
function channelSkillsDir(cwd) {
|
|
24957
|
-
return
|
|
25278
|
+
return join13(cwd, ".claude", "skills");
|
|
24958
25279
|
}
|
|
24959
25280
|
function isValidSkillName(name) {
|
|
24960
25281
|
return SKILL_NAME.test(name);
|
|
@@ -24989,7 +25310,7 @@ ${body.replace(/^\n+/, "").trimEnd()}
|
|
|
24989
25310
|
}
|
|
24990
25311
|
function readMeta(abs) {
|
|
24991
25312
|
try {
|
|
24992
|
-
const { fm } = splitFrontmatter(
|
|
25313
|
+
const { fm } = splitFrontmatter(readFileSync11(abs, "utf-8"));
|
|
24993
25314
|
return {
|
|
24994
25315
|
name: typeof fm["name"] === "string" ? fm["name"] : void 0,
|
|
24995
25316
|
description: typeof fm["description"] === "string" ? fm["description"] : void 0
|
|
@@ -24999,17 +25320,17 @@ function readMeta(abs) {
|
|
|
24999
25320
|
}
|
|
25000
25321
|
}
|
|
25001
25322
|
function listSkillFiles(dir) {
|
|
25002
|
-
if (!
|
|
25323
|
+
if (!existsSync13(dir)) return [];
|
|
25003
25324
|
let entries2;
|
|
25004
25325
|
try {
|
|
25005
|
-
entries2 =
|
|
25326
|
+
entries2 = readdirSync3(dir);
|
|
25006
25327
|
} catch {
|
|
25007
25328
|
return [];
|
|
25008
25329
|
}
|
|
25009
25330
|
const rows2 = [];
|
|
25010
25331
|
for (const entry of entries2) {
|
|
25011
25332
|
if (!isValidSkillName(entry)) continue;
|
|
25012
|
-
const abs =
|
|
25333
|
+
const abs = join13(dir, entry, "SKILL.md");
|
|
25013
25334
|
let stat;
|
|
25014
25335
|
try {
|
|
25015
25336
|
stat = statSync4(abs);
|
|
@@ -25038,7 +25359,7 @@ function readSkillFile(dir, name) {
|
|
|
25038
25359
|
return null;
|
|
25039
25360
|
}
|
|
25040
25361
|
if (!stat.isFile() || stat.size > MAX_SKILL_BYTES) return null;
|
|
25041
|
-
const { fm, body } = splitFrontmatter(
|
|
25362
|
+
const { fm, body } = splitFrontmatter(readFileSync11(abs, "utf-8"));
|
|
25042
25363
|
return {
|
|
25043
25364
|
name,
|
|
25044
25365
|
description: typeof fm["description"] === "string" ? fm["description"].trim() : "",
|
|
@@ -25060,18 +25381,18 @@ function writeSkillFile(dir, name, patch, baseMtime) {
|
|
|
25060
25381
|
if (baseMtime && stat.mtime.toISOString() !== baseMtime) {
|
|
25061
25382
|
return { status: "conflict", mtime: stat.mtime.toISOString() };
|
|
25062
25383
|
}
|
|
25063
|
-
const { fm } = splitFrontmatter(
|
|
25384
|
+
const { fm } = splitFrontmatter(readFileSync11(abs, "utf-8"));
|
|
25064
25385
|
const content = buildSkillFile({ ...fm, name, description: patch.description }, patch.body);
|
|
25065
25386
|
if (Buffer.byteLength(content, "utf8") > MAX_SKILL_BYTES) return { status: "too-large" };
|
|
25066
|
-
|
|
25387
|
+
writeFileSync8(abs, content, "utf8");
|
|
25067
25388
|
return { status: "ok", mtime: statSync4(abs).mtime.toISOString() };
|
|
25068
25389
|
}
|
|
25069
25390
|
function createSkillFile(dir, name, description) {
|
|
25070
25391
|
const abs = resolveSkillPath(dir, name);
|
|
25071
25392
|
if (!abs) return { status: "bad-name" };
|
|
25072
|
-
if (
|
|
25073
|
-
|
|
25074
|
-
|
|
25393
|
+
if (existsSync13(abs)) return { status: "exists" };
|
|
25394
|
+
mkdirSync9(join13(dir, name), { recursive: true });
|
|
25395
|
+
writeFileSync8(
|
|
25075
25396
|
abs,
|
|
25076
25397
|
buildSkillFile(
|
|
25077
25398
|
{ name, description },
|
|
@@ -25087,24 +25408,24 @@ Describe what this skill does and when to use it.
|
|
|
25087
25408
|
}
|
|
25088
25409
|
function deleteSkillFile(dir, name) {
|
|
25089
25410
|
const abs = resolveSkillPath(dir, name);
|
|
25090
|
-
if (!abs || !
|
|
25091
|
-
|
|
25411
|
+
if (!abs || !existsSync13(abs)) return { status: "not-found" };
|
|
25412
|
+
rmSync9(join13(dir, name), { recursive: true, force: true });
|
|
25092
25413
|
return { status: "ok" };
|
|
25093
25414
|
}
|
|
25094
25415
|
|
|
25095
25416
|
// ../api/src/claude/skills.ts
|
|
25096
25417
|
function defaultConfigDir() {
|
|
25097
|
-
return
|
|
25418
|
+
return join14(homedir5(), ".claude");
|
|
25098
25419
|
}
|
|
25099
25420
|
function expandHome2(p) {
|
|
25100
|
-
if (p === "~") return
|
|
25101
|
-
if (p.startsWith("~/")) return
|
|
25421
|
+
if (p === "~") return homedir5();
|
|
25422
|
+
if (p.startsWith("~/")) return join14(homedir5(), p.slice(2));
|
|
25102
25423
|
return p;
|
|
25103
25424
|
}
|
|
25104
25425
|
function parseFrontmatter(file) {
|
|
25105
25426
|
let content;
|
|
25106
25427
|
try {
|
|
25107
|
-
content =
|
|
25428
|
+
content = readFileSync12(file, "utf-8");
|
|
25108
25429
|
} catch {
|
|
25109
25430
|
return {};
|
|
25110
25431
|
}
|
|
@@ -25122,39 +25443,39 @@ function parseFrontmatter(file) {
|
|
|
25122
25443
|
function isSymlinkedDir(root, entry) {
|
|
25123
25444
|
if (!entry.isSymbolicLink()) return false;
|
|
25124
25445
|
try {
|
|
25125
|
-
return statSync5(
|
|
25446
|
+
return statSync5(join14(root, entry.name)).isDirectory();
|
|
25126
25447
|
} catch {
|
|
25127
25448
|
return false;
|
|
25128
25449
|
}
|
|
25129
25450
|
}
|
|
25130
25451
|
function findSkillFiles(root, maxDepth, out) {
|
|
25131
|
-
if (maxDepth < 0 || !
|
|
25452
|
+
if (maxDepth < 0 || !existsSync14(root)) return;
|
|
25132
25453
|
let entries2;
|
|
25133
25454
|
try {
|
|
25134
|
-
entries2 =
|
|
25455
|
+
entries2 = readdirSync4(root, { withFileTypes: true });
|
|
25135
25456
|
} catch {
|
|
25136
25457
|
return;
|
|
25137
25458
|
}
|
|
25138
25459
|
for (const entry of entries2) {
|
|
25139
25460
|
if (entry.isFile()) {
|
|
25140
|
-
if (entry.name === "SKILL.md") out.push(
|
|
25461
|
+
if (entry.name === "SKILL.md") out.push(join14(root, entry.name));
|
|
25141
25462
|
} else if (entry.isDirectory() || isSymlinkedDir(root, entry)) {
|
|
25142
25463
|
if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
|
|
25143
|
-
findSkillFiles(
|
|
25464
|
+
findSkillFiles(join14(root, entry.name), maxDepth - 1, out);
|
|
25144
25465
|
}
|
|
25145
25466
|
}
|
|
25146
25467
|
}
|
|
25147
25468
|
function pluginNameFor(file, root) {
|
|
25148
|
-
let dir =
|
|
25149
|
-
while (dir.startsWith(root) && dir !==
|
|
25469
|
+
let dir = dirname3(file);
|
|
25470
|
+
while (dir.startsWith(root) && dir !== dirname3(dir)) {
|
|
25150
25471
|
try {
|
|
25151
25472
|
const manifest = JSON.parse(
|
|
25152
|
-
|
|
25473
|
+
readFileSync12(join14(dir, ".claude-plugin", "plugin.json"), "utf-8")
|
|
25153
25474
|
);
|
|
25154
25475
|
if (typeof manifest.name === "string" && manifest.name.trim()) return manifest.name.trim();
|
|
25155
25476
|
} catch {
|
|
25156
25477
|
}
|
|
25157
|
-
dir =
|
|
25478
|
+
dir = dirname3(dir);
|
|
25158
25479
|
}
|
|
25159
25480
|
return void 0;
|
|
25160
25481
|
}
|
|
@@ -25164,29 +25485,29 @@ function findPluginMarkdown(pluginsRoot, dirName, maxDepth = 8) {
|
|
|
25164
25485
|
if (depth < 0) return;
|
|
25165
25486
|
let entries2;
|
|
25166
25487
|
try {
|
|
25167
|
-
entries2 =
|
|
25488
|
+
entries2 = readdirSync4(dir, { withFileTypes: true });
|
|
25168
25489
|
} catch {
|
|
25169
25490
|
return;
|
|
25170
25491
|
}
|
|
25171
25492
|
for (const entry of entries2) {
|
|
25172
25493
|
if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
|
|
25173
25494
|
if (!entry.isDirectory() && !isSymlinkedDir(dir, entry)) continue;
|
|
25174
|
-
const child =
|
|
25495
|
+
const child = join14(dir, entry.name);
|
|
25175
25496
|
if (entry.name === dirName) {
|
|
25176
25497
|
for (const f of readdirSafe(child)) {
|
|
25177
|
-
if (f.endsWith(".md")) out.push({ file:
|
|
25498
|
+
if (f.endsWith(".md")) out.push({ file: join14(child, f), plugin: pluginNameFor(join14(child, f), pluginsRoot) });
|
|
25178
25499
|
}
|
|
25179
25500
|
} else {
|
|
25180
25501
|
walk(child, depth - 1);
|
|
25181
25502
|
}
|
|
25182
25503
|
}
|
|
25183
25504
|
};
|
|
25184
|
-
if (
|
|
25505
|
+
if (existsSync14(pluginsRoot)) walk(pluginsRoot, maxDepth);
|
|
25185
25506
|
return out;
|
|
25186
25507
|
}
|
|
25187
25508
|
function readdirSafe(dir) {
|
|
25188
25509
|
try {
|
|
25189
|
-
return
|
|
25510
|
+
return readdirSync4(dir);
|
|
25190
25511
|
} catch {
|
|
25191
25512
|
return [];
|
|
25192
25513
|
}
|
|
@@ -25194,16 +25515,16 @@ function readdirSafe(dir) {
|
|
|
25194
25515
|
function listCommands(configDir, cwd) {
|
|
25195
25516
|
const base = configDir ? expandHome2(configDir) : defaultConfigDir();
|
|
25196
25517
|
const local = (dir, source) => readdirSafe(dir).filter((f) => f.endsWith(".md")).map((f) => ({
|
|
25197
|
-
name:
|
|
25198
|
-
description: (parseFrontmatter(
|
|
25518
|
+
name: basename3(f, ".md"),
|
|
25519
|
+
description: (parseFrontmatter(join14(dir, f)).description ?? "").trim(),
|
|
25199
25520
|
source,
|
|
25200
25521
|
kind: "command"
|
|
25201
25522
|
}));
|
|
25202
25523
|
const collected = [
|
|
25203
|
-
...local(
|
|
25204
|
-
...local(
|
|
25205
|
-
...findPluginMarkdown(
|
|
25206
|
-
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"),
|
|
25207
25528
|
description: (parseFrontmatter(file).description ?? "").trim(),
|
|
25208
25529
|
source: "plugin",
|
|
25209
25530
|
...plugin && { plugin },
|
|
@@ -25224,7 +25545,7 @@ function collectFrom(root, source, maxDepth, namePrefix) {
|
|
|
25224
25545
|
findSkillFiles(root, maxDepth, files);
|
|
25225
25546
|
return files.map((file) => {
|
|
25226
25547
|
const fm = parseFrontmatter(file);
|
|
25227
|
-
const name = fm.name?.trim() ||
|
|
25548
|
+
const name = fm.name?.trim() || basename3(dirname3(file));
|
|
25228
25549
|
const plugin = source === "plugin" ? pluginNameFor(file, root) : void 0;
|
|
25229
25550
|
const prefix = namePrefix ?? plugin;
|
|
25230
25551
|
return {
|
|
@@ -25240,10 +25561,10 @@ function collectFrom(root, source, maxDepth, namePrefix) {
|
|
|
25240
25561
|
function collectAll(configDir, cwd) {
|
|
25241
25562
|
const base = configDir ? expandHome2(configDir) : defaultConfigDir();
|
|
25242
25563
|
const collected = [
|
|
25243
|
-
...collectFrom(
|
|
25564
|
+
...collectFrom(join14(cwd, ".claude", "skills"), "project", 2),
|
|
25244
25565
|
...nestedProjectRoots(cwd).flatMap(({ dir, prefix }) => collectFrom(dir, "project", 2, prefix)),
|
|
25245
|
-
...collectFrom(
|
|
25246
|
-
...collectFrom(
|
|
25566
|
+
...collectFrom(join14(base, "skills"), "user", 2),
|
|
25567
|
+
...collectFrom(join14(base, "plugins"), "plugin", 8)
|
|
25247
25568
|
];
|
|
25248
25569
|
const byName = /* @__PURE__ */ new Map();
|
|
25249
25570
|
for (const skill of collected) {
|
|
@@ -25254,7 +25575,7 @@ function collectAll(configDir, cwd) {
|
|
|
25254
25575
|
function nestedProjectRoots(cwd) {
|
|
25255
25576
|
let entries2;
|
|
25256
25577
|
try {
|
|
25257
|
-
entries2 =
|
|
25578
|
+
entries2 = readdirSync4(cwd, { withFileTypes: true });
|
|
25258
25579
|
} catch {
|
|
25259
25580
|
return [];
|
|
25260
25581
|
}
|
|
@@ -25262,8 +25583,8 @@ function nestedProjectRoots(cwd) {
|
|
|
25262
25583
|
for (const entry of entries2) {
|
|
25263
25584
|
if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
|
|
25264
25585
|
if (!entry.isDirectory() && !isSymlinkedDir(cwd, entry)) continue;
|
|
25265
|
-
const skillsDir =
|
|
25266
|
-
if (
|
|
25586
|
+
const skillsDir = join14(cwd, entry.name, ".claude", "skills");
|
|
25587
|
+
if (existsSync14(skillsDir)) roots.push({ dir: skillsDir, prefix: entry.name });
|
|
25267
25588
|
}
|
|
25268
25589
|
return roots;
|
|
25269
25590
|
}
|
|
@@ -25275,7 +25596,7 @@ function listPluginSkillDetails(configDir, cwd) {
|
|
|
25275
25596
|
for (const { file, ...skill } of collectAll(configDir, cwd)) {
|
|
25276
25597
|
if (skill.source !== "plugin") continue;
|
|
25277
25598
|
try {
|
|
25278
|
-
const { body } = splitFrontmatter(
|
|
25599
|
+
const { body } = splitFrontmatter(readFileSync12(file, "utf-8"));
|
|
25279
25600
|
details.push({ ...skill, body, path: file, mtime: statSync5(file).mtime.toISOString() });
|
|
25280
25601
|
} catch {
|
|
25281
25602
|
}
|
|
@@ -25285,15 +25606,15 @@ function listPluginSkillDetails(configDir, cwd) {
|
|
|
25285
25606
|
function findSkillDetail(configDir, cwd, name, sources) {
|
|
25286
25607
|
const base = configDir ? expandHome2(configDir) : defaultConfigDir();
|
|
25287
25608
|
const roots = [
|
|
25288
|
-
[
|
|
25609
|
+
[join14(cwd, ".claude", "skills"), "project", 2],
|
|
25289
25610
|
...nestedProjectRoots(cwd).map(({ dir, prefix }) => [
|
|
25290
25611
|
dir,
|
|
25291
25612
|
"project",
|
|
25292
25613
|
2,
|
|
25293
25614
|
prefix
|
|
25294
25615
|
]),
|
|
25295
|
-
[
|
|
25296
|
-
[
|
|
25616
|
+
[join14(base, "skills"), "user", 2],
|
|
25617
|
+
[join14(base, "plugins"), "plugin", 8]
|
|
25297
25618
|
];
|
|
25298
25619
|
for (const [root, source, maxDepth, namePrefix] of roots) {
|
|
25299
25620
|
if (!sources.includes(source)) continue;
|
|
@@ -25301,7 +25622,7 @@ function findSkillDetail(configDir, cwd, name, sources) {
|
|
|
25301
25622
|
findSkillFiles(root, maxDepth, files);
|
|
25302
25623
|
for (const file of files) {
|
|
25303
25624
|
const fm = parseFrontmatter(file);
|
|
25304
|
-
const rawName = fm.name?.trim() ||
|
|
25625
|
+
const rawName = fm.name?.trim() || basename3(dirname3(file));
|
|
25305
25626
|
const plugin = source === "plugin" ? pluginNameFor(file, root) : void 0;
|
|
25306
25627
|
const prefix = namePrefix ?? plugin;
|
|
25307
25628
|
const skillName = prefix ? `${prefix}:${rawName}` : rawName;
|
|
@@ -25309,7 +25630,7 @@ function findSkillDetail(configDir, cwd, name, sources) {
|
|
|
25309
25630
|
let raw;
|
|
25310
25631
|
let mtime;
|
|
25311
25632
|
try {
|
|
25312
|
-
raw =
|
|
25633
|
+
raw = readFileSync12(file, "utf-8");
|
|
25313
25634
|
mtime = statSync5(file).mtime.toISOString();
|
|
25314
25635
|
} catch {
|
|
25315
25636
|
continue;
|
|
@@ -25337,24 +25658,24 @@ function expandSkillCommand(configDir, cwd, text) {
|
|
|
25337
25658
|
const body = skill.body.includes("$ARGUMENTS") ? skill.body.replaceAll("$ARGUMENTS", args) : skill.body + (args ? `
|
|
25338
25659
|
|
|
25339
25660
|
ARGUMENTS: ${args}` : "");
|
|
25340
|
-
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)}]
|
|
25341
25662
|
|
|
25342
25663
|
${body.trim()}`;
|
|
25343
25664
|
}
|
|
25344
25665
|
|
|
25345
25666
|
// src/claude/agents.ts
|
|
25346
25667
|
function defaultConfigDir2() {
|
|
25347
|
-
return
|
|
25668
|
+
return join15(homedir6(), ".claude");
|
|
25348
25669
|
}
|
|
25349
25670
|
function expandHome3(p) {
|
|
25350
|
-
if (p === "~") return
|
|
25351
|
-
if (p.startsWith("~/")) return
|
|
25671
|
+
if (p === "~") return homedir6();
|
|
25672
|
+
if (p.startsWith("~/")) return join15(homedir6(), p.slice(2));
|
|
25352
25673
|
return p;
|
|
25353
25674
|
}
|
|
25354
25675
|
function parseFrontmatter2(file) {
|
|
25355
25676
|
let content;
|
|
25356
25677
|
try {
|
|
25357
|
-
content =
|
|
25678
|
+
content = readFileSync13(file, "utf-8");
|
|
25358
25679
|
} catch {
|
|
25359
25680
|
return {};
|
|
25360
25681
|
}
|
|
@@ -25370,29 +25691,29 @@ function parseFrontmatter2(file) {
|
|
|
25370
25691
|
}
|
|
25371
25692
|
}
|
|
25372
25693
|
function collectFrom2(root, source) {
|
|
25373
|
-
if (!
|
|
25694
|
+
if (!existsSync15(root)) return [];
|
|
25374
25695
|
let entries2;
|
|
25375
25696
|
try {
|
|
25376
|
-
entries2 =
|
|
25697
|
+
entries2 = readdirSync5(root).filter((f) => f.endsWith(".md"));
|
|
25377
25698
|
} catch {
|
|
25378
25699
|
return [];
|
|
25379
25700
|
}
|
|
25380
25701
|
return entries2.map((file) => {
|
|
25381
|
-
const path =
|
|
25702
|
+
const path = join15(root, file);
|
|
25382
25703
|
const fm = parseFrontmatter2(path);
|
|
25383
|
-
const name = fm.name?.trim() ||
|
|
25704
|
+
const name = fm.name?.trim() || basename4(file, ".md");
|
|
25384
25705
|
return { name, description: (fm.description ?? "").trim(), source, path };
|
|
25385
25706
|
});
|
|
25386
25707
|
}
|
|
25387
25708
|
function listAgents(configDir, cwd) {
|
|
25388
25709
|
const base = configDir ? expandHome3(configDir) : defaultConfigDir2();
|
|
25389
25710
|
const collected = [
|
|
25390
|
-
...collectFrom2(
|
|
25391
|
-
...collectFrom2(
|
|
25711
|
+
...collectFrom2(join15(cwd, ".claude", "agents"), "project"),
|
|
25712
|
+
...collectFrom2(join15(base, "agents"), "user"),
|
|
25392
25713
|
// Plugin agents, namespaced `plugin:agent` the way the CLI lists them.
|
|
25393
|
-
...findPluginMarkdown(
|
|
25714
|
+
...findPluginMarkdown(join15(base, "plugins"), "agents").map(({ file, plugin }) => {
|
|
25394
25715
|
const fm = parseFrontmatter2(file);
|
|
25395
|
-
const name = fm.name?.trim() ||
|
|
25716
|
+
const name = fm.name?.trim() || basename4(file, ".md");
|
|
25396
25717
|
return {
|
|
25397
25718
|
name: plugin ? `${plugin}:${name}` : name,
|
|
25398
25719
|
description: (fm.description ?? "").trim(),
|
|
@@ -25411,7 +25732,7 @@ function readAgentPersona(configDir, cwd, name) {
|
|
|
25411
25732
|
const agent = listAgents(configDir, cwd).find((a) => a.name === name);
|
|
25412
25733
|
if (!agent) return void 0;
|
|
25413
25734
|
try {
|
|
25414
|
-
const content =
|
|
25735
|
+
const content = readFileSync13(agent.path, "utf-8");
|
|
25415
25736
|
return content.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/, "").trim();
|
|
25416
25737
|
} catch {
|
|
25417
25738
|
return void 0;
|
|
@@ -25420,13 +25741,13 @@ function readAgentPersona(configDir, cwd, name) {
|
|
|
25420
25741
|
|
|
25421
25742
|
// src/dashboard/memory-extraction-runner.ts
|
|
25422
25743
|
import { spawn as spawn4 } from "child_process";
|
|
25423
|
-
import { existsSync as
|
|
25744
|
+
import { existsSync as existsSync16, mkdtempSync as mkdtempSync5, readFileSync as readFileSync14, rmSync as rmSync10 } from "fs";
|
|
25424
25745
|
import { tmpdir as tmpdir4 } from "os";
|
|
25425
|
-
import { join as
|
|
25746
|
+
import { join as join17 } from "path";
|
|
25426
25747
|
|
|
25427
25748
|
// ../api/src/dashboard/profile-config.ts
|
|
25428
|
-
import { homedir as
|
|
25429
|
-
import { join as
|
|
25749
|
+
import { homedir as homedir7 } from "os";
|
|
25750
|
+
import { join as join16, parse, resolve as resolve6 } from "path";
|
|
25430
25751
|
|
|
25431
25752
|
// ../api/src/dashboard/profile-config-cache.ts
|
|
25432
25753
|
var cache3 = /* @__PURE__ */ new Map();
|
|
@@ -25445,7 +25766,7 @@ function profileEnv(key) {
|
|
|
25445
25766
|
function profileClaudeConfigDir() {
|
|
25446
25767
|
const config = cachedProfileConfig();
|
|
25447
25768
|
if (!config) return process.env["CLAUDE_CONFIG_DIR"] || void 0;
|
|
25448
|
-
return config.env["CLAUDE_CONFIG_DIR"]?.trim() ||
|
|
25769
|
+
return config.env["CLAUDE_CONFIG_DIR"]?.trim() || join16(homedir7(), ".claude");
|
|
25449
25770
|
}
|
|
25450
25771
|
function profileOauthToken() {
|
|
25451
25772
|
const env = cachedProfileConfig()?.env ?? {};
|
|
@@ -25455,7 +25776,7 @@ function profileOauthToken() {
|
|
|
25455
25776
|
}
|
|
25456
25777
|
function isUnsafeCwd(cwd) {
|
|
25457
25778
|
const p = resolve6(cwd);
|
|
25458
|
-
return p === parse(p).root || p === resolve6(
|
|
25779
|
+
return p === parse(p).root || p === resolve6(homedir7());
|
|
25459
25780
|
}
|
|
25460
25781
|
function defaultClaudeCwd() {
|
|
25461
25782
|
return profileEnv("CLAUDE_CWD") ?? process.cwd();
|
|
@@ -25506,7 +25827,7 @@ var SUGGEST_TOOLS = "Read,Glob,Grep";
|
|
|
25506
25827
|
function buildInvocation(runner, req, dir, auth, baseEnv = process.env, tools = "") {
|
|
25507
25828
|
const env = { ...baseEnv, CLAUDE_CODE_DISABLE_AUTO_MEMORY: "1" };
|
|
25508
25829
|
if (runner === "codex") {
|
|
25509
|
-
const outputFile =
|
|
25830
|
+
const outputFile = join17(dir, "last-message.txt");
|
|
25510
25831
|
return {
|
|
25511
25832
|
command: "codex",
|
|
25512
25833
|
args: [
|
|
@@ -25562,7 +25883,7 @@ ${req.user}`,
|
|
|
25562
25883
|
}
|
|
25563
25884
|
function run(inv, cwd) {
|
|
25564
25885
|
return new Promise((resolve8) => {
|
|
25565
|
-
if (!
|
|
25886
|
+
if (!existsSync16(cwd)) {
|
|
25566
25887
|
resolve8({ ok: false, error: `the channel folder ${cwd} does not exist on this Host` });
|
|
25567
25888
|
return;
|
|
25568
25889
|
}
|
|
@@ -25595,7 +25916,7 @@ function run(inv, cwd) {
|
|
|
25595
25916
|
let raw = stdout;
|
|
25596
25917
|
if (inv.outputFile) {
|
|
25597
25918
|
try {
|
|
25598
|
-
raw =
|
|
25919
|
+
raw = readFileSync14(inv.outputFile, "utf-8");
|
|
25599
25920
|
} catch {
|
|
25600
25921
|
raw = "";
|
|
25601
25922
|
}
|
|
@@ -25608,7 +25929,7 @@ function run(inv, cwd) {
|
|
|
25608
25929
|
async function complete(req, tools = "", cwd) {
|
|
25609
25930
|
const runner = runnerForModel(loadDashboardSettings().agent);
|
|
25610
25931
|
const config = resolveChannelConfig(req.channelId);
|
|
25611
|
-
const dir =
|
|
25932
|
+
const dir = mkdtempSync5(join17(tmpdir4(), "flyspace-memory-"));
|
|
25612
25933
|
try {
|
|
25613
25934
|
const inv = buildInvocation(
|
|
25614
25935
|
runner,
|
|
@@ -25623,7 +25944,7 @@ async function complete(req, tools = "", cwd) {
|
|
|
25623
25944
|
);
|
|
25624
25945
|
return await run(inv, cwd ?? dir);
|
|
25625
25946
|
} finally {
|
|
25626
|
-
|
|
25947
|
+
rmSync10(dir, { recursive: true, force: true });
|
|
25627
25948
|
}
|
|
25628
25949
|
}
|
|
25629
25950
|
function completeMemoryExtraction(req) {
|
|
@@ -26323,9 +26644,9 @@ var UsageStore = class {
|
|
|
26323
26644
|
|
|
26324
26645
|
// src/dashboard/rollover-summary.ts
|
|
26325
26646
|
import { spawn as spawn5 } from "child_process";
|
|
26326
|
-
import { existsSync as
|
|
26647
|
+
import { existsSync as existsSync17, mkdtempSync as mkdtempSync6, readFileSync as readFileSync15, rmSync as rmSync11 } from "fs";
|
|
26327
26648
|
import { tmpdir as tmpdir5 } from "os";
|
|
26328
|
-
import { join as
|
|
26649
|
+
import { join as join18 } from "path";
|
|
26329
26650
|
var HAIKU_MODEL = "haiku";
|
|
26330
26651
|
var CJK_PATTERN = /[ -〿-ヿ㐀-䶿一-鿿豈--]/;
|
|
26331
26652
|
function estimateTokens(text) {
|
|
@@ -26388,8 +26709,8 @@ function runSummaryPrint(input, options) {
|
|
|
26388
26709
|
return runPrint("claude", args, env).then((out) => out.trim());
|
|
26389
26710
|
}
|
|
26390
26711
|
async function runCodexSummary(input) {
|
|
26391
|
-
const dir =
|
|
26392
|
-
const lastMessageFile =
|
|
26712
|
+
const dir = mkdtempSync6(join18(tmpdir5(), "rollover-"));
|
|
26713
|
+
const lastMessageFile = join18(dir, "last-message.txt");
|
|
26393
26714
|
try {
|
|
26394
26715
|
await runPrint(
|
|
26395
26716
|
"codex",
|
|
@@ -26412,9 +26733,9 @@ ${input}`
|
|
|
26412
26733
|
],
|
|
26413
26734
|
{ ...process.env }
|
|
26414
26735
|
);
|
|
26415
|
-
return
|
|
26736
|
+
return existsSync17(lastMessageFile) ? readFileSync15(lastMessageFile, "utf8").trim() : "";
|
|
26416
26737
|
} finally {
|
|
26417
|
-
|
|
26738
|
+
rmSync11(dir, { recursive: true, force: true });
|
|
26418
26739
|
}
|
|
26419
26740
|
}
|
|
26420
26741
|
function runPrint(command, args, env) {
|
|
@@ -26654,7 +26975,7 @@ async function scanBackgroundTasks() {
|
|
|
26654
26975
|
|
|
26655
26976
|
// src/dashboard/attachment-downloader.ts
|
|
26656
26977
|
import { writeFile as writeFile2 } from "fs/promises";
|
|
26657
|
-
import { join as
|
|
26978
|
+
import { join as join19 } from "path";
|
|
26658
26979
|
import { GetObjectCommand } from "@aws-sdk/client-s3";
|
|
26659
26980
|
var debug4 = process.env["DEBUG"] === "true";
|
|
26660
26981
|
var ATTACHMENT_LINK = /\]\((?:https:\/\/[a-z0-9-]+\.flyspace\.ai)?\/api\/attachments\/([^)?\s]+)(?:\?[^)\s]*)?\)/g;
|
|
@@ -26721,7 +27042,7 @@ async function downloadOne2(key) {
|
|
|
26721
27042
|
if (bytes.length > sizeLimit) {
|
|
26722
27043
|
return { kind: "skip", skipped: { name, mimetype, reason: "too_large" } };
|
|
26723
27044
|
}
|
|
26724
|
-
const localPath =
|
|
27045
|
+
const localPath = join19(paths.UPLOADS_DIR, lastSegment);
|
|
26725
27046
|
await writeFile2(localPath, bytes);
|
|
26726
27047
|
if (debug4)
|
|
26727
27048
|
console.log(`[attachment-downloader] saved ${key} -> ${localPath} (${bytes.length} bytes)`);
|
|
@@ -26746,27 +27067,27 @@ async function downloadChatAttachments(body) {
|
|
|
26746
27067
|
}
|
|
26747
27068
|
|
|
26748
27069
|
// src/dashboard/doc-mention-guard.ts
|
|
26749
|
-
import { existsSync as
|
|
27070
|
+
import { existsSync as existsSync22, statSync as statSync8 } from "fs";
|
|
26750
27071
|
|
|
26751
27072
|
// src/dashboard/docs-routes.ts
|
|
26752
27073
|
import {
|
|
26753
27074
|
closeSync,
|
|
26754
27075
|
createReadStream,
|
|
26755
|
-
existsSync as
|
|
27076
|
+
existsSync as existsSync21,
|
|
26756
27077
|
lstatSync as lstatSync2,
|
|
26757
|
-
mkdirSync as
|
|
27078
|
+
mkdirSync as mkdirSync10,
|
|
26758
27079
|
openSync,
|
|
26759
27080
|
readSync,
|
|
26760
|
-
readdirSync as
|
|
26761
|
-
readFileSync as
|
|
27081
|
+
readdirSync as readdirSync6,
|
|
27082
|
+
readFileSync as readFileSync19,
|
|
26762
27083
|
realpathSync,
|
|
26763
|
-
renameSync as
|
|
26764
|
-
rmSync as
|
|
27084
|
+
renameSync as renameSync3,
|
|
27085
|
+
rmSync as rmSync12,
|
|
26765
27086
|
statSync as statSync7,
|
|
26766
|
-
writeFileSync as
|
|
27087
|
+
writeFileSync as writeFileSync9
|
|
26767
27088
|
} from "fs";
|
|
26768
27089
|
import { Readable } from "stream";
|
|
26769
|
-
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";
|
|
26770
27091
|
import { Hono as Hono4 } from "hono";
|
|
26771
27092
|
import { streamSSE } from "hono/streaming";
|
|
26772
27093
|
|
|
@@ -26878,8 +27199,8 @@ var requireDocsAccess = async (c, next) => {
|
|
|
26878
27199
|
};
|
|
26879
27200
|
|
|
26880
27201
|
// src/dashboard/docs-watcher.ts
|
|
26881
|
-
import { existsSync as
|
|
26882
|
-
import { basename as
|
|
27202
|
+
import { existsSync as existsSync18, watch } from "fs";
|
|
27203
|
+
import { basename as basename5, join as join20 } from "path";
|
|
26883
27204
|
var DEBOUNCE_MS = 200;
|
|
26884
27205
|
var MAX_PENDING = 200;
|
|
26885
27206
|
var IGNORED_SEGMENTS = /* @__PURE__ */ new Set([
|
|
@@ -26915,12 +27236,12 @@ function flush(cwd) {
|
|
|
26915
27236
|
function watchDocs(cwd, listener) {
|
|
26916
27237
|
let entry = entries.get(cwd);
|
|
26917
27238
|
if (!entry) {
|
|
26918
|
-
const root =
|
|
27239
|
+
const root = basename5(cwd);
|
|
26919
27240
|
const watcher = watch(cwd, { recursive: true, persistent: false }, (_event, filename) => {
|
|
26920
27241
|
const current = entries.get(cwd);
|
|
26921
27242
|
if (!current || filename === null) return;
|
|
26922
27243
|
const rel = filename.split("\\").join("/");
|
|
26923
|
-
if (rel === root && !
|
|
27244
|
+
if (rel === root && !existsSync18(join20(cwd, rel))) return;
|
|
26924
27245
|
if (isIgnoredDocPath(rel)) return;
|
|
26925
27246
|
if (current.pending.size < MAX_PENDING) current.pending.add(rel);
|
|
26926
27247
|
if (current.timer === null) current.timer = setTimeout(() => flush(cwd), DEBOUNCE_MS);
|
|
@@ -26974,7 +27295,7 @@ async function putDocTranslation(input) {
|
|
|
26974
27295
|
}
|
|
26975
27296
|
|
|
26976
27297
|
// ../api/src/dashboard/share-translate.ts
|
|
26977
|
-
import { createHash as
|
|
27298
|
+
import { createHash as createHash5 } from "crypto";
|
|
26978
27299
|
|
|
26979
27300
|
// ../api/src/store/doc-share-store.ts
|
|
26980
27301
|
function rowToKind(value) {
|
|
@@ -27284,7 +27605,7 @@ function languageName(lang) {
|
|
|
27284
27605
|
return BY_CODE.get(lang)?.name ?? null;
|
|
27285
27606
|
}
|
|
27286
27607
|
function translationHash(title, content) {
|
|
27287
|
-
return
|
|
27608
|
+
return createHash5("sha256").update(`${RECIPE_VERSION}
|
|
27288
27609
|
${title}
|
|
27289
27610
|
${content}`).digest("hex");
|
|
27290
27611
|
}
|
|
@@ -27519,7 +27840,7 @@ async function clearStaleDocAudios(channelId, sourcePath, lang, exceptHash) {
|
|
|
27519
27840
|
}
|
|
27520
27841
|
|
|
27521
27842
|
// ../api/src/dashboard/share-audio.ts
|
|
27522
|
-
import { createHash as
|
|
27843
|
+
import { createHash as createHash6 } from "crypto";
|
|
27523
27844
|
import { DeleteObjectCommand, PutObjectCommand as PutObjectCommand2 } from "@aws-sdk/client-s3";
|
|
27524
27845
|
|
|
27525
27846
|
// ../api/src/dashboard/tts-routes.ts
|
|
@@ -27718,7 +28039,7 @@ Pacing \u2014 the engine has NO pause control, so rhythm has to be built into th
|
|
|
27718
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.`;
|
|
27719
28040
|
}
|
|
27720
28041
|
function articleAudioHash(title, content) {
|
|
27721
|
-
return
|
|
28042
|
+
return createHash6("sha256").update(`v${RECIPE_VERSION2}
|
|
27722
28043
|
${title}
|
|
27723
28044
|
|
|
27724
28045
|
${content}`).digest("hex").slice(0, 32);
|
|
@@ -27945,7 +28266,7 @@ function queueShareAudio(share) {
|
|
|
27945
28266
|
var PENDING_STALE_MS = 30 * 60 * 1e3;
|
|
27946
28267
|
var FAILED_RETRY_MS = 10 * 60 * 1e3;
|
|
27947
28268
|
function langAudioHash(title, content, lang) {
|
|
27948
|
-
return
|
|
28269
|
+
return createHash6("sha256").update(`v${RECIPE_VERSION2}
|
|
27949
28270
|
${lang}
|
|
27950
28271
|
${translationHash(title, content)}`).digest("hex").slice(0, 32);
|
|
27951
28272
|
}
|
|
@@ -28232,8 +28553,8 @@ function createFeatureFlagsRouter() {
|
|
|
28232
28553
|
}
|
|
28233
28554
|
|
|
28234
28555
|
// ../api/src/dashboard/public-share-routes.ts
|
|
28235
|
-
import { existsSync as
|
|
28236
|
-
import { join as
|
|
28556
|
+
import { existsSync as existsSync20, readFileSync as readFileSync17, statSync as statSync6 } from "fs";
|
|
28557
|
+
import { join as join22 } from "path";
|
|
28237
28558
|
import { Hono as Hono3 } from "hono";
|
|
28238
28559
|
import { GetObjectCommand as GetObjectCommand3 } from "@aws-sdk/client-s3";
|
|
28239
28560
|
import { getSignedUrl as getSignedUrl2 } from "@aws-sdk/s3-request-presigner";
|
|
@@ -28439,14 +28760,14 @@ function injectShareHead(html, head) {
|
|
|
28439
28760
|
}
|
|
28440
28761
|
|
|
28441
28762
|
// ../api/src/dashboard/app-icon.ts
|
|
28442
|
-
import { createHash as
|
|
28443
|
-
import { existsSync as
|
|
28444
|
-
import { join as
|
|
28445
|
-
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";
|
|
28446
28767
|
var PLATE = "#0A0A0F";
|
|
28447
|
-
var BRAND_DIR =
|
|
28448
|
-
var MARK_FILE =
|
|
28449
|
-
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");
|
|
28450
28771
|
var LAYOUT = {
|
|
28451
28772
|
standard: { logo: 0.7, logoCx: 0.5, logoCy: 0.48, badge: 0.27, badgeCx: 0.22, badgeCy: 0.76 },
|
|
28452
28773
|
maskable: { logo: 0.56, logoCx: 0.5, logoCy: 0.48, badge: 0.23, badgeCx: 0.33, badgeCy: 0.66 }
|
|
@@ -28469,11 +28790,11 @@ function roundedPlate(size, fill = PLATE) {
|
|
|
28469
28790
|
}
|
|
28470
28791
|
async function renderBadge(box) {
|
|
28471
28792
|
const transparent = { r: 0, g: 0, b: 0, alpha: 0 };
|
|
28472
|
-
const raster = await
|
|
28473
|
-
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();
|
|
28474
28795
|
}
|
|
28475
28796
|
async function sampleBackground(logo) {
|
|
28476
|
-
const { data, info } = await
|
|
28797
|
+
const { data, info } = await sharp3(logo).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
|
28477
28798
|
const { width: w, height: h, channels } = info;
|
|
28478
28799
|
const edge = 1;
|
|
28479
28800
|
const samples = [
|
|
@@ -28518,13 +28839,13 @@ async function renderAppIcon({
|
|
|
28518
28839
|
size,
|
|
28519
28840
|
maskable ? "maskable" : "std",
|
|
28520
28841
|
plain ? "plain" : "badged",
|
|
28521
|
-
logo ?
|
|
28842
|
+
logo ? createHash7("sha1").update(logo).digest("hex").slice(0, 12) : transparent ? "stock-transparent" : "stock"
|
|
28522
28843
|
].join(":");
|
|
28523
28844
|
const hit = cache4.get(key);
|
|
28524
28845
|
if (hit) return hit;
|
|
28525
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,
|
|
28526
28847
|
// either on its usual dark plate or, for a favicon, trimmed and bare.
|
|
28527
|
-
(transparent ? await renderBadge(size) : await
|
|
28848
|
+
(transparent ? await renderBadge(size) : await sharp3(readFileSync16(MARK_FILE)).resize(size, size, { fit: "cover" }).png().toBuffer());
|
|
28528
28849
|
cache4.set(key, out);
|
|
28529
28850
|
return out;
|
|
28530
28851
|
}
|
|
@@ -28533,8 +28854,8 @@ async function composeIcon(logo, size, maskable, plain) {
|
|
|
28533
28854
|
const plate = await sampleBackground(logo) ?? PLATE;
|
|
28534
28855
|
const logoBox = Math.round(size * (plain ? PLAIN_LOGO : layout.logo));
|
|
28535
28856
|
const badgeBox = Math.round(size * layout.badge);
|
|
28536
|
-
const logoLayer = await
|
|
28537
|
-
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([
|
|
28538
28859
|
// Badge-less, the logo has the canvas to itself and sits dead centre;
|
|
28539
28860
|
// otherwise it's nudged up to leave the badge its corner.
|
|
28540
28861
|
{ input: logoLayer, ...place(size, logoBox, layout.logoCx, plain ? 0.5 : layout.logoCy) },
|
|
@@ -28545,12 +28866,12 @@ async function composeIcon(logo, size, maskable, plain) {
|
|
|
28545
28866
|
}
|
|
28546
28867
|
]
|
|
28547
28868
|
]).png().toBuffer();
|
|
28548
|
-
return
|
|
28869
|
+
return sharp3(composed).composite([{ input: roundedPlate(size), blend: "dest-in" }]).png().toBuffer();
|
|
28549
28870
|
}
|
|
28550
28871
|
|
|
28551
28872
|
// ../api/src/dashboard/share-og.ts
|
|
28552
|
-
import { createHash as
|
|
28553
|
-
import
|
|
28873
|
+
import { createHash as createHash8 } from "crypto";
|
|
28874
|
+
import sharp4 from "sharp";
|
|
28554
28875
|
var WIDTH = 1200;
|
|
28555
28876
|
var HEIGHT = 630;
|
|
28556
28877
|
var PAD = 80;
|
|
@@ -28683,7 +29004,7 @@ function roundedMask(size, radius) {
|
|
|
28683
29004
|
async function renderLogoChip(logo) {
|
|
28684
29005
|
if (!logo) return null;
|
|
28685
29006
|
try {
|
|
28686
|
-
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();
|
|
28687
29008
|
} catch {
|
|
28688
29009
|
return null;
|
|
28689
29010
|
}
|
|
@@ -28727,14 +29048,14 @@ function cacheKey(input) {
|
|
|
28727
29048
|
input.logo ?? "",
|
|
28728
29049
|
input.theme ?? ""
|
|
28729
29050
|
];
|
|
28730
|
-
return
|
|
29051
|
+
return createHash8("sha1").update(parts.join("\0")).digest("hex");
|
|
28731
29052
|
}
|
|
28732
29053
|
async function renderShareOgImage(input) {
|
|
28733
29054
|
const key = cacheKey(input);
|
|
28734
29055
|
const hit = cache5.get(key);
|
|
28735
29056
|
if (hit) return hit;
|
|
28736
29057
|
const chip = input.workspaceName?.trim() ? await renderLogoChip(decodeLogo(input.logo)) : null;
|
|
28737
|
-
const composed =
|
|
29058
|
+
const composed = sharp4(backdrop(input, !!chip));
|
|
28738
29059
|
const out = await (chip ? composed.composite([{ input: chip, left: PAD, top: LOGO_TOP }]) : composed).png({ compressionLevel: 9 }).toBuffer();
|
|
28739
29060
|
if (cache5.size >= CACHE_MAX) cache5.delete(cache5.keys().next().value);
|
|
28740
29061
|
cache5.set(key, out);
|
|
@@ -28742,7 +29063,7 @@ async function renderShareOgImage(input) {
|
|
|
28742
29063
|
}
|
|
28743
29064
|
|
|
28744
29065
|
// ../api/src/dashboard/share-ask.ts
|
|
28745
|
-
import { createHash as
|
|
29066
|
+
import { createHash as createHash9 } from "crypto";
|
|
28746
29067
|
var MAX_ARTICLE_CHARS3 = 24e3;
|
|
28747
29068
|
var MAX_QUESTION_CHARS = 500;
|
|
28748
29069
|
var SUGGESTION_COUNT = 4;
|
|
@@ -28807,7 +29128,7 @@ function parseSuggestions(raw) {
|
|
|
28807
29128
|
var CACHE_LIMIT = 200;
|
|
28808
29129
|
var suggestionCache = /* @__PURE__ */ new Map();
|
|
28809
29130
|
function articleHash(title, content, lang) {
|
|
28810
|
-
return
|
|
29131
|
+
return createHash9("sha256").update(`${lang ?? ""}
|
|
28811
29132
|
${title}
|
|
28812
29133
|
|
|
28813
29134
|
${content}`).digest("hex").slice(0, 32);
|
|
@@ -29063,7 +29384,7 @@ var shellCache = null;
|
|
|
29063
29384
|
function readShell(path) {
|
|
29064
29385
|
const { mtimeMs } = statSync6(path);
|
|
29065
29386
|
if (shellCache?.mtimeMs === mtimeMs) return shellCache.html;
|
|
29066
|
-
const html =
|
|
29387
|
+
const html = readFileSync17(path, "utf8").replaceAll('"/assets/', `"${BUILD_PREFIX}/`);
|
|
29067
29388
|
shellCache = { mtimeMs, html };
|
|
29068
29389
|
return html;
|
|
29069
29390
|
}
|
|
@@ -29083,17 +29404,17 @@ function serveBuildFile(c, webDist, dir, name) {
|
|
|
29083
29404
|
if (!type || !/^[A-Za-z0-9._-]+$/.test(name) || name.includes("..")) {
|
|
29084
29405
|
return c.text("not found", 404);
|
|
29085
29406
|
}
|
|
29086
|
-
const path =
|
|
29087
|
-
if (!
|
|
29407
|
+
const path = join22(webDist, dir, name);
|
|
29408
|
+
if (!existsSync20(path)) return c.text("not found", 404);
|
|
29088
29409
|
c.header("Content-Type", type);
|
|
29089
29410
|
c.header("Cache-Control", "public, max-age=31536000, immutable");
|
|
29090
29411
|
if (ext === ".css") {
|
|
29091
|
-
return c.body(
|
|
29412
|
+
return c.body(readFileSync17(path, "utf8").replaceAll("url(/fonts/", `url(${BUILD_PREFIX}/fonts/`));
|
|
29092
29413
|
}
|
|
29093
29414
|
if (ext === ".js") {
|
|
29094
|
-
return c.body(
|
|
29415
|
+
return c.body(readFileSync17(path, "utf8").replaceAll('"/assets/', `"${BUILD_PREFIX}/`));
|
|
29095
29416
|
}
|
|
29096
|
-
return c.body(new Uint8Array(
|
|
29417
|
+
return c.body(new Uint8Array(readFileSync17(path)));
|
|
29097
29418
|
}
|
|
29098
29419
|
var HTML_SHARE_CSP = "sandbox allow-scripts allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox";
|
|
29099
29420
|
function servePublishedHtml(c, share) {
|
|
@@ -29229,8 +29550,8 @@ ${analytics}` : head);
|
|
|
29229
29550
|
const requested = c.req.param("lang");
|
|
29230
29551
|
const lang = canonicalLanguage(requested);
|
|
29231
29552
|
if (!isTranslatableLanguage(lang)) return next();
|
|
29232
|
-
const shell =
|
|
29233
|
-
if (!
|
|
29553
|
+
const shell = join22(webDist, "index.html");
|
|
29554
|
+
if (!existsSync20(shell)) return next();
|
|
29234
29555
|
const share = await getDocShare(c.req.param("id"));
|
|
29235
29556
|
if (!share) return next();
|
|
29236
29557
|
if (requested !== lang) return c.redirect(`/share/${share.id}/${lang}`, 302);
|
|
@@ -29265,8 +29586,8 @@ ${analytics}` : head);
|
|
|
29265
29586
|
const share = await getDocShare(c.req.param("id"));
|
|
29266
29587
|
if (!share) return next();
|
|
29267
29588
|
if (share.kind === "html") return servePublishedHtml(c, share);
|
|
29268
|
-
const shell =
|
|
29269
|
-
if (!
|
|
29589
|
+
const shell = join22(webDist, "index.html");
|
|
29590
|
+
if (!existsSync20(shell)) return next();
|
|
29270
29591
|
return readerPage(
|
|
29271
29592
|
c,
|
|
29272
29593
|
share,
|
|
@@ -29291,7 +29612,7 @@ ${analytics}` : head);
|
|
|
29291
29612
|
}
|
|
29292
29613
|
|
|
29293
29614
|
// src/dashboard/artifact-export.ts
|
|
29294
|
-
import { readFileSync as
|
|
29615
|
+
import { readFileSync as readFileSync18 } from "fs";
|
|
29295
29616
|
async function exportDocAsArtifact(channelId, docPath) {
|
|
29296
29617
|
const owningProfile = findOwningProfile(channelId);
|
|
29297
29618
|
const channelConfig = await runWithProfile(
|
|
@@ -29300,7 +29621,7 @@ async function exportDocAsArtifact(channelId, docPath) {
|
|
|
29300
29621
|
);
|
|
29301
29622
|
const abs = resolveDocPath(channelConfig.cwd, docPath);
|
|
29302
29623
|
if (!abs) throw new Error(`doc not found: ${docPath}`);
|
|
29303
|
-
const content =
|
|
29624
|
+
const content = readFileSync18(abs, "utf8");
|
|
29304
29625
|
const title = extractTitle(abs, "md");
|
|
29305
29626
|
const today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
29306
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).
|
|
@@ -29518,9 +29839,9 @@ function readHead(absPath) {
|
|
|
29518
29839
|
}
|
|
29519
29840
|
}
|
|
29520
29841
|
function extractTitle(absPath, kind) {
|
|
29521
|
-
if (kind === "url" || kind === "excalidraw") return
|
|
29842
|
+
if (kind === "url" || kind === "excalidraw") return basename6(absPath);
|
|
29522
29843
|
const head = readHead(absPath);
|
|
29523
|
-
if (!head) return
|
|
29844
|
+
if (!head) return basename6(absPath);
|
|
29524
29845
|
if (kind === "md") {
|
|
29525
29846
|
const m = head.match(/^#{1,3}\s+(.+?)\s*$/m);
|
|
29526
29847
|
if (m) return m[1].replace(/[*_`]/g, "").trim();
|
|
@@ -29528,7 +29849,7 @@ function extractTitle(absPath, kind) {
|
|
|
29528
29849
|
const t = head.match(/<title[^>]*>([^<]+)<\/title>/i) ?? head.match(/<h1[^>]*>([^<]+)<\/h1>/i);
|
|
29529
29850
|
if (t) return t[1].trim();
|
|
29530
29851
|
}
|
|
29531
|
-
return
|
|
29852
|
+
return basename6(absPath);
|
|
29532
29853
|
}
|
|
29533
29854
|
function resolveDirPath(root, rel) {
|
|
29534
29855
|
if (rel.includes("\0")) return null;
|
|
@@ -29549,7 +29870,7 @@ function probeDir(absDir, showHidden) {
|
|
|
29549
29870
|
if (depth > MAX_SEARCH_DEPTH) return false;
|
|
29550
29871
|
let entries2;
|
|
29551
29872
|
try {
|
|
29552
|
-
entries2 =
|
|
29873
|
+
entries2 = readdirSync6(dir, { withFileTypes: true });
|
|
29553
29874
|
} catch {
|
|
29554
29875
|
return false;
|
|
29555
29876
|
}
|
|
@@ -29560,7 +29881,7 @@ function probeDir(absDir, showHidden) {
|
|
|
29560
29881
|
return false;
|
|
29561
29882
|
}
|
|
29562
29883
|
if (!showHidden && entry.name.startsWith(".")) continue;
|
|
29563
|
-
const abs =
|
|
29884
|
+
const abs = join23(dir, entry.name);
|
|
29564
29885
|
const kind = entryKind(entry, abs);
|
|
29565
29886
|
if (kind === "dir") {
|
|
29566
29887
|
if (SKIP_DIRS.has(entry.name)) hasOther = true;
|
|
@@ -29580,14 +29901,14 @@ function probeDir(absDir, showHidden) {
|
|
|
29580
29901
|
}
|
|
29581
29902
|
function readGitBranch(dir) {
|
|
29582
29903
|
try {
|
|
29583
|
-
let gitDir =
|
|
29904
|
+
let gitDir = join23(dir, ".git");
|
|
29584
29905
|
if (statSync7(gitDir).isFile()) {
|
|
29585
|
-
const pointer =
|
|
29906
|
+
const pointer = readFileSync19(gitDir, "utf8").trim();
|
|
29586
29907
|
const match = pointer.match(/^gitdir:\s*(.+)$/);
|
|
29587
29908
|
if (!match) return void 0;
|
|
29588
29909
|
gitDir = resolve7(dir, match[1]);
|
|
29589
29910
|
}
|
|
29590
|
-
const head =
|
|
29911
|
+
const head = readFileSync19(join23(gitDir, "HEAD"), "utf8").trim();
|
|
29591
29912
|
const branchMatch = head.match(/^ref:\s*refs\/heads\/(.+)$/);
|
|
29592
29913
|
if (branchMatch) return branchMatch[1];
|
|
29593
29914
|
return /^[0-9a-f]{7,40}$/i.test(head) ? head.slice(0, 7) : void 0;
|
|
@@ -29600,7 +29921,7 @@ function listDocLevel(root, relDir = "", sort = "newest", showHidden = false) {
|
|
|
29600
29921
|
if (absDir === null) return [];
|
|
29601
29922
|
let entries2;
|
|
29602
29923
|
try {
|
|
29603
|
-
entries2 =
|
|
29924
|
+
entries2 = readdirSync6(absDir, { withFileTypes: true });
|
|
29604
29925
|
} catch {
|
|
29605
29926
|
return [];
|
|
29606
29927
|
}
|
|
@@ -29609,14 +29930,14 @@ function listDocLevel(root, relDir = "", sort = "newest", showHidden = false) {
|
|
|
29609
29930
|
for (const entry of entries2) {
|
|
29610
29931
|
if (dirs.length + docs.length >= MAX_ENTRIES) break;
|
|
29611
29932
|
if (!showHidden && entry.name.startsWith(".")) continue;
|
|
29612
|
-
const abs =
|
|
29933
|
+
const abs = join23(absDir, entry.name);
|
|
29613
29934
|
const path = relative(root, abs).split(sep3).join("/");
|
|
29614
29935
|
const kind = entryKind(entry, abs);
|
|
29615
29936
|
if (kind === "dir") {
|
|
29616
29937
|
if (SKIP_DIRS.has(entry.name)) continue;
|
|
29617
29938
|
const probe = probeDir(abs, showHidden);
|
|
29618
29939
|
if (!probe.hasDocs && probe.hasOther) continue;
|
|
29619
|
-
const isRepo =
|
|
29940
|
+
const isRepo = existsSync21(join23(abs, ".git"));
|
|
29620
29941
|
dirs.push({
|
|
29621
29942
|
path,
|
|
29622
29943
|
name: entry.name,
|
|
@@ -29645,14 +29966,14 @@ function flatDocs(root, {
|
|
|
29645
29966
|
if (depth > MAX_SEARCH_DEPTH || hits.length >= MAX_FLAT_DOCS) return;
|
|
29646
29967
|
let entries2;
|
|
29647
29968
|
try {
|
|
29648
|
-
entries2 =
|
|
29969
|
+
entries2 = readdirSync6(dir, { withFileTypes: true });
|
|
29649
29970
|
} catch {
|
|
29650
29971
|
return;
|
|
29651
29972
|
}
|
|
29652
29973
|
for (const entry of entries2) {
|
|
29653
29974
|
if (hits.length >= MAX_FLAT_DOCS) return;
|
|
29654
29975
|
if (!showHidden && entry.name.startsWith(".")) continue;
|
|
29655
|
-
const abs =
|
|
29976
|
+
const abs = join23(dir, entry.name);
|
|
29656
29977
|
const kind = entryKind(entry, abs);
|
|
29657
29978
|
if (kind === "dir") {
|
|
29658
29979
|
if (!SKIP_DIRS.has(entry.name)) walk(abs, depth + 1);
|
|
@@ -29694,7 +30015,7 @@ function writeDocContent(root, rel, content, baseMtime) {
|
|
|
29694
30015
|
if (Buffer.byteLength(content, "utf8") > MAX_CONTENT_BYTES) {
|
|
29695
30016
|
return { status: "too-large" };
|
|
29696
30017
|
}
|
|
29697
|
-
|
|
30018
|
+
writeFileSync9(abs, content, "utf8");
|
|
29698
30019
|
return { status: "ok", mtime: statSync7(abs).mtime.toISOString() };
|
|
29699
30020
|
}
|
|
29700
30021
|
function resolveRawPath(root, rel) {
|
|
@@ -29716,7 +30037,7 @@ function resolveDownloadPath(root, rel) {
|
|
|
29716
30037
|
if (!rel || rel.includes("\0")) return null;
|
|
29717
30038
|
const abs = resolve7(root, rel);
|
|
29718
30039
|
if (abs !== root && !abs.startsWith(root + sep3)) return null;
|
|
29719
|
-
if (!isListableFile(
|
|
30040
|
+
if (!isListableFile(basename6(abs))) return null;
|
|
29720
30041
|
const contentType = MEDIA_EXTENSIONS[extname2(abs).toLowerCase()] ?? "application/octet-stream";
|
|
29721
30042
|
return { abs, contentType };
|
|
29722
30043
|
}
|
|
@@ -29732,7 +30053,7 @@ function uniqueName(absDir, name) {
|
|
|
29732
30053
|
let candidate = name;
|
|
29733
30054
|
for (let n = 1; n < 1e3; n++) {
|
|
29734
30055
|
try {
|
|
29735
|
-
statSync7(
|
|
30056
|
+
statSync7(join23(absDir, candidate));
|
|
29736
30057
|
} catch {
|
|
29737
30058
|
return candidate;
|
|
29738
30059
|
}
|
|
@@ -29754,8 +30075,8 @@ function saveUploadedFile(root, relDir, name, data) {
|
|
|
29754
30075
|
if (!(ext in DOC_EXTENSIONS) && !ASSET_LIST_EXTENSIONS.has(ext)) return { status: "bad-type" };
|
|
29755
30076
|
if (data.byteLength > MAX_UPLOAD_BYTES) return { status: "too-large" };
|
|
29756
30077
|
const final = uniqueName(absDir, safe);
|
|
29757
|
-
const abs =
|
|
29758
|
-
|
|
30078
|
+
const abs = join23(absDir, final);
|
|
30079
|
+
writeFileSync9(abs, data);
|
|
29759
30080
|
return { status: "ok", path: relative(root, abs).split(sep3).join("/"), name: final };
|
|
29760
30081
|
}
|
|
29761
30082
|
function createDocFolder(root, relDir, name) {
|
|
@@ -29768,13 +30089,13 @@ function createDocFolder(root, relDir, name) {
|
|
|
29768
30089
|
}
|
|
29769
30090
|
const safe = sanitizeUploadName(name);
|
|
29770
30091
|
if (!safe) return { status: "bad-name" };
|
|
29771
|
-
const abs =
|
|
30092
|
+
const abs = join23(absDir, safe);
|
|
29772
30093
|
try {
|
|
29773
30094
|
statSync7(abs);
|
|
29774
30095
|
return { status: "exists" };
|
|
29775
30096
|
} catch {
|
|
29776
30097
|
}
|
|
29777
|
-
|
|
30098
|
+
mkdirSync10(abs);
|
|
29778
30099
|
return { status: "ok", path: relative(root, abs).split(sep3).join("/"), name: safe };
|
|
29779
30100
|
}
|
|
29780
30101
|
function createDocFile(root, relDir, name, content) {
|
|
@@ -29791,9 +30112,9 @@ function createDocFile(root, relDir, name, content) {
|
|
|
29791
30112
|
if (!(ext in DOC_EXTENSIONS) && !(ext in CODE_EXTENSIONS)) return { status: "bad-name" };
|
|
29792
30113
|
if (SKIP_FILES.has(safe)) return { status: "bad-name" };
|
|
29793
30114
|
if (Buffer.byteLength(content, "utf8") > MAX_CONTENT_BYTES) return { status: "too-large" };
|
|
29794
|
-
const abs =
|
|
30115
|
+
const abs = join23(absDir, safe);
|
|
29795
30116
|
try {
|
|
29796
|
-
|
|
30117
|
+
writeFileSync9(abs, content, { encoding: "utf8", flag: "wx" });
|
|
29797
30118
|
} catch (err) {
|
|
29798
30119
|
if (err.code === "EEXIST") return { status: "exists" };
|
|
29799
30120
|
throw err;
|
|
@@ -29814,7 +30135,7 @@ function moveDocEntry(root, from, to) {
|
|
|
29814
30135
|
if (!isDir && !stat.isFile()) return { status: "not-found" };
|
|
29815
30136
|
const absTo = resolve7(root, to);
|
|
29816
30137
|
if (!absTo.startsWith(root + sep3)) return { status: "bad-target" };
|
|
29817
|
-
const name = sanitizeUploadName(
|
|
30138
|
+
const name = sanitizeUploadName(basename6(absTo));
|
|
29818
30139
|
if (!name) return { status: "bad-target" };
|
|
29819
30140
|
if (!isDir) {
|
|
29820
30141
|
const ext = extname2(name).toLowerCase();
|
|
@@ -29822,14 +30143,14 @@ function moveDocEntry(root, from, to) {
|
|
|
29822
30143
|
return { status: "bad-target" };
|
|
29823
30144
|
}
|
|
29824
30145
|
}
|
|
29825
|
-
const absToDir =
|
|
30146
|
+
const absToDir = dirname4(absTo);
|
|
29826
30147
|
if (resolveDirPath(root, relative(root, absToDir)) === null) return { status: "bad-target" };
|
|
29827
30148
|
try {
|
|
29828
30149
|
if (!statSync7(absToDir).isDirectory()) return { status: "bad-target" };
|
|
29829
30150
|
} catch {
|
|
29830
30151
|
return { status: "bad-target" };
|
|
29831
30152
|
}
|
|
29832
|
-
const finalAbs =
|
|
30153
|
+
const finalAbs = join23(absToDir, name);
|
|
29833
30154
|
if (isDir && (finalAbs === absFrom || finalAbs.startsWith(absFrom + sep3))) {
|
|
29834
30155
|
return { status: "into-self" };
|
|
29835
30156
|
}
|
|
@@ -29837,7 +30158,7 @@ function moveDocEntry(root, from, to) {
|
|
|
29837
30158
|
if (realpathSync(finalAbs) !== realpathSync(absFrom)) return { status: "exists" };
|
|
29838
30159
|
} catch {
|
|
29839
30160
|
}
|
|
29840
|
-
|
|
30161
|
+
renameSync3(absFrom, finalAbs);
|
|
29841
30162
|
return { status: "ok", path: relative(root, finalAbs).split(sep3).join("/"), name };
|
|
29842
30163
|
}
|
|
29843
30164
|
function deleteDocEntry(root, path) {
|
|
@@ -29852,7 +30173,7 @@ function deleteDocEntry(root, path) {
|
|
|
29852
30173
|
}
|
|
29853
30174
|
const isDir = stat.isDirectory();
|
|
29854
30175
|
if (!isDir && !stat.isFile() && !stat.isSymbolicLink()) return { status: "not-found" };
|
|
29855
|
-
|
|
30176
|
+
rmSync12(abs, { recursive: isDir });
|
|
29856
30177
|
return {
|
|
29857
30178
|
status: "ok",
|
|
29858
30179
|
path: relative(root, abs).split(sep3).join("/"),
|
|
@@ -29891,7 +30212,7 @@ function createDocsRouter({ gate = requireDocsAccess } = {}) {
|
|
|
29891
30212
|
}
|
|
29892
30213
|
if (!stat.isFile()) return c.json({ error: "not found" }, 404);
|
|
29893
30214
|
if (stat.size > MAX_RAW_BYTES) return c.json({ error: "file too large" }, 413);
|
|
29894
|
-
const name =
|
|
30215
|
+
const name = basename6(resolved2.abs);
|
|
29895
30216
|
const asciiName = name.replace(/[^\x20-\x7e]/g, "_").replace(/["\\]/g, "_");
|
|
29896
30217
|
const disposition = download ? "attachment" : "inline";
|
|
29897
30218
|
const stream = Readable.toWeb(createReadStream(resolved2.abs));
|
|
@@ -29913,7 +30234,7 @@ function createDocsRouter({ gate = requireDocsAccess } = {}) {
|
|
|
29913
30234
|
}
|
|
29914
30235
|
if (!stat.isFile()) return c.json({ error: "not found" }, 404);
|
|
29915
30236
|
if (stat.size > MAX_RAW_BYTES) return c.json({ error: "file too large" }, 413);
|
|
29916
|
-
return c.body(withDocLinkBridge(
|
|
30237
|
+
return c.body(withDocLinkBridge(readFileSync19(abs, "utf8")), 200, {
|
|
29917
30238
|
"Content-Type": "text/html; charset=utf-8",
|
|
29918
30239
|
"Content-Security-Policy": HTML_SHARE_CSP,
|
|
29919
30240
|
"X-Content-Type-Options": "nosniff",
|
|
@@ -30095,10 +30416,10 @@ function createDocsRouter({ gate = requireDocsAccess } = {}) {
|
|
|
30095
30416
|
// by; only docs get a parsed title.
|
|
30096
30417
|
kind: kind ?? "code",
|
|
30097
30418
|
lang: kind ? void 0 : CODE_EXTENSIONS[ext],
|
|
30098
|
-
title: kind ? extractTitle(abs, kind) :
|
|
30419
|
+
title: kind ? extractTitle(abs, kind) : basename6(abs),
|
|
30099
30420
|
mtime: stat.mtime.toISOString(),
|
|
30100
30421
|
tooLarge: tooLarge || void 0,
|
|
30101
|
-
content: tooLarge ? "" :
|
|
30422
|
+
content: tooLarge ? "" : readFileSync19(abs, "utf8")
|
|
30102
30423
|
});
|
|
30103
30424
|
});
|
|
30104
30425
|
app.put("/:id/docs/content", async (c) => {
|
|
@@ -30141,7 +30462,7 @@ function createDocsRouter({ gate = requireDocsAccess } = {}) {
|
|
|
30141
30462
|
channel,
|
|
30142
30463
|
rel,
|
|
30143
30464
|
title: extractTitle(abs, "md"),
|
|
30144
|
-
content:
|
|
30465
|
+
content: readFileSync19(abs, "utf8")
|
|
30145
30466
|
};
|
|
30146
30467
|
};
|
|
30147
30468
|
app.get("/:id/docs/translation/:lang", async (c) => {
|
|
@@ -30199,7 +30520,7 @@ function withDocLinkBridge(html) {
|
|
|
30199
30520
|
var DOC_MENTION_RE = /(?<![\w@/`])@((?:[\w.-]+\/)+[\w.-]+\.[A-Za-z0-9]{1,6})(?::(\d+))?(?![\w-])/g;
|
|
30200
30521
|
function isRealDoc(root, rel) {
|
|
30201
30522
|
const abs = resolveDocPath(root, rel);
|
|
30202
|
-
if (!abs || !
|
|
30523
|
+
if (!abs || !existsSync22(abs)) return false;
|
|
30203
30524
|
try {
|
|
30204
30525
|
return statSync8(abs).isFile();
|
|
30205
30526
|
} catch {
|
|
@@ -30640,7 +30961,7 @@ var BACKGROUND_CHECK_IN_MS = 30 * 6e4;
|
|
|
30640
30961
|
var MISSED_MESSAGE_WINDOW_MS = 24 * 60 * 60 * 1e3;
|
|
30641
30962
|
var MISSED_MESSAGE_THREAD_LIMIT = 100;
|
|
30642
30963
|
var delay = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
30643
|
-
function stripPathPrefixes(label, roots, home =
|
|
30964
|
+
function stripPathPrefixes(label, roots, home = homedir8()) {
|
|
30644
30965
|
let out = label;
|
|
30645
30966
|
for (const root of roots) {
|
|
30646
30967
|
if (root) out = out.replaceAll(`${root.replace(/\/+$/, "")}/`, "");
|
|
@@ -34195,6 +34516,7 @@ async function startServer() {
|
|
|
34195
34516
|
const reactionStore = new ReactionStore(paths.DB_FILE);
|
|
34196
34517
|
const slack = config.slackBotToken ? createSlackApp(config) : void 0;
|
|
34197
34518
|
await refreshChannelRegistry();
|
|
34519
|
+
void autoSyncPersonaAvatars(getProfile());
|
|
34198
34520
|
warnOnBrokenChannelCwds();
|
|
34199
34521
|
const stopChannelPolling = startChannelRegistryPolling();
|
|
34200
34522
|
await refreshAutomationRegistry();
|
|
@@ -34343,6 +34665,33 @@ export {
|
|
|
34343
34665
|
DEFAULT_TIMEZONE,
|
|
34344
34666
|
loadAutomations,
|
|
34345
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,
|
|
34346
34695
|
MEMORY_TYPES,
|
|
34347
34696
|
isMemoryType,
|
|
34348
34697
|
validateMemoryInput,
|
|
@@ -34408,16 +34757,6 @@ export {
|
|
|
34408
34757
|
CLI_VERSION,
|
|
34409
34758
|
isOlderVersion,
|
|
34410
34759
|
latestCliVersion,
|
|
34411
|
-
acquireHostLock,
|
|
34412
|
-
publishHostEndpoint,
|
|
34413
|
-
readHostEndpoint,
|
|
34414
|
-
setHostDbSender,
|
|
34415
|
-
handleHostDbResult,
|
|
34416
|
-
requestHostDb,
|
|
34417
|
-
handleAttachmentUrlResult,
|
|
34418
|
-
handleShouldRespondResult,
|
|
34419
|
-
LOCAL_DB_PATH,
|
|
34420
|
-
createHostDbClient,
|
|
34421
34760
|
workspaceSkillsDir,
|
|
34422
34761
|
channelSkillsDir,
|
|
34423
34762
|
isValidSkillName,
|