Skip to content

refactor(appkit): introduce ServiceManager for core service lifecycle#374

Open
ditadi wants to merge 1 commit into
mainfrom
stack/taskflow/service-registry
Open

refactor(appkit): introduce ServiceManager for core service lifecycle#374
ditadi wants to merge 1 commit into
mainfrom
stack/taskflow/service-registry

Conversation

@ditadi
Copy link
Copy Markdown
Contributor

@ditadi ditadi commented May 11, 2026

🥞 Stacked PR

Use this link to review incremental changes.


AppKit's core previously ran a hardcoded boot sequence for cache + telemetry. This refactor introduces a generic service container so the core no longer names concrete services in its bootstrap path:

  • ServiceManager — holds booted core services, resolves them by name via get<T>(name), and stops them in reverse start order. add(name, null) is a no-op so callers can pass opt-out results directly.
  • startCoreServices(config) — builds the ServiceManager AppKit ships with; lives next to the concrete service modules so core/appkit.ts stays free of concrete-class imports.

Cache and Telemetry expose a static boot(config) returning { instance, stop } | null. Telemetry returns null when no OTLP endpoint is configured (preserves the existing opt-out semantics).

Plugins receive a typed services locator through attachContext. The shape is inlined in BasePlugin so the shared package does not gain a new exported interface. Plugins resolve services via services.get<MyService>("my-service") when the base class doesn't surface them as properties.

Groundwork only — no behaviour change, no public-API removal. The goal is to make room for a third core service (TaskFlow) without re-threading the cross-package attachContext contract: adding a new service touches only the service module and startCoreServices. TaskFlow itself is intentionally NOT in this PR.

Verified: `pnpm -r typecheck`, `pnpm build`, full vitest run (123 files, 2261 tests) all green.

Signed-off-by: ditadi victordperd@gmail.com

AppKit's core previously ran a hardcoded boot sequence for cache +
telemetry. This refactor introduces a generic service container so
the core no longer names concrete services in its bootstrap path:

- `ServiceManager` — container that holds booted core services,
  resolves them by name via `get<T>(name)`, and stops them in reverse
  start order. `add(name, null)` is a no-op so callers can pass
  opt-out results directly.
- `startCoreServices(config)` — builds the ServiceManager AppKit ships
  with; lives next to the concrete service modules so `core/appkit.ts`
  stays free of concrete-class imports.

Cache and Telemetry expose a `static boot(config)` returning
`{ instance, stop } | null`. Telemetry returns `null` when no OTLP
endpoint is configured (preserves the existing opt-out semantics).

Plugins receive a typed `services` locator through `attachContext`;
the shape is inlined in `BasePlugin` so the shared package does not
gain a new exported interface. New plugins resolve services via
`services.get<MyService>("my-service")` when the base class doesn't
surface them as properties.

Groundwork only — no behaviour change, no public-API removal. The
goal is to make room for a third core service (TaskFlow) without
re-threading the cross-package `attachContext` contract: adding a
new service touches only the service module and `startCoreServices`.
TaskFlow itself is intentionally NOT in this PR.

Verified: pnpm -r typecheck, pnpm build, full vitest run
(123 files, 2261 tests) all green.

Signed-off-by: ditadi <victordperd@gmail.com>
@ditadi ditadi force-pushed the stack/taskflow/service-registry branch from 6efbe15 to a8b7010 Compare May 12, 2026 15:46
@ditadi ditadi changed the title refactor(appkit): introduce CoreServiceRegistry and ServiceLocator refactor(appkit): introduce ServiceManager for core service lifecycle May 12, 2026
@ditadi ditadi marked this pull request as ready for review May 12, 2026 16:31
@ditadi ditadi requested a review from a team as a code owner May 12, 2026 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant