mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 19:07:41 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user