-
Notifications
You must be signed in to change notification settings - Fork 101
fix(#1625): exclude agent working directories from git tracking #1627
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
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 |
|---|---|---|
|
|
@@ -43,6 +43,14 @@ const ( | |
| maxContextScanDepth = 5 | ||
| ) | ||
|
|
||
| // agentWorkingDirExcludes lists directory patterns that agents may create | ||
| // during execution but must never commit. These are added to | ||
| // .git/info/exclude before the agent runs so git ignores them entirely. | ||
| var agentWorkingDirExcludes = []string{ | ||
| ".agentready/", | ||
| ".fullsend-workspace/", | ||
| } | ||
|
|
||
| func newRunCmd() *cobra.Command { | ||
| var fullsendDir string | ||
| var outputBase string | ||
|
|
@@ -450,6 +458,14 @@ func runAgent(ctx context.Context, agentName, fullsendDir, outputBase, targetRep | |
| } | ||
| } | ||
|
|
||
| // 8a-2. Exclude agent working directories from git tracking. | ||
| // Agents may create working directories (e.g. .agentready/) during | ||
| // execution. These must never appear in commits. Adding them to | ||
| // .git/info/exclude ensures git status/add ignores them entirely. | ||
| if err := excludeAgentWorkingDirs(sandboxName, repoDir, printer); err != nil { | ||
| printer.StepWarn("Could not exclude agent working dirs: " + err.Error()) | ||
| } | ||
|
|
||
| // 8b. Copy agent-input files (if configured). | ||
| if h.AgentInput != "" { | ||
| inputStart := time.Now() | ||
|
|
@@ -1248,6 +1264,25 @@ func relOrAbs(base, path string) string { | |
| return rel | ||
| } | ||
|
|
||
| // excludeAgentWorkingDirs adds agent working directory patterns to | ||
| // .git/info/exclude so they are invisible to git status and git add. | ||
| func excludeAgentWorkingDirs(sandboxName, repoDir string, printer *ui.Printer) error { | ||
| var lines []string | ||
| for _, pattern := range agentWorkingDirExcludes { | ||
| lines = append(lines, pattern) | ||
| } | ||
| if len(lines) == 0 { | ||
| return nil | ||
| } | ||
|
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. [low] security excludeAgentWorkingDirs constructs a shell command via fmt.Sprintf with payload and repoDir interpolated into a single-quoted string. Safe with current hardcoded values and consistent with existing patterns, but fragile if a future agentWorkingDirExcludes entry contains a single quote. Suggested fix: Consider writing patterns to a temp file and appending via cat, or escaping the payload. 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. [low] command-injection excludeAgentWorkingDirs constructs a shell command via fmt.Sprintf with payload and repoDir interpolated into a single-quoted string. Currently safe with hardcoded values and consistent with the existing AGENTS.md exclude pattern (line 425), but fragile if a future agentWorkingDirExcludes entry contains a single quote. Suggested fix: Write patterns to a temp file and append via cat, or use an exec-style API that avoids shell interpolation. |
||
| payload := strings.Join(lines, "\n") | ||
| excludeCmd := fmt.Sprintf("printf '%%s\\n' '%s' >> %s/.git/info/exclude", | ||
| payload, repoDir) | ||
| if _, _, _, err := sandbox.Exec(sandboxName, excludeCmd, 5*time.Second); err != nil { | ||
| return fmt.Errorf("writing git exclude: %w", err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // hasAgentsMD checks whether the repo directory contains an AGENTS.md file | ||
| // in any common casing. | ||
| func hasAgentsMD(repoDir string) bool { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -582,6 +582,26 @@ func TestResolveLinuxBinary_Download(t *testing.T) { | |
| assert.NoError(t, validateLinuxBinary(binPath), "downloaded binary should be a valid Linux/amd64 ELF") | ||
| } | ||
|
|
||
| func TestAgentWorkingDirExcludes_ContainsKnownPatterns(t *testing.T) { | ||
|
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. [low] correctness Go tests verify the agentWorkingDirExcludes slice contents but do not test the excludeAgentWorkingDirs function itself. Shell command generation, error handling, and sandbox interaction are untested. Suggested fix: Add a unit test that exercises excludeAgentWorkingDirs with a mock sandbox, verifying the generated command and error paths. 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. [low] test-adequacy Go tests verify the agentWorkingDirExcludes slice contents but do not test the excludeAgentWorkingDirs function itself. The function shell command generation, error handling, and sandbox interaction remain untested. Suggested fix: Add a unit test for excludeAgentWorkingDirs that mocks sandbox.Exec and verifies the generated command string. |
||
| // Verify the exclusion list contains the known agent working directories. | ||
| expected := []string{".agentready/", ".fullsend-workspace/"} | ||
| for _, pattern := range expected { | ||
| found := false | ||
| for _, exclude := range agentWorkingDirExcludes { | ||
|
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. [low] test-assertion-style Manual loop with found flag to check slice membership can be replaced with assert.Contains(t, agentWorkingDirExcludes, pattern) which is more idiomatic. |
||
| if exclude == pattern { | ||
| found = true | ||
| break | ||
| } | ||
| } | ||
| assert.True(t, found, "agentWorkingDirExcludes should contain %q", pattern) | ||
| } | ||
| } | ||
|
|
||
| func TestAgentWorkingDirExcludes_NotEmpty(t *testing.T) { | ||
| assert.NotEmpty(t, agentWorkingDirExcludes, | ||
| "agentWorkingDirExcludes must not be empty — agents create working dirs that need exclusion") | ||
| } | ||
|
|
||
| func TestReadOIDCAuthFile_Success(t *testing.T) { | ||
| f := filepath.Join(t.TempDir(), "auth") | ||
| require.NoError(t, os.WriteFile(f, []byte("bearer test-token"), 0o600)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -126,6 +126,59 @@ fi | |
| echo "Changed files:" | ||
| echo "${CHANGED_FILES}" | sed 's/^/ /' | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
|
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. [high] correctness Section 2b ("Strip agent working directories") detects agent artifacts and logs warnings, but never actually removes them from the commit. STRIPPED_FILES is set but never consumed — no git rm, git reset HEAD, or filtering of CHANGED_FILES follows. The defense-in-depth layer is inert. Suggested fix: After the detection loop, use git rm --cached on each file in STRIPPED_FILES and amend the commit, or filter CHANGED_FILES to exclude them before the push step. |
||
| # 2b. Strip agent working directories (defense-in-depth) | ||
| # | ||
| # Agent working dirs (.agentready/, .fullsend-workspace/) should never | ||
| # appear in commits. The harness excludes them via .git/info/exclude, but | ||
| # if an agent manages to stage them anyway, strip them here before push. | ||
| # --------------------------------------------------------------------------- | ||
| AGENT_ARTIFACT_PATTERNS=".agentready/ .fullsend-workspace/" | ||
| STRIPPED_FILES="" | ||
| for file in ${CHANGED_FILES}; do | ||
| is_artifact=false | ||
| for pattern in ${AGENT_ARTIFACT_PATTERNS}; do | ||
| dir="${pattern%/}" # strip trailing slash for prefix matching | ||
| case "${file}" in | ||
| "${dir}"/*|"${dir}") is_artifact=true; break ;; | ||
| */"${dir}"/*|*/"${dir}") is_artifact=true; break ;; | ||
| esac | ||
| done | ||
| if [ "${is_artifact}" = "true" ]; then | ||
| echo "::warning::Stripping agent artifact from commit: ${file}" | ||
| STRIPPED_FILES="${STRIPPED_FILES} ${file}" | ||
| fi | ||
| done | ||
|
|
||
| if [ -n "${STRIPPED_FILES}" ]; then | ||
| echo "::warning::Agent committed working directory artifacts — stripping before push" | ||
| # shellcheck disable=SC2086 | ||
| git rm --cached --quiet ${STRIPPED_FILES} | ||
| git commit --amend --no-edit | ||
|
|
||
| # Rebuild CHANGED_FILES without the stripped artifacts. | ||
| CLEAN_FILES="" | ||
| for file in ${CHANGED_FILES}; do | ||
| is_stripped=false | ||
| for sf in ${STRIPPED_FILES}; do | ||
| if [ "${file}" = "${sf}" ]; then | ||
| is_stripped=true | ||
| break | ||
| fi | ||
| done | ||
| if [ "${is_stripped}" = "false" ]; then | ||
| CLEAN_FILES="${CLEAN_FILES}${CLEAN_FILES:+ | ||
| }${file}" | ||
| fi | ||
| done | ||
| CHANGED_FILES="${CLEAN_FILES}" | ||
|
|
||
| if [ -z "${CHANGED_FILES}" ]; then | ||
| echo "::notice::All changed files were agent artifacts — nothing to push" | ||
| exit 0 | ||
| fi | ||
| fi | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # 3. Authoritative secret scan | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
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.
[low] variable-construction-idiom
The loop copies agentWorkingDirExcludes into a new lines slice without transformation. Simplify to payload := strings.Join(agentWorkingDirExcludes, newline) and remove the lines variable.