Skip to content

Code Metrics

Generated: 2026-09-29 07:10 UTC


Lines of Code

Files Code Comment Blank Total
Source (src/terok/) 150 35 129 6 411 2 515 44 055
Tests (tests/) 203 47 944 4 064 4 058 56 066
Combined 353 83 073 10 475 6 573 100 121
  • Comment/code ratio: 18%
  • Test/source ratio: 136.5%
Source by module (click to expand)
Module Files Code Comment Blank
terok/ 150 35 129 6 411 2 515
terok/cli/ 23 5 382 953 449
terok/cli/commands/ 19 4 931 777 388
terok/cli/commands/_completers.py — 72 23 20
terok/cli/commands/_desktop_entry.py — 341 78 15
terok/cli/commands/_storage_view.py — 183 38 57
terok/cli/commands/acp.py — 303 76 13
terok/cli/commands/agents.py — 157 29 31
terok/cli/commands/auth.py — 184 39 3
terok/cli/commands/clearance.py — 14 10 10
terok/cli/commands/completions.py — 115 13 20
terok/cli/commands/image.py — 257 12 15
terok/cli/commands/info.py — 418 62 15
terok/cli/commands/panic.py — 86 22 2
terok/cli/commands/project.py — 460 38 47
terok/cli/commands/setup.py — 416 59 15
terok/cli/commands/shield.py — 243 49 28
terok/cli/commands/sickbay.py — 760 99 31
terok/cli/commands/task.py — 626 69 58
terok/cli/commands/uninstall.py — 148 22 3
terok/cli/commands/vault_change.py — 148 31 4
terok/cli/__init__.py — 2 3 3
terok/cli/__main__.py — 3 3 3
terok/cli/main.py — 346 129 49
terok/cli/tree.py — 100 41 6
terok/lib/ 81 15 074 3 180 1 162
terok/lib/api/ 10 1 523 290 49
terok/lib/api/__init__.py — 555 88 9
terok/lib/api/agents.py — 145 8 1
terok/lib/api/clearance.py — 43 20 10
terok/lib/api/gate.py — 61 38 1
terok/lib/api/project.py — 116 29 10
terok/lib/api/setup.py — 85 53 1
terok/lib/api/shield.py — 78 12 2
terok/lib/api/ssh_routing.py — 156 6 3
terok/lib/api/task.py — 124 24 10
terok/lib/api/vault.py — 160 12 2
terok/lib/core/ 14 2 911 609 315
terok/lib/core/config.py — 668 176 64
terok/lib/core/egress_sets.py — 112 14 6
terok/lib/core/images.py — 82 29 22
terok/lib/core/paths.py — 123 64 32
terok/lib/core/project_model.py — 221 48 12
terok/lib/core/projects.py — 560 46 30
terok/lib/core/runtime.py — 94 19 5
terok/lib/core/setup.py — 54 2 1
terok/lib/core/task_display.py — 53 27 29
terok/lib/core/task_state.py — 57 42 29
terok/lib/core/version.py — 212 39 22
terok/lib/core/work_status.py — 136 38 20
terok/lib/core/yaml_schema.py — 539 62 42
terok/lib/domain/ 17 4 037 882 328
terok/lib/domain/wizards/ 2 778 102 48
terok/lib/domain/wizards/new_project.py — 778 99 47
terok/lib/domain/auth.py — 287 76 20
terok/lib/domain/image_cleanup.py — 159 54 24
terok/lib/domain/log_format.py — 218 67 53
terok/lib/domain/panic.py — 336 43 13
terok/lib/domain/project.py — 775 184 32
terok/lib/domain/project_state.py — 234 36 34
terok/lib/domain/review_lag.py — 176 45 22
terok/lib/domain/ssh.py — 13 23 1
terok/lib/domain/storage.py — 223 64 23
terok/lib/domain/task.py — 176 56 16
terok/lib/domain/task_credentials.py — 146 20 6
terok/lib/domain/task_logs.py — 209 24 12
terok/lib/domain/vault.py — 30 37 9
terok/lib/domain/vault_rekey.py — 277 48 15
terok/lib/integrations/ 5 471 247 7
terok/lib/integrations/__init__.py — 8 11 2
terok/lib/integrations/clearance.py — 45 31 1
terok/lib/integrations/executor.py — 118 66 1
terok/lib/integrations/sandbox.py — 239 128 2
terok/lib/integrations/shield.py — 61 11 1
terok/lib/orchestration/ 23 5 595 887 362
terok/lib/orchestration/task_runners/ 8 1 895 258 82
terok/lib/orchestration/task_runners/__init__.py — 24 26 3
terok/lib/orchestration/task_runners/cli.py — 111 49 2
terok/lib/orchestration/task_runners/config.py — 62 22 18
terok/lib/orchestration/task_runners/container.py — 434 29 17
terok/lib/orchestration/task_runners/headless.py — 436 25 14
terok/lib/orchestration/task_runners/restart.py — 350 44 22
terok/lib/orchestration/task_runners/shield.py — 246 11 4
terok/lib/orchestration/task_runners/toad.py — 232 52 2
terok/lib/orchestration/tasks/ 7 1 625 307 111
terok/lib/orchestration/tasks/__init__.py — 105 31 3
terok/lib/orchestration/tasks/archive.py — 84 13 9
terok/lib/orchestration/tasks/identity.py — 101 33 14
terok/lib/orchestration/tasks/lifecycle.py — 649 83 31
terok/lib/orchestration/tasks/meta.py — 266 59 15
terok/lib/orchestration/tasks/naming.py — 47 31 22
terok/lib/orchestration/tasks/query.py — 373 57 17
terok/lib/orchestration/agent_config.py — 36 27 13
terok/lib/orchestration/container_doctor.py — 955 60 23
terok/lib/orchestration/container_exec.py — 63 20 9
terok/lib/orchestration/environment.py — 518 104 47
terok/lib/orchestration/hooks.py — 135 34 18
terok/lib/orchestration/image.py — 363 60 53
terok/lib/orchestration/ports.py — 5 14 6
terok/lib/util/ 11 537 257 100
terok/lib/util/ansi.py — 46 28 19
terok/lib/util/check_reporter.py — 165 47 20
terok/lib/util/emoji.py — 85 30 17
terok/lib/util/fs.py — 34 38 7
terok/lib/util/host_cmd.py — 32 26 9
terok/lib/util/logging_utils.py — 67 19 2
terok/lib/util/net.py — 11 16 7
terok/lib/util/output_capture.py — 60 33 15
terok/lib/util/subprocess_env.py — 31 6 1
terok/lib/util/yaml.py — 6 11 2
terok/resources/ 2 90 18 5
terok/resources/desktop/ 2 90 18 5
terok/tui/ 40 14 473 2 216 877
terok/tui/widgets/ 9 1 095 180 109
terok/tui/widgets/__init__.py — 30 13 3
terok/tui/widgets/ansi_log.py — 46 6 2
terok/tui/widgets/panic_button.py — 57 16 16
terok/tui/widgets/project_list.py — 90 23 14
terok/tui/widgets/project_state.py — 249 32 34
terok/tui/widgets/routing_matrix.py — 217 21 3
terok/tui/widgets/status_bar.py — 21 14 6
terok/tui/widgets/task_detail.py — 226 37 21
terok/tui/widgets/task_list.py — 159 18 10
terok/tui/__init__.py — 2 3 3
terok/tui/__main__.py — 3 3 3
terok/tui/_worker_entry.py — 72 6 4
terok/tui/agents_screen.py — 193 28 12
terok/tui/app.py — 2 381 384 106
terok/tui/askpass.py — 71 18 4
terok/tui/askpass_protocol.py — 61 34 19
terok/tui/askpass_service.py — 308 56 6
terok/tui/clearance_screen.py — 345 61 14
terok/tui/clipboard.py — 136 49 30
terok/tui/console_log.py — 293 63 13
terok/tui/console_output_screen.py — 106 16 10
terok/tui/gpu_screen.py — 244 18 7
terok/tui/key_routing_screen.py — 532 50 3
terok/tui/log_viewer.py — 498 46 4
terok/tui/polling.py — 438 121 72
terok/tui/project_actions.py — 1 128 186 39
terok/tui/screens.py — 2 785 321 188
terok/tui/selinux_fix_screen.py — 126 20 4
terok/tui/serve.py — 324 51 41
terok/tui/setup_screen.py — 137 50 11
terok/tui/shell_launch.py — 160 64 24
terok/tui/shield_sets_screen.py — 167 4 8
terok/tui/ssh_key_screens.py — 63 23 14
terok/tui/task_actions.py — 891 75 19
terok/tui/task_watcher.py — 139 15 5
terok/tui/text_screens.py — 112 20 20
terok/tui/tmux_session.py — 224 22 12
terok/tui/wizard_screens.py — 958 173 52
terok/tui/worker_actions.py — 337 35 8
terok/tui/worker_log_screen.py — 144 21 13
terok/ui_utils/ 3 88 32 17
terok/ui_utils/editor.py — 53 2 1
terok/ui_utils/terminal.py — 35 27 15
terok/__init__.py — 22 12 5

Architecture

Layer Overview

graph LR
    core["core (23 modules)"]
    domain["domain (25 modules)"]
    integrations["integrations (4 modules)"]
    orchestration["orchestration (9 modules)"]
    presentation["presentation (2 modules)"]
    core --> ?
    core -->|2 deps| integrations
    domain --> ?
    domain -->|44 deps| core
    domain -->|10 deps| integrations
    domain -->|17 deps| orchestration
    orchestration --> ?
    orchestration -->|40 deps| core
    orchestration -->|4 deps| integrations
    presentation --> ?
    presentation -->|15 deps| core
    presentation -->|22 deps| domain
    presentation -->|4 deps| orchestration

Module Dependency Graph

graph TD
    terok.cli -->|9| terok.lib.api
    terok.cli -->|5| terok.lib.core
    terok.cli -->|3| terok.lib.domain
    terok.cli -->|4| terok.lib.orchestration
    terok.cli -->|3| terok.lib.util
    terok.cli --> terok.ui_utils.terminal
    terok.lib.api -->|9| terok.lib.core
    terok.lib.api -->|14| terok.lib.domain
    terok.lib.api -->|9| terok.lib.integrations
    terok.lib.api -->|4| terok.lib.orchestration
    terok.lib.core --> terok
    terok.lib.core -->|2| terok.lib.integrations
    terok.lib.core -->|5| terok.lib.util
    terok.lib.domain -->|30| terok.lib.core
    terok.lib.domain --> terok.lib.integrations
    terok.lib.domain -->|13| terok.lib.orchestration
    terok.lib.domain -->|5| terok.lib.util
    terok.lib.domain --> terok.ui_utils.editor
    terok.lib.orchestration -->|26| terok.lib.core
    terok.lib.orchestration -->|4| terok.lib.integrations
    terok.lib.orchestration -->|15| terok.lib.util
    terok.lib.util -->|2| terok.lib.core
    terok.tui -->|10| terok.lib.api
    terok.tui --> terok.lib.core
    terok.tui -->|5| terok.lib.util
    terok.tui --> terok.ui_utils.terminal
    terok.ui_utils.terminal --> terok.lib.util

Module Boundaries

63 modules, 227 dependency edges — all boundaries validated.

Module Summary

63 modules across 5 layers (click to expand)
Module Layer Deps Description
terok.cli presentation 25 CLI frontend
terok.tui presentation 17 should extend api first; extending this allowlist is a design smell.
terok.lib.domain.panic domain 5 Emergency panic (cross-project lockdown)
terok.lib.domain.ssh domain 3 SSH provisioning workflow — mint, bind, render, pause for deploy-key registration.
terok.lib.domain.auth domain 3 Host-wide and project-scoped auth flow.
terok.lib.api domain 11 helpers that don't fit into a single sub-module.
terok.lib.api.vault domain 3
terok.lib.domain.vault_rekey domain 4 Rekey pre-flight — running-task round trip + credentials-DB holder scan.
terok.lib.api.ssh_routing domain 3
terok.lib.api.gate domain 3
terok.lib.api.shield domain 2
terok.lib.api.agents domain 5
terok.lib.api.clearance domain 1
terok.lib.api.setup domain 2
terok.lib.api.task domain 6
terok.lib.api.project domain 8
terok.lib.domain.vault domain 1 Vault access primitive (shared open/close handshake)
terok.lib.domain.task_credentials domain 2 translation that the sandbox itself doesn't model.
terok.lib.domain.review_lag domain 5 Rich domain object: Project (Aggregate Root)
terok.lib.domain.project domain 14
terok.lib.domain.task domain 5 Rich domain object: Task (Entity)
terok.lib.domain.task_logs domain 5 Task log viewing and streaming
terok.lib.domain.log_format domain 1 Agent log formatters (Claude stream-json, plain text)
terok.lib.domain.image_cleanup domain 2 Image listing & cleanup
terok.lib.domain.storage domain 4 Storage usage aggregation across package stack
terok.lib.orchestration.agent_config orchestration 2 Agent config resolution (terok-specific stack composition)
terok.lib.domain.project_state domain 7 Project infrastructure state (queries podman & filesystem)
terok.lib.domain.wizards.new_project domain 3 Interactive project creation
terok.lib.orchestration.task_runners orchestration 17 toad / headless / restart submodules behind a re-export init.
terok.lib.orchestration.tasks orchestration 18 init.
terok.lib.orchestration.environment orchestration 5 Task environment & volume mounts
terok.lib.orchestration.image orchestration 5 Dockerfile generation & image building
terok.lib.orchestration.ports orchestration 0 Task port allocation (delegates to terok-sandbox port registry)
terok.lib.orchestration.hooks orchestration 1 Task lifecycle hooks (host-side)
terok.lib.orchestration.container_exec orchestration 3 Container-based command execution (sandboxed git via podman exec)
terok.lib.orchestration.container_doctor orchestration 5 In-container health checks (layered doctor protocol via podman exec)
terok core 0 Top-level package (version metadata only)
terok.lib.core.version core 2 Version info
terok.lib.core.paths core 0 Path resolution (FHS/XDG)
terok.lib.core.config core 3 Configuration management
terok.lib.core.project_model core 0 Project data models (pure types, no I/O)
terok.lib.core.egress_sets core 1 Curated egress allowlist sets (shield t40 default content)
terok.lib.core.yaml_schema core 0 Raw YAML schema models (Pydantic validation, no I/O)
terok.lib.core.projects core 5 Project discovery and loading
terok.lib.core.images core 1 Image naming conventions
terok.lib.core.runtime core 1 Process-wide ContainerRuntime accessor
terok.lib.core.task_state core 1 Task lifecycle state — domain value object, status computation, container naming
terok.lib.core.task_display core 0 Presentation tables for task lifecycle, mode, and project badges
terok.lib.core.work_status core 1 Agent work status reading
terok.ui_utils.terminal core 1 Terminal ANSI formatting
terok.ui_utils.editor core 0 $EDITOR launching
terok.lib.util.fs core 0 Archive directory and filename helpers (timestamp + collision-free names)
terok.lib.util.ansi core 0 ANSI color utilities
terok.lib.util.logging_utils core 1 Debug logging stub
terok.lib.util.output_capture core 1 Tee build/run output to journald or a bespoke log file
terok.lib.util.emoji core 0 Emoji display-width utilities
terok.lib.util.yaml core 0 Centralised YAML I/O (round-trip via ruamel.yaml)
terok.lib.util.host_cmd core 0 Host-side subprocess safety guards
terok.lib.integrations.executor integrations 0
terok.lib.integrations.sandbox integrations 0
terok.lib.integrations.clearance integrations 0
terok.lib.integrations.shield integrations 0
terok.lib.core.setup core 3

Test Coverage

Overall line coverage: 83.5% (13475/16136 statements).

Each rectangle is a source file. Area is proportional to the number of statements; colour encodes the coverage percentage (green = fully covered, red = uncovered). Files are grouped by the first 3 directory levels.

Cognitive Complexity

Threshold: 15 (functions above this are listed below)

  • Functions analyzed: 1628
  • Median complexity: 1.0 · Average: 2.5 · Max: 79
  • Within threshold (15): 98% (1599/1628)
    0–  3 │ ██████████████████████████████ 1259 (77.3%)
    4–  6 │ █████                          190 (11.7%)
    7–  9 │ ██                              91 ( 5.6%)
   10– 12 │ █                               41 ( 2.5%)
   13– 15 │                                 18 ( 1.1%) ◄ threshold
   16– 18 │                                  8 ( 0.5%)
   19– 21 │                                 10 ( 0.6%)
   22– 25 │                                  2 ( 0.1%)
   26+    │                                  9 ( 0.6%)

29 functions exceeding threshold:

Complexity Function File
79 render_project_details src/terok/tui/widgets/project_state.py
43 task_logs src/terok/lib/domain/task_logs.py
43 LogViewerScreen::_stream_logs src/terok/tui/log_viewer.py
38 cmd_overview src/terok/cli/commands/_storage_view.py
35 render_task_details src/terok/tui/widgets/task_detail.py
30 main src/terok/cli/main.py
29 ClaudeStreamJsonFormatter::_handle_user src/terok/lib/domain/log_format.py
29 _TuiLogFormatter::_handle_user src/terok/tui/log_viewer.py
26 _dispatch_task_sub src/terok/cli/commands/task.py
24 _clear_rekey_blockers src/terok/cli/commands/vault_change.py
24 get_project_state src/terok/lib/domain/project_state.py
21 cmd_detail src/terok/cli/commands/_storage_view.py
21 dispatch src/terok/cli/commands/shield.py
21 get_version_info src/terok/lib/core/version.py
21 collect_wizard_inputs src/terok/lib/domain/wizards/new_project.py
21 task_list src/terok/lib/orchestration/tasks/query.py
21 PollingMixin::_sync_worker src/terok/tui/polling.py
20 is_completion_installed src/terok/cli/commands/completions.py
20 task_status src/terok/lib/orchestration/tasks/lifecycle.py
19 _format_type src/terok/cli/commands/info.py
19 summarize_gate_sync src/terok/lib/domain/project.py
18 validate_answer src/terok/lib/domain/wizards/new_project.py
17 _cmd_sickbay src/terok/cli/commands/sickbay.py
17 _parent_process_has_name src/terok/tui/shell_launch.py
16 _add_field src/terok/cli/commands/info.py
16 _cmd_project_delete src/terok/cli/commands/project.py
16 _check_unfired_hooks src/terok/cli/commands/sickbay.py
16 get_storage_overview src/terok/lib/domain/storage.py
16 _gate_token_check src/terok/lib/orchestration/container_doctor.py

Dead Code Analysis

Confidence Location Issue
100% confidence src/terok/lib/domain/task_logs.py:151 unused variable 'signum'

Docstring Coverage

  • Needed: 7; Found: 6; Missing: 1; Coverage: 85.7%
  • Needed: 7; Found: 5; Missing: 2; Coverage: 71.4%
  • Needed: 22; Found: 21; Missing: 1; Coverage: 95.5%
  • Needed: 56; Found: 55; Missing: 1; Coverage: 98.2%
  • Needed: 35; Found: 34; Missing: 1; Coverage: 97.1%
  • Needed: 21; Found: 19; Missing: 2; Coverage: 90.5%
  • Needed: 16; Found: 13; Missing: 3; Coverage: 81.2%
  • Needed: 13; Found: 8; Missing: 5; Coverage: 61.5%
  • Needed: 108; Found: 106; Missing: 2; Coverage: 98.1%
  • Needed: 21; Found: 20; Missing: 1; Coverage: 95.2%
  • Needed: 23; Found: 22; Missing: 1; Coverage: 95.7%
  • Needed: 15; Found: 10; Missing: 5; Coverage: 66.7%
  • Needed: 33; Found: 30; Missing: 3; Coverage: 90.9%
  • Needed: 67; Found: 53; Missing: 14; Coverage: 79.1%
  • Needed: 221; Found: 220; Missing: 1; Coverage: 99.5%
  • Needed: 19; Found: 17; Missing: 2; Coverage: 89.5%
  • Needed: 10; Found: 7; Missing: 3; Coverage: 70.0%
  • Needed: 72; Found: 60; Missing: 12; Coverage: 83.3%
  • Needed: 23; Found: 21; Missing: 2; Coverage: 91.3%
  • Needed: 54; Found: 39; Missing: 15; Coverage: 72.2%
  • Needed: 2099 - Found: 2022 - Missing: 77
  • Total coverage: 96.3% - Grade: Excellent

Generated by scc, complexipy, vulture, tach, and docstr-coverage.