@jini-ai/sidecar 0.1.2 → 0.3.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.
Files changed (2) hide show
  1. package/README.md +106 -0
  2. package/package.json +5 -4
package/README.md ADDED
@@ -0,0 +1,106 @@
1
+ # `@jini-ai/sidecar`
2
+
3
+ Process-runtime plumbing for an application that runs a long-lived helper process ("sidecar") next
4
+ to a shell or CLI. It answers the boring-but-load-bearing questions such a setup keeps asking: where
5
+ does this app's runtime directory live, what IPC socket path is safe on this platform, which TCP
6
+ port can I bind, how does the child validate the stamp its parent launched it with, and how does an
7
+ unrelated process later find the daemon that is already running. Nothing here starts an HTTP server
8
+ or knows what your sidecar actually does — it is the filesystem/IPC/port layer underneath that.
9
+
10
+ ## Install
11
+
12
+ ```sh
13
+ npm install @jini-ai/sidecar
14
+ ```
15
+
16
+ No peer dependencies. Its one dependency is `@jini-ai/core` (installed automatically); everything
17
+ else it uses is a Node built-in.
18
+
19
+ ## What you get
20
+
21
+ **Path resolution** — a namespace/project-scoped layout resolved from a caller-supplied
22
+ `SidecarContractDescriptor` (its env-var names, defaults, and normalizers) rather than from
23
+ hardcoded product constants: `resolveNamespace`, `resolveNamespaceRoot`, `resolveRuntimeRoot`,
24
+ `resolveRuntimeNamespaceRoot`, `resolveSourceRuntimeRoot`, `resolveProjectRoot`,
25
+ `resolveProjectTmpRoot`, `resolveSidecarBase`, `resolveAppRuntimeDir`, `resolveAppRuntimePath`,
26
+ `resolveLogsDir`, `resolveLogFilePath`, `resolveManifestPath`, `resolvePointerPath`.
27
+
28
+ **IPC paths** — `normalizeIpcPath` and `isWindowsNamedPipePath` (Windows named pipes vs. Unix
29
+ domain sockets), plus `resolveAppIpcPath` for the app-scoped socket path.
30
+
31
+ **JSON IPC** — `createJsonIpcServer({ socketPath, handler, maxFrameBytes, idleTimeoutMs })` and
32
+ `requestJsonIpc(socketPath, payload, { timeoutMs })`: a newline-delimited JSON request/response
33
+ channel over a local socket, with a per-frame byte cap and an idle-connection timeout.
34
+
35
+ **Port allocation** — `allocatePort({ host, label, port, reserved })`, which either honors a forced
36
+ port or finds a free dynamic one, returning `{ port, source: 'dynamic' | 'forced' }`.
37
+
38
+ **Launch and bootstrap** — `createSidecarLaunchEnv` (parent side: build the child's environment) and
39
+ `bootstrapSidecarRuntime(stamp, env, options)` (child side: validate the stamp against the expected
40
+ app via the injected contract and return a `SidecarRuntimeContext`). A stamp mismatch throws rather
41
+ than starting a sidecar that belongs to a different app.
42
+
43
+ **Local daemon registry** — a `dataDir`-scoped pointer file recording a running daemon's
44
+ URL/host/port/pid/start time, plus liveness checking: `resolveDaemonRegistryPath(dataDir)`,
45
+ `writeDaemonRegistryRecord`, `readLiveDaemonRegistryRecord` (returns `null` when the recorded pid is
46
+ gone), `removeDaemonRegistryRecordIfCurrent`, `isProcessAlive`.
47
+
48
+ **JSON file helpers** — `readJsonFile`, `writeJsonFile`, `removeFile`, `removePointerIfCurrent`.
49
+
50
+ ## Usage
51
+
52
+ ```ts
53
+ import {
54
+ allocatePort,
55
+ createJsonIpcServer,
56
+ requestJsonIpc,
57
+ resolveDaemonRegistryPath,
58
+ readLiveDaemonRegistryRecord,
59
+ writeDaemonRegistryRecord,
60
+ type LocalDaemonRegistryRecord,
61
+ } from '@jini-ai/sidecar';
62
+
63
+ const { port } = await allocatePort({ host: '127.0.0.1', label: 'daemon' });
64
+
65
+ const registryPath = resolveDaemonRegistryPath('/var/lib/example');
66
+ const record: LocalDaemonRegistryRecord = {
67
+ url: `http://127.0.0.1:${port}`,
68
+ host: '127.0.0.1',
69
+ port,
70
+ pid: process.pid,
71
+ startedAt: new Date().toISOString(),
72
+ };
73
+ await writeDaemonRegistryRecord(registryPath, record);
74
+
75
+ // Any other process, later — `null` when nothing is actually running.
76
+ const live = await readLiveDaemonRegistryRecord(registryPath);
77
+
78
+ const ipc = await createJsonIpcServer({
79
+ socketPath: '/tmp/example/daemon.sock',
80
+ handler: async (message) => ({ echo: message }),
81
+ });
82
+ const reply = await requestJsonIpc<{ echo: unknown }>('/tmp/example/daemon.sock', { ping: true });
83
+ await ipc.close();
84
+ ```
85
+
86
+ The path resolvers each additionally take a `contract: SidecarContractDescriptor` describing your
87
+ app's env-var names and defaults — see `src/types.ts` for its shape before wiring those up.
88
+
89
+ ## What's swappable
90
+
91
+ `SidecarContractDescriptor` is the seam, and it is why this package carries no product strings: your
92
+ app supplies its own env-var names, path defaults, and `normalizeStamp`/`normalizeApp`/
93
+ `normalizeNamespace` functions, and every path resolver plus `bootstrapSidecarRuntime` reads them
94
+ from there. `createJsonIpcServer` takes the message handler and its two safety bounds. Everything
95
+ else (socket framing, port probing, the registry record's field set and its pid-guarded removal) is
96
+ fixed concrete behavior with no injection point.
97
+
98
+ ## Runtime
99
+
100
+ `jini.runtime: "node"` — uses `node:net`, `node:fs`, `node:os`, and `process`.
101
+ ESM only — ships `"type": "module"` with no CommonJS `require` build.
102
+
103
+ ## Provenance
104
+
105
+ See [source-map.md](./source-map.md) for per-file provenance and scope decisions. Apache-2.0,
106
+ inherited from Open Design — see the repo `NOTICE`.
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@jini-ai/sidecar",
3
- "version": "0.1.2",
3
+ "version": "0.3.0",
4
+ "description": "Sidecar process runtime: JSON-IPC server and client, IPC path validation, namespace/runtime path resolution, port allocation, launch bootstrap, and a local daemon registry.",
4
5
  "license": "Apache-2.0",
5
6
  "repository": {
6
7
  "type": "git",
@@ -10,10 +11,10 @@
10
11
  "jini": {
11
12
  "domain": "platform",
12
13
  "kind": "process-bridge",
13
- "runtime": "node",
14
- "admission": "locked"
14
+ "runtime": "node"
15
15
  },
16
16
  "type": "module",
17
+ "sideEffects": false,
17
18
  "main": "./dist/index.js",
18
19
  "types": "./dist/index.d.ts",
19
20
  "exports": {
@@ -36,7 +37,7 @@
36
37
  "registry": "https://registry.npmjs.org"
37
38
  },
38
39
  "dependencies": {
39
- "@jini-ai/core": "0.1.2"
40
+ "@jini-ai/core": "0.3.0"
40
41
  },
41
42
  "devDependencies": {
42
43
  "@vitest/coverage-v8": "^2.1.9"