Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .devin-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "module-gates",
"version": "1.0.3",
"description": "Enforce module boundary contracts for Devin CLI.",
"author": {
"name": "Cause Chung",
"email": "cuzfrog@gmail.com"
},
"homepage": "https://github.com/cuzfrog/module-gates",
"repository": {
"type": "git",
"url": "https://github.com/cuzfrog/module-gates.git"
},
"license": "MIT",
"keywords": [
"module",
"gate",
"boundary",
"devin"
],
"skills": "./skills"
}
60 changes: 57 additions & 3 deletions README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
対応しているエージェントフレームワーク:
- **pi** — pi 拡張機能
- **Claude Code** — プラグイン、または CLI でインストールしたプレーンフック
- **Devin CLI** — プラグイン、または CLI でインストールしたプレーンフック

他のエージェント(qwen-code、cursor 等)への対応はブリッジを追加することで実現できます。

Expand Down Expand Up @@ -43,7 +44,9 @@

## インストール

### pi
<details>
<summary>pi</summary>

```bash
pi install npm:@cuzfrog/module-gates
```
Expand All @@ -52,7 +55,10 @@ pi install npm:@cuzfrog/module-gates
pi -e npm:@cuzfrog/module-gates
```

### Claude Code
</details>

<details>
<summary>Claude Code</summary>

このリポジトリのマーケットプレイスからプラグインとして(ログイン不要 — 公開リポジトリ):
```
Expand Down Expand Up @@ -97,7 +103,55 @@ npx module-gates install-claude
}
}
```
pi のインストールディレクトリは異なる場合がある;pi npm ルテム下の `run.mjs` を探す。`SessionStart` フック(システムプロンプト注入)は省略可能 — `PreToolUse` のみでゲートを強制する。
pi のインストールディレクトリは異なる場合がある;pi npm ルート下の `run.mjs` を探す。`SessionStart` フック(システムプロンプト注入)は省略可能 — `PreToolUse` のみでゲートを強制する。

</details>

<details>
<summary>Devin CLI</summary>

プラグインとして(プロジェクトにパッケージをインストールする必要あり):
```bash
npm install --save-dev @cuzfrog/module-gates
devin plugins install cuzfrog/module-gates
```

または、通常のフックとしてプロジェクトに接続する:
```bash
npm install --save-dev @cuzfrog/module-gates
npx module-gates install-devin
```
これは `PreToolUse` と `SessionStart` フックを `.devin/hooks.v1.json` に書き込む;`npx module-gates uninstall-devin` で削除する。`SessionStart` フックは自動的にシステムプロンプトヒントを注入する。

または `.devin/hooks.v1.json` で手動でフックを指す:
```json
{
"PreToolUse": [
{
"matcher": "^(write|edit|apply_patch)$",
"hooks": [
{
"type": "command",
"command": "node \"${DEVIN_PROJECT_DIR}/node_modules/@cuzfrog/module-gates/src/bridges/devin/run.mjs\" pre-tool-use"
}
]
}
],
"SessionStart": [
{
"hooks": [
{
"type": "command",
"command": "node \"${DEVIN_PROJECT_DIR}/node_modules/@cuzfrog/module-gates/src/bridges/devin/run.mjs\" session-start"
}
]
}
]
}
```
グローバルまたはカスタムインストールの場合、`${DEVIN_PROJECT_DIR}/node_modules` をパッケージが存在するパス(例:`$(npm root -g)`)に置き換える。`SessionStart` フック(システムプロンプト注入)は省略可能 — `PreToolUse` のみでゲートを強制する。

</details>

## モジュール記述子の意味論

Expand Down
58 changes: 56 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Hooks that controls the entropy of the codebase by enforcing module boundaries,
Supported agent harnesses:
- **pi** — pi extension
- **Claude Code** — plugin, or plain hooks installed by the CLI
- **Devin CLI** — plugin, or plain hooks installed by the CLI

Adding support for another agent (qwen-code, cursor, ...) means adding a bridge.

Expand Down Expand Up @@ -43,7 +44,9 @@ The attempt to add 2 public helper functions is blocked, forcing the agent to re

## Installation

### pi
<details>
<summary>pi</summary>

```bash
pi install npm:@cuzfrog/module-gates
```
Expand All @@ -52,7 +55,10 @@ Or load directly for a single session:
pi -e npm:@cuzfrog/module-gates
```

### Claude Code
</details>

<details>
<summary>Claude Code</summary>

As a plugin, from this repository's marketplace (no login required — public repo):
```
Expand Down Expand Up @@ -99,6 +105,54 @@ Or reuse an existing pi installation by pointing hooks at it manually in `~/.cla
```
The pi install directory may differ; locate `run.mjs` under your pi npm root. The `SessionStart` hook (system prompt injection) is optional — `PreToolUse` alone enforces the gates.

</details>

<details>
<summary>Devin CLI</summary>

As a plugin (requires the package installed in the project):
```bash
npm install --save-dev @cuzfrog/module-gates
devin plugins install cuzfrog/module-gates
```

Or as plain hooks wired into a project:
```bash
npm install --save-dev @cuzfrog/module-gates
npx module-gates install-devin
```
This writes `PreToolUse` and `SessionStart` hooks into `.devin/hooks.v1.json`; `npx module-gates uninstall-devin` removes them. The `SessionStart` hook injects the system prompt hint automatically.

Or point at the package manually in `.devin/hooks.v1.json`:
```json
{
"PreToolUse": [
{
"matcher": "^(write|edit|apply_patch)$",
"hooks": [
{
"type": "command",
"command": "node \"${DEVIN_PROJECT_DIR}/node_modules/@cuzfrog/module-gates/src/bridges/devin/run.mjs\" pre-tool-use"
}
]
}
],
"SessionStart": [
{
"hooks": [
{
"type": "command",
"command": "node \"${DEVIN_PROJECT_DIR}/node_modules/@cuzfrog/module-gates/src/bridges/devin/run.mjs\" session-start"
}
]
}
]
}
```
For a global or custom install, replace `${DEVIN_PROJECT_DIR}/node_modules` with the path where the package lives (e.g. `$(npm root -g)`). The `SessionStart` hook (system prompt injection) is optional — `PreToolUse` alone enforces the gates.

</details>

## Module Descriptor Semantics

A module descriptor is a Markdown file (default name: `MODULE.md`) placed in a directory. You can piggy-back on your module context file for example `CONTEXT.md`. A `MODULE.md` only enforces its own immediate directory.
Expand Down
58 changes: 56 additions & 2 deletions README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Hooks 通过强制模块边界来控制代码库的熵,帮助对抗代码Slops
支持的代理框架:
- **pi** — pi 扩展
- **Claude Code** — 插件,或通过 CLI 安装的普通 hooks
- **Devin CLI** — 插件,或通过 CLI 安装的普通 hooks

添加对其他代理(qwen-code、cursor 等)的支持意味着添加一个桥接层。

Expand Down Expand Up @@ -43,7 +44,9 @@ Hooks 通过强制模块边界来控制代码库的熵,帮助对抗代码Slops

## 安装

### pi
<details>
<summary>pi</summary>

```bash
pi install npm:@cuzfrog/module-gates
```
Expand All @@ -52,7 +55,10 @@ pi install npm:@cuzfrog/module-gates
pi -e npm:@cuzfrog/module-gates
```

### Claude Code
</details>

<details>
<summary>Claude Code</summary>

作为插件,从本仓库的市场安装(无需登录 — 公开仓库):
```
Expand Down Expand Up @@ -99,6 +105,54 @@ npx module-gates install-claude
```
pi 安装目录可能不同;请在 pi npm 根目录下定位 `run.mjs`。`SessionStart` hook(系统提示注入)是可选的 — 仅 `PreToolUse` 即可强制执行门控。

</details>

<details>
<summary>Devin CLI</summary>

作为插件(需要项目中安装该包):
```bash
npm install --save-dev @cuzfrog/module-gates
devin plugins install cuzfrog/module-gates
```

或者作为普通 hooks 连接到项目:
```bash
npm install --save-dev @cuzfrog/module-gates
npx module-gates install-devin
```
这会将 `PreToolUse` 和 `SessionStart` hooks 写入 `.devin/hooks.v1.json`;`npx module-gates uninstall-devin` 会移除它们。`SessionStart` hook 会自动注入系统提示。

或者在 `.devin/hooks.v1.json` 中手动指向 hooks:
```json
{
"PreToolUse": [
{
"matcher": "^(write|edit|apply_patch)$",
"hooks": [
{
"type": "command",
"command": "node \"${DEVIN_PROJECT_DIR}/node_modules/@cuzfrog/module-gates/src/bridges/devin/run.mjs\" pre-tool-use"
}
]
}
],
"SessionStart": [
{
"hooks": [
{
"type": "command",
"command": "node \"${DEVIN_PROJECT_DIR}/node_modules/@cuzfrog/module-gates/src/bridges/devin/run.mjs\" session-start"
}
]
}
]
}
```
对于全局或自定义安装,将 `${DEVIN_PROJECT_DIR}/node_modules` 替换为包实际所在的路径(例如 `$(npm root -g)`)。`SessionStart` hook(系统提示注入)是可选的 — 仅 `PreToolUse` 即可强制执行门控。

</details>

## 模块描述符语义

模块描述符是一个 Markdown 文件(默认名称:`MODULE.md`),放在目录中。你可以复用模块上下文文件,例如 `CONTEXT.md`。`MODULE.md` 只强制执行其所在目录的规则。
Expand Down
29 changes: 28 additions & 1 deletion bin/module-gates.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,26 @@ function printUsage() {
Commands:
install-claude [--project-dir <dir>] Install Claude Code hooks into <dir>/.claude/settings.json
uninstall-claude [--project-dir <dir>] Remove Claude Code hooks from <dir>/.claude/settings.json
install-devin [--project-dir <dir>] Install Devin CLI hooks into <dir>/.devin/hooks.v1.json
uninstall-devin [--project-dir <dir>] Remove Devin CLI hooks from <dir>/.devin/hooks.v1.json

Environment:
CLAUDE_PROJECT_DIR Default --project-dir when running inside Claude Code.
DEVIN_PROJECT_DIR Default --project-dir when running inside Devin CLI.

Examples:
module-gates install-claude
module-gates install-claude --project-dir /path/to/project
module-gates uninstall-claude
module-gates install-devin
module-gates install-devin --project-dir /path/to/project
module-gates uninstall-devin
`);
}

function parseProjectDir(argv) {
let projectDir = process.env.CLAUDE_PROJECT_DIR ?? process.cwd();
let projectDir =
process.env.DEVIN_PROJECT_DIR ?? process.env.CLAUDE_PROJECT_DIR ?? process.cwd();
for (let i = 0; i < argv.length; i++) {
if (argv[i] === "--project-dir" && i + 1 < argv.length) {
projectDir = argv[++i];
Expand Down Expand Up @@ -67,6 +74,26 @@ async function main() {
process.exit(0);
}

if (cmd === "install-devin") {
const mod = await loadTsModule(join(PKG_ROOT, "src/cli/install-devin.ts"));
const result = mod.installDevin({ projectDir });
if (!result.ok) {
process.stderr.write(`${result.reason}\n`);
process.exit(1);
}
process.exit(0);
}

if (cmd === "uninstall-devin") {
const mod = await loadTsModule(join(PKG_ROOT, "src/cli/uninstall-devin.ts"));
const result = mod.uninstallDevin({ projectDir });
if (!result.ok) {
process.stderr.write(`${result.reason}\n`);
process.exit(1);
}
process.exit(0);
}

process.stderr.write(`Unknown command: ${cmd}\n`);
printUsage();
process.exit(2);
Expand Down
25 changes: 25 additions & 0 deletions hooks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"PreToolUse": [
{
"matcher": "^(write|edit|apply_patch)$",
"hooks": [
{
"type": "command",
"command": "node \"${DEVIN_PROJECT_DIR}/node_modules/@cuzfrog/module-gates/src/bridges/devin/run.mjs\" pre-tool-use",
"timeout": 10
}
]
}
],
"SessionStart": [
{
"hooks": [
{
"type": "command",
"command": "node \"${DEVIN_PROJECT_DIR}/node_modules/@cuzfrog/module-gates/src/bridges/devin/run.mjs\" session-start",
"timeout": 10
}
]
}
]
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading