feat: implement TASK-WP1-05 account deletion

This commit is contained in:
suyx
2026-07-28 19:07:11 +08:00
parent 03f1509de7
commit 2358f97e5c
20 changed files with 2565 additions and 13 deletions
+19 -1
View File
@@ -3,6 +3,7 @@ import { join } from "node:path";
import { WorkerAiCallGate } from "./ai-call-gate.js";
import { readConfiguredLocalDataRoot } from "./runtime-config.js";
import { RetentionCleanup } from "./retention-cleanup.js";
import { StructuredJsonlLogger } from "./structured-log.js";
import { WorkerStorageStatus } from "./storage-status.js";
import { attachWorkerSupervisorControl, initializeWorkerCredentialClient, receiveWorkerCredentials } from "./supervisor-channel.js";
@@ -26,14 +27,31 @@ if (!workerPort && process.argv.includes("--dada-credential-stdin")) {
if (controlPipeIndex < 0 || !controlPipe) throw new Error("Supervisor control pipe name is required.");
const keepAlive = setInterval(() => undefined, 30_000);
let storage: WorkerStorageStatus | undefined;
let retention: RetentionCleanup | undefined;
let retentionTimer: ReturnType<typeof setInterval> | undefined;
const control = attachWorkerSupervisorControl(controlPipe, () => {
clearInterval(keepAlive);
if (retentionTimer) clearInterval(retentionTimer);
retention?.close();
storage?.close();
});
let storageStatus: "active" | "unavailable" = "active";
try {
const dataRoot = readConfiguredLocalDataRoot();
storage = new WorkerStorageStatus(join(dataRoot, "db", "dada.sqlite3"));
const databasePath = join(dataRoot, "db", "dada.sqlite3");
storage = new WorkerStorageStatus(databasePath);
retention = new RetentionCleanup({ databasePath });
const runRetentionCleanup = () => {
try {
retention?.purgeExpired();
} catch {
storageStatus = "unavailable";
storage?.markLogUnavailable();
control.reportStatus("storage_unavailable");
}
};
runRetentionCleanup();
retentionTimer = setInterval(runRetentionCleanup, 24 * 60 * 60 * 1_000);
const logger = new StructuredJsonlLogger({
component: "worker",
directory: join(dataRoot, "logs", "worker"),