Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx agentmods add instructions/zhangshenao/harness9/agents-mdgit clone --depth 1 https://github.com/ZhangShenao/harness9Wrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/instructions/zhangshenao/harness9/agents-md)<a href="https://agentmods.dev/instructions/zhangshenao/harness9/agents-md"><img src="https://agentmods.dev/badge/instructions/zhangshenao/harness9/agents-md.svg" alt="Measured on agentmods" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5 | $0.17330 | $0.17330 |
| Opus 5 | $0.08665 | $0.08665 |
| Sonnet 5 | $0.03466 | $0.03466 |
| Haiku 4.5 | $0.01733 | $0.01733 |
Grade A, and why
harness9 AGENTS.md scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 750 lines — stays where its author put it; the contents beside it link to each section on GitHub.
AGENTS.md — harness9 项目开发指南
1. 项目概述
harness9 是一款基于 Go 语言构建的轻量级、功能完备、生产可用的 Agent Harness 框架,旨在提供简洁、高效、可扩展的 Agent 编排能力。
核心设计理念
| 原则 | 说明 |
|---|---|
| 简洁 | 最小化抽象层,代码直白易读;极少的直接依赖数 |
| 完备 | 覆盖 Agent 运行所需的全部核心模块(Engine / Provider / Schema / Tools / Env) |
| 生产可用 | 错误恢复、上下文管理、超时控制、并发工具执行、Path Traversal 防护等生产级特性 |
核心架构
- 标准 ReAct: 每个 Turn 执行一次 LLM 调用(携带完整工具列表),工具调用结果作为 Observation 注入上下文
- 并发工具执行: 同 Turn 内多个工具调用并发执行,每工具独立超时控制
- 双模式运行: 阻塞式
Run+ 流式RunStream,共享同一引擎实例 - 自愈能力: 工具执行失败时,错误信息原样回传给 LLM,触发自动重试
- 双重压缩策略: SummarizationCompactor(默认,LLM 摘要,保留语义 + 增量更新)和 TokenBudgetCompactor(回退,字符截断),均在 80% 阈值触发,双向修复孤立工具对
- 实际 Token 用量: 从 API 响应 usage 字段提取,LLM 调用后实时更新 TUI 展示
- Planning(先规划后执行): Plan Mode(工具层权限过滤)+ TodoStore(状态机校验)+ 自动续跑 + 停滞检测
- Sub-Agent(子代理委派): 主代理通过
task工具把边界清晰的子任务委派给运行在隔离 Session 上的专门子代理(独立上下文 + 受限工具集 + 可选模型覆盖);内置 general-purpose 通用子代理(对标 Claude Code / DeepAgents,继承父全部可用工具与模型),支持.harness9/agents/*.md文件式定义、前台/后台双模式、@agent直跑、TaskTracker 后台任务管理;安全保障:禁止递归 + 权限只能更严不能扩权 + 上下文完全隔离 - 文件系统能力: OffloadHook(超大工具输出自动写入文件,context 保留摘要引用 + 分页检索)+ FilePlanWriter(todo 计划持久化到 markdown)+ DeleteSession 级联 GC
- 推理内容展示(Reasoning Display): Anthropic extended thinking(StreamChunkThinkingDelta)和 OpenRouter/DeepSeek reasoning_content 均路由为 EventThinkingDelta,TUI 以
│前缀深灰色块流式渲染,与正文回复形成视觉层次区分 - Shell 执行(
!前缀): 输入框以!开头进入 Shell 模式,命令通过bash -c异步执行(30s 超时),输出 inline 追加到对话流,并在下次 LLM dispatch 时前置注入为上下文;已知交互式命令(vim/ssh 等)自动拦截 - Human-in-the-Loop 权限控制: HookDecision(allow/deny/ask)三级决策 + DangerHook(19 条高危模式)+ PermissionHook(JSON 白名单,按需重载)+ 敏感路径硬保护(
/.ssh、/.aws 等)+ TUI 五选项审批对话框 + PermissionMode 枚举 - Long-Term Memory(跨会话长期记忆):
internal/ltm/包;SQLitelong_term_memories+ standalone FTS5memories_fts,复用state.db连接;MEMORY.md 物化视图(top-N 有界注入,≤5KB,规避 token bomb)+memory_search按需 FTS5 检索;三路触发:显式memory_write/memory_search工具 + 压缩前Extractor(LLM 提取,fail-open)+WithMemoryNudge(每 N 轮注入提示,防御性副本,不持久化);SHA256 内容签名去重 + TTL 过期 + 软删除(signature=NULL 释放槽位)+ 命中强化(use_count/last_used_at)+ 陈旧识别(StaleCandidates);Phase 3 接缝:Provider/Embedder/Consolidator 接口 + noopProvider - Sandbox(Docker 容器级隔离):
internal/sandbox/包;Environment接口(LocalEnvironment 进程级 / DockerEnvironment 容器级)+Container五状态生命周期(Pending→Running→Stopping→Terminated/Failed)+Manager(Create/Destroy/DestroyAll/ReapOrphans/ListAll,并发安全);工具透明路由(bash 命令通过 docker exec 进容器,文件工具通过 bind mount 共享 workDir);安全加固:--cap-drop all+--cap-add DAC_OVERRIDE/SETUID/SETGID(包管理器所需最小能力)+--security-opt no-new-privileges:true+--pids-limit 256+ tmpfs nosuid/noexec/nodev;Agent 级隔离(主 Agent 和每个 Sub-Agent 各自拥有独立容器);TUI SandboxBar 实时展示状态(颜色编码);label=harness9=1标记 + 启动时孤儿回收;SANDBOX_ENABLED=false时关闭(默认启用,Docker 不可用自动降级为本地进程模式),关闭时行为与引入前完全一致(向后兼容) - Observability(OpenTelemetry 可观测性):
internal/observability/包;三条非侵入式接入路径——OTELEngineObserver(实现EngineObserver接口,管理 Interaction Span + Turn Span)+TracingProvider(包装LLMProvider,为每次 LLM 调用创建 Span + Token Metrics)+ObservabilityHook(实现ToolHook,为每次工具调用创建 Span);Span 四层嵌套:harness9.interaction → harness9.turn → harness9.llm_request / harness9.tool;6 个关键 Metrics(LLM 延迟/Token 消耗/工具调用次数/工具执行耗时/Turn 总数);langfuse.trace.input(trace 根节点 prompt)/langfuse.observation.input/output(observation 层 LLM 消息与回复 + 工具参数与结果)/gen_ai.usage.*(Token 用量,Langfuse 自动换算费用);非法 UTF-8 字节自动净化,防止 OTLP 序列化失败;三种 Exporter:noop(默认零开销)/stdout(开发调试)/otlp(生产接入 Langfuse / Grafana / Jaeger);通过环境变量OTEL_ENABLED/OTEL_EXPORTER_TYPE/OTEL_EXPORTER_OTLP_ENDPOINT驱动,默认关闭向后兼容 - 网页搜索与抓取:
internal/tools/web_search.go/web_fetch.go/web_safety.go/web_content.go;web_search工具(DuckDuckGo HTML 端点 POST,无 API Key,20s 超时 + 10s dial 超时,golang.org/x/net/htmlDOM 解析,decodeUDDG还原真实 URL)+web_fetch工具(HTTP GET,15s 超时,5 次重定向上限,text/html→go-readability提取主内容 →html-to-markdown转 Markdown,text/*→ 原始文本,其他 → 不支持提示);isSafeURL共享 SSRF 安全门(scheme + userinfo + DNS 解析 + 9 个 IP 段检查(含 IPv6 ULAfc00::/7和链路本地fe80::/10)+ IPv4-mapped IPv6 规范化 + IPv6 loopback,DNS 失败 fail-closed,重定向链每跳复检);DefaultPromptBuilder实时注入当前日期:YYYY-MM-DD,防止 LLM 因训练截止日期偏差产生陈旧搜索词;主 Agent + 所有 Sub-Agent 均可使用,零额外配置 - Test & Eval(自动化测试与评估):
internal/evals/包;ScriptedProvider(确定性 LLM mock,按预设 Turn 序列返回回复,不发起真实 API 调用)+Assertion接口(Hard 断言:ToolCalled/ToolNotCalled/OutputContains/OutputExcludes/NoError/Error;Soft 断言:MaxTurns/MaxToolCalls,仅记警告不影响通过率)+EvalHarness(RunCase构建最小化隔离引擎 +recordingHook记录工具调用轨迹 +Suite批量运行)+SetupHermeticEnv(清除所有 API Key,标准 Hermetic 隔离环境(密封测试,防止 eval 调用真实 API),本地与 CI 环境一致)+BuildReport/WriteJSON/WriteMarkdown(JSON + Markdown 评估报告生成);internal/evals/dataset/黄金数据集(22 个用例:工具调用准确性 × 6 + Planning 完成率 × 4 + Context Engineering × 4 + Error Handling/Self-Healing × 3 + Memory 持久化 × 2 + Context Compaction × 3);.github/workflows/eval.ymlCI Quality Gate(PR 触发 hermetic eval,失败则阻断合并) - MCP 工具集成(Model Context Protocol):
internal/mcp/包;JSON-RPC 2.0 over stdio/HTTP;Config(.mcp.json加载,file-not-found 静默返回空)+StdioTransport(subprocess + NDJSON async reader goroutine + pending map ID 关联 + 三路 select ctx/done/response;transport_proc_unix.go独立进程组 + SIGKILL 终止 npx 孤儿 node 子进程,transport_proc_windows.gostub 回退单进程 kill)+HTTPTransport(无状态 POST)+Client(initialize → notifications/initialized → tools/list → tools/call 握手与调用)+Manager(并发 Start 30s per-server timeout,fail-soft,ServerStatus+ToolDetailsTUI 通知链,InjectTools闭包捕获避免循环变量 bug,WithNotifychannel 回调;Start始终返回 nil,失败状态通过Statuses()的StatusFailed暴露)+MCPToolAdapter(实现BaseTool接口,mcp__{server}__{tool}双下划线命名,对 Engine 完全透明);TUI MCPBar(状态栏实时展示)+/mcp模态工具面板(工具列表,e键tea.ExecProcess打开$EDITOR编辑.mcp.json;鼠标滚轮 + ↑↓/jk 双支持);.mcp.json配置文件驱动,main.go 中异步启动不阻塞 TUI 渲染;defer mcpMgr.Stop()Session 级生命周期;mcpPanelOverhead=4与contentH=m.height-4保持一致,确保面板撑满屏幕不遮挡对话区 - AutoDev(自举开发闭环):
skills/autodev/SKILL.md(/autodevAgentSkill,三阶段:需求澄清→Spec 生成与强制确认关卡→委派 dev sub-agent)+.harness9/agents/dev.md(dev sub-agent 定义:读规范→探索→实现→go build/test迭代循环(≤3 次)→gofmt→commit→push→gh pr create);git worktree(.autodev/<slug>/,代码隔离)+ Docker Sandbox(执行隔离,需SANDBOX_IMAGE=golang:1.25-bookworm);零新 Go 代码,完全由 Skill 文件 + Agent 定义文件驱动,复用现有 Skills 系统、Sub-Agent 系统、Sandbox 基础设施
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- yesterday Changed · +9 lines · +434 tokens per session db687655061c
- 5d ago First seen · 741 lines · 16,896 tokens per session scan A 4f9657d6c7c6
harness9 AGENTS.md is an instructions file published in the GitHub repository ZhangShenao/harness9 (137 stars, last pushed yesterday), licensed MIT. It adds 17,330 tokens to every session, about $0.0867 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.
Other instructions, from other repositories
vscode buildNext.instructions.md
Working notes and architecture documentation for the new esbuild-based build system in build/next. Use when making changes to the new build pipeline (transpile/bundle commands, NLS plugin, source-map handling, resource copying, or self-hosting watch tasks).
spec-kit AGENTS.md
AGENTS.md instructions for github/spec-kit, covering agents.md, about spec kit and specify, quickstart — add a new integration in 5 steps, integration architecture and integrationmanifest — file tracking.
codex AGENTS.md
AGENTS.md instructions for openai/codex, covering rust/codex-rs, the codex-core crate, code review rules, crate api surface and model visible context.
langchain AGENTS.md
AGENTS.md instructions for langchain-ai/langchain, covering global development guidelines for the langchain monorepo, corridor security analysis, project architecture and context, monorepo structure and development tools & commands.
vscode oss-third-party-notices.instructions.md
Instructions for microsoft/vscode, covering vs code oss third-party-notices pipeline, architecture, pipeline flow in ci, applying the notice (cutover) and fallback chain (never fail the build).
next.js AGENTS.md
Instructions for vercel/next.js, covering next.js development guide, codebase structure, monorepo overview, core package: packages/next and other important packages.