passport-bridge 0.20.0 → 0.21.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/dist/cliHook.js CHANGED
@@ -17,6 +17,7 @@
17
17
  import { value } from "./cliArgs.js";
18
18
  import { summarize } from "./cliHookClassify.js";
19
19
  import { classifyLine, localMachine, workingFolder, worthReporting } from "./cliHookLocal.js";
20
+ import { projectOf } from "./cliHookProject.js";
20
21
  import { codexAskBlocked, planGuard } from "./cliHookDecide.js";
21
22
  import { decideGuard, guardMachineOf } from "./cliHookGuard.js";
22
23
  import { detectMode } from "./cliHookMode.js";
@@ -124,11 +125,15 @@ function context(input, env, declared) {
124
125
  const toolUseId = text(input.tool_use_id, 128);
125
126
  const roots = Array.isArray(input.workspace_roots) ? input.workspace_roots : [];
126
127
  const cwdName = directoryName(input.cwd) ?? directoryName(roots[0]);
128
+ // Sessions group by project: its name and branch only, read locally and cached.
129
+ const { project, branch } = sessionId ? projectOf(workingFolder(input)) : {};
127
130
  return {
128
131
  runtime: detectRuntime(input, env, declared),
129
132
  ...(sessionId ? { sessionId } : {}),
130
133
  ...(toolUseId ? { toolUseId } : {}),
131
- ...(cwdName ? { cwdName } : {})
134
+ ...(cwdName ? { cwdName } : {}),
135
+ ...(project ? { project } : {}),
136
+ ...(branch ? { branch } : {})
132
137
  };
133
138
  }
134
139
  function reportable(findings, decided = [], local = false) {
@@ -17,6 +17,10 @@ export type CliHookReport = {
17
17
  sessionId?: string;
18
18
  toolUseId?: string;
19
19
  cwdName?: string;
20
+ /** The repository's name (never its owner or URL), for grouping sessions. */
21
+ project?: string;
22
+ /** The checked-out branch, when there is one. */
23
+ branch?: string;
20
24
  exitCode?: number;
21
25
  durationMs?: number;
22
26
  findings: ReportedFinding[];
@@ -114,6 +118,8 @@ export type ApiCall = (path: string, init: RequestInit) => Promise<Response>;
114
118
  export declare function profileApi(profile: string, signal: AbortSignal, fetcher: typeof fetch): Promise<ApiCall | null>;
115
119
  /** The report an older server accepts: no Autopilot fields, ask or deny only. */
116
120
  export declare function legacyReport(report: CliHookReport): CliHookReport | null;
121
+ /** The report a server from before project grouping accepts (bridge 0.21.0). */
122
+ export declare function withoutProject(report: CliHookReport): CliHookReport;
117
123
  type Send = (report: CliHookReport) => Promise<void>;
118
124
  /** Deliver reports with the same credential `passport discover` uses. Agent
119
125
  * keys are deliberately unsupported: a hook reports a person's own shell.
@@ -49,11 +49,16 @@ export async function profileApi(profile, signal, fetcher) {
49
49
  export function legacyReport(report) {
50
50
  if (report.decision === "allow")
51
51
  return null;
52
- const { scripts: _scripts, opaqueIds: _ids, projectChanged: _changed, drift: _drift, ...rest } = report;
52
+ const { scripts: _scripts, opaqueIds: _ids, projectChanged: _changed, drift: _drift, ...rest } = withoutProject(report);
53
53
  if (!rest.findings.length && !rest.opaque)
54
54
  return null;
55
55
  return { ...rest, findings: report.findings.map(({ vendor, verb, risk }) => ({ vendor, verb, risk })) };
56
56
  }
57
+ /** The report a server from before project grouping accepts (bridge 0.21.0). */
58
+ export function withoutProject(report) {
59
+ const { project: _project, branch: _branch, ...rest } = report;
60
+ return rest;
61
+ }
57
62
  function hasAutopilotFields(report) {
58
63
  return (report.decision === "allow" ||
59
64
  report.scripts !== undefined ||
@@ -72,8 +77,13 @@ async function postWith(api, report, signal) {
72
77
  body: JSON.stringify(body),
73
78
  signal
74
79
  });
75
- const response = await post(report);
80
+ let response = await post(report);
76
81
  await response.body?.cancel().catch(() => undefined);
82
+ // A server from before project grouping refuses those two fields: send the rest.
83
+ if (response.status === 400 && (report.project !== undefined || report.branch !== undefined)) {
84
+ response = await post(withoutProject(report));
85
+ await response.body?.cancel().catch(() => undefined);
86
+ }
77
87
  // A server that refuses the Autopilot fields still gets the row it knows.
78
88
  const legacy = response.status === 400 && hasAutopilotFields(report) ? legacyReport(report) : null;
79
89
  if (legacy)
@@ -57,6 +57,18 @@ export declare function localMachine(cwd: unknown, env?: Record<string, string |
57
57
  export declare function placeOfPath(path: string, machine: LocalMachine): Place;
58
58
  /** The path a word names, relative to `cwd`; null when it can't be known. */
59
59
  export declare function resolveWord(word: ShellWord, cwd: string | null, machine: LocalMachine): string | null;
60
+ export declare function readRef(text: string | null, prefix: string): string | null;
61
+ /**
62
+ * Where a repository keeps its data, read from the files git itself writes:
63
+ * the checkout's root, its own git folder (a worktree's lives under the main
64
+ * repository's `.git/worktrees/`), and the common folder every worktree of
65
+ * that repository shares. Null outside a repository.
66
+ */
67
+ export declare function gitLayout(dir: string, fs: LocalFs): {
68
+ root: string;
69
+ gitDir: string;
70
+ commonDir: string;
71
+ } | null;
60
72
  /** The current and default branch of the repository holding `dir`. */
61
73
  export declare function gitBranches(dir: string, fs: LocalFs): {
62
74
  current: string | null;
@@ -319,25 +319,38 @@ export function resolveWord(word, cwd, machine) {
319
319
  return canonical(base, machine.fs);
320
320
  return posix.join(canonical(base, machine.fs), "x");
321
321
  }
322
- function readRef(text, prefix) {
322
+ export function readRef(text, prefix) {
323
323
  const match = text ? /^ref:\s*(\S+)/.exec(text.trim()) : null;
324
324
  return match && match[1].startsWith(prefix) ? match[1].slice(prefix.length) : null;
325
325
  }
326
- /** The current and default branch of the repository holding `dir`. */
327
- export function gitBranches(dir, fs) {
326
+ /**
327
+ * Where a repository keeps its data, read from the files git itself writes:
328
+ * the checkout's root, its own git folder (a worktree's lives under the main
329
+ * repository's `.git/worktrees/`), and the common folder every worktree of
330
+ * that repository shares. Null outside a repository.
331
+ */
332
+ export function gitLayout(dir, fs) {
328
333
  const root = gitRoot(dir, fs);
329
334
  if (!root)
330
- return { current: null, defaultBranch: null };
335
+ return null;
331
336
  const marker = posix.join(root, ".git");
332
337
  let gitDir = marker;
333
338
  if (fs.isFile(marker)) {
334
339
  const pointer = /^gitdir:\s*(.+)$/m.exec(fs.readText(marker) ?? "")?.[1]?.trim();
335
340
  if (!pointer)
336
- return { current: null, defaultBranch: null };
337
- gitDir = pointer.startsWith("/") ? pointer : posix.join(root, pointer);
341
+ return null;
342
+ gitDir = posix.normalize(pointer.startsWith("/") ? pointer : posix.join(root, pointer));
338
343
  }
339
344
  const common = fs.readText(posix.join(gitDir, "commondir"))?.trim();
340
- const commonDir = common ? (common.startsWith("/") ? common : posix.join(gitDir, common)) : gitDir;
345
+ const commonDir = common ? posix.normalize(common.startsWith("/") ? common : posix.join(gitDir, common)) : gitDir;
346
+ return { root, gitDir, commonDir };
347
+ }
348
+ /** The current and default branch of the repository holding `dir`. */
349
+ export function gitBranches(dir, fs) {
350
+ const layout = gitLayout(dir, fs);
351
+ if (!layout)
352
+ return { current: null, defaultBranch: null };
353
+ const { gitDir, commonDir } = layout;
341
354
  return {
342
355
  current: readRef(fs.readText(posix.join(gitDir, "HEAD")), "refs/heads/"),
343
356
  defaultBranch: readRef(fs.readText(posix.join(commonDir, "refs/remotes/origin/HEAD")), "refs/remotes/origin/")
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Which project and branch an agent's command runs in, for grouping sessions
3
+ * by project. Read from the files git writes (no `git` process, no network),
4
+ * once per folder per process, and never throws.
5
+ *
6
+ * - project: the repository's name from its `origin` remote (the last path
7
+ * segment without `.git`; never the owner, host, or full URL), else the
8
+ * main checkout's folder name (so a worktree maps to its repository), else
9
+ * the working folder's own name.
10
+ * - branch: the checked-out branch; nothing for a detached HEAD.
11
+ *
12
+ * Outside a repository there is neither; the server falls back to the folder.
13
+ */
14
+ import { type LocalFs } from "./cliHookLocal.js";
15
+ export type ProjectInfo = {
16
+ project?: string;
17
+ branch?: string;
18
+ };
19
+ /** What this reads from the machine. Injected so tests never touch it. */
20
+ export type ProjectFs = Pick<LocalFs, "isDirectory" | "isFile" | "readText"> & {
21
+ /** The repository's config, which can be larger than `readText` allows. */
22
+ readConfig?(path: string): string | null;
23
+ };
24
+ export declare const MAX_PROJECT = 80;
25
+ export declare const MAX_BRANCH = 120;
26
+ /**
27
+ * The repository name in a remote URL: `git@github.com:acme/api.git`,
28
+ * `https://github.com/acme/api`, `ssh://git@host:22/acme/api.git/`, or a
29
+ * local path. Query strings and fragments are dropped, so a token in one
30
+ * never comes through.
31
+ */
32
+ export declare function repoNameFromUrl(url: string): string | undefined;
33
+ /** The `url` of `[remote "origin"]` in a git config. */
34
+ export declare function originUrl(config: string): string | undefined;
35
+ /** Detect without caching. Exported for tests. */
36
+ export declare function detectProject(cwd: string, fs: ProjectFs): ProjectInfo;
37
+ /**
38
+ * The project and branch for an agent's working folder, cached per folder
39
+ * for this process. Empty for anything but an absolute path, outside a
40
+ * repository, or on any error.
41
+ */
42
+ export declare function projectOf(cwd: unknown, fs?: ProjectFs): ProjectInfo;
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Which project and branch an agent's command runs in, for grouping sessions
3
+ * by project. Read from the files git writes (no `git` process, no network),
4
+ * once per folder per process, and never throws.
5
+ *
6
+ * - project: the repository's name from its `origin` remote (the last path
7
+ * segment without `.git`; never the owner, host, or full URL), else the
8
+ * main checkout's folder name (so a worktree maps to its repository), else
9
+ * the working folder's own name.
10
+ * - branch: the checked-out branch; nothing for a detached HEAD.
11
+ *
12
+ * Outside a repository there is neither; the server falls back to the folder.
13
+ */
14
+ import { closeSync, openSync, readSync } from "node:fs";
15
+ import { posix } from "node:path";
16
+ import { gitLayout, NODE_FS, readRef } from "./cliHookLocal.js";
17
+ export const MAX_PROJECT = 80;
18
+ export const MAX_BRANCH = 120;
19
+ /** A config's `origin` section sits near the top; this is plenty. */
20
+ const CONFIG_BYTES = 64 * 1024;
21
+ const CACHE_LIMIT = 64;
22
+ function readHead(path) {
23
+ let descriptor;
24
+ try {
25
+ descriptor = openSync(path, "r");
26
+ const buffer = Buffer.alloc(CONFIG_BYTES);
27
+ const read = readSync(descriptor, buffer, 0, CONFIG_BYTES, 0);
28
+ return buffer.toString("utf8", 0, read);
29
+ }
30
+ catch {
31
+ return null;
32
+ }
33
+ finally {
34
+ if (descriptor !== undefined)
35
+ closeSync(descriptor);
36
+ }
37
+ }
38
+ const NODE_PROJECT_FS = { ...NODE_FS, readConfig: readHead };
39
+ /** One line of text: no control characters, trimmed, bounded. */
40
+ function clean(value, max) {
41
+ if (typeof value !== "string")
42
+ return undefined;
43
+ const cleaned = value
44
+ .replace(/[\u0000-\u001f\u007f-\u009f]/g, "")
45
+ .trim()
46
+ .slice(0, max)
47
+ .trim();
48
+ return cleaned || undefined;
49
+ }
50
+ /** A name, never a path: the last segment, without a `.git` suffix. */
51
+ function nameOf(value) {
52
+ if (!value)
53
+ return undefined;
54
+ const trimmed = value.replace(/[\\/]+$/, "");
55
+ const segment = trimmed.slice(Math.max(trimmed.lastIndexOf("/"), trimmed.lastIndexOf("\\"), trimmed.lastIndexOf(":")) + 1);
56
+ const name = clean(segment.replace(/\.git$/i, ""), MAX_PROJECT);
57
+ return name && name !== "." && name !== ".." ? name : undefined;
58
+ }
59
+ /**
60
+ * The repository name in a remote URL: `git@github.com:acme/api.git`,
61
+ * `https://github.com/acme/api`, `ssh://git@host:22/acme/api.git/`, or a
62
+ * local path. Query strings and fragments are dropped, so a token in one
63
+ * never comes through.
64
+ */
65
+ export function repoNameFromUrl(url) {
66
+ const bare = url.trim().replace(/[?#].*$/, "");
67
+ return nameOf(bare);
68
+ }
69
+ /** The `url` of `[remote "origin"]` in a git config. */
70
+ export function originUrl(config) {
71
+ let inOrigin = false;
72
+ for (const raw of config.split(/\r?\n/)) {
73
+ const line = raw.trim();
74
+ if (!line || line.startsWith("#") || line.startsWith(";"))
75
+ continue;
76
+ const section = /^\[\s*([^\]\s"]+)(?:\s+"([^"]*)")?\s*\]/.exec(line);
77
+ if (section) {
78
+ inOrigin = section[1].toLowerCase() === "remote" && section[2] === "origin";
79
+ continue;
80
+ }
81
+ if (!inOrigin)
82
+ continue;
83
+ const entry = /^url\s*=\s*(.*)$/i.exec(line);
84
+ if (entry) {
85
+ const value = entry[1].replace(/^"(.*)"$/, "$1").trim();
86
+ if (value)
87
+ return value;
88
+ }
89
+ }
90
+ return undefined;
91
+ }
92
+ /** The main checkout's folder name: `/code/api/.git` → "api"; a bare `api.git` → "api". */
93
+ function commonName(commonDir) {
94
+ const dir = commonDir.replace(/\/+$/, "");
95
+ return posix.basename(dir) === ".git" ? nameOf(posix.dirname(dir)) : nameOf(dir);
96
+ }
97
+ /** Detect without caching. Exported for tests. */
98
+ export function detectProject(cwd, fs) {
99
+ const layout = gitLayout(posix.normalize(cwd), fs);
100
+ if (!layout)
101
+ return {};
102
+ const configPath = posix.join(layout.commonDir, "config");
103
+ const config = fs.readConfig ? fs.readConfig(configPath) : fs.readText(configPath);
104
+ const remote = config ? originUrl(config) : undefined;
105
+ const project = (remote && repoNameFromUrl(remote)) ?? commonName(layout.commonDir) ?? nameOf(cwd);
106
+ const branch = clean(readRef(fs.readText(posix.join(layout.gitDir, "HEAD")), "refs/heads/"), MAX_BRANCH);
107
+ return { ...(project ? { project } : {}), ...(branch ? { branch } : {}) };
108
+ }
109
+ const cache = new Map();
110
+ /**
111
+ * The project and branch for an agent's working folder, cached per folder
112
+ * for this process. Empty for anything but an absolute path, outside a
113
+ * repository, or on any error.
114
+ */
115
+ export function projectOf(cwd, fs = NODE_PROJECT_FS) {
116
+ if (typeof cwd !== "string" || !cwd.startsWith("/") || cwd.length > 4096)
117
+ return {};
118
+ const cached = fs === NODE_PROJECT_FS ? cache.get(cwd) : undefined;
119
+ if (cached)
120
+ return cached;
121
+ let info = {};
122
+ try {
123
+ info = detectProject(cwd, fs);
124
+ }
125
+ catch {
126
+ info = {};
127
+ }
128
+ if (fs === NODE_PROJECT_FS) {
129
+ if (cache.size >= CACHE_LIMIT)
130
+ cache.delete(cache.keys().next().value);
131
+ cache.set(cwd, info);
132
+ }
133
+ return info;
134
+ }
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * `passport sessions [--status running|idle|ended]`: your agents' recent
3
- * sessions with what Passport decided. On a terminal the rows line up when
4
- * they fit and stack one session at a time when they don't; piped output
5
- * keeps its fixed format.
3
+ * sessions with what Passport decided. Running sessions come first, under
4
+ * their project ("mcp-passport · 2 running"); ended ones follow. On a
5
+ * terminal the rows line up when they fit and stack one session at a time
6
+ * when they don't; piped output keeps its fixed format.
6
7
  */
7
8
  import { type ParsedArgs } from "./cliArgs.js";
8
9
  import { type AutopilotDependencies } from "./cliAutopilot.js";
@@ -12,6 +13,8 @@ type SessionRow = {
12
13
  id?: unknown;
13
14
  client?: unknown;
14
15
  folder?: unknown;
16
+ project?: unknown;
17
+ branch?: unknown;
15
18
  status?: unknown;
16
19
  startedAt?: unknown;
17
20
  lastActivityAt?: unknown;
@@ -25,11 +28,22 @@ type SessionRow = {
25
28
  environments?: unknown;
26
29
  waiting?: unknown;
27
30
  };
28
- /** One session's cells, for the terminal table: status, agent, folder,
29
- * started, counts, and environments with what's waiting. */
31
+ /** Sessions that reported no project or folder (app connections). */
32
+ export declare const NO_PROJECT = "No project";
33
+ /** A checked copy of shared/autopilotContract.ts sessionProject (the CLI
34
+ * can't import shared/): the repository, else the folder's name. */
35
+ export declare function projectOf(row: SessionRow): string | undefined;
36
+ /** One session's cells, for the terminal table: status, agent, branch (or
37
+ * folder), started, counts, and environments with what's waiting. Ended rows
38
+ * name their project too, since no group heading does. */
30
39
  export declare function sessionCells(row: SessionRow, now: number, unicode?: boolean): string[];
40
+ /** Running sessions under their project, busiest-latest first; then the rest. */
41
+ export declare function sessionSections(rows: SessionRow[]): Array<{
42
+ heading: string;
43
+ rows: SessionRow[];
44
+ }>;
31
45
  /** Sessions on a terminal, every one laid out the same way: its state, agent,
32
- * and folder; then when it started, what Passport decided, and where, broken
46
+ * and branch; then when it started, what Passport decided, and where, broken
33
47
  * only between those parts; then its link. */
34
48
  export declare function sessionTable(rows: SessionRow[], links: Array<string | null>, now: number, term: Term): string[];
35
49
  export declare function sessionLine(row: SessionRow, now: number, unicode?: boolean): string;
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * `passport sessions [--status running|idle|ended]`: your agents' recent
3
- * sessions with what Passport decided. On a terminal the rows line up when
4
- * they fit and stack one session at a time when they don't; piped output
5
- * keeps its fixed format.
3
+ * sessions with what Passport decided. Running sessions come first, under
4
+ * their project ("mcp-passport · 2 running"); ended ones follow. On a
5
+ * terminal the rows line up when they fit and stack one session at a time
6
+ * when they don't; piped output keeps its fixed format.
6
7
  */
7
8
  import { value } from "./cliArgs.js";
8
9
  import { api, json } from "./cliAutopilot.js";
@@ -24,6 +25,8 @@ const CLIENT_NAMES = {
24
25
  cli: "Passport CLI",
25
26
  terminal: "Passport CLI"
26
27
  };
28
+ /** Sessions that reported no project or folder (app connections). */
29
+ export const NO_PROJECT = "No project";
27
30
  function count(raw) {
28
31
  return typeof raw === "number" && Number.isFinite(raw) && raw >= 0 ? Math.trunc(raw) : 0;
29
32
  }
@@ -35,8 +38,29 @@ function when(ms, now) {
35
38
  const time = date.toLocaleTimeString("en-US", { hour: "numeric", minute: "2-digit" });
36
39
  return sameDay ? time : `${date.toLocaleDateString("en-US", { month: "short", day: "numeric" })} ${time}`;
37
40
  }
38
- /** One session's cells, for the terminal table: status, agent, folder,
39
- * started, counts, and environments with what's waiting. */
41
+ /** The folder's last segment ("/Users/x/code/api" → "api"). */
42
+ function folderName(raw) {
43
+ const folder = (text(raw, 400) ?? "").replace(/[\\/]+$/, "");
44
+ return text(folder.slice(Math.max(folder.lastIndexOf("/"), folder.lastIndexOf("\\")) + 1), 40);
45
+ }
46
+ /** A checked copy of shared/autopilotContract.ts sessionProject (the CLI
47
+ * can't import shared/): the repository, else the folder's name. */
48
+ export function projectOf(row) {
49
+ return text(row.project, 40) ?? folderName(row.folder);
50
+ }
51
+ /** What a row is called: its branch, else its folder. */
52
+ function placeOf(row) {
53
+ return text(row.branch, 60) ?? folderName(row.folder) ?? "";
54
+ }
55
+ function environmentsOf(row) {
56
+ return Array.isArray(row.environments) ? row.environments.filter(isEnvKind).map((env) => ENV_LABEL[env]) : [];
57
+ }
58
+ function running(row) {
59
+ return row.status === "running" || row.status === "idle";
60
+ }
61
+ /** One session's cells, for the terminal table: status, agent, branch (or
62
+ * folder), started, counts, and environments with what's waiting. Ended rows
63
+ * name their project too, since no group heading does. */
40
64
  export function sessionCells(row, now, unicode = true) {
41
65
  const status = row.status === "running" ? "Running" : row.status === "idle" ? "Idle" : "Ended";
42
66
  const dot = row.status === "running" ? (unicode ? "● " : "* ") : unicode ? "– " : "- ";
@@ -45,21 +69,38 @@ export function sessionCells(row, now, unicode = true) {
45
69
  const parts = [`${count(counts.ran)} ran`, `${count(counts.asked)} asked`];
46
70
  if (count(counts.blocked))
47
71
  parts.push(`${count(counts.blocked)} blocked`);
48
- const environments = Array.isArray(row.environments)
49
- ? row.environments.filter(isEnvKind).map((env) => ENV_LABEL[env])
50
- : [];
72
+ const environments = environmentsOf(row);
51
73
  const waiting = count(row.waiting) ? `Waiting for you (${count(row.waiting)})` : "";
74
+ const project = projectOf(row);
75
+ const place = placeOf(row);
76
+ const where = !running(row) && project && text(row.branch, 60)
77
+ ? `${project} ${unicode ? "›" : ">"} ${place}`
78
+ : place || (running(row) ? "" : (project ?? ""));
52
79
  return [
53
80
  `${dot}${status}`,
54
81
  CLIENT_NAMES[client] ?? client,
55
- text(row.folder, 40) ?? "",
82
+ where,
56
83
  `started ${when(row.startedAt, now)}`,
57
84
  parts.join(" · "),
58
85
  [environments.join(", "), waiting].filter(Boolean).join(" · ")
59
86
  ];
60
87
  }
88
+ /** Running sessions under their project, busiest-latest first; then the rest. */
89
+ export function sessionSections(rows) {
90
+ const latest = (row) => (typeof row.lastActivityAt === "number" ? row.lastActivityAt : 0);
91
+ const groups = new Map();
92
+ for (const row of rows.filter(running).sort((a, b) => latest(b) - latest(a))) {
93
+ const key = projectOf(row) ?? NO_PROJECT;
94
+ groups.set(key, [...(groups.get(key) ?? []), row]);
95
+ }
96
+ const ended = rows.filter((row) => !running(row));
97
+ return [
98
+ ...[...groups].map(([project, members]) => ({ heading: `${project} · ${members.length} running`, rows: members })),
99
+ ...(ended.length ? [{ heading: "Ended", rows: ended }] : [])
100
+ ];
101
+ }
61
102
  /** Sessions on a terminal, every one laid out the same way: its state, agent,
62
- * and folder; then when it started, what Passport decided, and where, broken
103
+ * and branch; then when it started, what Passport decided, and where, broken
63
104
  * only between those parts; then its link. */
64
105
  export function sessionTable(rows, links, now, term) {
65
106
  const cells = rows.map((row) => sessionCells(row, now, term.unicode));
@@ -78,31 +119,23 @@ export function sessionTable(rows, links, now, term) {
78
119
  });
79
120
  }
80
121
  export function sessionLine(row, now, unicode = true) {
81
- const status = row.status === "running" ? "Running" : row.status === "idle" ? "Idle" : "Ended";
82
- const dot = row.status === "running" ? (unicode ? "● " : "* ") : unicode ? "– " : "- ";
83
- const client = text(row.client, 40) ?? "agent";
84
- const name = CLIENT_NAMES[client] ?? client;
85
- const folder = text(row.folder, 40) ?? "";
86
- const counts = row.counts ?? {};
87
- const parts = [`${count(counts.ran)} ran`, `${count(counts.asked)} asked`];
88
- if (count(counts.blocked))
89
- parts.push(`${count(counts.blocked)} blocked`);
90
- const environments = Array.isArray(row.environments)
91
- ? row.environments.filter(isEnvKind).map((env) => ENV_LABEL[env])
92
- : [];
122
+ const [state = "", name = "", where = "", started = "", counts = ""] = sessionCells(row, now, unicode);
93
123
  const waiting = count(row.waiting) ? ` Waiting for you (${count(row.waiting)})` : "";
94
- return [
95
- `${dot}${status.padEnd(7)}`,
96
- name.padEnd(12),
97
- folder.padEnd(18),
98
- `started ${when(row.startedAt, now)}`.padEnd(18),
99
- parts.join(" · "),
100
- environments.length ? ` ${environments.join(", ")}` : ""
101
- ]
124
+ const envs = environmentsOf(row).join(", ");
125
+ return [state.padEnd(9), name.padEnd(12), where.padEnd(18), started.padEnd(18), counts, envs ? ` ${envs}` : ""]
102
126
  .join(" ")
103
127
  .trimEnd()
104
128
  .concat(waiting);
105
129
  }
130
+ /** Every section: its heading, then its rows, with a blank line between. */
131
+ function render(rows, links, now, rowsOf) {
132
+ return sessionSections(rows)
133
+ .map((section) => {
134
+ const sectionLinks = section.rows.map((row) => links[rows.indexOf(row)] ?? null);
135
+ return [section.heading, ...rowsOf(section.rows, sectionLinks)].join("\n");
136
+ })
137
+ .join("\n\n");
138
+ }
106
139
  export async function sessions(args, runtime, deps = {}) {
107
140
  const status = value(args, "status");
108
141
  if (status !== undefined && !["running", "idle", "ended"].includes(status)) {
@@ -123,9 +156,7 @@ export async function sessions(args, runtime, deps = {}) {
123
156
  const human = !rows.length
124
157
  ? "No sessions yet. Start your agent and its actions will show up here."
125
158
  : term.tty
126
- ? sessionTable(rows, links, now, term).join("\n")
127
- : rows
128
- .map((row, index) => links[index] ? `${sessionLine(row, now)}\n ${links[index]}` : sessionLine(row, now))
129
- .join("\n");
159
+ ? render(rows, links, now, (section, sectionLinks) => sessionTable(section, sectionLinks, now, term))
160
+ : render(rows, links, now, (section, sectionLinks) => section.map((row, index) => sectionLinks[index] ? `${sessionLine(row, now)}\n ${sectionLinks[index]}` : sessionLine(row, now)));
130
161
  return { json: { sessions: rows, nextCursor: page.nextCursor ?? null }, human };
131
162
  }
@@ -4,4 +4,4 @@
4
4
  * the version, then runs `npm run set-version -- <version>` in the plugin repo
5
5
  * and pushes (docs/RELEASING.md). `pluginPin.test.ts` fails when it drifts.
6
6
  */
7
- export declare const PLUGIN_PIN = "0.20.0";
7
+ export declare const PLUGIN_PIN = "0.21.0";
package/dist/pluginPin.js CHANGED
@@ -4,4 +4,4 @@
4
4
  * the version, then runs `npm run set-version -- <version>` in the plugin repo
5
5
  * and pushes (docs/RELEASING.md). `pluginPin.test.ts` fails when it drifts.
6
6
  */
7
- export const PLUGIN_PIN = "0.20.0";
7
+ export const PLUGIN_PIN = "0.21.0";
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.20.0";
1
+ export declare const VERSION = "0.21.0";
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // Keep in lockstep with bridge/package.json.
2
- export const VERSION = "0.20.0";
2
+ export const VERSION = "0.21.0";
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "passport-bridge",
3
- "version": "0.20.0",
3
+ "version": "0.21.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "passport-bridge",
9
- "version": "0.20.0",
9
+ "version": "0.21.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@modelcontextprotocol/sdk": "1.32.1"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "passport-bridge",
3
- "version": "0.20.0",
3
+ "version": "0.21.0",
4
4
  "description": "Passport CLI for governed terminal and CI agents, plus the local stdio-to-cloud MCP bridge.",
5
5
  "license": "MIT",
6
6
  "repository": {