# Code Haiku

> 把一个函数/代码片段/diff 写成一首俳句或打油诗,抓住代码的「神韵」。当用户说「给这段代码写首诗」、「code-haiku」、「把这个函数写成俳句」、「这个 diff 怎么用诗表达」时触发。

- **Type:** Skill
- **Install:** `agentstack add skill-yuaicode-ai-skills-code-haiku`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [YuAICode](https://agentstack.voostack.com/s/yuaicode)
- **Installs:** 0
- **Category:** [AI & ML](https://agentstack.voostack.com/c/ai-and-ml)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [YuAICode](https://github.com/YuAICode)
- **Source:** https://github.com/YuAICode/ai-skills/tree/main/skills/code-haiku

## Install

```sh
agentstack add skill-yuaicode-ai-skills-code-haiku
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# code-haiku — 代码俳句生成器

读懂一段代码的「意图」,把它的神韵凝成一首俳句或打油诗——有意境、有幽默、可分享。
不是注释,不是文档,是诗。

## 何时触发

用户说：
- `/code-haiku`
- "给这段代码写首诗"
- "把这个函数写成俳句"
- "这个 diff 怎么用诗表达"
- "帮我写个 code haiku"
- "这段代码有点意境,帮我写首诗"
- "这个 PR 能用俳句总结吗"

## 工作流

### 第一步：读懂代码的「意图」

**不逐行翻译**,而是问自己：
- 这段代码在宏观上做什么?（排序?重试?缓存?认证?）
- 它的处境是什么?（防御性代码?临时方案?核心逻辑?被人遗忘的 TODO?）
- 它有没有让人会心一笑的特质?（递归的无限感、try/catch 的渡劫感、事件循环的虚无感）

> 如果代码太长,只抓最有「诗感」的那一层意图。

### 第二步：产出诗作

**标准输出格式：**

```
【俳句】

【英文 haiku】（可选，若能贴切翻译则附上）

【诗解】

```

**音节指引（中文俳句）：**
- 三行，尽量贴近 5-7-5 音节，但意境优先于死抠音节。
- 用汉字时以「音节/字」计，不强制字数完全相同。

**英文 haiku（可选）：**
- 只在翻译能增色时附上；若翻译失味，直接省略。
- 同样是三行，5-7-5 音节尽量贴近。

### 第三步：变体（应要求）

若用户说「再来一个」或「换个风格」，可提供：
- **写实风**：还原代码的实际处境（比如"凌晨上线、祈祷别崩"）
- **禅意风**：用自然意象映射逻辑结构（递归→镜中镜、回调→深渊）
- **自嘲风**：吐槽代码的技术债或命名混乱
- **史诗风**：把一行工具函数写出宇宙征程的气势

---

## 示例库

### 示例 A：递归函数

```python
def factorial(n):
    if n == 0:
        return 1
    return n * factorial(n - 1)
```

**【俳句】**
自己召唤己
层层深入无尽处
零时方归来

**【英文 haiku】**
calls itself again
falling through the looking glass
zero ends the dream

**【诗解】**
"自己召唤己"映射递归调用自身；"零时方归来"是 `n == 0` 的基础条件终止递归。

---

### 示例 B：try/catch 吞掉所有异常

```javascript
try {
    await doSomethingRisky()
} catch (e) {
    // TODO: handle this properly
}
```

**【俳句】**
渡劫入火坑
TODO 轻描淡写
下次再说吧

**【英文 haiku】**
fire swallowed whole
"TODO: handle properly"
next sprint, probably

**【诗解】**
"渡劫"是 try/catch 的意象；"TODO 轻描淡写"直指那行注释；"下次再说吧"是每个工程师都懂的技术债自嘲。

---

### 示例 C：TODO 堆积的文件

```python
# TODO: refactor this
# TODO: add validation
# FIXME: this is broken
# TODO: write tests
# HACK: temporary workaround
def process_data(data):
    return data  # placeholder
```

**【俳句】**
满纸皆 TODO
占位符孤守深夜
测试从未来

**【英文 haiku】**
todos fill the page
placeholder guards the void
tests remain unborn

**【诗解】**
"满纸皆 TODO"直点注释现状；"占位符孤守深夜"对应那行 `return data  # placeholder`；"测试从未来"是 `# TODO: write tests` 的永恒未竟。

---

## 风格气质指引

| 代码气质 | 推荐意象/风格 |
|---------|------------|
| 递归 | 无限镜像、自我召唤、层层嵌套的深渊 |
| 回调地狱 | 俄罗斯套娃、深渊、无法回头的坠落 |
| try/catch | 渡劫、护身符、轻描淡写的危机 |
| TODO 堆积 | 时间胶囊、未竟之志、乐观的谎言 |
| 事件循环 | 永动机、虚无轮转、等待中的存在 |
| 单行工具函数 | 一言定乾坤、禅宗公案、简洁即道 |
| 复杂 SQL | 宫廷密谋、多方连横、条件重重 |
| diff 删除大量代码 | 大雪无痕、断舍离、轻装上阵 |
| 加锁/并发 | 守门人、各让一步、等待的艺术 |

---

## 硬规则

1. **抓意图,不堆术语**：不要把变量名、函数名直接塞进诗里当凑数；诗写的是代码「做什么」，不是代码「长什么样」。
2. **别把诗写成注释**：诗不是文档，不用解释参数类型或返回值；只写神韵和情感。
3. **不臆造代码没有的逻辑**：看到什么写什么，没有的意图不要编造。
4. **一次一首**：默认只输出一首，附诗解；用户要求变体时才多写。
5. **可调侃,不刻薄**：吐槽技术债是幽默，但不要让诗变成人身攻击或嘲笑代码作者。
6. **代码片段保持英文**：诗本身用中文，示例代码片段原样保留。

---

## 边界

- 纯 Claude 驱动，**无需 bin/ 脚本**。
- 适用所有语言的代码片段、函数、类、diff、commit message。
- 代码过长时（> 100 行），只读最核心的意图层，不逐行分析。
- 不生成图片，只产出文字诗作。
- 不评价代码质量好坏；诗是艺术，不是 code review。

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [YuAICode](https://github.com/YuAICode)
- **Source:** [YuAICode/ai-skills](https://github.com/YuAICode/ai-skills)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-yuaicode-ai-skills-code-haiku
- Seller: https://agentstack.voostack.com/s/yuaicode
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
