easel-canvas 0.1.1 → 0.2.1
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/README.md +103 -34
- package/bin/mcp.mjs +146 -40
- package/bin/server.mjs +67 -5
- package/dist/assets/index-BZFSkKqU.css +1 -0
- package/dist/assets/index-BwyrrnkP.js +65 -0
- package/dist/index.html +3 -3
- package/dist/viewer/viewer.css +1 -0
- package/dist/viewer/viewer.js +49 -0
- package/examples/demo/CLAUDE.md +8 -0
- package/examples/demo/assets/fonts/OFL-Anton.txt +93 -0
- package/examples/demo/assets/fonts/OFL-JetBrainsMono.txt +93 -0
- package/examples/demo/assets/fonts/anton-latin-400.woff2 +0 -0
- package/examples/demo/assets/fonts/jetbrains-mono-latin-400.woff2 +0 -0
- package/examples/demo/assets/ticket-qr.svg +5 -0
- package/examples/demo/board.json +47 -20
- package/examples/demo/comments.json +27 -7
- package/examples/demo/screens/brand.html +155 -0
- package/examples/demo/screens/clash.html +94 -0
- package/examples/demo/screens/empty-day.html +114 -0
- package/examples/demo/screens/film.html +98 -0
- package/examples/demo/screens/home-daylight.html +144 -0
- package/examples/demo/screens/home.html +132 -38
- package/examples/demo/screens/poster.html +77 -0
- package/examples/demo/screens/programme.html +125 -0
- package/examples/demo/screens/site.html +118 -0
- package/examples/demo/screens/square.html +71 -0
- package/examples/demo/screens/ticket.html +107 -0
- package/examples/demo/screens/timetable.html +192 -0
- package/examples/demo/tokens.json +54 -22
- package/package.json +4 -3
- package/server/activity.mjs +370 -0
- package/server/agents.mjs +20 -0
- package/server/args.mjs +23 -2
- package/server/board.mjs +4 -16
- package/server/boards.mjs +46 -21
- package/server/browser.mjs +68 -0
- package/server/chat.mjs +376 -56
- package/server/connect.mjs +94 -0
- package/server/copies.mjs +105 -0
- package/server/custom.mjs +101 -0
- package/server/export.mjs +627 -0
- package/server/forks.mjs +214 -0
- package/server/fsutil.mjs +8 -0
- package/server/history.mjs +152 -24
- package/server/html.mjs +11 -1
- package/server/index.mjs +153 -16
- package/server/occupancy.mjs +183 -0
- package/server/permissions.mjs +141 -0
- package/server/place.mjs +87 -0
- package/server/registry.mjs +110 -0
- package/server/routes.mjs +23 -54
- package/server/runs.mjs +167 -0
- package/server/snapshot.mjs +21 -9
- package/server/tokens.mjs +4 -1
- package/server/update.mjs +63 -0
- package/server/watch.mjs +12 -1
- package/dist/assets/index-DXUYTbPc.js +0 -55
- package/dist/assets/index-lfQlW-DC.css +0 -1
- package/examples/demo/screens/empty.html +0 -43
- package/examples/demo/screens/habit.html +0 -55
- package/examples/demo/screens/landing.html +0 -44
- package/examples/demo/screens/new-habit.html +0 -47
- package/examples/demo/screens/settings.html +0 -43
- package/examples/demo/screens/stats.html +0 -50
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// AI-generated with Claude Code, 2026-11-10, reviewed by Hyun Park
|
|
2
|
+
// `easel-canvas connect`: writes the Easel MCP entry (no port: easel-mcp finds the canvas for its folder) into each agent's config,
|
|
3
|
+
// merged into what is there, idempotent, never overwriting a file it cannot parse.
|
|
4
|
+
import { existsSync } from "node:fs";
|
|
5
|
+
import fs from "node:fs/promises";
|
|
6
|
+
import os from "node:os";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
|
|
9
|
+
export const MCP_COMMAND = { command: "npx", args: ["-y", "-p", "easel-canvas", "easel-mcp"] };
|
|
10
|
+
|
|
11
|
+
/** Agent → where its config lives and the entry it gets. JSON targets are project files; Codex only has a user config here */
|
|
12
|
+
export function targets({ project, home = os.homedir(), env = process.env }) {
|
|
13
|
+
const codexHome = env.CODEX_HOME || path.join(home, ".codex");
|
|
14
|
+
return {
|
|
15
|
+
claude: { label: "Claude Code", file: path.join(project, ".mcp.json"), entry: { type: "stdio", ...MCP_COMMAND }, applies: true },
|
|
16
|
+
cursor: { label: "Cursor", file: path.join(project, ".cursor/mcp.json"), entry: { type: "stdio", ...MCP_COMMAND }, applies: existsSync(path.join(project, ".cursor")) || existsSync(path.join(home, ".cursor")) },
|
|
17
|
+
gemini: { label: "Gemini CLI", file: path.join(project, ".gemini/settings.json"), entry: { ...MCP_COMMAND }, applies: existsSync(path.join(project, ".gemini")) || existsSync(path.join(home, ".gemini")) },
|
|
18
|
+
codex: { label: "Codex", file: path.join(codexHome, "config.toml"), toml: true, applies: existsSync(codexHome), needs: codexHome },
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
23
|
+
|
|
24
|
+
/** Existing JSON text (or null) → { status: "write" | "unchanged" | "invalid", text } with mcpServers.easel set */
|
|
25
|
+
export function mergeJson(text, entry) {
|
|
26
|
+
let data = {};
|
|
27
|
+
if (text != null && text.trim()) {
|
|
28
|
+
try {
|
|
29
|
+
data = JSON.parse(text);
|
|
30
|
+
} catch {
|
|
31
|
+
return { status: "invalid" };
|
|
32
|
+
}
|
|
33
|
+
if (!data || typeof data !== "object" || Array.isArray(data)) return { status: "invalid" };
|
|
34
|
+
}
|
|
35
|
+
if (data.mcpServers != null && (typeof data.mcpServers !== "object" || Array.isArray(data.mcpServers))) return { status: "invalid" };
|
|
36
|
+
if (same(data.mcpServers?.easel, entry)) return { status: "unchanged" };
|
|
37
|
+
const indent = /^[ \t]+(?=")/m.exec(text ?? "")?.[0] ?? 2;
|
|
38
|
+
return { status: "write", text: JSON.stringify({ ...data, mcpServers: { ...data.mcpServers, easel: entry } }, null, indent) + "\n" };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const CODEX_BLOCK = `[mcp_servers.easel]
|
|
42
|
+
command = "npx"
|
|
43
|
+
args = [${MCP_COMMAND.args.map((a) => JSON.stringify(a)).join(", ")}]
|
|
44
|
+
default_tools_approval_mode = "approve" # the tools only view, comment and arrange
|
|
45
|
+
`;
|
|
46
|
+
|
|
47
|
+
/** Existing config.toml text (or null) → the block appended when there is no [mcp_servers.easel] table; other content is never touched */
|
|
48
|
+
export function mergeToml(text) {
|
|
49
|
+
const t = text ?? "";
|
|
50
|
+
const m = /^[ \t]*\[mcp_servers\.(?:easel|"easel")\][^\n]*\n([\s\S]*?)(?=^[ \t]*\[|(?![\s\S]))/m.exec(t);
|
|
51
|
+
if (m) return { status: "unchanged", note: /--port/.test(m[1]) ? "has --port; remove it so easel-mcp finds the canvas by folder" : "" };
|
|
52
|
+
return { status: "write", text: t + (t && !t.endsWith("\n") ? "\n" : "") + (t.trim() ? "\n" : "") + CODEX_BLOCK };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Writes (or with dryRun only reports) each agent's config. agents: ids to write, default every one that applies.
|
|
57
|
+
* Returns one line per target.
|
|
58
|
+
*/
|
|
59
|
+
export async function connect({ project, home, env, agents = null, dryRun = false }) {
|
|
60
|
+
const all = targets({ project, home, env });
|
|
61
|
+
const unknown = (agents ?? []).filter((a) => !all[a]);
|
|
62
|
+
if (unknown.length) throw new Error(`Unknown agent ${unknown.join(", ")}. Use ${Object.keys(all).join(",")}`);
|
|
63
|
+
const lines = [];
|
|
64
|
+
const show = (f) => (f.startsWith(project + path.sep) ? path.relative(project, f) : f.replace(home ?? os.homedir(), "~"));
|
|
65
|
+
for (const [id, t] of Object.entries(all)) {
|
|
66
|
+
if (agents && !agents.includes(id)) continue;
|
|
67
|
+
if (!agents && !t.applies && !t.needs) {
|
|
68
|
+
lines.push(`skipped ${show(t.file)} (${t.label}): not used here (no .${id} folder); --agents ${id} writes it anyway`);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (t.needs && !existsSync(t.needs)) {
|
|
72
|
+
lines.push(`skipped ${show(t.file)} (${t.label}): ${show(t.needs)} not found, is Codex installed?`);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const text = await fs.readFile(t.file, "utf8").catch(() => null);
|
|
76
|
+
const r = t.toml ? mergeToml(text) : mergeJson(text, t.entry);
|
|
77
|
+
if (r.status === "invalid") {
|
|
78
|
+
lines.push(`skipped ${show(t.file)} (${t.label}): not valid JSON, left as is; add the easel entry by hand`);
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (r.status === "unchanged") {
|
|
82
|
+
lines.push(`unchanged ${show(t.file)} (${t.label})${r.note ? `: ${r.note}` : ""}`);
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (dryRun) {
|
|
86
|
+
lines.push(`would write ${show(t.file)} (${t.label}):\n${(t.toml ? CODEX_BLOCK : r.text).replace(/^/gm, " ")}`);
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
await fs.mkdir(path.dirname(t.file), { recursive: true });
|
|
90
|
+
await fs.writeFile(t.file, r.text);
|
|
91
|
+
lines.push(`wrote ${show(t.file)} (${t.label})`);
|
|
92
|
+
}
|
|
93
|
+
return lines;
|
|
94
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// AI-generated with Claude Code, 2026-11-10, reviewed by Hyun Park
|
|
2
|
+
// Folder copies that work without git: a copy of the tracked files before each in-app AI run (revertable after a restart),
|
|
3
|
+
// and snapshot copies of the design folder when it is not in a git repository. Both live in <design dir>/.easel/.
|
|
4
|
+
import fs from "node:fs/promises";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
|
|
7
|
+
import { easelDir, toPosix, writeAtomic } from "./fsutil.mjs";
|
|
8
|
+
|
|
9
|
+
export const KEEP_RUNS = 10;
|
|
10
|
+
const read = (p) => fs.readFile(p, "utf8").catch(() => null);
|
|
11
|
+
const EXTRA = ["comments.json", "tokens.json"]; // copied for manual recovery, not restored by a revert
|
|
12
|
+
|
|
13
|
+
/** Tracked files relative to the design folder: screens/<…>.html and board.json when present */
|
|
14
|
+
async function trackedRel(store) {
|
|
15
|
+
const out = (await store.listScreenFiles()).map((f) => toPosix(path.relative(path.dirname(store.screensDir), path.join(store.screensDir, f))));
|
|
16
|
+
if ((await read(store.boardPath)) != null) out.push("board.json");
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** A name trackedRel could have produced: board.json or screens/<…>.html, no dot segments */
|
|
21
|
+
export const isTrackedRel = (f) => typeof f === "string" && (f === "board.json" || (/^screens\/.+\.html$/.test(f) && !f.split("/").some((s) => s === "" || s.startsWith("."))));
|
|
22
|
+
|
|
23
|
+
const runsDir = async (dir) => path.join(await easelDir(dir), "runs");
|
|
24
|
+
|
|
25
|
+
/** Copies the tracked files (plus comments.json/tokens.json) to .easel/runs/<id>/ and keeps the newest KEEP_RUNS copies */
|
|
26
|
+
export async function copyRun(ctx, id, meta) {
|
|
27
|
+
const dest = path.join(await runsDir(ctx.dir), id);
|
|
28
|
+
const files = await trackedRel(ctx.store);
|
|
29
|
+
const extra = [];
|
|
30
|
+
for (const f of EXTRA) if ((await read(path.join(ctx.dir, f))) != null) extra.push(f);
|
|
31
|
+
for (const f of [...files, ...extra]) {
|
|
32
|
+
await fs.mkdir(path.dirname(path.join(dest, f)), { recursive: true });
|
|
33
|
+
await fs.copyFile(path.join(ctx.dir, f), path.join(dest, f));
|
|
34
|
+
}
|
|
35
|
+
await fs.writeFile(path.join(dest, "run.json"), JSON.stringify({ id, ...meta, at: new Date().toISOString(), files, extra }, null, 1) + "\n");
|
|
36
|
+
await pruneRuns(ctx.dir);
|
|
37
|
+
return dest;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Deletes run copies beyond the newest keep (ids are r<base36 time>) */
|
|
41
|
+
export async function pruneRuns(dir, keep = KEEP_RUNS) {
|
|
42
|
+
const d = await runsDir(dir);
|
|
43
|
+
const ids = (await fs.readdir(d).catch(() => [])).filter((n) => /^r[0-9a-z]+$/.test(n)).sort((a, b) => parseInt(b.slice(1), 36) - parseInt(a.slice(1), 36));
|
|
44
|
+
for (const n of ids.slice(keep)) await fs.rm(path.join(d, n), { recursive: true, force: true });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Restores the tracked files to the copy of run id as one history step; null when the copy is gone */
|
|
48
|
+
export async function revertRun(ctx, id) {
|
|
49
|
+
if (!/^r[0-9a-z]+$/.test(String(id ?? ""))) return null;
|
|
50
|
+
const src = path.join(await runsDir(ctx.dir), id);
|
|
51
|
+
const meta = await read(path.join(src, "run.json")).then((t) => (t ? JSON.parse(t) : null));
|
|
52
|
+
if (!meta) return null;
|
|
53
|
+
// run.json sits in the project folder where anything can edit it: only names of tracked files are restored
|
|
54
|
+
const copied = (Array.isArray(meta.files) ? meta.files : []).filter(isTrackedRel);
|
|
55
|
+
const changes = [];
|
|
56
|
+
const now = await trackedRel(ctx.store);
|
|
57
|
+
for (const f of [...new Set([...copied, ...now])]) {
|
|
58
|
+
const p = path.join(ctx.dir, f);
|
|
59
|
+
const before = await read(p);
|
|
60
|
+
const after = copied.includes(f) ? await read(path.join(src, f)) : null;
|
|
61
|
+
if (before === after) continue;
|
|
62
|
+
if (after == null) await fs.rm(p, { force: true });
|
|
63
|
+
else {
|
|
64
|
+
await fs.mkdir(path.dirname(p), { recursive: true });
|
|
65
|
+
await writeAtomic(p, after);
|
|
66
|
+
}
|
|
67
|
+
changes.push({ path: p, before, after });
|
|
68
|
+
}
|
|
69
|
+
ctx.history.push(`Revert ${meta.label ?? "AI"} run`, changes);
|
|
70
|
+
return { meta, changes };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/* ---------- Snapshot copies (no git) ---------- */
|
|
74
|
+
const snapsDir = async (dir) => path.join(await easelDir(dir), "snapshots");
|
|
75
|
+
const slug = (s) => String(s).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 40) || "snapshot";
|
|
76
|
+
|
|
77
|
+
/** Copies the design folder (without dot folders like .easel, .thumbs, .trash, .refs) to .easel/snapshots/<time>-<slug>/ */
|
|
78
|
+
export async function copySnapshot(dir, { message, author }) {
|
|
79
|
+
const at = new Date();
|
|
80
|
+
const name = `${at.toISOString().replace(/[:.]/g, "-")}-${slug(message)}`;
|
|
81
|
+
const dest = path.join(await snapsDir(dir), name);
|
|
82
|
+
await fs.mkdir(dest, { recursive: true });
|
|
83
|
+
// Entry by entry: fs.cp refuses a destination inside its source even when a filter skips it
|
|
84
|
+
for (const e of await fs.readdir(dir)) if (!e.startsWith(".")) await fs.cp(path.join(dir, e), path.join(dest, e), { recursive: true, filter: (s) => !path.basename(s).startsWith(".") });
|
|
85
|
+
await fs.writeFile(path.join(dest, ".snapshot.json"), JSON.stringify({ message, author, at: at.toISOString() }, null, 1) + "\n");
|
|
86
|
+
return { name, dest };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** "3 minutes ago", like git's %ar */
|
|
90
|
+
export function relTime(at, now = Date.now()) {
|
|
91
|
+
const s = Math.max(0, Math.round((now - new Date(at).getTime()) / 1000));
|
|
92
|
+
const [n, u] = s < 60 ? [s, "second"] : s < 3600 ? [Math.round(s / 60), "minute"] : s < 86400 ? [Math.round(s / 3600), "hour"] : [Math.round(s / 86400), "day"];
|
|
93
|
+
return `${n} ${u}${n === 1 ? "" : "s"} ago`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Snapshot copies, newest first, in the /api/snapshots row shape */
|
|
97
|
+
export async function listSnapshotCopies(dir) {
|
|
98
|
+
const d = path.join(dir, ".easel", "snapshots");
|
|
99
|
+
const out = [];
|
|
100
|
+
for (const n of await fs.readdir(d).catch(() => [])) {
|
|
101
|
+
const m = await read(path.join(d, n, ".snapshot.json")).then((t) => (t ? JSON.parse(t) : null)).catch(() => null);
|
|
102
|
+
if (m) out.push({ hash: n, author: m.author ?? "", when: relTime(m.at), subject: m.message ?? "", at: m.at, kind: "copy", path: toPosix(path.join(".easel", "snapshots", n)) });
|
|
103
|
+
}
|
|
104
|
+
return out.sort((a, b) => (a.at < b.at ? 1 : -1));
|
|
105
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// AI-generated with Claude Code, 2026-11-11, reviewed by Hyun Park
|
|
2
|
+
// Custom agent commands ("Custom command…" in the AI tab): stored per user in <EASEL_HOME or ~/.easel>/agents.json, never in the
|
|
3
|
+
// project (a cloned repository must not be able to ship a command). Run without a shell: {prompt} is substituted inside one argument.
|
|
4
|
+
import fs from "node:fs/promises";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
|
|
7
|
+
import { writeAtomic } from "./fsutil.mjs";
|
|
8
|
+
import { easelHome } from "./registry.mjs";
|
|
9
|
+
|
|
10
|
+
const file = (home) => path.join(home, "agents.json");
|
|
11
|
+
const MAX = 20;
|
|
12
|
+
|
|
13
|
+
/** Splits a command line into arguments like a POSIX shell would quote them: '…', "…" and \ escapes; no expansion of any kind */
|
|
14
|
+
export function splitCommand(line) {
|
|
15
|
+
const out = [];
|
|
16
|
+
let cur = "";
|
|
17
|
+
let has = false;
|
|
18
|
+
let q = null;
|
|
19
|
+
const s = String(line ?? "");
|
|
20
|
+
for (let i = 0; i < s.length; i++) {
|
|
21
|
+
const ch = s[i];
|
|
22
|
+
if (q === "'") {
|
|
23
|
+
if (ch === "'") q = null;
|
|
24
|
+
else cur += ch;
|
|
25
|
+
} else if (q === '"') {
|
|
26
|
+
if (ch === '"') q = null;
|
|
27
|
+
else if (ch === "\\" && i + 1 < s.length && /["\\$`]/.test(s[i + 1])) cur += s[++i];
|
|
28
|
+
else cur += ch;
|
|
29
|
+
} else if (ch === "'" || ch === '"') {
|
|
30
|
+
q = ch;
|
|
31
|
+
has = true;
|
|
32
|
+
} else if (ch === "\\" && i + 1 < s.length) {
|
|
33
|
+
cur += s[++i];
|
|
34
|
+
has = true;
|
|
35
|
+
} else if (/\s/.test(ch)) {
|
|
36
|
+
if (has || cur) out.push(cur);
|
|
37
|
+
cur = "";
|
|
38
|
+
has = false;
|
|
39
|
+
} else cur += ch;
|
|
40
|
+
}
|
|
41
|
+
if (q) throw new Error("Unclosed quote in the command");
|
|
42
|
+
if (has || cur) out.push(cur);
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Name and command checked before saving: a name, a program, and {prompt} in an argument after it */
|
|
47
|
+
export function checkCustom({ name, command }) {
|
|
48
|
+
const n = String(name ?? "").replace(/[\u0000-\u001f\u007f]+/g, " ").trim();
|
|
49
|
+
if (!n || n.length > 40) return { error: "Give the command a name (up to 40 characters)" };
|
|
50
|
+
const c = String(command ?? "").trim();
|
|
51
|
+
if (!c || c.length > 1000 || /[\r\n]/.test(c)) return { error: "Enter the command on one line" };
|
|
52
|
+
let args;
|
|
53
|
+
try {
|
|
54
|
+
args = splitCommand(c);
|
|
55
|
+
} catch (e) {
|
|
56
|
+
return { error: e.message };
|
|
57
|
+
}
|
|
58
|
+
if (!args.length || args[0].includes("{prompt}")) return { error: "The command must start with a program name" };
|
|
59
|
+
if (!args.slice(1).some((a) => a.includes("{prompt}"))) return { error: "Put {prompt} where your request should go" };
|
|
60
|
+
return { name: n, command: c };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** argv for a run: {prompt} replaced inside the argument it appears in, so the request is always exactly one argument's worth */
|
|
64
|
+
export function customArgv(command, prompt) {
|
|
65
|
+
const [cmd, ...rest] = splitCommand(command);
|
|
66
|
+
return { cmd, args: rest.map((a) => a.split("{prompt}").join(prompt)) };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export async function readCustom(home = easelHome()) {
|
|
70
|
+
try {
|
|
71
|
+
const d = JSON.parse(await fs.readFile(file(home), "utf8"));
|
|
72
|
+
return (Array.isArray(d.custom) ? d.custom : []).filter((c) => c && /^c[0-9a-z]+$/.test(c.id) && !checkCustom(c).error);
|
|
73
|
+
} catch {
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function writeCustom(list, home) {
|
|
79
|
+
await fs.mkdir(home, { recursive: true });
|
|
80
|
+
await writeAtomic(file(home), JSON.stringify({ custom: list }, null, 1) + "\n");
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Adds a command; { agent } or { error } */
|
|
84
|
+
export async function addCustom(body, home = easelHome()) {
|
|
85
|
+
const c = checkCustom(body);
|
|
86
|
+
if (c.error) return c;
|
|
87
|
+
const list = await readCustom(home);
|
|
88
|
+
if (list.length >= MAX) return { error: `Up to ${MAX} custom commands` };
|
|
89
|
+
const agent = { id: `c${Date.now().toString(36)}`, name: c.name, command: c.command };
|
|
90
|
+
while (list.some((x) => x.id === agent.id)) agent.id = `c${(parseInt(agent.id.slice(1), 36) + 1).toString(36)}`;
|
|
91
|
+
await writeCustom([...list, agent], home);
|
|
92
|
+
return { agent };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export async function removeCustom(id, home = easelHome()) {
|
|
96
|
+
const list = await readCustom(home);
|
|
97
|
+
await writeCustom(
|
|
98
|
+
list.filter((c) => c.id !== id),
|
|
99
|
+
home,
|
|
100
|
+
);
|
|
101
|
+
}
|