Skip to main content

Module commit_attribution

Module commit_attribution 

Source
Expand description

Commit attribution utilities for tracking Claude’s contributions.

This module provides functionality to track and attribute file changes to Claude or human contributors for git commit attribution.

Structs§

AttributionData
Full attribution data for git notes JSON.
AttributionSnapshotMessage
Attribution snapshot message for persistence.
AttributionState
Attribution state for tracking Claude’s contributions to files.
AttributionSummary
Summary of Claude’s contribution for a commit.
FileAttribution
Per-file attribution details for git notes.
FileAttributionState
Per-file attribution state.
FileChange
File change for bulk tracking.
SessionBaseline
Session baseline for tracking file state at session start.
SurfaceBreakdown
Surface breakdown for attribution.

Enums§

FileChangeType

Functions§

attribution_restore_state_from_log
Restore attribution state from log snapshots on session resume.
build_surface_key
Build a surface key that includes the model name. Format: “surface/model” (e.g., “cli/claude-sonnet”)
calculate_commit_attribution
Calculate final attribution for staged files. Compares session baseline to committed state.
compute_content_hash
Compute SHA-256 hash of content.
create_empty_attribution_state
Create an empty attribution state for a new session.
expand_file_path
Expand a relative path to absolute path.
get_attribution_repo_root
Get the repo root for attribution operations. Uses get_cwd() which respects agent worktree overrides, then resolves to git root to handle cd subdir case. Falls back to get_original_cwd() if git root can’t be determined.
get_client_surface
Get the current client surface from environment.
get_file_mtime
Get a file’s modification time (mtimeMs), falling back to Date.now() if the file doesn’t exist.
get_repo_class_cached
Synchronously return the cached repo classification. Returns None if the async check hasn’t run yet.
get_staged_files
Get staged files from git.
increment_prompt_count
Increment promptCount and save an attribution snapshot. Used to persist the prompt count across compaction.
is_internal_model_repo
Check if the current repo is in the allowlist for internal model names. This is a placeholder - would need proper async integration.
is_internal_model_repo_cached
Synchronously return the cached result of is_internal_model_repo(). Returns false if the check hasn’t run yet (safe default: don’t leak).
normalize_file_path
Normalize file path to relative path from cwd for consistent tracking. Resolves symlinks to handle /tmp vs /private/tmp on macOS.
restore_attribution_state_from_snapshots
Restore attribution state from snapshot messages.
sanitize_model_name
Sanitize a model name to its public equivalent. Maps internal variants to their public names based on model family.
sanitize_surface_key
Sanitize a surface key to use public model names. Converts internal model variants to their public equivalents.
state_to_snapshot_message
Convert attribution state to snapshot message for persistence.
track_bulk_file_changes
Track multiple file changes in bulk.
track_file_creation
Track a file creation by Claude (e.g., via bash command). Used when Claude creates a new file through a non-tracked mechanism.
track_file_deletion
Track a file deletion by Claude (e.g., via bash rm command). Used when Claude deletes a file through a non-tracked mechanism.
track_file_modification
Track a file modification by Claude. Called after Edit/Write tool completes.