excalidraw-plugin: parsed
tags: [excalidraw]
---
==⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠== You can decompress Drawing data with the command palette: 'Decompress current Excalidraw file'. For more info check in plugin settings under 'Saving'
✅ 简单直接回答你的问题:
在图片里的 AGENTS.md 规则中,**“Command” 指的就是 AI Coding Agent(Codex CLI)在终端里执行的 shell 命令**。
它不是你手动敲的命令,而是 AI 自己决定要执行的命令,用来感知项目、读取代码、构建、测试、git 操作等。
Codex(以及 Cursor、Aider、Windsurf、Hermes 等 agent)的工作模式是:
AI 不是直接改代码,而是先通过执行各种终端命令来“看”你的项目,然后再决定怎么修改。
所以 Command = AI 主动调用的 shell 指令。
| 类型 | 典型 Command 示例 | 输出特点 | 是否需要 byte cap? | 说明 |
|---|---|---|---|---|
| 探索项目结构 | find . -name "*.swift", ls -la Sources/, tree |
可能非常大 | 强烈需要 | 大项目里文件成百上千 |
| 读取代码 | cat Sources/Apptag/AppDelegate.swift, cat Package.swift |
文件越大输出越大 | 需要(除非很确定文件很小) | 这是最常见的触发 token 消耗的操作 |
| Git 操作 | git log --oneline, git diff, git show HEAD |
历史越多越大 | 需要 | git log 不加限制很容易几万行 |
| 构建 / 编译 | swift build, xcodebuild -scheme Apptag build, swift package resolve |
日志经常很 verbose | 需要 | 构建日志经常有几千行 |
| 依赖 / 环境检查 | swift package show-dependencies, which swift, xcodebuild -list |
中等大小 | 建议 cap | 保险起见 |
| 测试 / 运行 | swift test, xcodebuild test |
输出可能很大 | 需要 | 测试失败日志特别长 |
| 安全小命令 | pwd, git status, echo "test", ls(小目录) |
输出很小 | 不需要 | 可以直接执行 |
图片里的核心规则是:
Any command with unknown or potentially large output must be byte-capped.
意思是:**凡是输出未知或可能很大的命令,必须先做字节截断**。
默认写法:bash COMMAND 2>&1 | head -c 4000
关键点解析:
2>&1:把错误输出(stderr)也一起捕获,不然错误信息可能会漏掉或单独爆炸。head -c 4000:按**字节**截断前 4000 字节(约 4KB),而不是按行数。AGENTS.md 让 AI 自动遵守。这正是标题说的「只靠 AGENTS.md 一条规则就能省 40%-50% token」的原因——很多时候 AI 其实不需要看完整输出,前面一小部分就已经够它判断了。
推荐做法:
Apptag 项目根目录创建一个 AGENTS.md 文件(如果还没有的话)。6000 或 8000),因为你做 macOS App,有时候想多看一点构建日志或 Swift 文件内容。swift build / xcodebuild 而不是直接操作 .xcodeprojgit status 和 git diffhead -c示例(你可以直接复制使用):
## Command Output
Protect context usage. **Any command with unknown or potentially large output must be byte-capped.**
Default pattern:
COMMAND 2>&1 | head -c 6000
```
swift build 或 xcodebuildgit status 和 git diff总结:
AGENTS.md 后,Codex 就会**自动**给危险命令加 | head -c xxxx。需要我帮你写一个**完整版、适合你 Apptag 项目的 AGENTS.md**(包含 byte cap + Swift/macOS 专用规则 + git 工作流规则)吗?可以直接给你一个优化后的版本。
这里说的命令是啥? ^MVIaYBfC
rIEDYU1Q: [[DS/AI-vibe-coding/Agent.md/Drawing 26.0525.excalidraw.md#command是啥]]
576efc5c49a904d7fda09f7d439cd31d3e879fdd: [[X.Attachment/Pasted Image 20260525061319_361.png]]
%%
{
"type": "excalidraw",
"version": 2,
"source": "https://github.com/zsviczian/obsidian-excalidraw-plugin/releases/tag/2.26.4",
"elements": [
{
"id": "rIEDYU1Q",
"type": "embeddable",
"x": -3214.8860136153885,
"y": -44.01948628546188,
"width": 1537.550778921821,
"height": 1368.3696149604189,
"angle": 0,
"strokeColor": "#000000",
"backgroundColor": "transparent",
"fillStyle": "hachure",
"strokeWidth": 1,
"strokeStyle": "solid",
"roughness": 1,
"opacity": 100,
"roundness": null,
"seed": 75457,
"version": 317,
"versionNonce": 2058556918,
"updated": 1779661600603,
"isDeleted": false,
"groupIds": [],
"boundElements": [],
"link": "[[DS/AI-vibe-coding/Agent.md/Drawing 26.0525.excalidraw.md#command是啥]]",
"locked": false,
"frameId": null,
"hasTextLink": false,
"scale": [
1,
1
],
"customData": {
"mdProps": {
"useObsidianDefaults": false,
"backgroundMatchCanvas": false,
"backgroundMatchElement": true,
"backgroundColor": "#fff",
"backgroundOpacity": 60,
"borderMatchElement": true,
"borderColor": "#fff",
"borderOpacity": 0,
"filenameVisible": false
}
},
"index": "a0"
},
{
"id": "fJTi6oXU",
"type": "image",
"x": -1495.8129533185067,
"y": -950.6327765023773,
"width": 820.273596211439,
"height": 957.6337876781254,
"angle": 0,
"strokeColor": "transparent",
"backgroundColor": "transparent",
"fillStyle": "solid",
"strokeWidth": 2,
"strokeStyle": "solid",
"roughness": 1,
"opacity": 100,
"groupIds": [],
"frameId": null,
"index": "a1",
"roundness": null,
"seed": 1146352135,
"version": 128,
"versionNonce": 301936423,
"isDeleted": false,
"boundElements": [],
"updated": 1779660859336,
"link": null,
"locked": false,
"status": "pending",
"fileId": "576efc5c49a904d7fda09f7d439cd31d3e879fdd",
"scale": [
1,
1
],
"crop": null,
"hasTextLink": false
},
{
"id": "icMkfE70",
"type": "ellipse",
"x": -1124.2037634627256,
"y": -113.01442401669232,
"width": 72.70670725027355,
"height": 45.90000527469658,
"angle": 0,
"strokeColor": "#e03131",
"backgroundColor": "transparent",
"fillStyle": "solid",
"strokeWidth": 2,
"strokeStyle": "solid",
"roughness": 1,
"opacity": 100,
"groupIds": [],
"frameId": null,
"index": "a2",
"roundness": {
"type": 2
},
"seed": 596178057,
"version": 90,
"versionNonce": 523417033,
"isDeleted": false,
"boundElements": [
{
"id": "PTDJt3Dq",
"type": "arrow"
}
],
"updated": 1779660868303,
"link": null,
"locked": false,
"hasTextLink": false,
"customData": {
"legacyTextWrap": true
}
},
{
"id": "PTDJt3Dq",
"type": "arrow",
"x": -1128.118112308146,
"y": -99.03720116826618,
"width": 612.3460822285062,
"height": 71.74603822244849,
"angle": 0,
"strokeColor": "#e03131",
"backgroundColor": "transparent",
"fillStyle": "solid",
"strokeWidth": 2,
"strokeStyle": "solid",
"roughness": 1,
"opacity": 100,
"groupIds": [],
"frameId": null,
"index": "a3",
"roundness": {
"type": 2
},
"seed": 293768425,
"version": 138,
"versionNonce": 2120154791,
"isDeleted": false,
"boundElements": [],
"updated": 1779661607230,
"link": null,
"locked": false,
"points": [
[
0,
0
],
[
-612.3460822285062,
-71.74603822244849
]
],
"startBinding": {
"elementId": "icMkfE70",
"mode": "orbit",
"fixedPoint": [
0.9999999999999984,
0.5001
]
},
"endBinding": {
"elementId": "MVIaYBfC",
"mode": "orbit",
"fixedPoint": [
1,
0.5001
]
},
"startArrowhead": null,
"endArrowhead": "arrow",
"elbowed": false,
"moveMidPointsWithElement": false,
"hasTextLink": false
},
{
"id": "MVIaYBfC",
"type": "text",
"x": -2272.694175005402,
"y": -208.04244195378425,
"width": 526.22998046875,
"height": 73.09779558250918,
"angle": 0,
"strokeColor": "#e03131",
"backgroundColor": "transparent",
"fillStyle": "solid",
"strokeWidth": 2,
"strokeStyle": "solid",
"roughness": 1,
"opacity": 100,
"groupIds": [],
"frameId": null,
"index": "a4",
"roundness": null,
"seed": 1216333129,
"version": 124,
"versionNonce": 796299719,
"isDeleted": false,
"boundElements": [
{
"id": "PTDJt3Dq",
"type": "arrow"
}
],
"updated": 1779661607230,
"locked": false,
"text": "这里说的命令是啥?",
"rawText": "这里说的命令是啥?",
"fontSize": 58.47823646600734,
"fontFamily": 5,
"textAlign": "left",
"verticalAlign": "top",
"containerId": null,
"originalText": "这里说的命令是啥?",
"autoResize": true,
"lineHeight": 1.25,
"hasTextLink": false,
"link": null,
"customData": {
"legacyTextWrap": true
}
}
],
"appState": {
"theme": "light",
"viewBackgroundColor": "#ffffff",
"currentItemStrokeColor": "#e03131",
"currentItemBackgroundColor": "transparent",
"currentItemFillStyle": "solid",
"currentItemStrokeWidthKey": "bold",
"currentItemStrokeVariability": "constant",
"currentItemStrokeStyle": "solid",
"currentItemRoughness": 1,
"currentItemOpacity": 100,
"currentItemFontFamily": 5,
"currentItemFontSize": 20,
"currentItemTextAlign": "left",
"currentItemStartArrowhead": null,
"currentItemEndArrowhead": "arrow",
"currentItemArrowType": "round",
"currentItemFrameRole": null,
"scrollX": 3527.105201745457,
"scrollY": 290.6210450958806,
"zoom": {
"value": 0.670982
},
"currentItemRoundness": "round",
"gridSize": 20,
"gridStep": 5,
"gridModeEnabled": false,
"gridColor": {
"Bold": "rgba(217, 217, 217, 0.5)",
"Regular": "rgba(230, 230, 230, 0.5)"
},
"currentStrokeOptions": null,
"frameRendering": {
"enabled": true,
"clip": true,
"name": true,
"outline": true,
"markerName": true,
"markerEnabled": true
},
"objectsSnapModeEnabled": false,
"activeTool": {
"type": "selection",
"customType": null,
"locked": false,
"fromSelection": false,
"lastActiveTool": null
},
"disableContextMenu": false,
"bindingPreference": "enabled",
"isBindingEnabled": true,
"isMidpointSnappingEnabled": true,
"boxSelectionMode": "contain"
},
"files": {}
}
%%