@narumitw/pi-analytics 0.49.8 → 0.49.10

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/dist/index.ts.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/analytics.ts", "../src/collector.ts", "../src/errors.ts", "../src/menu.ts", "../src/storage/queries.ts", "../src/skills.ts", "../src/storage/files.ts", "../src/storage/format.ts", "../src/storage/store.ts"],
4
- "sourcesContent": ["import { randomUUID } from \"node:crypto\";\nimport path from \"node:path\";\nimport {\n\ttype ExtensionAPI,\n\ttype ExtensionContext,\n\tgetAgentDir,\n} from \"@earendil-works/pi-coding-agent\";\nimport { ResponseCollector } from \"./collector.js\";\nimport { type AnalyticsMenuDataSource, showAnalyticsMenu } from \"./menu.js\";\nimport { SkillTracker } from \"./skills.js\";\nimport type { ClearAnalyticsResult } from \"./storage/files.js\";\nimport type { AnalyticsSnapshot, TimeRange } from \"./storage/queries.js\";\nimport { AnalyticsStore } from \"./storage/store.js\";\nimport type { ModelIdentity, SettledRun, TriggerSource } from \"./types.js\";\n\nconst STORAGE_DIRECTORY = \"pi-analytics\";\n\nexport interface AnalyticsStorePort {\n\treadonly path: string;\n\trecordRun(run: SettledRun, signal?: AbortSignal): Promise<void>;\n\tgetSnapshot(range: TimeRange, signal?: AbortSignal): Promise<AnalyticsSnapshot>;\n\tclearAll(signal?: AbortSignal): Promise<ClearAnalyticsResult>;\n\tclose(): Promise<void>;\n}\n\ninterface AnalyticsDependencies {\n\tcreateStore(path: string): AnalyticsStorePort;\n\tcreateSkillTracker(cwd: string): SkillTracker;\n\tgetAgentDir(): string;\n\tnow(): number;\n\tcreateId(): string;\n}\n\nexport function createAnalyticsExtension(\n\tdependencies: Partial<AnalyticsDependencies> = {},\n): (pi: ExtensionAPI) => void {\n\tconst deps: AnalyticsDependencies = {\n\t\tcreateStore: dependencies.createStore ?? ((rootPath) => new AnalyticsStore(rootPath)),\n\t\tcreateSkillTracker: dependencies.createSkillTracker ?? ((cwd) => new SkillTracker(cwd)),\n\t\tgetAgentDir: dependencies.getAgentDir ?? getAgentDir,\n\t\tnow: dependencies.now ?? Date.now,\n\t\tcreateId: dependencies.createId ?? randomUUID,\n\t};\n\n\treturn function analyticsExtension(pi: ExtensionAPI): void {\n\t\tlet sessionGeneration = 0;\n\t\tlet sessionController = new AbortController();\n\t\tlet collector = new ResponseCollector();\n\t\tlet skillTracker: SkillTracker | undefined;\n\t\tlet store: AnalyticsStorePort | undefined;\n\t\tlet storageFailure: string | undefined;\n\t\tconst retiredCloseTasks = new Set<Promise<boolean>>();\n\t\tlet writeFailureActive = false;\n\t\tlet pendingTriggerSource: TriggerSource = \"unknown\";\n\t\tlet pendingAttemptWithoutRun = false;\n\n\t\tpi.registerCommand(\"analytics\", {\n\t\t\tdescription: \"Open local Pi usage analytics\",\n\t\t\thandler: async (args, ctx) => {\n\t\t\t\tif (args.trim()) {\n\t\t\t\t\tif (!ctx.hasUI || (ctx.mode !== \"tui\" && ctx.mode !== \"rpc\")) {\n\t\t\t\t\t\tthrow new Error(\"/analytics does not accept arguments.\");\n\t\t\t\t\t}\n\t\t\t\t\tctx.ui.notify(\"/analytics does not accept arguments.\", \"warning\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (!ctx.hasUI || (ctx.mode !== \"tui\" && ctx.mode !== \"rpc\")) {\n\t\t\t\t\tthrow new Error(\"/analytics requires Pi TUI or RPC mode.\");\n\t\t\t\t}\n\t\t\t\tconst generation = sessionGeneration;\n\t\t\t\tconst owner = sessionController;\n\t\t\t\tconst source = menuSource(generation, owner.signal);\n\t\t\t\tawait showAnalyticsMenu(ctx, source, {\n\t\t\t\t\tsignal: owner.signal,\n\t\t\t\t\tisCurrent: () => generation === sessionGeneration && !owner.signal.aborted,\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\n\t\tpi.on(\"session_start\", (_event, ctx) => {\n\t\t\t++sessionGeneration;\n\t\t\tconst previousStore = store;\n\t\t\tsessionController.abort(new DOMException(\"Analytics session replaced\", \"AbortError\"));\n\t\t\tif (previousStore) retire(previousStore);\n\t\t\tsessionController = new AbortController();\n\t\t\tcollector = new ResponseCollector();\n\t\t\tskillTracker = deps.createSkillTracker(ctx.cwd);\n\t\t\tstore = undefined;\n\t\t\tstorageFailure = undefined;\n\t\t\twriteFailureActive = false;\n\t\t\tpendingTriggerSource = \"unknown\";\n\t\t\tpendingAttemptWithoutRun = false;\n\t\t\tconst storageRoot = path.join(deps.getAgentDir(), STORAGE_DIRECTORY);\n\t\t\ttry {\n\t\t\t\tstore = deps.createStore(storageRoot);\n\t\t\t} catch {\n\t\t\t\tstorageFailure = unavailableMessage();\n\t\t\t\tsafeNotify(ctx, storageFailure, \"warning\");\n\t\t\t}\n\t\t});\n\n\t\tpi.on(\"input\", (event, ctx) => {\n\t\t\tconst now = deps.now();\n\t\t\tconst tracker = skillTracker;\n\t\t\ttracker?.observeInput(event.text, event.source, now);\n\t\t\tif (event.source !== \"extension\") pendingTriggerSource = event.source;\n\t\t\tif (!tracker || !collector.hasActiveRun()) return;\n\t\t\tconst explicit = tracker.consumeExplicitSkill();\n\t\t\tif (!explicit || !tracker.hasAvailableSkill(explicit.name)) return;\n\t\t\tcollector.activateSkill({\n\t\t\t\tname: explicit.name,\n\t\t\t\tinitiatedBy: \"user\",\n\t\t\t\tnow: explicit.observedAtMs,\n\t\t\t\tmodel: modelIdentity(ctx, pi),\n\t\t\t});\n\t\t});\n\n\t\tpi.on(\"before_agent_start\", async (event, ctx) => {\n\t\t\tconst generation = sessionGeneration;\n\t\t\tconst tracker = skillTracker;\n\t\t\tconst activeCollector = collector;\n\t\t\tif (!tracker) return;\n\t\t\tconst skills = availableSkills(pi, event.systemPromptOptions.skills ?? []);\n\t\t\tawait tracker.setAvailableSkills(skills);\n\t\t\tif (\n\t\t\t\tgeneration !== sessionGeneration ||\n\t\t\t\ttracker !== skillTracker ||\n\t\t\t\tactiveCollector !== collector\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst explicit = tracker.consumeExplicitSkill();\n\t\t\tconst interrupted = activeCollector.begin({\n\t\t\t\tid: deps.createId(),\n\t\t\t\tnow: deps.now(),\n\t\t\t\ttriggerSource: explicit?.source ?? pendingTriggerSource,\n\t\t\t\tmodel: modelIdentity(ctx, pi),\n\t\t\t});\n\t\t\tpendingTriggerSource = \"unknown\";\n\t\t\tif (interrupted) {\n\t\t\t\tawait persistRun(interrupted, ctx, generation, sessionController.signal);\n\t\t\t\tif (\n\t\t\t\t\tgeneration !== sessionGeneration ||\n\t\t\t\t\ttracker !== skillTracker ||\n\t\t\t\t\tactiveCollector !== collector\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (explicit && skills.some(({ name }) => name === explicit.name)) {\n\t\t\t\tactiveCollector.activateSkill({\n\t\t\t\t\tname: explicit.name,\n\t\t\t\t\tinitiatedBy: \"user\",\n\t\t\t\t\tnow: explicit.observedAtMs,\n\t\t\t\t\tmodel: modelIdentity(ctx, pi),\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\n\t\tpi.on(\"agent_start\", () => {\n\t\t\tif (collector.hasActiveRun()) collector.beginAttempt();\n\t\t\telse pendingAttemptWithoutRun = true;\n\t\t});\n\n\t\tpi.on(\"turn_start\", (_event, ctx) => ensureRun(ctx, \"extension\"));\n\n\t\tpi.on(\"before_provider_request\", (_event, ctx) => {\n\t\t\tensureRun(ctx, \"extension\");\n\t\t\tcollector.beginGeneration({\n\t\t\t\tid: deps.createId(),\n\t\t\t\tnow: deps.now(),\n\t\t\t\tmodel: modelIdentity(ctx, pi),\n\t\t\t});\n\t\t});\n\n\t\tpi.on(\"after_provider_response\", (event) => {\n\t\t\tcollector.recordProviderResponse({ status: event.status, now: deps.now() });\n\t\t});\n\n\t\tpi.on(\"message_end\", (event) => {\n\t\t\tif (event.message.role !== \"assistant\") return;\n\t\t\tcollector.finishGeneration({\n\t\t\t\tnow: deps.now(),\n\t\t\t\tstopReason: event.message.stopReason,\n\t\t\t\terrorMessage: event.message.errorMessage,\n\t\t\t});\n\t\t});\n\n\t\tpi.on(\"tool_execution_start\", (event, ctx) => {\n\t\t\tensureRun(ctx, \"extension\");\n\t\t\tcollector.beginTool({\n\t\t\t\tid: event.toolCallId,\n\t\t\t\tname: event.toolName,\n\t\t\t\tnow: deps.now(),\n\t\t\t\tmodel: modelIdentity(ctx, pi),\n\t\t\t});\n\t\t});\n\n\t\tpi.on(\"tool_result\", async (event, ctx) => {\n\t\t\tif (event.toolName === \"read\" && !isBuiltinReadTool(pi)) return;\n\t\t\tconst generation = sessionGeneration;\n\t\t\tconst tracker = skillTracker;\n\t\t\tconst activeCollector = collector;\n\t\t\tconst runId = activeCollector.getActiveRunId();\n\t\t\tif (!tracker || !runId) return;\n\t\t\tconst name = await tracker.matchSuccessfulRead({\n\t\t\t\ttoolName: event.toolName,\n\t\t\t\tinput: event.input,\n\t\t\t\tisError: event.isError,\n\t\t\t});\n\t\t\tif (\n\t\t\t\t!name ||\n\t\t\t\tgeneration !== sessionGeneration ||\n\t\t\t\ttracker !== skillTracker ||\n\t\t\t\tactiveCollector !== collector ||\n\t\t\t\tactiveCollector.getActiveRunId() !== runId\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tactiveCollector.activateSkill({\n\t\t\t\tname,\n\t\t\t\tinitiatedBy: \"model\",\n\t\t\t\tnow: deps.now(),\n\t\t\t\tmodel: modelIdentity(ctx, pi),\n\t\t\t});\n\t\t});\n\n\t\tpi.on(\"tool_execution_end\", (event) => {\n\t\t\tcollector.finishTool({ id: event.toolCallId, now: deps.now(), isError: event.isError });\n\t\t});\n\n\t\tpi.on(\"agent_settled\", async (_event, ctx) => {\n\t\t\tconst generation = sessionGeneration;\n\t\t\tconst owner = sessionController;\n\t\t\tconst run = collector.settle(deps.now());\n\t\t\tpendingAttemptWithoutRun = false;\n\t\t\tpendingTriggerSource = \"unknown\";\n\t\t\tskillTracker?.clearPending();\n\t\t\tif (run) await persistRun(run, ctx, generation, owner.signal);\n\t\t});\n\n\t\tpi.on(\"session_shutdown\", async (_event, ctx) => {\n\t\t\tconst activeStore = store;\n\t\t\t++sessionGeneration;\n\t\t\tsessionController.abort(new DOMException(\"Analytics session shut down\", \"AbortError\"));\n\t\t\tskillTracker?.clearPending();\n\t\t\tskillTracker = undefined;\n\t\t\tstore = undefined;\n\t\t\tcollector.interrupt(deps.now());\n\t\t\tconst closing = activeStore\n\t\t\t\t? [closeResult(activeStore), ...retiredCloseTasks]\n\t\t\t\t: [...retiredCloseTasks];\n\t\t\tconst results = await Promise.all(closing);\n\t\t\tif (results.some((closed) => !closed)) {\n\t\t\t\tsafeNotify(ctx, \"Analytics storage shutdown was incomplete.\", \"warning\");\n\t\t\t}\n\t\t});\n\n\t\tfunction retire(retiredStore: AnalyticsStorePort): void {\n\t\t\tconst task = closeResult(retiredStore).finally(() => retiredCloseTasks.delete(task));\n\t\t\tretiredCloseTasks.add(task);\n\t\t}\n\n\t\tasync function closeResult(activeStore: AnalyticsStorePort): Promise<boolean> {\n\t\t\ttry {\n\t\t\t\tawait activeStore.close();\n\t\t\t\treturn true;\n\t\t\t} catch {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\tfunction ensureRun(ctx: ExtensionContext, triggerSource: TriggerSource): void {\n\t\t\tif (collector.hasActiveRun()) return;\n\t\t\tcollector.begin({\n\t\t\t\tid: deps.createId(),\n\t\t\t\tnow: deps.now(),\n\t\t\t\ttriggerSource,\n\t\t\t\tmodel: modelIdentity(ctx, pi),\n\t\t\t});\n\t\t\tif (pendingAttemptWithoutRun) {\n\t\t\t\tpendingAttemptWithoutRun = false;\n\t\t\t\tcollector.beginAttempt();\n\t\t\t}\n\t\t}\n\n\t\tasync function persistRun(\n\t\t\trun: SettledRun,\n\t\t\tctx: ExtensionContext,\n\t\t\tgeneration: number,\n\t\t\tsignal: AbortSignal,\n\t\t): Promise<void> {\n\t\t\tconst activeStore = store;\n\t\t\tif (!activeStore || signal.aborted) return;\n\t\t\ttry {\n\t\t\t\tawait activeStore.recordRun(run, signal);\n\t\t\t\tif (generation !== sessionGeneration || activeStore !== store || signal.aborted) return;\n\t\t\t\tif (writeFailureActive) {\n\t\t\t\t\twriteFailureActive = false;\n\t\t\t\t\tsafeNotify(ctx, \"Local analytics storage recovered.\", \"info\");\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\tif (\n\t\t\t\t\tgeneration !== sessionGeneration ||\n\t\t\t\t\tactiveStore !== store ||\n\t\t\t\t\tsignal.aborted ||\n\t\t\t\t\twriteFailureActive\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\twriteFailureActive = true;\n\t\t\t\tsafeNotify(\n\t\t\t\t\tctx,\n\t\t\t\t\t\"Analytics could not save this response cycle; its metrics were dropped.\",\n\t\t\t\t\t\"warning\",\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tfunction menuSource(generation: number, signal: AbortSignal): AnalyticsMenuDataSource {\n\t\t\treturn {\n\t\t\t\tpath: store?.path ?? path.join(deps.getAgentDir(), STORAGE_DIRECTORY),\n\t\t\t\tasync load(range, actionSignal) {\n\t\t\t\t\tassertCurrent(generation, signal);\n\t\t\t\t\tconst activeStore = store;\n\t\t\t\t\tif (!activeStore) {\n\t\t\t\t\t\treturn { kind: \"unavailable\", message: storageFailure ?? unavailableMessage() };\n\t\t\t\t\t}\n\t\t\t\t\tconst snapshot = await activeStore.getSnapshot(range, actionSignal);\n\t\t\t\t\tassertCurrent(generation, signal);\n\t\t\t\t\treturn { kind: \"ready\", snapshot };\n\t\t\t\t},\n\t\t\t\tasync clearAll(actionSignal) {\n\t\t\t\t\tassertCurrent(generation, signal);\n\t\t\t\t\tconst activeStore = store;\n\t\t\t\t\tif (!activeStore) return { cleanupIncomplete: false };\n\t\t\t\t\treturn activeStore.clearAll(actionSignal);\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\tfunction assertCurrent(generation: number, signal: AbortSignal): void {\n\t\t\tif (generation !== sessionGeneration || signal.aborted) {\n\t\t\t\tthrow new DOMException(\"Analytics interaction replaced\", \"AbortError\");\n\t\t\t}\n\t\t}\n\t};\n}\n\nfunction modelIdentity(ctx: ExtensionContext, pi: ExtensionAPI): ModelIdentity | undefined {\n\tif (!ctx.model) return undefined;\n\treturn {\n\t\tprovider: ctx.model.provider,\n\t\tmodel: ctx.model.id,\n\t\tthinkingLevel: pi.getThinkingLevel(),\n\t};\n}\n\nexport function isBuiltinReadTool(pi: ExtensionAPI): boolean {\n\tconst read = pi.getAllTools().find(({ name }) => name === \"read\");\n\treturn read?.sourceInfo.source === \"builtin\";\n}\n\nfunction availableSkills(\n\tpi: ExtensionAPI,\n\tsystemSkills: ReadonlyArray<{ name: string; filePath: string }>,\n): Array<{ name: string; filePath: string }> {\n\tconst result = [...systemSkills];\n\tconst seen = new Set(result.map(({ name }) => name));\n\tconst getCommands = (pi as ExtensionAPI & { getCommands?: ExtensionAPI[\"getCommands\"] })\n\t\t.getCommands;\n\tfor (const command of typeof getCommands === \"function\" ? getCommands.call(pi) : []) {\n\t\tif (command.source !== \"skill\" || seen.has(command.name.replace(/^skill:/u, \"\"))) continue;\n\t\tconst name = command.name.replace(/^skill:/u, \"\");\n\t\tseen.add(name);\n\t\tresult.push({ name, filePath: command.sourceInfo.path });\n\t}\n\treturn result;\n}\n\nfunction unavailableMessage(): string {\n\treturn [\n\t\t\"Local analytics storage could not be initialized safely.\",\n\t\t\"Existing files were not replaced.\",\n\t\t\"No analytics are being collected.\",\n\t].join(\"\\n\");\n}\n\nfunction safeNotify(ctx: ExtensionContext, message: string, level: \"info\" | \"warning\"): void {\n\ttry {\n\t\tctx.ui.notify(message, level);\n\t} catch {\n\t\t// A replaced Pi context cannot receive lifecycle feedback.\n\t}\n}\n\nexport default createAnalyticsExtension();\n", "import { randomUUID } from \"node:crypto\";\nimport { classifyProviderError } from \"./errors.js\";\nimport type {\n\tGenerationOutcome,\n\tGenerationRecord,\n\tModelIdentity,\n\tProviderErrorRecord,\n\tRunOutcome,\n\tSettledRun,\n\tSkillActivationRecord,\n\tToolCallRecord,\n\tTriggerSource,\n} from \"./types.js\";\n\ninterface ActiveRun {\n\tid: string;\n\tstartedAtMs: number;\n\ttriggerSource: TriggerSource;\n\tinitialModel?: ModelIdentity;\n\tattemptCount: number;\n\tgenerations: GenerationRecord[];\n\tgenerationIds: Set<string>;\n\ttools: ToolCallRecord[];\n\ttoolIds: Set<string>;\n\tskills: SkillActivationRecord[];\n\tskillIndexes: Map<string, number>;\n\tproviderErrors: ProviderErrorRecord[];\n}\n\nexport class ResponseCollector {\n\tprivate active: ActiveRun | undefined;\n\n\thasActiveRun(): boolean {\n\t\treturn this.active !== undefined;\n\t}\n\n\tgetActiveRunId(): string | undefined {\n\t\treturn this.active?.id;\n\t}\n\n\tbegin(input: {\n\t\tid: string;\n\t\tnow: number;\n\t\ttriggerSource: TriggerSource;\n\t\tmodel?: ModelIdentity;\n\t}): SettledRun | undefined {\n\t\tconst interrupted = this.active ? this.finalize(input.now, \"interrupted\") : undefined;\n\t\tthis.active = {\n\t\t\tid: input.id,\n\t\t\tstartedAtMs: input.now,\n\t\t\ttriggerSource: input.triggerSource,\n\t\t\tinitialModel: input.model,\n\t\t\tattemptCount: 0,\n\t\t\tgenerations: [],\n\t\t\tgenerationIds: new Set(),\n\t\t\ttools: [],\n\t\t\ttoolIds: new Set(),\n\t\t\tskills: [],\n\t\t\tskillIndexes: new Map(),\n\t\t\tproviderErrors: [],\n\t\t};\n\t\treturn interrupted;\n\t}\n\n\tbeginAttempt(): void {\n\t\tif (this.active) this.active.attemptCount += 1;\n\t}\n\n\tbeginGeneration(input: { id: string; now: number; model?: ModelIdentity }): void {\n\t\tconst active = this.active;\n\t\tif (!active || active.generationIds.has(input.id)) return;\n\t\tactive.generationIds.add(input.id);\n\t\tactive.generations.push({\n\t\t\tid: input.id,\n\t\t\tordinal: active.generations.length,\n\t\t\tprovider: input.model?.provider,\n\t\t\tmodel: input.model?.model,\n\t\t\tthinkingLevel: input.model?.thinkingLevel,\n\t\t\tstartedAtMs: input.now,\n\t\t\toutcome: \"pending\",\n\t\t\tresponses: [],\n\t\t});\n\t}\n\n\trecordProviderResponse(input: { status: number; now: number }): void {\n\t\tconst generation = this.latestGeneration();\n\t\tif (generation?.outcome !== \"pending\") return;\n\t\tgeneration.responses.push({\n\t\t\tordinal: generation.responses.length,\n\t\t\toccurredAtMs: input.now,\n\t\t\tstatus: input.status,\n\t\t});\n\t}\n\n\tfinishGeneration(input: { now: number; stopReason: string; errorMessage?: string }): void {\n\t\tconst active = this.active;\n\t\tconst generation = this.latestGeneration();\n\t\tif (!active || !generation || generation.outcome !== \"pending\") return;\n\t\tgeneration.finishedAtMs = input.now;\n\t\tgeneration.durationMs = elapsed(generation.startedAtMs, input.now);\n\t\tgeneration.stopReason = input.stopReason;\n\t\tgeneration.outcome = generationOutcome(input.stopReason);\n\t\tif (generation.outcome === \"error\") {\n\t\t\tactive.providerErrors.push({\n\t\t\t\tid: randomUUID(),\n\t\t\t\tgenerationId: generation.id,\n\t\t\t\toccurredAtMs: input.now,\n\t\t\t\tprovider: generation.provider,\n\t\t\t\tmodel: generation.model,\n\t\t\t\tcategory: classifyProviderError(input.errorMessage),\n\t\t\t\trecovered: false,\n\t\t\t\tterminal: true,\n\t\t\t});\n\t\t}\n\t}\n\n\tbeginTool(input: { id: string; name: string; now: number; model?: ModelIdentity }): void {\n\t\tconst active = this.active;\n\t\tif (!active || active.toolIds.has(input.id)) return;\n\t\tactive.toolIds.add(input.id);\n\t\tactive.tools.push({\n\t\t\tid: input.id,\n\t\t\tordinal: active.tools.length,\n\t\t\tname: input.name,\n\t\t\tprovider: input.model?.provider,\n\t\t\tmodel: input.model?.model,\n\t\t\tstartedAtMs: input.now,\n\t\t\tisError: false,\n\t\t\tcompletionState: \"running\",\n\t\t});\n\t}\n\n\tfinishTool(input: { id: string; now: number; isError: boolean }): void {\n\t\tconst tool = this.active?.tools.find(({ id }) => id === input.id);\n\t\tif (tool?.completionState !== \"running\") return;\n\t\ttool.finishedAtMs = input.now;\n\t\ttool.durationMs = elapsed(tool.startedAtMs, input.now);\n\t\ttool.isError = input.isError;\n\t\ttool.completionState = \"finished\";\n\t}\n\n\tactivateSkill(input: {\n\t\tname: string;\n\t\tinitiatedBy: \"user\" | \"model\";\n\t\tnow: number;\n\t\tmodel?: ModelIdentity;\n\t}): void {\n\t\tconst active = this.active;\n\t\tif (!active) return;\n\t\tconst existingIndex = active.skillIndexes.get(input.name);\n\t\tif (existingIndex !== undefined) {\n\t\t\tconst existing = active.skills[existingIndex];\n\t\t\tif (existing && existing.initiatedBy === \"model\" && input.initiatedBy === \"user\") {\n\t\t\t\texisting.initiatedBy = \"user\";\n\t\t\t\texisting.occurredAtMs = input.now;\n\t\t\t\texisting.provider = input.model?.provider;\n\t\t\t\texisting.model = input.model?.model;\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tactive.skillIndexes.set(input.name, active.skills.length);\n\t\tactive.skills.push({\n\t\t\tid: randomUUID(),\n\t\t\tname: input.name,\n\t\t\tinitiatedBy: input.initiatedBy,\n\t\t\toccurredAtMs: input.now,\n\t\t\tprovider: input.model?.provider,\n\t\t\tmodel: input.model?.model,\n\t\t});\n\t}\n\n\tsettle(now: number): SettledRun | undefined {\n\t\treturn this.finalize(now);\n\t}\n\n\tinterrupt(now: number): SettledRun | undefined {\n\t\treturn this.finalize(now, \"interrupted\");\n\t}\n\n\tprivate latestGeneration(): GenerationRecord | undefined {\n\t\treturn this.active?.generations.at(-1);\n\t}\n\n\tprivate finalize(now: number, forcedOutcome?: RunOutcome): SettledRun | undefined {\n\t\tconst active = this.active;\n\t\tif (!active) return undefined;\n\t\tthis.active = undefined;\n\n\t\tfor (const generation of active.generations) {\n\t\t\tif (generation.outcome !== \"pending\") continue;\n\t\t\tgeneration.outcome = \"interrupted\";\n\t\t\tgeneration.finishedAtMs = now;\n\t\t\tgeneration.durationMs = elapsed(generation.startedAtMs, now);\n\t\t}\n\t\tfor (const tool of active.tools) {\n\t\t\tif (tool.completionState !== \"running\") continue;\n\t\t\ttool.completionState = \"interrupted\";\n\t\t\ttool.finishedAtMs = now;\n\t\t\ttool.durationMs = elapsed(tool.startedAtMs, now);\n\t\t}\n\n\t\tconst successfulGenerationIndexes = new Set(\n\t\t\tactive.generations\n\t\t\t\t.map((generation, index) => ({ generation, index }))\n\t\t\t\t.filter(({ generation }) => isSuccessfulGeneration(generation))\n\t\t\t\t.map(({ index }) => index),\n\t\t);\n\t\tlet recoveredHttpErrors = 0;\n\t\tlet httpErrors = 0;\n\t\tfor (const [generationIndex, generation] of active.generations.entries()) {\n\t\t\tconst hasLaterSuccess = [...successfulGenerationIndexes].some(\n\t\t\t\t(index) => index > generationIndex,\n\t\t\t);\n\t\t\tfor (const [responseIndex, response] of generation.responses.entries()) {\n\t\t\t\tif (response.status < 400) continue;\n\t\t\t\thttpErrors += 1;\n\t\t\t\tconst laterSuccessInGeneration = generation.responses\n\t\t\t\t\t.slice(responseIndex + 1)\n\t\t\t\t\t.some(({ status }) => status >= 200 && status < 400);\n\t\t\t\tif (laterSuccessInGeneration || hasLaterSuccess) recoveredHttpErrors += 1;\n\t\t\t}\n\t\t}\n\t\tfor (const error of active.providerErrors) {\n\t\t\tconst generationIndex = active.generations.findIndex(({ id }) => id === error.generationId);\n\t\t\terror.recovered = [...successfulGenerationIndexes].some((index) => index > generationIndex);\n\t\t\terror.terminal = !error.recovered;\n\t\t}\n\n\t\tconst recoveredGenerationErrors = active.providerErrors.filter(\n\t\t\t({ recovered }) => recovered,\n\t\t).length;\n\t\tconst providerErrorCount = httpErrors + active.providerErrors.length;\n\t\tconst recoveredErrorCount = recoveredHttpErrors + recoveredGenerationErrors;\n\t\tconst outcome = forcedOutcome ?? deriveOutcome(active.generations, providerErrorCount);\n\n\t\treturn {\n\t\t\tid: active.id,\n\t\t\tstartedAtMs: active.startedAtMs,\n\t\t\tfinishedAtMs: now,\n\t\t\tdurationMs: elapsed(active.startedAtMs, now),\n\t\t\ttriggerSource: active.triggerSource,\n\t\t\tinitialProvider: active.initialModel?.provider,\n\t\t\tinitialModel: active.initialModel?.model,\n\t\t\toutcome,\n\t\t\tattemptCount: active.attemptCount,\n\t\t\tgenerations: active.generations,\n\t\t\ttools: active.tools,\n\t\t\tskills: active.skills,\n\t\t\tproviderErrors: active.providerErrors,\n\t\t\ttoolErrorCount: active.tools.filter(({ isError }) => isError).length,\n\t\t\tproviderErrorCount,\n\t\t\trecoveredErrorCount,\n\t\t};\n\t}\n}\n\nfunction elapsed(start: number, end: number): number {\n\treturn Math.max(0, end - start);\n}\n\nfunction generationOutcome(stopReason: string): GenerationOutcome {\n\tswitch (stopReason) {\n\t\tcase \"stop\":\n\t\t\treturn \"stop\";\n\t\tcase \"toolUse\":\n\t\t\treturn \"tool_use\";\n\t\tcase \"error\":\n\t\t\treturn \"error\";\n\t\tcase \"aborted\":\n\t\t\treturn \"aborted\";\n\t\tcase \"length\":\n\t\t\treturn \"length\";\n\t\tdefault:\n\t\t\treturn \"interrupted\";\n\t}\n}\n\nfunction isSuccessfulGeneration(generation: GenerationRecord): boolean {\n\treturn generation.outcome === \"stop\" || generation.outcome === \"tool_use\";\n}\n\nfunction deriveOutcome(\n\tgenerations: readonly GenerationRecord[],\n\tproviderErrors: number,\n): RunOutcome {\n\tconst last = generations.at(-1);\n\tif (!last) return providerErrors > 0 ? \"error\" : \"success\";\n\tswitch (last.outcome) {\n\t\tcase \"stop\":\n\t\tcase \"tool_use\":\n\t\t\treturn providerErrors > 0 ? \"recovered_success\" : \"success\";\n\t\tcase \"error\":\n\t\t\treturn \"error\";\n\t\tcase \"aborted\":\n\t\t\treturn \"aborted\";\n\t\tcase \"length\":\n\t\t\treturn \"length\";\n\t\tdefault:\n\t\t\treturn \"interrupted\";\n\t}\n}\n", "import type { ProviderErrorCategory } from \"./types.js\";\n\nexport function classifyProviderError(message: string | undefined): ProviderErrorCategory {\n\tconst value = message?.toLowerCase() ?? \"\";\n\tif (/\\b(enotfound|eai_again|dns|getaddrinfo)\\b/u.test(value)) return \"dns\";\n\tif (/\\b(etimedout|timeout|timed out)\\b/u.test(value)) return \"timeout\";\n\tif (/\\b(econnrefused|connection refused)\\b/u.test(value)) return \"connection_refused\";\n\tif (/\\b(econnreset|connection reset|socket hang up)\\b/u.test(value)) {\n\t\treturn \"connection_reset\";\n\t}\n\tif (/\\b(tls|ssl|certificate|cert_|handshake)\\b/u.test(value)) return \"tls\";\n\tif (/\\b(fetch failed|network|socket|connection|transport)\\b/u.test(value)) {\n\t\treturn \"network_other\";\n\t}\n\treturn \"provider_other\";\n}\n", "import { stripVTControlCharacters } from \"node:util\";\nimport type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport type { MenuDefinition } from \"@narumitw/pi-tui-kit\";\nimport type { ClearAnalyticsResult } from \"./storage/files.js\";\nimport type {\n\tAnalyticsSnapshot,\n\tSkillStats,\n\tTimeRange,\n\tTimeRangeId,\n\tToolStats,\n} from \"./storage/queries.js\";\nimport { resolveTimeRange } from \"./storage/queries.js\";\n\nexport type AnalyticsLoadResult =\n\t| { kind: \"ready\"; snapshot: AnalyticsSnapshot }\n\t| { kind: \"unavailable\"; message: string };\n\nexport interface AnalyticsMenuDataSource {\n\tpath: string;\n\tload(range: TimeRange, signal: AbortSignal): Promise<AnalyticsLoadResult>;\n\tclearAll(signal: AbortSignal): Promise<ClearAnalyticsResult>;\n}\n\nexport interface AnalyticsMenuState {\n\trangeId: TimeRangeId;\n\trange: TimeRange;\n\tpath: string;\n\tresult: AnalyticsLoadResult;\n}\n\nexport interface AnalyticsMenuOptions {\n\trunConfirmation: typeof import(\"@narumitw/pi-tui-kit\")[\"runConfirmation\"];\n\tisCurrent(): boolean;\n}\n\ntype Screen = \"main\" | \"range\" | \"skills\" | \"tools\" | \"reliability\" | \"responses\" | \"privacy\";\ntype Action = \"setRange\" | \"clearData\";\n\nconst RANGE_LABELS: Record<TimeRangeId, string> = {\n\ttoday: \"Today\",\n\t\"7d\": \"Last 7 days\",\n\t\"30d\": \"Last 30 days\",\n\tall: \"All time\",\n};\n\nexport function createAnalyticsMenu(\n\tsource: AnalyticsMenuDataSource,\n\tnow: () => number = Date.now,\n\toptions?: AnalyticsMenuOptions,\n) {\n\tlet rangeId: TimeRangeId = \"7d\";\n\tlet cachedState: AnalyticsMenuState | undefined;\n\tconst loadState = async (signal: AbortSignal): Promise<AnalyticsMenuState> => {\n\t\tif (cachedState?.rangeId === rangeId) return cachedState;\n\t\tconst range = resolveTimeRange(rangeId, now());\n\t\tconst loaded = { rangeId, range, path: source.path, result: await source.load(range, signal) };\n\t\tif (!signal.aborted && rangeId === loaded.rangeId) cachedState = loaded;\n\t\treturn loaded;\n\t};\n\tconst getState = ({ signal }: { signal: AbortSignal }): Promise<AnalyticsMenuState> =>\n\t\tloadState(signal);\n\tconst menu: MenuDefinition<AnalyticsMenuState, Screen, Action> = {\n\t\tstart: \"main\",\n\t\tscreens: {\n\t\t\tmain: ({ state }) => ({\n\t\t\t\tkind: \"actions\",\n\t\t\t\ttitle: `Analytics \u00B7 ${RANGE_LABELS[state.rangeId]}`,\n\t\t\t\tlines: overviewLines(state.result),\n\t\t\t\titems: [\n\t\t\t\t\t{ id: \"range\", label: \"Change time range\", to: \"range\" },\n\t\t\t\t\t{ id: \"skills\", label: \"Skills\", to: \"skills\" },\n\t\t\t\t\t{ id: \"tools\", label: \"Tools\", to: \"tools\" },\n\t\t\t\t\t{ id: \"reliability\", label: \"Provider reliability\", to: \"reliability\" },\n\t\t\t\t\t{ id: \"responses\", label: \"Response cycles\", to: \"responses\" },\n\t\t\t\t\t{ id: \"privacy\", label: \"Data & privacy\", to: \"privacy\" },\n\t\t\t\t\t{ id: \"close\", label: \"Close\", close: true },\n\t\t\t\t],\n\t\t\t\thint: \"close\",\n\t\t\t}),\n\t\t\trange: ({ state }) => ({\n\t\t\t\tkind: \"choice\",\n\t\t\t\ttitle: \"Analytics time range\",\n\t\t\t\titems: (Object.keys(RANGE_LABELS) as TimeRangeId[]).map((id) => ({\n\t\t\t\t\tid,\n\t\t\t\t\tlabel: RANGE_LABELS[id],\n\t\t\t\t})),\n\t\t\t\taction: \"setRange\",\n\t\t\t\tcurrentItemId: state.rangeId,\n\t\t\t\tinitialItemId: state.rangeId,\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t\tskills: ({ state }) => skillsScreen(state.result),\n\t\t\ttools: ({ state }) => toolsScreen(state.result),\n\t\t\treliability: ({ state }) => ({\n\t\t\t\tkind: \"detail\",\n\t\t\t\ttitle: `Provider reliability \u00B7 ${RANGE_LABELS[state.rangeId]}`,\n\t\t\t\tlines: reliabilityLines(state.result),\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t\tresponses: ({ state }) => ({\n\t\t\t\tkind: \"detail\",\n\t\t\t\ttitle: `Response cycles \u00B7 ${RANGE_LABELS[state.rangeId]}`,\n\t\t\t\tlines: responseLines(state.result),\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t\tprivacy: ({ state }) => ({\n\t\t\t\tkind: \"actions\",\n\t\t\t\ttitle: \"Analytics data & privacy\",\n\t\t\t\tlines: privacyLines(state),\n\t\t\t\titems: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"clear\",\n\t\t\t\t\t\tlabel: \"Clear analytics data\u2026\",\n\t\t\t\t\t\taction: \"clearData\",\n\t\t\t\t\t\tdisabled: state.result.kind !== \"ready\",\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\thint: \"back\",\n\t\t\t}),\n\t\t},\n\t\tactions: {\n\t\t\tsetRange: async ({ itemId, signal }) => {\n\t\t\t\tif (!isRangeId(itemId)) return { kind: \"rejected\", error: new Error(\"Unknown range\") };\n\t\t\t\trangeId = itemId;\n\t\t\t\tcachedState = undefined;\n\t\t\t\tawait loadState(signal);\n\t\t\t\treturn signal.aborted ? { kind: \"close\" } : { kind: \"to\", screen: \"main\" };\n\t\t\t},\n\t\t\tclearData: async ({ ctx, state, signal }) => {\n\t\t\t\tif (state.result.kind !== \"ready\") return { kind: \"stay\" };\n\t\t\t\tif (!options) throw new Error(\"Analytics confirmation is unavailable\");\n\t\t\t\tconst count = state.result.snapshot.overview.responseCycles;\n\t\t\t\tconst confirmation = await options.runConfirmation(ctx, {\n\t\t\t\t\ttitle: \"Delete analytics data?\",\n\t\t\t\t\tmessage: `This will clear all local analytics history from:\\n\\n${safeDisplayText(state.path)}\\n\\nThe selected range currently shows ${count} response cycles. Other running Pi processes may add new records afterward.`,\n\t\t\t\t\tconfirmLabel: \"Delete data\",\n\t\t\t\t\tcancelLabel: \"Keep data\",\n\t\t\t\t\tsignal,\n\t\t\t\t\tisCurrent: options.isCurrent,\n\t\t\t\t\t// Keep the dashboard's existing domain-level error route as the only notifier.\n\t\t\t\t\tonError: () => undefined,\n\t\t\t\t});\n\t\t\t\tif (signal.aborted || !options.isCurrent()) return { kind: \"close\" };\n\t\t\t\tif (confirmation.kind === \"closed\") {\n\t\t\t\t\treturn confirmation.reason === \"close\" ? { kind: \"close\" } : { kind: \"stay\" };\n\t\t\t\t}\n\t\t\t\tif (confirmation.kind === \"stale\") return { kind: \"close\" };\n\t\t\t\tif (confirmation.kind === \"unsupported\") {\n\t\t\t\t\tthrow new Error(`Analytics confirmation is unavailable in ${confirmation.mode} mode`);\n\t\t\t\t}\n\t\t\t\tif (confirmation.kind === \"error\") throw confirmation.error;\n\n\t\t\t\tconst result = await source.clearAll(signal);\n\t\t\t\tcachedState = undefined;\n\t\t\t\tconst isCurrent = options.isCurrent();\n\t\t\t\tif (isCurrent) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tctx.ui.notify(\"Cleared local analytics data.\", \"info\");\n\t\t\t\t\t\tif (result.cleanupIncomplete) {\n\t\t\t\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\t\t\t\"Some obsolete analytics files are still in use. Stop other Pi processes and clear again to remove them.\",\n\t\t\t\t\t\t\t\t\"warning\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// The host can dispose the current UI after the ownership check.\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn signal.aborted || !isCurrent ? { kind: \"close\" } : { kind: \"to\", screen: \"main\" };\n\t\t\t},\n\t\t},\n\t};\n\treturn {\n\t\tmenu,\n\t\tgetState,\n\t\tpreload: (signal: AbortSignal) => loadState(signal),\n\t\tget rangeId() {\n\t\t\treturn rangeId;\n\t\t},\n\t};\n}\n\nexport async function showAnalyticsMenu(\n\tctx: ExtensionCommandContext,\n\tsource: AnalyticsMenuDataSource,\n\toptions: { signal: AbortSignal; isCurrent: () => boolean },\n): Promise<void> {\n\tconst { runConfirmation, runMenu, runTask } = await import(\"@narumitw/pi-tui-kit\");\n\tif (options.signal.aborted || !options.isCurrent()) return;\n\tconst controller = createAnalyticsMenu(source, Date.now, {\n\t\trunConfirmation,\n\t\tisCurrent: options.isCurrent,\n\t});\n\tconst loading = await runTask(ctx, {\n\t\tlabel: \"Loading local analytics\u2026\",\n\t\tsignal: options.signal,\n\t\tisCurrent: options.isCurrent,\n\t\ttask: ({ signal }) => controller.preload(signal),\n\t\tonError: () => undefined,\n\t});\n\tif (loading.kind !== \"completed\") {\n\t\tif (loading.kind === \"error\") {\n\t\t\tctx.ui.notify(\n\t\t\t\t\"Analytics failed: The local analytics query could not be completed. Existing data was not changed.\",\n\t\t\t\t\"error\",\n\t\t\t);\n\t\t}\n\t\treturn;\n\t}\n\tawait runMenu(ctx, controller.menu, {\n\t\tgetState: controller.getState,\n\t\tsignal: options.signal,\n\t\tisCurrent: options.isCurrent,\n\t\tonError: (_ctx, error) => {\n\t\t\tctx.ui.notify(`Analytics failed: ${safeErrorMessage(error)}`, \"error\");\n\t\t},\n\t});\n}\n\nfunction overviewLines(result: AnalyticsLoadResult): string[] {\n\tif (result.kind === \"unavailable\") {\n\t\treturn [result.message, \"\", \"No analytics are being collected.\"];\n\t}\n\tconst stats = result.snapshot.overview;\n\tif (stats.responseCycles === 0) {\n\t\treturn [\n\t\t\t\"No analytics yet.\",\n\t\t\t\"Collection is active. Complete one Pi response cycle, then open /analytics again.\",\n\t\t\t\"\",\n\t\t\t\"Includes settled response cycles only.\",\n\t\t];\n\t}\n\treturn [\n\t\tmetric(\"Response cycles\", stats.responseCycles),\n\t\tmetric(\"LLM calls\", stats.llmCalls),\n\t\tmetric(\n\t\t\t\"Calls per response\",\n\t\t\t`${formatDecimal(stats.callsPerResponse)} \u00B7 P95 ${stats.p95CallsPerResponse}`,\n\t\t),\n\t\tmetric(\"Tool calls\", stats.toolCalls),\n\t\tmetric(\"Tool errors\", stats.toolErrors),\n\t\tmetric(\"Skill activations\", stats.skillActivations),\n\t\tmetric(\"Provider errors\", stats.providerErrors),\n\t\tmetric(\"Recovered errors\", stats.recoveredErrors),\n\t\t\"\",\n\t\t\"Includes settled response cycles only.\",\n\t];\n}\n\nfunction skillsScreen(result: AnalyticsLoadResult) {\n\tif (result.kind === \"unavailable\") {\n\t\treturn {\n\t\t\tkind: \"browse\" as const,\n\t\t\ttitle: \"Skills\",\n\t\t\tlines: [result.message],\n\t\t\titems: [],\n\t\t\thint: \"back\" as const,\n\t\t};\n\t}\n\treturn {\n\t\tkind: \"browse\" as const,\n\t\ttitle: \"Skills\",\n\t\tlines:\n\t\t\tresult.snapshot.skills.length === 0\n\t\t\t\t? [\"No skill activations detected in this time range.\"]\n\t\t\t\t: undefined,\n\t\titems: result.snapshot.skills.map(skillItem),\n\t\tviewportSize: \"adaptive\" as const,\n\t\thint: \"back\" as const,\n\t};\n}\n\nfunction skillItem(skill: SkillStats) {\n\treturn {\n\t\tid: skill.name,\n\t\tlabel: safeDisplayText(skill.name),\n\t\tstatusText: `${skill.count} \u00B7 ${skill.modelInitiated} model / ${skill.userInitiated} user`,\n\t\tsearchText: skill.models.map(modelLabel).join(\" \"),\n\t\tdetails: [\n\t\t\tmetric(\"Activations\", skill.count),\n\t\t\tmetric(\"Model initiated\", skill.modelInitiated),\n\t\t\tmetric(\"User initiated\", skill.userInitiated),\n\t\t\t\"\",\n\t\t\t\"By model\",\n\t\t\t...skill.models.map((model) => `${modelLabel(model)}: ${model.count}`),\n\t\t\t\"\",\n\t\t\t`Last detected: ${formatTimestamp(skill.lastOccurredAtMs)}`,\n\t\t],\n\t};\n}\n\nfunction toolsScreen(result: AnalyticsLoadResult) {\n\tif (result.kind === \"unavailable\") {\n\t\treturn {\n\t\t\tkind: \"browse\" as const,\n\t\t\ttitle: \"Tools\",\n\t\t\tlines: [result.message],\n\t\t\titems: [],\n\t\t\thint: \"back\" as const,\n\t\t};\n\t}\n\treturn {\n\t\tkind: \"browse\" as const,\n\t\ttitle: \"Tools\",\n\t\tlines:\n\t\t\tresult.snapshot.tools.length === 0\n\t\t\t\t? [\"No tool calls detected in this time range.\"]\n\t\t\t\t: undefined,\n\t\titems: result.snapshot.tools.map(toolItem),\n\t\tviewportSize: \"adaptive\" as const,\n\t\thint: \"back\" as const,\n\t};\n}\n\nfunction toolItem(tool: ToolStats) {\n\treturn {\n\t\tid: tool.name,\n\t\tlabel: safeDisplayText(tool.name),\n\t\tstatusText: `${tool.count} \u00B7 ${tool.errors} errors`,\n\t\tsearchText: tool.models.map(modelLabel).join(\" \"),\n\t\tdetails: [\n\t\t\tmetric(\"Calls\", tool.count),\n\t\t\tmetric(\"Errors\", tool.errors),\n\t\t\t`Average duration: ${formatDecimal(tool.averageDurationMs)} ms`,\n\t\t\t\"\",\n\t\t\t\"By model\",\n\t\t\t...tool.models.map((model) => `${modelLabel(model)}: ${model.count}`),\n\t\t\t\"\",\n\t\t\t`Last detected: ${formatTimestamp(tool.lastOccurredAtMs)}`,\n\t\t],\n\t};\n}\n\nfunction reliabilityLines(result: AnalyticsLoadResult): string[] {\n\tif (result.kind === \"unavailable\") return [result.message];\n\tconst value = result.snapshot.reliability;\n\treturn [\n\t\t\"Observed provider errors only; provider-internal failures may be invisible.\",\n\t\t\"\",\n\t\tmetric(\"HTTP 429\", value.http429),\n\t\tmetric(\"HTTP 5xx\", value.http5xx),\n\t\tmetric(\"DNS\", value.categories.dns),\n\t\tmetric(\"Connection timeout\", value.categories.timeout),\n\t\tmetric(\"Connection refused\", value.categories.connection_refused),\n\t\tmetric(\"Connection reset\", value.categories.connection_reset),\n\t\tmetric(\"TLS\", value.categories.tls),\n\t\tmetric(\"Other network\", value.categories.network_other),\n\t\tmetric(\"Other provider\", value.categories.provider_other),\n\t\t\"\",\n\t\tmetric(\"Recovered\", value.recovered),\n\t\tmetric(\"Terminal failures\", value.terminal),\n\t];\n}\n\nfunction responseLines(result: AnalyticsLoadResult): string[] {\n\tif (result.kind === \"unavailable\") return [result.message];\n\tconst value = result.snapshot.responses;\n\treturn [\n\t\tmetric(\"Cycles\", value.count),\n\t\tmetric(\"LLM calls\", value.llmCalls),\n\t\tmetric(\"Average\", formatDecimal(value.average)),\n\t\tmetric(\"Median\", formatDecimal(value.median)),\n\t\tmetric(\"P95\", value.p95),\n\t\tmetric(\"Maximum\", value.maximum),\n\t\t\"\",\n\t\t\"Calls per response\",\n\t\tmetric(\"1 call\", value.distribution.one),\n\t\tmetric(\"2\u20133 calls\", value.distribution.twoToThree),\n\t\tmetric(\"4\u20136 calls\", value.distribution.fourToSix),\n\t\tmetric(\"7+ calls\", value.distribution.sevenPlus),\n\t];\n}\n\nfunction privacyLines(state: AnalyticsMenuState): string[] {\n\treturn [\n\t\t\"Local analytics files:\",\n\t\tsafeDisplayText(state.path),\n\t\t\"\",\n\t\t\"Stored: timestamps, extension-generated record IDs, model/provider IDs, thinking level, tool and skill names, durations, counts, HTTP statuses, and classified errors.\",\n\t\t\"Not stored: prompts, responses, thinking, tool arguments/results, raw errors, headers, cwd/file paths, session identity, or credentials.\",\n\t\t\"\",\n\t\t\"No database server, cloud connection, or other remote telemetry is used.\",\n\t\t\"Analytics are non-critical derived metadata; a failed local write may be dropped.\",\n\t];\n}\n\nfunction metric(label: string, value: string | number): string {\n\treturn `${label.padEnd(24)} ${value}`;\n}\n\nfunction formatDecimal(value: number): string {\n\treturn Number.isInteger(value)\n\t\t? String(value)\n\t\t: value.toFixed(2).replace(/0+$/u, \"\").replace(/\\.$/u, \"\");\n}\n\nfunction formatTimestamp(value: number): string {\n\treturn new Date(value).toLocaleString();\n}\n\nfunction modelLabel(model: { provider?: string; model?: string }): string {\n\tif (!model.provider && !model.model) return \"unknown\";\n\treturn safeDisplayText(`${model.provider ?? \"unknown\"}/${model.model ?? \"unknown\"}`);\n}\n\nfunction safeDisplayText(value: unknown): string {\n\treturn Array.from(stripVTControlCharacters(String(value)), (character) => {\n\t\tconst codePoint = character.codePointAt(0) ?? 0;\n\t\treturn codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f) ? \" \" : character;\n\t}).join(\"\");\n}\n\nfunction isRangeId(value: string): value is TimeRangeId {\n\treturn value === \"today\" || value === \"7d\" || value === \"30d\" || value === \"all\";\n}\n\nfunction safeErrorMessage(_error: unknown): string {\n\treturn \"The local analytics query could not be completed. Try again; existing data was not changed.\";\n}\n", "import type { ProviderErrorCategory, SettledRun } from \"../types.js\";\n\nexport type TimeRangeId = \"today\" | \"7d\" | \"30d\" | \"all\";\nexport interface TimeRange {\n\tid?: TimeRangeId;\n\tfromMs: number;\n\ttoMs: number;\n}\n\nexport interface OverviewStats {\n\tresponseCycles: number;\n\tllmCalls: number;\n\tcallsPerResponse: number;\n\tp95CallsPerResponse: number;\n\ttoolCalls: number;\n\ttoolErrors: number;\n\tskillActivations: number;\n\tproviderErrors: number;\n\trecoveredErrors: number;\n}\n\nexport interface ModelCount {\n\tprovider?: string;\n\tmodel?: string;\n\tcount: number;\n}\n\nexport interface SkillStats {\n\tname: string;\n\tcount: number;\n\tmodelInitiated: number;\n\tuserInitiated: number;\n\tlastOccurredAtMs: number;\n\tmodels: ModelCount[];\n}\n\nexport interface ToolStats {\n\tname: string;\n\tcount: number;\n\terrors: number;\n\taverageDurationMs: number;\n\tlastOccurredAtMs: number;\n\tmodels: ModelCount[];\n}\n\nexport interface ReliabilityStats {\n\thttp429: number;\n\thttp5xx: number;\n\trecovered: number;\n\tterminal: number;\n\tcategories: Record<ProviderErrorCategory, number>;\n}\n\nexport interface ResponseStats {\n\tcount: number;\n\tllmCalls: number;\n\taverage: number;\n\tmedian: number;\n\tp95: number;\n\tmaximum: number;\n\tdistribution: { one: number; twoToThree: number; fourToSix: number; sevenPlus: number };\n}\n\nexport interface AnalyticsSnapshot {\n\toverview: OverviewStats;\n\tskills: SkillStats[];\n\ttools: ToolStats[];\n\treliability: ReliabilityStats;\n\tresponses: ResponseStats;\n}\n\nconst DAY_MS = 24 * 60 * 60 * 1_000;\nconst ERROR_CATEGORIES: readonly ProviderErrorCategory[] = [\n\t\"dns\",\n\t\"timeout\",\n\t\"connection_refused\",\n\t\"connection_reset\",\n\t\"tls\",\n\t\"network_other\",\n\t\"provider_other\",\n];\n\nexport function resolveTimeRange(id: TimeRangeId, now = Date.now()): TimeRange {\n\tlet fromMs = 0;\n\tif (id === \"today\") {\n\t\tconst date = new Date(now);\n\t\tfromMs = new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime();\n\t} else if (id === \"7d\") fromMs = now - 7 * DAY_MS;\n\telse if (id === \"30d\") fromMs = now - 30 * DAY_MS;\n\treturn { id, fromMs, toMs: now + 1 };\n}\n\nexport async function querySnapshot(\n\truns: AsyncIterable<SettledRun> | Iterable<SettledRun>,\n\trange: TimeRange,\n\tsignal?: AbortSignal,\n): Promise<AnalyticsSnapshot> {\n\tconst generationCounts: number[] = [];\n\tconst seenRunIds = new Set<string>();\n\tconst skills = new Map<string, SkillStats>();\n\tconst tools = new Map<string, ToolStats & { totalDurationMs: number }>();\n\tconst categories = Object.fromEntries(\n\t\tERROR_CATEGORIES.map((category) => [category, 0]),\n\t) as Record<ProviderErrorCategory, number>;\n\tlet toolErrors = 0;\n\tlet providerErrors = 0;\n\tlet recoveredErrors = 0;\n\tlet http429 = 0;\n\tlet http5xx = 0;\n\tlet terminal = 0;\n\n\tfor await (const run of runs) {\n\t\tthrowIfAborted(signal);\n\t\tif (seenRunIds.has(run.id)) continue;\n\t\tseenRunIds.add(run.id);\n\t\tif (run.startedAtMs < range.fromMs || run.startedAtMs >= range.toMs) continue;\n\t\tgenerationCounts.push(run.generations.length);\n\t\ttoolErrors += run.toolErrorCount;\n\t\tproviderErrors += run.providerErrorCount;\n\t\trecoveredErrors += run.recoveredErrorCount;\n\n\t\tfor (const skill of run.skills) {\n\t\t\tconst item = skills.get(skill.name) ?? {\n\t\t\t\tname: skill.name,\n\t\t\t\tcount: 0,\n\t\t\t\tmodelInitiated: 0,\n\t\t\t\tuserInitiated: 0,\n\t\t\t\tlastOccurredAtMs: 0,\n\t\t\t\tmodels: [],\n\t\t\t};\n\t\t\titem.count += 1;\n\t\t\tif (skill.initiatedBy === \"user\") item.userInitiated += 1;\n\t\t\telse item.modelInitiated += 1;\n\t\t\titem.lastOccurredAtMs = Math.max(item.lastOccurredAtMs, skill.occurredAtMs);\n\t\t\tmergeModelCount(item.models, {\n\t\t\t\tprovider: skill.provider,\n\t\t\t\tmodel: skill.model,\n\t\t\t\tcount: 1,\n\t\t\t});\n\t\t\tskills.set(skill.name, item);\n\t\t}\n\n\t\tfor (const tool of run.tools) {\n\t\t\tconst item = tools.get(tool.name) ?? {\n\t\t\t\tname: tool.name,\n\t\t\t\tcount: 0,\n\t\t\t\terrors: 0,\n\t\t\t\taverageDurationMs: 0,\n\t\t\t\ttotalDurationMs: 0,\n\t\t\t\tlastOccurredAtMs: 0,\n\t\t\t\tmodels: [],\n\t\t\t};\n\t\t\titem.count += 1;\n\t\t\titem.errors += tool.isError ? 1 : 0;\n\t\t\titem.totalDurationMs += tool.durationMs ?? 0;\n\t\t\titem.averageDurationMs = item.totalDurationMs / item.count;\n\t\t\titem.lastOccurredAtMs = Math.max(item.lastOccurredAtMs, tool.startedAtMs);\n\t\t\tmergeModelCount(item.models, {\n\t\t\t\tprovider: tool.provider,\n\t\t\t\tmodel: tool.model,\n\t\t\t\tcount: 1,\n\t\t\t});\n\t\t\ttools.set(tool.name, item);\n\t\t}\n\n\t\tfor (const error of run.providerErrors) {\n\t\t\tcategories[error.category] += 1;\n\t\t\tterminal += error.terminal ? 1 : 0;\n\t\t}\n\t\tfor (const generation of run.generations) {\n\t\t\tfor (const response of generation.responses) {\n\t\t\t\tif (response.status === 429) http429 += 1;\n\t\t\t\tif (response.status >= 500 && response.status < 600) http5xx += 1;\n\t\t\t}\n\t\t}\n\t}\n\n\tconst responses = responseStatistics(generationCounts);\n\treturn {\n\t\toverview: {\n\t\t\tresponseCycles: responses.count,\n\t\t\tllmCalls: responses.llmCalls,\n\t\t\tcallsPerResponse: responses.average,\n\t\t\tp95CallsPerResponse: responses.p95,\n\t\t\ttoolCalls: sum([...tools.values()].map(({ count }) => count)),\n\t\t\ttoolErrors,\n\t\t\tskillActivations: sum([...skills.values()].map(({ count }) => count)),\n\t\t\tproviderErrors,\n\t\t\trecoveredErrors,\n\t\t},\n\t\tskills: [...skills.values()]\n\t\t\t.map((item) => ({ ...item, models: sortModels(item.models) }))\n\t\t\t.sort((left, right) => right.count - left.count || left.name.localeCompare(right.name)),\n\t\ttools: [...tools.values()]\n\t\t\t.map(({ totalDurationMs: _, ...item }) => ({ ...item, models: sortModels(item.models) }))\n\t\t\t.sort((left, right) => right.count - left.count || left.name.localeCompare(right.name)),\n\t\treliability: {\n\t\t\thttp429,\n\t\t\thttp5xx,\n\t\t\trecovered: recoveredErrors,\n\t\t\tterminal,\n\t\t\tcategories,\n\t\t},\n\t\tresponses,\n\t};\n}\n\nfunction responseStatistics(generationCounts: number[]): ResponseStats {\n\tconst sorted = [...generationCounts].sort((left, right) => left - right);\n\tconst count = sorted.length;\n\tconst llmCalls = sum(sorted);\n\tconst nearestRank = (percentile: number) =>\n\t\tcount === 0 ? 0 : (sorted[Math.max(0, Math.ceil(percentile * count) - 1)] ?? 0);\n\tconst median =\n\t\tcount === 0\n\t\t\t? 0\n\t\t\t: count % 2 === 1\n\t\t\t\t? (sorted[Math.floor(count / 2)] ?? 0)\n\t\t\t\t: ((sorted[count / 2 - 1] ?? 0) + (sorted[count / 2] ?? 0)) / 2;\n\treturn {\n\t\tcount,\n\t\tllmCalls,\n\t\taverage: count > 0 ? llmCalls / count : 0,\n\t\tmedian,\n\t\tp95: nearestRank(0.95),\n\t\tmaximum: sorted.at(-1) ?? 0,\n\t\tdistribution: {\n\t\t\tone: sorted.filter((value) => value === 1).length,\n\t\t\ttwoToThree: sorted.filter((value) => value >= 2 && value <= 3).length,\n\t\t\tfourToSix: sorted.filter((value) => value >= 4 && value <= 6).length,\n\t\t\tsevenPlus: sorted.filter((value) => value >= 7).length,\n\t\t},\n\t};\n}\n\nfunction mergeModelCount(models: ModelCount[], next: ModelCount): void {\n\tconst existing = models.find(\n\t\t({ provider, model }) => provider === next.provider && model === next.model,\n\t);\n\tif (existing) existing.count += next.count;\n\telse models.push(next);\n}\n\nfunction sortModels(models: ModelCount[]): ModelCount[] {\n\treturn models.sort(\n\t\t(left, right) =>\n\t\t\tright.count - left.count ||\n\t\t\t`${left.provider ?? \"\"}/${left.model ?? \"\"}`.localeCompare(\n\t\t\t\t`${right.provider ?? \"\"}/${right.model ?? \"\"}`,\n\t\t\t),\n\t);\n}\n\nfunction throwIfAborted(signal?: AbortSignal): void {\n\tif (signal?.aborted)\n\t\tthrow signal.reason ?? new DOMException(\"Analytics query aborted\", \"AbortError\");\n}\n\nfunction sum(values: readonly number[]): number {\n\treturn values.reduce((total, value) => total + value, 0);\n}\n", "import { realpath } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { InputSource } from \"@earendil-works/pi-coding-agent\";\n\nexport interface AvailableSkill {\n\tname: string;\n\tfilePath: string;\n}\n\nexport interface PendingExplicitSkill {\n\tname: string;\n\tobservedAtMs: number;\n\tsource: \"interactive\" | \"rpc\";\n}\n\nexport function explicitSkillName(text: string): string | undefined {\n\treturn text.match(/^\\/skill:([a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?)(?:\\s|$)/u)?.[1];\n}\n\nexport class SkillTracker {\n\tprivate pending: PendingExplicitSkill | undefined;\n\tprivate readonly skillByPath = new Map<string, string>();\n\tprivate readonly availableNames = new Set<string>();\n\n\tconstructor(\n\t\tprivate readonly cwd: string,\n\t\tprivate readonly canonicalize: (filePath: string) => Promise<string> = realpath,\n\t) {}\n\n\tobserveInput(text: string, source: InputSource, now: number): void {\n\t\tif (source === \"extension\") return;\n\t\tconst name = explicitSkillName(text);\n\t\tthis.pending = name ? { name, observedAtMs: now, source } : undefined;\n\t}\n\n\tconsumeExplicitSkill(): PendingExplicitSkill | undefined {\n\t\tconst pending = this.pending;\n\t\tthis.pending = undefined;\n\t\treturn pending;\n\t}\n\n\tclearPending(): void {\n\t\tthis.pending = undefined;\n\t}\n\n\thasAvailableSkill(name: string): boolean {\n\t\treturn this.availableNames.has(name);\n\t}\n\n\tasync setAvailableSkills(skills: readonly AvailableSkill[]): Promise<void> {\n\t\tthis.skillByPath.clear();\n\t\tthis.availableNames.clear();\n\t\tconst seenNames = new Set<string>();\n\t\tfor (const skill of skills) {\n\t\t\tif (seenNames.has(skill.name)) continue;\n\t\t\tseenNames.add(skill.name);\n\t\t\tthis.availableNames.add(skill.name);\n\t\t\tconst canonical = await this.canonicalize(skill.filePath).catch(() =>\n\t\t\t\tpath.resolve(this.cwd, skill.filePath),\n\t\t\t);\n\t\t\tthis.skillByPath.set(canonical, skill.name);\n\t\t}\n\t}\n\n\tasync matchSuccessfulRead(input: {\n\t\ttoolName: string;\n\t\tinput: unknown;\n\t\tisError: boolean;\n\t}): Promise<string | undefined> {\n\t\tif (input.toolName !== \"read\" || input.isError || !isRecord(input.input)) return undefined;\n\t\tconst rawPath = input.input.path;\n\t\tif (typeof rawPath !== \"string\" || rawPath.length === 0) return undefined;\n\t\tconst normalized = rawPath.startsWith(\"@\") ? rawPath.slice(1) : rawPath;\n\t\tconst absolute = path.resolve(this.cwd, normalized);\n\t\tconst canonical = await this.canonicalize(absolute).catch(() => absolute);\n\t\treturn this.skillByPath.get(canonical);\n\t}\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n", "import { randomUUID } from \"node:crypto\";\nimport { createReadStream, type Dirent } from \"node:fs\";\nimport {\n\tchmod,\n\tlstat,\n\tmkdir,\n\topen,\n\treaddir,\n\treadFile,\n\trename,\n\trm,\n\trmdir,\n\tunlink,\n\twriteFile,\n} from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { SettledRun } from \"../types.js\";\nimport {\n\tAnalyticsStorageFormatError,\n\tdecodeStoredRun,\n\tencodeStoredRun,\n\tMAX_STORED_RUN_BYTES,\n} from \"./format.js\";\n\nconst GENERATION_PATTERN =\n\t/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/u;\nconst DEFAULT_WRITE_TIMEOUT_MS = 5_000;\nconst YIELD_EVERY_RECORDS = 100;\n\nexport interface ClearAnalyticsResult {\n\tcleanupIncomplete: boolean;\n}\n\nexport class AnalyticsGenerationChangedError extends Error {\n\tconstructor() {\n\t\tsuper(\"The active analytics generation changed during the read.\");\n\t\tthis.name = \"AnalyticsGenerationChangedError\";\n\t}\n}\n\nexport class AnalyticsRunFiles {\n\tprivate readonly createId: () => string;\n\tprivate readonly writeTimeoutMs: number;\n\tprivate readonly beforeAppend?: (generation: string, signal: AbortSignal) => Promise<void>;\n\tprivate readonly beforeCleanupEntry?: (signal?: AbortSignal) => Promise<void>;\n\tprivate readonly beforeReadFile?: (signal?: AbortSignal) => Promise<void>;\n\tprivate writerId: string;\n\tprivate mutationTail: Promise<void> = Promise.resolve();\n\tprivate readonly lifecycle = new AbortController();\n\tprivate closed = false;\n\n\tconstructor(\n\t\treadonly path: string,\n\t\toptions: {\n\t\t\tcreateId?: () => string;\n\t\t\twriteTimeoutMs?: number;\n\t\t\tbeforeAppend?: (generation: string, signal: AbortSignal) => Promise<void>;\n\t\t\tbeforeCleanupEntry?: (signal?: AbortSignal) => Promise<void>;\n\t\t\tbeforeReadFile?: (signal?: AbortSignal) => Promise<void>;\n\t\t} = {},\n\t) {\n\t\tthis.createId = options.createId ?? randomUUID;\n\t\tthis.writeTimeoutMs = options.writeTimeoutMs ?? DEFAULT_WRITE_TIMEOUT_MS;\n\t\tthis.beforeAppend = options.beforeAppend;\n\t\tthis.beforeCleanupEntry = options.beforeCleanupEntry;\n\t\tthis.beforeReadFile = options.beforeReadFile;\n\t\tthis.writerId = validCreatedId(this.createId());\n\t}\n\n\tappend(run: SettledRun, signal?: AbortSignal): Promise<void> {\n\t\tif (this.closed) return Promise.reject(new Error(\"Analytics storage is closed.\"));\n\t\tconst frame = encodeStoredRun(run);\n\t\treturn this.enqueueMutation(() =>\n\t\t\twithDeadline(signal, this.lifecycle.signal, this.writeTimeoutMs, (operationSignal) =>\n\t\t\t\tthis.appendFrame(frame, operationSignal),\n\t\t\t),\n\t\t);\n\t}\n\n\tasync *read(signal?: AbortSignal): AsyncIterable<SettledRun> {\n\t\tthrowIfAborted(signal);\n\t\tconst generation = await this.readOrCreateGeneration(signal);\n\t\tconst directory = this.generationPath(generation);\n\t\tlet entries: Dirent[];\n\t\ttry {\n\t\t\tentries = await readdir(directory, { withFileTypes: true });\n\t\t} catch (error) {\n\t\t\tif (isNodeError(error) && error.code === \"ENOENT\") {\n\t\t\t\tawait this.assertGenerationUnchanged(generation, signal);\n\t\t\t\tthrow new AnalyticsGenerationChangedError();\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\t\tlet count = 0;\n\t\tfor (const entry of entries.sort((left, right) => left.name.localeCompare(right.name))) {\n\t\t\tthrowIfAborted(signal);\n\t\t\tif (!entry.name.endsWith(\".jsonl\")) continue;\n\t\t\tconst filePath = path.join(directory, entry.name);\n\t\t\ttry {\n\t\t\t\tawait this.beforeReadFile?.(signal);\n\t\t\t\tthrowIfAborted(signal);\n\t\t\t\tawait assertPrivateRegularFile(filePath);\n\t\t\t\tfor await (const run of readFrames(filePath, signal)) {\n\t\t\t\t\tyield run;\n\t\t\t\t\tcount += 1;\n\t\t\t\t\tif (count % YIELD_EVERY_RECORDS === 0) await yieldToEventLoop(signal);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tif (isNodeError(error) && error.code === \"ENOENT\") {\n\t\t\t\t\tawait this.assertGenerationUnchanged(generation, signal);\n\t\t\t\t\tthrow new AnalyticsGenerationChangedError();\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\tawait this.assertGenerationUnchanged(generation, signal);\n\t}\n\n\tclear(signal?: AbortSignal): Promise<ClearAnalyticsResult> {\n\t\tif (this.closed) return Promise.reject(new Error(\"Analytics storage is closed.\"));\n\t\tlet result: ClearAnalyticsResult = { cleanupIncomplete: false };\n\t\treturn this.enqueueMutation(() =>\n\t\t\twithLinkedSignals(signal, this.lifecycle.signal, async (operationSignal) => {\n\t\t\t\tthrowIfAborted(operationSignal);\n\t\t\t\tawait this.readOrCreateGeneration(operationSignal);\n\t\t\t\tconst next = validCreatedId(this.createId());\n\t\t\t\tawait this.publishGeneration(next);\n\t\t\t\tthis.writerId = validCreatedId(this.createId());\n\t\t\t\tconst current = await readGenerationMarker(path.join(this.path, \"current\"));\n\t\t\t\tawait ensurePrivateDirectory(this.generationPath(current));\n\t\t\t\tif (!(await this.cleanupObsoleteGenerations(operationSignal))) {\n\t\t\t\t\tresult = { cleanupIncomplete: true };\n\t\t\t\t}\n\t\t\t}),\n\t\t).then(() => result);\n\t}\n\n\tasync close(): Promise<void> {\n\t\tif (this.closed) return;\n\t\tthis.closed = true;\n\t\tthis.lifecycle.abort(new DOMException(\"Analytics storage closed\", \"AbortError\"));\n\t\tawait this.mutationTail.catch(() => undefined);\n\t}\n\n\tprivate enqueueMutation(operation: () => Promise<void>): Promise<void> {\n\t\tconst result = this.mutationTail.then(operation);\n\t\tthis.mutationTail = result.catch(() => undefined);\n\t\treturn result;\n\t}\n\n\tprivate async appendFrame(frame: string, signal: AbortSignal): Promise<void> {\n\t\tthrowIfAborted(signal);\n\t\tlet obsoleteDirectory: string | undefined;\n\t\tfor (let attempt = 0; attempt < 3; attempt += 1) {\n\t\t\tconst generation = await this.readOrCreateGeneration(signal);\n\t\t\tconst directory = this.generationPath(generation);\n\t\t\tawait ensurePrivateDirectory(directory);\n\t\t\tconst filePath = path.join(directory, `${this.writerId}.jsonl`);\n\t\t\tawait assertOptionalPrivateRegularFile(filePath);\n\t\t\tthrowIfAborted(signal);\n\t\t\tawait this.beforeAppend?.(generation, signal);\n\t\t\tthrowIfAborted(signal);\n\t\t\ttry {\n\t\t\t\tawait writeFile(filePath, frame, {\n\t\t\t\t\tencoding: \"utf8\",\n\t\t\t\t\tflag: \"a\",\n\t\t\t\t\tmode: 0o600,\n\t\t\t\t\tsignal,\n\t\t\t\t});\n\t\t\t\tif (process.platform !== \"win32\") await chmod(filePath, 0o600);\n\t\t\t\tconst current = await readGenerationMarker(path.join(this.path, \"current\"), signal);\n\t\t\t\tif (current === generation) {\n\t\t\t\t\tif (obsoleteDirectory) {\n\t\t\t\t\t\tawait cleanupGeneration(obsoleteDirectory, signal).catch(() => undefined);\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tobsoleteDirectory = directory;\n\t\t\t} catch (error) {\n\t\t\t\tthis.writerId = validCreatedId(this.createId());\n\t\t\t\tthrowIfAborted(signal);\n\t\t\t\tif (!isNodeError(error) || error.code !== \"ENOENT\") throw error;\n\t\t\t}\n\t\t}\n\t\tthrow new AnalyticsGenerationChangedError();\n\t}\n\n\tprivate async readOrCreateGeneration(signal?: AbortSignal): Promise<string> {\n\t\tthrowIfAborted(signal);\n\t\tawait ensurePrivateDirectory(this.path);\n\t\tawait ensurePrivateDirectory(path.join(this.path, \"generations\"));\n\t\tconst markerPath = path.join(this.path, \"current\");\n\t\tfor (let attempt = 0; attempt < 3; attempt += 1) {\n\t\t\tlet generation: string;\n\t\t\ttry {\n\t\t\t\tgeneration = await readGenerationMarker(markerPath, signal);\n\t\t\t} catch (error) {\n\t\t\t\tif (!isNodeError(error) || error.code !== \"ENOENT\") throw error;\n\t\t\t\tgeneration = validCreatedId(this.createId());\n\t\t\t\tthrowIfAborted(signal);\n\t\t\t\ttry {\n\t\t\t\t\tawait createPrivateFile(markerPath, `${generation}\\n`);\n\t\t\t\t} catch (createError) {\n\t\t\t\t\tif (!isNodeError(createError) || createError.code !== \"EEXIST\") throw createError;\n\t\t\t\t\tgeneration = await readGenerationMarker(markerPath, signal);\n\t\t\t\t}\n\t\t\t}\n\t\t\tawait ensurePrivateDirectory(this.generationPath(generation));\n\t\t\tconst current = await readGenerationMarker(markerPath, signal);\n\t\t\tif (current === generation) return generation;\n\t\t}\n\t\tthrow new AnalyticsGenerationChangedError();\n\t}\n\n\tprivate async publishGeneration(generation: string): Promise<void> {\n\t\tconst markerPath = path.join(this.path, \"current\");\n\t\tconst temporaryPath = path.join(this.path, `.current.${validCreatedId(this.createId())}.tmp`);\n\t\tawait createPrivateFile(temporaryPath, `${generation}\\n`);\n\t\ttry {\n\t\t\tawait rename(temporaryPath, markerPath);\n\t\t\tif (process.platform !== \"win32\") await chmod(markerPath, 0o600);\n\t\t} catch (error) {\n\t\t\tawait rm(temporaryPath, { force: true }).catch(() => undefined);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tprivate async cleanupObsoleteGenerations(signal?: AbortSignal): Promise<boolean> {\n\t\tlet complete = true;\n\t\tconst root = path.join(this.path, \"generations\");\n\t\tfor (const entry of await readdir(root, { withFileTypes: true })) {\n\t\t\tconst active = await readGenerationMarker(path.join(this.path, \"current\"));\n\t\t\tif (entry.name === active) continue;\n\t\t\tif (!entry.isDirectory() || !GENERATION_PATTERN.test(entry.name)) {\n\t\t\t\tcomplete = false;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tawait cleanupGeneration(path.join(root, entry.name), signal, this.beforeCleanupEntry);\n\t\t\t} catch {\n\t\t\t\tcomplete = false;\n\t\t\t\tif (signal?.aborted) break;\n\t\t\t}\n\t\t}\n\t\tconst active = await readGenerationMarker(path.join(this.path, \"current\"));\n\t\tconst remaining = await readdir(root, { withFileTypes: true });\n\t\treturn complete && remaining.every((entry) => entry.isDirectory() && entry.name === active);\n\t}\n\n\tprivate async assertGenerationUnchanged(generation: string, signal?: AbortSignal): Promise<void> {\n\t\tconst current = await readGenerationMarker(path.join(this.path, \"current\"), signal);\n\t\tif (current !== generation) throw new AnalyticsGenerationChangedError();\n\t}\n\n\tprivate generationPath(generation: string): string {\n\t\treturn path.join(this.path, \"generations\", generation);\n\t}\n}\n\nasync function* readFrames(filePath: string, signal?: AbortSignal): AsyncIterable<SettledRun> {\n\tlet pending = \"\";\n\tconst stream = createReadStream(filePath, { encoding: \"utf8\", signal });\n\tfor await (const chunk of stream) {\n\t\tthrowIfAborted(signal);\n\t\tpending += String(chunk);\n\t\twhile (true) {\n\t\t\tconst newline = pending.indexOf(\"\\n\");\n\t\t\tif (newline < 0) break;\n\t\t\tconst line = pending.slice(0, newline);\n\t\t\tpending = pending.slice(newline + 1);\n\t\t\tif (!line) continue;\n\t\t\tyield decodeStoredRun(line);\n\t\t}\n\t\tif (Buffer.byteLength(pending) > MAX_STORED_RUN_BYTES) {\n\t\t\tthrow new AnalyticsStorageFormatError(\"Analytics record is too large to read safely.\");\n\t\t}\n\t}\n\t// A writer always terminates complete frames with a newline. An unterminated tail is a\n\t// crash residue and is ignored; this writer file will not be reused after its process exits.\n}\n\nasync function readGenerationMarker(markerPath: string, signal?: AbortSignal): Promise<string> {\n\tawait assertPrivateRegularFile(markerPath);\n\tthrowIfAborted(signal);\n\tconst value = (await readFile(markerPath, { encoding: \"utf8\", signal })).trim();\n\tif (!GENERATION_PATTERN.test(value)) {\n\t\tthrow new AnalyticsStorageFormatError(\"Analytics generation marker is invalid.\");\n\t}\n\treturn value;\n}\n\nasync function ensurePrivateDirectory(directoryPath: string): Promise<void> {\n\ttry {\n\t\tconst metadata = await lstat(directoryPath);\n\t\tif (!metadata.isDirectory() || metadata.isSymbolicLink()) {\n\t\t\tthrow new Error(\"Analytics storage paths must be regular directories, not links.\");\n\t\t}\n\t} catch (error) {\n\t\tif (!isNodeError(error) || error.code !== \"ENOENT\") throw error;\n\t\tawait mkdir(directoryPath, { recursive: true, mode: 0o700 });\n\t\tconst metadata = await lstat(directoryPath);\n\t\tif (!metadata.isDirectory() || metadata.isSymbolicLink()) {\n\t\t\tthrow new Error(\"Analytics storage paths must be regular directories, not links.\");\n\t\t}\n\t}\n\tif (process.platform !== \"win32\") await chmod(directoryPath, 0o700);\n}\n\nasync function assertOptionalPrivateRegularFile(filePath: string): Promise<void> {\n\ttry {\n\t\tawait assertPrivateRegularFile(filePath);\n\t} catch (error) {\n\t\tif (isNodeError(error) && error.code === \"ENOENT\") return;\n\t\tthrow error;\n\t}\n}\n\nasync function assertPrivateRegularFile(filePath: string): Promise<void> {\n\tconst metadata = await lstat(filePath);\n\tif (!metadata.isFile() || metadata.isSymbolicLink()) {\n\t\tthrow new Error(\"Analytics storage files must be regular files, not links.\");\n\t}\n\tif (process.platform !== \"win32\") await chmod(filePath, 0o600);\n}\n\nasync function createPrivateFile(filePath: string, content: string): Promise<void> {\n\tconst handle = await open(filePath, \"wx\", 0o600);\n\ttry {\n\t\tawait handle.writeFile(content, \"utf8\");\n\t\tawait handle.sync();\n\t} finally {\n\t\tawait handle.close();\n\t}\n}\n\nasync function cleanupGeneration(\n\tdirectoryPath: string,\n\tsignal?: AbortSignal,\n\tbeforeEntry?: (signal?: AbortSignal) => Promise<void>,\n): Promise<void> {\n\tthrowIfAborted(signal);\n\tlet entries: Dirent[];\n\ttry {\n\t\tentries = await readdir(directoryPath, { withFileTypes: true });\n\t} catch (error) {\n\t\tif (isNodeError(error) && error.code === \"ENOENT\") return;\n\t\tthrow error;\n\t}\n\tfor (const entry of entries) {\n\t\tthrowIfAborted(signal);\n\t\tawait beforeEntry?.(signal);\n\t\tthrowIfAborted(signal);\n\t\tif (!entry.isFile() || !entry.name.endsWith(\".jsonl\")) {\n\t\t\tthrow new Error(\"Analytics generation contains an unexpected storage entry.\");\n\t\t}\n\t\tawait unlink(path.join(directoryPath, entry.name));\n\t}\n\tthrowIfAborted(signal);\n\tawait rmdir(directoryPath);\n}\n\nasync function withLinkedSignals<T>(\n\tcallerSignal: AbortSignal | undefined,\n\tlifecycleSignal: AbortSignal,\n\toperation: (signal: AbortSignal) => Promise<T>,\n): Promise<T> {\n\tthrowIfAborted(callerSignal);\n\tthrowIfAborted(lifecycleSignal);\n\tconst controller = new AbortController();\n\tconst abort = (signal: AbortSignal) =>\n\t\tcontroller.abort(\n\t\t\tsignal.reason ?? new DOMException(\"Analytics operation aborted\", \"AbortError\"),\n\t\t);\n\tconst callerAbort = () => callerSignal && abort(callerSignal);\n\tconst lifecycleAbort = () => abort(lifecycleSignal);\n\tcallerSignal?.addEventListener(\"abort\", callerAbort, { once: true });\n\tlifecycleSignal.addEventListener(\"abort\", lifecycleAbort, { once: true });\n\ttry {\n\t\treturn await operation(controller.signal);\n\t} finally {\n\t\tcallerSignal?.removeEventListener(\"abort\", callerAbort);\n\t\tlifecycleSignal.removeEventListener(\"abort\", lifecycleAbort);\n\t}\n}\n\nasync function withDeadline<T>(\n\tcallerSignal: AbortSignal | undefined,\n\tlifecycleSignal: AbortSignal,\n\ttimeoutMs: number,\n\toperation: (signal: AbortSignal) => Promise<T>,\n): Promise<T> {\n\tthrowIfAborted(callerSignal);\n\tthrowIfAborted(lifecycleSignal);\n\tconst controller = new AbortController();\n\tconst abort = (signal: AbortSignal) =>\n\t\tcontroller.abort(\n\t\t\tsignal.reason ?? new DOMException(\"Analytics operation aborted\", \"AbortError\"),\n\t\t);\n\tconst callerAbort = () => callerSignal && abort(callerSignal);\n\tconst lifecycleAbort = () => abort(lifecycleSignal);\n\tcallerSignal?.addEventListener(\"abort\", callerAbort, { once: true });\n\tlifecycleSignal.addEventListener(\"abort\", lifecycleAbort, { once: true });\n\tconst timer = setTimeout(\n\t\t() => controller.abort(new DOMException(\"Analytics write timed out\", \"TimeoutError\")),\n\t\tMath.max(1, timeoutMs),\n\t);\n\ttry {\n\t\treturn await operation(controller.signal);\n\t} catch (error) {\n\t\tif (\n\t\t\tcontroller.signal.aborted &&\n\t\t\terror instanceof Error &&\n\t\t\terror.name === \"AbortError\" &&\n\t\t\terror.cause === controller.signal.reason\n\t\t) {\n\t\t\tthrow controller.signal.reason;\n\t\t}\n\t\tthrow error;\n\t} finally {\n\t\tclearTimeout(timer);\n\t\tcallerSignal?.removeEventListener(\"abort\", callerAbort);\n\t\tlifecycleSignal.removeEventListener(\"abort\", lifecycleAbort);\n\t}\n}\n\nasync function yieldToEventLoop(signal?: AbortSignal): Promise<void> {\n\tawait new Promise<void>((resolve) => setImmediate(resolve));\n\tthrowIfAborted(signal);\n}\n\nfunction validCreatedId(value: string): string {\n\tif (!GENERATION_PATTERN.test(value)) throw new Error(\"Analytics storage received an invalid ID.\");\n\treturn value;\n}\n\nfunction throwIfAborted(signal?: AbortSignal): void {\n\tif (signal?.aborted) {\n\t\tthrow signal.reason ?? new DOMException(\"Analytics operation aborted\", \"AbortError\");\n\t}\n}\n\nfunction isNodeError(error: unknown): error is NodeJS.ErrnoException {\n\treturn error instanceof Error && \"code\" in error;\n}\n", "import type {\n\tGenerationOutcome,\n\tGenerationRecord,\n\tProviderErrorCategory,\n\tProviderErrorRecord,\n\tProviderResponseRecord,\n\tRunOutcome,\n\tSettledRun,\n\tSkillActivationRecord,\n\tToolCallRecord,\n} from \"../types.js\";\n\nexport const MAX_STORED_RUN_BYTES = 1024 * 1024;\nconst MAX_STRING_LENGTH = 4096;\nconst MAX_NESTED_RECORDS = 20_000;\nconst TRIGGER_SOURCES = [\"interactive\", \"rpc\", \"extension\", \"unknown\"] as const;\nconst RUN_OUTCOMES = [\n\t\"success\",\n\t\"recovered_success\",\n\t\"error\",\n\t\"aborted\",\n\t\"length\",\n\t\"interrupted\",\n] as const;\nconst GENERATION_OUTCOMES = [\n\t\"pending\",\n\t\"stop\",\n\t\"tool_use\",\n\t\"error\",\n\t\"aborted\",\n\t\"length\",\n\t\"interrupted\",\n] as const;\nconst ERROR_CATEGORIES = [\n\t\"dns\",\n\t\"timeout\",\n\t\"connection_refused\",\n\t\"connection_reset\",\n\t\"tls\",\n\t\"network_other\",\n\t\"provider_other\",\n] as const;\n\nexport class AnalyticsStorageFormatError extends Error {\n\tconstructor(message: string, options: { cause?: unknown } = {}) {\n\t\tsuper(message, options);\n\t\tthis.name = \"AnalyticsStorageFormatError\";\n\t}\n}\n\nexport function encodeStoredRun(run: SettledRun): string {\n\tconst encoded = `${JSON.stringify({\n\t\tformatVersion: 1,\n\t\trun: parseRun(run, { remaining: MAX_NESTED_RECORDS }),\n\t})}\\n`;\n\tif (Buffer.byteLength(encoded) > MAX_STORED_RUN_BYTES) {\n\t\tthrow new AnalyticsStorageFormatError(\"Analytics record is too large to store safely.\");\n\t}\n\treturn encoded;\n}\n\nexport function decodeStoredRun(line: string): SettledRun {\n\tif (Buffer.byteLength(line) > MAX_STORED_RUN_BYTES) {\n\t\tthrow new AnalyticsStorageFormatError(\"Analytics record is too large to read safely.\");\n\t}\n\tlet value: unknown;\n\ttry {\n\t\tvalue = JSON.parse(line);\n\t} catch (error) {\n\t\tthrow new AnalyticsStorageFormatError(\"Analytics record contains invalid JSON.\", {\n\t\t\tcause: error,\n\t\t});\n\t}\n\tconst envelope = asRecord(value, \"analytics record\");\n\tif (envelope.formatVersion !== 1) {\n\t\tthrow new AnalyticsStorageFormatError(\"Analytics record uses an unsupported format version.\");\n\t}\n\treturn parseRun(envelope.run, { remaining: MAX_NESTED_RECORDS });\n}\n\ninterface ParseBudget {\n\tremaining: number;\n}\n\nfunction parseRun(value: unknown, budget: ParseBudget): SettledRun {\n\tconst run = asRecord(value, \"run\");\n\treturn {\n\t\tid: requiredString(run.id, \"run.id\"),\n\t\tstartedAtMs: timestampValue(run.startedAtMs, \"run.startedAtMs\"),\n\t\tfinishedAtMs: timestampValue(run.finishedAtMs, \"run.finishedAtMs\"),\n\t\tdurationMs: durationValue(run.durationMs, \"run.durationMs\"),\n\t\ttriggerSource: enumValue(run.triggerSource, TRIGGER_SOURCES, \"run.triggerSource\"),\n\t\t...optionalProperty(\n\t\t\t\"initialProvider\",\n\t\t\toptionalString(run.initialProvider, \"run.initialProvider\"),\n\t\t),\n\t\t...optionalProperty(\"initialModel\", optionalString(run.initialModel, \"run.initialModel\")),\n\t\toutcome: enumValue(run.outcome, RUN_OUTCOMES, \"run.outcome\") as RunOutcome,\n\t\tattemptCount: boundedCount(run.attemptCount, \"run.attemptCount\"),\n\t\tgenerations: boundedArray(run.generations, \"run.generations\", budget).map((item, index) =>\n\t\t\tparseGeneration(item, index, budget),\n\t\t),\n\t\ttools: boundedArray(run.tools, \"run.tools\", budget).map(parseTool),\n\t\tskills: boundedArray(run.skills, \"run.skills\", budget).map(parseSkill),\n\t\tproviderErrors: boundedArray(run.providerErrors, \"run.providerErrors\", budget).map(\n\t\t\tparseProviderError,\n\t\t),\n\t\ttoolErrorCount: boundedCount(run.toolErrorCount, \"run.toolErrorCount\"),\n\t\tproviderErrorCount: boundedCount(run.providerErrorCount, \"run.providerErrorCount\"),\n\t\trecoveredErrorCount: boundedCount(run.recoveredErrorCount, \"run.recoveredErrorCount\"),\n\t};\n}\n\nfunction parseGeneration(value: unknown, index: number, budget: ParseBudget): GenerationRecord {\n\tconst item = asRecord(value, `run.generations[${index}]`);\n\tconst prefix = `run.generations[${index}]`;\n\treturn {\n\t\tid: requiredString(item.id, `${prefix}.id`),\n\t\tordinal: boundedCount(item.ordinal, `${prefix}.ordinal`),\n\t\t...optionalProperty(\"provider\", optionalString(item.provider, `${prefix}.provider`)),\n\t\t...optionalProperty(\"model\", optionalString(item.model, `${prefix}.model`)),\n\t\t...optionalProperty(\n\t\t\t\"thinkingLevel\",\n\t\t\toptionalString(item.thinkingLevel, `${prefix}.thinkingLevel`),\n\t\t),\n\t\tstartedAtMs: timestampValue(item.startedAtMs, `${prefix}.startedAtMs`),\n\t\t...optionalProperty(\n\t\t\t\"finishedAtMs\",\n\t\t\toptionalTimestamp(item.finishedAtMs, `${prefix}.finishedAtMs`),\n\t\t),\n\t\t...optionalProperty(\"durationMs\", optionalDuration(item.durationMs, `${prefix}.durationMs`)),\n\t\t...optionalProperty(\"stopReason\", optionalString(item.stopReason, `${prefix}.stopReason`)),\n\t\toutcome: enumValue(item.outcome, GENERATION_OUTCOMES, `${prefix}.outcome`) as GenerationOutcome,\n\t\tresponses: boundedArray(item.responses, `${prefix}.responses`, budget).map(\n\t\t\tparseProviderResponse,\n\t\t),\n\t};\n}\n\nfunction parseProviderResponse(value: unknown, index: number): ProviderResponseRecord {\n\tconst item = asRecord(value, `provider response ${index}`);\n\treturn {\n\t\tordinal: boundedCount(item.ordinal, \"providerResponse.ordinal\"),\n\t\toccurredAtMs: timestampValue(item.occurredAtMs, \"providerResponse.occurredAtMs\"),\n\t\tstatus: boundedInteger(item.status, \"providerResponse.status\", 999),\n\t};\n}\n\nfunction parseTool(value: unknown, index: number): ToolCallRecord {\n\tconst item = asRecord(value, `run.tools[${index}]`);\n\tconst prefix = `run.tools[${index}]`;\n\tconst ordinal = boundedCount(item.ordinal, `${prefix}.ordinal`);\n\treturn {\n\t\tid: `tool-${ordinal}`,\n\t\tordinal,\n\t\tname: requiredString(item.name, `${prefix}.name`),\n\t\t...optionalProperty(\"provider\", optionalString(item.provider, `${prefix}.provider`)),\n\t\t...optionalProperty(\"model\", optionalString(item.model, `${prefix}.model`)),\n\t\tstartedAtMs: timestampValue(item.startedAtMs, `${prefix}.startedAtMs`),\n\t\t...optionalProperty(\n\t\t\t\"finishedAtMs\",\n\t\t\toptionalTimestamp(item.finishedAtMs, `${prefix}.finishedAtMs`),\n\t\t),\n\t\t...optionalProperty(\"durationMs\", optionalDuration(item.durationMs, `${prefix}.durationMs`)),\n\t\tisError: booleanValue(item.isError, `${prefix}.isError`),\n\t\tcompletionState: enumValue(\n\t\t\titem.completionState,\n\t\t\t[\"running\", \"finished\", \"interrupted\"] as const,\n\t\t\t`${prefix}.completionState`,\n\t\t),\n\t};\n}\n\nfunction parseSkill(value: unknown, index: number): SkillActivationRecord {\n\tconst item = asRecord(value, `run.skills[${index}]`);\n\tconst prefix = `run.skills[${index}]`;\n\treturn {\n\t\tid: requiredString(item.id, `${prefix}.id`),\n\t\tname: requiredString(item.name, `${prefix}.name`),\n\t\tinitiatedBy: enumValue(item.initiatedBy, [\"user\", \"model\"] as const, `${prefix}.initiatedBy`),\n\t\toccurredAtMs: timestampValue(item.occurredAtMs, `${prefix}.occurredAtMs`),\n\t\t...optionalProperty(\"provider\", optionalString(item.provider, `${prefix}.provider`)),\n\t\t...optionalProperty(\"model\", optionalString(item.model, `${prefix}.model`)),\n\t};\n}\n\nfunction parseProviderError(value: unknown, index: number): ProviderErrorRecord {\n\tconst item = asRecord(value, `run.providerErrors[${index}]`);\n\tconst prefix = `run.providerErrors[${index}]`;\n\treturn {\n\t\tid: requiredString(item.id, `${prefix}.id`),\n\t\t...optionalProperty(\n\t\t\t\"generationId\",\n\t\t\toptionalString(item.generationId, `${prefix}.generationId`),\n\t\t),\n\t\toccurredAtMs: timestampValue(item.occurredAtMs, `${prefix}.occurredAtMs`),\n\t\t...optionalProperty(\"provider\", optionalString(item.provider, `${prefix}.provider`)),\n\t\t...optionalProperty(\"model\", optionalString(item.model, `${prefix}.model`)),\n\t\tcategory: enumValue(\n\t\t\titem.category,\n\t\t\tERROR_CATEGORIES,\n\t\t\t`${prefix}.category`,\n\t\t) as ProviderErrorCategory,\n\t\trecovered: booleanValue(item.recovered, `${prefix}.recovered`),\n\t\tterminal: booleanValue(item.terminal, `${prefix}.terminal`),\n\t};\n}\n\nfunction asRecord(value: unknown, name: string): Record<string, unknown> {\n\tif (typeof value !== \"object\" || value === null || Array.isArray(value)) invalid(name);\n\treturn value as Record<string, unknown>;\n}\n\nfunction boundedArray(value: unknown, name: string, budget: ParseBudget): unknown[] {\n\tif (!Array.isArray(value)) invalid(name);\n\tbudget.remaining -= value.length;\n\tif (budget.remaining < 0) {\n\t\tthrow new AnalyticsStorageFormatError(\"Analytics record is too large to process safely.\");\n\t}\n\treturn value;\n}\n\nfunction requiredString(value: unknown, name: string): string {\n\tif (typeof value !== \"string\" || value.length === 0 || value.length > MAX_STRING_LENGTH) {\n\t\tinvalid(name);\n\t}\n\treturn value;\n}\n\nfunction optionalString(value: unknown, name: string): string | undefined {\n\treturn value === undefined ? undefined : requiredString(value, name);\n}\n\nfunction boundedInteger(value: unknown, name: string, maximum: number): number {\n\tif (typeof value !== \"number\" || !Number.isSafeInteger(value) || value < 0 || value > maximum) {\n\t\tinvalid(name);\n\t}\n\treturn value;\n}\n\nfunction timestampValue(value: unknown, name: string): number {\n\treturn boundedInteger(value, name, Number.MAX_SAFE_INTEGER);\n}\n\nfunction optionalTimestamp(value: unknown, name: string): number | undefined {\n\treturn value === undefined ? undefined : timestampValue(value, name);\n}\n\nfunction durationValue(value: unknown, name: string): number {\n\treturn boundedInteger(value, name, Math.floor(Number.MAX_SAFE_INTEGER / MAX_NESTED_RECORDS));\n}\n\nfunction optionalDuration(value: unknown, name: string): number | undefined {\n\treturn value === undefined ? undefined : durationValue(value, name);\n}\n\nfunction boundedCount(value: unknown, name: string): number {\n\treturn boundedInteger(value, name, MAX_NESTED_RECORDS);\n}\n\nfunction booleanValue(value: unknown, name: string): boolean {\n\tif (typeof value !== \"boolean\") invalid(name);\n\treturn value;\n}\n\nfunction enumValue<const T extends readonly string[]>(\n\tvalue: unknown,\n\tvalues: T,\n\tname: string,\n): T[number] {\n\tif (typeof value !== \"string\" || !values.includes(value)) invalid(name);\n\treturn value as T[number];\n}\n\nfunction optionalProperty<K extends string, T>(key: K, value: T | undefined): { [P in K]?: T } {\n\treturn value === undefined ? {} : ({ [key]: value } as { [P in K]?: T });\n}\n\nfunction invalid(name: string): never {\n\tthrow new AnalyticsStorageFormatError(`Analytics record has an invalid ${name}.`);\n}\n", "import type { SettledRun } from \"../types.js\";\nimport {\n\tAnalyticsGenerationChangedError,\n\tAnalyticsRunFiles,\n\ttype ClearAnalyticsResult,\n} from \"./files.js\";\nimport { type AnalyticsSnapshot, querySnapshot, type TimeRange } from \"./queries.js\";\n\nexport class AnalyticsStore {\n\tprivate readonly files: AnalyticsRunFiles;\n\n\tconstructor(\n\t\trootPath: string,\n\t\tdependencies: {\n\t\t\tfiles?: AnalyticsRunFiles;\n\t\t\tcreateId?: () => string;\n\t\t\twriteTimeoutMs?: number;\n\t\t} = {},\n\t) {\n\t\tthis.files =\n\t\t\tdependencies.files ??\n\t\t\tnew AnalyticsRunFiles(rootPath, {\n\t\t\t\tcreateId: dependencies.createId,\n\t\t\t\twriteTimeoutMs: dependencies.writeTimeoutMs,\n\t\t\t});\n\t}\n\n\tget path(): string {\n\t\treturn this.files.path;\n\t}\n\n\trecordRun(run: SettledRun, signal?: AbortSignal): Promise<void> {\n\t\treturn this.files.append(run, signal);\n\t}\n\n\tasync getSnapshot(range: TimeRange, signal?: AbortSignal): Promise<AnalyticsSnapshot> {\n\t\tfor (let attempt = 0; attempt < 2; attempt += 1) {\n\t\t\ttry {\n\t\t\t\treturn await querySnapshot(this.files.read(signal), range, signal);\n\t\t\t} catch (error) {\n\t\t\t\tif (!(error instanceof AnalyticsGenerationChangedError) || attempt > 0) throw error;\n\t\t\t}\n\t\t}\n\t\tthrow new AnalyticsGenerationChangedError();\n\t}\n\n\tclearAll(signal?: AbortSignal): Promise<ClearAnalyticsResult> {\n\t\treturn this.files.clear(signal);\n\t}\n\n\tclose(): Promise<void> {\n\t\treturn this.files.close();\n\t}\n}\n"],
5
- "mappings": ";;;;AAAA,SAAS,cAAAA,mBAAkB;AAC3B,OAAOC,WAAU;AACjB;AAAA,EAGC;AAAA,OACM;;;ACNP,SAAS,kBAAkB;;;ACEpB,SAAS,sBAAsB,SAAoD;AACzF,QAAM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IAAI,aAAa,kCAAkC,YAAY;AAAA,MACtE;AAAA,IACD;AAAA,EACD;AACD;AAEA,SAAS,cAAc,KAAuB,IAA6C;AAC1F,MAAI,CAAC,IAAI,MAAO,QAAO;AACvB,SAAO;AAAA,IACN,UAAU,IAAI,MAAM;AAAA,IACpB,OAAO,IAAI,MAAM;AAAA,IACjB,eAAe,GAAG,iBAAiB;AAAA,EACpC;AACD;AAEO,SAAS,kBAAkB,IAA2B;AAC5D,QAAM,OAAO,GAAG,YAAY,EAAE,KAAK,CAAC,EAAE,KAAK,MAAM,SAAS,MAAM;AAChE,SAAO,MAAM,WAAW,WAAW;AACpC;AAEA,SAAS,gBACR,IACA,cAC4C;AAC5C,QAAM,SAAS,CAAC,GAAG,YAAY;AAC/B,QAAM,OAAO,IAAI,IAAI,OAAO,IAAI,CAAC,EAAE,KAAK,MAAM,IAAI,CAAC;AACnD,QAAM,cAAe,GACnB;AACF,aAAW,WAAW,OAAO,gBAAgB,aAAa,YAAY,KAAK,EAAE,IAAI,CAAC,GAAG;AACpF,QAAI,QAAQ,WAAW,WAAW,KAAK,IAAI,QAAQ,KAAK,QAAQ,YAAY,EAAE,CAAC,EAAG;AAClF,UAAM,OAAO,QAAQ,KAAK,QAAQ,YAAY,EAAE;AAChD,SAAK,IAAI,IAAI;AACb,WAAO,KAAK,EAAE,MAAM,UAAU,QAAQ,WAAW,KAAK,CAAC;AAAA,EACxD;AACA,SAAO;AACR;AAEA,SAAS,qBAA6B;AACrC,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,EACD,EAAE,KAAK,IAAI;AACZ;AAEA,SAAS,WAAW,KAAuB,SAAiB,OAAiC;AAC5F,MAAI;AACH,QAAI,GAAG,OAAO,SAAS,KAAK;AAAA,EAC7B,QAAQ;AAAA,EAER;AACD;AAEA,IAAO,oBAAQ,yBAAyB;",
4
+ "sourcesContent": ["import { randomUUID } from \"node:crypto\";\nimport path from \"node:path\";\nimport { type ExtensionAPI, type ExtensionContext, getAgentDir } from \"@earendil-works/pi-coding-agent\";\nimport { ResponseCollector } from \"./collector.js\";\nimport { type AnalyticsMenuDataSource, showAnalyticsMenu } from \"./menu.js\";\nimport { SkillTracker } from \"./skills.js\";\nimport type { ClearAnalyticsResult } from \"./storage/files.js\";\nimport type { AnalyticsSnapshot, TimeRange } from \"./storage/queries.js\";\nimport { AnalyticsStore } from \"./storage/store.js\";\nimport type { ModelIdentity, SettledRun, TriggerSource } from \"./types.js\";\n\ninterface PendingProviderGeneration {\n id: string;\n startedAtMs: number;\n model?: ModelIdentity;\n responses: Array<{ status: number; occurredAtMs: number }>;\n}\n\nconst STORAGE_DIRECTORY = \"pi-analytics\";\n\nexport interface AnalyticsStorePort {\n readonly path: string;\n recordRun(run: SettledRun, signal?: AbortSignal): Promise<void>;\n getSnapshot(range: TimeRange, signal?: AbortSignal): Promise<AnalyticsSnapshot>;\n clearAll(signal?: AbortSignal): Promise<ClearAnalyticsResult>;\n close(): Promise<void>;\n}\n\ninterface AnalyticsDependencies {\n createStore(path: string): AnalyticsStorePort;\n createSkillTracker(cwd: string): SkillTracker;\n getAgentDir(): string;\n now(): number;\n createId(): string;\n}\n\nexport function createAnalyticsExtension(\n dependencies: Partial<AnalyticsDependencies> = {},\n): (pi: ExtensionAPI) => void {\n const deps: AnalyticsDependencies = {\n createStore: dependencies.createStore ?? ((rootPath) => new AnalyticsStore(rootPath)),\n createSkillTracker: dependencies.createSkillTracker ?? ((cwd) => new SkillTracker(cwd)),\n getAgentDir: dependencies.getAgentDir ?? getAgentDir,\n now: dependencies.now ?? Date.now,\n createId: dependencies.createId ?? randomUUID,\n };\n\n return function analyticsExtension(pi: ExtensionAPI): void {\n let sessionGeneration = 0;\n let sessionController = new AbortController();\n let collector = new ResponseCollector();\n let skillTracker: SkillTracker | undefined;\n let store: AnalyticsStorePort | undefined;\n let storageFailure: string | undefined;\n const retiredCloseTasks = new Set<Promise<boolean>>();\n let writeFailureActive = false;\n let pendingTriggerSource: TriggerSource = \"unknown\";\n let pendingAttemptWithoutRun = false;\n let pendingProviderGeneration: PendingProviderGeneration | undefined;\n\n pi.registerCommand(\"analytics\", {\n description: \"Open local Pi usage analytics\",\n handler: async (args, ctx) => {\n if (args.trim()) {\n if (!ctx.hasUI || (ctx.mode !== \"tui\" && ctx.mode !== \"rpc\")) {\n throw new Error(\"/analytics does not accept arguments.\");\n }\n ctx.ui.notify(\"/analytics does not accept arguments.\", \"warning\");\n return;\n }\n if (!ctx.hasUI || (ctx.mode !== \"tui\" && ctx.mode !== \"rpc\")) {\n throw new Error(\"/analytics requires Pi TUI or RPC mode.\");\n }\n const generation = sessionGeneration;\n const owner = sessionController;\n const source = menuSource(generation, owner.signal);\n await showAnalyticsMenu(ctx, source, {\n signal: owner.signal,\n isCurrent: () => generation === sessionGeneration && !owner.signal.aborted,\n });\n },\n });\n\n pi.on(\"session_start\", (_event, ctx) => {\n ++sessionGeneration;\n const previousStore = store;\n sessionController.abort(new DOMException(\"Analytics session replaced\", \"AbortError\"));\n if (previousStore) retire(previousStore);\n sessionController = new AbortController();\n collector = new ResponseCollector();\n skillTracker = deps.createSkillTracker(ctx.cwd);\n store = undefined;\n storageFailure = undefined;\n writeFailureActive = false;\n pendingTriggerSource = \"unknown\";\n pendingAttemptWithoutRun = false;\n pendingProviderGeneration = undefined;\n const storageRoot = path.join(deps.getAgentDir(), STORAGE_DIRECTORY);\n try {\n store = deps.createStore(storageRoot);\n } catch {\n storageFailure = unavailableMessage();\n safeNotify(ctx, storageFailure, \"warning\");\n }\n });\n\n pi.on(\"input\", (event, ctx) => {\n const now = deps.now();\n const tracker = skillTracker;\n tracker?.observeInput(event.text, event.source, now);\n if (event.source !== \"extension\") pendingTriggerSource = event.source;\n if (!tracker || !collector.hasActiveRun()) return;\n const explicit = tracker.consumeExplicitSkill();\n if (!explicit || !tracker.hasAvailableSkill(explicit.name)) return;\n collector.activateSkill({\n name: explicit.name,\n initiatedBy: \"user\",\n now: explicit.observedAtMs,\n model: modelIdentity(ctx, pi),\n });\n });\n\n pi.on(\"before_agent_start\", async (event, ctx) => {\n // A cache warm has provider hooks but no assistant lifecycle. Drop any unclaimed\n // warm metadata when the next real agent run begins instead of classifying by timing.\n pendingProviderGeneration = undefined;\n const generation = sessionGeneration;\n const tracker = skillTracker;\n const activeCollector = collector;\n if (!tracker) return;\n const skills = availableSkills(pi, event.systemPromptOptions.skills ?? []);\n await tracker.setAvailableSkills(skills);\n if (generation !== sessionGeneration || tracker !== skillTracker || activeCollector !== collector) {\n return;\n }\n const explicit = tracker.consumeExplicitSkill();\n const interrupted = activeCollector.begin({\n id: deps.createId(),\n now: deps.now(),\n triggerSource: explicit?.source ?? pendingTriggerSource,\n model: modelIdentity(ctx, pi),\n });\n pendingTriggerSource = \"unknown\";\n if (interrupted) {\n await persistRun(interrupted, ctx, generation, sessionController.signal);\n if (generation !== sessionGeneration || tracker !== skillTracker || activeCollector !== collector) {\n return;\n }\n }\n if (explicit && skills.some(({ name }) => name === explicit.name)) {\n activeCollector.activateSkill({\n name: explicit.name,\n initiatedBy: \"user\",\n now: explicit.observedAtMs,\n model: modelIdentity(ctx, pi),\n });\n }\n });\n\n pi.on(\"agent_start\", () => {\n if (collector.hasActiveRun()) collector.beginAttempt();\n else pendingAttemptWithoutRun = true;\n });\n\n pi.on(\"turn_start\", (_event, ctx) => ensureRun(ctx, \"extension\"));\n\n pi.on(\"before_provider_request\", (_event, ctx) => {\n pendingProviderGeneration = {\n id: deps.createId(),\n startedAtMs: deps.now(),\n model: modelIdentity(ctx, pi),\n responses: [],\n };\n });\n\n pi.on(\"after_provider_response\", (event) => {\n pendingProviderGeneration?.responses.push({ status: event.status, occurredAtMs: deps.now() });\n });\n\n pi.on(\"message_start\", (event, ctx) => {\n if (event.message.role === \"assistant\") claimPendingProviderGeneration(ctx);\n });\n\n pi.on(\"message_end\", (event, ctx) => {\n if (event.message.role !== \"assistant\") return;\n claimPendingProviderGeneration(ctx);\n collector.finishGeneration({\n now: deps.now(),\n stopReason: event.message.stopReason,\n errorMessage: event.message.errorMessage,\n });\n });\n\n pi.on(\"tool_execution_start\", (event, ctx) => {\n ensureRun(ctx, \"extension\");\n collector.beginTool({\n id: event.toolCallId,\n name: event.toolName,\n now: deps.now(),\n model: modelIdentity(ctx, pi),\n });\n });\n\n pi.on(\"tool_result\", async (event, ctx) => {\n if (event.toolName === \"read\" && !isBuiltinReadTool(pi)) return;\n const generation = sessionGeneration;\n const tracker = skillTracker;\n const activeCollector = collector;\n const runId = activeCollector.getActiveRunId();\n if (!tracker || !runId) return;\n const name = await tracker.matchSuccessfulRead({\n toolName: event.toolName,\n input: event.input,\n isError: event.isError,\n });\n if (\n !name ||\n generation !== sessionGeneration ||\n tracker !== skillTracker ||\n activeCollector !== collector ||\n activeCollector.getActiveRunId() !== runId\n ) {\n return;\n }\n activeCollector.activateSkill({\n name,\n initiatedBy: \"model\",\n now: deps.now(),\n model: modelIdentity(ctx, pi),\n });\n });\n\n pi.on(\"tool_execution_end\", (event) => {\n collector.finishTool({ id: event.toolCallId, now: deps.now(), isError: event.isError });\n });\n\n pi.on(\"agent_settled\", async (_event, ctx) => {\n const generation = sessionGeneration;\n const owner = sessionController;\n const run = collector.settle(deps.now());\n pendingAttemptWithoutRun = false;\n pendingProviderGeneration = undefined;\n pendingTriggerSource = \"unknown\";\n skillTracker?.clearPending();\n if (run) await persistRun(run, ctx, generation, owner.signal);\n });\n\n pi.on(\"session_shutdown\", async (_event, ctx) => {\n const activeStore = store;\n ++sessionGeneration;\n sessionController.abort(new DOMException(\"Analytics session shut down\", \"AbortError\"));\n skillTracker?.clearPending();\n skillTracker = undefined;\n store = undefined;\n pendingProviderGeneration = undefined;\n collector.interrupt(deps.now());\n const closing = activeStore ? [closeResult(activeStore), ...retiredCloseTasks] : [...retiredCloseTasks];\n const results = await Promise.all(closing);\n if (results.some((closed) => !closed)) {\n safeNotify(ctx, \"Analytics storage shutdown was incomplete.\", \"warning\");\n }\n });\n\n function retire(retiredStore: AnalyticsStorePort): void {\n const task = closeResult(retiredStore).finally(() => retiredCloseTasks.delete(task));\n retiredCloseTasks.add(task);\n }\n\n async function closeResult(activeStore: AnalyticsStorePort): Promise<boolean> {\n try {\n await activeStore.close();\n return true;\n } catch {\n return false;\n }\n }\n\n function claimPendingProviderGeneration(ctx: ExtensionContext): void {\n const pending = pendingProviderGeneration;\n if (!pending) return;\n pendingProviderGeneration = undefined;\n ensureRun(ctx, \"extension\");\n collector.beginGeneration({\n id: pending.id,\n now: pending.startedAtMs,\n model: pending.model,\n });\n for (const response of pending.responses) {\n collector.recordProviderResponse({ status: response.status, now: response.occurredAtMs });\n }\n }\n\n function ensureRun(ctx: ExtensionContext, triggerSource: TriggerSource): void {\n if (collector.hasActiveRun()) return;\n collector.begin({\n id: deps.createId(),\n now: deps.now(),\n triggerSource,\n model: modelIdentity(ctx, pi),\n });\n if (pendingAttemptWithoutRun) {\n pendingAttemptWithoutRun = false;\n collector.beginAttempt();\n }\n }\n\n async function persistRun(\n run: SettledRun,\n ctx: ExtensionContext,\n generation: number,\n signal: AbortSignal,\n ): Promise<void> {\n const activeStore = store;\n if (!activeStore || signal.aborted) return;\n try {\n await activeStore.recordRun(run, signal);\n if (generation !== sessionGeneration || activeStore !== store || signal.aborted) return;\n if (writeFailureActive) {\n writeFailureActive = false;\n safeNotify(ctx, \"Local analytics storage recovered.\", \"info\");\n }\n } catch {\n if (generation !== sessionGeneration || activeStore !== store || signal.aborted || writeFailureActive) {\n return;\n }\n writeFailureActive = true;\n safeNotify(ctx, \"Analytics could not save this response cycle; its metrics were dropped.\", \"warning\");\n }\n }\n\n function menuSource(generation: number, signal: AbortSignal): AnalyticsMenuDataSource {\n return {\n path: store?.path ?? path.join(deps.getAgentDir(), STORAGE_DIRECTORY),\n async load(range, actionSignal) {\n assertCurrent(generation, signal);\n const activeStore = store;\n if (!activeStore) {\n return { kind: \"unavailable\", message: storageFailure ?? unavailableMessage() };\n }\n const snapshot = await activeStore.getSnapshot(range, actionSignal);\n assertCurrent(generation, signal);\n return { kind: \"ready\", snapshot };\n },\n async clearAll(actionSignal) {\n assertCurrent(generation, signal);\n const activeStore = store;\n if (!activeStore) return { cleanupIncomplete: false };\n return activeStore.clearAll(actionSignal);\n },\n };\n }\n\n function assertCurrent(generation: number, signal: AbortSignal): void {\n if (generation !== sessionGeneration || signal.aborted) {\n throw new DOMException(\"Analytics interaction replaced\", \"AbortError\");\n }\n }\n };\n}\n\nfunction modelIdentity(ctx: ExtensionContext, pi: ExtensionAPI): ModelIdentity | undefined {\n if (!ctx.model) return undefined;\n return {\n provider: ctx.model.provider,\n model: ctx.model.id,\n thinkingLevel: pi.getThinkingLevel(),\n };\n}\n\nexport function isBuiltinReadTool(pi: ExtensionAPI): boolean {\n const read = pi.getAllTools().find(({ name }) => name === \"read\");\n return read?.sourceInfo.source === \"builtin\";\n}\n\nfunction availableSkills(\n pi: ExtensionAPI,\n systemSkills: ReadonlyArray<{ name: string; filePath: string }>,\n): Array<{ name: string; filePath: string }> {\n const result = [...systemSkills];\n const seen = new Set(result.map(({ name }) => name));\n const getCommands = (pi as ExtensionAPI & { getCommands?: ExtensionAPI[\"getCommands\"] }).getCommands;\n for (const command of typeof getCommands === \"function\" ? getCommands.call(pi) : []) {\n if (command.source !== \"skill\" || seen.has(command.name.replace(/^skill:/u, \"\"))) continue;\n const name = command.name.replace(/^skill:/u, \"\");\n seen.add(name);\n result.push({ name, filePath: command.sourceInfo.path });\n }\n return result;\n}\n\nfunction unavailableMessage(): string {\n return [\n \"Local analytics storage could not be initialized safely.\",\n \"Existing files were not replaced.\",\n \"No analytics are being collected.\",\n ].join(\"\\n\");\n}\n\nfunction safeNotify(ctx: ExtensionContext, message: string, level: \"info\" | \"warning\"): void {\n try {\n ctx.ui.notify(message, level);\n } catch {\n // A replaced Pi context cannot receive lifecycle feedback.\n }\n}\n\nexport default createAnalyticsExtension();\n", "import { randomUUID } from \"node:crypto\";\nimport { classifyProviderError } from \"./errors.js\";\nimport type {\n GenerationOutcome,\n GenerationRecord,\n ModelIdentity,\n ProviderErrorRecord,\n RunOutcome,\n SettledRun,\n SkillActivationRecord,\n ToolCallRecord,\n TriggerSource,\n} from \"./types.js\";\n\ninterface ActiveRun {\n id: string;\n startedAtMs: number;\n triggerSource: TriggerSource;\n initialModel?: ModelIdentity;\n attemptCount: number;\n generations: GenerationRecord[];\n generationIds: Set<string>;\n tools: ToolCallRecord[];\n toolIds: Set<string>;\n skills: SkillActivationRecord[];\n skillIndexes: Map<string, number>;\n providerErrors: ProviderErrorRecord[];\n}\n\nexport class ResponseCollector {\n private active: ActiveRun | undefined;\n\n hasActiveRun(): boolean {\n return this.active !== undefined;\n }\n\n getActiveRunId(): string | undefined {\n return this.active?.id;\n }\n\n begin(input: {\n id: string;\n now: number;\n triggerSource: TriggerSource;\n model?: ModelIdentity;\n }): SettledRun | undefined {\n const interrupted = this.active ? this.finalize(input.now, \"interrupted\") : undefined;\n this.active = {\n id: input.id,\n startedAtMs: input.now,\n triggerSource: input.triggerSource,\n initialModel: input.model,\n attemptCount: 0,\n generations: [],\n generationIds: new Set(),\n tools: [],\n toolIds: new Set(),\n skills: [],\n skillIndexes: new Map(),\n providerErrors: [],\n };\n return interrupted;\n }\n\n beginAttempt(): void {\n if (this.active) this.active.attemptCount += 1;\n }\n\n beginGeneration(input: { id: string; now: number; model?: ModelIdentity }): void {\n const active = this.active;\n if (!active || active.generationIds.has(input.id)) return;\n active.generationIds.add(input.id);\n active.generations.push({\n id: input.id,\n ordinal: active.generations.length,\n provider: input.model?.provider,\n model: input.model?.model,\n thinkingLevel: input.model?.thinkingLevel,\n startedAtMs: input.now,\n outcome: \"pending\",\n responses: [],\n });\n }\n\n recordProviderResponse(input: { status: number; now: number }): void {\n const generation = this.latestGeneration();\n if (generation?.outcome !== \"pending\") return;\n generation.responses.push({\n ordinal: generation.responses.length,\n occurredAtMs: input.now,\n status: input.status,\n });\n }\n\n finishGeneration(input: { now: number; stopReason: string; errorMessage?: string }): void {\n const active = this.active;\n const generation = this.latestGeneration();\n if (!active || !generation || generation.outcome !== \"pending\") return;\n generation.finishedAtMs = input.now;\n generation.durationMs = elapsed(generation.startedAtMs, input.now);\n generation.stopReason = input.stopReason;\n generation.outcome = generationOutcome(input.stopReason);\n if (generation.outcome === \"error\") {\n active.providerErrors.push({\n id: randomUUID(),\n generationId: generation.id,\n occurredAtMs: input.now,\n provider: generation.provider,\n model: generation.model,\n category: classifyProviderError(input.errorMessage),\n recovered: false,\n terminal: true,\n });\n }\n }\n\n beginTool(input: { id: string; name: string; now: number; model?: ModelIdentity }): void {\n const active = this.active;\n if (!active || active.toolIds.has(input.id)) return;\n active.toolIds.add(input.id);\n active.tools.push({\n id: input.id,\n ordinal: active.tools.length,\n name: input.name,\n provider: input.model?.provider,\n model: input.model?.model,\n startedAtMs: input.now,\n isError: false,\n completionState: \"running\",\n });\n }\n\n finishTool(input: { id: string; now: number; isError: boolean }): void {\n const tool = this.active?.tools.find(({ id }) => id === input.id);\n if (tool?.completionState !== \"running\") return;\n tool.finishedAtMs = input.now;\n tool.durationMs = elapsed(tool.startedAtMs, input.now);\n tool.isError = input.isError;\n tool.completionState = \"finished\";\n }\n\n activateSkill(input: { name: string; initiatedBy: \"user\" | \"model\"; now: number; model?: ModelIdentity }): void {\n const active = this.active;\n if (!active) return;\n const existingIndex = active.skillIndexes.get(input.name);\n if (existingIndex !== undefined) {\n const existing = active.skills[existingIndex];\n if (existing && existing.initiatedBy === \"model\" && input.initiatedBy === \"user\") {\n existing.initiatedBy = \"user\";\n existing.occurredAtMs = input.now;\n existing.provider = input.model?.provider;\n existing.model = input.model?.model;\n }\n return;\n }\n active.skillIndexes.set(input.name, active.skills.length);\n active.skills.push({\n id: randomUUID(),\n name: input.name,\n initiatedBy: input.initiatedBy,\n occurredAtMs: input.now,\n provider: input.model?.provider,\n model: input.model?.model,\n });\n }\n\n settle(now: number): SettledRun | undefined {\n return this.finalize(now);\n }\n\n interrupt(now: number): SettledRun | undefined {\n return this.finalize(now, \"interrupted\");\n }\n\n private latestGeneration(): GenerationRecord | undefined {\n return this.active?.generations.at(-1);\n }\n\n private finalize(now: number, forcedOutcome?: RunOutcome): SettledRun | undefined {\n const active = this.active;\n if (!active) return undefined;\n this.active = undefined;\n\n for (const generation of active.generations) {\n if (generation.outcome !== \"pending\") continue;\n generation.outcome = \"interrupted\";\n generation.finishedAtMs = now;\n generation.durationMs = elapsed(generation.startedAtMs, now);\n }\n for (const tool of active.tools) {\n if (tool.completionState !== \"running\") continue;\n tool.completionState = \"interrupted\";\n tool.finishedAtMs = now;\n tool.durationMs = elapsed(tool.startedAtMs, now);\n }\n\n const successfulGenerationIndexes = new Set(\n active.generations\n .map((generation, index) => ({ generation, index }))\n .filter(({ generation }) => isSuccessfulGeneration(generation))\n .map(({ index }) => index),\n );\n let recoveredHttpErrors = 0;\n let httpErrors = 0;\n for (const [generationIndex, generation] of active.generations.entries()) {\n const hasLaterSuccess = [...successfulGenerationIndexes].some((index) => index > generationIndex);\n for (const [responseIndex, response] of generation.responses.entries()) {\n if (response.status < 400) continue;\n httpErrors += 1;\n const laterSuccessInGeneration = generation.responses\n .slice(responseIndex + 1)\n .some(({ status }) => status >= 200 && status < 400);\n if (laterSuccessInGeneration || hasLaterSuccess) recoveredHttpErrors += 1;\n }\n }\n for (const error of active.providerErrors) {\n const generationIndex = active.generations.findIndex(({ id }) => id === error.generationId);\n error.recovered = [...successfulGenerationIndexes].some((index) => index > generationIndex);\n error.terminal = !error.recovered;\n }\n\n const recoveredGenerationErrors = active.providerErrors.filter(({ recovered }) => recovered).length;\n const providerErrorCount = httpErrors + active.providerErrors.length;\n const recoveredErrorCount = recoveredHttpErrors + recoveredGenerationErrors;\n const outcome = forcedOutcome ?? deriveOutcome(active.generations, providerErrorCount);\n\n return {\n id: active.id,\n startedAtMs: active.startedAtMs,\n finishedAtMs: now,\n durationMs: elapsed(active.startedAtMs, now),\n triggerSource: active.triggerSource,\n initialProvider: active.initialModel?.provider,\n initialModel: active.initialModel?.model,\n outcome,\n attemptCount: active.attemptCount,\n generations: active.generations,\n tools: active.tools,\n skills: active.skills,\n providerErrors: active.providerErrors,\n toolErrorCount: active.tools.filter(({ isError }) => isError).length,\n providerErrorCount,\n recoveredErrorCount,\n };\n }\n}\n\nfunction elapsed(start: number, end: number): number {\n return Math.max(0, end - start);\n}\n\nfunction generationOutcome(stopReason: string): GenerationOutcome {\n switch (stopReason) {\n case \"stop\":\n return \"stop\";\n case \"toolUse\":\n return \"tool_use\";\n case \"error\":\n return \"error\";\n case \"aborted\":\n return \"aborted\";\n case \"length\":\n return \"length\";\n default:\n return \"interrupted\";\n }\n}\n\nfunction isSuccessfulGeneration(generation: GenerationRecord): boolean {\n return generation.outcome === \"stop\" || generation.outcome === \"tool_use\";\n}\n\nfunction deriveOutcome(generations: readonly GenerationRecord[], providerErrors: number): RunOutcome {\n const last = generations.at(-1);\n if (!last) return providerErrors > 0 ? \"error\" : \"success\";\n switch (last.outcome) {\n case \"stop\":\n case \"tool_use\":\n return providerErrors > 0 ? \"recovered_success\" : \"success\";\n case \"error\":\n return \"error\";\n case \"aborted\":\n return \"aborted\";\n case \"length\":\n return \"length\";\n default:\n return \"interrupted\";\n }\n}\n", "import type { ProviderErrorCategory } from \"./types.js\";\n\nexport function classifyProviderError(message: string | undefined): ProviderErrorCategory {\n const value = message?.toLowerCase() ?? \"\";\n if (/\\b(enotfound|eai_again|dns|getaddrinfo)\\b/u.test(value)) return \"dns\";\n if (/\\b(etimedout|timeout|timed out)\\b/u.test(value)) return \"timeout\";\n if (/\\b(econnrefused|connection refused)\\b/u.test(value)) return \"connection_refused\";\n if (/\\b(econnreset|connection reset|socket hang up)\\b/u.test(value)) {\n return \"connection_reset\";\n }\n if (/\\b(tls|ssl|certificate|cert_|handshake)\\b/u.test(value)) return \"tls\";\n if (/\\b(fetch failed|network|socket|connection|transport)\\b/u.test(value)) {\n return \"network_other\";\n }\n return \"provider_other\";\n}\n", "import { stripVTControlCharacters } from \"node:util\";\nimport type { ExtensionCommandContext } from \"@earendil-works/pi-coding-agent\";\nimport type { MenuDefinition } from \"@narumitw/pi-tui-kit\";\nimport type { ClearAnalyticsResult } from \"./storage/files.js\";\nimport type { AnalyticsSnapshot, SkillStats, TimeRange, TimeRangeId, ToolStats } from \"./storage/queries.js\";\nimport { resolveTimeRange } from \"./storage/queries.js\";\n\nexport type AnalyticsLoadResult =\n | { kind: \"ready\"; snapshot: AnalyticsSnapshot }\n | { kind: \"unavailable\"; message: string };\n\nexport interface AnalyticsMenuDataSource {\n path: string;\n load(range: TimeRange, signal: AbortSignal): Promise<AnalyticsLoadResult>;\n clearAll(signal: AbortSignal): Promise<ClearAnalyticsResult>;\n}\n\nexport interface AnalyticsMenuState {\n rangeId: TimeRangeId;\n range: TimeRange;\n path: string;\n result: AnalyticsLoadResult;\n}\n\nexport interface AnalyticsMenuOptions {\n runConfirmation: typeof import(\"@narumitw/pi-tui-kit\")[\"runConfirmation\"];\n isCurrent(): boolean;\n}\n\ntype Screen = \"main\" | \"range\" | \"skills\" | \"tools\" | \"reliability\" | \"responses\" | \"privacy\";\ntype Action = \"setRange\" | \"clearData\";\n\nconst RANGE_LABELS: Record<TimeRangeId, string> = {\n today: \"Today\",\n \"7d\": \"Last 7 days\",\n \"30d\": \"Last 30 days\",\n all: \"All time\",\n};\n\nexport function createAnalyticsMenu(\n source: AnalyticsMenuDataSource,\n now: () => number = Date.now,\n options?: AnalyticsMenuOptions,\n) {\n let rangeId: TimeRangeId = \"7d\";\n let cachedState: AnalyticsMenuState | undefined;\n const loadState = async (signal: AbortSignal): Promise<AnalyticsMenuState> => {\n if (cachedState?.rangeId === rangeId) return cachedState;\n const range = resolveTimeRange(rangeId, now());\n const loaded = { rangeId, range, path: source.path, result: await source.load(range, signal) };\n if (!signal.aborted && rangeId === loaded.rangeId) cachedState = loaded;\n return loaded;\n };\n const getState = ({ signal }: { signal: AbortSignal }): Promise<AnalyticsMenuState> => loadState(signal);\n const menu: MenuDefinition<AnalyticsMenuState, Screen, Action> = {\n start: \"main\",\n screens: {\n main: ({ state }) => ({\n kind: \"actions\",\n title: `Analytics \u00B7 ${RANGE_LABELS[state.rangeId]}`,\n lines: overviewLines(state.result),\n items: [\n { id: \"range\", label: \"Change time range\", to: \"range\" },\n { id: \"skills\", label: \"Skills\", to: \"skills\" },\n { id: \"tools\", label: \"Tools\", to: \"tools\" },\n { id: \"reliability\", label: \"Provider reliability\", to: \"reliability\" },\n { id: \"responses\", label: \"Response cycles\", to: \"responses\" },\n { id: \"privacy\", label: \"Data & privacy\", to: \"privacy\" },\n { id: \"close\", label: \"Close\", close: true },\n ],\n hint: \"close\",\n }),\n range: ({ state }) => ({\n kind: \"choice\",\n title: \"Analytics time range\",\n items: (Object.keys(RANGE_LABELS) as TimeRangeId[]).map((id) => ({\n id,\n label: RANGE_LABELS[id],\n })),\n action: \"setRange\",\n currentItemId: state.rangeId,\n initialItemId: state.rangeId,\n hint: \"back\",\n }),\n skills: ({ state }) => skillsScreen(state.result),\n tools: ({ state }) => toolsScreen(state.result),\n reliability: ({ state }) => ({\n kind: \"detail\",\n title: `Provider reliability \u00B7 ${RANGE_LABELS[state.rangeId]}`,\n lines: reliabilityLines(state.result),\n hint: \"back\",\n }),\n responses: ({ state }) => ({\n kind: \"detail\",\n title: `Response cycles \u00B7 ${RANGE_LABELS[state.rangeId]}`,\n lines: responseLines(state.result),\n hint: \"back\",\n }),\n privacy: ({ state }) => ({\n kind: \"actions\",\n title: \"Analytics data & privacy\",\n lines: privacyLines(state),\n items: [\n {\n id: \"clear\",\n label: \"Clear analytics data\u2026\",\n action: \"clearData\",\n disabled: state.result.kind !== \"ready\",\n },\n ],\n hint: \"back\",\n }),\n },\n actions: {\n setRange: async ({ itemId, signal }) => {\n if (!isRangeId(itemId)) return { kind: \"rejected\", error: new Error(\"Unknown range\") };\n rangeId = itemId;\n cachedState = undefined;\n await loadState(signal);\n return signal.aborted ? { kind: \"close\" } : { kind: \"to\", screen: \"main\" };\n },\n clearData: async ({ ctx, state, signal }) => {\n if (state.result.kind !== \"ready\") return { kind: \"stay\" };\n if (!options) throw new Error(\"Analytics confirmation is unavailable\");\n const count = state.result.snapshot.overview.responseCycles;\n const confirmation = await options.runConfirmation(ctx, {\n title: \"Delete analytics data?\",\n message: `This will clear all local analytics history from:\\n\\n${safeDisplayText(state.path)}\\n\\nThe selected range currently shows ${count} response cycles. Other running Pi processes may add new records afterward.`,\n confirmLabel: \"Delete data\",\n cancelLabel: \"Keep data\",\n signal,\n isCurrent: options.isCurrent,\n // Keep the dashboard's existing domain-level error route as the only notifier.\n onError: () => undefined,\n });\n if (signal.aborted || !options.isCurrent()) return { kind: \"close\" };\n if (confirmation.kind === \"closed\") {\n return confirmation.reason === \"close\" ? { kind: \"close\" } : { kind: \"stay\" };\n }\n if (confirmation.kind === \"stale\") return { kind: \"close\" };\n if (confirmation.kind === \"unsupported\") {\n throw new Error(`Analytics confirmation is unavailable in ${confirmation.mode} mode`);\n }\n if (confirmation.kind === \"error\") throw confirmation.error;\n\n const result = await source.clearAll(signal);\n cachedState = undefined;\n const isCurrent = options.isCurrent();\n if (isCurrent) {\n try {\n ctx.ui.notify(\"Cleared local analytics data.\", \"info\");\n if (result.cleanupIncomplete) {\n ctx.ui.notify(\n \"Some obsolete analytics files are still in use. Stop other Pi processes and clear again to remove them.\",\n \"warning\",\n );\n }\n } catch {\n // The host can dispose the current UI after the ownership check.\n }\n }\n return signal.aborted || !isCurrent ? { kind: \"close\" } : { kind: \"to\", screen: \"main\" };\n },\n },\n };\n return {\n menu,\n getState,\n preload: (signal: AbortSignal) => loadState(signal),\n get rangeId() {\n return rangeId;\n },\n };\n}\n\nexport async function showAnalyticsMenu(\n ctx: ExtensionCommandContext,\n source: AnalyticsMenuDataSource,\n options: { signal: AbortSignal; isCurrent: () => boolean },\n): Promise<void> {\n const { runConfirmation, runMenu, runTask } = await import(\"@narumitw/pi-tui-kit\");\n if (options.signal.aborted || !options.isCurrent()) return;\n const controller = createAnalyticsMenu(source, Date.now, {\n runConfirmation,\n isCurrent: options.isCurrent,\n });\n const loading = await runTask(ctx, {\n label: \"Loading local analytics\u2026\",\n signal: options.signal,\n isCurrent: options.isCurrent,\n task: ({ signal }) => controller.preload(signal),\n onError: () => undefined,\n });\n if (loading.kind !== \"completed\") {\n if (loading.kind === \"error\") {\n ctx.ui.notify(\n \"Analytics failed: The local analytics query could not be completed. Existing data was not changed.\",\n \"error\",\n );\n }\n return;\n }\n await runMenu(ctx, controller.menu, {\n getState: controller.getState,\n signal: options.signal,\n isCurrent: options.isCurrent,\n onError: (_ctx, error) => {\n ctx.ui.notify(`Analytics failed: ${safeErrorMessage(error)}`, \"error\");\n },\n });\n}\n\nfunction overviewLines(result: AnalyticsLoadResult): string[] {\n if (result.kind === \"unavailable\") {\n return [result.message, \"\", \"No analytics are being collected.\"];\n }\n const stats = result.snapshot.overview;\n if (stats.responseCycles === 0) {\n return [\n \"No analytics yet.\",\n \"Collection is active. Complete one Pi response cycle, then open /analytics again.\",\n \"\",\n \"Includes settled response cycles only.\",\n ];\n }\n return [\n metric(\"Response cycles\", stats.responseCycles),\n metric(\"LLM calls\", stats.llmCalls),\n metric(\"Calls per response\", `${formatDecimal(stats.callsPerResponse)} \u00B7 P95 ${stats.p95CallsPerResponse}`),\n metric(\"Tool calls\", stats.toolCalls),\n metric(\"Tool errors\", stats.toolErrors),\n metric(\"Skill activations\", stats.skillActivations),\n metric(\"Provider errors\", stats.providerErrors),\n metric(\"Recovered errors\", stats.recoveredErrors),\n \"\",\n \"Includes settled response cycles only.\",\n ];\n}\n\nfunction skillsScreen(result: AnalyticsLoadResult) {\n if (result.kind === \"unavailable\") {\n return {\n kind: \"browse\" as const,\n title: \"Skills\",\n lines: [result.message],\n items: [],\n hint: \"back\" as const,\n };\n }\n return {\n kind: \"browse\" as const,\n title: \"Skills\",\n lines: result.snapshot.skills.length === 0 ? [\"No skill activations detected in this time range.\"] : undefined,\n items: result.snapshot.skills.map(skillItem),\n viewportSize: \"adaptive\" as const,\n hint: \"back\" as const,\n };\n}\n\nfunction skillItem(skill: SkillStats) {\n return {\n id: skill.name,\n label: safeDisplayText(skill.name),\n statusText: `${skill.count} \u00B7 ${skill.modelInitiated} model / ${skill.userInitiated} user`,\n searchText: skill.models.map(modelLabel).join(\" \"),\n details: [\n metric(\"Activations\", skill.count),\n metric(\"Model initiated\", skill.modelInitiated),\n metric(\"User initiated\", skill.userInitiated),\n \"\",\n \"By model\",\n ...skill.models.map((model) => `${modelLabel(model)}: ${model.count}`),\n \"\",\n `Last detected: ${formatTimestamp(skill.lastOccurredAtMs)}`,\n ],\n };\n}\n\nfunction toolsScreen(result: AnalyticsLoadResult) {\n if (result.kind === \"unavailable\") {\n return {\n kind: \"browse\" as const,\n title: \"Tools\",\n lines: [result.message],\n items: [],\n hint: \"back\" as const,\n };\n }\n return {\n kind: \"browse\" as const,\n title: \"Tools\",\n lines: result.snapshot.tools.length === 0 ? [\"No tool calls detected in this time range.\"] : undefined,\n items: result.snapshot.tools.map(toolItem),\n viewportSize: \"adaptive\" as const,\n hint: \"back\" as const,\n };\n}\n\nfunction toolItem(tool: ToolStats) {\n return {\n id: tool.name,\n label: safeDisplayText(tool.name),\n statusText: `${tool.count} \u00B7 ${tool.errors} errors`,\n searchText: tool.models.map(modelLabel).join(\" \"),\n details: [\n metric(\"Calls\", tool.count),\n metric(\"Errors\", tool.errors),\n `Average duration: ${formatDecimal(tool.averageDurationMs)} ms`,\n \"\",\n \"By model\",\n ...tool.models.map((model) => `${modelLabel(model)}: ${model.count}`),\n \"\",\n `Last detected: ${formatTimestamp(tool.lastOccurredAtMs)}`,\n ],\n };\n}\n\nfunction reliabilityLines(result: AnalyticsLoadResult): string[] {\n if (result.kind === \"unavailable\") return [result.message];\n const value = result.snapshot.reliability;\n return [\n \"Observed provider errors only; provider-internal failures may be invisible.\",\n \"\",\n metric(\"HTTP 429\", value.http429),\n metric(\"HTTP 5xx\", value.http5xx),\n metric(\"DNS\", value.categories.dns),\n metric(\"Connection timeout\", value.categories.timeout),\n metric(\"Connection refused\", value.categories.connection_refused),\n metric(\"Connection reset\", value.categories.connection_reset),\n metric(\"TLS\", value.categories.tls),\n metric(\"Other network\", value.categories.network_other),\n metric(\"Other provider\", value.categories.provider_other),\n \"\",\n metric(\"Recovered\", value.recovered),\n metric(\"Terminal failures\", value.terminal),\n ];\n}\n\nfunction responseLines(result: AnalyticsLoadResult): string[] {\n if (result.kind === \"unavailable\") return [result.message];\n const value = result.snapshot.responses;\n return [\n metric(\"Cycles\", value.count),\n metric(\"LLM calls\", value.llmCalls),\n metric(\"Average\", formatDecimal(value.average)),\n metric(\"Median\", formatDecimal(value.median)),\n metric(\"P95\", value.p95),\n metric(\"Maximum\", value.maximum),\n \"\",\n \"Calls per response\",\n metric(\"1 call\", value.distribution.one),\n metric(\"2\u20133 calls\", value.distribution.twoToThree),\n metric(\"4\u20136 calls\", value.distribution.fourToSix),\n metric(\"7+ calls\", value.distribution.sevenPlus),\n ];\n}\n\nfunction privacyLines(state: AnalyticsMenuState): string[] {\n return [\n \"Local analytics files:\",\n safeDisplayText(state.path),\n \"\",\n \"Stored: timestamps, extension-generated record IDs, model/provider IDs, thinking level, tool and skill names, durations, counts, HTTP statuses, and classified errors.\",\n \"Not stored: prompts, responses, thinking, tool arguments/results, raw errors, headers, cwd/file paths, session identity, or credentials.\",\n \"\",\n \"No database server, cloud connection, or other remote telemetry is used.\",\n \"Analytics are non-critical derived metadata; a failed local write may be dropped.\",\n ];\n}\n\nfunction metric(label: string, value: string | number): string {\n return `${label.padEnd(24)} ${value}`;\n}\n\nfunction formatDecimal(value: number): string {\n return Number.isInteger(value) ? String(value) : value.toFixed(2).replace(/0+$/u, \"\").replace(/\\.$/u, \"\");\n}\n\nfunction formatTimestamp(value: number): string {\n return new Date(value).toLocaleString();\n}\n\nfunction modelLabel(model: { provider?: string; model?: string }): string {\n if (!model.provider && !model.model) return \"unknown\";\n return safeDisplayText(`${model.provider ?? \"unknown\"}/${model.model ?? \"unknown\"}`);\n}\n\nfunction safeDisplayText(value: unknown): string {\n return Array.from(stripVTControlCharacters(String(value)), (character) => {\n const codePoint = character.codePointAt(0) ?? 0;\n return codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f) ? \" \" : character;\n }).join(\"\");\n}\n\nfunction isRangeId(value: string): value is TimeRangeId {\n return value === \"today\" || value === \"7d\" || value === \"30d\" || value === \"all\";\n}\n\nfunction safeErrorMessage(_error: unknown): string {\n return \"The local analytics query could not be completed. Try again; existing data was not changed.\";\n}\n", "import type { ProviderErrorCategory, SettledRun } from \"../types.js\";\n\nexport type TimeRangeId = \"today\" | \"7d\" | \"30d\" | \"all\";\nexport interface TimeRange {\n id?: TimeRangeId;\n fromMs: number;\n toMs: number;\n}\n\nexport interface OverviewStats {\n responseCycles: number;\n llmCalls: number;\n callsPerResponse: number;\n p95CallsPerResponse: number;\n toolCalls: number;\n toolErrors: number;\n skillActivations: number;\n providerErrors: number;\n recoveredErrors: number;\n}\n\nexport interface ModelCount {\n provider?: string;\n model?: string;\n count: number;\n}\n\nexport interface SkillStats {\n name: string;\n count: number;\n modelInitiated: number;\n userInitiated: number;\n lastOccurredAtMs: number;\n models: ModelCount[];\n}\n\nexport interface ToolStats {\n name: string;\n count: number;\n errors: number;\n averageDurationMs: number;\n lastOccurredAtMs: number;\n models: ModelCount[];\n}\n\nexport interface ReliabilityStats {\n http429: number;\n http5xx: number;\n recovered: number;\n terminal: number;\n categories: Record<ProviderErrorCategory, number>;\n}\n\nexport interface ResponseStats {\n count: number;\n llmCalls: number;\n average: number;\n median: number;\n p95: number;\n maximum: number;\n distribution: { one: number; twoToThree: number; fourToSix: number; sevenPlus: number };\n}\n\nexport interface AnalyticsSnapshot {\n overview: OverviewStats;\n skills: SkillStats[];\n tools: ToolStats[];\n reliability: ReliabilityStats;\n responses: ResponseStats;\n}\n\nconst DAY_MS = 24 * 60 * 60 * 1_000;\nconst ERROR_CATEGORIES: readonly ProviderErrorCategory[] = [\n \"dns\",\n \"timeout\",\n \"connection_refused\",\n \"connection_reset\",\n \"tls\",\n \"network_other\",\n \"provider_other\",\n];\n\nexport function resolveTimeRange(id: TimeRangeId, now = Date.now()): TimeRange {\n let fromMs = 0;\n if (id === \"today\") {\n const date = new Date(now);\n fromMs = new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime();\n } else if (id === \"7d\") fromMs = now - 7 * DAY_MS;\n else if (id === \"30d\") fromMs = now - 30 * DAY_MS;\n return { id, fromMs, toMs: now + 1 };\n}\n\nexport async function querySnapshot(\n runs: AsyncIterable<SettledRun> | Iterable<SettledRun>,\n range: TimeRange,\n signal?: AbortSignal,\n): Promise<AnalyticsSnapshot> {\n const generationCounts: number[] = [];\n const seenRunIds = new Set<string>();\n const skills = new Map<string, SkillStats>();\n const tools = new Map<string, ToolStats & { totalDurationMs: number }>();\n const categories = Object.fromEntries(ERROR_CATEGORIES.map((category) => [category, 0])) as Record<\n ProviderErrorCategory,\n number\n >;\n let toolErrors = 0;\n let providerErrors = 0;\n let recoveredErrors = 0;\n let http429 = 0;\n let http5xx = 0;\n let terminal = 0;\n\n for await (const run of runs) {\n throwIfAborted(signal);\n if (seenRunIds.has(run.id)) continue;\n seenRunIds.add(run.id);\n if (run.startedAtMs < range.fromMs || run.startedAtMs >= range.toMs) continue;\n generationCounts.push(run.generations.length);\n toolErrors += run.toolErrorCount;\n providerErrors += run.providerErrorCount;\n recoveredErrors += run.recoveredErrorCount;\n\n for (const skill of run.skills) {\n const item = skills.get(skill.name) ?? {\n name: skill.name,\n count: 0,\n modelInitiated: 0,\n userInitiated: 0,\n lastOccurredAtMs: 0,\n models: [],\n };\n item.count += 1;\n if (skill.initiatedBy === \"user\") item.userInitiated += 1;\n else item.modelInitiated += 1;\n item.lastOccurredAtMs = Math.max(item.lastOccurredAtMs, skill.occurredAtMs);\n mergeModelCount(item.models, {\n provider: skill.provider,\n model: skill.model,\n count: 1,\n });\n skills.set(skill.name, item);\n }\n\n for (const tool of run.tools) {\n const item = tools.get(tool.name) ?? {\n name: tool.name,\n count: 0,\n errors: 0,\n averageDurationMs: 0,\n totalDurationMs: 0,\n lastOccurredAtMs: 0,\n models: [],\n };\n item.count += 1;\n item.errors += tool.isError ? 1 : 0;\n item.totalDurationMs += tool.durationMs ?? 0;\n item.averageDurationMs = item.totalDurationMs / item.count;\n item.lastOccurredAtMs = Math.max(item.lastOccurredAtMs, tool.startedAtMs);\n mergeModelCount(item.models, {\n provider: tool.provider,\n model: tool.model,\n count: 1,\n });\n tools.set(tool.name, item);\n }\n\n for (const error of run.providerErrors) {\n categories[error.category] += 1;\n terminal += error.terminal ? 1 : 0;\n }\n for (const generation of run.generations) {\n for (const response of generation.responses) {\n if (response.status === 429) http429 += 1;\n if (response.status >= 500 && response.status < 600) http5xx += 1;\n }\n }\n }\n\n const responses = responseStatistics(generationCounts);\n return {\n overview: {\n responseCycles: responses.count,\n llmCalls: responses.llmCalls,\n callsPerResponse: responses.average,\n p95CallsPerResponse: responses.p95,\n toolCalls: sum([...tools.values()].map(({ count }) => count)),\n toolErrors,\n skillActivations: sum([...skills.values()].map(({ count }) => count)),\n providerErrors,\n recoveredErrors,\n },\n skills: [...skills.values()]\n .map((item) => ({ ...item, models: sortModels(item.models) }))\n .sort((left, right) => right.count - left.count || left.name.localeCompare(right.name)),\n tools: [...tools.values()]\n .map(({ totalDurationMs: _, ...item }) => ({ ...item, models: sortModels(item.models) }))\n .sort((left, right) => right.count - left.count || left.name.localeCompare(right.name)),\n reliability: {\n http429,\n http5xx,\n recovered: recoveredErrors,\n terminal,\n categories,\n },\n responses,\n };\n}\n\nfunction responseStatistics(generationCounts: number[]): ResponseStats {\n const sorted = [...generationCounts].sort((left, right) => left - right);\n const count = sorted.length;\n const llmCalls = sum(sorted);\n const nearestRank = (percentile: number) =>\n count === 0 ? 0 : (sorted[Math.max(0, Math.ceil(percentile * count) - 1)] ?? 0);\n const median =\n count === 0\n ? 0\n : count % 2 === 1\n ? (sorted[Math.floor(count / 2)] ?? 0)\n : ((sorted[count / 2 - 1] ?? 0) + (sorted[count / 2] ?? 0)) / 2;\n return {\n count,\n llmCalls,\n average: count > 0 ? llmCalls / count : 0,\n median,\n p95: nearestRank(0.95),\n maximum: sorted.at(-1) ?? 0,\n distribution: {\n one: sorted.filter((value) => value === 1).length,\n twoToThree: sorted.filter((value) => value >= 2 && value <= 3).length,\n fourToSix: sorted.filter((value) => value >= 4 && value <= 6).length,\n sevenPlus: sorted.filter((value) => value >= 7).length,\n },\n };\n}\n\nfunction mergeModelCount(models: ModelCount[], next: ModelCount): void {\n const existing = models.find(({ provider, model }) => provider === next.provider && model === next.model);\n if (existing) existing.count += next.count;\n else models.push(next);\n}\n\nfunction sortModels(models: ModelCount[]): ModelCount[] {\n return models.sort(\n (left, right) =>\n right.count - left.count ||\n `${left.provider ?? \"\"}/${left.model ?? \"\"}`.localeCompare(`${right.provider ?? \"\"}/${right.model ?? \"\"}`),\n );\n}\n\nfunction throwIfAborted(signal?: AbortSignal): void {\n if (signal?.aborted) throw signal.reason ?? new DOMException(\"Analytics query aborted\", \"AbortError\");\n}\n\nfunction sum(values: readonly number[]): number {\n return values.reduce((total, value) => total + value, 0);\n}\n", "import { realpath } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { InputSource } from \"@earendil-works/pi-coding-agent\";\n\nexport interface AvailableSkill {\n name: string;\n filePath: string;\n}\n\nexport interface PendingExplicitSkill {\n name: string;\n observedAtMs: number;\n source: \"interactive\" | \"rpc\";\n}\n\nexport function explicitSkillName(text: string): string | undefined {\n return text.match(/^\\/skill:([a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?)(?:\\s|$)/u)?.[1];\n}\n\nexport class SkillTracker {\n private pending: PendingExplicitSkill | undefined;\n private readonly skillByPath = new Map<string, string>();\n private readonly availableNames = new Set<string>();\n\n constructor(\n private readonly cwd: string,\n private readonly canonicalize: (filePath: string) => Promise<string> = realpath,\n ) {}\n\n observeInput(text: string, source: InputSource, now: number): void {\n if (source === \"extension\") return;\n const name = explicitSkillName(text);\n this.pending = name ? { name, observedAtMs: now, source } : undefined;\n }\n\n consumeExplicitSkill(): PendingExplicitSkill | undefined {\n const pending = this.pending;\n this.pending = undefined;\n return pending;\n }\n\n clearPending(): void {\n this.pending = undefined;\n }\n\n hasAvailableSkill(name: string): boolean {\n return this.availableNames.has(name);\n }\n\n async setAvailableSkills(skills: readonly AvailableSkill[]): Promise<void> {\n this.skillByPath.clear();\n this.availableNames.clear();\n const seenNames = new Set<string>();\n for (const skill of skills) {\n if (seenNames.has(skill.name)) continue;\n seenNames.add(skill.name);\n this.availableNames.add(skill.name);\n const canonical = await this.canonicalize(skill.filePath).catch(() => path.resolve(this.cwd, skill.filePath));\n this.skillByPath.set(canonical, skill.name);\n }\n }\n\n async matchSuccessfulRead(input: {\n toolName: string;\n input: unknown;\n isError: boolean;\n }): Promise<string | undefined> {\n if (input.toolName !== \"read\" || input.isError || !isRecord(input.input)) return undefined;\n const rawPath = input.input.path;\n if (typeof rawPath !== \"string\" || rawPath.length === 0) return undefined;\n const normalized = rawPath.startsWith(\"@\") ? rawPath.slice(1) : rawPath;\n const absolute = path.resolve(this.cwd, normalized);\n const canonical = await this.canonicalize(absolute).catch(() => absolute);\n return this.skillByPath.get(canonical);\n }\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n", "import { randomUUID } from \"node:crypto\";\nimport { createReadStream, type Dirent } from \"node:fs\";\nimport { chmod, lstat, mkdir, open, readdir, readFile, rename, rm, rmdir, unlink, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { SettledRun } from \"../types.js\";\nimport { AnalyticsStorageFormatError, decodeStoredRun, encodeStoredRun, MAX_STORED_RUN_BYTES } from \"./format.js\";\n\nconst GENERATION_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/u;\nconst DEFAULT_WRITE_TIMEOUT_MS = 5_000;\nconst YIELD_EVERY_RECORDS = 100;\n\nexport interface ClearAnalyticsResult {\n cleanupIncomplete: boolean;\n}\n\nexport class AnalyticsGenerationChangedError extends Error {\n constructor() {\n super(\"The active analytics generation changed during the read.\");\n this.name = \"AnalyticsGenerationChangedError\";\n }\n}\n\nexport class AnalyticsRunFiles {\n private readonly createId: () => string;\n private readonly writeTimeoutMs: number;\n private readonly beforeAppend?: (generation: string, signal: AbortSignal) => Promise<void>;\n private readonly beforeCleanupEntry?: (signal?: AbortSignal) => Promise<void>;\n private readonly beforeReadFile?: (signal?: AbortSignal) => Promise<void>;\n private writerId: string;\n private mutationTail: Promise<void> = Promise.resolve();\n private readonly lifecycle = new AbortController();\n private closed = false;\n\n constructor(\n readonly path: string,\n options: {\n createId?: () => string;\n writeTimeoutMs?: number;\n beforeAppend?: (generation: string, signal: AbortSignal) => Promise<void>;\n beforeCleanupEntry?: (signal?: AbortSignal) => Promise<void>;\n beforeReadFile?: (signal?: AbortSignal) => Promise<void>;\n } = {},\n ) {\n this.createId = options.createId ?? randomUUID;\n this.writeTimeoutMs = options.writeTimeoutMs ?? DEFAULT_WRITE_TIMEOUT_MS;\n this.beforeAppend = options.beforeAppend;\n this.beforeCleanupEntry = options.beforeCleanupEntry;\n this.beforeReadFile = options.beforeReadFile;\n this.writerId = validCreatedId(this.createId());\n }\n\n append(run: SettledRun, signal?: AbortSignal): Promise<void> {\n if (this.closed) return Promise.reject(new Error(\"Analytics storage is closed.\"));\n const frame = encodeStoredRun(run);\n return this.enqueueMutation(() =>\n withDeadline(signal, this.lifecycle.signal, this.writeTimeoutMs, (operationSignal) =>\n this.appendFrame(frame, operationSignal),\n ),\n );\n }\n\n async *read(signal?: AbortSignal): AsyncIterable<SettledRun> {\n throwIfAborted(signal);\n const generation = await this.readOrCreateGeneration(signal);\n const directory = this.generationPath(generation);\n let entries: Dirent[];\n try {\n entries = await readdir(directory, { withFileTypes: true });\n } catch (error) {\n if (isNodeError(error) && error.code === \"ENOENT\") {\n await this.assertGenerationUnchanged(generation, signal);\n throw new AnalyticsGenerationChangedError();\n }\n throw error;\n }\n let count = 0;\n for (const entry of entries.sort((left, right) => left.name.localeCompare(right.name))) {\n throwIfAborted(signal);\n if (!entry.name.endsWith(\".jsonl\")) continue;\n const filePath = path.join(directory, entry.name);\n try {\n await this.beforeReadFile?.(signal);\n throwIfAborted(signal);\n await assertPrivateRegularFile(filePath);\n for await (const run of readFrames(filePath, signal)) {\n yield run;\n count += 1;\n if (count % YIELD_EVERY_RECORDS === 0) await yieldToEventLoop(signal);\n }\n } catch (error) {\n if (isNodeError(error) && error.code === \"ENOENT\") {\n await this.assertGenerationUnchanged(generation, signal);\n throw new AnalyticsGenerationChangedError();\n }\n throw error;\n }\n }\n await this.assertGenerationUnchanged(generation, signal);\n }\n\n clear(signal?: AbortSignal): Promise<ClearAnalyticsResult> {\n if (this.closed) return Promise.reject(new Error(\"Analytics storage is closed.\"));\n let result: ClearAnalyticsResult = { cleanupIncomplete: false };\n return this.enqueueMutation(() =>\n withLinkedSignals(signal, this.lifecycle.signal, async (operationSignal) => {\n throwIfAborted(operationSignal);\n await this.readOrCreateGeneration(operationSignal);\n const next = validCreatedId(this.createId());\n await this.publishGeneration(next);\n this.writerId = validCreatedId(this.createId());\n const current = await readGenerationMarker(path.join(this.path, \"current\"));\n await ensurePrivateDirectory(this.generationPath(current));\n if (!(await this.cleanupObsoleteGenerations(operationSignal))) {\n result = { cleanupIncomplete: true };\n }\n }),\n ).then(() => result);\n }\n\n async close(): Promise<void> {\n if (this.closed) return;\n this.closed = true;\n this.lifecycle.abort(new DOMException(\"Analytics storage closed\", \"AbortError\"));\n await this.mutationTail.catch(() => undefined);\n }\n\n private enqueueMutation(operation: () => Promise<void>): Promise<void> {\n const result = this.mutationTail.then(operation);\n this.mutationTail = result.catch(() => undefined);\n return result;\n }\n\n private async appendFrame(frame: string, signal: AbortSignal): Promise<void> {\n throwIfAborted(signal);\n let obsoleteDirectory: string | undefined;\n for (let attempt = 0; attempt < 3; attempt += 1) {\n const generation = await this.readOrCreateGeneration(signal);\n const directory = this.generationPath(generation);\n await ensurePrivateDirectory(directory);\n const filePath = path.join(directory, `${this.writerId}.jsonl`);\n await assertOptionalPrivateRegularFile(filePath);\n throwIfAborted(signal);\n await this.beforeAppend?.(generation, signal);\n throwIfAborted(signal);\n try {\n await writeFile(filePath, frame, {\n encoding: \"utf8\",\n flag: \"a\",\n mode: 0o600,\n signal,\n });\n if (process.platform !== \"win32\") await chmod(filePath, 0o600);\n const current = await readGenerationMarker(path.join(this.path, \"current\"), signal);\n if (current === generation) {\n if (obsoleteDirectory) {\n await cleanupGeneration(obsoleteDirectory, signal).catch(() => undefined);\n }\n return;\n }\n obsoleteDirectory = directory;\n } catch (error) {\n this.writerId = validCreatedId(this.createId());\n throwIfAborted(signal);\n if (!isNodeError(error) || error.code !== \"ENOENT\") throw error;\n }\n }\n throw new AnalyticsGenerationChangedError();\n }\n\n private async readOrCreateGeneration(signal?: AbortSignal): Promise<string> {\n throwIfAborted(signal);\n await ensurePrivateDirectory(this.path);\n await ensurePrivateDirectory(path.join(this.path, \"generations\"));\n const markerPath = path.join(this.path, \"current\");\n for (let attempt = 0; attempt < 3; attempt += 1) {\n let generation: string;\n try {\n generation = await readGenerationMarker(markerPath, signal);\n } catch (error) {\n if (!isNodeError(error) || error.code !== \"ENOENT\") throw error;\n generation = validCreatedId(this.createId());\n throwIfAborted(signal);\n try {\n await createPrivateFile(markerPath, `${generation}\\n`);\n } catch (createError) {\n if (!isNodeError(createError) || createError.code !== \"EEXIST\") throw createError;\n generation = await readGenerationMarker(markerPath, signal);\n }\n }\n await ensurePrivateDirectory(this.generationPath(generation));\n const current = await readGenerationMarker(markerPath, signal);\n if (current === generation) return generation;\n }\n throw new AnalyticsGenerationChangedError();\n }\n\n private async publishGeneration(generation: string): Promise<void> {\n const markerPath = path.join(this.path, \"current\");\n const temporaryPath = path.join(this.path, `.current.${validCreatedId(this.createId())}.tmp`);\n await createPrivateFile(temporaryPath, `${generation}\\n`);\n try {\n await rename(temporaryPath, markerPath);\n if (process.platform !== \"win32\") await chmod(markerPath, 0o600);\n } catch (error) {\n await rm(temporaryPath, { force: true }).catch(() => undefined);\n throw error;\n }\n }\n\n private async cleanupObsoleteGenerations(signal?: AbortSignal): Promise<boolean> {\n let complete = true;\n const root = path.join(this.path, \"generations\");\n for (const entry of await readdir(root, { withFileTypes: true })) {\n const active = await readGenerationMarker(path.join(this.path, \"current\"));\n if (entry.name === active) continue;\n if (!entry.isDirectory() || !GENERATION_PATTERN.test(entry.name)) {\n complete = false;\n continue;\n }\n try {\n await cleanupGeneration(path.join(root, entry.name), signal, this.beforeCleanupEntry);\n } catch {\n complete = false;\n if (signal?.aborted) break;\n }\n }\n const active = await readGenerationMarker(path.join(this.path, \"current\"));\n const remaining = await readdir(root, { withFileTypes: true });\n return complete && remaining.every((entry) => entry.isDirectory() && entry.name === active);\n }\n\n private async assertGenerationUnchanged(generation: string, signal?: AbortSignal): Promise<void> {\n const current = await readGenerationMarker(path.join(this.path, \"current\"), signal);\n if (current !== generation) throw new AnalyticsGenerationChangedError();\n }\n\n private generationPath(generation: string): string {\n return path.join(this.path, \"generations\", generation);\n }\n}\n\nasync function* readFrames(filePath: string, signal?: AbortSignal): AsyncIterable<SettledRun> {\n let pending = \"\";\n const stream = createReadStream(filePath, { encoding: \"utf8\", signal });\n for await (const chunk of stream) {\n throwIfAborted(signal);\n pending += String(chunk);\n while (true) {\n const newline = pending.indexOf(\"\\n\");\n if (newline < 0) break;\n const line = pending.slice(0, newline);\n pending = pending.slice(newline + 1);\n if (!line) continue;\n yield decodeStoredRun(line);\n }\n if (Buffer.byteLength(pending) > MAX_STORED_RUN_BYTES) {\n throw new AnalyticsStorageFormatError(\"Analytics record is too large to read safely.\");\n }\n }\n // A writer always terminates complete frames with a newline. An unterminated tail is a\n // crash residue and is ignored; this writer file will not be reused after its process exits.\n}\n\nasync function readGenerationMarker(markerPath: string, signal?: AbortSignal): Promise<string> {\n await assertPrivateRegularFile(markerPath);\n throwIfAborted(signal);\n const value = (await readFile(markerPath, { encoding: \"utf8\", signal })).trim();\n if (!GENERATION_PATTERN.test(value)) {\n throw new AnalyticsStorageFormatError(\"Analytics generation marker is invalid.\");\n }\n return value;\n}\n\nasync function ensurePrivateDirectory(directoryPath: string): Promise<void> {\n try {\n const metadata = await lstat(directoryPath);\n if (!metadata.isDirectory() || metadata.isSymbolicLink()) {\n throw new Error(\"Analytics storage paths must be regular directories, not links.\");\n }\n } catch (error) {\n if (!isNodeError(error) || error.code !== \"ENOENT\") throw error;\n await mkdir(directoryPath, { recursive: true, mode: 0o700 });\n const metadata = await lstat(directoryPath);\n if (!metadata.isDirectory() || metadata.isSymbolicLink()) {\n throw new Error(\"Analytics storage paths must be regular directories, not links.\");\n }\n }\n if (process.platform !== \"win32\") await chmod(directoryPath, 0o700);\n}\n\nasync function assertOptionalPrivateRegularFile(filePath: string): Promise<void> {\n try {\n await assertPrivateRegularFile(filePath);\n } catch (error) {\n if (isNodeError(error) && error.code === \"ENOENT\") return;\n throw error;\n }\n}\n\nasync function assertPrivateRegularFile(filePath: string): Promise<void> {\n const metadata = await lstat(filePath);\n if (!metadata.isFile() || metadata.isSymbolicLink()) {\n throw new Error(\"Analytics storage files must be regular files, not links.\");\n }\n if (process.platform !== \"win32\") await chmod(filePath, 0o600);\n}\n\nasync function createPrivateFile(filePath: string, content: string): Promise<void> {\n const handle = await open(filePath, \"wx\", 0o600);\n try {\n await handle.writeFile(content, \"utf8\");\n await handle.sync();\n } finally {\n await handle.close();\n }\n}\n\nasync function cleanupGeneration(\n directoryPath: string,\n signal?: AbortSignal,\n beforeEntry?: (signal?: AbortSignal) => Promise<void>,\n): Promise<void> {\n throwIfAborted(signal);\n let entries: Dirent[];\n try {\n entries = await readdir(directoryPath, { withFileTypes: true });\n } catch (error) {\n if (isNodeError(error) && error.code === \"ENOENT\") return;\n throw error;\n }\n for (const entry of entries) {\n throwIfAborted(signal);\n await beforeEntry?.(signal);\n throwIfAborted(signal);\n if (!entry.isFile() || !entry.name.endsWith(\".jsonl\")) {\n throw new Error(\"Analytics generation contains an unexpected storage entry.\");\n }\n await unlink(path.join(directoryPath, entry.name));\n }\n throwIfAborted(signal);\n await rmdir(directoryPath);\n}\n\nasync function withLinkedSignals<T>(\n callerSignal: AbortSignal | undefined,\n lifecycleSignal: AbortSignal,\n operation: (signal: AbortSignal) => Promise<T>,\n): Promise<T> {\n throwIfAborted(callerSignal);\n throwIfAborted(lifecycleSignal);\n const controller = new AbortController();\n const abort = (signal: AbortSignal) =>\n controller.abort(signal.reason ?? new DOMException(\"Analytics operation aborted\", \"AbortError\"));\n const callerAbort = () => callerSignal && abort(callerSignal);\n const lifecycleAbort = () => abort(lifecycleSignal);\n callerSignal?.addEventListener(\"abort\", callerAbort, { once: true });\n lifecycleSignal.addEventListener(\"abort\", lifecycleAbort, { once: true });\n try {\n return await operation(controller.signal);\n } finally {\n callerSignal?.removeEventListener(\"abort\", callerAbort);\n lifecycleSignal.removeEventListener(\"abort\", lifecycleAbort);\n }\n}\n\nasync function withDeadline<T>(\n callerSignal: AbortSignal | undefined,\n lifecycleSignal: AbortSignal,\n timeoutMs: number,\n operation: (signal: AbortSignal) => Promise<T>,\n): Promise<T> {\n throwIfAborted(callerSignal);\n throwIfAborted(lifecycleSignal);\n const controller = new AbortController();\n const abort = (signal: AbortSignal) =>\n controller.abort(signal.reason ?? new DOMException(\"Analytics operation aborted\", \"AbortError\"));\n const callerAbort = () => callerSignal && abort(callerSignal);\n const lifecycleAbort = () => abort(lifecycleSignal);\n callerSignal?.addEventListener(\"abort\", callerAbort, { once: true });\n lifecycleSignal.addEventListener(\"abort\", lifecycleAbort, { once: true });\n const timer = setTimeout(\n () => controller.abort(new DOMException(\"Analytics write timed out\", \"TimeoutError\")),\n Math.max(1, timeoutMs),\n );\n try {\n return await operation(controller.signal);\n } catch (error) {\n if (\n controller.signal.aborted &&\n error instanceof Error &&\n error.name === \"AbortError\" &&\n error.cause === controller.signal.reason\n ) {\n throw controller.signal.reason;\n }\n throw error;\n } finally {\n clearTimeout(timer);\n callerSignal?.removeEventListener(\"abort\", callerAbort);\n lifecycleSignal.removeEventListener(\"abort\", lifecycleAbort);\n }\n}\n\nasync function yieldToEventLoop(signal?: AbortSignal): Promise<void> {\n await new Promise<void>((resolve) => setImmediate(resolve));\n throwIfAborted(signal);\n}\n\nfunction validCreatedId(value: string): string {\n if (!GENERATION_PATTERN.test(value)) throw new Error(\"Analytics storage received an invalid ID.\");\n return value;\n}\n\nfunction throwIfAborted(signal?: AbortSignal): void {\n if (signal?.aborted) {\n throw signal.reason ?? new DOMException(\"Analytics operation aborted\", \"AbortError\");\n }\n}\n\nfunction isNodeError(error: unknown): error is NodeJS.ErrnoException {\n return error instanceof Error && \"code\" in error;\n}\n", "import type {\n GenerationOutcome,\n GenerationRecord,\n ProviderErrorCategory,\n ProviderErrorRecord,\n ProviderResponseRecord,\n RunOutcome,\n SettledRun,\n SkillActivationRecord,\n ToolCallRecord,\n} from \"../types.js\";\n\nexport const MAX_STORED_RUN_BYTES = 1024 * 1024;\nconst MAX_STRING_LENGTH = 4096;\nconst MAX_NESTED_RECORDS = 20_000;\nconst TRIGGER_SOURCES = [\"interactive\", \"rpc\", \"extension\", \"unknown\"] as const;\nconst RUN_OUTCOMES = [\"success\", \"recovered_success\", \"error\", \"aborted\", \"length\", \"interrupted\"] as const;\nconst GENERATION_OUTCOMES = [\"pending\", \"stop\", \"tool_use\", \"error\", \"aborted\", \"length\", \"interrupted\"] as const;\nconst ERROR_CATEGORIES = [\n \"dns\",\n \"timeout\",\n \"connection_refused\",\n \"connection_reset\",\n \"tls\",\n \"network_other\",\n \"provider_other\",\n] as const;\n\nexport class AnalyticsStorageFormatError extends Error {\n constructor(message: string, options: { cause?: unknown } = {}) {\n super(message, options);\n this.name = \"AnalyticsStorageFormatError\";\n }\n}\n\nexport function encodeStoredRun(run: SettledRun): string {\n const encoded = `${JSON.stringify({\n formatVersion: 1,\n run: parseRun(run, { remaining: MAX_NESTED_RECORDS }),\n })}\\n`;\n if (Buffer.byteLength(encoded) > MAX_STORED_RUN_BYTES) {\n throw new AnalyticsStorageFormatError(\"Analytics record is too large to store safely.\");\n }\n return encoded;\n}\n\nexport function decodeStoredRun(line: string): SettledRun {\n if (Buffer.byteLength(line) > MAX_STORED_RUN_BYTES) {\n throw new AnalyticsStorageFormatError(\"Analytics record is too large to read safely.\");\n }\n let value: unknown;\n try {\n value = JSON.parse(line);\n } catch (error) {\n throw new AnalyticsStorageFormatError(\"Analytics record contains invalid JSON.\", {\n cause: error,\n });\n }\n const envelope = asRecord(value, \"analytics record\");\n if (envelope.formatVersion !== 1) {\n throw new AnalyticsStorageFormatError(\"Analytics record uses an unsupported format version.\");\n }\n return parseRun(envelope.run, { remaining: MAX_NESTED_RECORDS });\n}\n\ninterface ParseBudget {\n remaining: number;\n}\n\nfunction parseRun(value: unknown, budget: ParseBudget): SettledRun {\n const run = asRecord(value, \"run\");\n return {\n id: requiredString(run.id, \"run.id\"),\n startedAtMs: timestampValue(run.startedAtMs, \"run.startedAtMs\"),\n finishedAtMs: timestampValue(run.finishedAtMs, \"run.finishedAtMs\"),\n durationMs: durationValue(run.durationMs, \"run.durationMs\"),\n triggerSource: enumValue(run.triggerSource, TRIGGER_SOURCES, \"run.triggerSource\"),\n ...optionalProperty(\"initialProvider\", optionalString(run.initialProvider, \"run.initialProvider\")),\n ...optionalProperty(\"initialModel\", optionalString(run.initialModel, \"run.initialModel\")),\n outcome: enumValue(run.outcome, RUN_OUTCOMES, \"run.outcome\") as RunOutcome,\n attemptCount: boundedCount(run.attemptCount, \"run.attemptCount\"),\n generations: boundedArray(run.generations, \"run.generations\", budget).map((item, index) =>\n parseGeneration(item, index, budget),\n ),\n tools: boundedArray(run.tools, \"run.tools\", budget).map(parseTool),\n skills: boundedArray(run.skills, \"run.skills\", budget).map(parseSkill),\n providerErrors: boundedArray(run.providerErrors, \"run.providerErrors\", budget).map(parseProviderError),\n toolErrorCount: boundedCount(run.toolErrorCount, \"run.toolErrorCount\"),\n providerErrorCount: boundedCount(run.providerErrorCount, \"run.providerErrorCount\"),\n recoveredErrorCount: boundedCount(run.recoveredErrorCount, \"run.recoveredErrorCount\"),\n };\n}\n\nfunction parseGeneration(value: unknown, index: number, budget: ParseBudget): GenerationRecord {\n const item = asRecord(value, `run.generations[${index}]`);\n const prefix = `run.generations[${index}]`;\n return {\n id: requiredString(item.id, `${prefix}.id`),\n ordinal: boundedCount(item.ordinal, `${prefix}.ordinal`),\n ...optionalProperty(\"provider\", optionalString(item.provider, `${prefix}.provider`)),\n ...optionalProperty(\"model\", optionalString(item.model, `${prefix}.model`)),\n ...optionalProperty(\"thinkingLevel\", optionalString(item.thinkingLevel, `${prefix}.thinkingLevel`)),\n startedAtMs: timestampValue(item.startedAtMs, `${prefix}.startedAtMs`),\n ...optionalProperty(\"finishedAtMs\", optionalTimestamp(item.finishedAtMs, `${prefix}.finishedAtMs`)),\n ...optionalProperty(\"durationMs\", optionalDuration(item.durationMs, `${prefix}.durationMs`)),\n ...optionalProperty(\"stopReason\", optionalString(item.stopReason, `${prefix}.stopReason`)),\n outcome: enumValue(item.outcome, GENERATION_OUTCOMES, `${prefix}.outcome`) as GenerationOutcome,\n responses: boundedArray(item.responses, `${prefix}.responses`, budget).map(parseProviderResponse),\n };\n}\n\nfunction parseProviderResponse(value: unknown, index: number): ProviderResponseRecord {\n const item = asRecord(value, `provider response ${index}`);\n return {\n ordinal: boundedCount(item.ordinal, \"providerResponse.ordinal\"),\n occurredAtMs: timestampValue(item.occurredAtMs, \"providerResponse.occurredAtMs\"),\n status: boundedInteger(item.status, \"providerResponse.status\", 999),\n };\n}\n\nfunction parseTool(value: unknown, index: number): ToolCallRecord {\n const item = asRecord(value, `run.tools[${index}]`);\n const prefix = `run.tools[${index}]`;\n const ordinal = boundedCount(item.ordinal, `${prefix}.ordinal`);\n return {\n id: `tool-${ordinal}`,\n ordinal,\n name: requiredString(item.name, `${prefix}.name`),\n ...optionalProperty(\"provider\", optionalString(item.provider, `${prefix}.provider`)),\n ...optionalProperty(\"model\", optionalString(item.model, `${prefix}.model`)),\n startedAtMs: timestampValue(item.startedAtMs, `${prefix}.startedAtMs`),\n ...optionalProperty(\"finishedAtMs\", optionalTimestamp(item.finishedAtMs, `${prefix}.finishedAtMs`)),\n ...optionalProperty(\"durationMs\", optionalDuration(item.durationMs, `${prefix}.durationMs`)),\n isError: booleanValue(item.isError, `${prefix}.isError`),\n completionState: enumValue(\n item.completionState,\n [\"running\", \"finished\", \"interrupted\"] as const,\n `${prefix}.completionState`,\n ),\n };\n}\n\nfunction parseSkill(value: unknown, index: number): SkillActivationRecord {\n const item = asRecord(value, `run.skills[${index}]`);\n const prefix = `run.skills[${index}]`;\n return {\n id: requiredString(item.id, `${prefix}.id`),\n name: requiredString(item.name, `${prefix}.name`),\n initiatedBy: enumValue(item.initiatedBy, [\"user\", \"model\"] as const, `${prefix}.initiatedBy`),\n occurredAtMs: timestampValue(item.occurredAtMs, `${prefix}.occurredAtMs`),\n ...optionalProperty(\"provider\", optionalString(item.provider, `${prefix}.provider`)),\n ...optionalProperty(\"model\", optionalString(item.model, `${prefix}.model`)),\n };\n}\n\nfunction parseProviderError(value: unknown, index: number): ProviderErrorRecord {\n const item = asRecord(value, `run.providerErrors[${index}]`);\n const prefix = `run.providerErrors[${index}]`;\n return {\n id: requiredString(item.id, `${prefix}.id`),\n ...optionalProperty(\"generationId\", optionalString(item.generationId, `${prefix}.generationId`)),\n occurredAtMs: timestampValue(item.occurredAtMs, `${prefix}.occurredAtMs`),\n ...optionalProperty(\"provider\", optionalString(item.provider, `${prefix}.provider`)),\n ...optionalProperty(\"model\", optionalString(item.model, `${prefix}.model`)),\n category: enumValue(item.category, ERROR_CATEGORIES, `${prefix}.category`) as ProviderErrorCategory,\n recovered: booleanValue(item.recovered, `${prefix}.recovered`),\n terminal: booleanValue(item.terminal, `${prefix}.terminal`),\n };\n}\n\nfunction asRecord(value: unknown, name: string): Record<string, unknown> {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) invalid(name);\n return value as Record<string, unknown>;\n}\n\nfunction boundedArray(value: unknown, name: string, budget: ParseBudget): unknown[] {\n if (!Array.isArray(value)) invalid(name);\n budget.remaining -= value.length;\n if (budget.remaining < 0) {\n throw new AnalyticsStorageFormatError(\"Analytics record is too large to process safely.\");\n }\n return value;\n}\n\nfunction requiredString(value: unknown, name: string): string {\n if (typeof value !== \"string\" || value.length === 0 || value.length > MAX_STRING_LENGTH) {\n invalid(name);\n }\n return value;\n}\n\nfunction optionalString(value: unknown, name: string): string | undefined {\n return value === undefined ? undefined : requiredString(value, name);\n}\n\nfunction boundedInteger(value: unknown, name: string, maximum: number): number {\n if (typeof value !== \"number\" || !Number.isSafeInteger(value) || value < 0 || value > maximum) {\n invalid(name);\n }\n return value;\n}\n\nfunction timestampValue(value: unknown, name: string): number {\n return boundedInteger(value, name, Number.MAX_SAFE_INTEGER);\n}\n\nfunction optionalTimestamp(value: unknown, name: string): number | undefined {\n return value === undefined ? undefined : timestampValue(value, name);\n}\n\nfunction durationValue(value: unknown, name: string): number {\n return boundedInteger(value, name, Math.floor(Number.MAX_SAFE_INTEGER / MAX_NESTED_RECORDS));\n}\n\nfunction optionalDuration(value: unknown, name: string): number | undefined {\n return value === undefined ? undefined : durationValue(value, name);\n}\n\nfunction boundedCount(value: unknown, name: string): number {\n return boundedInteger(value, name, MAX_NESTED_RECORDS);\n}\n\nfunction booleanValue(value: unknown, name: string): boolean {\n if (typeof value !== \"boolean\") invalid(name);\n return value;\n}\n\nfunction enumValue<const T extends readonly string[]>(value: unknown, values: T, name: string): T[number] {\n if (typeof value !== \"string\" || !values.includes(value)) invalid(name);\n return value as T[number];\n}\n\nfunction optionalProperty<K extends string, T>(key: K, value: T | undefined): { [P in K]?: T } {\n return value === undefined ? {} : ({ [key]: value } as { [P in K]?: T });\n}\n\nfunction invalid(name: string): never {\n throw new AnalyticsStorageFormatError(`Analytics record has an invalid ${name}.`);\n}\n", "import type { SettledRun } from \"../types.js\";\nimport { AnalyticsGenerationChangedError, AnalyticsRunFiles, type ClearAnalyticsResult } from \"./files.js\";\nimport { type AnalyticsSnapshot, querySnapshot, type TimeRange } from \"./queries.js\";\n\nexport class AnalyticsStore {\n private readonly files: AnalyticsRunFiles;\n\n constructor(\n rootPath: string,\n dependencies: {\n files?: AnalyticsRunFiles;\n createId?: () => string;\n writeTimeoutMs?: number;\n } = {},\n ) {\n this.files =\n dependencies.files ??\n new AnalyticsRunFiles(rootPath, {\n createId: dependencies.createId,\n writeTimeoutMs: dependencies.writeTimeoutMs,\n });\n }\n\n get path(): string {\n return this.files.path;\n }\n\n recordRun(run: SettledRun, signal?: AbortSignal): Promise<void> {\n return this.files.append(run, signal);\n }\n\n async getSnapshot(range: TimeRange, signal?: AbortSignal): Promise<AnalyticsSnapshot> {\n for (let attempt = 0; attempt < 2; attempt += 1) {\n try {\n return await querySnapshot(this.files.read(signal), range, signal);\n } catch (error) {\n if (!(error instanceof AnalyticsGenerationChangedError) || attempt > 0) throw error;\n }\n }\n throw new AnalyticsGenerationChangedError();\n }\n\n clearAll(signal?: AbortSignal): Promise<ClearAnalyticsResult> {\n return this.files.clear(signal);\n }\n\n close(): Promise<void> {\n return this.files.close();\n }\n}\n"],
5
+ "mappings": ";;;;AAAA,SAAS,cAAAA,mBAAkB;AAC3B,OAAOC,WAAU;AACjB,SAAmD,mBAAmB;;;ACFtE,SAAS,kBAAkB;;;ACEpB,SAAS,sBAAsB,SAAoD;AACxF,QAAM,QAAQ,SAAS,YAAY,KAAK;AACxC,MAAI,6CAA6C,KAAK,KAAK,EAAG,QAAO;AACrE,MAAI,qCAAqC,KAAK,KAAK,EAAG,QAAO;AAC7D,MAAI,yCAAyC,KAAK,KAAK,EAAG,QAAO;AACjE,MAAI,oDAAoD,KAAK,KAAK,GAAG;AACnE,WAAO;AAAA,EACT;AACA,MAAI,6CAA6C,KAAK,KAAK,EAAG,QAAO;AACrE,MAAI,0DAA0D,KAAK,KAAK,GAAG;AACzE,WAA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