Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

feat(books): MCP tools and slashdocs books CLI (4/7) - #271

Open
nehalkumarsingh wants to merge 13 commits into
nehal/book-mode-3-apifrom
nehal/book-mode-4-agents
Open

nehalkumarsingh wants to merge 13 commits into
nehal/book-mode-3-apifrom
nehal/book-mode-4-agents

Conversation

@nehalkumarsingh

Copy link
Copy Markdown
Contributor

Stack: 4/7. Based on #270 (API), then #269 (storage) and #268 (proposal). Review this PR after #270.

What and why

These are the agent surfaces for Book mode. Agents can create a book, read its outline, and push a new outline with the same conflict and validation rules people get.

  • MCP tools:

    • create_book, get_book (the per-reader manifest), get_book_outline, get_book_status.
    • update_book_outline, which takes the outline as an object. It reports outline_conflict with current_version_id on a stale base, and returns every validation problem.
    • delete_book, marked destructive.

    The tools call the REST handlers in-process, so the feature flag, auth and validation are shared.

  • CLI: slashdocs books create | show | status | delete, plus:

    • slashdocs books outline pull <book> [file], which writes pretty JSON (to stdout when no file is given or the file is -).
    • slashdocs books outline push <book> <file> [--base-version <id>] [--note "…"]. The file can be a pulled JSON (the base version defaults to its version_id) or a bare outline. A conflict exits 5 with a "pull again" message. Invalid outlines print each problem as path: message.
  • cli/README.md is updated.

How it was tested

  • go test ./api/... ./internal/... ./cli/... -count=1 passes with 0 skipped DB tests.
  • New CLI tests check request bodies, base-version defaulting, usage errors, exit codes and printed validation problems.
  • A new MCP test checks that a stale base keeps outline_conflict and current_version_id, and expectedMCPTools lists the six new tools.
  • gofmt and go vet are clean. go.mod/go.sum are unchanged.

Checklist

  • Tests pass locally
  • Tests added
  • Docs updated (cli/README.md)
  • No breaking change

🤖 Generated with Claude Code

nehalkumarsingh and others added 13 commits November 5, 2026 16:28
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
books status fell through to the generic compact row and printed a Go
map dump. It now lists each outline entry with its number (or front or
back), title, document ID and current version, marks placeholders, and
lists the documents not in the outline and the removed chapters. --json
still prints the raw payload. The test uses the server's real
bookStatusResponse shape.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
POST /v1/folders/{id}/book on a folder that is already a book now puts
the book's id in error.details.book_id. Only folder editors get this far,
and they can already read it from GET /v1/folders/{id}/book, so an agent
that tries to create a book can carry on with the one that exists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
books create printed only the new book id, so the documents the seeded
outline left out were visible only with --json. It now says how many
documents were placed and lists the ones not in the outline. When the
folder already is a book, the error names that book (from the new
book_exists details) and how to show it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every book tool but create_book needs a book_id, and no MCP tool
returned one for an existing book, so an agent told to edit a folder's
book had no way to find it. get_folder_book calls GET
/v1/folders/{id}/book (folder viewers) and returns the book_id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The CLI had no way to get the book id of an existing book, which every
books command but create needs. books show --folder <folder_id> looks
the book up with GET /v1/folders/{id}/book and shows it, and books show
now prints the book id in its header (--json keeps metadata.identifier).
Front and back matter are labelled by kind instead of a dash.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With SLASHDOCS_BOOKS_ENABLED off (the default), tools/list still offered
seven book tools that could only answer feature_disabled, so agents paid
context for them and tried them. The tools are now registered only when
book mode is on; the flag is read once at startup, the same value the
REST handlers check. The tools/list test runs with book mode on, and a
new test checks that with it off the book tools are not listed and
calling one is an unknown tool.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- delete_book said it deleted reading state and did not say it was
  permanent. It now says it permanently deletes the book and every
  outline version, that readers' saved places go too, and that the
  folder, documents and chapter progress stay.
- The outline argument now says that doc is a document ID from the
  book's folder and planned is a placeholder title, lists subtitle, and
  says to send only the outline field from get_book_outline.
- create_book, get_book_outline, update_book_outline, get_book_status
  and delete_book say they need editor access; get_book says it is the
  reader tool. update_book_outline names current_version_id and
  problems in its errors, and create_book names book_id in book_exists.
- The four book_id-only tools share one handler helper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pushing the same pulled file twice conflicted with the first push,
because the file still names the version it was pulled at, and the CLI
said someone else had changed the outline. If the agent then pulled
into the same file, it lost its edits.

push now remembers the version it saved for each book (as docs push
does). On a 409 it reads current_version_id: if that is its own push,
it says so and suggests --base-version <that version> or pulling into a
new file; otherwise it names the base and current versions.
explainOutlineError now updates the APIError message in place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- outline pull into a file now confirms like docs pull (check mark,
  version number and id, honours --quiet), and indents the server's
  JSON with json.Indent so the file keeps the server's key order.
- A file that is valid JSON but not an object (an array, or null) is
  now a usage error saying the file must be a JSON object, instead of a
  message with Go types or, for null, a request with an empty outline.
- A table test covers invalid JSON, an array, null and a missing file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The MCP book test covered only the stale-base conflict. It now also
pushes from the current version and checks the version number goes up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Build the books outline and summary tables in a strings.Builder and flush
them through one checked tabwriter call, and annotate the test file read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…k, list placeholders

- books outline push: after a successful push from a pulled file, rewrite
  the file's version_id and number to the new version, and drop the
  "which you pushed" conflict branch, which trusted a per-machine record
  and could talk a second agent into overwriting the first one's outline.
  Every conflict now gets the generic "pull and re-apply" message.
- MCP get_book runs the same bookReadLimit instance as GET /v1/books/:id,
  so both share one per-principal budget.
- books show renders from the toc, so placeholders are listed (as
  "planned") and the header count matches the rows.
- books delete help and the README say the delete is permanent and
  removes every outline version and readers' saved places.

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

Copy link
Copy Markdown
Contributor Author

End-to-end test evidence (stack tip 6dd1fe0)

Ran a real slashdocs-server built from the branch tip (frontend build embedded, SLASHDOCS_BOOKS_ENABLED=true, Postgres 17 with every migration) and drove it with headless Chromium as three signed-in users. Blobs used the in-memory store and sessions were signed cookies, so there was no S3 and no Dex; the compose jobs in CI cover both.

Check Result
Walkthrough: 12 flows, each asserted through the API and the screen 12/12 pass
frontend/e2e on the same server 26/28. book-mode.spec.ts passes 4/4. The 2 failures need Dex: the public-view sign-in and the @mention picker. The stack changes none of that code.
Frontend unit tests 289/289
Go suite (Postgres-backed, 0 skipped) pass
golangci-lint v2.14.0 0 issues
Flag off every book route 404, no book buttons, chapters still open as documents

What this PR's code did in the run:

  • The CLI commands books show, books status and books outline pull work against the server.
  • MCP tools/list shows the 7 book tools.
  • As the owner, get_book returns all 4 chapters.
  • As the partial reader, get_book returns 2 chapters with no hidden titles, and get_book_outline returns not_found.

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.

1 participant