fix: collect jsonl tail windows (#692)

Co-authored-by: Codex <codex@noreply.local>
This commit is contained in:
Lyon
2026-06-22 23:02:27 +08:00
committed by GitHub
parent 2201eb1759
commit 316301b8f4
+11 -4
View File
@@ -7866,7 +7866,7 @@ function renderWebObserveCollectTable(value: Record<string, unknown>): string {
if (jsonlTail.length > 0) {
lines.push(
"JSONL tail:",
webObserveTable(["TS", "ROLE", "TYPE", "COMMAND", "ATTEMPTS", "READY", "DOM", "PATH", "MESSAGE"], jsonlTail.map((item) => {
webObserveTable(["TS", "ROLE", "TYPE", "COMMAND", "MSG", "TRACE", "LOAD", "ATTEMPTS", "READY", "DOM", "PATH", "MESSAGE"], jsonlTail.map((item) => {
const error = record(item.error);
const attempts = Array.isArray(error.attempts) ? error.attempts : [];
const lastAttempt = attempts.length > 0 ? record(attempts[attempts.length - 1]) : {};
@@ -7884,6 +7884,9 @@ function renderWebObserveCollectTable(value: Record<string, unknown>): string {
webObserveShort(webObserveText(item.pageRole ?? item.role), 12),
webObserveShort(webObserveText(item.type), 20),
webObserveShort(webObserveText(item.commandId), 28),
webObserveText(item.messageCount),
webObserveText(item.traceRowCount ?? item.traceEventCount),
webObserveText(item.loadingCount),
webObserveText(attempts.length),
webObserveShort(webObserveText(readiness.reason), 24),
webObserveShort(domBits, 48),
@@ -9265,8 +9268,10 @@ const slimJsonl=(value)=>{
path:short(value.path||value.routePath||snapshot?.path,80),
routeSessionId:short(value.routeSessionId||snapshot?.routeSessionId,48),
activeSessionId:short(value.activeSessionId||snapshot?.activeSessionId,48),
messageCount:value.messageCount??snapshot?.messageCount,
messageCount:value.messageCount??(Array.isArray(value.messages)?value.messages.length:undefined)??snapshot?.messageCount,
traceEventCount:value.traceEventCount??snapshot?.traceEventCount,
traceRowCount:value.traceRowCount??(Array.isArray(value.traceRows)?value.traceRows.length:undefined)??snapshot?.traceRowCount,
loadingCount:value.loadingCount??(Array.isArray(value.loadings)?value.loadings.length:undefined)??snapshot?.loadingCount,
method:short(value.method,12),
status:value.status,
url:short(value.url,120),
@@ -9280,8 +9285,10 @@ if(selected){
const file=path.join(dir,selected); const relative=path.relative(dir,file);
if(relative.startsWith('..')||path.isAbsolute(relative)){console.log(JSON.stringify({ok:false,command:'web-probe-observe collect',stateDir:dir,mode:'file',reason:'file-outside-state-dir',file:selected,valuesRedacted:true},null,2)); process.exit(2);}
if(!fs.existsSync(file)||!fs.statSync(file).isFile()){console.log(JSON.stringify({ok:false,command:'web-probe-observe collect',stateDir:dir,mode:'file',reason:'file-not-found',file:selected,valuesRedacted:true},null,2)); process.exit(1);}
const st=fs.statSync(file); const raw=fs.readFileSync(file); const text=raw.slice(0,Math.min(raw.length,maxReadBytes)).toString('utf8'); const truncated=raw.length>maxReadBytes;
const lines=text.split(/\\r?\\n/).filter(Boolean); const isJsonl=selected.endsWith('.jsonl'); const isJson=selected.endsWith('.json');
const st=fs.statSync(file); const raw=fs.readFileSync(file); const truncated=raw.length>maxReadBytes; const isJsonl=selected.endsWith('.jsonl'); const isJson=selected.endsWith('.json');
const text=(isJsonl?raw.slice(Math.max(0,raw.length-maxReadBytes)):raw.slice(0,Math.min(raw.length,maxReadBytes))).toString('utf8');
const lines=text.split(/\\r?\\n/).filter(Boolean);
if(isJsonl&&truncated&&lines.length>0) lines.shift();
let jsonSummary=null;
if(isJson){try{const parsed=JSON.parse(raw.toString('utf8')); jsonSummary={topLevelKeys:parsed&&typeof parsed==='object'&&!Array.isArray(parsed)?Object.keys(parsed).slice(0,40):[],counts:slimObject(parsed&&parsed.counts),sampleMetrics:slimObject(parsed&&parsed.sampleMetrics),runtimeAlerts:slimObject(parsed&&parsed.runtimeAlerts),pagePerformance:slimObject(parsed&&parsed.pagePerformance),runnerErrors:Array.isArray(parsed&&parsed.runnerErrors)?parsed.runnerErrors.slice(-8).map(slimRunnerError).filter(Boolean):[],findings:Array.isArray(parsed&&parsed.findings)?parsed.findings.slice(0,8).map(slimFinding).filter(Boolean):[]}}catch(error){jsonSummary={parseError:String(error&&error.message||error).slice(0,160)}}}
const jsonlTail=isJsonl?lines.slice(-20).map((line,index)=>{try{return slimJsonl(JSON.parse(line))}catch(error){return {parseError:true,index,lineTail:line.slice(-240),error:String(error&&error.message||error).slice(0,160)}}}):null;