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
66 changes: 48 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ A common agent flow asks jev-code to find relevant files before editing, check c
it into small, size-limited pieces, such as one changed block of a file or one failure from a log.
3. **Exact checks run first.** Plain rules catch things like an added `test.skip`, deleted assertions,
deleted test files, and lockfile, CI or config changes.
4. **Jev answers fixed-choice questions about each piece.** Using your Jev credential (TypeSafe API key, or
an AI Gateway key with `JEV_PROVIDER=vercel`), jev-code asks
4. **Jev answers fixed-choice questions about each piece.** Using your Jev credential (TypeSafe API key,
an AI Gateway key with `JEV_PROVIDER=vercel`, or Cloudflare account id + API token with
`JEV_PROVIDER=cloudflare`), jev-code asks
[TypeSafe Jev](https://typesafe.ai), a model that answers multiple-choice questions, about one small piece
at a time. For example: "How closely is this changed block related to the task?" jev-code's own code, not
the model, turns the answers into flags using fixed thresholds.
Expand Down Expand Up @@ -68,8 +69,10 @@ After 0.1.0 is released: `npm install --global jev-code`.

```sh
export TYPESAFE_API_KEY="<your TypeSafe API key>" # default provider (or see Jev providers
# for the Vercel AI Gateway alternative)
# for the Vercel/Cloudflare alternatives)
export AI_GATEWAY_API_KEY="<your gateway key>" # JEV_PROVIDER=vercel
export CLOUDFLARE_ACCOUNT_ID="<your account id>" # JEV_PROVIDER=cloudflare
export CLOUDFLARE_API_TOKEN="<your API token>" # JEV_PROVIDER=cloudflare
```

**Example.** An agent was asked to fix a crash. It did, but it also skipped the test and removed an assertion.
Expand Down Expand Up @@ -175,7 +178,7 @@ There is no `pass` or `approved` result. Run `jev-code --help` for exit-code mea

By default, run records are saved under `.jev-code/runs/<run-id>/`. They can contain code and log lines, so they are private to your user and ignored by Git. Use `--no-persist` to disable them.

jev-code first sends TypeSafe the redacted request, input shape, diff presence, available capabilities and option names for routing. The selected workflow then sends only the task and bounded evidence it needs, such as changed blocks or short failure-log sections. Obvious secret files and common token formats are filtered on a best-effort basis, but jev-code is not a secret scanner. With the default provider, requests go to TypeSafe; with `JEV_PROVIDER=vercel`, requests additionally pass through the Vercel AI Gateway, which processes them even under zero-data-retention routing. Review both the gateway's and the upstream provider's data terms before sending private or regulated code.
jev-code first sends TypeSafe the redacted request, input shape, diff presence, available capabilities and option names for routing. The selected workflow then sends only the task and bounded evidence it needs, such as changed blocks or short failure-log sections. Obvious secret files and common token formats are filtered on a best-effort basis, but jev-code is not a secret scanner. With the default provider, requests go to TypeSafe; with `JEV_PROVIDER=vercel`, requests additionally pass through the Vercel AI Gateway, which processes them even under zero-data-retention routing; with `JEV_PROVIDER=cloudflare`, requests additionally pass through Cloudflare infrastructure. Review the gateway's or Cloudflare's and the upstream provider's data terms before sending private or regulated code.

jev-code does not replace tests, type checks, linters, security tools, or human review.

Expand All @@ -194,15 +197,18 @@ npm run check:package # package manifest and file-list checks used by the rele

`npm run smoke:real` makes a few real TypeSafe Jev requests after `npm run build`; it skips itself
without `TYPESAFE_API_KEY`. `npm run smoke:vercel` performs one minimal real Jev evaluation through
the Vercel AI Gateway; it requires `JEV_SMOKE=1` and `AI_GATEWAY_API_KEY` and skips itself otherwise,
so neither live test is part of `npm run check`. See [docs/architecture.md](docs/architecture.md) for how the code is organized and
the Vercel AI Gateway; it requires `JEV_SMOKE=1` and `AI_GATEWAY_API_KEY` and skips itself otherwise.
`npm run smoke:cloudflare` performs one minimal real Jev evaluation through Cloudflare Workers AI;
it requires `JEV_SMOKE=1`, `CLOUDFLARE_ACCOUNT_ID`, and a Cloudflare API token
(`CLOUDFLARE_API_TOKEN` or `JEV_CLOUDFLARE_API_TOKEN`) and skips itself otherwise, so no live test
is part of `npm run check`. See [docs/architecture.md](docs/architecture.md) for how the code is organized and
[docs/RELEASING.md](docs/RELEASING.md) for how releases are published.

## Jev providers

Jev inference is pluggable. Both providers expose the same Jev/System One capability to the review
Jev inference is pluggable. All providers expose the same Jev/System One capability to the review
engine through the same request/response schema, so workflows and reports are provider-independent.
The providers are different services, though: when the gateway does not report TypeSafe's separate
The providers are different services, though: when a proxy does not report TypeSafe's separate
confidence statistic, confidence is synthesized from the distribution and threshold-gated decisions
can differ from TypeSafe-direct (see below). Selection is entirely through configuration, at start:

Expand All @@ -218,31 +224,55 @@ export JEV_PROVIDER=vercel # Vercel AI Gateway hosting of Jev
export AI_GATEWAY_API_KEY="<key>" # canonical variable read by the ai package
```

or

```sh
export JEV_PROVIDER=cloudflare # Cloudflare Workers AI hosting of Jev
export CLOUDFLARE_ACCOUNT_ID="<your Cloudflare account id>"
export CLOUDFLARE_API_TOKEN="<your Cloudflare API token>"
# JEV_CLOUDFLARE_API_TOKEN may be used as an application-specific alias for the
# token; when both are set, the alias wins.

jev-code \
"Check the current changes against the user's task" \
--task-file task.md \
--json
```

An invalid `JEV_PROVIDER` name fails immediately at startup (exit 64), not halfway through a review.

**Model selection.** `--model` / `TYPESAFE_MODEL` select the TypeSafe-direct model for the default
provider. The Vercel provider runs in the gateway's model namespace: TypeSafe-direct ids
(`jev-1.13.0`) are a different namespace and are never forwarded — an unqualified id falls back to
the configured gateway model, and a slash-qualified gateway id (`typesafe-ai/jev-preview`) is
honored. The gateway model itself is configured with `JEV_GATEWAY_MODEL` (default `typesafe-ai/jev`,
the canonical Jev id on the Vercel AI Gateway).
the canonical Jev id on the Vercel AI Gateway). The Cloudflare provider likewise runs in Cloudflare's
own model namespace, which currently exposes Jev through the always-current alias `typesafe/jev`
rather than TypeSafe's pinned versions: unqualified ids are never forwarded, and only
`typesafe/`-qualified ids pass through. The alias is configurable with `JEV_CLOUDFLARE_MODEL`
(default `typesafe/jev`).

**Zero data retention.** Evaluations can contain repository source code and diffs, so the Vercel
provider routes only to providers with zero data retention agreements
(`providerOptions.gateway.zeroDataRetention = true`) by default. Set
`JEV_GATEWAY_ZERO_DATA_RETENTION=0` only for troubleshooting.
`JEV_GATEWAY_ZERO_DATA_RETENTION=0` only for troubleshooting. The Cloudflare provider has no
equivalent routing flag: requests pass through Cloudflare infrastructure, and jev-code makes no
data-retention claim for that path — review Cloudflare's and TypeSafe's data/privacy terms before
sending private source code.

Differences worth knowing:

- TypeSafe's separate per-question confidence statistic is preserved from the gateway response
(`providerMetadata.typesafe.confidence`, Choice/Score questions). When that metadata is genuinely
unavailable, the provider falls back to a value derived from the reported distribution (the mass
of the selected choice, or the maximum level mass for score) — an approximation, not the model's
own confidence, so threshold-gated decisions can differ from TypeSafe-direct in that case.
- TypeSafe's separate per-question confidence statistic is preserved from gateway responses
(`providerMetadata.typesafe.confidence`, Choice/Score questions) and from Cloudflare's native Jev
answers (`confidence`). When that statistic is genuinely unavailable, the provider falls back to a
value derived from the reported distribution (the mass of the selected choice, or the maximum
level mass for score) — an approximation, not the model's own confidence, so threshold-gated
decisions can differ from TypeSafe-direct in that case.
- Noul/boolean answers carry probability only; TypeSafe reports no separate confidence for them.
- Usage numbers come from the gateway; when it omits them, input usage is reported as a conservative
estimate of the request size (the same estimate the input-token budget reserves), and output usage
as zero.
Cloudflare speaks Jev's native contract, so unlike Vercel it needs no boolean translation.
- Usage numbers come from the gateway or from Cloudflare; when they are omitted, input usage is
reported as a conservative estimate of the request size (the same estimate the input-token budget
reserves), and output usage as zero.

## TypeSafe

Expand Down
8 changes: 5 additions & 3 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ higher folder supplies the implementation. `test/architecture.test.ts` scans eve
| ----------- | ------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- |
| `core` | Send structured questions to Jev safely: validate answers, enforce budgets, batch, retry | npm packages, `fs`, `child_process`, the SDK; only `node:` built-ins |
| `workflows` | Product logic: gather evidence, run exact checks, ask questions, turn answers into a report | any package or Node built-in, `process.env`, the SDK |
| `adapters` | Real implementations of the ports: read-only Git, file reads, parsers, redaction, Jev providers (TypeSafe SDK, Vercel AI Gateway) | the `cli` folder |
| `adapters` | Real implementations of the ports: read-only Git, file reads, parsers, redaction, Jev providers (TypeSafe SDK, Vercel AI Gateway, Cloudflare Workers AI) | the `cli` folder |
| `cli` | Parse arguments, wire adapters into workflows, print output, choose the exit code | nothing |

`src/cli.ts` (the `jev-code` binary) and `src/index.ts` (package exports) belong to `cli`. Every other
Expand All @@ -28,9 +28,11 @@ production file must live in one of the four folders. Tests and scripts may impo
Using `check` as the example:

1. **cli** parses the natural-language request and flags, reads `JEV_PROVIDER`, `TYPESAFE_API_KEY`,
`AI_GATEWAY_API_KEY` and `TYPESAFE_MODEL` through `adapters/config.ts`, and builds the dependencies
`AI_GATEWAY_API_KEY`, `CLOUDFLARE_ACCOUNT_ID`, `CLOUDFLARE_API_TOKEN` and `TYPESAFE_MODEL`
through `adapters/config.ts`, and builds the dependencies
in `adapters/dependencies.ts`. The provider factory selects `TypeSafeJevProvider` (direct API,
default) or `VercelJevProvider` (Vercel AI Gateway); unknown provider names fail at startup.
default), `VercelJevProvider` (Vercel AI Gateway), or `CloudflareJevProvider` (Cloudflare Workers
AI REST run endpoint); unknown provider names fail at startup.
2. **routing** (`cli/router.ts`) receives the redacted request plus deterministic context: diff presence,
input shape, available capabilities, and supplied option names. One validated choice selects `find`,
`check`, `triage_failures`, `triage_comments`, or `cannot_tell`. Fixed confidence and capability gates turn
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"smoke": "node scripts/smoke-cli.ts",
"smoke:real": "node scripts/smoke-real.ts",
"smoke:vercel": "node scripts/smoke-vercel.ts",
"smoke:cloudflare": "node scripts/smoke-cloudflare.ts",
"check": "npm run lint && npm run typecheck && npm test && npm run build && npm run smoke",
"check:package": "npm run build && node scripts/release.ts manifest && node scripts/release.ts pack --dry-run"
},
Expand Down
48 changes: 48 additions & 0 deletions scripts/smoke-cloudflare.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Optional live smoke test against Jev through Cloudflare Workers AI. Requires
* JEV_SMOKE=1, CLOUDFLARE_ACCOUNT_ID, and a Cloudflare API token
* (CLOUDFLARE_API_TOKEN or JEV_CLOUDFLARE_API_TOKEN) in the environment and
* performs one minimal real evaluation. Skips cleanly without credentials, so
* it never becomes required for normal CI.
*/
import { CLOUDFLARE_MODEL, createCloudflareAdapter } from "../src/adapters/cloudflare-jev.ts";
import { checkEnvironment } from "./smoke-env.ts";

const env = process.env;
const verdict = checkEnvironment(env, { provider: "cloudflare" });
if (verdict.skip) {
console.log(`smoke:cloudflare skipped: ${verdict.skip}`);
process.exit(0);
}

const adapter = createCloudflareAdapter(env);
const started = Date.now();
const response = (await adapter.ask(
{
state: { change: "renamed variable base to amount in price()" },
questions: {
renamed: { type: "noul", instructions: "Does the change rename a variable?" },
severity: {
type: "choice",
instructions: "How severe is this change?",
criteria: { cosmetic: "rename only", behavioral: "changes behavior" },
},
},
model: CLOUDFLARE_MODEL,
},
{ timeoutMs: 30_000 },
)) as {
model: string;
answers: Record<string, Record<string, unknown>>;
usage: { input_tokens: number; output_tokens: number };
};

const answers = response.answers;
if (!answers.renamed || !answers.severity) throw new Error("smoke:cloudflare: missing answers");
console.log(
`smoke:cloudflare ok: model=${response.model} renamed=${(answers.renamed as { noul: number }).noul} ` +
`severity=${(answers.severity as { choice: string }).choice} ` +
`confidence=${(answers.severity as { confidence: number }).confidence} ` +
`tokens=${response.usage.input_tokens}/${response.usage.output_tokens} ` +
`latencyMs=${Date.now() - started}`,
);
36 changes: 26 additions & 10 deletions scripts/smoke-env.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,40 @@
/** Shared skip logic for live smoke scripts. */
/**
* Shared skip logic for live smoke scripts.
*/
export interface SkipVerdict {
skip: string | null;
}

export type SmokeProvider = "typesafe" | "vercel" | "cloudflare";

/** The credential variable each provider's live smoke needs. */
const PROVIDER_KEYS: Record<SmokeProvider, { names: string[]; label: string; extra?: string[] }> = {
typesafe: { names: ["TYPESAFE_API_KEY"], label: "TYPESAFE_API_KEY" },
vercel: { names: ["AI_GATEWAY_API_KEY"], label: "AI_GATEWAY_API_KEY" },
cloudflare: {
names: ["JEV_CLOUDFLARE_API_TOKEN", "CLOUDFLARE_API_TOKEN"],
label: "CLOUDFLARE_API_TOKEN",
extra: ["CLOUDFLARE_ACCOUNT_ID"],
},
};

/**
* Decide whether a live smoke test should run: it must be explicitly requested
* and the matching credential must be present. Returns the skip reason or null.
* and the matching credential(s) must be present. Returns the skip reason or null.
*/
export function checkEnvironment(
env: NodeJS.ProcessEnv,
options: { provider: "typesafe" | "vercel" },
): SkipVerdict {
export function checkEnvironment(env: NodeJS.ProcessEnv, options: { provider: SmokeProvider }): SkipVerdict {
if (!/^(?:1|true|yes)$/i.test(env.JEV_SMOKE ?? "")) {
return { skip: "set JEV_SMOKE=1 to run live smoke tests" };
}
const key = options.provider === "vercel" ? env.AI_GATEWAY_API_KEY?.trim() : env.TYPESAFE_API_KEY?.trim();
const needs = PROVIDER_KEYS[options.provider];
const key = needs.names.some((name) => env[name]?.trim());
if (!key) {
return {
skip: `${options.provider === "vercel" ? "AI_GATEWAY_API_KEY" : "TYPESAFE_API_KEY"} is not set`,
};
return { skip: `${needs.label} is not set` };
}
for (const extra of needs.extra ?? []) {
if (!env[extra]?.trim()) {
return { skip: `${extra} is not set` };
}
}
return { skip: null };
}
Loading