Skip to content
TypeScript
1.3 KB
Raw Blame
/**
 * TranscriptParser 인터페이스 (PRD §8).
 * 공통: subagentCount = name ∈ {Task, Agent} 인 tool_use 수(★ 정렬키).
 *       skillFires = {Skill, SlashCommand}. mcpCalls = name.startsWith('mcp__').
 *       토큰 = 모든 assistant usage 합.
 */
import type { ParsedTranscript } from "../models";

export interface TranscriptParser {
  agent: "cc" | "codex";
  parse(transcriptPath: string, opts?: { model?: string }): ParsedTranscript;
}

export const SUBAGENT_NAMES = new Set(["Task", "Agent"]);
export const SKILL_NAMES = new Set(["Skill", "SlashCommand"]);

export function isMcp(name: string | null | undefined): boolean {
  return typeof name === "string" && name.startsWith("mcp__");
}

/** ['Read','Read','Bash'] → ['Read×2','Bash×1'] (빈도 압축) */
export function compressTools(tools: string[]): string[] {
  const counts = new Map<string, number>();
  for (const t of tools) counts.set(t, (counts.get(t) ?? 0) + 1);
  return [...counts.entries()].map(([t, c]) => `${t}×${c}`);
}

export function tsToMs(ts: unknown): number | null {
  if (typeof ts === "number") return ts;
  if (typeof ts === "string") {
    const ms = Date.parse(ts);
    return Number.isNaN(ms) ? null : ms;
  }
  return null;
}

export function truncate(s: string, n = 240): string {
  return s.length > n ? `${s.slice(0, n)}…` : s;
}