@jini-ai/sidecar 0.7.2 → 0.7.3-next.1
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/CHANGELOG.md +1 -8
- package/dist/daemon-registry.d.ts +7 -5
- package/dist/daemon-registry.js +5 -5
- package/dist/index.d.ts +1 -1
- package/dist/ipc-path.d.ts +2 -2
- package/dist/ipc-path.js +2 -2
- package/dist/json-file.d.ts +11 -7
- package/dist/json-file.js +7 -8
- package/dist/json-ipc.d.ts +1 -18
- package/dist/json-ipc.js +11 -35
- package/dist/net.d.ts +7 -2
- package/dist/net.js +2 -2
- package/dist/paths.d.ts +11 -11
- package/dist/paths.js +11 -11
- package/dist/port.js +4 -4
- package/dist/supervision/child-entries.d.ts +85 -0
- package/dist/supervision/child-entries.js +139 -0
- package/dist/supervision/child-exit-signal.d.ts +21 -0
- package/dist/supervision/child-exit-signal.js +24 -0
- package/dist/supervision/child-orphans.d.ts +37 -0
- package/dist/supervision/child-orphans.js +48 -0
- package/dist/supervision/child-process-inspection.d.ts +29 -0
- package/dist/supervision/child-process-inspection.js +32 -0
- package/dist/supervision/child-readiness.d.ts +57 -0
- package/dist/supervision/child-readiness.js +83 -0
- package/dist/supervision/child-registry.d.ts +98 -0
- package/dist/supervision/child-registry.js +118 -0
- package/dist/supervision/child-stop.d.ts +39 -0
- package/dist/supervision/child-stop.js +81 -0
- package/dist/supervision/child-transitions.d.ts +54 -0
- package/dist/supervision/child-transitions.js +62 -0
- package/dist/supervision/keyed-serializer.d.ts +29 -0
- package/dist/supervision/keyed-serializer.js +50 -0
- package/dist/supervision/supervisor-node.d.ts +29 -11
- package/dist/supervision/supervisor-node.js +40 -29
- package/dist/supervision/supervisor.d.ts +3 -0
- package/dist/supervision/supervisor.js +312 -276
- package/package.json +4 -5
- package/dist/respawn-policy.d.ts +0 -51
- package/dist/respawn-policy.js +0 -46
- package/dist/supervisor-node.d.ts +0 -71
- package/dist/supervisor-node.js +0 -120
- package/dist/supervisor.d.ts +0 -108
- package/dist/supervisor.js +0 -178
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
# @jini-ai/sidecar
|
|
2
2
|
|
|
3
|
-
## 0.7.2
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- @jini-ai/core@0.7.2
|
|
8
|
-
- @jini-ai/platform@0.7.2
|
|
9
|
-
|
|
10
3
|
## 0.7.1
|
|
11
4
|
|
|
12
5
|
### Patch Changes
|
|
@@ -94,7 +87,7 @@
|
|
|
94
87
|
|
|
95
88
|
### Patch Changes
|
|
96
89
|
|
|
97
|
-
-
|
|
90
|
+
- Host clean-up release (2026-10-08): code the first host moved into Jini, plus the Jini clean-up (see the commit log since 0.4.0).
|
|
98
91
|
|
|
99
92
|
## 0.4.0 — 2026-10-02
|
|
100
93
|
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* existing module in this package needed before. Depends on `node:path` and this package's
|
|
12
12
|
* own `json-file.ts`.
|
|
13
13
|
*/
|
|
14
|
+
import { type JsonFileWriter } from "./json-file.js";
|
|
14
15
|
/** A running local daemon's discoverable identity: where it listens and which process owns it. */
|
|
15
16
|
export interface LocalDaemonRegistryRecord {
|
|
16
17
|
/** The daemon's real, resolved base URL (e.g. `http://127.0.0.1:54213`). */
|
|
@@ -44,10 +45,11 @@ export declare function resolveDaemonRegistryPath({ dataDir }: {
|
|
|
44
45
|
* at `registryPath`. Safe under concurrent writers — the last writer to complete its rename wins,
|
|
45
46
|
* and every reader only ever observes a fully-written file, never a partial one.
|
|
46
47
|
*/
|
|
47
|
-
export declare function writeDaemonRegistryRecord({ registryPath, record }: {
|
|
48
|
+
export declare function writeDaemonRegistryRecord({ registryPath, record, writer }: {
|
|
48
49
|
registryPath: string;
|
|
49
50
|
record: LocalDaemonRegistryRecord;
|
|
50
|
-
|
|
51
|
+
writer: JsonFileWriter;
|
|
52
|
+
}, _optional?: Record<string, never>): Promise<void>;
|
|
51
53
|
/** The two path moves `removeDaemonRegistryRecordIfCurrent` makes; injectable so a race lost to
|
|
52
54
|
* another remover, or a refused restore, can be reproduced without a real filesystem race. */
|
|
53
55
|
export interface DaemonRegistryFilePorts {
|
|
@@ -82,11 +84,11 @@ export declare function removeDaemonRegistryRecordIfCurrent({ registryPath, pid
|
|
|
82
84
|
*/
|
|
83
85
|
export declare function isProcessAlive({ pid }: {
|
|
84
86
|
pid: number;
|
|
85
|
-
}): boolean;
|
|
87
|
+
}, _optional?: Record<string, never>): boolean;
|
|
86
88
|
/**
|
|
87
89
|
* Read a daemon's registry record at `registryPath` and return it only if it is well-formed AND
|
|
88
90
|
* its recorded `pid` is still alive — the combined "read, don't just trust" discovery primitive a
|
|
89
|
-
* CLI-side `resolveDaemonUrl({}, { discover })` probe needs. A stale record from a daemon that crashed
|
|
91
|
+
* CLI-side `resolveDaemonUrl({ env }, { discover })` probe needs. A stale record from a daemon that crashed
|
|
90
92
|
* (pid no longer alive), a missing file, or a malformed/foreign JSON file all resolve to `null`
|
|
91
93
|
* rather than throwing — discovery failing is an expected, non-exceptional outcome (the caller
|
|
92
94
|
* falls through to its own `defaultUrl`/error, per `resolveDaemonUrl`'s own contract).
|
|
@@ -94,5 +96,5 @@ export declare function isProcessAlive({ pid }: {
|
|
|
94
96
|
*/
|
|
95
97
|
export declare function readLiveDaemonRegistryRecord({ registryPath }: {
|
|
96
98
|
registryPath: string;
|
|
97
|
-
}): Promise<LocalDaemonRegistryRecord | null>;
|
|
99
|
+
}, _optional?: Record<string, never>): Promise<LocalDaemonRegistryRecord | null>;
|
|
98
100
|
//# sourceMappingURL=daemon-registry.d.ts.map
|
package/dist/daemon-registry.js
CHANGED
|
@@ -38,8 +38,8 @@ export function resolveDaemonRegistryPath({ dataDir }, { fileName = DEFAULT_DAEM
|
|
|
38
38
|
* at `registryPath`. Safe under concurrent writers — the last writer to complete its rename wins,
|
|
39
39
|
* and every reader only ever observes a fully-written file, never a partial one.
|
|
40
40
|
*/
|
|
41
|
-
export async function writeDaemonRegistryRecord({ registryPath, record }) {
|
|
42
|
-
await writeJsonFile({ filePath: registryPath, payload: record });
|
|
41
|
+
export async function writeDaemonRegistryRecord({ registryPath, record, writer }, _optional = {}) {
|
|
42
|
+
await writeJsonFile({ filePath: registryPath, payload: record, writer });
|
|
43
43
|
}
|
|
44
44
|
const DEFAULT_REGISTRY_FILE_PORTS = { rename, link };
|
|
45
45
|
/** Moves the public record aside; `false` when another remover already detached it (ENOENT). */
|
|
@@ -98,7 +98,7 @@ export async function removeDaemonRegistryRecordIfCurrent({ registryPath, pid },
|
|
|
98
98
|
* discovery purposes). `false` for a non-positive/non-integer `pid`, a `pid` that does not exist
|
|
99
99
|
* (`ESRCH`), or any other unexpected failure (treated conservatively as not confirmed alive).
|
|
100
100
|
*/
|
|
101
|
-
export function isProcessAlive({ pid }) {
|
|
101
|
+
export function isProcessAlive({ pid }, _optional = {}) {
|
|
102
102
|
if (!Number.isInteger(pid) || pid <= 0)
|
|
103
103
|
return false;
|
|
104
104
|
try {
|
|
@@ -130,13 +130,13 @@ function isValidRegistryRecord(value) {
|
|
|
130
130
|
/**
|
|
131
131
|
* Read a daemon's registry record at `registryPath` and return it only if it is well-formed AND
|
|
132
132
|
* its recorded `pid` is still alive — the combined "read, don't just trust" discovery primitive a
|
|
133
|
-
* CLI-side `resolveDaemonUrl({}, { discover })` probe needs. A stale record from a daemon that crashed
|
|
133
|
+
* CLI-side `resolveDaemonUrl({ env }, { discover })` probe needs. A stale record from a daemon that crashed
|
|
134
134
|
* (pid no longer alive), a missing file, or a malformed/foreign JSON file all resolve to `null`
|
|
135
135
|
* rather than throwing — discovery failing is an expected, non-exceptional outcome (the caller
|
|
136
136
|
* falls through to its own `defaultUrl`/error, per `resolveDaemonUrl`'s own contract).
|
|
137
137
|
* @returns The live record, or `null` when nothing live was found.
|
|
138
138
|
*/
|
|
139
|
-
export async function readLiveDaemonRegistryRecord({ registryPath }) {
|
|
139
|
+
export async function readLiveDaemonRegistryRecord({ registryPath }, _optional = {}) {
|
|
140
140
|
const record = await readJsonFile({ filePath: registryPath });
|
|
141
141
|
if (!isValidRegistryRecord(record))
|
|
142
142
|
return null;
|
package/dist/index.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export { isWindowsNamedPipePath, normalizeIpcPath } from "./ipc-path.js";
|
|
|
14
14
|
export { resolveAppIpcPath, resolveAppRuntimeDir, resolveAppRuntimePath, resolveLogFilePath, resolveLogsDir, resolveManifestPath, resolveNamespace, resolveNamespaceRoot, resolvePointerPath, resolveProjectRoot, resolveProjectTmpRoot, resolveRuntimeNamespaceRoot, resolveRuntimeRoot, resolveSidecarBase, resolveSourceRuntimeRoot, } from "./paths.js";
|
|
15
15
|
export { bootstrapSidecarRuntime, createSidecarLaunchEnv } from "./bootstrap.js";
|
|
16
16
|
export { allocatePort } from "./port.js";
|
|
17
|
-
export { readJsonFile, removeFile, removePointerIfCurrent, writeJsonFile } from "./json-file.js";
|
|
17
|
+
export { readJsonFile, removeFile, removePointerIfCurrent, writeJsonFile, type JsonFileWriter } from "./json-file.js";
|
|
18
18
|
export { createJsonIpcServer, requestJsonIpc } from "./json-ipc.js";
|
|
19
19
|
export type { LocalDaemonRegistryRecord } from "./daemon-registry.js";
|
|
20
20
|
export { isProcessAlive, readLiveDaemonRegistryRecord, removeDaemonRegistryRecordIfCurrent, resolveDaemonRegistryPath, writeDaemonRegistryRecord, } from "./daemon-registry.js";
|
package/dist/ipc-path.d.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
export declare function isWindowsNamedPipePath({ value }: {
|
|
13
13
|
value: unknown;
|
|
14
|
-
}): boolean;
|
|
14
|
+
}, _optional?: Record<string, never>): boolean;
|
|
15
15
|
/**
|
|
16
16
|
* Validate and return an IPC path: a Windows named pipe is accepted as-is, and
|
|
17
17
|
* any other value must be a non-empty, un-padded, null-byte-free absolute path.
|
|
@@ -19,5 +19,5 @@ export declare function isWindowsNamedPipePath({ value }: {
|
|
|
19
19
|
*/
|
|
20
20
|
export declare function normalizeIpcPath({ ipc }: {
|
|
21
21
|
ipc: unknown;
|
|
22
|
-
}): string;
|
|
22
|
+
}, _optional?: Record<string, never>): string;
|
|
23
23
|
//# sourceMappingURL=ipc-path.d.ts.map
|
package/dist/ipc-path.js
CHANGED
|
@@ -10,7 +10,7 @@ import { isAbsolute } from "node:path";
|
|
|
10
10
|
* Detect whether a value is a Windows named-pipe path (`\\.\pipe\...`).
|
|
11
11
|
* @returns `true` when `value` is such a pipe path.
|
|
12
12
|
*/
|
|
13
|
-
export function isWindowsNamedPipePath({ value }) {
|
|
13
|
+
export function isWindowsNamedPipePath({ value }, _optional = {}) {
|
|
14
14
|
return typeof value === "string" && value.startsWith("\\\\.\\pipe\\");
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
@@ -18,7 +18,7 @@ export function isWindowsNamedPipePath({ value }) {
|
|
|
18
18
|
* any other value must be a non-empty, un-padded, null-byte-free absolute path.
|
|
19
19
|
* @returns The validated IPC path.
|
|
20
20
|
*/
|
|
21
|
-
export function normalizeIpcPath({ ipc }) {
|
|
21
|
+
export function normalizeIpcPath({ ipc }, _optional = {}) {
|
|
22
22
|
if (typeof ipc !== "string")
|
|
23
23
|
throw new Error("sidecar ipc path must be a string");
|
|
24
24
|
if (ipc.length === 0)
|
package/dist/json-file.d.ts
CHANGED
|
@@ -4,36 +4,40 @@
|
|
|
4
4
|
* Small JSON file helpers for sidecar runtime state: a forgiving reader (null on
|
|
5
5
|
* any failure), an atomic pretty-printed writer via temp-file rename, a
|
|
6
6
|
* best-effort remove, and a guarded pointer removal that only deletes when the
|
|
7
|
-
* pointer still names the given run. Depends on `node:fs/promises
|
|
8
|
-
*
|
|
7
|
+
* pointer still names the given run. Depends on `node:fs/promises`; the atomic
|
|
8
|
+
* writer (replacement and durability) is the host's, passed as `writer`.
|
|
9
9
|
*/
|
|
10
|
+
import type { AtomicFileWriterPort } from "@jini-ai/core/contracts/runtime";
|
|
11
|
+
/** The host's atomic JSON writer (Node hosts pass `nodeAtomicWriter` of `@jini-ai/node-adapters/fs`). */
|
|
12
|
+
export type JsonFileWriter = Pick<AtomicFileWriterPort, "writeJson">;
|
|
10
13
|
/**
|
|
11
14
|
* Read and parse a JSON file, swallowing any read/parse error.
|
|
12
15
|
* @returns The parsed value, or `null` if missing or unreadable.
|
|
13
16
|
*/
|
|
14
17
|
export declare function readJsonFile<T = any>({ filePath }: {
|
|
15
18
|
filePath: string;
|
|
16
|
-
}): Promise<T | null>;
|
|
19
|
+
}, _optional?: Record<string, never>): Promise<T | null>;
|
|
17
20
|
/**
|
|
18
21
|
* Atomically write `payload` as pretty-printed JSON via a temp-file rename,
|
|
19
22
|
* creating the parent directory if needed. Existing modes are preserved; file bytes
|
|
20
23
|
* are synced before rename and the parent directory afterward. Sync failures propagate.
|
|
21
24
|
*/
|
|
22
|
-
export declare function writeJsonFile({ filePath, payload }: {
|
|
25
|
+
export declare function writeJsonFile({ filePath, payload, writer }: {
|
|
23
26
|
filePath: string;
|
|
24
27
|
payload: unknown;
|
|
25
|
-
|
|
28
|
+
writer: JsonFileWriter;
|
|
29
|
+
}, _optional?: Record<string, never>): Promise<void>;
|
|
26
30
|
/**
|
|
27
31
|
* Remove a file, forcing (no error if absent).
|
|
28
32
|
*/
|
|
29
33
|
export declare function removeFile({ filePath }: {
|
|
30
34
|
filePath: string;
|
|
31
|
-
}): Promise<void>;
|
|
35
|
+
}, _optional?: Record<string, never>): Promise<void>;
|
|
32
36
|
/**
|
|
33
37
|
* Remove a pointer file only if it still points at `runId`.
|
|
34
38
|
*/
|
|
35
39
|
export declare function removePointerIfCurrent({ pointerPath, runId }: {
|
|
36
40
|
pointerPath: string;
|
|
37
41
|
runId: string;
|
|
38
|
-
}): Promise<void>;
|
|
42
|
+
}, _optional?: Record<string, never>): Promise<void>;
|
|
39
43
|
//# sourceMappingURL=json-file.d.ts.map
|
package/dist/json-file.js
CHANGED
|
@@ -4,17 +4,16 @@
|
|
|
4
4
|
* Small JSON file helpers for sidecar runtime state: a forgiving reader (null on
|
|
5
5
|
* any failure), an atomic pretty-printed writer via temp-file rename, a
|
|
6
6
|
* best-effort remove, and a guarded pointer removal that only deletes when the
|
|
7
|
-
* pointer still names the given run. Depends on `node:fs/promises
|
|
8
|
-
*
|
|
7
|
+
* pointer still names the given run. Depends on `node:fs/promises`; the atomic
|
|
8
|
+
* writer (replacement and durability) is the host's, passed as `writer`.
|
|
9
9
|
*/
|
|
10
10
|
import { randomUUID } from "node:crypto";
|
|
11
11
|
import { readFile, rm } from "node:fs/promises";
|
|
12
|
-
import { writeJsonFileAtomicAsync } from "@jini-ai/platform/fs";
|
|
13
12
|
/**
|
|
14
13
|
* Read and parse a JSON file, swallowing any read/parse error.
|
|
15
14
|
* @returns The parsed value, or `null` if missing or unreadable.
|
|
16
15
|
*/
|
|
17
|
-
export async function readJsonFile({ filePath }) {
|
|
16
|
+
export async function readJsonFile({ filePath }, _optional = {}) {
|
|
18
17
|
try {
|
|
19
18
|
return JSON.parse(await readFile(filePath, "utf8"));
|
|
20
19
|
}
|
|
@@ -27,8 +26,8 @@ export async function readJsonFile({ filePath }) {
|
|
|
27
26
|
* creating the parent directory if needed. Existing modes are preserved; file bytes
|
|
28
27
|
* are synced before rename and the parent directory afterward. Sync failures propagate.
|
|
29
28
|
*/
|
|
30
|
-
export async function writeJsonFile({ filePath, payload }) {
|
|
31
|
-
await
|
|
29
|
+
export async function writeJsonFile({ filePath, payload, writer }, _optional = {}) {
|
|
30
|
+
await writer.writeJson({ filePath, data: payload }, {
|
|
32
31
|
createParent: true, trailingNewline: true, defaultMode: 0o666 & ~process.umask(),
|
|
33
32
|
tempPath: () => `${filePath}.${process.pid}.${randomUUID()}.tmp`,
|
|
34
33
|
});
|
|
@@ -36,13 +35,13 @@ export async function writeJsonFile({ filePath, payload }) {
|
|
|
36
35
|
/**
|
|
37
36
|
* Remove a file, forcing (no error if absent).
|
|
38
37
|
*/
|
|
39
|
-
export async function removeFile({ filePath }) {
|
|
38
|
+
export async function removeFile({ filePath }, _optional = {}) {
|
|
40
39
|
await rm(filePath, { force: true });
|
|
41
40
|
}
|
|
42
41
|
/**
|
|
43
42
|
* Remove a pointer file only if it still points at `runId`.
|
|
44
43
|
*/
|
|
45
|
-
export async function removePointerIfCurrent({ pointerPath, runId }) {
|
|
44
|
+
export async function removePointerIfCurrent({ pointerPath, runId }, _optional = {}) {
|
|
46
45
|
const pointer = await readJsonFile({ filePath: pointerPath });
|
|
47
46
|
if (pointer?.runId === runId)
|
|
48
47
|
await removeFile({ filePath: pointerPath });
|
package/dist/json-ipc.d.ts
CHANGED
|
@@ -11,23 +11,6 @@
|
|
|
11
11
|
* the IPC-path recognizer, and the public IPC types.
|
|
12
12
|
*/
|
|
13
13
|
import type { JsonIpcHandler, JsonIpcServerHandle } from "./types.js";
|
|
14
|
-
/**
|
|
15
|
-
* Shape an unknown error into the `{code?,message}` IPC error payload.
|
|
16
|
-
*
|
|
17
|
-
* Exported (previously module-private) for direct unit testing: its only
|
|
18
|
-
* current caller (a `JSON.parse` frame-parse failure) always passes a
|
|
19
|
-
* codeless `SyntaxError`, so the `code`-present branch below is real,
|
|
20
|
-
* generically useful behavior (any future caller with a Node-style errno
|
|
21
|
-
* error benefits from it) with no in-tree caller that happens to have one in
|
|
22
|
-
* hand today — matching this repo's "extract into a directly-testable pure
|
|
23
|
-
* function" convention rather than narrowing the type away.
|
|
24
|
-
*/
|
|
25
|
-
export declare function jsonIpcError({ error }: {
|
|
26
|
-
error: unknown;
|
|
27
|
-
}): {
|
|
28
|
-
code?: string;
|
|
29
|
-
message: string;
|
|
30
|
-
};
|
|
31
14
|
/**
|
|
32
15
|
* Prepare a socket path for binding: ensure the parent dir exists and
|
|
33
16
|
* unlink a stale socket (no-op for Windows named pipes).
|
|
@@ -42,7 +25,7 @@ export declare function jsonIpcError({ error }: {
|
|
|
42
25
|
*/
|
|
43
26
|
export declare function prepareIpcPath({ socketPath }: {
|
|
44
27
|
socketPath: string;
|
|
45
|
-
}): Promise<void>;
|
|
28
|
+
}, _optional?: Record<string, never>): Promise<void>;
|
|
46
29
|
/**
|
|
47
30
|
* Start a newline-delimited JSON IPC server on a unix socket / named pipe: each
|
|
48
31
|
* connection carries one JSON request, the handler's result is written back as
|
package/dist/json-ipc.js
CHANGED
|
@@ -10,12 +10,13 @@
|
|
|
10
10
|
* `node:net`, `node:path`, `node:string_decoder`, the shared net close helper,
|
|
11
11
|
* the IPC-path recognizer, and the public IPC types.
|
|
12
12
|
*/
|
|
13
|
+
import { createConsoleLogger } from '@jini-ai/core/primitives';
|
|
13
14
|
import { lstat, mkdir, rm } from "node:fs/promises";
|
|
14
15
|
import { createConnection } from "node:net";
|
|
15
16
|
import { createServer as createNetServer } from "node:net";
|
|
16
17
|
import { dirname } from "node:path";
|
|
17
18
|
import { StringDecoder } from "node:string_decoder";
|
|
18
|
-
import {
|
|
19
|
+
import { describeErrorForLog } from "@jini-ai/core";
|
|
19
20
|
import { isWindowsNamedPipePath } from "./ipc-path.js";
|
|
20
21
|
import { closeServer } from "./net.js";
|
|
21
22
|
/** Default cap on one connection's single frame (SEC-004): bytes received before a newline
|
|
@@ -82,29 +83,6 @@ function errorCode(error) {
|
|
|
82
83
|
const code = error.code;
|
|
83
84
|
return code == null ? null : String(code);
|
|
84
85
|
}
|
|
85
|
-
/**
|
|
86
|
-
* @internal Extract a human-readable message from an unknown thrown value.
|
|
87
|
-
*/
|
|
88
|
-
function errorMessage(error) {
|
|
89
|
-
return error instanceof Error ? error.message : String(error);
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Shape an unknown error into the `{code?,message}` IPC error payload.
|
|
93
|
-
*
|
|
94
|
-
* Exported (previously module-private) for direct unit testing: its only
|
|
95
|
-
* current caller (a `JSON.parse` frame-parse failure) always passes a
|
|
96
|
-
* codeless `SyntaxError`, so the `code`-present branch below is real,
|
|
97
|
-
* generically useful behavior (any future caller with a Node-style errno
|
|
98
|
-
* error benefits from it) with no in-tree caller that happens to have one in
|
|
99
|
-
* hand today — matching this repo's "extract into a directly-testable pure
|
|
100
|
-
* function" convention rather than narrowing the type away.
|
|
101
|
-
*/
|
|
102
|
-
export function jsonIpcError({ error }) {
|
|
103
|
-
return {
|
|
104
|
-
...(errorCode(error) == null ? {} : { code: errorCode(error) }),
|
|
105
|
-
message: errorMessage(error),
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
86
|
/**
|
|
109
87
|
* @internal Decide whether a unix socket path is a stale (dead) endpoint safe to
|
|
110
88
|
* unlink: it exists as a socket but refuses/ENOENTs on connect.
|
|
@@ -160,7 +138,7 @@ async function staleUnixSocketExists(socketPath) {
|
|
|
160
138
|
* Windows. Testing this function directly (asserting no filesystem call
|
|
161
139
|
* happens) verifies the real behavior on every platform this runs on.
|
|
162
140
|
*/
|
|
163
|
-
export async function prepareIpcPath({ socketPath }) {
|
|
141
|
+
export async function prepareIpcPath({ socketPath }, _optional = {}) {
|
|
164
142
|
if (isWindowsNamedPipePath({ value: socketPath }))
|
|
165
143
|
return;
|
|
166
144
|
await mkdir(dirname(socketPath), { recursive: true });
|
|
@@ -231,7 +209,7 @@ export async function createJsonIpcServer({ handler, socketPath, }, { maxFrameBy
|
|
|
231
209
|
// behavior (see archived provenance ledger's 2026-07-22 entry).
|
|
232
210
|
traceJsonIpc("server.socket_error", {
|
|
233
211
|
durationMs: jsonIpcTraceDurationMs(startedAt),
|
|
234
|
-
error:
|
|
212
|
+
error: describeErrorForLog({ err: error }),
|
|
235
213
|
socketPath,
|
|
236
214
|
traceId,
|
|
237
215
|
});
|
|
@@ -289,14 +267,14 @@ export async function createJsonIpcServer({ handler, socketPath, }, { maxFrameBy
|
|
|
289
267
|
// archived provenance ledger's 2026-07-22 entry).
|
|
290
268
|
traceJsonIpc("server.frame_parse_failed", {
|
|
291
269
|
durationMs: jsonIpcTraceDurationMs(startedAt),
|
|
292
|
-
error:
|
|
270
|
+
error: describeErrorForLog({ err: error }),
|
|
293
271
|
frameBytes: Buffer.byteLength(frame),
|
|
294
272
|
socketPath,
|
|
295
273
|
traceId,
|
|
296
274
|
});
|
|
297
275
|
socket.end(`${JSON.stringify({
|
|
298
276
|
ok: false,
|
|
299
|
-
error:
|
|
277
|
+
error: { code: "BAD_FRAME", message: "The sidecar could not read the request frame. Send one line of valid JSON." },
|
|
300
278
|
})}\n`);
|
|
301
279
|
return;
|
|
302
280
|
}
|
|
@@ -327,14 +305,12 @@ export async function createJsonIpcServer({ handler, socketPath, }, { maxFrameBy
|
|
|
327
305
|
catch (error) {
|
|
328
306
|
// SEC-004: a handler failure can embed paths, credentials, or other host detail (the
|
|
329
307
|
// same trust-boundary concern as SEC-005's HTTP fix). The peer gets a stable code plus
|
|
330
|
-
// the traceId as a correlation handle; the
|
|
308
|
+
// the traceId as a correlation handle; the error's class and code are logged
|
|
331
309
|
// server-side only, unconditionally (not gated behind JINI_JSON_IPC_TRACE).
|
|
332
|
-
|
|
333
|
-
// eslint-disable-next-line no-console
|
|
334
|
-
console.error(`[@jini-ai/sidecar] json-ipc handler failed (traceId=${traceId})`, redactedDetail);
|
|
310
|
+
createConsoleLogger({ prefix: '' }).error({ message: `[@jini-ai/sidecar] json-ipc handler failed (traceId=${traceId})` }, { error });
|
|
335
311
|
traceJsonIpc("server.handler_failed", {
|
|
336
312
|
durationMs: jsonIpcTraceDurationMs(startedAt),
|
|
337
|
-
error:
|
|
313
|
+
error: describeErrorForLog({ err: error }),
|
|
338
314
|
message: messageSummary,
|
|
339
315
|
socketPath,
|
|
340
316
|
traceId,
|
|
@@ -355,7 +331,7 @@ export async function createJsonIpcServer({ handler, socketPath, }, { maxFrameBy
|
|
|
355
331
|
});
|
|
356
332
|
return {
|
|
357
333
|
async close() {
|
|
358
|
-
await closeServer(server);
|
|
334
|
+
await closeServer({ server });
|
|
359
335
|
if (!isWindowsNamedPipePath({ value: socketPath }))
|
|
360
336
|
await rm(socketPath, { force: true });
|
|
361
337
|
},
|
|
@@ -480,7 +456,7 @@ export async function requestJsonIpc({ socketPath, payload }, { timeoutMs = 1500
|
|
|
480
456
|
// comment + archived provenance ledger's 2026-07-22 entry).
|
|
481
457
|
traceJsonIpc("client.socket_error", {
|
|
482
458
|
durationMs: jsonIpcTraceDurationMs(startedAt),
|
|
483
|
-
error:
|
|
459
|
+
error: describeErrorForLog({ err: error }),
|
|
484
460
|
message: messageSummary,
|
|
485
461
|
socketPath,
|
|
486
462
|
traceId,
|
package/dist/net.d.ts
CHANGED
|
@@ -10,10 +10,15 @@ import { type Server } from "node:net";
|
|
|
10
10
|
* @internal Close a listening server, resolving once closed (no-op if not
|
|
11
11
|
* listening).
|
|
12
12
|
*/
|
|
13
|
-
export declare function closeServer(server
|
|
13
|
+
export declare function closeServer({ server }: {
|
|
14
|
+
server: Server;
|
|
15
|
+
}, _optional?: Record<string, never>): Promise<void>;
|
|
14
16
|
/**
|
|
15
17
|
* @internal Start an exclusive TCP server on the given port/host, resolving with
|
|
16
18
|
* the listening server.
|
|
17
19
|
*/
|
|
18
|
-
export declare function listenOnPort(port
|
|
20
|
+
export declare function listenOnPort({ port, host }: {
|
|
21
|
+
port: number;
|
|
22
|
+
host: string;
|
|
23
|
+
}, _optional?: Record<string, never>): Promise<Server>;
|
|
19
24
|
//# sourceMappingURL=net.d.ts.map
|
package/dist/net.js
CHANGED
|
@@ -10,7 +10,7 @@ import { createServer as createNetServer } from "node:net";
|
|
|
10
10
|
* @internal Close a listening server, resolving once closed (no-op if not
|
|
11
11
|
* listening).
|
|
12
12
|
*/
|
|
13
|
-
export async function closeServer(server) {
|
|
13
|
+
export async function closeServer({ server }, _optional = {}) {
|
|
14
14
|
if (!server.listening)
|
|
15
15
|
return;
|
|
16
16
|
await new Promise((resolveClose, rejectClose) => {
|
|
@@ -21,7 +21,7 @@ export async function closeServer(server) {
|
|
|
21
21
|
* @internal Start an exclusive TCP server on the given port/host, resolving with
|
|
22
22
|
* the listening server.
|
|
23
23
|
*/
|
|
24
|
-
export async function listenOnPort(port, host) {
|
|
24
|
+
export async function listenOnPort({ port, host }, _optional = {}) {
|
|
25
25
|
const server = createNetServer();
|
|
26
26
|
await new Promise((resolveListen, rejectListen) => {
|
|
27
27
|
server.once("error", rejectListen);
|
package/dist/paths.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export declare function resolveNamespace<TStamp extends SidecarStampShape>({ con
|
|
|
21
21
|
*/
|
|
22
22
|
export declare function resolveProjectRoot({ projectRoot }: {
|
|
23
23
|
projectRoot: string;
|
|
24
|
-
}): string;
|
|
24
|
+
}, _optional?: Record<string, never>): string;
|
|
25
25
|
/**
|
|
26
26
|
* Resolve the project's tmp root (`<projectRoot>/<projectTmpDirName>`).
|
|
27
27
|
* @returns The resolved tmp root path.
|
|
@@ -29,12 +29,12 @@ export declare function resolveProjectRoot({ projectRoot }: {
|
|
|
29
29
|
export declare function resolveProjectTmpRoot<TStamp extends SidecarStampShape>({ contract, projectRoot, }: {
|
|
30
30
|
contract: SidecarContractDescriptor<TStamp>;
|
|
31
31
|
projectRoot: string;
|
|
32
|
-
}): string;
|
|
32
|
+
}, _optional?: Record<string, never>): string;
|
|
33
33
|
/**
|
|
34
34
|
* Resolve the source-scoped runtime root (`<projectTmpRoot>/<source>`).
|
|
35
35
|
* @returns The resolved source runtime root path.
|
|
36
36
|
*/
|
|
37
|
-
export declare function resolveSourceRuntimeRoot<TStamp extends SidecarStampShape>({ contract, projectRoot, source, }: ProjectRuntimePathRequest<TStamp>): string;
|
|
37
|
+
export declare function resolveSourceRuntimeRoot<TStamp extends SidecarStampShape>({ contract, projectRoot, source, }: ProjectRuntimePathRequest<TStamp>, _optional?: Record<string, never>): string;
|
|
38
38
|
/**
|
|
39
39
|
* Resolve the sidecar base from an explicit value, the env var named by the
|
|
40
40
|
* contract, or the source runtime root.
|
|
@@ -45,7 +45,7 @@ export declare function resolveSidecarBase<TStamp extends SidecarStampShape>({ c
|
|
|
45
45
|
* Resolve the namespace root (`<base>/<namespace>`).
|
|
46
46
|
* @returns The resolved namespace root path.
|
|
47
47
|
*/
|
|
48
|
-
export declare function resolveNamespaceRoot<TStamp extends SidecarStampShape>({ base, contract, namespace, }: RuntimePathRequest<TStamp>): string;
|
|
48
|
+
export declare function resolveNamespaceRoot<TStamp extends SidecarStampShape>({ base, contract, namespace, }: RuntimePathRequest<TStamp>, _optional?: Record<string, never>): string;
|
|
49
49
|
/**
|
|
50
50
|
* Resolve the namespace root (the directory that holds `logs/`, `runs/`,
|
|
51
51
|
* `current.json`, …) from a *live* {@link SidecarRuntimeContext}.
|
|
@@ -74,24 +74,24 @@ export declare function resolveRuntimeNamespaceRoot<TStamp extends SidecarStampS
|
|
|
74
74
|
contract: SidecarContractDescriptor<TStamp>;
|
|
75
75
|
runtime: Pick<SidecarRuntimeContext<TStamp>, "base" | "mode" | "namespace">;
|
|
76
76
|
runtimeMode: TStamp["mode"] | string;
|
|
77
|
-
}): string;
|
|
77
|
+
}, _optional?: Record<string, never>): string;
|
|
78
78
|
/**
|
|
79
79
|
* Resolve a per-run runtime root (`<namespaceRoot>/runs/<runId>`).
|
|
80
80
|
* @returns The resolved run runtime root path.
|
|
81
81
|
*/
|
|
82
|
-
export declare function resolveRuntimeRoot<TStamp extends SidecarStampShape>({ base, contract, namespace, runId, }: RuntimeRootRequest<TStamp>): string;
|
|
82
|
+
export declare function resolveRuntimeRoot<TStamp extends SidecarStampShape>({ base, contract, namespace, runId, }: RuntimeRootRequest<TStamp>, _optional?: Record<string, never>): string;
|
|
83
83
|
/**
|
|
84
84
|
* Resolve the namespace pointer file (`<namespaceRoot>/current.json`).
|
|
85
85
|
* @returns The resolved pointer path.
|
|
86
86
|
*/
|
|
87
|
-
export declare function resolvePointerPath<TStamp extends SidecarStampShape>({ base, contract, namespace }: RuntimePathRequest<TStamp>): string;
|
|
87
|
+
export declare function resolvePointerPath<TStamp extends SidecarStampShape>({ base, contract, namespace }: RuntimePathRequest<TStamp>, _optional?: Record<string, never>): string;
|
|
88
88
|
/**
|
|
89
89
|
* Resolve a run's manifest file (`<runtimeRoot>/manifest.json`).
|
|
90
90
|
* @returns The resolved manifest path.
|
|
91
91
|
*/
|
|
92
92
|
export declare function resolveManifestPath({ runtimeRoot }: {
|
|
93
93
|
runtimeRoot: string;
|
|
94
|
-
}): string;
|
|
94
|
+
}, _optional?: Record<string, never>): string;
|
|
95
95
|
/**
|
|
96
96
|
* Resolve an app's logs directory (`<runtimeRoot>/logs/<app>`).
|
|
97
97
|
* @returns The resolved logs directory path.
|
|
@@ -100,7 +100,7 @@ export declare function resolveLogsDir<TStamp extends SidecarStampShape>({ app,
|
|
|
100
100
|
app: TStamp["app"] | string;
|
|
101
101
|
contract: SidecarContractDescriptor<TStamp>;
|
|
102
102
|
runtimeRoot: string;
|
|
103
|
-
}): string;
|
|
103
|
+
}, _optional?: Record<string, never>): string;
|
|
104
104
|
/**
|
|
105
105
|
* Resolve an app's log file (`<logsDir>/<fileName>`, default `latest.log`).
|
|
106
106
|
* @returns The resolved log file path.
|
|
@@ -116,14 +116,14 @@ export declare function resolveLogFilePath<TStamp extends SidecarStampShape>({ a
|
|
|
116
116
|
* Resolve an app's runtime dir under a namespace root (`<namespaceRoot>/<app>`).
|
|
117
117
|
* @returns The resolved app runtime directory path.
|
|
118
118
|
*/
|
|
119
|
-
export declare function resolveAppRuntimeDir<TStamp extends SidecarStampShape>({ app, contract, namespaceRoot, }: AppRuntimePathRequest<TStamp>): string;
|
|
119
|
+
export declare function resolveAppRuntimeDir<TStamp extends SidecarStampShape>({ app, contract, namespaceRoot, }: AppRuntimePathRequest<TStamp>, _optional?: Record<string, never>): string;
|
|
120
120
|
/**
|
|
121
121
|
* Resolve a file inside an app's runtime dir, rejecting non-simple file names.
|
|
122
122
|
* @returns The resolved app runtime file path.
|
|
123
123
|
*/
|
|
124
124
|
export declare function resolveAppRuntimePath<TStamp extends SidecarStampShape>({ app, contract, fileName, namespaceRoot, }: AppRuntimePathRequest<TStamp> & {
|
|
125
125
|
fileName: string;
|
|
126
|
-
}): string;
|
|
126
|
+
}, _optional?: Record<string, never>): string;
|
|
127
127
|
/**
|
|
128
128
|
* Resolve an app's IPC endpoint: a Windows named pipe, or a unix socket under
|
|
129
129
|
* `<ipcBase>/<namespace>/<app>.sock`.
|
package/dist/paths.js
CHANGED
|
@@ -23,7 +23,7 @@ export function resolveNamespace({ contract }, options = {}) {
|
|
|
23
23
|
* Validate and resolve a project root to an absolute path.
|
|
24
24
|
* @returns The resolved absolute project root.
|
|
25
25
|
*/
|
|
26
|
-
export function resolveProjectRoot({ projectRoot }) {
|
|
26
|
+
export function resolveProjectRoot({ projectRoot }, _optional = {}) {
|
|
27
27
|
if (typeof projectRoot !== "string" || projectRoot.trim().length === 0) {
|
|
28
28
|
throw new Error("projectRoot must be a non-empty string");
|
|
29
29
|
}
|
|
@@ -33,14 +33,14 @@ export function resolveProjectRoot({ projectRoot }) {
|
|
|
33
33
|
* Resolve the project's tmp root (`<projectRoot>/<projectTmpDirName>`).
|
|
34
34
|
* @returns The resolved tmp root path.
|
|
35
35
|
*/
|
|
36
|
-
export function resolveProjectTmpRoot({ contract, projectRoot, }) {
|
|
36
|
+
export function resolveProjectTmpRoot({ contract, projectRoot, }, _optional = {}) {
|
|
37
37
|
return join(resolveProjectRoot({ projectRoot }), contract.defaults.projectTmpDirName);
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
40
|
* Resolve the source-scoped runtime root (`<projectTmpRoot>/<source>`).
|
|
41
41
|
* @returns The resolved source runtime root path.
|
|
42
42
|
*/
|
|
43
|
-
export function resolveSourceRuntimeRoot({ contract, projectRoot, source, }) {
|
|
43
|
+
export function resolveSourceRuntimeRoot({ contract, projectRoot, source, }, _optional = {}) {
|
|
44
44
|
return join(resolveProjectTmpRoot({ contract, projectRoot }), contract.normalizeSource({ source }));
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
@@ -55,7 +55,7 @@ export function resolveSidecarBase({ contract, source, }, { base, env = process.
|
|
|
55
55
|
* Resolve the namespace root (`<base>/<namespace>`).
|
|
56
56
|
* @returns The resolved namespace root path.
|
|
57
57
|
*/
|
|
58
|
-
export function resolveNamespaceRoot({ base, contract, namespace, }) {
|
|
58
|
+
export function resolveNamespaceRoot({ base, contract, namespace, }, _optional = {}) {
|
|
59
59
|
return join(resolve(base), contract.normalizeNamespace({ namespace }));
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
@@ -82,7 +82,7 @@ export function resolveNamespaceRoot({ base, contract, namespace, }) {
|
|
|
82
82
|
* `SIDECAR_MODES.RUNTIME`) so this generic helper does not have to hardcode
|
|
83
83
|
* the host product's mode strings.
|
|
84
84
|
*/
|
|
85
|
-
export function resolveRuntimeNamespaceRoot({ contract, runtime, runtimeMode, }) {
|
|
85
|
+
export function resolveRuntimeNamespaceRoot({ contract, runtime, runtimeMode, }, _optional = {}) {
|
|
86
86
|
if (runtime.mode === runtimeMode) {
|
|
87
87
|
// packaged: `base` already points INTO the namespace tree
|
|
88
88
|
// (`<namespaceRoot>/runtime`), so the namespace root is its parent.
|
|
@@ -95,28 +95,28 @@ export function resolveRuntimeNamespaceRoot({ contract, runtime, runtimeMode, })
|
|
|
95
95
|
* Resolve a per-run runtime root (`<namespaceRoot>/runs/<runId>`).
|
|
96
96
|
* @returns The resolved run runtime root path.
|
|
97
97
|
*/
|
|
98
|
-
export function resolveRuntimeRoot({ base, contract, namespace, runId, }) {
|
|
98
|
+
export function resolveRuntimeRoot({ base, contract, namespace, runId, }, _optional = {}) {
|
|
99
99
|
return join(resolveNamespaceRoot({ base, contract, namespace }), "runs", runId);
|
|
100
100
|
}
|
|
101
101
|
/**
|
|
102
102
|
* Resolve the namespace pointer file (`<namespaceRoot>/current.json`).
|
|
103
103
|
* @returns The resolved pointer path.
|
|
104
104
|
*/
|
|
105
|
-
export function resolvePointerPath({ base, contract, namespace }) {
|
|
105
|
+
export function resolvePointerPath({ base, contract, namespace }, _optional = {}) {
|
|
106
106
|
return join(resolveNamespaceRoot({ base, contract, namespace }), "current.json");
|
|
107
107
|
}
|
|
108
108
|
/**
|
|
109
109
|
* Resolve a run's manifest file (`<runtimeRoot>/manifest.json`).
|
|
110
110
|
* @returns The resolved manifest path.
|
|
111
111
|
*/
|
|
112
|
-
export function resolveManifestPath({ runtimeRoot }) {
|
|
112
|
+
export function resolveManifestPath({ runtimeRoot }, _optional = {}) {
|
|
113
113
|
return join(runtimeRoot, "manifest.json");
|
|
114
114
|
}
|
|
115
115
|
/**
|
|
116
116
|
* Resolve an app's logs directory (`<runtimeRoot>/logs/<app>`).
|
|
117
117
|
* @returns The resolved logs directory path.
|
|
118
118
|
*/
|
|
119
|
-
export function resolveLogsDir({ app, contract, runtimeRoot, }) {
|
|
119
|
+
export function resolveLogsDir({ app, contract, runtimeRoot, }, _optional = {}) {
|
|
120
120
|
return join(runtimeRoot, "logs", contract.normalizeApp({ app }));
|
|
121
121
|
}
|
|
122
122
|
/**
|
|
@@ -130,14 +130,14 @@ export function resolveLogFilePath({ app, contract, runtimeRoot, }, { fileName =
|
|
|
130
130
|
* Resolve an app's runtime dir under a namespace root (`<namespaceRoot>/<app>`).
|
|
131
131
|
* @returns The resolved app runtime directory path.
|
|
132
132
|
*/
|
|
133
|
-
export function resolveAppRuntimeDir({ app, contract, namespaceRoot, }) {
|
|
133
|
+
export function resolveAppRuntimeDir({ app, contract, namespaceRoot, }, _optional = {}) {
|
|
134
134
|
return join(namespaceRoot, contract.normalizeApp({ app }));
|
|
135
135
|
}
|
|
136
136
|
/**
|
|
137
137
|
* Resolve a file inside an app's runtime dir, rejecting non-simple file names.
|
|
138
138
|
* @returns The resolved app runtime file path.
|
|
139
139
|
*/
|
|
140
|
-
export function resolveAppRuntimePath({ app, contract, fileName, namespaceRoot, }) {
|
|
140
|
+
export function resolveAppRuntimePath({ app, contract, fileName, namespaceRoot, }, _optional = {}) {
|
|
141
141
|
if (fileName.length === 0 || fileName.includes("\0") || /[\\/]/.test(fileName)) {
|
|
142
142
|
throw new Error(`app runtime fileName must be a simple path segment: ${fileName}`);
|
|
143
143
|
}
|
package/dist/port.js
CHANGED
|
@@ -43,14 +43,14 @@ async function allocateForcedPort(port, label, host, reserved) {
|
|
|
43
43
|
}
|
|
44
44
|
let server = null;
|
|
45
45
|
try {
|
|
46
|
-
server = await listenOnPort(port, host);
|
|
46
|
+
server = await listenOnPort({ port, host });
|
|
47
47
|
}
|
|
48
48
|
catch (error) {
|
|
49
49
|
throw new Error(`forced ${label} port ${port} is not available (${errorCode(error) ?? errorMessage(error)})`);
|
|
50
50
|
}
|
|
51
51
|
finally {
|
|
52
52
|
if (server)
|
|
53
|
-
await closeServer(server);
|
|
53
|
+
await closeServer({ server });
|
|
54
54
|
}
|
|
55
55
|
reserved.add(port);
|
|
56
56
|
return { port, source: "forced" };
|
|
@@ -60,9 +60,9 @@ async function allocateForcedPort(port, label, host, reserved) {
|
|
|
60
60
|
* hands back whatever port it currently considers free.
|
|
61
61
|
*/
|
|
62
62
|
async function probeEphemeralPort({ host }) {
|
|
63
|
-
const server = await listenOnPort(0, host);
|
|
63
|
+
const server = await listenOnPort({ port: 0, host });
|
|
64
64
|
const address = server.address();
|
|
65
|
-
await closeServer(server);
|
|
65
|
+
await closeServer({ server });
|
|
66
66
|
if (address == null || typeof address === "string") {
|
|
67
67
|
throw new Error("failed to probe an ephemeral port");
|
|
68
68
|
}
|