From 8616ce83cfceae5527aa5df470a6015c47781667 Mon Sep 17 00:00:00 2001 From: _Kerman Date: Mon, 13 Jul 2026 16:36:26 +0800 Subject: [PATCH] refactor(agent-core-v2): derive wire-record scope from agent scope context MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AgentWireRecordService took an ad-hoc { homedir } options object as a constructor parameter, seeded per agent scope through SyncDescriptor args. Since agentHomedir is join(homeDir, agentScope), the store scope derived from it equals IAgentScopeContext.scope() — inject the scope context instead and drop both the options parameter and the IBootstrapService dependency. --- .../src/agent/wireRecord/wireRecordService.ts | 16 +++++++--------- .../agentLifecycle/agentLifecycleService.ts | 4 ++-- packages/agent-core-v2/test/harness/agent.ts | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/packages/agent-core-v2/src/agent/wireRecord/wireRecordService.ts b/packages/agent-core-v2/src/agent/wireRecord/wireRecordService.ts index 8fa579d9d..957bfbe90 100644 --- a/packages/agent-core-v2/src/agent/wireRecord/wireRecordService.ts +++ b/packages/agent-core-v2/src/agent/wireRecord/wireRecordService.ts @@ -3,7 +3,7 @@ import { relative } from 'pathe'; import { InstantiationType } from '#/_base/di/extensions'; import { Disposable } from '#/_base/di/lifecycle'; import { LifecycleScope, registerScopedService } from '#/_base/di/scope'; -import { IBootstrapService } from '#/app/bootstrap/bootstrap'; +import { IAgentScopeContext } from '#/agent/scopeContext/scopeContext'; import { IAppendLogStore } from '#/persistence/interface/appendLogStore'; import { IAgentWireService } from '#/wire/tokens'; import type { IWireService } from '#/wire/wireService'; @@ -29,18 +29,16 @@ export class AgentWireRecordService extends Disposable implements IAgentWireReco private readonly wireScope: string; constructor( - options: { readonly homedir?: string } = {}, - @IBootstrapService bootstrap: IBootstrapService, + @IAgentScopeContext scopeContext: IAgentScopeContext, @IAppendLogStore private readonly log?: IAppendLogStore, @IAgentWireService private readonly wire?: IWireService, ) { super(); - // Each agent scope seeds its own `homedir` (`/sessions/// - // agents/`); the wire log is the fixed `wire.jsonl` beneath it. The - // `IAppendLogStore` is App-scoped (shared, rooted at `homeDir`), so the - // store `scope` is the homedir made relative to `homeDir` — keeping every - // agent's records in its own file instead of one shared log. - this.wireScope = relative(bootstrap.homeDir, options.homedir ?? bootstrap.homeDir); + // The agent scope carries its persistence scope (`sessions/// + // agents/`); the wire log is the fixed `wire.jsonl` beneath it — + // the same scope `WireService` appends to, so `restore()` reads back + // what live dispatch wrote. + this.wireScope = scopeContext.scope(); if (this.log !== undefined) { this._register(this.log.acquire(this.wireScope, WIRE_RECORD_FILENAME)); } diff --git a/packages/agent-core-v2/src/session/agentLifecycle/agentLifecycleService.ts b/packages/agent-core-v2/src/session/agentLifecycle/agentLifecycleService.ts index c45956bd3..75f132c6e 100644 --- a/packages/agent-core-v2/src/session/agentLifecycle/agentLifecycleService.ts +++ b/packages/agent-core-v2/src/session/agentLifecycle/agentLifecycleService.ts @@ -231,10 +231,10 @@ export class AgentLifecycleService extends Disposable implements IAgentLifecycle readonly agentScope: string; readonly mcpManager: McpConnectionManager; }): ScopeSeed { - const { agentId, agentHomedir, agentScope, mcpManager } = input; + const { agentId, agentScope, mcpManager } = input; return [ [IAgentScopeContext, makeAgentScopeContext({ agentId, agentScope })], - [IAgentWireRecordService, new SyncDescriptor(AgentWireRecordService, [{ homedir: agentHomedir }])], + [IAgentWireRecordService, new SyncDescriptor(AgentWireRecordService)], [ IAgentWireService, new SyncDescriptor(WireService, [ diff --git a/packages/agent-core-v2/test/harness/agent.ts b/packages/agent-core-v2/test/harness/agent.ts index 0284573cd..e89f9bd32 100644 --- a/packages/agent-core-v2/test/harness/agent.ts +++ b/packages/agent-core-v2/test/harness/agent.ts @@ -1056,7 +1056,7 @@ export class AgentTestContext { (reg) => { reg.defineDescriptor( IAgentWireRecordService, - new SyncDescriptor(AgentWireRecordService, [{}]), + new SyncDescriptor(AgentWireRecordService), ); reg.defineDescriptor( IAgentWireService,