passport-bridge 0.26.0 → 0.28.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 +4 -4
- 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/cliHook.js +2 -2
- package/dist/cliHookBlind.d.ts +15 -0
- package/dist/cliHookBlind.js +65 -0
- package/dist/cliHookDecide.d.ts +8 -1
- package/dist/cliHookDecide.js +52 -4
- 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/cliHookSessionEnd.d.ts +48 -0
- package/dist/cliHookSessionEnd.js +162 -0
- 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
|
@@ -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 {};
|
package/dist/cliSessionsJson.js
CHANGED
|
@@ -27,7 +27,30 @@ export function list(raw) {
|
|
|
27
27
|
export function oneOf(raw, values) {
|
|
28
28
|
return typeof raw === "string" && values.includes(raw) ? raw : null;
|
|
29
29
|
}
|
|
30
|
-
|
|
30
|
+
export function windowOf(raw) {
|
|
31
|
+
const window = record(raw);
|
|
32
|
+
const label = text(window.label, 80);
|
|
33
|
+
if (!label || typeof window.since !== "number" || !Number.isFinite(window.since))
|
|
34
|
+
return null;
|
|
35
|
+
return { since: Math.max(0, window.since), until: time(window.until), label };
|
|
36
|
+
}
|
|
37
|
+
export function workCountsOf(raw) {
|
|
38
|
+
const work = record(raw);
|
|
39
|
+
if (typeof work.productionChanges !== "number")
|
|
40
|
+
return null;
|
|
41
|
+
return {
|
|
42
|
+
sessions: count(work.sessions),
|
|
43
|
+
items: count(work.items),
|
|
44
|
+
actions: count(work.actions),
|
|
45
|
+
changes: count(work.changes),
|
|
46
|
+
productionChanges: count(work.productionChanges),
|
|
47
|
+
unplaced: count(work.unplaced),
|
|
48
|
+
failed: count(work.failed),
|
|
49
|
+
asks: count(work.asks),
|
|
50
|
+
running: count(work.running),
|
|
51
|
+
shipped: count(work.shipped)
|
|
52
|
+
};
|
|
53
|
+
}
|
|
31
54
|
export const NOTABLE_REASONS = [
|
|
32
55
|
"failed",
|
|
33
56
|
"production",
|
|
@@ -92,9 +115,20 @@ function pullOf(raw) {
|
|
|
92
115
|
url: url && /^https:\/\//.test(url) ? url : null
|
|
93
116
|
};
|
|
94
117
|
}
|
|
118
|
+
/** The server's asks for a session or item (shared/askCounts.ts), as sent. */
|
|
119
|
+
function asksOf(raw) {
|
|
120
|
+
const asks = record(raw);
|
|
121
|
+
return {
|
|
122
|
+
total: count(asks.total),
|
|
123
|
+
allowed: count(asks.allowed),
|
|
124
|
+
declined: count(asks.declined),
|
|
125
|
+
expired: count(asks.expired),
|
|
126
|
+
answered: count(asks.answered),
|
|
127
|
+
waiting: count(asks.waiting)
|
|
128
|
+
};
|
|
129
|
+
}
|
|
95
130
|
function shapeOf(raw) {
|
|
96
131
|
const shape = record(raw);
|
|
97
|
-
const asks = record(shape.asks);
|
|
98
132
|
return {
|
|
99
133
|
actions: count(shape.actions),
|
|
100
134
|
reads: count(shape.reads),
|
|
@@ -105,14 +139,7 @@ function shapeOf(raw) {
|
|
|
105
139
|
dataChecks: count(shape.dataChecks),
|
|
106
140
|
undone: count(shape.undone),
|
|
107
141
|
unchecked: count(shape.unchecked),
|
|
108
|
-
asks:
|
|
109
|
-
total: count(asks.total),
|
|
110
|
-
allowed: count(asks.allowed),
|
|
111
|
-
declined: count(asks.declined),
|
|
112
|
-
expired: count(asks.expired),
|
|
113
|
-
answered: count(asks.answered),
|
|
114
|
-
waiting: count(asks.waiting)
|
|
115
|
-
},
|
|
142
|
+
asks: asksOf(shape.asks),
|
|
116
143
|
apps: list(shape.apps)
|
|
117
144
|
.map((app) => text(app, 80))
|
|
118
145
|
.filter((app) => !!app)
|
|
@@ -222,6 +249,8 @@ export function ledgerOf(raw) {
|
|
|
222
249
|
untilTs: time(ledger.untilTs),
|
|
223
250
|
total: count(ledger.total),
|
|
224
251
|
unplaced: count(ledger.unplaced),
|
|
252
|
+
unplacedIncluded: ledger.unplacedIncluded === true,
|
|
253
|
+
window: windowOf(ledger.window),
|
|
225
254
|
apps: list(ledger.apps).map((entry) => {
|
|
226
255
|
const app = record(entry);
|
|
227
256
|
const appKey = text(app.appKey, 80) ?? "";
|
|
@@ -306,6 +335,7 @@ export function sessionOf(raw, origin) {
|
|
|
306
335
|
unplaced: count(session.unplaced),
|
|
307
336
|
unchecked: count(session.unchecked),
|
|
308
337
|
waiting: count(session.waiting),
|
|
338
|
+
asks: session.asks === undefined ? null : asksOf(session.asks),
|
|
309
339
|
link: sessionLink(origin, id)
|
|
310
340
|
},
|
|
311
341
|
outcome: outcome
|
|
@@ -24,6 +24,10 @@ export declare function groupHeading(group: WorkGroupJson): string[];
|
|
|
24
24
|
/** One work item: its mark and title (with the PR's number), its agents,
|
|
25
25
|
* its shape, and its link, each wrapped only between parts. */
|
|
26
26
|
export declare function workItemLines(item: WorkItemJson, term: Term, group?: Pick<WorkGroupJson, "label" | "running" | "items">): string[];
|
|
27
|
+
/** The server's count shape as one line: "12 work items · 2 running · 4
|
|
28
|
+
* Production changes (1 unplaced) · 2 failed · 3 asks". Null from an older
|
|
29
|
+
* server: the CLI never adds up its own. */
|
|
30
|
+
export declare function workLine(work: WorkItemsJson["work"]): string[] | null;
|
|
27
31
|
export declare function renderWork(page: WorkItemsJson, term: Term, filtered: boolean, more: string | null): string;
|
|
28
32
|
export declare function renderLedger(ledger: LedgerJson, term: Term, now: number, since: string | undefined, link: string | null): string;
|
|
29
33
|
/**
|