lake-gate 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -21
- package/package.json +42 -10
- package/src/action.js +47 -1
- package/src/cli.js +33 -5
- package/src/config-core.js +38 -0
- package/src/config.js +2 -44
- package/src/estimate.js +33 -45
- package/src/github.js +73 -13
- package/src/hook.js +12 -4
- package/src/index.js +1 -0
- package/src/init.js +23 -3
- package/src/mcp.js +312 -0
- package/src/meter-core.js +535 -0
- package/src/models.js +193 -0
- package/src/plan.js +2 -2
- package/src/policy.js +12 -4
- package/src/review.js +319 -0
- package/src/sha256.js +37 -0
- package/src/store.js +1 -1
- package/src/sync.js +8 -4
- package/src/ui-server.js +81 -0
- package/src/workspace.js +104 -0
- package/ui/app.css +536 -0
- package/ui/app.js +836 -0
- package/ui/btn/approve.svg +5 -0
- package/ui/btn/changes.svg +5 -0
- package/ui/btn/open.svg +5 -0
- package/ui/data.js +95 -0
- package/ui/demo.js +262 -0
- package/ui/index.html +55 -0
- package/ui/inter.woff2 +0 -0
- package/ui/logo-mark.svg +1 -0
- package/ui/md.js +82 -0
package/README.md
CHANGED
|
@@ -2,30 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
**Your agent writes the plan. A teammate approves that exact version. Then the agent builds.**
|
|
4
4
|
|
|
5
|
-
lake-gate is a small, free, open-source plan gate for teams using Claude Code
|
|
5
|
+
lake-gate is a small, free, open-source plan gate for teams using Claude Code and Cursor (other agents work through the CLI). It runs in your repo and on GitHub. There is no Lake server, no account and no telemetry.
|
|
6
6
|
|
|
7
7
|
- **Plan export.** When Claude Code leaves plan mode, the plan is saved to `.lake/plans/<id>.md` with a complexity rating, a recommended model per step and a cost range.
|
|
8
8
|
- **Version-bound approval.** A teammate approves on the PR with `/lake approve <id>@<version>`. Edit one word of the plan and the approval no longer applies.
|
|
9
9
|
- **Local gate.** A Claude Code `PreToolUse` hook denies file edits and non-read-only shell commands until the active plan's current version is approved. Reading and exploring stay free.
|
|
10
10
|
- **PR check.** A GitHub Action sets the `lake/plan-approval` status. Make it required and unapproved plans can't merge.
|
|
11
|
-
- **
|
|
11
|
+
- **Review app.** Rendered plans, comments on exact lines, review rounds per plan version with a diff between them, verdicts and an activity timeline. Approve or request changes in one click. Run it locally with `npx lake-gate ui`, or use the hosted static app (it talks to the GitHub API straight from your browser). [Live demo with a made-up team](https://getlake.github.io/lake-gate/app/#/demo).
|
|
12
|
+
- **Approve from where you already are.** The Lake review app, GitHub's own **Approve** button, or your agent chat (MCP server for Claude Code and Cursor). They all write to the same place, the PR, so there is one source of truth.
|
|
13
|
+
- **Model and cost per step.** Every plan shows which model runs each step and what that costs, with the same estimator and price table as [lake-meter](https://getlake.github.io/lake-meter/). Declare the model in the plan (`Model: Opus 5.5`, or `(model: haiku)` on a step). Reviewers suggest a cheaper model, a dropped step or a cap, and the author accepts it in one click, which saves a new plan version.
|
|
14
|
+
- **Budget approval (optional).** Above `budget.approverAbove` dollars, one of `budget.approvers` must also approve that exact version. It shows in the app, the PR check and the MCP tools.
|
|
15
|
+
- **Small plans pass on their own.** Tiny, low-complexity plans are auto-approved by default, and quick fixes without a plan aren't gated at all. Set `autoApprove.mode` to `shadow` or `off` to be stricter.
|
|
12
16
|
|
|
13
17
|
## Install (about 10 minutes)
|
|
14
18
|
|
|
15
19
|
```bash
|
|
16
20
|
cd your-repo
|
|
17
|
-
npx lake-gate init # writes .lake/,
|
|
21
|
+
npx lake-gate init # writes .lake/, the Claude Code hook, the GitHub workflow, and MCP config for Claude Code + Cursor
|
|
18
22
|
npm i -D lake-gate # optional for JS repos: faster hook than npx
|
|
19
|
-
git add .lake .claude .github && git commit -m "Add lake-gate" && git push
|
|
23
|
+
git add .lake .claude .github .mcp.json .cursor && git commit -m "Add lake-gate" && git push
|
|
24
|
+
npx lake-gate ui # the review app on localhost
|
|
20
25
|
```
|
|
21
26
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
```bash
|
|
25
|
-
npm i -g github:getlake/lake-gate
|
|
26
|
-
# then in your repo:
|
|
27
|
-
lake-gate init
|
|
28
|
-
```
|
|
27
|
+
Trying it alone first? `npx lake-gate init --try` sets up a local-only trial where you can approve your own plans with `npx lake-gate approve`. Nothing is posted anywhere.
|
|
29
28
|
|
|
30
29
|
Then in GitHub: **Settings → Branches → branch protection → Require status checks → `lake/plan-approval`** (the check appears after the first PR runs).
|
|
31
30
|
|
|
@@ -33,7 +32,7 @@ Requirements: Node 18.17+, git, a GitHub repo. macOS/Linux shells for the hook (
|
|
|
33
32
|
|
|
34
33
|
## The flow
|
|
35
34
|
|
|
36
|
-
1. **Plan.** In Claude Code, use plan mode as usual. When the plan is accepted, the hook saves it to `.lake/plans/add-webhook-retries.md` and tells you its version and estimate.
|
|
35
|
+
1. **Plan.** In Claude Code, use plan mode as usual. When the plan is accepted, the hook saves it to `.lake/plans/add-webhook-retries.md` and tells you its version and estimate. In Cursor, ask the agent to call `lake_request_review`. Any other agent: save the plan as markdown and run `npx lake-gate plan plan.md`.
|
|
37
36
|
2. **Open a PR with the plan first** (a draft PR is fine). The Action posts one summary comment with the exact approve line.
|
|
38
37
|
3. **A teammate approves** with a PR comment or review: `/lake approve add-webhook-retries@86eab4d0`. The PR author and bots can't approve. Read-only users can't approve.
|
|
39
38
|
4. **Sync and build.** `npx lake-gate sync` pulls approvals into your local checkout (uses `GITHUB_TOKEN` or `gh auth token`). The agent can now edit. The code lands in the same PR and the check is green.
|
|
@@ -47,27 +46,63 @@ Commands on the PR, one per line:
|
|
|
47
46
|
| `/lake reject <id>@<version>` | Request changes. Blocks until the same person approves |
|
|
48
47
|
| `/lake revoke <id>` | Withdraw your approval |
|
|
49
48
|
|
|
49
|
+
## Reviewing: the app, GitHub, and your agent
|
|
50
|
+
|
|
51
|
+
Everything is stored on the PR as normal comments and reviews. There's no database and nothing new to host. The review app, the Action, `lake-gate sync` and the MCP server all read the same comments.
|
|
52
|
+
|
|
53
|
+
**Review app.** `npx lake-gate ui` opens `http://127.0.0.1:4848`. It uses your `gh` login (or `GITHUB_TOKEN`) through a small local proxy: the token never reaches the page, the proxy only talks to this repo, and it only writes PR comments. It also shows plans you haven't pushed yet, as drafts, with their local history. The hosted copy at `getlake.github.io/lake-gate/app/` is the same static app. It asks for a fine-grained token (Pull requests: read & write, Contents: read) and keeps it in your browser.
|
|
54
|
+
|
|
55
|
+
- Select text in a plan, or click a line, to comment on it (`c`). Threads reply and resolve.
|
|
56
|
+
- Each pushed version of the plan is a **round**. Comments stay attached to the round they were made on, and move forward to the current text when the quoted line still exists.
|
|
57
|
+
- **Changes** shows the diff between any two rounds. **Activity** is the timeline: who commented, approved or requested changes, on which version, and from where.
|
|
58
|
+
- `a` approve, `r` request changes, `j`/`k` next/previous thread, `?` for all shortcuts.
|
|
59
|
+
|
|
60
|
+
**GitHub.** Two ways, both counted by the same policy:
|
|
61
|
+
|
|
62
|
+
1. **GitHub's native review.** Approve or Request changes on the PR with GitHub's own buttons. It counts for the plan version at the reviewed commit (turn it off with `nativeReviews: false`). Line comments on the plan file show up as threads in the app.
|
|
63
|
+
2. **Buttons in the summary comment.** *Approve*, *Request changes* and *Open review* open the review app on the right plan with the approve sheet ready (`reviewUrl`, default: the hosted app).
|
|
64
|
+
|
|
65
|
+
The typed `/lake approve <id>@<version>` line still works everywhere.
|
|
66
|
+
|
|
67
|
+
**Your agent (MCP).** `init` registers `npx lake-gate mcp` in `.mcp.json` (Claude Code) and `.cursor/mcp.json` (Cursor). Tools:
|
|
68
|
+
|
|
69
|
+
| Tool | What it does |
|
|
70
|
+
|---|---|
|
|
71
|
+
| `lake_request_review` | Save the plan (with model and cost), optionally commit and push only the plan file, and return the review link |
|
|
72
|
+
| `lake_review_status` | Status, verdicts, open threads with line numbers, reviewer suggestions, budget approval, and the model/cost view with Lake's suggestions. Works before a PR exists. `wait_seconds` (up to 240) waits for new feedback |
|
|
73
|
+
| `lake_submit_revision` | Save a revised plan and resolve the threads it addresses. Or apply a suggestion in one step: `thread_id`, `suggestion_id` or `model` |
|
|
74
|
+
| `lake_review` | For reviewers: `approve`, `request_changes`, `comment` (on lines), `reply`, or `suggest` a cheaper model or a cap. Approvals need the exact version and say "via Claude Code (MCP)" |
|
|
75
|
+
|
|
76
|
+
The PR author can't approve their own plan from any surface. An approval from an agent chat is posted under the human's GitHub account, so only use it when that person asked for it.
|
|
77
|
+
|
|
78
|
+
**How it's stored.** Comments from the app and the MCP server are PR comments with a small hidden marker, for example `<!-- lake:c {"p":"plan-id","v":"86eab4d0","t":"t1","a":{"s":12,"e":14,"q":"quoted text"}} -->`. Verdicts are the usual `/lake approve|reject` lines, so older versions of lake-gate and humans read them the same way.
|
|
79
|
+
|
|
50
80
|
## What the estimate looks like
|
|
51
81
|
|
|
52
82
|
```
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
|
56
|
-
|
|
|
83
|
+
Planned model Opus 5.5: $2.53–$9.69 · Lake mix (cheapest model that fits each step): $2.31–$8.93
|
|
84
|
+
|
|
85
|
+
| # | Step | Complexity | Planned | Recommended | Est. cost |
|
|
86
|
+
| 1 | Bounded retry queue with backoff | medium | Opus 5.5 | Sonnet 5.5 | $0.38–$1.28 |
|
|
87
|
+
| 2 | Database migration: retry_count column | high | Opus 5.5 | Opus 5.5 | $2.10–$8.22 |
|
|
88
|
+
| 3 | Fix typo in README | low | Opus 5.5 | Haiku 5.5 | $0.046–$0.18|
|
|
57
89
|
```
|
|
58
90
|
|
|
59
|
-
It's a rough heuristic: keywords
|
|
91
|
+
It's a rough heuristic, the same one lake-meter uses: complexity from keywords, token bands per level, public API list prices. It isn't a quote. On a subscription plan you spend quota, not these dollars. Override prices with `catalog` in `.lake/config.json`.
|
|
60
92
|
|
|
61
93
|
## CLI
|
|
62
94
|
|
|
63
95
|
```
|
|
64
|
-
lake-gate init [--
|
|
96
|
+
lake-gate init [--try] [--force] set up the repo (--try: local-only trial, self-approval allowed)
|
|
97
|
+
lake-gate approve [id] approve your own plan (trial mode only)
|
|
65
98
|
lake-gate plan <file.md|-> [--id name] save a plan with an estimate and make it active
|
|
66
99
|
lake-gate estimate <file.md|-> print the estimate only
|
|
67
100
|
lake-gate status plans, versions, approval state
|
|
68
101
|
lake-gate sync [--pr N] pull approvals from the PR
|
|
69
102
|
lake-gate check [--plan id] exit 0 only if the active plan's current version is approved
|
|
70
103
|
lake-gate use <id> switch the active plan (the hook blocks agents from doing this)
|
|
104
|
+
lake-gate ui [--port 4848] [--no-open] the review app on localhost
|
|
105
|
+
lake-gate mcp MCP server (stdio) for Claude Code / Cursor
|
|
71
106
|
lake-gate hook claude the Claude Code PreToolUse hook (stdin JSON)
|
|
72
107
|
```
|
|
73
108
|
|
|
@@ -83,8 +118,12 @@ lake-gate hook claude the Claude Code PreToolUse hook (stdin
|
|
|
83
118
|
| `requirePlan` | `"warn"` | PR changes code without a plan: `off`, `warn`, `fail` |
|
|
84
119
|
| `localGate` | `"block"` | Hook behaviour: `block` (deny), `ask` (Claude Code prompts you), `off` |
|
|
85
120
|
| `readOnlyBash` | git status/log/diff, ls, cat, rg... | Bash commands allowed before approval (regexes; chained commands are not) |
|
|
86
|
-
| `autoApprove` | `{mode:"
|
|
87
|
-
| `
|
|
121
|
+
| `autoApprove` | `{mode:"on", maxUsd:1.5, maxSteps:3, maxComplexity:"low"}` | Tiny plans pass without a human. `off`, `shadow` (only report), or `on` |
|
|
122
|
+
| `budget` | `{approverAbove:null, approvers:[]}` | Above this many dollars (upper estimate of the planned model), one of `approvers` (logins or `@org/team`) must also approve |
|
|
123
|
+
| `gateWithoutPlan` | `false` | `true` blocks edits even when there's no plan |
|
|
124
|
+
| `provider`, `catalog` | `anthropic`, lake-meter prices | Same shape as lake-meter's price catalog |
|
|
125
|
+
| `nativeReviews` | `true` | GitHub's own Approve / Request changes count for the plan version at the reviewed commit |
|
|
126
|
+
| `reviewUrl` | hosted review app | Where the summary comment's buttons point. `""` hides them |
|
|
88
127
|
|
|
89
128
|
The PR check reads the config from the **base branch**, so a PR can't loosen its own policy.
|
|
90
129
|
|
|
@@ -99,12 +138,15 @@ The PR check reads the config from the **base branch**, so a PR can't loosen its
|
|
|
99
138
|
|
|
100
139
|
## Privacy
|
|
101
140
|
|
|
102
|
-
|
|
141
|
+
The CLI has no telemetry and no analytics. The only network calls are to the GitHub API: `sync`, `ui` and `mcp` read and write your PR, and the Action runs inside your GitHub. Plans stay in your repo. The hosted review app and landing page count anonymous page views with GoatCounter. Your token and plan content go only to GitHub. The local `lake-gate ui` has no analytics at all.
|
|
103
142
|
|
|
104
143
|
## Development
|
|
105
144
|
|
|
106
145
|
```bash
|
|
107
146
|
npm test # unit + end-to-end tests (temp git repos, simulated hook payloads, mocked GitHub API)
|
|
147
|
+
npm run build:ui # copies ui/ + the browser-safe core into landing/app (the Pages workflow does this)
|
|
148
|
+
node scripts/shots.cjs # screenshots of a running `lake-gate ui` into ui-shots/ (needs playwright + Chrome)
|
|
149
|
+
node scripts/ui-e2e.cjs # browser test: local server + fake GitHub, approve in the UI, check the posted comment
|
|
108
150
|
./scripts/demo.sh # packs the npm tarball, installs it in a throwaway repo, runs the whole flow
|
|
109
151
|
```
|
|
110
152
|
|
package/package.json
CHANGED
|
@@ -1,18 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lake-gate",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Version-bound team plan approval for AI coding agents
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Version-bound team plan approval for AI coding agents: review UI, Claude Code hook, MCP server, GitHub Action. No backend, no telemetry.",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"bin": {
|
|
6
|
+
"bin": {
|
|
7
|
+
"lake-gate": "bin/lake-gate.js"
|
|
8
|
+
},
|
|
7
9
|
"main": "src/index.js",
|
|
8
|
-
"exports": {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
|
|
10
|
+
"exports": {
|
|
11
|
+
".": "./src/index.js"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"bin",
|
|
15
|
+
"src",
|
|
16
|
+
"ui",
|
|
17
|
+
"templates",
|
|
18
|
+
"action.yml",
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE"
|
|
21
|
+
],
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=18.17"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"test": "node --test test/*.test.js",
|
|
27
|
+
"build:ui": "node scripts/build-ui.js"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"claude-code",
|
|
31
|
+
"hooks",
|
|
32
|
+
"ai-agents",
|
|
33
|
+
"plan-review",
|
|
34
|
+
"github-action",
|
|
35
|
+
"approval",
|
|
36
|
+
"cursor",
|
|
37
|
+
"codex",
|
|
38
|
+
"cost"
|
|
39
|
+
],
|
|
13
40
|
"license": "MIT",
|
|
14
41
|
"author": "Lake research team",
|
|
15
|
-
"repository": {
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "git+https://github.com/getlake/lake-gate.git"
|
|
45
|
+
},
|
|
16
46
|
"homepage": "https://github.com/getlake/lake-gate#readme",
|
|
17
|
-
"bugs": {
|
|
47
|
+
"bugs": {
|
|
48
|
+
"url": "https://github.com/getlake/lake-gate/issues"
|
|
49
|
+
}
|
|
18
50
|
}
|
package/src/action.js
CHANGED
|
@@ -2,21 +2,67 @@
|
|
|
2
2
|
// GitHub Action entry point. Uses only the REST API with the workflow's GITHUB_TOKEN; no checkout needed.
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import { client, evaluatePr, publish, renderSummary } from './github.js';
|
|
5
|
+
import { isPassing } from './policy.js';
|
|
6
|
+
import { verdictBody, encodeMarker } from './review.js';
|
|
7
|
+
|
|
8
|
+
export const CHECK_NAME = 'Lake plan review';
|
|
5
9
|
|
|
6
10
|
export function prNumberFromEvent(name, payload) {
|
|
7
11
|
if (payload.pull_request) return payload.pull_request.number;
|
|
8
12
|
if (name === 'issue_comment' && payload.issue && payload.issue.pull_request) return payload.issue.number;
|
|
13
|
+
if (name === 'check_run' && payload.check_run?.pull_requests?.length) return payload.check_run.pull_requests[0].number;
|
|
9
14
|
return null;
|
|
10
15
|
}
|
|
11
16
|
|
|
17
|
+
// Experimental (config.checkButtons): one-click buttons on a check run. A click arrives as a
|
|
18
|
+
// check_run "requested_action" event; the Action relays it as a bot comment that names the clicker,
|
|
19
|
+
// after checking the clicker has write access. Not yet verified against real GitHub.
|
|
20
|
+
export function checkActions(ev) {
|
|
21
|
+
const pending = ev.results.filter((r) => !isPassing(r));
|
|
22
|
+
if (pending.length === 1) {
|
|
23
|
+
const r = pending[0];
|
|
24
|
+
return [{ label: 'Approve plan', description: `Approve ${r.id}@${r.short}`.slice(0, 40), identifier: `approve:${r.short}` },
|
|
25
|
+
{ label: 'Request changes', description: `Block ${r.id}@${r.short}`.slice(0, 40), identifier: `reject:${r.short}` }];
|
|
26
|
+
}
|
|
27
|
+
return pending.slice(0, 3).map((r) => ({ label: `Approve ${r.id}`.slice(0, 20), description: `Approve ${r.id}@${r.short}`.slice(0, 40), identifier: `approve:${r.short}` }));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function publishCheck(gh, ev) {
|
|
31
|
+
const actions = checkActions(ev);
|
|
32
|
+
await gh.req('POST', '/check-runs', { name: CHECK_NAME, head_sha: ev.pr.head.sha, status: 'completed', conclusion: actions.length ? 'action_required' : 'success',
|
|
33
|
+
output: { title: ev.description.slice(0, 120), summary: renderSummary(ev).slice(0, 60000) }, ...(actions.length ? { actions } : {}) });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const WRITE = new Set(['admin', 'maintain', 'write']);
|
|
37
|
+
export async function relayCheckAction(gh, payload, ev) {
|
|
38
|
+
const [action, short] = String(payload.requested_action?.identifier || '').split(':');
|
|
39
|
+
const login = payload.sender?.login;
|
|
40
|
+
if (!['approve', 'reject'].includes(action) || !short || !login || payload.sender.type === 'Bot') return { relayed: false, reason: 'bad request' };
|
|
41
|
+
if (payload.check_run?.head_sha && payload.check_run.head_sha !== ev.pr.head.sha) return { relayed: false, reason: 'stale check run (PR has new commits)' };
|
|
42
|
+
const plan = ev.results.find((r) => r.short === short);
|
|
43
|
+
if (!plan) return { relayed: false, reason: `no plan at version ${short}` };
|
|
44
|
+
const perm = await gh.req('GET', `/collaborators/${encodeURIComponent(login)}/permission`);
|
|
45
|
+
if (!perm || !WRITE.has(perm.permission)) return { relayed: false, reason: `@${login} lacks write access` };
|
|
46
|
+
const body = verdictBody({ action, planId: plan.id, version: plan.digest, text: `${action === 'approve' ? 'Approved' : 'Changes requested'} by @${login} with the check-run button.`, via: 'GitHub check button' })
|
|
47
|
+
+ '\n' + encodeMarker('proxy', { by: login, assoc: 'COLLABORATOR' });
|
|
48
|
+
await gh.req('POST', `/issues/${ev.pr.number}/comments`, { body });
|
|
49
|
+
return { relayed: true, login, action, plan: plan.id };
|
|
50
|
+
}
|
|
51
|
+
|
|
12
52
|
export async function runAction(env = process.env, fetchImpl) {
|
|
13
53
|
const payload = JSON.parse(fs.readFileSync(env.GITHUB_EVENT_PATH, 'utf8'));
|
|
14
54
|
const number = prNumberFromEvent(env.GITHUB_EVENT_NAME, payload);
|
|
15
55
|
if (!number) { console.log('lake-gate: not a pull request event, nothing to do.'); return null; }
|
|
16
56
|
const token = env.INPUT_TOKEN || env.GITHUB_TOKEN;
|
|
17
57
|
const gh = client({ token, repo: env.GITHUB_REPOSITORY, api: env.GITHUB_API_URL || 'https://api.github.com', fetchImpl });
|
|
18
|
-
|
|
58
|
+
let ev = await evaluatePr(gh, number);
|
|
59
|
+
if (env.GITHUB_EVENT_NAME === 'check_run' && payload.action === 'requested_action') {
|
|
60
|
+
const r = await relayCheckAction(gh, payload, ev);
|
|
61
|
+
console.log(`lake-gate: check button: ${r.relayed ? `${r.action} ${r.plan} by @${r.login}` : `ignored (${r.reason})`}`);
|
|
62
|
+
if (r.relayed) ev = await evaluatePr(gh, number);
|
|
63
|
+
}
|
|
19
64
|
await publish(gh, ev, { comment: (env.INPUT_COMMENT || 'true') !== 'false' });
|
|
65
|
+
if (ev.config.checkButtons && ev.results.length) await publishCheck(gh, ev).catch((e) => console.log(`lake-gate: could not create check run buttons: ${e.message}`));
|
|
20
66
|
const md = renderSummary(ev);
|
|
21
67
|
if (env.GITHUB_STEP_SUMMARY) fs.appendFileSync(env.GITHUB_STEP_SUMMARY, md + '\n');
|
|
22
68
|
if (env.GITHUB_OUTPUT) fs.appendFileSync(env.GITHUB_OUTPUT, `state=${ev.state}\n`);
|
package/src/cli.js
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
|
-
import { repoRoot, exportPlan, loadPlan, listPlans, getState, setState, localStatus } from './store.js';
|
|
2
|
+
import { repoRoot, exportPlan, loadPlan, listPlans, getState, setState, localStatus, getApprovals, setApprovals } from './store.js';
|
|
3
3
|
import { loadConfig } from './config.js';
|
|
4
4
|
import { estimatePlan, renderEstimate, range } from './estimate.js';
|
|
5
5
|
import { handleClaudePreToolUse } from './hook.js';
|
|
6
6
|
import { syncFromGitHub, applyEvents } from './sync.js';
|
|
7
7
|
import { init, ACTION_REF } from './init.js';
|
|
8
|
+
import { startUi } from './ui-server.js';
|
|
9
|
+
import { serve as serveMcp } from './mcp.js';
|
|
8
10
|
|
|
9
11
|
const HELP = `lake-gate: version-bound team approval for AI coding agent plans
|
|
10
12
|
|
|
11
13
|
Usage:
|
|
12
|
-
lake-gate init [--
|
|
14
|
+
lake-gate init [--try] [--force] Set up .lake/, the Claude Code hook, MCP and the GitHub workflow
|
|
15
|
+
--try: solo trial, approve your own plans locally
|
|
16
|
+
lake-gate approve [id] Trial mode only: approve the active plan locally (never counts on the PR)
|
|
13
17
|
lake-gate plan <file.md|-> [--id name] Save a plan (any agent) to .lake/plans/ with an estimate; make it active
|
|
14
18
|
lake-gate estimate <file.md|-> Print complexity, model per step and cost range
|
|
15
19
|
lake-gate status Active plan, version and approval state
|
|
@@ -17,6 +21,8 @@ Usage:
|
|
|
17
21
|
lake-gate check [--plan id] Exit 0 if the active plan's current version is approved (pre-run check)
|
|
18
22
|
lake-gate use <id> Set the active plan (human only; the hook blocks agents)
|
|
19
23
|
lake-gate hook claude Claude Code PreToolUse hook (reads JSON on stdin)
|
|
24
|
+
lake-gate ui [--port 4848] [--no-open] Review UI on localhost: plans, inline comments, rounds, one-click approve
|
|
25
|
+
lake-gate mcp MCP server (stdio) for Claude Code / Cursor: request review, wait, revise, approve
|
|
20
26
|
|
|
21
27
|
No telemetry. No backend. Docs: https://github.com/getlake/lake-gate`;
|
|
22
28
|
|
|
@@ -26,7 +32,8 @@ const readInput = (f) => (f === '-' || !f ? fs.readFileSync(0, 'utf8') : fs.read
|
|
|
26
32
|
function describe(root, plan) {
|
|
27
33
|
const st = localStatus(root, plan);
|
|
28
34
|
const extra = st.state === 'pending' ? (st.stale ? ' (approval is for an older version)' : '') + `\n approve on the PR: /lake approve ${plan.id}@${plan.short}` : st.approvers?.length ? ` by ${st.approvers.map((a) => '@' + a).join(', ')}` : '';
|
|
29
|
-
|
|
35
|
+
const e = st.estimate;
|
|
36
|
+
return `${plan.id} v${plan.short} ${e.complexity} est. ${range(e.declared ? e.plannedUsd : e.usd)}${e.model ? ` on ${e.model.name}` : ''} ${st.state}${st.trial ? ' (trial, local only)' : ''}${extra}`;
|
|
30
37
|
}
|
|
31
38
|
|
|
32
39
|
export async function main(argv = process.argv.slice(2), io = { out: (s) => process.stdout.write(s + '\n'), err: (s) => process.stderr.write(s + '\n') }) {
|
|
@@ -34,8 +41,10 @@ export async function main(argv = process.argv.slice(2), io = { out: (s) => proc
|
|
|
34
41
|
const root = repoRoot();
|
|
35
42
|
switch (cmd) {
|
|
36
43
|
case 'init': {
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
const trial = args.includes('--try');
|
|
45
|
+
for (const l of init(root, { actionRef: flag(args, '--action-ref') || ACTION_REF, force: args.includes('--force'), trial })) io.out(l);
|
|
46
|
+
if (trial) io.out('\nTrial mode. Try the loop in 2 minutes:\n 1. In Claude Code, plan a task in plan mode and accept the plan. Edits are now gated.\n 2. npx lake-gate approve (you approve your own plan, locally only)\n 3. The agent continues. Edit the plan and it is gated again.\nFor your team: remove "try" from .lake/config.json, then:');
|
|
47
|
+
io.out(`${trial ? '' : '\nNext:\n'} git add .lake .claude .github .mcp.json .cursor && git commit -m "Add lake-gate" && git push\n Then review plans with: npx lake-gate ui (or in GitHub with Review changes → Approve)\n Optional: require the "lake/plan-approval" status check in branch protection.`);
|
|
39
48
|
return 0;
|
|
40
49
|
}
|
|
41
50
|
case 'plan': {
|
|
@@ -76,6 +85,17 @@ export async function main(argv = process.argv.slice(2), io = { out: (s) => proc
|
|
|
76
85
|
(ok ? io.out : io.err)(describe(root, plan));
|
|
77
86
|
return ok ? 0 : 1;
|
|
78
87
|
}
|
|
88
|
+
case 'approve': {
|
|
89
|
+
const cfg = loadConfig(root);
|
|
90
|
+
if (!cfg.try) { io.err('lake-gate approve works in trial mode only (npx lake-gate init --try). On a team, a teammate approves on the PR or in `npx lake-gate ui`.'); return 1; }
|
|
91
|
+
const id = args[0] || getState(root).active; const plan = id && loadPlan(root, id);
|
|
92
|
+
if (!plan) { io.err('lake-gate: no plan to approve.'); return 1; }
|
|
93
|
+
const store = getApprovals(root);
|
|
94
|
+
store[plan.id] = { digest: plan.digest, state: 'approved', approvers: ['you (trial)'], trial: true, syncedAt: new Date().toISOString() };
|
|
95
|
+
setApprovals(root, store);
|
|
96
|
+
io.out(`Approved ${plan.id} v${plan.short} locally (trial self-approval, does not count on the PR). The agent can build this version.`);
|
|
97
|
+
return 0;
|
|
98
|
+
}
|
|
79
99
|
case 'use': {
|
|
80
100
|
if (!args[0] || !loadPlan(root, args[0])) { io.err(`No plan named ${args[0]}`); return 1; }
|
|
81
101
|
const st = getState(root); st.active = args[0]; setState(root, st);
|
|
@@ -89,6 +109,14 @@ export async function main(argv = process.argv.slice(2), io = { out: (s) => proc
|
|
|
89
109
|
if (res) io.out(JSON.stringify(res));
|
|
90
110
|
return 0;
|
|
91
111
|
}
|
|
112
|
+
case 'ui': {
|
|
113
|
+
const r = await startUi({ root, port: Number(flag(args, '--port') || 4848), open: !args.includes('--no-open') });
|
|
114
|
+
io.out(`Lake review UI: ${r.url}`);
|
|
115
|
+
io.out(r.repo ? `Repo ${r.repo}. ${r.hasToken ? 'Posting as your GitHub login (token stays on this machine).' : 'No GitHub token found: read-only for public repos. Run `gh auth login` to post.'}` : 'No GitHub remote: showing local plans only.');
|
|
116
|
+
io.out('Ctrl+C to stop.');
|
|
117
|
+
return 0;
|
|
118
|
+
}
|
|
119
|
+
case 'mcp': { await serveMcp(); return 0; }
|
|
92
120
|
case undefined: case 'help': case '--help': case '-h': io.out(HELP); return 0;
|
|
93
121
|
case '--version': case '-v': io.out(JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url))).version); return 0;
|
|
94
122
|
default: io.err(`Unknown command: ${cmd}\n\n${HELP}`); return 1;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Browser-safe part of the config (no fs). config.js adds loadConfig for Node.
|
|
2
|
+
export const DEFAULT_CONFIG = {
|
|
3
|
+
requiredApprovals: 1,
|
|
4
|
+
allowedAssociations: ['OWNER', 'MEMBER', 'COLLABORATOR'],
|
|
5
|
+
ignoreLogins: [],
|
|
6
|
+
requirePlan: 'warn', // PR check when code changes without a plan: "off" | "warn" | "fail"
|
|
7
|
+
gateWithoutPlan: false, // true: block agent edits until there is a plan at all (strict teams)
|
|
8
|
+
try: false, // trial mode (`init --try`): `lake-gate approve` self-approves locally; never counts on the PR
|
|
9
|
+
localGate: 'block', // Claude Code hook: "block" | "ask" | "off"
|
|
10
|
+
gatedTools: ['Edit', 'Write', 'MultiEdit', 'NotebookEdit', 'Bash'],
|
|
11
|
+
readOnlyBash: [
|
|
12
|
+
'^\\s*(ls|pwd|cat|head|tail|wc|rg|grep|find|tree|file|stat|which|echo|env|date|du|df)(\\s|$)',
|
|
13
|
+
'^\\s*git\\s+(status|log|diff|show|branch|remote|rev-parse|ls-files|blame|fetch)(\\s|$)',
|
|
14
|
+
'^\\s*(npx\\s+(-y\\s+)?)?lake-gate(@\\S+)?\\s+(status|estimate|check|sync|plan|help)(\\s|$)',
|
|
15
|
+
],
|
|
16
|
+
nativeReviews: true, // GitHub "Review changes → Approve / Request changes" counts for the plan version at the reviewed commit
|
|
17
|
+
reviewUrl: 'https://getlake.github.io/lake-gate/app/', // Lake review UI linked from the PR summary ("" to hide the buttons)
|
|
18
|
+
checkButtons: false, // experimental: Approve / Request changes buttons on a GitHub check run (needs checks: write)
|
|
19
|
+
autoApprove: { mode: 'on', maxUsd: 1.5, maxSteps: 3, maxComplexity: 'low' }, // tiny plans pass without a human. mode: "off" | "shadow" | "on"
|
|
20
|
+
// Budget approval: above approverAbove (USD, upper estimate or the plan's "Budget cap") one of approvers
|
|
21
|
+
// (GitHub logins or "@org/team") must approve the exact version too. Off until you set both.
|
|
22
|
+
budget: { approverAbove: null, approvers: [], suggestAbove: 0, suggestCapAbove: 10 },
|
|
23
|
+
catalog: {}, // extra models in lake-meter's prices.json shape, e.g. { "my-model": { "label": "My model", "tier": "standard", "input": 1, "cacheRead": 0.1, "output": 5 } }
|
|
24
|
+
provider: 'anthropic', // model family for Lake's picks: "anthropic" | "openai". Prices: lake-meter's table (meter-core.js)
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function isObj(v) { return v && typeof v === 'object' && !Array.isArray(v); }
|
|
28
|
+
export function merge(base, over) {
|
|
29
|
+
if (!isObj(over)) return base;
|
|
30
|
+
const out = { ...base };
|
|
31
|
+
for (const [k, v] of Object.entries(over)) out[k] = isObj(v) && isObj(base[k]) ? merge(base[k], v) : v;
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function parseConfig(text) {
|
|
36
|
+
if (!text) return DEFAULT_CONFIG;
|
|
37
|
+
return merge(DEFAULT_CONFIG, JSON.parse(text));
|
|
38
|
+
}
|
package/src/config.js
CHANGED
|
@@ -1,50 +1,8 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import { parseConfig } from './config-core.js';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
// https://docs.anthropic.com/en/docs/about-claude/pricing on 2026-11-12.
|
|
6
|
-
// They are assumptions for a forecast, not a quote. Edit .lake/config.json to change them.
|
|
7
|
-
export const DEFAULT_CONFIG = {
|
|
8
|
-
requiredApprovals: 1,
|
|
9
|
-
allowedAssociations: ['OWNER', 'MEMBER', 'COLLABORATOR'],
|
|
10
|
-
ignoreLogins: [],
|
|
11
|
-
requirePlan: 'warn', // PR check when code changes without a plan: "off" | "warn" | "fail"
|
|
12
|
-
localGate: 'block', // Claude Code hook: "block" | "ask" | "off"
|
|
13
|
-
gatedTools: ['Edit', 'Write', 'MultiEdit', 'NotebookEdit', 'Bash'],
|
|
14
|
-
readOnlyBash: [
|
|
15
|
-
'^\\s*(ls|pwd|cat|head|tail|wc|rg|grep|find|tree|file|stat|which|echo|env|date|du|df)(\\s|$)',
|
|
16
|
-
'^\\s*git\\s+(status|log|diff|show|branch|remote|rev-parse|ls-files|blame|fetch)(\\s|$)',
|
|
17
|
-
'^\\s*(npx\\s+(-y\\s+)?)?lake-gate(@\\S+)?\\s+(status|estimate|check|sync|plan|help)(\\s|$)',
|
|
18
|
-
],
|
|
19
|
-
autoApprove: { mode: 'shadow', maxUsd: 1.5, maxSteps: 3, maxComplexity: 'low' }, // mode: "off" | "shadow" | "on"
|
|
20
|
-
cacheHitShare: 0.7,
|
|
21
|
-
pricesAsOf: '2026-11-12',
|
|
22
|
-
models: {
|
|
23
|
-
fast: { name: 'Claude Haiku 5.5', inputPerMTok: 0.5, cacheReadPerMTok: 0.05, outputPerMTok: 2.5 },
|
|
24
|
-
balanced: { name: 'Claude Sonnet 5.5', inputPerMTok: 2, cacheReadPerMTok: 0.1, outputPerMTok: 10 },
|
|
25
|
-
frontier: { name: 'Claude Opus 5.5', inputPerMTok: 4, cacheReadPerMTok: 0.2, outputPerMTok: 20 },
|
|
26
|
-
},
|
|
27
|
-
tierFor: { low: 'fast', medium: 'balanced', high: 'frontier' },
|
|
28
|
-
// Rough agentic token bands per step (input includes re-read context; output is generated code/text).
|
|
29
|
-
tokens: {
|
|
30
|
-
low: { in: [120000, 400000], out: [4000, 15000] },
|
|
31
|
-
medium: { in: [400000, 1200000], out: [15000, 45000] },
|
|
32
|
-
high: { in: [1000000, 3500000], out: [35000, 120000] },
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
function isObj(v) { return v && typeof v === 'object' && !Array.isArray(v); }
|
|
37
|
-
export function merge(base, over) {
|
|
38
|
-
if (!isObj(over)) return base;
|
|
39
|
-
const out = { ...base };
|
|
40
|
-
for (const [k, v] of Object.entries(over)) out[k] = isObj(v) && isObj(base[k]) ? merge(base[k], v) : v;
|
|
41
|
-
return out;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function parseConfig(text) {
|
|
45
|
-
if (!text) return DEFAULT_CONFIG;
|
|
46
|
-
return merge(DEFAULT_CONFIG, JSON.parse(text));
|
|
47
|
-
}
|
|
5
|
+
export { DEFAULT_CONFIG, merge, parseConfig } from './config-core.js';
|
|
48
6
|
|
|
49
7
|
export function loadConfig(root) {
|
|
50
8
|
const p = path.join(root, '.lake', 'config.json');
|
package/src/estimate.js
CHANGED
|
@@ -1,52 +1,38 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { normalizeBody } from './plan.js';
|
|
2
|
+
import { analyzePlan, scoreStep, PRICES } from './meter-core.js';
|
|
3
|
+
import { applyDeclarations } from './models.js';
|
|
2
4
|
|
|
3
5
|
const RANK = { low: 0, medium: 1, high: 2 };
|
|
4
6
|
export const complexityRank = (c) => RANK[c] ?? 1;
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
const LOW = /\b(typo|rename|copy|wording|docs?|readme|comment|bump|version bump|lint|format\w*|style|log message|changelog|config value|constant|label|tooltip|text)\b/i;
|
|
8
|
-
const MANY_FILES = /\b(across|all|every|each)\s+(the\s+)?(files|modules|services|packages|endpoints|components|call ?sites)\b/i;
|
|
9
|
-
const TESTS = /\b(test|tests|spec|e2e|integration)\b/i;
|
|
10
|
-
|
|
8
|
+
// Kept for callers of 0.1: classify one step with the shared scorer.
|
|
11
9
|
export function classifyStep(text) {
|
|
12
|
-
const reasons =
|
|
13
|
-
|
|
14
|
-
const h = text.match(HIGH); const l = text.match(LOW);
|
|
15
|
-
if (h) { score += 1; reasons.push(`mentions "${h[0]}"`); }
|
|
16
|
-
if (MANY_FILES.test(text)) { score += 1; reasons.push('touches many files'); }
|
|
17
|
-
if (l && !h) { score -= 1; reasons.push(`looks small ("${l[0]}")`); }
|
|
18
|
-
const words = text.split(/\s+/).length;
|
|
19
|
-
if (words > 80) { score += 1; reasons.push('long step'); }
|
|
20
|
-
if (TESTS.test(text) && score < 2 && !l) reasons.push('includes tests');
|
|
21
|
-
const complexity = score <= 0 ? 'low' : score === 1 ? 'medium' : 'high';
|
|
22
|
-
if (!reasons.length) reasons.push('default');
|
|
23
|
-
return { complexity, reasons };
|
|
10
|
+
const { complexity, reasons } = scoreStep({ title: text, body: '' });
|
|
11
|
+
return { complexity: levelToComplexity(complexity), level: complexity, reasons };
|
|
24
12
|
}
|
|
25
13
|
|
|
26
|
-
|
|
27
|
-
|
|
14
|
+
// One estimator for all Lake tools: steps, complexity 1-5, model picks and prices come from lake-meter's
|
|
15
|
+
// analyzePlan and price table (src/meter-core.js). complexity keeps the low/medium/high label for policy;
|
|
16
|
+
// level is the 1-5 score.
|
|
17
|
+
export const levelToComplexity = (n) => (n <= 2 ? 'low' : n === 3 ? 'medium' : 'high');
|
|
18
|
+
export function pricesFor(config) {
|
|
19
|
+
const extra = config.catalog || {};
|
|
20
|
+
return Object.keys(extra).length ? { ...PRICES, models: { ...PRICES.models, ...extra } } : PRICES;
|
|
21
|
+
}
|
|
28
22
|
export function estimatePlan(body, config) {
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const lo = usd(band.in[0], band.out[0], model, hit);
|
|
36
|
-
const hi = usd(band.in[1], band.out[1], model, hit);
|
|
37
|
-
const top = config.models.frontier;
|
|
38
|
-
return { n: i + 1, title: s.title.slice(0, 90), complexity, reasons, tier, model: model.name, tokens: band,
|
|
39
|
-
usd: [lo, hi], frontierUsd: [usd(band.in[0], band.out[0], top, hit), usd(band.in[1], band.out[1], top, hit)] };
|
|
40
|
-
});
|
|
41
|
-
const sum = (k, i) => steps.reduce((a, s) => a + s[k][i], 0);
|
|
42
|
-
const maxC = steps.reduce((a, s) => (complexityRank(s.complexity) > complexityRank(a) ? s.complexity : a), 'low');
|
|
43
|
-
return {
|
|
23
|
+
const prices = pricesFor(config);
|
|
24
|
+
const a = analyzePlan(normalizeBody(body), prices, { provider: config.provider || 'anthropic' });
|
|
25
|
+
const steps = a.steps.map((s) => ({ n: s.n, title: s.title.replace(/\s*[([]\s*model\s*:\s*[^)\]]+[)\]]/i, '').slice(0, 90), complexity: levelToComplexity(s.complexity), level: s.complexity, reasons: s.reasons, tier: s.tier,
|
|
26
|
+
model: s.modelLabel, modelKey: s.model, tokens: prices.assumptions.stepTokens[String(s.complexity)], usd: s.usd, frontierUsd: s.baselineUsd }));
|
|
27
|
+
const maxC = steps.reduce((m, s) => (complexityRank(s.complexity) > complexityRank(m) ? s.complexity : m), 'low');
|
|
28
|
+
return applyDeclarations({
|
|
44
29
|
steps,
|
|
45
30
|
complexity: maxC,
|
|
46
|
-
usd:
|
|
47
|
-
frontierUsd:
|
|
48
|
-
|
|
49
|
-
|
|
31
|
+
usd: a.total.usd,
|
|
32
|
+
frontierUsd: a.total.baselineUsd,
|
|
33
|
+
baseline: a.baselineLabel,
|
|
34
|
+
pricesAsOf: a.pricesVerifiedAt,
|
|
35
|
+
}, body, config);
|
|
50
36
|
}
|
|
51
37
|
|
|
52
38
|
export const money = (n) => (n < 0.1 ? `$${n.toFixed(3)}` : n < 10 ? `$${n.toFixed(2)}` : `$${Math.round(n)}`);
|
|
@@ -56,14 +42,16 @@ export function autoApproveVerdict(est, config) {
|
|
|
56
42
|
const a = config.autoApprove || {};
|
|
57
43
|
if (!a.mode || a.mode === 'off') return { eligible: false, mode: 'off', reasons: [] };
|
|
58
44
|
const reasons = [];
|
|
59
|
-
|
|
45
|
+
const top = est.exposure ?? est.usd[1];
|
|
46
|
+
if (top > a.maxUsd) reasons.push(`upper estimate ${money(top)} > ${money(a.maxUsd)}`);
|
|
47
|
+
if (config.budget?.approverAbove != null && top > config.budget.approverAbove) reasons.push('needs budget approval');
|
|
60
48
|
if (est.steps.length > a.maxSteps) reasons.push(`${est.steps.length} steps > ${a.maxSteps}`);
|
|
61
49
|
if (complexityRank(est.complexity) > complexityRank(a.maxComplexity)) reasons.push(`complexity ${est.complexity} > ${a.maxComplexity}`);
|
|
62
50
|
return { eligible: reasons.length === 0, mode: a.mode, reasons };
|
|
63
51
|
}
|
|
64
52
|
|
|
65
53
|
export function renderEstimate(est, config) {
|
|
66
|
-
const rows = est.steps.map((s) => `| ${s.n} | ${s.title.replace(/\|/g, '/')} | ${s.complexity} | ${s.model} | ${range(s.usd)} |`);
|
|
54
|
+
const rows = est.steps.map((s) => `| ${s.n} | ${s.title.replace(/\|/g, '/')} | ${s.complexity} | ${est.declared ? `${s.planned ? `${s.planned.name}${s.fit === 'risky' ? ' (may be too weak)' : ''}` : 'not set'} | ` : ''}${s.model} | ${range(s.planned ? s.planned.usd : s.usd)} |`);
|
|
67
55
|
const auto = autoApproveVerdict(est, config);
|
|
68
56
|
const autoLine = auto.mode === 'off' ? '' : auto.eligible
|
|
69
57
|
? `\nAuto-approve policy (${auto.mode}): ${auto.mode === 'on' ? 'this plan is auto-approved' : 'this plan would be auto-approved'} (small, low cost).`
|
|
@@ -71,12 +59,12 @@ export function renderEstimate(est, config) {
|
|
|
71
59
|
return [
|
|
72
60
|
'## Lake estimate',
|
|
73
61
|
'',
|
|
74
|
-
`Overall complexity: **${est.complexity}** · Estimated cost with the recommended model per step: **${range(est.usd)}** (all steps on ${
|
|
62
|
+
`Overall complexity: **${est.complexity}** · ${est.declared ? `Planned model${est.model ? ` **${est.model.name}**` : 's per step'}: **${range(est.plannedUsd)}** · Lake mix (cheapest model that fits each step): ${range(est.usd)}` : `Estimated cost with the recommended model per step: **${range(est.usd)}** (all steps on ${est.baseline}: ${range(est.frontierUsd)})`}${est.cap != null ? ` · Budget cap **${money(est.cap)}**` : ''}`,
|
|
75
63
|
'',
|
|
76
|
-
'| # | Step | Complexity | Recommended model | Est. cost |',
|
|
77
|
-
'|---|---|---|---|---|',
|
|
64
|
+
est.declared ? '| # | Step | Complexity | Planned model | Recommended model | Est. cost |' : '| # | Step | Complexity | Recommended model | Est. cost |',
|
|
65
|
+
est.declared ? '|---|---|---|---|---|---|' : '|---|---|---|---|---|',
|
|
78
66
|
...rows,
|
|
79
67
|
'',
|
|
80
|
-
`
|
|
68
|
+
`Same estimator and price table as lake-meter (API list prices as of ${est.pricesAsOf}). Not a quote. Subscription plans spend quota, not these dollars.` + autoLine,
|
|
81
69
|
].join('\n');
|
|
82
70
|
}
|