@bli-cockpit/telemetry-core 0.1.111 → 0.1.112
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/dist/collector-heartbeat.d.ts +17 -0
- package/dist/evidence-upload.d.ts +16 -0
- package/dist/evidence-upload.js +16 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/log-digest/log-projects.d.ts +1 -0
- package/dist/log-digest/log-projects.js +10 -3
- package/dist/log-digest/sources/collector.d.ts +2 -6
- package/dist/log-digest/sources/collector.js +70 -30
- package/dist/log-digest/sources/types.d.ts +1 -0
- package/dist/log-digest/sources/vercel-query.d.ts +17 -0
- package/dist/log-digest/sources/vercel-query.js +86 -0
- package/dist/log-digest/sources/vercel.d.ts +1 -1
- package/dist/log-digest/sources/vercel.js +77 -13
- package/dist/log-digest/tagged.d.ts +0 -1
- package/dist/log-digest/tagged.js +2 -4
- package/dist/log-digest/tower-classes.js +9 -1
- package/dist/mail-time.d.ts +1 -0
- package/dist/mail-time.js +24 -0
- package/dist/memory-hook-hours.d.ts +1 -0
- package/dist/memory-hook-hours.js +2 -1
- package/dist/memory-install-receipt.d.ts +18 -0
- package/dist/memory-install-receipt.js +12 -0
- package/dist/newest-check-runs.d.ts +21 -0
- package/dist/newest-check-runs.js +20 -0
- package/dist/provider-billing.d.ts +5 -0
- package/dist/provider-billing.js +70 -0
- package/dist/session-facts-text.js +3 -0
- package/dist/session-facts.d.ts +2 -1
- package/dist/session-facts.js +10 -3
- package/dist/session-git-refs.d.ts +41 -0
- package/dist/session-git-refs.js +362 -0
- package/dist/work-project-reference.d.ts +7 -0
- package/dist/work-project-reference.js +8 -0
- package/package.json +17 -2
|
@@ -166,6 +166,20 @@ export declare const CollectorHeartbeatSchema: z.ZodObject<{
|
|
|
166
166
|
memory_install: z.ZodOptional<z.ZodObject<{
|
|
167
167
|
schema_version: z.ZodLiteral<"memory-install-receipt.v1">;
|
|
168
168
|
checked_at: z.ZodString;
|
|
169
|
+
tower: z.ZodOptional<z.ZodObject<{
|
|
170
|
+
claude: z.ZodEnum<{
|
|
171
|
+
unknown: "unknown";
|
|
172
|
+
ok: "ok";
|
|
173
|
+
stale: "stale";
|
|
174
|
+
missing: "missing";
|
|
175
|
+
}>;
|
|
176
|
+
codex: z.ZodEnum<{
|
|
177
|
+
unknown: "unknown";
|
|
178
|
+
ok: "ok";
|
|
179
|
+
stale: "stale";
|
|
180
|
+
missing: "missing";
|
|
181
|
+
}>;
|
|
182
|
+
}, z.core.$strict>>;
|
|
169
183
|
claude: z.ZodObject<{
|
|
170
184
|
mcp: z.ZodEnum<{
|
|
171
185
|
unknown: "unknown";
|
|
@@ -210,6 +224,8 @@ export declare const CollectorHeartbeatSchema: z.ZodObject<{
|
|
|
210
224
|
hook_failed_24h: z.ZodOptional<z.ZodNumber>;
|
|
211
225
|
hook_via_daemon_24h: z.ZodOptional<z.ZodNumber>;
|
|
212
226
|
hook_via_direct_24h: z.ZodOptional<z.ZodNumber>;
|
|
227
|
+
hook_skipped_24h: z.ZodOptional<z.ZodNumber>;
|
|
228
|
+
hook_skipped_automated_24h: z.ZodOptional<z.ZodNumber>;
|
|
213
229
|
hook_skipped_trivial_24h: z.ZodOptional<z.ZodNumber>;
|
|
214
230
|
hook_billing_exhausted_24h: z.ZodOptional<z.ZodNumber>;
|
|
215
231
|
hook_chars_p50: z.ZodOptional<z.ZodNumber>;
|
|
@@ -225,6 +241,7 @@ export declare const CollectorHeartbeatSchema: z.ZodObject<{
|
|
|
225
241
|
printed: z.ZodNumber;
|
|
226
242
|
timeouts: z.ZodNumber;
|
|
227
243
|
failed: z.ZodNumber;
|
|
244
|
+
skipped: z.ZodOptional<z.ZodNumber>;
|
|
228
245
|
}, z.core.$strict>>>;
|
|
229
246
|
hook_stats_reason: z.ZodOptional<z.ZodString>;
|
|
230
247
|
hook_performance: z.ZodOptional<z.ZodObject<{
|
|
@@ -682,6 +682,14 @@ export declare const CodexSessionAttributionSchema: z.ZodObject<{
|
|
|
682
682
|
repo_label: z.ZodOptional<z.ZodString>;
|
|
683
683
|
branch: z.ZodOptional<z.ZodString>;
|
|
684
684
|
commit_shas: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
685
|
+
git_refs: z.ZodOptional<z.ZodObject<{
|
|
686
|
+
branches: z.ZodArray<z.ZodString>;
|
|
687
|
+
commit_shas: z.ZodArray<z.ZodString>;
|
|
688
|
+
pull_requests: z.ZodArray<z.ZodObject<{
|
|
689
|
+
repo: z.ZodString;
|
|
690
|
+
number: z.ZodNumber;
|
|
691
|
+
}, z.core.$strict>>;
|
|
692
|
+
}, z.core.$strict>>;
|
|
685
693
|
root_scope: z.ZodOptional<z.ZodEnum<{
|
|
686
694
|
inside: "inside";
|
|
687
695
|
outside: "outside";
|
|
@@ -853,6 +861,14 @@ export declare const CodexSessionAttributionReportRequestSchema: z.ZodObject<{
|
|
|
853
861
|
repo_label: z.ZodOptional<z.ZodString>;
|
|
854
862
|
branch: z.ZodOptional<z.ZodString>;
|
|
855
863
|
commit_shas: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
864
|
+
git_refs: z.ZodOptional<z.ZodObject<{
|
|
865
|
+
branches: z.ZodArray<z.ZodString>;
|
|
866
|
+
commit_shas: z.ZodArray<z.ZodString>;
|
|
867
|
+
pull_requests: z.ZodArray<z.ZodObject<{
|
|
868
|
+
repo: z.ZodString;
|
|
869
|
+
number: z.ZodNumber;
|
|
870
|
+
}, z.core.$strict>>;
|
|
871
|
+
}, z.core.$strict>>;
|
|
856
872
|
root_scope: z.ZodOptional<z.ZodEnum<{
|
|
857
873
|
inside: "inside";
|
|
858
874
|
outside: "outside";
|
package/dist/evidence-upload.js
CHANGED
|
@@ -4,6 +4,7 @@ import { ImageUseSchema } from "./image-store.js";
|
|
|
4
4
|
import { RawEvidencePointerSchema } from "./privacy.js";
|
|
5
5
|
import { RawEvidenceRedactionMetadataSchema } from "./secret-guards.js";
|
|
6
6
|
import { SessionFactsSchema } from "./session-facts.js";
|
|
7
|
+
import { GIT_REFS_BRANCH_LIMIT, GIT_REFS_PULL_REQUEST_LIMIT, GIT_REFS_SHA_LIMIT } from "./session-git-refs.js";
|
|
7
8
|
import { RawEvidenceUploadExtendAcceptedSchema, RawEvidenceUploadExtendRequestSchema } from "./evidence-upload-extend.js";
|
|
8
9
|
/**
|
|
9
10
|
* Chunked raw-evidence upload wire contract.
|
|
@@ -293,6 +294,21 @@ export const CodexSessionAttributionSchema = z
|
|
|
293
294
|
.array(z.string().regex(/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/))
|
|
294
295
|
.max(100)
|
|
295
296
|
.optional(),
|
|
297
|
+
/**
|
|
298
|
+
* BLI-27624: every branch, commit hash and pull request the transcript names (`session-git-refs.ts`). `branch` keeps only
|
|
299
|
+
* the first branch, so a session that starts on main and creates its branch mid-session never matched its pull request.
|
|
300
|
+
* Names, hex hashes and owner/repo#number only. Absent from a CLI published before this field.
|
|
301
|
+
*/
|
|
302
|
+
git_refs: z
|
|
303
|
+
.object({
|
|
304
|
+
branches: z.array(z.string().trim().min(1).max(200)).max(GIT_REFS_BRANCH_LIMIT),
|
|
305
|
+
commit_shas: z.array(z.string().regex(/^[0-9a-f]{7,40}$/)).max(GIT_REFS_SHA_LIMIT),
|
|
306
|
+
pull_requests: z
|
|
307
|
+
.array(z.object({ repo: z.string().regex(/^[a-z0-9_.-]+\/[a-z0-9_.-]+$/).max(200), number: z.number().int().positive() }).strict())
|
|
308
|
+
.max(GIT_REFS_PULL_REQUEST_LIMIT),
|
|
309
|
+
})
|
|
310
|
+
.strict()
|
|
311
|
+
.optional(),
|
|
296
312
|
root_scope: RootScopeSchema.optional(),
|
|
297
313
|
/**
|
|
298
314
|
* BLI-22734 (three shelves): which shelf this session row belongs to. Only `team` rows are ever sent; a
|
package/dist/index.d.ts
CHANGED
|
@@ -42,6 +42,7 @@ export * from "./risk-flags.js";
|
|
|
42
42
|
export * from "./run-verdict.js";
|
|
43
43
|
export * from "./secret-guards.js";
|
|
44
44
|
export * from "./session-facts.js";
|
|
45
|
+
export * from "./session-git-refs.js";
|
|
45
46
|
export { codexRevisionRecordSelector } from "./codex-record-copies.js";
|
|
46
47
|
export * from "./t3-projection-message.js";
|
|
47
48
|
export * from "./session-facts-delta.js";
|
|
@@ -63,3 +64,5 @@ export * from "./pi-transcript-usage.js";
|
|
|
63
64
|
export * from "./pi-transcript-extract.js";
|
|
64
65
|
export * from "./pi-transcript-lineage.js";
|
|
65
66
|
export * from "./work-next-order.js";
|
|
67
|
+
export { matchWorkProject } from "./work-project-reference.js";
|
|
68
|
+
export * from "./mail-time.js";
|
package/dist/index.js
CHANGED
|
@@ -42,6 +42,7 @@ export * from "./risk-flags.js";
|
|
|
42
42
|
export * from "./run-verdict.js";
|
|
43
43
|
export * from "./secret-guards.js";
|
|
44
44
|
export * from "./session-facts.js";
|
|
45
|
+
export * from "./session-git-refs.js";
|
|
45
46
|
export { codexRevisionRecordSelector } from "./codex-record-copies.js";
|
|
46
47
|
export * from "./t3-projection-message.js";
|
|
47
48
|
export * from "./session-facts-delta.js";
|
|
@@ -63,3 +64,5 @@ export * from "./pi-transcript-usage.js";
|
|
|
63
64
|
export * from "./pi-transcript-extract.js";
|
|
64
65
|
export * from "./pi-transcript-lineage.js";
|
|
65
66
|
export * from "./work-next-order.js";
|
|
67
|
+
export { matchWorkProject } from "./work-project-reference.js";
|
|
68
|
+
export * from "./mail-time.js";
|
|
@@ -139,6 +139,7 @@ export interface BrainRoute {
|
|
|
139
139
|
daily_runs: number;
|
|
140
140
|
/** The source label that chose the repo, or `default` when none did. */
|
|
141
141
|
matched: string;
|
|
142
|
+
ambiguous?: true;
|
|
142
143
|
}
|
|
143
144
|
/**
|
|
144
145
|
* Where the brain may work on one incident: the project's `brain` block, with the repo chosen by the incident's source
|
|
@@ -220,14 +220,21 @@ export function brainRouteFor(projectId, sources = []) {
|
|
|
220
220
|
if (!brain)
|
|
221
221
|
return null;
|
|
222
222
|
const bySource = brain.repos.by_source ?? {};
|
|
223
|
-
const
|
|
223
|
+
const repos = new Set([brain.repos.default, ...Object.values(bySource)]);
|
|
224
|
+
const githubRepoBySource = new Map([...repos].map((repo) => [`github:${repo.toLowerCase()}`, repo]));
|
|
225
|
+
const matches = sources.flatMap((source) => {
|
|
226
|
+
const repo = Object.hasOwn(bySource, source) ? bySource[source] : githubRepoBySource.get(source.toLowerCase());
|
|
227
|
+
return repo === undefined ? [] : [{ source, repo }];
|
|
228
|
+
});
|
|
229
|
+
const matched = matches[0];
|
|
224
230
|
return {
|
|
225
231
|
project: projectId,
|
|
226
|
-
repo: matched
|
|
232
|
+
repo: matched?.repo ?? brain.repos.default,
|
|
227
233
|
base_branch: brain.base_branch,
|
|
228
234
|
merge: brain.merge,
|
|
229
235
|
daily_runs: brain.daily_runs,
|
|
230
|
-
matched: matched ?? "default",
|
|
236
|
+
matched: matched?.source ?? "default",
|
|
237
|
+
...(!matched && repos.size > 1 ? { ambiguous: true } : {}),
|
|
231
238
|
};
|
|
232
239
|
}
|
|
233
240
|
/** A project id as `cockpit logs <project>` spells it: lowercase letters, digits and dashes. */
|
|
@@ -3,13 +3,9 @@ import { type SourceContext, type SourceLine, type SourceRead } from "./types.js
|
|
|
3
3
|
export declare function windowShare(fromEpoch: number, start: number | null, end: number): number;
|
|
4
4
|
/** The one line a tick receipt is judged as. */
|
|
5
5
|
export declare function receiptLine(report: Record<string, unknown>): string;
|
|
6
|
-
|
|
7
|
-
* Splits the stream into digest lines, folding each column-0 `{ ... }` receipt
|
|
8
|
-
* into one line. Body lines of a receipt whose start is not in the read are
|
|
9
|
-
* counted, not judged: they are JSON syntax, not log lines.
|
|
10
|
-
*/
|
|
11
|
-
export declare function streamLines(text: string, stream: string): {
|
|
6
|
+
export declare function streamLines(text: string, stream: string, legacyCutoff?: number): {
|
|
12
7
|
lines: SourceLine[];
|
|
13
8
|
bodySkipped: number;
|
|
9
|
+
legacy: boolean;
|
|
14
10
|
};
|
|
15
11
|
export declare function readCollector(context: SourceContext): Promise<SourceRead>;
|
|
@@ -8,14 +8,9 @@
|
|
|
8
8
|
* `sync.err.log` (stderr). Rotation is a rename, so an archive keeps the time of
|
|
9
9
|
* its last write and the next-newer file starts where it ended.
|
|
10
10
|
*
|
|
11
|
-
*
|
|
12
|
-
* file
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* `sync.log` is mostly the tick's `--json` receipt printed over hundreds of
|
|
16
|
-
* indented lines. Each receipt is folded into one line (status, mode and the
|
|
17
|
-
* failure reasons it names) before judging, so a failed tick is one template and
|
|
18
|
-
* a healthy one is one routine count.
|
|
11
|
+
* New lines start with their exact UTC time. Old log lines keep the
|
|
12
|
+
* proportional file-window behavior until they rotate away. Either receipt
|
|
13
|
+
* shape folds into the same short sync_report record before judging.
|
|
19
14
|
*/
|
|
20
15
|
import { open, readdir, stat } from "node:fs/promises";
|
|
21
16
|
import { join } from "node:path";
|
|
@@ -72,35 +67,69 @@ const RECEIPT_BODY = /^\s{2,}["{}[\]]|^[}\]],?$/;
|
|
|
72
67
|
* into one line. Body lines of a receipt whose start is not in the read are
|
|
73
68
|
* counted, not judged: they are JSON syntax, not log lines.
|
|
74
69
|
*/
|
|
75
|
-
|
|
70
|
+
const TIMESTAMP_PREFIX = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?Z) /;
|
|
71
|
+
function parseReceipt(text) {
|
|
72
|
+
try {
|
|
73
|
+
const value = JSON.parse(text);
|
|
74
|
+
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
75
|
+
? value
|
|
76
|
+
: null;
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export function streamLines(text, stream, legacyCutoff = 0) {
|
|
76
83
|
const out = [];
|
|
77
84
|
let bodySkipped = 0;
|
|
85
|
+
let legacy = false;
|
|
86
|
+
let offset = 0;
|
|
78
87
|
const unitOf = (line) => TAG.exec(line)?.[1] ?? (stream === "sync.err.log" ? "sync.err" : "sync");
|
|
79
88
|
const rows = text.split("\n");
|
|
80
89
|
for (let index = 0; index < rows.length; index += 1) {
|
|
81
|
-
const
|
|
90
|
+
const raw = rows[index];
|
|
91
|
+
const start = offset;
|
|
92
|
+
offset += raw.length + 1;
|
|
93
|
+
const timestamp = TIMESTAMP_PREFIX.exec(raw);
|
|
94
|
+
const parsedTime = timestamp ? Date.parse(timestamp[1]) / 1000 : NaN;
|
|
95
|
+
const stamped = Number.isFinite(parsedTime);
|
|
96
|
+
const row = (stamped ? raw.slice(timestamp[0].length) : raw).trimEnd();
|
|
97
|
+
if (!row.trim())
|
|
98
|
+
continue;
|
|
99
|
+
if (!stamped) {
|
|
100
|
+
legacy = true;
|
|
101
|
+
if (start < legacyCutoff)
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
const ts = stamped ? parsedTime : 0;
|
|
105
|
+
if (row.startsWith("{") && row !== "{") {
|
|
106
|
+
const report = parseReceipt(row);
|
|
107
|
+
if (typeof report?.status === "string") {
|
|
108
|
+
out.push({ unit: "sync", message: receiptLine(report), ts });
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
82
112
|
if (row === "{") {
|
|
83
113
|
let end = index + 1;
|
|
84
|
-
while (end < rows.length && rows[end] !== "}")
|
|
114
|
+
while (end < rows.length && rows[end].trimEnd() !== "}")
|
|
85
115
|
end += 1;
|
|
86
116
|
if (end < rows.length) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
out.push({ unit: "sync", message: receiptLine(report), ts
|
|
117
|
+
const report = parseReceipt(rows.slice(index, end + 1).join("\n"));
|
|
118
|
+
if (report) {
|
|
119
|
+
out.push({ unit: "sync", message: receiptLine(report), ts });
|
|
120
|
+
for (let skipped = index + 1; skipped <= end; skipped += 1)
|
|
121
|
+
offset += rows[skipped].length + 1;
|
|
90
122
|
index = end;
|
|
91
123
|
continue;
|
|
92
124
|
}
|
|
93
|
-
catch {
|
|
94
|
-
// not a receipt after all: fall through and judge its lines one by one
|
|
95
|
-
}
|
|
96
125
|
}
|
|
97
126
|
}
|
|
98
127
|
if (RECEIPT_BODY.test(row) || row === "{")
|
|
99
128
|
bodySkipped += 1;
|
|
100
|
-
else
|
|
101
|
-
out.push({ unit: unitOf(row), message: row, ts
|
|
129
|
+
else
|
|
130
|
+
out.push({ unit: unitOf(row), message: row, ts });
|
|
102
131
|
}
|
|
103
|
-
return { lines: out, bodySkipped };
|
|
132
|
+
return { lines: out, bodySkipped, legacy };
|
|
104
133
|
}
|
|
105
134
|
export async function readCollector(context) {
|
|
106
135
|
const { stateDir, window, log } = context;
|
|
@@ -132,6 +161,8 @@ export async function readCollector(context) {
|
|
|
132
161
|
const read = [];
|
|
133
162
|
let skipped = 0;
|
|
134
163
|
let bytesRead = 0;
|
|
164
|
+
let approximate = false;
|
|
165
|
+
let capped = false;
|
|
135
166
|
for (const stream of [...new Set(files.map((file) => file.stream))].sort()) {
|
|
136
167
|
const chain = files.filter((file) => file.stream === stream).sort((a, b) => a.index - b.index);
|
|
137
168
|
let budget = MAX_BYTES_PER_STREAM;
|
|
@@ -141,25 +172,34 @@ export async function readCollector(context) {
|
|
|
141
172
|
const older = chain[position + 1];
|
|
142
173
|
const start = older ? older.mtime : file.birth;
|
|
143
174
|
const share = windowShare(window.fromEpoch, start, end);
|
|
144
|
-
if (
|
|
175
|
+
if (file.size === 0)
|
|
145
176
|
continue;
|
|
146
|
-
const want = Math.min(budget,
|
|
177
|
+
const want = Math.min(budget, file.size);
|
|
147
178
|
budget -= want;
|
|
148
179
|
const text = await readTail(join(stateDir, file.name), want, file.size);
|
|
149
|
-
const
|
|
150
|
-
|
|
180
|
+
const legacyWant = Math.min(want, Math.ceil(file.size * share));
|
|
181
|
+
const legacyCutoff = legacyWant === want ? 0 : text.length - Math.ceil(text.length * legacyWant / want);
|
|
182
|
+
const parsed = streamLines(text, stream, legacyCutoff);
|
|
183
|
+
const selected = parsed.lines.filter((line) => line.ts === 0 || (line.ts >= window.fromEpoch && line.ts <= window.toEpoch));
|
|
184
|
+
lines.push(...selected);
|
|
151
185
|
skipped += parsed.bodySkipped;
|
|
152
186
|
bytesRead += want;
|
|
153
|
-
|
|
154
|
-
|
|
187
|
+
approximate ||= parsed.legacy && share > 0;
|
|
188
|
+
capped ||= want < file.size || (budget === 0 && position + 1 < chain.length);
|
|
189
|
+
if (parsed.legacy && share > 0)
|
|
190
|
+
read.push(`${file.name} ${Math.round(share * 100)}%`);
|
|
191
|
+
else if (selected.length > 0)
|
|
192
|
+
read.push(`${file.name} (exact times)`);
|
|
193
|
+
log("[logs collector] file read", { file: file.name, bytes: want, lines: selected.length, receipt_body_lines_skipped: parsed.bodySkipped });
|
|
155
194
|
if (budget <= 0)
|
|
156
195
|
break;
|
|
157
196
|
}
|
|
158
197
|
}
|
|
159
|
-
const notes = [
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
198
|
+
const notes = [`read ${read.length > 0 ? read.join(", ") : "no collector lines in the window"}`];
|
|
199
|
+
if (approximate)
|
|
200
|
+
notes.unshift("no per-line times in older logs: their share of each file is read from its end (approximate)");
|
|
201
|
+
if (capped)
|
|
202
|
+
notes.push("collector log read reached its byte cap; earlier lines may be missing");
|
|
163
203
|
if (skipped > 0)
|
|
164
204
|
notes.push(`${skipped.toLocaleString("en-US")} lines of tick receipts cut by log rotation (indented JSON) were counted, not judged`);
|
|
165
205
|
return { lines, notes, rawChars: bytesRead };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type LogWindow } from "../window.js";
|
|
2
|
+
import { type CliRun } from "./types.js";
|
|
3
|
+
import type { VercelRecord } from "./vercel.js";
|
|
4
|
+
type FetchPage = (args: readonly string[]) => Promise<CliRun>;
|
|
5
|
+
export declare function readVercelQuery(window: LogWindow, allLevels: boolean, target: readonly string[], version: string, fetch: FetchPage): Promise<{
|
|
6
|
+
runtime: {
|
|
7
|
+
records: VercelRecord[];
|
|
8
|
+
pages: number;
|
|
9
|
+
partial: boolean;
|
|
10
|
+
};
|
|
11
|
+
requests: {
|
|
12
|
+
records: VercelRecord[];
|
|
13
|
+
pages: number;
|
|
14
|
+
partial: boolean;
|
|
15
|
+
};
|
|
16
|
+
}>;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { isoOf } from "../window.js";
|
|
3
|
+
import { SourceRefusal } from "./types.js";
|
|
4
|
+
const PAGE_LIMIT = 100;
|
|
5
|
+
const MAX_PAGES_PER_STREAM = 120;
|
|
6
|
+
const Timestamp = z.string().transform((value) => Date.parse(value)).pipe(z.number().finite());
|
|
7
|
+
const Route = z.object({ timestamp: Timestamp, requestPath: z.string().nullish(), requestMethod: z.string().nullish() });
|
|
8
|
+
const QueryRow = z.discriminatedUnion("type", [
|
|
9
|
+
z.object({ type: z.literal("log"), data: Route.extend({ level: z.string(), message: z.string() }) }),
|
|
10
|
+
z.object({ type: z.literal("request"), data: Route.extend({ httpStatus: z.number().int() }) }),
|
|
11
|
+
z.object({
|
|
12
|
+
type: z.literal("summary"),
|
|
13
|
+
recordsReturned: z.number().int().nonnegative(),
|
|
14
|
+
excludedIntervals: z.array(z.unknown()),
|
|
15
|
+
pagination: z.object({ hasMore: z.boolean(), next: z.string().nullish() }),
|
|
16
|
+
}),
|
|
17
|
+
]);
|
|
18
|
+
function decodePage(stdout, stream, version) {
|
|
19
|
+
const invalid = () => new SourceRefusal("vercel_failed", `vercel ${version} returned an invalid ${stream} page`);
|
|
20
|
+
const records = [];
|
|
21
|
+
let summary;
|
|
22
|
+
for (const line of stdout.split("\n")) {
|
|
23
|
+
if (!line.trim())
|
|
24
|
+
continue;
|
|
25
|
+
const value = (() => { try {
|
|
26
|
+
return JSON.parse(line);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
throw invalid();
|
|
30
|
+
} })();
|
|
31
|
+
const row = QueryRow.safeParse(value);
|
|
32
|
+
if (!row.success || summary)
|
|
33
|
+
throw invalid();
|
|
34
|
+
if (row.data.type === "summary")
|
|
35
|
+
summary = row.data;
|
|
36
|
+
else if (row.data.type !== stream)
|
|
37
|
+
throw invalid();
|
|
38
|
+
else {
|
|
39
|
+
const data = row.data.data;
|
|
40
|
+
records.push({
|
|
41
|
+
timestamp: data.timestamp,
|
|
42
|
+
requestPath: data.requestPath ?? undefined,
|
|
43
|
+
requestMethod: data.requestMethod ?? undefined,
|
|
44
|
+
...("httpStatus" in data ? { responseStatusCode: data.httpStatus } : { level: data.level, message: data.message }),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (!summary || summary.recordsReturned !== records.length || (summary.pagination.hasMore && !summary.pagination.next)) {
|
|
49
|
+
throw invalid();
|
|
50
|
+
}
|
|
51
|
+
return { records, next: summary.pagination.hasMore ? summary.pagination.next ?? null : null, excluded: summary.excludedIntervals.length };
|
|
52
|
+
}
|
|
53
|
+
function firstPageArgs(stream, window, allLevels, target) {
|
|
54
|
+
const query = stream === "log" ? "level:error OR level:warning OR level:fatal" : "httpStatus >= 500 AND httpStatus < 600";
|
|
55
|
+
return [
|
|
56
|
+
"logs", stream === "log" ? "runtime" : "requests", ...target,
|
|
57
|
+
"--since", isoOf(window.fromEpoch), "--until", isoOf(window.toEpoch),
|
|
58
|
+
...(allLevels ? [] : ["--query", query]),
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
async function readStream(stream, initial, fetch, version) {
|
|
62
|
+
const records = [];
|
|
63
|
+
const cursors = new Set();
|
|
64
|
+
let cursor = null;
|
|
65
|
+
let partial = false;
|
|
66
|
+
for (let pages = 1; pages <= MAX_PAGES_PER_STREAM; pages += 1) {
|
|
67
|
+
const args = cursor ? ["logs", "--next", cursor] : initial;
|
|
68
|
+
const reply = await fetch([...args, "--json", "--limit", String(PAGE_LIMIT), "--no-color", "--non-interactive"]);
|
|
69
|
+
const page = decodePage(reply.stdout, stream, version);
|
|
70
|
+
for (const row of page.records)
|
|
71
|
+
records.push(row);
|
|
72
|
+
partial ||= page.excluded > 0;
|
|
73
|
+
cursor = page.next;
|
|
74
|
+
if (!cursor)
|
|
75
|
+
return { records, pages, partial };
|
|
76
|
+
if (cursors.has(cursor)) {
|
|
77
|
+
throw new SourceRefusal("vercel_failed", `vercel ${version} repeated its ${stream} page cursor`);
|
|
78
|
+
}
|
|
79
|
+
cursors.add(cursor);
|
|
80
|
+
}
|
|
81
|
+
return { records, pages: MAX_PAGES_PER_STREAM, partial: true };
|
|
82
|
+
}
|
|
83
|
+
export async function readVercelQuery(window, allLevels, target, version, fetch) {
|
|
84
|
+
const [runtime, requests] = await Promise.all(["log", "request"].map((stream) => readStream(stream, firstPageArgs(stream, window, allLevels, target), fetch, version)));
|
|
85
|
+
return { runtime, requests };
|
|
86
|
+
}
|
|
@@ -37,4 +37,4 @@ export declare function vercelRecordLines(records: readonly VercelRecord[], from
|
|
|
37
37
|
lines: SourceLine[];
|
|
38
38
|
classes: VercelClasses;
|
|
39
39
|
};
|
|
40
|
-
export declare function readDashboard(
|
|
40
|
+
export declare function readDashboard(input: SourceContext): Promise<SourceRead>;
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
*/
|
|
22
22
|
import { isoOf } from "../window.js";
|
|
23
23
|
import { SourceRefusal } from "./types.js";
|
|
24
|
+
import { readVercelQuery } from "./vercel-query.js";
|
|
24
25
|
export const VERCEL_PROJECT = "bli-cockpit-dashboard";
|
|
25
26
|
export const VERCEL_SCOPE = "bli-inc";
|
|
26
27
|
// The CLI answers a call with at most one page of 50 records; when more exist it repeats that page until
|
|
@@ -30,6 +31,7 @@ const MIN_SLICE_SECONDS = 4;
|
|
|
30
31
|
const MAX_CALLS = 240;
|
|
31
32
|
const CONCURRENCY = 4;
|
|
32
33
|
const CALL_TIMEOUT_MS = 45_000;
|
|
34
|
+
const DASHBOARD_READ_BUDGET_MS = 60_000;
|
|
33
35
|
// Default: only the records Vercel itself marks as trouble, plus every 5xx. A few calls an hour.
|
|
34
36
|
const PROBLEM_QUERIES = [["--level", "error"], ["--level", "warning"], ["--level", "fatal"], ["--status-code", "5xx"]];
|
|
35
37
|
const ALL_QUERIES = [[]];
|
|
@@ -114,6 +116,33 @@ export function vercelRecordLines(records, fromEpoch, unitPrefix) {
|
|
|
114
116
|
}
|
|
115
117
|
return { lines, classes };
|
|
116
118
|
}
|
|
119
|
+
const VERCEL_TARGET = ["--project", VERCEL_PROJECT, "--scope", VERCEL_SCOPE];
|
|
120
|
+
async function vercelVersion(context) {
|
|
121
|
+
const result = await context.run("vercel", ["--version"], { timeoutMs: 5_000, maxBytes: 4_096 });
|
|
122
|
+
const refusal = vercelRefusal(result);
|
|
123
|
+
if (refusal)
|
|
124
|
+
throw refusal;
|
|
125
|
+
const version = result.stdout.match(/^\s*(\d+\.\d+\.\d+(?:-[\w.-]+)?)\s*$/m)?.[1];
|
|
126
|
+
if (result.status !== 0 || !version) {
|
|
127
|
+
throw new SourceRefusal("vercel_failed", `vercel --version did not return a version (${result.failure ?? result.status ?? "no exit code"})`);
|
|
128
|
+
}
|
|
129
|
+
return version;
|
|
130
|
+
}
|
|
131
|
+
async function runVercel(context, version, args, allowPartial) {
|
|
132
|
+
const result = await context.run("vercel", args, { timeoutMs: context.limits?.timeoutMs ?? CALL_TIMEOUT_MS, maxBytes: 64 * 1024 * 1024, abortOn: VERCEL_ABORT_PATTERN });
|
|
133
|
+
const refusal = vercelRefusal(result);
|
|
134
|
+
if (refusal)
|
|
135
|
+
throw new SourceRefusal(refusal.reason, `vercel ${version}: ${refusal.detail}`);
|
|
136
|
+
if (result.failure && !(allowPartial && result.failure === "timeout")) {
|
|
137
|
+
throw new SourceRefusal("vercel_failed", `vercel ${version} logs could not run (${result.failure})`);
|
|
138
|
+
}
|
|
139
|
+
if ((result.status !== 0 && !(allowPartial && (result.status === null || result.stdout.includes('"id"')))) ||
|
|
140
|
+
(!allowPartial && result.truncated)) {
|
|
141
|
+
const tail = (result.stderr.trim().split("\n").pop() ?? "").slice(0, 160).replace(/\s+/g, " ");
|
|
142
|
+
throw new SourceRefusal("vercel_failed", `vercel ${version} logs exited ${result.status ?? "without a status"}${result.truncated ? " (output truncated)" : ""}: ${tail}`);
|
|
143
|
+
}
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
117
146
|
/** The window cut into slices, one per query; a slice that comes back full is split again later. */
|
|
118
147
|
function initialTasks(window, queries, allLevels) {
|
|
119
148
|
const queue = [];
|
|
@@ -125,17 +154,8 @@ function initialTasks(window, queries, allLevels) {
|
|
|
125
154
|
return queue;
|
|
126
155
|
}
|
|
127
156
|
/** One `vercel logs` call for a time slice; a refusal throws, a timeout is an answer the caller splits on. */
|
|
128
|
-
async function fetchSlice(context, task) {
|
|
129
|
-
const result = await context
|
|
130
|
-
const refusal = vercelRefusal(result);
|
|
131
|
-
if (refusal)
|
|
132
|
-
throw refusal;
|
|
133
|
-
if (result.failure && result.failure !== "timeout")
|
|
134
|
-
throw new SourceRefusal("vercel_failed", `the vercel CLI could not run (${result.failure})`);
|
|
135
|
-
if (result.status !== 0 && result.status !== null && !result.stdout.includes('"id"')) {
|
|
136
|
-
const tail = (result.stderr.trim().split("\n").pop() ?? "").slice(0, 160).replace(/\s+/g, " ");
|
|
137
|
-
throw new SourceRefusal("vercel_failed", `vercel logs exited ${result.status}: ${tail}`);
|
|
138
|
-
}
|
|
157
|
+
async function fetchSlice(context, version, task) {
|
|
158
|
+
const result = await runVercel(context, version, ["logs", ...VERCEL_TARGET, "--since", isoOf(task.from), "--until", isoOf(task.to), ...task.query, "--json", "--limit", "100", "--no-color", "--non-interactive"], true);
|
|
139
159
|
return { records: parseRecords(result.stdout), timedOut: result.failure === "timeout" };
|
|
140
160
|
}
|
|
141
161
|
function dashboardCoverageNote(allLevels, classes, recordCount) {
|
|
@@ -144,7 +164,51 @@ function dashboardCoverageNote(allLevels, classes, recordCount) {
|
|
|
144
164
|
? `requests ${requests.toLocaleString("en-US")}: 2xx ${classes.ok.toLocaleString("en-US")}, 3xx ${classes.redirect}, 4xx ${classes.client}, 5xx ${classes.server}`
|
|
145
165
|
: `read only the records Vercel marks error, warning or fatal, and every 5xx (${recordCount} records); info-only requests were not read (--all-levels reads them, slowly)`;
|
|
146
166
|
}
|
|
147
|
-
|
|
167
|
+
async function readQueryDashboard(context, version) {
|
|
168
|
+
const { window, log } = context;
|
|
169
|
+
const allLevels = context.allLevels ?? false;
|
|
170
|
+
const { runtime, requests } = await readVercelQuery(window, allLevels, VERCEL_TARGET, version, (args) => runVercel(context, version, args, false));
|
|
171
|
+
const { lines: runtimeLines } = vercelRecordLines(runtime.records, window.fromEpoch, "dashboard");
|
|
172
|
+
const { lines: requestLines, classes } = vercelRecordLines(requests.records, window.fromEpoch, "dashboard");
|
|
173
|
+
const lines = [...runtimeLines, ...requestLines];
|
|
174
|
+
const notes = [
|
|
175
|
+
allLevels
|
|
176
|
+
? `read ${runtime.records.length} runtime records; ${dashboardCoverageNote(true, classes, requests.records.length)}`
|
|
177
|
+
: `read ${runtime.records.length} error, warning or fatal runtime records and ${requests.records.length} 5xx requests; --all-levels reads every level and status`,
|
|
178
|
+
];
|
|
179
|
+
if (runtime.partial || requests.partial)
|
|
180
|
+
notes.push("incomplete: Vercel excluded time intervals or the page limit was reached");
|
|
181
|
+
log("[logs dashboard] read complete", {
|
|
182
|
+
version, runtime_pages: runtime.pages, request_pages: requests.pages, runtime_records: runtime.records.length,
|
|
183
|
+
request_records: requests.records.length, lines: lines.length, server_errors: classes.server, partial: runtime.partial || requests.partial, all_levels: allLevels,
|
|
184
|
+
});
|
|
185
|
+
return { lines, notes };
|
|
186
|
+
}
|
|
187
|
+
function withDashboardReadDeadline(context) {
|
|
188
|
+
const budgetMs = context.limits?.dashboardReadMs ?? DASHBOARD_READ_BUDGET_MS;
|
|
189
|
+
const deadline = performance.now() + budgetMs;
|
|
190
|
+
const refused = () => new SourceRefusal("vercel_read_deadline", `dashboard log read reached its ${budgetMs} ms time limit; request a shorter window`);
|
|
191
|
+
return {
|
|
192
|
+
...context,
|
|
193
|
+
run: async (command, args, options) => {
|
|
194
|
+
const remaining = Math.ceil(deadline - performance.now());
|
|
195
|
+
if (remaining <= 0)
|
|
196
|
+
throw refused();
|
|
197
|
+
const result = await context.run(command, args, { ...options, timeoutMs: Math.min(options.timeoutMs, remaining) });
|
|
198
|
+
if (performance.now() >= deadline || (remaining <= options.timeoutMs && result.failure === "timeout"))
|
|
199
|
+
throw refused();
|
|
200
|
+
return result;
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
export async function readDashboard(input) {
|
|
205
|
+
const context = withDashboardReadDeadline(input);
|
|
206
|
+
const version = await vercelVersion(context);
|
|
207
|
+
if (Number(version.split(".")[0]) >= 65)
|
|
208
|
+
return readQueryDashboard(context, version);
|
|
209
|
+
return readLegacyDashboard(context, version);
|
|
210
|
+
}
|
|
211
|
+
async function readLegacyDashboard(context, version) {
|
|
148
212
|
const { window, log } = context;
|
|
149
213
|
const allLevels = context.allLevels ?? false;
|
|
150
214
|
const queries = allLevels ? ALL_QUERIES : PROBLEM_QUERIES;
|
|
@@ -157,7 +221,7 @@ export async function readDashboard(context) {
|
|
|
157
221
|
let failure = null;
|
|
158
222
|
const attempt = async (task) => {
|
|
159
223
|
calls += 1;
|
|
160
|
-
const { records, timedOut } = await fetchSlice(context, task);
|
|
224
|
+
const { records, timedOut } = await fetchSlice(context, version, task);
|
|
161
225
|
for (const record of records)
|
|
162
226
|
if (record.id && !seen.has(record.id))
|
|
163
227
|
seen.set(record.id, record);
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
* and the Python-pinned tests run with it off.
|
|
18
18
|
*/
|
|
19
19
|
import { type JsonObject } from "./judge.js";
|
|
20
|
-
/** The line with its zero counters removed, so `failed=0` does not read as a failure. */
|
|
21
20
|
export declare function withoutZeroCounters(text: string): string;
|
|
22
21
|
export interface Tagged {
|
|
23
22
|
tag: string;
|
|
@@ -32,11 +32,9 @@ const EXPLAIN = [
|
|
|
32
32
|
"exception", "detail", "server_reason", "sync_reason", "error_code", "error_syscall",
|
|
33
33
|
];
|
|
34
34
|
const WORD = /[A-Za-z]+/g;
|
|
35
|
-
|
|
36
|
-
const ZERO_COUNTER = /\b(?:fail(?:ed|ures?)?|errors?)\s*[=:]\s*0\b/gi;
|
|
37
|
-
/** The line with its zero counters removed, so `failed=0` does not read as a failure. */
|
|
35
|
+
const EMPTY_FAILURE_COUNTER = /\b(?:fail(?:ed|ures?)?|errors?)\s*[=:]\s*(?:(?:0|null)\b|\[\s*\])/gi;
|
|
38
36
|
export function withoutZeroCounters(text) {
|
|
39
|
-
return text.replace(
|
|
37
|
+
return text.replace(EMPTY_FAILURE_COUNTER, "");
|
|
40
38
|
}
|
|
41
39
|
/** `[tag] sentence {json}` split into its parts, or null when the line does not start with a tag. */
|
|
42
40
|
export function parseTagged(message) {
|
|
@@ -39,9 +39,17 @@ export const TOWER_PATTERNS = [
|
|
|
39
39
|
class: "our_bug",
|
|
40
40
|
source: "^collector$",
|
|
41
41
|
match: raw `^\[raw-evidence\] git diff failed `,
|
|
42
|
-
note: "
|
|
42
|
+
note: "Git could not capture a diff. Older collectors also emitted this for plain folders, which now have their own skip reason.",
|
|
43
43
|
basis: "collector logs, 3 d: 1,218 lines, both diff_target values, every tick",
|
|
44
44
|
},
|
|
45
|
+
{
|
|
46
|
+
id: "collector-git-diff-not-worktree",
|
|
47
|
+
class: "dead_source",
|
|
48
|
+
source: "^collector$",
|
|
49
|
+
match: raw `^\[raw-evidence\] git diff skipped, not a working tree`,
|
|
50
|
+
note: "The folder can contribute transcripts but cannot contribute a Git diff.",
|
|
51
|
+
basis: "collector worktree probe; the Git process never attempts either diff target",
|
|
52
|
+
},
|
|
45
53
|
{
|
|
46
54
|
id: "collector-git-diff-root-missing",
|
|
47
55
|
class: "dead_source",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function formatMailTime(instant: string | null | undefined, timeZone?: string): string;
|