@bli-cockpit/telemetry-core 0.1.75 → 0.1.77
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/evidence-upload.d.ts +40 -0
- package/dist/evidence-upload.js +10 -0
- package/dist/image-marker-resolver.js +31 -22
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/log-digest/digest-source.js +33 -23
- package/dist/log-digest/digest.d.ts +4 -0
- package/dist/log-digest/digest.js +44 -35
- package/dist/log-digest/index.d.ts +1 -1
- package/dist/log-digest/judge.js +15 -10
- package/dist/log-digest/log-projects.d.ts +15 -1
- package/dist/log-digest/log-projects.js +3 -0
- package/dist/log-digest/merge.js +49 -35
- package/dist/log-digest/render.js +11 -6
- package/dist/log-digest/sources/process.js +38 -19
- package/dist/log-digest/sources/vercel.js +62 -47
- package/dist/log-digest/stored.js +31 -24
- package/dist/node-daemon-http-client.js +23 -23
- package/dist/session-client-app.d.ts +21 -0
- package/dist/session-client-app.js +51 -0
- package/dist/session-facts-active.d.ts +7 -0
- package/dist/session-facts-active.js +18 -0
- package/dist/session-facts-spawn.d.ts +36 -0
- package/dist/session-facts-spawn.js +50 -2
- package/dist/session-facts.d.ts +18 -10
- package/dist/session-facts.js +17 -12
- package/package.json +1 -1
|
@@ -257,6 +257,10 @@ export declare const RawEvidenceUploadBeginResponseObjectSchema: z.ZodObject<{
|
|
|
257
257
|
upload_id: z.ZodOptional<z.ZodString>;
|
|
258
258
|
received_chunk_indexes: z.ZodDefault<z.ZodArray<z.ZodNumber>>;
|
|
259
259
|
commit_ready: z.ZodOptional<z.ZodBoolean>;
|
|
260
|
+
signed_uploads: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
261
|
+
chunk_index: z.ZodNumber;
|
|
262
|
+
signed_url: z.ZodString;
|
|
263
|
+
}, z.core.$strict>>>;
|
|
260
264
|
reason: z.ZodOptional<z.ZodString>;
|
|
261
265
|
}, z.core.$strict>;
|
|
262
266
|
export type RawEvidenceUploadBeginResponseObject = z.infer<typeof RawEvidenceUploadBeginResponseObjectSchema>;
|
|
@@ -274,6 +278,10 @@ export declare const RawEvidenceUploadBeginResponseSchema: z.ZodObject<{
|
|
|
274
278
|
upload_id: z.ZodOptional<z.ZodString>;
|
|
275
279
|
received_chunk_indexes: z.ZodDefault<z.ZodArray<z.ZodNumber>>;
|
|
276
280
|
commit_ready: z.ZodOptional<z.ZodBoolean>;
|
|
281
|
+
signed_uploads: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
282
|
+
chunk_index: z.ZodNumber;
|
|
283
|
+
signed_url: z.ZodString;
|
|
284
|
+
}, z.core.$strict>>>;
|
|
277
285
|
reason: z.ZodOptional<z.ZodString>;
|
|
278
286
|
}, z.core.$strict>>;
|
|
279
287
|
}, z.core.$strict>;
|
|
@@ -329,6 +337,11 @@ export declare const RawEvidenceUploadChunkResponseSchema: z.ZodObject<{
|
|
|
329
337
|
received_chunk_count: z.ZodNumber;
|
|
330
338
|
}, z.core.$strict>;
|
|
331
339
|
export type RawEvidenceUploadChunkResponse = z.infer<typeof RawEvidenceUploadChunkResponseSchema>;
|
|
340
|
+
export declare const RawEvidenceDirectChunkSchema: z.ZodObject<{
|
|
341
|
+
chunk_index: z.ZodNumber;
|
|
342
|
+
byte_size: z.ZodNumber;
|
|
343
|
+
chunk_hash_sha256: z.ZodString;
|
|
344
|
+
}, z.core.$strict>;
|
|
332
345
|
export declare const RawEvidenceUploadCommitRequestSchema: z.ZodObject<{
|
|
333
346
|
schema_version: z.ZodLiteral<"ambient-raw-evidence-upload-commit.v1">;
|
|
334
347
|
generated_at: z.ZodString;
|
|
@@ -363,6 +376,11 @@ export declare const RawEvidenceUploadCommitRequestSchema: z.ZodObject<{
|
|
|
363
376
|
}, z.core.$strict>;
|
|
364
377
|
upload_id: z.ZodString;
|
|
365
378
|
object_key: z.ZodString;
|
|
379
|
+
direct_chunks: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
380
|
+
chunk_index: z.ZodNumber;
|
|
381
|
+
byte_size: z.ZodNumber;
|
|
382
|
+
chunk_hash_sha256: z.ZodString;
|
|
383
|
+
}, z.core.$strict>>>;
|
|
366
384
|
}, z.core.$strict>;
|
|
367
385
|
export type RawEvidenceUploadCommitRequest = z.infer<typeof RawEvidenceUploadCommitRequestSchema>;
|
|
368
386
|
export declare const RawEvidenceUploadCommitResponseSchema: z.ZodObject<{
|
|
@@ -579,6 +597,7 @@ export declare const CodexSessionAttributionSchema: z.ZodObject<{
|
|
|
579
597
|
first_timestamp: z.ZodNullable<z.ZodString>;
|
|
580
598
|
last_timestamp: z.ZodNullable<z.ZodString>;
|
|
581
599
|
wall_duration_seconds: z.ZodNullable<z.ZodNumber>;
|
|
600
|
+
active_seconds: z.ZodOptional<z.ZodNumber>;
|
|
582
601
|
transcript_bytes: z.ZodNumber;
|
|
583
602
|
transcript_lines: z.ZodNumber;
|
|
584
603
|
transcript_files: z.ZodNumber;
|
|
@@ -596,6 +615,16 @@ export declare const CodexSessionAttributionSchema: z.ZodObject<{
|
|
|
596
615
|
worker: "worker";
|
|
597
616
|
subagent: "subagent";
|
|
598
617
|
}>;
|
|
618
|
+
client_app: z.ZodOptional<z.ZodEnum<{
|
|
619
|
+
unknown: "unknown";
|
|
620
|
+
claude_cli: "claude_cli";
|
|
621
|
+
claude_desktop: "claude_desktop";
|
|
622
|
+
claude_ide: "claude_ide";
|
|
623
|
+
codex_cli: "codex_cli";
|
|
624
|
+
codex_desktop: "codex_desktop";
|
|
625
|
+
codex_ide: "codex_ide";
|
|
626
|
+
codex_exec: "codex_exec";
|
|
627
|
+
}>>;
|
|
599
628
|
parent_session_id: z.ZodOptional<z.ZodString>;
|
|
600
629
|
}, z.core.$strict>>;
|
|
601
630
|
}, z.core.$strict>>;
|
|
@@ -702,6 +731,7 @@ export declare const CodexSessionAttributionReportRequestSchema: z.ZodObject<{
|
|
|
702
731
|
first_timestamp: z.ZodNullable<z.ZodString>;
|
|
703
732
|
last_timestamp: z.ZodNullable<z.ZodString>;
|
|
704
733
|
wall_duration_seconds: z.ZodNullable<z.ZodNumber>;
|
|
734
|
+
active_seconds: z.ZodOptional<z.ZodNumber>;
|
|
705
735
|
transcript_bytes: z.ZodNumber;
|
|
706
736
|
transcript_lines: z.ZodNumber;
|
|
707
737
|
transcript_files: z.ZodNumber;
|
|
@@ -719,6 +749,16 @@ export declare const CodexSessionAttributionReportRequestSchema: z.ZodObject<{
|
|
|
719
749
|
worker: "worker";
|
|
720
750
|
subagent: "subagent";
|
|
721
751
|
}>;
|
|
752
|
+
client_app: z.ZodOptional<z.ZodEnum<{
|
|
753
|
+
unknown: "unknown";
|
|
754
|
+
claude_cli: "claude_cli";
|
|
755
|
+
claude_desktop: "claude_desktop";
|
|
756
|
+
claude_ide: "claude_ide";
|
|
757
|
+
codex_cli: "codex_cli";
|
|
758
|
+
codex_desktop: "codex_desktop";
|
|
759
|
+
codex_ide: "codex_ide";
|
|
760
|
+
codex_exec: "codex_exec";
|
|
761
|
+
}>>;
|
|
722
762
|
parent_session_id: z.ZodOptional<z.ZodString>;
|
|
723
763
|
}, z.core.$strict>>;
|
|
724
764
|
}, z.core.$strict>>;
|
package/dist/evidence-upload.js
CHANGED
|
@@ -112,6 +112,10 @@ export const RawEvidenceUploadBeginResponseObjectSchema = z
|
|
|
112
112
|
// A completed staged plan may use a chunk layout from an older collector.
|
|
113
113
|
// The client must commit it directly instead of mixing in its current plan.
|
|
114
114
|
commit_ready: z.boolean().optional(),
|
|
115
|
+
signed_uploads: z.array(z.object({
|
|
116
|
+
chunk_index: z.number().int().nonnegative(),
|
|
117
|
+
signed_url: z.string().url(),
|
|
118
|
+
}).strict()).optional(),
|
|
115
119
|
reason: SafeLabelSchema.optional(),
|
|
116
120
|
})
|
|
117
121
|
.strict();
|
|
@@ -147,6 +151,11 @@ export const RawEvidenceUploadChunkResponseSchema = z
|
|
|
147
151
|
received_chunk_count: z.number().int().nonnegative(),
|
|
148
152
|
})
|
|
149
153
|
.strict();
|
|
154
|
+
export const RawEvidenceDirectChunkSchema = z.object({
|
|
155
|
+
chunk_index: z.number().int().nonnegative(),
|
|
156
|
+
byte_size: z.number().int().positive().max(RAW_EVIDENCE_UPLOAD_MAX_CHUNK_BYTES),
|
|
157
|
+
chunk_hash_sha256: Sha256Schema,
|
|
158
|
+
}).strict();
|
|
150
159
|
export const RawEvidenceUploadCommitRequestSchema = z
|
|
151
160
|
.object({
|
|
152
161
|
schema_version: z.literal("ambient-raw-evidence-upload-commit.v1"),
|
|
@@ -154,6 +163,7 @@ export const RawEvidenceUploadCommitRequestSchema = z
|
|
|
154
163
|
provenance: CaptureProvenanceSchema,
|
|
155
164
|
upload_id: NonEmptyStringSchema,
|
|
156
165
|
object_key: NonEmptyStringSchema,
|
|
166
|
+
direct_chunks: z.array(RawEvidenceDirectChunkSchema).max(RAW_EVIDENCE_UPLOAD_MAX_CHUNK_COUNT).optional(),
|
|
157
167
|
})
|
|
158
168
|
.strict();
|
|
159
169
|
export const RawEvidenceUploadCommitResponseSchema = z
|
|
@@ -48,15 +48,37 @@ export function applyImageNotes(text, notes, escape = "json") {
|
|
|
48
48
|
return description ? describedMarker(whole, description, escape) : whole;
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
/** Logs one line per resolved text, with run-wide totals carried across calls. */
|
|
52
|
+
function createSummaryLogger(reader, log) {
|
|
53
|
+
let totalFound = 0;
|
|
54
|
+
let totalResolved = 0;
|
|
55
|
+
let totalLookups = 0;
|
|
56
|
+
return (summary) => {
|
|
57
|
+
totalFound += summary.found;
|
|
58
|
+
totalResolved += summary.resolved;
|
|
59
|
+
totalLookups += summary.lookups;
|
|
60
|
+
log(`${TAG} markers resolved`, {
|
|
61
|
+
reader,
|
|
62
|
+
found: summary.found,
|
|
63
|
+
resolved: summary.resolved,
|
|
64
|
+
missing: summary.found - summary.resolved,
|
|
65
|
+
missing_reasons: summary.reasons,
|
|
66
|
+
distinct: summary.distinct,
|
|
67
|
+
looked_up: summary.askedFor,
|
|
68
|
+
lookups: summary.lookups,
|
|
69
|
+
run_found: totalFound,
|
|
70
|
+
run_resolved: totalResolved,
|
|
71
|
+
run_lookups: totalLookups,
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/** The remembered descriptions, the batched lookups behind them and the run-wide counters that log them. */
|
|
76
|
+
function createMarkerLookups(lookup, options) {
|
|
52
77
|
const log = options.log ?? ((message, fields) => console.info(message, JSON.stringify(fields)));
|
|
53
78
|
const batchSize = Math.max(1, options.batchSize ?? DEFAULT_BATCH);
|
|
54
79
|
const maxRemembered = Math.max(1, options.maxRemembered ?? DEFAULT_MAX_REMEMBERED);
|
|
55
80
|
/** description, or null for "asked and there is none". A failed lookup is never remembered. */
|
|
56
81
|
const remembered = new Map();
|
|
57
|
-
let totalFound = 0;
|
|
58
|
-
let totalResolved = 0;
|
|
59
|
-
let totalLookups = 0;
|
|
60
82
|
function remember(prefix, description) {
|
|
61
83
|
if (remembered.size >= maxRemembered) {
|
|
62
84
|
const oldest = remembered.keys().next();
|
|
@@ -99,25 +121,12 @@ export function createImageDescriptionResolver(lookup, options) {
|
|
|
99
121
|
const { lookups, failed } = toAsk.length ? await fetchMissing(toAsk) : { lookups: 0, failed: new Set() };
|
|
100
122
|
return { found: markers.length, distinct, failed, lookups, askedFor: toAsk.length };
|
|
101
123
|
}
|
|
102
|
-
|
|
103
|
-
totalFound += summary.found;
|
|
104
|
-
totalResolved += summary.resolved;
|
|
105
|
-
totalLookups += summary.lookups;
|
|
106
|
-
log(`${TAG} markers resolved`, {
|
|
107
|
-
reader: options.reader,
|
|
108
|
-
found: summary.found,
|
|
109
|
-
resolved: summary.resolved,
|
|
110
|
-
missing: summary.found - summary.resolved,
|
|
111
|
-
missing_reasons: summary.reasons,
|
|
112
|
-
distinct: summary.distinct,
|
|
113
|
-
looked_up: summary.askedFor,
|
|
114
|
-
lookups: summary.lookups,
|
|
115
|
-
run_found: totalFound,
|
|
116
|
-
run_resolved: totalResolved,
|
|
117
|
-
run_lookups: totalLookups,
|
|
118
|
-
});
|
|
119
|
-
}
|
|
124
|
+
const logSummary = createSummaryLogger(options.reader, log);
|
|
120
125
|
const reasonFor = (prefix, failed) => (failed.has(prefix) ? "lookup_failed" : "no_description_row");
|
|
126
|
+
return { remembered, ask, logSummary, reasonFor };
|
|
127
|
+
}
|
|
128
|
+
export function createImageDescriptionResolver(lookup, options) {
|
|
129
|
+
const { remembered, ask, logSummary, reasonFor } = createMarkerLookups(lookup, options);
|
|
121
130
|
return {
|
|
122
131
|
async inline(text, callOptions) {
|
|
123
132
|
const asked = await ask(text);
|
package/dist/index.d.ts
CHANGED
|
@@ -30,6 +30,8 @@ export * from "./secret-guards.js";
|
|
|
30
30
|
export * from "./session-facts.js";
|
|
31
31
|
export * from "./session-facts-skills.js";
|
|
32
32
|
export * from "./session-facts-spawn.js";
|
|
33
|
+
export * from "./session-facts-active.js";
|
|
34
|
+
export * from "./session-client-app.js";
|
|
33
35
|
export * from "./source-adapter.js";
|
|
34
36
|
export * from "./ticket-id.js";
|
|
35
37
|
export * from "./trace-sink.js";
|
package/dist/index.js
CHANGED
|
@@ -30,6 +30,8 @@ export * from "./secret-guards.js";
|
|
|
30
30
|
export * from "./session-facts.js";
|
|
31
31
|
export * from "./session-facts-skills.js";
|
|
32
32
|
export * from "./session-facts-spawn.js";
|
|
33
|
+
export * from "./session-facts-active.js";
|
|
34
|
+
export * from "./session-client-app.js";
|
|
33
35
|
export * from "./source-adapter.js";
|
|
34
36
|
export * from "./ticket-id.js";
|
|
35
37
|
export * from "./trace-sink.js";
|
|
@@ -56,6 +56,34 @@ export function classifyTemplates(result, table, family) {
|
|
|
56
56
|
// What needs a person first, then by count: the same order the text view uses.
|
|
57
57
|
return rows.sort((a, b) => (CLASS_ORDER[a.class] ?? 0) - (CLASS_ORDER[b.class] ?? 0) || b.count - a.count || (a.tid < b.tid ? -1 : 1));
|
|
58
58
|
}
|
|
59
|
+
/** The source's lines, or the named refusal the source gave instead. */
|
|
60
|
+
async function readSource(read, context, log, family) {
|
|
61
|
+
try {
|
|
62
|
+
return await read(context);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
if (error instanceof SourceRefusal) {
|
|
66
|
+
log("[logs digest] refused", { reason: error.reason, source: family });
|
|
67
|
+
return { ok: false, reason: error.reason, detail: error.detail };
|
|
68
|
+
}
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/** Adds every line to the digest; when `wanted` names a template, also collects that template's lines as printable text. */
|
|
73
|
+
function feedDigest(digest, lines, wanted) {
|
|
74
|
+
const raw = [];
|
|
75
|
+
let matched = 0;
|
|
76
|
+
for (const line of lines) {
|
|
77
|
+
const before = wanted ? digest.groups.get(wanted)?.count ?? 0 : 0;
|
|
78
|
+
digest.addLine(line.unit, line.message, line.ts, { level: line.level });
|
|
79
|
+
if (wanted && (digest.groups.get(wanted)?.count ?? 0) !== before) {
|
|
80
|
+
matched += 1;
|
|
81
|
+
const stamp = line.ts ? `${new Date(line.ts * 1000).toISOString().slice(11, 19)}Z ` : "";
|
|
82
|
+
raw.push(`${stamp}${line.unit}: ${cut(redact(squash(line.message)), RAW_LINE_CHARS)}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return { raw, matched };
|
|
86
|
+
}
|
|
59
87
|
/** Reads, digests, classifies and renders one source. Never throws for a refusal: it is returned, named. */
|
|
60
88
|
export async function digestSource(request, env = {}) {
|
|
61
89
|
const log = env.log ?? defaultLog;
|
|
@@ -86,32 +114,14 @@ export async function digestSource(request, env = {}) {
|
|
|
86
114
|
const context = {
|
|
87
115
|
window, run: env.run ?? nodeRunCli, log, stateDir: env.stateDir, stdinText: env.stdinText, stdinIsTerminal: env.stdinIsTerminal, limits: env.limits, allLevels: request.allLevels,
|
|
88
116
|
};
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
source
|
|
92
|
-
}
|
|
93
|
-
catch (error) {
|
|
94
|
-
if (error instanceof SourceRefusal) {
|
|
95
|
-
log("[logs digest] refused", { reason: error.reason, source: family });
|
|
96
|
-
return { ok: false, reason: error.reason, detail: error.detail };
|
|
97
|
-
}
|
|
98
|
-
throw error;
|
|
99
|
-
}
|
|
117
|
+
const source = await readSource(read, context, log, family);
|
|
118
|
+
if ("ok" in source)
|
|
119
|
+
return source;
|
|
100
120
|
const digest = new Digest({ noise: table.noiseUnits, taggedLines: true });
|
|
101
|
-
const raw =
|
|
102
|
-
const wanted = request.raw;
|
|
103
|
-
let matched = 0;
|
|
104
|
-
for (const line of source.lines) {
|
|
105
|
-
const before = wanted ? digest.groups.get(wanted)?.count ?? 0 : 0;
|
|
106
|
-
digest.addLine(line.unit, line.message, line.ts, { level: line.level });
|
|
107
|
-
if (wanted && (digest.groups.get(wanted)?.count ?? 0) !== before) {
|
|
108
|
-
matched += 1;
|
|
109
|
-
const stamp = line.ts ? `${new Date(line.ts * 1000).toISOString().slice(11, 19)}Z ` : "";
|
|
110
|
-
raw.push(`${stamp}${line.unit}: ${cut(redact(squash(line.message)), RAW_LINE_CHARS)}`);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
121
|
+
const { raw, matched } = feedDigest(digest, source.lines, request.raw);
|
|
113
122
|
const result = digest.result();
|
|
114
123
|
const facts = windowFacts(window);
|
|
124
|
+
const wanted = request.raw;
|
|
115
125
|
if (wanted) {
|
|
116
126
|
const limit = request.rawLimit ?? RAW_DEFAULT_LIMIT;
|
|
117
127
|
const lines = raw.slice(-limit);
|
|
@@ -78,6 +78,10 @@ export declare class Digest {
|
|
|
78
78
|
addEntry(entry: JournalEntry): void;
|
|
79
79
|
/** One log line from any source. `ts` is epoch seconds (0 when the source has none). */
|
|
80
80
|
addLine(unit: string, message: string, ts: number, facts?: LineFacts): void;
|
|
81
|
+
private addJsonLine;
|
|
82
|
+
/** True when the line carried a `[tag]` and was filed; false leaves it for the plain-line rules. */
|
|
83
|
+
private addTaggedLine;
|
|
84
|
+
private addPlainLine;
|
|
81
85
|
/** A line the class table asked to see even without a trouble word (a `watch` pattern matches its masked text). */
|
|
82
86
|
private watched;
|
|
83
87
|
private routineCount;
|
|
@@ -113,49 +113,58 @@ export class Digest {
|
|
|
113
113
|
return;
|
|
114
114
|
const stripped = message.trim();
|
|
115
115
|
if (stripped.startsWith("{") || Array.from(stripped).length > LONG_LINE_CHARS) {
|
|
116
|
-
|
|
117
|
-
if (records === null) {
|
|
118
|
-
// journald splits a huge JSON line into pieces; a piece is not a sentence, and words like
|
|
119
|
-
// "archiveFailed" or "errors" inside it are key names, not failures.
|
|
120
|
-
this.routineCount(group, "json_fragment", null);
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
for (const data of records) {
|
|
124
|
-
if (this.routineUnits.has(bare)) {
|
|
125
|
-
this.routineCount(group, "relay", null); // watchdog and breaker records: ingested from their own files
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
const judged = judgeJson(data);
|
|
129
|
-
if (judged.important && judged.template !== null) {
|
|
130
|
-
this.addGroup(group, instance, judged.event, judged.template, ts, cut(pythonJson(data), EXAMPLE_CHARS * 2));
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
this.routineCount(group, judged.event, judged.subject);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
116
|
+
this.addJsonLine(stripped, group, instance, bare, ts);
|
|
136
117
|
return;
|
|
137
118
|
}
|
|
138
119
|
if (FRAME_LINE.test(message) || message.startsWith(" ")) {
|
|
139
120
|
this.routineCount(group, "traceback_frame", null); // a frame or code line whose traceback header was interleaved away
|
|
140
121
|
return;
|
|
141
122
|
}
|
|
142
|
-
if (this.taggedLines && !manager)
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
123
|
+
if (this.taggedLines && !manager && this.addTaggedLine(message, group, instance, ts, facts.level))
|
|
124
|
+
return;
|
|
125
|
+
this.addPlainLine(unit, message, group, instance, ts, manager);
|
|
126
|
+
}
|
|
127
|
+
addJsonLine(stripped, group, instance, bare, ts) {
|
|
128
|
+
const records = jsonRecords(stripped);
|
|
129
|
+
if (records === null) {
|
|
130
|
+
// journald splits a huge JSON line into pieces; a piece is not a sentence, and words like
|
|
131
|
+
// "archiveFailed" or "errors" inside it are key names, not failures.
|
|
132
|
+
this.routineCount(group, "json_fragment", null);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
for (const data of records) {
|
|
136
|
+
if (this.routineUnits.has(bare)) {
|
|
137
|
+
this.routineCount(group, "relay", null); // watchdog and breaker records: ingested from their own files
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
const judged = judgeJson(data);
|
|
141
|
+
if (judged.important && judged.template !== null) {
|
|
142
|
+
this.addGroup(group, instance, judged.event, judged.template, ts, cut(pythonJson(data), EXAMPLE_CHARS * 2));
|
|
157
143
|
}
|
|
144
|
+
else {
|
|
145
|
+
this.routineCount(group, judged.event, judged.subject);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/** True when the line carried a `[tag]` and was filed; false leaves it for the plain-line rules. */
|
|
150
|
+
addTaggedLine(message, group, instance, ts, level) {
|
|
151
|
+
const parsed = parseTagged(message);
|
|
152
|
+
if (!parsed)
|
|
153
|
+
return false;
|
|
154
|
+
const judged = judgeTagged(parsed, level);
|
|
155
|
+
if (!judged.important && this.watched(group, message)) {
|
|
156
|
+
this.addGroup(group, instance, "tagged", mask(message), ts, message);
|
|
158
157
|
}
|
|
158
|
+
else if (!judged.important) {
|
|
159
|
+
this.routineCount(group, judged.template, null);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
const template = judged.declaredWarning ? cut(judged.template, TEMPLATE_CHARS - DECLARED_WARNING.length) + DECLARED_WARNING : judged.template;
|
|
163
|
+
this.addGroup(group, instance, "tagged", template, ts, message);
|
|
164
|
+
}
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
addPlainLine(unit, message, group, instance, ts, manager) {
|
|
159
168
|
const event = manager ? "systemd" : unit === "kernel" ? "kernel" : "log";
|
|
160
169
|
// The source's own level is NOT a verdict on a plain line: Tower writes ordinary output to stderr, which Vercel
|
|
161
170
|
// and Railway both mark "error" (measured 2026-10-07). Words and fields decide; see tagged.ts.
|
|
@@ -15,6 +15,6 @@ export { VERCEL_PROJECT, VERCEL_SCOPE, readDashboard, routeTemplate, vercelRecor
|
|
|
15
15
|
export { readStdin } from "./sources/stdin.js";
|
|
16
16
|
export { BLIND_TEMPLATE_PREFIX, LOCAL_ACCESS_REFUSALS, STORED_MAX_TEMPLATES_PER_WINDOW, digestLines, mergeStored, notReadLines, scrubRow, storedRowBytes, toStoredRows, type DigestedLines, type StillRefusing, type StoredMerge, type StoredRow, type StoredWindow, type UnreadableSource, } from "./stored.js";
|
|
17
17
|
export { PROJECT_TABLES, projectClassTable } from "./project-classes.js";
|
|
18
|
-
export { BRAIN_PROJECT_IDS, LOG_EXCLUDED, LOG_EXCLUDED_SUPABASE_REFS, LOG_PROJECTS, LOG_PROJECT_IDS, LOG_PROJECT_PATTERN, TOWER_RAILWAY, VERCEL_TEAM_ID, brainRouteFor, findLogProject, type PushSource, type BrainConfig, type BrainMergePolicy, type BrainRoute, type GcpSource, type LogProject, type LogSource, type NotWiredSource, type RailwaySource, type SupabaseSource, type SupabaseStream, type VercelSource, } from "./log-projects.js";
|
|
18
|
+
export { BRAIN_PROJECT_IDS, LOG_EXCLUDED, LOG_EXCLUDED_SUPABASE_REFS, LOG_PROJECTS, LOG_PROJECT_IDS, LOG_PROJECT_PATTERN, TOWER_RAILWAY, VERCEL_TEAM_ID, brainRouteFor, findLogProject, type PushSource, type BrainConfig, type BrainMergePolicy, type BrainRoute, type GcpSource, type DeploysSource, type DbHostSource, type LogProject, type LogSource, type NotWiredSource, type RailwaySource, type SupabaseSource, type SupabaseStream, type VercelSource, } from "./log-projects.js";
|
|
19
19
|
export { STORED_EXAMPLE_CHARS, STORED_TEMPLATE_CHARS, scrubForStorage, scrubLine, scrubUnit } from "./scrub.js";
|
|
20
20
|
export { isStaleTemplate, remaskedTemplate, sameFailureUnderCurrentMask } from "./remask.js";
|
package/dist/log-digest/judge.js
CHANGED
|
@@ -50,22 +50,27 @@ function objectEnd(text, start) {
|
|
|
50
50
|
let inString = false;
|
|
51
51
|
for (let index = start; index < text.length; index += 1) {
|
|
52
52
|
const char = text[index];
|
|
53
|
+
if (inString && char === "\\") {
|
|
54
|
+
index += 1;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
53
57
|
if (inString) {
|
|
54
|
-
|
|
55
|
-
index += 1;
|
|
56
|
-
else if (char === '"')
|
|
57
|
-
inString = false;
|
|
58
|
+
inString = char !== '"';
|
|
58
59
|
continue;
|
|
59
60
|
}
|
|
60
|
-
if (char === '"')
|
|
61
|
+
if (char === '"') {
|
|
61
62
|
inString = true;
|
|
62
|
-
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (char === "{") {
|
|
63
66
|
depth += 1;
|
|
64
|
-
|
|
65
|
-
depth -= 1;
|
|
66
|
-
if (depth === 0)
|
|
67
|
-
return index + 1;
|
|
67
|
+
continue;
|
|
68
68
|
}
|
|
69
|
+
if (char !== "}")
|
|
70
|
+
continue;
|
|
71
|
+
depth -= 1;
|
|
72
|
+
if (depth === 0)
|
|
73
|
+
return index + 1;
|
|
69
74
|
}
|
|
70
75
|
return -1;
|
|
71
76
|
}
|
|
@@ -63,6 +63,20 @@ export interface GcpSource extends SourceBase {
|
|
|
63
63
|
/** The unit prefix of every line. */
|
|
64
64
|
unit_prefix: string;
|
|
65
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Deploy and build records (BLI-20772): every Railway deployment of the project and the Vercel deployments of its dashboard,
|
|
68
|
+
* written by the `platform-watch` service into `deploy_records` and `platform_events`. Read by the digest cron as an alert-style
|
|
69
|
+
* unit (already judged by the watcher) and by `cockpit logs search --source deploys`.
|
|
70
|
+
*/
|
|
71
|
+
export interface DeploysSource extends SourceBase {
|
|
72
|
+
kind: "deploys";
|
|
73
|
+
}
|
|
74
|
+
/** Database host health (BLI-20724): one sample a minute and the restarts, in `db_host_samples` and `platform_events`. */
|
|
75
|
+
export interface DbHostSource extends SourceBase {
|
|
76
|
+
kind: "db_host";
|
|
77
|
+
/** The Supabase project ref whose host is sampled. */
|
|
78
|
+
ref: string;
|
|
79
|
+
}
|
|
66
80
|
export interface NotWiredSource extends SourceBase {
|
|
67
81
|
kind: "not_wired";
|
|
68
82
|
/** The platform it would be read from. */
|
|
@@ -73,7 +87,7 @@ export interface NotWiredSource extends SourceBase {
|
|
|
73
87
|
export interface PushSource extends SourceBase {
|
|
74
88
|
kind: "push";
|
|
75
89
|
}
|
|
76
|
-
export type LogSource = PushSource | VercelSource | RailwaySource | SupabaseSource | GcpSource | NotWiredSource;
|
|
90
|
+
export type LogSource = PushSource | VercelSource | RailwaySource | SupabaseSource | GcpSource | DeploysSource | DbHostSource | NotWiredSource;
|
|
77
91
|
/**
|
|
78
92
|
* How the brain may land a fix (BLI-12859). `on_green`: the PR gets auto-merge, which GitHub performs only once the
|
|
79
93
|
* repo's own required checks pass. `pr_only`: the brain opens the PR and stops; a person merges.
|
|
@@ -55,6 +55,9 @@ export const LOG_PROJECTS = [
|
|
|
55
55
|
vercel("bli-cockpit-dashboard", "prj_tKAQTQFCCBIXfnEJWvAbMGAqJjuN", { unit_prefix: "dashboard", family: "dashboard" }),
|
|
56
56
|
{ kind: "railway", source: "railway:bli-cockpit-inference", family: "railway", ...TOWER_RAILWAY },
|
|
57
57
|
supabase("BLI-Cockpit", "bnwolptxyrjalnppqyaf"),
|
|
58
|
+
// BLI-20772 / BLI-20724: written by the `platform-watch` service, aggregated by the digest cron like every other source.
|
|
59
|
+
{ kind: "deploys", source: "deploys:tower", family: "deploys" },
|
|
60
|
+
{ kind: "db_host", source: "db-host:tower", family: "db_host", ref: "bnwolptxyrjalnppqyaf" },
|
|
58
61
|
],
|
|
59
62
|
// AGENTS.md "Velocity": merge on green without asking. `main`'s ruleset requires its checks and allows squash only.
|
|
60
63
|
brain: { repos: { default: "BLI-INC/bli-cockpit" }, base_branch: "main", merge: "on_green", daily_runs: 10 },
|
package/dist/log-digest/merge.js
CHANGED
|
@@ -12,6 +12,50 @@ function latest(a, b) {
|
|
|
12
12
|
const value = Math.max(a ?? 0, b ?? 0);
|
|
13
13
|
return value || null;
|
|
14
14
|
}
|
|
15
|
+
function widenSpan(merged, span) {
|
|
16
|
+
const [start, end] = span ?? [null, null];
|
|
17
|
+
if (start && (merged.span[0] === null || start < merged.span[0]))
|
|
18
|
+
merged.span[0] = start;
|
|
19
|
+
if (end && (merged.span[1] === null || end > merged.span[1]))
|
|
20
|
+
merged.span[1] = end;
|
|
21
|
+
}
|
|
22
|
+
function carryCursors(merged, cursors) {
|
|
23
|
+
const [first, last] = cursors ?? [null, null];
|
|
24
|
+
merged.cursors[0] = merged.cursors[0] ?? first;
|
|
25
|
+
merged.cursors[1] = last ?? merged.cursors[1];
|
|
26
|
+
}
|
|
27
|
+
function mergeGroup(merged, record, registry) {
|
|
28
|
+
const known = merged.groups.get(record.tid);
|
|
29
|
+
if (!known) {
|
|
30
|
+
merged.groups.set(record.tid, { ...registry[record.tid], ...record, instances: [...(record.instances ?? [])], tid: record.tid });
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
known.count += record.count;
|
|
34
|
+
known.first = earliest(known.first, record.first);
|
|
35
|
+
known.last = latest(known.last, record.last);
|
|
36
|
+
for (const instance of record.instances ?? []) {
|
|
37
|
+
if (!known.instances.includes(instance) && known.instances.length < 64)
|
|
38
|
+
known.instances.push(instance);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function addSubjects(into, subjects) {
|
|
42
|
+
for (const [subject, amount] of Object.entries(subjects)) {
|
|
43
|
+
if (subject in into || Object.keys(into).length < SUBJECTS_TRACKED)
|
|
44
|
+
into[subject] = (into[subject] ?? 0) + amount;
|
|
45
|
+
else
|
|
46
|
+
into["…"] = (into["…"] ?? 0) + amount;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function mergeRoutine(merged, routine) {
|
|
50
|
+
for (const [group, events] of Object.entries(routine ?? {})) {
|
|
51
|
+
const into = (merged.routine[group] ??= Object.create(null));
|
|
52
|
+
for (const [event, [count, subjects]] of Object.entries(events)) {
|
|
53
|
+
const record = (into[event] ??= [0, Object.create(null)]);
|
|
54
|
+
record[0] += count;
|
|
55
|
+
addSubjects(record[1], subjects);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
15
59
|
export function mergeResults(results, registry = {}) {
|
|
16
60
|
const merged = {
|
|
17
61
|
lines: 0, noise: 0,
|
|
@@ -23,42 +67,12 @@ export function mergeResults(results, registry = {}) {
|
|
|
23
67
|
for (const result of results) {
|
|
24
68
|
merged.lines += result.lines ?? 0;
|
|
25
69
|
merged.noise += result.noise ?? 0;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
merged.span[0] = start;
|
|
29
|
-
if (end && (merged.span[1] === null || end > merged.span[1]))
|
|
30
|
-
merged.span[1] = end;
|
|
31
|
-
const [first, last] = result.cursors ?? [null, null];
|
|
32
|
-
merged.cursors[0] = merged.cursors[0] ?? first;
|
|
33
|
-
merged.cursors[1] = last ?? merged.cursors[1];
|
|
70
|
+
widenSpan(merged, result.span);
|
|
71
|
+
carryCursors(merged, result.cursors);
|
|
34
72
|
const groups = result.groups ?? [];
|
|
35
|
-
for (const record of Array.isArray(groups) ? groups : Object.values(groups))
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
merged.groups.set(record.tid, { ...registry[record.tid], ...record, instances: [...(record.instances ?? [])], tid: record.tid });
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
known.count += record.count;
|
|
42
|
-
known.first = earliest(known.first, record.first);
|
|
43
|
-
known.last = latest(known.last, record.last);
|
|
44
|
-
for (const instance of record.instances ?? []) {
|
|
45
|
-
if (!known.instances.includes(instance) && known.instances.length < 64)
|
|
46
|
-
known.instances.push(instance);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
for (const [group, events] of Object.entries(result.routine ?? {})) {
|
|
50
|
-
const into = (merged.routine[group] ??= Object.create(null));
|
|
51
|
-
for (const [event, [count, subjects]] of Object.entries(events)) {
|
|
52
|
-
const record = (into[event] ??= [0, Object.create(null)]);
|
|
53
|
-
record[0] += count;
|
|
54
|
-
for (const [subject, amount] of Object.entries(subjects)) {
|
|
55
|
-
if (subject in record[1] || Object.keys(record[1]).length < SUBJECTS_TRACKED)
|
|
56
|
-
record[1][subject] = (record[1][subject] ?? 0) + amount;
|
|
57
|
-
else
|
|
58
|
-
record[1]["…"] = (record[1]["…"] ?? 0) + amount;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
73
|
+
for (const record of Array.isArray(groups) ? groups : Object.values(groups))
|
|
74
|
+
mergeGroup(merged, record, registry);
|
|
75
|
+
mergeRoutine(merged, result.routine);
|
|
62
76
|
}
|
|
63
77
|
const groups = [...merged.groups.values()].sort((a, b) => b.count - a.count || (a.tid < b.tid ? -1 : a.tid > b.tid ? 1 : 0));
|
|
64
78
|
return { lines: merged.lines, noise: merged.noise, span: merged.span, cursors: merged.cursors, groups, routine: merged.routine, breaker: {} };
|
|
@@ -73,12 +73,8 @@ export function fleetView(resultsByServer, classify, window) {
|
|
|
73
73
|
return { window: window ?? [Math.min(...(spans.length ? spans : [0])), Math.max(...(spans.length ? spans : [0]))], servers: resultsByServer, classify };
|
|
74
74
|
}
|
|
75
75
|
const compareTid = (a, b) => (a.tid < b.tid ? -1 : a.tid > b.tid ? 1 : 0);
|
|
76
|
-
/**
|
|
77
|
-
|
|
78
|
-
const [start, end] = view.window;
|
|
79
|
-
const names = Object.keys(view.servers).sort();
|
|
80
|
-
const kept = names.reduce((sum, name) => sum + view.servers[name].lines, 0);
|
|
81
|
-
const noise = names.reduce((sum, name) => sum + view.servers[name].noise, 0);
|
|
76
|
+
/** Every server's templates merged by tid: counts summed, times widened, the servers that saw it listed. */
|
|
77
|
+
function mergeFleetTemplates(view, names) {
|
|
82
78
|
const byTid = new Map();
|
|
83
79
|
for (const name of names) {
|
|
84
80
|
for (const record of view.servers[name].groups) {
|
|
@@ -93,6 +89,15 @@ export function renderFleet(view) {
|
|
|
93
89
|
entry.instances = [...new Set([...entry.instances, ...record.instances])].sort();
|
|
94
90
|
}
|
|
95
91
|
}
|
|
92
|
+
return byTid;
|
|
93
|
+
}
|
|
94
|
+
/** The fleet digest: every server's templates merged by tid, ERROR first, hiccups counted, WARNINGs one line. */
|
|
95
|
+
export function renderFleet(view) {
|
|
96
|
+
const [start, end] = view.window;
|
|
97
|
+
const names = Object.keys(view.servers).sort();
|
|
98
|
+
const kept = names.reduce((sum, name) => sum + view.servers[name].lines, 0);
|
|
99
|
+
const noise = names.reduce((sum, name) => sum + view.servers[name].noise, 0);
|
|
100
|
+
const byTid = mergeFleetTemplates(view, names);
|
|
96
101
|
const sections = { ERROR: [], hiccup: [], WARNING: [] };
|
|
97
102
|
for (const entry of byTid.values()) {
|
|
98
103
|
const verdict = view.classify(entry.unit, entry.template, entry.servers[0]);
|