Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ Update existing documentation:
openwiki --update
```

Reconfigure your provider, API key, model, or LangSmith key without running the
agent (for example, to switch to a different key):

```sh
openwiki --config
```

`--config` walks the setup prompts even when credentials already exist. Press
Enter on the API key or LangSmith prompt to keep the current value; only what you
retype is changed.

Show help:

```sh
Expand Down
113 changes: 108 additions & 5 deletions src/cli.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ type RunState =
errorDiagnostics?: ErrorDiagnostic[];
};

type ConfigState =
| { status: "editing" }
| { status: "saved"; result: InitSetupResult }
| { status: "error"; message: string };

type RunLogItem = {
actionCount?: number;
activeToolCallIds?: string[];
Expand Down Expand Up @@ -136,6 +141,9 @@ function App({ command }: AppProps) {
const activeRunLog = useRef<RunLogItem[]>([]);
const [runState, setRunState] = useState<RunState>({ status: "idle" });
const [completedRuns, setCompletedRuns] = useState<CompletedRun[]>([]);
const [configState, setConfigState] = useState<ConfigState>({
status: "editing",
});
const [activeUserMessage, setActiveUserMessage] = useState<string | null>(
command.kind === "run" ? command.userMessage : null,
);
Expand Down Expand Up @@ -225,13 +233,13 @@ function App({ command }: AppProps) {
return;
}

if (command.dryRun) {
process.exitCode = 0;
app.exit();
if (command.kind !== "run") {
return;
}

if (command.kind !== "run") {
if (command.dryRun) {
process.exitCode = 0;
app.exit();
return;
}

Expand Down Expand Up @@ -389,10 +397,94 @@ function App({ command }: AppProps) {
}
}, [app, autoExitOnSuccess, runState.status]);

// `--config` is a settings editor: once the setup flow resolves, render the
// outcome one last time and exit without ever invoking the agent.
useEffect(() => {
if (command.kind !== "config") {
return;
}

if (configState.status === "saved") {
process.exitCode = 0;
app.exit();
return;
}

if (configState.status === "error") {
process.exitCode = 1;
app.exit();
}
}, [app, command.kind, configState.status]);

if (command.kind === "help") {
return <HelpView />;
}

if (command.kind === "config") {
if (configState.status === "editing") {
return (
<InitSetup
reconfigure
modelIdOverride={null}
onComplete={(result) => {
if (result.modelId) {
setSessionModelId(result.modelId);
}
if (result.provider) {
setSessionProvider(result.provider);
}

setConfigState({ status: "saved", result });
}}
onError={(message) => {
setConfigState({ status: "error", message });
}}
/>
);
}

if (configState.status === "error") {
return (
<Box flexDirection="column">
<Header modelId={displayModelId} subtitle="Configuration failed" />
<StatusLine tone="error" label="Error" value={configState.message} />
</Box>
);
}

const { result } = configState;
const savedAnything =
result.savedApiKey ||
result.savedProvider ||
result.savedModelId ||
result.savedLangSmithKey;

return (
<Box flexDirection="column">
<Header
modelId={result.modelId ?? displayModelId}
subtitle="Configuration saved"
/>
<StatusLine
tone={savedAnything ? "success" : "muted"}
label="Credentials"
value={savedAnything ? "saved" : "unchanged"}
/>
{result.provider ? (
<StatusLine
tone="muted"
label="Provider"
value={getProviderLabel(result.provider)}
/>
) : null}
{result.modelId ? (
<StatusLine tone="muted" label="Model" value={result.modelId} />
) : null}
<StatusLine tone="muted" label="Next" value="run openwiki to start" />
</Box>
);
}

if (command.kind === "error") {
return (
<Box flexDirection="column">
Expand Down Expand Up @@ -3022,7 +3114,10 @@ function Rows({ rows }: RowsProps) {
const argv = process.argv.slice(2);
const parsedCommand = parseCommand(argv);

if (parsedCommand.kind === "run" && !parsedCommand.dryRun) {
if (
(parsedCommand.kind === "run" && !parsedCommand.dryRun) ||
parsedCommand.kind === "config"
) {
await loadOpenWikiEnv();
}

Expand Down Expand Up @@ -3112,6 +3207,14 @@ function writePrintErrorDiagnostics(error: unknown): void {
}

function resolveStartupCommand(command: CliCommand): CliCommand {
if (command.kind === "config" && !process.stdin.isTTY) {
return {
kind: "error",
exitCode: 1,
message: "openwiki --config requires an interactive terminal.",
};
}

if (
command.kind === "run" &&
!command.dryRun &&
Expand Down
27 changes: 27 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type HelpContent = {

export type CliCommand =
| { kind: "help"; exitCode: 0 }
| { kind: "config"; exitCode: 0 }
| {
kind: "run";
exitCode: 0;
Expand All @@ -43,6 +44,7 @@ export function parseCommand(argv: string[]): CliCommand {
let dryRun = false;
let modelId: string | null = null;
let print = false;
let config = false;
let command: OpenWikiCommand = "chat";
const userMessageParts: string[] = [];

Expand Down Expand Up @@ -71,6 +73,11 @@ export function parseCommand(argv: string[]): CliCommand {
continue;
}

if (arg === "--config") {
config = true;
continue;
}

if (arg === "--init" || arg === "--update") {
const nextCommand = arg === "--init" ? "init" : "update";

Expand Down Expand Up @@ -143,6 +150,19 @@ export function parseCommand(argv: string[]): CliCommand {
userMessageParts.length > 0 ? userMessageParts.join(" ") : null;
const shouldStart = command !== "chat" || userMessage !== null;

if (config) {
if (command !== "chat" || userMessage !== null || print) {
return {
kind: "error",
exitCode: 1,
message:
"--config cannot be combined with --init, --update, --print, or a message.",
};
}

return { kind: "config", exitCode: 0 };
}

if (print && !shouldStart) {
return {
kind: "error",
Expand Down Expand Up @@ -178,6 +198,7 @@ export const helpContent: HelpContent = {
"openwiki [--modelId <model>] [message]",
"openwiki --init [message]",
"openwiki --update [message]",
"openwiki --config",
],
commands: [
{
Expand All @@ -194,6 +215,11 @@ export const helpContent: HelpContent = {
label: "--update",
description: "Update existing OpenWiki documentation.",
},
{
label: "--config",
description:
"Reconfigure provider, API key, model, and LangSmith without running the agent.",
},
{
label: "-p, --print",
description: "Run once and print the final assistant output.",
Expand All @@ -213,6 +239,7 @@ export const helpContent: HelpContent = {
"openwiki",
"openwiki --init",
"openwiki --update",
"openwiki --config",
'openwiki "What can you do?"',
'openwiki -p "Summarize what OpenWiki can do"',
"openwiki --modelId gpt-5.5",
Expand Down
Loading