Repository navigation
pathing #94
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
pathing #94
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -718,7 +718,25 @@ function getBrokerConnectionFileInfo( | |
| return { hasApiKey: false } | ||
| } | ||
|
|
||
| const connectionPath = join(cwd, '.agent-relay', 'connection.json') | ||
| const candidates = brokerConnectionPathCandidates(cwd) | ||
| let firstExisting: BrokerConnectionFileInfo | undefined | ||
|
|
||
| for (const connectionPath of candidates) { | ||
| if (!existsSync(connectionPath)) continue | ||
|
|
||
| const info = readBrokerConnectionFileInfo(connectionPath, baseUrl, brokerPid) | ||
| if (info.status === 'matches') return info | ||
| firstExisting ??= info | ||
| } | ||
|
|
||
| return firstExisting ?? { path: candidates[0], status: 'missing', hasApiKey: false } | ||
| } | ||
|
|
||
| function readBrokerConnectionFileInfo( | ||
| connectionPath: string, | ||
| baseUrl: string | undefined, | ||
| brokerPid: number | undefined | ||
| ): BrokerConnectionFileInfo { | ||
| if (!existsSync(connectionPath)) { | ||
| return { path: connectionPath, status: 'missing', hasApiKey: false } | ||
| } | ||
|
|
@@ -745,6 +763,18 @@ function getBrokerConnectionFileInfo( | |
| } | ||
| } | ||
|
|
||
| function brokerConnectionPathCandidates(cwd: string): string[] { | ||
| return [ | ||
| join(cwd, '.agentworkforce', 'relay', 'connection.json'), | ||
| join(cwd, '.agent-relay', 'connection.json') | ||
| ] | ||
| } | ||
|
|
||
| function resolveBrokerConnectionPath(cwd: string): string { | ||
| const candidates = brokerConnectionPathCandidates(cwd) | ||
| return candidates.find((candidate) => existsSync(candidate)) ?? candidates[0] | ||
| } | ||
|
|
||
| function toInboundDeliveryMode(mode?: TerminalAttachMode): InboundDeliveryMode { | ||
| return mode === 'drive' ? 'manual_flush' : 'auto_inject' | ||
| } | ||
|
|
@@ -845,14 +875,19 @@ function getBrokerRuntimeSafeName(name: string): string { | |
| } | ||
|
|
||
| function getBrokerRuntimeCleanupPaths(cwd: string, brokerName: string): string[] { | ||
| const root = join(cwd, '.agent-relay') | ||
| const legacyRoot = join(cwd, '.agent-relay') | ||
| const currentRoot = join(cwd, '.agentworkforce', 'relay') | ||
| const safeName = getBrokerRuntimeSafeName(brokerName) | ||
|
|
||
| return [ | ||
| join(root, 'connection.json'), | ||
| join(root, `broker-${safeName}.lock`), | ||
| join(root, `state-${safeName}.json`), | ||
| join(root, `pending-${safeName}.json`) | ||
| join(currentRoot, 'connection.json'), | ||
| join(currentRoot, `broker-${safeName}.lock`), | ||
| join(currentRoot, `state-${safeName}.json`), | ||
| join(currentRoot, `pending-${safeName}.json`), | ||
| join(legacyRoot, 'connection.json'), | ||
| join(legacyRoot, `broker-${safeName}.lock`), | ||
| join(legacyRoot, `state-${safeName}.json`), | ||
| join(legacyRoot, `pending-${safeName}.json`) | ||
| ] | ||
| } | ||
|
|
||
|
|
@@ -1268,20 +1303,25 @@ export class BrokerManager { | |
| } | ||
|
|
||
| private async connectExistingBroker(projectId: string, cwd: string): Promise<AgentRelayClient | null> { | ||
| const connectionPath = join(cwd, '.agent-relay', 'connection.json') | ||
| if (!existsSync(connectionPath)) { | ||
| const connectionPaths = brokerConnectionPathCandidates(cwd).filter((candidate) => existsSync(candidate)) | ||
| if (connectionPaths.length === 0) { | ||
| return null | ||
| } | ||
|
|
||
| try { | ||
| const client = AgentRelayClient.connect({ cwd }) | ||
| await client.getSession() | ||
| console.log(`[broker] Reusing existing broker for project ${projectId}: ${connectionPath}`) | ||
| return client | ||
| } catch (err) { | ||
| console.warn(`[broker] Existing broker connection is not reusable for project ${projectId}:`, err) | ||
| return null | ||
| for (const connectionPath of connectionPaths) { | ||
| let client: AgentRelayClient | undefined | ||
| try { | ||
| client = AgentRelayClient.connect({ cwd, connectionPath }) | ||
| await client.getSession() | ||
| console.log(`[broker] Reusing existing broker for project ${projectId}: ${connectionPath}`) | ||
| return client | ||
| } catch (err) { | ||
| client?.disconnect() | ||
| console.warn(`[broker] Existing broker connection is not reusable for project ${projectId}:`, err) | ||
| } | ||
| } | ||
|
Comment on lines
+1311
to
1322
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: When probing multiple connection files, a client instance is created before health-checking with Severity Level: Major
|
||
|
|
||
| return null | ||
| } | ||
|
|
||
| // Re-establish a local broker whose process has died or wedged. When this | ||
|
|
||
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.
Avoid calling
brokerConnectionPathCandidates(cwd)twice to prevent redundant array allocations and path joins. Storing the candidates in a local variable is cleaner and more efficient.