Repository navigation
refactor(subagents): add driver registry and runtime policy #381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import type { | ||
| SubagentProviderConfig, | ||
| SubagentsConfig, | ||
| } from "./local-agent-config.js"; | ||
| import { | ||
| localAgentProviderEnvironment, | ||
| localAgentProviderEnvironmentOverrides, | ||
| } from "./local-agent-config.js"; | ||
| import type { | ||
| LocalAgentDriverKind, | ||
| LocalAgentProviderInstanceId, | ||
| } from "./local-agent-provider.js"; | ||
| import type { LocalAgentDriver } from "./local-agent-runtime.js"; | ||
|
|
||
| export interface LocalAgentDriverFactoryContext { | ||
| instance: SubagentProviderConfig; | ||
| env: NodeJS.ProcessEnv; | ||
| envOverrides: Record<string, string>; | ||
| } | ||
|
|
||
| export type LocalAgentDriverFactory = ( | ||
| context: LocalAgentDriverFactoryContext, | ||
| ) => LocalAgentDriver; | ||
|
|
||
| export class LocalAgentProviderRegistry { | ||
| private readonly factories = new Map<LocalAgentDriverKind, LocalAgentDriverFactory>(); | ||
|
|
||
| register(kind: LocalAgentDriverKind, factory: LocalAgentDriverFactory): this { | ||
| if (this.factories.has(kind)) throw new Error(`Local agent driver already registered: ${kind}`); | ||
| this.factories.set(kind, factory); | ||
| return this; | ||
| } | ||
|
|
||
| create( | ||
| instance: SubagentProviderConfig, | ||
| subagents: SubagentsConfig | undefined, | ||
| inheritedEnv: NodeJS.ProcessEnv, | ||
| ): LocalAgentDriver { | ||
| const factory = this.factories.get(instance.driver); | ||
| if (!factory) throw new Error(`No local agent driver registered for: ${instance.driver}`); | ||
| const env = subagents | ||
| ? localAgentProviderEnvironment(subagents, instance.id, inheritedEnv) | ||
| : inheritedEnv; | ||
| const envOverrides = subagents | ||
| ? localAgentProviderEnvironmentOverrides(subagents, instance.id) | ||
| : {}; | ||
| return new ProviderInstanceDriver(instance.id, factory({ instance, env, envOverrides })); | ||
| } | ||
| } | ||
|
|
||
| class ProviderInstanceDriver implements LocalAgentDriver { | ||
| readonly provider: LocalAgentDriverKind; | ||
| readonly runtimePolicy: LocalAgentDriver["runtimePolicy"]; | ||
|
|
||
| constructor( | ||
| readonly providerInstanceId: LocalAgentProviderInstanceId, | ||
| private readonly driver: LocalAgentDriver, | ||
| ) { | ||
| this.provider = driver.provider; | ||
| this.runtimePolicy = driver.runtimePolicy; | ||
| } | ||
|
|
||
| createRuntime(context: Parameters<LocalAgentDriver["createRuntime"]>[0]) { | ||
| return this.driver.createRuntime(context); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
git diff 711096e8ec4c4c45267ca45acbbb88bb4fe3578c 8a73fa86cab2b002ed7ae61bd5859d0a27a91c94 -- src/local-agent-runtime-pool.ts src/local-agent-acp.ts src/local-agent-adapters.ts src/local-agent-runtime.ts sed -n '355,400p' src/local-agent-manager.tsRepository: Waishnav/devspace
Length of output: 10536
🏁 Script executed:
Repository: Waishnav/devspace
Length of output: 29692
🏁 Script executed:
Repository: Waishnav/devspace
Length of output: 28578
🏁 Script executed:
Repository: Waishnav/devspace
Length of output: 3950
Key ACP runtimes by workspace identity.
Distinct
open_workspaceIDs can refer to the same root. ACP’s workspace key uses that root, so those IDs can share a runtime and its session tracking. This violates the workspace ownership contract. The removed ACP key also used the resolved root, so this PR preserves the collision rather than introducing it. Pass the storedworkspaceIdinto the runtime context. For requests without an ID, isolate by agent ID instead of falling back to the root.🐛 Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents