@aaac/observability 0.1.17 → 0.2.0
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/README.md +1 -1
- package/dist/{chunk-3DXZNA3E.js → chunk-4PNXLHYZ.js} +125 -35
- package/dist/chunk-4PNXLHYZ.js.map +1 -0
- package/dist/{chunk-EKFRH7PX.js → chunk-D4ZWC5FU.js} +2 -2
- package/dist/cli/global-record.d.ts +1 -1
- package/dist/cli/global-record.js +2 -2
- package/dist/cli/global-record.js.map +1 -1
- package/dist/cli/index.js +17 -11
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +27 -6
- package/dist/index.js +1 -1
- package/package.json +2 -1
- package/dist/chunk-3DXZNA3E.js.map +0 -1
- /package/dist/{chunk-EKFRH7PX.js.map → chunk-D4ZWC5FU.js.map} +0 -0
package/dist/cli/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/cli/index.ts","../../src/generated/program.ts","../../src/generated/contract.ts","../../src/cli/record.ts","../../src/cli/query.ts","../../src/cli/backfill.ts","../../src/cli/ingest-vendor-otel.ts","../../src/cli/report.ts","../../src/cli/handlers.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * aaac-observ CLI entry point.\n *\n * Reads the version from package.json, creates the generated Commander\n * program with hand-written handlers, and executes it.\n */\nimport { readFileSync } from \"node:fs\";\nimport { dirname, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { createProgram } from \"../generated/program.js\";\nimport { handlers } from \"./handlers.js\";\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\nconst pkg = JSON.parse(\n readFileSync(resolve(__dirname, \"../../package.json\"), \"utf8\"),\n) as { version: string };\n\nconst program = createProgram(handlers, pkg.version);\nawait program.parseAsync();\n","// Auto-generated by cli-contracts. Do not edit.\nimport { Command } from \"commander\";\nimport { CONTRACT_YAML, CONTRACT_JSON_STR } from \"./contract.js\";\n\nexport interface CommandHandlers {\n record: (options: { eventType?: string; lifecycle?: string; spanId?: string; parentSpanId?: string; sessionId?: string; traceId?: string; source?: string; attr?: string; link?: string; db?: string }, parentOpts: Record<string, unknown>) => Promise<void>;\n recordHook: (hookName: string | undefined, options: { mappingConfig?: string; db?: string }, parentOpts: Record<string, unknown>) => Promise<void>;\n backfill: (options: { db?: string; endpoint?: string; serviceName?: string; from?: string; to?: string; eventType?: string; dryRun?: boolean; flushTimeoutMs?: string }, parentOpts: Record<string, unknown>) => Promise<void>;\n ingestVendorOtel: (options: { db?: string; input?: string; source?: string; dryRun?: boolean }, parentOpts: Record<string, unknown>) => Promise<void>;\n query: (options: { kind?: string; issue?: string; traceId?: string; spanId?: string; eventType?: string; taskId?: string; from?: string; to?: string; direction?: string; db?: string }, parentOpts: Record<string, unknown>) => Promise<void>;\n report: (options: { projectId?: string; from?: string; to?: string; baselineFrom?: string; baselineTo?: string; format?: string; db?: string }, parentOpts: Record<string, unknown>) => Promise<void>;\n}\n\nexport function createProgram(\n handlers: CommandHandlers,\n version: string,\n): Command {\n const program = new Command();\n program\n .name(\"aaac-observ\")\n .version(version, \"-V, --version\")\n .description(\"aaac-observ — register external events and query the observability store\");\n\n\n program\n .command(\"record\")\n .description(\"Register an external event into the observability pipeline (thin entrypoint for EventCollector.registerExternalEvent)\")\n .option(\"-t, --event-type <value>\", \"Event type (e.g. promotion.commit, process.edit, agent.session)\")\n .option(\"-l, --lifecycle <value>\", \"Event lifecycle phase: open | close | event | instant\")\n .option(\"-s, --span-id <value>\", \"Span ID (auto-generated if omitted)\")\n .option(\"--parent-span-id <value>\", \"Parent span ID for hierarchy\")\n .option(\"--session-id <value>\", \"Session ID to associate with the event\")\n .option(\"--trace-id <value>\", \"Trace ID for distributed tracing\")\n .option(\"--source <value>\", \"Event source identifier (default: external)\")\n .option(\"--attr <value>\", \"Attribute as key=value (repeatable, e.g. --attr git.commit=abc123)\")\n .option(\"--link <value>\", \"Cross-axis link as targetSpanId:linkType[:targetTraceId] (repeatable)\")\n .option(\"--db <value>\", \"Path to observability SQLite database (overrides default)\")\n .action(async (opts, cmd) => {\n await handlers.record(opts, cmd.optsWithGlobals());\n });\n\n program\n .command(\"record-hook\")\n .description(\"Record a Cursor/git hook event — parses stdin JSON, resolves event_mapping into 3-axis spans/links, injects session_id, and emits human-events (fail-open)\")\n .argument(\"<hook-name>\", \"Cursor/git hook name (e.g. afterFileEdit, subagentStart, beforeShellExecution)\")\n .option(\"--mapping-config <value>\", \"Path to event-mapping.json (default: .agent-logs/config/event-mapping.json)\")\n .option(\"--db <value>\", \"Path to observability SQLite database (overrides default)\")\n .action(async (hookName, opts, cmd) => {\n await handlers.recordHook(hookName, opts, cmd.optsWithGlobals());\n });\n\n program\n .command(\"backfill\")\n .description(\"Re-emit historical spans from SQLite to an OTLP backend\")\n .option(\"--db <value>\", \"Path to observability SQLite database (overrides default)\")\n .option(\"--endpoint <value>\", \"OTLP HTTP endpoint URL (fallback: OTEL_EXPORTER_OTLP_ENDPOINT)\")\n .option(\"--service-name <value>\", \"OTEL service name reported to backend (default: @aaac/observability)\")\n .option(\"--from <value>\", \"Backfill spans starting at or after this ISO 8601 time\")\n .option(\"--to <value>\", \"Backfill spans starting at or before this ISO 8601 time\")\n .option(\"--event-type <value>\", \"Filter by event type (e.g. agent.session)\")\n .option(\"--dry-run\", \"Print span count without emitting to OTLP backend\")\n .option(\"--flush-timeout-ms <value>\", \"Maximum ms to wait for OTLP flush before exit (default: 2000; use ≥30000 for >5k spans)\")\n .action(async (opts, cmd) => {\n await handlers.backfill(opts, cmd.optsWithGlobals());\n });\n\n program\n .command(\"ingest-vendor-otel\")\n .description(\"Project a vendor OTLP/JSON trace export (e.g. Claude Code token/cost/trace) into the SQLite Ledger\")\n .option(\"--db <value>\", \"Path to observability SQLite database (overrides default)\")\n .option(\"-i, --input <value>\", \"Path to the OTLP/JSON trace export (reads stdin when omitted)\")\n .option(\"--source <value>\", \"Source tag for projected events (default: claude-code-otel)\")\n .option(\"--dry-run\", \"Parse and project without writing to the Ledger\")\n .action(async (opts, cmd) => {\n await handlers.ingestVendorOtel(opts, cmd.optsWithGlobals());\n });\n\n program\n .command(\"query\")\n .description(\"Query the observability store via QueryAdapter\")\n .option(\"-k, --kind <value>\", \"Query kind: trace | span | search | links | issue\")\n .option(\"--issue <value>\", \"Issue ID for issue queries (--kind issue)\")\n .option(\"--trace-id <value>\", \"Trace ID for trace queries (--kind trace)\")\n .option(\"-s, --span-id <value>\", \"Span ID for span/links queries (--kind span or --kind links)\")\n .option(\"--event-type <value>\", \"Event type filter for search queries (--kind search)\")\n .option(\"--task-id <value>\", \"Task ID filter for search queries (--kind search)\")\n .option(\"--from <value>\", \"Start time in ISO 8601 format for search queries (--kind search)\")\n .option(\"--to <value>\", \"End time in ISO 8601 format for search queries (--kind search)\")\n .option(\"-d, --direction <value>\", \"Link traversal direction for links queries (default: both)\")\n .option(\"--db <value>\", \"Path to observability SQLite database (overrides default)\")\n .action(async (opts, cmd) => {\n await handlers.query(opts, cmd.optsWithGlobals());\n });\n\n program\n .command(\"report\")\n .description(\"Generate an Observability diagnostic report (Layer 1-3 + link completion + Person Tier) from the SQLite Ledger\")\n .option(\"-p, --project-id <value>\", \"Restrict the report to a single project_id (project.id attr / service.name)\")\n .option(\"--from <value>\", \"Start time (ISO 8601) for the current/after window\")\n .option(\"--to <value>\", \"End time (ISO 8601) for the current/after window\")\n .option(\"--baseline-from <value>\", \"Start time (ISO 8601) of the baseline/before window (enables Before/After comparison)\")\n .option(\"--baseline-to <value>\", \"End time (ISO 8601) of the baseline/before window (enables Before/After comparison)\")\n .option(\"-f, --format <value>\", \"Output format: markdown (default) | json\")\n .option(\"--db <value>\", \"Path to observability SQLite database (overrides default)\")\n .action(async (opts, cmd) => {\n await handlers.report(opts, cmd.optsWithGlobals());\n });\n\n\n // Built-in extract command (auto-injected by cli-contracts)\n program\n .command(\"extract\")\n .description(\"Extract contract specification for this CLI tool.\")\n .argument(\"[commands...]\", \"Command IDs to extract. Use dot notation.\")\n .option(\"-a, --all\", \"Extract all commands.\", false)\n .option(\"--include-meta\", \"Include extraction metadata.\", true)\n .option(\"-F, --format <format>\", \"Output format (yaml or json).\", \"yaml\")\n .action(async (commands: string[], opts: { all?: boolean; includeMeta?: boolean; format?: string }, cmd: Command) => {\n if (commands.length === 0 && !opts.all) {\n process.stderr.write(JSON.stringify({ code: \"INVALID_ARGS\", message: \"Specify command IDs or use --all\" }) + \"\\n\");\n process.exit(2);\n }\n\n const format = opts.format || \"yaml\";\n const doc = JSON.parse(CONTRACT_JSON_STR);\n const cmdIds = opts.all ? [] : commands;\n\n if (cmdIds.length === 0) {\n // --all: output full contract\n if (format === \"json\") {\n const out: Record<string, unknown> = {};\n if (opts.includeMeta) {\n out._meta = {\n source: \"embedded\",\n type: \"cli-contracts/extract\",\n extractedAt: new Date().toISOString(),\n specVersion: doc.cli_contracts ?? \"0.1.0\",\n commands: [\"aaac-observ.record\",\"aaac-observ.record-hook\",\"aaac-observ.backfill\",\"aaac-observ.ingest-vendor-otel\",\"aaac-observ.query\",\"aaac-observ.report\"],\n };\n }\n Object.assign(out, doc);\n process.stdout.write(JSON.stringify(out, null, 2) + \"\\n\");\n } else {\n // YAML output\n const yamlLines: string[] = [];\n yamlLines.push(\"# aaac-observ extract\");\n yamlLines.push(\"# source: embedded\");\n yamlLines.push(\"# type: cli-contracts/command-extract\");\n if (opts.includeMeta) {\n yamlLines.push(\"---\");\n yamlLines.push(\"source: embedded\");\n yamlLines.push(\"type: cli-contracts/command-extract\");\n yamlLines.push(\"extractedAt: \" + new Date().toISOString());\n yamlLines.push(\"spec_version: \" + (doc.cli_contracts ?? \"0.1.0\"));\n yamlLines.push(\"commands:\");\n for (const id of [\"aaac-observ.record\",\"aaac-observ.record-hook\",\"aaac-observ.backfill\",\"aaac-observ.ingest-vendor-otel\",\"aaac-observ.query\",\"aaac-observ.report\"]) {\n yamlLines.push(\" - \" + id);\n }\n }\n yamlLines.push(\"---\");\n yamlLines.push(CONTRACT_YAML);\n process.stdout.write(yamlLines.join(\"\\n\") + \"\\n\");\n }\n } else {\n // Filter specific commands\n const filtered: Record<string, unknown> = {\n cli_contracts: doc.cli_contracts,\n info: doc.info,\n command_sets: {},\n };\n const fcs = filtered.command_sets as Record<string, Record<string, unknown>>;\n for (const [setId, cs] of Object.entries(doc.command_sets ?? {})) {\n const cmds = (cs as Record<string, unknown>).commands as Record<string, unknown> | undefined;\n if (!cmds) continue;\n const matched: Record<string, unknown> = {};\n for (const [cmdId, cmdDef] of Object.entries(cmds)) {\n const fullId = setId + \".\" + cmdId;\n if (cmdIds.some((id) => id === cmdId || id === fullId || cmdId.startsWith(id + \".\"))) {\n matched[cmdId] = cmdDef;\n }\n }\n if (Object.keys(matched).length > 0) {\n const setCopy = { ...(cs as Record<string, unknown>) };\n setCopy.commands = matched;\n fcs[setId] = setCopy;\n }\n }\n if (doc.components) filtered.components = doc.components;\n process.stdout.write(JSON.stringify(filtered, null, 2) + \"\\n\");\n }\n process.exit(0);\n });\n return program;\n}\n","// Auto-generated by cli-contracts. Do not edit.\n// Embedded contract for the extract subcommand.\n\nexport const CONTRACT_YAML: string = \"# yaml-language-server: $schema=./node_modules/cli-contracts/schemas/cli-contract.schema.json\\ncli_contracts: 0.1.0\\n\\ninfo:\\n title: AaaC Observability CLI\\n version: 0.1.0\\n description: aaac-observ — external event registration and query for @aaac/observability\\n\\ncommand_sets:\\n aaac-observ:\\n summary: aaac-observ — register external events and query the observability store\\n executable: aaac-observ\\n commands:\\n record:\\n summary: Register an external event into the observability pipeline (thin entrypoint for EventCollector.registerExternalEvent)\\n options:\\n - name: event-type\\n aliases: [t]\\n schema: { type: string }\\n description: \\\"Event type (e.g. promotion.commit, process.edit, agent.session)\\\"\\n - name: lifecycle\\n aliases: [l]\\n schema:\\n type: string\\n enum: [open, close, event, instant]\\n description: \\\"Event lifecycle phase: open | close | event | instant\\\"\\n - name: span-id\\n aliases: [s]\\n schema: { type: string }\\n description: Span ID (auto-generated if omitted)\\n - name: parent-span-id\\n schema: { type: string }\\n description: Parent span ID for hierarchy\\n - name: session-id\\n schema: { type: string }\\n description: Session ID to associate with the event\\n - name: trace-id\\n schema: { type: string }\\n description: Trace ID for distributed tracing\\n - name: source\\n schema: { type: string }\\n description: \\\"Event source identifier (default: external)\\\"\\n - name: attr\\n schema:\\n type: array\\n items: { type: string }\\n description: \\\"Attribute as key=value (repeatable, e.g. --attr git.commit=abc123)\\\"\\n - name: link\\n schema:\\n type: array\\n items: { type: string }\\n description: \\\"Cross-axis link as targetSpanId:linkType[:targetTraceId] (repeatable)\\\"\\n - name: db\\n schema: { type: string }\\n description: Path to observability SQLite database (overrides default)\\n exits:\\n '0':\\n description: Event registered successfully\\n stdout:\\n format: json\\n schema:\\n type: object\\n properties:\\n eventId:\\n type: string\\n spanId:\\n type: string\\n '1':\\n description: Registration failed (validation error or write error)\\n stderr:\\n format: text\\n\\n record-hook:\\n summary: Record a Cursor/git hook event — parses stdin JSON, resolves event_mapping into 3-axis spans/links, injects session_id, and emits human-events (fail-open)\\n arguments:\\n - name: hook-name\\n index: 0\\n required: true\\n schema: { type: string }\\n description: \\\"Cursor/git hook name (e.g. afterFileEdit, subagentStart, beforeShellExecution)\\\"\\n options:\\n - name: mapping-config\\n schema: { type: string }\\n description: \\\"Path to event-mapping.json (default: .agent-logs/config/event-mapping.json)\\\"\\n - name: db\\n schema: { type: string }\\n description: Path to observability SQLite database (overrides default)\\n exits:\\n '0':\\n description: Hook recorded (or no-op when stdin/mapping unavailable) — always fail-open\\n stdout:\\n format: json\\n schema:\\n type: object\\n properties:\\n recorded:\\n type: integer\\n fallback:\\n type: boolean\\n\\n backfill:\\n summary: Re-emit historical spans from SQLite to an OTLP backend\\n description: |\\n Reads closed/instant spans from the local SQLite database and emits them\\n via OtelEmitter to an OTLP-compatible backend.\\n\\n IMPORTANT — idempotency: The OTel SDK does not support specifying custom\\n spanIds, so each backfill invocation creates NEW spans in the backend.\\n Repeated invocations will produce DUPLICATE data. Use --from/--to to\\n control scope. See #125 §7 for full idempotency guidance.\\n options:\\n - name: db\\n schema: { type: string }\\n description: Path to observability SQLite database (overrides default)\\n - name: endpoint\\n schema: { type: string }\\n description: \\\"OTLP HTTP endpoint URL (fallback: OTEL_EXPORTER_OTLP_ENDPOINT)\\\"\\n - name: service-name\\n schema: { type: string }\\n description: \\\"OTEL service name reported to backend (default: @aaac/observability)\\\"\\n - name: from\\n schema: { type: string }\\n description: Backfill spans starting at or after this ISO 8601 time\\n - name: to\\n schema: { type: string }\\n description: Backfill spans starting at or before this ISO 8601 time\\n - name: event-type\\n schema: { type: string }\\n description: \\\"Filter by event type (e.g. agent.session)\\\"\\n - name: dry-run\\n schema: { type: boolean }\\n description: Print span count without emitting to OTLP backend\\n - name: flush-timeout-ms\\n schema: { type: integer }\\n description: \\\"Maximum ms to wait for OTLP flush before exit (default: 2000; use ≥30000 for >5k spans)\\\"\\n exits:\\n '0':\\n description: Backfill completed\\n stdout:\\n format: json\\n schema:\\n type: object\\n properties:\\n spansFound:\\n type: integer\\n spansEmitted:\\n type: integer\\n dryRun:\\n type: boolean\\n '1':\\n description: Backfill failed (missing endpoint, DB error, etc.)\\n stderr:\\n format: text\\n\\n ingest-vendor-otel:\\n summary: Project a vendor OTLP/JSON trace export (e.g. Claude Code token/cost/trace) into the SQLite Ledger\\n description: |\\n Canonical Projection batch (observability-integration.md §9.2 / T-D2).\\n\\n Reads a vendor OTLP/JSON trace export from --input (file) or stdin, projects\\n each span into a Canonical Event, and backfills it into the SQLite Ledger.\\n\\n Idempotent: every event carries a deterministic dedup_key\\n (vendor-otel:{traceId}:{spanId}) enforced by UNIQUE + INSERT OR IGNORE, so\\n re-running on the same export inserts nothing new (reported as\\n skippedDuplicate). Hook/runtime records remain the primary source; vendor\\n OTEL is auxiliary evidence.\\n options:\\n - name: db\\n schema: { type: string }\\n description: Path to observability SQLite database (overrides default)\\n - name: input\\n aliases: [i]\\n schema: { type: string }\\n description: \\\"Path to the OTLP/JSON trace export (reads stdin when omitted)\\\"\\n - name: source\\n schema: { type: string }\\n description: \\\"Source tag for projected events (default: claude-code-otel)\\\"\\n - name: dry-run\\n schema: { type: boolean }\\n description: Parse and project without writing to the Ledger\\n exits:\\n '0':\\n description: Ingestion completed\\n stdout:\\n format: json\\n schema:\\n type: object\\n properties:\\n found:\\n type: integer\\n inserted:\\n type: integer\\n skippedDuplicate:\\n type: integer\\n skippedInvalid:\\n type: integer\\n dryRun:\\n type: boolean\\n '1':\\n description: Ingestion failed (unreadable input, invalid JSON, DB error)\\n stderr:\\n format: text\\n\\n query:\\n summary: Query the observability store via QueryAdapter\\n options:\\n - name: kind\\n aliases: [k]\\n schema:\\n type: string\\n enum: [trace, span, search, links, issue]\\n description: \\\"Query kind: trace | span | search | links | issue\\\"\\n - name: issue\\n schema: { type: string }\\n description: \\\"Issue ID for issue queries (--kind issue)\\\"\\n - name: trace-id\\n schema: { type: string }\\n description: Trace ID for trace queries (--kind trace)\\n - name: span-id\\n aliases: [s]\\n schema: { type: string }\\n description: Span ID for span/links queries (--kind span or --kind links)\\n - name: event-type\\n schema: { type: string }\\n description: Event type filter for search queries (--kind search)\\n - name: task-id\\n schema: { type: string }\\n description: Task ID filter for search queries (--kind search)\\n - name: from\\n schema: { type: string }\\n description: Start time in ISO 8601 format for search queries (--kind search)\\n - name: to\\n schema: { type: string }\\n description: End time in ISO 8601 format for search queries (--kind search)\\n - name: direction\\n aliases: [d]\\n schema:\\n type: string\\n enum: [forward, reverse, both]\\n description: \\\"Link traversal direction for links queries (default: both)\\\"\\n - name: db\\n schema: { type: string }\\n description: Path to observability SQLite database (overrides default)\\n exits:\\n '0':\\n description: Query succeeded — results as JSON array\\n stdout:\\n format: json\\n schema:\\n type: object\\n '1':\\n description: Query failed\\n stderr:\\n format: text\\n\\n report:\\n summary: Generate an Observability diagnostic report (Layer 1-3 + link completion + Person Tier) from the SQLite Ledger\\n description: |\\n Customer-facing Observability diagnostic (#179 WS-F T-F1). Computes the\\n same Layer 1-3 / link-completion / Person-Tier metrics rendered by the\\n `aaac-diagnostic` Grafana dashboard, over the local SQLite Ledger.\\n\\n Output is Markdown (default) or JSON. Use --project-id to scope to a\\n single project (internal or a cooperating customer project). Supply\\n --baseline-from / --baseline-to to add a Before/After comparison\\n section against a baseline window; --from / --to bound the current\\n (after) window.\\n options:\\n - name: project-id\\n aliases: [p]\\n schema: { type: string }\\n description: Restrict the report to a single project_id (project.id attr / service.name)\\n - name: from\\n schema: { type: string }\\n description: Start time (ISO 8601) for the current/after window\\n - name: to\\n schema: { type: string }\\n description: End time (ISO 8601) for the current/after window\\n - name: baseline-from\\n schema: { type: string }\\n description: Start time (ISO 8601) of the baseline/before window (enables Before/After comparison)\\n - name: baseline-to\\n schema: { type: string }\\n description: End time (ISO 8601) of the baseline/before window (enables Before/After comparison)\\n - name: format\\n aliases: [f]\\n schema:\\n type: string\\n enum: [markdown, json]\\n description: \\\"Output format: markdown (default) | json\\\"\\n - name: db\\n schema: { type: string }\\n description: Path to observability SQLite database (overrides default)\\n exits:\\n '0':\\n description: Report generated — Markdown or JSON on stdout\\n stdout:\\n format: text\\n '1':\\n description: Report generation failed\\n stderr:\\n format: text\\n\";\n\nexport const CONTRACT_JSON_STR: string = \"{\\n \\\"cli_contracts\\\": \\\"0.1.0\\\",\\n \\\"info\\\": {\\n \\\"title\\\": \\\"AaaC Observability CLI\\\",\\n \\\"version\\\": \\\"0.1.0\\\",\\n \\\"description\\\": \\\"aaac-observ — external event registration and query for @aaac/observability\\\"\\n },\\n \\\"command_sets\\\": {\\n \\\"aaac-observ\\\": {\\n \\\"summary\\\": \\\"aaac-observ — register external events and query the observability store\\\",\\n \\\"executable\\\": \\\"aaac-observ\\\",\\n \\\"commands\\\": {\\n \\\"record\\\": {\\n \\\"summary\\\": \\\"Register an external event into the observability pipeline (thin entrypoint for EventCollector.registerExternalEvent)\\\",\\n \\\"options\\\": [\\n {\\n \\\"name\\\": \\\"event-type\\\",\\n \\\"aliases\\\": [\\n \\\"t\\\"\\n ],\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Event type (e.g. promotion.commit, process.edit, agent.session)\\\"\\n },\\n {\\n \\\"name\\\": \\\"lifecycle\\\",\\n \\\"aliases\\\": [\\n \\\"l\\\"\\n ],\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\",\\n \\\"enum\\\": [\\n \\\"open\\\",\\n \\\"close\\\",\\n \\\"event\\\",\\n \\\"instant\\\"\\n ]\\n },\\n \\\"description\\\": \\\"Event lifecycle phase: open | close | event | instant\\\"\\n },\\n {\\n \\\"name\\\": \\\"span-id\\\",\\n \\\"aliases\\\": [\\n \\\"s\\\"\\n ],\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Span ID (auto-generated if omitted)\\\"\\n },\\n {\\n \\\"name\\\": \\\"parent-span-id\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Parent span ID for hierarchy\\\"\\n },\\n {\\n \\\"name\\\": \\\"session-id\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Session ID to associate with the event\\\"\\n },\\n {\\n \\\"name\\\": \\\"trace-id\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Trace ID for distributed tracing\\\"\\n },\\n {\\n \\\"name\\\": \\\"source\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Event source identifier (default: external)\\\"\\n },\\n {\\n \\\"name\\\": \\\"attr\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"array\\\",\\n \\\"items\\\": {\\n \\\"type\\\": \\\"string\\\"\\n }\\n },\\n \\\"description\\\": \\\"Attribute as key=value (repeatable, e.g. --attr git.commit=abc123)\\\"\\n },\\n {\\n \\\"name\\\": \\\"link\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"array\\\",\\n \\\"items\\\": {\\n \\\"type\\\": \\\"string\\\"\\n }\\n },\\n \\\"description\\\": \\\"Cross-axis link as targetSpanId:linkType[:targetTraceId] (repeatable)\\\"\\n },\\n {\\n \\\"name\\\": \\\"db\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Path to observability SQLite database (overrides default)\\\"\\n }\\n ],\\n \\\"exits\\\": {\\n \\\"0\\\": {\\n \\\"description\\\": \\\"Event registered successfully\\\",\\n \\\"stdout\\\": {\\n \\\"format\\\": \\\"json\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"object\\\",\\n \\\"properties\\\": {\\n \\\"eventId\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"spanId\\\": {\\n \\\"type\\\": \\\"string\\\"\\n }\\n }\\n }\\n }\\n },\\n \\\"1\\\": {\\n \\\"description\\\": \\\"Registration failed (validation error or write error)\\\",\\n \\\"stderr\\\": {\\n \\\"format\\\": \\\"text\\\"\\n }\\n }\\n }\\n },\\n \\\"record-hook\\\": {\\n \\\"summary\\\": \\\"Record a Cursor/git hook event — parses stdin JSON, resolves event_mapping into 3-axis spans/links, injects session_id, and emits human-events (fail-open)\\\",\\n \\\"arguments\\\": [\\n {\\n \\\"name\\\": \\\"hook-name\\\",\\n \\\"index\\\": 0,\\n \\\"required\\\": true,\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Cursor/git hook name (e.g. afterFileEdit, subagentStart, beforeShellExecution)\\\"\\n }\\n ],\\n \\\"options\\\": [\\n {\\n \\\"name\\\": \\\"mapping-config\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Path to event-mapping.json (default: .agent-logs/config/event-mapping.json)\\\"\\n },\\n {\\n \\\"name\\\": \\\"db\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Path to observability SQLite database (overrides default)\\\"\\n }\\n ],\\n \\\"exits\\\": {\\n \\\"0\\\": {\\n \\\"description\\\": \\\"Hook recorded (or no-op when stdin/mapping unavailable) — always fail-open\\\",\\n \\\"stdout\\\": {\\n \\\"format\\\": \\\"json\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"object\\\",\\n \\\"properties\\\": {\\n \\\"recorded\\\": {\\n \\\"type\\\": \\\"integer\\\"\\n },\\n \\\"fallback\\\": {\\n \\\"type\\\": \\\"boolean\\\"\\n }\\n }\\n }\\n }\\n }\\n }\\n },\\n \\\"backfill\\\": {\\n \\\"summary\\\": \\\"Re-emit historical spans from SQLite to an OTLP backend\\\",\\n \\\"description\\\": \\\"Reads closed/instant spans from the local SQLite database and emits them\\\\nvia OtelEmitter to an OTLP-compatible backend.\\\\n\\\\nIMPORTANT — idempotency: The OTel SDK does not support specifying custom\\\\nspanIds, so each backfill invocation creates NEW spans in the backend.\\\\nRepeated invocations will produce DUPLICATE data. Use --from/--to to\\\\ncontrol scope. See #125 §7 for full idempotency guidance.\\\\n\\\",\\n \\\"options\\\": [\\n {\\n \\\"name\\\": \\\"db\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Path to observability SQLite database (overrides default)\\\"\\n },\\n {\\n \\\"name\\\": \\\"endpoint\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"OTLP HTTP endpoint URL (fallback: OTEL_EXPORTER_OTLP_ENDPOINT)\\\"\\n },\\n {\\n \\\"name\\\": \\\"service-name\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"OTEL service name reported to backend (default: @aaac/observability)\\\"\\n },\\n {\\n \\\"name\\\": \\\"from\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Backfill spans starting at or after this ISO 8601 time\\\"\\n },\\n {\\n \\\"name\\\": \\\"to\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Backfill spans starting at or before this ISO 8601 time\\\"\\n },\\n {\\n \\\"name\\\": \\\"event-type\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Filter by event type (e.g. agent.session)\\\"\\n },\\n {\\n \\\"name\\\": \\\"dry-run\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"boolean\\\"\\n },\\n \\\"description\\\": \\\"Print span count without emitting to OTLP backend\\\"\\n },\\n {\\n \\\"name\\\": \\\"flush-timeout-ms\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"integer\\\"\\n },\\n \\\"description\\\": \\\"Maximum ms to wait for OTLP flush before exit (default: 2000; use ≥30000 for >5k spans)\\\"\\n }\\n ],\\n \\\"exits\\\": {\\n \\\"0\\\": {\\n \\\"description\\\": \\\"Backfill completed\\\",\\n \\\"stdout\\\": {\\n \\\"format\\\": \\\"json\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"object\\\",\\n \\\"properties\\\": {\\n \\\"spansFound\\\": {\\n \\\"type\\\": \\\"integer\\\"\\n },\\n \\\"spansEmitted\\\": {\\n \\\"type\\\": \\\"integer\\\"\\n },\\n \\\"dryRun\\\": {\\n \\\"type\\\": \\\"boolean\\\"\\n }\\n }\\n }\\n }\\n },\\n \\\"1\\\": {\\n \\\"description\\\": \\\"Backfill failed (missing endpoint, DB error, etc.)\\\",\\n \\\"stderr\\\": {\\n \\\"format\\\": \\\"text\\\"\\n }\\n }\\n }\\n },\\n \\\"ingest-vendor-otel\\\": {\\n \\\"summary\\\": \\\"Project a vendor OTLP/JSON trace export (e.g. Claude Code token/cost/trace) into the SQLite Ledger\\\",\\n \\\"description\\\": \\\"Canonical Projection batch (observability-integration.md §9.2 / T-D2).\\\\n\\\\nReads a vendor OTLP/JSON trace export from --input (file) or stdin, projects\\\\neach span into a Canonical Event, and backfills it into the SQLite Ledger.\\\\n\\\\nIdempotent: every event carries a deterministic dedup_key\\\\n(vendor-otel:{traceId}:{spanId}) enforced by UNIQUE + INSERT OR IGNORE, so\\\\nre-running on the same export inserts nothing new (reported as\\\\nskippedDuplicate). Hook/runtime records remain the primary source; vendor\\\\nOTEL is auxiliary evidence.\\\\n\\\",\\n \\\"options\\\": [\\n {\\n \\\"name\\\": \\\"db\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Path to observability SQLite database (overrides default)\\\"\\n },\\n {\\n \\\"name\\\": \\\"input\\\",\\n \\\"aliases\\\": [\\n \\\"i\\\"\\n ],\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Path to the OTLP/JSON trace export (reads stdin when omitted)\\\"\\n },\\n {\\n \\\"name\\\": \\\"source\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Source tag for projected events (default: claude-code-otel)\\\"\\n },\\n {\\n \\\"name\\\": \\\"dry-run\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"boolean\\\"\\n },\\n \\\"description\\\": \\\"Parse and project without writing to the Ledger\\\"\\n }\\n ],\\n \\\"exits\\\": {\\n \\\"0\\\": {\\n \\\"description\\\": \\\"Ingestion completed\\\",\\n \\\"stdout\\\": {\\n \\\"format\\\": \\\"json\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"object\\\",\\n \\\"properties\\\": {\\n \\\"found\\\": {\\n \\\"type\\\": \\\"integer\\\"\\n },\\n \\\"inserted\\\": {\\n \\\"type\\\": \\\"integer\\\"\\n },\\n \\\"skippedDuplicate\\\": {\\n \\\"type\\\": \\\"integer\\\"\\n },\\n \\\"skippedInvalid\\\": {\\n \\\"type\\\": \\\"integer\\\"\\n },\\n \\\"dryRun\\\": {\\n \\\"type\\\": \\\"boolean\\\"\\n }\\n }\\n }\\n }\\n },\\n \\\"1\\\": {\\n \\\"description\\\": \\\"Ingestion failed (unreadable input, invalid JSON, DB error)\\\",\\n \\\"stderr\\\": {\\n \\\"format\\\": \\\"text\\\"\\n }\\n }\\n }\\n },\\n \\\"query\\\": {\\n \\\"summary\\\": \\\"Query the observability store via QueryAdapter\\\",\\n \\\"options\\\": [\\n {\\n \\\"name\\\": \\\"kind\\\",\\n \\\"aliases\\\": [\\n \\\"k\\\"\\n ],\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\",\\n \\\"enum\\\": [\\n \\\"trace\\\",\\n \\\"span\\\",\\n \\\"search\\\",\\n \\\"links\\\",\\n \\\"issue\\\"\\n ]\\n },\\n \\\"description\\\": \\\"Query kind: trace | span | search | links | issue\\\"\\n },\\n {\\n \\\"name\\\": \\\"issue\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Issue ID for issue queries (--kind issue)\\\"\\n },\\n {\\n \\\"name\\\": \\\"trace-id\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Trace ID for trace queries (--kind trace)\\\"\\n },\\n {\\n \\\"name\\\": \\\"span-id\\\",\\n \\\"aliases\\\": [\\n \\\"s\\\"\\n ],\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Span ID for span/links queries (--kind span or --kind links)\\\"\\n },\\n {\\n \\\"name\\\": \\\"event-type\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Event type filter for search queries (--kind search)\\\"\\n },\\n {\\n \\\"name\\\": \\\"task-id\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Task ID filter for search queries (--kind search)\\\"\\n },\\n {\\n \\\"name\\\": \\\"from\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Start time in ISO 8601 format for search queries (--kind search)\\\"\\n },\\n {\\n \\\"name\\\": \\\"to\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"End time in ISO 8601 format for search queries (--kind search)\\\"\\n },\\n {\\n \\\"name\\\": \\\"direction\\\",\\n \\\"aliases\\\": [\\n \\\"d\\\"\\n ],\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\",\\n \\\"enum\\\": [\\n \\\"forward\\\",\\n \\\"reverse\\\",\\n \\\"both\\\"\\n ]\\n },\\n \\\"description\\\": \\\"Link traversal direction for links queries (default: both)\\\"\\n },\\n {\\n \\\"name\\\": \\\"db\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Path to observability SQLite database (overrides default)\\\"\\n }\\n ],\\n \\\"exits\\\": {\\n \\\"0\\\": {\\n \\\"description\\\": \\\"Query succeeded — results as JSON array\\\",\\n \\\"stdout\\\": {\\n \\\"format\\\": \\\"json\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"object\\\"\\n }\\n }\\n },\\n \\\"1\\\": {\\n \\\"description\\\": \\\"Query failed\\\",\\n \\\"stderr\\\": {\\n \\\"format\\\": \\\"text\\\"\\n }\\n }\\n }\\n },\\n \\\"report\\\": {\\n \\\"summary\\\": \\\"Generate an Observability diagnostic report (Layer 1-3 + link completion + Person Tier) from the SQLite Ledger\\\",\\n \\\"description\\\": \\\"Customer-facing Observability diagnostic (#179 WS-F T-F1). Computes the\\\\nsame Layer 1-3 / link-completion / Person-Tier metrics rendered by the\\\\n`aaac-diagnostic` Grafana dashboard, over the local SQLite Ledger.\\\\n\\\\nOutput is Markdown (default) or JSON. Use --project-id to scope to a\\\\nsingle project (internal or a cooperating customer project). Supply\\\\n--baseline-from / --baseline-to to add a Before/After comparison\\\\nsection against a baseline window; --from / --to bound the current\\\\n(after) window.\\\\n\\\",\\n \\\"options\\\": [\\n {\\n \\\"name\\\": \\\"project-id\\\",\\n \\\"aliases\\\": [\\n \\\"p\\\"\\n ],\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Restrict the report to a single project_id (project.id attr / service.name)\\\"\\n },\\n {\\n \\\"name\\\": \\\"from\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Start time (ISO 8601) for the current/after window\\\"\\n },\\n {\\n \\\"name\\\": \\\"to\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"End time (ISO 8601) for the current/after window\\\"\\n },\\n {\\n \\\"name\\\": \\\"baseline-from\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Start time (ISO 8601) of the baseline/before window (enables Before/After comparison)\\\"\\n },\\n {\\n \\\"name\\\": \\\"baseline-to\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"End time (ISO 8601) of the baseline/before window (enables Before/After comparison)\\\"\\n },\\n {\\n \\\"name\\\": \\\"format\\\",\\n \\\"aliases\\\": [\\n \\\"f\\\"\\n ],\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\",\\n \\\"enum\\\": [\\n \\\"markdown\\\",\\n \\\"json\\\"\\n ]\\n },\\n \\\"description\\\": \\\"Output format: markdown (default) | json\\\"\\n },\\n {\\n \\\"name\\\": \\\"db\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Path to observability SQLite database (overrides default)\\\"\\n }\\n ],\\n \\\"exits\\\": {\\n \\\"0\\\": {\\n \\\"description\\\": \\\"Report generated — Markdown or JSON on stdout\\\",\\n \\\"stdout\\\": {\\n \\\"format\\\": \\\"text\\\"\\n }\\n },\\n \\\"1\\\": {\\n \\\"description\\\": \\\"Report generation failed\\\",\\n \\\"stderr\\\": {\\n \\\"format\\\": \\\"text\\\"\\n }\\n }\\n }\\n }\\n }\\n }\\n }\\n}\";\n","/**\n * record handler — thin entrypoint for EventCollector.registerExternalEvent.\n *\n * Wires the CLI options to the write pipeline:\n * options → EventCollector.registerExternalEvent\n * → Normalizer → Correlator → Enricher → SqliteSink + OtelEmitter\n *\n * architecture.md §9 / OBSERVABILITY_TASKS.md Phase 3-2\n * shift-left-event-mapping.md: aaac-observ record is the thin entrypoint\n */\nimport { createPipeline, generateId, DEFAULT_DB_PATH } from \"../index.js\";\nimport type { CanonicalLink, AttrValue, Lifecycle } from \"../types/canonical-event.js\";\n\n// ── Parsers ──────────────────────────────────────────────────────────────────\n\n/**\n * Parse comma-separated key=value attribute string into a Record.\n * Also accepts a JSON object string.\n *\n * Examples:\n * \"git.commit=abc123,git.branch=main\"\n * '{\"git.commit\":\"abc123\",\"git.branch\":\"main\"}'\n */\nexport function parseAttr(attrStr: string | undefined): Record<string, AttrValue> {\n if (!attrStr) return {};\n const trimmed = attrStr.trim();\n if (trimmed.startsWith(\"{\")) {\n try {\n return JSON.parse(trimmed) as Record<string, AttrValue>;\n } catch {\n // fall through to key=value parsing\n }\n }\n const result: Record<string, AttrValue> = {};\n for (const pair of trimmed.split(\",\")) {\n const eqIdx = pair.indexOf(\"=\");\n if (eqIdx > 0) {\n const key = pair.slice(0, eqIdx).trim();\n const val = pair.slice(eqIdx + 1).trim();\n result[key] = val;\n }\n }\n return result;\n}\n\n/**\n * Parse comma-separated link string into a CanonicalLink array.\n * Format per item: targetSpanId:linkType[:targetTraceId]\n *\n * Example: \"spanId123:materializes_as_commit,spanId456:contains_change:traceId789\"\n */\nexport function parseLinks(linkStr: string | undefined): CanonicalLink[] {\n if (!linkStr) return [];\n const links: CanonicalLink[] = [];\n for (const item of linkStr.split(\",\")) {\n const parts = item.trim().split(\":\");\n if (parts.length >= 2) {\n const targetSpanId = parts[0].trim();\n const linkType = parts[1].trim();\n const targetTraceId = parts[2]?.trim() || undefined;\n if (targetSpanId && linkType) {\n links.push({ targetSpanId, linkType, targetTraceId });\n }\n }\n }\n return links;\n}\n\n// ── Handler ──────────────────────────────────────────────────────────────────\n\n/**\n * Options as parsed from the generated CommandHandlers interface.\n * NOTE: attr and link are strings (last value from --option) not arrays,\n * because the generated Commander program does not use a collector.\n * Comma-separate multiple values: --attr \"key1=val1,key2=val2\"\n */\nexport interface RecordHandlerOptions {\n eventType?: string;\n lifecycle?: string;\n spanId?: string;\n parentSpanId?: string;\n sessionId?: string;\n traceId?: string;\n source?: string;\n attr?: string;\n link?: string;\n db?: string;\n}\n\n/**\n * Handle `aaac-observ record`.\n *\n * Required options: --event-type, --lifecycle\n * On success: writes the event through the full pipeline and prints\n * { eventId, spanId } to stdout.\n * On error: writes to stderr and exits with code 1.\n */\nexport async function handleRecord(\n options: RecordHandlerOptions,\n _parentOpts: Record<string, unknown>,\n): Promise<void> {\n // ── Validate required options ──────────────────────────────────────────────\n if (!options.eventType) {\n process.stderr.write(\"Error: --event-type (-t) is required\\n\");\n process.exit(1);\n }\n const validLifecycles: readonly string[] = [\"open\", \"close\", \"event\", \"instant\"];\n if (!options.lifecycle) {\n process.stderr.write(\n `Error: --lifecycle (-l) is required (${validLifecycles.join(\"|\")})\\n`,\n );\n process.exit(1);\n }\n if (!validLifecycles.includes(options.lifecycle)) {\n process.stderr.write(\n `Error: --lifecycle must be one of: ${validLifecycles.join(\"|\")}\\n`,\n );\n process.exit(1);\n }\n\n // ── Build event payload ────────────────────────────────────────────────────\n const dbPath = options.db ?? DEFAULT_DB_PATH;\n const spanId = options.spanId ?? generateId();\n const attributes = parseAttr(options.attr);\n const links = parseLinks(options.link);\n\n // Inject well-known scalars into attributes so the Normalizer picks them up\n if (options.sessionId) {\n attributes[\"session_id\"] = options.sessionId;\n }\n // trace_id stored as attribute for user reference; canonical traceId is\n // managed by Normalizer/Correlator (propagated via parentSpanId chain)\n if (options.traceId) {\n attributes[\"trace_id\"] = options.traceId;\n }\n\n // ── Build & execute pipeline ───────────────────────────────────────────────\n let capturedEventId: string | undefined;\n\n const { collector, sink } = createPipeline({\n dbPath,\n // Use afterCorrelate to capture the event id before it is written\n afterCorrelate: (event) => {\n capturedEventId = event.id;\n return event;\n },\n // Enable the default enrichment rules (R1–R5). This is the path the git\n // post-commit hook uses to record promotion.commit (close) with\n // committed_files; R5 (cross-axis) must run here to add the\n // materializes_as_commit link to task spans whose modified files intersect\n // the commit. R3/R4 accumulation persists in the SQLite-backed cache of the\n // same db file, so R5 sees it across the process boundary (#143 / #140).\n // Enricher is fail-open, so a rule error never blocks recording.\n });\n\n try {\n collector.registerExternalEvent({\n source: options.source ?? \"external\",\n eventType: options.eventType,\n lifecycle: options.lifecycle as Lifecycle,\n spanId,\n parentSpanId: options.parentSpanId,\n attributes,\n links,\n });\n } catch (err) {\n process.stderr.write(\n `Error: ${err instanceof Error ? err.message : String(err)}\\n`,\n );\n sink.close();\n process.exit(1);\n }\n\n sink.close();\n\n const result = { eventId: capturedEventId, spanId };\n process.stdout.write(JSON.stringify(result) + \"\\n\");\n}\n","/**\n * query handler — read path via QueryAdapter.\n *\n * Routes --kind to the appropriate SqliteQueryAdapter method and emits\n * results as JSON to stdout.\n *\n * Supported kinds:\n * trace → QueryAdapter.getTrace(--trace-id)\n * span → QueryAdapter.getSpan(--span-id) [+ QueryAdapter.getSpanEvents]\n * search → QueryAdapter.querySpans({ eventType, taskId, from, to })\n * links → QueryAdapter.getLinks(--span-id, --direction)\n * issue → analyzeOutcomeChain(--issue) [#178 T-E2]\n *\n * architecture.md §12 / OBSERVABILITY_TASKS.md Phase 3-2 (record CLI + query)\n */\nimport { SqliteQueryAdapter, DEFAULT_DB_PATH } from \"../index.js\";\nimport { isoToUnixNano } from \"../types/ids.js\";\nimport type { LinkDirection } from \"../query/models.js\";\nimport { analyzeOutcomeChain, OUTCOME_CHAIN_STAGES } from \"../analysis/outcome-chain.js\";\n\n// ── Handler ───────────────────────────────────────────────────────────────────\n\n/**\n * Options as parsed from the generated CommandHandlers interface.\n */\nexport interface QueryHandlerOptions {\n kind?: string;\n traceId?: string;\n spanId?: string;\n eventType?: string;\n taskId?: string;\n from?: string;\n to?: string;\n direction?: string;\n issue?: string;\n db?: string;\n}\n\n/** JSON replacer that serialises BigInt as a string. */\nfunction bigIntReplacer(_key: string, value: unknown): unknown {\n return typeof value === \"bigint\" ? value.toString() : value;\n}\n\n/**\n * Handle `aaac-observ query`.\n *\n * Required option: --kind (trace|span|search|links)\n * On success: writes a JSON array/object to stdout.\n * On error: writes to stderr and exits with code 1.\n *\n * DESIGN NOTE: all required-arg validation happens BEFORE the adapter is\n * created, so that when process.exit is mocked to throw in tests there is no\n * risk of a double-close on the database connection.\n */\nexport async function handleQuery(\n options: QueryHandlerOptions,\n _parentOpts: Record<string, unknown>,\n): Promise<void> {\n // Proposal shorthand: `aaac-observ query --issue <id>` (#178 T-E2)\n if (options.issue && !options.kind) {\n options.kind = \"issue\";\n }\n\n const validKinds = [\"trace\", \"span\", \"search\", \"links\", \"issue\"] as const;\n type QueryKind = (typeof validKinds)[number];\n\n // ── Validate options (before opening the adapter) ─────────────────────────\n if (!options.kind) {\n process.stderr.write(\n `Error: --kind (-k) is required (${validKinds.join(\"|\")})\\n`,\n );\n process.exit(1);\n }\n if (!validKinds.includes(options.kind as QueryKind)) {\n process.stderr.write(\n `Error: --kind must be one of: ${validKinds.join(\"|\")}\\n`,\n );\n process.exit(1);\n }\n\n const kind = options.kind as QueryKind;\n\n // Validate sub-command required args (before adapter creation)\n if (kind === \"trace\" && !options.traceId) {\n process.stderr.write(\"Error: --trace-id is required for --kind trace\\n\");\n process.exit(1);\n }\n if (kind === \"span\" && !options.spanId) {\n process.stderr.write(\"Error: --span-id is required for --kind span\\n\");\n process.exit(1);\n }\n if (kind === \"links\" && !options.spanId) {\n process.stderr.write(\"Error: --span-id is required for --kind links\\n\");\n process.exit(1);\n }\n if (kind === \"issue\" && !options.issue) {\n process.stderr.write(\"Error: --issue is required for --kind issue\\n\");\n process.exit(1);\n }\n\n // ── Open adapter ──────────────────────────────────────────────────────────\n const dbPath = options.db ?? DEFAULT_DB_PATH;\n const adapter = new SqliteQueryAdapter(dbPath);\n\n try {\n let result: unknown;\n\n switch (kind) {\n // ── trace: all spans in a trace ─────────────────────────────────────\n case \"trace\": {\n // options.traceId is guaranteed by pre-validation above\n result = adapter.getTrace(options.traceId!);\n break;\n }\n\n // ── span: single span + its events ──────────────────────────────────\n case \"span\": {\n // options.spanId is guaranteed by pre-validation above\n const span = adapter.getSpan(options.spanId!);\n const events = adapter.getSpanEvents(options.spanId!);\n result = span !== undefined ? { span, events } : null;\n break;\n }\n\n // ── search: spans matching event-type / task-id / time range ─────────\n case \"search\": {\n const filter: Parameters<typeof adapter.querySpans>[0] = {};\n if (options.eventType) filter.eventType = options.eventType;\n if (options.taskId) filter.taskId = options.taskId;\n if (options.from) filter.fromTimeUnixNano = isoToUnixNano(options.from);\n if (options.to) filter.toTimeUnixNano = isoToUnixNano(options.to);\n result = adapter.querySpans(filter);\n break;\n }\n\n // ── links: link traversal ─────────────────────────────────────────────\n case \"links\": {\n const validDirections = [\"forward\", \"reverse\", \"both\"] as const;\n type Dir = (typeof validDirections)[number];\n const dir: Dir =\n options.direction !== undefined &&\n validDirections.includes(options.direction as Dir)\n ? (options.direction as Dir)\n : \"both\";\n result = adapter.getLinks(options.spanId!, dir as LinkDirection);\n break;\n }\n\n // ── issue: Outcome chain analysis for an Issue (#178 T-E2) ──────────\n case \"issue\": {\n // options.issue is guaranteed by pre-validation above\n result = analyzeOutcomeChain(adapter, options.issue!);\n break;\n }\n }\n\n process.stdout.write(JSON.stringify(result, bigIntReplacer) + \"\\n\");\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n\n // Graceful handling: an un-initialised (fresh empty) database has no\n // tables yet. Return an empty / null result rather than an error so that\n // `aaac-observ query` on a machine with no recorded events behaves\n // predictably.\n if (msg.includes(\"no such table\") || msg.includes(\"no such column\")) {\n let emptyResult: unknown;\n if (kind === \"span\") {\n emptyResult = null;\n } else if (kind === \"issue\") {\n // No tables → all stages are missing\n emptyResult = {\n issueId: options.issue ?? \"\",\n stages: OUTCOME_CHAIN_STAGES.map((s) => ({\n eventType: s,\n status: \"missing\",\n spanIds: [],\n })),\n complete: false,\n gaps: [...OUTCOME_CHAIN_STAGES],\n provisional: [],\n };\n } else {\n emptyResult = [];\n }\n process.stdout.write(JSON.stringify(emptyResult, bigIntReplacer) + \"\\n\");\n adapter.close();\n return;\n }\n\n process.stderr.write(`Error: ${msg}\\n`);\n adapter.close();\n process.exit(1);\n }\n\n adapter.close();\n}\n","/**\n * backfill handler — re-emit historical spans from SQLite to an OTLP backend.\n *\n * Reads closed/instant spans from the local SQLite database and emits them\n * via OtelEmitter to an OTLP-compatible backend (e.g. OTel Collector →\n * ClickHouse).\n *\n * ## Idempotency design (important)\n *\n * The OTel SDK does NOT support specifying a custom spanId when creating spans.\n * Therefore, each backfill invocation will create NEW spans in the OTLP backend\n * with different spanIds than the originals recorded in SQLite. Repeated\n * invocations will produce DUPLICATE data in the backend (e.g. ClickHouse).\n *\n * Recommended idempotency strategies:\n * 1. Run backfill only once per SQLite DB / time range.\n * 2. Use --from / --to to backfill specific time windows; track which windows\n * have already been backfilled externally.\n * 3. Truncate the ClickHouse target table before re-running (destructive; safe\n * for dev environments).\n * 4. Use ClickHouse ReplacingMergeTree / FINAL for approximate deduplication\n * (requires schema changes; not the default otel_traces schema).\n *\n * The --dry-run flag prints span metadata without emitting; use it to verify\n * scope before committing to a real backfill.\n *\n * architecture.md §11 / docs/observability-setup.md / #125 §7\n */\nimport { SqliteQueryAdapter, OtelEmitter, DEFAULT_DB_PATH, isoToUnixNano } from \"../index.js\";\nimport { mapAllEventsToSpans } from \"../otel/span-mapper.js\";\nimport type { MappedSpan, MappedSpanLink } from \"../otel/span-mapper.js\";\nimport type { SpanRecord, LinkRecord } from \"../query/models.js\";\n\n// ── Handler options ───────────────────────────────────────────────────────────\n\nexport interface BackfillHandlerOptions {\n /** SQLite database path. Defaults to DEFAULT_DB_PATH. */\n db?: string;\n /**\n * OTLP HTTP endpoint URL.\n * Fallback: OTEL_EXPORTER_OTLP_ENDPOINT env var.\n * Required unless --dry-run is set.\n */\n endpoint?: string;\n /** OTEL service name reported to the backend. Default: '@aaac/observability'. */\n serviceName?: string;\n /** Filter: only backfill spans starting at or after this ISO 8601 time. */\n from?: string;\n /** Filter: only backfill spans starting at or before this ISO 8601 time. */\n to?: string;\n /** Filter: only backfill spans of this event type (e.g. 'agent.session'). */\n eventType?: string;\n /**\n * Print span metadata to stdout without actually emitting to the OTLP backend.\n * Useful for previewing scope before committing to a real backfill.\n */\n dryRun?: boolean;\n /**\n * Maximum milliseconds to wait for the OTLP flush before the CLI exits.\n * Default: 2000 ms (preserves existing vitest compatibility — unreachable\n * endpoints resolve immediately via connection-refused, so tests are unaffected\n * by the default value).\n *\n * For large backfills (> 5 000 spans) the BatchSpanProcessor needs significantly\n * more time. Recommended production value: 30 000 ms.\n *\n * Rule of thumb: allow ≥ 400 ms per 512-span batch\n * (i.e. ceil(spansFound / 512) * 400 ms, rounded up generously).\n *\n * Accepts `string` because the generated CLI program forwards the raw\n * `--flush-timeout-ms` option value verbatim; it is coerced to a number\n * (see `effectiveFlushMs`) inside the handler.\n */\n flushTimeoutMs?: number | string;\n}\n\n// ── MappedSpan reconstruction ─────────────────────────────────────────────────\n\n/**\n * Reconstruct a MappedSpan from a stored SpanRecord + its forward links.\n *\n * Backfill works at the \"span\" level (not the raw event level) because\n * SqliteSink materialises open+close into the `spans` table at write time.\n * Only closed or instant spans carry meaningful duration information.\n */\nfunction spanRecordToMappedSpan(\n span: SpanRecord,\n links: LinkRecord[],\n): MappedSpan {\n const start = span.startTime ?? 0n;\n const end = span.endTime ?? start;\n\n // Reconstruct MappedSpanLinks from the stored canonical_links rows.\n const mappedLinks: MappedSpanLink[] = links.map((l) => ({\n targetSpanId: l.targetSpanId,\n targetTraceId: l.targetTraceId ?? undefined,\n attributes: {\n link_type: l.linkType,\n ...(l.attributes ?? {}),\n },\n }));\n\n return {\n spanId: span.spanId,\n traceId: span.traceId ?? \"\",\n parentSpanId: span.parentSpanId ?? undefined,\n name: span.eventType,\n startTimeUnixNano: start,\n endTimeUnixNano: end,\n attributes: span.attributes,\n spanEvents: [], // span events are not stored in the spans table\n links: mappedLinks,\n };\n}\n\n// ── Handler ───────────────────────────────────────────────────────────────────\n\n/**\n * Handle `aaac-observ backfill`.\n *\n * Emits historical spans from the SQLite store to an OTLP backend.\n * Prints a JSON summary to stdout:\n * { spansFound: number, spansEmitted: number, dryRun: boolean }\n *\n * On error: writes to stderr and exits with code 1.\n *\n * IMPORTANT — idempotency: Re-running backfill without --from/--to restriction\n * will re-emit all matching spans, creating DUPLICATES in the OTLP backend.\n * See module-level comment for mitigation strategies.\n */\nexport async function handleBackfill(\n options: BackfillHandlerOptions,\n _parentOpts: Record<string, unknown>,\n): Promise<void> {\n const dbPath = options.db ?? DEFAULT_DB_PATH;\n const dryRun = options.dryRun ?? false;\n\n // ── Validate endpoint (not needed for dry-run) ────────────────────────────\n const endpoint = options.endpoint ?? process.env[\"OTEL_EXPORTER_OTLP_ENDPOINT\"];\n if (!dryRun && !endpoint) {\n process.stderr.write(\n \"Error: --endpoint is required (or set OTEL_EXPORTER_OTLP_ENDPOINT) unless --dry-run\\n\",\n );\n process.exit(1);\n }\n\n // ── Validate and parse time filters ───────────────────────────────────────\n // isoToUnixNano() silently falls back to currentTimeUnixNano() for invalid\n // ISO strings (shared utility — behaviour unchanged for other callers).\n // Backfill must validate explicitly so a typo in --from/--to causes exit 1\n // rather than a silent wrong-boundary backfill (F1 / issue #125).\n let fromNano: bigint | undefined;\n let toNano: bigint | undefined;\n if (options.from) {\n if (Number.isNaN(Date.parse(options.from))) {\n process.stderr.write(\n `Error: invalid --from value \"${options.from}\" — expected ISO 8601\\n`,\n );\n process.exit(1);\n }\n fromNano = isoToUnixNano(options.from);\n }\n if (options.to) {\n if (Number.isNaN(Date.parse(options.to))) {\n process.stderr.write(\n `Error: invalid --to value \"${options.to}\" — expected ISO 8601\\n`,\n );\n process.exit(1);\n }\n toNano = isoToUnixNano(options.to);\n }\n\n // ── Query spans from SQLite ────────────────────────────────────────────────\n const adapter = new SqliteQueryAdapter(dbPath);\n let spans: SpanRecord[];\n try {\n spans = adapter.querySpans({\n ...(options.eventType ? { eventType: options.eventType } : {}),\n ...(fromNano !== undefined ? { fromTimeUnixNano: fromNano } : {}),\n ...(toNano !== undefined ? { toTimeUnixNano: toNano } : {}),\n });\n // Only backfill spans that have completed (closed or instant).\n // Open spans are missing their end_time and would emit with zero duration.\n spans = spans.filter((s) => s.status === \"closed\" || s.status === \"instant\");\n } catch (err) {\n process.stderr.write(\n `Error: failed to query SQLite — ${err instanceof Error ? err.message : String(err)}\\n`,\n );\n adapter.close();\n process.exit(1);\n return; // unreachable, but satisfies TS control-flow\n }\n\n const spansFound = spans.length;\n\n if (dryRun) {\n adapter.close();\n const result = { spansFound, spansEmitted: 0, dryRun: true };\n process.stdout.write(JSON.stringify(result) + \"\\n\");\n return;\n }\n\n // ── Reconstruct MappedSpans with their links ──────────────────────────────\n const mappedSpans: MappedSpan[] = [];\n for (const span of spans) {\n let links: LinkRecord[] = [];\n try {\n links = adapter.getLinks(span.spanId, \"forward\");\n } catch {\n // fail-open: missing links are non-fatal for backfill\n }\n mappedSpans.push(spanRecordToMappedSpan(span, links));\n }\n\n adapter.close();\n\n // ── Large-backfill warning ────────────────────────────────────────────────\n // Warn before emitting when the operator-supplied (or default) flush timeout\n // is likely too short for the span count. Rule of thumb: each 512-span batch\n // takes ~400 ms → 1 000 spans ≈ 2 batches ≈ 800 ms, well under 2 s, but\n // 13 000 spans ≈ 26 batches ≈ 10 400 ms, which exceeds the 2 s default.\n // Emitting the warning here (before the emit loop) lets the operator ^C and\n // re-run with --flush-timeout-ms 30000 before any data is sent.\n const effectiveFlushMs =\n options.flushTimeoutMs != null ? Number(options.flushTimeoutMs) : 2000;\n if (spansFound > 1000 && effectiveFlushMs < 10000) {\n process.stderr.write(\n `Warning: ${spansFound} spans queued but --flush-timeout-ms is ` +\n `${effectiveFlushMs} ms (< 10 000 ms). Large batches may not fully ` +\n `flush before the deadline. Recommended: --flush-timeout-ms 30000\\n`,\n );\n }\n\n // ── Emit via OtelEmitter ──────────────────────────────────────────────────\n const emitter = new OtelEmitter({\n endpoint,\n serviceName: options.serviceName,\n });\n\n let spansEmitted = 0;\n for (const mapped of mappedSpans) {\n try {\n emitter.emit(mapped);\n spansEmitted++;\n } catch {\n // fail-open: individual span failures are non-fatal\n }\n }\n\n // Flush pending batch before reporting success.\n // Race against effectiveFlushMs so that an unreachable OTLP endpoint\n // never causes the CLI to hang indefinitely. OtelEmitter.shutdown() already\n // swallows its own errors, so the race is purely a time-bound escape hatch.\n // Default 2 000 ms preserves vitest idempotency-test compatibility (unreachable\n // endpoints resolve immediately via connection-refused; the timeout is never hit\n // in tests). For production use with > 5 000 spans pass --flush-timeout-ms 30000.\n await Promise.race([\n emitter.shutdown(),\n new Promise<void>((resolve) => setTimeout(resolve, effectiveFlushMs)),\n ]);\n\n const result = { spansFound, spansEmitted, dryRun: false };\n process.stdout.write(JSON.stringify(result) + \"\\n\");\n}\n","/**\n * ingest-vendor-otel handler — Canonical Projection of vendor OTEL into the Ledger.\n *\n * observability-integration.md §9.2 (T-D2): backfill Claude Code (vendor) OTEL\n * token/cost/trace exports into the SQLite Ledger so they become queryable\n * Canonical Events. The Ledger remains the canonical source of truth; vendor OTEL\n * is auxiliary evidence (\"OTEL は補助証跡。正本は Canonical Event\").\n *\n * ## Idempotency (§9.2)\n *\n * Every projected event carries a deterministic dedup_key\n * (`vendor-otel:{traceId}:{spanId}`). SqliteSink enforces UNIQUE(dedup_key) via\n * INSERT OR IGNORE, so re-running this command on the same export is a true no-op:\n * already-present rows are reported as `skippedDuplicate`. Hook/runtime records\n * (dedup_key = NULL) are the primary source and are never overwritten.\n *\n * Reads the OTLP/JSON trace export from --input (a file path) or stdin. Writes\n * directly to the SQLite Ledger (no OTLP re-emit — vendor spans already live in\n * their own pipeline), which makes the projection inherently fail-open with\n * respect to ClickHouse availability.\n */\nimport { readFile } from \"node:fs/promises\";\nimport { SqliteSink, DEFAULT_DB_PATH } from \"../index.js\";\nimport {\n mapVendorOtelExport,\n VENDOR_OTEL_SOURCE,\n} from \"../normalize/vendor-otel-mapper.js\";\n\n// ── Handler options ───────────────────────────────────────────────────────────\n\nexport interface IngestVendorOtelOptions {\n /** SQLite database path. Defaults to DEFAULT_DB_PATH. */\n db?: string;\n /** Path to the vendor OTLP/JSON trace export. Reads stdin when omitted. */\n input?: string;\n /** `source` tag applied to projected events. Default: 'claude-code-otel'. */\n source?: string;\n /** Parse + project without writing to the Ledger (prints counts only). */\n dryRun?: boolean;\n}\n\n/** Result printed to stdout as JSON. */\nexport interface IngestVendorOtelResult {\n /** Vendor spans projected to CanonicalEvents. */\n found: number;\n /** New rows written to the Ledger. */\n inserted: number;\n /** Rows already present (dedup_key collision) — idempotent re-run evidence. */\n skippedDuplicate: number;\n /** Vendor spans skipped for lacking a stable trace/span identity. */\n skippedInvalid: number;\n /** True when --dry-run was set (no writes performed). */\n dryRun: boolean;\n}\n\n// ── stdin helper ───────────────────────────────────────────────────────────────\n\n/** Read the whole stdin stream as a UTF-8 string (\"\" on TTY / error). */\nasync function readStdin(): Promise<string> {\n if (process.stdin.isTTY) return \"\";\n return new Promise<string>((resolve) => {\n let data = \"\";\n let settled = false;\n const finish = (): void => {\n if (settled) return;\n settled = true;\n resolve(data);\n };\n try {\n process.stdin.setEncoding(\"utf8\");\n process.stdin.on(\"data\", (chunk) => {\n data += chunk;\n });\n process.stdin.on(\"end\", finish);\n process.stdin.on(\"error\", finish);\n process.stdin.on(\"close\", finish);\n } catch {\n finish();\n }\n });\n}\n\n// ── Handler ───────────────────────────────────────────────────────────────────\n\n/**\n * Handle `aaac-observ ingest-vendor-otel`.\n *\n * Prints a JSON summary to stdout:\n * { found, inserted, skippedDuplicate, skippedInvalid, dryRun }\n *\n * On error (unreadable input / invalid JSON / DB failure): writes to stderr and\n * exits with code 1.\n */\nexport async function handleIngestVendorOtel(\n options: IngestVendorOtelOptions,\n _parentOpts: Record<string, unknown>,\n): Promise<void> {\n const dbPath = options.db ?? DEFAULT_DB_PATH;\n const dryRun = options.dryRun ?? false;\n const source = options.source ?? VENDOR_OTEL_SOURCE;\n\n // ── Read input (file or stdin) ─────────────────────────────────────────────\n let raw: string;\n try {\n raw = options.input ? await readFile(options.input, \"utf8\") : await readStdin();\n } catch (err) {\n process.stderr.write(\n `Error: failed to read input — ${err instanceof Error ? err.message : String(err)}\\n`,\n );\n process.exit(1);\n return;\n }\n\n if (raw.trim() === \"\") {\n process.stderr.write(\n \"Error: no input — provide --input <file> or pipe an OTLP/JSON trace export via stdin\\n\",\n );\n process.exit(1);\n return;\n }\n\n // ── Parse OTLP/JSON ────────────────────────────────────────────────────────\n let doc: unknown;\n try {\n doc = JSON.parse(raw);\n } catch (err) {\n process.stderr.write(\n `Error: invalid JSON input — ${err instanceof Error ? err.message : String(err)}\\n`,\n );\n process.exit(1);\n return;\n }\n\n // ── Project to CanonicalEvents ─────────────────────────────────────────────\n const { events, skipped: skippedInvalid } = mapVendorOtelExport(doc, { source });\n const found = events.length;\n\n if (dryRun) {\n const result: IngestVendorOtelResult = {\n found,\n inserted: 0,\n skippedDuplicate: 0,\n skippedInvalid,\n dryRun: true,\n };\n process.stdout.write(JSON.stringify(result) + \"\\n\");\n return;\n }\n\n // ── Write to the Ledger (idempotent via dedup_key) ─────────────────────────\n const sink = new SqliteSink(dbPath);\n let inserted = 0;\n let skippedDuplicate = 0;\n try {\n for (const event of events) {\n if (sink.write(event)) {\n inserted += 1;\n } else {\n skippedDuplicate += 1;\n }\n }\n } catch (err) {\n sink.close();\n process.stderr.write(\n `Error: failed to write to Ledger — ${err instanceof Error ? err.message : String(err)}\\n`,\n );\n process.exit(1);\n return;\n }\n sink.close();\n\n const result: IngestVendorOtelResult = {\n found,\n inserted,\n skippedDuplicate,\n skippedInvalid,\n dryRun: false,\n };\n process.stdout.write(JSON.stringify(result) + \"\\n\");\n}\n","/**\n * report handler — Observability 診断レポート生成 (#179 WS-F T-F1).\n *\n * Reads the local SQLite Ledger via SqliteQueryAdapter and renders the Layer 1–3\n * / link-completion / Person-Tier diagnostic as Markdown (default) or JSON.\n *\n * Mirrors the metric formulas of the `aaac-diagnostic` Grafana dashboard\n * (docker/observability/analysis-views.sql) so the CLI report and the dashboard\n * agree. Optionally produces a Before/After comparison when a baseline window is\n * supplied.\n *\n * Follows the handleQuery pattern: required-arg validation runs before the\n * adapter is opened, and a fresh/empty database degrades gracefully to an empty\n * report rather than an error.\n */\nimport { SqliteQueryAdapter, DEFAULT_DB_PATH } from \"../index.js\";\nimport {\n generateDiagnosticReport,\n renderReportMarkdown,\n renderReportJson,\n type DiagnosticReport,\n type DiagnosticReportOptions,\n} from \"../analysis/diagnostic-report.js\";\n\nexport interface ReportHandlerOptions {\n projectId?: string;\n from?: string;\n to?: string;\n baselineFrom?: string;\n baselineTo?: string;\n format?: string;\n db?: string;\n}\n\n/** An empty report shaped like generateDiagnosticReport output (for fresh DBs). */\nfunction emptyReport(options: ReportHandlerOptions): DiagnosticReport {\n const report: DiagnosticReport = {\n generatedAt: new Date().toISOString(),\n projectId: options.projectId ?? null,\n period: { from: options.from ?? null, to: options.to ?? null },\n metrics: {\n layer1: [],\n layer2: [],\n layer3: [],\n linkCompletion: { sessionLinkRate: [], stageArrival: [], provisional: [] },\n tierRatio: [],\n summary: {\n issueCount: 0,\n sessionCount: 0,\n totalCostUsd: 0,\n avgLeverage: 0,\n avgCommitRate: 0,\n avgCiPassRate: 0,\n avgChainCompleteness: 0,\n sessionLinkRate: 0,\n tierCounts: { high: 0, mid: 0, low: 0 },\n },\n },\n };\n return report;\n}\n\n/**\n * Handle `aaac-observ report`.\n *\n * On success: writes the rendered report (Markdown or JSON) to stdout.\n * On error: writes to stderr and exits with code 1.\n */\nexport async function handleReport(\n options: ReportHandlerOptions,\n _parentOpts: Record<string, unknown>,\n): Promise<void> {\n const validFormats = [\"markdown\", \"json\"] as const;\n type Format = (typeof validFormats)[number];\n\n // ── Validate options (before opening the adapter) ─────────────────────────\n if (options.format !== undefined && !validFormats.includes(options.format as Format)) {\n process.stderr.write(`Error: --format must be one of: ${validFormats.join(\"|\")}\\n`);\n process.exit(1);\n }\n const format: Format = (options.format as Format) ?? \"markdown\";\n\n const render = (report: DiagnosticReport): string =>\n format === \"json\" ? renderReportJson(report) : renderReportMarkdown(report);\n\n // ── Open adapter ──────────────────────────────────────────────────────────\n const dbPath = options.db ?? DEFAULT_DB_PATH;\n const adapter = new SqliteQueryAdapter(dbPath);\n\n try {\n const reportOptions: DiagnosticReportOptions = {};\n if (options.projectId !== undefined) reportOptions.projectId = options.projectId;\n if (options.from !== undefined) reportOptions.from = options.from;\n if (options.to !== undefined) reportOptions.to = options.to;\n if (options.baselineFrom !== undefined) reportOptions.baselineFrom = options.baselineFrom;\n if (options.baselineTo !== undefined) reportOptions.baselineTo = options.baselineTo;\n\n const report = generateDiagnosticReport(adapter, reportOptions);\n process.stdout.write(render(report) + \"\\n\");\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n\n // Fresh/empty database: no tables yet → emit an empty report, not an error.\n if (msg.includes(\"no such table\") || msg.includes(\"no such column\")) {\n process.stdout.write(render(emptyReport(options)) + \"\\n\");\n adapter.close();\n return;\n }\n\n process.stderr.write(`Error: ${msg}\\n`);\n adapter.close();\n process.exit(1);\n }\n\n adapter.close();\n}\n","/**\n * CLI command handlers for aaac-observ.\n *\n * Implements the CommandHandlers interface generated by cli-contracts and\n * delegates to the domain-specific handler modules.\n *\n * Usage (in index.ts):\n * import { handlers } from './handlers.js';\n * import { createProgram } from '../generated/program.js';\n * const program = createProgram(handlers, version);\n * await program.parseAsync();\n */\nimport type { CommandHandlers } from \"../generated/program.js\";\nimport { handleRecord } from \"./record.js\";\nimport { handleRecordHook } from \"./record-hook.js\";\nimport { handleQuery } from \"./query.js\";\nimport { handleBackfill } from \"./backfill.js\";\nimport { handleIngestVendorOtel } from \"./ingest-vendor-otel.js\";\nimport { handleReport } from \"./report.js\";\n\nexport const handlers: CommandHandlers = {\n record: handleRecord,\n recordHook: handleRecordHook,\n query: handleQuery,\n backfill: handleBackfill,\n ingestVendorOtel: handleIngestVendorOtel,\n report: handleReport,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAOA,SAAS,oBAAoB;AAC7B,SAAS,SAAS,eAAe;AACjC,SAAS,qBAAqB;;;ACR9B,SAAS,eAAe;;;ACEjB,IAAM,gBAAwB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A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result","resolve","resolve","result"]}
|
|
1
|
+
{"version":3,"sources":["../../src/cli/index.ts","../../src/generated/program.ts","../../src/generated/contract.ts","../../src/cli/record.ts","../../src/cli/query.ts","../../src/cli/backfill.ts","../../src/cli/ingest-vendor-otel.ts","../../src/cli/report.ts","../../src/cli/handlers.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * aaac-observ CLI entry point.\n *\n * Reads the version from package.json, creates the generated Commander\n * program with hand-written handlers, and executes it.\n */\nimport { readFileSync } from \"node:fs\";\nimport { dirname, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n// Imported through the generated barrel — `cli-contracts generate` always emits\n// generated/index.ts as the entry point of the generated module set, so reaching\n// past it into generated/program.ts leaves the barrel (and everything only it\n// re-exports) unbuilt and unreachable (#287).\nimport { createProgram } from \"../generated/index.js\";\nimport { handlers } from \"./handlers.js\";\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\nconst manifest: unknown = JSON.parse(\n readFileSync(resolve(__dirname, \"../../package.json\"), \"utf8\"),\n);\n// This package's own manifest, but still bytes off disk: `as { version: string }`\n// promised a string and would have handed `createProgram` whatever was there.\nconst version =\n typeof manifest === \"object\" && manifest !== null\n ? (manifest as Record<string, unknown>).version\n : undefined;\nif (typeof version !== \"string\") {\n throw new Error(\"@aaac/observability package.json declares no string `version`\");\n}\n\nconst program = createProgram(handlers, version);\nawait program.parseAsync();\n","// Auto-generated by cli-contracts. Do not edit.\nimport { Command } from \"commander\";\nimport { CONTRACT_YAML, CONTRACT_JSON_STR } from \"./contract.js\";\n\nexport interface CommandHandlers {\n record: (options: { eventType?: string; lifecycle?: string; spanId?: string; parentSpanId?: string; sessionId?: string; traceId?: string; source?: string; attr?: string; link?: string; db?: string }, parentOpts: Record<string, unknown>) => Promise<void>;\n recordHook: (hookName: string | undefined, options: { mappingConfig?: string; db?: string }, parentOpts: Record<string, unknown>) => Promise<void>;\n backfill: (options: { db?: string; endpoint?: string; serviceName?: string; from?: string; to?: string; eventType?: string; dryRun?: boolean; flushTimeoutMs?: string }, parentOpts: Record<string, unknown>) => Promise<void>;\n ingestVendorOtel: (options: { db?: string; input?: string; source?: string; dryRun?: boolean }, parentOpts: Record<string, unknown>) => Promise<void>;\n query: (options: { kind?: string; issue?: string; traceId?: string; spanId?: string; eventType?: string; taskId?: string; from?: string; to?: string; direction?: string; db?: string }, parentOpts: Record<string, unknown>) => Promise<void>;\n report: (options: { projectId?: string; from?: string; to?: string; baselineFrom?: string; baselineTo?: string; format?: string; db?: string }, parentOpts: Record<string, unknown>) => Promise<void>;\n}\n\nexport function createProgram(\n handlers: CommandHandlers,\n version: string,\n): Command {\n const program = new Command();\n program\n .name(\"aaac-observ\")\n .version(version, \"-V, --version\")\n .description(\"aaac-observ — register external events and query the observability store\");\n\n\n program\n .command(\"record\")\n .description(\"Register an external event into the observability pipeline (thin entrypoint for EventCollector.registerExternalEvent)\")\n .option(\"-t, --event-type <value>\", \"Event type (e.g. promotion.commit, process.edit, agent.session)\")\n .option(\"-l, --lifecycle <value>\", \"Event lifecycle phase: open | close | event | instant\")\n .option(\"-s, --span-id <value>\", \"Span ID (auto-generated if omitted)\")\n .option(\"--parent-span-id <value>\", \"Parent span ID for hierarchy\")\n .option(\"--session-id <value>\", \"Session ID to associate with the event\")\n .option(\"--trace-id <value>\", \"Trace ID for distributed tracing\")\n .option(\"--source <value>\", \"Event source identifier (default: external)\")\n .option(\"--attr <value>\", \"Attribute as key=value (repeatable, e.g. --attr git.commit=abc123)\")\n .option(\"--link <value>\", \"Cross-axis link as targetSpanId:linkType[:targetTraceId] (repeatable)\")\n .option(\"--db <value>\", \"Path to observability SQLite database (overrides default)\")\n .action(async (opts, cmd) => {\n await handlers.record(opts, cmd.optsWithGlobals());\n });\n\n program\n .command(\"record-hook\")\n .description(\"Record a Cursor/git hook event — parses stdin JSON, resolves event_mapping into 3-axis spans/links, injects session_id, and emits human-events (fail-open)\")\n .argument(\"<hook-name>\", \"Cursor/git hook name (e.g. afterFileEdit, subagentStart, beforeShellExecution)\")\n .option(\"--mapping-config <value>\", \"Path to event-mapping.json (default: .agent-logs/config/event-mapping.json)\")\n .option(\"--db <value>\", \"Path to observability SQLite database (overrides default)\")\n .action(async (hookName, opts, cmd) => {\n await handlers.recordHook(hookName, opts, cmd.optsWithGlobals());\n });\n\n program\n .command(\"backfill\")\n .description(\"Re-emit historical spans from SQLite to an OTLP backend\")\n .option(\"--db <value>\", \"Path to observability SQLite database (overrides default)\")\n .option(\"--endpoint <value>\", \"OTLP HTTP endpoint URL (fallback: OTEL_EXPORTER_OTLP_ENDPOINT)\")\n .option(\"--service-name <value>\", \"OTEL service name reported to backend (default: @aaac/observability)\")\n .option(\"--from <value>\", \"Backfill spans starting at or after this ISO 8601 time\")\n .option(\"--to <value>\", \"Backfill spans starting at or before this ISO 8601 time\")\n .option(\"--event-type <value>\", \"Filter by event type (e.g. agent.session)\")\n .option(\"--dry-run\", \"Print span count without emitting to OTLP backend\")\n .option(\"--flush-timeout-ms <value>\", \"Maximum ms to wait for OTLP flush before exit (default: 2000; use ≥30000 for >5k spans)\")\n .action(async (opts, cmd) => {\n await handlers.backfill(opts, cmd.optsWithGlobals());\n });\n\n program\n .command(\"ingest-vendor-otel\")\n .description(\"Project a vendor OTLP/JSON trace export (e.g. Claude Code token/cost/trace) into the SQLite Ledger\")\n .option(\"--db <value>\", \"Path to observability SQLite database (overrides default)\")\n .option(\"-i, --input <value>\", \"Path to the OTLP/JSON trace export (reads stdin when omitted)\")\n .option(\"--source <value>\", \"Source tag for projected events (default: claude-code-otel)\")\n .option(\"--dry-run\", \"Parse and project without writing to the Ledger\")\n .action(async (opts, cmd) => {\n await handlers.ingestVendorOtel(opts, cmd.optsWithGlobals());\n });\n\n program\n .command(\"query\")\n .description(\"Query the observability store via QueryAdapter\")\n .option(\"-k, --kind <value>\", \"Query kind: trace | span | search | links | issue (optional when --issue is set)\")\n .option(\"--issue <value>\", \"Issue ID — implies --kind issue when --kind is omitted\")\n .option(\"--trace-id <value>\", \"Trace ID for trace queries (--kind trace)\")\n .option(\"-s, --span-id <value>\", \"Span ID for span/links queries (--kind span or --kind links)\")\n .option(\"--event-type <value>\", \"Event type filter for search queries (--kind search)\")\n .option(\"--task-id <value>\", \"Task ID filter for search queries (--kind search)\")\n .option(\"--from <value>\", \"Start time in ISO 8601 format for search queries (--kind search)\")\n .option(\"--to <value>\", \"End time in ISO 8601 format for search queries (--kind search)\")\n .option(\"-d, --direction <value>\", \"Link traversal direction for links queries (default: both)\")\n .option(\"--db <value>\", \"Path to observability SQLite database (overrides default)\")\n .action(async (opts, cmd) => {\n await handlers.query(opts, cmd.optsWithGlobals());\n });\n\n program\n .command(\"report\")\n .description(\"Generate an Observability diagnostic report (Layer 1-3 + link completion + Person Tier) from the SQLite Ledger\")\n .option(\"-p, --project-id <value>\", \"Restrict the report to a single project_id (project.id attr / service.name)\")\n .option(\"--from <value>\", \"Start time (ISO 8601) for the current/after window\")\n .option(\"--to <value>\", \"End time (ISO 8601) for the current/after window\")\n .option(\"--baseline-from <value>\", \"Start time (ISO 8601) of the baseline/before window (enables Before/After comparison)\")\n .option(\"--baseline-to <value>\", \"End time (ISO 8601) of the baseline/before window (enables Before/After comparison)\")\n .option(\"-f, --format <value>\", \"Output format: markdown (default) | json\")\n .option(\"--db <value>\", \"Path to observability SQLite database (overrides default)\")\n .action(async (opts, cmd) => {\n await handlers.report(opts, cmd.optsWithGlobals());\n });\n\n\n // Built-in extract command (auto-injected by cli-contracts)\n program\n .command(\"extract\")\n .description(\"Extract contract specification for this CLI tool.\")\n .argument(\"[commands...]\", \"Command IDs to extract. Use dot notation.\")\n .option(\"-a, --all\", \"Extract all commands.\", false)\n .option(\"--include-meta\", \"Include extraction metadata.\", true)\n .option(\"-F, --format <format>\", \"Output format (yaml or json).\", \"yaml\")\n .action(async (commands: string[], opts: { all?: boolean; includeMeta?: boolean; format?: string }, cmd: Command) => {\n if (commands.length === 0 && !opts.all) {\n process.stderr.write(JSON.stringify({ code: \"INVALID_ARGS\", message: \"Specify command IDs or use --all\" }) + \"\\n\");\n process.exit(2);\n }\n\n const format = opts.format || \"yaml\";\n const doc = JSON.parse(CONTRACT_JSON_STR);\n const cmdIds = opts.all ? [] : commands;\n\n if (cmdIds.length === 0) {\n // --all: output full contract\n if (format === \"json\") {\n const out: Record<string, unknown> = {};\n if (opts.includeMeta) {\n out._meta = {\n source: \"embedded\",\n type: \"cli-contracts/extract\",\n extractedAt: new Date().toISOString(),\n specVersion: doc.cli_contracts ?? \"0.1.0\",\n commands: [\"aaac-observ.record\",\"aaac-observ.record-hook\",\"aaac-observ.backfill\",\"aaac-observ.ingest-vendor-otel\",\"aaac-observ.query\",\"aaac-observ.report\"],\n };\n }\n Object.assign(out, doc);\n process.stdout.write(JSON.stringify(out, null, 2) + \"\\n\");\n } else {\n // YAML output\n const yamlLines: string[] = [];\n yamlLines.push(\"# aaac-observ extract\");\n yamlLines.push(\"# source: embedded\");\n yamlLines.push(\"# type: cli-contracts/command-extract\");\n if (opts.includeMeta) {\n yamlLines.push(\"---\");\n yamlLines.push(\"source: embedded\");\n yamlLines.push(\"type: cli-contracts/command-extract\");\n yamlLines.push(\"extractedAt: \" + new Date().toISOString());\n yamlLines.push(\"spec_version: \" + (doc.cli_contracts ?? \"0.1.0\"));\n yamlLines.push(\"commands:\");\n for (const id of [\"aaac-observ.record\",\"aaac-observ.record-hook\",\"aaac-observ.backfill\",\"aaac-observ.ingest-vendor-otel\",\"aaac-observ.query\",\"aaac-observ.report\"]) {\n yamlLines.push(\" - \" + id);\n }\n }\n yamlLines.push(\"---\");\n yamlLines.push(CONTRACT_YAML);\n process.stdout.write(yamlLines.join(\"\\n\") + \"\\n\");\n }\n } else {\n // Filter specific commands\n const filtered: Record<string, unknown> = {\n cli_contracts: doc.cli_contracts,\n info: doc.info,\n command_sets: {},\n };\n const fcs = filtered.command_sets as Record<string, Record<string, unknown>>;\n for (const [setId, cs] of Object.entries(doc.command_sets ?? {})) {\n const cmds = (cs as Record<string, unknown>).commands as Record<string, unknown> | undefined;\n if (!cmds) continue;\n const matched: Record<string, unknown> = {};\n for (const [cmdId, cmdDef] of Object.entries(cmds)) {\n const fullId = setId + \".\" + cmdId;\n if (cmdIds.some((id) => id === cmdId || id === fullId || cmdId.startsWith(id + \".\"))) {\n matched[cmdId] = cmdDef;\n }\n }\n if (Object.keys(matched).length > 0) {\n const setCopy = { ...(cs as Record<string, unknown>) };\n setCopy.commands = matched;\n fcs[setId] = setCopy;\n }\n }\n if (doc.components) filtered.components = doc.components;\n process.stdout.write(JSON.stringify(filtered, null, 2) + \"\\n\");\n }\n process.exit(0);\n });\n return program;\n}\n","// Auto-generated by cli-contracts. Do not edit.\n// Embedded contract for the extract subcommand.\n\nexport const CONTRACT_YAML: string = \"# yaml-language-server: $schema=./node_modules/cli-contracts/schemas/cli-contract.schema.json\\ncli_contracts: 0.1.0\\n\\ninfo:\\n title: AaaC Observability CLI\\n version: 0.1.0\\n description: aaac-observ — external event registration and query for @aaac/observability\\n\\ncommand_sets:\\n aaac-observ:\\n summary: aaac-observ — register external events and query the observability store\\n executable: aaac-observ\\n commands:\\n record:\\n summary: Register an external event into the observability pipeline (thin entrypoint for EventCollector.registerExternalEvent)\\n options:\\n - name: event-type\\n aliases: [t]\\n schema: { type: string }\\n description: \\\"Event type (e.g. promotion.commit, process.edit, agent.session)\\\"\\n - name: lifecycle\\n aliases: [l]\\n schema:\\n type: string\\n enum: [open, close, event, instant]\\n description: \\\"Event lifecycle phase: open | close | event | instant\\\"\\n - name: span-id\\n aliases: [s]\\n schema: { type: string }\\n description: Span ID (auto-generated if omitted)\\n - name: parent-span-id\\n schema: { type: string }\\n description: Parent span ID for hierarchy\\n - name: session-id\\n schema: { type: string }\\n description: Session ID to associate with the event\\n - name: trace-id\\n schema: { type: string }\\n description: Trace ID for distributed tracing\\n - name: source\\n schema: { type: string }\\n description: \\\"Event source identifier (default: external)\\\"\\n - name: attr\\n schema:\\n type: array\\n items: { type: string }\\n description: \\\"Attribute as key=value (repeatable, e.g. --attr git.commit=abc123)\\\"\\n - name: link\\n schema:\\n type: array\\n items: { type: string }\\n description: \\\"Cross-axis link as targetSpanId:linkType[:targetTraceId] (repeatable)\\\"\\n - name: db\\n schema: { type: string }\\n description: Path to observability SQLite database (overrides default)\\n exits:\\n '0':\\n description: Event registered successfully\\n stdout:\\n format: json\\n schema:\\n type: object\\n properties:\\n eventId:\\n type: string\\n spanId:\\n type: string\\n '1':\\n description: Registration failed (validation error or write error)\\n stderr:\\n format: text\\n\\n record-hook:\\n summary: Record a Cursor/git hook event — parses stdin JSON, resolves event_mapping into 3-axis spans/links, injects session_id, and emits human-events (fail-open)\\n arguments:\\n - name: hook-name\\n index: 0\\n required: true\\n schema: { type: string }\\n description: \\\"Cursor/git hook name (e.g. afterFileEdit, subagentStart, beforeShellExecution)\\\"\\n options:\\n - name: mapping-config\\n schema: { type: string }\\n description: \\\"Path to event-mapping.json (default: .agent-logs/config/event-mapping.json)\\\"\\n - name: db\\n schema: { type: string }\\n description: Path to observability SQLite database (overrides default)\\n exits:\\n '0':\\n description: Hook recorded (or no-op when stdin/mapping unavailable) — always fail-open\\n stdout:\\n format: json\\n schema:\\n type: object\\n properties:\\n recorded:\\n type: integer\\n fallback:\\n type: boolean\\n\\n backfill:\\n summary: Re-emit historical spans from SQLite to an OTLP backend\\n description: |\\n Reads closed/instant spans from the local SQLite database and emits them\\n via OtelEmitter to an OTLP-compatible backend.\\n\\n IMPORTANT — idempotency: The OTel SDK does not support specifying custom\\n spanIds, so each backfill invocation creates NEW spans in the backend.\\n Repeated invocations will produce DUPLICATE data. Use --from/--to to\\n control scope. See #125 §7 for full idempotency guidance.\\n options:\\n - name: db\\n schema: { type: string }\\n description: Path to observability SQLite database (overrides default)\\n - name: endpoint\\n schema: { type: string }\\n description: \\\"OTLP HTTP endpoint URL (fallback: OTEL_EXPORTER_OTLP_ENDPOINT)\\\"\\n - name: service-name\\n schema: { type: string }\\n description: \\\"OTEL service name reported to backend (default: @aaac/observability)\\\"\\n - name: from\\n schema: { type: string }\\n description: Backfill spans starting at or after this ISO 8601 time\\n - name: to\\n schema: { type: string }\\n description: Backfill spans starting at or before this ISO 8601 time\\n - name: event-type\\n schema: { type: string }\\n description: \\\"Filter by event type (e.g. agent.session)\\\"\\n - name: dry-run\\n schema: { type: boolean }\\n description: Print span count without emitting to OTLP backend\\n - name: flush-timeout-ms\\n schema: { type: integer }\\n description: \\\"Maximum ms to wait for OTLP flush before exit (default: 2000; use ≥30000 for >5k spans)\\\"\\n exits:\\n '0':\\n description: Backfill completed\\n stdout:\\n format: json\\n schema:\\n type: object\\n properties:\\n spansFound:\\n type: integer\\n spansEmitted:\\n type: integer\\n dryRun:\\n type: boolean\\n '1':\\n description: Backfill failed (missing endpoint, DB error, etc.)\\n stderr:\\n format: text\\n\\n ingest-vendor-otel:\\n summary: Project a vendor OTLP/JSON trace export (e.g. Claude Code token/cost/trace) into the SQLite Ledger\\n description: |\\n Canonical Projection batch (observability-integration.md §9.2 / T-D2).\\n\\n Reads a vendor OTLP/JSON trace export from --input (file) or stdin, projects\\n each span into a Canonical Event, and backfills it into the SQLite Ledger.\\n\\n Idempotent: every event carries a deterministic dedup_key\\n (vendor-otel:{traceId}:{spanId}) enforced by UNIQUE + INSERT OR IGNORE, so\\n re-running on the same export inserts nothing new (reported as\\n skippedDuplicate). Hook/runtime records remain the primary source; vendor\\n OTEL is auxiliary evidence.\\n options:\\n - name: db\\n schema: { type: string }\\n description: Path to observability SQLite database (overrides default)\\n - name: input\\n aliases: [i]\\n schema: { type: string }\\n description: \\\"Path to the OTLP/JSON trace export (reads stdin when omitted)\\\"\\n - name: source\\n schema: { type: string }\\n description: \\\"Source tag for projected events (default: claude-code-otel)\\\"\\n - name: dry-run\\n schema: { type: boolean }\\n description: Parse and project without writing to the Ledger\\n exits:\\n '0':\\n description: Ingestion completed\\n stdout:\\n format: json\\n schema:\\n type: object\\n properties:\\n found:\\n type: integer\\n inserted:\\n type: integer\\n skippedDuplicate:\\n type: integer\\n skippedInvalid:\\n type: integer\\n dryRun:\\n type: boolean\\n '1':\\n description: Ingestion failed (unreadable input, invalid JSON, DB error)\\n stderr:\\n format: text\\n\\n query:\\n summary: Query the observability store via QueryAdapter\\n options:\\n - name: kind\\n aliases: [k]\\n schema:\\n type: string\\n enum: [trace, span, search, links, issue]\\n description: \\\"Query kind: trace | span | search | links | issue (optional when --issue is set)\\\"\\n - name: issue\\n schema: { type: string }\\n description: \\\"Issue ID — implies --kind issue when --kind is omitted\\\"\\n - name: trace-id\\n schema: { type: string }\\n description: Trace ID for trace queries (--kind trace)\\n - name: span-id\\n aliases: [s]\\n schema: { type: string }\\n description: Span ID for span/links queries (--kind span or --kind links)\\n - name: event-type\\n schema: { type: string }\\n description: Event type filter for search queries (--kind search)\\n - name: task-id\\n schema: { type: string }\\n description: Task ID filter for search queries (--kind search)\\n - name: from\\n schema: { type: string }\\n description: Start time in ISO 8601 format for search queries (--kind search)\\n - name: to\\n schema: { type: string }\\n description: End time in ISO 8601 format for search queries (--kind search)\\n - name: direction\\n aliases: [d]\\n schema:\\n type: string\\n enum: [forward, reverse, both]\\n description: \\\"Link traversal direction for links queries (default: both)\\\"\\n - name: db\\n schema: { type: string }\\n description: Path to observability SQLite database (overrides default)\\n exits:\\n '0':\\n description: Query succeeded — results as JSON array\\n stdout:\\n format: json\\n schema:\\n type: object\\n '1':\\n description: Query failed\\n stderr:\\n format: text\\n\\n report:\\n summary: Generate an Observability diagnostic report (Layer 1-3 + link completion + Person Tier) from the SQLite Ledger\\n description: |\\n Customer-facing Observability diagnostic (#179 WS-F T-F1). Computes the\\n same Layer 1-3 / link-completion / Person-Tier metrics rendered by the\\n `aaac-diagnostic` Grafana dashboard, over the local SQLite Ledger.\\n\\n Output is Markdown (default) or JSON. Use --project-id to scope to a\\n single project (internal or a cooperating customer project). Supply\\n --baseline-from / --baseline-to to add a Before/After comparison\\n section against a baseline window; --from / --to bound the current\\n (after) window.\\n options:\\n - name: project-id\\n aliases: [p]\\n schema: { type: string }\\n description: Restrict the report to a single project_id (project.id attr / service.name)\\n - name: from\\n schema: { type: string }\\n description: Start time (ISO 8601) for the current/after window\\n - name: to\\n schema: { type: string }\\n description: End time (ISO 8601) for the current/after window\\n - name: baseline-from\\n schema: { type: string }\\n description: Start time (ISO 8601) of the baseline/before window (enables Before/After comparison)\\n - name: baseline-to\\n schema: { type: string }\\n description: End time (ISO 8601) of the baseline/before window (enables Before/After comparison)\\n - name: format\\n aliases: [f]\\n schema:\\n type: string\\n enum: [markdown, json]\\n description: \\\"Output format: markdown (default) | json\\\"\\n - name: db\\n schema: { type: string }\\n description: Path to observability SQLite database (overrides default)\\n exits:\\n '0':\\n description: Report generated — Markdown or JSON on stdout\\n stdout:\\n format: text\\n '1':\\n description: Report generation failed\\n stderr:\\n format: text\\n\";\n\nexport const CONTRACT_JSON_STR: string = \"{\\n \\\"cli_contracts\\\": \\\"0.1.0\\\",\\n \\\"info\\\": {\\n \\\"title\\\": \\\"AaaC Observability CLI\\\",\\n \\\"version\\\": \\\"0.1.0\\\",\\n \\\"description\\\": \\\"aaac-observ — external event registration and query for @aaac/observability\\\"\\n },\\n \\\"command_sets\\\": {\\n \\\"aaac-observ\\\": {\\n \\\"summary\\\": \\\"aaac-observ — register external events and query the observability store\\\",\\n \\\"executable\\\": \\\"aaac-observ\\\",\\n \\\"commands\\\": {\\n \\\"record\\\": {\\n \\\"summary\\\": \\\"Register an external event into the observability pipeline (thin entrypoint for EventCollector.registerExternalEvent)\\\",\\n \\\"options\\\": [\\n {\\n \\\"name\\\": \\\"event-type\\\",\\n \\\"aliases\\\": [\\n \\\"t\\\"\\n ],\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Event type (e.g. promotion.commit, process.edit, agent.session)\\\"\\n },\\n {\\n \\\"name\\\": \\\"lifecycle\\\",\\n \\\"aliases\\\": [\\n \\\"l\\\"\\n ],\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\",\\n \\\"enum\\\": [\\n \\\"open\\\",\\n \\\"close\\\",\\n \\\"event\\\",\\n \\\"instant\\\"\\n ]\\n },\\n \\\"description\\\": \\\"Event lifecycle phase: open | close | event | instant\\\"\\n },\\n {\\n \\\"name\\\": \\\"span-id\\\",\\n \\\"aliases\\\": [\\n \\\"s\\\"\\n ],\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Span ID (auto-generated if omitted)\\\"\\n },\\n {\\n \\\"name\\\": \\\"parent-span-id\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Parent span ID for hierarchy\\\"\\n },\\n {\\n \\\"name\\\": \\\"session-id\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Session ID to associate with the event\\\"\\n },\\n {\\n \\\"name\\\": \\\"trace-id\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Trace ID for distributed tracing\\\"\\n },\\n {\\n \\\"name\\\": \\\"source\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Event source identifier (default: external)\\\"\\n },\\n {\\n \\\"name\\\": \\\"attr\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"array\\\",\\n \\\"items\\\": {\\n \\\"type\\\": \\\"string\\\"\\n }\\n },\\n \\\"description\\\": \\\"Attribute as key=value (repeatable, e.g. --attr git.commit=abc123)\\\"\\n },\\n {\\n \\\"name\\\": \\\"link\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"array\\\",\\n \\\"items\\\": {\\n \\\"type\\\": \\\"string\\\"\\n }\\n },\\n \\\"description\\\": \\\"Cross-axis link as targetSpanId:linkType[:targetTraceId] (repeatable)\\\"\\n },\\n {\\n \\\"name\\\": \\\"db\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Path to observability SQLite database (overrides default)\\\"\\n }\\n ],\\n \\\"exits\\\": {\\n \\\"0\\\": {\\n \\\"description\\\": \\\"Event registered successfully\\\",\\n \\\"stdout\\\": {\\n \\\"format\\\": \\\"json\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"object\\\",\\n \\\"properties\\\": {\\n \\\"eventId\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"spanId\\\": {\\n \\\"type\\\": \\\"string\\\"\\n }\\n }\\n }\\n }\\n },\\n \\\"1\\\": {\\n \\\"description\\\": \\\"Registration failed (validation error or write error)\\\",\\n \\\"stderr\\\": {\\n \\\"format\\\": \\\"text\\\"\\n }\\n }\\n }\\n },\\n \\\"record-hook\\\": {\\n \\\"summary\\\": \\\"Record a Cursor/git hook event — parses stdin JSON, resolves event_mapping into 3-axis spans/links, injects session_id, and emits human-events (fail-open)\\\",\\n \\\"arguments\\\": [\\n {\\n \\\"name\\\": \\\"hook-name\\\",\\n \\\"index\\\": 0,\\n \\\"required\\\": true,\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Cursor/git hook name (e.g. afterFileEdit, subagentStart, beforeShellExecution)\\\"\\n }\\n ],\\n \\\"options\\\": [\\n {\\n \\\"name\\\": \\\"mapping-config\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Path to event-mapping.json (default: .agent-logs/config/event-mapping.json)\\\"\\n },\\n {\\n \\\"name\\\": \\\"db\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Path to observability SQLite database (overrides default)\\\"\\n }\\n ],\\n \\\"exits\\\": {\\n \\\"0\\\": {\\n \\\"description\\\": \\\"Hook recorded (or no-op when stdin/mapping unavailable) — always fail-open\\\",\\n \\\"stdout\\\": {\\n \\\"format\\\": \\\"json\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"object\\\",\\n \\\"properties\\\": {\\n \\\"recorded\\\": {\\n \\\"type\\\": \\\"integer\\\"\\n },\\n \\\"fallback\\\": {\\n \\\"type\\\": \\\"boolean\\\"\\n }\\n }\\n }\\n }\\n }\\n }\\n },\\n \\\"backfill\\\": {\\n \\\"summary\\\": \\\"Re-emit historical spans from SQLite to an OTLP backend\\\",\\n \\\"description\\\": \\\"Reads closed/instant spans from the local SQLite database and emits them\\\\nvia OtelEmitter to an OTLP-compatible backend.\\\\n\\\\nIMPORTANT — idempotency: The OTel SDK does not support specifying custom\\\\nspanIds, so each backfill invocation creates NEW spans in the backend.\\\\nRepeated invocations will produce DUPLICATE data. Use --from/--to to\\\\ncontrol scope. See #125 §7 for full idempotency guidance.\\\\n\\\",\\n \\\"options\\\": [\\n {\\n \\\"name\\\": \\\"db\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Path to observability SQLite database (overrides default)\\\"\\n },\\n {\\n \\\"name\\\": \\\"endpoint\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"OTLP HTTP endpoint URL (fallback: OTEL_EXPORTER_OTLP_ENDPOINT)\\\"\\n },\\n {\\n \\\"name\\\": \\\"service-name\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"OTEL service name reported to backend (default: @aaac/observability)\\\"\\n },\\n {\\n \\\"name\\\": \\\"from\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Backfill spans starting at or after this ISO 8601 time\\\"\\n },\\n {\\n \\\"name\\\": \\\"to\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Backfill spans starting at or before this ISO 8601 time\\\"\\n },\\n {\\n \\\"name\\\": \\\"event-type\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Filter by event type (e.g. agent.session)\\\"\\n },\\n {\\n \\\"name\\\": \\\"dry-run\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"boolean\\\"\\n },\\n \\\"description\\\": \\\"Print span count without emitting to OTLP backend\\\"\\n },\\n {\\n \\\"name\\\": \\\"flush-timeout-ms\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"integer\\\"\\n },\\n \\\"description\\\": \\\"Maximum ms to wait for OTLP flush before exit (default: 2000; use ≥30000 for >5k spans)\\\"\\n }\\n ],\\n \\\"exits\\\": {\\n \\\"0\\\": {\\n \\\"description\\\": \\\"Backfill completed\\\",\\n \\\"stdout\\\": {\\n \\\"format\\\": \\\"json\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"object\\\",\\n \\\"properties\\\": {\\n \\\"spansFound\\\": {\\n \\\"type\\\": \\\"integer\\\"\\n },\\n \\\"spansEmitted\\\": {\\n \\\"type\\\": \\\"integer\\\"\\n },\\n \\\"dryRun\\\": {\\n \\\"type\\\": \\\"boolean\\\"\\n }\\n }\\n }\\n }\\n },\\n \\\"1\\\": {\\n \\\"description\\\": \\\"Backfill failed (missing endpoint, DB error, etc.)\\\",\\n \\\"stderr\\\": {\\n \\\"format\\\": \\\"text\\\"\\n }\\n }\\n }\\n },\\n \\\"ingest-vendor-otel\\\": {\\n \\\"summary\\\": \\\"Project a vendor OTLP/JSON trace export (e.g. Claude Code token/cost/trace) into the SQLite Ledger\\\",\\n \\\"description\\\": \\\"Canonical Projection batch (observability-integration.md §9.2 / T-D2).\\\\n\\\\nReads a vendor OTLP/JSON trace export from --input (file) or stdin, projects\\\\neach span into a Canonical Event, and backfills it into the SQLite Ledger.\\\\n\\\\nIdempotent: every event carries a deterministic dedup_key\\\\n(vendor-otel:{traceId}:{spanId}) enforced by UNIQUE + INSERT OR IGNORE, so\\\\nre-running on the same export inserts nothing new (reported as\\\\nskippedDuplicate). Hook/runtime records remain the primary source; vendor\\\\nOTEL is auxiliary evidence.\\\\n\\\",\\n \\\"options\\\": [\\n {\\n \\\"name\\\": \\\"db\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Path to observability SQLite database (overrides default)\\\"\\n },\\n {\\n \\\"name\\\": \\\"input\\\",\\n \\\"aliases\\\": [\\n \\\"i\\\"\\n ],\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Path to the OTLP/JSON trace export (reads stdin when omitted)\\\"\\n },\\n {\\n \\\"name\\\": \\\"source\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Source tag for projected events (default: claude-code-otel)\\\"\\n },\\n {\\n \\\"name\\\": \\\"dry-run\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"boolean\\\"\\n },\\n \\\"description\\\": \\\"Parse and project without writing to the Ledger\\\"\\n }\\n ],\\n \\\"exits\\\": {\\n \\\"0\\\": {\\n \\\"description\\\": \\\"Ingestion completed\\\",\\n \\\"stdout\\\": {\\n \\\"format\\\": \\\"json\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"object\\\",\\n \\\"properties\\\": {\\n \\\"found\\\": {\\n \\\"type\\\": \\\"integer\\\"\\n },\\n \\\"inserted\\\": {\\n \\\"type\\\": \\\"integer\\\"\\n },\\n \\\"skippedDuplicate\\\": {\\n \\\"type\\\": \\\"integer\\\"\\n },\\n \\\"skippedInvalid\\\": {\\n \\\"type\\\": \\\"integer\\\"\\n },\\n \\\"dryRun\\\": {\\n \\\"type\\\": \\\"boolean\\\"\\n }\\n }\\n }\\n }\\n },\\n \\\"1\\\": {\\n \\\"description\\\": \\\"Ingestion failed (unreadable input, invalid JSON, DB error)\\\",\\n \\\"stderr\\\": {\\n \\\"format\\\": \\\"text\\\"\\n }\\n }\\n }\\n },\\n \\\"query\\\": {\\n \\\"summary\\\": \\\"Query the observability store via QueryAdapter\\\",\\n \\\"options\\\": [\\n {\\n \\\"name\\\": \\\"kind\\\",\\n \\\"aliases\\\": [\\n \\\"k\\\"\\n ],\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\",\\n \\\"enum\\\": [\\n \\\"trace\\\",\\n \\\"span\\\",\\n \\\"search\\\",\\n \\\"links\\\",\\n \\\"issue\\\"\\n ]\\n },\\n \\\"description\\\": \\\"Query kind: trace | span | search | links | issue (optional when --issue is set)\\\"\\n },\\n {\\n \\\"name\\\": \\\"issue\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Issue ID — implies --kind issue when --kind is omitted\\\"\\n },\\n {\\n \\\"name\\\": \\\"trace-id\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Trace ID for trace queries (--kind trace)\\\"\\n },\\n {\\n \\\"name\\\": \\\"span-id\\\",\\n \\\"aliases\\\": [\\n \\\"s\\\"\\n ],\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Span ID for span/links queries (--kind span or --kind links)\\\"\\n },\\n {\\n \\\"name\\\": \\\"event-type\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Event type filter for search queries (--kind search)\\\"\\n },\\n {\\n \\\"name\\\": \\\"task-id\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Task ID filter for search queries (--kind search)\\\"\\n },\\n {\\n \\\"name\\\": \\\"from\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Start time in ISO 8601 format for search queries (--kind search)\\\"\\n },\\n {\\n \\\"name\\\": \\\"to\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"End time in ISO 8601 format for search queries (--kind search)\\\"\\n },\\n {\\n \\\"name\\\": \\\"direction\\\",\\n \\\"aliases\\\": [\\n \\\"d\\\"\\n ],\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\",\\n \\\"enum\\\": [\\n \\\"forward\\\",\\n \\\"reverse\\\",\\n \\\"both\\\"\\n ]\\n },\\n \\\"description\\\": \\\"Link traversal direction for links queries (default: both)\\\"\\n },\\n {\\n \\\"name\\\": \\\"db\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Path to observability SQLite database (overrides default)\\\"\\n }\\n ],\\n \\\"exits\\\": {\\n \\\"0\\\": {\\n \\\"description\\\": \\\"Query succeeded — results as JSON array\\\",\\n \\\"stdout\\\": {\\n \\\"format\\\": \\\"json\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"object\\\"\\n }\\n }\\n },\\n \\\"1\\\": {\\n \\\"description\\\": \\\"Query failed\\\",\\n \\\"stderr\\\": {\\n \\\"format\\\": \\\"text\\\"\\n }\\n }\\n }\\n },\\n \\\"report\\\": {\\n \\\"summary\\\": \\\"Generate an Observability diagnostic report (Layer 1-3 + link completion + Person Tier) from the SQLite Ledger\\\",\\n \\\"description\\\": \\\"Customer-facing Observability diagnostic (#179 WS-F T-F1). Computes the\\\\nsame Layer 1-3 / link-completion / Person-Tier metrics rendered by the\\\\n`aaac-diagnostic` Grafana dashboard, over the local SQLite Ledger.\\\\n\\\\nOutput is Markdown (default) or JSON. Use --project-id to scope to a\\\\nsingle project (internal or a cooperating customer project). Supply\\\\n--baseline-from / --baseline-to to add a Before/After comparison\\\\nsection against a baseline window; --from / --to bound the current\\\\n(after) window.\\\\n\\\",\\n \\\"options\\\": [\\n {\\n \\\"name\\\": \\\"project-id\\\",\\n \\\"aliases\\\": [\\n \\\"p\\\"\\n ],\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Restrict the report to a single project_id (project.id attr / service.name)\\\"\\n },\\n {\\n \\\"name\\\": \\\"from\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Start time (ISO 8601) for the current/after window\\\"\\n },\\n {\\n \\\"name\\\": \\\"to\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"End time (ISO 8601) for the current/after window\\\"\\n },\\n {\\n \\\"name\\\": \\\"baseline-from\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Start time (ISO 8601) of the baseline/before window (enables Before/After comparison)\\\"\\n },\\n {\\n \\\"name\\\": \\\"baseline-to\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"End time (ISO 8601) of the baseline/before window (enables Before/After comparison)\\\"\\n },\\n {\\n \\\"name\\\": \\\"format\\\",\\n \\\"aliases\\\": [\\n \\\"f\\\"\\n ],\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\",\\n \\\"enum\\\": [\\n \\\"markdown\\\",\\n \\\"json\\\"\\n ]\\n },\\n \\\"description\\\": \\\"Output format: markdown (default) | json\\\"\\n },\\n {\\n \\\"name\\\": \\\"db\\\",\\n \\\"schema\\\": {\\n \\\"type\\\": \\\"string\\\"\\n },\\n \\\"description\\\": \\\"Path to observability SQLite database (overrides default)\\\"\\n }\\n ],\\n \\\"exits\\\": {\\n \\\"0\\\": {\\n \\\"description\\\": \\\"Report generated — Markdown or JSON on stdout\\\",\\n \\\"stdout\\\": {\\n \\\"format\\\": \\\"text\\\"\\n }\\n },\\n \\\"1\\\": {\\n \\\"description\\\": \\\"Report generation failed\\\",\\n \\\"stderr\\\": {\\n \\\"format\\\": \\\"text\\\"\\n }\\n }\\n }\\n }\\n }\\n }\\n }\\n}\";\n","/**\n * record handler — thin entrypoint for EventCollector.registerExternalEvent.\n *\n * Wires the CLI options to the write pipeline:\n * options → EventCollector.registerExternalEvent\n * → Normalizer → Correlator → Enricher → SqliteSink + OtelEmitter\n *\n * architecture.md §9 / OBSERVABILITY_TASKS.md Phase 3-2\n * shift-left-event-mapping.md: aaac-observ record is the thin entrypoint\n */\nimport { createPipeline, generateId, DEFAULT_DB_PATH } from \"../index.js\";\nimport {\n isAttrMap,\n type CanonicalLink,\n type AttrValue,\n type Lifecycle,\n} from \"../types/canonical-event.js\";\n\n// ── Parsers ──────────────────────────────────────────────────────────────────\n\n/**\n * Parse comma-separated key=value attribute string into a Record.\n * Also accepts a JSON object string.\n *\n * Examples:\n * \"git.commit=abc123,git.branch=main\"\n * '{\"git.commit\":\"abc123\",\"git.branch\":\"main\"}'\n */\nexport function parseAttr(attrStr: string | undefined): Record<string, AttrValue> {\n if (!attrStr) return {};\n const trimmed = attrStr.trim();\n if (trimmed.startsWith(\"{\")) {\n try {\n const parsed: unknown = JSON.parse(trimmed);\n if (isAttrMap(parsed)) return parsed;\n // Parsed, but not a flat attribute map — the same answer unparseable\n // input gets: fall through to key=value parsing.\n } catch {\n // fall through to key=value parsing\n }\n }\n const result: Record<string, AttrValue> = {};\n for (const pair of trimmed.split(\",\")) {\n const eqIdx = pair.indexOf(\"=\");\n if (eqIdx > 0) {\n const key = pair.slice(0, eqIdx).trim();\n const val = pair.slice(eqIdx + 1).trim();\n result[key] = val;\n }\n }\n return result;\n}\n\n/**\n * Parse comma-separated link string into a CanonicalLink array.\n * Format per item: targetSpanId:linkType[:targetTraceId]\n *\n * Example: \"spanId123:materializes_as_commit,spanId456:contains_change:traceId789\"\n */\nexport function parseLinks(linkStr: string | undefined): CanonicalLink[] {\n if (!linkStr) return [];\n const links: CanonicalLink[] = [];\n for (const item of linkStr.split(\",\")) {\n const parts = item.trim().split(\":\");\n if (parts.length >= 2) {\n const targetSpanId = parts[0].trim();\n const linkType = parts[1].trim();\n const targetTraceId = parts[2]?.trim() || undefined;\n if (targetSpanId && linkType) {\n links.push({ targetSpanId, linkType, targetTraceId });\n }\n }\n }\n return links;\n}\n\n// ── Handler ──────────────────────────────────────────────────────────────────\n\n/**\n * Options as parsed from the generated CommandHandlers interface.\n * NOTE: attr and link are strings (last value from --option) not arrays,\n * because the generated Commander program does not use a collector.\n * Comma-separate multiple values: --attr \"key1=val1,key2=val2\"\n */\nexport interface RecordHandlerOptions {\n eventType?: string;\n lifecycle?: string;\n spanId?: string;\n parentSpanId?: string;\n sessionId?: string;\n traceId?: string;\n source?: string;\n attr?: string;\n link?: string;\n db?: string;\n}\n\n/**\n * Handle `aaac-observ record`.\n *\n * Required options: --event-type, --lifecycle\n * On success: writes the event through the full pipeline and prints\n * { eventId, spanId } to stdout.\n * On error: writes to stderr and exits with code 1.\n */\nexport async function handleRecord(\n options: RecordHandlerOptions,\n _parentOpts: Record<string, unknown>,\n): Promise<void> {\n // ── Validate required options ──────────────────────────────────────────────\n if (!options.eventType) {\n process.stderr.write(\"Error: --event-type (-t) is required\\n\");\n process.exit(1);\n }\n const validLifecycles: readonly string[] = [\"open\", \"close\", \"event\", \"instant\"];\n if (!options.lifecycle) {\n process.stderr.write(\n `Error: --lifecycle (-l) is required (${validLifecycles.join(\"|\")})\\n`,\n );\n process.exit(1);\n }\n if (!validLifecycles.includes(options.lifecycle)) {\n process.stderr.write(\n `Error: --lifecycle must be one of: ${validLifecycles.join(\"|\")}\\n`,\n );\n process.exit(1);\n }\n\n // ── Build event payload ────────────────────────────────────────────────────\n const dbPath = options.db ?? DEFAULT_DB_PATH;\n const spanId = options.spanId ?? generateId();\n const attributes = parseAttr(options.attr);\n const links = parseLinks(options.link);\n\n // Inject well-known scalars into attributes so the Normalizer picks them up\n if (options.sessionId) {\n attributes[\"session_id\"] = options.sessionId;\n }\n // trace_id stored as attribute for user reference; canonical traceId is\n // managed by Normalizer/Correlator (propagated via parentSpanId chain)\n if (options.traceId) {\n attributes[\"trace_id\"] = options.traceId;\n }\n\n // ── Build & execute pipeline ───────────────────────────────────────────────\n let capturedEventId: string | undefined;\n\n const { collector, sink } = createPipeline({\n dbPath,\n // Use afterCorrelate to capture the event id before it is written\n afterCorrelate: (event) => {\n capturedEventId = event.id;\n return event;\n },\n // Enable the default enrichment rules (R1–R5). This is the path the git\n // post-commit hook uses to record promotion.commit (close) with\n // committed_files; R5 (cross-axis) must run here to add the\n // materializes_as_commit link to task spans whose modified files intersect\n // the commit. R3/R4 accumulation persists in the SQLite-backed cache of the\n // same db file, so R5 sees it across the process boundary (#143 / #140).\n // Enricher is fail-open, so a rule error never blocks recording.\n });\n\n try {\n collector.registerExternalEvent({\n source: options.source ?? \"external\",\n eventType: options.eventType,\n lifecycle: options.lifecycle as Lifecycle,\n spanId,\n parentSpanId: options.parentSpanId,\n attributes,\n links,\n });\n } catch (err) {\n process.stderr.write(\n `Error: ${err instanceof Error ? err.message : String(err)}\\n`,\n );\n sink.close();\n process.exit(1);\n }\n\n sink.close();\n\n const result = { eventId: capturedEventId, spanId };\n process.stdout.write(JSON.stringify(result) + \"\\n\");\n}\n","/**\n * query handler — read path via QueryAdapter.\n *\n * Routes --kind to the appropriate SqliteQueryAdapter method and emits\n * results as JSON to stdout.\n *\n * Supported kinds:\n * trace → QueryAdapter.getTrace(--trace-id)\n * span → QueryAdapter.getSpan(--span-id) [+ QueryAdapter.getSpanEvents]\n * search → QueryAdapter.querySpans({ eventType, taskId, from, to })\n * links → QueryAdapter.getLinks(--span-id, --direction)\n * issue → analyzeOutcomeChain(--issue) [#178 T-E2]\n *\n * architecture.md §12 / OBSERVABILITY_TASKS.md Phase 3-2 (record CLI + query)\n */\nimport { SqliteQueryAdapter, DEFAULT_DB_PATH } from \"../index.js\";\nimport { isoToUnixNano } from \"../types/ids.js\";\nimport type { LinkDirection } from \"../query/models.js\";\nimport { analyzeOutcomeChain, OUTCOME_CHAIN_STAGES } from \"../analysis/outcome-chain.js\";\n\n// ── Handler ───────────────────────────────────────────────────────────────────\n\n/**\n * Options as parsed from the generated CommandHandlers interface.\n */\nexport interface QueryHandlerOptions {\n kind?: string;\n traceId?: string;\n spanId?: string;\n eventType?: string;\n taskId?: string;\n from?: string;\n to?: string;\n direction?: string;\n issue?: string;\n db?: string;\n}\n\n/** JSON replacer that serialises BigInt as a string. */\nfunction bigIntReplacer(_key: string, value: unknown): unknown {\n return typeof value === \"bigint\" ? value.toString() : value;\n}\n\n/**\n * Handle `aaac-observ query`.\n *\n * Required option: --kind (trace|span|search|links)\n * On success: writes a JSON array/object to stdout.\n * On error: writes to stderr and exits with code 1.\n *\n * DESIGN NOTE: all required-arg validation happens BEFORE the adapter is\n * created, so that when process.exit is mocked to throw in tests there is no\n * risk of a double-close on the database connection.\n */\nexport async function handleQuery(\n options: QueryHandlerOptions,\n _parentOpts: Record<string, unknown>,\n): Promise<void> {\n // Proposal shorthand: `aaac-observ query --issue <id>` (#178 T-E2)\n if (options.issue && !options.kind) {\n options.kind = \"issue\";\n }\n\n const validKinds = [\"trace\", \"span\", \"search\", \"links\", \"issue\"] as const;\n type QueryKind = (typeof validKinds)[number];\n\n // ── Validate options (before opening the adapter) ─────────────────────────\n if (!options.kind) {\n process.stderr.write(\n `Error: --kind (-k) is required (${validKinds.join(\"|\")})\\n`,\n );\n process.exit(1);\n }\n if (!validKinds.includes(options.kind as QueryKind)) {\n process.stderr.write(\n `Error: --kind must be one of: ${validKinds.join(\"|\")}\\n`,\n );\n process.exit(1);\n }\n\n const kind = options.kind as QueryKind;\n\n // Validate sub-command required args (before adapter creation)\n if (kind === \"trace\" && !options.traceId) {\n process.stderr.write(\"Error: --trace-id is required for --kind trace\\n\");\n process.exit(1);\n }\n if (kind === \"span\" && !options.spanId) {\n process.stderr.write(\"Error: --span-id is required for --kind span\\n\");\n process.exit(1);\n }\n if (kind === \"links\" && !options.spanId) {\n process.stderr.write(\"Error: --span-id is required for --kind links\\n\");\n process.exit(1);\n }\n if (kind === \"issue\" && !options.issue) {\n process.stderr.write(\"Error: --issue is required for --kind issue\\n\");\n process.exit(1);\n }\n\n // ── Open adapter ──────────────────────────────────────────────────────────\n const dbPath = options.db ?? DEFAULT_DB_PATH;\n const adapter = new SqliteQueryAdapter(dbPath);\n\n try {\n let result: unknown;\n\n switch (kind) {\n // ── trace: all spans in a trace ─────────────────────────────────────\n case \"trace\": {\n // options.traceId is guaranteed by pre-validation above\n result = adapter.getTrace(options.traceId!);\n break;\n }\n\n // ── span: single span + its events ──────────────────────────────────\n case \"span\": {\n // options.spanId is guaranteed by pre-validation above\n const span = adapter.getSpan(options.spanId!);\n const events = adapter.getSpanEvents(options.spanId!);\n result = span !== undefined ? { span, events } : null;\n break;\n }\n\n // ── search: spans matching event-type / task-id / time range ─────────\n case \"search\": {\n const filter: Parameters<typeof adapter.querySpans>[0] = {};\n if (options.eventType) filter.eventType = options.eventType;\n if (options.taskId) filter.taskId = options.taskId;\n if (options.from) filter.fromTimeUnixNano = isoToUnixNano(options.from);\n if (options.to) filter.toTimeUnixNano = isoToUnixNano(options.to);\n result = adapter.querySpans(filter);\n break;\n }\n\n // ── links: link traversal ─────────────────────────────────────────────\n case \"links\": {\n const validDirections = [\"forward\", \"reverse\", \"both\"] as const;\n type Dir = (typeof validDirections)[number];\n const dir: Dir =\n options.direction !== undefined &&\n validDirections.includes(options.direction as Dir)\n ? (options.direction as Dir)\n : \"both\";\n result = adapter.getLinks(options.spanId!, dir as LinkDirection);\n break;\n }\n\n // ── issue: Outcome chain analysis for an Issue (#178 T-E2) ──────────\n case \"issue\": {\n // options.issue is guaranteed by pre-validation above\n result = analyzeOutcomeChain(adapter, options.issue!);\n break;\n }\n }\n\n process.stdout.write(JSON.stringify(result, bigIntReplacer) + \"\\n\");\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n\n // Graceful handling: an un-initialised (fresh empty) database has no\n // tables yet. Return an empty / null result rather than an error so that\n // `aaac-observ query` on a machine with no recorded events behaves\n // predictably.\n if (msg.includes(\"no such table\") || msg.includes(\"no such column\")) {\n let emptyResult: unknown;\n if (kind === \"span\") {\n emptyResult = null;\n } else if (kind === \"issue\") {\n // No tables → all stages are missing\n emptyResult = {\n issueId: options.issue ?? \"\",\n stages: OUTCOME_CHAIN_STAGES.map((s) => ({\n eventType: s,\n status: \"missing\",\n spanIds: [],\n })),\n complete: false,\n gaps: [...OUTCOME_CHAIN_STAGES],\n provisional: [],\n };\n } else {\n emptyResult = [];\n }\n process.stdout.write(JSON.stringify(emptyResult, bigIntReplacer) + \"\\n\");\n adapter.close();\n return;\n }\n\n process.stderr.write(`Error: ${msg}\\n`);\n adapter.close();\n process.exit(1);\n }\n\n adapter.close();\n}\n","/**\n * backfill handler — re-emit historical spans from SQLite to an OTLP backend.\n *\n * Reads closed/instant spans from the local SQLite database and emits them\n * via OtelEmitter to an OTLP-compatible backend (e.g. OTel Collector →\n * ClickHouse).\n *\n * ## Idempotency design (important)\n *\n * The OTel SDK does NOT support specifying a custom spanId when creating spans.\n * Therefore, each backfill invocation will create NEW spans in the OTLP backend\n * with different spanIds than the originals recorded in SQLite. Repeated\n * invocations will produce DUPLICATE data in the backend (e.g. ClickHouse).\n *\n * Recommended idempotency strategies:\n * 1. Run backfill only once per SQLite DB / time range.\n * 2. Use --from / --to to backfill specific time windows; track which windows\n * have already been backfilled externally.\n * 3. Truncate the ClickHouse target table before re-running (destructive; safe\n * for dev environments).\n * 4. Use ClickHouse ReplacingMergeTree / FINAL for approximate deduplication\n * (requires schema changes; not the default otel_traces schema).\n *\n * The --dry-run flag prints span metadata without emitting; use it to verify\n * scope before committing to a real backfill.\n *\n * architecture.md §11 / docs/observability-setup.md / #125 §7\n */\nimport { SqliteQueryAdapter, OtelEmitter, DEFAULT_DB_PATH, isoToUnixNano } from \"../index.js\";\nimport { mapAllEventsToSpans } from \"../otel/span-mapper.js\";\nimport type { MappedSpan, MappedSpanLink } from \"../otel/span-mapper.js\";\nimport type { SpanRecord, LinkRecord } from \"../query/models.js\";\n\n// ── Handler options ───────────────────────────────────────────────────────────\n\nexport interface BackfillHandlerOptions {\n /** SQLite database path. Defaults to DEFAULT_DB_PATH. */\n db?: string;\n /**\n * OTLP HTTP endpoint URL.\n * Fallback: OTEL_EXPORTER_OTLP_ENDPOINT env var.\n * Required unless --dry-run is set.\n */\n endpoint?: string;\n /** OTEL service name reported to the backend. Default: '@aaac/observability'. */\n serviceName?: string;\n /** Filter: only backfill spans starting at or after this ISO 8601 time. */\n from?: string;\n /** Filter: only backfill spans starting at or before this ISO 8601 time. */\n to?: string;\n /** Filter: only backfill spans of this event type (e.g. 'agent.session'). */\n eventType?: string;\n /**\n * Print span metadata to stdout without actually emitting to the OTLP backend.\n * Useful for previewing scope before committing to a real backfill.\n */\n dryRun?: boolean;\n /**\n * Maximum milliseconds to wait for the OTLP flush before the CLI exits.\n * Default: 2000 ms (preserves existing vitest compatibility — unreachable\n * endpoints resolve immediately via connection-refused, so tests are unaffected\n * by the default value).\n *\n * For large backfills (> 5 000 spans) the BatchSpanProcessor needs significantly\n * more time. Recommended production value: 30 000 ms.\n *\n * Rule of thumb: allow ≥ 400 ms per 512-span batch\n * (i.e. ceil(spansFound / 512) * 400 ms, rounded up generously).\n *\n * Accepts `string` because the generated CLI program forwards the raw\n * `--flush-timeout-ms` option value verbatim; it is coerced to a number\n * (see `effectiveFlushMs`) inside the handler.\n */\n flushTimeoutMs?: number | string;\n}\n\n// ── MappedSpan reconstruction ─────────────────────────────────────────────────\n\n/**\n * Reconstruct a MappedSpan from a stored SpanRecord + its forward links.\n *\n * Backfill works at the \"span\" level (not the raw event level) because\n * SqliteSink materialises open+close into the `spans` table at write time.\n * Only closed or instant spans carry meaningful duration information.\n */\nfunction spanRecordToMappedSpan(\n span: SpanRecord,\n links: LinkRecord[],\n): MappedSpan {\n const start = span.startTime ?? 0n;\n const end = span.endTime ?? start;\n\n // Reconstruct MappedSpanLinks from the stored canonical_links rows.\n const mappedLinks: MappedSpanLink[] = links.map((l) => ({\n targetSpanId: l.targetSpanId,\n targetTraceId: l.targetTraceId ?? undefined,\n attributes: {\n link_type: l.linkType,\n ...(l.attributes ?? {}),\n },\n }));\n\n return {\n spanId: span.spanId,\n traceId: span.traceId ?? \"\",\n parentSpanId: span.parentSpanId ?? undefined,\n name: span.eventType,\n startTimeUnixNano: start,\n endTimeUnixNano: end,\n attributes: span.attributes,\n spanEvents: [], // span events are not stored in the spans table\n links: mappedLinks,\n };\n}\n\n// ── Handler ───────────────────────────────────────────────────────────────────\n\n/**\n * Handle `aaac-observ backfill`.\n *\n * Emits historical spans from the SQLite store to an OTLP backend.\n * Prints a JSON summary to stdout:\n * { spansFound: number, spansEmitted: number, dryRun: boolean }\n *\n * On error: writes to stderr and exits with code 1.\n *\n * IMPORTANT — idempotency: Re-running backfill without --from/--to restriction\n * will re-emit all matching spans, creating DUPLICATES in the OTLP backend.\n * See module-level comment for mitigation strategies.\n */\nexport async function handleBackfill(\n options: BackfillHandlerOptions,\n _parentOpts: Record<string, unknown>,\n): Promise<void> {\n const dbPath = options.db ?? DEFAULT_DB_PATH;\n const dryRun = options.dryRun ?? false;\n\n // ── Validate endpoint (not needed for dry-run) ────────────────────────────\n const endpoint = options.endpoint ?? process.env[\"OTEL_EXPORTER_OTLP_ENDPOINT\"];\n if (!dryRun && !endpoint) {\n process.stderr.write(\n \"Error: --endpoint is required (or set OTEL_EXPORTER_OTLP_ENDPOINT) unless --dry-run\\n\",\n );\n process.exit(1);\n }\n\n // ── Validate and parse time filters ───────────────────────────────────────\n // isoToUnixNano() silently falls back to currentTimeUnixNano() for invalid\n // ISO strings (shared utility — behaviour unchanged for other callers).\n // Backfill must validate explicitly so a typo in --from/--to causes exit 1\n // rather than a silent wrong-boundary backfill (F1 / issue #125).\n let fromNano: bigint | undefined;\n let toNano: bigint | undefined;\n if (options.from) {\n if (Number.isNaN(Date.parse(options.from))) {\n process.stderr.write(\n `Error: invalid --from value \"${options.from}\" — expected ISO 8601\\n`,\n );\n process.exit(1);\n }\n fromNano = isoToUnixNano(options.from);\n }\n if (options.to) {\n if (Number.isNaN(Date.parse(options.to))) {\n process.stderr.write(\n `Error: invalid --to value \"${options.to}\" — expected ISO 8601\\n`,\n );\n process.exit(1);\n }\n toNano = isoToUnixNano(options.to);\n }\n\n // ── Query spans from SQLite ────────────────────────────────────────────────\n const adapter = new SqliteQueryAdapter(dbPath);\n let spans: SpanRecord[];\n try {\n spans = adapter.querySpans({\n ...(options.eventType ? { eventType: options.eventType } : {}),\n ...(fromNano !== undefined ? { fromTimeUnixNano: fromNano } : {}),\n ...(toNano !== undefined ? { toTimeUnixNano: toNano } : {}),\n });\n // Only backfill spans that have completed (closed or instant).\n // Open spans are missing their end_time and would emit with zero duration.\n spans = spans.filter((s) => s.status === \"closed\" || s.status === \"instant\");\n } catch (err) {\n process.stderr.write(\n `Error: failed to query SQLite — ${err instanceof Error ? err.message : String(err)}\\n`,\n );\n adapter.close();\n process.exit(1);\n return; // unreachable, but satisfies TS control-flow\n }\n\n const spansFound = spans.length;\n\n if (dryRun) {\n adapter.close();\n const result = { spansFound, spansEmitted: 0, dryRun: true };\n process.stdout.write(JSON.stringify(result) + \"\\n\");\n return;\n }\n\n // ── Reconstruct MappedSpans with their links ──────────────────────────────\n const mappedSpans: MappedSpan[] = [];\n for (const span of spans) {\n let links: LinkRecord[] = [];\n try {\n links = adapter.getLinks(span.spanId, \"forward\");\n } catch {\n // fail-open: missing links are non-fatal for backfill\n }\n mappedSpans.push(spanRecordToMappedSpan(span, links));\n }\n\n adapter.close();\n\n // ── Large-backfill warning ────────────────────────────────────────────────\n // Warn before emitting when the operator-supplied (or default) flush timeout\n // is likely too short for the span count. Rule of thumb: each 512-span batch\n // takes ~400 ms → 1 000 spans ≈ 2 batches ≈ 800 ms, well under 2 s, but\n // 13 000 spans ≈ 26 batches ≈ 10 400 ms, which exceeds the 2 s default.\n // Emitting the warning here (before the emit loop) lets the operator ^C and\n // re-run with --flush-timeout-ms 30000 before any data is sent.\n const effectiveFlushMs =\n options.flushTimeoutMs != null ? Number(options.flushTimeoutMs) : 2000;\n if (spansFound > 1000 && effectiveFlushMs < 10000) {\n process.stderr.write(\n `Warning: ${spansFound} spans queued but --flush-timeout-ms is ` +\n `${effectiveFlushMs} ms (< 10 000 ms). Large batches may not fully ` +\n `flush before the deadline. Recommended: --flush-timeout-ms 30000\\n`,\n );\n }\n\n // ── Emit via OtelEmitter ──────────────────────────────────────────────────\n const emitter = new OtelEmitter({\n endpoint,\n serviceName: options.serviceName,\n });\n\n let spansEmitted = 0;\n for (const mapped of mappedSpans) {\n try {\n emitter.emit(mapped);\n spansEmitted++;\n } catch {\n // fail-open: individual span failures are non-fatal\n }\n }\n\n // Flush pending batch before reporting success.\n // Race against effectiveFlushMs so that an unreachable OTLP endpoint\n // never causes the CLI to hang indefinitely. OtelEmitter.shutdown() already\n // swallows its own errors, so the race is purely a time-bound escape hatch.\n // Default 2 000 ms preserves vitest idempotency-test compatibility (unreachable\n // endpoints resolve immediately via connection-refused; the timeout is never hit\n // in tests). For production use with > 5 000 spans pass --flush-timeout-ms 30000.\n await Promise.race([\n emitter.shutdown(),\n new Promise<void>((resolve) => setTimeout(resolve, effectiveFlushMs)),\n ]);\n\n const result = { spansFound, spansEmitted, dryRun: false };\n process.stdout.write(JSON.stringify(result) + \"\\n\");\n}\n","/**\n * ingest-vendor-otel handler — Canonical Projection of vendor OTEL into the Ledger.\n *\n * observability-integration.md §9.2 (T-D2): backfill Claude Code (vendor) OTEL\n * token/cost/trace exports into the SQLite Ledger so they become queryable\n * Canonical Events. The Ledger remains the canonical source of truth; vendor OTEL\n * is auxiliary evidence (\"OTEL は補助証跡。正本は Canonical Event\").\n *\n * ## Idempotency (§9.2)\n *\n * Every projected event carries a deterministic dedup_key\n * (`vendor-otel:{traceId}:{spanId}`). SqliteSink enforces UNIQUE(dedup_key) via\n * INSERT OR IGNORE, so re-running this command on the same export is a true no-op:\n * already-present rows are reported as `skippedDuplicate`. Hook/runtime records\n * (dedup_key = NULL) are the primary source and are never overwritten.\n *\n * Reads the OTLP/JSON trace export from --input (a file path) or stdin. Writes\n * directly to the SQLite Ledger (no OTLP re-emit — vendor spans already live in\n * their own pipeline), which makes the projection inherently fail-open with\n * respect to ClickHouse availability.\n */\nimport { readFile } from \"node:fs/promises\";\nimport { SqliteSink, DEFAULT_DB_PATH } from \"../index.js\";\nimport {\n mapVendorOtelExport,\n VENDOR_OTEL_SOURCE,\n} from \"../normalize/vendor-otel-mapper.js\";\n\n// ── Handler options ───────────────────────────────────────────────────────────\n\nexport interface IngestVendorOtelOptions {\n /** SQLite database path. Defaults to DEFAULT_DB_PATH. */\n db?: string;\n /** Path to the vendor OTLP/JSON trace export. Reads stdin when omitted. */\n input?: string;\n /** `source` tag applied to projected events. Default: 'claude-code-otel'. */\n source?: string;\n /** Parse + project without writing to the Ledger (prints counts only). */\n dryRun?: boolean;\n}\n\n/** Result printed to stdout as JSON. */\nexport interface IngestVendorOtelResult {\n /** Vendor spans projected to CanonicalEvents. */\n found: number;\n /** New rows written to the Ledger. */\n inserted: number;\n /** Rows already present (dedup_key collision) — idempotent re-run evidence. */\n skippedDuplicate: number;\n /** Vendor spans skipped for lacking a stable trace/span identity. */\n skippedInvalid: number;\n /** True when --dry-run was set (no writes performed). */\n dryRun: boolean;\n}\n\n// ── stdin helper ───────────────────────────────────────────────────────────────\n\n/** Read the whole stdin stream as a UTF-8 string (\"\" on TTY / error). */\nasync function readStdin(): Promise<string> {\n if (process.stdin.isTTY) return \"\";\n return new Promise<string>((resolve) => {\n let data = \"\";\n let settled = false;\n const finish = (): void => {\n if (settled) return;\n settled = true;\n resolve(data);\n };\n try {\n process.stdin.setEncoding(\"utf8\");\n process.stdin.on(\"data\", (chunk) => {\n data += chunk;\n });\n process.stdin.on(\"end\", finish);\n process.stdin.on(\"error\", finish);\n process.stdin.on(\"close\", finish);\n } catch {\n finish();\n }\n });\n}\n\n// ── Handler ───────────────────────────────────────────────────────────────────\n\n/**\n * Handle `aaac-observ ingest-vendor-otel`.\n *\n * Prints a JSON summary to stdout:\n * { found, inserted, skippedDuplicate, skippedInvalid, dryRun }\n *\n * On error (unreadable input / invalid JSON / DB failure): writes to stderr and\n * exits with code 1.\n */\nexport async function handleIngestVendorOtel(\n options: IngestVendorOtelOptions,\n _parentOpts: Record<string, unknown>,\n): Promise<void> {\n const dbPath = options.db ?? DEFAULT_DB_PATH;\n const dryRun = options.dryRun ?? false;\n const source = options.source ?? VENDOR_OTEL_SOURCE;\n\n // ── Read input (file or stdin) ─────────────────────────────────────────────\n let raw: string;\n try {\n raw = options.input ? await readFile(options.input, \"utf8\") : await readStdin();\n } catch (err) {\n process.stderr.write(\n `Error: failed to read input — ${err instanceof Error ? err.message : String(err)}\\n`,\n );\n process.exit(1);\n return;\n }\n\n if (raw.trim() === \"\") {\n process.stderr.write(\n \"Error: no input — provide --input <file> or pipe an OTLP/JSON trace export via stdin\\n\",\n );\n process.exit(1);\n return;\n }\n\n // ── Parse OTLP/JSON ────────────────────────────────────────────────────────\n let doc: unknown;\n try {\n doc = JSON.parse(raw);\n } catch (err) {\n process.stderr.write(\n `Error: invalid JSON input — ${err instanceof Error ? err.message : String(err)}\\n`,\n );\n process.exit(1);\n return;\n }\n\n // ── Project to CanonicalEvents ─────────────────────────────────────────────\n const { events, skipped: skippedInvalid } = mapVendorOtelExport(doc, { source });\n const found = events.length;\n\n if (dryRun) {\n const result: IngestVendorOtelResult = {\n found,\n inserted: 0,\n skippedDuplicate: 0,\n skippedInvalid,\n dryRun: true,\n };\n process.stdout.write(JSON.stringify(result) + \"\\n\");\n return;\n }\n\n // ── Write to the Ledger (idempotent via dedup_key) ─────────────────────────\n const sink = new SqliteSink(dbPath);\n let inserted = 0;\n let skippedDuplicate = 0;\n try {\n for (const event of events) {\n if (sink.write(event)) {\n inserted += 1;\n } else {\n skippedDuplicate += 1;\n }\n }\n } catch (err) {\n sink.close();\n process.stderr.write(\n `Error: failed to write to Ledger — ${err instanceof Error ? err.message : String(err)}\\n`,\n );\n process.exit(1);\n return;\n }\n sink.close();\n\n const result: IngestVendorOtelResult = {\n found,\n inserted,\n skippedDuplicate,\n skippedInvalid,\n dryRun: false,\n };\n process.stdout.write(JSON.stringify(result) + \"\\n\");\n}\n","/**\n * report handler — Observability 診断レポート生成 (#179 WS-F T-F1).\n *\n * Reads the local SQLite Ledger via SqliteQueryAdapter and renders the Layer 1–3\n * / link-completion / Person-Tier diagnostic as Markdown (default) or JSON.\n *\n * Mirrors the metric formulas of the `aaac-diagnostic` Grafana dashboard\n * (docker/observability/analysis-views.sql) so the CLI report and the dashboard\n * agree. Optionally produces a Before/After comparison when a baseline window is\n * supplied.\n *\n * Follows the handleQuery pattern: required-arg validation runs before the\n * adapter is opened, and a fresh/empty database degrades gracefully to an empty\n * report rather than an error.\n */\nimport { SqliteQueryAdapter, DEFAULT_DB_PATH } from \"../index.js\";\nimport {\n generateDiagnosticReport,\n renderReportMarkdown,\n renderReportJson,\n type DiagnosticReport,\n type DiagnosticReportOptions,\n} from \"../analysis/diagnostic-report.js\";\n\nexport interface ReportHandlerOptions {\n projectId?: string;\n from?: string;\n to?: string;\n baselineFrom?: string;\n baselineTo?: string;\n format?: string;\n db?: string;\n}\n\n/** An empty report shaped like generateDiagnosticReport output (for fresh DBs). */\nfunction emptyReport(options: ReportHandlerOptions): DiagnosticReport {\n const report: DiagnosticReport = {\n generatedAt: new Date().toISOString(),\n projectId: options.projectId ?? null,\n period: { from: options.from ?? null, to: options.to ?? null },\n metrics: {\n layer1: [],\n layer2: [],\n layer3: [],\n linkCompletion: { sessionLinkRate: [], stageArrival: [], provisional: [] },\n tierRatio: [],\n summary: {\n issueCount: 0,\n sessionCount: 0,\n totalCostUsd: 0,\n avgLeverage: 0,\n avgCommitRate: 0,\n avgCiPassRate: 0,\n avgChainCompleteness: 0,\n sessionLinkRate: 0,\n tierCounts: { high: 0, mid: 0, low: 0 },\n },\n },\n };\n return report;\n}\n\n/**\n * Handle `aaac-observ report`.\n *\n * On success: writes the rendered report (Markdown or JSON) to stdout.\n * On error: writes to stderr and exits with code 1.\n */\nexport async function handleReport(\n options: ReportHandlerOptions,\n _parentOpts: Record<string, unknown>,\n): Promise<void> {\n const validFormats = [\"markdown\", \"json\"] as const;\n type Format = (typeof validFormats)[number];\n\n // ── Validate options (before opening the adapter) ─────────────────────────\n if (options.format !== undefined && !validFormats.includes(options.format as Format)) {\n process.stderr.write(`Error: --format must be one of: ${validFormats.join(\"|\")}\\n`);\n process.exit(1);\n }\n const format: Format = (options.format as Format) ?? \"markdown\";\n\n const render = (report: DiagnosticReport): string =>\n format === \"json\" ? renderReportJson(report) : renderReportMarkdown(report);\n\n // ── Open adapter ──────────────────────────────────────────────────────────\n const dbPath = options.db ?? DEFAULT_DB_PATH;\n const adapter = new SqliteQueryAdapter(dbPath);\n\n try {\n const reportOptions: DiagnosticReportOptions = {};\n if (options.projectId !== undefined) reportOptions.projectId = options.projectId;\n if (options.from !== undefined) reportOptions.from = options.from;\n if (options.to !== undefined) reportOptions.to = options.to;\n if (options.baselineFrom !== undefined) reportOptions.baselineFrom = options.baselineFrom;\n if (options.baselineTo !== undefined) reportOptions.baselineTo = options.baselineTo;\n\n const report = generateDiagnosticReport(adapter, reportOptions);\n process.stdout.write(render(report) + \"\\n\");\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err);\n\n // Fresh/empty database: no tables yet → emit an empty report, not an error.\n if (msg.includes(\"no such table\") || msg.includes(\"no such column\")) {\n process.stdout.write(render(emptyReport(options)) + \"\\n\");\n adapter.close();\n return;\n }\n\n process.stderr.write(`Error: ${msg}\\n`);\n adapter.close();\n process.exit(1);\n }\n\n adapter.close();\n}\n","/**\n * CLI command handlers for aaac-observ.\n *\n * Implements the CommandHandlers interface generated by cli-contracts and\n * delegates to the domain-specific handler modules.\n *\n * Usage (in index.ts):\n * import { handlers } from './handlers.js';\n * import { createProgram } from '../generated/index.js';\n * const program = createProgram(handlers, version);\n * await program.parseAsync();\n */\nimport type { CommandHandlers } from \"../generated/index.js\";\nimport { handleRecord } from \"./record.js\";\nimport { handleRecordHook } from \"./record-hook.js\";\nimport { handleQuery } from \"./query.js\";\nimport { handleBackfill } from \"./backfill.js\";\nimport { handleIngestVendorOtel } from \"./ingest-vendor-otel.js\";\nimport { handleReport } from \"./report.js\";\n\nexport const handlers: CommandHandlers = {\n record: handleRecord,\n recordHook: handleRecordHook,\n query: handleQuery,\n backfill: handleBackfill,\n ingestVendorOtel: handleIngestVendorOtel,\n report: handleReport,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAOA,SAAS,oBAAoB;AAC7B,SAAS,SAAS,eAAe;AACjC,SAAS,qBAAqB;;;ACR9B,SAAS,eAAe;;;ACEjB,IAAM,gBAAwB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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AU,cAAc,UAAU,OAAO;AAC/C,MAAM,QAAQ,WAAW;","names":["handlers","version","program","result","resolve","resolve","result"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -338,16 +338,31 @@ declare function mapVendorOtelExport(doc: unknown, options?: VendorOtelMapOption
|
|
|
338
338
|
* a get → mutate → set discipline, so this is transparent).
|
|
339
339
|
*/
|
|
340
340
|
|
|
341
|
+
/**
|
|
342
|
+
* What a caller knows about a cached value and this store does not.
|
|
343
|
+
*
|
|
344
|
+
* `get` is generic over `T`, so the caller's predicate is the only thing that
|
|
345
|
+
* can establish it. That is not ceremony for the in-memory backend, where the
|
|
346
|
+
* value came from a `set` in the same process: {@link SqliteCacheStore} reads
|
|
347
|
+
* rows another process wrote, possibly from an older build, so `as T` there
|
|
348
|
+
* promised whatever the call site asked for and returned whatever the row held —
|
|
349
|
+
* `cacheGet<string[]>` on a row holding an object answered it, and the rule's
|
|
350
|
+
* `?? []` cannot see a value that is present and wrong (`v.push is not a
|
|
351
|
+
* function`). Both backends satisfy one interface, and consumers do not choose
|
|
352
|
+
* which one they get, so the check belongs to the interface.
|
|
353
|
+
*/
|
|
354
|
+
type CachedValuePredicate<T> = (value: unknown) => value is T;
|
|
341
355
|
/** Minimal key-value store contract used by the Correlator. */
|
|
342
356
|
interface CacheStore {
|
|
343
|
-
|
|
357
|
+
/** The value under `key` if `is` accepts it, else `undefined` — the same answer an absent key gets. */
|
|
358
|
+
get<T>(key: string, is: CachedValuePredicate<T>): T | undefined;
|
|
344
359
|
set(key: string, value: unknown): void;
|
|
345
360
|
del(key: string): void;
|
|
346
361
|
}
|
|
347
362
|
/** In-memory cache backed by a Map (default, single-process). */
|
|
348
363
|
declare class MemoryCacheStore implements CacheStore {
|
|
349
364
|
private readonly map;
|
|
350
|
-
get<T
|
|
365
|
+
get<T>(key: string, is: CachedValuePredicate<T>): T | undefined;
|
|
351
366
|
set(key: string, value: unknown): void;
|
|
352
367
|
del(key: string): void;
|
|
353
368
|
}
|
|
@@ -363,7 +378,7 @@ declare class MemoryCacheStore implements CacheStore {
|
|
|
363
378
|
declare class SqliteCacheStore implements CacheStore {
|
|
364
379
|
private readonly db;
|
|
365
380
|
constructor(db: DatabaseSync);
|
|
366
|
-
get<T
|
|
381
|
+
get<T>(key: string, is: CachedValuePredicate<T>): T | undefined;
|
|
367
382
|
set(key: string, value: unknown): void;
|
|
368
383
|
del(key: string): void;
|
|
369
384
|
}
|
|
@@ -411,8 +426,8 @@ declare class Correlator {
|
|
|
411
426
|
getOpenSpan(spanId: string): CanonicalEvent | undefined;
|
|
412
427
|
/** Store a value under an arbitrary key (TTL not enforced in Phase 0). */
|
|
413
428
|
cacheSet(key: string, value: unknown): void;
|
|
414
|
-
/** Retrieve a cached value;
|
|
415
|
-
cacheGet<T
|
|
429
|
+
/** Retrieve a cached value; undefined if absent or not what `is` accepts. */
|
|
430
|
+
cacheGet<T>(key: string, is: CachedValuePredicate<T>): T | undefined;
|
|
416
431
|
/** Remove a cached entry. */
|
|
417
432
|
cacheDel(key: string): void;
|
|
418
433
|
/** Return the number of currently-open spans (useful for testing). */
|
|
@@ -471,7 +486,7 @@ interface EnrichApi {
|
|
|
471
486
|
* Read from the Correlator's shared in-memory cache.
|
|
472
487
|
* Returns undefined if the key is absent.
|
|
473
488
|
*/
|
|
474
|
-
cacheGet<T
|
|
489
|
+
cacheGet<T>(key: string, is: CachedValuePredicate<T>): T | undefined;
|
|
475
490
|
/**
|
|
476
491
|
* Write to the Correlator's shared in-memory cache.
|
|
477
492
|
* Overwrites any existing value for the key.
|
|
@@ -1182,6 +1197,12 @@ interface EventMappingResult {
|
|
|
1182
1197
|
declare function evaluateMapping(rule: EventMappingRule, hookInput: Record<string, unknown>): EventMappingResult;
|
|
1183
1198
|
/**
|
|
1184
1199
|
* Load an event-mapping config file (YAML or JSON).
|
|
1200
|
+
*
|
|
1201
|
+
* Throws when the file is not one, with the reason named — the same exit an
|
|
1202
|
+
* unreadable path or a YAML syntax error already takes here, and `record-hook`
|
|
1203
|
+
* already catches all three into the generic-fallback recording (AC-3). Empty
|
|
1204
|
+
* and comment-only YAML parse to `null`, which is how `.mappings` on `null`
|
|
1205
|
+
* reached the recorder as a `TypeError` instead of as a fallback.
|
|
1185
1206
|
*/
|
|
1186
1207
|
declare function loadEventMappingConfig(filePath: string): Promise<EventMappingConfig>;
|
|
1187
1208
|
|