@g9tm/app-diagnostic 0.2.0 → 0.2.2
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/package.json +20 -12
- package/src/bytes.ts +48 -48
- package/src/host.ts +124 -124
- package/src/index.ts +30 -30
- package/src/live/bundle.ts +77 -77
- package/src/live/channel.ts +496 -496
- package/src/live/handlers.ts +426 -426
- package/src/live/models.ts +366 -360
- package/src/live/upload.ts +175 -175
- package/src/recording.ts +176 -176
- package/src/store.ts +39 -39
- package/src/strings.generated.ts +242 -242
- package/src/strings.ts +37 -37
- package/src/tester/archive.ts +83 -83
- package/src/tester/compose.ts +99 -99
- package/src/tester/engine.ts +2 -0
- package/src/tester/feed.ts +182 -182
- package/src/tester/gesture.ts +61 -61
- package/src/tester/model.ts +125 -125
- package/src/tester/outbox.ts +131 -131
- package/src/tester/screen.ts +117 -117
- package/src/tester/store.ts +145 -145
- package/src/tester/timeline.ts +98 -98
- package/src/upload.ts +236 -236
- package/src/wire.ts +133 -133
package/src/tester/timeline.ts
CHANGED
|
@@ -1,98 +1,98 @@
|
|
|
1
|
-
// The app's own account of a screen recording (G9AppDiagnostic.Maui TesterTimelineRecorder): every log line the app
|
|
2
|
-
// wrote and every finger that landed, each with its offset in seconds from the recording's start, written beside the
|
|
3
|
-
// video as `timeline-*.json` and attached `pairedWith` the video. The lab's local AI takes a frame exactly where something
|
|
4
|
-
// HAPPENED, and an agent reads «0:42 tapped, 0:43 sync failed». Cheap: it listens to the app's log, appends to a bounded
|
|
5
|
-
// list and writes once at the end. The JSON is the .NET one, key for key.
|
|
6
|
-
import type { Unsubscribe } from '../host.ts';
|
|
7
|
-
|
|
8
|
-
/** One line of the app's log, as the timeline keeps it. */
|
|
9
|
-
export interface TesterLogLine {
|
|
10
|
-
readonly timeMs: number;
|
|
11
|
-
/** trace | debug | info | warn | error | critical (written as the .NET names), or a .NET name already. */
|
|
12
|
-
readonly level: string;
|
|
13
|
-
readonly category: string;
|
|
14
|
-
readonly message: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export type SubscribeLog = (listener: (line: TesterLogLine) => void) => Unsubscribe;
|
|
18
|
-
|
|
19
|
-
/** Hard cap — a 10-minute recording of a busy screen stays a few hundred kilobytes. */
|
|
20
|
-
const MAX_EVENTS = 4000;
|
|
21
|
-
const MAX_MESSAGE = 400;
|
|
22
|
-
|
|
23
|
-
export interface TimelineEvent {
|
|
24
|
-
readonly t: number;
|
|
25
|
-
readonly kind: 'log' | 'touch';
|
|
26
|
-
readonly level?: string;
|
|
27
|
-
readonly source?: string;
|
|
28
|
-
readonly text?: string;
|
|
29
|
-
readonly x?: number;
|
|
30
|
-
readonly y?: number;
|
|
31
|
-
readonly fingers?: number;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** The .NET LogLevel names (the gateway, the live console and the timeline all read these). */
|
|
35
|
-
export const LOG_LEVEL_NAMES: Readonly<Record<string, string>> = { trace: 'Trace', debug: 'Debug', info: 'Information', warn: 'Warning', error: 'Error', critical: 'Critical' };
|
|
36
|
-
|
|
37
|
-
export const levelName = (level: string): string => LOG_LEVEL_NAMES[level] ?? level;
|
|
38
|
-
|
|
39
|
-
export class TesterTimeline {
|
|
40
|
-
private events: TimelineEvent[] = [];
|
|
41
|
-
private startedMs = 0;
|
|
42
|
-
private running = false;
|
|
43
|
-
private off: Unsubscribe | null = null;
|
|
44
|
-
|
|
45
|
-
get isRunning(): boolean {
|
|
46
|
-
return this.running;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
start(startedMs: number, subscribe: SubscribeLog | null | undefined): void {
|
|
50
|
-
if (this.running) return;
|
|
51
|
-
this.events = [];
|
|
52
|
-
this.startedMs = startedMs;
|
|
53
|
-
this.running = true;
|
|
54
|
-
this.off =
|
|
55
|
-
subscribe?.((e) => {
|
|
56
|
-
const text = e.message.length > MAX_MESSAGE ? `${e.message.slice(0, MAX_MESSAGE)}…` : e.message;
|
|
57
|
-
this.push({ t: this.offset(e.timeMs), kind: 'log', level: levelName(e.level), source: e.category, text });
|
|
58
|
-
}) ?? null;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/** A finger landing, as fractions of the window (0..1). */
|
|
62
|
-
touch(x: number, y: number, fingers: number, atMs: number = Date.now()): void {
|
|
63
|
-
if (!this.running) return;
|
|
64
|
-
this.push({ t: this.offset(atMs), kind: 'touch', x: round(x, 3), y: round(y, 3), fingers });
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/** Stops listening and answers the file's JSON, or null when nothing happened. */
|
|
68
|
-
stop(): string | null {
|
|
69
|
-
if (!this.running) return null;
|
|
70
|
-
this.running = false;
|
|
71
|
-
this.off?.();
|
|
72
|
-
this.off = null;
|
|
73
|
-
if (this.events.length === 0) return null;
|
|
74
|
-
const events = this.events.slice().sort((a, b) => a.t - b.t);
|
|
75
|
-
this.events = [];
|
|
76
|
-
return JSON.stringify({ startedUtc: new Date(this.startedMs).toISOString(), events });
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
private push(event: TimelineEvent): void {
|
|
80
|
-
if (this.events.length < MAX_EVENTS) this.events.push(event);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
private offset(ms: number): number {
|
|
84
|
-
return round(Math.max(0, (ms - this.startedMs) / 1000), 2);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function round(v: number, digits: number): number {
|
|
89
|
-
const k = 10 ** digits;
|
|
90
|
-
return Math.round(v * k) / k;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/** `timeline-20261023-141502.json` (the .NET name, UTC). */
|
|
94
|
-
export function timelineFileName(startedMs: number): string {
|
|
95
|
-
const d = new Date(startedMs);
|
|
96
|
-
const p = (n: number) => String(n).padStart(2, '0');
|
|
97
|
-
return `timeline-${d.getUTCFullYear()}${p(d.getUTCMonth() + 1)}${p(d.getUTCDate())}-${p(d.getUTCHours())}${p(d.getUTCMinutes())}${p(d.getUTCSeconds())}.json`;
|
|
98
|
-
}
|
|
1
|
+
// The app's own account of a screen recording (G9AppDiagnostic.Maui TesterTimelineRecorder): every log line the app
|
|
2
|
+
// wrote and every finger that landed, each with its offset in seconds from the recording's start, written beside the
|
|
3
|
+
// video as `timeline-*.json` and attached `pairedWith` the video. The lab's local AI takes a frame exactly where something
|
|
4
|
+
// HAPPENED, and an agent reads «0:42 tapped, 0:43 sync failed». Cheap: it listens to the app's log, appends to a bounded
|
|
5
|
+
// list and writes once at the end. The JSON is the .NET one, key for key.
|
|
6
|
+
import type { Unsubscribe } from '../host.ts';
|
|
7
|
+
|
|
8
|
+
/** One line of the app's log, as the timeline keeps it. */
|
|
9
|
+
export interface TesterLogLine {
|
|
10
|
+
readonly timeMs: number;
|
|
11
|
+
/** trace | debug | info | warn | error | critical (written as the .NET names), or a .NET name already. */
|
|
12
|
+
readonly level: string;
|
|
13
|
+
readonly category: string;
|
|
14
|
+
readonly message: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type SubscribeLog = (listener: (line: TesterLogLine) => void) => Unsubscribe;
|
|
18
|
+
|
|
19
|
+
/** Hard cap — a 10-minute recording of a busy screen stays a few hundred kilobytes. */
|
|
20
|
+
const MAX_EVENTS = 4000;
|
|
21
|
+
const MAX_MESSAGE = 400;
|
|
22
|
+
|
|
23
|
+
export interface TimelineEvent {
|
|
24
|
+
readonly t: number;
|
|
25
|
+
readonly kind: 'log' | 'touch';
|
|
26
|
+
readonly level?: string;
|
|
27
|
+
readonly source?: string;
|
|
28
|
+
readonly text?: string;
|
|
29
|
+
readonly x?: number;
|
|
30
|
+
readonly y?: number;
|
|
31
|
+
readonly fingers?: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The .NET LogLevel names (the gateway, the live console and the timeline all read these). */
|
|
35
|
+
export const LOG_LEVEL_NAMES: Readonly<Record<string, string>> = { trace: 'Trace', debug: 'Debug', info: 'Information', warn: 'Warning', error: 'Error', critical: 'Critical' };
|
|
36
|
+
|
|
37
|
+
export const levelName = (level: string): string => LOG_LEVEL_NAMES[level] ?? level;
|
|
38
|
+
|
|
39
|
+
export class TesterTimeline {
|
|
40
|
+
private events: TimelineEvent[] = [];
|
|
41
|
+
private startedMs = 0;
|
|
42
|
+
private running = false;
|
|
43
|
+
private off: Unsubscribe | null = null;
|
|
44
|
+
|
|
45
|
+
get isRunning(): boolean {
|
|
46
|
+
return this.running;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
start(startedMs: number, subscribe: SubscribeLog | null | undefined): void {
|
|
50
|
+
if (this.running) return;
|
|
51
|
+
this.events = [];
|
|
52
|
+
this.startedMs = startedMs;
|
|
53
|
+
this.running = true;
|
|
54
|
+
this.off =
|
|
55
|
+
subscribe?.((e) => {
|
|
56
|
+
const text = e.message.length > MAX_MESSAGE ? `${e.message.slice(0, MAX_MESSAGE)}…` : e.message;
|
|
57
|
+
this.push({ t: this.offset(e.timeMs), kind: 'log', level: levelName(e.level), source: e.category, text });
|
|
58
|
+
}) ?? null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** A finger landing, as fractions of the window (0..1). */
|
|
62
|
+
touch(x: number, y: number, fingers: number, atMs: number = Date.now()): void {
|
|
63
|
+
if (!this.running) return;
|
|
64
|
+
this.push({ t: this.offset(atMs), kind: 'touch', x: round(x, 3), y: round(y, 3), fingers });
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Stops listening and answers the file's JSON, or null when nothing happened. */
|
|
68
|
+
stop(): string | null {
|
|
69
|
+
if (!this.running) return null;
|
|
70
|
+
this.running = false;
|
|
71
|
+
this.off?.();
|
|
72
|
+
this.off = null;
|
|
73
|
+
if (this.events.length === 0) return null;
|
|
74
|
+
const events = this.events.slice().sort((a, b) => a.t - b.t);
|
|
75
|
+
this.events = [];
|
|
76
|
+
return JSON.stringify({ startedUtc: new Date(this.startedMs).toISOString(), events });
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
private push(event: TimelineEvent): void {
|
|
80
|
+
if (this.events.length < MAX_EVENTS) this.events.push(event);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
private offset(ms: number): number {
|
|
84
|
+
return round(Math.max(0, (ms - this.startedMs) / 1000), 2);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function round(v: number, digits: number): number {
|
|
89
|
+
const k = 10 ** digits;
|
|
90
|
+
return Math.round(v * k) / k;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** `timeline-20261023-141502.json` (the .NET name, UTC). */
|
|
94
|
+
export function timelineFileName(startedMs: number): string {
|
|
95
|
+
const d = new Date(startedMs);
|
|
96
|
+
const p = (n: number) => String(n).padStart(2, '0');
|
|
97
|
+
return `timeline-${d.getUTCFullYear()}${p(d.getUTCMonth() + 1)}${p(d.getUTCDate())}-${p(d.getUTCHours())}${p(d.getUTCMinutes())}${p(d.getUTCSeconds())}.json`;
|
|
98
|
+
}
|