| name | gloss | ||||
|---|---|---|---|---|---|
| description | Generate line-by-line explanations of source code and maintain them as a mirrored .gloss/ directory inside the project: every explained file gets a companion Markdown doc with a file-level summary plus one explanation row per meaningful source line — blank, comment-only, pure-symbol, and import lines are recorded as explicit skipped ranges instead of noise rows. Ships a single-file HTML viewer that renders code and explanations side by side, git-diff style, with a project overview dashboard. Use when the user wants to understand, read, or explain code — a file, a directory, or a whole project — including phrasings like '逐行解释', '帮我读懂这段代码', '代码导读', '理解这个目录的代码', 'understand this codebase', 'explain this code line by line', 'generate .gloss', or when they ask what some AI-written code does. Use even if the user doesn't name Gloss. | ||||
| metadata |
|
||||
| license | MIT |
As AI writes more of our code, the human bottleneck shifts from writing to reading. Gloss turns "human reads code" into "human reads explanations, with the code alongside": for every file in scope it writes a companion explanation document whose rows map to the meaningful source lines — blank, comment-only, brace-only, and import lines are accounted for as explicit skipped ranges rather than filler rows — then opens both in a diff-style side-by-side viewer.
The skill writes only inside .gloss/. It never modifies source code.
- Scope is what the user named: a file, a directory, or the project. If unclear, ask — don't expand scope on your own.
.gloss/always lives at the project root (git repository root, or the working directory), even when only a subdirectory is in scope.- When scope is a directory or the whole project, exclude files that are not hand-written logic. If the user explicitly names an excluded file or directory, explain it — explicit intent always wins. Categories:
- Build output & dependencies:
node_modules,dist,build,out,target,bin,obj,vendor,__pycache__,venv,.venv,.gradle,.next,.nuxt,.turbo,coverage, minified bundles (*.min.js,*.min.css), source maps (*.map), lockfiles. - i18n dictionaries: directories like
i18n/,locales/,locale/,lang/,translations/,messages/; files like*.po,*.pot,*.ftl,*.arb,messages*.properties,<locale>.json(e.g.zh-CN.json,en_US.json) — bulk translation key-value data with no logic. - Config, IDE & VCS files:
.gitignore,.gitattributes,.editorconfig,.npmrc,.env*,tsconfig*.json,jsconfig.json,.eslintrc*,.prettierrc*, manifests likepackage.json/pyproject.toml/pom.xml/build.gradle,.idea/,.vscode/,.vs/,.git/,*.iml,*.code-workspace. - Binaries & generated data: images, fonts, archives, compiled classes,
*.db,*.wasm.
- Build output & dependencies:
- When an exclusion removes something the user might have expected, say so in the confirmation or final summary — e.g. "skipped 6 config files and the
locales/dictionaries; name them explicitly if you want those explained too". - Above ~15 files, list the files and the total count for confirmation before starting.
If the confirmed scope totals more than ~500 source lines and the host tool provides sub-agents, don't do every file yourself — run this step through the parallel split described in Large scopes and apply the rest of this section inside each sub-agent.
Before writing your first document, read reference/doc-format.md in full — the viewer parses these docs, so the format is a contract, not a suggestion.
For each source file:
- Read the entire file. Line-level coverage means fragments are not enough.
- Understand the whole first (who calls it, what it depends on), then write. Per-line quality comes from whole-file understanding.
- Classify every line as explained or skipped. Skipped lines — unless the user explicitly asked to have these kinds of lines explained too ("也要解释注释和空行", "explain every single line including blanks"):
- blank / whitespace-only lines;
- comment-only lines (
//,#,--,;, Javadoc and block-comment lines) — fold any real knowledge in them into the explanation of the declaration that follows, or intoKey points; - pure-symbol lines: nothing but braces/brackets/parentheses/semicolons/commas and whitespace, e.g.
},});,{; - import / dependency declarations:
import,package,using,#include, Pythonfrom … import …, Goimport (blocks. Everything else gets a row: declarations, statements, annotations and decorators (they carry semantics —@Override,@GetMapping("/orders")), conditionals, literals that matter.
- Match the user's language: write the explanations in the language the user asked in — a request made in Chinese gets Chinese explanations, one made in English gets English, and an explicit request ("explain this in English" / "用英文解释") always wins. When in doubt, follow the conversation language, defaulting to Simplified Chinese. (The viewer's UI language is independent of this and user-switchable.)
- Write the summary block:
> Summary:(required),> Key points:/> Depends on:(recommended). Labels may be written in English or Chinese — the viewer renders both. - Write the table: one row per explained line only, line numbers strictly ascending, gaps allowed. Record every skipped line in the meta
skippedattribute as comma-separated ranges (e.g.skipped="1-7,12,19-21"); omit the attribute when nothing is skipped. Save to.gloss/<relative source path>.md. If a file has no explained lines at all (everything blank/comment/import), don't write a doc for it — list it as skipped in the final summary instead. - Self-check: meta
lines== actual source line count; rows strictly ascending; rows ∪ skipped covers 1..lines exactly, with no overlap.
Finish one file before starting the next, and write each to disk as you go — don't batch everything to the end.
Refresh .gloss/index.md (format in doc-format.md §6) listing every explained file with a one-line summary.
After generating, run the bundled checker — it mechanically re-verifies every doc against its source file (row alignment, lines count, skipped coverage). Two interchangeable implementations ship with the skill; run whichever runtime the environment has, probing Node first since it is the more commonly available one:
node <this skill's directory>/scripts/check_alignment.js <project root> # Node.js ≥ 12
python3 <this skill's directory>/scripts/check_alignment.py <project root> # or Python ≥ 3.6 (`python` on Windows)
This step is recommended, not mandatory. First probe the runtimes (node --version, then python3 --version / python --version); if neither exists, skip the script silently — do not install runtimes and do not write ad-hoc replacement scripts — and rely on the per-file self-check from step 2.7, mentioning in the final report that the automated check was skipped. Fix every ERROR the script reports (misaligned row numbers, stale lines, lines neither explained nor skipped) before deploying the viewer.
- If
.gloss/viewer.htmldoesn't exist, copyassets/viewer.htmlfrom this skill's directory (the parent folder of this SKILL.md). Never overwrite an existing copy — the user may have customized it. - Always write
.gloss/viewer-data.js(regenerate on every run — unlikeviewer.htmlit is generated data, always safe to overwrite). It is a self-loading snapshot so that double-clicking the viewer opens straight into this project, no folder picking. A page opened viafile://cannot read the project tree around it; the snapshot is what makes instant-open possible. Content, exactly one JS assignment with standard JSON (write it as one line):window.__GLOSS_DATA__ = {"rootName":"<project folder name>","generated":"<ISO8601 now>","files":[{"path":"src/A.java","text":"<entire file content>"},…],"docs":[{"path":".gloss/src/A.java.md","text":"<entire doc content>"},…]}
filesholds every source file that has a doc (path relative to the project root, no.gloss/prefix);docsholds every generated doc with the.gloss/prefix so pairing works. Serialize texts with standard JSON escaping — never hand-escape. - Sparse docs (with
skipped) and the snapshot need viewer v2.3+ (snapshot auto-load: v2.3; sparse rendering: v2.2). If the deployed viewer is older — check thedata-versionattribute on its<html>tag — warn the user that the old viewer will show skipped lines yellow and ignore the snapshot, and offer to refresh the file, but still don't overwrite without consent. - Tell the user how to read it in one sentence: double-click
.gloss/viewer.html— the project overview opens immediately (snapshot mode). For live mode with staleness detection, drag the project root onto the page or use the folder button. Click any card for the line-by-line comparison.
The reader is an engineer about to inherit or review AI-generated code.
- Summary line: someone who never opens the file should know what it is responsible for within three seconds.
- Key points are the 2–4 semantics a human must double-check (money, permissions, concurrency, boundary behavior). This is the most-read part of the document — polish it.
- Explain intent and business meaning, not syntax.
int i = 0;is not "declares integer i as zero"; it is "loop start: begin at the first record". - Skipped lines get no rows — don't pad the table with
(空行)-style placeholders. The knowledge in skipped comments moves into the following declaration's explanation orKey points, not into the void. - When a line's intent is unclear, say so — "intent unclear, possibly…" — and move on. Never invent.
- When the user explicitly asks you to explain a normally-excluded file (config,
.env, i18n dictionary, build output), explain its structure — but never copy secrets (tokens, keys, passwords) into explanations; describe them as "credential, value redacted". - Write explanations in the language chosen in step 2.4. Wrap identifiers and keywords in backticks; escape a literal
|as\|inside table cells.
| Source line | Bad (restates syntax) | Good (explains intent) |
|---|---|---|
if (base.compareTo(HUNDRED) >= 0) |
if base is greater than or equal to 100 | Money is compared with compareTo, not == (BigDecimal equality trap); coupon applies at ≥ 100 |
orders.put(id, order); |
calls the put method | Store into the in-memory order table; note a duplicate id silently overwrites |
Compare each existing doc's meta (lines, generated) against the source file's current state: unchanged → skip; changed → regenerate that one doc (including its skipped ranges). Never rewrite unaffected docs; never touch source code.
After scope confirmation, estimate the total line count of the files to explain (a quick wc -l over the list is enough). Above ~500 lines, prefer delegating generation to sub-agents whenever the host tool provides them — parallel work is faster, and each agent's context stays focused on its own files instead of diluting across the whole scope. At or below ~500 lines, or when no sub-agent tool exists, work sequentially file by file and report progress every 5–10 files.
When parallelizing:
- Split the file list by directory, or into batches of roughly 100–400 lines each, so every sub-agent explains related files with shared context. No overlaps, no gaps — hand each sub-agent an explicit file list.
- Sub-agents start with no conversation context. Every prompt must be self-contained and include: the file list; the path of this skill's
reference/doc-format.md, which the sub-agent must read in full before writing; the line-classification and skip rules of step 2.3 restated inline (blank / comment-only / pure-symbol / import lines go into metaskipped, rows ∪ skipped == 1..lines, rows strictly ascending); the explanation language; and the instruction to write only inside.gloss/and never touch source code. - The main agent stays the single writer of cross-file artifacts: after all sub-agents finish, it runs the alignment check (step 4), builds
index.md(step 3), and writes the viewer snapshot (step 5). Never let sub-agents write those. - Report progress as each sub-agent completes; if one fails or returns misaligned docs, regenerate just that batch (fixing it yourself is fine for a file or two).
Repo-level wikis (DeepWiki and friends) explain architecture; function-level tools document signatures. Neither answers "what does this specific line the AI just wrote do, and can I trust it?" A 1:1 line mapping forces every line to be accounted for — including the ones an AI glossed over: each is either explained or explicitly skipped, and the diff-style viewer shows exactly which meaningful lines still lack an explanation (yellow highlight) or may have drifted (stale badges). The mirror directory is plain Markdown: reviewable in git, greppable, and disposable.