feat(cli): let orca fill read its value from stdin (#29850)

Add `orca fill --value-stdin` so passwords and other secrets stay out of
argv and shell history. Fill drops one trailing newline from stdin (secret
readers end with one) and rejects empty stdin so a failed reader cannot
silently clear the field; `--value ''` still clears.

Share one flag-or-stdin reader with `orca computer type`/`set-value` and
the `--body-file -` reader. Computer commands keep their existing
semantics: no newline trimming, set-value still accepts empty stdin, and
`--text-stdin=true` style keeps reading stdin.

Fixes #29849

Co-authored-by: Neil <neil@stably.ai>
This commit is contained in:
Prateek Rungta
2026-11-15 01:23:31 -08:00
committed by GitHub
co-authored by Neil
parent 3301055c8f
commit a2bcfef327
10 changed files with 176 additions and 51 deletions
+4 -38
View File
@@ -8,9 +8,9 @@ import {
getOptionalNumberFlag,
getOptionalPositiveIntegerFlag,
getOptionalStringFlag,
getRequiredStringFlag,
getRequiredStringFlagAllowingEmpty
getRequiredStringFlag
} from '../arguments/flags'
import { getFlagOrStdinPayload } from '../arguments/flag-or-stdin-payload'
import { RuntimeClientError } from '../runtime/connection/types'
import {
validateDragTarget,
@@ -140,7 +140,7 @@ export function getComputerDragActionFlags(flags: Map<string, string | boolean>)
export async function getComputerTextActionFlags(flags: Map<string, string | boolean>): Promise<{
text: string
}> {
return { text: await getTextPayload(flags, 'text') }
return { text: await getFlagOrStdinPayload(flags, 'text') }
}
export async function getComputerTypeTextActionFlags(
@@ -190,44 +190,10 @@ export async function getComputerSetValueActionFlags(
}> {
return {
elementIndex: getRequiredNonNegativeIntegerFlag(flags, 'element-index'),
value: await getTextPayload(flags, 'value')
value: await getFlagOrStdinPayload(flags, 'value', { allowEmptyStdin: true })
}
}
async function getTextPayload(
flags: Map<string, string | boolean>,
name: 'text' | 'value'
): Promise<string> {
const stdinFlag = `${name}-stdin`
if (flags.has(stdinFlag)) {
if (flags.has(name)) {
throw new RuntimeClientError(
'invalid_argument',
`Use either --${name} or --${stdinFlag}, not both`
)
}
const payload = await readStdin()
if (name === 'text' && payload.length === 0) {
throw new RuntimeClientError('invalid_argument', 'Missing text from stdin')
}
return payload
}
return name === 'value'
? getRequiredStringFlagAllowingEmpty(flags, name)
: getRequiredStringFlag(flags, name)
}
async function readStdin(): Promise<string> {
if (process.stdin.isTTY) {
throw new RuntimeClientError('invalid_argument', 'stdin payload requested but stdin is a TTY')
}
const chunks: Buffer[] = []
for await (const chunk of process.stdin) {
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk)))
}
return Buffer.concat(chunks).toString('utf8')
}
function getOptionalPositiveNumberFlag(
flags: Map<string, string | boolean>,
name: string