@procedures/peer 0.3.0 → 0.5.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.
- package/CHANGELOG.md +50 -0
- package/dist/.tsbuildinfo +1 -1
- package/dist/connection/index.d.ts.map +1 -1
- package/dist/connection/index.js +4 -1
- package/dist/connection/index.js.map +1 -1
- package/dist/input-schemas.d.ts +5 -7
- package/dist/input-schemas.d.ts.map +1 -1
- package/dist/input-schemas.js +4 -15
- package/dist/input-schemas.js.map +1 -1
- package/dist/lockfile.d.ts +5 -2
- package/dist/lockfile.d.ts.map +1 -1
- package/dist/lockfile.js +5 -2
- package/dist/lockfile.js.map +1 -1
- package/dist/module.d.ts +2 -1
- package/dist/module.d.ts.map +1 -1
- package/dist/module.js +2 -7
- package/dist/module.js.map +1 -1
- package/dist/output-schemas.d.ts +1 -4
- package/dist/output-schemas.d.ts.map +1 -1
- package/dist/output-schemas.js +0 -23
- package/dist/output-schemas.js.map +1 -1
- package/dist/procedures/index.d.ts +0 -6
- package/dist/procedures/index.d.ts.map +1 -1
- package/dist/procedures/index.js +1 -3
- package/dist/procedures/index.js.map +1 -1
- package/dist/types.d.ts +0 -58
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/connection/index.ts +3 -1
- package/src/input-schemas.ts +4 -27
- package/src/lockfile.ts +7 -3
- package/src/module.ts +2 -7
- package/src/output-schemas.ts +0 -29
- package/src/procedures/index.ts +1 -8
- package/src/types.ts +0 -76
- package/dist/procedures/server.start.d.ts +0 -14
- package/dist/procedures/server.start.d.ts.map +0 -1
- package/dist/procedures/server.start.js +0 -182
- package/dist/procedures/server.start.js.map +0 -1
- package/dist/procedures/server.status.d.ts +0 -13
- package/dist/procedures/server.status.d.ts.map +0 -1
- package/dist/procedures/server.status.js +0 -118
- package/dist/procedures/server.status.js.map +0 -1
- package/dist/procedures/server.stop.d.ts +0 -12
- package/dist/procedures/server.stop.d.ts.map +0 -1
- package/dist/procedures/server.stop.js +0 -98
- package/dist/procedures/server.stop.js.map +0 -1
- package/src/procedures/server.start.ts +0 -212
- package/src/procedures/server.status.ts +0 -141
- package/src/procedures/server.stop.ts +0 -123
package/src/output-schemas.ts
CHANGED
|
@@ -12,9 +12,6 @@ import type {
|
|
|
12
12
|
ServerConnectOutput,
|
|
13
13
|
ServerCreateOutput,
|
|
14
14
|
ServerDisconnectOutput,
|
|
15
|
-
ServerStartOutput,
|
|
16
|
-
ServerStatusOutput,
|
|
17
|
-
ServerStopOutput,
|
|
18
15
|
} from "./types.js";
|
|
19
16
|
import type { ServerCallOutput } from "./procedures/server.call.js";
|
|
20
17
|
import type { ServerConnectionsOutput } from "./procedures/server.connections.js";
|
|
@@ -62,32 +59,6 @@ export const ManifestGenerateOutputSchema: z.ZodType<ManifestGenerateOutput> = z
|
|
|
62
59
|
filesWritten: z.array(z.string()).optional().describe("The files that the call wrote, with outputDir"),
|
|
63
60
|
});
|
|
64
61
|
|
|
65
|
-
export const ServerStartOutputSchema: z.ZodType<ServerStartOutput> = z.looseObject({
|
|
66
|
-
success: z.boolean().describe("True when the server started"),
|
|
67
|
-
pid: z.number().optional().describe("The process id of the server"),
|
|
68
|
-
port: z.number().optional().describe("The port of the server"),
|
|
69
|
-
endpoint: z.string().optional().describe("The URL of the server"),
|
|
70
|
-
logFile: z.string().optional().describe("The log file of the server"),
|
|
71
|
-
message: z.string().describe("A message about the result"),
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
export const ServerStopOutputSchema: z.ZodType<ServerStopOutput> = z.looseObject({
|
|
75
|
-
success: z.boolean().describe("True when the server stopped"),
|
|
76
|
-
message: z.string().describe("A message about the result"),
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
export const ServerStatusOutputSchema: z.ZodType<ServerStatusOutput> = z.looseObject({
|
|
80
|
-
running: z.boolean().describe("True when a server runs"),
|
|
81
|
-
pid: z.number().optional().describe("The process id of the server"),
|
|
82
|
-
port: z.number().optional().describe("The port of the server"),
|
|
83
|
-
endpoint: z.string().optional().describe("The URL of the server"),
|
|
84
|
-
transport: z.string().optional().describe("The transport of the server"),
|
|
85
|
-
startedAt: z.string().optional().describe("The start time (ISO 8601)"),
|
|
86
|
-
uptime: z.string().optional().describe("The time since the start, as text"),
|
|
87
|
-
logFile: z.string().optional().describe("The log file of the server"),
|
|
88
|
-
message: z.string().describe("A message about the result"),
|
|
89
|
-
});
|
|
90
|
-
|
|
91
62
|
export const ServerCallOutputSchema: z.ZodType<ServerCallOutput> = z.looseObject({
|
|
92
63
|
result: z.unknown().describe("The result of the remote procedure"),
|
|
93
64
|
connectionId: z.string().describe("The connection that the call used"),
|
package/src/procedures/index.ts
CHANGED
|
@@ -16,14 +16,7 @@ export type { ServerDisconnectInput, ServerDisconnectOutput } from "./server.dis
|
|
|
16
16
|
export { manifestGenerateProcedure } from "./manifest.generate.js";
|
|
17
17
|
export type { ManifestGenerateInput, ManifestGenerateOutput } from "./manifest.generate.js";
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
export type { ServerStartInput, ServerStartOutput } from "./server.start.js";
|
|
21
|
-
|
|
22
|
-
export { serverStopProcedure } from "./server.stop.js";
|
|
23
|
-
export type { ServerStopInput, ServerStopOutput } from "./server.stop.js";
|
|
24
|
-
|
|
25
|
-
export { serverStatusProcedure } from "./server.status.js";
|
|
26
|
-
export type { ServerStatusInput, ServerStatusOutput } from "./server.status.js";
|
|
19
|
+
// server.start, server.stop and server.status are in @procedures/server (the package of the host)
|
|
27
20
|
|
|
28
21
|
export { serverCallProcedure } from "./server.call.js";
|
|
29
22
|
export type { ServerCallInput, ServerCallOutput } from "./server.call.js";
|
package/src/types.ts
CHANGED
|
@@ -181,79 +181,3 @@ export interface ProcedureUpdateMessage {
|
|
|
181
181
|
added?: ProcedureInfo[];
|
|
182
182
|
removed?: string[]; // Procedure paths as strings
|
|
183
183
|
}
|
|
184
|
-
|
|
185
|
-
// =============================================================================
|
|
186
|
-
// server.start Types
|
|
187
|
-
// =============================================================================
|
|
188
|
-
|
|
189
|
-
export interface ServerStartInput {
|
|
190
|
-
/** Port to listen on */
|
|
191
|
-
port?: number | undefined;
|
|
192
|
-
/** Host to bind to */
|
|
193
|
-
host?: string | undefined;
|
|
194
|
-
/** Transport type */
|
|
195
|
-
transport?: "http" | "websocket" | "both" | undefined;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
export interface ServerStartOutput {
|
|
199
|
-
/** Whether start succeeded */
|
|
200
|
-
success: boolean;
|
|
201
|
-
/** Process ID of server */
|
|
202
|
-
pid?: number | undefined;
|
|
203
|
-
/** Port server is running on */
|
|
204
|
-
port?: number | undefined;
|
|
205
|
-
/** Endpoint URL */
|
|
206
|
-
endpoint?: string | undefined;
|
|
207
|
-
/** Log file path */
|
|
208
|
-
logFile?: string | undefined;
|
|
209
|
-
/** Status message */
|
|
210
|
-
message: string;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// =============================================================================
|
|
214
|
-
// server.stop Types
|
|
215
|
-
// =============================================================================
|
|
216
|
-
|
|
217
|
-
export interface ServerStopInput {
|
|
218
|
-
/** Port of server to stop (stops all if omitted) */
|
|
219
|
-
port?: number | undefined;
|
|
220
|
-
/** Force kill with SIGKILL instead of SIGTERM */
|
|
221
|
-
force?: boolean | undefined;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
export interface ServerStopOutput {
|
|
225
|
-
/** Whether stop succeeded */
|
|
226
|
-
success: boolean;
|
|
227
|
-
/** Status message */
|
|
228
|
-
message: string;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// =============================================================================
|
|
232
|
-
// server.status Types
|
|
233
|
-
// =============================================================================
|
|
234
|
-
|
|
235
|
-
export interface ServerStatusInput {
|
|
236
|
-
/** Port to check (shows all if omitted) */
|
|
237
|
-
port?: number | undefined;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
export interface ServerStatusOutput {
|
|
241
|
-
/** Whether server is running */
|
|
242
|
-
running: boolean;
|
|
243
|
-
/** Process ID */
|
|
244
|
-
pid?: number | undefined;
|
|
245
|
-
/** Port */
|
|
246
|
-
port?: number | undefined;
|
|
247
|
-
/** Endpoint URL */
|
|
248
|
-
endpoint?: string | undefined;
|
|
249
|
-
/** Transport type */
|
|
250
|
-
transport?: string | undefined;
|
|
251
|
-
/** When server started (ISO string) */
|
|
252
|
-
startedAt?: string | undefined;
|
|
253
|
-
/** Human-readable uptime */
|
|
254
|
-
uptime?: string | undefined;
|
|
255
|
-
/** Log file path */
|
|
256
|
-
logFile?: string | undefined;
|
|
257
|
-
/** Status message */
|
|
258
|
-
message: string;
|
|
259
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Procedure: server.start
|
|
3
|
-
* Starts the CLI server as a background daemon
|
|
4
|
-
*/
|
|
5
|
-
import { type Effects, type Procedure } from "@procedures/client";
|
|
6
|
-
import type { ServerStartInput, ServerStartOutput } from "../types.js";
|
|
7
|
-
export declare const serverStartProcedure: Procedure<ServerStartInput, ServerStartOutput, {
|
|
8
|
-
description: string;
|
|
9
|
-
effects: Effects;
|
|
10
|
-
args: string[];
|
|
11
|
-
shorts: Record<string, string>;
|
|
12
|
-
}>;
|
|
13
|
-
export type { ServerStartInput, ServerStartOutput };
|
|
14
|
-
//# sourceMappingURL=server.start.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.start.d.ts","sourceRoot":"","sources":["../../src/procedures/server.start.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,EAAmB,KAAK,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAKnF,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAyEvE,eAAO,MAAM,oBAAoB,EAAE,SAAS,CAC1C,gBAAgB,EAChB,iBAAiB,EACjB;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,CAuHjF,CAAC;AAEX,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Procedure: server.start
|
|
3
|
-
* Starts the CLI server as a background daemon
|
|
4
|
-
*/
|
|
5
|
-
import { spawn } from "node:child_process";
|
|
6
|
-
import * as fs from "node:fs";
|
|
7
|
-
import * as path from "node:path";
|
|
8
|
-
import * as os from "node:os";
|
|
9
|
-
import { createProcedure } from "@procedures/client";
|
|
10
|
-
import { wrapSchema } from "../schema.js";
|
|
11
|
-
import { ServerStartOutputSchema } from "../output-schemas.js";
|
|
12
|
-
import { serverStartInputSchema } from "../input-schemas.js";
|
|
13
|
-
import { checkServer, readLockfileForPort } from "../lockfile.js";
|
|
14
|
-
const MARK_DIR = path.join(os.homedir(), ".mark");
|
|
15
|
-
const SERVERS_DIR = path.join(MARK_DIR, "servers");
|
|
16
|
-
const LOG_PATH = path.join(MARK_DIR, "server.log");
|
|
17
|
-
const LOG_PREV_PATH = path.join(MARK_DIR, "server.log.1");
|
|
18
|
-
const serverStartOutputSchema = wrapSchema(ServerStartOutputSchema);
|
|
19
|
-
/**
|
|
20
|
-
* Check if process is alive
|
|
21
|
-
*/
|
|
22
|
-
function isProcessAlive(pid) {
|
|
23
|
-
try {
|
|
24
|
-
process.kill(pid, 0);
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
catch {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Rotate log file
|
|
33
|
-
*/
|
|
34
|
-
function rotateLog() {
|
|
35
|
-
try {
|
|
36
|
-
fs.mkdirSync(MARK_DIR, { recursive: true });
|
|
37
|
-
if (fs.existsSync(LOG_PATH)) {
|
|
38
|
-
fs.renameSync(LOG_PATH, LOG_PREV_PATH);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
catch {
|
|
42
|
-
// Ignore rotation errors
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Find the CLI entry point
|
|
47
|
-
*/
|
|
48
|
-
function findCliPath() {
|
|
49
|
-
// First, try to use the currently running script if it's the CLI
|
|
50
|
-
const currentScript = process.argv[1];
|
|
51
|
-
if (currentScript) {
|
|
52
|
-
// Normalize path for cross-platform check
|
|
53
|
-
const normalized = currentScript.replace(/\\/g, "/");
|
|
54
|
-
// mark runs as dist/bin.js (its bin) or dist/cli.js
|
|
55
|
-
if (normalized.endsWith("/dist/bin.js") || normalized.endsWith("cli.js") || normalized.includes("cli/dist")) {
|
|
56
|
-
// Return absolute path
|
|
57
|
-
return path.resolve(currentScript);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
// Try to find the mark CLI in node_modules or as a direct path
|
|
61
|
-
const candidates = [
|
|
62
|
-
path.join(process.cwd(), "node_modules", "@procedures", "mark", "dist", "cli.js"),
|
|
63
|
-
path.join(process.cwd(), "node_modules", ".bin", "mark"),
|
|
64
|
-
// Check parent directories for monorepo setups
|
|
65
|
-
path.join(process.cwd(), "..", "cli", "dist", "cli.js"),
|
|
66
|
-
// Direct check in current directory
|
|
67
|
-
path.join(process.cwd(), "dist", "cli.js"),
|
|
68
|
-
];
|
|
69
|
-
// Check which candidate exists
|
|
70
|
-
for (const candidate of candidates) {
|
|
71
|
-
if (fs.existsSync(candidate)) {
|
|
72
|
-
return candidate;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
// Fallback: try mark in PATH (will fail if not installed globally)
|
|
76
|
-
return "mark";
|
|
77
|
-
}
|
|
78
|
-
export const serverStartProcedure = createProcedure()
|
|
79
|
-
.path(["server", "start"])
|
|
80
|
-
.input(serverStartInputSchema)
|
|
81
|
-
.output(serverStartOutputSchema)
|
|
82
|
-
.meta({
|
|
83
|
-
description: "Start CLI server as background daemon",
|
|
84
|
-
// The daemon loads the procedure packages of the workspace. The procedure moves server.log
|
|
85
|
-
// over server.log.1.
|
|
86
|
-
effects: { reads: ["fs", "server"], writes: ["fs", "network", "process", "server"] },
|
|
87
|
-
args: [],
|
|
88
|
-
shorts: { port: "p", host: "h" },
|
|
89
|
-
})
|
|
90
|
-
.handler(async (input) => {
|
|
91
|
-
const port = input.port ?? 3000;
|
|
92
|
-
// Loopback by default; pass host: "0.0.0.0" to expose on the LAN deliberately.
|
|
93
|
-
// See documentation/BUGS-2026-07.md (H19).
|
|
94
|
-
const host = input.host ?? "127.0.0.1";
|
|
95
|
-
const transport = input.transport ?? "http";
|
|
96
|
-
// Check if server is already running on this port
|
|
97
|
-
const existing = readLockfileForPort(port);
|
|
98
|
-
if (existing && (await checkServer(existing)) === "alive") {
|
|
99
|
-
return {
|
|
100
|
-
success: false,
|
|
101
|
-
message: `Server already running on port ${port} (PID ${existing.pid})`,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
// Rotate log file
|
|
105
|
-
rotateLog();
|
|
106
|
-
// Ensure directories exist
|
|
107
|
-
fs.mkdirSync(SERVERS_DIR, { recursive: true });
|
|
108
|
-
// Open log file for writing
|
|
109
|
-
const logFd = fs.openSync(LOG_PATH, "a");
|
|
110
|
-
// Find CLI path
|
|
111
|
-
const cliPath = findCliPath();
|
|
112
|
-
// Build arguments
|
|
113
|
-
const args = ["--server", "--port", String(port), "--host", host];
|
|
114
|
-
if (transport !== "http") {
|
|
115
|
-
args.push("--transport", transport);
|
|
116
|
-
}
|
|
117
|
-
// Determine how to spawn
|
|
118
|
-
let spawnCmd;
|
|
119
|
-
let spawnArgs;
|
|
120
|
-
if (cliPath === "mark" || cliPath.endsWith(".bin/mark") || cliPath.endsWith(".bin\\mark")) {
|
|
121
|
-
// Use mark command directly
|
|
122
|
-
spawnCmd = cliPath;
|
|
123
|
-
spawnArgs = args;
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
// Use node to run the JS file
|
|
127
|
-
spawnCmd = process.execPath;
|
|
128
|
-
spawnArgs = [cliPath, ...args];
|
|
129
|
-
}
|
|
130
|
-
// Spawn daemon process
|
|
131
|
-
const child = spawn(spawnCmd, spawnArgs, {
|
|
132
|
-
detached: true,
|
|
133
|
-
stdio: ["ignore", logFd, logFd],
|
|
134
|
-
env: { ...process.env },
|
|
135
|
-
cwd: process.cwd(),
|
|
136
|
-
// No console window on Windows (deep dive CLI-16)
|
|
137
|
-
windowsHide: true,
|
|
138
|
-
});
|
|
139
|
-
// Unref so parent can exit
|
|
140
|
-
child.unref();
|
|
141
|
-
fs.closeSync(logFd);
|
|
142
|
-
// Poll for lockfile (server takes ~4-8s to load ecosystem)
|
|
143
|
-
const maxWait = 15000;
|
|
144
|
-
const pollInterval = 500;
|
|
145
|
-
const startTime = Date.now();
|
|
146
|
-
while (Date.now() - startTime < maxWait) {
|
|
147
|
-
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
148
|
-
// Check if child died
|
|
149
|
-
if (child.pid && !isProcessAlive(child.pid)) {
|
|
150
|
-
break;
|
|
151
|
-
}
|
|
152
|
-
// Check for lockfile
|
|
153
|
-
const lockfile = readLockfileForPort(port);
|
|
154
|
-
if (lockfile && (await checkServer(lockfile)) === "alive") {
|
|
155
|
-
return {
|
|
156
|
-
success: true,
|
|
157
|
-
pid: lockfile.pid,
|
|
158
|
-
port: lockfile.port,
|
|
159
|
-
endpoint: lockfile.endpoint,
|
|
160
|
-
logFile: LOG_PATH,
|
|
161
|
-
message: `Server started (PID ${lockfile.pid})`,
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
// Timed out waiting for lockfile, but child may still be alive
|
|
166
|
-
if (child.pid && isProcessAlive(child.pid)) {
|
|
167
|
-
return {
|
|
168
|
-
success: true,
|
|
169
|
-
pid: child.pid,
|
|
170
|
-
port,
|
|
171
|
-
endpoint: `http://${host === "0.0.0.0" ? "localhost" : host}:${port}/api`,
|
|
172
|
-
logFile: LOG_PATH,
|
|
173
|
-
message: `Server starting (PID ${child.pid}, still loading...)`,
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
return {
|
|
177
|
-
success: false,
|
|
178
|
-
message: `Failed to start server. Check ${LOG_PATH} for details.`,
|
|
179
|
-
};
|
|
180
|
-
})
|
|
181
|
-
.build();
|
|
182
|
-
//# sourceMappingURL=server.start.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.start.js","sourceRoot":"","sources":["../../src/procedures/server.start.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAgC,MAAM,oBAAoB,CAAC;AACnF,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAGlE,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC;AAClD,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;AACnD,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;AACnD,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;AAE1D,MAAM,uBAAuB,GAAG,UAAU,CAAoB,uBAAuB,C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AAI;gBACnB,QAAQ,EAAE,QAAQ,CAAC,QAAQ;gBAC3B,OAAO,EAAE,QAAQ;gBACjB,OAAO,EAAE,uBAAuB,QAAQ,CAAC,GAAG,GAAG;aAChD,CAAC;QACJ,CAAC;IACH,CAAC;IAED,+DAA+D;IAC/D,IAAI,KAAK,CAAC,GAAG,IAAI,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QAC3C,OAAO;YACL,OAAO,EAAE,IAAI;YACb,GAAG,EAAE,KAAK,CAAC,GAAG;YACd,IAAI;YACJ,QAAQ,EAAE,UAAU,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,IAAI,IAAI,MAAM;YACzE,OAAO,EAAE,QAAQ;YACjB,OAAO,EAAE,wBAAwB,KAAK,CAAC,GAAG,qBAAqB;SAChE,CAAC;IACJ,CAAC;IAED,OAAO;QACL,OAAO,EAAE,KAAK;QACd,OAAO,EAAE,iCAAiC,QAAQ,eAAe;KAClE,CAAC;AACJ,CAAC,CAAC;KACD,KAAK,EAAE,CAAC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Procedure: server.status
|
|
3
|
-
* Gets the current CLI server status
|
|
4
|
-
*/
|
|
5
|
-
import { type Effects, type Procedure } from "@procedures/client";
|
|
6
|
-
import type { ServerStatusInput, ServerStatusOutput } from "../types.js";
|
|
7
|
-
export declare const serverStatusProcedure: Procedure<ServerStatusInput, ServerStatusOutput, {
|
|
8
|
-
description: string;
|
|
9
|
-
effects: Effects;
|
|
10
|
-
output: string;
|
|
11
|
-
}>;
|
|
12
|
-
export type { ServerStatusInput, ServerStatusOutput };
|
|
13
|
-
//# sourceMappingURL=server.status.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.status.d.ts","sourceRoot":"","sources":["../../src/procedures/server.status.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAmB,KAAK,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAKnF,OAAO,KAAK,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAqCzE,eAAO,MAAM,qBAAqB,EAAE,SAAS,CAC3C,iBAAiB,EACjB,kBAAkB,EAClB;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAsFjD,CAAC;AAEX,YAAY,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,CAAC"}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Procedure: server.status
|
|
3
|
-
* Gets the current CLI server status
|
|
4
|
-
*/
|
|
5
|
-
import * as path from "node:path";
|
|
6
|
-
import * as os from "node:os";
|
|
7
|
-
import { createProcedure } from "@procedures/client";
|
|
8
|
-
import { wrapSchema } from "../schema.js";
|
|
9
|
-
import { ServerStatusOutputSchema } from "../output-schemas.js";
|
|
10
|
-
import { serverStatusInputSchema } from "../input-schemas.js";
|
|
11
|
-
import { checkServer, readAllLockfiles, readLockfileForPort, removeLockfileForPort } from "../lockfile.js";
|
|
12
|
-
const MARK_DIR = path.join(os.homedir(), ".mark");
|
|
13
|
-
const LOG_PATH = path.join(MARK_DIR, "server.log");
|
|
14
|
-
const serverStatusOutputSchema = wrapSchema(ServerStatusOutputSchema);
|
|
15
|
-
/**
|
|
16
|
-
* Format uptime as human-readable string
|
|
17
|
-
*/
|
|
18
|
-
function formatUptime(startedAt) {
|
|
19
|
-
const start = new Date(startedAt).getTime();
|
|
20
|
-
const now = Date.now();
|
|
21
|
-
const diff = Math.floor((now - start) / 1000);
|
|
22
|
-
if (diff < 60) {
|
|
23
|
-
return `${diff}s`;
|
|
24
|
-
}
|
|
25
|
-
if (diff < 3600) {
|
|
26
|
-
const mins = Math.floor(diff / 60);
|
|
27
|
-
const secs = diff % 60;
|
|
28
|
-
return `${mins}m ${secs}s`;
|
|
29
|
-
}
|
|
30
|
-
if (diff < 86400) {
|
|
31
|
-
const hours = Math.floor(diff / 3600);
|
|
32
|
-
const mins = Math.floor((diff % 3600) / 60);
|
|
33
|
-
return `${hours}h ${mins}m`;
|
|
34
|
-
}
|
|
35
|
-
const days = Math.floor(diff / 86400);
|
|
36
|
-
const hours = Math.floor((diff % 86400) / 3600);
|
|
37
|
-
return `${days}d ${hours}h`;
|
|
38
|
-
}
|
|
39
|
-
export const serverStatusProcedure = createProcedure()
|
|
40
|
-
.path(["server", "status"])
|
|
41
|
-
.input(serverStatusInputSchema)
|
|
42
|
-
.output(serverStatusOutputSchema)
|
|
43
|
-
.meta({
|
|
44
|
-
description: "Get CLI server status",
|
|
45
|
-
// It deletes the lockfile of a server that does not answer
|
|
46
|
-
effects: { reads: ["fs", "server"], writes: ["fs"], idempotent: true },
|
|
47
|
-
args: [],
|
|
48
|
-
shorts: { port: "p" },
|
|
49
|
-
output: "text",
|
|
50
|
-
})
|
|
51
|
-
.handler(async (input) => {
|
|
52
|
-
// Get target servers
|
|
53
|
-
let targets;
|
|
54
|
-
if (input.port !== undefined) {
|
|
55
|
-
const lockfile = readLockfileForPort(input.port);
|
|
56
|
-
targets = lockfile ? [lockfile] : [];
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
targets = readAllLockfiles();
|
|
60
|
-
}
|
|
61
|
-
if (targets.length === 0) {
|
|
62
|
-
return {
|
|
63
|
-
running: false,
|
|
64
|
-
message: input.port
|
|
65
|
-
? `No server found on port ${input.port}`
|
|
66
|
-
: "No servers running",
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
// For single server, return detailed info
|
|
70
|
-
if (targets.length === 1) {
|
|
71
|
-
const lockfile = targets[0];
|
|
72
|
-
const { pid, port, endpoint, startedAt, transport } = lockfile;
|
|
73
|
-
if ((await checkServer(lockfile)) !== "alive") {
|
|
74
|
-
removeLockfileForPort(port);
|
|
75
|
-
return {
|
|
76
|
-
running: false,
|
|
77
|
-
message: "Server is not running (cleaned up stale lockfile)",
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
const uptime = formatUptime(startedAt);
|
|
81
|
-
return {
|
|
82
|
-
running: true,
|
|
83
|
-
pid,
|
|
84
|
-
port,
|
|
85
|
-
endpoint,
|
|
86
|
-
transport,
|
|
87
|
-
startedAt,
|
|
88
|
-
uptime,
|
|
89
|
-
logFile: LOG_PATH,
|
|
90
|
-
message: `Server running (PID ${pid}, port ${port}, uptime ${uptime})`,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
// Multiple servers - summarize
|
|
94
|
-
const lines = [];
|
|
95
|
-
let anyRunning = false;
|
|
96
|
-
for (const lockfile of targets) {
|
|
97
|
-
const { pid, port, endpoint, startedAt } = lockfile;
|
|
98
|
-
if ((await checkServer(lockfile)) !== "alive") {
|
|
99
|
-
removeLockfileForPort(port);
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
anyRunning = true;
|
|
103
|
-
const uptime = formatUptime(startedAt);
|
|
104
|
-
lines.push(` Port ${port}: PID ${pid}, uptime ${uptime}, ${endpoint}`);
|
|
105
|
-
}
|
|
106
|
-
if (!anyRunning) {
|
|
107
|
-
return {
|
|
108
|
-
running: false,
|
|
109
|
-
message: "No servers running (cleaned up stale lockfiles)",
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
return {
|
|
113
|
-
running: true,
|
|
114
|
-
message: `${lines.length} server(s) running:\n${lines.join("\n")}`,
|
|
115
|
-
};
|
|
116
|
-
})
|
|
117
|
-
.build();
|
|
118
|
-
//# sourceMappingURL=server.status.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.status.js","sourceRoot":"","sources":["../../src/procedures/server.status.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,E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C,QAAQ,CAAC,CAAC,KAAK,OAAO,EAAE,CAAC;YAC9C,qBAAqB,CAAC,IAAI,CAAC,CAAC;YAC5B,SAAS;QACX,CAAC;QACD,UAAU,GAAG,IAAI,CAAC;QAClB,MAAM,MAAM,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC;QACvC,KAAK,CAAC,IAAI,CAAC,UAAU,IAAI,SAAS,GAAG,YAAY,MAAM,KAAK,QAAQ,EAAE,CAAC,CAAC;IAC1E,CAAC;IAED,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO;YACL,OAAO,EAAE,KAAK;YACd,OAAO,EAAE,iDAAiD;SAC3D,CAAC;IACJ,CAAC;IAED,OAAO;QACL,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,GAAG,KAAK,CAAC,MAAM,wBAAwB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;KACnE,CAAC;AACJ,CAAC,CAAC;KACD,KAAK,EAAE,CAAC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Procedure: server.stop
|
|
3
|
-
* Stops the running CLI server daemon
|
|
4
|
-
*/
|
|
5
|
-
import { type Effects, type Procedure } from "@procedures/client";
|
|
6
|
-
import type { ServerStopInput, ServerStopOutput } from "../types.js";
|
|
7
|
-
export declare const serverStopProcedure: Procedure<ServerStopInput, ServerStopOutput, {
|
|
8
|
-
description: string;
|
|
9
|
-
effects: Effects;
|
|
10
|
-
}>;
|
|
11
|
-
export type { ServerStopInput, ServerStopOutput };
|
|
12
|
-
//# sourceMappingURL=server.stop.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.stop.d.ts","sourceRoot":"","sources":["../../src/procedures/server.stop.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAmB,KAAK,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAKnF,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAqBrE,eAAO,MAAM,mBAAmB,EAAE,SAAS,CACzC,eAAe,EACf,gBAAgB,EAChB;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAsFjC,CAAC;AAEX,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Procedure: server.stop
|
|
3
|
-
* Stops the running CLI server daemon
|
|
4
|
-
*/
|
|
5
|
-
import { createProcedure } from "@procedures/client";
|
|
6
|
-
import { wrapSchema } from "../schema.js";
|
|
7
|
-
import { ServerStopOutputSchema } from "../output-schemas.js";
|
|
8
|
-
import { serverStopInputSchema } from "../input-schemas.js";
|
|
9
|
-
import { checkServer, readAllLockfiles, readLockfileForPort, removeLockfileForPort } from "../lockfile.js";
|
|
10
|
-
const serverStopOutputSchema = wrapSchema(ServerStopOutputSchema);
|
|
11
|
-
/**
|
|
12
|
-
* Kill process by PID
|
|
13
|
-
*/
|
|
14
|
-
function killProcess(pid, signal = "SIGTERM") {
|
|
15
|
-
try {
|
|
16
|
-
process.kill(pid, signal);
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
catch {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
export const serverStopProcedure = createProcedure()
|
|
24
|
-
.path(["server", "stop"])
|
|
25
|
-
.input(serverStopInputSchema)
|
|
26
|
-
.output(serverStopOutputSchema)
|
|
27
|
-
.meta({
|
|
28
|
-
description: "Stop running CLI server",
|
|
29
|
-
// It stops the servers of the lockfiles and deletes their lockfiles
|
|
30
|
-
effects: { reads: ["fs", "server"], writes: ["fs", "server"], idempotent: true },
|
|
31
|
-
args: [],
|
|
32
|
-
shorts: { port: "p" },
|
|
33
|
-
})
|
|
34
|
-
.handler(async (input) => {
|
|
35
|
-
const force = input.force ?? false;
|
|
36
|
-
const signal = force ? "SIGKILL" : "SIGTERM";
|
|
37
|
-
// Get target servers
|
|
38
|
-
let targets;
|
|
39
|
-
if (input.port !== undefined) {
|
|
40
|
-
const lockfile = readLockfileForPort(input.port);
|
|
41
|
-
targets = lockfile ? [lockfile] : [];
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
targets = readAllLockfiles();
|
|
45
|
-
}
|
|
46
|
-
if (targets.length === 0) {
|
|
47
|
-
return {
|
|
48
|
-
success: false,
|
|
49
|
-
message: input.port
|
|
50
|
-
? `No server found on port ${input.port}`
|
|
51
|
-
: "No servers running",
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
const results = [];
|
|
55
|
-
let allSuccess = true;
|
|
56
|
-
for (const lockfile of targets) {
|
|
57
|
-
const { pid, port } = lockfile;
|
|
58
|
-
// Signal the PID only when the server answers as the peer of this lockfile: Windows reuses
|
|
59
|
-
// PIDs, and before, a stale lockfile made this kill an unrelated process (deep dive CLI-4)
|
|
60
|
-
const state = await checkServer(lockfile);
|
|
61
|
-
if (state !== "alive") {
|
|
62
|
-
removeLockfileForPort(port);
|
|
63
|
-
results.push(state === "dead"
|
|
64
|
-
? `Port ${port}: cleaned up stale lockfile`
|
|
65
|
-
: `Port ${port}: another process answers on this port; nothing stopped (stale lockfile removed)`);
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
const sent = killProcess(pid, signal);
|
|
69
|
-
if (!sent) {
|
|
70
|
-
allSuccess = false;
|
|
71
|
-
results.push(`Port ${port}: failed to send ${signal} to PID ${pid}`);
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
// Wait for process to die
|
|
75
|
-
const maxWait = force ? 500 : 5000;
|
|
76
|
-
const startTime = Date.now();
|
|
77
|
-
let stopped = false;
|
|
78
|
-
while (Date.now() - startTime < maxWait) {
|
|
79
|
-
if ((await checkServer(lockfile, 300)) === "dead") {
|
|
80
|
-
removeLockfileForPort(port);
|
|
81
|
-
results.push(`Port ${port}: stopped (PID ${pid})`);
|
|
82
|
-
stopped = true;
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
86
|
-
}
|
|
87
|
-
if (!stopped) {
|
|
88
|
-
allSuccess = false;
|
|
89
|
-
results.push(`Port ${port}: PID ${pid} did not stop${force ? "" : " (try --force)"}`);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return {
|
|
93
|
-
success: allSuccess,
|
|
94
|
-
message: results.join("\n"),
|
|
95
|
-
};
|
|
96
|
-
})
|
|
97
|
-
.build();
|
|
98
|
-
//# sourceMappingURL=server.stop.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.stop.js","sourceRoot":"","sources":["../../src/procedures/server.stop.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAgC,MAAM,oBAAoB,CAAC;AACnF,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,qBAAqB,EAAqB,MAAM,gBAAgB,CAAC;AAI9H,MAAM,sBAAsB,GAAG,UAAU,CAAmB,sBAAsB,CAAC,CAAC;AAMpF;;GAEG;AACH,SAAS,WAAW,CAAC,GAAW,EAAE,MAAM,GAAmB,SAAS;IAClE,IAAI,CAAC;QACH,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,mBAAmB,GAI5B,eAAe,EAAE;KAClB,IAAI,CAAC,CAAC,QAAQ,EAAE,MAAM,CAAC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