The framework ships rhema-sandbox-ssh; the claw's sandbox seam now wires it as a third kind beside local and http. The ssh choice carries a host (any destination the local ssh config resolves) and a workspace base, default /root, with one directory per claw workspace under it so two sessions never share a root. The seed probe makes the root first and quotes it for the remote bash. The settings screen gains the SSH host card, and /v1/sandbox carries host and workspace. The rhema family moves to 0.4.1 in lockstep to pick the crate up.
331 lines
9.2 KiB
Vue
331 lines
9.2 KiB
Vue
<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 host = ref('')
|
|
const workspace = ref('')
|
|
|
|
const dirty = computed(() => {
|
|
const state = props.state
|
|
if (!state) return false
|
|
if (kind.value !== state.kind) return true
|
|
if (kind.value === 'http') {
|
|
const normalized = url.value.trim().replace(/\/+$/, '')
|
|
if (normalized !== (state.url ?? '')) return true
|
|
return token.value.trim() !== '' || clearToken.value
|
|
}
|
|
if (kind.value === 'ssh') {
|
|
if (host.value.trim() !== (state.host ?? '')) return true
|
|
if (workspace.value.trim() !== (state.ssh_workspace ?? '')) return true
|
|
}
|
|
return false
|
|
})
|
|
|
|
const urlValid = computed(() => /^https?:\/\/.+/.test(url.value.trim()))
|
|
|
|
const hostValid = computed(
|
|
() => host.value.trim() !== '' && !host.value.trim().includes(' '),
|
|
)
|
|
|
|
const ready = computed(() => {
|
|
if (kind.value === 'http') return urlValid.value
|
|
if (kind.value === 'ssh') return hostValid.value
|
|
return true
|
|
})
|
|
|
|
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.',
|
|
)
|
|
|
|
const hostHint = computed(() =>
|
|
host.value.trim() && !hostValid.value
|
|
? 'One destination, no spaces: an alias or user@host your ssh config resolves.'
|
|
: 'An alias or user@host your ssh config resolves.',
|
|
)
|
|
|
|
function sync(): void {
|
|
const state = props.state
|
|
if (!state) return
|
|
kind.value = state.kind
|
|
url.value = state.url ?? ''
|
|
token.value = ''
|
|
clearToken.value = false
|
|
host.value = state.host ?? ''
|
|
workspace.value = state.ssh_workspace ?? ''
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|
|
if (kind.value === 'ssh') {
|
|
choice.host = host.value.trim()
|
|
choice.workspace = workspace.value.trim()
|
|
}
|
|
emit('save', choice)
|
|
}
|
|
|
|
// The path the staged choice would use, not the saved one.
|
|
const workspacePath = computed(() => {
|
|
const state = props.state
|
|
if (!state) return ''
|
|
if (kind.value === 'local') return state.local_workspace
|
|
if (kind.value === 'http') return state.remote_workspace
|
|
return state.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>
|
|
|
|
<label class="option" :class="{ selected: kind === 'ssh' }">
|
|
<input v-model="kind" type="radio" value="ssh" :disabled="saving" />
|
|
<span class="option-text">
|
|
<span class="option-title">
|
|
SSH host
|
|
<span v-if="state.kind === 'ssh'" class="current">current</span>
|
|
</span>
|
|
<span class="option-detail">
|
|
Commands run on a box the claw reaches with ssh, nothing installed on the far end.
|
|
</span>
|
|
</span>
|
|
</label>
|
|
</SettingCard>
|
|
|
|
<SettingCard v-if="kind === 'ssh'" title="SSH host">
|
|
<SettingRow title="Destination" :description="hostHint">
|
|
<input
|
|
v-model="host"
|
|
type="text"
|
|
class="mono"
|
|
placeholder="me@box.example"
|
|
autocomplete="off"
|
|
spellcheck="false"
|
|
:disabled="saving"
|
|
/>
|
|
</SettingRow>
|
|
<SettingRow
|
|
title="Workspace base"
|
|
description="The remote directory the claw's workspaces live under. Defaults to /root."
|
|
>
|
|
<input
|
|
v-model="workspace"
|
|
type="text"
|
|
class="mono"
|
|
placeholder="/root"
|
|
autocomplete="off"
|
|
spellcheck="false"
|
|
:disabled="saving"
|
|
/>
|
|
</SettingRow>
|
|
</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 !== 'local'" 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>
|