agentix-cli 0.30.0 → 0.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/dist/{App-IEQXWJ7B.js → App-2LAWZNMG.js} +2 -2
  2. package/dist/{ChatApp-NWOSAP5U.js → ChatApp-2KRDHMTV.js} +2 -2
  3. package/dist/{agent-SPE7Q7MD.js → agent-ZRRIMLTX.js} +2 -2
  4. package/dist/{board-dashboard-K4DM32SO.js → board-dashboard-LL3YVODL.js} +192 -171
  5. package/dist/board-dashboard-LL3YVODL.js.map +1 -0
  6. package/dist/{chunk-MGNJWBVP.js → chunk-2DBGOCCW.js} +2 -2
  7. package/dist/{chunk-MGNJWBVP.js.map → chunk-2DBGOCCW.js.map} +1 -1
  8. package/dist/chunk-2DMVKLLE.js +13 -0
  9. package/dist/chunk-2DMVKLLE.js.map +1 -0
  10. package/dist/chunk-2GIDVZ4H.js +3 -0
  11. package/dist/{chunk-EVWEG3VD.js.map → chunk-2GIDVZ4H.js.map} +1 -1
  12. package/dist/{chunk-UCQ2N3KO.js → chunk-2TJ5L7CB.js} +2 -2
  13. package/dist/{chunk-FKBGJYWQ.js → chunk-3RHPZXCR.js} +2 -2
  14. package/dist/{chunk-DI7FMCDK.js → chunk-4CR463C6.js} +2 -2
  15. package/dist/{chunk-IVQO43U2.js → chunk-5FEQI22L.js} +2 -2
  16. package/dist/{chunk-45BLFNDG.js → chunk-6VQKHMEQ.js} +47 -47
  17. package/dist/chunk-6VQKHMEQ.js.map +1 -0
  18. package/dist/{chunk-52ZPELD2.js → chunk-7CVJ4JOE.js} +2 -2
  19. package/dist/{chunk-4KXBUORV.js → chunk-A4YR3PQY.js} +2 -2
  20. package/dist/{chunk-Q7CZIRBB.js → chunk-B2XTYYXV.js} +2 -2
  21. package/dist/{chunk-JKYMXLYL.js → chunk-G5MFPNGJ.js} +2 -2
  22. package/dist/{chunk-EL3J74N2.js → chunk-GWQIMAJ7.js} +2 -2
  23. package/dist/{chunk-42DCRKUD.js → chunk-H57XXGMF.js} +96 -94
  24. package/dist/chunk-H57XXGMF.js.map +1 -0
  25. package/dist/{chunk-V4HURNMX.js → chunk-JGJE5Y2J.js} +2 -2
  26. package/dist/{chunk-SC5DIKBB.js → chunk-JWKIFAXA.js} +2 -2
  27. package/dist/{chunk-UU4WOZNR.js → chunk-K6E7WJ7O.js} +2 -2
  28. package/dist/{chunk-AUNDQPDR.js → chunk-MFVI5FOM.js} +2 -2
  29. package/dist/{chunk-M4AMWP3H.js → chunk-QLTM3F7M.js} +17 -8
  30. package/dist/{chunk-M4AMWP3H.js.map → chunk-QLTM3F7M.js.map} +1 -1
  31. package/dist/{chunk-IWMW5432.js → chunk-V7FYSZSV.js} +1 -1
  32. package/dist/{chunk-IWMW5432.js.map → chunk-V7FYSZSV.js.map} +1 -1
  33. package/dist/chunk-VMDA2SX2.js +43 -0
  34. package/dist/chunk-VMDA2SX2.js.map +1 -0
  35. package/dist/{chunk-GK7XAM3D.js → chunk-W3YGESNK.js} +2 -2
  36. package/dist/{chunk-GUBMLV34.js → chunk-WFIBOAXN.js} +8 -8
  37. package/dist/chunk-WFIBOAXN.js.map +1 -0
  38. package/dist/cli.js +1 -1
  39. package/dist/client-IP643GRO.js +2 -0
  40. package/dist/config-IVDP46ZG.js +2 -0
  41. package/dist/config-mutator-UCGAV3SP.js +2 -0
  42. package/dist/doctor-MMT4SREV.js +2 -0
  43. package/dist/index.d.ts +35 -0
  44. package/dist/index.js +1 -1
  45. package/dist/processes-I3XAPHG7.js +2 -0
  46. package/dist/program-7ULXLTD6.js +2 -0
  47. package/dist/query-RHVR6QUZ.js +2 -0
  48. package/dist/registry-OB6S66XX.js +2 -0
  49. package/dist/request-planner-F5NVL2G7.js +2 -0
  50. package/dist/request-planner-F5NVL2G7.js.map +1 -0
  51. package/dist/{review-candidates-O2PS7L3B.js → review-candidates-IRPKFWL2.js} +2 -2
  52. package/dist/{rotation-memo-7T75BLEX.js → rotation-memo-QEO3COFH.js} +3 -3
  53. package/dist/rotation-memo-QEO3COFH.js.map +1 -0
  54. package/dist/{routing-5K7PGHPL.js → routing-OSPRKRAY.js} +2 -2
  55. package/dist/scheduler-JL6K5HHI.js +2 -0
  56. package/dist/{seat-FZRNRAHQ.js → seat-2MHKVMW2.js} +2 -2
  57. package/dist/{select-SOJYFAMI.js → select-7LCHJVPK.js} +2 -2
  58. package/dist/{surface-usage-NS74AXSE.js → surface-usage-UREILT2E.js} +2 -2
  59. package/dist/web/activity-graph.global.js +901 -368
  60. package/dist/web/activity-graph.global.js.map +1 -1
  61. package/dist/wiki-MY32MON3.js +2 -0
  62. package/package.json +2 -1
  63. package/dist/board-dashboard-K4DM32SO.js.map +0 -1
  64. package/dist/chunk-42DCRKUD.js.map +0 -1
  65. package/dist/chunk-45BLFNDG.js.map +0 -1
  66. package/dist/chunk-4BR7D2OU.js +0 -36
  67. package/dist/chunk-4BR7D2OU.js.map +0 -1
  68. package/dist/chunk-EVWEG3VD.js +0 -3
  69. package/dist/chunk-GMNKJXTR.js +0 -13
  70. package/dist/chunk-GMNKJXTR.js.map +0 -1
  71. package/dist/chunk-GUBMLV34.js.map +0 -1
  72. package/dist/client-5Z3URGPY.js +0 -2
  73. package/dist/config-ORSGLVRW.js +0 -2
  74. package/dist/config-mutator-JB3S2E7H.js +0 -2
  75. package/dist/doctor-FS2BX6H4.js +0 -2
  76. package/dist/processes-WU23U2OJ.js +0 -2
  77. package/dist/program-DWZAI4GY.js +0 -2
  78. package/dist/query-3HXGBKGM.js +0 -2
  79. package/dist/registry-EJRWAJYG.js +0 -2
  80. package/dist/request-planner-BCOXUAPA.js +0 -2
  81. package/dist/request-planner-BCOXUAPA.js.map +0 -1
  82. package/dist/rotation-memo-7T75BLEX.js.map +0 -1
  83. package/dist/scheduler-DSAOMV4O.js +0 -2
  84. package/dist/wiki-34XVI32N.js +0 -2
  85. /package/dist/{App-IEQXWJ7B.js.map → App-2LAWZNMG.js.map} +0 -0
  86. /package/dist/{ChatApp-NWOSAP5U.js.map → ChatApp-2KRDHMTV.js.map} +0 -0
  87. /package/dist/{agent-SPE7Q7MD.js.map → agent-ZRRIMLTX.js.map} +0 -0
  88. /package/dist/{chunk-UCQ2N3KO.js.map → chunk-2TJ5L7CB.js.map} +0 -0
  89. /package/dist/{chunk-FKBGJYWQ.js.map → chunk-3RHPZXCR.js.map} +0 -0
  90. /package/dist/{chunk-DI7FMCDK.js.map → chunk-4CR463C6.js.map} +0 -0
  91. /package/dist/{chunk-IVQO43U2.js.map → chunk-5FEQI22L.js.map} +0 -0
  92. /package/dist/{chunk-52ZPELD2.js.map → chunk-7CVJ4JOE.js.map} +0 -0
  93. /package/dist/{chunk-4KXBUORV.js.map → chunk-A4YR3PQY.js.map} +0 -0
  94. /package/dist/{chunk-Q7CZIRBB.js.map → chunk-B2XTYYXV.js.map} +0 -0
  95. /package/dist/{chunk-JKYMXLYL.js.map → chunk-G5MFPNGJ.js.map} +0 -0
  96. /package/dist/{chunk-EL3J74N2.js.map → chunk-GWQIMAJ7.js.map} +0 -0
  97. /package/dist/{chunk-V4HURNMX.js.map → chunk-JGJE5Y2J.js.map} +0 -0
  98. /package/dist/{chunk-SC5DIKBB.js.map → chunk-JWKIFAXA.js.map} +0 -0
  99. /package/dist/{chunk-UU4WOZNR.js.map → chunk-K6E7WJ7O.js.map} +0 -0
  100. /package/dist/{chunk-AUNDQPDR.js.map → chunk-MFVI5FOM.js.map} +0 -0
  101. /package/dist/{chunk-GK7XAM3D.js.map → chunk-W3YGESNK.js.map} +0 -0
  102. /package/dist/{client-5Z3URGPY.js.map → client-IP643GRO.js.map} +0 -0
  103. /package/dist/{config-ORSGLVRW.js.map → config-IVDP46ZG.js.map} +0 -0
  104. /package/dist/{config-mutator-JB3S2E7H.js.map → config-mutator-UCGAV3SP.js.map} +0 -0
  105. /package/dist/{doctor-FS2BX6H4.js.map → doctor-MMT4SREV.js.map} +0 -0
  106. /package/dist/{processes-WU23U2OJ.js.map → processes-I3XAPHG7.js.map} +0 -0
  107. /package/dist/{program-DWZAI4GY.js.map → program-7ULXLTD6.js.map} +0 -0
  108. /package/dist/{query-3HXGBKGM.js.map → query-RHVR6QUZ.js.map} +0 -0
  109. /package/dist/{registry-EJRWAJYG.js.map → registry-OB6S66XX.js.map} +0 -0
  110. /package/dist/{review-candidates-O2PS7L3B.js.map → review-candidates-IRPKFWL2.js.map} +0 -0
  111. /package/dist/{routing-5K7PGHPL.js.map → routing-OSPRKRAY.js.map} +0 -0
  112. /package/dist/{scheduler-DSAOMV4O.js.map → scheduler-JL6K5HHI.js.map} +0 -0
  113. /package/dist/{seat-FZRNRAHQ.js.map → seat-2MHKVMW2.js.map} +0 -0
  114. /package/dist/{select-SOJYFAMI.js.map → select-7LCHJVPK.js.map} +0 -0
  115. /package/dist/{surface-usage-NS74AXSE.js.map → surface-usage-UREILT2E.js.map} +0 -0
  116. /package/dist/{wiki-34XVI32N.js.map → wiki-MY32MON3.js.map} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/storage/traces.ts"],"sourcesContent":["import type Database from \"better-sqlite3\"\nimport { newEventId } from \"@/intent/ulid\"\n\n// --- Task trace store ---\n//\n// Improvement plan #2 — per-task observability backed by SQLite. One\n// task_traces row per executeTask invocation, an append-only stream of\n// task_trace_steps inside it. The store is intentionally dumb: it stores\n// what callers give it. Callers (capture sites in src/agents/runtime.ts)\n// are responsible for byte-capping large step payloads so the daemon\n// memory stays bounded under tool-heavy turns.\n//\n// Why a separate store layer (vs writing inline in runtime.ts)?\n// - Tests can exercise the trace lifecycle against a temp SQLite without\n// spinning up the agent runtime.\n// - The HTTP endpoints (GET /task/:id/trace) read through the same\n// functions producers write through, so there's a single source of\n// truth on field names + semantics.\n// - Future capture sites (sdk tier, orchestrator tier) reuse this API\n// without copying SQL.\n//\n// Why ULID for task_id?\n// - URL-safe in HTTP routes (GET /task/:id/trace).\n// - Time-sortable, so listTraces ORDER BY started_at and ORDER BY\n// task_id agree without an explicit timestamp column index.\n// - Already in-tree (src/intent/ulid.ts); no new dep.\n//\n// Cross-DB FK note:\n// intent_event_id and intent_decided_by are logical foreign keys into\n// the intent ledger at .agentx/intent/ledger.sqlite. better-sqlite3\n// doesn't enforce cross-database FKs and we don't ATTACH the ledger\n// here on purpose — the rescue plan's append-only contract on the\n// ledger is honoured by routing all writes through src/intent/ledger.ts.\n// Joins happen at the HTTP / CLI layer when needed.\n\nexport interface TraceStartInput {\n agentId: string\n channel?: string | null\n chatId?: string | null\n messagePreview?: string | null\n /** Full untruncated user message — used by `agentx trace replay <taskId>`\n * to re-fire a recorded task against the current agent config. NULL on\n * rows from before migration v8, in which case replay falls back to\n * messagePreview (which is capped at 200 chars). */\n originalMessage?: string | null\n workflowRunId?: string | null\n workflowId?: string | null\n workflowNodeId?: string | null\n intentEventId?: string | null\n intentDecidedBy?: string | null\n resumeSessionId?: string | null\n model?: string | null\n}\n\nexport interface TraceEndInput {\n status: \"ok\" | \"error\" | \"timeout\"\n finalSessionId?: string | null\n inputTokens?: number | null\n outputTokens?: number | null\n cacheReadTokens?: number | null\n cacheCreateTokens?: number | null\n tier2InputTokens?: number | null\n tier2OutputTokens?: number | null\n tier2CacheReadTokens?: number | null\n tier2CacheCreateTokens?: number | null\n /** Whether the turn continued a provider session. The resume decision\n * is made after task:started, so it is recorded at the end. Omitted\n * leaves both resumed and resume_session_id untouched. */\n resumed?: boolean | null\n resumeSessionId?: string | null\n /** Request-gate experiment arm: \"treatment\" | \"holdout\". */\n jevArm?: string | null\n error?: string | null\n /** The agent's final reply text. Stored verbatim so `replay --diff`\n * can compare original output vs the new run's output without\n * reconstructing it from the step ledger. NULL when the response\n * wasn't captured (older rows or non-text outputs). */\n finalResponse?: string | null\n}\n\nexport interface TraceStepInput {\n /** Coarse step kind. Conventional values: \"tool_use\" | \"tool_result\" |\n * \"llm_message\" | \"session_rotation\" | \"error\" | \"preflight\". Free-form\n * strings allowed so future capture sites don't need a schema bump. */\n name: string\n /** Fine-grained name within the kind. For \"tool_use\", this is the tool\n * name (e.g. \"Bash\", \"Edit\"). Optional. */\n action?: string | null\n status?: \"ok\" | \"error\" | \"in-flight\" | null\n /** JSON-stringified input or human-readable summary. Caller-byte-capped. */\n inputSummary?: string | null\n outputSummary?: string | null\n error?: string | null\n /** Step duration when known. Optional — many step kinds are point-in-time. */\n ms?: number | null\n}\n\nexport interface TraceRecord {\n taskId: string\n agentId: string\n channel: string | null\n chatId: string | null\n workflowRunId: string | null\n workflowId: string | null\n workflowNodeId: string | null\n intentEventId: string | null\n intentDecidedBy: string | null\n resumeSessionId: string | null\n finalSessionId: string | null\n model: string | null\n status: string\n startedAt: number\n finishedAt: number | null\n durationMs: number | null\n inputTokens: number | null\n outputTokens: number | null\n cacheReadTokens: number | null\n cacheCreateTokens: number | null\n tier2InputTokens: number | null\n tier2OutputTokens: number | null\n tier2CacheReadTokens: number | null\n tier2CacheCreateTokens: number | null\n /** NULL on rows recorded before migration v12. */\n resumed: boolean | null\n /** NULL when the request gate was not active (or before migration v13). */\n jevArm: string | null\n error: string | null\n messagePreview: string | null\n /** Full untruncated user message — populated for traces from migration v8\n * onward. NULL on older rows; consumers should fall back to messagePreview. */\n originalMessage: string | null\n /** Agent's final reply text — populated for traces from migration v8\n * onward when the executor records it on end. */\n finalResponse: string | null\n}\n\nexport interface TraceStepRecord {\n taskId: string\n seq: number\n name: string\n action: string | null\n status: string | null\n inputSummary: string | null\n outputSummary: string | null\n error: string | null\n ms: number | null\n startedAt: number\n}\n\nexport interface ListTracesFilters {\n agentId?: string\n channel?: string\n chatId?: string\n workflowRunId?: string\n status?: string\n /** ms epoch */\n since?: number\n /** ms epoch */\n until?: number\n /** Default 100, capped at 1000. */\n limit?: number\n}\n\n/**\n * Insert an in-flight trace row and return its ULID. Callers thread the\n * returned id through the executor and call recordTraceEnd at finish time.\n *\n * `taskId` is optional — when supplied, the caller has already allocated\n * a ULID upstream (e.g. registry.execute generating it before the bus\n * event so the runtime can capture per-step rows under the same id).\n * When omitted, a fresh ULID is allocated here.\n */\nexport function recordTraceStart(\n db: Database.Database,\n input: TraceStartInput,\n taskId: string = newEventId(),\n): string {\n db.prepare(`\n INSERT INTO task_traces (\n task_id, agent_id, channel, chat_id, workflow_run_id, workflow_id,\n workflow_node_id, intent_event_id, intent_decided_by, resume_session_id,\n model, status, started_at, message_preview, original_message\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'in-flight', ?, ?, ?)\n `).run(\n taskId,\n input.agentId,\n input.channel ?? null,\n input.chatId ?? null,\n input.workflowRunId ?? null,\n input.workflowId ?? null,\n input.workflowNodeId ?? null,\n input.intentEventId ?? null,\n input.intentDecidedBy ?? null,\n input.resumeSessionId ?? null,\n input.model ?? null,\n Date.now(),\n input.messagePreview ?? null,\n input.originalMessage ?? null,\n )\n return taskId\n}\n\n/**\n * Finalize a trace. duration_ms is computed from finished_at - started_at\n * inside the UPDATE so the two columns can never disagree. Idempotent —\n * calling twice on the same task_id overwrites the prior end values; the\n * second call's status wins. (Soft-overwrite is intentional: timeout\n * handlers may write before a late stream-completion arrives.)\n */\nexport function recordTraceEnd(db: Database.Database, taskId: string, input: TraceEndInput): void {\n const finishedAt = Date.now()\n db.prepare(`\n UPDATE task_traces SET\n status = ?,\n final_session_id = ?,\n input_tokens = ?,\n output_tokens = ?,\n cache_read_tokens = ?,\n cache_create_tokens = ?,\n tier2_input_tokens = ?,\n tier2_output_tokens = ?,\n tier2_cache_read_tokens = ?,\n tier2_cache_create_tokens = ?,\n resumed = COALESCE(?, resumed),\n resume_session_id = COALESCE(?, resume_session_id),\n jev_arm = COALESCE(?, jev_arm),\n error = ?,\n final_response = COALESCE(?, final_response),\n finished_at = ?,\n duration_ms = ? - started_at\n WHERE task_id = ?\n `).run(\n input.status,\n input.finalSessionId ?? null,\n input.inputTokens ?? null,\n input.outputTokens ?? null,\n input.cacheReadTokens ?? null,\n input.cacheCreateTokens ?? null,\n input.tier2InputTokens ?? null,\n input.tier2OutputTokens ?? null,\n input.tier2CacheReadTokens ?? null,\n input.tier2CacheCreateTokens ?? null,\n input.resumed == null ? null : input.resumed ? 1 : 0,\n input.resumeSessionId ?? null,\n input.jevArm ?? null,\n input.error ?? null,\n input.finalResponse ?? null,\n finishedAt,\n finishedAt,\n taskId,\n )\n}\n\n/**\n * Append a step. seq is auto-allocated as MAX(seq)+1 within a transaction\n * so concurrent step writes for the same task_id can't collide. Returns\n * the assigned seq, useful for downstream correlation.\n */\nexport function recordTraceStep(db: Database.Database, taskId: string, input: TraceStepInput): number {\n const startedAt = Date.now()\n const allocateAndInsert = db.transaction((): number => {\n const row = db\n .prepare(\"SELECT MAX(seq) AS max_seq FROM task_trace_steps WHERE task_id = ?\")\n .get(taskId) as { max_seq: number | null } | undefined\n const seq = ((row?.max_seq ?? -1) as number) + 1\n db.prepare(`\n INSERT INTO task_trace_steps (\n task_id, seq, name, action, status, input_summary, output_summary, error, ms, started_at\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\n `).run(\n taskId,\n seq,\n input.name,\n input.action ?? null,\n input.status ?? null,\n input.inputSummary ?? null,\n input.outputSummary ?? null,\n input.error ?? null,\n input.ms ?? null,\n startedAt,\n )\n return seq\n })\n return allocateAndInsert()\n}\n\nfunction rowToTrace(row: Record<string, unknown>): TraceRecord {\n return {\n taskId: row.task_id as string,\n agentId: row.agent_id as string,\n channel: (row.channel as string) ?? null,\n chatId: (row.chat_id as string) ?? null,\n workflowRunId: (row.workflow_run_id as string) ?? null,\n workflowId: (row.workflow_id as string) ?? null,\n workflowNodeId: (row.workflow_node_id as string) ?? null,\n intentEventId: (row.intent_event_id as string) ?? null,\n intentDecidedBy: (row.intent_decided_by as string) ?? null,\n resumeSessionId: (row.resume_session_id as string) ?? null,\n finalSessionId: (row.final_session_id as string) ?? null,\n model: (row.model as string) ?? null,\n status: row.status as string,\n startedAt: row.started_at as number,\n finishedAt: (row.finished_at as number) ?? null,\n durationMs: (row.duration_ms as number) ?? null,\n inputTokens: (row.input_tokens as number) ?? null,\n outputTokens: (row.output_tokens as number) ?? null,\n cacheReadTokens: (row.cache_read_tokens as number) ?? null,\n cacheCreateTokens: (row.cache_create_tokens as number) ?? null,\n tier2InputTokens: (row.tier2_input_tokens as number) ?? null,\n tier2OutputTokens: (row.tier2_output_tokens as number) ?? null,\n tier2CacheReadTokens: (row.tier2_cache_read_tokens as number) ?? null,\n tier2CacheCreateTokens: (row.tier2_cache_create_tokens as number) ?? null,\n resumed: row.resumed == null ? null : row.resumed === 1,\n jevArm: (row.jev_arm as string) ?? null,\n error: (row.error as string) ?? null,\n messagePreview: (row.message_preview as string) ?? null,\n originalMessage: (row.original_message as string) ?? null,\n finalResponse: (row.final_response as string) ?? null,\n }\n}\n\nfunction rowToStep(row: Record<string, unknown>): TraceStepRecord {\n return {\n taskId: row.task_id as string,\n seq: row.seq as number,\n name: row.name as string,\n action: (row.action as string) ?? null,\n status: (row.status as string) ?? null,\n inputSummary: (row.input_summary as string) ?? null,\n outputSummary: (row.output_summary as string) ?? null,\n error: (row.error as string) ?? null,\n ms: (row.ms as number) ?? null,\n startedAt: row.started_at as number,\n }\n}\n\n/** Fetch a trace + its ordered steps. Returns null if no such task_id. */\nexport function getTrace(\n db: Database.Database,\n taskId: string,\n): { task: TraceRecord; steps: TraceStepRecord[] } | null {\n const row = db.prepare(\"SELECT * FROM task_traces WHERE task_id = ?\").get(taskId) as\n | Record<string, unknown>\n | undefined\n if (!row) return null\n const stepRows = db\n .prepare(\"SELECT * FROM task_trace_steps WHERE task_id = ? ORDER BY seq\")\n .all(taskId) as Record<string, unknown>[]\n return { task: rowToTrace(row), steps: stepRows.map(rowToStep) }\n}\n\n/**\n * Cancel any in-flight trace rows left over from a previous daemon\n * lifetime. Mirrors the intent ledger's startup cleanup (rescue plan\n * Phase 1 commit a8514d9): a hard-killed daemon never gets to fire\n * task:completed, so the row sits \"in-flight\" forever and contaminates\n * triage queries (`agentx trace list --status in-flight`) with stale\n * orphans. Run once at daemon boot before subscribers attach.\n *\n * Returns the number of rows updated. duration_ms is intentionally NOT\n * computed — we don't know when the task actually ended; preserving\n * NULL there is more honest than backdating to \"now\".\n */\nexport function cleanupOrphanedTraces(db: Database.Database): number {\n const now = Date.now()\n const r = db.prepare(`\n UPDATE task_traces\n SET status = 'canceled',\n error = 'daemon-restart (orphaned in-flight)',\n finished_at = ?\n WHERE status = 'in-flight'\n `).run(now)\n return (r.changes ?? 0) as number\n}\n\n/** Triage / dashboard surface — list traces newest-first, filtered. */\nexport function listTraces(db: Database.Database, filters: ListTracesFilters = {}): TraceRecord[] {\n const where: string[] = []\n const params: unknown[] = []\n if (filters.agentId) { where.push(\"agent_id = ?\"); params.push(filters.agentId) }\n if (filters.channel) { where.push(\"channel = ?\"); params.push(filters.channel) }\n if (filters.chatId) { where.push(\"chat_id = ?\"); params.push(filters.chatId) }\n if (filters.workflowRunId) { where.push(\"workflow_run_id = ?\"); params.push(filters.workflowRunId) }\n if (filters.status) { where.push(\"status = ?\"); params.push(filters.status) }\n if (filters.since !== undefined) { where.push(\"started_at >= ?\"); params.push(filters.since) }\n if (filters.until !== undefined) { where.push(\"started_at <= ?\"); params.push(filters.until) }\n\n const limit = Math.max(1, Math.min(filters.limit ?? 100, 1000))\n const sql = `\n SELECT * FROM task_traces\n ${where.length > 0 ? \"WHERE \" + where.join(\" AND \") : \"\"}\n ORDER BY started_at DESC\n LIMIT ?\n `\n params.push(limit)\n return (db.prepare(sql).all(...params) as Record<string, unknown>[]).map(rowToTrace)\n}\n"],"mappings":"+CACAA,IA2KO,SAASC,EACdC,EACAC,EACAC,EAAiBC,EAAW,EACpB,CACR,OAAAH,EAAG,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAMV,EAAE,IACDE,EACAD,EAAM,QACNA,EAAM,SAAW,KACjBA,EAAM,QAAU,KAChBA,EAAM,eAAiB,KACvBA,EAAM,YAAc,KACpBA,EAAM,gBAAkB,KACxBA,EAAM,eAAiB,KACvBA,EAAM,iBAAmB,KACzB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TraceStart","db","input","taskId","newEventId","recordTraceEnd","finishedAt","recordTraceStep","startedAt","seq","rowToTrace","row","rowToStep","getTrace","stepRows","cleanupOrphanedTraces","now","listTraces","filters","where","params","limit","sql"]}
@@ -1,2 +1,2 @@
1
- import{v as l,w}from"./chunk-MGNJWBVP.js";import{a as i,f as p}from"./chunk-F4HZTZHW.js";w();p();var d="task-tier";function u(e){return{task:f(e.message,2e3),agent:e.agent,channel:e.channel??null,continuesExistingSession:e.isFollowUp??!1,...e.toolsAvailable?{toolsAvailable:e.toolsAvailable}:{}}}var c={needsFlagship:i("This task needs the strongest available model to be done correctly.",{true:"Doing it well takes real reasoning: writing or reviewing code, diagnosing a failure, planning work across several steps, weighing a judgement, handling money, touching production or anything irreversible, following a long or ambiguous instruction, or work where being subtly wrong would not be noticed. Anything where a weaker model would produce something that LOOKS right belongs here.",false:"It is mechanical and its result is obvious on sight: acknowledging or confirming a message, restating or formatting something already written, a greeting, a status echo, reading one file and reporting what it says, a lookup with one right answer, a scheduled heartbeat with nothing to decide."})};function g(e){return e.needsFlagship.noul}function f(e,n){return e.length>n?`${e.slice(0,n)}\u2026`:e}var h=.2,m=60*60*1e3;function F(e,n){if(e==="claude-code"){let t=n?.cheapModels?.[e]??n?.cheapModel;return t&&/^(claude-|haiku$|sonnet$|opus$)/.test(t)?t:void 0}if(e==="codex-cli"){let t=n?.cheapModels?.[e];return t&&/^(gpt-|o\d)/.test(t)?t:void 0}}async function M(e){let n=(o,r=null)=>({downgraded:!1,needsFlagship:r,reason:o});if(e.channel==="voice"||e.channel==="desktop"||e.channel==="opencode")return n(`${e.channel} requests retain the configured model`);if(!e.cheapModel)return n("no cheaper model configured");if(e.isFollowUp){let o=e.sessionIdleMs??0,r=e.cacheTtlMs??m;if(o<r)return n(`follow-up on a warm cache (idle ${Math.round(o/1e3)}s) \u2014 swapping would cost more than it saves`)}let t;try{t=await l(d,u(e),c,{incumbent:{needsFlagship:1},features:{agent:e.agent,channel:e.channel??"unknown"}})}catch{return n("routing seat threw \u2014 keeping the flagship")}if(!t)return n("routing seat unavailable \u2014 keeping the flagship");let s=g(t.answers);if(t.mode!=="active")return n(`shadow \u2014 would ${s<(e.threshold??h)?"downgrade":"keep"} (${s.toFixed(2)})`,s);let a=e.threshold??h;return s>=a?n(`needs the flagship (${s.toFixed(2)})`,s):{model:e.cheapModel,downgraded:!0,needsFlagship:s,reason:`mechanical task (${s.toFixed(2)} below ${a}) \u2192 ${e.cheapModel}`}}export{F as a,M as b};
2
- //# sourceMappingURL=chunk-GK7XAM3D.js.map
1
+ import{v as l,w}from"./chunk-2DBGOCCW.js";import{a as i,f as p}from"./chunk-F4HZTZHW.js";w();p();var d="task-tier";function u(e){return{task:f(e.message,2e3),agent:e.agent,channel:e.channel??null,continuesExistingSession:e.isFollowUp??!1,...e.toolsAvailable?{toolsAvailable:e.toolsAvailable}:{}}}var c={needsFlagship:i("This task needs the strongest available model to be done correctly.",{true:"Doing it well takes real reasoning: writing or reviewing code, diagnosing a failure, planning work across several steps, weighing a judgement, handling money, touching production or anything irreversible, following a long or ambiguous instruction, or work where being subtly wrong would not be noticed. Anything where a weaker model would produce something that LOOKS right belongs here.",false:"It is mechanical and its result is obvious on sight: acknowledging or confirming a message, restating or formatting something already written, a greeting, a status echo, reading one file and reporting what it says, a lookup with one right answer, a scheduled heartbeat with nothing to decide."})};function g(e){return e.needsFlagship.noul}function f(e,n){return e.length>n?`${e.slice(0,n)}\u2026`:e}var h=.2,m=60*60*1e3;function F(e,n){if(e==="claude-code"){let t=n?.cheapModels?.[e]??n?.cheapModel;return t&&/^(claude-|haiku$|sonnet$|opus$)/.test(t)?t:void 0}if(e==="codex-cli"){let t=n?.cheapModels?.[e];return t&&/^(gpt-|o\d)/.test(t)?t:void 0}}async function M(e){let n=(o,r=null)=>({downgraded:!1,needsFlagship:r,reason:o});if(e.channel==="voice"||e.channel==="desktop"||e.channel==="opencode")return n(`${e.channel} requests retain the configured model`);if(!e.cheapModel)return n("no cheaper model configured");if(e.isFollowUp){let o=e.sessionIdleMs??0,r=e.cacheTtlMs??m;if(o<r)return n(`follow-up on a warm cache (idle ${Math.round(o/1e3)}s) \u2014 swapping would cost more than it saves`)}let t;try{t=await l(d,u(e),c,{incumbent:{needsFlagship:1},features:{agent:e.agent,channel:e.channel??"unknown"}})}catch{return n("routing seat threw \u2014 keeping the flagship")}if(!t)return n("routing seat unavailable \u2014 keeping the flagship");let s=g(t.answers);if(t.mode!=="active")return n(`shadow \u2014 would ${s<(e.threshold??h)?"downgrade":"keep"} (${s.toFixed(2)})`,s);let a=e.threshold??h;return s>=a?n(`needs the flagship (${s.toFixed(2)})`,s):{model:e.cheapModel,downgraded:!0,needsFlagship:s,reason:`mechanical task (${s.toFixed(2)} below ${a}) \u2192 ${e.cheapModel}`}}export{F as a,M as b};
2
+ //# sourceMappingURL=chunk-W3YGESNK.js.map