Skip to content

refactor(runtime): retire bespoke config, JSON, payload, and path helpers #614

Closed

Description

@Sinity

Scope

Composite issue for compacting runtime/support code by retiring small bespoke frameworks, using already-declared dependencies where appropriate, and deleting surface-naming ceremony.

Problem

Several parts of Polylogue duplicate functionality already available from dependencies or from nearby shared abstractions:

  • pydantic-settings is declared but config/env handling is handwritten in dataclasses and direct os.environ reads;
  • XDG/platform path resolution is hand-rolled instead of using a standard platform path helper;
  • JSON serialization has a canonical wrapper, but strict typed boundaries still use forgiving recursive guards in places where Pydantic/TypeAdapter should fail loudly;
  • MCP payload modules re-alias shared surface payloads under MCP-prefixed names without adding behavior;
  • HTML code highlighting regexes generated Markdown HTML instead of using markdown-it renderer rules;
  • path/token sanitization policy is spread across display paths, source-root materialization, browser tokens, blob hashes, and semantic referenced paths;
  • some runtime dependencies are declared but not used.

Already completed

Remaining

  1. Config: Either consume pydantic-settings through a typed settings adapter or remove it from dependencies. Current polylogue/config.py uses dataclass config and direct env reads; no imports of pydantic_settings/BaseSettings exist in the codebase.
  2. Platform paths: Either adopt platformdirs for config/data/cache/state roots, or document why the local XDG helper in polylogue/paths/_roots.py is deliberately retained.
  3. JSON boundary policy: Direct stdlib json is allowed only for explicitly allowlisted compatibility cases. Machine output, proof evidence, manifests, browser capture, and schemas go through typed/canonical boundaries. Many direct json.dump(s)/json.load(s) call sites still exist.
  4. MCP payload aliases: Delete MCP-prefixed aliases around shared surface payload models (polylogue/mcp/payloads.py:47-51). MCP modules should contain only real MCP-specific wrappers/helpers.
  5. Markdown highlighting: Use markdown-it token renderer rules, not regex post-processing over generated HTML.
  6. Path/token policies: Named by trust boundary — display path, source-root materialization, filename token, blob hash, referenced path, browser token. See fix(semantic): preserve parser drift, action paths, and source paths #623.
  7. Unused dependencies: glom is declared in pyproject.toml:43-46 but has no imports in the codebase. Either adopt it to delete local extraction code, or remove with evidence.

Policy

  • Prefer third-party wheels and existing typed boundaries.
  • Do not collapse distinct boundary policies into one generic helper.
  • No import shims or compatibility aliases for moved helpers.
  • products terminology → insights when touching derived read-model helpers or registries.

Consolidated findings

This issue absorbs and supersedes:

Related but kept separate:

Ref #578
Ref #635

Activity

  1. changed the title [-]refactor(deps): use or remove unused glom dependency[/-] [+]refactor(deps): use or remove unused runtime dependencies[/+] on May 1, 2026
  2. added
    type:refactor
    on May 1, 2026
  3. changed the title [-]refactor(deps): use or remove unused runtime dependencies[/-] [+]refactor(runtime): retire bespoke config, JSON, payload, and path helpers[/+] on May 1, 2026
  4. added
    area:core
    on May 1, 2026
  5. Sinity commented on May 1, 2026

    @Sinity
    OwnerAuthor

    Compactness guard: this should prefer third-party wheels and existing typed boundaries, but not collapse distinct boundary policies into one helper layer.

    Suggested classification per candidate:

    • config/env: use pydantic-settings or a typed settings model where runtime configuration is the contract; direct os.environ reads should become rare and owned;
    • platform paths: use a standard path provider if it can express the XDG/source-checkout split cleanly;
    • JSON: strict TypeAdapter/Pydantic at typed boundaries, forgiving decode only where raw-ingest quarantine semantics explicitly require it;
    • MCP payload aliases: delete aliases that add no behavior, but keep distinct DTOs when they are real wire contracts and prove conversion parity;
    • path/token sanitization: split display redaction, source-root trust, browser token handling, blob IDs, and semantic referenced paths before centralizing;
    • declared-but-unused dependencies such as glom: either adopt them to delete local extraction code, or remove them with evidence.

    The success metric should be fewer policies and less local parsing code, not a new helpers.py that every subsystem depends on.

  6. Sinity commented on May 1, 2026

    @Sinity
    OwnerAuthor

    Implementation anchors and acceptance additions from the 2026-05-01 follow-up audit.

    Code/dependency anchors:

    • pyproject.toml:43-46: declared runtime dependencies include pydantic-settings and glom.
    • Repository scan: no imports of pydantic_settings/BaseSettings; no imports of platformdirs; no imports of glom outside packaging metadata.
    • polylogue/config.py:29-151: dataclass config and direct env reads.
    • polylogue/paths/_roots.py:9-33: hand-rolled XDG fallback.
    • polylogue/lib/json.py: central JSON wrapper exists, but there are many direct json.dump(s)/json.load(s) call sites across polylogue and devtools.
    • polylogue/mcp/payloads.py:47-51: MCP-prefixed aliases around shared surface payload models.

    Acceptance additions:

    • Either consume pydantic-settings through a typed settings adapter or remove it from dependencies.
    • Either adopt platformdirs for config/data/cache/state roots or document why the local XDG helper is deliberately retained.
    • Add a JSON-boundary policy: direct stdlib json is allowed only for explicitly allowlisted compatibility cases; machine output, proof evidence, manifests, browser capture, and schemas go through typed/canonical boundaries.
    • Path policy names are trust-boundary-specific: display path, source-root materialization, filename token, blob hash, referenced path, browser token.
  7. Sinity commented on May 1, 2026

    @Sinity
    OwnerAuthor

    Compactness/package-boundary integration from 2026-05-01 bundle

    The downloaded decision bundle reinforces the compactness direction here, but also clarifies the alias policy:

    Already-covered compactness work from the naming stream should not be reopened here: JSON, hashing, time, security, payload coercion, outcome grammar, and metrics have moved to polylogue.core in #659-#665.

    Remaining compactness slices still owned here include settings/platform paths, MCP payload alias removal, markdown renderer-rule highlighting, path policy naming, and declared-but-unused dependency decisions.

    Ref #635

  8. Sinity commented on May 2, 2026

    @Sinity
    OwnerAuthor

    Current targets for the "bespoke helpers" retirement

    Based on the issue title's scope:

    Config: polylogue/config.py — runtime config/XDG resolution. Check if it's using custom path construction that platformdirs already covers.

    JSON: polylogue/lib/json.py was referenced but polylogue/lib/ no longer exists. The JSON helpers likely moved to polylogue/core/ or polylogue/archive/. Find the current module:

    rg "def (dumps|loads)" polylogue/ --include="*.py" -l | grep -i json

    It wraps orjson with Decimal → float conversion. If this is the only caller, consider whether orjson.dumps with a custom default is simpler than a dedicated wrapper.

    Payload helpers: check polylogue/archive/raw_payload.py — payload type detection/normalization. These may duplicate what the schema/property-test infrastructure already covers.

    Path helpers: check polylogue/sources/source.py and polylogue/archive/attachment.py — path resolution and sanitization. The attachment path sanitization ordering issue from #623 may surface path helpers that can be unified.

    Approach

    Grep for each category, list every function, check whether a standard library or upstream dependency already does the same thing. Delete if yes, narrow the contract if no.

  9. Sinity commented on May 3, 2026

    @Sinity
    OwnerAuthor

    All three acceptance criteria are already satisfied in the current codebase:

    • pydantic-settings: zero imports found (already removed)
    • platformdirs: zero imports found (already removed)
    • MCP payload aliases: already canonical imports from polylogue.surfaces.payloads, no deprecated re-export aliases

    The remaining items from the original scope (JSON boundary policy, markdown highlighting, path/token policies) are tracked in #623 and #723 respectively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:corearea:docstype:refactor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions