Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions docs/runtimes.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,25 @@ When adding a runtime, fill in the security matrix below and register it in `run
| Runtime | Purpose | Inference |
|---------|---------|-----------|
| `claude` | Production agent runs via Claude Code | Required |
| `opencode` | OpenCode agent runs (stub — not yet functional; resolved by `runtime.Resolve()` but not in `ValidRuntimes()` until implemented) | Required |
| `dummy` | Behaviour tests — scripted ops in real sandbox | None |

## Security feature matrix

| Feature | Where it runs | Claude Code | Notes for future runtimes |
|---------|---------------|-------------|---------------------------|
| **Host-side context injection scan** (DeBERTa / LLM Guard, unicode, SSRF patterns on repo context files) | Host + sandbox `scan context` | ✓ | Requires sandbox image with ML models; harness `security.host_scanners` |
| **Host-side runtime content scan** (agent def, SKILL.md, plugin JSON before upload) | Host (`scanRuntimeContent`) | ✓ | Uses `security.InputPipeline()`; not part of `Runtime` interface — runner responsibility |
| **Tirith** (Bash command scanning) | Sandbox PreToolUse hook | ✓ | `tirith_check.py`; harness `security.sandbox_hooks.tirith` |
| **SSRF pre-tool** | Sandbox PreToolUse hook | ✓ | `ssrf_pretool.py`; default on |
| **Canary token detection** | Sandbox Pre/PostToolUse hooks | ✓ | `canary_pretool.py` / `canary_posttool.py` |
| **Secret redaction** | Sandbox PostToolUse hook | ✓ | `secret_redact_posttool.py` |
| **Unicode normalization** | Sandbox PostToolUse hook | ✓ | `unicode_posttool.py` |
| **Context suppression** | Sandbox PostToolUse hook | ✓ | `context_suppress_posttool.py` |
| **Tool allowlist** | Sandbox PreToolUse hook | opt-in | `tool_allowlist_pretool.py`; requires `FULLSEND_TOOL_ALLOWLIST` |
| **Prompt injection (DeBERTa)** | Host Path A + sandbox Path B | ✓ | Same scanner stack as context files when enabled in harness |
| **Optional Claude sandbox hooks** | `ClaudeHooksBootstrap` type assert | ✓ only | Other runtimes must define their own hook/bootstrap extension; absence means **no** sandbox tool hooks installed |
| **Transcript / debug artifacts** | `TranscriptHandler` | ✓ (stream-json, `claude-debug.log`) | Format-specific; not shared across runtimes |
| Feature | Where it runs | Claude Code | OpenCode (stub) | Notes for future runtimes |
|---------|---------------|-------------|-----------------|---------------------------|
| **Host-side context injection scan** (DeBERTa / LLM Guard, unicode, SSRF patterns on repo context files) | Host + sandbox `scan context` | ✓ | N/A — stub | Requires sandbox image with ML models; harness `security.host_scanners` |
| **Host-side runtime content scan** (agent def, SKILL.md, plugin JSON before upload) | Host (`scanRuntimeContent`) | ✓ | N/A — stub | Uses `security.InputPipeline()`; not part of `Runtime` interface — runner responsibility |
| **Tirith** (Bash command scanning) | Sandbox PreToolUse hook | ✓ | N/A — stub | `tirith_check.py`; harness `security.sandbox_hooks.tirith` |
| **SSRF pre-tool** | Sandbox PreToolUse hook | ✓ | N/A — stub | `ssrf_pretool.py`; default on |
| **Canary token detection** | Sandbox Pre/PostToolUse hooks | ✓ | N/A — stub | `canary_pretool.py` / `canary_posttool.py` |
| **Secret redaction** | Sandbox PostToolUse hook | ✓ | N/A — stub | `secret_redact_posttool.py` |
| **Unicode normalization** | Sandbox PostToolUse hook | ✓ | N/A — stub | `unicode_posttool.py` |
| **Context suppression** | Sandbox PostToolUse hook | ✓ | N/A — stub | `context_suppress_posttool.py` |
| **Tool allowlist** | Sandbox PreToolUse hook | opt-in | N/A — stub | `tool_allowlist_pretool.py`; requires `FULLSEND_TOOL_ALLOWLIST` |
| **Prompt injection (DeBERTa)** | Host Path A + sandbox Path B | ✓ | N/A — stub | Same scanner stack as context files when enabled in harness |
| **Optional Claude sandbox hooks** | `ClaudeHooksBootstrap` type assert | ✓ only | ✗ — does not implement `ClaudeHooksBootstrap` | Other runtimes must define their own hook/bootstrap extension; absence means **no** sandbox tool hooks installed |
| **Transcript / debug artifacts** | `TranscriptHandler` | ✓ (stream-json, `claude-debug.log`) | No-op — see #1935 | Format-specific; not shared across runtimes |

### Fail modes

Expand Down
15 changes: 14 additions & 1 deletion internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ func TestValidRuntimes(t *testing.T) {
runtimes := ValidRuntimes()
assert.Contains(t, runtimes, "claude")
assert.Contains(t, runtimes, "dummy")
assert.NotContains(t, runtimes, "opencode", "opencode is resolved via runtime.Resolve() but not user-selectable until implemented")
}

func TestOrgConfigValidateRuntime(t *testing.T) {
Expand All @@ -397,6 +398,11 @@ func TestOrgConfigValidateRuntime(t *testing.T) {
}
require.NoError(t, cfg.Validate())

// opencode is resolvable via runtime.Resolve() but not in ValidRuntimes(),
// so config validation must reject it until the runtime is implemented.
cfg.Defaults.Runtime = "opencode"
require.Error(t, cfg.Validate())

cfg.Defaults.Runtime = "invalid"
require.Error(t, cfg.Validate())
}
Expand Down Expand Up @@ -646,10 +652,17 @@ func TestPerRepoConfigValidate_Runtime(t *testing.T) {
}
assert.NoError(t, cfg.Validate())

cfg.Runtime = "invalid"
// opencode is resolvable via runtime.Resolve() but not in ValidRuntimes(),
// so config validation must reject it until the runtime is implemented.
cfg.Runtime = "opencode"
err := cfg.Validate()
assert.Error(t, err)
assert.Contains(t, err.Error(), "invalid runtime")

cfg.Runtime = "invalid"
err = cfg.Validate()
assert.Error(t, err)
assert.Contains(t, err.Error(), "invalid runtime")
}

func TestParsePerRepoConfig(t *testing.T) {
Expand Down
75 changes: 75 additions & 0 deletions internal/runtime/opencode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package runtime

import (
"context"
"fmt"
"io"
"time"

"github.com/fullsend-ai/fullsend/internal/sandbox"
"github.com/fullsend-ai/fullsend/internal/ui"
)

// OpenCodeRuntime is a stub implementation of the Runtime and TranscriptHandler
// interfaces for the OpenCode agent runtime. All methods are no-ops or return
// not-implemented errors. Subsequent PRs will fill in stream parsing, bootstrap,
// run execution, and transcript extraction.
type OpenCodeRuntime struct{}

func (OpenCodeRuntime) Name() string { return "opencode" }

// System returns the OTEL GenAI gen_ai.system value. OpenCode is multi-provider
// (Anthropic, OpenAI, Google, etc.), so the system is the runtime itself rather
// than a single model vendor. The actual model vendor may be capturable from
// opencode's stream/export events in a future PR once the event schema is
// confirmed (see #1935).
func (OpenCodeRuntime) System() string { return "opencode" }

// ConfigDir returns the opencode config directory inside the sandbox.
// Provisional — verify opencode's config discovery before implementing
// Bootstrap (#1260). Consider placing config outside the agent-writable
// workspace (like Claude's /sandbox/claude-config) to prevent the agent
// from rewriting its own runtime config.
func (OpenCodeRuntime) ConfigDir() string { return sandbox.SandboxWorkspace + "/.opencode" }
Comment thread
sonupreetam marked this conversation as resolved.
Resolved

func (OpenCodeRuntime) WorkspaceDir() string { return sandbox.SandboxWorkspace }

func (OpenCodeRuntime) EnvExports() []string { return nil }

func (OpenCodeRuntime) Bootstrap(_ BootstrapInput) error {
return fmt.Errorf("opencode runtime is not yet implemented")
}

func (OpenCodeRuntime) Run(_ context.Context, _ RunParams, _ *ui.Printer, _ time.Time, _ *RunMetrics) (int, error) {
return -1, fmt.Errorf("opencode runtime is not yet implemented")
}

func (OpenCodeRuntime) ClearIterationArtifacts(_ string) error { return nil }

// TranscriptHandler stub methods — return not-implemented errors for extract
// methods (to avoid silent success claims in CI logs) and no-ops for parse
// methods (which correctly indicate "nothing found"). See #1935.

func (OpenCodeRuntime) ExtractTranscripts(_, _, _ string) error {
return fmt.Errorf("opencode transcript extraction not implemented (see #1935)")
}

func (OpenCodeRuntime) ExtractDebugLog(_, _, _ string) error {
return fmt.Errorf("opencode debug log extraction not implemented (see #1935)")
}

func (OpenCodeRuntime) ParseTranscriptErrors(_ string) []TranscriptError { return nil }

func (OpenCodeRuntime) ParseTranscriptFile(_ string) (TranscriptError, bool) {
return TranscriptError{}, false
}

func (OpenCodeRuntime) EmitTranscriptErrors(w io.Writer, summaries []TranscriptError) {
emitTranscriptErrors(w, summaries)
}

// Compile-time interface assertions.
var (
_ Runtime = OpenCodeRuntime{}
_ TranscriptHandler = OpenCodeRuntime{}
)
70 changes: 70 additions & 0 deletions internal/runtime/opencode_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package runtime

import (
"bytes"
"context"
"testing"
"time"

"github.com/fullsend-ai/fullsend/internal/sandbox"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestOpenCodeRuntimeMetadata(t *testing.T) {
t.Parallel()

rt := OpenCodeRuntime{}
assert.Equal(t, "opencode", rt.Name())
assert.Equal(t, "opencode", rt.System())
assert.Equal(t, sandbox.SandboxWorkspace+"/.opencode", rt.ConfigDir()) // provisional — see ConfigDir() comment
assert.Equal(t, sandbox.SandboxWorkspace, rt.WorkspaceDir())
assert.Nil(t, rt.EnvExports())
}

func TestOpenCodeRuntimeRun_NotImplemented(t *testing.T) {
t.Parallel()

rt := OpenCodeRuntime{}
exit, err := rt.Run(context.Background(), RunParams{}, nil, time.Now(), nil)
assert.Equal(t, -1, exit)
require.Error(t, err)
assert.Contains(t, err.Error(), "not yet implemented")
}

func TestOpenCodeRuntimeBootstrap_NotImplemented(t *testing.T) {
t.Parallel()

rt := OpenCodeRuntime{}
err := rt.Bootstrap(nil)
require.Error(t, err)
assert.Contains(t, err.Error(), "not yet implemented")
}

func TestOpenCodeRuntimeExtractStubs_NotImplemented(t *testing.T) {
t.Parallel()

rt := OpenCodeRuntime{}
err := rt.ExtractTranscripts("", "", "")
require.Error(t, err)
assert.Contains(t, err.Error(), "#1935")

err = rt.ExtractDebugLog("", "", "")
require.Error(t, err)
assert.Contains(t, err.Error(), "#1935")
}

func TestOpenCodeRuntimeNoopMethods(t *testing.T) {
t.Parallel()

rt := OpenCodeRuntime{}
assert.Nil(t, rt.ParseTranscriptErrors(""))
assert.NoError(t, rt.ClearIterationArtifacts(""))

te, ok := rt.ParseTranscriptFile("")
assert.False(t, ok)
assert.Equal(t, TranscriptError{}, te)

var buf bytes.Buffer
rt.EmitTranscriptErrors(&buf, nil)
}
3 changes: 3 additions & 0 deletions internal/runtime/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ func Resolve(name string) (Backend, error) {
// Selected only via explicit per-repo/org config (behaviour test orgs).
r := DummyRuntime{}
return Backend{Runtime: r, Transcripts: r}, nil
case "opencode":
Comment thread
sonupreetam marked this conversation as resolved.
Resolved
r := OpenCodeRuntime{}
return Backend{Runtime: r, Transcripts: r}, nil
default:
return Backend{}, fmt.Errorf("unknown runtime %q: must be one of %s", name, strings.Join(config.ValidRuntimes(), ", "))
}
Expand Down
15 changes: 15 additions & 0 deletions internal/runtime/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ func TestResolve(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, "dummy", dummy.Runtime.Name())

oc, err := Resolve("opencode")
require.NoError(t, err)
assert.Equal(t, "opencode", oc.Runtime.Name())
assert.NotNil(t, oc.Transcripts)
_, isOC := oc.Transcripts.(OpenCodeRuntime)
assert.True(t, isOC, "Transcripts should be OpenCodeRuntime")

_, err = Resolve("unknown")
require.Error(t, err)
}
Expand Down Expand Up @@ -57,6 +64,14 @@ func TestResolveFromPerRepoConfig(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, "dummy", dummyBackend.Runtime.Name())

// opencode is not in ValidRuntimes() but is resolvable via Resolve().
// A hand-written config bypassing validation can reach the stub.
ocCfg := config.NewPerRepoConfig(nil, "")
ocCfg.SetRuntime("opencode")
ocBackend, err := ResolveFromPerRepoConfig(ocCfg)
require.NoError(t, err)
assert.Equal(t, "opencode", ocBackend.Runtime.Name())

invalidCfg := config.NewPerRepoConfig(nil, "")
invalidCfg.SetRuntime("invalid")
_, err = ResolveFromPerRepoConfig(invalidCfg)
Expand Down
Loading