This adds support for a new flag, `-w,--writable-root`, that can be specified multiple times to _amend_ the list of folders that should be configured as "writable roots" by the sandbox used in `full-auto` mode. Values that are passed as relative paths will be resolved to absolute paths. Incidentally, this required updating a number of the `agent*.test.ts` files: it feels like some of the setup logic across those tests could be consolidated. In my testing, it seems that this might be slightly out of distribution for the model, as I had to explicitly tell it to run `apply_patch` and that it had the permissions to write those files (initially, it just showed me a diff and told me to apply it myself). Nevertheless, I think this is a good starting point.
107 lines
2.9 KiB
TypeScript
107 lines
2.9 KiB
TypeScript
import type { ApprovalPolicy } from "./approvals";
|
|
import type { AppConfig } from "./utils/config";
|
|
import type { ResponseItem } from "openai/resources/responses/responses";
|
|
|
|
import TerminalChat from "./components/chat/terminal-chat";
|
|
import TerminalChatPastRollout from "./components/chat/terminal-chat-past-rollout";
|
|
import { checkInGit } from "./utils/check-in-git";
|
|
import { CLI_VERSION, type TerminalChatSession } from "./utils/session.js";
|
|
import { onExit } from "./utils/terminal";
|
|
import { ConfirmInput } from "@inkjs/ui";
|
|
import { Box, Text, useApp, useStdin } from "ink";
|
|
import React, { useMemo, useState } from "react";
|
|
|
|
export type AppRollout = {
|
|
session: TerminalChatSession;
|
|
items: Array<ResponseItem>;
|
|
};
|
|
|
|
type Props = {
|
|
prompt?: string;
|
|
config: AppConfig;
|
|
imagePaths?: Array<string>;
|
|
rollout?: AppRollout;
|
|
approvalPolicy: ApprovalPolicy;
|
|
additionalWritableRoots: ReadonlyArray<string>;
|
|
fullStdout: boolean;
|
|
};
|
|
|
|
export default function App({
|
|
prompt,
|
|
config,
|
|
rollout,
|
|
imagePaths,
|
|
approvalPolicy,
|
|
additionalWritableRoots,
|
|
fullStdout,
|
|
}: Props): JSX.Element {
|
|
const app = useApp();
|
|
const [accepted, setAccepted] = useState(() => false);
|
|
const [cwd, inGitRepo] = useMemo(
|
|
() => [process.cwd(), checkInGit(process.cwd())],
|
|
[],
|
|
);
|
|
const { internal_eventEmitter } = useStdin();
|
|
internal_eventEmitter.setMaxListeners(20);
|
|
|
|
if (rollout) {
|
|
return (
|
|
<TerminalChatPastRollout
|
|
session={rollout.session}
|
|
items={rollout.items}
|
|
/>
|
|
);
|
|
}
|
|
|
|
if (!inGitRepo && !accepted) {
|
|
return (
|
|
<Box flexDirection="column">
|
|
<Box borderStyle="round" paddingX={1} width={64}>
|
|
<Text>
|
|
● OpenAI <Text bold>Codex</Text>{" "}
|
|
<Text dimColor>
|
|
(research preview) <Text color="blueBright">v{CLI_VERSION}</Text>
|
|
</Text>
|
|
</Text>
|
|
</Box>
|
|
<Box
|
|
borderStyle="round"
|
|
borderColor="redBright"
|
|
flexDirection="column"
|
|
gap={1}
|
|
>
|
|
<Text>
|
|
<Text color="yellow">Warning!</Text> It can be dangerous to run a
|
|
coding agent outside of a git repo in case there are changes that
|
|
you want to revert. Do you want to continue?
|
|
</Text>
|
|
<Text>{cwd}</Text>
|
|
<ConfirmInput
|
|
defaultChoice="cancel"
|
|
onCancel={() => {
|
|
app.exit();
|
|
onExit();
|
|
// eslint-disable-next-line
|
|
console.error(
|
|
"Quitting! Run again to accept or from inside a git repo",
|
|
);
|
|
}}
|
|
onConfirm={() => setAccepted(true)}
|
|
/>
|
|
</Box>
|
|
</Box>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<TerminalChat
|
|
config={config}
|
|
prompt={prompt}
|
|
imagePaths={imagePaths}
|
|
approvalPolicy={approvalPolicy}
|
|
additionalWritableRoots={additionalWritableRoots}
|
|
fullStdout={fullStdout}
|
|
/>
|
|
);
|
|
}
|