@devness/useai 0.5.35 → 0.5.37
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 +230 -56
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -656,7 +656,7 @@ var VERSION;
|
|
|
656
656
|
var init_version = __esm({
|
|
657
657
|
"../shared/dist/constants/version.js"() {
|
|
658
658
|
"use strict";
|
|
659
|
-
VERSION = "0.5.
|
|
659
|
+
VERSION = "0.5.37";
|
|
660
660
|
}
|
|
661
661
|
});
|
|
662
662
|
|
|
@@ -1540,9 +1540,9 @@ function createZodEnum(values, params) {
|
|
|
1540
1540
|
});
|
|
1541
1541
|
}
|
|
1542
1542
|
function cleanParams(params, data) {
|
|
1543
|
-
const
|
|
1544
|
-
const
|
|
1545
|
-
return
|
|
1543
|
+
const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
|
|
1544
|
+
const p2 = typeof p === "string" ? { message: p } : p;
|
|
1545
|
+
return p2;
|
|
1546
1546
|
}
|
|
1547
1547
|
function custom(check2, _params = {}, fatal) {
|
|
1548
1548
|
if (check2)
|
|
@@ -5262,9 +5262,9 @@ function resolveNpxPath() {
|
|
|
5262
5262
|
} catch {
|
|
5263
5263
|
}
|
|
5264
5264
|
}
|
|
5265
|
-
for (const
|
|
5266
|
-
if (existsSync2(
|
|
5267
|
-
return
|
|
5265
|
+
for (const p of KNOWN_PATHS) {
|
|
5266
|
+
if (existsSync2(p))
|
|
5267
|
+
return p;
|
|
5268
5268
|
}
|
|
5269
5269
|
throw new Error("Could not find npx. Ensure Node.js is installed and npx is in your PATH.");
|
|
5270
5270
|
}
|
|
@@ -5391,7 +5391,7 @@ async function killDaemon() {
|
|
|
5391
5391
|
}
|
|
5392
5392
|
const pids = findPidsByPort(port);
|
|
5393
5393
|
if (pids.length > 0) {
|
|
5394
|
-
await Promise.all(pids.map((
|
|
5394
|
+
await Promise.all(pids.map((p) => killPid(p)));
|
|
5395
5395
|
}
|
|
5396
5396
|
try {
|
|
5397
5397
|
if (existsSync3(DAEMON_PID_FILE))
|
|
@@ -6034,7 +6034,8 @@ var init_dist = __esm({
|
|
|
6034
6034
|
|
|
6035
6035
|
// src/tools.ts
|
|
6036
6036
|
import { createToolRegistry } from "@devness/mcp-setup/dist/registry.js";
|
|
6037
|
-
import {
|
|
6037
|
+
import { existsSync as existsSync6 } from "fs";
|
|
6038
|
+
import { hasBinary, readJsonFile, writeJsonFile, injectInstructions, removeInstructions } from "@devness/mcp-setup/dist/formats.js";
|
|
6038
6039
|
import { join as join4 } from "path";
|
|
6039
6040
|
import { homedir as homedir4 } from "os";
|
|
6040
6041
|
function installStandardHttp(configPath) {
|
|
@@ -6053,12 +6054,83 @@ function installVscodeHttp(configPath) {
|
|
|
6053
6054
|
config2["servers"] = servers;
|
|
6054
6055
|
writeJsonFile(configPath, config2);
|
|
6055
6056
|
}
|
|
6057
|
+
function installCrushHttp(configPath) {
|
|
6058
|
+
const config2 = readJsonFile(configPath);
|
|
6059
|
+
const servers = config2["mcp"] ?? {};
|
|
6060
|
+
delete servers["useai"];
|
|
6061
|
+
servers["UseAI"] = { type: "http", url: MCP_HTTP_URL };
|
|
6062
|
+
config2["mcp"] = servers;
|
|
6063
|
+
writeJsonFile(configPath, config2);
|
|
6064
|
+
}
|
|
6065
|
+
function createExtraTool(def) {
|
|
6066
|
+
const supportsUrl = true;
|
|
6067
|
+
const jsonKey = def.configFormat === "crush" ? "mcp" : "mcpServers";
|
|
6068
|
+
return {
|
|
6069
|
+
id: def.id,
|
|
6070
|
+
name: def.name,
|
|
6071
|
+
configFormat: def.configFormat,
|
|
6072
|
+
supportsUrl,
|
|
6073
|
+
getConfigPath: () => def.configPath,
|
|
6074
|
+
detect: def.detect,
|
|
6075
|
+
isConfigured() {
|
|
6076
|
+
const config2 = readJsonFile(def.configPath);
|
|
6077
|
+
const servers = config2[jsonKey];
|
|
6078
|
+
return !!servers?.["UseAI"] || !!servers?.["useai"];
|
|
6079
|
+
},
|
|
6080
|
+
install() {
|
|
6081
|
+
const config2 = readJsonFile(def.configPath);
|
|
6082
|
+
const servers = config2[jsonKey] ?? {};
|
|
6083
|
+
delete servers["useai"];
|
|
6084
|
+
servers["UseAI"] = def.configFormat === "crush" ? { type: "stdio", ...MCP_STDIO_ENTRY } : { ...MCP_STDIO_ENTRY };
|
|
6085
|
+
config2[jsonKey] = servers;
|
|
6086
|
+
writeJsonFile(def.configPath, config2);
|
|
6087
|
+
if (def.instructions) injectInstructions(INSTRUCTIONS, def.instructions);
|
|
6088
|
+
},
|
|
6089
|
+
installHttp() {
|
|
6090
|
+
if (def.configFormat === "crush") {
|
|
6091
|
+
installCrushHttp(def.configPath);
|
|
6092
|
+
} else {
|
|
6093
|
+
installStandardHttp(def.configPath);
|
|
6094
|
+
}
|
|
6095
|
+
if (def.instructions) injectInstructions(INSTRUCTIONS, def.instructions);
|
|
6096
|
+
},
|
|
6097
|
+
remove() {
|
|
6098
|
+
const config2 = readJsonFile(def.configPath);
|
|
6099
|
+
const servers = config2[jsonKey];
|
|
6100
|
+
if (servers) {
|
|
6101
|
+
delete servers["UseAI"];
|
|
6102
|
+
delete servers["useai"];
|
|
6103
|
+
if (Object.keys(servers).length === 0) delete config2[jsonKey];
|
|
6104
|
+
writeJsonFile(def.configPath, config2);
|
|
6105
|
+
}
|
|
6106
|
+
if (def.instructions) removeInstructions(INSTRUCTIONS, def.instructions);
|
|
6107
|
+
},
|
|
6108
|
+
getManualHint: () => def.instructions ? null : def.manualHint ?? null
|
|
6109
|
+
};
|
|
6110
|
+
}
|
|
6111
|
+
function matchesTool(tool, query) {
|
|
6112
|
+
const q = query.toLowerCase().replace(/[\s-_]+/g, "");
|
|
6113
|
+
const id = tool.id.toLowerCase().replace(/[\s-_]+/g, "");
|
|
6114
|
+
const name = tool.name.toLowerCase().replace(/[\s-_]+/g, "");
|
|
6115
|
+
return id === q || name === q || id.includes(q) || name.includes(q);
|
|
6116
|
+
}
|
|
6056
6117
|
function resolveTools(names) {
|
|
6057
|
-
const { matched: baseMatched, unmatched } = registry.resolveTools(names);
|
|
6118
|
+
const { matched: baseMatched, unmatched: registryUnmatched } = registry.resolveTools(names);
|
|
6058
6119
|
const matched = baseMatched.map((bt) => AI_TOOLS.find((t) => t.id === bt.id));
|
|
6059
|
-
|
|
6120
|
+
const stillUnmatched = [];
|
|
6121
|
+
for (const name of registryUnmatched) {
|
|
6122
|
+
const found = extraTools.filter((t) => matchesTool(t, name));
|
|
6123
|
+
if (found.length > 0) {
|
|
6124
|
+
for (const f of found) {
|
|
6125
|
+
if (!matched.includes(f)) matched.push(f);
|
|
6126
|
+
}
|
|
6127
|
+
} else {
|
|
6128
|
+
stillUnmatched.push(name);
|
|
6129
|
+
}
|
|
6130
|
+
}
|
|
6131
|
+
return { matched, unmatched: stillUnmatched };
|
|
6060
6132
|
}
|
|
6061
|
-
var USEAI_INSTRUCTIONS_TEXT, MCP_HTTP_URL, MCP_HTTP_ENTRY, INSTRUCTIONS, registry, home, appSupport, toolInstructions, URL_SUPPORTED_TOOLS, AI_TOOLS;
|
|
6133
|
+
var USEAI_INSTRUCTIONS_TEXT, MCP_HTTP_URL, MCP_HTTP_ENTRY, INSTRUCTIONS, registry, home, appSupport, toolInstructions, URL_SUPPORTED_TOOLS, registryTools, MCP_STDIO_ENTRY, extraTools, AI_TOOLS;
|
|
6062
6134
|
var init_tools = __esm({
|
|
6063
6135
|
"src/tools.ts"() {
|
|
6064
6136
|
"use strict";
|
|
@@ -6115,7 +6187,7 @@ var init_tools = __esm({
|
|
|
6115
6187
|
"opencode",
|
|
6116
6188
|
"crush"
|
|
6117
6189
|
]);
|
|
6118
|
-
|
|
6190
|
+
registryTools = registry.tools.map((baseTool) => {
|
|
6119
6191
|
const supportsUrl = URL_SUPPORTED_TOOLS.has(baseTool.id);
|
|
6120
6192
|
return {
|
|
6121
6193
|
...baseTool,
|
|
@@ -6136,6 +6208,60 @@ var init_tools = __esm({
|
|
|
6136
6208
|
}
|
|
6137
6209
|
};
|
|
6138
6210
|
});
|
|
6211
|
+
MCP_STDIO_ENTRY = { command: "npx", args: ["-y", "@devness/useai@latest"] };
|
|
6212
|
+
extraTools = [
|
|
6213
|
+
createExtraTool({
|
|
6214
|
+
id: "antigravity",
|
|
6215
|
+
name: "Antigravity",
|
|
6216
|
+
configFormat: "standard",
|
|
6217
|
+
configPath: join4(home, ".gemini", "antigravity", "mcp_config.json"),
|
|
6218
|
+
detect: () => existsSync6(join4(home, ".gemini", "antigravity")),
|
|
6219
|
+
instructions: { method: "append", path: join4(home, ".gemini", "GEMINI.md") }
|
|
6220
|
+
}),
|
|
6221
|
+
createExtraTool({
|
|
6222
|
+
id: "copilot-cli",
|
|
6223
|
+
name: "Copilot CLI",
|
|
6224
|
+
configFormat: "standard",
|
|
6225
|
+
configPath: join4(home, ".copilot", "mcp-config.json"),
|
|
6226
|
+
detect: () => hasBinary("copilot") || existsSync6(join4(home, ".copilot")),
|
|
6227
|
+
manualHint: "No global instructions file \u2014 add UseAI instructions to your project-level agent rules."
|
|
6228
|
+
}),
|
|
6229
|
+
createExtraTool({
|
|
6230
|
+
id: "trae",
|
|
6231
|
+
name: "Trae",
|
|
6232
|
+
configFormat: "standard",
|
|
6233
|
+
configPath: join4(appSupport, "Trae", "User", "mcp.json"),
|
|
6234
|
+
detect: () => existsSync6(join4(appSupport, "Trae")),
|
|
6235
|
+
manualHint: "Open Trae Settings \u2192 Rules and paste the instructions below."
|
|
6236
|
+
}),
|
|
6237
|
+
createExtraTool({
|
|
6238
|
+
id: "kilo-code",
|
|
6239
|
+
name: "Kilo Code",
|
|
6240
|
+
configFormat: "standard",
|
|
6241
|
+
configPath: join4(
|
|
6242
|
+
appSupport,
|
|
6243
|
+
"Code",
|
|
6244
|
+
"User",
|
|
6245
|
+
"globalStorage",
|
|
6246
|
+
"kilocode.kilo-code",
|
|
6247
|
+
"settings",
|
|
6248
|
+
"mcp_settings.json"
|
|
6249
|
+
),
|
|
6250
|
+
detect: () => existsSync6(
|
|
6251
|
+
join4(appSupport, "Code", "User", "globalStorage", "kilocode.kilo-code")
|
|
6252
|
+
),
|
|
6253
|
+
manualHint: "Add the instructions below to .kilocode/rules/useai.md in your project root."
|
|
6254
|
+
}),
|
|
6255
|
+
createExtraTool({
|
|
6256
|
+
id: "crush",
|
|
6257
|
+
name: "Crush",
|
|
6258
|
+
configFormat: "crush",
|
|
6259
|
+
configPath: join4(home, ".config", "crush", "crush.json"),
|
|
6260
|
+
detect: () => hasBinary("crush") || existsSync6(join4(home, ".config", "crush")),
|
|
6261
|
+
manualHint: "No global instructions file \u2014 add UseAI instructions to your project-level .crush.json."
|
|
6262
|
+
})
|
|
6263
|
+
];
|
|
6264
|
+
AI_TOOLS = [...registryTools, ...extraTools];
|
|
6139
6265
|
}
|
|
6140
6266
|
});
|
|
6141
6267
|
|
|
@@ -6481,7 +6607,8 @@ async function runSetup(args) {
|
|
|
6481
6607
|
tools = matched;
|
|
6482
6608
|
}
|
|
6483
6609
|
if (isStatus) {
|
|
6484
|
-
|
|
6610
|
+
const detected = tools.filter((t) => t.detect());
|
|
6611
|
+
(await getShared()).showStatus(detected);
|
|
6485
6612
|
} else if (isRemove) {
|
|
6486
6613
|
await fullRemoveFlow(tools, autoYes, explicit);
|
|
6487
6614
|
} else if (isStdio) {
|
|
@@ -6497,7 +6624,6 @@ var init_setup = __esm({
|
|
|
6497
6624
|
init_source();
|
|
6498
6625
|
init_dist();
|
|
6499
6626
|
init_tools();
|
|
6500
|
-
p;
|
|
6501
6627
|
}
|
|
6502
6628
|
});
|
|
6503
6629
|
|
|
@@ -8593,7 +8719,7 @@ var init_schemas2 = __esm({
|
|
|
8593
8719
|
defineLazy(inst._zod, "pattern", () => {
|
|
8594
8720
|
if (def.options.every((o) => o._zod.pattern)) {
|
|
8595
8721
|
const patterns = def.options.map((o) => o._zod.pattern);
|
|
8596
|
-
return new RegExp(`^(${patterns.map((
|
|
8722
|
+
return new RegExp(`^(${patterns.map((p) => cleanRegex(p.source)).join("|")})$`);
|
|
8597
8723
|
}
|
|
8598
8724
|
return void 0;
|
|
8599
8725
|
});
|
|
@@ -9180,9 +9306,9 @@ var init_registries = __esm({
|
|
|
9180
9306
|
return this;
|
|
9181
9307
|
}
|
|
9182
9308
|
get(schema) {
|
|
9183
|
-
const
|
|
9184
|
-
if (
|
|
9185
|
-
const pm = { ...this.get(
|
|
9309
|
+
const p = schema._zod.parent;
|
|
9310
|
+
if (p) {
|
|
9311
|
+
const pm = { ...this.get(p) ?? {} };
|
|
9186
9312
|
delete pm.id;
|
|
9187
9313
|
return { ...pm, ...this._map.get(schema) };
|
|
9188
9314
|
}
|
|
@@ -16809,7 +16935,7 @@ var require_util = __commonJS({
|
|
|
16809
16935
|
}
|
|
16810
16936
|
exports.evaluatedPropsToName = evaluatedPropsToName;
|
|
16811
16937
|
function setEvaluated(gen, props, ps) {
|
|
16812
|
-
Object.keys(ps).forEach((
|
|
16938
|
+
Object.keys(ps).forEach((p) => gen.assign((0, codegen_1._)`${props}${(0, codegen_1.getProperty)(p)}`, true));
|
|
16813
16939
|
}
|
|
16814
16940
|
exports.setEvaluated = setEvaluated;
|
|
16815
16941
|
var snippets = {};
|
|
@@ -17382,11 +17508,11 @@ var require_code2 = __commonJS({
|
|
|
17382
17508
|
}
|
|
17383
17509
|
exports.noPropertyInData = noPropertyInData;
|
|
17384
17510
|
function allSchemaProperties(schemaMap) {
|
|
17385
|
-
return schemaMap ? Object.keys(schemaMap).filter((
|
|
17511
|
+
return schemaMap ? Object.keys(schemaMap).filter((p) => p !== "__proto__") : [];
|
|
17386
17512
|
}
|
|
17387
17513
|
exports.allSchemaProperties = allSchemaProperties;
|
|
17388
17514
|
function schemaProperties(it, schemaMap) {
|
|
17389
|
-
return allSchemaProperties(schemaMap).filter((
|
|
17515
|
+
return allSchemaProperties(schemaMap).filter((p) => !(0, util_1.alwaysValidSchema)(it, schemaMap[p]));
|
|
17390
17516
|
}
|
|
17391
17517
|
exports.schemaProperties = schemaProperties;
|
|
17392
17518
|
function callValidateCode({ schemaCode, data, it: { gen, topSchemaRef, schemaPath, errorPath }, it }, func, context, passSchema) {
|
|
@@ -17864,12 +17990,12 @@ var require_resolve = __commonJS({
|
|
|
17864
17990
|
function getFullPath(resolver, id = "", normalize) {
|
|
17865
17991
|
if (normalize !== false)
|
|
17866
17992
|
id = normalizeId(id);
|
|
17867
|
-
const
|
|
17868
|
-
return _getFullPath(resolver,
|
|
17993
|
+
const p = resolver.parse(id);
|
|
17994
|
+
return _getFullPath(resolver, p);
|
|
17869
17995
|
}
|
|
17870
17996
|
exports.getFullPath = getFullPath;
|
|
17871
|
-
function _getFullPath(resolver,
|
|
17872
|
-
const serialized = resolver.serialize(
|
|
17997
|
+
function _getFullPath(resolver, p) {
|
|
17998
|
+
const serialized = resolver.serialize(p);
|
|
17873
17999
|
return serialized.split("#")[0] + "#";
|
|
17874
18000
|
}
|
|
17875
18001
|
exports._getFullPath = _getFullPath;
|
|
@@ -18644,11 +18770,11 @@ var require_compile = __commonJS({
|
|
|
18644
18770
|
return sch || this.schemas[ref] || resolveSchema.call(this, root, ref);
|
|
18645
18771
|
}
|
|
18646
18772
|
function resolveSchema(root, ref) {
|
|
18647
|
-
const
|
|
18648
|
-
const refPath = (0, resolve_1._getFullPath)(this.opts.uriResolver,
|
|
18773
|
+
const p = this.opts.uriResolver.parse(ref);
|
|
18774
|
+
const refPath = (0, resolve_1._getFullPath)(this.opts.uriResolver, p);
|
|
18649
18775
|
let baseId = (0, resolve_1.getFullPath)(this.opts.uriResolver, root.baseId, void 0);
|
|
18650
18776
|
if (Object.keys(root.schema).length > 0 && refPath === baseId) {
|
|
18651
|
-
return getJsonPointer.call(this,
|
|
18777
|
+
return getJsonPointer.call(this, p, root);
|
|
18652
18778
|
}
|
|
18653
18779
|
const id = (0, resolve_1.normalizeId)(refPath);
|
|
18654
18780
|
const schOrRef = this.refs[id] || this.schemas[id];
|
|
@@ -18656,7 +18782,7 @@ var require_compile = __commonJS({
|
|
|
18656
18782
|
const sch = resolveSchema.call(this, root, schOrRef);
|
|
18657
18783
|
if (typeof (sch === null || sch === void 0 ? void 0 : sch.schema) !== "object")
|
|
18658
18784
|
return;
|
|
18659
|
-
return getJsonPointer.call(this,
|
|
18785
|
+
return getJsonPointer.call(this, p, sch);
|
|
18660
18786
|
}
|
|
18661
18787
|
if (typeof (schOrRef === null || schOrRef === void 0 ? void 0 : schOrRef.schema) !== "object")
|
|
18662
18788
|
return;
|
|
@@ -18670,7 +18796,7 @@ var require_compile = __commonJS({
|
|
|
18670
18796
|
baseId = (0, resolve_1.resolveUrl)(this.opts.uriResolver, baseId, schId);
|
|
18671
18797
|
return new SchemaEnv({ schema, schemaId, root, baseId });
|
|
18672
18798
|
}
|
|
18673
|
-
return getJsonPointer.call(this,
|
|
18799
|
+
return getJsonPointer.call(this, p, schOrRef);
|
|
18674
18800
|
}
|
|
18675
18801
|
exports.resolveSchema = resolveSchema;
|
|
18676
18802
|
var PREVENT_SCOPE_CHANGE = /* @__PURE__ */ new Set([
|
|
@@ -19675,9 +19801,9 @@ var require_core = __commonJS({
|
|
|
19675
19801
|
this.addSchema(_schema, ref, meta);
|
|
19676
19802
|
}
|
|
19677
19803
|
async function _loadSchema(ref) {
|
|
19678
|
-
const
|
|
19679
|
-
if (
|
|
19680
|
-
return
|
|
19804
|
+
const p = this._loading[ref];
|
|
19805
|
+
if (p)
|
|
19806
|
+
return p;
|
|
19681
19807
|
try {
|
|
19682
19808
|
return await (this._loading[ref] = loadSchema(ref));
|
|
19683
19809
|
} finally {
|
|
@@ -21159,12 +21285,12 @@ var require_additionalProperties = __commonJS({
|
|
|
21159
21285
|
const propsSchema = (0, util_1.schemaRefOrVal)(it, parentSchema.properties, "properties");
|
|
21160
21286
|
definedProp = (0, code_1.isOwnProperty)(gen, propsSchema, key);
|
|
21161
21287
|
} else if (props.length) {
|
|
21162
|
-
definedProp = (0, codegen_1.or)(...props.map((
|
|
21288
|
+
definedProp = (0, codegen_1.or)(...props.map((p) => (0, codegen_1._)`${key} === ${p}`));
|
|
21163
21289
|
} else {
|
|
21164
21290
|
definedProp = codegen_1.nil;
|
|
21165
21291
|
}
|
|
21166
21292
|
if (patProps.length) {
|
|
21167
|
-
definedProp = (0, codegen_1.or)(definedProp, ...patProps.map((
|
|
21293
|
+
definedProp = (0, codegen_1.or)(definedProp, ...patProps.map((p) => (0, codegen_1._)`${(0, code_1.usePattern)(cxt, p)}.test(${key})`));
|
|
21168
21294
|
}
|
|
21169
21295
|
return (0, codegen_1.not)(definedProp);
|
|
21170
21296
|
}
|
|
@@ -21244,7 +21370,7 @@ var require_properties = __commonJS({
|
|
|
21244
21370
|
if (it.opts.unevaluated && allProps.length && it.props !== true) {
|
|
21245
21371
|
it.props = util_1.mergeEvaluated.props(gen, (0, util_1.toHash)(allProps), it.props);
|
|
21246
21372
|
}
|
|
21247
|
-
const properties = allProps.filter((
|
|
21373
|
+
const properties = allProps.filter((p) => !(0, util_1.alwaysValidSchema)(it, schema[p]));
|
|
21248
21374
|
if (properties.length === 0)
|
|
21249
21375
|
return;
|
|
21250
21376
|
const valid = gen.name("valid");
|
|
@@ -21294,7 +21420,7 @@ var require_patternProperties = __commonJS({
|
|
|
21294
21420
|
const { gen, schema, data, parentSchema, it } = cxt;
|
|
21295
21421
|
const { opts } = it;
|
|
21296
21422
|
const patterns = (0, code_1.allSchemaProperties)(schema);
|
|
21297
|
-
const alwaysValidPatterns = patterns.filter((
|
|
21423
|
+
const alwaysValidPatterns = patterns.filter((p) => (0, util_1.alwaysValidSchema)(it, schema[p]));
|
|
21298
21424
|
if (patterns.length === 0 || alwaysValidPatterns.length === patterns.length && (!it.opts.unevaluated || it.props === true)) {
|
|
21299
21425
|
return;
|
|
21300
21426
|
}
|
|
@@ -25418,7 +25544,7 @@ var session_state_exports = {};
|
|
|
25418
25544
|
__export(session_state_exports, {
|
|
25419
25545
|
SessionState: () => SessionState
|
|
25420
25546
|
});
|
|
25421
|
-
import { appendFileSync, existsSync as
|
|
25547
|
+
import { appendFileSync, existsSync as existsSync7 } from "fs";
|
|
25422
25548
|
import { basename, join as join5 } from "path";
|
|
25423
25549
|
var SessionState;
|
|
25424
25550
|
var init_session_state = __esm({
|
|
@@ -25516,7 +25642,7 @@ var init_session_state = __esm({
|
|
|
25516
25642
|
}
|
|
25517
25643
|
initializeKeystore() {
|
|
25518
25644
|
ensureDir();
|
|
25519
|
-
if (
|
|
25645
|
+
if (existsSync7(KEYSTORE_FILE)) {
|
|
25520
25646
|
const ks = readJson(KEYSTORE_FILE, null);
|
|
25521
25647
|
if (ks) {
|
|
25522
25648
|
try {
|
|
@@ -25575,7 +25701,7 @@ __export(register_tools_exports, {
|
|
|
25575
25701
|
registerTools: () => registerTools
|
|
25576
25702
|
});
|
|
25577
25703
|
import { createHash as createHash3, randomUUID as randomUUID3 } from "crypto";
|
|
25578
|
-
import { existsSync as
|
|
25704
|
+
import { existsSync as existsSync8, renameSync as renameSync2 } from "fs";
|
|
25579
25705
|
import { join as join7 } from "path";
|
|
25580
25706
|
function getConfig() {
|
|
25581
25707
|
return readJson(CONFIG_FILE, {
|
|
@@ -25788,7 +25914,7 @@ function registerTools(server2, session2, opts) {
|
|
|
25788
25914
|
const activePath = join7(ACTIVE_DIR, `${session2.sessionId}.jsonl`);
|
|
25789
25915
|
const sealedPath = join7(SEALED_DIR, `${session2.sessionId}.jsonl`);
|
|
25790
25916
|
try {
|
|
25791
|
-
if (
|
|
25917
|
+
if (existsSync8(activePath)) {
|
|
25792
25918
|
renameSync2(activePath, sealedPath);
|
|
25793
25919
|
}
|
|
25794
25920
|
} catch {
|
|
@@ -25903,7 +26029,7 @@ var init_html = __esm({
|
|
|
25903
26029
|
});
|
|
25904
26030
|
|
|
25905
26031
|
// src/dashboard/local-api.ts
|
|
25906
|
-
import { existsSync as
|
|
26032
|
+
import { existsSync as existsSync9, unlinkSync as unlinkSync4 } from "fs";
|
|
25907
26033
|
import { join as join8 } from "path";
|
|
25908
26034
|
function json(res, status, data) {
|
|
25909
26035
|
const body = JSON.stringify(data);
|
|
@@ -26137,7 +26263,7 @@ function handleDeleteSession(req, res, sessionId) {
|
|
|
26137
26263
|
const milestonesRemoved = milestones.length - remaining.length;
|
|
26138
26264
|
if (milestonesRemoved > 0) writeJson(MILESTONES_FILE, remaining);
|
|
26139
26265
|
const chainPath = join8(SEALED_DIR, `${sessionId}.jsonl`);
|
|
26140
|
-
if (
|
|
26266
|
+
if (existsSync9(chainPath)) unlinkSync4(chainPath);
|
|
26141
26267
|
json(res, 200, { deleted: true, session_id: sessionId, milestones_removed: milestonesRemoved });
|
|
26142
26268
|
} catch (err) {
|
|
26143
26269
|
json(res, 500, { error: err.message });
|
|
@@ -26160,7 +26286,7 @@ function handleDeleteConversation(req, res, conversationId) {
|
|
|
26160
26286
|
if (milestonesRemoved > 0) writeJson(MILESTONES_FILE, remainingMilestones);
|
|
26161
26287
|
for (const sid of sessionIds) {
|
|
26162
26288
|
const chainPath = join8(SEALED_DIR, `${sid}.jsonl`);
|
|
26163
|
-
if (
|
|
26289
|
+
if (existsSync9(chainPath)) unlinkSync4(chainPath);
|
|
26164
26290
|
}
|
|
26165
26291
|
json(res, 200, { deleted: true, conversation_id: conversationId, sessions_removed: sessionIds.size, milestones_removed: milestonesRemoved });
|
|
26166
26292
|
} catch (err) {
|
|
@@ -26198,7 +26324,7 @@ __export(daemon_exports, {
|
|
|
26198
26324
|
});
|
|
26199
26325
|
import { createServer } from "http";
|
|
26200
26326
|
import { createHash as createHash4, randomUUID as randomUUID4 } from "crypto";
|
|
26201
|
-
import { existsSync as
|
|
26327
|
+
import { existsSync as existsSync10, readdirSync, readFileSync as readFileSync4, appendFileSync as appendFileSync2, renameSync as renameSync3, writeFileSync as writeFileSync4, unlinkSync as unlinkSync5, statSync } from "fs";
|
|
26202
26328
|
import { join as join9 } from "path";
|
|
26203
26329
|
function getActiveUseaiSessionIds() {
|
|
26204
26330
|
const ids = /* @__PURE__ */ new Set();
|
|
@@ -26209,7 +26335,7 @@ function getActiveUseaiSessionIds() {
|
|
|
26209
26335
|
}
|
|
26210
26336
|
function sealOrphanFile(sessionId) {
|
|
26211
26337
|
const filePath = join9(ACTIVE_DIR, `${sessionId}.jsonl`);
|
|
26212
|
-
if (!
|
|
26338
|
+
if (!existsSync10(filePath)) return;
|
|
26213
26339
|
try {
|
|
26214
26340
|
const content = readFileSync4(filePath, "utf-8").trim();
|
|
26215
26341
|
if (!content) return;
|
|
@@ -26306,7 +26432,7 @@ function sealOrphanFile(sessionId) {
|
|
|
26306
26432
|
}
|
|
26307
26433
|
}
|
|
26308
26434
|
function sealOrphanedSessions() {
|
|
26309
|
-
if (!
|
|
26435
|
+
if (!existsSync10(ACTIVE_DIR)) return;
|
|
26310
26436
|
const activeIds = getActiveUseaiSessionIds();
|
|
26311
26437
|
const mcpMap = readMcpMap();
|
|
26312
26438
|
const mappedUseaiIds = new Set(Object.values(mcpMap));
|
|
@@ -26335,7 +26461,7 @@ function sealOrphanedSessions() {
|
|
|
26335
26461
|
}
|
|
26336
26462
|
function isSessionAlreadySealed(session2) {
|
|
26337
26463
|
const activePath = join9(ACTIVE_DIR, `${session2.sessionId}.jsonl`);
|
|
26338
|
-
return !
|
|
26464
|
+
return !existsSync10(activePath);
|
|
26339
26465
|
}
|
|
26340
26466
|
function sealRichness(s) {
|
|
26341
26467
|
let score = 0;
|
|
@@ -26420,7 +26546,7 @@ function autoSealSession(active) {
|
|
|
26420
26546
|
const activePath = join9(ACTIVE_DIR, `${session2.sessionId}.jsonl`);
|
|
26421
26547
|
const sealedPath = join9(SEALED_DIR, `${session2.sessionId}.jsonl`);
|
|
26422
26548
|
try {
|
|
26423
|
-
if (
|
|
26549
|
+
if (existsSync10(activePath)) {
|
|
26424
26550
|
renameSync3(activePath, sealedPath);
|
|
26425
26551
|
}
|
|
26426
26552
|
} catch {
|
|
@@ -26551,7 +26677,7 @@ function sendJsonRpcResult(res, rpcId, text) {
|
|
|
26551
26677
|
function readChainMetadata(useaiSessionId) {
|
|
26552
26678
|
const activePath = join9(ACTIVE_DIR, `${useaiSessionId}.jsonl`);
|
|
26553
26679
|
const sealedPath = join9(SEALED_DIR, `${useaiSessionId}.jsonl`);
|
|
26554
|
-
const chainPath =
|
|
26680
|
+
const chainPath = existsSync10(activePath) ? activePath : existsSync10(sealedPath) ? sealedPath : null;
|
|
26555
26681
|
if (!chainPath) return null;
|
|
26556
26682
|
try {
|
|
26557
26683
|
const firstLine = readFileSync4(chainPath, "utf-8").split("\n")[0];
|
|
@@ -26576,7 +26702,7 @@ function recoverStartSession(staleMcpSessionId, args, rpcId, res, req) {
|
|
|
26576
26702
|
const map = readMcpMap();
|
|
26577
26703
|
const prevSessionId = map[staleMcpSessionId];
|
|
26578
26704
|
const prevActivePath = prevSessionId ? join9(ACTIVE_DIR, `${prevSessionId}.jsonl`) : null;
|
|
26579
|
-
if (prevActivePath &&
|
|
26705
|
+
if (prevActivePath && existsSync10(prevActivePath)) {
|
|
26580
26706
|
sealOrphanFile(prevSessionId);
|
|
26581
26707
|
}
|
|
26582
26708
|
const meta = prevSessionId ? readChainMetadata(prevSessionId) : null;
|
|
@@ -26617,7 +26743,7 @@ function recoverHeartbeat(staleMcpSessionId, rpcId, res) {
|
|
|
26617
26743
|
const useaiSessionId = map[staleMcpSessionId];
|
|
26618
26744
|
if (!useaiSessionId) return false;
|
|
26619
26745
|
const chainPath = join9(ACTIVE_DIR, `${useaiSessionId}.jsonl`);
|
|
26620
|
-
if (!
|
|
26746
|
+
if (!existsSync10(chainPath)) {
|
|
26621
26747
|
sendJsonRpcResult(res, rpcId, "Session already ended (recovered).");
|
|
26622
26748
|
return true;
|
|
26623
26749
|
}
|
|
@@ -26654,7 +26780,7 @@ function recoverEndSession(staleMcpSessionId, args, rpcId, res) {
|
|
|
26654
26780
|
if (!useaiSessionId) return false;
|
|
26655
26781
|
const activePath = join9(ACTIVE_DIR, `${useaiSessionId}.jsonl`);
|
|
26656
26782
|
const sealedPath = join9(SEALED_DIR, `${useaiSessionId}.jsonl`);
|
|
26657
|
-
const chainPath =
|
|
26783
|
+
const chainPath = existsSync10(activePath) ? activePath : existsSync10(sealedPath) ? sealedPath : null;
|
|
26658
26784
|
if (!chainPath) return false;
|
|
26659
26785
|
const isAlreadySealed = chainPath === sealedPath;
|
|
26660
26786
|
const content = readFileSync4(chainPath, "utf-8").trim();
|
|
@@ -26959,7 +27085,7 @@ async function startDaemon(port) {
|
|
|
26959
27085
|
const listenPort = port ?? DAEMON_PORT;
|
|
26960
27086
|
ensureDir();
|
|
26961
27087
|
try {
|
|
26962
|
-
if (
|
|
27088
|
+
if (existsSync10(KEYSTORE_FILE)) {
|
|
26963
27089
|
const ks = readJson(KEYSTORE_FILE, null);
|
|
26964
27090
|
if (ks) daemonSigningKey = decryptKeystore(ks);
|
|
26965
27091
|
}
|
|
@@ -27183,7 +27309,7 @@ async function startDaemon(port) {
|
|
|
27183
27309
|
}
|
|
27184
27310
|
}
|
|
27185
27311
|
try {
|
|
27186
|
-
if (
|
|
27312
|
+
if (existsSync10(DAEMON_PID_FILE)) {
|
|
27187
27313
|
unlinkSync5(DAEMON_PID_FILE);
|
|
27188
27314
|
}
|
|
27189
27315
|
} catch {
|
|
@@ -27344,6 +27470,49 @@ if (subcommand === "mcp" || subcommand?.startsWith("--") || !subcommand && proce
|
|
|
27344
27470
|
await runSetup2(args);
|
|
27345
27471
|
process.exit(0);
|
|
27346
27472
|
}
|
|
27473
|
+
if (subcommand === "update") {
|
|
27474
|
+
const { fetchLatestVersion: fetchLatestVersion2, fetchDaemonHealth: fetchDaemonHealth2, killDaemon: killDaemon2, ensureDaemon: ensureDaemon2, VERSION: VERSION3 } = await Promise.resolve().then(() => (init_dist(), dist_exports));
|
|
27475
|
+
console.log(`Current version: ${VERSION3}`);
|
|
27476
|
+
console.log("Checking for updates...");
|
|
27477
|
+
const latest = await fetchLatestVersion2();
|
|
27478
|
+
if (!latest) {
|
|
27479
|
+
console.error("Failed to fetch latest version from npm.");
|
|
27480
|
+
process.exit(1);
|
|
27481
|
+
}
|
|
27482
|
+
console.log(`Latest version: ${latest}`);
|
|
27483
|
+
const healthBefore = await fetchDaemonHealth2();
|
|
27484
|
+
const runningVersion = healthBefore?.version;
|
|
27485
|
+
if (runningVersion) {
|
|
27486
|
+
console.log(`Running daemon: ${runningVersion}`);
|
|
27487
|
+
}
|
|
27488
|
+
if (runningVersion === latest && VERSION3 === latest) {
|
|
27489
|
+
console.log("Already up to date.");
|
|
27490
|
+
process.exit(0);
|
|
27491
|
+
}
|
|
27492
|
+
console.log("Stopping daemon...");
|
|
27493
|
+
await killDaemon2();
|
|
27494
|
+
console.log("Clearing npx cache...");
|
|
27495
|
+
const { execSync: execSync4 } = await import("child_process");
|
|
27496
|
+
try {
|
|
27497
|
+
execSync4("npm cache clean --force", { stdio: "ignore", timeout: 15e3 });
|
|
27498
|
+
} catch {
|
|
27499
|
+
}
|
|
27500
|
+
console.log("Restarting daemon...");
|
|
27501
|
+
const ok = await ensureDaemon2({ preferOnline: true });
|
|
27502
|
+
if (!ok) {
|
|
27503
|
+
console.error("Daemon failed to start after update.");
|
|
27504
|
+
process.exit(1);
|
|
27505
|
+
}
|
|
27506
|
+
const healthAfter = await fetchDaemonHealth2();
|
|
27507
|
+
const newVersion = healthAfter?.version;
|
|
27508
|
+
console.log(`Daemon now running: ${newVersion ?? "unknown"}`);
|
|
27509
|
+
if (newVersion === latest) {
|
|
27510
|
+
console.log("Update successful!");
|
|
27511
|
+
} else {
|
|
27512
|
+
console.log("Warning: daemon version does not match latest. You may need to retry.");
|
|
27513
|
+
}
|
|
27514
|
+
process.exit(0);
|
|
27515
|
+
}
|
|
27347
27516
|
if (subcommand === "daemon") {
|
|
27348
27517
|
const { startDaemon: startDaemon2 } = await Promise.resolve().then(() => (init_daemon2(), daemon_exports));
|
|
27349
27518
|
const portArg = process.argv.indexOf("--port");
|
|
@@ -27352,6 +27521,11 @@ if (subcommand === "daemon") {
|
|
|
27352
27521
|
await new Promise(() => {
|
|
27353
27522
|
});
|
|
27354
27523
|
}
|
|
27524
|
+
if (subcommand) {
|
|
27525
|
+
console.error(`Unknown subcommand: "${subcommand}"`);
|
|
27526
|
+
console.error("Available commands: mcp, daemon, update");
|
|
27527
|
+
process.exit(1);
|
|
27528
|
+
}
|
|
27355
27529
|
var { McpServer: McpServer2 } = await Promise.resolve().then(() => (init_mcp(), mcp_exports));
|
|
27356
27530
|
var { StdioServerTransport: StdioServerTransport2 } = await Promise.resolve().then(() => (init_stdio2(), stdio_exports));
|
|
27357
27531
|
var { VERSION: VERSION2, ensureDir: ensureDir2 } = await Promise.resolve().then(() => (init_dist(), dist_exports));
|