feat(trace): local storage mode for AI coding sessions

Merged
MA
2mo ago
+2542-344

Refs PFM-7675

Summary

Chainloop Trace records an AI coding session and attests it to a control plane on git push. This PR adds a local storage mode. A repository records its sessions and stores the evidence on disk, with no control plane, login, or network.

The mode is a committed repository policy in .chainloop.yml:

  • traceStorage: CONTROL_PLANE (the default) or LOCAL.
  • tracePath: the trace directory, where Chainloop Trace keeps its data in every mode. The default is .git/chainloop-trace. A relative path starts at the root of the checkout.
  • traceRequired: replaces the deprecated requireTrace.

chainloop trace init --local sets up a repository with no control plane (R-008). --trace-path sets the trace directory and does not turn on local mode. trace init is a one-time setup for each repository. In a clone, the first traced session installs the git hooks, so a teammate does not run trace init.

When a control-plane trace init fails because the user is not authenticated, the error has a tip to run chainloop trace init --local.

In local mode, the pre-push hook runs the same assembly as a push (R-002, R-009). It writes each material under its content digest in the local-sessions folder of the trace directory (R-003). It also writes statement.json, the in-toto statement that a push would sign, with the chainloop.dev/attestation/v0.2 predicate. The statement has no envelope and no signature, so it is not an attestation (R-006). A failure to store a session blocks the push only when traceRequired is set.

chainloop trace run --local -- <command> stores one wrapped session the same way. trace run takes its settings from its flags and does not read traceStorage.

Secret redaction stays on by default, with a CHAINLOOP_TRACE_NO_REDACT opt-out for a trusted local store (R-004). Local mode opens no control-plane connection (R-005). A trace uninstall keeps the stored sessions. The session-start message names local mode and the directory of the stored sessions (R-012).

Implements the design in docs/specs/issue-3582-trace-evidence-export.md. Decision Record rows D-021 to D-024 record the changes from the PR review:

  • The statement replaces the manifest.json index.
  • tracePath sets the trace directory in every mode.
  • trace run has a --local flag.
  • A clone needs no trace init.

Refs #3582

Flow

  1. Set up the repository:
% chainloop trace init --local

Congratulations, your repository is initialized in local mode

  storage       local (no control plane)
  sessions      written to .git/chainloop-trace/local-sessions on each push
  harnesses     claude-code

What's next

  1. Commit these files. Every clone then uses local mode:
       git add .chainloop.yml .claude/settings.json
  2. Start claude-code and write some code
  3. Commit and push. The pre-push hook writes the session evidence to disk
  1. Start a session. The session-start message says:
Chainloop Trace is recording this session in local mode.
Chainloop Trace writes the session evidence to <repo>/.git/chainloop-trace/local-sessions when you push.
  1. Commit and push:
INF AI coding session evidence stored at <repo>/.git/chainloop-trace/local-sessions sessions=1
  1. The stored session:
.git/chainloop-trace/local-sessions/<session-id>/statement.json
.git/chainloop-trace/local-sessions/<session-id>/evidence/sha256-<digest>

A control-plane init with no login:

ERR authentication required, please run "chainloop auth login"
Tip: run "chainloop trace init --local" to configure it in local mode

AI disclosure: parts of this PR were written with Claude Code.