From c48d8ac7160c3cdcf32ed4e488807d3daeb8d457 Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Fri, 5 Jun 2026 13:07:23 +0900 Subject: feat(observability): Phase A logging substrate — Logger/Span ABI + journal sink (250 tests) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Structured, agent-first logging captured durably to an append-only journal file. Kernel (contracts/logging.ts): leveled/attributed Logger + Span, auto-scoped per extension (host stamps manifest.id, unspoofable), incremental span records (open/close) for crash-reconstructable traces, injected LogSink (pure record-builder). ctx.log on ToolContract; runTurn opens turn/step/tool-call spans and captures the verbatim pre-mutation prompt (the 'before') on the step span. journal-sink (new package, bootstrap dep — not an extension): LogSink appending NDJSON to a rotating journal; pure serialize + thin fs edge; fail-safe drop, never blocks a turn. host-bin injects it via HostDeps; session-orchestrator threads host.logger (childed per turn) into runTurn. Redaction is per-extension self-redaction (no shared helper — isolation over DRY). The out-of-process collector + SQLite store + the verbatim 'after' provider.request capture are Phase B / next (notes/observability-design.md §10/§11). Verified: tsc -b clean, 250 tests (218→+32), biome clean. Live boot: a turn's journal holds host logs + turn/step spans (open+close) + the prompt:before record with the verbatim messages array. Harness: ORCHESTRATOR §3 rule-scoping map; .dispatch/rules/isolation-over-dry.md; notes/observability-design.md (design D1–D10 + Phase A/B plan). --- packages/host-bin/package.json | 3 ++- packages/host-bin/src/main.ts | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) (limited to 'packages/host-bin') diff --git a/packages/host-bin/package.json b/packages/host-bin/package.json index 12ae633..a3e24c8 100644 --- a/packages/host-bin/package.json +++ b/packages/host-bin/package.json @@ -11,6 +11,7 @@ "@dispatch/provider-openai-compat": "workspace:*", "@dispatch/session-orchestrator": "workspace:*", "@dispatch/transport-http": "workspace:*", - "@dispatch/tool-read-file": "workspace:*" + "@dispatch/tool-read-file": "workspace:*", + "@dispatch/journal-sink": "workspace:*" } } diff --git a/packages/host-bin/src/main.ts b/packages/host-bin/src/main.ts index 0cb0d37..0c795b8 100644 --- a/packages/host-bin/src/main.ts +++ b/packages/host-bin/src/main.ts @@ -2,14 +2,16 @@ import { mkdirSync } from "node:fs"; import { dirname } from "node:path"; import { extension as authApikeyExt } from "@dispatch/auth-apikey"; import { extension as conversationStoreExt } from "@dispatch/conversation-store"; +import { createJournalSink } from "@dispatch/journal-sink"; import { type ConfigAccess, createBus, createHost, + createLogger, type EventsEmitter, type Extension, type HostDeps, - type Logger, + type LogDeps, type PermissionGate, type ScheduledJob, type SecretsAccess, @@ -22,15 +24,6 @@ import { extension as toolReadFileExt } from "@dispatch/tool-read-file"; import { createServer, extension as transportHttpExt } from "@dispatch/transport-http"; import { configMapToAccess, envToConfigMap } from "./config.js"; -function createConsoleLogger(): Logger { - return { - debug: (message: string, ...args: unknown[]) => console.debug(`[debug] ${message}`, ...args), - info: (message: string, ...args: unknown[]) => console.info(`[info] ${message}`, ...args), - warn: (message: string, ...args: unknown[]) => console.warn(`[warn] ${message}`, ...args), - error: (message: string, ...args: unknown[]) => console.error(`[error] ${message}`, ...args), - }; -} - function createEmptySecrets(): SecretsAccess { return { get: async () => null, @@ -64,7 +57,11 @@ const CORE_EXTENSIONS: readonly Extension[] = [ ]; async function boot(): Promise { - const logger = createConsoleLogger(); + const journalPath = process.env.DISPATCH_JOURNAL ?? "./.dispatch/journal/app.ndjson"; + mkdirSync(dirname(journalPath), { recursive: true }); + const logSink = createJournalSink({ path: journalPath }); + const logDeps: LogDeps = { now: () => Date.now(), newId: () => crypto.randomUUID() }; + const logger = createLogger({ extensionId: "host-bin" }, logSink, logDeps); const dbPath = process.env.DISPATCH_DB ?? "./.dispatch-data/dispatch.db"; mkdirSync(dirname(dbPath), { recursive: true }); @@ -83,6 +80,8 @@ async function boot(): Promise { scheduler: createNoopScheduler(), bus: createBus(logger), events: createNoopEvents(), + logSink, + logDeps, }; const host = createHost(CORE_EXTENSIONS, deps); @@ -102,6 +101,7 @@ async function boot(): Promise { const port = Number(process.env.BACKEND_PORT) || Number(process.env.PORT) || 24203; const server = Bun.serve({ fetch: app.fetch, port }); logger.info(`Dispatch listening on http://localhost:${server.port}`); + console.info(`Dispatch listening on http://localhost:${server.port}`); } boot().catch((err) => { -- cgit v1.2.3