espennilsen/pi / extensions/pi-a2a
pi-a2a
Flaggedtool-telemetry.ts
View on GitHubimport type { TelemetrySnapshot, ToolCallRecord } from "./types.ts";
/** Copy buffered tool calls into a snapshot payload without draining the buffer. */
export function buildRecentToolCallsSnapshot(recentToolCalls: readonly ToolCallRecord[]): ToolCallRecord[] | undefined {
return recentToolCalls.length > 0 ? [...recentToolCalls] : undefined;
}
/** Build the final idle snapshot sent during shutdown, including any unsent tool calls. */
export function buildIdleTelemetrySnapshot(recentToolCalls: readonly ToolCallRecord[]): TelemetrySnapshot {
const snapshot: TelemetrySnapshot = {
queueDepth: 0,
activeTasks: 0,
maxConcurrent: 1,
};
const toolCallSnapshot = buildRecentToolCallsSnapshot(recentToolCalls);
if (toolCallSnapshot !== undefined) snapshot.recentToolCalls = toolCallSnapshot;
return snapshot;
}
/** Serialize async telemetry operations so snapshot + drain stays atomic. */
export function createSerializedAsyncRunner() {
let queue = Promise.resolve();
return async function runSerialized<T>(operation: () => Promise<T>): Promise<T> {
const result = queue.then(operation, operation);
queue = result.then(() => undefined, () => undefined);
return result;
};
}
/** Drop only the tool calls that were successfully reported to the hub. */
export function drainRecentToolCalls(recentToolCalls: ToolCallRecord[], sentCount: number): void {
if (sentCount <= 0) return;
recentToolCalls.splice(0, sentCount);
}
/** Reset all in-memory tool telemetry state for a fresh session lifecycle. */
export function resetToolTelemetryState(
toolCallsInProgress: Map<string, unknown>,
recentToolCalls: ToolCallRecord[],
): void {
toolCallsInProgress.clear();
recentToolCalls.length = 0;
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |