@cleocode/git-shim

中文文档
2026.11.1发布于 2026/11/12MITTypeScriptES Module构建来源已验证近 30 天下载 1.2万

Harness-agnostic git shim for CLEO agent branch-protection (T1118)

原始使用文档
文档目录8 节
  1. Installation
  2. Activation gate
  3. Environment contract
  4. CLEO_ORCHESTRATE_MERGE=1 contract (T1587 / ADR-062 integrat…
  5. Bypass workflow
  6. Audit record schema
  7. Defense-in-depth pipeline
  8. References

@cleocode/git-shim

Part of CLEO. Start with the root README; run cleo <command> --help for any command.

Harness-agnostic git PATH override that fences agent (worker | lead | subagent) git invocations. Provides two layers of enforcement:

  1. T1118 denylist — branch-mutation operations (checkout, switch, branch -D, worktree add, reset --hard, rebase, push --force, etc.).
  2. T1591 boundary fence — contextual rules tied to the worktree-by-default model (ADR-055) + worktree-merge integration (ADR-062):
    • (a) git add MUST stage paths inside the active worktree.
    • (b) git commit -m "<msg>" MUST embed a CLEO task ID (T<NUM>).
    • (c) git merge MUST be invoked by completeAgentWorktreeViaMerge (signalled via CLEO_ORCHESTRATE_MERGE=1).
    • (d) git cherry-pick <ref> MUST NOT take a task/T<NUM> source (cherry-pick from worktree branches is the deprecated integration path superseded by ADR-062).

Every block and every bypass is recorded in <XDG_DATA_HOME ?? ~/.local/share>/cleo/audit/git-shim.jsonl.

Installation

The shim ships as the git bin entry of this package. The orchestrator materialises a git symlink inside <projectRoot>/.cleo/bin/ (or any shim directory) via installShimSymlink(...) and prepends that directory to the spawned agent's PATH.

Activation gate

The shim only enforces when the agent role is restricted:

CLEO_AGENT_ROLE=worker  # or lead, subagent

Orchestrators (the absence of CLEO_AGENT_ROLE or CLEO_AGENT_ROLE=orchestrator) bypass the shim entirely — this keeps orchestration code paths fast and unencumbered.

Environment contract

VariableSet byPurpose
CLEO_AGENT_ROLEorchestrator (spawn)Activates the fence for restricted roles.
CLEO_WORKTREE_ROOTorchestrator (spawn)Explicit worktree path; auto-detected from cwd otherwise.
CLEO_TASK_IDorchestrator (spawn)Active task ID; auto-derived from worktree path otherwise.
CLEO_ORCHESTRATE_MERGEcompleteAgentWorktreeViaMerge (T1587)Single-purpose grant — allows git merge. See below.
CLEO_ALLOW_BRANCH_OPSoperator (manual)Single-shot bypass for the legacy denylist. Audited.
CLEO_ALLOW_GIToperator (emergency)Universal bypass for any T1591 boundary block. Audited.
CLEO_AUDIT_LOG_PATHtestsOverride audit log location.
CLEO_REAL_GIT_PATHtestsSkip PATH walk; use this binary as real git.
CLEO_SHIM_MARKERinstaller (optional)Path-fragment that identifies the shim dir. Default: .cleo/bin/git-shim.

CLEO_ORCHESTRATE_MERGE=1 contract (T1587 / ADR-062 integration)

packages/core/src/spawn/branch-lock.ts::completeAgentWorktreeViaMerge is the only sanctioned entry point for git merge on a CLEO task branch. It MUST set CLEO_ORCHESTRATE_MERGE=1 in the env passed to the spawned git merge --no-ff process. The shim's boundary (c) refuses any other git merge invocation from a restricted role.

Concretely (see branch-lock.ts:830):

execFileSync('git', ['merge', '--no-ff', branch, '-m', subject], {
  cwd: gitRoot,
  encoding: 'utf-8',
  stdio: ['pipe', 'pipe', 'pipe'],
  env: { ...process.env, CLEO_ORCHESTRATE_MERGE: '1' },
});

If you discover a code path that needs to invoke git merge from restricted-role context other than completeAgentWorktreeViaMerge, file a follow-up task — do NOT silently set CLEO_ORCHESTRATE_MERGE=1 elsewhere. The narrow scope of this env var is what makes the boundary auditable.

--abort, --continue, and --quit flag invocations are exempt — they do not perform a merge.

Bypass workflow

For a legitimate emergency (e.g. operator hotfix, incident triage):

# One-off bypass; audit entry written to git-shim.jsonl.
CLEO_ALLOW_GIT=1 git <subcommand> ...

The bypass is logged with full context (subcommand, args, cwd, role, task_id, worktree_path). Reviewers can list bypasses via:

jq 'select(.outcome | startswith("bypassed"))' \
  ~/.local/share/cleo/audit/git-shim.jsonl

Audit record schema

interface AuditRecord {
  ts: string;                          // ISO 8601
  outcome: 'blocked' | 'bypassed-allow-git' | 'bypassed-orchestrate-merge';
  boundary: 'a' | 'b' | 'c' | 'd' | 'denylist';
  code: string;                        // E_GIT_OP_BLOCKED | E_GIT_BOUNDARY_*
  subcommand: string;
  args: string[];
  cwd: string;
  worktree_path: string | null;
  task_id: string | null;
  role: string | null;
  context: Record<string, string>;
}

The schema is project-agnostic: the audit log under ~/.local/share/cleo/audit/ is shared across every CLEO-managed project on the host.

Defense-in-depth pipeline

The git-binary fence (this package) is one layer in a multi-checkpoint pipeline:

LayerPackageCatches
Git binary@cleocode/git-shim (this)Direct git invocations from agents
Commit-msg hook@cleocode/core (T1588)Editor-flow commits (no inline -m)
Drift watchdog@cleocode/core (T1594)Files modified outside worktree
Pre-push reconcile@cleocode/core (T1595)Branch state drift before push
Sync linterCI (T1598)Review-time policy mismatches

Both T1588 (hook) and T1591 (shim, boundary b) enforce the commit-subject T-ID rule. This is intentional defense in depth: a developer who disables the local hook still trips the shim.

References

  • ADR-055 — worktree-by-default agent isolation
  • ADR-062 — worktree integration via git merge --no-ff (not cherry-pick)
  • T1118 — original branch-lock engine (denylist)
  • T1587 — completeAgentWorktreeViaMerge (sets CLEO_ORCHESTRATE_MERGE=1)
  • T1591 — this fence (boundary a/b/c/d)

版本与发布记录

@cleocode/git-shim 共发布 268 个版本,首次发布于 2026/04/23;过去 12 个月发布了 268 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2026.11.1latest2026/11/12今天
2026.11.1-rc.ci.711canary2026/11/12今天
2026.11.1-canary.122026/11/12今天
2026.11.1-canary.112026/11/12今天
2026.11.1-canary.102026/11/12今天
2026.11.1-canary.92026/11/111 天前

关于 @cleocode/git-shim 的常见问题

@cleocode/git-shim 是什么?

Harness-agnostic git shim for CLEO agent branch-protection (T1118)

如何安装 @cleocode/git-shim?

在项目目录运行 npm install @cleocode/git-shim,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 git,可以用 npx git 直接运行。

@cleocode/git-shim 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cleocode/git-shim 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@cleocode/git-shim 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24.16.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@cleocode/git-shim 可以商用吗?

@cleocode/git-shim 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cleocode/git-shim 的下载量有多少?

根据 npm 官方下载统计,@cleocode/git-shim 在 2026/10/10 – 2026/11/08 这 30 天内被下载 12,278 次,日均约 409 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cleocode/git-shim 还在维护吗?

最新版本 2026.11.1 发布于 2026/11/12(今天);至今共发布 268 个版本,其中过去 12 个月发布了 268 个;首次发布于 2026/04/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。