OpenViking icon indicating copy to clipboard operation
OpenViking copied to clipboard

[Feature]: Add a WorkBuddy ingest harness source

Open zhangzhangco opened this issue 2 months ago • 2 comments

Issue Origin

Observed or reproduced in a real environment.

Reproduced against openviking 0.4.20 installed from PyPI (uv tool install), on macOS (darwin 24.x), with real WorkBuddy session logs on disk at ~/.workbuddy/projects/<project-slug>/<session-uuid>.jsonl.

Problem Statement

WorkBuddy (Tencent's agentic coding / desktop assistant) writes its conversation logs in a layout that looks identical to Claude Code's:

~/.workbuddy/projects/<project-slug>/<session-uuid>.jsonl   # append-only JSONL

…but the record schema is different, so the existing claude_code adapter silently yields zero usable messages:

Claude Code WorkBuddy
turn record type in {user, assistant} type == "message" + top-level role
payload nested message{role, content, model} flat content[] + providerData.model
text block types text input_text (user) / output_text (assistant)
timestamp ISO-8601 string epoch milliseconds
session title (none) type == "ai-title" record

The gap is asymmetric and visible in the docs. WorkBuddy is already a first-class citizen on the read side: PR #4321 ("docs: add DeepSeek Harness, WorkBuddy, and Doubao guides", merged 2026-08-25) added docs/images/agents/{en,zh}/workbuddy.md, documenting how to attach OpenViking to WorkBuddy over MCP. But on the write side, the "Supported harnesses" table in docs/{en,zh}/agent-integrations/09-log-ingestion.md lists claude_code, codex, hermes, openclaw, opencode, cursor — and no workbuddy.

So today a WorkBuddy user can recall from the memory store, but can never contribute their own conversation history to it.

Root cause of the non-obvious part (important)

WorkBuddy injects the entire system prompt, project context and per-turn metadata into the user turn itself:

<system-reminder data-role="user-context">
  … system prompt, project context, tool listing, current time …
</system-reminder>
<user_query>the actual ask</user_query>

A naive adapter that maps user turns to memory would therefore feed the system prompt into ov memory extraction. On a real 88-session corpus this pollutes the memory store badly enough to make recall useless — memories end up being extracts of the agent's own instructions rather than anything the human said.

Any WorkBuddy adapter must strip the injected block and keep only the <user_query> body, dropping the turn entirely if nothing survives.

Proposed Solution

Add openviking/ingest/sources/workbuddy.py — a JsonlLogSource subclass (~185 lines) registered as @register_source("workbuddy"):

  • file_glob = "*/*.jsonl", default_paths() -> ~/.workbuddy/projects
  • session_ref_for_file() — bounded peek (~400 lines, cached on mtime+size) to pick up title (ai-title record), started_at, meta.cwd, meta.model
  • parse_line() — keeps type == "message" with role in {user, assistant}, joins input_text / output_text blocks, strips host-injected <system-reminder> / <automation_system_reminder> / <previous_user_message> blocks, prefers the <user_query> body, drops empty turns
  • assistant peer via assistant_peer(model) → workbuddy__<model>
  • user peer via user_peer(cwd=...)

Registration is a 2-line change to sources/__init__.py. No config-schema change is needed — IngestConfig.harnesses is already a free-form Dict[str, IngestHarnessConfig], so ingest.harnesses.workbuddy works as soon as the source is registered.

Docs follow-up, same PR: add a workbuddy row (Status: Supported, default path ~/.workbuddy/projects/*/*.jsonl, note "injects system reminders into user turns; adapter strips them") to the "Supported harnesses" table in docs/{en,zh}/agent-integrations/09-log-ingestion.md, and add workbuddy to that page's opening harness enumeration.

Alternatives Considered

  1. Reuse the claude_code adapter with paths pointing at ~/.workbuddy/projects. Doesn't work — the record schema differs, so parse_line matches nothing. Verified against real logs.
  2. Reuse the codex adapter. Same problem, and Codex's payload nesting doesn't exist here.
  3. Feed user turns verbatim and let the server-side extractor sort out the noise. Rejected: the injected block is the system prompt, and memory extraction has no way to tell it apart from user-authored text.
  4. A separate third-party plugin package instead of an upstream source. Considered, but the work is ~185 lines, purely additive, and has no WorkBuddy-specific dependency — unlike the MCP/plugin side (see Additional Context), it belongs in-tree next to the other six adapters.

Feature Area

Session Management

Use Case

Keeping one memory store across all of a user's harnesses. A WorkBuddy user wants the same behaviour Claude Code / Codex / Cursor users already get: historical sessions backfilled once, then incrementally watched, so that find / search can recall a decision made in a WorkBuddy session from inside a different harness (or a different WorkBuddy workspace).

Config after this lands:

{
  "ingest": {
    "enabled": true,
    "harnesses": {
      "workbuddy": { "enabled": true, "mode": "both" }
    }
  }
}

Real-world result on a local corpus (mode: both): 87 sessions / 1552 messages / 86 commits backfilled on first run, then a steady-state read lag equal to the in-flight turn only.

Example API (Optional)

Not applicable — no public API surface changes. Registry side only:

from openviking.ingest.sources import (  # noqa: F401
    claude_code, codex, cursor, hermes, openclaw, opencode, workbuddy,
)

Additional Context

Verification already performed locally (on 0.4.20, so against essentially this interface):

  • ruff check / ruff format --check (repo rule set: E,W,F,I,C,B, line-length 100) → clean; mypy → clean
  • round-trip on real logs: 88 sessions discovered, titles/cwd/model resolved, <system-reminder> stripping confirmed by grepping the resulting memory namespace for system-reminder / user_query / Project Context → zero matches

Explicitly out of scope for this issue/PR (separate concerns, would need their own design discussion per CONTRIBUTING):

  • the read/recall side (an MCP stdio proxy bridging WorkBuddy's MCP client to an HTTP /mcp endpoint, plus a UserPromptSubmit hook for auto-recall) — these are WorkBuddy-side integration glue, not upstream Python, and the MCP half is already covered by the guide from #4321
  • a latent environment dependency in tests/ingest/test_peer.py::test_git_human_peer_falls_back_without_repo: it asserts resolve_git_human_peer(str(tmp_path), "me") == "me", but git config --get user.email falls back to the machine's global identity outside a repo, so that assertion fails on any developer machine that has user.email set. It passes in CI only because runners have no global git identity. Mentioned here for context; not touched by this PR (one PR = one concern). The proposed test therefore deliberately does not pin the user-side peer id.

Routing, per the module table in CONTRIBUTING_CN.md: this falls under Resource | 导入、Watch 与任务流水线.

Contribution

  • [x] I am willing to contribute to implementing this feature

zhangzhangco avatar Sep 15 '26 07:09 zhangzhangco

And maybe you could help implement it!

qin-ctx avatar Sep 15 '26 13:09 qin-ctx

Thanks! Implemented in #5084 — happy to adjust based on your review.

Three things I found while validating the adapter against the real 89-session corpus, which are worth folding back into the spec above:

  1. There is one more injected block: <memory_and_skills_reminder> (222 occurrences in this corpus). Rather than blacklisting a tag list, the adapter removes the host blocks and then keeps only <user_query> — a whitelist is more robust against new host-injected tags.
  2. Quoted history contains complete <user_query> blocks. 90 of 395 user turns contain more than one <user_query>, and a "take the first query" rule picks the wrong text in 52 of them (the quoted earlier turn wins). Stripping <previous_user_message> / <previous_assistant_message> / <previous_tool_call> before extracting the query fixes it: 324 turns then yield exactly one query, 71 yield none (compaction summaries and "continue from the summary" prompts) and are dropped, 0 are ambiguous.
  3. ai-title is not always near the top of the file — observed anywhere from line 2 to line ~1500, so a ~400-line peek is not always enough. session_ref_for_file walks the head under a 2000-line / 4 MB budget and caches the result on (mtime, size), since discovery runs on every poll.

Round-trip on that corpus with the new adapter: 89 sessions discovered, 40 with a title, 88 with cwd, 10 distinct models, and zero leftover markers (system-reminder, user_query, Project Context, …) in the imported user text.

Agreed on scope: the WorkBuddy-side MCP/hook glue and the test_peer.py environment dependency are left alone.

zhangzhangco avatar Sep 16 '26 01:09 zhangzhangco