Blog /

Engineering notes

Make capability dependencies explicit

Resolve declared capability IDs before dispatching application code.

DevCodex Labs2 min read
On this page
  1. Give a capability a stable identity
  2. Resolve a local declaration
  3. Review the result before acting
  4. Sources

Give a capability a stable identity

A short tool name can be shared by unrelated providers. A providerId::capabilityId lets a caller select a declared capability. Pin the provider version with its definition in the load configuration.

Resolve a local declaration

Install @devcodex/capability-graph@2.2.0 with Node.js 20.19+ in the 20.x line or Node.js 22.12+. Save the declaration as provider.json and the ESM script as resolve.mjs in the same directory, then run node resolve.mjs. The known ID selects the report view directly without a model.

{"providerId":"reports","name":"Reports","version":"1.0.0","capabilities":[{"id":"schema","name":"Report schema","description":"Fields in a report"},{"id":"view","name":"View report","description":"Open a report","relations":{"requires":["schema"]}}]}
import { CapabilityGraph } from '@devcodex/capability-graph';
import { fileURLToPath } from 'node:url';

const file = fileURLToPath(new URL('./provider.json', import.meta.url));
const graph = await CapabilityGraph.open({ providers: [{ file }] });
try {
  const result = await graph.resolve({ ids: ['reports::view'] });
  console.log({
    completeness: result.meta.completeness,
    nodes: result.nodes.map(({ capability, origin, applicability }) => ({
      id: capability.id, origin, applicability: applicability.status,
    })),
    edges: result.edges,
    unresolved: result.unresolved,
  });
} finally {
  await graph.close();
}

Review the result before acting

The local 2.2.0 run returned complete, with reports::view marked selected and reports::schema marked dependency. The edge was reports::view → reports::schema with type requires, and unresolved was empty.

Change the view's requires array to ["shared::schema"] and run again with only the reports provider. The local run returned partial, kept the selected view and reported an unresolved edge to shared::schema with reason target_unavailable. Hold dispatch until the required provider is available and the dependency resolves.

When declarations have applicability conditions, pass verified business facts as context. If a required node's applicability is unknown, obtain the missing facts before dispatch. The host checks authorization and uses the edges to plan dependency order. The result's node list is sorted by ID.

Sources

Related work