@hachej/boring-ui-cli 0.1.12 → 0.1.14
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 +209 -16
- package/dist/index.js +9 -137
- package/dist/server/cli.js +305 -0
- package/dist/server/localWorkspaces.js +159 -0
- package/package.json +19 -5
- package/public/assets/{CodeEditor-DQqOn4xz-DuFpBvbb.js → CodeEditor-DQqOn4xz-KzhiCz--.js} +1 -1
- package/public/assets/{FileTree-BVfqs3rR-Czof9U4p.js → FileTree-Dl-qUAB0-B2la_qys.js} +10 -10
- package/public/assets/{MarkdownEditor-CcCDF65H-D2GfBGsV.js → MarkdownEditor-yc6mFsnI-But_i4l5.js} +59 -59
- package/public/assets/{_baseUniq-CsAl84mt.js → _baseUniq-DdgAi7yq.js} +1 -1
- package/public/assets/{arc-PTZanISu.js → arc-CCqUtds5.js} +1 -1
- package/public/assets/{architectureDiagram-Q4EWVU46-CVcjgRnu.js → architectureDiagram-Q4EWVU46-B_KUn6cs.js} +1 -1
- package/public/assets/{blockDiagram-DXYQGD6D-Bru_ZwpZ.js → blockDiagram-DXYQGD6D-DZgTILG7.js} +1 -1
- package/public/assets/{c4Diagram-AHTNJAMY-BW3IBSCV.js → c4Diagram-AHTNJAMY-CJflQswY.js} +1 -1
- package/public/assets/channel-DGvkobtu.js +1 -0
- package/public/assets/{chunk-4BX2VUAB-YcjheD0W.js → chunk-4BX2VUAB-iDI_gnLq.js} +1 -1
- package/public/assets/{chunk-4TB4RGXK-D56FxuL5.js → chunk-4TB4RGXK-DKWIFYxg.js} +1 -1
- package/public/assets/{chunk-55IACEB6-B6MbtPYM.js → chunk-55IACEB6-D__oMXZt.js} +1 -1
- package/public/assets/{chunk-EDXVE4YY-DzJUuRqn.js → chunk-EDXVE4YY-Do1Ka_m9.js} +1 -1
- package/public/assets/{chunk-FMBD7UC4-CHrv3vIp.js → chunk-FMBD7UC4-lANxhjIk.js} +1 -1
- package/public/assets/{chunk-OYMX7WX6-BT4nDcXl.js → chunk-OYMX7WX6-D5V4Ykah.js} +1 -1
- package/public/assets/{chunk-QZHKN3VN-ZltyYxH5.js → chunk-QZHKN3VN-Qd0rJnNE.js} +1 -1
- package/public/assets/{chunk-YZCP3GAM-BaUQKTaA.js → chunk-YZCP3GAM-CFwEplp0.js} +1 -1
- package/public/assets/classDiagram-6PBFFD2Q-CbsNjbES.js +1 -0
- package/public/assets/classDiagram-v2-HSJHXN6E-CbsNjbES.js +1 -0
- package/public/assets/clone-CGN5Up_u.js +1 -0
- package/public/assets/{cose-bilkent-S5V4N54A-D_3_vdXE.js → cose-bilkent-S5V4N54A-DfVWRV6i.js} +1 -1
- package/public/assets/{dagre-KV5264BT-BG41F0c2.js → dagre-KV5264BT-DwkYud_A.js} +1 -1
- package/public/assets/{diagram-5BDNPKRD-DIvJKX1t.js → diagram-5BDNPKRD-BVmqnZKF.js} +1 -1
- package/public/assets/{diagram-G4DWMVQ6-BAvBh9MI.js → diagram-G4DWMVQ6-Be8h-c7h.js} +1 -1
- package/public/assets/{diagram-MMDJMWI5-7Ck3ersx.js → diagram-MMDJMWI5-CeQIY42x.js} +1 -1
- package/public/assets/{diagram-TYMM5635-CfYIGnZO.js → diagram-TYMM5635-2m1E87ZC.js} +1 -1
- package/public/assets/{erDiagram-SMLLAGMA-J8_GEWbc.js → erDiagram-SMLLAGMA-CEAPDf64.js} +1 -1
- package/public/assets/{flowDiagram-DWJPFMVM-DSNWoowL.js → flowDiagram-DWJPFMVM-70-QVqzZ.js} +1 -1
- package/public/assets/{ganttDiagram-T4ZO3ILL-CqeSgxFm.js → ganttDiagram-T4ZO3ILL-CQUeK6YZ.js} +1 -1
- package/public/assets/{gitGraphDiagram-UUTBAWPF-WTqcsRvO.js → gitGraphDiagram-UUTBAWPF-BAxMyzkG.js} +1 -1
- package/public/assets/{graph-DV--OlCM.js → graph-DBYJAYcR.js} +1 -1
- package/public/assets/{highlighted-body-OFNGDK62-5nFXisM5.js → highlighted-body-OFNGDK62-D32MCa1A.js} +1 -1
- package/public/assets/index-CyEGNm7Z.css +1 -0
- package/public/assets/index-DfV9nLZO.js +1324 -0
- package/public/assets/{index-BCTkptLY.js → index-Dnr-P_qO.js} +1 -1
- package/public/assets/{infoDiagram-42DDH7IO-21ZE2SqE.js → infoDiagram-42DDH7IO-D4XwdS2Z.js} +1 -1
- package/public/assets/{ishikawaDiagram-UXIWVN3A-BZHBECQ2.js → ishikawaDiagram-UXIWVN3A-7F_PxA8e.js} +1 -1
- package/public/assets/{journeyDiagram-VCZTEJTY-r3HLhR12.js → journeyDiagram-VCZTEJTY-CBJ4F9tD.js} +1 -1
- package/public/assets/{kanban-definition-6JOO6SKY-CPVAOYpU.js → kanban-definition-6JOO6SKY-DNxo2cA_.js} +1 -1
- package/public/assets/{layout-DVgbi3D8.js → layout-xHv827iK.js} +1 -1
- package/public/assets/{linear-BhYOZzNM.js → linear-C4D-wE9b.js} +1 -1
- package/public/assets/{min-DfE81L3F.js → min-DRKJR04f.js} +1 -1
- package/public/assets/{mindmap-definition-QFDTVHPH-CA2yvXBH.js → mindmap-definition-QFDTVHPH-BFEYUDaK.js} +1 -1
- package/public/assets/{pieDiagram-DEJITSTG-L_mmH_pC.js → pieDiagram-DEJITSTG-OgFPC-fQ.js} +1 -1
- package/public/assets/{quadrantDiagram-34T5L4WZ-CnQ66FVE.js → quadrantDiagram-34T5L4WZ-gcFm5ymy.js} +1 -1
- package/public/assets/{requirementDiagram-MS252O5E-DDS8MLl5.js → requirementDiagram-MS252O5E-C-NXT7Xx.js} +1 -1
- package/public/assets/{sankeyDiagram-XADWPNL6-dVHOsqxu.js → sankeyDiagram-XADWPNL6-BVTpXbQ9.js} +1 -1
- package/public/assets/{sequenceDiagram-FGHM5R23-ChrdcmX-.js → sequenceDiagram-FGHM5R23-6nnB6xSY.js} +1 -1
- package/public/assets/{stateDiagram-FHFEXIEX-BPKTx0lB.js → stateDiagram-FHFEXIEX-vvjjWHqR.js} +1 -1
- package/public/assets/stateDiagram-v2-QKLJ7IA2-UKC2Fz8g.js +1 -0
- package/public/assets/{timeline-definition-GMOUNBTQ-CcLsYfJW.js → timeline-definition-GMOUNBTQ-DfgoENQV.js} +1 -1
- package/public/assets/{vennDiagram-DHZGUBPP-Be3AUip7.js → vennDiagram-DHZGUBPP-CwtXgny7.js} +1 -1
- package/public/assets/{wardley-RL74JXVD-1V2kQ4MI.js → wardley-RL74JXVD-YWQ--wCx.js} +1 -1
- package/public/assets/{wardleyDiagram-NUSXRM2D-DpRPkIlo.js → wardleyDiagram-NUSXRM2D-0iSD2F3A.js} +1 -1
- package/public/assets/{xychartDiagram-5P7HB3ND-Cvj_r6ra.js → xychartDiagram-5P7HB3ND-DpVtsfdW.js} +1 -1
- package/public/index.html +3 -3
- package/public/assets/channel-CFDWsi74.js +0 -1
- package/public/assets/classDiagram-6PBFFD2Q-DIdIurqI.js +0 -1
- package/public/assets/classDiagram-v2-HSJHXN6E-DIdIurqI.js +0 -1
- package/public/assets/clone-4dCRxMF-.js +0 -1
- package/public/assets/index-C6eyf77n.css +0 -1
- package/public/assets/index-XsaRyZHq.js +0 -1349
- package/public/assets/stateDiagram-v2-QKLJ7IA2-DJmb7lXU.js +0 -1
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { execSync } from "node:child_process";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import { basename, isAbsolute, join, resolve } from "node:path";
|
|
5
|
+
import { parseArgs } from "node:util";
|
|
6
|
+
import { AuthStorage, ModelRegistry } from "@mariozechner/pi-coding-agent";
|
|
7
|
+
import { createLocalWorkspaceRegistry } from "./localWorkspaces.js";
|
|
8
|
+
const MODE_MAP = {
|
|
9
|
+
"local": "direct",
|
|
10
|
+
// no sandbox, full network access
|
|
11
|
+
"local-sandbox": "local"
|
|
12
|
+
// bwrap isolated, no network (Linux only)
|
|
13
|
+
};
|
|
14
|
+
function httpError(message, statusCode) {
|
|
15
|
+
const error = new Error(message);
|
|
16
|
+
error.statusCode = statusCode;
|
|
17
|
+
return error;
|
|
18
|
+
}
|
|
19
|
+
function firstString(value) {
|
|
20
|
+
if (typeof value === "string") return value;
|
|
21
|
+
if (!Array.isArray(value)) return void 0;
|
|
22
|
+
return value.find((item) => typeof item === "string");
|
|
23
|
+
}
|
|
24
|
+
function resolveWorkspaceIdFromRequest(request) {
|
|
25
|
+
const headers = request.headers ?? {};
|
|
26
|
+
const headerValue = headers["x-boring-workspace-id"] ?? Object.entries(headers).find(([key]) => key.toLowerCase() === "x-boring-workspace-id")?.[1];
|
|
27
|
+
const query = request.query;
|
|
28
|
+
const raw = firstString(headerValue) ?? firstString(query?.workspaceId) ?? "";
|
|
29
|
+
const workspaceId = raw.trim();
|
|
30
|
+
if (!workspaceId) throw httpError("workspace id is required", 400);
|
|
31
|
+
if (workspaceId.includes("\0") || workspaceId.includes("/") || workspaceId.includes("\\") || workspaceId.includes("..") || isAbsolute(workspaceId)) {
|
|
32
|
+
throw httpError("invalid workspace id", 400);
|
|
33
|
+
}
|
|
34
|
+
return workspaceId;
|
|
35
|
+
}
|
|
36
|
+
function toCoreWorkspace(workspace) {
|
|
37
|
+
return {
|
|
38
|
+
id: workspace.id,
|
|
39
|
+
name: workspace.name,
|
|
40
|
+
slug: workspace.id,
|
|
41
|
+
isDefault: false,
|
|
42
|
+
createdAt: workspace.createdAt,
|
|
43
|
+
updatedAt: workspace.updatedAt,
|
|
44
|
+
unavailable: !workspace.available,
|
|
45
|
+
path: workspace.path
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function openBrowser(url) {
|
|
49
|
+
try {
|
|
50
|
+
const opener = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
|
|
51
|
+
execSync(`${opener} ${url}`, { stdio: "ignore" });
|
|
52
|
+
} catch {
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function ensureFrontendBuilt(publicDir) {
|
|
56
|
+
if (existsSync(join(publicDir, "index.html"))) return;
|
|
57
|
+
console.error("\nError: boring-ui frontend not found.");
|
|
58
|
+
console.error("Run `pnpm build:full` in packages/cli to build it first.\n");
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
async function registerStatic(app, publicDir) {
|
|
62
|
+
ensureFrontendBuilt(publicDir);
|
|
63
|
+
const { default: fastifyStatic } = await import("@fastify/static");
|
|
64
|
+
await app.register(fastifyStatic, {
|
|
65
|
+
root: publicDir,
|
|
66
|
+
prefix: "/",
|
|
67
|
+
wildcard: false
|
|
68
|
+
});
|
|
69
|
+
app.setNotFoundHandler(async (req, reply) => {
|
|
70
|
+
if (req.url.startsWith("/api/")) {
|
|
71
|
+
return reply.code(404).send({ error: "Not found" });
|
|
72
|
+
}
|
|
73
|
+
return reply.sendFile("index.html", publicDir);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
const AUTH_GUIDE = [
|
|
77
|
+
"",
|
|
78
|
+
" \u26A0 No LLM provider configured.",
|
|
79
|
+
"",
|
|
80
|
+
" In another terminal, launch pi and run /login to set up an API key or",
|
|
81
|
+
" sign in to a subscription (Claude Pro/Max, ChatGPT Plus, Copilot):",
|
|
82
|
+
"",
|
|
83
|
+
" pi # if installed globally",
|
|
84
|
+
" npx @mariozechner/pi-coding-agent # otherwise",
|
|
85
|
+
"",
|
|
86
|
+
" Then at pi's prompt: /login",
|
|
87
|
+
"",
|
|
88
|
+
" Credentials are saved at ~/.pi/agent/auth.json. Then refresh the browser.",
|
|
89
|
+
""
|
|
90
|
+
].join("\n");
|
|
91
|
+
function checkAuth() {
|
|
92
|
+
const authStorage = AuthStorage.create();
|
|
93
|
+
const registry = ModelRegistry.create(authStorage);
|
|
94
|
+
return registry.getAvailable().length;
|
|
95
|
+
}
|
|
96
|
+
async function startFolderMode(opts) {
|
|
97
|
+
const workspaceRoot = process.env.BORING_AGENT_WORKSPACE_ROOT ?? resolve(opts.folderArg ?? process.cwd());
|
|
98
|
+
const projectName = basename(resolve(workspaceRoot)) || "workspace";
|
|
99
|
+
const modelCount = checkAuth();
|
|
100
|
+
console.log(`
|
|
101
|
+
${projectName}`);
|
|
102
|
+
console.log(` workspace ${workspaceRoot}`);
|
|
103
|
+
console.log(` mode ${opts.cliMode}`);
|
|
104
|
+
console.log(` port ${opts.port}`);
|
|
105
|
+
console.log(` host ${opts.host}`);
|
|
106
|
+
if (modelCount === 0) console.log(AUTH_GUIDE);
|
|
107
|
+
const { createWorkspaceAgentServer } = await import("@hachej/boring-workspace/app/server");
|
|
108
|
+
const app = await createWorkspaceAgentServer({
|
|
109
|
+
workspaceRoot,
|
|
110
|
+
mode: opts.mode,
|
|
111
|
+
logger: false
|
|
112
|
+
});
|
|
113
|
+
app.get("/api/v1/workspace/meta", async () => ({
|
|
114
|
+
workspaceRoot,
|
|
115
|
+
projectName
|
|
116
|
+
}));
|
|
117
|
+
await registerStatic(app, opts.publicDir);
|
|
118
|
+
await app.listen({ port: opts.port, host: opts.host });
|
|
119
|
+
console.log(`
|
|
120
|
+
http://localhost:${opts.port}
|
|
121
|
+
`);
|
|
122
|
+
openBrowser(`http://localhost:${opts.port}`);
|
|
123
|
+
}
|
|
124
|
+
async function startWorkspacesMode(opts) {
|
|
125
|
+
const [workspaceAppServer, workspaceServer, agentServer, fastifyModule] = await Promise.all([
|
|
126
|
+
import("@hachej/boring-workspace/app/server"),
|
|
127
|
+
import("@hachej/boring-workspace/server"),
|
|
128
|
+
import("@hachej/boring-agent/server"),
|
|
129
|
+
import("fastify")
|
|
130
|
+
]);
|
|
131
|
+
const registry = createLocalWorkspaceRegistry();
|
|
132
|
+
const app = fastifyModule.default({ logger: false, bodyLimit: 16 * 1024 * 1024 });
|
|
133
|
+
const bridges = /* @__PURE__ */ new Map();
|
|
134
|
+
function getBridge(workspaceId) {
|
|
135
|
+
let bridge = bridges.get(workspaceId);
|
|
136
|
+
if (!bridge) {
|
|
137
|
+
bridge = workspaceServer.createInMemoryBridge();
|
|
138
|
+
bridges.set(workspaceId, bridge);
|
|
139
|
+
}
|
|
140
|
+
return bridge;
|
|
141
|
+
}
|
|
142
|
+
async function requireWorkspace(workspaceId) {
|
|
143
|
+
const workspace = await registry.get(workspaceId);
|
|
144
|
+
if (!workspace) throw httpError("unknown workspace", 404);
|
|
145
|
+
if (!workspace.available) throw httpError("workspace folder unavailable", 409);
|
|
146
|
+
return workspace;
|
|
147
|
+
}
|
|
148
|
+
async function workspaceFromRequest(request) {
|
|
149
|
+
return await requireWorkspace(resolveWorkspaceIdFromRequest(request));
|
|
150
|
+
}
|
|
151
|
+
app.get("/api/v1/local-workspaces", async () => ({
|
|
152
|
+
workspaces: await registry.list()
|
|
153
|
+
}));
|
|
154
|
+
app.post("/api/v1/local-workspaces", async (request, reply) => {
|
|
155
|
+
const body = request.body;
|
|
156
|
+
if (typeof body?.path !== "string" || !body.path.trim()) {
|
|
157
|
+
return reply.code(400).send({ error: "workspace path is required" });
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
160
|
+
const workspace = await registry.add(body.path, {
|
|
161
|
+
name: typeof body.name === "string" ? body.name : void 0
|
|
162
|
+
});
|
|
163
|
+
return { workspace };
|
|
164
|
+
} catch (error) {
|
|
165
|
+
return reply.code(400).send({
|
|
166
|
+
error: error instanceof Error ? error.message : "unable to add workspace"
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
app.delete("/api/v1/local-workspaces/:id", async (request) => {
|
|
171
|
+
const { id } = request.params;
|
|
172
|
+
await registry.remove(id);
|
|
173
|
+
return { ok: true };
|
|
174
|
+
});
|
|
175
|
+
app.get("/api/v1/workspaces", async () => ({
|
|
176
|
+
workspaces: (await registry.list()).map(toCoreWorkspace)
|
|
177
|
+
}));
|
|
178
|
+
app.get("/api/v1/workspaces/:id", async (request, reply) => {
|
|
179
|
+
const { id } = request.params;
|
|
180
|
+
const workspace = await registry.get(id);
|
|
181
|
+
if (!workspace) return reply.code(404).send({ error: "workspace not found" });
|
|
182
|
+
return { workspace: toCoreWorkspace(workspace), role: "owner" };
|
|
183
|
+
});
|
|
184
|
+
await app.register(agentServer.registerAgentRoutes, {
|
|
185
|
+
mode: opts.mode,
|
|
186
|
+
systemPromptAppend: workspaceAppServer.buildWorkspaceContextPrompt(),
|
|
187
|
+
getWorkspaceId: async (request) => (await workspaceFromRequest(request)).id,
|
|
188
|
+
getWorkspaceRoot: async (workspaceId) => (await requireWorkspace(workspaceId)).path,
|
|
189
|
+
getSessionNamespace: async ({ workspaceId }) => `local-workspace-${workspaceId}`,
|
|
190
|
+
getResourceLoaderOptions: async ({ workspaceRoot }) => ({
|
|
191
|
+
additionalSkillPaths: [join(workspaceRoot, ".agents", "skills")]
|
|
192
|
+
}),
|
|
193
|
+
getExtraTools: async ({ workspaceId, workspaceRoot, workspaceFsCapability }) => [
|
|
194
|
+
...workspaceServer.createWorkspaceUiTools(getBridge(workspaceId), {
|
|
195
|
+
workspaceRoot: workspaceFsCapability === "strong" ? workspaceRoot : void 0
|
|
196
|
+
})
|
|
197
|
+
]
|
|
198
|
+
});
|
|
199
|
+
await app.register(workspaceServer.uiRoutes, {
|
|
200
|
+
getBridge: async (request) => getBridge((await workspaceFromRequest(request)).id)
|
|
201
|
+
});
|
|
202
|
+
app.get("/api/v1/workspace/meta", async () => ({
|
|
203
|
+
projectName: "Boring UI",
|
|
204
|
+
workspacesMode: true
|
|
205
|
+
}));
|
|
206
|
+
await registerStatic(app, opts.publicDir);
|
|
207
|
+
await app.listen({ port: opts.port, host: opts.host });
|
|
208
|
+
const initialWorkspace = (await registry.list()).find((workspace) => workspace.available);
|
|
209
|
+
const initialUrl = initialWorkspace ? `http://localhost:${opts.port}/workspace/${encodeURIComponent(initialWorkspace.id)}` : `http://localhost:${opts.port}`;
|
|
210
|
+
console.log(`
|
|
211
|
+
Boring UI`);
|
|
212
|
+
console.log(` workspaces ${registry.path}`);
|
|
213
|
+
console.log(` mode ${opts.cliMode}`);
|
|
214
|
+
console.log(` port ${opts.port}`);
|
|
215
|
+
console.log(` host ${opts.host}`);
|
|
216
|
+
console.log(`
|
|
217
|
+
${initialUrl}
|
|
218
|
+
`);
|
|
219
|
+
if (checkAuth() === 0) console.log(AUTH_GUIDE);
|
|
220
|
+
openBrowser(initialUrl);
|
|
221
|
+
}
|
|
222
|
+
async function handleWorkspacesCommand(opts) {
|
|
223
|
+
const registry = createLocalWorkspaceRegistry();
|
|
224
|
+
const subcommand = opts.positionals[1];
|
|
225
|
+
if (subcommand === "add") {
|
|
226
|
+
const target = opts.positionals[2];
|
|
227
|
+
if (!target) throw new Error("usage: boring-ui workspaces add <folder>");
|
|
228
|
+
const workspace = await registry.add(target, { name: opts.args.name });
|
|
229
|
+
console.log(`${workspace.name}
|
|
230
|
+
id ${workspace.id}
|
|
231
|
+
path ${workspace.path}`);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
if (subcommand === "list") {
|
|
235
|
+
const workspaces = await registry.list();
|
|
236
|
+
if (workspaces.length === 0) {
|
|
237
|
+
console.log("No workspaces. Add one with `boring-ui workspaces add <folder>`.");
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
for (const workspace of workspaces) {
|
|
241
|
+
console.log(`${workspace.available ? "\u2713" : "!"} ${workspace.name} ${workspace.id}
|
|
242
|
+
${workspace.path}`);
|
|
243
|
+
}
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
if (subcommand === "remove") {
|
|
247
|
+
const id = opts.positionals[2];
|
|
248
|
+
if (!id) throw new Error("usage: boring-ui workspaces remove <id>");
|
|
249
|
+
await registry.remove(id);
|
|
250
|
+
console.log(`removed ${id}`);
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
if (subcommand === "rename") {
|
|
254
|
+
const id = opts.positionals[2];
|
|
255
|
+
const name = opts.positionals.slice(3).join(" ");
|
|
256
|
+
if (!id || !name) throw new Error("usage: boring-ui workspaces rename <id> <name>");
|
|
257
|
+
const workspace = await registry.rename(id, name);
|
|
258
|
+
console.log(`renamed ${workspace.id} -> ${workspace.name}`);
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
await startWorkspacesMode(opts);
|
|
262
|
+
}
|
|
263
|
+
async function runCli(options) {
|
|
264
|
+
const { values: args, positionals } = parseArgs({
|
|
265
|
+
args: options.argv,
|
|
266
|
+
options: {
|
|
267
|
+
port: { type: "string", short: "p" },
|
|
268
|
+
host: { type: "string" },
|
|
269
|
+
mode: { type: "string", short: "m" },
|
|
270
|
+
name: { type: "string", short: "n" }
|
|
271
|
+
},
|
|
272
|
+
allowPositionals: true,
|
|
273
|
+
strict: false
|
|
274
|
+
});
|
|
275
|
+
const port = Number(args.port ?? process.env.PORT) || 5200;
|
|
276
|
+
const host = args.host ?? process.env.HOST ?? "0.0.0.0";
|
|
277
|
+
const rawMode = args.mode ?? process.env.BORING_MODE ?? "local-sandbox";
|
|
278
|
+
if (!(rawMode in MODE_MAP)) {
|
|
279
|
+
throw new Error(`invalid --mode "${rawMode}". Valid options: ${Object.keys(MODE_MAP).join(", ")}`);
|
|
280
|
+
}
|
|
281
|
+
const cliMode = rawMode;
|
|
282
|
+
const mode = MODE_MAP[cliMode];
|
|
283
|
+
const base = {
|
|
284
|
+
publicDir: options.publicDir,
|
|
285
|
+
port,
|
|
286
|
+
host,
|
|
287
|
+
cliMode,
|
|
288
|
+
mode
|
|
289
|
+
};
|
|
290
|
+
if (positionals[0] === "workspaces") {
|
|
291
|
+
await handleWorkspacesCommand({
|
|
292
|
+
...base,
|
|
293
|
+
args: { name: args.name },
|
|
294
|
+
positionals
|
|
295
|
+
});
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
await startFolderMode({
|
|
299
|
+
...base,
|
|
300
|
+
folderArg: positionals[0]
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
export {
|
|
304
|
+
runCli
|
|
305
|
+
};
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { existsSync, statSync } from "node:fs";
|
|
4
|
+
import { mkdir, readFile, realpath, rename, writeFile } from "node:fs/promises";
|
|
5
|
+
import { homedir } from "node:os";
|
|
6
|
+
import { basename, dirname, resolve } from "node:path";
|
|
7
|
+
const DEFAULT_REGISTRY_PATH = resolve(homedir(), ".boring-ui", "workspaces.yaml");
|
|
8
|
+
function getDefaultLocalWorkspaceRegistryPath() {
|
|
9
|
+
return process.env.BORING_UI_WORKSPACES_PATH ? resolve(process.env.BORING_UI_WORKSPACES_PATH) : DEFAULT_REGISTRY_PATH;
|
|
10
|
+
}
|
|
11
|
+
function slugify(value) {
|
|
12
|
+
return value.trim().toLowerCase().normalize("NFKD").replace(/[^a-z0-9_-]+/g, "-").replace(/^-+|-+$/g, "") || "workspace";
|
|
13
|
+
}
|
|
14
|
+
function workspaceIdForPath(path) {
|
|
15
|
+
const hash = createHash("sha1").update(path).digest("hex").slice(0, 8);
|
|
16
|
+
return `${slugify(basename(path))}-${hash}`;
|
|
17
|
+
}
|
|
18
|
+
function yamlString(value) {
|
|
19
|
+
if (/^[a-zA-Z0-9_./:@ -]+$/.test(value) && !value.startsWith(" ") && !value.endsWith(" ")) {
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
return JSON.stringify(value);
|
|
23
|
+
}
|
|
24
|
+
function unquoteYamlString(value) {
|
|
25
|
+
const trimmed = value.trim();
|
|
26
|
+
if (!trimmed) return "";
|
|
27
|
+
if (trimmed.startsWith('"') && trimmed.endsWith('"') || trimmed.startsWith("'") && trimmed.endsWith("'")) {
|
|
28
|
+
try {
|
|
29
|
+
return JSON.parse(trimmed);
|
|
30
|
+
} catch {
|
|
31
|
+
return trimmed.slice(1, -1);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return trimmed;
|
|
35
|
+
}
|
|
36
|
+
function parseRegistryYaml(content) {
|
|
37
|
+
const result = [];
|
|
38
|
+
let current = null;
|
|
39
|
+
for (const line of content.split(/\r?\n/)) {
|
|
40
|
+
const trimmed = line.trim();
|
|
41
|
+
if (!trimmed || trimmed.startsWith("#") || trimmed === "version: 1" || trimmed === "workspaces:") continue;
|
|
42
|
+
const itemMatch = line.match(/^\s*-\s+id:\s*(.*)$/);
|
|
43
|
+
if (itemMatch) {
|
|
44
|
+
if (current?.id && current.name && current.path && current.createdAt && current.updatedAt) {
|
|
45
|
+
result.push(current);
|
|
46
|
+
}
|
|
47
|
+
current = { id: unquoteYamlString(itemMatch[1] ?? "") };
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const fieldMatch = line.match(/^\s+(name|path|createdAt|updatedAt):\s*(.*)$/);
|
|
51
|
+
if (fieldMatch && current) {
|
|
52
|
+
current[fieldMatch[1]] = unquoteYamlString(fieldMatch[2] ?? "");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (current?.id && current.name && current.path && current.createdAt && current.updatedAt) {
|
|
56
|
+
result.push(current);
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
function serializeRegistryYaml(workspaces) {
|
|
61
|
+
const lines = ["version: 1", "workspaces:"];
|
|
62
|
+
for (const workspace of workspaces) {
|
|
63
|
+
lines.push(
|
|
64
|
+
` - id: ${yamlString(workspace.id)}`,
|
|
65
|
+
` name: ${yamlString(workspace.name)}`,
|
|
66
|
+
` path: ${yamlString(workspace.path)}`,
|
|
67
|
+
` createdAt: ${yamlString(workspace.createdAt)}`,
|
|
68
|
+
` updatedAt: ${yamlString(workspace.updatedAt)}`
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
return `${lines.join("\n")}
|
|
72
|
+
`;
|
|
73
|
+
}
|
|
74
|
+
async function resolveWorkspacePath(input) {
|
|
75
|
+
const absolute = resolve(input);
|
|
76
|
+
try {
|
|
77
|
+
return await realpath(absolute);
|
|
78
|
+
} catch {
|
|
79
|
+
return absolute;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function pathIsDirectory(path) {
|
|
83
|
+
try {
|
|
84
|
+
return statSync(path).isDirectory();
|
|
85
|
+
} catch {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function pathExists(path) {
|
|
90
|
+
return existsSync(path);
|
|
91
|
+
}
|
|
92
|
+
function withAvailability(workspace) {
|
|
93
|
+
return { ...workspace, available: pathIsDirectory(workspace.path) };
|
|
94
|
+
}
|
|
95
|
+
function createLocalWorkspaceRegistry(path = getDefaultLocalWorkspaceRegistryPath()) {
|
|
96
|
+
async function readStored() {
|
|
97
|
+
try {
|
|
98
|
+
return parseRegistryYaml(await readFile(path, "utf-8"));
|
|
99
|
+
} catch (error) {
|
|
100
|
+
if (error?.code === "ENOENT") return [];
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async function writeStored(workspaces) {
|
|
105
|
+
await mkdir(dirname(path), { recursive: true });
|
|
106
|
+
const tmp = `${path}.${process.pid}.${Date.now()}.tmp`;
|
|
107
|
+
await writeFile(tmp, serializeRegistryYaml(workspaces), "utf-8");
|
|
108
|
+
await rename(tmp, path);
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
path,
|
|
112
|
+
async list() {
|
|
113
|
+
return (await readStored()).map(withAvailability);
|
|
114
|
+
},
|
|
115
|
+
async get(id) {
|
|
116
|
+
const workspace = (await readStored()).find((entry) => entry.id === id);
|
|
117
|
+
return workspace ? withAvailability(workspace) : null;
|
|
118
|
+
},
|
|
119
|
+
async add(inputPath, opts) {
|
|
120
|
+
const workspacePath = await resolveWorkspacePath(inputPath);
|
|
121
|
+
if (pathExists(workspacePath) && !pathIsDirectory(workspacePath)) {
|
|
122
|
+
throw new Error(`workspace path is not a directory: ${workspacePath}`);
|
|
123
|
+
}
|
|
124
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
125
|
+
const workspaces = await readStored();
|
|
126
|
+
const id = workspaceIdForPath(workspacePath);
|
|
127
|
+
const existing = workspaces.find((entry) => entry.id === id);
|
|
128
|
+
if (existing) return withAvailability(existing);
|
|
129
|
+
const workspace = {
|
|
130
|
+
id,
|
|
131
|
+
name: opts?.name?.trim() || basename(workspacePath) || id,
|
|
132
|
+
path: workspacePath,
|
|
133
|
+
createdAt: now,
|
|
134
|
+
updatedAt: now
|
|
135
|
+
};
|
|
136
|
+
workspaces.push(workspace);
|
|
137
|
+
await writeStored(workspaces);
|
|
138
|
+
return withAvailability(workspace);
|
|
139
|
+
},
|
|
140
|
+
async remove(id) {
|
|
141
|
+
await writeStored((await readStored()).filter((entry) => entry.id !== id));
|
|
142
|
+
},
|
|
143
|
+
async rename(id, name) {
|
|
144
|
+
const nextName = name.trim();
|
|
145
|
+
if (!nextName) throw new Error("workspace name is required");
|
|
146
|
+
const workspaces = await readStored();
|
|
147
|
+
const workspace = workspaces.find((entry) => entry.id === id);
|
|
148
|
+
if (!workspace) throw new Error(`workspace not found: ${id}`);
|
|
149
|
+
workspace.name = nextName;
|
|
150
|
+
workspace.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
151
|
+
await writeStored(workspaces);
|
|
152
|
+
return withAvailability(workspace);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
export {
|
|
157
|
+
createLocalWorkspaceRegistry,
|
|
158
|
+
getDefaultLocalWorkspaceRegistryPath
|
|
159
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hachej/boring-ui-cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"description": "Turn an agent into an app",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -13,12 +13,24 @@
|
|
|
13
13
|
],
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@fastify/static": "^8.0.0",
|
|
16
|
-
"
|
|
17
|
-
"
|
|
16
|
+
"fastify": "^5.4.0",
|
|
17
|
+
"lucide-react": "^1.8.0",
|
|
18
|
+
"@hachej/boring-agent": "0.1.14",
|
|
19
|
+
"@hachej/boring-ui-kit": "0.1.14",
|
|
20
|
+
"@hachej/boring-workspace": "0.1.14"
|
|
18
21
|
},
|
|
19
22
|
"devDependencies": {
|
|
23
|
+
"@tailwindcss/vite": "^4.0.0",
|
|
24
|
+
"@types/react": "^19.0.0",
|
|
25
|
+
"@types/react-dom": "^19.0.0",
|
|
26
|
+
"@vitejs/plugin-react": "^4.0.0",
|
|
27
|
+
"react": "^19.0.0",
|
|
28
|
+
"react-dom": "^19.0.0",
|
|
29
|
+
"tailwindcss": "^4.0.0",
|
|
20
30
|
"tsup": "^8.4.0",
|
|
21
|
-
"typescript": "^5.8.3"
|
|
31
|
+
"typescript": "^5.8.3",
|
|
32
|
+
"vite": "^6.0.0",
|
|
33
|
+
"vitest": "^3.1.3"
|
|
22
34
|
},
|
|
23
35
|
"repository": {
|
|
24
36
|
"type": "git",
|
|
@@ -26,7 +38,9 @@
|
|
|
26
38
|
},
|
|
27
39
|
"scripts": {
|
|
28
40
|
"build": "tsup",
|
|
41
|
+
"build:front": "vite build",
|
|
29
42
|
"build:full": "node scripts/build-full.mjs",
|
|
30
|
-
"typecheck": "tsc --noEmit"
|
|
43
|
+
"typecheck": "pnpm --filter @hachej/boring-agent build && pnpm --filter @hachej/boring-workspace build && tsc --noEmit",
|
|
44
|
+
"test": "pnpm --filter @hachej/boring-ui-kit build && vitest run"
|
|
31
45
|
}
|
|
32
46
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as he,j as hi,bk as fp,bl as ua}from"./index-
|
|
1
|
+
import{r as he,j as hi,bk as fp,bl as ua}from"./index-DfV9nLZO.js";import{k as up,b as dp,s as pp}from"./index-Vcq4gwWv.js";let no=[],Fh=[];(()=>{let i="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map(e=>e?parseInt(e,36):1);for(let e=0,t=0;e<i.length;e++)(e%2?Fh:no).push(t=t+i[e])})();function mp(i){if(i<768)return!1;for(let e=0,t=no.length;;){let r=e+t>>1;if(i<no[r])t=r;else if(i>=Fh[r])e=r+1;else return!0;if(e==t)return!1}}function da(i){return i>=127462&&i<=127487}const pa=8205;function gp(i,e,t=!0,r=!0){return(t?Hh:Qp)(i,e,r)}function Hh(i,e,t){if(e==i.length)return e;e&&Kh(i.charCodeAt(e))&&Jh(i.charCodeAt(e-1))&&e--;let r=fs(i,e);for(e+=ma(r);e<i.length;){let n=fs(i,e);if(r==pa||n==pa||t&&mp(n))e+=ma(n),r=n;else if(da(n)){let s=0,o=e-2;for(;o>=0&&da(fs(i,o));)s++,o-=2;if(s%2==0)break;e+=2}else break}return e}function Qp(i,e,t){for(;e>0;){let r=Hh(i,e-2,t);if(r<e)return r;e--}return 0}function fs(i,e){let t=i.charCodeAt(e);if(!Jh(t)||e+1==i.length)return t;let r=i.charCodeAt(e+1);return Kh(r)?(t-55296<<10)+(r-56320)+65536:t}function Kh(i){return i>=56320&&i<57344}function Jh(i){return i>=55296&&i<56320}function ma(i){return i<65536?1:2}class E{lineAt(e){if(e<0||e>this.length)throw new RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,r){[e,t]=wi(this,e,t);let n=[];return this.decompose(0,e,n,2),r.length&&r.decompose(0,r.length,n,3),this.decompose(t,this.length,n,1),He.from(n,this.length-(t-e)+r.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=wi(this,e,t);let r=[];return this.decompose(e,t,r,0),He.from(r,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),r=this.length-this.scanIdentical(e,-1),n=new Hi(this),s=new Hi(e);for(let o=t,l=t;;){if(n.next(o),s.next(o),o=0,n.lineBreak!=s.lineBreak||n.done!=s.done||n.value!=s.value)return!1;if(l+=n.value.length,n.done||l>=r)return!0}}iter(e=1){return new Hi(this,e)}iterRange(e,t=this.length){return new ec(this,e,t)}iterLines(e,t){let r;if(e==null)r=this.iter();else{t==null&&(t=this.lines+1);let n=this.line(e).from;r=this.iterRange(n,Math.max(n,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new tc(r)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?E.empty:e.length<=32?new ie(e):He.from(ie.split(e,[]))}}class ie extends E{constructor(e,t=Sp(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,r,n){for(let s=0;;s++){let o=this.text[s],l=n+o.length;if((t?r:l)>=e)return new kp(n,l,r,o);n=l+1,r++}}decompose(e,t,r,n){let s=e<=0&&t>=this.length?this:new ie(ga(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(n&1){let o=r.pop(),l=sn(s.text,o.text.slice(),0,s.length);if(l.length<=32)r.push(new ie(l,o.length+s.length));else{let a=l.length>>1;r.push(new ie(l.slice(0,a)),new ie(l.slice(a)))}}else r.push(s)}replace(e,t,r){if(!(r instanceof ie))return super.replace(e,t,r);[e,t]=wi(this,e,t);let n=sn(this.text,sn(r.text,ga(this.text,0,e)),t),s=this.length+r.length-(t-e);return n.length<=32?new ie(n,s):He.from(ie.split(n,[]),s)}sliceString(e,t=this.length,r=`
|
|
2
2
|
`){[e,t]=wi(this,e,t);let n="";for(let s=0,o=0;s<=t&&o<this.text.length;o++){let l=this.text[o],a=s+l.length;s>e&&o&&(n+=r),e<a&&t>s&&(n+=l.slice(Math.max(0,e-s),t-s)),s=a+1}return n}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(e,t){let r=[],n=-1;for(let s of e)r.push(s),n+=s.length+1,r.length==32&&(t.push(new ie(r,n)),r=[],n=-1);return n>-1&&t.push(new ie(r,n)),t}}class He extends E{constructor(e,t){super(),this.children=e,this.length=t,this.lines=0;for(let r of e)this.lines+=r.lines}lineInner(e,t,r,n){for(let s=0;;s++){let o=this.children[s],l=n+o.length,a=r+o.lines-1;if((t?a:l)>=e)return o.lineInner(e,t,r,n);n=l+1,r=a+1}}decompose(e,t,r,n){for(let s=0,o=0;o<=t&&s<this.children.length;s++){let l=this.children[s],a=o+l.length;if(e<=a&&t>=o){let O=n&((o<=e?1:0)|(a>=t?2:0));o>=e&&a<=t&&!O?r.push(l):l.decompose(e-o,t-o,r,O)}o=a+1}}replace(e,t,r){if([e,t]=wi(this,e,t),r.lines<this.lines)for(let n=0,s=0;n<this.children.length;n++){let o=this.children[n],l=s+o.length;if(e>=s&&t<=l){let a=o.replace(e-s,t-s,r),O=this.lines-o.lines+a.lines;if(a.lines<O>>4&&a.lines>O>>6){let h=this.children.slice();return h[n]=a,new He(h,this.length-(t-e)+r.length)}return super.replace(s,l,a)}s=l+1}return super.replace(e,t,r)}sliceString(e,t=this.length,r=`
|
|
3
3
|
`){[e,t]=wi(this,e,t);let n="";for(let s=0,o=0;s<this.children.length&&o<=t;s++){let l=this.children[s],a=o+l.length;o>e&&s&&(n+=r),e<a&&t>o&&(n+=l.sliceString(e-o,t-o,r)),o=a+1}return n}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(e,t){if(!(e instanceof He))return 0;let r=0,[n,s,o,l]=t>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;n+=t,s+=t){if(n==o||s==l)return r;let a=this.children[n],O=e.children[s];if(a!=O)return r+a.scanIdentical(O,t);r+=a.length+1}}static from(e,t=e.reduce((r,n)=>r+n.length+1,-1)){let r=0;for(let u of e)r+=u.lines;if(r<32){let u=[];for(let p of e)p.flatten(u);return new ie(u,t)}let n=Math.max(32,r>>5),s=n<<1,o=n>>1,l=[],a=0,O=-1,h=[];function c(u){let p;if(u.lines>s&&u instanceof He)for(let m of u.children)c(m);else u.lines>o&&(a>o||!a)?(f(),l.push(u)):u instanceof ie&&a&&(p=h[h.length-1])instanceof ie&&u.lines+p.lines<=32?(a+=u.lines,O+=u.length+1,h[h.length-1]=new ie(p.text.concat(u.text),p.length+1+u.length)):(a+u.lines>n&&f(),a+=u.lines,O+=u.length+1,h.push(u))}function f(){a!=0&&(l.push(h.length==1?h[0]:He.from(h,O)),O=-1,a=h.length=0)}for(let u of e)c(u);return f(),l.length==1?l[0]:new He(l,t)}}E.empty=new ie([""],0);function Sp(i){let e=-1;for(let t of i)e+=t.length+1;return e}function sn(i,e,t=0,r=1e9){for(let n=0,s=0,o=!0;s<i.length&&n<=r;s++){let l=i[s],a=n+l.length;a>=t&&(a>r&&(l=l.slice(0,r-n)),n<t&&(l=l.slice(t-n)),o?(e[e.length-1]+=l,o=!1):e.push(l)),n=a+1}return e}function ga(i,e,t){return sn(i,[""],e,t)}class Hi{constructor(e,t=1){this.dir=t,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[e],this.offsets=[t>0?1:(e instanceof ie?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let r=this.nodes.length-1,n=this.nodes[r],s=this.offsets[r],o=s>>1,l=n instanceof ie?n.text.length:n.children.length;if(o==(t>0?l:0)){if(r==0)return this.done=!0,this.value="",this;t>0&&this.offsets[r-1]++,this.nodes.pop(),this.offsets.pop()}else if((s&1)==(t>0?0:1)){if(this.offsets[r]+=t,e==0)return this.lineBreak=!0,this.value=`
|
|
4
4
|
`,this;e--}else if(n instanceof ie){let a=n.text[o+(t<0?-1:0)];if(this.offsets[r]+=t,a.length>Math.max(0,e))return this.value=e==0?a:t>0?a.slice(e):a.slice(0,a.length-e),this;e-=a.length}else{let a=n.children[o+(t<0?-1:0)];e>a.length?(e-=a.length,this.offsets[r]+=t):(t<0&&this.offsets[r]--,this.nodes.push(a),this.offsets.push(t>0?1:(a instanceof ie?a.text.length:a.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}}class ec{constructor(e,t,r){this.value="",this.done=!1,this.cursor=new Hi(e,t>r?-1:1),this.pos=t>r?e.length:0,this.from=Math.min(t,r),this.to=Math.max(t,r)}nextInner(e,t){if(t<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;e+=Math.max(0,t<0?this.pos-this.to:this.from-this.pos);let r=t<0?this.pos-this.from:this.to-this.pos;e>r&&(e=r),r-=e;let{value:n}=this.cursor.next(e);return this.pos+=(n.length+e)*t,this.value=n.length<=r?n:t<0?n.slice(n.length-r):n.slice(0,r),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=""}}class tc{constructor(e){this.inner=e,this.afterBreak=!0,this.value="",this.done=!1}next(e=0){let{done:t,lineBreak:r,value:n}=this.inner.next(e);return t&&this.afterBreak?(this.value="",this.afterBreak=!1):t?(this.done=!0,this.value=""):r?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=n,this.afterBreak=!1),this}get lineBreak(){return!1}}typeof Symbol<"u"&&(E.prototype[Symbol.iterator]=function(){return this.iter()},Hi.prototype[Symbol.iterator]=ec.prototype[Symbol.iterator]=tc.prototype[Symbol.iterator]=function(){return this});let kp=class{constructor(e,t,r,n){this.from=e,this.to=t,this.number=r,this.text=n}get length(){return this.to-this.from}};function wi(i,e,t){return e=Math.max(0,Math.min(i.length,e)),[e,Math.max(e,Math.min(i.length,t))]}function ae(i,e,t=!0,r=!0){return gp(i,e,t,r)}function bp(i){return i>=56320&&i<57344}function yp(i){return i>=55296&&i<56320}function ic(i,e){let t=i.charCodeAt(e);if(!yp(t)||e+1==i.length)return t;let r=i.charCodeAt(e+1);return bp(r)?(t-55296<<10)+(r-56320)+65536:t}function xp(i){return i<=65535?String.fromCharCode(i):(i-=65536,String.fromCharCode((i>>10)+55296,(i&1023)+56320))}function rc(i){return i<65536?1:2}const so=/\r\n?|\n/;var Qe=(function(i){return i[i.Simple=0]="Simple",i[i.TrackDel=1]="TrackDel",i[i.TrackBefore=2]="TrackBefore",i[i.TrackAfter=3]="TrackAfter",i})(Qe||(Qe={}));class nt{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;t<this.sections.length;t+=2)e+=this.sections[t];return e}get newLength(){let e=0;for(let t=0;t<this.sections.length;t+=2){let r=this.sections[t+1];e+=r<0?this.sections[t]:r}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let t=0,r=0,n=0;t<this.sections.length;){let s=this.sections[t++],o=this.sections[t++];o<0?(e(r,n,s),n+=s):n+=o,r+=s}}iterChangedRanges(e,t=!1){oo(this,e,t)}get invertedDesc(){let e=[];for(let t=0;t<this.sections.length;){let r=this.sections[t++],n=this.sections[t++];n<0?e.push(r,n):e.push(n,r)}return new nt(e)}composeDesc(e){return this.empty?e:e.empty?this:nc(this,e)}mapDesc(e,t=!1){return e.empty?this:lo(this,e,t)}mapPos(e,t=-1,r=Qe.Simple){let n=0,s=0;for(let o=0;o<this.sections.length;){let l=this.sections[o++],a=this.sections[o++],O=n+l;if(a<0){if(O>e)return s+(e-n);s+=l}else{if(r!=Qe.Simple&&O>=e&&(r==Qe.TrackDel&&n<e&&O>e||r==Qe.TrackBefore&&n<e||r==Qe.TrackAfter&&O>e))return null;if(O>e||O==e&&t<0&&!l)return e==n||t<0?s:s+a;s+=a}n=O}if(e>n)throw new RangeError(`Position ${e} is out of range for changeset of length ${n}`);return s}touchesRange(e,t=e){for(let r=0,n=0;r<this.sections.length&&n<=t;){let s=this.sections[r++],o=this.sections[r++],l=n+s;if(o>=0&&n<=t&&l>=e)return n<e&&l>t?"cover":!0;n=l}return!1}toString(){let e="";for(let t=0;t<this.sections.length;){let r=this.sections[t++],n=this.sections[t++];e+=(e?" ":"")+r+(n>=0?":"+n:"")}return e}toJSON(){return this.sections}static fromJSON(e){if(!Array.isArray(e)||e.length%2||e.some(t=>typeof t!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new nt(e)}static create(e){return new nt(e)}}class se extends nt{constructor(e,t){super(e),this.inserted=t}apply(e){if(this.length!=e.length)throw new RangeError("Applying change set to a document with the wrong length");return oo(this,(t,r,n,s,o)=>e=e.replace(n,n+(r-t),o),!1),e}mapDesc(e,t=!1){return lo(this,e,t,!0)}invert(e){let t=this.sections.slice(),r=[];for(let n=0,s=0;n<t.length;n+=2){let o=t[n],l=t[n+1];if(l>=0){t[n]=l,t[n+1]=o;let a=n>>1;for(;r.length<a;)r.push(E.empty);r.push(o?e.slice(s,s+o):E.empty)}s+=o}return new se(t,r)}compose(e){return this.empty?e:e.empty?this:nc(this,e,!0)}map(e,t=!1){return e.empty?this:lo(this,e,t,!0)}iterChanges(e,t=!1){oo(this,e,t)}get desc(){return nt.create(this.sections)}filter(e){let t=[],r=[],n=[],s=new or(this);e:for(let o=0,l=0;;){let a=o==e.length?1e9:e[o++];for(;l<a||l==a&&s.len==0;){if(s.done)break e;let h=Math.min(s.len,a-l);ue(n,h,-1);let c=s.ins==-1?-1:s.off==0?s.ins:0;ue(t,h,c),c>0&&Rt(r,t,s.text),s.forward(h),l+=h}let O=e[o++];for(;l<O;){if(s.done)break e;let h=Math.min(s.len,O-l);ue(t,h,-1),ue(n,h,s.ins==-1?-1:s.off==0?s.ins:0),s.forward(h),l+=h}}return{changes:new se(t,r),filtered:nt.create(n)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let r=this.sections[t],n=this.sections[t+1];n<0?e.push(r):n==0?e.push([r]):e.push([r].concat(this.inserted[t>>1].toJSON()))}return e}static of(e,t,r){let n=[],s=[],o=0,l=null;function a(h=!1){if(!h&&!n.length)return;o<t&&ue(n,t-o,-1);let c=new se(n,s);l=l?l.compose(c.map(l)):c,n=[],s=[],o=0}function O(h){if(Array.isArray(h))for(let c of h)O(c);else if(h instanceof se){if(h.length!=t)throw new RangeError(`Mismatched change set length (got ${h.length}, expected ${t})`);a(),l=l?l.compose(h.map(l)):h}else{let{from:c,to:f=c,insert:u}=h;if(c>f||c<0||f>t)throw new RangeError(`Invalid change range ${c} to ${f} (in doc of length ${t})`);let p=u?typeof u=="string"?E.of(u.split(r||so)):u:E.empty,m=p.length;if(c==f&&m==0)return;c<o&&a(),c>o&&ue(n,c-o,-1),ue(n,f-c,m),Rt(s,n,p),o=f}}return O(e),a(!l),l}static empty(e){return new se(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let t=[],r=[];for(let n=0;n<e.length;n++){let s=e[n];if(typeof s=="number")t.push(s,-1);else{if(!Array.isArray(s)||typeof s[0]!="number"||s.some((o,l)=>l&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(s.length==1)t.push(s[0],0);else{for(;r.length<n;)r.push(E.empty);r[n]=E.of(s.slice(1)),t.push(s[0],r[n].length)}}}return new se(t,r)}static createSet(e,t){return new se(e,t)}}function ue(i,e,t,r=!1){if(e==0&&t<=0)return;let n=i.length-2;n>=0&&t<=0&&t==i[n+1]?i[n]+=e:n>=0&&e==0&&i[n]==0?i[n+1]+=t:r?(i[n]+=e,i[n+1]+=t):i.push(e,t)}function Rt(i,e,t){if(t.length==0)return;let r=e.length-2>>1;if(r<i.length)i[i.length-1]=i[i.length-1].append(t);else{for(;i.length<r;)i.push(E.empty);i.push(t)}}function oo(i,e,t){let r=i.inserted;for(let n=0,s=0,o=0;o<i.sections.length;){let l=i.sections[o++],a=i.sections[o++];if(a<0)n+=l,s+=l;else{let O=n,h=s,c=E.empty;for(;O+=l,h+=a,a&&r&&(c=c.append(r[o-2>>1])),!(t||o==i.sections.length||i.sections[o+1]<0);)l=i.sections[o++],a=i.sections[o++];e(n,O,s,h,c),n=O,s=h}}}function lo(i,e,t,r=!1){let n=[],s=r?[]:null,o=new or(i),l=new or(e);for(let a=-1;;){if(o.done&&l.len||l.done&&o.len)throw new Error("Mismatched change set lengths");if(o.ins==-1&&l.ins==-1){let O=Math.min(o.len,l.len);ue(n,O,-1),o.forward(O),l.forward(O)}else if(l.ins>=0&&(o.ins<0||a==o.i||o.off==0&&(l.len<o.len||l.len==o.len&&!t))){let O=l.len;for(ue(n,l.ins,-1);O;){let h=Math.min(o.len,O);o.ins>=0&&a<o.i&&o.len<=h&&(ue(n,0,o.ins),s&&Rt(s,n,o.text),a=o.i),o.forward(h),O-=h}l.next()}else if(o.ins>=0){let O=0,h=o.len;for(;h;)if(l.ins==-1){let c=Math.min(h,l.len);O+=c,h-=c,l.forward(c)}else if(l.ins==0&&l.len<h)h-=l.len,l.next();else break;ue(n,O,a<o.i?o.ins:0),s&&a<o.i&&Rt(s,n,o.text),a=o.i,o.forward(o.len-h)}else{if(o.done&&l.done)return s?se.createSet(n,s):nt.create(n);throw new Error("Mismatched change set lengths")}}}function nc(i,e,t=!1){let r=[],n=t?[]:null,s=new or(i),o=new or(e);for(let l=!1;;){if(s.done&&o.done)return n?se.createSet(r,n):nt.create(r);if(s.ins==0)ue(r,s.len,0,l),s.next();else if(o.len==0&&!o.done)ue(r,0,o.ins,l),n&&Rt(n,r,o.text),o.next();else{if(s.done||o.done)throw new Error("Mismatched change set lengths");{let a=Math.min(s.len2,o.len),O=r.length;if(s.ins==-1){let h=o.ins==-1?-1:o.off?0:o.ins;ue(r,a,h,l),n&&h&&Rt(n,r,o.text)}else o.ins==-1?(ue(r,s.off?0:s.len,a,l),n&&Rt(n,r,s.textBit(a))):(ue(r,s.off?0:s.len,o.off?0:o.ins,l),n&&!o.off&&Rt(n,r,o.text));l=(s.ins>a||o.ins>=0&&o.len>a)&&(l||r.length>O),s.forward2(a),o.forward(a)}}}}class or{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i<e.length?(this.len=e[this.i++],this.ins=e[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,t=this.i-2>>1;return t>=e.length?E.empty:e[t]}textBit(e){let{inserted:t}=this.set,r=this.i-2>>1;return r>=t.length&&!e?E.empty:t[r].slice(this.off,e==null?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){this.ins==-1?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}}class It{constructor(e,t,r){this.from=e,this.to=t,this.flags=r}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get bidiLevel(){let e=this.flags&7;return e==7?null:e}get goalColumn(){let e=this.flags>>6;return e==16777215?void 0:e}map(e,t=-1){let r,n;return this.empty?r=n=e.mapPos(this.from,t):(r=e.mapPos(this.from,1),n=e.mapPos(this.to,-1)),r==this.from&&n==this.to?this:new It(r,n,this.flags)}extend(e,t=e,r=0){if(e<=this.anchor&&t>=this.anchor)return S.range(e,t,void 0,void 0,r);let n=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return S.range(this.anchor,n,void 0,void 0,r)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&this.goalColumn==e.goalColumn&&(!t||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return S.range(e.anchor,e.head)}static create(e,t,r){return new It(e,t,r)}}class S{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:S.create(this.ranges.map(r=>r.map(e,t)),this.mainIndex)}eq(e,t=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let r=0;r<this.ranges.length;r++)if(!this.ranges[r].eq(e.ranges[r],t))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new S([this.main],0)}addRange(e,t=!0){return S.create([e].concat(this.ranges),t?0:this.mainIndex+1)}replaceRange(e,t=this.mainIndex){let r=this.ranges.slice();return r[t]=e,S.create(r,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(e){if(!e||!Array.isArray(e.ranges)||typeof e.main!="number"||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new S(e.ranges.map(t=>It.fromJSON(t)),e.main)}static single(e,t=e){return new S([S.range(e,t)],0)}static create(e,t=0){if(e.length==0)throw new RangeError("A selection needs at least one range");for(let r=0,n=0;n<e.length;n++){let s=e[n];if(s.empty?s.from<=r:s.from<r)return S.normalized(e.slice(),t);r=s.to}return new S(e,t)}static cursor(e,t=0,r,n){return It.create(e,e,(t==0?0:t<0?8:16)|(r==null?7:Math.min(6,r))|(n??16777215)<<6)}static range(e,t,r,n,s){let o=(r??16777215)<<6|(n==null?7:Math.min(6,n));return!s&&e!=t&&(s=t<e?1:-1),t<e?It.create(t,e,48|o):It.create(e,t,(s?s<0?8:16:0)|o)}static normalized(e,t=0){let r=e[t];e.sort((n,s)=>n.from-s.from),t=e.indexOf(r);for(let n=1;n<e.length;n++){let s=e[n],o=e[n-1];if(s.empty?s.from<=o.to:s.from<o.to){let l=o.from,a=Math.max(s.to,o.to);n<=t&&t--,e.splice(--n,2,s.anchor>s.head?S.range(a,l):S.range(l,a))}}return new S(e,t)}}function sc(i,e){for(let t of i.ranges)if(t.to>e)throw new RangeError("Selection points outside of document")}let dl=0;class Z{constructor(e,t,r,n,s){this.combine=e,this.compareInput=t,this.compare=r,this.isStatic=n,this.id=dl++,this.default=e([]),this.extensions=typeof s=="function"?s(this):s}get reader(){return this}static define(e={}){return new Z(e.combine||(t=>t),e.compareInput||((t,r)=>t===r),e.compare||(e.combine?(t,r)=>t===r:pl),!!e.static,e.enables)}of(e){return new on([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new on(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new on(e,this,2,t)}from(e,t){return t||(t=r=>r),this.compute([e],r=>t(r.field(e)))}}function pl(i,e){return i==e||i.length==e.length&&i.every((t,r)=>t===e[r])}class on{constructor(e,t,r,n){this.dependencies=e,this.facet=t,this.type=r,this.value=n,this.id=dl++}dynamicSlot(e){var t;let r=this.value,n=this.facet.compareInput,s=this.id,o=e[s]>>1,l=this.type==2,a=!1,O=!1,h=[];for(let c of this.dependencies)c=="doc"?a=!0:c=="selection"?O=!0:(((t=e[c.id])!==null&&t!==void 0?t:1)&1)==0&&h.push(e[c.id]);return{create(c){return c.values[o]=r(c),1},update(c,f){if(a&&f.docChanged||O&&(f.docChanged||f.selection)||ao(c,h)){let u=r(c);if(l?!Qa(u,c.values[o],n):!n(u,c.values[o]))return c.values[o]=u,1}return 0},reconfigure:(c,f)=>{let u,p=f.config.address[s];if(p!=null){let m=gn(f,p);if(this.dependencies.every(g=>g instanceof Z?f.facet(g)===c.facet(g):g instanceof We?f.field(g,!1)==c.field(g,!1):!0)||(l?Qa(u=r(c),m,n):n(u=r(c),m)))return c.values[o]=m,0}else u=r(c);return c.values[o]=u,1}}}}function Qa(i,e,t){if(i.length!=e.length)return!1;for(let r=0;r<i.length;r++)if(!t(i[r],e[r]))return!1;return!0}function ao(i,e){let t=!1;for(let r of e)Ki(i,r)&1&&(t=!0);return t}function Pp(i,e,t){let r=t.map(a=>i[a.id]),n=t.map(a=>a.type),s=r.filter(a=>!(a&1)),o=i[e.id]>>1;function l(a){let O=[];for(let h=0;h<r.length;h++){let c=gn(a,r[h]);if(n[h]==2)for(let f of c)O.push(f);else O.push(c)}return e.combine(O)}return{create(a){for(let O of r)Ki(a,O);return a.values[o]=l(a),1},update(a,O){if(!ao(a,s))return 0;let h=l(a);return e.compare(h,a.values[o])?0:(a.values[o]=h,1)},reconfigure(a,O){let h=ao(a,r),c=O.config.facets[e.id],f=O.facet(e);if(c&&!h&&pl(t,c))return a.values[o]=f,0;let u=l(a);return e.compare(u,f)?(a.values[o]=f,0):(a.values[o]=u,1)}}}const Wr=Z.define({static:!0});class We{constructor(e,t,r,n,s){this.id=e,this.createF=t,this.updateF=r,this.compareF=n,this.spec=s,this.provides=void 0}static define(e){let t=new We(dl++,e.create,e.update,e.compare||((r,n)=>r===n),e);return e.provide&&(t.provides=e.provide(t)),t}create(e){let t=e.facet(Wr).find(r=>r.field==this);return((t==null?void 0:t.create)||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:r=>(r.values[t]=this.create(r),1),update:(r,n)=>{let s=r.values[t],o=this.updateF(s,n);return this.compareF(s,o)?0:(r.values[t]=o,1)},reconfigure:(r,n)=>{let s=r.facet(Wr),o=n.facet(Wr),l;return(l=s.find(a=>a.field==this))&&l!=o.find(a=>a.field==this)?(r.values[t]=l.create(r),1):n.config.address[this.id]!=null?(r.values[t]=n.field(this),0):(r.values[t]=this.create(r),1)}}}init(e){return[this,Wr.of({field:this,create:e})]}get extension(){return this}}const Bt={lowest:4,low:3,default:2,high:1,highest:0};function Ei(i){return e=>new oc(e,i)}const oi={highest:Ei(Bt.highest),high:Ei(Bt.high),default:Ei(Bt.default),low:Ei(Bt.low),lowest:Ei(Bt.lowest)};class oc{constructor(e,t){this.inner=e,this.prec=t}}class gt{of(e){return new Oo(this,e)}reconfigure(e){return gt.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}}class Oo{constructor(e,t){this.compartment=e,this.inner=t}}class mn{constructor(e,t,r,n,s,o){for(this.base=e,this.compartments=t,this.dynamicSlots=r,this.address=n,this.staticValues=s,this.facets=o,this.statusTemplate=[];this.statusTemplate.length<r.length;)this.statusTemplate.push(0)}staticFacet(e){let t=this.address[e.id];return t==null?e.default:this.staticValues[t>>1]}static resolve(e,t,r){let n=[],s=Object.create(null),o=new Map;for(let f of $p(e,t,o))f instanceof We?n.push(f):(s[f.facet.id]||(s[f.facet.id]=[])).push(f);let l=Object.create(null),a=[],O=[];for(let f of n)l[f.id]=O.length<<1,O.push(u=>f.slot(u));let h=r==null?void 0:r.config.facets;for(let f in s){let u=s[f],p=u[0].facet,m=h&&h[f]||[];if(u.every(g=>g.type==0))if(l[p.id]=a.length<<1|1,pl(m,u))a.push(r.facet(p));else{let g=p.combine(u.map(Q=>Q.value));a.push(r&&p.compare(g,r.facet(p))?r.facet(p):g)}else{for(let g of u)g.type==0?(l[g.id]=a.length<<1|1,a.push(g.value)):(l[g.id]=O.length<<1,O.push(Q=>g.dynamicSlot(Q)));l[p.id]=O.length<<1,O.push(g=>Pp(g,p,u))}}let c=O.map(f=>f(l));return new mn(e,o,c,l,a,s)}}function $p(i,e,t){let r=[[],[],[],[],[]],n=new Map;function s(o,l){let a=n.get(o);if(a!=null){if(a<=l)return;let O=r[a].indexOf(o);O>-1&&r[a].splice(O,1),o instanceof Oo&&t.delete(o.compartment)}if(n.set(o,l),Array.isArray(o))for(let O of o)s(O,l);else if(o instanceof Oo){if(t.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let O=e.get(o.compartment)||o.inner;t.set(o.compartment,O),s(O,l)}else if(o instanceof oc)s(o.inner,o.prec);else if(o instanceof We)r[l].push(o),o.provides&&s(o.provides,l);else if(o instanceof on)r[l].push(o),o.facet.extensions&&s(o.facet.extensions,Bt.default);else{let O=o.extension;if(!O)throw new Error(`Unrecognized extension value in extension set (${o}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);s(O,l)}}return s(i,Bt.default),r.reduce((o,l)=>o.concat(l))}function Ki(i,e){if(e&1)return 2;let t=e>>1,r=i.status[t];if(r==4)throw new Error("Cyclic dependency between fields and/or facets");if(r&2)return r;i.status[t]=4;let n=i.computeSlot(i,i.config.dynamicSlots[t]);return i.status[t]=2|n}function gn(i,e){return e&1?i.config.staticValues[e>>1]:i.values[e>>1]}const lc=Z.define(),ho=Z.define({combine:i=>i.some(e=>e),static:!0}),ac=Z.define({combine:i=>i.length?i[0]:void 0,static:!0}),Oc=Z.define(),hc=Z.define(),cc=Z.define(),fc=Z.define({combine:i=>i.length?i[0]:!1});class $t{constructor(e,t){this.type=e,this.value=t}static define(){return new wp}}class wp{of(e){return new $t(this,e)}}class vp{constructor(e){this.map=e}of(e){return new Y(this,e)}}class Y{constructor(e,t){this.type=e,this.value=t}map(e){let t=this.type.map(this.value,e);return t===void 0?void 0:t==this.value?this:new Y(this.type,t)}is(e){return this.type==e}static define(e={}){return new vp(e.map||(t=>t))}static mapEffects(e,t){if(!e.length)return e;let r=[];for(let n of e){let s=n.map(t);s&&r.push(s)}return r}}Y.reconfigure=Y.define();Y.appendConfig=Y.define();class ne{constructor(e,t,r,n,s,o){this.startState=e,this.changes=t,this.selection=r,this.effects=n,this.annotations=s,this.scrollIntoView=o,this._doc=null,this._state=null,r&&sc(r,t.newLength),s.some(l=>l.type==ne.time)||(this.annotations=s.concat(ne.time.of(Date.now())))}static create(e,t,r,n,s,o){return new ne(e,t,r,n,s,o)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(e){for(let t of this.annotations)if(t.type==e)return t.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(e){let t=this.annotation(ne.userEvent);return!!(t&&(t==e||t.length>e.length&&t.slice(0,e.length)==e&&t[e.length]=="."))}}ne.time=$t.define();ne.userEvent=$t.define();ne.addToHistory=$t.define();ne.remote=$t.define();function Tp(i,e){let t=[];for(let r=0,n=0;;){let s,o;if(r<i.length&&(n==e.length||e[n]>=i[r]))s=i[r++],o=i[r++];else if(n<e.length)s=e[n++],o=e[n++];else return t;!t.length||t[t.length-1]<s?t.push(s,o):t[t.length-1]<o&&(t[t.length-1]=o)}}function uc(i,e,t){var r;let n,s,o;return t?(n=e.changes,s=se.empty(e.changes.length),o=i.changes.compose(e.changes)):(n=e.changes.map(i.changes),s=i.changes.mapDesc(e.changes,!0),o=i.changes.compose(n)),{changes:o,selection:e.selection?e.selection.map(s):(r=i.selection)===null||r===void 0?void 0:r.map(n),effects:Y.mapEffects(i.effects,n).concat(Y.mapEffects(e.effects,s)),annotations:i.annotations.length?i.annotations.concat(e.annotations):e.annotations,scrollIntoView:i.scrollIntoView||e.scrollIntoView}}function co(i,e,t){let r=e.selection,n=Qi(e.annotations);return e.userEvent&&(n=n.concat(ne.userEvent.of(e.userEvent))),{changes:e.changes instanceof se?e.changes:se.of(e.changes||[],t,i.facet(ac)),selection:r&&(r instanceof S?r:S.single(r.anchor,r.head)),effects:Qi(e.effects),annotations:n,scrollIntoView:!!e.scrollIntoView}}function dc(i,e,t){let r=co(i,e.length?e[0]:{},i.doc.length);e.length&&e[0].filter===!1&&(t=!1);for(let s=1;s<e.length;s++){e[s].filter===!1&&(t=!1);let o=!!e[s].sequential;r=uc(r,co(i,e[s],o?r.changes.newLength:i.doc.length),o)}let n=ne.create(i,r.changes,r.selection,r.effects,r.annotations,r.scrollIntoView);return Zp(t?Xp(n):n)}function Xp(i){let e=i.startState,t=!0;for(let n of e.facet(Oc)){let s=n(i);if(s===!1){t=!1;break}Array.isArray(s)&&(t=t===!0?s:Tp(t,s))}if(t!==!0){let n,s;if(t===!1)s=i.changes.invertedDesc,n=se.empty(e.doc.length);else{let o=i.changes.filter(t);n=o.changes,s=o.filtered.mapDesc(o.changes).invertedDesc}i=ne.create(e,n,i.selection&&i.selection.map(s),Y.mapEffects(i.effects,s),i.annotations,i.scrollIntoView)}let r=e.facet(hc);for(let n=r.length-1;n>=0;n--){let s=r[n](i);s instanceof ne?i=s:Array.isArray(s)&&s.length==1&&s[0]instanceof ne?i=s[0]:i=dc(e,Qi(s),!1)}return i}function Zp(i){let e=i.startState,t=e.facet(cc),r=i;for(let n=t.length-1;n>=0;n--){let s=t[n](i);s&&Object.keys(s).length&&(r=uc(r,co(e,s,i.changes.newLength),!0))}return r==i?i:ne.create(e,i.changes,i.selection,r.effects,r.annotations,r.scrollIntoView)}const Rp=[];function Qi(i){return i==null?Rp:Array.isArray(i)?i:[i]}var re=(function(i){return i[i.Word=0]="Word",i[i.Space=1]="Space",i[i.Other=2]="Other",i})(re||(re={}));const Cp=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let fo;try{fo=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function qp(i){if(fo)return fo.test(i);for(let e=0;e<i.length;e++){let t=i[e];if(/\w/.test(t)||t>""&&(t.toUpperCase()!=t.toLowerCase()||Cp.test(t)))return!0}return!1}function Ap(i){return e=>{if(!/\S/.test(e))return re.Space;if(qp(e))return re.Word;for(let t=0;t<i.length;t++)if(e.indexOf(i[t])>-1)return re.Word;return re.Other}}class _{constructor(e,t,r,n,s,o){this.config=e,this.doc=t,this.selection=r,this.values=n,this.status=e.statusTemplate.slice(),this.computeSlot=s,o&&(o._state=this);for(let l=0;l<this.config.dynamicSlots.length;l++)Ki(this,l<<1);this.computeSlot=null}field(e,t=!0){let r=this.config.address[e.id];if(r==null){if(t)throw new RangeError("Field is not present in this state");return}return Ki(this,r),gn(this,r)}update(...e){return dc(this,e,!0)}applyTransaction(e){let t=this.config,{base:r,compartments:n}=t;for(let l of e.effects)l.is(gt.reconfigure)?(t&&(n=new Map,t.compartments.forEach((a,O)=>n.set(O,a)),t=null),n.set(l.value.compartment,l.value.extension)):l.is(Y.reconfigure)?(t=null,r=l.value):l.is(Y.appendConfig)&&(t=null,r=Qi(r).concat(l.value));let s;t?s=e.startState.values.slice():(t=mn.resolve(r,n,this),s=new _(t,this.doc,this.selection,t.dynamicSlots.map(()=>null),(a,O)=>O.reconfigure(a,this),null).values);let o=e.startState.facet(ho)?e.newSelection:e.newSelection.asSingle();new _(t,e.newDoc,o,s,(l,a)=>a.update(l,e),e)}replaceSelection(e){return typeof e=="string"&&(e=this.toText(e)),this.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:e},range:S.cursor(t.from+e.length)}))}changeByRange(e){let t=this.selection,r=e(t.ranges[0]),n=this.changes(r.changes),s=[r.range],o=Qi(r.effects);for(let l=1;l<t.ranges.length;l++){let a=e(t.ranges[l]),O=this.changes(a.changes),h=O.map(n);for(let f=0;f<l;f++)s[f]=s[f].map(h);let c=n.mapDesc(O,!0);s.push(a.range.map(c)),n=n.compose(h),o=Y.mapEffects(o,h).concat(Y.mapEffects(Qi(a.effects),c))}return{changes:n,selection:S.create(s,t.mainIndex),effects:o}}changes(e=[]){return e instanceof se?e:se.of(e,this.doc.length,this.facet(_.lineSeparator))}toText(e){return E.of(e.split(this.facet(_.lineSeparator)||so))}sliceDoc(e=0,t=this.doc.length){return this.doc.sliceString(e,t,this.lineBreak)}facet(e){let t=this.config.address[e.id];return t==null?e.default:(Ki(this,t),gn(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let r in e){let n=e[r];n instanceof We&&this.config.address[n.id]!=null&&(t[r]=n.spec.toJSON(this.field(e[r]),this))}return t}static fromJSON(e,t={},r){if(!e||typeof e.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let n=[];if(r){for(let s in r)if(Object.prototype.hasOwnProperty.call(e,s)){let o=r[s],l=e[s];n.push(o.init(a=>o.spec.fromJSON(l,a)))}}return _.create({doc:e.doc,selection:S.fromJSON(e.selection),extensions:t.extensions?n.concat([t.extensions]):n})}static create(e={}){let t=mn.resolve(e.extensions||[],new Map),r=e.doc instanceof E?e.doc:E.of((e.doc||"").split(t.staticFacet(_.lineSeparator)||so)),n=e.selection?e.selection instanceof S?e.selection:S.single(e.selection.anchor,e.selection.head):S.single(0);return sc(n,r.length),t.staticFacet(ho)||(n=n.asSingle()),new _(t,r,n,t.dynamicSlots.map(()=>null),(s,o)=>o.create(s),null)}get tabSize(){return this.facet(_.tabSize)}get lineBreak(){return this.facet(_.lineSeparator)||`
|