From 302e14cf2738b22f10c1545b24252d0e17e16687 Mon Sep 17 00:00:00 2001 From: mayor Date: Fri, 2 Jan 2026 00:10:55 -0800 Subject: [PATCH] feat(prime): Add session metadata output for seance discovery MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New outputSessionMetadata() function prints a structured line at prime start: [GAS TOWN] role:mayor pid:12345 session:abc-uuid-123 This enables gt seance to discover sessions from Claude transcripts, complementing the existing event emission to .events.jsonl. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- internal/cmd/prime.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/internal/cmd/prime.go b/internal/cmd/prime.go index 7a29b917..759e750d 100644 --- a/internal/cmd/prime.go +++ b/internal/cmd/prime.go @@ -118,6 +118,9 @@ func runPrime(cmd *cobra.Command, args []string) error { // Emit session_start event for seance discovery emitSessionEvent(ctx) + // Output session metadata for seance discovery + outputSessionMetadata(ctx) + // Output context if err := outputPrimeContext(ctx); err != nil { return err @@ -1523,3 +1526,28 @@ func emitSessionEvent(ctx RoleContext) { payload := events.SessionPayload(sessionID, actor, topic, ctx.WorkDir) events.LogFeed(events.TypeSessionStart, actor, payload) } + +// outputSessionMetadata prints a structured metadata line for seance discovery. +// Format: [GAS TOWN] role: pid: session: +// This enables gt seance to discover sessions from gt prime output. +func outputSessionMetadata(ctx RoleContext) { + if ctx.Role == RoleUnknown { + return + } + + // Get agent identity for the role field + actor := getAgentIdentity(ctx) + if actor == "" { + return + } + + // Get session ID from environment (set by Claude Code hooks) + sessionID := os.Getenv("CLAUDE_SESSION_ID") + if sessionID == "" { + // Fall back to a generated identifier + sessionID = fmt.Sprintf("%s-%d", actor, os.Getpid()) + } + + // Output structured metadata line + fmt.Printf("[GAS TOWN] role:%s pid:%d session:%s\n", actor, os.Getpid(), sessionID) +}