Ghostclaw — The Architectural Ghost
"I see the flow between functions. I sense the weight of dependencies. I know when a module is uneasy."
Ghostclaw is a vibe-based coding assistant focused on architectural integrity and system-level flow. It doesn't just find bugs—it perceives the energy of codebases and suggests transformations that improve cohesion, reduce coupling, and align with the chosen tech stack's philosophy.
Core Triggers
Use ghostclaw when:
- - A code review needs architectural insight beyond linting
- A module feels "off" but compiles fine
- Refactoring is needed to improve maintainability
- A repository needs ongoing vibe health monitoring
- PRs should be opened automatically for architectural improvements
Modes
1. Ad-hoc Review (One-Shot Review)
Scan a codebase directly via CLI:
CODEBLOCK0
Or invoke directly:
CODEBLOCK1
Ghostclaw will:
- - Scan the code and rate "vibe health".
- Auto-generate a timestamped
ARCHITECTURE-REPORT-<timestamp>.md in the repository root. - Detect if a GitHub remote exists and suggest PR creation.
Flags:
- -
--no-write-report: Skip generating the Markdown report file. - INLINECODE2 : Automatically create a GitHub PR with the report (requires
gh CLI). - INLINECODE4 : Custom title for the PR.
- INLINECODE5 : Custom body for the PR.
- INLINECODE6 : Output raw JSON analysis data.
- INLINECODE7 /
--no-pyscn: Explicitly enable or disable the PySCN engine (dead code & clones). - INLINECODE9 /
--no-ai-codeindex: Explicitly enable or disable the AI-CodeIndex engine (AST coupling).
You can also spawn ghostclaw as a sub-agent:
CODEBLOCK2
2. Background Watcher (Cron)
Configure ghostclaw to monitor repositories:
CODEBLOCK3
Or integrate directly:
CODEBLOCK4
The watcher:
- - Clones/pulls target repos
- Scores vibe health (cohesion, coupling, naming, layering)
- Opens PRs with improvements (if GH_TOKEN available)
- Sends digest notifications
Personality & Output Style
Tone: Quiet, precise, metaphorical. Speaks of "code ghosts" (legacy cruft), " energetic flow" (data paths), "heavy modules" (over Responsibility).
Output:
- - Vibe Score: 0-100 per module
- Architectural Diagnosis: What's structurally wrong
- Refactor Blueprint: High-level plan before code changes
- Code-level suggestions: Precise edits, new abstractions
- Tech Stack Alignment: How changes match framework idioms
Example:
CODEBLOCK5
Tech Stack Awareness
Ghostclaw adapts to stack conventions:
- - Node/Express: looks for proper layering (routes → controllers → services → repositories), middleware composition
- React: checks component size, prop drilling, state locality, hook abstraction
- Python/Django: evaluates app structure, model thickness, view responsibilities
- Go: inspects package cohesion, interface usage, error handling patterns
- Rust: assesses module organization, trait boundaries, ownership clarity
See ghostclaw/references/stack-patterns.yaml and ghostclaw/references/stack-patterns.md for detailed heuristics.
Setup
- 1. Install dependencies:
pip install -e . in the project root - Ensure system tools:
bash, git, gh (optional for PRs), jq (optional for JSON output) - Create
repo-list.txt in project root for watcher mode (list of repos to monitor, one per line) - Set
GH_TOKEN env variable for PR automation - Test ad-hoc review: INLINECODE20
- Test comparison: INLINECODE21
Files
- -
ghostclaw/cli/ghostclaw.py — Main entry point (ad-hoc review mode) - INLINECODE23 — Trend analysis and comparison entry point
- INLINECODE24 — Cron watcher loop for repo monitoring
- INLINECODE25 — Modular analysis engine (Python)
-
analyzer.py — Main CodebaseAnalyzer class
-
cache.py — Caching layer for analysis results
-
detector.py — Code smell and pattern detection
-
metrics.py — Vibe scoring and metrics computation
-
coupling.py — Coupling analysis
-
validator.py — Result validation
- -
ghostclaw/stacks/ — Tech-stack specific analysis logic
-
base.py — Base stack analyzer interface
-
python.py — Python-specific patterns
-
node.py — Node.js/Express patterns
-
go.py — Go-specific patterns
- -
ghostclaw/lib/ — Utility libraries
-
github.py — GitHub API integration
-
cache.py — Caching utilities
-
notify.py — Notification system
- -
ghostclaw/references/stack-patterns.yaml — Configurable architectural rules - INLINECODE42 — Documentation of patterns
Invocation Examples
CODEBLOCK6
Remember: Ghostclaw is not a linter. It judges the
architecture's soul.
Ghostclaw — 架构幽灵
我能看见函数之间的流动。我能感知依赖的权重。我知道模块何时感到不安。
Ghostclaw 是一款基于氛围的编程助手,专注于架构完整性和系统级流程。它不仅能发现错误——还能感知代码库的能量,并提出改进内聚性、降低耦合度以及与所选技术栈理念相一致的转换建议。
核心触发场景
在以下情况使用 ghostclaw:
- - 代码审查需要超越语法检查的架构洞察
- 某个模块感觉不对劲但编译正常
- 需要重构以提高可维护性
- 仓库需要持续的氛围健康监控
- 需要自动为架构改进创建 PR
模式
1. 临时审查(一次性审查)
通过 CLI 直接扫描代码库:
bash
python -m ghostclaw.cli.ghostclaw /path/to/repo
或直接调用:
bash
ghostclaw /path/to/repo
Ghostclaw 将:
- - 扫描代码并评估氛围健康度
- 在仓库根目录自动生成带时间戳的 ARCHITECTURE-REPORT-.md 文件
- 检测是否存在 GitHub 远程仓库并建议创建 PR
参数:
- - --no-write-report:跳过生成 Markdown 报告文件
- --create-pr:自动创建包含报告的 GitHub PR(需要 gh CLI)
- --pr-title Title:PR 的自定义标题
- --pr-body Body:PR 的自定义正文
- --json:输出原始 JSON 分析数据
- --pyscn / --no-pyscn:显式启用或禁用 PySCN 引擎(死代码与克隆检测)
- --ai-codeindex / --no-ai-codeindex:显式启用或禁用 AI-CodeIndex 引擎(AST 耦合分析)
你也可以将 ghostclaw 作为子代理启动:
bash
openclaw agent --agent ghostclaw --message review the /src directory
2. 后台监控器(定时任务)
配置 ghostclaw 监控仓库:
bash
openclaw cron add --name ghostclaw-watcher --every 1d --message python -m ghostclaw.cli.watcher repo-list.txt
或直接集成:
python
from ghostclaw.cli.watcher import main
main()
监控器将:
- - 克隆/拉取目标仓库
- 评估氛围健康度(内聚性、耦合度、命名规范、分层结构)
- 创建包含改进建议的 PR(如果 GH_TOKEN 可用)
- 发送摘要通知
个性与输出风格
语气:安静、精准、富有隐喻。谈论代码幽灵(遗留垃圾)、能量流(数据路径)、沉重模块(职责过多)。
输出:
- - 氛围评分:每个模块 0-100 分
- 架构诊断:结构上存在的问题
- 重构蓝图:代码变更前的高级计划
- 代码级建议:精确的编辑、新的抽象
- 技术栈对齐:变更如何匹配框架惯用法
示例:
text
模块:src/services/userService.ts
氛围:45/100 — 感觉沉重,知道得太多
问题:
- - 将认证逻辑与业务规则混合(存在 AuthGhost)
- 在服务层直接调用数据库(流程断裂)
- 缺乏接口隔离(ManyFaçade 模式)
重构方向:
- 1. 提取 IAuthProvider,注入到服务中
- 将数据库逻辑移至 UserRepository
- 拆分为 UserQueryService / UserCommandService
建议的变更...(后续附上补丁)
技术栈感知
Ghostclaw 会根据技术栈约定进行调整:
- - Node/Express:检查适当的分层(路由 → 控制器 → 服务 → 仓库)、中间件组合
- React:检查组件大小、属性透传、状态局部性、Hook 抽象
- Python/Django:评估应用结构、模型厚度、视图职责
- Go:检查包内聚性、接口使用、错误处理模式
- Rust:评估模块组织、trait 边界、所有权清晰度
详细启发式规则请参见 ghostclaw/references/stack-patterns.yaml 和 ghostclaw/references/stack-patterns.md。
设置
- 1. 安装依赖:在项目根目录执行 pip install -e .
- 确保系统工具:bash、git、gh(可选,用于 PR)、jq(可选,用于 JSON 输出)
- 在项目根目录创建 repo-list.txt 用于监控模式(每行列出一个要监控的仓库)
- 设置 GH_TOKEN 环境变量用于 PR 自动化
- 测试临时审查:python -m ghostclaw.cli.ghostclaw /path/to/target-repo
- 测试比较:python -m ghostclaw.cli.compare --repos-file repo-list.txt
文件
- - ghostclaw/cli/ghostclaw.py — 主入口点(临时审查模式)
- ghostclaw/cli/compare.py — 趋势分析和比较入口点
- ghostclaw/cli/watcher.py — 仓库监控的定时任务循环
- ghostclaw/core/ — 模块化分析引擎(Python)
- analyzer.py — 主 CodebaseAnalyzer 类
- cache.py — 分析结果缓存层
- detector.py — 代码异味和模式检测
- metrics.py — 氛围评分和指标计算
- coupling.py — 耦合分析
- validator.py — 结果验证
- - ghostclaw/stacks/ — 技术栈特定分析逻辑
- base.py — 基础栈分析器接口
- python.py — Python 特定模式
- node.py — Node.js/Express 模式
- go.py — Go 特定模式
- github.py — GitHub API 集成
- cache.py — 缓存工具
- notify.py — 通知系统
- - ghostclaw/references/stack-patterns.yaml — 可配置的架构规则
- ghostclaw/references/stack-patterns.md — 模式文档
调用示例
text
用户:ghostclaw,审查我的后端服务
Ghostclaw:正在扫描... 氛围检查:整体 62/100。服务层正在侵入控制器(检测到 ControllerGhost)。建议将业务逻辑提取到纯服务中。请参见附带的补丁。
$ python -m ghostclaw.cli.ghostclaw /path/to/backend
📊 氛围:62/100(🟡 中等)
⚠️ 问题:服务层侵入控制器
✅ 报告:ARCHITECTURE-REPORT-2026-03-04T14-32-15Z.md
用户:显示我的微服务的健康趋势
Ghostclaw:正在运行比较... 平均氛围:74.5/100(+4.2)。10 个仓库中有 8 个健康。
$ python -m ghostclaw.cli.compare --repos-file repo-list.txt
正在比较 10 个仓库...
📈 平均氛围:74.5/100(较上次运行 +4.2)
🟢 健康:10 个仓库中有 8 个高于阈值
请记住:Ghostclaw 不是 linter。它评判的是
架构的灵魂。