flyspace-cli 0.1.51 → 0.1.53
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-R5RECXRP.js → chunk-GX5467VC.js} +942 -851
- package/dist/cli.js +715 -144
- package/dist/index.js +1 -1
- package/package.json +2 -1
- package/system.capabilities.md +7 -36
- package/system.default.md +3 -3
- package/system.slack.md +28 -0
|
@@ -10390,7 +10390,7 @@ var require_ms = __commonJS({
|
|
|
10390
10390
|
options = options || {};
|
|
10391
10391
|
var type = typeof val;
|
|
10392
10392
|
if (type === "string" && val.length > 0) {
|
|
10393
|
-
return
|
|
10393
|
+
return parse2(val);
|
|
10394
10394
|
} else if (type === "number" && isFinite(val)) {
|
|
10395
10395
|
return options.long ? fmtLong(val) : fmtShort(val);
|
|
10396
10396
|
}
|
|
@@ -10398,7 +10398,7 @@ var require_ms = __commonJS({
|
|
|
10398
10398
|
"val is not a non-empty string or a valid number. val=" + JSON.stringify(val)
|
|
10399
10399
|
);
|
|
10400
10400
|
};
|
|
10401
|
-
function
|
|
10401
|
+
function parse2(str) {
|
|
10402
10402
|
str = String(str);
|
|
10403
10403
|
if (str.length > 100) {
|
|
10404
10404
|
return;
|
|
@@ -12978,10 +12978,10 @@ var require_axios = __commonJS({
|
|
|
12978
12978
|
}
|
|
12979
12979
|
};
|
|
12980
12980
|
var CanceledError$1 = CanceledError;
|
|
12981
|
-
function settle(
|
|
12981
|
+
function settle(resolve9, reject, response) {
|
|
12982
12982
|
const validateStatus = response.config.validateStatus;
|
|
12983
12983
|
if (!response.status || !validateStatus || validateStatus(response.status)) {
|
|
12984
|
-
|
|
12984
|
+
resolve9(response);
|
|
12985
12985
|
} else {
|
|
12986
12986
|
reject(
|
|
12987
12987
|
new AxiosError$1(
|
|
@@ -13573,7 +13573,7 @@ var require_axios = __commonJS({
|
|
|
13573
13573
|
}
|
|
13574
13574
|
var isHttpAdapterSupported = typeof process !== "undefined" && utils$1.kindOf(process) === "process";
|
|
13575
13575
|
var wrapAsync = (asyncExecutor) => {
|
|
13576
|
-
return new Promise((
|
|
13576
|
+
return new Promise((resolve9, reject) => {
|
|
13577
13577
|
let onDone;
|
|
13578
13578
|
let isDone;
|
|
13579
13579
|
const done = (value, isRejected) => {
|
|
@@ -13583,7 +13583,7 @@ var require_axios = __commonJS({
|
|
|
13583
13583
|
};
|
|
13584
13584
|
const _resolve = (value) => {
|
|
13585
13585
|
done(value);
|
|
13586
|
-
|
|
13586
|
+
resolve9(value);
|
|
13587
13587
|
};
|
|
13588
13588
|
const _reject = (reason) => {
|
|
13589
13589
|
done(reason, true);
|
|
@@ -13630,7 +13630,7 @@ var require_axios = __commonJS({
|
|
|
13630
13630
|
}
|
|
13631
13631
|
};
|
|
13632
13632
|
var httpAdapter = isHttpAdapterSupported && function httpAdapter2(config) {
|
|
13633
|
-
return wrapAsync(async function dispatchHttpRequest(
|
|
13633
|
+
return wrapAsync(async function dispatchHttpRequest(resolve9, reject, onDone) {
|
|
13634
13634
|
let { data, lookup: lookup2, family, httpVersion = 1, http2Options } = config;
|
|
13635
13635
|
const { responseType, responseEncoding } = config;
|
|
13636
13636
|
const method = config.method.toUpperCase();
|
|
@@ -13720,7 +13720,7 @@ var require_axios = __commonJS({
|
|
|
13720
13720
|
}
|
|
13721
13721
|
let convertedData;
|
|
13722
13722
|
if (method !== "GET") {
|
|
13723
|
-
return settle(
|
|
13723
|
+
return settle(resolve9, reject, {
|
|
13724
13724
|
status: 405,
|
|
13725
13725
|
statusText: "method not allowed",
|
|
13726
13726
|
headers: {},
|
|
@@ -13742,7 +13742,7 @@ var require_axios = __commonJS({
|
|
|
13742
13742
|
} else if (responseType === "stream") {
|
|
13743
13743
|
convertedData = stream__default["default"].Readable.from(convertedData);
|
|
13744
13744
|
}
|
|
13745
|
-
return settle(
|
|
13745
|
+
return settle(resolve9, reject, {
|
|
13746
13746
|
data: convertedData,
|
|
13747
13747
|
status: 200,
|
|
13748
13748
|
statusText: "OK",
|
|
@@ -13983,7 +13983,7 @@ var require_axios = __commonJS({
|
|
|
13983
13983
|
};
|
|
13984
13984
|
if (responseType === "stream") {
|
|
13985
13985
|
response.data = responseStream;
|
|
13986
|
-
settle(
|
|
13986
|
+
settle(resolve9, reject, response);
|
|
13987
13987
|
} else {
|
|
13988
13988
|
const responseBuffer = [];
|
|
13989
13989
|
let totalResponseBytes = 0;
|
|
@@ -14033,7 +14033,7 @@ var require_axios = __commonJS({
|
|
|
14033
14033
|
} catch (err) {
|
|
14034
14034
|
return reject(AxiosError$1.from(err, null, config, response.request, response));
|
|
14035
14035
|
}
|
|
14036
|
-
settle(
|
|
14036
|
+
settle(resolve9, reject, response);
|
|
14037
14037
|
});
|
|
14038
14038
|
}
|
|
14039
14039
|
abortEmitter.once("abort", (err) => {
|
|
@@ -14283,7 +14283,7 @@ var require_axios = __commonJS({
|
|
|
14283
14283
|
};
|
|
14284
14284
|
var isXHRAdapterSupported = typeof XMLHttpRequest !== "undefined";
|
|
14285
14285
|
var xhrAdapter = isXHRAdapterSupported && function(config) {
|
|
14286
|
-
return new Promise(function dispatchXhrRequest(
|
|
14286
|
+
return new Promise(function dispatchXhrRequest(resolve9, reject) {
|
|
14287
14287
|
const _config = resolveConfig(config);
|
|
14288
14288
|
let requestData = _config.data;
|
|
14289
14289
|
const requestHeaders = AxiosHeaders$1.from(_config.headers).normalize();
|
|
@@ -14318,7 +14318,7 @@ var require_axios = __commonJS({
|
|
|
14318
14318
|
};
|
|
14319
14319
|
settle(
|
|
14320
14320
|
function _resolve(value) {
|
|
14321
|
-
|
|
14321
|
+
resolve9(value);
|
|
14322
14322
|
done();
|
|
14323
14323
|
},
|
|
14324
14324
|
function _reject(err) {
|
|
@@ -14710,8 +14710,8 @@ var require_axios = __commonJS({
|
|
|
14710
14710
|
config
|
|
14711
14711
|
);
|
|
14712
14712
|
!isStreamResponse && unsubscribe && unsubscribe();
|
|
14713
|
-
return await new Promise((
|
|
14714
|
-
settle(
|
|
14713
|
+
return await new Promise((resolve9, reject) => {
|
|
14714
|
+
settle(resolve9, reject, {
|
|
14715
14715
|
data: responseData,
|
|
14716
14716
|
headers: AxiosHeaders$1.from(response.headers),
|
|
14717
14717
|
status: response.status,
|
|
@@ -15115,8 +15115,8 @@ var require_axios = __commonJS({
|
|
|
15115
15115
|
throw new TypeError("executor must be a function.");
|
|
15116
15116
|
}
|
|
15117
15117
|
let resolvePromise;
|
|
15118
|
-
this.promise = new Promise(function promiseExecutor(
|
|
15119
|
-
resolvePromise =
|
|
15118
|
+
this.promise = new Promise(function promiseExecutor(resolve9) {
|
|
15119
|
+
resolvePromise = resolve9;
|
|
15120
15120
|
});
|
|
15121
15121
|
const token = this;
|
|
15122
15122
|
this.promise.then((cancel) => {
|
|
@@ -15129,9 +15129,9 @@ var require_axios = __commonJS({
|
|
|
15129
15129
|
});
|
|
15130
15130
|
this.promise.then = (onfulfilled) => {
|
|
15131
15131
|
let _resolve;
|
|
15132
|
-
const promise = new Promise((
|
|
15133
|
-
token.subscribe(
|
|
15134
|
-
_resolve =
|
|
15132
|
+
const promise = new Promise((resolve9) => {
|
|
15133
|
+
token.subscribe(resolve9);
|
|
15134
|
+
_resolve = resolve9;
|
|
15135
15135
|
}).then(onfulfilled);
|
|
15136
15136
|
promise.cancel = function reject() {
|
|
15137
15137
|
token.unsubscribe(_resolve);
|
|
@@ -17417,7 +17417,7 @@ var require_MsEdgeTTS = __commonJS({
|
|
|
17417
17417
|
};
|
|
17418
17418
|
const ws = this._ws = this._isBrowser ? new isomorphic_ws_1.default(synthUrl) : new isomorphic_ws_1.default(synthUrl, { ...options, agent: this._agent });
|
|
17419
17419
|
ws.binaryType = "arraybuffer";
|
|
17420
|
-
return new Promise((
|
|
17420
|
+
return new Promise((resolve9, reject) => {
|
|
17421
17421
|
let connecting = true;
|
|
17422
17422
|
const connectionTimeout = this._connectionTimeoutMs ? setTimeout(() => {
|
|
17423
17423
|
connecting = false;
|
|
@@ -17460,7 +17460,7 @@ Path:${messageTypes.SPEECH_CONFIG}${_MsEdgeTTS.JSON_XML_DELIM}
|
|
|
17460
17460
|
}
|
|
17461
17461
|
}
|
|
17462
17462
|
}
|
|
17463
|
-
`, void 0, ws).then(
|
|
17463
|
+
`, void 0, ws).then(resolve9, (error) => {
|
|
17464
17464
|
this._closeSocket(ws);
|
|
17465
17465
|
reject(error);
|
|
17466
17466
|
});
|
|
@@ -17602,12 +17602,12 @@ Path:${messageTypes.SPEECH_CONFIG}${_MsEdgeTTS.JSON_XML_DELIM}
|
|
|
17602
17602
|
this._log("<-", message);
|
|
17603
17603
|
return;
|
|
17604
17604
|
}
|
|
17605
|
-
await new Promise((
|
|
17605
|
+
await new Promise((resolve9, reject) => {
|
|
17606
17606
|
socket.send(message, (error) => {
|
|
17607
17607
|
if (error)
|
|
17608
17608
|
return reject(error);
|
|
17609
17609
|
this._log("<-", message);
|
|
17610
|
-
|
|
17610
|
+
resolve9();
|
|
17611
17611
|
});
|
|
17612
17612
|
});
|
|
17613
17613
|
}
|
|
@@ -17643,8 +17643,8 @@ Path:${messageTypes.SPEECH_CONFIG}${_MsEdgeTTS.JSON_XML_DELIM}
|
|
|
17643
17643
|
* 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).
|
|
17644
17644
|
*/
|
|
17645
17645
|
getVoices() {
|
|
17646
|
-
return new Promise((
|
|
17647
|
-
axios_1.default.get(_MsEdgeTTS.VOICES_URL).then((res) =>
|
|
17646
|
+
return new Promise((resolve9, reject) => {
|
|
17647
|
+
axios_1.default.get(_MsEdgeTTS.VOICES_URL).then((res) => resolve9(res.data)).catch(reject);
|
|
17648
17648
|
});
|
|
17649
17649
|
}
|
|
17650
17650
|
/**
|
|
@@ -17747,7 +17747,7 @@ Path:${messageTypes.SPEECH_CONFIG}${_MsEdgeTTS.JSON_XML_DELIM}
|
|
|
17747
17747
|
const metadataFilePath = !!metadataStream ? (0, utils_1.joinPath)(dirPath, "metadata.json") : null;
|
|
17748
17748
|
try {
|
|
17749
17749
|
await Promise.all([
|
|
17750
|
-
new Promise((
|
|
17750
|
+
new Promise((resolve9, reject) => {
|
|
17751
17751
|
const writableAudioFile = audioStream.pipe(fs.createWriteStream(audioFilePath));
|
|
17752
17752
|
audioStream.once("error", (e) => {
|
|
17753
17753
|
writableAudioFile.destroy();
|
|
@@ -17755,7 +17755,7 @@ Path:${messageTypes.SPEECH_CONFIG}${_MsEdgeTTS.JSON_XML_DELIM}
|
|
|
17755
17755
|
});
|
|
17756
17756
|
writableAudioFile.once("close", async () => {
|
|
17757
17757
|
if (writableAudioFile.bytesWritten > 0) {
|
|
17758
|
-
|
|
17758
|
+
resolve9(audioFilePath);
|
|
17759
17759
|
} else {
|
|
17760
17760
|
reject(new Error("No audio data received"));
|
|
17761
17761
|
fs.rmSync(audioFilePath, { force: true });
|
|
@@ -17763,9 +17763,9 @@ Path:${messageTypes.SPEECH_CONFIG}${_MsEdgeTTS.JSON_XML_DELIM}
|
|
|
17763
17763
|
});
|
|
17764
17764
|
writableAudioFile.once("error", reject);
|
|
17765
17765
|
}),
|
|
17766
|
-
new Promise((
|
|
17766
|
+
new Promise((resolve9, reject) => {
|
|
17767
17767
|
if (!metadataFilePath) {
|
|
17768
|
-
return
|
|
17768
|
+
return resolve9(null);
|
|
17769
17769
|
}
|
|
17770
17770
|
const metadataItems = { Metadata: [] };
|
|
17771
17771
|
metadataStream.on("data", (chunk) => {
|
|
@@ -17775,7 +17775,7 @@ Path:${messageTypes.SPEECH_CONFIG}${_MsEdgeTTS.JSON_XML_DELIM}
|
|
|
17775
17775
|
metadataStream.once("close", () => {
|
|
17776
17776
|
if (metadataItems.Metadata.length > 0) {
|
|
17777
17777
|
fs.writeFileSync(metadataFilePath, JSON.stringify(metadataItems, null, 2));
|
|
17778
|
-
|
|
17778
|
+
resolve9(metadataFilePath);
|
|
17779
17779
|
} else {
|
|
17780
17780
|
reject(new Error("No metadata received"));
|
|
17781
17781
|
fs.rmSync(metadataFilePath, { force: true });
|
|
@@ -17964,7 +17964,7 @@ function loadConfig() {
|
|
|
17964
17964
|
claudeCwd: process.env["CLAUDE_CWD"] ?? process.cwd(),
|
|
17965
17965
|
claudeConfigDir: process.env["CLAUDE_CONFIG_DIR"] || void 0,
|
|
17966
17966
|
claudeCodeOauthToken: process.env["CLAUDE_CODE_OAUTH_TOKEN"] || void 0,
|
|
17967
|
-
botName: process.env["BOT_NAME"] ?? "
|
|
17967
|
+
botName: process.env["BOT_NAME"] ?? "Bot",
|
|
17968
17968
|
allowedUserIds,
|
|
17969
17969
|
maxTurns: parseInt(process.env["MAX_TURNS"] ?? "10", 10),
|
|
17970
17970
|
model: process.env["CUSTIE_MODEL"]?.trim() || "sonnet",
|
|
@@ -18121,6 +18121,7 @@ function stopAutomationRegistryPolling() {
|
|
|
18121
18121
|
}
|
|
18122
18122
|
|
|
18123
18123
|
// ../api/src/channels.ts
|
|
18124
|
+
import { createHash } from "crypto";
|
|
18124
18125
|
import { existsSync as existsSync2, mkdirSync, realpathSync, statSync } from "fs";
|
|
18125
18126
|
import { homedir } from "os";
|
|
18126
18127
|
import { isAbsolute, relative, resolve as resolve2, sep } from "path";
|
|
@@ -18310,8 +18311,15 @@ function findChannelById(id) {
|
|
|
18310
18311
|
function findChannelByExternalId(externalId) {
|
|
18311
18312
|
return byExternalId.get(externalId);
|
|
18312
18313
|
}
|
|
18313
|
-
function
|
|
18314
|
-
return
|
|
18314
|
+
function agentDmKey(agentName, userId) {
|
|
18315
|
+
return `agent:${agentName}:${userId}`;
|
|
18316
|
+
}
|
|
18317
|
+
function dmCwd(dmKey, profile = getProfile()) {
|
|
18318
|
+
return `${profile}/dm-${createHash("sha256").update(dmKey).digest("hex").slice(0, 24)}`;
|
|
18319
|
+
}
|
|
18320
|
+
function findChannelByAgentName(agentName, userId) {
|
|
18321
|
+
const dmKey = agentDmKey(agentName, userId);
|
|
18322
|
+
return getProfileChannelRegistry().find((c) => c.agentName === agentName && c.dmKey === dmKey);
|
|
18315
18323
|
}
|
|
18316
18324
|
function findChannel(ref) {
|
|
18317
18325
|
if (!ref) return void 0;
|
|
@@ -18577,28 +18585,24 @@ async function ensureChannelProvisioned(externalChannelId, opts = {}) {
|
|
|
18577
18585
|
throw err;
|
|
18578
18586
|
}
|
|
18579
18587
|
}
|
|
18580
|
-
async function
|
|
18581
|
-
const
|
|
18582
|
-
|
|
18583
|
-
|
|
18584
|
-
).select().single();
|
|
18585
|
-
if (error) throw new Error(error.message);
|
|
18586
|
-
if (data.profile !== getProfile()) {
|
|
18587
|
-
throw new Error(`agent DM upsert for ${input.agentName} resolved to another workspace's channel`);
|
|
18588
|
+
async function ensureAgentDmChannel(agentName, viewer, opts) {
|
|
18589
|
+
const existing = findChannelByAgentName(agentName, viewer.userId);
|
|
18590
|
+
if (existing) {
|
|
18591
|
+
return existing.name === opts.name ? existing : updateChannelById(existing.id, { name: opts.name });
|
|
18588
18592
|
}
|
|
18589
|
-
|
|
18590
|
-
return rowToChannel(data);
|
|
18591
|
-
}
|
|
18592
|
-
async function ensureAgentDmChannel(agentName, opts) {
|
|
18593
|
+
const dmKey = agentDmKey(agentName, viewer.userId);
|
|
18593
18594
|
try {
|
|
18594
|
-
return await
|
|
18595
|
+
return await createChannel({
|
|
18595
18596
|
name: opts.name,
|
|
18596
|
-
cwd:
|
|
18597
|
-
|
|
18597
|
+
cwd: dmCwd(dmKey),
|
|
18598
|
+
visibility: "private",
|
|
18599
|
+
memberEmails: [viewer.email],
|
|
18600
|
+
agentName,
|
|
18601
|
+
dmKey
|
|
18598
18602
|
});
|
|
18599
18603
|
} catch (err) {
|
|
18600
18604
|
await refreshChannelRegistry();
|
|
18601
|
-
const raced = findChannelByAgentName(agentName);
|
|
18605
|
+
const raced = findChannelByAgentName(agentName, viewer.userId);
|
|
18602
18606
|
if (raced) return raced;
|
|
18603
18607
|
throw err;
|
|
18604
18608
|
}
|
|
@@ -18629,7 +18633,9 @@ async function ensureMemberDmChannel(a, b) {
|
|
|
18629
18633
|
try {
|
|
18630
18634
|
return await createChannel({
|
|
18631
18635
|
name: `${a.handle}, ${b.handle}`,
|
|
18632
|
-
|
|
18636
|
+
// Hash the whole key: a prefix of the sorted ids is just the first user's
|
|
18637
|
+
// id, which put every DM that user sorts first in into one shared folder.
|
|
18638
|
+
cwd: dmCwd(dmKey),
|
|
18633
18639
|
visibility: "private",
|
|
18634
18640
|
memberEmails: [a.email, b.email],
|
|
18635
18641
|
dmKey
|
|
@@ -18835,7 +18841,7 @@ function modelLabel(value) {
|
|
|
18835
18841
|
|
|
18836
18842
|
// src/claude/container.ts
|
|
18837
18843
|
import { execFileSync } from "child_process";
|
|
18838
|
-
import { createHash } from "crypto";
|
|
18844
|
+
import { createHash as createHash2 } from "crypto";
|
|
18839
18845
|
import { existsSync as existsSync4, mkdirSync as mkdirSync3 } from "fs";
|
|
18840
18846
|
import { join as join2 } from "path";
|
|
18841
18847
|
|
|
@@ -18934,7 +18940,7 @@ function memoryLimit() {
|
|
|
18934
18940
|
return process.env["FLYSPACE_AGENT_MEMORY"]?.trim() || "2g";
|
|
18935
18941
|
}
|
|
18936
18942
|
function containerHomeFor(cwd) {
|
|
18937
|
-
const digest =
|
|
18943
|
+
const digest = createHash2("sha256").update(cwd).digest("hex").slice(0, 12);
|
|
18938
18944
|
const label = (cwd.split("/").pop() || "channel").replace(/[^a-zA-Z0-9._-]/g, "-").slice(0, 32);
|
|
18939
18945
|
return join2(paths.CONTAINER_HOMES_DIR, `${label}-${digest}`);
|
|
18940
18946
|
}
|
|
@@ -19055,14 +19061,14 @@ function userFlags() {
|
|
|
19055
19061
|
|
|
19056
19062
|
// src/claude/sandbox.ts
|
|
19057
19063
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
19058
|
-
import { createHash as
|
|
19064
|
+
import { createHash as createHash3 } from "crypto";
|
|
19059
19065
|
import { existsSync as existsSync5, mkdirSync as mkdirSync4, writeFileSync } from "fs";
|
|
19060
19066
|
import { join as join3 } from "path";
|
|
19061
19067
|
function sandboxRuntimeEntrypoint() {
|
|
19062
19068
|
return join3(paths.PACKAGE_ROOT, "node_modules/@anthropic-ai/sandbox-runtime/dist/cli.js");
|
|
19063
19069
|
}
|
|
19064
19070
|
function sandboxHomeFor(cwd) {
|
|
19065
|
-
const digest =
|
|
19071
|
+
const digest = createHash3("sha256").update(cwd).digest("hex").slice(0, 12);
|
|
19066
19072
|
const label = (cwd.split("/").pop() || "channel").replace(/[^a-zA-Z0-9._-]/g, "-").slice(0, 32);
|
|
19067
19073
|
return join3(paths.SANDBOX_HOMES_DIR, `${label}-${digest}`);
|
|
19068
19074
|
}
|
|
@@ -19619,11 +19625,10 @@ function extractUsage(result) {
|
|
|
19619
19625
|
outputTokens: usage.output_tokens ?? 0,
|
|
19620
19626
|
cacheReadTokens: usage.cache_read_input_tokens ?? 0,
|
|
19621
19627
|
cacheCreationTokens: usage.cache_creation_input_tokens ?? 0,
|
|
19622
|
-
|
|
19623
|
-
//
|
|
19624
|
-
//
|
|
19625
|
-
|
|
19626
|
-
...result.total_cost_usd != null ? { costSource: "reported" } : {},
|
|
19628
|
+
// Not `total_cost_usd`: on a resumed session it is the running total for
|
|
19629
|
+
// the whole session, so recording it per run counted earlier runs again
|
|
19630
|
+
// (a $13 thread showed $72). The store prices this run's tokens instead.
|
|
19631
|
+
costUsd: 0,
|
|
19627
19632
|
...primaryModel(result.modelUsage) ? { model: primaryModel(result.modelUsage) } : {},
|
|
19628
19633
|
...result.duration_ms != null ? { durationMs: result.duration_ms } : {},
|
|
19629
19634
|
...result.num_turns != null ? { numTurns: result.num_turns } : {}
|
|
@@ -19728,14 +19733,20 @@ function loadSystemPrompt() {
|
|
|
19728
19733
|
const filePath = existsSync7(customPath) ? customPath : defaultPath;
|
|
19729
19734
|
return readFileSync2(filePath, "utf-8").trim();
|
|
19730
19735
|
}
|
|
19731
|
-
function
|
|
19732
|
-
const
|
|
19733
|
-
if (!existsSync7(
|
|
19734
|
-
return readFileSync2(
|
|
19736
|
+
function loadPackagePrompt(file) {
|
|
19737
|
+
const filePath = resolve4(paths.PACKAGE_ROOT, file);
|
|
19738
|
+
if (!existsSync7(filePath)) return "";
|
|
19739
|
+
return readFileSync2(filePath, "utf-8").trim();
|
|
19740
|
+
}
|
|
19741
|
+
function loadCapabilities(slackBound) {
|
|
19742
|
+
return [
|
|
19743
|
+
loadPackagePrompt("system.capabilities.md"),
|
|
19744
|
+
slackBound ? loadPackagePrompt("system.slack.md") : ""
|
|
19745
|
+
].filter(Boolean).join("\n\n");
|
|
19735
19746
|
}
|
|
19736
|
-
function buildSystemPrompt(botName, agentPersona, channelPrompt, outputStyle) {
|
|
19747
|
+
function buildSystemPrompt(botName, agentPersona, channelPrompt, outputStyle, slackBound = true) {
|
|
19737
19748
|
const prompt = loadSystemPrompt().replaceAll("{{botName}}", botName);
|
|
19738
|
-
const capabilities = loadCapabilities();
|
|
19749
|
+
const capabilities = loadCapabilities(slackBound);
|
|
19739
19750
|
const withCapabilities = capabilities ? `${prompt}
|
|
19740
19751
|
|
|
19741
19752
|
${capabilities}` : prompt;
|
|
@@ -19828,7 +19839,8 @@ function buildArgs(prompt, botName, options, resumeSessionId, isolatedStyle) {
|
|
|
19828
19839
|
options.channelPrompt,
|
|
19829
19840
|
// Host runs: the CLI applies settings.json's style itself. An isolated run
|
|
19830
19841
|
// cannot see that file, so a custom style's body is injected here instead.
|
|
19831
|
-
isolatedStyle?.builtIn ? void 0 : isolatedStyle?.body
|
|
19842
|
+
isolatedStyle?.builtIn ? void 0 : isolatedStyle?.body,
|
|
19843
|
+
options.slackBound
|
|
19832
19844
|
),
|
|
19833
19845
|
options.memoryPrompt,
|
|
19834
19846
|
docsAccessPromptNote(options.docsAccess, options.docsAccessUnverified)
|
|
@@ -19883,7 +19895,7 @@ function pinnedClaudeConfigDir(dir) {
|
|
|
19883
19895
|
return resolvePath(dir.replace(/^~(?=\/|$)/, homedir3())) === resolvePath(homedir3(), ".claude") ? void 0 : dir;
|
|
19884
19896
|
}
|
|
19885
19897
|
function runCli(prompt, cwd, botName, options, claudeConfigDir, resumeSessionId, claudeCodeOauthToken) {
|
|
19886
|
-
return new Promise((
|
|
19898
|
+
return new Promise((resolve9, reject) => {
|
|
19887
19899
|
const isolated = options.runtime === "container" || options.runtime === "sandbox";
|
|
19888
19900
|
const args = buildArgs(
|
|
19889
19901
|
prompt,
|
|
@@ -20049,7 +20061,7 @@ function runCli(prompt, cwd, botName, options, claudeConfigDir, resumeSessionId,
|
|
|
20049
20061
|
console.log(`[agent] stderr: ${stderr.trim()}`);
|
|
20050
20062
|
}
|
|
20051
20063
|
if (cancelled) {
|
|
20052
|
-
|
|
20064
|
+
resolve9({
|
|
20053
20065
|
sessionId: liveSessionId ?? resumeSessionId ?? "",
|
|
20054
20066
|
text: "",
|
|
20055
20067
|
isCancelled: true
|
|
@@ -20058,7 +20070,7 @@ function runCli(prompt, cwd, botName, options, claudeConfigDir, resumeSessionId,
|
|
|
20058
20070
|
}
|
|
20059
20071
|
if (timedOut) {
|
|
20060
20072
|
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.`;
|
|
20061
|
-
|
|
20073
|
+
resolve9({
|
|
20062
20074
|
sessionId: liveSessionId ?? resumeSessionId ?? "",
|
|
20063
20075
|
text,
|
|
20064
20076
|
isError: true,
|
|
@@ -20096,7 +20108,7 @@ function runCli(prompt, cwd, botName, options, claudeConfigDir, resumeSessionId,
|
|
|
20096
20108
|
!!claudeCodeOauthToken
|
|
20097
20109
|
);
|
|
20098
20110
|
recordUsage2(response, options);
|
|
20099
|
-
|
|
20111
|
+
resolve9(
|
|
20100
20112
|
response.isError ? {
|
|
20101
20113
|
...response,
|
|
20102
20114
|
failure: {
|
|
@@ -20110,7 +20122,7 @@ function runCli(prompt, cwd, botName, options, claudeConfigDir, resumeSessionId,
|
|
|
20110
20122
|
);
|
|
20111
20123
|
} catch {
|
|
20112
20124
|
const fallback = onLine ? "" : stdout.trim();
|
|
20113
|
-
|
|
20125
|
+
resolve9({ sessionId: resumeSessionId ?? "", text: fallback || "No response" });
|
|
20114
20126
|
}
|
|
20115
20127
|
});
|
|
20116
20128
|
});
|
|
@@ -20191,6 +20203,11 @@ var featureFlags = {
|
|
|
20191
20203
|
"ai-cost": {
|
|
20192
20204
|
title: "AI cost",
|
|
20193
20205
|
description: "Shows admins what the agent has spent: a Cost section in a channel's AI overview and a per-thread cost in the thread menu. Estimated at API list rates, so on a Claude subscription it will not match your bill.",
|
|
20206
|
+
stage: "setting"
|
|
20207
|
+
},
|
|
20208
|
+
"session-retro": {
|
|
20209
|
+
title: "Session retro",
|
|
20210
|
+
description: "Once a thread costs more than $15, admins get a Retro button in its header: an AI review of where the spend went and what to do differently next time. The thread transcript and run usage are sent to an AI model.",
|
|
20194
20211
|
stage: "beta"
|
|
20195
20212
|
},
|
|
20196
20213
|
"read-aloud": {
|
|
@@ -20201,7 +20218,7 @@ var featureFlags = {
|
|
|
20201
20218
|
excalidraw: {
|
|
20202
20219
|
title: "Excalidraw",
|
|
20203
20220
|
description: "Create and edit whiteboard drawings (.excalidraw files) in the Docs pane. Existing drawings stay viewable with this off.",
|
|
20204
|
-
stage: "
|
|
20221
|
+
stage: "ga"
|
|
20205
20222
|
},
|
|
20206
20223
|
sandbox: {
|
|
20207
20224
|
title: "Sandbox runtime",
|
|
@@ -20211,7 +20228,7 @@ var featureFlags = {
|
|
|
20211
20228
|
dictation: {
|
|
20212
20229
|
title: "Dictation",
|
|
20213
20230
|
description: "A mic button in the message composer that turns speech into text as you talk. Each phrase uses speech-to-text.",
|
|
20214
|
-
stage: "
|
|
20231
|
+
stage: "setting"
|
|
20215
20232
|
},
|
|
20216
20233
|
"agent-memory": {
|
|
20217
20234
|
title: "Agent memory",
|
|
@@ -20226,11 +20243,26 @@ var featureFlags = {
|
|
|
20226
20243
|
autocomplete: {
|
|
20227
20244
|
title: "Autocomplete",
|
|
20228
20245
|
description: "Gray inline suggestions in the message composer that continue what you are typing, based on the channel. Press Tab to accept, Esc to dismiss. Your draft is sent to an AI model.",
|
|
20229
|
-
stage: "
|
|
20246
|
+
stage: "setting"
|
|
20247
|
+
},
|
|
20248
|
+
"auto-channel": {
|
|
20249
|
+
title: "Auto channel",
|
|
20250
|
+
description: "New question picks the channel for you: an AI model reads your message and the channel list, and posts it where it belongs. You can still pick a channel yourself.",
|
|
20251
|
+
stage: "setting"
|
|
20230
20252
|
},
|
|
20231
20253
|
languages: {
|
|
20232
20254
|
title: "Languages",
|
|
20233
20255
|
description: "Pick the interface language in your user settings (13 languages, machine translated). Off: the interface is always English.",
|
|
20256
|
+
stage: "ga"
|
|
20257
|
+
},
|
|
20258
|
+
"continuous-chat": {
|
|
20259
|
+
title: "Continuous chat",
|
|
20260
|
+
description: "Read a direct message as one continuous chat instead of a list of threads: a new session starts each day (4am) or with /new, and each message is tagged with a topic so the Threads view (View menu) groups the DM by topic. Your DM messages are sent to an AI model for tagging.",
|
|
20261
|
+
stage: "beta"
|
|
20262
|
+
},
|
|
20263
|
+
"daily-line": {
|
|
20264
|
+
title: "Daily line",
|
|
20265
|
+
description: "A soft colour glow and one quiet line in the corner of Rounds mode's empty space, a different decision or fact from your workspace memory each day. The memory is sent to an AI model to phrase the line.",
|
|
20234
20266
|
stage: "beta"
|
|
20235
20267
|
}
|
|
20236
20268
|
};
|
|
@@ -20246,7 +20278,7 @@ function resolveFeatureFlags(enabledIds, devHost) {
|
|
|
20246
20278
|
const out = {};
|
|
20247
20279
|
for (const id of featureFlagIds) {
|
|
20248
20280
|
const stage = featureFlags[id].stage;
|
|
20249
|
-
out[id] = stage === "ga" || isFeatureVisible(stage, devHost) && enabled.has(id);
|
|
20281
|
+
out[id] = stage === "ga" || (stage === "setting" || isFeatureVisible(stage, devHost)) && enabled.has(id);
|
|
20250
20282
|
}
|
|
20251
20283
|
return out;
|
|
20252
20284
|
}
|
|
@@ -21620,10 +21652,10 @@ function recordCodexUsage(response, options) {
|
|
|
21620
21652
|
});
|
|
21621
21653
|
}
|
|
21622
21654
|
function runCodexCli(prompt, cwd, options, resumeSessionId) {
|
|
21623
|
-
return new Promise((
|
|
21655
|
+
return new Promise((resolve9, reject) => {
|
|
21624
21656
|
const finish = (response) => {
|
|
21625
21657
|
recordCodexUsage(response, options);
|
|
21626
|
-
|
|
21658
|
+
resolve9(response);
|
|
21627
21659
|
};
|
|
21628
21660
|
const scratch = mkdtempSync(join5(tmpdir(), "flyspace-codex-"));
|
|
21629
21661
|
const lastMessageFile = join5(scratch, "last-message.txt");
|
|
@@ -22468,7 +22500,7 @@ var DEFAULT_TIMEOUT_MS = 12e4;
|
|
|
22468
22500
|
var KILL_GRACE_MS3 = 5e3;
|
|
22469
22501
|
function runScriptAutomation(opts) {
|
|
22470
22502
|
const { name, script, cwd, timeoutMs = DEFAULT_TIMEOUT_MS } = opts;
|
|
22471
|
-
return new Promise((
|
|
22503
|
+
return new Promise((resolve9, reject) => {
|
|
22472
22504
|
const child = spawn3("/bin/bash", [script], { cwd, env: resolveMiseEnv(cwd), stdio: ["ignore", "pipe", "pipe"] });
|
|
22473
22505
|
let stdout = "";
|
|
22474
22506
|
let stderr = "";
|
|
@@ -22503,7 +22535,7 @@ function runScriptAutomation(opts) {
|
|
|
22503
22535
|
} else if (code !== 0) {
|
|
22504
22536
|
reject(new Error(`script exited with code ${code}: ${stderr.trim()}`));
|
|
22505
22537
|
} else {
|
|
22506
|
-
|
|
22538
|
+
resolve9();
|
|
22507
22539
|
}
|
|
22508
22540
|
});
|
|
22509
22541
|
});
|
|
@@ -23273,8 +23305,8 @@ var MessageQueue = class {
|
|
|
23273
23305
|
const chains = Array.from(this.chains.values());
|
|
23274
23306
|
if (chains.length === 0) return true;
|
|
23275
23307
|
let timer;
|
|
23276
|
-
const timeout = new Promise((
|
|
23277
|
-
timer = setTimeout(() =>
|
|
23308
|
+
const timeout = new Promise((resolve9) => {
|
|
23309
|
+
timer = setTimeout(() => resolve9(false), timeoutMs);
|
|
23278
23310
|
});
|
|
23279
23311
|
const done = Promise.all(chains).then(() => true);
|
|
23280
23312
|
const result = await Promise.race([done, timeout]);
|
|
@@ -23836,7 +23868,7 @@ async function summariseThreadTranscript(transcript, opts, deps = {}) {
|
|
|
23836
23868
|
}
|
|
23837
23869
|
|
|
23838
23870
|
// src/dashboard/chat-agent.ts
|
|
23839
|
-
import { homedir as
|
|
23871
|
+
import { homedir as homedir8 } from "os";
|
|
23840
23872
|
|
|
23841
23873
|
// src/mcp/config.ts
|
|
23842
23874
|
import { mkdtempSync as mkdtempSync2, rmSync as rmSync4, writeFileSync as writeFileSync4 } from "fs";
|
|
@@ -23963,7 +23995,7 @@ function secretsMatch(a, b) {
|
|
|
23963
23995
|
}
|
|
23964
23996
|
|
|
23965
23997
|
// ../api/src/mcp/oauth.ts
|
|
23966
|
-
import { createHash as
|
|
23998
|
+
import { createHash as createHash4, randomBytes as randomBytes2 } from "crypto";
|
|
23967
23999
|
var RESERVED_AUTHORIZE_PARAMS = /* @__PURE__ */ new Set([
|
|
23968
24000
|
"client_id",
|
|
23969
24001
|
"redirect_uri",
|
|
@@ -23981,7 +24013,7 @@ function createStateToken() {
|
|
|
23981
24013
|
}
|
|
23982
24014
|
function createPkcePair() {
|
|
23983
24015
|
const verifier = base64url(randomBytes2(32));
|
|
23984
|
-
const challenge = base64url(
|
|
24016
|
+
const challenge = base64url(createHash4("sha256").update(verifier).digest());
|
|
23985
24017
|
return { verifier, challenge };
|
|
23986
24018
|
}
|
|
23987
24019
|
function clientEnvName(providerSlug, suffix) {
|
|
@@ -24350,7 +24382,7 @@ function needsRefresh(expiresAt, now = Date.now()) {
|
|
|
24350
24382
|
if (!expiresAt) return false;
|
|
24351
24383
|
return new Date(expiresAt).getTime() - now < REFRESH_SKEW_MS;
|
|
24352
24384
|
}
|
|
24353
|
-
var sleep = (ms) => new Promise((
|
|
24385
|
+
var sleep = (ms) => new Promise((resolve9) => setTimeout(resolve9, ms));
|
|
24354
24386
|
async function refreshConnection(params) {
|
|
24355
24387
|
const { workspaceId, connection, provider } = params;
|
|
24356
24388
|
const deps = params.deps ?? {};
|
|
@@ -24551,10 +24583,10 @@ async function withMcpConfig(profile, connectionIds, fn, extraServers = {}) {
|
|
|
24551
24583
|
|
|
24552
24584
|
// ../api/src/version.ts
|
|
24553
24585
|
import { readFileSync as readFileSync7 } from "fs";
|
|
24554
|
-
var CLI_VERSION = true ? "0.1.
|
|
24586
|
+
var CLI_VERSION = true ? "0.1.53" : devVersion();
|
|
24555
24587
|
function isOlderVersion(a, b) {
|
|
24556
|
-
const
|
|
24557
|
-
const [pa, pb] = [
|
|
24588
|
+
const parse2 = (v) => v.replace(/^v/, "").split("-")[0].split(".").map(Number);
|
|
24589
|
+
const [pa, pb] = [parse2(a), parse2(b)];
|
|
24558
24590
|
if (pa.length !== 3 || pb.length !== 3 || [...pa, ...pb].some(Number.isNaN)) return false;
|
|
24559
24591
|
for (let i = 0; i < 3; i++) if (pa[i] !== pb[i]) return pa[i] < pb[i];
|
|
24560
24592
|
return false;
|
|
@@ -24677,14 +24709,14 @@ function handleHostDbResult(id, res) {
|
|
|
24677
24709
|
}
|
|
24678
24710
|
function whenConnected() {
|
|
24679
24711
|
if (sender) return Promise.resolve(sender);
|
|
24680
|
-
return new Promise((
|
|
24712
|
+
return new Promise((resolve9, reject) => {
|
|
24681
24713
|
const timer = setTimeout(() => {
|
|
24682
24714
|
onSender = onSender.filter((w) => w !== wake);
|
|
24683
24715
|
reject(new Error("Host is not connected to the Data API"));
|
|
24684
24716
|
}, REQUEST_TIMEOUT_MS);
|
|
24685
24717
|
const wake = () => {
|
|
24686
24718
|
clearTimeout(timer);
|
|
24687
|
-
|
|
24719
|
+
resolve9(sender);
|
|
24688
24720
|
};
|
|
24689
24721
|
onSender.push(wake);
|
|
24690
24722
|
});
|
|
@@ -24692,12 +24724,12 @@ function whenConnected() {
|
|
|
24692
24724
|
async function requestHostDb(req) {
|
|
24693
24725
|
const send = await whenConnected();
|
|
24694
24726
|
const id = randomUUID2();
|
|
24695
|
-
return new Promise((
|
|
24727
|
+
return new Promise((resolve9, reject) => {
|
|
24696
24728
|
const timer = setTimeout(() => {
|
|
24697
24729
|
pending.delete(id);
|
|
24698
24730
|
reject(new Error("Data API did not answer in time"));
|
|
24699
24731
|
}, REQUEST_TIMEOUT_MS);
|
|
24700
|
-
pending.set(id, { resolve:
|
|
24732
|
+
pending.set(id, { resolve: resolve9, reject, timer });
|
|
24701
24733
|
send({ type: "db", id, req });
|
|
24702
24734
|
});
|
|
24703
24735
|
}
|
|
@@ -24709,14 +24741,14 @@ function handleAttachmentUrlResult(id, url) {
|
|
|
24709
24741
|
async function requestAttachmentUrl(key) {
|
|
24710
24742
|
const send = await whenConnected();
|
|
24711
24743
|
const id = randomUUID2();
|
|
24712
|
-
return new Promise((
|
|
24744
|
+
return new Promise((resolve9, reject) => {
|
|
24713
24745
|
const timer = setTimeout(() => {
|
|
24714
24746
|
pendingUrls.delete(id);
|
|
24715
24747
|
reject(new Error("Data API did not answer in time"));
|
|
24716
24748
|
}, REQUEST_TIMEOUT_MS);
|
|
24717
24749
|
pendingUrls.set(id, (url) => {
|
|
24718
24750
|
clearTimeout(timer);
|
|
24719
|
-
|
|
24751
|
+
resolve9(url);
|
|
24720
24752
|
});
|
|
24721
24753
|
send({ type: "attachment-url", id, key });
|
|
24722
24754
|
});
|
|
@@ -24856,135 +24888,492 @@ function readAgentPersona(configDir, cwd, name) {
|
|
|
24856
24888
|
}
|
|
24857
24889
|
}
|
|
24858
24890
|
|
|
24859
|
-
// src/
|
|
24860
|
-
import
|
|
24861
|
-
|
|
24862
|
-
|
|
24863
|
-
|
|
24864
|
-
|
|
24865
|
-
|
|
24866
|
-
|
|
24867
|
-
|
|
24868
|
-
|
|
24869
|
-
|
|
24870
|
-
|
|
24871
|
-
|
|
24872
|
-
|
|
24873
|
-
|
|
24874
|
-
|
|
24875
|
-
|
|
24876
|
-
|
|
24877
|
-
|
|
24878
|
-
|
|
24879
|
-
|
|
24880
|
-
|
|
24881
|
-
|
|
24882
|
-
|
|
24883
|
-
|
|
24884
|
-
|
|
24885
|
-
|
|
24886
|
-
|
|
24887
|
-
|
|
24888
|
-
|
|
24889
|
-
|
|
24890
|
-
|
|
24891
|
-
|
|
24892
|
-
|
|
24893
|
-
|
|
24894
|
-
|
|
24895
|
-
|
|
24896
|
-
|
|
24897
|
-
|
|
24898
|
-
|
|
24899
|
-
|
|
24900
|
-
|
|
24901
|
-
|
|
24891
|
+
// ../api/src/claude/skills.ts
|
|
24892
|
+
import { existsSync as existsSync14, readdirSync as readdirSync4, readFileSync as readFileSync11, statSync as statSync6 } from "fs";
|
|
24893
|
+
import { homedir as homedir6 } from "os";
|
|
24894
|
+
import { basename as basename3, dirname as dirname2, join as join12 } from "path";
|
|
24895
|
+
import yaml3 from "js-yaml";
|
|
24896
|
+
|
|
24897
|
+
// ../api/src/claude/skill-files.ts
|
|
24898
|
+
import {
|
|
24899
|
+
existsSync as existsSync13,
|
|
24900
|
+
mkdirSync as mkdirSync9,
|
|
24901
|
+
readFileSync as readFileSync10,
|
|
24902
|
+
readdirSync as readdirSync3,
|
|
24903
|
+
rmSync as rmSync6,
|
|
24904
|
+
statSync as statSync5,
|
|
24905
|
+
writeFileSync as writeFileSync6
|
|
24906
|
+
} from "fs";
|
|
24907
|
+
import { homedir as homedir5 } from "os";
|
|
24908
|
+
import { join as join11, resolve as resolve6, sep as sep3 } from "path";
|
|
24909
|
+
import yaml2 from "js-yaml";
|
|
24910
|
+
var MAX_SKILL_BYTES = 2 * 1024 * 1024;
|
|
24911
|
+
var SKILL_NAME = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
|
|
24912
|
+
function expandHome2(p) {
|
|
24913
|
+
if (p === "~") return homedir5();
|
|
24914
|
+
if (p.startsWith("~/")) return join11(homedir5(), p.slice(2));
|
|
24915
|
+
return p;
|
|
24916
|
+
}
|
|
24917
|
+
function workspaceSkillsDir(configDir) {
|
|
24918
|
+
return join11(configDir ? expandHome2(configDir) : join11(homedir5(), ".claude"), "skills");
|
|
24919
|
+
}
|
|
24920
|
+
function channelSkillsDir(cwd) {
|
|
24921
|
+
return join11(cwd, ".claude", "skills");
|
|
24922
|
+
}
|
|
24923
|
+
function isValidSkillName(name) {
|
|
24924
|
+
return SKILL_NAME.test(name);
|
|
24925
|
+
}
|
|
24926
|
+
function resolveSkillPath(dir, name) {
|
|
24927
|
+
if (!isValidSkillName(name)) return null;
|
|
24928
|
+
const abs = resolve6(dir, name, "SKILL.md");
|
|
24929
|
+
if (!abs.startsWith(resolve6(dir) + sep3)) return null;
|
|
24930
|
+
return abs;
|
|
24931
|
+
}
|
|
24932
|
+
function splitFrontmatter(raw) {
|
|
24933
|
+
const match = raw.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n?/);
|
|
24934
|
+
if (!match) return { fm: {}, body: raw };
|
|
24935
|
+
let fm = {};
|
|
24936
|
+
try {
|
|
24937
|
+
fm = yaml2.load(match[1]) ?? {};
|
|
24938
|
+
} catch {
|
|
24939
|
+
fm = {};
|
|
24902
24940
|
}
|
|
24903
|
-
|
|
24904
|
-
|
|
24905
|
-
|
|
24941
|
+
return { fm, body: raw.slice(match[0].length) };
|
|
24942
|
+
}
|
|
24943
|
+
function buildSkillFile(fm, body) {
|
|
24944
|
+
const { name, description, ...rest } = fm;
|
|
24945
|
+
const ordered = { name, description, ...rest };
|
|
24946
|
+
const front = yaml2.dump(ordered, { lineWidth: -1 }).trimEnd();
|
|
24947
|
+
return `---
|
|
24948
|
+
${front}
|
|
24949
|
+
---
|
|
24950
|
+
|
|
24951
|
+
${body.replace(/^\n+/, "").trimEnd()}
|
|
24952
|
+
`;
|
|
24953
|
+
}
|
|
24954
|
+
function readMeta(abs) {
|
|
24955
|
+
try {
|
|
24956
|
+
const { fm } = splitFrontmatter(readFileSync10(abs, "utf-8"));
|
|
24906
24957
|
return {
|
|
24907
|
-
|
|
24908
|
-
|
|
24909
|
-
sessionId: row.session_id,
|
|
24910
|
-
runner: row.runner === "codex" ? "codex" : "claude",
|
|
24911
|
-
createdAt: row.created_at,
|
|
24912
|
-
updatedAt: row.updated_at
|
|
24958
|
+
name: typeof fm["name"] === "string" ? fm["name"] : void 0,
|
|
24959
|
+
description: typeof fm["description"] === "string" ? fm["description"] : void 0
|
|
24913
24960
|
};
|
|
24961
|
+
} catch {
|
|
24962
|
+
return {};
|
|
24914
24963
|
}
|
|
24915
|
-
|
|
24916
|
-
|
|
24917
|
-
|
|
24918
|
-
|
|
24919
|
-
|
|
24920
|
-
|
|
24921
|
-
|
|
24964
|
+
}
|
|
24965
|
+
function listSkillFiles(dir) {
|
|
24966
|
+
if (!existsSync13(dir)) return [];
|
|
24967
|
+
let entries2;
|
|
24968
|
+
try {
|
|
24969
|
+
entries2 = readdirSync3(dir);
|
|
24970
|
+
} catch {
|
|
24971
|
+
return [];
|
|
24922
24972
|
}
|
|
24923
|
-
|
|
24924
|
-
|
|
24925
|
-
|
|
24926
|
-
|
|
24927
|
-
|
|
24928
|
-
|
|
24929
|
-
|
|
24930
|
-
|
|
24931
|
-
|
|
24932
|
-
|
|
24933
|
-
|
|
24973
|
+
const rows2 = [];
|
|
24974
|
+
for (const entry of entries2) {
|
|
24975
|
+
if (!isValidSkillName(entry)) continue;
|
|
24976
|
+
const abs = join11(dir, entry, "SKILL.md");
|
|
24977
|
+
let stat;
|
|
24978
|
+
try {
|
|
24979
|
+
stat = statSync5(abs);
|
|
24980
|
+
} catch {
|
|
24981
|
+
continue;
|
|
24982
|
+
}
|
|
24983
|
+
if (!stat.isFile()) continue;
|
|
24984
|
+
const meta = readMeta(abs);
|
|
24985
|
+
rows2.push({
|
|
24986
|
+
// The directory name is the identifier the CLI resolves by, so it wins
|
|
24987
|
+
// over a frontmatter `name` that has drifted away from it.
|
|
24988
|
+
name: entry,
|
|
24989
|
+
description: (meta.description ?? "").trim(),
|
|
24990
|
+
mtime: stat.mtime.toISOString()
|
|
24991
|
+
});
|
|
24934
24992
|
}
|
|
24935
|
-
|
|
24936
|
-
|
|
24993
|
+
return rows2.sort((a, b) => a.name.localeCompare(b.name));
|
|
24994
|
+
}
|
|
24995
|
+
function readSkillFile(dir, name) {
|
|
24996
|
+
const abs = resolveSkillPath(dir, name);
|
|
24997
|
+
if (!abs) return null;
|
|
24998
|
+
let stat;
|
|
24999
|
+
try {
|
|
25000
|
+
stat = statSync5(abs);
|
|
25001
|
+
} catch {
|
|
25002
|
+
return null;
|
|
24937
25003
|
}
|
|
24938
|
-
|
|
24939
|
-
|
|
24940
|
-
|
|
24941
|
-
|
|
24942
|
-
|
|
24943
|
-
|
|
24944
|
-
|
|
24945
|
-
|
|
24946
|
-
|
|
24947
|
-
|
|
24948
|
-
|
|
24949
|
-
|
|
24950
|
-
|
|
24951
|
-
|
|
24952
|
-
|
|
25004
|
+
if (!stat.isFile() || stat.size > MAX_SKILL_BYTES) return null;
|
|
25005
|
+
const { fm, body } = splitFrontmatter(readFileSync10(abs, "utf-8"));
|
|
25006
|
+
return {
|
|
25007
|
+
name,
|
|
25008
|
+
description: typeof fm["description"] === "string" ? fm["description"].trim() : "",
|
|
25009
|
+
body,
|
|
25010
|
+
mtime: stat.mtime.toISOString(),
|
|
25011
|
+
path: abs
|
|
25012
|
+
};
|
|
25013
|
+
}
|
|
25014
|
+
function writeSkillFile(dir, name, patch, baseMtime) {
|
|
25015
|
+
const abs = resolveSkillPath(dir, name);
|
|
25016
|
+
if (!abs) return { status: "not-found" };
|
|
25017
|
+
let stat;
|
|
25018
|
+
try {
|
|
25019
|
+
stat = statSync5(abs);
|
|
25020
|
+
} catch {
|
|
25021
|
+
return { status: "not-found" };
|
|
24953
25022
|
}
|
|
24954
|
-
|
|
24955
|
-
|
|
24956
|
-
|
|
24957
|
-
* thread_ts), so moving a thread in the dashboard without this leaves the
|
|
24958
|
-
* agent unable to find its own session: the next turn would start from
|
|
24959
|
-
* scratch and lose the conversation, and any `!model`/`!effort` override on
|
|
24960
|
-
* the thread would silently revert.
|
|
24961
|
-
*
|
|
24962
|
-
* A row already sitting on the destination key wins — that means the thread
|
|
24963
|
-
* has been moved back and forth and the destination row is the newer state,
|
|
24964
|
-
* so the stale source row is dropped rather than overwriting it.
|
|
24965
|
-
*
|
|
24966
|
-
* Returns how many rows were re-keyed in each table.
|
|
24967
|
-
*/
|
|
24968
|
-
moveThread(fromChannelId, toChannelId, threadTs) {
|
|
24969
|
-
const move = this.db.transaction(() => {
|
|
24970
|
-
const counts = { sessions: 0, modelOverrides: 0, effortOverrides: 0 };
|
|
24971
|
-
for (const table of ["sessions", "model_overrides", "effort_overrides"]) {
|
|
24972
|
-
const updated = this.db.prepare(
|
|
24973
|
-
`UPDATE OR IGNORE ${table} SET channel_id = ?
|
|
24974
|
-
WHERE channel_id = ? AND thread_ts = ?`
|
|
24975
|
-
).run(toChannelId, fromChannelId, threadTs);
|
|
24976
|
-
this.db.prepare(`DELETE FROM ${table} WHERE channel_id = ? AND thread_ts = ?`).run(fromChannelId, threadTs);
|
|
24977
|
-
if (table === "sessions") counts.sessions = updated.changes;
|
|
24978
|
-
else if (table === "model_overrides") counts.modelOverrides = updated.changes;
|
|
24979
|
-
else counts.effortOverrides = updated.changes;
|
|
24980
|
-
}
|
|
24981
|
-
return counts;
|
|
24982
|
-
});
|
|
24983
|
-
return move();
|
|
25023
|
+
if (!stat.isFile()) return { status: "not-found" };
|
|
25024
|
+
if (baseMtime && stat.mtime.toISOString() !== baseMtime) {
|
|
25025
|
+
return { status: "conflict", mtime: stat.mtime.toISOString() };
|
|
24984
25026
|
}
|
|
24985
|
-
|
|
24986
|
-
|
|
24987
|
-
|
|
25027
|
+
const { fm } = splitFrontmatter(readFileSync10(abs, "utf-8"));
|
|
25028
|
+
const content = buildSkillFile({ ...fm, name, description: patch.description }, patch.body);
|
|
25029
|
+
if (Buffer.byteLength(content, "utf8") > MAX_SKILL_BYTES) return { status: "too-large" };
|
|
25030
|
+
writeFileSync6(abs, content, "utf8");
|
|
25031
|
+
return { status: "ok", mtime: statSync5(abs).mtime.toISOString() };
|
|
25032
|
+
}
|
|
25033
|
+
function createSkillFile(dir, name, description) {
|
|
25034
|
+
const abs = resolveSkillPath(dir, name);
|
|
25035
|
+
if (!abs) return { status: "bad-name" };
|
|
25036
|
+
if (existsSync13(abs)) return { status: "exists" };
|
|
25037
|
+
mkdirSync9(join11(dir, name), { recursive: true });
|
|
25038
|
+
writeFileSync6(
|
|
25039
|
+
abs,
|
|
25040
|
+
buildSkillFile(
|
|
25041
|
+
{ name, description },
|
|
25042
|
+
`# ${name}
|
|
25043
|
+
|
|
25044
|
+
Describe what this skill does and when to use it.
|
|
25045
|
+
`
|
|
25046
|
+
),
|
|
25047
|
+
"utf8"
|
|
25048
|
+
);
|
|
25049
|
+
const detail = readSkillFile(dir, name);
|
|
25050
|
+
return detail ? { status: "ok", skill: detail } : { status: "bad-name" };
|
|
25051
|
+
}
|
|
25052
|
+
function deleteSkillFile(dir, name) {
|
|
25053
|
+
const abs = resolveSkillPath(dir, name);
|
|
25054
|
+
if (!abs || !existsSync13(abs)) return { status: "not-found" };
|
|
25055
|
+
rmSync6(join11(dir, name), { recursive: true, force: true });
|
|
25056
|
+
return { status: "ok" };
|
|
25057
|
+
}
|
|
25058
|
+
|
|
25059
|
+
// ../api/src/claude/skills.ts
|
|
25060
|
+
function defaultConfigDir2() {
|
|
25061
|
+
return join12(homedir6(), ".claude");
|
|
25062
|
+
}
|
|
25063
|
+
function expandHome3(p) {
|
|
25064
|
+
if (p === "~") return homedir6();
|
|
25065
|
+
if (p.startsWith("~/")) return join12(homedir6(), p.slice(2));
|
|
25066
|
+
return p;
|
|
25067
|
+
}
|
|
25068
|
+
function parseFrontmatter2(file) {
|
|
25069
|
+
let content;
|
|
25070
|
+
try {
|
|
25071
|
+
content = readFileSync11(file, "utf-8");
|
|
25072
|
+
} catch {
|
|
25073
|
+
return {};
|
|
25074
|
+
}
|
|
25075
|
+
const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
25076
|
+
if (!match) return {};
|
|
25077
|
+
try {
|
|
25078
|
+
const fm = yaml3.load(match[1]);
|
|
25079
|
+
const name = typeof fm?.["name"] === "string" ? fm["name"] : void 0;
|
|
25080
|
+
const description = typeof fm?.["description"] === "string" ? fm["description"] : void 0;
|
|
25081
|
+
return { name, description };
|
|
25082
|
+
} catch {
|
|
25083
|
+
return {};
|
|
25084
|
+
}
|
|
25085
|
+
}
|
|
25086
|
+
function isSymlinkedDir(root, entry) {
|
|
25087
|
+
if (!entry.isSymbolicLink()) return false;
|
|
25088
|
+
try {
|
|
25089
|
+
return statSync6(join12(root, entry.name)).isDirectory();
|
|
25090
|
+
} catch {
|
|
25091
|
+
return false;
|
|
25092
|
+
}
|
|
25093
|
+
}
|
|
25094
|
+
function findSkillFiles(root, maxDepth, out) {
|
|
25095
|
+
if (maxDepth < 0 || !existsSync14(root)) return;
|
|
25096
|
+
let entries2;
|
|
25097
|
+
try {
|
|
25098
|
+
entries2 = readdirSync4(root, { withFileTypes: true });
|
|
25099
|
+
} catch {
|
|
25100
|
+
return;
|
|
25101
|
+
}
|
|
25102
|
+
for (const entry of entries2) {
|
|
25103
|
+
if (entry.isFile()) {
|
|
25104
|
+
if (entry.name === "SKILL.md") out.push(join12(root, entry.name));
|
|
25105
|
+
} else if (entry.isDirectory() || isSymlinkedDir(root, entry)) {
|
|
25106
|
+
if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
|
|
25107
|
+
findSkillFiles(join12(root, entry.name), maxDepth - 1, out);
|
|
25108
|
+
}
|
|
25109
|
+
}
|
|
25110
|
+
}
|
|
25111
|
+
function pluginNameFor(file, root) {
|
|
25112
|
+
let dir = dirname2(file);
|
|
25113
|
+
while (dir.startsWith(root) && dir !== dirname2(dir)) {
|
|
25114
|
+
try {
|
|
25115
|
+
const manifest = JSON.parse(
|
|
25116
|
+
readFileSync11(join12(dir, ".claude-plugin", "plugin.json"), "utf-8")
|
|
25117
|
+
);
|
|
25118
|
+
if (typeof manifest.name === "string" && manifest.name.trim()) return manifest.name.trim();
|
|
25119
|
+
} catch {
|
|
25120
|
+
}
|
|
25121
|
+
dir = dirname2(dir);
|
|
25122
|
+
}
|
|
25123
|
+
return void 0;
|
|
25124
|
+
}
|
|
25125
|
+
function collectFrom2(root, source, maxDepth, namePrefix) {
|
|
25126
|
+
const files = [];
|
|
25127
|
+
findSkillFiles(root, maxDepth, files);
|
|
25128
|
+
return files.map((file) => {
|
|
25129
|
+
const fm = parseFrontmatter2(file);
|
|
25130
|
+
const name = fm.name?.trim() || basename3(dirname2(file));
|
|
25131
|
+
const plugin = source === "plugin" ? pluginNameFor(file, root) : void 0;
|
|
25132
|
+
const prefix = namePrefix ?? plugin;
|
|
25133
|
+
return {
|
|
25134
|
+
name: prefix ? `${prefix}:${name}` : name,
|
|
25135
|
+
description: (fm.description ?? "").trim(),
|
|
25136
|
+
source,
|
|
25137
|
+
...plugin && { plugin },
|
|
25138
|
+
// Only read by `listPluginSkillDetails`; `listSkills` strips it.
|
|
25139
|
+
file
|
|
25140
|
+
};
|
|
25141
|
+
});
|
|
25142
|
+
}
|
|
25143
|
+
function collectAll(configDir, cwd) {
|
|
25144
|
+
const base = configDir ? expandHome3(configDir) : defaultConfigDir2();
|
|
25145
|
+
const collected = [
|
|
25146
|
+
...collectFrom2(join12(cwd, ".claude", "skills"), "project", 2),
|
|
25147
|
+
...nestedProjectRoots(cwd).flatMap(({ dir, prefix }) => collectFrom2(dir, "project", 2, prefix)),
|
|
25148
|
+
...collectFrom2(join12(base, "skills"), "user", 2),
|
|
25149
|
+
...collectFrom2(join12(base, "plugins"), "plugin", 8)
|
|
25150
|
+
];
|
|
25151
|
+
const byName = /* @__PURE__ */ new Map();
|
|
25152
|
+
for (const skill of collected) {
|
|
25153
|
+
if (skill.name && !byName.has(skill.name)) byName.set(skill.name, skill);
|
|
25154
|
+
}
|
|
25155
|
+
return [...byName.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
25156
|
+
}
|
|
25157
|
+
function nestedProjectRoots(cwd) {
|
|
25158
|
+
let entries2;
|
|
25159
|
+
try {
|
|
25160
|
+
entries2 = readdirSync4(cwd, { withFileTypes: true });
|
|
25161
|
+
} catch {
|
|
25162
|
+
return [];
|
|
25163
|
+
}
|
|
25164
|
+
const roots = [];
|
|
25165
|
+
for (const entry of entries2) {
|
|
25166
|
+
if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
|
|
25167
|
+
if (!entry.isDirectory() && !isSymlinkedDir(cwd, entry)) continue;
|
|
25168
|
+
const skillsDir = join12(cwd, entry.name, ".claude", "skills");
|
|
25169
|
+
if (existsSync14(skillsDir)) roots.push({ dir: skillsDir, prefix: entry.name });
|
|
25170
|
+
}
|
|
25171
|
+
return roots;
|
|
25172
|
+
}
|
|
25173
|
+
function listSkills(configDir, cwd) {
|
|
25174
|
+
return collectAll(configDir, cwd).map(({ file: _file, ...skill }) => skill);
|
|
25175
|
+
}
|
|
25176
|
+
function listPluginSkillDetails(configDir, cwd) {
|
|
25177
|
+
const details = [];
|
|
25178
|
+
for (const { file, ...skill } of collectAll(configDir, cwd)) {
|
|
25179
|
+
if (skill.source !== "plugin") continue;
|
|
25180
|
+
try {
|
|
25181
|
+
const { body } = splitFrontmatter(readFileSync11(file, "utf-8"));
|
|
25182
|
+
details.push({ ...skill, body, path: file, mtime: statSync6(file).mtime.toISOString() });
|
|
25183
|
+
} catch {
|
|
25184
|
+
}
|
|
25185
|
+
}
|
|
25186
|
+
return details;
|
|
25187
|
+
}
|
|
25188
|
+
function findSkillDetail(configDir, cwd, name, sources) {
|
|
25189
|
+
const base = configDir ? expandHome3(configDir) : defaultConfigDir2();
|
|
25190
|
+
const roots = [
|
|
25191
|
+
[join12(cwd, ".claude", "skills"), "project", 2],
|
|
25192
|
+
...nestedProjectRoots(cwd).map(({ dir, prefix }) => [
|
|
25193
|
+
dir,
|
|
25194
|
+
"project",
|
|
25195
|
+
2,
|
|
25196
|
+
prefix
|
|
25197
|
+
]),
|
|
25198
|
+
[join12(base, "skills"), "user", 2],
|
|
25199
|
+
[join12(base, "plugins"), "plugin", 8]
|
|
25200
|
+
];
|
|
25201
|
+
for (const [root, source, maxDepth, namePrefix] of roots) {
|
|
25202
|
+
if (!sources.includes(source)) continue;
|
|
25203
|
+
const files = [];
|
|
25204
|
+
findSkillFiles(root, maxDepth, files);
|
|
25205
|
+
for (const file of files) {
|
|
25206
|
+
const fm = parseFrontmatter2(file);
|
|
25207
|
+
const rawName = fm.name?.trim() || basename3(dirname2(file));
|
|
25208
|
+
const plugin = source === "plugin" ? pluginNameFor(file, root) : void 0;
|
|
25209
|
+
const prefix = namePrefix ?? plugin;
|
|
25210
|
+
const skillName = prefix ? `${prefix}:${rawName}` : rawName;
|
|
25211
|
+
if (skillName !== name) continue;
|
|
25212
|
+
let raw;
|
|
25213
|
+
let mtime;
|
|
25214
|
+
try {
|
|
25215
|
+
raw = readFileSync11(file, "utf-8");
|
|
25216
|
+
mtime = statSync6(file).mtime.toISOString();
|
|
25217
|
+
} catch {
|
|
25218
|
+
continue;
|
|
25219
|
+
}
|
|
25220
|
+
const { body } = splitFrontmatter(raw);
|
|
25221
|
+
return {
|
|
25222
|
+
name: skillName,
|
|
25223
|
+
description: (fm.description ?? "").trim(),
|
|
25224
|
+
source,
|
|
25225
|
+
...plugin && { plugin },
|
|
25226
|
+
body,
|
|
25227
|
+
path: file,
|
|
25228
|
+
mtime
|
|
25229
|
+
};
|
|
25230
|
+
}
|
|
25231
|
+
}
|
|
25232
|
+
return null;
|
|
25233
|
+
}
|
|
25234
|
+
function expandSkillCommand(configDir, cwd, text) {
|
|
25235
|
+
const match = text.trimStart().match(/^\/([\w.:-]+)(?:\s+([\s\S]*))?$/);
|
|
25236
|
+
if (!match) return null;
|
|
25237
|
+
const skill = findSkillDetail(configDir, cwd, match[1], ["project", "user", "plugin"]);
|
|
25238
|
+
if (!skill) return null;
|
|
25239
|
+
const args = match[2]?.trim() ?? "";
|
|
25240
|
+
const body = skill.body.includes("$ARGUMENTS") ? skill.body.replaceAll("$ARGUMENTS", args) : skill.body + (args ? `
|
|
25241
|
+
|
|
25242
|
+
ARGUMENTS: ${args}` : "");
|
|
25243
|
+
return `[the user ran the /${skill.name} skill; its instructions follow. Base directory for this skill: ${dirname2(skill.path)}]
|
|
25244
|
+
|
|
25245
|
+
${body.trim()}`;
|
|
25246
|
+
}
|
|
25247
|
+
|
|
25248
|
+
// src/store/session-store.ts
|
|
25249
|
+
import Database2 from "better-sqlite3";
|
|
25250
|
+
var SessionStore = class {
|
|
25251
|
+
db;
|
|
25252
|
+
constructor(dbPath) {
|
|
25253
|
+
this.db = new Database2(dbPath);
|
|
25254
|
+
this.db.pragma("journal_mode = WAL");
|
|
25255
|
+
this.init();
|
|
25256
|
+
}
|
|
25257
|
+
init() {
|
|
25258
|
+
this.db.exec(`
|
|
25259
|
+
CREATE TABLE IF NOT EXISTS sessions (
|
|
25260
|
+
channel_id TEXT NOT NULL,
|
|
25261
|
+
thread_ts TEXT NOT NULL,
|
|
25262
|
+
session_id TEXT NOT NULL,
|
|
25263
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
25264
|
+
updated_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
25265
|
+
PRIMARY KEY (channel_id, thread_ts)
|
|
25266
|
+
)
|
|
25267
|
+
`);
|
|
25268
|
+
const sessionColumns = this.db.prepare("PRAGMA table_info(sessions)").all();
|
|
25269
|
+
if (!sessionColumns.some((c) => c.name === "runner")) {
|
|
25270
|
+
this.db.exec(`ALTER TABLE sessions ADD COLUMN runner TEXT NOT NULL DEFAULT 'claude'`);
|
|
25271
|
+
}
|
|
25272
|
+
this.db.exec(`DELETE FROM sessions WHERE runner = 'opencode'`);
|
|
25273
|
+
this.db.exec(`
|
|
25274
|
+
CREATE TABLE IF NOT EXISTS model_overrides (
|
|
25275
|
+
channel_id TEXT NOT NULL,
|
|
25276
|
+
thread_ts TEXT NOT NULL,
|
|
25277
|
+
model TEXT NOT NULL,
|
|
25278
|
+
updated_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
25279
|
+
PRIMARY KEY (channel_id, thread_ts)
|
|
25280
|
+
)
|
|
25281
|
+
`);
|
|
25282
|
+
this.db.exec(`
|
|
25283
|
+
CREATE TABLE IF NOT EXISTS effort_overrides (
|
|
25284
|
+
channel_id TEXT NOT NULL,
|
|
25285
|
+
thread_ts TEXT NOT NULL,
|
|
25286
|
+
effort TEXT NOT NULL,
|
|
25287
|
+
updated_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
25288
|
+
PRIMARY KEY (channel_id, thread_ts)
|
|
25289
|
+
)
|
|
25290
|
+
`);
|
|
25291
|
+
}
|
|
25292
|
+
getSession(channelId, threadTs) {
|
|
25293
|
+
const row = this.db.prepare("SELECT * FROM sessions WHERE channel_id = ? AND thread_ts = ?").get(channelId, threadTs);
|
|
25294
|
+
if (!row) return void 0;
|
|
25295
|
+
return {
|
|
25296
|
+
channelId: row.channel_id,
|
|
25297
|
+
threadTs: row.thread_ts,
|
|
25298
|
+
sessionId: row.session_id,
|
|
25299
|
+
runner: row.runner === "codex" ? "codex" : "claude",
|
|
25300
|
+
createdAt: row.created_at,
|
|
25301
|
+
updatedAt: row.updated_at
|
|
25302
|
+
};
|
|
25303
|
+
}
|
|
25304
|
+
saveSession(channelId, threadTs, sessionId, runner = "claude") {
|
|
25305
|
+
this.db.prepare(
|
|
25306
|
+
`INSERT INTO sessions (channel_id, thread_ts, session_id, runner)
|
|
25307
|
+
VALUES (?, ?, ?, ?)
|
|
25308
|
+
ON CONFLICT (channel_id, thread_ts)
|
|
25309
|
+
DO UPDATE SET session_id = excluded.session_id, runner = excluded.runner, updated_at = datetime('now')`
|
|
25310
|
+
).run(channelId, threadTs, sessionId, runner);
|
|
25311
|
+
}
|
|
25312
|
+
/** All sessions, newest activity first. Read-only listing for the dashboard. */
|
|
25313
|
+
listSessions() {
|
|
25314
|
+
const rows2 = this.db.prepare("SELECT * FROM sessions ORDER BY updated_at DESC").all();
|
|
25315
|
+
return rows2.map((row) => ({
|
|
25316
|
+
channelId: row.channel_id,
|
|
25317
|
+
threadTs: row.thread_ts,
|
|
25318
|
+
sessionId: row.session_id,
|
|
25319
|
+
runner: row.runner === "codex" ? "codex" : "claude",
|
|
25320
|
+
createdAt: row.created_at,
|
|
25321
|
+
updatedAt: row.updated_at
|
|
25322
|
+
}));
|
|
25323
|
+
}
|
|
25324
|
+
deleteSession(channelId, threadTs) {
|
|
25325
|
+
this.db.prepare("DELETE FROM sessions WHERE channel_id = ? AND thread_ts = ?").run(channelId, threadTs);
|
|
25326
|
+
}
|
|
25327
|
+
/**
|
|
25328
|
+
* Drop every session in a channel. Used when the channel's execution runtime
|
|
25329
|
+
* changes (`channels.runtime`, 0035): the session ids here point at Claude
|
|
25330
|
+
* session files stored under whichever runtime wrote them — the host's
|
|
25331
|
+
* CLAUDE_CONFIG_DIR, or the container's own per-channel home — so after a
|
|
25332
|
+
* switch every one of them resolves to a file the new runtime cannot see.
|
|
25333
|
+
* Left in place, the next turn in each thread would `--resume` an id that
|
|
25334
|
+
* does not exist there and lose the conversation in a confusing way; dropping
|
|
25335
|
+
* them makes the next turn cleanly start fresh instead.
|
|
25336
|
+
*
|
|
25337
|
+
* Returns how many were removed, so the caller can log something meaningful.
|
|
25338
|
+
*/
|
|
25339
|
+
deleteSessionsForChannel(channelId) {
|
|
25340
|
+
const result = this.db.prepare("DELETE FROM sessions WHERE channel_id = ?").run(channelId);
|
|
25341
|
+
return result.changes;
|
|
25342
|
+
}
|
|
25343
|
+
/**
|
|
25344
|
+
* Re-key a single thread's rows onto a different channel. `sessions`,
|
|
25345
|
+
* `model_overrides` and `effort_overrides` are all keyed by (channel_id,
|
|
25346
|
+
* thread_ts), so moving a thread in the dashboard without this leaves the
|
|
25347
|
+
* agent unable to find its own session: the next turn would start from
|
|
25348
|
+
* scratch and lose the conversation, and any `!model`/`!effort` override on
|
|
25349
|
+
* the thread would silently revert.
|
|
25350
|
+
*
|
|
25351
|
+
* A row already sitting on the destination key wins — that means the thread
|
|
25352
|
+
* has been moved back and forth and the destination row is the newer state,
|
|
25353
|
+
* so the stale source row is dropped rather than overwriting it.
|
|
25354
|
+
*
|
|
25355
|
+
* Returns how many rows were re-keyed in each table.
|
|
25356
|
+
*/
|
|
25357
|
+
moveThread(fromChannelId, toChannelId, threadTs) {
|
|
25358
|
+
const move = this.db.transaction(() => {
|
|
25359
|
+
const counts = { sessions: 0, modelOverrides: 0, effortOverrides: 0 };
|
|
25360
|
+
for (const table of ["sessions", "model_overrides", "effort_overrides"]) {
|
|
25361
|
+
const updated = this.db.prepare(
|
|
25362
|
+
`UPDATE OR IGNORE ${table} SET channel_id = ?
|
|
25363
|
+
WHERE channel_id = ? AND thread_ts = ?`
|
|
25364
|
+
).run(toChannelId, fromChannelId, threadTs);
|
|
25365
|
+
this.db.prepare(`DELETE FROM ${table} WHERE channel_id = ? AND thread_ts = ?`).run(fromChannelId, threadTs);
|
|
25366
|
+
if (table === "sessions") counts.sessions = updated.changes;
|
|
25367
|
+
else if (table === "model_overrides") counts.modelOverrides = updated.changes;
|
|
25368
|
+
else counts.effortOverrides = updated.changes;
|
|
25369
|
+
}
|
|
25370
|
+
return counts;
|
|
25371
|
+
});
|
|
25372
|
+
return move();
|
|
25373
|
+
}
|
|
25374
|
+
getModelOverride(channelId, threadTs) {
|
|
25375
|
+
const row = this.db.prepare("SELECT model FROM model_overrides WHERE channel_id = ? AND thread_ts = ?").get(channelId, threadTs);
|
|
25376
|
+
return row?.model;
|
|
24988
25377
|
}
|
|
24989
25378
|
setModelOverride(channelId, threadTs, model) {
|
|
24990
25379
|
this.db.prepare(
|
|
@@ -25019,13 +25408,13 @@ var SessionStore = class {
|
|
|
25019
25408
|
|
|
25020
25409
|
// src/dashboard/memory-extraction-runner.ts
|
|
25021
25410
|
import { spawn as spawn4 } from "child_process";
|
|
25022
|
-
import { existsSync as
|
|
25411
|
+
import { existsSync as existsSync15, mkdtempSync as mkdtempSync3, readFileSync as readFileSync12, rmSync as rmSync7 } from "fs";
|
|
25023
25412
|
import { tmpdir as tmpdir3 } from "os";
|
|
25024
|
-
import { join as
|
|
25413
|
+
import { join as join14 } from "path";
|
|
25025
25414
|
|
|
25026
25415
|
// ../api/src/dashboard/profile-config.ts
|
|
25027
|
-
import { homedir as
|
|
25028
|
-
import { join as
|
|
25416
|
+
import { homedir as homedir7 } from "os";
|
|
25417
|
+
import { join as join13, parse, resolve as resolve7 } from "path";
|
|
25029
25418
|
|
|
25030
25419
|
// ../api/src/dashboard/profile-config-cache.ts
|
|
25031
25420
|
var cache2 = /* @__PURE__ */ new Map();
|
|
@@ -25044,7 +25433,7 @@ function profileEnv(key) {
|
|
|
25044
25433
|
function profileClaudeConfigDir() {
|
|
25045
25434
|
const config = cachedProfileConfig();
|
|
25046
25435
|
if (!config) return process.env["CLAUDE_CONFIG_DIR"] || void 0;
|
|
25047
|
-
return config.env["CLAUDE_CONFIG_DIR"]?.trim() ||
|
|
25436
|
+
return config.env["CLAUDE_CONFIG_DIR"]?.trim() || join13(homedir7(), ".claude");
|
|
25048
25437
|
}
|
|
25049
25438
|
function profileOauthToken() {
|
|
25050
25439
|
const env = cachedProfileConfig()?.env ?? {};
|
|
@@ -25052,6 +25441,10 @@ function profileOauthToken() {
|
|
|
25052
25441
|
if (env["CLAUDE_CONFIG_DIR"]) return void 0;
|
|
25053
25442
|
return process.env["CLAUDE_CODE_OAUTH_TOKEN"] || void 0;
|
|
25054
25443
|
}
|
|
25444
|
+
function isUnsafeCwd(cwd) {
|
|
25445
|
+
const p = resolve7(cwd);
|
|
25446
|
+
return p === parse(p).root || p === resolve7(homedir7());
|
|
25447
|
+
}
|
|
25055
25448
|
function defaultClaudeCwd() {
|
|
25056
25449
|
return profileEnv("CLAUDE_CWD") ?? process.cwd();
|
|
25057
25450
|
}
|
|
@@ -25064,8 +25457,13 @@ function defaultEffort() {
|
|
|
25064
25457
|
}
|
|
25065
25458
|
function resolveChannelConfig(channelId) {
|
|
25066
25459
|
const channel = findChannel(channelId);
|
|
25460
|
+
const profile = channel?.profile ?? getProfile();
|
|
25461
|
+
const cwd = channel?.cwd ?? defaultClaudeCwd();
|
|
25067
25462
|
return {
|
|
25068
|
-
|
|
25463
|
+
// Never hand an agent or the Docs pane the filesystem root or $HOME (a
|
|
25464
|
+
// Host running as a launchd/systemd service has process.cwd() === '/').
|
|
25465
|
+
// Fall back to a per-channel logical folder instead of exposing the disk.
|
|
25466
|
+
cwd: isUnsafeCwd(cwd) ? resolveLogicalCwd(channel?.dmKey ? dmCwd(channel.dmKey, profile) : `${profile}/${channelId}`) : cwd,
|
|
25069
25467
|
model: channel?.model?.trim() || defaultModel(),
|
|
25070
25468
|
effort: channel?.effort ?? defaultEffort(),
|
|
25071
25469
|
runtime: channel?.runtime ?? "host",
|
|
@@ -25076,7 +25474,7 @@ function resolveChannelConfig(channelId) {
|
|
|
25076
25474
|
claudeConfigDir: profileClaudeConfigDir(),
|
|
25077
25475
|
claudeCodeOauthToken: profileOauthToken(),
|
|
25078
25476
|
agentName: channel?.agentName ?? null,
|
|
25079
|
-
profile
|
|
25477
|
+
profile,
|
|
25080
25478
|
mcpConnections: channel?.mcpConnections ?? []
|
|
25081
25479
|
};
|
|
25082
25480
|
}
|
|
@@ -25087,13 +25485,15 @@ function findOwningProfile(channelId) {
|
|
|
25087
25485
|
// src/dashboard/memory-extraction-runner.ts
|
|
25088
25486
|
var CLAUDE_MODEL = "sonnet";
|
|
25089
25487
|
var CODEX_MODEL = "gpt-6-astra";
|
|
25488
|
+
var CHEAP_CLAUDE_MODEL = "haiku";
|
|
25489
|
+
var CHEAP_CODEX_MODEL = "gpt-5.6-luna";
|
|
25090
25490
|
var CODEX_EFFORT2 = "low";
|
|
25091
25491
|
var TIMEOUT_MS2 = 15e4;
|
|
25092
25492
|
var SUGGEST_TOOLS = "Read,Glob,Grep";
|
|
25093
25493
|
function buildInvocation(runner, req, dir, auth, baseEnv = process.env, tools = "") {
|
|
25094
25494
|
const env = { ...baseEnv, CLAUDE_CODE_DISABLE_AUTO_MEMORY: "1" };
|
|
25095
25495
|
if (runner === "codex") {
|
|
25096
|
-
const outputFile =
|
|
25496
|
+
const outputFile = join14(dir, "last-message.txt");
|
|
25097
25497
|
return {
|
|
25098
25498
|
command: "codex",
|
|
25099
25499
|
args: [
|
|
@@ -25106,7 +25506,7 @@ function buildInvocation(runner, req, dir, auth, baseEnv = process.env, tools =
|
|
|
25106
25506
|
"-s",
|
|
25107
25507
|
"read-only",
|
|
25108
25508
|
"-m",
|
|
25109
|
-
CODEX_MODEL,
|
|
25509
|
+
req.tier === "cheap" ? CHEAP_CODEX_MODEL : CODEX_MODEL,
|
|
25110
25510
|
"-c",
|
|
25111
25511
|
`model_reasoning_effort=${CODEX_EFFORT2}`,
|
|
25112
25512
|
"--output-last-message",
|
|
@@ -25128,12 +25528,12 @@ ${req.user}`,
|
|
|
25128
25528
|
else delete env["CLAUDE_CONFIG_DIR"];
|
|
25129
25529
|
if (auth.claudeCodeOauthToken) env["CLAUDE_CODE_OAUTH_TOKEN"] = auth.claudeCodeOauthToken;
|
|
25130
25530
|
else delete env["CLAUDE_CODE_OAUTH_TOKEN"];
|
|
25531
|
+
const model = req.tier === "cheap" ? CHEAP_CLAUDE_MODEL : CLAUDE_MODEL;
|
|
25131
25532
|
return {
|
|
25132
25533
|
command: "claude",
|
|
25133
25534
|
args: [
|
|
25134
25535
|
"-p",
|
|
25135
|
-
"--model",
|
|
25136
|
-
CLAUDE_MODEL,
|
|
25536
|
+
...isModelForGateway(model, baseEnv["ANTHROPIC_MODEL"]) ? ["--model", model] : [],
|
|
25137
25537
|
"--no-session-persistence",
|
|
25138
25538
|
"--tools",
|
|
25139
25539
|
tools,
|
|
@@ -25148,9 +25548,9 @@ ${req.user}`,
|
|
|
25148
25548
|
};
|
|
25149
25549
|
}
|
|
25150
25550
|
function run(inv, cwd) {
|
|
25151
|
-
return new Promise((
|
|
25152
|
-
if (!
|
|
25153
|
-
|
|
25551
|
+
return new Promise((resolve9) => {
|
|
25552
|
+
if (!existsSync15(cwd)) {
|
|
25553
|
+
resolve9({ ok: false, error: `the channel folder ${cwd} does not exist on this Host` });
|
|
25154
25554
|
return;
|
|
25155
25555
|
}
|
|
25156
25556
|
const child = spawn4(inv.command, inv.args, {
|
|
@@ -25168,7 +25568,7 @@ function run(inv, cwd) {
|
|
|
25168
25568
|
child.on("error", (err) => {
|
|
25169
25569
|
clearTimeout(timer);
|
|
25170
25570
|
console.error(`[memory-extraction] ${inv.command} failed to start:`, err.message);
|
|
25171
|
-
|
|
25571
|
+
resolve9({ ok: false, error: `${inv.command} failed to start: ${err.message}` });
|
|
25172
25572
|
});
|
|
25173
25573
|
child.on("close", (code) => {
|
|
25174
25574
|
clearTimeout(timer);
|
|
@@ -25176,18 +25576,18 @@ function run(inv, cwd) {
|
|
|
25176
25576
|
const detail = (stderr || stdout).trim().split("\n").at(-1) ?? "";
|
|
25177
25577
|
const error = `${inv.command} exited ${code ?? "on timeout"}: ${detail.slice(0, 200)}`;
|
|
25178
25578
|
console.error(`[memory-extraction] ${error}`);
|
|
25179
|
-
|
|
25579
|
+
resolve9({ ok: false, error });
|
|
25180
25580
|
return;
|
|
25181
25581
|
}
|
|
25182
25582
|
let raw = stdout;
|
|
25183
25583
|
if (inv.outputFile) {
|
|
25184
25584
|
try {
|
|
25185
|
-
raw =
|
|
25585
|
+
raw = readFileSync12(inv.outputFile, "utf-8");
|
|
25186
25586
|
} catch {
|
|
25187
25587
|
raw = "";
|
|
25188
25588
|
}
|
|
25189
25589
|
}
|
|
25190
|
-
|
|
25590
|
+
resolve9({ ok: true, raw });
|
|
25191
25591
|
});
|
|
25192
25592
|
child.stdin.end(inv.stdin);
|
|
25193
25593
|
});
|
|
@@ -25195,7 +25595,7 @@ function run(inv, cwd) {
|
|
|
25195
25595
|
async function complete(req, tools = "", cwd) {
|
|
25196
25596
|
const runner = runnerForModel(loadDashboardSettings().agent);
|
|
25197
25597
|
const config = resolveChannelConfig(req.channelId);
|
|
25198
|
-
const dir = mkdtempSync3(
|
|
25598
|
+
const dir = mkdtempSync3(join14(tmpdir3(), "flyspace-memory-"));
|
|
25199
25599
|
try {
|
|
25200
25600
|
const inv = buildInvocation(
|
|
25201
25601
|
runner,
|
|
@@ -25210,7 +25610,7 @@ async function complete(req, tools = "", cwd) {
|
|
|
25210
25610
|
);
|
|
25211
25611
|
return await run(inv, cwd ?? dir);
|
|
25212
25612
|
} finally {
|
|
25213
|
-
|
|
25613
|
+
rmSync7(dir, { recursive: true, force: true });
|
|
25214
25614
|
}
|
|
25215
25615
|
}
|
|
25216
25616
|
function completeMemoryExtraction(req) {
|
|
@@ -25360,6 +25760,31 @@ var RATE_CARDS = [
|
|
|
25360
25760
|
cacheReadPer1M: 0.02,
|
|
25361
25761
|
cacheWritePer1M: 0.2,
|
|
25362
25762
|
effectiveFrom: EPOCH
|
|
25763
|
+
},
|
|
25764
|
+
{
|
|
25765
|
+
// Groq's models page, checked 2026-10-30. Our own spend (titles, translation,
|
|
25766
|
+
// autocomplete, retros), priced so we can account for it. Groq does not
|
|
25767
|
+
// publish a cache-hit rate here, so cache reads are priced at full input.
|
|
25768
|
+
id: "groq:gpt-oss-120b@1030",
|
|
25769
|
+
provider: "groq",
|
|
25770
|
+
model: "GPT OSS 120B",
|
|
25771
|
+
matches: ["openai/gpt-oss-120b", "gpt-oss-120b"],
|
|
25772
|
+
inputPer1M: 0.15,
|
|
25773
|
+
outputPer1M: 0.6,
|
|
25774
|
+
cacheReadPer1M: 0.15,
|
|
25775
|
+
cacheWritePer1M: 0.15,
|
|
25776
|
+
effectiveFrom: EPOCH
|
|
25777
|
+
},
|
|
25778
|
+
{
|
|
25779
|
+
id: "groq:gpt-oss-20b@1030",
|
|
25780
|
+
provider: "groq",
|
|
25781
|
+
model: "GPT OSS 20B",
|
|
25782
|
+
matches: ["openai/gpt-oss-20b", "gpt-oss-20b"],
|
|
25783
|
+
inputPer1M: 0.075,
|
|
25784
|
+
outputPer1M: 0.3,
|
|
25785
|
+
cacheReadPer1M: 0.075,
|
|
25786
|
+
cacheWritePer1M: 0.075,
|
|
25787
|
+
effectiveFrom: EPOCH
|
|
25363
25788
|
}
|
|
25364
25789
|
];
|
|
25365
25790
|
var BY_ID = new Map(RATE_CARDS.map((c) => [c.id, c]));
|
|
@@ -25375,6 +25800,7 @@ function providerFor(model) {
|
|
|
25375
25800
|
if (id.startsWith("claude") || /^(opus|sonnet|haiku|fable|mythos)/.test(id)) return "anthropic";
|
|
25376
25801
|
if (id.startsWith("deepseek")) return "deepseek";
|
|
25377
25802
|
if (id.startsWith("kimi") || id.startsWith("moonshot") || id === "k3") return "moonshot";
|
|
25803
|
+
if (id.startsWith("openai/gpt-oss") || id.startsWith("gpt-oss") || id.startsWith("whisper")) return "groq";
|
|
25378
25804
|
if (id.startsWith("gpt")) return "openai";
|
|
25379
25805
|
return "unknown";
|
|
25380
25806
|
}
|
|
@@ -25884,9 +26310,9 @@ var UsageStore = class {
|
|
|
25884
26310
|
|
|
25885
26311
|
// src/dashboard/rollover-summary.ts
|
|
25886
26312
|
import { spawn as spawn5 } from "child_process";
|
|
25887
|
-
import { existsSync as
|
|
26313
|
+
import { existsSync as existsSync16, mkdtempSync as mkdtempSync4, readFileSync as readFileSync13, rmSync as rmSync8 } from "fs";
|
|
25888
26314
|
import { tmpdir as tmpdir4 } from "os";
|
|
25889
|
-
import { join as
|
|
26315
|
+
import { join as join15 } from "path";
|
|
25890
26316
|
var HAIKU_MODEL = "haiku";
|
|
25891
26317
|
var CJK_PATTERN = /[ -〿-ヿ㐀-䶿一-鿿豈--]/;
|
|
25892
26318
|
function estimateTokens(text) {
|
|
@@ -25949,8 +26375,8 @@ function runSummaryPrint(input, options) {
|
|
|
25949
26375
|
return runPrint("claude", args, env).then((out) => out.trim());
|
|
25950
26376
|
}
|
|
25951
26377
|
async function runCodexSummary(input) {
|
|
25952
|
-
const dir = mkdtempSync4(
|
|
25953
|
-
const lastMessageFile =
|
|
26378
|
+
const dir = mkdtempSync4(join15(tmpdir4(), "rollover-"));
|
|
26379
|
+
const lastMessageFile = join15(dir, "last-message.txt");
|
|
25954
26380
|
try {
|
|
25955
26381
|
await runPrint(
|
|
25956
26382
|
"codex",
|
|
@@ -25973,13 +26399,13 @@ ${input}`
|
|
|
25973
26399
|
],
|
|
25974
26400
|
{ ...process.env }
|
|
25975
26401
|
);
|
|
25976
|
-
return
|
|
26402
|
+
return existsSync16(lastMessageFile) ? readFileSync13(lastMessageFile, "utf8").trim() : "";
|
|
25977
26403
|
} finally {
|
|
25978
|
-
|
|
26404
|
+
rmSync8(dir, { recursive: true, force: true });
|
|
25979
26405
|
}
|
|
25980
26406
|
}
|
|
25981
26407
|
function runPrint(command, args, env) {
|
|
25982
|
-
return new Promise((
|
|
26408
|
+
return new Promise((resolve9, reject) => {
|
|
25983
26409
|
const child = spawn5(command, args, {
|
|
25984
26410
|
// A stateless rewrite touches no files — tmpdir keeps it that way and
|
|
25985
26411
|
// avoids picking up an unrelated project's own CLAUDE.md/AGENTS.md,
|
|
@@ -26009,7 +26435,7 @@ function runPrint(command, args, env) {
|
|
|
26009
26435
|
reject(new Error(`${command} summary exited with code ${code}: ${stderr.trim()}`));
|
|
26010
26436
|
return;
|
|
26011
26437
|
}
|
|
26012
|
-
|
|
26438
|
+
resolve9(stdout);
|
|
26013
26439
|
});
|
|
26014
26440
|
});
|
|
26015
26441
|
}
|
|
@@ -26197,6 +26623,7 @@ import { execFile } from "child_process";
|
|
|
26197
26623
|
import { promisify } from "util";
|
|
26198
26624
|
var execFileAsync = promisify(execFile);
|
|
26199
26625
|
var WAKE_THREAD_RE = /chat wake\b.*?--thread[ =]['"]?([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/;
|
|
26626
|
+
var ABOUT_RE = /chat wake\b.*?--about[ =](?:"([^"]*)"|'([^']*)'|(\S+))/;
|
|
26200
26627
|
function parseEtime(etime) {
|
|
26201
26628
|
const [days, rest] = etime.includes("-") ? etime.split("-") : ["0", etime];
|
|
26202
26629
|
const parts = rest.split(":").map(Number);
|
|
@@ -26205,23 +26632,41 @@ function parseEtime(etime) {
|
|
|
26205
26632
|
return Number(days) * 86400 + h * 3600 + m * 60 + s;
|
|
26206
26633
|
}
|
|
26207
26634
|
function parseBackgroundTasks(psOutput, now = Date.now()) {
|
|
26635
|
+
const rows2 = psOutput.split("\n").flatMap((line) => {
|
|
26636
|
+
const m = /^\s*(\d+)\s+(\d+)\s+(\S+)\s+(.*)$/.exec(line);
|
|
26637
|
+
return m ? [{ pid: Number(m[1]), ppid: Number(m[2]), age: parseEtime(m[3]), command: m[4] }] : [];
|
|
26638
|
+
});
|
|
26639
|
+
const children = /* @__PURE__ */ new Map();
|
|
26640
|
+
for (const row of rows2) children.set(row.ppid, [...children.get(row.ppid) ?? [], row]);
|
|
26641
|
+
const isJob = (command) => !/^\S*node\b/.test(command) && WAKE_THREAD_RE.test(command);
|
|
26642
|
+
const jobPids = new Set(rows2.filter((r) => isJob(r.command)).map((r) => r.pid));
|
|
26208
26643
|
const byThread = /* @__PURE__ */ new Map();
|
|
26209
|
-
for (const
|
|
26210
|
-
|
|
26211
|
-
|
|
26212
|
-
|
|
26213
|
-
|
|
26214
|
-
|
|
26215
|
-
|
|
26644
|
+
for (const row of rows2) {
|
|
26645
|
+
if (!jobPids.has(row.pid) || jobPids.has(row.ppid)) continue;
|
|
26646
|
+
const threadId = WAKE_THREAD_RE.exec(row.command)[1];
|
|
26647
|
+
let current;
|
|
26648
|
+
const stack = [...children.get(row.pid) ?? []];
|
|
26649
|
+
while (stack.length) {
|
|
26650
|
+
const child = stack.pop();
|
|
26651
|
+
stack.push(...children.get(child.pid) ?? []);
|
|
26652
|
+
if (!jobPids.has(child.pid) && (!current || child.age < current.age)) current = child;
|
|
26653
|
+
}
|
|
26654
|
+
const about = ABOUT_RE.exec(row.command);
|
|
26216
26655
|
const list = byThread.get(threadId) ?? [];
|
|
26217
|
-
list.push({
|
|
26656
|
+
list.push({
|
|
26657
|
+
pid: row.pid,
|
|
26658
|
+
startedAt: now - row.age * 1e3,
|
|
26659
|
+
command: row.command,
|
|
26660
|
+
...about && { about: (about[1] ?? about[2] ?? about[3]).trim() },
|
|
26661
|
+
...current && { current: current.command }
|
|
26662
|
+
});
|
|
26218
26663
|
byThread.set(threadId, list);
|
|
26219
26664
|
}
|
|
26220
26665
|
return byThread;
|
|
26221
26666
|
}
|
|
26222
26667
|
async function scanBackgroundTasks() {
|
|
26223
26668
|
try {
|
|
26224
|
-
const { stdout } = await execFileAsync("ps", ["-axo", "pid=,etime=,command="], {
|
|
26669
|
+
const { stdout } = await execFileAsync("ps", ["-axo", "pid=,ppid=,etime=,command="], {
|
|
26225
26670
|
maxBuffer: 16 * 1024 * 1024
|
|
26226
26671
|
});
|
|
26227
26672
|
return parseBackgroundTasks(stdout);
|
|
@@ -26232,7 +26677,7 @@ async function scanBackgroundTasks() {
|
|
|
26232
26677
|
|
|
26233
26678
|
// src/dashboard/attachment-downloader.ts
|
|
26234
26679
|
import { writeFile as writeFile2 } from "fs/promises";
|
|
26235
|
-
import { join as
|
|
26680
|
+
import { join as join16 } from "path";
|
|
26236
26681
|
import { GetObjectCommand } from "@aws-sdk/client-s3";
|
|
26237
26682
|
var debug4 = process.env["DEBUG"] === "true";
|
|
26238
26683
|
var ATTACHMENT_LINK = /\]\((?:https:\/\/[a-z0-9-]+\.flyspace\.ai)?\/api\/attachments\/([^)?\s]+)(?:\?[^)\s]*)?\)/g;
|
|
@@ -26299,7 +26744,7 @@ async function downloadOne2(key) {
|
|
|
26299
26744
|
if (bytes.length > sizeLimit) {
|
|
26300
26745
|
return { kind: "skip", skipped: { name, mimetype, reason: "too_large" } };
|
|
26301
26746
|
}
|
|
26302
|
-
const localPath =
|
|
26747
|
+
const localPath = join16(paths.UPLOADS_DIR, lastSegment);
|
|
26303
26748
|
await writeFile2(localPath, bytes);
|
|
26304
26749
|
if (debug4)
|
|
26305
26750
|
console.log(`[attachment-downloader] saved ${key} -> ${localPath} (${bytes.length} bytes)`);
|
|
@@ -26324,27 +26769,27 @@ async function downloadChatAttachments(body) {
|
|
|
26324
26769
|
}
|
|
26325
26770
|
|
|
26326
26771
|
// src/dashboard/doc-mention-guard.ts
|
|
26327
|
-
import { existsSync as
|
|
26772
|
+
import { existsSync as existsSync21, statSync as statSync9 } from "fs";
|
|
26328
26773
|
|
|
26329
26774
|
// src/dashboard/docs-routes.ts
|
|
26330
26775
|
import {
|
|
26331
26776
|
closeSync,
|
|
26332
26777
|
createReadStream,
|
|
26333
|
-
existsSync as
|
|
26778
|
+
existsSync as existsSync20,
|
|
26334
26779
|
lstatSync as lstatSync2,
|
|
26335
|
-
mkdirSync as
|
|
26780
|
+
mkdirSync as mkdirSync10,
|
|
26336
26781
|
openSync,
|
|
26337
26782
|
readSync,
|
|
26338
|
-
readdirSync as
|
|
26339
|
-
readFileSync as
|
|
26783
|
+
readdirSync as readdirSync5,
|
|
26784
|
+
readFileSync as readFileSync17,
|
|
26340
26785
|
realpathSync as realpathSync2,
|
|
26341
26786
|
renameSync as renameSync2,
|
|
26342
|
-
rmSync as
|
|
26343
|
-
statSync as
|
|
26344
|
-
writeFileSync as
|
|
26787
|
+
rmSync as rmSync9,
|
|
26788
|
+
statSync as statSync8,
|
|
26789
|
+
writeFileSync as writeFileSync7
|
|
26345
26790
|
} from "fs";
|
|
26346
26791
|
import { Readable } from "stream";
|
|
26347
|
-
import { basename as
|
|
26792
|
+
import { basename as basename5, dirname as dirname3, extname as extname2, join as join20, relative as relative2, resolve as resolve8, sep as sep4 } from "path";
|
|
26348
26793
|
import { Hono as Hono4 } from "hono";
|
|
26349
26794
|
import { streamSSE } from "hono/streaming";
|
|
26350
26795
|
|
|
@@ -26456,8 +26901,8 @@ var requireDocsAccess = async (c, next) => {
|
|
|
26456
26901
|
};
|
|
26457
26902
|
|
|
26458
26903
|
// src/dashboard/docs-watcher.ts
|
|
26459
|
-
import { existsSync as
|
|
26460
|
-
import { basename as
|
|
26904
|
+
import { existsSync as existsSync17, watch } from "fs";
|
|
26905
|
+
import { basename as basename4, join as join17 } from "path";
|
|
26461
26906
|
var DEBOUNCE_MS = 200;
|
|
26462
26907
|
var MAX_PENDING = 200;
|
|
26463
26908
|
var IGNORED_SEGMENTS = /* @__PURE__ */ new Set([
|
|
@@ -26493,12 +26938,12 @@ function flush(cwd) {
|
|
|
26493
26938
|
function watchDocs(cwd, listener) {
|
|
26494
26939
|
let entry = entries.get(cwd);
|
|
26495
26940
|
if (!entry) {
|
|
26496
|
-
const root =
|
|
26941
|
+
const root = basename4(cwd);
|
|
26497
26942
|
const watcher = watch(cwd, { recursive: true, persistent: false }, (_event, filename) => {
|
|
26498
26943
|
const current = entries.get(cwd);
|
|
26499
26944
|
if (!current || filename === null) return;
|
|
26500
26945
|
const rel = filename.split("\\").join("/");
|
|
26501
|
-
if (rel === root && !
|
|
26946
|
+
if (rel === root && !existsSync17(join17(cwd, rel))) return;
|
|
26502
26947
|
if (isIgnoredDocPath(rel)) return;
|
|
26503
26948
|
if (current.pending.size < MAX_PENDING) current.pending.add(rel);
|
|
26504
26949
|
if (current.timer === null) current.timer = setTimeout(() => flush(cwd), DEBOUNCE_MS);
|
|
@@ -26552,7 +26997,7 @@ async function putDocTranslation(input) {
|
|
|
26552
26997
|
}
|
|
26553
26998
|
|
|
26554
26999
|
// ../api/src/dashboard/share-translate.ts
|
|
26555
|
-
import { createHash as
|
|
27000
|
+
import { createHash as createHash5 } from "crypto";
|
|
26556
27001
|
|
|
26557
27002
|
// ../api/src/store/doc-share-store.ts
|
|
26558
27003
|
function rowToKind(value) {
|
|
@@ -26862,7 +27307,7 @@ function languageName(lang) {
|
|
|
26862
27307
|
return BY_CODE.get(lang)?.name ?? null;
|
|
26863
27308
|
}
|
|
26864
27309
|
function translationHash(title, content) {
|
|
26865
|
-
return
|
|
27310
|
+
return createHash5("sha256").update(`${RECIPE_VERSION}
|
|
26866
27311
|
${title}
|
|
26867
27312
|
${content}`).digest("hex");
|
|
26868
27313
|
}
|
|
@@ -27018,7 +27463,7 @@ async function clearStaleDocAudios(channelId, sourcePath, lang, exceptHash) {
|
|
|
27018
27463
|
}
|
|
27019
27464
|
|
|
27020
27465
|
// ../api/src/dashboard/share-audio.ts
|
|
27021
|
-
import { createHash as
|
|
27466
|
+
import { createHash as createHash6 } from "crypto";
|
|
27022
27467
|
import { DeleteObjectCommand, PutObjectCommand as PutObjectCommand2 } from "@aws-sdk/client-s3";
|
|
27023
27468
|
|
|
27024
27469
|
// ../api/src/dashboard/tts-routes.ts
|
|
@@ -27217,7 +27662,7 @@ Pacing \u2014 the engine has NO pause control, so rhythm has to be built into th
|
|
|
27217
27662
|
Output plain text ONLY. No tags of any kind, no angle brackets, no Markdown, no quotation wrapping. Any tag you emit will be deleted before synthesis, so it buys nothing and costs meaning.`;
|
|
27218
27663
|
}
|
|
27219
27664
|
function articleAudioHash(title, content) {
|
|
27220
|
-
return
|
|
27665
|
+
return createHash6("sha256").update(`v${RECIPE_VERSION2}
|
|
27221
27666
|
${title}
|
|
27222
27667
|
|
|
27223
27668
|
${content}`).digest("hex").slice(0, 32);
|
|
@@ -27340,7 +27785,7 @@ function truncationNotice(lang, voice) {
|
|
|
27340
27785
|
if (lang === "en" || lang.startsWith("en-")) return TRUNCATION_NOTICE.en;
|
|
27341
27786
|
return null;
|
|
27342
27787
|
}
|
|
27343
|
-
var sleep2 = (ms) => new Promise((
|
|
27788
|
+
var sleep2 = (ms) => new Promise((resolve9) => setTimeout(resolve9, ms));
|
|
27344
27789
|
async function synthesizeWithRetry(script, voice) {
|
|
27345
27790
|
let lastError;
|
|
27346
27791
|
for (let attempt = 1; attempt <= SYNTH_ATTEMPTS; attempt += 1) {
|
|
@@ -27444,7 +27889,7 @@ function queueShareAudio(share) {
|
|
|
27444
27889
|
var PENDING_STALE_MS = 30 * 60 * 1e3;
|
|
27445
27890
|
var FAILED_RETRY_MS = 10 * 60 * 1e3;
|
|
27446
27891
|
function langAudioHash(title, content, lang) {
|
|
27447
|
-
return
|
|
27892
|
+
return createHash6("sha256").update(`v${RECIPE_VERSION2}
|
|
27448
27893
|
${lang}
|
|
27449
27894
|
${translationHash(title, content)}`).digest("hex").slice(0, 32);
|
|
27450
27895
|
}
|
|
@@ -27818,7 +28263,8 @@ function createFeatureFlagsRouter() {
|
|
|
27818
28263
|
if (auth.role !== "admin") return c.json({ error: "admin access required" }, 403);
|
|
27819
28264
|
const flagId = c.req.param("flagId") ?? "";
|
|
27820
28265
|
if (!isFeatureFlagId(flagId)) return c.json({ error: "unknown feature flag" }, 404);
|
|
27821
|
-
|
|
28266
|
+
const stage = featureFlags[flagId].stage;
|
|
28267
|
+
if (stage !== "setting" && !isFeatureVisible(stage, isDevHost(c))) {
|
|
27822
28268
|
return c.json({ error: "this feature flag cannot be changed here" }, 403);
|
|
27823
28269
|
}
|
|
27824
28270
|
if (enabled) await enableFeatureFlag(auth.workspaceId, flagId, auth.userId);
|
|
@@ -27831,8 +28277,8 @@ function createFeatureFlagsRouter() {
|
|
|
27831
28277
|
}
|
|
27832
28278
|
|
|
27833
28279
|
// ../api/src/dashboard/public-share-routes.ts
|
|
27834
|
-
import { existsSync as
|
|
27835
|
-
import { join as
|
|
28280
|
+
import { existsSync as existsSync19, readFileSync as readFileSync15, statSync as statSync7 } from "fs";
|
|
28281
|
+
import { join as join19 } from "path";
|
|
27836
28282
|
import { Hono as Hono3 } from "hono";
|
|
27837
28283
|
import { GetObjectCommand as GetObjectCommand3 } from "@aws-sdk/client-s3";
|
|
27838
28284
|
import { getSignedUrl as getSignedUrl2 } from "@aws-sdk/s3-request-presigner";
|
|
@@ -28038,14 +28484,14 @@ function injectShareHead(html, head) {
|
|
|
28038
28484
|
}
|
|
28039
28485
|
|
|
28040
28486
|
// ../api/src/dashboard/app-icon.ts
|
|
28041
|
-
import { createHash as
|
|
28042
|
-
import { existsSync as
|
|
28043
|
-
import { join as
|
|
28487
|
+
import { createHash as createHash7 } from "crypto";
|
|
28488
|
+
import { existsSync as existsSync18, readFileSync as readFileSync14 } from "fs";
|
|
28489
|
+
import { join as join18 } from "path";
|
|
28044
28490
|
import sharp2 from "sharp";
|
|
28045
28491
|
var PLATE = "#0A0A0F";
|
|
28046
|
-
var BRAND_DIR =
|
|
28047
|
-
var MARK_FILE =
|
|
28048
|
-
var MARK_SVG_FILE =
|
|
28492
|
+
var BRAND_DIR = existsSync18(join18(paths.WEB_ROOT, "public")) ? join18(paths.WEB_ROOT, "public") : join18(paths.PACKAGE_ROOT, "dist", "brand");
|
|
28493
|
+
var MARK_FILE = join18(BRAND_DIR, "icons", "icon-512.png");
|
|
28494
|
+
var MARK_SVG_FILE = join18(BRAND_DIR, "favicon.svg");
|
|
28049
28495
|
var LAYOUT = {
|
|
28050
28496
|
standard: { logo: 0.7, logoCx: 0.5, logoCy: 0.48, badge: 0.27, badgeCx: 0.22, badgeCy: 0.76 },
|
|
28051
28497
|
maskable: { logo: 0.56, logoCx: 0.5, logoCy: 0.48, badge: 0.23, badgeCx: 0.33, badgeCy: 0.66 }
|
|
@@ -28068,7 +28514,7 @@ function roundedPlate(size, fill = PLATE) {
|
|
|
28068
28514
|
}
|
|
28069
28515
|
async function renderBadge(box) {
|
|
28070
28516
|
const transparent = { r: 0, g: 0, b: 0, alpha: 0 };
|
|
28071
|
-
const raster = await sharp2(
|
|
28517
|
+
const raster = await sharp2(readFileSync14(MARK_SVG_FILE)).resize(512, 512, { fit: "contain", background: transparent }).png().toBuffer();
|
|
28072
28518
|
return sharp2(raster).trim().resize(box, box, { fit: "contain", background: transparent }).png().toBuffer();
|
|
28073
28519
|
}
|
|
28074
28520
|
async function sampleBackground(logo) {
|
|
@@ -28117,13 +28563,13 @@ async function renderAppIcon({
|
|
|
28117
28563
|
size,
|
|
28118
28564
|
maskable ? "maskable" : "std",
|
|
28119
28565
|
plain ? "plain" : "badged",
|
|
28120
|
-
logo ?
|
|
28566
|
+
logo ? createHash7("sha1").update(logo).digest("hex").slice(0, 12) : transparent ? "stock-transparent" : "stock"
|
|
28121
28567
|
].join(":");
|
|
28122
28568
|
const hit = cache4.get(key);
|
|
28123
28569
|
if (hit) return hit;
|
|
28124
28570
|
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,
|
|
28125
28571
|
// either on its usual dark plate or, for a favicon, trimmed and bare.
|
|
28126
|
-
(transparent ? await renderBadge(size) : await sharp2(
|
|
28572
|
+
(transparent ? await renderBadge(size) : await sharp2(readFileSync14(MARK_FILE)).resize(size, size, { fit: "cover" }).png().toBuffer());
|
|
28127
28573
|
cache4.set(key, out);
|
|
28128
28574
|
return out;
|
|
28129
28575
|
}
|
|
@@ -28146,41 +28592,9 @@ async function composeIcon(logo, size, maskable, plain) {
|
|
|
28146
28592
|
]).png().toBuffer();
|
|
28147
28593
|
return sharp2(composed).composite([{ input: roundedPlate(size), blend: "dest-in" }]).png().toBuffer();
|
|
28148
28594
|
}
|
|
28149
|
-
function buildManifest(profile, displayName2) {
|
|
28150
|
-
const workspace = displayName2?.trim() || profile;
|
|
28151
|
-
const icon = (file) => `/icons/app/${profile}/${file}`;
|
|
28152
|
-
return {
|
|
28153
|
-
id: `/?workspace=${profile}`,
|
|
28154
|
-
name: workspace === "Flyspace" ? "Flyspace" : `${workspace} \xB7 Flyspace`,
|
|
28155
|
-
short_name: workspace,
|
|
28156
|
-
description: "The AI native workspace",
|
|
28157
|
-
start_url: `/?workspace=${profile}`,
|
|
28158
|
-
scope: "/",
|
|
28159
|
-
display: "standalone",
|
|
28160
|
-
background_color: PLATE,
|
|
28161
|
-
theme_color: PLATE,
|
|
28162
|
-
icons: [
|
|
28163
|
-
{ src: icon("icon-192.png"), sizes: "192x192", type: "image/png" },
|
|
28164
|
-
{ src: icon("icon-512.png"), sizes: "512x512", type: "image/png" },
|
|
28165
|
-
{
|
|
28166
|
-
src: icon("icon-512-maskable.png"),
|
|
28167
|
-
sizes: "512x512",
|
|
28168
|
-
type: "image/png",
|
|
28169
|
-
purpose: "maskable"
|
|
28170
|
-
}
|
|
28171
|
-
],
|
|
28172
|
-
shortcuts: [
|
|
28173
|
-
{
|
|
28174
|
-
name: "New post",
|
|
28175
|
-
url: `/?workspace=${profile}&compose=1`,
|
|
28176
|
-
icons: [{ src: icon("icon-192.png"), sizes: "192x192", type: "image/png" }]
|
|
28177
|
-
}
|
|
28178
|
-
]
|
|
28179
|
-
};
|
|
28180
|
-
}
|
|
28181
28595
|
|
|
28182
28596
|
// ../api/src/dashboard/share-og.ts
|
|
28183
|
-
import { createHash as
|
|
28597
|
+
import { createHash as createHash8 } from "crypto";
|
|
28184
28598
|
import sharp3 from "sharp";
|
|
28185
28599
|
var WIDTH = 1200;
|
|
28186
28600
|
var HEIGHT = 630;
|
|
@@ -28358,7 +28772,7 @@ function cacheKey(input) {
|
|
|
28358
28772
|
input.logo ?? "",
|
|
28359
28773
|
input.theme ?? ""
|
|
28360
28774
|
];
|
|
28361
|
-
return
|
|
28775
|
+
return createHash8("sha1").update(parts.join("\0")).digest("hex");
|
|
28362
28776
|
}
|
|
28363
28777
|
async function renderShareOgImage(input) {
|
|
28364
28778
|
const key = cacheKey(input);
|
|
@@ -28373,7 +28787,7 @@ async function renderShareOgImage(input) {
|
|
|
28373
28787
|
}
|
|
28374
28788
|
|
|
28375
28789
|
// ../api/src/dashboard/share-ask.ts
|
|
28376
|
-
import { createHash as
|
|
28790
|
+
import { createHash as createHash9 } from "crypto";
|
|
28377
28791
|
var MAX_ARTICLE_CHARS3 = 24e3;
|
|
28378
28792
|
var MAX_QUESTION_CHARS = 500;
|
|
28379
28793
|
var SUGGESTION_COUNT = 4;
|
|
@@ -28438,7 +28852,7 @@ function parseSuggestions(raw) {
|
|
|
28438
28852
|
var CACHE_LIMIT = 200;
|
|
28439
28853
|
var suggestionCache = /* @__PURE__ */ new Map();
|
|
28440
28854
|
function articleHash(title, content, lang) {
|
|
28441
|
-
return
|
|
28855
|
+
return createHash9("sha256").update(`${lang ?? ""}
|
|
28442
28856
|
${title}
|
|
28443
28857
|
|
|
28444
28858
|
${content}`).digest("hex").slice(0, 32);
|
|
@@ -28692,9 +29106,9 @@ function createPublicShareApiRouter() {
|
|
|
28692
29106
|
var BUILD_PREFIX = "/share/_assets";
|
|
28693
29107
|
var shellCache = null;
|
|
28694
29108
|
function readShell(path) {
|
|
28695
|
-
const { mtimeMs } =
|
|
29109
|
+
const { mtimeMs } = statSync7(path);
|
|
28696
29110
|
if (shellCache?.mtimeMs === mtimeMs) return shellCache.html;
|
|
28697
|
-
const html =
|
|
29111
|
+
const html = readFileSync15(path, "utf8").replaceAll('"/assets/', `"${BUILD_PREFIX}/`);
|
|
28698
29112
|
shellCache = { mtimeMs, html };
|
|
28699
29113
|
return html;
|
|
28700
29114
|
}
|
|
@@ -28714,17 +29128,17 @@ function serveBuildFile(c, webDist, dir, name) {
|
|
|
28714
29128
|
if (!type || !/^[A-Za-z0-9._-]+$/.test(name) || name.includes("..")) {
|
|
28715
29129
|
return c.text("not found", 404);
|
|
28716
29130
|
}
|
|
28717
|
-
const path =
|
|
28718
|
-
if (!
|
|
29131
|
+
const path = join19(webDist, dir, name);
|
|
29132
|
+
if (!existsSync19(path)) return c.text("not found", 404);
|
|
28719
29133
|
c.header("Content-Type", type);
|
|
28720
29134
|
c.header("Cache-Control", "public, max-age=31536000, immutable");
|
|
28721
29135
|
if (ext === ".css") {
|
|
28722
|
-
return c.body(
|
|
29136
|
+
return c.body(readFileSync15(path, "utf8").replaceAll("url(/fonts/", `url(${BUILD_PREFIX}/fonts/`));
|
|
28723
29137
|
}
|
|
28724
29138
|
if (ext === ".js") {
|
|
28725
|
-
return c.body(
|
|
29139
|
+
return c.body(readFileSync15(path, "utf8").replaceAll('"/assets/', `"${BUILD_PREFIX}/`));
|
|
28726
29140
|
}
|
|
28727
|
-
return c.body(new Uint8Array(
|
|
29141
|
+
return c.body(new Uint8Array(readFileSync15(path)));
|
|
28728
29142
|
}
|
|
28729
29143
|
var HTML_SHARE_CSP = "sandbox allow-scripts allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox";
|
|
28730
29144
|
function servePublishedHtml(c, share) {
|
|
@@ -28860,8 +29274,8 @@ ${analytics}` : head);
|
|
|
28860
29274
|
const requested = c.req.param("lang");
|
|
28861
29275
|
const lang = canonicalLanguage(requested);
|
|
28862
29276
|
if (!isTranslatableLanguage(lang)) return next();
|
|
28863
|
-
const shell =
|
|
28864
|
-
if (!
|
|
29277
|
+
const shell = join19(webDist, "index.html");
|
|
29278
|
+
if (!existsSync19(shell)) return next();
|
|
28865
29279
|
const share = await getDocShare(c.req.param("id"));
|
|
28866
29280
|
if (!share) return next();
|
|
28867
29281
|
if (requested !== lang) return c.redirect(`/share/${share.id}/${lang}`, 302);
|
|
@@ -28896,8 +29310,8 @@ ${analytics}` : head);
|
|
|
28896
29310
|
const share = await getDocShare(c.req.param("id"));
|
|
28897
29311
|
if (!share) return next();
|
|
28898
29312
|
if (share.kind === "html") return servePublishedHtml(c, share);
|
|
28899
|
-
const shell =
|
|
28900
|
-
if (!
|
|
29313
|
+
const shell = join19(webDist, "index.html");
|
|
29314
|
+
if (!existsSync19(shell)) return next();
|
|
28901
29315
|
return readerPage(
|
|
28902
29316
|
c,
|
|
28903
29317
|
share,
|
|
@@ -28922,7 +29336,7 @@ ${analytics}` : head);
|
|
|
28922
29336
|
}
|
|
28923
29337
|
|
|
28924
29338
|
// src/dashboard/artifact-export.ts
|
|
28925
|
-
import { readFileSync as
|
|
29339
|
+
import { readFileSync as readFileSync16 } from "fs";
|
|
28926
29340
|
async function exportDocAsArtifact(channelId, docPath) {
|
|
28927
29341
|
const owningProfile = findOwningProfile(channelId);
|
|
28928
29342
|
const channelConfig = await runWithProfile(
|
|
@@ -28931,7 +29345,7 @@ async function exportDocAsArtifact(channelId, docPath) {
|
|
|
28931
29345
|
);
|
|
28932
29346
|
const abs = resolveDocPath(channelConfig.cwd, docPath);
|
|
28933
29347
|
if (!abs) throw new Error(`doc not found: ${docPath}`);
|
|
28934
|
-
const content =
|
|
29348
|
+
const content = readFileSync16(abs, "utf8");
|
|
28935
29349
|
const title = extractTitle(abs, "md");
|
|
28936
29350
|
const today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
28937
29351
|
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).
|
|
@@ -29092,7 +29506,7 @@ function entryKind(entry, abs) {
|
|
|
29092
29506
|
if (entry.isFile()) return "file";
|
|
29093
29507
|
if (!entry.isSymbolicLink()) return null;
|
|
29094
29508
|
try {
|
|
29095
|
-
const target =
|
|
29509
|
+
const target = statSync8(abs);
|
|
29096
29510
|
return target.isDirectory() ? "dir" : target.isFile() ? "file" : null;
|
|
29097
29511
|
} catch {
|
|
29098
29512
|
return null;
|
|
@@ -29105,11 +29519,11 @@ function fileNode(root, abs, name) {
|
|
|
29105
29519
|
const lang = CODE_EXTENSIONS[ext];
|
|
29106
29520
|
let stat;
|
|
29107
29521
|
try {
|
|
29108
|
-
stat =
|
|
29522
|
+
stat = statSync8(abs);
|
|
29109
29523
|
} catch {
|
|
29110
29524
|
return null;
|
|
29111
29525
|
}
|
|
29112
|
-
const path = relative2(root, abs).split(
|
|
29526
|
+
const path = relative2(root, abs).split(sep4).join("/");
|
|
29113
29527
|
const mtime = stat.mtime.toISOString();
|
|
29114
29528
|
if (kind) {
|
|
29115
29529
|
return {
|
|
@@ -29148,9 +29562,9 @@ function readHead(absPath) {
|
|
|
29148
29562
|
}
|
|
29149
29563
|
}
|
|
29150
29564
|
function extractTitle(absPath, kind) {
|
|
29151
|
-
if (kind === "url" || kind === "excalidraw") return
|
|
29565
|
+
if (kind === "url" || kind === "excalidraw") return basename5(absPath);
|
|
29152
29566
|
const head = readHead(absPath);
|
|
29153
|
-
if (!head) return
|
|
29567
|
+
if (!head) return basename5(absPath);
|
|
29154
29568
|
if (kind === "md") {
|
|
29155
29569
|
const m = head.match(/^#{1,3}\s+(.+?)\s*$/m);
|
|
29156
29570
|
if (m) return m[1].replace(/[*_`]/g, "").trim();
|
|
@@ -29158,12 +29572,12 @@ function extractTitle(absPath, kind) {
|
|
|
29158
29572
|
const t = head.match(/<title[^>]*>([^<]+)<\/title>/i) ?? head.match(/<h1[^>]*>([^<]+)<\/h1>/i);
|
|
29159
29573
|
if (t) return t[1].trim();
|
|
29160
29574
|
}
|
|
29161
|
-
return
|
|
29575
|
+
return basename5(absPath);
|
|
29162
29576
|
}
|
|
29163
29577
|
function resolveDirPath(root, rel) {
|
|
29164
29578
|
if (rel.includes("\0")) return null;
|
|
29165
|
-
const abs =
|
|
29166
|
-
if (abs !== root && !abs.startsWith(root +
|
|
29579
|
+
const abs = resolve8(root, rel);
|
|
29580
|
+
if (abs !== root && !abs.startsWith(root + sep4)) return null;
|
|
29167
29581
|
return abs;
|
|
29168
29582
|
}
|
|
29169
29583
|
function isListableFile(name) {
|
|
@@ -29179,7 +29593,7 @@ function probeDir(absDir, showHidden) {
|
|
|
29179
29593
|
if (depth > MAX_SEARCH_DEPTH) return false;
|
|
29180
29594
|
let entries2;
|
|
29181
29595
|
try {
|
|
29182
|
-
entries2 =
|
|
29596
|
+
entries2 = readdirSync5(dir, { withFileTypes: true });
|
|
29183
29597
|
} catch {
|
|
29184
29598
|
return false;
|
|
29185
29599
|
}
|
|
@@ -29190,7 +29604,7 @@ function probeDir(absDir, showHidden) {
|
|
|
29190
29604
|
return false;
|
|
29191
29605
|
}
|
|
29192
29606
|
if (!showHidden && entry.name.startsWith(".")) continue;
|
|
29193
|
-
const abs =
|
|
29607
|
+
const abs = join20(dir, entry.name);
|
|
29194
29608
|
const kind = entryKind(entry, abs);
|
|
29195
29609
|
if (kind === "dir") {
|
|
29196
29610
|
if (SKIP_DIRS.has(entry.name)) hasOther = true;
|
|
@@ -29210,14 +29624,14 @@ function probeDir(absDir, showHidden) {
|
|
|
29210
29624
|
}
|
|
29211
29625
|
function readGitBranch(dir) {
|
|
29212
29626
|
try {
|
|
29213
|
-
let gitDir =
|
|
29214
|
-
if (
|
|
29215
|
-
const pointer =
|
|
29627
|
+
let gitDir = join20(dir, ".git");
|
|
29628
|
+
if (statSync8(gitDir).isFile()) {
|
|
29629
|
+
const pointer = readFileSync17(gitDir, "utf8").trim();
|
|
29216
29630
|
const match = pointer.match(/^gitdir:\s*(.+)$/);
|
|
29217
29631
|
if (!match) return void 0;
|
|
29218
|
-
gitDir =
|
|
29632
|
+
gitDir = resolve8(dir, match[1]);
|
|
29219
29633
|
}
|
|
29220
|
-
const head =
|
|
29634
|
+
const head = readFileSync17(join20(gitDir, "HEAD"), "utf8").trim();
|
|
29221
29635
|
const branchMatch = head.match(/^ref:\s*refs\/heads\/(.+)$/);
|
|
29222
29636
|
if (branchMatch) return branchMatch[1];
|
|
29223
29637
|
return /^[0-9a-f]{7,40}$/i.test(head) ? head.slice(0, 7) : void 0;
|
|
@@ -29230,7 +29644,7 @@ function listDocLevel(root, relDir = "", sort = "newest", showHidden = false) {
|
|
|
29230
29644
|
if (absDir === null) return [];
|
|
29231
29645
|
let entries2;
|
|
29232
29646
|
try {
|
|
29233
|
-
entries2 =
|
|
29647
|
+
entries2 = readdirSync5(absDir, { withFileTypes: true });
|
|
29234
29648
|
} catch {
|
|
29235
29649
|
return [];
|
|
29236
29650
|
}
|
|
@@ -29239,14 +29653,14 @@ function listDocLevel(root, relDir = "", sort = "newest", showHidden = false) {
|
|
|
29239
29653
|
for (const entry of entries2) {
|
|
29240
29654
|
if (dirs.length + docs.length >= MAX_ENTRIES) break;
|
|
29241
29655
|
if (!showHidden && entry.name.startsWith(".")) continue;
|
|
29242
|
-
const abs =
|
|
29243
|
-
const path = relative2(root, abs).split(
|
|
29656
|
+
const abs = join20(absDir, entry.name);
|
|
29657
|
+
const path = relative2(root, abs).split(sep4).join("/");
|
|
29244
29658
|
const kind = entryKind(entry, abs);
|
|
29245
29659
|
if (kind === "dir") {
|
|
29246
29660
|
if (SKIP_DIRS.has(entry.name)) continue;
|
|
29247
29661
|
const probe = probeDir(abs, showHidden);
|
|
29248
29662
|
if (!probe.hasDocs && probe.hasOther) continue;
|
|
29249
|
-
const isRepo =
|
|
29663
|
+
const isRepo = existsSync20(join20(abs, ".git"));
|
|
29250
29664
|
dirs.push({
|
|
29251
29665
|
path,
|
|
29252
29666
|
name: entry.name,
|
|
@@ -29275,14 +29689,14 @@ function flatDocs(root, {
|
|
|
29275
29689
|
if (depth > MAX_SEARCH_DEPTH || hits.length >= MAX_FLAT_DOCS) return;
|
|
29276
29690
|
let entries2;
|
|
29277
29691
|
try {
|
|
29278
|
-
entries2 =
|
|
29692
|
+
entries2 = readdirSync5(dir, { withFileTypes: true });
|
|
29279
29693
|
} catch {
|
|
29280
29694
|
return;
|
|
29281
29695
|
}
|
|
29282
29696
|
for (const entry of entries2) {
|
|
29283
29697
|
if (hits.length >= MAX_FLAT_DOCS) return;
|
|
29284
29698
|
if (!showHidden && entry.name.startsWith(".")) continue;
|
|
29285
|
-
const abs =
|
|
29699
|
+
const abs = join20(dir, entry.name);
|
|
29286
29700
|
const kind = entryKind(entry, abs);
|
|
29287
29701
|
if (kind === "dir") {
|
|
29288
29702
|
if (!SKIP_DIRS.has(entry.name)) walk(abs, depth + 1);
|
|
@@ -29302,8 +29716,8 @@ function flatDocs(root, {
|
|
|
29302
29716
|
}
|
|
29303
29717
|
function resolveDocPath(root, rel) {
|
|
29304
29718
|
if (!rel || rel.includes("\0")) return null;
|
|
29305
|
-
const abs =
|
|
29306
|
-
if (abs !== root && !abs.startsWith(root +
|
|
29719
|
+
const abs = resolve8(root, rel);
|
|
29720
|
+
if (abs !== root && !abs.startsWith(root + sep4)) return null;
|
|
29307
29721
|
const ext = extname2(abs).toLowerCase();
|
|
29308
29722
|
if (!(ext in DOC_EXTENSIONS) && !(ext in CODE_EXTENSIONS)) return null;
|
|
29309
29723
|
return abs;
|
|
@@ -29313,7 +29727,7 @@ function writeDocContent(root, rel, content, baseMtime) {
|
|
|
29313
29727
|
if (!abs) return { status: "not-found" };
|
|
29314
29728
|
let stat;
|
|
29315
29729
|
try {
|
|
29316
|
-
stat =
|
|
29730
|
+
stat = statSync8(abs);
|
|
29317
29731
|
} catch {
|
|
29318
29732
|
return { status: "not-found" };
|
|
29319
29733
|
}
|
|
@@ -29324,29 +29738,29 @@ function writeDocContent(root, rel, content, baseMtime) {
|
|
|
29324
29738
|
if (Buffer.byteLength(content, "utf8") > MAX_CONTENT_BYTES) {
|
|
29325
29739
|
return { status: "too-large" };
|
|
29326
29740
|
}
|
|
29327
|
-
|
|
29328
|
-
return { status: "ok", mtime:
|
|
29741
|
+
writeFileSync7(abs, content, "utf8");
|
|
29742
|
+
return { status: "ok", mtime: statSync8(abs).mtime.toISOString() };
|
|
29329
29743
|
}
|
|
29330
29744
|
function resolveRawPath(root, rel) {
|
|
29331
29745
|
if (!rel || rel.includes("\0")) return null;
|
|
29332
|
-
const abs =
|
|
29333
|
-
if (abs !== root && !abs.startsWith(root +
|
|
29746
|
+
const abs = resolve8(root, rel);
|
|
29747
|
+
if (abs !== root && !abs.startsWith(root + sep4)) return null;
|
|
29334
29748
|
const contentType = MEDIA_EXTENSIONS[extname2(abs).toLowerCase()];
|
|
29335
29749
|
if (!contentType) return null;
|
|
29336
29750
|
return { abs, contentType };
|
|
29337
29751
|
}
|
|
29338
29752
|
function resolveHtmlPath(root, rel) {
|
|
29339
29753
|
if (!rel || rel.includes("\0")) return null;
|
|
29340
|
-
const abs =
|
|
29341
|
-
if (abs !== root && !abs.startsWith(root +
|
|
29754
|
+
const abs = resolve8(root, rel);
|
|
29755
|
+
if (abs !== root && !abs.startsWith(root + sep4)) return null;
|
|
29342
29756
|
if (DOC_EXTENSIONS[extname2(abs).toLowerCase()] !== "html") return null;
|
|
29343
29757
|
return abs;
|
|
29344
29758
|
}
|
|
29345
29759
|
function resolveDownloadPath(root, rel) {
|
|
29346
29760
|
if (!rel || rel.includes("\0")) return null;
|
|
29347
|
-
const abs =
|
|
29348
|
-
if (abs !== root && !abs.startsWith(root +
|
|
29349
|
-
if (!isListableFile(
|
|
29761
|
+
const abs = resolve8(root, rel);
|
|
29762
|
+
if (abs !== root && !abs.startsWith(root + sep4)) return null;
|
|
29763
|
+
if (!isListableFile(basename5(abs))) return null;
|
|
29350
29764
|
const contentType = MEDIA_EXTENSIONS[extname2(abs).toLowerCase()] ?? "application/octet-stream";
|
|
29351
29765
|
return { abs, contentType };
|
|
29352
29766
|
}
|
|
@@ -29362,7 +29776,7 @@ function uniqueName(absDir, name) {
|
|
|
29362
29776
|
let candidate = name;
|
|
29363
29777
|
for (let n = 1; n < 1e3; n++) {
|
|
29364
29778
|
try {
|
|
29365
|
-
|
|
29779
|
+
statSync8(join20(absDir, candidate));
|
|
29366
29780
|
} catch {
|
|
29367
29781
|
return candidate;
|
|
29368
29782
|
}
|
|
@@ -29374,7 +29788,7 @@ function saveUploadedFile(root, relDir, name, data) {
|
|
|
29374
29788
|
const absDir = resolveDirPath(root, relDir);
|
|
29375
29789
|
if (absDir === null) return { status: "no-dir" };
|
|
29376
29790
|
try {
|
|
29377
|
-
if (!
|
|
29791
|
+
if (!statSync8(absDir).isDirectory()) return { status: "no-dir" };
|
|
29378
29792
|
} catch {
|
|
29379
29793
|
return { status: "no-dir" };
|
|
29380
29794
|
}
|
|
@@ -29384,34 +29798,34 @@ function saveUploadedFile(root, relDir, name, data) {
|
|
|
29384
29798
|
if (!(ext in DOC_EXTENSIONS) && !ASSET_LIST_EXTENSIONS.has(ext)) return { status: "bad-type" };
|
|
29385
29799
|
if (data.byteLength > MAX_UPLOAD_BYTES) return { status: "too-large" };
|
|
29386
29800
|
const final = uniqueName(absDir, safe);
|
|
29387
|
-
const abs =
|
|
29388
|
-
|
|
29389
|
-
return { status: "ok", path: relative2(root, abs).split(
|
|
29801
|
+
const abs = join20(absDir, final);
|
|
29802
|
+
writeFileSync7(abs, data);
|
|
29803
|
+
return { status: "ok", path: relative2(root, abs).split(sep4).join("/"), name: final };
|
|
29390
29804
|
}
|
|
29391
29805
|
function createDocFolder(root, relDir, name) {
|
|
29392
29806
|
const absDir = resolveDirPath(root, relDir);
|
|
29393
29807
|
if (absDir === null) return { status: "no-dir" };
|
|
29394
29808
|
try {
|
|
29395
|
-
if (!
|
|
29809
|
+
if (!statSync8(absDir).isDirectory()) return { status: "no-dir" };
|
|
29396
29810
|
} catch {
|
|
29397
29811
|
return { status: "no-dir" };
|
|
29398
29812
|
}
|
|
29399
29813
|
const safe = sanitizeUploadName(name);
|
|
29400
29814
|
if (!safe) return { status: "bad-name" };
|
|
29401
|
-
const abs =
|
|
29815
|
+
const abs = join20(absDir, safe);
|
|
29402
29816
|
try {
|
|
29403
|
-
|
|
29817
|
+
statSync8(abs);
|
|
29404
29818
|
return { status: "exists" };
|
|
29405
29819
|
} catch {
|
|
29406
29820
|
}
|
|
29407
|
-
|
|
29408
|
-
return { status: "ok", path: relative2(root, abs).split(
|
|
29821
|
+
mkdirSync10(abs);
|
|
29822
|
+
return { status: "ok", path: relative2(root, abs).split(sep4).join("/"), name: safe };
|
|
29409
29823
|
}
|
|
29410
29824
|
function createDocFile(root, relDir, name, content) {
|
|
29411
29825
|
const absDir = resolveDirPath(root, relDir);
|
|
29412
29826
|
if (absDir === null) return { status: "no-dir" };
|
|
29413
29827
|
try {
|
|
29414
|
-
if (!
|
|
29828
|
+
if (!statSync8(absDir).isDirectory()) return { status: "no-dir" };
|
|
29415
29829
|
} catch {
|
|
29416
29830
|
return { status: "no-dir" };
|
|
29417
29831
|
}
|
|
@@ -29421,30 +29835,30 @@ function createDocFile(root, relDir, name, content) {
|
|
|
29421
29835
|
if (!(ext in DOC_EXTENSIONS) && !(ext in CODE_EXTENSIONS)) return { status: "bad-name" };
|
|
29422
29836
|
if (SKIP_FILES.has(safe)) return { status: "bad-name" };
|
|
29423
29837
|
if (Buffer.byteLength(content, "utf8") > MAX_CONTENT_BYTES) return { status: "too-large" };
|
|
29424
|
-
const abs =
|
|
29838
|
+
const abs = join20(absDir, safe);
|
|
29425
29839
|
try {
|
|
29426
|
-
|
|
29840
|
+
writeFileSync7(abs, content, { encoding: "utf8", flag: "wx" });
|
|
29427
29841
|
} catch (err) {
|
|
29428
29842
|
if (err.code === "EEXIST") return { status: "exists" };
|
|
29429
29843
|
throw err;
|
|
29430
29844
|
}
|
|
29431
|
-
return { status: "ok", path: relative2(root, abs).split(
|
|
29845
|
+
return { status: "ok", path: relative2(root, abs).split(sep4).join("/"), name: safe };
|
|
29432
29846
|
}
|
|
29433
29847
|
function moveDocEntry(root, from, to) {
|
|
29434
29848
|
if (!from || !to || from.includes("\0") || to.includes("\0")) return { status: "not-found" };
|
|
29435
|
-
const absFrom =
|
|
29436
|
-
if (!absFrom.startsWith(root +
|
|
29849
|
+
const absFrom = resolve8(root, from);
|
|
29850
|
+
if (!absFrom.startsWith(root + sep4)) return { status: "not-found" };
|
|
29437
29851
|
let stat;
|
|
29438
29852
|
try {
|
|
29439
|
-
stat =
|
|
29853
|
+
stat = statSync8(absFrom);
|
|
29440
29854
|
} catch {
|
|
29441
29855
|
return { status: "not-found" };
|
|
29442
29856
|
}
|
|
29443
29857
|
const isDir = stat.isDirectory();
|
|
29444
29858
|
if (!isDir && !stat.isFile()) return { status: "not-found" };
|
|
29445
|
-
const absTo =
|
|
29446
|
-
if (!absTo.startsWith(root +
|
|
29447
|
-
const name = sanitizeUploadName(
|
|
29859
|
+
const absTo = resolve8(root, to);
|
|
29860
|
+
if (!absTo.startsWith(root + sep4)) return { status: "bad-target" };
|
|
29861
|
+
const name = sanitizeUploadName(basename5(absTo));
|
|
29448
29862
|
if (!name) return { status: "bad-target" };
|
|
29449
29863
|
if (!isDir) {
|
|
29450
29864
|
const ext = extname2(name).toLowerCase();
|
|
@@ -29452,15 +29866,15 @@ function moveDocEntry(root, from, to) {
|
|
|
29452
29866
|
return { status: "bad-target" };
|
|
29453
29867
|
}
|
|
29454
29868
|
}
|
|
29455
|
-
const absToDir =
|
|
29869
|
+
const absToDir = dirname3(absTo);
|
|
29456
29870
|
if (resolveDirPath(root, relative2(root, absToDir)) === null) return { status: "bad-target" };
|
|
29457
29871
|
try {
|
|
29458
|
-
if (!
|
|
29872
|
+
if (!statSync8(absToDir).isDirectory()) return { status: "bad-target" };
|
|
29459
29873
|
} catch {
|
|
29460
29874
|
return { status: "bad-target" };
|
|
29461
29875
|
}
|
|
29462
|
-
const finalAbs =
|
|
29463
|
-
if (isDir && (finalAbs === absFrom || finalAbs.startsWith(absFrom +
|
|
29876
|
+
const finalAbs = join20(absToDir, name);
|
|
29877
|
+
if (isDir && (finalAbs === absFrom || finalAbs.startsWith(absFrom + sep4))) {
|
|
29464
29878
|
return { status: "into-self" };
|
|
29465
29879
|
}
|
|
29466
29880
|
try {
|
|
@@ -29468,12 +29882,12 @@ function moveDocEntry(root, from, to) {
|
|
|
29468
29882
|
} catch {
|
|
29469
29883
|
}
|
|
29470
29884
|
renameSync2(absFrom, finalAbs);
|
|
29471
|
-
return { status: "ok", path: relative2(root, finalAbs).split(
|
|
29885
|
+
return { status: "ok", path: relative2(root, finalAbs).split(sep4).join("/"), name };
|
|
29472
29886
|
}
|
|
29473
29887
|
function deleteDocEntry(root, path) {
|
|
29474
29888
|
if (!path || path.includes("\0")) return { status: "not-found" };
|
|
29475
|
-
const abs =
|
|
29476
|
-
if (!abs.startsWith(root +
|
|
29889
|
+
const abs = resolve8(root, path);
|
|
29890
|
+
if (!abs.startsWith(root + sep4)) return { status: "not-found" };
|
|
29477
29891
|
let stat;
|
|
29478
29892
|
try {
|
|
29479
29893
|
stat = lstatSync2(abs);
|
|
@@ -29482,10 +29896,10 @@ function deleteDocEntry(root, path) {
|
|
|
29482
29896
|
}
|
|
29483
29897
|
const isDir = stat.isDirectory();
|
|
29484
29898
|
if (!isDir && !stat.isFile() && !stat.isSymbolicLink()) return { status: "not-found" };
|
|
29485
|
-
|
|
29899
|
+
rmSync9(abs, { recursive: isDir });
|
|
29486
29900
|
return {
|
|
29487
29901
|
status: "ok",
|
|
29488
|
-
path: relative2(root, abs).split(
|
|
29902
|
+
path: relative2(root, abs).split(sep4).join("/"),
|
|
29489
29903
|
type: isDir ? "dir" : "file"
|
|
29490
29904
|
};
|
|
29491
29905
|
}
|
|
@@ -29515,13 +29929,13 @@ function createDocsRouter({ gate = requireDocsAccess } = {}) {
|
|
|
29515
29929
|
if (!resolved) return c.json({ error: "not found" }, 404);
|
|
29516
29930
|
let stat;
|
|
29517
29931
|
try {
|
|
29518
|
-
stat =
|
|
29932
|
+
stat = statSync8(resolved.abs);
|
|
29519
29933
|
} catch {
|
|
29520
29934
|
return c.json({ error: "not found" }, 404);
|
|
29521
29935
|
}
|
|
29522
29936
|
if (!stat.isFile()) return c.json({ error: "not found" }, 404);
|
|
29523
29937
|
if (stat.size > MAX_RAW_BYTES) return c.json({ error: "file too large" }, 413);
|
|
29524
|
-
const name =
|
|
29938
|
+
const name = basename5(resolved.abs);
|
|
29525
29939
|
const asciiName = name.replace(/[^\x20-\x7e]/g, "_").replace(/["\\]/g, "_");
|
|
29526
29940
|
const disposition = download ? "attachment" : "inline";
|
|
29527
29941
|
const stream = Readable.toWeb(createReadStream(resolved.abs));
|
|
@@ -29537,13 +29951,13 @@ function createDocsRouter({ gate = requireDocsAccess } = {}) {
|
|
|
29537
29951
|
if (!abs) return c.json({ error: "not found" }, 404);
|
|
29538
29952
|
let stat;
|
|
29539
29953
|
try {
|
|
29540
|
-
stat =
|
|
29954
|
+
stat = statSync8(abs);
|
|
29541
29955
|
} catch {
|
|
29542
29956
|
return c.json({ error: "not found" }, 404);
|
|
29543
29957
|
}
|
|
29544
29958
|
if (!stat.isFile()) return c.json({ error: "not found" }, 404);
|
|
29545
29959
|
if (stat.size > MAX_RAW_BYTES) return c.json({ error: "file too large" }, 413);
|
|
29546
|
-
return c.body(withDocLinkBridge(
|
|
29960
|
+
return c.body(withDocLinkBridge(readFileSync17(abs, "utf8")), 200, {
|
|
29547
29961
|
"Content-Type": "text/html; charset=utf-8",
|
|
29548
29962
|
"Content-Security-Policy": HTML_SHARE_CSP,
|
|
29549
29963
|
"X-Content-Type-Options": "nosniff",
|
|
@@ -29661,7 +30075,7 @@ function createDocsRouter({ gate = requireDocsAccess } = {}) {
|
|
|
29661
30075
|
if (!abs) return c.json({ error: "not found" }, 404);
|
|
29662
30076
|
let stat;
|
|
29663
30077
|
try {
|
|
29664
|
-
stat =
|
|
30078
|
+
stat = statSync8(abs);
|
|
29665
30079
|
} catch {
|
|
29666
30080
|
return c.json({ error: "not found" }, 404);
|
|
29667
30081
|
}
|
|
@@ -29710,7 +30124,7 @@ function createDocsRouter({ gate = requireDocsAccess } = {}) {
|
|
|
29710
30124
|
if (!abs) return c.json({ error: "not found" }, 404);
|
|
29711
30125
|
let stat;
|
|
29712
30126
|
try {
|
|
29713
|
-
stat =
|
|
30127
|
+
stat = statSync8(abs);
|
|
29714
30128
|
} catch {
|
|
29715
30129
|
return c.json({ error: "not found" }, 404);
|
|
29716
30130
|
}
|
|
@@ -29725,10 +30139,10 @@ function createDocsRouter({ gate = requireDocsAccess } = {}) {
|
|
|
29725
30139
|
// by; only docs get a parsed title.
|
|
29726
30140
|
kind: kind ?? "code",
|
|
29727
30141
|
lang: kind ? void 0 : CODE_EXTENSIONS[ext],
|
|
29728
|
-
title: kind ? extractTitle(abs, kind) :
|
|
30142
|
+
title: kind ? extractTitle(abs, kind) : basename5(abs),
|
|
29729
30143
|
mtime: stat.mtime.toISOString(),
|
|
29730
30144
|
tooLarge: tooLarge || void 0,
|
|
29731
|
-
content: tooLarge ? "" :
|
|
30145
|
+
content: tooLarge ? "" : readFileSync17(abs, "utf8")
|
|
29732
30146
|
});
|
|
29733
30147
|
});
|
|
29734
30148
|
app.put("/:id/docs/content", async (c) => {
|
|
@@ -29761,7 +30175,7 @@ function createDocsRouter({ gate = requireDocsAccess } = {}) {
|
|
|
29761
30175
|
}
|
|
29762
30176
|
let stat;
|
|
29763
30177
|
try {
|
|
29764
|
-
stat =
|
|
30178
|
+
stat = statSync8(abs);
|
|
29765
30179
|
} catch {
|
|
29766
30180
|
return { error: c.json({ error: "not found" }, 404) };
|
|
29767
30181
|
}
|
|
@@ -29771,7 +30185,7 @@ function createDocsRouter({ gate = requireDocsAccess } = {}) {
|
|
|
29771
30185
|
channel,
|
|
29772
30186
|
rel,
|
|
29773
30187
|
title: extractTitle(abs, "md"),
|
|
29774
|
-
content:
|
|
30188
|
+
content: readFileSync17(abs, "utf8")
|
|
29775
30189
|
};
|
|
29776
30190
|
};
|
|
29777
30191
|
app.get("/:id/docs/translation/:lang", async (c) => {
|
|
@@ -29829,9 +30243,9 @@ function withDocLinkBridge(html) {
|
|
|
29829
30243
|
var DOC_MENTION_RE = /(?<![\w@/`])@((?:[\w.-]+\/)+[\w.-]+\.[A-Za-z0-9]{1,6})(?::(\d+))?(?![\w-])/g;
|
|
29830
30244
|
function isRealDoc(root, rel) {
|
|
29831
30245
|
const abs = resolveDocPath(root, rel);
|
|
29832
|
-
if (!abs || !
|
|
30246
|
+
if (!abs || !existsSync21(abs)) return false;
|
|
29833
30247
|
try {
|
|
29834
|
-
return
|
|
30248
|
+
return statSync9(abs).isFile();
|
|
29835
30249
|
} catch {
|
|
29836
30250
|
return false;
|
|
29837
30251
|
}
|
|
@@ -30250,7 +30664,7 @@ function loadChatAgentConfig() {
|
|
|
30250
30664
|
maxBudgetUsd = Number.isFinite(n) && n > 0 ? n : void 0;
|
|
30251
30665
|
}
|
|
30252
30666
|
return {
|
|
30253
|
-
botName: process.env["BOT_NAME"] ?? "
|
|
30667
|
+
botName: process.env["BOT_NAME"] ?? "Bot",
|
|
30254
30668
|
maxBudgetUsd,
|
|
30255
30669
|
sessionCompactThresholdTokens: parseTokenCount(
|
|
30256
30670
|
process.env["SESSION_COMPACT_THRESHOLD_TOKENS"],
|
|
@@ -30265,10 +30679,11 @@ function loadChatAgentConfig() {
|
|
|
30265
30679
|
var RETRY_DELAY_MS = 3e3;
|
|
30266
30680
|
var MAX_CONSECUTIVE_WAKES = 5;
|
|
30267
30681
|
var BACKGROUND_SWEEP_MS = 6e4;
|
|
30682
|
+
var BACKGROUND_CHECK_IN_MS = 30 * 6e4;
|
|
30268
30683
|
var MISSED_MESSAGE_WINDOW_MS = 24 * 60 * 60 * 1e3;
|
|
30269
30684
|
var MISSED_MESSAGE_THREAD_LIMIT = 100;
|
|
30270
30685
|
var delay = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
30271
|
-
function stripPathPrefixes(label, roots, home =
|
|
30686
|
+
function stripPathPrefixes(label, roots, home = homedir8()) {
|
|
30272
30687
|
let out = label;
|
|
30273
30688
|
for (const root of roots) {
|
|
30274
30689
|
if (root) out = out.replaceAll(`${root.replace(/\/+$/, "")}/`, "");
|
|
@@ -30506,6 +30921,16 @@ var ChatAgent = class {
|
|
|
30506
30921
|
if (tasks?.length) {
|
|
30507
30922
|
watched.tasks = tasks;
|
|
30508
30923
|
this.channelActivityNotifier()("background", { channelId: watched.channelId, threadId, on: true });
|
|
30924
|
+
const oldest = Math.min(...tasks.map((t) => t.startedAt));
|
|
30925
|
+
if (!watched.checkedIn && Date.now() - oldest >= BACKGROUND_CHECK_IN_MS) {
|
|
30926
|
+
watched.checkedIn = true;
|
|
30927
|
+
const pids = tasks.map((t) => t.about ? `${t.pid}: ${t.about}` : t.pid).join(", ");
|
|
30928
|
+
const text2 = `Background task (PID ${pids}) is still running after ${Math.round((Date.now() - oldest) / 6e4)} min. Check its log: if it is stuck, kill it and retry or report; if it is genuinely progressing, say how long is left.`;
|
|
30929
|
+
await runWithProfile(watched.profile, async () => {
|
|
30930
|
+
const { replyId } = await postToDashboardChannel({ threadId, text: text2 });
|
|
30931
|
+
await this.wake(threadId, replyId, text2);
|
|
30932
|
+
}).catch((err) => console.error("[chat-agent] background check-in failed:", err.message));
|
|
30933
|
+
}
|
|
30509
30934
|
continue;
|
|
30510
30935
|
}
|
|
30511
30936
|
this.watchedTasks.delete(threadId);
|
|
@@ -30829,6 +31254,10 @@ var ChatAgent = class {
|
|
|
30829
31254
|
const { data: thread, error } = await this.supabase().from("threads").select("id, channel_id, title").eq("id", msg.threadId).single();
|
|
30830
31255
|
if (error || !thread) {
|
|
30831
31256
|
console.error(`[chat-agent] thread ${msg.threadId} not found:`, error?.message);
|
|
31257
|
+
await this.postReply(
|
|
31258
|
+
msg.threadId,
|
|
31259
|
+
`\u26A0\uFE0F I couldn't start this run: failed to load the thread (${error?.message ?? "not found"}).`
|
|
31260
|
+
);
|
|
30832
31261
|
return;
|
|
30833
31262
|
}
|
|
30834
31263
|
const notify = this.openThinkingNotifier(msg.threadId);
|
|
@@ -30904,9 +31333,11 @@ var ChatAgent = class {
|
|
|
30904
31333
|
...isHumanAuthor(msg.author) ? { senderHandle: msg.author } : {}
|
|
30905
31334
|
});
|
|
30906
31335
|
if (memory.enabled) channelConfig = { ...channelConfig, disableAutoMemory: true };
|
|
31336
|
+
const { data: channelRow } = await this.supabase().from("channels").select("external_channel_id").eq("id", thread.channel_id).maybeSingle();
|
|
30907
31337
|
channelConfig = {
|
|
30908
31338
|
...channelConfig,
|
|
30909
|
-
permissionThread: { threadId: msg.threadId, channelId: thread.channel_id }
|
|
31339
|
+
permissionThread: { threadId: msg.threadId, channelId: thread.channel_id },
|
|
31340
|
+
slackBound: !!channelRow?.external_channel_id
|
|
30910
31341
|
};
|
|
30911
31342
|
if (memory.memoryPrompt) channelConfig = { ...channelConfig, memoryPrompt: memory.memoryPrompt };
|
|
30912
31343
|
const store = this.openSessionStore();
|
|
@@ -30932,7 +31363,7 @@ var ChatAgent = class {
|
|
|
30932
31363
|
${msg.body}` : msg.woken ? `[background task finished]
|
|
30933
31364
|
[note: nobody sent a new message. A background task you launched earlier in this thread has finished and reported the result below (it is already posted in the thread, so do not repeat it). Carry on with whatever was meant to happen next, then report. If nothing is left to do, say so in one line.]
|
|
30934
31365
|
|
|
30935
|
-
${msg.body}` : msg.body;
|
|
31366
|
+
${msg.body}` : expandSkillCommand(channelConfig.claudeConfigDir, channelConfig.cwd, msg.body) ?? msg.body;
|
|
30936
31367
|
const barePrompt = header + interruptionNote + recoveryNote + body + buildFilesPromptSection(attachments);
|
|
30937
31368
|
let resumableSessionId = session?.runner === activeRunner ? session.sessionId : void 0;
|
|
30938
31369
|
let prompt = barePrompt;
|
|
@@ -31214,22 +31645,22 @@ ${msg.body}` : msg.body;
|
|
|
31214
31645
|
let ready;
|
|
31215
31646
|
try {
|
|
31216
31647
|
channel = this.supabase().channel(`agent-thinking:${threadId}`);
|
|
31217
|
-
ready = new Promise((
|
|
31648
|
+
ready = new Promise((resolve9) => {
|
|
31218
31649
|
const timeout = setTimeout(() => {
|
|
31219
31650
|
console.error(`[chat-agent] thinking-channel ${threadId}: subscribe timed out after 10s`);
|
|
31220
|
-
|
|
31651
|
+
resolve9(false);
|
|
31221
31652
|
}, 1e4);
|
|
31222
31653
|
channel.subscribe((status, err) => {
|
|
31223
31654
|
if (status === "SUBSCRIBED") {
|
|
31224
31655
|
clearTimeout(timeout);
|
|
31225
|
-
|
|
31656
|
+
resolve9(true);
|
|
31226
31657
|
} else if (status === "CHANNEL_ERROR" || status === "TIMED_OUT" || status === "CLOSED") {
|
|
31227
31658
|
console.error(
|
|
31228
31659
|
`[chat-agent] thinking-channel ${threadId}: ${status}`,
|
|
31229
31660
|
err?.message ?? ""
|
|
31230
31661
|
);
|
|
31231
31662
|
clearTimeout(timeout);
|
|
31232
|
-
|
|
31663
|
+
resolve9(false);
|
|
31233
31664
|
}
|
|
31234
31665
|
});
|
|
31235
31666
|
});
|
|
@@ -31276,19 +31707,19 @@ ${msg.body}` : msg.body;
|
|
|
31276
31707
|
let ready;
|
|
31277
31708
|
try {
|
|
31278
31709
|
channel = this.supabase().channel("channel-activity");
|
|
31279
|
-
ready = new Promise((
|
|
31710
|
+
ready = new Promise((resolve9) => {
|
|
31280
31711
|
const timeout = setTimeout(() => {
|
|
31281
31712
|
console.error("[chat-agent] channel-activity: subscribe timed out after 10s");
|
|
31282
|
-
|
|
31713
|
+
resolve9(false);
|
|
31283
31714
|
}, 1e4);
|
|
31284
31715
|
channel.subscribe((status, err) => {
|
|
31285
31716
|
if (status === "SUBSCRIBED") {
|
|
31286
31717
|
clearTimeout(timeout);
|
|
31287
|
-
|
|
31718
|
+
resolve9(true);
|
|
31288
31719
|
} else if (status === "CHANNEL_ERROR" || status === "TIMED_OUT" || status === "CLOSED") {
|
|
31289
31720
|
console.error(`[chat-agent] channel-activity: ${status}`, err?.message ?? "");
|
|
31290
31721
|
clearTimeout(timeout);
|
|
31291
|
-
|
|
31722
|
+
resolve9(false);
|
|
31292
31723
|
}
|
|
31293
31724
|
});
|
|
31294
31725
|
});
|
|
@@ -31359,6 +31790,7 @@ ${msg.body}` : msg.body;
|
|
|
31359
31790
|
maxBudgetUsd: this.config.maxBudgetUsd,
|
|
31360
31791
|
agentPersona,
|
|
31361
31792
|
channelPrompt: channelConfig.prompt,
|
|
31793
|
+
slackBound: channelConfig.slackBound,
|
|
31362
31794
|
onActivity,
|
|
31363
31795
|
signal,
|
|
31364
31796
|
mcpConfigPath,
|
|
@@ -31403,7 +31835,8 @@ ${msg.body}` : msg.body;
|
|
|
31403
31835
|
this.config.botName,
|
|
31404
31836
|
agentPersona,
|
|
31405
31837
|
channelConfig.prompt,
|
|
31406
|
-
resolveSelectedOutputStyle(channelConfig.claudeConfigDir)?.body
|
|
31838
|
+
resolveSelectedOutputStyle(channelConfig.claudeConfigDir)?.body,
|
|
31839
|
+
channelConfig.slackBound
|
|
31407
31840
|
),
|
|
31408
31841
|
channelConfig.memoryPrompt,
|
|
31409
31842
|
docsAccessPromptNote(channelConfig.docsAccess, channelConfig.docsAccessUnverified)
|
|
@@ -31577,436 +32010,92 @@ ${msg.body}` : msg.body;
|
|
|
31577
32010
|
await this.postReply(msg.threadId, "\u23F9 Stopped by user.", activities);
|
|
31578
32011
|
}
|
|
31579
32012
|
return true;
|
|
31580
|
-
}
|
|
31581
|
-
if (response.sessionId)
|
|
31582
|
-
store.saveSession(channelKey, msg.threadId, response.sessionId, "claude");
|
|
31583
|
-
await this.postReply(msg.threadId, response.text || "No response", activities);
|
|
31584
|
-
return true;
|
|
31585
|
-
}
|
|
31586
|
-
/**
|
|
31587
|
-
* A thread's messages in order, for anything that needs the raw
|
|
31588
|
-
* author/body pairs rather than `fetchThreadContext`'s formatted block —
|
|
31589
|
-
* currently just the rollover sliding-window seed. Shares the same query
|
|
31590
|
-
* (and the same archived-replies exclusion) so the two callers never drift.
|
|
31591
|
-
*/
|
|
31592
|
-
async fetchThreadMessages(threadId, excludeReplyId) {
|
|
31593
|
-
const { data, error } = await this.supabase().from("thread_replies").select("id, author, body").eq("thread_id", threadId).is("archived_at", null).order("created_at", { ascending: true });
|
|
31594
|
-
if (error || !data) return [];
|
|
31595
|
-
const prior = excludeReplyId ? data.filter((r) => r.id !== excludeReplyId) : data;
|
|
31596
|
-
return prior.map((r) => ({ author: r.author, body: r.body }));
|
|
31597
|
-
}
|
|
31598
|
-
/**
|
|
31599
|
-
* Thread history before the triggering message, formatted like the Slack
|
|
31600
|
-
* listener's thread context block. Empty string when the trigger is the
|
|
31601
|
-
* only message (nothing to seed).
|
|
31602
|
-
*/
|
|
31603
|
-
async fetchThreadContext(threadId, excludeReplyId) {
|
|
31604
|
-
const prior = await this.fetchThreadMessages(threadId, excludeReplyId);
|
|
31605
|
-
if (prior.length === 0) return "";
|
|
31606
|
-
const lines = prior.map((r) => `${r.author}: ${r.body}`).join("\n");
|
|
31607
|
-
return `[thread context: messages before this one]
|
|
31608
|
-
${lines}
|
|
31609
|
-
[end thread context]
|
|
31610
|
-
|
|
31611
|
-
`;
|
|
31612
|
-
}
|
|
31613
|
-
/**
|
|
31614
|
-
* Last recorded run's replayed context for a thread; see `contextTokensOf`.
|
|
31615
|
-
*/
|
|
31616
|
-
lastRunContextTokens(threadTs) {
|
|
31617
|
-
return contextTokensOf(this.openUsageStore().recent(1, { threadTs })[0]);
|
|
31618
|
-
}
|
|
31619
|
-
/**
|
|
31620
|
-
* Builds the rollover handoff seed for a thread past the compact
|
|
31621
|
-
* threshold — see docs/session-auto-compact.md and rollover-summary.ts.
|
|
31622
|
-
* `undefined` on anything that stops rollover from being safe to do
|
|
31623
|
-
* (nothing to summarize, or the Haiku call itself failed); the caller
|
|
31624
|
-
* treats that as "skip rollover, resume the old session as normal".
|
|
31625
|
-
*/
|
|
31626
|
-
async buildRolloverSeed(threadId, excludeReplyId, auth) {
|
|
31627
|
-
const messages = await this.fetchThreadMessages(threadId, excludeReplyId);
|
|
31628
|
-
if (messages.length === 0) return void 0;
|
|
31629
|
-
const recentVerbatimTokens = this.config.recentVerbatimTokens ?? DEFAULT_RECENT_VERBATIM_TOKENS;
|
|
31630
|
-
return this.summarizeForRollover(messages, recentVerbatimTokens, auth);
|
|
31631
|
-
}
|
|
31632
|
-
/** Programmatic check for `@path` doc mentions: the model's paths are
|
|
31633
|
-
* never trusted, only ones that resolve to a real file in the channel
|
|
31634
|
-
* folder stay as mentions. */
|
|
31635
|
-
async guardDocMentionsFor(threadId, body) {
|
|
31636
|
-
if (!body.includes("@")) return body;
|
|
31637
|
-
try {
|
|
31638
|
-
const { data: thread } = await this.supabase().from("threads").select("channel_id").eq("id", threadId).single();
|
|
31639
|
-
if (!thread?.channel_id) return body;
|
|
31640
|
-
const cwd = runWithProfile(
|
|
31641
|
-
findOwningProfile(thread.channel_id),
|
|
31642
|
-
() => resolveChannelConfig(thread.channel_id).cwd
|
|
31643
|
-
);
|
|
31644
|
-
return guardDocMentions(body, cwd);
|
|
31645
|
-
} catch {
|
|
31646
|
-
return body;
|
|
31647
|
-
}
|
|
31648
|
-
}
|
|
31649
|
-
async postReply(threadId, body, activities) {
|
|
31650
|
-
const row = {
|
|
31651
|
-
thread_id: threadId,
|
|
31652
|
-
author: AGENT_AUTHOR,
|
|
31653
|
-
body: await this.guardDocMentionsFor(threadId, await uploadLocalImages(body))
|
|
31654
|
-
};
|
|
31655
|
-
if (activities && activities.length > 0) row["activities"] = activities;
|
|
31656
|
-
let { error } = await this.supabase().from("thread_replies").insert(row);
|
|
31657
|
-
if (error && row["activities"]) {
|
|
31658
|
-
delete row["activities"];
|
|
31659
|
-
({ error } = await this.supabase().from("thread_replies").insert(row));
|
|
31660
|
-
}
|
|
31661
|
-
if (error) {
|
|
31662
|
-
console.error(`[chat-agent] failed to post reply to ${threadId}:`, error.message);
|
|
31663
|
-
}
|
|
31664
|
-
}
|
|
31665
|
-
};
|
|
31666
|
-
|
|
31667
|
-
// ../api/src/claude/skills.ts
|
|
31668
|
-
import { existsSync as existsSync21, readdirSync as readdirSync5, readFileSync as readFileSync17, statSync as statSync9 } from "fs";
|
|
31669
|
-
import { homedir as homedir8 } from "os";
|
|
31670
|
-
import { basename as basename5, dirname as dirname3, join as join20 } from "path";
|
|
31671
|
-
import yaml3 from "js-yaml";
|
|
31672
|
-
|
|
31673
|
-
// ../api/src/claude/skill-files.ts
|
|
31674
|
-
import {
|
|
31675
|
-
existsSync as existsSync20,
|
|
31676
|
-
mkdirSync as mkdirSync10,
|
|
31677
|
-
readFileSync as readFileSync16,
|
|
31678
|
-
readdirSync as readdirSync4,
|
|
31679
|
-
rmSync as rmSync9,
|
|
31680
|
-
statSync as statSync8,
|
|
31681
|
-
writeFileSync as writeFileSync7
|
|
31682
|
-
} from "fs";
|
|
31683
|
-
import { homedir as homedir7 } from "os";
|
|
31684
|
-
import { join as join19, resolve as resolve7, sep as sep4 } from "path";
|
|
31685
|
-
import yaml2 from "js-yaml";
|
|
31686
|
-
var MAX_SKILL_BYTES = 2 * 1024 * 1024;
|
|
31687
|
-
var SKILL_NAME = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
|
|
31688
|
-
function expandHome2(p) {
|
|
31689
|
-
if (p === "~") return homedir7();
|
|
31690
|
-
if (p.startsWith("~/")) return join19(homedir7(), p.slice(2));
|
|
31691
|
-
return p;
|
|
31692
|
-
}
|
|
31693
|
-
function workspaceSkillsDir(configDir) {
|
|
31694
|
-
return join19(configDir ? expandHome2(configDir) : join19(homedir7(), ".claude"), "skills");
|
|
31695
|
-
}
|
|
31696
|
-
function channelSkillsDir(cwd) {
|
|
31697
|
-
return join19(cwd, ".claude", "skills");
|
|
31698
|
-
}
|
|
31699
|
-
function isValidSkillName(name) {
|
|
31700
|
-
return SKILL_NAME.test(name);
|
|
31701
|
-
}
|
|
31702
|
-
function resolveSkillPath(dir, name) {
|
|
31703
|
-
if (!isValidSkillName(name)) return null;
|
|
31704
|
-
const abs = resolve7(dir, name, "SKILL.md");
|
|
31705
|
-
if (!abs.startsWith(resolve7(dir) + sep4)) return null;
|
|
31706
|
-
return abs;
|
|
31707
|
-
}
|
|
31708
|
-
function splitFrontmatter(raw) {
|
|
31709
|
-
const match = raw.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n?/);
|
|
31710
|
-
if (!match) return { fm: {}, body: raw };
|
|
31711
|
-
let fm = {};
|
|
31712
|
-
try {
|
|
31713
|
-
fm = yaml2.load(match[1]) ?? {};
|
|
31714
|
-
} catch {
|
|
31715
|
-
fm = {};
|
|
31716
|
-
}
|
|
31717
|
-
return { fm, body: raw.slice(match[0].length) };
|
|
31718
|
-
}
|
|
31719
|
-
function buildSkillFile(fm, body) {
|
|
31720
|
-
const { name, description, ...rest } = fm;
|
|
31721
|
-
const ordered = { name, description, ...rest };
|
|
31722
|
-
const front = yaml2.dump(ordered, { lineWidth: -1 }).trimEnd();
|
|
31723
|
-
return `---
|
|
31724
|
-
${front}
|
|
31725
|
-
---
|
|
31726
|
-
|
|
31727
|
-
${body.replace(/^\n+/, "").trimEnd()}
|
|
31728
|
-
`;
|
|
31729
|
-
}
|
|
31730
|
-
function readMeta(abs) {
|
|
31731
|
-
try {
|
|
31732
|
-
const { fm } = splitFrontmatter(readFileSync16(abs, "utf-8"));
|
|
31733
|
-
return {
|
|
31734
|
-
name: typeof fm["name"] === "string" ? fm["name"] : void 0,
|
|
31735
|
-
description: typeof fm["description"] === "string" ? fm["description"] : void 0
|
|
31736
|
-
};
|
|
31737
|
-
} catch {
|
|
31738
|
-
return {};
|
|
31739
|
-
}
|
|
31740
|
-
}
|
|
31741
|
-
function listSkillFiles(dir) {
|
|
31742
|
-
if (!existsSync20(dir)) return [];
|
|
31743
|
-
let entries2;
|
|
31744
|
-
try {
|
|
31745
|
-
entries2 = readdirSync4(dir);
|
|
31746
|
-
} catch {
|
|
31747
|
-
return [];
|
|
31748
|
-
}
|
|
31749
|
-
const rows2 = [];
|
|
31750
|
-
for (const entry of entries2) {
|
|
31751
|
-
if (!isValidSkillName(entry)) continue;
|
|
31752
|
-
const abs = join19(dir, entry, "SKILL.md");
|
|
31753
|
-
let stat;
|
|
31754
|
-
try {
|
|
31755
|
-
stat = statSync8(abs);
|
|
31756
|
-
} catch {
|
|
31757
|
-
continue;
|
|
31758
|
-
}
|
|
31759
|
-
if (!stat.isFile()) continue;
|
|
31760
|
-
const meta = readMeta(abs);
|
|
31761
|
-
rows2.push({
|
|
31762
|
-
// The directory name is the identifier the CLI resolves by, so it wins
|
|
31763
|
-
// over a frontmatter `name` that has drifted away from it.
|
|
31764
|
-
name: entry,
|
|
31765
|
-
description: (meta.description ?? "").trim(),
|
|
31766
|
-
mtime: stat.mtime.toISOString()
|
|
31767
|
-
});
|
|
31768
|
-
}
|
|
31769
|
-
return rows2.sort((a, b) => a.name.localeCompare(b.name));
|
|
31770
|
-
}
|
|
31771
|
-
function readSkillFile(dir, name) {
|
|
31772
|
-
const abs = resolveSkillPath(dir, name);
|
|
31773
|
-
if (!abs) return null;
|
|
31774
|
-
let stat;
|
|
31775
|
-
try {
|
|
31776
|
-
stat = statSync8(abs);
|
|
31777
|
-
} catch {
|
|
31778
|
-
return null;
|
|
31779
|
-
}
|
|
31780
|
-
if (!stat.isFile() || stat.size > MAX_SKILL_BYTES) return null;
|
|
31781
|
-
const { fm, body } = splitFrontmatter(readFileSync16(abs, "utf-8"));
|
|
31782
|
-
return {
|
|
31783
|
-
name,
|
|
31784
|
-
description: typeof fm["description"] === "string" ? fm["description"].trim() : "",
|
|
31785
|
-
body,
|
|
31786
|
-
mtime: stat.mtime.toISOString(),
|
|
31787
|
-
path: abs
|
|
31788
|
-
};
|
|
31789
|
-
}
|
|
31790
|
-
function writeSkillFile(dir, name, patch, baseMtime) {
|
|
31791
|
-
const abs = resolveSkillPath(dir, name);
|
|
31792
|
-
if (!abs) return { status: "not-found" };
|
|
31793
|
-
let stat;
|
|
31794
|
-
try {
|
|
31795
|
-
stat = statSync8(abs);
|
|
31796
|
-
} catch {
|
|
31797
|
-
return { status: "not-found" };
|
|
32013
|
+
}
|
|
32014
|
+
if (response.sessionId)
|
|
32015
|
+
store.saveSession(channelKey, msg.threadId, response.sessionId, "claude");
|
|
32016
|
+
await this.postReply(msg.threadId, response.text || "No response", activities);
|
|
32017
|
+
return true;
|
|
31798
32018
|
}
|
|
31799
|
-
|
|
31800
|
-
|
|
31801
|
-
|
|
32019
|
+
/**
|
|
32020
|
+
* A thread's messages in order, for anything that needs the raw
|
|
32021
|
+
* author/body pairs rather than `fetchThreadContext`'s formatted block —
|
|
32022
|
+
* currently just the rollover sliding-window seed. Shares the same query
|
|
32023
|
+
* (and the same archived-replies exclusion) so the two callers never drift.
|
|
32024
|
+
*/
|
|
32025
|
+
async fetchThreadMessages(threadId, excludeReplyId) {
|
|
32026
|
+
const { data, error } = await this.supabase().from("thread_replies").select("id, author, body").eq("thread_id", threadId).is("archived_at", null).order("created_at", { ascending: true });
|
|
32027
|
+
if (error || !data) return [];
|
|
32028
|
+
const prior = excludeReplyId ? data.filter((r) => r.id !== excludeReplyId) : data;
|
|
32029
|
+
return prior.map((r) => ({ author: r.author, body: r.body }));
|
|
31802
32030
|
}
|
|
31803
|
-
|
|
31804
|
-
|
|
31805
|
-
|
|
31806
|
-
|
|
31807
|
-
|
|
31808
|
-
|
|
31809
|
-
|
|
31810
|
-
|
|
31811
|
-
|
|
31812
|
-
|
|
31813
|
-
|
|
31814
|
-
|
|
31815
|
-
abs,
|
|
31816
|
-
buildSkillFile(
|
|
31817
|
-
{ name, description },
|
|
31818
|
-
`# ${name}
|
|
31819
|
-
|
|
31820
|
-
Describe what this skill does and when to use it.
|
|
31821
|
-
`
|
|
31822
|
-
),
|
|
31823
|
-
"utf8"
|
|
31824
|
-
);
|
|
31825
|
-
const detail = readSkillFile(dir, name);
|
|
31826
|
-
return detail ? { status: "ok", skill: detail } : { status: "bad-name" };
|
|
31827
|
-
}
|
|
31828
|
-
function deleteSkillFile(dir, name) {
|
|
31829
|
-
const abs = resolveSkillPath(dir, name);
|
|
31830
|
-
if (!abs || !existsSync20(abs)) return { status: "not-found" };
|
|
31831
|
-
rmSync9(join19(dir, name), { recursive: true, force: true });
|
|
31832
|
-
return { status: "ok" };
|
|
31833
|
-
}
|
|
32031
|
+
/**
|
|
32032
|
+
* Thread history before the triggering message, formatted like the Slack
|
|
32033
|
+
* listener's thread context block. Empty string when the trigger is the
|
|
32034
|
+
* only message (nothing to seed).
|
|
32035
|
+
*/
|
|
32036
|
+
async fetchThreadContext(threadId, excludeReplyId) {
|
|
32037
|
+
const prior = await this.fetchThreadMessages(threadId, excludeReplyId);
|
|
32038
|
+
if (prior.length === 0) return "";
|
|
32039
|
+
const lines = prior.map((r) => `${r.author}: ${r.body}`).join("\n");
|
|
32040
|
+
return `[thread context: messages before this one]
|
|
32041
|
+
${lines}
|
|
32042
|
+
[end thread context]
|
|
31834
32043
|
|
|
31835
|
-
|
|
31836
|
-
function defaultConfigDir2() {
|
|
31837
|
-
return join20(homedir8(), ".claude");
|
|
31838
|
-
}
|
|
31839
|
-
function expandHome3(p) {
|
|
31840
|
-
if (p === "~") return homedir8();
|
|
31841
|
-
if (p.startsWith("~/")) return join20(homedir8(), p.slice(2));
|
|
31842
|
-
return p;
|
|
31843
|
-
}
|
|
31844
|
-
function parseFrontmatter2(file) {
|
|
31845
|
-
let content;
|
|
31846
|
-
try {
|
|
31847
|
-
content = readFileSync17(file, "utf-8");
|
|
31848
|
-
} catch {
|
|
31849
|
-
return {};
|
|
31850
|
-
}
|
|
31851
|
-
const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
31852
|
-
if (!match) return {};
|
|
31853
|
-
try {
|
|
31854
|
-
const fm = yaml3.load(match[1]);
|
|
31855
|
-
const name = typeof fm?.["name"] === "string" ? fm["name"] : void 0;
|
|
31856
|
-
const description = typeof fm?.["description"] === "string" ? fm["description"] : void 0;
|
|
31857
|
-
return { name, description };
|
|
31858
|
-
} catch {
|
|
31859
|
-
return {};
|
|
31860
|
-
}
|
|
31861
|
-
}
|
|
31862
|
-
function isSymlinkedDir(root, entry) {
|
|
31863
|
-
if (!entry.isSymbolicLink()) return false;
|
|
31864
|
-
try {
|
|
31865
|
-
return statSync9(join20(root, entry.name)).isDirectory();
|
|
31866
|
-
} catch {
|
|
31867
|
-
return false;
|
|
32044
|
+
`;
|
|
31868
32045
|
}
|
|
31869
|
-
|
|
31870
|
-
|
|
31871
|
-
|
|
31872
|
-
|
|
31873
|
-
|
|
31874
|
-
entries2 = readdirSync5(root, { withFileTypes: true });
|
|
31875
|
-
} catch {
|
|
31876
|
-
return;
|
|
32046
|
+
/**
|
|
32047
|
+
* Last recorded run's replayed context for a thread; see `contextTokensOf`.
|
|
32048
|
+
*/
|
|
32049
|
+
lastRunContextTokens(threadTs) {
|
|
32050
|
+
return contextTokensOf(this.openUsageStore().recent(1, { threadTs })[0]);
|
|
31877
32051
|
}
|
|
31878
|
-
|
|
31879
|
-
|
|
31880
|
-
|
|
31881
|
-
|
|
31882
|
-
|
|
31883
|
-
|
|
31884
|
-
|
|
32052
|
+
/**
|
|
32053
|
+
* Builds the rollover handoff seed for a thread past the compact
|
|
32054
|
+
* threshold — see docs/session-auto-compact.md and rollover-summary.ts.
|
|
32055
|
+
* `undefined` on anything that stops rollover from being safe to do
|
|
32056
|
+
* (nothing to summarize, or the Haiku call itself failed); the caller
|
|
32057
|
+
* treats that as "skip rollover, resume the old session as normal".
|
|
32058
|
+
*/
|
|
32059
|
+
async buildRolloverSeed(threadId, excludeReplyId, auth) {
|
|
32060
|
+
const messages = await this.fetchThreadMessages(threadId, excludeReplyId);
|
|
32061
|
+
if (messages.length === 0) return void 0;
|
|
32062
|
+
const recentVerbatimTokens = this.config.recentVerbatimTokens ?? DEFAULT_RECENT_VERBATIM_TOKENS;
|
|
32063
|
+
return this.summarizeForRollover(messages, recentVerbatimTokens, auth);
|
|
31885
32064
|
}
|
|
31886
|
-
|
|
31887
|
-
|
|
31888
|
-
|
|
31889
|
-
|
|
32065
|
+
/** Programmatic check for `@path` doc mentions: the model's paths are
|
|
32066
|
+
* never trusted, only ones that resolve to a real file in the channel
|
|
32067
|
+
* folder stay as mentions. */
|
|
32068
|
+
async guardDocMentionsFor(threadId, body) {
|
|
32069
|
+
if (!body.includes("@")) return body;
|
|
31890
32070
|
try {
|
|
31891
|
-
const
|
|
31892
|
-
|
|
32071
|
+
const { data: thread } = await this.supabase().from("threads").select("channel_id").eq("id", threadId).single();
|
|
32072
|
+
if (!thread?.channel_id) return body;
|
|
32073
|
+
const cwd = runWithProfile(
|
|
32074
|
+
findOwningProfile(thread.channel_id),
|
|
32075
|
+
() => resolveChannelConfig(thread.channel_id).cwd
|
|
31893
32076
|
);
|
|
31894
|
-
|
|
32077
|
+
return guardDocMentions(body, cwd);
|
|
31895
32078
|
} catch {
|
|
32079
|
+
return body;
|
|
31896
32080
|
}
|
|
31897
|
-
dir = dirname3(dir);
|
|
31898
32081
|
}
|
|
31899
|
-
|
|
31900
|
-
|
|
31901
|
-
|
|
31902
|
-
|
|
31903
|
-
|
|
31904
|
-
return files.map((file) => {
|
|
31905
|
-
const fm = parseFrontmatter2(file);
|
|
31906
|
-
const name = fm.name?.trim() || basename5(dirname3(file));
|
|
31907
|
-
const plugin = source === "plugin" ? pluginNameFor(file, root) : void 0;
|
|
31908
|
-
const prefix = namePrefix ?? plugin;
|
|
31909
|
-
return {
|
|
31910
|
-
name: prefix ? `${prefix}:${name}` : name,
|
|
31911
|
-
description: (fm.description ?? "").trim(),
|
|
31912
|
-
source,
|
|
31913
|
-
...plugin && { plugin },
|
|
31914
|
-
// Only read by `listPluginSkillDetails`; `listSkills` strips it.
|
|
31915
|
-
file
|
|
32082
|
+
async postReply(threadId, body, activities) {
|
|
32083
|
+
const row = {
|
|
32084
|
+
thread_id: threadId,
|
|
32085
|
+
author: AGENT_AUTHOR,
|
|
32086
|
+
body: await this.guardDocMentionsFor(threadId, await uploadLocalImages(body))
|
|
31916
32087
|
};
|
|
31917
|
-
|
|
31918
|
-
}
|
|
31919
|
-
|
|
31920
|
-
|
|
31921
|
-
|
|
31922
|
-
...collectFrom2(join20(cwd, ".claude", "skills"), "project", 2),
|
|
31923
|
-
...nestedProjectRoots(cwd).flatMap(({ dir, prefix }) => collectFrom2(dir, "project", 2, prefix)),
|
|
31924
|
-
...collectFrom2(join20(base, "skills"), "user", 2),
|
|
31925
|
-
...collectFrom2(join20(base, "plugins"), "plugin", 8)
|
|
31926
|
-
];
|
|
31927
|
-
const byName = /* @__PURE__ */ new Map();
|
|
31928
|
-
for (const skill of collected) {
|
|
31929
|
-
if (skill.name && !byName.has(skill.name)) byName.set(skill.name, skill);
|
|
31930
|
-
}
|
|
31931
|
-
return [...byName.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
31932
|
-
}
|
|
31933
|
-
function nestedProjectRoots(cwd) {
|
|
31934
|
-
let entries2;
|
|
31935
|
-
try {
|
|
31936
|
-
entries2 = readdirSync5(cwd, { withFileTypes: true });
|
|
31937
|
-
} catch {
|
|
31938
|
-
return [];
|
|
31939
|
-
}
|
|
31940
|
-
const roots = [];
|
|
31941
|
-
for (const entry of entries2) {
|
|
31942
|
-
if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
|
|
31943
|
-
if (!entry.isDirectory() && !isSymlinkedDir(cwd, entry)) continue;
|
|
31944
|
-
const skillsDir = join20(cwd, entry.name, ".claude", "skills");
|
|
31945
|
-
if (existsSync21(skillsDir)) roots.push({ dir: skillsDir, prefix: entry.name });
|
|
31946
|
-
}
|
|
31947
|
-
return roots;
|
|
31948
|
-
}
|
|
31949
|
-
function listSkills(configDir, cwd) {
|
|
31950
|
-
return collectAll(configDir, cwd).map(({ file: _file, ...skill }) => skill);
|
|
31951
|
-
}
|
|
31952
|
-
function listPluginSkillDetails(configDir, cwd) {
|
|
31953
|
-
const details = [];
|
|
31954
|
-
for (const { file, ...skill } of collectAll(configDir, cwd)) {
|
|
31955
|
-
if (skill.source !== "plugin") continue;
|
|
31956
|
-
try {
|
|
31957
|
-
const { body } = splitFrontmatter(readFileSync17(file, "utf-8"));
|
|
31958
|
-
details.push({ ...skill, body, path: file, mtime: statSync9(file).mtime.toISOString() });
|
|
31959
|
-
} catch {
|
|
32088
|
+
if (activities && activities.length > 0) row["activities"] = activities;
|
|
32089
|
+
let { error } = await this.supabase().from("thread_replies").insert(row);
|
|
32090
|
+
if (error && row["activities"]) {
|
|
32091
|
+
delete row["activities"];
|
|
32092
|
+
({ error } = await this.supabase().from("thread_replies").insert(row));
|
|
31960
32093
|
}
|
|
31961
|
-
|
|
31962
|
-
|
|
31963
|
-
}
|
|
31964
|
-
function findSkillDetail(configDir, cwd, name, sources) {
|
|
31965
|
-
const base = configDir ? expandHome3(configDir) : defaultConfigDir2();
|
|
31966
|
-
const roots = [
|
|
31967
|
-
[join20(cwd, ".claude", "skills"), "project", 2],
|
|
31968
|
-
...nestedProjectRoots(cwd).map(({ dir, prefix }) => [
|
|
31969
|
-
dir,
|
|
31970
|
-
"project",
|
|
31971
|
-
2,
|
|
31972
|
-
prefix
|
|
31973
|
-
]),
|
|
31974
|
-
[join20(base, "skills"), "user", 2],
|
|
31975
|
-
[join20(base, "plugins"), "plugin", 8]
|
|
31976
|
-
];
|
|
31977
|
-
for (const [root, source, maxDepth, namePrefix] of roots) {
|
|
31978
|
-
if (!sources.includes(source)) continue;
|
|
31979
|
-
const files = [];
|
|
31980
|
-
findSkillFiles(root, maxDepth, files);
|
|
31981
|
-
for (const file of files) {
|
|
31982
|
-
const fm = parseFrontmatter2(file);
|
|
31983
|
-
const rawName = fm.name?.trim() || basename5(dirname3(file));
|
|
31984
|
-
const plugin = source === "plugin" ? pluginNameFor(file, root) : void 0;
|
|
31985
|
-
const prefix = namePrefix ?? plugin;
|
|
31986
|
-
const skillName = prefix ? `${prefix}:${rawName}` : rawName;
|
|
31987
|
-
if (skillName !== name) continue;
|
|
31988
|
-
let raw;
|
|
31989
|
-
let mtime;
|
|
31990
|
-
try {
|
|
31991
|
-
raw = readFileSync17(file, "utf-8");
|
|
31992
|
-
mtime = statSync9(file).mtime.toISOString();
|
|
31993
|
-
} catch {
|
|
31994
|
-
continue;
|
|
31995
|
-
}
|
|
31996
|
-
const { body } = splitFrontmatter(raw);
|
|
31997
|
-
return {
|
|
31998
|
-
name: skillName,
|
|
31999
|
-
description: (fm.description ?? "").trim(),
|
|
32000
|
-
source,
|
|
32001
|
-
...plugin && { plugin },
|
|
32002
|
-
body,
|
|
32003
|
-
path: file,
|
|
32004
|
-
mtime
|
|
32005
|
-
};
|
|
32094
|
+
if (error) {
|
|
32095
|
+
console.error(`[chat-agent] failed to post reply to ${threadId}:`, error.message);
|
|
32006
32096
|
}
|
|
32007
32097
|
}
|
|
32008
|
-
|
|
32009
|
-
}
|
|
32098
|
+
};
|
|
32010
32099
|
|
|
32011
32100
|
// src/slack/commands.ts
|
|
32012
32101
|
var SKILL_SELECT_ACTION_ID = "custie_skill_select";
|
|
@@ -34033,13 +34122,13 @@ async function recoverStaleReactions(client, reactionStore) {
|
|
|
34033
34122
|
var ts2 = () => (/* @__PURE__ */ new Date()).toISOString();
|
|
34034
34123
|
var POWER_POLL_MS = 3e4;
|
|
34035
34124
|
function isOnACPower() {
|
|
34036
|
-
return new Promise((
|
|
34125
|
+
return new Promise((resolve9) => {
|
|
34037
34126
|
execFile2("pmset", ["-g", "ps"], { timeout: 2e3 }, (err, stdout) => {
|
|
34038
34127
|
if (err) {
|
|
34039
|
-
|
|
34128
|
+
resolve9(true);
|
|
34040
34129
|
return;
|
|
34041
34130
|
}
|
|
34042
|
-
|
|
34131
|
+
resolve9(stdout.includes("'AC Power'"));
|
|
34043
34132
|
});
|
|
34044
34133
|
});
|
|
34045
34134
|
}
|
|
@@ -34177,6 +34266,8 @@ export {
|
|
|
34177
34266
|
listMemberChannels,
|
|
34178
34267
|
refreshCache,
|
|
34179
34268
|
resolveChannelId,
|
|
34269
|
+
resolveRateCard,
|
|
34270
|
+
explainCost,
|
|
34180
34271
|
UsageStore,
|
|
34181
34272
|
listActiveUsers,
|
|
34182
34273
|
displayNameFor,
|
|
@@ -34238,6 +34329,7 @@ export {
|
|
|
34238
34329
|
MEMORY_TYPES,
|
|
34239
34330
|
isMemoryType,
|
|
34240
34331
|
validateMemoryInput,
|
|
34332
|
+
rowToMemory,
|
|
34241
34333
|
listMemories,
|
|
34242
34334
|
getMemory,
|
|
34243
34335
|
saveMemory,
|
|
@@ -34360,6 +34452,17 @@ export {
|
|
|
34360
34452
|
LOCAL_DB_PATH,
|
|
34361
34453
|
createHostDbClient,
|
|
34362
34454
|
listAgents,
|
|
34455
|
+
workspaceSkillsDir,
|
|
34456
|
+
channelSkillsDir,
|
|
34457
|
+
isValidSkillName,
|
|
34458
|
+
listSkillFiles,
|
|
34459
|
+
readSkillFile,
|
|
34460
|
+
writeSkillFile,
|
|
34461
|
+
createSkillFile,
|
|
34462
|
+
deleteSkillFile,
|
|
34463
|
+
listSkills,
|
|
34464
|
+
listPluginSkillDetails,
|
|
34465
|
+
findSkillDetail,
|
|
34363
34466
|
SessionStore,
|
|
34364
34467
|
setProfileConfigCache,
|
|
34365
34468
|
cachedProfileConfig,
|
|
@@ -34414,7 +34517,6 @@ export {
|
|
|
34414
34517
|
createFeatureFlagsRouter,
|
|
34415
34518
|
PLATE,
|
|
34416
34519
|
renderAppIcon,
|
|
34417
|
-
buildManifest,
|
|
34418
34520
|
clientKey,
|
|
34419
34521
|
createPublicShareApiRouter,
|
|
34420
34522
|
createPublicShareAssetRouter,
|
|
@@ -34430,17 +34532,6 @@ export {
|
|
|
34430
34532
|
syncSupportReply,
|
|
34431
34533
|
loadChatAgentConfig,
|
|
34432
34534
|
ChatAgent,
|
|
34433
|
-
workspaceSkillsDir,
|
|
34434
|
-
channelSkillsDir,
|
|
34435
|
-
isValidSkillName,
|
|
34436
|
-
listSkillFiles,
|
|
34437
|
-
readSkillFile,
|
|
34438
|
-
writeSkillFile,
|
|
34439
|
-
createSkillFile,
|
|
34440
|
-
deleteSkillFile,
|
|
34441
|
-
listSkills,
|
|
34442
|
-
listPluginSkillDetails,
|
|
34443
|
-
findSkillDetail,
|
|
34444
34535
|
recentRunsForWorkspace,
|
|
34445
34536
|
lastRunsForWorkspace,
|
|
34446
34537
|
installUsageRecording,
|