@jini-ai/sidecar 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Support. While redistributing the Work or
166
+ Derivative Works thereof, You may choose to offer, and charge a
167
+ fee for, acceptance of support, warranty, indemnity, or other
168
+ liability obligations and/or rights consistent with this License.
169
+ However, in accepting such obligations, You may act only on Your
170
+ own behalf and on Your sole responsibility, not on behalf of any
171
+ other Contributor, and only if You agree to indemnify, defend,
172
+ and hold each Contributor harmless for any liability incurred by,
173
+ or claims asserted against, such Contributor by reason of your
174
+ accepting any such warranty or support.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Open Design contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @module bootstrap
3
+ *
4
+ * Sidecar launch-env composition and runtime bootstrap. `createSidecarLaunchEnv`
5
+ * builds the env a child sidecar is spawned with (base/ipc/namespace/source);
6
+ * `bootstrapSidecarRuntime` validates the incoming stamp against the resolved
7
+ * app/ipc/env, writes the canonical env back, and returns the live runtime
8
+ * context. Depends on the path resolvers and the public types.
9
+ */
10
+ import type { BootstrapSidecarRuntimeOptions, SidecarLaunchEnvRequest, SidecarRuntimeContext, SidecarStampShape } from "./types.js";
11
+ /**
12
+ * Compose the environment a child sidecar is launched with: the resolved base,
13
+ * the stamp's ipc path, namespace, and source, layered over `extraEnv`.
14
+ * @returns The launch environment.
15
+ */
16
+ export declare function createSidecarLaunchEnv<TStamp extends SidecarStampShape>({ base, contract, extraEnv, stamp, }: SidecarLaunchEnvRequest<TStamp>): NodeJS.ProcessEnv;
17
+ /**
18
+ * Bootstrap a sidecar runtime from an incoming stamp and env: validate app and
19
+ * ipc path, confirm no conflicting env, write the canonical env back, and return
20
+ * the resolved live runtime context.
21
+ * @returns The resolved {@link SidecarRuntimeContext}.
22
+ */
23
+ export declare function bootstrapSidecarRuntime<TStamp extends SidecarStampShape>(stampInput: unknown, env: NodeJS.ProcessEnv, options: BootstrapSidecarRuntimeOptions<TStamp>): SidecarRuntimeContext<TStamp>;
24
+ //# sourceMappingURL=bootstrap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EACV,8BAA8B,EAC9B,uBAAuB,EACvB,qBAAqB,EACrB,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAEpB;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,SAAS,iBAAiB,EAAE,EACvE,IAAI,EACJ,QAAQ,EACR,QAAsB,EACtB,KAAK,GACN,EAAE,uBAAuB,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,UAAU,CASrD;AAaD;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,SAAS,iBAAiB,EACtE,UAAU,EAAE,OAAO,EACnB,GAAG,EAAE,MAAM,CAAC,UAAU,EACtB,OAAO,EAAE,8BAA8B,CAAC,MAAM,CAAC,GAC9C,qBAAqB,CAAC,MAAM,CAAC,CAmC/B"}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * @module bootstrap
3
+ *
4
+ * Sidecar launch-env composition and runtime bootstrap. `createSidecarLaunchEnv`
5
+ * builds the env a child sidecar is spawned with (base/ipc/namespace/source);
6
+ * `bootstrapSidecarRuntime` validates the incoming stamp against the resolved
7
+ * app/ipc/env, writes the canonical env back, and returns the live runtime
8
+ * context. Depends on the path resolvers and the public types.
9
+ */
10
+ import { resolveAppIpcPath, resolveSidecarBase } from "./paths.js";
11
+ /**
12
+ * Compose the environment a child sidecar is launched with: the resolved base,
13
+ * the stamp's ipc path, namespace, and source, layered over `extraEnv`.
14
+ * @returns The launch environment.
15
+ */
16
+ export function createSidecarLaunchEnv({ base, contract, extraEnv = process.env, stamp, }) {
17
+ const normalizedStamp = contract.normalizeStamp(stamp);
18
+ return {
19
+ ...extraEnv,
20
+ [contract.env.base]: resolveSidecarBase({ base, contract, env: extraEnv, source: normalizedStamp.source }),
21
+ [contract.env.ipcPath]: normalizedStamp.ipc,
22
+ [contract.env.namespace]: normalizedStamp.namespace,
23
+ [contract.env.source]: normalizedStamp.source,
24
+ };
25
+ }
26
+ /**
27
+ * @internal Assert that an existing env value, if present, matches the expected
28
+ * canonical value.
29
+ */
30
+ function assertMatchingEnv(env, key, expected) {
31
+ const current = env[key];
32
+ if (current != null && current !== expected) {
33
+ throw new Error(`sidecar env mismatch for ${key}: expected ${expected}, received ${current}`);
34
+ }
35
+ }
36
+ /**
37
+ * Bootstrap a sidecar runtime from an incoming stamp and env: validate app and
38
+ * ipc path, confirm no conflicting env, write the canonical env back, and return
39
+ * the resolved live runtime context.
40
+ * @returns The resolved {@link SidecarRuntimeContext}.
41
+ */
42
+ export function bootstrapSidecarRuntime(stampInput, env, options) {
43
+ const stamp = options.contract.normalizeStamp(stampInput);
44
+ const expectedApp = options.contract.normalizeApp(options.app);
45
+ if (stamp.app !== expectedApp) {
46
+ throw new Error(`sidecar stamp app mismatch: expected ${expectedApp}, received ${stamp.app}`);
47
+ }
48
+ const base = resolveSidecarBase({
49
+ base: options.base ?? null,
50
+ contract: options.contract,
51
+ env,
52
+ ...(options.projectRoot === undefined ? {} : { projectRoot: options.projectRoot }),
53
+ source: stamp.source,
54
+ });
55
+ const ipc = resolveAppIpcPath({ app: stamp.app, contract: options.contract, env, namespace: stamp.namespace });
56
+ if (stamp.ipc !== ipc) {
57
+ throw new Error(`sidecar ipc path mismatch: expected ${ipc}, received ${stamp.ipc}`);
58
+ }
59
+ assertMatchingEnv(env, options.contract.env.ipcPath, stamp.ipc);
60
+ assertMatchingEnv(env, options.contract.env.namespace, stamp.namespace);
61
+ assertMatchingEnv(env, options.contract.env.source, stamp.source);
62
+ env[options.contract.env.ipcPath] = ipc;
63
+ env[options.contract.env.namespace] = stamp.namespace;
64
+ env[options.contract.env.source] = stamp.source;
65
+ return {
66
+ app: stamp.app,
67
+ base,
68
+ ipc,
69
+ mode: stamp.mode,
70
+ namespace: stamp.namespace,
71
+ source: stamp.source,
72
+ };
73
+ }
74
+ //# sourceMappingURL=bootstrap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,YA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AC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC;IACtD,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC;IAEhD,OAAO;QACL,GAAG,EAAE,KAAK,CAAC,GAAG;QACd,IAAI;QACJ,GAAG;QACH,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,MAAM,EAAE,KAAK,CAAC,MAAM;KACrB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * @module daemon-registry
3
+ *
4
+ * A local daemon "where am I listening" registry: a small, atomically-written JSON pointer
5
+ * file recording a running daemon's URL/host/port/pid, plus a liveness-checked reader so a
6
+ * separate process (e.g. a CLI invocation) can discover it without trusting a stale record
7
+ * left behind by a daemon that crashed rather than shutting down cleanly. Built on this
8
+ * package's own `json-file.ts` (atomic write, forgiving read, guarded pointer removal) — the
9
+ * exact primitives OD's sidecar already uses for its own `current.json` namespace pointer
10
+ * (see `paths.ts`'s `resolvePointerPath`) — plus a new `isProcessAlive` liveness probe no
11
+ * existing module in this package needed before. Depends on `node:path` and this package's
12
+ * own `json-file.ts`.
13
+ */
14
+ /** A running local daemon's discoverable identity: where it listens and which process owns it. */
15
+ export interface LocalDaemonRegistryRecord {
16
+ /** The daemon's real, resolved base URL (e.g. `http://127.0.0.1:54213`). */
17
+ readonly url: string;
18
+ /** The host the daemon is reachable on (already loopback-substituted — see `resolveReportHost`). */
19
+ readonly host: string;
20
+ /** The daemon's bound TCP port. */
21
+ readonly port: number;
22
+ /** The OS process id of the daemon process that wrote this record. */
23
+ readonly pid: number;
24
+ /** ISO-8601 timestamp of when the daemon started listening. */
25
+ readonly startedAt: string;
26
+ }
27
+ /**
28
+ * Resolve the on-disk path of a daemon's registry record, scoped to its `dataDir` by default —
29
+ * the same per-instance isolation `dataDir` already provides for `<dataDir>/events.db`, so two
30
+ * daemons on one machine (each with their own `dataDir`, already a hard requirement for two
31
+ * independent sqlite files) never collide on a single global registry path.
32
+ * @param dataDir - The daemon's own data directory (same value passed to `createLocalNodeDaemon`).
33
+ * @param fileName - Override the record's file name. Defaults to `daemon.json`.
34
+ * @returns The resolved absolute registry file path.
35
+ * @throws When `dataDir` is not a non-empty string.
36
+ */
37
+ export declare function resolveDaemonRegistryPath(dataDir: string, fileName?: string): string;
38
+ /**
39
+ * Durably (atomically, via `json-file.ts`'s temp-file-rename writer) record a daemon's identity
40
+ * at `registryPath`. Safe under concurrent writers — the last writer to complete its rename wins,
41
+ * and every reader only ever observes a fully-written file, never a partial one.
42
+ */
43
+ export declare function writeDaemonRegistryRecord(registryPath: string, record: LocalDaemonRegistryRecord): Promise<void>;
44
+ /**
45
+ * Remove a daemon's registry record at `registryPath`, but only if it still names `pid` as the
46
+ * owning process — the same guarded-removal shape `json-file.ts`'s `removePointerIfCurrent` uses
47
+ * for its own pointer file. Guards a fast crash-restart race on a reused `dataDir`: an old
48
+ * daemon's delayed shutdown cleanup must never delete a newer daemon's already-written record.
49
+ */
50
+ export declare function removeDaemonRegistryRecordIfCurrent(registryPath: string, pid: number): Promise<void>;
51
+ /**
52
+ * Probe whether OS process `pid` is currently alive, via `process.kill(pid, 0)` (sends no
53
+ * actual signal — `0` only tests deliverability). This is the liveness half of "verify, don't
54
+ * just trust the file": a registry record left behind by a daemon that crashed instead of
55
+ * shutting down cleanly must not be handed to a caller as if it were still reachable.
56
+ * @param pid - The process id to probe.
57
+ * @returns `true` when the process exists (either the signal-check succeeded, or it failed with
58
+ * `EPERM` — the process exists but this process lacks permission to signal it, still "alive" for
59
+ * discovery purposes). `false` for a non-positive/non-integer `pid`, a `pid` that does not exist
60
+ * (`ESRCH`), or any other unexpected failure (treated conservatively as not confirmed alive).
61
+ */
62
+ export declare function isProcessAlive(pid: number): boolean;
63
+ /**
64
+ * Read a daemon's registry record at `registryPath` and return it only if it is well-formed AND
65
+ * its recorded `pid` is still alive — the combined "read, don't just trust" discovery primitive a
66
+ * CLI-side `resolveDaemonUrl({ discover })` probe needs. A stale record from a daemon that crashed
67
+ * (pid no longer alive), a missing file, or a malformed/foreign JSON file all resolve to `null`
68
+ * rather than throwing — discovery failing is an expected, non-exceptional outcome (the caller
69
+ * falls through to its own `defaultUrl`/error, per `resolveDaemonUrl`'s own contract).
70
+ * @returns The live record, or `null` when nothing live was found.
71
+ */
72
+ export declare function readLiveDaemonRegistryRecord(registryPath: string): Promise<LocalDaemonRegistryRecord | null>;
73
+ //# sourceMappingURL=daemon-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"daemon-registry.d.ts","sourceRoot":"","sources":["../src/daemon-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AASH,kGAAkG;AAClG,MAAM,WAAW,yBAAyB;IACxC,4EAA4E;IAC5E,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,oGAAoG;IACpG,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,mCAAmC;IACnC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,sEAAsE;IACtE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,+DAA+D;IAC/D,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,GAAE,MAA0C,GAAG,MAAM,CAKvH;AAED;;;;GAIG;AACH,wBAAsB,yBAAyB,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,yBAAyB,GAAG,OAAO,CAAC,IAAI,CAAC,CAEtH;AAED;;;;;GAKG;AACH,wBAAsB,mCAAmC,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAG1G;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CASnD;AA0BD;;;;;;;;GAQG;AACH,wBAAsB,4BAA4B,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC,CAKlH"}
@@ -0,0 +1,115 @@
1
+ /**
2
+ * @module daemon-registry
3
+ *
4
+ * A local daemon "where am I listening" registry: a small, atomically-written JSON pointer
5
+ * file recording a running daemon's URL/host/port/pid, plus a liveness-checked reader so a
6
+ * separate process (e.g. a CLI invocation) can discover it without trusting a stale record
7
+ * left behind by a daemon that crashed rather than shutting down cleanly. Built on this
8
+ * package's own `json-file.ts` (atomic write, forgiving read, guarded pointer removal) — the
9
+ * exact primitives OD's sidecar already uses for its own `current.json` namespace pointer
10
+ * (see `paths.ts`'s `resolvePointerPath`) — plus a new `isProcessAlive` liveness probe no
11
+ * existing module in this package needed before. Depends on `node:path` and this package's
12
+ * own `json-file.ts`.
13
+ */
14
+ import { join, resolve } from "node:path";
15
+ import { readJsonFile, removeFile, writeJsonFile } from "./json-file.js";
16
+ /** Default file name for a daemon's registry record, resolved relative to its `dataDir`. */
17
+ const DEFAULT_DAEMON_REGISTRY_FILE_NAME = "daemon.json";
18
+ /**
19
+ * Resolve the on-disk path of a daemon's registry record, scoped to its `dataDir` by default —
20
+ * the same per-instance isolation `dataDir` already provides for `<dataDir>/events.db`, so two
21
+ * daemons on one machine (each with their own `dataDir`, already a hard requirement for two
22
+ * independent sqlite files) never collide on a single global registry path.
23
+ * @param dataDir - The daemon's own data directory (same value passed to `createLocalNodeDaemon`).
24
+ * @param fileName - Override the record's file name. Defaults to `daemon.json`.
25
+ * @returns The resolved absolute registry file path.
26
+ * @throws When `dataDir` is not a non-empty string.
27
+ */
28
+ export function resolveDaemonRegistryPath(dataDir, fileName = DEFAULT_DAEMON_REGISTRY_FILE_NAME) {
29
+ if (typeof dataDir !== "string" || dataDir.trim().length === 0) {
30
+ throw new Error("dataDir must be a non-empty string");
31
+ }
32
+ return join(resolve(dataDir), fileName);
33
+ }
34
+ /**
35
+ * Durably (atomically, via `json-file.ts`'s temp-file-rename writer) record a daemon's identity
36
+ * at `registryPath`. Safe under concurrent writers — the last writer to complete its rename wins,
37
+ * and every reader only ever observes a fully-written file, never a partial one.
38
+ */
39
+ export async function writeDaemonRegistryRecord(registryPath, record) {
40
+ await writeJsonFile(registryPath, record);
41
+ }
42
+ /**
43
+ * Remove a daemon's registry record at `registryPath`, but only if it still names `pid` as the
44
+ * owning process — the same guarded-removal shape `json-file.ts`'s `removePointerIfCurrent` uses
45
+ * for its own pointer file. Guards a fast crash-restart race on a reused `dataDir`: an old
46
+ * daemon's delayed shutdown cleanup must never delete a newer daemon's already-written record.
47
+ */
48
+ export async function removeDaemonRegistryRecordIfCurrent(registryPath, pid) {
49
+ const record = await readJsonFile(registryPath);
50
+ if (record?.pid === pid)
51
+ await removeFile(registryPath);
52
+ }
53
+ /**
54
+ * Probe whether OS process `pid` is currently alive, via `process.kill(pid, 0)` (sends no
55
+ * actual signal — `0` only tests deliverability). This is the liveness half of "verify, don't
56
+ * just trust the file": a registry record left behind by a daemon that crashed instead of
57
+ * shutting down cleanly must not be handed to a caller as if it were still reachable.
58
+ * @param pid - The process id to probe.
59
+ * @returns `true` when the process exists (either the signal-check succeeded, or it failed with
60
+ * `EPERM` — the process exists but this process lacks permission to signal it, still "alive" for
61
+ * discovery purposes). `false` for a non-positive/non-integer `pid`, a `pid` that does not exist
62
+ * (`ESRCH`), or any other unexpected failure (treated conservatively as not confirmed alive).
63
+ */
64
+ export function isProcessAlive(pid) {
65
+ if (!Number.isInteger(pid) || pid <= 0)
66
+ return false;
67
+ try {
68
+ process.kill(pid, 0);
69
+ return true;
70
+ }
71
+ catch (error) {
72
+ const code = error?.code;
73
+ return code === "EPERM";
74
+ }
75
+ }
76
+ /**
77
+ * @internal Structural + type validation for a value read back from a registry file — a
78
+ * cross-process JSON file is untrusted input (wrong version, hand-edited, truncated write from
79
+ * a process that was killed mid-write despite the atomic-rename writer, etc.).
80
+ */
81
+ function isValidRegistryRecord(value) {
82
+ if (value === null || typeof value !== "object")
83
+ return false;
84
+ const record = value;
85
+ return (typeof record.url === "string" &&
86
+ record.url.length > 0 &&
87
+ typeof record.host === "string" &&
88
+ record.host.length > 0 &&
89
+ typeof record.port === "number" &&
90
+ Number.isInteger(record.port) &&
91
+ record.port > 0 &&
92
+ typeof record.pid === "number" &&
93
+ Number.isInteger(record.pid) &&
94
+ record.pid > 0 &&
95
+ typeof record.startedAt === "string" &&
96
+ record.startedAt.length > 0);
97
+ }
98
+ /**
99
+ * Read a daemon's registry record at `registryPath` and return it only if it is well-formed AND
100
+ * its recorded `pid` is still alive — the combined "read, don't just trust" discovery primitive a
101
+ * CLI-side `resolveDaemonUrl({ discover })` probe needs. A stale record from a daemon that crashed
102
+ * (pid no longer alive), a missing file, or a malformed/foreign JSON file all resolve to `null`
103
+ * rather than throwing — discovery failing is an expected, non-exceptional outcome (the caller
104
+ * falls through to its own `defaultUrl`/error, per `resolveDaemonUrl`'s own contract).
105
+ * @returns The live record, or `null` when nothing live was found.
106
+ */
107
+ export async function readLiveDaemonRegistryRecord(registryPath) {
108
+ const record = await readJsonFile(registryPath);
109
+ if (!isValidRegistryRecord(record))
110
+ return null;
111
+ if (!isProcessAlive(record.pid))
112
+ return null;
113
+ return record;
114
+ }
115
+ //# sourceMappingURL=daemon-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"daemon-registry.js","sourceRoot":"","sources":["../src/daemon-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEzE,4FAA4F;AAC5F,MAAM,iCAAiC,GAAG,aAAa,CAAC;AAgBxD;;;;;;;;;GASG;AACH,MAAM,UAAU,y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MAAM,GAAG,KAA2C,CAAC;IAC3D,OAAO,CACL,OAAO,MAAM,CAAC,GAAG,KAAK,QAAQ;QAC9B,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC;QACrB,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ;QAC/B,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC;QACtB,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ;QAC/B,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC;QAC7B,MAAM,CAAC,IAAI,GAAG,CAAC;QACf,OAAO,MAAM,CAAC,GAAG,KAAK,QAAQ;QAC9B,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC;QAC5B,MAAM,CAAC,GAAG,GAAG,CAAC;QACd,OAAO,MAAM,CAAC,SAAS,KAAK,QAAQ;QACpC,MAAM,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAC5B,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,4BAA4B,CAAC,YAAoB;IACrE,MAAM,MAAM,GAAG,MAAM,YAAY,CAAU,YAAY,CAAC,CAAC;IACzD,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC;QAAE,OAAO,IAAI,CAAC;IAChD,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAC7C,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @module @jini-ai/sidecar
3
+ *
4
+ * Public barrel for the generic sidecar runtime package. Re-exports the exact
5
+ * prior public surface — the data types, IPC-path validators, namespace/runtime
6
+ * path resolvers, launch-env + bootstrap, port allocation, JSON file helpers, and
7
+ * the JSON-IPC server/client — plus (2026-07-21) the local daemon-registry
8
+ * primitives (`daemon-registry.ts`): a `dataDir`-scoped pointer-file record of a
9
+ * running daemon's URL/host/port/pid, and a liveness-checked reader. This file
10
+ * contains no logic; every implementation lives in a concern module beside it.
11
+ */
12
+ export type { AppIpcPathRequest, AppRuntimePathRequest, BaseResolutionOptions, BootstrapSidecarRuntimeOptions, JsonIpcHandler, JsonIpcServerHandle, NamespaceResolutionOptions, PortAllocation, PortRequest, ProjectRuntimePathRequest, RuntimePathRequest, RuntimeRootRequest, SidecarContractDescriptor, SidecarLaunchEnvRequest, SidecarRuntimeContext, SidecarStampShape, } from "./types.js";
13
+ export { isWindowsNamedPipePath, normalizeIpcPath } from "./ipc-path.js";
14
+ export { resolveAppIpcPath, resolveAppRuntimeDir, resolveAppRuntimePath, resolveLogFilePath, resolveLogsDir, resolveManifestPath, resolveNamespace, resolveNamespaceRoot, resolvePointerPath, resolveProjectRoot, resolveProjectTmpRoot, resolveRuntimeNamespaceRoot, resolveRuntimeRoot, resolveSidecarBase, resolveSourceRuntimeRoot, } from "./paths.js";
15
+ export { bootstrapSidecarRuntime, createSidecarLaunchEnv } from "./bootstrap.js";
16
+ export { allocatePort } from "./port.js";
17
+ export { readJsonFile, removeFile, removePointerIfCurrent, writeJsonFile } from "./json-file.js";
18
+ export { createJsonIpcServer, requestJsonIpc } from "./json-ipc.js";
19
+ export type { LocalDaemonRegistryRecord } from "./daemon-registry.js";
20
+ export { isProcessAlive, readLiveDaemonRegistryRecord, removeDaemonRegistryRecordIfCurrent, resolveDaemonRegistryPath, writeDaemonRegistryRecord, } from "./daemon-registry.js";
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,YAAY,EACV,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,8BAA8B,EAC9B,cAAc,EACd,mBAAmB,EACnB,0BAA0B,EAC1B,cAAc,EACd,WAAW,EACX,yBAAyB,EACzB,kBAAkB,EAClB,kBAAkB,EAClB,yBAAyB,EACzB,uBAAuB,EACvB,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,qBAAqB,EACrB,2BAA2B,EAC3B,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACjG,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpE,YAAY,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,EACL,cAAc,EACd,4BAA4B,EAC5B,mCAAmC,EACnC,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,sBAAsB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @module @jini-ai/sidecar
3
+ *
4
+ * Public barrel for the generic sidecar runtime package. Re-exports the exact
5
+ * prior public surface — the data types, IPC-path validators, namespace/runtime
6
+ * path resolvers, launch-env + bootstrap, port allocation, JSON file helpers, and
7
+ * the JSON-IPC server/client — plus (2026-07-21) the local daemon-registry
8
+ * primitives (`daemon-registry.ts`): a `dataDir`-scoped pointer-file record of a
9
+ * running daemon's URL/host/port/pid, and a liveness-checked reader. This file
10
+ * contains no logic; every implementation lives in a concern module beside it.
11
+ */
12
+ export { isWindowsNamedPipePath, normalizeIpcPath } from "./ipc-path.js";
13
+ export { resolveAppIpcPath, resolveAppRuntimeDir, resolveAppRuntimePath, resolveLogFilePath, resolveLogsDir, resolveManifestPath, resolveNamespace, resolveNamespaceRoot, resolvePointerPath, resolveProjectRoot, resolveProjectTmpRoot, resolveRuntimeNamespaceRoot, resolveRuntimeRoot, resolveSidecarBase, resolveSourceRuntimeRoot, } from "./paths.js";
14
+ export { bootstrapSidecarRuntime, createSidecarLaunchEnv } from "./bootstrap.js";
15
+ export { allocatePort } from "./port.js";
16
+ export { readJsonFile, removeFile, removePointerIfCurrent, writeJsonFile } from "./json-file.js";
17
+ export { createJsonIpcServer, requestJsonIpc } from "./json-ipc.js";
18
+ export { isProcessAlive, readLiveDaemonRegistryRecord, removeDaemonRegistryRecordIfCurrent, resolveDaemonRegistryPath, writeDaemonRegistryRecord, } from "./daemon-registry.js";
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAoBH,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,qBAAqB,EACrB,2BAA2B,EAC3B,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACjG,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpE,OAAO,EACL,cAAc,EACd,4BAA4B,EAC5B,mCAAmC,EACnC,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @module ipc-path
3
+ *
4
+ * IPC path shape helpers: recognizing a Windows named-pipe path and validating
5
+ * that an IPC path is a well-formed absolute socket path (or a named pipe).
6
+ * Depends only on `node:path`.
7
+ */
8
+ /**
9
+ * Detect whether a value is a Windows named-pipe path (`\\.\pipe\...`).
10
+ * @returns `true` when `value` is such a pipe path.
11
+ */
12
+ export declare function isWindowsNamedPipePath(value: unknown): boolean;
13
+ /**
14
+ * Validate and return an IPC path: a Windows named pipe is accepted as-is, and
15
+ * any other value must be a non-empty, un-padded, null-byte-free absolute path.
16
+ * @returns The validated IPC path.
17
+ */
18
+ export declare function normalizeIpcPath(ipc: unknown): string;
19
+ //# sourceMappingURL=ipc-path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ipc-path.d.ts","sourceRoot":"","sources":["../src/ipc-path.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAE9D;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAQrD"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @module ipc-path
3
+ *
4
+ * IPC path shape helpers: recognizing a Windows named-pipe path and validating
5
+ * that an IPC path is a well-formed absolute socket path (or a named pipe).
6
+ * Depends only on `node:path`.
7
+ */
8
+ import { isAbsolute } from "node:path";
9
+ /**
10
+ * Detect whether a value is a Windows named-pipe path (`\\.\pipe\...`).
11
+ * @returns `true` when `value` is such a pipe path.
12
+ */
13
+ export function isWindowsNamedPipePath(value) {
14
+ return typeof value === "string" && value.startsWith("\\\\.\\pipe\\");
15
+ }
16
+ /**
17
+ * Validate and return an IPC path: a Windows named pipe is accepted as-is, and
18
+ * any other value must be a non-empty, un-padded, null-byte-free absolute path.
19
+ * @returns The validated IPC path.
20
+ */
21
+ export function normalizeIpcPath(ipc) {
22
+ if (typeof ipc !== "string")
23
+ throw new Error("sidecar ipc path must be a string");
24
+ if (ipc.length === 0)
25
+ throw new Error("sidecar ipc path must not be empty");
26
+ if (ipc.trim() !== ipc)
27
+ throw new Error("sidecar ipc path must not contain leading or trailing whitespace");
28
+ if (ipc.includes("\0"))
29
+ throw new Error("sidecar ipc path must not contain null bytes");
30
+ if (isWindowsNamedPipePath(ipc))
31
+ return ipc;
32
+ if (!isAbsolute(ipc))
33
+ throw new Error(`sidecar ipc path must be absolute: ${ipc}`);
34
+ return ipc;
35
+ }
36
+ //# sourceMappingURL=ipc-path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ipc-path.js","sourceRoot":"","sources":["../src/ipc-path.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAAc;IACnD,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC;AACxE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAY;IAC3C,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IAClF,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IAC5E,IAAI,GAAG,CAAC,IAAI,EAAE,KAAK,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAC;IAC5G,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IACxF,IAAI,sBAAsB,CAAC,GAAG,CAAC;QAAE,OAAO,GAAG,CAAC;IAC5C,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,sCAAsC,GAAG,EAAE,CAAC,CAAC;IACnF,OAAO,GAAG,CAAC;AACb,CAAC"}