forked from vhaudiquet/rhema-claw
feat(claw): choose where bash runs, this host or a remote sandbox
The daemon's `bash` always ran on its own host. A deployment that wants the shell isolated, or on a machine with the project's toolchain, had no way to say so, and the web settings had no surface for it. A sandbox choice now persists in the settings table, and the daemon can be seeded from `sandbox` in claw.yaml. `local` keeps the existing shell; `http` wraps `rhema-sandbox-http` in a `ShellSandbox` and gives every handler a `ShellTools` built over it. Chat turns, forge turns, and coding jobs all read the choice per dispatch, so a switch applies on the next turn without a restart. A remote sandbox starts empty. The first command for a workspace probes `/workspace` and, when it is empty, sends the host workspace as a tarball through the protocol's seed route. Later edits stay in the sandbox; the claw does not copy them back. The web settings gain a System > Sandbox page: the two kinds, the URL and a write-only token, a forget-token action, and the effective workspace. `GET /v1/sandbox` never returns the token; `PUT` validates and persists the choice. Tests: the sandbox state and config validation, the HTTP route round trip, and a remote turn that seeds a fresh sandbox and runs its shell there. fmt, clippy with -D warnings, the workspace tests, and the web typecheck and build pass.
This commit is contained in:
1 parent
5dc8402107
commit
1aa8d5578e
20 files changed
+1502
-23
No files matched your search
+43
-1
@@ -17,6 +17,8 @@ import type {
|
||||
NewAccount,
|
||||
ProviderCredentials,
|
||||
ProvidersState,
|
||||
SandboxSelection,
|
||||
SandboxState,
|
||||
StreamStatus,
|
||||
} from '~/composables/useClaw'
|
||||
import { useTranscript } from '~/composables/useTranscript'
|
||||
@@ -58,7 +60,13 @@ const SETTINGS_SECTIONS: { label: string; entries: { id: string; label: string }
|
||||
],
|
||||
},
|
||||
{ label: 'Providers', entries: [{ id: 'providers', label: 'Model providers' }] },
|
||||
{ label: 'System', entries: [{ id: 'about', label: 'About' }] },
|
||||
{
|
||||
label: 'System',
|
||||
entries: [
|
||||
{ id: 'sandbox', label: 'Sandbox' },
|
||||
{ id: 'about', label: 'About' },
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
function parseHash(): Route {
|
||||
@@ -265,6 +273,8 @@ const mutatingIdentity = ref(false)
|
||||
const accounts = ref<ClawAccount[] | null>(null)
|
||||
const accountsLoading = ref(false)
|
||||
const mutatingAccounts = ref(false)
|
||||
const sandboxState = ref<SandboxState | null>(null)
|
||||
const savingSandbox = ref(false)
|
||||
const streamStatus = ref<StreamStatus>('connecting')
|
||||
const busy = ref(false)
|
||||
const authRequired = ref(false)
|
||||
@@ -499,6 +509,30 @@ async function removeProvider(id: string): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshSandbox(): Promise<void> {
|
||||
try {
|
||||
sandboxState.value = await claw.sandbox()
|
||||
apiError.value = null
|
||||
} catch (err) {
|
||||
noteApiError(err)
|
||||
}
|
||||
}
|
||||
|
||||
async function saveSandbox(choice: SandboxSelection): Promise<void> {
|
||||
savingSandbox.value = true
|
||||
try {
|
||||
sandboxState.value = await claw.setSandbox(choice)
|
||||
pushNotice(
|
||||
choice.kind === 'http' ? 'sandbox: remote host' : 'sandbox: this machine',
|
||||
)
|
||||
apiError.value = null
|
||||
} catch (err) {
|
||||
noteApiError(err)
|
||||
} finally {
|
||||
savingSandbox.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function send(message: { text: string; images: StagedImage[] }): Promise<void> {
|
||||
// The optimistic row renders the staged previews; the stream's
|
||||
// user_message echo carries the stored ids and dedupes against it.
|
||||
@@ -581,6 +615,7 @@ function saveToken(): void {
|
||||
void refreshSessions()
|
||||
void refreshIdentity()
|
||||
void refreshAccounts()
|
||||
void refreshSandbox()
|
||||
}
|
||||
|
||||
// --- the one live subscription ---------------------------------------
|
||||
@@ -657,6 +692,7 @@ onMounted(() => {
|
||||
void refreshIdentity()
|
||||
void refreshProviders()
|
||||
void refreshAccounts()
|
||||
void refreshSandbox()
|
||||
void refreshSessions()
|
||||
healthTimer = setInterval(checkHealth, 30000)
|
||||
sessionsTimer = setInterval(() => void refreshSessions(), 20000)
|
||||
@@ -789,6 +825,12 @@ onUnmounted(() => {
|
||||
@add="addProvider"
|
||||
@remove="removeProvider"
|
||||
/>
|
||||
<SettingsSandboxPage
|
||||
v-show="route.section === 'sandbox'"
|
||||
:state="sandboxState"
|
||||
:saving="savingSandbox"
|
||||
@save="saveSandbox"
|
||||
/>
|
||||
<SettingsAboutPage v-show="route.section === 'about'" :claw-up="clawUp" />
|
||||
</template>
|
||||
</main>
|
||||
|
||||
@@ -0,0 +1,259 @@
|
||||
<script setup lang="ts">
|
||||
// The Sandbox page: where the agent's `bash` runs. The choice saves as
|
||||
// a whole; the token is write-only, so an empty field keeps whatever
|
||||
// the claw already stored. Presentational: data flows in as props,
|
||||
// intent flows up as events.
|
||||
import type { SandboxKind, SandboxSelection, SandboxState } from '~/composables/useClaw'
|
||||
|
||||
const props = defineProps<{
|
||||
state: SandboxState | null
|
||||
saving: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
save: [choice: SandboxSelection]
|
||||
}>()
|
||||
|
||||
const kind = ref<SandboxKind>('local')
|
||||
const url = ref('')
|
||||
const token = ref('')
|
||||
const clearToken = ref(false)
|
||||
|
||||
const dirty = computed(() => {
|
||||
const state = props.state
|
||||
if (!state) return false
|
||||
if (kind.value !== state.kind) return true
|
||||
if (kind.value !== 'http') return false
|
||||
const normalized = url.value.trim().replace(/\/+$/, '')
|
||||
if (normalized !== (state.url ?? '')) return true
|
||||
return token.value.trim() !== '' || clearToken.value
|
||||
})
|
||||
|
||||
const urlValid = computed(() => /^https?:\/\/.+/.test(url.value.trim()))
|
||||
|
||||
const ready = computed(() => kind.value !== 'http' || urlValid.value)
|
||||
|
||||
const urlHint = computed(() =>
|
||||
url.value.trim() && !urlValid.value
|
||||
? 'The URL must start with http:// or https://.'
|
||||
: 'The sandboxd base URL, for example https://box.example:7600.',
|
||||
)
|
||||
|
||||
function sync(): void {
|
||||
const state = props.state
|
||||
if (!state) return
|
||||
kind.value = state.kind
|
||||
url.value = state.url ?? ''
|
||||
token.value = ''
|
||||
clearToken.value = false
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.state,
|
||||
(state) => {
|
||||
if (state) sync()
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
function discard(): void {
|
||||
sync()
|
||||
}
|
||||
|
||||
function save(): void {
|
||||
if (!dirty.value || props.saving || !ready.value) return
|
||||
const choice: SandboxSelection = { kind: kind.value }
|
||||
if (kind.value === 'http') {
|
||||
choice.url = url.value.trim()
|
||||
if (token.value.trim() !== '') {
|
||||
choice.token = token.value.trim()
|
||||
} else if (clearToken.value) {
|
||||
choice.clear_token = true
|
||||
}
|
||||
}
|
||||
emit('save', choice)
|
||||
}
|
||||
|
||||
// The path the staged choice would use, not the saved one.
|
||||
const workspacePath = computed(() => {
|
||||
const state = props.state
|
||||
if (!state) return ''
|
||||
return kind.value === 'http' ? state.remote_workspace : state.local_workspace
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="page">
|
||||
<PageHeader title="Sandbox" subtitle="Where the agent's bash runs.">
|
||||
<template #actions>
|
||||
<button :disabled="!dirty || saving" @click="discard">Discard</button>
|
||||
<button class="primary" :disabled="!dirty || saving || !ready" @click="save">
|
||||
{{ saving ? 'Saving…' : 'Save' }}
|
||||
</button>
|
||||
</template>
|
||||
</PageHeader>
|
||||
|
||||
<div class="scroll">
|
||||
<p v-if="!state" class="muted">loading sandbox…</p>
|
||||
|
||||
<template v-else>
|
||||
<SettingCard title="Execution" meta="applies on the next turn">
|
||||
<label class="option" :class="{ selected: kind === 'local' }">
|
||||
<input v-model="kind" type="radio" value="local" :disabled="saving" />
|
||||
<span class="option-text">
|
||||
<span class="option-title">
|
||||
This machine
|
||||
<span v-if="state.kind === 'local'" class="current">current</span>
|
||||
</span>
|
||||
<span class="option-detail">
|
||||
Commands run as processes on the daemon's host.
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<label class="option" :class="{ selected: kind === 'http' }">
|
||||
<input v-model="kind" type="radio" value="http" :disabled="saving" />
|
||||
<span class="option-text">
|
||||
<span class="option-title">
|
||||
Remote sandbox
|
||||
<span v-if="state.kind === 'http'" class="current">current</span>
|
||||
</span>
|
||||
<span class="option-detail">
|
||||
Commands run on a host that speaks the sandbox protocol over HTTP.
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
</SettingCard>
|
||||
|
||||
<SettingCard v-if="kind === 'http'" title="Remote sandbox">
|
||||
<SettingRow
|
||||
title="URL"
|
||||
:description="urlHint"
|
||||
>
|
||||
<input
|
||||
v-model="url"
|
||||
type="text"
|
||||
class="mono"
|
||||
placeholder="https://box.example:7600"
|
||||
autocomplete="off"
|
||||
spellcheck="false"
|
||||
:disabled="saving"
|
||||
/>
|
||||
</SettingRow>
|
||||
<SettingRow
|
||||
title="Token"
|
||||
:description="state.token_set
|
||||
? 'A token is stored. Leave this blank to keep it.'
|
||||
: 'The shared secret the daemon checks. Leave it blank when the daemon has none.'"
|
||||
>
|
||||
<input
|
||||
v-model="token"
|
||||
type="password"
|
||||
:placeholder="state.token_set ? 'stored' : 'optional'"
|
||||
autocomplete="off"
|
||||
:disabled="saving || clearToken"
|
||||
/>
|
||||
</SettingRow>
|
||||
<SettingRow
|
||||
v-if="state.token_set"
|
||||
title="Stored token"
|
||||
:description="clearToken
|
||||
? 'The stored token is removed when you save.'
|
||||
: 'The token stays in the settings table until you replace or forget it.'"
|
||||
>
|
||||
<button class="ghost" :disabled="saving" @click="clearToken = !clearToken">
|
||||
{{ clearToken ? 'Keep token' : 'Forget token' }}
|
||||
</button>
|
||||
</SettingRow>
|
||||
</SettingCard>
|
||||
|
||||
<AppCallout v-if="kind === 'http'" variant="info" title="Remote commands start from a copy">
|
||||
On first use the claw sends the local workspace to the sandbox as a tarball.
|
||||
Later edits stay in the sandbox; the claw does not copy them back.
|
||||
</AppCallout>
|
||||
|
||||
<SettingCard title="Workspace">
|
||||
<SettingRow
|
||||
title="Path"
|
||||
description="Where the agent's bash starts under this choice."
|
||||
>
|
||||
<code>{{ workspacePath }}</code>
|
||||
</SettingRow>
|
||||
</SettingCard>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.scroll {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 0 24px 24px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
max-width: 860px;
|
||||
}
|
||||
|
||||
.muted {
|
||||
color: var(--text3);
|
||||
padding: 8px 2px;
|
||||
}
|
||||
|
||||
.option {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 12px;
|
||||
padding: 13px 16px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.option:hover {
|
||||
background: var(--elevated);
|
||||
}
|
||||
|
||||
.option.selected {
|
||||
background: color-mix(in srgb, var(--accent) 8%, var(--surface));
|
||||
}
|
||||
|
||||
.option input[type='radio'] {
|
||||
flex: none;
|
||||
margin: 3px 0 0;
|
||||
accent-color: var(--accent);
|
||||
}
|
||||
|
||||
.option-text {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.option-title {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 8px;
|
||||
color: var(--text);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.option-detail {
|
||||
color: var(--text3);
|
||||
font-size: 12.5px;
|
||||
}
|
||||
|
||||
.current {
|
||||
color: var(--accent-text);
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
}
|
||||
</style>
|
||||
@@ -220,6 +220,34 @@ export interface ActiveBackend {
|
||||
active: { provider: string; model: string }
|
||||
}
|
||||
|
||||
/** Where the agent's `bash` runs: this host or a daemon speaking the
|
||||
* sandbox protocol over HTTP. */
|
||||
export type SandboxKind = 'local' | 'http'
|
||||
|
||||
/** The sandbox state `GET /v1/sandbox` serves. The token never rides
|
||||
* the wire; `token_set` says whether one is stored. */
|
||||
export interface SandboxState {
|
||||
kind: SandboxKind
|
||||
url: string | null
|
||||
token_set: boolean
|
||||
/** Where `bash` starts under the current choice. */
|
||||
workspace: string
|
||||
/** The daemon's chat workspace, whatever the choice. */
|
||||
local_workspace: string
|
||||
/** The path a remote sandbox exposes. */
|
||||
remote_workspace: string
|
||||
}
|
||||
|
||||
/** The body `PUT /v1/sandbox` takes. `token` is write-only, and
|
||||
* `clear_token` drops the stored one. An omitted `url` keeps the
|
||||
* current one. */
|
||||
export interface SandboxSelection {
|
||||
kind: SandboxKind
|
||||
url?: string
|
||||
token?: string
|
||||
clear_token?: boolean
|
||||
}
|
||||
|
||||
/** A failed API call: the status plus the claw's `error` string when it sent one. */
|
||||
export class ClawError extends Error {
|
||||
/** HTTP status; 0 when the claw was unreachable at all. */
|
||||
@@ -383,6 +411,11 @@ export interface ClawApi {
|
||||
/** `DELETE /v1/providers/{id}` — remove a backend instance; answers
|
||||
* the new providers state. The last backend is refused claw-side. */
|
||||
removeProvider(id: string): Promise<ProvidersState>
|
||||
/** `GET /v1/sandbox`: where the agent's `bash` runs. */
|
||||
sandbox(): Promise<SandboxState>
|
||||
/** `PUT /v1/sandbox`: switch the sandbox, persisted claw-side. The
|
||||
* choice applies on the next turn. */
|
||||
setSandbox(choice: SandboxSelection): Promise<SandboxState>
|
||||
/** `GET /v1/accounts` — the stored accounts, redacted. */
|
||||
accounts(): Promise<ClawAccount[]>
|
||||
/** `POST /v1/accounts` — store an account (the secret is write-only),
|
||||
@@ -563,6 +596,18 @@ export function useClaw(token: Ref<string | null>): ClawApi {
|
||||
})) as ProvidersState
|
||||
}
|
||||
|
||||
async function sandbox(): Promise<SandboxState> {
|
||||
return (await get('/v1/sandbox', token.value)) as SandboxState
|
||||
}
|
||||
|
||||
async function setSandbox(choice: SandboxSelection): Promise<SandboxState> {
|
||||
return (await send('/v1/sandbox', {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json', ...authHeaders(token.value) },
|
||||
body: JSON.stringify(choice),
|
||||
})) as SandboxState
|
||||
}
|
||||
|
||||
async function accounts(): Promise<ClawAccount[]> {
|
||||
const body = (await get('/v1/accounts', token.value)) as { accounts: ClawAccount[] }
|
||||
return body.accounts
|
||||
@@ -757,6 +802,8 @@ export function useClaw(token: Ref<string | null>): ClawApi {
|
||||
models,
|
||||
setCredentials,
|
||||
removeProvider,
|
||||
sandbox,
|
||||
setSandbox,
|
||||
accounts,
|
||||
addAccount,
|
||||
removeAccount,
|
||||
|
||||
Reference in new issue
Block a user