flyspace-cli 0.1.56 → 0.1.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-ZUYZL7Y3.js → chunk-TAUF3WGB.js} +826 -487
- package/dist/cli.js +267 -432
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { createRequire as __flyspaceCreateRequire } from 'node:module';
|
|
3
3
|
const require = __flyspaceCreateRequire(import.meta.url);
|
|
4
4
|
import {
|
|
5
|
+
AuthApiError,
|
|
5
6
|
AutomationManager,
|
|
6
7
|
BOT_DM_KEY,
|
|
7
8
|
BOT_LABEL,
|
|
@@ -10,6 +11,7 @@ import {
|
|
|
10
11
|
BUILT_IN_OUTPUT_STYLES,
|
|
11
12
|
CLI_VERSION,
|
|
12
13
|
ChatAgent,
|
|
14
|
+
DEFAULT_API_URL,
|
|
13
15
|
DEFAULT_TIMEZONE,
|
|
14
16
|
DocShareSlugTakenError,
|
|
15
17
|
HANDLE_PATTERN,
|
|
@@ -28,9 +30,11 @@ import {
|
|
|
28
30
|
UsageStore,
|
|
29
31
|
acquireHostLock,
|
|
30
32
|
agentViewer,
|
|
33
|
+
apiUrl,
|
|
31
34
|
authorFor,
|
|
32
35
|
blockToFallbackText,
|
|
33
36
|
bodyTextFor,
|
|
37
|
+
boundWorkspaces,
|
|
34
38
|
buildAuthorizeUrl,
|
|
35
39
|
buildAutoTitle,
|
|
36
40
|
cachedProfileConfig,
|
|
@@ -38,6 +42,7 @@ import {
|
|
|
38
42
|
channelSkillsDir,
|
|
39
43
|
claudeAuthFailed,
|
|
40
44
|
clearClaudeAuthFailed,
|
|
45
|
+
clearLocalAuth,
|
|
41
46
|
clientKey,
|
|
42
47
|
codexAuthAvailable,
|
|
43
48
|
consumeOAuthState,
|
|
@@ -57,6 +62,7 @@ import {
|
|
|
57
62
|
createStateToken,
|
|
58
63
|
createTtsRouter,
|
|
59
64
|
createWorkspace,
|
|
65
|
+
credentialsPath,
|
|
60
66
|
crossOriginShell,
|
|
61
67
|
defaultClaudeCwd,
|
|
62
68
|
defaultEffort,
|
|
@@ -72,21 +78,25 @@ import {
|
|
|
72
78
|
deleteWorkspaceDomain,
|
|
73
79
|
deriveConnectionSlug,
|
|
74
80
|
detectSourceLanguage,
|
|
81
|
+
deviceKeyPath,
|
|
75
82
|
displayNameFor,
|
|
76
83
|
dropShareAudio,
|
|
77
84
|
dropShareLangAudioKeys,
|
|
78
85
|
effectiveModel,
|
|
86
|
+
ensureDeviceKey,
|
|
79
87
|
ensureUsersCached,
|
|
80
88
|
escalateToHuman,
|
|
81
89
|
exchangeCode,
|
|
82
90
|
explainCost,
|
|
83
91
|
extractCategories,
|
|
84
92
|
extractTitle,
|
|
93
|
+
fetchWhoAmI,
|
|
85
94
|
filterReadableDocsChannels,
|
|
86
95
|
findDocShareBySource,
|
|
87
96
|
findOwningProfile,
|
|
88
97
|
findSkillDetail,
|
|
89
98
|
flatDocs,
|
|
99
|
+
getAccessToken,
|
|
90
100
|
getAgentPaused,
|
|
91
101
|
getAllowGuestAccess,
|
|
92
102
|
getChannelDocsMemberAccess,
|
|
@@ -156,6 +166,7 @@ import {
|
|
|
156
166
|
loadBotIdentity,
|
|
157
167
|
loadChatAgentConfig,
|
|
158
168
|
loadConfig,
|
|
169
|
+
loadCredentials,
|
|
159
170
|
loadDashboardSettings,
|
|
160
171
|
loadEffectiveAutomations,
|
|
161
172
|
loadEnvFiles,
|
|
@@ -170,6 +181,7 @@ import {
|
|
|
170
181
|
mentionedUserIds,
|
|
171
182
|
onboardingPending,
|
|
172
183
|
pinnedClaudeConfigDir,
|
|
184
|
+
pollDeviceToken,
|
|
173
185
|
profileClaudeConfigDir,
|
|
174
186
|
profileEnv,
|
|
175
187
|
profileFromHost,
|
|
@@ -186,6 +198,7 @@ import {
|
|
|
186
198
|
refreshUserCache,
|
|
187
199
|
removeChannelMember,
|
|
188
200
|
renderAppIcon,
|
|
201
|
+
requestDeviceCode,
|
|
189
202
|
requestHostDb,
|
|
190
203
|
requireDocsAccess,
|
|
191
204
|
requireSlackBotToken,
|
|
@@ -199,15 +212,18 @@ import {
|
|
|
199
212
|
resolveRateCard,
|
|
200
213
|
resolveRawPath,
|
|
201
214
|
resolveUserId,
|
|
215
|
+
revokeDevice,
|
|
202
216
|
revokeDocShare,
|
|
203
217
|
rowToMemory,
|
|
204
218
|
runAutomation,
|
|
219
|
+
runPersonaCmd,
|
|
205
220
|
runScriptAutomation,
|
|
206
221
|
runnerForModel,
|
|
207
222
|
safeRedirectPath,
|
|
208
223
|
saveAgentProfile,
|
|
209
224
|
saveBotIdentity,
|
|
210
225
|
saveChannelMemory,
|
|
226
|
+
saveCredentials,
|
|
211
227
|
saveDashboardSettings,
|
|
212
228
|
saveMemory,
|
|
213
229
|
saveWorkspaceBranding,
|
|
@@ -257,12 +273,13 @@ import {
|
|
|
257
273
|
usageLimitedModels,
|
|
258
274
|
usageLimitedUntil,
|
|
259
275
|
useDirectSupabase,
|
|
276
|
+
useHostDbWithoutCredentials,
|
|
260
277
|
useLocalCache,
|
|
261
278
|
validateMemoryInput,
|
|
262
279
|
workspaceHostname,
|
|
263
280
|
workspaceSkillsDir,
|
|
264
281
|
writeSkillFile
|
|
265
|
-
} from "./chunk-
|
|
282
|
+
} from "./chunk-TAUF3WGB.js";
|
|
266
283
|
import {
|
|
267
284
|
canReadThread,
|
|
268
285
|
firstReplyBody,
|
|
@@ -297,7 +314,6 @@ import {
|
|
|
297
314
|
getR2Bucket,
|
|
298
315
|
getR2Client,
|
|
299
316
|
getSupabaseClient,
|
|
300
|
-
hasSupabaseCredentials,
|
|
301
317
|
isCwdUsable,
|
|
302
318
|
isEffort,
|
|
303
319
|
isHumanAuthor,
|
|
@@ -444,191 +460,6 @@ async function preflight(opts = {}) {
|
|
|
444
460
|
exit(1);
|
|
445
461
|
}
|
|
446
462
|
|
|
447
|
-
// src/auth/device-auth.ts
|
|
448
|
-
import { createPrivateKey, createPublicKey, generateKeyPairSync, sign } from "crypto";
|
|
449
|
-
import { existsSync, mkdirSync as mkdirSync2, readFileSync as readFileSync2, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
450
|
-
import { dirname as dirname2, join as join2 } from "path";
|
|
451
|
-
var DEFAULT_API_URL = "https://app.flyspace.ai";
|
|
452
|
-
var EXPIRY_SKEW_MS = 6e4;
|
|
453
|
-
var AuthApiError = class extends Error {
|
|
454
|
-
constructor(message, status) {
|
|
455
|
-
super(message);
|
|
456
|
-
this.status = status;
|
|
457
|
-
this.name = "AuthApiError";
|
|
458
|
-
}
|
|
459
|
-
};
|
|
460
|
-
function apiUrl() {
|
|
461
|
-
return (process.env["FLYSPACE_API_URL"] || DEFAULT_API_URL).replace(/\/+$/, "");
|
|
462
|
-
}
|
|
463
|
-
function deviceKeyPath() {
|
|
464
|
-
return join2(paths.BASE_CONFIG_DIR, "device.key");
|
|
465
|
-
}
|
|
466
|
-
function credentialsPath() {
|
|
467
|
-
return join2(paths.BASE_CONFIG_DIR, "credentials.json");
|
|
468
|
-
}
|
|
469
|
-
function ensureDeviceKey(path = deviceKeyPath()) {
|
|
470
|
-
let created = false;
|
|
471
|
-
if (!existsSync(path)) {
|
|
472
|
-
const { privateKey: privateKey2 } = generateKeyPairSync("ed25519");
|
|
473
|
-
mkdirSync2(dirname2(path), { recursive: true });
|
|
474
|
-
writeFileSync2(path, privateKey2.export({ type: "pkcs8", format: "pem" }), { mode: 384 });
|
|
475
|
-
created = true;
|
|
476
|
-
}
|
|
477
|
-
const privateKey = createPrivateKey(readFileSync2(path, "utf8"));
|
|
478
|
-
const publicKeyBase64 = createPublicKey(privateKey).export({ type: "spki", format: "der" }).toString(
|
|
479
|
-
"base64"
|
|
480
|
-
);
|
|
481
|
-
return { privateKey, publicKeyBase64, created };
|
|
482
|
-
}
|
|
483
|
-
function loadCredentials(path = credentialsPath()) {
|
|
484
|
-
if (!existsSync(path)) return null;
|
|
485
|
-
try {
|
|
486
|
-
return JSON.parse(readFileSync2(path, "utf8"));
|
|
487
|
-
} catch {
|
|
488
|
-
return null;
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
function saveCredentials(creds, path = credentialsPath()) {
|
|
492
|
-
mkdirSync2(dirname2(path), { recursive: true });
|
|
493
|
-
writeFileSync2(path, `${JSON.stringify(creds, null, 2)}
|
|
494
|
-
`, { mode: 384 });
|
|
495
|
-
}
|
|
496
|
-
function clearLocalAuth() {
|
|
497
|
-
rmSync2(credentialsPath(), { force: true });
|
|
498
|
-
rmSync2(deviceKeyPath(), { force: true });
|
|
499
|
-
}
|
|
500
|
-
async function post(base, path, body, token) {
|
|
501
|
-
return fetch(`${base}${path}`, {
|
|
502
|
-
method: "POST",
|
|
503
|
-
headers: {
|
|
504
|
-
"content-type": "application/json",
|
|
505
|
-
...token ? { authorization: `Bearer ${token}` } : {}
|
|
506
|
-
},
|
|
507
|
-
body: JSON.stringify(body)
|
|
508
|
-
});
|
|
509
|
-
}
|
|
510
|
-
async function readJson(res) {
|
|
511
|
-
try {
|
|
512
|
-
return await res.json();
|
|
513
|
-
} catch {
|
|
514
|
-
return {};
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
async function expectOk(res, what) {
|
|
518
|
-
const json = await readJson(res);
|
|
519
|
-
if (!res.ok) {
|
|
520
|
-
const reason = typeof json["error"] === "string" ? json["error"] : res.statusText;
|
|
521
|
-
throw new AuthApiError(`${what} failed (${res.status}): ${reason}`, res.status);
|
|
522
|
-
}
|
|
523
|
-
return json;
|
|
524
|
-
}
|
|
525
|
-
function toSlugs(value) {
|
|
526
|
-
return Array.isArray(value) ? value.filter((v) => typeof v === "string") : [];
|
|
527
|
-
}
|
|
528
|
-
function toGrant(json) {
|
|
529
|
-
const user = json["user"] ?? {};
|
|
530
|
-
return {
|
|
531
|
-
accessToken: String(json["access_token"]),
|
|
532
|
-
expiresIn: Number(json["expires_in"]),
|
|
533
|
-
deviceId: String(json["device_id"]),
|
|
534
|
-
userEmail: String(user["email"] ?? ""),
|
|
535
|
-
workspaces: toSlugs(json["workspaces"])
|
|
536
|
-
};
|
|
537
|
-
}
|
|
538
|
-
async function requestDeviceCode(base, input2) {
|
|
539
|
-
const res = await post(base, "/api/auth/device/code", {
|
|
540
|
-
public_key: input2.publicKey,
|
|
541
|
-
name: input2.name,
|
|
542
|
-
platform: input2.platform
|
|
543
|
-
});
|
|
544
|
-
const json = await expectOk(res, "Requesting a device code");
|
|
545
|
-
return {
|
|
546
|
-
deviceCode: String(json["device_code"]),
|
|
547
|
-
userCode: String(json["user_code"]),
|
|
548
|
-
verificationUri: String(json["verification_uri"]),
|
|
549
|
-
expiresIn: Number(json["expires_in"]),
|
|
550
|
-
interval: Number(json["interval"] ?? 5)
|
|
551
|
-
};
|
|
552
|
-
}
|
|
553
|
-
async function pollDeviceToken(base, deviceCode) {
|
|
554
|
-
const res = await post(base, "/api/auth/device/token", { device_code: deviceCode });
|
|
555
|
-
const json = await readJson(res);
|
|
556
|
-
if (res.ok) return { status: "approved", grant: toGrant(json) };
|
|
557
|
-
switch (json["error"]) {
|
|
558
|
-
case "authorization_pending":
|
|
559
|
-
return { status: "pending" };
|
|
560
|
-
case "slow_down":
|
|
561
|
-
return { status: "slow_down" };
|
|
562
|
-
case "access_denied":
|
|
563
|
-
return { status: "denied" };
|
|
564
|
-
case "expired_token":
|
|
565
|
-
return { status: "expired" };
|
|
566
|
-
default:
|
|
567
|
-
throw new AuthApiError(`Polling for approval failed (${res.status}): ${String(json["error"] ?? res.statusText)}`, res.status);
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
async function refreshAccessToken(creds, privateKey) {
|
|
571
|
-
const challenge = await expectOk(
|
|
572
|
-
await post(creds.apiUrl, "/api/auth/device/challenge", { device_id: creds.deviceId }),
|
|
573
|
-
"Requesting a refresh challenge"
|
|
574
|
-
);
|
|
575
|
-
const nonce = String(challenge["nonce"]);
|
|
576
|
-
const signature = sign(null, Buffer.from(nonce), privateKey).toString("base64");
|
|
577
|
-
const json = await expectOk(
|
|
578
|
-
await post(creds.apiUrl, "/api/auth/device/refresh", { device_id: creds.deviceId, nonce, signature }),
|
|
579
|
-
"Refreshing the access token"
|
|
580
|
-
);
|
|
581
|
-
return {
|
|
582
|
-
...creds,
|
|
583
|
-
accessToken: String(json["access_token"]),
|
|
584
|
-
accessTokenExpiresAt: Date.now() + Number(json["expires_in"]) * 1e3
|
|
585
|
-
};
|
|
586
|
-
}
|
|
587
|
-
async function fetchWhoAmI(base, token) {
|
|
588
|
-
const res = await fetch(`${base}/api/auth/device/me`, { headers: { authorization: `Bearer ${token}` } });
|
|
589
|
-
const json = await expectOk(res, "Checking the session");
|
|
590
|
-
const user = json["user"] ?? {};
|
|
591
|
-
const device = json["device"] ?? {};
|
|
592
|
-
return {
|
|
593
|
-
userEmail: String(user["email"] ?? ""),
|
|
594
|
-
deviceId: String(device["id"] ?? ""),
|
|
595
|
-
deviceName: String(device["name"] ?? ""),
|
|
596
|
-
workspaces: toSlugs(json["workspaces"])
|
|
597
|
-
};
|
|
598
|
-
}
|
|
599
|
-
async function boundWorkspaces() {
|
|
600
|
-
const creds = loadCredentials();
|
|
601
|
-
if (!creds) return null;
|
|
602
|
-
try {
|
|
603
|
-
const me = await fetchWhoAmI(creds.apiUrl, await getAccessToken());
|
|
604
|
-
saveCredentials({ ...loadCredentials() ?? creds, workspaces: me.workspaces });
|
|
605
|
-
return { workspaces: me.workspaces, fresh: true };
|
|
606
|
-
} catch {
|
|
607
|
-
return { workspaces: creds.workspaces ?? [], fresh: false };
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
async function revokeDevice(base, token) {
|
|
611
|
-
await expectOk(await post(base, "/api/auth/device/revoke", {}, token), "Revoking this device");
|
|
612
|
-
}
|
|
613
|
-
async function getAccessToken() {
|
|
614
|
-
const fromEnv = process.env["FLYSPACE_TOKEN"];
|
|
615
|
-
if (fromEnv) return fromEnv;
|
|
616
|
-
const creds = loadCredentials();
|
|
617
|
-
if (!creds) return null;
|
|
618
|
-
if (creds.accessTokenExpiresAt - EXPIRY_SKEW_MS > Date.now()) return creds.accessToken;
|
|
619
|
-
const { privateKey } = ensureDeviceKey();
|
|
620
|
-
const refreshed = await refreshAccessToken(creds, privateKey);
|
|
621
|
-
saveCredentials(refreshed);
|
|
622
|
-
return refreshed.accessToken;
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
// src/commands/supabase-via-host.ts
|
|
626
|
-
function useHostDbWithoutCredentials() {
|
|
627
|
-
const viaHost = !!loadCredentials() && (!hasSupabaseCredentials() || !!readHostEndpoint());
|
|
628
|
-
if (viaHost) setSupabaseClient(createHostDbClient("local-host"));
|
|
629
|
-
return viaHost;
|
|
630
|
-
}
|
|
631
|
-
|
|
632
463
|
// src/commands/start.ts
|
|
633
464
|
async function runStart() {
|
|
634
465
|
loadEnvFiles();
|
|
@@ -638,7 +469,7 @@ async function runStart() {
|
|
|
638
469
|
}
|
|
639
470
|
|
|
640
471
|
// src/commands/config.ts
|
|
641
|
-
import { existsSync
|
|
472
|
+
import { existsSync, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
642
473
|
import { spawn } from "child_process";
|
|
643
474
|
import { resolve } from "path";
|
|
644
475
|
function maskToken(value) {
|
|
@@ -656,12 +487,12 @@ function printConfig() {
|
|
|
656
487
|
console.log("\n Paths:");
|
|
657
488
|
console.log(` Config dir: ${paths.CONFIG_DIR}`);
|
|
658
489
|
console.log(` Data dir: ${paths.DATA_DIR}`);
|
|
659
|
-
console.log(` Config file: ${paths.CONFIG_FILE} ${
|
|
660
|
-
console.log(` Prompt file: ${paths.PROMPT_FILE} ${
|
|
661
|
-
console.log(` Database: ${paths.DB_FILE} ${
|
|
490
|
+
console.log(` Config file: ${paths.CONFIG_FILE} ${existsSync(paths.CONFIG_FILE) ? "(exists)" : "(not found)"}`);
|
|
491
|
+
console.log(` Prompt file: ${paths.PROMPT_FILE} ${existsSync(paths.PROMPT_FILE) ? "(exists)" : "(not found)"}`);
|
|
492
|
+
console.log(` Database: ${paths.DB_FILE} ${existsSync(paths.DB_FILE) ? "(exists)" : "(not found)"}`);
|
|
662
493
|
console.log(` Log dir: ${paths.LOG_DIR}`);
|
|
663
494
|
const repoEnv = resolve(process.cwd(), ".env");
|
|
664
|
-
console.log(` Repo .env: ${repoEnv} ${
|
|
495
|
+
console.log(` Repo .env: ${repoEnv} ${existsSync(repoEnv) ? "(exists)" : "(not found)"}`);
|
|
665
496
|
const envKeys = [
|
|
666
497
|
"SLACK_BOT_TOKEN",
|
|
667
498
|
"SLACK_APP_TOKEN",
|
|
@@ -685,13 +516,13 @@ function printConfig() {
|
|
|
685
516
|
}
|
|
686
517
|
function editConfig() {
|
|
687
518
|
ensureDirs();
|
|
688
|
-
if (!
|
|
519
|
+
if (!existsSync(paths.CONFIG_FILE)) {
|
|
689
520
|
const defaultEnv = resolve(paths.PACKAGE_ROOT, ".env.example");
|
|
690
|
-
if (
|
|
691
|
-
const content =
|
|
692
|
-
|
|
521
|
+
if (existsSync(defaultEnv)) {
|
|
522
|
+
const content = readFileSync2(defaultEnv, "utf-8");
|
|
523
|
+
writeFileSync2(paths.CONFIG_FILE, content);
|
|
693
524
|
} else {
|
|
694
|
-
|
|
525
|
+
writeFileSync2(paths.CONFIG_FILE, "");
|
|
695
526
|
}
|
|
696
527
|
console.log(`[flyspace] Created ${paths.CONFIG_FILE}`);
|
|
697
528
|
}
|
|
@@ -725,14 +556,14 @@ async function runConfig(args) {
|
|
|
725
556
|
|
|
726
557
|
// src/commands/setup.ts
|
|
727
558
|
import { execFileSync as execFileSync2, execSync as execSync4 } from "child_process";
|
|
728
|
-
import { mkdirSync as
|
|
729
|
-
import { join as
|
|
559
|
+
import { mkdirSync as mkdirSync4 } from "fs";
|
|
560
|
+
import { join as join6 } from "path";
|
|
730
561
|
import { confirm as confirm2 } from "@inquirer/prompts";
|
|
731
562
|
|
|
732
563
|
// ../api/src/service.ts
|
|
733
564
|
import { execSync } from "child_process";
|
|
734
|
-
import { existsSync as
|
|
735
|
-
import { basename, dirname as
|
|
565
|
+
import { existsSync as existsSync2, readFileSync as readFileSync3, realpathSync } from "fs";
|
|
566
|
+
import { basename, dirname as dirname2, join as join2 } from "path";
|
|
736
567
|
import { homedir, platform } from "os";
|
|
737
568
|
function flyspaceHome(entry = process.argv[1]) {
|
|
738
569
|
let cliPath;
|
|
@@ -745,8 +576,8 @@ function flyspaceHome(entry = process.argv[1]) {
|
|
|
745
576
|
if (at <= 0) return void 0;
|
|
746
577
|
const npmPrefix = cliPath.slice(0, at);
|
|
747
578
|
if (basename(npmPrefix) !== "cli") return void 0;
|
|
748
|
-
const home2 =
|
|
749
|
-
return
|
|
579
|
+
const home2 = dirname2(npmPrefix);
|
|
580
|
+
return existsSync2(join2(home2, "bin", "flyspace")) && existsSync2(join2(home2, "node", "bin", "node")) ? home2 : void 0;
|
|
750
581
|
}
|
|
751
582
|
function serviceLabel(profile) {
|
|
752
583
|
return profile === DEFAULT_PROFILE ? "ai.flyspace" : `ai.flyspace.${profile}`;
|
|
@@ -755,33 +586,33 @@ function plistName(profile) {
|
|
|
755
586
|
return `${serviceLabel(profile)}.plist`;
|
|
756
587
|
}
|
|
757
588
|
function plistPath(profile) {
|
|
758
|
-
return
|
|
589
|
+
return join2(homedir(), "Library", "LaunchAgents", plistName(profile));
|
|
759
590
|
}
|
|
760
591
|
function legacyServiceLabel(profile) {
|
|
761
592
|
return profile === DEFAULT_PROFILE ? "io.flycoder.flyspace" : `io.flycoder.flyspace.${profile}`;
|
|
762
593
|
}
|
|
763
594
|
function legacyPlistPath(profile) {
|
|
764
|
-
return
|
|
595
|
+
return join2(homedir(), "Library", "LaunchAgents", `${legacyServiceLabel(profile)}.plist`);
|
|
765
596
|
}
|
|
766
597
|
function systemdUnitName(profile) {
|
|
767
598
|
return profile === DEFAULT_PROFILE ? "flyspace" : `flyspace-${profile}`;
|
|
768
599
|
}
|
|
769
600
|
function systemdUnitPath(profile) {
|
|
770
|
-
return
|
|
601
|
+
return join2(homedir(), ".config", "systemd", "user", `${systemdUnitName(profile)}.service`);
|
|
771
602
|
}
|
|
772
603
|
function isServiceInstalled(profile) {
|
|
773
|
-
if (platform() === "darwin") return
|
|
774
|
-
if (platform() === "linux") return
|
|
604
|
+
if (platform() === "darwin") return existsSync2(plistPath(profile));
|
|
605
|
+
if (platform() === "linux") return existsSync2(systemdUnitPath(profile));
|
|
775
606
|
return false;
|
|
776
607
|
}
|
|
777
608
|
function serviceBinaryMissing(file) {
|
|
778
609
|
const bin = serviceBinary(file);
|
|
779
|
-
return !!bin && !
|
|
610
|
+
return !!bin && !existsSync2(bin);
|
|
780
611
|
}
|
|
781
612
|
function serviceBinary(file) {
|
|
782
613
|
let text;
|
|
783
614
|
try {
|
|
784
|
-
text =
|
|
615
|
+
text = readFileSync3(file, "utf-8");
|
|
785
616
|
} catch {
|
|
786
617
|
return void 0;
|
|
787
618
|
}
|
|
@@ -791,7 +622,7 @@ function profileServiceFile(profile) {
|
|
|
791
622
|
return platform() === "darwin" ? plistPath(profile) : systemdUnitPath(profile);
|
|
792
623
|
}
|
|
793
624
|
function hostServiceFile() {
|
|
794
|
-
return platform() === "darwin" ? hostPlistPath() :
|
|
625
|
+
return platform() === "darwin" ? hostPlistPath() : join2(homedir(), ".config", "systemd", "user", `${HOST_SYSTEMD_UNIT}.service`);
|
|
795
626
|
}
|
|
796
627
|
function restartService(profile) {
|
|
797
628
|
const os = platform();
|
|
@@ -821,10 +652,10 @@ function restartService(profile) {
|
|
|
821
652
|
var HOST_SERVICE_LABEL = "ai.flyspace.dashboard";
|
|
822
653
|
var HOST_SYSTEMD_UNIT = "flyspace-host";
|
|
823
654
|
function hostPlistPath() {
|
|
824
|
-
return
|
|
655
|
+
return join2(homedir(), "Library", "LaunchAgents", `${HOST_SERVICE_LABEL}.plist`);
|
|
825
656
|
}
|
|
826
657
|
function isHostServiceInstalled() {
|
|
827
|
-
if (platform() === "darwin" || platform() === "linux") return
|
|
658
|
+
if (platform() === "darwin" || platform() === "linux") return existsSync2(hostServiceFile());
|
|
828
659
|
return false;
|
|
829
660
|
}
|
|
830
661
|
function restartHostService() {
|
|
@@ -864,9 +695,9 @@ function isHostServiceRunning() {
|
|
|
864
695
|
}
|
|
865
696
|
|
|
866
697
|
// src/commands/install.ts
|
|
867
|
-
import { existsSync as
|
|
698
|
+
import { existsSync as existsSync3, mkdirSync as mkdirSync2, readFileSync as readFileSync4, writeFileSync as writeFileSync3, unlinkSync } from "fs";
|
|
868
699
|
import { execSync as execSync2 } from "child_process";
|
|
869
|
-
import { dirname as
|
|
700
|
+
import { dirname as dirname3, join as join3, resolve as resolve2 } from "path";
|
|
870
701
|
import { homedir as homedir2, platform as platform2 } from "os";
|
|
871
702
|
function log(msg) {
|
|
872
703
|
console.log(`
|
|
@@ -889,7 +720,7 @@ function detectAgentBinDirs() {
|
|
|
889
720
|
for (const cli of ["claude", "codex"]) {
|
|
890
721
|
try {
|
|
891
722
|
const p = execSync2(`which ${cli}`, { encoding: "utf-8", stdio: "pipe" }).trim();
|
|
892
|
-
if (p) dirs.add(
|
|
723
|
+
if (p) dirs.add(dirname3(p));
|
|
893
724
|
} catch {
|
|
894
725
|
}
|
|
895
726
|
}
|
|
@@ -897,16 +728,16 @@ function detectAgentBinDirs() {
|
|
|
897
728
|
}
|
|
898
729
|
function detectNodeBinDir() {
|
|
899
730
|
const home2 = flyspaceHome();
|
|
900
|
-
return home2 ?
|
|
731
|
+
return home2 ? join3(home2, "node", "bin") : dirname3(process.execPath);
|
|
901
732
|
}
|
|
902
733
|
function nodeShimDirs() {
|
|
903
|
-
return [
|
|
904
|
-
(d) =>
|
|
734
|
+
return [join3(homedir2(), ".local", "share", "mise", "shims"), join3(homedir2(), ".asdf", "shims")].filter(
|
|
735
|
+
(d) => existsSync3(d)
|
|
905
736
|
);
|
|
906
737
|
}
|
|
907
738
|
function detectCustieBin() {
|
|
908
739
|
const home2 = flyspaceHome();
|
|
909
|
-
if (home2) return
|
|
740
|
+
if (home2) return join3(home2, "bin", "flyspace");
|
|
910
741
|
const argv1 = process.argv[1];
|
|
911
742
|
if (argv1) {
|
|
912
743
|
return resolve2(argv1);
|
|
@@ -918,9 +749,9 @@ function detectCustieBin() {
|
|
|
918
749
|
}
|
|
919
750
|
}
|
|
920
751
|
function readEnvFile() {
|
|
921
|
-
if (!
|
|
752
|
+
if (!existsSync3(paths.CONFIG_FILE)) return {};
|
|
922
753
|
const vars = {};
|
|
923
|
-
for (const line of
|
|
754
|
+
for (const line of readFileSync4(paths.CONFIG_FILE, "utf-8").split("\n")) {
|
|
924
755
|
const trimmed = line.trim();
|
|
925
756
|
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
926
757
|
const eq = trimmed.indexOf("=");
|
|
@@ -964,9 +795,9 @@ async function installMacOS(spec) {
|
|
|
964
795
|
const custieBin = detectCustieBin();
|
|
965
796
|
const agentBinDirs = detectAgentBinDirs();
|
|
966
797
|
const logDir = paths.LOG_DIR;
|
|
967
|
-
|
|
798
|
+
mkdirSync2(logDir, { recursive: true });
|
|
968
799
|
const envVars = spec.env;
|
|
969
|
-
const homebrewBin =
|
|
800
|
+
const homebrewBin = existsSync3("/opt/homebrew/bin") ? "/opt/homebrew/bin" : void 0;
|
|
970
801
|
const pathParts = [
|
|
971
802
|
detectNodeBinDir(),
|
|
972
803
|
...agentBinDirs,
|
|
@@ -1005,14 +836,14 @@ ${Object.entries(envVars).map(([k, v]) => ` <key>${k}</key>
|
|
|
1005
836
|
<true/>
|
|
1006
837
|
|
|
1007
838
|
<key>StandardOutPath</key>
|
|
1008
|
-
<string>${
|
|
839
|
+
<string>${join3(logDir, `${spec.logName}.log`)}</string>
|
|
1009
840
|
|
|
1010
841
|
<key>StandardErrorPath</key>
|
|
1011
|
-
<string>${
|
|
842
|
+
<string>${join3(logDir, `${spec.logName}-error.log`)}</string>
|
|
1012
843
|
</dict>
|
|
1013
844
|
</plist>`;
|
|
1014
845
|
const agentPlistPath = spec.plistPath;
|
|
1015
|
-
|
|
846
|
+
mkdirSync2(dirname3(agentPlistPath), { recursive: true });
|
|
1016
847
|
try {
|
|
1017
848
|
run(`launchctl unload "${agentPlistPath}"`, { silent: true });
|
|
1018
849
|
} catch {
|
|
@@ -1021,7 +852,7 @@ ${Object.entries(envVars).map(([k, v]) => ` <key>${k}</key>
|
|
|
1021
852
|
unlinkSync(agentPlistPath);
|
|
1022
853
|
} catch {
|
|
1023
854
|
}
|
|
1024
|
-
|
|
855
|
+
writeFileSync3(agentPlistPath, plist);
|
|
1025
856
|
run(`launchctl load "${agentPlistPath}"`, { silent: true });
|
|
1026
857
|
success(`LaunchAgent installed and loaded (${spec.label}).`);
|
|
1027
858
|
console.log(` Logs: ${logDir}`);
|
|
@@ -1032,9 +863,9 @@ async function installLinux(spec) {
|
|
|
1032
863
|
const custieBin = detectCustieBin();
|
|
1033
864
|
const agentBinDirs = detectAgentBinDirs();
|
|
1034
865
|
const logDir = paths.LOG_DIR;
|
|
1035
|
-
|
|
866
|
+
mkdirSync2(logDir, { recursive: true });
|
|
1036
867
|
const envLines = Object.entries(spec.env).map(([k, v]) => `Environment="${k}=${v}"`).join("\n");
|
|
1037
|
-
const linuxbrewBin =
|
|
868
|
+
const linuxbrewBin = existsSync3("/home/linuxbrew/.linuxbrew/bin") ? "/home/linuxbrew/.linuxbrew/bin" : void 0;
|
|
1038
869
|
const pathParts = [
|
|
1039
870
|
detectNodeBinDir(),
|
|
1040
871
|
...agentBinDirs,
|
|
@@ -1058,16 +889,16 @@ RestartSec=5
|
|
|
1058
889
|
${envLines}
|
|
1059
890
|
Environment="PATH=${pathParts.join(":")}"
|
|
1060
891
|
|
|
1061
|
-
StandardOutput=append:${
|
|
1062
|
-
StandardError=append:${
|
|
892
|
+
StandardOutput=append:${join3(logDir, `${spec.logName}.log`)}
|
|
893
|
+
StandardError=append:${join3(logDir, `${spec.logName}-error.log`)}
|
|
1063
894
|
|
|
1064
895
|
[Install]
|
|
1065
896
|
WantedBy=default.target
|
|
1066
897
|
`;
|
|
1067
898
|
const unitName = spec.unitName;
|
|
1068
|
-
const unitDir =
|
|
1069
|
-
|
|
1070
|
-
|
|
899
|
+
const unitDir = join3(homedir2(), ".config", "systemd", "user");
|
|
900
|
+
mkdirSync2(unitDir, { recursive: true });
|
|
901
|
+
writeFileSync3(join3(unitDir, `${unitName}.service`), unit);
|
|
1071
902
|
run("systemctl --user daemon-reload", { silent: true });
|
|
1072
903
|
run(`systemctl --user enable --now ${unitName}`, { silent: true });
|
|
1073
904
|
success(`systemd user service installed and started (${unitName}).`);
|
|
@@ -1094,16 +925,16 @@ async function installHostService() {
|
|
|
1094
925
|
}
|
|
1095
926
|
|
|
1096
927
|
// ../api/src/commands/profiles.ts
|
|
1097
|
-
import { existsSync as
|
|
928
|
+
import { existsSync as existsSync4, readdirSync, statSync } from "fs";
|
|
1098
929
|
import { execSync as execSync3 } from "child_process";
|
|
1099
|
-
import { join as
|
|
930
|
+
import { join as join4 } from "path";
|
|
1100
931
|
import { platform as platform3 } from "os";
|
|
1101
932
|
function listProfiles() {
|
|
1102
933
|
const profiles = [];
|
|
1103
|
-
if (
|
|
934
|
+
if (existsSync4(paths.PROFILES_DIR)) {
|
|
1104
935
|
for (const entry of readdirSync(paths.PROFILES_DIR)) {
|
|
1105
936
|
try {
|
|
1106
|
-
if (statSync(
|
|
937
|
+
if (statSync(join4(paths.PROFILES_DIR, entry)).isDirectory()) {
|
|
1107
938
|
profiles.push(entry);
|
|
1108
939
|
}
|
|
1109
940
|
} catch {
|
|
@@ -1132,23 +963,23 @@ import { execFileSync } from "child_process";
|
|
|
1132
963
|
import {
|
|
1133
964
|
closeSync,
|
|
1134
965
|
cpSync,
|
|
1135
|
-
existsSync as
|
|
966
|
+
existsSync as existsSync5,
|
|
1136
967
|
lstatSync,
|
|
1137
|
-
mkdirSync as
|
|
968
|
+
mkdirSync as mkdirSync3,
|
|
1138
969
|
openSync,
|
|
1139
970
|
readdirSync as readdirSync2,
|
|
1140
|
-
readFileSync as
|
|
971
|
+
readFileSync as readFileSync5,
|
|
1141
972
|
readSync,
|
|
1142
973
|
realpathSync as realpathSync2,
|
|
1143
974
|
statSync as statSync2,
|
|
1144
975
|
symlinkSync
|
|
1145
976
|
} from "fs";
|
|
1146
977
|
import { homedir as homedir3 } from "os";
|
|
1147
|
-
import { basename as basename2, join as
|
|
978
|
+
import { basename as basename2, join as join5, resolve as resolve3 } from "path";
|
|
1148
979
|
var MAX_JSONL_HEAD_BYTES = 64 * 1024;
|
|
1149
980
|
var GIT_SCAN_ROOTS = ["Workspaces", "Projects", "code"];
|
|
1150
981
|
function flyspaceRoot() {
|
|
1151
|
-
return process.env["FLYSPACE_ROOT"] ||
|
|
982
|
+
return process.env["FLYSPACE_ROOT"] || join5(homedir3(), "Flyspace");
|
|
1152
983
|
}
|
|
1153
984
|
function onPath(cmd) {
|
|
1154
985
|
try {
|
|
@@ -1159,16 +990,16 @@ function onPath(cmd) {
|
|
|
1159
990
|
}
|
|
1160
991
|
}
|
|
1161
992
|
function claudeDir() {
|
|
1162
|
-
return process.env["CLAUDE_CONFIG_DIR"] ||
|
|
993
|
+
return process.env["CLAUDE_CONFIG_DIR"] || join5(homedir3(), ".claude");
|
|
1163
994
|
}
|
|
1164
995
|
function codexDir() {
|
|
1165
|
-
return process.env["CODEX_HOME"] ||
|
|
996
|
+
return process.env["CODEX_HOME"] || join5(homedir3(), ".codex");
|
|
1166
997
|
}
|
|
1167
998
|
function claudeLoggedIn() {
|
|
1168
999
|
if (["ANTHROPIC_API_KEY", "ANTHROPIC_AUTH_TOKEN", "CLAUDE_CODE_OAUTH_TOKEN"].some((k) => process.env[k])) return true;
|
|
1169
|
-
if (
|
|
1000
|
+
if (existsSync5(join5(claudeDir(), ".credentials.json"))) return true;
|
|
1170
1001
|
try {
|
|
1171
|
-
const raw = JSON.parse(
|
|
1002
|
+
const raw = JSON.parse(readFileSync5(join5(homedir3(), ".claude.json"), "utf-8"));
|
|
1172
1003
|
if (raw.oauthAccount) return true;
|
|
1173
1004
|
} catch {
|
|
1174
1005
|
}
|
|
@@ -1183,7 +1014,7 @@ function claudeLoggedIn() {
|
|
|
1183
1014
|
}
|
|
1184
1015
|
}
|
|
1185
1016
|
function codexLoggedIn() {
|
|
1186
|
-
return !!process.env["OPENAI_API_KEY"] ||
|
|
1017
|
+
return !!process.env["OPENAI_API_KEY"] || existsSync5(join5(codexDir(), "auth.json"));
|
|
1187
1018
|
}
|
|
1188
1019
|
function jsonlFiles(dir, depth) {
|
|
1189
1020
|
const out = [];
|
|
@@ -1194,7 +1025,7 @@ function jsonlFiles(dir, depth) {
|
|
|
1194
1025
|
return out;
|
|
1195
1026
|
}
|
|
1196
1027
|
for (const e of entries) {
|
|
1197
|
-
const full =
|
|
1028
|
+
const full = join5(dir, e.name);
|
|
1198
1029
|
if (e.isDirectory()) {
|
|
1199
1030
|
if (depth > 0) out.push(...jsonlFiles(full, depth - 1));
|
|
1200
1031
|
} else if (e.name.endsWith(".jsonl")) {
|
|
@@ -1231,7 +1062,7 @@ function cwdFromTranscript(file) {
|
|
|
1231
1062
|
}
|
|
1232
1063
|
function codexTrustedPaths() {
|
|
1233
1064
|
try {
|
|
1234
|
-
const toml =
|
|
1065
|
+
const toml = readFileSync5(join5(codexDir(), "config.toml"), "utf-8");
|
|
1235
1066
|
return [...toml.matchAll(/^\[projects\.(?:"([^"]+)"|'([^']+)')\]/gm)].map((m) => m[1] ?? m[2]);
|
|
1236
1067
|
} catch {
|
|
1237
1068
|
return [];
|
|
@@ -1254,7 +1085,7 @@ function gitRepos() {
|
|
|
1254
1085
|
const home2 = homedir3();
|
|
1255
1086
|
const found = [];
|
|
1256
1087
|
for (const rootName of GIT_SCAN_ROOTS) {
|
|
1257
|
-
const root =
|
|
1088
|
+
const root = join5(home2, rootName);
|
|
1258
1089
|
let entries;
|
|
1259
1090
|
try {
|
|
1260
1091
|
entries = readdirSync2(root, { withFileTypes: true });
|
|
@@ -1262,7 +1093,7 @@ function gitRepos() {
|
|
|
1262
1093
|
continue;
|
|
1263
1094
|
}
|
|
1264
1095
|
for (const e of entries) {
|
|
1265
|
-
if (e.isDirectory() &&
|
|
1096
|
+
if (e.isDirectory() && existsSync5(join5(root, e.name, ".git"))) found.push(join5(root, e.name));
|
|
1266
1097
|
}
|
|
1267
1098
|
}
|
|
1268
1099
|
return found;
|
|
@@ -1286,12 +1117,12 @@ function detectRunners(history = { claude: false, codex: false }) {
|
|
|
1286
1117
|
function linkedTargets(slug) {
|
|
1287
1118
|
const out = /* @__PURE__ */ new Map();
|
|
1288
1119
|
if (!SLUG_RE.test(slug)) return out;
|
|
1289
|
-
const dir =
|
|
1120
|
+
const dir = join5(flyspaceRoot(), slug);
|
|
1290
1121
|
try {
|
|
1291
1122
|
for (const e of readdirSync2(dir, { withFileTypes: true })) {
|
|
1292
1123
|
if (!e.isSymbolicLink()) continue;
|
|
1293
1124
|
try {
|
|
1294
|
-
out.set(realpathSync2(
|
|
1125
|
+
out.set(realpathSync2(join5(dir, e.name)), e.name);
|
|
1295
1126
|
} catch {
|
|
1296
1127
|
}
|
|
1297
1128
|
}
|
|
@@ -1322,11 +1153,11 @@ function scanOnboarding(slug) {
|
|
|
1322
1153
|
});
|
|
1323
1154
|
}
|
|
1324
1155
|
};
|
|
1325
|
-
const claudeProjects =
|
|
1156
|
+
const claudeProjects = join5(claudeDir(), "projects");
|
|
1326
1157
|
try {
|
|
1327
1158
|
for (const e of readdirSync2(claudeProjects, { withFileTypes: true })) {
|
|
1328
1159
|
if (!e.isDirectory()) continue;
|
|
1329
|
-
const files = jsonlFiles(
|
|
1160
|
+
const files = jsonlFiles(join5(claudeProjects, e.name), 0);
|
|
1330
1161
|
if (!files.length) continue;
|
|
1331
1162
|
history.claude = true;
|
|
1332
1163
|
files.sort((a, b) => b.mtime - a.mtime);
|
|
@@ -1339,7 +1170,7 @@ function scanOnboarding(slug) {
|
|
|
1339
1170
|
}
|
|
1340
1171
|
} catch {
|
|
1341
1172
|
}
|
|
1342
|
-
const codexSessions = jsonlFiles(
|
|
1173
|
+
const codexSessions = jsonlFiles(join5(codexDir(), "sessions"), 4);
|
|
1343
1174
|
if (codexSessions.length) history.codex = true;
|
|
1344
1175
|
const perCwd = /* @__PURE__ */ new Map();
|
|
1345
1176
|
for (const f of codexSessions) {
|
|
@@ -1388,15 +1219,15 @@ function scanOnboarding(slug) {
|
|
|
1388
1219
|
fromGitScan
|
|
1389
1220
|
};
|
|
1390
1221
|
}
|
|
1391
|
-
var GENERAL_TEMPLATE_DIR =
|
|
1222
|
+
var GENERAL_TEMPLATE_DIR = join5(paths.PACKAGE_ROOT, "templates", "general");
|
|
1392
1223
|
function makeLink(target, linkPath) {
|
|
1393
1224
|
symlinkSync(target, linkPath, process.platform === "win32" ? "junction" : "dir");
|
|
1394
1225
|
}
|
|
1395
1226
|
var SLUG_RE = /^[a-z0-9][a-z0-9-]*$/;
|
|
1396
1227
|
function assertLinkable(target) {
|
|
1397
|
-
const home2 =
|
|
1398
|
-
const root =
|
|
1399
|
-
const denied = [
|
|
1228
|
+
const home2 = existsSync5(homedir3()) ? realpathSync2(homedir3()) : homedir3();
|
|
1229
|
+
const root = existsSync5(flyspaceRoot()) ? realpathSync2(flyspaceRoot()) : flyspaceRoot();
|
|
1230
|
+
const denied = [join5(home2, ".ssh"), join5(home2, "Library"), join5(home2, ".config"), join5(home2, ".gnupg")];
|
|
1400
1231
|
if (target === home2 || target === "/" || target === root || target.startsWith(`${root}/`)) {
|
|
1401
1232
|
throw new Error(`cannot link ${target}`);
|
|
1402
1233
|
}
|
|
@@ -1404,12 +1235,12 @@ function assertLinkable(target) {
|
|
|
1404
1235
|
}
|
|
1405
1236
|
function linkProjectFolders(slug, items2) {
|
|
1406
1237
|
if (!SLUG_RE.test(slug)) throw new Error(`invalid workspace slug: ${slug}`);
|
|
1407
|
-
const dir =
|
|
1408
|
-
|
|
1238
|
+
const dir = join5(flyspaceRoot(), slug);
|
|
1239
|
+
mkdirSync3(dir, { recursive: true });
|
|
1409
1240
|
const results = [];
|
|
1410
1241
|
for (const item of items2) {
|
|
1411
1242
|
if (!SLUG_RE.test(item.name)) throw new Error(`invalid channel name: ${item.name}`);
|
|
1412
|
-
const dest =
|
|
1243
|
+
const dest = join5(dir, item.name);
|
|
1413
1244
|
let exists = true;
|
|
1414
1245
|
try {
|
|
1415
1246
|
lstatSync(dest);
|
|
@@ -1436,7 +1267,7 @@ function linkProjectFolders(slug, items2) {
|
|
|
1436
1267
|
assertLinkable(realpathSync2(target));
|
|
1437
1268
|
makeLink(target, dest);
|
|
1438
1269
|
} else {
|
|
1439
|
-
|
|
1270
|
+
mkdirSync3(dest, { recursive: true });
|
|
1440
1271
|
if (item.name === "general") cpSync(GENERAL_TEMPLATE_DIR, dest, { recursive: true });
|
|
1441
1272
|
}
|
|
1442
1273
|
}
|
|
@@ -1870,8 +1701,8 @@ ${BOLD2}Flyspace Setup${RESET2}
|
|
|
1870
1701
|
const anyReady = runners.some((r) => r.installed && r.loggedIn);
|
|
1871
1702
|
for (const slug of workspaces) {
|
|
1872
1703
|
if (!/^[a-z0-9][a-z0-9-]*$/.test(slug)) continue;
|
|
1873
|
-
const dir =
|
|
1874
|
-
|
|
1704
|
+
const dir = join6(flyspaceRoot(), slug);
|
|
1705
|
+
mkdirSync4(dir, { recursive: true });
|
|
1875
1706
|
ok(`Folder ${tilde2(dir)}`);
|
|
1876
1707
|
}
|
|
1877
1708
|
let hostRunning = false;
|
|
@@ -1910,8 +1741,8 @@ ${BOLD2}Flyspace Setup${RESET2}
|
|
|
1910
1741
|
|
|
1911
1742
|
// src/commands/doctor.ts
|
|
1912
1743
|
import { execFile } from "child_process";
|
|
1913
|
-
import { existsSync as
|
|
1914
|
-
import { join as
|
|
1744
|
+
import { existsSync as existsSync6, readFileSync as readFileSync6 } from "fs";
|
|
1745
|
+
import { join as join7 } from "path";
|
|
1915
1746
|
import { parse as parseEnv } from "dotenv";
|
|
1916
1747
|
import { tmpdir } from "os";
|
|
1917
1748
|
import { promisify } from "util";
|
|
@@ -1978,12 +1809,12 @@ async function probe(id) {
|
|
|
1978
1809
|
}
|
|
1979
1810
|
async function probeProfilesClaude(workspaces) {
|
|
1980
1811
|
for (const name of workspaces) {
|
|
1981
|
-
const file =
|
|
1982
|
-
const env =
|
|
1812
|
+
const file = join7(paths.PROFILES_DIR, name, "config.env");
|
|
1813
|
+
const env = existsSync6(file) ? parseEnv(readFileSync6(file, "utf-8")) : {};
|
|
1983
1814
|
const token = env["CLAUDE_CODE_OAUTH_TOKEN"];
|
|
1984
1815
|
const configDir2 = env["CLAUDE_CONFIG_DIR"];
|
|
1985
1816
|
const plist = profileServiceFile(name);
|
|
1986
|
-
if (!token &&
|
|
1817
|
+
if (!token && existsSync6(plist) && readFileSync6(plist, "utf-8").includes("CLAUDE_CODE_OAUTH_TOKEN"))
|
|
1987
1818
|
bad2(
|
|
1988
1819
|
`${name}: CLAUDE_CODE_OAUTH_TOKEN is set in ${tilde3(plist)} but not in ${tilde3(file)}; the dashboard ignores the plist`,
|
|
1989
1820
|
`move the token into ${tilde3(file)}, then restart the dashboard service`
|
|
@@ -2086,10 +1917,10 @@ ${BOLD3}Flyspace Doctor${RESET3}
|
|
|
2086
1917
|
}
|
|
2087
1918
|
|
|
2088
1919
|
// src/commands/uninstall.ts
|
|
2089
|
-
import { existsSync as
|
|
1920
|
+
import { existsSync as existsSync7, mkdirSync as mkdirSync5, readFileSync as readFileSync7, rmSync as rmSync2, unlinkSync as unlinkSync2, writeFileSync as writeFileSync4 } from "fs";
|
|
2090
1921
|
import { confirm as confirm3 } from "@inquirer/prompts";
|
|
2091
1922
|
import { execSync as execSync5 } from "child_process";
|
|
2092
|
-
import { basename as basename3, join as
|
|
1923
|
+
import { basename as basename3, join as join8 } from "path";
|
|
2093
1924
|
import { homedir as homedir4, platform as platform5 } from "os";
|
|
2094
1925
|
function log2(msg) {
|
|
2095
1926
|
console.log(`
|
|
@@ -2110,7 +1941,7 @@ async function runServiceUninstall(profile = getProfile()) {
|
|
|
2110
1941
|
if (os === "darwin") {
|
|
2111
1942
|
const removed = [];
|
|
2112
1943
|
for (const plist of [plistPath(profile), legacyPlistPath(profile)]) {
|
|
2113
|
-
if (!
|
|
1944
|
+
if (!existsSync7(plist)) continue;
|
|
2114
1945
|
try {
|
|
2115
1946
|
run2(`launchctl unload "${plist}"`);
|
|
2116
1947
|
} catch {
|
|
@@ -2132,7 +1963,7 @@ async function runServiceUninstall(profile = getProfile()) {
|
|
|
2132
1963
|
run2(`systemctl --user disable --now ${unitName}`);
|
|
2133
1964
|
} catch {
|
|
2134
1965
|
}
|
|
2135
|
-
const unitPath =
|
|
1966
|
+
const unitPath = join8(homedir4(), ".config", "systemd", "user", `${unitName}.service`);
|
|
2136
1967
|
try {
|
|
2137
1968
|
unlinkSync2(unitPath);
|
|
2138
1969
|
} catch {
|
|
@@ -2147,13 +1978,13 @@ async function runServiceUninstall(profile = getProfile()) {
|
|
|
2147
1978
|
}
|
|
2148
1979
|
}
|
|
2149
1980
|
async function runUninstall(args = []) {
|
|
2150
|
-
const prefix = process.env["FLYSPACE_PREFIX"] ||
|
|
2151
|
-
const targets = [paths.BASE_CONFIG_DIR, paths.BASE_DATA_DIR, prefix].filter(
|
|
1981
|
+
const prefix = process.env["FLYSPACE_PREFIX"] || join8(homedir4(), ".flyspace");
|
|
1982
|
+
const targets = [paths.BASE_CONFIG_DIR, paths.BASE_DATA_DIR, prefix].filter(existsSync7);
|
|
2152
1983
|
console.log("\n This removes Flyspace from this machine:");
|
|
2153
1984
|
console.log(" - revokes this device and removes every background service");
|
|
2154
1985
|
for (const t of targets) console.log(` - deletes ${t}`);
|
|
2155
1986
|
console.log(" Your channel folders (~/Flyspace) are kept.\n");
|
|
2156
|
-
const backupSources = [paths.BASE_CONFIG_DIR, paths.BASE_DATA_DIR].filter(
|
|
1987
|
+
const backupSources = [paths.BASE_CONFIG_DIR, paths.BASE_DATA_DIR].filter(existsSync7);
|
|
2157
1988
|
const interactive = !args.includes("--yes") && !args.includes("-y");
|
|
2158
1989
|
let backup = !args.includes("--no-backup") && backupSources.length > 0;
|
|
2159
1990
|
if (interactive) {
|
|
@@ -2165,10 +1996,10 @@ async function runUninstall(args = []) {
|
|
|
2165
1996
|
}
|
|
2166
1997
|
let backupFile;
|
|
2167
1998
|
if (backup) {
|
|
2168
|
-
const dir =
|
|
2169
|
-
|
|
1999
|
+
const dir = join8(homedir4(), "Flyspace", ".uninstall-backups");
|
|
2000
|
+
mkdirSync5(dir, { recursive: true });
|
|
2170
2001
|
const stamp2 = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
2171
|
-
backupFile =
|
|
2002
|
+
backupFile = join8(dir, `flyspace-${stamp2}.tar.gz`);
|
|
2172
2003
|
const rel = backupSources.map((s) => `"${s.replace(/^\//, "")}"`).join(" ");
|
|
2173
2004
|
try {
|
|
2174
2005
|
run2(`tar -czf "${backupFile}" -C / ${rel}`);
|
|
@@ -2192,18 +2023,18 @@ async function runUninstall(args = []) {
|
|
|
2192
2023
|
await runServiceUninstall(profile);
|
|
2193
2024
|
}
|
|
2194
2025
|
for (const t of targets) {
|
|
2195
|
-
|
|
2026
|
+
rmSync2(t, { recursive: true, force: true });
|
|
2196
2027
|
success2(`Deleted ${t}`);
|
|
2197
2028
|
}
|
|
2198
|
-
for (const rc of [".zshrc", ".bashrc", ".profile"].map((f) =>
|
|
2199
|
-
if (!
|
|
2200
|
-
const before =
|
|
2029
|
+
for (const rc of [".zshrc", ".bashrc", ".profile"].map((f) => join8(homedir4(), f))) {
|
|
2030
|
+
if (!existsSync7(rc)) continue;
|
|
2031
|
+
const before = readFileSync7(rc, "utf-8");
|
|
2201
2032
|
const after = before.replace(
|
|
2202
2033
|
/\n# Flyspace CLI\nexport PATH="[^"\n]*\.flyspace\/bin:\$PATH"\n?/g,
|
|
2203
2034
|
"\n"
|
|
2204
2035
|
);
|
|
2205
2036
|
if (after !== before) {
|
|
2206
|
-
|
|
2037
|
+
writeFileSync4(rc, after);
|
|
2207
2038
|
success2(`Removed PATH entry from ${rc}`);
|
|
2208
2039
|
}
|
|
2209
2040
|
}
|
|
@@ -2218,7 +2049,7 @@ async function runUninstall(args = []) {
|
|
|
2218
2049
|
}
|
|
2219
2050
|
|
|
2220
2051
|
// src/commands/profiles-cmd.ts
|
|
2221
|
-
import { rmSync as
|
|
2052
|
+
import { rmSync as rmSync3 } from "fs";
|
|
2222
2053
|
var USAGE = `
|
|
2223
2054
|
Usage: flyspace profiles [list]
|
|
2224
2055
|
flyspace profiles remove <name>
|
|
@@ -2275,7 +2106,7 @@ async function removeCmd(name) {
|
|
|
2275
2106
|
}
|
|
2276
2107
|
const { configDir: configDir2, dataDir } = runWithProfile(name, () => ({ configDir: paths.CONFIG_DIR, dataDir: paths.DATA_DIR }));
|
|
2277
2108
|
if (isServiceInstalled(name)) await runWithProfile(name, runUninstall);
|
|
2278
|
-
|
|
2109
|
+
rmSync3(configDir2, { recursive: true, force: true });
|
|
2279
2110
|
console.log(`\x1B[32m+\x1B[0m Local config removed: ${configDir2}`);
|
|
2280
2111
|
console.log(`
|
|
2281
2112
|
Kept: ${dataDir} (sessions, logs) and any ~/Flyspace/${name}/ channel folders.`);
|
|
@@ -2292,8 +2123,8 @@ async function runProfiles(args = []) {
|
|
|
2292
2123
|
|
|
2293
2124
|
// src/commands/upgrade.ts
|
|
2294
2125
|
import { execSync as execSync6 } from "child_process";
|
|
2295
|
-
import { existsSync as
|
|
2296
|
-
import { dirname as
|
|
2126
|
+
import { existsSync as existsSync8, readFileSync as readFileSync8, realpathSync as realpathSync3 } from "fs";
|
|
2127
|
+
import { dirname as dirname4, join as join9 } from "path";
|
|
2297
2128
|
function restartInstalledProfiles() {
|
|
2298
2129
|
if (isHostServiceInstalled()) {
|
|
2299
2130
|
console.log(restartHostService() ? "\nHost restarted." : "\nHost restart failed; run: flyspace setup --start-host --restart");
|
|
@@ -2314,19 +2145,19 @@ Restarting ${installed.length} instance(s)...`);
|
|
|
2314
2145
|
}
|
|
2315
2146
|
}
|
|
2316
2147
|
function installTarget(entry) {
|
|
2317
|
-
const home2 = flyspaceHome(entry) ?? (entry.endsWith("/bin/flyspace") ?
|
|
2318
|
-
if (home2 &&
|
|
2319
|
-
return { prefix:
|
|
2148
|
+
const home2 = flyspaceHome(entry) ?? (entry.endsWith("/bin/flyspace") ? dirname4(dirname4(entry)) : void 0);
|
|
2149
|
+
if (home2 && existsSync8(join9(home2, "cli", "lib", "node_modules", "flyspace-cli"))) {
|
|
2150
|
+
return { prefix: join9(home2, "cli"), nodeBin: join9(home2, "node", "bin") };
|
|
2320
2151
|
}
|
|
2321
2152
|
try {
|
|
2322
2153
|
const real = realpathSync3(entry);
|
|
2323
2154
|
const at = real.indexOf(`/lib/node_modules/${"flyspace-cli"}/`);
|
|
2324
|
-
if (at > 0) return { prefix: real.slice(0, at), nodeBin:
|
|
2155
|
+
if (at > 0) return { prefix: real.slice(0, at), nodeBin: join9(real.slice(0, at), "bin") };
|
|
2325
2156
|
} catch {
|
|
2326
2157
|
}
|
|
2327
|
-
const prefix = entry.endsWith("/bin/flyspace") ?
|
|
2328
|
-
if (prefix &&
|
|
2329
|
-
return { prefix, nodeBin:
|
|
2158
|
+
const prefix = entry.endsWith("/bin/flyspace") ? dirname4(dirname4(entry)) : void 0;
|
|
2159
|
+
if (prefix && existsSync8(join9(prefix, "lib", "node_modules", "flyspace-cli"))) {
|
|
2160
|
+
return { prefix, nodeBin: join9(prefix, "bin") };
|
|
2330
2161
|
}
|
|
2331
2162
|
return void 0;
|
|
2332
2163
|
}
|
|
@@ -2344,8 +2175,8 @@ function installTargets() {
|
|
|
2344
2175
|
}
|
|
2345
2176
|
function installedVersion(target) {
|
|
2346
2177
|
try {
|
|
2347
|
-
const pkg =
|
|
2348
|
-
return JSON.parse(
|
|
2178
|
+
const pkg = join9(target.prefix, "lib", "node_modules", "flyspace-cli", "package.json");
|
|
2179
|
+
return JSON.parse(readFileSync8(pkg, "utf-8")).version;
|
|
2349
2180
|
} catch {
|
|
2350
2181
|
return void 0;
|
|
2351
2182
|
}
|
|
@@ -2356,11 +2187,11 @@ function npmInstallCommand(target) {
|
|
|
2356
2187
|
}
|
|
2357
2188
|
function npmEnv(target) {
|
|
2358
2189
|
const home2 = flyspaceHome();
|
|
2359
|
-
const nodeBin = target?.nodeBin ?? (home2 ?
|
|
2190
|
+
const nodeBin = target?.nodeBin ?? (home2 ? join9(home2, "node", "bin") : void 0);
|
|
2360
2191
|
return nodeBin ? { ...process.env, PATH: `${nodeBin}:${process.env.PATH ?? ""}` } : process.env;
|
|
2361
2192
|
}
|
|
2362
2193
|
async function runUpgrade() {
|
|
2363
|
-
const current = "0.1.
|
|
2194
|
+
const current = "0.1.58";
|
|
2364
2195
|
console.log(`Current version: ${current}`);
|
|
2365
2196
|
console.log("Checking for updates...\n");
|
|
2366
2197
|
try {
|
|
@@ -2403,13 +2234,13 @@ You can upgrade manually with: ${npmInstallCommand()}`);
|
|
|
2403
2234
|
import { WebClient } from "@slack/web-api";
|
|
2404
2235
|
|
|
2405
2236
|
// src/automations/config-file.ts
|
|
2406
|
-
import { readFileSync as
|
|
2237
|
+
import { readFileSync as readFileSync9, existsSync as existsSync9 } from "fs";
|
|
2407
2238
|
import yaml from "js-yaml";
|
|
2408
2239
|
var EMPTY_CONFIG = { schedules: [], triggers: [], mention_triggers: [] };
|
|
2409
2240
|
function loadAutomationsFile() {
|
|
2410
2241
|
const filePath = paths.AUTOMATIONS_FILE;
|
|
2411
|
-
if (!
|
|
2412
|
-
const raw =
|
|
2242
|
+
if (!existsSync9(filePath)) return { ...EMPTY_CONFIG };
|
|
2243
|
+
const raw = readFileSync9(filePath, "utf-8");
|
|
2413
2244
|
if (!raw.trim()) return { ...EMPTY_CONFIG };
|
|
2414
2245
|
const parsed = yaml.load(raw);
|
|
2415
2246
|
return {
|
|
@@ -2420,7 +2251,7 @@ function loadAutomationsFile() {
|
|
|
2420
2251
|
}
|
|
2421
2252
|
|
|
2422
2253
|
// src/commands/automation.ts
|
|
2423
|
-
import { readFileSync as
|
|
2254
|
+
import { readFileSync as readFileSync10 } from "fs";
|
|
2424
2255
|
var USAGE2 = `
|
|
2425
2256
|
Usage: flyspace automation <subcommand> [options]
|
|
2426
2257
|
|
|
@@ -2708,7 +2539,7 @@ async function handleEdit(manager, name, args) {
|
|
|
2708
2539
|
console.error(`"${name}" runs a script, not a prompt.`);
|
|
2709
2540
|
process.exit(1);
|
|
2710
2541
|
}
|
|
2711
|
-
const prompt = inline ??
|
|
2542
|
+
const prompt = inline ?? readFileSync10(file, "utf8");
|
|
2712
2543
|
if (!prompt.trim()) {
|
|
2713
2544
|
console.error("Prompt must not be empty.");
|
|
2714
2545
|
process.exit(1);
|
|
@@ -2820,7 +2651,7 @@ async function runAutomationCmd(args) {
|
|
|
2820
2651
|
}
|
|
2821
2652
|
|
|
2822
2653
|
// src/commands/usage.ts
|
|
2823
|
-
import { existsSync as
|
|
2654
|
+
import { existsSync as existsSync10 } from "fs";
|
|
2824
2655
|
var HELP4 = `
|
|
2825
2656
|
Usage: flyspace usage [options]
|
|
2826
2657
|
|
|
@@ -2947,7 +2778,7 @@ async function runUsage(args) {
|
|
|
2947
2778
|
return;
|
|
2948
2779
|
}
|
|
2949
2780
|
const { days, by, explain, json } = parsed;
|
|
2950
|
-
if (!
|
|
2781
|
+
if (!existsSync10(paths.DB_FILE)) {
|
|
2951
2782
|
console.log("No usage recorded yet (the database does not exist).");
|
|
2952
2783
|
return;
|
|
2953
2784
|
}
|
|
@@ -3062,17 +2893,17 @@ async function runRestart() {
|
|
|
3062
2893
|
|
|
3063
2894
|
// src/commands/logs.ts
|
|
3064
2895
|
import { spawn as spawn3 } from "child_process";
|
|
3065
|
-
import { existsSync as
|
|
3066
|
-
import { join as
|
|
2896
|
+
import { existsSync as existsSync11 } from "fs";
|
|
2897
|
+
import { join as join10 } from "path";
|
|
3067
2898
|
function serviceLogFile(errors) {
|
|
3068
2899
|
const suffix = errors ? "-error.log" : ".log";
|
|
3069
|
-
const candidates = ["host", "custie"].map((name) =>
|
|
3070
|
-
return candidates.find((file) =>
|
|
2900
|
+
const candidates = ["host", "custie"].map((name) => join10(paths.LOG_DIR, `${name}${suffix}`));
|
|
2901
|
+
return candidates.find((file) => existsSync11(file)) ?? candidates[0];
|
|
3071
2902
|
}
|
|
3072
2903
|
async function runLogs(args) {
|
|
3073
2904
|
const showErrors = args.includes("--error") || args.includes("-e");
|
|
3074
2905
|
const logFile = serviceLogFile(showErrors);
|
|
3075
|
-
if (!
|
|
2906
|
+
if (!existsSync11(logFile)) {
|
|
3076
2907
|
console.error(`Log file not found: ${logFile}`);
|
|
3077
2908
|
console.error("Is the service installed? Run `flyspace install` first.");
|
|
3078
2909
|
process.exit(1);
|
|
@@ -3093,7 +2924,7 @@ async function runLogs(args) {
|
|
|
3093
2924
|
|
|
3094
2925
|
// src/commands/slack.ts
|
|
3095
2926
|
import { execFileSync as execFileSync3 } from "child_process";
|
|
3096
|
-
import { existsSync as
|
|
2927
|
+
import { existsSync as existsSync12, readFileSync as readFileSync11, writeFileSync as writeFileSync5 } from "fs";
|
|
3097
2928
|
import { resolve as resolve4 } from "path";
|
|
3098
2929
|
import { tmpdir as tmpdir2, homedir as homedir5 } from "os";
|
|
3099
2930
|
import { input, confirm as confirm4, select, checkbox } from "@inquirer/prompts";
|
|
@@ -5065,7 +4896,7 @@ async function threadReplies(client2, nameOrId, ts2) {
|
|
|
5065
4896
|
async function postMessage(client2, args) {
|
|
5066
4897
|
const channelArg = getArg2(args, "--channel");
|
|
5067
4898
|
const textFilePath = getArg2(args, "--text-file");
|
|
5068
|
-
const text = textFilePath ?
|
|
4899
|
+
const text = textFilePath ? readFileSync11(textFilePath, "utf8") : getArg2(args, "--text");
|
|
5069
4900
|
const threadTs = getArg2(args, "--thread");
|
|
5070
4901
|
const markdown = args.includes("--markdown");
|
|
5071
4902
|
const broadcast = args.includes("--broadcast") && Boolean(threadTs);
|
|
@@ -5163,7 +4994,7 @@ function defaultClaudeConfigDir() {
|
|
|
5163
4994
|
return process.env.CLAUDE_CONFIG_DIR || resolve4(homedir5(), ".claude");
|
|
5164
4995
|
}
|
|
5165
4996
|
function hasClaudeCredentials(configDir2) {
|
|
5166
|
-
if (
|
|
4997
|
+
if (existsSync12(resolve4(configDir2, ".credentials.json"))) {
|
|
5167
4998
|
return true;
|
|
5168
4999
|
}
|
|
5169
5000
|
if (process.platform === "darwin") {
|
|
@@ -5220,7 +5051,7 @@ async function ensureClaudeCodeReady() {
|
|
|
5220
5051
|
}
|
|
5221
5052
|
function getManifestYaml(botName) {
|
|
5222
5053
|
const manifestPath = resolve4(paths.PACKAGE_ROOT, "slack-app-manifest.yml");
|
|
5223
|
-
const raw =
|
|
5054
|
+
const raw = readFileSync11(manifestPath, "utf-8");
|
|
5224
5055
|
return raw.replace(/name: Custie/g, `name: ${botName}`);
|
|
5225
5056
|
}
|
|
5226
5057
|
async function stepPersonalise() {
|
|
@@ -5637,7 +5468,7 @@ function writeConfigFile(config) {
|
|
|
5637
5468
|
`OWNER_USER_ID=${config.ownerUserId}`,
|
|
5638
5469
|
``
|
|
5639
5470
|
].join("\n");
|
|
5640
|
-
|
|
5471
|
+
writeFileSync5(paths.CONFIG_FILE, envContent);
|
|
5641
5472
|
success4(`Config written to ${paths.CONFIG_FILE}`);
|
|
5642
5473
|
}
|
|
5643
5474
|
function printNextSteps() {
|
|
@@ -5649,11 +5480,11 @@ function printNextSteps() {
|
|
|
5649
5480
|
console.log(" Run \x1B[1mflyspace service install\x1B[0m\n");
|
|
5650
5481
|
}
|
|
5651
5482
|
function copyDefaultPrompt(botName) {
|
|
5652
|
-
if (!
|
|
5483
|
+
if (!existsSync12(paths.PROMPT_FILE)) {
|
|
5653
5484
|
const defaultPrompt = resolve4(paths.PACKAGE_ROOT, "system.default.md");
|
|
5654
|
-
if (
|
|
5655
|
-
const content =
|
|
5656
|
-
|
|
5485
|
+
if (existsSync12(defaultPrompt)) {
|
|
5486
|
+
const content = readFileSync11(defaultPrompt, "utf-8").replace(/\{\{botName\}\}/g, botName);
|
|
5487
|
+
writeFileSync5(paths.PROMPT_FILE, content);
|
|
5657
5488
|
success4(`Default prompt copied to ${paths.PROMPT_FILE}`);
|
|
5658
5489
|
}
|
|
5659
5490
|
}
|
|
@@ -5665,7 +5496,7 @@ async function runSlackSetup(args) {
|
|
|
5665
5496
|
const prereq = await ensureClaudeCodeReady();
|
|
5666
5497
|
if (!prereq) return;
|
|
5667
5498
|
const { claudeConfigDir } = prereq;
|
|
5668
|
-
if (
|
|
5499
|
+
if (existsSync12(paths.CONFIG_FILE)) {
|
|
5669
5500
|
const reconfigure = await confirm4({
|
|
5670
5501
|
message: `Config already exists at ${paths.CONFIG_FILE}. Reconfigure?`,
|
|
5671
5502
|
default: false
|
|
@@ -6026,21 +5857,21 @@ async function runChatCmd(args) {
|
|
|
6026
5857
|
}
|
|
6027
5858
|
|
|
6028
5859
|
// src/commands/memory.ts
|
|
6029
|
-
import { readFileSync as
|
|
5860
|
+
import { readFileSync as readFileSync13 } from "fs";
|
|
6030
5861
|
|
|
6031
5862
|
// src/store/claude-memory-import.ts
|
|
6032
|
-
import { existsSync as
|
|
5863
|
+
import { existsSync as existsSync13, readdirSync as readdirSync3, readFileSync as readFileSync12 } from "fs";
|
|
6033
5864
|
import { homedir as homedir6 } from "os";
|
|
6034
|
-
import { basename as basename5, join as
|
|
5865
|
+
import { basename as basename5, join as join11 } from "path";
|
|
6035
5866
|
import dotenv from "dotenv";
|
|
6036
5867
|
function claudeMemoryDir(cwd, configDir2) {
|
|
6037
|
-
return
|
|
5868
|
+
return join11(configDir2, "projects", cwd.replaceAll(/[^a-zA-Z0-9]/g, "-"), "memory");
|
|
6038
5869
|
}
|
|
6039
5870
|
function profileClaudeConfigDirFor(profile) {
|
|
6040
|
-
const dir = profile === "default" ? paths.BASE_CONFIG_DIR :
|
|
6041
|
-
const file =
|
|
6042
|
-
const env =
|
|
6043
|
-
return env["CLAUDE_CONFIG_DIR"]?.trim() ||
|
|
5871
|
+
const dir = profile === "default" ? paths.BASE_CONFIG_DIR : join11(paths.PROFILES_DIR, profile);
|
|
5872
|
+
const file = join11(dir, "config.env");
|
|
5873
|
+
const env = existsSync13(file) ? dotenv.parse(readFileSync12(file)) : {};
|
|
5874
|
+
return env["CLAUDE_CONFIG_DIR"]?.trim() || join11(homedir6(), ".claude");
|
|
6044
5875
|
}
|
|
6045
5876
|
var TYPE_MAP = {
|
|
6046
5877
|
user: "preference",
|
|
@@ -6085,11 +5916,11 @@ function parseClaudeMemory(fileName, text, channelId) {
|
|
|
6085
5916
|
return input2;
|
|
6086
5917
|
}
|
|
6087
5918
|
async function importClaudeMemories(dir, channelId, opts = {}) {
|
|
6088
|
-
if (!
|
|
5919
|
+
if (!existsSync13(dir)) throw new Error(`No Claude memory directory at ${dir}`);
|
|
6089
5920
|
const files = readdirSync3(dir).filter((f) => f.endsWith(".md") && f !== "MEMORY.md").sort();
|
|
6090
5921
|
const results = [];
|
|
6091
5922
|
for (const file of files) {
|
|
6092
|
-
const parsed = parseClaudeMemory(file,
|
|
5923
|
+
const parsed = parseClaudeMemory(file, readFileSync12(join11(dir, file), "utf-8"), channelId);
|
|
6093
5924
|
if ("skip" in parsed) {
|
|
6094
5925
|
results.push({ file, outcome: "skipped", reason: parsed.skip });
|
|
6095
5926
|
continue;
|
|
@@ -6201,7 +6032,7 @@ ${memory.body}`);
|
|
|
6201
6032
|
);
|
|
6202
6033
|
}
|
|
6203
6034
|
if (!isMemoryType(type)) throw new Error(`--type must be one of ${MEMORY_TYPES.join(", ")}`);
|
|
6204
|
-
const body = bodyArg === "-" ?
|
|
6035
|
+
const body = bodyArg === "-" ? readFileSync13(0, "utf-8") : bodyArg;
|
|
6205
6036
|
const thread = getArg4(rest, "--thread");
|
|
6206
6037
|
const { created, changed } = await saveMemory(
|
|
6207
6038
|
target,
|
|
@@ -6301,12 +6132,12 @@ async function runMcpCmd(args) {
|
|
|
6301
6132
|
|
|
6302
6133
|
// src/commands/dashboard.ts
|
|
6303
6134
|
import { spawn as spawn6, spawnSync } from "child_process";
|
|
6304
|
-
import { existsSync as
|
|
6135
|
+
import { existsSync as existsSync27 } from "fs";
|
|
6305
6136
|
import { platform as platform7 } from "os";
|
|
6306
|
-
import { join as
|
|
6137
|
+
import { join as join19 } from "path";
|
|
6307
6138
|
|
|
6308
6139
|
// src/reconcile.ts
|
|
6309
|
-
import { existsSync as
|
|
6140
|
+
import { existsSync as existsSync14, mkdirSync as mkdirSync6, writeFileSync as writeFileSync6 } from "fs";
|
|
6310
6141
|
async function boundWorkspaces2() {
|
|
6311
6142
|
return (await boundWorkspaces())?.workspaces ?? null;
|
|
6312
6143
|
}
|
|
@@ -6317,13 +6148,13 @@ async function servedWorkspaces2() {
|
|
|
6317
6148
|
async function reconcileProfile(profile) {
|
|
6318
6149
|
return runWithProfile(profile, async () => {
|
|
6319
6150
|
const log5 = [];
|
|
6320
|
-
const hadConfigDir =
|
|
6321
|
-
const hadDataDir =
|
|
6151
|
+
const hadConfigDir = existsSync14(paths.CONFIG_DIR);
|
|
6152
|
+
const hadDataDir = existsSync14(paths.DATA_DIR);
|
|
6322
6153
|
ensureDirs();
|
|
6323
6154
|
if (!hadConfigDir) log5.push(`config dir created (${paths.CONFIG_DIR})`);
|
|
6324
6155
|
if (!hadDataDir) log5.push(`data dir created (${paths.DATA_DIR})`);
|
|
6325
|
-
if (!
|
|
6326
|
-
|
|
6156
|
+
if (!existsSync14(paths.CONFIG_FILE)) {
|
|
6157
|
+
writeFileSync6(paths.CONFIG_FILE, `BOT_NAME=${profile}
|
|
6327
6158
|
`);
|
|
6328
6159
|
log5.push(`config.env written (${paths.CONFIG_FILE})`);
|
|
6329
6160
|
}
|
|
@@ -6332,7 +6163,7 @@ async function reconcileProfile(profile) {
|
|
|
6332
6163
|
if (!channel.cwd) continue;
|
|
6333
6164
|
const cwd = expandPath(channel.cwd);
|
|
6334
6165
|
if (isCwdUsable(cwd)) continue;
|
|
6335
|
-
|
|
6166
|
+
mkdirSync6(cwd, { recursive: true });
|
|
6336
6167
|
log5.push(`channel "${channel.name}" cwd created (${cwd})`);
|
|
6337
6168
|
}
|
|
6338
6169
|
return log5;
|
|
@@ -6479,7 +6310,7 @@ async function verifyTurnstileToken(token) {
|
|
|
6479
6310
|
import { Hono as Hono6 } from "hono";
|
|
6480
6311
|
|
|
6481
6312
|
// ../api/src/store/device-store.ts
|
|
6482
|
-
import { createHash as createHash2, createPublicKey
|
|
6313
|
+
import { createHash as createHash2, createPublicKey, randomBytes as randomBytes3, randomInt } from "crypto";
|
|
6483
6314
|
var DEVICE_CODE_TTL_MS = 10 * 6e4;
|
|
6484
6315
|
var ACCESS_TOKEN_TTL_MS = 15 * 6e4;
|
|
6485
6316
|
var CHALLENGE_TTL_MS = 2 * 6e4;
|
|
@@ -6488,7 +6319,7 @@ var sha256 = (s) => createHash2("sha256").update(s).digest("hex");
|
|
|
6488
6319
|
function parseEd25519PublicKey(b64) {
|
|
6489
6320
|
if (typeof b64 !== "string" || b64.length > 200) return null;
|
|
6490
6321
|
try {
|
|
6491
|
-
const key =
|
|
6322
|
+
const key = createPublicKey({ key: Buffer.from(b64, "base64"), format: "der", type: "spki" });
|
|
6492
6323
|
return key.asymmetricKeyType === "ed25519" ? key : null;
|
|
6493
6324
|
} catch {
|
|
6494
6325
|
return null;
|
|
@@ -6709,19 +6540,19 @@ import { randomBytes as randomBytes4, randomUUID as randomUUID2, verify as verif
|
|
|
6709
6540
|
import { WebSocket, WebSocketServer } from "ws";
|
|
6710
6541
|
|
|
6711
6542
|
// ../api/src/dashboard/host-identity.ts
|
|
6712
|
-
import { createPrivateKey
|
|
6713
|
-
import { existsSync as
|
|
6714
|
-
import { dirname as
|
|
6543
|
+
import { createPrivateKey, createPublicKey as createPublicKey2, generateKeyPairSync } from "crypto";
|
|
6544
|
+
import { existsSync as existsSync15, mkdirSync as mkdirSync7, readFileSync as readFileSync14, writeFileSync as writeFileSync7 } from "fs";
|
|
6545
|
+
import { dirname as dirname5, join as join12 } from "path";
|
|
6715
6546
|
function hostPrivateKeyPath() {
|
|
6716
|
-
return process.env["FLYSPACE_HOST_KEY_PATH"] ||
|
|
6547
|
+
return process.env["FLYSPACE_HOST_KEY_PATH"] || join12(paths.BASE_CONFIG_DIR, "host.key");
|
|
6717
6548
|
}
|
|
6718
6549
|
function loadHostPrivateKey(path = hostPrivateKeyPath()) {
|
|
6719
|
-
if (!
|
|
6550
|
+
if (!existsSync15(path)) {
|
|
6720
6551
|
throw new Error(
|
|
6721
6552
|
`No Host identity at ${path}. Run \`pnpm run generate-host-key\` on this machine, then set FLYSPACE_HOST_PUBLIC_KEY on the Data process to the printed public key.`
|
|
6722
6553
|
);
|
|
6723
6554
|
}
|
|
6724
|
-
return
|
|
6555
|
+
return createPrivateKey(readFileSync14(path, "utf8"));
|
|
6725
6556
|
}
|
|
6726
6557
|
|
|
6727
6558
|
// ../api/src/dashboard/uploads-routes.ts
|
|
@@ -7538,7 +7369,7 @@ function createAdminRouter() {
|
|
|
7538
7369
|
}
|
|
7539
7370
|
|
|
7540
7371
|
// ../api/src/dashboard/data-api.ts
|
|
7541
|
-
import { existsSync as
|
|
7372
|
+
import { existsSync as existsSync17 } from "fs";
|
|
7542
7373
|
import sharp4 from "sharp";
|
|
7543
7374
|
|
|
7544
7375
|
// ../api/src/dashboard/automations-routes.ts
|
|
@@ -11450,7 +11281,7 @@ async function threadRuns(workspace, threadTs) {
|
|
|
11450
11281
|
}
|
|
11451
11282
|
|
|
11452
11283
|
// ../api/src/dashboard/usage-report.ts
|
|
11453
|
-
import { existsSync as
|
|
11284
|
+
import { existsSync as existsSync16 } from "fs";
|
|
11454
11285
|
function mergeByLabel(buckets) {
|
|
11455
11286
|
const merged = /* @__PURE__ */ new Map();
|
|
11456
11287
|
for (const bucket of buckets) {
|
|
@@ -11496,7 +11327,7 @@ function toReport(days, rows, labelChannel) {
|
|
|
11496
11327
|
};
|
|
11497
11328
|
}
|
|
11498
11329
|
function fromLocalStore(days, labelChannel) {
|
|
11499
|
-
const store =
|
|
11330
|
+
const store = existsSync16(paths.DB_FILE) ? getLocalCache().openUsageStore(paths.DB_FILE) : null;
|
|
11500
11331
|
if (!store) return { ...EMPTY, days };
|
|
11501
11332
|
const window = days === 0 ? void 0 : days;
|
|
11502
11333
|
try {
|
|
@@ -11538,7 +11369,7 @@ async function buildChannelUsageReport(channelId, days, labelChannel) {
|
|
|
11538
11369
|
const { totals, byDay } = await channelUsageForWorkspace(workspace, aliasIds, window);
|
|
11539
11370
|
return { days, totals: totals.runs > 0 ? totals : null, byDay };
|
|
11540
11371
|
} catch {
|
|
11541
|
-
const store =
|
|
11372
|
+
const store = existsSync16(paths.DB_FILE) ? getLocalCache().openUsageStore(paths.DB_FILE) : null;
|
|
11542
11373
|
if (!store) return { days, totals: null, byDay: [] };
|
|
11543
11374
|
try {
|
|
11544
11375
|
const targetLabel = labelChannel(channelId);
|
|
@@ -11571,7 +11402,7 @@ async function buildThreadUsage(threadTs) {
|
|
|
11571
11402
|
if (totals.runs === 0) return empty;
|
|
11572
11403
|
return { ...empty, totals, byModel, contextTokens: contextOf(mainRun) };
|
|
11573
11404
|
} catch {
|
|
11574
|
-
const store =
|
|
11405
|
+
const store = existsSync16(paths.DB_FILE) ? getLocalCache().openUsageStore(paths.DB_FILE) : null;
|
|
11575
11406
|
if (!store) return empty;
|
|
11576
11407
|
try {
|
|
11577
11408
|
const totals = store.threadTotals(threadTs);
|
|
@@ -12561,7 +12392,7 @@ function registerDataRoutes(api, agent = {}) {
|
|
|
12561
12392
|
runs2.set(name, { lastRun: run4.lastRunAt.toISOString(), lastStatus: run4.lastStatus });
|
|
12562
12393
|
}
|
|
12563
12394
|
} catch {
|
|
12564
|
-
const runStore =
|
|
12395
|
+
const runStore = existsSync17(paths.DB_FILE) ? getLocalCache().openAutomationRunStore(paths.DB_FILE) : null;
|
|
12565
12396
|
if (runStore) {
|
|
12566
12397
|
try {
|
|
12567
12398
|
for (const run4 of runStore.listLastRuns()) {
|
|
@@ -12623,7 +12454,7 @@ function registerDataRoutes(api, agent = {}) {
|
|
|
12623
12454
|
const runs2 = (await recentRunsForWorkspace(getProfile(), 200)).map(toResponse4);
|
|
12624
12455
|
return c.json({ runs: runs2 });
|
|
12625
12456
|
} catch {
|
|
12626
|
-
const runStore =
|
|
12457
|
+
const runStore = existsSync17(paths.DB_FILE) ? getLocalCache().openAutomationRunStore(paths.DB_FILE) : null;
|
|
12627
12458
|
if (!runStore) return c.json({ runs: [] });
|
|
12628
12459
|
try {
|
|
12629
12460
|
const runs2 = runStore.listRuns(200).map(toResponse4);
|
|
@@ -12810,7 +12641,7 @@ function registerDataRoutes(api, agent = {}) {
|
|
|
12810
12641
|
} catch {
|
|
12811
12642
|
latest = /* @__PURE__ */ new Map();
|
|
12812
12643
|
totals = /* @__PURE__ */ new Map();
|
|
12813
|
-
const usageStore =
|
|
12644
|
+
const usageStore = existsSync17(paths.DB_FILE) ? getLocalCache().openUsageStore(paths.DB_FILE) : null;
|
|
12814
12645
|
if (usageStore) {
|
|
12815
12646
|
try {
|
|
12816
12647
|
latest = usageStore.latestByThread(threadTsList);
|
|
@@ -13076,11 +12907,11 @@ function createDeviceAuthRouter() {
|
|
|
13076
12907
|
}
|
|
13077
12908
|
|
|
13078
12909
|
// ../api/src/dashboard/skills-routes.ts
|
|
13079
|
-
import { dirname as
|
|
12910
|
+
import { dirname as dirname6 } from "path";
|
|
13080
12911
|
|
|
13081
12912
|
// ../api/src/dashboard/skill-mirror.ts
|
|
13082
12913
|
import { createHash as createHash5 } from "crypto";
|
|
13083
|
-
import { existsSync as
|
|
12914
|
+
import { existsSync as existsSync18, statSync as statSync3 } from "fs";
|
|
13084
12915
|
var SYNC_INTERVAL_MS = 6e4;
|
|
13085
12916
|
var UPSERT_BATCH = 50;
|
|
13086
12917
|
function mirrorScopeOf(ref) {
|
|
@@ -13088,7 +12919,7 @@ function mirrorScopeOf(ref) {
|
|
|
13088
12919
|
}
|
|
13089
12920
|
function isDir(path) {
|
|
13090
12921
|
try {
|
|
13091
|
-
return
|
|
12922
|
+
return existsSync18(path) && statSync3(path).isDirectory();
|
|
13092
12923
|
} catch {
|
|
13093
12924
|
return false;
|
|
13094
12925
|
}
|
|
@@ -13430,11 +13261,11 @@ function createGatedRouter(agent, register) {
|
|
|
13430
13261
|
}
|
|
13431
13262
|
|
|
13432
13263
|
// src/dashboard/host-api.ts
|
|
13433
|
-
import { existsSync as
|
|
13264
|
+
import { existsSync as existsSync23, readFileSync as readFileSync17, statSync as statSync5 } from "fs";
|
|
13434
13265
|
import sharp5 from "sharp";
|
|
13435
13266
|
|
|
13436
13267
|
// src/dashboard/channels-routes.ts
|
|
13437
|
-
import { existsSync as
|
|
13268
|
+
import { existsSync as existsSync19, mkdirSync as mkdirSync8 } from "fs";
|
|
13438
13269
|
import { Hono as Hono36 } from "hono";
|
|
13439
13270
|
function coerceAccess(raw) {
|
|
13440
13271
|
if (raw === "open" || raw === "*" || raw === "all") return raw;
|
|
@@ -13480,7 +13311,7 @@ function coerceMemberEmails(raw) {
|
|
|
13480
13311
|
function ensureCwdDir(cwd) {
|
|
13481
13312
|
const expanded = expandPath(cwd);
|
|
13482
13313
|
if (isLogicalCwd(cwd) || isUnderLogicalRoot(expanded)) return;
|
|
13483
|
-
if (!
|
|
13314
|
+
if (!existsSync19(expanded)) mkdirSync8(expanded, { recursive: true });
|
|
13484
13315
|
}
|
|
13485
13316
|
function toResponse3(channel) {
|
|
13486
13317
|
return {
|
|
@@ -13634,8 +13465,8 @@ function createChannelWriteRouter() {
|
|
|
13634
13465
|
}
|
|
13635
13466
|
|
|
13636
13467
|
// src/dashboard/skills-routes-host.ts
|
|
13637
|
-
import { existsSync as
|
|
13638
|
-
import { dirname as
|
|
13468
|
+
import { existsSync as existsSync20, statSync as statSync4 } from "fs";
|
|
13469
|
+
import { dirname as dirname7 } from "path";
|
|
13639
13470
|
import { Hono as Hono37 } from "hono";
|
|
13640
13471
|
function workspaceScope() {
|
|
13641
13472
|
const claudeConfigDir = profileClaudeConfigDir();
|
|
@@ -13643,7 +13474,7 @@ function workspaceScope() {
|
|
|
13643
13474
|
return {
|
|
13644
13475
|
dir: workspaceSkillsDir(claudeConfigDir),
|
|
13645
13476
|
// `~/.claude` itself, which exists wherever the CLI has ever run.
|
|
13646
|
-
root:
|
|
13477
|
+
root: dirname7(workspaceSkillsDir(claudeConfigDir)),
|
|
13647
13478
|
cwd,
|
|
13648
13479
|
claudeConfigDir,
|
|
13649
13480
|
// Only plugin skills. Project skills belong to a specific channel's cwd, so
|
|
@@ -13669,7 +13500,7 @@ function inheritedSkills(scope, own) {
|
|
|
13669
13500
|
}
|
|
13670
13501
|
function rootExists(dir) {
|
|
13671
13502
|
try {
|
|
13672
|
-
return
|
|
13503
|
+
return existsSync20(dir) && statSync4(dir).isDirectory();
|
|
13673
13504
|
} catch {
|
|
13674
13505
|
return false;
|
|
13675
13506
|
}
|
|
@@ -13776,9 +13607,9 @@ async function resolveAgentIdentities(viewer) {
|
|
|
13776
13607
|
|
|
13777
13608
|
// ../api/src/dashboard/providers.ts
|
|
13778
13609
|
import { execFileSync as execFileSync4 } from "child_process";
|
|
13779
|
-
import { existsSync as
|
|
13610
|
+
import { existsSync as existsSync21, readFileSync as readFileSync15 } from "fs";
|
|
13780
13611
|
import { homedir as homedir7 } from "os";
|
|
13781
|
-
import { join as
|
|
13612
|
+
import { join as join13, resolve as resolve5 } from "path";
|
|
13782
13613
|
var PROVIDER_LABELS = {
|
|
13783
13614
|
claude: "Claude Code",
|
|
13784
13615
|
codex: "Codex"
|
|
@@ -13799,7 +13630,7 @@ function binaryOnPath(bin) {
|
|
|
13799
13630
|
function claudeAuthAvailable() {
|
|
13800
13631
|
if (profileEnv("CLAUDE_CODE_OAUTH_TOKEN")?.trim()) return true;
|
|
13801
13632
|
const configDir2 = profileClaudeConfigDir() || resolve5(homedir7(), ".claude");
|
|
13802
|
-
if (
|
|
13633
|
+
if (existsSync21(join13(configDir2, ".credentials.json"))) return true;
|
|
13803
13634
|
if (process.platform !== "darwin") return false;
|
|
13804
13635
|
try {
|
|
13805
13636
|
execFileSync4("security", ["find-generic-password", "-s", "Claude Code-credentials"], {
|
|
@@ -13843,9 +13674,9 @@ function claudeAccount() {
|
|
|
13843
13674
|
}
|
|
13844
13675
|
}
|
|
13845
13676
|
function codexAccount() {
|
|
13846
|
-
const home2 = process.env["CODEX_HOME"]?.trim() ||
|
|
13677
|
+
const home2 = process.env["CODEX_HOME"]?.trim() || join13(homedir7(), ".codex");
|
|
13847
13678
|
try {
|
|
13848
|
-
const auth = JSON.parse(
|
|
13679
|
+
const auth = JSON.parse(readFileSync15(join13(home2, "auth.json"), "utf8"));
|
|
13849
13680
|
const payload = auth.tokens?.id_token?.split(".")[1];
|
|
13850
13681
|
if (!payload) return void 0;
|
|
13851
13682
|
const claims = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
|
|
@@ -13876,9 +13707,9 @@ function providerStatuses() {
|
|
|
13876
13707
|
// src/dashboard/provider-login-host.ts
|
|
13877
13708
|
import { spawn as spawn4 } from "child_process";
|
|
13878
13709
|
import { randomUUID as randomUUID4 } from "crypto";
|
|
13879
|
-
import { chmodSync, existsSync as
|
|
13710
|
+
import { chmodSync, existsSync as existsSync22, mkdirSync as mkdirSync9, readFileSync as readFileSync16, writeFileSync as writeFileSync8 } from "fs";
|
|
13880
13711
|
import { createRequire } from "module";
|
|
13881
|
-
import { dirname as
|
|
13712
|
+
import { dirname as dirname8, join as join14 } from "path";
|
|
13882
13713
|
import { Hono as Hono38 } from "hono";
|
|
13883
13714
|
var SESSION_TTL_MS = 10 * 6e4;
|
|
13884
13715
|
var URL_WAIT_MS = 3e4;
|
|
@@ -13941,10 +13772,10 @@ function waitFor(s, parse, ms) {
|
|
|
13941
13772
|
}
|
|
13942
13773
|
function loadPty() {
|
|
13943
13774
|
const require2 = createRequire(import.meta.url);
|
|
13944
|
-
const root =
|
|
13945
|
-
const helper =
|
|
13775
|
+
const root = dirname8(require2.resolve("node-pty/package.json"));
|
|
13776
|
+
const helper = join14(root, "prebuilds", `${process.platform}-${process.arch}`, "spawn-helper");
|
|
13946
13777
|
try {
|
|
13947
|
-
if (
|
|
13778
|
+
if (existsSync22(helper)) chmodSync(helper, 493);
|
|
13948
13779
|
} catch {
|
|
13949
13780
|
}
|
|
13950
13781
|
return require2("node-pty");
|
|
@@ -13984,9 +13815,9 @@ async function startClaude() {
|
|
|
13984
13815
|
return { id, url };
|
|
13985
13816
|
}
|
|
13986
13817
|
function saveClaudeToken(configFile, token) {
|
|
13987
|
-
|
|
13988
|
-
const current =
|
|
13989
|
-
|
|
13818
|
+
mkdirSync9(dirname8(configFile), { recursive: true });
|
|
13819
|
+
const current = existsSync22(configFile) ? readFileSync16(configFile, "utf-8") : "";
|
|
13820
|
+
writeFileSync8(configFile, upsertEnvLine(current, "CLAUDE_CODE_OAUTH_TOKEN", token), { mode: 384 });
|
|
13990
13821
|
const cached = cachedProfileConfig();
|
|
13991
13822
|
if (cached) cached.env["CLAUDE_CODE_OAUTH_TOKEN"] = token;
|
|
13992
13823
|
clearClaudeAuthFailed();
|
|
@@ -14209,7 +14040,7 @@ function registerHostRoutes(api) {
|
|
|
14209
14040
|
const errors = c.req.query("error") === "true" || c.req.query("error") === "1";
|
|
14210
14041
|
const limit = Math.min(Number(c.req.query("limit")) || 200, 2e3);
|
|
14211
14042
|
const file = serviceLogFile(errors);
|
|
14212
|
-
const exists =
|
|
14043
|
+
const exists = existsSync23(file);
|
|
14213
14044
|
return c.json({
|
|
14214
14045
|
file,
|
|
14215
14046
|
exists,
|
|
@@ -14219,8 +14050,8 @@ function registerHostRoutes(api) {
|
|
|
14219
14050
|
});
|
|
14220
14051
|
}
|
|
14221
14052
|
function tailFile(file, limit) {
|
|
14222
|
-
if (!
|
|
14223
|
-
const lines =
|
|
14053
|
+
if (!existsSync23(file)) return [];
|
|
14054
|
+
const lines = readFileSync17(file, "utf-8").split("\n");
|
|
14224
14055
|
if (lines.at(-1) === "") lines.pop();
|
|
14225
14056
|
return lines.slice(-limit);
|
|
14226
14057
|
}
|
|
@@ -14238,21 +14069,21 @@ function createHostApiRouter(agent = {}) {
|
|
|
14238
14069
|
|
|
14239
14070
|
// src/dashboard/agent-bridge-host.ts
|
|
14240
14071
|
import { sign as signRaw, timingSafeEqual } from "crypto";
|
|
14241
|
-
import { existsSync as
|
|
14072
|
+
import { existsSync as existsSync25, readFileSync as readFileSync20 } from "fs";
|
|
14242
14073
|
import dotenv2 from "dotenv";
|
|
14243
14074
|
import { WebSocket as WebSocket2 } from "ws";
|
|
14244
14075
|
|
|
14245
14076
|
// src/dashboard/session-import-host.ts
|
|
14246
14077
|
import {
|
|
14247
14078
|
closeSync as closeSync2,
|
|
14248
|
-
existsSync as
|
|
14079
|
+
existsSync as existsSync24,
|
|
14249
14080
|
openSync as openSync2,
|
|
14250
14081
|
readdirSync as readdirSync4,
|
|
14251
|
-
readFileSync as
|
|
14082
|
+
readFileSync as readFileSync18,
|
|
14252
14083
|
readSync as readSync2,
|
|
14253
14084
|
realpathSync as realpathSync4
|
|
14254
14085
|
} from "fs";
|
|
14255
|
-
import { basename as basename6, join as
|
|
14086
|
+
import { basename as basename6, join as join15, resolve as resolve6 } from "path";
|
|
14256
14087
|
var MAX_AGE_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
14257
14088
|
var HEAD_BYTES = 64 * 1024;
|
|
14258
14089
|
var TITLE_MAX = 80;
|
|
@@ -14293,7 +14124,7 @@ function blocksText(content, kinds) {
|
|
|
14293
14124
|
return parts.length ? cleanText2(parts.join("\n\n")) : null;
|
|
14294
14125
|
}
|
|
14295
14126
|
function boundSessionIds() {
|
|
14296
|
-
if (!
|
|
14127
|
+
if (!existsSync24(paths.DB_FILE)) return /* @__PURE__ */ new Set();
|
|
14297
14128
|
const store = new SessionStore(paths.DB_FILE);
|
|
14298
14129
|
try {
|
|
14299
14130
|
return new Set(store.listSessions().map((s) => s.sessionId));
|
|
@@ -14394,14 +14225,14 @@ function scanSessionFolders(slug) {
|
|
|
14394
14225
|
]);
|
|
14395
14226
|
};
|
|
14396
14227
|
if (agents.has("claude")) {
|
|
14397
|
-
const root =
|
|
14228
|
+
const root = join15(claudeDir(), "projects");
|
|
14398
14229
|
let dirs = [];
|
|
14399
14230
|
try {
|
|
14400
14231
|
dirs = readdirSync4(root, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name);
|
|
14401
14232
|
} catch {
|
|
14402
14233
|
}
|
|
14403
14234
|
for (const dir of dirs) {
|
|
14404
|
-
const files = jsonlFiles(
|
|
14235
|
+
const files = jsonlFiles(join15(root, dir), 0).filter((f) => f.mtime >= since2);
|
|
14405
14236
|
let cwd = null;
|
|
14406
14237
|
for (const f of files) {
|
|
14407
14238
|
cwd ??= cwdFromTranscript(f.file);
|
|
@@ -14415,7 +14246,7 @@ function scanSessionFolders(slug) {
|
|
|
14415
14246
|
}
|
|
14416
14247
|
}
|
|
14417
14248
|
if (agents.has("codex")) {
|
|
14418
|
-
for (const f of jsonlFiles(
|
|
14249
|
+
for (const f of jsonlFiles(join15(codexDir(), "sessions"), 4)) {
|
|
14419
14250
|
if (f.mtime < since2) continue;
|
|
14420
14251
|
const s = codexSummary(f.file, f.mtime);
|
|
14421
14252
|
if (s) add(s.cwd, s.session);
|
|
@@ -14442,22 +14273,22 @@ function scanSessionFolders(slug) {
|
|
|
14442
14273
|
function findTranscript(agent, sessionId) {
|
|
14443
14274
|
if (!/^[A-Za-z0-9-]+$/.test(sessionId)) return null;
|
|
14444
14275
|
if (agent === "claude") {
|
|
14445
|
-
const root =
|
|
14276
|
+
const root = join15(claudeDir(), "projects");
|
|
14446
14277
|
try {
|
|
14447
14278
|
for (const e of readdirSync4(root, { withFileTypes: true })) {
|
|
14448
|
-
const file =
|
|
14449
|
-
if (e.isDirectory() &&
|
|
14279
|
+
const file = join15(root, e.name, `${sessionId}.jsonl`);
|
|
14280
|
+
if (e.isDirectory() && existsSync24(file)) return file;
|
|
14450
14281
|
}
|
|
14451
14282
|
} catch {
|
|
14452
14283
|
}
|
|
14453
14284
|
return null;
|
|
14454
14285
|
}
|
|
14455
|
-
return jsonlFiles(
|
|
14286
|
+
return jsonlFiles(join15(codexDir(), "sessions"), 4).find((f) => f.file.endsWith(`${sessionId}.jsonl`))?.file ?? null;
|
|
14456
14287
|
}
|
|
14457
14288
|
function readSessionMessages(agent, sessionId, afterUuid) {
|
|
14458
14289
|
const file = findTranscript(agent, sessionId);
|
|
14459
14290
|
if (!file) return null;
|
|
14460
|
-
const lines = parseLines(
|
|
14291
|
+
const lines = parseLines(readFileSync18(file, "utf-8"));
|
|
14461
14292
|
const messages = agent === "claude" ? claudeMessages(lines) : codexMessages(lines);
|
|
14462
14293
|
if (!afterUuid) return messages;
|
|
14463
14294
|
const idx = messages.findIndex((m) => m.uuid === afterUuid);
|
|
@@ -14514,7 +14345,7 @@ async function handleHostRequest(req) {
|
|
|
14514
14345
|
}
|
|
14515
14346
|
|
|
14516
14347
|
// src/dashboard/doc-share-publisher.ts
|
|
14517
|
-
import { readFileSync as
|
|
14348
|
+
import { readFileSync as readFileSync19, statSync as statSync6 } from "fs";
|
|
14518
14349
|
import { extname, posix } from "path";
|
|
14519
14350
|
var MAX_ASSET_BYTES = 20 * 1024 * 1024;
|
|
14520
14351
|
var MAX_CONTENT_BYTES = 2 * 1024 * 1024;
|
|
@@ -14629,7 +14460,7 @@ function readDocShareBundle({ cwd, sourcePath }) {
|
|
|
14629
14460
|
}
|
|
14630
14461
|
if (!stat.isFile()) return { status: "not-found" };
|
|
14631
14462
|
if (stat.size > MAX_CONTENT_BYTES) return { status: "too-large" };
|
|
14632
|
-
const source =
|
|
14463
|
+
const source = readFileSync19(abs, "utf8");
|
|
14633
14464
|
const title = extractTitle(abs, kind === "markdown" ? "md" : kind);
|
|
14634
14465
|
if (kind === "excalidraw") {
|
|
14635
14466
|
try {
|
|
@@ -14700,7 +14531,7 @@ function readDocShareBundle({ cwd, sourcePath }) {
|
|
|
14700
14531
|
let text = null;
|
|
14701
14532
|
try {
|
|
14702
14533
|
const size = statSync6(docAbs).size;
|
|
14703
|
-
if (size <= budget) text =
|
|
14534
|
+
if (size <= budget) text = readFileSync19(docAbs, "utf8");
|
|
14704
14535
|
} catch {
|
|
14705
14536
|
continue;
|
|
14706
14537
|
}
|
|
@@ -14717,7 +14548,7 @@ function readDocShareBundle({ cwd, sourcePath }) {
|
|
|
14717
14548
|
let body;
|
|
14718
14549
|
try {
|
|
14719
14550
|
if (statSync6(resolved.abs).size > MAX_ASSET_BYTES) continue;
|
|
14720
|
-
body =
|
|
14551
|
+
body = readFileSync19(resolved.abs);
|
|
14721
14552
|
} catch {
|
|
14722
14553
|
continue;
|
|
14723
14554
|
}
|
|
@@ -14745,13 +14576,13 @@ function readDocShareBundle({ cwd, sourcePath }) {
|
|
|
14745
14576
|
|
|
14746
14577
|
// src/dashboard/host-upgrade.ts
|
|
14747
14578
|
import { spawn as spawn5 } from "child_process";
|
|
14748
|
-
import { mkdirSync as
|
|
14749
|
-
import { join as
|
|
14579
|
+
import { mkdirSync as mkdirSync10, openSync as openSync3 } from "fs";
|
|
14580
|
+
import { join as join16 } from "path";
|
|
14750
14581
|
var running = false;
|
|
14751
14582
|
function startHostUpgrade() {
|
|
14752
14583
|
if (running) return { started: false };
|
|
14753
|
-
|
|
14754
|
-
const log5 = openSync3(
|
|
14584
|
+
mkdirSync10(paths.LOG_DIR, { recursive: true });
|
|
14585
|
+
const log5 = openSync3(join16(paths.LOG_DIR, "host-upgrade.log"), "a");
|
|
14755
14586
|
const child = spawn5(process.execPath, [process.argv[1] ?? "", "upgrade"], {
|
|
14756
14587
|
detached: true,
|
|
14757
14588
|
stdio: ["ignore", log5, log5]
|
|
@@ -14844,7 +14675,7 @@ function dataSocketUrl() {
|
|
|
14844
14675
|
return `ws://127.0.0.1:${process.env["FLYSPACE_DATA_API_PORT"] ?? DEFAULT_DATA_API_PORT}${HOST_SOCKET_PATH}`;
|
|
14845
14676
|
}
|
|
14846
14677
|
function listLocalSessions() {
|
|
14847
|
-
if (!
|
|
14678
|
+
if (!existsSync25(paths.DB_FILE)) return [];
|
|
14848
14679
|
const store = new SessionStore(paths.DB_FILE);
|
|
14849
14680
|
try {
|
|
14850
14681
|
return store.listSessions();
|
|
@@ -14896,10 +14727,10 @@ function buildHostConfigSnapshot() {
|
|
|
14896
14727
|
const snapshot2 = {};
|
|
14897
14728
|
for (const profile of listProfiles()) {
|
|
14898
14729
|
snapshot2[profile] = runWithProfile(profile, () => ({
|
|
14899
|
-
env:
|
|
14730
|
+
env: existsSync25(paths.CONFIG_FILE) ? dotenv2.parse(readFileSync20(paths.CONFIG_FILE, "utf-8")) : {},
|
|
14900
14731
|
// Only a model someone actually saved: before that it is just the Claude
|
|
14901
14732
|
// default, which would show the wrong agent in admin for a Codex user.
|
|
14902
|
-
agentModel:
|
|
14733
|
+
agentModel: existsSync25(paths.DASHBOARD_SETTINGS_FILE) ? loadDashboardSettings().agent : void 0
|
|
14903
14734
|
}));
|
|
14904
14735
|
}
|
|
14905
14736
|
return snapshot2;
|
|
@@ -15084,8 +14915,8 @@ function send(ws, msg) {
|
|
|
15084
14915
|
}
|
|
15085
14916
|
|
|
15086
14917
|
// src/dashboard/machine-server.ts
|
|
15087
|
-
import { existsSync as
|
|
15088
|
-
import { join as
|
|
14918
|
+
import { existsSync as existsSync26 } from "fs";
|
|
14919
|
+
import { join as join17 } from "path";
|
|
15089
14920
|
import { serveStatic } from "@hono/node-server/serve-static";
|
|
15090
14921
|
|
|
15091
14922
|
// ../api/src/dashboard/app-icon-routes.ts
|
|
@@ -15162,7 +14993,7 @@ function pngResponse(c, png) {
|
|
|
15162
14993
|
}
|
|
15163
14994
|
|
|
15164
14995
|
// src/dashboard/machine-server.ts
|
|
15165
|
-
var WEB_DIST =
|
|
14996
|
+
var WEB_DIST = join17(paths.WEB_ROOT, "dist");
|
|
15166
14997
|
async function bootMachine() {
|
|
15167
14998
|
await reconcileAll().catch(
|
|
15168
14999
|
(err) => console.error("[dashboard] reconcileAll failed:", err.message)
|
|
@@ -15182,14 +15013,14 @@ async function bootMachine() {
|
|
|
15182
15013
|
function mountSpa(app) {
|
|
15183
15014
|
app.route("/share", createPublicShareAssetRouter(WEB_DIST));
|
|
15184
15015
|
app.route("/", createAppIconRouter());
|
|
15185
|
-
if (
|
|
15016
|
+
if (existsSync26(WEB_DIST) || existsSync26(join17(paths.WEB_ROOT, "package.json"))) {
|
|
15186
15017
|
app.use("/*", serveStatic({ root: WEB_DIST }));
|
|
15187
15018
|
}
|
|
15188
15019
|
app.get("/assets/*", (c) => c.text("stale asset \u2014 reload for the current build", 404));
|
|
15189
|
-
const spaFallback = serveStatic({ path:
|
|
15020
|
+
const spaFallback = serveStatic({ path: join17(WEB_DIST, "index.html") });
|
|
15190
15021
|
app.get("*", async (c, next) => {
|
|
15191
|
-
if (!
|
|
15192
|
-
const isCheckout =
|
|
15022
|
+
if (!existsSync26(join17(WEB_DIST, "index.html"))) {
|
|
15023
|
+
const isCheckout = existsSync26(join17(paths.WEB_ROOT, "package.json"));
|
|
15193
15024
|
return c.text(
|
|
15194
15025
|
isCheckout ? `Workspace UI build missing (${WEB_DIST}).
|
|
15195
15026
|
Run \`pnpm build:web\` from the repo root.
|
|
@@ -15202,8 +15033,8 @@ The JSON API is live under /api.` : "This install has no bundled Workspace UI.\n
|
|
|
15202
15033
|
}
|
|
15203
15034
|
|
|
15204
15035
|
// src/dashboard/host-log-file.ts
|
|
15205
|
-
import { createWriteStream, fstatSync, mkdirSync as
|
|
15206
|
-
import { join as
|
|
15036
|
+
import { createWriteStream, fstatSync, mkdirSync as mkdirSync11, statSync as statSync7 } from "fs";
|
|
15037
|
+
import { join as join18 } from "path";
|
|
15207
15038
|
var STAMPED = /^\[\d{4}-\d{2}-\d{2}T/;
|
|
15208
15039
|
function stamp(text) {
|
|
15209
15040
|
const ts2 = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -15232,12 +15063,12 @@ function tee(stream, fd, file) {
|
|
|
15232
15063
|
}
|
|
15233
15064
|
function ensureHostLogFiles() {
|
|
15234
15065
|
try {
|
|
15235
|
-
|
|
15066
|
+
mkdirSync11(paths.LOG_DIR, { recursive: true });
|
|
15236
15067
|
} catch {
|
|
15237
15068
|
return;
|
|
15238
15069
|
}
|
|
15239
|
-
tee(process.stdout, 1,
|
|
15240
|
-
tee(process.stderr, 2,
|
|
15070
|
+
tee(process.stdout, 1, join18(paths.LOG_DIR, "host.log"));
|
|
15071
|
+
tee(process.stderr, 2, join18(paths.LOG_DIR, "host-error.log"));
|
|
15241
15072
|
}
|
|
15242
15073
|
|
|
15243
15074
|
// src/dashboard/host-dashboard.ts
|
|
@@ -15363,8 +15194,8 @@ function openBrowser2(url) {
|
|
|
15363
15194
|
}
|
|
15364
15195
|
}
|
|
15365
15196
|
function ensureWebBuild() {
|
|
15366
|
-
if (
|
|
15367
|
-
if (!
|
|
15197
|
+
if (existsSync27(join19(paths.WEB_ROOT, "dist", "index.html"))) return;
|
|
15198
|
+
if (!existsSync27(join19(paths.WEB_ROOT, "package.json"))) return;
|
|
15368
15199
|
console.log(" packages/ui/dist missing, building the dashboard UI...");
|
|
15369
15200
|
const result = spawnSync("pnpm", ["build"], {
|
|
15370
15201
|
cwd: paths.WEB_ROOT,
|
|
@@ -15414,7 +15245,7 @@ async function runDashboard(args) {
|
|
|
15414
15245
|
}
|
|
15415
15246
|
|
|
15416
15247
|
// src/commands/workspace.ts
|
|
15417
|
-
import { existsSync as
|
|
15248
|
+
import { existsSync as existsSync28, mkdirSync as mkdirSync12, writeFileSync as writeFileSync9 } from "fs";
|
|
15418
15249
|
var USAGE7 = `
|
|
15419
15250
|
Usage: flyspace workspace <subcommand> [options]
|
|
15420
15251
|
|
|
@@ -15500,10 +15331,10 @@ function provisionLocal(botName) {
|
|
|
15500
15331
|
ensureDirs();
|
|
15501
15332
|
console.log(` config dir ready (${paths.CONFIG_DIR})`);
|
|
15502
15333
|
console.log(` data dir ready (${paths.DATA_DIR})`);
|
|
15503
|
-
if (
|
|
15334
|
+
if (existsSync28(paths.CONFIG_FILE)) {
|
|
15504
15335
|
console.log(" config.env exists");
|
|
15505
15336
|
} else {
|
|
15506
|
-
|
|
15337
|
+
writeFileSync9(paths.CONFIG_FILE, `BOT_NAME=${botName}
|
|
15507
15338
|
`);
|
|
15508
15339
|
console.log(` config.env written (${paths.CONFIG_FILE})`);
|
|
15509
15340
|
}
|
|
@@ -15522,8 +15353,8 @@ async function provisionChannels(specs) {
|
|
|
15522
15353
|
continue;
|
|
15523
15354
|
}
|
|
15524
15355
|
const cwd = expandPath(spec.cwd);
|
|
15525
|
-
if (!
|
|
15526
|
-
|
|
15356
|
+
if (!existsSync28(cwd)) {
|
|
15357
|
+
mkdirSync12(cwd, { recursive: true });
|
|
15527
15358
|
console.log(` created cwd ${cwd}`);
|
|
15528
15359
|
}
|
|
15529
15360
|
await createChannel({ name: spec.name, cwd, position: index });
|
|
@@ -15624,10 +15455,10 @@ async function runDesktopCmd(args) {
|
|
|
15624
15455
|
}
|
|
15625
15456
|
|
|
15626
15457
|
// src/cli.ts
|
|
15627
|
-
import { join as
|
|
15458
|
+
import { join as join20 } from "path";
|
|
15628
15459
|
var home = flyspaceHome();
|
|
15629
15460
|
if (home) {
|
|
15630
|
-
const bin =
|
|
15461
|
+
const bin = join20(home, "bin");
|
|
15631
15462
|
const path = process.env.PATH ?? "";
|
|
15632
15463
|
if (!path.split(":").includes(bin)) process.env.PATH = path ? `${bin}:${path}` : bin;
|
|
15633
15464
|
}
|
|
@@ -15652,6 +15483,7 @@ var USAGE10 = `
|
|
|
15652
15483
|
usage Show agent token usage and cost for this workspace
|
|
15653
15484
|
chat Inspect dashboard chat channels and move threads between them
|
|
15654
15485
|
memory Read and write a channel's persistent agent memory
|
|
15486
|
+
persona Use a claudecafe character's faces as the bot's avatars
|
|
15655
15487
|
profiles List local profiles (bound here? scheduler?) or remove one
|
|
15656
15488
|
workspace Provision a workspace (Supabase rows + local profile dirs)
|
|
15657
15489
|
reconcile Repair a workspace's local files against Supabase
|
|
@@ -15754,6 +15586,9 @@ async function main() {
|
|
|
15754
15586
|
case "memory":
|
|
15755
15587
|
await runMemoryCmd(args.slice(1));
|
|
15756
15588
|
break;
|
|
15589
|
+
case "persona":
|
|
15590
|
+
await runPersonaCmd(args.slice(1));
|
|
15591
|
+
break;
|
|
15757
15592
|
case "profile":
|
|
15758
15593
|
case "profiles":
|
|
15759
15594
|
await runProfiles(args.slice(1));
|
|
@@ -15769,7 +15604,7 @@ async function main() {
|
|
|
15769
15604
|
break;
|
|
15770
15605
|
case "-v":
|
|
15771
15606
|
case "--version":
|
|
15772
|
-
printRaw("0.1.
|
|
15607
|
+
printRaw("0.1.58");
|
|
15773
15608
|
break;
|
|
15774
15609
|
case "-h":
|
|
15775
15610
|
case "--help":
|