diff --git a/packages/agent-core-v2/src/session/btw/btw.ts b/packages/agent-core-v2/src/features/btw/btw.ts similarity index 100% rename from packages/agent-core-v2/src/session/btw/btw.ts rename to packages/agent-core-v2/src/features/btw/btw.ts diff --git a/packages/agent-core-v2/src/features/btw/btwFeature.ts b/packages/agent-core-v2/src/features/btw/btwFeature.ts new file mode 100644 index 00000000000..c47d509f424 --- /dev/null +++ b/packages/agent-core-v2/src/features/btw/btwFeature.ts @@ -0,0 +1,26 @@ +/** + * `btw` domain — `BtwFeature`: the side-question ("by the way") capability + * assembled as one App-scope Feature unit. + * + * Contributes the per-Session `ISessionBtwService` through the `features` + * base-class seams; retracting the unit withdraws it across the scope tree. + * Registered into the feature table at import. + */ + +import { LifecycleScope } from '#/app/scopes'; +import { Feature } from '#/features/feature'; +import { registerFeature } from '#/features/featureRegistry'; + +import { ISessionBtwService } from './btw'; +import { SessionBtwService } from './btwService'; + +export class BtwFeature extends Feature { + static override readonly name = 'btw'; + + constructor() { + super(); + this.contributeService(LifecycleScope.Session, ISessionBtwService, SessionBtwService); + } +} + +registerFeature(BtwFeature); diff --git a/packages/agent-core-v2/src/session/btw/btwService.ts b/packages/agent-core-v2/src/features/btw/btwService.ts similarity index 73% rename from packages/agent-core-v2/src/session/btw/btwService.ts rename to packages/agent-core-v2/src/features/btw/btwService.ts index 0b81d2cd7cf..74f45a0d1e5 100644 --- a/packages/agent-core-v2/src/session/btw/btwService.ts +++ b/packages/agent-core-v2/src/features/btw/btwService.ts @@ -5,16 +5,14 @@ * `IAgentLifecycleService.fork`, then disables tool calls via an * `onBeforeExecuteTool` veto listener (blocks every tool call with the * `toolApproval.formatDenyMessage`-formatted TOOL_CALL_DISABLED_MESSAGE) and - * appends the side-channel system reminder. Bound at Session scope — - * `fork('main')` is a session-level operation, so the service injects the - * session's `IAgentLifecycleService` directly rather than resolving it through - * the main agent's accessor. Callers materialize the main agent first; - * forking a missing source throws. + * appends the side-channel system reminder. Contributed at Session scope by + * `BtwFeature` (`features/btw/btwFeature`) — `fork('main')` is a + * session-level operation, so the service injects the session's + * `IAgentLifecycleService` directly rather than resolving it through the main + * agent's accessor. Callers materialize the main agent first; forking a + * missing source throws. */ -import { LifecycleScope } from '#/app/scopes'; - -import { ScopeActivation, registerScopedService } from '#/_base/di/scope'; import { IAgentSystemReminderService } from '#/agent/systemReminder/systemReminder'; import { IAgentToolApprovalService } from '#/agent/toolApproval/toolApproval'; import { denyToolExecution } from '#/agent/toolExecutor/beforeToolExecuteEvent'; @@ -50,11 +48,3 @@ export class SessionBtwService implements ISessionBtwService { return child.id; } } - -registerScopedService( - LifecycleScope.Session, - ISessionBtwService, - SessionBtwService, - ScopeActivation.OnScopeCreated, - 'session-btw', -); diff --git a/packages/agent-core-v2/src/index.ts b/packages/agent-core-v2/src/index.ts index df9feb7ea2a..6d910fcaba4 100644 --- a/packages/agent-core-v2/src/index.ts +++ b/packages/agent-core-v2/src/index.ts @@ -289,6 +289,9 @@ export * from '#/app/flag/flagService'; export * from '#/agent/activityView/activityView'; import '#/agent/activityView/activityViewService'; +export * from '#/features/btw/btw'; +export * from '#/features/btw/btwService'; +import '#/features/btw/btwFeature'; import '#/features/plan/profile/plan'; export * from '#/features/plan/tools/enter-plan-mode/enter-plan-mode'; import '#/features/plan/tools/enter-plan-mode/enterPlanModeTool'; @@ -625,8 +628,6 @@ export * from '#/agent/rpc/prompt-metadata'; export * from '#/agent/scopeContext/scopeContext'; export * from '#/agent/stepRetry/stepRetry'; export * from '#/agent/stepRetry/stepRetryService'; -export * from '#/session/btw/btw'; -export * from '#/session/btw/btwService'; export * from '#/session/sessionInit/sessionInit'; export * from '#/session/sessionInit/sessionInitService'; export * from '#/session/sessionInit/profile/init'; diff --git a/packages/agent-core-v2/test/session/btw/btw.test.ts b/packages/agent-core-v2/test/features/btw/btw.test.ts similarity index 97% rename from packages/agent-core-v2/test/session/btw/btw.test.ts rename to packages/agent-core-v2/test/features/btw/btw.test.ts index 049d49a114e..2e3fc9d9f0b 100644 --- a/packages/agent-core-v2/test/session/btw/btw.test.ts +++ b/packages/agent-core-v2/test/features/btw/btw.test.ts @@ -6,14 +6,14 @@ import { TestInstantiationService } from '#/_base/di/test'; import { IAgentSystemReminderService } from '#/agent/systemReminder/systemReminder'; import { IAgentToolApprovalService } from '#/agent/toolApproval/toolApproval'; import { IAgentToolExecutorService } from '#/agent/toolExecutor/toolExecutor'; -import type { ToolCall } from '#/kosong/contract/message'; -import { IAgentLifecycleService } from '#/session/agentLifecycle/agentLifecycle'; import { ISessionBtwService, SIDE_QUESTION_SYSTEM_REMINDER, TOOL_CALL_DISABLED_MESSAGE, -} from '#/session/btw/btw'; -import { SessionBtwService } from '#/session/btw/btwService'; +} from '#/features/btw/btw'; +import { SessionBtwService } from '#/features/btw/btwService'; +import type { ToolCall } from '#/kosong/contract/message'; +import { IAgentLifecycleService } from '#/session/agentLifecycle/agentLifecycle'; import { stubToolExecutorEvents, type ToolExecutorEventStubs } from '../../agent/toolExecutor/stubs';