DEV Community

啦啦啦种太阳
啦啦啦种太阳

Posted on Originally published at dsh-plugin.com

Cordis services and injection: how DeepSeek Harness orders plugin activation

Most "how do I extend this thing" questions about DeepSeek Harness turn out to be a question about services. A plugin does not reach into some central object and switch behaviour on; it provides a capability under a stable name, or it asks for one by name and waits. Once you can tell a service definition from its provider from the code that consumes it, activation order stops being something you guess and starts being something the framework computes for you.

This is a walk through that model using the Cordis primer and the architecture reference. It is about composition and lifecycle — not a claim that any particular plugin, or the data it handles, is safe to load.

A service definition, provider and consumer connected by a context

Three roles that get blurred together

The primer describes a plugin as a function with optional inject and apply(ctx) fields, or as a Service subclass mounted into a context. A service claims a stable key — ctx.tools, ctx.llm, ctx.sessions — and consumers find the capability through that key instead of importing a concrete class.

Role Responsibility The question it answers
Definition Establish the interface What contract must an implementation satisfy?
Provider Implement the service Which composition supplies it?
Consumer Use the capability Which service does it require?
Context Resolve scoped services and offer framework APIs Which implementation is visible here?

The architecture reference frames a swappable capability as a seam: a definition, a provider that implements it, and a consumer that is often a model-facing tool. One package can play more than one role. What does not follow is that a definition alone produces a working implementation, or that a consumer creates the thing it uses. Those are separate facts and they fail separately.

inject is how activation gets ordered

A plugin declares the services it needs through inject, and Cordis holds that plugin until those services exist. That is the whole mechanism, and it is worth being precise about what it buys you: it removes the need to predict a global startup sequence for every plugin in the tree.

What it does not do is install anything. Declaring a dependency on a service never pulls in a provider package, and a service name present in one context is not evidence that the same name resolves to the same implementation somewhere else. When a consumer sits forever without activating, the missing service is the thing to look for — not a missing package install.

Configuration expressions have their own timing. The primer notes that an entry's config is interpolated after declared injections activate, evaluated against the plugin's context, while the disabled expression is evaluated at each mount decision against the loader context, and other entry metadata stays literal. If a configuration expression reads a service, both the declared dependency and the context it evaluates in are part of the design.

When activation fails, a waiting consumer is often downstream of the provider error rather than the cause of it. Startup diagnostics is about collecting exactly that evidence: a pending entry on its own does not tell you which provider is at fault.

Adding or replacing a capability

  1. Identify the capability and its existing service definition. Read the methods and event contracts before picking an extension point.
  2. Find the provider in the composition you actually run, and the consumers using the key. Check whether any package combines roles.
  3. Declare what the consumer needs and obtain the capability through the context, keeping behaviour tied to the documented interface rather than one implementation's quirks.
  4. Register the provider or consumer in the intended composition and scope. The architecture describes provider swaps through service seams; visibility still depends on context.
  5. Test activation and a representative operation. On replacement or unload, confirm registrations were withdrawn and no stale behaviour survived.

The two seams are easy to confuse. ctx.llm is the model adapter seam; ctx.tools is the scoped tool registry. Registering an adapter on the first is a different act from registering a model-facing capability on the second. And because a swap changes behaviour for every consumer that resolves that service, it has to be judged against the shared contract, not against one caller's happy path.

Events, effects, and why unload is the hard part

Services are for direct capability calls. Events are the extension points for observation, interception and policy, and the primer lists emit, waterfall, parallel, serial and bail as distinct dispatch shapes. The mode belongs to the event's contract.

The one that catches people is waterfall. A listener receives next and delegates with next(); returning without calling it short-circuits everything downstream. An observer that forgets to delegate has silently changed behaviour instead of observing it.

Registrations — listeners, tool schemas, adapters, prompt sections — are reversible effects. ctx.effect() and helpers such as ctx.on() dispose them with the owning instance, and where teardown order matters the primer recommends keeping related work inside one effect so it unwinds in the intended order. Reload and teardown should remove the old registrations. A provider that starts cleanly but leaves its old listeners behind after replacement is not a finished integration.

These properties are independent. A correctly injected service does not guarantee a listener delegates correctly, and correct disposal does not establish that a replacement provider behaves like the one it replaced. Test them one at a time.

Scope is a container, not a promise

A context is a scoped service container. The Context reference documents child contexts created by extend, isolate and intercept without mutating the parent; isolate gives a named service an independent scope. A service present in one scope is not proof that a consumer elsewhere resolves the same implementation — Context capabilities goes through those distinctions.

None of this is a trust boundary. Injection does not install missing packages, does not validate external systems, and does not vouch for the implementation behind a key. An activated plugin can still fail when its actual operation runs. Review the code and configuration appropriate to your deployment.

Comparing a replacement honestly

Run the same representative consumer operation before and after the swap. Registration proves the provider appeared; the operation checks the interface behaviour the consumer depends on. Then unload it and confirm its effects are gone. Keep each result separate rather than reading one clean activation as evidence that the whole integration is correct.

The terms worth keeping straight

  • Plugin — a unit mounted by Cordis, possibly acting in several roles.
  • Service definition — the interface for a capability.
  • Provider — an implementation made available under a context key.
  • Consumer — a plugin or component that uses the capability.
  • Injection — a declaration that coordinates access to required services.
  • Effect — a registration with cleanup tied to its lifecycle.

If you are starting from nothing, the companion pieces are the plugin tree overview, which covers how profiles and bundles assemble the tree these services live in, and the first plugin tutorial for the local loop.

Originally published at https://dsh-plugin.com/blog/cordis-plugins-services-dependency-injection

Top comments (0)