AgentStack
Browse Sign in
Browse Why AgentStack Sell Docs
Sign in
SKILL verified MIT Self-run

Cc Harness Patterns

skill-cablate-ai-toolkit-cc-harness-patterns · by cablate

Harness Engineering 設計模式 — 基於 Claude Code 原始碼逆向分析的 12 條可遷移原則。Use when: 設計 agent 系統架構、實作 tool orchestration、設計 context 管理策略、建構 agent loop。

— No reviews yet
0 installs
36 views
0.0% view→install

Install

$ agentstack add skill-cablate-ai-toolkit-cc-harness-patterns

✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • ✓ Prompt-injection patterns
  • ✓ Secret / credential exfiltration
  • ✓ Dangerous shell & filesystem operations
  • ✓ Untrusted network calls
  • ✓ Known-malicious package signatures

What it can access

  • ✓ Network access No
  • ✓ Filesystem access No
  • ✓ Shell / process execution No
  • ✓ Environment & secrets No
  • ✓ Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

View the full security report →

Verified badge

Passed review? Show it. Paste this badge into your README, it links to the public security report.

AgentStack Verified badge Links to your public security report.
[![AgentStack Verified](https://agentstack.voostack.com/badges/verified.svg)](https://agentstack.voostack.com/security/report/skill-cablate-ai-toolkit-cc-harness-patterns)

Reliability & compatibility

✓ Security review passed
0 installs to date
— no reviews yet
○ 5mo ago

Declared compatibility

Claude CodeClaude Desktop

Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.

Preview Execution monitoring

We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.

How agent discovery & health will work →
Are you the author of Cc Harness Patterns? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

Harness Engineering 設計模式

Harness = Tools + Knowledge + Observation + Action Interfaces + Permissions

基於 Claude Code v2.1.88(92,500 行 TypeScript)逆向分析。

1. Agent Loop:Async Generator 模式

Claude Code 的 agent loop 用 async generator 實作:

async function* queryModel(...): AsyncGenerator {
  // yield 每個 stream event,呼叫端按需消費
}

核心循環:queryModel() → 檢查 stop_reason → tool_use 時呼叫 runTools() → 結果回注 messages → 再次 queryModel()

stop_reason 分支:end_turn(結束)、tool_use(執行工具)、max_tokens(context 滿了,觸發 compaction)

2. Tool Orchestration:讀寫分離

function isConcurrencySafe(input): boolean {
  // 工具自己聲明是否可並行
}
  • partitionToolCalls() 把一批工具呼叫分成可並行組和必須串行組
  • 讀工具自動合批並行(FileRead、Grep、Glob)
  • 寫工具強制串行(FileEdit、FileWrite、Bash)
  • 決策權在工具端(Single Responsibility),不在 orchestrator

3. 工具執行 7 層管道

Schema Validation → Custom validateInput() → Input Sanitization
→ PreToolUse Hooks → Permission Resolution → Execution → PostToolUse Hooks

每層只問一個問題:「能否拒絕?」拒絕即停,不往下走。執行邏輯永遠在最後一層。

4. Cache 穩定性模式

Sticky Latch:影響 cache key 的欄位一旦啟用就不在 session 內關閉。

if (!fastModeHeaderLatched && isFastMode) {
  fastModeHeaderLatched = true  // 永遠 latched
}

確定性 ID:注入 context 的 ID 從穩定輸入衍���,不隨機生成。

靜態/動態邊界:SYSTEM_PROMPT_DYNAMIC_BOUNDARY 把 prompt 分成可全域快取的靜態段和 session 特定的動態段,防 2^N 快取桶爆炸。

Attachment > Inline:動態 agent 列表從 tool description 移到 attachment message,避免 MCP 連接/plugin 載入導致 tool schema cache bust。省 fleet 10.2% cache creation tokens。

5. Context Engineering

原則:什麼進 context、什麼順序、何時壓縮。

  • 訊息處理管道 normalizeMessagesForAPI:10 步處理(過濾空訊息、合併連續同角色、注入 system-reminder、truncate 過長結果...)
  • Compaction 三模式:BASE(全壓)、PARTIALFROM(從某點壓)、PARTIALUP_TO(壓到某點)
  • `` 草稿:讓模型在 scratchpad 思考,結果不進 context
  • Deferred Tool Loading:36 個工具不全塞 prompt,ToolSearch 按需載入 schema

6. Multi-session Continuity

  • Forked Agent:子 agent 繼承父 session 的 prompt cache(Memory extraction、AgentSummary、Dream 都用此模式)
  • progress log:跨 context window 的進度檔(claude-progress.txt)
  • AutoDream:背景記憶整合,三層閘門(時間≥24h + session≥5 + 檔案鎖),四階段 consolidation prompt

7. Observability

  • 三層追��:Analytics(業務事件)/ OpenTelemetry(效能)/ DiagnosticTracking(per-turn 計數器)
  • PII 安全型別:PiiSafeString 型別系統,編譯期防止 PII 進入遙測
  • Frustration Signal:追蹤使用者 swearing、重複 "continue" prompt,路由至 Datadog

參考

詳見 references/design-principles.md。

Source & license

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

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

Reviews

No reviews yet, be the first.

Versions

  • v0.1.0 Imported from the upstream source.