@the-librarian/cli 1.0.0-rc.3 → 1.0.0-rc.30
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 +201 -0
- package/dist/bin.js +0 -0
- package/dist/commands/install.d.ts +6 -0
- package/dist/commands/install.d.ts.map +1 -1
- package/dist/commands/install.js +54 -2
- package/dist/commands/install.js.map +1 -1
- package/dist/harnesses/codex.d.ts +13 -0
- package/dist/harnesses/codex.d.ts.map +1 -1
- package/dist/harnesses/codex.js +217 -26
- package/dist/harnesses/codex.js.map +1 -1
- package/dist/harnesses/hermes.d.ts +1 -1
- package/dist/harnesses/hermes.d.ts.map +1 -1
- package/dist/harnesses/hermes.js +7 -3
- package/dist/harnesses/hermes.js.map +1 -1
- package/dist/harnesses/opencode.d.ts +12 -0
- package/dist/harnesses/opencode.d.ts.map +1 -1
- package/dist/harnesses/opencode.js +125 -4
- package/dist/harnesses/opencode.js.map +1 -1
- package/dist/paths.d.ts +16 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +22 -0
- package/dist/paths.js.map +1 -1
- package/dist/prompt.d.ts +7 -0
- package/dist/prompt.d.ts.map +1 -1
- package/dist/prompt.js +79 -29
- package/dist/prompt.js.map +1 -1
- package/dist/runtime.d.ts +20 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +252 -7
- package/dist/runtime.js.map +1 -1
- package/dist/server/admin.d.ts +31 -0
- package/dist/server/admin.d.ts.map +1 -0
- package/dist/server/admin.js +131 -0
- package/dist/server/admin.js.map +1 -0
- package/dist/server/autoupdate.d.ts +184 -0
- package/dist/server/autoupdate.d.ts.map +1 -0
- package/dist/server/autoupdate.js +794 -0
- package/dist/server/autoupdate.js.map +1 -0
- package/dist/server/boot.d.ts +51 -0
- package/dist/server/boot.d.ts.map +1 -0
- package/dist/server/boot.js +233 -0
- package/dist/server/boot.js.map +1 -0
- package/dist/server/deploy-state.d.ts +33 -0
- package/dist/server/deploy-state.d.ts.map +1 -0
- package/dist/server/deploy-state.js +79 -0
- package/dist/server/deploy-state.js.map +1 -0
- package/dist/server/docker.d.ts +53 -0
- package/dist/server/docker.d.ts.map +1 -0
- package/dist/server/docker.js +166 -0
- package/dist/server/docker.js.map +1 -0
- package/dist/server/down.d.ts +19 -0
- package/dist/server/down.d.ts.map +1 -0
- package/dist/server/down.js +62 -0
- package/dist/server/down.js.map +1 -0
- package/dist/server/index.d.ts +8 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +50 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/logs.d.ts +50 -0
- package/dist/server/logs.d.ts.map +1 -0
- package/dist/server/logs.js +162 -0
- package/dist/server/logs.js.map +1 -0
- package/dist/server/preflight.d.ts +24 -0
- package/dist/server/preflight.d.ts.map +1 -0
- package/dist/server/preflight.js +58 -0
- package/dist/server/preflight.js.map +1 -0
- package/dist/server/redact.d.ts +2 -0
- package/dist/server/redact.d.ts.map +1 -0
- package/dist/server/redact.js +26 -0
- package/dist/server/redact.js.map +1 -0
- package/dist/server/status.d.ts +20 -0
- package/dist/server/status.d.ts.map +1 -0
- package/dist/server/status.js +103 -0
- package/dist/server/status.js.map +1 -0
- package/dist/server/up.d.ts +226 -0
- package/dist/server/up.d.ts.map +1 -0
- package/dist/server/up.js +723 -0
- package/dist/server/up.js.map +1 -0
- package/dist/server/update.d.ts +35 -0
- package/dist/server/update.d.ts.map +1 -0
- package/dist/server/update.js +308 -0
- package/dist/server/update.js.map +1 -0
- package/package.json +10 -11
package/dist/runtime.d.ts
CHANGED
|
@@ -12,6 +12,26 @@ export interface RuntimeOptions {
|
|
|
12
12
|
shell?: Shell;
|
|
13
13
|
/** Inject a prompter (tests). Defaults to a real stdio-backed prompter. */
|
|
14
14
|
prompter?: Prompter;
|
|
15
|
+
/**
|
|
16
|
+
* The process environment to read existing `LIBRARIAN_*` vars from (BUG 2).
|
|
17
|
+
* Injectable so tests never touch the real `process.env` and never log a
|
|
18
|
+
* token. Defaults to `process.env` in `runInstall`.
|
|
19
|
+
*/
|
|
20
|
+
env?: NodeJS.ProcessEnv;
|
|
21
|
+
/**
|
|
22
|
+
* Whether the run is interactive (a TTY is attached). Gates `server up`'s
|
|
23
|
+
* best-effort offers (the Tailscale offer; the `0.0.0.0` confirm). Defaults
|
|
24
|
+
* to `process.stdin.isTTY` — a non-interactive run never silently exposes the
|
|
25
|
+
* server beyond localhost (it keeps `127.0.0.1`). Injectable for tests.
|
|
26
|
+
*/
|
|
27
|
+
interactive?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* The host platform, defaulting to `process.platform`. Threads into the
|
|
30
|
+
* `server` ops that branch on it: preflight's daemon hint and boot
|
|
31
|
+
* persistence (Linux systemd vs the macOS deferred notice). Injectable so the
|
|
32
|
+
* darwin path is testable from a Linux host.
|
|
33
|
+
*/
|
|
34
|
+
platform?: NodeJS.Platform;
|
|
15
35
|
}
|
|
16
36
|
/**
|
|
17
37
|
* The CLI entrypoint. Dispatches to the command handlers and — crucially —
|
package/dist/runtime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAe,KAAK,KAAK,EAAE,MAAM,UAAU,CAAC;AAGnD,OAAO,EAAqC,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAe,KAAK,KAAK,EAAE,MAAM,UAAU,CAAC;AAGnD,OAAO,EAAqC,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAmB/E,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,cAAc;IAC7B,0EAA0E;IAC1E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uDAAuD;IACvD,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC;CAC5B;AAID;;;;;;GAMG;AACH,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,SAAS,CAAC,CAY7F;AAmXD,wBAAgB,KAAK,IAAI,MAAM,CAyB9B"}
|
package/dist/runtime.js
CHANGED
|
@@ -15,8 +15,17 @@ import { formatConfig, readConfig, redact, setConfig } from "./config.js";
|
|
|
15
15
|
import { doctor } from "./doctor.js";
|
|
16
16
|
import { detectShell } from "./env.js";
|
|
17
17
|
import { allHarnesses } from "./harnesses/index.js";
|
|
18
|
-
import { flagString, parseArgs } from "./parse-args.js";
|
|
18
|
+
import { flagBool, flagString, parseArgs } from "./parse-args.js";
|
|
19
19
|
import { createPrompter, MissingValueError } from "./prompt.js";
|
|
20
|
+
import { runAdmin } from "./server/admin.js";
|
|
21
|
+
import { autoUpdateStatus, disableAutoUpdate, enableAutoUpdate, runAutoUpdate, uninstallAutoUpdate, } from "./server/autoupdate.js";
|
|
22
|
+
import { disableBoot, enableBoot } from "./server/boot.js";
|
|
23
|
+
import { runDown } from "./server/down.js";
|
|
24
|
+
import { serverUsage } from "./server/index.js";
|
|
25
|
+
import { runLogs } from "./server/logs.js";
|
|
26
|
+
import { serverStatus } from "./server/status.js";
|
|
27
|
+
import { runUp } from "./server/up.js";
|
|
28
|
+
import { runUpdate as runServerUpdate } from "./server/update.js";
|
|
20
29
|
import { status } from "./status.js";
|
|
21
30
|
import { cliVersion } from "./version.js";
|
|
22
31
|
const PHASE_2_STUBS = new Set(["report", "self-update"]);
|
|
@@ -66,6 +75,9 @@ async function dispatch(argv, options) {
|
|
|
66
75
|
// Diagnostic: exits 0 even when it flags problems.
|
|
67
76
|
return ok(await doctor(options.home));
|
|
68
77
|
}
|
|
78
|
+
if (command === "server") {
|
|
79
|
+
return runServerCommand(rest, options);
|
|
80
|
+
}
|
|
69
81
|
if (PHASE_2_STUBS.has(command)) {
|
|
70
82
|
return runPhase2Stub(command);
|
|
71
83
|
}
|
|
@@ -105,23 +117,255 @@ async function runInstallCommand(rest, options) {
|
|
|
105
117
|
const { positionals, flags } = parseArgs(rest);
|
|
106
118
|
const shell = options.shell ?? resolveShellFlag(flags);
|
|
107
119
|
const prompter = options.prompter ?? createPrompter();
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
120
|
+
try {
|
|
121
|
+
const outcome = await runInstall(positionals, {
|
|
122
|
+
home: options.home,
|
|
123
|
+
shell,
|
|
124
|
+
prompter,
|
|
125
|
+
env: options.env,
|
|
126
|
+
});
|
|
127
|
+
// A mid-install failure makes the command non-zero so scripts notice; a
|
|
128
|
+
// pure skip (CLI absent) is a success.
|
|
129
|
+
return outcome.failed.length > 0 ? errOut(outcome.output) : ok(outcome.output);
|
|
130
|
+
}
|
|
131
|
+
finally {
|
|
132
|
+
// Tear down the shared readline (BUG 1) so an open interface doesn't keep
|
|
133
|
+
// the event loop alive and hang the process after the command completes.
|
|
134
|
+
prompter.close();
|
|
135
|
+
}
|
|
112
136
|
}
|
|
113
137
|
async function runUninstallCommand(rest, options) {
|
|
114
138
|
const { positionals, flags } = parseArgs(rest);
|
|
115
139
|
const shell = options.shell ?? resolveShellFlag(flags);
|
|
116
140
|
const prompter = options.prompter ?? createPrompter();
|
|
117
|
-
|
|
118
|
-
|
|
141
|
+
try {
|
|
142
|
+
const outcome = await runUninstall(positionals, { home: options.home, shell, prompter });
|
|
143
|
+
return outcome.failed.length > 0 ? errOut(outcome.output) : ok(outcome.output);
|
|
144
|
+
}
|
|
145
|
+
finally {
|
|
146
|
+
prompter.close();
|
|
147
|
+
}
|
|
119
148
|
}
|
|
120
149
|
async function runUpdateCommand(rest, options) {
|
|
121
150
|
const { positionals } = parseArgs(rest);
|
|
122
151
|
const outcome = await runUpdate(positionals, { home: options.home });
|
|
123
152
|
return outcome.failed.length > 0 ? errOut(outcome.output) : ok(outcome.output);
|
|
124
153
|
}
|
|
154
|
+
// --- server command group (self-host) ------------------------------------
|
|
155
|
+
/**
|
|
156
|
+
* `librarian server [subcommand]`. With no subcommand (or `--help`/`-h`) it
|
|
157
|
+
* prints the command surface (§4). Implemented: `up` (S2/S3), `down` / `logs` /
|
|
158
|
+
* `status` (S4), `update` (S5), `enable-boot` / `disable-boot` (S6), `admin`
|
|
159
|
+
* (S7a). An unknown subcommand errors with the surface. Preflight + the
|
|
160
|
+
* `docker.ts` seam (S1) back every container op.
|
|
161
|
+
*/
|
|
162
|
+
async function runServerCommand(rest, options) {
|
|
163
|
+
const [subcommand, ...subRest] = rest;
|
|
164
|
+
if (!subcommand || subcommand === "--help" || subcommand === "-h") {
|
|
165
|
+
return ok(serverUsage());
|
|
166
|
+
}
|
|
167
|
+
if (subcommand === "up") {
|
|
168
|
+
return runServerUpCommand(subRest, options);
|
|
169
|
+
}
|
|
170
|
+
if (subcommand === "update") {
|
|
171
|
+
return runServerUpdateCommand(subRest, options);
|
|
172
|
+
}
|
|
173
|
+
if (subcommand === "down") {
|
|
174
|
+
return runServerDownCommand();
|
|
175
|
+
}
|
|
176
|
+
if (subcommand === "logs") {
|
|
177
|
+
return runServerLogsCommand(subRest);
|
|
178
|
+
}
|
|
179
|
+
if (subcommand === "status") {
|
|
180
|
+
return runServerStatusCommand(subRest, options);
|
|
181
|
+
}
|
|
182
|
+
if (subcommand === "enable-boot") {
|
|
183
|
+
return runServerEnableBootCommand(options);
|
|
184
|
+
}
|
|
185
|
+
if (subcommand === "disable-boot") {
|
|
186
|
+
return runServerDisableBootCommand(options);
|
|
187
|
+
}
|
|
188
|
+
if (subcommand === "autoupdate") {
|
|
189
|
+
return runServerAutoUpdateCommand(subRest, options);
|
|
190
|
+
}
|
|
191
|
+
if (subcommand === "admin") {
|
|
192
|
+
return runServerAdminCommand(subRest, options);
|
|
193
|
+
}
|
|
194
|
+
return err(`Unknown server subcommand: ${subcommand}\n\n${serverUsage()}`);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* `librarian server up [flags]` (S2, localhost path). Parses the flags, builds
|
|
198
|
+
* a prompter (for the loop-closer env offer), and runs the orchestrated flow.
|
|
199
|
+
* A failure surfaces as one clean stderr line via the top-level catch — no
|
|
200
|
+
* stack trace, and the master key (carried only on the success stdout) never
|
|
201
|
+
* reaches an error path.
|
|
202
|
+
*/
|
|
203
|
+
async function runServerUpCommand(rest, options) {
|
|
204
|
+
const { flags } = parseArgs(rest);
|
|
205
|
+
const prompter = options.prompter ?? createPrompter();
|
|
206
|
+
// Interactivity gates the best-effort offers (Tailscale; the `0.0.0.0`
|
|
207
|
+
// confirm). Explicit override wins; otherwise a TTY means interactive. A
|
|
208
|
+
// non-interactive run never silently exposes the server beyond localhost.
|
|
209
|
+
const interactive = options.interactive ?? Boolean(process.stdin.isTTY);
|
|
210
|
+
try {
|
|
211
|
+
const result = await runUp({
|
|
212
|
+
ref: flagString(flags.ref),
|
|
213
|
+
dir: flagString(flags.dir),
|
|
214
|
+
host: flagString(flags.host),
|
|
215
|
+
dataVolume: flagString(flags["data-volume"]),
|
|
216
|
+
enableBoot: flagBool(flags["enable-boot"]),
|
|
217
|
+
yes: flagBool(flags.yes),
|
|
218
|
+
}, {
|
|
219
|
+
home: options.home,
|
|
220
|
+
prompter,
|
|
221
|
+
interactive,
|
|
222
|
+
...(options.platform ? { platform: options.platform } : {}),
|
|
223
|
+
});
|
|
224
|
+
return ok(result.output);
|
|
225
|
+
}
|
|
226
|
+
finally {
|
|
227
|
+
prompter.close();
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* `librarian server enable-boot` (S6). On Linux, installs + enables the systemd
|
|
232
|
+
* unit that starts the existing named container on boot (the unit references the
|
|
233
|
+
* container by name and carries NO secret). On macOS, prints the deferred notice
|
|
234
|
+
* and exits 0 (NOT an error). A real failure surfaces as one clean stderr line.
|
|
235
|
+
*/
|
|
236
|
+
async function runServerEnableBootCommand(options) {
|
|
237
|
+
const result = await enableBoot(options.platform ? { platform: options.platform } : {});
|
|
238
|
+
return ok(result.output);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* `librarian server disable-boot` (S6). On Linux, disables + removes the systemd
|
|
242
|
+
* unit and reloads systemd; safe if already disabled/absent (a teaching message,
|
|
243
|
+
* no crash). On macOS, prints the deferred notice and exits 0.
|
|
244
|
+
*/
|
|
245
|
+
async function runServerDisableBootCommand(options) {
|
|
246
|
+
const result = await disableBoot(options.platform ? { platform: options.platform } : {});
|
|
247
|
+
return ok(result.output);
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* `librarian server autoupdate <enable|disable|uninstall|status> [--cadence …]`
|
|
251
|
+
* and the internal `--run` (T3). `enable` installs a host scheduler (systemd timer
|
|
252
|
+
* / cron fallback) that fires hourly and runs `--run`, plus writes enabled+cadence
|
|
253
|
+
* into the running server (so the dashboard reflects it). `disable` flips the
|
|
254
|
+
* setting off (timer stays). `uninstall` removes the timer/cron. `status` reports
|
|
255
|
+
* timer-installed + the server's enabled/cadence/last-run + up-to-date. `--run` is
|
|
256
|
+
* the wrapper the timer calls: it reads the settings from the running server,
|
|
257
|
+
* applies the due-check, and conditionally runs `server update` — FULLY fail-soft
|
|
258
|
+
* (never throws out of the timer). A real failure on the operator-facing verbs
|
|
259
|
+
* surfaces as one clean stderr line via the top-level catch.
|
|
260
|
+
*/
|
|
261
|
+
async function runServerAutoUpdateCommand(subRest, options) {
|
|
262
|
+
const { positionals, flags } = parseArgs(subRest);
|
|
263
|
+
const platformOpt = options.platform ? { platform: options.platform } : {};
|
|
264
|
+
const base = { home: options.home, dir: flagString(flags.dir), ...platformOpt };
|
|
265
|
+
// `--run` is the timer's wrapper. It is fail-soft by construction (it never
|
|
266
|
+
// throws) and always exits 0 so the timer's unit never fails; its one-line
|
|
267
|
+
// outcome is its stdout.
|
|
268
|
+
if (flagBool(flags.run)) {
|
|
269
|
+
const result = await runAutoUpdate(base);
|
|
270
|
+
return ok(result.output);
|
|
271
|
+
}
|
|
272
|
+
const [verb] = positionals;
|
|
273
|
+
if (verb === "enable") {
|
|
274
|
+
const result = await enableAutoUpdate({ ...base, cadence: flagString(flags.cadence) });
|
|
275
|
+
return ok(result.output);
|
|
276
|
+
}
|
|
277
|
+
if (verb === "disable") {
|
|
278
|
+
return ok((await disableAutoUpdate(base)).output);
|
|
279
|
+
}
|
|
280
|
+
if (verb === "uninstall") {
|
|
281
|
+
return ok((await uninstallAutoUpdate(base)).output);
|
|
282
|
+
}
|
|
283
|
+
if (verb === "status" || verb === undefined) {
|
|
284
|
+
return ok((await autoUpdateStatus(base)).output);
|
|
285
|
+
}
|
|
286
|
+
return err(`Unknown autoupdate subcommand: ${verb}\n\n` +
|
|
287
|
+
"Usage: librarian server autoupdate <enable|disable|uninstall|status> [--cadence daily|weekly]");
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* `librarian server admin <backup|restore|auth|rebuild> [args…]` (S7a). Runs a
|
|
291
|
+
* curated admin verb inside the running container via
|
|
292
|
+
* `docker exec [-it] the-librarian the-librarian <verb> [args…]` (spec §7). The
|
|
293
|
+
* args are passed through VERBATIM — so we do NOT run them through `parseArgs`
|
|
294
|
+
* (that would reorder/strip flags); the in-container CLI parses them. An
|
|
295
|
+
* interactive run adds `-it` so the CLI can prompt (e.g. `restore`'s
|
|
296
|
+
* `--secret-key`). A rejected verb or a down container surfaces as one clean
|
|
297
|
+
* stderr line via the top-level catch, with no `docker exec`.
|
|
298
|
+
*/
|
|
299
|
+
async function runServerAdminCommand(subRest, options) {
|
|
300
|
+
const interactive = options.interactive ?? Boolean(process.stdin.isTTY);
|
|
301
|
+
const result = await runAdmin(subRest, {
|
|
302
|
+
interactive,
|
|
303
|
+
...(options.platform ? { platform: options.platform } : {}),
|
|
304
|
+
});
|
|
305
|
+
return ok(result.output);
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* `librarian server update [--ref <tag|main>] [--yes]` (S5). Re-pins the deploy
|
|
309
|
+
* dir to the resolved ref, rebuilds the image, recreates the container
|
|
310
|
+
* (PRESERVING the data volume), waits for health (rolling back on failure), and
|
|
311
|
+
* applies pending data-dir migrations. Idempotent: already at the ref + healthy
|
|
312
|
+
* → a clean no-op. The agent token is reused from the running container (clients
|
|
313
|
+
* keep working) and never reaches an error path or a file. A failure surfaces as
|
|
314
|
+
* one clean stderr line via the top-level catch (already secret-redacted).
|
|
315
|
+
*/
|
|
316
|
+
async function runServerUpdateCommand(rest, options) {
|
|
317
|
+
const { flags } = parseArgs(rest);
|
|
318
|
+
const result = await runServerUpdate({
|
|
319
|
+
ref: flagString(flags.ref),
|
|
320
|
+
dir: flagString(flags.dir),
|
|
321
|
+
yes: flagBool(flags.yes),
|
|
322
|
+
home: options.home,
|
|
323
|
+
});
|
|
324
|
+
return ok(result.output);
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* `librarian server down` (S4). Stops the container — DATA SACRED (it issues
|
|
328
|
+
* only `docker stop`, never any `rm`/volume op). A not-running container is a
|
|
329
|
+
* friendly success; a real failure surfaces via the top-level catch as one
|
|
330
|
+
* clean stderr line. No flags today.
|
|
331
|
+
*/
|
|
332
|
+
async function runServerDownCommand() {
|
|
333
|
+
const result = await runDown({});
|
|
334
|
+
return ok(result.output);
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* `librarian server logs [-f] [--service mcp|dashboard|all]` (S4). `-f` is a
|
|
338
|
+
* short flag the tiny parser treats as a positional, so we accept it there (or
|
|
339
|
+
* `--follow`). `--service` selects which of the two co-located services to show
|
|
340
|
+
* (filtered from the combined stream). A bad `--service` value is a teaching
|
|
341
|
+
* error via the top-level catch.
|
|
342
|
+
*
|
|
343
|
+
* A FOLLOW (`-f`) streams its lines straight to `process.stdout` LIVE inside
|
|
344
|
+
* `runLogs` (a tail never closes on its own — buffering it to return here is the
|
|
345
|
+
* old hang), so there's no captured `output` to print; we just propagate the
|
|
346
|
+
* followed process's exit code. The one-shot path returns its captured output.
|
|
347
|
+
*/
|
|
348
|
+
async function runServerLogsCommand(rest) {
|
|
349
|
+
const { positionals, flags } = parseArgs(rest);
|
|
350
|
+
const follow = positionals.includes("-f") || flagBool(flags.follow) || flagBool(flags.f);
|
|
351
|
+
const result = await runLogs({ follow, service: flagString(flags.service) });
|
|
352
|
+
if (follow) {
|
|
353
|
+
// Lines already streamed live; pass through the follow's exit code.
|
|
354
|
+
return { stdout: "", stderr: "", exitCode: result.exitCode ?? 0 };
|
|
355
|
+
}
|
|
356
|
+
return ok(result.output);
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* `librarian server status` (S4). Reports running/health (from `docker inspect`)
|
|
360
|
+
* and the deployed-vs-latest badge (deploy-state ref vs `fetchLatestVersion`).
|
|
361
|
+
* Offline/unknown degrades to `unknown`/`?` and still exits 0 — only a missing
|
|
362
|
+
* docker (preflight) makes it non-zero, via the top-level catch.
|
|
363
|
+
*/
|
|
364
|
+
async function runServerStatusCommand(rest, options) {
|
|
365
|
+
const { flags } = parseArgs(rest);
|
|
366
|
+
const result = await serverStatus({ home: options.home, dir: flagString(flags.dir) });
|
|
367
|
+
return ok(result.output);
|
|
368
|
+
}
|
|
125
369
|
// --- Phase 2 stubs (friendly "coming later") -----------------------------
|
|
126
370
|
function runPhase2Stub(command) {
|
|
127
371
|
const detail = command === "report"
|
|
@@ -142,6 +386,7 @@ export function usage() {
|
|
|
142
386
|
" status Live table of harness / installed / version",
|
|
143
387
|
" doctor Diagnose token, server reachability, harness CLIs",
|
|
144
388
|
" config Show or set MCP URL, token, server URL",
|
|
389
|
+
" server Self-host the Librarian server (run `server` for its commands)",
|
|
145
390
|
" self-update Update the librarian CLI itself",
|
|
146
391
|
" report Push this machine's state to the server",
|
|
147
392
|
"",
|
package/dist/runtime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,EAAE;AACF,4EAA4E;AAC5E,wEAAwE;AACxE,6EAA6E;AAC7E,wEAAwE;AACxE,6EAA6E;AAC7E,8EAA8E;AAC9E,yEAAyE;AACzE,kBAAkB;AAElB,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAwB,MAAM,aAAa,CAAC;AAChG,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,WAAW,EAAc,MAAM,UAAU,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAgB,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAiB,MAAM,aAAa,CAAC;AAC/E,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAiB1C,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC;AAEzD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,IAAc,EAAE,UAA0B,EAAE;IACvE,IAAI,CAAC;QACH,OAAO,MAAM,QAAQ,CAAC,IAAI,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kEAAkE;QAClE,EAAE;QACF,QAAQ;QACR,2DAA2D;QAC3D,uEAAuE;QACvE,sEAAsE;QACtE,wCAAwC;QACxC,8CAA8C;QAC9C,EAAE;QACF,cAAc,SAAS,EAAE;KAC1B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC;AAED,4EAA4E;AAE5E,SAAS,EAAE,CAAC,MAAc;IACxB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;AAC7C,CAAC;AAED,SAAS,GAAG,CAAC,MAAc;IACzB,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;AAC7C,CAAC;AAED,qFAAqF;AACrF,SAAS,MAAM,CAAC,MAAc;IAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** The curated admin verbs exposed under `server admin` (spec §7). */
|
|
2
|
+
export declare const ADMIN_VERBS: readonly ["backup", "restore", "auth", "rebuild"];
|
|
3
|
+
export type AdminVerb = (typeof ADMIN_VERBS)[number];
|
|
4
|
+
/** A teaching error from `admin`; the runtime renders `.message` as one stderr line. */
|
|
5
|
+
export declare class AdminError extends Error {
|
|
6
|
+
constructor(message: string);
|
|
7
|
+
}
|
|
8
|
+
export interface AdminOptions {
|
|
9
|
+
/** Platform for preflight's daemon hint. Default `process.platform`. */
|
|
10
|
+
platform?: NodeJS.Platform | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Whether the run is interactive (a TTY is attached). When true we add
|
|
13
|
+
* `docker exec -it` so the in-container CLI can prompt (e.g. `restore`'s
|
|
14
|
+
* `--secret-key` prompt, `auth reset-password`). A non-interactive run omits
|
|
15
|
+
* `-it` so it works in scripts/CI without a TTY.
|
|
16
|
+
*/
|
|
17
|
+
interactive?: boolean | undefined;
|
|
18
|
+
}
|
|
19
|
+
export interface AdminResult {
|
|
20
|
+
/** Human-readable report for stdout (the in-container CLI's own output). */
|
|
21
|
+
output: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Run `server admin <verb> [args…]`. Validates the verb is curated, preflights
|
|
25
|
+
* docker, confirms the container is running, then runs
|
|
26
|
+
* `docker exec [-it] the-librarian the-librarian <verb> [args…]` — passing the
|
|
27
|
+
* args through VERBATIM. A rejected verb / down container is a teaching
|
|
28
|
+
* `AdminError`; no `docker exec` runs in either case.
|
|
29
|
+
*/
|
|
30
|
+
export declare function runAdmin(argv: readonly string[], options?: AdminOptions): Promise<AdminResult>;
|
|
31
|
+
//# sourceMappingURL=admin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admin.d.ts","sourceRoot":"","sources":["../../src/server/admin.ts"],"names":[],"mappings":"AA+BA,sEAAsE;AACtE,eAAO,MAAM,WAAW,mDAAoD,CAAC;AAE7E,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAErD,wFAAwF;AACxF,qBAAa,UAAW,SAAQ,KAAK;gBACvB,OAAO,EAAE,MAAM;CAI5B;AAED,MAAM,WAAW,YAAY;IAC3B,wEAAwE;IACxE,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,GAAG,SAAS,CAAC;IACvC;;;;;OAKG;IACH,WAAW,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACnC;AAED,MAAM,WAAW,WAAW;IAC1B,4EAA4E;IAC5E,MAAM,EAAE,MAAM,CAAC;CAChB;AAyCD;;;;;;GAMG;AACH,wBAAsB,QAAQ,CAC5B,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,OAAO,GAAE,YAAiB,GACzB,OAAO,CAAC,WAAW,CAAC,CA6DtB"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// `librarian server admin <verb> [args…]` — run a curated subset of the
|
|
2
|
+
// folded-in admin CLI (`@librarian/cli`, the `the-librarian` binary) INSIDE the
|
|
3
|
+
// running all-in-one container. Spec §7 ("Folded-in admin").
|
|
4
|
+
//
|
|
5
|
+
// One uniform mechanism: `docker exec the-librarian the-librarian <verb> [args…]`.
|
|
6
|
+
// Running it in the container (not on the host) gives the admin CLI direct
|
|
7
|
+
// access to the data dir + the store/settings the server already uses — which is
|
|
8
|
+
// exactly what lets `auth` recovery bypass a locked dashboard and lets
|
|
9
|
+
// `backup`/`restore` reuse the store rather than re-implement it. (The CLI is
|
|
10
|
+
// bundled into the runtime image in the same slice — see all-in-one.Dockerfile.)
|
|
11
|
+
//
|
|
12
|
+
// CURATED set (spec §7): only `backup | restore | auth | rebuild` are exposed.
|
|
13
|
+
// `seed` / `migrate-data-dir` / `export` / `handoffs` exist in @librarian/cli but
|
|
14
|
+
// are deliberately NOT folded in here (seed is dev-only; migrate-data-dir runs
|
|
15
|
+
// automatically on `update`; export + handoffs are power-user/dashboard surfaces).
|
|
16
|
+
// They stay reachable via a raw `docker exec` if ever truly needed.
|
|
17
|
+
//
|
|
18
|
+
// Args after the verb are passed through VERBATIM, in order — this module never
|
|
19
|
+
// parses, reorders, or rewrites them (so e.g. `auth reset-password --user x` and
|
|
20
|
+
// `restore --secret-key …` reach the CLI exactly as typed). A bearer/secret may
|
|
21
|
+
// ride through as an arg the CLI itself reads; this module never logs or persists
|
|
22
|
+
// it (AGENTS.md: privacy beats convenience).
|
|
23
|
+
//
|
|
24
|
+
// Everything goes through the injectable `docker.ts` seam, so tests assert the
|
|
25
|
+
// exact argv without a real daemon or container.
|
|
26
|
+
import { run, runInteractive } from "./docker.js";
|
|
27
|
+
import { preflight } from "./preflight.js";
|
|
28
|
+
import { redactSecrets } from "./redact.js";
|
|
29
|
+
import { CONTAINER_NAME } from "./up.js";
|
|
30
|
+
/** The curated admin verbs exposed under `server admin` (spec §7). */
|
|
31
|
+
export const ADMIN_VERBS = ["backup", "restore", "auth", "rebuild"];
|
|
32
|
+
/** A teaching error from `admin`; the runtime renders `.message` as one stderr line. */
|
|
33
|
+
export class AdminError extends Error {
|
|
34
|
+
constructor(message) {
|
|
35
|
+
super(message);
|
|
36
|
+
this.name = "AdminError";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** True iff `verb` is one of the curated admin verbs. */
|
|
40
|
+
function isAdminVerb(verb) {
|
|
41
|
+
return ADMIN_VERBS.includes(verb);
|
|
42
|
+
}
|
|
43
|
+
/** The teaching message for an unknown/dropped verb — names what IS available. */
|
|
44
|
+
function unknownVerbMessage(verb) {
|
|
45
|
+
const allowed = ADMIN_VERBS.join(" | ");
|
|
46
|
+
const lead = verb === undefined
|
|
47
|
+
? "`librarian server admin` needs a subcommand."
|
|
48
|
+
: `\`${verb}\` is not an \`admin\` subcommand.`;
|
|
49
|
+
return [
|
|
50
|
+
lead,
|
|
51
|
+
"",
|
|
52
|
+
`Allowed: ${allowed}.`,
|
|
53
|
+
"",
|
|
54
|
+
"Not exposed here (by design): `seed` (dev-only), `migrate-data-dir` (runs",
|
|
55
|
+
"automatically on `librarian server update`), `export`, and `handoffs`",
|
|
56
|
+
"(power-user / dashboard surfaces).",
|
|
57
|
+
].join("\n");
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Confirm the container is up before exec'ing into it. `docker inspect` reports
|
|
61
|
+
* `running` when it is; any other status (or a failed inspect → absent) is a
|
|
62
|
+
* teaching error pointing at `server up`, with NO `docker exec`.
|
|
63
|
+
*/
|
|
64
|
+
async function assertContainerRunning() {
|
|
65
|
+
const result = await run("docker", ["inspect", "--format", "{{.State.Status}}", CONTAINER_NAME]);
|
|
66
|
+
const status = result.code === 0 ? result.stdout.trim() : null;
|
|
67
|
+
if (status !== "running") {
|
|
68
|
+
throw new AdminError("The server isn't running — run `librarian server up` first, then re-run " +
|
|
69
|
+
"this admin command.");
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Run `server admin <verb> [args…]`. Validates the verb is curated, preflights
|
|
74
|
+
* docker, confirms the container is running, then runs
|
|
75
|
+
* `docker exec [-it] the-librarian the-librarian <verb> [args…]` — passing the
|
|
76
|
+
* args through VERBATIM. A rejected verb / down container is a teaching
|
|
77
|
+
* `AdminError`; no `docker exec` runs in either case.
|
|
78
|
+
*/
|
|
79
|
+
export async function runAdmin(argv, options = {}) {
|
|
80
|
+
const [verb, ...rest] = argv;
|
|
81
|
+
// Validate FIRST — a rejected verb must never reach a `docker exec` (and we
|
|
82
|
+
// don't even need a daemon to tell the user the verb is wrong).
|
|
83
|
+
if (verb === undefined || !isAdminVerb(verb)) {
|
|
84
|
+
throw new AdminError(unknownVerbMessage(verb));
|
|
85
|
+
}
|
|
86
|
+
await preflight(options.platform ? { platform: options.platform } : {});
|
|
87
|
+
await assertContainerRunning();
|
|
88
|
+
// A prompt is only needed when the run is interactive AND the operator hasn't
|
|
89
|
+
// already supplied the secret on the command line. With `--secret-key` present
|
|
90
|
+
// there is nothing to prompt for, so run non-interactively even on a TTY (SC-3:
|
|
91
|
+
// `restore --secret-key X` omits `-t`).
|
|
92
|
+
const willPrompt = options.interactive === true && !rest.includes("--secret-key");
|
|
93
|
+
if (willPrompt) {
|
|
94
|
+
// Inherit stdio so a `-it` exec can prompt the operator's real terminal (e.g.
|
|
95
|
+
// `restore` / `auth reset-password` reading a secret no-echo). The capture
|
|
96
|
+
// runner below uses `stdio:["ignore",…]`, so pairing it with `-t` only ever
|
|
97
|
+
// produced "the input device is not a TTY". Output streams live to the
|
|
98
|
+
// terminal — nothing to capture or redact here.
|
|
99
|
+
const code = await runInteractive("docker", [
|
|
100
|
+
"exec",
|
|
101
|
+
"-it",
|
|
102
|
+
CONTAINER_NAME,
|
|
103
|
+
"the-librarian",
|
|
104
|
+
verb,
|
|
105
|
+
...rest,
|
|
106
|
+
]);
|
|
107
|
+
// `null` = the process was signalled (e.g. the operator Ctrl-C'd the prompt) —
|
|
108
|
+
// a clean cancel, not a failure to surface.
|
|
109
|
+
if (code !== 0 && code !== null) {
|
|
110
|
+
throw new AdminError(`\`the-librarian ${verb}\` failed in the container (exit ${code}).` +
|
|
111
|
+
`\n\nResolve the error above, then re-run \`librarian server admin ${verb}\`.`);
|
|
112
|
+
}
|
|
113
|
+
return { output: "" };
|
|
114
|
+
}
|
|
115
|
+
// Non-interactive: `docker exec the-librarian the-librarian <verb> [args…]` —
|
|
116
|
+
// args verbatim, NEVER `-it` (the runner ignores stdin). Output is captured.
|
|
117
|
+
const execArgs = ["exec", CONTAINER_NAME, "the-librarian", verb, ...rest];
|
|
118
|
+
const result = await run("docker", execArgs);
|
|
119
|
+
if (result.code !== 0) {
|
|
120
|
+
// `admin` forwards secret-bearing args (`restore --secret-key …`, `auth …`),
|
|
121
|
+
// so a failed in-container step can echo them back. Redact before surfacing,
|
|
122
|
+
// identically to `update`/`up` (I-3) — the shared helper is the choke point.
|
|
123
|
+
const detail = redactSecrets(result.stderr.trim() || result.stdout.trim());
|
|
124
|
+
throw new AdminError(`\`the-librarian ${verb}\` failed in the container (exit ${result.code ?? "signal"})` +
|
|
125
|
+
(detail ? `:\n${detail}` : ".") +
|
|
126
|
+
`\n\nResolve the error above, then re-run \`librarian server admin ${verb}\`.`);
|
|
127
|
+
}
|
|
128
|
+
// The in-container CLI's own output is the report (stdout, then any stderr).
|
|
129
|
+
return { output: result.stdout + result.stderr };
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=admin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admin.js","sourceRoot":"","sources":["../../src/server/admin.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,gFAAgF;AAChF,6DAA6D;AAC7D,EAAE;AACF,mFAAmF;AACnF,2EAA2E;AAC3E,iFAAiF;AACjF,uEAAuE;AACvE,8EAA8E;AAC9E,iFAAiF;AACjF,EAAE;AACF,+EAA+E;AAC/E,kFAAkF;AAClF,+EAA+E;AAC/E,mFAAm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