passport-bridge 0.26.0 → 0.27.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 -2
- package/dist/blindKind.d.ts +15 -0
- package/dist/blindKind.js +5 -0
- package/dist/cliChanges.d.ts +12 -4
- package/dist/cliChanges.js +26 -15
- package/dist/cliGuardState.js +2 -2
- package/dist/cliHookBlind.d.ts +15 -0
- package/dist/cliHookBlind.js +65 -0
- package/dist/cliHookLocal.d.ts +7 -16
- package/dist/cliHookLocal.js +75 -97
- package/dist/cliHookLocalCode.js +7 -1
- package/dist/cliHookLocalFs.d.ts +15 -0
- package/dist/cliHookLocalFs.js +77 -0
- package/dist/cliHookScripts.d.ts +2 -1
- package/dist/cliOutput.js +2 -2
- package/dist/cliProjectSummary.d.ts +1 -1
- package/dist/cliProjectSummary.js +19 -8
- package/dist/cliScriptRead.d.ts +5 -4
- package/dist/cliScriptRead.js +3 -2
- package/dist/cliSeen.d.ts +24 -15
- package/dist/cliSeen.js +34 -16
- package/dist/cliSessions.js +20 -6
- package/dist/cliSessionsJson.d.ts +48 -0
- package/dist/cliSessionsJson.js +40 -10
- package/dist/cliSessionsRender.d.ts +4 -0
- package/dist/cliSessionsRender.js +42 -8
- package/dist/inlineCode.d.ts +35 -0
- package/dist/inlineCode.js +201 -0
- package/dist/inlineScan.d.ts +23 -0
- package/dist/inlineScan.js +389 -0
- package/dist/localCommands.d.ts +10 -3
- package/dist/localCommands.js +59 -37
- package/dist/localFiles.d.ts +38 -2
- package/dist/localFiles.js +453 -33
- package/dist/localGit.js +53 -17
- package/dist/localShared.d.ts +3 -0
- 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
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/** The hook's view of this computer's files (`cliHookLocal.ts`): injected so tests never touch them. */
|
|
2
|
+
import { closeSync, fstatSync, lstatSync, openSync, readFileSync, readSync, realpathSync, statSync } from "node:fs";
|
|
3
|
+
import { SCRIPT_MAX_BYTES } from "./cliScriptRead.js";
|
|
4
|
+
const MAX_TEXT = 4096;
|
|
5
|
+
export const NODE_FS = {
|
|
6
|
+
realpath(path) {
|
|
7
|
+
try {
|
|
8
|
+
return realpathSync.native(path);
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
readText(path) {
|
|
15
|
+
try {
|
|
16
|
+
if (statSync(path).size > MAX_TEXT)
|
|
17
|
+
return null;
|
|
18
|
+
return readFileSync(path, "utf8");
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
isDirectory(path) {
|
|
25
|
+
try {
|
|
26
|
+
return statSync(path).isDirectory();
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
isFile(path) {
|
|
33
|
+
try {
|
|
34
|
+
return lstatSync(path).isFile() || statSync(path).isFile();
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
readScript(path) {
|
|
41
|
+
let descriptor;
|
|
42
|
+
try {
|
|
43
|
+
descriptor = openSync(path, "r");
|
|
44
|
+
const stat = fstatSync(descriptor);
|
|
45
|
+
if (!stat.isFile() || stat.size > SCRIPT_MAX_BYTES)
|
|
46
|
+
return null;
|
|
47
|
+
const buffer = Buffer.alloc(stat.size);
|
|
48
|
+
let offset = 0;
|
|
49
|
+
while (offset < stat.size) {
|
|
50
|
+
const read = readSync(descriptor, buffer, offset, stat.size - offset, offset);
|
|
51
|
+
if (read <= 0)
|
|
52
|
+
break;
|
|
53
|
+
offset += read;
|
|
54
|
+
}
|
|
55
|
+
// Binary files aren't scripts.
|
|
56
|
+
if (buffer.subarray(0, offset).includes(0))
|
|
57
|
+
return null;
|
|
58
|
+
return { text: buffer.toString("utf8", 0, offset), mtimeMs: stat.mtimeMs, size: stat.size };
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
if (descriptor !== undefined)
|
|
65
|
+
closeSync(descriptor);
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
statFile(path) {
|
|
69
|
+
try {
|
|
70
|
+
const stat = statSync(path);
|
|
71
|
+
return stat.isFile() ? { mtimeMs: stat.mtimeMs, size: stat.size } : null;
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
};
|
package/dist/cliHookScripts.d.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import type { CliFinding } from "./cliHookClassify.js";
|
|
9
9
|
import type { CodeScript } from "./cliHookLocalCode.js";
|
|
10
10
|
import type { CommandShape } from "./cliHookParse.js";
|
|
11
|
+
import type { Blind } from "./blindKind.js";
|
|
11
12
|
import { type ScriptFs, type ScriptReader, type ScriptSegment } from "./cliScriptRead.js";
|
|
12
13
|
import type { LocalAction, Place, ShellWord } from "./localCommands.js";
|
|
13
14
|
/** The parts of the classifier's machine script reading needs. */
|
|
@@ -24,7 +25,7 @@ export type ScriptMachine = {
|
|
|
24
25
|
type Walk = {
|
|
25
26
|
findings: CliFinding[];
|
|
26
27
|
complete: boolean;
|
|
27
|
-
blind?:
|
|
28
|
+
blind?: Blind;
|
|
28
29
|
};
|
|
29
30
|
/** The classifier's helpers, passed in. */
|
|
30
31
|
export type ScriptHost<M extends ScriptMachine> = {
|
package/dist/cliOutput.js
CHANGED
|
@@ -151,10 +151,10 @@ function helpText(verb) {
|
|
|
151
151
|
env: "passport env [--json]\npassport env set <vendor> <resource> <production|staging|development>\nShows where commands in this folder land, read the way each vendor's own CLI reads it: Railway, Vercel, Supabase, Wrangler, Netlify, Firebase, Convex, Neon, Fly, Heroku, kubectl, AWS, gcloud, Terraform, Stripe, and database URLs. One row per app: the resource, how Passport knows (linked, a flag, the vendor's default), and its environment. Anything Passport can't place counts as Production. Read on this computer; nothing is sent.\n set place a resource for the whole workspace. Admins choose any environment; everyone else can only say Production.\nJSON: {environments:[{vendor,resource,how,kind,assumed,note?}]}",
|
|
152
152
|
sessions:
|
|
153
153
|
// copy-style-allow double-space: help columns line up
|
|
154
|
-
"passport sessions [--all] [--running] [--production-changes] [--project <name>] [--pr <number>] [--since <when>] [--status running|ended]\npassport sessions <session-id>\nYour agents' work the way the Sessions page shows it: work items (a pull request or branch, every session on it rolled up) by project, each with its agents and what happened: actions, active time, failures, confirmed Production changes, unplaced changes, asks and how they ended, and how much Passport couldn't check. Notable work comes first; routine work folds into one line per project.\n --all every work item, routine ones too (pass one of --all, --running, --production-changes)\n --running work items with a running session\n --production-changes changes to confirmed Production, by app and target (7 days unless --since)\n --project <name> one project (repository, else folder)\n --pr <number> one pull request\n --since <when> today, 24h, 7d, 30d, 90d, or a date (YYYY-MM-DD)\n --status <status> running or ended sessions only\n <session-id> one session: its outcome and recent actions with what they acted on\nJSON: {view,groups:[{key,kind,label,apps,running,production,unplaced,items:[{key,title,project,branch,pull,agents,sessions,sessionIds,startedAt,lastActivityAt,activeMs,running,waiting,shape,reasons,severity,link}],routine}],totals,complete,nextCursor}; --production-changes: {view,sinceTs,untilTs,total,unplaced,apps:[{appKey,appName,count,lastTs,targets}]}; <session-id>: {view,session,outcome,approvals,timeline,nextCursor}",
|
|
154
|
+
"passport sessions [--all] [--running] [--production-changes] [--project <name>] [--pr <number>] [--since <when>] [--status running|ended]\npassport sessions <session-id>\nYour agents' work the way the Sessions page shows it: work items (a pull request or branch, every session on it rolled up) by project, each with its agents and what happened: actions, active time, failures, confirmed Production changes, unplaced changes, asks and how they ended, and how much Passport couldn't check. Notable work comes first; routine work folds into one line per project.\n --all every work item, routine ones too (pass one of --all, --running, --production-changes)\n --running work items with a running session\n --production-changes changes to confirmed Production, by app and target (7 days unless --since)\n --project <name> one project (repository, else folder)\n --pr <number> one pull request\n --since <when> today, 24h, 7d, 30d, 90d, or a date (YYYY-MM-DD)\n --status <status> running or ended sessions only\n <session-id> one session: its outcome and recent actions with what they acted on\nJSON: {view,groups:[{key,kind,label,apps,running,production,unplaced,items:[{key,title,project,branch,pull,agents,sessions,sessionIds,startedAt,lastActivityAt,activeMs,running,waiting,shape,reasons,severity,link}],routine}],totals,work,window,complete,nextCursor}; --production-changes: {view,sinceTs,untilTs,total,unplaced,window,apps:[{appKey,appName,count,lastTs,targets}]}; <session-id>: {view,session,outcome,approvals,timeline,nextCursor}",
|
|
155
155
|
changes:
|
|
156
156
|
// copy-style-allow double-space: help columns line up
|
|
157
|
-
"passport changes [--env production] [--since <when>] [--until <date>] [--project <name>] [--pr <number>] [--app <key>] [--agent <id>]\nWhat your agents changed in Production, the list Sessions › Production changes shows: every change, delete, and irreversible action that ran on confirmed Production in the window, grouped by app, newest first. Each row has its time and command, then the agent, the person, the pull request (else branch), Failed or Approved, and whether Passport can undo it. Blocked and declined actions never reached Production and aren't listed; changes to targets nobody placed are one count.\n --env <env> production (the only one for now)\n --since <when> 1h, 6h, 24h (default),
|
|
157
|
+
"passport changes [--env production] [--since <when>] [--until <date>] [--project <name>] [--pr <number>] [--app <key>] [--agent <id>]\nWhat your agents changed in Production, the list Sessions › Production changes shows: every change, delete, and irreversible action that ran on confirmed Production in the window, grouped by app, newest first. Each row has its time and command, then the agent, the person, the pull request (else branch), Failed or Approved, and whether Passport can undo it. Blocked and declined actions never reached Production and aren't listed; changes to targets nobody placed are one count.\n --env <env> production (the only one for now)\n --since <when> 1h, 6h, 24h, 7d (default), 30d, today, or a date (YYYY-MM-DD)\n --until <date> through the end of a date (YYYY-MM-DD)\n --project <name> one project (repository, else folder)\n --pr <number> one pull request\n --app <key> one app, or several separated by commas\n --agent <id> one agent (claude-code, codex, cursor)\nJSON: {view,environment,sinceTs,untilTs,total,unplaced,complete,window,apps:[{vendor,appName,changes:[{id,ts,person,agent,agentName,appKey,vendor,appName,command,target,actionClass,result,approved,sessionId,project,branch,pull,undo}]}]}",
|
|
158
158
|
// copy-style-allow double-space: help columns line up
|
|
159
159
|
exec: "passport exec [--wait <sec>] [--ask-again] [--verbose] [--mask | --no-masking] -- <cli> [args…]\nRuns railway, gh, vercel, wrangler, supabase, stripe, aws, neonctl, or flyctl with a key Passport holds, after your Autopilot rules decide. The key reaches only that command's environment, short-lived where the vendor allows (GitHub App tokens, 15-minute AWS sessions, 15-minute Cloudflare tokens). The exit code passes through unchanged.\n Output: when stdout isn't a terminal (an agent's shell, a pipe, a log), any copy of the key the CLI prints (raw, base64, or URL-encoded) reads <hidden by Passport>, since that output is kept and read later. In a terminal the CLI gets the terminal itself (colors, prompts), unmasked.\n --mask hide the key in a terminal too (the CLI then writes to a pipe)\n --no-masking never hide it (in a shim, set PASSPORT_EXEC_NO_MASKING=1)\n --verbose say which key was issued (on stderr)\n Asks: waits for your approval in Passport when you're at the keyboard or with --wait; otherwise exits 4 with the approval id. Run passport wait <id>, then the command again.\n Blocked or declined: exit 5 with the reason. A decline answers the same command for ten minutes; --ask-again requests it again.\n No key in Passport, or it stopped working: exit 3.\n Offline: nothing runs (exit 1); exec never uses a key on this computer.\n Refuses shells, env, and subcommands that would print the key or run another program with it.",
|
|
160
160
|
// copy-style-allow double-space: help columns line up
|
|
@@ -5,5 +5,5 @@ export declare function projectOf(raw: unknown, link: string | null): ProjectJso
|
|
|
5
5
|
/** Where each target is placed: "acme-api main Production, deploys on merge". */
|
|
6
6
|
export declare function environmentCells(env: ProjectEnvironmentJson): [string, string];
|
|
7
7
|
/** The summary block: name and counts, Environments, Rules, and Production
|
|
8
|
-
* changes
|
|
8
|
+
* changes, all over the server's window, each section only when it has something. */
|
|
9
9
|
export declare function renderProject(project: ProjectJson, term: Term): string;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* list alone.
|
|
7
7
|
*/
|
|
8
8
|
import { ENV_LABEL } from "./cliHookEnvironment.js";
|
|
9
|
-
import { count, list, oneOf, PROJECT_KINDS as KINDS, record, text, time } from "./cliSessionsJson.js";
|
|
9
|
+
import { count, list, oneOf, PROJECT_KINDS as KINDS, record, text, time, windowOf, workCountsOf } from "./cliSessionsJson.js";
|
|
10
10
|
import { countOf } from "./plural.js";
|
|
11
11
|
import { joinParts, table, wrap } from "./term.js";
|
|
12
12
|
/** Changes per app: one row per change (servers since #794), else an older
|
|
@@ -77,9 +77,12 @@ export function projectOf(raw, link) {
|
|
|
77
77
|
production: {
|
|
78
78
|
total: count(production.total),
|
|
79
79
|
unplaced: count(production.unplaced),
|
|
80
|
+
unplacedIncluded: production.unplacedIncluded === true,
|
|
80
81
|
apps: productionApps(production)
|
|
81
82
|
},
|
|
82
|
-
totals: { items: count(totals.items), sessions: count(totals.sessions), running: count(totals.running) }
|
|
83
|
+
totals: { items: count(totals.items), sessions: count(totals.sessions), running: count(totals.running) },
|
|
84
|
+
work: workCountsOf(totals.work),
|
|
85
|
+
window: windowOf(body.window)
|
|
83
86
|
};
|
|
84
87
|
}
|
|
85
88
|
const PLACEMENT = {
|
|
@@ -97,14 +100,15 @@ export function environmentCells(env) {
|
|
|
97
100
|
return [env.label, reached.join(" · ") || "No changes"];
|
|
98
101
|
}
|
|
99
102
|
/** The summary block: name and counts, Environments, Rules, and Production
|
|
100
|
-
* changes
|
|
103
|
+
* changes, all over the server's window, each section only when it has something. */
|
|
101
104
|
export function renderProject(project, term) {
|
|
102
105
|
const blocks = [];
|
|
103
106
|
blocks.push([
|
|
104
107
|
project.project,
|
|
105
108
|
...joinParts([
|
|
106
109
|
countOf(project.totals.sessions, "session"),
|
|
107
|
-
...(project.totals.running ? [`${project.totals.running.toLocaleString("en-US")} running`] : [])
|
|
110
|
+
...(project.totals.running ? [`${project.totals.running.toLocaleString("en-US")} running`] : []),
|
|
111
|
+
...(project.window ? [project.window.label] : [])
|
|
108
112
|
], term.width)
|
|
109
113
|
].join("\n"));
|
|
110
114
|
if (project.environments.length)
|
|
@@ -120,13 +124,20 @@ export function renderProject(project, term) {
|
|
|
120
124
|
}
|
|
121
125
|
const production = project.production;
|
|
122
126
|
const apps = production.apps.map((app) => `${app.appName} ${app.count.toLocaleString("en-US")}`);
|
|
127
|
+
// A server since the count shape counts unplaced changes among Production
|
|
128
|
+
// changes; an older one counted only confirmed Production, unplaced apart.
|
|
129
|
+
const where = production.unplacedIncluded ? "Production" : "confirmed Production";
|
|
123
130
|
const line = production.total
|
|
124
|
-
? `${countOf(production.total, "change")} on
|
|
125
|
-
:
|
|
131
|
+
? `${countOf(production.total, "change")} on ${where}: ${apps.join(", ")}`
|
|
132
|
+
: `No changes on ${where}`;
|
|
133
|
+
const unplaced = production.unplacedIncluded
|
|
134
|
+
? `${countOf(production.unplaced, "unplaced action")} among them`
|
|
135
|
+
: countOf(production.unplaced, "unplaced action");
|
|
126
136
|
blocks.push([
|
|
127
|
-
|
|
137
|
+
// The page's window, as the server said it; an older server counted 7 days.
|
|
138
|
+
project.window ? `Production changes · ${project.window.label}` : "Production changes, last 7 days",
|
|
128
139
|
...wrap(line, term.width, " ", " "),
|
|
129
|
-
...(production.unplaced ? wrap(
|
|
140
|
+
...(production.unplaced ? wrap(unplaced, term.width, " ") : [])
|
|
130
141
|
].join("\n"));
|
|
131
142
|
if (project.link)
|
|
132
143
|
blocks.push(`Open in Passport:\n${project.link}`);
|
package/dist/cliScriptRead.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ import { localOpaqueSalt, opaqueIdOf } from "./cliOpaqueId.js";
|
|
|
24
24
|
export { localOpaqueSalt, opaqueIdOf };
|
|
25
25
|
import { type ActionClass, type ActionEnv } from "./cliAutopilotPolicy.js";
|
|
26
26
|
import type { CliFinding } from "./cliHookClassify.js";
|
|
27
|
+
import { type Blind } from "./blindKind.js";
|
|
27
28
|
export declare const SCRIPT_MAX_BYTES: number;
|
|
28
29
|
export declare const SCRIPT_MAX_FILES = 20;
|
|
29
30
|
export declare const SCRIPT_MAX_DEPTH = 3;
|
|
@@ -88,8 +89,8 @@ export type ScriptOutcome = {
|
|
|
88
89
|
complete: boolean;
|
|
89
90
|
/** Read at all (false: Passport couldn't open it, the old rules apply). */
|
|
90
91
|
read: boolean;
|
|
91
|
-
/** A line inside it Passport couldn't tell anything about: its program. */
|
|
92
|
-
blind?:
|
|
92
|
+
/** A line inside it Passport couldn't tell anything about: its program and kind. */
|
|
93
|
+
blind?: Blind;
|
|
93
94
|
};
|
|
94
95
|
type CacheEntry = {
|
|
95
96
|
m: number;
|
|
@@ -97,7 +98,7 @@ type CacheEntry = {
|
|
|
97
98
|
h: string;
|
|
98
99
|
c: boolean;
|
|
99
100
|
f: CliFinding[];
|
|
100
|
-
/** The first blind program inside, if any. */
|
|
101
|
+
/** The first blind program inside, if any, as `program\tkind` (no tab: a program). */
|
|
101
102
|
b?: string;
|
|
102
103
|
/** Other files it read: path, mtime, size. */
|
|
103
104
|
x: [string, number, number][];
|
|
@@ -180,7 +181,7 @@ export declare function globMatches(glob: string, value: string): boolean;
|
|
|
180
181
|
export type Classify = (line: string, cwd: string | null, depth: number) => {
|
|
181
182
|
findings: CliFinding[];
|
|
182
183
|
complete: boolean;
|
|
183
|
-
blind?:
|
|
184
|
+
blind?: Blind;
|
|
184
185
|
};
|
|
185
186
|
/** A known project script, as a finding the guard decides like any other. */
|
|
186
187
|
export declare function projectFinding(action: CliProjectAction, label: string): CliFinding;
|
package/dist/cliScriptRead.js
CHANGED
|
@@ -26,6 +26,7 @@ export { localOpaqueSalt, opaqueIdOf };
|
|
|
26
26
|
import { readFileSync } from "node:fs";
|
|
27
27
|
import { join, posix } from "node:path";
|
|
28
28
|
import { riskOfClass } from "./cliAutopilotPolicy.js";
|
|
29
|
+
import { blindOfText } from "./blindKind.js";
|
|
29
30
|
import { credentialDir, writePrivateAtomic } from "./credentialStorage.js";
|
|
30
31
|
import { linesDigestInput, makeLines, packageLines, parseRepoActions, shellLines } from "./cliScriptText.js";
|
|
31
32
|
export const SCRIPT_MAX_BYTES = 256 * 1024;
|
|
@@ -302,7 +303,7 @@ function fromCache(reader, segment, fs, stat, cached) {
|
|
|
302
303
|
return { findings: cached.f, complete: cached.c, read: true, hash: cached.h, ...blindOf(cached) };
|
|
303
304
|
}
|
|
304
305
|
function blindOf(cached) {
|
|
305
|
-
return cached.b === undefined ? {} : { blind: cached.b };
|
|
306
|
+
return cached.b === undefined ? {} : { blind: blindOfText(cached.b) };
|
|
306
307
|
}
|
|
307
308
|
/** Classify each line a segment runs, one level deeper. */
|
|
308
309
|
function classifyLines(reader, segment, lines, fs, classify, depth) {
|
|
@@ -382,7 +383,7 @@ function readSegment(reader, segment, fs, classify, depth) {
|
|
|
382
383
|
h: pinned,
|
|
383
384
|
c: complete,
|
|
384
385
|
f: tagged,
|
|
385
|
-
...(blind === undefined ? {} : { b: blind }),
|
|
386
|
+
...(blind === undefined ? {} : { b: `${blind.program}\t${blind.kind}` }),
|
|
386
387
|
x: others,
|
|
387
388
|
u: reader.wall()
|
|
388
389
|
};
|
package/dist/cliSeen.d.ts
CHANGED
|
@@ -10,17 +10,31 @@
|
|
|
10
10
|
* a vendor command with a variable), but Passport can't allow it.
|
|
11
11
|
* - `b`/`B` Blind: Passport couldn't tell what it does (an unknown program, a
|
|
12
12
|
* script outside the project, an unknown package, SQL from a file, a
|
|
13
|
-
* one-liner). Its program's name
|
|
13
|
+
* one-liner). Its program's name and kind go in a log beside the marks.
|
|
14
14
|
*
|
|
15
15
|
* Marks written before 0.24.0 (`g` an app's action, `o` not checked, `.`
|
|
16
16
|
* anything else) still count, `o` as blind. Batches go to Passport at most
|
|
17
17
|
* every five minutes with an id, so a retried batch lands once, and they
|
|
18
18
|
* travel on their own, never inside a report that can expire. Only counts and
|
|
19
|
-
* blind programs' names ever leave the computer.
|
|
19
|
+
* blind programs' names and kinds ever leave the computer.
|
|
20
20
|
*/
|
|
21
21
|
import type { CliFinding } from "./cliHookClassify.js";
|
|
22
|
+
import type { Blind, BlindKind } from "./blindKind.js";
|
|
22
23
|
export declare const SEEN_REPORT_MS: number;
|
|
23
24
|
export type SeenMark = "d" | "D" | "p" | "P" | "b" | "B";
|
|
25
|
+
export type { Blind, BlindKind } from "./blindKind.js";
|
|
26
|
+
/** One entry of a batch's busiest blind programs. */
|
|
27
|
+
export type BlindProgram = {
|
|
28
|
+
program: string;
|
|
29
|
+
count: number;
|
|
30
|
+
kind?: BlindKind;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Send each blind program's kind with the batch. Servers accept `kind` from
|
|
34
|
+
* the release that adds it (it lands before this bridge ships); an older
|
|
35
|
+
* server rejects the field, so this is the one switch to turn it off.
|
|
36
|
+
*/
|
|
37
|
+
export declare const CLI_SEEN_KINDS = true;
|
|
24
38
|
type Buckets = {
|
|
25
39
|
decided: number;
|
|
26
40
|
placed: number;
|
|
@@ -41,11 +55,8 @@ export type SeenBatch = {
|
|
|
41
55
|
governed: number;
|
|
42
56
|
opaque: number;
|
|
43
57
|
sessions?: SeenSession[];
|
|
44
|
-
/** The busiest programs among blind commands, up to 10. */
|
|
45
|
-
blindPrograms?:
|
|
46
|
-
program: string;
|
|
47
|
-
count: number;
|
|
48
|
-
}>;
|
|
58
|
+
/** The busiest programs among blind commands, by program and kind, up to 10. */
|
|
59
|
+
blindPrograms?: BlindProgram[];
|
|
49
60
|
} & Buckets;
|
|
50
61
|
/** The shape servers from before the buckets accept. */
|
|
51
62
|
export type LegacySeen = {
|
|
@@ -79,18 +90,17 @@ type Pending = SeenBatch & {
|
|
|
79
90
|
export type SeenLine = {
|
|
80
91
|
findings: readonly CliFinding[];
|
|
81
92
|
complete: boolean;
|
|
82
|
-
blind?:
|
|
93
|
+
blind?: Blind;
|
|
83
94
|
};
|
|
84
|
-
|
|
85
|
-
export declare function seenMark(line: SeenLine): {
|
|
95
|
+
export type Seen = {
|
|
86
96
|
mark: SeenMark;
|
|
87
97
|
program?: string;
|
|
98
|
+
kind?: BlindKind;
|
|
88
99
|
};
|
|
100
|
+
/** What one command was, for coverage: its bucket, and the program and kind when blind. */
|
|
101
|
+
export declare function seenMark(line: SeenLine): Seen;
|
|
89
102
|
/** Count one command the guard saw, and its session when it ran in one. Never throws. */
|
|
90
|
-
export declare function noteSeen(profile: string, runtime: string, seen:
|
|
91
|
-
mark: SeenMark;
|
|
92
|
-
program?: string;
|
|
93
|
-
}, now?: number, sessionId?: string): void;
|
|
103
|
+
export declare function noteSeen(profile: string, runtime: string, seen: Seen, now?: number, sessionId?: string): void;
|
|
94
104
|
/** Count several commands at once (the fast path's spool). Never throws. */
|
|
95
105
|
export declare function noteSeenMany(profile: string, runtime: string, marks: string, now?: number): void;
|
|
96
106
|
/** Today's counts for one agent on this computer. */
|
|
@@ -99,4 +109,3 @@ export declare function seenToday(profile: string, runtime: string, now?: number
|
|
|
99
109
|
export declare function claimSeenBatch(profile: string, now?: number, force?: boolean): Pending | null;
|
|
100
110
|
/** Passport recorded the batch: move the mark forward and forget old days. */
|
|
101
111
|
export declare function settleSeenBatch(profile: string, batch: string, now?: number): void;
|
|
102
|
-
export {};
|
package/dist/cliSeen.js
CHANGED
|
@@ -10,19 +10,19 @@
|
|
|
10
10
|
* a vendor command with a variable), but Passport can't allow it.
|
|
11
11
|
* - `b`/`B` Blind: Passport couldn't tell what it does (an unknown program, a
|
|
12
12
|
* script outside the project, an unknown package, SQL from a file, a
|
|
13
|
-
* one-liner). Its program's name
|
|
13
|
+
* one-liner). Its program's name and kind go in a log beside the marks.
|
|
14
14
|
*
|
|
15
15
|
* Marks written before 0.24.0 (`g` an app's action, `o` not checked, `.`
|
|
16
16
|
* anything else) still count, `o` as blind. Batches go to Passport at most
|
|
17
17
|
* every five minutes with an id, so a retried batch lands once, and they
|
|
18
18
|
* travel on their own, never inside a report that can expire. Only counts and
|
|
19
|
-
* blind programs' names ever leave the computer.
|
|
19
|
+
* blind programs' names and kinds ever leave the computer.
|
|
20
20
|
*/
|
|
21
21
|
import { randomBytes } from "node:crypto";
|
|
22
22
|
import { appendFileSync, closeSync, constants, mkdirSync, openSync, readdirSync, readFileSync, rmSync, statSync, utimesSync } from "node:fs";
|
|
23
23
|
import { join } from "node:path";
|
|
24
24
|
import { localDay } from "./cliAnswered.js";
|
|
25
|
-
import { opaqueProgram } from "./cliHookOpaque.js";
|
|
25
|
+
import { opaqueKind, opaqueProgram } from "./cliHookOpaque.js";
|
|
26
26
|
import { credentialDir, ensurePrivateDirectory, writePrivateAtomic } from "./credentialStorage.js";
|
|
27
27
|
import { assertProfileName } from "./credentials.js";
|
|
28
28
|
const DIRECTORY = "seen";
|
|
@@ -30,6 +30,13 @@ export const SEEN_REPORT_MS = 5 * 60 * 1000;
|
|
|
30
30
|
const KEEP_DAYS = 3;
|
|
31
31
|
const RUNTIME = /^[a-z][a-z-]{0,23}$/;
|
|
32
32
|
const MAX_BATCH = 100_000;
|
|
33
|
+
/**
|
|
34
|
+
* Send each blind program's kind with the batch. Servers accept `kind` from
|
|
35
|
+
* the release that adds it (it lands before this bridge ships); an older
|
|
36
|
+
* server rejects the field, so this is the one switch to turn it off.
|
|
37
|
+
*/
|
|
38
|
+
export const CLI_SEEN_KINDS = true;
|
|
39
|
+
const KINDS = new Set(["inline", "script", "program"]);
|
|
33
40
|
const MARKS = /^[dDpPbBgo.]+$/;
|
|
34
41
|
const SESSION_ID = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
35
42
|
const PROGRAM = /^[a-z0-9._+-]{1,40}$/;
|
|
@@ -43,15 +50,19 @@ function programName(name) {
|
|
|
43
50
|
const plain = (name ?? "").toLowerCase();
|
|
44
51
|
return PROGRAM.test(plain) ? plain : "other";
|
|
45
52
|
}
|
|
46
|
-
/** What one command was, for coverage: its bucket, and the program when blind. */
|
|
53
|
+
/** What one command was, for coverage: its bucket, and the program and kind when blind. */
|
|
47
54
|
export function seenMark(line) {
|
|
48
55
|
const app = line.findings.some((finding) => finding.vendor && !finding.local && finding.risk !== "local");
|
|
49
56
|
if (line.complete)
|
|
50
57
|
return { mark: app ? "D" : "d" };
|
|
51
58
|
const unread = line.findings.find((finding) => finding.risk === "unknown" && !finding.placed);
|
|
52
|
-
if (line.blind
|
|
53
|
-
|
|
54
|
-
|
|
59
|
+
if (line.blind)
|
|
60
|
+
return { mark: app ? "B" : "b", program: programName(line.blind.program), kind: line.blind.kind };
|
|
61
|
+
if (unread) {
|
|
62
|
+
const program = opaqueProgram(unread) ?? unread.vendor;
|
|
63
|
+
const opaque = opaqueKind(unread);
|
|
64
|
+
const kind = opaque === "script" || opaque === "task-runner" ? "script" : "program";
|
|
65
|
+
return { mark: app ? "B" : "b", program: programName(program), kind };
|
|
55
66
|
}
|
|
56
67
|
return { mark: app ? "P" : "p" };
|
|
57
68
|
}
|
|
@@ -70,7 +81,7 @@ function statePath(profile) {
|
|
|
70
81
|
assertProfileName(profile);
|
|
71
82
|
return join(directory(), `${profile}.json`);
|
|
72
83
|
}
|
|
73
|
-
/** Beside the day's marks: one blind command's program per line. */
|
|
84
|
+
/** Beside the day's marks: one blind command's `program\tkind` per line (no tab before 0.27: kind program). */
|
|
74
85
|
function programLogPath(profile, runtime, day) {
|
|
75
86
|
return logPath(profile, runtime, day).replace(/\.log$/, ".blind.log");
|
|
76
87
|
}
|
|
@@ -85,7 +96,8 @@ export function noteSeen(profile, runtime, seen, now = Date.now(), sessionId) {
|
|
|
85
96
|
appendFileSync(sessionLogPath(profile, runtime, day), `${sessionId} ${seen.mark}\n`, { mode: 0o600 });
|
|
86
97
|
}
|
|
87
98
|
if (seen.program && (seen.mark === "b" || seen.mark === "B")) {
|
|
88
|
-
|
|
99
|
+
const kind = seen.kind && KINDS.has(seen.kind) ? seen.kind : "program";
|
|
100
|
+
appendFileSync(programLogPath(profile, runtime, day), `${programName(seen.program)}\t${kind}\n`, { mode: 0o600 });
|
|
89
101
|
}
|
|
90
102
|
}
|
|
91
103
|
catch {
|
|
@@ -157,7 +169,8 @@ function sessionsSince(path, from) {
|
|
|
157
169
|
const sessions = [...counts.values()].sort((a, b) => b.count - a.count).slice(0, MAX_SESSIONS);
|
|
158
170
|
return { sessions, end };
|
|
159
171
|
}
|
|
160
|
-
/** The busiest blind programs in the program log after `from` bytes,
|
|
172
|
+
/** The busiest blind programs in the program log after `from` bytes, by
|
|
173
|
+
* program and kind (by program alone without `CLI_SEEN_KINDS`), and where it ends. */
|
|
161
174
|
function programsSince(path, from) {
|
|
162
175
|
let text;
|
|
163
176
|
try {
|
|
@@ -170,13 +183,18 @@ function programsSince(path, from) {
|
|
|
170
183
|
if (end <= from)
|
|
171
184
|
return { programs: [], end: Math.max(from, 0) };
|
|
172
185
|
const counts = new Map();
|
|
173
|
-
for (const
|
|
174
|
-
|
|
175
|
-
|
|
186
|
+
for (const line of text.slice(from, end).split("\n")) {
|
|
187
|
+
const [program, written] = line.split("\t");
|
|
188
|
+
if (!program || !PROGRAM.test(program))
|
|
189
|
+
continue;
|
|
190
|
+
const kind = written && KINDS.has(written) ? written : "program";
|
|
191
|
+
const key = CLI_SEEN_KINDS ? `${program}\t${kind}` : program;
|
|
192
|
+
const entry = counts.get(key) ?? { program, count: 0, ...(CLI_SEEN_KINDS ? { kind } : {}) };
|
|
193
|
+
entry.count++;
|
|
194
|
+
counts.set(key, entry);
|
|
176
195
|
}
|
|
177
|
-
const programs = [...counts]
|
|
178
|
-
.
|
|
179
|
-
.sort((a, b) => b.count - a.count || a.program.localeCompare(b.program))
|
|
196
|
+
const programs = [...counts.values()]
|
|
197
|
+
.sort((a, b) => b.count - a.count || a.program.localeCompare(b.program) || (a.kind ?? "").localeCompare(b.kind ?? ""))
|
|
180
198
|
.slice(0, MAX_PROGRAMS);
|
|
181
199
|
return { programs, end };
|
|
182
200
|
}
|
package/dist/cliSessions.js
CHANGED
|
@@ -23,7 +23,7 @@ import { api, json } from "./cliAutopilot.js";
|
|
|
23
23
|
import { failure, timeoutMs } from "./cliSupport.js";
|
|
24
24
|
import { termOf } from "./term.js";
|
|
25
25
|
import { hashLink } from "./webLinks.js";
|
|
26
|
-
import { count, ID, ledgerOf, list, mergeGroups, record, sessionOf, text, workGroupOf } from "./cliSessionsJson.js";
|
|
26
|
+
import { count, ID, ledgerOf, list, mergeGroups, record, sessionOf, text, windowOf, workCountsOf, workGroupOf } from "./cliSessionsJson.js";
|
|
27
27
|
import { renderLedger, renderSession, renderWork } from "./cliSessionsRender.js";
|
|
28
28
|
import { projectOf, renderProject } from "./cliProjectSummary.js";
|
|
29
29
|
export * from "./cliSessionsJson.js";
|
|
@@ -101,10 +101,12 @@ async function read(client, path, args, runtime, fallback) {
|
|
|
101
101
|
}
|
|
102
102
|
/** A project's summary, or null when the server has no project page (older
|
|
103
103
|
* servers) or can't read it: the work list still prints on its own. */
|
|
104
|
-
async function projectSummary(client, name, args, runtime) {
|
|
104
|
+
async function projectSummary(client, name, args, runtime, range = {}) {
|
|
105
105
|
try {
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
// The page counts over the same window as the work list (--since).
|
|
107
|
+
const window = query({ since: range.since });
|
|
108
|
+
const raw = await read(client, `/api/my/projects/${encodeURIComponent(name)}${window}`, args, runtime, "No project.");
|
|
109
|
+
return projectOf(raw, hashLink(client.origin, `#projects/${encodeURIComponent(name)}${window}`));
|
|
108
110
|
}
|
|
109
111
|
catch {
|
|
110
112
|
return null;
|
|
@@ -138,6 +140,8 @@ export async function sessions(args, runtime, deps = {}) {
|
|
|
138
140
|
const view = views[0] === "all" ? "all" : views[0] === "running" ? "running" : "notable";
|
|
139
141
|
const pages = [];
|
|
140
142
|
let totals = { items: 0, notable: 0, running: 0 };
|
|
143
|
+
let counts = null;
|
|
144
|
+
let window = null;
|
|
141
145
|
let complete = true;
|
|
142
146
|
let cursor;
|
|
143
147
|
for (let page = 0; page < MAX_PAGES; page++) {
|
|
@@ -146,17 +150,27 @@ export async function sessions(args, runtime, deps = {}) {
|
|
|
146
150
|
if (page === 0) {
|
|
147
151
|
const raw = record(body.totals);
|
|
148
152
|
totals = { items: count(raw.items), notable: count(raw.notable), running: count(raw.running) };
|
|
153
|
+
counts = workCountsOf(raw.work);
|
|
154
|
+
window = windowOf(body.window);
|
|
149
155
|
complete = body.complete !== false;
|
|
150
156
|
}
|
|
151
157
|
cursor = text(body.nextCursor, 400);
|
|
152
158
|
if (!cursor)
|
|
153
159
|
break;
|
|
154
160
|
}
|
|
155
|
-
const result = {
|
|
161
|
+
const result = {
|
|
162
|
+
view,
|
|
163
|
+
groups: mergeGroups(pages),
|
|
164
|
+
totals,
|
|
165
|
+
work: counts,
|
|
166
|
+
window,
|
|
167
|
+
complete,
|
|
168
|
+
nextCursor: cursor ?? null
|
|
169
|
+
};
|
|
156
170
|
// `--project <name>` alone (no lens, pull request, or status) opens with
|
|
157
171
|
// the project's page, as the web does.
|
|
158
172
|
const project = view === "notable" && filters.project && !filters.pr && !filters.status
|
|
159
|
-
? await projectSummary(client, filters.project, args, runtime)
|
|
173
|
+
? await projectSummary(client, filters.project, args, runtime, { since: filters.since })
|
|
160
174
|
: null;
|
|
161
175
|
const webQuery = query({
|
|
162
176
|
...(view === "notable" ? {} : { view }),
|
|
@@ -4,6 +4,38 @@ export declare function time(raw: unknown): number | null;
|
|
|
4
4
|
export declare function record(raw: unknown): Record<string, unknown>;
|
|
5
5
|
export declare function list(raw: unknown): unknown[];
|
|
6
6
|
export declare function oneOf<T extends string>(raw: unknown, values: readonly T[]): T | null;
|
|
7
|
+
/**
|
|
8
|
+
* The server's count shape (shared/workCountsContract.ts): one classifier for
|
|
9
|
+
* every surface, so the CLI prints the server's numbers and never sums its
|
|
10
|
+
* own. Null from a server older than the shape; the CLI then prints only
|
|
11
|
+
* what that server sent.
|
|
12
|
+
*/
|
|
13
|
+
export type WorkCountsJson = {
|
|
14
|
+
sessions: number;
|
|
15
|
+
items: number;
|
|
16
|
+
actions: number;
|
|
17
|
+
changes: number;
|
|
18
|
+
/** Changes that ran and succeeded on Production or on a target nobody placed. */
|
|
19
|
+
productionChanges: number;
|
|
20
|
+
/** Of productionChanges, the ones nobody placed. */
|
|
21
|
+
unplaced: number;
|
|
22
|
+
failed: number;
|
|
23
|
+
asks: number;
|
|
24
|
+
running: number;
|
|
25
|
+
shipped: number;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* The window a count covers, as the server stamped it (shared/workCountsContract.ts
|
|
29
|
+
* CountWindow): its start (0: any time), its end (null: now), and the words
|
|
30
|
+
* the CLI prints after the count ("Last 7 days"). Null from older servers.
|
|
31
|
+
*/
|
|
32
|
+
export type WindowJson = {
|
|
33
|
+
since: number;
|
|
34
|
+
until: number | null;
|
|
35
|
+
label: string;
|
|
36
|
+
};
|
|
37
|
+
export declare function windowOf(raw: unknown): WindowJson | null;
|
|
38
|
+
export declare function workCountsOf(raw: unknown): WorkCountsJson | null;
|
|
7
39
|
export declare const NOTABLE_REASONS: readonly ["failed", "production", "blocked", "declined", "asked", "dataCheck", "undone", "unplaced", "unchecked"];
|
|
8
40
|
type Reason = (typeof NOTABLE_REASONS)[number];
|
|
9
41
|
type Severity = "failed" | "asked" | "production" | null;
|
|
@@ -83,6 +115,10 @@ export type WorkItemsJson = {
|
|
|
83
115
|
notable: number;
|
|
84
116
|
running: number;
|
|
85
117
|
};
|
|
118
|
+
/** The server's count shape for every matched session; null from older servers. */
|
|
119
|
+
work: WorkCountsJson | null;
|
|
120
|
+
/** The span those counts cover; null from older servers. */
|
|
121
|
+
window: WindowJson | null;
|
|
86
122
|
/** False when the window held more sessions than one read covers. */
|
|
87
123
|
complete: boolean;
|
|
88
124
|
/** Set when more work items remain than the CLI read. */
|
|
@@ -104,8 +140,13 @@ export type LedgerJson = {
|
|
|
104
140
|
view: "production-changes";
|
|
105
141
|
sinceTs: number | null;
|
|
106
142
|
untilTs: number | null;
|
|
143
|
+
/** Production changes; with `unplacedIncluded`, the unplaced ones are among them. */
|
|
107
144
|
total: number;
|
|
108
145
|
unplaced: number;
|
|
146
|
+
/** False from a server that counted unplaced changes apart from `total`. */
|
|
147
|
+
unplacedIncluded: boolean;
|
|
148
|
+
/** The span `total` covers; null from older servers. */
|
|
149
|
+
window: WindowJson | null;
|
|
109
150
|
apps: Array<{
|
|
110
151
|
appKey: string;
|
|
111
152
|
appName: string;
|
|
@@ -150,6 +191,8 @@ export type SessionJson = {
|
|
|
150
191
|
unplaced: number;
|
|
151
192
|
unchecked: number;
|
|
152
193
|
waiting: number;
|
|
194
|
+
/** The session's asks, the count the web's tile and row read; null from an older server. */
|
|
195
|
+
asks: ShapeJson["asks"] | null;
|
|
153
196
|
link: string | null;
|
|
154
197
|
};
|
|
155
198
|
outcome: {
|
|
@@ -223,6 +266,7 @@ export type ProjectJson = {
|
|
|
223
266
|
production: {
|
|
224
267
|
total: number;
|
|
225
268
|
unplaced: number;
|
|
269
|
+
unplacedIncluded: boolean;
|
|
226
270
|
apps: Array<{
|
|
227
271
|
appKey: string;
|
|
228
272
|
appName: string;
|
|
@@ -234,5 +278,9 @@ export type ProjectJson = {
|
|
|
234
278
|
sessions: number;
|
|
235
279
|
running: number;
|
|
236
280
|
};
|
|
281
|
+
/** The project's count shape; null from older servers. */
|
|
282
|
+
work: WorkCountsJson | null;
|
|
283
|
+
/** The span every count covers (the Sessions filter's); null from older servers. */
|
|
284
|
+
window: WindowJson | null;
|
|
237
285
|
};
|
|
238
286
|
export {};
|