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 (