Skip to content
Open
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
43 changes: 42 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ notes.

## Customizing

OpenWiki supports OpenAI (with an API key or a ChatGPT login), OpenRouter, Nebius Token Factory, Fireworks, Baseten, NVIDIA NIM, an OpenAI-compatible provider, AWS Bedrock, Anthropic, and Google Vertex AI (Claude models) out of the box. The onboarding default is OpenAI with `gpt-5.6-terra`, and each inference provider also includes pre-defined model options plus support for custom model IDs.
OpenWiki supports OpenAI (with an API key or a ChatGPT login), Grok Build (subscription CLI), OpenRouter, Nebius Token Factory, Fireworks, Baseten, NVIDIA NIM, an OpenAI-compatible provider, AWS Bedrock, Anthropic, and Google Vertex AI (Claude models) out of the box. The onboarding default is OpenAI with `gpt-5.6-terra`, and each inference provider also includes pre-defined model options plus support for custom model IDs.

### Alternative base URLs

Expand Down Expand Up @@ -320,6 +320,47 @@ For CI, authenticate before the update job runs — for example with

Base URLs (and all credentials) can be set in your environment or stored in `~/.openwiki/.env`.

### Grok Build (subscription)

The `grok-build` provider runs documentation jobs through the local [Grok Build](https://grok.com)
CLI (`grok`) using your Grok subscription login — no xAI API key required. OpenWiki
spawns `grok` headlessly with `--always-approve` and `--output-format streaming-json`,
and model usage draws on the same session as interactive Grok Build.

Prerequisites:

1. Install the Grok Build CLI and ensure `grok` is on your `PATH` (or set
`OPENWIKI_GROK_BUILD_BINARY` to the full path).
2. Run `grok login` once so the CLI has a valid subscription session.

```bash
OPENWIKI_PROVIDER=grok-build openwiki code --init
# or
OPENWIKI_PROVIDER=grok-build openwiki personal --init
```

Optional overrides:

```bash
# Binary path when `grok` is not on PATH
OPENWIKI_GROK_BUILD_BINARY=/path/to/grok

# Model (defaults to grok-4.5)
OPENWIKI_MODEL_ID=grok-4.5

# Max agent turns for a documentation run (default 50)
OPENWIKI_GROK_BUILD_MAX_TURNS=50

# Overall run timeout in seconds (default 1800)
OPENWIKI_AGENT_CLI_TIMEOUT_SECONDS=1800
```

**Local / subscription only.** Prefer this provider on a machine where you already
use Grok Build interactively. It is not a drop-in for the scheduled GitHub Actions
or GitLab CI examples, which expect a metered API key and do not have a `grok login`
session. Runs use `--always-approve` so the CLI can write documentation files;
treat the model like any coding agent with write access to the repo.

### Provider retry attempts

OpenWiki uses LangChain's built-in retry handling for transient provider errors.
Expand Down
114 changes: 114 additions & 0 deletions src/agent/engines/child-env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import { MANAGED_ENV_KEYS } from "../../env.js";
import { isSecretLikeKey } from "../../diagnostics.js";

/**
* Environment keys the agent CLI is allowed to inherit from the parent.
*
* Intentionally minimal: enough for PATH lookup, home-directory session
* files (`~/.grok`, `~/.gemini/antigravity-cli`), temp dirs, locale, and
* corporate proxy/CA setup. Everything else — especially OpenWiki-managed
* credentials — is dropped.
*/
const PASSTHROUGH_ENV_KEYS = new Set([
"PATH",
"Path",
"HOME",
"USERPROFILE",
"HOMEDRIVE",
"HOMEPATH",
"USER",
"USERNAME",
"LOGNAME",
"TMPDIR",
"TMP",
"TEMP",
"TERM",
"COLORTERM",
"NO_COLOR",
"FORCE_COLOR",
"SHELL",
"ComSpec",
"COMSPEC",
"SYSTEMROOT",
"SystemRoot",
"WINDIR",
"PATHEXT",
"PROCESSOR_ARCHITECTURE",
"APPDATA",
"LOCALAPPDATA",
"XDG_CONFIG_HOME",
"XDG_DATA_HOME",
"XDG_CACHE_HOME",
"XDG_STATE_HOME",
"XDG_RUNTIME_DIR",
"HTTP_PROXY",
"HTTPS_PROXY",
"NO_PROXY",
"ALL_PROXY",
"http_proxy",
"https_proxy",
"no_proxy",
"all_proxy",
"SSL_CERT_FILE",
"SSL_CERT_DIR",
"REQUESTS_CA_BUNDLE",
"CURL_CA_BUNDLE",
"NODE_EXTRA_CA_CERTS",
]);

const MANAGED_ENV_KEY_SET = new Set<string>(MANAGED_ENV_KEYS);

/**
* Builds a scrubbed environment for vendor agent-CLI children.
*
* Drops every {@link MANAGED_ENV_KEYS} entry (provider keys, OAuth tokens,
* connector secrets), secret-like keys, and OpenWiki/LangChain config so a
* prompt-injected shell step or compromised binary cannot read credentials
* that OpenWiki loaded into `process.env`.
*/
export function buildAgentCliChildEnv(
parent: NodeJS.ProcessEnv = process.env,
): NodeJS.ProcessEnv {
const env: NodeJS.ProcessEnv = {};

for (const [key, value] of Object.entries(parent)) {
if (value === undefined) {
continue;
}

if (!shouldPassEnvKey(key)) {
continue;
}

env[key] = value;
}

return env;
}

/** Exported for tests. */
export function shouldPassEnvKey(key: string): boolean {
if (MANAGED_ENV_KEY_SET.has(key)) {
return false;
}

if (isSecretLikeKey(key)) {
return false;
}

// Defense in depth: never forward OpenWiki or LangChain/LangSmith vars even
// when they are not in MANAGED_ENV_KEYS (e.g. future keys, LANGCHAIN_ENDPOINT).
if (
key.startsWith("OPENWIKI_") ||
key.startsWith("LANGCHAIN_") ||
key.startsWith("LANGSMITH_")
) {
return false;
}

if (key.startsWith("LC_")) {
return true;
}

return PASSTHROUGH_ENV_KEYS.has(key) || key === "LANG";
}
Loading