slateboard 0.0.0-stage → 0.1.0

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.
Files changed (53) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +217 -2
  3. package/dist/bin.js +363 -0
  4. package/dist/chunk-3TOSW3FU.js +83 -0
  5. package/dist/chunk-3ZLMW2RI.js +74 -0
  6. package/dist/chunk-7GQK2VEN.js +44 -0
  7. package/dist/chunk-BWNUX4FT.js +65 -0
  8. package/dist/chunk-FMO5B2KJ.js +142 -0
  9. package/dist/chunk-FNBCYJA2.js +44 -0
  10. package/dist/chunk-GD6AEWOM.js +16028 -0
  11. package/dist/chunk-I5SMACZY.js +27 -0
  12. package/dist/chunk-KPOE4I3O.js +47 -0
  13. package/dist/chunk-LDIOPHXZ.js +269 -0
  14. package/dist/chunk-MKT3PGWK.js +43 -0
  15. package/dist/chunk-ONZFKR4I.js +6726 -0
  16. package/dist/chunk-SQHGMBUM.js +2499 -0
  17. package/dist/chunk-TCKAXJOM.js +9 -0
  18. package/dist/chunk-WKKEXOKW.js +19712 -0
  19. package/dist/chunk-WXM4BB4D.js +10706 -0
  20. package/dist/client-JHI2EG6J.js +286 -0
  21. package/dist/commands-ONES545N.js +21 -0
  22. package/dist/daemon-PALF5CS6.js +17 -0
  23. package/dist/doctor-H5Y5L2JZ.js +148 -0
  24. package/dist/hooks-2TI5OLAU.js +21 -0
  25. package/dist/http-APU3FWKO.js +13 -0
  26. package/dist/isomorphic-git-BZUKICXS.js +18761 -0
  27. package/dist/lifecycle-ZB5HEO5P.js +29 -0
  28. package/dist/local-6MC4LZJK.js +28 -0
  29. package/dist/service-FAEKZ3X2.js +15 -0
  30. package/dist/service-command-26BPMBK3.js +100 -0
  31. package/dist/src-QZIVUACM.js +69 -0
  32. package/dist/src-YVFB3ZLM.js +175 -0
  33. package/dist/ui/apple-touch-icon.png +0 -0
  34. package/dist/ui/assets/atkinson-hyperlegible-mono-latin-ext-wght-normal-CXgNM06D.woff2 +0 -0
  35. package/dist/ui/assets/atkinson-hyperlegible-mono-latin-wght-normal-CoA7y8X5.woff2 +0 -0
  36. package/dist/ui/assets/atkinson-hyperlegible-next-latin-ext-wght-normal-C6vrW8VD.woff2 +0 -0
  37. package/dist/ui/assets/atkinson-hyperlegible-next-latin-wght-normal-BcXVPD7q.woff2 +0 -0
  38. package/dist/ui/assets/index-4WzXlYHs.css +1 -0
  39. package/dist/ui/assets/index-ZKfByx7Q.js +42 -0
  40. package/dist/ui/favicon.ico +0 -0
  41. package/dist/ui/favicon.svg +1 -0
  42. package/dist/ui/icon-192.png +0 -0
  43. package/dist/ui/icon-512.png +0 -0
  44. package/dist/ui/icon-maskable-512.png +0 -0
  45. package/dist/ui/index.html +25 -0
  46. package/dist/ui/manifest.webmanifest +13 -0
  47. package/dist/upgrade-FND3UBJR.js +213 -0
  48. package/migrations/0001_init.sql +75 -0
  49. package/migrations/0002_item_keys.sql +23 -0
  50. package/migrations/0003_item_claims.sql +4 -0
  51. package/migrations/0004_git_transitions.sql +2 -0
  52. package/migrations/0005_roadmap_file.sql +4 -0
  53. package/package.json +38 -4
@@ -0,0 +1,74 @@
1
+ import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+ import {
3
+ run
4
+ } from "./chunk-I5SMACZY.js";
5
+
6
+ // src/hooks.ts
7
+ import { chmodSync, existsSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
8
+ import path from "node:path";
9
+ var HOOK = "commit-msg";
10
+ var MARKER = "# slate commit-msg hook";
11
+ var CHAINED = `${HOOK}.slate-chained`;
12
+ var HOOK_SCRIPT = `#!/bin/sh
13
+ ${MARKER} (slate hooks install; remove with slate hooks uninstall).
14
+ # On a slate/<KEY>-... branch, adds "slate: <KEY>" to the message unless it already names <KEY>.
15
+ chained="$(dirname "$0")/${CHAINED}"
16
+ if [ -x "$chained" ]; then "$chained" "$@" || exit $?; fi
17
+ msg="$1"
18
+ # Merges keep their message.
19
+ [ -f "$(git rev-parse --git-path MERGE_HEAD)" ] && exit 0
20
+ branch=$(git symbolic-ref --short -q HEAD) || exit 0
21
+ key=$(printf '%s\\n' "$branch" | sed -n 's#^slate/\\([A-Za-z][A-Za-z]*-[0-9][0-9]*\\).*$#\\1#p' | tr '[:lower:]' '[:upper:]')
22
+ [ -n "$key" ] || exit 0
23
+ # Nothing written (git aborts empty messages) or the key is already there: leave it alone.
24
+ body=$(grep -v '^#' "$msg" | tr -d '[:space:]')
25
+ [ -n "$body" ] || exit 0
26
+ grep -v '^#' "$msg" | grep -qiE "(^|[^A-Za-z0-9_-])$key([^A-Za-z0-9_-]|$)" && exit 0
27
+ git interpret-trailers --in-place --trailer "slate: $key" "$msg"
28
+ `;
29
+ async function hooksDir(cwd, git = run) {
30
+ const result = await git("git", ["-C", cwd, "rev-parse", "--path-format=absolute", "--git-path", "hooks"]);
31
+ if (result.code !== 0) throw new Error(`${cwd} is not in a git repository`);
32
+ return result.stdout.trim();
33
+ }
34
+ var isOurs = (file) => existsSync(file) && readFileSync(file, "utf8").includes(MARKER);
35
+ async function hookInstalled(cwd, git = run) {
36
+ return isOurs(path.join(await hooksDir(cwd, git), HOOK));
37
+ }
38
+ async function installHook(cwd, git = run) {
39
+ const dir = await hooksDir(cwd, git);
40
+ const file = path.join(dir, HOOK);
41
+ const lines = [];
42
+ if (existsSync(file) && !isOurs(file)) {
43
+ if (existsSync(path.join(dir, CHAINED))) throw new Error(`${file} is not slate's and ${CHAINED} already exists; merge them by hand`);
44
+ renameSync(file, path.join(dir, CHAINED));
45
+ lines.push(`kept the existing ${HOOK} hook as ${CHAINED}; it runs first`);
46
+ }
47
+ const fresh = !isOurs(file);
48
+ writeFileSync(file, HOOK_SCRIPT);
49
+ chmodSync(file, 493);
50
+ lines.unshift(fresh ? `installed ${file}` : `updated ${file}`);
51
+ return lines;
52
+ }
53
+ async function uninstallHook(cwd, git = run) {
54
+ const dir = await hooksDir(cwd, git);
55
+ const file = path.join(dir, HOOK);
56
+ if (!isOurs(file)) return [`no slate ${HOOK} hook in ${dir}`];
57
+ rmSync(file);
58
+ const chained = path.join(dir, CHAINED);
59
+ if (existsSync(chained)) {
60
+ renameSync(chained, file);
61
+ return [`removed slate's hook; restored the previous ${HOOK} hook`];
62
+ }
63
+ return [`removed ${file}`];
64
+ }
65
+
66
+ export {
67
+ HOOK,
68
+ MARKER,
69
+ HOOK_SCRIPT,
70
+ hooksDir,
71
+ hookInstalled,
72
+ installHook,
73
+ uninstallHook
74
+ };
@@ -0,0 +1,44 @@
1
+ import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+ import {
3
+ baseUrl
4
+ } from "./chunk-3TOSW3FU.js";
5
+
6
+ // src/http.ts
7
+ var ApiError = class extends Error {
8
+ constructor(message, code, status) {
9
+ super(message);
10
+ this.code = code;
11
+ this.status = status;
12
+ }
13
+ code;
14
+ status;
15
+ };
16
+ async function request(port, method, path, body) {
17
+ const res = await fetch(`${baseUrl(port)}/api${path}`, {
18
+ method,
19
+ headers: body === void 0 ? {} : { "content-type": "application/json" },
20
+ ...body === void 0 ? {} : { body: JSON.stringify(body) },
21
+ signal: AbortSignal.timeout(3e4)
22
+ });
23
+ if (!res.ok) {
24
+ let error = {};
25
+ try {
26
+ error = (await res.json()).error ?? {};
27
+ } catch {
28
+ }
29
+ throw new ApiError(error.message ?? `${method} ${path} answered ${res.status}`, error.code ?? "http", res.status);
30
+ }
31
+ return res;
32
+ }
33
+ async function api(port, method, path, body) {
34
+ return await (await request(port, method, path, body)).json();
35
+ }
36
+ async function apiText(port, path) {
37
+ return (await request(port, "GET", path)).text();
38
+ }
39
+
40
+ export {
41
+ ApiError,
42
+ api,
43
+ apiText
44
+ };
@@ -0,0 +1,65 @@
1
+ import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+ import {
3
+ Store,
4
+ createServices
5
+ } from "./chunk-WXM4BB4D.js";
6
+ import {
7
+ dbFile
8
+ } from "./chunk-3TOSW3FU.js";
9
+
10
+ // src/readonly.ts
11
+ import { existsSync, mkdtempSync, rmSync } from "node:fs";
12
+ import { tmpdir } from "node:os";
13
+ import path from "node:path";
14
+ import { DatabaseSync } from "node:sqlite";
15
+ function openReadOnly(file) {
16
+ return new DatabaseSync(file, { readOnly: true });
17
+ }
18
+ function schemaVersionOf(db) {
19
+ const hasMeta = db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'meta'").get();
20
+ if (!hasMeta) return 0;
21
+ const row = db.prepare("SELECT value FROM meta WHERE key = 'schema_version'").get();
22
+ return row ? Number(row.value) : 0;
23
+ }
24
+ function readSchemaVersion(home) {
25
+ const file = dbFile(home);
26
+ if (!existsSync(file)) return null;
27
+ const db = openReadOnly(file);
28
+ try {
29
+ return schemaVersionOf(db);
30
+ } finally {
31
+ db.close();
32
+ }
33
+ }
34
+ function activeProjectPaths(db) {
35
+ return db.prepare("SELECT name, path FROM projects WHERE archived = 0 ORDER BY name").all();
36
+ }
37
+ function withSnapshot(home, fn) {
38
+ const file = dbFile(home);
39
+ if (!existsSync(file)) throw new Error(`no database at ${file}; start slate once to create it`);
40
+ const dir = mkdtempSync(path.join(tmpdir(), "slate-snapshot-"));
41
+ try {
42
+ const source = openReadOnly(file);
43
+ try {
44
+ source.prepare("VACUUM INTO ?").run(path.join(dir, "slate.db"));
45
+ } finally {
46
+ source.close();
47
+ }
48
+ const store = Store.open({ home: dir });
49
+ try {
50
+ return fn(createServices(store));
51
+ } finally {
52
+ store.close();
53
+ }
54
+ } finally {
55
+ rmSync(dir, { recursive: true, force: true });
56
+ }
57
+ }
58
+
59
+ export {
60
+ openReadOnly,
61
+ schemaVersionOf,
62
+ readSchemaVersion,
63
+ activeProjectPaths,
64
+ withSnapshot
65
+ };
@@ -0,0 +1,142 @@
1
+ import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+ import {
3
+ stopPid
4
+ } from "./chunk-FNBCYJA2.js";
5
+ import {
6
+ readSchemaVersion
7
+ } from "./chunk-BWNUX4FT.js";
8
+ import {
9
+ startDaemon
10
+ } from "./chunk-SQHGMBUM.js";
11
+ import {
12
+ START_TIMEOUT_MS,
13
+ logFile
14
+ } from "./chunk-MKT3PGWK.js";
15
+ import {
16
+ DEFAULT_PORT,
17
+ baseUrl,
18
+ dbFile,
19
+ health,
20
+ home,
21
+ liveLock,
22
+ mcpUrl,
23
+ waitForHealth
24
+ } from "./chunk-3TOSW3FU.js";
25
+
26
+ // src/lifecycle.ts
27
+ import { readFileSync, rmSync } from "node:fs";
28
+ import path from "node:path";
29
+ function clearLockOf(pid, dir) {
30
+ const file = path.join(dir, "server.lock");
31
+ try {
32
+ if (JSON.parse(readFileSync(file, "utf8")).pid === pid) rmSync(file, { force: true });
33
+ } catch {
34
+ }
35
+ }
36
+ async function stopServer(service, options = {}) {
37
+ const dir = options.home ?? home();
38
+ const before = liveLock(dir);
39
+ let viaService = false;
40
+ if (service?.installed()) {
41
+ viaService = await service.state() === "running";
42
+ await service.stop();
43
+ }
44
+ const lock = liveLock(dir);
45
+ if (lock) {
46
+ await stopPid(lock.pid, options.timeoutMs !== void 0 ? { timeoutMs: options.timeoutMs } : {});
47
+ clearLockOf(lock.pid, dir);
48
+ }
49
+ return { wasRunning: before !== null || viaService, viaService, port: before?.port ?? null, pid: before?.pid ?? null };
50
+ }
51
+ async function stopCommand(service) {
52
+ const result = await stopServer(service);
53
+ if (!result.wasRunning) console.log("slate is not running");
54
+ else console.log(`slate stopped${result.viaService ? " (service)" : result.pid ? ` (pid ${result.pid})` : ""}`);
55
+ return 0;
56
+ }
57
+ async function restartCommand(service, port) {
58
+ if (service?.installed()) {
59
+ await service.restart();
60
+ const servicePort = service.unit()?.port ?? DEFAULT_PORT;
61
+ const up = await waitForHealth(servicePort, START_TIMEOUT_MS);
62
+ if (!up) {
63
+ console.error(`slate: the service did not come back on ${baseUrl(servicePort)}; see ${logFile()}`);
64
+ return 1;
65
+ }
66
+ console.log(`slate ${up.version} restarted at ${baseUrl(servicePort)} (pid ${up.pid}, service)`);
67
+ return 0;
68
+ }
69
+ const stopped = await stopServer(null);
70
+ return startDaemon(stopped.port ?? port, null);
71
+ }
72
+ function formatUptime(seconds) {
73
+ const d = Math.floor(seconds / 86400);
74
+ const h = Math.floor(seconds % 86400 / 3600);
75
+ const m = Math.floor(seconds % 3600 / 60);
76
+ const s = Math.floor(seconds % 60);
77
+ if (d) return `${d}d ${h}h`;
78
+ if (h) return `${h}h ${m}m`;
79
+ if (m) return `${m}m ${s}s`;
80
+ return `${s}s`;
81
+ }
82
+ function describeService(service, state) {
83
+ if (!service || !state) return `not supported on ${process.platform}`;
84
+ if (state === "not-installed") return "not installed";
85
+ return `installed, ${state} (${service.platform.kind}, ${service.unitPath})`;
86
+ }
87
+ function updateLine(update) {
88
+ if (!update || !update.latestVersion) return "unknown (no registry check yet)";
89
+ return update.updateAvailable ? `${update.latestVersion} available, run \`slate upgrade\`` : `up to date (latest ${update.latestVersion})`;
90
+ }
91
+ function statusLines(s) {
92
+ const lines = [`slate ${s.version}`];
93
+ const row = (label, value) => lines.push(` ${label.padEnd(9)}${value}`);
94
+ if (s.running) {
95
+ const extra = s.running.version !== s.version ? `, server version ${s.running.version}` : "";
96
+ row("server", `running at ${baseUrl(s.port)}`);
97
+ row("pid", String(s.running.pid));
98
+ row("uptime", `${formatUptime(s.running.uptime ?? 0)}${extra}`);
99
+ } else {
100
+ row("server", "not running");
101
+ }
102
+ row("mcp", mcpUrl(s.port));
103
+ row("db", dbFile(s.home));
104
+ const schema = s.running?.schemaVersion ?? s.schemaVersion;
105
+ row("schema", schema instanceof Error ? `unreadable: ${schema.message}` : schema === null || schema === void 0 ? "no database yet" : String(schema));
106
+ row("service", describeService(s.service, s.serviceState));
107
+ row("update", updateLine(s.running ?? s.cachedUpdate));
108
+ return lines;
109
+ }
110
+ async function statusCommand(service, port, version) {
111
+ const dir = home();
112
+ const lock = liveLock(dir);
113
+ const actualPort = lock?.port ?? port;
114
+ const running = await health(actualPort);
115
+ let schemaVersion = null;
116
+ let cachedUpdate = null;
117
+ if (!running) {
118
+ try {
119
+ schemaVersion = readSchemaVersion(dir);
120
+ } catch (err) {
121
+ schemaVersion = err;
122
+ }
123
+ const { readUpdateCache, updateStatus } = await import("./src-QZIVUACM.js");
124
+ const cache = readUpdateCache(dir);
125
+ cachedUpdate = cache ? updateStatus(version, cache.latestVersion) : null;
126
+ }
127
+ const serviceState = service ? await service.state() : null;
128
+ for (const line of statusLines({ version, home: dir, port: actualPort, running, service, serviceState, cachedUpdate, schemaVersion })) {
129
+ console.log(line);
130
+ }
131
+ return 0;
132
+ }
133
+
134
+ export {
135
+ stopServer,
136
+ stopCommand,
137
+ restartCommand,
138
+ formatUptime,
139
+ describeService,
140
+ statusLines,
141
+ statusCommand
142
+ };
@@ -0,0 +1,44 @@
1
+ import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+
3
+ // src/processes.ts
4
+ var STOP_TIMEOUT_MS = 5e3;
5
+ function isAlive(pid) {
6
+ try {
7
+ process.kill(pid, 0);
8
+ return true;
9
+ } catch (err) {
10
+ return err.code === "EPERM";
11
+ }
12
+ }
13
+ async function waitForExit(pid, timeoutMs, alive) {
14
+ const deadline = Date.now() + timeoutMs;
15
+ while (Date.now() < deadline) {
16
+ if (!alive(pid)) return true;
17
+ await new Promise((r) => setTimeout(r, 50));
18
+ }
19
+ return !alive(pid);
20
+ }
21
+ async function stopPid(pid, options = {}) {
22
+ const { timeoutMs = STOP_TIMEOUT_MS, kill = (p, s) => process.kill(p, s), alive = isAlive } = options;
23
+ if (!alive(pid)) return "gone";
24
+ try {
25
+ kill(pid, "SIGTERM");
26
+ } catch (err) {
27
+ if (err.code === "ESRCH") return "gone";
28
+ throw err;
29
+ }
30
+ if (await waitForExit(pid, timeoutMs, alive)) return "terminated";
31
+ try {
32
+ kill(pid, "SIGKILL");
33
+ } catch (err) {
34
+ if (err.code === "ESRCH") return "terminated";
35
+ throw err;
36
+ }
37
+ if (await waitForExit(pid, 2e3, alive)) return "killed";
38
+ throw new Error(`process ${pid} did not exit after SIGKILL`);
39
+ }
40
+
41
+ export {
42
+ isAlive,
43
+ stopPid
44
+ };