forge-cw 0.1.15 → 0.1.17
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/console/assets/index-o23w8qWI.js +31 -0
- package/console/index.html +1 -1
- package/dist/index.js +1289 -1069
- package/package.json +1 -1
- package/console/assets/index-m_7gobK_.js +0 -31
package/dist/index.js
CHANGED
|
@@ -38,8 +38,8 @@ import { createRequire } from "node:module";
|
|
|
38
38
|
function quietSqliteWarning() {
|
|
39
39
|
const emitWarning = process.emitWarning;
|
|
40
40
|
process.emitWarning = function(warning, ...rest) {
|
|
41
|
-
const
|
|
42
|
-
if (
|
|
41
|
+
const text2 = typeof warning === "string" ? warning : warning.message;
|
|
42
|
+
if (text2.startsWith("SQLite is an experimental feature"))
|
|
43
43
|
return;
|
|
44
44
|
return emitWarning.call(process, warning, ...rest);
|
|
45
45
|
};
|
|
@@ -972,8 +972,8 @@ function createDoctorClient(cwBin) {
|
|
|
972
972
|
}
|
|
973
973
|
function readContextTokens(cwHome, env = process.env) {
|
|
974
974
|
const file = join3(cwHome, "tokens.env");
|
|
975
|
-
const
|
|
976
|
-
const has = (name) => Boolean(env[name]?.trim()) || new RegExp(`^\\s*(export\\s+)?${name}\\s*=\\s*\\S`, "m").test(
|
|
975
|
+
const text2 = existsSync3(file) ? readFileSync3(file, "utf-8") : "";
|
|
976
|
+
const has = (name) => Boolean(env[name]?.trim()) || new RegExp(`^\\s*(export\\s+)?${name}\\s*=\\s*\\S`, "m").test(text2);
|
|
977
977
|
return { linear: has("LINEAR_API_KEY"), notion: has("NOTION_TOKEN") };
|
|
978
978
|
}
|
|
979
979
|
var CACHE_MS, TIMEOUT_MS;
|
|
@@ -1004,8 +1004,8 @@ function summarizeChecks(rollup) {
|
|
|
1004
1004
|
return "pending";
|
|
1005
1005
|
return "passing";
|
|
1006
1006
|
}
|
|
1007
|
-
function parseShortstat(
|
|
1008
|
-
const num2 = (re) => Number(re.exec(
|
|
1007
|
+
function parseShortstat(text2) {
|
|
1008
|
+
const num2 = (re) => Number(re.exec(text2)?.[1] ?? 0);
|
|
1009
1009
|
return {
|
|
1010
1010
|
files: num2(/(\d+) files? changed/),
|
|
1011
1011
|
insertions: num2(/(\d+) insertions?\(\+\)/),
|
|
@@ -1286,7 +1286,7 @@ var init_task_review = __esm({
|
|
|
1286
1286
|
runCommand = createRunner();
|
|
1287
1287
|
GitReadError = class extends Error {
|
|
1288
1288
|
};
|
|
1289
|
-
lines = (
|
|
1289
|
+
lines = (text2) => text2.split("\n").filter((line) => line.length > 0);
|
|
1290
1290
|
CW_LINKED_FILES = /* @__PURE__ */ new Set([".claude", ".env", "TASK_NOTES.md", "SHARED_CONTEXT.md"]);
|
|
1291
1291
|
PR_FIELDS = "number,state,url,isDraft,baseRefName,headRefOid,reviewDecision,statusCheckRollup";
|
|
1292
1292
|
PR_STATES = /* @__PURE__ */ new Set(["OPEN", "MERGED", "CLOSED"]);
|
|
@@ -1494,20 +1494,20 @@ function callCodexAppServer(bin, codexHome, timeoutMs = TIMEOUT_MS3) {
|
|
|
1494
1494
|
for (const line of lines2) {
|
|
1495
1495
|
if (!line.trim())
|
|
1496
1496
|
continue;
|
|
1497
|
-
let
|
|
1497
|
+
let message2;
|
|
1498
1498
|
try {
|
|
1499
|
-
|
|
1499
|
+
message2 = JSON.parse(line);
|
|
1500
1500
|
} catch {
|
|
1501
1501
|
continue;
|
|
1502
1502
|
}
|
|
1503
|
-
if (
|
|
1503
|
+
if (message2.id !== READ_ID)
|
|
1504
1504
|
continue;
|
|
1505
|
-
if (
|
|
1506
|
-
return fail(new Error(String(
|
|
1507
|
-
return done(obj(
|
|
1505
|
+
if (message2.error)
|
|
1506
|
+
return fail(new Error(String(message2.error.message ?? "codex app-server returned an error")));
|
|
1507
|
+
return done(obj(message2.result) ?? {});
|
|
1508
1508
|
}
|
|
1509
1509
|
});
|
|
1510
|
-
const send = (
|
|
1510
|
+
const send = (message2) => child.stdin.write(`${JSON.stringify(message2)}
|
|
1511
1511
|
`);
|
|
1512
1512
|
send({ jsonrpc: "2.0", id: 1, method: "initialize", params: { clientInfo: { name: "forge", title: "Forge", version: "0.1.0" } } });
|
|
1513
1513
|
send({ jsonrpc: "2.0", method: "initialized", params: {} });
|
|
@@ -1748,7 +1748,7 @@ var init_login_manager = __esm({
|
|
|
1748
1748
|
import { spawn as spawn4 } from "node:child_process";
|
|
1749
1749
|
function importApiKey(cwBin, account, harness, apiKey) {
|
|
1750
1750
|
return new Promise((resolve10) => {
|
|
1751
|
-
const redact = (
|
|
1751
|
+
const redact = (text2) => text2.split(apiKey).join("***").trim();
|
|
1752
1752
|
const child = spawn4(cwBin, ["account", "login", account, "--harness", harness, "--with-api-key", "-"], {
|
|
1753
1753
|
env: envWithoutHarness(),
|
|
1754
1754
|
stdio: ["pipe", "pipe", "pipe"]
|
|
@@ -1840,15 +1840,15 @@ var init_editors = __esm({
|
|
|
1840
1840
|
});
|
|
1841
1841
|
|
|
1842
1842
|
// ../core/dist/output.js
|
|
1843
|
-
function tailOutput(
|
|
1844
|
-
return stripAnsi(
|
|
1843
|
+
function tailOutput(text2, max = 20) {
|
|
1844
|
+
return stripAnsi(text2).split("\n").map((line) => line.trimEnd()).filter((line) => line.length > 0).slice(-max).join("\n");
|
|
1845
1845
|
}
|
|
1846
1846
|
var ANSI_RE2, stripAnsi;
|
|
1847
1847
|
var init_output = __esm({
|
|
1848
1848
|
"../core/dist/output.js"() {
|
|
1849
1849
|
"use strict";
|
|
1850
1850
|
ANSI_RE2 = /\x1b\[[0-9;]*[A-Za-z]/g;
|
|
1851
|
-
stripAnsi = (
|
|
1851
|
+
stripAnsi = (text2) => text2.replace(ANSI_RE2, "");
|
|
1852
1852
|
}
|
|
1853
1853
|
});
|
|
1854
1854
|
|
|
@@ -1986,8 +1986,8 @@ function cwRoutes(reader, options = {}) {
|
|
|
1986
1986
|
return c.json({ ok: true, name: trimmed });
|
|
1987
1987
|
} catch (err) {
|
|
1988
1988
|
const stderr = err.stderr?.trim().split("\n")[0];
|
|
1989
|
-
const
|
|
1990
|
-
return c.json({ ok: false, error: `Failed to create account: ${
|
|
1989
|
+
const message2 = stderr || (err instanceof Error ? err.message : "Unknown error");
|
|
1990
|
+
return c.json({ ok: false, error: `Failed to create account: ${message2}` }, 500);
|
|
1991
1991
|
}
|
|
1992
1992
|
});
|
|
1993
1993
|
app.delete("/accounts/:name", async (c) => {
|
|
@@ -2004,8 +2004,8 @@ function cwRoutes(reader, options = {}) {
|
|
|
2004
2004
|
rmSync4(accountDir, { recursive: true, force: true });
|
|
2005
2005
|
return c.json({ ok: true });
|
|
2006
2006
|
} catch (err) {
|
|
2007
|
-
const
|
|
2008
|
-
return c.json({ ok: false, error: `Failed to remove account: ${
|
|
2007
|
+
const message2 = err instanceof Error ? err.message : "Unknown error";
|
|
2008
|
+
return c.json({ ok: false, error: `Failed to remove account: ${message2}` }, 500);
|
|
2009
2009
|
}
|
|
2010
2010
|
});
|
|
2011
2011
|
app.post("/accounts/:name/login", async (c) => {
|
|
@@ -2445,8 +2445,8 @@ ${result2.stderr}`);
|
|
|
2445
2445
|
writeFileSync(join7(reader.cwHome, "projects.json"), JSON.stringify(projects, null, 2));
|
|
2446
2446
|
return c.json({ ok: true });
|
|
2447
2447
|
} catch (err) {
|
|
2448
|
-
const
|
|
2449
|
-
return c.json({ ok: false, error: `Failed to update projects: ${
|
|
2448
|
+
const message2 = err instanceof Error ? err.message : "Unknown error";
|
|
2449
|
+
return c.json({ ok: false, error: `Failed to update projects: ${message2}` }, 500);
|
|
2450
2450
|
}
|
|
2451
2451
|
});
|
|
2452
2452
|
app.post("/delete-project", async (c) => {
|
|
@@ -2506,8 +2506,8 @@ ${result2.stderr}`);
|
|
|
2506
2506
|
try {
|
|
2507
2507
|
entries = readdirSync3(target, { withFileTypes: true });
|
|
2508
2508
|
} catch (err) {
|
|
2509
|
-
const
|
|
2510
|
-
return c.json({ ok: false, error: `Cannot read directory: ${
|
|
2509
|
+
const message2 = err instanceof Error ? err.message : "Unknown error";
|
|
2510
|
+
return c.json({ ok: false, error: `Cannot read directory: ${message2}` }, 500);
|
|
2511
2511
|
}
|
|
2512
2512
|
const dirs = entries.filter((entry) => entry.isDirectory() && !entry.name.startsWith(".")).map(({ name }) => {
|
|
2513
2513
|
const full = join7(target, name);
|
|
@@ -2558,8 +2558,8 @@ ${result2.stderr}`);
|
|
|
2558
2558
|
options.events?.emit("project.registered", { project: projectName, path: projectPath });
|
|
2559
2559
|
return c.json({ ok: true, project: projectName });
|
|
2560
2560
|
} catch (err) {
|
|
2561
|
-
const
|
|
2562
|
-
return c.json({ ok: false, error: `Failed to register project: ${
|
|
2561
|
+
const message2 = err instanceof Error ? err.message : "Unknown error";
|
|
2562
|
+
return c.json({ ok: false, error: `Failed to register project: ${message2}` }, 500);
|
|
2563
2563
|
}
|
|
2564
2564
|
});
|
|
2565
2565
|
return app;
|
|
@@ -2638,6 +2638,20 @@ function readSkill(reader, dir) {
|
|
|
2638
2638
|
return null;
|
|
2639
2639
|
}
|
|
2640
2640
|
}
|
|
2641
|
+
function readCommands(reader, installPath) {
|
|
2642
|
+
const dir = join8(installPath, "commands");
|
|
2643
|
+
if (!existsSync6(dir))
|
|
2644
|
+
return [];
|
|
2645
|
+
return readdirSync4(dir).filter((f) => f.endsWith(".md")).sort().flatMap((file) => {
|
|
2646
|
+
try {
|
|
2647
|
+
const { frontmatter } = reader.parseFrontmatter(readFileSync6(join8(dir, file), "utf-8"));
|
|
2648
|
+
const hint = frontmatter["argument-hint"];
|
|
2649
|
+
return [{ name: `/${basename2(file, ".md")}`, description: String(frontmatter["description"] ?? ""), ...typeof hint === "string" && hint ? { argumentHint: hint } : {} }];
|
|
2650
|
+
} catch {
|
|
2651
|
+
return [];
|
|
2652
|
+
}
|
|
2653
|
+
});
|
|
2654
|
+
}
|
|
2641
2655
|
function manifestRepo(manifest) {
|
|
2642
2656
|
const repo = manifest["repository"];
|
|
2643
2657
|
if (typeof repo === "string")
|
|
@@ -2697,6 +2711,20 @@ function projectSkillNames(projectPath) {
|
|
|
2697
2711
|
return [];
|
|
2698
2712
|
return readdirSync4(dir, { withFileTypes: true }).filter((e) => e.isDirectory() && existsSync6(join8(dir, e.name, "SKILL.md"))).map((e) => e.name).sort();
|
|
2699
2713
|
}
|
|
2714
|
+
function installsOf(reader, name) {
|
|
2715
|
+
return pluginScopes(reader).flatMap(({ scope, scopeRef }) => {
|
|
2716
|
+
const configDir = reader.getSkillConfigDir(scope, scopeRef);
|
|
2717
|
+
const installed = readJson(join8(configDir, "plugins", "installed_plugins.json"))["plugins"];
|
|
2718
|
+
if (!isRecord(installed))
|
|
2719
|
+
return [];
|
|
2720
|
+
return Object.entries(installed).flatMap(([id, entries]) => {
|
|
2721
|
+
const user = Array.isArray(entries) ? entries.find((e) => isRecord(e) && e["scope"] === "user") : void 0;
|
|
2722
|
+
if (!user || splitPluginId(id).name !== name)
|
|
2723
|
+
return [];
|
|
2724
|
+
return [{ id, scope, scopeRef, version: String(user["version"] ?? ""), configDir, update: pluginUpdateArgs(id) }];
|
|
2725
|
+
});
|
|
2726
|
+
});
|
|
2727
|
+
}
|
|
2700
2728
|
async function listPlugins(reader, remoteOf) {
|
|
2701
2729
|
const found = /* @__PURE__ */ new Map();
|
|
2702
2730
|
for (const { scope, scopeRef } of pluginScopes(reader)) {
|
|
@@ -2745,6 +2773,7 @@ async function listPlugins(reader, remoteOf) {
|
|
|
2745
2773
|
repo,
|
|
2746
2774
|
installs: list.map((f) => f.install),
|
|
2747
2775
|
skills: skillDirs(newest.install.installPath, manifest).flatMap((dir) => readSkill(reader, dir) ?? []),
|
|
2776
|
+
commands: readCommands(reader, newest.install.installPath),
|
|
2748
2777
|
project: match?.name,
|
|
2749
2778
|
contributing: match ? existsSync6(join8(match.path, "CONTRIBUTING.md")) : false,
|
|
2750
2779
|
projectSkills: match ? projectSkillNames(match.path) : []
|
|
@@ -2796,7 +2825,7 @@ function marketplaceSourceOf(reader, marketplace) {
|
|
|
2796
2825
|
}
|
|
2797
2826
|
return void 0;
|
|
2798
2827
|
}
|
|
2799
|
-
var isRecord, inside, pluginScopes, knownMarketplaces, numeric, knowsMarketplace;
|
|
2828
|
+
var isRecord, inside, pluginScopes, knownMarketplaces, numeric, pluginUpdateArgs, knowsMarketplace;
|
|
2800
2829
|
var init_plugins = __esm({
|
|
2801
2830
|
"../core/dist/plugins.js"() {
|
|
2802
2831
|
"use strict";
|
|
@@ -2812,6 +2841,7 @@ var init_plugins = __esm({
|
|
|
2812
2841
|
];
|
|
2813
2842
|
knownMarketplaces = (configDir) => readJson(join8(configDir, "plugins", "known_marketplaces.json"));
|
|
2814
2843
|
numeric = (v) => /^\d+(\.\d+)*$/.test(v) ? v.split(".").map(Number) : null;
|
|
2844
|
+
pluginUpdateArgs = (id) => [["plugin", "marketplace", "update", splitPluginId(id).marketplace], ["plugin", "update", id]];
|
|
2815
2845
|
knowsMarketplace = (configDir, marketplace) => isRecord(knownMarketplaces(configDir)[marketplace]);
|
|
2816
2846
|
}
|
|
2817
2847
|
});
|
|
@@ -2904,8 +2934,8 @@ function skillRoutes(reader, options = {}) {
|
|
|
2904
2934
|
cpSync(source, target, { recursive: true });
|
|
2905
2935
|
return c.json({ ok: true });
|
|
2906
2936
|
} catch (err) {
|
|
2907
|
-
const
|
|
2908
|
-
return c.json({ error: `Failed to copy skill: ${
|
|
2937
|
+
const message2 = err instanceof Error ? err.message : "Unknown error";
|
|
2938
|
+
return c.json({ error: `Failed to copy skill: ${message2}` }, 500);
|
|
2909
2939
|
}
|
|
2910
2940
|
});
|
|
2911
2941
|
app.get("/global/:name", (c) => {
|
|
@@ -2941,8 +2971,8 @@ function skillRoutes(reader, options = {}) {
|
|
|
2941
2971
|
writeFileSync2(join9(dir, "SKILL.md"), content, "utf-8");
|
|
2942
2972
|
return c.json({ ok: true, dir });
|
|
2943
2973
|
} catch (err) {
|
|
2944
|
-
const
|
|
2945
|
-
return c.json({ error: `Failed to create skill: ${
|
|
2974
|
+
const message2 = err instanceof Error ? err.message : "Unknown error";
|
|
2975
|
+
return c.json({ error: `Failed to create skill: ${message2}` }, 500);
|
|
2946
2976
|
}
|
|
2947
2977
|
});
|
|
2948
2978
|
const scopePatterns = [
|
|
@@ -2968,8 +2998,8 @@ function skillRoutes(reader, options = {}) {
|
|
|
2968
2998
|
writeFileSync2(skillMd, content, "utf-8");
|
|
2969
2999
|
return c.json({ ok: true });
|
|
2970
3000
|
} catch (err) {
|
|
2971
|
-
const
|
|
2972
|
-
return c.json({ error: `Failed to update skill: ${
|
|
3001
|
+
const message2 = err instanceof Error ? err.message : "Unknown error";
|
|
3002
|
+
return c.json({ error: `Failed to update skill: ${message2}` }, 500);
|
|
2973
3003
|
}
|
|
2974
3004
|
});
|
|
2975
3005
|
app.put(`${pattern}/references/:filename`, async (c) => {
|
|
@@ -2992,8 +3022,8 @@ function skillRoutes(reader, options = {}) {
|
|
|
2992
3022
|
writeFileSync2(join9(refsDir, filename), content, "utf-8");
|
|
2993
3023
|
return c.json({ ok: true });
|
|
2994
3024
|
} catch (err) {
|
|
2995
|
-
const
|
|
2996
|
-
return c.json({ error: `Failed to write reference: ${
|
|
3025
|
+
const message2 = err instanceof Error ? err.message : "Unknown error";
|
|
3026
|
+
return c.json({ error: `Failed to write reference: ${message2}` }, 500);
|
|
2997
3027
|
}
|
|
2998
3028
|
});
|
|
2999
3029
|
app.delete(`${pattern}/references/:filename`, (c) => {
|
|
@@ -3013,8 +3043,8 @@ function skillRoutes(reader, options = {}) {
|
|
|
3013
3043
|
unlinkSync(refFile);
|
|
3014
3044
|
return c.json({ ok: true });
|
|
3015
3045
|
} catch (err) {
|
|
3016
|
-
const
|
|
3017
|
-
return c.json({ error: `Failed to delete reference: ${
|
|
3046
|
+
const message2 = err instanceof Error ? err.message : "Unknown error";
|
|
3047
|
+
return c.json({ error: `Failed to delete reference: ${message2}` }, 500);
|
|
3018
3048
|
}
|
|
3019
3049
|
});
|
|
3020
3050
|
app.delete(pattern, (c) => {
|
|
@@ -3032,8 +3062,8 @@ function skillRoutes(reader, options = {}) {
|
|
|
3032
3062
|
rmSync2(dir, { recursive: true, force: true });
|
|
3033
3063
|
return c.json({ ok: true });
|
|
3034
3064
|
} catch (err) {
|
|
3035
|
-
const
|
|
3036
|
-
return c.json({ error: `Failed to delete skill: ${
|
|
3065
|
+
const message2 = err instanceof Error ? err.message : "Unknown error";
|
|
3066
|
+
return c.json({ error: `Failed to delete skill: ${message2}` }, 500);
|
|
3037
3067
|
}
|
|
3038
3068
|
});
|
|
3039
3069
|
}
|
|
@@ -3096,7 +3126,7 @@ function skillRoutes(reader, options = {}) {
|
|
|
3096
3126
|
const install = plugin?.installs.find((i) => i.scope === scope && i.scopeRef === ref);
|
|
3097
3127
|
if (!plugin || !install)
|
|
3098
3128
|
return c.json({ error: `${id} is not installed in ${ref || "that scope"}` }, 404);
|
|
3099
|
-
const failed = await runClaude(install.scope, ref,
|
|
3129
|
+
const failed = await runClaude(install.scope, ref, pluginUpdateArgs(plugin.id), `Failed to update ${plugin.name}`);
|
|
3100
3130
|
if (failed)
|
|
3101
3131
|
return c.json({ error: failed.error }, failed.status);
|
|
3102
3132
|
const version = (await find())?.installs.find((i) => i.scope === install.scope && i.scopeRef === ref)?.version ?? install.version;
|
|
@@ -3172,6 +3202,10 @@ function ensureSpawnHelperPermissions() {
|
|
|
3172
3202
|
} catch {
|
|
3173
3203
|
}
|
|
3174
3204
|
}
|
|
3205
|
+
function slashLine(text2) {
|
|
3206
|
+
const line = typeof text2 === "string" ? text2.trim() : "";
|
|
3207
|
+
return line.length <= SLASH_MAX && /^\/[A-Za-z0-9][\w:.-]*( [^\x00-\x1f\x7f]*)?$/.test(line) ? line : null;
|
|
3208
|
+
}
|
|
3175
3209
|
function buildLaunch(session, isNew) {
|
|
3176
3210
|
const env = envWithoutHarness();
|
|
3177
3211
|
const harness = session.harness ?? "claude";
|
|
@@ -3240,7 +3274,7 @@ function buildLaunch(session, isNew) {
|
|
|
3240
3274
|
cmd += ` --model ${shellQuote(session.model)}`;
|
|
3241
3275
|
return { command: cmd + harnessFlag, env };
|
|
3242
3276
|
}
|
|
3243
|
-
var SCROLLBACK_LIMIT, IDLE_TIMEOUT_MS, CLEANUP_INTERVAL_MS, shellQuote, PTYManager;
|
|
3277
|
+
var SCROLLBACK_LIMIT, IDLE_TIMEOUT_MS, CLEANUP_INTERVAL_MS, shellQuote, SLASH_MAX, PTYManager;
|
|
3244
3278
|
var init_pty_manager = __esm({
|
|
3245
3279
|
"../core/dist/pty-manager.js"() {
|
|
3246
3280
|
"use strict";
|
|
@@ -3251,6 +3285,7 @@ var init_pty_manager = __esm({
|
|
|
3251
3285
|
CLEANUP_INTERVAL_MS = 5 * 60 * 1e3;
|
|
3252
3286
|
shellQuote = (value) => `'${value.replace(/'/g, "'\\''")}'`;
|
|
3253
3287
|
ensureSpawnHelperPermissions();
|
|
3288
|
+
SLASH_MAX = 300;
|
|
3254
3289
|
PTYManager = class {
|
|
3255
3290
|
states;
|
|
3256
3291
|
sessions = /* @__PURE__ */ new Map();
|
|
@@ -3303,10 +3338,10 @@ var init_pty_manager = __esm({
|
|
|
3303
3338
|
if (ptySession.scrollback.length > SCROLLBACK_LIMIT) {
|
|
3304
3339
|
ptySession.scrollback.splice(0, ptySession.scrollback.length - SCROLLBACK_LIMIT);
|
|
3305
3340
|
}
|
|
3306
|
-
const
|
|
3341
|
+
const message2 = JSON.stringify({ type: "output", data });
|
|
3307
3342
|
for (const client of ptySession.clients) {
|
|
3308
3343
|
try {
|
|
3309
|
-
client.send(
|
|
3344
|
+
client.send(message2);
|
|
3310
3345
|
} catch {
|
|
3311
3346
|
ptySession.clients.delete(client);
|
|
3312
3347
|
}
|
|
@@ -3314,10 +3349,10 @@ var init_pty_manager = __esm({
|
|
|
3314
3349
|
});
|
|
3315
3350
|
ptySession.onExitDisposable = ptyProcess.onExit(({ exitCode }) => {
|
|
3316
3351
|
this.states?.exit(key, exitCode);
|
|
3317
|
-
const
|
|
3352
|
+
const message2 = JSON.stringify({ type: "exit", code: exitCode });
|
|
3318
3353
|
for (const client of ptySession.clients) {
|
|
3319
3354
|
try {
|
|
3320
|
-
client.send(
|
|
3355
|
+
client.send(message2);
|
|
3321
3356
|
} catch {
|
|
3322
3357
|
}
|
|
3323
3358
|
}
|
|
@@ -3371,11 +3406,11 @@ var init_pty_manager = __esm({
|
|
|
3371
3406
|
return this.sessions.get(sessionId);
|
|
3372
3407
|
}
|
|
3373
3408
|
// types a line into a live session, then Enter apart, so the agent's prompt takes it as typed and not as a paste
|
|
3374
|
-
typeLine(project, sessionDir,
|
|
3409
|
+
typeLine(project, sessionDir, text2) {
|
|
3375
3410
|
const session = this.sessions.get(this.makeKey(project, sessionDir));
|
|
3376
3411
|
if (!session)
|
|
3377
3412
|
return false;
|
|
3378
|
-
session.pty.write(
|
|
3413
|
+
session.pty.write(text2);
|
|
3379
3414
|
setTimeout(() => session.pty.write("\r"), 150);
|
|
3380
3415
|
return true;
|
|
3381
3416
|
}
|
|
@@ -3412,11 +3447,11 @@ var init_pty_manager = __esm({
|
|
|
3412
3447
|
});
|
|
3413
3448
|
|
|
3414
3449
|
// ../core/dist/state-classifier-local.js
|
|
3415
|
-
function latestMarker(
|
|
3450
|
+
function latestMarker(text2, markers) {
|
|
3416
3451
|
let best = null;
|
|
3417
3452
|
let bestAt = -1;
|
|
3418
3453
|
for (const marker of markers) {
|
|
3419
|
-
const at = lastIndex(
|
|
3454
|
+
const at = lastIndex(text2, marker.re);
|
|
3420
3455
|
if (at > bestAt) {
|
|
3421
3456
|
best = marker;
|
|
3422
3457
|
bestAt = at;
|
|
@@ -3451,9 +3486,9 @@ var init_state_classifier_local = __esm({
|
|
|
3451
3486
|
// a spinner that stopped moving: a stall or a slow redraw, so it is only a guess
|
|
3452
3487
|
{ state: "working", confidence: 0.5, re: new RegExp("\\p{Lu}\\p{Ll}+ing\u2026|\\(\\d+s \xB7 |esc to interrupt", "gu") }
|
|
3453
3488
|
];
|
|
3454
|
-
lastIndex = (
|
|
3489
|
+
lastIndex = (text2, re) => {
|
|
3455
3490
|
let at = -1;
|
|
3456
|
-
for (const m of
|
|
3491
|
+
for (const m of text2.matchAll(re))
|
|
3457
3492
|
at = (m.index ?? 0) + m[0].length;
|
|
3458
3493
|
return at;
|
|
3459
3494
|
};
|
|
@@ -3462,8 +3497,8 @@ var init_state_classifier_local = __esm({
|
|
|
3462
3497
|
});
|
|
3463
3498
|
|
|
3464
3499
|
// ../core/dist/state-classifier-jev.js
|
|
3465
|
-
function jevScreen(
|
|
3466
|
-
const kept =
|
|
3500
|
+
function jevScreen(text2, lines2 = SCREEN_LINES) {
|
|
3501
|
+
const kept = text2.split("\n").map((l) => l.replace(FOOTER_NOISE, "").trim()).filter(Boolean).filter((l, i, all) => l !== all[i - 1]).slice(-lines2).join("\n");
|
|
3467
3502
|
return kept.slice(-SCREEN_CHARS);
|
|
3468
3503
|
}
|
|
3469
3504
|
function createJevClassifier({ apiKey, model = "jev-latest", timeoutMs = 3e3, fetch: fetch2 = globalThis.fetch }) {
|
|
@@ -3556,11 +3591,11 @@ var init_terminal_screen = __esm({
|
|
|
3556
3591
|
const line = buffer.getLine(y);
|
|
3557
3592
|
if (!line)
|
|
3558
3593
|
continue;
|
|
3559
|
-
const
|
|
3594
|
+
const text2 = line.translateToString(false);
|
|
3560
3595
|
if (line.isWrapped && rows.length)
|
|
3561
|
-
rows[rows.length - 1] +=
|
|
3596
|
+
rows[rows.length - 1] += text2;
|
|
3562
3597
|
else
|
|
3563
|
-
rows.push(
|
|
3598
|
+
rows.push(text2);
|
|
3564
3599
|
}
|
|
3565
3600
|
const trimmed = rows.map((r) => r.trimEnd());
|
|
3566
3601
|
while (trimmed.length && !trimmed[trimmed.length - 1])
|
|
@@ -3992,8 +4027,8 @@ var init_liveframe = __esm({
|
|
|
3992
4027
|
init_output();
|
|
3993
4028
|
LiveframeError = class extends Error {
|
|
3994
4029
|
status;
|
|
3995
|
-
constructor(
|
|
3996
|
-
super(
|
|
4030
|
+
constructor(message2, status = 502) {
|
|
4031
|
+
super(message2);
|
|
3997
4032
|
this.status = status;
|
|
3998
4033
|
}
|
|
3999
4034
|
};
|
|
@@ -4299,632 +4334,148 @@ var init_cw_install = __esm({
|
|
|
4299
4334
|
}
|
|
4300
4335
|
});
|
|
4301
4336
|
|
|
4302
|
-
//
|
|
4303
|
-
|
|
4304
|
-
|
|
4305
|
-
|
|
4306
|
-
|
|
4307
|
-
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
|
|
4314
|
-
|
|
4315
|
-
|
|
4316
|
-
|
|
4317
|
-
|
|
4318
|
-
|
|
4319
|
-
|
|
4320
|
-
|
|
4321
|
-
|
|
4322
|
-
|
|
4323
|
-
|
|
4324
|
-
|
|
4325
|
-
|
|
4326
|
-
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
output = (output + data).slice(-64 * 1024);
|
|
4332
|
-
});
|
|
4333
|
-
proc.onExit(({ exitCode }) => {
|
|
4334
|
-
clearTimeout(timer);
|
|
4335
|
-
const json = stripAnsi(output).split(/\r?\n/).reverse().map((line) => line.slice(line.indexOf("{")).trim()).find((line) => parseJson(line) !== null);
|
|
4336
|
-
resolve10({ code: exitCode, stdout: json ?? "", stderr: output });
|
|
4337
|
-
});
|
|
4338
|
-
});
|
|
4339
|
-
}
|
|
4340
|
-
function parseJson(text) {
|
|
4341
|
-
try {
|
|
4342
|
-
return JSON.parse(text);
|
|
4343
|
-
} catch {
|
|
4344
|
-
return null;
|
|
4337
|
+
// ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/internal/constants.js
|
|
4338
|
+
var require_constants = __commonJS({
|
|
4339
|
+
"../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/internal/constants.js"(exports, module) {
|
|
4340
|
+
"use strict";
|
|
4341
|
+
var SEMVER_SPEC_VERSION = "2.0.0";
|
|
4342
|
+
var MAX_LENGTH = 256;
|
|
4343
|
+
var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || /* istanbul ignore next */
|
|
4344
|
+
9007199254740991;
|
|
4345
|
+
var MAX_SAFE_COMPONENT_LENGTH = 16;
|
|
4346
|
+
var MAX_SAFE_BUILD_LENGTH = MAX_LENGTH - 6;
|
|
4347
|
+
var RELEASE_TYPES = [
|
|
4348
|
+
"major",
|
|
4349
|
+
"premajor",
|
|
4350
|
+
"minor",
|
|
4351
|
+
"preminor",
|
|
4352
|
+
"patch",
|
|
4353
|
+
"prepatch",
|
|
4354
|
+
"prerelease"
|
|
4355
|
+
];
|
|
4356
|
+
module.exports = {
|
|
4357
|
+
MAX_LENGTH,
|
|
4358
|
+
MAX_SAFE_COMPONENT_LENGTH,
|
|
4359
|
+
MAX_SAFE_BUILD_LENGTH,
|
|
4360
|
+
MAX_SAFE_INTEGER,
|
|
4361
|
+
RELEASE_TYPES,
|
|
4362
|
+
SEMVER_SPEC_VERSION,
|
|
4363
|
+
FLAG_INCLUDE_PRERELEASE: 1,
|
|
4364
|
+
FLAG_LOOSE: 2
|
|
4365
|
+
};
|
|
4345
4366
|
}
|
|
4346
|
-
}
|
|
4347
|
-
|
|
4348
|
-
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
while (next < items.length) {
|
|
4352
|
-
const i = next++;
|
|
4353
|
-
out[i] = await fn(items[i]);
|
|
4354
|
-
}
|
|
4355
|
-
};
|
|
4356
|
-
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
|
|
4357
|
-
return out;
|
|
4358
|
-
}
|
|
4359
|
-
var PAGE_TYPES, KiokuError, NOT_INSTALLED, START_TIMEOUT_MS, WRITE_TIMEOUT_MS, PUBLISH_TIMEOUT_MS, CACHE_MS2, ACTIVITY_SINCE, ACTIVITY_LIMIT, PARALLEL, TIERS, REPO, AREA, LANGUAGE, MISSING, brainName, Kioku;
|
|
4360
|
-
var init_kioku = __esm({
|
|
4361
|
-
"../core/dist/kioku.js"() {
|
|
4367
|
+
});
|
|
4368
|
+
|
|
4369
|
+
// ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/internal/debug.js
|
|
4370
|
+
var require_debug = __commonJS({
|
|
4371
|
+
"../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/internal/debug.js"(exports, module) {
|
|
4362
4372
|
"use strict";
|
|
4363
|
-
|
|
4364
|
-
init_cw_doctor();
|
|
4365
|
-
init_cw_install();
|
|
4366
|
-
init_output();
|
|
4367
|
-
PAGE_TYPES = {
|
|
4368
|
-
memory: { kind: "memory" },
|
|
4369
|
-
instinct: { kind: "memory", sub: "instinct" },
|
|
4370
|
-
decision: { kind: "knowledge", sub: "decision" },
|
|
4371
|
-
playbook: { kind: "knowledge", sub: "playbook" },
|
|
4372
|
-
context: { kind: "knowledge", sub: "context" },
|
|
4373
|
-
rule: { kind: "rule" }
|
|
4373
|
+
var debug = typeof process === "object" && process.env && process.env.NODE_DEBUG && /\bsemver\b/i.test(process.env.NODE_DEBUG) ? (...args) => console.error("SEMVER", ...args) : () => {
|
|
4374
4374
|
};
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4375
|
+
module.exports = debug;
|
|
4376
|
+
}
|
|
4377
|
+
});
|
|
4378
|
+
|
|
4379
|
+
// ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/internal/re.js
|
|
4380
|
+
var require_re = __commonJS({
|
|
4381
|
+
"../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/internal/re.js"(exports, module) {
|
|
4382
|
+
"use strict";
|
|
4383
|
+
var {
|
|
4384
|
+
MAX_SAFE_COMPONENT_LENGTH,
|
|
4385
|
+
MAX_SAFE_BUILD_LENGTH,
|
|
4386
|
+
MAX_LENGTH
|
|
4387
|
+
} = require_constants();
|
|
4388
|
+
var debug = require_debug();
|
|
4389
|
+
exports = module.exports = {};
|
|
4390
|
+
var re = exports.re = [];
|
|
4391
|
+
var safeRe = exports.safeRe = [];
|
|
4392
|
+
var src = exports.src = [];
|
|
4393
|
+
var safeSrc = exports.safeSrc = [];
|
|
4394
|
+
var t = exports.t = {};
|
|
4395
|
+
var R = 0;
|
|
4396
|
+
var LETTERDASHNUMBER = "[a-zA-Z0-9-]";
|
|
4397
|
+
var safeRegexReplacements = [
|
|
4398
|
+
["\\s", 1],
|
|
4399
|
+
["\\d", MAX_LENGTH],
|
|
4400
|
+
[LETTERDASHNUMBER, MAX_SAFE_BUILD_LENGTH]
|
|
4401
|
+
];
|
|
4402
|
+
var makeSafeRegex = (value) => {
|
|
4403
|
+
for (const [token, max] of safeRegexReplacements) {
|
|
4404
|
+
value = value.split(`${token}*`).join(`${token}{0,${max}}`).split(`${token}+`).join(`${token}{1,${max}}`);
|
|
4380
4405
|
}
|
|
4406
|
+
return value;
|
|
4381
4407
|
};
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
|
|
4389
|
-
|
|
4390
|
-
|
|
4391
|
-
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4408
|
+
var createToken = (name, value, isGlobal) => {
|
|
4409
|
+
const safe = makeSafeRegex(value);
|
|
4410
|
+
const index = R++;
|
|
4411
|
+
debug(name, index, value);
|
|
4412
|
+
t[name] = index;
|
|
4413
|
+
src[index] = value;
|
|
4414
|
+
safeSrc[index] = safe;
|
|
4415
|
+
re[index] = new RegExp(value, isGlobal ? "g" : void 0);
|
|
4416
|
+
safeRe[index] = new RegExp(safe, isGlobal ? "g" : void 0);
|
|
4417
|
+
};
|
|
4418
|
+
createToken("NUMERICIDENTIFIER", "0|[1-9]\\d*");
|
|
4419
|
+
createToken("NUMERICIDENTIFIERLOOSE", "\\d+");
|
|
4420
|
+
createToken("NONNUMERICIDENTIFIER", `\\d*[a-zA-Z-]${LETTERDASHNUMBER}*`);
|
|
4421
|
+
createToken("MAINVERSION", `(${src[t.NUMERICIDENTIFIER]})\\.(${src[t.NUMERICIDENTIFIER]})\\.(${src[t.NUMERICIDENTIFIER]})`);
|
|
4422
|
+
createToken("MAINVERSIONLOOSE", `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.(${src[t.NUMERICIDENTIFIERLOOSE]})\\.(${src[t.NUMERICIDENTIFIERLOOSE]})`);
|
|
4423
|
+
createToken("PRERELEASEIDENTIFIER", `(?:${src[t.NONNUMERICIDENTIFIER]}|${src[t.NUMERICIDENTIFIER]})`);
|
|
4424
|
+
createToken("PRERELEASEIDENTIFIERLOOSE", `(?:${src[t.NONNUMERICIDENTIFIER]}|${src[t.NUMERICIDENTIFIERLOOSE]})`);
|
|
4425
|
+
createToken("PRERELEASE", `(?:-(${src[t.PRERELEASEIDENTIFIER]}(?:\\.${src[t.PRERELEASEIDENTIFIER]})*))`);
|
|
4426
|
+
createToken("PRERELEASELOOSE", `(?:-?(${src[t.PRERELEASEIDENTIFIERLOOSE]}(?:\\.${src[t.PRERELEASEIDENTIFIERLOOSE]})*))`);
|
|
4427
|
+
createToken("BUILDIDENTIFIER", `${LETTERDASHNUMBER}+`);
|
|
4428
|
+
createToken("BUILD", `(?:\\+(${src[t.BUILDIDENTIFIER]}(?:\\.${src[t.BUILDIDENTIFIER]})*))`);
|
|
4429
|
+
createToken("FULLPLAIN", `v?${src[t.MAINVERSION]}${src[t.PRERELEASE]}?${src[t.BUILD]}?`);
|
|
4430
|
+
createToken("FULL", `^${src[t.FULLPLAIN]}$`);
|
|
4431
|
+
createToken("LOOSEPLAIN", `[v=\\s]*${src[t.MAINVERSIONLOOSE]}${src[t.PRERELEASELOOSE]}?${src[t.BUILD]}?`);
|
|
4432
|
+
createToken("LOOSE", `^${src[t.LOOSEPLAIN]}$`);
|
|
4433
|
+
createToken("GTLT", "((?:<|>)?=?)");
|
|
4434
|
+
createToken("XRANGEIDENTIFIERLOOSE", `${src[t.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`);
|
|
4435
|
+
createToken("XRANGEIDENTIFIER", `${src[t.NUMERICIDENTIFIER]}|x|X|\\*`);
|
|
4436
|
+
createToken("XRANGEPLAIN", `[v=\\s]*(${src[t.XRANGEIDENTIFIER]})(?:\\.(${src[t.XRANGEIDENTIFIER]})(?:\\.(${src[t.XRANGEIDENTIFIER]})(?:${src[t.PRERELEASE]})?${src[t.BUILD]}?)?)?`);
|
|
4437
|
+
createToken("XRANGEPLAINLOOSE", `[v=\\s]*(${src[t.XRANGEIDENTIFIERLOOSE]})(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})(?:${src[t.PRERELEASELOOSE]})?${src[t.BUILD]}?)?)?`);
|
|
4438
|
+
createToken("XRANGE", `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAIN]}$`);
|
|
4439
|
+
createToken("XRANGELOOSE", `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAINLOOSE]}$`);
|
|
4440
|
+
createToken("COERCEPLAIN", `${"(^|[^\\d])(\\d{1,"}${MAX_SAFE_COMPONENT_LENGTH}})(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?`);
|
|
4441
|
+
createToken("COERCE", `${src[t.COERCEPLAIN]}(?:$|[^\\d])`);
|
|
4442
|
+
createToken("COERCEFULL", src[t.COERCEPLAIN] + `(?:${src[t.PRERELEASE]})?(?:${src[t.BUILD]})?(?:$|[^\\d])`);
|
|
4443
|
+
createToken("COERCERTL", src[t.COERCE], true);
|
|
4444
|
+
createToken("COERCERTLFULL", src[t.COERCEFULL], true);
|
|
4445
|
+
createToken("LONETILDE", "(?:~>?)");
|
|
4446
|
+
createToken("TILDETRIM", `(\\s*)${src[t.LONETILDE]}\\s+`, true);
|
|
4447
|
+
exports.tildeTrimReplace = "$1~";
|
|
4448
|
+
createToken("TILDE", `^${src[t.LONETILDE]}${src[t.XRANGEPLAIN]}$`);
|
|
4449
|
+
createToken("TILDELOOSE", `^${src[t.LONETILDE]}${src[t.XRANGEPLAINLOOSE]}$`);
|
|
4450
|
+
createToken("LONECARET", "(?:\\^)");
|
|
4451
|
+
createToken("CARETTRIM", `(\\s*)${src[t.LONECARET]}\\s+`, true);
|
|
4452
|
+
exports.caretTrimReplace = "$1^";
|
|
4453
|
+
createToken("CARET", `^${src[t.LONECARET]}${src[t.XRANGEPLAIN]}$`);
|
|
4454
|
+
createToken("CARETLOOSE", `^${src[t.LONECARET]}${src[t.XRANGEPLAINLOOSE]}$`);
|
|
4455
|
+
createToken("COMPARATORLOOSE", `^${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]})$|^$`);
|
|
4456
|
+
createToken("COMPARATOR", `^${src[t.GTLT]}\\s*(${src[t.FULLPLAIN]})$|^$`);
|
|
4457
|
+
createToken("COMPARATORTRIM", `(\\s*)${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]}|${src[t.XRANGEPLAIN]})`, true);
|
|
4458
|
+
exports.comparatorTrimReplace = "$1$2$3";
|
|
4459
|
+
createToken("HYPHENRANGE", `^\\s*(${src[t.XRANGEPLAIN]})\\s+-\\s+(${src[t.XRANGEPLAIN]})\\s*$`);
|
|
4460
|
+
createToken("HYPHENRANGELOOSE", `^\\s*(${src[t.XRANGEPLAINLOOSE]})\\s+-\\s+(${src[t.XRANGEPLAINLOOSE]})\\s*$`);
|
|
4461
|
+
createToken("STAR", "(<|>)?=?\\s*\\*");
|
|
4462
|
+
createToken("GTE0", "^\\s*>=\\s*0\\.0\\.0\\s*$");
|
|
4463
|
+
createToken("GTE0PRE", "^\\s*>=\\s*0\\.0\\.0-0\\s*$");
|
|
4464
|
+
}
|
|
4465
|
+
});
|
|
4466
|
+
|
|
4467
|
+
// ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/internal/parse-options.js
|
|
4468
|
+
var require_parse_options = __commonJS({
|
|
4469
|
+
"../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/internal/parse-options.js"(exports, module) {
|
|
4470
|
+
"use strict";
|
|
4471
|
+
var looseOption = Object.freeze({ loose: true });
|
|
4472
|
+
var emptyOpts = Object.freeze({});
|
|
4473
|
+
var parseOptions = (options) => {
|
|
4474
|
+
if (!options) {
|
|
4475
|
+
return emptyOpts;
|
|
4414
4476
|
}
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
return this.binPath ??= resolveKiokuBin();
|
|
4418
|
-
}
|
|
4419
|
-
async status(fresh = false) {
|
|
4420
|
-
const previous = this.snapshot;
|
|
4421
|
-
if (fresh || !previous || this.now() - previous.at > CACHE_MS2) {
|
|
4422
|
-
const value = this.read();
|
|
4423
|
-
this.snapshot = { at: this.now(), value };
|
|
4424
|
-
value.catch(() => {
|
|
4425
|
-
if (this.snapshot?.value === value)
|
|
4426
|
-
this.snapshot = previous;
|
|
4427
|
-
});
|
|
4428
|
-
}
|
|
4429
|
-
const pending = fresh || !previous ? this.snapshot.value : previous.value;
|
|
4430
|
-
const [snapshot, viewer] = await Promise.all([pending, this.viewer?.catch(() => null) ?? null]);
|
|
4431
|
-
return { ...snapshot, viewer: viewer?.address ?? null };
|
|
4432
|
-
}
|
|
4433
|
-
async json(args, cwd) {
|
|
4434
|
-
const result2 = await this.run(this.bin, [...args, "--json"], cwd);
|
|
4435
|
-
return result2.code === 0 ? parseJson(result2.stdout) : null;
|
|
4436
|
-
}
|
|
4437
|
-
async read() {
|
|
4438
|
-
const [version, list] = await Promise.all([
|
|
4439
|
-
this.run(this.bin, ["--version"], homedir5()),
|
|
4440
|
-
this.json(["brain", "list"], homedir5())
|
|
4441
|
-
]);
|
|
4442
|
-
if (version.code !== 0)
|
|
4443
|
-
return MISSING;
|
|
4444
|
-
const listed = list?.brains ?? [];
|
|
4445
|
-
const entries = Object.entries(this.projects()).filter(([, p]) => existsSync12(p.path));
|
|
4446
|
-
const readBrain = async (b) => {
|
|
4447
|
-
if (!b.onDisk)
|
|
4448
|
-
return { kinds: {}, namespaces: [], writes: [] };
|
|
4449
|
-
const [ns, log] = await Promise.all([
|
|
4450
|
-
this.json(["namespace", "list", "--brain", b.key], b.folder),
|
|
4451
|
-
this.json(["brain", "log", "--since", ACTIVITY_SINCE, "--brain", b.key], b.folder)
|
|
4452
|
-
]);
|
|
4453
|
-
const kinds = {};
|
|
4454
|
-
const namespaces = ns?.brains?.find((x) => x.brain === brainName(b))?.namespaces ?? [];
|
|
4455
|
-
for (const n of namespaces) {
|
|
4456
|
-
for (const [kind, count] of Object.entries(n.pages))
|
|
4457
|
-
kinds[kind] = (kinds[kind] ?? 0) + count;
|
|
4458
|
-
}
|
|
4459
|
-
return { kinds, namespaces: namespaces.map((n) => n.namespace), writes: log?.writes ?? [] };
|
|
4460
|
-
};
|
|
4461
|
-
const readChain = async (path) => (await this.json(["brain", "list"], path))?.chain ?? [];
|
|
4462
|
-
const [perBrain, chains] = await Promise.all([
|
|
4463
|
-
mapLimit(listed, PARALLEL / 2, readBrain),
|
|
4464
|
-
mapLimit(entries, PARALLEL / 2, ([, p]) => readChain(p.path))
|
|
4465
|
-
]);
|
|
4466
|
-
const activity = perBrain.flatMap((p) => p.writes).sort((x, y) => y.date.localeCompare(x.date));
|
|
4467
|
-
const brains = listed.map((b, i) => {
|
|
4468
|
-
const { kinds, namespaces } = perBrain[i];
|
|
4469
|
-
const name = brainName(b);
|
|
4470
|
-
return {
|
|
4471
|
-
...b,
|
|
4472
|
-
pages: Object.values(kinds).reduce((sum, n) => sum + n, 0),
|
|
4473
|
-
kinds,
|
|
4474
|
-
namespaces,
|
|
4475
|
-
touched: activity.find((w) => w.brain === name)?.date ?? null
|
|
4476
|
-
};
|
|
4477
|
-
});
|
|
4478
|
-
const projects = Object.fromEntries(entries.map(([name], i) => [name, chains[i].map(({ name: name2, tier }) => ({ name: name2, tier }))]));
|
|
4479
|
-
return {
|
|
4480
|
-
installed: true,
|
|
4481
|
-
version: parseJson(version.stdout)?.version ?? null,
|
|
4482
|
-
brains,
|
|
4483
|
-
projects,
|
|
4484
|
-
activity: activity.slice(0, ACTIVITY_LIMIT).map(({ verb, title, path, date, author, brain }) => ({ verb, title, path, date, author, brain }))
|
|
4485
|
-
};
|
|
4486
|
-
}
|
|
4487
|
-
// writes through kioku, which validates, commits and pushes a shared brain; Forge never writes a brain's files
|
|
4488
|
-
async save(input) {
|
|
4489
|
-
const type = PAGE_TYPES[input.type];
|
|
4490
|
-
if (!type)
|
|
4491
|
-
throw new KiokuError(`unknown page type ${input.type}`, 400);
|
|
4492
|
-
const brain = await this.findBrain(input.brain);
|
|
4493
|
-
const args = [
|
|
4494
|
-
"page",
|
|
4495
|
-
"save",
|
|
4496
|
-
"--brain",
|
|
4497
|
-
brain.key,
|
|
4498
|
-
"--kind",
|
|
4499
|
-
type.kind,
|
|
4500
|
-
...type.sub ? ["--sub", type.sub] : [],
|
|
4501
|
-
"--title",
|
|
4502
|
-
input.title,
|
|
4503
|
-
"--summary",
|
|
4504
|
-
input.summary,
|
|
4505
|
-
"--source",
|
|
4506
|
-
"Forge",
|
|
4507
|
-
...input.namespace ? ["--namespace", input.namespace] : [],
|
|
4508
|
-
...input.create ? ["--create"] : [],
|
|
4509
|
-
"--json"
|
|
4510
|
-
];
|
|
4511
|
-
const { out, fail } = await this.invoke(args, brain.folder, this.write, input.body);
|
|
4512
|
-
if (out?.status === "done" && out.path) {
|
|
4513
|
-
this.expire();
|
|
4514
|
-
return { status: "done", brain: brainName(brain), path: out.path, publication: out.publication ?? null };
|
|
4515
|
-
}
|
|
4516
|
-
if (out?.status === "similar")
|
|
4517
|
-
return { status: "similar", similar: (out.similar ?? []).map(({ brain: brain2, path, title, summary }) => ({ brain: brain2, path, title, summary })) };
|
|
4518
|
-
if (out?.status === "namespace")
|
|
4519
|
-
return { status: "namespace", namespaces: (out.namespaces ?? []).map(({ namespace, summary }) => ({ namespace, summary })) };
|
|
4520
|
-
throw fail("kioku could not save the page");
|
|
4521
|
-
}
|
|
4522
|
-
// the cached reading when there is one, else only the list of brains
|
|
4523
|
-
async listBrains() {
|
|
4524
|
-
return this.snapshot ? (await this.snapshot.value).brains : (await this.json(["brain", "list"], homedir5()))?.brains ?? [];
|
|
4525
|
-
}
|
|
4526
|
-
async findBrain(key) {
|
|
4527
|
-
const brain = (await this.listBrains()).find((b) => b.key === key);
|
|
4528
|
-
if (!brain?.onDisk)
|
|
4529
|
-
throw new KiokuError(`no brain ${key} on this machine`, 404);
|
|
4530
|
-
return brain;
|
|
4531
|
-
}
|
|
4532
|
-
// the next status reads again, while the old reading still answers a poll that is not fresh
|
|
4533
|
-
expire() {
|
|
4534
|
-
if (this.snapshot)
|
|
4535
|
-
this.snapshot.at = -Infinity;
|
|
4536
|
-
}
|
|
4537
|
-
// runs a verb that writes; fail turns kioku's refusal into a 400 with its message
|
|
4538
|
-
async invoke(args, cwd, run2, input) {
|
|
4539
|
-
const result2 = await run2(this.bin, args, cwd, input);
|
|
4540
|
-
if (result2.code === 127)
|
|
4541
|
-
throw new KiokuError(NOT_INSTALLED, 404);
|
|
4542
|
-
const out = parseJson(result2.stdout);
|
|
4543
|
-
return { out, ok: result2.code === 0 && out !== null && !out.error, fail: (fallback) => new KiokuError(out?.error?.message ?? (tailOutput(result2.stderr, 1) || fallback), 400) };
|
|
4544
|
-
}
|
|
4545
|
-
async change(args, cwd, run2 = this.write) {
|
|
4546
|
-
const { out, ok, fail } = await this.invoke([...args, "--json"], cwd, run2);
|
|
4547
|
-
if (!ok || !out)
|
|
4548
|
-
throw fail(`kioku ${args.slice(0, 2).join(" ")} failed`);
|
|
4549
|
-
this.expire();
|
|
4550
|
-
return out;
|
|
4551
|
-
}
|
|
4552
|
-
// makes a brain on this machine only; kioku never makes a repository here
|
|
4553
|
-
async createBrain(input) {
|
|
4554
|
-
assertRepo(input.repo, "the brain");
|
|
4555
|
-
if (!TIERS.includes(input.tier))
|
|
4556
|
-
throw new KiokuError(`the tier is one of ${TIERS.join(", ")}`, 400);
|
|
4557
|
-
if (input.team)
|
|
4558
|
-
assertRepo(input.team, "the team brain");
|
|
4559
|
-
if (input.language && !LANGUAGE.test(input.language))
|
|
4560
|
-
throw new KiokuError("the language is a tag such as en or es", 400);
|
|
4561
|
-
const args = [
|
|
4562
|
-
"brain",
|
|
4563
|
-
"create",
|
|
4564
|
-
input.repo,
|
|
4565
|
-
"--tier",
|
|
4566
|
-
input.tier,
|
|
4567
|
-
...input.team && input.tier === "project" ? ["--team", input.team] : [],
|
|
4568
|
-
...input.language ? ["--language", input.language] : []
|
|
4569
|
-
];
|
|
4570
|
-
const { brain, name, path } = await this.change(args, homedir5());
|
|
4571
|
-
return { brain, name, path };
|
|
4572
|
-
}
|
|
4573
|
-
async addArea(key, area, summary) {
|
|
4574
|
-
if (!AREA.test(area))
|
|
4575
|
-
throw new KiokuError("an area is letters, digits, dots, dashes and underscores, with / between parts", 400);
|
|
4576
|
-
if (!summary)
|
|
4577
|
-
throw new KiokuError("say what the area is for", 400);
|
|
4578
|
-
const brain = await this.findBrain(key);
|
|
4579
|
-
const out = await this.change(["namespace", "add", area, `--summary=${summary}`, "--brain", brain.key], brain.folder);
|
|
4580
|
-
return { brain: out.brain, namespace: out.namespace };
|
|
4581
|
-
}
|
|
4582
|
-
// writes the project's kioku.yaml; a brain the machine does not know is made first, since kioku links only known brains without a terminal
|
|
4583
|
-
async linkProject(input) {
|
|
4584
|
-
if (!input.brain && !input.team)
|
|
4585
|
-
throw new KiokuError("name a project brain, a team brain, or both", 400);
|
|
4586
|
-
const path = this.projects()[input.project]?.path;
|
|
4587
|
-
if (!path || !existsSync12(path))
|
|
4588
|
-
throw new KiokuError(`no CW project ${input.project} on this machine`, 404);
|
|
4589
|
-
if (input.brain)
|
|
4590
|
-
assertRepo(input.brain, "the project brain");
|
|
4591
|
-
if (input.team)
|
|
4592
|
-
assertRepo(input.team, "the team brain");
|
|
4593
|
-
const known = await this.listBrains();
|
|
4594
|
-
const isKnown = (repo) => known.some((b) => b.key === repo || b.key.endsWith(`/${repo}`));
|
|
4595
|
-
const created = [];
|
|
4596
|
-
if (input.team && !isKnown(input.team))
|
|
4597
|
-
created.push((await this.createBrain({ repo: input.team, tier: "team" })).brain);
|
|
4598
|
-
if (input.brain && !isKnown(input.brain))
|
|
4599
|
-
created.push((await this.createBrain({ repo: input.brain, tier: "project", team: input.team })).brain);
|
|
4600
|
-
const args = ["init", ...input.brain ? [input.brain] : [], ...input.team ? ["--team", input.team] : []];
|
|
4601
|
-
const { file } = await this.change(args, path);
|
|
4602
|
-
return { file, created };
|
|
4603
|
-
}
|
|
4604
|
-
// the only verb that reaches a git host: without `to`, kioku makes a private GitHub repository with gh
|
|
4605
|
-
async publish(key, to) {
|
|
4606
|
-
if (to?.startsWith("-"))
|
|
4607
|
-
throw new KiokuError("the address cannot start with -", 400);
|
|
4608
|
-
const brain = await this.findBrain(key);
|
|
4609
|
-
if (brain.remote)
|
|
4610
|
-
throw new KiokuError(`${brainName(brain)} already has a repository: ${brain.remote}`, 400);
|
|
4611
|
-
const out = await this.change(["brain", "publish", brain.key, ...to ? ["--to", to] : []], brain.folder, this.terminal ??= createTerminalRunner(envWithoutHost(), PUBLISH_TIMEOUT_MS));
|
|
4612
|
-
return { brain: out.brain, status: out.status, remote: out.remote ?? null };
|
|
4613
|
-
}
|
|
4614
|
-
// one viewer at a time; a second call reuses the running one
|
|
4615
|
-
async openViewer() {
|
|
4616
|
-
this.viewer ??= this.startViewer();
|
|
4617
|
-
return (await this.viewer).address;
|
|
4618
|
-
}
|
|
4619
|
-
startViewer() {
|
|
4620
|
-
const started = new Promise((resolve10, reject) => {
|
|
4621
|
-
const child = spawn7(this.bin, ["web", "--json", "--no-open"], { cwd: homedir5(), stdio: ["ignore", "pipe", "pipe"] });
|
|
4622
|
-
const lines2 = createInterface({ input: child.stdout });
|
|
4623
|
-
let stderr = "";
|
|
4624
|
-
let settled = false;
|
|
4625
|
-
const finish = () => {
|
|
4626
|
-
settled = true;
|
|
4627
|
-
clearTimeout(timer);
|
|
4628
|
-
lines2.close();
|
|
4629
|
-
child.stdout?.resume();
|
|
4630
|
-
};
|
|
4631
|
-
const fail = (err) => {
|
|
4632
|
-
if (settled)
|
|
4633
|
-
return;
|
|
4634
|
-
finish();
|
|
4635
|
-
child.kill();
|
|
4636
|
-
reject(err);
|
|
4637
|
-
};
|
|
4638
|
-
const timer = setTimeout(() => fail(new KiokuError("kioku web did not start in time")), this.startTimeoutMs);
|
|
4639
|
-
child.stderr?.on("data", (chunk) => {
|
|
4640
|
-
stderr = (stderr + chunk.toString()).slice(-4096);
|
|
4641
|
-
});
|
|
4642
|
-
lines2.on("line", (line) => {
|
|
4643
|
-
const event = parseJson(line);
|
|
4644
|
-
if (settled || event?.event !== "listening" || !event.address?.startsWith("http://127.0.0.1:"))
|
|
4645
|
-
return;
|
|
4646
|
-
finish();
|
|
4647
|
-
resolve10({ child, address: event.address });
|
|
4648
|
-
});
|
|
4649
|
-
child.on("error", (err) => {
|
|
4650
|
-
const missing = err.code === "ENOENT";
|
|
4651
|
-
fail(new KiokuError(missing ? NOT_INSTALLED : err.message, missing ? 404 : 502));
|
|
4652
|
-
});
|
|
4653
|
-
child.on("close", (code) => {
|
|
4654
|
-
if (this.viewer === started)
|
|
4655
|
-
this.viewer = null;
|
|
4656
|
-
fail(new KiokuError(tailOutput(stderr, 1) || `kioku web exited with code ${code}`));
|
|
4657
|
-
});
|
|
4658
|
-
});
|
|
4659
|
-
started.catch(() => {
|
|
4660
|
-
if (this.viewer === started)
|
|
4661
|
-
this.viewer = null;
|
|
4662
|
-
});
|
|
4663
|
-
return started;
|
|
4664
|
-
}
|
|
4665
|
-
stopViewer() {
|
|
4666
|
-
void this.viewer?.then((v) => v.child.kill(), () => {
|
|
4667
|
-
});
|
|
4668
|
-
this.viewer = null;
|
|
4669
|
-
}
|
|
4670
|
-
dispose() {
|
|
4671
|
-
this.stopViewer();
|
|
4672
|
-
}
|
|
4673
|
-
};
|
|
4674
|
-
}
|
|
4675
|
-
});
|
|
4676
|
-
|
|
4677
|
-
// ../core/dist/kioku-routes.js
|
|
4678
|
-
import { Hono as Hono4 } from "hono";
|
|
4679
|
-
function kiokuRoutes(kioku = new Kioku(), options = {}) {
|
|
4680
|
-
const app = new Hono4();
|
|
4681
|
-
app.onError((err, c) => {
|
|
4682
|
-
if (err instanceof KiokuError)
|
|
4683
|
-
return c.json({ error: err.message }, err.status);
|
|
4684
|
-
throw err;
|
|
4685
|
-
});
|
|
4686
|
-
app.get("/status", async (c) => c.json(await kioku.status(c.req.query("fresh") === "1")));
|
|
4687
|
-
app.post("/pages", async (c) => {
|
|
4688
|
-
const input = await c.req.json().catch(() => ({}));
|
|
4689
|
-
const brain = input.brain?.trim();
|
|
4690
|
-
const title = input.title?.trim();
|
|
4691
|
-
const summary = input.summary?.trim();
|
|
4692
|
-
if (!brain || !input.type || !title || !summary || !input.body?.trim())
|
|
4693
|
-
return c.json({ error: "brain, type, title, summary and body are required" }, 400);
|
|
4694
|
-
const result2 = await kioku.save({ brain, type: input.type, title, summary, body: input.body, namespace: input.namespace?.trim() || void 0, create: input.create === true });
|
|
4695
|
-
return c.json(result2, result2.status === "done" ? 201 : 200);
|
|
4696
|
-
});
|
|
4697
|
-
app.post("/brains", async (c) => {
|
|
4698
|
-
const { repo, tier, team, language } = await body(c);
|
|
4699
|
-
return c.json(await kioku.createBrain({ repo: trim(repo) ?? "", tier: tier ?? "", team: trim(team), language: trim(language) }), 201);
|
|
4700
|
-
});
|
|
4701
|
-
app.post("/areas", async (c) => {
|
|
4702
|
-
const { brain, area, summary } = await body(c);
|
|
4703
|
-
return c.json(await kioku.addArea(brain ?? "", trim(area) ?? "", trim(summary) ?? ""), 201);
|
|
4704
|
-
});
|
|
4705
|
-
app.post("/link", async (c) => {
|
|
4706
|
-
const { project, brain, team } = await body(c);
|
|
4707
|
-
return c.json(await kioku.linkProject({ project: project ?? "", brain: trim(brain), team: trim(team) }));
|
|
4708
|
-
});
|
|
4709
|
-
app.post("/publish", async (c) => {
|
|
4710
|
-
const { brain, to, understood } = await body(c);
|
|
4711
|
-
if (understood !== true)
|
|
4712
|
-
return c.json({ error: "publishing needs the warning accepted" }, 400);
|
|
4713
|
-
return c.json(await kioku.publish(brain ?? "", trim(to)));
|
|
4714
|
-
});
|
|
4715
|
-
app.post("/remember", async (c) => {
|
|
4716
|
-
const { project, sessionDir, text } = await c.req.json().catch(() => ({}));
|
|
4717
|
-
const line = text?.trim();
|
|
4718
|
-
if (!project || !sessionDir || !line)
|
|
4719
|
-
return c.json({ error: "project, sessionDir and text are required" }, 400);
|
|
4720
|
-
if (line.length > REMEMBER_MAX)
|
|
4721
|
-
return c.json({ error: `keep it under ${REMEMBER_MAX} characters` }, 400);
|
|
4722
|
-
if (options.canRemember && !options.canRemember(project, sessionDir))
|
|
4723
|
-
return c.json({ error: "only Claude Code sessions have kioku's skill" }, 400);
|
|
4724
|
-
if (!options.type?.(project, sessionDir, rememberPrompt(line)))
|
|
4725
|
-
return c.json({ error: "the session has no live terminal" }, 409);
|
|
4726
|
-
return c.json({ ok: true });
|
|
4727
|
-
});
|
|
4728
|
-
app.post("/viewer", async (c) => c.json({ address: await kioku.openViewer() }));
|
|
4729
|
-
app.delete("/viewer", (c) => {
|
|
4730
|
-
kioku.stopViewer();
|
|
4731
|
-
return c.json({ ok: true });
|
|
4732
|
-
});
|
|
4733
|
-
return app;
|
|
4734
|
-
}
|
|
4735
|
-
var trim, REMEMBER_MAX, body;
|
|
4736
|
-
var init_kioku_routes = __esm({
|
|
4737
|
-
"../core/dist/kioku-routes.js"() {
|
|
4738
|
-
"use strict";
|
|
4739
|
-
init_kioku();
|
|
4740
|
-
trim = (value) => value?.trim() || void 0;
|
|
4741
|
-
REMEMBER_MAX = 500;
|
|
4742
|
-
body = (c) => c.req.json().catch(() => ({}));
|
|
4743
|
-
}
|
|
4744
|
-
});
|
|
4745
|
-
|
|
4746
|
-
// ../sdk/dist/define.js
|
|
4747
|
-
function isShellExecutor(run2) {
|
|
4748
|
-
return typeof run2 === "object" && run2 !== null && run2.kind === "shell";
|
|
4749
|
-
}
|
|
4750
|
-
var SDK_VERSION, MODULE_ID_RE;
|
|
4751
|
-
var init_define = __esm({
|
|
4752
|
-
"../sdk/dist/define.js"() {
|
|
4753
|
-
"use strict";
|
|
4754
|
-
SDK_VERSION = "1.0.0";
|
|
4755
|
-
MODULE_ID_RE = /^[a-z][a-z0-9-]{1,31}$/;
|
|
4756
|
-
}
|
|
4757
|
-
});
|
|
4758
|
-
|
|
4759
|
-
// ../sdk/dist/errors.js
|
|
4760
|
-
var PermissionError;
|
|
4761
|
-
var init_errors = __esm({
|
|
4762
|
-
"../sdk/dist/errors.js"() {
|
|
4763
|
-
"use strict";
|
|
4764
|
-
PermissionError = class extends Error {
|
|
4765
|
-
permission;
|
|
4766
|
-
value;
|
|
4767
|
-
constructor(permission, value) {
|
|
4768
|
-
super(`permission ${permission} does not cover ${value}`);
|
|
4769
|
-
this.name = "PermissionError";
|
|
4770
|
-
this.permission = permission;
|
|
4771
|
-
this.value = value;
|
|
4772
|
-
}
|
|
4773
|
-
};
|
|
4774
|
-
}
|
|
4775
|
-
});
|
|
4776
|
-
|
|
4777
|
-
// ../sdk/dist/index.js
|
|
4778
|
-
var init_dist = __esm({
|
|
4779
|
-
"../sdk/dist/index.js"() {
|
|
4780
|
-
"use strict";
|
|
4781
|
-
init_define();
|
|
4782
|
-
init_errors();
|
|
4783
|
-
}
|
|
4784
|
-
});
|
|
4785
|
-
|
|
4786
|
-
// ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/internal/constants.js
|
|
4787
|
-
var require_constants = __commonJS({
|
|
4788
|
-
"../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/internal/constants.js"(exports, module) {
|
|
4789
|
-
"use strict";
|
|
4790
|
-
var SEMVER_SPEC_VERSION = "2.0.0";
|
|
4791
|
-
var MAX_LENGTH = 256;
|
|
4792
|
-
var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || /* istanbul ignore next */
|
|
4793
|
-
9007199254740991;
|
|
4794
|
-
var MAX_SAFE_COMPONENT_LENGTH = 16;
|
|
4795
|
-
var MAX_SAFE_BUILD_LENGTH = MAX_LENGTH - 6;
|
|
4796
|
-
var RELEASE_TYPES = [
|
|
4797
|
-
"major",
|
|
4798
|
-
"premajor",
|
|
4799
|
-
"minor",
|
|
4800
|
-
"preminor",
|
|
4801
|
-
"patch",
|
|
4802
|
-
"prepatch",
|
|
4803
|
-
"prerelease"
|
|
4804
|
-
];
|
|
4805
|
-
module.exports = {
|
|
4806
|
-
MAX_LENGTH,
|
|
4807
|
-
MAX_SAFE_COMPONENT_LENGTH,
|
|
4808
|
-
MAX_SAFE_BUILD_LENGTH,
|
|
4809
|
-
MAX_SAFE_INTEGER,
|
|
4810
|
-
RELEASE_TYPES,
|
|
4811
|
-
SEMVER_SPEC_VERSION,
|
|
4812
|
-
FLAG_INCLUDE_PRERELEASE: 1,
|
|
4813
|
-
FLAG_LOOSE: 2
|
|
4814
|
-
};
|
|
4815
|
-
}
|
|
4816
|
-
});
|
|
4817
|
-
|
|
4818
|
-
// ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/internal/debug.js
|
|
4819
|
-
var require_debug = __commonJS({
|
|
4820
|
-
"../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/internal/debug.js"(exports, module) {
|
|
4821
|
-
"use strict";
|
|
4822
|
-
var debug = typeof process === "object" && process.env && process.env.NODE_DEBUG && /\bsemver\b/i.test(process.env.NODE_DEBUG) ? (...args) => console.error("SEMVER", ...args) : () => {
|
|
4823
|
-
};
|
|
4824
|
-
module.exports = debug;
|
|
4825
|
-
}
|
|
4826
|
-
});
|
|
4827
|
-
|
|
4828
|
-
// ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/internal/re.js
|
|
4829
|
-
var require_re = __commonJS({
|
|
4830
|
-
"../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/internal/re.js"(exports, module) {
|
|
4831
|
-
"use strict";
|
|
4832
|
-
var {
|
|
4833
|
-
MAX_SAFE_COMPONENT_LENGTH,
|
|
4834
|
-
MAX_SAFE_BUILD_LENGTH,
|
|
4835
|
-
MAX_LENGTH
|
|
4836
|
-
} = require_constants();
|
|
4837
|
-
var debug = require_debug();
|
|
4838
|
-
exports = module.exports = {};
|
|
4839
|
-
var re = exports.re = [];
|
|
4840
|
-
var safeRe = exports.safeRe = [];
|
|
4841
|
-
var src = exports.src = [];
|
|
4842
|
-
var safeSrc = exports.safeSrc = [];
|
|
4843
|
-
var t = exports.t = {};
|
|
4844
|
-
var R = 0;
|
|
4845
|
-
var LETTERDASHNUMBER = "[a-zA-Z0-9-]";
|
|
4846
|
-
var safeRegexReplacements = [
|
|
4847
|
-
["\\s", 1],
|
|
4848
|
-
["\\d", MAX_LENGTH],
|
|
4849
|
-
[LETTERDASHNUMBER, MAX_SAFE_BUILD_LENGTH]
|
|
4850
|
-
];
|
|
4851
|
-
var makeSafeRegex = (value) => {
|
|
4852
|
-
for (const [token, max] of safeRegexReplacements) {
|
|
4853
|
-
value = value.split(`${token}*`).join(`${token}{0,${max}}`).split(`${token}+`).join(`${token}{1,${max}}`);
|
|
4854
|
-
}
|
|
4855
|
-
return value;
|
|
4856
|
-
};
|
|
4857
|
-
var createToken = (name, value, isGlobal) => {
|
|
4858
|
-
const safe = makeSafeRegex(value);
|
|
4859
|
-
const index = R++;
|
|
4860
|
-
debug(name, index, value);
|
|
4861
|
-
t[name] = index;
|
|
4862
|
-
src[index] = value;
|
|
4863
|
-
safeSrc[index] = safe;
|
|
4864
|
-
re[index] = new RegExp(value, isGlobal ? "g" : void 0);
|
|
4865
|
-
safeRe[index] = new RegExp(safe, isGlobal ? "g" : void 0);
|
|
4866
|
-
};
|
|
4867
|
-
createToken("NUMERICIDENTIFIER", "0|[1-9]\\d*");
|
|
4868
|
-
createToken("NUMERICIDENTIFIERLOOSE", "\\d+");
|
|
4869
|
-
createToken("NONNUMERICIDENTIFIER", `\\d*[a-zA-Z-]${LETTERDASHNUMBER}*`);
|
|
4870
|
-
createToken("MAINVERSION", `(${src[t.NUMERICIDENTIFIER]})\\.(${src[t.NUMERICIDENTIFIER]})\\.(${src[t.NUMERICIDENTIFIER]})`);
|
|
4871
|
-
createToken("MAINVERSIONLOOSE", `(${src[t.NUMERICIDENTIFIERLOOSE]})\\.(${src[t.NUMERICIDENTIFIERLOOSE]})\\.(${src[t.NUMERICIDENTIFIERLOOSE]})`);
|
|
4872
|
-
createToken("PRERELEASEIDENTIFIER", `(?:${src[t.NONNUMERICIDENTIFIER]}|${src[t.NUMERICIDENTIFIER]})`);
|
|
4873
|
-
createToken("PRERELEASEIDENTIFIERLOOSE", `(?:${src[t.NONNUMERICIDENTIFIER]}|${src[t.NUMERICIDENTIFIERLOOSE]})`);
|
|
4874
|
-
createToken("PRERELEASE", `(?:-(${src[t.PRERELEASEIDENTIFIER]}(?:\\.${src[t.PRERELEASEIDENTIFIER]})*))`);
|
|
4875
|
-
createToken("PRERELEASELOOSE", `(?:-?(${src[t.PRERELEASEIDENTIFIERLOOSE]}(?:\\.${src[t.PRERELEASEIDENTIFIERLOOSE]})*))`);
|
|
4876
|
-
createToken("BUILDIDENTIFIER", `${LETTERDASHNUMBER}+`);
|
|
4877
|
-
createToken("BUILD", `(?:\\+(${src[t.BUILDIDENTIFIER]}(?:\\.${src[t.BUILDIDENTIFIER]})*))`);
|
|
4878
|
-
createToken("FULLPLAIN", `v?${src[t.MAINVERSION]}${src[t.PRERELEASE]}?${src[t.BUILD]}?`);
|
|
4879
|
-
createToken("FULL", `^${src[t.FULLPLAIN]}$`);
|
|
4880
|
-
createToken("LOOSEPLAIN", `[v=\\s]*${src[t.MAINVERSIONLOOSE]}${src[t.PRERELEASELOOSE]}?${src[t.BUILD]}?`);
|
|
4881
|
-
createToken("LOOSE", `^${src[t.LOOSEPLAIN]}$`);
|
|
4882
|
-
createToken("GTLT", "((?:<|>)?=?)");
|
|
4883
|
-
createToken("XRANGEIDENTIFIERLOOSE", `${src[t.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`);
|
|
4884
|
-
createToken("XRANGEIDENTIFIER", `${src[t.NUMERICIDENTIFIER]}|x|X|\\*`);
|
|
4885
|
-
createToken("XRANGEPLAIN", `[v=\\s]*(${src[t.XRANGEIDENTIFIER]})(?:\\.(${src[t.XRANGEIDENTIFIER]})(?:\\.(${src[t.XRANGEIDENTIFIER]})(?:${src[t.PRERELEASE]})?${src[t.BUILD]}?)?)?`);
|
|
4886
|
-
createToken("XRANGEPLAINLOOSE", `[v=\\s]*(${src[t.XRANGEIDENTIFIERLOOSE]})(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})(?:\\.(${src[t.XRANGEIDENTIFIERLOOSE]})(?:${src[t.PRERELEASELOOSE]})?${src[t.BUILD]}?)?)?`);
|
|
4887
|
-
createToken("XRANGE", `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAIN]}$`);
|
|
4888
|
-
createToken("XRANGELOOSE", `^${src[t.GTLT]}\\s*${src[t.XRANGEPLAINLOOSE]}$`);
|
|
4889
|
-
createToken("COERCEPLAIN", `${"(^|[^\\d])(\\d{1,"}${MAX_SAFE_COMPONENT_LENGTH}})(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?(?:\\.(\\d{1,${MAX_SAFE_COMPONENT_LENGTH}}))?`);
|
|
4890
|
-
createToken("COERCE", `${src[t.COERCEPLAIN]}(?:$|[^\\d])`);
|
|
4891
|
-
createToken("COERCEFULL", src[t.COERCEPLAIN] + `(?:${src[t.PRERELEASE]})?(?:${src[t.BUILD]})?(?:$|[^\\d])`);
|
|
4892
|
-
createToken("COERCERTL", src[t.COERCE], true);
|
|
4893
|
-
createToken("COERCERTLFULL", src[t.COERCEFULL], true);
|
|
4894
|
-
createToken("LONETILDE", "(?:~>?)");
|
|
4895
|
-
createToken("TILDETRIM", `(\\s*)${src[t.LONETILDE]}\\s+`, true);
|
|
4896
|
-
exports.tildeTrimReplace = "$1~";
|
|
4897
|
-
createToken("TILDE", `^${src[t.LONETILDE]}${src[t.XRANGEPLAIN]}$`);
|
|
4898
|
-
createToken("TILDELOOSE", `^${src[t.LONETILDE]}${src[t.XRANGEPLAINLOOSE]}$`);
|
|
4899
|
-
createToken("LONECARET", "(?:\\^)");
|
|
4900
|
-
createToken("CARETTRIM", `(\\s*)${src[t.LONECARET]}\\s+`, true);
|
|
4901
|
-
exports.caretTrimReplace = "$1^";
|
|
4902
|
-
createToken("CARET", `^${src[t.LONECARET]}${src[t.XRANGEPLAIN]}$`);
|
|
4903
|
-
createToken("CARETLOOSE", `^${src[t.LONECARET]}${src[t.XRANGEPLAINLOOSE]}$`);
|
|
4904
|
-
createToken("COMPARATORLOOSE", `^${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]})$|^$`);
|
|
4905
|
-
createToken("COMPARATOR", `^${src[t.GTLT]}\\s*(${src[t.FULLPLAIN]})$|^$`);
|
|
4906
|
-
createToken("COMPARATORTRIM", `(\\s*)${src[t.GTLT]}\\s*(${src[t.LOOSEPLAIN]}|${src[t.XRANGEPLAIN]})`, true);
|
|
4907
|
-
exports.comparatorTrimReplace = "$1$2$3";
|
|
4908
|
-
createToken("HYPHENRANGE", `^\\s*(${src[t.XRANGEPLAIN]})\\s+-\\s+(${src[t.XRANGEPLAIN]})\\s*$`);
|
|
4909
|
-
createToken("HYPHENRANGELOOSE", `^\\s*(${src[t.XRANGEPLAINLOOSE]})\\s+-\\s+(${src[t.XRANGEPLAINLOOSE]})\\s*$`);
|
|
4910
|
-
createToken("STAR", "(<|>)?=?\\s*\\*");
|
|
4911
|
-
createToken("GTE0", "^\\s*>=\\s*0\\.0\\.0\\s*$");
|
|
4912
|
-
createToken("GTE0PRE", "^\\s*>=\\s*0\\.0\\.0-0\\s*$");
|
|
4913
|
-
}
|
|
4914
|
-
});
|
|
4915
|
-
|
|
4916
|
-
// ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/internal/parse-options.js
|
|
4917
|
-
var require_parse_options = __commonJS({
|
|
4918
|
-
"../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/internal/parse-options.js"(exports, module) {
|
|
4919
|
-
"use strict";
|
|
4920
|
-
var looseOption = Object.freeze({ loose: true });
|
|
4921
|
-
var emptyOpts = Object.freeze({});
|
|
4922
|
-
var parseOptions = (options) => {
|
|
4923
|
-
if (!options) {
|
|
4924
|
-
return emptyOpts;
|
|
4925
|
-
}
|
|
4926
|
-
if (typeof options !== "object") {
|
|
4927
|
-
return looseOption;
|
|
4477
|
+
if (typeof options !== "object") {
|
|
4478
|
+
return looseOption;
|
|
4928
4479
|
}
|
|
4929
4480
|
return options;
|
|
4930
4481
|
};
|
|
@@ -6360,420 +5911,1077 @@ var require_valid2 = __commonJS({
|
|
|
6360
5911
|
} catch (er) {
|
|
6361
5912
|
return null;
|
|
6362
5913
|
}
|
|
6363
|
-
};
|
|
6364
|
-
module.exports = validRange;
|
|
6365
|
-
}
|
|
6366
|
-
});
|
|
6367
|
-
|
|
6368
|
-
// ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/ranges/outside.js
|
|
6369
|
-
var require_outside = __commonJS({
|
|
6370
|
-
"../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/ranges/outside.js"(exports, module) {
|
|
6371
|
-
"use strict";
|
|
6372
|
-
var SemVer = require_semver();
|
|
6373
|
-
var Comparator = require_comparator();
|
|
6374
|
-
var { ANY } = Comparator;
|
|
6375
|
-
var Range = require_range();
|
|
6376
|
-
var satisfies = require_satisfies();
|
|
6377
|
-
var gt = require_gt();
|
|
6378
|
-
var lt = require_lt();
|
|
6379
|
-
var lte = require_lte();
|
|
6380
|
-
var gte = require_gte();
|
|
6381
|
-
var outside = (version, range, hilo, options) => {
|
|
6382
|
-
version = new SemVer(version, options);
|
|
6383
|
-
range = new Range(range, options);
|
|
6384
|
-
let gtfn, ltefn, ltfn, comp, ecomp;
|
|
6385
|
-
switch (hilo) {
|
|
6386
|
-
case ">":
|
|
6387
|
-
gtfn = gt;
|
|
6388
|
-
ltefn = lte;
|
|
6389
|
-
ltfn = lt;
|
|
6390
|
-
comp = ">";
|
|
6391
|
-
ecomp = ">=";
|
|
6392
|
-
break;
|
|
6393
|
-
case "<":
|
|
6394
|
-
gtfn = lt;
|
|
6395
|
-
ltefn = gte;
|
|
6396
|
-
ltfn = gt;
|
|
6397
|
-
comp = "<";
|
|
6398
|
-
ecomp = "<=";
|
|
6399
|
-
break;
|
|
6400
|
-
default:
|
|
6401
|
-
throw new TypeError('Must provide a hilo val of "<" or ">"');
|
|
5914
|
+
};
|
|
5915
|
+
module.exports = validRange;
|
|
5916
|
+
}
|
|
5917
|
+
});
|
|
5918
|
+
|
|
5919
|
+
// ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/ranges/outside.js
|
|
5920
|
+
var require_outside = __commonJS({
|
|
5921
|
+
"../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/ranges/outside.js"(exports, module) {
|
|
5922
|
+
"use strict";
|
|
5923
|
+
var SemVer = require_semver();
|
|
5924
|
+
var Comparator = require_comparator();
|
|
5925
|
+
var { ANY } = Comparator;
|
|
5926
|
+
var Range = require_range();
|
|
5927
|
+
var satisfies = require_satisfies();
|
|
5928
|
+
var gt = require_gt();
|
|
5929
|
+
var lt = require_lt();
|
|
5930
|
+
var lte = require_lte();
|
|
5931
|
+
var gte = require_gte();
|
|
5932
|
+
var outside = (version, range, hilo, options) => {
|
|
5933
|
+
version = new SemVer(version, options);
|
|
5934
|
+
range = new Range(range, options);
|
|
5935
|
+
let gtfn, ltefn, ltfn, comp, ecomp;
|
|
5936
|
+
switch (hilo) {
|
|
5937
|
+
case ">":
|
|
5938
|
+
gtfn = gt;
|
|
5939
|
+
ltefn = lte;
|
|
5940
|
+
ltfn = lt;
|
|
5941
|
+
comp = ">";
|
|
5942
|
+
ecomp = ">=";
|
|
5943
|
+
break;
|
|
5944
|
+
case "<":
|
|
5945
|
+
gtfn = lt;
|
|
5946
|
+
ltefn = gte;
|
|
5947
|
+
ltfn = gt;
|
|
5948
|
+
comp = "<";
|
|
5949
|
+
ecomp = "<=";
|
|
5950
|
+
break;
|
|
5951
|
+
default:
|
|
5952
|
+
throw new TypeError('Must provide a hilo val of "<" or ">"');
|
|
5953
|
+
}
|
|
5954
|
+
if (satisfies(version, range, options)) {
|
|
5955
|
+
return false;
|
|
5956
|
+
}
|
|
5957
|
+
for (let i = 0; i < range.set.length; ++i) {
|
|
5958
|
+
const comparators = range.set[i];
|
|
5959
|
+
let high = null;
|
|
5960
|
+
let low = null;
|
|
5961
|
+
comparators.forEach((comparator) => {
|
|
5962
|
+
if (comparator.semver === ANY) {
|
|
5963
|
+
comparator = new Comparator(">=0.0.0");
|
|
5964
|
+
}
|
|
5965
|
+
high = high || comparator;
|
|
5966
|
+
low = low || comparator;
|
|
5967
|
+
if (gtfn(comparator.semver, high.semver, options)) {
|
|
5968
|
+
high = comparator;
|
|
5969
|
+
} else if (ltfn(comparator.semver, low.semver, options)) {
|
|
5970
|
+
low = comparator;
|
|
5971
|
+
}
|
|
5972
|
+
});
|
|
5973
|
+
if (high.operator === comp || high.operator === ecomp) {
|
|
5974
|
+
return false;
|
|
5975
|
+
}
|
|
5976
|
+
if ((!low.operator || low.operator === comp) && ltefn(version, low.semver)) {
|
|
5977
|
+
return false;
|
|
5978
|
+
} else if (low.operator === ecomp && ltfn(version, low.semver)) {
|
|
5979
|
+
return false;
|
|
5980
|
+
}
|
|
5981
|
+
}
|
|
5982
|
+
return true;
|
|
5983
|
+
};
|
|
5984
|
+
module.exports = outside;
|
|
5985
|
+
}
|
|
5986
|
+
});
|
|
5987
|
+
|
|
5988
|
+
// ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/ranges/gtr.js
|
|
5989
|
+
var require_gtr = __commonJS({
|
|
5990
|
+
"../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/ranges/gtr.js"(exports, module) {
|
|
5991
|
+
"use strict";
|
|
5992
|
+
var outside = require_outside();
|
|
5993
|
+
var gtr = (version, range, options) => outside(version, range, ">", options);
|
|
5994
|
+
module.exports = gtr;
|
|
5995
|
+
}
|
|
5996
|
+
});
|
|
5997
|
+
|
|
5998
|
+
// ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/ranges/ltr.js
|
|
5999
|
+
var require_ltr = __commonJS({
|
|
6000
|
+
"../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/ranges/ltr.js"(exports, module) {
|
|
6001
|
+
"use strict";
|
|
6002
|
+
var outside = require_outside();
|
|
6003
|
+
var ltr = (version, range, options) => outside(version, range, "<", options);
|
|
6004
|
+
module.exports = ltr;
|
|
6005
|
+
}
|
|
6006
|
+
});
|
|
6007
|
+
|
|
6008
|
+
// ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/ranges/intersects.js
|
|
6009
|
+
var require_intersects = __commonJS({
|
|
6010
|
+
"../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/ranges/intersects.js"(exports, module) {
|
|
6011
|
+
"use strict";
|
|
6012
|
+
var Range = require_range();
|
|
6013
|
+
var intersects = (r1, r2, options) => {
|
|
6014
|
+
r1 = new Range(r1, options);
|
|
6015
|
+
r2 = new Range(r2, options);
|
|
6016
|
+
return r1.intersects(r2, options);
|
|
6017
|
+
};
|
|
6018
|
+
module.exports = intersects;
|
|
6019
|
+
}
|
|
6020
|
+
});
|
|
6021
|
+
|
|
6022
|
+
// ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/ranges/simplify.js
|
|
6023
|
+
var require_simplify = __commonJS({
|
|
6024
|
+
"../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/ranges/simplify.js"(exports, module) {
|
|
6025
|
+
"use strict";
|
|
6026
|
+
var satisfies = require_satisfies();
|
|
6027
|
+
var compare = require_compare();
|
|
6028
|
+
module.exports = (versions, range, options) => {
|
|
6029
|
+
const set = [];
|
|
6030
|
+
let first = null;
|
|
6031
|
+
let prev = null;
|
|
6032
|
+
const v = versions.sort((a, b) => compare(a, b, options));
|
|
6033
|
+
for (const version of v) {
|
|
6034
|
+
const included = satisfies(version, range, options);
|
|
6035
|
+
if (included) {
|
|
6036
|
+
prev = version;
|
|
6037
|
+
if (!first) {
|
|
6038
|
+
first = version;
|
|
6039
|
+
}
|
|
6040
|
+
} else {
|
|
6041
|
+
if (prev) {
|
|
6042
|
+
set.push([first, prev]);
|
|
6043
|
+
}
|
|
6044
|
+
prev = null;
|
|
6045
|
+
first = null;
|
|
6046
|
+
}
|
|
6047
|
+
}
|
|
6048
|
+
if (first) {
|
|
6049
|
+
set.push([first, null]);
|
|
6050
|
+
}
|
|
6051
|
+
const ranges = [];
|
|
6052
|
+
for (const [min, max] of set) {
|
|
6053
|
+
if (min === max) {
|
|
6054
|
+
ranges.push(min);
|
|
6055
|
+
} else if (!max && min === v[0]) {
|
|
6056
|
+
ranges.push("*");
|
|
6057
|
+
} else if (!max) {
|
|
6058
|
+
ranges.push(`>=${min}`);
|
|
6059
|
+
} else if (min === v[0]) {
|
|
6060
|
+
ranges.push(`<=${max}`);
|
|
6061
|
+
} else {
|
|
6062
|
+
ranges.push(`${min} - ${max}`);
|
|
6063
|
+
}
|
|
6064
|
+
}
|
|
6065
|
+
const simplified = ranges.join(" || ");
|
|
6066
|
+
const original = typeof range.raw === "string" ? range.raw : String(range);
|
|
6067
|
+
return simplified.length < original.length ? simplified : range;
|
|
6068
|
+
};
|
|
6069
|
+
}
|
|
6070
|
+
});
|
|
6071
|
+
|
|
6072
|
+
// ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/ranges/subset.js
|
|
6073
|
+
var require_subset = __commonJS({
|
|
6074
|
+
"../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/ranges/subset.js"(exports, module) {
|
|
6075
|
+
"use strict";
|
|
6076
|
+
var Range = require_range();
|
|
6077
|
+
var Comparator = require_comparator();
|
|
6078
|
+
var { ANY } = Comparator;
|
|
6079
|
+
var satisfies = require_satisfies();
|
|
6080
|
+
var compare = require_compare();
|
|
6081
|
+
var subset = (sub, dom, options = {}) => {
|
|
6082
|
+
if (sub === dom) {
|
|
6083
|
+
return true;
|
|
6084
|
+
}
|
|
6085
|
+
sub = new Range(sub, options);
|
|
6086
|
+
dom = new Range(dom, options);
|
|
6087
|
+
let sawNonNull = false;
|
|
6088
|
+
OUTER: for (const simpleSub of sub.set) {
|
|
6089
|
+
for (const simpleDom of dom.set) {
|
|
6090
|
+
const isSub = simpleSubset(simpleSub, simpleDom, options);
|
|
6091
|
+
sawNonNull = sawNonNull || isSub !== null;
|
|
6092
|
+
if (isSub) {
|
|
6093
|
+
continue OUTER;
|
|
6094
|
+
}
|
|
6095
|
+
}
|
|
6096
|
+
if (sawNonNull) {
|
|
6097
|
+
return false;
|
|
6098
|
+
}
|
|
6099
|
+
}
|
|
6100
|
+
return true;
|
|
6101
|
+
};
|
|
6102
|
+
var minimumVersionWithPreRelease = [new Comparator(">=0.0.0-0")];
|
|
6103
|
+
var minimumVersion = [new Comparator(">=0.0.0")];
|
|
6104
|
+
var simpleSubset = (sub, dom, options) => {
|
|
6105
|
+
if (sub === dom) {
|
|
6106
|
+
return true;
|
|
6107
|
+
}
|
|
6108
|
+
if (sub.length === 1 && sub[0].semver === ANY) {
|
|
6109
|
+
if (dom.length === 1 && dom[0].semver === ANY) {
|
|
6110
|
+
return true;
|
|
6111
|
+
} else if (options.includePrerelease) {
|
|
6112
|
+
sub = minimumVersionWithPreRelease;
|
|
6113
|
+
} else {
|
|
6114
|
+
sub = minimumVersion;
|
|
6115
|
+
}
|
|
6116
|
+
}
|
|
6117
|
+
if (dom.length === 1 && dom[0].semver === ANY) {
|
|
6118
|
+
if (options.includePrerelease) {
|
|
6119
|
+
return true;
|
|
6120
|
+
} else {
|
|
6121
|
+
dom = minimumVersion;
|
|
6122
|
+
}
|
|
6123
|
+
}
|
|
6124
|
+
const eqSet = /* @__PURE__ */ new Set();
|
|
6125
|
+
let gt, lt;
|
|
6126
|
+
for (const c of sub) {
|
|
6127
|
+
if (c.operator === ">" || c.operator === ">=") {
|
|
6128
|
+
gt = higherGT(gt, c, options);
|
|
6129
|
+
} else if (c.operator === "<" || c.operator === "<=") {
|
|
6130
|
+
lt = lowerLT(lt, c, options);
|
|
6131
|
+
} else {
|
|
6132
|
+
eqSet.add(c.semver);
|
|
6133
|
+
}
|
|
6134
|
+
}
|
|
6135
|
+
if (eqSet.size > 1) {
|
|
6136
|
+
return null;
|
|
6137
|
+
}
|
|
6138
|
+
let gtltComp;
|
|
6139
|
+
if (gt && lt) {
|
|
6140
|
+
gtltComp = compare(gt.semver, lt.semver, options);
|
|
6141
|
+
if (gtltComp > 0) {
|
|
6142
|
+
return null;
|
|
6143
|
+
} else if (gtltComp === 0 && (gt.operator !== ">=" || lt.operator !== "<=")) {
|
|
6144
|
+
return null;
|
|
6145
|
+
}
|
|
6402
6146
|
}
|
|
6403
|
-
|
|
6404
|
-
|
|
6147
|
+
for (const eq of eqSet) {
|
|
6148
|
+
if (gt && !satisfies(eq, String(gt), options)) {
|
|
6149
|
+
return null;
|
|
6150
|
+
}
|
|
6151
|
+
if (lt && !satisfies(eq, String(lt), options)) {
|
|
6152
|
+
return null;
|
|
6153
|
+
}
|
|
6154
|
+
for (const c of dom) {
|
|
6155
|
+
if (!satisfies(eq, String(c), options)) {
|
|
6156
|
+
return false;
|
|
6157
|
+
}
|
|
6158
|
+
}
|
|
6159
|
+
return true;
|
|
6405
6160
|
}
|
|
6406
|
-
|
|
6407
|
-
|
|
6408
|
-
|
|
6409
|
-
|
|
6410
|
-
|
|
6411
|
-
|
|
6412
|
-
|
|
6161
|
+
let higher, lower;
|
|
6162
|
+
let hasDomLT, hasDomGT;
|
|
6163
|
+
let needDomLTPre = lt && !options.includePrerelease && lt.semver.prerelease.length ? lt.semver : false;
|
|
6164
|
+
let needDomGTPre = gt && !options.includePrerelease && gt.semver.prerelease.length ? gt.semver : false;
|
|
6165
|
+
if (needDomLTPre && needDomLTPre.prerelease.length === 1 && lt.operator === "<" && needDomLTPre.prerelease[0] === 0) {
|
|
6166
|
+
needDomLTPre = false;
|
|
6167
|
+
}
|
|
6168
|
+
for (const c of dom) {
|
|
6169
|
+
hasDomGT = hasDomGT || c.operator === ">" || c.operator === ">=";
|
|
6170
|
+
hasDomLT = hasDomLT || c.operator === "<" || c.operator === "<=";
|
|
6171
|
+
if (gt) {
|
|
6172
|
+
if (needDomGTPre) {
|
|
6173
|
+
if (c.semver.prerelease && c.semver.prerelease.length && c.semver.major === needDomGTPre.major && c.semver.minor === needDomGTPre.minor && c.semver.patch === needDomGTPre.patch) {
|
|
6174
|
+
needDomGTPre = false;
|
|
6175
|
+
}
|
|
6413
6176
|
}
|
|
6414
|
-
|
|
6415
|
-
|
|
6416
|
-
|
|
6417
|
-
|
|
6418
|
-
|
|
6419
|
-
|
|
6177
|
+
if (c.operator === ">" || c.operator === ">=") {
|
|
6178
|
+
higher = higherGT(gt, c, options);
|
|
6179
|
+
if (higher === c && higher !== gt) {
|
|
6180
|
+
return false;
|
|
6181
|
+
}
|
|
6182
|
+
} else if (gt.operator === ">=" && !c.test(gt.semver)) {
|
|
6183
|
+
return false;
|
|
6420
6184
|
}
|
|
6421
|
-
});
|
|
6422
|
-
if (high.operator === comp || high.operator === ecomp) {
|
|
6423
|
-
return false;
|
|
6424
6185
|
}
|
|
6425
|
-
if (
|
|
6426
|
-
|
|
6427
|
-
|
|
6186
|
+
if (lt) {
|
|
6187
|
+
if (needDomLTPre) {
|
|
6188
|
+
if (c.semver.prerelease && c.semver.prerelease.length && c.semver.major === needDomLTPre.major && c.semver.minor === needDomLTPre.minor && c.semver.patch === needDomLTPre.patch) {
|
|
6189
|
+
needDomLTPre = false;
|
|
6190
|
+
}
|
|
6191
|
+
}
|
|
6192
|
+
if (c.operator === "<" || c.operator === "<=") {
|
|
6193
|
+
lower = lowerLT(lt, c, options);
|
|
6194
|
+
if (lower === c && lower !== lt) {
|
|
6195
|
+
return false;
|
|
6196
|
+
}
|
|
6197
|
+
} else if (lt.operator === "<=" && !c.test(lt.semver)) {
|
|
6198
|
+
return false;
|
|
6199
|
+
}
|
|
6200
|
+
}
|
|
6201
|
+
if (!c.operator && (lt || gt) && gtltComp !== 0) {
|
|
6428
6202
|
return false;
|
|
6429
6203
|
}
|
|
6430
6204
|
}
|
|
6205
|
+
if (gt && hasDomLT && !lt && gtltComp !== 0) {
|
|
6206
|
+
return false;
|
|
6207
|
+
}
|
|
6208
|
+
if (lt && hasDomGT && !gt && gtltComp !== 0) {
|
|
6209
|
+
return false;
|
|
6210
|
+
}
|
|
6211
|
+
if (needDomGTPre || needDomLTPre) {
|
|
6212
|
+
return false;
|
|
6213
|
+
}
|
|
6431
6214
|
return true;
|
|
6432
6215
|
};
|
|
6433
|
-
|
|
6434
|
-
|
|
6435
|
-
|
|
6436
|
-
|
|
6437
|
-
|
|
6438
|
-
|
|
6439
|
-
|
|
6440
|
-
|
|
6441
|
-
|
|
6442
|
-
|
|
6443
|
-
|
|
6216
|
+
var higherGT = (a, b, options) => {
|
|
6217
|
+
if (!a) {
|
|
6218
|
+
return b;
|
|
6219
|
+
}
|
|
6220
|
+
const comp = compare(a.semver, b.semver, options);
|
|
6221
|
+
return comp > 0 ? a : comp < 0 ? b : b.operator === ">" && a.operator === ">=" ? b : a;
|
|
6222
|
+
};
|
|
6223
|
+
var lowerLT = (a, b, options) => {
|
|
6224
|
+
if (!a) {
|
|
6225
|
+
return b;
|
|
6226
|
+
}
|
|
6227
|
+
const comp = compare(a.semver, b.semver, options);
|
|
6228
|
+
return comp < 0 ? a : comp > 0 ? b : b.operator === "<" && a.operator === "<=" ? b : a;
|
|
6229
|
+
};
|
|
6230
|
+
module.exports = subset;
|
|
6444
6231
|
}
|
|
6445
6232
|
});
|
|
6446
6233
|
|
|
6447
|
-
// ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/
|
|
6448
|
-
var
|
|
6449
|
-
"../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/
|
|
6234
|
+
// ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/index.js
|
|
6235
|
+
var require_semver2 = __commonJS({
|
|
6236
|
+
"../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/index.js"(exports, module) {
|
|
6450
6237
|
"use strict";
|
|
6238
|
+
var internalRe = require_re();
|
|
6239
|
+
var constants3 = require_constants();
|
|
6240
|
+
var SemVer = require_semver();
|
|
6241
|
+
var identifiers = require_identifiers();
|
|
6242
|
+
var parse = require_parse();
|
|
6243
|
+
var valid = require_valid();
|
|
6244
|
+
var clean = require_clean();
|
|
6245
|
+
var inc = require_inc();
|
|
6246
|
+
var diff = require_diff();
|
|
6247
|
+
var major = require_major();
|
|
6248
|
+
var minor = require_minor();
|
|
6249
|
+
var patch = require_patch();
|
|
6250
|
+
var prerelease = require_prerelease();
|
|
6251
|
+
var compare = require_compare();
|
|
6252
|
+
var rcompare = require_rcompare();
|
|
6253
|
+
var compareLoose = require_compare_loose();
|
|
6254
|
+
var compareBuild = require_compare_build();
|
|
6255
|
+
var sort = require_sort();
|
|
6256
|
+
var rsort = require_rsort();
|
|
6257
|
+
var gt = require_gt();
|
|
6258
|
+
var lt = require_lt();
|
|
6259
|
+
var eq = require_eq();
|
|
6260
|
+
var neq = require_neq();
|
|
6261
|
+
var gte = require_gte();
|
|
6262
|
+
var lte = require_lte();
|
|
6263
|
+
var cmp = require_cmp();
|
|
6264
|
+
var coerce = require_coerce();
|
|
6265
|
+
var truncate = require_truncate();
|
|
6266
|
+
var Comparator = require_comparator();
|
|
6267
|
+
var Range = require_range();
|
|
6268
|
+
var satisfies = require_satisfies();
|
|
6269
|
+
var toComparators = require_to_comparators();
|
|
6270
|
+
var maxSatisfying = require_max_satisfying();
|
|
6271
|
+
var minSatisfying = require_min_satisfying();
|
|
6272
|
+
var minVersion = require_min_version();
|
|
6273
|
+
var validRange = require_valid2();
|
|
6451
6274
|
var outside = require_outside();
|
|
6452
|
-
var
|
|
6453
|
-
|
|
6275
|
+
var gtr = require_gtr();
|
|
6276
|
+
var ltr = require_ltr();
|
|
6277
|
+
var intersects = require_intersects();
|
|
6278
|
+
var simplifyRange = require_simplify();
|
|
6279
|
+
var subset = require_subset();
|
|
6280
|
+
module.exports = {
|
|
6281
|
+
parse,
|
|
6282
|
+
valid,
|
|
6283
|
+
clean,
|
|
6284
|
+
inc,
|
|
6285
|
+
diff,
|
|
6286
|
+
major,
|
|
6287
|
+
minor,
|
|
6288
|
+
patch,
|
|
6289
|
+
prerelease,
|
|
6290
|
+
compare,
|
|
6291
|
+
rcompare,
|
|
6292
|
+
compareLoose,
|
|
6293
|
+
compareBuild,
|
|
6294
|
+
sort,
|
|
6295
|
+
rsort,
|
|
6296
|
+
gt,
|
|
6297
|
+
lt,
|
|
6298
|
+
eq,
|
|
6299
|
+
neq,
|
|
6300
|
+
gte,
|
|
6301
|
+
lte,
|
|
6302
|
+
cmp,
|
|
6303
|
+
coerce,
|
|
6304
|
+
truncate,
|
|
6305
|
+
Comparator,
|
|
6306
|
+
Range,
|
|
6307
|
+
satisfies,
|
|
6308
|
+
toComparators,
|
|
6309
|
+
maxSatisfying,
|
|
6310
|
+
minSatisfying,
|
|
6311
|
+
minVersion,
|
|
6312
|
+
validRange,
|
|
6313
|
+
outside,
|
|
6314
|
+
gtr,
|
|
6315
|
+
ltr,
|
|
6316
|
+
intersects,
|
|
6317
|
+
simplifyRange,
|
|
6318
|
+
subset,
|
|
6319
|
+
SemVer,
|
|
6320
|
+
re: internalRe.re,
|
|
6321
|
+
src: internalRe.src,
|
|
6322
|
+
tokens: internalRe.t,
|
|
6323
|
+
SEMVER_SPEC_VERSION: constants3.SEMVER_SPEC_VERSION,
|
|
6324
|
+
RELEASE_TYPES: constants3.RELEASE_TYPES,
|
|
6325
|
+
compareIdentifiers: identifiers.compareIdentifiers,
|
|
6326
|
+
rcompareIdentifiers: identifiers.rcompareIdentifiers
|
|
6327
|
+
};
|
|
6454
6328
|
}
|
|
6455
6329
|
});
|
|
6456
6330
|
|
|
6457
|
-
//
|
|
6458
|
-
|
|
6459
|
-
"
|
|
6460
|
-
|
|
6461
|
-
|
|
6462
|
-
|
|
6463
|
-
|
|
6464
|
-
|
|
6465
|
-
|
|
6331
|
+
// ../core/dist/kioku-versions.js
|
|
6332
|
+
function readRelease(r, bin) {
|
|
6333
|
+
const version = String(r["tag_name"]).replace(/^v/, "");
|
|
6334
|
+
return {
|
|
6335
|
+
version,
|
|
6336
|
+
prerelease: r["prerelease"] === true,
|
|
6337
|
+
date: text(r["published_at"]) ?? "",
|
|
6338
|
+
notes: text(r["body"])?.trim() ?? "",
|
|
6339
|
+
notesUrl: text(r["html_url"]) ?? `https://github.com/${KIOKU_REPO}/releases/tag/v${version}`,
|
|
6340
|
+
install: commandLine(bin, ["update", version])
|
|
6341
|
+
};
|
|
6342
|
+
}
|
|
6343
|
+
function mismatches(installed, all, plugins) {
|
|
6344
|
+
const tool = installed ? majorOf(installed) : null;
|
|
6345
|
+
if (tool === null)
|
|
6346
|
+
return [];
|
|
6347
|
+
return plugins.flatMap((p) => {
|
|
6348
|
+
const plugin = majorOf(p.version);
|
|
6349
|
+
if (plugin === null || plugin === tool)
|
|
6350
|
+
return [];
|
|
6351
|
+
const env = p.scope === "global" ? "" : `CLAUDE_CONFIG_DIR=${quote(p.configDir)} `;
|
|
6352
|
+
const release = all.find((r) => majorOf(r.version) === plugin);
|
|
6353
|
+
const fix = plugin < tool ? { kind: "plugin", command: p.update.map((args) => env + commandLine("claude", args)).join(" && ") } : release ? { kind: "release", version: release.version, command: release.install } : null;
|
|
6354
|
+
return [{ scope: p.scope, scopeRef: p.scopeRef, plugin: p.id, version: p.version, fix }];
|
|
6355
|
+
});
|
|
6356
|
+
}
|
|
6357
|
+
function stableActionFor(installed, stable2) {
|
|
6358
|
+
if (!stable2 || !installed || installed === stable2.version)
|
|
6359
|
+
return null;
|
|
6360
|
+
if (import_semver.default.prerelease(installed))
|
|
6361
|
+
return "back";
|
|
6362
|
+
return import_semver.default.gt(stable2.version, installed) ? "update" : null;
|
|
6363
|
+
}
|
|
6364
|
+
function pickReleases(listed, installed, plugins, bin) {
|
|
6365
|
+
const all = (Array.isArray(listed) ? listed : []).filter(isRecord2).filter((r) => r["draft"] !== true && isVersion(String(r["tag_name"] ?? "").replace(/^v/, ""))).map((r) => readRelease(r, bin)).sort((a, b) => import_semver.default.rcompare(a.version, b.version));
|
|
6366
|
+
const stable2 = all.find((r) => !r.prerelease) ?? null;
|
|
6367
|
+
const newer = (v) => (!installed || import_semver.default.gt(v, installed)) && (!stable2 || import_semver.default.gt(v, stable2.version));
|
|
6368
|
+
return {
|
|
6369
|
+
installed,
|
|
6370
|
+
stable: stable2,
|
|
6371
|
+
stableAction: stableActionFor(installed, stable2),
|
|
6372
|
+
prereleases: all.filter((r) => r.prerelease && newer(r.version)),
|
|
6373
|
+
mismatches: mismatches(installed, all, plugins)
|
|
6374
|
+
};
|
|
6375
|
+
}
|
|
6376
|
+
function readUpdate(out, command) {
|
|
6377
|
+
const agents = (Array.isArray(out["agents"]) ? out["agents"] : []).filter(isRecord2).map((a) => ({
|
|
6378
|
+
host: String(a["host"] ?? ""),
|
|
6379
|
+
name: String(a["name"] ?? ""),
|
|
6380
|
+
from: text(a["from"]),
|
|
6381
|
+
to: text(a["to"]),
|
|
6382
|
+
changed: a["changed"] === true,
|
|
6383
|
+
error: message(a["error"])
|
|
6384
|
+
}));
|
|
6385
|
+
return { status: String(out["status"] ?? ""), version: text(out["version"]), was: text(out["was"]), agents, finishError: message(out["finishError"]), command };
|
|
6386
|
+
}
|
|
6387
|
+
function readLabs(out, bin) {
|
|
6388
|
+
const listed = isRecord2(out) && Array.isArray(out["labs"]) ? out["labs"] : [];
|
|
6389
|
+
return listed.filter(isRecord2).filter((l) => LAB_NAME.test(String(l["name"] ?? ""))).map((l) => {
|
|
6390
|
+
const name = String(l["name"]);
|
|
6391
|
+
const enabled = l["enabled"] === true;
|
|
6392
|
+
const settings = isRecord2(l["settings"]) ? l["settings"] : void 0;
|
|
6393
|
+
const set = settings && Object.fromEntries(Object.entries(settings).filter(([, value]) => value !== null && value !== void 0).map(([key, value]) => [key, commandLine(bin, ["config", "set", `labs.${name}.${key}`, typeof value === "string" ? value : JSON.stringify(value)])]));
|
|
6394
|
+
return {
|
|
6395
|
+
name,
|
|
6396
|
+
title: text(l["title"]) ?? name,
|
|
6397
|
+
about: text(l["about"]) ?? "",
|
|
6398
|
+
enabled,
|
|
6399
|
+
...settings ? { settings, set } : {},
|
|
6400
|
+
...text(l["command"]) ? { command: text(l["command"]) } : {},
|
|
6401
|
+
toggle: commandLine(bin, labArgs(name, !enabled))
|
|
6466
6402
|
};
|
|
6467
|
-
|
|
6403
|
+
});
|
|
6404
|
+
}
|
|
6405
|
+
var import_semver, KIOKU_REPO, RELEASES_ARGS, LAB_NAME, isVersion, quote, commandLine, updateArgs, labArgs, LABS_ARGS, majorOf, isRecord2, text, message;
|
|
6406
|
+
var init_kioku_versions = __esm({
|
|
6407
|
+
"../core/dist/kioku-versions.js"() {
|
|
6408
|
+
"use strict";
|
|
6409
|
+
import_semver = __toESM(require_semver2(), 1);
|
|
6410
|
+
KIOKU_REPO = "monoku/kioku";
|
|
6411
|
+
RELEASES_ARGS = ["api", `repos/${KIOKU_REPO}/releases`];
|
|
6412
|
+
LAB_NAME = /^[A-Za-z0-9][\w-]*$/;
|
|
6413
|
+
isVersion = (v) => import_semver.default.valid(v) === v;
|
|
6414
|
+
quote = (arg) => /^[\w./@:=-]+$/.test(arg) ? arg : `'${arg.replace(/'/g, `'\\''`)}'`;
|
|
6415
|
+
commandLine = (bin, args) => [bin, ...args].map(quote).join(" ");
|
|
6416
|
+
updateArgs = (version, check = false) => ["update", version, ...check ? ["--check"] : []];
|
|
6417
|
+
labArgs = (name, enabled) => ["config", "set", `labs.${name}.enabled`, String(enabled)];
|
|
6418
|
+
LABS_ARGS = ["labs", "list"];
|
|
6419
|
+
majorOf = (v) => import_semver.default.parse(v)?.major ?? null;
|
|
6420
|
+
isRecord2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
6421
|
+
text = (v) => typeof v === "string" ? v : null;
|
|
6422
|
+
message = (v) => text(v) ?? (isRecord2(v) ? text(v["message"]) : null);
|
|
6468
6423
|
}
|
|
6469
6424
|
});
|
|
6470
6425
|
|
|
6471
|
-
//
|
|
6472
|
-
|
|
6473
|
-
|
|
6426
|
+
// ../core/dist/kioku.js
|
|
6427
|
+
import { spawn as spawn7 } from "node:child_process";
|
|
6428
|
+
import { existsSync as existsSync12 } from "node:fs";
|
|
6429
|
+
import { homedir as homedir5 } from "node:os";
|
|
6430
|
+
import { join as join13 } from "node:path";
|
|
6431
|
+
import { createInterface } from "node:readline";
|
|
6432
|
+
import * as pty3 from "node-pty";
|
|
6433
|
+
function assertVersion(version) {
|
|
6434
|
+
if (!isVersion(version))
|
|
6435
|
+
throw new KiokuError(`a kioku version reads like 5.0.0 or 5.0.0-rc.1, not "${version}"`, 400);
|
|
6436
|
+
}
|
|
6437
|
+
function assertRepo(repo, what) {
|
|
6438
|
+
if (!REPO.test(repo))
|
|
6439
|
+
throw new KiokuError(`${what} is named as owner/repo, not "${repo}"`, 400);
|
|
6440
|
+
}
|
|
6441
|
+
function resolveKiokuBin(pathVar = process.env.PATH, home = homedir5()) {
|
|
6442
|
+
const fallback = join13(home, ".local", "bin", "kioku");
|
|
6443
|
+
return findOnPath("kioku", pathVar) ?? (existsSync12(fallback) ? fallback : "kioku");
|
|
6444
|
+
}
|
|
6445
|
+
function rememberPrompt(text2) {
|
|
6446
|
+
return `Remember this with kioku: ${text2.replace(/\s+/g, " ").trim()}`;
|
|
6447
|
+
}
|
|
6448
|
+
function createTerminalRunner(env, timeoutMs) {
|
|
6449
|
+
return (bin, args, cwd) => new Promise((resolve10) => {
|
|
6450
|
+
let proc;
|
|
6451
|
+
try {
|
|
6452
|
+
proc = pty3.spawn(bin, args, { name: "xterm-256color", cols: 400, rows: 40, cwd, env });
|
|
6453
|
+
} catch {
|
|
6454
|
+
return resolve10({ code: 127, stdout: "", stderr: "ENOENT" });
|
|
6455
|
+
}
|
|
6456
|
+
let output = "";
|
|
6457
|
+
const timer = setTimeout(() => proc.kill(), timeoutMs);
|
|
6458
|
+
proc.onData((data) => {
|
|
6459
|
+
output = (output + data).slice(-64 * 1024);
|
|
6460
|
+
});
|
|
6461
|
+
proc.onExit(({ exitCode }) => {
|
|
6462
|
+
clearTimeout(timer);
|
|
6463
|
+
const json = stripAnsi(output).split(/\r?\n/).reverse().map((line) => line.slice(line.indexOf("{")).trim()).find((line) => parseJson(line) !== null);
|
|
6464
|
+
resolve10({ code: exitCode, stdout: json ?? "", stderr: output });
|
|
6465
|
+
});
|
|
6466
|
+
});
|
|
6467
|
+
}
|
|
6468
|
+
function parseJson(text2) {
|
|
6469
|
+
try {
|
|
6470
|
+
return JSON.parse(text2);
|
|
6471
|
+
} catch {
|
|
6472
|
+
return null;
|
|
6473
|
+
}
|
|
6474
|
+
}
|
|
6475
|
+
async function mapLimit(items, limit, fn) {
|
|
6476
|
+
const out = new Array(items.length);
|
|
6477
|
+
let next = 0;
|
|
6478
|
+
const worker = async () => {
|
|
6479
|
+
while (next < items.length) {
|
|
6480
|
+
const i = next++;
|
|
6481
|
+
out[i] = await fn(items[i]);
|
|
6482
|
+
}
|
|
6483
|
+
};
|
|
6484
|
+
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
|
|
6485
|
+
return out;
|
|
6486
|
+
}
|
|
6487
|
+
var PAGE_TYPES, KiokuError, NOT_INSTALLED, START_TIMEOUT_MS, WRITE_TIMEOUT_MS, TERMINAL_TIMEOUT_MS, CACHE_MS2, RELEASES_CACHE_MS, SHOWN_BIN, ACTIVITY_SINCE, ACTIVITY_LIMIT, PARALLEL, TIERS, REPO, AREA, LANGUAGE, MISSING, brainName, Kioku;
|
|
6488
|
+
var init_kioku = __esm({
|
|
6489
|
+
"../core/dist/kioku.js"() {
|
|
6474
6490
|
"use strict";
|
|
6475
|
-
|
|
6476
|
-
|
|
6477
|
-
|
|
6478
|
-
|
|
6479
|
-
|
|
6480
|
-
|
|
6481
|
-
|
|
6482
|
-
|
|
6483
|
-
|
|
6484
|
-
|
|
6485
|
-
|
|
6486
|
-
|
|
6487
|
-
|
|
6488
|
-
|
|
6489
|
-
|
|
6490
|
-
|
|
6491
|
-
|
|
6491
|
+
init_task_review();
|
|
6492
|
+
init_cw_doctor();
|
|
6493
|
+
init_cw_install();
|
|
6494
|
+
init_output();
|
|
6495
|
+
init_kioku_versions();
|
|
6496
|
+
PAGE_TYPES = {
|
|
6497
|
+
memory: { kind: "memory" },
|
|
6498
|
+
instinct: { kind: "memory", sub: "instinct" },
|
|
6499
|
+
decision: { kind: "knowledge", sub: "decision" },
|
|
6500
|
+
playbook: { kind: "knowledge", sub: "playbook" },
|
|
6501
|
+
context: { kind: "knowledge", sub: "context" },
|
|
6502
|
+
rule: { kind: "rule" }
|
|
6503
|
+
};
|
|
6504
|
+
KiokuError = class extends Error {
|
|
6505
|
+
status;
|
|
6506
|
+
constructor(message2, status = 502) {
|
|
6507
|
+
super(message2);
|
|
6508
|
+
this.status = status;
|
|
6509
|
+
}
|
|
6510
|
+
};
|
|
6511
|
+
NOT_INSTALLED = "kioku is not installed on this machine";
|
|
6512
|
+
START_TIMEOUT_MS = 2e4;
|
|
6513
|
+
WRITE_TIMEOUT_MS = 6e4;
|
|
6514
|
+
TERMINAL_TIMEOUT_MS = 3 * 6e4;
|
|
6515
|
+
CACHE_MS2 = 5 * 6e4;
|
|
6516
|
+
RELEASES_CACHE_MS = 10 * 6e4;
|
|
6517
|
+
SHOWN_BIN = "kioku";
|
|
6518
|
+
ACTIVITY_SINCE = "2w";
|
|
6519
|
+
ACTIVITY_LIMIT = 40;
|
|
6520
|
+
PARALLEL = 6;
|
|
6521
|
+
TIERS = ["personal", "project", "team"];
|
|
6522
|
+
REPO = /^[\w.-]+\/[\w.-]+(\/[\w.-]+)?$/;
|
|
6523
|
+
AREA = /^[A-Za-z0-9][\w.-]*(\/[A-Za-z0-9][\w.-]*)*$/;
|
|
6524
|
+
LANGUAGE = /^[A-Za-z]{2,3}(-[A-Za-z0-9]+)*$/;
|
|
6525
|
+
MISSING = { installed: false, version: null, brains: [], projects: {}, activity: [] };
|
|
6526
|
+
brainName = (b) => b.name ?? b.key;
|
|
6527
|
+
Kioku = class {
|
|
6528
|
+
run;
|
|
6529
|
+
write;
|
|
6530
|
+
terminal;
|
|
6531
|
+
startTimeoutMs;
|
|
6532
|
+
projects;
|
|
6533
|
+
pluginInstalls;
|
|
6534
|
+
now;
|
|
6535
|
+
binPath;
|
|
6536
|
+
viewer = null;
|
|
6537
|
+
snapshot = null;
|
|
6538
|
+
releaseList = null;
|
|
6539
|
+
constructor(options = {}) {
|
|
6540
|
+
this.binPath = options.bin;
|
|
6541
|
+
this.run = options.run ?? createRunner();
|
|
6542
|
+
this.write = options.write ?? createRunner(envWithoutHost(), WRITE_TIMEOUT_MS);
|
|
6543
|
+
this.terminal = options.terminal;
|
|
6544
|
+
this.startTimeoutMs = options.startTimeoutMs ?? START_TIMEOUT_MS;
|
|
6545
|
+
this.projects = options.projects ?? (() => ({}));
|
|
6546
|
+
this.pluginInstalls = options.pluginInstalls ?? (() => []);
|
|
6547
|
+
this.now = options.now ?? Date.now;
|
|
6548
|
+
}
|
|
6549
|
+
// resolved on first use, so a Forge that never opens Memory does not search PATH
|
|
6550
|
+
get bin() {
|
|
6551
|
+
return this.binPath ??= resolveKiokuBin();
|
|
6552
|
+
}
|
|
6553
|
+
async status(fresh = false) {
|
|
6554
|
+
const previous = this.snapshot;
|
|
6555
|
+
if (fresh || !previous || this.now() - previous.at > CACHE_MS2) {
|
|
6556
|
+
const value = this.read();
|
|
6557
|
+
this.snapshot = { at: this.now(), value };
|
|
6558
|
+
value.catch(() => {
|
|
6559
|
+
if (this.snapshot?.value === value)
|
|
6560
|
+
this.snapshot = previous;
|
|
6561
|
+
});
|
|
6562
|
+
}
|
|
6563
|
+
const pending = fresh || !previous ? this.snapshot.value : previous.value;
|
|
6564
|
+
const [snapshot, viewer] = await Promise.all([pending, this.viewer?.catch(() => null) ?? null]);
|
|
6565
|
+
return { ...snapshot, viewer: viewer?.address ?? null };
|
|
6566
|
+
}
|
|
6567
|
+
async json(args, cwd) {
|
|
6568
|
+
const result2 = await this.run(this.bin, [...args, "--json"], cwd);
|
|
6569
|
+
return result2.code === 0 ? parseJson(result2.stdout) : null;
|
|
6570
|
+
}
|
|
6571
|
+
async read() {
|
|
6572
|
+
const [version, list] = await Promise.all([
|
|
6573
|
+
this.run(this.bin, ["--version"], homedir5()),
|
|
6574
|
+
this.json(["brain", "list"], homedir5())
|
|
6575
|
+
]);
|
|
6576
|
+
if (version.code !== 0)
|
|
6577
|
+
return MISSING;
|
|
6578
|
+
const listed = list?.brains ?? [];
|
|
6579
|
+
const entries = Object.entries(this.projects()).filter(([, p]) => existsSync12(p.path));
|
|
6580
|
+
const readBrain = async (b) => {
|
|
6581
|
+
if (!b.onDisk)
|
|
6582
|
+
return { kinds: {}, namespaces: [], writes: [] };
|
|
6583
|
+
const [ns, log] = await Promise.all([
|
|
6584
|
+
this.json(["namespace", "list", "--brain", b.key], b.folder),
|
|
6585
|
+
this.json(["brain", "log", "--since", ACTIVITY_SINCE, "--brain", b.key], b.folder)
|
|
6586
|
+
]);
|
|
6587
|
+
const kinds = {};
|
|
6588
|
+
const namespaces = ns?.brains?.find((x) => x.brain === brainName(b))?.namespaces ?? [];
|
|
6589
|
+
for (const n of namespaces) {
|
|
6590
|
+
for (const [kind, count] of Object.entries(n.pages))
|
|
6591
|
+
kinds[kind] = (kinds[kind] ?? 0) + count;
|
|
6492
6592
|
}
|
|
6493
|
-
|
|
6494
|
-
|
|
6593
|
+
return { kinds, namespaces: namespaces.map((n) => n.namespace), writes: log?.writes ?? [] };
|
|
6594
|
+
};
|
|
6595
|
+
const readChain = async (path) => (await this.json(["brain", "list"], path))?.chain ?? [];
|
|
6596
|
+
const [perBrain, chains] = await Promise.all([
|
|
6597
|
+
mapLimit(listed, PARALLEL / 2, readBrain),
|
|
6598
|
+
mapLimit(entries, PARALLEL / 2, ([, p]) => readChain(p.path))
|
|
6599
|
+
]);
|
|
6600
|
+
const activity = perBrain.flatMap((p) => p.writes).sort((x, y) => y.date.localeCompare(x.date));
|
|
6601
|
+
const brains = listed.map((b, i) => {
|
|
6602
|
+
const { kinds, namespaces } = perBrain[i];
|
|
6603
|
+
const name = brainName(b);
|
|
6604
|
+
return {
|
|
6605
|
+
...b,
|
|
6606
|
+
pages: Object.values(kinds).reduce((sum, n) => sum + n, 0),
|
|
6607
|
+
kinds,
|
|
6608
|
+
namespaces,
|
|
6609
|
+
touched: activity.find((w) => w.brain === name)?.date ?? null
|
|
6610
|
+
};
|
|
6611
|
+
});
|
|
6612
|
+
const projects = Object.fromEntries(entries.map(([name], i) => [name, chains[i].map(({ name: name2, tier }) => ({ name: name2, tier }))]));
|
|
6613
|
+
return {
|
|
6614
|
+
installed: true,
|
|
6615
|
+
version: parseJson(version.stdout)?.version ?? null,
|
|
6616
|
+
brains,
|
|
6617
|
+
projects,
|
|
6618
|
+
activity: activity.slice(0, ACTIVITY_LIMIT).map(({ verb, title, path, date, author, brain }) => ({ verb, title, path, date, author, brain }))
|
|
6619
|
+
};
|
|
6620
|
+
}
|
|
6621
|
+
// writes through kioku, which validates, commits and pushes a shared brain; Forge never writes a brain's files
|
|
6622
|
+
async save(input) {
|
|
6623
|
+
const type = PAGE_TYPES[input.type];
|
|
6624
|
+
if (!type)
|
|
6625
|
+
throw new KiokuError(`unknown page type ${input.type}`, 400);
|
|
6626
|
+
const brain = await this.findBrain(input.brain);
|
|
6627
|
+
const args = [
|
|
6628
|
+
"page",
|
|
6629
|
+
"save",
|
|
6630
|
+
"--brain",
|
|
6631
|
+
brain.key,
|
|
6632
|
+
"--kind",
|
|
6633
|
+
type.kind,
|
|
6634
|
+
...type.sub ? ["--sub", type.sub] : [],
|
|
6635
|
+
"--title",
|
|
6636
|
+
input.title,
|
|
6637
|
+
"--summary",
|
|
6638
|
+
input.summary,
|
|
6639
|
+
"--source",
|
|
6640
|
+
"Forge",
|
|
6641
|
+
...input.namespace ? ["--namespace", input.namespace] : [],
|
|
6642
|
+
...input.create ? ["--create"] : [],
|
|
6643
|
+
"--json"
|
|
6644
|
+
];
|
|
6645
|
+
const { out, fail } = await this.invoke(args, brain.folder, this.write, input.body);
|
|
6646
|
+
if (out?.status === "done" && out.path) {
|
|
6647
|
+
this.expire();
|
|
6648
|
+
return { status: "done", brain: brainName(brain), path: out.path, publication: out.publication ?? null };
|
|
6495
6649
|
}
|
|
6650
|
+
if (out?.status === "similar")
|
|
6651
|
+
return { status: "similar", similar: (out.similar ?? []).map(({ brain: brain2, path, title, summary }) => ({ brain: brain2, path, title, summary })) };
|
|
6652
|
+
if (out?.status === "namespace")
|
|
6653
|
+
return { status: "namespace", namespaces: (out.namespaces ?? []).map(({ namespace, summary }) => ({ namespace, summary })) };
|
|
6654
|
+
throw fail("kioku could not save the page");
|
|
6496
6655
|
}
|
|
6497
|
-
|
|
6498
|
-
|
|
6656
|
+
// the cached reading when there is one, else only the list of brains
|
|
6657
|
+
async listBrains() {
|
|
6658
|
+
return this.snapshot ? (await this.snapshot.value).brains : (await this.json(["brain", "list"], homedir5()))?.brains ?? [];
|
|
6499
6659
|
}
|
|
6500
|
-
|
|
6501
|
-
|
|
6502
|
-
if (
|
|
6503
|
-
|
|
6504
|
-
|
|
6505
|
-
ranges.push("*");
|
|
6506
|
-
} else if (!max) {
|
|
6507
|
-
ranges.push(`>=${min}`);
|
|
6508
|
-
} else if (min === v[0]) {
|
|
6509
|
-
ranges.push(`<=${max}`);
|
|
6510
|
-
} else {
|
|
6511
|
-
ranges.push(`${min} - ${max}`);
|
|
6512
|
-
}
|
|
6660
|
+
async findBrain(key) {
|
|
6661
|
+
const brain = (await this.listBrains()).find((b) => b.key === key);
|
|
6662
|
+
if (!brain?.onDisk)
|
|
6663
|
+
throw new KiokuError(`no brain ${key} on this machine`, 404);
|
|
6664
|
+
return brain;
|
|
6513
6665
|
}
|
|
6514
|
-
|
|
6515
|
-
|
|
6516
|
-
|
|
6517
|
-
|
|
6518
|
-
}
|
|
6519
|
-
});
|
|
6520
|
-
|
|
6521
|
-
// ../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/ranges/subset.js
|
|
6522
|
-
var require_subset = __commonJS({
|
|
6523
|
-
"../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/ranges/subset.js"(exports, module) {
|
|
6524
|
-
"use strict";
|
|
6525
|
-
var Range = require_range();
|
|
6526
|
-
var Comparator = require_comparator();
|
|
6527
|
-
var { ANY } = Comparator;
|
|
6528
|
-
var satisfies = require_satisfies();
|
|
6529
|
-
var compare = require_compare();
|
|
6530
|
-
var subset = (sub, dom, options = {}) => {
|
|
6531
|
-
if (sub === dom) {
|
|
6532
|
-
return true;
|
|
6666
|
+
// the next status reads again, while the old reading still answers a poll that is not fresh
|
|
6667
|
+
expire() {
|
|
6668
|
+
if (this.snapshot)
|
|
6669
|
+
this.snapshot.at = -Infinity;
|
|
6533
6670
|
}
|
|
6534
|
-
|
|
6535
|
-
|
|
6536
|
-
|
|
6537
|
-
|
|
6538
|
-
|
|
6539
|
-
|
|
6540
|
-
|
|
6541
|
-
if (isSub) {
|
|
6542
|
-
continue OUTER;
|
|
6543
|
-
}
|
|
6544
|
-
}
|
|
6545
|
-
if (sawNonNull) {
|
|
6546
|
-
return false;
|
|
6547
|
-
}
|
|
6671
|
+
// runs a verb that writes; fail turns kioku's refusal into a 400 with its message
|
|
6672
|
+
async invoke(args, cwd, run2, input) {
|
|
6673
|
+
const result2 = await run2(this.bin, args, cwd, input);
|
|
6674
|
+
if (result2.code === 127)
|
|
6675
|
+
throw new KiokuError(NOT_INSTALLED, 404);
|
|
6676
|
+
const out = parseJson(result2.stdout);
|
|
6677
|
+
return { out, ok: result2.code === 0 && out !== null && !out.error, fail: (fallback) => new KiokuError(out?.error?.message ?? (tailOutput(result2.stderr, 1) || fallback), 400) };
|
|
6548
6678
|
}
|
|
6549
|
-
|
|
6550
|
-
|
|
6551
|
-
|
|
6552
|
-
|
|
6553
|
-
|
|
6554
|
-
|
|
6555
|
-
return true;
|
|
6679
|
+
async change(args, cwd, run2 = this.write) {
|
|
6680
|
+
const { out, ok, fail } = await this.invoke([...args, "--json"], cwd, run2);
|
|
6681
|
+
if (!ok || !out)
|
|
6682
|
+
throw fail(`kioku ${args.slice(0, 2).join(" ")} failed`);
|
|
6683
|
+
this.expire();
|
|
6684
|
+
return out;
|
|
6556
6685
|
}
|
|
6557
|
-
|
|
6558
|
-
|
|
6559
|
-
|
|
6560
|
-
|
|
6561
|
-
|
|
6562
|
-
|
|
6563
|
-
|
|
6564
|
-
|
|
6686
|
+
// makes a brain on this machine only; kioku never makes a repository here
|
|
6687
|
+
async createBrain(input) {
|
|
6688
|
+
assertRepo(input.repo, "the brain");
|
|
6689
|
+
if (!TIERS.includes(input.tier))
|
|
6690
|
+
throw new KiokuError(`the tier is one of ${TIERS.join(", ")}`, 400);
|
|
6691
|
+
if (input.team)
|
|
6692
|
+
assertRepo(input.team, "the team brain");
|
|
6693
|
+
if (input.language && !LANGUAGE.test(input.language))
|
|
6694
|
+
throw new KiokuError("the language is a tag such as en or es", 400);
|
|
6695
|
+
const args = [
|
|
6696
|
+
"brain",
|
|
6697
|
+
"create",
|
|
6698
|
+
input.repo,
|
|
6699
|
+
"--tier",
|
|
6700
|
+
input.tier,
|
|
6701
|
+
...input.team && input.tier === "project" ? ["--team", input.team] : [],
|
|
6702
|
+
...input.language ? ["--language", input.language] : []
|
|
6703
|
+
];
|
|
6704
|
+
const { brain, name, path } = await this.change(args, homedir5());
|
|
6705
|
+
return { brain, name, path };
|
|
6565
6706
|
}
|
|
6566
|
-
|
|
6567
|
-
if (
|
|
6568
|
-
|
|
6569
|
-
|
|
6570
|
-
|
|
6571
|
-
|
|
6707
|
+
async addArea(key, area, summary) {
|
|
6708
|
+
if (!AREA.test(area))
|
|
6709
|
+
throw new KiokuError("an area is letters, digits, dots, dashes and underscores, with / between parts", 400);
|
|
6710
|
+
if (!summary)
|
|
6711
|
+
throw new KiokuError("say what the area is for", 400);
|
|
6712
|
+
const brain = await this.findBrain(key);
|
|
6713
|
+
const out = await this.change(["namespace", "add", area, `--summary=${summary}`, "--brain", brain.key], brain.folder);
|
|
6714
|
+
return { brain: out.brain, namespace: out.namespace };
|
|
6572
6715
|
}
|
|
6573
|
-
|
|
6574
|
-
|
|
6575
|
-
|
|
6576
|
-
|
|
6577
|
-
|
|
6578
|
-
|
|
6579
|
-
|
|
6580
|
-
|
|
6581
|
-
|
|
6582
|
-
|
|
6716
|
+
// writes the project's kioku.yaml; a brain the machine does not know is made first, since kioku links only known brains without a terminal
|
|
6717
|
+
async linkProject(input) {
|
|
6718
|
+
if (!input.brain && !input.team)
|
|
6719
|
+
throw new KiokuError("name a project brain, a team brain, or both", 400);
|
|
6720
|
+
const path = this.projects()[input.project]?.path;
|
|
6721
|
+
if (!path || !existsSync12(path))
|
|
6722
|
+
throw new KiokuError(`no CW project ${input.project} on this machine`, 404);
|
|
6723
|
+
if (input.brain)
|
|
6724
|
+
assertRepo(input.brain, "the project brain");
|
|
6725
|
+
if (input.team)
|
|
6726
|
+
assertRepo(input.team, "the team brain");
|
|
6727
|
+
const known = await this.listBrains();
|
|
6728
|
+
const isKnown = (repo) => known.some((b) => b.key === repo || b.key.endsWith(`/${repo}`));
|
|
6729
|
+
const created = [];
|
|
6730
|
+
if (input.team && !isKnown(input.team))
|
|
6731
|
+
created.push((await this.createBrain({ repo: input.team, tier: "team" })).brain);
|
|
6732
|
+
if (input.brain && !isKnown(input.brain))
|
|
6733
|
+
created.push((await this.createBrain({ repo: input.brain, tier: "project", team: input.team })).brain);
|
|
6734
|
+
const args = ["init", ...input.brain ? [input.brain] : [], ...input.team ? ["--team", input.team] : []];
|
|
6735
|
+
const { file } = await this.change(args, path);
|
|
6736
|
+
return { file, created };
|
|
6583
6737
|
}
|
|
6584
|
-
|
|
6585
|
-
|
|
6738
|
+
// the only verb that reaches a git host: without `to`, kioku makes a private GitHub repository with gh
|
|
6739
|
+
async publish(key, to) {
|
|
6740
|
+
if (to?.startsWith("-"))
|
|
6741
|
+
throw new KiokuError("the address cannot start with -", 400);
|
|
6742
|
+
const brain = await this.findBrain(key);
|
|
6743
|
+
if (brain.remote)
|
|
6744
|
+
throw new KiokuError(`${brainName(brain)} already has a repository: ${brain.remote}`, 400);
|
|
6745
|
+
const out = await this.change(["brain", "publish", brain.key, ...to ? ["--to", to] : []], brain.folder, this.terminalRun);
|
|
6746
|
+
return { brain: out.brain, status: out.status, remote: out.remote ?? null };
|
|
6586
6747
|
}
|
|
6587
|
-
|
|
6588
|
-
|
|
6589
|
-
gtltComp = compare(gt.semver, lt.semver, options);
|
|
6590
|
-
if (gtltComp > 0) {
|
|
6591
|
-
return null;
|
|
6592
|
-
} else if (gtltComp === 0 && (gt.operator !== ">=" || lt.operator !== "<=")) {
|
|
6593
|
-
return null;
|
|
6594
|
-
}
|
|
6748
|
+
get terminalRun() {
|
|
6749
|
+
return this.terminal ??= createTerminalRunner(envWithoutHost(), TERMINAL_TIMEOUT_MS);
|
|
6595
6750
|
}
|
|
6596
|
-
|
|
6597
|
-
|
|
6598
|
-
|
|
6599
|
-
|
|
6600
|
-
|
|
6601
|
-
|
|
6602
|
-
|
|
6603
|
-
|
|
6604
|
-
|
|
6605
|
-
|
|
6606
|
-
|
|
6751
|
+
// kioku has no verb that lists releases and its repository is private, so gh reads them; a failed read keeps the last list
|
|
6752
|
+
async releases(fresh = false) {
|
|
6753
|
+
const cached = this.releaseList;
|
|
6754
|
+
const [status, listed] = await Promise.all([
|
|
6755
|
+
// the installed version comes from the status reading, which an update renews
|
|
6756
|
+
this.status(),
|
|
6757
|
+
!fresh && cached && this.now() - cached.at <= RELEASES_CACHE_MS ? null : this.run("gh", RELEASES_ARGS, homedir5())
|
|
6758
|
+
]);
|
|
6759
|
+
let error = null;
|
|
6760
|
+
if (listed) {
|
|
6761
|
+
const raw = listed.code === 0 ? parseJson(listed.stdout) : null;
|
|
6762
|
+
if (Array.isArray(raw))
|
|
6763
|
+
this.releaseList = { at: this.now(), raw };
|
|
6764
|
+
else
|
|
6765
|
+
error = listed.code === 127 ? "gh is not installed, and the releases of monoku/kioku are read with it" : tailOutput(listed.stderr, 1) || "gh could not read the releases of monoku/kioku";
|
|
6607
6766
|
}
|
|
6608
|
-
return
|
|
6767
|
+
return { ...pickReleases(this.releaseList?.raw ?? [], status.version, this.pluginInstalls(), SHOWN_BIN), command: commandLine("gh", RELEASES_ARGS), error };
|
|
6609
6768
|
}
|
|
6610
|
-
|
|
6611
|
-
|
|
6612
|
-
|
|
6613
|
-
|
|
6614
|
-
|
|
6615
|
-
|
|
6769
|
+
// only looks: kioku answers whether it would install, without a terminal
|
|
6770
|
+
async checkUpdate(version) {
|
|
6771
|
+
assertVersion(version);
|
|
6772
|
+
const args = updateArgs(version, true);
|
|
6773
|
+
const { out, ok, fail } = await this.invoke([...args, "--json"], homedir5(), this.run);
|
|
6774
|
+
if (!ok || !out)
|
|
6775
|
+
throw fail(`kioku update ${version} --check failed`);
|
|
6776
|
+
return { ...readUpdate(out, commandLine(SHOWN_BIN, args)), install: commandLine(SHOWN_BIN, updateArgs(version)) };
|
|
6777
|
+
}
|
|
6778
|
+
// kioku installs a named version only for a person at a terminal
|
|
6779
|
+
async update(version) {
|
|
6780
|
+
assertVersion(version);
|
|
6781
|
+
const args = updateArgs(version);
|
|
6782
|
+
const { out, ok, fail } = await this.invoke([...args, "--json"], homedir5(), this.terminalRun);
|
|
6783
|
+
if (!ok || !out)
|
|
6784
|
+
throw fail(`kioku update ${version} failed`);
|
|
6785
|
+
this.status(true).catch(() => {
|
|
6786
|
+
});
|
|
6787
|
+
return readUpdate(out, commandLine(SHOWN_BIN, args));
|
|
6616
6788
|
}
|
|
6617
|
-
|
|
6618
|
-
|
|
6619
|
-
|
|
6620
|
-
if (
|
|
6621
|
-
|
|
6622
|
-
|
|
6623
|
-
|
|
6624
|
-
|
|
6625
|
-
|
|
6626
|
-
|
|
6627
|
-
|
|
6628
|
-
|
|
6629
|
-
|
|
6630
|
-
|
|
6631
|
-
|
|
6632
|
-
|
|
6633
|
-
}
|
|
6634
|
-
}
|
|
6635
|
-
if (lt) {
|
|
6636
|
-
if (needDomLTPre) {
|
|
6637
|
-
if (c.semver.prerelease && c.semver.prerelease.length && c.semver.major === needDomLTPre.major && c.semver.minor === needDomLTPre.minor && c.semver.patch === needDomLTPre.patch) {
|
|
6638
|
-
needDomLTPre = false;
|
|
6639
|
-
}
|
|
6640
|
-
}
|
|
6641
|
-
if (c.operator === "<" || c.operator === "<=") {
|
|
6642
|
-
lower = lowerLT(lt, c, options);
|
|
6643
|
-
if (lower === c && lower !== lt) {
|
|
6644
|
-
return false;
|
|
6645
|
-
}
|
|
6646
|
-
} else if (lt.operator === "<=" && !c.test(lt.semver)) {
|
|
6647
|
-
return false;
|
|
6648
|
-
}
|
|
6649
|
-
}
|
|
6650
|
-
if (!c.operator && (lt || gt) && gtltComp !== 0) {
|
|
6651
|
-
return false;
|
|
6652
|
-
}
|
|
6789
|
+
// each version brings its own labs; a kioku without the verb has none
|
|
6790
|
+
async labs() {
|
|
6791
|
+
const result2 = await this.run(this.bin, [...LABS_ARGS, "--json"], homedir5());
|
|
6792
|
+
if (result2.code === 127)
|
|
6793
|
+
throw new KiokuError(NOT_INSTALLED, 404);
|
|
6794
|
+
const out = result2.code === 0 ? parseJson(result2.stdout) : null;
|
|
6795
|
+
return { labs: out ? readLabs(out, SHOWN_BIN) : null, command: commandLine(SHOWN_BIN, LABS_ARGS) };
|
|
6796
|
+
}
|
|
6797
|
+
// only a lab the installed kioku lists, so no other key reaches config set
|
|
6798
|
+
async setLab(name, enabled) {
|
|
6799
|
+
if (!(await this.labs()).labs?.some((l) => l.name === name))
|
|
6800
|
+
throw new KiokuError(`this kioku has no lab ${name}`, 404);
|
|
6801
|
+
const { ok, fail } = await this.invoke([...labArgs(name, enabled), "--json"], homedir5(), this.terminalRun);
|
|
6802
|
+
if (!ok)
|
|
6803
|
+
throw fail(`kioku config set labs.${name}.enabled failed`);
|
|
6804
|
+
return this.labs();
|
|
6653
6805
|
}
|
|
6654
|
-
|
|
6655
|
-
|
|
6806
|
+
// one viewer at a time; a second call reuses the running one
|
|
6807
|
+
async openViewer() {
|
|
6808
|
+
this.viewer ??= this.startViewer();
|
|
6809
|
+
return (await this.viewer).address;
|
|
6656
6810
|
}
|
|
6657
|
-
|
|
6658
|
-
|
|
6811
|
+
startViewer() {
|
|
6812
|
+
const started = new Promise((resolve10, reject) => {
|
|
6813
|
+
const child = spawn7(this.bin, ["web", "--json", "--no-open"], { cwd: homedir5(), stdio: ["ignore", "pipe", "pipe"] });
|
|
6814
|
+
const lines2 = createInterface({ input: child.stdout });
|
|
6815
|
+
let stderr = "";
|
|
6816
|
+
let settled = false;
|
|
6817
|
+
const finish = () => {
|
|
6818
|
+
settled = true;
|
|
6819
|
+
clearTimeout(timer);
|
|
6820
|
+
lines2.close();
|
|
6821
|
+
child.stdout?.resume();
|
|
6822
|
+
};
|
|
6823
|
+
const fail = (err) => {
|
|
6824
|
+
if (settled)
|
|
6825
|
+
return;
|
|
6826
|
+
finish();
|
|
6827
|
+
child.kill();
|
|
6828
|
+
reject(err);
|
|
6829
|
+
};
|
|
6830
|
+
const timer = setTimeout(() => fail(new KiokuError("kioku web did not start in time")), this.startTimeoutMs);
|
|
6831
|
+
child.stderr?.on("data", (chunk) => {
|
|
6832
|
+
stderr = (stderr + chunk.toString()).slice(-4096);
|
|
6833
|
+
});
|
|
6834
|
+
lines2.on("line", (line) => {
|
|
6835
|
+
const event = parseJson(line);
|
|
6836
|
+
if (settled || event?.event !== "listening" || !event.address?.startsWith("http://127.0.0.1:"))
|
|
6837
|
+
return;
|
|
6838
|
+
finish();
|
|
6839
|
+
resolve10({ child, address: event.address });
|
|
6840
|
+
});
|
|
6841
|
+
child.on("error", (err) => {
|
|
6842
|
+
const missing = err.code === "ENOENT";
|
|
6843
|
+
fail(new KiokuError(missing ? NOT_INSTALLED : err.message, missing ? 404 : 502));
|
|
6844
|
+
});
|
|
6845
|
+
child.on("close", (code) => {
|
|
6846
|
+
if (this.viewer === started)
|
|
6847
|
+
this.viewer = null;
|
|
6848
|
+
fail(new KiokuError(tailOutput(stderr, 1) || `kioku web exited with code ${code}`));
|
|
6849
|
+
});
|
|
6850
|
+
});
|
|
6851
|
+
started.catch(() => {
|
|
6852
|
+
if (this.viewer === started)
|
|
6853
|
+
this.viewer = null;
|
|
6854
|
+
});
|
|
6855
|
+
return started;
|
|
6659
6856
|
}
|
|
6660
|
-
|
|
6661
|
-
|
|
6857
|
+
stopViewer() {
|
|
6858
|
+
void this.viewer?.then((v) => v.child.kill(), () => {
|
|
6859
|
+
});
|
|
6860
|
+
this.viewer = null;
|
|
6662
6861
|
}
|
|
6663
|
-
|
|
6664
|
-
|
|
6665
|
-
var higherGT = (a, b, options) => {
|
|
6666
|
-
if (!a) {
|
|
6667
|
-
return b;
|
|
6862
|
+
dispose() {
|
|
6863
|
+
this.stopViewer();
|
|
6668
6864
|
}
|
|
6669
|
-
const comp = compare(a.semver, b.semver, options);
|
|
6670
|
-
return comp > 0 ? a : comp < 0 ? b : b.operator === ">" && a.operator === ">=" ? b : a;
|
|
6671
6865
|
};
|
|
6672
|
-
|
|
6673
|
-
|
|
6674
|
-
|
|
6866
|
+
}
|
|
6867
|
+
});
|
|
6868
|
+
|
|
6869
|
+
// ../core/dist/kioku-routes.js
|
|
6870
|
+
import { Hono as Hono4 } from "hono";
|
|
6871
|
+
function kiokuRoutes(kioku = new Kioku(), options = {}) {
|
|
6872
|
+
const app = new Hono4();
|
|
6873
|
+
app.onError((err, c) => {
|
|
6874
|
+
if (err instanceof KiokuError)
|
|
6875
|
+
return c.json({ error: err.message }, err.status);
|
|
6876
|
+
throw err;
|
|
6877
|
+
});
|
|
6878
|
+
app.get("/status", async (c) => c.json(await kioku.status(c.req.query("fresh") === "1")));
|
|
6879
|
+
app.post("/pages", async (c) => {
|
|
6880
|
+
const input = await c.req.json().catch(() => ({}));
|
|
6881
|
+
const brain = input.brain?.trim();
|
|
6882
|
+
const title = input.title?.trim();
|
|
6883
|
+
const summary = input.summary?.trim();
|
|
6884
|
+
if (!brain || !input.type || !title || !summary || !input.body?.trim())
|
|
6885
|
+
return c.json({ error: "brain, type, title, summary and body are required" }, 400);
|
|
6886
|
+
const result2 = await kioku.save({ brain, type: input.type, title, summary, body: input.body, namespace: input.namespace?.trim() || void 0, create: input.create === true });
|
|
6887
|
+
return c.json(result2, result2.status === "done" ? 201 : 200);
|
|
6888
|
+
});
|
|
6889
|
+
app.post("/brains", async (c) => {
|
|
6890
|
+
const { repo, tier, team, language } = await body(c);
|
|
6891
|
+
return c.json(await kioku.createBrain({ repo: trim(repo) ?? "", tier: tier ?? "", team: trim(team), language: trim(language) }), 201);
|
|
6892
|
+
});
|
|
6893
|
+
app.post("/areas", async (c) => {
|
|
6894
|
+
const { brain, area, summary } = await body(c);
|
|
6895
|
+
return c.json(await kioku.addArea(brain ?? "", trim(area) ?? "", trim(summary) ?? ""), 201);
|
|
6896
|
+
});
|
|
6897
|
+
app.post("/link", async (c) => {
|
|
6898
|
+
const { project, brain, team } = await body(c);
|
|
6899
|
+
return c.json(await kioku.linkProject({ project: project ?? "", brain: trim(brain), team: trim(team) }));
|
|
6900
|
+
});
|
|
6901
|
+
app.post("/publish", async (c) => {
|
|
6902
|
+
const { brain, to, understood } = await body(c);
|
|
6903
|
+
if (understood !== true)
|
|
6904
|
+
return c.json({ error: "publishing needs the warning accepted" }, 400);
|
|
6905
|
+
return c.json(await kioku.publish(brain ?? "", trim(to)));
|
|
6906
|
+
});
|
|
6907
|
+
app.get("/releases", async (c) => c.json(await kioku.releases(c.req.query("fresh") === "1")));
|
|
6908
|
+
app.post("/update/check", async (c) => c.json(await kioku.checkUpdate(trim((await body(c)).version) ?? "")));
|
|
6909
|
+
app.post("/update", async (c) => c.json(await kioku.update(trim((await body(c)).version) ?? "")));
|
|
6910
|
+
app.get("/labs", async (c) => c.json(await kioku.labs()));
|
|
6911
|
+
app.post("/labs/:name", async (c) => {
|
|
6912
|
+
const { enabled } = await body(c);
|
|
6913
|
+
if (typeof enabled !== "boolean")
|
|
6914
|
+
return c.json({ error: "enabled is true or false" }, 400);
|
|
6915
|
+
return c.json(await kioku.setLab(c.req.param("name"), enabled));
|
|
6916
|
+
});
|
|
6917
|
+
app.post("/remember", async (c) => {
|
|
6918
|
+
const { project, sessionDir, text: text2 } = await c.req.json().catch(() => ({}));
|
|
6919
|
+
const line = text2?.trim();
|
|
6920
|
+
if (!project || !sessionDir || !line)
|
|
6921
|
+
return c.json({ error: "project, sessionDir and text are required" }, 400);
|
|
6922
|
+
if (line.length > REMEMBER_MAX)
|
|
6923
|
+
return c.json({ error: `keep it under ${REMEMBER_MAX} characters` }, 400);
|
|
6924
|
+
if (options.canRemember && !options.canRemember(project, sessionDir))
|
|
6925
|
+
return c.json({ error: "only Claude Code sessions have kioku's skill" }, 400);
|
|
6926
|
+
if (!options.type?.(project, sessionDir, rememberPrompt(line)))
|
|
6927
|
+
return c.json({ error: "the session has no live terminal" }, 409);
|
|
6928
|
+
return c.json({ ok: true });
|
|
6929
|
+
});
|
|
6930
|
+
app.post("/viewer", async (c) => c.json({ address: await kioku.openViewer() }));
|
|
6931
|
+
app.delete("/viewer", (c) => {
|
|
6932
|
+
kioku.stopViewer();
|
|
6933
|
+
return c.json({ ok: true });
|
|
6934
|
+
});
|
|
6935
|
+
return app;
|
|
6936
|
+
}
|
|
6937
|
+
var trim, REMEMBER_MAX, body;
|
|
6938
|
+
var init_kioku_routes = __esm({
|
|
6939
|
+
"../core/dist/kioku-routes.js"() {
|
|
6940
|
+
"use strict";
|
|
6941
|
+
init_kioku();
|
|
6942
|
+
trim = (value) => value?.trim() || void 0;
|
|
6943
|
+
REMEMBER_MAX = 500;
|
|
6944
|
+
body = (c) => c.req.json().catch(() => ({}));
|
|
6945
|
+
}
|
|
6946
|
+
});
|
|
6947
|
+
|
|
6948
|
+
// ../sdk/dist/define.js
|
|
6949
|
+
function isShellExecutor(run2) {
|
|
6950
|
+
return typeof run2 === "object" && run2 !== null && run2.kind === "shell";
|
|
6951
|
+
}
|
|
6952
|
+
var SDK_VERSION, MODULE_ID_RE;
|
|
6953
|
+
var init_define = __esm({
|
|
6954
|
+
"../sdk/dist/define.js"() {
|
|
6955
|
+
"use strict";
|
|
6956
|
+
SDK_VERSION = "1.0.0";
|
|
6957
|
+
MODULE_ID_RE = /^[a-z][a-z0-9-]{1,31}$/;
|
|
6958
|
+
}
|
|
6959
|
+
});
|
|
6960
|
+
|
|
6961
|
+
// ../sdk/dist/errors.js
|
|
6962
|
+
var PermissionError;
|
|
6963
|
+
var init_errors = __esm({
|
|
6964
|
+
"../sdk/dist/errors.js"() {
|
|
6965
|
+
"use strict";
|
|
6966
|
+
PermissionError = class extends Error {
|
|
6967
|
+
permission;
|
|
6968
|
+
value;
|
|
6969
|
+
constructor(permission, value) {
|
|
6970
|
+
super(`permission ${permission} does not cover ${value}`);
|
|
6971
|
+
this.name = "PermissionError";
|
|
6972
|
+
this.permission = permission;
|
|
6973
|
+
this.value = value;
|
|
6675
6974
|
}
|
|
6676
|
-
const comp = compare(a.semver, b.semver, options);
|
|
6677
|
-
return comp < 0 ? a : comp > 0 ? b : b.operator === "<" && a.operator === "<=" ? b : a;
|
|
6678
6975
|
};
|
|
6679
|
-
module.exports = subset;
|
|
6680
6976
|
}
|
|
6681
6977
|
});
|
|
6682
6978
|
|
|
6683
|
-
//
|
|
6684
|
-
var
|
|
6685
|
-
"
|
|
6979
|
+
// ../sdk/dist/index.js
|
|
6980
|
+
var init_dist = __esm({
|
|
6981
|
+
"../sdk/dist/index.js"() {
|
|
6686
6982
|
"use strict";
|
|
6687
|
-
|
|
6688
|
-
|
|
6689
|
-
var SemVer = require_semver();
|
|
6690
|
-
var identifiers = require_identifiers();
|
|
6691
|
-
var parse = require_parse();
|
|
6692
|
-
var valid = require_valid();
|
|
6693
|
-
var clean = require_clean();
|
|
6694
|
-
var inc = require_inc();
|
|
6695
|
-
var diff = require_diff();
|
|
6696
|
-
var major = require_major();
|
|
6697
|
-
var minor = require_minor();
|
|
6698
|
-
var patch = require_patch();
|
|
6699
|
-
var prerelease = require_prerelease();
|
|
6700
|
-
var compare = require_compare();
|
|
6701
|
-
var rcompare = require_rcompare();
|
|
6702
|
-
var compareLoose = require_compare_loose();
|
|
6703
|
-
var compareBuild = require_compare_build();
|
|
6704
|
-
var sort = require_sort();
|
|
6705
|
-
var rsort = require_rsort();
|
|
6706
|
-
var gt = require_gt();
|
|
6707
|
-
var lt = require_lt();
|
|
6708
|
-
var eq = require_eq();
|
|
6709
|
-
var neq = require_neq();
|
|
6710
|
-
var gte = require_gte();
|
|
6711
|
-
var lte = require_lte();
|
|
6712
|
-
var cmp = require_cmp();
|
|
6713
|
-
var coerce = require_coerce();
|
|
6714
|
-
var truncate = require_truncate();
|
|
6715
|
-
var Comparator = require_comparator();
|
|
6716
|
-
var Range = require_range();
|
|
6717
|
-
var satisfies = require_satisfies();
|
|
6718
|
-
var toComparators = require_to_comparators();
|
|
6719
|
-
var maxSatisfying = require_max_satisfying();
|
|
6720
|
-
var minSatisfying = require_min_satisfying();
|
|
6721
|
-
var minVersion = require_min_version();
|
|
6722
|
-
var validRange = require_valid2();
|
|
6723
|
-
var outside = require_outside();
|
|
6724
|
-
var gtr = require_gtr();
|
|
6725
|
-
var ltr = require_ltr();
|
|
6726
|
-
var intersects = require_intersects();
|
|
6727
|
-
var simplifyRange = require_simplify();
|
|
6728
|
-
var subset = require_subset();
|
|
6729
|
-
module.exports = {
|
|
6730
|
-
parse,
|
|
6731
|
-
valid,
|
|
6732
|
-
clean,
|
|
6733
|
-
inc,
|
|
6734
|
-
diff,
|
|
6735
|
-
major,
|
|
6736
|
-
minor,
|
|
6737
|
-
patch,
|
|
6738
|
-
prerelease,
|
|
6739
|
-
compare,
|
|
6740
|
-
rcompare,
|
|
6741
|
-
compareLoose,
|
|
6742
|
-
compareBuild,
|
|
6743
|
-
sort,
|
|
6744
|
-
rsort,
|
|
6745
|
-
gt,
|
|
6746
|
-
lt,
|
|
6747
|
-
eq,
|
|
6748
|
-
neq,
|
|
6749
|
-
gte,
|
|
6750
|
-
lte,
|
|
6751
|
-
cmp,
|
|
6752
|
-
coerce,
|
|
6753
|
-
truncate,
|
|
6754
|
-
Comparator,
|
|
6755
|
-
Range,
|
|
6756
|
-
satisfies,
|
|
6757
|
-
toComparators,
|
|
6758
|
-
maxSatisfying,
|
|
6759
|
-
minSatisfying,
|
|
6760
|
-
minVersion,
|
|
6761
|
-
validRange,
|
|
6762
|
-
outside,
|
|
6763
|
-
gtr,
|
|
6764
|
-
ltr,
|
|
6765
|
-
intersects,
|
|
6766
|
-
simplifyRange,
|
|
6767
|
-
subset,
|
|
6768
|
-
SemVer,
|
|
6769
|
-
re: internalRe.re,
|
|
6770
|
-
src: internalRe.src,
|
|
6771
|
-
tokens: internalRe.t,
|
|
6772
|
-
SEMVER_SPEC_VERSION: constants3.SEMVER_SPEC_VERSION,
|
|
6773
|
-
RELEASE_TYPES: constants3.RELEASE_TYPES,
|
|
6774
|
-
compareIdentifiers: identifiers.compareIdentifiers,
|
|
6775
|
-
rcompareIdentifiers: identifiers.rcompareIdentifiers
|
|
6776
|
-
};
|
|
6983
|
+
init_define();
|
|
6984
|
+
init_errors();
|
|
6777
6985
|
}
|
|
6778
6986
|
});
|
|
6779
6987
|
|
|
@@ -6810,7 +7018,7 @@ function expandOne(template, settings, kind) {
|
|
|
6810
7018
|
const out = [];
|
|
6811
7019
|
for (const item of items) {
|
|
6812
7020
|
let missing = false;
|
|
6813
|
-
const
|
|
7021
|
+
const text2 = template.replace(TEMPLATE_RE, (_all, key, isList, field, offset) => {
|
|
6814
7022
|
const v = isList ? item?.[field] : settings[key];
|
|
6815
7023
|
const s = typeof v === "string" ? v : typeof v === "number" && Number.isFinite(v) ? String(v) : "";
|
|
6816
7024
|
if (s && safeValue(s, kind, offset === 0))
|
|
@@ -6819,7 +7027,7 @@ function expandOne(template, settings, kind) {
|
|
|
6819
7027
|
return "";
|
|
6820
7028
|
});
|
|
6821
7029
|
if (!missing)
|
|
6822
|
-
out.push(
|
|
7030
|
+
out.push(text2);
|
|
6823
7031
|
}
|
|
6824
7032
|
return out;
|
|
6825
7033
|
}
|
|
@@ -6875,9 +7083,9 @@ var init_module_permissions = __esm({
|
|
|
6875
7083
|
import { readFileSync as readFileSync10 } from "node:fs";
|
|
6876
7084
|
import { join as join15, resolve as resolve5, sep as sep3 } from "node:path";
|
|
6877
7085
|
function checkSdk(range, version = SDK_VERSION) {
|
|
6878
|
-
if (!
|
|
7086
|
+
if (!import_semver2.default.validRange(range))
|
|
6879
7087
|
return `sdk range "${range}" is not valid semver`;
|
|
6880
|
-
return
|
|
7088
|
+
return import_semver2.default.satisfies(version, range) ? null : `needs SDK ${range}, Forge has ${version}`;
|
|
6881
7089
|
}
|
|
6882
7090
|
function checkManifest(raw, moduleDir) {
|
|
6883
7091
|
if (!isObject(raw))
|
|
@@ -6888,7 +7096,7 @@ function checkManifest(raw, moduleDir) {
|
|
|
6888
7096
|
return { kind: "legacy", manifest: raw };
|
|
6889
7097
|
}
|
|
6890
7098
|
const errors = [];
|
|
6891
|
-
const err = (path,
|
|
7099
|
+
const err = (path, message2) => errors.push(`${path}: ${message2}`);
|
|
6892
7100
|
for (const key of Object.keys(raw))
|
|
6893
7101
|
if (!TOP_LEVEL.has(key))
|
|
6894
7102
|
err(`/${key}`, "unknown field");
|
|
@@ -7026,8 +7234,8 @@ function scalar(def, raw, path, errors) {
|
|
|
7026
7234
|
errors.push({ path, message: "required" });
|
|
7027
7235
|
return void 0;
|
|
7028
7236
|
}
|
|
7029
|
-
const fail = (
|
|
7030
|
-
errors.push({ path, message });
|
|
7237
|
+
const fail = (message2) => {
|
|
7238
|
+
errors.push({ path, message: message2 });
|
|
7031
7239
|
return void 0;
|
|
7032
7240
|
};
|
|
7033
7241
|
switch (def.type) {
|
|
@@ -7051,11 +7259,11 @@ function scalar(def, raw, path, errors) {
|
|
|
7051
7259
|
return typeof v === "string" && def.values.includes(v) ? v : fail(`must be one of ${def.values.join(", ")}`);
|
|
7052
7260
|
}
|
|
7053
7261
|
}
|
|
7054
|
-
var
|
|
7262
|
+
var import_semver2, V1_FIELDS, TOP_LEVEL, PERMISSIONS, SCALAR_TYPES, FORMATS, isObject, isStringArray;
|
|
7055
7263
|
var init_module_manifest = __esm({
|
|
7056
7264
|
"../core/dist/module-manifest.js"() {
|
|
7057
7265
|
"use strict";
|
|
7058
|
-
|
|
7266
|
+
import_semver2 = __toESM(require_semver2(), 1);
|
|
7059
7267
|
init_dist();
|
|
7060
7268
|
init_module_permissions();
|
|
7061
7269
|
V1_FIELDS = ["server", "view", "permissions", "id"];
|
|
@@ -7216,8 +7424,8 @@ import { existsSync as existsSync13, readdirSync as readdirSync7, readFileSync a
|
|
|
7216
7424
|
import { basename as basename4, dirname as dirname7, join as join16, resolve as resolve6, sep as sep4 } from "node:path";
|
|
7217
7425
|
import { pathToFileURL } from "node:url";
|
|
7218
7426
|
function disabled(id, c, reason, m) {
|
|
7219
|
-
const
|
|
7220
|
-
return { id, name:
|
|
7427
|
+
const text2 = (v, fallback) => typeof v === "string" && v ? v : fallback;
|
|
7428
|
+
return { id, name: text2(m?.name, id), version: text2(m?.version, ""), displayName: text2(m?.displayName, id), source: c.source, state: "disabled", reason };
|
|
7221
7429
|
}
|
|
7222
7430
|
function packages(root, source, packaged) {
|
|
7223
7431
|
if (!existsSync13(root))
|
|
@@ -7679,8 +7887,8 @@ var init_module_install = __esm({
|
|
|
7679
7887
|
expand = (spec, cwd) => resolve7(cwd, expandHome(spec));
|
|
7680
7888
|
InstallError = class extends Error {
|
|
7681
7889
|
code;
|
|
7682
|
-
constructor(code,
|
|
7683
|
-
super(
|
|
7890
|
+
constructor(code, message2) {
|
|
7891
|
+
super(message2);
|
|
7684
7892
|
this.code = code;
|
|
7685
7893
|
}
|
|
7686
7894
|
};
|
|
@@ -8011,11 +8219,11 @@ async function run(found, confirmation, output, requestSignal) {
|
|
|
8011
8219
|
return action.run(input, ctx);
|
|
8012
8220
|
}
|
|
8013
8221
|
async function readJson3(c) {
|
|
8014
|
-
const
|
|
8015
|
-
if (!
|
|
8222
|
+
const text2 = await c.req.text();
|
|
8223
|
+
if (!text2)
|
|
8016
8224
|
return void 0;
|
|
8017
8225
|
try {
|
|
8018
|
-
return JSON.parse(
|
|
8226
|
+
return JSON.parse(text2);
|
|
8019
8227
|
} catch {
|
|
8020
8228
|
return void 0;
|
|
8021
8229
|
}
|
|
@@ -8027,10 +8235,10 @@ function describe(err) {
|
|
|
8027
8235
|
if (err instanceof PermissionError)
|
|
8028
8236
|
return { code: "permission", message: err.message, permission: err.permission, value: err.value };
|
|
8029
8237
|
const e = err;
|
|
8030
|
-
const
|
|
8238
|
+
const message2 = typeof e?.message === "string" ? e.message : String(err);
|
|
8031
8239
|
if (e?.name === "ModuleError" && typeof e.code === "string")
|
|
8032
|
-
return { code: e.code, message };
|
|
8033
|
-
return { code: "module_error", message };
|
|
8240
|
+
return { code: e.code, message: message2 };
|
|
8241
|
+
return { code: "module_error", message: message2 };
|
|
8034
8242
|
}
|
|
8035
8243
|
function errorResponse(c, mod, err) {
|
|
8036
8244
|
const body2 = describe(err);
|
|
@@ -8084,8 +8292,8 @@ var init_module_routes = __esm({
|
|
|
8084
8292
|
});
|
|
8085
8293
|
|
|
8086
8294
|
// ../core/dist/module-jobs.js
|
|
8087
|
-
function parseEvery(
|
|
8088
|
-
const m = /^(\d+)(s|m|h)$/.exec(
|
|
8295
|
+
function parseEvery(text2) {
|
|
8296
|
+
const m = /^(\d+)(s|m|h)$/.exec(text2.trim());
|
|
8089
8297
|
if (!m)
|
|
8090
8298
|
throw new Error("every must look like 30s, 2m or 1h");
|
|
8091
8299
|
const ms = Number(m[1]) * UNITS[m[2]];
|
|
@@ -8257,9 +8465,9 @@ function createForgeServer(options) {
|
|
|
8257
8465
|
const generalSessions = new GeneralSessions(join18(dataDir, "general-sessions.json"));
|
|
8258
8466
|
const terminalWss = createTerminalWss(ptyManager, cwReader, { localOnly, general: generalSessions });
|
|
8259
8467
|
app.route("/api/liveframe", liveframeRoutes());
|
|
8260
|
-
const kioku = new Kioku({ projects: () => cwReader.getProjects() });
|
|
8468
|
+
const kioku = new Kioku({ projects: () => cwReader.getProjects(), pluginInstalls: () => installsOf(cwReader, "kioku") });
|
|
8261
8469
|
app.route("/api/kioku", kiokuRoutes(kioku, {
|
|
8262
|
-
type: (project, sessionDir,
|
|
8470
|
+
type: (project, sessionDir, text2) => ptyManager.typeLine(project, sessionDir, text2),
|
|
8263
8471
|
// kioku's plugin, and so its skill, exists only for Claude Code
|
|
8264
8472
|
canRemember: (project, sessionDir) => cwReader.getSession(project, sessionDir)?.harness === "claude"
|
|
8265
8473
|
}));
|
|
@@ -8273,11 +8481,11 @@ function createForgeServer(options) {
|
|
|
8273
8481
|
}
|
|
8274
8482
|
});
|
|
8275
8483
|
const moduleEvents = new ModuleEvents({
|
|
8276
|
-
onError: (id,
|
|
8484
|
+
onError: (id, message2) => {
|
|
8277
8485
|
const status = moduleHost.get(id)?.status;
|
|
8278
8486
|
if (status)
|
|
8279
|
-
status.lastEventError =
|
|
8280
|
-
console.warn(`[module ${id}] ${
|
|
8487
|
+
status.lastEventError = message2;
|
|
8488
|
+
console.warn(`[module ${id}] ${message2}`);
|
|
8281
8489
|
}
|
|
8282
8490
|
});
|
|
8283
8491
|
const startModule = (mod) => {
|
|
@@ -8329,6 +8537,17 @@ function createForgeServer(options) {
|
|
|
8329
8537
|
generalSessions.forget(sessionId);
|
|
8330
8538
|
return c.json({ ok: true });
|
|
8331
8539
|
});
|
|
8540
|
+
app.post("/api/cw/terminal/command", async (c) => {
|
|
8541
|
+
const { project, sessionDir, line } = await c.req.json().catch(() => ({}));
|
|
8542
|
+
const command = slashLine(line);
|
|
8543
|
+
if (!project || !sessionDir || !command)
|
|
8544
|
+
return c.json({ error: "project, sessionDir and a slash command on one line are required" }, 400);
|
|
8545
|
+
if (cwReader.getSession(project, sessionDir)?.harness !== "claude")
|
|
8546
|
+
return c.json({ error: "only Claude Code sessions run plugin commands" }, 400);
|
|
8547
|
+
if (!ptyManager.typeLine(project, sessionDir, command))
|
|
8548
|
+
return c.json({ error: "the session has no live terminal" }, 409);
|
|
8549
|
+
return c.json({ ok: true });
|
|
8550
|
+
});
|
|
8332
8551
|
async function resolveAction(c) {
|
|
8333
8552
|
const moduleName = c.req.param("module");
|
|
8334
8553
|
const actionId = c.req.param("action");
|
|
@@ -8522,6 +8741,7 @@ var init_server = __esm({
|
|
|
8522
8741
|
init_module_jobs();
|
|
8523
8742
|
init_module_events();
|
|
8524
8743
|
init_kioku();
|
|
8744
|
+
init_plugins();
|
|
8525
8745
|
}
|
|
8526
8746
|
});
|
|
8527
8747
|
|