ktx/packages/cli/test
Andrey Avtomonov 21744fc520
feat(cli): profile ingest runs and split model vs tool time (#249)
* feat(cli): profile ingest runs to find where wall-clock time goes

Add opt-in profiling for `ktx ingest`. Each timed phase, work unit, and
agent loop now records durationMs / step count / token usage in the
trace, and a post-run aggregator rolls them up into a "where did the
time go" report printed to stderr.

Enable per run with KTX_PROFILE_INGEST (1/true -> human table, json ->
raw structured profile) or persistently via `ingest.profile` in
ktx.yaml. The json form emits raw milliseconds, token counts, and a
summary.headline one-line diagnosis so coding agents can parse it
directly; json wins when both env and config request profiling.

- runtime-port: RunLoopMetrics (totalMs, usage, stepCount,
  stepBoundariesMs) plus onMetrics callbacks on text/object generation
- ai-sdk + claude-code runtimes: capture per-loop timing and token usage
- work-unit-executor and stages 3/4: thread metrics into trace events
- ingest-bundle.runner: time worktree / triage / clustering / index /
  reconcile / squash phases and emit the profile in a finally block
  (best-effort; never affects the run outcome)
- ingest-profile: new trace+transcript aggregator with table/json formatters
- config: ingest.profile flag; docs: profiling section in ktx-ingest.mdx

* fix(cli): flush tool-call logs before reading ingest profile

Tool transcripts are appended fire-and-forget so the agent hot path never
blocks on logging. The ingest profiler read them before the writes settled,
so per-work-unit toolMs (and the model-vs-tool split derived from it) could
be incomplete. Track in-flight appends and expose flushToolCallLogs() —
bounded by a timeout so it can never hang — and flush before the profiler
reads the transcript.
2026-06-01 15:49:17 +02:00
..
commands feat(cli): shell completion for commands, flags, and entity names (#244) 2026-05-31 23:44:33 +02:00
completion feat(cli): shell completion for commands, flags, and entity names (#244) 2026-05-31 23:44:33 +02:00
connectors test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
context feat(cli): profile ingest runs and split model vs tool time (#249) 2026-06-01 15:49:17 +02:00
fixtures test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
io test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
llm test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
telemetry feat(cli): profile ingest runs and split model vs tool time (#249) 2026-06-01 15:49:17 +02:00
admin-reindex.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
admin.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
cli-program-telemetry.test.ts feat(cli): shell completion for commands, flags, and entity names (#244) 2026-05-31 23:44:33 +02:00
cli-program.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
command-tree.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
connection.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
context-build-view.test.ts feat(cli)!: remove fast mode; ktx ingest always builds enriched context (KLO-721) (#237) 2026-05-29 17:41:04 +02:00
database-tree-picker.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
demo-assets.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
demo-metrics.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
doctor.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
embedding-resolution.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
example-smoke.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
index.test.ts feat(cli): shell completion for commands, flags, and entity names (#244) 2026-05-31 23:44:33 +02:00
ingest-query-executor.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
ingest-report-file.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
ingest-viz.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
ingest.test-utils.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
ingest.test.ts fix(cli): treat artifact-producing ingests with failures as partial (#238) 2026-05-30 00:42:59 +02:00
knowledge.test.ts feat(cli): shell completion for commands, flags, and entity names (#244) 2026-05-31 23:44:33 +02:00
local-adapters.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
local-scan-connectors.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
managed-local-embeddings.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
managed-mcp-daemon.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
managed-python-command.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
managed-python-daemon.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
managed-python-http.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
managed-python-runtime.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
mcp-http-server.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
mcp-server-factory.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
memory-flow-interactive.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
memory-flow-tui.test.tsx test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
next-steps.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
notion-page-picker.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
print-command-tree.test.ts feat(cli): shell completion for commands, flags, and entity names (#244) 2026-05-31 23:44:33 +02:00
project-dir.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
project-resolver.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
prompt-navigation.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
proxy-env.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
public-ingest-copy.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
public-ingest.test.ts feat(cli)!: remove fast mode; ktx ingest always builds enriched context (KLO-721) (#237) 2026-05-29 17:41:04 +02:00
runtime-requirements.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
runtime.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
scan.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
setup-agents.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
setup-context.test.ts feat(cli)!: remove fast mode; ktx ingest always builds enriched context (KLO-721) (#237) 2026-05-29 17:41:04 +02:00
setup-databases.test.ts feat(cli)!: remove fast mode; ktx ingest always builds enriched context (KLO-721) (#237) 2026-05-29 17:41:04 +02:00
setup-demo-tour.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
setup-embeddings.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
setup-interrupt.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
setup-models.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
setup-project.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
setup-prompts.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
setup-ready-menu.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
setup-runtime.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
setup-secrets.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
setup-sources-notion.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
setup-sources.test.ts fix(cli): align Notion setup credential to --source-auth-token-ref (#236) 2026-05-29 17:23:46 +02:00
setup.test.ts fix(cli): treat artifact-producing ingests with failures as partial (#238) 2026-05-30 00:42:59 +02:00
sl.test.ts feat(cli): shell completion for commands, flags, and entity names (#244) 2026-05-31 23:44:33 +02:00
source-mapping.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
sql.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
standalone-smoke.test.ts feat(cli)!: remove fast mode; ktx ingest always builds enriched context (KLO-721) (#237) 2026-05-29 17:41:04 +02:00
status-project.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
text-ingest.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
tree-picker-state.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
tree-picker-tui.test.tsx test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00
viz-fallback.test.ts test: split cli tests from source tree (#216) 2026-05-26 08:49:05 +02:00