Skip to content

Reduce duplication across TasksApi / useTasksApi / TasksPanel handler maps #798

Closed

Description

@blinkagent

Problem

Every time a new request, command, or notification is added to the Tasks IPC layer, it must be manually defined in three places:

  1. packages/shared/src/tasks/api.ts — canonical defineRequest/defineCommand/defineNotification + TasksApi object
  2. packages/tasks/src/hooks/useTasksApi.ts — webview-side wrapper that re-lists every entry as a convenience method
  3. src/webviews/tasks/tasksPanel.ts — extension-side requestHandlers / commandHandlers maps that re-list every entry by method name

Nothing enforces that these three stay in sync. Forgetting to wire up a new method in one of them is a silent bug — the TypeScript compiler won't catch it.

Desired outcome

  • A single source of truth (TasksApi) should drive the handler/hook shape so the compiler errors when a method is missing.
  • Ideally, useTasksApi and the TasksPanel handler maps could be partially or fully generated/inferred from the TasksApi definition (e.g. mapped types, helper that iterates over TasksApi entries, or codegen).
  • Adding a new request/command/notification should require touching as few files as possible — ideally just the definition and the implementation.

Ideas

  • Use mapped types over typeof TasksApi to derive the required handler signatures, making requestHandlers / commandHandlers type-incomplete if a handler is missing.
  • Generate useTasksApi from TasksApi entries automatically (the hook is already a thin request()/command() pass-through).
  • Explore a registry pattern or codegen script that reads the TasksApi object and emits boilerplate.

Created on behalf of @EhabY

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions