From 70de7afa3c3efdd8954f0c846c02eeaadbcade77 Mon Sep 17 00:00:00 2001 From: Sylvain Duchesne Date: Tue, 14 Jul 2026 10:37:46 +0200 Subject: [PATCH] =?UTF-8?q?feat(logs):=20logs=20donn=C3=A9es=20restructur?= =?UTF-8?q?=C3=A9s=20=E2=80=94=20identit=C3=A9=20en=20pr=C3=A9fixe,=20trac?= =?UTF-8?q?e=20r=C3=A9solution/barri=C3=A8re,=20inspection=20outbox?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Chemin données bas-niveau du polyfill rendu lisible pour diagnostiquer en session live : - Format identité-en-premier : `[][polyfill] OP shortNuri (label)` ; console.error épars (store-registry, inbox) unifiés au même préfixe. - Trace (derrière le flag debug) : issue de la barrière ensureRepoOpen (synced|timed-out + durée) et résultat sémantique de chaque étage de résolution (resolvePointer/canonicalDoc/resolveAccount/resolveShimDoc/readScopeIndex). - outbox-log.ts (nouveau) : inspection read-only de l'outbox hors-ligne au démarrage de session ; console.warn si non vide (anomalie, toujours visible), sous flag si vide. Le comptage seul est fiable (payloads BARE opaques côté JS). Pas de changement fonctionnel. bun test 126 pass ; tsc 0 erreur. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_014GbGgNEHRejVKoREvFuDFg --- packages/client/src/access-log.ts | 44 +++++++++-- packages/client/src/inbox.ts | 3 +- packages/client/src/open-repo.ts | 8 ++ packages/client/src/outbox-log.ts | 98 +++++++++++++++++++++++++ packages/client/src/polyfill.ts | 21 +++++- packages/client/src/store-registry.ts | 39 +++++++--- packages/client/test/access-log.test.ts | 27 +++---- 7 files changed, 207 insertions(+), 33 deletions(-) create mode 100644 packages/client/src/outbox-log.ts diff --git a/packages/client/src/access-log.ts b/packages/client/src/access-log.ts index c761e92..b7434ed 100644 --- a/packages/client/src/access-log.ts +++ b/packages/client/src/access-log.ts @@ -56,11 +56,39 @@ export function enabled(): boolean { * (`getCurrentUser`) — the account/space the operation is scoped under, which is * the discriminating signal for the isolation leak. NOT the physical wallet id * (shared, constant → useless). `(none)` when no identity is set yet (startup). + * Exported so every other polyfill-layer log site (store-registry, inbox, + * outbox-log, …) shares the exact same identity resolution as the access log, + * instead of re-deriving it — see {@link accessLogPrefix}. */ -function activeIdentity(): string { +export function activeIdentity(): string { return getCurrentUser() ?? "(none)"; } +/** + * The common line prefix for every polyfill-layer low-level-data-path log: + * `[][polyfill]` — identity FIRST (the discriminating scan signal), + * `[polyfill]` glued right after with no space between the two brackets. Used by + * {@link logAccess} itself, by the unified `console.error`s in store-registry.ts / + * inbox.ts, and by the BARRIER / stage-resolution / OUTBOX lines (open-repo.ts, + * store-registry.ts, outbox-log.ts) — one single prefix builder so every polyfill + * log line is visually groupable by identity when scanning a live session. + */ +export function accessLogPrefix(): string { + return "[" + activeIdentity() + "][polyfill]"; +} + +/** + * Emit one CONCISE diagnostic line — ONLY when {@link enabled} — prefixed by + * {@link accessLogPrefix}. Used for the precise data-path trace (BARRIER + * resolution, per-stage resolution outcome, the empty-OUTBOX line): a single + * line per stage/event, never a dump. Callers pass the fully-composed suffix + * (e.g. `"BARRIER " + shortNuri(nuri) + " synced (842ms)"`). + */ +export function logStage(line: string): void { + if (!enabled()) return; + console.log(accessLogPrefix() + " " + line); +} + /** * Shorten a NURI for the access log: the full form (`did:ng:o::v:<...>`, * ~100 chars) is too verbose to scan. Drop the `did:ng:o:` prefix and the `:v:<...>` @@ -77,11 +105,13 @@ export function shortNuri(nuri: string): string { /** * Log one document access — but ONLY when {@link enabled}. Off → returns * immediately, prints nothing. Format: - * `[polyfill] [] READ (