Import packages/plugin/src/harness-remote-bridge.ts
This commit is contained in:
parent
e7b37ac811
commit
cd33e6a12c
|
|
@ -74,10 +74,10 @@ const commandExecuteArgsSchema = z.object({
|
||||||
agentId: z.string().min(1).max(128),
|
agentId: z.string().min(1).max(128),
|
||||||
line: z.string().min(1).max(2048),
|
line: z.string().min(1).max(2048),
|
||||||
// dsh-commands <= 0.1.2 calls this field `images`; dsh-commands 0.1.5
|
// dsh-commands <= 0.1.2 calls this field `images`; dsh-commands 0.1.5
|
||||||
// renamed it to `submittedAttachments`. Only empty arrays are exposed by
|
// renamed it to `submittedAttachments`. Current Hosts resolve opaque file
|
||||||
// the Remote bridge; command attachments are deliberately out of scope.
|
// receipts in the receiving Session; legacy image arguments stay empty.
|
||||||
images: z.array(z.never()).length(0).optional(),
|
images: z.array(z.never()).length(0).optional(),
|
||||||
submittedAttachments: z.array(z.never()).length(0).optional(),
|
submittedAttachments: z.array(z.object({ type: z.literal('file'), receiptId: z.string().min(1).max(512) }).strict()).max(32).optional(),
|
||||||
}).strict().superRefine((value, context) => {
|
}).strict().superRefine((value, context) => {
|
||||||
if (value.images !== undefined && value.submittedAttachments !== undefined) {
|
if (value.images !== undefined && value.submittedAttachments !== undefined) {
|
||||||
context.addIssue({
|
context.addIssue({
|
||||||
|
|
@ -159,6 +159,7 @@ export const HARNESS_REMOTE_ALLOWLIST = [
|
||||||
'schedule/deliveryLimits',
|
'schedule/deliveryLimits',
|
||||||
'schedule/edit',
|
'schedule/edit',
|
||||||
'schedule/run',
|
'schedule/run',
|
||||||
|
'fileUploads/upload',
|
||||||
'session/attachment',
|
'session/attachment',
|
||||||
'session/cancel',
|
'session/cancel',
|
||||||
'session/canOpenWorkspacePath',
|
'session/canOpenWorkspacePath',
|
||||||
|
|
@ -305,12 +306,17 @@ export class HarnessRemoteBridge {
|
||||||
private readonly codexWorkspace?: CodexWorkspaceBridge,
|
private readonly codexWorkspace?: CodexWorkspaceBridge,
|
||||||
private readonly resolveWorkspaceRoot?: NativeWorkspaceResolver,
|
private readonly resolveWorkspaceRoot?: NativeWorkspaceResolver,
|
||||||
private readonly schedule?: ScheduleCreateService,
|
private readonly schedule?: ScheduleCreateService,
|
||||||
|
private readonly uploadAttachment?: (body: unknown) => Promise<unknown>,
|
||||||
) {
|
) {
|
||||||
this.terminalCarrier = usesDuplexTerminal(harnessVersion) ? new TerminalCarrierCompat(gateway) : undefined
|
this.terminalCarrier = usesDuplexTerminal(harnessVersion) ? new TerminalCarrierCompat(gateway) : undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
async call(input: unknown): Promise<TypertRpcResult> {
|
async call(input: unknown): Promise<TypertRpcResult> {
|
||||||
const params = callSchema.parse(input) as HarnessRemoteCallParams
|
const params = callSchema.parse(input) as HarnessRemoteCallParams
|
||||||
|
if ((params.endpoint === 'remoteUploads/upload' || params.endpoint === 'remoteImages/upload') && this.uploadAttachment !== undefined) {
|
||||||
|
const payload = z.object({ args: z.unknown() }).strict().parse(params.payload)
|
||||||
|
return { ok: true, value: await this.uploadAttachment(payload.args) }
|
||||||
|
}
|
||||||
this.assertAllowed(params.endpoint)
|
this.assertAllowed(params.endpoint)
|
||||||
if (TERMINAL_STREAMS.has(params.endpoint)) throw new RpcError('METHOD_NOT_ALLOWED', 'Use a stream for this terminal endpoint.')
|
if (TERMINAL_STREAMS.has(params.endpoint)) throw new RpcError('METHOD_NOT_ALLOWED', 'Use a stream for this terminal endpoint.')
|
||||||
if (['settings/update', 'settings/replace', 'settings/mutate'].includes(params.endpoint)) {
|
if (['settings/update', 'settings/replace', 'settings/mutate'].includes(params.endpoint)) {
|
||||||
|
|
@ -858,18 +864,18 @@ export class HarnessRemoteBridge {
|
||||||
if (baseSegments.some(segment => segment === '..')) {
|
if (baseSegments.some(segment => segment === '..')) {
|
||||||
throw workspaceFileFailure('WORKSPACE_PATH_DENIED', 'The requested workspace path is outside the workspace.', 'outside-root')
|
throw workspaceFileFailure('WORKSPACE_PATH_DENIED', 'The requested workspace path is outside the workspace.', 'outside-root')
|
||||||
}
|
}
|
||||||
const safeBaseRel = await this.verifyWorkspacePathContainment(sessionWorkspace.root, rawBaseFile, endpoint)
|
const safeBaseRel = await this.verifyWorkspacePathContainment(sessionWorkspace.root, rawBaseFile, endpoint, sessionWorkspace.cwd)
|
||||||
const baseCandidate = resolve(sessionWorkspace.root, safeBaseRel)
|
const baseCandidate = resolve(sessionWorkspace.root, safeBaseRel)
|
||||||
const baseDir = dirname(baseCandidate)
|
const baseDir = dirname(baseCandidate)
|
||||||
const targetCandidate = resolve(baseDir, path)
|
const targetCandidate = resolve(baseDir, path)
|
||||||
safeRel = await this.verifyWorkspacePathContainment(sessionWorkspace.root, targetCandidate, endpoint)
|
safeRel = await this.verifyWorkspacePathContainment(sessionWorkspace.root, targetCandidate, endpoint, sessionWorkspace.cwd)
|
||||||
} else {
|
} else {
|
||||||
const path = typeof args.path === 'string' ? args.path : '.'
|
const path = typeof args.path === 'string' ? args.path : '.'
|
||||||
const pathSegments = process.platform === 'win32' ? path.replaceAll('\\', '/').split('/') : path.split('/')
|
const pathSegments = process.platform === 'win32' ? path.replaceAll('\\', '/').split('/') : path.split('/')
|
||||||
if (pathSegments.some(segment => segment === '..')) {
|
if (pathSegments.some(segment => segment === '..')) {
|
||||||
throw workspaceFileFailure('WORKSPACE_PATH_DENIED', 'The requested workspace path is outside the workspace.', 'outside-root')
|
throw workspaceFileFailure('WORKSPACE_PATH_DENIED', 'The requested workspace path is outside the workspace.', 'outside-root')
|
||||||
}
|
}
|
||||||
safeRel = await this.verifyWorkspacePathContainment(sessionWorkspace.root, path, endpoint)
|
safeRel = await this.verifyWorkspacePathContainment(sessionWorkspace.root, path, endpoint, sessionWorkspace.cwd)
|
||||||
}
|
}
|
||||||
|
|
||||||
let finalArgs: Record<string, unknown> = isRecord(rootPayload.args)
|
let finalArgs: Record<string, unknown> = isRecord(rootPayload.args)
|
||||||
|
|
@ -939,8 +945,15 @@ export class HarnessRemoteBridge {
|
||||||
root: string,
|
root: string,
|
||||||
path: string,
|
path: string,
|
||||||
endpoint: string,
|
endpoint: string,
|
||||||
|
cwd = root,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const candidate = isAbsolute(path) ? resolve(path) : resolve(root, path)
|
const supplied = isAbsolute(path) ? resolve(path) : resolve(root, path)
|
||||||
|
const cwdRelative = relative(resolve(cwd), supplied)
|
||||||
|
// Only the Host-authorized cwd is an accepted alias for the canonical root.
|
||||||
|
// Do not realpath arbitrary inputs: internal symlinks must still be denied.
|
||||||
|
const candidate = isAbsolute(path) && !isPathOutside(cwdRelative)
|
||||||
|
? resolve(root, cwdRelative)
|
||||||
|
: supplied
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
const rootDrive = parse(root).root.toLowerCase()
|
const rootDrive = parse(root).root.toLowerCase()
|
||||||
const candDrive = parse(candidate).root.toLowerCase()
|
const candDrive = parse(candidate).root.toLowerCase()
|
||||||
|
|
@ -1245,13 +1258,16 @@ function requiresWorkspaceChangePath(version: string | undefined): boolean {
|
||||||
&& ((Number(match[2]) === 1 && Number(match[3]) >= 7) || Number(match[2]) === 2)
|
&& ((Number(match[2]) === 1 && Number(match[3]) >= 7) || Number(match[2]) === 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function dispatchCommandForHost(
|
export async function dispatchCommandForHost(
|
||||||
gateway: LocalTypertGateway,
|
gateway: LocalTypertGateway,
|
||||||
payload: unknown,
|
payload: unknown,
|
||||||
signal: AbortSignal,
|
signal: AbortSignal,
|
||||||
harnessVersion?: string,
|
harnessVersion?: string,
|
||||||
): Promise<TypertRpcResult> {
|
): Promise<TypertRpcResult> {
|
||||||
const parsed = commandExecutePayloadSchema.parse(payload)
|
const parsed = commandExecutePayloadSchema.parse(payload)
|
||||||
|
if (harnessSessionGeneration(harnessVersion) !== 'v3' && (parsed.args.submittedAttachments?.length ?? 0) > 0) {
|
||||||
|
throw new RpcError('METHOD_NOT_ALLOWED', 'This Host does not support command file receipts.')
|
||||||
|
}
|
||||||
const legacyPayload = {
|
const legacyPayload = {
|
||||||
args: {
|
args: {
|
||||||
agentId: parsed.args.agentId,
|
agentId: parsed.args.agentId,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue