mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-12-06 03:41:38 +08:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b46830d3d2 |
+1
-1
@@ -136,7 +136,7 @@ Bots often open pull requests from branches in your own repository. Runs there u
|
||||
|
||||
Steps that run after Claude, including post steps such as `actions/checkout`'s cleanup, trust `GITHUB_ENV`, `GITHUB_PATH` and git's config files, and the action's own outputs in `GITHUB_OUTPUT`. When the session ends, the action restores those files, including config pulled in through `include.path`, to how they were before it started, and logs a warning naming any it changed. A session therefore can't pass environment variables to later steps through `GITHUB_ENV`, and `git config` changes it made, such as the upstream that `git push -u` records, don't last. Use `--json-schema` to pass results on. What a session writes to `GITHUB_OUTPUT` is dropped, because the action passes on only its own outputs. What a session writes to `GITHUB_STEP_SUMMARY` is kept, unless it replaced the file with a link or something else that isn't a file.
|
||||
|
||||
Claude's file tools can't change anything in `~/.mix`, or in the directories that `MIX_HOME`, `MIX_ARCHIVES` or `MIX_XDG` name, because later `mix` commands run what is there. Set those variables for the whole job, because the action can't see ones that only a later step sets. A directory that contains the workspace isn't protected, because Claude couldn't edit the repository then. This applies even with an allow rule for `Write` or `Edit`. Shell commands that write there by name, such as `cp`, `touch` or a redirect, are refused too. Commands such as `mix local.hex` still work where the workflow allows them.
|
||||
Claude's file tools can't change anything in `~/.mix`, in the directories that `MIX_HOME` and `MIX_ARCHIVES` name, in Mix's XDG data and config directories if `MIX_XDG` is set, or the file that `MIX_REBAR3` names, because later `mix` commands run what is there. Set those variables for the whole job, because the action can't see ones that only a later step sets. Use absolute paths, because the action resolves a relative one against its own working directory. A directory that contains the workspace isn't protected, because Claude couldn't edit the repository then. This applies even with an allow rule for `Write` or `Edit`. Shell commands that write there by name, such as `cp`, `touch` or a redirect, are refused too. Commands such as `mix local.hex` still work where the workflow allows them.
|
||||
|
||||
While Claude runs, and for the action's own git commands afterwards, git ignores `core.fsmonitor`. Git hooks are off for the action's own commits after the session, and from before the checkout on pull requests that `restrict_untrusted_prs` applies to. During the session these are set in the repository's git config and by the wrapper scripts. Global git config also sets `safe.bareRepository=explicit` for the session, so git won't use a repository it finds in a folder that has no `.git`. A workflow that has Claude work in a bare repository needs to pass `--git-dir`. If a run is killed before it restores this, the setting stays in the global config of a self-hosted runner that keeps its home directory. Git LFS uploads through a hook, so the action uploads objects itself for its own commits, but a push Claude makes on such a pull request won't include them.
|
||||
|
||||
|
||||
@@ -176,20 +176,32 @@ function toRulePath(directory: string): string {
|
||||
|
||||
/**
|
||||
* Rules that keep Claude's file tools out of Mix's home directory. Every later mix
|
||||
* command loads the archives and runs the rebar3 kept there. These are rules rather than
|
||||
* files to restore, because a session may install Hex there for later steps to use.
|
||||
* command loads the archives and config.exs and runs the rebar3 kept there. These are
|
||||
* rules rather than files to restore, because a session may install Hex there for later
|
||||
* steps to use.
|
||||
*/
|
||||
export function mixHomeDenyRules(): string[] {
|
||||
const { MIX_ARCHIVES, MIX_HOME, MIX_XDG, XDG_DATA_HOME } = process.env;
|
||||
const home = process.env.HOME || homedir();
|
||||
const xdgHome =
|
||||
MIX_XDG && join(XDG_DATA_HOME || join(home, ".local/share"), "mix");
|
||||
const moved = [MIX_HOME, MIX_ARCHIVES, xdgHome]
|
||||
const { env } = process;
|
||||
const home = env.HOME || homedir();
|
||||
// With MIX_XDG, the config has a directory of its own.
|
||||
const xdgHomes = env.MIX_XDG
|
||||
? [
|
||||
join(env.XDG_DATA_HOME || join(home, ".local/share"), "mix"),
|
||||
join(env.XDG_CONFIG_HOME || join(home, ".config"), "mix"),
|
||||
]
|
||||
: [];
|
||||
const moved = [env.MIX_HOME, env.MIX_ARCHIVES, ...xdgHomes]
|
||||
.flatMap((path) => (path ? [resolve(path)] : []))
|
||||
// A rule for a directory that holds the workspace would stop all edits.
|
||||
.filter((directory) => !holdsWorkspace(directory))
|
||||
.map(toRulePath);
|
||||
return [...new Set(["~/.mix", ...moved])].map((path) => `Edit(${path}/**)`);
|
||||
const rules = ["~/.mix", ...moved].map((path) => `Edit(${path}/**)`);
|
||||
// Mix looks up a bare name on PATH.
|
||||
const rebar3 = env.MIX_REBAR3;
|
||||
if (rebar3 && isAbsolute(rebar3) && !holdsWorkspace(rebar3)) {
|
||||
rules.push(`Edit(${toRulePath(resolve(rebar3))})`);
|
||||
}
|
||||
return [...new Set(rules)];
|
||||
}
|
||||
|
||||
function readSnapshot(file: TrackedFile): FileSnapshot {
|
||||
|
||||
@@ -38,6 +38,7 @@ const KEYS = [
|
||||
"XDG_CONFIG_HOME",
|
||||
"MIX_ARCHIVES",
|
||||
"MIX_HOME",
|
||||
"MIX_REBAR3",
|
||||
"MIX_XDG",
|
||||
"XDG_DATA_HOME",
|
||||
"GIT_CONFIG_GLOBAL",
|
||||
@@ -681,9 +682,27 @@ describe("session guard", () => {
|
||||
expect(mixHomeDenyRules()).toEqual([
|
||||
"Edit(~/.mix/**)",
|
||||
`Edit(/${join(dir, "home", ".local/share/mix")}/**)`,
|
||||
`Edit(/${join(dir, "home", ".config/mix")}/**)`,
|
||||
]);
|
||||
process.env.XDG_DATA_HOME = "/data";
|
||||
expect(mixHomeDenyRules()).toContain("Edit(//data/mix/**)");
|
||||
process.env.XDG_CONFIG_HOME = "/config";
|
||||
expect(mixHomeDenyRules()).toEqual([
|
||||
"Edit(~/.mix/**)",
|
||||
"Edit(//data/mix/**)",
|
||||
"Edit(//config/mix/**)",
|
||||
]);
|
||||
});
|
||||
|
||||
test("covers the rebar3 that MIX_REBAR3 names", () => {
|
||||
process.env.MIX_REBAR3 = "/opt/tools/rebar3";
|
||||
expect(mixHomeDenyRules()).toEqual([
|
||||
"Edit(~/.mix/**)",
|
||||
"Edit(//opt/tools/rebar3)",
|
||||
]);
|
||||
for (const value of ["rebar3", process.cwd()]) {
|
||||
process.env.MIX_REBAR3 = value;
|
||||
expect(mixHomeDenyRules()).toEqual(["Edit(~/.mix/**)"]);
|
||||
}
|
||||
});
|
||||
|
||||
test("leaves out a directory that holds the workspace", () => {
|
||||
|
||||
Reference in New Issue
Block a user