passport-bridge 0.38.0 → 0.41.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 +2 -4
- package/dist/cliExec.d.ts +4 -2
- package/dist/cliExec.js +22 -8
- package/dist/cliHook.d.ts +6 -7
- package/dist/cliHook.js +19 -43
- package/dist/cliHookAfter.js +1 -1
- package/dist/cliHookClassify.d.ts +0 -41
- package/dist/cliHookClassify.js +7 -13
- package/dist/cliHookDecide.d.ts +2 -0
- package/dist/cliHookDecide.js +2 -3
- package/dist/cliHookDeliver.d.ts +3 -30
- package/dist/cliHookDeliver.js +1 -29
- package/dist/cliHookPlace.js +1 -1
- package/dist/cliHookProject.d.ts +1 -1
- package/dist/cliHookProject.js +1 -1
- package/dist/cliHookPushed.d.ts +15 -1
- package/dist/cliHookPushed.js +68 -3
- package/dist/cliHookRewrite.d.ts +6 -5
- package/dist/cliHookRewrite.js +23 -7
- package/dist/cliHookVendorsGitlab.d.ts +1 -3
- package/dist/cliHookVendorsGitlab.js +1 -3
- package/dist/connectorKit/manifests/github.generated.js +1 -1
- package/dist/connectorKit/manifests/githubHooks.generated.js +13 -4
- package/dist/connectorKit/manifests/railway.generated.js +1 -1
- package/dist/controlPlane.generated.d.ts +18 -6
- package/dist/controlPlaneBasic.generated.d.ts +3 -0
- package/dist/controlPlaneBasic.generated.js +9 -1
- package/dist/controlPlaneCli.d.ts +1 -0
- package/dist/controlPlaneCli.js +1 -0
- package/dist/controlPlaneExec.d.ts +3 -0
- package/dist/controlPlaneExec.js +27 -6
- package/dist/controlPlaneGithub.generated.d.ts +2 -2
- package/dist/controlPlaneGithub.generated.js +3 -2
- package/dist/controlPlaneGithubCatalog.generated.d.ts +3 -0
- package/dist/controlPlaneGithubCatalog.generated.js +13 -0
- package/dist/controlPlaneGithubCli.generated.d.ts +9 -0
- package/dist/controlPlaneGithubCli.generated.js +35 -7
- package/dist/controlPlaneModel.generated.d.ts +30 -1
- package/dist/controlPlaneModel.generated.js +51 -1
- package/dist/controlPlaneSupabase.d.ts +3 -0
- package/dist/controlPlaneSupabase.js +8 -0
- package/dist/execGithubRepo.d.ts +23 -2
- package/dist/execGithubRepo.js +120 -8
- package/dist/hookFs.d.ts +39 -0
- package/dist/hookFs.js +128 -0
- package/dist/hookLine.d.ts +67 -0
- package/dist/hookLine.js +263 -0
- package/dist/localIrreversible.d.ts +7 -8
- package/dist/localIrreversible.js +201 -32
- 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/dist/blindKind.d.ts +0 -15
- package/dist/blindKind.js +0 -5
- package/dist/cliHookBlind.d.ts +0 -15
- package/dist/cliHookBlind.js +0 -65
- package/dist/cliHookCoverage.d.ts +0 -20
- package/dist/cliHookCoverage.js +0 -139
- package/dist/cliHookLocal.d.ts +0 -97
- package/dist/cliHookLocal.js +0 -637
- package/dist/cliHookLocalCode.d.ts +0 -56
- package/dist/cliHookLocalCode.js +0 -244
- package/dist/cliHookLocalFs.d.ts +0 -19
- package/dist/cliHookLocalFs.js +0 -108
- package/dist/cliHookOpaque.d.ts +0 -23
- package/dist/cliHookOpaque.js +0 -35
- package/dist/cliHookScripts.d.ts +0 -63
- package/dist/cliHookScripts.js +0 -378
- package/dist/cliHookUncheckedName.d.ts +0 -8
- package/dist/cliHookUncheckedName.js +0 -60
- package/dist/cliScriptRead.d.ts +0 -208
- package/dist/cliScriptRead.js +0 -522
- package/dist/cliScriptText.d.ts +0 -86
- package/dist/cliScriptText.js +0 -440
- package/dist/inlineCode.d.ts +0 -35
- package/dist/inlineCode.js +0 -201
- package/dist/inlineScan.d.ts +0 -23
- package/dist/inlineScan.js +0 -389
- package/dist/localCommands.d.ts +0 -48
- package/dist/localCommands.js +0 -604
- package/dist/localFiles.d.ts +0 -58
- package/dist/localFiles.js +0 -692
- package/dist/localGit.d.ts +0 -56
- package/dist/localGit.js +0 -381
- package/dist/localNetwork.d.ts +0 -16
- package/dist/localNetwork.js +0 -185
- package/dist/localReach.d.ts +0 -43
- package/dist/localReach.js +0 -213
- package/dist/localShared.d.ts +0 -102
- package/dist/localShared.js +0 -173
- package/dist/localTools.d.ts +0 -52
- package/dist/localTools.js +0 -670
- package/dist/repoCheckouts.d.ts +0 -40
- package/dist/repoCheckouts.js +0 -113
package/README.md
CHANGED
|
@@ -204,7 +204,7 @@ passport hook status
|
|
|
204
204
|
passport hook uninstall --agent claude-code --guard --apply # guard only
|
|
205
205
|
```
|
|
206
206
|
|
|
207
|
-
Two hooks per agent. `passport hook` runs after each shell command and records the vendor, a coarse verb and a risk class in Activity (never the command line, its output, or your folder path). `passport hook guard` runs before each command and decides only through the control plane (`src/cliHookDecide.ts`, docs/design/control-plane.md):
|
|
207
|
+
Two hooks per agent. `passport hook` runs after each shell command and, for a vendor command, records the vendor, a coarse verb and a risk class in Activity (never the command line, its output, or your folder path). `passport hook guard` runs before each command and decides only through the control plane (`src/cliHookDecide.ts`, docs/design/control-plane.md):
|
|
208
208
|
|
|
209
209
|
- A consequential `gh`, `git push`, `railway` or `supabase` command on a platform your workspace connected goes to `POST /api/cp/decide` through the classifiers (`src/controlPlaneGuard.ts`, `src/controlPlaneRailwayGuard.ts`, `src/controlPlaneSupabase.ts`).
|
|
210
210
|
- A write or delete verb of a vendor CLI that is a basic platform for you (you hold a working key for it in Passport) goes to `POST /api/cp/decide/cli` with the verb only (`src/controlPlaneCli.ts`).
|
|
@@ -215,9 +215,7 @@ What the guard asks about comes from `GET /api/cp/cli` (`src/cpCli.ts`), cached
|
|
|
215
215
|
|
|
216
216
|
**Speed.** Hooks must never slow agents down. The launcher `$PASSPORT_HOME/cli/bin/passport` (written by `src/initInstall.ts`) answers plain reads and local dev commands in POSIX sh without starting Node (`src/launcherFastPath.ts`): it prints nothing, as the full guard would, and only while the cached `GET /api/cp/cli` is fresh (`cli-policy/fastpath2.ok`).
|
|
217
217
|
|
|
218
|
-
**
|
|
219
|
-
|
|
220
|
-
**Everyday commands** (`src/cliHookLocal.ts`, tables in `src/localCommands.ts`, `localTools.ts`, `localFiles.ts`, `localGit.ts`, `localNetwork.ts`) are classified by what they touch on this computer. The guard says nothing for them, except the ones that can't be undone.
|
|
218
|
+
**How a line is read** (`src/hookLine.ts`). Each simple command is read in the folder it runs in (after a `cd`), and so are the commands a line hides: `bash -c '…'`, `eval`, `$(…)`, a heredoc fed to a shell, a shell script it runs (`./x.sh`, `bash x.sh`, `source x.sh`) and a package script (`npm run x`). Scripts are read only to catch a hidden vendor command or one that can't be undone; nothing is sent. Everyday commands (`ls`, `npm test`, `rm -rf build`) are neither classified nor recorded.
|
|
221
219
|
|
|
222
220
|
- Claude Code: `PreToolUse`, plus `PostToolUse` and `PostToolUseFailure` (failed or interrupted calls, recorded as ran with a non-zero exit), in `~/.claude/settings.json` (`CLAUDE_CONFIG_DIR` honored).
|
|
223
221
|
- Codex: the same events in `~/.codex/hooks.json` (`CODEX_HOME` honored). Codex supports deny only, so it never gets the rewrite.
|
package/dist/cliExec.d.ts
CHANGED
|
@@ -40,12 +40,14 @@ export type ExecDependencies = {
|
|
|
40
40
|
home?: string;
|
|
41
41
|
};
|
|
42
42
|
export { execTarget };
|
|
43
|
-
export {
|
|
44
|
-
/** The classified finding the server decides on: vendor, verb, risk. Never an
|
|
43
|
+
export { githubTarget } from "./execGithubRepo.js";
|
|
44
|
+
/** The classified finding the server decides on: vendor, verb, risk, and for `gh api` the method gh sends. Never an
|
|
45
|
+
* argument. */
|
|
45
46
|
export declare function execFinding(vendor: ExecVendor, binary: string, args: readonly string[]): {
|
|
46
47
|
vendor: string;
|
|
47
48
|
verb: string;
|
|
48
49
|
risk: string;
|
|
50
|
+
method?: string;
|
|
49
51
|
};
|
|
50
52
|
/** Only the vendor's own variables, as plain single-line strings. None for a Railway read Passport sends with the
|
|
51
53
|
* person's own sign-in (`ownSignIn`: Passport mints only for actions). */
|
package/dist/cliExec.js
CHANGED
|
@@ -23,8 +23,9 @@ import { basename } 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 { execControlPlaneRefusal, execIdsWanted, execRailwayScope, execRelease } from "./controlPlaneExec.js";
|
|
26
|
+
import { execControlPlaneRefusal, execIdsWanted, execRailwayScope, execRelease, execSupabaseProject } from "./controlPlaneExec.js";
|
|
27
27
|
import { classifyCommand, UNRECOGNIZED_VERB } from "./cliHookClassify.js";
|
|
28
|
+
import { GH_VALUES, ghApiMethod, parseArgs as parseGhArgs } from "./controlPlaneGithubCli.generated.js";
|
|
28
29
|
import { redactCommand } from "./cliHookRedact.js";
|
|
29
30
|
import { noteExecVendor } from "./execMarker.js";
|
|
30
31
|
import { CliFailure, callerFrom, failure, readBoundedJson, resolveCliAuth, safeApiError, timeoutMs } from "./cliSupport.js";
|
|
@@ -41,8 +42,8 @@ export const EXEC_RESULT_PATH = "/api/my/exec/result";
|
|
|
41
42
|
const SESSION = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
42
43
|
const RUNTIME = /^[a-z0-9-]{1,24}$/;
|
|
43
44
|
export { execTarget };
|
|
44
|
-
export {
|
|
45
|
-
import {
|
|
45
|
+
export { githubTarget } from "./execGithubRepo.js";
|
|
46
|
+
import { githubTarget } from "./execGithubRepo.js";
|
|
46
47
|
function quote(part) {
|
|
47
48
|
return /^[A-Za-z0-9_@%+=:,./-]+$/.test(part) ? part : `'${part.replaceAll("'", `'\\''`)}'`;
|
|
48
49
|
}
|
|
@@ -50,7 +51,8 @@ function quote(part) {
|
|
|
50
51
|
function carrierOf(binary) {
|
|
51
52
|
return !execVendorOf(binary) && Object.hasOwn(EXEC_CARRIERS, binary) ? binary : undefined;
|
|
52
53
|
}
|
|
53
|
-
/** The classified finding the server decides on: vendor, verb, risk. Never an
|
|
54
|
+
/** The classified finding the server decides on: vendor, verb, risk, and for `gh api` the method gh sends. Never an
|
|
55
|
+
* argument. */
|
|
54
56
|
export function execFinding(vendor, binary, args) {
|
|
55
57
|
const command = [binary, ...args].map(quote).join(" ");
|
|
56
58
|
const carrier = carrierOf(binary);
|
|
@@ -66,7 +68,15 @@ export function execFinding(vendor, binary, args) {
|
|
|
66
68
|
.filter((token) => /^-{0,2}[A-Za-z0-9][A-Za-z0-9._:+-]{0,39}$/.test(token))
|
|
67
69
|
.slice(0, 4)
|
|
68
70
|
.join(" ");
|
|
69
|
-
|
|
71
|
+
const finding = { vendor: carrier ?? vendor, verb: verb || UNRECOGNIZED_VERB, risk: found?.risk ?? "unknown" };
|
|
72
|
+
// `gh api`: Passport reads the method (a read isn't decided; anything else is decided), never the endpoint.
|
|
73
|
+
if (vendor !== "gh" || carrier || finding.verb.split(" ")[0] !== "api")
|
|
74
|
+
return finding;
|
|
75
|
+
const parsed = parseGhArgs(args, GH_VALUES.api);
|
|
76
|
+
if (parsed.pos[0] !== "api")
|
|
77
|
+
return finding;
|
|
78
|
+
const { method, read } = ghApiMethod(parsed);
|
|
79
|
+
return { ...finding, method: read ? method : method === "GET" || method === "HEAD" ? "POST" : method };
|
|
70
80
|
}
|
|
71
81
|
/** Only the vendor's own variables, as plain single-line strings. None for a Railway read Passport sends with the
|
|
72
82
|
* person's own sign-in (`ownSignIn`: Passport mints only for actions). */
|
|
@@ -185,7 +195,7 @@ function prepare(args, runtime, deps, auth) {
|
|
|
185
195
|
return failure("--agent must be an agent name.", 6, "usage");
|
|
186
196
|
const rest = args.positionals.slice(1);
|
|
187
197
|
const cwd = deps.cwd ?? process.cwd();
|
|
188
|
-
const
|
|
198
|
+
const gh = vendor === "gh" ? githubTarget(rest, { cwd, env: runtime.env, ...(deps.home ? { home: deps.home } : {}) }) : {};
|
|
189
199
|
const folder = basename(cwd)
|
|
190
200
|
.replace(/[\u0000-\u001f\u007f]/g, "")
|
|
191
201
|
.slice(0, 80);
|
|
@@ -206,7 +216,8 @@ function prepare(args, runtime, deps, auth) {
|
|
|
206
216
|
...(session ? { sessionId: session } : {}),
|
|
207
217
|
...(folder && !/[\\/]/.test(folder) ? { folder } : {}),
|
|
208
218
|
...(summary ? { commandSummary: summary.slice(0, 400) } : {}),
|
|
209
|
-
...(repo ? { repo } : {}),
|
|
219
|
+
...(gh.repo ? { repo: gh.repo } : {}),
|
|
220
|
+
...(gh.repoName ? { repoName: gh.repoName } : {}),
|
|
210
221
|
...(bool(args, "ask-again") ? { askAgain: true } : {})
|
|
211
222
|
}
|
|
212
223
|
};
|
|
@@ -223,6 +234,7 @@ export async function exec(args, runtime, deps = {}) {
|
|
|
223
234
|
const auth = resolveCliAuth(args, runtime.env);
|
|
224
235
|
const prepared = prepare(args, runtime, deps, auth);
|
|
225
236
|
await execRailwayScope(prepared, auth, runtime.env, deps.home, value(args, "decision"));
|
|
237
|
+
await execSupabaseProject(prepared, runtime.env);
|
|
226
238
|
const { vendor, binary } = prepared;
|
|
227
239
|
const client = deps.api ??
|
|
228
240
|
memberApi({ auth, caller: callerFrom(args, runtime.env), timeoutMs: timeoutMs(args), signal: runtime.signal });
|
|
@@ -407,7 +419,9 @@ async function basicDecision(api, profile, prepared, runtime, args) {
|
|
|
407
419
|
return;
|
|
408
420
|
const { askCliVerb } = await import("./controlPlaneCli.js");
|
|
409
421
|
const session = value(args, "session");
|
|
410
|
-
|
|
422
|
+
// Authorize decides it again and spends an Allow once with the credential: this ask only finds it.
|
|
423
|
+
const extra = { exec: true, ...(session ? { sessionId: session } : {}) };
|
|
424
|
+
const answer = await askCliVerb(api, vendor, verb, extra, runtime.signal);
|
|
411
425
|
if (answer.kind === "block")
|
|
412
426
|
failure(answer.message, 5, "blocked");
|
|
413
427
|
}
|
package/dist/cliHook.d.ts
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
* with Passport's own words. Anything Passport doesn't decide gets no answer,
|
|
7
7
|
* so the agent's own permission rules apply. The one allow it gives is the
|
|
8
8
|
* rewrite to `passport exec` (Claude Code), where exec then decides.
|
|
9
|
-
* - `passport hook` (audit) runs after a command. It
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* - `passport hook` (audit) runs after a command. It records the vendor
|
|
10
|
+
* commands the line ran (vendor, a coarse verb and a risk class), one
|
|
11
|
+
* Activity row per line. Everyday commands aren't classified or recorded.
|
|
12
12
|
*
|
|
13
13
|
* Both work inside `HOOK_BUDGET_MS`, and neither ever sends the command line,
|
|
14
14
|
* its arguments, the output, the full working directory, or the environment.
|
|
@@ -19,9 +19,7 @@ import { type ParsedArgs } from "./cliArgs.js";
|
|
|
19
19
|
import { type CliFinding } from "./cliHookClassify.js";
|
|
20
20
|
import { type HookInput } from "./cliHookInput.js";
|
|
21
21
|
import { type CliHookReport, type HookDependencies, type HookRuntime } from "./cliHookDeliver.js";
|
|
22
|
-
export { HOOK_BUDGET_MS, HOOK_RUNTIMES,
|
|
23
|
-
export { opaqueKind, opaqueProgram } from "./cliHookOpaque.js";
|
|
24
|
-
import { type ScriptReader } from "./cliScriptRead.js";
|
|
22
|
+
export { HOOK_BUDGET_MS, HOOK_RUNTIMES, type CliHookReport, type HookDependencies, type HookRuntime, type ReportedFinding } from "./cliHookDeliver.js";
|
|
25
23
|
export { outcomeOf } from "./cliHookOutcome.js";
|
|
26
24
|
import type { CommandResult, Env, Runtime } from "./cliSupport.js";
|
|
27
25
|
export type { HookInput };
|
|
@@ -44,7 +42,8 @@ export declare function safeVerb(raw: string | null): string;
|
|
|
44
42
|
* hooks by default.
|
|
45
43
|
*/
|
|
46
44
|
export declare function detectRuntime(input: HookInput, env: Env, declared?: string): HookRuntime;
|
|
47
|
-
|
|
45
|
+
/** One row for a line that ran vendor commands; null for any other line. */
|
|
46
|
+
export declare function buildReport(input: HookInput, findings: CliFinding[], env: Env, declared?: string): CliHookReport | null;
|
|
48
47
|
/** Normalise one stdin event into the command and when it runs. */
|
|
49
48
|
export declare function shellEvent(input: HookInput): ShellEvent | null;
|
|
50
49
|
/** `passport exec` records its own action, with its decision and credential. */
|
package/dist/cliHook.js
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
* with Passport's own words. Anything Passport doesn't decide gets no answer,
|
|
7
7
|
* so the agent's own permission rules apply. The one allow it gives is the
|
|
8
8
|
* rewrite to `passport exec` (Claude Code), where exec then decides.
|
|
9
|
-
* - `passport hook` (audit) runs after a command. It
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* - `passport hook` (audit) runs after a command. It records the vendor
|
|
10
|
+
* commands the line ran (vendor, a coarse verb and a risk class), one
|
|
11
|
+
* Activity row per line. Everyday commands aren't classified or recorded.
|
|
12
12
|
*
|
|
13
13
|
* Both work inside `HOOK_BUDGET_MS`, and neither ever sends the command line,
|
|
14
14
|
* its arguments, the output, the full working directory, or the environment.
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import { value } from "./cliArgs.js";
|
|
19
19
|
import { summarize, unknownVerb, UNRECOGNIZED_VERB } from "./cliHookClassify.js";
|
|
20
|
-
import { classifyLine, localMachine, workingFolder
|
|
20
|
+
import { classifyLine, localMachine, workingFolder } from "./hookLine.js";
|
|
21
21
|
import { placeOf, reportProject, sessionPlace } from "./cliHookPlace.js";
|
|
22
22
|
import { localRefusal, planGuard } from "./cliHookDecide.js";
|
|
23
23
|
import { denyOutput } from "./cliHookGuard.js";
|
|
@@ -25,16 +25,12 @@ import { localIrreversibleVerbs } from "./localIrreversible.js";
|
|
|
25
25
|
import { permissionModeOf } from "./cliHookMode.js";
|
|
26
26
|
import { commandText, readInput, record, subagentOf } from "./cliHookInput.js";
|
|
27
27
|
import { budgetSignal, HOOK_BUDGET_MS, HOOK_RUNTIMES, leftovers, localProfile, localSelection, agentKeyApi, profileApi, queueAfterCommand, reportSender, runFlush, startFlushIfDue } from "./cliHookDeliver.js";
|
|
28
|
-
export { HOOK_BUDGET_MS, HOOK_RUNTIMES
|
|
29
|
-
import { opaqueNames } from "./cliHookOpaque.js";
|
|
30
|
-
export { opaqueKind, opaqueProgram } from "./cliHookOpaque.js";
|
|
28
|
+
export { HOOK_BUDGET_MS, HOOK_RUNTIMES } from "./cliHookDeliver.js";
|
|
31
29
|
import { readCpCli } from "./cpCli.js";
|
|
32
|
-
import { saveScriptCache, scriptReader, scriptReport } from "./cliScriptRead.js";
|
|
33
30
|
import { standDownForManaged } from "./managedHooks.js";
|
|
34
31
|
import { isCursorEvent, outcomeOfInput } from "./cliHookOutcome.js";
|
|
35
32
|
export { outcomeOf } from "./cliHookOutcome.js";
|
|
36
33
|
const MAX_FINDINGS = 8;
|
|
37
|
-
const MAX_OPAQUE_KINDS = 6;
|
|
38
34
|
const SHELL_TOOLS = new Set(["Bash", "bash", "shell", "Shell"]);
|
|
39
35
|
const VERB_TOKEN = /^-{0,2}[A-Za-z0-9][A-Za-z0-9._:+-]{0,39}$/;
|
|
40
36
|
const VENDOR_NAME = /^[a-z0-9._-]{1,40}$/;
|
|
@@ -105,40 +101,25 @@ function reportable(findings, session = {}) {
|
|
|
105
101
|
return findings
|
|
106
102
|
.filter((finding) => Boolean(finding.vendor))
|
|
107
103
|
.filter((finding) => VENDOR_NAME.test(finding.vendor))
|
|
108
|
-
.filter((finding) => worthReporting(finding))
|
|
109
104
|
.slice(0, MAX_FINDINGS)
|
|
110
105
|
.map((finding) => ({
|
|
111
106
|
vendor: finding.vendor,
|
|
112
107
|
verb: safeVerb(finding.verbKey ?? finding.verb ?? unknownVerb(finding.args)),
|
|
113
108
|
risk: finding.risk,
|
|
114
|
-
// Read from a project script: its name, never its contents (item 6).
|
|
115
|
-
...(finding.from ? { from: finding.from } : {}),
|
|
116
|
-
...(finding.project && !finding.project.repoFile ? { projectAction: finding.project.id } : {}),
|
|
117
109
|
...placeOf(finding, session)
|
|
118
110
|
}));
|
|
119
111
|
}
|
|
120
|
-
|
|
112
|
+
/** One row for a line that ran vendor commands; null for any other line. */
|
|
113
|
+
export function buildReport(input, findings, env, declared) {
|
|
121
114
|
const summary = summarize(findings);
|
|
122
|
-
const extra = scriptReport(scripts);
|
|
123
|
-
// A script that changed under a project action is worth a row of its own.
|
|
124
|
-
if (!summary.governed.length && !summary.opaque && !extra.projectChanged && !extra.drift)
|
|
125
|
-
return null;
|
|
126
115
|
const governed = reportable(summary.governed, sessionPlace(input));
|
|
127
|
-
if (!governed.length
|
|
116
|
+
if (!governed.length)
|
|
128
117
|
return null;
|
|
129
|
-
// What couldn't be read is named only when there is some (`cliHookOpaque.ts`, `cliHookUncheckedName.ts`).
|
|
130
|
-
const { kinds, programs, names } = summary.opaque
|
|
131
|
-
? await opaqueNames(summary.unknown, MAX_OPAQUE_KINDS)
|
|
132
|
-
: { kinds: [], programs: [], names: [] };
|
|
133
118
|
return {
|
|
134
119
|
...context(input, env, declared),
|
|
135
120
|
...outcomeOfInput(input),
|
|
136
121
|
findings: governed,
|
|
137
|
-
opaque: summary.opaque
|
|
138
|
-
...(kinds.length ? { opaqueKinds: kinds } : {}),
|
|
139
|
-
...(programs.length ? { opaquePrograms: programs } : {}),
|
|
140
|
-
...(names.length ? { opaqueNames: names } : {}),
|
|
141
|
-
...extra
|
|
122
|
+
opaque: summary.opaque
|
|
142
123
|
};
|
|
143
124
|
}
|
|
144
125
|
/** Normalise one stdin event into the command and when it runs. */
|
|
@@ -232,12 +213,8 @@ async function runAudit(args, runtime, deps) {
|
|
|
232
213
|
// `passport exec` records its own row; what it created or kept failing at still counts.
|
|
233
214
|
if (isPassportExec(command))
|
|
234
215
|
return void (await after.afterExec({ ...facts, command, args, runtime, deps, base }));
|
|
235
|
-
|
|
236
|
-
const
|
|
237
|
-
const machine = { ...localMachine(workingFolder(input), runtime.env), scripts };
|
|
238
|
-
const findings = classifyLine(command, machine).findings;
|
|
239
|
-
saveScriptCache(scripts);
|
|
240
|
-
const built = await buildReport(input, findings, runtime.env, declared, scripts);
|
|
216
|
+
const findings = classifyLine(command, localMachine(workingFolder(input), runtime.env)).findings;
|
|
217
|
+
const built = buildReport(input, findings, runtime.env, declared);
|
|
241
218
|
// A sign-in that expired, what it created, a retry loop: the report, and what Claude Code reads.
|
|
242
219
|
const { report, output } = await after.afterCommand({ ...facts, command, findings, report: built, base });
|
|
243
220
|
if (output)
|
|
@@ -276,15 +253,14 @@ async function runGuard(args, runtime, deps) {
|
|
|
276
253
|
// Cursor runs the hook it imported from Claude Code too: with Passport's own Cursor entry there, that one decides.
|
|
277
254
|
if (event.cursorImported && (await cursorHasOwnEntry(runtime, "guard")))
|
|
278
255
|
return;
|
|
279
|
-
|
|
280
|
-
const scripts = scriptReader({ phase: "pre", now: deps.budget?.scriptClock });
|
|
281
|
-
const machine = { ...localMachine(workingFolder(input), runtime.env), scripts };
|
|
256
|
+
const machine = localMachine(workingFolder(input), runtime.env);
|
|
282
257
|
const line = classifyLine(event.command, machine);
|
|
283
258
|
const declared = value(args, "client");
|
|
284
259
|
const runtimeName = detectRuntime(input, runtime.env, declared);
|
|
285
260
|
const client = outputClient(event, runtimeName);
|
|
286
261
|
// A command that can't be undone runs only on Passport's allow: out of time or failing, it is refused.
|
|
287
|
-
const local = localIrreversibleVerbs(
|
|
262
|
+
const local = localIrreversibleVerbs(event.command, machine);
|
|
263
|
+
deps.budget?.read?.();
|
|
288
264
|
const refuseLocal = () => {
|
|
289
265
|
if (local[0])
|
|
290
266
|
runtime.stdout.write(`${JSON.stringify(denyOutput(client, localRefusal(local[0], "unreachable")))}\n`);
|
|
@@ -298,9 +274,9 @@ async function runGuard(args, runtime, deps) {
|
|
|
298
274
|
deps,
|
|
299
275
|
input,
|
|
300
276
|
event,
|
|
301
|
-
scripts,
|
|
302
277
|
machine,
|
|
303
278
|
line,
|
|
279
|
+
local,
|
|
304
280
|
declared,
|
|
305
281
|
runtimeName,
|
|
306
282
|
client,
|
|
@@ -314,7 +290,7 @@ async function runGuard(args, runtime, deps) {
|
|
|
314
290
|
}
|
|
315
291
|
/** The guard's answer for a classified line; throws only before it has written an answer. */
|
|
316
292
|
async function guardLine(at) {
|
|
317
|
-
const { args, runtime, deps, input, event, machine, line, declared, client, budget } = at;
|
|
293
|
+
const { args, runtime, deps, input, event, machine, line, local, declared, client, budget } = at;
|
|
318
294
|
const clock = deps.now ?? Date.now;
|
|
319
295
|
const { profile, byDefault } = localSelection(args, runtime.env);
|
|
320
296
|
const cp = profile ? readCpCli(profile) : null;
|
|
@@ -334,7 +310,7 @@ async function guardLine(at) {
|
|
|
334
310
|
toolInput: record(input.tool_input),
|
|
335
311
|
sessionId: sessionOfInput(input),
|
|
336
312
|
named: value(args, "profile"),
|
|
337
|
-
...{ profile, machine, env: runtime.env, invocation: deps.invocation, client, canReport, cp },
|
|
313
|
+
...{ profile, cwd: machine.cwd, env: runtime.env, invocation: deps.invocation, client, canReport, cp },
|
|
338
314
|
cursorImported: Boolean(event.cursorImported),
|
|
339
315
|
ask: { openApi, budget, deadline, now: clock }
|
|
340
316
|
})
|
|
@@ -349,6 +325,7 @@ async function guardLine(at) {
|
|
|
349
325
|
report: context(input, runtime.env, declared),
|
|
350
326
|
command: event.command,
|
|
351
327
|
findings: line.findings,
|
|
328
|
+
local,
|
|
352
329
|
cwd: machine.cwd,
|
|
353
330
|
env: runtime.env,
|
|
354
331
|
budget,
|
|
@@ -366,8 +343,7 @@ async function guardLine(at) {
|
|
|
366
343
|
}
|
|
367
344
|
}
|
|
368
345
|
async function afterAnswer(at) {
|
|
369
|
-
const { args, runtime, deps,
|
|
370
|
-
saveScriptCache(scripts);
|
|
346
|
+
const { args, runtime, deps, runtimeName, profile, byDefault, cp, plan, budget, clock, canReport } = at;
|
|
371
347
|
if (!profile || !canReport)
|
|
372
348
|
return;
|
|
373
349
|
// After the answer, on this computer only: the launcher's fast path, then what a detached flush sends.
|
package/dist/cliHookAfter.js
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* The report carries only the vendor, kinds, names, and counts. Claude Code
|
|
19
19
|
* hears about a sign-in or a retry loop in its own words, as `additionalContext`.
|
|
20
20
|
*/
|
|
21
|
-
import { classifyLine, localMachine, workingFolder } from "./
|
|
21
|
+
import { classifyLine, localMachine, workingFolder } from "./hookLine.js";
|
|
22
22
|
import { execInner } from "./cliHookRewrite.js";
|
|
23
23
|
import { nextRetry, readSessionState, writeSessionState } from "./cliHookSessionState.js";
|
|
24
24
|
import { EXEC_VENDOR_NAMES, vendorCommand } from "./execVendors.js";
|
|
@@ -27,54 +27,13 @@ export type CliFinding = {
|
|
|
27
27
|
/** The words after the program name. Local only; never reported, and read
|
|
28
28
|
* only to find the environment a command acts on. */
|
|
29
29
|
args?: string[];
|
|
30
|
-
/** An everyday command (`cliHookLocal.ts`): its class and environment come
|
|
31
|
-
* from what it touches on this computer, not from the vendor map. */
|
|
32
|
-
local?: LocalFacts;
|
|
33
|
-
/** `git push`: where the push lands, from the branch it pushes. */
|
|
34
|
-
pushEnvironment?: "production" | "development" | "other";
|
|
35
30
|
/** Where this command runs on the machine, for reading folder links: its
|
|
36
31
|
* folder after any `cd`, and database variables set in front of it. Local
|
|
37
32
|
* only; never reported. */
|
|
38
33
|
at?: {
|
|
39
34
|
cwd: string | null;
|
|
40
35
|
};
|
|
41
|
-
/** An unknown part whose class and environment Passport knows (the
|
|
42
|
-
* project's own code read only partly): Placed, not Blind, for coverage.
|
|
43
|
-
* Local only; never reported. */
|
|
44
|
-
placed?: true;
|
|
45
|
-
/** Read from the project's own script (`cliScriptRead.ts`): its name as a
|
|
46
|
-
* person knows it, "deploy.sh" or "make deploy". Reported as provenance. */
|
|
47
|
-
from?: string;
|
|
48
|
-
/** An unchecked part as a person names it: `make release`, `npm run
|
|
49
|
-
* migrate`, `scripts/deploy.sh`. Local; reported only as the safe name
|
|
50
|
-
* `cliHookUncheckedName.ts` makes of it. */
|
|
51
|
-
subject?: string;
|
|
52
|
-
/** Part of code run on the line itself (`node -e`, `npx tsx -e`): there is
|
|
53
|
-
* no script to name or describe. Local only; never reported. */
|
|
54
|
-
inline?: true;
|
|
55
|
-
/** A known project script (item 5): the server's project action that
|
|
56
|
-
* classifies it. It sets class and environment only; it never allows. */
|
|
57
|
-
project?: {
|
|
58
|
-
id: string;
|
|
59
|
-
actionClass: LocalFacts["actionClass"];
|
|
60
|
-
environment: LocalFacts["environment"];
|
|
61
|
-
/** From the repository's `.passport/actions.toml`: it can only make things stricter. */
|
|
62
|
-
repoFile?: true;
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
/** What an everyday command does, worked out on this machine. */
|
|
66
|
-
export type LocalFacts = {
|
|
67
|
-
actionClass: "read" | "change" | "delete" | "irreversible";
|
|
68
|
-
environment: "development" | "production" | "staging" | "other";
|
|
69
|
-
/** In words: "this project", "your home folder", "this computer". */
|
|
70
|
-
touches: string;
|
|
71
|
-
/** Allowed project work and reads: counted, not recorded one by one. */
|
|
72
|
-
quiet: boolean;
|
|
73
|
-
sudo?: true;
|
|
74
36
|
};
|
|
75
|
-
/** A delete inside the temporary folder (a scratchpad, `$TMPDIR/…`; never the
|
|
76
|
-
* folder itself, which is Irreversible): nothing there is worth a backup. */
|
|
77
|
-
export declare function temporaryFiles(finding: CliFinding): boolean;
|
|
78
37
|
export type CliSummary = {
|
|
79
38
|
governed: CliFinding[];
|
|
80
39
|
unknown: CliFinding[];
|
package/dist/cliHookClassify.js
CHANGED
|
@@ -14,11 +14,6 @@ import { awsVerbKey, parseAwsCommand } from "./awsCommands.js";
|
|
|
14
14
|
import { spawnedCommands } from "./cliHookSpawn.js";
|
|
15
15
|
import { NPX_PACKAGE_TO_VENDOR, VENDORS } from "./cliHookVendors.js";
|
|
16
16
|
import { parseKube } from "./kubeCommand.js";
|
|
17
|
-
/** A delete inside the temporary folder (a scratchpad, `$TMPDIR/…`; never the
|
|
18
|
-
* folder itself, which is Irreversible): nothing there is worth a backup. */
|
|
19
|
-
export function temporaryFiles(finding) {
|
|
20
|
-
return finding.local?.actionClass === "delete" && finding.local.touches === "temporary files";
|
|
21
|
-
}
|
|
22
17
|
const RISK_ORDER = {
|
|
23
18
|
local: 0,
|
|
24
19
|
read: 1,
|
|
@@ -60,8 +55,8 @@ export function unknownVerb(args) {
|
|
|
60
55
|
const first = args?.[0];
|
|
61
56
|
return first && SUBCOMMAND_WORD.test(first) ? first : UNRECOGNIZED_VERB;
|
|
62
57
|
}
|
|
63
|
-
function opaque(via, note
|
|
64
|
-
return { vendor: null, verb: null, risk: "unknown", confidence: "low", via, note
|
|
58
|
+
function opaque(via, note) {
|
|
59
|
+
return { vendor: null, verb: null, risk: "unknown", confidence: "low", via, note };
|
|
65
60
|
}
|
|
66
61
|
function classifySql(sql, via) {
|
|
67
62
|
let risk = "read";
|
|
@@ -406,7 +401,7 @@ function classifyPackageRunner(argv, prog, via, envInjected) {
|
|
|
406
401
|
(Object.hasOwn(NPX_PACKAGE_TO_VENDOR, trimmed) ? NPX_PACKAGE_TO_VENDOR[trimmed] : undefined) ??
|
|
407
402
|
(vendorSpec(trimmed) ? trimmed : null);
|
|
408
403
|
if (!vendor)
|
|
409
|
-
return [opaque([...via, prog], `npx package ${raw} not in vendor map
|
|
404
|
+
return [opaque([...via, prog], `npx package ${raw} not in vendor map`)];
|
|
410
405
|
return [classifyVendor(vendor, argv.slice(packageIndex + 1), [...via, prog], envInjected)];
|
|
411
406
|
}
|
|
412
407
|
function classifyInterpreter(argv, prog, via) {
|
|
@@ -417,7 +412,7 @@ function classifyInterpreter(argv, prog, via) {
|
|
|
417
412
|
return hits.map((hit) => ({ ...hit, via: [...via, `${prog} ${argv[codeIndex]}`], confidence: "low" }));
|
|
418
413
|
}
|
|
419
414
|
if (argv.length > 1 && !argv[1].startsWith("-")) {
|
|
420
|
-
return [opaque([...via, prog], `runs script ${argv[1]}; may spawn CLIs
|
|
415
|
+
return [opaque([...via, prog], `runs script ${argv[1]}; may spawn CLIs`)];
|
|
421
416
|
}
|
|
422
417
|
return [];
|
|
423
418
|
}
|
|
@@ -430,7 +425,7 @@ function classifySimpleCommand(argv, via, envInjected, depth) {
|
|
|
430
425
|
return classifyCommand(argv[flagIndex + 1], depth + 1, [...via, `${prog} -c`]);
|
|
431
426
|
}
|
|
432
427
|
if (argv.length > 1 && !argv[1].startsWith("-")) {
|
|
433
|
-
return [opaque([...via, `${prog} <script>`], `runs script file ${argv[1]}; contents not inspectable
|
|
428
|
+
return [opaque([...via, `${prog} <script>`], `runs script file ${argv[1]}; contents not inspectable`)];
|
|
434
429
|
}
|
|
435
430
|
// A bare shell reading stdin reaches us through its nested heredoc.
|
|
436
431
|
return [];
|
|
@@ -438,7 +433,7 @@ function classifySimpleCommand(argv, via, envInjected, depth) {
|
|
|
438
433
|
if (prog === "eval")
|
|
439
434
|
return classifyCommand(argv.slice(1).join(" "), depth + 1, [...via, "eval"]);
|
|
440
435
|
if (prog === "source" || prog === ".") {
|
|
441
|
-
return [opaque([...via, "source"], `sources ${argv[1]}; contents not inspectable
|
|
436
|
+
return [opaque([...via, "source"], `sources ${argv[1]}; contents not inspectable`)];
|
|
442
437
|
}
|
|
443
438
|
if (prog === "xargs")
|
|
444
439
|
return [];
|
|
@@ -453,8 +448,7 @@ function classifySimpleCommand(argv, via, envInjected, depth) {
|
|
|
453
448
|
if (INTERPRETERS.has(prog))
|
|
454
449
|
return classifyInterpreter(argv, prog, via);
|
|
455
450
|
if (prog === "make" || prog === "just" || prog === "task") {
|
|
456
|
-
|
|
457
|
-
return [opaque([...via, prog], `task runner target ${argv[1] || ""}; recipe not inspectable`, `${prog}${target}`)];
|
|
451
|
+
return [opaque([...via, prog], `task runner target ${argv[1] || ""}; recipe not inspectable`)];
|
|
458
452
|
}
|
|
459
453
|
if (prog === "ssh") {
|
|
460
454
|
const rest = argv.slice(1).filter((arg) => !arg.startsWith("-"));
|
package/dist/cliHookDecide.d.ts
CHANGED
|
@@ -37,6 +37,8 @@ export type GuardContext = {
|
|
|
37
37
|
} | null;
|
|
38
38
|
command: string;
|
|
39
39
|
findings: readonly CliFinding[];
|
|
40
|
+
/** What the line does that can't be undone on this computer (`localIrreversible.ts`). */
|
|
41
|
+
local?: readonly LocalIrreversibleVerb[];
|
|
40
42
|
/** The command's folder, for the control plane's repository and branch, and Railway's link. */
|
|
41
43
|
cwd?: string | null;
|
|
42
44
|
/** The agent's environment (Railway's link from the shell; whether `passport exec` issued the credential). */
|
package/dist/cliHookDecide.js
CHANGED
|
@@ -18,7 +18,6 @@
|
|
|
18
18
|
import { homedir } from "node:os";
|
|
19
19
|
import { denyOutput } from "./cliHookGuard.js";
|
|
20
20
|
import { LOCAL_IRREVERSIBLE_VERBS, LOCAL_VENDOR } from "./controlPlaneBasic.generated.js";
|
|
21
|
-
import { localIrreversibleVerbs } from "./localIrreversible.js";
|
|
22
21
|
import { setShadowDeadline } from "./kitShadowBudget.js";
|
|
23
22
|
import { shadowAfterDecision } from "./kitShadow.js";
|
|
24
23
|
/** A cheap check before a classifier loads: `gh …`, a `git … push`, or `railway …`. Every other command pays nothing. */
|
|
@@ -48,7 +47,7 @@ export function vendorVerbs(findings, vendors) {
|
|
|
48
47
|
const seen = new Set();
|
|
49
48
|
const out = [];
|
|
50
49
|
for (const finding of findings) {
|
|
51
|
-
if (!finding.vendor || !vendors.includes(finding.vendor) || finding.
|
|
50
|
+
if (!finding.vendor || !vendors.includes(finding.vendor) || finding.inert)
|
|
52
51
|
continue;
|
|
53
52
|
if (finding.risk !== "write" && finding.risk !== "destructive")
|
|
54
53
|
continue;
|
|
@@ -82,7 +81,7 @@ function asking(context, local) {
|
|
|
82
81
|
}
|
|
83
82
|
/** What the guard answers: a block's refusal, or nothing. */
|
|
84
83
|
export async function planGuard(context) {
|
|
85
|
-
const local =
|
|
84
|
+
const local = context.local ?? [];
|
|
86
85
|
const refuse = (verb, why) => ({
|
|
87
86
|
output: denyOutput(context.client, localRefusal(verb, why))
|
|
88
87
|
});
|
package/dist/cliHookDeliver.d.ts
CHANGED
|
@@ -34,26 +34,6 @@ export type CliHookReport = {
|
|
|
34
34
|
durationMs?: number;
|
|
35
35
|
findings: ReportedFinding[];
|
|
36
36
|
opaque: boolean;
|
|
37
|
-
opaqueKinds?: string[];
|
|
38
|
-
/** The program of each part Passport couldn't check: its first word only
|
|
39
|
-
* (`python`, `make`, `npx`), never a script name or an argument. */
|
|
40
|
-
opaquePrograms?: string[];
|
|
41
|
-
/** Each such part as a person names it, in a safe form
|
|
42
|
-
* (`cliHookUncheckedName.ts`): `scripts/deploy.sh`, `make release`,
|
|
43
|
-
* `npm run migrate`, or the program. Never an argument. */
|
|
44
|
-
opaqueNames?: string[];
|
|
45
|
-
/** Project scripts in this command (item 6): how many parts were fully and
|
|
46
|
-
* partly checked. Counts only. */
|
|
47
|
-
scripts?: {
|
|
48
|
-
checked: number;
|
|
49
|
-
partly: number;
|
|
50
|
-
};
|
|
51
|
-
/** Keyed hashes of the partly checked parts (item 5), never their names. */
|
|
52
|
-
opaqueIds?: string[];
|
|
53
|
-
/** Project actions whose script changed since they were set. Ids only. */
|
|
54
|
-
projectChanged?: string[];
|
|
55
|
-
/** A script changed between the guard's check and the run. */
|
|
56
|
-
drift?: true;
|
|
57
37
|
/** The agent session ended or started (SessionEnd / SessionStart). */
|
|
58
38
|
sessionEnded?: boolean;
|
|
59
39
|
sessionStarted?: true;
|
|
@@ -90,14 +70,10 @@ export type ReportedFinding = {
|
|
|
90
70
|
vendor: string;
|
|
91
71
|
verb: string;
|
|
92
72
|
risk: string;
|
|
93
|
-
/** The project script it was read from: "deploy.sh", "make deploy". */
|
|
94
|
-
from?: string;
|
|
95
73
|
/** Where it actually ran, when not the session's folder (bridge 0.33.0):
|
|
96
74
|
* that folder's repository ("owner/name") and branch. */
|
|
97
75
|
project?: string;
|
|
98
76
|
branch?: string;
|
|
99
|
-
/** The project action that classified it. */
|
|
100
|
-
projectAction?: string;
|
|
101
77
|
};
|
|
102
78
|
export type HookDependencies = {
|
|
103
79
|
/** Deliver one report. The default posts it to the signed-in workspace. */
|
|
@@ -105,12 +81,11 @@ export type HookDependencies = {
|
|
|
105
81
|
/** Network seam for the default delivery and the policy refresh. */
|
|
106
82
|
fetch?: typeof fetch;
|
|
107
83
|
now?: () => number;
|
|
108
|
-
/** The hook's budget
|
|
109
|
-
* `
|
|
110
|
-
* that compares decisions supplies its own so host load cannot change one. */
|
|
84
|
+
/** The hook's budget. By default a `HOOK_BUDGET_MS` timer; a test supplies its own so host load cannot change a
|
|
85
|
+
* decision, and `read` runs once the guard has read the line, before it asks Passport. */
|
|
111
86
|
budget?: {
|
|
112
87
|
signal: AbortSignal;
|
|
113
|
-
|
|
88
|
+
read?: () => void;
|
|
114
89
|
};
|
|
115
90
|
/** How the guard's rewrite starts `passport`; found on PATH by default. */
|
|
116
91
|
invocation?: string;
|
|
@@ -131,8 +106,6 @@ export declare function profileApi(profile: string, signal: AbortSignal, fetcher
|
|
|
131
106
|
/** An agent key's calls (`PASSPORT_AGENT_KEY` with `PASSPORT_ENDPOINT`), as `passport exec` makes them; null without
|
|
132
107
|
* both. */
|
|
133
108
|
export declare function agentKeyApi(env: Env, fetcher: typeof fetch): ApiCall | null;
|
|
134
|
-
/** The report an older server accepts: no script or project-action fields. */
|
|
135
|
-
export declare function legacyReport(report: CliHookReport): CliHookReport | null;
|
|
136
109
|
/** The report a server from before session markers (bridge 0.23.0) accepts,
|
|
137
110
|
* or null: a start marker alone has nothing it knows. */
|
|
138
111
|
export declare function withoutSessionFacts(report: CliHookReport): CliHookReport | null;
|
package/dist/cliHookDeliver.js
CHANGED
|
@@ -64,13 +64,6 @@ export function agentKeyApi(env, fetcher) {
|
|
|
64
64
|
return fetcher(`${origin}${path}`, { ...init, headers });
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
|
-
/** The report an older server accepts: no script or project-action fields. */
|
|
68
|
-
export function legacyReport(report) {
|
|
69
|
-
const { scripts: _scripts, opaqueIds: _ids, projectChanged: _changed, drift: _drift, ...rest } = withoutProject(report);
|
|
70
|
-
if (!rest.findings.length && !rest.opaque)
|
|
71
|
-
return null;
|
|
72
|
-
return { ...rest, findings: report.findings.map(({ vendor, verb, risk }) => ({ vendor, verb, risk })) };
|
|
73
|
-
}
|
|
74
67
|
function hasSessionFacts(report) {
|
|
75
68
|
return report.sessionStarted !== undefined || report.model !== undefined || report.attended !== undefined;
|
|
76
69
|
}
|
|
@@ -85,13 +78,6 @@ export function withoutProject(report) {
|
|
|
85
78
|
const { project: _project, branch: _branch, ...rest } = report;
|
|
86
79
|
return rest;
|
|
87
80
|
}
|
|
88
|
-
function hasScriptFields(report) {
|
|
89
|
-
return (report.scripts !== undefined ||
|
|
90
|
-
report.opaqueIds !== undefined ||
|
|
91
|
-
report.projectChanged !== undefined ||
|
|
92
|
-
report.drift !== undefined ||
|
|
93
|
-
report.findings.some((finding) => finding.from !== undefined || finding.projectAction !== undefined));
|
|
94
|
-
}
|
|
95
81
|
/** Whether a report still says something once a field an older server refuses is gone. */
|
|
96
82
|
function worthSending(report) {
|
|
97
83
|
const facts = report.signIn ?? report.creates ?? report.removes ?? report.retry;
|
|
@@ -154,15 +140,6 @@ async function postFallbacks(post, initial) {
|
|
|
154
140
|
response = await post(report);
|
|
155
141
|
await response.body?.cancel().catch(() => undefined);
|
|
156
142
|
}
|
|
157
|
-
// A server from before unchecked names (bridge 0.31.0) refuses them.
|
|
158
|
-
if (response.status === 400 && report.opaqueNames !== undefined) {
|
|
159
|
-
const { opaqueNames: _names, ...rest } = report;
|
|
160
|
-
report = rest;
|
|
161
|
-
if (!report.findings.length && !report.opaque && !report.sessionStarted && !report.sessionEnded)
|
|
162
|
-
return;
|
|
163
|
-
response = await post(report);
|
|
164
|
-
await response.body?.cancel().catch(() => undefined);
|
|
165
|
-
}
|
|
166
143
|
// A server from before session markers (bridge 0.23.0) refuses their facts.
|
|
167
144
|
if (response.status === 400 && hasSessionFacts(report)) {
|
|
168
145
|
const older = withoutSessionFacts(report);
|
|
@@ -174,13 +151,8 @@ async function postFallbacks(post, initial) {
|
|
|
174
151
|
}
|
|
175
152
|
// A server from before project grouping refuses those two fields: send the rest.
|
|
176
153
|
if (response.status === 400 && (report.project !== undefined || report.branch !== undefined)) {
|
|
177
|
-
|
|
178
|
-
await response.body?.cancel().catch(() => undefined);
|
|
154
|
+
await (await post(withoutProject(report))).body?.cancel().catch(() => undefined);
|
|
179
155
|
}
|
|
180
|
-
// A server that refuses the script fields still gets the row it knows.
|
|
181
|
-
const legacy = response.status === 400 && hasScriptFields(report) ? legacyReport(report) : null;
|
|
182
|
-
if (legacy)
|
|
183
|
-
await (await post(legacy)).body?.cancel().catch(() => undefined);
|
|
184
156
|
}
|
|
185
157
|
/** Deliver reports with the same credential `passport discover` uses. Agent
|
|
186
158
|
* keys are deliberately unsupported: a hook reports a person's own shell.
|
package/dist/cliHookPlace.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* so the action counts for them. Names only; an older server gets the
|
|
8
8
|
* repository's name alone (`cliHookDeliver.ts`).
|
|
9
9
|
*/
|
|
10
|
-
import { workingFolder } from "./
|
|
10
|
+
import { workingFolder } from "./hookLine.js";
|
|
11
11
|
import { projectOf } from "./cliHookProject.js";
|
|
12
12
|
/** The project, how it was known, and the branch of the session's own folder. */
|
|
13
13
|
export function reportProject(cwd) {
|
package/dist/cliHookProject.d.ts
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
*
|
|
17
17
|
* Outside a repository there is neither; the server falls back to the folder.
|
|
18
18
|
*/
|
|
19
|
-
import { type LocalFs } from "./
|
|
19
|
+
import { type LocalFs } from "./hookFs.js";
|
|
20
20
|
import { originUrl, ownerRepoFromUrl } from "./gitRemote.js";
|
|
21
21
|
export { originUrl, ownerRepoFromUrl };
|
|
22
22
|
export type ProjectInfo = {
|