@wipcomputer/wip-ai-devops-toolbox 1.9.20
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.
- package/.license-guard.json +7 -0
- package/.publish-skill.json +4 -0
- package/CHANGELOG.md +1120 -0
- package/CLA.md +19 -0
- package/DEV-GUIDE-GENERAL-PUBLIC.md +882 -0
- package/LICENSE +52 -0
- package/README.md +238 -0
- package/SKILL.md +728 -0
- package/TECHNICAL.md +282 -0
- package/UNIVERSAL-INTERFACE.md +180 -0
- package/_trash/RELEASE-NOTES-v1-8-0.md +29 -0
- package/_trash/RELEASE-NOTES-v1-8-1.md +7 -0
- package/_trash/RELEASE-NOTES-v1-8-2.md +7 -0
- package/_trash/RELEASE-NOTES-v1-9-0.md +37 -0
- package/_trash/RELEASE-NOTES-v1-9-1.md +38 -0
- package/_trash/RELEASE-NOTES-v1-9-10.md +40 -0
- package/_trash/RELEASE-NOTES-v1-9-2.md +40 -0
- package/_trash/RELEASE-NOTES-v1-9-6.md +72 -0
- package/_trash/RELEASE-NOTES-v1-9-7.md +23 -0
- package/_trash/RELEASE-NOTES-v1-9-9.md +75 -0
- package/_trash/guide 2/DEV-GUIDE.md +487 -0
- package/_trash/guide 2/scripts/deploy-public.sh +152 -0
- package/package.json +27 -0
- package/scripts/SKILL-deploy-public.md +61 -0
- package/scripts/SKILL-post-merge-rename.md +47 -0
- package/scripts/deploy-public.sh +264 -0
- package/scripts/post-merge-rename.sh +205 -0
- package/scripts/publish-skill.sh +134 -0
- package/tools/deploy-public/LICENSE +52 -0
- package/tools/deploy-public/README.md +31 -0
- package/tools/deploy-public/SKILL.md +71 -0
- package/tools/deploy-public/deploy-public.sh +264 -0
- package/tools/deploy-public/package.json +9 -0
- package/tools/ldm-jobs/LICENSE +52 -0
- package/tools/ldm-jobs/README.md +46 -0
- package/tools/ldm-jobs/backup.sh +16 -0
- package/tools/ldm-jobs/branch-protect.sh +39 -0
- package/tools/ldm-jobs/crystal-capture.sh +19 -0
- package/tools/ldm-jobs/setup-shell.sh +27 -0
- package/tools/ldm-jobs/visibility-audit.sh +27 -0
- package/tools/post-merge-rename/LICENSE +52 -0
- package/tools/post-merge-rename/README.md +29 -0
- package/tools/post-merge-rename/SKILL.md +57 -0
- package/tools/post-merge-rename/package.json +9 -0
- package/tools/post-merge-rename/post-merge-rename.sh +122 -0
- package/tools/wip-branch-guard/INSTALL.md +41 -0
- package/tools/wip-branch-guard/guard.mjs +259 -0
- package/tools/wip-branch-guard/package.json +11 -0
- package/tools/wip-file-guard/CHANGELOG.md +6 -0
- package/tools/wip-file-guard/LICENSE +52 -0
- package/tools/wip-file-guard/README.md +113 -0
- package/tools/wip-file-guard/REFERENCE.md +86 -0
- package/tools/wip-file-guard/SKILL.md +105 -0
- package/tools/wip-file-guard/guard.mjs +128 -0
- package/tools/wip-file-guard/openclaw.plugin.json +8 -0
- package/tools/wip-file-guard/package.json +27 -0
- package/tools/wip-file-guard/test.sh +119 -0
- package/tools/wip-license-guard/LICENSE +52 -0
- package/tools/wip-license-guard/README.md +32 -0
- package/tools/wip-license-guard/SKILL.md +65 -0
- package/tools/wip-license-guard/cli.mjs +464 -0
- package/tools/wip-license-guard/core.mjs +310 -0
- package/tools/wip-license-guard/hook.mjs +146 -0
- package/tools/wip-license-guard/package.json +15 -0
- package/tools/wip-license-hook/CHANGELOG.md +17 -0
- package/tools/wip-license-hook/LICENSE +52 -0
- package/tools/wip-license-hook/README.md +200 -0
- package/tools/wip-license-hook/SKILL.md +111 -0
- package/tools/wip-license-hook/dist/cli/index.d.ts +15 -0
- package/tools/wip-license-hook/dist/cli/index.js +170 -0
- package/tools/wip-license-hook/dist/cli/index.js.map +1 -0
- package/tools/wip-license-hook/dist/core/detector.d.ts +12 -0
- package/tools/wip-license-hook/dist/core/detector.js +104 -0
- package/tools/wip-license-hook/dist/core/detector.js.map +1 -0
- package/tools/wip-license-hook/dist/core/index.d.ts +4 -0
- package/tools/wip-license-hook/dist/core/index.js +5 -0
- package/tools/wip-license-hook/dist/core/index.js.map +1 -0
- package/tools/wip-license-hook/dist/core/ledger.d.ts +49 -0
- package/tools/wip-license-hook/dist/core/ledger.js +72 -0
- package/tools/wip-license-hook/dist/core/ledger.js.map +1 -0
- package/tools/wip-license-hook/dist/core/reporter.d.ts +14 -0
- package/tools/wip-license-hook/dist/core/reporter.js +227 -0
- package/tools/wip-license-hook/dist/core/reporter.js.map +1 -0
- package/tools/wip-license-hook/dist/core/scanner.d.ts +39 -0
- package/tools/wip-license-hook/dist/core/scanner.js +325 -0
- package/tools/wip-license-hook/dist/core/scanner.js.map +1 -0
- package/tools/wip-license-hook/hooks/pre-pull.sh +55 -0
- package/tools/wip-license-hook/hooks/pre-push.sh +51 -0
- package/tools/wip-license-hook/mcp-server.mjs +119 -0
- package/tools/wip-license-hook/package-lock.json +54 -0
- package/tools/wip-license-hook/package.json +43 -0
- package/tools/wip-license-hook/src/cli/index.ts +189 -0
- package/tools/wip-license-hook/src/core/detector.ts +130 -0
- package/tools/wip-license-hook/src/core/index.ts +4 -0
- package/tools/wip-license-hook/src/core/ledger.ts +116 -0
- package/tools/wip-license-hook/src/core/reporter.ts +255 -0
- package/tools/wip-license-hook/src/core/scanner.ts +367 -0
- package/tools/wip-license-hook/tsconfig.json +16 -0
- package/tools/wip-readme-format/README.md +49 -0
- package/tools/wip-readme-format/SKILL.md +84 -0
- package/tools/wip-readme-format/format.mjs +570 -0
- package/tools/wip-readme-format/package.json +15 -0
- package/tools/wip-release/CHANGELOG.md +42 -0
- package/tools/wip-release/LICENSE +52 -0
- package/tools/wip-release/README.md +45 -0
- package/tools/wip-release/REFERENCE.md +100 -0
- package/tools/wip-release/SKILL.md +139 -0
- package/tools/wip-release/cli.js +161 -0
- package/tools/wip-release/core.mjs +1174 -0
- package/tools/wip-release/mcp-server.mjs +109 -0
- package/tools/wip-release/package.json +36 -0
- package/tools/wip-repo-init/README.md +38 -0
- package/tools/wip-repo-init/SKILL.md +77 -0
- package/tools/wip-repo-init/init.mjs +142 -0
- package/tools/wip-repo-init/package.json +11 -0
- package/tools/wip-repo-permissions-hook/LICENSE +52 -0
- package/tools/wip-repo-permissions-hook/README.md +86 -0
- package/tools/wip-repo-permissions-hook/SKILL.md +73 -0
- package/tools/wip-repo-permissions-hook/cli.js +83 -0
- package/tools/wip-repo-permissions-hook/core.mjs +122 -0
- package/tools/wip-repo-permissions-hook/guard.mjs +64 -0
- package/tools/wip-repo-permissions-hook/mcp-server.mjs +92 -0
- package/tools/wip-repo-permissions-hook/openclaw.plugin.json +8 -0
- package/tools/wip-repo-permissions-hook/package.json +31 -0
- package/tools/wip-repos/LICENSE +52 -0
- package/tools/wip-repos/README.md +77 -0
- package/tools/wip-repos/SKILL.md +80 -0
- package/tools/wip-repos/cli.mjs +176 -0
- package/tools/wip-repos/core.mjs +290 -0
- package/tools/wip-repos/mcp-server.mjs +157 -0
- package/tools/wip-repos/package.json +34 -0
- package/tools/wip-universal-installer/CHANGELOG.md +57 -0
- package/tools/wip-universal-installer/LICENSE +52 -0
- package/tools/wip-universal-installer/README.md +81 -0
- package/tools/wip-universal-installer/REFERENCE.md +122 -0
- package/tools/wip-universal-installer/SKILL.md +87 -0
- package/tools/wip-universal-installer/SPEC.md +180 -0
- package/tools/wip-universal-installer/detect.mjs +130 -0
- package/tools/wip-universal-installer/examples/minimal/README.md +20 -0
- package/tools/wip-universal-installer/examples/minimal/SKILL.md +28 -0
- package/tools/wip-universal-installer/examples/minimal/cli.mjs +4 -0
- package/tools/wip-universal-installer/examples/minimal/core.mjs +8 -0
- package/tools/wip-universal-installer/examples/minimal/mcp-server.mjs +27 -0
- package/tools/wip-universal-installer/examples/minimal/package.json +12 -0
- package/tools/wip-universal-installer/install.js +930 -0
- package/tools/wip-universal-installer/package.json +36 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
#
|
|
3
|
+
# post-merge-rename.sh
|
|
4
|
+
# Scans for branches merged into main and renames them with --merged-YYYY-MM-DD.
|
|
5
|
+
# Branches already renamed (containing --merged-) are skipped.
|
|
6
|
+
# Never deletes branches. Only renames.
|
|
7
|
+
#
|
|
8
|
+
# Usage:
|
|
9
|
+
# bash post-merge-rename.sh # scan + rename all
|
|
10
|
+
# bash post-merge-rename.sh <branch> # rename a specific branch
|
|
11
|
+
# bash post-merge-rename.sh --dry-run # preview only
|
|
12
|
+
# bash post-merge-rename.sh <branch> --dry-run # preview specific branch
|
|
13
|
+
#
|
|
14
|
+
# Run this after merging a PR, or periodically to catch missed renames.
|
|
15
|
+
#
|
|
16
|
+
# Author: CC-mini (Opus 4.6)
|
|
17
|
+
# Date: 2026-03-08
|
|
18
|
+
|
|
19
|
+
set -euo pipefail
|
|
20
|
+
|
|
21
|
+
DRY_RUN=false
|
|
22
|
+
SPECIFIC_BRANCH=""
|
|
23
|
+
|
|
24
|
+
for arg in "$@"; do
|
|
25
|
+
case "$arg" in
|
|
26
|
+
--dry-run) DRY_RUN=true ;;
|
|
27
|
+
--help|-h)
|
|
28
|
+
echo "Usage: post-merge-rename.sh [<branch>] [--dry-run]"
|
|
29
|
+
echo ""
|
|
30
|
+
echo "Scans for branches merged into main and renames them"
|
|
31
|
+
echo "with --merged-YYYY-MM-DD suffix. Never deletes branches."
|
|
32
|
+
exit 0
|
|
33
|
+
;;
|
|
34
|
+
*) SPECIFIC_BRANCH="$arg" ;;
|
|
35
|
+
esac
|
|
36
|
+
done
|
|
37
|
+
|
|
38
|
+
# Must be in a git repo
|
|
39
|
+
if ! git rev-parse --is-inside-work-tree &>/dev/null; then
|
|
40
|
+
echo "Error: not inside a git repo."
|
|
41
|
+
exit 1
|
|
42
|
+
fi
|
|
43
|
+
|
|
44
|
+
# Fetch latest remote state
|
|
45
|
+
git fetch origin --prune 2>/dev/null || true
|
|
46
|
+
|
|
47
|
+
rename_branch() {
|
|
48
|
+
local branch="$1"
|
|
49
|
+
local trimmed
|
|
50
|
+
trimmed=$(echo "$branch" | sed 's/^[[:space:]]*//' | sed 's/[[:space:]]*$//')
|
|
51
|
+
|
|
52
|
+
# Skip main
|
|
53
|
+
[[ "$trimmed" == "main" || "$trimmed" == "master" ]] && return
|
|
54
|
+
|
|
55
|
+
# Skip already renamed
|
|
56
|
+
[[ "$trimmed" == *"--merged-"* ]] && return
|
|
57
|
+
|
|
58
|
+
# Skip current branch (can't rename the checked-out branch)
|
|
59
|
+
local current
|
|
60
|
+
current=$(git branch --show-current)
|
|
61
|
+
if [[ "$trimmed" == "$current" ]]; then
|
|
62
|
+
echo " SKIP $trimmed (currently checked out)"
|
|
63
|
+
return
|
|
64
|
+
fi
|
|
65
|
+
|
|
66
|
+
# Find merge date: when this branch's tip became reachable from main
|
|
67
|
+
local merge_date
|
|
68
|
+
merge_date=$(git log main --format="%ai" --ancestry-path "$(git merge-base main "$trimmed" 2>/dev/null)..main" 2>/dev/null | tail -1 | cut -d' ' -f1)
|
|
69
|
+
|
|
70
|
+
# Fallback: use the branch tip's own date
|
|
71
|
+
if [[ -z "$merge_date" ]]; then
|
|
72
|
+
merge_date=$(git log "$trimmed" -1 --format="%ai" 2>/dev/null | cut -d' ' -f1)
|
|
73
|
+
fi
|
|
74
|
+
|
|
75
|
+
if [[ -z "$merge_date" ]]; then
|
|
76
|
+
echo " SKIP $trimmed (could not determine merge date)"
|
|
77
|
+
return
|
|
78
|
+
fi
|
|
79
|
+
|
|
80
|
+
local new_name="${trimmed}--merged-${merge_date}"
|
|
81
|
+
|
|
82
|
+
if $DRY_RUN; then
|
|
83
|
+
echo " [dry-run] $trimmed -> $new_name"
|
|
84
|
+
else
|
|
85
|
+
echo " Renaming: $trimmed -> $new_name"
|
|
86
|
+
|
|
87
|
+
# Rename local
|
|
88
|
+
git branch -m "$trimmed" "$new_name" 2>/dev/null || true
|
|
89
|
+
|
|
90
|
+
# Push new name to remote
|
|
91
|
+
git push origin "$new_name" 2>/dev/null || true
|
|
92
|
+
|
|
93
|
+
# Remove old name from remote
|
|
94
|
+
git push origin --delete "$trimmed" 2>/dev/null || true
|
|
95
|
+
fi
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if [[ -n "$SPECIFIC_BRANCH" && "$SPECIFIC_BRANCH" != "--dry-run" ]]; then
|
|
99
|
+
# Rename a specific branch
|
|
100
|
+
echo "Checking branch: $SPECIFIC_BRANCH"
|
|
101
|
+
if git merge-base --is-ancestor "$SPECIFIC_BRANCH" main 2>/dev/null; then
|
|
102
|
+
rename_branch "$SPECIFIC_BRANCH"
|
|
103
|
+
else
|
|
104
|
+
echo " $SPECIFIC_BRANCH is NOT merged into main. Leaving as-is."
|
|
105
|
+
fi
|
|
106
|
+
else
|
|
107
|
+
# Scan all local branches merged into main
|
|
108
|
+
echo "Scanning for merged branches..."
|
|
109
|
+
merged=$(git branch --merged main | grep -v "^\*" | grep -v "main$" | grep -v "master$" | grep -v "\-\-merged\-" || true)
|
|
110
|
+
|
|
111
|
+
if [[ -z "$merged" ]]; then
|
|
112
|
+
echo " No unrenamed merged branches found. All clean."
|
|
113
|
+
exit 0
|
|
114
|
+
fi
|
|
115
|
+
|
|
116
|
+
while IFS= read -r branch; do
|
|
117
|
+
rename_branch "$branch"
|
|
118
|
+
done <<< "$merged"
|
|
119
|
+
fi
|
|
120
|
+
|
|
121
|
+
echo ""
|
|
122
|
+
echo "Done."
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# wip-branch-guard Installation
|
|
2
|
+
|
|
3
|
+
Add this hook to `~/.claude/settings.json` under `hooks.PreToolUse`:
|
|
4
|
+
|
|
5
|
+
```json
|
|
6
|
+
{
|
|
7
|
+
"matcher": "Write|Edit|NotebookEdit|Bash",
|
|
8
|
+
"hooks": [
|
|
9
|
+
{
|
|
10
|
+
"type": "command",
|
|
11
|
+
"command": "node /Users/lesa/.ldm/extensions/wip-branch-guard/guard.mjs",
|
|
12
|
+
"timeout": 5
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Then copy the guard to the extensions directory:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
mkdir -p ~/.ldm/extensions/wip-branch-guard
|
|
22
|
+
cp guard.mjs package.json ~/.ldm/extensions/wip-branch-guard/
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## What it does
|
|
26
|
+
|
|
27
|
+
Blocks ALL file writes and git commits when Claude Code is on main branch.
|
|
28
|
+
Agents must create a branch or use a worktree before editing anything.
|
|
29
|
+
|
|
30
|
+
## What it allows on main
|
|
31
|
+
|
|
32
|
+
- Read, Glob, Grep (read-only tools)
|
|
33
|
+
- git status, git log, git diff, git branch, git checkout, git pull, git merge, git push
|
|
34
|
+
- gh commands (issues, PRs, releases)
|
|
35
|
+
- Opening files in browser/mdview
|
|
36
|
+
|
|
37
|
+
## Test
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
node ~/.ldm/extensions/wip-branch-guard/guard.mjs --check
|
|
41
|
+
```
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// wip-branch-guard/guard.mjs
|
|
3
|
+
// PreToolUse hook for Claude Code.
|
|
4
|
+
// Blocks ALL file writes and git commits when on main branch.
|
|
5
|
+
// Agents must work on branches or worktrees. Never on main.
|
|
6
|
+
|
|
7
|
+
import { execSync } from 'node:child_process';
|
|
8
|
+
import { dirname } from 'node:path';
|
|
9
|
+
import { statSync } from 'node:fs';
|
|
10
|
+
|
|
11
|
+
// Tools that modify files or git state
|
|
12
|
+
const WRITE_TOOLS = new Set(['Write', 'Edit', 'NotebookEdit']);
|
|
13
|
+
const BASH_TOOL = 'Bash';
|
|
14
|
+
|
|
15
|
+
// Git commands that should be blocked on main
|
|
16
|
+
const BLOCKED_GIT_PATTERNS = [
|
|
17
|
+
/\bgit\s+commit\b/,
|
|
18
|
+
/\bgit\s+add\b/,
|
|
19
|
+
/\bgit\s+stash\b/,
|
|
20
|
+
/\bgit\s+reset\b/,
|
|
21
|
+
/\bgit\s+revert\b/,
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
// Git commands that are ALLOWED on main (read-only or merge operations)
|
|
25
|
+
const ALLOWED_GIT_PATTERNS = [
|
|
26
|
+
/\bgit\s+merge\b/,
|
|
27
|
+
/\bgit\s+pull\b/,
|
|
28
|
+
/\bgit\s+fetch\b/,
|
|
29
|
+
/\bgit\s+push\b/,
|
|
30
|
+
/\bgit\s+status\b/,
|
|
31
|
+
/\bgit\s+log\b/,
|
|
32
|
+
/\bgit\s+diff\b/,
|
|
33
|
+
/\bgit\s+branch\b/,
|
|
34
|
+
/\bgit\s+checkout\b/,
|
|
35
|
+
/\bgit\s+worktree\b/,
|
|
36
|
+
/\bgit\s+stash\s+drop\b/,
|
|
37
|
+
/\bgit\s+stash\s+list\b/,
|
|
38
|
+
/\bgit\s+remote\b/,
|
|
39
|
+
/\bgit\s+describe\b/,
|
|
40
|
+
/\bgit\s+tag\b/,
|
|
41
|
+
/\bgit\s+rev-parse\b/,
|
|
42
|
+
/\bgit\s+show\b/,
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
// Non-git bash commands that write files (common patterns)
|
|
46
|
+
const BLOCKED_BASH_PATTERNS = [
|
|
47
|
+
/\bcp\s+/,
|
|
48
|
+
/\bmv\s+/,
|
|
49
|
+
/\brm\s+/,
|
|
50
|
+
/\bmkdir\s+/,
|
|
51
|
+
/\btouch\s+/,
|
|
52
|
+
/\bnpm\s+link\b/,
|
|
53
|
+
/\bnpm\s+install\s+-g\b/,
|
|
54
|
+
/>\s/, // redirects
|
|
55
|
+
/\btee\s+/,
|
|
56
|
+
/\bsed\s+-i/,
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
// Allowed bash patterns (read-only operations, even though they match blocked patterns)
|
|
60
|
+
const ALLOWED_BASH_PATTERNS = [
|
|
61
|
+
/\bls\b/,
|
|
62
|
+
/\bcat\b/,
|
|
63
|
+
/\bhead\b/,
|
|
64
|
+
/\btail\b/,
|
|
65
|
+
/\bgrep\b/,
|
|
66
|
+
/\brg\b/,
|
|
67
|
+
/\bfind\b/,
|
|
68
|
+
/\bwc\b/,
|
|
69
|
+
/\becho\b/,
|
|
70
|
+
/\bcurl\b/,
|
|
71
|
+
/\bgh\s+(issue|pr|release|api)\b/,
|
|
72
|
+
/\bgh\s+pr\s+merge\b/,
|
|
73
|
+
/\bnode\s+-e\b/,
|
|
74
|
+
/\blsof\b/,
|
|
75
|
+
/\bopen\s+-a\b/,
|
|
76
|
+
/\bpwd\b/,
|
|
77
|
+
/--dry-run/,
|
|
78
|
+
/--help/,
|
|
79
|
+
/\bwip-release\b.*--dry-run/,
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
function deny(reason) {
|
|
83
|
+
const output = {
|
|
84
|
+
hookSpecificOutput: {
|
|
85
|
+
hookEventName: 'PreToolUse',
|
|
86
|
+
permissionDecision: 'deny',
|
|
87
|
+
permissionDecisionReason: reason,
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
process.stdout.write(JSON.stringify(output));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function findRepoRoot(filePath) {
|
|
94
|
+
// Walk up from a file path to find the git repo root
|
|
95
|
+
try {
|
|
96
|
+
let dir = filePath;
|
|
97
|
+
// If it's a file, start from its directory
|
|
98
|
+
try {
|
|
99
|
+
if (statSync(dir).isFile()) dir = dirname(dir);
|
|
100
|
+
} catch {
|
|
101
|
+
dir = dirname(dir); // File might not exist yet
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Use git rev-parse from the directory
|
|
105
|
+
const result = execSync('git rev-parse --show-toplevel 2>/dev/null', {
|
|
106
|
+
cwd: dir,
|
|
107
|
+
encoding: 'utf8',
|
|
108
|
+
timeout: 3000,
|
|
109
|
+
}).trim();
|
|
110
|
+
return result;
|
|
111
|
+
} catch {}
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function getCurrentBranch(cwd) {
|
|
116
|
+
try {
|
|
117
|
+
return execSync('git branch --show-current 2>/dev/null', {
|
|
118
|
+
cwd: cwd || process.cwd(),
|
|
119
|
+
encoding: 'utf8',
|
|
120
|
+
timeout: 3000,
|
|
121
|
+
}).trim();
|
|
122
|
+
} catch {
|
|
123
|
+
return null; // Not in a git repo
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function isInWorktree(cwd) {
|
|
128
|
+
try {
|
|
129
|
+
const gitDir = execSync('git rev-parse --git-dir 2>/dev/null', {
|
|
130
|
+
cwd: cwd || process.cwd(),
|
|
131
|
+
encoding: 'utf8',
|
|
132
|
+
timeout: 3000,
|
|
133
|
+
}).trim();
|
|
134
|
+
return gitDir.includes('/worktrees/');
|
|
135
|
+
} catch {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// CLI mode
|
|
141
|
+
if (process.argv.includes('--check')) {
|
|
142
|
+
const branch = getCurrentBranch();
|
|
143
|
+
const worktree = isInWorktree();
|
|
144
|
+
console.log(`Branch: ${branch || '(not in git repo)'}`);
|
|
145
|
+
console.log(`Worktree: ${worktree ? 'yes' : 'no'}`);
|
|
146
|
+
console.log(`Status: ${branch === 'main' || branch === 'master' ? 'BLOCKED (on main)' : 'OK'}`);
|
|
147
|
+
process.exit(branch === 'main' || branch === 'master' ? 1 : 0);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async function main() {
|
|
151
|
+
let raw = '';
|
|
152
|
+
for await (const chunk of process.stdin) {
|
|
153
|
+
raw += chunk;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
let input;
|
|
157
|
+
try {
|
|
158
|
+
input = JSON.parse(raw);
|
|
159
|
+
} catch {
|
|
160
|
+
process.exit(0);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const toolName = input.tool_name || '';
|
|
164
|
+
const toolInput = input.tool_input || {};
|
|
165
|
+
|
|
166
|
+
// Determine which repo to check.
|
|
167
|
+
// Claude Code always opens in .openclaw, but edits files in other repos.
|
|
168
|
+
// We need to check the branch of THE REPO THE FILE LIVES IN, not the CWD.
|
|
169
|
+
const filePath = toolInput.file_path || toolInput.filePath || '';
|
|
170
|
+
const command = toolInput.command || '';
|
|
171
|
+
|
|
172
|
+
// For Write/Edit: derive repo from the file path
|
|
173
|
+
// For Bash: try to extract repo path from the command (cd, or file paths in args)
|
|
174
|
+
let repoDir = null;
|
|
175
|
+
|
|
176
|
+
if (filePath) {
|
|
177
|
+
// Walk up from file path to find .git directory
|
|
178
|
+
repoDir = findRepoRoot(filePath);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (!repoDir && command) {
|
|
182
|
+
// Try to extract a path from the bash command
|
|
183
|
+
// Common patterns: cd "/path/to/repo" && ..., or paths in arguments
|
|
184
|
+
const cdMatch = command.match(/cd\s+["']?([^"'&|;]+?)["']?\s*(?:&&|;|$)/);
|
|
185
|
+
if (cdMatch) {
|
|
186
|
+
repoDir = findRepoRoot(cdMatch[1].trim());
|
|
187
|
+
}
|
|
188
|
+
// Also check for git -C /path/to/repo
|
|
189
|
+
const gitCMatch = command.match(/git\s+-C\s+["']?([^"'&|;]+?)["']?\s/);
|
|
190
|
+
if (!repoDir && gitCMatch) {
|
|
191
|
+
repoDir = findRepoRoot(gitCMatch[1].trim());
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Fall back to CWD
|
|
196
|
+
if (!repoDir) {
|
|
197
|
+
repoDir = process.env.CWD || process.cwd();
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Check if the target repo is on main
|
|
201
|
+
const branch = getCurrentBranch(repoDir);
|
|
202
|
+
if (!branch || (branch !== 'main' && branch !== 'master')) {
|
|
203
|
+
// Not on main, allow everything
|
|
204
|
+
process.exit(0);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// We're on main. Check if this is a write operation.
|
|
208
|
+
|
|
209
|
+
// Block Write/Edit tools entirely on main
|
|
210
|
+
if (WRITE_TOOLS.has(toolName)) {
|
|
211
|
+
deny(`BLOCKED: Cannot ${toolName} while on main branch. Create a branch first: git checkout -b cc-mini/your-feature. Or use a worktree.`);
|
|
212
|
+
process.exit(0);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// For Bash, check the command
|
|
216
|
+
if (toolName === BASH_TOOL && command) {
|
|
217
|
+
// First check if it's explicitly allowed (read-only)
|
|
218
|
+
for (const pattern of ALLOWED_BASH_PATTERNS) {
|
|
219
|
+
if (pattern.test(command)) {
|
|
220
|
+
process.exit(0);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Check for blocked git commands
|
|
225
|
+
for (const pattern of BLOCKED_GIT_PATTERNS) {
|
|
226
|
+
if (pattern.test(command)) {
|
|
227
|
+
// Make sure it's not an allowed git operation
|
|
228
|
+
let isAllowed = false;
|
|
229
|
+
for (const ap of ALLOWED_GIT_PATTERNS) {
|
|
230
|
+
if (ap.test(command)) { isAllowed = true; break; }
|
|
231
|
+
}
|
|
232
|
+
if (!isAllowed) {
|
|
233
|
+
deny(`BLOCKED: Cannot run "${command.substring(0, 60)}..." on main branch. Create a branch first.`);
|
|
234
|
+
process.exit(0);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// Check for file-writing bash commands
|
|
240
|
+
for (const pattern of BLOCKED_BASH_PATTERNS) {
|
|
241
|
+
if (pattern.test(command)) {
|
|
242
|
+
// Check it's not a read-only context
|
|
243
|
+
let isAllowed = false;
|
|
244
|
+
for (const ap of ALLOWED_BASH_PATTERNS) {
|
|
245
|
+
if (ap.test(command)) { isAllowed = true; break; }
|
|
246
|
+
}
|
|
247
|
+
if (!isAllowed) {
|
|
248
|
+
deny(`BLOCKED: Cannot run file-modifying command on main branch. Create a branch first.`);
|
|
249
|
+
process.exit(0);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Allow everything else (Read, Glob, Grep, Agent, etc.)
|
|
256
|
+
process.exit(0);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
main().catch(() => process.exit(0));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wipcomputer/wip-branch-guard",
|
|
3
|
+
"version": "1.9.20",
|
|
4
|
+
"description": "PreToolUse hook that blocks all writes on main branch. Forces agents to work on branches or worktrees.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "guard.mjs",
|
|
7
|
+
"bin": {
|
|
8
|
+
"wip-branch-guard": "guard.mjs"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT"
|
|
11
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
Dual License: MIT + AGPLv3
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 WIP Computer, Inc.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
1. MIT License (local and personal use)
|
|
7
|
+
---------------------------------------
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
SOFTWARE.
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
2. GNU Affero General Public License v3.0 (commercial and cloud use)
|
|
29
|
+
--------------------------------------------------------------------
|
|
30
|
+
|
|
31
|
+
If you run this software as part of a hosted service, cloud platform,
|
|
32
|
+
marketplace listing, or any network-accessible offering for commercial
|
|
33
|
+
purposes, the AGPLv3 terms apply. You must either:
|
|
34
|
+
|
|
35
|
+
a) Release your complete source code under AGPLv3, or
|
|
36
|
+
b) Obtain a commercial license.
|
|
37
|
+
|
|
38
|
+
This program is free software: you can redistribute it and/or modify
|
|
39
|
+
it under the terms of the GNU Affero General Public License as published
|
|
40
|
+
by the Free Software Foundation, either version 3 of the License, or
|
|
41
|
+
(at your option) any later version.
|
|
42
|
+
|
|
43
|
+
This program is distributed in the hope that it will be useful,
|
|
44
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
45
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
46
|
+
GNU Affero General Public License for more details.
|
|
47
|
+
|
|
48
|
+
You should have received a copy of the GNU Affero General Public License
|
|
49
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
AGPLv3 for personal use is free. Commercial licenses available.
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
###### WIP Computer
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@wipcomputer/wip-file-guard) [](https://github.com/wipcomputer/wip-ai-devops-toolbox/blob/main/tools/wip-file-guard/guard.mjs) [](https://github.com/wipcomputer/wip-ai-devops-toolbox/blob/main/tools/wip-file-guard/openclaw.plugin.json) [](https://github.com/wipcomputer/wip-ai-devops-toolbox/blob/main/tools/wip-file-guard/guard.mjs) [](https://github.com/wipcomputer/wip-ai-devops-toolbox/blob/main/tools/wip-file-guard/SKILL.md) [](https://github.com/wipcomputer/wip-ai-devops-toolbox/blob/main/tools/wip-universal-installer/SPEC.md)
|
|
4
|
+
|
|
5
|
+
# File Guard
|
|
6
|
+
|
|
7
|
+
PreToolUse hook that blocks destructive edits to protected files. When an AI agent tries to overwrite or strip content from files like CLAUDE.md, SHARED-CONTEXT.md, or SOUL.md... it gets blocked with a clear explanation of what went wrong.
|
|
8
|
+
|
|
9
|
+
## The Problem
|
|
10
|
+
|
|
11
|
+
AI agents replace content instead of extending it. After context compaction, behavioral rules like "don't delete things" vanish. The agent rewrites your CLAUDE.md, strips 30 lines from SHARED-CONTEXT.md, or replaces your SOUL.md with a shorter version. Every time.
|
|
12
|
+
|
|
13
|
+
File Guard is a technical guardrail. It doesn't ask the agent to be careful. It blocks the operation before it happens.
|
|
14
|
+
|
|
15
|
+
## How It Works
|
|
16
|
+
|
|
17
|
+
Two rules:
|
|
18
|
+
|
|
19
|
+
1. **Write is blocked** on protected files. Always. Use Edit instead.
|
|
20
|
+
2. **Edit is blocked** when it removes more than 2 net lines from a protected file.
|
|
21
|
+
|
|
22
|
+
The agent gets a deny message explaining what happened and telling it to re-read the file and add content instead of replacing it.
|
|
23
|
+
|
|
24
|
+
### Protected Files
|
|
25
|
+
|
|
26
|
+
| File | What it protects |
|
|
27
|
+
|------|-----------------|
|
|
28
|
+
| `CLAUDE.md` | Project instructions, boot sequence, system docs |
|
|
29
|
+
| `SHARED-CONTEXT.md` | Cross-agent shared state |
|
|
30
|
+
| `SOUL.md` | Agent identity |
|
|
31
|
+
| `IDENTITY.md` | Agent identity (alternate format) |
|
|
32
|
+
| `CONTEXT.md` | Current state snapshot |
|
|
33
|
+
| `TOOLS.md` | Tool and workflow rules |
|
|
34
|
+
| `MEMORY.md` | Persistent memory and preferences |
|
|
35
|
+
|
|
36
|
+
## Install
|
|
37
|
+
|
|
38
|
+
Open your AI coding tool and say:
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
Read the README at github.com/wipcomputer/wip-file-guard.
|
|
42
|
+
Then explain to me:
|
|
43
|
+
1. What is this tool?
|
|
44
|
+
2. What does it do?
|
|
45
|
+
3. What would it change or fix in our current system?
|
|
46
|
+
|
|
47
|
+
Then ask me:
|
|
48
|
+
- Do you have more questions?
|
|
49
|
+
- Do you want to integrate it into our system?
|
|
50
|
+
- Do you want to clone it (use as-is) or fork it (so you can contribute back if you find bugs)?
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Your agent will read the repo, explain the tool, and walk you through integration interactively.
|
|
54
|
+
|
|
55
|
+
Also see **[wip-release](https://github.com/wipcomputer/wip-release)** ... one-command release pipeline for agent-native software.
|
|
56
|
+
|
|
57
|
+
See [REFERENCE.md](REFERENCE.md) for manual install instructions (Claude Code, OpenClaw, CLI).
|
|
58
|
+
|
|
59
|
+
## Four Interfaces
|
|
60
|
+
|
|
61
|
+
One core, four interfaces into the same guard logic.
|
|
62
|
+
|
|
63
|
+
| Interface | File | What it does |
|
|
64
|
+
|-----------|------|-------------|
|
|
65
|
+
| **Core** | `guard.mjs` | Pure guard logic. Reads stdin JSON, decides allow/deny. |
|
|
66
|
+
| **Claude Code** | `guard.mjs` (PreToolUse hook) | Hooks into CC's PreToolUse event. Blocks before the edit happens. |
|
|
67
|
+
| **OpenClaw** | `openclaw.plugin.json` | Lifecycle hook for OpenClaw agents. Same rules, different runtime. |
|
|
68
|
+
| **CLI** | `guard.mjs --list`, `test.sh` | Testing and inspection from the command line. |
|
|
69
|
+
|
|
70
|
+
See [REFERENCE.md](REFERENCE.md) for customization (adding protected files, changing thresholds).
|
|
71
|
+
|
|
72
|
+
## Tests
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
bash test.sh
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
wip-file-guard tests
|
|
80
|
+
===================
|
|
81
|
+
|
|
82
|
+
PASS: Block Write to CLAUDE.md
|
|
83
|
+
PASS: Block Write to SHARED-CONTEXT.md
|
|
84
|
+
PASS: Allow Write to random file
|
|
85
|
+
PASS: Block Edit removing 5 lines from CLAUDE.md
|
|
86
|
+
PASS: Allow Edit adding lines to CLAUDE.md
|
|
87
|
+
PASS: Allow Edit on non-protected file (even removing lines)
|
|
88
|
+
PASS: Allow Edit with small removal (2 lines)
|
|
89
|
+
PASS: Block Edit with 4 line removal from SOUL.md
|
|
90
|
+
PASS: Block Write to IDENTITY.md
|
|
91
|
+
PASS: Block Write to TOOLS.md
|
|
92
|
+
|
|
93
|
+
Results: 10 passed, 0 failed
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Why This Exists
|
|
97
|
+
|
|
98
|
+
Context compaction erases behavioral rules. An agent that was told "never delete content from CLAUDE.md" forgets that instruction after compaction. It then proceeds to replace 50 lines with 10, confident it's improving the file.
|
|
99
|
+
|
|
100
|
+
This happened five times in one session. The fix isn't better prompting. It's a hook that blocks the operation before it executes. Behavioral rules degrade. Technical guards don't.
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## License
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
CLI, OpenClaw plugin, hooks MIT (use anywhere, no restrictions)
|
|
108
|
+
Hosted or cloud service use AGPL (network service distribution)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
AGPL for personal use is free.
|
|
112
|
+
|
|
113
|
+
Built by Parker Todd Brooks, Lēsa (OpenClaw, Claude Opus 4.6), Claude Code (Claude Opus 4.6).
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
###### WIP Computer
|
|
2
|
+
# wip-file-guard ... Reference
|
|
3
|
+
|
|
4
|
+
Manual install instructions, CLI usage, and customization.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
Install to your LDM OS home:
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
mkdir -p ~/.ldm/extensions/wip-file-guard
|
|
12
|
+
cp guard.mjs openclaw.plugin.json package.json ~/.ldm/extensions/wip-file-guard/
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
All config paths should point to the installed location (`~/.ldm/extensions/`), not the source repo.
|
|
16
|
+
|
|
17
|
+
## Claude Code
|
|
18
|
+
|
|
19
|
+
Add to `~/.claude/settings.json`:
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"hooks": {
|
|
24
|
+
"PreToolUse": [
|
|
25
|
+
{
|
|
26
|
+
"matcher": "Edit|Write",
|
|
27
|
+
"hooks": [
|
|
28
|
+
{
|
|
29
|
+
"type": "command",
|
|
30
|
+
"command": "node ~/.ldm/extensions/wip-file-guard/guard.mjs",
|
|
31
|
+
"timeout": 5
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## OpenClaw
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
cp -r ~/.ldm/extensions/wip-file-guard ~/.openclaw/extensions/wip-file-guard
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The `openclaw.plugin.json` registers a `before_tool_use` lifecycle hook that applies the same rules.
|
|
47
|
+
|
|
48
|
+
## CLI
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# List protected files
|
|
52
|
+
node guard.mjs --list
|
|
53
|
+
|
|
54
|
+
# Test the guard with a simulated input
|
|
55
|
+
echo '{"tool_name":"Write","tool_input":{"file_path":"/foo/CLAUDE.md"}}' | node guard.mjs
|
|
56
|
+
|
|
57
|
+
# Run the test suite
|
|
58
|
+
bash test.sh
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Customization
|
|
62
|
+
|
|
63
|
+
### Adding Protected Files
|
|
64
|
+
|
|
65
|
+
Edit the `PROTECTED` set in `guard.mjs`:
|
|
66
|
+
|
|
67
|
+
```javascript
|
|
68
|
+
const PROTECTED = new Set([
|
|
69
|
+
'CLAUDE.md',
|
|
70
|
+
'SHARED-CONTEXT.md',
|
|
71
|
+
'SOUL.md',
|
|
72
|
+
'IDENTITY.md',
|
|
73
|
+
'CONTEXT.md',
|
|
74
|
+
'TOOLS.md',
|
|
75
|
+
'MEMORY.md',
|
|
76
|
+
'YOUR-FILE-HERE.md', // add yours
|
|
77
|
+
]);
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Changing the Line Threshold
|
|
81
|
+
|
|
82
|
+
The default blocks edits that remove more than 2 net lines. Change the threshold in the Edit handler:
|
|
83
|
+
|
|
84
|
+
```javascript
|
|
85
|
+
if (removed > 2) { // change 2 to your threshold
|
|
86
|
+
```
|