passport-bridge 0.20.0 → 0.22.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/README.md +1 -1
- package/dist/cliAutopilot.d.ts +1 -1
- package/dist/cliAutopilot.js +2 -1
- package/dist/cliExec.js +2 -2
- package/dist/cliHook.js +9 -4
- package/dist/cliHookClassify.d.ts +10 -0
- package/dist/cliHookClassify.js +14 -0
- package/dist/cliHookDecide.js +3 -2
- package/dist/cliHookDeliver.d.ts +6 -0
- package/dist/cliHookDeliver.js +12 -2
- package/dist/cliHookLocal.d.ts +12 -0
- package/dist/cliHookLocal.js +20 -7
- package/dist/cliHookProject.d.ts +42 -0
- package/dist/cliHookProject.js +134 -0
- package/dist/cliSessions.d.ts +20 -6
- package/dist/cliSessions.js +65 -34
- package/dist/cliSpeed.d.ts +2 -1
- package/dist/cliSpeed.js +27 -8
- package/dist/pluginPin.d.ts +1 -1
- package/dist/pluginPin.js +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -287,7 +287,7 @@ passport actions sync # propose this repository's .passport/actions.toml
|
|
|
287
287
|
- `wait` long-polls `GET /api/my/approvals/<id>/wait` (30 s per request), after a short first look that names who decides, until a person decides or the request expires; `--timeout <s>` caps it. Agents run it as a background command and are woken when it exits. Once Passport says the request is still pending (never for one that doesn't exist or is already decided), on a terminal it prints the approval link and one live line (`Waiting for Erin · 1:32 left`); piped, `Waiting for a decision on <id> (until it expires at 14:05).` and `Open in Passport: <url>`. Ctrl-C exits 4 with `The request is still open. Keep waiting any time.` and `Run: passport wait <id>`. Approved: `Approved by Ramish (once). Run the command again.`, or `… for this session. Matching commands in this session run without asking.` (exit 0). Declined: the person's note, cleaned and labelled, `Declined by Ramish. Their note: "Use staging first"` (exit 5, cause `approval_denied`). Expired: `Expired at 14:05 with no decision. Run the command again to ask again.` (exit 5, cause `approval_expired`). Still waiting at `--timeout`: exit 4 with the same command as `next`.
|
|
288
288
|
- `sessions` lists recent sessions (`GET /api/my/agent-sessions`): status, agent, folder, start, `42 ran · 2 asked · 1 blocked`, environments touched, and `Waiting for you` when approvals are pending.
|
|
289
289
|
- `sync` writes the allows Passport is sure of into each agent's own permission settings, so those prompts disappear offline and in Codex (`src/nativeSync.ts`). Only reads, test runners, builds and type checks, linters that only check, `git status`, `git add`, and `git commit`, checked against the person's rules. Formatters, fixing linters, `mv`/`cp`, and package scripts stay with the hook, which sees what they touch; deletes, installs, pushes, and Production never sync. Claude Code: `Bash(npm test *)` in `permissions.allow` of `~/.claude/settings.json`. Codex: `prefix_rule(pattern = ["npm", "test"], decision = "allow")` in `~/.codex/rules/passport.rules`, a file Passport owns. Cursor CLI: `Shell(npm:test*)` in `permissions.allow` of `~/.cursor/cli-config.json`. Cursor: `npm test` in `terminalAllowlist` of `~/.cursor/permissions.json`, only when that list already exists there (defining it replaces Cursor's in-app list). Entries Passport added are listed in `$PASSPORT_HOME/native-sync.json`; an entry you had before is never claimed or removed, and a file Passport can't parse exactly (JSONC) is left alone. Sync runs on `init`, `init --org`, every rules refresh, and `passport sync`; `hook uninstall`, `sync --remove`, and signing out of the last profile take the entries out.
|
|
290
|
-
- `status` is one screen, like `gh auth status`, with a label per row (`You` with the name you signed in as, `Computer`, `Guard`, `Autopilot`, `Apps`, `Keys`, `Shims`, `This folder`, `Allowlists`, `CLI`); under 60 columns each label gets its own row, and piped it never wraps. `Guard` lists each agent's guard (`✓ Claude Code On`, `! Codex Not trusted`) with its fix on the line under it, the coverage line, and sends the daily guard report when due. It also adds today's speed line, `Passport
|
|
290
|
+
- `status` is one screen, like `gh auth status`, with a label per row (`You` with the name you signed in as, `Computer`, `Guard`, `Autopilot`, `Apps`, `Keys`, `Shims`, `This folder`, `Allowlists`, `CLI`); under 60 columns each label gets its own row, and piped it never wraps. `Guard` lists each agent's guard (`✓ Claude Code On`, `! Codex Not trusted`) with its fix on the line under it, the coverage line, and sends the daily guard report when due. It also adds today's speed line, `Passport adds ~20 ms per action and asked you twice today. 412 actions ran on their own.` (across your computers when the server keeps speed numbers, else `(this computer)`), and `Answered for you: N prompts today` (allows the hook gave in Claude Code and Cursor, and Codex commands Passport synced, counted only when the agent would have prompted) and which agents' allowlists are synced. Under the presets, one line per exception that lets something run your presets would ask about, in the web's words: `! 1 exception: deletes run in Production without asking, even without a backup.` Counts are appended locally (`$PASSPORT_HOME/answered/`) and sent in batches at most every five minutes as `answered: {batch, count}` on `POST /api/my/cli-activity`.
|
|
291
291
|
- `actions` tells Passport what a project script does (`src/cliActions.ts`): `actions add <script> [args…] --environment <kind> --class <class>` sends the path in the repository (or `make`, `npm`, `pnpm`, `yarn` with the target), an argument glob, the repository's remote fingerprint and name, and the SHA-256 of what it runs, never its contents, to `POST /api/my/project-actions`. `--id <op_…>` resolves a Session row's **Tell Passport what this does** from this computer's scan cache. `actions sync` proposes each entry of `.passport/actions.toml`. A change, delete, or irreversible in Production applies at once; anything looser waits for an admin. The guard then decides a matching run as vendor `project` with that class and environment; it never makes a line allowed on its own, and a changed script stops matching (`projectChanged`) until it's set again. `.passport/actions.toml` entries apply locally only when they ask or block.
|
|
292
292
|
- `rules test`, `sessions`, `actions`, and `sync` need a member profile. `wait` also works for a cloud agent's agent token, on the approval its own `passport exec` opened.
|
|
293
293
|
|
package/dist/cliAutopilot.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export type AutopilotStatus = {
|
|
|
37
37
|
today: number;
|
|
38
38
|
source: "workspace" | "this-computer";
|
|
39
39
|
};
|
|
40
|
-
/** "Passport
|
|
40
|
+
/** "Passport adds ~20 ms per action and asked you twice today. …": across your
|
|
41
41
|
* computers when Passport keeps the numbers, else this computer's own. */
|
|
42
42
|
speed?: {
|
|
43
43
|
line: string;
|
package/dist/cliAutopilot.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
import { guardStatus } from "./cliStatusGuard.js";
|
|
12
12
|
import { value } from "./cliArgs.js";
|
|
13
13
|
import { CLASS_LABEL, OTHER_APPS, causeSentence, PRESET_ROWS, rowLabel } from "./cliAutopilotPolicy.js";
|
|
14
|
+
import { unknownVerb } from "./cliHookClassify.js";
|
|
14
15
|
import { classifyLine, localMachine } from "./cliHookLocal.js";
|
|
15
16
|
import { ENV_KINDS, isEnvKind } from "./cliHookEnvironment.js";
|
|
16
17
|
import { decideGuard, guardLabel } from "./cliHookGuard.js";
|
|
@@ -92,7 +93,7 @@ function localTest(command, findings, complete, policy, machine) {
|
|
|
92
93
|
*/
|
|
93
94
|
function testBody(lead, label, target, environment) {
|
|
94
95
|
if (lead.local) {
|
|
95
|
-
const finding = { vendor: lead.vendor, verb: lead.verb ??
|
|
96
|
+
const finding = { vendor: lead.vendor, verb: lead.verb ?? unknownVerb(lead.args), risk: lead.risk };
|
|
96
97
|
return { finding: { ...finding, environment: environment ?? lead.local.environment } };
|
|
97
98
|
}
|
|
98
99
|
// Where this computer placed it: a flag, the folder's link, or a mapping.
|
package/dist/cliExec.js
CHANGED
|
@@ -23,7 +23,7 @@ import { basename, dirname, join, resolve } from "node:path";
|
|
|
23
23
|
import { bool, value } from "./cliArgs.js";
|
|
24
24
|
import { memberApi } from "./cliClient.js";
|
|
25
25
|
import { passportUnreachable } from "./cliOutput.js";
|
|
26
|
-
import { classifyCommand } from "./cliHookClassify.js";
|
|
26
|
+
import { classifyCommand, UNRECOGNIZED_VERB } from "./cliHookClassify.js";
|
|
27
27
|
import { reportedEnvironment } from "./cliHookEnvironment.js";
|
|
28
28
|
import { localMachine } from "./cliHookLocal.js";
|
|
29
29
|
import { NODE_LINK_FS } from "./envLinkFs.js";
|
|
@@ -75,7 +75,7 @@ export function execFinding(vendor, binary, args, policy, where) {
|
|
|
75
75
|
const environment = reportedEnvironment(target);
|
|
76
76
|
return {
|
|
77
77
|
vendor,
|
|
78
|
-
verb: verb ||
|
|
78
|
+
verb: verb || UNRECOGNIZED_VERB,
|
|
79
79
|
risk: found?.risk ?? "unknown",
|
|
80
80
|
...(environment ? { environment } : {}),
|
|
81
81
|
// Where it lands, for a server that reads it (Phase 4.5).
|
package/dist/cliHook.js
CHANGED
|
@@ -15,8 +15,9 @@
|
|
|
15
15
|
* open: the agent must never notice this hook going wrong.
|
|
16
16
|
*/
|
|
17
17
|
import { value } from "./cliArgs.js";
|
|
18
|
-
import { summarize } from "./cliHookClassify.js";
|
|
18
|
+
import { summarize, unknownVerb, UNRECOGNIZED_VERB } 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";
|
|
@@ -68,7 +69,7 @@ export function safeVerb(raw) {
|
|
|
68
69
|
.split(/\s+/)
|
|
69
70
|
.filter((token) => VERB_TOKEN.test(token))
|
|
70
71
|
.slice(0, 4);
|
|
71
|
-
return tokens.join(" ").slice(0, 80).trim() ||
|
|
72
|
+
return tokens.join(" ").slice(0, 80).trim() || UNRECOGNIZED_VERB;
|
|
72
73
|
}
|
|
73
74
|
function isCursorEvent(input) {
|
|
74
75
|
return input.hook_event_name === "beforeShellExecution" || input.hook_event_name === "afterShellExecution";
|
|
@@ -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) {
|
|
@@ -141,7 +146,7 @@ function reportable(findings, decided = [], local = false) {
|
|
|
141
146
|
const entry = decided.find((candidate) => candidate.finding === finding);
|
|
142
147
|
return {
|
|
143
148
|
vendor: finding.vendor,
|
|
144
|
-
verb: safeVerb(finding.verbKey ?? finding.verb),
|
|
149
|
+
verb: safeVerb(finding.verbKey ?? finding.verb ?? unknownVerb(finding.args)),
|
|
145
150
|
risk: finding.risk,
|
|
146
151
|
...(entry?.reported ? { environment: entry.reported } : {}),
|
|
147
152
|
...entry?.placement,
|
|
@@ -68,6 +68,16 @@ export type CliSummary = {
|
|
|
68
68
|
maxRisk: CliRisk | "none";
|
|
69
69
|
opaque: boolean;
|
|
70
70
|
};
|
|
71
|
+
/** The verb a command the vendor map doesn't know reports when it has no
|
|
72
|
+
* subcommand to name. The web app reads it as "command not recognized". */
|
|
73
|
+
export declare const UNRECOGNIZED_VERB = "unrecognized";
|
|
74
|
+
/**
|
|
75
|
+
* What to call a command the vendor map doesn't know: its subcommand, the
|
|
76
|
+
* word right after the program (`foo bar --x` is "bar"), else
|
|
77
|
+
* UNRECOGNIZED_VERB. Only lowercase letters and hyphens count as a
|
|
78
|
+
* subcommand, so a path, a value, or a secret is never reported.
|
|
79
|
+
*/
|
|
80
|
+
export declare function unknownVerb(args: readonly string[] | undefined): string;
|
|
71
81
|
/** One simple command's words, wrappers and all, through the vendor map. */
|
|
72
82
|
export declare function classifyArgv(raw: string[], viaOuter?: string[], depth?: number): CliFinding[];
|
|
73
83
|
/** Nested text: a heredoc body reaching a shell, psql, or an interpreter. */
|
package/dist/cliHookClassify.js
CHANGED
|
@@ -38,6 +38,20 @@ function finding(vendor, verb, risk, via, confidence, envInjected) {
|
|
|
38
38
|
...(envInjected.length ? { envInjected: envInjected.map((entry) => entry.split("=")[0]) } : {})
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
|
+
/** The verb a command the vendor map doesn't know reports when it has no
|
|
42
|
+
* subcommand to name. The web app reads it as "command not recognized". */
|
|
43
|
+
export const UNRECOGNIZED_VERB = "unrecognized";
|
|
44
|
+
const SUBCOMMAND_WORD = /^[a-z][a-z-]{0,23}$/;
|
|
45
|
+
/**
|
|
46
|
+
* What to call a command the vendor map doesn't know: its subcommand, the
|
|
47
|
+
* word right after the program (`foo bar --x` is "bar"), else
|
|
48
|
+
* UNRECOGNIZED_VERB. Only lowercase letters and hyphens count as a
|
|
49
|
+
* subcommand, so a path, a value, or a secret is never reported.
|
|
50
|
+
*/
|
|
51
|
+
export function unknownVerb(args) {
|
|
52
|
+
const first = args?.[0];
|
|
53
|
+
return first && SUBCOMMAND_WORD.test(first) ? first : UNRECOGNIZED_VERB;
|
|
54
|
+
}
|
|
41
55
|
function opaque(via, note) {
|
|
42
56
|
return { vendor: null, verb: null, risk: "unknown", confidence: "low", via, note };
|
|
43
57
|
}
|
package/dist/cliHookDecide.js
CHANGED
|
@@ -21,6 +21,7 @@ import { isEnvKind } from "./cliHookEnvironment.js";
|
|
|
21
21
|
import { askMessage, guardOutput, waitingMessage } from "./cliHookGuard.js";
|
|
22
22
|
import { OFFLINE_CACHE_MAX_MS, OFFLINE_DEFAULT, OFFLINE_NOTES, offlineDecision } from "./cliGuardState.js";
|
|
23
23
|
import { commandKey } from "./cliHookKey.js";
|
|
24
|
+
import { unknownVerb, UNRECOGNIZED_VERB } from "./cliHookClassify.js";
|
|
24
25
|
import { redactCommand } from "./cliHookRedact.js";
|
|
25
26
|
export const CLI_DECIDE_PATH = "/api/my/cli/decide";
|
|
26
27
|
const MAX_RESPONSE_BYTES = 16 * 1024;
|
|
@@ -82,7 +83,7 @@ function safeVerbOf(raw) {
|
|
|
82
83
|
.split(/\s+/)
|
|
83
84
|
.filter((token) => VERB_TOKEN.test(token))
|
|
84
85
|
.slice(0, 4);
|
|
85
|
-
return tokens.join(" ").slice(0, 80).trim() ||
|
|
86
|
+
return tokens.join(" ").slice(0, 80).trim() || UNRECOGNIZED_VERB;
|
|
86
87
|
}
|
|
87
88
|
export function decideRequest(decision, context, command, local = false) {
|
|
88
89
|
const findings = (decision.decided ?? [])
|
|
@@ -92,7 +93,7 @@ export function decideRequest(decision, context, command, local = false) {
|
|
|
92
93
|
.slice(0, MAX_FINDINGS)
|
|
93
94
|
.map((entry) => ({
|
|
94
95
|
vendor: entry.finding.vendor,
|
|
95
|
-
verb: safeVerbOf(entry.finding.verbKey ?? entry.finding.verb),
|
|
96
|
+
verb: safeVerbOf(entry.finding.verbKey ?? entry.finding.verb ?? unknownVerb(entry.finding.args)),
|
|
96
97
|
risk: entry.finding.risk,
|
|
97
98
|
...(entry.reported ? { environment: entry.reported } : {}),
|
|
98
99
|
...entry.placement
|
package/dist/cliHookDeliver.d.ts
CHANGED
|
@@ -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.
|
package/dist/cliHookDeliver.js
CHANGED
|
@@ -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
|
-
|
|
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)
|
package/dist/cliHookLocal.d.ts
CHANGED
|
@@ -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;
|
package/dist/cliHookLocal.js
CHANGED
|
@@ -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
|
-
/**
|
|
327
|
-
|
|
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
|
|
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
|
|
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
|
+
}
|
package/dist/cliSessions.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `passport sessions [--status running|idle|ended]`: your agents' recent
|
|
3
|
-
* sessions with what Passport decided.
|
|
4
|
-
*
|
|
5
|
-
*
|
|
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
|
-
/**
|
|
29
|
-
|
|
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
|
|
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;
|
package/dist/cliSessions.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `passport sessions [--status running|idle|ended]`: your agents' recent
|
|
3
|
-
* sessions with what Passport decided.
|
|
4
|
-
*
|
|
5
|
-
*
|
|
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
|
-
/**
|
|
39
|
-
|
|
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 =
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
95
|
-
|
|
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
|
-
?
|
|
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
|
}
|
package/dist/cliSpeed.d.ts
CHANGED
|
@@ -78,11 +78,12 @@ export declare function settleSpeedBatch(profile: string, batch: string, now?: n
|
|
|
78
78
|
export type SpeedToday = {
|
|
79
79
|
checks: number;
|
|
80
80
|
addedMs: number;
|
|
81
|
+
p50Ms: number;
|
|
81
82
|
asked: number;
|
|
82
83
|
ranOnTheirOwn: number;
|
|
83
84
|
};
|
|
84
85
|
export declare function summarizeToday(entries: readonly SpeedClientBatch[]): SpeedToday;
|
|
85
|
-
/** "Passport
|
|
86
|
+
/** "Passport adds ~20 ms per action and asked you twice today. 412 actions ran on their own." */
|
|
86
87
|
export declare function speedLine(today: SpeedToday): string | null;
|
|
87
88
|
/** Today on this computer, for `passport status` when Passport can't say. */
|
|
88
89
|
export declare function speedToday(profile: string, now?: number): SpeedClientBatch[];
|
package/dist/cliSpeed.js
CHANGED
|
@@ -222,21 +222,39 @@ export function settleSpeedBatch(profile, batch, now = Date.now()) {
|
|
|
222
222
|
/* Sent again next time, under the same batch id. */
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
|
+
/** The bucket bound holding the median run (`percentileMs` in shared/speedContract.ts). */
|
|
226
|
+
function medianMs(buckets) {
|
|
227
|
+
const total = buckets.reduce((sum, n) => sum + n, 0);
|
|
228
|
+
if (!total)
|
|
229
|
+
return 0;
|
|
230
|
+
const wanted = Math.max(1, Math.ceil(total * 0.5));
|
|
231
|
+
let seen = 0;
|
|
232
|
+
for (let index = 0; index < buckets.length; index++) {
|
|
233
|
+
seen += buckets[index] ?? 0;
|
|
234
|
+
if (seen >= wanted)
|
|
235
|
+
return index < SPEED_BUCKETS_MS.length ? SPEED_BUCKETS_MS[index] : 5000;
|
|
236
|
+
}
|
|
237
|
+
return 5000;
|
|
238
|
+
}
|
|
225
239
|
export function summarizeToday(entries) {
|
|
226
240
|
const sum = (pick) => entries.reduce((total, entry) => total + pick(entry), 0);
|
|
241
|
+
const buckets = SPEED_BUCKETS_MS.map((_, index) => sum((entry) => entry.buckets[index] ?? 0));
|
|
242
|
+
buckets.push(sum((entry) => entry.buckets[SPEED_BUCKETS_MS.length] ?? 0));
|
|
227
243
|
return {
|
|
228
244
|
checks: sum((entry) => entry.count),
|
|
229
245
|
addedMs: sum((entry) => entry.sumMs),
|
|
246
|
+
p50Ms: medianMs(buckets),
|
|
230
247
|
asked: sum((entry) => entry.ask),
|
|
231
248
|
ranOnTheirOwn: sum((entry) => entry.allow + entry.none)
|
|
232
249
|
};
|
|
233
250
|
}
|
|
234
|
-
function
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
251
|
+
function perAction(p50Ms) {
|
|
252
|
+
const last = SPEED_BUCKETS_MS[SPEED_BUCKETS_MS.length - 1];
|
|
253
|
+
if (p50Ms > last)
|
|
254
|
+
return `over ${last / 1000} s`;
|
|
255
|
+
if (p50Ms >= 1000)
|
|
256
|
+
return `~${p50Ms / 1000} s`;
|
|
257
|
+
return `~${p50Ms} ms`;
|
|
240
258
|
}
|
|
241
259
|
function times(count) {
|
|
242
260
|
if (count === 0)
|
|
@@ -247,13 +265,13 @@ function times(count) {
|
|
|
247
265
|
return "asked you twice";
|
|
248
266
|
return `asked you ${count.toLocaleString("en-US")} times`;
|
|
249
267
|
}
|
|
250
|
-
/** "Passport
|
|
268
|
+
/** "Passport adds ~20 ms per action and asked you twice today. 412 actions ran on their own." */
|
|
251
269
|
export function speedLine(today) {
|
|
252
270
|
if (!today.checks)
|
|
253
271
|
return null;
|
|
254
272
|
const ran = today.ranOnTheirOwn;
|
|
255
273
|
const own = `${ran.toLocaleString("en-US")} ${ran === 1 ? "action ran on its own" : "actions ran on their own"}.`;
|
|
256
|
-
return `Passport
|
|
274
|
+
return `Passport adds ${perAction(today.p50Ms)} per action and ${times(today.asked)} today. ${own}`;
|
|
257
275
|
}
|
|
258
276
|
/** Today on this computer, for `passport status` when Passport can't say. */
|
|
259
277
|
export function speedToday(profile, now = Date.now()) {
|
|
@@ -302,6 +320,7 @@ export async function todayStatus(fetchApi, profile, signal, now) {
|
|
|
302
320
|
? {
|
|
303
321
|
checks: amount(reported.checks) ?? 0,
|
|
304
322
|
addedMs: amount(reported.addedMs) ?? 0,
|
|
323
|
+
p50Ms: amount(reported.p50Ms) ?? 0,
|
|
305
324
|
asked: amount(reported.asked) ?? 0,
|
|
306
325
|
ranOnTheirOwn: amount(reported.ranOnTheirOwn) ?? 0
|
|
307
326
|
}
|
package/dist/pluginPin.d.ts
CHANGED
package/dist/pluginPin.js
CHANGED
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.22.0";
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Keep in lockstep with bridge/package.json.
|
|
2
|
-
export const VERSION = "0.
|
|
2
|
+
export const VERSION = "0.22.0";
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "passport-bridge",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "passport-bridge",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.22.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@modelcontextprotocol/sdk": "1.32.1"
|