carson 3.20.0 → 3.21.1

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: 0e7fdc44d330fd415b8f6d9ee479d5256d6fc860e5d63c7c9287f28ebbdb2ba4
4
- data.tar.gz: 19056bd376bcab3b7077e38ba4e42f2b9f5a3ffbf2c8027f0aa6626bb70587fb
3
+ metadata.gz: 6e487779056ecbcf22d7aca1527c557051cd2ce94b31e030a515ffedcb8bbce5
4
+ data.tar.gz: 9cc271426a2c241d855f9a11d7b583e1bb0db2a8041e2972e8bdb3b7df4b55a7
5
5
  SHA512:
6
- metadata.gz: 13f0d5ac83272711329d435a935dd940afc461c5c3b10e20d23842492e8e53f7032cf34a8b027d70db80563af148cda5f99c2c8e7ec4025b94f4d72609ea9d1d
7
- data.tar.gz: b1903c6a8f8682adc7b942e49b553579d014d56c0bb65587465568119d41583a14e0cb4a7b00bc61b9165fac79094567395dbf2b39191e3c9d673dc0750dc4f5
6
+ metadata.gz: 1e9085ad4e193f0b0c09b5ea890bbbc708194c0ccaf9b5dea96e4daafa5b074f08790ac994d44fbcee3767641eb519cc97d4b05ae65bc29532a2c695a752807c
7
+ data.tar.gz: 2bc2779bde9dabc17a79c2e0668f370a8f8aecd9ee41bbb56c51ebedf394d1546e029f611a7ffc2072e496a4d01ade6e390157ca4b4468bdf220a1ac4bb99393
data/LICENSE CHANGED
@@ -1,21 +1,91 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Hailei Wang (WHL) <wanghailei@gmail.com>
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ # PolyForm Shield License 1.0.0
2
+
3
+ <https://polyformproject.org/licenses/shield/1.0.0>
4
+
5
+ Required Notice: Copyright (c) 2026 Hailei Wang (WHL) <wanghailei@gmail.com>
6
+
7
+ ## Acceptance
8
+
9
+ In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
10
+
11
+ ## Copyright License
12
+
13
+ The licensor grants you a copyright license for the software to do everything you might do with the software that would otherwise infringe the licensor's copyright in it for any permitted purpose. However, you may only distribute the software according to Distribution License and make changes or new works based on the software according to Changes and New Works License.
14
+
15
+ ## Distribution License
16
+
17
+ The licensor grants you an additional copyright license to distribute copies of the software. Your license to distribute covers distributing the software with changes and new works permitted by Changes and New Works License.
18
+
19
+ ## Notices
20
+
21
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with `Required Notice:` that the licensor provided with the software. For example:
22
+
23
+ > Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
24
+
25
+ ## Changes and New Works License
26
+
27
+ The licensor grants you an additional copyright license to make changes and new works based on the software for any permitted purpose.
28
+
29
+ ## Patent License
30
+
31
+ The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.
32
+
33
+ ## Noncompete
34
+
35
+ Any purpose is a permitted purpose, except for providing any product that competes with the software or any product the licensor or any of its affiliates provides using the software.
36
+
37
+ ## Competition
38
+
39
+ Goods and services compete even when they provide functionality through different kinds of interfaces or for different technical platforms. Applications can compete with services, libraries with plugins, frameworks with development tools, and so on, even if they're written in different programming languages or for different computer architectures. Goods and services compete even when provided free of charge. If you market a product as a practical substitute for the software or another product, it definitely competes.
40
+
41
+ ## New Products
42
+
43
+ If you are using the software to provide a product that does not compete, but the licensor or any of its affiliates brings your product into competition by providing a new version of the software or another product using the software, you may continue using versions of the software available under these terms beforehand to provide your competing product, but not any later versions.
44
+
45
+ ## Discontinued Products
46
+
47
+ You may begin using the software to compete with a product or service that the licensor or any of its affiliates has stopped providing, unless the licensor includes a plain-text line beginning with `Licensor Line of Business:` with the software that mentions that line of business. For example:
48
+
49
+ > Licensor Line of Business: YoyodyneCMS Content Management System (http://example.com/cms)
50
+
51
+ ## Sales of Business
52
+
53
+ If the licensor or any of its affiliates sells a line of business developing the software or using the software to provide a product, the buyer can also enforce Noncompete for that product.
54
+
55
+ ## Fair Use
56
+
57
+ You may have "fair use" rights for the software under the law. These terms do not limit them.
58
+
59
+ ## No Other Rights
60
+
61
+ These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.
62
+
63
+ ## Patent Defense
64
+
65
+ If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
66
+
67
+ ## Violations
68
+
69
+ The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.
70
+
71
+ ## No Liability
72
+
73
+ As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
74
+
75
+ ## Definitions
76
+
77
+ The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.
78
+
79
+ A **product** can be a good or service, or a combination of them.
80
+
81
+ **You** refers to the individual or entity agreeing to these terms.
82
+
83
+ **Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all its affiliates.
84
+
85
+ **Affiliates** means the other organizations than an organization has control over, is under the control of, or is under common control with.
86
+
87
+ **Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
88
+
89
+ **Your licenses** are all the licenses granted to you for the software under these terms.
90
+
91
+ **Use** means anything you do with the software requiring one of your licenses.
data/README.md CHANGED
@@ -6,13 +6,13 @@
6
6
 
7
7
  Named after the head of household in Downton Abbey, Carson is your repositories' autonomous governance runtime — you write the code, Carson manages everything else. From commit-time checks through PR triage, agent dispatch, merge, and cleanup, Carson runs the household with discipline and professional standards. Carson itself has no intelligence — it follows a deterministic decision tree. The intelligence comes from the coding agents it dispatches (Codex, Claude) to fix problems.
8
8
 
9
- ## The Problem to Solve
9
+ ## The Problem
10
10
 
11
11
  Managing a growing portfolio of repositories is rewarding work — but the operational overhead scales faster than the code itself. PR templates go stale, reviewer feedback gets quietly buried, and what passes on a developer's laptop fails in CI. When coding agents start producing PRs across multiple projects, the coordination load multiplies: checking results, dispatching fixes, clicking merge, cleaning up branches.
12
12
 
13
13
  Carson exists so you can focus on what matters — building — while governance runs itself.
14
14
 
15
- ## How Carson Works
15
+ ## What Carson Does
16
16
 
17
17
  Carson is an autonomous governance runtime that lives on your workstation and in CI, never inside the repositories it governs. It operates at two levels:
18
18
 
@@ -40,7 +40,7 @@ Carson orchestrates a closed governance loop across two layers:
40
40
 
41
41
  Carson's role is governance orchestration — gating on results and dispatching action. The actual CI runs and code fixes are delegated to specialised tools: GitHub Actions for CI and coding agents for remediation.
42
42
 
43
- ## Opinions
43
+ ### Principles
44
44
 
45
45
  Carson is opinionated about governance. These are non-negotiable principles, not configurable defaults:
46
46
 
@@ -51,6 +51,14 @@ Carson is opinionated about governance. These are non-negotiable principles, not
51
51
 
52
52
  Everything else bends to your preference. Which branch is main, how PRs are merged, which repositories to govern, which coding agent to dispatch — Carson asks during setup and remembers. Sensible defaults are provided; you only change what matters to you. See `MANUAL.md` for the full list.
53
53
 
54
+ ## When to Use Carson
55
+
56
+ - **You run coding agents across multiple repositories** and need a single command that triages every open PR, merges what's ready, dispatches agents to fix what's broken, and reports what needs your attention.
57
+ - **Your PR feedback gets buried.** Carson blocks merge until every reviewer comment is explicitly acknowledged — accepted, rejected, or deferred — so nothing is silently ignored.
58
+ - **CI breaks and nobody notices.** `carson audit` runs on every commit via managed hooks, and `carson govern` watches CI status across your portfolio continuously.
59
+ - **You onboard new repositories often** and want consistent hooks, templates, and governance from the first commit without manual setup.
60
+ - **You want agent-safe worktree management.** `carson worktree create` auto-syncs, branches, and isolates; `carson worktree remove` guards against unpushed work and active shells before cleanup.
61
+
54
62
  ## Quickstart
55
63
 
56
64
  Prerequisites: Ruby `>= 3.4`, `git`, and `gem` in your PATH. `gh` (GitHub CLI) is recommended for full review governance features.
data/RELEASE.md CHANGED
@@ -5,6 +5,26 @@ 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.21.1
9
+
10
+ ### What changed
11
+
12
+ - **Command guard false-positive fix** — the `command-guard` regex now matches `gh pr create/merge` only at command position (start of line or after `&&`, `||`, `;`, `|`). Previously it matched inside string arguments, blocking legitimate commands like `git commit -m 'Document gh pr create hook'`.
13
+
14
+ ## 3.21.0
15
+
16
+ ### What changed
17
+
18
+ - **Command guard for governed repositories** — Carson now detects and blocks raw `git push` and `gh pr create/merge` commands in governed repos, redirecting agents to `carson deliver` instead. Three enforcement layers:
19
+ - **Pre-push hook** — blocks raw `git push` in governed repos. Carson sets `CARSON_PUSH=1` internally so its own pushes pass through.
20
+ - **Command guard script** — a Claude Code `PreToolUse` hook that intercepts `gh pr create` and `gh pr merge` Bash commands in governed repos.
21
+ - **Existing pre-push guard** — the main/master branch push block now uses the same `BLOCKED` message format with explicit recovery guidance.
22
+ - **`with_env_var` helper** — new Runtime utility for temporarily setting environment variables with guaranteed cleanup.
23
+
24
+ ### UX improvement
25
+
26
+ - Agents that forget to use `carson deliver` are caught at push time or tool-call time with a clear message: what happened, why, and what to use instead. Born from scar: a preflight agent used raw `git push github main` and `gh pr create` in a governed repo, wasting work and requiring manual recovery (2026-03-09).
27
+
8
28
  ## 3.20.0
9
29
 
10
30
  ### What changed
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.20.0
1
+ 3.21.1
data/carson.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.summary = "Autonomous repository governance — you write the code, Carson manages everything else."
11
11
  spec.description = "Carson is a governance runtime that lives outside the repositories it governs — no Carson-owned artefacts in your repo. On every commit, managed hooks enforce centralised lint policy and review gates. At portfolio level, carson govern triages every open PR across your registered repositories: merge what's ready, dispatch coding agents to fix what's failing, escalate what needs human judgement. One command, all your projects, unmanned."
12
12
  spec.homepage = "https://github.com/wanghailei/carson"
13
- spec.license = "MIT"
13
+ spec.license = "PolyForm-Shield-1.0.0"
14
14
  spec.required_ruby_version = ">= 3.4"
15
15
  spec.metadata = {
16
16
  "source_code_uri" => "https://github.com/wanghailei/carson",
data/exe/carson CHANGED
@@ -5,9 +5,9 @@ $LOAD_PATH.unshift( File.expand_path( "../lib", __dir__ ) )
5
5
  require "carson"
6
6
 
7
7
  exit Carson::CLI.start(
8
- argv: ARGV.dup,
8
+ arguments: ARGV.dup,
9
9
  repo_root: Dir.pwd,
10
10
  tool_root: File.expand_path( "..", __dir__ ),
11
- out: $stdout,
12
- err: $stderr
11
+ output: $stdout,
12
+ error: $stderr
13
13
  )
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env bash
2
+ # Carson command guard — Claude Code PreToolUse hook.
3
+ #
4
+ # Blocks raw `gh pr create` and `gh pr merge` in Carson-governed repositories.
5
+ # Agents should use `carson deliver` instead.
6
+ #
7
+ # Claude Code sends JSON on stdin: {"tool_name": "Bash", "tool_input": {"command": "..."}}
8
+ # To block: print reason to stderr, exit 2.
9
+ # To allow: exit 0.
10
+ #
11
+ # Registration in ~/.claude/settings.json:
12
+ # "PreToolUse": [
13
+ # {
14
+ # "matcher": "Bash",
15
+ # "hooks": [
16
+ # {
17
+ # "type": "command",
18
+ # "command": "~/.carson/hooks/command-guard"
19
+ # }
20
+ # ]
21
+ # }
22
+ # ]
23
+ set -euo pipefail
24
+
25
+ # Read the tool call JSON from stdin.
26
+ input="$(cat)"
27
+
28
+ # Only inspect Bash tool calls.
29
+ tool_name="$(echo "$input" | jq -r '.tool_name // empty' 2>/dev/null)"
30
+ [ "$tool_name" = "Bash" ] || exit 0
31
+
32
+ command_text="$(echo "$input" | jq -r '.tool_input.command // empty' 2>/dev/null)"
33
+ [ -n "$command_text" ] || exit 0
34
+
35
+ # Check for gh pr commands that Carson replaces.
36
+ # Match only at command position: start of line, or after a shell operator (&&, ||, ;, |).
37
+ # This avoids false positives from gh pr references inside commit messages or string arguments.
38
+ guarded_pattern='(^|&&|\|\||;|\|)\s*gh\s+pr\s+(create|merge)'
39
+ if ! echo "$command_text" | grep -qE "$guarded_pattern"; then
40
+ exit 0
41
+ fi
42
+
43
+ # Check if the current directory is inside a governed repository.
44
+ config_file="${HOME}/.carson/config.json"
45
+ [ -f "$config_file" ] || exit 0
46
+
47
+ repo_root="$(git rev-parse --show-toplevel 2>/dev/null || echo "")"
48
+ [ -n "$repo_root" ] || exit 0
49
+
50
+ normalised="$(cd "$repo_root" && pwd -P)"
51
+ if ! grep -qF "\"$normalised\"" "$config_file" 2>/dev/null; then
52
+ exit 0
53
+ fi
54
+
55
+ # This is a raw gh pr command in a governed repo — block it.
56
+ echo "BLOCKED: raw \`gh pr create/merge\` in a Carson-governed repository." >&2
57
+ echo "Use \`carson deliver\` instead — it handles push, PR, and merge with safety guards." >&2
58
+ exit 2
data/hooks/pre-push CHANGED
@@ -1,23 +1,59 @@
1
1
  #!/usr/bin/env bash
2
+ # Carson pre-push hook — enforces push policy in governed repositories.
3
+ #
4
+ # Guards:
5
+ # 1. Blocks direct push to main/master refs.
6
+ # 2. Blocks raw git push in governed repos — agents must use `carson deliver`.
7
+ # Carson sets CARSON_PUSH=1 internally so its own pushes pass through.
8
+ #
9
+ # Bypass (emergency only): git push --no-verify
2
10
  set -euo pipefail
3
11
 
4
12
  hooks_dir="$(cd "$(dirname "$0")" && pwd)"
5
13
  style="$(cat "$hooks_dir/workflow_style" 2>/dev/null || echo "branch")"
6
14
  [ "$style" = "trunk" ] && exit 0
7
15
 
16
+ # --- Guard 1: block pushes to main/master refs ---
17
+
8
18
  remote_name="${1:-unknown}"
9
19
  remote_url="${2:-unknown}"
10
20
  has_commit_push=false
11
21
  while read -r local_ref local_sha remote_ref remote_sha; do
12
22
  case "$remote_ref" in
13
23
  refs/heads/main|refs/heads/master)
14
- echo "Carson policy: direct push to ${remote_ref#refs/heads/} is blocked on remote ${remote_name} (${remote_url}). Use a pull request." >&2
24
+ echo "BLOCKED: direct push to ${remote_ref#refs/heads/} is not allowed." >&2
25
+ echo "Use \`carson deliver\` instead — it handles push, PR, and merge with safety guards." >&2
26
+ echo "Bypass (emergency only): git push --no-verify" >&2
15
27
  exit 1
16
28
  ;;
17
29
  esac
18
30
  [[ "$local_sha" != "0000000000000000000000000000000000000000" ]] && has_commit_push=true
19
31
  done
20
32
 
33
+ # --- Guard 2: block raw git push in governed repos ---
34
+ # Carson sets CARSON_PUSH=1 when pushing internally via `deliver`.
35
+ # If the variable is absent, this is a raw git push from an agent or human.
36
+
37
+ if [[ -z "${CARSON_PUSH:-}" ]]; then
38
+ config_file="${HOME}/.carson/config.json"
39
+ if [[ -f "$config_file" ]]; then
40
+ repo_root="$(git rev-parse --show-toplevel 2>/dev/null || echo "")"
41
+ if [[ -n "$repo_root" ]]; then
42
+ # Check if this repo appears in govern.repos.
43
+ # Uses a simple grep against the JSON — no jq dependency required.
44
+ normalised="$(cd "$repo_root" && pwd -P)"
45
+ if grep -qF "\"$normalised\"" "$config_file" 2>/dev/null; then
46
+ echo "BLOCKED: raw \`git push\` in a Carson-governed repository." >&2
47
+ echo "Use \`carson deliver\` instead — it handles push, PR, and merge with safety guards." >&2
48
+ echo "Bypass (emergency only): git push --no-verify" >&2
49
+ exit 1
50
+ fi
51
+ fi
52
+ fi
53
+ fi
54
+
55
+ # --- Template sync on push ---
56
+
21
57
  if $has_commit_push; then
22
58
  if [[ -n "${CARSON_BIN:-}" ]]; then
23
59
  ruby "$CARSON_BIN" template apply --push-prep || exit 1
@@ -1,3 +1,4 @@
1
+ # Defines the WorkOrder and Result data structures for agent dispatch.
1
2
  module Carson
2
3
  module Adapters
3
4
  module Agent
@@ -1,8 +1,10 @@
1
+ # Dispatches coding work to the Claude Code CLI and parses its output.
1
2
  require "open3"
2
3
  require "json"
3
4
 
4
5
  module Carson
5
6
  module Adapters
7
+ # Adapter for dispatching work to Claude Code.
6
8
  class Claude
7
9
  include Prompt
8
10
 
@@ -1,8 +1,10 @@
1
+ # Dispatches coding work to the OpenAI Codex CLI and parses its output.
1
2
  require "open3"
2
3
  require "json"
3
4
 
4
5
  module Carson
5
6
  module Adapters
7
+ # Adapter for dispatching work to OpenAI Codex.
6
8
  class Codex
7
9
  include Prompt
8
10
 
@@ -1,7 +1,9 @@
1
+ # Executes git commands via Open3 and returns structured output.
1
2
  require "open3"
2
3
 
3
4
  module Carson
4
5
  module Adapters
6
+ # Thin wrapper around the git CLI. Runs commands via Open3.
5
7
  class Git
6
8
  def initialize( repo_root: )
7
9
  @repo_root = repo_root
@@ -1,7 +1,9 @@
1
+ # Executes gh CLI commands via Open3 for GitHub API access.
1
2
  require "open3"
2
3
 
3
4
  module Carson
4
5
  module Adapters
6
+ # Thin wrapper around the gh CLI for GitHub API access.
5
7
  class GitHub
6
8
  def initialize( repo_root: )
7
9
  @repo_root = repo_root
@@ -1,5 +1,7 @@
1
+ # Builds structured prompts for dispatching work orders to coding agents.
1
2
  module Carson
2
3
  module Adapters
4
+ # Builds structured prompts for coding agent dispatch.
3
5
  module Prompt
4
6
  private
5
7