For AI agents: the complete documentation index is available at https://devcodex-labs.github.io/capability-graph/llms.txt, the full documentation bundle is available at https://devcodex-labs.github.io/capability-graph/llms-full.txt, and this page is available as Markdown at https://devcodex-labs.github.io/capability-graph/guides/lifecycle-and-reload.md.

管理生命周期与重新加载

可用

生命周期

  1. CapabilityGraph.open() 固定来源根并完整校验初始视图。
  2. 查询持有当前视图的读取引用。
  3. 作者更新定义后显式 reload({ providerId })
  4. 新候选完整通过才成为 current;旧 current 成为 previous。
  5. close() 停止接受新查询并回收 Core 拥有的视图句柄。
import { CapabilityGraph } from '@devcodex/capability-graph';

// Configuration fragment: replace the path with the provider from the tutorial.
const config = {
  hostAllowedProviders: ['acme.http'],
  integrationEnabledProviders: ['acme.http'],
  providers: [{ providerId: 'acme.http',
    authority: { kind: 'file' as const, rootDir: '/absolute/path/to/acme-provider' } }]
};
const graph = await CapabilityGraph.open(config);
try {
  const reloaded = await graph.reload({ providerId: 'acme.http' });
  console.log(reloaded.ok, reloaded.providers);
} finally {
  await graph.close();
}

这是接入片段,先准备入门页的 Provider 并替换目录。适合作者更新定义后主动刷新;只改知识正文不需要为了静态图重新加载。预期 reloaded.oktrue;定义内容未变时修订也可不变。刷新返回 ok: false 时读取 providers 内的错误,不要只等 Promise resolve 就报告更新成功。

rootDir 在 open 时固定为绝对根,之后改变 cwd 不会重定位来源。Core 不监听文件,也不定时刷新。

刷新失败不会删除仍可完整读取的旧 current;状态会通过 Provider 结果中的 refreshFailed 暴露。句柄清理失败也不会覆盖已经成功的业务结果,而是在生命周期诊断中有界汇总。