Skip to content

Introduce a run context for the enrichment pipeline's runJob #146

Description

@cursor

Spec: Fowler-style refactoring review (cloud agent, 2026-08-05). Refactor only — no behavior change.

What to change

In lib/enrichment/process.ts:

  1. runJob takes 18 positional parameters (~426–445) and runs ~300 lines. Introduce a parameter object (e.g. EnrichmentRunContext holding repository, gateway, blob store, transcriber, place resolver, search, memory repository, projects/proposals/rejected names, thread repository, push, artifacts, embeddings) built once per processPendingEnrichments call.
  2. Dependency wiring — the ~50 lines of options.x ?? getX(environment) at the top of processPendingEnrichments (~792–835) become an extracted resolveEnrichmentDeps(options).
  3. The needs_attention result mapping is copy-pasted 4× in runJob (failed job ~446–453, thread missing ~470–477, capability refusal ~518–525, catch-all ~718–725). Extract attentionResults(targetCaptureIds, threadId, reason, retryable).
  4. The nested ternary computing idempotencyKey in queueJobsForThreads (~295–301) becomes a named enrichmentJobKey(...) decision function.
  5. Extract the memory-tool construction (~544–577) and the project matching/propose block (~620–645) into named functions.

Out of scope: the enrichment repositories (separate ticket); any change to job semantics, idempotency-key values, or retry policy.

Acceptance criteria

  • runJob receives one context object plus the job; no function in the file takes more than ~5 parameters
  • The four needs_attention blocks share one helper; idempotency keys are produced by one named function with unchanged values
  • mise run lint passes; tests/enrichment-*.spec.ts pass unchanged

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions