@moxt-ai/mobius 0.0.281 → 0.0.282
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/dist/acp/acp-error.d.ts +2 -2
- package/dist/acp/acp-error.d.ts.map +1 -1
- package/dist/acp/acp-error.js +3 -4
- package/dist/acp/acp-error.js.map +1 -1
- package/dist/acp/agent/agent-definition.d.ts +1 -1
- package/dist/acp/agent/agent-definition.d.ts.map +1 -1
- package/dist/acp/agent/agent-definition.js +3 -9
- package/dist/acp/agent/agent-definition.js.map +1 -1
- package/dist/acp/agent-process-pool.d.ts +5 -1
- package/dist/acp/agent-process-pool.d.ts.map +1 -1
- package/dist/acp/agent-process-pool.js +57 -2
- package/dist/acp/agent-process-pool.js.map +1 -1
- package/dist/acp/agent-query-processes.d.ts.map +1 -1
- package/dist/acp/agent-query-processes.js +1 -0
- package/dist/acp/agent-query-processes.js.map +1 -1
- package/dist/acp/agent-runtime-manager.d.ts.map +1 -1
- package/dist/acp/agent-runtime-manager.js +45 -16
- package/dist/acp/agent-runtime-manager.js.map +1 -1
- package/dist/acp/content/raster.d.ts.map +1 -1
- package/dist/acp/content/raster.js +6 -13
- package/dist/acp/content/raster.js.map +1 -1
- package/dist/acp/external-content/local-external-content-store.d.ts.map +1 -1
- package/dist/acp/external-content/local-external-content-store.js +14 -59
- package/dist/acp/external-content/local-external-content-store.js.map +1 -1
- package/dist/acp/session-event-store.d.ts +2 -2
- package/dist/acp/session-event-store.d.ts.map +1 -1
- package/dist/acp/session-event-store.js +10 -11
- package/dist/acp/session-event-store.js.map +1 -1
- package/dist/acp/session-live-event-position.d.ts +2 -2
- package/dist/acp/session-live-event-position.d.ts.map +1 -1
- package/dist/acp/session-live-event-position.js +8 -23
- package/dist/acp/session-live-event-position.js.map +1 -1
- package/dist/acp/session-store.d.ts +2 -2
- package/dist/acp/session-store.d.ts.map +1 -1
- package/dist/acp/session-store.js +11 -37
- package/dist/acp/session-store.js.map +1 -1
- package/dist/agent/catalog.d.ts +2 -2
- package/dist/agent/catalog.d.ts.map +1 -1
- package/dist/agent/catalog.js +3 -3
- package/dist/agent/catalog.js.map +1 -1
- package/dist/agent/specification/vendors/pi-agent.d.ts +3 -1
- package/dist/agent/specification/vendors/pi-agent.d.ts.map +1 -1
- package/dist/agent/specification/vendors/pi-agent.js +14 -1
- package/dist/agent/specification/vendors/pi-agent.js.map +1 -1
- package/dist/cli/handler/agents/index.d.ts.map +1 -1
- package/dist/cli/handler/agents/index.js +2 -2
- package/dist/cli/handler/agents/index.js.map +1 -1
- package/dist/cli/handler/logs/logic/collect-local-logs.d.ts.map +1 -1
- package/dist/cli/handler/logs/logic/collect-local-logs.js +10 -124
- package/dist/cli/handler/logs/logic/collect-local-logs.js.map +1 -1
- package/dist/cli/handler/pair/logic/pair-list-output.d.ts +1 -1
- package/dist/cli/handler/pair/logic/pair-list-output.d.ts.map +1 -1
- package/dist/cli/handler/pair/logic/pair-list-output.js +17 -29
- package/dist/cli/handler/pair/logic/pair-list-output.js.map +1 -1
- package/dist/cli.js +8630 -8273
- package/dist/cli.js.map +4 -4
- package/dist/daemon/control/local-client.d.ts +0 -3
- package/dist/daemon/control/local-client.d.ts.map +1 -1
- package/dist/daemon/control/local-client.js +2 -60
- package/dist/daemon/control/local-client.js.map +1 -1
- package/dist/daemon/control/local-server.d.ts.map +1 -1
- package/dist/daemon/control/local-server.js +2 -1
- package/dist/daemon/control/local-server.js.map +1 -1
- package/dist/daemon/lifecycle/manager-client.d.ts.map +1 -1
- package/dist/daemon/lifecycle/manager-client.js +5 -11
- package/dist/daemon/lifecycle/manager-client.js.map +1 -1
- package/dist/daemon/lifecycle/manager.js +1 -1
- package/dist/daemon/lifecycle/manager.js.map +1 -1
- package/dist/daemon/lifecycle/unhandled-rejection.d.ts.map +1 -1
- package/dist/daemon/lifecycle/unhandled-rejection.js +2 -2
- package/dist/daemon/lifecycle/unhandled-rejection.js.map +1 -1
- package/dist/daemon/lifecycle/worker-lifecycle-log.d.ts.map +1 -1
- package/dist/daemon/lifecycle/worker-lifecycle-log.js +2 -1
- package/dist/daemon/lifecycle/worker-lifecycle-log.js.map +1 -1
- package/dist/daemon/lifecycle/worker-process.d.ts.map +1 -1
- package/dist/daemon/lifecycle/worker-process.js +4 -5
- package/dist/daemon/lifecycle/worker-process.js.map +1 -1
- package/dist/daemon/lifecycle/worker.d.ts.map +1 -1
- package/dist/daemon/lifecycle/worker.js +3 -1
- package/dist/daemon/lifecycle/worker.js.map +1 -1
- package/dist/daemon/pairing/pair-local-machine.d.ts +1 -1
- package/dist/daemon/pairing/pair-local-machine.d.ts.map +1 -1
- package/dist/daemon/pairing/pair-local-machine.js +8 -12
- package/dist/daemon/pairing/pair-local-machine.js.map +1 -1
- package/dist/daemon/upgrades/data.d.ts +0 -3
- package/dist/daemon/upgrades/data.d.ts.map +1 -1
- package/dist/daemon/upgrades/data.js +6 -80
- package/dist/daemon/upgrades/data.js.map +1 -1
- package/dist/daemon/upgrades/package.js +8 -8
- package/dist/daemon/upgrades/package.js.map +1 -1
- package/dist/daemon/upgrades/upgrade.d.ts.map +1 -1
- package/dist/daemon/upgrades/upgrade.js +2 -1
- package/dist/daemon/upgrades/upgrade.js.map +1 -1
- package/dist/infra/operation-error.d.ts +9 -0
- package/dist/infra/operation-error.d.ts.map +1 -0
- package/dist/infra/operation-error.js +16 -0
- package/dist/infra/operation-error.js.map +1 -0
- package/dist/runtime/command/agent-settings-discovery.d.ts.map +1 -1
- package/dist/runtime/command/agent-settings-discovery.js +2 -1
- package/dist/runtime/command/agent-settings-discovery.js.map +1 -1
- package/dist/runtime/command/native-session-requests.d.ts.map +1 -1
- package/dist/runtime/command/native-session-requests.js +2 -1
- package/dist/runtime/command/native-session-requests.js.map +1 -1
- package/dist/runtime/command/registry/file-read/logic/local-file-streamer.d.ts.map +1 -1
- package/dist/runtime/command/registry/file-read/logic/local-file-streamer.js +8 -11
- package/dist/runtime/command/registry/file-read/logic/local-file-streamer.js.map +1 -1
- package/dist/runtime/command/registry/history.d.ts.map +1 -1
- package/dist/runtime/command/registry/history.js +2 -1
- package/dist/runtime/command/registry/history.js.map +1 -1
- package/dist/runtime/command/registry/session.d.ts.map +1 -1
- package/dist/runtime/command/registry/session.js +2 -1
- package/dist/runtime/command/registry/session.js.map +1 -1
- package/dist/runtime/command/transport.d.ts +0 -2
- package/dist/runtime/command/transport.d.ts.map +1 -1
- package/dist/runtime/command/transport.js +2 -20
- package/dist/runtime/command/transport.js.map +1 -1
- package/dist/runtime/connection/runtime-connection.d.ts +27 -0
- package/dist/runtime/connection/runtime-connection.d.ts.map +1 -0
- package/dist/runtime/connection/runtime-connection.js +29 -0
- package/dist/runtime/connection/runtime-connection.js.map +1 -0
- package/dist/{storage → runtime/connection}/runtime-installation-store.d.ts +1 -25
- package/dist/runtime/connection/runtime-installation-store.d.ts.map +1 -0
- package/dist/{storage → runtime/connection}/runtime-installation-store.js +33 -87
- package/dist/runtime/connection/runtime-installation-store.js.map +1 -0
- package/dist/runtime/engine.d.ts +2 -1
- package/dist/runtime/engine.d.ts.map +1 -1
- package/dist/runtime/engine.js +9 -12
- package/dist/runtime/engine.js.map +1 -1
- package/dist/runtime/observability/diagnostic-log.d.ts.map +1 -1
- package/dist/runtime/observability/diagnostic-log.js +9 -21
- package/dist/runtime/observability/diagnostic-log.js.map +1 -1
- package/dist/runtime/run.d.ts.map +1 -1
- package/dist/runtime/run.js +8 -7
- package/dist/runtime/run.js.map +1 -1
- package/dist/runtime/session/execute-prompt.d.ts.map +1 -1
- package/dist/runtime/session/execute-prompt.js +1 -1
- package/dist/runtime/session/execute-prompt.js.map +1 -1
- package/dist/runtime/session/prompt-artifact-resolver.d.ts +2 -2
- package/dist/runtime/session/prompt-artifact-resolver.d.ts.map +1 -1
- package/dist/runtime/session/prompt-artifact-resolver.js +3 -4
- package/dist/runtime/session/prompt-artifact-resolver.js.map +1 -1
- package/dist/runtime/workspace/local-authorization-error.d.ts +2 -2
- package/dist/runtime/workspace/local-authorization-error.d.ts.map +1 -1
- package/dist/runtime/workspace/local-authorization-error.js +3 -3
- package/dist/runtime/workspace/local-authorization-error.js.map +1 -1
- package/dist/runtime/workspace/workspace-directory.d.ts.map +1 -1
- package/dist/runtime/workspace/workspace-directory.js +9 -10
- package/dist/runtime/workspace/workspace-directory.js.map +1 -1
- package/dist/runtime.js +8378 -8072
- package/dist/runtime.js.map +4 -4
- package/dist/storage/daemon/control-token.d.ts +3 -0
- package/dist/storage/daemon/control-token.d.ts.map +1 -0
- package/dist/storage/daemon/control-token.js +31 -0
- package/dist/storage/daemon/control-token.js.map +1 -0
- package/dist/storage/daemon/manager-lock.d.ts +8 -0
- package/dist/storage/daemon/manager-lock.d.ts.map +1 -0
- package/dist/storage/daemon/manager-lock.js +50 -0
- package/dist/storage/daemon/manager-lock.js.map +1 -0
- package/dist/storage/daemon/release-files.d.ts +9 -0
- package/dist/storage/daemon/release-files.d.ts.map +1 -0
- package/dist/storage/daemon/release-files.js +13 -0
- package/dist/storage/daemon/release-files.js.map +1 -0
- package/dist/storage/daemon/version-data.d.ts +11 -0
- package/dist/storage/daemon/version-data.d.ts.map +1 -0
- package/dist/storage/daemon/version-data.js +93 -0
- package/dist/storage/daemon/version-data.js.map +1 -0
- package/dist/storage/files/local-files.d.ts +27 -0
- package/dist/storage/files/local-files.d.ts.map +1 -0
- package/dist/storage/files/local-files.js +66 -0
- package/dist/storage/files/local-files.js.map +1 -0
- package/dist/storage/files/output-file.d.ts +14 -0
- package/dist/storage/files/output-file.d.ts.map +1 -0
- package/dist/storage/files/output-file.js +27 -0
- package/dist/storage/files/output-file.js.map +1 -0
- package/dist/storage/files/scratch-directory.d.ts +17 -0
- package/dist/storage/files/scratch-directory.d.ts.map +1 -0
- package/dist/storage/files/scratch-directory.js +76 -0
- package/dist/storage/files/scratch-directory.js.map +1 -0
- package/dist/storage/installation/installation-files.d.ts +28 -0
- package/dist/storage/installation/installation-files.d.ts.map +1 -0
- package/dist/storage/installation/installation-files.js +75 -0
- package/dist/storage/installation/installation-files.js.map +1 -0
- package/dist/storage/logs/log-files.d.ts +31 -0
- package/dist/storage/logs/log-files.d.ts.map +1 -0
- package/dist/storage/logs/log-files.js +149 -0
- package/dist/storage/logs/log-files.js.map +1 -0
- package/dist/storage/session/acp-session-table.d.ts +25 -0
- package/dist/storage/session/acp-session-table.d.ts.map +1 -0
- package/dist/storage/session/acp-session-table.js +47 -0
- package/dist/storage/session/acp-session-table.js.map +1 -0
- package/dist/storage/session/live-event-position-table.d.ts +11 -0
- package/dist/storage/session/live-event-position-table.d.ts.map +1 -0
- package/dist/storage/session/live-event-position-table.js +31 -0
- package/dist/storage/session/live-event-position-table.js.map +1 -0
- package/dist/{acp/session-event-cache-database.d.ts → storage/session/session-event-cache-table.d.ts} +3 -3
- package/dist/storage/session/session-event-cache-table.d.ts.map +1 -0
- package/dist/{acp/session-event-cache-database.js → storage/session/session-event-cache-table.js} +3 -3
- package/dist/storage/session/session-event-cache-table.js.map +1 -0
- package/dist/storage/sqlite/local-databases.d.ts +6 -0
- package/dist/storage/sqlite/local-databases.d.ts.map +1 -1
- package/dist/storage/sqlite/local-databases.js +10 -0
- package/dist/storage/sqlite/local-databases.js.map +1 -1
- package/dist/util/node-error.d.ts +3 -0
- package/dist/util/node-error.d.ts.map +1 -0
- package/dist/util/node-error.js +5 -0
- package/dist/util/node-error.js.map +1 -0
- package/dist/util/process/local-executable.d.ts +9 -0
- package/dist/util/process/local-executable.d.ts.map +1 -0
- package/dist/util/process/local-executable.js +19 -0
- package/dist/util/process/local-executable.js.map +1 -0
- package/package.json +1 -1
- package/dist/acp/session-event-cache-database.d.ts.map +0 -1
- package/dist/acp/session-event-cache-database.js.map +0 -1
- package/dist/storage/runtime-installation-store.d.ts.map +0 -1
- package/dist/storage/runtime-installation-store.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control-token.d.ts","sourceRoot":"","sources":["../../../src/storage/daemon/control-token.ts"],"names":[],"mappings":"AASA,gHAAgH;AAChH,wBAAsB,wBAAwB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAmBtF"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { isNodeError } from "../../util/node-error.js";
|
|
5
|
+
function controlTokenPath(stateDirectory) {
|
|
6
|
+
return join(stateDirectory, "manager.token");
|
|
7
|
+
}
|
|
8
|
+
/** The secret local control clients present to the daemon, created on first use with owner-only permissions. */
|
|
9
|
+
export async function readOrCreateControlToken(stateDirectory) {
|
|
10
|
+
const path = controlTokenPath(stateDirectory);
|
|
11
|
+
try {
|
|
12
|
+
return (await readFile(path, "utf8")).trim();
|
|
13
|
+
}
|
|
14
|
+
catch (cause) {
|
|
15
|
+
if (!isNodeError(cause, "ENOENT")) {
|
|
16
|
+
throw cause;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const token = randomBytes(32).toString("base64url");
|
|
20
|
+
try {
|
|
21
|
+
await writeFile(path, `${token}\n`, { flag: "wx", mode: 0o600 });
|
|
22
|
+
return token;
|
|
23
|
+
}
|
|
24
|
+
catch (cause) {
|
|
25
|
+
if (!isNodeError(cause, "EEXIST")) {
|
|
26
|
+
throw cause;
|
|
27
|
+
}
|
|
28
|
+
return (await readFile(path, "utf8")).trim();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=control-token.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"control-token.js","sourceRoot":"","sources":["../../../src/storage/daemon/control-token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,SAAS,gBAAgB,CAAC,cAAsB;IAC5C,OAAO,IAAI,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;AACjD,CAAC;AAED,gHAAgH;AAChH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAAC,cAAsB;IACjE,MAAM,IAAI,GAAG,gBAAgB,CAAC,cAAc,CAAC,CAAC;IAC9C,IAAI,CAAC;QACD,OAAO,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACjD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE,CAAC;YAChC,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC;IACD,MAAM,KAAK,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IACpD,IAAI,CAAC;QACD,MAAM,SAAS,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QACjE,OAAO,KAAK,CAAC;IACjB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE,CAAC;YAChC,MAAM,KAAK,CAAC;QAChB,CAAC;QACD,OAAO,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACjD,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Takes the lock file that makes this process the only holder of a daemon role. A lock left by a
|
|
3
|
+
* process that is gone is replaced. Returns the release function, or null when a live process holds it.
|
|
4
|
+
*/
|
|
5
|
+
export declare function acquireManagerLock(stateDirectory: string, name?: string): Promise<(() => Promise<void>) | null>;
|
|
6
|
+
/** True while the manager lock file exists. */
|
|
7
|
+
export declare function managerLockExists(stateDirectory: string): Promise<boolean>;
|
|
8
|
+
//# sourceMappingURL=manager-lock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager-lock.d.ts","sourceRoot":"","sources":["../../../src/storage/daemon/manager-lock.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,wBAAsB,kBAAkB,CACpC,cAAc,EAAE,MAAM,EACtB,IAAI,SAAiB,GACtB,OAAO,CAAC,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CA0BvC;AAED,+CAA+C;AAC/C,wBAAsB,iBAAiB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAUhF"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { readFile, unlink, writeFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { isNodeError } from "../../util/node-error.js";
|
|
4
|
+
/**
|
|
5
|
+
* Takes the lock file that makes this process the only holder of a daemon role. A lock left by a
|
|
6
|
+
* process that is gone is replaced. Returns the release function, or null when a live process holds it.
|
|
7
|
+
*/
|
|
8
|
+
export async function acquireManagerLock(stateDirectory, name = "manager.lock") {
|
|
9
|
+
const path = join(stateDirectory, name);
|
|
10
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
11
|
+
try {
|
|
12
|
+
await writeFile(path, `${process.pid.toString()}\n`, { flag: "wx", mode: 0o600 });
|
|
13
|
+
return async () => await unlink(path).catch(() => undefined);
|
|
14
|
+
}
|
|
15
|
+
catch (cause) {
|
|
16
|
+
if (!isNodeError(cause, "EEXIST")) {
|
|
17
|
+
throw cause;
|
|
18
|
+
}
|
|
19
|
+
const encoded = await readFile(path, "utf8").catch(() => "");
|
|
20
|
+
const pid = Number(encoded.trim());
|
|
21
|
+
if (Number.isSafeInteger(pid) && pid > 1) {
|
|
22
|
+
try {
|
|
23
|
+
process.kill(pid, 0);
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
catch (probeCause) {
|
|
27
|
+
if (!isNodeError(probeCause, "ESRCH")) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
await unlink(path).catch(() => undefined);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
/** True while the manager lock file exists. */
|
|
38
|
+
export async function managerLockExists(stateDirectory) {
|
|
39
|
+
try {
|
|
40
|
+
await readFile(join(stateDirectory, "manager.lock"), "utf8");
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
catch (cause) {
|
|
44
|
+
if (isNodeError(cause, "ENOENT")) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
throw cause;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=manager-lock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager-lock.js","sourceRoot":"","sources":["../../../src/storage/daemon/manager-lock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACpC,cAAsB,EACtB,IAAI,GAAG,cAAc;IAErB,MAAM,IAAI,GAAG,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;IACxC,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,GAAG,CAAC,EAAE,OAAO,IAAI,CAAC,EAAE,CAAC;QAC9C,IAAI,CAAC;YACD,MAAM,SAAS,CAAC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EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,CAAC;QAC7D,OAAO,IAAI,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,IAAI,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE,CAAC;YAC/B,OAAO,KAAK,CAAC;QACjB,CAAC;QACD,MAAM,KAAK,CAAC;IAChB,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** npm installs each daemon release into its own prefix, so an upgrade never overwrites the running release. */
|
|
2
|
+
export declare function releasePrefix(version: string): string;
|
|
3
|
+
export interface InstalledRelease {
|
|
4
|
+
readonly manifest: string;
|
|
5
|
+
readonly packageRoot: string;
|
|
6
|
+
}
|
|
7
|
+
/** The canonical directory of the Mobius package npm installed into `prefix`, and its package.json text. */
|
|
8
|
+
export declare function readInstalledRelease(prefix: string): Promise<InstalledRelease>;
|
|
9
|
+
//# sourceMappingURL=release-files.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"release-files.d.ts","sourceRoot":"","sources":["../../../src/storage/daemon/release-files.ts"],"names":[],"mappings":"AAIA,gHAAgH;AAChH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAErD;AAED,MAAM,WAAW,gBAAgB;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAChC;AAED,4GAA4G;AAC5G,wBAAsB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAGpF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { readFile, realpath } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { readStateDirectory } from "../state-directory.js";
|
|
4
|
+
/** npm installs each daemon release into its own prefix, so an upgrade never overwrites the running release. */
|
|
5
|
+
export function releasePrefix(version) {
|
|
6
|
+
return join(readStateDirectory(), "npm", version);
|
|
7
|
+
}
|
|
8
|
+
/** The canonical directory of the Mobius package npm installed into `prefix`, and its package.json text. */
|
|
9
|
+
export async function readInstalledRelease(prefix) {
|
|
10
|
+
const packageRoot = await realpath(join(prefix, "node_modules", "@moxt-ai", "mobius"));
|
|
11
|
+
return { manifest: await readFile(join(packageRoot, "package.json"), "utf8"), packageRoot };
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=release-files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"release-files.js","sourceRoot":"","sources":["../../../src/storage/daemon/release-files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D,gHAAgH;AAChH,MAAM,UAAU,aAAa,CAAC,OAAe;IACzC,OAAO,IAAI,CAAC,kBAAkB,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AACtD,CAAC;AAOD,4GAA4G;AAC5G,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,MAAc;IACrD,MAAM,WAAW,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;IACvF,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC;AAChG,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class DataInheritanceError extends Error {
|
|
2
|
+
readonly code = "data_inheritance_failed";
|
|
3
|
+
}
|
|
4
|
+
/** The version the current data pointer names, or null when there is no pointer. */
|
|
5
|
+
export declare function readCurrentDataVersion(root: string, signal: AbortSignal): Promise<string | null>;
|
|
6
|
+
export declare function versionDataExists(root: string, version: string, signal: AbortSignal): Promise<boolean>;
|
|
7
|
+
/** Copies one version's data into a new version's directory. Symbolic links are rejected. */
|
|
8
|
+
export declare function copyVersionData(root: string, sourceVersion: string, targetVersion: string, signal: AbortSignal): Promise<void>;
|
|
9
|
+
/** Points the current data pointer at a version whose data directory exists. */
|
|
10
|
+
export declare function writeCurrentDataVersion(root: string, version: string, signal: AbortSignal): Promise<void>;
|
|
11
|
+
//# sourceMappingURL=version-data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version-data.d.ts","sourceRoot":"","sources":["../../../src/storage/daemon/version-data.ts"],"names":[],"mappings":"AAUA,qBAAa,oBAAqB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,IAAI,6BAA6B;CAC7C;AAED,oFAAoF;AACpF,wBAAsB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAgBtG;AAED,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAU5G;AAED,6FAA6F;AAC7F,wBAAsB,eAAe,CACjC,IAAI,EAAE,MAAM,EACZ,aAAa,EAAE,MAAM,EACrB,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,WAAW,GACpB,OAAO,CAAC,IAAI,CAAC,CAgCf;AAED,gFAAgF;AAChF,wBAAsB,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAW/G"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { cp, lstat, mkdtemp, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { runtimeUpgradeVersionSchema } from "@moxt-ai/mobius-sdk/protocol";
|
|
5
|
+
import { validateLocalPath } from "../../util/filesystem/private-path.js";
|
|
6
|
+
import { isNodeError } from "../../util/node-error.js";
|
|
7
|
+
// Each daemon version keeps its data in `versions/<version>/` under the state root, and
|
|
8
|
+
// `current-data.txt` names the version whose data is current.
|
|
9
|
+
export class DataInheritanceError extends Error {
|
|
10
|
+
code = "data_inheritance_failed";
|
|
11
|
+
}
|
|
12
|
+
/** The version the current data pointer names, or null when there is no pointer. */
|
|
13
|
+
export async function readCurrentDataVersion(root, signal) {
|
|
14
|
+
// A relative, version-only pointer remains valid if the state root is moved.
|
|
15
|
+
const pointer = join(root, "current-data.txt");
|
|
16
|
+
try {
|
|
17
|
+
await validateLocalPath(pointer, false, true, signal);
|
|
18
|
+
const value = (await readFile(pointer, { encoding: "utf8", signal })).trim();
|
|
19
|
+
if (!value.startsWith("versions/")) {
|
|
20
|
+
throw new DataInheritanceError("The current data pointer must name a version directory");
|
|
21
|
+
}
|
|
22
|
+
return runtimeUpgradeVersionSchema.parse(value.slice("versions/".length));
|
|
23
|
+
}
|
|
24
|
+
catch (cause) {
|
|
25
|
+
if (isNodeError(cause, "ENOENT")) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
throw cause;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export async function versionDataExists(root, version, signal) {
|
|
32
|
+
try {
|
|
33
|
+
await validateLocalPath(join(root, "versions", version), true, true, signal);
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
catch (cause) {
|
|
37
|
+
if (!isNodeError(cause, "ENOENT")) {
|
|
38
|
+
throw cause;
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** Copies one version's data into a new version's directory. Symbolic links are rejected. */
|
|
44
|
+
export async function copyVersionData(root, sourceVersion, targetVersion, signal) {
|
|
45
|
+
const versions = join(root, "versions");
|
|
46
|
+
const source = join(versions, sourceVersion);
|
|
47
|
+
const target = join(versions, targetVersion);
|
|
48
|
+
await validateLocalPath(root, true, true, signal);
|
|
49
|
+
await validateLocalPath(versions, true, true, signal);
|
|
50
|
+
await validateLocalPath(source, true, true, signal);
|
|
51
|
+
const staging = await mkdtemp(join(versions, `.${targetVersion}-`));
|
|
52
|
+
try {
|
|
53
|
+
await cp(source, staging, {
|
|
54
|
+
recursive: true,
|
|
55
|
+
filter: async (path) => {
|
|
56
|
+
signal.throwIfAborted();
|
|
57
|
+
if ((await lstat(path)).isSymbolicLink()) {
|
|
58
|
+
throw new DataInheritanceError("The inherited data contains a symbolic link");
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
signal.throwIfAborted();
|
|
64
|
+
try {
|
|
65
|
+
await rename(staging, target);
|
|
66
|
+
}
|
|
67
|
+
catch (cause) {
|
|
68
|
+
// Another CLI may have finished the same first-use copy.
|
|
69
|
+
if (!isNodeError(cause, "EEXIST") && !isNodeError(cause, "ENOTEMPTY")) {
|
|
70
|
+
throw cause;
|
|
71
|
+
}
|
|
72
|
+
await validateLocalPath(target, true, true, signal);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
await rm(staging, { recursive: true, force: true });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** Points the current data pointer at a version whose data directory exists. */
|
|
80
|
+
export async function writeCurrentDataVersion(root, version, signal) {
|
|
81
|
+
await validateLocalPath(root, true, true, signal);
|
|
82
|
+
await validateLocalPath(join(root, "versions", version), true, true, signal);
|
|
83
|
+
const temporary = join(root, `.current-data-${randomUUID()}.txt`);
|
|
84
|
+
try {
|
|
85
|
+
await writeFile(temporary, `versions/${version}\n`, { mode: 0o600, flag: "wx", signal });
|
|
86
|
+
signal.throwIfAborted();
|
|
87
|
+
await rename(temporary, join(root, "current-data.txt"));
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
await rm(temporary, { force: true });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=version-data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version-data.js","sourceRoot":"","sources":["../../../src/storage/daemon/version-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACvF,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAC;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,wFAAwF;AACxF,8DAA8D;AAE9D,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAClC,IAAI,GAAG,yBAAyB,CAAC;CAC7C;AAED,oFAAoF;AACpF,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,IAAY,EAAE,MAAmB;IAC1E,6EAA6E;IAC7E,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC;IAC/C,IAAI,CAAC;QACD,MAAM,iBAAiB,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QACtD,MAAM,KAAK,GAAG,CAAC,MAAM,QAAQ,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAC7E,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;YACjC,MAAM,IAAI,oBAAoB,CAAC,wDAAwD,CAAC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AI,EAAE,MAAM,CAAC,CAAC;IAClD,MAAM,iBAAiB,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IAC7E,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,EAAE,iBAAiB,UAAU,EAAE,MAAM,CAAC,CAAC;IAClE,IAAI,CAAC;QACD,MAAM,SAAS,CAAC,SAAS,EAAE,YAAY,OAAO,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;QACzF,MAAM,CAAC,cAAc,EAAE,CAAC;QACxB,MAAM,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC,CAAC;IAC5D,CAAC;YAAS,CAAC;QACP,MAAM,EAAE,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACzC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** What a path names once symbolic links are followed. */
|
|
2
|
+
export type LocalPathKind = "directory" | "file" | "other";
|
|
3
|
+
export interface LocalPathMetadata {
|
|
4
|
+
readonly kind: LocalPathKind;
|
|
5
|
+
readonly modifiedAt: Date;
|
|
6
|
+
readonly modifiedMilliseconds: number;
|
|
7
|
+
readonly size: number;
|
|
8
|
+
}
|
|
9
|
+
/** What a directory entry is, without following symbolic links. */
|
|
10
|
+
export type LocalDirectoryEntryKind = "directory" | "file" | "symbolic-link" | "device" | "fifo" | "socket" | "unknown";
|
|
11
|
+
export interface LocalDirectoryEntry {
|
|
12
|
+
readonly kind: LocalDirectoryEntryKind;
|
|
13
|
+
readonly name: string;
|
|
14
|
+
}
|
|
15
|
+
/** The absolute path with every symbolic link resolved. Fails when the path does not exist. */
|
|
16
|
+
export declare function canonicalPath(path: string): Promise<string>;
|
|
17
|
+
export declare function readPathMetadata(path: string): Promise<LocalPathMetadata>;
|
|
18
|
+
export declare function listDirectory(path: string): Promise<readonly LocalDirectoryEntry[]>;
|
|
19
|
+
/** Creates the directory and its missing parents with owner-only permissions. */
|
|
20
|
+
export declare function ensurePrivateDirectory(path: string): Promise<void>;
|
|
21
|
+
/** Creates the directory when it is missing, then returns its canonical path, or null when it is not a directory. */
|
|
22
|
+
export declare function ensureCanonicalDirectory(path: string): Promise<string | null>;
|
|
23
|
+
/** The first `byteLength` bytes of a file, zero-filled when the file is shorter. */
|
|
24
|
+
export declare function readFileStart(path: string, byteLength: number): Promise<Uint8Array>;
|
|
25
|
+
export declare function readFileBytes(path: string): Promise<Uint8Array>;
|
|
26
|
+
export declare function readFileChunks(path: string, chunkBytes: number, signal: AbortSignal): AsyncIterable<Uint8Array>;
|
|
27
|
+
//# sourceMappingURL=local-files.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-files.d.ts","sourceRoot":"","sources":["../../../src/storage/files/local-files.ts"],"names":[],"mappings":"AAGA,0DAA0D;AAC1D,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,MAAM,GAAG,OAAO,CAAC;AAE3D,MAAM,WAAW,iBAAiB;IAC9B,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC;IAC1B,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACzB;AAED,mEAAmE;AACnE,MAAM,MAAM,uBAAuB,GAAG,WAAW,GAAG,MAAM,GAAG,eAAe,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;AAExH,MAAM,WAAW,mBAAmB;IAChC,QAAQ,CAAC,IAAI,EAAE,uBAAuB,CAAC;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACzB;AAqBD,+FAA+F;AAC/F,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAEjE;AAED,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAQ/E;AAED,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,mBAAmB,EAAE,CAAC,CAGzF;AAED,iFAAiF;AACjF,wBAAsB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAExE;AAED,qHAAqH;AACrH,wBAAsB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAInF;AAED,oFAAoF;AACpF,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CASzF;AAED,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAErE;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,aAAa,CAAC,UAAU,CAAC,CAE/G"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { createReadStream } from "node:fs";
|
|
2
|
+
import { mkdir, open, readdir, readFile, realpath, stat } from "node:fs/promises";
|
|
3
|
+
function entryKind(entry) {
|
|
4
|
+
if (entry.isDirectory()) {
|
|
5
|
+
return "directory";
|
|
6
|
+
}
|
|
7
|
+
if (entry.isFile()) {
|
|
8
|
+
return "file";
|
|
9
|
+
}
|
|
10
|
+
if (entry.isSymbolicLink()) {
|
|
11
|
+
return "symbolic-link";
|
|
12
|
+
}
|
|
13
|
+
if (entry.isBlockDevice() || entry.isCharacterDevice()) {
|
|
14
|
+
return "device";
|
|
15
|
+
}
|
|
16
|
+
if (entry.isFIFO()) {
|
|
17
|
+
return "fifo";
|
|
18
|
+
}
|
|
19
|
+
return entry.isSocket() ? "socket" : "unknown";
|
|
20
|
+
}
|
|
21
|
+
/** The absolute path with every symbolic link resolved. Fails when the path does not exist. */
|
|
22
|
+
export async function canonicalPath(path) {
|
|
23
|
+
return await realpath(path);
|
|
24
|
+
}
|
|
25
|
+
export async function readPathMetadata(path) {
|
|
26
|
+
const metadata = await stat(path);
|
|
27
|
+
return {
|
|
28
|
+
kind: metadata.isDirectory() ? "directory" : metadata.isFile() ? "file" : "other",
|
|
29
|
+
modifiedAt: metadata.mtime,
|
|
30
|
+
modifiedMilliseconds: metadata.mtimeMs,
|
|
31
|
+
size: metadata.size,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export async function listDirectory(path) {
|
|
35
|
+
const entries = await readdir(path, { withFileTypes: true });
|
|
36
|
+
return entries.map((entry) => ({ kind: entryKind(entry), name: entry.name }));
|
|
37
|
+
}
|
|
38
|
+
/** Creates the directory and its missing parents with owner-only permissions. */
|
|
39
|
+
export async function ensurePrivateDirectory(path) {
|
|
40
|
+
await mkdir(path, { mode: 0o700, recursive: true });
|
|
41
|
+
}
|
|
42
|
+
/** Creates the directory when it is missing, then returns its canonical path, or null when it is not a directory. */
|
|
43
|
+
export async function ensureCanonicalDirectory(path) {
|
|
44
|
+
await ensurePrivateDirectory(path);
|
|
45
|
+
const resolved = await realpath(path);
|
|
46
|
+
return (await stat(resolved)).isDirectory() ? resolved : null;
|
|
47
|
+
}
|
|
48
|
+
/** The first `byteLength` bytes of a file, zero-filled when the file is shorter. */
|
|
49
|
+
export async function readFileStart(path, byteLength) {
|
|
50
|
+
const bytes = new Uint8Array(byteLength);
|
|
51
|
+
const handle = await open(path, "r");
|
|
52
|
+
try {
|
|
53
|
+
await handle.read(bytes, 0, byteLength, 0);
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
await handle.close();
|
|
57
|
+
}
|
|
58
|
+
return bytes;
|
|
59
|
+
}
|
|
60
|
+
export async function readFileBytes(path) {
|
|
61
|
+
return await readFile(path);
|
|
62
|
+
}
|
|
63
|
+
export function readFileChunks(path, chunkBytes, signal) {
|
|
64
|
+
return createReadStream(path, { highWaterMark: chunkBytes, signal });
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=local-files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-files.js","sourceRoot":"","sources":["../../../src/storage/files/local-files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAe,MAAM,SAAS,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAoBlF,SAAS,SAAS,CAAC,KAAa;IAC5B,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;QACtB,OAAO,WAAW,CAAC;IACvB,CAAC;IACD,IAAI,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC;QACjB,OAAO,MAAM,CAAC;IAClB,CAAC;IACD,IAAI,KAAK,CAAC,cAAc,EAAE,EAAE,CAAC;QACzB,OAAO,eAAe,CAAC;IAC3B,CAAC;IACD,IAAI,KAAK,CAAC,aAAa,EAAE,IAAI,KAAK,CAAC,iBAAiB,EAAE,EAAE,CAAC;QACrD,OAAO,QAAQ,CAAC;IACpB,CAAC;IACD,IAAI,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC;QACjB,OAAO,MAAM,CAAC;IAClB,CAAC;IACD,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;AACnD,CAAC;AAED,+FAA+F;AAC/F,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,IAAY;IAC5C,OAAO,MAAM,QAAQ,CAAC,IAAI,CAAC,CAAC;AAChC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,IAAY;IAC/C,MAAM,QAAQ,G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EAAE,UAAkB;IAChE,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC;IACzC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACrC,IAAI,CAAC;QACD,MAAM,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;IAC/C,CAAC;YAAS,CAAC;QACP,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,IAAY;IAC5C,OAAO,MAAM,QAAQ,CAAC,IAAI,CAAC,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,IAAY,EAAE,UAAkB,EAAE,MAAmB;IAChF,OAAO,gBAAgB,CAAC,IAAI,EAAE,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,CAAC;AACzE,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type ExistingFileWrite = {
|
|
2
|
+
readonly kind: "written";
|
|
3
|
+
} | {
|
|
4
|
+
readonly kind: "missing";
|
|
5
|
+
readonly cause: unknown;
|
|
6
|
+
} | {
|
|
7
|
+
readonly kind: "unwritable";
|
|
8
|
+
readonly cause: unknown;
|
|
9
|
+
} | {
|
|
10
|
+
readonly kind: "not-a-file";
|
|
11
|
+
};
|
|
12
|
+
/** Replaces the content of an existing regular file, refusing to follow a symbolic link at `path`. */
|
|
13
|
+
export declare function writeExistingFile(path: string, content: string, signal: AbortSignal): Promise<ExistingFileWrite>;
|
|
14
|
+
//# sourceMappingURL=output-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output-file.d.ts","sourceRoot":"","sources":["../../../src/storage/files/output-file.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,iBAAiB,GACvB;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;CAAE,GAC5B;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GACrD;IAAE,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GACxD;IAAE,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAA;CAAE,CAAC;AAEtC,sGAAsG;AACtG,wBAAsB,iBAAiB,CACnC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,WAAW,GACpB,OAAO,CAAC,iBAAiB,CAAC,CAmB5B"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { constants } from "node:fs";
|
|
2
|
+
import { open } from "node:fs/promises";
|
|
3
|
+
import { isNodeError } from "../../util/node-error.js";
|
|
4
|
+
/** Replaces the content of an existing regular file, refusing to follow a symbolic link at `path`. */
|
|
5
|
+
export async function writeExistingFile(path, content, signal) {
|
|
6
|
+
let file;
|
|
7
|
+
try {
|
|
8
|
+
file = await open(path, constants.O_WRONLY | constants.O_NOFOLLOW);
|
|
9
|
+
}
|
|
10
|
+
catch (cause) {
|
|
11
|
+
return isNodeError(cause, "ENOENT") ? { kind: "missing", cause } : { kind: "unwritable", cause };
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
const metadata = await file.stat();
|
|
15
|
+
if (!metadata.isFile()) {
|
|
16
|
+
return { kind: "not-a-file" };
|
|
17
|
+
}
|
|
18
|
+
signal.throwIfAborted();
|
|
19
|
+
await file.truncate(0);
|
|
20
|
+
await file.writeFile(content, "utf8");
|
|
21
|
+
return { kind: "written" };
|
|
22
|
+
}
|
|
23
|
+
finally {
|
|
24
|
+
await file.close();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=output-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|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* A private directory that one process owns under a shared parent. The owner refreshes its lease, so
|
|
3
|
+
* any owner can remove the directories a crashed process left behind without touching a running one.
|
|
4
|
+
*/
|
|
5
|
+
export declare class ScratchDirectory {
|
|
6
|
+
#private;
|
|
7
|
+
constructor(parent: string);
|
|
8
|
+
/** Refreshes this directory's lease and removes sibling directories whose lease is older than `leaseMilliseconds`. */
|
|
9
|
+
readonly refreshLease: (leaseMilliseconds: number) => Promise<void>;
|
|
10
|
+
/** Writes `bytes` atomically to `<group>/<name>` with owner-only permissions and returns the path. */
|
|
11
|
+
readonly write: (group: string, name: string, bytes: Uint8Array, signal: AbortSignal) => Promise<string>;
|
|
12
|
+
readonly remove: (path: string) => Promise<void>;
|
|
13
|
+
/** The canonical path of a written file, or null when it is gone, is not a regular file, or escapes its directory. */
|
|
14
|
+
readonly resolveFile: (path: string) => Promise<string | null>;
|
|
15
|
+
readonly removeAll: () => Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=scratch-directory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scratch-directory.d.ts","sourceRoot":"","sources":["../../../src/storage/files/scratch-directory.ts"],"names":[],"mappings":"AAeA;;;GAGG;AACH,qBAAa,gBAAgB;;IAGzB,YAAY,MAAM,EAAE,MAAM,EAEzB;IAED,sHAAsH;IACtH,QAAQ,CAAC,YAAY,sBAA6B,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC,CAqBtE;IAEF,sGAAsG;IACtG,QAAQ,CAAC,KAAK,UAAiB,MAAM,QAAQ,MAAM,SAAS,UAAU,UAAU,WAAW,KAAG,OAAO,CAAC,MAAM,CAAC,CAO3G;IAEF,QAAQ,CAAC,MAAM,SAAgB,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC,CAEnD;IAEF,sHAAsH;IACtH,QAAQ,CAAC,WAAW,SAAgB,MAAM,KAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAajE;IAEF,QAAQ,CAAC,SAAS,QAAa,OAAO,CAAC,IAAI,CAAC,CAE1C;CACL"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { lstat, mkdir, readdir, realpath, rename, rm, stat, utimes, writeFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
async function atomicWrite(path, bytes, signal) {
|
|
5
|
+
const temporary = `${path}.${randomUUID()}.tmp`;
|
|
6
|
+
try {
|
|
7
|
+
await writeFile(temporary, bytes, { mode: 0o600, signal });
|
|
8
|
+
signal.throwIfAborted();
|
|
9
|
+
await rename(temporary, path);
|
|
10
|
+
}
|
|
11
|
+
finally {
|
|
12
|
+
await rm(temporary, { force: true });
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A private directory that one process owns under a shared parent. The owner refreshes its lease, so
|
|
17
|
+
* any owner can remove the directories a crashed process left behind without touching a running one.
|
|
18
|
+
*/
|
|
19
|
+
export class ScratchDirectory {
|
|
20
|
+
#root;
|
|
21
|
+
constructor(parent) {
|
|
22
|
+
this.#root = join(parent, randomUUID());
|
|
23
|
+
}
|
|
24
|
+
/** Refreshes this directory's lease and removes sibling directories whose lease is older than `leaseMilliseconds`. */
|
|
25
|
+
refreshLease = async (leaseMilliseconds) => {
|
|
26
|
+
await mkdir(this.#root, { mode: 0o700, recursive: true });
|
|
27
|
+
const now = new Date();
|
|
28
|
+
await utimes(this.#root, now, now);
|
|
29
|
+
for (const directory of await readdir(dirname(this.#root), { withFileTypes: true })) {
|
|
30
|
+
if (!directory.isDirectory() || !/^[a-f0-9-]{36}$/u.test(directory.name)) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const path = join(dirname(this.#root), directory.name);
|
|
34
|
+
if (path === this.#root) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
// Another process may remove its own directory during this scan.
|
|
38
|
+
const modified = await stat(path).then((entry) => entry.mtimeMs, () => Date.now());
|
|
39
|
+
if (modified + leaseMilliseconds <= Date.now()) {
|
|
40
|
+
await rm(path, { force: true, recursive: true });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
/** Writes `bytes` atomically to `<group>/<name>` with owner-only permissions and returns the path. */
|
|
45
|
+
write = async (group, name, bytes, signal) => {
|
|
46
|
+
const directory = join(this.#root, group);
|
|
47
|
+
await mkdir(directory, { mode: 0o700, recursive: true });
|
|
48
|
+
signal.throwIfAborted();
|
|
49
|
+
const path = join(directory, name);
|
|
50
|
+
await atomicWrite(path, bytes, signal);
|
|
51
|
+
return path;
|
|
52
|
+
};
|
|
53
|
+
remove = async (path) => {
|
|
54
|
+
await rm(path, { force: true });
|
|
55
|
+
};
|
|
56
|
+
/** The canonical path of a written file, or null when it is gone, is not a regular file, or escapes its directory. */
|
|
57
|
+
resolveFile = async (path) => {
|
|
58
|
+
try {
|
|
59
|
+
const [resolvedDirectory, resolvedPath, file] = await Promise.all([
|
|
60
|
+
realpath(dirname(path)),
|
|
61
|
+
realpath(path),
|
|
62
|
+
lstat(path),
|
|
63
|
+
]);
|
|
64
|
+
return file.isFile() && !file.isSymbolicLink() && dirname(resolvedPath) === resolvedDirectory
|
|
65
|
+
? resolvedPath
|
|
66
|
+
: null;
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
removeAll = async () => {
|
|
73
|
+
await rm(this.#root, { force: true, recursive: true });
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=scratch-directory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scratch-directory.js","sourceRoot":"","sources":["../../../src/storage/files/scratch-directory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ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;IAEO,MAAM,GAAG,KAAK,EAAE,IAAY,EAAiB,EAAE;QACpD,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACpC,CAAC,CAAC;IAEF,sHAAsH;IAC7G,WAAW,GAAG,KAAK,EAAE,IAAY,EAA0B,EAAE;QAClE,IAAI,CAAC;YACD,MAAM,CAAC,iBAAiB,EAAE,YAAY,EAAE,IAAI,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;gBAC9D,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;gBACvB,QAAQ,CAAC,IAAI,CAAC;gBACd,KAAK,CAAC,IAAI,CAAC;aACd,CAAC,CAAC;YACH,OAAO,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,IAAI,OAAO,CAAC,YAAY,CAAC,KAAK,iBAAiB;gBACzF,CAAC,CAAC,YAAY;gBACd,CAAC,CAAC,IAAI,CAAC;QACf,CAAC;QAAC,MAAM,CAAC;YACL,OAAO,IAAI,CAAC;QAChB,CAAC;IACL,CAAC,CAAC;IAEO,SAAS,GAAG,KAAK,IAAmB,EAAE;QAC3C,MAAM,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3D,CAAC,CAAC;CACL"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare function applicationDirectory(root: string, applicationId: string): string;
|
|
2
|
+
export declare function installationPointerPath(applicationDirectory: string): string;
|
|
3
|
+
export declare function installationDirectory(applicationDirectory: string, installationId: string): string;
|
|
4
|
+
export declare function connectionDirectory(installationDirectory: string): string;
|
|
5
|
+
export declare function connectionFilePath(connectionDirectory: string, connectionId: string): string;
|
|
6
|
+
/** Channel index files are named by a hash, so a channel ID never becomes part of a path. */
|
|
7
|
+
export declare function channelIndexFilePath(installationDirectory: string, channelId: string): string;
|
|
8
|
+
export type InstallationFileRead = {
|
|
9
|
+
readonly kind: "read";
|
|
10
|
+
readonly text: string;
|
|
11
|
+
} | {
|
|
12
|
+
readonly kind: "missing";
|
|
13
|
+
readonly cause: unknown;
|
|
14
|
+
} | {
|
|
15
|
+
readonly kind: "unopenable";
|
|
16
|
+
readonly cause: unknown;
|
|
17
|
+
} | {
|
|
18
|
+
readonly kind: "not-a-small-file";
|
|
19
|
+
};
|
|
20
|
+
/** Reads a small regular file. Errors after the file is open propagate. */
|
|
21
|
+
export declare function readInstallationFile(path: string): Promise<InstallationFileRead>;
|
|
22
|
+
/** Replaces a file atomically with owner-only permissions, creating its directory when it is missing. */
|
|
23
|
+
export declare function writeInstallationFile(path: string, text: string, signal: AbortSignal): Promise<void>;
|
|
24
|
+
/** Creates a file with owner-only permissions. Fails with `EEXIST` when it already exists. */
|
|
25
|
+
export declare function createInstallationFile(path: string, text: string): Promise<void>;
|
|
26
|
+
export declare function listInstallationFiles(directory: string): Promise<readonly string[]>;
|
|
27
|
+
export declare function removeInstallationFile(path: string): Promise<void>;
|
|
28
|
+
//# sourceMappingURL=installation-files.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"installation-files.d.ts","sourceRoot":"","sources":["../../../src/storage/installation/installation-files.ts"],"names":[],"mappings":"AAWA,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,CAEhF;AAED,wBAAgB,uBAAuB,CAAC,oBAAoB,EAAE,MAAM,GAAG,MAAM,CAE5E;AAED,wBAAgB,qBAAqB,CAAC,oBAAoB,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,CAElG;AAED,wBAAgB,mBAAmB,CAAC,qBAAqB,EAAE,MAAM,GAAG,MAAM,CAEzE;AAED,wBAAgB,kBAAkB,CAAC,mBAAmB,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAE5F;AAED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