Skip to content

feat: add OpenClaw workspace context loading - #97

Merged
pavelanni merged 3 commits into
mainfrom
feature/openclaw-workspace-compat
Jul 1, 2026
Merged

pavelanni merged 3 commits into
mainfrom
feature/openclaw-workspace-compat

Conversation

@pavelanni

@pavelanni pavelanni commented Jul 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Load OpenClaw-compatible workspace files (AGENTS.md, SOUL.md, USER.md, IDENTITY.md, TOOLS.md) from the workspace directory and inject as ## Project Context in the system prompt
  • Works in both phase 1 (single-shot) and phase 2 (agentic loop) modes — existing deployments with only system-prompt.txt are unaffected
  • Per-file truncation at 20K chars, total at 60K chars, matching OpenClaw defaults
  • Rune-safe truncation preserves valid UTF-8 at boundaries

Test plan

  • Unit tests: all five files present (order and headers verified)
  • Unit tests: partial files, no files, empty files, nonexistent directory
  • Unit tests: per-file truncation at 20K chars
  • Unit tests: total truncation at 60K chars
  • Unit tests: Unicode content truncation (rune safety)
  • golangci-lint run ./internal/cmd/... passes (zero issues in changed packages)
  • make test passes (no regressions)
  • Deploy with OpenClaw workspace ConfigMap and verify context appears in LLM prompts

Note: make lint has pre-existing failures in demo/batch/document-service/main.go and internal/logger/logger.go — unrelated to this change.

Assisted-By: Claude (Anthropic AI) [email protected]

Summary by CodeRabbit

  • New Features

    • Added support for loading OpenClaw-compatible workspace context files at startup and injecting them into the agent prompt.
    • Added a deployable manifest for running with workspace context (including health endpoints and external exposure).
  • Documentation

    • Updated README “How it works” and the agent configuration guide with workspace context layout, load order, truncation rules, and compatibility details.
    • Added/expanded guidance on how workspace files become project context.
  • Tests

    • Added tests covering workspace context generation, missing/empty file skipping, per-file and total truncation, and Unicode-safe handling.

Load OpenClaw-compatible workspace files (AGENTS.md, SOUL.md,
USER.md, IDENTITY.md, TOOLS.md) from the workspace directory and
inject them as structured project context into the system prompt.
This gives OpenClaw users a migration path to DocsClaw's leaner
runtime without changing their workspace configuration.

Works in both phase 1 (single-shot) and phase 2 (agentic loop).
Per-file truncation at 20K chars, total at 60K chars, matching
OpenClaw defaults.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Pavel Anni <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: 0e3a2503-5b44-4909-bd4a-99b7ddeef786

📥 Commits

Reviewing files that changed from the base of the PR and between 125de7d and d2d3dcb.

📒 Files selected for processing (2)
  • deploy/openclaw-workspace-agent.yaml
  • internal/cmd/serve.go

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to data retention organization setting


📝 Walkthrough

Walkthrough

Adds OpenClaw-compatible workspace context loading to docsclaw, appends the loaded markdown content to the startup system prompt, and updates tests, documentation, and deployment assets for the workspace-aware flow.

Changes

OpenClaw Workspace Context

Layer / File(s) Summary
Prompt loading and wiring
internal/cmd/serve.go
Loads workspace markdown files, applies rune-safe per-file and total limits, formats a Project Context block, and appends it to systemPrompt during startup.
Workspace tests and fixtures
internal/cmd/workspace_test.go, testdata/openclaw-workspace/*
Adds coverage for file ordering, partial and empty inputs, truncation, whitespace-only files, Unicode handling, and missing workspace paths using fixture markdown files.
Docs and deployment manifest
README.md, docs/agent-config-guide.md, deploy/openclaw-workspace-agent.yaml
Documents workspace context behavior and prompt assembly, and adds a Kubernetes/OpenShift manifest with config maps, deployment, service, and route for the workspace-aware agent.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related issues

Possibly related PRs

  • redhat-et/docsclaw#74: Both PRs extend internal/cmd/serve.go by appending startup-derived context into systemPrompt.
  • redhat-et/docsclaw#79: This PR extends the agent config/docs flow that the referenced PR helped establish around tools.workspace and related configuration.

Sequence Diagram(s)

sequenceDiagram
  participant runServe
  participant loadWorkspaceContext
  participant Filesystem
  participant systemPrompt

  runServe->>loadWorkspaceContext: call with workspace directory
  loadWorkspaceContext->>Filesystem: read AGENTS.md, SOUL.md, USER.md, IDENTITY.md, TOOLS.md
  Filesystem-->>loadWorkspaceContext: file contents or missing/empty results
  loadWorkspaceContext->>loadWorkspaceContext: apply per-file and total rune limits
  loadWorkspaceContext-->>runServe: formatted Project Context block
  runServe->>systemPrompt: append workspace context
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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 clearly summarizes the main change: loading OpenClaw workspace context into DocsClaw.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/openclaw-workspace-compat

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

- Use rune-based truncation instead of byte-based to prevent
  splitting multi-byte UTF-8 characters at truncation boundaries
- Move workspace context loading after slog.SetDefault so
  truncation warnings use the configured structured logger
- Fix deployment manifest: use init container to seed OpenClaw
  files from ConfigMap into a writable emptyDir so write_file
  works at runtime
- Add Unicode truncation test verifying rune safety

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Pavel Anni <[email protected]>
@pavelanni
pavelanni marked this pull request as ready for review July 1, 2026 13:31

@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 `@deploy/openclaw-workspace-agent.yaml`:
- Around line 98-100: The seed-workspace init command currently uses a raw
wildcard copy that fails when no .md files are present, causing the pod to exit
before DocsClaw starts. Update the command in the seed-workspace init container
to use a glob-safe approach, such as a shell loop or enabling nullglob, so the
copy becomes a no-op when /openclaw-files has no matches. Keep the fix localized
to the command array for seed-workspace and preserve successful startup when the
optional workspace files are absent.

In `@internal/cmd/serve.go`:
- Around line 160-162: In the workspace file loading path in serve.go, the
current os.ReadFile error handling in the file iteration treats all failures as
missing files and silently continues. Update the logic around the read of
filepath.Join(workspaceDir, name) to skip only errors matching os.ErrNotExist,
and for any other failure log a warning with the file name and error before
continuing. Keep the behavior localized to the workspace scan code so unreadable
files are surfaced without breaking the request flow.
🪄 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: Enterprise

Run ID: adb1df46-b758-4a13-af1f-85deea62a533

📥 Commits

Reviewing files that changed from the base of the PR and between c4da67b and 125de7d.

📒 Files selected for processing (10)
  • README.md
  • deploy/openclaw-workspace-agent.yaml
  • docs/agent-config-guide.md
  • internal/cmd/serve.go
  • internal/cmd/workspace_test.go
  • testdata/openclaw-workspace/AGENTS.md
  • testdata/openclaw-workspace/IDENTITY.md
  • testdata/openclaw-workspace/SOUL.md
  • testdata/openclaw-workspace/TOOLS.md
  • testdata/openclaw-workspace/USER.md

Comment thread deploy/openclaw-workspace-agent.yaml Resolved
Comment thread internal/cmd/serve.go Resolved
- Use a shell loop with existence check in the seed-workspace init
  container so it exits cleanly when no .md files are present
- Log a warning for workspace file read errors other than not-found
  instead of silently skipping them

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Pavel Anni <[email protected]>
@pavelanni
pavelanni merged commit 853a4bb into main Jul 1, 2026
4 checks passed
@pavelanni
pavelanni deleted the feature/openclaw-workspace-compat branch July 1, 2026 14:48
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