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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- **Dashboard and API: link review perspectives to a repo file and set up an agent sandbox without editing config files (#18797).** Review Gate has owner, repo, path and ref fields with the resolver status and an Unlink button; `PUT /api/config/review` accepts `perspectives_source` (set, and `null` to clear), gated like `definition_source` by `GitHubPromptAllowed` with an error that points to Settings, Security, Prompt sources, and re-resolves the set in the same request, so no restart is needed. The 409 for inline perspective edits now names Unlink. An agent's General tab gains editable sandbox image, runtime and Job fields and a "Copy sandbox settings from..." action (Secret names only, never values); `PUT /api/config/agent/<name>/general` takes `sandboxImage`, `sandboxRuntime`, `sandboxJob` and `sandboxCopyFrom`; Settings, Security gains `agent_sandbox.job.env_from_secrets`. Saving an enabled sandbox with no image anywhere is refused with `sandbox.image` named, and the "no sandbox image" warning links to the controls that fix it.
4 changes: 4 additions & 0 deletions src/docs/agent-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,10 @@ is refused at the tier the non-conversational half requires.
For prompt file resolution and the complete built-in `${VAR}` reference, see
[Policy and prompt templates](../policies/README.md).

### Sandbox settings (`agents.<name>.sandbox`)

An agent's `sandbox` block (image, runtime, Job fields) is editable from its General tab under "Sandbox settings: image, runtime and Job", and through `PUT /api/config/agent/<name>/general` with `sandboxImage`, `sandboxRuntime`, `sandboxJob` and `sandboxCopyFrom` (hivecommons/hive#18797). A blank value inherits the hive-wide `agent_sandbox` default, which is set under Settings, Security. "Copy sandbox settings from..." copies another agent's complete block, Secret names included and never values. Enabling a sandbox that resolves no image is refused with the field named. The full set of controls and keys is in [sandbox-isolation.md](sandbox-isolation.md#setting-up-a-sandbox-from-the-dashboard).

### Declarative extensions

Three optional blocks replace hardcoded behavior with declarations:
Expand Down
6 changes: 4 additions & 2 deletions src/docs/review-swarm.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ perspectives:
- **The source wins; inline is the fallback.** While the source resolves, its set replaces inline `review.perspectives` and `review.perspective_prompts` everywhere the effective set is read (`ReviewConfig.EffectivePerspectives`). Inline values stay in the config and apply whenever nothing resolves.
- **Fallback order.** A fetch that has no GitHub client or fails, and a document that is malformed, each keep the last-known-good document for that source. With none cached, the inline set applies, and if that is empty too, the built-ins. A source whose repo is not on the allowlist is ignored outright (logged, nothing fetched or cached) and the inline set applies. A malformed document keeps the last-known-good set and records a warning rather than quietly dropping to the five built-ins. Only a document that parsed cleanly is remembered, so the cache never holds a corrupt set. A fetch is bounded to 8 seconds.
- **When it resolves.** Resolution happens at startup, before the first relay install, and again on every config reload. Each time the relay's perspective set is reinstalled, so a verdict naming a removed perspective is refused and an added one is accepted without a restart. Heads waiting on a removed perspective settle rather than stay stuck (#14905). A dashboard edit of the review config keeps the linked set.
- **Same trust gate as `definition_source`.** The source repo must be on the seed-only `variables.security.github_prompt_allowlist`; see [agent-configuration.md](agent-configuration.md#the-trust-boundary-allowlisted-repos-are-seed-only).
- **Dashboard.** Governor → Features → Review Gate → Perspectives shows the linked set (not the inline fallback), a "Linked to owner/repo/path@ref" line, and the resolver's status and any warning. The perspective checkboxes and focus text are read-only and "Add perspective" is hidden, and `PUT /api/config/review` answers 409 for `perspectives` / `perspective_prompts` edits that the next resolve would replace. `combined_perspectives`, `plan_match` and `max_perspectives_per_pr` stay editable.
- **Same trust gate as `definition_source`.** The source repo must be allowed by `GitHubPromptAllowed`: on the seed `variables.security.github_prompt_allowlist`, or approved by an owner under Settings, Security, Prompt sources; see [agent-configuration.md](agent-configuration.md#the-trust-boundary-allowlisted-repos-are-seed-only).
- **Dashboard.** Governor → Features → Review Gate → Perspectives has a "Link perspectives to a repo file" section with `owner`, `repo`, `path` and `ref` fields, so the source never needs a hand edit of the config files (hivecommons/hive#18797). While a source is set the section shows the resolver's status (`github:owner/repo@ref`, `github-cache:owner/repo`, or "not resolved yet") and any warning, plus an **Unlink** button. The perspectives below it show the linked set (not the inline fallback) with a "Linked to owner/repo/path@ref" line; the checkboxes and focus text are read-only and "Add perspective" is hidden. Blank all four fields and save to unlink too. If the linked repo is not approved the section says so and points to Settings, Security, Prompt sources. `combined_perspectives`, `plan_match` and `max_perspectives_per_pr` stay editable.
- **API.** `PUT /api/config/review` accepts `perspectives_source` as `{"owner": "...", "repo": "...", "path": "...", "ref": "..."}` to set it, and `null` (or an object missing `owner`, `repo` or `path`) to clear it. The repo must pass the same gate as `definition_source` (the seed allowlist or an owner approval, see below); otherwise the request is refused with 400 and a message that names the repo and points to Settings, Security, Prompt sources. A successful save re-resolves the source in the same request, so the new set is in effect without a restart, and unlinking drops the linked set at once. `GET /api/config/review` returns `perspectives_source`, `perspectives_linked`, `perspectives_source_status`, `perspectives_source_warning` and `perspectives_source_approved`. While a source is set, `PUT /api/config/review` answers 409 for `perspectives` / `perspective_prompts` edits that the next resolve would replace; the message names the Unlink button. Send `perspectives_source: null` together with the inline edit to unlink and edit in one request.
- **Both config files.** The save writes the same marshalled config to `/data/hive.yaml.runtime` and `/data/hive.yaml.dashboard` through the one `Config.Save` path, so a dashboard or API change to the source is never half-applied. Do not hand-edit either file for this setting.

### Combined perspectives: recommended, opt-in

Expand Down
10 changes: 10 additions & 0 deletions src/docs/sandbox-isolation.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,16 @@ A target in another repository is ignored, because the workspace clones the prim

**Refusals fail the kick and push nothing.** A closed PR, a fork PR, a PR another agent opened, a PR no hive agent opened, a head that moved since checkout, an unreadable PR or a failed scan all fail the kick with a reason that names the PR. The run record carries the reason, and the audit log gets a `sandbox_target_pr_refused` line with `repo=`, `number=`, `source=` and `reason=`, or the broker's usual `sandbox_broker_rejected`. If the refusal comes after the run, the commits stay in the workspace, and the run record notes them as withheld.

## Setting up a sandbox from the dashboard

Nothing about a sandbox needs a hand edit of the config files (hivecommons/hive#18797). Everything below saves through the normal config API, which writes both `/data/hive.yaml.runtime` and `/data/hive.yaml.dashboard`.

- **Hive-wide defaults.** Settings, Security, "Advanced sandbox: default image and Job settings" edits `agent_sandbox.image`, `runtime`, the Job defaults (workspace claim and mount, service account, scheduler name, TTL) and `agent_sandbox.job.env_from_secrets`. The section opens by itself when the sandbox is on and no image is set. API: `PUT /api/config/governor/security` with `agentSandboxImage`, `agentSandboxRuntime`, `agentSandboxJobWorkspaceClaim`, `agentSandboxJobEnvFromSecrets` and the other `agentSandbox*` keys.
- **One agent.** The agent's General tab has "Sandbox settings: image, runtime and Job" with its own `sandbox.image`, `sandbox.runtime` and Job fields. A blank field inherits the hive default, shown as the placeholder. API: `PUT /api/config/agent/<name>/general` with `sandboxImage`, `sandboxRuntime` and `sandboxJob` (`workspaceClaim`, `workspaceClaimMount`, `serviceAccount`, `schedulerName`, `ttlSeconds`, `envFromSecrets`). Node selector, tolerations, resources and volumes have no field; they travel with the copy action below and survive an edit.
- **Copy from another agent.** "Copy sandbox settings from..." lists the agents whose block is complete (an image and a usable runtime, plus a workspace claim for `runtime: job`) and copies the block, turning the sandbox on. API: `PUT /api/config/agent/<name>/general` with `{"sandboxCopyFrom": "<agent>"}`. The copy is deep. The source's `publish.verify` commands are not copied (they are written for the source's repository); the receiving agent keeps its own.
- **Secrets are names only.** `env_from_secrets` holds Kubernetes Secret names. The API refuses anything that is not a valid name (a `KEY=value` pair, for one), so a value can never be written to the config file through these controls.
- **Refused without an image.** Turning the sandbox on, or saving an enabled sandbox, when no image resolves from the agent or `agent_sandbox.image` is refused with 400 and a message naming `sandbox.image` and `agent_sandbox.image`. The "no sandbox image" warning on the agent card and in the General tab links to the agent's Sandbox settings and to the default image controls.

## Running sandboxed kicks as Kubernetes Jobs

`sandbox.runtime: job` runs an agent's sandboxed kicks as a Kubernetes `Job` in the hive's own namespace instead of a rootless Podman container on the hive pod's node ([#6311](https://github.com/hivecommons/hive/issues/6311)). It exists for work that must run in a **different runtime than the hive image** - a different base OS, a heavyweight toolchain, or on **accelerator hardware** reached through a device plugin - while hive stays the orchestrator.
Expand Down
62 changes: 62 additions & 0 deletions src/pkg/config/save_perspectives_sandbox_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package config

import (
"os"
"path/filepath"
"strings"
"testing"
)

// hivecommons/hive#18797: review.perspectives_source and the agent sandbox
// block are set from the dashboard, so one save must leave /data/hive.yaml.runtime
// and /data/hive.yaml.dashboard carrying the same values. A hand edit of one
// file was reverted or resurrected by the other.
func TestSaveKeepsRuntimeAndDashboardOverlayConsistentForLinkedSettings(t *testing.T) {
dir := t.TempDir()
origOverlay, origRuntime := DashboardOverlayFile, RuntimeConfigFile
DashboardOverlayFile = filepath.Join(dir, "hive.yaml.dashboard")
RuntimeConfigFile = filepath.Join(dir, "hive.yaml.runtime")
t.Cleanup(func() { DashboardOverlayFile, RuntimeConfigFile = origOverlay, origRuntime })
t.Setenv("KUBERNETES_SERVICE_HOST", "10.0.0.1")

on := true
cfg := &Config{
SourcePath: filepath.Join(dir, "hive.yaml"),
Project: ProjectConfig{Org: "testorg"},
AgentRuntimeConfig: AgentRuntimeConfig{
Agents: map[string]AgentConfig{"reviewer": {Role: "reviewer", Sandbox: &AgentSandboxOverride{
Enabled: &on, Image: "registry.example/sbx:1", Runtime: SandboxRuntimeJob,
Job: &SandboxJobConfig{WorkspaceClaim: "hive-data", EnvFromSecrets: []string{"gh-token"}},
}}},
AgentSandbox: AgentSandboxConfig{Image: "registry.example/default:1"},
},
}
cfg.Review.PerspectivesSource = &DefinitionSourceConfig{Owner: "acme", Repo: "rules", Path: ".hive/p.yaml", Ref: "main"}
if err := cfg.Save(); err != nil {
t.Fatalf("Save: %v", err)
}

for _, p := range []string{RuntimeConfigFile, DashboardOverlayFile} {
data, err := os.ReadFile(p)
if err != nil {
t.Fatalf("%s not written: %v", p, err)
}
for _, want := range []string{"perspectives_source:", "repo: rules", "registry.example/sbx:1", "registry.example/default:1", "gh-token", "workspace_claim: hive-data"} {
if !strings.Contains(string(data), want) {
t.Errorf("%s is missing %q", p, want)
}
}
}

// Clearing the source clears it from both files in the same save.
cfg.Review.PerspectivesSource = nil
if err := cfg.Save(); err != nil {
t.Fatalf("Save after unlink: %v", err)
}
for _, p := range []string{RuntimeConfigFile, DashboardOverlayFile} {
data, _ := os.ReadFile(p)
if strings.Contains(string(data), "perspectives_source") {
t.Errorf("%s still carries perspectives_source after an unlink", p)
}
}
}
12 changes: 11 additions & 1 deletion src/pkg/dashboard/agent_sandbox_warnings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const src = fs.readFileSync(path.join(__dirname, 'static-src', 'js', 'agent-card
const m = src.match(/function agentSandboxWarningsHtml\(a\) \{[\s\S]*?\n \}\n/);
assert.ok(m, 'agentSandboxWarningsHtml not found');
const esc = s => String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/"/g, '&quot;');
const agentSandboxWarningsHtml = new Function('esc', m[0] + '; return agentSandboxWarningsHtml;')(esc);
const fix = src.match(/const NO_SANDBOX_IMAGE_WARNING = [^\n]*\n function sandboxImageFixLinksHtml\(w, a\) \{[\s\S]*?\n \}\n/);
assert.ok(fix, 'sandboxImageFixLinksHtml not found');
const agentSandboxWarningsHtml = new Function('esc', fix[0] + m[0] + '; return agentSandboxWarningsHtml;')(esc);

test('renders one agent-error line per warning', () => {
const html = agentSandboxWarningsHtml({ sandbox_warnings: ['operator missing', 'no <gvisor>'] });
Expand All @@ -27,3 +29,11 @@ test('shipped index.html carries the card hook', () => {
const html = fs.readFileSync(path.join(__dirname, 'static', 'index.html'), 'utf8');
assert.ok(html.includes('${agentSandboxWarningsHtml(a)}'));
});

test('the no-sandbox-image warning links to the agent and the default controls (#18797)', () => {
const html = agentSandboxWarningsHtml({ name: 'reviewer', sandbox_warnings: ['no sandbox image: neither the agent\'s sandbox.image nor agent_sandbox.image is set'] });
assert.ok(html.includes('data-agent="reviewer"'));
assert.ok(html.includes('data-config-type="agent" data-tab="General"'));
assert.ok(html.includes('data-config-type="governor" data-tab="Security"'));
assert.ok(!agentSandboxWarningsHtml({ name: 'x', sandbox_warnings: ['operator missing'] }).includes('data-action'));
});
43 changes: 35 additions & 8 deletions src/pkg/dashboard/api_agent_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ func (s *Server) handleAgentConfigGet(w http.ResponseWriter, r *http.Request) {
// complete block, and which other agents a block can be copied from.
"sandboxDefaultsProblem": agentCfg.SandboxBlockProblem(s.deps.Config.AgentSandbox),
"sandboxCopySources": s.sandboxCopySources(name),
"sandboxFields": agentSandboxFieldsView(agentCfg, s.deps.Config.AgentSandbox),
"replicas": agentCfg.Replicas,
},
"cadences": cadences,
Expand Down Expand Up @@ -658,14 +659,40 @@ func (s *Server) handleAgentConfigGeneral(w http.ResponseWriter, r *http.Request
agentCfg.Aliases = a
}
}
if v, ok := body["sandboxEnabled"]; ok {
if b, ok := v.(bool); ok {
block, err := s.sandboxBlockForToggle(name, agentCfg, b, sandboxCopyFromBody(body))
if err != nil {
jsonError(w, err.Error(), http.StatusBadRequest)
return
}
agentCfg.Sandbox = block
// Sandbox block edits (#18525, #18797). Field edits land first unless a
// copy_from is named, so "enable + set the image" in one save sees the
// image; with a copy the copied block is written first and the edits go
// on top of it. A bare sandboxCopyFrom (no sandboxEnabled) copies and
// enables, the dialog's "Copy sandbox settings from" action.
copyFrom := sandboxCopyFromBody(body)
if copyFrom == "" {
if err := applySandboxEdits(&agentCfg, body); err != nil {
jsonError(w, err.Error(), http.StatusBadRequest)
return
}
}
enable, hasToggle := body["sandboxEnabled"].(bool)
if !hasToggle && copyFrom != "" {
enable, hasToggle = true, true
}
if hasToggle {
block, err := s.sandboxBlockForToggle(name, agentCfg, enable, copyFrom)
if err != nil {
jsonError(w, err.Error(), http.StatusBadRequest)
return
}
agentCfg.Sandbox = block
}
if copyFrom != "" {
if err := applySandboxEdits(&agentCfg, body); err != nil {
jsonError(w, err.Error(), http.StatusBadRequest)
return
}
}
if sandboxEditsPresent(body) {
if err := sandboxEnabledProblem(name, agentCfg, s.deps.Config.AgentSandbox); err != nil {
jsonError(w, err.Error(), http.StatusBadRequest)
return
}
}
if v, ok := body["sandboxSubstrate"]; ok {
Expand Down
Loading
Loading