* Move out checking out PRs from `etupGit` (#377 intent) * Keep subagent-related changes from #377
This commit is contained in:
committed by
pullfrog[bot]
parent
b472aa1ba9
commit
da72d0d6ee
@@ -144201,7 +144201,7 @@ function initToolState(params) {
|
|||||||
return {
|
return {
|
||||||
progressCommentId: resolvedId,
|
progressCommentId: resolvedId,
|
||||||
subagents: /* @__PURE__ */ new Map(),
|
subagents: /* @__PURE__ */ new Map(),
|
||||||
activeSubagentId: void 0,
|
selfSubagentId: void 0,
|
||||||
backgroundProcesses: /* @__PURE__ */ new Map(),
|
backgroundProcesses: /* @__PURE__ */ new Map(),
|
||||||
usageEntries: []
|
usageEntries: []
|
||||||
};
|
};
|
||||||
@@ -144379,12 +144379,13 @@ async function startMcpHttpServer(ctx) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
async function startSubagentMcpServer(ctx) {
|
async function startSubagentMcpServer(params) {
|
||||||
const subagentToolState = {
|
const subagentToolState = {
|
||||||
...ctx.toolState,
|
...params.ctx.toolState,
|
||||||
|
selfSubagentId: params.subagentId,
|
||||||
backgroundProcesses: /* @__PURE__ */ new Map()
|
backgroundProcesses: /* @__PURE__ */ new Map()
|
||||||
};
|
};
|
||||||
const subagentCtx = { ...ctx, toolState: subagentToolState };
|
const subagentCtx = { ...params.ctx, toolState: subagentToolState };
|
||||||
const tools = buildSubagentTools(subagentCtx);
|
const tools = buildSubagentTools(subagentCtx);
|
||||||
const startResult = await selectMcpPort(subagentCtx, tools);
|
const startResult = await selectMcpPort(subagentCtx, tools);
|
||||||
return { url: startResult.url, stop: () => startResult.server.stop() };
|
return { url: startResult.url, stop: () => startResult.server.stop() };
|
||||||
@@ -147464,12 +147465,7 @@ async function setupGit(params) {
|
|||||||
$("git", ["remote", "set-url", "origin", originUrl], { cwd: repoDir });
|
$("git", ["remote", "set-url", "origin", originUrl], { cwd: repoDir });
|
||||||
params.toolState.pushUrl = originUrl;
|
params.toolState.pushUrl = originUrl;
|
||||||
$("git", ["config", "--local", "credential.helper", ""], { cwd: repoDir });
|
$("git", ["config", "--local", "credential.helper", ""], { cwd: repoDir });
|
||||||
if (params.event.is_pr !== true || !params.event.issue_number) {
|
log.info("\xBB git authentication configured");
|
||||||
log.info("\xBB git authentication configured");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const prNumber = params.event.issue_number;
|
|
||||||
await checkoutPrBranch(prNumber, params);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// utils/time.ts
|
// utils/time.ts
|
||||||
|
|||||||
+17
-6
@@ -25,6 +25,7 @@ export type SubagentStatus = "running" | "completed" | "failed";
|
|||||||
|
|
||||||
export type SubagentState = {
|
export type SubagentState = {
|
||||||
id: string;
|
id: string;
|
||||||
|
label: string;
|
||||||
status: SubagentStatus;
|
status: SubagentStatus;
|
||||||
mode: string;
|
mode: string;
|
||||||
stdoutFilePath: string;
|
stdoutFilePath: string;
|
||||||
@@ -46,8 +47,9 @@ export interface ToolState {
|
|||||||
selectedMode?: string;
|
selectedMode?: string;
|
||||||
// per-subagent lifecycle tracking (keyed by subagent uuid)
|
// per-subagent lifecycle tracking (keyed by subagent uuid)
|
||||||
subagents: Map<string, SubagentState>;
|
subagents: Map<string, SubagentState>;
|
||||||
// set while a subagent is running — routes set_output to the correct subagent and prevents nesting
|
// only set on subagent shallow copies — routes set_output to the owning subagent.
|
||||||
activeSubagentId: string | undefined;
|
// never set on the orchestrator's shared state.
|
||||||
|
selfSubagentId: string | undefined;
|
||||||
backgroundProcesses: Map<string, BackgroundProcess>;
|
backgroundProcesses: Map<string, BackgroundProcess>;
|
||||||
review?: {
|
review?: {
|
||||||
id: number;
|
id: number;
|
||||||
@@ -81,7 +83,7 @@ export function initToolState(params: InitToolStateParams): ToolState {
|
|||||||
return {
|
return {
|
||||||
progressCommentId: resolvedId,
|
progressCommentId: resolvedId,
|
||||||
subagents: new Map(),
|
subagents: new Map(),
|
||||||
activeSubagentId: undefined,
|
selfSubagentId: undefined,
|
||||||
backgroundProcesses: new Map(),
|
backgroundProcesses: new Map(),
|
||||||
usageEntries: [],
|
usageEntries: [],
|
||||||
};
|
};
|
||||||
@@ -391,21 +393,30 @@ export type ManagedMcpServer = {
|
|||||||
stop: () => Promise<void>;
|
stop: () => Promise<void>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type StartSubagentMcpServerParams = {
|
||||||
|
ctx: ToolContext;
|
||||||
|
subagentId: string;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start a per-subagent MCP server (common tools only — no push/PR/delegation).
|
* Start a per-subagent MCP server (common tools only — no push/PR/delegation).
|
||||||
* Each subagent gets its own server; call stop() when the subagent completes.
|
* Each subagent gets its own server; call stop() when the subagent completes.
|
||||||
*
|
*
|
||||||
* The subagent gets its own shallow copy of toolState so scalar writes
|
* The subagent gets its own shallow copy of toolState so scalar writes
|
||||||
* (pushUrl, pushDest, selectedMode, etc.) don't mutate the orchestrator's state.
|
* (pushUrl, pushDest, selectedMode, etc.) don't mutate the orchestrator's state.
|
||||||
|
* selfSubagentId is set on the copy so set_output routes to the correct subagent.
|
||||||
* Shared references (subagents Map, usageEntries array, dependencyInstallation)
|
* Shared references (subagents Map, usageEntries array, dependencyInstallation)
|
||||||
* are intentionally shared for coordination (set_output routing, usage tracking).
|
* are intentionally shared for coordination (set_output routing, usage tracking).
|
||||||
*/
|
*/
|
||||||
export async function startSubagentMcpServer(ctx: ToolContext): Promise<ManagedMcpServer> {
|
export async function startSubagentMcpServer(
|
||||||
|
params: StartSubagentMcpServerParams
|
||||||
|
): Promise<ManagedMcpServer> {
|
||||||
const subagentToolState: ToolState = {
|
const subagentToolState: ToolState = {
|
||||||
...ctx.toolState,
|
...params.ctx.toolState,
|
||||||
|
selfSubagentId: params.subagentId,
|
||||||
backgroundProcesses: new Map(),
|
backgroundProcesses: new Map(),
|
||||||
};
|
};
|
||||||
const subagentCtx: ToolContext = { ...ctx, toolState: subagentToolState };
|
const subagentCtx: ToolContext = { ...params.ctx, toolState: subagentToolState };
|
||||||
const tools = buildSubagentTools(subagentCtx);
|
const tools = buildSubagentTools(subagentCtx);
|
||||||
const startResult = await selectMcpPort(subagentCtx, tools);
|
const startResult = await selectMcpPort(subagentCtx, tools);
|
||||||
return { url: startResult.url, stop: () => startResult.server.stop() };
|
return { url: startResult.url, stop: () => startResult.server.stop() };
|
||||||
|
|||||||
+3
-17
@@ -2,8 +2,7 @@ import { execSync } from "node:child_process";
|
|||||||
import { mkdtempSync } from "node:fs";
|
import { mkdtempSync } from "node:fs";
|
||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import type { PayloadEvent, ShellPermission } from "../external.ts";
|
import type { ShellPermission } from "../external.ts";
|
||||||
import { checkoutPrBranch } from "../mcp/checkout.ts";
|
|
||||||
import type { ToolState } from "../mcp/server.ts";
|
import type { ToolState } from "../mcp/server.ts";
|
||||||
import { log } from "./cli.ts";
|
import { log } from "./cli.ts";
|
||||||
import type { OctokitWithPlugins } from "./github.ts";
|
import type { OctokitWithPlugins } from "./github.ts";
|
||||||
@@ -59,9 +58,7 @@ export interface GitContext {
|
|||||||
postCheckoutScript: string | null;
|
postCheckoutScript: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SetupGitParams extends GitContext {
|
export type SetupGitParams = GitContext;
|
||||||
event: PayloadEvent;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* setup git configuration and authentication for the repository.
|
* setup git configuration and authentication for the repository.
|
||||||
@@ -170,16 +167,5 @@ export async function setupGit(params: SetupGitParams): Promise<void> {
|
|||||||
// disable credential helpers to prevent prompts and ensure clean auth state
|
// disable credential helpers to prevent prompts and ensure clean auth state
|
||||||
$("git", ["config", "--local", "credential.helper", ""], { cwd: repoDir });
|
$("git", ["config", "--local", "credential.helper", ""], { cwd: repoDir });
|
||||||
|
|
||||||
// non-PR events: stay on default branch
|
log.info("» git authentication configured");
|
||||||
if (params.event.is_pr !== true || !params.event.issue_number) {
|
|
||||||
log.info("» git authentication configured");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// PR event: checkout PR branch using shared helper
|
|
||||||
const prNumber = params.event.issue_number;
|
|
||||||
|
|
||||||
// use shared checkout helper (handles fork remotes, push config, post-checkout hook)
|
|
||||||
// this updates toolState.pushUrl for fork PRs and sets toolState.issueNumber
|
|
||||||
await checkoutPrBranch(prNumber, params);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user