feat(R08): split ScheduleTaskTab, FolderTab, DashboardTab, StructureGraphView

Team Hoa, EPIC R08 (UI/Application Separation) - Team Hoa scope only
(R08-T11 -> T14; R08-T01->T10 belong to Team Duy/Team Nam).

- R08-T11: ui/schedule_task_tab.py (795 lines) -> presentation/scheduling/
  {kanban_board_widget,calendar_view_widget,ai_task_creator_dialog,
  ai_task_import_dialog,run_history_dialog}.py + schedule_task_tab.py
  shell. Kanban CRUD/drag-drop now goes through
  application/scheduling/task_application_service.py (R07-T04) instead of
  ~30 lines of inline if/elif per drag target.
- R08-T12: ui/folder_tab.py (1587 lines, the largest of the four) ->
  presentation/folder/{workspace_file_tree,document_preview_manager,
  code_editor,office_document_renderer,ai_file_editor_dialog,
  ai_edit_model_resolver,ai_edit_pipeline}.py + folder_tab.py shell.
  Closes the R06-T05 loop: FileWorkspaceService existed since R06 with
  zero production call sites (confirmed by grep); every plain-text write
  (save/create/write_content) now goes through it, gaining path
  containment and a Python-syntax warning the original code never had.
  Pure helpers (_read_text, _is_probably_text, _pptx_available,
  _split_code_block, _parse_ai_output) moved to
  application/workspaces/{file_preview_helpers,ai_edit_output}.py.
- R08-T13: ui/dashboard_tab.py (437 lines) -> presentation/dashboard/
  {token_usage_card_widget,usage_chart_widget,habits_widget}.py +
  dashboard_tab.py shell, backed by a new
  application/monitoring/dashboard_query_service.py (pricing/period/
  summary queries the three widgets used to each recompute separately).
  Directory-ownership note left in the checklist for Team Nam.
- R08-T14: ui/structure_graph_view.py (1035 lines) ->
  presentation/graph/{graph_scene_items,graph_renderer,
  graph_messages_view,graph_qa_widget}.py + structure_graph_view.py
  shell. Extraction helpers (_pdf_to_markdown, _extract_file_contents)
  moved to application/workspaces/graph_index_service.py (pure Python).
  Renderer and Q&A panel talk only through signals
  (node_selected/graph_rendered/raw_json_ready/project_changed) - neither
  imports the other.
- presentation/shared/web_engine_support.py: HAS_WEB_ENGINE, previously
  duplicated (folder_tab imported it FROM structure_graph_view.py) - now
  one shared flag instead of one screen importing another screen's module.

All four old ui/*.py files deleted; app.py and ui/workspace_tab.py updated
to the new import paths (each god-file only had 1-2 real construction
sites, so import sites were updated directly rather than kept as a
strangler-fig shim - unlike core/tools.py at R05, which had dozens).

pytest: 377 pass (+94 vs the R07 baseline of 328; same 4 pre-existing
failures as the R05/R06 baseline, unrelated to this work).
scripts/check_imports.py: PASS. python -c "import cowork_local.app": OK.
Every new file < 400 lines (largest: graph_renderer.py, 391).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-27 20:55:32 +09:00
co-authored by Claude Sonnet 5
parent 69ab8e125b
commit 0e51356a7d
51 changed files with 5746 additions and 3877 deletions
+103
View File
@@ -0,0 +1,103 @@
"""EPIC R08-T13: DashboardQueryService — no Qt.
``core/usage_tracker.py::USAGE_DIR`` is a module-level constant (not
injectable per-call except through an explicit ``directory=`` kwarg
``load_events`` alone accepts) — this is a pre-existing testability gap the
original ``ui/dashboard_tab.py`` also had (it had zero tests before this
task). Monkeypatching the module attribute is what lets these tests write
usage events without touching the real ``~/.cowork_local/usage/``.
"""
from __future__ import annotations
import json
from datetime import date, timedelta
import pytest
from cowork_local.application.monitoring import DashboardQueryService
from cowork_local.config import AppConfig
from cowork_local.core import usage_tracker as ut
from cowork_local.state import AppContext
@pytest.fixture
def usage_dir(tmp_path, monkeypatch):
d = tmp_path / "usage"
monkeypatch.setattr(ut, "USAGE_DIR", d)
return d
@pytest.fixture
def ctx(tmp_path):
return AppContext(AppConfig.load(tmp_path / "config.json"))
def _write_event(usage_dir, day: date, **overrides):
usage_dir.mkdir(parents=True, exist_ok=True)
event = {
"ts": f"{day.isoformat()}T10:00:00", "source": "cowork", "label": "Test chat",
"provider": "anthropic", "model": "claude-sonnet-4-6",
"in": 100, "out": 50, "cache": 0, "estimated": False,
"account": "", "machine": "",
}
event.update(overrides)
path = usage_dir / f"{day.isoformat()}.jsonl"
with path.open("a", encoding="utf-8") as f:
f.write(json.dumps(event) + "\n")
def test_period_range_is_inclusive_end(usage_dir, ctx):
query = DashboardQueryService(ctx)
start, end = query.period_range("week", 0)
assert start <= end
def test_summary_aggregates_events_in_range(usage_dir, ctx):
today = date.today()
_write_event(usage_dir, today, **{"in": 100, "out": 50})
_write_event(usage_dir, today - timedelta(days=400), **{"in": 999, "out": 999}) # out of range
query = DashboardQueryService(ctx)
summary = query.summary(today, today)
assert len(summary["events"]) == 1
assert summary["stats"]["in"] == 100
assert summary["stats"]["out"] == 50
assert summary["total_cost"] >= 0
def test_summary_empty_range_has_no_events(usage_dir, ctx):
query = DashboardQueryService(ctx)
summary = query.summary(date(2020, 1, 1), date(2020, 1, 1))
assert summary["events"] == []
assert summary["stats"]["total"] == 0
def test_pricing_returns_a_dict_with_currency(usage_dir, ctx):
query = DashboardQueryService(ctx)
pricing = query.pricing()
assert "currency" in pricing
def test_chart_series_returns_points_for_the_granularity(usage_dir, ctx):
today = date.today()
_write_event(usage_dir, today)
query = DashboardQueryService(ctx)
pts = query.chart_series("week", 0, "tokens")
assert len(pts) == 7 # week view = 7 days
assert all(isinstance(p, tuple) and len(p) == 2 for p in pts)
def test_budget_status_none_when_no_budget_set(usage_dir, ctx):
query = DashboardQueryService(ctx)
assert query.budget_status() is None
def test_set_budget_then_status_reflects_it(usage_dir, ctx):
query = DashboardQueryService(ctx)
query.set_budget(100.0, "USD")
status = query.budget_status()
assert status is not None
assert status["amount_usd"] == pytest.approx(100.0)
@@ -0,0 +1,76 @@
"""EPIC R08-T12: pure helpers moved out of ui/folder_tab.py into
application/workspaces/ (file_preview_helpers.py, ai_edit_output.py) — no Qt,
directly unit-testable, unlike when they lived as private module functions
inside the Qt widget file.
"""
from __future__ import annotations
from cowork_local.application.workspaces.ai_edit_output import (
parse_ai_output,
split_code_block,
)
from cowork_local.application.workspaces.file_preview_helpers import (
is_probably_text,
read_text,
)
def test_read_text_returns_file_contents(tmp_path):
f = tmp_path / "a.txt"
f.write_text("hello", encoding="utf-8")
assert read_text(str(f)) == "hello"
def test_read_text_on_missing_file_returns_a_note_not_raise(tmp_path):
result = read_text(str(tmp_path / "missing.txt"))
assert "could not read file" in result
def test_is_probably_text_true_for_utf8(tmp_path):
f = tmp_path / "a.txt"
f.write_text("hello world", encoding="utf-8")
assert is_probably_text(str(f)) is True
def test_is_probably_text_false_for_null_bytes(tmp_path):
f = tmp_path / "a.bin"
f.write_bytes(b"\x00\x01\x02")
assert is_probably_text(str(f)) is False
def test_split_code_block_extracts_fenced_block_and_summary():
text = "Here is the change:\n\n```python\nprint('hi')\n```"
content, summary = split_code_block(text)
assert content == "print('hi')\n"
assert summary == "Here is the change:"
def test_split_code_block_no_fence_returns_none_and_full_text():
content, summary = split_code_block("just prose, no code")
assert content is None
assert summary == "just prose, no code"
def test_parse_ai_output_extracts_file_target():
text = "FILE: new/thing.py\n```python\nx = 1\n```"
target, content, summary, image_gens = parse_ai_output(text)
assert target == "new/thing.py"
assert content == "x = 1\n"
assert image_gens == []
def test_parse_ai_output_extracts_image_gen_directives():
text = ("Adding an illustration.\n"
"IMAGE_GEN: a red fox in a forest => assets/fox.png\n"
"```html\n<img src='assets/fox.png'>\n```")
target, content, summary, image_gens = parse_ai_output(text)
assert image_gens == [("a red fox in a forest", "assets/fox.png")]
assert "IMAGE_GEN" not in summary
def test_parse_ai_output_no_directives_or_code_block():
target, content, summary, image_gens = parse_ai_output("just an answer")
assert target is None
assert content is None
assert image_gens == []
assert summary == "just an answer"
+44
View File
@@ -0,0 +1,44 @@
"""EPIC R08-T14: graph_index_service.py — pure helpers moved out of
ui/structure_graph_view.py, no Qt.
"""
from __future__ import annotations
from cowork_local.application.workspaces.graph_index_service import extract_file_contents
def test_extract_file_contents_reads_text_files(tmp_path):
f = tmp_path / "a.py"
f.write_text("print('hello')\n", encoding="utf-8")
block, cache = extract_file_contents([str(f)], {}, str(tmp_path))
assert "print('hello')" in block
assert str(f) in cache
assert cache[str(f)]
def test_extract_file_contents_reuses_the_cache(tmp_path):
f = tmp_path / "a.txt"
f.write_text("original", encoding="utf-8")
seed_cache = {str(f): "cached content, not re-read"}
block, cache = extract_file_contents([str(f)], seed_cache, str(tmp_path))
assert "cached content, not re-read" in block
def test_extract_file_contents_skips_unreadable_paths_without_raising(tmp_path):
missing = tmp_path / "does-not-exist.txt"
block, cache = extract_file_contents([str(missing)], {}, str(tmp_path))
assert block == ""
def test_extract_file_contents_respects_max_total_budget(tmp_path):
f1 = tmp_path / "a.txt"
f1.write_text("x" * 100, encoding="utf-8")
f2 = tmp_path / "b.txt"
f2.write_text("y" * 100, encoding="utf-8")
block, cache = extract_file_contents([str(f1), str(f2)], {}, str(tmp_path), max_total=50)
assert len(block) < 250 # bounded, not both files in full