26 Commits
Author SHA1 Message Date
sausheong 40fb986b3f feat: MCP adapter falls back to structured content when a tool returns no text
Servers that return their result only as structuredContent (no TextContent
block) reached the agent as an empty result. Serialize StructuredContent to
JSON in that case; when text is present it still wins, since the MCP spec
has tools send the same data as text.
2026-09-30 21:04:09 +08:00
sausheong 26f81ac21f feat: exa_search tool backed by the Exa Search API
ExaSearchTool (tools/web) calls POST https://api.exa.ai/search with
query-relevant highlights, optional category, domain and published-date
filters, and the shared SSRF-safe search client.
2026-09-28 15:13:10 +08:00
sausheong d47a71f779 feat: Stagehand natural-language browser tool
Add tools/stagehand, a browser tool built on the Stagehand Go SDK
(act/observe/extract/navigate/get_text/screenshot) with persistent named
sessions. Runs on local Chrome by default or Browserbase when an API key
is configured. Stagehand's internal inference is routed through the
harness LLMProvider via NewGenerateFunc, so it shares the agent's
provider, usage observers and admission guards.

The Stagehand SDK requires Go 1.26, so the module now declares go 1.26.0.
2026-09-28 01:25:08 +08:00
sausheong 9a013f6f4b Raise WebFetchTool's output cap to ~1M tokens
MaxOutputLength was 50,000 chars, truncating fetched pages to a few
paragraphs well before hitting any model's context window. Match Sonnet
5's 1M-token context using this codebase's 4-chars/token estimate
(session.Session.EstimateTokens), and raise the raw HTTP read cap
(maxFetchSize) to 8MB so plain-text/JSON responses that don't shrink
during HTML->markdown conversion aren't cut short before the output cap
even applies.
2026-09-22 17:45:40 +08:00
sausheong 0972eed3ea Harden Harness runtime, persistence and execution for Hand 2026-09-09 22:55:55 +08:00
sausheong eb4fa67976 fix: harden runtime against panics/races, close path-traversal and fail-open gaps
- Runtime.Run rejects concurrent invocations instead of racing on shared state; panics in tools, hooks, and permission checkers are recovered and surfaced as errors/denials instead of crashing the loop
- AgentSpec.Loop now actually overrides RuntimeDeps.AgentLoop per-agent, as documented
- session.Store validates agent ID / session key as single path components, preventing traversal outside the session directory
- ValidatePathInWorkDir resolves symlinks on the target itself, not just its parent, closing a workspace-escape gap
- bash tool now fails closed on an unrecognized ExecPolicy.Level instead of allowing everything
- browser tool rejects unknown actions instead of silently no-op'ing

Bump README to v0.3.4 and document the AgentSpec.Loop override semantics.
2026-08-02 10:14:20 +08:00
sausheong 7f0c3fd23d fix(bash): reject real newline/CR and redirection in allowlist mode (S1) 2026-06-13 16:25:44 +08:00
sausheong a5f21d3a2c fix(bash): treat background & as a command separator in allowlist mode (S1) 2026-06-13 16:23:51 +08:00
sausheong 1752cbf2fb fix(file): honor ctx cancellation in read_file/edit_file (N12) 2026-06-13 12:51:30 +08:00
sausheong e133f97e1e fix(web): decode all HTML entities via html.UnescapeString (N11) 2026-06-13 12:50:07 +08:00
sausheong d6db565d7c fix(web): dial all validated IPs for dual-stack fallback (I1); fix live SSRF test to await fetch (M1) 2026-06-13 11:56:30 +08:00
sausheong fb5103fb87 feat(file): cap read_file/edit_file size to prevent OOM (N5) 2026-06-13 11:27:34 +08:00
sausheong 01b55a1446 fix(browser): block private-IP resolution via host-resolver-rules (S3) 2026-06-13 11:25:22 +08:00
sausheong 7d85074509 fix(web): all web_search backends use SafeHTTPClient (N4) 2026-06-13 11:22:15 +08:00
sausheong d7777f7c89 fix(web): web_fetch uses SafeHTTPClient — pins validated IP (S2) 2026-06-13 11:20:12 +08:00
sausheong 1e00916a82 fix(web): block 0.0.0.0/8, CGNAT, and reserved ranges in isPrivateIP (S2 hardening) 2026-06-13 11:19:03 +08:00
sausheong 083122a81f feat(web): add SafeHTTPClient with IP-pinning transport (S2) 2026-06-13 11:15:26 +08:00
sausheong 87f77c76ba feat(tools/file): edit_file atomic + preserve existing mode 2026-06-13 00:51:57 +08:00
sausheong 7ae944f0eb feat(tools/file): write_file atomic + 0600 2026-06-13 00:50:46 +08:00
sausheong cf47b2fca8 feat(mcp): expose session Ping on Client
Gateway supervisors need a cheap liveness probe to detect mid-flight
upstream death (crashed stdio child, restarted HTTP server). Client.Ping
forwards to the SDK session's MCP ping; a non-nil error means the
session is no longer usable.

Also moves examples/minimal's keep-import-live statement above the REPL
loop — it sat after an infinite for loop, tripping go vet's unreachable
code check.
2026-06-10 12:44:21 +08:00
sausheong 65021e1fe2 fix(file tools): resolve relative paths against WorkDir before workspace validation
When the agent supplies a relative path (e.g. "app.py"), filepath.Abs resolves
it against the process CWD, not the workspace — causing ValidatePathInWorkDir
to reject paths that are legitimately inside the workspace.

Join relative paths with WorkDir before resolution so the agent can use bare
filenames without hitting the outside-workspace error.
2026-05-12 17:10:32 +08:00
sausheong 0ca0fed9f7 fix(browser): reap orphaned Chromes when parent dies hard
chromedp launches Chrome as detached subprocesses; on SIGKILL, OOM, or
any path that bypasses our cleanup chain they reparent to PID 1 and
survive indefinitely. Each launch now allocates a known harness-browser-*
user-data-dir and registers it with a single detached /bin/sh watchdog
spawned via Setsid. When the parent dies the watchdog detects stdin EOF
and pkills + rm -rfs every still-tracked path. Clean teardown untracks
the path so a later hard exit can't kill the next session sharing the
process.
2026-05-08 22:08:58 +08:00
sausheong 7e9801bf9c Remove upstream-project attribution from docs and code comments
Strips references to the upstream npm-package agent harness from
README design notes, developer.md, the compaction package, the
runtime context/streaming comments, and the tools/mcp adapter
doc-comments. The technical patterns being described stand on their
own; the attribution chain isn't needed.

Remaining mentions of the word in the providers/anthropic package
are literal Anthropic model identifiers (the 'claude-…' API model
strings) — those are functional product names, not attribution.
2026-05-08 13:43:10 +08:00
sausheong 76c03019c8 Add hooks and MCP as first-class components; expand docs
Promotes the two remaining "deliberately not in scope" components from
the harness model to first-class subsystems, and overhauls the docs.

Hooks (runtime/types.go, runtime/runtime.go, runtime/hooks_test.go):
- New runtime.LifecycleHooks struct on LoopConfig.Hooks with five
  Go callbacks: OnUserPromptSubmit (may rewrite prompt),
  OnSessionStart, BeforeToolUse (gating with same shape as
  PermissionChecker), AfterToolUse (observe), OnStop (with reason:
  completed/max_turns/error/aborted).
- Wired into Run, dispatchTool, executeToolKickoff at all 8 exit
  points + both tool-execution paths.
- 8 tests covering each hook firing.

MCP (tools/mcp/, runtime/builder.go, runtime/types.go):
- New tools/mcp package using the official
  github.com/modelcontextprotocol/go-sdk v1.5.0. Stdio and
  Streamable HTTP transports.
- ServerConfig now exposes Headers + HTTPClient for HTTP auth
  (static bearer, OAuth via oauth2.NewClient, mTLS, custom
  RoundTripper). Header injection clones requests so SDK retries
  see clean params.
- First-class AgentSpec.MCPServers — BuildRuntime connects each
  server, registers adapter tools (mcp__<server>__<tool>), stashes
  clients on Runtime.
- New Runtime.Close() releases sessions; idempotent.
- 14 tests including end-to-end header propagation through the SDK
  via httptest.Server.

Examples:
- support-agent now demonstrates Skills + Permission + LifecycleHooks
  together. Audit log via AfterToolUse + OnStop, JSONL output.
- defer rt.Close() added to all four examples (no-op without MCP,
  idiomatic).

Docs:
- README expanded: Why harness, Requirements, Install, Examples
  table, Configuration (env vars), Non-goals, Testing, expanded
  Status. Quick Start fixed to use real BuildRuntime API.
- developer.md mental-model diagram replaced with two correct ones:
  composition (how a Runtime is wired) and per-Run sequence (what
  rt.Run actually does, including hook fan-out and the tool batch
  loop).
- developer.md gains Lifecycle hooks + MCP servers subsections with
  full snippets, including Streamable HTTP auth and OAuth recipes
  (clientcredentials + authcode flows via golang.org/x/oauth2).
- LICENSE file added (MIT).

All 18 packages build and test green.
2026-05-08 13:34:00 +08:00
sausheong 123a233cb7 Drop Felix references; harness stands as a platform on its own
Removes every Felix mention from public-facing surfaces so the framework
reads as a standalone agent platform rather than an extracted module.

User-visible changes:
- HTTP User-Agent on web_fetch / web_search: Felix/1.0 → harness/1.0
- bash tool path-substitution prefix: '[felix]' → '[harness]'
- On-disk paths: <workspace>/.felix/ → <workspace>/.harness/
  (todos.json + spill/ tree); tests updated in lockstep.
- OTel trace attributes: felix.trace_id / felix.total_ms /
  felix.phase_count → harness.* equivalents.

Doc-comment changes:
- Examples (lta-agent, data-agent) lose 'non-Felix consumer' framing.
- README drops the 'extracted from Felix' lede and the 'What was lifted
  from Felix' section, replaced with a 'Design' overview that points
  to developer.md.
- Runtime / tool / compaction doc comments rewritten so behaviour
  notes describe what the harness does without naming the prior origin.
- Test-fixture text 'you are felix' → 'you are an assistant'.

Verified: zero 'felix' (case-insensitive) in tracked .go / .md files.
All 16 packages build and pass tests.
2026-05-08 00:24:06 +08:00
sausheong 1f2c471ff9 Initial commit: Go agentic harness extracted from Felix 2026-05-07 11:31:42 +08:00