@cosmicstack/mercury-agent 1.2.1 → 1.2.2
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/index.js +179 -146
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1450,7 +1450,7 @@ var init_mimo = __esm({
|
|
|
1450
1450
|
|
|
1451
1451
|
// src/utils/platform.ts
|
|
1452
1452
|
import { existsSync as existsSync6 } from "fs";
|
|
1453
|
-
import {
|
|
1453
|
+
import { posix as posixPath } from "path";
|
|
1454
1454
|
function isTermux(env = process.env, platform = process.platform) {
|
|
1455
1455
|
if (platform !== "linux") return false;
|
|
1456
1456
|
return Boolean(
|
|
@@ -1460,7 +1460,7 @@ function isTermux(env = process.env, platform = process.platform) {
|
|
|
1460
1460
|
function resolveShell(env = process.env, fileExists = existsSync6, platform = process.platform) {
|
|
1461
1461
|
const candidates = [env.MERCURY_SHELL, env.SHELL];
|
|
1462
1462
|
if (isTermux(env, platform)) {
|
|
1463
|
-
candidates.push(env.PREFIX ?
|
|
1463
|
+
candidates.push(env.PREFIX ? posixPath.join(env.PREFIX, "bin", "sh") : void 0);
|
|
1464
1464
|
}
|
|
1465
1465
|
candidates.push("/bin/sh");
|
|
1466
1466
|
return candidates.find((candidate) => candidate && fileExists(candidate)) || "/bin/sh";
|
|
@@ -1525,9 +1525,9 @@ __export(chatgpt_session_exports, {
|
|
|
1525
1525
|
saveChatGPTSession: () => saveChatGPTSession
|
|
1526
1526
|
});
|
|
1527
1527
|
import { readFileSync as readFileSync5, writeFileSync as writeFileSync5, existsSync as existsSync7, mkdirSync as mkdirSync6 } from "fs";
|
|
1528
|
-
import { join as
|
|
1528
|
+
import { join as join7 } from "path";
|
|
1529
1529
|
function getSessionPath() {
|
|
1530
|
-
return
|
|
1530
|
+
return join7(getMercuryHome(), "chatgpt-session.json");
|
|
1531
1531
|
}
|
|
1532
1532
|
function loadChatGPTSession() {
|
|
1533
1533
|
const path9 = getSessionPath();
|
|
@@ -1985,9 +1985,9 @@ __export(github_session_exports, {
|
|
|
1985
1985
|
validateGitHubToken: () => validateGitHubToken
|
|
1986
1986
|
});
|
|
1987
1987
|
import { readFileSync as readFileSync6, writeFileSync as writeFileSync6, existsSync as existsSync8, mkdirSync as mkdirSync7 } from "fs";
|
|
1988
|
-
import { join as
|
|
1988
|
+
import { join as join8 } from "path";
|
|
1989
1989
|
function getSessionPath2() {
|
|
1990
|
-
return
|
|
1990
|
+
return join8(getMercuryHome(), "github-session.json");
|
|
1991
1991
|
}
|
|
1992
1992
|
function loadGitHubSession() {
|
|
1993
1993
|
const path9 = getSessionPath2();
|
|
@@ -2581,7 +2581,7 @@ __export(registry_exports, {
|
|
|
2581
2581
|
searchFeed: () => searchFeed
|
|
2582
2582
|
});
|
|
2583
2583
|
import { existsSync as existsSync10, mkdirSync as mkdirSync9, readFileSync as readFileSync8, writeFileSync as writeFileSync8 } from "fs";
|
|
2584
|
-
import { join as
|
|
2584
|
+
import { join as join10 } from "path";
|
|
2585
2585
|
import { homedir as homedir2 } from "os";
|
|
2586
2586
|
function isValidSkillId(id) {
|
|
2587
2587
|
return ID_RE.test(id);
|
|
@@ -2681,10 +2681,10 @@ var init_registry = __esm({
|
|
|
2681
2681
|
feedCachePath;
|
|
2682
2682
|
constructor(opts = {}) {
|
|
2683
2683
|
this.registryUrl = (opts.registry || DEFAULT_REGISTRY).replace(/\/$/, "");
|
|
2684
|
-
this.cacheDir = opts.cacheDir ||
|
|
2684
|
+
this.cacheDir = opts.cacheDir || join10(homedir2(), ".mercury", "cache");
|
|
2685
2685
|
this.cacheTtlMs = (opts.cacheTtlSeconds ?? DEFAULT_CACHE_TTL_SECONDS) * 1e3;
|
|
2686
2686
|
this.fetchImpl = opts.fetchImpl || globalThis.fetch;
|
|
2687
|
-
this.feedCachePath =
|
|
2687
|
+
this.feedCachePath = join10(this.cacheDir, "registry-feed.json");
|
|
2688
2688
|
}
|
|
2689
2689
|
/** Fetch (or read from cache) the full registry feed. */
|
|
2690
2690
|
async getFeed(force = false) {
|
|
@@ -2823,7 +2823,7 @@ import {
|
|
|
2823
2823
|
writeFileSync as writeFileSync9,
|
|
2824
2824
|
unlinkSync as unlinkSync4
|
|
2825
2825
|
} from "fs";
|
|
2826
|
-
import { dirname as dirname2, join as
|
|
2826
|
+
import { dirname as dirname2, join as join11, relative, resolve as resolve3, sep } from "path";
|
|
2827
2827
|
import { homedir as homedir3 } from "os";
|
|
2828
2828
|
import { parse as parseYaml2 } from "yaml";
|
|
2829
2829
|
function emptyIndex() {
|
|
@@ -2875,8 +2875,8 @@ var init_store = __esm({
|
|
|
2875
2875
|
indexPath;
|
|
2876
2876
|
registry;
|
|
2877
2877
|
constructor(opts = {}) {
|
|
2878
|
-
this.installRoot = opts.installRoot ||
|
|
2879
|
-
this.indexPath =
|
|
2878
|
+
this.installRoot = opts.installRoot || join11(homedir3(), ".mercury", "skills");
|
|
2879
|
+
this.indexPath = join11(this.installRoot, INDEX_FILENAME);
|
|
2880
2880
|
this.registry = opts.registry;
|
|
2881
2881
|
}
|
|
2882
2882
|
// ---------- Index ----------
|
|
@@ -3787,7 +3787,7 @@ __export(loader_exports, {
|
|
|
3787
3787
|
SkillLoader: () => SkillLoader
|
|
3788
3788
|
});
|
|
3789
3789
|
import { existsSync as existsSync12, readFileSync as readFileSync10, readdirSync as readdirSync4, mkdirSync as mkdirSync11, writeFileSync as writeFileSync10, rmSync as rmSync4, unlinkSync as unlinkSync5 } from "fs";
|
|
3790
|
-
import { join as
|
|
3790
|
+
import { join as join12 } from "path";
|
|
3791
3791
|
import { parse as parseYaml3 } from "yaml";
|
|
3792
3792
|
function parseSkillMd(content) {
|
|
3793
3793
|
const fmMatch = content.match(/^---\s*\n([\s\S]*?)\n---\s*\n([\s\S]*)$/);
|
|
@@ -3821,7 +3821,7 @@ var init_loader = __esm({
|
|
|
3821
3821
|
loaded = /* @__PURE__ */ new Map();
|
|
3822
3822
|
intentRouter;
|
|
3823
3823
|
constructor(skillsDir) {
|
|
3824
|
-
this.skillsDir = skillsDir ||
|
|
3824
|
+
this.skillsDir = skillsDir || join12(getMercuryHome(), "skills");
|
|
3825
3825
|
this.intentRouter = new IntentRouter();
|
|
3826
3826
|
}
|
|
3827
3827
|
discover() {
|
|
@@ -3861,12 +3861,12 @@ var init_loader = __esm({
|
|
|
3861
3861
|
const raw = readFileSync10(skillPath, "utf-8");
|
|
3862
3862
|
const parsed = parseSkillMd(raw);
|
|
3863
3863
|
if (!parsed || parsed.meta.name !== name) continue;
|
|
3864
|
-
const skillDir =
|
|
3864
|
+
const skillDir = join12(skillPath, "..");
|
|
3865
3865
|
const skill = {
|
|
3866
3866
|
...parsed.meta,
|
|
3867
3867
|
instructions: parsed.instructions,
|
|
3868
|
-
scriptsDir: existsSync12(
|
|
3869
|
-
referencesDir: existsSync12(
|
|
3868
|
+
scriptsDir: existsSync12(join12(skillDir, "scripts")) ? join12(skillDir, "scripts") : void 0,
|
|
3869
|
+
referencesDir: existsSync12(join12(skillDir, "references")) ? join12(skillDir, "references") : void 0
|
|
3870
3870
|
};
|
|
3871
3871
|
lastMatch = skill;
|
|
3872
3872
|
} catch (err) {
|
|
@@ -3890,9 +3890,9 @@ var init_loader = __esm({
|
|
|
3890
3890
|
if (!existsSync12(this.skillsDir)) return out2;
|
|
3891
3891
|
for (const entry of readdirSync4(this.skillsDir, { withFileTypes: true })) {
|
|
3892
3892
|
if (!entry.isDirectory() || entry.name.startsWith("_") || entry.name.startsWith(".")) continue;
|
|
3893
|
-
const dir =
|
|
3894
|
-
if (existsSync12(
|
|
3895
|
-
const flat =
|
|
3893
|
+
const dir = join12(this.skillsDir, entry.name);
|
|
3894
|
+
if (existsSync12(join12(dir, DISABLED_FILE))) continue;
|
|
3895
|
+
const flat = join12(dir, SKILL_FILE);
|
|
3896
3896
|
if (existsSync12(flat)) {
|
|
3897
3897
|
out2.push(flat);
|
|
3898
3898
|
continue;
|
|
@@ -3905,9 +3905,9 @@ var init_loader = __esm({
|
|
|
3905
3905
|
}
|
|
3906
3906
|
for (const child of children) {
|
|
3907
3907
|
if (!child.isDirectory() || child.name.startsWith("_") || child.name.startsWith(".")) continue;
|
|
3908
|
-
const childDir =
|
|
3909
|
-
if (existsSync12(
|
|
3910
|
-
const nested =
|
|
3908
|
+
const childDir = join12(dir, child.name);
|
|
3909
|
+
if (existsSync12(join12(childDir, DISABLED_FILE))) continue;
|
|
3910
|
+
const nested = join12(childDir, SKILL_FILE);
|
|
3911
3911
|
if (existsSync12(nested)) out2.push(nested);
|
|
3912
3912
|
}
|
|
3913
3913
|
}
|
|
@@ -3950,12 +3950,12 @@ var init_loader = __esm({
|
|
|
3950
3950
|
return text;
|
|
3951
3951
|
}
|
|
3952
3952
|
saveSkill(name, content) {
|
|
3953
|
-
const skillDir =
|
|
3953
|
+
const skillDir = join12(this.skillsDir, name);
|
|
3954
3954
|
if (!existsSync12(skillDir)) {
|
|
3955
3955
|
mkdirSync11(skillDir, { recursive: true });
|
|
3956
3956
|
}
|
|
3957
|
-
writeFileSync10(
|
|
3958
|
-
const disabledPath =
|
|
3957
|
+
writeFileSync10(join12(skillDir, SKILL_FILE), content, "utf-8");
|
|
3958
|
+
const disabledPath = join12(skillDir, DISABLED_FILE);
|
|
3959
3959
|
if (existsSync12(disabledPath)) {
|
|
3960
3960
|
unlinkSync5(disabledPath);
|
|
3961
3961
|
}
|
|
@@ -3986,7 +3986,7 @@ var init_loader = __esm({
|
|
|
3986
3986
|
setSkillActive(name, active) {
|
|
3987
3987
|
const entry = this.findSkillEntryByName(name);
|
|
3988
3988
|
if (!entry) return false;
|
|
3989
|
-
const disabledPath =
|
|
3989
|
+
const disabledPath = join12(entry.skillDir, DISABLED_FILE);
|
|
3990
3990
|
if (active) {
|
|
3991
3991
|
if (existsSync12(disabledPath)) unlinkSync5(disabledPath);
|
|
3992
3992
|
} else {
|
|
@@ -4028,7 +4028,7 @@ var init_loader = __esm({
|
|
|
4028
4028
|
const raw = readFileSync10(skillPath, "utf-8");
|
|
4029
4029
|
const parsed = parseSkillMd(raw);
|
|
4030
4030
|
if (parsed?.meta.name === name) {
|
|
4031
|
-
lastMatch =
|
|
4031
|
+
lastMatch = join12(skillPath, "..");
|
|
4032
4032
|
}
|
|
4033
4033
|
} catch {
|
|
4034
4034
|
continue;
|
|
@@ -4042,10 +4042,10 @@ var init_loader = __esm({
|
|
|
4042
4042
|
if (!existsSync12(this.skillsDir)) return out2;
|
|
4043
4043
|
for (const entry of readdirSync4(this.skillsDir, { withFileTypes: true })) {
|
|
4044
4044
|
if (!entry.isDirectory() || entry.name.startsWith("_") || entry.name.startsWith(".")) continue;
|
|
4045
|
-
const dir =
|
|
4046
|
-
const flat =
|
|
4045
|
+
const dir = join12(this.skillsDir, entry.name);
|
|
4046
|
+
const flat = join12(dir, SKILL_FILE);
|
|
4047
4047
|
if (existsSync12(flat)) {
|
|
4048
|
-
out2.push({ skillPath: flat, disabled: existsSync12(
|
|
4048
|
+
out2.push({ skillPath: flat, disabled: existsSync12(join12(dir, DISABLED_FILE)) });
|
|
4049
4049
|
continue;
|
|
4050
4050
|
}
|
|
4051
4051
|
let children = [];
|
|
@@ -4056,17 +4056,17 @@ var init_loader = __esm({
|
|
|
4056
4056
|
}
|
|
4057
4057
|
for (const child of children) {
|
|
4058
4058
|
if (!child.isDirectory() || child.name.startsWith("_") || child.name.startsWith(".")) continue;
|
|
4059
|
-
const childDir =
|
|
4060
|
-
const nested =
|
|
4059
|
+
const childDir = join12(dir, child.name);
|
|
4060
|
+
const nested = join12(childDir, SKILL_FILE);
|
|
4061
4061
|
if (existsSync12(nested)) {
|
|
4062
|
-
out2.push({ skillPath: nested, disabled: existsSync12(
|
|
4062
|
+
out2.push({ skillPath: nested, disabled: existsSync12(join12(childDir, DISABLED_FILE)) });
|
|
4063
4063
|
}
|
|
4064
4064
|
}
|
|
4065
4065
|
}
|
|
4066
4066
|
return out2;
|
|
4067
4067
|
}
|
|
4068
4068
|
seedTemplate() {
|
|
4069
|
-
const templateDir =
|
|
4069
|
+
const templateDir = join12(this.skillsDir, "_template");
|
|
4070
4070
|
mkdirSync11(templateDir, { recursive: true });
|
|
4071
4071
|
const content = `---
|
|
4072
4072
|
name: template-skill
|
|
@@ -4101,13 +4101,13 @@ Describe what this skill enables Mercury to do. When invoked via the use_skill t
|
|
|
4101
4101
|
- The skill name must be unique among installed skills
|
|
4102
4102
|
- Add \`category\`, \`categories\`, \`intents\`, and \`tags\` in frontmatter for automatic intent routing
|
|
4103
4103
|
`;
|
|
4104
|
-
writeFileSync10(
|
|
4104
|
+
writeFileSync10(join12(templateDir, SKILL_FILE), content, "utf-8");
|
|
4105
4105
|
logger.info("Seeded template skill");
|
|
4106
4106
|
}
|
|
4107
4107
|
ensureDefaultSkills() {
|
|
4108
4108
|
for (const seed of DEFAULT_SKILL_SEEDS) {
|
|
4109
|
-
const skillDir =
|
|
4110
|
-
const skillFile =
|
|
4109
|
+
const skillDir = join12(this.skillsDir, seed.dirName);
|
|
4110
|
+
const skillFile = join12(skillDir, seed.fileName);
|
|
4111
4111
|
if (existsSync12(skillFile)) continue;
|
|
4112
4112
|
mkdirSync11(skillDir, { recursive: true });
|
|
4113
4113
|
writeFileSync10(skillFile, seed.content, "utf-8");
|
|
@@ -5735,15 +5735,18 @@ __export(pool_search_exports, {
|
|
|
5735
5735
|
formatPoolContextBlock: () => formatPoolContextBlock,
|
|
5736
5736
|
searchPool: () => searchPool
|
|
5737
5737
|
});
|
|
5738
|
-
import { join as
|
|
5738
|
+
import { join as join14 } from "path";
|
|
5739
5739
|
import { existsSync as existsSync15, mkdirSync as mkdirSync14 } from "fs";
|
|
5740
|
-
import
|
|
5740
|
+
import { createRequire as createRequire2 } from "module";
|
|
5741
|
+
function loadDatabase() {
|
|
5742
|
+
return require3("better-sqlite3");
|
|
5743
|
+
}
|
|
5741
5744
|
function getCacheDb() {
|
|
5742
5745
|
if (cacheDb) return cacheDb;
|
|
5743
5746
|
const dir = getMemoryDir();
|
|
5744
5747
|
if (!existsSync15(dir)) mkdirSync14(dir, { recursive: true });
|
|
5745
|
-
const dbPath =
|
|
5746
|
-
cacheDb =
|
|
5748
|
+
const dbPath = join14(dir, "pool-search-cache.db");
|
|
5749
|
+
cacheDb = loadDatabase()(dbPath);
|
|
5747
5750
|
cacheDb.exec(`
|
|
5748
5751
|
CREATE TABLE IF NOT EXISTS pool_search_cache (
|
|
5749
5752
|
query_hash TEXT PRIMARY KEY,
|
|
@@ -5868,13 +5871,14 @@ function dedupeAgainstLocal(pool, localSummaries, threshold = 0.8) {
|
|
|
5868
5871
|
return true;
|
|
5869
5872
|
});
|
|
5870
5873
|
}
|
|
5871
|
-
var CACHE_TTL_MS, REQUEST_TIMEOUT_MS, MAX_CACHE_ROWS, cacheDb;
|
|
5874
|
+
var require3, CACHE_TTL_MS, REQUEST_TIMEOUT_MS, MAX_CACHE_ROWS, cacheDb;
|
|
5872
5875
|
var init_pool_search = __esm({
|
|
5873
5876
|
"src/cloud/pool-search.ts"() {
|
|
5874
5877
|
"use strict";
|
|
5875
5878
|
init_config();
|
|
5876
5879
|
init_logger();
|
|
5877
5880
|
init_pairing();
|
|
5881
|
+
require3 = createRequire2(import.meta.url);
|
|
5878
5882
|
CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
5879
5883
|
REQUEST_TIMEOUT_MS = 800;
|
|
5880
5884
|
MAX_CACHE_ROWS = 500;
|
|
@@ -5890,9 +5894,9 @@ __export(crash_flag_exports, {
|
|
|
5890
5894
|
writeCrashFlag: () => writeCrashFlag
|
|
5891
5895
|
});
|
|
5892
5896
|
import { existsSync as existsSync16, readFileSync as readFileSync12, writeFileSync as writeFileSync11, unlinkSync as unlinkSync7 } from "fs";
|
|
5893
|
-
import { join as
|
|
5897
|
+
import { join as join15 } from "path";
|
|
5894
5898
|
function crashFlagPath() {
|
|
5895
|
-
return
|
|
5899
|
+
return join15(getMercuryHome(), CRASH_FLAG_FILE);
|
|
5896
5900
|
}
|
|
5897
5901
|
function writeCrashFlag(flag) {
|
|
5898
5902
|
try {
|
|
@@ -5928,7 +5932,7 @@ var init_crash_flag = __esm({
|
|
|
5928
5932
|
// src/cli/daemon.ts
|
|
5929
5933
|
import { spawn as spawn4 } from "child_process";
|
|
5930
5934
|
import { existsSync as existsSync32, readFileSync as readFileSync22, writeFileSync as writeFileSync21, unlinkSync as unlinkSync10, mkdirSync as mkdirSync21, openSync as openSync3 } from "fs";
|
|
5931
|
-
import { join as
|
|
5935
|
+
import { join as join23 } from "path";
|
|
5932
5936
|
import process2 from "process";
|
|
5933
5937
|
import chalk6 from "chalk";
|
|
5934
5938
|
function isStandaloneBinary() {
|
|
@@ -5952,13 +5956,13 @@ function buildDaemonSpawnArgs() {
|
|
|
5952
5956
|
return { command: process2.execPath, args: [script, "start", "--daemon"] };
|
|
5953
5957
|
}
|
|
5954
5958
|
function pidPath() {
|
|
5955
|
-
return
|
|
5959
|
+
return join23(getMercuryHome(), PID_FILE);
|
|
5956
5960
|
}
|
|
5957
5961
|
function foregroundPidPath() {
|
|
5958
|
-
return
|
|
5962
|
+
return join23(getMercuryHome(), FOREGROUND_PID_FILE);
|
|
5959
5963
|
}
|
|
5960
5964
|
function logPath() {
|
|
5961
|
-
return
|
|
5965
|
+
return join23(getMercuryHome(), LOG_FILE);
|
|
5962
5966
|
}
|
|
5963
5967
|
function registerRuntimeProcess(mode) {
|
|
5964
5968
|
const path9 = mode === "daemon" ? pidPath() : foregroundPidPath();
|
|
@@ -6191,7 +6195,7 @@ var init_daemon = __esm({
|
|
|
6191
6195
|
|
|
6192
6196
|
// src/cli/service.ts
|
|
6193
6197
|
import { existsSync as existsSync33, mkdirSync as mkdirSync22, writeFileSync as writeFileSync22, unlinkSync as unlinkSync11 } from "fs";
|
|
6194
|
-
import { join as
|
|
6198
|
+
import { join as join24 } from "path";
|
|
6195
6199
|
import { homedir as homedir8 } from "os";
|
|
6196
6200
|
import chalk7 from "chalk";
|
|
6197
6201
|
import { execSync as execSync8 } from "child_process";
|
|
@@ -6199,9 +6203,9 @@ function isServiceInstalled() {
|
|
|
6199
6203
|
const platform = process.platform;
|
|
6200
6204
|
if (isTermux()) return false;
|
|
6201
6205
|
if (platform === "darwin") {
|
|
6202
|
-
return existsSync33(
|
|
6206
|
+
return existsSync33(join24(homedir8(), "Library", "LaunchAgents", "com.cosmicstack.mercury.plist"));
|
|
6203
6207
|
} else if (platform === "linux") {
|
|
6204
|
-
return existsSync33(
|
|
6208
|
+
return existsSync33(join24(homedir8(), ".config", "systemd", "user", "mercury.service"));
|
|
6205
6209
|
} else if (platform === "win32") {
|
|
6206
6210
|
try {
|
|
6207
6211
|
execSync8(`schtasks /query /tn "${WIN_TASK_NAME}"`, { stdio: "pipe", shell: "cmd.exe" });
|
|
@@ -6237,9 +6241,9 @@ function getNodeBinPath() {
|
|
|
6237
6241
|
}
|
|
6238
6242
|
function getDistPath() {
|
|
6239
6243
|
if (!process.argv[1]) {
|
|
6240
|
-
return
|
|
6244
|
+
return join24(homedir8(), ".nvm", "versions", "node", `v${process.version.slice(1)}`, "lib", "node_modules", "@cosmicstack", "mercury-agent", "dist", "index.js");
|
|
6241
6245
|
}
|
|
6242
|
-
return
|
|
6246
|
+
return join24(process.argv[1], "..", "..", "lib", "node_modules", "@cosmicstack", "mercury-agent", "dist", "index.js");
|
|
6243
6247
|
}
|
|
6244
6248
|
function getServiceLaunchArgs() {
|
|
6245
6249
|
if (isStandaloneBinary()) {
|
|
@@ -6302,7 +6306,7 @@ function restartService() {
|
|
|
6302
6306
|
try {
|
|
6303
6307
|
execSync8(`launchctl kickstart -k ${target}`, { stdio: "inherit" });
|
|
6304
6308
|
} catch {
|
|
6305
|
-
const plistPath =
|
|
6309
|
+
const plistPath = join24(homedir8(), "Library", "LaunchAgents", "com.cosmicstack.mercury.plist");
|
|
6306
6310
|
execSync8(`launchctl load "${plistPath}"`, { stdio: "inherit" });
|
|
6307
6311
|
execSync8(`launchctl kickstart -k ${target}`, { stdio: "inherit" });
|
|
6308
6312
|
}
|
|
@@ -6364,16 +6368,16 @@ function showTermuxServiceHelp(action) {
|
|
|
6364
6368
|
console.log("");
|
|
6365
6369
|
}
|
|
6366
6370
|
function installMac() {
|
|
6367
|
-
const plistDir =
|
|
6368
|
-
const plistPath =
|
|
6371
|
+
const plistDir = join24(homedir8(), "Library", "LaunchAgents");
|
|
6372
|
+
const plistPath = join24(plistDir, "com.cosmicstack.mercury.plist");
|
|
6369
6373
|
if (!existsSync33(plistDir)) {
|
|
6370
6374
|
mkdirSync22(plistDir, { recursive: true });
|
|
6371
6375
|
}
|
|
6372
6376
|
const nodeBin = getNodeBinPath();
|
|
6373
6377
|
const scriptPath = getDistPath();
|
|
6374
6378
|
const home = getMercuryHome();
|
|
6375
|
-
const logPath2 =
|
|
6376
|
-
const errPath =
|
|
6379
|
+
const logPath2 = join24(home, "daemon.log");
|
|
6380
|
+
const errPath = join24(home, "daemon-error.log");
|
|
6377
6381
|
const launchArgs = getServiceLaunchArgs();
|
|
6378
6382
|
const programArgsXml = launchArgs.map((a) => ` <string>${a}</string>`).join("\n");
|
|
6379
6383
|
const plist = `<?xml version="1.0" encoding="UTF-8"?>
|
|
@@ -6425,7 +6429,7 @@ ${programArgsXml}
|
|
|
6425
6429
|
console.log("");
|
|
6426
6430
|
}
|
|
6427
6431
|
function uninstallMac() {
|
|
6428
|
-
const plistPath =
|
|
6432
|
+
const plistPath = join24(homedir8(), "Library", "LaunchAgents", "com.cosmicstack.mercury.plist");
|
|
6429
6433
|
if (!existsSync33(plistPath)) {
|
|
6430
6434
|
console.log(chalk7.yellow(" Mercury service is not installed."));
|
|
6431
6435
|
console.log("");
|
|
@@ -6446,7 +6450,7 @@ function uninstallMac() {
|
|
|
6446
6450
|
console.log("");
|
|
6447
6451
|
}
|
|
6448
6452
|
function showMacStatus() {
|
|
6449
|
-
const plistPath =
|
|
6453
|
+
const plistPath = join24(homedir8(), "Library", "LaunchAgents", "com.cosmicstack.mercury.plist");
|
|
6450
6454
|
if (!existsSync33(plistPath)) {
|
|
6451
6455
|
console.log(chalk7.yellow(" Mercury service is not installed."));
|
|
6452
6456
|
console.log(chalk7.dim(" Run `mercury service install` to set it up."));
|
|
@@ -6464,11 +6468,11 @@ function showMacStatus() {
|
|
|
6464
6468
|
console.log("");
|
|
6465
6469
|
}
|
|
6466
6470
|
function installLinux() {
|
|
6467
|
-
const systemdDir =
|
|
6471
|
+
const systemdDir = join24(homedir8(), ".config", "systemd", "user");
|
|
6468
6472
|
if (!existsSync33(systemdDir)) {
|
|
6469
6473
|
mkdirSync22(systemdDir, { recursive: true });
|
|
6470
6474
|
}
|
|
6471
|
-
const servicePath =
|
|
6475
|
+
const servicePath = join24(systemdDir, "mercury.service");
|
|
6472
6476
|
const nodeBin = getNodeBinPath();
|
|
6473
6477
|
const scriptPath = getDistPath();
|
|
6474
6478
|
const home = getMercuryHome();
|
|
@@ -6485,8 +6489,8 @@ RestartSec=5
|
|
|
6485
6489
|
Environment=PATH=${process.env.PATH || "/usr/local/bin:/usr/bin:/bin"}
|
|
6486
6490
|
Environment=HOME=${homedir8()}
|
|
6487
6491
|
WorkingDirectory=${homedir8()}
|
|
6488
|
-
StandardOutput=append:${
|
|
6489
|
-
StandardError=append:${
|
|
6492
|
+
StandardOutput=append:${join24(home, "daemon.log")}
|
|
6493
|
+
StandardError=append:${join24(home, "daemon-error.log")}
|
|
6490
6494
|
|
|
6491
6495
|
[Install]
|
|
6492
6496
|
WantedBy=default.target`;
|
|
@@ -6510,14 +6514,14 @@ WantedBy=default.target`;
|
|
|
6510
6514
|
console.log("");
|
|
6511
6515
|
console.log(chalk7.green(" Mercury service installed (systemd --user)"));
|
|
6512
6516
|
console.log(chalk7.dim(` Service: ${servicePath}`));
|
|
6513
|
-
console.log(chalk7.dim(` Logs: ${
|
|
6517
|
+
console.log(chalk7.dim(` Logs: ${join24(home, "daemon.log")}`));
|
|
6514
6518
|
console.log(chalk7.dim(" Auto-starts on login. Auto-restarts on crash (5s delay)."));
|
|
6515
6519
|
console.log("");
|
|
6516
6520
|
console.log(chalk7.dim(" Uninstall: mercury service uninstall"));
|
|
6517
6521
|
console.log("");
|
|
6518
6522
|
}
|
|
6519
6523
|
function uninstallLinux() {
|
|
6520
|
-
const servicePath =
|
|
6524
|
+
const servicePath = join24(homedir8(), ".config", "systemd", "user", "mercury.service");
|
|
6521
6525
|
if (!existsSync33(servicePath)) {
|
|
6522
6526
|
console.log(chalk7.yellow(" Mercury service is not installed."));
|
|
6523
6527
|
console.log("");
|
|
@@ -6543,7 +6547,7 @@ function uninstallLinux() {
|
|
|
6543
6547
|
console.log("");
|
|
6544
6548
|
}
|
|
6545
6549
|
function showLinuxStatus() {
|
|
6546
|
-
const servicePath =
|
|
6550
|
+
const servicePath = join24(homedir8(), ".config", "systemd", "user", "mercury.service");
|
|
6547
6551
|
if (!existsSync33(servicePath)) {
|
|
6548
6552
|
console.log(chalk7.yellow(" Mercury service is not installed."));
|
|
6549
6553
|
console.log(chalk7.dim(" Run `mercury service install` to set it up."));
|
|
@@ -6563,7 +6567,7 @@ function installWindows() {
|
|
|
6563
6567
|
const nodeBin = getNodeBinPath();
|
|
6564
6568
|
const scriptPath = getDistPath();
|
|
6565
6569
|
const home = getMercuryHome();
|
|
6566
|
-
const logPath2 =
|
|
6570
|
+
const logPath2 = join24(home, "daemon.log");
|
|
6567
6571
|
const cmd = getServiceLaunchArgs().map((a) => `"${a}"`).join(" ");
|
|
6568
6572
|
try {
|
|
6569
6573
|
execSync8(
|
|
@@ -6629,9 +6633,9 @@ var init_service = __esm({
|
|
|
6629
6633
|
|
|
6630
6634
|
// src/cloud/runtime-status.ts
|
|
6631
6635
|
import { existsSync as existsSync34, readFileSync as readFileSync23, unlinkSync as unlinkSync12, writeFileSync as writeFileSync23 } from "fs";
|
|
6632
|
-
import { join as
|
|
6636
|
+
import { join as join25 } from "path";
|
|
6633
6637
|
function statusPath() {
|
|
6634
|
-
return
|
|
6638
|
+
return join25(getMercuryHome(), "cloud-online.json");
|
|
6635
6639
|
}
|
|
6636
6640
|
function markCloudRuntimeOnline(agentId, mode) {
|
|
6637
6641
|
writeFileSync23(statusPath(), JSON.stringify({ agentId, mode, pid: process.pid, connectedAt: Date.now() }), {
|
|
@@ -6653,6 +6657,25 @@ function clearCloudRuntimeOnline(ownerPid) {
|
|
|
6653
6657
|
} catch {
|
|
6654
6658
|
}
|
|
6655
6659
|
}
|
|
6660
|
+
function isCloudRuntimeOnline(agentId, mode) {
|
|
6661
|
+
if (!existsSync34(statusPath())) return false;
|
|
6662
|
+
try {
|
|
6663
|
+
const status2 = JSON.parse(readFileSync23(statusPath(), "utf-8"));
|
|
6664
|
+
if (status2.agentId !== agentId || !status2.pid || mode && status2.mode !== mode) return false;
|
|
6665
|
+
process.kill(status2.pid, 0);
|
|
6666
|
+
return true;
|
|
6667
|
+
} catch {
|
|
6668
|
+
return false;
|
|
6669
|
+
}
|
|
6670
|
+
}
|
|
6671
|
+
async function waitForCloudRuntimeOnline(agentId, timeoutMs = 2e4, mode) {
|
|
6672
|
+
const deadline = Date.now() + timeoutMs;
|
|
6673
|
+
while (Date.now() < deadline) {
|
|
6674
|
+
if (isCloudRuntimeOnline(agentId, mode)) return true;
|
|
6675
|
+
await new Promise((resolve19) => setTimeout(resolve19, 200));
|
|
6676
|
+
}
|
|
6677
|
+
return false;
|
|
6678
|
+
}
|
|
6656
6679
|
var init_runtime_status = __esm({
|
|
6657
6680
|
"src/cloud/runtime-status.ts"() {
|
|
6658
6681
|
"use strict";
|
|
@@ -7981,7 +8004,7 @@ async function runCloudConnect() {
|
|
|
7981
8004
|
console.log(chalk8.dim(` Agent ID: ${config2.cloud.agentId}`));
|
|
7982
8005
|
console.log(chalk8.dim(` Tier: ${config2.cloud.tier || "free"}`));
|
|
7983
8006
|
console.log(chalk8.dim(` API URL: ${config2.cloud.apiUrl}`));
|
|
7984
|
-
await
|
|
8007
|
+
await activateCloudRuntime(config2.cloud.agentId, false);
|
|
7985
8008
|
return;
|
|
7986
8009
|
}
|
|
7987
8010
|
if (config2.cloud.refreshToken) {
|
|
@@ -8005,7 +8028,7 @@ async function runCloudConnect() {
|
|
|
8005
8028
|
console.log(chalk8.red(` \u2717 Token refresh failed: ${err.message}`));
|
|
8006
8029
|
}
|
|
8007
8030
|
if (refreshed) {
|
|
8008
|
-
await
|
|
8031
|
+
await activateCloudRuntime(config2.cloud.agentId, true);
|
|
8009
8032
|
return;
|
|
8010
8033
|
}
|
|
8011
8034
|
}
|
|
@@ -8033,7 +8056,7 @@ async function runCloudConnect() {
|
|
|
8033
8056
|
console.log(chalk8.red(` \u2717 Agent API key recovery failed: ${err.message}`));
|
|
8034
8057
|
}
|
|
8035
8058
|
if (recovered) {
|
|
8036
|
-
await
|
|
8059
|
+
await activateCloudRuntime(config2.cloud.agentId, true);
|
|
8037
8060
|
return;
|
|
8038
8061
|
}
|
|
8039
8062
|
}
|
|
@@ -8064,7 +8087,7 @@ async function runCloudConnect() {
|
|
|
8064
8087
|
console.log(chalk8.dim(` Tier: ${result.cloudConfig.tier}`));
|
|
8065
8088
|
console.log(chalk8.dim(` Model: ${result.model}`));
|
|
8066
8089
|
console.log("");
|
|
8067
|
-
await
|
|
8090
|
+
await activateCloudRuntime(result.cloudConfig.agentId, true);
|
|
8068
8091
|
}
|
|
8069
8092
|
async function runCloudDisconnect() {
|
|
8070
8093
|
const daemonWasRunning = getDaemonStatus().running;
|
|
@@ -8165,25 +8188,35 @@ async function runCloudLogin() {
|
|
|
8165
8188
|
console.log(chalk8.yellow(" Run `mercury cloud connect` to re-pair."));
|
|
8166
8189
|
return;
|
|
8167
8190
|
}
|
|
8168
|
-
await
|
|
8191
|
+
await activateCloudRuntime(config2.cloud.agentId, true);
|
|
8169
8192
|
}
|
|
8170
|
-
async function
|
|
8193
|
+
async function activateCloudRuntime(agentId, credentialsChanged) {
|
|
8194
|
+
const foreground = getForegroundRuntimeStatus();
|
|
8171
8195
|
const daemon = getDaemonStatus();
|
|
8172
8196
|
const serviceRunning = isServiceRunning();
|
|
8173
|
-
|
|
8174
|
-
|
|
8175
|
-
|
|
8176
|
-
|
|
8177
|
-
|
|
8178
|
-
return;
|
|
8179
|
-
}
|
|
8197
|
+
const hadManagedRuntime = daemon.running || serviceRunning;
|
|
8198
|
+
if (foreground.running) {
|
|
8199
|
+
if (!credentialsChanged && isCloudRuntimeOnline(agentId, "foreground")) {
|
|
8200
|
+
console.log(chalk8.green(` Mercury Cloud WebSocket is already online in foreground PID ${foreground.pid}.`));
|
|
8201
|
+
return;
|
|
8180
8202
|
}
|
|
8181
|
-
|
|
8182
|
-
|
|
8183
|
-
|
|
8184
|
-
|
|
8185
|
-
console.log(chalk8.green(" \u2713 Mercury daemon started in the background."));
|
|
8203
|
+
if (!hadManagedRuntime) {
|
|
8204
|
+
throw new Error("Cloud credentials were saved, but Mercury is running only in the foreground. Restart that foreground session to activate its Cloud WebSocket");
|
|
8205
|
+
}
|
|
8206
|
+
console.log(chalk8.yellow(` Foreground Mercury (PID: ${foreground.pid}) keeps its local session while the managed Cloud runtime restarts.`));
|
|
8186
8207
|
}
|
|
8208
|
+
clearCloudRuntimeOnline();
|
|
8209
|
+
if (daemon.running) {
|
|
8210
|
+
console.log(chalk8.dim(` Restarting Mercury (PID: ${daemon.pid}) to activate Cloud...`));
|
|
8211
|
+
if (!await stopDaemon()) {
|
|
8212
|
+
throw new Error("Cloud credentials were saved, but the running Mercury process could not be restarted");
|
|
8213
|
+
}
|
|
8214
|
+
}
|
|
8215
|
+
startManagedRuntime();
|
|
8216
|
+
if (!await waitForCloudRuntimeOnline(agentId, 2e4, "daemon")) {
|
|
8217
|
+
throw new Error("Mercury restarted, but its Cloud WebSocket did not become online within 20 seconds");
|
|
8218
|
+
}
|
|
8219
|
+
console.log(chalk8.green(" \u2713 Mercury daemon restarted with Cloud credentials."));
|
|
8187
8220
|
}
|
|
8188
8221
|
function startManagedRuntime() {
|
|
8189
8222
|
if (isServiceInstalled()) {
|
|
@@ -8569,7 +8602,7 @@ init_logger();
|
|
|
8569
8602
|
init_redact();
|
|
8570
8603
|
import { readFileSync as readFileSync31, writeFileSync as writeFileSync27, existsSync as existsSync42 } from "fs";
|
|
8571
8604
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
8572
|
-
import { dirname as dirname9, join as
|
|
8605
|
+
import { dirname as dirname9, join as join33 } from "path";
|
|
8573
8606
|
import { Command } from "commander";
|
|
8574
8607
|
import readline2 from "readline";
|
|
8575
8608
|
import chalk9 from "chalk";
|
|
@@ -11786,7 +11819,7 @@ init_logger();
|
|
|
11786
11819
|
init_config();
|
|
11787
11820
|
import { spawn } from "child_process";
|
|
11788
11821
|
import { existsSync as existsSync9, mkdirSync as mkdirSync8, readFileSync as readFileSync7, writeFileSync as writeFileSync7 } from "fs";
|
|
11789
|
-
import { join as
|
|
11822
|
+
import { join as join9 } from "path";
|
|
11790
11823
|
var MAX_OUTPUT = 1024 * 1024;
|
|
11791
11824
|
var MAX_TASKS = 20;
|
|
11792
11825
|
var PRUNE_AGE_MS = 60 * 60 * 1e3;
|
|
@@ -12244,7 +12277,7 @@ Recovered after restart: task was running when process exited.`.trim();
|
|
|
12244
12277
|
}
|
|
12245
12278
|
save() {
|
|
12246
12279
|
try {
|
|
12247
|
-
const dir =
|
|
12280
|
+
const dir = join9(getMercuryHome(), "memory");
|
|
12248
12281
|
if (!existsSync9(dir)) {
|
|
12249
12282
|
mkdirSync8(dir, { recursive: true });
|
|
12250
12283
|
}
|
|
@@ -12254,7 +12287,7 @@ Recovered after restart: task was running when process exited.`.trim();
|
|
|
12254
12287
|
}
|
|
12255
12288
|
}
|
|
12256
12289
|
getFilePath() {
|
|
12257
|
-
return
|
|
12290
|
+
return join9(getMercuryHome(), "memory", BG_TASKS_FILE);
|
|
12258
12291
|
}
|
|
12259
12292
|
toSummary(task) {
|
|
12260
12293
|
const combined = task.stdout + "\n" + task.stderr;
|
|
@@ -20863,7 +20896,7 @@ init_provider_models();
|
|
|
20863
20896
|
init_config();
|
|
20864
20897
|
init_logger();
|
|
20865
20898
|
import { chmodSync as chmodSync2, closeSync as closeSync2, existsSync as existsSync14, fsyncSync, mkdirSync as mkdirSync13, openSync as openSync2, readFileSync as readFileSync11, renameSync as renameSync4, unlinkSync as unlinkSync6, writeSync } from "fs";
|
|
20866
|
-
import { dirname as dirname3, join as
|
|
20899
|
+
import { dirname as dirname3, join as join13 } from "path";
|
|
20867
20900
|
import { z as z2 } from "zod";
|
|
20868
20901
|
var channelMessageSchema = z2.object({
|
|
20869
20902
|
id: z2.string(),
|
|
@@ -20911,7 +20944,7 @@ var WorkLedger = class {
|
|
|
20911
20944
|
terminalMaxAgeMs;
|
|
20912
20945
|
now;
|
|
20913
20946
|
constructor(options = {}) {
|
|
20914
|
-
this.filePath = options.filePath ??
|
|
20947
|
+
this.filePath = options.filePath ?? join13(getMercuryHome(), "work-ledger.json");
|
|
20915
20948
|
this.maxTerminalEntries = options.maxTerminalEntries ?? DEFAULT_MAX_TERMINAL_ENTRIES;
|
|
20916
20949
|
this.terminalMaxAgeMs = options.terminalMaxAgeMs ?? DEFAULT_TERMINAL_MAX_AGE_MS;
|
|
20917
20950
|
this.now = options.now ?? Date.now;
|
|
@@ -26156,11 +26189,11 @@ init_config();
|
|
|
26156
26189
|
init_logger();
|
|
26157
26190
|
import cron from "node-cron";
|
|
26158
26191
|
import { existsSync as existsSync18, readFileSync as readFileSync13, writeFileSync as writeFileSync12, mkdirSync as mkdirSync15 } from "fs";
|
|
26159
|
-
import { join as
|
|
26192
|
+
import { join as join16 } from "path";
|
|
26160
26193
|
import { parse as parseYaml4, stringify as stringifyYaml2 } from "yaml";
|
|
26161
26194
|
var SCHEDULES_FILE = "schedules.yaml";
|
|
26162
26195
|
function getSchedulesPath() {
|
|
26163
|
-
return
|
|
26196
|
+
return join16(getMercuryHome(), SCHEDULES_FILE);
|
|
26164
26197
|
}
|
|
26165
26198
|
function loadSchedules() {
|
|
26166
26199
|
const path9 = getSchedulesPath();
|
|
@@ -26813,7 +26846,7 @@ var FileLockManager = class {
|
|
|
26813
26846
|
init_config();
|
|
26814
26847
|
init_logger();
|
|
26815
26848
|
import { readFileSync as readFileSync14, writeFileSync as writeFileSync13, existsSync as existsSync19, mkdirSync as mkdirSync16 } from "fs";
|
|
26816
|
-
import { join as
|
|
26849
|
+
import { join as join17 } from "path";
|
|
26817
26850
|
var TASK_BOARD_FILE = "task-board.json";
|
|
26818
26851
|
var TaskBoard = class {
|
|
26819
26852
|
entries = /* @__PURE__ */ new Map();
|
|
@@ -26835,7 +26868,7 @@ var TaskBoard = class {
|
|
|
26835
26868
|
}
|
|
26836
26869
|
save() {
|
|
26837
26870
|
const filePath = this.getFilePath();
|
|
26838
|
-
const dir =
|
|
26871
|
+
const dir = join17(getMercuryHome(), "memory");
|
|
26839
26872
|
if (!existsSync19(dir)) {
|
|
26840
26873
|
mkdirSync16(dir, { recursive: true });
|
|
26841
26874
|
}
|
|
@@ -26896,7 +26929,7 @@ var TaskBoard = class {
|
|
|
26896
26929
|
return `a${max + 1}`;
|
|
26897
26930
|
}
|
|
26898
26931
|
getFilePath() {
|
|
26899
|
-
return
|
|
26932
|
+
return join17(getMercuryHome(), "memory", TASK_BOARD_FILE);
|
|
26900
26933
|
}
|
|
26901
26934
|
};
|
|
26902
26935
|
|
|
@@ -27301,7 +27334,7 @@ Error: ${result.error || "unknown"}`);
|
|
|
27301
27334
|
init_config();
|
|
27302
27335
|
init_logger();
|
|
27303
27336
|
import { readFileSync as readFileSync15, writeFileSync as writeFileSync14, existsSync as existsSync20, mkdirSync as mkdirSync17 } from "fs";
|
|
27304
|
-
import { join as
|
|
27337
|
+
import { join as join18 } from "path";
|
|
27305
27338
|
var BOARDS_FILE = "boards.json";
|
|
27306
27339
|
var BoardManager = class {
|
|
27307
27340
|
boards = /* @__PURE__ */ new Map();
|
|
@@ -27344,7 +27377,7 @@ var BoardManager = class {
|
|
|
27344
27377
|
}
|
|
27345
27378
|
}
|
|
27346
27379
|
save(changedBoardId) {
|
|
27347
|
-
const dir =
|
|
27380
|
+
const dir = join18(getMercuryHome(), "memory");
|
|
27348
27381
|
if (!existsSync20(dir)) {
|
|
27349
27382
|
mkdirSync17(dir, { recursive: true });
|
|
27350
27383
|
}
|
|
@@ -27904,7 +27937,7 @@ ${depResults.join("\n")}`);
|
|
|
27904
27937
|
`;
|
|
27905
27938
|
}
|
|
27906
27939
|
getFilePath() {
|
|
27907
|
-
return
|
|
27940
|
+
return join18(getMercuryHome(), "memory", BOARDS_FILE);
|
|
27908
27941
|
}
|
|
27909
27942
|
};
|
|
27910
27943
|
|
|
@@ -28471,7 +28504,7 @@ var ChannelRegistry = class {
|
|
|
28471
28504
|
init_config();
|
|
28472
28505
|
init_logger();
|
|
28473
28506
|
import { existsSync as existsSync21, readFileSync as readFileSync16, writeFileSync as writeFileSync15 } from "fs";
|
|
28474
|
-
import { join as
|
|
28507
|
+
import { join as join19 } from "path";
|
|
28475
28508
|
var TOKEN_FILE = "token-usage.json";
|
|
28476
28509
|
function safeNumber(value) {
|
|
28477
28510
|
if (value === null || value === void 0) return 0;
|
|
@@ -28637,7 +28670,7 @@ var TokenBudget = class {
|
|
|
28637
28670
|
}
|
|
28638
28671
|
}
|
|
28639
28672
|
persist() {
|
|
28640
|
-
const path9 =
|
|
28673
|
+
const path9 = join19(getMercuryHome(), TOKEN_FILE);
|
|
28641
28674
|
try {
|
|
28642
28675
|
const data = {
|
|
28643
28676
|
dailyUsed: this.sanitizeCount(this.dailyUsed),
|
|
@@ -28651,7 +28684,7 @@ var TokenBudget = class {
|
|
|
28651
28684
|
}
|
|
28652
28685
|
}
|
|
28653
28686
|
restore() {
|
|
28654
|
-
const path9 =
|
|
28687
|
+
const path9 = join19(getMercuryHome(), TOKEN_FILE);
|
|
28655
28688
|
if (!existsSync21(path9)) return;
|
|
28656
28689
|
try {
|
|
28657
28690
|
const raw = readFileSync16(path9, "utf-8");
|
|
@@ -28713,7 +28746,7 @@ var TokenBudget = class {
|
|
|
28713
28746
|
init_config();
|
|
28714
28747
|
init_logger();
|
|
28715
28748
|
import { existsSync as existsSync22, readFileSync as readFileSync17, writeFileSync as writeFileSync16, mkdirSync as mkdirSync19 } from "fs";
|
|
28716
|
-
import { join as
|
|
28749
|
+
import { join as join20, resolve as resolve5, sep as sep2 } from "path";
|
|
28717
28750
|
import { homedir as homedir5 } from "os";
|
|
28718
28751
|
import { parse as parseYaml5, stringify as stringifyYaml3 } from "yaml";
|
|
28719
28752
|
var DEFAULT_MANIFEST = {
|
|
@@ -28820,7 +28853,7 @@ var DEFAULT_MANIFEST = {
|
|
|
28820
28853
|
}
|
|
28821
28854
|
}
|
|
28822
28855
|
};
|
|
28823
|
-
var PERMISSIONS_FILE =
|
|
28856
|
+
var PERMISSIONS_FILE = join20(getMercuryHome(), "permissions.yaml");
|
|
28824
28857
|
function splitShellSegments(command) {
|
|
28825
28858
|
const out2 = [];
|
|
28826
28859
|
let buf = "";
|
|
@@ -29477,7 +29510,7 @@ function createCreateFileTool(permissions, getCwd) {
|
|
|
29477
29510
|
import { tool as tool5, zodSchema as zodSchema5 } from "ai";
|
|
29478
29511
|
import { z as z6 } from "zod";
|
|
29479
29512
|
import { existsSync as existsSync26, readdirSync as readdirSync5, statSync } from "fs";
|
|
29480
|
-
import { resolve as resolve9, isAbsolute as isAbsolute4, join as
|
|
29513
|
+
import { resolve as resolve9, isAbsolute as isAbsolute4, join as join21 } from "path";
|
|
29481
29514
|
function createListDirTool(permissions, getCwd) {
|
|
29482
29515
|
return tool5({
|
|
29483
29516
|
description: "List the contents of a directory. Shows file names, types, and sizes.",
|
|
@@ -29501,7 +29534,7 @@ function createListDirTool(permissions, getCwd) {
|
|
|
29501
29534
|
const entries = readdirSync5(resolved, { withFileTypes: true });
|
|
29502
29535
|
const lines = entries.map((entry) => {
|
|
29503
29536
|
const isDir = entry.isDirectory();
|
|
29504
|
-
const fullPath =
|
|
29537
|
+
const fullPath = join21(resolved, entry.name);
|
|
29505
29538
|
let size = "";
|
|
29506
29539
|
try {
|
|
29507
29540
|
if (!isDir) {
|
|
@@ -30302,7 +30335,7 @@ import { tool as tool27, zodSchema as zodSchema27 } from "ai";
|
|
|
30302
30335
|
import { z as z28 } from "zod";
|
|
30303
30336
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
30304
30337
|
import { writeFileSync as writeFileSync20, unlinkSync as unlinkSync9 } from "fs";
|
|
30305
|
-
import { join as
|
|
30338
|
+
import { join as join22 } from "path";
|
|
30306
30339
|
var CO_AUTHOR = "Mercury <mercury@cosmicstack.org>";
|
|
30307
30340
|
function createGitCommitTool(permissions, getCwd) {
|
|
30308
30341
|
return tool27({
|
|
@@ -30318,7 +30351,7 @@ function createGitCommitTool(permissions, getCwd) {
|
|
|
30318
30351
|
|
|
30319
30352
|
Co-authored-by: ${CO_AUTHOR}`;
|
|
30320
30353
|
const cwd = getCwd();
|
|
30321
|
-
const msgFilePath =
|
|
30354
|
+
const msgFilePath = join22(cwd, ".git", "MERCU_MSG");
|
|
30322
30355
|
writeFileSync20(msgFilePath, fullMessage, "utf-8");
|
|
30323
30356
|
const result = execFileSync2("git", ["commit", "-F", msgFilePath], {
|
|
30324
30357
|
encoding: "utf-8",
|
|
@@ -30332,7 +30365,7 @@ Co-authored-by: ${CO_AUTHOR}`;
|
|
|
30332
30365
|
return result.trim() || "Committed successfully.";
|
|
30333
30366
|
} catch (err) {
|
|
30334
30367
|
try {
|
|
30335
|
-
unlinkSync9(
|
|
30368
|
+
unlinkSync9(join22(getCwd(), ".git", "MERCU_MSG"));
|
|
30336
30369
|
} catch {
|
|
30337
30370
|
}
|
|
30338
30371
|
const stderr = err.stderr?.trim() || "";
|
|
@@ -31801,7 +31834,7 @@ init_logger();
|
|
|
31801
31834
|
import { Hono as Hono12 } from "hono";
|
|
31802
31835
|
import { createAdaptorServer } from "@hono/node-server";
|
|
31803
31836
|
import { readFileSync as readFileSync30, existsSync as existsSync41, readdirSync as readdirSync7 } from "fs";
|
|
31804
|
-
import { join as
|
|
31837
|
+
import { join as join32, dirname as dirname8 } from "path";
|
|
31805
31838
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
31806
31839
|
|
|
31807
31840
|
// src/web/middleware.ts
|
|
@@ -31811,12 +31844,12 @@ import { getCookie } from "hono/cookie";
|
|
|
31811
31844
|
init_config();
|
|
31812
31845
|
import { compareSync, hashSync, genSaltSync } from "bcryptjs";
|
|
31813
31846
|
import { readFileSync as readFileSync24, writeFileSync as writeFileSync24, existsSync as existsSync35, mkdirSync as mkdirSync23 } from "fs";
|
|
31814
|
-
import { join as
|
|
31847
|
+
import { join as join26 } from "path";
|
|
31815
31848
|
import { randomBytes } from "crypto";
|
|
31816
31849
|
var SESSION_COOKIE = "mercury_session";
|
|
31817
31850
|
var SESSION_MAX_AGE = 7 * 24 * 60 * 60;
|
|
31818
31851
|
function getWebConfigPath() {
|
|
31819
|
-
return
|
|
31852
|
+
return join26(getMercuryHome(), "web-config.json");
|
|
31820
31853
|
}
|
|
31821
31854
|
function getWebPort() {
|
|
31822
31855
|
const envPort = parseInt(process.env.MERCURY_PORT || "", 10);
|
|
@@ -31907,7 +31940,7 @@ function createSessionToken() {
|
|
|
31907
31940
|
var sessions = /* @__PURE__ */ new Map();
|
|
31908
31941
|
var SESSION_FILE = "web-sessions.json";
|
|
31909
31942
|
function getSessionFilePath() {
|
|
31910
|
-
return
|
|
31943
|
+
return join26(getMercuryHome(), SESSION_FILE);
|
|
31911
31944
|
}
|
|
31912
31945
|
function persistSessions() {
|
|
31913
31946
|
try {
|
|
@@ -32002,15 +32035,15 @@ async function errorHandler(c, next) {
|
|
|
32002
32035
|
import { Hono } from "hono";
|
|
32003
32036
|
import { setCookie, getCookie as getCookie2 } from "hono/cookie";
|
|
32004
32037
|
import { existsSync as existsSync36, readFileSync as readFileSync25 } from "fs";
|
|
32005
|
-
import { join as
|
|
32038
|
+
import { join as join27, dirname as dirname7 } from "path";
|
|
32006
32039
|
import { fileURLToPath } from "url";
|
|
32007
32040
|
import process3 from "process";
|
|
32008
32041
|
function resolveWebDir(...segments) {
|
|
32009
32042
|
const __dirname3 = dirname7(fileURLToPath(import.meta.url));
|
|
32010
32043
|
if (typeof process3.versions.bun === "string" && __dirname3.includes("$bunfs")) {
|
|
32011
|
-
return
|
|
32044
|
+
return join27(dirname7(process3.execPath), ...segments);
|
|
32012
32045
|
}
|
|
32013
|
-
return
|
|
32046
|
+
return join27(__dirname3, ...segments);
|
|
32014
32047
|
}
|
|
32015
32048
|
var spaLoginIndex = resolveWebDir("web", "ui", "index.html");
|
|
32016
32049
|
function renderLoginPage(error) {
|
|
@@ -32237,7 +32270,7 @@ init_registry();
|
|
|
32237
32270
|
init_store();
|
|
32238
32271
|
import { Hono as Hono5 } from "hono";
|
|
32239
32272
|
import { existsSync as existsSync37, readFileSync as readFileSync26 } from "fs";
|
|
32240
|
-
import { join as
|
|
32273
|
+
import { join as join28 } from "path";
|
|
32241
32274
|
init_config();
|
|
32242
32275
|
import cron3 from "node-cron";
|
|
32243
32276
|
var system = new Hono5();
|
|
@@ -32363,7 +32396,7 @@ system.put("/api/permissions", async (c) => {
|
|
|
32363
32396
|
return c.json({ success: true, manifest: next });
|
|
32364
32397
|
});
|
|
32365
32398
|
system.get("/api/usage", (c) => {
|
|
32366
|
-
const usagePath =
|
|
32399
|
+
const usagePath = join28(getMercuryHome(), "token-usage.json");
|
|
32367
32400
|
let data = {
|
|
32368
32401
|
dailyUsed: 0,
|
|
32369
32402
|
dailyBudget: 0,
|
|
@@ -32451,7 +32484,7 @@ var system_default = system;
|
|
|
32451
32484
|
// src/web/api/brain.ts
|
|
32452
32485
|
init_config();
|
|
32453
32486
|
import { Hono as Hono6 } from "hono";
|
|
32454
|
-
import { join as
|
|
32487
|
+
import { join as join29 } from "path";
|
|
32455
32488
|
var userMemory = null;
|
|
32456
32489
|
var SQLITE_DEPENDENCY_ERROR = "Second brain dependency issue: better-sqlite3 (SQLite backend) is not available. Install dependencies and restart Mercury.";
|
|
32457
32490
|
function setUserMemory(mem) {
|
|
@@ -32462,7 +32495,7 @@ function ensureMemory() {
|
|
|
32462
32495
|
if (!isBetterSqlite3Available()) return null;
|
|
32463
32496
|
try {
|
|
32464
32497
|
const config2 = loadConfig();
|
|
32465
|
-
const dbPath =
|
|
32498
|
+
const dbPath = join29(getMemoryDir(), "second-brain", "second-brain.db");
|
|
32466
32499
|
userMemory = new UserMemoryStore(config2, "user:owner", dbPath);
|
|
32467
32500
|
return userMemory;
|
|
32468
32501
|
} catch (err) {
|
|
@@ -32693,7 +32726,7 @@ var brain_default = brain;
|
|
|
32693
32726
|
init_config();
|
|
32694
32727
|
import { Hono as Hono7 } from "hono";
|
|
32695
32728
|
import { existsSync as existsSync38, readFileSync as readFileSync27, writeFileSync as writeFileSync25, readdirSync as readdirSync6, statSync as statSync4 } from "fs";
|
|
32696
|
-
import { join as
|
|
32729
|
+
import { join as join30, extname, basename as basename4, relative as relative2, resolve as resolve17 } from "path";
|
|
32697
32730
|
var webChannel = null;
|
|
32698
32731
|
var programmingMode = null;
|
|
32699
32732
|
var modelSwitchFn = null;
|
|
@@ -32734,7 +32767,7 @@ function setModelSwitchCallback(fn) {
|
|
|
32734
32767
|
function setCurrentProviderCallback(fn) {
|
|
32735
32768
|
currentProviderFn = fn;
|
|
32736
32769
|
}
|
|
32737
|
-
var CHAT_SETTINGS_FILE =
|
|
32770
|
+
var CHAT_SETTINGS_FILE = join30(getMercuryHome(), "web-chat-settings.json");
|
|
32738
32771
|
function loadSettings() {
|
|
32739
32772
|
if (!existsSync38(CHAT_SETTINGS_FILE)) {
|
|
32740
32773
|
return { bypassPermissions: false, restrictUser: false, workspace: "" };
|
|
@@ -32971,7 +33004,7 @@ chat.get("/api/workspace/tree", (c) => {
|
|
|
32971
33004
|
try {
|
|
32972
33005
|
const entries = readdirSync6(targetDir, { withFileTypes: true });
|
|
32973
33006
|
const items = entries.filter((e) => !IGNORED_DIRS.has(e.name) && !e.name.startsWith(".")).map((e) => {
|
|
32974
|
-
const fullPath =
|
|
33007
|
+
const fullPath = join30(targetDir, e.name);
|
|
32975
33008
|
const relPath = relative2(rootDir, fullPath);
|
|
32976
33009
|
const isDir = e.isDirectory();
|
|
32977
33010
|
const ext = isDir ? "" : extname(e.name);
|
|
@@ -33315,13 +33348,13 @@ init_platform();
|
|
|
33315
33348
|
import { Hono as Hono11 } from "hono";
|
|
33316
33349
|
import { execSync as execSync9 } from "child_process";
|
|
33317
33350
|
import { existsSync as existsSync40, readFileSync as readFileSync29, writeFileSync as writeFileSync26 } from "fs";
|
|
33318
|
-
import { join as
|
|
33351
|
+
import { join as join31, resolve as resolve18, basename as basename5 } from "path";
|
|
33319
33352
|
import { generateText as generateText7 } from "ai";
|
|
33320
33353
|
var providerRegistry2;
|
|
33321
33354
|
function setIDEProviders(pr) {
|
|
33322
33355
|
providerRegistry2 = pr;
|
|
33323
33356
|
}
|
|
33324
|
-
var CHAT_SETTINGS_FILE2 =
|
|
33357
|
+
var CHAT_SETTINGS_FILE2 = join31(getMercuryHome(), "web-chat-settings.json");
|
|
33325
33358
|
function getWorkspaceRoot() {
|
|
33326
33359
|
try {
|
|
33327
33360
|
if (existsSync40(CHAT_SETTINGS_FILE2)) {
|
|
@@ -33581,14 +33614,14 @@ ide.get("/api/workspace/info", (c) => {
|
|
|
33581
33614
|
} catch {
|
|
33582
33615
|
}
|
|
33583
33616
|
let projectType = "unknown";
|
|
33584
|
-
if (existsSync40(
|
|
33585
|
-
else if (existsSync40(
|
|
33586
|
-
else if (existsSync40(
|
|
33587
|
-
else if (existsSync40(
|
|
33617
|
+
if (existsSync40(join31(cwd, "package.json"))) projectType = "node";
|
|
33618
|
+
else if (existsSync40(join31(cwd, "Cargo.toml"))) projectType = "rust";
|
|
33619
|
+
else if (existsSync40(join31(cwd, "go.mod"))) projectType = "go";
|
|
33620
|
+
else if (existsSync40(join31(cwd, "pyproject.toml")) || existsSync40(join31(cwd, "setup.py"))) projectType = "python";
|
|
33588
33621
|
let projectName = basename5(cwd);
|
|
33589
33622
|
try {
|
|
33590
33623
|
if (projectType === "node") {
|
|
33591
|
-
const pkg = JSON.parse(readFileSync29(
|
|
33624
|
+
const pkg = JSON.parse(readFileSync29(join31(cwd, "package.json"), "utf8"));
|
|
33592
33625
|
projectName = pkg.name || projectName;
|
|
33593
33626
|
}
|
|
33594
33627
|
} catch {
|
|
@@ -33679,9 +33712,9 @@ function resolveWebDir2(subpath) {
|
|
|
33679
33712
|
const envVar = subpath === "static" ? process.env.MERCURY_WEB_STATIC : process.env.MERCURY_UI_DIR;
|
|
33680
33713
|
if (envVar) return envVar;
|
|
33681
33714
|
if (typeof process.versions.bun === "string" && __dirname.includes("$bunfs")) {
|
|
33682
|
-
return
|
|
33715
|
+
return join32(dirname8(process.execPath), "web", subpath);
|
|
33683
33716
|
}
|
|
33684
|
-
return
|
|
33717
|
+
return join32(__dirname, "web", subpath);
|
|
33685
33718
|
}
|
|
33686
33719
|
var staticDir = resolveWebDir2("static");
|
|
33687
33720
|
var uiDir = resolveWebDir2("ui");
|
|
@@ -33698,7 +33731,7 @@ var MIME_TYPES = {
|
|
|
33698
33731
|
webmanifest: "application/manifest+json",
|
|
33699
33732
|
map: "application/json"
|
|
33700
33733
|
};
|
|
33701
|
-
var spaIndexPath =
|
|
33734
|
+
var spaIndexPath = join32(uiDir, "index.html");
|
|
33702
33735
|
var spaAvailable = existsSync41(spaIndexPath);
|
|
33703
33736
|
app4.use("*", errorHandler);
|
|
33704
33737
|
app4.use("*", authGuard);
|
|
@@ -33716,7 +33749,7 @@ app4.route("/", workspace_ide_default);
|
|
|
33716
33749
|
app4.get("/vendor/*", (c) => {
|
|
33717
33750
|
const subPath = c.req.path.slice("/vendor/".length);
|
|
33718
33751
|
if (!subPath || subPath.includes("..")) return c.notFound();
|
|
33719
|
-
const filePath =
|
|
33752
|
+
const filePath = join32(staticDir, "vendor", subPath);
|
|
33720
33753
|
if (existsSync41(filePath)) {
|
|
33721
33754
|
const ext = subPath.split(".").pop() || "";
|
|
33722
33755
|
return new Response(readFileSync30(filePath), {
|
|
@@ -33729,7 +33762,7 @@ if (spaAvailable) {
|
|
|
33729
33762
|
app4.get("/assets/*", (c) => {
|
|
33730
33763
|
const subPath = c.req.path.slice("/assets/".length);
|
|
33731
33764
|
if (!subPath || subPath.includes("..")) return c.notFound();
|
|
33732
|
-
const filePath =
|
|
33765
|
+
const filePath = join32(uiDir, "assets", subPath);
|
|
33733
33766
|
if (existsSync41(filePath)) {
|
|
33734
33767
|
const ext = subPath.split(".").pop() || "";
|
|
33735
33768
|
return new Response(readFileSync30(filePath), {
|
|
@@ -33753,7 +33786,7 @@ if (spaAvailable) {
|
|
|
33753
33786
|
}
|
|
33754
33787
|
for (const fileName of SPA_TOP_LEVEL_FILES) {
|
|
33755
33788
|
app4.get(`/${fileName}`, (c) => {
|
|
33756
|
-
const filePath =
|
|
33789
|
+
const filePath = join32(uiDir, fileName);
|
|
33757
33790
|
if (existsSync41(filePath)) {
|
|
33758
33791
|
const ext = fileName.split(".").pop() || "";
|
|
33759
33792
|
return new Response(readFileSync30(filePath), {
|
|
@@ -33766,7 +33799,7 @@ if (spaAvailable) {
|
|
|
33766
33799
|
app4.get("/icons/*", (c) => {
|
|
33767
33800
|
const subPath = c.req.path.slice("/icons/".length);
|
|
33768
33801
|
if (!subPath || subPath.includes("..")) return c.notFound();
|
|
33769
|
-
const filePath =
|
|
33802
|
+
const filePath = join32(uiDir, "icons", subPath);
|
|
33770
33803
|
if (existsSync41(filePath)) {
|
|
33771
33804
|
const ext = subPath.split(".").pop() || "";
|
|
33772
33805
|
return new Response(readFileSync30(filePath), {
|
|
@@ -33779,7 +33812,7 @@ if (spaAvailable) {
|
|
|
33779
33812
|
if (c.req.path.startsWith("/api/")) return c.notFound();
|
|
33780
33813
|
const reqPath = c.req.path.slice(1);
|
|
33781
33814
|
if (reqPath && !reqPath.includes("/") && !reqPath.includes("..")) {
|
|
33782
|
-
const filePath =
|
|
33815
|
+
const filePath = join32(uiDir, reqPath);
|
|
33783
33816
|
if (existsSync41(filePath)) {
|
|
33784
33817
|
const ext = reqPath.split(".").pop() || "";
|
|
33785
33818
|
return new Response(readFileSync30(filePath), {
|
|
@@ -33863,9 +33896,9 @@ function stopWebServer() {
|
|
|
33863
33896
|
var __dirname2 = dirname9(fileURLToPath3(import.meta.url));
|
|
33864
33897
|
var pkgVersion;
|
|
33865
33898
|
try {
|
|
33866
|
-
pkgVersion = JSON.parse(readFileSync31(
|
|
33899
|
+
pkgVersion = JSON.parse(readFileSync31(join33(__dirname2, "..", "package.json"), "utf8")).version;
|
|
33867
33900
|
} catch {
|
|
33868
|
-
pkgVersion = "1.2.
|
|
33901
|
+
pkgVersion = "1.2.2";
|
|
33869
33902
|
}
|
|
33870
33903
|
function hr() {
|
|
33871
33904
|
console.log(chalk9.dim("\u2500".repeat(50)));
|
|
@@ -34240,7 +34273,7 @@ async function promptValidatedValue(prompt, validator, existingValue, options) {
|
|
|
34240
34273
|
}
|
|
34241
34274
|
}
|
|
34242
34275
|
function appendToEnv(key, value) {
|
|
34243
|
-
const envPath =
|
|
34276
|
+
const envPath = join33(getMercuryHome(), ".env");
|
|
34244
34277
|
let envContent = "";
|
|
34245
34278
|
if (existsSync42(envPath)) {
|
|
34246
34279
|
envContent = readFileSync31(envPath, "utf-8");
|
|
@@ -37386,7 +37419,7 @@ program.command("upgrade").description("Upgrade Mercury to the latest version").
|
|
|
37386
37419
|
} catch {
|
|
37387
37420
|
try {
|
|
37388
37421
|
const globalDir = execSync11("npm root -g", { encoding: "utf-8" }).trim();
|
|
37389
|
-
const pkgDir =
|
|
37422
|
+
const pkgDir = join33(globalDir, "@cosmicstack", "mercury-agent");
|
|
37390
37423
|
const { rmSync: rmSync6 } = await import("fs");
|
|
37391
37424
|
try {
|
|
37392
37425
|
rmSync6(pkgDir, { recursive: true, force: true });
|