annotate-source-files
About
This skill automatically adds PUT workflow annotations to source files using the correct comment syntax for over 30 programming languages. It handles annotation generation, multiline comments, .internal variables, and validation, making it ideal for documenting workflows in data pipelines or multi-step computations. Use it after analyzing a codebase and creating an annotation plan to embed structured documentation directly into your source files.
Quick Install
Claude Code
Recommendednpx skills add pjt222/agent-almanac -a claude-code/plugin add https://github.com/pjt222/agent-almanacgit clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/annotate-source-filesCopy and paste this command in Claude Code to install this skill
Documentation
注源檔
添 PUT 工作流注於源檔,使 putior 可取結構化工作流數而生 Mermaid 圖。
用時
- 以
analyze-codebase-workflow析畢且有注計後乃用 - 添工作流文於新或既源檔乃用
- 以手標與連豐自察工作流乃用
- 書數管、ETL、多步計算乃用
入
- 必要:待注之源檔
- 必要:注計或工作流諸步之知
- 可選:風格:單行或多行(默:單行)
- 可選:用
put_generate()生骨乎(默:是)
法
第一步:定注之前綴
各語有特注前綴。以 get_comment_prefix() 得之。
library(putior)
# Common prefixes
get_comment_prefix("R") # "#"
get_comment_prefix("py") # "#"
get_comment_prefix("sql") # "--"
get_comment_prefix("js") # "//"
get_comment_prefix("ts") # "//"
get_comment_prefix("go") # "//"
get_comment_prefix("rs") # "//"
get_comment_prefix("m") # "%"
get_comment_prefix("lua") # "--"
得: 一串如 "#"、"--"、"//"、或 "%"。
行注與塊注:putior 察行注(
//、#、--)及 C 式塊注(/* */、/** */)中之注。JS/TS 行注與塊注皆掃。Python 三引號串(''' ''')不察——Python 注用#。
敗則: 若擴未識,檔語或不支。以 get_supported_extensions() 察全列。不支之語用 # 為約默。
第二步:生注骨
用 put_generate() 以自察 I/O 建注樣。
# Print suggestions to console
put_generate("./src/etl/")
# Single-line style (default)
put_generate("./src/etl/", style = "single")
# Multiline style for complex annotations
put_generate("./src/etl/", style = "multiline")
# Copy to clipboard for pasting
put_generate("./src/etl/", output = "clipboard")
R 檔之例:
# put id:'extract_data', label:'Extract Customer Data', input:'customers.csv', output:'raw_data.internal'
SQL 之例:
-- put id:'load_data', label:'Load Customer Table', output:'customers'
得: 每源檔一或多注行,預填察函名與 I/O。
敗則: 若無薦生,檔或無可識 I/O 式。依碼解手書注。
第三步:精注
編骨以添正標、連、元。
注語法參:
<prefix> put id:'unique_id', label:'Human Readable Label', input:'file1.csv, file2.rds', output:'result.parquet, summary.internal'
欄:
id(必):獨識,連節用label(必):圖顯之人讀述input:入檔或量逗列output:出檔或量逗列.internal擴:標記憶量(腳本間未存)node_type:控 Mermaid 節形與類:"input"— 體育場形([...])為數源與設"output"— 子程形[[...]]為生物"process"— 矩[...]為處理步(默)"decision"— 菱{...}為條件邏輯"start"/"end"— 體育場形([...])為入/終節
附 node_type 之例:
# put id:'config', label:'Load Config', node_type:'input', output:'config.internal'
# put id:'transform', label:'Apply Rules', node_type:'process', input:'config.internal', output:'result.rds'
# put id:'report', label:'Generate Report', node_type:'output', input:'result.rds'
多行語法(為繁注):
# put id:'complex_step', \
# label:'Multi-line Label', \
# input:'data.csv, config.yaml', \
# output:'result.parquet'
塊注語法(唯 // 前綴之語:JS、TS、Go、Rust、C、C++、Java 等):
用 // 行注之語亦支 /* */ 與 /** */ 塊注中之 PUT 注。塊內用 * put 為行前:
/* put id:'init', label:'Initialize Config', output:'config.internal' */
/**
* put id:'process', \
* label:'Process Records', \
* input:'config.internal, records.json', \
* output:'results.json'
*/
function processRecords(config, records) {
// ...
}
JSDoc 式注尤宜於書工作流步附 API 文:
/**
* Transform raw sensor data into normalized readings.
* put id:'normalize', label:'Normalize Sensor Data', input:'raw_readings.json', output:'normalized.parquet'
*/
export function normalizeSensorData(readings: SensorReading[]): NormalizedData {
// ...
}
注:塊注注不支
#前綴之語(R、Python、Shell)或--前綴之語(SQL、Lua)。彼語唯用行注。塊起注不支跨行反斜續。
跨檔數流(以檔 I/O 連本):
# Script 1: extract.R
# put id:'extract', label:'Extract Data', output:'raw_data.internal, raw_data.rds'
data <- read.csv("source.csv")
saveRDS(data, "raw_data.rds")
# Script 2: transform.R
# put id:'transform', label:'Transform Data', input:'raw_data.rds', output:'clean_data.parquet'
data <- readRDS("raw_data.rds")
arrow::write_parquet(clean, "clean_data.parquet")
得: 注精附正 ID、標、I/O 欄映實數流。
敗則: 若 I/O 不定,用 .internal 擴於記憶中間,用明檔名於持數。
第四步:插注於檔
置注於檔首或相關塊之上。
位之例:
- 檔級注:置檔首(shebang 或檔頭注後)
- 塊級注:置所述塊之上
- 每檔多注:於有別工作流段之檔用
R 檔位例:
#!/usr/bin/env Rscript
# ETL Extract Script
#
# put id:'read_source', label:'Read Source Data', input:'raw_data.csv', output:'df.internal'
df <- read.csv("raw_data.csv")
# put id:'clean_data', label:'Clean and Validate', input:'df.internal', output:'clean.rds'
df_clean <- df[complete.cases(df), ]
saveRDS(df_clean, "clean.rds")
用 Edit 工具插注於既檔而不擾周圍碼。
得: 注插於每源檔之宜位。
敗則: 若注亂編之語法高亮,確注前綴合語。PUT 注為標注,當不影碼執行。
第五步:驗注
行 putior 驗以察注語法與連。
# Scan annotated files
workflow <- put("./src/", validate = TRUE)
# Check for validation issues
print(workflow)
cat(sprintf("Total nodes: %d\n", nrow(workflow)))
# Verify connections by checking input/output overlap
inputs <- unlist(strsplit(workflow$input, ",\\s*"))
outputs <- unlist(strsplit(workflow$output, ",\\s*"))
connected <- intersect(inputs, outputs)
cat(sprintf("Connected data flows: %d\n", length(connected)))
# Generate diagram to visually inspect
cat(put_diagram(workflow, theme = "github", show_source_info = TRUE))
# Merge with auto-detected for maximum coverage
merged <- put_merge("./src/", merge_strategy = "supplement")
cat(put_diagram(merged, theme = "github"))
得: 諸注皆析無訛。圖示連之工作流。put_merge() 補自察之隙。
敗則: 常驗患:
- 閉引闕:
id:'name→id:'name' - 內用雙引:
id:"name"→id:'name' - 跨檔重 ID:每
id於掃目內必獨 - 反斜續於誤行:
\必為換行前末字
驗
- 每注檔有語法有效 PUT 注
-
put("./src/")返期節數之數框 - 掃目無重
id -
put_diagram()生連之流圖(非諸離節) - 多行注(若用)正析附反斜續
-
.internal量只為出,勿為跨檔入 - 經
exclude排之檔不現於工作流(如put("./src/", exclude = "test_")跳試助)
陷
- 引套誤:PUT 注用單引:
id:'name'。雙引於串境致析患 - 重 ID:每
id於掃範內必全獨。用如<script>_<step>之命約(如extract_read、transform_clean) .internal為跨檔入:.internal量只於本執行時存。本間傳數用持檔式(.rds、.csv、.parquet)為一本之出、他本之入- 連闕:若圖示離節,察一注之出檔名與他注之入檔名全合(含擴)
- 誤注前綴:SQL 檔用
#或 Python 用//致注被視為碼。恆以get_comment_prefix()驗 - 忘多行續:多行注每續行必以
\終,下行必以注前綴始 - Python 三引號串:putior 不掃 Python 三引號串(
''' '''、""" """)。Python PUT 注恆用# - 元管道注:若注亦掃注之建本(如呼
put()與put_diagram()之本),本自之注現於所生圖。或從掃排此檔(見generate-workflow-diagram常陷),或勿於建本置 PUT 注
參
analyze-codebase-workflow— 前置:生此技所循之注計generate-workflow-diagram— 下步:自注生終圖install-putior— 注前 putior 必裝configure-putior-mcp— MCP 工具供互注助
GitHub Repository
Related Skills
content-collections
MetaThis skill provides a production-tested setup for Content Collections, a TypeScript-first tool that transforms Markdown/MDX files into type-safe data collections with Zod validation. Use it when building blogs, documentation sites, or content-heavy Vite + React applications to ensure type safety and automatic content validation. It covers everything from Vite plugin configuration and MDX compilation to deployment optimization and schema validation.
polymarket
MetaThis skill enables developers to build applications with the Polymarket prediction markets platform, including API integration for trading and market data. It also provides real-time data streaming via WebSocket to monitor live trades and market activity. Use it for implementing trading strategies or creating tools that process live market updates.
creating-opencode-plugins
MetaThis skill helps developers create OpenCode plugins that hook into 25+ event types like commands, files, and LSP operations. It provides the plugin structure, event API specifications, and implementation patterns for JavaScript/TypeScript modules. Use it when you need to intercept, monitor, or extend the OpenCode AI assistant's lifecycle with custom event-driven logic.
sglang
MetaSGLang is a high-performance LLM serving framework that specializes in fast, structured generation for JSON, regex, and agentic workflows using its RadixAttention prefix caching. It delivers significantly faster inference, especially for tasks with repeated prefixes, making it ideal for complex, structured outputs and multi-turn conversations. Choose SGLang over alternatives like vLLM when you need constrained decoding or are building applications with extensive prefix sharing.
