feat: add independent managed SSH agent packages
Managed SSH previously tied remote Agent and Runtime artifacts to desktop packaging and Host activation. Settings now manages verified Linux x64 and arm64 .gbagent packages explicitly, with source-aligned download and update plus offline import and export. Each package contains the signed Agent, pinned Node, and compatible OpenCode Runtime, and project activation never downloads one automatically. Dedicated native CI and a protected release workflow publish deterministic, signed cumulative catalogs to GitHub and Beijing OSS without replacing the desktop Latest release. Desktop packaging is metadata-only, remains independent of Agent artifacts and signing credentials, and Linux desktop releases add RPM installers. The managed SSH path also keeps model credentials in Main, enforces Ask as read-only, verifies signed Agent and Runtime inputs, preserves ACP recovery, and reports Host update cancellation and failures accurately. Release note: 远程项目现可在“设置”中手动下载、更新或离线导入签名 Agent 包,桌面安装包与远程组件发布相互独立;Linux 桌面版同时新增 RPM 安装包。
This commit is contained in:
@@ -34,7 +34,7 @@ export class InstallationChallengeVerifier {
|
||||
|
||||
issue(): InstallationChallenge {
|
||||
this.#purgeExpired()
|
||||
const serverNonce = randomBytes(32).toString('base64url')
|
||||
const serverNonce = randomBytes(32).toString('hex')
|
||||
const expiresAt = this.#now() + this.#lifetimeMs
|
||||
this.#pending.set(serverNonce, expiresAt)
|
||||
return { serverNonce, expiresAt }
|
||||
|
||||
@@ -60,6 +60,7 @@ describe('managed daemon lifecycle', () => {
|
||||
lifetimeMs: 100
|
||||
})
|
||||
const challenge = verifier.issue()
|
||||
expect(challenge.serverNonce).toMatch(/^[a-f0-9]{64}$/u)
|
||||
const response = verifier.createResponse({
|
||||
serverNonce: challenge.serverNonce,
|
||||
clientNonce: 'client-1',
|
||||
|
||||
@@ -584,12 +584,22 @@ async function readExactly(
|
||||
let remaining = byteLength
|
||||
while (remaining > 0) {
|
||||
signal.throwIfAborted()
|
||||
const chunk = socket.read(remaining) as Buffer | null
|
||||
if (chunk !== null) {
|
||||
const readableBytes = Math.min(
|
||||
remaining,
|
||||
socket.readableLength
|
||||
)
|
||||
if (readableBytes > 0) {
|
||||
const chunk = socket.read(readableBytes) as Buffer | null
|
||||
if (chunk === null || chunk.byteLength !== readableBytes) {
|
||||
throw new ModelBridgeBrokerError('transport-failed')
|
||||
}
|
||||
chunks.push(chunk)
|
||||
remaining -= chunk.byteLength
|
||||
continue
|
||||
}
|
||||
if (socket.readableEnded || socket.destroyed) {
|
||||
throw new ModelBridgeBrokerError('transport-failed')
|
||||
}
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const onReadable = (): void => {
|
||||
cleanup()
|
||||
@@ -619,6 +629,17 @@ async function readExactly(
|
||||
socket.once('end', onClose)
|
||||
socket.once('error', onError)
|
||||
signal.addEventListener('abort', onAbort, { once: true })
|
||||
if (signal.aborted) {
|
||||
onAbort()
|
||||
return
|
||||
}
|
||||
if (socket.readableLength > 0) {
|
||||
onReadable()
|
||||
return
|
||||
}
|
||||
if (socket.readableEnded || socket.destroyed) {
|
||||
onClose()
|
||||
}
|
||||
})
|
||||
}
|
||||
return Buffer.concat(chunks, byteLength)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { randomUUID } from 'node:crypto'
|
||||
import { randomBytes, randomUUID } from 'node:crypto'
|
||||
import { spawn as nodeSpawn } from 'node:child_process'
|
||||
import {
|
||||
createServer,
|
||||
@@ -37,12 +37,18 @@ export type ModelBridgeProtocol = ModelBridgeModelProtocol
|
||||
// The Anthropic and OpenAI SDK adapters refuse to issue a request without an
|
||||
// apiKey option. This fixed value is only a local compatibility marker. The
|
||||
// loopback proxy verifies and removes its header before creating the wire
|
||||
// request, so it is neither a credential nor visible outside the sandbox.
|
||||
// request. A separate per-helper random route capability authenticates local
|
||||
// requests, so this marker is neither a credential nor visible upstream.
|
||||
export const MODEL_BRIDGE_SDK_AUTH_SENTINEL =
|
||||
'goodbuddy-local-model-bridge-v1'
|
||||
|
||||
export type OpenCodeModelBridgeProviderConfig = {
|
||||
model: string
|
||||
agent: {
|
||||
title: {
|
||||
disable: true
|
||||
}
|
||||
}
|
||||
provider: Record<
|
||||
string,
|
||||
{
|
||||
@@ -100,6 +106,7 @@ const DEFAULT_REQUEST_TIMEOUT_MS = 180_000
|
||||
const RESPONSE_CLOSE_TIMEOUT_MS = 2_000
|
||||
const MAXIMUM_HTTP_HEADER_BYTES = 16 * 1024
|
||||
const MAXIMUM_HTTP_HEADER_COUNT = 32
|
||||
const MODEL_BRIDGE_ROUTE_TOKEN_PATTERN = /^[A-Za-z0-9_-]{43}$/u
|
||||
const CREDENTIAL_INBOUND_HEADER_NAMES = new Set([
|
||||
'api-key',
|
||||
'authorization',
|
||||
@@ -116,6 +123,7 @@ const FORWARDED_HEADER_NAMES = [
|
||||
|
||||
export class ModelBridgeLoopbackProxy {
|
||||
readonly #exchange: ModelBridgeExchange
|
||||
readonly #routeToken: string
|
||||
readonly #maximumConnections: number
|
||||
readonly #requestTimeoutMs: number
|
||||
readonly #sockets = new Set<Socket>()
|
||||
@@ -128,10 +136,15 @@ export class ModelBridgeLoopbackProxy {
|
||||
|
||||
constructor(options: {
|
||||
exchange: ModelBridgeExchange
|
||||
routeToken?: string
|
||||
maximumConnections?: number
|
||||
requestTimeoutMs?: number
|
||||
}) {
|
||||
this.#exchange = options.exchange
|
||||
this.#routeToken = parseModelBridgeRouteToken(
|
||||
options.routeToken ??
|
||||
randomBytes(32).toString('base64url')
|
||||
)
|
||||
this.#maximumConnections = boundedInteger(
|
||||
options.maximumConnections ?? DEFAULT_MAXIMUM_CONNECTIONS,
|
||||
1,
|
||||
@@ -195,7 +208,8 @@ export class ModelBridgeLoopbackProxy {
|
||||
'Model bridge loopback address is unavailable'
|
||||
)
|
||||
}
|
||||
this.#origin = `http://${LOOPBACK_HOST}:${address.port}`
|
||||
this.#origin =
|
||||
`http://${LOOPBACK_HOST}:${address.port}/${this.#routeToken}`
|
||||
return this.#origin
|
||||
} catch (error) {
|
||||
await this.close()
|
||||
@@ -280,7 +294,10 @@ export class ModelBridgeLoopbackProxy {
|
||||
timeout.unref?.()
|
||||
|
||||
try {
|
||||
const request = await parseHttpRequest(incoming)
|
||||
const request = await parseHttpRequest(
|
||||
incoming,
|
||||
this.#routeToken
|
||||
)
|
||||
await this.#acquireDispatch(cancellation.signal)
|
||||
dispatchHeld = true
|
||||
dispatched = normalizeExchangeResult(
|
||||
@@ -483,6 +500,14 @@ export function createOpenCodeModelBridgeProviderConfig(input: {
|
||||
const baseURL = `${origin}/v1`
|
||||
return {
|
||||
model: `${providerId}/${model}`,
|
||||
// GoodBuddy owns conversation titles. A first-prompt title request can
|
||||
// race the real ACP prompt, abandon its Provider response, and correctly
|
||||
// poison the no-replay ledger before the user request can run.
|
||||
agent: {
|
||||
title: {
|
||||
disable: true
|
||||
}
|
||||
},
|
||||
provider: {
|
||||
[providerId]: {
|
||||
name,
|
||||
@@ -513,12 +538,15 @@ export function createOpenCodeModelBridgeProviderConfig(input: {
|
||||
}
|
||||
|
||||
async function parseHttpRequest(
|
||||
incoming: IncomingMessage
|
||||
incoming: IncomingMessage,
|
||||
routeToken: string
|
||||
): Promise<RemoteModelGatewayRequest> {
|
||||
if (incoming.method !== 'POST') {
|
||||
throw new HttpRequestError(405, 'method-not-allowed')
|
||||
}
|
||||
const path = remoteModelApiPathSchema.safeParse(incoming.url)
|
||||
const path = remoteModelApiPathSchema.safeParse(
|
||||
authenticatedApiPath(incoming.url, routeToken)
|
||||
)
|
||||
if (!path.success) {
|
||||
throw new HttpRequestError(404, 'path-not-allowed')
|
||||
}
|
||||
@@ -838,14 +866,35 @@ function parseLoopbackOrigin(input: string): string {
|
||||
url.hostname !== LOOPBACK_HOST ||
|
||||
url.username ||
|
||||
url.password ||
|
||||
url.pathname !== '/' ||
|
||||
!MODEL_BRIDGE_ROUTE_TOKEN_PATTERN.test(
|
||||
url.pathname.slice(1)
|
||||
) ||
|
||||
url.search ||
|
||||
url.hash ||
|
||||
url.port === ''
|
||||
) {
|
||||
throw new Error('Model bridge origin must be loopback HTTP')
|
||||
throw new Error(
|
||||
'Model bridge origin must be authenticated loopback HTTP'
|
||||
)
|
||||
}
|
||||
return url.origin
|
||||
return `${url.origin}${url.pathname}`
|
||||
}
|
||||
|
||||
function parseModelBridgeRouteToken(value: string): string {
|
||||
if (!MODEL_BRIDGE_ROUTE_TOKEN_PATTERN.test(value)) {
|
||||
throw new Error('Model bridge route capability is invalid')
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
function authenticatedApiPath(
|
||||
input: string | undefined,
|
||||
routeToken: string
|
||||
): string | undefined {
|
||||
const prefix = `/${routeToken}`
|
||||
return input?.startsWith(`${prefix}/`)
|
||||
? input.slice(prefix.length)
|
||||
: undefined
|
||||
}
|
||||
|
||||
function boundedMetadataText(
|
||||
|
||||
@@ -31,6 +31,7 @@ import {
|
||||
} from './model-bridge-broker'
|
||||
|
||||
const temporaryPaths: string[] = []
|
||||
const modelBridgeRouteToken = 'A'.repeat(43)
|
||||
const validResponse: RemoteModelGatewayResponse = {
|
||||
status: 201,
|
||||
headers: {
|
||||
@@ -208,6 +209,27 @@ describe('model bridge loopback helper', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('rejects loopback requests without the per-helper route capability', async () => {
|
||||
const exchange = vi.fn(async () => validResponse)
|
||||
const proxy = new ModelBridgeLoopbackProxy({ exchange })
|
||||
const origin = await proxy.listen()
|
||||
try {
|
||||
const response = await sendHttp(origin, {
|
||||
authenticated: false,
|
||||
path: '/v1/messages',
|
||||
headers: {
|
||||
'x-api-key': MODEL_BRIDGE_SDK_AUTH_SENTINEL
|
||||
},
|
||||
body: '{}'
|
||||
})
|
||||
|
||||
expect(response.status).toBe(404)
|
||||
expect(exchange).not.toHaveBeenCalled()
|
||||
} finally {
|
||||
await proxy.close()
|
||||
}
|
||||
})
|
||||
|
||||
it('drops harmless SDK metadata headers but rejects chunked framing', async () => {
|
||||
const exchange = vi.fn<ModelBridgeExchange>(
|
||||
async () => validResponse
|
||||
@@ -430,17 +452,24 @@ describe('model bridge loopback helper', () => {
|
||||
protocol,
|
||||
model: 'private-model',
|
||||
name: 'Private model',
|
||||
loopbackOrigin: 'http://127.0.0.1:12345',
|
||||
loopbackOrigin:
|
||||
`http://127.0.0.1:12345/${modelBridgeRouteToken}`,
|
||||
supportsImageInput: true
|
||||
})
|
||||
|
||||
expect(config).toMatchObject({
|
||||
model: `${providerId}/private-model`,
|
||||
agent: {
|
||||
title: {
|
||||
disable: true
|
||||
}
|
||||
},
|
||||
provider: {
|
||||
[providerId]: {
|
||||
npm,
|
||||
options: {
|
||||
baseURL: 'http://127.0.0.1:12345/v1'
|
||||
baseURL:
|
||||
`http://127.0.0.1:12345/${modelBridgeRouteToken}/v1`
|
||||
},
|
||||
models: {
|
||||
'private-model': {
|
||||
@@ -525,6 +554,52 @@ describe('model bridge Unix broker', () => {
|
||||
}
|
||||
)
|
||||
|
||||
runOnUnix(
|
||||
'drains a response larger than the Unix socket receive buffer',
|
||||
async () => {
|
||||
const scratch = privateTemporaryDirectory()
|
||||
const responseBody = Buffer.alloc(256 * 1024, 0x61)
|
||||
const broker = new ModelBridgeBrokerServer({
|
||||
scratchDirectory: scratch,
|
||||
dispatch: async () => ({
|
||||
...validResponse,
|
||||
bodyBase64: responseBody.toString('base64')
|
||||
})
|
||||
})
|
||||
await broker.listen()
|
||||
try {
|
||||
const exchange = createUnixModelBridgeExchange({
|
||||
socketPath: broker.socketPath,
|
||||
requestTimeoutMs: 2_000
|
||||
})
|
||||
const exchanged = await exchange(
|
||||
{
|
||||
method: 'POST',
|
||||
path: '/v1/responses',
|
||||
headers: { 'content-type': 'application/json' },
|
||||
bodyBase64: Buffer.from('{}').toString('base64')
|
||||
},
|
||||
{
|
||||
requestId: 'request-large-response',
|
||||
signal: new AbortController().signal
|
||||
}
|
||||
)
|
||||
expect('response' in exchanged).toBe(true)
|
||||
if ('response' in exchanged) {
|
||||
expect(
|
||||
Buffer.from(
|
||||
exchanged.response.bodyBase64,
|
||||
'base64'
|
||||
).byteLength
|
||||
).toBe(responseBody.byteLength)
|
||||
await exchanged.acknowledgeDelivery()
|
||||
}
|
||||
} finally {
|
||||
await broker.close()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
runOnUnix(
|
||||
'refuses to replace or remove a non-socket endpoint path',
|
||||
async () => {
|
||||
@@ -608,6 +683,7 @@ async function sendHttp(
|
||||
options: {
|
||||
method?: string
|
||||
path?: string
|
||||
authenticated?: boolean
|
||||
headers?: Record<string, string>
|
||||
body?: string
|
||||
}
|
||||
@@ -618,11 +694,19 @@ async function sendHttp(
|
||||
}> {
|
||||
const url = new URL(origin)
|
||||
const body = options.body ?? ''
|
||||
const requestPath = options.path ?? '/v1/messages'
|
||||
const basePath =
|
||||
url.pathname === '/'
|
||||
? ''
|
||||
: url.pathname.replace(/\/$/u, '')
|
||||
const requestOptions: RequestOptions = {
|
||||
hostname: url.hostname,
|
||||
port: url.port,
|
||||
method: options.method ?? 'POST',
|
||||
path: options.path ?? '/v1/messages',
|
||||
path:
|
||||
options.authenticated === false
|
||||
? requestPath
|
||||
: `${basePath}${requestPath}`,
|
||||
headers: {
|
||||
...(options.headers ?? {}),
|
||||
...(!hasHeader(options.headers, 'content-length') &&
|
||||
|
||||
Reference in New Issue
Block a user