@mog-sdk/cli 0.8.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/README.md +8 -0
- package/dist/mog.cjs +499 -0
- package/dist/mog.cjs.map +1 -0
- package/package.json +28 -0
package/README.md
ADDED
package/dist/mog.cjs
ADDED
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
|
|
26
|
+
// ../node_modules/.pnpm/tsup@8.5.1_@microsoft+api-extractor@7.58.7_@types+node@25.9.1__jiti@2.7.0_postcss@8.5.15_tsx@4.22.3_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js
|
|
27
|
+
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
|
|
28
|
+
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
29
|
+
|
|
30
|
+
// src/mog.ts
|
|
31
|
+
var import_node_child_process = require("child_process");
|
|
32
|
+
var import_node_crypto2 = require("crypto");
|
|
33
|
+
var import_node_fs = require("fs");
|
|
34
|
+
var import_promises = require("fs/promises");
|
|
35
|
+
var import_node_net = __toESM(require("net"), 1);
|
|
36
|
+
var import_node_path2 = require("path");
|
|
37
|
+
var import_node_url = require("url");
|
|
38
|
+
var import_node = require("@mog-sdk/node");
|
|
39
|
+
|
|
40
|
+
// src/protocol.ts
|
|
41
|
+
var import_node_crypto = require("crypto");
|
|
42
|
+
var import_node_os = require("os");
|
|
43
|
+
var import_node_path = require("path");
|
|
44
|
+
function parseCliArgs(argv) {
|
|
45
|
+
const [command, ...rest] = argv;
|
|
46
|
+
switch (command) {
|
|
47
|
+
case void 0:
|
|
48
|
+
case "-h":
|
|
49
|
+
case "--help":
|
|
50
|
+
case "help":
|
|
51
|
+
return { kind: "help" };
|
|
52
|
+
case "_daemon": {
|
|
53
|
+
const stateKey = rest[0];
|
|
54
|
+
if (!stateKey) throw new Error("Internal error: _daemon requires a state key.");
|
|
55
|
+
return { kind: "daemon", stateKey };
|
|
56
|
+
}
|
|
57
|
+
case "create": {
|
|
58
|
+
return parseCreateCommand(rest);
|
|
59
|
+
}
|
|
60
|
+
case "load": {
|
|
61
|
+
const path = rest[0];
|
|
62
|
+
if (!path) throw new Error("Usage: mog load <path>");
|
|
63
|
+
return { kind: "load", path: (0, import_node_path.resolve)(path) };
|
|
64
|
+
}
|
|
65
|
+
case "execute": {
|
|
66
|
+
return {
|
|
67
|
+
kind: "execute",
|
|
68
|
+
id: requiredOption(rest, "--id", "Usage: mog execute --id <workbookId> --code <code>"),
|
|
69
|
+
code: optionalOption(rest, "--code"),
|
|
70
|
+
codeFile: optionalOption(rest, "--code-file")
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
case "commit":
|
|
74
|
+
return {
|
|
75
|
+
kind: "commit",
|
|
76
|
+
id: requiredOption(rest, "--id", "Usage: mog commit --id <workbookId> [--path <path>]"),
|
|
77
|
+
path: optionalOption(rest, "--path")
|
|
78
|
+
};
|
|
79
|
+
case "unload":
|
|
80
|
+
return {
|
|
81
|
+
kind: "unload",
|
|
82
|
+
id: requiredOption(rest, "--id", "Usage: mog unload --id <workbookId>")
|
|
83
|
+
};
|
|
84
|
+
case "list":
|
|
85
|
+
return { kind: "list" };
|
|
86
|
+
case "shutdown":
|
|
87
|
+
return { kind: "shutdown" };
|
|
88
|
+
default:
|
|
89
|
+
throw new Error(`Unknown command: ${command}
|
|
90
|
+
|
|
91
|
+
${usage()}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function stateKeyForCwd(cwd = process.cwd()) {
|
|
95
|
+
return (0, import_node_crypto.createHash)("sha256").update(cwd).digest("hex").slice(0, 20);
|
|
96
|
+
}
|
|
97
|
+
function socketPathForState(stateKey) {
|
|
98
|
+
return process.env.MOG_CLI_SOCKET ?? (0, import_node_path.join)((0, import_node_os.tmpdir)(), `mog-${stateKey}.sock`);
|
|
99
|
+
}
|
|
100
|
+
function pidPathForState(stateKey) {
|
|
101
|
+
return process.env.MOG_CLI_PID ?? (0, import_node_path.join)((0, import_node_os.tmpdir)(), `mog-${stateKey}.pid`);
|
|
102
|
+
}
|
|
103
|
+
function toJsonSafe(value) {
|
|
104
|
+
return toJsonSafeInner(value, /* @__PURE__ */ new WeakSet());
|
|
105
|
+
}
|
|
106
|
+
function usage() {
|
|
107
|
+
return [
|
|
108
|
+
"Usage:",
|
|
109
|
+
" mog create <path>",
|
|
110
|
+
" mog create --name <workbookName> --path <directory>",
|
|
111
|
+
" mog load <path>",
|
|
112
|
+
" mog execute --id <workbookId> --code <code>",
|
|
113
|
+
" mog execute --id <workbookId> --code-file <path>",
|
|
114
|
+
" mog commit --id <workbookId> [--path <path>]",
|
|
115
|
+
" mog unload --id <workbookId>",
|
|
116
|
+
" mog list",
|
|
117
|
+
"",
|
|
118
|
+
"Execute code runs inside the Mog daemon with these bindings:",
|
|
119
|
+
" wb, workbook, ws, activeSheet, api, Utils, console",
|
|
120
|
+
"",
|
|
121
|
+
"Example:",
|
|
122
|
+
' mog execute --id abc --code "await ws.setCell(\\"A1\\", 42); return ws.getValue(\\"A1\\");"'
|
|
123
|
+
].join("\n");
|
|
124
|
+
}
|
|
125
|
+
function parseCreateCommand(args) {
|
|
126
|
+
const directPath = args[0] && !args[0].startsWith("--") ? args[0] : void 0;
|
|
127
|
+
const name = optionalOption(args, "--name");
|
|
128
|
+
const directory = optionalOption(args, "--path");
|
|
129
|
+
if (directPath) {
|
|
130
|
+
if (name || directory) {
|
|
131
|
+
throw new Error(
|
|
132
|
+
"Usage: mog create <path>\n mog create --name <workbookName> --path <directory>"
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
kind: "create",
|
|
137
|
+
path: (0, import_node_path.resolve)(directPath),
|
|
138
|
+
name: workbookNameFromPath(directPath)
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
if (!name || !directory) {
|
|
142
|
+
throw new Error(
|
|
143
|
+
"Usage: mog create <path>\n mog create --name <workbookName> --path <directory>"
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
kind: "create",
|
|
148
|
+
path: (0, import_node_path.resolve)(directory, workbookFileName(name)),
|
|
149
|
+
name: workbookNameFromPath(name)
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function requiredOption(args, name, errorMessage) {
|
|
153
|
+
const value = optionalOption(args, name);
|
|
154
|
+
if (!value) throw new Error(errorMessage);
|
|
155
|
+
return value;
|
|
156
|
+
}
|
|
157
|
+
function optionalOption(args, name) {
|
|
158
|
+
const index = args.indexOf(name);
|
|
159
|
+
if (index === -1) return void 0;
|
|
160
|
+
const value = args[index + 1];
|
|
161
|
+
if (!value || value.startsWith("--")) {
|
|
162
|
+
throw new Error(`Missing value for ${name}`);
|
|
163
|
+
}
|
|
164
|
+
return value;
|
|
165
|
+
}
|
|
166
|
+
function workbookFileName(name) {
|
|
167
|
+
const trimmed = name.trim();
|
|
168
|
+
if (!trimmed) throw new Error("Workbook name must not be empty.");
|
|
169
|
+
if (trimmed.includes("/") || trimmed.includes("\\")) {
|
|
170
|
+
throw new Error("Workbook name must not contain path separators.");
|
|
171
|
+
}
|
|
172
|
+
return trimmed.toLowerCase().endsWith(".xlsx") ? trimmed : `${trimmed}.xlsx`;
|
|
173
|
+
}
|
|
174
|
+
function workbookNameFromPath(path) {
|
|
175
|
+
return (0, import_node_path.basename)(path).replace(/\.xlsx$/i, "");
|
|
176
|
+
}
|
|
177
|
+
function toJsonSafeInner(value, seen) {
|
|
178
|
+
if (value == null) return value;
|
|
179
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
180
|
+
return value;
|
|
181
|
+
}
|
|
182
|
+
if (typeof value === "bigint") return value.toString();
|
|
183
|
+
if (typeof value === "function") {
|
|
184
|
+
return `[Function ${value.name || "anonymous"}]`;
|
|
185
|
+
}
|
|
186
|
+
if (value instanceof Date) return value.toISOString();
|
|
187
|
+
if (value instanceof Uint8Array) {
|
|
188
|
+
return {
|
|
189
|
+
type: "Uint8Array",
|
|
190
|
+
length: value.byteLength,
|
|
191
|
+
base64: Buffer.from(value).toString("base64")
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
if (Array.isArray(value)) return value.map((entry) => toJsonSafeInner(entry, seen));
|
|
195
|
+
if (value instanceof Map) {
|
|
196
|
+
return Object.fromEntries(
|
|
197
|
+
[...value.entries()].map(([key, entry]) => [String(key), toJsonSafeInner(entry, seen)])
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
if (value instanceof Set) return [...value].map((entry) => toJsonSafeInner(entry, seen));
|
|
201
|
+
if (typeof value === "object") {
|
|
202
|
+
if (seen.has(value)) return "[Circular]";
|
|
203
|
+
seen.add(value);
|
|
204
|
+
return Object.fromEntries(
|
|
205
|
+
Object.entries(value).map(([key, entry]) => [key, toJsonSafeInner(entry, seen)])
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
return String(value);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// src/mog.ts
|
|
212
|
+
var workbooks = /* @__PURE__ */ new Map();
|
|
213
|
+
async function main() {
|
|
214
|
+
const command = parseCliArgs(process.argv.slice(2));
|
|
215
|
+
if (command.kind === "help") {
|
|
216
|
+
console.log(usage());
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
if (command.kind === "daemon") {
|
|
220
|
+
await runDaemon(command.stateKey);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
const stateKey = stateKeyForCwd();
|
|
224
|
+
const request = await commandToRequest(command);
|
|
225
|
+
const response = await sendWithAutoStart(stateKey, request);
|
|
226
|
+
if (!response.ok) {
|
|
227
|
+
console.error(JSON.stringify(response, null, 2));
|
|
228
|
+
process.exitCode = 1;
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
console.log(JSON.stringify(response.result, null, 2));
|
|
232
|
+
}
|
|
233
|
+
async function commandToRequest(command) {
|
|
234
|
+
switch (command.kind) {
|
|
235
|
+
case "create":
|
|
236
|
+
return {
|
|
237
|
+
method: "create",
|
|
238
|
+
path: command.path,
|
|
239
|
+
...command.name ? { name: command.name } : {}
|
|
240
|
+
};
|
|
241
|
+
case "load":
|
|
242
|
+
return { method: "load", path: command.path };
|
|
243
|
+
case "execute": {
|
|
244
|
+
const code = command.codeFile ? await (0, import_promises.readFile)((0, import_node_path2.resolve)(command.codeFile), "utf8") : command.code;
|
|
245
|
+
if (!code) {
|
|
246
|
+
throw new Error("Usage: mog execute --id <workbookId> --code <code>");
|
|
247
|
+
}
|
|
248
|
+
return { method: "execute", id: command.id, code };
|
|
249
|
+
}
|
|
250
|
+
case "commit":
|
|
251
|
+
return {
|
|
252
|
+
method: "commit",
|
|
253
|
+
id: command.id,
|
|
254
|
+
...command.path ? { path: (0, import_node_path2.resolve)(command.path) } : {}
|
|
255
|
+
};
|
|
256
|
+
case "unload":
|
|
257
|
+
return { method: "unload", id: command.id };
|
|
258
|
+
case "list":
|
|
259
|
+
return { method: "list" };
|
|
260
|
+
case "shutdown":
|
|
261
|
+
return { method: "shutdown" };
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
async function sendWithAutoStart(stateKey, request) {
|
|
265
|
+
try {
|
|
266
|
+
return await sendRequest(stateKey, request);
|
|
267
|
+
} catch {
|
|
268
|
+
await startDaemon(stateKey);
|
|
269
|
+
await waitForDaemon(stateKey);
|
|
270
|
+
return sendRequest(stateKey, request);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
async function startDaemon(stateKey) {
|
|
274
|
+
const cliPath = (0, import_node_url.fileURLToPath)(importMetaUrl);
|
|
275
|
+
const child = (0, import_node_child_process.spawn)(process.execPath, [cliPath, "_daemon", stateKey], {
|
|
276
|
+
detached: true,
|
|
277
|
+
stdio: "ignore",
|
|
278
|
+
env: process.env
|
|
279
|
+
});
|
|
280
|
+
child.unref();
|
|
281
|
+
}
|
|
282
|
+
async function waitForDaemon(stateKey) {
|
|
283
|
+
const started = Date.now();
|
|
284
|
+
let lastError;
|
|
285
|
+
while (Date.now() - started < 5e3) {
|
|
286
|
+
try {
|
|
287
|
+
await sendRequest(stateKey, { method: "ping" });
|
|
288
|
+
return;
|
|
289
|
+
} catch (error) {
|
|
290
|
+
lastError = error;
|
|
291
|
+
await new Promise((resolveWait) => setTimeout(resolveWait, 100));
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
throw new Error(`Mog daemon did not start: ${String(lastError)}`);
|
|
295
|
+
}
|
|
296
|
+
function sendRequest(stateKey, request) {
|
|
297
|
+
const socketPath = socketPathForState(stateKey);
|
|
298
|
+
return new Promise((resolveRequest, rejectRequest) => {
|
|
299
|
+
const client = import_node_net.default.createConnection(socketPath);
|
|
300
|
+
let data = "";
|
|
301
|
+
client.setEncoding("utf8");
|
|
302
|
+
client.setTimeout(5e3);
|
|
303
|
+
client.on("connect", () => {
|
|
304
|
+
client.end(JSON.stringify(request));
|
|
305
|
+
});
|
|
306
|
+
client.on("data", (chunk) => {
|
|
307
|
+
data += chunk;
|
|
308
|
+
});
|
|
309
|
+
client.on("end", () => {
|
|
310
|
+
try {
|
|
311
|
+
resolveRequest(JSON.parse(data));
|
|
312
|
+
} catch (error) {
|
|
313
|
+
rejectRequest(error);
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
client.on("timeout", () => {
|
|
317
|
+
client.destroy(new Error("Timed out waiting for Mog daemon response."));
|
|
318
|
+
});
|
|
319
|
+
client.on("error", rejectRequest);
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
async function runDaemon(stateKey) {
|
|
323
|
+
const socketPath = socketPathForState(stateKey);
|
|
324
|
+
const pidPath = pidPathForState(stateKey);
|
|
325
|
+
if ((0, import_node_fs.existsSync)(socketPath)) {
|
|
326
|
+
(0, import_node_fs.unlinkSync)(socketPath);
|
|
327
|
+
}
|
|
328
|
+
const server = import_node_net.default.createServer({ allowHalfOpen: true }, (socket) => {
|
|
329
|
+
let data = "";
|
|
330
|
+
socket.setEncoding("utf8");
|
|
331
|
+
socket.on("data", (chunk) => {
|
|
332
|
+
data += chunk;
|
|
333
|
+
});
|
|
334
|
+
socket.on("end", () => {
|
|
335
|
+
void handleRawRequest(data, server).then((response) => {
|
|
336
|
+
socket.end(JSON.stringify(response));
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
await new Promise((resolveListen, rejectListen) => {
|
|
341
|
+
server.once("error", rejectListen);
|
|
342
|
+
server.listen(socketPath, () => {
|
|
343
|
+
server.off("error", rejectListen);
|
|
344
|
+
(0, import_node_fs.writeFileSync)(pidPath, String(process.pid));
|
|
345
|
+
resolveListen();
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
const cleanup = async () => {
|
|
349
|
+
for (const entry of workbooks.values()) {
|
|
350
|
+
await Promise.resolve(entry.workbook.dispose());
|
|
351
|
+
}
|
|
352
|
+
workbooks.clear();
|
|
353
|
+
await (0, import_promises.unlink)(socketPath).catch(() => void 0);
|
|
354
|
+
await (0, import_promises.unlink)(pidPath).catch(() => void 0);
|
|
355
|
+
};
|
|
356
|
+
process.once("SIGTERM", () => {
|
|
357
|
+
void cleanup().finally(() => process.exit(0));
|
|
358
|
+
});
|
|
359
|
+
process.once("SIGINT", () => {
|
|
360
|
+
void cleanup().finally(() => process.exit(0));
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
async function handleRawRequest(raw, server) {
|
|
364
|
+
try {
|
|
365
|
+
const request = JSON.parse(raw);
|
|
366
|
+
return { ok: true, result: await handleRequest(request, server) };
|
|
367
|
+
} catch (error) {
|
|
368
|
+
return {
|
|
369
|
+
ok: false,
|
|
370
|
+
error: {
|
|
371
|
+
message: error instanceof Error ? error.message : String(error),
|
|
372
|
+
...error instanceof Error && error.stack ? { stack: error.stack } : {}
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
async function handleRequest(request, server) {
|
|
378
|
+
switch (request.method) {
|
|
379
|
+
case "ping":
|
|
380
|
+
return { status: "ok", handles: workbooks.size };
|
|
381
|
+
case "create": {
|
|
382
|
+
if ((0, import_node_fs.existsSync)(request.path)) {
|
|
383
|
+
throw new Error(`Workbook already exists: ${request.path}`);
|
|
384
|
+
}
|
|
385
|
+
await (0, import_promises.mkdir)((0, import_node_path2.dirname)(request.path), { recursive: true });
|
|
386
|
+
const workbook = request.name ? await (0, import_node.createWorkbook)({ documentId: request.name }) : await (0, import_node.createWorkbook)();
|
|
387
|
+
await workbook.save(request.path);
|
|
388
|
+
const id = (0, import_node_crypto2.randomUUID)();
|
|
389
|
+
const entry = { id, path: request.path, workbook, loadedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
390
|
+
workbooks.set(id, entry);
|
|
391
|
+
return describeEntry(entry);
|
|
392
|
+
}
|
|
393
|
+
case "load": {
|
|
394
|
+
await (0, import_promises.stat)(request.path);
|
|
395
|
+
const workbook = await (0, import_node.createWorkbook)(request.path);
|
|
396
|
+
const id = (0, import_node_crypto2.randomUUID)();
|
|
397
|
+
const entry = { id, path: request.path, workbook, loadedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
398
|
+
workbooks.set(id, entry);
|
|
399
|
+
return describeEntry(entry);
|
|
400
|
+
}
|
|
401
|
+
case "execute": {
|
|
402
|
+
const entry = requireWorkbook(request.id);
|
|
403
|
+
const logs = [];
|
|
404
|
+
const scopedConsole = makeScopedConsole(logs);
|
|
405
|
+
const AsyncFunction = Object.getPrototypeOf(async function() {
|
|
406
|
+
}).constructor;
|
|
407
|
+
const fn = new AsyncFunction(
|
|
408
|
+
"wb",
|
|
409
|
+
"workbook",
|
|
410
|
+
"ws",
|
|
411
|
+
"activeSheet",
|
|
412
|
+
"api",
|
|
413
|
+
"Utils",
|
|
414
|
+
"console",
|
|
415
|
+
`"use strict";
|
|
416
|
+
${request.code}`
|
|
417
|
+
);
|
|
418
|
+
const result = await fn(
|
|
419
|
+
entry.workbook,
|
|
420
|
+
entry.workbook,
|
|
421
|
+
entry.workbook.activeSheet,
|
|
422
|
+
entry.workbook.activeSheet,
|
|
423
|
+
import_node.api,
|
|
424
|
+
import_node.Utils,
|
|
425
|
+
scopedConsole
|
|
426
|
+
);
|
|
427
|
+
return { result: toJsonSafe(result), logs };
|
|
428
|
+
}
|
|
429
|
+
case "commit": {
|
|
430
|
+
const entry = requireWorkbook(request.id);
|
|
431
|
+
const path = request.path ?? entry.path;
|
|
432
|
+
const bytes = await entry.workbook.save(path);
|
|
433
|
+
return { id: entry.id, path, bytes: bytes.byteLength };
|
|
434
|
+
}
|
|
435
|
+
case "unload": {
|
|
436
|
+
const entry = requireWorkbook(request.id);
|
|
437
|
+
await Promise.resolve(entry.workbook.dispose());
|
|
438
|
+
workbooks.delete(entry.id);
|
|
439
|
+
return { id: entry.id, unloaded: true };
|
|
440
|
+
}
|
|
441
|
+
case "list":
|
|
442
|
+
return [...workbooks.values()].map(describeEntry);
|
|
443
|
+
case "shutdown":
|
|
444
|
+
for (const entry of workbooks.values()) {
|
|
445
|
+
await Promise.resolve(entry.workbook.dispose());
|
|
446
|
+
}
|
|
447
|
+
workbooks.clear();
|
|
448
|
+
server.close();
|
|
449
|
+
return { shutdown: true };
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
function requireWorkbook(id) {
|
|
453
|
+
const entry = workbooks.get(id);
|
|
454
|
+
if (!entry) throw new Error(`Unknown workbook id: ${id}`);
|
|
455
|
+
return entry;
|
|
456
|
+
}
|
|
457
|
+
function describeEntry(entry) {
|
|
458
|
+
return {
|
|
459
|
+
id: entry.id,
|
|
460
|
+
path: entry.path,
|
|
461
|
+
loadedAt: entry.loadedAt
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
function makeScopedConsole(logs) {
|
|
465
|
+
const push = (level, args) => {
|
|
466
|
+
logs.push(`[${level}] ${args.map(formatLogArg).join(" ")}`);
|
|
467
|
+
};
|
|
468
|
+
return {
|
|
469
|
+
log: (...args) => push("log", args),
|
|
470
|
+
info: (...args) => push("info", args),
|
|
471
|
+
warn: (...args) => push("warn", args),
|
|
472
|
+
error: (...args) => push("error", args)
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
function formatLogArg(arg) {
|
|
476
|
+
if (typeof arg === "string") return arg;
|
|
477
|
+
try {
|
|
478
|
+
return JSON.stringify(toJsonSafe(arg));
|
|
479
|
+
} catch {
|
|
480
|
+
return String(arg);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
main().catch((error) => {
|
|
484
|
+
console.error(
|
|
485
|
+
JSON.stringify(
|
|
486
|
+
{
|
|
487
|
+
ok: false,
|
|
488
|
+
error: {
|
|
489
|
+
message: error instanceof Error ? error.message : String(error),
|
|
490
|
+
...error instanceof Error && error.stack ? { stack: error.stack } : {}
|
|
491
|
+
}
|
|
492
|
+
},
|
|
493
|
+
null,
|
|
494
|
+
2
|
|
495
|
+
)
|
|
496
|
+
);
|
|
497
|
+
process.exitCode = 1;
|
|
498
|
+
});
|
|
499
|
+
//# sourceMappingURL=mog.cjs.map
|
package/dist/mog.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../node_modules/.pnpm/tsup@8.5.1_@microsoft+api-extractor@7.58.7_@types+node@25.9.1__jiti@2.7.0_postcss@8.5.15_tsx@4.22.3_typescript@5.9.3/node_modules/tsup/assets/cjs_shims.js","../src/mog.ts","../src/protocol.ts"],"sourcesContent":["// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () => \n typeof document === \"undefined\" \n ? new URL(`file:${__filename}`).href \n : (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT') \n ? document.currentScript.src \n : new URL(\"main.js\", document.baseURI).href;\n\nexport const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()\n","#!/usr/bin/env node\nimport { spawn } from 'node:child_process';\nimport { randomUUID } from 'node:crypto';\nimport { existsSync, unlinkSync, writeFileSync } from 'node:fs';\nimport { mkdir, readFile, stat, unlink } from 'node:fs/promises';\nimport net from 'node:net';\nimport { dirname, resolve } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { api, createWorkbook, Utils, type Workbook } from '@mog-sdk/node';\nimport {\n parseCliArgs,\n pidPathForState,\n socketPathForState,\n stateKeyForCwd,\n toJsonSafe,\n usage,\n type DaemonRequest,\n type DaemonResponse,\n} from './protocol';\n\ntype WorkbookEntry = {\n id: string;\n path: string;\n workbook: Workbook;\n loadedAt: string;\n};\n\nconst workbooks = new Map<string, WorkbookEntry>();\n\nasync function main(): Promise<void> {\n const command = parseCliArgs(process.argv.slice(2));\n\n if (command.kind === 'help') {\n console.log(usage());\n return;\n }\n\n if (command.kind === 'daemon') {\n await runDaemon(command.stateKey);\n return;\n }\n\n const stateKey = stateKeyForCwd();\n const request = await commandToRequest(command);\n const response = await sendWithAutoStart(stateKey, request);\n if (!response.ok) {\n console.error(JSON.stringify(response, null, 2));\n process.exitCode = 1;\n return;\n }\n console.log(JSON.stringify(response.result, null, 2));\n}\n\nasync function commandToRequest(\n command: Exclude<ReturnType<typeof parseCliArgs>, { kind: 'help' | 'daemon' }>,\n): Promise<DaemonRequest> {\n switch (command.kind) {\n case 'create':\n return {\n method: 'create',\n path: command.path,\n ...(command.name ? { name: command.name } : {}),\n };\n case 'load':\n return { method: 'load', path: command.path };\n case 'execute': {\n const code = command.codeFile\n ? await readFile(resolve(command.codeFile), 'utf8')\n : command.code;\n if (!code) {\n throw new Error('Usage: mog execute --id <workbookId> --code <code>');\n }\n return { method: 'execute', id: command.id, code };\n }\n case 'commit':\n return {\n method: 'commit',\n id: command.id,\n ...(command.path ? { path: resolve(command.path) } : {}),\n };\n case 'unload':\n return { method: 'unload', id: command.id };\n case 'list':\n return { method: 'list' };\n case 'shutdown':\n return { method: 'shutdown' };\n }\n}\n\nasync function sendWithAutoStart(\n stateKey: string,\n request: DaemonRequest,\n): Promise<DaemonResponse> {\n try {\n return await sendRequest(stateKey, request);\n } catch {\n await startDaemon(stateKey);\n await waitForDaemon(stateKey);\n return sendRequest(stateKey, request);\n }\n}\n\nasync function startDaemon(stateKey: string): Promise<void> {\n const cliPath = fileURLToPath(import.meta.url);\n const child = spawn(process.execPath, [cliPath, '_daemon', stateKey], {\n detached: true,\n stdio: 'ignore',\n env: process.env,\n });\n child.unref();\n}\n\nasync function waitForDaemon(stateKey: string): Promise<void> {\n const started = Date.now();\n let lastError: unknown;\n while (Date.now() - started < 5000) {\n try {\n await sendRequest(stateKey, { method: 'ping' });\n return;\n } catch (error) {\n lastError = error;\n await new Promise((resolveWait) => setTimeout(resolveWait, 100));\n }\n }\n throw new Error(`Mog daemon did not start: ${String(lastError)}`);\n}\n\nfunction sendRequest(stateKey: string, request: DaemonRequest): Promise<DaemonResponse> {\n const socketPath = socketPathForState(stateKey);\n return new Promise((resolveRequest, rejectRequest) => {\n const client = net.createConnection(socketPath);\n let data = '';\n client.setEncoding('utf8');\n client.setTimeout(5000);\n client.on('connect', () => {\n client.end(JSON.stringify(request));\n });\n client.on('data', (chunk) => {\n data += chunk;\n });\n client.on('end', () => {\n try {\n resolveRequest(JSON.parse(data) as DaemonResponse);\n } catch (error) {\n rejectRequest(error);\n }\n });\n client.on('timeout', () => {\n client.destroy(new Error('Timed out waiting for Mog daemon response.'));\n });\n client.on('error', rejectRequest);\n });\n}\n\nasync function runDaemon(stateKey: string): Promise<void> {\n const socketPath = socketPathForState(stateKey);\n const pidPath = pidPathForState(stateKey);\n if (existsSync(socketPath)) {\n unlinkSync(socketPath);\n }\n\n const server = net.createServer({ allowHalfOpen: true }, (socket) => {\n let data = '';\n socket.setEncoding('utf8');\n socket.on('data', (chunk) => {\n data += chunk;\n });\n socket.on('end', () => {\n void handleRawRequest(data, server).then((response) => {\n socket.end(JSON.stringify(response));\n });\n });\n });\n\n await new Promise<void>((resolveListen, rejectListen) => {\n server.once('error', rejectListen);\n server.listen(socketPath, () => {\n server.off('error', rejectListen);\n writeFileSync(pidPath, String(process.pid));\n resolveListen();\n });\n });\n\n const cleanup = async () => {\n for (const entry of workbooks.values()) {\n await Promise.resolve(entry.workbook.dispose());\n }\n workbooks.clear();\n await unlink(socketPath).catch(() => undefined);\n await unlink(pidPath).catch(() => undefined);\n };\n\n process.once('SIGTERM', () => {\n void cleanup().finally(() => process.exit(0));\n });\n process.once('SIGINT', () => {\n void cleanup().finally(() => process.exit(0));\n });\n}\n\nasync function handleRawRequest(raw: string, server: net.Server): Promise<DaemonResponse> {\n try {\n const request = JSON.parse(raw) as DaemonRequest;\n return { ok: true, result: await handleRequest(request, server) };\n } catch (error) {\n return {\n ok: false,\n error: {\n message: error instanceof Error ? error.message : String(error),\n ...(error instanceof Error && error.stack ? { stack: error.stack } : {}),\n },\n };\n }\n}\n\nasync function handleRequest(request: DaemonRequest, server: net.Server): Promise<unknown> {\n switch (request.method) {\n case 'ping':\n return { status: 'ok', handles: workbooks.size };\n case 'create': {\n if (existsSync(request.path)) {\n throw new Error(`Workbook already exists: ${request.path}`);\n }\n await mkdir(dirname(request.path), { recursive: true });\n const workbook = request.name\n ? await createWorkbook({ documentId: request.name })\n : await createWorkbook();\n await workbook.save(request.path);\n const id = randomUUID();\n const entry = { id, path: request.path, workbook, loadedAt: new Date().toISOString() };\n workbooks.set(id, entry);\n return describeEntry(entry);\n }\n case 'load': {\n await stat(request.path);\n const workbook = await createWorkbook(request.path);\n const id = randomUUID();\n const entry = { id, path: request.path, workbook, loadedAt: new Date().toISOString() };\n workbooks.set(id, entry);\n return describeEntry(entry);\n }\n case 'execute': {\n const entry = requireWorkbook(request.id);\n const logs: string[] = [];\n const scopedConsole = makeScopedConsole(logs);\n const AsyncFunction = Object.getPrototypeOf(async function () {\n // TypeScript target helper.\n }).constructor as new (...args: string[]) => (...args: unknown[]) => Promise<unknown>;\n const fn = new AsyncFunction(\n 'wb',\n 'workbook',\n 'ws',\n 'activeSheet',\n 'api',\n 'Utils',\n 'console',\n `\"use strict\";\\n${request.code}`,\n );\n const result = await fn(\n entry.workbook,\n entry.workbook,\n entry.workbook.activeSheet,\n entry.workbook.activeSheet,\n api,\n Utils,\n scopedConsole,\n );\n return { result: toJsonSafe(result), logs };\n }\n case 'commit': {\n const entry = requireWorkbook(request.id);\n const path = request.path ?? entry.path;\n const bytes = await entry.workbook.save(path);\n return { id: entry.id, path, bytes: bytes.byteLength };\n }\n case 'unload': {\n const entry = requireWorkbook(request.id);\n await Promise.resolve(entry.workbook.dispose());\n workbooks.delete(entry.id);\n return { id: entry.id, unloaded: true };\n }\n case 'list':\n return [...workbooks.values()].map(describeEntry);\n case 'shutdown':\n for (const entry of workbooks.values()) {\n await Promise.resolve(entry.workbook.dispose());\n }\n workbooks.clear();\n server.close();\n return { shutdown: true };\n }\n}\n\nfunction requireWorkbook(id: string): WorkbookEntry {\n const entry = workbooks.get(id);\n if (!entry) throw new Error(`Unknown workbook id: ${id}`);\n return entry;\n}\n\nfunction describeEntry(entry: WorkbookEntry): object {\n return {\n id: entry.id,\n path: entry.path,\n loadedAt: entry.loadedAt,\n };\n}\n\nfunction makeScopedConsole(logs: string[]): Pick<Console, 'log' | 'warn' | 'error' | 'info'> {\n const push = (level: string, args: unknown[]) => {\n logs.push(`[${level}] ${args.map(formatLogArg).join(' ')}`);\n };\n return {\n log: (...args: unknown[]) => push('log', args),\n info: (...args: unknown[]) => push('info', args),\n warn: (...args: unknown[]) => push('warn', args),\n error: (...args: unknown[]) => push('error', args),\n };\n}\n\nfunction formatLogArg(arg: unknown): string {\n if (typeof arg === 'string') return arg;\n try {\n return JSON.stringify(toJsonSafe(arg));\n } catch {\n return String(arg);\n }\n}\n\nmain().catch((error) => {\n console.error(\n JSON.stringify(\n {\n ok: false,\n error: {\n message: error instanceof Error ? error.message : String(error),\n ...(error instanceof Error && error.stack ? { stack: error.stack } : {}),\n },\n },\n null,\n 2,\n ),\n );\n process.exitCode = 1;\n});\n","import { createHash } from 'node:crypto';\nimport { tmpdir } from 'node:os';\nimport { basename, join, resolve } from 'node:path';\n\nexport type CliCommand =\n | { kind: 'help' }\n | { kind: 'daemon'; stateKey: string }\n | { kind: 'create'; path: string; name?: string }\n | { kind: 'load'; path: string }\n | { kind: 'execute'; id: string; code?: string; codeFile?: string }\n | { kind: 'commit'; id: string; path?: string }\n | { kind: 'unload'; id: string }\n | { kind: 'list' }\n | { kind: 'shutdown' };\n\nexport type DaemonRequest =\n | { method: 'ping' }\n | { method: 'create'; path: string; name?: string }\n | { method: 'load'; path: string }\n | { method: 'execute'; id: string; code: string }\n | { method: 'commit'; id: string; path?: string }\n | { method: 'unload'; id: string }\n | { method: 'list' }\n | { method: 'shutdown' };\n\nexport type DaemonResponse =\n | { ok: true; result: unknown }\n | { ok: false; error: { message: string; stack?: string } };\n\nexport function parseCliArgs(argv: readonly string[]): CliCommand {\n const [command, ...rest] = argv;\n\n switch (command) {\n case undefined:\n case '-h':\n case '--help':\n case 'help':\n return { kind: 'help' };\n case '_daemon': {\n const stateKey = rest[0];\n if (!stateKey) throw new Error('Internal error: _daemon requires a state key.');\n return { kind: 'daemon', stateKey };\n }\n case 'create': {\n return parseCreateCommand(rest);\n }\n case 'load': {\n const path = rest[0];\n if (!path) throw new Error('Usage: mog load <path>');\n return { kind: 'load', path: resolve(path) };\n }\n case 'execute': {\n return {\n kind: 'execute',\n id: requiredOption(rest, '--id', 'Usage: mog execute --id <workbookId> --code <code>'),\n code: optionalOption(rest, '--code'),\n codeFile: optionalOption(rest, '--code-file'),\n };\n }\n case 'commit':\n return {\n kind: 'commit',\n id: requiredOption(rest, '--id', 'Usage: mog commit --id <workbookId> [--path <path>]'),\n path: optionalOption(rest, '--path'),\n };\n case 'unload':\n return {\n kind: 'unload',\n id: requiredOption(rest, '--id', 'Usage: mog unload --id <workbookId>'),\n };\n case 'list':\n return { kind: 'list' };\n case 'shutdown':\n return { kind: 'shutdown' };\n default:\n throw new Error(`Unknown command: ${command}\\n\\n${usage()}`);\n }\n}\n\nexport function stateKeyForCwd(cwd = process.cwd()): string {\n return createHash('sha256').update(cwd).digest('hex').slice(0, 20);\n}\n\nexport function socketPathForState(stateKey: string): string {\n return process.env.MOG_CLI_SOCKET ?? join(tmpdir(), `mog-${stateKey}.sock`);\n}\n\nexport function pidPathForState(stateKey: string): string {\n return process.env.MOG_CLI_PID ?? join(tmpdir(), `mog-${stateKey}.pid`);\n}\n\nexport function toJsonSafe(value: unknown): unknown {\n return toJsonSafeInner(value, new WeakSet<object>());\n}\n\nexport function usage(): string {\n return [\n 'Usage:',\n ' mog create <path>',\n ' mog create --name <workbookName> --path <directory>',\n ' mog load <path>',\n ' mog execute --id <workbookId> --code <code>',\n ' mog execute --id <workbookId> --code-file <path>',\n ' mog commit --id <workbookId> [--path <path>]',\n ' mog unload --id <workbookId>',\n ' mog list',\n '',\n 'Execute code runs inside the Mog daemon with these bindings:',\n ' wb, workbook, ws, activeSheet, api, Utils, console',\n '',\n 'Example:',\n ' mog execute --id abc --code \"await ws.setCell(\\\\\"A1\\\\\", 42); return ws.getValue(\\\\\"A1\\\\\");\"',\n ].join('\\n');\n}\n\nfunction parseCreateCommand(args: readonly string[]): Extract<CliCommand, { kind: 'create' }> {\n const directPath = args[0] && !args[0].startsWith('--') ? args[0] : undefined;\n const name = optionalOption(args, '--name');\n const directory = optionalOption(args, '--path');\n\n if (directPath) {\n if (name || directory) {\n throw new Error(\n 'Usage: mog create <path>\\n mog create --name <workbookName> --path <directory>',\n );\n }\n return {\n kind: 'create',\n path: resolve(directPath),\n name: workbookNameFromPath(directPath),\n };\n }\n\n if (!name || !directory) {\n throw new Error(\n 'Usage: mog create <path>\\n mog create --name <workbookName> --path <directory>',\n );\n }\n\n return {\n kind: 'create',\n path: resolve(directory, workbookFileName(name)),\n name: workbookNameFromPath(name),\n };\n}\n\nfunction requiredOption(args: readonly string[], name: string, errorMessage: string): string {\n const value = optionalOption(args, name);\n if (!value) throw new Error(errorMessage);\n return value;\n}\n\nfunction optionalOption(args: readonly string[], name: string): string | undefined {\n const index = args.indexOf(name);\n if (index === -1) return undefined;\n const value = args[index + 1];\n if (!value || value.startsWith('--')) {\n throw new Error(`Missing value for ${name}`);\n }\n return value;\n}\n\nfunction workbookFileName(name: string): string {\n const trimmed = name.trim();\n if (!trimmed) throw new Error('Workbook name must not be empty.');\n if (trimmed.includes('/') || trimmed.includes('\\\\')) {\n throw new Error('Workbook name must not contain path separators.');\n }\n return trimmed.toLowerCase().endsWith('.xlsx') ? trimmed : `${trimmed}.xlsx`;\n}\n\nfunction workbookNameFromPath(path: string): string {\n return basename(path).replace(/\\.xlsx$/i, '');\n}\n\nfunction toJsonSafeInner(value: unknown, seen: WeakSet<object>): unknown {\n if (value == null) return value;\n if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {\n return value;\n }\n if (typeof value === 'bigint') return value.toString();\n if (typeof value === 'function') {\n return `[Function ${(value as { name?: string }).name || 'anonymous'}]`;\n }\n if (value instanceof Date) return value.toISOString();\n if (value instanceof Uint8Array) {\n return {\n type: 'Uint8Array',\n length: value.byteLength,\n base64: Buffer.from(value).toString('base64'),\n };\n }\n if (Array.isArray(value)) return value.map((entry) => toJsonSafeInner(entry, seen));\n if (value instanceof Map) {\n return Object.fromEntries(\n [...value.entries()].map(([key, entry]) => [String(key), toJsonSafeInner(entry, seen)]),\n );\n }\n if (value instanceof Set) return [...value].map((entry) => toJsonSafeInner(entry, seen));\n if (typeof value === 'object') {\n if (seen.has(value)) return '[Circular]';\n seen.add(value);\n return Object.fromEntries(\n Object.entries(value).map(([key, entry]) => [key, toJsonSafeInner(entry, seen)]),\n );\n }\n return String(value);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,IAAM,mBAAmB,MACvB,OAAO,aAAa,cAChB,IAAI,IAAI,QAAQ,UAAU,EAAE,EAAE,OAC7B,SAAS,iBAAiB,SAAS,cAAc,QAAQ,YAAY,MAAM,WAC1E,SAAS,cAAc,MACvB,IAAI,IAAI,WAAW,SAAS,OAAO,EAAE;AAEtC,IAAM,gBAAgC,iCAAiB;;;ACX9D,gCAAsB;AACtB,IAAAA,sBAA2B;AAC3B,qBAAsD;AACtD,sBAA8C;AAC9C,sBAAgB;AAChB,IAAAC,oBAAiC;AACjC,sBAA8B;AAC9B,kBAA0D;;;ACR1D,yBAA2B;AAC3B,qBAAuB;AACvB,uBAAwC;AA2BjC,SAAS,aAAa,MAAqC;AAChE,QAAM,CAAC,SAAS,GAAG,IAAI,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net"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mog-sdk/cli",
|
|
3
|
+
"version": "0.8.0",
|
|
4
|
+
"description": "Minimal command-line interface for operating Mog workbooks with the headless SDK",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "commonjs",
|
|
7
|
+
"bin": {
|
|
8
|
+
"mog": "./dist/mog.cjs"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=18"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/fundamental-research-labs/mog",
|
|
20
|
+
"directory": "cli"
|
|
21
|
+
},
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@mog-sdk/node": "0.8.0"
|
|
27
|
+
}
|
|
28
|
+
}
|