Power 配置

理解 Power 唯一实例、City 级配置与执行上下文的边界。

一个 City 中,每个 Power ID 只有一份宿主配置:

宿主保存 Power Config
→ City 持有一个 Power 实例
→ City 在每次执行时投影配置快照
→ Power 从当前 PowerContext.config 读取
const city = new City({
  powers: [web_power],
  workspaces: [workspace],
  power_host: {
    config: (power_id) => open_power_config_store(power_id),
    notifications: (power_id, agent_id) => open_notifications(power_id, agent_id),
  },
});

city.agents.add(agent);

PowerConfigStore.get() 同步返回当前完整配置快照,set(config) 原子替换完整配置。Agent 不保存 Power 引用或配置;同一份配置会提供给所有 Agent。多账号或多租户结构由具体 Power 在自己的 Config 中定义,City 不提供通用命名配置层。

Config action 由 Power 在 initialize() 中注册。City 调用 city.powers.invoke_config() 时注入 该 Power 唯一的 get/set store;Action、Hook、System 与 Availability 则从当前调用的 PowerContext.config 读取不可变快照。

配置保存后,Power 应主动释放或刷新受配置影响的长期资源。连接、回调和客户端对象不能写入 Config;它们仍由 Power 按账号、Agent 或其他真实领域身份管理,并最终由 dispose() 统一释放。