shadok-ai 0.17.44 → 0.17.46

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.
@@ -26,7 +26,7 @@ and automatically starts the shadok-ai server when it is not running (port
26
26
  | `choose <id> <n>` | single-select dialog: picks and commits option n |
27
27
  | `toggle <id> <n>` then `confirm <id>` | multi-select dialog: check/uncheck then submit |
28
28
  | `freetext <id> <n> "text"` | the "Type something" option: a free answer |
29
- | `list [--cwd DIR]` | driven agents (local state + alive/dead) and resumable sessions |
29
+ | `list [--cwd DIR]` | driven agents (local state + alive/dead) and resumable sessions. With `--peer X`: the agents running ON X (from X itself, tagged `peer`), plus X's resumable sessions only for a `--cwd` you name — a path on X |
30
30
  | `diff <id>` | the agent's changes (git status + diff against the worktree's base) |
31
31
  | `stop <id>` | ends the session (for ALL its clients) |
32
32
  | `screen <id>` | raw TUI screen (debug) |
@@ -192,7 +192,9 @@ pilotctl stop <id> --peer brasdroit1
192
192
  - **member** — you act like an invited user: `list`, `diff`, resume/drive/stop
193
193
  **any** agent on X, spawn more, read its usage. You are not an admin (no
194
194
  account or peer management).
195
- Track the ids you `spawn` either way and drive them by id.
195
+ Track the ids you `spawn` either way and drive them by id. `list --peer X`
196
+ answers with X's agents and says so (`peer: <url>`); a refusal comes back as
197
+ an explicit `peer-scope` error, never as your own machine's list.
196
198
 
197
199
  ## Guardrails
198
200
 
@@ -448,7 +448,40 @@ async function cmdDialog(id, flags) {
448
448
  return r;
449
449
  }
450
450
 
451
+ /**
452
+ * `list` against a REMOTE peer. The local half of a plain `list` — pilotctl's
453
+ * own state files, a `holderPid` and a local `pidAlive` — describes THIS
454
+ * machine, so over a peer link it is not "less precise", it is another
455
+ * machine's answer to the question (issue #423: a full, plausible list of the
456
+ * caller's own sessions came back with nothing to say so). Ask the peer for
457
+ * the agents running on IT (`GET /live`, which it scopes to what we may see),
458
+ * and say WHICH machine answered. `resumable` is keyed by a directory: the
459
+ * caller's cwd generally does not exist over there, and an empty answer would
460
+ * read as "nothing resumable" — so it is queried only for a `--cwd` the caller
461
+ * named, and otherwise left out rather than filled with a meaningless `[]`.
462
+ */
463
+ async function cmdListPeer(flags) {
464
+ const live = await fetch(`${httpBase()}/live`, { headers: authHeaders() });
465
+ if (live.status === 401 || live.status === 403)
466
+ throw Object.assign(
467
+ new Error(
468
+ `peer-scope: ${httpBase()} refused to list its agents (HTTP ${live.status}) — ` +
469
+ "a restricted peer may only drive the agents it spawned; track their ids from `spawn`",
470
+ ),
471
+ { code: "peer-scope" },
472
+ );
473
+ if (!live.ok) throw new Error(`peer ${httpBase()} answered HTTP ${live.status} to /live`);
474
+ const agents = (await live.json()).map((a) => ({ sessionId: a.id, ...a }));
475
+ const out = { peer: httpBase(), agents };
476
+ if (flags.cwd) {
477
+ const r = await fetch(`${httpBase()}/sessions?cwd=${encodeURIComponent(flags.cwd)}`, { headers: authHeaders() });
478
+ if (r.ok) out.resumable = await r.json();
479
+ }
480
+ return out;
481
+ }
482
+
451
483
  async function cmdList(flags) {
484
+ if (PEER) return cmdListPeer(flags);
452
485
  await ensureServer();
453
486
  const cwd = flags.cwd ?? process.cwd();
454
487
  const r = await fetch(`${httpBase()}/sessions?cwd=${encodeURIComponent(cwd)}`, { headers: authHeaders() });
@@ -702,6 +735,11 @@ export async function run(argv) {
702
735
  : `unknown peer "${flags.peer}" — add it with: pilotctl peer add <alias> <url> <token>`,
703
736
  );
704
737
  setPeer(target);
738
+ } else {
739
+ // No peer asked for THIS call: target the local server. `PEER` is module
740
+ // state, so without this a peer chosen by an earlier `run()` in the same
741
+ // process (an importer, the tests) would silently retarget this one.
742
+ setPeer(null);
705
743
  }
706
744
  switch (cmd) {
707
745
  case "spawn":
@@ -30,6 +30,45 @@ test("list combines resumable sessions and local agents", async () => {
30
30
  }
31
31
  });
32
32
 
33
+ test("list --peer asks the PEER for its agents, never the local state (#423)", async () => {
34
+ const mock = await startMockServer({
35
+ live: [{ id: "remote-1", cwd: "/workspace", branch: null, busy: false, clients: 1, lastPrompt: "hi" }],
36
+ sessions: [{ id: "old-remote", mtime: 1 }],
37
+ });
38
+ // A local state file that a plain `list` would report: it must NOT leak in.
39
+ writeState("local-only", { sessionId: "local-only", cwd: "/only/on/caller", holderPid: process.pid });
40
+ const url = `http://127.0.0.1:${mock.port}`;
41
+ try {
42
+ const r = await run(["list", "--peer-url", url, "--peer-token", "tok"]);
43
+ assert.equal(r.peer, url);
44
+ assert.deepEqual(r.agents.map((a) => a.sessionId), ["remote-1"]);
45
+ assert.ok(r.agents.every((a) => !("holderPid" in a) && !("live" in a)), "no local-only fields");
46
+ // No --cwd: the caller's cwd means nothing over there, so no resumable list.
47
+ assert.ok(!("resumable" in r));
48
+ const live = mock.http.find((h) => h.url === "/live");
49
+ assert.equal(live.peer, "tok");
50
+ assert.ok(!mock.http.some((h) => h.url.startsWith("/sessions")));
51
+ // An explicit --cwd is a path on the peer: queried there.
52
+ const r2 = await run(["list", "--peer-url", url, "--peer-token", "tok", "--cwd", "/workspace"]);
53
+ assert.deepEqual(r2.resumable, [{ id: "old-remote", mtime: 1 }]);
54
+ assert.ok(mock.http.some((h) => h.url === "/sessions?cwd=%2Fworkspace" && h.peer === "tok"));
55
+ } finally {
56
+ await mock.close();
57
+ }
58
+ });
59
+
60
+ test("list --peer refused by the peer → an explicit peer-scope error, not a local list", async () => {
61
+ const mock = await startMockServer({ liveStatus: 401, live: { error: "unauthorized" } });
62
+ try {
63
+ await assert.rejects(
64
+ () => run(["list", "--peer-url", `http://127.0.0.1:${mock.port}`, "--peer-token", "tok"]),
65
+ /peer-scope/,
66
+ );
67
+ } finally {
68
+ await mock.close();
69
+ }
70
+ });
71
+
33
72
  test("diff goes through the server while the session is live", async () => {
34
73
  const mock = await startMockServer({
35
74
  diff: { status: "M x.txt", diff: "--- a/x.txt", branch: "shadok-ai/abc" },
@@ -19,8 +19,12 @@ export function startMockServer(script = {}) {
19
19
  const raw = Buffer.concat(chunks).toString("utf8");
20
20
  let body;
21
21
  try { body = raw ? JSON.parse(raw) : undefined; } catch { body = raw; }
22
- http_.push({ method: req.method, url: req.url, body, sessionKey: req.headers["x-shadok-session-key"] });
22
+ http_.push({ method: req.method, url: req.url, body, sessionKey: req.headers["x-shadok-session-key"], peer: req.headers["x-shadok-peer"] });
23
23
  res.setHeader("content-type", "application/json");
24
+ if (req.url.startsWith("/live")) {
25
+ if (script.liveStatus) res.statusCode = script.liveStatus;
26
+ return res.end(JSON.stringify(script.live ?? []));
27
+ }
24
28
  if (req.url.startsWith("/sessions")) return res.end(JSON.stringify(script.sessions ?? []));
25
29
  if (req.url.startsWith("/diff"))
26
30
  return res.end(
@@ -7,14 +7,23 @@ export type DeploymentMode = "multi-tenant" | "mono-tenant";
7
7
  /** Accounts exist only when a GUI password is set (it is the admin account). */
8
8
  export declare function accountsEnabled(guiPassword: string): boolean;
9
9
  /**
10
- * Can this process create OS users? Root, or passwordless sudo.
10
+ * Can this process create OS users FOR GROUP ISOLATION? Root, or passwordless
11
+ * sudo — and only on Linux. The isolation is implemented with Linux-only tooling
12
+ * (`useradd`, `setpriv`, `runuser`); on macOS or Windows it cannot work, so a
13
+ * host there must never auto-enable multi-tenant. Without this gate, a Mac
14
+ * running as root (or with cached/passwordless sudo) plus a GUI password flipped
15
+ * to multi-tenant and failed the boot migration on the very first `useradd`,
16
+ * leaving the red "isolation did NOT complete" banner on an instance that was
17
+ * only ever meant to be a password-gated single-user cockpit.
11
18
  * `SHADOK_FORCE_MULTITENANT=1` forces true and `=0` forces false (tests,
12
- * unusual setups) — same style as `inContainer` in `ssh.ts`.
19
+ * unusual setups) — same style as `inContainer` in `ssh.ts`; the explicit
20
+ * override is checked BEFORE the platform gate so an operator keeps control.
13
21
  */
14
22
  export declare function probeCanProvision(deps?: {
15
23
  getuid?: () => number | undefined;
16
24
  canSudo?: () => boolean;
17
25
  env?: NodeJS.ProcessEnv;
26
+ platform?: NodeJS.Platform;
18
27
  }): boolean;
19
28
  /** Multi-tenant iff BOTH capabilities hold; otherwise stay mono-tenant. */
20
29
  export declare function deploymentMode(input: {
@@ -17,18 +17,29 @@ function defaultCanSudo() {
17
17
  }
18
18
  }
19
19
  /**
20
- * Can this process create OS users? Root, or passwordless sudo.
20
+ * Can this process create OS users FOR GROUP ISOLATION? Root, or passwordless
21
+ * sudo — and only on Linux. The isolation is implemented with Linux-only tooling
22
+ * (`useradd`, `setpriv`, `runuser`); on macOS or Windows it cannot work, so a
23
+ * host there must never auto-enable multi-tenant. Without this gate, a Mac
24
+ * running as root (or with cached/passwordless sudo) plus a GUI password flipped
25
+ * to multi-tenant and failed the boot migration on the very first `useradd`,
26
+ * leaving the red "isolation did NOT complete" banner on an instance that was
27
+ * only ever meant to be a password-gated single-user cockpit.
21
28
  * `SHADOK_FORCE_MULTITENANT=1` forces true and `=0` forces false (tests,
22
- * unusual setups) — same style as `inContainer` in `ssh.ts`.
29
+ * unusual setups) — same style as `inContainer` in `ssh.ts`; the explicit
30
+ * override is checked BEFORE the platform gate so an operator keeps control.
23
31
  */
24
32
  export function probeCanProvision(deps = {}) {
25
33
  const env = deps.env ?? process.env;
26
34
  const getuid = deps.getuid ?? (() => process.getuid?.());
27
35
  const canSudo = deps.canSudo ?? defaultCanSudo;
36
+ const platform = deps.platform ?? process.platform;
28
37
  if (env.SHADOK_FORCE_MULTITENANT === "1")
29
38
  return true;
30
39
  if (env.SHADOK_FORCE_MULTITENANT === "0")
31
40
  return false;
41
+ if (platform !== "linux")
42
+ return false;
32
43
  if (getuid() === 0)
33
44
  return true;
34
45
  return canSudo();
@@ -1 +1 @@
1
- {"version":3,"file":"capability.js","sourceRoot":"","sources":["../src/capability.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAS/C,gFAAgF;AAChF,MAAM,UAAU,eAAe,CAAC,WAAmB;IACjD,OAAO,WAAW,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;AACnC,CAAC;AAED;;;GAGG;AACH,SAAS,cAAc;IACrB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GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACvC,OAAO,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AACpE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shadok-ai",
3
- "version": "0.17.44",
3
+ "version": "0.17.46",
4
4
  "main": "dist/session.js",
5
5
  "scripts": {
6
6
  "test": "node --import tsx --test --test-timeout=120000 test/*.ts context/*/test/*.test.mjs",