feat: add managed SSH execution spaces

Add managed SSH Hosts and projects with signed side-by-side GoodBuddy Agent and OpenCode Runtime installation, Ask and Execute workspace access, a Main-owned model bridge, detached Agent lifecycle, durable ACP output recovery, and project activation UI.

Use protocol v2 with bounded FIFO frames over SSH instead of custom credit, priority, batching, or model-message chunking. Mismatched Host Agents now upgrade automatically, an exactly verified Node runtime is reused on-host, and local Portable builds can embed strictly verified Agent artifacts.

Release note: 新增托管 SSH 远程项目,可自动安装或升级签名 Agent/OpenCode Runtime,并在 SSH 断线后继续 Agent 工作和同步未确认输出。
This commit is contained in:
mesalogo
2026-08-24 23:02:18 +08:00
parent 3829a871f5
commit 607bb33249
258 changed files with 99449 additions and 2427 deletions
+113
View File
@@ -0,0 +1,113 @@
import {
createHmac,
randomBytes,
timingSafeEqual
} from 'node:crypto'
const CHALLENGE_DOMAIN = 'goodbuddy-agent-installation-challenge-v1\0'
export type InstallationChallenge = {
serverNonce: string
expiresAt: number
}
export class InstallationChallengeVerifier {
readonly #secret: Buffer
readonly #now: () => number
readonly #lifetimeMs: number
readonly #pending = new Map<string, number>()
constructor(
secret: Uint8Array,
options: { now?: () => number; lifetimeMs?: number } = {}
) {
if (secret.byteLength < 32) {
throw new RangeError('Installation challenge secret is too short')
}
this.#secret = Buffer.from(secret)
this.#now = options.now ?? Date.now
this.#lifetimeMs = options.lifetimeMs ?? 30_000
if (!Number.isSafeInteger(this.#lifetimeMs) || this.#lifetimeMs < 1) {
throw new RangeError('Invalid installation challenge lifetime')
}
}
issue(): InstallationChallenge {
this.#purgeExpired()
const serverNonce = randomBytes(32).toString('base64url')
const expiresAt = this.#now() + this.#lifetimeMs
this.#pending.set(serverNonce, expiresAt)
return { serverNonce, expiresAt }
}
createResponse(input: {
serverNonce: string
clientNonce: string
controllerId: string
}): string {
return calculateResponse(this.#secret, input)
}
verify(input: {
serverNonce: string
clientNonce: string
controllerId: string
response: string
}): boolean {
const expiresAt = this.#pending.get(input.serverNonce)
this.#pending.delete(input.serverNonce)
if (expiresAt === undefined || expiresAt < this.#now()) {
return false
}
const expected = Buffer.from(
calculateResponse(this.#secret, input),
'base64url'
)
let received: Buffer
try {
received = Buffer.from(input.response, 'base64url')
} catch {
return false
}
return (
expected.byteLength === received.byteLength &&
timingSafeEqual(expected, received)
)
}
#purgeExpired(): void {
const now = this.#now()
for (const [nonce, expiresAt] of this.#pending) {
if (expiresAt < now) {
this.#pending.delete(nonce)
}
}
}
}
function calculateResponse(
secret: Uint8Array,
input: {
serverNonce: string
clientNonce: string
controllerId: string
}
): string {
for (const value of [
input.serverNonce,
input.clientNonce,
input.controllerId
]) {
if (!/^[A-Za-z0-9._:-]{1,128}$/u.test(value)) {
throw new Error('Invalid installation challenge field')
}
}
return createHmac('sha256', secret)
.update(CHALLENGE_DOMAIN)
.update(input.serverNonce)
.update('\0')
.update(input.clientNonce)
.update('\0')
.update(input.controllerId)
.digest('base64url')
}