home-hosted 0.12.0 → 0.13.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 +95 -49
- package/dist/chunks/{archive-DpCwA8Nf.js → archive-DP-XQR8X.js} +15 -2
- package/dist/chunks/archive-DP-XQR8X.js.map +1 -0
- package/dist/chunks/{atomic-CEfCUfkQ.js → atomic-C1PfJpE7.js} +3 -2
- package/dist/chunks/atomic-C1PfJpE7.js.map +1 -0
- package/dist/chunks/{backup-CPrJVPJI.js → backup-CZcVca2a.js} +101 -76
- package/dist/chunks/backup-CZcVca2a.js.map +1 -0
- package/dist/chunks/{backups-Bd2SF2qd.js → backups-CFRaWe_m.js} +881 -536
- package/dist/chunks/backups-CFRaWe_m.js.map +1 -0
- package/dist/chunks/{contracts-ku5ypHXJ.js → contracts-CMBD1TF9.js} +381 -407
- package/dist/chunks/contracts-CMBD1TF9.js.map +1 -0
- package/dist/chunks/{daemon-TwXk5vb8.js → daemon-qKVECISl.js} +52 -20
- package/dist/chunks/daemon-qKVECISl.js.map +1 -0
- package/dist/chunks/{docker-CGv4Uv7w.js → docker-Cy9Lyvda.js} +4 -3
- package/dist/chunks/docker-Cy9Lyvda.js.map +1 -0
- package/dist/chunks/{down-BlX5X3bm.js → down-pKbGCW9d.js} +22 -17
- package/dist/chunks/down-pKbGCW9d.js.map +1 -0
- package/dist/chunks/{init-DdmqHVra.js → init-BZ7hK9Vf.js} +19 -6
- package/dist/chunks/init-BZ7hK9Vf.js.map +1 -0
- package/dist/chunks/{last-stop-BZ08Z89-.js → last-stop-C-BXz_XI.js} +6 -5
- package/dist/chunks/last-stop-C-BXz_XI.js.map +1 -0
- package/dist/chunks/{layout-D74TGUnr.js → layout-DwTtmund.js} +2 -2
- package/dist/chunks/{layout-D74TGUnr.js.map → layout-DwTtmund.js.map} +1 -1
- package/dist/chunks/lazy-Ce5zEAq1.js +66 -0
- package/dist/chunks/lazy-Ce5zEAq1.js.map +1 -0
- package/dist/chunks/{log-buffer-HnP0jKhZ.js → log-buffer-Dy9HHDMD.js} +114 -50
- package/dist/chunks/log-buffer-Dy9HHDMD.js.map +1 -0
- package/dist/chunks/{logs-gI_69Q1P.js → logs---TI_bxM.js} +23 -21
- package/dist/chunks/logs---TI_bxM.js.map +1 -0
- package/dist/chunks/{migrate-BTlsibvF.js → migrate-Cfoq-Vgh.js} +5 -5
- package/dist/chunks/{migrate-BTlsibvF.js.map → migrate-Cfoq-Vgh.js.map} +1 -1
- package/dist/chunks/{nanny-CjnnrIpm.js → nanny-B-Eu0sFW.js} +3 -3
- package/dist/chunks/{nanny-CjnnrIpm.js.map → nanny-B-Eu0sFW.js.map} +1 -1
- package/dist/chunks/{nanny-20aBXL1o.js → nanny-BtWfy0QH.js} +121 -23
- package/dist/chunks/nanny-BtWfy0QH.js.map +1 -0
- package/dist/chunks/{nanny-DUaAfCV-.js → nanny-ChMtq1Zl.js} +3 -3
- package/dist/chunks/{nanny-DUaAfCV-.js.map → nanny-ChMtq1Zl.js.map} +1 -1
- package/dist/chunks/{nanny-sweep-Ca9kPAVi.js → nanny-sweep-DErnlPY1.js} +5 -4
- package/dist/chunks/nanny-sweep-DErnlPY1.js.map +1 -0
- package/dist/chunks/{parse-B9owE47G.js → parse-DhmG26fI.js} +4 -4
- package/dist/chunks/{parse-B9owE47G.js.map → parse-DhmG26fI.js.map} +1 -1
- package/dist/chunks/{paths-BT94q6-w.js → paths-CGlGDrOU.js} +36 -2
- package/dist/chunks/paths-CGlGDrOU.js.map +1 -0
- package/dist/chunks/{restart-UZgeDukG.js → restart-Des4DrAN.js} +25 -59
- package/dist/chunks/restart-Des4DrAN.js.map +1 -0
- package/dist/chunks/{schema-o7Lgk0V1.js → schema-B240VXcV.js} +11 -10
- package/dist/chunks/schema-B240VXcV.js.map +1 -0
- package/dist/chunks/{secrets-D7PdYh71.js → secrets-BieELnZh.js} +22 -4
- package/dist/chunks/secrets-BieELnZh.js.map +1 -0
- package/dist/chunks/{server-BuIeSsRu.js → server-Bge2r2qQ.js} +3 -3
- package/dist/chunks/{server-BuIeSsRu.js.map → server-Bge2r2qQ.js.map} +1 -1
- package/dist/chunks/{set-password-DegMumPh.js → set-password-D5vZqqSX.js} +7 -7
- package/dist/chunks/set-password-D5vZqqSX.js.map +1 -0
- package/dist/chunks/{set-token-21d1FTDC.js → set-token-obPiEJYk.js} +7 -7
- package/dist/chunks/set-token-obPiEJYk.js.map +1 -0
- package/dist/chunks/{settings-BVSBnIwJ.js → settings-xu-XTfWg.js} +126 -35
- package/dist/chunks/settings-xu-XTfWg.js.map +1 -0
- package/dist/chunks/{setup-temp-XiuAtiW2.js → setup-temp-CAN4_bA-.js} +6 -6
- package/dist/chunks/setup-temp-CAN4_bA-.js.map +1 -0
- package/dist/chunks/{src-BL97vLVb.js → src-BtWMFmzZ.js} +2246 -1061
- package/dist/chunks/src-BtWMFmzZ.js.map +1 -0
- package/dist/chunks/{status-EuWdRq8Q.js → status-DT1EsA-B.js} +12 -8
- package/dist/chunks/status-DT1EsA-B.js.map +1 -0
- package/dist/chunks/{ui-DbPuwddJ.js → ui-D562aqw5.js} +9 -7
- package/dist/chunks/ui-D562aqw5.js.map +1 -0
- package/dist/chunks/{ui-revert-BhqOAhmM.js → ui-revert-EkBBwRTt.js} +3 -3
- package/dist/chunks/{ui-revert-BhqOAhmM.js.map → ui-revert-EkBBwRTt.js.map} +1 -1
- package/dist/chunks/{ui-switch-CMoslPO2.js → ui-switch-BnZTdMDd.js} +3 -3
- package/dist/chunks/{ui-switch-CMoslPO2.js.map → ui-switch-BnZTdMDd.js.map} +1 -1
- package/dist/chunks/{ui-update-TTBBoDik.js → ui-update-_xryLYxw.js} +5 -5
- package/dist/chunks/{ui-update-TTBBoDik.js.map → ui-update-_xryLYxw.js.map} +1 -1
- package/dist/chunks/{up-C4H13hBw.js → up-Pdz-l6IH.js} +25 -11
- package/dist/chunks/up-Pdz-l6IH.js.map +1 -0
- package/dist/chunks/{usage-CSBgLRN5.js → usage-DFrCVXpT.js} +29 -3
- package/dist/chunks/usage-DFrCVXpT.js.map +1 -0
- package/dist/chunks/{workspaces-CAln2sQ7.js → workspaces-DYcfvKV_.js} +16 -8
- package/dist/chunks/workspaces-DYcfvKV_.js.map +1 -0
- package/dist/chunks/wsl-temperature-BiCI4iK6.js.map +1 -1
- package/dist/cli.js +80 -70
- package/dist/cli.js.map +1 -1
- package/dist/client.js +25 -1
- package/dist/client.js.map +1 -1
- package/dist/types/api/backups.d.ts +8 -3
- package/dist/types/api/control.d.ts +4 -3
- package/dist/types/api/events.d.ts +2 -1
- package/dist/types/api/health.d.ts +1 -0
- package/dist/types/api/metrics.d.ts +3 -1
- package/dist/types/api/settings.d.ts +2 -2
- package/dist/types/api/state.d.ts +8 -2
- package/dist/types/app.d.ts +26 -11
- package/dist/types/cli/backup.d.ts +7 -0
- package/dist/types/cli/down.d.ts +5 -0
- package/dist/types/cli/logs.d.ts +14 -2
- package/dist/types/cli/restart.d.ts +0 -1
- package/dist/types/cli/set-password.d.ts +2 -2
- package/dist/types/cli/up.d.ts +8 -2
- package/dist/types/client.d.ts +5618 -11
- package/dist/types/config/secrets.d.ts +2 -0
- package/dist/types/config/settings.d.ts +54 -8
- package/dist/types/config/store.d.ts +16 -3
- package/dist/types/config/workspaces.d.ts +4 -1
- package/dist/types/helpers/copy-tree.d.ts +5 -0
- package/dist/types/helpers/daemon.d.ts +20 -7
- package/dist/types/helpers/error.d.ts +8 -0
- package/dist/types/helpers/event-stream.d.ts +21 -0
- package/dist/types/helpers/openapi.d.ts +12 -24
- package/dist/types/helpers/paths.d.ts +18 -0
- package/dist/types/helpers/utf8-chunks.d.ts +15 -0
- package/dist/types/middleware/auth.d.ts +19 -3
- package/dist/types/providers/host.d.ts +1 -1
- package/dist/types/providers/log-tail.d.ts +27 -0
- package/dist/types/providers/nanny-sweep.d.ts +3 -0
- package/dist/types/providers/nanny.d.ts +10 -0
- package/dist/types/providers/proc.d.ts +9 -0
- package/dist/types/providers/process.d.ts +17 -0
- package/dist/types/providers/telegram.d.ts +45 -3
- package/dist/types/providers/wsl-temperature.d.ts +0 -4
- package/dist/types/services/auth.d.ts +36 -4
- package/dist/types/services/backups.d.ts +125 -1
- package/dist/types/services/ddns.d.ts +5 -0
- package/dist/types/services/exposure.d.ts +54 -1
- package/dist/types/services/history.d.ts +1 -0
- package/dist/types/services/host-monitor.d.ts +1 -0
- package/dist/types/services/log-buffer.d.ts +11 -0
- package/dist/types/services/log-files.d.ts +1 -11
- package/dist/types/services/log-relay.d.ts +0 -1
- package/dist/types/services/panel.d.ts +19 -0
- package/dist/types/services/proxy-certificates/certificates.d.ts +116 -0
- package/dist/types/services/proxy.d.ts +46 -69
- package/dist/types/services/state.d.ts +0 -3
- package/dist/types/services/supervisor/entry.d.ts +10 -0
- package/dist/types/services/supervisor/health.d.ts +3 -2
- package/dist/types/services/supervisor/output.d.ts +126 -0
- package/dist/types/services/supervisor/persistent.d.ts +4 -1
- package/dist/types/services/supervisor/records.d.ts +81 -1
- package/dist/types/services/supervisor.d.ts +32 -0
- package/dist/types/shared/action-outcome.d.ts +25 -0
- package/dist/types/shared/api-client.d.ts +218 -4
- package/dist/types/shared/backup-scope.d.ts +58 -0
- package/dist/types/shared/contracts.d.ts +142 -200
- package/dist/types/shared/ddns-form.d.ts +13 -0
- package/dist/types/shared/form-repair.d.ts +6 -0
- package/dist/types/shared/lazy.d.ts +4 -0
- package/dist/types/shared/live-frames.d.ts +22 -0
- package/dist/types/shared/live-series.d.ts +21 -0
- package/dist/types/shared/live-store.d.ts +72 -0
- package/dist/types/shared/patch-diff.d.ts +13 -2
- package/dist/types/shared/proxy-form.d.ts +2 -0
- package/dist/types/shared/server-form.d.ts +121 -0
- package/dist/types/shared/stream-access.d.ts +20 -0
- package/docs/API.md +45 -16
- package/docs/BACKUPS.md +31 -11
- package/docs/CLI.md +34 -61
- package/docs/DDNS.md +3 -1
- package/docs/NOTIFICATIONS.md +7 -1
- package/docs/REVERSE_PROXY.md +7 -1
- package/docs/SECURITY.md +21 -10
- package/docs/SERVERS.md +102 -23
- package/docs/UI_CREATION.md +10 -1
- package/docs/demo/blank-host-restore.sh +4 -3
- package/package.json +5 -7
- package/uis/stock/dist/assets/CopyButton-BUBKRJyY.js +1 -0
- package/uis/stock/dist/assets/GlobalSettingsView-yYMcRWvt.js +1 -0
- package/uis/stock/dist/assets/LogViewer-DIliXy62.js +1 -0
- package/uis/stock/dist/assets/LogsView-B7Z-7RNg.js +1 -0
- package/uis/stock/dist/assets/Modal-DmKa5Qpp.js +39 -0
- package/uis/stock/dist/assets/ProxyView-DvZiNkwb.js +1 -0
- package/uis/stock/dist/assets/ServerDetailView-6idGT_EX.js +2 -0
- package/uis/stock/dist/assets/SettingsShell-CeGtleYI.js +1 -0
- package/uis/stock/dist/assets/SettingsView-BrhJIrmk.js +2 -0
- package/uis/stock/dist/assets/de-BRITeb0H.js +1 -0
- package/uis/stock/dist/assets/es-B2zIEssV.js +1 -0
- package/uis/stock/dist/assets/fr-s0ZOBEqh.js +1 -0
- package/uis/stock/dist/assets/index-C1MehbKy.css +2 -0
- package/uis/stock/dist/assets/index-CnBN54wF.js +15 -0
- package/uis/stock/dist/assets/ja-CU7MR85V.js +1 -0
- package/uis/stock/dist/assets/ko-tL5Me6d-.js +1 -0
- package/uis/stock/dist/assets/ru-92yrvkNJ.js +1 -0
- package/uis/stock/dist/assets/vi-CzvY16k2.js +1 -0
- package/uis/stock/dist/assets/zh-CN-DDwFW_uW.js +1 -0
- package/uis/stock/dist/index.html +3 -2
- package/uis/stock/dist/ui.json +3 -3
- package/dist/chunks/archive-DpCwA8Nf.js.map +0 -1
- package/dist/chunks/atomic-CEfCUfkQ.js.map +0 -1
- package/dist/chunks/backup-CPrJVPJI.js.map +0 -1
- package/dist/chunks/backups-Bd2SF2qd.js.map +0 -1
- package/dist/chunks/contracts-ku5ypHXJ.js.map +0 -1
- package/dist/chunks/daemon-TwXk5vb8.js.map +0 -1
- package/dist/chunks/docker-CGv4Uv7w.js.map +0 -1
- package/dist/chunks/down-BlX5X3bm.js.map +0 -1
- package/dist/chunks/init-DdmqHVra.js.map +0 -1
- package/dist/chunks/last-stop-BZ08Z89-.js.map +0 -1
- package/dist/chunks/log-buffer-HnP0jKhZ.js.map +0 -1
- package/dist/chunks/logs-gI_69Q1P.js.map +0 -1
- package/dist/chunks/nanny-20aBXL1o.js.map +0 -1
- package/dist/chunks/nanny-sweep-Ca9kPAVi.js.map +0 -1
- package/dist/chunks/paths-BT94q6-w.js.map +0 -1
- package/dist/chunks/restart-UZgeDukG.js.map +0 -1
- package/dist/chunks/schema-o7Lgk0V1.js.map +0 -1
- package/dist/chunks/secrets-D7PdYh71.js.map +0 -1
- package/dist/chunks/set-password-DegMumPh.js.map +0 -1
- package/dist/chunks/set-token-21d1FTDC.js.map +0 -1
- package/dist/chunks/settings-BVSBnIwJ.js.map +0 -1
- package/dist/chunks/setup-temp-XiuAtiW2.js.map +0 -1
- package/dist/chunks/src-BL97vLVb.js.map +0 -1
- package/dist/chunks/status-EuWdRq8Q.js.map +0 -1
- package/dist/chunks/ui-DbPuwddJ.js.map +0 -1
- package/dist/chunks/up-C4H13hBw.js.map +0 -1
- package/dist/chunks/usage-CSBgLRN5.js.map +0 -1
- package/dist/chunks/workspaces-CAln2sQ7.js.map +0 -1
- package/docs/RESTORE_DEMO.md +0 -306
- package/uis/stock/dist/assets/de-DyGrM1KK.js +0 -1
- package/uis/stock/dist/assets/es-BebHdc0E.js +0 -1
- package/uis/stock/dist/assets/fr-DsDTrxhI.js +0 -1
- package/uis/stock/dist/assets/index-6LANO2Ua.css +0 -2
- package/uis/stock/dist/assets/index-D06cUZbM.js +0 -56
- package/uis/stock/dist/assets/ja-D3RARJjW.js +0 -1
- package/uis/stock/dist/assets/ko-CKI3dFoD.js +0 -1
- package/uis/stock/dist/assets/ru-DEU5ujXt.js +0 -1
- package/uis/stock/dist/assets/vi-ULKPnasj.js +0 -1
- package/uis/stock/dist/assets/zh-CN-tCvnOxWy.js +0 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { i as ensureStateDir } from "./paths-CGlGDrOU.js";
|
|
1
2
|
import path from "node:path";
|
|
2
3
|
import fs from "node:fs";
|
|
3
4
|
import { Buffer } from "node:buffer";
|
|
5
|
+
import { StringDecoder } from "node:string_decoder";
|
|
4
6
|
//#region src/services/log-files.ts
|
|
5
7
|
/**
|
|
6
8
|
* Append-only JSONL per server, one line per log entry, rotated by size.
|
|
@@ -88,16 +90,18 @@ var LogFiles = class {
|
|
|
88
90
|
* a line that was on disk — a search that answers "nothing found" while the log holds the
|
|
89
91
|
* match is worse than a shorter window.
|
|
90
92
|
*/
|
|
91
|
-
readTail(serverId, tail) {
|
|
93
|
+
async readTail(serverId, tail) {
|
|
92
94
|
if (!this.getConfig().persist) return [];
|
|
93
95
|
const sources = this.retained(serverId);
|
|
94
|
-
const
|
|
96
|
+
const parts = [];
|
|
97
|
+
let found = 0;
|
|
95
98
|
for (const file of sources) {
|
|
96
|
-
if (
|
|
97
|
-
const chunk =
|
|
98
|
-
|
|
99
|
+
if (found >= tail) break;
|
|
100
|
+
const chunk = await readFileTail(file, tail - found);
|
|
101
|
+
parts.unshift(chunk);
|
|
102
|
+
found += chunk.length;
|
|
99
103
|
}
|
|
100
|
-
return
|
|
104
|
+
return parts.flat().slice(-tail);
|
|
101
105
|
}
|
|
102
106
|
clear(serverId) {
|
|
103
107
|
this.pending.delete(serverId);
|
|
@@ -136,7 +140,7 @@ var LogFiles = class {
|
|
|
136
140
|
write(serverId, lines) {
|
|
137
141
|
const { maxBytes } = this.getConfig();
|
|
138
142
|
const file = this.currentPath(serverId);
|
|
139
|
-
|
|
143
|
+
ensureStateDir(this.dir);
|
|
140
144
|
let encoded = [];
|
|
141
145
|
let bytes = 0;
|
|
142
146
|
const commit = () => {
|
|
@@ -185,46 +189,6 @@ var LogFiles = class {
|
|
|
185
189
|
}
|
|
186
190
|
if (fs.existsSync(this.currentPath(serverId))) fs.renameSync(this.currentPath(serverId), this.rotatedPath(serverId, 1));
|
|
187
191
|
}
|
|
188
|
-
/**
|
|
189
|
-
* The last `tail` parseable lines of one file.
|
|
190
|
-
*
|
|
191
|
-
* Reads backwards, growing the window until it has enough lines. It used to read exactly one
|
|
192
|
-
* fixed chunk, which silently truncated: a JSONL line here is a couple of hundred bytes, so
|
|
193
|
-
* one 256 KB chunk holds roughly 1500 of them, while the route accepts `tail=5000`. Asking
|
|
194
|
-
* for 5000 returned 1464 and dropped 3536 lines with no error — the oldest line handed back
|
|
195
|
-
* was not the oldest asked for.
|
|
196
|
-
*/
|
|
197
|
-
readTailChunk(file, tail) {
|
|
198
|
-
let handle;
|
|
199
|
-
try {
|
|
200
|
-
handle = fs.openSync(file, "r");
|
|
201
|
-
} catch {
|
|
202
|
-
return [];
|
|
203
|
-
}
|
|
204
|
-
try {
|
|
205
|
-
const size = fs.fstatSync(handle).size;
|
|
206
|
-
if (size === 0) return [];
|
|
207
|
-
let start = Math.max(0, size - READ_CHUNK_BYTES);
|
|
208
|
-
let parsed = [];
|
|
209
|
-
while (true) {
|
|
210
|
-
const length = size - start;
|
|
211
|
-
const buffer = Buffer.alloc(length);
|
|
212
|
-
fs.readSync(handle, buffer, 0, length, start);
|
|
213
|
-
const raw = buffer.toString("utf8").split("\n");
|
|
214
|
-
parsed = [];
|
|
215
|
-
for (const entry of start > 0 ? raw.slice(1) : raw) {
|
|
216
|
-
if (entry.trim().length === 0) continue;
|
|
217
|
-
try {
|
|
218
|
-
parsed.push(JSON.parse(entry));
|
|
219
|
-
} catch {}
|
|
220
|
-
}
|
|
221
|
-
if (parsed.length >= tail || start === 0) return parsed.slice(-tail);
|
|
222
|
-
start = Math.max(0, start - READ_CHUNK_BYTES);
|
|
223
|
-
}
|
|
224
|
-
} finally {
|
|
225
|
-
fs.closeSync(handle);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
192
|
currentPath(serverId) {
|
|
229
193
|
return path.join(this.dir, `${serverId}.log`);
|
|
230
194
|
}
|
|
@@ -270,6 +234,91 @@ var LogFiles = class {
|
|
|
270
234
|
return current === void 0 ? covered : [current, ...covered];
|
|
271
235
|
}
|
|
272
236
|
};
|
|
237
|
+
/**
|
|
238
|
+
* The last `tail` parseable lines of one file, oldest first.
|
|
239
|
+
*
|
|
240
|
+
* Reads backwards one chunk at a time, carrying the bytes before a chunk's first newline into
|
|
241
|
+
* the next (older) chunk, so every byte is read and parsed once and the cost is what is returned.
|
|
242
|
+
* The previous reader grew a window by a fixed step and re-read and re-parsed all of it each
|
|
243
|
+
* time, synchronously: 5000 lines of 8 KB took seconds with the event loop held throughout.
|
|
244
|
+
* Lines are cut on the `\n` byte, which never occurs inside a UTF-8 sequence, so no character is
|
|
245
|
+
* split. A blank line, a torn write at the end and anything that does not parse are skipped.
|
|
246
|
+
*/
|
|
247
|
+
async function readFileTail(file, tail) {
|
|
248
|
+
if (tail <= 0) return [];
|
|
249
|
+
let handle;
|
|
250
|
+
try {
|
|
251
|
+
handle = await fs.promises.open(file, "r");
|
|
252
|
+
} catch {
|
|
253
|
+
return [];
|
|
254
|
+
}
|
|
255
|
+
const found = [];
|
|
256
|
+
const take = (bytes) => {
|
|
257
|
+
const text = bytes.toString("utf8");
|
|
258
|
+
if (text.trim().length === 0) return;
|
|
259
|
+
try {
|
|
260
|
+
found.push(JSON.parse(text));
|
|
261
|
+
} catch {}
|
|
262
|
+
};
|
|
263
|
+
try {
|
|
264
|
+
let end = (await handle.stat()).size;
|
|
265
|
+
let carry = [];
|
|
266
|
+
while (end > 0 && found.length < tail) {
|
|
267
|
+
const start = Math.max(0, end - READ_CHUNK_BYTES);
|
|
268
|
+
const chunk = Buffer.allocUnsafe(end - start);
|
|
269
|
+
let filled = 0;
|
|
270
|
+
while (filled < chunk.length) {
|
|
271
|
+
const { bytesRead } = await handle.read(chunk, filled, chunk.length - filled, start + filled);
|
|
272
|
+
if (bytesRead <= 0) break;
|
|
273
|
+
filled += bytesRead;
|
|
274
|
+
}
|
|
275
|
+
const bytes = chunk.subarray(0, filled);
|
|
276
|
+
end = start;
|
|
277
|
+
let lineEnd = bytes.length;
|
|
278
|
+
let newline = bytes.lastIndexOf(10, lineEnd - 1);
|
|
279
|
+
if (newline === -1) {
|
|
280
|
+
carry.unshift(bytes);
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
take(Buffer.concat([bytes.subarray(newline + 1), ...carry]));
|
|
284
|
+
carry = [];
|
|
285
|
+
lineEnd = newline;
|
|
286
|
+
while (found.length < tail && lineEnd > 0) {
|
|
287
|
+
newline = bytes.lastIndexOf(10, lineEnd - 1);
|
|
288
|
+
if (newline === -1) break;
|
|
289
|
+
take(bytes.subarray(newline + 1, lineEnd));
|
|
290
|
+
lineEnd = newline;
|
|
291
|
+
}
|
|
292
|
+
carry = [bytes.subarray(0, lineEnd)];
|
|
293
|
+
}
|
|
294
|
+
if (end === 0 && found.length < tail) take(Buffer.concat(carry));
|
|
295
|
+
} finally {
|
|
296
|
+
await handle.close();
|
|
297
|
+
}
|
|
298
|
+
return found.slice(0, tail).reverse();
|
|
299
|
+
}
|
|
300
|
+
//#endregion
|
|
301
|
+
//#region src/helpers/utf8-chunks.ts
|
|
302
|
+
/**
|
|
303
|
+
* Decodes one byte stream's chunks as UTF-8, carrying a character split across two chunks.
|
|
304
|
+
*
|
|
305
|
+
* A pipe or a bounded read cuts wherever it likes, so `chunk.toString()` per chunk turned a `€`
|
|
306
|
+
* straddling the cut into two U+FFFD. One decoder per stream, ended when the stream ends.
|
|
307
|
+
*/
|
|
308
|
+
var Utf8Chunks = class {
|
|
309
|
+
decoder = new StringDecoder("utf8");
|
|
310
|
+
write(chunk) {
|
|
311
|
+
return typeof chunk === "string" ? chunk : this.decoder.write(chunk);
|
|
312
|
+
}
|
|
313
|
+
/** The stream ended: whatever incomplete bytes remain, rendered as U+FFFD. */
|
|
314
|
+
end() {
|
|
315
|
+
return this.decoder.end();
|
|
316
|
+
}
|
|
317
|
+
/** Drop held bytes without rendering them, e.g. when the source was replaced. */
|
|
318
|
+
reset() {
|
|
319
|
+
this.decoder = new StringDecoder("utf8");
|
|
320
|
+
}
|
|
321
|
+
};
|
|
273
322
|
//#endregion
|
|
274
323
|
//#region src/services/log-buffer.ts
|
|
275
324
|
/** A partial line past this size is emitted rather than buffered further. */
|
|
@@ -325,11 +374,13 @@ var LogBuffer = class {
|
|
|
325
374
|
var LineSplitter = class {
|
|
326
375
|
emit;
|
|
327
376
|
pending = "";
|
|
377
|
+
/** One splitter is one byte stream, so a character split across two chunks survives. */
|
|
378
|
+
decoder = new Utf8Chunks();
|
|
328
379
|
constructor(emit) {
|
|
329
380
|
this.emit = emit;
|
|
330
381
|
}
|
|
331
382
|
push(stream, chunk) {
|
|
332
|
-
this.pending +=
|
|
383
|
+
this.pending += this.decoder.write(chunk);
|
|
333
384
|
const parts = this.pending.split("\n");
|
|
334
385
|
this.pending = parts.pop() ?? "";
|
|
335
386
|
for (const part of parts) this.emit(stream, part.replace(/\r$/, ""));
|
|
@@ -339,12 +390,25 @@ var LineSplitter = class {
|
|
|
339
390
|
}
|
|
340
391
|
}
|
|
341
392
|
flush(stream) {
|
|
393
|
+
this.pending += this.decoder.end();
|
|
342
394
|
if (this.pending.length === 0) return;
|
|
343
395
|
this.emit(stream, this.pending.replace(/\r$/, ""));
|
|
344
396
|
this.pending = "";
|
|
345
397
|
}
|
|
398
|
+
/**
|
|
399
|
+
* Throws away a held partial line, because the bytes that would have finished it are gone.
|
|
400
|
+
*
|
|
401
|
+
* Only the file-transport reader calls this, when it drops a backlog: it discards from a byte
|
|
402
|
+
* offset, so whatever half-line it was holding can never be completed by what follows. Keeping it
|
|
403
|
+
* would splice the fragment onto the first surviving line and emit text the child never wrote —
|
|
404
|
+
* corrupted output presented as real, which is worse than the gap it was meant to describe.
|
|
405
|
+
*/
|
|
406
|
+
discard() {
|
|
407
|
+
this.pending = "";
|
|
408
|
+
this.decoder.reset();
|
|
409
|
+
}
|
|
346
410
|
};
|
|
347
411
|
//#endregion
|
|
348
|
-
export { LogBuffer as n,
|
|
412
|
+
export { LogFiles as i, LogBuffer as n, Utf8Chunks as r, LineSplitter as t };
|
|
349
413
|
|
|
350
|
-
//# sourceMappingURL=log-buffer-
|
|
414
|
+
//# sourceMappingURL=log-buffer-Dy9HHDMD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-buffer-Dy9HHDMD.js","names":[],"sources":["../../src/services/log-files.ts","../../src/helpers/utf8-chunks.ts","../../src/services/log-buffer.ts"],"sourcesContent":["import type { LogLine, LogsConfig } from '#src/shared/contracts'\nimport { Buffer } from 'node:buffer'\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport { ensureStateDir } from '#src/helpers/paths'\n\n/**\n * Append-only JSONL per server, one line per log entry, rotated by size.\n *\n * JSONL keeps the tail readable without parsing a stream, and appending needs no\n * rewrite of the existing file. Writes are batched on a short timer so a chatty\n * child cannot turn into a syscall per line.\n */\nconst FLUSH_INTERVAL_MS = 250\nconst MAX_PENDING_LINES = 500\nconst READ_CHUNK_BYTES = 256 * 1024\n\nexport interface LogFileInfo {\n name: string\n sizeBytes: number\n}\n\nexport class LogFiles {\n private readonly pending = new Map<string, LogLine[]>()\n private timer: NodeJS.Timeout | null = null\n private closed = false\n\n constructor(\n private readonly dir: string,\n private readonly getConfig: () => LogsConfig,\n ) {}\n\n get directory(): string {\n return this.dir\n }\n\n /** The retention a nanny has to apply itself, on the same files. */\n get config(): LogsConfig {\n return this.getConfig()\n }\n\n append(serverId: string, line: LogLine): void {\n if (this.closed || !this.getConfig().persist)\n return\n\n const bucket = this.pending.get(serverId) ?? []\n bucket.push(line)\n this.pending.set(serverId, bucket)\n\n if (bucket.length >= MAX_PENDING_LINES) {\n this.flush()\n return\n }\n this.timer ??= setTimeout(() => {\n this.timer = null\n this.flush()\n }, FLUSH_INTERVAL_MS)\n this.timer.unref()\n }\n\n flush(): void {\n if (this.pending.size === 0)\n return\n\n const batches = [...this.pending.entries()]\n this.pending.clear()\n\n for (const [serverId, lines] of batches) {\n try {\n this.write(serverId, lines)\n }\n catch {\n // Logging must never take the control plane down.\n }\n }\n }\n\n info(serverId: string): { enabled: boolean, sizeBytes: number, files: LogFileInfo[] } {\n const config = this.getConfig()\n const files: LogFileInfo[] = []\n let sizeBytes = 0\n\n if (!config.persist)\n return { enabled: false, sizeBytes, files }\n\n for (const file of this.retained(serverId)) {\n try {\n const stats = fs.statSync(file)\n files.push({ name: path.basename(file), sizeBytes: stats.size })\n // The whole retained set, not just the newest file: this is summed into the page's\n // \"on disk\" total, and a server whose current file had just rotated read as nearly\n // empty while its rotations sat beside it.\n sizeBytes += stats.size\n }\n catch {\n // Not there yet.\n }\n }\n\n return { enabled: config.persist, sizeBytes, files }\n }\n\n /**\n * Reads the last `tail` lines, newest file first, padding from the rotations behind it.\n *\n * With `persist` off there is nothing this panel is willing to serve, even though a\n * persistent entry's nanny still writes its file: that file is the log's transport —\n * there is no pipe to carry it — and `persist` decides what counts as history.\n *\n * Every *retained* file is a source, not just `.1`: `keep` is the number of rotations the\n * person asked to keep, so a 5000-line window over a 10 MB rotation could not be filled by\n * the current file and `.1` alone. It read two of eleven files and returned \"no matches\" for\n * a line that was on disk — a search that answers \"nothing found\" while the log holds the\n * match is worse than a shorter window.\n */\n async readTail(serverId: string, tail: number): Promise<LogLine[]> {\n if (!this.getConfig().persist)\n return []\n\n // Newest first, so each file's lines go in front of the ones already read.\n const sources = this.retained(serverId)\n const parts: LogLine[][] = []\n let found = 0\n\n for (const file of sources) {\n if (found >= tail)\n break\n const chunk = await readFileTail(file, tail - found)\n parts.unshift(chunk)\n found += chunk.length\n }\n\n return parts.flat().slice(-tail)\n }\n\n clear(serverId: string): void {\n // The batch that has not been flushed yet is still this server's, and `flush()` would write it\n // straight back — so the lines a delete was meant to remove reappeared a moment later.\n this.pending.delete(serverId)\n // Every file this id has, not the ones `keep` would name: lowering `keep` leaves rotations\n // numbered above it, and those are still this server's bytes. Deleting \"all the logs\" and\n // leaving five files behind is the worst version of this bug, because nothing lists them.\n for (const file of this.ownedFiles(serverId)) {\n try {\n fs.rmSync(file, { force: true })\n }\n catch {\n // Nothing to remove.\n }\n }\n }\n\n /**\n * Drops rotations above the current `keep`, for every server, now.\n *\n * `rotate` prunes too, but it only runs when a file fills — which on a quiet entry can be days\n * after the person lowered the ceiling. A retention setting that takes effect \"eventually, once\n * the server is chatty enough\" is not the promise the page makes, so the settings save calls\n * this directly.\n */\n prune(): void {\n let names: string[]\n try {\n names = fs.readdirSync(this.dir)\n }\n catch {\n return\n }\n\n const ids = new Set<string>()\n for (const name of names) {\n // `<id>.log` or `<id>.log.<n>`; the id charset has no dot, so the first dot ends it.\n const dot = name.indexOf('.log')\n if (dot > 0 && (name.length === dot + 4 || name.startsWith('.log.', dot)))\n ids.add(name.slice(0, dot))\n }\n for (const id of ids) this.pruneServer(id)\n }\n\n dispose(): void {\n this.closed = true\n if (this.timer !== null)\n clearTimeout(this.timer)\n this.timer = null\n this.flush()\n }\n\n private write(serverId: string, lines: LogLine[]): void {\n const { maxBytes } = this.getConfig()\n const file = this.currentPath(serverId)\n ensureStateDir(this.dir)\n\n // A batch is split at the size limit: writing it whole would sail past\n // maxBytes long before the next rotation check runs.\n let encoded: string[] = []\n let bytes = 0\n\n const commit = (): void => {\n if (encoded.length === 0)\n return\n const payload = `${encoded.join('\\n')}\\n`\n const currentSize = fs.existsSync(file) ? fs.statSync(file).size : 0\n if (currentSize + Buffer.byteLength(payload) > maxBytes)\n this.rotate(serverId)\n fs.appendFileSync(this.currentPath(serverId), payload)\n encoded = []\n bytes = 0\n }\n\n for (const line of lines) {\n const json = JSON.stringify(line)\n const size = Buffer.byteLength(json) + 1\n if (bytes > 0 && bytes + size > maxBytes)\n commit()\n encoded.push(json)\n bytes += size\n }\n\n commit()\n }\n\n /**\n * Drops this id's rotations numbered above `keep`.\n *\n * They are left over from a higher ceiling (or an older release). Renaming up only ever shifts\n * them further out of reach, so they have to be removed outright: a retention setting is a\n * promise about the directory, not about a rename loop.\n */\n private pruneServer(serverId: string): void {\n const { keep } = this.getConfig()\n const current = this.currentPath(serverId)\n for (const file of this.ownedFiles(serverId)) {\n if (file === current)\n continue\n const index = Number(file.slice(current.length + 1))\n if (!Number.isInteger(index) || index <= keep)\n continue\n try {\n fs.rmSync(file, { force: true })\n }\n catch {\n // Already gone.\n }\n }\n }\n\n private rotate(serverId: string): void {\n const { keep } = this.getConfig()\n this.pruneServer(serverId)\n for (let index = keep - 1; index >= 1; index--) {\n const from = this.rotatedPath(serverId, index)\n if (!fs.existsSync(from))\n continue\n fs.renameSync(from, this.rotatedPath(serverId, index + 1))\n }\n if (fs.existsSync(this.currentPath(serverId))) {\n fs.renameSync(this.currentPath(serverId), this.rotatedPath(serverId, 1))\n }\n }\n\n private currentPath(serverId: string): string {\n return path.join(this.dir, `${serverId}.log`)\n }\n\n private rotatedPath(serverId: string, index: number): string {\n return path.join(this.dir, `${serverId}.log.${index}`)\n }\n\n /**\n * Every file this id owns on disk, newest first, found by reading the directory.\n *\n * The count comes from the directory rather than from `keep` because the two disagree the\n * moment a person lowers it: `rotate` only renames *up* to the new ceiling, so it never removes\n * the rotations numbered above it. Those files stayed, were invisible to `info()`, were served\n * by no reader, and survived a `clear` — growth the retention setting promised to bound, in\n * files nothing would ever show. Reading the directory is also what makes them prunable.\n */\n private ownedFiles(serverId: string): string[] {\n const current = this.currentPath(serverId)\n const prefix = `${serverId}.log.`\n let names: string[]\n try {\n names = fs.readdirSync(this.dir)\n }\n catch {\n return fs.existsSync(current) ? [current] : []\n }\n\n // `.log.1`, `.log.2`, … in numeric order — a plain string sort puts `.10` before `.2`.\n const rotated = names\n .filter(name => name.startsWith(prefix))\n .map(name => ({ name, index: Number(name.slice(prefix.length)) }))\n .filter(entry => Number.isInteger(entry.index) && entry.index >= 1)\n .sort((a, b) => a.index - b.index)\n .map(entry => path.join(this.dir, entry.name))\n\n // Newest first, which is the order `info()` lists and the order a tail walks.\n return fs.existsSync(current) ? [current, ...rotated] : rotated\n }\n\n /**\n * The files `keep` still covers, newest first — what `info` lists and what a tail may read.\n *\n * The current file is always first and never counted against `keep`, which is what the UI\n * promises (\"before rolling to .1, .2, …\").\n */\n private retained(serverId: string): string[] {\n const { keep } = this.getConfig()\n const owned = this.ownedFiles(serverId)\n if (owned.length === 0)\n return []\n const [current, ...rotated] = owned\n // `rotated` is ascending from `.1`, so the first `keep` of it are the newest rotations.\n const covered = rotated.slice(0, keep)\n return current === undefined ? covered : [current, ...covered]\n }\n}\n\n/**\n * The last `tail` parseable lines of one file, oldest first.\n *\n * Reads backwards one chunk at a time, carrying the bytes before a chunk's first newline into\n * the next (older) chunk, so every byte is read and parsed once and the cost is what is returned.\n * The previous reader grew a window by a fixed step and re-read and re-parsed all of it each\n * time, synchronously: 5000 lines of 8 KB took seconds with the event loop held throughout.\n * Lines are cut on the `\\n` byte, which never occurs inside a UTF-8 sequence, so no character is\n * split. A blank line, a torn write at the end and anything that does not parse are skipped.\n */\nasync function readFileTail(file: string, tail: number): Promise<LogLine[]> {\n if (tail <= 0)\n return []\n let handle: fs.promises.FileHandle\n try {\n handle = await fs.promises.open(file, 'r')\n }\n catch {\n return []\n }\n\n const found: LogLine[] = [] // newest first\n const take = (bytes: Buffer): void => {\n const text = bytes.toString('utf8')\n if (text.trim().length === 0)\n return\n try {\n found.push(JSON.parse(text) as LogLine)\n }\n catch {\n // A partial line, or a torn write at the file's end.\n }\n }\n\n try {\n let end = (await handle.stat()).size\n // The start of the line the newer chunks began in the middle of, newest piece last.\n let carry: Buffer[] = []\n while (end > 0 && found.length < tail) {\n const start = Math.max(0, end - READ_CHUNK_BYTES)\n const chunk = Buffer.allocUnsafe(end - start)\n let filled = 0\n while (filled < chunk.length) {\n const { bytesRead } = await handle.read(chunk, filled, chunk.length - filled, start + filled)\n if (bytesRead <= 0)\n break\n filled += bytesRead\n }\n // A file shrunk under the read: what was not filled is not data.\n const bytes = chunk.subarray(0, filled)\n end = start\n\n let lineEnd = bytes.length\n let newline = bytes.lastIndexOf(0x0A, lineEnd - 1)\n if (newline === -1) {\n carry.unshift(bytes)\n continue\n }\n // The newest line here continues into what the newer chunks left over.\n take(Buffer.concat([bytes.subarray(newline + 1), ...carry]))\n carry = []\n lineEnd = newline\n while (found.length < tail && lineEnd > 0) {\n newline = bytes.lastIndexOf(0x0A, lineEnd - 1)\n if (newline === -1)\n break\n take(bytes.subarray(newline + 1, lineEnd))\n lineEnd = newline\n }\n carry = [bytes.subarray(0, lineEnd)]\n }\n // The file's first line has no newline before it.\n if (end === 0 && found.length < tail)\n take(Buffer.concat(carry))\n }\n finally {\n await handle.close()\n }\n\n return found.slice(0, tail).reverse()\n}\n","import type { Buffer } from 'node:buffer'\nimport { StringDecoder } from 'node:string_decoder'\n\n/**\n * Decodes one byte stream's chunks as UTF-8, carrying a character split across two chunks.\n *\n * A pipe or a bounded read cuts wherever it likes, so `chunk.toString()` per chunk turned a `€`\n * straddling the cut into two U+FFFD. One decoder per stream, ended when the stream ends.\n */\nexport class Utf8Chunks {\n private decoder = new StringDecoder('utf8')\n\n write(chunk: string | Buffer): string {\n return typeof chunk === 'string' ? chunk : this.decoder.write(chunk)\n }\n\n /** The stream ended: whatever incomplete bytes remain, rendered as U+FFFD. */\n end(): string {\n return this.decoder.end()\n }\n\n /** Drop held bytes without rendering them, e.g. when the source was replaced. */\n reset(): void {\n this.decoder = new StringDecoder('utf8')\n }\n}\n","import type { Buffer } from 'node:buffer'\nimport type { LogLine, LogStream } from '#src/shared/contracts'\nimport { Utf8Chunks } from '#src/helpers/utf8-chunks'\n\n/** A partial line past this size is emitted rather than buffered further. */\nconst MAX_PENDING_CHARS = 64 * 1024\n\n/**\n * How many *characters* the ring may hold, on top of its line count.\n *\n * `logBufferLines` bounds lines, and a line is capped at 64 KiB by the splitter — so 500 lines\n * of a chatty 2 MB/s writer is ~32 MB per server, times every server, in the panel's heap. The\n * count is the user's setting; this is the ceiling that keeps that setting from being a memory\n * bomb. Generous enough that ordinary logs never reach it (500 lines is well under 1 MB).\n */\nconst MAX_TOTAL_CHARS = 4 * 1024 * 1024\n\n/** Fixed-capacity line buffer; oldest lines are dropped first. */\nexport class LogBuffer {\n private lines: LogLine[] = []\n /** Characters held, so the byte ceiling never needs a rescan. */\n private chars = 0\n\n constructor(private capacity: number) {}\n\n push(line: LogLine): void {\n this.lines.push(line)\n this.chars += line.text.length\n if (this.lines.length > this.capacity)\n this.dropOldest(this.lines.length - this.capacity)\n // Drop past the ceiling too, keeping at least one line so a single oversized line is still\n // shown rather than leaving the buffer empty.\n while (this.chars > MAX_TOTAL_CHARS && this.lines.length > 1)\n this.dropOldest(1)\n }\n\n /** Removes the oldest `count` lines and keeps `chars` in step with them. */\n private dropOldest(count: number): void {\n const dropped = this.lines.splice(0, count)\n for (const line of dropped) this.chars -= line.text.length\n }\n\n extend(lines: LogLine[]): void {\n for (const line of lines) this.push(line)\n }\n\n list(limit?: number): LogLine[] {\n if (limit === undefined || limit >= this.lines.length)\n return [...this.lines]\n return this.lines.slice(-limit)\n }\n\n clear(): void {\n this.lines = []\n this.chars = 0\n }\n\n get size(): number {\n return this.lines.length\n }\n}\n\n/**\n * Splits a chunk into complete lines, keeping a trailing partial line buffered:\n * a child writing \"hel\" then \"lo\\n\" must surface one line, not two.\n */\nexport class LineSplitter {\n private pending = ''\n /** One splitter is one byte stream, so a character split across two chunks survives. */\n private readonly decoder = new Utf8Chunks()\n\n constructor(private readonly emit: (stream: LogStream, text: string) => void) {}\n\n push(stream: LogStream, chunk: string | Buffer): void {\n this.pending += this.decoder.write(chunk)\n const parts = this.pending.split('\\n')\n this.pending = parts.pop() ?? ''\n for (const part of parts) this.emit(stream, part.replace(/\\r$/, ''))\n // A child that never sends a newline (a progress bar, one minified JSON blob)\n // must not grow this string without bound: past the cap it is emitted in pieces.\n while (this.pending.length > MAX_PENDING_CHARS) {\n this.emit(stream, this.pending.slice(0, MAX_PENDING_CHARS))\n this.pending = this.pending.slice(MAX_PENDING_CHARS)\n }\n }\n\n flush(stream: LogStream): void {\n this.pending += this.decoder.end()\n if (this.pending.length === 0)\n return\n this.emit(stream, this.pending.replace(/\\r$/, ''))\n this.pending = ''\n }\n\n /**\n * Throws away a held partial line, because the bytes that would have finished it are gone.\n *\n * Only the file-transport reader calls this, when it drops a backlog: it discards from a byte\n * offset, so whatever half-line it was holding can never be completed by what follows. Keeping it\n * would splice the fragment onto the first surviving line and emit text the child never wrote —\n * corrupted output presented as real, which is worse than the gap it was meant to describe.\n */\n discard(): void {\n this.pending = ''\n this.decoder.reset()\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,IAAM,oBAAoB;AAC1B,IAAM,oBAAoB;AAC1B,IAAM,mBAAmB;AAOzB,IAAa,WAAb,MAAsB;CAMD;CACA;CANnB,0BAA2B,IAAI,IAAuB;CACtD,QAAuC;CACvC,SAAiB;CAEjB,YACE,KACA,WACA;EAFiB,KAAA,MAAA;EACA,KAAA,YAAA;CAChB;CAEH,IAAI,YAAoB;EACtB,OAAO,KAAK;CACd;;CAGA,IAAI,SAAqB;EACvB,OAAO,KAAK,UAAU;CACxB;CAEA,OAAO,UAAkB,MAAqB;EAC5C,IAAI,KAAK,UAAU,CAAC,KAAK,UAAU,CAAC,CAAC,SACnC;EAEF,MAAM,SAAS,KAAK,QAAQ,IAAI,QAAQ,KAAK,CAAC;EAC9C,OAAO,KAAK,IAAI;EAChB,KAAK,QAAQ,IAAI,UAAU,MAAM;EAEjC,IAAI,OAAO,UAAU,mBAAmB;GACtC,KAAK,MAAM;GACX;EACF;EACA,KAAK,UAAU,iBAAiB;GAC9B,KAAK,QAAQ;GACb,KAAK,MAAM;EACb,GAAG,iBAAiB;EACpB,KAAK,MAAM,MAAM;CACnB;CAEA,QAAc;EACZ,IAAI,KAAK,QAAQ,SAAS,GACxB;EAEF,MAAM,UAAU,CAAC,GAAG,KAAK,QAAQ,QAAQ,CAAC;EAC1C,KAAK,QAAQ,MAAM;EAEnB,KAAK,MAAM,CAAC,UAAU,UAAU,SAC9B,IAAI;GACF,KAAK,MAAM,UA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AM,QAAyB;EAC7B,KAAK,WAAW,KAAK,QAAQ,IAAI;EACjC,IAAI,KAAK,QAAQ,WAAW,GAC1B;EACF,KAAK,KAAK,QAAQ,KAAK,QAAQ,QAAQ,OAAO,EAAE,CAAC;EACjD,KAAK,UAAU;CACjB;;;;;;;;;CAUA,UAAgB;EACd,KAAK,UAAU;EACf,KAAK,QAAQ,MAAM;CACrB;AACF"}
|
|
@@ -13,7 +13,7 @@ var logsArgs = {
|
|
|
13
13
|
},
|
|
14
14
|
lines: {
|
|
15
15
|
type: "string",
|
|
16
|
-
description: "how many lines to show (default 50, `all`
|
|
16
|
+
description: "how many lines to show: a count of at least 1 (default 50), or `all`"
|
|
17
17
|
},
|
|
18
18
|
follow: {
|
|
19
19
|
type: "boolean",
|
|
@@ -47,23 +47,19 @@ function isUnreadable(file) {
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* (not 1000), and `--lines 0x10` parsed as 0 — which is the "whole log" sentinel, so a bounded
|
|
56
|
-
* request silently became an unbounded one. Neither is a typo falling back to a default; both are
|
|
57
|
-
* a wrong answer the caller cannot see. The whole trimmed argument has to be a decimal integer.
|
|
50
|
+
* `--lines`: a whole decimal count of at least 1, or `all` — `0` inside means "the whole log", the
|
|
51
|
+
* sentinel `readLog`/`followLog` take. Anything else is refused with the reason, never read as a
|
|
52
|
+
* default: `--lines abc` and `--lines 0x10` silently printed 50 lines, and `--lines 0` (or a negative)
|
|
53
|
+
* printed the whole log, so a typo or a bounded request answered something nobody asked for and the
|
|
54
|
+
* output looked complete.
|
|
58
55
|
*/
|
|
59
56
|
function parseLines(raw) {
|
|
60
|
-
if (raw === void 0) return DEFAULT_LINES;
|
|
57
|
+
if (raw === void 0) return { lines: DEFAULT_LINES };
|
|
61
58
|
const trimmed = raw.trim();
|
|
62
|
-
if (trimmed.toLowerCase() === "all") return 0;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return parsed < 0 ? 0 : parsed;
|
|
59
|
+
if (trimmed.toLowerCase() === "all") return { lines: 0 };
|
|
60
|
+
const parsed = /^\d+$/.test(trimmed) ? Number.parseInt(trimmed, 10) : NaN;
|
|
61
|
+
if (!Number.isSafeInteger(parsed) || parsed < 1) return { error: `--lines takes a whole number of at least 1, or \`all\` — got "${raw}"` };
|
|
62
|
+
return { lines: parsed };
|
|
67
63
|
}
|
|
68
64
|
/**
|
|
69
65
|
* Resolves which log a `logs` call is about: the panel's own console, or one server's.
|
|
@@ -77,7 +73,7 @@ function parseLines(raw) {
|
|
|
77
73
|
* disagree with `start`/`stop` on a host that does not declare a `default` workspace.
|
|
78
74
|
*/
|
|
79
75
|
async function resolveTarget(input) {
|
|
80
|
-
const { daemonLogPath, workspaceLogsDir, workspacesPath } = await import("./paths-
|
|
76
|
+
const { daemonLogPath, workspaceLogsDir, workspacesPath } = await import("./paths-CGlGDrOU.js").then((n) => n.d);
|
|
81
77
|
if (input.id === void 0 || input.id.length === 0) return { file: daemonLogPath };
|
|
82
78
|
const id = input.id.trim();
|
|
83
79
|
if (!(input.workspace !== void 0 && input.workspace.length > 0)) {
|
|
@@ -97,7 +93,7 @@ async function resolveTarget(input) {
|
|
|
97
93
|
}
|
|
98
94
|
/** The workspace this host treats as the default — the panel's own rule, read from the registry. */
|
|
99
95
|
async function defaultWorkspace(registryFile) {
|
|
100
|
-
const { readDefaultWorkspaceId } = await import("./workspaces-
|
|
96
|
+
const { readDefaultWorkspaceId } = await import("./workspaces-DYcfvKV_.js").then((n) => n.i);
|
|
101
97
|
return readDefaultWorkspaceId(registryFile);
|
|
102
98
|
}
|
|
103
99
|
/**
|
|
@@ -124,7 +120,7 @@ async function defaultWorkspace(registryFile) {
|
|
|
124
120
|
async function refuseUnknownServer(target, json) {
|
|
125
121
|
const { serverId, workspaceId } = target;
|
|
126
122
|
if (serverId === void 0 || workspaceId === void 0) return false;
|
|
127
|
-
const { workspaceServersPath, workspacesPath } = await import("./paths-
|
|
123
|
+
const { workspaceServersPath, workspacesPath } = await import("./paths-CGlGDrOU.js").then((n) => n.d);
|
|
128
124
|
const { readDeclaredServerIds } = await import("./server-ids-DRuNLVCV.js");
|
|
129
125
|
const { logExists } = await import("./daemon-log-BVj8cDEo.js").then((n) => n.t);
|
|
130
126
|
const { nearestWord } = await import("./nearest-6KgQEDUe.js").then((n) => n.n);
|
|
@@ -136,7 +132,7 @@ async function refuseUnknownServer(target, json) {
|
|
|
136
132
|
* same id. A log on disk still wins, for the same reason it does for a removed server.
|
|
137
133
|
*/
|
|
138
134
|
if (!logExists(target.file)) {
|
|
139
|
-
const { readWorkspaceIds } = await import("./workspaces-
|
|
135
|
+
const { readWorkspaceIds } = await import("./workspaces-DYcfvKV_.js").then((n) => n.i);
|
|
140
136
|
const known = readWorkspaceIds(workspacesPath);
|
|
141
137
|
if (known !== null && !known.includes(workspaceId)) {
|
|
142
138
|
const suggestion = nearestWord(workspaceId, known);
|
|
@@ -159,7 +155,13 @@ async function refuseUnknownServer(target, json) {
|
|
|
159
155
|
}
|
|
160
156
|
async function runLogs(input) {
|
|
161
157
|
const { readLog } = await import("./daemon-log-BVj8cDEo.js").then((n) => n.t);
|
|
162
|
-
const
|
|
158
|
+
const count = parseLines(input.lines);
|
|
159
|
+
if ("error" in count) {
|
|
160
|
+
refusal(count.error);
|
|
161
|
+
process.exitCode = 1;
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const lines = count.lines;
|
|
163
165
|
const target = await resolveTarget({
|
|
164
166
|
id: input.id,
|
|
165
167
|
workspace: input.workspace
|
|
@@ -262,4 +264,4 @@ var logsCommand = defineCommand({
|
|
|
262
264
|
//#endregion
|
|
263
265
|
export { logsCommand };
|
|
264
266
|
|
|
265
|
-
//# sourceMappingURL=logs
|
|
267
|
+
//# sourceMappingURL=logs---TI_bxM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logs---TI_bxM.js","names":[],"sources":["../../src/cli/logs.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { defineCommand } from 'citty'\nimport { bold, dim, fail, refusal } from '#src/cli/io'\nimport { errorMessage } from '#src/shared/error-message'\n\n/** `logs` answers \"what has the panel been saying\" — the file `up` redirects it into. */\n\nexport const logsArgs = {\n id: { type: 'positional', required: false, description: 'show one server\\'s own log instead of the panel console' },\n lines: { type: 'string', description: 'how many lines to show: a count of at least 1 (default 50), or `all`' },\n follow: { type: 'boolean', description: 'keep printing as the panel writes (like tail -f)' },\n json: { type: 'boolean', description: 'print machine-readable JSON' },\n workspace: { type: 'string', alias: 'w', description: 'the workspace the server is in (default: the panel\\'s default workspace)' },\n} as const\n\nconst DEFAULT_LINES = 50\n\n/**\n * Whether a path exists but cannot be read — the case `readLog` cannot distinguish from absence,\n * because it folds every failure into \"nothing there\".\n *\n * A *missing* log is normal (a panel that has not started), so only a real permission or IO\n * refusal is reported. `R_OK` is the question being asked; existence alone would call an\n * unreadable file readable.\n */\nfunction isUnreadable(file: string): boolean {\n try {\n fs.accessSync(file, fs.constants.R_OK)\n return false\n }\n catch (error) {\n // Missing is not unreadable: that is the ordinary empty case.\n return (error as NodeJS.ErrnoException).code !== 'ENOENT'\n }\n}\n\n/**\n * `--lines`: a whole decimal count of at least 1, or `all` — `0` inside means \"the whole log\", the\n * sentinel `readLog`/`followLog` take. Anything else is refused with the reason, never read as a\n * default: `--lines abc` and `--lines 0x10` silently printed 50 lines, and `--lines 0` (or a negative)\n * printed the whole log, so a typo or a bounded request answered something nobody asked for and the\n * output looked complete.\n */\nexport function parseLines(raw: string | undefined): { lines: number } | { error: string } {\n if (raw === undefined)\n return { lines: DEFAULT_LINES }\n const trimmed = raw.trim()\n if (trimmed.toLowerCase() === 'all')\n return { lines: 0 }\n const parsed = /^\\d+$/.test(trimmed) ? Number.parseInt(trimmed, 10) : Number.NaN\n if (!Number.isSafeInteger(parsed) || parsed < 1)\n return { error: `--lines takes a whole number of at least 1, or \\`all\\` — got \"${raw}\"` }\n return { lines: parsed }\n}\n\nexport interface LogTarget {\n /** The file the lines come from, for the header and for `--json`'s `path`. */\n file: string\n /** The workspace the file is in, when the target is one server's log. */\n workspaceId?: string\n /** The id asked for, when the target is one server's log. */\n serverId?: string\n}\n\n/**\n * Resolves which log a `logs` call is about: the panel's own console, or one server's.\n *\n * A server's log is JSONL on disk (`<id>.log`, plus `.log.N` rotations) and is readable with no\n * session, no token and no answering panel — the same property that makes `panel.console` a\n * first-class diagnostic. The workspace is explicit because a server id is only unique inside one.\n *\n * An omitted `--workspace` resolves through `defaultWorkspaceId` — the same rule the panel uses for\n * an omitted `?workspace` — because reading `DEFAULT_WORKSPACE_ID` literally here made `logs`\n * disagree with `start`/`stop` on a host that does not declare a `default` workspace.\n */\nasync function resolveTarget(input: { id?: string, workspace?: string }): Promise<LogTarget> {\n const { daemonLogPath, workspaceLogsDir, workspacesPath } = await import('#src/helpers/paths')\n if (input.id === undefined || input.id.length === 0)\n return { file: daemonLogPath }\n\n const id = input.id.trim()\n const explicit = input.workspace !== undefined && input.workspace.length > 0\n // `readDefaultWorkspaceId`, not `DEFAULT_WORKSPACE_ID`: \"which one is the default\" is the panel's\n // own rule (`default` if declared, else the first listed), and reading the literal id here made\n // `logs` name a workspace that `start`/`stop` would not act in. Read only when it is needed.\n if (!explicit) {\n const workspaceId = await defaultWorkspace(workspacesPath)\n return { file: path.join(workspaceLogsDir(workspaceId), `${id}.log`), workspaceId, serverId: id }\n }\n // Refused rather than guessed: an id is only unique inside a workspace, and reading the default\n // one for a server that lives elsewhere would print another server's output under this name.\n const workspaceId = input.workspace!.trim()\n return { file: path.join(workspaceLogsDir(workspaceId), `${id}.log`), workspaceId, serverId: id }\n}\n\n/** The workspace this host treats as the default — the panel's own rule, read from the registry. */\nasync function defaultWorkspace(registryFile: string): Promise<string> {\n const { readDefaultWorkspaceId } = await import('#src/config/workspaces')\n return readDefaultWorkspaceId(registryFile)\n}\n\n/**\n * Refuses an id this workspace's `servers.config.json` does not declare, **unless a log for it is\n * on disk** — returns whether it refused, so the caller stops before printing an answer.\n *\n * `logs webx` printed `no output yet — …/webx.log` and exited 0, so a diagnostic session's first\n * command agreed with a typo, and `logs webx | grep -q error` was a silently empty pipeline that\n * reads as \"no errors\". `start webx`/`stop webx` refuse the same id over the same config, so the\n * two commands now agree.\n *\n * The log's own existence is the exception, on purpose: a file outlives the entry that wrote it,\n * so refusing on the config alone would make the log of a **removed** server unreadable — the one\n * log a person is most likely to want. It is read as before, and a note says the entry is gone.\n *\n * \"I cannot tell\" (no config, an unparseable one) is not \"there is no such entry\", so it answers as\n * it did before. So does the panel console, which is not a server at all.\n *\n * `refusal()` plus an exit code rather than `fail()`, the same shape as the unreadable-file branch\n * in `runLogs`: `fail()` ends the process, and a command module that can be called in-process\n * should leave that decision where the answer is decided. One refusal is still one message on one\n * stream.\n */\nasync function refuseUnknownServer(target: LogTarget, json: boolean): Promise<boolean> {\n const { serverId, workspaceId } = target\n if (serverId === undefined || workspaceId === undefined)\n return false\n\n const { workspaceServersPath, workspacesPath } = await import('#src/helpers/paths')\n const { readDeclaredServerIds } = await import('#src/config/server-ids')\n const { logExists } = await import('#src/helpers/daemon-log')\n const { nearestWord } = await import('#src/cli/nearest')\n\n /**\n * The workspace itself first: an id that names no workspace makes every answer below meaningless,\n * and the old code joined it into a path and read a file that could not exist. `logs web -w typo`\n * printed `no output yet — …/.hh/typo/.logs/web.log` and exited 0, so `logs web -w typo | grep -q\n * error` was an empty pipeline that reads as \"no errors\" — while `start web -w typo` refused the\n * same id. A log on disk still wins, for the same reason it does for a removed server.\n */\n if (!logExists(target.file)) {\n const { readWorkspaceIds } = await import('#src/config/workspaces')\n const known = readWorkspaceIds(workspacesPath)\n if (known !== null && !known.includes(workspaceId)) {\n const suggestion = nearestWord(workspaceId, known)\n refusal(`unknown workspace \"${workspaceId}\"${suggestion === null ? '' : ` — did you mean \\`${suggestion}\\`?`} (${workspacesPath})`)\n process.exitCode = 1\n return true\n }\n }\n\n const declared = readDeclaredServerIds(workspaceServersPath(workspaceId))\n if (declared === null || declared.includes(serverId))\n return false\n\n // The log is the reason this command exists, so a file on disk is always read. Saying the entry\n // is gone is the part that stops \"this server has written nothing\" from being the conclusion.\n if (logExists(target.file)) {\n if (!json)\n process.stderr.write(`${dim(`${workspaceId}/${serverId} is not in servers.config.json any more — reading the log it left behind`)}\\n`)\n return false\n }\n\n const suggestion = nearestWord(serverId, declared)\n // The hint names the config file, not `usage`: that command needs an answering panel, and the\n // person reading this is most often holding a panel that is why they are here. The file is\n // readable either way, and it is the same source this refusal just read.\n const hint = suggestion === null\n ? `it is not in ${workspaceServersPath(workspaceId)}`\n : `did you mean \\`${suggestion}\\`? (${workspaceServersPath(workspaceId)})`\n // One refusal, one message, one stream: stdout carries only an answer, and there is none to give.\n // The `--json` form answers nothing either, because `{ lines: [] }` is the empty success this\n // refusal exists to stop.\n refusal(`unknown server \"${serverId}\" in workspace \"${workspaceId}\" — ${hint}`)\n process.exitCode = 1\n return true\n}\n\nexport async function runLogs(input: { id?: string, lines?: string, follow?: boolean, json?: boolean, workspace?: string }): Promise<void> {\n const { readLog } = await import('#src/helpers/daemon-log')\n const count = parseLines(input.lines)\n if ('error' in count) {\n refusal(count.error)\n process.exitCode = 1\n return\n }\n const lines = count.lines\n const target = await resolveTarget({ id: input.id, workspace: input.workspace })\n const logPath = target.file\n // A server's log is JSONL, the panel console is text. `--json` must still hand back the **stored**\n // record, so only the human form is rendered.\n const isServerLog = target.serverId !== undefined\n\n // A typo agrees with an empty log unless the entry's own config is consulted — see\n // `refuseUnknownServer` for why this is a refusal and not a silence.\n if (await refuseUnknownServer(target, input.json === true))\n return\n\n if (input.follow === true) {\n const { followLog } = await import('#src/helpers/daemon-log')\n // `lines` goes through unchanged: `readLog` already reads `0` as \"the whole log\", which is what\n // `--lines all` parsed to. This used to rewrite 0 to\n // `DEFAULT_LINES`, so `logs --lines all --follow` printed 50 lines of a 200-line log while the\n // help and synopsis advertise `[--lines <n>] [--follow]` as composable — the worst failure\n // for a diagnostic command, since the answer looked complete. Same class as `--follow --json`\n // ignoring `--json`, which the branch below already fixed.\n if (input.json !== true) {\n // A server's log is JSONL, so the human form renders each line; a chunk can end mid-line, so\n // only complete lines are rendered and the tail is carried to the next chunk.\n if (!isServerLog) {\n await followLog(logPath, lines, chunk => process.stdout.write(chunk))\n return\n }\n let partial = ''\n const emitLine = (raw: string): void => {\n process.stdout.write(`${renderLine(raw, true)}\\n`)\n }\n await followLog(logPath, lines, (chunk) => {\n partial += chunk\n const parts = partial.split('\\n')\n partial = parts.pop() ?? ''\n for (const part of parts) {\n if (part.length > 0)\n emitLine(part)\n }\n })\n if (partial.length > 0)\n emitLine(partial)\n return\n }\n // `--follow --json` used to ignore `--json` and print raw text, which the synopsis\n // (`logs [--lines <n>] [--follow] [--json]`) advertised as composable. A stream has no\n // single document, so the machine-readable form of it is one JSON object per line — each\n // carrying the same `path` the one-shot form reports, so a consumer needs no out-of-band\n // knowledge of which file it is reading.\n const emit = (line: string): void => {\n process.stdout.write(`${JSON.stringify({ path: logPath, line })}\\n`)\n }\n // A chunk can end mid-line, so lines are only emitted once their newline has arrived.\n let pending = ''\n await followLog(logPath, lines, (chunk) => {\n pending += chunk\n const parts = pending.split('\\n')\n pending = parts.pop() ?? ''\n for (const part of parts) emit(part)\n })\n if (pending.length > 0)\n emit(pending)\n return\n }\n\n const output = readLog(logPath, lines)\n\n // Checked once, before either output form. `readLog` treats every read failure as \"not there\",\n // so an unreadable log and a missing one look identical to it — and both surfaces would then\n // claim the panel has written nothing when it may have written plenty. A panel run as another\n // user (systemd, root) is the realistic case. Doing this above the `--json` branch is what keeps\n // the two forms from disagreeing: `--json` used to answer `{ lines: [] }` while the text form\n // reported the permission problem, because the check sat below it.\n if (output.length === 0 && isUnreadable(logPath)) {\n if (input.json === true) {\n process.stdout.write(`${JSON.stringify({ path: logPath, error: 'unreadable' }, null, 2)}\\n`)\n }\n else {\n // The refusal goes to **stderr**: stdout is the answer, and a script reading a diagnostic\n // command's output must not have to tell a permission problem from a line of the log. The\n // `--json` branch above keeps its document on stdout because that *is* the answer — `error`\n // is the key a JSON consumer reads there.\n refusal(`cannot read ${logPath} — check its permissions`)\n }\n process.exitCode = 1\n return\n }\n\n if (input.json === true) {\n process.stdout.write(`${JSON.stringify({ path: logPath, lines: output }, null, 2)}\\n`)\n return\n }\n\n if (output.length === 0) {\n // Not an error: a panel that has just started, or never started, has nothing to say.\n process.stdout.write(`${dim(`no output yet — ${logPath}`)}\\n`)\n return\n }\n\n process.stdout.write(`${bold(logPath)}\\n`)\n for (const line of output)\n process.stdout.write(`${renderLine(line, isServerLog)}\\n`)\n}\n\n/**\n * One stored server line as text.\n *\n * A server's log is JSONL (`{ ts, stream, text }`), so the raw bytes would show a person a JSON\n * object per line where the panel shows them a log. A line that does not parse is not dropped: a\n * truncated write still says something, and hiding it is worse than showing it raw.\n */\nfunction renderLine(raw: string, server: boolean): string {\n if (!server)\n return raw\n try {\n const parsed: unknown = JSON.parse(raw)\n if (typeof parsed === 'object' && parsed !== null && typeof (parsed as { text?: unknown }).text === 'string')\n return (parsed as { text: string }).text\n }\n catch {\n // Fall through: an unparseable line is shown as it was written.\n }\n return raw\n}\n\nexport const logsCommand = defineCommand({\n // No `description`: the one copy is `SUMMARIES` in `cli.ts`. See `server.ts` for why a module copy\n // here is unreachable.\n meta: { name: 'logs' },\n args: logsArgs,\n async run({ args }) {\n try {\n await runLogs({ id: args.id, lines: args.lines, follow: args.follow, json: args.json, workspace: args.workspace })\n }\n catch (error) {\n fail(errorMessage(error))\n }\n },\n})\n"],"mappings":";;;;;;;AASA,IAAa,WAAW;CACtB,IAAI;EAAE,MAAM;EAAc,UAAU;EAAO,aAAa;CAA0D;CAClH,OAAO;EAAE,MAAM;EAAU,aAAa;CAAuE;CAC7G,QAAQ;EAAE,MAAM;EAAW,aAAa;CAAmD;CAC3F,MAAM;EA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,OAAQ,OAA8B,SAAS,UAClG,OAAQ,OAA4B;CACxC,QACM,CAEN;CACA,OAAO;AACT;AAEA,IAAa,cAAc,cAAc;CAGvC,MAAM,EAAE,MAAM,OAAO;CACrB,MAAM;CACN,MAAM,IAAI,EAAE,QAAQ;EAClB,IAAI;GACF,MAAM,QAAQ;IAAE,IAAI,KAAK;IAAI,OAAO,KAAK;IAAO,QAAQ,KAAK;IAAQ,MAAM,KAAK;IAAM,WAAW,KAAK;GAAU,CAAC;EACnH,SACO,OAAO;GACZ,KAAK,aAAa,KAAK,CAAC;EAC1B;CACF;AACF,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { C as errorMessage, _ as prompt, d as dim, f as fail, m as green, t as appVersion } from "../cli.js";
|
|
2
|
-
import {
|
|
2
|
+
import { A as workspaceServersPath, j as workspaceSettingsPath, o as globalSettingsPath } from "./paths-CGlGDrOU.js";
|
|
3
|
+
import { t as writeFileAtomic } from "./atomic-C1PfJpE7.js";
|
|
3
4
|
import { n as readStateFile } from "./config-text-DifCHhnz.js";
|
|
4
5
|
import { t as isRecord } from "./shape-DnTKzjQ2.js";
|
|
5
|
-
import { c as planConfigMigrations, i as parseWorkspaceSettings, n as parseServersFile, o as stampConfig, s as applyConfigMigrations, t as parseGlobalSettings } from "./parse-
|
|
6
|
-
import {
|
|
7
|
-
import { n as WorkspaceRegistry } from "./workspaces-CAln2sQ7.js";
|
|
6
|
+
import { c as planConfigMigrations, i as parseWorkspaceSettings, n as parseServersFile, o as stampConfig, s as applyConfigMigrations, t as parseGlobalSettings } from "./parse-DhmG26fI.js";
|
|
7
|
+
import { n as WorkspaceRegistry } from "./workspaces-DYcfvKV_.js";
|
|
8
8
|
import process from "node:process";
|
|
9
9
|
import { defineCommand } from "citty";
|
|
10
10
|
import path from "node:path";
|
|
@@ -152,4 +152,4 @@ var migrateCommand = defineCommand({
|
|
|
152
152
|
//#endregion
|
|
153
153
|
export { migrateCommand };
|
|
154
154
|
|
|
155
|
-
//# sourceMappingURL=migrate-
|
|
155
|
+
//# sourceMappingURL=migrate-Cfoq-Vgh.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrate-BTlsibvF.js","names":[],"sources":["../../src/cli/migrate.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { defineCommand } from 'citty'\nimport { dim, fail, green, prompt } from '#src/cli/io'\nimport { applyConfigMigrations, planConfigMigrations, UNSTAMPED_SCHEMA } from '#src/config/migrations'\nimport { parseGlobalSettings, parseServersFile, parseWorkspaceSettings, stampConfig } from '#src/config/parse'\nimport { WorkspaceRegistry } from '#src/config/workspaces'\nimport { writeFileAtomic } from '#src/helpers/atomic'\nimport { readStateFile } from '#src/helpers/config-text'\nimport { globalSettingsPath, workspaceServersPath, workspaceSettingsPath } from '#src/helpers/paths'\nimport { appVersion } from '#src/helpers/version'\nimport { errorMessage } from '#src/shared/error-message'\nimport { isRecord } from '#src/shared/shape'\n\n/**\n * `migrate` lifts a state directory to the config schema this release understands:\n * it stamps the global settings, each workspace's settings and each workspace's\n * servers config, and applies any pending schema migration to them.\n *\n * Deliberately loud: it prints every step first, backs a file up before writing\n * it, refuses to write one it cannot read, and never runs on its own — a detached\n * daemon cannot prompt, so consent comes from `--yes`, from\n * `HHOSTED_MIGRATE=allow`, or from a person at a terminal.\n */\n\nexport const migrateArgs = {\n dryRun: { type: 'boolean', description: 'print what would change, write nothing' },\n yes: { type: 'boolean', alias: 'y', description: 'apply without asking (or set HHOSTED_MIGRATE=allow)' },\n} as const\n\ninterface Target {\n file: string\n label: string\n validate: (raw: unknown) => string | null\n}\n\n/** Every file a migration may have to stamp, and how this release reads it. */\nfunction targets(): Target[] {\n const list: Target[] = [\n {\n file: globalSettingsPath,\n label: 'global settings',\n validate: raw => parseGlobalSettings(raw).errors[0] ?? null,\n },\n ]\n\n const registry = new WorkspaceRegistry()\n registry.load()\n if (registry.configError !== null)\n fail(`cannot read ${registry.path}: ${registry.configError}`)\n\n for (const workspace of registry.all()) {\n list.push({\n file: workspaceSettingsPath(workspace.id),\n label: `workspace ${workspace.id} settings`,\n validate: raw => parseWorkspaceSettings(raw).errors[0] ?? null,\n })\n list.push({\n file: workspaceServersPath(workspace.id),\n label: `workspace ${workspace.id} servers`,\n validate: (raw) => {\n // The defaults live in the workspace settings; an absent one reads as schema defaults.\n // Read through the *parser* only when that file is already this release's schema; a\n // pending migration means the reader would refuse it, and the defaults would be lost.\n let defaults: Record<string, unknown> = {}\n try {\n const settingsRaw = JSON.parse(readStateFile(workspaceSettingsPath(workspace.id))) as Record<string, unknown>\n const meta = typeof settingsRaw.meta === 'object' && settingsRaw.meta !== null ? settingsRaw.meta as { schema?: number } : {}\n const from = typeof meta.schema === 'number' ? meta.schema : UNSTAMPED_SCHEMA\n const lifted = planConfigMigrations(from).steps.length > 0 ? applyConfigMigrations(settingsRaw, from).config : settingsRaw\n defaults = (lifted?.defaults ?? {}) as Record<string, unknown>\n }\n catch {\n // No settings file yet: the servers still have to be readable.\n }\n return parseServersFile(raw, defaults).errors[0] ?? null\n },\n })\n }\n return list\n}\n\nexport async function runMigrate(dryRun: boolean, yes: boolean): Promise<void> {\n const files = targets()\n const existing = files.filter(target => fs.existsSync(target.file))\n if (existing.length === 0)\n fail(`no home-hosted state to migrate — nothing at ${globalSettingsPath} or any workspace`)\n\n const consented = yes || (process.env.HHOSTED_MIGRATE ?? '').toLowerCase() === 'allow'\n let stampOnly = 0\n let lifted = 0\n /** Files whose schema has steps, counted for `--dry-run` — which writes none of them. */\n let needsLift = 0\n\n for (const target of existing) {\n let raw: Record<string, unknown>\n try {\n raw = JSON.parse(readStateFile(target.file)) as Record<string, unknown>\n }\n catch (error) {\n fail(`cannot read ${target.file}: ${errorMessage(error)}`)\n }\n\n const meta = typeof raw.meta === 'object' && raw.meta !== null ? raw.meta as { schema?: number, writtenBy?: string } : {}\n const from = typeof meta.schema === 'number' ? meta.schema : UNSTAMPED_SCHEMA\n const plan = planConfigMigrations(from)\n\n if (plan.tooNew) {\n fail(`${target.file} was written by home-hosted ${meta.writtenBy ?? 'a newer release'} (config schema ${from});\\n this release understands schema ${plan.to}. Install that version, or edit the file yourself.`)\n }\n\n /**\n * Validate what this release will actually read: the file as-is when it needs no migration,\n * otherwise the result the steps produce.\n *\n * The parsed check cannot be run on the raw file when a migration is pending — the reader\n * refuses an older schema by design (`readStamp`), which would make `migrate` refuse every\n * config it exists to lift. `checkShape` below catches a file that is not even JSON-shaped\n * before the steps touch it.\n */\n const migrated = plan.steps.length === 0 ? raw : applyConfigMigrations(raw, from).config\n if (plan.steps.length > 0 && (!isRecord(migrated))) {\n fail(`${target.file} did not produce an object when migrated — refusing to write it`)\n }\n const problem = target.validate(migrated)\n if (problem !== null)\n fail(`${target.file} is not a config this release can read: ${problem}`)\n\n // A chain with a gap would lift the file part-way and then stamp it as the current schema, so the\n // file would claim a shape it does not have. Refused rather than written.\n if (plan.reached !== plan.to) {\n fail(`${target.file} is schema ${from} and this release can only lift it to schema ${plan.reached} — the migration chain in configMigrations has a gap to schema ${plan.to}.\n That is a bug in this release: report it rather than editing the file.`)\n }\n\n if (plan.steps.length === 0) {\n const stamped = stampConfig(raw)\n const changes = JSON.stringify(stamped) !== JSON.stringify(raw)\n if (changes)\n stampOnly += 1\n // A dry run has to *say* what it would stamp. It used to stay silent and then close with\n // \"nothing was written (--dry-run)\", so an upgrader rehearsing the one command they were told\n // to rehearse saw an empty report while the real run rewrote three files and printed\n // \"3 file(s) stamped\" — the plan a person reads to decide did not describe the run it plans.\n if (changes && dryRun)\n process.stdout.write(`stamping ${target.label}: meta.writtenBy → home-hosted ${appVersion()} (schema ${plan.to}, no steps)\\n`)\n // `docs/` and `README.md` promise a `.bak` beside **each** file this command rewrites, and this\n // branch rewrites one too — it only restamps it. Keeping no backup here made the promise\n // conditional on which path the file took, and a hand-formatted `servers.config.json` came back\n // reindented with no copy of what the person wrote. No consent is asked for a restamp: it\n // changes `meta.writtenBy` and nothing else, so there is no decision to make — unlike a schema\n // step, which is why the two branches differ on that and not on the backup.\n if (changes && !dryRun) {\n fs.copyFileSync(target.file, `${target.file}.bak`)\n writeFileAtomic(target.file, `${JSON.stringify(stamped, null, 2)}\\n`)\n }\n continue\n }\n\n needsLift += 1\n\n process.stdout.write(`migrating ${target.label}: config schema ${from} → ${plan.to}\\n`)\n for (const [index, step] of plan.steps.entries())\n process.stdout.write(` ${index + 1}. ${step.describe}\\n`)\n\n if (dryRun)\n continue\n\n if (!consented) {\n if (process.stdin.isTTY !== true) {\n fail(`${target.file} needs ${plan.steps.length} migration(s) and this session cannot ask.\\n re-run with --yes, or set HHOSTED_MIGRATE=allow for unattended runs`)\n }\n const answer = await prompt(`Apply ${plan.steps.length} migration(s) to ${path.basename(target.file)}? [y/N] `)\n if (!/^yes$|^y$/i.test(answer.trim())) {\n process.stdout.write('cancelled — nothing was written\\n')\n return\n }\n }\n\n const migratedProblem = target.validate(migrated)\n if (migratedProblem !== null)\n fail(`the migration produced a config this release cannot read:\\n ${migratedProblem}`)\n\n fs.copyFileSync(target.file, `${target.file}.bak`)\n writeFileAtomic(target.file, `${JSON.stringify(stampConfig(migrated), null, 2)}\\n`)\n lifted += 1\n process.stdout.write(`${green(`migrated ${target.label} to schema ${plan.to}`)} in ${target.file}\\n`)\n process.stdout.write(` ${dim(`previous file kept at ${target.file}.bak`)}\\n`)\n }\n\n // \"nothing to migrate\" has to mean nothing happened: a run that lifted three files printed it\n // anyway, because only the stamp-only path counted. The line a person reads to decide whether to\n // re-run has to agree with the lines above it.\n //\n // A dry run answers the same question in the same words, in the tense of a plan: it is the run a\n // person rehearses *before* letting a migration touch state they cannot easily restore, so its\n // closing line may not contradict the work it just described.\n const done: string[] = []\n if (dryRun) {\n if (needsLift > 0)\n done.push(green(`${needsLift} file(s) would be migrated`))\n if (stampOnly > 0)\n done.push(green(`${stampOnly} file(s) would be stamped`))\n process.stdout.write(\n done.length === 0\n ? `every file is already what home-hosted ${appVersion()} understands — nothing to migrate\\n`\n : `${done.join(', ')} to what home-hosted ${appVersion()} understands\\n`,\n )\n process.stdout.write(`${dim('nothing was written (--dry-run)')}\\n`)\n return\n }\n\n if (lifted > 0)\n done.push(green(`${lifted} file(s) migrated`))\n if (stampOnly > 0)\n done.push(green(`${stampOnly} file(s) stamped`))\n if (done.length === 0)\n process.stdout.write(`every file is already what home-hosted ${appVersion()} understands — nothing to migrate\\n`)\n else\n process.stdout.write(`${done.join(', ')} to what home-hosted ${appVersion()} understands\\n`)\n}\n\nexport const migrateCommand = defineCommand({\n meta: { name: 'migrate' },\n args: migrateArgs,\n run: async ({ args }) => {\n await runMigrate(args.dryRun === true, args.yes === true)\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA0BA,IAAa,cAAc;CACzB,QAAQ;EAAE,MAAM;EAAW,aAAa;CAAyC;CACjF,KAAK;EAAE,MAAM;EAAW,OAAO;EAAK,aAAa;CAAsD;AACzG;;AASA,SAAS,UAAoB;CAC3B,MAAM,OAAiB,CACrB;EACE,MAAM;EACN,OAAO;EACP,WAAU,QAAO,oBAAoB,GAAG,CAAC,CAAC,OAAO,MAAM;CACzD,CACF;CAEA,MAAM,WAAW,IAAI,kBAAkB;CACvC,SAAS,KAAK;CACd,IAAI,SAAS,gBAAgB,MAC3B,KAAK,eAAe,SAAS,KAAK,IAAI,SAAS,aAAa;CAE9D,KAAK,MAAM,aAAa,SAAS,IAAI,GAAG;EACtC,KAAK,KAAK;GACR,MAAM,sBAAsB,UAAU,EAAE;GACxC,OAAO,aAAa,UAAU,GAAG;GACjC,WAAU,QAAO,uBAAuB,GAAG,CAAC,CAAC,OAAO,MAAM;EAC5D,CAAC;EACD,KAAK,KAAK;GACR,MAAM,qBAAqB,UAAU,EAAE;GACvC,OAAO,aAAa,UAAU,GAAG;GACjC,WAAW,QAAQ;IAIjB,IAAI,WAAoC,CAAC;IACzC,IAAI;KACF,MAAM,cAAc,KAAK,MAAM,cAAc,sBAAsB,UAAU,EAAE,C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AM,EAAE,MAAM,UAAU;CACxB,MAAM;CACN,KAAK,OAAO,EAAE,WAAW;EACvB,MAAM,WAAW,KAAK,WAAW,MAAM,KAAK,QAAQ,IAAI;CAC1D;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"migrate-Cfoq-Vgh.js","names":[],"sources":["../../src/cli/migrate.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\nimport process from 'node:process'\nimport { defineCommand } from 'citty'\nimport { dim, fail, green, prompt } from '#src/cli/io'\nimport { applyConfigMigrations, planConfigMigrations, UNSTAMPED_SCHEMA } from '#src/config/migrations'\nimport { parseGlobalSettings, parseServersFile, parseWorkspaceSettings, stampConfig } from '#src/config/parse'\nimport { WorkspaceRegistry } from '#src/config/workspaces'\nimport { writeFileAtomic } from '#src/helpers/atomic'\nimport { readStateFile } from '#src/helpers/config-text'\nimport { globalSettingsPath, workspaceServersPath, workspaceSettingsPath } from '#src/helpers/paths'\nimport { appVersion } from '#src/helpers/version'\nimport { errorMessage } from '#src/shared/error-message'\nimport { isRecord } from '#src/shared/shape'\n\n/**\n * `migrate` lifts a state directory to the config schema this release understands:\n * it stamps the global settings, each workspace's settings and each workspace's\n * servers config, and applies any pending schema migration to them.\n *\n * Deliberately loud: it prints every step first, backs a file up before writing\n * it, refuses to write one it cannot read, and never runs on its own — a detached\n * daemon cannot prompt, so consent comes from `--yes`, from\n * `HHOSTED_MIGRATE=allow`, or from a person at a terminal.\n */\n\nexport const migrateArgs = {\n dryRun: { type: 'boolean', description: 'print what would change, write nothing' },\n yes: { type: 'boolean', alias: 'y', description: 'apply without asking (or set HHOSTED_MIGRATE=allow)' },\n} as const\n\ninterface Target {\n file: string\n label: string\n validate: (raw: unknown) => string | null\n}\n\n/** Every file a migration may have to stamp, and how this release reads it. */\nfunction targets(): Target[] {\n const list: Target[] = [\n {\n file: globalSettingsPath,\n label: 'global settings',\n validate: raw => parseGlobalSettings(raw).errors[0] ?? null,\n },\n ]\n\n const registry = new WorkspaceRegistry()\n registry.load()\n if (registry.configError !== null)\n fail(`cannot read ${registry.path}: ${registry.configError}`)\n\n for (const workspace of registry.all()) {\n list.push({\n file: workspaceSettingsPath(workspace.id),\n label: `workspace ${workspace.id} settings`,\n validate: raw => parseWorkspaceSettings(raw).errors[0] ?? null,\n })\n list.push({\n file: workspaceServersPath(workspace.id),\n label: `workspace ${workspace.id} servers`,\n validate: (raw) => {\n // The defaults live in the workspace settings; an absent one reads as schema defaults.\n // Read through the *parser* only when that file is already this release's schema; a\n // pending migration means the reader would refuse it, and the defaults would be lost.\n let defaults: Record<string, unknown> = {}\n try {\n const settingsRaw = JSON.parse(readStateFile(workspaceSettingsPath(workspace.id))) as Record<string, unknown>\n const meta = typeof settingsRaw.meta === 'object' && settingsRaw.meta !== null ? settingsRaw.meta as { schema?: number } : {}\n const from = typeof meta.schema === 'number' ? meta.schema : UNSTAMPED_SCHEMA\n const lifted = planConfigMigrations(from).steps.length > 0 ? applyConfigMigrations(settingsRaw, from).config : settingsRaw\n defaults = (lifted?.defaults ?? {}) as Record<string, unknown>\n }\n catch {\n // No settings file yet: the servers still have to be readable.\n }\n return parseServersFile(raw, defaults).errors[0] ?? null\n },\n })\n }\n return list\n}\n\nexport async function runMigrate(dryRun: boolean, yes: boolean): Promise<void> {\n const files = targets()\n const existing = files.filter(target => fs.existsSync(target.file))\n if (existing.length === 0)\n fail(`no home-hosted state to migrate — nothing at ${globalSettingsPath} or any workspace`)\n\n const consented = yes || (process.env.HHOSTED_MIGRATE ?? '').toLowerCase() === 'allow'\n let stampOnly = 0\n let lifted = 0\n /** Files whose schema has steps, counted for `--dry-run` — which writes none of them. */\n let needsLift = 0\n\n for (const target of existing) {\n let raw: Record<string, unknown>\n try {\n raw = JSON.parse(readStateFile(target.file)) as Record<string, unknown>\n }\n catch (error) {\n fail(`cannot read ${target.file}: ${errorMessage(error)}`)\n }\n\n const meta = typeof raw.meta === 'object' && raw.meta !== null ? raw.meta as { schema?: number, writtenBy?: string } : {}\n const from = typeof meta.schema === 'number' ? meta.schema : UNSTAMPED_SCHEMA\n const plan = planConfigMigrations(from)\n\n if (plan.tooNew) {\n fail(`${target.file} was written by home-hosted ${meta.writtenBy ?? 'a newer release'} (config schema ${from});\\n this release understands schema ${plan.to}. Install that version, or edit the file yourself.`)\n }\n\n /**\n * Validate what this release will actually read: the file as-is when it needs no migration,\n * otherwise the result the steps produce.\n *\n * The parsed check cannot be run on the raw file when a migration is pending — the reader\n * refuses an older schema by design (`readStamp`), which would make `migrate` refuse every\n * config it exists to lift. `checkShape` below catches a file that is not even JSON-shaped\n * before the steps touch it.\n */\n const migrated = plan.steps.length === 0 ? raw : applyConfigMigrations(raw, from).config\n if (plan.steps.length > 0 && (!isRecord(migrated))) {\n fail(`${target.file} did not produce an object when migrated — refusing to write it`)\n }\n const problem = target.validate(migrated)\n if (problem !== null)\n fail(`${target.file} is not a config this release can read: ${problem}`)\n\n // A chain with a gap would lift the file part-way and then stamp it as the current schema, so the\n // file would claim a shape it does not have. Refused rather than written.\n if (plan.reached !== plan.to) {\n fail(`${target.file} is schema ${from} and this release can only lift it to schema ${plan.reached} — the migration chain in configMigrations has a gap to schema ${plan.to}.\n That is a bug in this release: report it rather than editing the file.`)\n }\n\n if (plan.steps.length === 0) {\n const stamped = stampConfig(raw)\n const changes = JSON.stringify(stamped) !== JSON.stringify(raw)\n if (changes)\n stampOnly += 1\n // A dry run has to *say* what it would stamp. It used to stay silent and then close with\n // \"nothing was written (--dry-run)\", so an upgrader rehearsing the one command they were told\n // to rehearse saw an empty report while the real run rewrote three files and printed\n // \"3 file(s) stamped\" — the plan a person reads to decide did not describe the run it plans.\n if (changes && dryRun)\n process.stdout.write(`stamping ${target.label}: meta.writtenBy → home-hosted ${appVersion()} (schema ${plan.to}, no steps)\\n`)\n // `docs/` and `README.md` promise a `.bak` beside **each** file this command rewrites, and this\n // branch rewrites one too — it only restamps it. Keeping no backup here made the promise\n // conditional on which path the file took, and a hand-formatted `servers.config.json` came back\n // reindented with no copy of what the person wrote. No consent is asked for a restamp: it\n // changes `meta.writtenBy` and nothing else, so there is no decision to make — unlike a schema\n // step, which is why the two branches differ on that and not on the backup.\n if (changes && !dryRun) {\n fs.copyFileSync(target.file, `${target.file}.bak`)\n writeFileAtomic(target.file, `${JSON.stringify(stamped, null, 2)}\\n`)\n }\n continue\n }\n\n needsLift += 1\n\n process.stdout.write(`migrating ${target.label}: config schema ${from} → ${plan.to}\\n`)\n for (const [index, step] of plan.steps.entries())\n process.stdout.write(` ${index + 1}. ${step.describe}\\n`)\n\n if (dryRun)\n continue\n\n if (!consented) {\n if (process.stdin.isTTY !== true) {\n fail(`${target.file} needs ${plan.steps.length} migration(s) and this session cannot ask.\\n re-run with --yes, or set HHOSTED_MIGRATE=allow for unattended runs`)\n }\n const answer = await prompt(`Apply ${plan.steps.length} migration(s) to ${path.basename(target.file)}? [y/N] `)\n if (!/^yes$|^y$/i.test(answer.trim())) {\n process.stdout.write('cancelled — nothing was written\\n')\n return\n }\n }\n\n const migratedProblem = target.validate(migrated)\n if (migratedProblem !== null)\n fail(`the migration produced a config this release cannot read:\\n ${migratedProblem}`)\n\n fs.copyFileSync(target.file, `${target.file}.bak`)\n writeFileAtomic(target.file, `${JSON.stringify(stampConfig(migrated), null, 2)}\\n`)\n lifted += 1\n process.stdout.write(`${green(`migrated ${target.label} to schema ${plan.to}`)} in ${target.file}\\n`)\n process.stdout.write(` ${dim(`previous file kept at ${target.file}.bak`)}\\n`)\n }\n\n // \"nothing to migrate\" has to mean nothing happened: a run that lifted three files printed it\n // anyway, because only the stamp-only path counted. The line a person reads to decide whether to\n // re-run has to agree with the lines above it.\n //\n // A dry run answers the same question in the same words, in the tense of a plan: it is the run a\n // person rehearses *before* letting a migration touch state they cannot easily restore, so its\n // closing line may not contradict the work it just described.\n const done: string[] = []\n if (dryRun) {\n if (needsLift > 0)\n done.push(green(`${needsLift} file(s) would be migrated`))\n if (stampOnly > 0)\n done.push(green(`${stampOnly} file(s) would be stamped`))\n process.stdout.write(\n done.length === 0\n ? `every file is already what home-hosted ${appVersion()} understands — nothing to migrate\\n`\n : `${done.join(', ')} to what home-hosted ${appVersion()} understands\\n`,\n )\n process.stdout.write(`${dim('nothing was written (--dry-run)')}\\n`)\n return\n }\n\n if (lifted > 0)\n done.push(green(`${lifted} file(s) migrated`))\n if (stampOnly > 0)\n done.push(green(`${stampOnly} file(s) stamped`))\n if (done.length === 0)\n process.stdout.write(`every file is already what home-hosted ${appVersion()} understands — nothing to migrate\\n`)\n else\n process.stdout.write(`${done.join(', ')} to what home-hosted ${appVersion()} understands\\n`)\n}\n\nexport const migrateCommand = defineCommand({\n meta: { name: 'migrate' },\n args: migrateArgs,\n run: async ({ args }) => {\n await runMigrate(args.dryRun === true, args.yes === true)\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA0BA,IAAa,cAAc;CACzB,QAAQ;EAAE,MAAM;EAAW,aAAa;CAAyC;CACjF,KAAK;EAAE,MAAM;EAAW,OAAO;EAAK,aAAa;CAAsD;AACzG;;AASA,SAAS,UAAoB;CAC3B,MAAM,OAAiB,CACrB;EACE,MAAM;EACN,OAAO;EACP,WAAU,QAAO,oBAAoB,GAAG,CAAC,CAAC,OAAO,MAAM;CACzD,CACF;CAEA,MAAM,WAAW,IAAI,kBAAkB;CACvC,SAAS,KAAK;CACd,IAAI,SAAS,gBAAgB,MAC3B,KAAK,eAAe,SAAS,KAAK,IAAI,SAAS,aAAa;CAE9D,KAAK,MAAM,aAAa,SAAS,IAAI,GAAG;EACtC,KAAK,KAAK;GACR,MAAM,sBAAsB,UAAU,EAAE;GACxC,OAAO,aAAa,UAAU,GAAG;GACjC,WAAU,QAAO,uBAAuB,GAAG,CAAC,CAAC,OAAO,MAAM;EAC5D,CAAC;EACD,KAAK,KAAK;GACR,MAAM,qBAAqB,UAAU,EAAE;GACvC,OAAO,aAAa,UAAU,GAAG;GACjC,WAAW,QAAQ;IAIjB,IAAI,WAAoC,CAAC;IACzC,IAAI;KACF,MAA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AAe;AAC/F;AAEA,IAAa,iBAAiB,cAAc;CAC1C,MAAM,EAAE,MAAM,UAAU;CACxB,MAAM;CACN,KAAK,OAAO,EAAE,WAAW;EACvB,MAAM,WAAW,KAAK,WAAW,MAAM,KAAK,QAAQ,IAAI;CAC1D;AACF,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { T as terminate, b as writeNannyState, c as describeSpawnError, f as nannyLogFile, n as NANNY_HEARTBEAT_MS, r as NANNY_TRAPPED_SIGNALS, s as describeNannyExit, w as spawnManaged } from "./nanny-BtWfy0QH.js";
|
|
2
|
+
import { i as LogFiles, t as LineSplitter } from "./log-buffer-Dy9HHDMD.js";
|
|
3
3
|
import process from "node:process";
|
|
4
4
|
//#region src/services/nanny.ts
|
|
5
5
|
/** Signals this nanny's own process group; false where there is none to signal (Windows, not a leader). */
|
|
@@ -129,4 +129,4 @@ async function runNanny(spec, statePath) {
|
|
|
129
129
|
//#endregion
|
|
130
130
|
export { runNanny };
|
|
131
131
|
|
|
132
|
-
//# sourceMappingURL=nanny-
|
|
132
|
+
//# sourceMappingURL=nanny-B-Eu0sFW.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nanny-
|
|
1
|
+
{"version":3,"file":"nanny-B-Eu0sFW.js","names":[],"sources":["../../src/services/nanny.ts"],"sourcesContent":["import type { ChildProcess } from 'node:child_process'\nimport type { LogStream, NannyExit, NannySpec, NannyState } from '#src/shared/contracts'\nimport process from 'node:process'\nimport { describeNannyExit, describeSpawnError, NANNY_HEARTBEAT_MS, NANNY_TRAPPED_SIGNALS, nannyLogFile, writeNannyState } from '#src/providers/nanny'\nimport { spawnManaged, terminate } from '#src/providers/process'\nimport { LineSplitter } from '#src/services/log-buffer'\nimport { LogFiles } from '#src/services/log-files'\n\n/** Signals this nanny's own process group; false where there is none to signal (Windows, not a leader). */\nfunction signalOwnGroup(signal: NodeJS.Signals): boolean {\n if (process.platform === 'win32')\n return false\n try {\n process.kill(-process.pid, signal)\n return true\n }\n catch {\n return false\n }\n}\n\n/**\n * The nanny of one persistent entry: it spawns the child, owns its pipes, writes its\n * output to the entry's JSONL log and mirrors the child's exit.\n *\n * This is the whole reason a persistent entry survives the panel. The pipes belong to\n * a process that is not the panel, so a panel stop, restart or SIGKILL cannot break\n * them; the log keeps being written; and the exit code the panel would have collected\n * as a parent is left in the state file for whoever comes back.\n *\n * It deliberately does *not* restart anything: retries, backoff and health stay the\n * panel's business, so there is only ever one supervisor making that decision.\n */\nexport async function runNanny(spec: NannySpec, statePath: string): Promise<void> {\n const id = spec.serverId\n const startedAt = Date.now()\n const logFile = nannyLogFile(spec.logDir, id)\n // The file is this entry's log *transport*, not its retention policy: the panel\n // still decides whether that history is served. So it is always written.\n const logFiles = new LogFiles(spec.logDir, () => ({ ...spec.logs, persist: true }))\n\n let childPid: number | null = null\n let lastExit: NannyExit | null = null\n let exitCode = 0\n\n const persistState = (): void => {\n const state: NannyState = {\n serverId: id,\n nannyPid: process.pid,\n childPid,\n startedAt,\n logFile,\n heartbeatAt: Date.now(),\n }\n if (lastExit !== null)\n state.lastExit = lastExit\n writeNannyState(statePath, state)\n }\n\n const emit = (stream: LogStream, text: string): void => {\n logFiles.append(id, { ts: Date.now(), stream, text })\n }\n\n // The traps go up before the child exists, and before anything about this nanny is on\n // disk: a stop that lands in between would otherwise kill a nanny that had not taken\n // over its child yet, orphaning that child with no record of it anywhere.\n let stopping = false\n let pending: NodeJS.Signals | null = null\n let spawned: ChildProcess | null = null\n\n const stopChild = (child: ChildProcess, signal: NodeJS.Signals): void => {\n emit('system', `${signal} — stopping this entry (grace ${spec.stop.graceMs}ms)`)\n // The panel signals this pid alone (`nannyStopOptions`), so `killGroup` is honoured here: one\n // signal to this group reaches the child and what it spawned exactly once, and the copy this\n // nanny receives is ignored. The escalation stays on the child's pid — the group holds us too.\n if (spec.stop.killGroup && NANNY_TRAPPED_SIGNALS.has(spec.stop.signal) && signalOwnGroup(spec.stop.signal)) {\n const escalate = setTimeout(() => {\n try {\n child.kill('SIGKILL')\n }\n catch {\n // already gone\n }\n }, spec.stop.graceMs)\n escalate.unref()\n child.once('exit', () => clearTimeout(escalate))\n return\n }\n void terminate(child, { signal: spec.stop.signal, killGroup: false, graceMs: spec.stop.graceMs })\n }\n\n const onSignal = (signal: NodeJS.Signals): void => {\n if (stopping)\n return\n stopping = true\n // Nothing to stop yet: the spawn is right behind this, and it reads `pending`.\n if (spawned === null)\n pending = signal\n else\n stopChild(spawned, signal)\n }\n\n // The same set `stopPersistentEntries` reads: a signal outside it ends this process without\n // forwarding anything, so the sweep has to signal the child itself.\n for (const signal of NANNY_TRAPPED_SIGNALS)\n process.on(signal, () => onSignal(signal))\n\n // Not detached: the child shares this nanny's process group, which is the group the\n // panel signals — one `kill(-pid)` still reaches the whole tree.\n const child = spawnManaged(\n { command: spec.command, args: spec.args, cwd: spec.cwd, env: spec.env },\n { detached: false },\n )\n spawned = child\n childPid = child.pid ?? null\n persistState()\n emit('system', `persistent: nanny pid ${process.pid} runs this entry`)\n // A stop that arrived before the spawn still has to reach the child it just made.\n if (pending !== null)\n stopChild(child, pending)\n\n const stdout = new LineSplitter((stream, text) => emit(stream, text))\n const stderr = new LineSplitter((stream, text) => emit(stream, text))\n child.stdout?.on('data', chunk => stdout.push('stdout', chunk))\n child.stderr?.on('data', chunk => stderr.push('stderr', chunk))\n\n const heartbeat = setInterval(persistState, NANNY_HEARTBEAT_MS)\n heartbeat.unref()\n\n await new Promise<void>((resolve) => {\n let settled = false\n const finish = (code: number | null, signal: NodeJS.Signals | null, runtimeMs: number, note?: string): void => {\n if (settled)\n return\n settled = true\n clearInterval(heartbeat)\n stdout.flush('stdout')\n stderr.flush('stderr')\n lastExit = { code, signal, at: Date.now(), runtimeMs }\n // The same formatter the panel uses, so the reason an entry died reads identically in the\n // nanny's mirror and in the panel's own log. Hand-rolling it here meant this line lost the\n // exit-code hint that the panel's line gained.\n emit('system', note ?? `persistent: exited with ${describeNannyExit(lastExit)}`)\n persistState()\n logFiles.dispose()\n // The panel reads the real cause from the state file; this is only the mirror.\n exitCode = code ?? (signal === null ? 0 : 1)\n resolve()\n }\n\n child.once('exit', (code, signal) => finish(code, signal, Date.now() - startedAt))\n child.once('error', (error: Error) => {\n // A command that cannot even be spawned: the panel reports it as \"did not start\".\n // Through the same formatter the panel uses, so a missing working directory is named\n // here too — this nanny is the only spawner a persistent entry has.\n finish(null, null, 0, `persistent: could not start the entry: ${describeSpawnError(error as NodeJS.ErrnoException, spec.command, spec.cwd)}`)\n })\n })\n\n // This nanny lives exactly as long as the child it owns, and says so by exiting.\n // Lingering is what an inherited pipe would do to us — a successor that kept our\n // stdout open refs the event loop — and a nanny that outlives its child is worse\n // than useless: the panel would report a healthy entry while the real server is a\n // detached process it can neither stop nor read. Exiting hands the entry back to\n // the panel, which is where `reclaim` can put it under a fresh nanny.\n process.exit(exitCode)\n}\n"],"mappings":";;;;;AASA,SAAS,eAAe,QAAiC;CACvD,IAAI,QAAQ,aAAa,SACvB,OAAO;CACT,IAAI;EACF,QAAQ,KAAK,CAAC,QAAQ,KAAK,MAAM;EACjC,OAAO;CACT,QACM;EACJ,OAAO;CACT;AACF;;;;;;;;;;;;;AAcA,eAAsB,SAAS,MAAiB,WAAkC;CAChF,MAAM,KAAK,KAAK;CAChB,MAAM,YAAY,KAAK,IAAI;CAC3B,MAAM,UAAU,aAAa,KAAK,QAAQ,EAAE;CAG5C,MAAM,WAAW,IAAI,SAAS,KAAK,eAAe;EAAE,GAAG,KAAK;EAAM,SAAS;CAAK,EAAE;CAElF,IAAI,WAA0B;CAC9B,IAAI,WAA6B;CACjC,IAAI,WAAW;CAEf,MAAM,qBAA2B;EAC/B,MAAM,QAAoB;GACxB,UAAU;GACV,UAAU,QAAQ;GAClB;GACA;GACA;GACA,aAAa,KAAK,IAAI;EACxB;EACA,IAAI,aAAa,MACf,MAAM,WAAW;EACnB,gBAAgB,WAAW,KAAK;CAClC;CA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