Ghost Catalog Skill
Manage semantic file headers and maintain the Ghost Catalog database for any workspace.
Header Format (SOM File ID)
Every cataloged file gets a semantic header in the first 20 lines:
CODEBLOCK0
Comment style adapts to file type:
- - Python/Shell/YAML/TOML:
# prefix - JavaScript/TypeScript/Go/Rust/C:
// prefix inside /* ... */ block - HTML/XML:
<!-- ... --> block - Markdown:
<!-- ... --> HTML comment block - CSS:
/* ... */ block - SQL:
-- prefix
File ID Schema: SOM-XXX-NNNN-vX.X.X
| Segment | Meaning | Examples |
|---|
| INLINECODE8 | Somacosf namespace (constant) | INLINECODE9 |
| INLINECODE10 |
3-letter category code |
SCR (script),
DOC (doc),
CFG (config),
SCH (schema),
CMP (component),
TST (test),
DAT (data),
STY (style),
LIB (library),
API (api route),
UTL (utility),
HKS (hooks) |
|
NNNN | 4-digit sequential number |
0001,
0042,
0338 |
|
vX.X.X | Semantic version |
v1.0.0,
v2.1.3 |
Category Codes
| Code | Category | File Types |
|---|
| INLINECODE30 | Script | INLINECODE31 , .sh, .ps1, INLINECODE34 |
| INLINECODE35 |
Document |
.md,
.txt,
.rst |
|
CFG | Config |
.json,
.yaml,
.yml,
.toml,
.env,
.ini |
|
SCH | Schema |
.prisma,
.graphql,
.sql |
|
CMP | Component |
.tsx,
.jsx,
.vue,
.svelte |
|
TST | Test |
*.test.*,
*.spec.* |
|
DAT | Data |
.csv,
.json (data files),
.db |
|
STY | Style |
.css,
.scss,
.less |
|
LIB | Library |
.ts,
.js (lib modules) |
|
API | API Route |
route.ts,
route.js (Next.js API routes) |
|
UTL | Utility | Helper/utility modules |
|
HKS | Hooks | React hooks, git hooks |
Catalog Database
The catalog lives at data/ghost-catalog.db (SQLite). Schema:
CODEBLOCK1
Commands
When the user invokes /ghost-catalog, determine which operation to perform based on their request. Default to scan if no specific command is given.
1. scan (default)
Scan the workspace for all source files. For each file:
- 1. Check if it already has a SOM header (look for
file_id: SOM- in first 20 lines) - If header exists: parse and validate it, update the catalog DB
- If no header: report it as untagged
Output a summary table:
CODEBLOCK2
Ignore system (layered, merged at scan time):
- 1.
.ghost_ignore (primary) -- Ghost Catalog's own ignore file, lives at project root. Follows .gitignore syntax. This is the canonical source of what to skip. - INLINECODE81 (inherited) -- automatically merged; anything git ignores, Ghost Catalog ignores too.
- Hardcoded fallbacks -- if neither file exists, use:
.git/, node_modules/, .next/, .vercel/, __pycache__/, .venv/, dist/, build/, INLINECODE90
When scanning, parse .ghost_ignore and .gitignore into a combined exclusion set. Only scan files that survive both filters. The goal: catalog project files only -- no dependencies, no build artifacts, no binaries, no secrets, no lock files.
2. tag <path|pattern>
Apply a Ghost Catalog header to one or more files:
- 1. Read the file content
- Determine the category from file extension and location
- Query the catalog DB for the next available sequence number in that category
- Generate the header with appropriate comment syntax
- Prepend the header to the file (preserve existing content)
- Insert into the catalog DB
When tagging multiple files, show a preview table first and ask for confirmation before applying.
3. validate
Check all tagged files for header compliance:
- - Required fields present:
file_id, name, description, category, version, created, INLINECODE101 - File ID format valid: INLINECODE102
- Version in file_id matches version field
- Filename in header matches actual filename
- No duplicate file IDs
Output a validation report with pass/warn/fail for each file.
4. search <query>
Search the catalog by any field:
- -
search proxy - fuzzy match on name/description - INLINECODE105 - filter by category
- INLINECODE106 - filter by tag
- INLINECODE107 - filter by agent
Display results as a formatted table with file_id, name, category, and path.
5. info <file_id>
Show detailed metadata for a specific file from the catalog DB.
6. stats
Show catalog statistics:
- - Total files, tagged vs untagged
- Breakdown by category
- Top tags
- Agent activity
- Last sync time
7. report
Generate a full compliance report in markdown format, saved to docs/ghost-catalog-report.md.
Implementation Notes
- - Use Python 3 with
sqlite3 stdlib for database operations - For scanning, use the Glob and Read tools rather than spawning processes
- When generating headers, always check what comment style the file uses
- Sequence numbers are global per category (not per project)
- The catalog DB should be created at
data/ghost-catalog.db if it doesn't exist - Always use
AGENT-DROID-001 as the agent_id when this skill applies headers - Version starts at
v1.0.0 for new files - INLINECODE116 date is always today's date when applying or updating headers
- INLINECODE117 date is preserved if already set, otherwise today's date
Verification
After any write operation (tag, validate --fix), re-read the modified files to confirm headers were applied correctly. Report any failures.
Auto-Invocation Guidance
This skill should be considered when:
- - The user asks about file organization, cataloging, or headers
- A scan reveals many untagged files and the user wants to fix compliance
- The user creates new files and wants them cataloged
- The user asks "what files are in this project" or "show me the catalog"
Ghost Catalog 技能
管理工作区中所有文件的语义化文件头,并维护 Ghost Catalog 数据库。
文件头格式(SOM 文件 ID)
每个被编目的文件在前 20 行内都会获得一个语义化文件头:
file_id: SOM-XXX-NNNN-vX.X.X
name: filename.ext
description: 该文件的功能描述
project_id: PROJECT-NAME
category: script | doc | config | schema | component | test | data | style
tags: [tag1, tag2, tag3]
created: YYYY-MM-DD
modified: YYYY-MM-DD
version: X.X.X
agent_id: AGENT-DROID-001
注释样式会根据文件类型自动适配:
- - Python/Shell/YAML/TOML:使用 # 前缀
- JavaScript/TypeScript/Go/Rust/C:在 / ... / 块内使用 // 前缀
- HTML/XML:使用 块
- Markdown:使用 HTML 注释块
- CSS:使用 / ... / 块
- SQL:使用 -- 前缀
文件 ID 格式:SOM-XXX-NNNN-vX.X.X
| 段 | 含义 | 示例 |
|---|
| SOM | Somacosf 命名空间(固定值) | SOM |
| XXX |
3 字母分类代码 | SCR(脚本)、DOC(文档)、CFG(配置)、SCH(模式)、CMP(组件)、TST(测试)、DAT(数据)、STY(样式)、LIB(库)、API(API 路由)、UTL(工具)、HKS(钩子) |
| NNNN | 4 位顺序号 | 0001、0042、0338 |
| vX.X.X | 语义化版本号 | v1.0.0、v2.1.3 |
分类代码
| 代码 | 分类 | 文件类型 |
|---|
| SCR | 脚本 | .py、.sh、.ps1、.bat |
| DOC |
文档 | .md、.txt、.rst |
| CFG | 配置 | .json、.yaml、.yml、.toml、.env、.ini |
| SCH | 模式 | .prisma、.graphql、.sql |
| CMP | 组件 | .tsx、.jsx、.vue、.svelte |
| TST | 测试 |
.test.、
.spec. |
| DAT | 数据 | .csv、.json(数据文件)、.db |
| STY | 样式 | .css、.scss、.less |
| LIB | 库 | .ts、.js(库模块) |
| API | API 路由 | route.ts、route.js(Next.js API 路由) |
| UTL | 工具 | 辅助/工具模块 |
| HKS | 钩子 | React 钩子、Git 钩子 |
编目数据库
编目数据存储在 data/ghost-catalog.db(SQLite 数据库)。数据库模式如下:
sql
CREATE TABLE IF NOT EXISTS file_catalog (
file_id TEXT PRIMARY KEY,
name TEXT NOT NULL,
description TEXT,
path TEXT NOT NULL,
project_id TEXT,
category TEXT,
version TEXT,
created TEXT,
modified TEXT,
agent_id TEXT,
execution TEXT,
checksum TEXT,
lastsynced TIMESTAMP DEFAULT CURRENTTIMESTAMP
);
CREATE TABLE IF NOT EXISTS file_tags (
file_id TEXT,
tag TEXT,
PRIMARY KEY (file_id, tag),
FOREIGN KEY (fileid) REFERENCES filecatalog(file_id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS agent_registry (
id TEXT PRIMARY KEY,
name TEXT,
model TEXT,
firstseen TIMESTAMP DEFAULT CURRENTTIMESTAMP,
last_active TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idxcategory ON filecatalog(category);
CREATE INDEX IF NOT EXISTS idxproject ON filecatalog(project_id);
CREATE INDEX IF NOT EXISTS idxagent ON filecatalog(agent_id);
CREATE INDEX IF NOT EXISTS idxtags ON filetags(tag);
命令
当用户调用 /ghost-catalog 时,根据其请求确定要执行的操作。如果未指定具体命令,则默认执行 scan 操作。
1. scan(默认)
扫描工作区中的所有源文件。对于每个文件:
- 1. 检查是否已有 SOM 文件头(在前 20 行中查找 file_id: SOM-)
- 如果存在文件头:解析并验证,更新编目数据库
- 如果没有文件头:将其报告为未标记文件
输出汇总表格:
已扫描:150 个文件
已标记: 42 个文件(28%)
未标记:108 个文件
错误: 0 个
忽略系统(分层合并,在扫描时生效):
- 1. .ghostignore(主要)—— Ghost Catalog 自身的忽略文件,位于项目根目录。遵循 .gitignore 语法。这是决定跳过哪些文件的权威来源。
- .gitignore(继承)—— 自动合并;Git 忽略的内容,Ghost Catalog 也会忽略。
- 硬编码后备规则—— 如果上述两个文件都不存在,则使用:.git/、nodemodules/、.next/、.vercel/、pycache/、.venv/、dist/、build/、.factory/
扫描时,解析 .ghost_ignore 和 .gitignore 文件,生成合并后的排除集。仅扫描同时通过两个过滤器的文件。目标:仅编目项目文件—— 不包含依赖项、构建产物、二进制文件、机密文件和锁文件。
2. tag <路径|模式>
为一个或多个文件应用 Ghost Catalog 文件头:
- 1. 读取文件内容
- 根据文件扩展名和位置确定分类
- 查询编目数据库,获取该分类中下一个可用的顺序号
- 使用适当的注释语法生成文件头
- 将文件头添加到文件开头(保留原有内容)
- 插入到编目数据库中
标记多个文件时,先显示预览表格,在应用前请求确认。
3. validate
检查所有已标记文件的文件头合规性:
- - 必填字段是否存在:file_id、name、description、category、version、created、modified
- 文件 ID 格式是否有效:SOM-XXX-NNNN-vX.X.X
- 文件 ID 中的版本号是否与版本字段匹配
- 文件头中的文件名是否与实际文件名一致
- 无重复文件 ID
输出验证报告,对每个文件显示通过/警告/失败状态。
4. search <查询条件>
按任意字段搜索编目:
- - search proxy —— 对名称/描述进行模糊匹配
- search --category script —— 按分类筛选
- search --tag opentelemetry —— 按标签筛选
- search --agent AGENT-CLAUDE-002 —— 按代理筛选
以格式化表格形式显示结果,包含文件 ID、名称、分类和路径。
5. info <文件 ID>
从编目数据库中显示特定文件的详细元数据。
6. stats
显示编目统计信息:
- - 文件总数,已标记与未标记数量
- 按分类细分
- 热门标签
- 代理活动
- 上次同步时间
7. report
生成完整的合规性报告,格式为 Markdown,保存到 docs/ghost-catalog-report.md。
实现说明
- - 使用 Python 3 及其标准库中的 sqlite3 进行数据库操作
- 扫描时使用 Glob 和 Read 工具,而非启动子进程
- 生成文件头时,始终检查文件使用的注释样式
- 顺序号按分类全局分配(不按项目分配)
- 如果编目数据库不存在,应在 data/ghost-catalog.db 路径创建
- 当此技能应用文件头时,始终使用 AGENT-DROID-001 作为 agent_id
- 新文件的版本号从 v1.0.0 开始
- 应用或更新文件头时,modified 日期始终为当天日期
- 如果已设置 created 日期