graphify icon indicating copy to clipboard operation
graphify copied to clipboard

Add a true OpenCode semantic extraction backend in graphify/llm.py

Open MRNAQA opened this issue 7 months ago • 1 comments

Summary

Graphify currently supports OpenCode as a platform install and assistant-skill orchestration path, but not as a true direct semantic backend in graphify/llm.py.

Today:

  • graphify/llm.py supports claude and kimi
  • graphify/skill-opencode.md uses OpenCode agent orchestration
  • graphify update remains AST-only
  • OpenCode install writes AGENTS.md plus a bash-only plugin reminder

This leaves a gap for OpenCode users who want a first-class direct semantic backend, similar to the current direct backend layer, without depending on Claude-specific auth or the assistant-skill path.

Motivation

  • OpenCode is already a documented first-class platform in Graphify.
  • The current architecture has an asymmetry: OpenCode exists as orchestration/install support, but not as a direct backend entry in graphify/llm.py.
  • The current code/comments/docs can be confusing because backend capability, assistant orchestration, and AST-only update behavior are described in different places.

Proposed Solution

Add backend="opencode" to graphify/llm.py as a direct semantic extraction backend.

MVP scope:

  • Implement the backend via opencode run --format json
  • Reuse the existing _EXTRACTION_SYSTEM and _read_files(...) prompt-building flow
  • Parse OpenCode JSON event streams and extract the final assistant text payload
  • Pass that payload through the existing _parse_llm_json(...) normalization path
  • Keep extract_corpus_parallel(...) behavior unchanged apart from supporting the new backend

Acceptance Criteria

  • [ ] graphify.llm.extract_files_direct(..., backend="opencode") returns valid Graphify extraction fragments
  • [ ] graphify.llm.extract_corpus_parallel(..., backend="opencode") works with existing chunk merge behavior and callbacks
  • [ ] Subprocess failure, missing CLI, missing text payload, and malformed JSON outputs fail with deterministic errors
  • [ ] README and OpenCode skill docs clearly distinguish direct backend support from assistant orchestration and from AST-only graphify update
  • [ ] Tests cover success and failure cases for the new backend transport

Non-Goals

  • Do not implement opencode serve in the first PR
  • Do not redesign graphify update into a full semantic-update CLI
  • Do not rely on --file / --attach in the MVP transport
  • Do not remove the existing skill-opencode.md orchestration path

Alternatives Considered

  • opencode serve / SDK transport first: more moving parts, larger scope
  • Keep OpenCode as skill-only orchestration: preserves the current backend gap
  • Attachment-based transport: local validation suggests inline prompt text is the safer first step

Notes

During local validation, opencode run --format json --pure --dangerously-skip-permissions already produced a machine-readable JSON event stream with a final text event, which makes it a plausible MVP transport.

Also worth noting: graphify/llm.py comments currently imply a public direct-backend usage path, but the visible CLI path in __main__.py does not currently expose a general --backend switch. If maintainers agree, this issue can stay scoped to the backend-layer MVP and leave CLI exposure/docs cleanup as follow-up or adjacent work.

MRNAQA avatar May 01 '26 10:05 MRNAQA

Closing this because I am no longer pursuing the OpenCode semantic backend work.

MRNAQA avatar May 01 '26 11:05 MRNAQA