Skip to content

Add option to manually attach a session#688

Draft
computermode wants to merge 8 commits intomainfrom
attach-session-id
Draft

Add option to manually attach a session#688
computermode wants to merge 8 commits intomainfrom
attach-session-id

Conversation

@computermode
Copy link
Contributor

@computermode computermode commented Mar 12, 2026

Summary

Adds a new attach command accessible via entire attach <session-id>. Enables users to retroactively capture an agent session that wasn't tracked (ie if the agent was created outside of the project's root directory).

The attach command allows for an optional -a or --agent flag to set the agent. It can auto-detect the agent type for sessions from Gemini and Claude. It also allows for a -f or --force flag that will append the agent session to the user's last commit message. Otherwise, the user has the option to either append or copy the checkpoint ID themselves via the dialog prompts.

Notes/known issues

  • session_turn_count defaults to 0 if we can't find it in the metadata. I don't believe we display the session turns in the UI (we display steps) so I don't believe this is presented to the user. That data is not always captured - not sure how big of a deal this is for the first pass through/version for this command.
  • Opencode sessions are already tracked by Entire when they're started from sub-folders. The attach command works for Opencode sessions that weren't tracked in the project folder (say, if Entire was enabled after Opencode was installed), but it won't detect Opencode sessions from folders outside the project. (attach doesn't care about folder location for other agents: this is isolated to Opencode atm)

Test plan

  • Unit tests for missing session ID, transcript not found, success path, duplicate session detection, and checkpoint ID output
  • Manual test: entire attach <real-session-id> with Claude sessions
  • Manual test: entire attach --force <session-id> amends the latest commit without prompting
  • Manual test: entire attach --agent gemini <session-id> with Gemini sessions
  • Manual test: entire attach --agent factoryai-droid <session-id> with Droid sessions
  • Manual test: entire attach --agent cursor <session-id> with Cursor sessions
  • Manual test: entire attach <gemini-session-id> with Gemini sessions
  • Checkpoints for Claude sessions are viewable in entire.io w/ all the proper metadata
  • Checkpoints for Gemini sessions are viewable in entire.io w/ all the proper metadata
  • Checkpoints for Factoryai-droid sessions are viewable in entire.io w/ all the proper metadata
  • Checkpoints for cursor sessions are viewable in entire.io w/ all the proper metadata
  • Verify entire rewind works on attach-created checkpoints

Copilot AI review requested due to automatic review settings March 12, 2026 18:02
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new entire attach <session-id> command to retroactively capture an agent session (from an existing transcript) and turn it into an Entire checkpoint + tracked session.

Changes:

  • Registers a new attach Cobra command and implements session attachment + checkpoint creation/condensation flow.
  • Adds transcript-path fallback logic to search Claude project directories when sessions were started from subdirectories.
  • Adds unit tests covering several attach scenarios (missing args, transcript missing, success path, duplicate session, output includes trailer).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 10 comments.

File Description
cmd/entire/cli/transcript.go Adds helper functions to locate session transcripts (including subdirectory search).
cmd/entire/cli/root.go Registers the new attach command on the root CLI.
cmd/entire/cli/attach.go Implements attach end-to-end: resolve transcript, extract files/prompt, save checkpoint, condense, optionally amend commit.
cmd/entire/cli/attach_test.go Introduces unit tests for attach behaviors and outputs.
Comments suppressed due to low confidence (1)

cmd/entire/cli/transcript.go:96

  • sanitizePathForSearch does not match Claude Code's SanitizePathForClaude behavior for non-ASCII paths (this implementation replaces each UTF-8 byte with '-', while SanitizePathForClaude replaces each non-alphanumeric rune once via regex). This can cause searchTranscriptInSubdirs to compute the wrong repoPrefix and fail to find transcripts for repos under paths containing non-ASCII characters. Prefer reusing the existing sanitizer (e.g., paths.SanitizePathForClaude / claudecode.SanitizePathForClaude) instead of duplicating the logic here.
}

// FindCheckpointUUID finds the UUID of the message containing the tool_result
// for the given tool_use_id. This is used to find the checkpoint point for
// transcript truncation when rewinding to a task.
// Returns the UUID and true if found, empty string and false otherwise.
func FindCheckpointUUID(transcript []transcriptLine, toolUseID string) (string, bool) {
	for _, line := range transcript {
		if line.Type != transcriptTypeUser {
			continue
		}

		var msg userMessageWithToolResults

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 5 changed files in this pull request and generated 5 comments.

computermode and others added 4 commits March 18, 2026 13:25
Add searchTranscriptInProjectDirs to search for session transcripts
across an agent's project directories when the primary lookup fails.
This handles cases where sessions were started from subdirectories
(different CWD hash). Also fix parameter shadowing of the transcript
package by renaming transcript params to lines, and remove the
now-unnecessary local type alias.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Entire-Checkpoint: 750296d02171
When a session's UserPromptSubmit hook doesn't fire (e.g. Factory AI
Droid exec mode), the TurnEnd handler now backfills prompt.txt by
extracting the first user prompt from the transcript. This ensures
checkpoint metadata includes the prompt even for agents that skip
hook invocations.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Entire-Checkpoint: 031fc80a52d1
Implement the `entire attach` command that imports an existing agent
session transcript into the Entire tracking system. Features include:

- Resolve transcripts across agent types (Claude Code, Gemini CLI,
  OpenCode, Cursor, Copilot CLI, Factory AI Droid)
- Auto-detect agent from transcript when --agent flag is wrong
- Normalize Gemini transcripts (convert content arrays to strings)
  while preserving all other fields
- Single-pass transcript metadata extraction (prompt, turns, model)
- Create checkpoint with file change detection
- Offer to amend the last commit with Entire-Checkpoint trailer
- Support --force flag for non-interactive use
- Depth-limited directory walking for transcript search fallback

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Entire-Checkpoint: 97c75100bbac
- Fix appendCheckpointTrailer false positive on body text containing
  ": " by using a strict git trailer regex (^[A-Za-z][A-Za-z0-9-]*: )
  instead of a loose strings.Contains check
- Return error explicitly when OpenRepository fails instead of
  silently continuing past the empty-repo guard
- Add debug logging in detectAgentByTranscript for failed agent
  attempts to aid troubleshooting
- Refactor runAttach into smaller helpers to resolve maintidx lint
  (validateAttachPreconditions, resolveAgentAndTranscript,
  collectFileChanges, storeTranscript, printAttachConfirmation)
- Wrap json.MarshalIndent return to resolve wrapcheck lint
- Remove unnecessary tt := tt loop variable capture (Go 1.22+)
- Add test case for body text with ": " not being treated as trailer

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Entire-Checkpoint: 23d9d11d11e7
computermode and others added 4 commits March 18, 2026 15:35
Address PR #688 review feedback by breaking up attach.go (669→459 lines)
and relocating misplaced concerns to their proper packages:

- Move trailer manipulation (AppendCheckpointTrailer, IsTrailerLine) to
  trailers package where other trailer operations live
- Move normalizeGeminiTranscript to geminicli.NormalizeTranscript since
  it's Gemini-specific transcript logic
- Extract transcript utilities (extractTranscriptMetadata,
  estimateSessionDuration) to attach_transcript.go
- Replace hardcoded agentSessionBaseDirs map with SessionBaseDirProvider
  optional interface on Agent, implemented by Claude Code, Gemini CLI,
  Cursor, and Factory AI Droid
- Fix storeTranscript parameter ordering: ctx first per Go convention
- Distinguish "detection failed" from "no changes found" in attach output
- Switch estimateSessionDuration from bytes.Split to bufio.Scanner
- Simplify resolveAndValidateTranscript by removing redundant agentName
  parameter

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Entire-Checkpoint: 475f14207459
…ogic

- Revert estimateSessionDuration from bufio.Scanner back to bytes.Split:
  Scanner has a 64KB default line limit that silently truncates large
  JSONL lines (tool results can easily exceed this). Since data is
  already in memory, bytes.Split has no memory overhead and no limit.
- Remove dual-context (ctx, logCtx) from collectFileChanges, matching
  the fix already applied to storeTranscript. No other function in the
  codebase takes two context parameters.
- Replace addCheckpointTrailer in manual_commit_hooks.go with a
  one-line delegation to trailers.AppendCheckpointTrailer, eliminating
  55 lines of duplicated trailer-appending logic.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Entire-Checkpoint: 874d71c3e4a0
Entire-Checkpoint: 7e8f69399bbe
Cursor and Factory AI Droid both use JSONL transcripts and support
GetSessionBaseDir for fallback transcript search, but had no attach
test coverage. Add tests verifying:
- Cursor flat layout attach (CLI-style <id>.jsonl)
- Cursor nested layout attach (IDE-style <id>/<id>.jsonl)
- Factory AI Droid flat layout attach

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Entire-Checkpoint: 5d90be021b38
@computermode computermode requested a review from Soph March 19, 2026 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants