Class: Agent::Lock::CLI::Commands::Whoami

Inherits:
Base
  • Object
show all
Defined in:
lib/agent/lock/cli/commands/whoami.rb

Overview

Who a lock taken from here would say holds it, and who its parent is.

A sub-agent runs inside its parent's process, so nothing but the AGENT_ID it was told to use tells the two apart. A typo or a missing export puts its locks down under somebody else's name, where they block no sibling, and nothing says so. This is the check to run before the first claim: AGENT_ID=rey-frontend alock whoami.

It reads the environment and nothing else. No tree and no store, so asking the question can neither fail outside a checkout nor leave a store behind in one.

Constant Summary collapse

SOURCES =

Where #id came from, worded for a human. The keys are Identity's own symbols, which are what --json reports.

{
  explicit: "from AGENT_ID",
  session: "from CLAUDE_SESSION_ID",
  fingerprint: "from the process fingerprint"
}.freeze
PARENT_SOURCES =

Where #parent_id came from, likewise.

{
  explicit: "from AGENT_PARENT_ID",
  inferred: "inferred: the session this runs in, since AGENT_ID names somebody else"
}.freeze

Instance Attribute Summary

Attributes inherited from Base

#launcher

Instance Method Summary collapse

Methods inherited from Base

inherited, #initialize

Constructor Details

This class inherits a constructor from Agent::Lock::CLI::Commands::Base

Instance Method Details

#call(**options) ⇒ Object

Parameters:

  • options (Hash)


43
44
45
46
47
48
49
50
# File 'lib/agent/lock/cli/commands/whoami.rb', line 43

def call(**options)
  identity = Identity.current
  warn_shared(identity) unless identity.source == :explicit
  return say(JSON.pretty_generate(as_hash(identity))) if options[:json]

  say("id:     #{identity.id}  (#{SOURCES.fetch(identity.source)})")
  say(parent_line(identity))
end