Files
PaperClipAI/packages/adapters/claude-local/src/server
Devin Foley c294f21a34 fix(claude-local): join every row of a hard-wrapped setup-token URL (#22653)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - People connect a Claude subscription from "Connect a model".
Paperclip runs `claude setup-token` in a terminal and reads the sign-in
link from the output
> - When the CLI prints the link as plain text, the terminal hard-wraps
it over several rows. `reassembleUrl` joins the rows and validates the
result
> - It returns the first join that validates. `state` is the last query
key and needs only 16 characters, so a join that stops inside `state`
can validate one row early
> - The leftover row then sits where the prompt should be. Prompt
binding returns null, and the sign-in dialog hangs. No truncated URL
gets out, because the parser fails closed
> - This pull request uses the wrap shape: every row but the last has
the same width, so the parser joins until a row is shorter than the
first row
> - The benefit is that the plain-text path works at every terminal
width, not only at the widths where the break misses `state`

## Linked Issues or Issue Description

Refs #19949 (the plain-text path section). The fix follows the change
that @aron-intframe proposed and measured in the first comment on that
issue.

The login-method line defect from the same issue is in a separate pull
request, as the triage comment asks. Refs #20050 (PTY window size).

## What Changed

- `setup-token-parse.ts`: `reassembleUrl` no longer returns at the first
join that validates. If the first row validates on its own, the URL is
unwrapped, and the parser stops there as before. Otherwise it joins
until a row is shorter than the first row, and it returns the last join
that validated.
- Tests: the 64-column `claude.com` wrap from #19949, a sweep of every
width from 40 to 200 columns for both accepted URLs, and a test that a
two-row wrap with a valid first row still fails closed.

## Verification

- `pnpm exec vitest run packages/adapters/claude-local/src/server/`: 391
passed, 2 skipped.
- The 64-column test and the width sweep fail on `master` and pass with
this change.
- `pnpm --filter @paperclipai/adapter-claude-local typecheck` passes.
- With a 385-character URL like the one in #19949, `master` fails at 49
of 161 widths from 40 to 200. This branch passes at all 161.

## Risks

- Low risk. Each existing test passes, including the code-like value
after the URL, the repeated OSC 8 rows, and the hostile line between
fragments.
- One gap stays: a two-row wrap whose first row already holds 16 or more
`state` characters. One row gives no width to compare, so the parser
fails closed as it does today. A 200-column PTY (#20050) avoids this for
current URL lengths.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with shell, file
edit, and code execution tools.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
2026-11-23 11:52:21 -08:00
..