Skip to content

Add first-class OpenCode documentation and support - #71

Open
ainetx wants to merge 2 commits into
mainfrom
opencode
Open

Add first-class OpenCode documentation and support#71
ainetx wants to merge 2 commits into
mainfrom
opencode

Conversation

@ainetx

@ainetx ainetx commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Added opt-in support for OpenCode v1.18.4 as an additional agent host.
    • Generates OpenCode-native subagents while preserving user-managed files and configurations.
    • Added collision detection, stale-file reconciliation, preview reporting, and read-only integration inspection.
    • Reports partial results when existing files cannot be safely managed.
  • Documentation

    • Updated architecture, product, setup, and integration guidance with OpenCode compatibility, limitations, and usage instructions.
  • Tests

    • Added compatibility fixtures and comprehensive coverage for generation, ownership, collisions, and partial outcomes.

ainetx and others added 2 commits July 23, 2026 21:08
Signed-off-by: ainetx <viator@via-net.org>
Co-authored-by: Constructor Studio <291158726+constructor-studio[bot]@users.noreply.github.com>
Studio-Generated-By: Constructor Studio
Studio-Source-Repo: https://github.com/constructorfabric/studio
Constructor-Fabric: https://github.com/constructorfabric
Studio-Version: skill=1.0.0, cli=1.5.10
Studio-Workflows: cf-sdlc-doc-prd,cf-sdlc-doc-design,cf-sdlc-doc-feature
Signed-off-by: ainetx <viator@via-net.org>
Co-authored-by: Constructor Studio <291158726+constructor-studio[bot]@users.noreply.github.com>
Studio-Generated-By: Constructor Studio
Studio-Source-Repo: https://github.com/constructorfabric/studio
Constructor-Fabric: https://github.com/constructorfabric
Studio-Version: skill=1.0.0, cli=1.5.10
Studio-Workflows: cf-sdlc-implement,cf-code-planning,cf-documenting-gen
@code-ranker-app

Copy link
Copy Markdown
Contributor

@sonarqubecloud

sonarqubecloud Bot commented Aug 4, 2026

Copy link
Copy Markdown

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

OpenCode integration

Layer / File(s) Summary
Requirements and product contract
architecture/PRD.md
Defines OpenCode v1.18.4 as an explicit-only host with bounded capabilities, preserved configuration, collision metadata, acceptance criteria, and compatibility assumptions.
Architecture and feature design
architecture/DESIGN.md, architecture/features/agent-integration.md
Documents native .opencode/agents output, ownership markers, collision exclusions, partial results, read-only inspection, state transitions, and deferred capabilities.
Status and operator documentation
architecture/DECOMPOSITION.md, guides/AGENT-TOOLS.md
Updates feature statuses and documents OpenCode commands, supported capabilities, ownership rules, inspection behavior, and default-host selection.
Native generation and ownership management
skills/studio/scripts/studio/commands/agents.py
Adds OpenCode templates, registration, markers, persisted exclusions, collision preservation, stale-file reconciliation, partial results, and dedicated native processing.
CLI inspection and v2 routing
skills/studio/scripts/studio/commands/agents.py, tests/test_cmd_generate_agents_v2.py
Adds explicit selection, the --opencode shortcut, read-only inspection, preserved-output confirmation, listing output, and bypasses manifest translation for OpenCode.
Compatibility and integration validation
tests/fixtures/opencode/*, tests/test_agents_coverage.py, tests/test_cli_agents_e2e.py, tests/test_subagent_registration.py
Adds v1.18.4 fixture validation and tests for default exclusion, native output, collisions, partial results, read-only state, and ownership-based cleanup.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Operator
  participant AgentCLI
  participant AgentGenerator
  participant OpenCodeFiles
  participant OwnershipRecords

  Operator->>AgentCLI: select OpenCode
  AgentCLI->>AgentGenerator: resolve explicit request
  AgentGenerator->>OpenCodeFiles: inspect markers and cf-* files
  OpenCodeFiles-->>AgentGenerator: owned outputs and collisions
  AgentGenerator->>OwnershipRecords: save path-only exclusions
  AgentGenerator->>OpenCodeFiles: write only permitted native agents
  AgentGenerator-->>AgentCLI: generated, preserved, or partial status
  AgentCLI-->>Operator: report OpenCode state
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.70% 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 pull request's main changes: first-class OpenCode documentation and support.
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 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch opencode

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

@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: 3

🧹 Nitpick comments (2)
skills/studio/scripts/studio/commands/agents.py (2)

5556-5579: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Write the ownership record atomically.

_save_opencode_unowned_outputs writes the record in place. If the process stops during the write, the file becomes truncated or invalid JSON. _load_opencode_unowned_outputs then warns and returns an empty set, so recorded exclusions are lost for the next run. Write to a temporary file in the same directory and replace the target.

♻️ Proposed atomic write
     try:
         record_path.parent.mkdir(parents=True, exist_ok=True)
-        record_path.write_text(
-            json.dumps(
-                {
-                    "schema": _OPENCODE_UNOWNED_OUTPUTS_SCHEMA,
-                    "paths": sorted(paths),
-                },
-                indent=2,
-            ) + "\n",
-            encoding="utf-8",
-        )
+        payload = json.dumps(
+            {
+                "schema": _OPENCODE_UNOWNED_OUTPUTS_SCHEMA,
+                "paths": sorted(paths),
+            },
+            indent=2,
+        ) + "\n"
+        tmp_path = record_path.with_name(record_path.name + ".tmp")
+        tmp_path.write_text(payload, encoding="utf-8")
+        os.replace(tmp_path, record_path)
     except OSError as exc:
🤖 Prompt for 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.

In `@skills/studio/scripts/studio/commands/agents.py` around lines 5556 - 5579,
Update _save_opencode_unowned_outputs to serialize the record to a temporary
file in record_path.parent, then atomically replace record_path only after the
temporary write completes successfully. Preserve the existing schema validation
and warning behavior, and clean up any temporary file on failure so interrupted
writes cannot leave a truncated ownership record.

5641-5641: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Derive the sentinel path from _INSTALL_MARKERS.

.opencode/.cf-studio-installed is now written in four places (Line 5641, Line 5700, Line 6087, Line 6361) while _INSTALL_MARKERS["opencode"] at Line 3475 already declares it. If the marker path changes, the ownership checks and the marker writer can drift apart. Add one helper that returns the path and use it in all four sites.

♻️ Proposed helper
+def _opencode_install_marker_path(project_root: Path) -> Path:
+    """Return the OpenCode installation sentinel path."""
+    return project_root / _INSTALL_MARKERS["opencode"][0]
     rel_path = _safe_relpath(canonical, root_resolved)
-    install_marker = project_root / ".opencode" / ".cf-studio-installed"
+    install_marker = _opencode_install_marker_path(project_root)
🤖 Prompt for 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.

In `@skills/studio/scripts/studio/commands/agents.py` at line 5641, Derive the
opencode installation marker through a single helper backed by
_INSTALL_MARKERS["opencode"], then replace the hardcoded
.opencode/.cf-studio-installed path at the four referenced sites, including the
ownership checks and marker writer. Keep all existing marker behavior unchanged.

Source: Linters/SAST tools

🤖 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 `@architecture/DECOMPOSITION.md`:
- Line 289: Update Feature 2.5's scope, requirements, API, and data sections in
the DECOMPOSITION.md file to include the complete OpenCode agent integration
inventory that is already documented in DESIGN.md and AGENT-TOOLS.md.
Specifically, add the missing cpt-studio-fr-core-opencode agent (the OpenCode
CLI forms handler), include the `.opencode` output paths, and document the
associated metadata paths that are currently omitted. Ensure that Feature 2.5
now lists all supported agents and accurately reflects the full scope of
OpenCode integration covered in the referenced design and tools documentation.

In `@architecture/DESIGN.md`:
- Around line 792-800: Update the OpenAI support entry in the documented
six-agent list to include the native `.codex/agents/` output alongside
`.agents/skills/`. Keep the existing OpenAI scope and all other agent
descriptions unchanged.

In `@tests/test_cmd_generate_agents_v2.py`:
- Around line 813-815: Update the _spy_confirm confirmation stub to return the
expected "PROCEED" action string instead of the boolean True, while preserving
its existing preview argument capture so _run_v2_generate_path continues into
_run_v2_pipeline.

---

Nitpick comments:
In `@skills/studio/scripts/studio/commands/agents.py`:
- Around line 5556-5579: Update _save_opencode_unowned_outputs to serialize the
record to a temporary file in record_path.parent, then atomically replace
record_path only after the temporary write completes successfully. Preserve the
existing schema validation and warning behavior, and clean up any temporary file
on failure so interrupted writes cannot leave a truncated ownership record.
- Line 5641: Derive the opencode installation marker through a single helper
backed by _INSTALL_MARKERS["opencode"], then replace the hardcoded
.opencode/.cf-studio-installed path at the four referenced sites, including the
ownership checks and marker writer. Keep all existing marker behavior unchanged.
🪄 Autofix

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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2b9cdc22-c152-45b4-8734-c6d32c9420c2

📥 Commits

Reviewing files that changed from the base of the PR and between 420aff3 and 8063312.

📒 Files selected for processing (11)
  • architecture/DECOMPOSITION.md
  • architecture/DESIGN.md
  • architecture/PRD.md
  • architecture/features/agent-integration.md
  • guides/AGENT-TOOLS.md
  • skills/studio/scripts/studio/commands/agents.py
  • tests/fixtures/opencode/v1.18.4/compatibility.json
  • tests/test_agents_coverage.py
  • tests/test_cli_agents_e2e.py
  • tests/test_cmd_generate_agents_v2.py
  • tests/test_subagent_registration.py

- **Design Constraints Covered**:

None
- `p1` - `cpt-studio-constraint-opencode-owned-output`

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Complete the Agent Integration feature inventory for OpenCode.

Line 289 adds the OpenCode ownership constraint, but Feature 2.5 still lists only five supported agents. It also omits cpt-studio-fr-core-opencode, the OpenCode CLI forms, and the .opencode output and metadata paths.

Update the Feature 2.5 scope, requirements, API, and data sections so architecture/DECOMPOSITION.md matches architecture/DESIGN.md and guides/AGENT-TOOLS.md.

🤖 Prompt for 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.

In `@architecture/DECOMPOSITION.md` at line 289, Update Feature 2.5's scope,
requirements, API, and data sections in the DECOMPOSITION.md file to include the
complete OpenCode agent integration inventory that is already documented in
DESIGN.md and AGENT-TOOLS.md. Specifically, add the missing
cpt-studio-fr-core-opencode agent (the OpenCode CLI forms handler), include the
`.opencode` output paths, and document the associated metadata paths that are
currently omitted. Ensure that Feature 2.5 now lists all supported agents and
accurately reflects the full scope of OpenCode integration covered in the
referenced design and tools documentation.

Comment thread architecture/DESIGN.md
Comment on lines +792 to +800
- Support 6 agents: Windsurf (`.windsurf/workflows/` + `.agents/skills/`), Cursor (`.cursor/commands/` + `.agents/skills/`), Claude (`.claude/commands/` + `.claude/agents/`), Copilot (`.github/prompts/` + `.github/agents/` + `.agents/skills/`), OpenAI (`.agents/skills/` only), and explicitly selected OpenCode (`.agents/skills` discovery plus `.opencode/agents/cf-*.md` native subagents)
- For OpenCode v1.18.4, translate the current `agents.toml` registry profiles into native subagent files without adding model/provider defaults or `.opencode/commands`; defer v2 manifest translation
- Full overwrite on each invocation applies only to generator-owned `cf-*` outputs whose ownership is proven (no merge with existing files). For OpenCode, proof requires `.opencode/.cf-studio-installed` and the per-file Studio marker; an ownership-unproven `cf-*` name collision is preserved, path-recorded as an exclusion, and reported as partial
- Normalize generated agent output names so new files use a `cf-` prefix or a dedicated Studio-owned path; migrate legacy non-prefixed generated storytelling files only when ownership checks prove they are generated, and preserve user-edited files
- Support `--agent` flag for single-agent regeneration
- Support `--agent` flag for single-agent regeneration; OpenCode is selected only by canonical `--agent opencode` or convenience `--opencode`, never by the initial default target set

##### Responsibility boundaries

Does NOT maintain agent-specific state. Does NOT define SKILL extension content — collects from kit files. Does NOT persist agent selection in config.
Does NOT maintain agent-specific state. Does NOT define SKILL extension content — collects from kit files. Does NOT persist agent selection in config. In the OpenCode rollout it does NOT manage root `AGENTS.md`, user `opencode.json`, OpenCode installation or execution, runtime model/provider defaults, or user-owned `.opencode` content.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Check whether OpenAI/Codex generation writes .codex/agents/ subagent files.
rg -n '\.codex/agents' architecture/features/subagent-registration.md skills/studio/scripts/studio/commands/agents.py 2>/dev/null
rg -n 'OpenAI' -A3 -B3 architecture/DESIGN.md | head -80

Repository: constructorfabric/studio

Length of output: 6913


Document the OpenAI/Codex native output surface. The implementation and feature contract generate files under .codex/agents/. Update OpenAI ('.agents/skills/' only) to include .codex/agents/.

🧰 Tools
🪛 markdownlint-cli2 (0.23.1)

[warning] 798-798: Multiple headings with the same content

(MD024, no-duplicate-heading)

🤖 Prompt for 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.

In `@architecture/DESIGN.md` around lines 792 - 800, Update the OpenAI support
entry in the documented six-agent list to include the native `.codex/agents/`
output alongside `.agents/skills/`. Keep the existing OpenAI scope and all other
agent descriptions unchanged.

Comment on lines +813 to 815
def _spy_confirm(args, preview_create, preview_update, preview_delete=0, **_kwargs):
confirm_args.append((preview_create, preview_update, preview_delete))
return True # proceed

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Return the "PROCEED" action from the confirmation spy.

_confirm_v2_generation returns an action string. _run_v2_generate_path returns 0 when the value is not "PROCEED". The spy returns True, so the run stops right after confirmation and never reaches _run_v2_pipeline. The assertions still pass because the preview counts are captured before confirmation, so the test silently covers less than the comment claims.

💚 Proposed fix for the confirmation spy contract
         def _spy_confirm(args, preview_create, preview_update, preview_delete=0, **_kwargs):
             confirm_args.append((preview_create, preview_update, preview_delete))
-            return True  # proceed
+            return "PROCEED"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def _spy_confirm(args, preview_create, preview_update, preview_delete=0, **_kwargs):
confirm_args.append((preview_create, preview_update, preview_delete))
return True # proceed
def _spy_confirm(args, preview_create, preview_update, preview_delete=0, **_kwargs):
confirm_args.append((preview_create, preview_update, preview_delete))
return "PROCEED"
🤖 Prompt for 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.

In `@tests/test_cmd_generate_agents_v2.py` around lines 813 - 815, Update the
_spy_confirm confirmation stub to return the expected "PROCEED" action string
instead of the boolean True, while preserving its existing preview argument
capture so _run_v2_generate_path continues into _run_v2_pipeline.

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