passport-bridge 0.31.0 → 0.32.1
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/cliAutopilotPolicy.d.ts +2 -0
- package/dist/cliChanges.d.ts +2 -0
- package/dist/cliChanges.js +6 -2
- package/dist/cliExec.js +10 -26
- package/dist/cliGuardState.d.ts +2 -0
- package/dist/cliGuardState.js +1 -1
- package/dist/cliHook.d.ts +1 -1
- package/dist/cliHook.js +23 -22
- package/dist/cliHookAfter.d.ts +11 -3
- package/dist/cliHookAfter.js +59 -17
- package/dist/cliHookAudit.d.ts +4 -4
- package/dist/cliHookAudit.js +8 -6
- package/dist/cliHookDeliver.d.ts +9 -0
- package/dist/cliHookDeliver.js +27 -1
- package/dist/cliHookExtras.d.ts +3 -2
- package/dist/cliHookExtras.js +5 -5
- package/dist/cliHookLifecycle.d.ts +1 -1
- package/dist/cliHookLifecycle.js +7 -6
- package/dist/cliHookLinks.d.ts +45 -0
- package/dist/cliHookLinks.js +301 -0
- package/dist/cliHookLocal.d.ts +6 -0
- package/dist/cliHookLocal.js +10 -4
- package/dist/cliHookOpaque.d.ts +7 -0
- package/dist/cliHookOpaque.js +6 -0
- package/dist/cliHookProject.d.ts +2 -0
- package/dist/cliHookProject.js +14 -0
- package/dist/cliHookPushed.d.ts +18 -0
- package/dist/cliHookPushed.js +32 -0
- package/dist/cliPolicyV2.js +2 -0
- package/dist/cliSessionsJson.d.ts +4 -0
- package/dist/cliSessionsJson.js +7 -1
- package/dist/cliSessionsRender.js +6 -3
- package/dist/cliStatus.js +10 -5
- package/dist/execLinks.d.ts +66 -0
- package/dist/execLinks.js +124 -0
- package/dist/externalLinks.d.ts +51 -0
- package/dist/externalLinks.js +332 -0
- package/dist/hookFastPath.js +1 -1
- package/dist/launcherFastAnswers.d.ts +26 -0
- package/dist/launcherFastAnswers.js +44 -0
- package/dist/launcherFastPath.d.ts +1 -21
- package/dist/launcherFastPath.js +2 -39
- package/dist/localBackups.js +4 -1
- package/dist/localBackupsGate.d.ts +15 -0
- package/dist/localBackupsGate.js +24 -0
- package/dist/localGit.d.ts +7 -0
- package/dist/localGit.js +44 -16
- package/dist/pluginPin.d.ts +1 -1
- package/dist/pluginPin.js +1 -1
- package/dist/signInFailure.d.ts +6 -2
- package/dist/signInFailure.js +6 -2
- 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/dist/cliHookExtras.js
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
* an agent down).
|
|
6
6
|
*/
|
|
7
7
|
import { claimSeenBatch, noteSeen, seenMark, settleSeenBatch } from "./cliSeen.js";
|
|
8
|
-
import { guardHeartbeat, guardHeartbeatDue } from "./cliGuardHealth.js";
|
|
9
8
|
export const HEARTBEAT_MIN_LEFT_MS = 300;
|
|
10
9
|
const HOOK_RUNTIMES = new Set(["claude-code", "codex", "copilot", "cursor", "other"]);
|
|
11
10
|
/** Count what the guard saw, once even when Cursor runs its imported copy of
|
|
@@ -30,9 +29,10 @@ export function legacySeen(seen) {
|
|
|
30
29
|
: {})
|
|
31
30
|
};
|
|
32
31
|
}
|
|
33
|
-
/** A guard run's first report waits a day; later ones go when due.
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
/** A guard run's first report waits a day; later ones go when due. The
|
|
33
|
+
* report's code (`cliGuardHealth.ts`) loads only here, never on a guard's own path. */
|
|
34
|
+
export async function heartbeatDue(profile, now) {
|
|
35
|
+
return (await import("./cliGuardHealth.js")).guardHeartbeatDue(profile, now, true);
|
|
36
36
|
}
|
|
37
37
|
/** Send one coverage batch under its agent; it counts as sent once Passport took it. */
|
|
38
38
|
export async function sendSeen(claimed, post, profile, now) {
|
|
@@ -43,5 +43,5 @@ export async function sendSeen(claimed, post, profile, now) {
|
|
|
43
43
|
settleSeenBatch(profile, claimed.batch, now);
|
|
44
44
|
}
|
|
45
45
|
export async function heartbeat(api, profile, env, signal, now) {
|
|
46
|
-
await guardHeartbeat(api, profile, env, signal, now);
|
|
46
|
+
await (await import("./cliGuardHealth.js")).guardHeartbeat(api, profile, env, signal, now);
|
|
47
47
|
}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
import { type ParsedArgs } from "./cliArgs.js";
|
|
15
15
|
import type { CliHookReport, HookDependencies, HookRuntime } from "./cliHookDeliver.js";
|
|
16
16
|
import type { HookInput } from "./cliHookInput.js";
|
|
17
|
-
import {
|
|
17
|
+
import type { RepoRuleReport } from "./repoRules.js";
|
|
18
18
|
import type { Env, Runtime } from "./cliSupport.js";
|
|
19
19
|
export declare function isLifecycleEvent(input: HookInput): boolean;
|
|
20
20
|
/** The marker for one lifecycle event, or null (no session id, or not one).
|
package/dist/cliHookLifecycle.js
CHANGED
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
import { value } from "./cliArgs.js";
|
|
15
15
|
import { detectMode } from "./cliHookMode.js";
|
|
16
16
|
import { gitRootOf, projectOf } from "./cliHookProject.js";
|
|
17
|
-
import { markRepoRulesSeen, repoRulesAt } from "./repoRules.js";
|
|
18
17
|
const MODEL = /^[A-Za-z0-9][A-Za-z0-9._:@/[\]-]{0,79}$/;
|
|
19
18
|
const SESSION_ID = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
20
19
|
export function isLifecycleEvent(input) {
|
|
@@ -66,12 +65,13 @@ export function lifecycleReport(input, runtime, env, repoRules = []) {
|
|
|
66
65
|
...(started && repoRules.length ? { repoRules: [...repoRules] } : {})
|
|
67
66
|
};
|
|
68
67
|
}
|
|
69
|
-
/** A start's repo rules: read from the repository's root, new versions only.
|
|
70
|
-
|
|
68
|
+
/** A start's repo rules: read from the repository's root, new versions only.
|
|
69
|
+
* `repoRules.ts` loads only for a start. */
|
|
70
|
+
async function repoRulesOf(input) {
|
|
71
71
|
if (input.hook_event_name !== "SessionStart")
|
|
72
72
|
return { fresh: [], seen: [] };
|
|
73
73
|
const { project } = projectOf(input.cwd);
|
|
74
|
-
return repoRulesAt(gitRootOf(input.cwd) ?? null, project);
|
|
74
|
+
return (await import("./repoRules.js")).repoRulesAt(gitRootOf(input.cwd) ?? null, project);
|
|
75
75
|
}
|
|
76
76
|
/** Which agent: the installed entry names it (`--client codex`); Claude
|
|
77
77
|
* Code's entry is unqualified. */
|
|
@@ -84,11 +84,12 @@ export async function lifecycle(input, args, runtime, deps) {
|
|
|
84
84
|
if (!isLifecycleEvent(input))
|
|
85
85
|
return false;
|
|
86
86
|
const name = runtimeOf(args, runtime.env);
|
|
87
|
-
const rules = repoRulesOf(input);
|
|
87
|
+
const rules = await repoRulesOf(input);
|
|
88
88
|
const report = lifecycleReport(input, name, runtime.env, rules.fresh);
|
|
89
89
|
if (!report)
|
|
90
90
|
return true;
|
|
91
|
-
|
|
91
|
+
if (rules.seen.length)
|
|
92
|
+
(await import("./repoRules.js")).markRepoRulesSeen(rules.seen);
|
|
92
93
|
const deliver = await import("./cliHookDeliver.js");
|
|
93
94
|
const now = (deps.now ?? Date.now)();
|
|
94
95
|
await noteUsage(input, runtime.env, name, deliver.profileAuth(args, runtime.env));
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Links from a command to the real thing (bridge 0.32.0): the pull request
|
|
3
|
+
* `gh pr create` opened, the run `gh run watch` followed, the deployment
|
|
4
|
+
* `railway up` or `vercel deploy` started, the Supabase project a migration
|
|
5
|
+
* went to.
|
|
6
|
+
*
|
|
7
|
+
* First what the command printed: the start and end of its output (at most
|
|
8
|
+
* 16 KB, whole lines), read on this computer. Then what this computer knows
|
|
9
|
+
* when nothing was printed: a `gh pr merge 12` in a folder whose `origin` is
|
|
10
|
+
* on GitHub, a `git push` (the compare page from the lines git prints), a
|
|
11
|
+
* folder linked to a Supabase, Railway, Neon, Fly, or Cloudflare project.
|
|
12
|
+
*
|
|
13
|
+
* Only a URL the allowlist in `externalLinks.ts` (a checked copy of
|
|
14
|
+
* shared/externalLinks.ts) accepts ever leaves, rebuilt from its parts;
|
|
15
|
+
* nothing else from the output does. The server checks each one again.
|
|
16
|
+
*/
|
|
17
|
+
import type { CliFinding } from "./cliHookClassify.js";
|
|
18
|
+
import { type ProjectFs } from "./cliHookProject.js";
|
|
19
|
+
import { type LinkFs } from "./envLinkFs.js";
|
|
20
|
+
import { type KnownLink } from "./externalLinks.js";
|
|
21
|
+
import { type OutputInput } from "./signInFailure.js";
|
|
22
|
+
/** How much of a command's output the hook reads for links: its start and its end. */
|
|
23
|
+
export declare const LINK_HEAD_BYTES: number;
|
|
24
|
+
export declare const LINK_TAIL_BYTES: number;
|
|
25
|
+
/** What link reading may touch. Injected so tests never read the real machine. */
|
|
26
|
+
export type LinksMachine = {
|
|
27
|
+
fs: LinkFs;
|
|
28
|
+
project?: ProjectFs;
|
|
29
|
+
home: string;
|
|
30
|
+
};
|
|
31
|
+
/** The output's start and end, whole lines only, so a cut never shortens an id. */
|
|
32
|
+
export declare function outputForLinks(input: OutputInput): string;
|
|
33
|
+
/**
|
|
34
|
+
* A `git push` to GitHub: the compare page of what it sent, or the branch it
|
|
35
|
+
* created, from the lines git prints ("To github.com:o/r.git" and
|
|
36
|
+
* " 1a2b3c4..5d6e7f8 claude/x -> claude/x").
|
|
37
|
+
*/
|
|
38
|
+
export declare function pushLinks(output: string): KnownLink[];
|
|
39
|
+
/**
|
|
40
|
+
* The links for a command that ran: what it printed, then what this computer
|
|
41
|
+
* knows. Never throws; empty for a command no vendor in it links to. With
|
|
42
|
+
* `ownOnly` (a line with a `passport exec` part, which sends its own links),
|
|
43
|
+
* only links to the vendors of this line's own findings.
|
|
44
|
+
*/
|
|
45
|
+
export declare function linksOf(findings: readonly CliFinding[], input: OutputInput, machine?: LinksMachine, ownOnly?: boolean): string[];
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Links from a command to the real thing (bridge 0.32.0): the pull request
|
|
3
|
+
* `gh pr create` opened, the run `gh run watch` followed, the deployment
|
|
4
|
+
* `railway up` or `vercel deploy` started, the Supabase project a migration
|
|
5
|
+
* went to.
|
|
6
|
+
*
|
|
7
|
+
* First what the command printed: the start and end of its output (at most
|
|
8
|
+
* 16 KB, whole lines), read on this computer. Then what this computer knows
|
|
9
|
+
* when nothing was printed: a `gh pr merge 12` in a folder whose `origin` is
|
|
10
|
+
* on GitHub, a `git push` (the compare page from the lines git prints), a
|
|
11
|
+
* folder linked to a Supabase, Railway, Neon, Fly, or Cloudflare project.
|
|
12
|
+
*
|
|
13
|
+
* Only a URL the allowlist in `externalLinks.ts` (a checked copy of
|
|
14
|
+
* shared/externalLinks.ts) accepts ever leaves, rebuilt from its parts;
|
|
15
|
+
* nothing else from the output does. The server checks each one again.
|
|
16
|
+
*/
|
|
17
|
+
import { homedir } from "node:os";
|
|
18
|
+
import { posix } from "node:path";
|
|
19
|
+
import { gitRootOf, originOf } from "./cliHookProject.js";
|
|
20
|
+
import { NODE_LINK_FS, PROJECT_FILE_MAX, GLOBAL_FILE_MAX, findUp, foldersUp, readLinkFile } from "./envLinkFs.js";
|
|
21
|
+
import { actionLink, actionLinksIn, githubRepoOf, pickLinks, stripeLink, MAX_ACTION_LINKS } from "./externalLinks.js";
|
|
22
|
+
import { ANSI, outputParts } from "./signInFailure.js";
|
|
23
|
+
/** How much of a command's output the hook reads for links: its start and its end. */
|
|
24
|
+
export const LINK_HEAD_BYTES = 6 * 1024;
|
|
25
|
+
export const LINK_TAIL_BYTES = 10 * 1024;
|
|
26
|
+
const NODE_MACHINE = { fs: NODE_LINK_FS, home: homedir() };
|
|
27
|
+
/** The output's start and end, whole lines only, so a cut never shortens an id. */
|
|
28
|
+
export function outputForLinks(input) {
|
|
29
|
+
const text = outputParts(input).join("\n").replace(ANSI, "");
|
|
30
|
+
if (text.length <= LINK_HEAD_BYTES + LINK_TAIL_BYTES)
|
|
31
|
+
return text;
|
|
32
|
+
const head = text.slice(0, LINK_HEAD_BYTES);
|
|
33
|
+
const tail = text.slice(-LINK_TAIL_BYTES);
|
|
34
|
+
return `${head.slice(0, Math.max(0, head.lastIndexOf("\n")))}\n${tail.slice(tail.indexOf("\n") + 1)}`;
|
|
35
|
+
}
|
|
36
|
+
/** The words after the verb that aren't flags or a flag's value. */
|
|
37
|
+
function positionals(args, skip, valued) {
|
|
38
|
+
const out = [];
|
|
39
|
+
for (let index = skip; index < args.length; index++) {
|
|
40
|
+
const word = args[index];
|
|
41
|
+
if (word.startsWith("-")) {
|
|
42
|
+
if (valued.has(word))
|
|
43
|
+
index++;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
out.push(word);
|
|
47
|
+
}
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
/** A flag's value: `--repo x`, `--repo=x`, `-R x`. */
|
|
51
|
+
function flag(args, names) {
|
|
52
|
+
for (let index = 0; index < args.length; index++) {
|
|
53
|
+
const word = args[index];
|
|
54
|
+
for (const name of names) {
|
|
55
|
+
if (word === name)
|
|
56
|
+
return args[index + 1];
|
|
57
|
+
if (word.startsWith(`${name}=`))
|
|
58
|
+
return word.slice(name.length + 1);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
function repoOf(finding, machine) {
|
|
64
|
+
const named = flag(finding.args ?? [], ["-R", "--repo"]);
|
|
65
|
+
if (named)
|
|
66
|
+
return githubRepoOf(`https://github.com/${named.replace(/^https:\/\/github\.com\//, "")}`);
|
|
67
|
+
const origin = originOf(finding.at?.cwd ?? null, machine.project);
|
|
68
|
+
return origin ? githubRepoOf(origin) : null;
|
|
69
|
+
}
|
|
70
|
+
const GH_VALUED = new Set(["-R", "--repo", "-j", "--job", "-L", "--limit", "-a", "--attempt", "-i", "--interval"]);
|
|
71
|
+
const GH_PAGES = {
|
|
72
|
+
"pr merge": "pull",
|
|
73
|
+
"pr view": "pull",
|
|
74
|
+
"pr checkout": "pull",
|
|
75
|
+
"pr close": "pull",
|
|
76
|
+
"pr reopen": "pull",
|
|
77
|
+
"pr ready": "pull",
|
|
78
|
+
"pr review": "pull",
|
|
79
|
+
"pr comment": "pull",
|
|
80
|
+
"pr edit": "pull",
|
|
81
|
+
"pr checks": "pull",
|
|
82
|
+
"issue view": "issues",
|
|
83
|
+
"issue close": "issues",
|
|
84
|
+
"issue reopen": "issues",
|
|
85
|
+
"issue comment": "issues",
|
|
86
|
+
"issue edit": "issues",
|
|
87
|
+
"run view": "actions/runs",
|
|
88
|
+
"run watch": "actions/runs",
|
|
89
|
+
"run rerun": "actions/runs",
|
|
90
|
+
"run cancel": "actions/runs",
|
|
91
|
+
"workflow run": "actions/workflows"
|
|
92
|
+
};
|
|
93
|
+
/** `gh pr merge 12`, `gh run watch 41210596791`, `gh workflow run ci.yml`: the page it acted on. */
|
|
94
|
+
function ghLinks(finding, machine) {
|
|
95
|
+
const args = finding.args ?? [];
|
|
96
|
+
const [noun, verb] = args.filter((word) => !word.startsWith("-"));
|
|
97
|
+
const page = GH_PAGES[`${noun} ${verb}`];
|
|
98
|
+
if (!page)
|
|
99
|
+
return [];
|
|
100
|
+
const words = positionals(args, args.indexOf(verb) + 1, GH_VALUED);
|
|
101
|
+
// A URL names the thing itself.
|
|
102
|
+
const direct = words.map((word) => actionLink(word)).find((link) => link !== null);
|
|
103
|
+
if (direct)
|
|
104
|
+
return [direct];
|
|
105
|
+
const id = page === "actions/workflows"
|
|
106
|
+
? words.find((word) => /^[A-Za-z0-9_.-]{1,100}\.ya?ml$/.test(word))
|
|
107
|
+
: words.map((word) => word.replace(/^#/, "")).find((word) => /^\d{1,15}$/.test(word));
|
|
108
|
+
const repo = id ? repoOf(finding, machine) : null;
|
|
109
|
+
const link = repo ? actionLink(`https://github.com/${repo.owner}/${repo.repo}/${page}/${id}`) : null;
|
|
110
|
+
return link ? [link] : [];
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* A `git push` to GitHub: the compare page of what it sent, or the branch it
|
|
114
|
+
* created, from the lines git prints ("To github.com:o/r.git" and
|
|
115
|
+
* " 1a2b3c4..5d6e7f8 claude/x -> claude/x").
|
|
116
|
+
*/
|
|
117
|
+
export function pushLinks(output) {
|
|
118
|
+
const to = /^To (\S+)$/m.exec(output)?.[1];
|
|
119
|
+
const remote = to?.startsWith("github.com:") ? `git@${to}` : to;
|
|
120
|
+
const repo = remote ? githubRepoOf(remote) : null;
|
|
121
|
+
if (!repo)
|
|
122
|
+
return [];
|
|
123
|
+
const base = `https://github.com/${repo.owner}/${repo.repo}`;
|
|
124
|
+
const update = /^\s*[+ ]?\s*([0-9a-f]{7,40})\.\.\.?([0-9a-f]{7,40})\s+\S+\s+->\s+\S+/m.exec(output);
|
|
125
|
+
if (update)
|
|
126
|
+
return [actionLink(`${base}/compare/${update[1]}...${update[2]}`)];
|
|
127
|
+
const created = /^\s*\*\s+\[new branch\]\s+\S+\s+->\s+(\S+)/m.exec(output);
|
|
128
|
+
const branch = created ? actionLink(`${base}/tree/${created[1]}`) : null;
|
|
129
|
+
return branch ? [branch] : [];
|
|
130
|
+
}
|
|
131
|
+
function nearest(machine, cwd, relative) {
|
|
132
|
+
if (!cwd)
|
|
133
|
+
return null;
|
|
134
|
+
const root = gitRootOf(cwd, machine.project) ?? null;
|
|
135
|
+
const found = findUp(machine.fs, cwd, relative, root, machine.home);
|
|
136
|
+
const read = found ? readLinkFile(machine.fs, found.path, { max: PROJECT_FILE_MAX, inside: root ?? cwd }) : null;
|
|
137
|
+
return read && "text" in read ? read.text : null;
|
|
138
|
+
}
|
|
139
|
+
function record(value) {
|
|
140
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
141
|
+
}
|
|
142
|
+
function json(text) {
|
|
143
|
+
try {
|
|
144
|
+
return text ? record(JSON.parse(text)) : null;
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function one(link) {
|
|
151
|
+
return link ? [link] : [];
|
|
152
|
+
}
|
|
153
|
+
/** `supabase db push`, `functions deploy`, `branches create`: the project, by flag or the folder's link. */
|
|
154
|
+
function supabaseLinks(finding, machine) {
|
|
155
|
+
const args = finding.args ?? [];
|
|
156
|
+
if (args.includes("--local") || args.some((word) => word.startsWith("--db-url")))
|
|
157
|
+
return [];
|
|
158
|
+
const ref = flag(args, ["--project-ref"]) ?? nearest(machine, finding.at?.cwd, "supabase/.temp/project-ref")?.trim();
|
|
159
|
+
if (!ref)
|
|
160
|
+
return [];
|
|
161
|
+
const branches = finding.verb === "branches create";
|
|
162
|
+
return one(actionLink(`https://supabase.com/dashboard/project/${ref}${branches ? "/branches" : ""}`));
|
|
163
|
+
}
|
|
164
|
+
/** The folder's Railway link (`~/.railway/config.json`, walking up): its service, else its project. */
|
|
165
|
+
function railwayLinks(finding, machine) {
|
|
166
|
+
const cwd = finding.at?.cwd;
|
|
167
|
+
if (!cwd)
|
|
168
|
+
return [];
|
|
169
|
+
const read = readLinkFile(machine.fs, posix.join(machine.home, ".railway", "config.json"), { max: GLOBAL_FILE_MAX });
|
|
170
|
+
const projects = record("text" in read ? json(read.text)?.projects : undefined);
|
|
171
|
+
if (!projects)
|
|
172
|
+
return [];
|
|
173
|
+
for (const folder of foldersUp(cwd, null, "/")) {
|
|
174
|
+
const entry = Object.hasOwn(projects, folder) ? record(projects[folder]) : null;
|
|
175
|
+
if (!entry)
|
|
176
|
+
continue;
|
|
177
|
+
const { project, service, environment } = entry;
|
|
178
|
+
const env = typeof environment === "string" ? `?environmentId=${environment}` : "";
|
|
179
|
+
const named = flag(finding.args ?? [], ["-s", "--service"]);
|
|
180
|
+
const path = typeof service === "string" && !named ? `/service/${service}` : "";
|
|
181
|
+
return one(actionLink(`https://railway.com/project/${String(project)}${path}${env}`));
|
|
182
|
+
}
|
|
183
|
+
return [];
|
|
184
|
+
}
|
|
185
|
+
function neonLinks(finding, machine) {
|
|
186
|
+
const id = flag(finding.args ?? [], ["--project-id"]) ?? json(nearest(machine, finding.at?.cwd, ".neon"))?.projectId;
|
|
187
|
+
return typeof id === "string" ? one(actionLink(`https://console.neon.tech/app/projects/${id}`)) : [];
|
|
188
|
+
}
|
|
189
|
+
const TOML_STRING = (key) => new RegExp(`^\\s*${key}\\s*=\\s*["']([^"'\\n]+)["']`, "m");
|
|
190
|
+
function flyLinks(finding, machine) {
|
|
191
|
+
const named = flag(finding.args ?? [], ["-a", "--app"]);
|
|
192
|
+
const app = named ?? TOML_STRING("app").exec(nearest(machine, finding.at?.cwd, "fly.toml") ?? "")?.[1];
|
|
193
|
+
return app ? one(actionLink(`https://fly.io/apps/${app}`)) : [];
|
|
194
|
+
}
|
|
195
|
+
/** `wrangler deploy`: the Worker's page, from the account and name in wrangler.toml. */
|
|
196
|
+
function wranglerLinks(finding, machine) {
|
|
197
|
+
if (finding.verb !== "deploy" && finding.verb !== "publish")
|
|
198
|
+
return [];
|
|
199
|
+
const toml = nearest(machine, finding.at?.cwd, "wrangler.toml") ?? "";
|
|
200
|
+
const account = TOML_STRING("account_id").exec(toml)?.[1];
|
|
201
|
+
const name = TOML_STRING("name").exec(toml)?.[1];
|
|
202
|
+
if (!account || !name)
|
|
203
|
+
return [];
|
|
204
|
+
return one(actionLink(`https://dash.cloudflare.com/${account}/workers/services/view/${name}/production`));
|
|
205
|
+
}
|
|
206
|
+
const AWS_REGION = /^[a-z]{2}(?:-gov)?-[a-z]+-\d$/;
|
|
207
|
+
/** `aws s3 mb s3://bucket`, `aws ec2 run-instances`: the bucket or the instance. */
|
|
208
|
+
function awsLinks(finding, output) {
|
|
209
|
+
const args = finding.args ?? [];
|
|
210
|
+
const region = flag(args, ["--region"]);
|
|
211
|
+
const inRegion = region && AWS_REGION.test(region) ? region : undefined;
|
|
212
|
+
const bucket = finding.verb === "s3 mb" ? /^s3:\/\/([^/\s]+)\/?$/.exec(args.find((word) => word.startsWith("s3://")) ?? "") : null;
|
|
213
|
+
if (bucket) {
|
|
214
|
+
return one(actionLink(`https://s3.console.aws.amazon.com/s3/buckets/${bucket[1]}${inRegion ? `?region=${inRegion}` : ""}`));
|
|
215
|
+
}
|
|
216
|
+
const instance = finding.verb === "ec2 run-instances" ? /"InstanceId":\s*"(i-[0-9a-f]{8,17})"/.exec(output) : null;
|
|
217
|
+
if (!instance || !inRegion)
|
|
218
|
+
return [];
|
|
219
|
+
return one(actionLink(`https://${inRegion}.console.aws.amazon.com/ec2/home?region=${inRegion}#InstanceDetails:instanceId=${instance[1]}`));
|
|
220
|
+
}
|
|
221
|
+
/** A Stripe CLI call that printed one object: its dashboard page, in the mode it ran in. */
|
|
222
|
+
function stripeLinks(output) {
|
|
223
|
+
const start = output.indexOf("{");
|
|
224
|
+
const body = start >= 0 ? json(output.slice(start)) : null;
|
|
225
|
+
if (!body || typeof body.id !== "string" || typeof body.livemode !== "boolean")
|
|
226
|
+
return [];
|
|
227
|
+
return one(stripeLink(body.id, body.livemode));
|
|
228
|
+
}
|
|
229
|
+
function derived(finding, output, machine) {
|
|
230
|
+
switch (finding.vendor) {
|
|
231
|
+
case "gh":
|
|
232
|
+
return ghLinks(finding, machine);
|
|
233
|
+
case "git":
|
|
234
|
+
return finding.verb === "push" ? pushLinks(output) : [];
|
|
235
|
+
case "supabase":
|
|
236
|
+
return supabaseLinks(finding, machine);
|
|
237
|
+
case "railway":
|
|
238
|
+
return railwayLinks(finding, machine);
|
|
239
|
+
case "neonctl":
|
|
240
|
+
case "neon":
|
|
241
|
+
return neonLinks(finding, machine);
|
|
242
|
+
case "flyctl":
|
|
243
|
+
case "fly":
|
|
244
|
+
return flyLinks(finding, machine);
|
|
245
|
+
case "wrangler":
|
|
246
|
+
return wranglerLinks(finding, machine);
|
|
247
|
+
case "aws":
|
|
248
|
+
return awsLinks(finding, output);
|
|
249
|
+
case "stripe":
|
|
250
|
+
return stripeLinks(output);
|
|
251
|
+
default:
|
|
252
|
+
return [];
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/** Vendors whose own CLI says where something landed. */
|
|
256
|
+
const LINKED_VENDORS = new Set([
|
|
257
|
+
"gh",
|
|
258
|
+
"git",
|
|
259
|
+
"railway",
|
|
260
|
+
"vercel",
|
|
261
|
+
"supabase",
|
|
262
|
+
"sentry-cli",
|
|
263
|
+
"neonctl",
|
|
264
|
+
"neon",
|
|
265
|
+
"flyctl",
|
|
266
|
+
"fly",
|
|
267
|
+
"wrangler",
|
|
268
|
+
"stripe",
|
|
269
|
+
"aws"
|
|
270
|
+
]);
|
|
271
|
+
/** Whose pages each vendor CLI's links are. */
|
|
272
|
+
const LINK_VENDOR_OF = {
|
|
273
|
+
gh: "github",
|
|
274
|
+
git: "github",
|
|
275
|
+
"sentry-cli": "sentry",
|
|
276
|
+
neonctl: "neon",
|
|
277
|
+
flyctl: "fly",
|
|
278
|
+
wrangler: "cloudflare"
|
|
279
|
+
};
|
|
280
|
+
/**
|
|
281
|
+
* The links for a command that ran: what it printed, then what this computer
|
|
282
|
+
* knows. Never throws; empty for a command no vendor in it links to. With
|
|
283
|
+
* `ownOnly` (a line with a `passport exec` part, which sends its own links),
|
|
284
|
+
* only links to the vendors of this line's own findings.
|
|
285
|
+
*/
|
|
286
|
+
export function linksOf(findings, input, machine = NODE_MACHINE, ownOnly = false) {
|
|
287
|
+
const linked = findings.filter((finding) => finding.vendor && LINKED_VENDORS.has(finding.vendor) && !finding.inert);
|
|
288
|
+
if (!linked.length)
|
|
289
|
+
return [];
|
|
290
|
+
try {
|
|
291
|
+
const output = outputForLinks(input);
|
|
292
|
+
const printed = actionLinksIn(output, MAX_ACTION_LINKS * 2);
|
|
293
|
+
const known = linked.flatMap((finding) => derived(finding, output, machine));
|
|
294
|
+
const own = new Set(linked.map((finding) => LINK_VENDOR_OF[finding.vendor] ?? finding.vendor));
|
|
295
|
+
const kept = [...printed, ...known].filter((link) => !ownOnly || own.has(link.vendor));
|
|
296
|
+
return pickLinks(kept, MAX_ACTION_LINKS).map((link) => link.url);
|
|
297
|
+
}
|
|
298
|
+
catch {
|
|
299
|
+
return [];
|
|
300
|
+
}
|
|
301
|
+
}
|
package/dist/cliHookLocal.d.ts
CHANGED
|
@@ -71,6 +71,12 @@ export declare function gitBranches(dir: string, fs: LocalFs): {
|
|
|
71
71
|
* `.git` file points at its own). Only for a push, and at most a few tiny reads.
|
|
72
72
|
*/
|
|
73
73
|
export declare function folderPushPlace(args: readonly string[], cwd: string | null, machine: Pick<LocalMachine, "fs">): ReturnType<typeof pushPlace>;
|
|
74
|
+
/** The folder a `git … push` runs in (`-C` moves it; null when unknown) and
|
|
75
|
+
* the arguments after `push`. Undefined for any other git command. */
|
|
76
|
+
export declare function pushFolder(args: readonly string[], cwd: string | null): {
|
|
77
|
+
folder: string | null;
|
|
78
|
+
args: string[];
|
|
79
|
+
} | undefined;
|
|
74
80
|
export type LineResult = {
|
|
75
81
|
findings: CliFinding[];
|
|
76
82
|
/** Every part understood: the only lines Passport may allow. */
|
package/dist/cliHookLocal.js
CHANGED
|
@@ -291,6 +291,15 @@ export function gitBranches(dir, fs) {
|
|
|
291
291
|
* `.git` file points at its own). Only for a push, and at most a few tiny reads.
|
|
292
292
|
*/
|
|
293
293
|
export function folderPushPlace(args, cwd, machine) {
|
|
294
|
+
const push = pushFolder(args, cwd);
|
|
295
|
+
if (!push)
|
|
296
|
+
return undefined;
|
|
297
|
+
const branches = push.folder ? gitBranches(push.folder, machine.fs) : { current: null, defaultBranch: null };
|
|
298
|
+
return pushPlace(push.args, { currentBranch: branches.current, defaultBranch: branches.defaultBranch });
|
|
299
|
+
}
|
|
300
|
+
/** The folder a `git … push` runs in (`-C` moves it; null when unknown) and
|
|
301
|
+
* the arguments after `push`. Undefined for any other git command. */
|
|
302
|
+
export function pushFolder(args, cwd) {
|
|
294
303
|
let index = 0;
|
|
295
304
|
let folder = cwd;
|
|
296
305
|
while (index < args.length && args[index].startsWith("-")) {
|
|
@@ -303,10 +312,7 @@ export function folderPushPlace(args, cwd, machine) {
|
|
|
303
312
|
else
|
|
304
313
|
index++;
|
|
305
314
|
}
|
|
306
|
-
|
|
307
|
-
return undefined;
|
|
308
|
-
const branches = folder ? gitBranches(folder, machine.fs) : { current: null, defaultBranch: null };
|
|
309
|
-
return pushPlace(args.slice(index + 1), { currentBranch: branches.current, defaultBranch: branches.defaultBranch });
|
|
315
|
+
return args[index] === "push" ? { folder, args: args.slice(index + 1) } : undefined;
|
|
310
316
|
}
|
|
311
317
|
const RISK_OF_CLASS = { read: "read", change: "write", delete: "destructive", irreversible: "destructive" };
|
|
312
318
|
/** A local action as a finding the guard and reports understand. */
|
package/dist/cliHookOpaque.d.ts
CHANGED
|
@@ -14,3 +14,10 @@ export declare function opaqueParts(unknown: readonly CliFinding[], max: number)
|
|
|
14
14
|
kinds: string[];
|
|
15
15
|
programs: string[];
|
|
16
16
|
};
|
|
17
|
+
/** Kinds, programs, and the names `cliHookUncheckedName.ts` gives a command's
|
|
18
|
+
* opaque parts (that module loads only when there are some). */
|
|
19
|
+
export declare function opaqueNames(unknown: readonly CliFinding[], max: number): Promise<{
|
|
20
|
+
kinds: string[];
|
|
21
|
+
programs: string[];
|
|
22
|
+
names: string[];
|
|
23
|
+
}>;
|
package/dist/cliHookOpaque.js
CHANGED
|
@@ -27,3 +27,9 @@ export function opaqueParts(unknown, max) {
|
|
|
27
27
|
programs: [...new Set(programs)].slice(0, max)
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
+
/** Kinds, programs, and the names `cliHookUncheckedName.ts` gives a command's
|
|
31
|
+
* opaque parts (that module loads only when there are some). */
|
|
32
|
+
export async function opaqueNames(unknown, max) {
|
|
33
|
+
const { uncheckedNames } = await import("./cliHookUncheckedName.js");
|
|
34
|
+
return { ...opaqueParts(unknown, max), names: uncheckedNames(unknown, max) };
|
|
35
|
+
}
|
package/dist/cliHookProject.d.ts
CHANGED
|
@@ -42,3 +42,5 @@ export declare function detectProject(cwd: string, fs: ProjectFs): ProjectInfo;
|
|
|
42
42
|
export declare function projectOf(cwd: unknown, fs?: ProjectFs): ProjectInfo;
|
|
43
43
|
/** The repository's root folder for an agent's working folder, or undefined. */
|
|
44
44
|
export declare function gitRootOf(cwd: unknown, fs?: ProjectFs): string | undefined;
|
|
45
|
+
/** The `origin` remote's URL for an agent's working folder, read here and never sent; undefined outside a repository. */
|
|
46
|
+
export declare function originOf(cwd: unknown, fs?: ProjectFs): string | undefined;
|
package/dist/cliHookProject.js
CHANGED
|
@@ -143,3 +143,17 @@ export function gitRootOf(cwd, fs = NODE_PROJECT_FS) {
|
|
|
143
143
|
return undefined;
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
|
+
/** The `origin` remote's URL for an agent's working folder, read here and never sent; undefined outside a repository. */
|
|
147
|
+
export function originOf(cwd, fs = NODE_PROJECT_FS) {
|
|
148
|
+
if (typeof cwd !== "string" || !cwd.startsWith("/") || cwd.length > 4096)
|
|
149
|
+
return undefined;
|
|
150
|
+
try {
|
|
151
|
+
const layout = gitLayout(posix.normalize(cwd), fs);
|
|
152
|
+
const configPath = layout ? posix.join(layout.commonDir, "config") : null;
|
|
153
|
+
const config = configPath ? (fs.readConfig ? fs.readConfig(configPath) : fs.readText(configPath)) : null;
|
|
154
|
+
return config ? originUrl(config) : undefined;
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The branch a `git push` sent, for the session's title (bridge 0.31.1).
|
|
3
|
+
*
|
|
4
|
+
* Agents often stay in one folder (the main checkout) and push from other
|
|
5
|
+
* worktrees (`cd ../wt/x && git push -u origin claude/x`), so the folder's
|
|
6
|
+
* own branch never says what they worked on. After a push that succeeded,
|
|
7
|
+
* the report carries the one non-default branch it sent and the name of the
|
|
8
|
+
* repository it ran in (`cliHookProject.ts`), read from the files git writes.
|
|
9
|
+
* Never an argument, a remote, or a URL.
|
|
10
|
+
*/
|
|
11
|
+
import type { CliFinding } from "./cliHookClassify.js";
|
|
12
|
+
import { type LocalFs } from "./cliHookLocal.js";
|
|
13
|
+
export type PushedBranch = {
|
|
14
|
+
branch: string;
|
|
15
|
+
project?: string;
|
|
16
|
+
};
|
|
17
|
+
/** The last non-default branch this command line pushed, or undefined. */
|
|
18
|
+
export declare function pushedOf(findings: readonly CliFinding[], fs?: LocalFs): PushedBranch | undefined;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The branch a `git push` sent, for the session's title (bridge 0.31.1).
|
|
3
|
+
*
|
|
4
|
+
* Agents often stay in one folder (the main checkout) and push from other
|
|
5
|
+
* worktrees (`cd ../wt/x && git push -u origin claude/x`), so the folder's
|
|
6
|
+
* own branch never says what they worked on. After a push that succeeded,
|
|
7
|
+
* the report carries the one non-default branch it sent and the name of the
|
|
8
|
+
* repository it ran in (`cliHookProject.ts`), read from the files git writes.
|
|
9
|
+
* Never an argument, a remote, or a URL.
|
|
10
|
+
*/
|
|
11
|
+
import { gitBranches, NODE_FS, pushFolder } from "./cliHookLocal.js";
|
|
12
|
+
import { detectProject, MAX_BRANCH, projectOf } from "./cliHookProject.js";
|
|
13
|
+
import { pushedBranch } from "./localGit.js";
|
|
14
|
+
const CONTROL = /[\u0000-\u001f\u007f-\u009f\s]/;
|
|
15
|
+
/** The last non-default branch this command line pushed, or undefined. */
|
|
16
|
+
export function pushedOf(findings, fs = NODE_FS) {
|
|
17
|
+
let found;
|
|
18
|
+
for (const finding of findings) {
|
|
19
|
+
if (finding.vendor !== "git" || finding.verb !== "push" || finding.pushEnvironment !== "development")
|
|
20
|
+
continue;
|
|
21
|
+
const push = pushFolder(finding.args ?? [], finding.at?.cwd ?? null);
|
|
22
|
+
if (!push?.folder)
|
|
23
|
+
continue;
|
|
24
|
+
const { current, defaultBranch } = gitBranches(push.folder, fs);
|
|
25
|
+
const branch = pushedBranch(push.args, { currentBranch: current, defaultBranch });
|
|
26
|
+
if (!branch || branch.length > MAX_BRANCH || CONTROL.test(branch))
|
|
27
|
+
continue;
|
|
28
|
+
const { project } = fs === NODE_FS ? projectOf(push.folder) : detectProject(push.folder, fs);
|
|
29
|
+
found = { branch, ...(project ? { project } : {}) };
|
|
30
|
+
}
|
|
31
|
+
return found;
|
|
32
|
+
}
|
package/dist/cliPolicyV2.js
CHANGED
|
@@ -488,6 +488,7 @@ export function serializeCliPolicyV2(policy) {
|
|
|
488
488
|
...(autopilot.reportsSteps ? { descriptions: true } : {}),
|
|
489
489
|
...(autopilot.askLines ? { asks: true } : {}),
|
|
490
490
|
...(autopilot.reportsAfterFacts ? { afterFacts: true } : {}),
|
|
491
|
+
...(autopilot.reportsLinks ? { links: true } : {}),
|
|
491
492
|
...(autopilot.retryLoops ? { retryLoops: true } : {}),
|
|
492
493
|
...(autopilot.heldKeys?.length ? { heldKeys: autopilot.heldKeys } : {}),
|
|
493
494
|
...(autopilot.productionKeys?.length ? { productionKeys: autopilot.productionKeys } : {}),
|
|
@@ -513,6 +514,7 @@ function keptReports(body) {
|
|
|
513
514
|
...(body.descriptions === true ? { reportsSteps: true } : {}),
|
|
514
515
|
...(body.asks === true ? { askLines: true } : {}),
|
|
515
516
|
...(body.afterFacts === true ? { reportsAfterFacts: true } : {}),
|
|
517
|
+
...(body.links === true ? { reportsLinks: true } : {}),
|
|
516
518
|
...(body.retryLoops === true ? { retryLoops: true } : {}),
|
|
517
519
|
...(productionKeys(body.heldKeys) ? { heldKeys: productionKeys(body.heldKeys) } : {})
|
|
518
520
|
};
|
|
@@ -170,6 +170,8 @@ export type TimelineJson = {
|
|
|
170
170
|
unchecked: boolean;
|
|
171
171
|
approvalId: string | null;
|
|
172
172
|
ms: number | null;
|
|
173
|
+
/** Where it landed in the vendor's own app: allowlisted URLs, the thing itself first. */
|
|
174
|
+
links: string[];
|
|
173
175
|
};
|
|
174
176
|
/** `passport sessions <id> --json`. */
|
|
175
177
|
export type SessionJson = {
|
|
@@ -232,6 +234,8 @@ export declare function workGroupOf(raw: unknown, origin?: string): WorkGroupJso
|
|
|
232
234
|
/** Pages merged: a group split across pages joins its first part. */
|
|
233
235
|
export declare function mergeGroups(pages: readonly WorkGroupJson[][]): WorkGroupJson[];
|
|
234
236
|
export declare function ledgerOf(raw: unknown): LedgerJson;
|
|
237
|
+
/** A server's links, checked against the allowlist again: URLs only. */
|
|
238
|
+
export declare function linkUrls(raw: unknown): string[];
|
|
235
239
|
export declare function folderName(raw: unknown): string | undefined;
|
|
236
240
|
export declare function sessionOf(raw: unknown, origin?: string): SessionJson;
|
|
237
241
|
/** "3 pushes, 1 pull request opened, 2 deploys"; null when nothing shipped. */
|
package/dist/cliSessionsJson.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* detail, every string stripped of control characters. Unknown fields drop
|
|
5
5
|
* out; a missing count reads 0.
|
|
6
6
|
*/
|
|
7
|
+
import { checkedLinks } from "./externalLinks.js";
|
|
7
8
|
import { isEnvKind } from "./cliHookEnvironment.js";
|
|
8
9
|
import { taskLink, workLink } from "./webLinks.js";
|
|
9
10
|
export function text(raw, max = 200) {
|
|
@@ -292,9 +293,14 @@ function timelineOf(raw) {
|
|
|
292
293
|
outcome: oneOf(entry.outcome, ["ok", "error", "blocked"]) ?? "ok",
|
|
293
294
|
unchecked: !!entry.unchecked,
|
|
294
295
|
approvalId: text(entry.approvalId, 128) ?? null,
|
|
295
|
-
ms: time(entry.ms)
|
|
296
|
+
ms: time(entry.ms),
|
|
297
|
+
links: linkUrls(entry.links)
|
|
296
298
|
};
|
|
297
299
|
}
|
|
300
|
+
/** A server's links, checked against the allowlist again: URLs only. */
|
|
301
|
+
export function linkUrls(raw) {
|
|
302
|
+
return (checkedLinks(Array.isArray(raw) ? raw.slice(0, 3) : []) ?? []).map((link) => link.url);
|
|
303
|
+
}
|
|
298
304
|
export function folderName(raw) {
|
|
299
305
|
const folder = (text(raw, 400) ?? "").replace(/[\\/]+$/, "");
|
|
300
306
|
return text(folder.slice(Math.max(folder.lastIndexOf("/"), folder.lastIndexOf("\\")) + 1), 60);
|
|
@@ -378,11 +378,14 @@ export function renderSession(detail, term, now) {
|
|
|
378
378
|
const aligned = table(cells, Number.POSITIVE_INFINITY);
|
|
379
379
|
// Too wide: each action stacks, its time and command, then its details
|
|
380
380
|
// broken only between parts.
|
|
381
|
+
// An action's primary link goes under it, beside its command.
|
|
382
|
+
const linked = (index, indent) => recent[index].links[0] ? [`${indent}${recent[index].links[0]}`] : [];
|
|
381
383
|
const rows = aligned.every((line) => visibleLength(line) <= term.width)
|
|
382
|
-
? aligned
|
|
383
|
-
: cells.flatMap(([at = "", command = "", details = ""]) => [
|
|
384
|
+
? aligned.flatMap((line, index) => [line, ...linked(index, " ".repeat(line.indexOf(cells[index][1])))])
|
|
385
|
+
: cells.flatMap(([at = "", command = "", details = ""], index) => [
|
|
384
386
|
...wrap(`${at.padEnd(at.length + 2)}${command}`, term.width, "", " "),
|
|
385
|
-
...joinParts(details.split(" · "), term.width, " ")
|
|
387
|
+
...joinParts(details.split(" · "), term.width, " "),
|
|
388
|
+
...linked(index, " ")
|
|
386
389
|
]);
|
|
387
390
|
const more = detail.timeline.length > RECENT_ROWS || detail.nextCursor;
|
|
388
391
|
blocks.push(["Recent actions", ...rows, ...(more && session.link ? [`Every action: ${session.link}`] : [])].join("\n"));
|