carson 2.33.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 83e70e6824d3de6da2d444aa9d0b2859f3710e357f87cdcf65cecc512ff63fee
4
- data.tar.gz: 6c09bd64199ab8ee6f7fa14722b670a123c7cb051ea2937c1e2bbfddb696fded
3
+ metadata.gz: 20f9db167969ae68e42a19efcc96c40108f4f3ab3f8b460369283457c9449e4b
4
+ data.tar.gz: 7e94bf5adcafdbd532bd6e789304e04c2a555b7adcbce441363e681a27493c25
5
5
  SHA512:
6
- metadata.gz: 3a6570b397a73c27aab1d33e044bd28f56d1f643e57e76b40d3bbd5cdd1ff5da2779467980c9f595c6a25cbe2524cf5ff6508050a2736677ebb94079434eb749
7
- data.tar.gz: 33d29172314ab043a5a38122b91fac3c150b3d846ef113cff953fefec5f56f8c35af1290a48ef951fe1154de4caf749cd779daf98c09c939518c0e64f7a72ecd
6
+ metadata.gz: 7bdc870e0ae003717b5e624d61386a41a89b5dcd20ec0e0c6fa5106b26791b53106bc43f763ca6199e79ca2bac8e76efcbff21d1ebbb126996550b009848f79f
7
+ data.tar.gz: 19dce95ec2fd4fc5a89de09f8e26b814e6b077285159d425639e68e635eda195d52171c7e388ce27efd27b685f7486e2fc6f8fcf0e7005407cdf672bb9c9f7a2
data/RELEASE.md CHANGED
@@ -5,6 +5,28 @@ Release-note scope rule:
5
5
  - `RELEASE.md` records only version deltas, breaking changes, and migration actions.
6
6
  - Operational usage guides live in `MANUAL.md` and `API.md`.
7
7
 
8
+ ## 3.0.0 — Agent-Oriented Carson
9
+
10
+ ### Theme
11
+
12
+ Carson is for coding agents. The primary consumer of Carson's commands, lifecycle management, and governance is the coding agent working on behalf of the developer. Carson 3.0 reorients the product around this truth.
13
+
14
+ ### What changed
15
+
16
+ - **`carson status` — agent session briefing.** One command to know the full state of the estate: current branch and dirty/sync state, active worktrees, open PRs with CI and review status, stale branches ready for pruning, and governance health. Supports `--json` for machine-readable structured output — agents can parse the response directly instead of scraping human text.
17
+ - **Deferred worktree cleanup model.** Worktrees are no longer expected to be deleted immediately after use. The new lifecycle: create a worktree, do work, mark it done, clean up later in batch via `carson housekeep` or `carson prune`. This eliminates the #1 agent session crash: worktree directory disappearing while the agent's shell CWD is inside it.
18
+ - **`docs/agent-orient.md` — the agent's needs document.** Written from the coding agent's authentic perspective: what it experiences, what friction exists, and what it needs Carson to become. This document guides all 3.0 development.
19
+
20
+ ### UX
21
+
22
+ - `carson status` prints a concise briefing by default. Silence is preserved — status reports only what needs attention.
23
+ - `carson status --json` produces a stable JSON schema for programmatic consumption.
24
+
25
+ ### Migration
26
+
27
+ - No breaking changes. All 2.x commands continue to work unchanged.
28
+ - `docs/plan.md` has been removed — superseded by `docs/agent-orient.md`.
29
+
8
30
  ## 2.33.0 — Safe Worktree Remove
9
31
 
10
32
  ### What changed
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.33.0
1
+ 3.0.0
data/lib/carson/cli.rb CHANGED
@@ -53,7 +53,7 @@ module Carson
53
53
 
54
54
  def self.build_parser
55
55
  OptionParser.new do |opts|
56
- opts.banner = "Usage: carson [setup [--remote NAME] [--main-branch NAME] [--workflow STYLE] [--merge METHOD] [--canonical PATH]|audit|sync|prune [--all]|worktree remove <name-or-path>|onboard [repo_path]|refresh [--all|repo_path]|offboard [repo_path]|template check|template apply|review gate|review sweep|govern [--dry-run] [--json] [--loop SECONDS]|version]"
56
+ opts.banner = "Usage: carson [status [--json]|setup [--remote NAME] [--main-branch NAME] [--workflow STYLE] [--merge METHOD] [--canonical PATH]|audit|sync|prune [--all]|worktree remove <name-or-path>|onboard [repo_path]|refresh [--all|repo_path]|offboard [repo_path]|template check|template apply|review gate|review sweep|govern [--dry-run] [--json] [--loop SECONDS]|version]"
57
57
  end
58
58
  end
59
59
 
@@ -88,6 +88,8 @@ module Carson
88
88
  parse_worktree_subcommand( argv: argv, parser: parser, err: err )
89
89
  when "review"
90
90
  parse_named_subcommand( command: command, usage: "gate|sweep", argv: argv, parser: parser, err: err )
91
+ when "status"
92
+ parse_status_command( argv: argv, err: err )
91
93
  when "govern"
92
94
  parse_govern_subcommand( argv: argv, err: err )
93
95
  else
@@ -228,6 +230,15 @@ module Carson
228
230
  { command: :invalid }
229
231
  end
230
232
 
233
+ def self.parse_status_command( argv:, err: )
234
+ json_flag = argv.delete( "--json" ) ? true : false
235
+ unless argv.empty?
236
+ err.puts "#{BADGE} Unexpected arguments for status: #{argv.join( ' ' )}"
237
+ return { command: :invalid }
238
+ end
239
+ { command: "status", json: json_flag }
240
+ end
241
+
231
242
  def self.parse_govern_subcommand( argv:, err: )
232
243
  options = {
233
244
  dry_run: false,
@@ -266,6 +277,8 @@ module Carson
266
277
  return Runtime::EXIT_ERROR if command == :invalid
267
278
 
268
279
  case command
280
+ when "status"
281
+ runtime.status!( json_output: parsed.fetch( :json, false ) )
269
282
  when "setup"
270
283
  runtime.setup!( cli_choices: parsed.fetch( :cli_choices, {} ) )
271
284
  when "audit"
@@ -0,0 +1,229 @@
1
+ # Agent session briefing — one command to know the full state of the estate.
2
+ # Gathers branch, working tree, worktrees, open PRs, stale branches,
3
+ # governance health, and version. Supports human-readable and JSON output.
4
+ module Carson
5
+ class Runtime
6
+ module Status
7
+ # Entry point for `carson status`. Collects estate state and reports.
8
+ def status!( json_output: false )
9
+ data = gather_status
10
+
11
+ if json_output
12
+ out.puts JSON.pretty_generate( data )
13
+ else
14
+ print_status( data: data )
15
+ end
16
+
17
+ EXIT_OK
18
+ end
19
+
20
+ private
21
+
22
+ # Collects all status facets into a structured hash.
23
+ def gather_status
24
+ data = {
25
+ version: Carson::VERSION,
26
+ branch: gather_branch_info,
27
+ worktrees: gather_worktree_info,
28
+ governance: gather_governance_info
29
+ }
30
+
31
+ # PR and stale branch data require gh — gather with graceful fallback.
32
+ if gh_available?
33
+ data[ :pull_requests ] = gather_pr_info
34
+ data[ :stale_branches ] = gather_stale_branch_info
35
+ end
36
+
37
+ data
38
+ end
39
+
40
+ # Branch name, clean/dirty state, sync status with remote.
41
+ def gather_branch_info
42
+ branch = current_branch
43
+ dirty = working_tree_dirty?
44
+ sync = remote_sync_status( branch: branch )
45
+
46
+ { name: branch, dirty: dirty, sync: sync }
47
+ end
48
+
49
+ # Returns true when the working tree has uncommitted changes.
50
+ def working_tree_dirty?
51
+ stdout, _, success, = git_run( "status", "--porcelain" )
52
+ return true unless success
53
+ !stdout.strip.empty?
54
+ end
55
+
56
+ # Compares local branch against its remote tracking ref.
57
+ # Returns :in_sync, :ahead, :behind, :diverged, or :no_remote.
58
+ def remote_sync_status( branch: )
59
+ remote = config.git_remote
60
+ remote_ref = "#{remote}/#{branch}"
61
+
62
+ # Check if the remote ref exists.
63
+ _, _, exists, = git_run( "rev-parse", "--verify", remote_ref )
64
+ return :no_remote unless exists
65
+
66
+ ahead_behind, _, success, = git_run( "rev-list", "--left-right", "--count", "#{branch}...#{remote_ref}" )
67
+ return :unknown unless success
68
+
69
+ parts = ahead_behind.strip.split( /\s+/ )
70
+ ahead = parts[ 0 ].to_i
71
+ behind = parts[ 1 ].to_i
72
+
73
+ if ahead.zero? && behind.zero?
74
+ :in_sync
75
+ elsif ahead.positive? && behind.zero?
76
+ :ahead
77
+ elsif ahead.zero? && behind.positive?
78
+ :behind
79
+ else
80
+ :diverged
81
+ end
82
+ end
83
+
84
+ # Lists all worktrees with branch and lifecycle state.
85
+ def gather_worktree_info
86
+ entries = worktree_list
87
+ # Filter out the main worktree (the repository root itself).
88
+ entries.reject { |wt| wt.fetch( :path ) == repo_root }.map do |wt|
89
+ {
90
+ path: wt.fetch( :path ),
91
+ name: File.basename( wt.fetch( :path ) ),
92
+ branch: wt.fetch( :branch, nil )
93
+ }
94
+ end
95
+ end
96
+
97
+ # Queries open PRs via gh.
98
+ def gather_pr_info
99
+ stdout, _, success, = gh_run(
100
+ "pr", "list", "--state", "open",
101
+ "--json", "number,title,headRefName,statusCheckRollup,reviewDecision"
102
+ )
103
+ return [] unless success
104
+
105
+ prs = JSON.parse( stdout ) rescue []
106
+ prs.map do |pr|
107
+ ci = summarise_checks( rollup: pr[ "statusCheckRollup" ] )
108
+ review = pr[ "reviewDecision" ].to_s
109
+ review_label = review_decision_label( decision: review )
110
+
111
+ {
112
+ number: pr[ "number" ],
113
+ title: pr[ "title" ],
114
+ branch: pr[ "headRefName" ],
115
+ ci: ci,
116
+ review: review_label
117
+ }
118
+ end
119
+ end
120
+
121
+ # Summarises check rollup into a single status word.
122
+ def summarise_checks( rollup: )
123
+ entries = Array( rollup )
124
+ return :none if entries.empty?
125
+
126
+ states = entries.map { |c| c[ "conclusion" ].to_s.upcase }
127
+ return :fail if states.any? { |s| s == "FAILURE" || s == "CANCELLED" || s == "TIMED_OUT" }
128
+ return :pending if states.any? { |s| s == "" || s == "PENDING" || s == "QUEUED" || s == "IN_PROGRESS" }
129
+
130
+ :pass
131
+ end
132
+
133
+ # Translates GitHub review decision to a concise label.
134
+ def review_decision_label( decision: )
135
+ case decision.upcase
136
+ when "APPROVED" then :approved
137
+ when "CHANGES_REQUESTED" then :changes_requested
138
+ when "REVIEW_REQUIRED" then :review_required
139
+ else :none
140
+ end
141
+ end
142
+
143
+ # Counts local branches that are stale (tracking a deleted upstream).
144
+ def gather_stale_branch_info
145
+ stdout, _, success, = git_run( "branch", "-vv" )
146
+ return { count: 0 } unless success
147
+
148
+ gone_branches = stdout.lines.select { |l| l.include?( ": gone]" ) }
149
+ { count: gone_branches.size }
150
+ end
151
+
152
+ # Quick governance health check: are templates in sync?
153
+ def gather_governance_info
154
+ result = with_captured_output { template_check! }
155
+ {
156
+ templates: result == EXIT_OK ? :in_sync : :drifted
157
+ }
158
+ rescue StandardError
159
+ { templates: :unknown }
160
+ end
161
+
162
+ # Prints the human-readable status report.
163
+ def print_status( data: )
164
+ puts_line "Carson #{data.fetch( :version )}"
165
+ puts_line ""
166
+
167
+ # Branch
168
+ branch = data.fetch( :branch )
169
+ dirty_marker = branch.fetch( :dirty ) ? " (dirty)" : ""
170
+ sync_marker = format_sync( sync: branch.fetch( :sync ) )
171
+ puts_line "Branch: #{branch.fetch( :name )}#{dirty_marker}#{sync_marker}"
172
+
173
+ # Worktrees
174
+ worktrees = data.fetch( :worktrees )
175
+ if worktrees.any?
176
+ puts_line ""
177
+ puts_line "Worktrees:"
178
+ worktrees.each do |wt|
179
+ branch_label = wt.fetch( :branch ) || "(detached)"
180
+ puts_line " #{wt.fetch( :name )} #{branch_label}"
181
+ end
182
+ end
183
+
184
+ # Pull requests
185
+ prs = data.fetch( :pull_requests, nil )
186
+ if prs && prs.any?
187
+ puts_line ""
188
+ puts_line "Pull requests:"
189
+ prs.each do |pr|
190
+ ci_label = pr.fetch( :ci ).to_s
191
+ review_label = pr.fetch( :review ).to_s.tr( "_", " " )
192
+ puts_line " ##{pr.fetch( :number )} #{pr.fetch( :title )}"
193
+ puts_line " CI: #{ci_label} Review: #{review_label}"
194
+ end
195
+ end
196
+
197
+ # Stale branches
198
+ stale = data.fetch( :stale_branches, nil )
199
+ if stale && stale.fetch( :count ) > 0
200
+ count = stale.fetch( :count )
201
+ puts_line ""
202
+ puts_line "#{count} stale branch#{plural_suffix( count: count )} ready for pruning."
203
+ end
204
+
205
+ # Governance
206
+ gov = data.fetch( :governance )
207
+ templates = gov.fetch( :templates )
208
+ unless templates == :in_sync
209
+ puts_line ""
210
+ puts_line "Templates: #{templates} — run `carson sync` to fix."
211
+ end
212
+ end
213
+
214
+ # Formats sync status for display.
215
+ def format_sync( sync: )
216
+ case sync
217
+ when :in_sync then ""
218
+ when :ahead then " (ahead of remote)"
219
+ when :behind then " (behind remote)"
220
+ when :diverged then " (diverged from remote)"
221
+ when :no_remote then " (no remote tracking)"
222
+ else ""
223
+ end
224
+ end
225
+ end
226
+
227
+ include Status
228
+ end
229
+ end
@@ -220,3 +220,4 @@ require_relative "runtime/audit"
220
220
  require_relative "runtime/review"
221
221
  require_relative "runtime/govern"
222
222
  require_relative "runtime/setup"
223
+ require_relative "runtime/status"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carson
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.33.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hailei Wang
@@ -67,6 +67,7 @@ files:
67
67
  - lib/carson/runtime/review/sweep_support.rb
68
68
  - lib/carson/runtime/review/utility.rb
69
69
  - lib/carson/runtime/setup.rb
70
+ - lib/carson/runtime/status.rb
70
71
  - lib/carson/version.rb
71
72
  - templates/.github/AGENTS.md
72
73
  - templates/.github/CLAUDE.md