comments.py

clew/mcp_server/comments.py

Wiki comments: what a person writes on a served page, kept for the agent (2.1, owner Q/A).

_events

list[dict[str, Any]] clew.mcp_server.comments.CommentStore._events(self)

The log's events, in order; an unreadable line is skipped.

clew/mcp_server/comments.py:165

Show on the map →

Called by all

Calls none

Source · 12 lines
    def _events(self) -> list[dict[str, Any]]:
        """@brief Events. @return List."""
        if not self.path.is_file():
            return []
        events = []
        for line in self.path.read_text(encoding="utf-8").splitlines():
            try:
                events.append(json.loads(line))
            except json.JSONDecodeError:
                continue
        return events
Activity · 9 steps
lines 167–167◇ if not self.path.is_file()lines 168–168return []lines 169–169events = []lines 170–170◇ for line in self.path.read_text(encoding="utf-8").splitlines()lines 171–171trylines 172–172events.append(json.loads(line))lines 173–173except json.JSONDecodeErrorlines 174–174continuelines 175–175return events

Flows

_public

dict[str, Any] clew.mcp_server.comments._public(dict[str, Any] event)

A stored event's public fields.

clew/mcp_server/comments.py:220

Show on the map →

Called by add, all

Calls none

Source · 3 lines
def _public(event: dict[str, Any]) -> dict[str, Any]:
    """@brief Public fields. @return Dict."""
    return {k: event[k] for k in ("id", "at", "page", "anchor", "quote", "body")}

1 more lines, not shown

Activity · 1 steps
lines 222–222return {k: event[k] for k in ("id", "at", "page", "anchor", "quote", "body")}

Flows

add

dict[str, Any] clew.mcp_server.comments.CommentStore.add(self, str page, str anchor, str quote, str body)

Record a comment.

clew/mcp_server/comments.py:95

Show on the map →

Called by none

Calls _append, _check, _public, _write_pending

Source · 21 lines
    def add(self, page: str, anchor: str, quote: str, body: str) -> dict[str, Any]:
        """REFUSED, NEVER CUT: an empty body or a field over its limit raises ValueError naming it.

        @brief Add a comment.
        @return The comment.
        """
        _check(body, page, anchor, quote)
        record = {
            "op": "add",
            "id": secrets.token_hex(6),
            "at": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
            "page": page,
            "anchor": anchor,
            "quote": quote,
            "body": body,
        }
        with _LOCK:
            self._append(record)
            self._write_pending()
        return {**_public(record), "status": "new"}
Activity · 6 steps
lines 101–101_check(body, page, anchor, quote)lines 102–110record = { "op": "add", "id": secrets.token_hex(6), "at": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"), "page": page, "anchor": anchor, "quote": quote, "body": body, }lines 111–111with _LOCKlines 112–112self._append(record)lines 113–113self._write_pending()lines 114–114return {**_public(record), "status": "new"}

Requirements

REQ-DDB-WIKI-054

all

list[dict[str, Any]] clew.mcp_server.comments.CommentStore.all(self)

Every comment, oldest first, with its status.

clew/mcp_server/comments.py:132

Show on the map →

Called by _accepted, _apply, _bounded_output, _checked_blocking, _checked_list_section, _class_side_is_only_enum_mirrors, _comment_fields, _comments, _components, _derives_from_py_enum, _edge_defaults, _insert_recovered_macro

15 more_is_flat_req_list, _joined, _one_class, _prepare, _receiver_module, _recover_class_fields_into, _recover_into, _sbom, _string_list, _strings, _tier, flowchart_section, read_key_list, reconcile, unread

Tested by

61 teststest_a_bare_term_finds_the_files_containing_it, test_a_call_to_an_overridden_endpoint_is_annotated_with_its_implementors, test_a_comment_is_pushed_as_a_channel_notification, test_a_config_symbols_own_gates_carry_the_resolved_default, test_a_declared_root_outside_the_repository_is_refused, test_a_measured_link_carries_its_extent, test_a_non_virtual_function_gets_no_override_fields, test_a_real_build_records_a_breakdown_covering_every_stage, test_a_runtime_is_enabled_branch_is_not_a_gate, test_a_session_ignoring_the_index_is_escalated, test_a_step_brief_is_plain_text_and_the_home_card_counts_every_flow, test_a_steps_dialog_carries_its_recorded_values
49 moretest_an_ambiguous_call_without_a_selector_behaves_as_before, test_an_audience_can_redact_owners, test_an_index_without_the_relation_degrades_to_empty, test_an_oversized_reply_compacts_the_message_but_keeps_the_axis, test_c_binding_edge_is_resolved_and_never_exact, test_callees_merge_dataflow_tagged_as_key_not_call, test_chain_trace_records_what_the_fanout_taper_dropped, test_clew_documents_itself_with_its_own_wiki, test_dossier_does_not_double_report_dataflow, test_dot_flows_are_balanced_digraphs, test_each_assertion_is_a_diamond_failing_into_its_mode, test_each_file_is_one_slice_of_its_block, test_every_block_is_a_wedge_and_wedges_do_not_overlap, test_every_test_s_slice_of_a_flow_comes_from_one_pass_over_its_steps, test_extracting_items_that_match_no_member_is_refused, test_flows_past_the_cap_open_in_a_details, test_grading_appends_a_pass_history, test_harvested_sites_carry_provenance, test_inherited_members_do_not_pair_the_interface_with_itself, test_lens_facts_ride_on_components_and_absent_sources_stay_absent, test_list_files_pattern_is_a_glob_over_path_or_filename, test_mermaid_flows_are_sequence_diagrams, test_n_dossiers_share_the_budget_instead_of_each_claiming_it, test_neighbours_past_the_cap_open_in_a_details, test_no_successor_has_appeared_for_roots_on_the_modern_revisions, test_out_of_line_constructor, test_python_binding_edge_is_resolved_and_never_exact, test_python_definitions_are_recovered_with_class_qualification, test_python_self_qualified_call_is_member_provenance, test_query_surface_invariants_hold_on_real_data, test_registration_site_is_harvested_but_is_not_itself_a_call_edge, test_requirement_traceability_state_is_known, test_search_prose_returns_a_snippet, test_set_scoring_counts_members_and_precision, test_submodules_and_clones_both_become_sub_indexes, test_test_code_is_a_lens_not_a_box, test_test_files_and_common_keys_are_left_out, test_text_escalates_and_never_repeats, test_the_chain_loses_its_outermost_ring_before_a_neighbour_list_is_trimmed, test_the_dossier_names_the_callees_the_index_cannot_resolve, test_the_five_strength_vocabularies_are_distinct_objects, test_the_override_fields_reach_the_mcp_wire, test_the_payload_keeps_the_shape_the_folder_reads, test_the_prose_corpus_returns_snippets, test_the_site_has_an_architecture_tab, test_the_view_strip_has_every_view_in_order, test_udm_default_is_unresolved_not_absent, test_vote_records_the_reason_each_attempt_failed, test_with_nothing_declared_blocks_are_packages

Calls _events, _events, _public, list

Source · 10 lines
    def all(self) -> list[dict[str, Any]]:
        """@brief All comments. @return List."""
        comments: dict[str, dict[str, Any]] = {}
        for event in self._events():
            if event.get("op") == "add":
                comments[event["id"]] = {**_public(event), "status": "new"}
            elif event.get("op") == "read" and event.get("id") in comments:
                comments[event["id"]]["status"] = "read"
        return list(comments.values())
Activity · 7 steps
lines 134–134comments: dict[str, dict[str, Any]] = {}lines 135–135◇ for event in self._events()lines 136–136◇ if event.get("op") == "add"lines 137–137comments[event["id"]] = {**_public(event), "status": "new"}lines 138–138◇ elif event.get("op") == "read" and event.get("id") in commentslines 139–139comments[event["id"]]["status"] = "read"lines 140–140return list(comments.values())

Requirements

REQ-DDB-WIKI-054

Flows

for_repo

CommentStore clew.mcp_server.comments.CommentStore.for_repo(cls, Path state_root, str repo_path, bool counted=True)

The store for one repository.

clew/mcp_server/comments.py:81

Show on the map →

Called by none

Calls pending_key

Source · 6 lines
    def for_repo(cls, state_root: Path, repo_path: str, counted: bool = True) -> CommentStore:
        """@brief Locate a repository's store. @return Store."""
        key = pending_key(repo_path)
        root = Path(state_root)
        return cls(root / LOG_DIR / f"{key}.jsonl", root / PENDING_DIR / key, counted)
Activity · 3 steps
lines 83–83key = pending_key(repo_path)lines 84–84root = Path(state_root)lines 85–85return cls(root / LOG_DIR / f"{key}.jsonl", root / PENDING_DIR / key, counted)

Requirements

REQ-DDB-WIKI-054

mark_read

None clew.mcp_server.comments.CommentStore.mark_read(self, list[str] ids)

Mark comments read (they stay in the log).

clew/mcp_server/comments.py:121

Show on the map →

Called by none

Calls _append, _write_pending

Source · 7 lines
    def mark_read(self, ids: list[str]) -> None:
        """@brief Mark read. @return None."""
        with _LOCK:
            for cid in ids:
                self._append({"op": "read", "id": cid})
            self._write_pending()
Activity · 4 steps
lines 123–123with _LOCKlines 124–124◇ for cid in idslines 125–125self._append({"op": "read", "id": cid})lines 126–126self._write_pending()

Requirements

REQ-DDB-WIKI-054

pending_key

str clew.mcp_server.comments.pending_key(str repo_path)

The pending-count file's name for a repository: a hash of its resolved path.

clew/mcp_server/comments.py:51

Source · 10 lines
def pending_key(repo_path: str) -> str:
    """THE HOOK COMPUTES THIS TOO, from `CLAUDE_PROJECT_DIR` (`clew_hook._comment_key`), so both
    resolve the path the same way; a test pins that the two agree.

    @brief Pending key.
    @return Key.
    """
    return hashlib.sha256(os.path.realpath(repo_path).encode("utf-8")).hexdigest()[:16]

Activity · 1 steps
lines 58–58return hashlib.sha256(os.path.realpath(repo_path).encode("utf-8")).hexdigest()[:16]

Requirements

REQ-DDB-WIKI-054

unread

list[dict[str, Any]] clew.mcp_server.comments.CommentStore.unread(self)

The comments not yet read, oldest first.

clew/mcp_server/comments.py:146

Show on the map →

Called by _write_pending

Calls all

Source · 4 lines
    def unread(self) -> list[dict[str, Any]]:
        """@brief Unread comments. @return List."""
        return [c for c in self.all() if c["status"] == "new"]
Activity · 1 steps
lines 148–148return [c for c in self.all() if c["status"] == "new"]

Requirements

REQ-DDB-WIKI-054