Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:23blocks OS Ai maestro Commit Trace Service

From Leeroopedia
Knowledge Sources
Domains Git_Introspection, Services
Last Updated 2026-10-26 18:00 GMT

Overview

Concrete tool for tracing a git commit back to the agent and session that made it, matching by sha, PR number, or commit subject across the mesh, provided by AI Maestro's `services/commit-trace-service.ts`.

Description

The commit-trace-service answers "which agent made this commit?" Three match strategies, strongest to weakest: `sha` (the session recorded this exact commit, confidence "exact"), `pr` (the commit on main is a squash "... (#528)"; the session opened or merged PR 528, confidence "likely"), `subject` (same first line of message, as in a rebase merge or cherry-pick, confidence "weak"). The service queries each host's agent commit index (`lib/commit-index`), merges results, lists unreachable hosts (down, not hidden), and supports a `local=1` mode for peer requests (no forwarding loop). It refreshes the agent's index on demand within a time budget, and warms unread transcripts out of the request. A rebase merge with a changed message, a PR opened from the GitHub UI, and non-Claude-Code sessions cannot be traced.

Usage

Call `traceCommit(query, deps)` for `GET /api/commits/<sha>` and `getAgentCommits(agentId)` for `GET /api/agents/<id>/commits`.

Code Reference

Source Location

  • Repository: ai-maestro
  • File: services/commit-trace-service.ts
  • Lines: L1-L496

Signature

export interface TraceMatch {
  hostId: string; agentId: string; agentName: string; sessionId: string
  via: 'sha' | 'pr' | 'subject'
  confidence: 'exact' | 'likely' | 'weak'
  role: 'committed' | 'opened' | 'merged'
  commits: TraceCommit[]; prs: TracePr[]
}

export interface TraceResult {
  query: string; shas: string[]; subject?: string; pr?: number
  matches: TraceMatch[]; unreachable: string[]; partial?: boolean
}

export interface TraceDeps { /* listAgents, ensureIndex, git, hostId, peers, fetchImpl, warm? */ }

export async function traceCommit(query: string, deps: TraceDeps): Promise<TraceResult>
export async function getAgentCommits(agentId: string): Promise<ServiceResult<...>>

Import

import { traceCommit, getAgentCommits, type TraceResult } from '@/services/commit-trace-service'

I/O Contract

Inputs

Name Type Required Description
query string Yes Commit sha (full or abbreviated) to trace
deps TraceDeps Yes Injected: listAgents, ensureIndex, git, hostId, peers, fetchImpl

Outputs

Name Type Description
TraceResult.matches TraceMatch[] Each match with confidence and role
TraceResult.unreachable string[] Hosts that were down
TraceResult.partial undefined Some transcripts could not be read in time

Usage Examples

Trace a commit

import { traceCommit } from '@/services/commit-trace-service'

const result = await traceCommit('abc1234', deps)
for (const match of result.matches) {
  console.log(`${match.agentName} ${match.role} (${match.confidence}) in session ${match.sessionId}`)
}

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment