lake-gate 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +152 -2
- package/action.yml +21 -0
- package/bin/lake-gate.js +3 -0
- package/package.json +48 -4
- package/src/action.js +75 -0
- package/src/cli.js +124 -0
- package/src/config-core.js +38 -0
- package/src/config.js +10 -0
- package/src/estimate.js +70 -0
- package/src/github.js +170 -0
- package/src/hook.js +73 -0
- package/src/index.js +10 -0
- package/src/init.js +62 -0
- package/src/mcp.js +312 -0
- package/src/meter-core.js +535 -0
- package/src/models.js +193 -0
- package/src/plan.js +90 -0
- package/src/policy.js +57 -0
- package/src/review.js +319 -0
- package/src/sha256.js +37 -0
- package/src/store.js +90 -0
- package/src/sync.js +50 -0
- package/src/ui-server.js +81 -0
- package/src/workspace.js +104 -0
- package/templates/lake-gate.yml +28 -0
- package/templates/plans-README.md +10 -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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Lake
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,153 @@
|
|
|
1
|
-
#
|
|
1
|
+
# lake-gate
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Your agent writes the plan. A teammate approves that exact version. Then the agent builds.**
|
|
4
|
+
|
|
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
|
+
|
|
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
|
+
- **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
|
+
- **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
|
+
- **PR check.** A GitHub Action sets the `lake/plan-approval` status. Make it required and unapproved plans can't merge.
|
|
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.
|
|
16
|
+
|
|
17
|
+
## Install (about 10 minutes)
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
cd your-repo
|
|
21
|
+
npx lake-gate init # writes .lake/, the Claude Code hook, the GitHub workflow, and MCP config for Claude Code + Cursor
|
|
22
|
+
npm i -D lake-gate # optional for JS repos: faster hook than npx
|
|
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
|
|
25
|
+
```
|
|
26
|
+
|
|
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.
|
|
28
|
+
|
|
29
|
+
Then in GitHub: **Settings → Branches → branch protection → Require status checks → `lake/plan-approval`** (the check appears after the first PR runs).
|
|
30
|
+
|
|
31
|
+
Requirements: Node 18.17+, git, a GitHub repo. macOS/Linux shells for the hook (Windows: use WSL for now).
|
|
32
|
+
|
|
33
|
+
## The flow
|
|
34
|
+
|
|
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`.
|
|
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.
|
|
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.
|
|
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.
|
|
39
|
+
5. **Plan changes?** Edit the plan file. The version changes, the gate closes again and the PR check turns red until someone approves the new version.
|
|
40
|
+
|
|
41
|
+
Commands on the PR, one per line:
|
|
42
|
+
|
|
43
|
+
| Comment | Effect |
|
|
44
|
+
|---|---|
|
|
45
|
+
| `/lake approve <id>@<version>` | Approve this exact version |
|
|
46
|
+
| `/lake reject <id>@<version>` | Request changes. Blocks until the same person approves |
|
|
47
|
+
| `/lake revoke <id>` | Withdraw your approval |
|
|
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
|
+
|
|
80
|
+
## What the estimate looks like
|
|
81
|
+
|
|
82
|
+
```
|
|
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|
|
|
89
|
+
```
|
|
90
|
+
|
|
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`.
|
|
92
|
+
|
|
93
|
+
## CLI
|
|
94
|
+
|
|
95
|
+
```
|
|
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)
|
|
98
|
+
lake-gate plan <file.md|-> [--id name] save a plan with an estimate and make it active
|
|
99
|
+
lake-gate estimate <file.md|-> print the estimate only
|
|
100
|
+
lake-gate status plans, versions, approval state
|
|
101
|
+
lake-gate sync [--pr N] pull approvals from the PR
|
|
102
|
+
lake-gate check [--plan id] exit 0 only if the active plan's current version is approved
|
|
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
|
|
106
|
+
lake-gate hook claude the Claude Code PreToolUse hook (stdin JSON)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
`check` is the pre-run gate for anything that isn't Claude Code, e.g. `npx lake-gate check && codex exec "implement .lake/plans/x.md"`.
|
|
110
|
+
|
|
111
|
+
## Configuration: `.lake/config.json`
|
|
112
|
+
|
|
113
|
+
| Key | Default | Meaning |
|
|
114
|
+
|---|---|---|
|
|
115
|
+
| `requiredApprovals` | `1` | Distinct non-author approvals needed |
|
|
116
|
+
| `allowedAssociations` | `OWNER, MEMBER, COLLABORATOR` | Who may approve |
|
|
117
|
+
| `ignoreLogins` | `[]` | Logins that never count (e.g. a shared agent account) |
|
|
118
|
+
| `requirePlan` | `"warn"` | PR changes code without a plan: `off`, `warn`, `fail` |
|
|
119
|
+
| `localGate` | `"block"` | Hook behaviour: `block` (deny), `ask` (Claude Code prompts you), `off` |
|
|
120
|
+
| `readOnlyBash` | git status/log/diff, ls, cat, rg... | Bash commands allowed before approval (regexes; chained commands are not) |
|
|
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 |
|
|
127
|
+
|
|
128
|
+
The PR check reads the config from the **base branch**, so a PR can't loosen its own policy.
|
|
129
|
+
|
|
130
|
+
## What it does not do (read this)
|
|
131
|
+
|
|
132
|
+
- **It is a guardrail, not a security boundary.** The local hook stops an agent from drifting into implementation. A human can turn it off (`LAKE_GATE=off`, editing settings). The real enforcement point is the required GitHub status.
|
|
133
|
+
- **A malicious insider can bypass the PR check** by editing the workflow in a `pull_request` run. Protect `.github/` and `.lake/config.json` with CODEOWNERS if that matters to you. Comment events always run the workflow from the default branch.
|
|
134
|
+
- **Approval doesn't stop a run that goes wrong after it starts.** lake-gate gates the start of implementation. It does not watch direction or spend during a run (yet).
|
|
135
|
+
- Fork PRs get a read-only token, so the status can't be posted. It's meant for internal team repos.
|
|
136
|
+
- Cost numbers are forecasts from a heuristic, not measurements.
|
|
137
|
+
- Claude Code is gated by the hook. Cursor and Codex use `lake-gate check` as a pre-run step.
|
|
138
|
+
|
|
139
|
+
## Privacy
|
|
140
|
+
|
|
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.
|
|
142
|
+
|
|
143
|
+
## Development
|
|
144
|
+
|
|
145
|
+
```bash
|
|
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
|
|
150
|
+
./scripts/demo.sh # packs the npm tarball, installs it in a throwaway repo, runs the whole flow
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
MIT © Lake
|
package/action.yml
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
name: Lake plan gate
|
|
2
|
+
description: Version-bound team approval for AI coding agent plans. Sets the lake/plan-approval commit status.
|
|
3
|
+
author: Lake
|
|
4
|
+
branding:
|
|
5
|
+
icon: check-circle
|
|
6
|
+
color: green
|
|
7
|
+
inputs:
|
|
8
|
+
token:
|
|
9
|
+
description: GitHub token with statuses:write and issues:write (the default GITHUB_TOKEN works).
|
|
10
|
+
required: false
|
|
11
|
+
default: ${{ github.token }}
|
|
12
|
+
comment:
|
|
13
|
+
description: Post and update one summary comment on the PR.
|
|
14
|
+
required: false
|
|
15
|
+
default: 'true'
|
|
16
|
+
outputs:
|
|
17
|
+
state:
|
|
18
|
+
description: success or failure
|
|
19
|
+
runs:
|
|
20
|
+
using: node24
|
|
21
|
+
main: src/action.js
|
package/bin/lake-gate.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lake-gate",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
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
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"lake-gate": "bin/lake-gate.js"
|
|
8
|
+
},
|
|
9
|
+
"main": "src/index.js",
|
|
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
|
+
],
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"author": "Lake research team",
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "git+https://github.com/getlake/lake-gate.git"
|
|
45
|
+
},
|
|
46
|
+
"homepage": "https://github.com/getlake/lake-gate#readme",
|
|
47
|
+
"bugs": {
|
|
48
|
+
"url": "https://github.com/getlake/lake-gate/issues"
|
|
49
|
+
}
|
|
50
|
+
}
|
package/src/action.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// GitHub Action entry point. Uses only the REST API with the workflow's GITHUB_TOKEN; no checkout needed.
|
|
3
|
+
import fs from 'node:fs';
|
|
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';
|
|
9
|
+
|
|
10
|
+
export function prNumberFromEvent(name, payload) {
|
|
11
|
+
if (payload.pull_request) return payload.pull_request.number;
|
|
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;
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
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
|
+
|
|
52
|
+
export async function runAction(env = process.env, fetchImpl) {
|
|
53
|
+
const payload = JSON.parse(fs.readFileSync(env.GITHUB_EVENT_PATH, 'utf8'));
|
|
54
|
+
const number = prNumberFromEvent(env.GITHUB_EVENT_NAME, payload);
|
|
55
|
+
if (!number) { console.log('lake-gate: not a pull request event, nothing to do.'); return null; }
|
|
56
|
+
const token = env.INPUT_TOKEN || env.GITHUB_TOKEN;
|
|
57
|
+
const gh = client({ token, repo: env.GITHUB_REPOSITORY, api: env.GITHUB_API_URL || 'https://api.github.com', fetchImpl });
|
|
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
|
+
}
|
|
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}`));
|
|
66
|
+
const md = renderSummary(ev);
|
|
67
|
+
if (env.GITHUB_STEP_SUMMARY) fs.appendFileSync(env.GITHUB_STEP_SUMMARY, md + '\n');
|
|
68
|
+
if (env.GITHUB_OUTPUT) fs.appendFileSync(env.GITHUB_OUTPUT, `state=${ev.state}\n`);
|
|
69
|
+
console.log(`lake-gate: ${ev.state}: ${ev.description}`);
|
|
70
|
+
return ev;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
74
|
+
runAction().catch((e) => { console.error(`::error::lake-gate: ${e.message}`); process.exit(1); });
|
|
75
|
+
}
|
package/src/cli.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import { repoRoot, exportPlan, loadPlan, listPlans, getState, setState, localStatus, getApprovals, setApprovals } from './store.js';
|
|
3
|
+
import { loadConfig } from './config.js';
|
|
4
|
+
import { estimatePlan, renderEstimate, range } from './estimate.js';
|
|
5
|
+
import { handleClaudePreToolUse } from './hook.js';
|
|
6
|
+
import { syncFromGitHub, applyEvents } from './sync.js';
|
|
7
|
+
import { init, ACTION_REF } from './init.js';
|
|
8
|
+
import { startUi } from './ui-server.js';
|
|
9
|
+
import { serve as serveMcp } from './mcp.js';
|
|
10
|
+
|
|
11
|
+
const HELP = `lake-gate: version-bound team approval for AI coding agent plans
|
|
12
|
+
|
|
13
|
+
Usage:
|
|
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)
|
|
17
|
+
lake-gate plan <file.md|-> [--id name] Save a plan (any agent) to .lake/plans/ with an estimate; make it active
|
|
18
|
+
lake-gate estimate <file.md|-> Print complexity, model per step and cost range
|
|
19
|
+
lake-gate status Active plan, version and approval state
|
|
20
|
+
lake-gate sync [--pr N] Pull approvals from the PR on GitHub (uses GITHUB_TOKEN or gh)
|
|
21
|
+
lake-gate check [--plan id] Exit 0 if the active plan's current version is approved (pre-run check)
|
|
22
|
+
lake-gate use <id> Set the active plan (human only; the hook blocks agents)
|
|
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
|
|
26
|
+
|
|
27
|
+
No telemetry. No backend. Docs: https://github.com/getlake/lake-gate`;
|
|
28
|
+
|
|
29
|
+
const flag = (args, name) => { const i = args.indexOf(name); return i >= 0 ? args[i + 1] : undefined; };
|
|
30
|
+
const readInput = (f) => (f === '-' || !f ? fs.readFileSync(0, 'utf8') : fs.readFileSync(f, 'utf8'));
|
|
31
|
+
|
|
32
|
+
function describe(root, plan) {
|
|
33
|
+
const st = localStatus(root, plan);
|
|
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(', ')}` : '';
|
|
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}`;
|
|
37
|
+
}
|
|
38
|
+
|
|
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') }) {
|
|
40
|
+
const [cmd, ...args] = argv;
|
|
41
|
+
const root = repoRoot();
|
|
42
|
+
switch (cmd) {
|
|
43
|
+
case 'init': {
|
|
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.`);
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
case 'plan': {
|
|
51
|
+
const { plan, estimate } = exportPlan(root, readInput(args.find((a) => !a.startsWith('--') && a !== flag(args, '--id'))), { id: flag(args, '--id'), source: 'cli' });
|
|
52
|
+
io.out(`Saved .lake/plans/${plan.id}.md version ${plan.short} ${estimate.complexity} est. ${range(estimate.usd)}`);
|
|
53
|
+
io.out(`Approve on the PR with: /lake approve ${plan.id}@${plan.short}`);
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
case 'estimate': {
|
|
57
|
+
const cfg = loadConfig(root);
|
|
58
|
+
io.out(renderEstimate(estimatePlan(readInput(args[0]), cfg), cfg));
|
|
59
|
+
return 0;
|
|
60
|
+
}
|
|
61
|
+
case 'status': {
|
|
62
|
+
const st = getState(root);
|
|
63
|
+
const plans = listPlans(root);
|
|
64
|
+
if (!plans.length) { io.out('No plans yet. Use plan mode in Claude Code, or: lake-gate plan <file.md>'); return 0; }
|
|
65
|
+
for (const p of plans) io.out(`${p.id === st.active ? '*' : ' '} ${describe(root, p)}`);
|
|
66
|
+
return 0;
|
|
67
|
+
}
|
|
68
|
+
case 'sync': {
|
|
69
|
+
if (flag(args, '--from-json')) { // offline/testing: {prAuthor, events}
|
|
70
|
+
const j = JSON.parse(fs.readFileSync(flag(args, '--from-json'), 'utf8'));
|
|
71
|
+
applyEvents(root, j);
|
|
72
|
+
} else {
|
|
73
|
+
const r = await syncFromGitHub(root, { pr: flag(args, '--pr') && Number(flag(args, '--pr')) });
|
|
74
|
+
io.out(`Synced approvals from PR #${r.pr}.`);
|
|
75
|
+
}
|
|
76
|
+
for (const p of listPlans(root)) io.out(' ' + describe(root, p));
|
|
77
|
+
return 0;
|
|
78
|
+
}
|
|
79
|
+
case 'check': {
|
|
80
|
+
const id = flag(args, '--plan') || getState(root).active;
|
|
81
|
+
const plan = id && loadPlan(root, id);
|
|
82
|
+
if (!plan) { io.err('lake-gate: no active plan.'); return 1; }
|
|
83
|
+
const st = localStatus(root, plan);
|
|
84
|
+
const ok = st.state === 'approved' || st.state === 'auto-approved';
|
|
85
|
+
(ok ? io.out : io.err)(describe(root, plan));
|
|
86
|
+
return ok ? 0 : 1;
|
|
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
|
+
}
|
|
99
|
+
case 'use': {
|
|
100
|
+
if (!args[0] || !loadPlan(root, args[0])) { io.err(`No plan named ${args[0]}`); return 1; }
|
|
101
|
+
const st = getState(root); st.active = args[0]; setState(root, st);
|
|
102
|
+
io.out(`Active plan: ${args[0]}`);
|
|
103
|
+
return 0;
|
|
104
|
+
}
|
|
105
|
+
case 'hook': {
|
|
106
|
+
if (args[0] !== 'claude') { io.err('Supported: lake-gate hook claude'); return 1; }
|
|
107
|
+
const input = JSON.parse(fs.readFileSync(0, 'utf8') || '{}');
|
|
108
|
+
const res = handleClaudePreToolUse(input);
|
|
109
|
+
if (res) io.out(JSON.stringify(res));
|
|
110
|
+
return 0;
|
|
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; }
|
|
120
|
+
case undefined: case 'help': case '--help': case '-h': io.out(HELP); return 0;
|
|
121
|
+
case '--version': case '-v': io.out(JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url))).version); return 0;
|
|
122
|
+
default: io.err(`Unknown command: ${cmd}\n\n${HELP}`); return 1;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -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
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { parseConfig } from './config-core.js';
|
|
4
|
+
|
|
5
|
+
export { DEFAULT_CONFIG, merge, parseConfig } from './config-core.js';
|
|
6
|
+
|
|
7
|
+
export function loadConfig(root) {
|
|
8
|
+
const p = path.join(root, '.lake', 'config.json');
|
|
9
|
+
return parseConfig(fs.existsSync(p) ? fs.readFileSync(p, 'utf8') : null);
|
|
10
|
+
}
|
package/src/estimate.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { normalizeBody } from './plan.js';
|
|
2
|
+
import { analyzePlan, scoreStep, PRICES } from './meter-core.js';
|
|
3
|
+
import { applyDeclarations } from './models.js';
|
|
4
|
+
|
|
5
|
+
const RANK = { low: 0, medium: 1, high: 2 };
|
|
6
|
+
export const complexityRank = (c) => RANK[c] ?? 1;
|
|
7
|
+
|
|
8
|
+
// Kept for callers of 0.1: classify one step with the shared scorer.
|
|
9
|
+
export function classifyStep(text) {
|
|
10
|
+
const { complexity, reasons } = scoreStep({ title: text, body: '' });
|
|
11
|
+
return { complexity: levelToComplexity(complexity), level: complexity, reasons };
|
|
12
|
+
}
|
|
13
|
+
|
|
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
|
+
}
|
|
22
|
+
export function estimatePlan(body, config) {
|
|
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({
|
|
29
|
+
steps,
|
|
30
|
+
complexity: maxC,
|
|
31
|
+
usd: a.total.usd,
|
|
32
|
+
frontierUsd: a.total.baselineUsd,
|
|
33
|
+
baseline: a.baselineLabel,
|
|
34
|
+
pricesAsOf: a.pricesVerifiedAt,
|
|
35
|
+
}, body, config);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const money = (n) => (n < 0.1 ? `$${n.toFixed(3)}` : n < 10 ? `$${n.toFixed(2)}` : `$${Math.round(n)}`);
|
|
39
|
+
export const range = ([a, b]) => `${money(a)}–${money(b)}`;
|
|
40
|
+
|
|
41
|
+
export function autoApproveVerdict(est, config) {
|
|
42
|
+
const a = config.autoApprove || {};
|
|
43
|
+
if (!a.mode || a.mode === 'off') return { eligible: false, mode: 'off', reasons: [] };
|
|
44
|
+
const reasons = [];
|
|
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');
|
|
48
|
+
if (est.steps.length > a.maxSteps) reasons.push(`${est.steps.length} steps > ${a.maxSteps}`);
|
|
49
|
+
if (complexityRank(est.complexity) > complexityRank(a.maxComplexity)) reasons.push(`complexity ${est.complexity} > ${a.maxComplexity}`);
|
|
50
|
+
return { eligible: reasons.length === 0, mode: a.mode, reasons };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function renderEstimate(est, config) {
|
|
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)} |`);
|
|
55
|
+
const auto = autoApproveVerdict(est, config);
|
|
56
|
+
const autoLine = auto.mode === 'off' ? '' : auto.eligible
|
|
57
|
+
? `\nAuto-approve policy (${auto.mode}): ${auto.mode === 'on' ? 'this plan is auto-approved' : 'this plan would be auto-approved'} (small, low cost).`
|
|
58
|
+
: `\nAuto-approve policy (${auto.mode}): needs a human (${auto.reasons.join('; ')}).`;
|
|
59
|
+
return [
|
|
60
|
+
'## Lake estimate',
|
|
61
|
+
'',
|
|
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)}**` : ''}`,
|
|
63
|
+
'',
|
|
64
|
+
est.declared ? '| # | Step | Complexity | Planned model | Recommended model | Est. cost |' : '| # | Step | Complexity | Recommended model | Est. cost |',
|
|
65
|
+
est.declared ? '|---|---|---|---|---|---|' : '|---|---|---|---|---|',
|
|
66
|
+
...rows,
|
|
67
|
+
'',
|
|
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,
|
|
69
|
+
].join('\n');
|
|
70
|
+
}
|