Skip to content

feat: add agent runbook management tool - #2112

Merged
yohamta0 merged 4 commits into
mainfrom
runbook-manage
May 7, 2026
Merged

yohamta0 merged 4 commits into
mainfrom
runbook-manage

Conversation

@yohamta0

@yohamta0 yohamta0 commented May 7, 2026 •

Copy link
Copy Markdown
Member

Summary

  • add an agent runbook_manage tool for listing, searching, reading, creating, updating, patching, and ensuring metadata on Markdown runbooks
  • wire the docs and workspace stores through agent API/session/tool construction
  • update the built-in agent prompt to prefer runbook management for complex and operational workflows
  • add runbook management coverage for permissions, workspace filtering, update safety, and error paths

Validation

  • go test ./internal/agent -run 'TestRunbookManage|TestRegisteredTools' -count=1
  • go test ./internal/service/frontend/...
  • go test ./internal/agent -coverprofile=/tmp/dagu-agent-runbook.cover
  • runbook_manage.go statement coverage: 97.3% (220/226)

Notes

  • go test ./... was run locally before this push and reached the end, but existing Docker-backed internal/intg tests failed while waiting on test containers unrelated to this change.

Summary by CodeRabbit

Release Notes

  • New Features
    • Introduced runbook management capabilities enabling users to create, search, list, retrieve, update, and patch Markdown documentation.
    • Updated agent system prompts to automatically check and leverage existing runbooks for complex operational tasks.
    • Added workspace-scoped access control for runbook resources.

@coderabbitai

coderabbitai Bot commented May 7, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2d0f0a4f-a55b-4b59-8068-7216d05c4052

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR adds a new runbook_manage agent tool for CRUD-like operations on Markdown runbooks stored in a DocStore, along with infrastructure plumbing to wire documentation and workspace persistence stores through the API, session manager, and tool configuration layers, enabling workspace-scoped access control and runbook metadata management.

Changes

Runbook Management Tool & Infrastructure

Layer / File(s) Summary
Type & Config Extensions
internal/agent/types.go, internal/agent/tool_registry.go
UserIdentity gains WorkspaceAccess field for optional workspace-scoped permissions. ToolConfig adds DocStore and WorkspaceStore fields to make these persistence layers available to tools.
API & Session Configuration
internal/agent/api.go, internal/agent/session.go
APIConfig and SessionManagerConfig both gain DocStore and WorkspaceStore fields. UserIdentity construction refactored to set defaults then override from authenticated user, cloning workspace access.
Infrastructure Wiring
internal/agent/api.go, internal/agent/session.go, internal/service/frontend/server.go
NewAPI and NewSessionManager wire store fields from config into instances. buildSessionManagerConfig passes stores into session configuration. createLoop propagates stores into tool configuration. Frontend server creates workspace store and passes it through to agent API initialization.
Runbook Tool Implementation
internal/agent/runbook_manage.go
New runbook_manage tool supports list, search, get, create, update, patch, and ensure_metadata actions on Markdown runbooks with YAML frontmatter metadata. Enforces write permissions, validates IDs, filters by workspace visibility, strips/rebuilds frontmatter, normalizes limits, and handles patch uniqueness constraints.
Tests & Documentation
internal/agent/runbook_manage_test.go, internal/agent/tool_registry_test.go, internal/agent/system_prompt.txt
Comprehensive test suite with mock stores covers CRUD flows, permission checks, error handling, workspace filtering, and edge cases (duplicate patches, metadata conflicts). Registry test updated to include runbook_manage. System prompt updated to guide use of runbook search/get before complex tasks and patch/save workflows after them.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

  • dagucloud/dagu#2019: Both PRs add workspace-scoped access control and plumb WorkspaceAccess through UserIdentity and API/SessionManager layers.
  • dagucloud/dagu#2097: Both PRs extend agent tool/session infrastructure by propagating new persistence stores (DocStore, WorkspaceStore) through ToolConfig and session/tool execution layers.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.00% 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 accurately summarizes the main change—adding a runbook management tool to the agent system. It is concise, specific, and clearly reflects the primary feature introduced across the changeset.
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.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch runbook-manage

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/agent/runbook_manage_test.go`:
- Around line 83-84: The local variable named copy shadows Go's built-in copy
function; rename it (for example to docCopy or cp) where it's declared as copy
:= *doc and update any subsequent uses (e.g., return &copy, nil) to use the new
identifier so golangci-lint revive/govet warnings are eliminated while
preserving the same behavior.
- Around line 289-295: The test calls NewRunbookManageTool(...).Run with a
zero-value ToolContext{} which leaves the embedded Context nil and doesn't
exercise the real ListFlat path; update the non-error call to invoke Run with a
valid context (ToolContext{Context: context.Background()}) so the ListFlat code
path receives a non-nil context, while retaining the zero-value ToolContext{}
variant only for the nil-store/unavailability early-exit case; target the Run
invocation associated with NewRunbookManageTool and the assertions that follow
so the change affects the successful-list assertion but not the error-path test.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b47d3231-d6b8-42bb-a6ab-4fc2c6a90f1e

📥 Commits

Reviewing files that changed from the base of the PR and between 59d92fc and 7c5daa5.

📒 Files selected for processing (9)
  • internal/agent/api.go
  • internal/agent/runbook_manage.go
  • internal/agent/runbook_manage_test.go
  • internal/agent/session.go
  • internal/agent/system_prompt.txt
  • internal/agent/tool_registry.go
  • internal/agent/tool_registry_test.go
  • internal/agent/types.go
  • internal/service/frontend/server.go

Comment thread internal/agent/runbook_manage_test.go Outdated
Comment thread internal/agent/runbook_manage_test.go
@yohamta0
yohamta0 merged commit fd33bdd into main May 7, 2026
10 checks passed
@yohamta0
yohamta0 deleted the runbook-manage branch May 7, 2026 04:02
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