@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.
@@ -1,83 +1,83 @@
1
- // A tester report → ONE zip in the outbox (G9AppDiagnostic.Maui TesterReportSendFlow.BuildArchiveAsync). The archive
2
- // describes itself (the uploader reads report.json back out of it, no sidecar):
3
- //
4
- // report.json the draft (the .NET keys)
5
- // Screenshot/ Recording/ Voice/ File/ what the tester captured
6
- // Diagnostic/timeline-*.json a screen recording's app timeline (paired with the video)
7
- // Diagnostic/context.txt the report header, where it started, and the app's own context
8
- // Diagnostic/logs/… the app's logs (collectLogs)
9
- // DatabaseBackup/… only when the tester opted in (createDatabaseBackup) — opt-in and last
10
- //
11
- // Logs and the backup are bonuses: a failure there never costs the report.
12
- import type { DiagnosticFiles, DiagnosticZipEntry } from '../host.ts';
13
- import { kindFolder, TesterAttachmentKind, type TesterReportDraft } from './model.ts';
14
-
15
- export interface TesterArchiveHooks {
16
- /** The app's own context, appended to context.txt (sync state, servers…). */
17
- readonly contextText?: () => Promise<string>;
18
- /** The app's logs as zip entries (names under `Diagnostic/logs/`). */
19
- readonly collectLogs?: () => Promise<readonly DiagnosticZipEntry[]>;
20
- /** The app's local-store backup when the tester opted in (null: none could be made); `cleanup` after the zip. */
21
- readonly createDatabaseBackup?: () => Promise<{ readonly entries: readonly DiagnosticZipEntry[]; readonly cleanup?: () => Promise<void> } | null>;
22
- }
23
-
24
- export interface TesterArchiveInput {
25
- readonly files: DiagnosticFiles;
26
- readonly draft: TesterReportDraft;
27
- /** The draft's folder (its kind folders are packed). */
28
- readonly reportDir: string;
29
- /** The archive's path in the outbox. */
30
- readonly out: string;
31
- readonly productName: string;
32
- readonly app: { readonly appVersion: string; readonly environment: string; readonly platform: string };
33
- readonly hooks?: TesterArchiveHooks;
34
- }
35
-
36
- /** `tester-report-<id>.zip` (the .NET outbox name). */
37
- export const outboxName = (reportId: string): string => `tester-report-${reportId}.zip`;
38
-
39
- /** The context file's header (.NET WriteContextFileAsync), then where the report started. */
40
- export function testerContextLines(draft: TesterReportDraft, productName: string, app: TesterArchiveInput['app']): string[] {
41
- const title = `${productName} tester report context`;
42
- return [
43
- title,
44
- '='.repeat(title.length),
45
- `ReportId : ${draft.id}`,
46
- `CreatedUtc : ${draft.createdUtc}`,
47
- `AppVersion : ${app.appVersion}`,
48
- `Environment : ${app.environment}`,
49
- `Platform : ${app.platform}`,
50
- `Author : ${draft.username ?? '—'}`,
51
- `Kind : ${draft.kind ?? 'bug'}`,
52
- `Build : ${draft.branch ?? '?'} @ ${draft.commit ?? '?'}`,
53
- `Attachments : ${draft.attachments.length}`,
54
- `DatabaseBackup: ${draft.includeDatabaseBackup ? 'requested' : 'no'}`,
55
- `LocalAI : ${draft.aiPack === false ? 'not wanted' : 'allowed'}`,
56
- ...(draft.screenContext ?? []),
57
- ];
58
- }
59
-
60
- const PACKED = [TesterAttachmentKind.Screenshot, TesterAttachmentKind.Recording, TesterAttachmentKind.Voice, TesterAttachmentKind.File, TesterAttachmentKind.Diagnostic];
61
-
62
- /** Builds the outbox archive; resolves its path. The draft folder is left for the caller to discard. */
63
- export async function buildTesterArchive(input: TesterArchiveInput): Promise<string> {
64
- const { files, draft, hooks } = input;
65
- await files.remove(input.out).catch(() => {});
66
- const appContext = (await hooks?.contextText?.().catch(() => '')) ?? '';
67
- const context = [...testerContextLines(draft, input.productName, input.app), '', appContext].join('\n');
68
- const entries: DiagnosticZipEntry[] = [
69
- { name: 'report.json', text: JSON.stringify(draft, null, 2) },
70
- ...PACKED.map((k) => ({ name: kindFolder(k), path: `${input.reportDir}/${kindFolder(k)}` })),
71
- { name: 'Diagnostic/context.txt', text: context },
72
- ];
73
- const logs = (await hooks?.collectLogs?.().catch(() => [])) ?? [];
74
- entries.push(...logs);
75
- let backup: { readonly entries: readonly DiagnosticZipEntry[]; readonly cleanup?: () => Promise<void> } | null = null;
76
- if (draft.includeDatabaseBackup && hooks?.createDatabaseBackup) backup = await hooks.createDatabaseBackup().catch(() => null);
77
- if (backup) entries.push(...backup.entries);
78
- try {
79
- return (await files.zip(input.out, entries)).path;
80
- } finally {
81
- if (backup?.cleanup) await backup.cleanup().catch(() => {});
82
- }
83
- }
1
+ // A tester report → ONE zip in the outbox (G9AppDiagnostic.Maui TesterReportSendFlow.BuildArchiveAsync). The archive
2
+ // describes itself (the uploader reads report.json back out of it, no sidecar):
3
+ //
4
+ // report.json the draft (the .NET keys)
5
+ // Screenshot/ Recording/ Voice/ File/ what the tester captured
6
+ // Diagnostic/timeline-*.json a screen recording's app timeline (paired with the video)
7
+ // Diagnostic/context.txt the report header, where it started, and the app's own context
8
+ // Diagnostic/logs/… the app's logs (collectLogs)
9
+ // DatabaseBackup/… only when the tester opted in (createDatabaseBackup) — opt-in and last
10
+ //
11
+ // Logs and the backup are bonuses: a failure there never costs the report.
12
+ import type { DiagnosticFiles, DiagnosticZipEntry } from '../host.ts';
13
+ import { kindFolder, TesterAttachmentKind, type TesterReportDraft } from './model.ts';
14
+
15
+ export interface TesterArchiveHooks {
16
+ /** The app's own context, appended to context.txt (sync state, servers…). */
17
+ readonly contextText?: () => Promise<string>;
18
+ /** The app's logs as zip entries (names under `Diagnostic/logs/`). */
19
+ readonly collectLogs?: () => Promise<readonly DiagnosticZipEntry[]>;
20
+ /** The app's local-store backup when the tester opted in (null: none could be made); `cleanup` after the zip. */
21
+ readonly createDatabaseBackup?: () => Promise<{ readonly entries: readonly DiagnosticZipEntry[]; readonly cleanup?: () => Promise<void> } | null>;
22
+ }
23
+
24
+ export interface TesterArchiveInput {
25
+ readonly files: DiagnosticFiles;
26
+ readonly draft: TesterReportDraft;
27
+ /** The draft's folder (its kind folders are packed). */
28
+ readonly reportDir: string;
29
+ /** The archive's path in the outbox. */
30
+ readonly out: string;
31
+ readonly productName: string;
32
+ readonly app: { readonly appVersion: string; readonly environment: string; readonly platform: string };
33
+ readonly hooks?: TesterArchiveHooks;
34
+ }
35
+
36
+ /** `tester-report-<id>.zip` (the .NET outbox name). */
37
+ export const outboxName = (reportId: string): string => `tester-report-${reportId}.zip`;
38
+
39
+ /** The context file's header (.NET WriteContextFileAsync), then where the report started. */
40
+ export function testerContextLines(draft: TesterReportDraft, productName: string, app: TesterArchiveInput['app']): string[] {
41
+ const title = `${productName} tester report context`;
42
+ return [
43
+ title,
44
+ '='.repeat(title.length),
45
+ `ReportId : ${draft.id}`,
46
+ `CreatedUtc : ${draft.createdUtc}`,
47
+ `AppVersion : ${app.appVersion}`,
48
+ `Environment : ${app.environment}`,
49
+ `Platform : ${app.platform}`,
50
+ `Author : ${draft.username ?? '—'}`,
51
+ `Kind : ${draft.kind ?? 'bug'}`,
52
+ `Build : ${draft.branch ?? '?'} @ ${draft.commit ?? '?'}`,
53
+ `Attachments : ${draft.attachments.length}`,
54
+ `DatabaseBackup: ${draft.includeDatabaseBackup ? 'requested' : 'no'}`,
55
+ `LocalAI : ${draft.aiPack === false ? 'not wanted' : 'allowed'}`,
56
+ ...(draft.screenContext ?? []),
57
+ ];
58
+ }
59
+
60
+ const PACKED = [TesterAttachmentKind.Screenshot, TesterAttachmentKind.Recording, TesterAttachmentKind.Voice, TesterAttachmentKind.File, TesterAttachmentKind.Diagnostic];
61
+
62
+ /** Builds the outbox archive; resolves its path. The draft folder is left for the caller to discard. */
63
+ export async function buildTesterArchive(input: TesterArchiveInput): Promise<string> {
64
+ const { files, draft, hooks } = input;
65
+ await files.remove(input.out).catch(() => {});
66
+ const appContext = (await hooks?.contextText?.().catch(() => '')) ?? '';
67
+ const context = [...testerContextLines(draft, input.productName, input.app), '', appContext].join('\n');
68
+ const entries: DiagnosticZipEntry[] = [
69
+ { name: 'report.json', text: JSON.stringify(draft, null, 2) },
70
+ ...PACKED.map((k) => ({ name: kindFolder(k), path: `${input.reportDir}/${kindFolder(k)}` })),
71
+ { name: 'Diagnostic/context.txt', text: context },
72
+ ];
73
+ const logs = (await hooks?.collectLogs?.().catch(() => [])) ?? [];
74
+ entries.push(...logs);
75
+ let backup: { readonly entries: readonly DiagnosticZipEntry[]; readonly cleanup?: () => Promise<void> } | null = null;
76
+ if (draft.includeDatabaseBackup && hooks?.createDatabaseBackup) backup = await hooks.createDatabaseBackup().catch(() => null);
77
+ if (backup) entries.push(...backup.entries);
78
+ try {
79
+ return (await files.zip(input.out, entries)).path;
80
+ } finally {
81
+ if (backup?.cleanup) await backup.cleanup().catch(() => {});
82
+ }
83
+ }
@@ -1,99 +1,99 @@
1
- // The send form's rules (owner, 2026-10-31; G9AppDiagnostic.Maui TesterReportSendFlow + TesterModeOptions): no title
2
- // field and no pre-filled description. The title is the APP's («مشکل در بخش نقشه — …»), worded by the report's kind on
3
- // send («پیشنهاد بهبود در بخش نقشه — …»); the description is the app's block followed by the tester's own words. The
4
- // draft keeps autoTitle / autoDescription so the gateway and the local AI read the tester's words apart from the app's.
5
- import { type DiagStringKey, type DiagTranslate } from '../strings.ts';
6
- import { TesterAttachmentKind, type TesterReportDraft } from './model.ts';
7
- import { captureScreen, contextFileLines, descriptionBlock, suggestedTitle, type TesterScreenDescription, toSnapshot } from './screen.ts';
8
-
9
- /** A kind of report: its key (a contract with the gateway and Didban) and its label's text key. */
10
- export interface TesterReportKind {
11
- readonly key: string;
12
- /** A package text, or the app's own label function. */
13
- readonly label: DiagStringKey | ((t: DiagTranslate) => string);
14
- }
15
-
16
- /** The four kinds, a bug first (TesterReportKind.Defaults). */
17
- export const DEFAULT_REPORT_KINDS: readonly TesterReportKind[] = [
18
- { key: 'bug', label: 'TesterReportKindBug' },
19
- { key: 'feature', label: 'TesterReportKindFeature' },
20
- { key: 'improvement', label: 'TesterReportKindImprovement' },
21
- { key: 'investigation', label: 'TesterReportKindInvestigation' },
22
- ];
23
-
24
- export const kindLabel = (k: TesterReportKind, t: DiagTranslate): string => (typeof k.label === 'function' ? k.label(t) : t(k.label));
25
-
26
- /** When the tester must write words before sending (TesterDescriptionRule). */
27
- export type TesterDescriptionRule = 'optional' | 'required' | 'requiredWithoutMedia';
28
-
29
- /** Whether this report needs the tester's words: `requiredWithoutMedia` = unless it carries a voice note or a recording. */
30
- export function descriptionRequired(draft: TesterReportDraft, rule: TesterDescriptionRule): boolean {
31
- if (rule === 'required') return true;
32
- if (rule === 'requiredWithoutMedia') return !draft.attachments.some((a) => a.kind === TesterAttachmentKind.Voice || a.kind === TesterAttachmentKind.Recording);
33
- return false;
34
- }
35
-
36
- /** The tester's own words in a draft: its description without the app's block (the form shows only these). */
37
- export function testerWords(draft: TesterReportDraft): string {
38
- let text = (draft.description ?? '').replace(/\r\n/g, '\n');
39
- const block = draft.autoDescription?.replace(/\r\n/g, '\n').trim();
40
- if (block) {
41
- const at = text.indexOf(block);
42
- if (at >= 0) text = text.slice(0, at) + text.slice(at + block.length);
43
- }
44
- return text.trim();
45
- }
46
-
47
- /**
48
- * The app's title in the report's kind: «مشکل در بخش نقشه — سایت» → «پیشنهاد بهبود در بخش نقشه — سایت» for an improvement.
49
- * The screen gave the problem form; its section and site are kept, the kind's label replaces «مشکل». A title in no known
50
- * form is left as it is.
51
- */
52
- export function kindTitle(autoTitle: string | null | undefined, kind: string | null | undefined, kinds: readonly TesterReportKind[], t: DiagTranslate): string | null {
53
- if (!autoTitle || !autoTitle.trim()) return autoTitle ?? null;
54
- const chosen = kinds.find((k) => k.key === kind);
55
- if (!chosen) return autoTitle;
56
- const prefix = t('TesterAutoTitleFormat', '');
57
- if (!autoTitle.startsWith(prefix)) return autoTitle;
58
- return t('TesterAutoTitleKindFormat', kindLabel(chosen, t), autoTitle.slice(prefix.length));
59
- }
60
-
61
- /** The app's facts at the moment a report starts (or, for one started by a recording, at send). */
62
- export function screenFacts(describe: ((d: TesterScreenDescription) => void) | undefined, t: DiagTranslate, now: () => number = Date.now) {
63
- const c = captureScreen(describe, now);
64
- const title = suggestedTitle(c, t);
65
- const block = descriptionBlock(c, t);
66
- return { autoTitle: title || null, autoDescription: block || null, screen: toSnapshot(c), screenContext: contextFileLines(c) };
67
- }
68
-
69
- export interface ComposeInput {
70
- readonly kinds: readonly TesterReportKind[];
71
- readonly t: DiagTranslate;
72
- readonly describe?: (d: TesterScreenDescription) => void;
73
- readonly now?: () => number;
74
- }
75
-
76
- /**
77
- * The report's final title and description from what the tester wrote: a report with no app title yet (one started by a
78
- * recording) reads the screen now; the title is worded by the kind; the description is the app's block, then the words.
79
- */
80
- export function compose(draft: TesterReportDraft, words: string, input: ComposeInput): TesterReportDraft {
81
- let next: TesterReportDraft = draft;
82
- if (!next.autoTitle || !next.autoTitle.trim()) {
83
- const facts = screenFacts(input.describe, input.t, input.now);
84
- next = { ...next, autoTitle: facts.autoTitle };
85
- if (!next.autoDescription || !next.autoDescription.trim()) {
86
- next = {
87
- ...next,
88
- autoDescription: facts.autoDescription,
89
- screen: next.screen ?? facts.screen,
90
- screenContext: next.screenContext && next.screenContext.length > 0 ? next.screenContext : facts.screenContext,
91
- };
92
- }
93
- }
94
- const autoTitle = kindTitle(next.autoTitle, next.kind, input.kinds, input.t);
95
- const header = next.autoDescription?.trim() ?? '';
96
- const w = words.trim();
97
- const description = header.length === 0 ? w : w.length === 0 ? header : `${header}\n\n${w}`;
98
- return { ...next, autoTitle, title: autoTitle ?? next.title ?? '', description };
99
- }
1
+ // The send form's rules (owner, 2026-10-31; G9AppDiagnostic.Maui TesterReportSendFlow + TesterModeOptions): no title
2
+ // field and no pre-filled description. The title is the APP's («مشکل در بخش نقشه — …»), worded by the report's kind on
3
+ // send («پیشنهاد بهبود در بخش نقشه — …»); the description is the app's block followed by the tester's own words. The
4
+ // draft keeps autoTitle / autoDescription so the gateway and the local AI read the tester's words apart from the app's.
5
+ import { type DiagStringKey, type DiagTranslate } from '../strings.ts';
6
+ import { TesterAttachmentKind, type TesterReportDraft } from './model.ts';
7
+ import { captureScreen, contextFileLines, descriptionBlock, suggestedTitle, type TesterScreenDescription, toSnapshot } from './screen.ts';
8
+
9
+ /** A kind of report: its key (a contract with the gateway and Didban) and its label's text key. */
10
+ export interface TesterReportKind {
11
+ readonly key: string;
12
+ /** A package text, or the app's own label function. */
13
+ readonly label: DiagStringKey | ((t: DiagTranslate) => string);
14
+ }
15
+
16
+ /** The four kinds, a bug first (TesterReportKind.Defaults). */
17
+ export const DEFAULT_REPORT_KINDS: readonly TesterReportKind[] = [
18
+ { key: 'bug', label: 'TesterReportKindBug' },
19
+ { key: 'feature', label: 'TesterReportKindFeature' },
20
+ { key: 'improvement', label: 'TesterReportKindImprovement' },
21
+ { key: 'investigation', label: 'TesterReportKindInvestigation' },
22
+ ];
23
+
24
+ export const kindLabel = (k: TesterReportKind, t: DiagTranslate): string => (typeof k.label === 'function' ? k.label(t) : t(k.label));
25
+
26
+ /** When the tester must write words before sending (TesterDescriptionRule). */
27
+ export type TesterDescriptionRule = 'optional' | 'required' | 'requiredWithoutMedia';
28
+
29
+ /** Whether this report needs the tester's words: `requiredWithoutMedia` = unless it carries a voice note or a recording. */
30
+ export function descriptionRequired(draft: TesterReportDraft, rule: TesterDescriptionRule): boolean {
31
+ if (rule === 'required') return true;
32
+ if (rule === 'requiredWithoutMedia') return !draft.attachments.some((a) => a.kind === TesterAttachmentKind.Voice || a.kind === TesterAttachmentKind.Recording);
33
+ return false;
34
+ }
35
+
36
+ /** The tester's own words in a draft: its description without the app's block (the form shows only these). */
37
+ export function testerWords(draft: TesterReportDraft): string {
38
+ let text = (draft.description ?? '').replace(/\r\n/g, '\n');
39
+ const block = draft.autoDescription?.replace(/\r\n/g, '\n').trim();
40
+ if (block) {
41
+ const at = text.indexOf(block);
42
+ if (at >= 0) text = text.slice(0, at) + text.slice(at + block.length);
43
+ }
44
+ return text.trim();
45
+ }
46
+
47
+ /**
48
+ * The app's title in the report's kind: «مشکل در بخش نقشه — سایت» → «پیشنهاد بهبود در بخش نقشه — سایت» for an improvement.
49
+ * The screen gave the problem form; its section and site are kept, the kind's label replaces «مشکل». A title in no known
50
+ * form is left as it is.
51
+ */
52
+ export function kindTitle(autoTitle: string | null | undefined, kind: string | null | undefined, kinds: readonly TesterReportKind[], t: DiagTranslate): string | null {
53
+ if (!autoTitle || !autoTitle.trim()) return autoTitle ?? null;
54
+ const chosen = kinds.find((k) => k.key === kind);
55
+ if (!chosen) return autoTitle;
56
+ const prefix = t('TesterAutoTitleFormat', '');
57
+ if (!autoTitle.startsWith(prefix)) return autoTitle;
58
+ return t('TesterAutoTitleKindFormat', kindLabel(chosen, t), autoTitle.slice(prefix.length));
59
+ }
60
+
61
+ /** The app's facts at the moment a report starts (or, for one started by a recording, at send). */
62
+ export function screenFacts(describe: ((d: TesterScreenDescription) => void) | undefined, t: DiagTranslate, now: () => number = Date.now) {
63
+ const c = captureScreen(describe, now);
64
+ const title = suggestedTitle(c, t);
65
+ const block = descriptionBlock(c, t);
66
+ return { autoTitle: title || null, autoDescription: block || null, screen: toSnapshot(c), screenContext: contextFileLines(c) };
67
+ }
68
+
69
+ export interface ComposeInput {
70
+ readonly kinds: readonly TesterReportKind[];
71
+ readonly t: DiagTranslate;
72
+ readonly describe?: (d: TesterScreenDescription) => void;
73
+ readonly now?: () => number;
74
+ }
75
+
76
+ /**
77
+ * The report's final title and description from what the tester wrote: a report with no app title yet (one started by a
78
+ * recording) reads the screen now; the title is worded by the kind; the description is the app's block, then the words.
79
+ */
80
+ export function compose(draft: TesterReportDraft, words: string, input: ComposeInput): TesterReportDraft {
81
+ let next: TesterReportDraft = draft;
82
+ if (!next.autoTitle || !next.autoTitle.trim()) {
83
+ const facts = screenFacts(input.describe, input.t, input.now);
84
+ next = { ...next, autoTitle: facts.autoTitle };
85
+ if (!next.autoDescription || !next.autoDescription.trim()) {
86
+ next = {
87
+ ...next,
88
+ autoDescription: facts.autoDescription,
89
+ screen: next.screen ?? facts.screen,
90
+ screenContext: next.screenContext && next.screenContext.length > 0 ? next.screenContext : facts.screenContext,
91
+ };
92
+ }
93
+ }
94
+ const autoTitle = kindTitle(next.autoTitle, next.kind, input.kinds, input.t);
95
+ const header = next.autoDescription?.trim() ?? '';
96
+ const w = words.trim();
97
+ const description = header.length === 0 ? w : w.length === 0 ? header : `${header}\n\n${w}`;
98
+ return { ...next, autoTitle, title: autoTitle ?? next.title ?? '', description };
99
+ }
@@ -388,6 +388,8 @@ export class TesterEngine {
388
388
  this.timeline.touch(e.x, e.y, e.fingers, this.now());
389
389
  return;
390
390
  }
391
+ // Only a tap or a whole gesture counts: a watcher may report more (a `seq` trace of a touch, 2026-11-15).
392
+ if (e.type !== 'tap' && e.type !== 'gesture') return;
391
393
  const s = this.state$.get();
392
394
  if (!s.enabled) return;
393
395
  const excluded = e.excluded === true;