The ssh sandbox took its credential from a key file the local disk had to hold, so a daemon whose secrets live in a store could not reach a far box without staging a file first. The choice gains private_key, the key text itself, threaded to the ssh backend's with_private_key; unset, the built-in hunt tries the agent and the default key files as before. The route keeps the token's write-only contract: GET /v1/sandbox answers private_key_set and never the key, PUT takes private_key and clear_private_key, an absent field keeps the stored one, a present-but-blank one clears it, and config.yaml's sandbox section accepts the field for boot seeding. The settings page grows the key textarea with its forget row, the token UI's shape. The three sandbox deps move to 0.4.2 for the seam, so the crate builds once the rhema 0.4.2 release lands on crates.io; until then the Rust gates cannot run and were checked by hand (cargo fmt parses the tree, vue-tsc passes).
376 lines
11 KiB
Vue
376 lines
11 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 privateKey = ref('')
|
|
const clearPrivateKey = ref(false)
|
|
|
|
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 privateKey.value.trim() !== '' || clearPrivateKey.value
|
|
}
|
|
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 ?? ''
|
|
privateKey.value = ''
|
|
clearPrivateKey.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
|
|
}
|
|
}
|
|
if (kind.value === 'ssh') {
|
|
choice.host = host.value.trim()
|
|
choice.workspace = workspace.value.trim()
|
|
if (privateKey.value.trim() !== '') {
|
|
choice.private_key = privateKey.value
|
|
} else if (clearPrivateKey.value) {
|
|
choice.clear_private_key = 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 ''
|
|
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>
|
|
<SettingRow
|
|
title="Private key"
|
|
:description="state.private_key_set
|
|
? 'A key is stored. Leave this blank to keep it, or paste a replacement.'
|
|
: 'The key text itself (OpenSSH or PEM), not a path: the claw stores it, it stages no file. Leave blank to authenticate through an agent or the default key files.'"
|
|
>
|
|
<textarea
|
|
v-model="privateKey"
|
|
class="mono key-input"
|
|
rows="3"
|
|
:placeholder="state.private_key_set ? 'stored' : '-----BEGIN OPENSSH PRIVATE KEY-----'"
|
|
autocomplete="off"
|
|
spellcheck="false"
|
|
:disabled="saving || clearPrivateKey"
|
|
/>
|
|
</SettingRow>
|
|
<SettingRow
|
|
v-if="state.private_key_set"
|
|
title="Stored key"
|
|
:description="clearPrivateKey
|
|
? 'The stored key is removed when you save.'
|
|
: 'The key stays in the settings table until you replace or forget it.'"
|
|
>
|
|
<button class="ghost" :disabled="saving" @click="clearPrivateKey = !clearPrivateKey">
|
|
{{ clearPrivateKey ? 'Keep key' : 'Forget key' }}
|
|
</button>
|
|
</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;
|
|
}
|
|
|
|
.key-input {
|
|
width: 100%;
|
|
min-width: 0;
|
|
resize: vertical;
|
|
font-size: 12px;
|
|
word-break: break-all;
|
|
}
|
|
</style>
|