You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(cli): trace download --output follows a planted link and creates the file with the default mode #1090
bgagent trace download --output <file> writes the artifact with createWriteStream(opts.output) (cli/src/commands/trace.ts). A symbolic link at that path is followed: one that leads nowhere passes the existsSync check without --force, and the file it names is created; one that leads to an existing file is written through with --force. A new file gets the process's default mode (0644 with the usual umask), not owner-only. replay --output, the neighbouring command, writes through writeSecretFile (cli/src/config.ts), which creates the file owner-only and, since #1084, replaces it in one step and refuses a link, a FIFO, a socket or a directory at the path that belongs to another user.
A trace holds what the agent did in the task, turn by turn: the model's thinking and text, its tool calls with their inputs, and the beginning of each tool's output.
Proposal
Write the download to a temporary file beside the target, owner-only and created exclusively, and rename it over the target when the stream has ended, with the refusals of writeSecretFile for what is at the path. The targets that writeSecretFile writes in place stay writable in the same way, as createWriteStream writes them today: a device such as /dev/null, a FIFO, a symbolic link that does not resolve to a regular file (/dev/stdout when it is a pipe or a terminal), and a file that cannot be replaced (a file mounted on its own, a directory that takes no new file). writeSecretFile takes a string today, so this needs either a streaming variant that shares its checks or the checks as a function of their own.
Acceptance criteria
A new file is created with mode 0600; an existing one is replaced in one step and is 0600 afterwards.
A symbolic link, a FIFO, a socket or a directory at the path is refused when it belongs to another user, by the rule of writeSecretFile, before the download starts. A link put at the path while the download runs is replaced by the rename, not followed.
--output /dev/null --force and --output /dev/stdout --force write as they do today, and the device keeps its mode. A file that cannot be replaced is written in place.
A download that fails midway leaves the old file whole and no temporary file.
Activity