@bigmistqke/workpad 0.0.0-stage → 0.18.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/LICENSE +21 -0
- package/README.md +781 -2
- package/bin/workpad.ts +1526 -0
- package/dist/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/taggedTemplateLiteral.js +5 -0
- package/dist/bin/workpad.js +1202 -0
- package/dist/client/runtime.js +1194 -0
- package/dist/define.js +27 -0
- package/dist/plugins/alert/README.md +18 -0
- package/dist/plugins/alert/index.js +40 -0
- package/dist/plugins/alert/public/style.css +40 -0
- package/dist/plugins/ansi/README.md +36 -0
- package/dist/plugins/ansi/index.js +63 -0
- package/dist/plugins/ansi/public/style.css +28 -0
- package/dist/plugins/badge/README.md +32 -0
- package/dist/plugins/badge/index.js +28 -0
- package/dist/plugins/badge/public/style.css +30 -0
- package/dist/plugins/chat/README.md +81 -0
- package/dist/plugins/chat/index.js +96 -0
- package/dist/plugins/chat/public/client.js +3 -0
- package/dist/plugins/chat/public/style.css +143 -0
- package/dist/plugins/claude/README.md +116 -0
- package/dist/plugins/claude/channel.js +130 -0
- package/dist/plugins/claude/doctor.js +316 -0
- package/dist/plugins/claude/index.js +199 -0
- package/dist/plugins/claude/session.js +68 -0
- package/dist/plugins/code/README.md +54 -0
- package/dist/plugins/code/diff.js +75 -0
- package/dist/plugins/code/index.js +105 -0
- package/dist/plugins/code/public/client.js +1 -0
- package/dist/plugins/code/public/style.css +99 -0
- package/dist/plugins/comments/README.md +30 -0
- package/dist/plugins/comments/index.js +39 -0
- package/dist/plugins/comments/public/client.js +24 -0
- package/dist/plugins/comments/public/style.css +224 -0
- package/dist/plugins/details/README.md +24 -0
- package/dist/plugins/details/index.js +28 -0
- package/dist/plugins/details/public/style.css +7 -0
- package/dist/plugins/draft/README.md +14 -0
- package/dist/plugins/draft/index.js +27 -0
- package/dist/plugins/draft/public/style.css +21 -0
- package/dist/plugins/forge/README.md +22 -0
- package/dist/plugins/forge/index.js +83 -0
- package/dist/plugins/form/README.md +126 -0
- package/dist/plugins/form/index.js +179 -0
- package/dist/plugins/form/public/style.css +172 -0
- package/dist/plugins/grid/README.md +45 -0
- package/dist/plugins/grid/index.js +35 -0
- package/dist/plugins/grid/public/style.css +98 -0
- package/dist/plugins/iframe/README.md +18 -0
- package/dist/plugins/iframe/index.js +49 -0
- package/dist/plugins/iframe/public/style.css +28 -0
- package/dist/plugins/index.js +44 -0
- package/dist/plugins/lightbox/README.md +24 -0
- package/dist/plugins/lightbox/index.js +20 -0
- package/dist/plugins/lightbox/public/client.js +4 -0
- package/dist/plugins/lightbox/public/style.css +66 -0
- package/dist/plugins/mermaid/README.md +21 -0
- package/dist/plugins/mermaid/index.js +42 -0
- package/dist/plugins/mermaid/public/style.css +21 -0
- package/dist/plugins/opencode/README.md +48 -0
- package/dist/plugins/opencode/channel.js +92 -0
- package/dist/plugins/opencode/index.js +64 -0
- package/dist/plugins/opencode/shim.js +150 -0
- package/dist/plugins/quiet/README.md +26 -0
- package/dist/plugins/quiet/index.js +23 -0
- package/dist/plugins/tabs/README.md +44 -0
- package/dist/plugins/tabs/index.js +75 -0
- package/dist/plugins/tabs/public/client.js +1 -0
- package/dist/plugins/tabs/public/style.css +98 -0
- package/dist/plugins/terminal/README.md +63 -0
- package/dist/plugins/terminal/host.js +338 -0
- package/dist/plugins/terminal/index.js +170 -0
- package/dist/plugins/terminal/modes.js +32 -0
- package/dist/plugins/terminal/public/client.js +41 -0
- package/dist/plugins/terminal/public/style.css +511 -0
- package/dist/plugins/terminal/server.js +256 -0
- package/dist/plugins/terminal/sizes.js +58 -0
- package/dist/plugins/timeline/README.md +48 -0
- package/dist/plugins/timeline/index.js +83 -0
- package/dist/plugins/timeline/public/style.css +138 -0
- package/dist/plugins/toc/README.md +40 -0
- package/dist/plugins/toc/index.js +29 -0
- package/dist/plugins/toc/public/client.js +1 -0
- package/dist/plugins/toc/public/style.css +117 -0
- package/dist/plugins/window/README.md +51 -0
- package/dist/plugins/window/index.js +91 -0
- package/dist/solid/index.js +41 -0
- package/dist/src/agents.js +81 -0
- package/dist/src/anchors.js +52 -0
- package/dist/src/api.js +282 -0
- package/dist/src/archive.js +49 -0
- package/dist/src/auth.js +67 -0
- package/dist/src/build.js +159 -0
- package/dist/src/client/page/base.css +1762 -0
- package/dist/src/client/page/main.js +2121 -0
- package/dist/src/config.js +76 -0
- package/dist/src/document.js +93 -0
- package/dist/src/entries.js +264 -0
- package/dist/src/events.js +322 -0
- package/dist/src/files.js +47 -0
- package/dist/src/formstate.js +65 -0
- package/dist/src/help.js +213 -0
- package/dist/src/html.js +34 -0
- package/dist/src/hub.js +348 -0
- package/dist/src/icons.js +6 -0
- package/dist/src/listen.js +132 -0
- package/dist/src/listeners.js +64 -0
- package/dist/src/load.js +81 -0
- package/dist/src/loader.js +179 -0
- package/dist/src/migrate.js +314 -0
- package/dist/src/package.js +52 -0
- package/dist/src/pages/blocks.js +67 -0
- package/dist/src/pages/board.js +59 -0
- package/dist/src/pages/index.js +27 -0
- package/dist/src/pages/markdown.js +863 -0
- package/dist/src/pages/render.js +761 -0
- package/dist/src/pages/window.js +29 -0
- package/dist/src/plugins.js +283 -0
- package/dist/src/public.js +24 -0
- package/dist/src/rename.js +130 -0
- package/dist/src/running.js +146 -0
- package/dist/src/serve.js +188 -0
- package/dist/src/server.js +1105 -0
- package/dist/src/site.js +179 -0
- package/dist/src/state.js +155 -0
- package/dist/src/status.js +323 -0
- package/dist/src/thread.js +68 -0
- package/dist/src/watchdog.js +38 -0
- package/dist/src/ws.js +128 -0
- package/package.json +154 -4
- package/plugins/README.md +304 -0
- package/plugins/alert/README.md +18 -0
- package/plugins/alert/index.ts +50 -0
- package/plugins/alert/public/style.css +40 -0
- package/plugins/ansi/README.md +36 -0
- package/plugins/ansi/index.ts +95 -0
- package/plugins/ansi/public/style.css +28 -0
- package/plugins/badge/README.md +32 -0
- package/plugins/badge/index.ts +36 -0
- package/plugins/badge/public/style.css +30 -0
- package/plugins/chat/README.md +81 -0
- package/plugins/chat/autosize.ts +139 -0
- package/plugins/chat/client.tsx +187 -0
- package/plugins/chat/index.ts +146 -0
- package/plugins/chat/public/style.css +143 -0
- package/plugins/claude/README.md +116 -0
- package/plugins/claude/channel.ts +136 -0
- package/plugins/claude/doctor.ts +274 -0
- package/plugins/claude/index.ts +248 -0
- package/plugins/claude/session.ts +70 -0
- package/plugins/code/README.md +54 -0
- package/plugins/code/client.ts +73 -0
- package/plugins/code/diff.ts +96 -0
- package/plugins/code/index.ts +136 -0
- package/plugins/code/public/style.css +99 -0
- package/plugins/comments/README.md +30 -0
- package/plugins/comments/client.ts +723 -0
- package/plugins/comments/index.ts +48 -0
- package/plugins/comments/public/style.css +224 -0
- package/plugins/details/README.md +24 -0
- package/plugins/details/index.ts +30 -0
- package/plugins/details/public/style.css +7 -0
- package/plugins/draft/README.md +14 -0
- package/plugins/draft/index.ts +23 -0
- package/plugins/draft/public/style.css +21 -0
- package/plugins/forge/README.md +22 -0
- package/plugins/forge/index.ts +84 -0
- package/plugins/form/README.md +126 -0
- package/plugins/form/index.ts +199 -0
- package/plugins/form/public/style.css +172 -0
- package/plugins/grid/README.md +45 -0
- package/plugins/grid/index.ts +41 -0
- package/plugins/grid/public/style.css +98 -0
- package/plugins/iframe/README.md +18 -0
- package/plugins/iframe/index.ts +53 -0
- package/plugins/iframe/public/style.css +28 -0
- package/plugins/index.ts +49 -0
- package/plugins/lightbox/README.md +24 -0
- package/plugins/lightbox/client.ts +109 -0
- package/plugins/lightbox/index.ts +25 -0
- package/plugins/lightbox/public/style.css +66 -0
- package/plugins/mermaid/README.md +21 -0
- package/plugins/mermaid/index.ts +46 -0
- package/plugins/mermaid/public/style.css +21 -0
- package/plugins/opencode/README.md +48 -0
- package/plugins/opencode/channel.ts +112 -0
- package/plugins/opencode/index.ts +91 -0
- package/plugins/opencode/shim.ts +166 -0
- package/plugins/quiet/README.md +26 -0
- package/plugins/quiet/index.ts +28 -0
- package/plugins/tabs/README.md +44 -0
- package/plugins/tabs/client.ts +96 -0
- package/plugins/tabs/index.ts +103 -0
- package/plugins/tabs/public/style.css +98 -0
- package/plugins/terminal/README.md +63 -0
- package/plugins/terminal/client.ts +391 -0
- package/plugins/terminal/host.ts +434 -0
- package/plugins/terminal/index.ts +199 -0
- package/plugins/terminal/modes.ts +30 -0
- package/plugins/terminal/public/style.css +225 -0
- package/plugins/terminal/server.ts +266 -0
- package/plugins/terminal/sizes.ts +72 -0
- package/plugins/timeline/README.md +48 -0
- package/plugins/timeline/index.ts +82 -0
- package/plugins/timeline/public/style.css +138 -0
- package/plugins/toc/README.md +40 -0
- package/plugins/toc/client.ts +236 -0
- package/plugins/toc/index.ts +55 -0
- package/plugins/toc/public/style.css +117 -0
- package/plugins/window/README.md +51 -0
- package/plugins/window/index.ts +92 -0
- package/skills/workpad/SKILL.md +592 -0
- package/solid/index.tsx +80 -0
- package/src/agents.ts +134 -0
- package/src/anchors.ts +85 -0
- package/src/api.ts +444 -0
- package/src/archive.ts +75 -0
- package/src/auth.ts +99 -0
- package/src/build.ts +213 -0
- package/src/client/base.ts +19 -0
- package/src/client/forms.ts +420 -0
- package/src/client/markdown.ts +147 -0
- package/src/client/page/base.css +1762 -0
- package/src/client/page/board.ts +166 -0
- package/src/client/page/elsewhere.ts +153 -0
- package/src/client/page/fresh.ts +343 -0
- package/src/client/page/heading-link.ts +32 -0
- package/src/client/page/live.ts +134 -0
- package/src/client/page/main.ts +398 -0
- package/src/client/page/orphans.ts +64 -0
- package/src/client/page/place.ts +260 -0
- package/src/client/page/sort.ts +49 -0
- package/src/client/page/sticky.ts +58 -0
- package/src/client/page/theme.ts +36 -0
- package/src/client/page/view.ts +9 -0
- package/src/client/page/waiting.ts +278 -0
- package/src/client/page/window.ts +40 -0
- package/src/client/reactive.ts +19 -0
- package/src/client/read.ts +111 -0
- package/src/client/runtime.ts +499 -0
- package/src/client/scroll.ts +90 -0
- package/src/client/toast.ts +99 -0
- package/src/config.ts +111 -0
- package/src/define.ts +997 -0
- package/src/document.ts +191 -0
- package/src/entries.ts +352 -0
- package/src/events.ts +463 -0
- package/src/files.ts +74 -0
- package/src/formstate.ts +72 -0
- package/src/help.ts +240 -0
- package/src/html.ts +44 -0
- package/src/hub.ts +435 -0
- package/src/icons.ts +18 -0
- package/src/listen.ts +171 -0
- package/src/listeners.ts +89 -0
- package/src/load.ts +113 -0
- package/src/loader.ts +227 -0
- package/src/migrate.ts +352 -0
- package/src/package.ts +62 -0
- package/src/pages/blocks.ts +106 -0
- package/src/pages/board.ts +89 -0
- package/src/pages/index.ts +79 -0
- package/src/pages/markdown.ts +976 -0
- package/src/pages/render.ts +845 -0
- package/src/pages/window.ts +69 -0
- package/src/plugins.ts +319 -0
- package/src/public.ts +39 -0
- package/src/rename.ts +147 -0
- package/src/running.ts +171 -0
- package/src/serve.ts +221 -0
- package/src/server.ts +1385 -0
- package/src/site.ts +170 -0
- package/src/state.ts +327 -0
- package/src/status.ts +466 -0
- package/src/thread.ts +98 -0
- package/src/watchdog.ts +53 -0
- package/src/ws.ts +155 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { DEFAULT_PORT } from "./config.js";
|
|
2
|
+
import { createServer } from "./server.js";
|
|
3
|
+
import { watchServer, watchStalls } from "./watchdog.js";
|
|
4
|
+
import { alive, recordedPid, recordedPort, recordedSharedPort, runningServer, sharedServer } from "./running.js";
|
|
5
|
+
import { listenHost, machineConfigFile, machineDir, machineServerFile, readMachineConfig, serverUrl, stateDir } from "./entries.js";
|
|
6
|
+
import { createHub } from "./hub.js";
|
|
7
|
+
import { VERSION, compareVersions } from "./package.js";
|
|
8
|
+
import fs from "node:fs";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import http from "node:http";
|
|
11
|
+
// src/serve.ts
|
|
12
|
+
/** Listen on the previous port, else the default, else the next free one; then record it in server.json. */
|
|
13
|
+
async function start(project) {
|
|
14
|
+
const other = await runningServer(project, { except: process.pid });
|
|
15
|
+
if (other) {
|
|
16
|
+
console.log(`workpad: ${project.name} is already served at ${other}`);
|
|
17
|
+
process.exit(0);
|
|
18
|
+
}
|
|
19
|
+
const recorded = recordedPid(project);
|
|
20
|
+
if (recorded && recorded !== process.pid && alive(recorded)) {
|
|
21
|
+
console.log(`workpad: ${project.name} is already served by pid ${recorded}, which doesn't answer yet`);
|
|
22
|
+
process.exit(0);
|
|
23
|
+
}
|
|
24
|
+
fs.mkdirSync(project.pagesDir, { recursive: true });
|
|
25
|
+
const machine = readMachineConfig();
|
|
26
|
+
const host = listenHost(machine);
|
|
27
|
+
const origins = machine?.origins ?? [];
|
|
28
|
+
const url = serverUrl(null);
|
|
29
|
+
const wp = createServer(project, { origins: () => origins });
|
|
30
|
+
await wp.config();
|
|
31
|
+
const server = http.createServer((req, res) => {
|
|
32
|
+
wp.handle(req, res);
|
|
33
|
+
});
|
|
34
|
+
server.on("upgrade", (req, conn, head) => wp.upgrade(req, conn, head));
|
|
35
|
+
const candidates = [...new Set([
|
|
36
|
+
recordedPort(project),
|
|
37
|
+
DEFAULT_PORT,
|
|
38
|
+
...Array.from({ length: 50 }, (_, i) => DEFAULT_PORT + 1 + i)
|
|
39
|
+
].filter((p) => !!p))];
|
|
40
|
+
for (const port of candidates) {
|
|
41
|
+
if (!await listenOn(server, port, host)) continue;
|
|
42
|
+
fs.writeFileSync(project.serverFile, JSON.stringify({
|
|
43
|
+
port,
|
|
44
|
+
pid: process.pid,
|
|
45
|
+
...url && { url }
|
|
46
|
+
}, null, 2) + "\n");
|
|
47
|
+
watchServer(server);
|
|
48
|
+
watchStalls();
|
|
49
|
+
try {
|
|
50
|
+
fs.unlinkSync(path.join(project.wp, "server.lock"));
|
|
51
|
+
} catch {}
|
|
52
|
+
const cleanup = () => {
|
|
53
|
+
try {
|
|
54
|
+
if (JSON.parse(fs.readFileSync(project.serverFile, "utf8")).pid === process.pid) fs.unlinkSync(project.serverFile);
|
|
55
|
+
} catch {}
|
|
56
|
+
};
|
|
57
|
+
process.on("exit", cleanup);
|
|
58
|
+
const yieldToOther = async () => {
|
|
59
|
+
if (await runningServer(project, { except: process.pid })) {
|
|
60
|
+
console.log("workpad: another server of this project took over");
|
|
61
|
+
process.exit(0);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
setTimeout(yieldToOther, 1500).unref();
|
|
65
|
+
setInterval(yieldToOther, 3e4).unref();
|
|
66
|
+
for (const signal of [
|
|
67
|
+
"SIGINT",
|
|
68
|
+
"SIGTERM",
|
|
69
|
+
"SIGHUP"
|
|
70
|
+
]) process.on(signal, () => process.exit(0));
|
|
71
|
+
console.log(`workpad: ${project.name} (${project.dir}) at ${url ?? `http://localhost:${port}`}`);
|
|
72
|
+
return port;
|
|
73
|
+
}
|
|
74
|
+
throw new Error(`no free port from ${DEFAULT_PORT} to ${DEFAULT_PORT + 50}`);
|
|
75
|
+
}
|
|
76
|
+
/** Run the shared server. Exits (0) when one as new or newer runs already. */
|
|
77
|
+
async function startShared(dir = machineDir(), state = stateDir()) {
|
|
78
|
+
const file = machineServerFile(state);
|
|
79
|
+
const other = await sharedServer(file, { except: process.pid });
|
|
80
|
+
if (other) {
|
|
81
|
+
if (compareVersions(VERSION, other.version) <= 0) {
|
|
82
|
+
console.log(`workpad: the shared server ${other.version} runs at ${other.origin}`);
|
|
83
|
+
process.exit(0);
|
|
84
|
+
}
|
|
85
|
+
await takeOver(other);
|
|
86
|
+
}
|
|
87
|
+
const config = readMachineConfig(dir);
|
|
88
|
+
if (!config) throw new Error(`no machine config: ${machineConfigFile(dir)}`);
|
|
89
|
+
const url = serverUrl(config);
|
|
90
|
+
fs.mkdirSync(state, { recursive: true });
|
|
91
|
+
const hub = createHub({
|
|
92
|
+
dir,
|
|
93
|
+
state,
|
|
94
|
+
onShutdown: () => process.exit(0)
|
|
95
|
+
});
|
|
96
|
+
const server = http.createServer((req, res) => {
|
|
97
|
+
hub.handle(req, res);
|
|
98
|
+
});
|
|
99
|
+
server.on("upgrade", (req, conn, head) => hub.upgrade(req, conn, head));
|
|
100
|
+
const first = config.port ?? DEFAULT_PORT;
|
|
101
|
+
const candidates = [...new Set([
|
|
102
|
+
other ? Number(new URL(other.origin).port) : null,
|
|
103
|
+
recordedSharedPort(file),
|
|
104
|
+
first,
|
|
105
|
+
...Array.from({ length: 50 }, (_, i) => first + 1 + i)
|
|
106
|
+
].filter((p) => !!p))];
|
|
107
|
+
for (const port of candidates) {
|
|
108
|
+
if (!await listenOn(server, port, listenHost(config))) continue;
|
|
109
|
+
fs.writeFileSync(file, JSON.stringify({
|
|
110
|
+
port,
|
|
111
|
+
pid: process.pid,
|
|
112
|
+
version: VERSION,
|
|
113
|
+
...url && { url }
|
|
114
|
+
}, null, 2) + "\n");
|
|
115
|
+
watchServer(server);
|
|
116
|
+
watchStalls();
|
|
117
|
+
try {
|
|
118
|
+
fs.unlinkSync(path.join(state, "server.lock"));
|
|
119
|
+
} catch {}
|
|
120
|
+
process.on("exit", () => {
|
|
121
|
+
try {
|
|
122
|
+
if (JSON.parse(fs.readFileSync(file, "utf8")).pid === process.pid) fs.unlinkSync(file);
|
|
123
|
+
} catch {}
|
|
124
|
+
});
|
|
125
|
+
const yieldToOther = async () => {
|
|
126
|
+
if (await sharedServer(file, { except: process.pid })) {
|
|
127
|
+
console.log("workpad: another shared server took over");
|
|
128
|
+
process.exit(0);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
setTimeout(yieldToOther, 1500).unref();
|
|
132
|
+
setInterval(yieldToOther, 3e4).unref();
|
|
133
|
+
for (const signal of [
|
|
134
|
+
"SIGINT",
|
|
135
|
+
"SIGTERM",
|
|
136
|
+
"SIGHUP"
|
|
137
|
+
]) process.on(signal, () => process.exit(0));
|
|
138
|
+
const origin = url ?? `http://localhost:${port}`;
|
|
139
|
+
console.log(`workpad ${VERSION}: the shared server at ${origin}`);
|
|
140
|
+
for (const p of hub.projects()) console.log(` ${origin}${p.base}/ ${p.dir}`);
|
|
141
|
+
return port;
|
|
142
|
+
}
|
|
143
|
+
throw new Error(`no free port from ${first} to ${first + 50}`);
|
|
144
|
+
}
|
|
145
|
+
/** Ask an older shared server to make way, and wait until it has (else end its process). */
|
|
146
|
+
async function takeOver(other) {
|
|
147
|
+
console.log(`workpad ${VERSION}: taking over from the shared server ${other.version} at ${other.origin}`);
|
|
148
|
+
try {
|
|
149
|
+
await fetch(`${other.origin}/api/shutdown`, {
|
|
150
|
+
method: "POST",
|
|
151
|
+
headers: { "content-type": "application/json" },
|
|
152
|
+
body: JSON.stringify({ version: VERSION }),
|
|
153
|
+
signal: AbortSignal.timeout(2e3)
|
|
154
|
+
});
|
|
155
|
+
} catch {}
|
|
156
|
+
const gone = async () => {
|
|
157
|
+
try {
|
|
158
|
+
await fetch(`${other.origin}/api/health`, { signal: AbortSignal.timeout(300) });
|
|
159
|
+
return false;
|
|
160
|
+
} catch {
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
for (let i = 0; i < 25; i++) {
|
|
165
|
+
if (await gone()) return;
|
|
166
|
+
await new Promise((r) => setTimeout(r, 200));
|
|
167
|
+
}
|
|
168
|
+
try {
|
|
169
|
+
process.kill(other.pid, "SIGTERM");
|
|
170
|
+
} catch {}
|
|
171
|
+
for (let i = 0; i < 25 && !await gone(); i++) await new Promise((r) => setTimeout(r, 200));
|
|
172
|
+
}
|
|
173
|
+
function listenOn(server, port, host) {
|
|
174
|
+
return new Promise((resolve, reject) => {
|
|
175
|
+
const onError = (err) => {
|
|
176
|
+
server.off("listening", onListening);
|
|
177
|
+
err.code === "EADDRINUSE" ? resolve(false) : reject(err);
|
|
178
|
+
};
|
|
179
|
+
const onListening = () => {
|
|
180
|
+
server.off("error", onError);
|
|
181
|
+
resolve(true);
|
|
182
|
+
};
|
|
183
|
+
server.once("error", onError);
|
|
184
|
+
server.once("listening", onListening);
|
|
185
|
+
server.listen(port, host);
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
export { start, startShared };
|