Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions packages/agent/src/adapters/local-tools/registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ describe("local-tools registry", () => {
expected: true,
},
{
name: "cloud run without a token",
name: "cloud run without a token (resolved lazily at call time)",
meta: { environment: "cloud" as const },
token: undefined,
expected: false,
expected: true,
},
{
name: "desktop run with a token",
Expand All @@ -59,17 +59,14 @@ describe("local-tools registry", () => {
token: undefined,
expected: false,
},
])(
"exposes git_signed_commit only in $name when cloud+token",
({ meta, token, expected }) => {
const tools = enabledLocalTools({ cwd: "/repo", token }, meta);
const hasSignedCommit = tools.some((t) => t.name === "git_signed_commit");
expect(hasSignedCommit).toBe(expected);
},
);
])("exposes git_signed_commit in $name", ({ meta, token, expected }) => {
const tools = enabledLocalTools({ cwd: "/repo", token }, meta);
const hasSignedCommit = tools.some((t) => t.name === "git_signed_commit");
expect(hasSignedCommit).toBe(expected);
});

it("does not treat legacy taskRunId-only metadata as cloud", () => {
const tools = enabledLocalTools({ cwd: "/repo", token: "ghs_x" }, {
const tools = enabledLocalTools({ cwd: "/repo", token: undefined }, {
taskRunId: "run-1",
} as unknown as { environment?: "local" | "cloud" });
const hasSignedCommit = tools.some((t) => t.name === "git_signed_commit");
Expand Down
33 changes: 24 additions & 9 deletions packages/agent/src/adapters/local-tools/tools/signed-commit.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isCloudRun } from "../../../utils/common";
import { isCloudRun, resolveGithubToken } from "../../../utils/common";
import {
runSignedCommitTool,
SIGNED_COMMIT_TOOL_DESCRIPTION,
Expand All @@ -8,19 +8,34 @@ import {
import { defineLocalTool } from "../registry";

/**
* `git_signed_commit` as a local tool. Cloud runs only, and only when a GitHub
* token is available (the commit is created via GitHub's API, which also signs
* it). Committing is core to cloud tasks, so keep it visible past ToolSearch.
* `git_signed_commit` as a local tool. Cloud-run only; the token is resolved
* lazily at call time so the tool stays visible even when the GitHub token
* lands in `process.env` after the session was created (e.g. an orchestrator
* injecting it post-spawn). Committing is core to cloud tasks, so keep it
* exposed past ToolSearch via `alwaysLoad`.
*/
export const signedCommitTool = defineLocalTool({
name: SIGNED_COMMIT_TOOL_NAME,
description: SIGNED_COMMIT_TOOL_DESCRIPTION,
schema: signedCommitToolSchema,
alwaysLoad: true,
isEnabled: (ctx, meta) => isCloudRun(meta) && !!ctx.token,
handler: (ctx, args) =>
runSignedCommitTool(
{ cwd: ctx.cwd, token: ctx.token ?? "", taskId: ctx.taskId },
isEnabled: (_ctx, meta) => isCloudRun(meta),
handler: (ctx, args) => {
const token = ctx.token ?? resolveGithubToken();
if (!token) {
return Promise.resolve({
content: [
{
type: "text" as const,
text: `${SIGNED_COMMIT_TOOL_NAME} failed: no GitHub token in env (GH_TOKEN/GITHUB_TOKEN)`,
},
],
isError: true,
});
}
return runSignedCommitTool(
{ cwd: ctx.cwd, token, taskId: ctx.taskId },
args,
),
);
},
});
Loading