Skip to content

loopway 2.0 slice 3: Claude Code sessions per thread, through loopway's MCP - #502

Merged
mcwhittemore merged 6 commits into
mainfrom
v2-slice-3-sessions
Nov 11, 2026
Merged

mcwhittemore merged 6 commits into
mainfrom
v2-slice-3-sessions

Conversation

@mcwhittemore

@mcwhittemore mcwhittemore commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #498. Slice 3 of #486.

Each open thread's queued updates now go to a Claude Code session that acts as loopway-bot and talks back through loopway's own MCP server.

  • Harness (claude.ts, transcript.ts): claude -p --permission-mode auto --output-format stream-json with the bot's prompt plus the updates; later batches use --resume. A usage limit holds every delivery until the reset. It lives in packages/cli rather than a new package, and is Claude Code only.
  • Bot front matter: model and harness (default claude). Sessions run in the directory loopway runs in (no cwd key).
  • Delivery (sessions.ts): all queued updates in one run, oldest first; --max (default 3) caps runs. A delivered batch leaves the queue; an API error, usage limit or bad exit leaves it and the thread retries after 5 minutes. The env has GH_TOKEN and the git author and committer from the github block of ~/.loopway/config.json.
  • MCP (mcp.ts): a local HTTP server with comment(subject, body), one path per thread. Each comment is recorded on the thread (sent) and carries a hidden <!-- loopway:thread=<id> -->. A thread's own comment is not queued back to it, but is queued to every other thread holding the subject. A turn with no message logs turn ended without a message.
  • Contract with slice 4: session, sent and <state dir>/threads/<id>.log as written in 2.0 slice 3: Claude Code sessions per thread, talking through loopway's MCP #498.
  • Updates now carry the comment or review body, so the session can read it.

How to test it locally

Needs gh auth login and a working bot token in ~/.loopway/config.json ({"github": {"token": "...", "name": "loopway-bot", "email": "loopwaybot@craftmill.dev"}}).

# in a checkout of this branch
git fetch && git checkout v2-slice-3-sessions
npm install && npm run build
mkdir -p scratch/.loopway && cd scratch
cat > .loopway/dev.md <<'EOF'
---
repos: [craftmilldev/loopway-sandbox]
on: issue
model: sonnet
---

Answer the issue in a comment.
EOF
node ../packages/cli/dist/index.js   # leave this running

# in a second terminal
gh issue create -R craftmilldev/loopway-sandbox --title "What's 2+2?" --body "Reply in one comment."
tail -f ~/.loopway/state/*/threads/*.log   # the session, as it runs
# when loopway-bot has answered, reply as yourself (the issue number is in the URL above):
gh issue comment <number> -R craftmilldev/loopway-sandbox --body "Now times 3."
grep -A4 '"session"' ~/.loopway/state/*/threads/*.json   # the same session id, resumed
  1. The log shows run started, sent ... comment on ... and run finished; a comment by loopway-bot answers 4, and it is not queued back to that thread.
  2. After "Now times 3." the log says resumed and the answer is 12.
  3. For a failed run, set model: nonesuch in .loopway/dev.md and restart loopway: the log says run failed ..., the updates stay pending in loopway threads, and it retries after 5 minutes. Killing claude mid-run does the same.

(If state has moved by the time you read this, see the README's Credentials and state.) Close the sandbox issue when you are done.

Verification

verifications/502.md. Tests, typecheck, lint and format pass. Steps 1 to 5 ran live in the sandbox with the real claude and the refreshed bot token: loopway-bot answered 4, "Now times 3." resumed the same session and got 12, its own comments were not queued back, a bad model name failed the run with the error in the log, and the TUI showed the session, log and Sent section. Not done live: killing claude mid-run (covered by tests). The live run found that a brand-new issue queued nothing, so its thread never ran; a thread that has never run now gets a first run.

🤖 Generated with Claude Code

@github-actions

Copy link
Copy Markdown

This PR conflicts with its base branch. Rebase onto it, resolve the conflicts, and push.

@github-actions github-actions Bot added the conflicts Conflicts with its base branch; set and cleared by the Label merge conflicts workflow label Nov 11, 2026
@github-actions github-actions Bot removed the conflicts Conflicts with its base branch; set and cleared by the Label merge conflicts workflow label Nov 11, 2026
@mcwhittemore

Copy link
Copy Markdown
Collaborator Author
Rebased onto main (the TUI from #500 is in; its Session, Sent and log helpers were identical to mine, so I kept main's and added only markerOf). Checks pass (117 tests, typecheck, lint, format). verifications/502.md now shows the TUI thread view over a real session, log and (empty) Sent section. Still open: the saved bot token is rejected by GitHub, so the live comment steps need a refreshed token. If #504 merges first, I will move the session log and sent writes onto its state helpers.

@mcwhittemore

Copy link
Copy Markdown
Collaborator Author

It looks like something is wrong with the mcp server...

> @loopway/cli@2.0.0-alpha build
dev 853d52ab · open · created 2026-11-10 15:58
session idle · last run 2026-11-10 20:53
Subjects
▸ craftmilldev/loopway#498 open
Pending (0)
  none
Sent (0)
  none
Session log
  ⎿ (no output)
● mcp__loopway__comment(craftmilldev/loopway#498)
  ⎿ could not comment: GitHub 401 on /repos/craftmilldev/loopway/issues/498/comments:…
I couldn't post a comment on craftmilldev/loopway#498 this turn. GitHub returned `401…
Nothing on the issue needed a reply anyway. The two updates were project-board automa…
loopway-bot's GitHub token has expired or been revoked. Until it's refreshed, the bot…
── run finished ──
turn ended without a message
-> delivered 3 updates
── run started ──
● Bash(Check cwd removal and gh auth)
  ⎿ 3665cb6 Drop the bot cwd key: sessions run where loopway runs; add copy-paste set…
● mcp__loopway__comment(craftmilldev/loopway#498)
  ⎿ could not comment: GitHub 401 on /repos/craftmilldev/loopway/issues/498/comments:…
I couldn't post on craftmilldev/loopway#498 again. loopway's `comment` tool got `401 …
There's nothing to post anyway: both of your requests are already done in commit 3665…
- **`cwd` key:** removed. Searching `src` and the README finds no bot `cwd` left.
- **Setup commands:** the copy-paste block is in the README's Sessions section and th…
The comment I tried to post said this and that nothing else needs changing.
The bot's GitHub token needs replacing. Until it is, the bot can't read or reply on a…
── run finished ──
turn ended without a message

@mcwhittemore

Copy link
Copy Markdown
Collaborator Author
Thanks for running it. The MCP server is working: your log shows the session calling mcp__loopway__comment and loopway answering. The failure is the bot token, which GitHub rejects with 401 (`could not comment: GitHub 401 on .../comments`). It is the same expired `github.token` in ~/.loopway/config.json that I hit; refreshing it should let the comment through. So that this does not hide inside the session, a refused comment is now also written to the thread log as `!! comment on failed: ...` (pushed, with a test, and noted in verifications/502.md).

@github-actions github-actions Bot added the conflicts Conflicts with its base branch; set and cleared by the Label merge conflicts workflow label Nov 11, 2026
@github-actions

Copy link
Copy Markdown

This PR conflicts with its base branch. Rebase onto it, resolve the conflicts, and push.

mcwhittemore and others added 2 commits November 10, 2026 21:01
… loopway's MCP

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot removed the conflicts Conflicts with its base branch; set and cleared by the Label merge conflicts workflow label Nov 11, 2026
mcwhittemore and others added 3 commits November 10, 2026 21:06
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mcwhittemore

Copy link
Copy Markdown
Collaborator Author
Rebased onto main with #504 (all my state now goes through `stateDir`, `threadLogPath` and the thread files under `~/.loopway/state//`; only config.json stays at the top). Reran the checks (121 tests, typecheck, lint, format) and steps 1 to 5 live in the sandbox with the refreshed bot token: `loopway-bot` answered 4, "Now times 3." resumed the same session and got 12, the bot own comments were not queued back, a bad model name failed the run with the error in the log, and the TUI showed the session, log and Sent section. The live run found a real bug: a brand-new issue queues nothing, so its thread never ran. A thread that has never run now gets a first run (and is told again after a failed first run). Details in verifications/502.md. Two notes: killing `claude` mid-run is covered by tests only, and sandbox issue 10 (yours, "What's 2+2?") was also answered by my loopway while it ran; I was not allowed to close it, so it is still open.

@mcwhittemore

Copy link
Copy Markdown
Collaborator Author

Does waiting for the poller mean its not polling for messages yet? I'm seeing this in a test run.

loopway · 0 threads
No threads yet.
waiting for the poller
↑/↓ move · enter open · esc clear filter · q quit

@mcwhittemore

Copy link
Copy Markdown
Collaborator Author
It is polling. That line is the TUI placeholder for "the poller has not printed anything yet": the bottom line only changes when the poller reports an event (a new subject, an update) or an error, and a quiet repo reports nothing, so it stays on `waiting for the poller` (discovery every 2 minutes, known subjects every 30 seconds). In my sandbox run it showed that line until the first issue was found. It is slice 4 code, not this PR, so I have not changed it; I will pass it to the coordinator as a follow-up: show something like "polling, last checked 14:02" so a quiet repo does not look stuck.

@mcwhittemore

Copy link
Copy Markdown
Collaborator Author

I'm not seeing any updates.

staring runner

Matthews-MacBook-Pro:scratch mcwhittemore$ pwd
/Users/mcwhittemore/plumbline/garden/loopway/.claude/worktrees/agent-afa0630aa81fdf9e6/scratch
Matthews-MacBook-Pro:scratch mcwhittemore$ npm run cli

> loopway@2.0.0-alpha cli
> npm run start -w @loopway/cli --


> @loopway/cli@2.0.0-alpha start
> tsx src/index.ts

creating issue

Matthews-MacBook-Pro:loopway mcwhittemore$ gh issue create -R craftmilldev/loopway-sandbox --title "What's 2+3?" --body "Reply in one comment."

Creating issue in craftmilldev/loopway-sandbox

https://github.com/craftmilldev/loopway-sandbox/issues/13

running runner

loopway · 0 threads
No threads yet.
waiting for the poller
↑/↓ move · enter open · esc clear filter · q quit

…T_CWD to the checkout root

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mcwhittemore

Copy link
Copy Markdown
Collaborator Author
Found it, and it is my copy-paste block, not the poller. Your `ps` environment shows `INIT_CWD=.../agent-afa0630aa81fdf9e6` (the checkout root), not `scratch/`: under `npm run cli` npm sets INIT_CWD to the workspace root, so loopway read the checkout's own `.loopway/dev.md` (repos: craftmilldev/loopway) and never looked at the sandbox, which is why issue 13 showed nothing. Fix, pushed: run the built file from the scratch directory instead, `node ../packages/cli/dist/index.js` (after `npm run build`), in the README, docs/developing.md and the PR body. I checked it from another directory: it reads that directory's `.loopway/` and `~/.loopway/state/` follows it. To test now: stop the running loopway, then `cd scratch && node ../packages/cli/dist/index.js`. Issue 13 is older than that run's first start, so open a new sandbox issue after it starts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2.0 slice 3: Claude Code sessions per thread, talking through loopway's MCP

1 participant