{"version":3,"file":"retained-children.d.ts","sourceRoot":"","sources":["../../../../src/runs/background/retained-children.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAMxD,MAAM,WAAW,aAAa;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,UAAU,CAAC;CACzB;AAmBD,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,aAAa,EAAE,CA0B7F;AAED,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,aAAa,EAAE,GAAG,MAAM,CAexE","sourcesContent":["import * as fs from \"node:fs\";\nimport type { TokenUsage } from \"../../shared/types.ts\";\nimport { listAsyncRuns } from \"./async-status.ts\";\n\nconst MAX_RETAINED_CHILDREN = 10;\nconst MAX_TASK_SUMMARY_LENGTH = 120;\n\nexport interface RetainedChild {\n\trunId: string;\n\tparentRunId?: string;\n\tagent: string;\n\ttaskSummary: string;\n\tcompletedAt: number;\n\tsessionPath: string;\n\ttokenTotals?: TokenUsage;\n}\n\nfunction retainedSessionFile(sessionFile: string | undefined): sessionFile is string {\n\tif (!sessionFile?.endsWith(\".jsonl\")) return false;\n\ttry {\n\t\tconst stat = fs.lstatSync(sessionFile);\n\t\treturn stat.isFile() && !stat.isSymbolicLink();\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction boundedTaskSummary(value: string | undefined): string {\n\tconst normalized = value?.replace(/\\s+/g, \" \").trim() ?? \"\";\n\treturn normalized.length > MAX_TASK_SUMMARY_LENGTH\n\t\t? `${normalized.slice(0, MAX_TASK_SUMMARY_LENGTH - 1)}…`\n\t\t: normalized;\n}\n\nexport function listRetainedChildren(asyncDirRoot: string, sessionId: string): RetainedChild[] {\n\treturn listAsyncRuns(asyncDirRoot, { sessionId, states: [\"complete\"], reconcile: false })\n\t\t.flatMap((run) => {\n\t\t\tif (!run.parentWorkflowRunId || run.steps.length !== 1) return [];\n\t\t\tconst step = run.steps[0]!;\n\t\t\tif (\n\t\t\t\t(step.status !== \"complete\" && step.status !== \"completed\") ||\n\t\t\t\t!retainedSessionFile(step.sessionFile ?? run.sessionFile)\n\t\t\t)\n\t\t\t\treturn [];\n\t\t\tconst completedAt = run.endedAt;\n\t\t\tif (completedAt === undefined) return [];\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\trunId: run.id,\n\t\t\t\t\t...(run.parentWorkflowRunId ? { parentRunId: run.parentWorkflowRunId } : {}),\n\t\t\t\t\tagent: step.agent,\n\t\t\t\t\ttaskSummary: boundedTaskSummary(step.description),\n\t\t\t\t\tcompletedAt,\n\t\t\t\t\tsessionPath: step.sessionFile ?? run.sessionFile!,\n\t\t\t\t\t...((step.tokens ?? run.totalTokens) ? { tokenTotals: step.tokens ?? run.totalTokens } : {}),\n\t\t\t\t},\n\t\t\t];\n\t\t})\n\t\t.sort((left, right) => right.completedAt - left.completedAt)\n\t\t.slice(0, MAX_RETAINED_CHILDREN);\n}\n\nexport function formatRetainedChildren(children: RetainedChild[]): string {\n\tif (children.length === 0) return \"No completed retained children in the active parent session.\";\n\treturn [\n\t\t`Completed retained children (newest first, last ${MAX_RETAINED_CHILDREN}):`,\n\t\t...children.flatMap((child) => [\n\t\t\t`- ${child.runId} | ${child.agent} | ${new Date(child.completedAt).toISOString()}`,\n\t\t\t`  task: ${child.taskSummary || \"(no task summary)\"}`,\n\t\t\t`  session: ${child.sessionPath}`,\n\t\t\t...(child.tokenTotals\n\t\t\t\t? [\n\t\t\t\t\t\t`  tokens: input ${child.tokenTotals.input}, output ${child.tokenTotals.output}, total ${child.tokenTotals.total}`,\n\t\t\t\t\t]\n\t\t\t\t: []),\n\t\t]),\n\t].join(\"\\n\");\n}\n"]}