Skip to content

Expose preview status/logs/restart tools to the AI chat#59

Merged
pablopunk merged 5 commits into
mainfrom
fractal-doce-dev-i-ve-been-thinking-about-exposing-more-internal-fde1ca
May 14, 2026
Merged

Expose preview status/logs/restart tools to the AI chat#59
pablopunk merged 5 commits into
mainfrom
fractal-doce-dev-i-ve-been-thinking-about-exposing-more-internal-fde1ca

Conversation

@pablopunk
Copy link
Copy Markdown
Owner

@pablopunk pablopunk commented May 14, 2026

Summary

  • New backend service + per-project token + internal API at /api/internal/ai-tools/preview/{status,logs,restart} that the chat agent can call to check the doce preview server, read its logs, and restart it
  • Three OpenCode custom tools (get_doce_preview_status, read_doce_preview_logs, restart_doce_preview) generated at runtime into ${DATA_PATH}/opencode/tools/. Tools auto-resolve projectId + token from context.directory; no agent-visible internal IDs
  • Chat tool registry: dropped colored icons and added a getDetails({input,output,status}) field so each tool defines its own concise expanded view instead of raw JSON dumps

Caveats

  • OpenCode 1.14.48 currently crashes any custom tool that declares an args: field with undefined is not an object (evaluating 'g.split'). To work around it, the three tools take no arguments and use sensible defaults (logs always returns tail+signal; restart records a generic reason). Once that bug is fixed in opencode we can re-add typed args without other changes.

Test plan

  • Open an existing project's chat, ask "Is the preview running?" — Preview Status tool call should render and the expanded panel should show a one-line summary
  • Ask "Read the recent preview logs" — Preview Logs should return the last error signal + tail
  • Manually break the preview (e.g. introduce a syntax error in src/pages/index.astro), then ask the agent to diagnose + fix — it should chain status → logs → restart as needed
  • Verify no colored icons remain on any tool calls and no raw JSON Input: blocks appear in expanded views

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added AI tools for preview status checks, log viewing, and restart capabilities
    • Enhanced tool call display with richer contextual details and metadata
  • Documentation

    • Updated preview troubleshooting guide with improved tool usage recommendations

Review Change Stack

pablopunk and others added 5 commits May 12, 2026 20:36
Registers get_doce_preview_status, read_doce_preview_logs, and restart_doce_preview
in the chat tool registry, adds their service/schema skeleton, and updates the agent
system prompt in DOCE.md to guide correct tool usage order.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Generates 3 hidden OpenCode custom tools (get_doce_preview_status,
read_doce_preview_logs, restart_doce_preview) at startup under
${DATA_PATH}/opencode/tools/. Each tool resolves projectId from its
session directory, reads a per-project token, and POSTs to a new
internal API at /api/internal/ai-tools/preview/{action} that executes
the existing service layer scoped to the project owner.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Tools now declare an optional getDetails({input,output,status}) that
returns a short summary string for the expanded panel. Default expanded
view falls back to a tiny raw output preview (instead of the full
Input/Output JSON blocks), or "No additional details." when there is
nothing to show. Drops the leftover colored iconClass on the doce
preview tools and registers focused summaries (status -> output
summary/error, logs -> summary + extracted signal, restart -> reason +
result summary).

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Two integration fixes for the OpenCode custom-tool wiring:

1. runtime: always re-emit ~/.config/opencode/{opencode.json,tools,plugins}
   before deciding to reuse a running opencode. Previously these only got
   written on a fresh spawn, so a running daemon would never see updated
   tool sources.

2. tool sources: drop the `args` field on all three doce preview tools and
   drop the node:path import. OpenCode 1.14.48 crashes any tool call that
   declares an `args` object (even {}) with
   "undefined is not an object (evaluating 'g.split')" inside its internal
   wrapper. Tools without `args` execute correctly. The tools now read
   sensible defaults from session context instead of taking model-provided
   arguments.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
doce-dev-www Ready Ready Preview, Comment May 14, 2026 0:56am

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

Caution

Review failed

Pull request was closed or merged during review

Walkthrough

This PR implements internal Doce preview tools for OpenCode that enable monitoring and management of Docker Compose preview services. It adds three new tools—get_doce_preview_status, read_doce_preview_logs, and restart_doce_preview—with per-project token authentication. The changes include token infrastructure, internal API endpoints, service logic for status/logs/restart operations, tool source code generation, OpenCode runtime integration, and documentation updates. The feature is wired into project setup and session creation flows.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 13.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Expose preview status/logs/restart tools to the AI chat' directly and clearly describes the main change: making three preview management tools (status, logs, restart) available to the AI chat agent.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot temporarily deployed to pr-59 May 14, 2026 00:56 Destroyed
@pablopunk pablopunk merged commit a702289 into main May 14, 2026
7 of 8 checks passed
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