Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
06910a4
Add --acp flag: serve the Agent Client Protocol over stdio
espetro Nov 2, 2026
986354a
Fix free-mode admission and session lifecycle in --acp
rodriveiga01 Nov 13, 2026
562fb98
Document ACP free-mode research findings in NOTES.md
nicholaslilly Nov 16, 2026
cf55289
fix(acp): make --acp safe for T3/Zed stdio hosts
nicholaslilly Nov 16, 2026
74f4740
fix(acp): add model fallback and transient polling to ensureNow
nicholaslilly Nov 16, 2026
22b1332
fix(acp): session modes, clearer errors, and cancel stopReason
nicholaslilly Nov 16, 2026
4925b98
test(acp): host-fix coverage and scripted stdio harness
nicholaslilly Nov 16, 2026
fda9f3e
chore(acp): restore scm test loader and record live allowlist blocker
nicholaslilly Nov 16, 2026
9c9097d
docs(acp): add draft PR body for CodebuffAI/freebuff
nicholaslilly Nov 16, 2026
d574101
fix(acp): align early-branch test with main OSC startup
nicholaslilly Nov 16, 2026
80c7e15
fix(acp): emit current_mode_update and track picker mode id
nicholaslilly Nov 16, 2026
fcefe60
docs(acp): note mode-update and cancel-bin evidence in live blocker
nicholaslilly Nov 16, 2026
bb018a5
docs(acp): refresh draft PR evidence for mode-update and cancel-bin
nicholaslilly Nov 16, 2026
3866379
feat(acp): add official --acp readiness gate and handshake-only harness
nicholaslilly Nov 16, 2026
a8b21c7
feat(acp): add one-shot live E2E runner for when official --acp ships
nicholaslilly Nov 16, 2026
6f4f162
docs(acp): document Desktop gap and when-ready watcher for allowlist
nicholaslilly Nov 16, 2026
3540af4
docs(acp): record upstream confirmation that official --acp clears al…
nicholaslilly Nov 16, 2026
a70c9a8
fix(acp): send refusal reasons as agent_message_chunk; fix self-fallback
nicholaslilly Nov 19, 2026
471ceb6
fix(acp): send startup logs to stderr and bound shutdown
nicholaslilly Dec 2, 2026
b3823f4
feat(sdk): add a tool-approval seam to run options
nicholaslilly Dec 2, 2026
5472833
feat(acp): permissions, prompt blocks and failure statuses
nicholaslilly Dec 2, 2026
bbcb403
docs(acp): correct the notice facts and propose free-mode ad delivery
nicholaslilly Dec 2, 2026
43a3f4d
docs(acp): remove internal PR draft and sanitize live evidence
GekkeTovie Dec 2, 2026
27e2afe
Merge current main into the ACP branch
GekkeTovie Dec 2, 2026
fd7a424
chore(acp): drop stale .gitignore exception for deleted evidence
GekkeTovie Dec 2, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,6 @@ scripts/identity/out/
# Ad creative projects (Remotion, npm-only, not Bun workspaces): renders and deps stay local
ad-creatives/*/out/
ad-creatives/*/node_modules/

# ACP stdio harness local transcripts (may include account notices / PII)
scripts/acp-harness-*.jsonl
113 changes: 113 additions & 0 deletions NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Freebuff ACP free-mode — research notes

Branch base: `rodriveiga01/freebuff` `feature/acp-agent` @ `9eec2f1` (one commit on `681a041` / espetro `#1611`).

## 1. Upstream PR #1611 (espetro)

Adds `freebuff --acp`: ACP v1 over stdio via `@agentclientprotocol/sdk`. Reuses `getCodebuffClient()` → SDK `run()` so free-mode admission, `freebuff_instance_id`, and device signing match the TUI. In-tree is required — external wrappers get `third_party_client` refusals.

**Review (codebuff-team):** constructor bug — `new FreebuffAcpAgent(log)` vs `{ logger }`; hardcoded `agent: 'base2-free'` + `costMode: LITE`; `as never` casts; picocolors drive-by.

**Nic (nicholaslilly):** T3 Local ACP handshake works; self-built Windows binary still gets `third_party_client_warning` — official allowlisted binary still required for live free mode. Gist patch linked for host fixes.

**Rodrigo (rodriveiga01):** fork commit `9eec2f1` — admission via `callFreebuffSession`, process lifetime release, constructor + `loadPackageVersion()`, mode maps, refusal as notice + `stopReason: "refusal"`. 18 tests pass locally; **no live free-mode completion verified**.

## 2. Rodrigo vs base (`681a041...9eec2f1`)

| Area | Change |
| --- | --- |
| `freebuff-session.ts` | New `AcpFreebuffSession`: serialized `ensure` → POST claim, reuse per model, `release` on shutdown |
| `acp-agent.ts` | `defaultRunTurn` admits via `acpFreebuffSession.ensure`; `AGENT_MODE_TO_ID` / `AGENT_MODE_TO_COST_MODE`; `AcpSessionError` → notice + `refusal` |
| `serve.ts` | `{ logger }` constructor; `loadPackageVersion()`; SIGINT/SIGTERM/`connection.closed` → release + exit; console → stderr |
| Tests | Constructor shape fix; refusal wording tests in `acp-session.test.ts` |

## 3. Nic gist — keep / port / drop

**Port into Rodrigo base:**

- Lowercase `'user-agent': getCliAdRequestUserAgent()` on completions (fixes AI SDK header merge → 403).
- `--acp` ⇒ `trustAgents` in `parseArgs`.
- Early `--acp` branch in `main()` before OSC/TTY/trust readline (stdout must stay JSON-RPC-only).
- `sessionModes` / `setSessionMode` + Freebuff model picker (`FREEBUFF_ACP_MODEL_MODES`).
- `formatFreebuffAcpError` for `third_party_client` / `prompt_policy` (+ rate_limit / waiting_room).
- `model_unavailable` fallback + 90s POST→GET transient poll (408/429/503 backoff) — **into** `AcpFreebuffSession.ensureNow`, not a second admission path.

**Drop:**

- Inline `ensureFreebuffSession` + shared Zustand store admission.
- Throw-on-refusal (`RequestError.invalidParams` for admission failures).
- Hardcoded `AGENT_MODE_TO_COST_MODE.LITE` / `getFreebuffCliAgentIdForSelection` bypass of mode maps.

## 4. Conflict resolution

1. **Admission:** exactly one path — `acpFreebuffSession.ensure` → `ensureNow` inside `defaultRunTurn`. Delete Nic’s `ensureFreebuffSession`.
2. **Refusal:** catch `AcpSessionError` (and refusal-class run errors) in `prompt()` → one `agent_message_chunk` + `stopReason: "refusal"`. Never also throw. Transient timeout / hard failures after poll become ACP errors (invalid params / agent message), not duplicate refusal reports.

## 5. ACP protocol (v1) — relevant surface

- **initialize:** negotiate `protocolVersion`, capabilities, `agentInfo` / `clientInfo`.
- **session/new:** returns `sessionId` + optional `modes: { currentModeId, availableModes }`.
- **session/set_mode:** unknown mode → JSON-RPC `-32602` invalid params.
- **session/prompt:** streams `session/update` (`agent_message_chunk`, `agent_thought_chunk`, `tool_call`, `tool_call_update`, `current_mode_update`); ACP v1 also has `notice`, but it is fire-and-forget and only allowed when the client advertises `session.notices`, so errors stay `agent_message_chunk` text; response `stopReason`: `end_turn` | `max_tokens` | `max_turn_requests` | `refusal` | `cancelled`.
- **session/cancel:** abort in-flight turn → `cancelled` (must not surface as protocol error).
- Transport: newline-delimited JSON-RPC over stdio; stdout is protocol-only.

## 6. Freebuff free-mode internals

- **`callFreebuffSession`:** POST/GET/DELETE `/api/v1/freebuff/session` with instance id, model, multi-session headers, device signing.
- **`AcpFreebuffSession.ensureNow` (Rodrigo):** single POST; throw `AcpSessionError` on non-active; release on model switch.
- **Enhance:** poll GET after POST; backoff on 408/429/503; one `model_unavailable` fallback; give up at 90s with clear error.
- **`defaultRunTurn`:** `AGENT_MODE_TO_ID[mode]` + `AGENT_MODE_TO_COST_MODE[mode]`; attach `freebuffSessionMetadata` + `clientDescriptorMetadata`.
- **Hour release:** `serveAcp` on normal exit, SIGINT, SIGTERM, stdin/`connection.closed`.

## 7. T3 Code Local ACP launch

From T3 docs (`providers-acp.md`) + Nic’s notes:

- Settings → Providers → Local ACP command.
- **Command:** `freebuff` (or path to binary/entry).
- **Args:** `--acp` (one literal arg).
- Env overrides optional; credentials stay in Freebuff keychain (no ACP auth).
- Models/modes come from ACP `session/new` → `modes` (picker).
- Spawn is direct (`shell: false`); Windows `.cmd` shims are problematic — prefer real executable / `bun run cli/src/entry.ts --acp` for dev.
- Expectation: lowercase Freebuff-CLI user-agent on completions; no TTY trust prompt; streamed `session/update` then `end_turn`.

## 8. Live gate risk (hit 2026-11-15)

Self-compiled / `bun run cli/src/entry.ts --acp` still gets:

```text
third_party_client_warning — Freebuff free mode only works through the official
Freebuff CLI, Freebuff Desktop and freebuff.com. … the server refused the request
and recorded a strike on the account.
```

Installed official CLI is `freebuff 0.2.36` and **does not include `--acp`**, so T3 Local ACP cannot use an allowlisted binary yet.

**Do not keep retrying live completions from a non-allowlisted build** — each refusal adds strikes.

Protocol/unit gates can still pass. Live free-mode completion + T3 editor E2E remain blocked until Codebuff ships an allowlisted build with `--acp`.

### Upstream confirmation (espetro on #319)

> It has to live in the official binary. … what fails is the client allowlist, which an **in-tree flag satisfies**.

So the unblock is: merge in-tree `--acp` (#1672 / #1611) → official npm/Desktop CLI release → T3 points at that binary. Self-built Windows binaries remain third-party even with `CODEBUFF_IS_BINARY` + Freebuff-CLI UA.

## 9. When an official `--acp` build ships

Strike-safe readiness check (no prompts):

```text
bun scripts/acp-official-ready.ts --npm
bun scripts/acp-official-ready.ts --bin path/to/official/freebuff
```

Then live + T3 E2E (only on allowlisted official builds):

```text
FREEBUFF_ACP_CMD="<official> --acp --trust-agents" bun scripts/acp-stdio-harness.ts --handshake-only --set-mode MAX
FREEBUFF_ACP_CMD="<official> --acp --trust-agents" bun scripts/acp-stdio-harness.ts --live --turns 2 --set-mode MAX
```

Point T3 `providerInstances.freebuff-acp` at that binary, capture screenshots of streamed reply + mode switch + second turn.
3 changes: 3 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"bun": "1.3.14"
},
"dependencies": {
"@agentclientprotocol/sdk": "^2.2.0",
"@codebuff/sdk": "workspace:*",
"@opentui/core": "0.3.4",
"@opentui/react": "0.3.4",
Expand Down
Loading
Loading