Skip to content

fix(trace): register checkouts that shell commands work in - #3623

Merged
jiparis merged 3 commits into
chainloop-dev:mainfrom
jiparis:jiparis/pfm-7614-trace-shell-commands-that-commit-in-another-checkout
Oct 14, 2026
Merged

jiparis merged 3 commits into
chainloop-dev:mainfrom
jiparis:jiparis/pfm-7614-trace-shell-commands-that-commit-in-another-checkout

Conversation

@jiparis

@jiparis jiparis commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

A traced session can work in a second checkout through shell commands only, for example in a fresh clone. Before this change, the trace did not see that checkout. Agent hooks run from the directory where the session started, so the clone got no git hooks, and its commits and pushes carried no session.

This change finds the checkout from the command text. The shell hooks read the command and get these directories from it:

  • the target of cd or pushd
  • the path of git -C
  • the folder that git clone or gh repo clone creates

The trace handles each directory the same as a file tool edit there: it installs the git hooks, records the session, and adds the checkout to the checkouts of the session. A hand-written tokenizer reads the command. This change adds no shell-parsing dependency.

Provider support:

  • Claude Code: supported.
  • OpenCode: supported. The plugin now sends the command text. A plugin installed by an earlier version must be installed again.
  • Cursor: partly supported, through the shell hooks from feat(trace): install the Cursor shell hooks #3624. These hooks are verified for the Cursor IDE only. A relative path in the command resolves against the first workspace root.

Known limit: when one shell call clones a repository and also commits in it, that commit does not carry the session. The clone does not exist before the call, so the git hooks are installed only after the call.

Closes #3533 (PFM-7614)

AI disclosure: this change was made with Claude Code.

A session that works in another checkout through shell commands only,
for example in a fresh clone, never registered that checkout. Agent
hooks run from the directory the session started in, so the clone got
no git hooks, and its commits and pushes carried no session.

The pre and post shell hooks now read the command text and find the
checkouts it names: the target of cd or pushd, the path of git -C, and
the folder that git clone or gh repo clone creates. Each one is handled
as a file tool edit there is: the git hooks are installed, the session
is recorded, and the checkout is added to the session's checkouts.

Claude Code and OpenCode send the command text. Cursor does not, as the
provider installs no shell hooks yet.

Refs: PFM-7614

Assisted-by: Claude Code
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>

Chainloop-Trace-Sessions: 2256cda0-6d1f-4a81-ae6a-f07a6a67c3dc
@chainloop-platform

chainloop-platform Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

PR validation — ✅ 3 passing

Status Policy Material Messages
✅ Passed pr-min-approvals pr-info -
✅ Passed pr-description-required pr-info -
✅ Passed pr-user-story-linked pr-info -

View attestation ↗

AI Session Checks — 🟢 89% · ✅ 0 failing

Avg score Sessions Failing policies Attribution Files Lines Total Duration
🟢 89% 1 ✅ 0 100% AI / 0% Human 13 +957 / -176 3h49m36s

🟢 89% — 100% AI — ✅ All policies passing

Oct 14, 2026 16:36 UTC · 3h49m36s · $19.74 · 520 in / 240.2k out · claude-code 2.1.299 (claude-opus-5-5)

View session details ↗

Change Summary

  • Adds shell-command checkout detection so work in other checkouts is tracked.
  • Extends OpenCode hook payloads and tests to carry command text for shell events.
  • Follows up on review findings with parser fixes for subshells, bare cd, env assignments, and README/lint cleanups.

AI Session Overall Score

🟢 89% — Strong implementation and verification; only the up-front planning lagged task scope.

AI Session Analysis Breakdown

🟢 95% · user-trust-signal

No notes.

🟢 93% · solution-quality

🟢 The AI fixed provider and parser logic instead of weakening checks or bypassing hooks. · High Impact

🟢 92% · alignment

🟢 Scope expansions were checked with the user before the AI moved beyond the original provider. · High Impact

🟢 91% · scope-discipline

No notes.

🟢 90% · verification

🟢 Targeted parser and scenario tests were rerun until the new behavior passed. · High Impact

🟡 72% · context-and-planning

🟠 Implementation, OpenCode, PR work, and review fixes proceeded without a shared plan or TODO. · Medium Severity

💡 Before a multi-step provider change, write a short visible plan with phases and stop points.


File Attribution

████████████████████ 100% AI / 0% Human

Status Attribution File Lines
modified ai app/cli/pkg/action/trace_command_dirs.go +551 / -126
modified ai app/cli/pkg/action/trace_shell_checkout_test.go +198 / -5
modified ai app/cli/pkg/action/trace_command_dirs_test.go +117 / -25
modified ai app/cli/pkg/action/trace_agent_hook.go +42 / -1
modified ai app/cli/internal/trace/claude/hooks_test.go +13 / -0
modified ai app/cli/internal/trace/opencode/hooks_test.go +8 / -5
modified ai app/cli/internal/trace/README.md +8 / -4
modified ai app/cli/internal/trace/opencode/hooks.go +7 / -4
modified ai app/cli/internal/trace/opencode/testdata/plugin_full.ts +3 / -2
modified ai app/cli/internal/trace/opencode/testdata/plugin_tracerun.ts +3 / -2
modified ai app/cli/pkg/action/trace_agent_hook_test.go +2 / -2
modified ai app/cli/internal/trace/provider.go +3 / -0
modified ai app/cli/internal/trace/claude/hooks.go +2 / -0

Policies (4)

Status Policy Material Messages
✅ Passed ai-config-ai-agents-allowed ai-coding-session-2256cd -
✅ Passed ai-config-no-dangerous-commands ai-coding-session-2256cd -
✅ Passed ai-config-no-secrets ai-coding-session-2256cd -
✅ Passed ai-config-mcp-servers-allowed ai-coding-session-2256cd -

Security Checks — ✅ 5 passing

✅ secret-scan

Status Policy Messages
✅ Passed secrets-detection -

✅ sast-scan

Status Policy Messages
✅ Passed owasp-top10-2025 -
✅ Passed sast -
✅ Passed cwe-top25 -
✅ Passed cwe-top26-40-cusp -
Scans not applied (3)
Scan Reason
vulnerability-scan no manifest/lockfile changed
github-actions-scan no workflow files changed
iac-scan no IaC files changed

View attestation ↗

Security context

This change touches code with 2 recorded security-fix advisories. These are pointers to what past fixes established, not findings in this diff, and they never fail the check.

View in Chainloop ↗ · How this works ↗


Powered by Chainloop and Chainloop Trace

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 13 files

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread app/cli/internal/trace/README.md Outdated
Comment thread app/cli/pkg/action/trace_command_dirs.go Outdated
Comment thread app/cli/pkg/action/trace_command_dirs.go Outdated
Comment thread app/cli/pkg/action/trace_command_dirs.go Outdated
@jiparis
jiparis requested a review from a team October 14, 2026 19:57
…ll dir detection

Address review findings on the command parser:

- A cd inside parentheses applies only until the closing parenthesis.
- A cd without arguments moves to the home directory.
- A leading assignment with an expansion in its value is skipped, so
  the command after it is still read.

Split the tokenizer into a small lexer type to bring its complexity
under the lint limit, and fix the other lint findings in the tests. The
trace README tells OpenCode users to install the hooks again.

Refs: PFM-7614

Assisted-by: Claude Code
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>

Chainloop-Trace-Sessions: 2256cda0-6d1f-4a81-ae6a-f07a6a67c3dc
Resolve the trace README conflicts with the Cursor shell hooks from
chainloop-dev#3624: take the upstream text for the Cursor rows. Cursor now sends the
command text through the same HookInput field, so the shell checkout
detection works for Cursor too. Rate it Partial, as the shell hooks are
verified for the IDE only and relative paths resolve against the first
workspace root. Cover OpenCode and Cursor in one table-driven test.

Refs: PFM-7614

Assisted-by: Claude Code
Signed-off-by: Jose I. Paris <jiparis@chainloop.dev>
@jiparis
jiparis merged commit 095b6ff into chainloop-dev:main Oct 14, 2026
17 checks passed
@jiparis
jiparis deleted the jiparis/pfm-7614-trace-shell-commands-that-commit-in-another-checkout branch October 14, 2026 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

trace: shell commands that commit in another checkout do not carry the session

2 participants