@wipcomputer/wip-repo-permissions-hook 1.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.
- package/LICENSE +52 -0
- package/README.md +86 -0
- package/SKILL.md +73 -0
- package/cli.js +83 -0
- package/core.mjs +122 -0
- package/guard.mjs +64 -0
- package/mcp-server.mjs +92 -0
- package/openclaw.plugin.json +8 -0
- package/package.json +31 -0
package/LICENSE
ADDED
|
@@ -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.
|
package/README.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
###### WIP Computer
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@wipcomputer/wip-repo-permissions-hook) [](https://github.com/wipcomputer/wip-ai-devops-toolbox/blob/main/tools/wip-repo-permissions-hook/cli.js) [](https://github.com/wipcomputer/wip-ai-devops-toolbox/blob/main/tools/wip-repo-permissions-hook/mcp-server.mjs) [](https://github.com/wipcomputer/wip-ai-devops-toolbox/blob/main/tools/wip-repo-permissions-hook/openclaw.plugin.json) [](https://github.com/wipcomputer/wip-ai-devops-toolbox/blob/main/tools/wip-repo-permissions-hook/guard.mjs) [](https://github.com/wipcomputer/wip-ai-devops-toolbox/blob/main/tools/wip-repo-permissions-hook/SKILL.md) [](https://github.com/wipcomputer/wip-ai-devops-toolbox/blob/main/tools/wip-universal-installer/SPEC.md)
|
|
4
|
+
|
|
5
|
+
# wip-repo-permissions-hook
|
|
6
|
+
|
|
7
|
+
## Repo visibility guard. Blocks repos from going public without a -private counterpart.
|
|
8
|
+
|
|
9
|
+
Every repo follows the public/private pattern. The private repo is the working repo with `ai/` folders (plans, todos, dev updates). The public repo is the same code without `ai/`. Making a repo public without the -private counterpart exposes internal development context.
|
|
10
|
+
|
|
11
|
+
This tool blocks that.
|
|
12
|
+
|
|
13
|
+
## How It Works
|
|
14
|
+
|
|
15
|
+
Before any repo visibility change to public, the guard checks:
|
|
16
|
+
|
|
17
|
+
1. Is this a fork of an external project? If yes, allow (exempt).
|
|
18
|
+
2. Does `{repo-name}-private` exist on GitHub? If yes, allow.
|
|
19
|
+
3. Otherwise, block with an error.
|
|
20
|
+
|
|
21
|
+
## Surfaces
|
|
22
|
+
|
|
23
|
+
- **CLI** ... `wip-repo-permissions check|audit|can-publish`
|
|
24
|
+
- **Claude Code hook** ... PreToolUse:Bash, blocks `gh repo edit --visibility public`
|
|
25
|
+
- **OpenClaw plugin** ... before_tool_use lifecycle hook
|
|
26
|
+
- **Cron audit** ... periodic scan of all public repos via ldm-jobs
|
|
27
|
+
|
|
28
|
+
## CLI Usage
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# Check a single repo
|
|
32
|
+
node cli.js check wipcomputer/memory-crystal
|
|
33
|
+
# -> OK: memory-crystal-private exists
|
|
34
|
+
|
|
35
|
+
# Check a repo without -private (blocked)
|
|
36
|
+
node cli.js check wipcomputer/wip-bridge
|
|
37
|
+
# -> BLOCKED: no -private counterpart
|
|
38
|
+
|
|
39
|
+
# Audit all public repos in org
|
|
40
|
+
node cli.js audit wipcomputer
|
|
41
|
+
|
|
42
|
+
# Alias for check
|
|
43
|
+
node cli.js can-publish wipcomputer/wip-ai-devops-toolbox
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Claude Code Setup
|
|
47
|
+
|
|
48
|
+
Add to `~/.claude/settings.json`:
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
{
|
|
52
|
+
"hooks": {
|
|
53
|
+
"PreToolUse": [
|
|
54
|
+
{
|
|
55
|
+
"matcher": "Bash",
|
|
56
|
+
"hooks": [{
|
|
57
|
+
"type": "command",
|
|
58
|
+
"command": "node /path/to/wip-repo-permissions-hook/guard.mjs",
|
|
59
|
+
"timeout": 10
|
|
60
|
+
}]
|
|
61
|
+
}
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## OpenClaw Setup
|
|
68
|
+
|
|
69
|
+
Symlink or copy to extensions:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
cp -r tools/wip-repo-permissions-hook ~/.ldm/extensions/wip-repo-permissions-hook
|
|
73
|
+
ln -sf ~/.ldm/extensions/wip-repo-permissions-hook ~/.openclaw/extensions/wip-repo-permissions-hook
|
|
74
|
+
openclaw gateway restart
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## License
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
CLI, MCP server, OpenClaw plugin, hooks MIT (use anywhere, no restrictions)
|
|
81
|
+
Hosted or cloud service use AGPL (network service distribution)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
AGPL for personal use is free.
|
|
85
|
+
|
|
86
|
+
Built by Parker Todd Brooks, Lēsa (OpenClaw, Claude Opus 4.6), Claude Code (Claude Opus 4.6).
|
package/SKILL.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: wip-repo-permissions-hook
|
|
3
|
+
description: Repo visibility guard. Blocks repos from going public without a -private counterpart.
|
|
4
|
+
license: MIT
|
|
5
|
+
interface: [cli, module, mcp, hook, plugin]
|
|
6
|
+
metadata:
|
|
7
|
+
display-name: "Repo Visibility Guard"
|
|
8
|
+
version: "1.0.0"
|
|
9
|
+
homepage: "https://github.com/wipcomputer/wip-ai-devops-toolbox"
|
|
10
|
+
author: "Parker Todd Brooks"
|
|
11
|
+
category: dev-tools
|
|
12
|
+
capabilities:
|
|
13
|
+
- visibility-check
|
|
14
|
+
- org-audit
|
|
15
|
+
- public-gate
|
|
16
|
+
requires:
|
|
17
|
+
bins: [node, gh]
|
|
18
|
+
openclaw:
|
|
19
|
+
requires:
|
|
20
|
+
bins: [node, gh]
|
|
21
|
+
install:
|
|
22
|
+
- id: node
|
|
23
|
+
kind: node
|
|
24
|
+
package: "@wipcomputer/wip-repo-permissions-hook"
|
|
25
|
+
bins: [wip-repo-permissions]
|
|
26
|
+
label: "Install via npm"
|
|
27
|
+
emoji: "🔒"
|
|
28
|
+
compatibility: Requires node, gh (GitHub CLI). Node.js 18+.
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
# Repo Permissions Hook
|
|
32
|
+
|
|
33
|
+
## What This Does
|
|
34
|
+
|
|
35
|
+
Prevents repos from being made public unless a `-private` counterpart exists on GitHub. Protects internal plans, todos, and development context from accidental exposure.
|
|
36
|
+
|
|
37
|
+
## The Rule
|
|
38
|
+
|
|
39
|
+
Every repo that goes public must have a `{name}-private` repo. The private repo holds `ai/` folders with plans, todos, dev updates, and notes. The public repo has the same code without `ai/`.
|
|
40
|
+
|
|
41
|
+
Forks of external projects are exempt.
|
|
42
|
+
|
|
43
|
+
## How to Use
|
|
44
|
+
|
|
45
|
+
### Check before changing visibility
|
|
46
|
+
```bash
|
|
47
|
+
node cli.js check <org>/<repo>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Audit all public repos
|
|
51
|
+
```bash
|
|
52
|
+
node cli.js audit <org>
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Install as Claude Code hook
|
|
56
|
+
Add to `~/.claude/settings.json` under `hooks.PreToolUse` with matcher `"Bash"`.
|
|
57
|
+
|
|
58
|
+
### Install as OpenClaw plugin
|
|
59
|
+
Copy to `~/.ldm/extensions/wip-repo-permissions-hook/` and restart gateway.
|
|
60
|
+
|
|
61
|
+
### MCP
|
|
62
|
+
|
|
63
|
+
Tools: `repo_permissions_check`, `repo_permissions_audit`
|
|
64
|
+
|
|
65
|
+
Add to `.mcp.json`:
|
|
66
|
+
```json
|
|
67
|
+
{
|
|
68
|
+
"wip-repo-permissions": {
|
|
69
|
+
"command": "node",
|
|
70
|
+
"args": ["/path/to/tools/wip-repo-permissions-hook/mcp-server.mjs"]
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
```
|
package/cli.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* wip-repo-permissions-hook/cli.js
|
|
4
|
+
* CLI for repo visibility permissions.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* wip-repo-permissions check <org/repo> Check if repo can be public
|
|
8
|
+
* wip-repo-permissions audit <org> Audit all public repos
|
|
9
|
+
* wip-repo-permissions can-publish <org/repo> Alias for check
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { checkPrivateCounterpart, auditOrg } from './core.mjs';
|
|
13
|
+
|
|
14
|
+
const args = process.argv.slice(2);
|
|
15
|
+
const command = args[0];
|
|
16
|
+
const target = args[1];
|
|
17
|
+
|
|
18
|
+
function usage() {
|
|
19
|
+
console.log('wip-repo-permissions ... repo visibility guard\n');
|
|
20
|
+
console.log('Usage:');
|
|
21
|
+
console.log(' wip-repo-permissions check <org/repo> Check if repo can be made public');
|
|
22
|
+
console.log(' wip-repo-permissions audit <org> Audit all public repos in org');
|
|
23
|
+
console.log(' wip-repo-permissions can-publish <org/repo> Alias for check');
|
|
24
|
+
console.log('\nExamples:');
|
|
25
|
+
console.log(' wip-repo-permissions check wipcomputer/wip-bridge');
|
|
26
|
+
console.log(' wip-repo-permissions audit wipcomputer');
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!command || !target) usage();
|
|
31
|
+
|
|
32
|
+
switch (command) {
|
|
33
|
+
case 'check':
|
|
34
|
+
case 'can-publish': {
|
|
35
|
+
const parts = target.split('/');
|
|
36
|
+
if (parts.length !== 2) {
|
|
37
|
+
console.error('Error: target must be org/repo (e.g. wipcomputer/memory-crystal)');
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
const [org, repo] = parts;
|
|
41
|
+
const result = checkPrivateCounterpart(org, repo);
|
|
42
|
+
|
|
43
|
+
if (result.allowed) {
|
|
44
|
+
console.log(` OK: ${result.reason}`);
|
|
45
|
+
process.exit(0);
|
|
46
|
+
} else {
|
|
47
|
+
console.error(` ${result.reason}`);
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
case 'audit': {
|
|
54
|
+
const org = target;
|
|
55
|
+
console.log(`\nAuditing public repos in ${org}...\n`);
|
|
56
|
+
|
|
57
|
+
const { violations, ok } = auditOrg(org);
|
|
58
|
+
|
|
59
|
+
if (ok.length > 0) {
|
|
60
|
+
console.log(` Compliant (${ok.length}):`);
|
|
61
|
+
for (const r of ok) {
|
|
62
|
+
console.log(` OK ${r.name}`);
|
|
63
|
+
}
|
|
64
|
+
console.log('');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (violations.length > 0) {
|
|
68
|
+
console.log(` VIOLATIONS (${violations.length}):`);
|
|
69
|
+
for (const v of violations) {
|
|
70
|
+
console.log(` !! ${v.name} ... no -private counterpart`);
|
|
71
|
+
}
|
|
72
|
+
console.log('');
|
|
73
|
+
console.error(` ${violations.length} repo(s) are public without a -private counterpart.`);
|
|
74
|
+
process.exit(1);
|
|
75
|
+
} else {
|
|
76
|
+
console.log(' All public repos have -private counterparts (or are exempt forks).');
|
|
77
|
+
process.exit(0);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
default:
|
|
82
|
+
usage();
|
|
83
|
+
}
|
package/core.mjs
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* wip-repo-permissions-hook/core.mjs
|
|
3
|
+
* Pure logic for repo visibility permissions.
|
|
4
|
+
* Blocks repos from going public without a -private counterpart.
|
|
5
|
+
* Zero dependencies. Uses gh CLI for GitHub API calls.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { execFileSync } from 'node:child_process';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Check if a repo has a -private counterpart on GitHub.
|
|
12
|
+
* @param {string} org - GitHub org (e.g. "wipcomputer")
|
|
13
|
+
* @param {string} repoName - Repo name (e.g. "memory-crystal")
|
|
14
|
+
* @returns {{ allowed: boolean, reason: string }}
|
|
15
|
+
*/
|
|
16
|
+
export function checkPrivateCounterpart(org, repoName) {
|
|
17
|
+
// If the repo itself IS the private repo, allow
|
|
18
|
+
if (repoName.endsWith('-private')) {
|
|
19
|
+
return { allowed: true, reason: `${repoName} is already a private repo.` };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Check if it's a fork (forks of external projects are exempt)
|
|
23
|
+
const forkStatus = isThirdPartyFork(org, repoName);
|
|
24
|
+
if (forkStatus.isFork) {
|
|
25
|
+
return { allowed: true, reason: `${repoName} is a fork of ${forkStatus.parent}. Forks are exempt.` };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Check if -private counterpart exists
|
|
29
|
+
const privateName = `${repoName}-private`;
|
|
30
|
+
try {
|
|
31
|
+
execFileSync('gh', ['api', `repos/${org}/${privateName}`, '--jq', '.name'], {
|
|
32
|
+
encoding: 'utf8',
|
|
33
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
34
|
+
timeout: 10000,
|
|
35
|
+
});
|
|
36
|
+
return { allowed: true, reason: `${privateName} exists. ${repoName} can be public.` };
|
|
37
|
+
} catch {
|
|
38
|
+
return {
|
|
39
|
+
allowed: false,
|
|
40
|
+
reason: `BLOCKED: ${org}/${repoName} cannot be made public. No -private counterpart found (expected ${org}/${privateName}). Create the -private repo first, move all ai/ content there, then make this repo public.`,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Check if a repo is a fork of an external project.
|
|
47
|
+
* @param {string} org
|
|
48
|
+
* @param {string} repoName
|
|
49
|
+
* @returns {{ isFork: boolean, parent: string }}
|
|
50
|
+
*/
|
|
51
|
+
export function isThirdPartyFork(org, repoName) {
|
|
52
|
+
try {
|
|
53
|
+
const json = execFileSync('gh', ['api', `repos/${org}/${repoName}`, '--jq', '{fork: .fork, parent: .parent.full_name}'], {
|
|
54
|
+
encoding: 'utf8',
|
|
55
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
56
|
+
timeout: 10000,
|
|
57
|
+
});
|
|
58
|
+
const data = JSON.parse(json);
|
|
59
|
+
if (data.fork && data.parent && !data.parent.startsWith(`${org}/`)) {
|
|
60
|
+
return { isFork: true, parent: data.parent };
|
|
61
|
+
}
|
|
62
|
+
return { isFork: false, parent: '' };
|
|
63
|
+
} catch {
|
|
64
|
+
return { isFork: false, parent: '' };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Audit all public repos in an org for missing -private counterparts.
|
|
70
|
+
* @param {string} org
|
|
71
|
+
* @returns {{ violations: Array<{name: string, reason: string}>, ok: Array<{name: string, reason: string}> }}
|
|
72
|
+
*/
|
|
73
|
+
export function auditOrg(org) {
|
|
74
|
+
// Get all public repos
|
|
75
|
+
let repos;
|
|
76
|
+
try {
|
|
77
|
+
const json = execFileSync('gh', [
|
|
78
|
+
'repo', 'list', org,
|
|
79
|
+
'--visibility', 'public',
|
|
80
|
+
'--json', 'name',
|
|
81
|
+
'--limit', '200',
|
|
82
|
+
], { encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'], timeout: 30000 });
|
|
83
|
+
repos = JSON.parse(json);
|
|
84
|
+
} catch (e) {
|
|
85
|
+
throw new Error(`Failed to list repos for ${org}: ${e.message}`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const violations = [];
|
|
89
|
+
const ok = [];
|
|
90
|
+
|
|
91
|
+
for (const repo of repos) {
|
|
92
|
+
const result = checkPrivateCounterpart(org, repo.name);
|
|
93
|
+
if (result.allowed) {
|
|
94
|
+
ok.push({ name: repo.name, reason: result.reason });
|
|
95
|
+
} else {
|
|
96
|
+
violations.push({ name: repo.name, reason: result.reason });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return { violations, ok };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Extract repo org/name from a gh command string.
|
|
105
|
+
* Looks for patterns like: gh repo edit wipcomputer/repo-name --visibility public
|
|
106
|
+
* @param {string} command
|
|
107
|
+
* @returns {{ org: string, repo: string, isVisibilityChange: boolean } | null}
|
|
108
|
+
*/
|
|
109
|
+
export function parseVisibilityCommand(command) {
|
|
110
|
+
// Match: gh repo edit <org/repo> ... --visibility public
|
|
111
|
+
const editMatch = command.match(/gh\s+repo\s+edit\s+([^\s]+)/);
|
|
112
|
+
if (!editMatch) return null;
|
|
113
|
+
|
|
114
|
+
const visibilityMatch = command.match(/--visibility\s+(public|private|internal)/);
|
|
115
|
+
if (!visibilityMatch || visibilityMatch[1] !== 'public') return null;
|
|
116
|
+
|
|
117
|
+
const slug = editMatch[1];
|
|
118
|
+
const parts = slug.split('/');
|
|
119
|
+
if (parts.length !== 2) return null;
|
|
120
|
+
|
|
121
|
+
return { org: parts[0], repo: parts[1], isVisibilityChange: true };
|
|
122
|
+
}
|
package/guard.mjs
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* wip-repo-permissions-hook/guard.mjs
|
|
4
|
+
* PreToolUse:Bash hook for Claude Code.
|
|
5
|
+
* Blocks `gh repo edit --visibility public` unless -private counterpart exists.
|
|
6
|
+
* Same pattern as wip-file-guard/guard.mjs.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { parseVisibilityCommand, checkPrivateCounterpart } from './core.mjs';
|
|
10
|
+
|
|
11
|
+
function deny(reason) {
|
|
12
|
+
const output = {
|
|
13
|
+
hookSpecificOutput: {
|
|
14
|
+
hookEventName: 'PreToolUse',
|
|
15
|
+
permissionDecision: 'deny',
|
|
16
|
+
permissionDecisionReason: reason,
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
process.stdout.write(JSON.stringify(output));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function main() {
|
|
23
|
+
let raw = '';
|
|
24
|
+
for await (const chunk of process.stdin) {
|
|
25
|
+
raw += chunk;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let input;
|
|
29
|
+
try {
|
|
30
|
+
input = JSON.parse(raw);
|
|
31
|
+
} catch {
|
|
32
|
+
// Can't parse input, allow by default
|
|
33
|
+
process.exit(0);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const toolName = input.tool_name || '';
|
|
37
|
+
const toolInput = input.tool_input || {};
|
|
38
|
+
|
|
39
|
+
// Only check Bash commands
|
|
40
|
+
if (toolName !== 'Bash') {
|
|
41
|
+
process.exit(0);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const command = toolInput.command || '';
|
|
45
|
+
|
|
46
|
+
// Only check commands that look like visibility changes
|
|
47
|
+
const parsed = parseVisibilityCommand(command);
|
|
48
|
+
if (!parsed) {
|
|
49
|
+
process.exit(0);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Check if the repo can be made public
|
|
53
|
+
const result = checkPrivateCounterpart(parsed.org, parsed.repo);
|
|
54
|
+
|
|
55
|
+
if (!result.allowed) {
|
|
56
|
+
deny(result.reason);
|
|
57
|
+
process.exit(0);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Allowed
|
|
61
|
+
process.exit(0);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
main().catch(() => process.exit(0));
|
package/mcp-server.mjs
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// wip-repo-permissions-hook/mcp-server.mjs
|
|
3
|
+
// MCP server exposing repo visibility guard as tools.
|
|
4
|
+
// Wraps core.mjs. Registered via .mcp.json.
|
|
5
|
+
|
|
6
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
7
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
8
|
+
import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
9
|
+
import {
|
|
10
|
+
checkPrivateCounterpart, auditOrg,
|
|
11
|
+
} from './core.mjs';
|
|
12
|
+
|
|
13
|
+
const server = new Server(
|
|
14
|
+
{ name: 'wip-repo-permissions', version: '1.0.0' },
|
|
15
|
+
{ capabilities: { tools: {} } }
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
// ── Tool Definitions ──
|
|
19
|
+
|
|
20
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
21
|
+
tools: [
|
|
22
|
+
{
|
|
23
|
+
name: 'repo_permissions_check',
|
|
24
|
+
description: 'Check if a repo has a -private counterpart on GitHub. Required before making any repo public.',
|
|
25
|
+
inputSchema: {
|
|
26
|
+
type: 'object',
|
|
27
|
+
properties: {
|
|
28
|
+
org: { type: 'string', description: 'GitHub org (e.g. wipcomputer)' },
|
|
29
|
+
repo: { type: 'string', description: 'Repo name (e.g. memory-crystal)' },
|
|
30
|
+
},
|
|
31
|
+
required: ['org', 'repo'],
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'repo_permissions_audit',
|
|
36
|
+
description: 'Audit all public repos in a GitHub org for missing -private counterparts. Returns violations and passing repos.',
|
|
37
|
+
inputSchema: {
|
|
38
|
+
type: 'object',
|
|
39
|
+
properties: {
|
|
40
|
+
org: { type: 'string', description: 'GitHub org (e.g. wipcomputer)' },
|
|
41
|
+
},
|
|
42
|
+
required: ['org'],
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
}));
|
|
47
|
+
|
|
48
|
+
// ── Tool Handlers ──
|
|
49
|
+
|
|
50
|
+
server.setRequestHandler(CallToolRequestSchema, async (req) => {
|
|
51
|
+
const { name, arguments: args } = req.params;
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
if (name === 'repo_permissions_check') {
|
|
55
|
+
const result = checkPrivateCounterpart(args.org, args.repo);
|
|
56
|
+
return {
|
|
57
|
+
content: [{
|
|
58
|
+
type: 'text',
|
|
59
|
+
text: `${result.allowed ? 'ALLOWED' : 'BLOCKED'}: ${result.reason}`,
|
|
60
|
+
}],
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (name === 'repo_permissions_audit') {
|
|
65
|
+
const result = auditOrg(args.org);
|
|
66
|
+
const lines = [];
|
|
67
|
+
if (result.violations.length > 0) {
|
|
68
|
+
lines.push(`${result.violations.length} violation(s):`);
|
|
69
|
+
for (const v of result.violations) {
|
|
70
|
+
lines.push(` BLOCKED: ${v.name} - ${v.reason}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
lines.push(`${result.ok.length} repo(s) OK.`);
|
|
74
|
+
return {
|
|
75
|
+
content: [{ type: 'text', text: lines.join('\n') }],
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
content: [{ type: 'text', text: `Unknown tool: ${name}` }],
|
|
81
|
+
isError: true,
|
|
82
|
+
};
|
|
83
|
+
} catch (err) {
|
|
84
|
+
return {
|
|
85
|
+
content: [{ type: 'text', text: `Error: ${err.message}` }],
|
|
86
|
+
isError: true,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const transport = new StdioServerTransport();
|
|
92
|
+
await server.connect(transport);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "wip-repo-permissions-hook",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Blocks repos from going public without a -private counterpart. Protects internal plans, todos, and dev context from exposure.",
|
|
5
|
+
"lifecycle": {
|
|
6
|
+
"before_tool_use": "./guard.mjs"
|
|
7
|
+
}
|
|
8
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wipcomputer/wip-repo-permissions-hook",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Repo visibility guard. Blocks repos from going public without a -private counterpart.",
|
|
6
|
+
"main": "core.mjs",
|
|
7
|
+
"bin": {
|
|
8
|
+
"wip-repo-permissions": "./cli.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "bash test.sh"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"claude-code",
|
|
15
|
+
"openclaw",
|
|
16
|
+
"hook",
|
|
17
|
+
"repo-guard",
|
|
18
|
+
"visibility",
|
|
19
|
+
"ai-safety",
|
|
20
|
+
"pretooluse"
|
|
21
|
+
],
|
|
22
|
+
"author": "Parker Todd Brooks",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/wipcomputer/wip-ai-devops-toolbox.git"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@modelcontextprotocol/sdk": "^1.0.0"
|
|
30
|
+
}
|
|
31
|
+
}
|