shennian 0.3.74 → 0.3.75
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.
|
@@ -261,8 +261,8 @@
|
|
|
261
261
|
},
|
|
262
262
|
{
|
|
263
263
|
"file": "src/daemon-ipc/paths.js",
|
|
264
|
-
"beforeBytes":
|
|
265
|
-
"afterBytes":
|
|
264
|
+
"beforeBytes": 2006,
|
|
265
|
+
"afterBytes": 902
|
|
266
266
|
},
|
|
267
267
|
{
|
|
268
268
|
"file": "src/daemon-ipc/protocol.js",
|
|
@@ -276,8 +276,8 @@
|
|
|
276
276
|
},
|
|
277
277
|
{
|
|
278
278
|
"file": "src/daemon-ipc/server.js",
|
|
279
|
-
"beforeBytes":
|
|
280
|
-
"afterBytes":
|
|
279
|
+
"beforeBytes": 6704,
|
|
280
|
+
"afterBytes": 3447
|
|
281
281
|
},
|
|
282
282
|
{
|
|
283
283
|
"file": "src/daemon-log.js",
|
|
@@ -11,5 +11,5 @@ export declare function resolveDaemonIpcPaths(rootDir?: string, platform?: NodeJ
|
|
|
11
11
|
* local bridge is a separate, daemon-owned IPC endpoint whose handler still
|
|
12
12
|
* requires the per-turn managed Room capability.
|
|
13
13
|
*/
|
|
14
|
-
export declare function getManagedRoomIpcRoot(shennianDir?: string): string;
|
|
14
|
+
export declare function getManagedRoomIpcRoot(shennianDir?: string, tempDirectory?: string): string;
|
|
15
15
|
export declare function resolveManagedRoomIpcPaths(rootDir?: string, platform?: NodeJS.Platform): DaemonIpcPaths;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import s from"node:crypto";import a from"node:os";import
|
|
1
|
+
import s from"node:crypto";import a from"node:os";import t from"node:path";import{getShennianDir as i}from"../config/index.js";const f="SHENNIAN_MANAGED_ROOM_IPC_ROOT";function c(e=i(),n=process.platform){const o=t.join(e,"runtime"),r=t.join(o,"daemon-ipc.secret");if(n==="win32"){const p=s.createHash("sha256").update(t.resolve(e).toLowerCase()).digest("hex").slice(0,20);return{runtimeDirectory:o,secretFile:r,endpoint:`\\\\.\\pipe\\shennian-daemon-${p}`,transport:"windows_named_pipe"}}return{runtimeDirectory:o,secretFile:r,endpoint:t.join(o,"daemon.sock"),transport:"unix_socket"}}function m(e=i(),n=a.tmpdir()){const o=s.createHash("sha256").update(t.resolve(e)).digest("hex").slice(0,20);return t.join(n,`sn-mr-${o}`)}function l(e=m(),n=process.platform){return c(e,n)}export{f as MANAGED_ROOM_IPC_ROOT_ENV,m as getManagedRoomIpcRoot,c as resolveDaemonIpcPaths,l as resolveManagedRoomIpcPaths};
|
|
@@ -7,6 +7,7 @@ export type DaemonIpcServer = {
|
|
|
7
7
|
paths: DaemonIpcPaths;
|
|
8
8
|
close(): Promise<void>;
|
|
9
9
|
};
|
|
10
|
+
export declare function assertUnixSocketEndpointLength(endpoint: string, platform?: NodeJS.Platform): void;
|
|
10
11
|
export declare function startDaemonIpcServer(options: {
|
|
11
12
|
handlers: Record<string, DaemonIpcHandler>;
|
|
12
13
|
paths?: DaemonIpcPaths;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import _ from"node:crypto";import u from"node:fs";import h from"node:net";import{resolveDaemonIpcPaths as
|
|
2
|
-
`);p<0||(c=!0,
|
|
3
|
-
`)}function
|
|
1
|
+
import _ from"node:crypto";import u from"node:fs";import h from"node:net";import{resolveDaemonIpcPaths as w}from"./paths.js";import{DAEMON_IPC_MAX_REQUEST_BYTES as S,DAEMON_IPC_VERSION as l,DaemonIpcError as f}from"./protocol.js";import{ensurePrivateRuntimeDirectory as I,loadOrCreateDaemonIpcSecret as P}from"./secret.js";function v(n,e=process.platform){const r=e==="darwin"?104:e==="linux"?107:null;if(r!==null&&Buffer.byteLength(n,"utf8")>r)throw new f("ipc_endpoint_too_long",`Daemon IPC endpoint exceeds the ${e} Unix socket path limit.`)}async function L(n){const e=n.paths??w();I(e.runtimeDirectory);const r=P(e.runtimeDirectory,e.secretFile);e.transport==="unix_socket"&&(v(e.endpoint),await k(e.endpoint));const o=h.createServer(t=>{t.setEncoding("utf8");let s="",c=!1;t.on("data",d=>{if(c)return;if(s+=d,Buffer.byteLength(s,"utf8")>S){c=!0,m(t,a("unknown","request_too_large","Daemon IPC request is too large."));return}const p=s.indexOf(`
|
|
2
|
+
`);p<0||(c=!0,C(s.slice(0,p),r,n.handlers).then(y=>m(t,y)).catch(()=>m(t,a("unknown","internal_error","Daemon IPC request failed."))))}),t.on("error",()=>{})});await new Promise((t,s)=>{const c=d=>s(d);o.once("error",c),o.listen(e.endpoint,()=>{o.off("error",c),t()})});let i=null;if(e.transport==="unix_socket")try{u.chmodSync(e.endpoint,384);const t=u.lstatSync(e.endpoint);if(!t.isSocket()||t.isSymbolicLink())throw new f("unsafe_ipc_endpoint","Daemon IPC endpoint was not created as a Unix socket.");i={dev:t.dev,ino:t.ino}}catch(t){throw await new Promise(s=>o.close(()=>s())),t}return{paths:e,close:async()=>{if(await new Promise(t=>o.close(()=>t())),e.transport==="unix_socket"&&i)try{const t=u.lstatSync(e.endpoint);t.isSocket()&&t.dev===i.dev&&t.ino===i.ino&&u.unlinkSync(e.endpoint)}catch{}}}}async function k(n){try{const e=u.lstatSync(n);if(!e.isSocket()||e.isSymbolicLink())throw new f("unsafe_ipc_endpoint","Refusing to replace a non-socket IPC endpoint.");if(await g(n))throw new f("daemon_ipc_in_use","Another Shennian daemon IPC server is already running.");u.unlinkSync(n)}catch(e){if(x(e))return;throw e}}function g(n){return new Promise(e=>{const r=h.createConnection(n),o=i=>{r.destroy(),e(i)};r.once("connect",()=>o(!0)),r.once("error",()=>o(!1)),r.setTimeout(300,()=>o(!1))})}async function C(n,e,r){let o;try{o=JSON.parse(n)}catch{return a("unknown","invalid_json","Daemon IPC request must be JSON.")}const i=typeof o.requestId=="string"?o.requestId.slice(0,128):"unknown";if(o.version!==l)return a(i,"unsupported_version","Unsupported daemon IPC version.");if(!D(o.auth,e))return a(i,"unauthorized","Daemon IPC authentication failed.");if(typeof o.method!="string"||!/^[a-z][a-z0-9_.-]{0,127}$/.test(o.method))return a(i,"invalid_method","Invalid daemon IPC method.");const t=r[o.method];if(!t)return a(i,"method_not_found","Daemon IPC method is not supported.");try{const s=await t(o.params,{requestId:i});return{version:l,requestId:i,ok:!0,result:s}}catch(s){return s instanceof f?a(i,s.code,s.message):a(i,"method_failed","Daemon IPC method failed.")}}function D(n,e){if(typeof n!="string")return!1;const r=Buffer.from(n),o=Buffer.from(e);return r.length===o.length&&_.timingSafeEqual(r,o)}function a(n,e,r){return{version:l,requestId:n,ok:!1,error:{code:e,message:r}}}function m(n,e){n.end(`${JSON.stringify(e)}
|
|
3
|
+
`)}function x(n){return typeof n=="object"&&n!==null&&"code"in n&&n.code==="ENOENT"}export{v as assertUnixSocketEndpointLength,L as startDaemonIpcServer};
|