--- 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' # command是啥 **✅ 简单直接回答你的问题:** 在图片里的 `AGENTS.md` 规则中,**“Command” 指的就是 AI Coding Agent(Codex CLI)在终端里执行的 shell 命令**。 它不是你手动敲的命令,而是 **AI 自己决定要执行的命令**,用来感知项目、读取代码、构建、测试、git 操作等。 --- ### 在 Vibe Coding(AI 辅助编码)场景里,Command 具体是什么? Codex(以及 Cursor、Aider、Windsurf、Hermes 等 agent)的工作模式是: > **AI 不是直接改代码**,而是先通过执行各种终端命令来“看”你的项目,然后再决定怎么修改。 所以 **Command = AI 主动调用的 shell 指令**。 #### 常见 Command 分类举例(以你正在开发的 **Apptag** macOS App 为例): | 类型 | 典型 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 ``` **关键点解析:** 1. **`2>&1`**:把错误输出(stderr)也一起捕获,不然错误信息可能会漏掉或单独爆炸。 2. **`head -c 4000`**:按**字节**截断前 4000 字节(约 4KB),而不是按行数。 - 为什么用字节而不是行?因为一行可能有几千个字符(比如 minified 的 JS、长日志行),按行截断不靠谱。 3. **不是简单限制行数**,而是给“未知命令”做**默认 byte cap**,写进 `AGENTS.md` 让 AI 自动遵守。 这正是标题说的「只靠 AGENTS.md 一条规则就能省 40%-50% token」的原因——很多时候 AI 其实不需要看完整输出,前面一小部分就已经够它判断了。 --- ### 实际使用建议(给你当前 Codex + Apptag 项目) **推荐做法:** 1. 在你 `Apptag` 项目根目录创建一个 `AGENTS.md` 文件(如果还没有的话)。 2. 把图片里的规则放进去,并可以适当调大一点(比如 `6000` 或 `8000`),因为你做 macOS App,有时候想多看一点构建日志或 Swift 文件内容。 3. 可以再补充一些针对 Swift/macOS 的规则,比如: - 优先使用 `swift build` / `xcodebuild` 而不是直接操作 `.xcodeproj` - 修改代码前先 `git status` 和 `git diff` - 大文件读取必须加 `head -c` **示例(你可以直接复制使用):** ```markdown ## Command Output Protect context usage. **Any command with unknown or potentially large output must be byte-capped.** Default pattern: ```bash COMMAND 2>&1 | head -c 6000 ``` ## Project Specific Rules (Apptag - macOS Swift App) - 这是 macOS App 项目,主要使用 Swift + SwiftUI / AppKit - 构建命令优先使用 `swift build` 或 `xcodebuild` - 查看 Swift 文件时,如果文件较大,必须使用 byte cap - 提交前必须检查 `git status` 和 `git diff` ``` --- **总结:** - **Command** = AI 在终端里自己执行的 shell 命令(不是你手动敲的)。 - 这条规则的核心就是**防止 AI 把大输出全塞进 context**,从而大幅节省 token。 - 把这个规则写进 `AGENTS.md` 后,Codex 就会**自动**给危险命令加 `| head -c xxxx`。 需要我帮你写一个**完整版、适合你 Apptag 项目的 AGENTS.md**(包含 byte cap + Swift/macOS 专用规则 + git 工作流规则)吗?可以直接给你一个优化后的版本。 # 这个例子要照抄吗 # 这个例子要照抄吗 # 例子要照抄吗 # Excalidraw Data ## Text Elements 这里说的命令是啥? ^MVIaYBfC ## Element Links rIEDYU1Q: [[DS/AI-vibe-coding/Agent.md/Drawing 26.0525.excalidraw.md#command是啥]] ## Embedded Files 576efc5c49a904d7fda09f7d439cd31d3e879fdd: [[X.Attachment/Pasted Image 20260525061319_361.png]] %% ## Drawing ```json { "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": {} } ``` %%