@sessionbus/dsh 0.1.0-pre.11 → 0.1.0-pre.12

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 (3) hide show
  1. package/README.md +3 -0
  2. package/package.json +1 -1
  3. package/plugin.cjs +14 -5
package/README.md CHANGED
@@ -64,6 +64,9 @@ host level and put their shared `node_modules/.bin` on the daemon service's
64
64
 
65
65
  Without an explicit socket, peers use `$XDG_RUNTIME_DIR/sessionbus/presence.sock`
66
66
  or `/tmp/sessionbus-<uid>/presence.sock`, matching the daemon's discovery rule.
67
+ Set `SESSIONBUS_DSH_TRACE=1` to write one-line mode, readiness, root-lifecycle,
68
+ publication-gate, and socket-connection diagnostics to stderr; tracing is off
69
+ by default.
67
70
 
68
71
  Uninstall without invoking DSH by running the installed bin from the profile:
69
72
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sessionbus/dsh",
3
- "version": "0.1.0-pre.11",
3
+ "version": "0.1.0-pre.12",
4
4
  "type": "commonjs",
5
5
  "main": "plugin.cjs",
6
6
  "exports": "./plugin.cjs",
package/plugin.cjs CHANGED
@@ -72,7 +72,7 @@ function readConfiguration(ctx, config = {}, ambient = process.env) {
72
72
  : path.join("/tmp", `sessionbus-${process.getuid()}`, "presence.sock");
73
73
  const localKey = Object.hasOwn(config, "local_key") ? config.local_key : value("SESSIONBUS_LOCAL_KEY");
74
74
  if (!text(socket) || localKey !== undefined && !text(localKey)) throw new Error("connection settings are invalid");
75
- return { settings: { mode, product: config.product, groups: [...groups], socket, localKey }, token };
75
+ return { settings: { mode, product: config.product, groups: [...groups], socket, localKey }, token, trace: value("SESSIONBUS_DSH_TRACE") === "1" };
76
76
  }
77
77
 
78
78
  function captureContext(ctx) {
@@ -294,7 +294,9 @@ function createRuntime(ctx, config, dependencies, prepared) {
294
294
  let ready = false;
295
295
  let warned = false;
296
296
  const warn = (error) => { if (active() && !warned) { warned = true; dependencies.stderr(`sessionbus: ${clean(error)}\n`); } };
297
+ const trace = (message) => { if (configured.trace && active()) dependencies.stderr(`sessionbus trace: ${message}\n`); };
297
298
  const root = (agent) => ctx.agents.roots().includes(agent);
299
+ trace(`mode=${values.mode} ready=false socket=${values.socket}`);
298
300
  const publicationError = (agent, error, record) => {
299
301
  if (record && peers.get(agent) === record) {
300
302
  record.peer?.shutdown();
@@ -307,14 +309,19 @@ function createRuntime(ctx, config, dependencies, prepared) {
307
309
  }
308
310
  };
309
311
  const present = (agent) => {
310
- if (values.mode !== "peer" || !ready || !root(agent) || peers.has(agent)) return;
312
+ const isRoot = root(agent);
313
+ const reason = values.mode !== "peer" ? "not-peer" : !ready ? "not-ready" : !isRoot ? "not-root" : peers.has(agent) ? "published" : "publish";
314
+ trace(`present id=${agent?.session?.id || agent?.id || "unknown"} root=${isRoot} reason=${reason}`);
315
+ if (reason !== "publish") return;
311
316
  try {
312
317
  const current = identity(ctx, agent, values.product, values.groups);
313
- if (!current) return;
318
+ if (!current) { trace(`present id=${agent?.id || "unknown"} root=${isRoot} reason=no-session-id`); return; }
314
319
  const record = { peer: undefined, identity: current, rehello: Promise.resolve() };
315
320
  const peer = dependencies.connectPeer(current, (cancel, request) => native.deliver(cancel, request, agent), connectionEnvironment(values), {
316
321
  connect: (socket) => {
322
+ trace(`connect id=${current.session_id} socket=${socket}`);
317
323
  const stream = net.createConnection(socket);
324
+ stream.once("connect", () => trace(`connect id=${current.session_id} state=connected`));
318
325
  stream.once("error", (error) => publicationError(agent, error, record));
319
326
  return stream;
320
327
  },
@@ -327,8 +334,8 @@ function createRuntime(ctx, config, dependencies, prepared) {
327
334
  const forget = (agent) => { peers.get(agent)?.peer.shutdown(); peers.delete(agent); };
328
335
  let removeCreated = () => {}, removeDisposed = () => {}, removeTitle = () => {};
329
336
  if (values.mode === "peer") {
330
- removeCreated = ctx.on("agent/created", ({ agent }) => present(agent), { global: true });
331
- removeDisposed = ctx.on("agent/disposed", ({ agent }) => forget(agent), { global: true });
337
+ removeCreated = ctx.on("agent/created", ({ agent }) => { trace(`agent/created id=${agent?.session?.id || agent?.id || "unknown"} scope=global`); present(agent); }, { global: true });
338
+ removeDisposed = ctx.on("agent/disposed", ({ agent }) => { trace(`agent/disposed id=${agent?.session?.id || agent?.id || "unknown"} scope=global`); forget(agent); }, { global: true });
332
339
  removeTitle = ctx.on("session/event", (session, event) => {
333
340
  if (event.type !== "session/title") return;
334
341
  const agent = ctx.agents.get(session.id);
@@ -372,6 +379,7 @@ function createRuntime(ctx, config, dependencies, prepared) {
372
379
  });
373
380
  const start = () => {
374
381
  ready = true;
382
+ trace(`mode=${values.mode} ready=true`);
375
383
  if (values.mode === "lane") {
376
384
  const environment = connectionEnvironment(values, launchToken);
377
385
  launchToken = undefined;
@@ -394,6 +402,7 @@ function createRuntime(ctx, config, dependencies, prepared) {
394
402
  };
395
403
  const removeReady = ctx.appReady.onReady(start);
396
404
  const close = () => {
405
+ trace(`mode=${values.mode} ready=false reason=close`);
397
406
  removeReady(); removeCreated(); removeDisposed(); removeTitle(); removeCommand(); removeGrant(); removeTool();
398
407
  for (const agent of peers.keys()) forget(agent);
399
408
  worker?.shutdown(); native.removeEvents();