@hanfang5057/co-space 0.0.0-stage → 0.1.9

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 hanfang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,37 @@
1
- # Temporary Holding Version
1
+ # CoSpace Local Server
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ CoSpace Local Server provides stdio MCP tools and a local document-review web app. The Agent MCP process starts or connects to a separate local daemon. The daemon keeps serving the review page after the Agent exits.
4
+
5
+ ## Configure an Agent
6
+
7
+ Add this stdio MCP server to an Agent that supports Node.js 24 or later:
8
+
9
+ ```json
10
+ {
11
+ "mcpServers": {
12
+ "cospace": {
13
+ "command": "npx",
14
+ "args": ["-y", "@hanfang5057/co-space@latest", "mcp"]
15
+ }
16
+ }
17
+ }
18
+ ```
19
+
20
+ Restart or reconnect the Agent after changing its MCP configuration. The review URL is returned by MCP and can be opened later with `npx -y @hanfang5057/co-space@latest service open`. Publishing a newer package does not replace a running daemon: after all Agents disconnect, run `npx -y @hanfang5057/co-space@latest service restart`, then reconnect the Agent to apply the update.
21
+
22
+ ## Manage the local service
23
+
24
+ ```sh
25
+ npx -y @hanfang5057/co-space@latest service status
26
+ npx -y @hanfang5057/co-space@latest service open
27
+ npx -y @hanfang5057/co-space@latest service stop
28
+ npx -y @hanfang5057/co-space@latest service restart
29
+ npx -y @hanfang5057/co-space@latest service rollback
30
+ ```
31
+
32
+ Stopping the service preserves user data. Uninstalling the package or removing an Agent's MCP configuration also preserves data.
33
+ Stop or restart is refused while an Agent is actively connected; disconnect the Agent first.
34
+
35
+ ## Local data
36
+
37
+ By default, CoSpace uses the existing Desktop data directory `~/.cospace/webapp`. Set `COSPACE_WEB_HOME` to select another profile. Desktop and all generic Agent integrations using the same profile share one service and dataset. The DSH plugin remains isolated under its DSH-specific data home.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import '../dist/cli.js';
package/dist/cli.js ADDED
@@ -0,0 +1,364 @@
1
+ // apps/local-server/src/cli.js
2
+ import { readFile as readFile2, readdir } from "node:fs/promises";
3
+ import { spawn as spawn2 } from "node:child_process";
4
+ import path3 from "node:path";
5
+ import { fileURLToPath, pathToFileURL } from "node:url";
6
+
7
+ // packages/local-runtime/src/manager.js
8
+ import { createHash as createHash2, randomBytes } from "node:crypto";
9
+ import { open, mkdir, readFile, rm, stat, writeFile, copyFile, rename, chmod } from "node:fs/promises";
10
+ import { spawn } from "node:child_process";
11
+ import path2 from "node:path";
12
+
13
+ // packages/local-runtime/src/paths.js
14
+ import { createHash } from "node:crypto";
15
+ import { homedir } from "node:os";
16
+ import { realpathSync } from "node:fs";
17
+ import path from "node:path";
18
+ var LOCAL_PROTOCOL_VERSION = 1;
19
+ function resolveDataHome(env = process.env) {
20
+ return path.resolve(env.COSPACE_WEB_HOME || path.join(homedir(), ".cospace", "webapp"));
21
+ }
22
+ function canonicalPathIncludingMissingSegments(target) {
23
+ const resolved = path.resolve(target);
24
+ const missingSegments = [];
25
+ let current = resolved;
26
+ while (true) {
27
+ try {
28
+ return path.resolve(realpathSync.native(current), ...missingSegments);
29
+ } catch (error) {
30
+ if (error.code !== "ENOENT" && error.code !== "ENOTDIR") return resolved;
31
+ const parent = path.dirname(current);
32
+ if (parent === current) return resolved;
33
+ missingSegments.unshift(path.basename(current));
34
+ current = parent;
35
+ }
36
+ }
37
+ }
38
+ function appDataRoot(env, platform) {
39
+ if (platform === "win32") return env.LOCALAPPDATA || path.join(homedir(), "AppData", "Local");
40
+ if (platform === "darwin") return path.join(homedir(), "Library", "Application Support");
41
+ return env.XDG_DATA_HOME || path.join(homedir(), ".local", "share");
42
+ }
43
+ function resolveRuntimeHome({ dataHome = resolveDataHome(), env = process.env, platform = process.platform } = {}) {
44
+ const canonicalHome = canonicalPathIncludingMissingSegments(dataHome);
45
+ const profile = createHash("sha256").update(canonicalHome).digest("hex").slice(0, 16);
46
+ return path.join(appDataRoot(env, platform), "CoSpace", "local-server", "profiles", profile);
47
+ }
48
+ var endpointFile = (runtimeHome) => path.join(runtimeHome, "endpoint.json");
49
+ var secretFile = (runtimeHome) => path.join(runtimeHome, "secrets.json");
50
+
51
+ // packages/local-runtime/src/manager.js
52
+ var sleep = (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds));
53
+ async function readEndpoint(runtimeHome) {
54
+ try {
55
+ return JSON.parse(await readFile(endpointFile(runtimeHome), "utf8"));
56
+ } catch {
57
+ return null;
58
+ }
59
+ }
60
+ async function readSecrets(runtimeHome) {
61
+ try {
62
+ return JSON.parse(await readFile(secretFile(runtimeHome), "utf8"));
63
+ } catch {
64
+ return null;
65
+ }
66
+ }
67
+ async function installRuntimeVersion({ sourceVersionHome, runtimeHome, version }) {
68
+ if (!sourceVersionHome || !runtimeHome || !version) throw new TypeError("sourceVersionHome, runtimeHome, and version are required");
69
+ const versionHome = path2.join(runtimeHome, "versions", version);
70
+ const assetFiles = ["daemon.cjs", "web/index.html", "web/app.js", "web/app.css"];
71
+ const digests = async (home) => Object.fromEntries(await Promise.all(assetFiles.map(async (name) => {
72
+ const content = await readFile(path2.join(home, name));
73
+ return [name, createHash2("sha256").update(content).digest("hex")];
74
+ })));
75
+ const expectedHashes = await digests(sourceVersionHome);
76
+ try {
77
+ const marker = JSON.parse(await readFile(path2.join(versionHome, "runtime.json"), "utf8"));
78
+ if (marker.version === version && marker.protocolVersion === LOCAL_PROTOCOL_VERSION && JSON.stringify(marker.hashes) === JSON.stringify(expectedHashes)) {
79
+ const installedHashes2 = await digests(versionHome);
80
+ if (JSON.stringify(installedHashes2) === JSON.stringify(expectedHashes)) return versionHome;
81
+ }
82
+ throw Object.assign(new Error(`Installed CoSpace runtime ${version} is incomplete or incompatible`), { code: "RUNTIME_ASSETS_INVALID" });
83
+ } catch (error) {
84
+ if (error.code !== "ENOENT" && error.code !== "ENOTDIR") throw error;
85
+ }
86
+ await mkdir(path2.join(runtimeHome, "versions"), { recursive: true, mode: 448 });
87
+ const staging = `${versionHome}.staging-${process.pid}-${randomBytes(6).toString("hex")}`;
88
+ await rm(staging, { recursive: true, force: true });
89
+ await mkdir(path2.join(staging, "web"), { recursive: true, mode: 448 });
90
+ await copyFile(path2.join(sourceVersionHome, "daemon.cjs"), path2.join(staging, "daemon.cjs"));
91
+ for (const name of ["index.html", "app.js", "app.css"]) await copyFile(path2.join(sourceVersionHome, "web", name), path2.join(staging, "web", name));
92
+ const installedHashes = await digests(staging);
93
+ if (JSON.stringify(installedHashes) !== JSON.stringify(expectedHashes)) {
94
+ await rm(staging, { recursive: true, force: true });
95
+ throw Object.assign(new Error("CoSpace runtime copy failed its integrity check"), { code: "RUNTIME_INTEGRITY_FAILED" });
96
+ }
97
+ await writeFile(path2.join(staging, "runtime.json"), `${JSON.stringify({ version, protocolVersion: LOCAL_PROTOCOL_VERSION, hashes: installedHashes })}
98
+ `, { mode: 384 });
99
+ try {
100
+ await rename(staging, versionHome);
101
+ } catch (error) {
102
+ await rm(staging, { recursive: true, force: true });
103
+ if (error.code !== "EEXIST" && error.code !== "ENOTEMPTY") throw error;
104
+ try {
105
+ const marker = JSON.parse(await readFile(path2.join(versionHome, "runtime.json"), "utf8"));
106
+ if (marker.version === version && marker.protocolVersion === LOCAL_PROTOCOL_VERSION && JSON.stringify(marker.hashes) === JSON.stringify(expectedHashes)) return versionHome;
107
+ } catch {
108
+ }
109
+ throw Object.assign(new Error(`Could not install CoSpace runtime ${version}`), { code: "RUNTIME_INSTALL_CONFLICT" });
110
+ }
111
+ return versionHome;
112
+ }
113
+ async function reachableEndpoint(runtimeHome) {
114
+ const endpoint = await readEndpoint(runtimeHome);
115
+ if (!endpoint || endpoint.runtimeId !== path2.basename(runtimeHome) || endpoint.host !== "127.0.0.1" || !Number.isInteger(endpoint.port) || endpoint.port < 1 || endpoint.port > 65535) return null;
116
+ try {
117
+ const response = await fetch(`http://${endpoint.host}:${endpoint.port}/__cospace/health`, { signal: AbortSignal.timeout(700) });
118
+ const health = await response.json();
119
+ if (!response.ok || health.ready !== true || health.runtimeId !== endpoint.runtimeId) return null;
120
+ return { ...endpoint, version: health.version, protocolVersion: health.protocolVersion, activeMcpClients: health.activeMcpClients || 0 };
121
+ } catch {
122
+ return null;
123
+ }
124
+ }
125
+ function assertCompatible(endpoint) {
126
+ if (endpoint && endpoint.protocolVersion !== LOCAL_PROTOCOL_VERSION) {
127
+ throw Object.assign(new Error(`CoSpace Local Server protocol ${endpoint.protocolVersion} is incompatible with this client. Stop or upgrade the service before reconnecting.`), { code: "LOCAL_SERVER_PROTOCOL_MISMATCH" });
128
+ }
129
+ }
130
+ async function ensureLocalDaemon({ dataHome = resolveDataHome(), runtimeHome = resolveRuntimeHome({ dataHome }), versionHome, sourceVersionHome, version = "0.0.0", node = process.execPath, timeoutMs = 2e4 } = {}) {
131
+ if (!versionHome) versionHome = await installRuntimeVersion({ sourceVersionHome, runtimeHome, version });
132
+ await mkdir(runtimeHome, { recursive: true, mode: 448 });
133
+ await ensureSecrets(runtimeHome);
134
+ let endpoint = await reachableEndpoint(runtimeHome);
135
+ assertCompatible(endpoint);
136
+ if (endpoint) {
137
+ const secrets = await readSecrets(runtimeHome);
138
+ if (!secrets?.rpcToken || !secrets?.uiToken) throw new Error("CoSpace service credentials are missing; stop and restart the service to recover.");
139
+ return { ...endpoint, dataHome, runtimeHome, rpcToken: secrets.rpcToken, uiToken: secrets.uiToken };
140
+ }
141
+ const lockPath = path2.join(runtimeHome, "start.lock");
142
+ const nonce = randomBytes(16).toString("hex");
143
+ const deadline = Date.now() + timeoutMs;
144
+ let ownsLock = false;
145
+ while (Date.now() < deadline) {
146
+ endpoint = await reachableEndpoint(runtimeHome);
147
+ assertCompatible(endpoint);
148
+ if (endpoint) {
149
+ const secrets = await readSecrets(runtimeHome);
150
+ if (!secrets?.rpcToken || !secrets?.uiToken) throw new Error("CoSpace service credentials are missing; stop and restart the service to recover.");
151
+ return { ...endpoint, dataHome, runtimeHome, rpcToken: secrets.rpcToken, uiToken: secrets.uiToken };
152
+ }
153
+ try {
154
+ const lock = await open(lockPath, "wx", 384);
155
+ await lock.writeFile(JSON.stringify({ pid: process.pid, nonce, startedAt: Date.now() }));
156
+ await lock.close();
157
+ ownsLock = true;
158
+ break;
159
+ } catch (error) {
160
+ if (error.code !== "EEXIST") throw error;
161
+ let lockInfo = null;
162
+ try {
163
+ lockInfo = JSON.parse(await readFile(lockPath, "utf8"));
164
+ } catch {
165
+ }
166
+ if (lockInfo?.pid && lockInfo.pid !== process.pid) {
167
+ try {
168
+ process.kill(lockInfo.pid, 0);
169
+ } catch {
170
+ await rm(lockPath, { force: true });
171
+ continue;
172
+ }
173
+ } else {
174
+ const info = await stat(lockPath).catch(() => null);
175
+ if (info && Date.now() - info.mtimeMs > timeoutMs) await rm(lockPath, { force: true });
176
+ }
177
+ await sleep(200);
178
+ }
179
+ }
180
+ if (ownsLock) {
181
+ const daemonPath = path2.join(versionHome, "daemon.cjs");
182
+ const logHandle = await open(path2.join(runtimeHome, "daemon.log"), "a", 384);
183
+ try {
184
+ const child = spawn(node, [daemonPath], {
185
+ detached: true,
186
+ windowsHide: true,
187
+ stdio: ["ignore", logHandle.fd, logHandle.fd],
188
+ env: {
189
+ ...process.env,
190
+ COSPACE_DATA_HOME: dataHome,
191
+ COSPACE_RUNTIME_HOME: runtimeHome,
192
+ COSPACE_VERSION_HOME: versionHome,
193
+ COSPACE_PACKAGE_VERSION: version
194
+ }
195
+ });
196
+ child.unref();
197
+ } finally {
198
+ await logHandle.close();
199
+ }
200
+ }
201
+ while (Date.now() < deadline) {
202
+ endpoint = await reachableEndpoint(runtimeHome);
203
+ assertCompatible(endpoint);
204
+ if (endpoint) {
205
+ const secrets = await readSecrets(runtimeHome);
206
+ if (!secrets?.rpcToken) throw new Error("CoSpace service started without an RPC credential");
207
+ return { ...endpoint, dataHome, runtimeHome, rpcToken: secrets.rpcToken, uiToken: secrets.uiToken };
208
+ }
209
+ await sleep(200);
210
+ }
211
+ if (ownsLock) {
212
+ try {
213
+ const lockInfo = JSON.parse(await readFile(lockPath, "utf8"));
214
+ if (lockInfo.nonce === nonce) await rm(lockPath, { force: true });
215
+ } catch {
216
+ }
217
+ }
218
+ throw Object.assign(new Error("CoSpace Local Server did not become ready. Run `cospace-local service status` for details."), { code: "LOCAL_SERVER_START_TIMEOUT" });
219
+ }
220
+ async function localServiceStatus({ dataHome = resolveDataHome(), runtimeHome = resolveRuntimeHome({ dataHome }) } = {}) {
221
+ const endpoint = await reachableEndpoint(runtimeHome);
222
+ return endpoint ? { running: true, compatible: endpoint.protocolVersion === LOCAL_PROTOCOL_VERSION, ...endpoint, url: `http://${endpoint.host}:${endpoint.port}/` } : { running: false, dataHome, runtimeHome };
223
+ }
224
+ async function stopLocalDaemon({ dataHome = resolveDataHome(), runtimeHome = resolveRuntimeHome({ dataHome }), timeoutMs = 8e3 } = {}) {
225
+ const endpoint = await reachableEndpoint(runtimeHome);
226
+ if (!endpoint) return { stopped: true, wasRunning: false };
227
+ const secrets = await readSecrets(runtimeHome);
228
+ const response = await fetch(`http://${endpoint.host}:${endpoint.port}/__cospace/control/stop`, {
229
+ method: "POST",
230
+ headers: { "x-cospace-rpc-token": secrets?.rpcToken || "" },
231
+ signal: AbortSignal.timeout(1500)
232
+ });
233
+ if (!response.ok) {
234
+ const body = await response.json().catch(() => ({}));
235
+ throw Object.assign(new Error(body.error?.message || `CoSpace service refused to stop (${response.status})`), { code: body.error?.code || "LOCAL_SERVER_STOP_REJECTED", details: body.error?.details });
236
+ }
237
+ const deadline = Date.now() + timeoutMs;
238
+ while (Date.now() < deadline) {
239
+ if (!await reachableEndpoint(runtimeHome)) return { stopped: true, wasRunning: true };
240
+ await sleep(150);
241
+ }
242
+ throw Object.assign(new Error("CoSpace Local Server did not stop before the timeout"), { code: "LOCAL_SERVER_STOP_TIMEOUT" });
243
+ }
244
+ async function ensureSecrets(runtimeHome, { randomBytesFn = randomBytes } = {}) {
245
+ await mkdir(runtimeHome, { recursive: true, mode: 448 });
246
+ const file = secretFile(runtimeHome);
247
+ try {
248
+ const secrets = JSON.parse(await readFile(file, "utf8"));
249
+ if (typeof secrets?.uiToken !== "string" || typeof secrets?.rpcToken !== "string") throw Object.assign(new Error("Invalid CoSpace credentials file"), { code: "LOCAL_SERVER_CREDENTIALS_INVALID" });
250
+ await chmod(file, 384).catch(() => {
251
+ });
252
+ return secrets;
253
+ } catch (error) {
254
+ if (error.code !== "ENOENT") throw error;
255
+ const secrets = { uiToken: randomBytesFn(32).toString("base64url"), rpcToken: randomBytesFn(32).toString("base64url") };
256
+ try {
257
+ await writeFile(file, `${JSON.stringify(secrets)}
258
+ `, { mode: 384, flag: "wx" });
259
+ } catch (writeError) {
260
+ if (writeError.code !== "EEXIST") throw writeError;
261
+ }
262
+ const saved = JSON.parse(await readFile(file, "utf8"));
263
+ if (typeof saved?.uiToken !== "string" || typeof saved?.rpcToken !== "string") throw Object.assign(new Error("Invalid CoSpace credentials file"), { code: "LOCAL_SERVER_CREDENTIALS_INVALID" });
264
+ return saved;
265
+ }
266
+ }
267
+
268
+ // apps/local-server/src/cli.js
269
+ var distRoot = path3.dirname(fileURLToPath(import.meta.url));
270
+ var metadata = JSON.parse(await readFile2(path3.join(distRoot, "package.json"), "utf8"));
271
+ function openBrowser(url) {
272
+ const [command, args] = process.platform === "darwin" ? ["open", [url]] : process.platform === "win32" ? ["rundll32", ["url.dll,FileProtocolHandler", url]] : ["xdg-open", [url]];
273
+ const child = spawn2(command, args, { detached: true, stdio: "ignore", windowsHide: true });
274
+ child.once("error", (error) => {
275
+ process.stderr.write(`Could not open browser: ${error.message}
276
+ `);
277
+ });
278
+ child.unref();
279
+ }
280
+ async function currentPaths() {
281
+ const dataHome = resolveDataHome();
282
+ const runtimeHome = resolveRuntimeHome({ dataHome });
283
+ const versionHome = await installRuntimeVersion({ sourceVersionHome: distRoot, runtimeHome, version: metadata.version });
284
+ return { dataHome, runtimeHome, versionHome };
285
+ }
286
+ async function ensureService() {
287
+ const paths = await currentPaths();
288
+ return ensureLocalDaemon({ ...paths, version: metadata.version });
289
+ }
290
+ async function rollbackService(targetVersion) {
291
+ const dataHome = resolveDataHome();
292
+ const runtimeHome = resolveRuntimeHome({ dataHome });
293
+ const running = await localServiceStatus({ dataHome, runtimeHome });
294
+ if (running.running) await stopLocalDaemon({ dataHome, runtimeHome });
295
+ const versionsRoot = path3.join(runtimeHome, "versions");
296
+ const names = await readdir(versionsRoot).catch(() => []);
297
+ const installed = [];
298
+ for (const name of names) {
299
+ if (!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(name)) continue;
300
+ try {
301
+ const marker = JSON.parse(await readFile2(path3.join(versionsRoot, name, "runtime.json"), "utf8"));
302
+ if (marker.version === name && marker.protocolVersion === metadata.protocolVersion) installed.push(name);
303
+ } catch {
304
+ }
305
+ }
306
+ const currentVersion = running.version || metadata.version;
307
+ const target = targetVersion || installed.filter((version) => version.localeCompare(currentVersion, "en", { numeric: true }) < 0).sort((left, right) => right.localeCompare(left, "en", { numeric: true }))[0];
308
+ if (!target || !installed.includes(target)) throw new Error(targetVersion ? `Local Server runtime ${targetVersion} is not installed` : "No previous Local Server runtime is available to roll back to");
309
+ const sourceVersionHome = path3.join(versionsRoot, target);
310
+ const versionHome = await installRuntimeVersion({ sourceVersionHome, runtimeHome, version: target });
311
+ const endpoint = await ensureLocalDaemon({ dataHome, runtimeHome, versionHome, version: target });
312
+ return endpoint;
313
+ }
314
+ async function runMcp() {
315
+ const endpoint = await ensureService();
316
+ const { startStdioMcp } = await import(pathToFileURL(path3.join(distRoot, "mcp.cjs")).href);
317
+ await startStdioMcp({ ...endpoint, url: `http://${endpoint.host}:${endpoint.port}/` }, { packageVersion: metadata.version });
318
+ }
319
+ async function runService(command, argument2) {
320
+ if (command === "status") {
321
+ const status = await localServiceStatus();
322
+ process.stdout.write(status.running ? `CoSpace Local Server ${status.version}
323
+ ${status.url}
324
+ Active Agent connections: ${status.activeMcpClients}
325
+ ` : "CoSpace Local Server is not running.\n");
326
+ return;
327
+ }
328
+ if (command === "stop") {
329
+ const result = await stopLocalDaemon();
330
+ process.stdout.write(result.wasRunning ? "CoSpace Local Server stopped. Data was preserved.\n" : "CoSpace Local Server was not running.\n");
331
+ return;
332
+ }
333
+ if (command === "start" || command === "restart") {
334
+ if (command === "restart") await stopLocalDaemon();
335
+ const endpoint = await ensureService();
336
+ process.stdout.write(`CoSpace Local Server ${endpoint.version} is running at http://${endpoint.host}:${endpoint.port}/
337
+ `);
338
+ return;
339
+ }
340
+ if (command === "rollback") {
341
+ const endpoint = await rollbackService(argument2);
342
+ process.stdout.write(`CoSpace Local Server rolled back to ${endpoint.version} at http://${endpoint.host}:${endpoint.port}/
343
+ `);
344
+ return;
345
+ }
346
+ if (command === "open") {
347
+ const endpoint = await ensureService();
348
+ openBrowser(`http://${endpoint.host}:${endpoint.port}/`);
349
+ process.stdout.write(`Opening CoSpace at http://${endpoint.host}:${endpoint.port}/
350
+ `);
351
+ return;
352
+ }
353
+ throw new Error(`Unknown service command: ${command || "(missing)"}`);
354
+ }
355
+ var [mode = "mcp", subcommand, argument] = process.argv.slice(2);
356
+ try {
357
+ if (mode === "mcp") await runMcp();
358
+ else if (mode === "service") await runService(subcommand, argument);
359
+ else throw new Error(`Unknown command: ${mode}`);
360
+ } catch (error) {
361
+ process.stderr.write(`CoSpace Local Server: ${error.message}
362
+ `);
363
+ process.exitCode = 1;
364
+ }