Skip to content

Code Metrics

Generated: 2026-11-17 14:29 UTC


Lines of Code

Files Code Comment Blank Total
Source (src/terok/) 157 43 089 6 944 2 625 52 658
Tests (tests/) 225 61 307 4 252 4 447 70 006
Combined 382 104 396 11 196 7 072 122 664
  • Comment/code ratio: 16%
  • Test/source ratio: 142.3%
Source by module (click to expand)
Module Files Code Comment Blank
terok/ 157 43 089 6 944 2 625
terok/cli/ 23 6 191 929 424
terok/cli/commands/ 19 5 736 750 362
terok/cli/commands/_completers.py — 72 23 20
terok/cli/commands/_desktop_entry.py — 341 78 15
terok/cli/commands/_storage_view.py — 248 28 38
terok/cli/commands/acp.py — 303 76 13
terok/cli/commands/agents.py — 157 29 31
terok/cli/commands/auth.py — 213 10 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 — 58 21 2
terok/cli/commands/project.py — 460 38 47
terok/cli/commands/setup.py — 462 66 16
terok/cli/commands/shield.py — 781 30 9
terok/cli/commands/sickbay.py — 878 121 39
terok/cli/commands/task.py — 663 72 61
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 — 350 132 50
terok/cli/tree.py — 100 41 6
terok/lib/ 84 19 060 3 578 1 253
terok/lib/api/ 10 1 810 273 41
terok/lib/api/__init__.py — 604 85 9
terok/lib/api/agents.py — 159 8 1
terok/lib/api/clearance.py — 119 6 1
terok/lib/api/gate.py — 61 38 1
terok/lib/api/project.py — 138 29 10
terok/lib/api/setup.py — 85 53 1
terok/lib/api/shield.py — 203 12 3
terok/lib/api/ssh_routing.py — 156 6 3
terok/lib/api/task.py — 122 24 10
terok/lib/api/vault.py — 163 12 2
terok/lib/core/ 16 4 149 733 351
terok/lib/core/config.py — 700 218 82
terok/lib/core/config_reference.py — 106 14 2
terok/lib/core/egress_sets.py — 443 64 16
terok/lib/core/images.py — 82 29 22
terok/lib/core/instructions.py — 112 17 4
terok/lib/core/paths.py — 123 64 32
terok/lib/core/project_model.py — 285 17 13
terok/lib/core/projects.py — 1 045 79 29
terok/lib/core/runtime.py — 108 18 5
terok/lib/core/setup.py — 60 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 — 131 36 21
terok/lib/core/yaml_schema.py — 632 64 43
terok/lib/domain/ 19 5 680 944 308
terok/lib/domain/wizards/ 2 799 104 48
terok/lib/domain/wizards/new_project.py — 799 101 47
terok/lib/domain/auth.py — 287 76 20
terok/lib/domain/clearance.py — 284 49 13
terok/lib/domain/egress_promotion.py — 1 206 111 11
terok/lib/domain/image_cleanup.py — 159 54 24
terok/lib/domain/log_format.py — 322 28 16
terok/lib/domain/panic.py — 242 20 17
terok/lib/domain/project.py — 775 184 32
terok/lib/domain/project_state.py — 234 36 34
terok/lib/domain/review_lag.py — 190 37 19
terok/lib/domain/ssh.py — 13 23 1
terok/lib/domain/storage.py — 334 36 12
terok/lib/domain/task.py — 171 53 19
terok/lib/domain/task_credentials.py — 146 20 6
terok/lib/domain/task_logs.py — 211 25 12
terok/lib/domain/vault.py — 30 37 9
terok/lib/domain/vault_rekey.py — 277 48 15
terok/lib/integrations/ 5 602 264 9
terok/lib/integrations/__init__.py — 8 11 2
terok/lib/integrations/clearance.py — 85 9 2
terok/lib/integrations/executor.py — 132 73 1
terok/lib/integrations/sandbox.py — 316 160 3
terok/lib/integrations/shield.py — 61 11 1
terok/lib/orchestration/ 22 5 817 990 416
terok/lib/orchestration/task_runners/ 8 2 111 307 117
terok/lib/orchestration/task_runners/__init__.py — 28 26 3
terok/lib/orchestration/task_runners/cli.py — 114 48 2
terok/lib/orchestration/task_runners/config.py — 62 22 18
terok/lib/orchestration/task_runners/container.py — 477 51 34
terok/lib/orchestration/task_runners/headless.py — 419 31 16
terok/lib/orchestration/task_runners/restart.py — 517 58 33
terok/lib/orchestration/task_runners/shield.py — 298 16 8
terok/lib/orchestration/task_runners/toad.py — 196 55 3
terok/lib/orchestration/tasks/ 7 1 631 307 114
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 — 652 83 31
terok/lib/orchestration/tasks/meta.py — 286 59 15
terok/lib/orchestration/tasks/naming.py — 47 31 22
terok/lib/orchestration/tasks/query.py — 356 57 20
terok/lib/orchestration/agent_config.py — 37 27 13
terok/lib/orchestration/container_doctor.py — 902 98 41
terok/lib/orchestration/environment.py — 633 143 54
terok/lib/orchestration/hooks.py — 135 34 18
terok/lib/orchestration/image.py — 363 57 53
terok/lib/orchestration/ports.py — 5 14 6
terok/lib/util/ 11 1 002 366 127
terok/lib/util/ansi.py — 46 28 19
terok/lib/util/check_reporter.py — 166 47 21
terok/lib/util/emoji.py — 85 30 17
terok/lib/util/fs.py — 34 38 7
terok/lib/util/host_cmd.py — 33 27 10
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 — 469 119 27
terok/resources/ 2 90 18 5
terok/resources/desktop/ 2 90 18 5
terok/tui/ 44 17 638 2 375 921
terok/tui/widgets/ 9 1 183 178 105
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 — 95 26 14
terok/tui/widgets/project_state.py — 260 35 33
terok/tui/widgets/routing_matrix.py — 217 21 3
terok/tui/widgets/status_bar.py — 21 14 6
terok/tui/widgets/task_detail.py — 300 29 18
terok/tui/widgets/task_list.py — 157 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 624 331 104
terok/tui/askpass.py — 103 20 4
terok/tui/askpass_protocol.py — 88 35 23
terok/tui/askpass_service.py — 379 45 26
terok/tui/clearance_screen.py — 424 66 16
terok/tui/clipboard.py — 136 49 30
terok/tui/console_log.py — 353 62 13
terok/tui/console_output_screen.py — 231 17 8
terok/tui/gpu_screen.py — 244 18 7
terok/tui/instructions_screen.py — 116 27 8
terok/tui/key_routing_screen.py — 506 49 3
terok/tui/log_viewer.py — 498 46 4
terok/tui/polling.py — 438 121 72
terok/tui/project_actions.py — 1 555 167 38
terok/tui/screens.py — 2 919 339 193
terok/tui/selinux_fix_screen.py — 126 20 4
terok/tui/serve.py — 324 51 41
terok/tui/setup_screen.py — 139 50 11
terok/tui/shell_launch.py — 160 64 24
terok/tui/shield_bypass_screen.py — 55 3 6
terok/tui/shield_harvest_screen.py — 614 56 4
terok/tui/shield_promote_screen.py — 578 88 16
terok/tui/shield_sets_screen.py — 200 43 18
terok/tui/ssh_key_screens.py — 63 23 14
terok/tui/task_actions.py — 1 040 81 25
terok/tui/task_watcher.py — 139 15 5
terok/tui/text_screens.py — 376 59 9
terok/tui/tmux_session.py — 222 30 16
terok/tui/wizard_screens.py — 1 027 122 30
terok/tui/worker_actions.py — 346 38 9
terok/tui/worker_log_screen.py — 162 22 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 (26 modules)"]
    domain["domain (27 modules)"]
    integrations["integrations (4 modules)"]
    orchestration["orchestration (8 modules)"]
    presentation["presentation (2 modules)"]
    core --> ?
    core -->|3 deps| integrations
    domain -->|56 deps| core
    domain -->|14 deps| integrations
    domain -->|22 deps| orchestration
    orchestration -->|39 deps| core
    orchestration -->|4 deps| integrations
    presentation -->|16 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 -->|11| terok.lib.core
    terok.lib.api -->|16| terok.lib.domain
    terok.lib.api -->|10| terok.lib.integrations
    terok.lib.api -->|5| terok.lib.orchestration
    terok.lib.core --> terok
    terok.lib.core -->|3| terok.lib.integrations
    terok.lib.core -->|7| terok.lib.util
    terok.lib.domain --> terok
    terok.lib.domain -->|37| terok.lib.core
    terok.lib.domain -->|4| terok.lib.integrations
    terok.lib.domain -->|17| terok.lib.orchestration
    terok.lib.domain -->|6| terok.lib.util
    terok.lib.domain --> terok.ui_utils.editor
    terok.lib.orchestration -->|25| terok.lib.core
    terok.lib.orchestration -->|4| terok.lib.integrations
    terok.lib.orchestration -->|14| 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

67 modules, 251 dependency edges — all boundaries validated.

Module Summary

67 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 12 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 4
terok.lib.domain.egress_promotion domain 7 the project, an egress set or a break-glass override; export for user groups.
terok.lib.api.agents domain 6
terok.lib.api.clearance domain 3
terok.lib.domain.clearance domain 7 A task's clearance prompts — hub addressing by the recorded short id, mute.
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 6 Storage usage aggregation across package stack
terok.lib.orchestration.agent_config orchestration 3 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 16 toad / headless / restart submodules behind a re-export init.
terok.lib.orchestration.tasks orchestration 17 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_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.instructions core 2 The global instructions file and what each instructions layer inherits
terok.lib.core.config_reference core 1 The config schema as Markdown, for the TUI's options reference
terok.lib.core.project_model core 0 Project data models (pure types, no I/O)
terok.lib.core.egress_sets core 3 Egress allowlist sets — built-in and the operator's own (shield t40 content a project opts into)
terok.lib.core.yaml_schema core 0 Raw YAML schema models (Pydantic validation, no I/O)
terok.lib.core.projects core 6 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.util.net core 0 URL helpers — host formatting, git remote hosts
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: 88.1% (17276/19614 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: 2139
  • Median complexity: 1 · Average: 2.6 · Max: 116
  • Within threshold (15): 99% (2107/2139)
    0–  3 │ ██████████████████████████████ 1626 (76.0%)
    4–  6 │ █████                          265 (12.4%)
    7–  9 │ ██                             133 ( 6.2%)
   10– 12 │ █                               58 ( 2.7%)
   13– 15 │                                 25 ( 1.2%) ◄ threshold
   16– 18 │                                  8 ( 0.4%)
   19– 21 │                                 10 ( 0.5%)
   22– 25 │                                  4 ( 0.2%)
   26+    │                                 10 ( 0.5%)

32 functions exceeding threshold:

Complexity Function File
116 TerokTUI::handle_worker_state_changed src/terok/tui/app.py
79 render_project_details src/terok/tui/widgets/project_state.py
48 render_task_details src/terok/tui/widgets/task_detail.py
43 task_logs src/terok/lib/domain/task_logs.py
43 LogViewerScreen::_stream_logs src/terok/tui/log_viewer.py
31 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
27 _dispatch_task_sub src/terok/cli/commands/task.py
27 TerokTUI::_clear_rekey_blockers src/terok/tui/app.py
24 _clear_rekey_blockers src/terok/cli/commands/vault_change.py
24 get_project_state src/terok/lib/domain/project_state.py
23 dispatch src/terok/cli/commands/shield.py
22 _export src/terok/lib/domain/egress_promotion.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
21 render_vault_status src/terok/tui/screens.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
19 ProjectActionsMixin::_edit_and_save src/terok/tui/project_actions.py
18 cmd_overview src/terok/cli/commands/_storage_view.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 _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:152 unused variable 'signum'

Docstring Coverage

  • Needed: 7; Found: 6; Missing: 1; Coverage: 85.7%
  • Needed: 7; Found: 5; Missing: 2; Coverage: 71.4%
  • Needed: 53; Found: 49; Missing: 4; Coverage: 92.5%
  • Needed: 56; Found: 55; Missing: 1; Coverage: 98.2%
  • Needed: 35; Found: 34; Missing: 1; Coverage: 97.1%
  • Needed: 25; Found: 23; Missing: 2; Coverage: 92.0%
  • Needed: 16; Found: 13; Missing: 3; Coverage: 81.2%
  • Needed: 13; Found: 8; Missing: 5; Coverage: 61.5%
  • Needed: 114; Found: 112; Missing: 2; Coverage: 98.2%
  • Needed: 32; Found: 31; Missing: 1; Coverage: 96.9%
  • Needed: 15; Found: 10; Missing: 5; Coverage: 66.7%
  • Needed: 33; Found: 30; Missing: 3; Coverage: 90.9%
  • Needed: 91; Found: 77; Missing: 14; Coverage: 84.6%
  • Needed: 230; Found: 229; Missing: 1; Coverage: 99.6%
  • Needed: 19; Found: 17; Missing: 2; Coverage: 89.5%
  • Needed: 12; Found: 10; Missing: 2; Coverage: 83.3%
  • Needed: 80; Found: 68; Missing: 12; Coverage: 85.0%
  • Needed: 23; Found: 21; Missing: 2; Coverage: 91.3%
  • Needed: 65; Found: 52; Missing: 13; Coverage: 80.0%
  • Needed: 2542 - Found: 2466 - Missing: 76
  • Total coverage: 97.0% - Grade: Excellent

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