rea
morluto
Reverse engineer anything with agents, from app behavior down to native binaries.
PROJECT TOPICS
INSTALL REFERENCE
dsh plugin --profile web add github:Grove-ovo/dsh-stack
该命令指向仓库当前默认分支;尚无绑定当前 commit 的完整验证结果。
PROJECT README
The Safety Rail & State Machine for GitHub Stacked PR Workflows in DeepSeek Harness.
English | 中文
dsh-stack is a Cordis plugin for DeepSeek Harness that enforces safety policies for multi-PR dependency workflows (Stacked PRs) within the dsh stack commands. Every sync, land, and cleanup goes through guards that are enforced by default and admit only explicit, narrowly-scoped exemptions (see --self-approve); SHA-bound validation records make "tested once" provable per commit. This is defense in depth on top of — not a replacement for — GitHub branch-protection rules (required checks, stale-review dismissal), which remain the enforcement layer for other tools and the web UI.
Imagine constructing a 3-story building with a stacked PR workflow:
Trunk (master)
└── PR #101 (feat/auth-db)
└── PR #102 (feat/auth-api)
└── PR #103 (feat/auth-ui)
When Floor 1 requires revisions during Code Review:
gh stack rebase / gh stack push then rewrites the affected upper commits and updates the remote branches."Sync Success" notification and reflexively click Merge.dsh-stack Saves YouGitHub's native gh stack provides the plumbing — gh stack rebase (cascade rebase after a base layer changes), gh stack push, and gh stack sync (fetch, reconcile, rebase if the trunk moved, and sync PR state). dsh-stack is the on-site safety inspector on top of that plumbing: it halts operations when the local working tree is dirty, re-runs local test suites on every layer touched by a rebase and binds the result to the exact commit tested, warns that approvals may need re-validation under your repository rules after SHA rewrites, polls GitHub for MERGED confirmation, and deletes branches only when the dependent count is verified to be zero — conditionally, so a branch that moved is retained.
dsh-stack works on top of the official GitHub CLI and gh-stack extension:
# 1. Ensure GitHub CLI is installed (>= 2.90.0 required)
gh --version
# 2. Install official GitHub gh-stack extension (>= 0.1.0 required)
gh extension install github/gh-stack
# 3. Authenticate with GitHub
gh auth login
[!NOTE] When running with a locally built DeepSeek Harness source checkout, ensure the monorepo has been built (
pnpm run build) before runningpnpm dsh webso that client web bundles are present.
From npm (recommended — prebuilt, no build permission needed):
dsh plugin --profile default add dsh-stack
From GitHub (installs sources and builds via prepare):
dsh plugin --profile default add github:Grove-ovo/dsh-stack
[!NOTE] pnpm ≥ 10 blocks a git dependency's build script until allowlisted. If the first
addfails, copy the exact package key pnpm prints intoallowBuildsunder your profile'spnpm-workspace.yaml($DSH_HOME/profiles/default/pnpm-workspace.yaml) and re-run. Pin a commit (github:Grove-ovo/dsh-stack#<sha>) for reproducible installs.
From a local checkout (development):
git clone https://github.com/Grove-ovo/dsh-stack.git
cd dsh-stack && pnpm install # `prepare` builds lib/
dsh plugin --profile default add ./dsh-stack
Configuring validation (optional):
By default every layer is validated with pnpm test (falling back to npm test). Projects using another runner configure it in the profile's cordis.patch.yml ($DSH_HOME/profiles/default/cordis.patch.yml):
- replace:
- id: stack
config:
validationCommand: ['pytest', '-q'] # executable + args as an array
validationTimeoutMs: 600000 # default 120000
Records are fingerprinted by the command: changing validationCommand invalidates previous validation records, so a layer must be re-verified under the new command before it can land.
Any install path activates the bundle automatically (the dsh.bundle manifest joins the profile layer stack), and dsh plugin --profile default remove dsh-stack removes it. Verify the composed profile:
dsh --profile default --dump-config | grep stack
dsh-stack enforces eight guard assertions across the PR lifecycle — binding by default for every operation routed through the plugin's commands, with only explicit, narrowly-scoped exemptions:
┌─────────────────────────────────────────────────────────────────────────┐
│ dsh-stack Guard System │
├───────────────┬─────────────────────────────────────────────────────────┤
│ 1. G-ENV │ Environment & Auth Guard: gh >= 2.90.0, extension >= 0.1.0│
│ 2. G-TREE │ Clean Worktree Guard: git status --porcelain pre-flight │
│ 3. G-TOPO │ Topology DAG Guard: no cross-forks, cycles, or orphans │
│ 4. G-TEST │ Rewritten Layer Guard: mandatory local test execution │
│ 5. G-VERIFY │ Validation-Record Guard: SHA-bound proof per layer │
│ 6. G-LAND │ Landing Eligibility Guard: CI green & Review Approved │
│ 7. G-POLL │ Merge Confirmation Guard: active polling of MERGED state│
│ 8. G-DEL │ Zero-Dependent Cleanup: strictly 0 open dependents │
└───────────────┴─────────────────────────────────────────────────────────┘
gh-stack extension ($\ge 0.1.0$), and active GraphQL authentication. Intercepts CLI recommendation prompts to prevent false-ready states.git status --porcelain. Aborts synchronization before rebasing if uncommitted modifications exist.pnpm test, fallback npm test; custom command and timeout configurable). Outcomes are written as SHA-bound validation records — a record is only valid for the exact head commit it was proven for. Restoration is best-effort and never silent: if the workspace could not be restored after validation, the failure is reported./stack-land refuses to merge any open layer without a passing record for its current head SHA. Missing, stale (head moved), or failed records each produce a distinct blocker; fix tests and re-run /stack-verify — no rebase or push needed.--self-approve for approvals) never hides violations of another category. Gracefully accommodates already-merged base PRs in the stack.MERGED before branch deletion. Stacked merges can enter GitHub's merge queue, so observed states (e.g. QUEUED) are reported instead of flattening "not yet merged" into a failure.--force-with-lease=<ref>:<expectedSha> and local deletes use update-ref -d <ref> <expectedSha>, so a branch that received commits after the merge (or between the check and the delete) is retained, not destroyed. Fails safe (retaining branches with warnings) if queries fail or return non-integer values. /stack-cleanup re-runs this pass idempotently for partial lands.| Command | Syntax | Role | Guards Enforced | Machine Output |
|---|---|---|---|---|
/stack-doctor |
/stack-doctor [--json] |
Health Check | G-ENV | DoctorOutputJson |
/stack |
/stack [pr...] [--json] |
Topology & Link | G-ENV, G-TOPO | StackOutputJson |
/stack-sync |
/stack-sync [--dry-run] [--json] |
Sync, Re-validate & Record | G-ENV, G-TREE, G-TEST | SyncOutputJson |
/stack-land |
/stack-land [--dry-run] [--limit <n>] [--self-approve] [--json] |
Guarded Ordered Merge | G-ENV, G-VERIFY, G-LAND, G-POLL, G-DEL | LandOutputJson / LandPreviewJson |
/stack-verify |
/stack-verify [--json] |
In-place Re-validation | G-ENV, G-TOPO, G-TEST | VerifyOutputJson |
/stack-cleanup |
/stack-cleanup [--json] |
Idempotent Branch Pruning | G-ENV, G-TOPO, G-DEL | CleanupOutputJson |
/stack-doctor (Environment Diagnostic)Runs an end-to-end audit of local tooling and network connectivity:
/stack-doctor
Output Example:
## Stack Doctor Diagnostic Report
| Component | Status | Details |
|---|---|---|
| GitHub CLI (gh) | ✅ Ready | `gh version 2.92.0 (2026-04-28)` |
| gh-stack Extension | ✅ Ready | `gh stack version 0.1.1` |
| Auth & API Status | ✅ Authenticated | User: `alice` |
/stack [pr...] (Stack Inspection & Linking)Visualizes PR dependencies as an ASCII DAG. Accepts space- or comma-separated PR numbers with optional # prefixes:
# Auto-detect from current git branch
/stack
# Link explicit PR chain
/stack 101 102 103
/stack #101, #102, #103
Output Example:
### 📦 GitHub Stack Topology (Trunk: `master`)
master (Trunk)
│
├─ #101 [feat/auth-db] (APPROVED | CI: SUCCESS)
│ │
│ └─ #102 [feat/auth-api] (APPROVED | CI: SUCCESS)
│ │
│ └─ #103 [feat/auth-ui] (CHANGES_REQUESTED | CI: PENDING)
/stack-sync (Sync, Re-validate & Record)Syncs the stack via gh stack sync (fetch, reconcile, rebase if the trunk moved, push), then re-runs local test suites on every touched layer and records the SHA-bound result:
# Preview rebase without touching git state
/stack-sync --dry-run
# Sync the stack, re-validate every touched layer, record results
/stack-sync
Output Example on Test Failure:
### 🛑 Sync Halted: Validation Failure on Layer #102
Branch `feat/auth-api` failed tests after rebase.
AssertionError: Token validation expected 200, received 401
**Safety Guard Triggered**: Fix test errors on branch `feat/auth-api` before landing.
/stack-land (Topological Merge & Safe Branch Cleanup)Merges PRs bottom-to-top, verifies MERGED status, and safely prunes branches with 0 dependents:
# Preview landing order (works even before approvals; guard findings are included in the preview)
/stack-land --dry-run
# Land only bottom 2 layers
/stack-land --limit 2
# Solo maintainer: waive the review-approval requirement explicitly (CI checks stay enforced)
/stack-land --self-approve
# Land complete stack
/stack-land
Output Example:
### 🚀 Official Stack Landed Successfully
Merged 2 PRs in order (limited from 3).
**Branch Cleanup Summary**:
- ✅ Deleted clean branch: `feat/auth-db`
- ⚠️ Retained branch: `feat/auth-api` (Branch "feat/auth-api" still has 1 open PR(s) depending on it.)
[!NOTE]
--self-approveexists because GitHub rejects self-approvals on your own PRs. It waives only the review-approval guard (CI, topology, validation-record, and merge-state checks remain enforced), prints a solo-maintainer warning banner, and setsselfApproved: truein--jsonoutput. Team repositories should rely on real peer review and never use this flag.
--json)Every command supports --json for integration into autonomous AI agents (such as DeepSeek Harness agents) or CI/CD pipelines:
/stack-doctor --json
/stack --json
/stack-sync --dry-run --json
/stack-land --limit 2 --json
/stack-verify --json
/stack-cleanup --json
/stack-land --dry-run --json never describes actions as performed. It returns a preview envelope with the verdict and the machine-coded reasons:
{
"mode": "preview",
"canLand": false,
"plannedPrNumbers": [101, 102],
"blockers": [{ "code": "GUARD_ERR_UNVERIFIED", "prNumber": 101, "message": "..." }],
"cleanupCandidates": ["feat/auth-api"],
"wouldRetain": ["feat/auth-db"]
}
Agents act on stable guard codes (GUARD_ERR_UNVERIFIED, GUARD_ERR_VALIDATION_STALE, GUARD_ERR_VALIDATION_FAILED, GUARD_ERR_CI_FAILED, GUARD_ERR_NOT_APPROVED, …) instead of parsing English error text.
The behaviors this plugin is held to (each covered by the test suite):
--dryrun, --limit 0) produce zero link/sync/merge/delete calls.--self-approve waives only review approvals; with any CI failure or missing/stale validation record, merge calls stay at zero./stack-land is blocked by the recorded failure; after /stack-verify passes, land proceeds. Merges never run without a passing record for the current head SHA./stack-cleanup completes pruning without re-merging and reports observed merge states instead of ambiguous timeouts.SyncOutputJson){
"ok": true,
"dryRun": false,
"trunk": "master",
"syncedLayers": [
{ "prNumber": 101, "headRef": "feat/auth-db", "newSha": "8a3f91c" },
{ "prNumber": 102, "headRef": "feat/auth-api", "newSha": "b4e120d" }
],
"validationResults": [
{ "prNumber": 101, "headRef": "feat/auth-db", "passed": true, "output": "Tests passed" },
{ "prNumber": 102, "headRef": "feat/auth-api", "passed": true, "output": "Tests passed" }
]
}
┌─────────────────────────────────────────────────────────┐
│ dsh UI / Agent │
│ Slash Commands: /stack, /stack-sync, ... │
└────────────────────────────┬────────────────────────────┘
│ CommandInvocation
┌────────────────────────────▼────────────────────────────┐
│ dsh-stack Runtime Engine │
│ ├── GuardEngine (8 Guard Assertions / Remediation) │
│ └── StackOrchestrator (DAG Parsing & State Machine) │
└────────────────────────────┬────────────────────────────┘
│ depends on interface
┌────────────────────────────▼────────────────────────────┐
│ GhClient Interface │
│ Decoupled abstraction for 100% testability │
└──────────────┬───────────────────────────┬──────────────┘
│ (Production) │ (Test Fixture)
┌──────────────▼─────────────┐ ┌───────────▼──────────────┐
│ ExecGhClient (execFile) │ │ MockGhClient (In-Memory)│
│ - child_process timeout │ │ - full test suite │
│ - AbortSignal propagation │ │ - 100% deterministic │
│ - robust checkout & fetch │ │ - 3-5 layer fixtures │
│ - Detached HEAD restore │ │ - instant mock polling │
│ - fail-safe cleanup pass │ └──────────────────────────┘
└────────────────────────────┘
Tests run on Node.js's native test runner; npm test builds lib/, runs a strict typecheck, then executes the full suite (tsdown and typescript are the only dev dependencies), so the package-entry assertions exercise the shipped artifact:
# Build lib/, typecheck, then run the full test suite
npm test
npm run test:node
# Run via Vitest (when working in parent monorepo context)
npm run test:vitest
What this plugin enforces — and, just as important, what it does not.
Trust model
gh (PRs, review decisions, check rollups). The plugin trusts these responses at query time; a state change between a check and a subsequent mutation is narrowed where practical (branch deletion is SHA-conditional) but not eliminated.Permissions & scope
link, sync/push, merge, branch deletion) require write access to the repository and are executed with your gh credentials.--self-approve is a scoped, auditable exemption for solo maintainers: it waives only the review-approval guard, is prominently flagged in output and JSON (selfApproved: true), and never waives CI, topology, or validation-record checks. Team repositories should rely on peer review.Known boundaries
/stack-cleanup for post-settlement pruning, but it does not drive the queue itself.gh operations.Reporting bugs: please open an issue with the command, the --json output, and your gh / gh-stack versions.
CLASSIFICATION EVIDENCE
系统优先读取 GitHub Topics,再与站内分类词典和词根规则比对。当前命中: deepseek。