flyspace-cli 0.1.59 → 0.1.60
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-44WHW7NK.js → chunk-PXZUNZ4S.js} +54 -2
- package/dist/{chunk-7W5FEG63.js → chunk-SIR6PTDT.js} +370 -918
- package/dist/{chunk-XACRG7BO.js → chunk-XYS7SVWC.js} +594 -13
- package/dist/cli.js +247 -222
- package/dist/index.js +2 -2
- package/dist/{threads-I52LSA5X.js → threads-QQRWT3OM.js} +23 -2
- package/package.json +1 -1
- package/system.capabilities.md +2 -0
|
@@ -4,6 +4,7 @@ const require = __flyspaceCreateRequire(import.meta.url);
|
|
|
4
4
|
import {
|
|
5
5
|
AGENT_AUTHOR,
|
|
6
6
|
DEFAULT_AUTO_CONTINUE_LIMIT,
|
|
7
|
+
DEFAULT_CODEX_MODEL,
|
|
7
8
|
SUPPORT_BOT_AUTHOR,
|
|
8
9
|
SYNCED_BOT_AUTHOR,
|
|
9
10
|
SessionStore,
|
|
@@ -25,15 +26,21 @@ import {
|
|
|
25
26
|
getR2Bucket,
|
|
26
27
|
getR2Client,
|
|
27
28
|
getSupabaseClient,
|
|
28
|
-
hasSupabaseCredentials,
|
|
29
29
|
isChannelAccessAllowed,
|
|
30
30
|
isEffort,
|
|
31
31
|
isHumanAuthor,
|
|
32
32
|
isPermissionMode,
|
|
33
|
+
loadConfig,
|
|
34
|
+
loadEnvFiles,
|
|
35
|
+
mcpStrictConfigEnabled,
|
|
33
36
|
onChannelRegistryChange,
|
|
34
37
|
paths,
|
|
35
38
|
postToDashboardChannel,
|
|
36
39
|
refreshChannelRegistry,
|
|
40
|
+
requestAttachmentUrl,
|
|
41
|
+
requestPluginSvg,
|
|
42
|
+
requestShouldRespond,
|
|
43
|
+
requireSlackBotToken,
|
|
37
44
|
resolveAutoContinueLimit,
|
|
38
45
|
resolveChannelPermissionMode,
|
|
39
46
|
resolveChannelPrompt,
|
|
@@ -45,15 +52,16 @@ import {
|
|
|
45
52
|
resolveModel,
|
|
46
53
|
resolveOwnPersona,
|
|
47
54
|
runWithProfile,
|
|
48
|
-
|
|
55
|
+
sendAgentFailure,
|
|
49
56
|
setSupabaseClientFactory,
|
|
50
57
|
startChannelRegistryPolling,
|
|
51
58
|
sweepScratchDir,
|
|
52
59
|
syncPostToDashboard,
|
|
53
60
|
updateChannelById,
|
|
54
61
|
uploadLocalImages,
|
|
62
|
+
useHostDbWithoutCredentials,
|
|
55
63
|
warnOnBrokenChannelCwds
|
|
56
|
-
} from "./chunk-
|
|
64
|
+
} from "./chunk-XYS7SVWC.js";
|
|
57
65
|
|
|
58
66
|
// ../../node_modules/.pnpm/delayed-stream@1.0.0/node_modules/delayed-stream/lib/delayed_stream.js
|
|
59
67
|
var require_delayed_stream = __commonJS({
|
|
@@ -9286,7 +9294,7 @@ var require_sign = __commonJS({
|
|
|
9286
9294
|
"../../node_modules/.pnpm/math-intrinsics@1.1.0/node_modules/math-intrinsics/sign.js"(exports, module) {
|
|
9287
9295
|
"use strict";
|
|
9288
9296
|
var $isNaN = require_isNaN();
|
|
9289
|
-
module.exports = function
|
|
9297
|
+
module.exports = function sign(number) {
|
|
9290
9298
|
if ($isNaN(number) || number === 0) {
|
|
9291
9299
|
return number;
|
|
9292
9300
|
}
|
|
@@ -9650,7 +9658,7 @@ var require_get_intrinsic = __commonJS({
|
|
|
9650
9658
|
var min = require_min();
|
|
9651
9659
|
var pow = require_pow();
|
|
9652
9660
|
var round = require_round();
|
|
9653
|
-
var
|
|
9661
|
+
var sign = require_sign();
|
|
9654
9662
|
var $Function = Function;
|
|
9655
9663
|
var getEvalledConstructor = function(expressionSyntax) {
|
|
9656
9664
|
try {
|
|
@@ -9764,7 +9772,7 @@ var require_get_intrinsic = __commonJS({
|
|
|
9764
9772
|
"%Math.min%": min,
|
|
9765
9773
|
"%Math.pow%": pow,
|
|
9766
9774
|
"%Math.round%": round,
|
|
9767
|
-
"%Math.sign%":
|
|
9775
|
+
"%Math.sign%": sign,
|
|
9768
9776
|
"%Reflect.getPrototypeOf%": $ReflectGPO
|
|
9769
9777
|
};
|
|
9770
9778
|
if (getProto) {
|
|
@@ -10954,7 +10962,7 @@ var require_supports_color = __commonJS({
|
|
|
10954
10962
|
return 1;
|
|
10955
10963
|
}
|
|
10956
10964
|
if ("CI" in env) {
|
|
10957
|
-
if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE", "DRONE"].some((
|
|
10965
|
+
if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
|
|
10958
10966
|
return 1;
|
|
10959
10967
|
}
|
|
10960
10968
|
return min;
|
|
@@ -13009,10 +13017,10 @@ var require_axios = __commonJS({
|
|
|
13009
13017
|
}
|
|
13010
13018
|
};
|
|
13011
13019
|
var CanceledError$1 = CanceledError;
|
|
13012
|
-
function settle(
|
|
13020
|
+
function settle(resolve7, reject, response) {
|
|
13013
13021
|
const validateStatus = response.config.validateStatus;
|
|
13014
13022
|
if (!response.status || !validateStatus || validateStatus(response.status)) {
|
|
13015
|
-
|
|
13023
|
+
resolve7(response);
|
|
13016
13024
|
} else {
|
|
13017
13025
|
reject(
|
|
13018
13026
|
new AxiosError$1(
|
|
@@ -13604,7 +13612,7 @@ var require_axios = __commonJS({
|
|
|
13604
13612
|
}
|
|
13605
13613
|
var isHttpAdapterSupported = typeof process !== "undefined" && utils$1.kindOf(process) === "process";
|
|
13606
13614
|
var wrapAsync = (asyncExecutor) => {
|
|
13607
|
-
return new Promise((
|
|
13615
|
+
return new Promise((resolve7, reject) => {
|
|
13608
13616
|
let onDone;
|
|
13609
13617
|
let isDone;
|
|
13610
13618
|
const done = (value, isRejected) => {
|
|
@@ -13614,7 +13622,7 @@ var require_axios = __commonJS({
|
|
|
13614
13622
|
};
|
|
13615
13623
|
const _resolve = (value) => {
|
|
13616
13624
|
done(value);
|
|
13617
|
-
|
|
13625
|
+
resolve7(value);
|
|
13618
13626
|
};
|
|
13619
13627
|
const _reject = (reason) => {
|
|
13620
13628
|
done(reason, true);
|
|
@@ -13661,7 +13669,7 @@ var require_axios = __commonJS({
|
|
|
13661
13669
|
}
|
|
13662
13670
|
};
|
|
13663
13671
|
var httpAdapter = isHttpAdapterSupported && function httpAdapter2(config) {
|
|
13664
|
-
return wrapAsync(async function dispatchHttpRequest(
|
|
13672
|
+
return wrapAsync(async function dispatchHttpRequest(resolve7, reject, onDone) {
|
|
13665
13673
|
let { data, lookup: lookup2, family, httpVersion = 1, http2Options } = config;
|
|
13666
13674
|
const { responseType, responseEncoding } = config;
|
|
13667
13675
|
const method = config.method.toUpperCase();
|
|
@@ -13751,7 +13759,7 @@ var require_axios = __commonJS({
|
|
|
13751
13759
|
}
|
|
13752
13760
|
let convertedData;
|
|
13753
13761
|
if (method !== "GET") {
|
|
13754
|
-
return settle(
|
|
13762
|
+
return settle(resolve7, reject, {
|
|
13755
13763
|
status: 405,
|
|
13756
13764
|
statusText: "method not allowed",
|
|
13757
13765
|
headers: {},
|
|
@@ -13773,7 +13781,7 @@ var require_axios = __commonJS({
|
|
|
13773
13781
|
} else if (responseType === "stream") {
|
|
13774
13782
|
convertedData = stream__default["default"].Readable.from(convertedData);
|
|
13775
13783
|
}
|
|
13776
|
-
return settle(
|
|
13784
|
+
return settle(resolve7, reject, {
|
|
13777
13785
|
data: convertedData,
|
|
13778
13786
|
status: 200,
|
|
13779
13787
|
statusText: "OK",
|
|
@@ -14014,7 +14022,7 @@ var require_axios = __commonJS({
|
|
|
14014
14022
|
};
|
|
14015
14023
|
if (responseType === "stream") {
|
|
14016
14024
|
response.data = responseStream;
|
|
14017
|
-
settle(
|
|
14025
|
+
settle(resolve7, reject, response);
|
|
14018
14026
|
} else {
|
|
14019
14027
|
const responseBuffer = [];
|
|
14020
14028
|
let totalResponseBytes = 0;
|
|
@@ -14064,7 +14072,7 @@ var require_axios = __commonJS({
|
|
|
14064
14072
|
} catch (err) {
|
|
14065
14073
|
return reject(AxiosError$1.from(err, null, config, response.request, response));
|
|
14066
14074
|
}
|
|
14067
|
-
settle(
|
|
14075
|
+
settle(resolve7, reject, response);
|
|
14068
14076
|
});
|
|
14069
14077
|
}
|
|
14070
14078
|
abortEmitter.once("abort", (err) => {
|
|
@@ -14314,7 +14322,7 @@ var require_axios = __commonJS({
|
|
|
14314
14322
|
};
|
|
14315
14323
|
var isXHRAdapterSupported = typeof XMLHttpRequest !== "undefined";
|
|
14316
14324
|
var xhrAdapter = isXHRAdapterSupported && function(config) {
|
|
14317
|
-
return new Promise(function dispatchXhrRequest(
|
|
14325
|
+
return new Promise(function dispatchXhrRequest(resolve7, reject) {
|
|
14318
14326
|
const _config = resolveConfig(config);
|
|
14319
14327
|
let requestData = _config.data;
|
|
14320
14328
|
const requestHeaders = AxiosHeaders$1.from(_config.headers).normalize();
|
|
@@ -14349,7 +14357,7 @@ var require_axios = __commonJS({
|
|
|
14349
14357
|
};
|
|
14350
14358
|
settle(
|
|
14351
14359
|
function _resolve(value) {
|
|
14352
|
-
|
|
14360
|
+
resolve7(value);
|
|
14353
14361
|
done();
|
|
14354
14362
|
},
|
|
14355
14363
|
function _reject(err) {
|
|
@@ -14568,8 +14576,8 @@ var require_axios = __commonJS({
|
|
|
14568
14576
|
};
|
|
14569
14577
|
var DEFAULT_CHUNK_SIZE = 64 * 1024;
|
|
14570
14578
|
var { isFunction } = utils$1;
|
|
14571
|
-
var globalFetchAPI = (({ Request
|
|
14572
|
-
Request
|
|
14579
|
+
var globalFetchAPI = (({ Request, Response: Response2 }) => ({
|
|
14580
|
+
Request,
|
|
14573
14581
|
Response: Response2
|
|
14574
14582
|
}))(utils$1.global);
|
|
14575
14583
|
var { ReadableStream: ReadableStream$1, TextEncoder: TextEncoder$1 } = utils$1.global;
|
|
@@ -14588,18 +14596,18 @@ var require_axios = __commonJS({
|
|
|
14588
14596
|
globalFetchAPI,
|
|
14589
14597
|
env
|
|
14590
14598
|
);
|
|
14591
|
-
const { fetch: envFetch, Request
|
|
14599
|
+
const { fetch: envFetch, Request, Response: Response2 } = env;
|
|
14592
14600
|
const isFetchSupported = envFetch ? isFunction(envFetch) : typeof fetch === "function";
|
|
14593
|
-
const isRequestSupported = isFunction(
|
|
14601
|
+
const isRequestSupported = isFunction(Request);
|
|
14594
14602
|
const isResponseSupported = isFunction(Response2);
|
|
14595
14603
|
if (!isFetchSupported) {
|
|
14596
14604
|
return false;
|
|
14597
14605
|
}
|
|
14598
14606
|
const isReadableStreamSupported = isFetchSupported && isFunction(ReadableStream$1);
|
|
14599
|
-
const encodeText = isFetchSupported && (typeof TextEncoder$1 === "function" ? /* @__PURE__ */ ((encoder) => (str) => encoder.encode(str))(new TextEncoder$1()) : async (str) => new Uint8Array(await new
|
|
14607
|
+
const encodeText = isFetchSupported && (typeof TextEncoder$1 === "function" ? /* @__PURE__ */ ((encoder) => (str) => encoder.encode(str))(new TextEncoder$1()) : async (str) => new Uint8Array(await new Request(str).arrayBuffer()));
|
|
14600
14608
|
const supportsRequestStream = isRequestSupported && isReadableStreamSupported && test(() => {
|
|
14601
14609
|
let duplexAccessed = false;
|
|
14602
|
-
const hasContentType = new
|
|
14610
|
+
const hasContentType = new Request(platform.origin, {
|
|
14603
14611
|
body: new ReadableStream$1(),
|
|
14604
14612
|
method: "POST",
|
|
14605
14613
|
get duplex() {
|
|
@@ -14636,7 +14644,7 @@ var require_axios = __commonJS({
|
|
|
14636
14644
|
return body.size;
|
|
14637
14645
|
}
|
|
14638
14646
|
if (utils$1.isSpecCompliantForm(body)) {
|
|
14639
|
-
const _request = new
|
|
14647
|
+
const _request = new Request(platform.origin, {
|
|
14640
14648
|
method: "POST",
|
|
14641
14649
|
body
|
|
14642
14650
|
});
|
|
@@ -14684,7 +14692,7 @@ var require_axios = __commonJS({
|
|
|
14684
14692
|
let requestContentLength;
|
|
14685
14693
|
try {
|
|
14686
14694
|
if (onUploadProgress && supportsRequestStream && method !== "get" && method !== "head" && (requestContentLength = await resolveBodyLength(headers, data)) !== 0) {
|
|
14687
|
-
let _request = new
|
|
14695
|
+
let _request = new Request(url2, {
|
|
14688
14696
|
method: "POST",
|
|
14689
14697
|
body: data,
|
|
14690
14698
|
duplex: "half"
|
|
@@ -14704,7 +14712,7 @@ var require_axios = __commonJS({
|
|
|
14704
14712
|
if (!utils$1.isString(withCredentials)) {
|
|
14705
14713
|
withCredentials = withCredentials ? "include" : "omit";
|
|
14706
14714
|
}
|
|
14707
|
-
const isCredentialsSupported = isRequestSupported && "credentials" in
|
|
14715
|
+
const isCredentialsSupported = isRequestSupported && "credentials" in Request.prototype;
|
|
14708
14716
|
const resolvedOptions = {
|
|
14709
14717
|
...fetchOptions,
|
|
14710
14718
|
signal: composedSignal,
|
|
@@ -14714,7 +14722,7 @@ var require_axios = __commonJS({
|
|
|
14714
14722
|
duplex: "half",
|
|
14715
14723
|
credentials: isCredentialsSupported ? withCredentials : void 0
|
|
14716
14724
|
};
|
|
14717
|
-
request = isRequestSupported && new
|
|
14725
|
+
request = isRequestSupported && new Request(url2, resolvedOptions);
|
|
14718
14726
|
let response = await (isRequestSupported ? _fetch(request, fetchOptions) : _fetch(url2, resolvedOptions));
|
|
14719
14727
|
const isStreamResponse = supportsResponseStream && (responseType === "stream" || responseType === "response");
|
|
14720
14728
|
if (supportsResponseStream && (onDownloadProgress || isStreamResponse && unsubscribe)) {
|
|
@@ -14741,8 +14749,8 @@ var require_axios = __commonJS({
|
|
|
14741
14749
|
config
|
|
14742
14750
|
);
|
|
14743
14751
|
!isStreamResponse && unsubscribe && unsubscribe();
|
|
14744
|
-
return await new Promise((
|
|
14745
|
-
settle(
|
|
14752
|
+
return await new Promise((resolve7, reject) => {
|
|
14753
|
+
settle(resolve7, reject, {
|
|
14746
14754
|
data: responseData,
|
|
14747
14755
|
headers: AxiosHeaders$1.from(response.headers),
|
|
14748
14756
|
status: response.status,
|
|
@@ -14774,8 +14782,8 @@ var require_axios = __commonJS({
|
|
|
14774
14782
|
var seedCache = /* @__PURE__ */ new Map();
|
|
14775
14783
|
var getFetch = (config) => {
|
|
14776
14784
|
let env = config && config.env || {};
|
|
14777
|
-
const { fetch: fetch2, Request
|
|
14778
|
-
const seeds = [
|
|
14785
|
+
const { fetch: fetch2, Request, Response: Response2 } = env;
|
|
14786
|
+
const seeds = [Request, Response2, fetch2];
|
|
14779
14787
|
let len = seeds.length, i = len, seed, target, map = seedCache;
|
|
14780
14788
|
while (i--) {
|
|
14781
14789
|
seed = seeds[i];
|
|
@@ -15146,8 +15154,8 @@ var require_axios = __commonJS({
|
|
|
15146
15154
|
throw new TypeError("executor must be a function.");
|
|
15147
15155
|
}
|
|
15148
15156
|
let resolvePromise;
|
|
15149
|
-
this.promise = new Promise(function promiseExecutor(
|
|
15150
|
-
resolvePromise =
|
|
15157
|
+
this.promise = new Promise(function promiseExecutor(resolve7) {
|
|
15158
|
+
resolvePromise = resolve7;
|
|
15151
15159
|
});
|
|
15152
15160
|
const token = this;
|
|
15153
15161
|
this.promise.then((cancel) => {
|
|
@@ -15160,9 +15168,9 @@ var require_axios = __commonJS({
|
|
|
15160
15168
|
});
|
|
15161
15169
|
this.promise.then = (onfulfilled) => {
|
|
15162
15170
|
let _resolve;
|
|
15163
|
-
const promise = new Promise((
|
|
15164
|
-
token.subscribe(
|
|
15165
|
-
_resolve =
|
|
15171
|
+
const promise = new Promise((resolve7) => {
|
|
15172
|
+
token.subscribe(resolve7);
|
|
15173
|
+
_resolve = resolve7;
|
|
15166
15174
|
}).then(onfulfilled);
|
|
15167
15175
|
promise.cancel = function reject() {
|
|
15168
15176
|
token.unsubscribe(_resolve);
|
|
@@ -17448,7 +17456,7 @@ var require_MsEdgeTTS = __commonJS({
|
|
|
17448
17456
|
};
|
|
17449
17457
|
const ws = this._ws = this._isBrowser ? new isomorphic_ws_1.default(synthUrl) : new isomorphic_ws_1.default(synthUrl, { ...options, agent: this._agent });
|
|
17450
17458
|
ws.binaryType = "arraybuffer";
|
|
17451
|
-
return new Promise((
|
|
17459
|
+
return new Promise((resolve7, reject) => {
|
|
17452
17460
|
let connecting = true;
|
|
17453
17461
|
const connectionTimeout = this._connectionTimeoutMs ? setTimeout(() => {
|
|
17454
17462
|
connecting = false;
|
|
@@ -17491,7 +17499,7 @@ Path:${messageTypes.SPEECH_CONFIG}${_MsEdgeTTS.JSON_XML_DELIM}
|
|
|
17491
17499
|
}
|
|
17492
17500
|
}
|
|
17493
17501
|
}
|
|
17494
|
-
`, void 0, ws).then(
|
|
17502
|
+
`, void 0, ws).then(resolve7, (error) => {
|
|
17495
17503
|
this._closeSocket(ws);
|
|
17496
17504
|
reject(error);
|
|
17497
17505
|
});
|
|
@@ -17633,12 +17641,12 @@ Path:${messageTypes.SPEECH_CONFIG}${_MsEdgeTTS.JSON_XML_DELIM}
|
|
|
17633
17641
|
this._log("<-", message);
|
|
17634
17642
|
return;
|
|
17635
17643
|
}
|
|
17636
|
-
await new Promise((
|
|
17644
|
+
await new Promise((resolve7, reject) => {
|
|
17637
17645
|
socket.send(message, (error) => {
|
|
17638
17646
|
if (error)
|
|
17639
17647
|
return reject(error);
|
|
17640
17648
|
this._log("<-", message);
|
|
17641
|
-
|
|
17649
|
+
resolve7();
|
|
17642
17650
|
});
|
|
17643
17651
|
});
|
|
17644
17652
|
}
|
|
@@ -17674,8 +17682,8 @@ Path:${messageTypes.SPEECH_CONFIG}${_MsEdgeTTS.JSON_XML_DELIM}
|
|
|
17674
17682
|
* These, however, are not all. The complete list of voices supported by this module [can be found here](https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/language-support) (neural, standard, and preview).
|
|
17675
17683
|
*/
|
|
17676
17684
|
getVoices() {
|
|
17677
|
-
return new Promise((
|
|
17678
|
-
axios_1.default.get(_MsEdgeTTS.VOICES_URL).then((res) =>
|
|
17685
|
+
return new Promise((resolve7, reject) => {
|
|
17686
|
+
axios_1.default.get(_MsEdgeTTS.VOICES_URL).then((res) => resolve7(res.data)).catch(reject);
|
|
17679
17687
|
});
|
|
17680
17688
|
}
|
|
17681
17689
|
/**
|
|
@@ -17778,7 +17786,7 @@ Path:${messageTypes.SPEECH_CONFIG}${_MsEdgeTTS.JSON_XML_DELIM}
|
|
|
17778
17786
|
const metadataFilePath = !!metadataStream ? (0, utils_1.joinPath)(dirPath, "metadata.json") : null;
|
|
17779
17787
|
try {
|
|
17780
17788
|
await Promise.all([
|
|
17781
|
-
new Promise((
|
|
17789
|
+
new Promise((resolve7, reject) => {
|
|
17782
17790
|
const writableAudioFile = audioStream.pipe(fs.createWriteStream(audioFilePath));
|
|
17783
17791
|
audioStream.once("error", (e) => {
|
|
17784
17792
|
writableAudioFile.destroy();
|
|
@@ -17786,7 +17794,7 @@ Path:${messageTypes.SPEECH_CONFIG}${_MsEdgeTTS.JSON_XML_DELIM}
|
|
|
17786
17794
|
});
|
|
17787
17795
|
writableAudioFile.once("close", async () => {
|
|
17788
17796
|
if (writableAudioFile.bytesWritten > 0) {
|
|
17789
|
-
|
|
17797
|
+
resolve7(audioFilePath);
|
|
17790
17798
|
} else {
|
|
17791
17799
|
reject(new Error("No audio data received"));
|
|
17792
17800
|
fs.rmSync(audioFilePath, { force: true });
|
|
@@ -17794,9 +17802,9 @@ Path:${messageTypes.SPEECH_CONFIG}${_MsEdgeTTS.JSON_XML_DELIM}
|
|
|
17794
17802
|
});
|
|
17795
17803
|
writableAudioFile.once("error", reject);
|
|
17796
17804
|
}),
|
|
17797
|
-
new Promise((
|
|
17805
|
+
new Promise((resolve7, reject) => {
|
|
17798
17806
|
if (!metadataFilePath) {
|
|
17799
|
-
return
|
|
17807
|
+
return resolve7(null);
|
|
17800
17808
|
}
|
|
17801
17809
|
const metadataItems = { Metadata: [] };
|
|
17802
17810
|
metadataStream.on("data", (chunk) => {
|
|
@@ -17806,7 +17814,7 @@ Path:${messageTypes.SPEECH_CONFIG}${_MsEdgeTTS.JSON_XML_DELIM}
|
|
|
17806
17814
|
metadataStream.once("close", () => {
|
|
17807
17815
|
if (metadataItems.Metadata.length > 0) {
|
|
17808
17816
|
fs.writeFileSync(metadataFilePath, JSON.stringify(metadataItems, null, 2));
|
|
17809
|
-
|
|
17817
|
+
resolve7(metadataFilePath);
|
|
17810
17818
|
} else {
|
|
17811
17819
|
reject(new Error("No metadata received"));
|
|
17812
17820
|
fs.rmSync(metadataFilePath, { force: true });
|
|
@@ -18484,12 +18492,12 @@ async function setAgentPaused(workspaceId, paused) {
|
|
|
18484
18492
|
|
|
18485
18493
|
// ../api/src/dashboard/auth-context.ts
|
|
18486
18494
|
function onboardingPending(ctx) {
|
|
18487
|
-
const
|
|
18488
|
-
if (!ctx.onboarded && !ctx.passwordSet)
|
|
18489
|
-
if (!ctx.onboarded)
|
|
18490
|
-
if (ctx.role === "admin" && !ctx.agentConnectedAt)
|
|
18491
|
-
if (ctx.role === "admin" && !ctx.projectsSetupAt)
|
|
18492
|
-
return
|
|
18495
|
+
const pending = [];
|
|
18496
|
+
if (!ctx.onboarded && !ctx.passwordSet) pending.push("account");
|
|
18497
|
+
if (!ctx.onboarded) pending.push("profile");
|
|
18498
|
+
if (ctx.role === "admin" && !ctx.agentConnectedAt) pending.push("agent");
|
|
18499
|
+
if (ctx.role === "admin" && !ctx.projectsSetupAt) pending.push("projects");
|
|
18500
|
+
return pending;
|
|
18493
18501
|
}
|
|
18494
18502
|
var inFlight = /* @__PURE__ */ new Map();
|
|
18495
18503
|
var CACHE_TTL_MS2 = 3e4;
|
|
@@ -18790,8 +18798,8 @@ async function agentViewer(c) {
|
|
|
18790
18798
|
|
|
18791
18799
|
// src/claude/agent.ts
|
|
18792
18800
|
import { spawn } from "child_process";
|
|
18793
|
-
import { existsSync as
|
|
18794
|
-
import { resolve as
|
|
18801
|
+
import { existsSync as existsSync6, readFileSync as readFileSync3, statSync as statSync2 } from "fs";
|
|
18802
|
+
import { resolve as resolve3, resolve as resolvePath } from "path";
|
|
18795
18803
|
import { homedir as homedir2 } from "os";
|
|
18796
18804
|
import { randomUUID } from "crypto";
|
|
18797
18805
|
|
|
@@ -19217,10 +19225,10 @@ var PluginUiSession = class {
|
|
|
19217
19225
|
onEvent(event) {
|
|
19218
19226
|
if (event.type === "control_response") {
|
|
19219
19227
|
const res = event.response;
|
|
19220
|
-
const
|
|
19221
|
-
if (!
|
|
19228
|
+
const resolve7 = res?.request_id ? this.pending.get(res.request_id) : void 0;
|
|
19229
|
+
if (!resolve7 || !res?.request_id) return;
|
|
19222
19230
|
this.pending.delete(res.request_id);
|
|
19223
|
-
|
|
19231
|
+
resolve7(res.subtype === "success" ? res.response?.tree : void 0);
|
|
19224
19232
|
return;
|
|
19225
19233
|
}
|
|
19226
19234
|
const e = event;
|
|
@@ -19239,8 +19247,8 @@ var PluginUiSession = class {
|
|
|
19239
19247
|
}
|
|
19240
19248
|
render(instanceId) {
|
|
19241
19249
|
const requestId = `flyspace-ui-render-${++this.seq}`;
|
|
19242
|
-
return new Promise((
|
|
19243
|
-
this.pending.set(requestId,
|
|
19250
|
+
return new Promise((resolve7) => {
|
|
19251
|
+
this.pending.set(requestId, resolve7);
|
|
19244
19252
|
this.write({
|
|
19245
19253
|
type: "control_request",
|
|
19246
19254
|
request_id: requestId,
|
|
@@ -19261,11 +19269,11 @@ var PluginUiSession = class {
|
|
|
19261
19269
|
*/
|
|
19262
19270
|
async finish() {
|
|
19263
19271
|
if (this.panes.length) {
|
|
19264
|
-
await new Promise((
|
|
19265
|
-
const timer2 = setTimeout(
|
|
19272
|
+
await new Promise((resolve7) => {
|
|
19273
|
+
const timer2 = setTimeout(resolve7, SETTLE_TIMEOUT_MS);
|
|
19266
19274
|
this.onInvalidate = () => {
|
|
19267
19275
|
clearTimeout(timer2);
|
|
19268
|
-
|
|
19276
|
+
resolve7();
|
|
19269
19277
|
};
|
|
19270
19278
|
});
|
|
19271
19279
|
this.onInvalidate = void 0;
|
|
@@ -19274,8 +19282,8 @@ var PluginUiSession = class {
|
|
|
19274
19282
|
this.panes.map(async (p) => ({ ...p, tree: await this.render(p.id) }))
|
|
19275
19283
|
);
|
|
19276
19284
|
let timer;
|
|
19277
|
-
const timeout = new Promise((
|
|
19278
|
-
timer = setTimeout(() =>
|
|
19285
|
+
const timeout = new Promise((resolve7) => {
|
|
19286
|
+
timer = setTimeout(() => resolve7(void 0), RENDER_TIMEOUT_MS);
|
|
19279
19287
|
});
|
|
19280
19288
|
const rendered = await Promise.race([renders, timeout]);
|
|
19281
19289
|
clearTimeout(timer);
|
|
@@ -19299,88 +19307,6 @@ function resolveModelAlias(model) {
|
|
|
19299
19307
|
return MODEL_ALIASES[model.toLowerCase()] ?? model;
|
|
19300
19308
|
}
|
|
19301
19309
|
|
|
19302
|
-
// ../api/src/config.ts
|
|
19303
|
-
import dotenv from "dotenv";
|
|
19304
|
-
import { existsSync as existsSync5 } from "fs";
|
|
19305
|
-
import { resolve as resolve2 } from "path";
|
|
19306
|
-
var DEFAULT_CODEX_MODEL = "";
|
|
19307
|
-
function mcpStrictConfigEnabled() {
|
|
19308
|
-
return process.env["MCP_STRICT_CONFIG"]?.trim() === "true";
|
|
19309
|
-
}
|
|
19310
|
-
function loadEnvFiles() {
|
|
19311
|
-
if (existsSync5(paths.CONFIG_FILE)) {
|
|
19312
|
-
dotenv.config({ path: paths.CONFIG_FILE, override: true, quiet: true });
|
|
19313
|
-
}
|
|
19314
|
-
const candidates = [resolve2(paths.PACKAGE_ROOT, ".env"), resolve2(process.cwd(), ".env")];
|
|
19315
|
-
for (const path of new Set(candidates)) {
|
|
19316
|
-
if (existsSync5(path)) {
|
|
19317
|
-
dotenv.config({ path, override: false, quiet: true });
|
|
19318
|
-
}
|
|
19319
|
-
}
|
|
19320
|
-
}
|
|
19321
|
-
function parseBudget(raw) {
|
|
19322
|
-
if (raw === void 0) return 10;
|
|
19323
|
-
const n = Number.parseFloat(raw);
|
|
19324
|
-
if (!Number.isFinite(n) || n <= 0) return void 0;
|
|
19325
|
-
return n;
|
|
19326
|
-
}
|
|
19327
|
-
function parseEffort(raw) {
|
|
19328
|
-
const trimmed = raw?.trim().toLowerCase();
|
|
19329
|
-
return trimmed && isEffort(trimmed) ? trimmed : void 0;
|
|
19330
|
-
}
|
|
19331
|
-
var SLACK_ENV = ["SLACK_BOT_TOKEN", "SLACK_APP_TOKEN", "SLACK_SIGNING_SECRET"];
|
|
19332
|
-
function slackConfigured(env = process.env) {
|
|
19333
|
-
return SLACK_ENV.some((name) => env[name]?.trim());
|
|
19334
|
-
}
|
|
19335
|
-
function requireSlackBotToken(config) {
|
|
19336
|
-
if (!config.slackBotToken) {
|
|
19337
|
-
throw new Error("Slack is not configured: set SLACK_BOT_TOKEN to use Slack commands");
|
|
19338
|
-
}
|
|
19339
|
-
return config.slackBotToken;
|
|
19340
|
-
}
|
|
19341
|
-
function requireEnv(name) {
|
|
19342
|
-
const value = process.env[name];
|
|
19343
|
-
if (!value) {
|
|
19344
|
-
throw new Error(`Missing required environment variable: ${name}`);
|
|
19345
|
-
}
|
|
19346
|
-
return value;
|
|
19347
|
-
}
|
|
19348
|
-
function loadConfig() {
|
|
19349
|
-
const ownerUserId = process.env["OWNER_USER_ID"] || void 0;
|
|
19350
|
-
const allowedUserIds = new Set(
|
|
19351
|
-
(process.env["ALLOWED_USER_IDS"] ?? "").split(",").map((s) => s.trim()).filter(Boolean)
|
|
19352
|
-
);
|
|
19353
|
-
if (ownerUserId && allowedUserIds.size > 0) {
|
|
19354
|
-
allowedUserIds.add(ownerUserId);
|
|
19355
|
-
}
|
|
19356
|
-
const autoRespondChannelIds = new Set(
|
|
19357
|
-
(process.env["AUTO_RESPOND_CHANNEL_IDS"] ?? "").split(",").map((s) => s.trim()).filter(Boolean)
|
|
19358
|
-
);
|
|
19359
|
-
const slackEnglishOnlyExemptChannelIds = new Set(
|
|
19360
|
-
(process.env["SLACK_ENGLISH_ONLY_EXEMPT_CHANNEL_IDS"] ?? "").split(",").map((s) => s.trim()).filter(Boolean)
|
|
19361
|
-
);
|
|
19362
|
-
const slack = slackConfigured();
|
|
19363
|
-
return {
|
|
19364
|
-
slackBotToken: slack ? requireEnv("SLACK_BOT_TOKEN") : void 0,
|
|
19365
|
-
slackAppToken: slack ? requireEnv("SLACK_APP_TOKEN") : void 0,
|
|
19366
|
-
slackSigningSecret: slack ? requireEnv("SLACK_SIGNING_SECRET") : void 0,
|
|
19367
|
-
claudeCwd: process.env["CLAUDE_CWD"] ?? process.cwd(),
|
|
19368
|
-
claudeConfigDir: process.env["CLAUDE_CONFIG_DIR"] || void 0,
|
|
19369
|
-
claudeCodeOauthToken: process.env["CLAUDE_CODE_OAUTH_TOKEN"] || void 0,
|
|
19370
|
-
botName: process.env["BOT_NAME"] ?? "Bot",
|
|
19371
|
-
allowedUserIds,
|
|
19372
|
-
maxTurns: parseInt(process.env["MAX_TURNS"] ?? "10", 10),
|
|
19373
|
-
model: process.env["CUSTIE_MODEL"]?.trim() || "sonnet",
|
|
19374
|
-
effort: parseEffort(process.env["CUSTIE_EFFORT"]),
|
|
19375
|
-
maxBudgetUsd: parseBudget(process.env["MAX_BUDGET_USD"]),
|
|
19376
|
-
ownerUserId,
|
|
19377
|
-
autoRespondChannelIds,
|
|
19378
|
-
codexModel: process.env["CUSTIE_CODEX_MODEL"]?.trim() || DEFAULT_CODEX_MODEL,
|
|
19379
|
-
slackEnglishOnly: process.env["SLACK_ENGLISH_ONLY"] === "true",
|
|
19380
|
-
slackEnglishOnlyExemptChannelIds
|
|
19381
|
-
};
|
|
19382
|
-
}
|
|
19383
|
-
|
|
19384
19310
|
// ../api/src/utils/mise-env.ts
|
|
19385
19311
|
import { execFileSync as execFileSync3 } from "child_process";
|
|
19386
19312
|
function resolveMiseEnv(cwd) {
|
|
@@ -19402,9 +19328,9 @@ function readMiseEnv(cwd) {
|
|
|
19402
19328
|
}
|
|
19403
19329
|
|
|
19404
19330
|
// ../api/src/store/output-styles-store.ts
|
|
19405
|
-
import { existsSync as
|
|
19331
|
+
import { existsSync as existsSync5, mkdirSync as mkdirSync4, readdirSync, readFileSync as readFileSync2, renameSync, rmSync, statSync, writeFileSync as writeFileSync2 } from "fs";
|
|
19406
19332
|
import { homedir } from "os";
|
|
19407
|
-
import { join as join4, resolve as
|
|
19333
|
+
import { join as join4, resolve as resolve2, sep } from "path";
|
|
19408
19334
|
var BUILT_IN_OUTPUT_STYLES = [
|
|
19409
19335
|
{ slug: "default", name: "Default", description: "Claude Code\u2019s standard software engineering prompt." },
|
|
19410
19336
|
{ slug: "proactive", name: "Proactive", description: "Works autonomously and makes reasonable calls instead of asking." },
|
|
@@ -19423,8 +19349,8 @@ function stylesDir(claudeConfigDir) {
|
|
|
19423
19349
|
}
|
|
19424
19350
|
function styleFile(claudeConfigDir, id) {
|
|
19425
19351
|
if (!ID_RE.test(id)) return null;
|
|
19426
|
-
const dir =
|
|
19427
|
-
const file =
|
|
19352
|
+
const dir = resolve2(stylesDir(claudeConfigDir));
|
|
19353
|
+
const file = resolve2(dir, `${id}.md`);
|
|
19428
19354
|
return file.startsWith(dir + sep) ? file : null;
|
|
19429
19355
|
}
|
|
19430
19356
|
function slugify(name) {
|
|
@@ -19467,14 +19393,14 @@ ${p.body.trim()}
|
|
|
19467
19393
|
`;
|
|
19468
19394
|
}
|
|
19469
19395
|
function atomicWrite(file, content) {
|
|
19470
|
-
mkdirSync4(
|
|
19396
|
+
mkdirSync4(resolve2(file, ".."), { recursive: true });
|
|
19471
19397
|
const tmp = `${file}.${process.pid}.tmp`;
|
|
19472
19398
|
writeFileSync2(tmp, content);
|
|
19473
19399
|
renameSync(tmp, file);
|
|
19474
19400
|
}
|
|
19475
19401
|
function readStyle(claudeConfigDir, id) {
|
|
19476
19402
|
const file = styleFile(claudeConfigDir, id);
|
|
19477
|
-
if (!file || !
|
|
19403
|
+
if (!file || !existsSync5(file)) return null;
|
|
19478
19404
|
const stat = statSync(file);
|
|
19479
19405
|
const p = parseStyle(readFileSync2(file, "utf8"), id);
|
|
19480
19406
|
return {
|
|
@@ -19488,7 +19414,7 @@ function readStyle(claudeConfigDir, id) {
|
|
|
19488
19414
|
}
|
|
19489
19415
|
function listOutputStyles(claudeConfigDir) {
|
|
19490
19416
|
const dir = stylesDir(claudeConfigDir);
|
|
19491
|
-
if (!
|
|
19417
|
+
if (!existsSync5(dir)) return [];
|
|
19492
19418
|
return readdirSync(dir).filter((f) => f.endsWith(".md")).map((f) => readStyle(claudeConfigDir, f.slice(0, -3))).filter((s) => !!s).sort((a, b) => a.name.localeCompare(b.name));
|
|
19493
19419
|
}
|
|
19494
19420
|
function assertNameFree(claudeConfigDir, name, exceptId) {
|
|
@@ -19501,7 +19427,7 @@ function createOutputStyle(claudeConfigDir, params) {
|
|
|
19501
19427
|
if (!id) throw new Error("name must contain letters or digits");
|
|
19502
19428
|
assertNameFree(claudeConfigDir, params.name);
|
|
19503
19429
|
const file = styleFile(claudeConfigDir, id);
|
|
19504
|
-
if (
|
|
19430
|
+
if (existsSync5(file) || BUILT_IN_OUTPUT_STYLES.some((s) => s.slug === id)) {
|
|
19505
19431
|
throw new OutputStyleConflictError(`an output style named "${params.name}" already exists`);
|
|
19506
19432
|
}
|
|
19507
19433
|
atomicWrite(file, serialize({ ...params, extra: [] }));
|
|
@@ -19509,7 +19435,7 @@ function createOutputStyle(claudeConfigDir, params) {
|
|
|
19509
19435
|
}
|
|
19510
19436
|
function updateOutputStyle(claudeConfigDir, id, patch) {
|
|
19511
19437
|
const file = styleFile(claudeConfigDir, id);
|
|
19512
|
-
if (!file || !
|
|
19438
|
+
if (!file || !existsSync5(file)) return null;
|
|
19513
19439
|
const current = parseStyle(readFileSync2(file, "utf8"), id);
|
|
19514
19440
|
if (patch.name !== void 0 && patch.name !== current.name) assertNameFree(claudeConfigDir, patch.name, id);
|
|
19515
19441
|
const next = { ...current, ...patch };
|
|
@@ -19521,7 +19447,7 @@ function updateOutputStyle(claudeConfigDir, id, patch) {
|
|
|
19521
19447
|
}
|
|
19522
19448
|
function deleteOutputStyle(claudeConfigDir, id) {
|
|
19523
19449
|
const file = styleFile(claudeConfigDir, id);
|
|
19524
|
-
if (!file || !
|
|
19450
|
+
if (!file || !existsSync5(file)) return false;
|
|
19525
19451
|
const name = parseStyle(readFileSync2(file, "utf8"), id).name;
|
|
19526
19452
|
rmSync(file);
|
|
19527
19453
|
if (readSettings(claudeConfigDir)["outputStyle"] === name) writeDefaultName(claudeConfigDir, void 0);
|
|
@@ -19532,7 +19458,7 @@ function settingsFile(claudeConfigDir) {
|
|
|
19532
19458
|
}
|
|
19533
19459
|
function readSettings(claudeConfigDir) {
|
|
19534
19460
|
const file = settingsFile(claudeConfigDir);
|
|
19535
|
-
if (!
|
|
19461
|
+
if (!existsSync5(file)) return {};
|
|
19536
19462
|
const parsed = JSON.parse(readFileSync2(file, "utf8"));
|
|
19537
19463
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
19538
19464
|
throw new Error(`${file} is not a JSON object`);
|
|
@@ -19976,13 +19902,13 @@ function getMaxDurationMs(streaming) {
|
|
|
19976
19902
|
}
|
|
19977
19903
|
function loadSystemPrompt() {
|
|
19978
19904
|
const customPath = paths.PROMPT_FILE;
|
|
19979
|
-
const defaultPath =
|
|
19980
|
-
const filePath =
|
|
19905
|
+
const defaultPath = resolve3(paths.PACKAGE_ROOT, "system.default.md");
|
|
19906
|
+
const filePath = existsSync6(customPath) ? customPath : defaultPath;
|
|
19981
19907
|
return readFileSync3(filePath, "utf-8").trim();
|
|
19982
19908
|
}
|
|
19983
19909
|
function loadPackagePrompt(file) {
|
|
19984
|
-
const filePath =
|
|
19985
|
-
if (!
|
|
19910
|
+
const filePath = resolve3(paths.PACKAGE_ROOT, file);
|
|
19911
|
+
if (!existsSync6(filePath)) return "";
|
|
19986
19912
|
return readFileSync3(filePath, "utf-8").trim();
|
|
19987
19913
|
}
|
|
19988
19914
|
function loadCapabilities(slackBound) {
|
|
@@ -20047,7 +19973,7 @@ function owningServiceLabel(env = process.env) {
|
|
|
20047
19973
|
return /^[A-Za-z0-9._-]+$/.test(label) ? label : void 0;
|
|
20048
19974
|
}
|
|
20049
19975
|
function buildHookSettings(runtime, builtInStyleName) {
|
|
20050
|
-
const guardScript = runtime === "container" ? `${CONTAINER_PATHS.hooks}/bash-guard.mjs` :
|
|
19976
|
+
const guardScript = runtime === "container" ? `${CONTAINER_PATHS.hooks}/bash-guard.mjs` : resolve3(paths.PACKAGE_ROOT, "hooks/bash-guard.mjs");
|
|
20051
19977
|
const selfLabel = runtime === "container" ? void 0 : owningServiceLabel();
|
|
20052
19978
|
const guardEnv = selfLabel ? `FLYSPACE_SELF_SERVICE_LABEL='${selfLabel}' ` : "";
|
|
20053
19979
|
return JSON.stringify({
|
|
@@ -20148,7 +20074,7 @@ function pinnedClaudeConfigDir(dir) {
|
|
|
20148
20074
|
return resolvePath(dir.replace(/^~(?=\/|$)/, homedir2())) === resolvePath(homedir2(), ".claude") ? void 0 : dir;
|
|
20149
20075
|
}
|
|
20150
20076
|
function runCli(prompt, cwd, botName, options, claudeConfigDir, resumeSessionId, claudeCodeOauthToken) {
|
|
20151
|
-
return new Promise((
|
|
20077
|
+
return new Promise((resolve7, reject) => {
|
|
20152
20078
|
const isolated = options.runtime === "container" || options.runtime === "sandbox";
|
|
20153
20079
|
const args = buildArgs(
|
|
20154
20080
|
prompt,
|
|
@@ -20330,7 +20256,7 @@ function runCli(prompt, cwd, botName, options, claudeConfigDir, resumeSessionId,
|
|
|
20330
20256
|
console.log(`[agent] stderr: ${stderr.trim()}`);
|
|
20331
20257
|
}
|
|
20332
20258
|
if (cancelled) {
|
|
20333
|
-
|
|
20259
|
+
resolve7({
|
|
20334
20260
|
sessionId: liveSessionId ?? resumeSessionId ?? "",
|
|
20335
20261
|
text: "",
|
|
20336
20262
|
isCancelled: true
|
|
@@ -20339,7 +20265,7 @@ function runCli(prompt, cwd, botName, options, claudeConfigDir, resumeSessionId,
|
|
|
20339
20265
|
}
|
|
20340
20266
|
if (timedOut) {
|
|
20341
20267
|
const text = timeoutKind === "wall-clock" && streaming ? `This task ran for over ${Math.round(maxDurationMs / 6e4)} minutes in total, so I was terminated as a runaway backstop. I was still making progress \u2014 the task is just too big for one turn. Consider splitting it into smaller steps, or continue and I'll pick up where I left off.` : `I got stuck for over ${Math.round((timeoutKind === "idle" ? idleTimeoutMs : maxDurationMs) / 6e4)} minutes with no activity and had to be terminated. Most likely cause: a Bash tool call to a long-running process (dev server, watcher, \`tail -f\`, etc.) that never exits. If you wanted to start a server, ask me to run it in the background (\`nohup ... > /tmp/log 2>&1 & disown\`) and I'll come back with the PID.`;
|
|
20342
|
-
|
|
20268
|
+
resolve7({
|
|
20343
20269
|
sessionId: liveSessionId ?? resumeSessionId ?? "",
|
|
20344
20270
|
text,
|
|
20345
20271
|
isError: true,
|
|
@@ -20377,7 +20303,7 @@ function runCli(prompt, cwd, botName, options, claudeConfigDir, resumeSessionId,
|
|
|
20377
20303
|
!!claudeCodeOauthToken
|
|
20378
20304
|
);
|
|
20379
20305
|
recordUsage2(response, options);
|
|
20380
|
-
|
|
20306
|
+
resolve7(
|
|
20381
20307
|
response.isError ? {
|
|
20382
20308
|
...response,
|
|
20383
20309
|
failure: {
|
|
@@ -20391,13 +20317,13 @@ function runCli(prompt, cwd, botName, options, claudeConfigDir, resumeSessionId,
|
|
|
20391
20317
|
);
|
|
20392
20318
|
} catch {
|
|
20393
20319
|
const fallback = onLine ? "" : stdout.trim();
|
|
20394
|
-
|
|
20320
|
+
resolve7({ sessionId: resumeSessionId ?? "", text: fallback || "No response" });
|
|
20395
20321
|
}
|
|
20396
20322
|
});
|
|
20397
20323
|
});
|
|
20398
20324
|
}
|
|
20399
20325
|
async function askClaude(prompt, cwd, botName, options, claudeConfigDir, resumeSessionId, claudeCodeOauthToken) {
|
|
20400
|
-
if (!
|
|
20326
|
+
if (!existsSync6(cwd) || !statSync2(cwd).isDirectory()) {
|
|
20401
20327
|
console.error(`[agent] working directory does not exist: ${cwd}`);
|
|
20402
20328
|
return {
|
|
20403
20329
|
sessionId: resumeSessionId ?? "",
|
|
@@ -21056,454 +20982,12 @@ async function runCompanion(config, userId, slot) {
|
|
|
21056
20982
|
}
|
|
21057
20983
|
|
|
21058
20984
|
// src/commands/persona.ts
|
|
21059
|
-
import { execFileSync as
|
|
20985
|
+
import { execFileSync as execFileSync4 } from "child_process";
|
|
21060
20986
|
import { createHash as createHash3 } from "crypto";
|
|
21061
|
-
import { existsSync as
|
|
20987
|
+
import { existsSync as existsSync7, mkdtempSync as mkdtempSync2, readdirSync as readdirSync2, readFileSync as readFileSync4, renameSync as renameSync2, rmSync as rmSync3, writeFileSync as writeFileSync3 } from "fs";
|
|
21062
20988
|
import { homedir as homedir3 } from "os";
|
|
21063
|
-
import { basename as basename2, join as
|
|
20989
|
+
import { basename as basename2, join as join6 } from "path";
|
|
21064
20990
|
import sharp from "sharp";
|
|
21065
|
-
|
|
21066
|
-
// src/auth/device-auth.ts
|
|
21067
|
-
import { createPrivateKey, createPublicKey, generateKeyPairSync, sign } from "crypto";
|
|
21068
|
-
import { existsSync as existsSync8, mkdirSync as mkdirSync5, readFileSync as readFileSync4, rmSync as rmSync3, writeFileSync as writeFileSync3 } from "fs";
|
|
21069
|
-
import { dirname, join as join6 } from "path";
|
|
21070
|
-
var DEFAULT_API_URL = "https://app.flyspace.ai";
|
|
21071
|
-
var EXPIRY_SKEW_MS = 6e4;
|
|
21072
|
-
var AuthApiError = class extends Error {
|
|
21073
|
-
constructor(message, status) {
|
|
21074
|
-
super(message);
|
|
21075
|
-
this.status = status;
|
|
21076
|
-
this.name = "AuthApiError";
|
|
21077
|
-
}
|
|
21078
|
-
};
|
|
21079
|
-
function apiUrl() {
|
|
21080
|
-
return (process.env["FLYSPACE_API_URL"] || DEFAULT_API_URL).replace(/\/+$/, "");
|
|
21081
|
-
}
|
|
21082
|
-
function deviceKeyPath() {
|
|
21083
|
-
return join6(paths.BASE_CONFIG_DIR, "device.key");
|
|
21084
|
-
}
|
|
21085
|
-
function credentialsPath() {
|
|
21086
|
-
return join6(paths.BASE_CONFIG_DIR, "credentials.json");
|
|
21087
|
-
}
|
|
21088
|
-
function ensureDeviceKey(path = deviceKeyPath()) {
|
|
21089
|
-
let created = false;
|
|
21090
|
-
if (!existsSync8(path)) {
|
|
21091
|
-
const { privateKey: privateKey2 } = generateKeyPairSync("ed25519");
|
|
21092
|
-
mkdirSync5(dirname(path), { recursive: true });
|
|
21093
|
-
writeFileSync3(path, privateKey2.export({ type: "pkcs8", format: "pem" }), { mode: 384 });
|
|
21094
|
-
created = true;
|
|
21095
|
-
}
|
|
21096
|
-
const privateKey = createPrivateKey(readFileSync4(path, "utf8"));
|
|
21097
|
-
const publicKeyBase64 = createPublicKey(privateKey).export({ type: "spki", format: "der" }).toString(
|
|
21098
|
-
"base64"
|
|
21099
|
-
);
|
|
21100
|
-
return { privateKey, publicKeyBase64, created };
|
|
21101
|
-
}
|
|
21102
|
-
function loadCredentials(path = credentialsPath()) {
|
|
21103
|
-
if (!existsSync8(path)) return null;
|
|
21104
|
-
try {
|
|
21105
|
-
return JSON.parse(readFileSync4(path, "utf8"));
|
|
21106
|
-
} catch {
|
|
21107
|
-
return null;
|
|
21108
|
-
}
|
|
21109
|
-
}
|
|
21110
|
-
function saveCredentials(creds, path = credentialsPath()) {
|
|
21111
|
-
mkdirSync5(dirname(path), { recursive: true });
|
|
21112
|
-
writeFileSync3(path, `${JSON.stringify(creds, null, 2)}
|
|
21113
|
-
`, { mode: 384 });
|
|
21114
|
-
}
|
|
21115
|
-
function clearLocalAuth() {
|
|
21116
|
-
rmSync3(credentialsPath(), { force: true });
|
|
21117
|
-
rmSync3(deviceKeyPath(), { force: true });
|
|
21118
|
-
}
|
|
21119
|
-
async function post(base, path, body, token) {
|
|
21120
|
-
return fetch(`${base}${path}`, {
|
|
21121
|
-
method: "POST",
|
|
21122
|
-
headers: {
|
|
21123
|
-
"content-type": "application/json",
|
|
21124
|
-
...token ? { authorization: `Bearer ${token}` } : {}
|
|
21125
|
-
},
|
|
21126
|
-
body: JSON.stringify(body)
|
|
21127
|
-
});
|
|
21128
|
-
}
|
|
21129
|
-
async function readJson(res) {
|
|
21130
|
-
try {
|
|
21131
|
-
return await res.json();
|
|
21132
|
-
} catch {
|
|
21133
|
-
return {};
|
|
21134
|
-
}
|
|
21135
|
-
}
|
|
21136
|
-
async function expectOk(res, what) {
|
|
21137
|
-
const json = await readJson(res);
|
|
21138
|
-
if (!res.ok) {
|
|
21139
|
-
const reason = typeof json["error"] === "string" ? json["error"] : res.statusText;
|
|
21140
|
-
throw new AuthApiError(`${what} failed (${res.status}): ${reason}`, res.status);
|
|
21141
|
-
}
|
|
21142
|
-
return json;
|
|
21143
|
-
}
|
|
21144
|
-
function toSlugs(value) {
|
|
21145
|
-
return Array.isArray(value) ? value.filter((v) => typeof v === "string") : [];
|
|
21146
|
-
}
|
|
21147
|
-
function toGrant(json) {
|
|
21148
|
-
const user = json["user"] ?? {};
|
|
21149
|
-
return {
|
|
21150
|
-
accessToken: String(json["access_token"]),
|
|
21151
|
-
expiresIn: Number(json["expires_in"]),
|
|
21152
|
-
deviceId: String(json["device_id"]),
|
|
21153
|
-
userEmail: String(user["email"] ?? ""),
|
|
21154
|
-
workspaces: toSlugs(json["workspaces"])
|
|
21155
|
-
};
|
|
21156
|
-
}
|
|
21157
|
-
async function requestDeviceCode(base, input) {
|
|
21158
|
-
const res = await post(base, "/api/auth/device/code", {
|
|
21159
|
-
public_key: input.publicKey,
|
|
21160
|
-
name: input.name,
|
|
21161
|
-
platform: input.platform
|
|
21162
|
-
});
|
|
21163
|
-
const json = await expectOk(res, "Requesting a device code");
|
|
21164
|
-
return {
|
|
21165
|
-
deviceCode: String(json["device_code"]),
|
|
21166
|
-
userCode: String(json["user_code"]),
|
|
21167
|
-
verificationUri: String(json["verification_uri"]),
|
|
21168
|
-
expiresIn: Number(json["expires_in"]),
|
|
21169
|
-
interval: Number(json["interval"] ?? 5)
|
|
21170
|
-
};
|
|
21171
|
-
}
|
|
21172
|
-
async function pollDeviceToken(base, deviceCode) {
|
|
21173
|
-
const res = await post(base, "/api/auth/device/token", { device_code: deviceCode });
|
|
21174
|
-
const json = await readJson(res);
|
|
21175
|
-
if (res.ok) return { status: "approved", grant: toGrant(json) };
|
|
21176
|
-
switch (json["error"]) {
|
|
21177
|
-
case "authorization_pending":
|
|
21178
|
-
return { status: "pending" };
|
|
21179
|
-
case "slow_down":
|
|
21180
|
-
return { status: "slow_down" };
|
|
21181
|
-
case "access_denied":
|
|
21182
|
-
return { status: "denied" };
|
|
21183
|
-
case "expired_token":
|
|
21184
|
-
return { status: "expired" };
|
|
21185
|
-
default:
|
|
21186
|
-
throw new AuthApiError(`Polling for approval failed (${res.status}): ${String(json["error"] ?? res.statusText)}`, res.status);
|
|
21187
|
-
}
|
|
21188
|
-
}
|
|
21189
|
-
async function refreshAccessToken(creds, privateKey) {
|
|
21190
|
-
const challenge = await expectOk(
|
|
21191
|
-
await post(creds.apiUrl, "/api/auth/device/challenge", { device_id: creds.deviceId }),
|
|
21192
|
-
"Requesting a refresh challenge"
|
|
21193
|
-
);
|
|
21194
|
-
const nonce = String(challenge["nonce"]);
|
|
21195
|
-
const signature = sign(null, Buffer.from(nonce), privateKey).toString("base64");
|
|
21196
|
-
const json = await expectOk(
|
|
21197
|
-
await post(creds.apiUrl, "/api/auth/device/refresh", { device_id: creds.deviceId, nonce, signature }),
|
|
21198
|
-
"Refreshing the access token"
|
|
21199
|
-
);
|
|
21200
|
-
return {
|
|
21201
|
-
...creds,
|
|
21202
|
-
accessToken: String(json["access_token"]),
|
|
21203
|
-
accessTokenExpiresAt: Date.now() + Number(json["expires_in"]) * 1e3
|
|
21204
|
-
};
|
|
21205
|
-
}
|
|
21206
|
-
async function fetchWhoAmI(base, token) {
|
|
21207
|
-
const res = await fetch(`${base}/api/auth/device/me`, { headers: { authorization: `Bearer ${token}` } });
|
|
21208
|
-
const json = await expectOk(res, "Checking the session");
|
|
21209
|
-
const user = json["user"] ?? {};
|
|
21210
|
-
const device = json["device"] ?? {};
|
|
21211
|
-
return {
|
|
21212
|
-
userEmail: String(user["email"] ?? ""),
|
|
21213
|
-
deviceId: String(device["id"] ?? ""),
|
|
21214
|
-
deviceName: String(device["name"] ?? ""),
|
|
21215
|
-
workspaces: toSlugs(json["workspaces"])
|
|
21216
|
-
};
|
|
21217
|
-
}
|
|
21218
|
-
async function boundWorkspaces() {
|
|
21219
|
-
const creds = loadCredentials();
|
|
21220
|
-
if (!creds) return null;
|
|
21221
|
-
try {
|
|
21222
|
-
const me = await fetchWhoAmI(creds.apiUrl, await getAccessToken());
|
|
21223
|
-
saveCredentials({ ...loadCredentials() ?? creds, workspaces: me.workspaces });
|
|
21224
|
-
return { workspaces: me.workspaces, fresh: true };
|
|
21225
|
-
} catch {
|
|
21226
|
-
return { workspaces: creds.workspaces ?? [], fresh: false };
|
|
21227
|
-
}
|
|
21228
|
-
}
|
|
21229
|
-
async function revokeDevice(base, token) {
|
|
21230
|
-
await expectOk(await post(base, "/api/auth/device/revoke", {}, token), "Revoking this device");
|
|
21231
|
-
}
|
|
21232
|
-
async function getAccessToken() {
|
|
21233
|
-
const fromEnv = process.env["FLYSPACE_TOKEN"];
|
|
21234
|
-
if (fromEnv) return fromEnv;
|
|
21235
|
-
const creds = loadCredentials();
|
|
21236
|
-
if (!creds) return null;
|
|
21237
|
-
if (creds.accessTokenExpiresAt - EXPIRY_SKEW_MS > Date.now()) return creds.accessToken;
|
|
21238
|
-
const { privateKey } = ensureDeviceKey();
|
|
21239
|
-
const refreshed = await refreshAccessToken(creds, privateKey);
|
|
21240
|
-
saveCredentials(refreshed);
|
|
21241
|
-
return refreshed.accessToken;
|
|
21242
|
-
}
|
|
21243
|
-
|
|
21244
|
-
// src/dashboard/host-db-client.ts
|
|
21245
|
-
import { createClient } from "@supabase/supabase-js";
|
|
21246
|
-
import { randomUUID as randomUUID2 } from "crypto";
|
|
21247
|
-
|
|
21248
|
-
// src/dashboard/host-lock.ts
|
|
21249
|
-
import { execFileSync as execFileSync4 } from "child_process";
|
|
21250
|
-
import { randomBytes } from "crypto";
|
|
21251
|
-
import { mkdirSync as mkdirSync6, readFileSync as readFileSync5, rmSync as rmSync4, writeFileSync as writeFileSync4 } from "fs";
|
|
21252
|
-
import { join as join7 } from "path";
|
|
21253
|
-
function hostLockPath() {
|
|
21254
|
-
return join7(paths.BASE_DATA_DIR, "host.lock");
|
|
21255
|
-
}
|
|
21256
|
-
function isLiveFlyspace(pid) {
|
|
21257
|
-
try {
|
|
21258
|
-
process.kill(pid, 0);
|
|
21259
|
-
const command = execFileSync4("ps", ["-p", String(pid), "-o", "command="], {
|
|
21260
|
-
encoding: "utf8"
|
|
21261
|
-
});
|
|
21262
|
-
return command.includes("flyspace") || command.includes("host-server");
|
|
21263
|
-
} catch {
|
|
21264
|
-
return false;
|
|
21265
|
-
}
|
|
21266
|
-
}
|
|
21267
|
-
function readLockPid(path) {
|
|
21268
|
-
try {
|
|
21269
|
-
const pid = Number(JSON.parse(readFileSync5(path, "utf8")).pid);
|
|
21270
|
-
return Number.isInteger(pid) && pid > 0 ? pid : null;
|
|
21271
|
-
} catch {
|
|
21272
|
-
return null;
|
|
21273
|
-
}
|
|
21274
|
-
}
|
|
21275
|
-
function acquireHostLock() {
|
|
21276
|
-
const path = hostLockPath();
|
|
21277
|
-
mkdirSync6(paths.BASE_DATA_DIR, { recursive: true });
|
|
21278
|
-
const body = JSON.stringify({
|
|
21279
|
-
pid: process.pid,
|
|
21280
|
-
startedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
21281
|
-
execPath: process.argv[1] ?? ""
|
|
21282
|
-
});
|
|
21283
|
-
for (let attempt = 0; attempt < 2; attempt++) {
|
|
21284
|
-
try {
|
|
21285
|
-
writeFileSync4(path, body, { flag: "wx", mode: 384 });
|
|
21286
|
-
const release = () => {
|
|
21287
|
-
if (readLockPid(path) === process.pid) rmSync4(path, { force: true });
|
|
21288
|
-
};
|
|
21289
|
-
process.once("exit", release);
|
|
21290
|
-
return release;
|
|
21291
|
-
} catch (err) {
|
|
21292
|
-
if (err.code !== "EEXIST") throw err;
|
|
21293
|
-
const holder = readLockPid(path);
|
|
21294
|
-
if (holder === process.pid) return () => {
|
|
21295
|
-
};
|
|
21296
|
-
if (holder && isLiveFlyspace(holder)) {
|
|
21297
|
-
throw new Error(
|
|
21298
|
-
`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.`
|
|
21299
|
-
);
|
|
21300
|
-
}
|
|
21301
|
-
rmSync4(path, { force: true });
|
|
21302
|
-
}
|
|
21303
|
-
}
|
|
21304
|
-
throw new Error(`Could not take the Host lock at ${path}`);
|
|
21305
|
-
}
|
|
21306
|
-
function publishHostEndpoint(port) {
|
|
21307
|
-
const path = hostLockPath();
|
|
21308
|
-
if (readLockPid(path) !== process.pid) return null;
|
|
21309
|
-
const token = randomBytes(32).toString("hex");
|
|
21310
|
-
const lock = JSON.parse(readFileSync5(path, "utf8"));
|
|
21311
|
-
writeFileSync4(path, JSON.stringify({ ...lock, port, token }), { mode: 384 });
|
|
21312
|
-
return token;
|
|
21313
|
-
}
|
|
21314
|
-
function readHostEndpoint() {
|
|
21315
|
-
try {
|
|
21316
|
-
const { pid, port, token } = JSON.parse(readFileSync5(hostLockPath(), "utf8"));
|
|
21317
|
-
if (pid === process.pid || !Number.isInteger(port) || typeof token !== "string") return null;
|
|
21318
|
-
return { port, token };
|
|
21319
|
-
} catch {
|
|
21320
|
-
return null;
|
|
21321
|
-
}
|
|
21322
|
-
}
|
|
21323
|
-
|
|
21324
|
-
// src/dashboard/host-db-client.ts
|
|
21325
|
-
var REQUEST_TIMEOUT_MS2 = 3e4;
|
|
21326
|
-
var pending = /* @__PURE__ */ new Map();
|
|
21327
|
-
var sender = null;
|
|
21328
|
-
var onSender = [];
|
|
21329
|
-
function setHostDbSender(fn) {
|
|
21330
|
-
sender = fn;
|
|
21331
|
-
if (!fn) return;
|
|
21332
|
-
const waiting = onSender;
|
|
21333
|
-
onSender = [];
|
|
21334
|
-
for (const wake of waiting) wake();
|
|
21335
|
-
}
|
|
21336
|
-
function sendAgentFailure(report) {
|
|
21337
|
-
sender?.({ type: "agent-failure", ...report });
|
|
21338
|
-
}
|
|
21339
|
-
function handleHostDbResult(id, res) {
|
|
21340
|
-
const p = pending.get(id);
|
|
21341
|
-
if (!p) return;
|
|
21342
|
-
pending.delete(id);
|
|
21343
|
-
clearTimeout(p.timer);
|
|
21344
|
-
p.resolve(res);
|
|
21345
|
-
}
|
|
21346
|
-
function whenConnected() {
|
|
21347
|
-
if (sender) return Promise.resolve(sender);
|
|
21348
|
-
return new Promise((resolve8, reject) => {
|
|
21349
|
-
const timer = setTimeout(() => {
|
|
21350
|
-
onSender = onSender.filter((w) => w !== wake);
|
|
21351
|
-
reject(new Error("Host is not connected to the Data API"));
|
|
21352
|
-
}, REQUEST_TIMEOUT_MS2);
|
|
21353
|
-
const wake = () => {
|
|
21354
|
-
clearTimeout(timer);
|
|
21355
|
-
resolve8(sender);
|
|
21356
|
-
};
|
|
21357
|
-
onSender.push(wake);
|
|
21358
|
-
});
|
|
21359
|
-
}
|
|
21360
|
-
async function requestHostDb(req) {
|
|
21361
|
-
const send = await whenConnected();
|
|
21362
|
-
const id = randomUUID2();
|
|
21363
|
-
return new Promise((resolve8, reject) => {
|
|
21364
|
-
const timer = setTimeout(() => {
|
|
21365
|
-
pending.delete(id);
|
|
21366
|
-
reject(new Error("Data API did not answer in time"));
|
|
21367
|
-
}, REQUEST_TIMEOUT_MS2);
|
|
21368
|
-
pending.set(id, { resolve: resolve8, reject, timer });
|
|
21369
|
-
send({ type: "db", id, req });
|
|
21370
|
-
});
|
|
21371
|
-
}
|
|
21372
|
-
var pendingUrls = /* @__PURE__ */ new Map();
|
|
21373
|
-
function handleAttachmentUrlResult(id, url) {
|
|
21374
|
-
pendingUrls.get(id)?.(url);
|
|
21375
|
-
pendingUrls.delete(id);
|
|
21376
|
-
}
|
|
21377
|
-
async function requestAttachmentUrl(key) {
|
|
21378
|
-
const send = await whenConnected();
|
|
21379
|
-
const id = randomUUID2();
|
|
21380
|
-
return new Promise((resolve8, reject) => {
|
|
21381
|
-
const timer = setTimeout(() => {
|
|
21382
|
-
pendingUrls.delete(id);
|
|
21383
|
-
reject(new Error("Data API did not answer in time"));
|
|
21384
|
-
}, REQUEST_TIMEOUT_MS2);
|
|
21385
|
-
pendingUrls.set(id, (url) => {
|
|
21386
|
-
clearTimeout(timer);
|
|
21387
|
-
resolve8(url);
|
|
21388
|
-
});
|
|
21389
|
-
send({ type: "attachment-url", id, key });
|
|
21390
|
-
});
|
|
21391
|
-
}
|
|
21392
|
-
var pendingSvgs = /* @__PURE__ */ new Map();
|
|
21393
|
-
function handlePluginSvgResult(id, url) {
|
|
21394
|
-
pendingSvgs.get(id)?.(url);
|
|
21395
|
-
pendingSvgs.delete(id);
|
|
21396
|
-
}
|
|
21397
|
-
async function requestPluginSvg(workspace, svg) {
|
|
21398
|
-
const send = await whenConnected();
|
|
21399
|
-
const id = randomUUID2();
|
|
21400
|
-
return new Promise((resolve8, reject) => {
|
|
21401
|
-
const timer = setTimeout(() => {
|
|
21402
|
-
pendingSvgs.delete(id);
|
|
21403
|
-
reject(new Error("Data API did not answer in time"));
|
|
21404
|
-
}, REQUEST_TIMEOUT_MS2);
|
|
21405
|
-
pendingSvgs.set(id, (url) => {
|
|
21406
|
-
clearTimeout(timer);
|
|
21407
|
-
resolve8(url);
|
|
21408
|
-
});
|
|
21409
|
-
send({ type: "plugin-svg", id, workspace, svg });
|
|
21410
|
-
});
|
|
21411
|
-
}
|
|
21412
|
-
var pendingRespond = /* @__PURE__ */ new Map();
|
|
21413
|
-
function handleShouldRespondResult(id, respond) {
|
|
21414
|
-
pendingRespond.get(id)?.(respond);
|
|
21415
|
-
pendingRespond.delete(id);
|
|
21416
|
-
}
|
|
21417
|
-
async function requestShouldRespond(transcript) {
|
|
21418
|
-
const send = await whenConnected().catch(() => null);
|
|
21419
|
-
if (!send) return false;
|
|
21420
|
-
const id = randomUUID2();
|
|
21421
|
-
return new Promise((resolve8) => {
|
|
21422
|
-
const timer = setTimeout(() => {
|
|
21423
|
-
pendingRespond.delete(id);
|
|
21424
|
-
resolve8(false);
|
|
21425
|
-
}, REQUEST_TIMEOUT_MS2);
|
|
21426
|
-
pendingRespond.set(id, (respond) => {
|
|
21427
|
-
clearTimeout(timer);
|
|
21428
|
-
resolve8(respond);
|
|
21429
|
-
});
|
|
21430
|
-
send({ type: "should-respond", id, transcript });
|
|
21431
|
-
});
|
|
21432
|
-
}
|
|
21433
|
-
var BODYLESS_STATUS = /* @__PURE__ */ new Set([101, 204, 205, 304]);
|
|
21434
|
-
function dbFetch(send) {
|
|
21435
|
-
return async (input, init) => {
|
|
21436
|
-
const req = new Request(input, init);
|
|
21437
|
-
const url = new URL(req.url);
|
|
21438
|
-
const method = req.method.toUpperCase();
|
|
21439
|
-
const res = await send({
|
|
21440
|
-
method,
|
|
21441
|
-
path: `${url.pathname}${url.search}`,
|
|
21442
|
-
headers: Object.fromEntries(req.headers.entries()),
|
|
21443
|
-
body: method === "GET" || method === "HEAD" ? void 0 : await req.text()
|
|
21444
|
-
});
|
|
21445
|
-
const noBody = method === "HEAD" || BODYLESS_STATUS.has(res.status);
|
|
21446
|
-
return new Response(noBody ? null : res.body, { status: res.status, headers: res.headers });
|
|
21447
|
-
};
|
|
21448
|
-
}
|
|
21449
|
-
var hostDbFetch = dbFetch(requestHostDb);
|
|
21450
|
-
var LOCAL_DB_PATH = "/internal/db";
|
|
21451
|
-
async function requestViaLocalHost(req) {
|
|
21452
|
-
const deadline = Date.now() + REQUEST_TIMEOUT_MS2;
|
|
21453
|
-
let endpoint = readHostEndpoint();
|
|
21454
|
-
while (!endpoint && Date.now() < deadline) {
|
|
21455
|
-
await new Promise((r) => setTimeout(r, 1e3));
|
|
21456
|
-
endpoint = readHostEndpoint();
|
|
21457
|
-
}
|
|
21458
|
-
if (!endpoint) throw new Error("No local Host to reach the Data API through");
|
|
21459
|
-
const res = await fetch(`http://127.0.0.1:${endpoint.port}${LOCAL_DB_PATH}`, {
|
|
21460
|
-
method: "POST",
|
|
21461
|
-
headers: { authorization: `Bearer ${endpoint.token}`, "content-type": "application/json" },
|
|
21462
|
-
body: JSON.stringify(req),
|
|
21463
|
-
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS2 + 5e3)
|
|
21464
|
-
});
|
|
21465
|
-
if (!res.ok) throw new Error(`Local Host DB relay answered ${res.status}`);
|
|
21466
|
-
return await res.json();
|
|
21467
|
-
}
|
|
21468
|
-
function relayChannel(topic) {
|
|
21469
|
-
const channel = {
|
|
21470
|
-
on: () => channel,
|
|
21471
|
-
subscribe: (callback) => {
|
|
21472
|
-
queueMicrotask(() => callback?.("SUBSCRIBED"));
|
|
21473
|
-
return channel;
|
|
21474
|
-
},
|
|
21475
|
-
send: async (msg) => {
|
|
21476
|
-
if (msg.type !== "broadcast" || !sender) return "error";
|
|
21477
|
-
sender({ type: "db-broadcast", topic, event: msg.event, payload: msg.payload ?? {} });
|
|
21478
|
-
return "ok";
|
|
21479
|
-
},
|
|
21480
|
-
unsubscribe: async () => "ok"
|
|
21481
|
-
};
|
|
21482
|
-
return channel;
|
|
21483
|
-
}
|
|
21484
|
-
function createHostDbClient(via = "socket") {
|
|
21485
|
-
const client = createClient("https://host-db.invalid", "host-device", {
|
|
21486
|
-
auth: { persistSession: false, autoRefreshToken: false },
|
|
21487
|
-
global: { fetch: via === "socket" ? hostDbFetch : dbFetch(requestViaLocalHost) }
|
|
21488
|
-
});
|
|
21489
|
-
return new Proxy(client, {
|
|
21490
|
-
get(target, prop) {
|
|
21491
|
-
if (prop === "channel") return relayChannel;
|
|
21492
|
-
if (prop === "removeChannel") return async () => "ok";
|
|
21493
|
-
const value = Reflect.get(target, prop, target);
|
|
21494
|
-
return typeof value === "function" ? value.bind(target) : value;
|
|
21495
|
-
}
|
|
21496
|
-
});
|
|
21497
|
-
}
|
|
21498
|
-
|
|
21499
|
-
// src/commands/supabase-via-host.ts
|
|
21500
|
-
function useHostDbWithoutCredentials() {
|
|
21501
|
-
const viaHost = !!loadCredentials() && (!hasSupabaseCredentials() || !!readHostEndpoint());
|
|
21502
|
-
if (viaHost) setSupabaseClient(createHostDbClient("local-host"));
|
|
21503
|
-
return viaHost;
|
|
21504
|
-
}
|
|
21505
|
-
|
|
21506
|
-
// src/commands/persona.ts
|
|
21507
20991
|
var USAGE = `
|
|
21508
20992
|
Usage: flyspace persona avatars [--character <id>] [--clear]
|
|
21509
20993
|
|
|
@@ -21534,34 +21018,34 @@ var PACKS = {
|
|
|
21534
21018
|
}
|
|
21535
21019
|
};
|
|
21536
21020
|
function pluginInstalled() {
|
|
21537
|
-
const claudeDir = process.env["CLAUDE_CONFIG_DIR"] ||
|
|
21538
|
-
return
|
|
21021
|
+
const claudeDir = process.env["CLAUDE_CONFIG_DIR"] || join6(homedir3(), ".claude");
|
|
21022
|
+
return existsSync7(join6(claudeDir, "plugins", "cache", "claudecafe", "persona-panel"));
|
|
21539
21023
|
}
|
|
21540
21024
|
function installPack(root, character) {
|
|
21541
21025
|
const pack = PACKS[character];
|
|
21542
21026
|
if (!pack) throw new Error(`No published pack for "${character}".`);
|
|
21543
|
-
const charactersDir =
|
|
21544
|
-
|
|
21545
|
-
const staging = mkdtempSync2(
|
|
21027
|
+
const charactersDir = join6(root, "characters");
|
|
21028
|
+
execFileSync4("mkdir", ["-p", charactersDir]);
|
|
21029
|
+
const staging = mkdtempSync2(join6(charactersDir, `.${character}-`));
|
|
21546
21030
|
try {
|
|
21547
|
-
const zip =
|
|
21548
|
-
|
|
21549
|
-
const digest = createHash3("sha256").update(
|
|
21031
|
+
const zip = join6(staging, "pack.zip");
|
|
21032
|
+
execFileSync4("curl", ["-fsSL", "--max-time", "60", "-o", zip, pack.url]);
|
|
21033
|
+
const digest = createHash3("sha256").update(readFileSync4(zip)).digest("hex");
|
|
21550
21034
|
if (digest !== pack.sha256) throw new Error(`${character} pack SHA-256 mismatch`);
|
|
21551
|
-
|
|
21552
|
-
const folder =
|
|
21553
|
-
if (
|
|
21554
|
-
renameSync2(
|
|
21035
|
+
execFileSync4("unzip", ["-q", zip, "-d", staging]);
|
|
21036
|
+
const folder = join6(charactersDir, character);
|
|
21037
|
+
if (existsSync7(folder)) renameSync2(folder, join6(staging, "previous"));
|
|
21038
|
+
renameSync2(join6(staging, character), folder);
|
|
21555
21039
|
} finally {
|
|
21556
|
-
|
|
21040
|
+
rmSync3(staging, { recursive: true, force: true });
|
|
21557
21041
|
}
|
|
21558
21042
|
}
|
|
21559
21043
|
function cafeRoot() {
|
|
21560
|
-
return
|
|
21044
|
+
return join6(process.env["XDG_CONFIG_HOME"] || join6(homedir3(), ".config"), "claudecafe");
|
|
21561
21045
|
}
|
|
21562
21046
|
function configuredCharacter(root) {
|
|
21563
21047
|
try {
|
|
21564
|
-
const config = JSON.parse(
|
|
21048
|
+
const config = JSON.parse(readFileSync4(join6(root, "config.json"), "utf8"));
|
|
21565
21049
|
if (config.character && config.character !== "none") return config.character;
|
|
21566
21050
|
} catch {
|
|
21567
21051
|
}
|
|
@@ -21588,11 +21072,11 @@ var DEFAULT_BOT_NAMES = /* @__PURE__ */ new Set(["Bot", "Workspace Agent"]);
|
|
|
21588
21072
|
async function syncPersonaAvatars(profile, requested) {
|
|
21589
21073
|
const root = cafeRoot();
|
|
21590
21074
|
const character = requested || configuredCharacter(root);
|
|
21591
|
-
const dir =
|
|
21592
|
-
if (!
|
|
21075
|
+
const dir = join6(root, "characters", character, "avatars");
|
|
21076
|
+
if (!existsSync7(dir)) installPack(root, character);
|
|
21593
21077
|
const avatars = {};
|
|
21594
21078
|
for (const file of readdirSync2(dir).filter((f) => f.endsWith(".webp"))) {
|
|
21595
|
-
const image = await sharp(
|
|
21079
|
+
const image = await sharp(join6(dir, file)).resize({ width: AVATAR_SIZE, height: AVATAR_SIZE, fit: "cover", position: "top" }).webp({ quality: 80 }).toBuffer();
|
|
21596
21080
|
avatars[basename2(file, ".webp")] = `data:image/webp;base64,${image.toString("base64")}`;
|
|
21597
21081
|
}
|
|
21598
21082
|
if (!Object.keys(avatars).length) throw new Error(`No .webp avatars in ${dir}.`);
|
|
@@ -21610,14 +21094,14 @@ async function autoSyncPersonaAvatars(profile) {
|
|
|
21610
21094
|
const root = cafeRoot();
|
|
21611
21095
|
const character = configuredCharacter(root);
|
|
21612
21096
|
const stamp = `${character}@${PACKS[character]?.version ?? "local"}`;
|
|
21613
|
-
const marker =
|
|
21097
|
+
const marker = join6(root, `.flyspace-avatars-${profile}`);
|
|
21614
21098
|
try {
|
|
21615
|
-
if (
|
|
21099
|
+
if (readFileSync4(marker, "utf8") === stamp) return;
|
|
21616
21100
|
} catch {
|
|
21617
21101
|
}
|
|
21618
21102
|
try {
|
|
21619
21103
|
const { count } = await syncPersonaAvatars(profile, character);
|
|
21620
|
-
|
|
21104
|
+
writeFileSync3(marker, stamp);
|
|
21621
21105
|
console.log(`[persona] synced ${count} ${character} avatars`);
|
|
21622
21106
|
} catch (err) {
|
|
21623
21107
|
console.warn(`[persona] avatar sync skipped: ${err.message}`);
|
|
@@ -22074,24 +21558,24 @@ async function loadAgentMemory(profile, channelId, opts = {}) {
|
|
|
22074
21558
|
async function buildPrompt(profile, channelId, opts) {
|
|
22075
21559
|
const workspace = await getWorkspaceBySlug(profile);
|
|
22076
21560
|
const handle = opts.senderHandle?.toLowerCase();
|
|
22077
|
-
const
|
|
21561
|
+
const sender = workspace && handle ? (await listMemberships(workspace.id)).find(
|
|
22078
21562
|
(m) => m.userId && m.handle.toLowerCase() === handle
|
|
22079
21563
|
) : void 0;
|
|
22080
21564
|
const [channel, shared, own] = await Promise.all([
|
|
22081
21565
|
listMemories({ scope: "channel", channelId }),
|
|
22082
21566
|
workspace ? listMemories({ scope: "workspace", workspaceId: workspace.id }) : [],
|
|
22083
|
-
workspace &&
|
|
21567
|
+
workspace && sender ? listMemories({ scope: "user", workspaceId: workspace.id, userId: sender.userId }) : []
|
|
22084
21568
|
]);
|
|
22085
21569
|
const extras = {
|
|
22086
21570
|
workspace: shared,
|
|
22087
|
-
...
|
|
21571
|
+
...sender ? { user: { userId: sender.userId, handle: sender.handle, memories: own } } : {}
|
|
22088
21572
|
};
|
|
22089
21573
|
return formatMemoryPrompt(channelId, channel, extras);
|
|
22090
21574
|
}
|
|
22091
21575
|
|
|
22092
21576
|
// src/dashboard/settings-host.ts
|
|
22093
|
-
import { writeFileSync as
|
|
22094
|
-
import { dirname
|
|
21577
|
+
import { writeFileSync as writeFileSync4, existsSync as existsSync8, mkdirSync as mkdirSync5, readFileSync as readFileSync5, rmSync as rmSync4 } from "fs";
|
|
21578
|
+
import { dirname } from "path";
|
|
22095
21579
|
|
|
22096
21580
|
// ../api/src/dashboard/auto-title.ts
|
|
22097
21581
|
var GROQ_API_URL = "https://api.groq.com/openai/v1/chat/completions";
|
|
@@ -22252,9 +21736,9 @@ function parseAgentProfiles(raw) {
|
|
|
22252
21736
|
return entries2.length > 0 ? Object.fromEntries(entries2) : void 0;
|
|
22253
21737
|
}
|
|
22254
21738
|
function loadDashboardSettings() {
|
|
22255
|
-
if (!
|
|
21739
|
+
if (!existsSync8(paths.DASHBOARD_SETTINGS_FILE)) return localDefaults();
|
|
22256
21740
|
try {
|
|
22257
|
-
const raw = JSON.parse(
|
|
21741
|
+
const raw = JSON.parse(readFileSync5(paths.DASHBOARD_SETTINGS_FILE, "utf-8"));
|
|
22258
21742
|
const providers = parseProviders(raw.providers, {
|
|
22259
21743
|
agent: normalizeDefaultModel(raw.agent, localDefaults().agent),
|
|
22260
21744
|
fallbackModel: typeof raw.fallbackModel === "string" && isAllowedModel(raw.fallbackModel) ? raw.fallbackModel : void 0
|
|
@@ -22281,9 +21765,9 @@ function withFallbackModel(providers, model) {
|
|
|
22281
21765
|
return [cleared[0], { runner, model }, ...cleared.slice(1).filter((p) => p.runner !== runner)];
|
|
22282
21766
|
}
|
|
22283
21767
|
function writeSettings(next) {
|
|
22284
|
-
|
|
21768
|
+
mkdirSync5(dirname(paths.DASHBOARD_SETTINGS_FILE), { recursive: true });
|
|
22285
21769
|
const merged = { ...readSettingsFile() ?? {}, ...next };
|
|
22286
|
-
|
|
21770
|
+
writeFileSync4(paths.DASHBOARD_SETTINGS_FILE, JSON.stringify(merged, null, 2), "utf-8");
|
|
22287
21771
|
return next;
|
|
22288
21772
|
}
|
|
22289
21773
|
function saveDashboardSettings(patch) {
|
|
@@ -22317,13 +21801,13 @@ async function loadFullDashboardSettings(profile = getProfile()) {
|
|
|
22317
21801
|
function saveWorkspacePrompt(prompt) {
|
|
22318
21802
|
const trimmed = prompt.trim();
|
|
22319
21803
|
if (!trimmed || trimmed === loadWorkspacePrompt().defaultPrompt) return resetWorkspacePrompt();
|
|
22320
|
-
|
|
22321
|
-
|
|
21804
|
+
mkdirSync5(dirname(paths.PROMPT_FILE), { recursive: true });
|
|
21805
|
+
writeFileSync4(paths.PROMPT_FILE, `${trimmed}
|
|
22322
21806
|
`, "utf-8");
|
|
22323
21807
|
return loadWorkspacePrompt();
|
|
22324
21808
|
}
|
|
22325
21809
|
function resetWorkspacePrompt() {
|
|
22326
|
-
|
|
21810
|
+
rmSync4(paths.PROMPT_FILE, { force: true });
|
|
22327
21811
|
return loadWorkspacePrompt();
|
|
22328
21812
|
}
|
|
22329
21813
|
function saveAgentProfile(name, patch) {
|
|
@@ -22348,9 +21832,9 @@ function saveAgentProfile(name, patch) {
|
|
|
22348
21832
|
|
|
22349
21833
|
// ../api/src/codex/agent.ts
|
|
22350
21834
|
import { spawn as spawn2 } from "child_process";
|
|
22351
|
-
import { existsSync as
|
|
21835
|
+
import { existsSync as existsSync9, mkdtempSync as mkdtempSync3, readFileSync as readFileSync6, rmSync as rmSync5, statSync as statSync3 } from "fs";
|
|
22352
21836
|
import { tmpdir as tmpdir2 } from "os";
|
|
22353
|
-
import { join as
|
|
21837
|
+
import { join as join7 } from "path";
|
|
22354
21838
|
var AUTH_ERROR_PATTERNS2 = [
|
|
22355
21839
|
/401 unauthorized/i,
|
|
22356
21840
|
/missing bearer or basic authentication/i,
|
|
@@ -22481,8 +21965,8 @@ function getMaxDurationMs2() {
|
|
|
22481
21965
|
}
|
|
22482
21966
|
function codexAuthAvailable(env = process.env) {
|
|
22483
21967
|
if (env["OPENAI_API_KEY"]?.trim()) return true;
|
|
22484
|
-
const home = env["CODEX_HOME"]?.trim() ||
|
|
22485
|
-
return
|
|
21968
|
+
const home = env["CODEX_HOME"]?.trim() || join7(env["HOME"] ?? "", ".codex");
|
|
21969
|
+
return existsSync9(join7(home, "auth.json"));
|
|
22486
21970
|
}
|
|
22487
21971
|
function applySystemPrompt(prompt, options, resumeSessionId) {
|
|
22488
21972
|
if (resumeSessionId || !options.systemPrompt?.trim()) return prompt;
|
|
@@ -22531,13 +22015,13 @@ function recordCodexUsage(response, options) {
|
|
|
22531
22015
|
});
|
|
22532
22016
|
}
|
|
22533
22017
|
function runCodexCli(prompt, cwd, options, resumeSessionId) {
|
|
22534
|
-
return new Promise((
|
|
22018
|
+
return new Promise((resolve7, reject) => {
|
|
22535
22019
|
const finish = (response) => {
|
|
22536
22020
|
recordCodexUsage(response, options);
|
|
22537
|
-
|
|
22021
|
+
resolve7(response);
|
|
22538
22022
|
};
|
|
22539
|
-
const scratch = mkdtempSync3(
|
|
22540
|
-
const lastMessageFile =
|
|
22023
|
+
const scratch = mkdtempSync3(join7(tmpdir2(), "flyspace-codex-"));
|
|
22024
|
+
const lastMessageFile = join7(scratch, "last-message.txt");
|
|
22541
22025
|
const args = buildArgs2(prompt, options, lastMessageFile, resumeSessionId);
|
|
22542
22026
|
console.log(`[codex] spawning codex CLI in ${cwd}`);
|
|
22543
22027
|
console.log(`[codex] args: ${args.slice(0, -1).join(" ")}`);
|
|
@@ -22550,7 +22034,7 @@ function runCodexCli(prompt, cwd, options, resumeSessionId) {
|
|
|
22550
22034
|
let stderr = "";
|
|
22551
22035
|
let timedOut = false;
|
|
22552
22036
|
let cancelled = false;
|
|
22553
|
-
let
|
|
22037
|
+
let pending = "";
|
|
22554
22038
|
const seenItemIds = /* @__PURE__ */ new Set();
|
|
22555
22039
|
const onActivity = options.onActivity;
|
|
22556
22040
|
const consumeLine = (raw) => {
|
|
@@ -22607,7 +22091,7 @@ function runCodexCli(prompt, cwd, options, resumeSessionId) {
|
|
|
22607
22091
|
const cleanup = () => {
|
|
22608
22092
|
clearTimeout(timeoutHandle);
|
|
22609
22093
|
if (signal) signal.removeEventListener("abort", onAbort);
|
|
22610
|
-
|
|
22094
|
+
rmSync5(scratch, { recursive: true, force: true });
|
|
22611
22095
|
};
|
|
22612
22096
|
child.stdout.setEncoding("utf8");
|
|
22613
22097
|
child.stderr.setEncoding("utf8");
|
|
@@ -22615,9 +22099,9 @@ function runCodexCli(prompt, cwd, options, resumeSessionId) {
|
|
|
22615
22099
|
const chunk = data.toString();
|
|
22616
22100
|
stdout += chunk;
|
|
22617
22101
|
if (!onActivity) return;
|
|
22618
|
-
|
|
22619
|
-
const lines =
|
|
22620
|
-
|
|
22102
|
+
pending += chunk;
|
|
22103
|
+
const lines = pending.split("\n");
|
|
22104
|
+
pending = lines.pop() ?? "";
|
|
22621
22105
|
for (const line of lines) consumeLine(line);
|
|
22622
22106
|
});
|
|
22623
22107
|
child.stderr.on("data", (data) => {
|
|
@@ -22636,7 +22120,7 @@ function runCodexCli(prompt, cwd, options, resumeSessionId) {
|
|
|
22636
22120
|
child.on("close", (code, signal2) => {
|
|
22637
22121
|
let lastMessage = "";
|
|
22638
22122
|
try {
|
|
22639
|
-
lastMessage =
|
|
22123
|
+
lastMessage = readFileSync6(lastMessageFile, "utf8").trim();
|
|
22640
22124
|
} catch {
|
|
22641
22125
|
lastMessage = "";
|
|
22642
22126
|
}
|
|
@@ -22690,7 +22174,7 @@ function runCodexCli(prompt, cwd, options, resumeSessionId) {
|
|
|
22690
22174
|
});
|
|
22691
22175
|
}
|
|
22692
22176
|
async function askCodex(prompt, cwd, options = {}, resumeSessionId) {
|
|
22693
|
-
if (!
|
|
22177
|
+
if (!existsSync9(cwd) || !statSync3(cwd).isDirectory()) {
|
|
22694
22178
|
console.error(`[codex] working directory does not exist: ${cwd}`);
|
|
22695
22179
|
return {
|
|
22696
22180
|
sessionId: resumeSessionId ?? "",
|
|
@@ -22951,11 +22435,11 @@ function walkBlock(token, out) {
|
|
|
22951
22435
|
}
|
|
22952
22436
|
function walkList(list, indent, out) {
|
|
22953
22437
|
const style = list.ordered ? "ordered" : "bullet";
|
|
22954
|
-
let
|
|
22438
|
+
let pending = [];
|
|
22955
22439
|
const flush2 = () => {
|
|
22956
|
-
if (
|
|
22957
|
-
out.push({ type: "rich_text_list", style, indent, elements:
|
|
22958
|
-
|
|
22440
|
+
if (pending.length > 0) {
|
|
22441
|
+
out.push({ type: "rich_text_list", style, indent, elements: pending });
|
|
22442
|
+
pending = [];
|
|
22959
22443
|
}
|
|
22960
22444
|
};
|
|
22961
22445
|
for (const item of list.items) {
|
|
@@ -22979,7 +22463,7 @@ function walkList(list, indent, out) {
|
|
|
22979
22463
|
}
|
|
22980
22464
|
}
|
|
22981
22465
|
}
|
|
22982
|
-
|
|
22466
|
+
pending.push({
|
|
22983
22467
|
type: "rich_text_section",
|
|
22984
22468
|
elements: inline.length > 0 ? mergeAdjacentText(inline) : [{ type: "text", text: "" }]
|
|
22985
22469
|
});
|
|
@@ -23143,7 +22627,7 @@ function renderAsciiTable(t) {
|
|
|
23143
22627
|
}
|
|
23144
22628
|
|
|
23145
22629
|
// src/store/channel-cache.ts
|
|
23146
|
-
import { mkdirSync as
|
|
22630
|
+
import { mkdirSync as mkdirSync6 } from "fs";
|
|
23147
22631
|
|
|
23148
22632
|
// src/store/sqlite.ts
|
|
23149
22633
|
import Database from "better-sqlite3";
|
|
@@ -23167,7 +22651,7 @@ function getDb() {
|
|
|
23167
22651
|
const file = paths.DB_FILE;
|
|
23168
22652
|
const existing = dbs.get(file);
|
|
23169
22653
|
if (existing) return existing;
|
|
23170
|
-
|
|
22654
|
+
mkdirSync6(paths.DATA_DIR, { recursive: true });
|
|
23171
22655
|
const db = openLocalDatabase(file);
|
|
23172
22656
|
if (!db) return null;
|
|
23173
22657
|
db.exec(`
|
|
@@ -23382,7 +22866,7 @@ var DEFAULT_TIMEOUT_MS = 12e4;
|
|
|
23382
22866
|
var KILL_GRACE_MS3 = 5e3;
|
|
23383
22867
|
function runScriptAutomation(opts) {
|
|
23384
22868
|
const { name, script, cwd, timeoutMs = DEFAULT_TIMEOUT_MS } = opts;
|
|
23385
|
-
return new Promise((
|
|
22869
|
+
return new Promise((resolve7, reject) => {
|
|
23386
22870
|
const child = spawn3("/bin/bash", [script], { cwd, env: resolveMiseEnv(cwd), stdio: ["ignore", "pipe", "pipe"] });
|
|
23387
22871
|
let stdout = "";
|
|
23388
22872
|
let stderr = "";
|
|
@@ -23417,7 +22901,7 @@ function runScriptAutomation(opts) {
|
|
|
23417
22901
|
} else if (code !== 0) {
|
|
23418
22902
|
reject(new Error(`script exited with code ${code}: ${stderr.trim()}`));
|
|
23419
22903
|
} else {
|
|
23420
|
-
|
|
22904
|
+
resolve7();
|
|
23421
22905
|
}
|
|
23422
22906
|
});
|
|
23423
22907
|
});
|
|
@@ -23683,17 +23167,17 @@ var TriggerEngine = class {
|
|
|
23683
23167
|
};
|
|
23684
23168
|
|
|
23685
23169
|
// src/store/user-cache.ts
|
|
23686
|
-
import { existsSync as
|
|
23687
|
-
import { join as
|
|
23170
|
+
import { existsSync as existsSync10, readFileSync as readFileSync7 } from "fs";
|
|
23171
|
+
import { join as join8 } from "path";
|
|
23688
23172
|
function jsonUserCachePath() {
|
|
23689
|
-
const file =
|
|
23690
|
-
return
|
|
23173
|
+
const file = join8(paths.CONFIG_DIR, "slack_users.json");
|
|
23174
|
+
return existsSync10(file) ? file : void 0;
|
|
23691
23175
|
}
|
|
23692
23176
|
function readJsonUserCache() {
|
|
23693
23177
|
const file = jsonUserCachePath();
|
|
23694
23178
|
if (!file) return void 0;
|
|
23695
23179
|
try {
|
|
23696
|
-
const parsed = JSON.parse(
|
|
23180
|
+
const parsed = JSON.parse(readFileSync7(file, "utf8"));
|
|
23697
23181
|
return parsed.users;
|
|
23698
23182
|
} catch {
|
|
23699
23183
|
return void 0;
|
|
@@ -24085,8 +23569,8 @@ var MessageQueue = class {
|
|
|
24085
23569
|
const chains = Array.from(this.chains.values());
|
|
24086
23570
|
if (chains.length === 0) return true;
|
|
24087
23571
|
let timer;
|
|
24088
|
-
const timeout = new Promise((
|
|
24089
|
-
timer = setTimeout(() =>
|
|
23572
|
+
const timeout = new Promise((resolve7) => {
|
|
23573
|
+
timer = setTimeout(() => resolve7(false), timeoutMs);
|
|
24090
23574
|
});
|
|
24091
23575
|
const done = Promise.all(chains).then(() => true);
|
|
24092
23576
|
const result = await Promise.race([done, timeout]);
|
|
@@ -24100,7 +23584,7 @@ var MessageQueue = class {
|
|
|
24100
23584
|
|
|
24101
23585
|
// src/slack/file-downloader.ts
|
|
24102
23586
|
import { writeFile } from "fs/promises";
|
|
24103
|
-
import { join as
|
|
23587
|
+
import { join as join9, extname } from "path";
|
|
24104
23588
|
var debug3 = process.env["DEBUG"] === "true";
|
|
24105
23589
|
var SUPPORTED_IMAGE_MIMETYPES = /* @__PURE__ */ new Set([
|
|
24106
23590
|
"image/png",
|
|
@@ -24200,7 +23684,7 @@ async function downloadOne(file, botToken) {
|
|
|
24200
23684
|
const ext = extname(originalName) || `.${file.filetype ?? "bin"}`;
|
|
24201
23685
|
const safeName = sanitizeFilename(originalName.replace(ext, ""));
|
|
24202
23686
|
const filename = `${Date.now()}-${file.id ?? "unnamed"}-${safeName}${ext}`;
|
|
24203
|
-
const localPath =
|
|
23687
|
+
const localPath = join9(paths.UPLOADS_DIR, filename);
|
|
24204
23688
|
await writeFile(localPath, buffer);
|
|
24205
23689
|
if (debug3)
|
|
24206
23690
|
console.log(`[file-downloader] saved ${file.id} -> ${localPath} (${buffer.length} bytes)`);
|
|
@@ -24652,12 +24136,12 @@ import { homedir as homedir8 } from "os";
|
|
|
24652
24136
|
import { stripVTControlCharacters } from "util";
|
|
24653
24137
|
|
|
24654
24138
|
// src/mcp/config.ts
|
|
24655
|
-
import { mkdtempSync as mkdtempSync4, rmSync as
|
|
24139
|
+
import { mkdtempSync as mkdtempSync4, rmSync as rmSync6, writeFileSync as writeFileSync5 } from "fs";
|
|
24656
24140
|
import { tmpdir as tmpdir3 } from "os";
|
|
24657
|
-
import { join as
|
|
24141
|
+
import { join as join10 } from "path";
|
|
24658
24142
|
|
|
24659
24143
|
// ../api/src/mcp/crypto.ts
|
|
24660
|
-
import { createCipheriv, createDecipheriv, randomBytes
|
|
24144
|
+
import { createCipheriv, createDecipheriv, randomBytes, timingSafeEqual } from "crypto";
|
|
24661
24145
|
var ALGORITHM = "aes-256-gcm";
|
|
24662
24146
|
var KEY_BYTES = 32;
|
|
24663
24147
|
var IV_BYTES = 12;
|
|
@@ -24690,7 +24174,7 @@ function currentKeyVersion() {
|
|
|
24690
24174
|
);
|
|
24691
24175
|
}
|
|
24692
24176
|
function encrypt(key, purpose, plaintext) {
|
|
24693
|
-
const iv =
|
|
24177
|
+
const iv = randomBytes(IV_BYTES);
|
|
24694
24178
|
const cipher = createCipheriv(ALGORITHM, key, iv);
|
|
24695
24179
|
cipher.setAAD(Buffer.from(purpose, "utf8"));
|
|
24696
24180
|
const ciphertext = Buffer.concat([cipher.update(plaintext, "utf8"), cipher.final()]);
|
|
@@ -24710,7 +24194,7 @@ function decrypt(key, purpose, blob) {
|
|
|
24710
24194
|
}
|
|
24711
24195
|
function createEnvelope() {
|
|
24712
24196
|
const keyVersion = currentKeyVersion();
|
|
24713
|
-
const key =
|
|
24197
|
+
const key = randomBytes(KEY_BYTES);
|
|
24714
24198
|
const wrappedDek = encrypt(
|
|
24715
24199
|
readMasterKey(keyVersion),
|
|
24716
24200
|
purposeForDek(keyVersion),
|
|
@@ -24776,7 +24260,7 @@ function secretsMatch(a, b) {
|
|
|
24776
24260
|
}
|
|
24777
24261
|
|
|
24778
24262
|
// ../api/src/mcp/oauth.ts
|
|
24779
|
-
import { createHash as createHash4, randomBytes as
|
|
24263
|
+
import { createHash as createHash4, randomBytes as randomBytes2 } from "crypto";
|
|
24780
24264
|
var RESERVED_AUTHORIZE_PARAMS = /* @__PURE__ */ new Set([
|
|
24781
24265
|
"client_id",
|
|
24782
24266
|
"redirect_uri",
|
|
@@ -24790,10 +24274,10 @@ function base64url(buffer) {
|
|
|
24790
24274
|
return buffer.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
24791
24275
|
}
|
|
24792
24276
|
function createStateToken() {
|
|
24793
|
-
return base64url(
|
|
24277
|
+
return base64url(randomBytes2(32));
|
|
24794
24278
|
}
|
|
24795
24279
|
function createPkcePair() {
|
|
24796
|
-
const verifier = base64url(
|
|
24280
|
+
const verifier = base64url(randomBytes2(32));
|
|
24797
24281
|
const challenge = base64url(createHash4("sha256").update(verifier).digest());
|
|
24798
24282
|
return { verifier, challenge };
|
|
24799
24283
|
}
|
|
@@ -24914,7 +24398,7 @@ async function exchangeCode(params) {
|
|
|
24914
24398
|
);
|
|
24915
24399
|
return { ...tokens, scopes: tokens.scopes.length ? tokens.scopes : provider.defaultScopes };
|
|
24916
24400
|
}
|
|
24917
|
-
async function
|
|
24401
|
+
async function refreshAccessToken(params) {
|
|
24918
24402
|
const { provider, client, refreshToken } = params;
|
|
24919
24403
|
return requestToken(
|
|
24920
24404
|
provider,
|
|
@@ -25163,7 +24647,7 @@ function needsRefresh(expiresAt, now = Date.now()) {
|
|
|
25163
24647
|
if (!expiresAt) return false;
|
|
25164
24648
|
return new Date(expiresAt).getTime() - now < REFRESH_SKEW_MS;
|
|
25165
24649
|
}
|
|
25166
|
-
var sleep = (ms) => new Promise((
|
|
24650
|
+
var sleep = (ms) => new Promise((resolve7) => setTimeout(resolve7, ms));
|
|
25167
24651
|
async function refreshConnection(params) {
|
|
25168
24652
|
const { workspaceId, connection, provider } = params;
|
|
25169
24653
|
const deps = params.deps ?? {};
|
|
@@ -25200,7 +24684,7 @@ async function renew(workspaceId, connection, provider, deps) {
|
|
|
25200
24684
|
}
|
|
25201
24685
|
let tokens;
|
|
25202
24686
|
try {
|
|
25203
|
-
tokens = await
|
|
24687
|
+
tokens = await refreshAccessToken({
|
|
25204
24688
|
provider,
|
|
25205
24689
|
client: readOAuthClient(provider.slug),
|
|
25206
24690
|
refreshToken,
|
|
@@ -25340,12 +24824,12 @@ async function buildMcpConfig(profile, connectionIds) {
|
|
|
25340
24824
|
return { config, skipped };
|
|
25341
24825
|
}
|
|
25342
24826
|
function writeMcpConfigFile(config) {
|
|
25343
|
-
const dir = mkdtempSync4(
|
|
25344
|
-
const path =
|
|
25345
|
-
|
|
24827
|
+
const dir = mkdtempSync4(join10(tmpdir3(), "flyspace-mcp-"));
|
|
24828
|
+
const path = join10(dir, "mcp-config.json");
|
|
24829
|
+
writeFileSync5(path, JSON.stringify(config), { mode: 384 });
|
|
25346
24830
|
return {
|
|
25347
24831
|
path,
|
|
25348
|
-
cleanup: () =>
|
|
24832
|
+
cleanup: () => rmSync6(dir, { recursive: true, force: true })
|
|
25349
24833
|
};
|
|
25350
24834
|
}
|
|
25351
24835
|
async function withMcpConfig(profile, connectionIds, fn, extraServers = {}) {
|
|
@@ -25363,8 +24847,8 @@ async function withMcpConfig(profile, connectionIds, fn, extraServers = {}) {
|
|
|
25363
24847
|
}
|
|
25364
24848
|
|
|
25365
24849
|
// ../api/src/version.ts
|
|
25366
|
-
import { readFileSync as
|
|
25367
|
-
var CLI_VERSION = true ? "0.1.
|
|
24850
|
+
import { readFileSync as readFileSync8 } from "fs";
|
|
24851
|
+
var CLI_VERSION = true ? "0.1.60" : devVersion();
|
|
25368
24852
|
function isOlderVersion(a, b) {
|
|
25369
24853
|
const parse2 = (v) => v.replace(/^v/, "").split("-")[0].split(".").map(Number);
|
|
25370
24854
|
const [pa, pb] = [parse2(a), parse2(b)];
|
|
@@ -25372,7 +24856,7 @@ function isOlderVersion(a, b) {
|
|
|
25372
24856
|
for (let i = 0; i < 3; i++) if (pa[i] !== pb[i]) return pa[i] < pb[i];
|
|
25373
24857
|
return false;
|
|
25374
24858
|
}
|
|
25375
|
-
var LATEST_TTL_MS =
|
|
24859
|
+
var LATEST_TTL_MS = 5 * 6e4;
|
|
25376
24860
|
var latest = null;
|
|
25377
24861
|
async function latestCliVersion() {
|
|
25378
24862
|
if (latest && Date.now() - latest.at < LATEST_TTL_MS) return latest.version;
|
|
@@ -25387,50 +24871,50 @@ async function latestCliVersion() {
|
|
|
25387
24871
|
}
|
|
25388
24872
|
|
|
25389
24873
|
// src/claude/agents.ts
|
|
25390
|
-
import { existsSync as
|
|
24874
|
+
import { existsSync as existsSync13, readdirSync as readdirSync5, readFileSync as readFileSync11 } from "fs";
|
|
25391
24875
|
import { homedir as homedir6 } from "os";
|
|
25392
|
-
import { basename as basename4, join as
|
|
24876
|
+
import { basename as basename4, join as join13 } from "path";
|
|
25393
24877
|
import yaml3 from "js-yaml";
|
|
25394
24878
|
|
|
25395
24879
|
// ../api/src/claude/skills.ts
|
|
25396
|
-
import { existsSync as
|
|
24880
|
+
import { existsSync as existsSync12, readdirSync as readdirSync4, readFileSync as readFileSync10, statSync as statSync5 } from "fs";
|
|
25397
24881
|
import { homedir as homedir5 } from "os";
|
|
25398
|
-
import { basename as basename3, dirname as
|
|
24882
|
+
import { basename as basename3, dirname as dirname2, join as join12 } from "path";
|
|
25399
24883
|
import yaml2 from "js-yaml";
|
|
25400
24884
|
|
|
25401
24885
|
// ../api/src/claude/skill-files.ts
|
|
25402
24886
|
import {
|
|
25403
|
-
existsSync as
|
|
25404
|
-
mkdirSync as
|
|
25405
|
-
readFileSync as
|
|
24887
|
+
existsSync as existsSync11,
|
|
24888
|
+
mkdirSync as mkdirSync7,
|
|
24889
|
+
readFileSync as readFileSync9,
|
|
25406
24890
|
readdirSync as readdirSync3,
|
|
25407
|
-
rmSync as
|
|
24891
|
+
rmSync as rmSync7,
|
|
25408
24892
|
statSync as statSync4,
|
|
25409
|
-
writeFileSync as
|
|
24893
|
+
writeFileSync as writeFileSync6
|
|
25410
24894
|
} from "fs";
|
|
25411
24895
|
import { homedir as homedir4 } from "os";
|
|
25412
|
-
import { join as
|
|
24896
|
+
import { join as join11, resolve as resolve4, sep as sep2 } from "path";
|
|
25413
24897
|
import yaml from "js-yaml";
|
|
25414
24898
|
var MAX_SKILL_BYTES = 2 * 1024 * 1024;
|
|
25415
24899
|
var SKILL_NAME = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
|
|
25416
24900
|
function expandHome(p) {
|
|
25417
24901
|
if (p === "~") return homedir4();
|
|
25418
|
-
if (p.startsWith("~/")) return
|
|
24902
|
+
if (p.startsWith("~/")) return join11(homedir4(), p.slice(2));
|
|
25419
24903
|
return p;
|
|
25420
24904
|
}
|
|
25421
24905
|
function workspaceSkillsDir(configDir) {
|
|
25422
|
-
return
|
|
24906
|
+
return join11(configDir ? expandHome(configDir) : join11(homedir4(), ".claude"), "skills");
|
|
25423
24907
|
}
|
|
25424
24908
|
function channelSkillsDir(cwd) {
|
|
25425
|
-
return
|
|
24909
|
+
return join11(cwd, ".claude", "skills");
|
|
25426
24910
|
}
|
|
25427
24911
|
function isValidSkillName(name) {
|
|
25428
24912
|
return SKILL_NAME.test(name);
|
|
25429
24913
|
}
|
|
25430
24914
|
function resolveSkillPath(dir, name) {
|
|
25431
24915
|
if (!isValidSkillName(name)) return null;
|
|
25432
|
-
const abs =
|
|
25433
|
-
if (!abs.startsWith(
|
|
24916
|
+
const abs = resolve4(dir, name, "SKILL.md");
|
|
24917
|
+
if (!abs.startsWith(resolve4(dir) + sep2)) return null;
|
|
25434
24918
|
return abs;
|
|
25435
24919
|
}
|
|
25436
24920
|
function splitFrontmatter(raw) {
|
|
@@ -25457,7 +24941,7 @@ ${body.replace(/^\n+/, "").trimEnd()}
|
|
|
25457
24941
|
}
|
|
25458
24942
|
function readMeta(abs) {
|
|
25459
24943
|
try {
|
|
25460
|
-
const { fm } = splitFrontmatter(
|
|
24944
|
+
const { fm } = splitFrontmatter(readFileSync9(abs, "utf-8"));
|
|
25461
24945
|
return {
|
|
25462
24946
|
name: typeof fm["name"] === "string" ? fm["name"] : void 0,
|
|
25463
24947
|
description: typeof fm["description"] === "string" ? fm["description"] : void 0
|
|
@@ -25467,7 +24951,7 @@ function readMeta(abs) {
|
|
|
25467
24951
|
}
|
|
25468
24952
|
}
|
|
25469
24953
|
function listSkillFiles(dir) {
|
|
25470
|
-
if (!
|
|
24954
|
+
if (!existsSync11(dir)) return [];
|
|
25471
24955
|
let entries2;
|
|
25472
24956
|
try {
|
|
25473
24957
|
entries2 = readdirSync3(dir);
|
|
@@ -25477,7 +24961,7 @@ function listSkillFiles(dir) {
|
|
|
25477
24961
|
const rows2 = [];
|
|
25478
24962
|
for (const entry of entries2) {
|
|
25479
24963
|
if (!isValidSkillName(entry)) continue;
|
|
25480
|
-
const abs =
|
|
24964
|
+
const abs = join11(dir, entry, "SKILL.md");
|
|
25481
24965
|
let stat;
|
|
25482
24966
|
try {
|
|
25483
24967
|
stat = statSync4(abs);
|
|
@@ -25506,7 +24990,7 @@ function readSkillFile(dir, name) {
|
|
|
25506
24990
|
return null;
|
|
25507
24991
|
}
|
|
25508
24992
|
if (!stat.isFile() || stat.size > MAX_SKILL_BYTES) return null;
|
|
25509
|
-
const { fm, body } = splitFrontmatter(
|
|
24993
|
+
const { fm, body } = splitFrontmatter(readFileSync9(abs, "utf-8"));
|
|
25510
24994
|
return {
|
|
25511
24995
|
name,
|
|
25512
24996
|
description: typeof fm["description"] === "string" ? fm["description"].trim() : "",
|
|
@@ -25528,18 +25012,18 @@ function writeSkillFile(dir, name, patch, baseMtime) {
|
|
|
25528
25012
|
if (baseMtime && stat.mtime.toISOString() !== baseMtime) {
|
|
25529
25013
|
return { status: "conflict", mtime: stat.mtime.toISOString() };
|
|
25530
25014
|
}
|
|
25531
|
-
const { fm } = splitFrontmatter(
|
|
25015
|
+
const { fm } = splitFrontmatter(readFileSync9(abs, "utf-8"));
|
|
25532
25016
|
const content = buildSkillFile({ ...fm, name, description: patch.description }, patch.body);
|
|
25533
25017
|
if (Buffer.byteLength(content, "utf8") > MAX_SKILL_BYTES) return { status: "too-large" };
|
|
25534
|
-
|
|
25018
|
+
writeFileSync6(abs, content, "utf8");
|
|
25535
25019
|
return { status: "ok", mtime: statSync4(abs).mtime.toISOString() };
|
|
25536
25020
|
}
|
|
25537
25021
|
function createSkillFile(dir, name, description) {
|
|
25538
25022
|
const abs = resolveSkillPath(dir, name);
|
|
25539
25023
|
if (!abs) return { status: "bad-name" };
|
|
25540
|
-
if (
|
|
25541
|
-
|
|
25542
|
-
|
|
25024
|
+
if (existsSync11(abs)) return { status: "exists" };
|
|
25025
|
+
mkdirSync7(join11(dir, name), { recursive: true });
|
|
25026
|
+
writeFileSync6(
|
|
25543
25027
|
abs,
|
|
25544
25028
|
buildSkillFile(
|
|
25545
25029
|
{ name, description },
|
|
@@ -25555,24 +25039,24 @@ Describe what this skill does and when to use it.
|
|
|
25555
25039
|
}
|
|
25556
25040
|
function deleteSkillFile(dir, name) {
|
|
25557
25041
|
const abs = resolveSkillPath(dir, name);
|
|
25558
|
-
if (!abs || !
|
|
25559
|
-
|
|
25042
|
+
if (!abs || !existsSync11(abs)) return { status: "not-found" };
|
|
25043
|
+
rmSync7(join11(dir, name), { recursive: true, force: true });
|
|
25560
25044
|
return { status: "ok" };
|
|
25561
25045
|
}
|
|
25562
25046
|
|
|
25563
25047
|
// ../api/src/claude/skills.ts
|
|
25564
25048
|
function defaultConfigDir() {
|
|
25565
|
-
return
|
|
25049
|
+
return join12(homedir5(), ".claude");
|
|
25566
25050
|
}
|
|
25567
25051
|
function expandHome2(p) {
|
|
25568
25052
|
if (p === "~") return homedir5();
|
|
25569
|
-
if (p.startsWith("~/")) return
|
|
25053
|
+
if (p.startsWith("~/")) return join12(homedir5(), p.slice(2));
|
|
25570
25054
|
return p;
|
|
25571
25055
|
}
|
|
25572
25056
|
function parseFrontmatter(file) {
|
|
25573
25057
|
let content;
|
|
25574
25058
|
try {
|
|
25575
|
-
content =
|
|
25059
|
+
content = readFileSync10(file, "utf-8");
|
|
25576
25060
|
} catch {
|
|
25577
25061
|
return {};
|
|
25578
25062
|
}
|
|
@@ -25590,13 +25074,13 @@ function parseFrontmatter(file) {
|
|
|
25590
25074
|
function isSymlinkedDir(root, entry) {
|
|
25591
25075
|
if (!entry.isSymbolicLink()) return false;
|
|
25592
25076
|
try {
|
|
25593
|
-
return statSync5(
|
|
25077
|
+
return statSync5(join12(root, entry.name)).isDirectory();
|
|
25594
25078
|
} catch {
|
|
25595
25079
|
return false;
|
|
25596
25080
|
}
|
|
25597
25081
|
}
|
|
25598
25082
|
function findSkillFiles(root, maxDepth, out) {
|
|
25599
|
-
if (maxDepth < 0 || !
|
|
25083
|
+
if (maxDepth < 0 || !existsSync12(root)) return;
|
|
25600
25084
|
let entries2;
|
|
25601
25085
|
try {
|
|
25602
25086
|
entries2 = readdirSync4(root, { withFileTypes: true });
|
|
@@ -25605,24 +25089,24 @@ function findSkillFiles(root, maxDepth, out) {
|
|
|
25605
25089
|
}
|
|
25606
25090
|
for (const entry of entries2) {
|
|
25607
25091
|
if (entry.isFile()) {
|
|
25608
|
-
if (entry.name === "SKILL.md") out.push(
|
|
25092
|
+
if (entry.name === "SKILL.md") out.push(join12(root, entry.name));
|
|
25609
25093
|
} else if (entry.isDirectory() || isSymlinkedDir(root, entry)) {
|
|
25610
25094
|
if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
|
|
25611
|
-
findSkillFiles(
|
|
25095
|
+
findSkillFiles(join12(root, entry.name), maxDepth - 1, out);
|
|
25612
25096
|
}
|
|
25613
25097
|
}
|
|
25614
25098
|
}
|
|
25615
25099
|
function pluginNameFor(file, root) {
|
|
25616
|
-
let dir =
|
|
25617
|
-
while (dir.startsWith(root) && dir !==
|
|
25100
|
+
let dir = dirname2(file);
|
|
25101
|
+
while (dir.startsWith(root) && dir !== dirname2(dir)) {
|
|
25618
25102
|
try {
|
|
25619
25103
|
const manifest = JSON.parse(
|
|
25620
|
-
|
|
25104
|
+
readFileSync10(join12(dir, ".claude-plugin", "plugin.json"), "utf-8")
|
|
25621
25105
|
);
|
|
25622
25106
|
if (typeof manifest.name === "string" && manifest.name.trim()) return manifest.name.trim();
|
|
25623
25107
|
} catch {
|
|
25624
25108
|
}
|
|
25625
|
-
dir =
|
|
25109
|
+
dir = dirname2(dir);
|
|
25626
25110
|
}
|
|
25627
25111
|
return void 0;
|
|
25628
25112
|
}
|
|
@@ -25639,17 +25123,17 @@ function findPluginMarkdown(pluginsRoot, dirName, maxDepth = 8) {
|
|
|
25639
25123
|
for (const entry of entries2) {
|
|
25640
25124
|
if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
|
|
25641
25125
|
if (!entry.isDirectory() && !isSymlinkedDir(dir, entry)) continue;
|
|
25642
|
-
const child =
|
|
25126
|
+
const child = join12(dir, entry.name);
|
|
25643
25127
|
if (entry.name === dirName) {
|
|
25644
25128
|
for (const f of readdirSafe(child)) {
|
|
25645
|
-
if (f.endsWith(".md")) out.push({ file:
|
|
25129
|
+
if (f.endsWith(".md")) out.push({ file: join12(child, f), plugin: pluginNameFor(join12(child, f), pluginsRoot) });
|
|
25646
25130
|
}
|
|
25647
25131
|
} else {
|
|
25648
25132
|
walk(child, depth - 1);
|
|
25649
25133
|
}
|
|
25650
25134
|
}
|
|
25651
25135
|
};
|
|
25652
|
-
if (
|
|
25136
|
+
if (existsSync12(pluginsRoot)) walk(pluginsRoot, maxDepth);
|
|
25653
25137
|
return out;
|
|
25654
25138
|
}
|
|
25655
25139
|
function readdirSafe(dir) {
|
|
@@ -25663,14 +25147,14 @@ function listCommands(configDir, cwd) {
|
|
|
25663
25147
|
const base = configDir ? expandHome2(configDir) : defaultConfigDir();
|
|
25664
25148
|
const local = (dir, source) => readdirSafe(dir).filter((f) => f.endsWith(".md")).map((f) => ({
|
|
25665
25149
|
name: basename3(f, ".md"),
|
|
25666
|
-
description: (parseFrontmatter(
|
|
25150
|
+
description: (parseFrontmatter(join12(dir, f)).description ?? "").trim(),
|
|
25667
25151
|
source,
|
|
25668
25152
|
kind: "command"
|
|
25669
25153
|
}));
|
|
25670
25154
|
const collected = [
|
|
25671
|
-
...local(
|
|
25672
|
-
...local(
|
|
25673
|
-
...findPluginMarkdown(
|
|
25155
|
+
...local(join12(cwd, ".claude", "commands"), "project"),
|
|
25156
|
+
...local(join12(base, "commands"), "user"),
|
|
25157
|
+
...findPluginMarkdown(join12(base, "plugins"), "commands").map(({ file, plugin }) => ({
|
|
25674
25158
|
name: plugin ? `${plugin}:${basename3(file, ".md")}` : basename3(file, ".md"),
|
|
25675
25159
|
description: (parseFrontmatter(file).description ?? "").trim(),
|
|
25676
25160
|
source: "plugin",
|
|
@@ -25692,7 +25176,7 @@ function collectFrom(root, source, maxDepth, namePrefix) {
|
|
|
25692
25176
|
findSkillFiles(root, maxDepth, files);
|
|
25693
25177
|
return files.map((file) => {
|
|
25694
25178
|
const fm = parseFrontmatter(file);
|
|
25695
|
-
const name = fm.name?.trim() || basename3(
|
|
25179
|
+
const name = fm.name?.trim() || basename3(dirname2(file));
|
|
25696
25180
|
const plugin = source === "plugin" ? pluginNameFor(file, root) : void 0;
|
|
25697
25181
|
const prefix = namePrefix ?? plugin;
|
|
25698
25182
|
return {
|
|
@@ -25708,10 +25192,10 @@ function collectFrom(root, source, maxDepth, namePrefix) {
|
|
|
25708
25192
|
function collectAll(configDir, cwd) {
|
|
25709
25193
|
const base = configDir ? expandHome2(configDir) : defaultConfigDir();
|
|
25710
25194
|
const collected = [
|
|
25711
|
-
...collectFrom(
|
|
25195
|
+
...collectFrom(join12(cwd, ".claude", "skills"), "project", 2),
|
|
25712
25196
|
...nestedProjectRoots(cwd).flatMap(({ dir, prefix }) => collectFrom(dir, "project", 2, prefix)),
|
|
25713
|
-
...collectFrom(
|
|
25714
|
-
...collectFrom(
|
|
25197
|
+
...collectFrom(join12(base, "skills"), "user", 2),
|
|
25198
|
+
...collectFrom(join12(base, "plugins"), "plugin", 8)
|
|
25715
25199
|
];
|
|
25716
25200
|
const byName = /* @__PURE__ */ new Map();
|
|
25717
25201
|
for (const skill of collected) {
|
|
@@ -25730,8 +25214,8 @@ function nestedProjectRoots(cwd) {
|
|
|
25730
25214
|
for (const entry of entries2) {
|
|
25731
25215
|
if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
|
|
25732
25216
|
if (!entry.isDirectory() && !isSymlinkedDir(cwd, entry)) continue;
|
|
25733
|
-
const skillsDir =
|
|
25734
|
-
if (
|
|
25217
|
+
const skillsDir = join12(cwd, entry.name, ".claude", "skills");
|
|
25218
|
+
if (existsSync12(skillsDir)) roots.push({ dir: skillsDir, prefix: entry.name });
|
|
25735
25219
|
}
|
|
25736
25220
|
return roots;
|
|
25737
25221
|
}
|
|
@@ -25743,7 +25227,7 @@ function listPluginSkillDetails(configDir, cwd) {
|
|
|
25743
25227
|
for (const { file, ...skill } of collectAll(configDir, cwd)) {
|
|
25744
25228
|
if (skill.source !== "plugin") continue;
|
|
25745
25229
|
try {
|
|
25746
|
-
const { body } = splitFrontmatter(
|
|
25230
|
+
const { body } = splitFrontmatter(readFileSync10(file, "utf-8"));
|
|
25747
25231
|
details.push({ ...skill, body, path: file, mtime: statSync5(file).mtime.toISOString() });
|
|
25748
25232
|
} catch {
|
|
25749
25233
|
}
|
|
@@ -25753,15 +25237,15 @@ function listPluginSkillDetails(configDir, cwd) {
|
|
|
25753
25237
|
function findSkillDetail(configDir, cwd, name, sources) {
|
|
25754
25238
|
const base = configDir ? expandHome2(configDir) : defaultConfigDir();
|
|
25755
25239
|
const roots = [
|
|
25756
|
-
[
|
|
25240
|
+
[join12(cwd, ".claude", "skills"), "project", 2],
|
|
25757
25241
|
...nestedProjectRoots(cwd).map(({ dir, prefix }) => [
|
|
25758
25242
|
dir,
|
|
25759
25243
|
"project",
|
|
25760
25244
|
2,
|
|
25761
25245
|
prefix
|
|
25762
25246
|
]),
|
|
25763
|
-
[
|
|
25764
|
-
[
|
|
25247
|
+
[join12(base, "skills"), "user", 2],
|
|
25248
|
+
[join12(base, "plugins"), "plugin", 8]
|
|
25765
25249
|
];
|
|
25766
25250
|
for (const [root, source, maxDepth, namePrefix] of roots) {
|
|
25767
25251
|
if (!sources.includes(source)) continue;
|
|
@@ -25769,7 +25253,7 @@ function findSkillDetail(configDir, cwd, name, sources) {
|
|
|
25769
25253
|
findSkillFiles(root, maxDepth, files);
|
|
25770
25254
|
for (const file of files) {
|
|
25771
25255
|
const fm = parseFrontmatter(file);
|
|
25772
|
-
const rawName = fm.name?.trim() || basename3(
|
|
25256
|
+
const rawName = fm.name?.trim() || basename3(dirname2(file));
|
|
25773
25257
|
const plugin = source === "plugin" ? pluginNameFor(file, root) : void 0;
|
|
25774
25258
|
const prefix = namePrefix ?? plugin;
|
|
25775
25259
|
const skillName = prefix ? `${prefix}:${rawName}` : rawName;
|
|
@@ -25777,7 +25261,7 @@ function findSkillDetail(configDir, cwd, name, sources) {
|
|
|
25777
25261
|
let raw;
|
|
25778
25262
|
let mtime;
|
|
25779
25263
|
try {
|
|
25780
|
-
raw =
|
|
25264
|
+
raw = readFileSync10(file, "utf-8");
|
|
25781
25265
|
mtime = statSync5(file).mtime.toISOString();
|
|
25782
25266
|
} catch {
|
|
25783
25267
|
continue;
|
|
@@ -25805,24 +25289,24 @@ function expandSkillCommand(configDir, cwd, text) {
|
|
|
25805
25289
|
const body = skill.body.includes("$ARGUMENTS") ? skill.body.replaceAll("$ARGUMENTS", args) : skill.body + (args ? `
|
|
25806
25290
|
|
|
25807
25291
|
ARGUMENTS: ${args}` : "");
|
|
25808
|
-
return `[the user ran the /${skill.name} skill; its instructions follow. Base directory for this skill: ${
|
|
25292
|
+
return `[the user ran the /${skill.name} skill; its instructions follow. Base directory for this skill: ${dirname2(skill.path)}]
|
|
25809
25293
|
|
|
25810
25294
|
${body.trim()}`;
|
|
25811
25295
|
}
|
|
25812
25296
|
|
|
25813
25297
|
// src/claude/agents.ts
|
|
25814
25298
|
function defaultConfigDir2() {
|
|
25815
|
-
return
|
|
25299
|
+
return join13(homedir6(), ".claude");
|
|
25816
25300
|
}
|
|
25817
25301
|
function expandHome3(p) {
|
|
25818
25302
|
if (p === "~") return homedir6();
|
|
25819
|
-
if (p.startsWith("~/")) return
|
|
25303
|
+
if (p.startsWith("~/")) return join13(homedir6(), p.slice(2));
|
|
25820
25304
|
return p;
|
|
25821
25305
|
}
|
|
25822
25306
|
function parseFrontmatter2(file) {
|
|
25823
25307
|
let content;
|
|
25824
25308
|
try {
|
|
25825
|
-
content =
|
|
25309
|
+
content = readFileSync11(file, "utf-8");
|
|
25826
25310
|
} catch {
|
|
25827
25311
|
return {};
|
|
25828
25312
|
}
|
|
@@ -25838,7 +25322,7 @@ function parseFrontmatter2(file) {
|
|
|
25838
25322
|
}
|
|
25839
25323
|
}
|
|
25840
25324
|
function collectFrom2(root, source) {
|
|
25841
|
-
if (!
|
|
25325
|
+
if (!existsSync13(root)) return [];
|
|
25842
25326
|
let entries2;
|
|
25843
25327
|
try {
|
|
25844
25328
|
entries2 = readdirSync5(root).filter((f) => f.endsWith(".md"));
|
|
@@ -25846,7 +25330,7 @@ function collectFrom2(root, source) {
|
|
|
25846
25330
|
return [];
|
|
25847
25331
|
}
|
|
25848
25332
|
return entries2.map((file) => {
|
|
25849
|
-
const path =
|
|
25333
|
+
const path = join13(root, file);
|
|
25850
25334
|
const fm = parseFrontmatter2(path);
|
|
25851
25335
|
const name = fm.name?.trim() || basename4(file, ".md");
|
|
25852
25336
|
return { name, description: (fm.description ?? "").trim(), source, path };
|
|
@@ -25855,10 +25339,10 @@ function collectFrom2(root, source) {
|
|
|
25855
25339
|
function listAgents(configDir, cwd) {
|
|
25856
25340
|
const base = configDir ? expandHome3(configDir) : defaultConfigDir2();
|
|
25857
25341
|
const collected = [
|
|
25858
|
-
...collectFrom2(
|
|
25859
|
-
...collectFrom2(
|
|
25342
|
+
...collectFrom2(join13(cwd, ".claude", "agents"), "project"),
|
|
25343
|
+
...collectFrom2(join13(base, "agents"), "user"),
|
|
25860
25344
|
// Plugin agents, namespaced `plugin:agent` the way the CLI lists them.
|
|
25861
|
-
...findPluginMarkdown(
|
|
25345
|
+
...findPluginMarkdown(join13(base, "plugins"), "agents").map(({ file, plugin }) => {
|
|
25862
25346
|
const fm = parseFrontmatter2(file);
|
|
25863
25347
|
const name = fm.name?.trim() || basename4(file, ".md");
|
|
25864
25348
|
return {
|
|
@@ -25879,7 +25363,7 @@ function readAgentPersona(configDir, cwd, name) {
|
|
|
25879
25363
|
const agent = listAgents(configDir, cwd).find((a) => a.name === name);
|
|
25880
25364
|
if (!agent) return void 0;
|
|
25881
25365
|
try {
|
|
25882
|
-
const content =
|
|
25366
|
+
const content = readFileSync11(agent.path, "utf-8");
|
|
25883
25367
|
return content.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/, "").trim();
|
|
25884
25368
|
} catch {
|
|
25885
25369
|
return void 0;
|
|
@@ -25888,13 +25372,13 @@ function readAgentPersona(configDir, cwd, name) {
|
|
|
25888
25372
|
|
|
25889
25373
|
// src/dashboard/memory-extraction-runner.ts
|
|
25890
25374
|
import { spawn as spawn4 } from "child_process";
|
|
25891
|
-
import { existsSync as
|
|
25375
|
+
import { existsSync as existsSync14, mkdtempSync as mkdtempSync5, readFileSync as readFileSync12, rmSync as rmSync8 } from "fs";
|
|
25892
25376
|
import { tmpdir as tmpdir4 } from "os";
|
|
25893
|
-
import { join as
|
|
25377
|
+
import { join as join15 } from "path";
|
|
25894
25378
|
|
|
25895
25379
|
// ../api/src/dashboard/profile-config.ts
|
|
25896
25380
|
import { homedir as homedir7 } from "os";
|
|
25897
|
-
import { join as
|
|
25381
|
+
import { join as join14, parse, resolve as resolve5 } from "path";
|
|
25898
25382
|
|
|
25899
25383
|
// ../api/src/dashboard/profile-config-cache.ts
|
|
25900
25384
|
var cache3 = /* @__PURE__ */ new Map();
|
|
@@ -25913,7 +25397,7 @@ function profileEnv(key) {
|
|
|
25913
25397
|
function profileClaudeConfigDir() {
|
|
25914
25398
|
const config = cachedProfileConfig();
|
|
25915
25399
|
if (!config) return process.env["CLAUDE_CONFIG_DIR"] || void 0;
|
|
25916
|
-
return config.env["CLAUDE_CONFIG_DIR"]?.trim() ||
|
|
25400
|
+
return config.env["CLAUDE_CONFIG_DIR"]?.trim() || join14(homedir7(), ".claude");
|
|
25917
25401
|
}
|
|
25918
25402
|
function profileOauthToken() {
|
|
25919
25403
|
const env = cachedProfileConfig()?.env ?? {};
|
|
@@ -25922,8 +25406,8 @@ function profileOauthToken() {
|
|
|
25922
25406
|
return process.env["CLAUDE_CODE_OAUTH_TOKEN"] || void 0;
|
|
25923
25407
|
}
|
|
25924
25408
|
function isUnsafeCwd(cwd) {
|
|
25925
|
-
const p =
|
|
25926
|
-
return p === parse(p).root || p ===
|
|
25409
|
+
const p = resolve5(cwd);
|
|
25410
|
+
return p === parse(p).root || p === resolve5(homedir7());
|
|
25927
25411
|
}
|
|
25928
25412
|
function defaultClaudeCwd() {
|
|
25929
25413
|
return profileEnv("CLAUDE_CWD") ?? process.cwd();
|
|
@@ -25974,7 +25458,7 @@ var SUGGEST_TOOLS = "Read,Glob,Grep";
|
|
|
25974
25458
|
function buildInvocation(runner, req, dir, auth, baseEnv = process.env, tools = "") {
|
|
25975
25459
|
const env = { ...baseEnv, CLAUDE_CODE_DISABLE_AUTO_MEMORY: "1" };
|
|
25976
25460
|
if (runner === "codex") {
|
|
25977
|
-
const outputFile =
|
|
25461
|
+
const outputFile = join15(dir, "last-message.txt");
|
|
25978
25462
|
return {
|
|
25979
25463
|
command: "codex",
|
|
25980
25464
|
args: [
|
|
@@ -26029,9 +25513,9 @@ ${req.user}`,
|
|
|
26029
25513
|
};
|
|
26030
25514
|
}
|
|
26031
25515
|
function run(inv, cwd) {
|
|
26032
|
-
return new Promise((
|
|
26033
|
-
if (!
|
|
26034
|
-
|
|
25516
|
+
return new Promise((resolve7) => {
|
|
25517
|
+
if (!existsSync14(cwd)) {
|
|
25518
|
+
resolve7({ ok: false, error: `the channel folder ${cwd} does not exist on this Host` });
|
|
26035
25519
|
return;
|
|
26036
25520
|
}
|
|
26037
25521
|
const child = spawn4(inv.command, inv.args, {
|
|
@@ -26049,7 +25533,7 @@ function run(inv, cwd) {
|
|
|
26049
25533
|
child.on("error", (err) => {
|
|
26050
25534
|
clearTimeout(timer);
|
|
26051
25535
|
console.error(`[memory-extraction] ${inv.command} failed to start:`, err.message);
|
|
26052
|
-
|
|
25536
|
+
resolve7({ ok: false, error: `${inv.command} failed to start: ${err.message}` });
|
|
26053
25537
|
});
|
|
26054
25538
|
child.on("close", (code) => {
|
|
26055
25539
|
clearTimeout(timer);
|
|
@@ -26057,18 +25541,18 @@ function run(inv, cwd) {
|
|
|
26057
25541
|
const detail = (stderr || stdout).trim().split("\n").at(-1) ?? "";
|
|
26058
25542
|
const error = `${inv.command} exited ${code ?? "on timeout"}: ${detail.slice(0, 200)}`;
|
|
26059
25543
|
console.error(`[memory-extraction] ${error}`);
|
|
26060
|
-
|
|
25544
|
+
resolve7({ ok: false, error });
|
|
26061
25545
|
return;
|
|
26062
25546
|
}
|
|
26063
25547
|
let raw = stdout;
|
|
26064
25548
|
if (inv.outputFile) {
|
|
26065
25549
|
try {
|
|
26066
|
-
raw =
|
|
25550
|
+
raw = readFileSync12(inv.outputFile, "utf-8");
|
|
26067
25551
|
} catch {
|
|
26068
25552
|
raw = "";
|
|
26069
25553
|
}
|
|
26070
25554
|
}
|
|
26071
|
-
|
|
25555
|
+
resolve7({ ok: true, raw });
|
|
26072
25556
|
});
|
|
26073
25557
|
child.stdin.end(inv.stdin);
|
|
26074
25558
|
});
|
|
@@ -26076,7 +25560,7 @@ function run(inv, cwd) {
|
|
|
26076
25560
|
async function complete(req, tools = "", cwd) {
|
|
26077
25561
|
const runner = runnerForModel(loadDashboardSettings().agent);
|
|
26078
25562
|
const config = resolveChannelConfig(req.channelId);
|
|
26079
|
-
const dir = mkdtempSync5(
|
|
25563
|
+
const dir = mkdtempSync5(join15(tmpdir4(), "flyspace-memory-"));
|
|
26080
25564
|
try {
|
|
26081
25565
|
const inv = buildInvocation(
|
|
26082
25566
|
runner,
|
|
@@ -26091,7 +25575,7 @@ async function complete(req, tools = "", cwd) {
|
|
|
26091
25575
|
);
|
|
26092
25576
|
return await run(inv, cwd ?? dir);
|
|
26093
25577
|
} finally {
|
|
26094
|
-
|
|
25578
|
+
rmSync8(dir, { recursive: true, force: true });
|
|
26095
25579
|
}
|
|
26096
25580
|
}
|
|
26097
25581
|
function completeMemoryExtraction(req) {
|
|
@@ -26104,7 +25588,7 @@ function suggestChannelField(req) {
|
|
|
26104
25588
|
}
|
|
26105
25589
|
|
|
26106
25590
|
// src/store/usage-store.ts
|
|
26107
|
-
import { randomUUID as
|
|
25591
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
26108
25592
|
import Database2 from "better-sqlite3";
|
|
26109
25593
|
|
|
26110
25594
|
// ../api/src/store/rate-cards.ts
|
|
@@ -26445,7 +25929,7 @@ var UsageStore = class {
|
|
|
26445
25929
|
if (ids.length === 0) return;
|
|
26446
25930
|
const update = this.db.prepare("UPDATE agent_usage SET row_uid = ? WHERE id = ?");
|
|
26447
25931
|
this.db.transaction(() => {
|
|
26448
|
-
for (const { id } of ids) update.run(
|
|
25932
|
+
for (const { id } of ids) update.run(randomUUID2(), id);
|
|
26449
25933
|
})();
|
|
26450
25934
|
}
|
|
26451
25935
|
/**
|
|
@@ -26483,7 +25967,7 @@ var UsageStore = class {
|
|
|
26483
25967
|
cost_usd, duration_ms, num_turns, is_error
|
|
26484
25968
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
26485
25969
|
).run(
|
|
26486
|
-
|
|
25970
|
+
randomUUID2(),
|
|
26487
25971
|
ranAt.toISOString(),
|
|
26488
25972
|
entry.source,
|
|
26489
25973
|
entry.channelId ?? null,
|
|
@@ -26791,9 +26275,9 @@ var UsageStore = class {
|
|
|
26791
26275
|
|
|
26792
26276
|
// src/dashboard/rollover-summary.ts
|
|
26793
26277
|
import { spawn as spawn5 } from "child_process";
|
|
26794
|
-
import { existsSync as
|
|
26278
|
+
import { existsSync as existsSync15, mkdtempSync as mkdtempSync6, readFileSync as readFileSync13, rmSync as rmSync9 } from "fs";
|
|
26795
26279
|
import { tmpdir as tmpdir5 } from "os";
|
|
26796
|
-
import { join as
|
|
26280
|
+
import { join as join16 } from "path";
|
|
26797
26281
|
var HAIKU_MODEL = "haiku";
|
|
26798
26282
|
var CJK_PATTERN = /[ -〿-ヿ㐀-䶿一-鿿豈--]/;
|
|
26799
26283
|
function estimateTokens(text) {
|
|
@@ -26856,8 +26340,8 @@ function runSummaryPrint(input, options) {
|
|
|
26856
26340
|
return runPrint("claude", args, env).then((out) => out.trim());
|
|
26857
26341
|
}
|
|
26858
26342
|
async function runCodexSummary(input) {
|
|
26859
|
-
const dir = mkdtempSync6(
|
|
26860
|
-
const lastMessageFile =
|
|
26343
|
+
const dir = mkdtempSync6(join16(tmpdir5(), "rollover-"));
|
|
26344
|
+
const lastMessageFile = join16(dir, "last-message.txt");
|
|
26861
26345
|
try {
|
|
26862
26346
|
await runPrint(
|
|
26863
26347
|
"codex",
|
|
@@ -26880,13 +26364,13 @@ ${input}`
|
|
|
26880
26364
|
],
|
|
26881
26365
|
{ ...process.env }
|
|
26882
26366
|
);
|
|
26883
|
-
return
|
|
26367
|
+
return existsSync15(lastMessageFile) ? readFileSync13(lastMessageFile, "utf8").trim() : "";
|
|
26884
26368
|
} finally {
|
|
26885
|
-
|
|
26369
|
+
rmSync9(dir, { recursive: true, force: true });
|
|
26886
26370
|
}
|
|
26887
26371
|
}
|
|
26888
26372
|
function runPrint(command, args, env) {
|
|
26889
|
-
return new Promise((
|
|
26373
|
+
return new Promise((resolve7, reject) => {
|
|
26890
26374
|
const child = spawn5(command, args, {
|
|
26891
26375
|
// A stateless rewrite touches no files — tmpdir keeps it that way and
|
|
26892
26376
|
// avoids picking up an unrelated project's own CLAUDE.md/AGENTS.md,
|
|
@@ -26916,7 +26400,7 @@ function runPrint(command, args, env) {
|
|
|
26916
26400
|
reject(new Error(`${command} summary exited with code ${code}: ${stderr.trim()}`));
|
|
26917
26401
|
return;
|
|
26918
26402
|
}
|
|
26919
|
-
|
|
26403
|
+
resolve7(stdout);
|
|
26920
26404
|
});
|
|
26921
26405
|
});
|
|
26922
26406
|
}
|
|
@@ -27122,7 +26606,7 @@ async function scanBackgroundTasks() {
|
|
|
27122
26606
|
|
|
27123
26607
|
// src/dashboard/attachment-downloader.ts
|
|
27124
26608
|
import { writeFile as writeFile2 } from "fs/promises";
|
|
27125
|
-
import { join as
|
|
26609
|
+
import { join as join17 } from "path";
|
|
27126
26610
|
import { GetObjectCommand } from "@aws-sdk/client-s3";
|
|
27127
26611
|
var debug4 = process.env["DEBUG"] === "true";
|
|
27128
26612
|
var ATTACHMENT_LINK = /\]\((?:https:\/\/[a-z0-9-]+\.flyspace\.ai)?\/api\/attachments\/([^)?\s]+)(?:\?[^)\s]*)?\)/g;
|
|
@@ -27189,7 +26673,7 @@ async function downloadOne2(key) {
|
|
|
27189
26673
|
if (bytes.length > sizeLimit) {
|
|
27190
26674
|
return { kind: "skip", skipped: { name, mimetype, reason: "too_large" } };
|
|
27191
26675
|
}
|
|
27192
|
-
const localPath =
|
|
26676
|
+
const localPath = join17(paths.UPLOADS_DIR, lastSegment);
|
|
27193
26677
|
await writeFile2(localPath, bytes);
|
|
27194
26678
|
if (debug4)
|
|
27195
26679
|
console.log(`[attachment-downloader] saved ${key} -> ${localPath} (${bytes.length} bytes)`);
|
|
@@ -27249,27 +26733,27 @@ async function offloadPluginUi(workspace, state) {
|
|
|
27249
26733
|
var pluginUiHash = (state) => sha256(JSON.stringify(state));
|
|
27250
26734
|
|
|
27251
26735
|
// src/dashboard/doc-mention-guard.ts
|
|
27252
|
-
import { existsSync as
|
|
26736
|
+
import { existsSync as existsSync20, statSync as statSync8 } from "fs";
|
|
27253
26737
|
|
|
27254
26738
|
// src/dashboard/docs-routes.ts
|
|
27255
26739
|
import {
|
|
27256
26740
|
closeSync,
|
|
27257
26741
|
createReadStream,
|
|
27258
|
-
existsSync as
|
|
26742
|
+
existsSync as existsSync19,
|
|
27259
26743
|
lstatSync as lstatSync2,
|
|
27260
|
-
mkdirSync as
|
|
26744
|
+
mkdirSync as mkdirSync8,
|
|
27261
26745
|
openSync,
|
|
27262
26746
|
readSync,
|
|
27263
26747
|
readdirSync as readdirSync6,
|
|
27264
|
-
readFileSync as
|
|
26748
|
+
readFileSync as readFileSync17,
|
|
27265
26749
|
realpathSync,
|
|
27266
26750
|
renameSync as renameSync3,
|
|
27267
|
-
rmSync as
|
|
26751
|
+
rmSync as rmSync10,
|
|
27268
26752
|
statSync as statSync7,
|
|
27269
|
-
writeFileSync as
|
|
26753
|
+
writeFileSync as writeFileSync7
|
|
27270
26754
|
} from "fs";
|
|
27271
26755
|
import { Readable } from "stream";
|
|
27272
|
-
import { basename as basename6, dirname as
|
|
26756
|
+
import { basename as basename6, dirname as dirname3, extname as extname2, join as join21, relative, resolve as resolve6, sep as sep3 } from "path";
|
|
27273
26757
|
import { Hono as Hono4 } from "hono";
|
|
27274
26758
|
import { streamSSE } from "hono/streaming";
|
|
27275
26759
|
|
|
@@ -27381,8 +26865,8 @@ var requireDocsAccess = async (c, next) => {
|
|
|
27381
26865
|
};
|
|
27382
26866
|
|
|
27383
26867
|
// src/dashboard/docs-watcher.ts
|
|
27384
|
-
import { existsSync as
|
|
27385
|
-
import { basename as basename5, join as
|
|
26868
|
+
import { existsSync as existsSync16, watch } from "fs";
|
|
26869
|
+
import { basename as basename5, join as join18 } from "path";
|
|
27386
26870
|
var DEBOUNCE_MS = 200;
|
|
27387
26871
|
var MAX_PENDING = 200;
|
|
27388
26872
|
var IGNORED_SEGMENTS = /* @__PURE__ */ new Set([
|
|
@@ -27423,7 +26907,7 @@ function watchDocs(cwd, listener) {
|
|
|
27423
26907
|
const current = entries.get(cwd);
|
|
27424
26908
|
if (!current || filename === null) return;
|
|
27425
26909
|
const rel = filename.split("\\").join("/");
|
|
27426
|
-
if (rel === root && !
|
|
26910
|
+
if (rel === root && !existsSync16(join18(cwd, rel))) return;
|
|
27427
26911
|
if (isIgnoredDocPath(rel)) return;
|
|
27428
26912
|
if (current.pending.size < MAX_PENDING) current.pending.add(rel);
|
|
27429
26913
|
if (current.timer === null) current.timer = setTimeout(() => flush(cwd), DEBOUNCE_MS);
|
|
@@ -28344,7 +27828,7 @@ function truncationNotice(lang, voice) {
|
|
|
28344
27828
|
if (lang === "en" || lang.startsWith("en-")) return TRUNCATION_NOTICE.en;
|
|
28345
27829
|
return null;
|
|
28346
27830
|
}
|
|
28347
|
-
var sleep2 = (ms) => new Promise((
|
|
27831
|
+
var sleep2 = (ms) => new Promise((resolve7) => setTimeout(resolve7, ms));
|
|
28348
27832
|
async function synthesizeWithRetry(script, voice) {
|
|
28349
27833
|
let lastError;
|
|
28350
27834
|
for (let attempt = 1; attempt <= SYNTH_ATTEMPTS; attempt += 1) {
|
|
@@ -28735,8 +28219,8 @@ function createFeatureFlagsRouter() {
|
|
|
28735
28219
|
}
|
|
28736
28220
|
|
|
28737
28221
|
// ../api/src/dashboard/public-share-routes.ts
|
|
28738
|
-
import { existsSync as
|
|
28739
|
-
import { join as
|
|
28222
|
+
import { existsSync as existsSync18, readFileSync as readFileSync15, statSync as statSync6 } from "fs";
|
|
28223
|
+
import { join as join20 } from "path";
|
|
28740
28224
|
import { Hono as Hono3 } from "hono";
|
|
28741
28225
|
import { GetObjectCommand as GetObjectCommand3 } from "@aws-sdk/client-s3";
|
|
28742
28226
|
import { getSignedUrl as getSignedUrl2 } from "@aws-sdk/s3-request-presigner";
|
|
@@ -28943,13 +28427,13 @@ function injectShareHead(html, head) {
|
|
|
28943
28427
|
|
|
28944
28428
|
// ../api/src/dashboard/app-icon.ts
|
|
28945
28429
|
import { createHash as createHash8 } from "crypto";
|
|
28946
|
-
import { existsSync as
|
|
28947
|
-
import { join as
|
|
28430
|
+
import { existsSync as existsSync17, readFileSync as readFileSync14 } from "fs";
|
|
28431
|
+
import { join as join19 } from "path";
|
|
28948
28432
|
import sharp3 from "sharp";
|
|
28949
28433
|
var PLATE = "#0A0A0F";
|
|
28950
|
-
var BRAND_DIR =
|
|
28951
|
-
var MARK_FILE =
|
|
28952
|
-
var MARK_SVG_FILE =
|
|
28434
|
+
var BRAND_DIR = existsSync17(join19(paths.WEB_ROOT, "public")) ? join19(paths.WEB_ROOT, "public") : join19(paths.PACKAGE_ROOT, "dist", "brand");
|
|
28435
|
+
var MARK_FILE = join19(BRAND_DIR, "icons", "icon-512.png");
|
|
28436
|
+
var MARK_SVG_FILE = join19(BRAND_DIR, "favicon.svg");
|
|
28953
28437
|
var LAYOUT = {
|
|
28954
28438
|
standard: { logo: 0.7, logoCx: 0.5, logoCy: 0.48, badge: 0.27, badgeCx: 0.22, badgeCy: 0.76 },
|
|
28955
28439
|
maskable: { logo: 0.56, logoCx: 0.5, logoCy: 0.48, badge: 0.23, badgeCx: 0.33, badgeCy: 0.66 }
|
|
@@ -28972,7 +28456,7 @@ function roundedPlate(size, fill = PLATE) {
|
|
|
28972
28456
|
}
|
|
28973
28457
|
async function renderBadge(box) {
|
|
28974
28458
|
const transparent = { r: 0, g: 0, b: 0, alpha: 0 };
|
|
28975
|
-
const raster = await sharp3(
|
|
28459
|
+
const raster = await sharp3(readFileSync14(MARK_SVG_FILE)).resize(512, 512, { fit: "contain", background: transparent }).png().toBuffer();
|
|
28976
28460
|
return sharp3(raster).trim().resize(box, box, { fit: "contain", background: transparent }).png().toBuffer();
|
|
28977
28461
|
}
|
|
28978
28462
|
async function sampleBackground(logo) {
|
|
@@ -29027,7 +28511,7 @@ async function renderAppIcon({
|
|
|
29027
28511
|
if (hit) return hit;
|
|
29028
28512
|
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,
|
|
29029
28513
|
// either on its usual dark plate or, for a favicon, trimmed and bare.
|
|
29030
|
-
(transparent ? await renderBadge(size) : await sharp3(
|
|
28514
|
+
(transparent ? await renderBadge(size) : await sharp3(readFileSync14(MARK_FILE)).resize(size, size, { fit: "cover" }).png().toBuffer());
|
|
29031
28515
|
cache4.set(key, out);
|
|
29032
28516
|
return out;
|
|
29033
28517
|
}
|
|
@@ -29566,7 +29050,7 @@ var shellCache = null;
|
|
|
29566
29050
|
function readShell(path) {
|
|
29567
29051
|
const { mtimeMs } = statSync6(path);
|
|
29568
29052
|
if (shellCache?.mtimeMs === mtimeMs) return shellCache.html;
|
|
29569
|
-
const html =
|
|
29053
|
+
const html = readFileSync15(path, "utf8").replaceAll('"/assets/', `"${BUILD_PREFIX}/`);
|
|
29570
29054
|
shellCache = { mtimeMs, html };
|
|
29571
29055
|
return html;
|
|
29572
29056
|
}
|
|
@@ -29586,17 +29070,17 @@ function serveBuildFile(c, webDist, dir, name) {
|
|
|
29586
29070
|
if (!type || !/^[A-Za-z0-9._-]+$/.test(name) || name.includes("..")) {
|
|
29587
29071
|
return c.text("not found", 404);
|
|
29588
29072
|
}
|
|
29589
|
-
const path =
|
|
29590
|
-
if (!
|
|
29073
|
+
const path = join20(webDist, dir, name);
|
|
29074
|
+
if (!existsSync18(path)) return c.text("not found", 404);
|
|
29591
29075
|
c.header("Content-Type", type);
|
|
29592
29076
|
c.header("Cache-Control", "public, max-age=31536000, immutable");
|
|
29593
29077
|
if (ext === ".css") {
|
|
29594
|
-
return c.body(
|
|
29078
|
+
return c.body(readFileSync15(path, "utf8").replaceAll("url(/fonts/", `url(${BUILD_PREFIX}/fonts/`));
|
|
29595
29079
|
}
|
|
29596
29080
|
if (ext === ".js") {
|
|
29597
|
-
return c.body(
|
|
29081
|
+
return c.body(readFileSync15(path, "utf8").replaceAll('"/assets/', `"${BUILD_PREFIX}/`));
|
|
29598
29082
|
}
|
|
29599
|
-
return c.body(new Uint8Array(
|
|
29083
|
+
return c.body(new Uint8Array(readFileSync15(path)));
|
|
29600
29084
|
}
|
|
29601
29085
|
var HTML_SHARE_CSP = "sandbox allow-scripts allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox";
|
|
29602
29086
|
function servePublishedHtml(c, share) {
|
|
@@ -29732,8 +29216,8 @@ ${analytics}` : head);
|
|
|
29732
29216
|
const requested = c.req.param("lang");
|
|
29733
29217
|
const lang = canonicalLanguage(requested);
|
|
29734
29218
|
if (!isTranslatableLanguage(lang)) return next();
|
|
29735
|
-
const shell =
|
|
29736
|
-
if (!
|
|
29219
|
+
const shell = join20(webDist, "index.html");
|
|
29220
|
+
if (!existsSync18(shell)) return next();
|
|
29737
29221
|
const share = await getDocShare(c.req.param("id"));
|
|
29738
29222
|
if (!share) return next();
|
|
29739
29223
|
if (requested !== lang) return c.redirect(`/share/${share.id}/${lang}`, 302);
|
|
@@ -29768,8 +29252,8 @@ ${analytics}` : head);
|
|
|
29768
29252
|
const share = await getDocShare(c.req.param("id"));
|
|
29769
29253
|
if (!share) return next();
|
|
29770
29254
|
if (share.kind === "html") return servePublishedHtml(c, share);
|
|
29771
|
-
const shell =
|
|
29772
|
-
if (!
|
|
29255
|
+
const shell = join20(webDist, "index.html");
|
|
29256
|
+
if (!existsSync18(shell)) return next();
|
|
29773
29257
|
return readerPage(
|
|
29774
29258
|
c,
|
|
29775
29259
|
share,
|
|
@@ -29794,7 +29278,7 @@ ${analytics}` : head);
|
|
|
29794
29278
|
}
|
|
29795
29279
|
|
|
29796
29280
|
// src/dashboard/artifact-export.ts
|
|
29797
|
-
import { readFileSync as
|
|
29281
|
+
import { readFileSync as readFileSync16 } from "fs";
|
|
29798
29282
|
async function exportDocAsArtifact(channelId, docPath) {
|
|
29799
29283
|
const owningProfile = findOwningProfile(channelId);
|
|
29800
29284
|
const channelConfig = await runWithProfile(
|
|
@@ -29803,7 +29287,7 @@ async function exportDocAsArtifact(channelId, docPath) {
|
|
|
29803
29287
|
);
|
|
29804
29288
|
const abs = resolveDocPath(channelConfig.cwd, docPath);
|
|
29805
29289
|
if (!abs) throw new Error(`doc not found: ${docPath}`);
|
|
29806
|
-
const content =
|
|
29290
|
+
const content = readFileSync16(abs, "utf8");
|
|
29807
29291
|
const title = extractTitle(abs, "md");
|
|
29808
29292
|
const today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
29809
29293
|
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).
|
|
@@ -30035,7 +29519,7 @@ function extractTitle(absPath, kind) {
|
|
|
30035
29519
|
}
|
|
30036
29520
|
function resolveDirPath(root, rel) {
|
|
30037
29521
|
if (rel.includes("\0")) return null;
|
|
30038
|
-
const abs =
|
|
29522
|
+
const abs = resolve6(root, rel);
|
|
30039
29523
|
if (abs !== root && !abs.startsWith(root + sep3)) return null;
|
|
30040
29524
|
return abs;
|
|
30041
29525
|
}
|
|
@@ -30063,7 +29547,7 @@ function probeDir(absDir, showHidden) {
|
|
|
30063
29547
|
return false;
|
|
30064
29548
|
}
|
|
30065
29549
|
if (!showHidden && entry.name.startsWith(".")) continue;
|
|
30066
|
-
const abs =
|
|
29550
|
+
const abs = join21(dir, entry.name);
|
|
30067
29551
|
const kind = entryKind(entry, abs);
|
|
30068
29552
|
if (kind === "dir") {
|
|
30069
29553
|
if (SKIP_DIRS.has(entry.name)) hasOther = true;
|
|
@@ -30083,14 +29567,14 @@ function probeDir(absDir, showHidden) {
|
|
|
30083
29567
|
}
|
|
30084
29568
|
function readGitBranch(dir) {
|
|
30085
29569
|
try {
|
|
30086
|
-
let gitDir =
|
|
29570
|
+
let gitDir = join21(dir, ".git");
|
|
30087
29571
|
if (statSync7(gitDir).isFile()) {
|
|
30088
|
-
const pointer =
|
|
29572
|
+
const pointer = readFileSync17(gitDir, "utf8").trim();
|
|
30089
29573
|
const match = pointer.match(/^gitdir:\s*(.+)$/);
|
|
30090
29574
|
if (!match) return void 0;
|
|
30091
|
-
gitDir =
|
|
29575
|
+
gitDir = resolve6(dir, match[1]);
|
|
30092
29576
|
}
|
|
30093
|
-
const head =
|
|
29577
|
+
const head = readFileSync17(join21(gitDir, "HEAD"), "utf8").trim();
|
|
30094
29578
|
const branchMatch = head.match(/^ref:\s*refs\/heads\/(.+)$/);
|
|
30095
29579
|
if (branchMatch) return branchMatch[1];
|
|
30096
29580
|
return /^[0-9a-f]{7,40}$/i.test(head) ? head.slice(0, 7) : void 0;
|
|
@@ -30112,14 +29596,14 @@ function listDocLevel(root, relDir = "", sort = "newest", showHidden = false) {
|
|
|
30112
29596
|
for (const entry of entries2) {
|
|
30113
29597
|
if (dirs.length + docs.length >= MAX_ENTRIES) break;
|
|
30114
29598
|
if (!showHidden && entry.name.startsWith(".")) continue;
|
|
30115
|
-
const abs =
|
|
29599
|
+
const abs = join21(absDir, entry.name);
|
|
30116
29600
|
const path = relative(root, abs).split(sep3).join("/");
|
|
30117
29601
|
const kind = entryKind(entry, abs);
|
|
30118
29602
|
if (kind === "dir") {
|
|
30119
29603
|
if (SKIP_DIRS.has(entry.name)) continue;
|
|
30120
29604
|
const probe = probeDir(abs, showHidden);
|
|
30121
29605
|
if (!probe.hasDocs && probe.hasOther) continue;
|
|
30122
|
-
const isRepo =
|
|
29606
|
+
const isRepo = existsSync19(join21(abs, ".git"));
|
|
30123
29607
|
dirs.push({
|
|
30124
29608
|
path,
|
|
30125
29609
|
name: entry.name,
|
|
@@ -30155,7 +29639,7 @@ function flatDocs(root, {
|
|
|
30155
29639
|
for (const entry of entries2) {
|
|
30156
29640
|
if (hits.length >= MAX_FLAT_DOCS) return;
|
|
30157
29641
|
if (!showHidden && entry.name.startsWith(".")) continue;
|
|
30158
|
-
const abs =
|
|
29642
|
+
const abs = join21(dir, entry.name);
|
|
30159
29643
|
const kind = entryKind(entry, abs);
|
|
30160
29644
|
if (kind === "dir") {
|
|
30161
29645
|
if (!SKIP_DIRS.has(entry.name)) walk(abs, depth + 1);
|
|
@@ -30175,7 +29659,7 @@ function flatDocs(root, {
|
|
|
30175
29659
|
}
|
|
30176
29660
|
function resolveDocPath(root, rel) {
|
|
30177
29661
|
if (!rel || rel.includes("\0")) return null;
|
|
30178
|
-
const abs =
|
|
29662
|
+
const abs = resolve6(root, rel);
|
|
30179
29663
|
if (abs !== root && !abs.startsWith(root + sep3)) return null;
|
|
30180
29664
|
const ext = extname2(abs).toLowerCase();
|
|
30181
29665
|
if (!(ext in DOC_EXTENSIONS) && !(ext in CODE_EXTENSIONS)) return null;
|
|
@@ -30197,12 +29681,12 @@ function writeDocContent(root, rel, content, baseMtime) {
|
|
|
30197
29681
|
if (Buffer.byteLength(content, "utf8") > MAX_CONTENT_BYTES) {
|
|
30198
29682
|
return { status: "too-large" };
|
|
30199
29683
|
}
|
|
30200
|
-
|
|
29684
|
+
writeFileSync7(abs, content, "utf8");
|
|
30201
29685
|
return { status: "ok", mtime: statSync7(abs).mtime.toISOString() };
|
|
30202
29686
|
}
|
|
30203
29687
|
function resolveRawPath(root, rel) {
|
|
30204
29688
|
if (!rel || rel.includes("\0")) return null;
|
|
30205
|
-
const abs =
|
|
29689
|
+
const abs = resolve6(root, rel);
|
|
30206
29690
|
if (abs !== root && !abs.startsWith(root + sep3)) return null;
|
|
30207
29691
|
const contentType = MEDIA_EXTENSIONS[extname2(abs).toLowerCase()];
|
|
30208
29692
|
if (!contentType) return null;
|
|
@@ -30210,14 +29694,14 @@ function resolveRawPath(root, rel) {
|
|
|
30210
29694
|
}
|
|
30211
29695
|
function resolveHtmlPath(root, rel) {
|
|
30212
29696
|
if (!rel || rel.includes("\0")) return null;
|
|
30213
|
-
const abs =
|
|
29697
|
+
const abs = resolve6(root, rel);
|
|
30214
29698
|
if (abs !== root && !abs.startsWith(root + sep3)) return null;
|
|
30215
29699
|
if (DOC_EXTENSIONS[extname2(abs).toLowerCase()] !== "html") return null;
|
|
30216
29700
|
return abs;
|
|
30217
29701
|
}
|
|
30218
29702
|
function resolveDownloadPath(root, rel) {
|
|
30219
29703
|
if (!rel || rel.includes("\0")) return null;
|
|
30220
|
-
const abs =
|
|
29704
|
+
const abs = resolve6(root, rel);
|
|
30221
29705
|
if (abs !== root && !abs.startsWith(root + sep3)) return null;
|
|
30222
29706
|
if (!isListableFile(basename6(abs))) return null;
|
|
30223
29707
|
const contentType = MEDIA_EXTENSIONS[extname2(abs).toLowerCase()] ?? "application/octet-stream";
|
|
@@ -30235,7 +29719,7 @@ function uniqueName(absDir, name) {
|
|
|
30235
29719
|
let candidate = name;
|
|
30236
29720
|
for (let n = 1; n < 1e3; n++) {
|
|
30237
29721
|
try {
|
|
30238
|
-
statSync7(
|
|
29722
|
+
statSync7(join21(absDir, candidate));
|
|
30239
29723
|
} catch {
|
|
30240
29724
|
return candidate;
|
|
30241
29725
|
}
|
|
@@ -30257,8 +29741,8 @@ function saveUploadedFile(root, relDir, name, data) {
|
|
|
30257
29741
|
if (!(ext in DOC_EXTENSIONS) && !ASSET_LIST_EXTENSIONS.has(ext)) return { status: "bad-type" };
|
|
30258
29742
|
if (data.byteLength > MAX_UPLOAD_BYTES) return { status: "too-large" };
|
|
30259
29743
|
const final = uniqueName(absDir, safe);
|
|
30260
|
-
const abs =
|
|
30261
|
-
|
|
29744
|
+
const abs = join21(absDir, final);
|
|
29745
|
+
writeFileSync7(abs, data);
|
|
30262
29746
|
return { status: "ok", path: relative(root, abs).split(sep3).join("/"), name: final };
|
|
30263
29747
|
}
|
|
30264
29748
|
function createDocFolder(root, relDir, name) {
|
|
@@ -30271,13 +29755,13 @@ function createDocFolder(root, relDir, name) {
|
|
|
30271
29755
|
}
|
|
30272
29756
|
const safe = sanitizeUploadName(name);
|
|
30273
29757
|
if (!safe) return { status: "bad-name" };
|
|
30274
|
-
const abs =
|
|
29758
|
+
const abs = join21(absDir, safe);
|
|
30275
29759
|
try {
|
|
30276
29760
|
statSync7(abs);
|
|
30277
29761
|
return { status: "exists" };
|
|
30278
29762
|
} catch {
|
|
30279
29763
|
}
|
|
30280
|
-
|
|
29764
|
+
mkdirSync8(abs);
|
|
30281
29765
|
return { status: "ok", path: relative(root, abs).split(sep3).join("/"), name: safe };
|
|
30282
29766
|
}
|
|
30283
29767
|
function createDocFile(root, relDir, name, content) {
|
|
@@ -30294,9 +29778,9 @@ function createDocFile(root, relDir, name, content) {
|
|
|
30294
29778
|
if (!(ext in DOC_EXTENSIONS) && !(ext in CODE_EXTENSIONS)) return { status: "bad-name" };
|
|
30295
29779
|
if (SKIP_FILES.has(safe)) return { status: "bad-name" };
|
|
30296
29780
|
if (Buffer.byteLength(content, "utf8") > MAX_CONTENT_BYTES) return { status: "too-large" };
|
|
30297
|
-
const abs =
|
|
29781
|
+
const abs = join21(absDir, safe);
|
|
30298
29782
|
try {
|
|
30299
|
-
|
|
29783
|
+
writeFileSync7(abs, content, { encoding: "utf8", flag: "wx" });
|
|
30300
29784
|
} catch (err) {
|
|
30301
29785
|
if (err.code === "EEXIST") return { status: "exists" };
|
|
30302
29786
|
throw err;
|
|
@@ -30305,7 +29789,7 @@ function createDocFile(root, relDir, name, content) {
|
|
|
30305
29789
|
}
|
|
30306
29790
|
function moveDocEntry(root, from, to) {
|
|
30307
29791
|
if (!from || !to || from.includes("\0") || to.includes("\0")) return { status: "not-found" };
|
|
30308
|
-
const absFrom =
|
|
29792
|
+
const absFrom = resolve6(root, from);
|
|
30309
29793
|
if (!absFrom.startsWith(root + sep3)) return { status: "not-found" };
|
|
30310
29794
|
let stat;
|
|
30311
29795
|
try {
|
|
@@ -30315,7 +29799,7 @@ function moveDocEntry(root, from, to) {
|
|
|
30315
29799
|
}
|
|
30316
29800
|
const isDir = stat.isDirectory();
|
|
30317
29801
|
if (!isDir && !stat.isFile()) return { status: "not-found" };
|
|
30318
|
-
const absTo =
|
|
29802
|
+
const absTo = resolve6(root, to);
|
|
30319
29803
|
if (!absTo.startsWith(root + sep3)) return { status: "bad-target" };
|
|
30320
29804
|
const name = sanitizeUploadName(basename6(absTo));
|
|
30321
29805
|
if (!name) return { status: "bad-target" };
|
|
@@ -30325,14 +29809,14 @@ function moveDocEntry(root, from, to) {
|
|
|
30325
29809
|
return { status: "bad-target" };
|
|
30326
29810
|
}
|
|
30327
29811
|
}
|
|
30328
|
-
const absToDir =
|
|
29812
|
+
const absToDir = dirname3(absTo);
|
|
30329
29813
|
if (resolveDirPath(root, relative(root, absToDir)) === null) return { status: "bad-target" };
|
|
30330
29814
|
try {
|
|
30331
29815
|
if (!statSync7(absToDir).isDirectory()) return { status: "bad-target" };
|
|
30332
29816
|
} catch {
|
|
30333
29817
|
return { status: "bad-target" };
|
|
30334
29818
|
}
|
|
30335
|
-
const finalAbs =
|
|
29819
|
+
const finalAbs = join21(absToDir, name);
|
|
30336
29820
|
if (isDir && (finalAbs === absFrom || finalAbs.startsWith(absFrom + sep3))) {
|
|
30337
29821
|
return { status: "into-self" };
|
|
30338
29822
|
}
|
|
@@ -30345,7 +29829,7 @@ function moveDocEntry(root, from, to) {
|
|
|
30345
29829
|
}
|
|
30346
29830
|
function deleteDocEntry(root, path) {
|
|
30347
29831
|
if (!path || path.includes("\0")) return { status: "not-found" };
|
|
30348
|
-
const abs =
|
|
29832
|
+
const abs = resolve6(root, path);
|
|
30349
29833
|
if (!abs.startsWith(root + sep3)) return { status: "not-found" };
|
|
30350
29834
|
let stat;
|
|
30351
29835
|
try {
|
|
@@ -30355,7 +29839,7 @@ function deleteDocEntry(root, path) {
|
|
|
30355
29839
|
}
|
|
30356
29840
|
const isDir = stat.isDirectory();
|
|
30357
29841
|
if (!isDir && !stat.isFile() && !stat.isSymbolicLink()) return { status: "not-found" };
|
|
30358
|
-
|
|
29842
|
+
rmSync10(abs, { recursive: isDir });
|
|
30359
29843
|
return {
|
|
30360
29844
|
status: "ok",
|
|
30361
29845
|
path: relative(root, abs).split(sep3).join("/"),
|
|
@@ -30416,7 +29900,7 @@ function createDocsRouter({ gate = requireDocsAccess } = {}) {
|
|
|
30416
29900
|
}
|
|
30417
29901
|
if (!stat.isFile()) return c.json({ error: "not found" }, 404);
|
|
30418
29902
|
if (stat.size > MAX_RAW_BYTES) return c.json({ error: "file too large" }, 413);
|
|
30419
|
-
return c.body(withDocLinkBridge(
|
|
29903
|
+
return c.body(withDocLinkBridge(readFileSync17(abs, "utf8")), 200, {
|
|
30420
29904
|
"Content-Type": "text/html; charset=utf-8",
|
|
30421
29905
|
"Content-Security-Policy": HTML_SHARE_CSP,
|
|
30422
29906
|
"X-Content-Type-Options": "nosniff",
|
|
@@ -30601,7 +30085,7 @@ function createDocsRouter({ gate = requireDocsAccess } = {}) {
|
|
|
30601
30085
|
title: kind ? extractTitle(abs, kind) : basename6(abs),
|
|
30602
30086
|
mtime: stat.mtime.toISOString(),
|
|
30603
30087
|
tooLarge: tooLarge || void 0,
|
|
30604
|
-
content: tooLarge ? "" :
|
|
30088
|
+
content: tooLarge ? "" : readFileSync17(abs, "utf8")
|
|
30605
30089
|
});
|
|
30606
30090
|
});
|
|
30607
30091
|
app.put("/:id/docs/content", async (c) => {
|
|
@@ -30644,7 +30128,7 @@ function createDocsRouter({ gate = requireDocsAccess } = {}) {
|
|
|
30644
30128
|
channel,
|
|
30645
30129
|
rel,
|
|
30646
30130
|
title: extractTitle(abs, "md"),
|
|
30647
|
-
content:
|
|
30131
|
+
content: readFileSync17(abs, "utf8")
|
|
30648
30132
|
};
|
|
30649
30133
|
};
|
|
30650
30134
|
app.get("/:id/docs/translation/:lang", async (c) => {
|
|
@@ -30702,7 +30186,7 @@ function withDocLinkBridge(html) {
|
|
|
30702
30186
|
var DOC_MENTION_RE = /(?<![\w@/`])@((?:[\w.-]+\/)+[\w.-]+\.[A-Za-z0-9]{1,6})(?::(\d+))?(?![\w-])/g;
|
|
30703
30187
|
function isRealDoc(root, rel) {
|
|
30704
30188
|
const abs = resolveDocPath(root, rel);
|
|
30705
|
-
if (!abs || !
|
|
30189
|
+
if (!abs || !existsSync20(abs)) return false;
|
|
30706
30190
|
try {
|
|
30707
30191
|
return statSync8(abs).isFile();
|
|
30708
30192
|
} catch {
|
|
@@ -32142,22 +31626,22 @@ ${msg.body}` : expandSkillCommand(channelConfig.claudeConfigDir, channelConfig.c
|
|
|
32142
31626
|
let ready;
|
|
32143
31627
|
try {
|
|
32144
31628
|
channel = this.supabase().channel(`agent-thinking:${threadId}`);
|
|
32145
|
-
ready = new Promise((
|
|
31629
|
+
ready = new Promise((resolve7) => {
|
|
32146
31630
|
const timeout = setTimeout(() => {
|
|
32147
31631
|
console.error(`[chat-agent] thinking-channel ${threadId}: subscribe timed out after 10s`);
|
|
32148
|
-
|
|
31632
|
+
resolve7(false);
|
|
32149
31633
|
}, 1e4);
|
|
32150
31634
|
channel.subscribe((status, err) => {
|
|
32151
31635
|
if (status === "SUBSCRIBED") {
|
|
32152
31636
|
clearTimeout(timeout);
|
|
32153
|
-
|
|
31637
|
+
resolve7(true);
|
|
32154
31638
|
} else if (status === "CHANNEL_ERROR" || status === "TIMED_OUT" || status === "CLOSED") {
|
|
32155
31639
|
console.error(
|
|
32156
31640
|
`[chat-agent] thinking-channel ${threadId}: ${status}`,
|
|
32157
31641
|
err?.message ?? ""
|
|
32158
31642
|
);
|
|
32159
31643
|
clearTimeout(timeout);
|
|
32160
|
-
|
|
31644
|
+
resolve7(false);
|
|
32161
31645
|
}
|
|
32162
31646
|
});
|
|
32163
31647
|
});
|
|
@@ -32167,9 +31651,9 @@ ${msg.body}` : expandSkillCommand(channelConfig.claudeConfigDir, channelConfig.c
|
|
|
32167
31651
|
}, activity: () => {
|
|
32168
31652
|
} };
|
|
32169
31653
|
}
|
|
32170
|
-
let
|
|
31654
|
+
let pending = ready;
|
|
32171
31655
|
const send = (event, payload, last = false) => {
|
|
32172
|
-
|
|
31656
|
+
pending = pending.then(async (subscribed) => {
|
|
32173
31657
|
if (subscribed) {
|
|
32174
31658
|
const res = await channel.send({ type: "broadcast", event, payload }).catch((err) => err.message);
|
|
32175
31659
|
if (res !== "ok") {
|
|
@@ -32179,7 +31663,7 @@ ${msg.body}` : expandSkillCommand(channelConfig.claudeConfigDir, channelConfig.c
|
|
|
32179
31663
|
return subscribed;
|
|
32180
31664
|
}).catch(() => false);
|
|
32181
31665
|
if (last) {
|
|
32182
|
-
void
|
|
31666
|
+
void pending.finally(() => void this.supabase().removeChannel(channel));
|
|
32183
31667
|
}
|
|
32184
31668
|
};
|
|
32185
31669
|
return {
|
|
@@ -32204,19 +31688,19 @@ ${msg.body}` : expandSkillCommand(channelConfig.claudeConfigDir, channelConfig.c
|
|
|
32204
31688
|
let ready;
|
|
32205
31689
|
try {
|
|
32206
31690
|
channel = this.supabase().channel("channel-activity");
|
|
32207
|
-
ready = new Promise((
|
|
31691
|
+
ready = new Promise((resolve7) => {
|
|
32208
31692
|
const timeout = setTimeout(() => {
|
|
32209
31693
|
console.error("[chat-agent] channel-activity: subscribe timed out after 10s");
|
|
32210
|
-
|
|
31694
|
+
resolve7(false);
|
|
32211
31695
|
}, 1e4);
|
|
32212
31696
|
channel.subscribe((status, err) => {
|
|
32213
31697
|
if (status === "SUBSCRIBED") {
|
|
32214
31698
|
clearTimeout(timeout);
|
|
32215
|
-
|
|
31699
|
+
resolve7(true);
|
|
32216
31700
|
} else if (status === "CHANNEL_ERROR" || status === "TIMED_OUT" || status === "CLOSED") {
|
|
32217
31701
|
console.error(`[chat-agent] channel-activity: ${status}`, err?.message ?? "");
|
|
32218
31702
|
clearTimeout(timeout);
|
|
32219
|
-
|
|
31703
|
+
resolve7(false);
|
|
32220
31704
|
}
|
|
32221
31705
|
});
|
|
32222
31706
|
});
|
|
@@ -32226,9 +31710,9 @@ ${msg.body}` : expandSkillCommand(channelConfig.claudeConfigDir, channelConfig.c
|
|
|
32226
31710
|
};
|
|
32227
31711
|
return this.channelActivitySend;
|
|
32228
31712
|
}
|
|
32229
|
-
let
|
|
31713
|
+
let pending = ready;
|
|
32230
31714
|
this.channelActivitySend = (event, payload) => {
|
|
32231
|
-
|
|
31715
|
+
pending = pending.then(async (subscribed) => {
|
|
32232
31716
|
if (subscribed) {
|
|
32233
31717
|
const res = await channel.send({ type: "broadcast", event, payload }).catch((err) => err.message);
|
|
32234
31718
|
if (res !== "ok") {
|
|
@@ -34147,7 +33631,7 @@ ${matched.prompt}`,
|
|
|
34147
33631
|
|
|
34148
33632
|
// src/store/automation-run-store.ts
|
|
34149
33633
|
import Database3 from "better-sqlite3";
|
|
34150
|
-
import { randomUUID as
|
|
33634
|
+
import { randomUUID as randomUUID3 } from "crypto";
|
|
34151
33635
|
var LOG_RETENTION = 2e3;
|
|
34152
33636
|
var AutomationRunStore = class {
|
|
34153
33637
|
db;
|
|
@@ -34210,7 +33694,7 @@ var AutomationRunStore = class {
|
|
|
34210
33694
|
if (ids.length === 0) return;
|
|
34211
33695
|
const update = this.db.prepare("UPDATE automation_run_log SET row_uid = ? WHERE id = ?");
|
|
34212
33696
|
this.db.transaction(() => {
|
|
34213
|
-
for (const { id } of ids) update.run(
|
|
33697
|
+
for (const { id } of ids) update.run(randomUUID3(), id);
|
|
34214
33698
|
})();
|
|
34215
33699
|
}
|
|
34216
33700
|
getLastRun(name) {
|
|
@@ -34255,7 +33739,7 @@ var AutomationRunStore = class {
|
|
|
34255
33739
|
).run(name, when.toISOString(), status);
|
|
34256
33740
|
this.db.prepare(
|
|
34257
33741
|
"INSERT INTO automation_run_log (row_uid, name, run_at, status, duration_ms) VALUES (?, ?, ?, ?, ?)"
|
|
34258
|
-
).run(
|
|
33742
|
+
).run(randomUUID3(), name, when.toISOString(), status, durationMs ?? null);
|
|
34259
33743
|
const guard = this.holdUnsynced ? " AND synced_at IS NOT NULL" : "";
|
|
34260
33744
|
this.db.prepare(
|
|
34261
33745
|
`DELETE FROM automation_run_log
|
|
@@ -34528,18 +34012,18 @@ var ReactionStore = class {
|
|
|
34528
34012
|
};
|
|
34529
34013
|
|
|
34530
34014
|
// ../api/src/store/supabase-direct.ts
|
|
34531
|
-
import { createClient
|
|
34532
|
-
var
|
|
34015
|
+
import { createClient } from "@supabase/supabase-js";
|
|
34016
|
+
var REQUEST_TIMEOUT_MS2 = 15e3;
|
|
34533
34017
|
function createDirectSupabaseClient() {
|
|
34534
34018
|
const url = process.env["SUPABASE_URL"];
|
|
34535
34019
|
const key = process.env["SUPABASE_SECRET_KEY"];
|
|
34536
34020
|
if (!url || !key) {
|
|
34537
34021
|
throw new Error("SUPABASE_URL / SUPABASE_SECRET_KEY not set \u2014 check .env");
|
|
34538
34022
|
}
|
|
34539
|
-
return
|
|
34023
|
+
return createClient(url, key, {
|
|
34540
34024
|
auth: { persistSession: false },
|
|
34541
34025
|
global: {
|
|
34542
|
-
fetch: (input, init) => fetch(input, { ...init, signal: init?.signal ?? AbortSignal.timeout(
|
|
34026
|
+
fetch: (input, init) => fetch(input, { ...init, signal: init?.signal ?? AbortSignal.timeout(REQUEST_TIMEOUT_MS2) })
|
|
34543
34027
|
}
|
|
34544
34028
|
});
|
|
34545
34029
|
}
|
|
@@ -34639,12 +34123,12 @@ function startWatchdog(opts) {
|
|
|
34639
34123
|
// src/index.ts
|
|
34640
34124
|
var DRAIN_TIMEOUT_MS = 15e3;
|
|
34641
34125
|
async function recoverStaleReactions(client, reactionStore) {
|
|
34642
|
-
const
|
|
34643
|
-
if (
|
|
34126
|
+
const pending = reactionStore.listAll();
|
|
34127
|
+
if (pending.length === 0) return;
|
|
34644
34128
|
console.log(
|
|
34645
|
-
`[${ts2()}] [flyspace] clearing ${
|
|
34129
|
+
`[${ts2()}] [flyspace] clearing ${pending.length} stale reaction(s) from previous run`
|
|
34646
34130
|
);
|
|
34647
|
-
for (const r of
|
|
34131
|
+
for (const r of pending) {
|
|
34648
34132
|
try {
|
|
34649
34133
|
await client.reactions.remove({
|
|
34650
34134
|
channel: r.channelId,
|
|
@@ -34659,13 +34143,13 @@ async function recoverStaleReactions(client, reactionStore) {
|
|
|
34659
34143
|
var ts2 = () => (/* @__PURE__ */ new Date()).toISOString();
|
|
34660
34144
|
var POWER_POLL_MS = 3e4;
|
|
34661
34145
|
function isOnACPower() {
|
|
34662
|
-
return new Promise((
|
|
34146
|
+
return new Promise((resolve7) => {
|
|
34663
34147
|
execFile2("pmset", ["-g", "ps"], { timeout: 2e3 }, (err, stdout) => {
|
|
34664
34148
|
if (err) {
|
|
34665
|
-
|
|
34149
|
+
resolve7(true);
|
|
34666
34150
|
return;
|
|
34667
34151
|
}
|
|
34668
|
-
|
|
34152
|
+
resolve7(stdout.includes("'AC Power'"));
|
|
34669
34153
|
});
|
|
34670
34154
|
});
|
|
34671
34155
|
}
|
|
@@ -34774,8 +34258,8 @@ async function startServer() {
|
|
|
34774
34258
|
const shutdown = async (signal) => {
|
|
34775
34259
|
if (shuttingDown) return;
|
|
34776
34260
|
shuttingDown = true;
|
|
34777
|
-
const
|
|
34778
|
-
console.log(`[${ts2()}] [flyspace] shutting down (${signal}, ${
|
|
34261
|
+
const pending = slackRuntime?.listeners.pendingCount() ?? 0;
|
|
34262
|
+
console.log(`[${ts2()}] [flyspace] shutting down (${signal}, ${pending} thread queue(s))`);
|
|
34779
34263
|
if (slackRuntime) {
|
|
34780
34264
|
const drained = await slackRuntime.listeners.drain(DRAIN_TIMEOUT_MS);
|
|
34781
34265
|
if (!drained) {
|
|
@@ -34815,11 +34299,6 @@ export {
|
|
|
34815
34299
|
resolveUserId,
|
|
34816
34300
|
ensureUsersCached,
|
|
34817
34301
|
useLocalCache,
|
|
34818
|
-
loadEnvFiles,
|
|
34819
|
-
SLACK_ENV,
|
|
34820
|
-
slackConfigured,
|
|
34821
|
-
requireSlackBotToken,
|
|
34822
|
-
loadConfig,
|
|
34823
34302
|
getWorkspaceDomain,
|
|
34824
34303
|
insertWorkspaceDomain,
|
|
34825
34304
|
updateWorkspaceDomainStatus,
|
|
@@ -34907,33 +34386,6 @@ export {
|
|
|
34907
34386
|
DEFAULT_TIMEZONE,
|
|
34908
34387
|
loadAutomations,
|
|
34909
34388
|
loadEffectiveAutomations,
|
|
34910
|
-
DEFAULT_API_URL,
|
|
34911
|
-
AuthApiError,
|
|
34912
|
-
apiUrl,
|
|
34913
|
-
deviceKeyPath,
|
|
34914
|
-
credentialsPath,
|
|
34915
|
-
ensureDeviceKey,
|
|
34916
|
-
loadCredentials,
|
|
34917
|
-
saveCredentials,
|
|
34918
|
-
clearLocalAuth,
|
|
34919
|
-
requestDeviceCode,
|
|
34920
|
-
pollDeviceToken,
|
|
34921
|
-
fetchWhoAmI,
|
|
34922
|
-
boundWorkspaces,
|
|
34923
|
-
revokeDevice,
|
|
34924
|
-
getAccessToken,
|
|
34925
|
-
acquireHostLock,
|
|
34926
|
-
publishHostEndpoint,
|
|
34927
|
-
readHostEndpoint,
|
|
34928
|
-
setHostDbSender,
|
|
34929
|
-
handleHostDbResult,
|
|
34930
|
-
requestHostDb,
|
|
34931
|
-
handleAttachmentUrlResult,
|
|
34932
|
-
handlePluginSvgResult,
|
|
34933
|
-
handleShouldRespondResult,
|
|
34934
|
-
LOCAL_DB_PATH,
|
|
34935
|
-
createHostDbClient,
|
|
34936
|
-
useHostDbWithoutCredentials,
|
|
34937
34389
|
runPersonaCmd,
|
|
34938
34390
|
MEMORY_TYPES,
|
|
34939
34391
|
isMemoryType,
|