Skip to content
Merged
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
30 changes: 26 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,16 @@ npx @expo/code-review-cli doctor
The scaffolded default is **Anthropic via the Claude Code CLI**: locally your
`claude` login is enough, and for CI it helps you mint a token with
`claude setup-token`. It also handles the alternatives (an OpenAI **API key**,
a **ChatGPT/Codex subscription** sign-in). `doctor` offers to run it whenever a
credential is missing.
a **ChatGPT/Codex subscription** sign-in, or a Meta Model API key for **Muse
Spark**). `doctor` offers to run it whenever a credential is missing.

In CI, store the credential as the repo secret the scaffolded workflow forwards
(`CLAUDE_CODE_REVIEW_SHARED_API_TOKEN` by default — an `sk-ant-oat…` token from
`claude setup-token`, or an `sk-ant-api…` Console key; the CLI reads either).

Prefer **OpenAI** (API key, or a ChatGPT/Codex subscription, or both mixed) or
another provider? See [Other providers & auth modes](#other-providers) below.
Prefer **Muse Spark**, **OpenAI** (API key, or a ChatGPT/Codex subscription, or
both mixed), or another provider? See [Other providers & auth modes](#other-providers)
below.

### Reviewing (already configured)

Expand Down Expand Up @@ -721,6 +722,27 @@ fallback key; `ecr doctor` diagnoses setup.
} }
```

- **Meta / Muse Spark 1.2 (public Model API).** Set the default model and any
model-pinned agent frontmatter to `meta/muse-spark-1.2`. ECR supplies the fixed
public Responses endpoint and the `@ai-sdk/openai` adapter; the generic
Chat-Completions compatibility adapter is intentionally not used because it
loses Muse's reasoning continuity across tool turns. Standard and Contributor
model ids are supported.

```jsonc
"model": "meta/muse-spark-1.2",
"auth": { "providers": {
"meta": { "mode": "api-key", "tokenEnv": "META_API_KEY" }
} }
```

Create the key in the [Meta AI developer portal](https://developer.meta.com/ai/).
Locally, export it as `META_API_KEY`. In each review-running workflow, replace
the Anthropic credential line with
`META_API_KEY: ${{ secrets.META_API_KEY }}`, set the repo variable
`ECR_EXPECTED_TOKEN_ENV=META_API_KEY`, and remove the Claude CLI install step
if no configured agent uses an `anthropic/…` model. Muse runs with high reasoning.

- **OpenAI: ChatGPT/Codex subscription (OAuth) + usage-based API key** — the
recommended mix if you review with OpenAI. Default models run on the
subscription (zero marginal cost); a metered key covers subscription-excluded
Expand Down
20 changes: 20 additions & 0 deletions llp/0003-model-runtimes-and-credentials.explainer.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,26 @@ POSIX, where `execvp` never searches cwd. This is a knowingly accepted residual,
oversight, and must not be silently reintroduced as a "fix" ([observed]
`opencode.ts:305-314`).

### Muse Spark via Meta Model API

Muse Spark uses the existing OpenCode engine, but OpenCode `1.18.4` does not ship a
resolvable `meta` provider. `buildOpencodeConfig` therefore synthesizes one only for an
in-use `meta` API-key entry without an `upstream`; an entry with `upstream` remains an
alias and never redirects that upstream's credential to Meta. The native provider's
destination is fixed to `https://api.meta.ai/v1`, its credential is an environment
interpolation (never the key value), and its adapter is `@ai-sdk/openai` so requests use
the Responses API and preserve encrypted reasoning across tool turns. The generic
`@ai-sdk/openai-compatible` adapter is deliberately not used because its Chat
Completions path loses that continuity [observed:
`opencode.ts` `META_MODEL_API_BASE_URL` / `META_MUSE_MODELS` / `buildOpencodeConfig`].

The declared model catalog is an allowlist (`muse-spark-1.2` and
`muse-spark-1.2-contributor`), not a reflection of arbitrary config strings. This keeps
the existing preflight honest: a misspelled or not-yet-supported Meta model remains
absent from the server's provider model list and fails once before any pass. Both models
declare their public context/output limits, multimodal inputs, high reasoning, and
encrypted reasoning inclusion [observed: `opencode.ts` `META_MUSE_MODELS`].

## Claude Code CLI Containment

The Claude Code engine runs each review pass as a single stateless
Expand Down
1 change: 1 addition & 0 deletions llp/0007-cli-commands-and-ci.explainer.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ doctor resolves auth the way real reviews do: a `routing.jsonc` `defaults.auth`
- It hands out only ACCESS tokens; the refresh token never leaves OpenCode's store, because OpenCode's refresh tokens are SINGLE-USE (rotation) and OpenCode is their sole legitimate consumer — a copy in a shell config or CI secret dies on the next rotation and can take the whole sign-in down with it [observed: `src/commands/setup-auth.ts:87-93`].
- The exported shell line single-quotes the token value so a token containing shell metacharacters (`$HOME`, `!`) is never expanded when sourced [observed: `src/commands/setup-auth.ts:127-131`; test in `src/__tests__/setup-auth.test.ts`].
- `anthropic` auth is always satisfied by the Claude Code CLI subscription-login flow regardless of the declared `mode` (oauth vs api-key) — mode is irrelevant for that provider [observed: `src/commands/setup-auth.ts:50-59`].
- A `meta` API-key entry is a manual-key plan: setup-auth points to the Meta AI developer portal and prints the configured `META_API_KEY` export, while doctor uses the same generic provider readiness check as the real review [observed: `src/commands/setup-auth.ts` `planFromAuth` / manual-key guidance; `src/core/auth.ts` `PROVIDER_KEY_ENV`].
- The two interactive logins run via `spawnSync` with `stdio: "inherit"` and `cwd: os.tmpdir()` — the tmpdir cwd keeps a possibly-untrusted checkout from becoming the login subprocess's working directory, and the `inherit` stdio is why these two calls cannot be converted to `exec.ts`'s capturing `run()` [observed: `src/commands/setup-auth.ts:200-203,256-259`].

## init and dismiss
Expand Down
9 changes: 9 additions & 0 deletions llp/0009-adoption-templates-and-ci-workflows.guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ The three workflows share a posture built entirely around one fact: a reviewer j

**Concurrency defaults by auth mode.** The commented `chunk.concurrency` default is 6 for an API key and 3 for a subscription (OAuth) credential, "one account handles many parallel streams poorly, and several PRs may review on the same credential at once" [observed: `templates/config.jsonc:28-30`].

**Muse Spark is opt-in without weakening the default secret surface.** The root config
documents `meta/muse-spark-1.2` plus a `META_API_KEY` auth entry, and each
review-running workflow shows the corresponding secret line commented out. It is not
forwarded by the default scaffold: adopters replace the Anthropic line and set
`ECR_EXPECTED_TOKEN_ENV=META_API_KEY`, so the model process receives only the
credential actually selected by trusted config. The default remains Anthropic and
`dismiss.yml` still receives no model credential [observed: `templates/config.jsonc`;
`templates/workflow.yml`, `command.yml`, and `atlantis.yml`].

**Keep the `**/*` catch-all first in `routing.jsonc`.** Scopes match last-match-wins, so a `**/*` catch-all must come first and more specific scopes come after to override it [observed: `templates/routing.jsonc:27-31`; `AGENTS.md:17-18`]. Nothing validates the order — reversing it silently changes which config applies to already-routed files [inferred: no code checks that the `**/*` catch-all comes first, so reversing it silently changes routing].

**`scope-config.jsonc` deliberately omits `auth` and `commentTag`.** It is a *different* template from the root `config.jsonc`, not a copy. A scope config carries no `auth` block — credentials are root-only, and the loader plus the CI guard reject a scope config that declares one [observed: `templates/scope-config.jsonc:1-3`; `AGENTS.md:51`]. It also omits `commentTag`, because a scope's PR-comment marker is always derived as `<rootTag>:<scope-name>` so `ecr ci` and `ecr review --scope --post` target the same comment; declaring one is rejected by the scope schema [observed: `templates/scope-config.jsonc:23-25`]. Reusing the root `config.jsonc` template for a scope — a tempting "simplification" — would break the trust boundary (LLP 0006).
Expand Down
19 changes: 19 additions & 0 deletions src/__tests__/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,25 @@ test("checkProviderAuth: an entry for an IN-USE provider is still enforced", ()
expect(r.detail).toContain("openai");
});

test("checkProviderAuth: Meta uses META_API_KEY and rejects cross-provider reuse", () => {
const meta = cfgWithModels(["meta/muse-spark-1.2"], {
mode: "api-key",
provider: "meta",
tokenEnv: "META_API_KEY",
});
expect(checkProviderAuth(meta, {}).detail).toContain("META_API_KEY");
expect(checkProviderAuth(meta, { META_API_KEY: "meta-review-key" }).ok).toBe(true);

const wrongOwner = cfgWithModels(["openai/gpt-5.5"], {
mode: "api-key",
provider: "openai",
tokenEnv: "META_API_KEY",
});
const result = checkProviderAuth(wrongOwner, { META_API_KEY: "meta-review-key" });
expect(result.ok).toBe(false);
expect(result.detail).toContain("meta's well-known credential env");
});

test("prepareAuth: does not forward a dead unused-provider api-key into its key env", async () => {
// An entry for a provider no model uses must not have its tokenEnv copied into the
// provider key env — checkProviderAuth skips its guard, so forwarding would
Expand Down
80 changes: 80 additions & 0 deletions src/__tests__/opencode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
resolveEngineDispatch,
resolveOpencodeCli,
STACK_VERIFIER_AGENT,
META_MODEL_API_BASE_URL,
} from "../core/opencode.js";
import type { OpencodeHandle } from "../core/opencode.js";
import type { ClaudeCodeHandle } from "../core/claude-code.js";
Expand Down Expand Up @@ -341,6 +342,85 @@ test("an upstream-alias auth entry synthesizes a provider block with exactly the
expect(opencode.provider?.openai).toBeUndefined();
});

test("Meta auth synthesizes the public Muse Responses provider without embedding its key", () => {
const config = configWith({
agents: [{ id: "correctness", model: "meta/muse-spark-1.2" }],
coordinatorModel: "meta/muse-spark-1.2",
auth: [{ mode: "api-key", provider: "meta", tokenEnv: "META_API_KEY" }],
});
const opencode = buildOpencodeConfig(config) as {
provider?: Record<
string,
{
npm: string;
options: { baseURL: string; apiKey: string };
models: Record<string, { reasoning?: boolean; options?: Record<string, unknown> }>;
}
>;
};
const meta = opencode.provider?.meta;
expect(meta).toBeDefined();
expect(meta!.npm).toBe("@ai-sdk/openai");
expect(meta!.options).toEqual({
baseURL: META_MODEL_API_BASE_URL,
apiKey: "{env:META_API_KEY}",
});
expect(Object.keys(meta!.models)).toEqual(["muse-spark-1.2"]);
expect(meta!.models["muse-spark-1.2"]?.reasoning).toBe(true);
expect(meta!.models["muse-spark-1.2"]?.options).toMatchObject({
reasoningEffort: "high",
include: ["reasoning.encrypted_content"],
});
});

test("a Meta-named upstream alias does not redirect the upstream credential to Meta", () => {
const config = configWith({
agents: [{ id: "correctness", model: "meta/muse-spark-1.2" }],
coordinatorModel: "meta/muse-spark-1.2",
auth: [
{
mode: "api-key",
provider: "meta",
tokenEnv: "CLAUDE_CODE_REVIEW_SHARED_API_TOKEN",
upstream: "anthropic",
},
],
});
const opencode = buildOpencodeConfig(config) as {
provider?: Record<
string,
{ npm: string; options: { apiKey: string; baseURL?: string }; models: object }
>;
};
const alias = opencode.provider?.meta;
expect(alias).toBeDefined();
expect(alias!.npm).toBe("@ai-sdk/anthropic");
expect(alias!.options).toEqual({ apiKey: "{env:CLAUDE_CODE_REVIEW_SHARED_API_TOKEN}" });
expect(alias!.options.baseURL).toBeUndefined();
expect(Object.keys(alias!.models)).toEqual(["muse-spark-1.2"]);
});

test("Meta provider does not register an unknown Muse id, so preflight can reject it", () => {
const config = configWith({
agents: [{ id: "correctness", model: "meta/muse-spark-typo" }],
coordinatorModel: "meta/muse-spark-typo",
auth: [{ mode: "api-key", provider: "meta", tokenEnv: "META_API_KEY" }],
});
const opencode = buildOpencodeConfig(config) as {
provider?: Record<string, { models: Record<string, unknown> }>;
};
expect(opencode.provider?.meta?.models).toEqual({});
expect(
findUnknownModels(["meta/muse-spark-typo"], { meta: ["muse-spark-1.2"] }, ["meta"]),
).toEqual([
{
model: "meta/muse-spark-typo",
reason: "model",
suggestions: ["muse-spark-1.2"],
},
]);
});

test("buildOpencodeConfig registers the no-tools stack verifier (empty tool list)", () => {
const opencode = buildOpencodeConfig(configWith({})) as {
agent: Record<string, { tools: Record<string, boolean> }>;
Expand Down
3 changes: 3 additions & 0 deletions src/__tests__/research.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ test("the wrapper hands the MCP server a constructed environment, not an inherit
PATH: process.env.PATH ?? "",
HOME: "/root",
ANTHROPIC_API_KEY: "must-not-reach-the-server",
META_API_KEY: "must-not-reach-the-server",
CLAUDE_CODE_OAUTH_TOKEN: "must-not-reach-the-server",
AWS_SECRET_ACCESS_KEY: "must-not-reach-the-server",
GITHUB_TOKEN: "must-not-reach-the-server",
Expand Down Expand Up @@ -93,6 +94,7 @@ test("research child environment forwards only locale, proxy variables, and the
no_proxy: "localhost",
BRAVE_SEARCH_API_KEY: "search-only",
SECRET_TOKEN: "must-not-be-forwarded",
META_API_KEY: "must-not-be-forwarded",
PATH: "/private/bin",
}),
).toMatchObject({
Expand All @@ -103,6 +105,7 @@ test("research child environment forwards only locale, proxy variables, and the
BRAVE_SEARCH_API_KEY: "search-only",
});
expect(researchChildEnvironment({ SECRET_TOKEN: "nope" })).not.toHaveProperty("SECRET_TOKEN");
expect(researchChildEnvironment({ META_API_KEY: "nope" })).not.toHaveProperty("META_API_KEY");
expect(researchChildEnvironment({ PATH: "/private/bin" })).not.toHaveProperty("PATH");
});

Expand Down
8 changes: 8 additions & 0 deletions src/__tests__/setup-auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ test("plan: the mixed setup needs one ChatGPT login and one manual key", () => {
expect(plan.unsupported).toEqual([]);
});

test("plan: Meta Model API is a manual API key setup", () => {
const plan = planFromAuth([{ provider: "meta", mode: "api-key", tokenEnv: "META_API_KEY" }]);
expect(plan.manualKeys).toEqual([
{ provider: "meta", tokenEnv: "META_API_KEY", upstream: undefined },
]);
expect(plan.unsupported).toEqual([]);
});

test("plan: an anthropic entry (any mode) → claudeLogin; api-key without tokenEnv needs nothing", () => {
const plan = planFromAuth([
// Mode is irrelevant for anthropic — it is always served by the Claude Code CLI.
Expand Down
7 changes: 6 additions & 1 deletion src/commands/setup-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ getting each credential:
opens your browser) and prints the \`export <tokenEnv>=…\` line for
CI/headless runs.
• an API key (api-key entries): prints where to create the key, the exact
permissions it needs, and the export line to fill in.
permissions it needs, and the export line to fill in. Meta Model API
(\`meta/muse-spark-…\`) uses META_API_KEY from the Meta AI developer portal.

Without a repo config, it offers the recommended ChatGPT/Codex subscription flow
with the default env name.
Expand Down Expand Up @@ -300,6 +301,10 @@ export async function setupAuthCommand(argv: string[] = []): Promise<void> {
} else if (upstream === "anthropic") {
err(" https://console.anthropic.com/settings/keys — a workspace-scoped key");
err(" with a spend limit is all the reviewer needs.");
} else if (upstream === "meta") {
// @ref LLP 0007#doctor-and-setup-auth [implements] — Meta uses a manual API key
err(" https://developer.meta.com/ai/ — create a Model API key with access to");
err(" Muse Spark, then store it as a dedicated review secret.");
} else {
err(` mint a key for the "${upstream}" provider.`);
}
Expand Down
1 change: 1 addition & 0 deletions src/core/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const PROVIDER_KEY_ENV: Record<string, string> = {
openai: "OPENAI_API_KEY",
google: "GOOGLE_GENERATIVE_AI_API_KEY",
openrouter: "OPENROUTER_API_KEY",
meta: "META_API_KEY",
};

/**
Expand Down
60 changes: 60 additions & 0 deletions src/core/opencode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,44 @@ import type { ResearchMcpRuntime } from "./research.js";
/** Discriminant for the Claude Code CLI engine (see core/claude-code.ts). */
export const CLAUDE_CODE_ENGINE = "claude-code" as const;

/** Fixed so repo config cannot redirect the Meta credential. */
// @ref LLP 0003#muse-spark-via-meta-model-api [implements] — fixed endpoint and model allowlist
export const META_MODEL_API_BASE_URL = "https://api.meta.ai/v1";

/** Supported public Muse models. Unknown ids remain visible to preflight. */
export const META_MUSE_MODELS: Record<string, Record<string, unknown>> = {
"muse-spark-1.2": {
name: "Muse Spark 1.2",
reasoning: true,
limit: { context: 1_048_576, output: 131_072 },
modalities: {
input: ["text", "image", "pdf", "video"],
output: ["text"],
},
options: {
store: false,
reasoningEffort: "high",
reasoningSummary: "auto",
include: ["reasoning.encrypted_content"],
},
},
"muse-spark-1.2-contributor": {
name: "Muse Spark 1.2 Contributor",
reasoning: true,
limit: { context: 1_048_576, output: 131_072 },
modalities: {
input: ["text", "image", "pdf", "video"],
output: ["text"],
},
options: {
store: false,
reasoningEffort: "high",
reasoningSummary: "auto",
include: ["reasoning.encrypted_content"],
},
},
};

/**
* Resolve which engine an agent's pass dispatches to, and (when claude) which
* claude handle to run it against. The per-agent router (engineOf) wins; absent it
Expand Down Expand Up @@ -221,6 +259,28 @@ export function buildOpencodeConfig(
config.coordinator.model,
];
for (const entry of config.auth) {
if (
entry.provider === "meta" &&
entry.mode === "api-key" &&
entry.tokenEnv &&
!entry.upstream
) {
// Muse needs the Responses adapter; openai-compatible uses Chat Completions.
provider.meta = {
npm: "@ai-sdk/openai",
name: "Meta Model API",
options: {
baseURL: META_MODEL_API_BASE_URL,
apiKey: `{env:${entry.tokenEnv}}`,
},
models: Object.fromEntries(
Object.entries(META_MUSE_MODELS).filter(([model]) =>
referencedModels.includes(`meta/${model}`),
),
),
};
continue;
}
if (!entry.upstream || !entry.tokenEnv) {
continue;
}
Expand Down
2 changes: 2 additions & 0 deletions templates/atlantis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ jobs:
# Anthropic review credential — the env var named by auth.tokenEnv in
# config.jsonc (see workflow.yml for the accepted token shapes).
CLAUDE_CODE_REVIEW_SHARED_API_TOKEN: ${{ secrets.CLAUDE_CODE_REVIEW_SHARED_API_TOKEN }}
# Muse alternative (also set ECR_EXPECTED_TOKEN_ENV=META_API_KEY):
# META_API_KEY: ${{ secrets.META_API_KEY }}
# Optional search-only credential for trusted platform documentation research.
BRAVE_SEARCH_API_KEY: ${{ secrets.BRAVE_SEARCH_API_KEY }}
# Optional: override the model for every agent.
Expand Down
2 changes: 2 additions & 0 deletions templates/command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ jobs:
# by `claude setup-token`, or an `sk-ant-api…` Console key (the Claude
# Code CLI reads either).
CLAUDE_CODE_REVIEW_SHARED_API_TOKEN: ${{ secrets.CLAUDE_CODE_REVIEW_SHARED_API_TOKEN }}
# Muse alternative (also set ECR_EXPECTED_TOKEN_ENV=META_API_KEY):
# META_API_KEY: ${{ secrets.META_API_KEY }}
# Optional search-only credential for trusted platform documentation research.
BRAVE_SEARCH_API_KEY: ${{ secrets.BRAVE_SEARCH_API_KEY }}
# Optional: override the model for every agent.
Expand Down
Loading