@the-librarian/cli 1.0.0-rc.3 → 1.0.0-rc.31
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
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
declare const AUTOUPDATE_CADENCES: readonly ["daily", "weekly"];
|
|
2
|
+
type AutoUpdateCadence = (typeof AUTOUPDATE_CADENCES)[number];
|
|
3
|
+
/** The oneshot service unit that runs the `--run` wrapper (single instance per host). */
|
|
4
|
+
export declare const AUTOUPDATE_SERVICE_NAME = "the-librarian-autoupdate.service";
|
|
5
|
+
/** The timer unit that fires the oneshot service ~hourly. */
|
|
6
|
+
export declare const AUTOUPDATE_TIMER_NAME = "the-librarian-autoupdate.timer";
|
|
7
|
+
/** A stable marker that tags OUR crontab line, so we can find/replace/remove it idempotently. */
|
|
8
|
+
export declare const CRON_MARKER = "# the-librarian-autoupdate";
|
|
9
|
+
/**
|
|
10
|
+
* The substring every OUR systemd unit's `Description=` carries (both the service
|
|
11
|
+
* and the timer descriptions start with it). `uninstall` reads a unit file and
|
|
12
|
+
* confirms this marker BEFORE deleting it (FIX I2) — so a same-named unit a human
|
|
13
|
+
* authored is never `rm`'d out from under them.
|
|
14
|
+
*/
|
|
15
|
+
export declare const UNIT_DESCRIPTION_MARKER = "The Librarian \u2014 auto-update";
|
|
16
|
+
/** The absolute path the oneshot service is installed at (system unit, via sudo). */
|
|
17
|
+
export declare function servicePath(): string;
|
|
18
|
+
/** The absolute path the timer is installed at (system unit, via sudo). */
|
|
19
|
+
export declare function timerPath(): string;
|
|
20
|
+
/** A teaching error from autoupdate ops; the runtime renders `.message` as one stderr line. */
|
|
21
|
+
export declare class AutoUpdateError extends Error {
|
|
22
|
+
constructor(message: string);
|
|
23
|
+
}
|
|
24
|
+
export interface AutoUpdateResult {
|
|
25
|
+
/** Human-readable report for stdout. */
|
|
26
|
+
output: string;
|
|
27
|
+
}
|
|
28
|
+
export interface AutoUpdateOptions {
|
|
29
|
+
/** Platform — gates the macOS deferral + systemd-vs-cron choice. Default `process.platform`. */
|
|
30
|
+
platform?: NodeJS.Platform | undefined;
|
|
31
|
+
/** Override home (tests). Threads into `server update`/`status`. */
|
|
32
|
+
home?: string | undefined;
|
|
33
|
+
/** Deploy dir override. Default: `~/.librarian/server`. Threads into update/status. */
|
|
34
|
+
dir?: string | undefined;
|
|
35
|
+
}
|
|
36
|
+
export interface EnableOptions extends AutoUpdateOptions {
|
|
37
|
+
/** Cadence to write into the running server. Default daily. Validated daily|weekly. */
|
|
38
|
+
cadence?: string | undefined;
|
|
39
|
+
}
|
|
40
|
+
export interface RunOptions extends AutoUpdateOptions {
|
|
41
|
+
/**
|
|
42
|
+
* Sink for the wrapper's one-line log entries (the timer's journal). Defaults
|
|
43
|
+
* to a `process.stderr` writer; tests inject a recorder. Every wrapper outcome
|
|
44
|
+
* (skip / update / failure) emits exactly one line here — and the wrapper never
|
|
45
|
+
* throws, so the timer's unit always exits 0.
|
|
46
|
+
*/
|
|
47
|
+
log?: ((line: string) => void) | undefined;
|
|
48
|
+
/** Health-wait bound for the inner `server update` (small in tests). */
|
|
49
|
+
healthAttempts?: number | undefined;
|
|
50
|
+
/** Milliseconds between health polls for the inner update (0 in tests). */
|
|
51
|
+
healthIntervalMs?: number | undefined;
|
|
52
|
+
/** Injected current time for the due-check (tests). Default `new Date()`. */
|
|
53
|
+
now?: Date | undefined;
|
|
54
|
+
}
|
|
55
|
+
/** Inputs to the pure service generator (only the librarian path — NEVER a secret). */
|
|
56
|
+
export interface ServiceUnitInput {
|
|
57
|
+
/** Absolute path to the `librarian` binary the oneshot runs with `server autoupdate --run`. */
|
|
58
|
+
librarianPath: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Generate the oneshot service unit text. PURE + unit-tested. Contains NO secret —
|
|
62
|
+
* it runs `librarian server autoupdate --run`, which reads the settings from the
|
|
63
|
+
* running container itself (via `docker exec`), so nothing sensitive is written
|
|
64
|
+
* into this world-readable unit file. `Type=oneshot` because the wrapper runs to
|
|
65
|
+
* completion each fire (it is the timer's job to schedule, not the service's).
|
|
66
|
+
*/
|
|
67
|
+
export declare function generateServiceUnit(input: ServiceUnitInput): string;
|
|
68
|
+
/**
|
|
69
|
+
* Generate the timer unit text. PURE + unit-tested. Fires the oneshot service
|
|
70
|
+
* roughly hourly (`OnCalendar=hourly`, with `Persistent=true` so a missed fire
|
|
71
|
+
* while the host was off runs at next boot). The FREQUENT fire is deliberate: the
|
|
72
|
+
* cadence (daily/weekly) is a due-check IN the wrapper, NOT the timer period — so
|
|
73
|
+
* the dashboard can change cadence (a setting) with no host action (spec §4). A
|
|
74
|
+
* randomized delay spreads load and avoids every host updating on the exact hour.
|
|
75
|
+
*/
|
|
76
|
+
export declare function generateTimerUnit(): string;
|
|
77
|
+
/**
|
|
78
|
+
* The crontab line for the cron fallback (systemd absent). Fires the wrapper at
|
|
79
|
+
* minute 17 of every hour (off the top-of-hour to spread load), tagged with
|
|
80
|
+
* {@link CRON_MARKER} so it can be found/replaced/removed idempotently. NO secret
|
|
81
|
+
* — same reasoning as the systemd unit (the wrapper reads settings from the
|
|
82
|
+
* container at run time).
|
|
83
|
+
*/
|
|
84
|
+
export declare function cronLine(librarianPath: string): string;
|
|
85
|
+
/** The one-line macOS-deferred notice (boot persistence + autoupdate are Linux-only for now). */
|
|
86
|
+
export declare const MACOS_NOTICE: string;
|
|
87
|
+
/** The configured auto-update state read from the running server. */
|
|
88
|
+
export interface RunningConfig {
|
|
89
|
+
enabled: boolean;
|
|
90
|
+
cadence: AutoUpdateCadence;
|
|
91
|
+
lastRunAt: string | null;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Read the auto-update config from the RUNNING server via `docker exec node -e`
|
|
95
|
+
* (the internal tRPC listener, loopback inside the container). Returns null when
|
|
96
|
+
* the container is down / the exec fails / the response is unusable — the caller
|
|
97
|
+
* treats null as "unreachable" and SKIPS (never auto-updates an unknown server).
|
|
98
|
+
* Never throws.
|
|
99
|
+
*/
|
|
100
|
+
export declare function readRunningConfig(): Promise<RunningConfig | null>;
|
|
101
|
+
/**
|
|
102
|
+
* Write the auto-update config into the RUNNING server (so the dashboard reflects
|
|
103
|
+
* the CLI's enable/cadence) via `docker exec node -e` → internal tRPC `set`.
|
|
104
|
+
* Returns true on success, false when the container is down / the write failed.
|
|
105
|
+
* Never throws — a write failure during `enable` is surfaced as a non-fatal hint
|
|
106
|
+
* (the timer is still installed; the operator can toggle from the dashboard).
|
|
107
|
+
*/
|
|
108
|
+
export declare function writeRunningConfig(input: {
|
|
109
|
+
enabled?: boolean;
|
|
110
|
+
cadence?: AutoUpdateCadence;
|
|
111
|
+
}): Promise<boolean>;
|
|
112
|
+
/**
|
|
113
|
+
* Stamp `last_run_at` to NOW in the running server (the internal tRPC `stampRun`)
|
|
114
|
+
* after a SUCCESSFUL auto-update, so the next due-check advances by one cadence
|
|
115
|
+
* window. Returns true on success, false when the (freshly recreated) container
|
|
116
|
+
* isn't reachable yet / the call failed — a failed stamp is non-fatal (the update
|
|
117
|
+
* itself succeeded; the worst case is one extra due-check next fire). Never throws.
|
|
118
|
+
*/
|
|
119
|
+
export declare function stampRunInServer(): Promise<boolean>;
|
|
120
|
+
/**
|
|
121
|
+
* Install the host scheduler + write the enabled/cadence settings into the running
|
|
122
|
+
* server. On Linux with systemd: write the oneshot service + the .timer to
|
|
123
|
+
* `/etc/systemd/system`, `daemon-reload`, then `enable --now` the TIMER (the
|
|
124
|
+
* service is oneshot — only the timer is enabled). Idempotent: re-running rewrites
|
|
125
|
+
* the SAME unit paths and re-enables, never duplicating. Where systemd is absent:
|
|
126
|
+
* install an hourly cron line (idempotent via {@link CRON_MARKER}). On macOS: print
|
|
127
|
+
* the deferred notice and skip cleanly.
|
|
128
|
+
*
|
|
129
|
+
* The settings write (enabled=true + cadence) is best-effort: a down server is a
|
|
130
|
+
* non-fatal hint (the timer is installed; the operator toggles from the dashboard
|
|
131
|
+
* once the server is up). The timer is what makes auto-update actually happen.
|
|
132
|
+
*/
|
|
133
|
+
export declare function enableAutoUpdate(options?: EnableOptions): Promise<AutoUpdateResult>;
|
|
134
|
+
/**
|
|
135
|
+
* Disable auto-update WITHOUT removing the timer (spec §3 SC2): flip
|
|
136
|
+
* `enabled=false` in the running server so the next `--run` no-ops, leaving the
|
|
137
|
+
* timer installed. Idempotent. A down server is a teaching error (we can't flip a
|
|
138
|
+
* setting on a server we can't reach) — the operator can also toggle it off from
|
|
139
|
+
* the dashboard.
|
|
140
|
+
*/
|
|
141
|
+
export declare function disableAutoUpdate(options?: AutoUpdateOptions): Promise<AutoUpdateResult>;
|
|
142
|
+
/**
|
|
143
|
+
* Remove the host scheduler entirely (spec §3 SC2): on systemd, `disable --now`
|
|
144
|
+
* the timer (tolerating "not loaded"), remove BOTH unit files, then
|
|
145
|
+
* `daemon-reload`. Where systemd is absent, strip our tagged crontab line. Safe if
|
|
146
|
+
* already absent — idempotent, never a crash. Does NOT touch the server's
|
|
147
|
+
* `enabled` setting (the timer is gone, so it no longer matters; leaving the
|
|
148
|
+
* setting avoids a needless server round-trip on a down server). On macOS: notice.
|
|
149
|
+
*/
|
|
150
|
+
export declare function uninstallAutoUpdate(options?: AutoUpdateOptions): Promise<AutoUpdateResult>;
|
|
151
|
+
/**
|
|
152
|
+
* Report the auto-update state (spec §3 SC3): is the timer/cron installed?, the
|
|
153
|
+
* server's enabled/cadence/last-run (read from the running server), and the
|
|
154
|
+
* up-to-date badge (reusing `server status`' deployed-vs-latest render). A down
|
|
155
|
+
* server degrades the server-side fields to "unknown (server unreachable)" but
|
|
156
|
+
* still reports the host-side timer state and exits 0.
|
|
157
|
+
*/
|
|
158
|
+
export declare function autoUpdateStatus(options?: AutoUpdateOptions): Promise<AutoUpdateResult>;
|
|
159
|
+
/** The fixed lock path: `~/.librarian/server/.autoupdate.lock` (no root needed). */
|
|
160
|
+
export declare function autoUpdateLockPath(options: {
|
|
161
|
+
home?: string | undefined;
|
|
162
|
+
dir?: string | undefined;
|
|
163
|
+
}): string;
|
|
164
|
+
/**
|
|
165
|
+
* The wrapper the timer/cron fires (spec §3 SC4/SC7). Reads the auto-update
|
|
166
|
+
* settings from the RUNNING server, applies the due-check, and conditionally runs
|
|
167
|
+
* `server update`. FULLY FAIL-SOFT — it NEVER throws (the timer's unit always
|
|
168
|
+
* exits 0); every outcome is one log line:
|
|
169
|
+
*
|
|
170
|
+
* - Server UNREACHABLE → SKIP (never auto-update a server in an unknown state).
|
|
171
|
+
* - NOT (enabled && due) → SKIP (the no-op the disabled/not-due case wants).
|
|
172
|
+
* - enabled && due → run `server update`. On SUCCESS, stamp `last_run_at`
|
|
173
|
+
* (so the next due-check advances). On FAILURE (the update's own health-check
|
|
174
|
+
* rollback left the prior container running), log + do NOT stamp (so the next
|
|
175
|
+
* fire retries).
|
|
176
|
+
*
|
|
177
|
+
* The due-check is computed HOST-SIDE from the config the server returned (so the
|
|
178
|
+
* single source of truth — the core helper's logic — is mirrored here without a
|
|
179
|
+
* second round-trip): enabled AND the cadence has elapsed since `lastRunAt`
|
|
180
|
+
* (never-run → due).
|
|
181
|
+
*/
|
|
182
|
+
export declare function runAutoUpdate(options?: RunOptions): Promise<AutoUpdateResult>;
|
|
183
|
+
export {};
|
|
184
|
+
//# sourceMappingURL=autoupdate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autoupdate.d.ts","sourceRoot":"","sources":["../../src/server/autoupdate.ts"],"names":[],"mappings":"AAiEA,QAAA,MAAM,mBAAmB,8BAA+B,CAAC;AACzD,KAAK,iBAAiB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AAM9D,yFAAyF;AACzF,eAAO,MAAM,uBAAuB,qCAAqC,CAAC;AAE1E,6DAA6D;AAC7D,eAAO,MAAM,qBAAqB,mCAAmC,CAAC;AAKtE,iGAAiG;AACjG,eAAO,MAAM,WAAW,+BAA+B,CAAC;AAExD;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,qCAAgC,CAAC;AAQrE,qFAAqF;AACrF,wBAAgB,WAAW,IAAI,MAAM,CAEpC;AAED,2EAA2E;AAC3E,wBAAgB,SAAS,IAAI,MAAM,CAElC;AAED,+FAA+F;AAC/F,qBAAa,eAAgB,SAAQ,KAAK;gBAC5B,OAAO,EAAE,MAAM;CAI5B;AAED,MAAM,WAAW,gBAAgB;IAC/B,wCAAwC;IACxC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,iBAAiB;IAChC,gGAAgG;IAChG,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,GAAG,SAAS,CAAC;IACvC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