Class: Carson::Runtime

Inherits:
Object
  • Object
show all
Includes:
Abandon, Audit, Deliver, Housekeep, List, Local, LoopRunner, Receive, Recover, Review, Setup, Status
Defined in:
lib/carson/runtime.rb,
lib/carson/runtime.rb,
lib/carson/runtime/list.rb,
lib/carson/runtime/audit.rb,
lib/carson/runtime/local.rb,
lib/carson/runtime/setup.rb,
lib/carson/runtime/review.rb,
lib/carson/runtime/status.rb,
lib/carson/runtime/abandon.rb,
lib/carson/runtime/deliver.rb,
lib/carson/runtime/receive.rb,
lib/carson/runtime/recover.rb,
lib/carson/runtime/housekeep.rb,
lib/carson/runtime/local/sync.rb,
lib/carson/runtime/local/hooks.rb,
lib/carson/runtime/local/prune.rb,
lib/carson/runtime/loop_runner.rb,
lib/carson/runtime/local/onboard.rb,
lib/carson/runtime/local/template.rb,
lib/carson/runtime/local/worktree.rb,
lib/carson/runtime/review/utility.rb,
lib/carson/runtime/local/merge_proof.rb,
lib/carson/runtime/review/query_text.rb,
lib/carson/runtime/review/data_access.rb,
lib/carson/runtime/review/gate_support.rb,
lib/carson/runtime/review/sweep_support.rb

Defined Under Namespace

Modules: Abandon, Audit, Deliver, Housekeep, List, Local, LoopRunner, Receive, Recover, Review, Setup, Status

Constant Summary collapse

EXIT_OK =

Shared exit-code contract used by all commands and CI smoke assertions.

0
EXIT_ERROR =
1
EXIT_BLOCK =
2
REPORT_MD =
"pr_report_latest.md".freeze
REPORT_JSON =
"pr_report_latest.json".freeze
REVIEW_GATE_REPORT_MD =
"review_gate_latest.md".freeze
REVIEW_GATE_REPORT_JSON =
"review_gate_latest.json".freeze
REVIEW_SWEEP_REPORT_MD =
"review_sweep_latest.md".freeze
REVIEW_SWEEP_REPORT_JSON =
"review_sweep_latest.json".freeze
DISPOSITION_TOKENS =
%w[accepted rejected deferred].freeze

Constants included from LoopRunner

LoopRunner::LOOP_SLEEP_SLICE_SECONDS, LoopRunner::LOOP_STOP_SIGNALS

Constants included from Recover

Recover::GOVERNANCE_SURFACE_PREFIXES

Constants included from Deliver

Deliver::DELIVER_MERGE_ATTEMPT_CAP

Constants included from Setup

Setup::WELL_KNOWN_REMOTES

Constants included from Local

Local::SUPERSEDED, Local::TEMPLATE_SYNC_BRANCH

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Housekeep

#housekeep!, #housekeep_one_dry_run, #reap_dead_worktrees!, #reap_dead_worktrees_plan

Methods included from Recover

#recover!

Methods included from Receive

#receive!, #receive_cycle!, #receive_loop!

Methods included from Deliver

#deliver!

Methods included from Abandon

#abandon!

Methods included from Status

#status!

Methods included from Review

#review_gate!, #review_sweep!

Methods included from Setup

#setup!

Methods included from Local

#branch_absorbed_into_main?, #cwd_worktree_branch, #main_worktree_root, #merge_proof_for_branch, #merge_proof_for_remote_ref, #offboard!, #onboard!, #prune!, #prune_plan, #realpath_safe, #refresh!, #refresh_all!, #sweep_stale_worktrees!, #sync!, #template_apply!, #template_check!, #worktree_create!, #worktree_list, #worktree_list!, #worktree_remove!

Methods included from Audit

#audit!

Methods included from List

#list!

Constructor Details

#initialize(repo_root:, tool_root:, output:, error:, in_stream: $stdin, verbose: false, work_dir: nil) ⇒ Runtime

Runtime wiring for repository context, tool paths, and output streams. work_dir: the actual directory for git/gh command execution. When running from a worktree, this is the worktree path; repo_root remains the canonical main tree root for config, ledger, and path resolution.



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/carson/runtime.rb', line 29

def initialize( repo_root:, tool_root:, output:, error:, in_stream: $stdin, verbose: false, work_dir: nil )
	@repo_root = repo_root
	@work_dir = work_dir || repo_root
	@tool_root = tool_root
	@output = output
	@error = error
	@in = in_stream
	@verbose = verbose
	@config = Config.load( repo_root: repo_root )
	@git_adapter = Adapters::Git.new( repo_root: @work_dir )
	@github_adapter = Adapters::GitHub.new( repo_root: @work_dir )
	@template_sync_result = nil
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



54
55
56
# File 'lib/carson/runtime.rb', line 54

def config
  @config
end

#outputObject (readonly)

Returns the value of attribute output.



54
55
56
# File 'lib/carson/runtime.rb', line 54

def output
  @output
end

#template_sync_resultObject (readonly)

Returns the value of attribute template_sync_result.



43
44
45
# File 'lib/carson/runtime.rb', line 43

def template_sync_result
  @template_sync_result
end

Instance Method Details

#branch_record(name: current_branch) ⇒ Object

Passive branch record for the current checkout.



108
109
110
# File 'lib/carson/runtime.rb', line 108

def branch_record( name: current_branch )
	repository_record.branch( name ).reload
end

#current_headObject

Current branch head SHA for delivery identity.



95
96
97
# File 'lib/carson/runtime.rb', line 95

def current_head
	git_capture!( "rev-parse", "HEAD" ).strip
end

#git_capture!(*args) ⇒ Object

Captures git stdout and raises on non-zero exit.



240
241
242
243
244
245
246
247
# File 'lib/carson/runtime.rb', line 240

def git_capture!( *args )
	stdout_text, stderr_text, success, = git_run( *args )
	unless success
		error.print stderr_text unless stderr_text.empty?
		raise "git #{args.join( ' ' )} failed"
	end
	stdout_text
end

#git_run(*args) ⇒ Object

Low-level git invocation wrapper.



256
257
258
# File 'lib/carson/runtime.rb', line 256

def git_run( *args )
	git_adapter.run( *args )
end

#ledgerObject

Lazy ledger: only constructed when a command actually needs delivery state. Read-only commands (worktree list, audit, prune, sync) never touch the govern state lock file.



48
49
50
# File 'lib/carson/runtime.rb', line 48

def ledger
	@ledger ||= Ledger.new( path: @config.govern_state_path )
end

#puts_line(message) ⇒ Object

Single output funnel to keep messaging style consistent. Prefixes non-empty lines with the Carson badge (⧓).



131
132
133
134
135
136
137
# File 'lib/carson/runtime.rb', line 131

def puts_line( message )
	if message.to_s.strip.empty?
		output.puts ""
	else
		output.puts "#{BADGE} #{message}"
	end
end

#puts_verbose(message) ⇒ Object

Prints a line only when verbose mode is active.



68
69
70
# File 'lib/carson/runtime.rb', line 68

def puts_verbose( message )
	puts_line( message ) if verbose?
end

#repository_recordObject

Passive repository record for the current runtime context. Uses main_worktree_root so the repo_path stored in the ledger is always the canonical main tree path, regardless of which worktree the command runs from. This ensures receive (which looks up by main tree path) finds worktree deliveries.



103
104
105
# File 'lib/carson/runtime.rb', line 103

def repository_record
	Repository.new( path: main_worktree_root, runtime: self )
end

#verbose?Boolean

Returns true when full diagnostic output is enabled via –verbose.

Returns:

  • (Boolean)


63
64
65
# File 'lib/carson/runtime.rb', line 63

def verbose?
	@verbose
end