Community写作与编辑github.com

andr-ca/agentharness

用于编码代理的可移植工程策略——git、测试、日志记录和语言约定,编写一次,随处引用

agentharness 是什么?

该技能为编码代理提供了统一、可移植的工程规范,涵盖 Git 工作流、测试标准、日志记录和语言约定。其核心日志模块为不同项目阶段(原型、内部工具、生产)定义了严格的日志级别(TRACE 到 CRITICAL)和结构化日志实践,强制使用静态消息标签和结构化字段,而非字符串插值,从而提升日志的可查询性与可分析性。该技能支持 YAML 配置模板,可轻松切换本地开发环境(人类可读格式)与生产环境(JSON 格式),并内置日志轮转和多后端(文件、控制台、OTEL)支持。此外,它明确禁止记录密码、令牌、API 密钥等敏感信息,要求在日志记录前进行脱敏或省略。该技能广泛适用于 Claude Code、Coder、Cursor 等 AI 编码代理,确保代理在不同项目和语言中遵循一致的工程标准,减少重复配置,提高代码质量和可维护性。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add andr-ca/agentharness

Installed? Explore more 写作与编辑 skills: steipete/notion, langchain-ai/langchain, bytedance/podcast-generation · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

Logging

This skill is self-contained for day-to-day use. Deeper reference (needs the full harness checkout): patterns/logging/LOGGING_STANDARDS.md (full mandate and config schema), patterns/logging/logging.yaml.example (tested YAML template), patterns/logging/config_loader.py (Python reference implementation with 99% test coverage).

When this applies

Full structured logging with YAML config, multiple backends, and rotation is required at Production tier. Prototypes: print()/console.log() is fine. Internal tools: structured logging recommended, single-backend acceptable. Check the project's rigor tier first.

Log levels — pick the right one

LevelUse for
TRACEHigh-frequency per-call details; disabled in production by default
DEBUGDeveloper diagnostic info; disabled in production by default
INFONormal operational events (startup, request completed)
WARNINGSomething unexpected but recoverable; worth investigating
ERRORA real failure that the system couldn't recover from
CRITICALThe process must stop or data is corrupted

Rule of thumb: if you'd page someone at 3am, it's ERROR or CRITICAL.

Structured logging: message + fields, never string interpolation

# WRONG: unstructured — can't query or filter by user_id or duration
logger.info(f"Request completed for user {user_id} in {duration}ms")

# RIGHT: message is a static label; context is in structured fields
logger.info("request.completed", user_id=user_id, duration_ms=duration)
// Node/pino/winston equivalent
logger.info({ userId, durationMs }, 'request.completed');

What NOT to log

Never log: passwords, tokens, API keys, full credit card numbers, SSNs, session IDs, or any data under a PII/GDPR policy. Redact or omit before logging. If logging usefulness and secrecy conflict, redact. Do not log the secret "for completeness."

# WRONG: logs the raw token
logger.info("auth.token_issued", token=issued_token)

# RIGHT: log only what's safe to expose
logger.info("auth.token_issued", user_id=user_id, expires_at=exp)

Configuration: YAML template, not hand-rolled

Copy patterns/logging/logging.yaml.example as your starting point:

cp patterns/logging/logging.yaml.example config/logging.yaml

The template supports ${VAR:-default} interpolation, multiple handler backends (file, console, OTEL), and rotation. Hand-rolling a logging schema from scratch duplicates tested work.

Verification before marking work complete

  1. Run the code path and confirm log lines actually emit — don't assume.
  2. Pipe a log line through jq (or equivalent) to confirm it's valid JSON (or whatever your configured format is).
  3. State in the PR description which events you verified emit correctly.

Local vs. production output

Local/dev: human-readable (pretty / dev format, colorized). Production: machine-parseable JSON, no color codes. Configure this via an environment variable, not a code branch:

handlers:
  console:
    formatter: ${LOG_FORMAT:-json}   # override to 'pretty' in dev

相关技能