trylode 0.3.0 → 0.4.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/PERMISSIONS.md +9 -1
- package/README.md +1 -1
- package/bin/cli.mjs +42 -14
- package/package.json +1 -1
- package/skill/PERMISSIONS.md +4 -1
- package/skill/SKILL.md +8 -6
- package/skill/scripts/lode.mjs +47 -20
- package/skill/scripts/verify.mjs +354 -0
package/PERMISSIONS.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
- `.mcp.json`: one `"lode"` server entry, `https://trylode.io/mcp?src=setup`. Other entries are unchanged.
|
|
8
8
|
- `.cursor/mcp.json`: the same entry for Cursor.
|
|
9
|
-
- `CLAUDE.md` (created if missing
|
|
9
|
+
- `CLAUDE.md` and `AGENTS.md` (each created if missing; `AGENTS.md` left out with `--no-agents-md`): one marked block with the Lode rules line, added at the end. Nothing else in the file changes.
|
|
10
10
|
- `.cursor/rules/lode.mdc`: the rules line as a Cursor rule.
|
|
11
11
|
- `.claude/skills/lode-integration-check/`: a copy of the Lode Integration Check skill.
|
|
12
12
|
- `.claude/lode-init.json`: a note of what was added, so `remove` can undo exactly that.
|
|
@@ -25,6 +25,14 @@ If a `gate.mjs` or `gate-packages.json` that differs from this package's copy is
|
|
|
25
25
|
|
|
26
26
|
The same as `--gate`, for a second hook: one `PostToolUseFailure` entry in `.claude/settings.local.json` that runs `.claude/skills/lode-integration-check/scripts/failure-hook.mjs` after a shell command fails, plus that script and `failure-signals.json`. When a command fails with an integration error it recognises, it sends Lode (`POST https://trylode.io/v1/triage`) only the one app and platform named and a failure code, worked out on your machine; never the error text, the command, paths, versions or file contents. `npx trylode remove --triage --yes` takes out only the failure hook.
|
|
27
27
|
|
|
28
|
+
### Only with `--verify` (the verify hook, Claude Code only, off unless you add it)
|
|
29
|
+
|
|
30
|
+
The same as `--gate`, for a third hook: one `Stop` entry in `.claude/settings.local.json` that runs `.claude/skills/lode-integration-check/scripts/verify.mjs --hook` when the agent is about to finish, plus that script and `gate-packages.json`. It does what `npx trylode verify` does (below), only when the project's packages on Lode's list, their versions or its platform files changed since its last run in that session, and stops the agent once for each new finding of `sdk-deprecated`, `installed-affected` or `plan-needed`, never twice for the same one. `npx trylode remove --verify --yes` takes out only the verify hook.
|
|
31
|
+
|
|
32
|
+
### `npx trylode verify` (writes nothing)
|
|
33
|
+
|
|
34
|
+
Reads `package.json`, `package-lock.json` (installed versions only), `requirements.txt` and `pyproject.toml`, never through links, and whether platform config files exist (names only). Only when the project uses a package on Lode's list, it sends `POST https://trylode.io/v1/gate?log=0` with those package names and Lode platform codes, with logging off, plus one run code with the first request (`hook`, `cli` or `ci`: the verify hook, the command, or the command in CI), of which Lode keeps only that code and the date, to count runs; and, when a platform config file was found, it reads the public change feed `https://trylode.io/api/changes.json`; never versions, paths, file contents or anything else. Installed versions are compared with the advisory ranges in Lode's answer on your machine. Exit code 1 only when a finding has a code you list with `--fail-on`; if Lode can't be reached it says so and exits 0. Environment variables it reads: `CI` (to choose the run code `ci`) and, for the hook, `CLAUDE_PROJECT_DIR` (the project folder).
|
|
35
|
+
|
|
28
36
|
## Reads
|
|
29
37
|
|
|
30
38
|
Only the files above, to see what is already there. It never follows links, never edits a file it can't parse or couldn't write back exactly (a repeated key, or a number JSON can't keep exactly), and refuses files that are links, hard links, larger than 1 MB or not plain UTF-8.
|
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ npx trylode setup --yes # adds it
|
|
|
10
10
|
It adds:
|
|
11
11
|
|
|
12
12
|
1. **Lode's MCP server** to `.mcp.json` (Claude Code) and `.cursor/mcp.json` (Cursor). Hosted, no sign-in or API key.
|
|
13
|
-
2. **The rules line** to `CLAUDE.md`, `AGENTS.md` (if
|
|
13
|
+
2. **The rules line** to `CLAUDE.md`, `AGENTS.md` (each created if missing; `--no-agents-md` leaves `AGENTS.md` out) and `.cursor/rules/lode.mdc`. This is the step that matters most: agents reliably use a tool their instructions file tells them about.
|
|
14
14
|
3. **The Lode Integration Check skill** in `.claude/skills/`.
|
|
15
15
|
|
|
16
16
|
Optional (Claude Code only): Lode Gate. Running `npx trylode setup --gate --yes` adds a hook that runs just before the agent installs a package Lode knows (for example, `npm install resend`) and injects Lode's facts into the agent's context: required platform plan, recorded regions, and any SDK deprecation or published security advisory (each with a link and date). It never blocks an install and applies only to you, in this project (`.claude/settings.local.json`, kept out of git). When triggered, it sends only package names and a few codes to Lode—never your full command, source code, or local file paths. See [PERMISSIONS.md](PERMISSIONS.md) for details.
|
package/bin/cli.mjs
CHANGED
|
@@ -1,42 +1,57 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// npx trylode setup (LOD-248, Paul approved 01-12-2026): puts Lode into this project for the coding agents that read it.
|
|
3
3
|
// It is the Lode Integration Check skill's reviewed `init`, packaged: it writes Lode's MCP server (address tagged
|
|
4
|
-
// ?src=setup), the rules line (CLAUDE.md, AGENTS.md
|
|
4
|
+
// ?src=setup), the rules line (CLAUDE.md, AGENTS.md, .cursor/rules/lode.mdc) and the skill, shows the plan
|
|
5
5
|
// first and writes only with --yes. It sends nothing to Lode. `npx trylode remove --yes` undoes only what it added.
|
|
6
6
|
// With --gate (LOD-262) it also runs the skill's reviewed `init --gate` (warn mode, .claude/settings.local.json only).
|
|
7
|
+
// With --verify it runs `init --verify` the same way (the Stop hook). `npx trylode verify` runs the check itself: in CI,
|
|
8
|
+
// --fail-on sets the exit code (1 when a listed code is found; Lode unreachable never fails).
|
|
7
9
|
// No dependencies, no install scripts. See PERMISSIONS.md.
|
|
8
10
|
|
|
9
11
|
const USAGE = `Usage:
|
|
10
|
-
npx trylode setup [--yes] [--client claude|cursor|all] [--no-rules] [--gate] [--triage]
|
|
12
|
+
npx trylode setup [--yes] [--client claude|cursor|all] [--no-rules] [--no-agents-md] [--gate] [--triage] [--verify]
|
|
11
13
|
Shows what it would add to this project, and adds it with --yes:
|
|
12
14
|
.mcp.json and .cursor/mcp.json: one "lode" server entry (other entries unchanged)
|
|
13
|
-
CLAUDE.md, AGENTS.md
|
|
15
|
+
CLAUDE.md, AGENTS.md, .cursor/rules/lode.mdc: the Lode rules line (each created if missing;
|
|
16
|
+
--no-agents-md leaves AGENTS.md out)
|
|
14
17
|
.claude/skills/lode-integration-check/: the Lode Integration Check skill
|
|
15
18
|
--gate Also enables Lode Gate for Claude Code in .claude/settings.local.json (user-local, not shared).
|
|
16
19
|
Injects Lode's facts into the agent's context before installing a known package; never blocks.
|
|
17
20
|
--triage Also enables the Lode failure hook for Claude Code in .claude/settings.local.json (user-local, not shared).
|
|
18
21
|
When a command fails with an integration error it recognises, adds Lode's facts to the agent's context; never blocks.
|
|
19
|
-
|
|
22
|
+
--verify Also enables the Lode verify hook for Claude Code in .claude/settings.local.json (user-local, not shared).
|
|
23
|
+
When the agent is about to finish and the project's packages changed, checks them against Lode's facts
|
|
24
|
+
and stops the agent once per new finding so you hear about it.
|
|
25
|
+
npx trylode verify [--fail-on act|any|code,code] [--since YYYY-MM-DD] [--json]
|
|
26
|
+
Checks this project's packages on Lode's list against Lode's facts. Exit code 1 only when a finding has a
|
|
27
|
+
code --fail-on lists (for CI); warn only without it. Sends package names on Lode's list and platform codes,
|
|
28
|
+
with logging off (a verify run is counted by date and run code only). If Lode can't be reached it prints
|
|
29
|
+
that and exits 0.
|
|
30
|
+
npx trylode remove [--yes] [--gate] [--triage] [--verify]
|
|
20
31
|
Takes out only what setup (or the skill's init) added.
|
|
21
32
|
--gate Removes only Lode Gate (leaves the rest of your Lode setup intact).
|
|
22
33
|
--triage Removes only the Lode failure hook.
|
|
34
|
+
--verify Removes only the Lode verify hook.
|
|
23
35
|
|
|
24
36
|
Setup and remove send nothing to Lode. What Lode Gate sends when it runs: PERMISSIONS.md. More: https://trylode.io/agents/`;
|
|
25
37
|
|
|
26
38
|
// LOD-262 (Paul's wording, 02-12-2026): the one line setup adds when Gate is not on.
|
|
27
39
|
const GATE_OFFER = 'Optional for Claude Code: Lode Gate adds Lode\'s facts to your agent\'s context before installing a known package (never blocks). Enable with: npx trylode setup --gate --yes';
|
|
40
|
+
// LOD-287 (Paul approved the wording 03-12-2026): the one line setup adds when the verify hook is not on.
|
|
41
|
+
const VERIFY_OFFER = 'Optional for Claude Code: Lode verify checks this project\'s integrations against Lode\'s facts before the agent says it is done, and stops it once for each new finding. Enable with: npx trylode setup --verify --yes';
|
|
28
42
|
|
|
29
43
|
const argv = process.argv.slice(2);
|
|
30
44
|
const cmd = argv[0];
|
|
31
45
|
// Only these flags are passed on; anything else is ignored. --gate is handled here (warn mode, this person only):
|
|
32
46
|
// --shared and --mode are never passed through, so setup can't put the hook in a committed file (LOD-262).
|
|
33
47
|
const flags = [];
|
|
34
|
-
let gate = false, triage = false, client = 'all';
|
|
48
|
+
let gate = false, triage = false, verify = false, client = 'all';
|
|
35
49
|
for (let i = 1; i < argv.length; i++) {
|
|
36
50
|
const a = argv[i];
|
|
37
|
-
if (a === '--yes' || a === '--no-rules') flags.push(a);
|
|
51
|
+
if (a === '--yes' || a === '--no-rules' || a === '--no-agents-md') flags.push(a);
|
|
38
52
|
else if (a === '--gate') gate = true;
|
|
39
53
|
else if (a === '--triage') triage = true;
|
|
54
|
+
else if (a === '--verify') verify = true;
|
|
40
55
|
else if (a === '--client' && ['claude', 'cursor', 'all'].includes(argv[i + 1])) { client = argv[i + 1]; flags.push(a, argv[i + 1]); i++; }
|
|
41
56
|
}
|
|
42
57
|
const yes = flags.includes('--yes') ? ['--yes'] : [];
|
|
@@ -49,28 +64,41 @@ async function steps() {
|
|
|
49
64
|
if (cmd === 'setup') {
|
|
50
65
|
const first = await run(['init', '--src', 'setup', ...flags]);
|
|
51
66
|
if (!OK.test(first)) return { out: [first], ok: false };
|
|
52
|
-
if (client === 'cursor') return { out: [first, ...(gate || triage ? ['Lode Gate and the
|
|
53
|
-
if (gate || triage) {
|
|
67
|
+
if (client === 'cursor') return { out: [first, ...(gate || triage || verify ? ['Lode Gate, the failure hook and the verify hook are for Claude Code only, so they were ignored with --client cursor.'] : [])], ok: true };
|
|
68
|
+
if (gate || triage || verify) {
|
|
54
69
|
const out = [first]; let ok = true;
|
|
55
|
-
for (const [on, f] of [[gate, '--gate'], [triage, '--triage']]) if (on) { const g = await run(['init', f, '--src', 'setup', ...yes]); out.push(g); ok = ok && OK.test(g); }
|
|
70
|
+
for (const [on, f] of [[gate, '--gate'], [triage, '--triage'], [verify, '--verify']]) if (on) { const g = await run(['init', f, '--src', 'setup', ...yes]); out.push(g); ok = ok && OK.test(g); }
|
|
56
71
|
return { out, ok };
|
|
57
72
|
}
|
|
58
|
-
// Offer Gate only when
|
|
73
|
+
// Offer Gate and verify only when they aren't on yet (dry runs of the reviewed check; they write nothing)
|
|
59
74
|
const dry = await run(['init', '--gate', '--src', 'setup']);
|
|
60
|
-
|
|
75
|
+
const dryVerify = await run(['init', '--verify', '--src', 'setup']);
|
|
76
|
+
return { out: [first, ...(/already on in this project/.test(dry) ? [] : [GATE_OFFER]), ...(/already on in this project/.test(dryVerify) ? [] : [VERIFY_OFFER])], ok: true };
|
|
61
77
|
}
|
|
62
78
|
if (cmd === 'remove') {
|
|
63
79
|
// Each hook first (only the ones that are on are reported), then the rest unless only hooks were named
|
|
64
|
-
const
|
|
80
|
+
const named = gate || triage || verify;
|
|
81
|
+
const hooks = named ? [gate && '--gate', triage && '--triage', verify && '--verify'].filter(Boolean) : ['--gate', '--triage', '--verify'];
|
|
65
82
|
const outs = [];
|
|
66
|
-
for (const f of hooks) { const g = await run(['init', f, '--remove', '--src', 'setup', ...yes]); if (!/Nothing to remove/.test(g) ||
|
|
67
|
-
if (
|
|
83
|
+
for (const f of hooks) { const g = await run(['init', f, '--remove', '--src', 'setup', ...yes]); if (!/Nothing to remove/.test(g) || named) outs.push(g); }
|
|
84
|
+
if (named) return { out: outs, ok: outs.every((o) => OK.test(o)) };
|
|
68
85
|
const rest = await run(['init', '--remove', '--src', 'setup', ...yes]);
|
|
69
86
|
return { out: [...outs, rest], ok: OK.test(rest) && outs.every((o) => OK.test(o)) };
|
|
70
87
|
}
|
|
71
88
|
return null;
|
|
72
89
|
}
|
|
73
90
|
|
|
91
|
+
// npx trylode verify: the check itself (no files written). Exit 1 only for a --fail-on code, 2 for a bad code.
|
|
92
|
+
if (cmd === 'verify') {
|
|
93
|
+
const v = await import('../skill/scripts/verify.mjs');
|
|
94
|
+
const at = (k) => { const i = argv.indexOf(k); return i > 0 && typeof argv[i + 1] === 'string' && !argv[i + 1].startsWith('--') ? argv[i + 1] : undefined; };
|
|
95
|
+
const failOn = v.parseFailOn(at('--fail-on'));
|
|
96
|
+
if (failOn.error) { console.error(`trylode verify: unknown --fail-on code "${failOn.error}". Use act, any or codes from: ${v.CODES.join(', ')}`); process.exit(2); }
|
|
97
|
+
const res = await v.verify(process.cwd(), { since: at('--since'), run: v.runCode(process.env) });
|
|
98
|
+
console.log(argv.includes('--json') ? JSON.stringify({ ...res, fail_on: failOn, failing: v.failing(res, failOn).map((f) => f.package) }, null, 2) : v.format(res, failOn));
|
|
99
|
+
process.exit(v.failing(res, failOn).length ? 1 : 0);
|
|
100
|
+
}
|
|
101
|
+
|
|
74
102
|
try {
|
|
75
103
|
const r = await steps();
|
|
76
104
|
if (!r) { console.log(USAGE); process.exit(cmd && !['help', '--help', '-h'].includes(cmd) ? 1 : 0); }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trylode",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "One command puts Lode in your project: the MCP server, the rules line and the skill, so your coding agent checks integration facts before it adds a third-party service.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": { "trylode": "bin/cli.mjs" },
|
package/skill/PERMISSIONS.md
CHANGED
|
@@ -16,11 +16,14 @@ secrets. Privacy policy: https://trylode.io/privacy/
|
|
|
16
16
|
| `stack` | `package.json`, `requirements.txt`, `pyproject.toml`, `Gemfile`, `go.mod`, variable NAMES in `.env.example`, `vercel.json`, `netlify.toml`, `supabase/config.toml` | with `--share`: the app and platform codes found, the framework | nothing |
|
|
17
17
|
| `triage` | nothing | the app, platform, one fixed symptom code, the HTTP status if given (only its class is kept) and the `--object` code if given (sent only when it is one of the platform's object codes, otherwise not sent); with `--share`: the outcome code and the `--switched-to` app | nothing |
|
|
18
18
|
| `watch` (`watch`, `watch changes`, `watch stop`) | `lode-integrations.json`, `.lode/watch.json` and an existing `.gitignore` (never through links; a file not in the expected shape is refused) | `watch`: only with `--share`, the Lode ids of the integrations still kept in `lode-integrations.json` (at most 50); Lode makes a fresh random watch code, unless `--project-code` asks it to use the file's own project code; the watch code and token on later updates. `watch changes` and `watch stop`: the watch code and the token only. Lode keeps the list of ids until the watch is stopped; `stop` deletes it | `watch --share`: `.lode/watch.json` (mode 0600: the watch code and the secret token Lode returns once; the `.lode` folder is made if missing) and, only when a `.gitignore` already exists, one appended `.lode/` line; `watch stop` removes the token file |
|
|
19
|
-
| `init` | `.mcp.json`, `.cursor/mcp.json`, `.claude/lode-init.json`, `CLAUDE.md`, `AGENTS.md`, `.cursor/rules/lode.mdc` | nothing | only with `--yes`, only inside a project folder and never through links: one `lode` entry in those MCP files, a copy of this skill in `.claude/skills/`, the Lode rules line as one marked block at the end of `CLAUDE.md` (created if missing
|
|
19
|
+
| `init` | `.mcp.json`, `.cursor/mcp.json`, `.claude/lode-init.json`, `CLAUDE.md`, `AGENTS.md`, `.cursor/rules/lode.mdc` | nothing | only with `--yes`, only inside a project folder and never through links: one `lode` entry in those MCP files, a copy of this skill in `.claude/skills/`, the Lode rules line as one marked block at the end of `CLAUDE.md` and `AGENTS.md` (each created if missing; `AGENTS.md` left out with `--no-agents-md`) and as `.cursor/rules/lode.mdc` (left out with `--no-rules`), and a note of what was added in `.claude/lode-init.json`; a file it can't parse is left alone; `init --remove --yes` undoes only what init added (the rules block only when unchanged); with `--src setup` (used by `npx trylode setup`) the entry's address is `https://trylode.io/mcp?src=setup`, and `--remove` recognises either address |
|
|
20
20
|
| `init --gate` (Lode Gate, opt-in) | `.claude/settings.local.json` (or `.claude/settings.json` with `--shared`), `.claude/lode-init.json`, `.claude/.gitignore`, the Gate files already in `.claude/skills/lode-integration-check/` | nothing | only with `--yes`, only inside a project folder and never through links: one PreToolUse hook entry in that settings file (by default only for you: Claude Code keeps `settings.local.json` out of git; `--shared` gives it to everyone who opens the project), a copy of this skill with `gate.mjs` and `gate-packages.json` in `.claude/skills/` (it never overwrites a file, and refuses if Gate files already there differ from its own), two lines at the end of `.claude/.gitignore` inside a git repository (a comment and `settings.local.json`, so the hook file is never committed; `--remove` takes out exactly those two), and a note in `.claude/lode-init.json`; `init --gate --remove --yes` deletes only the files it copied, unchanged, from its fixed list |
|
|
21
21
|
| Gate hook (`scripts/gate.mjs`, runs before each shell command once switched on) | the shell command Claude is about to run and the session id (on your machine only; the id is used only to name the temp file below), the project folder (`CLAUDE_PROJECT_DIR`, else the working folder), whether `vercel.json`, `.vercel/project.json`, `netlify.toml`, `supabase/config.toml`, `wrangler.toml`, `wrangler.json` or `wrangler.jsonc` exist there (names only, never contents), `gate-packages.json`, and `LODE_GATE_LOG` | only when the command installs a package on Lode's list: those package names, the package manager, the platform codes found, the mode and a random code for the Claude Code session; never the command, versions, paths, file contents or the session id; with `LODE_GATE_LOG=0` Lode keeps nothing except the daily rate-limit count | a random session code in your temp folder (tidied after a day) |
|
|
22
22
|
| `init --triage` (the failure hook, opt-in) | the same files as `init --gate`, for the failure hook's own entry | nothing | only with `--yes`, under the same rules as `init --gate`: one `PostToolUseFailure` hook entry in `.claude/settings.local.json` (or `.claude/settings.json` with `--shared`), `failure-hook.mjs` and `failure-signals.json` copied with this skill, the same `.claude/.gitignore` lines and a note in `.claude/lode-init.json`; `init --triage --remove --yes` undoes only that |
|
|
23
23
|
| Failure hook (`scripts/failure-hook.mjs`, runs after a shell command fails, once switched on) | the failed command and its output (on your machine only; never sent or stored), the session id (only to name the temp file below), whether `vercel.json`, `.vercel/project.json`, `netlify.toml`, `supabase/config.toml`, `wrangler.toml`, `wrangler.json` or `wrangler.jsonc` exist (names only), `failure-signals.json`, and `LODE_GATE_LOG` | only when the output shows an integration failure it recognises and names exactly one app and one platform from Lode's list: one `POST https://trylode.io/v1/triage` (1.5 second limit) with that app, that platform, one failure code and the HTTP status number if shown, at most once per app, platform and failure in a session; never the output text, the command, paths, versions, file contents or the session id; with `LODE_GATE_LOG=0` Lode keeps nothing | a temp file listing the failures already asked about in this session (tidied after a day) |
|
|
24
|
+
| `verify` (and `npx trylode verify`) | `package.json`, `package-lock.json` (installed versions only), `requirements.txt`, `pyproject.toml` (never through links, never a file that isn't a plain file, at most 1 MB each and 20 MB for the lockfile), whether `vercel.json`, `.vercel/project.json`, `netlify.toml`, `supabase/config.toml`, `wrangler.toml`, `wrangler.json` or `wrangler.jsonc` exist (names only), and `gate-packages.json`; environment variables `CI` (to choose the run code) and, for the hook, `CLAUDE_PROJECT_DIR` | only when the project uses a package on Lode's list: `POST https://trylode.io/v1/gate?log=0` (2.5 second limit, in groups of 10, at most 30 packages) with those package names and the platform codes, with logging off, so Lode keeps nothing except the daily rate-limit count; the first of those requests also sends one run code (`hook`, `cli` or `ci`: the hook, the command, or the command in CI), and Lode keeps only that code and the date, to count runs; and, when a platform file was found, one read of the public change feed `https://trylode.io/api/changes.json`; never versions, paths, file contents or the session id. Installed versions are compared with the advisory ranges in Lode's answer on your machine | nothing |
|
|
25
|
+
| `init --verify` (the verify hook, opt-in) | the same files as `init --gate`, for the verify hook's own entry | nothing | only with `--yes`, under the same rules as `init --gate`: one `Stop` hook entry in `.claude/settings.local.json` (or `.claude/settings.json` with `--shared`), `verify.mjs` and `gate-packages.json` copied with this skill, the same `.claude/.gitignore` lines and a note in `.claude/lode-init.json`; `init --verify --remove --yes` undoes only that |
|
|
26
|
+
| Verify hook (`scripts/verify.mjs --hook`, runs when Claude is about to finish, once switched on) | the files `verify` reads and the session id (only to name the temp file below) | the same as `verify`, and only when the packages on Lode's list, their versions or the platform files changed since its last run in that Claude Code session; never versions, paths, file contents or the session id. It stops Claude once for each new finding of `sdk-deprecated`, `installed-affected` or `plan-needed`, never twice for the same one; if Lode can't be reached it stops nothing | a temp file with a hash of what it last checked and the findings already raised in this session (tidied after a day) |
|
|
24
27
|
|
|
25
28
|
Connect the MCP server at `https://trylode.io/mcp?log=0` to keep Lode from logging your requests (only the daily
|
|
26
29
|
rate-limit count and anything you choose to send are kept).
|
package/skill/SKILL.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: lode-integration-check
|
|
3
|
-
description: 'Use before you add, recommend, compare, connect or install a third-party service, SDK or integration, or decide to build
|
|
3
|
+
description: 'Use before you add, recommend, compare, connect or install a third-party service, SDK or integration, or decide to build it yourself (auth, email, payments, database, background jobs, rate limiting), on Xero, QuickBooks Online, HubSpot, Shopify, Stripe, Supabase, Vercel, Netlify, n8n, Lovable, Replit, Linear, GitHub, LangChain, Grok Build (Cursor) or Cloudflare. Also use to ask if two products work together, or when an integration fails. Examples: "add auth to my Supabase app", "which Xero app syncs purchase orders", "Stripe payouts stopped reaching QuickBooks". Returns Lode''s facts, each with its source link and last-verified date: what syncs and which way, price by currency, platform plan, regions, limits, who built it; also checks a project''s stack and overlaps. Sends Lode only what you look up (app, platform, needs, region) and fixed codes, never errors, logs or code; choices only with --share after the user agrees. Writes: init only with --yes; chose and adr save to lode-integrations.json and docs/adr/.'
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Lode Integration Check
|
|
@@ -13,7 +13,7 @@ sold. Use it so the user gets facts, not guesses, before an integration is chose
|
|
|
13
13
|
|
|
14
14
|
- The user wants to connect one product to another on Xero, QuickBooks Online, HubSpot, Shopify,
|
|
15
15
|
Stripe, Supabase, Vercel, Netlify, n8n, Linear or GitHub, add a connector to a Lovable or Replit app, add a
|
|
16
|
-
LangChain integration package, add a Cursor plugin or MCP server, or connect a service to Cloudflare Workers.
|
|
16
|
+
LangChain integration package, add a Grok Build (formerly Cursor) plugin or MCP server, or connect a service to Cloudflare Workers.
|
|
17
17
|
- You are about to add any third-party integration to a project (a package, SDK, platform integration,
|
|
18
18
|
connector or MCP server). Run `stack` first (or call `check_stack` on the Lode MCP server), so the user
|
|
19
19
|
sees what Lode documents about the stack it joins: the plans it needs, overlaps and function run-time limits.
|
|
@@ -231,7 +231,9 @@ Pick the one code that fits what you see: `credential-invalid`, `token-expired`,
|
|
|
231
231
|
`package-incompatible`, `capability-missing` (add `--object`), `validation-rejected`, `data-mismatch`,
|
|
232
232
|
`webhook-not-received`, `webhook-signature-failed`, `event-duplicate-or-out-of-order`, `api-deprecated`,
|
|
233
233
|
`region-unavailable`, `connection-failed`, `setup-step-missing`, `service-outage`, `mcp-connect-failed`,
|
|
234
|
-
`mcp-tool-error`,
|
|
234
|
+
`mcp-tool-error`,
|
|
235
|
+
`connection-expired`, `login-required-unattended` (these two only when the run had no person present), or
|
|
236
|
+
`other`. Lode answers with the sourced facts that explain that kind of failure for that
|
|
235
237
|
pair: documented limitations, plan requirements, run-time limits, platform rules, regions, setup steps and
|
|
236
238
|
recent status-page incidents, and, for `capability-missing`, the apps on that platform that document the
|
|
237
239
|
object. Never send error messages, logs, code or project details: only the codes. If Lode has no matching
|
|
@@ -248,9 +250,9 @@ node scripts/lode.mjs init [--client claude|cursor|all]
|
|
|
248
250
|
|
|
249
251
|
It shows the files it would change: one `lode` entry in `.mcp.json` (Claude Code) and/or
|
|
250
252
|
`.cursor/mcp.json` (Cursor), a copy of this skill in `.claude/skills/`, and the Lode rules line (so the
|
|
251
|
-
agent checks Lode before it adds an integration) at the end of `CLAUDE.md` (created if
|
|
252
|
-
|
|
253
|
-
|
|
253
|
+
agent checks Lode before it adds an integration) at the end of `CLAUDE.md` and `AGENTS.md` (each created if
|
|
254
|
+
missing), and as `.cursor/rules/lode.mdc`. Add `--no-rules` to leave the rules line out, or `--no-agents-md`
|
|
255
|
+
to leave out `AGENTS.md`. It writes nothing until the
|
|
254
256
|
user agrees and you run it again with `--yes`. It runs only in a project folder, never through links, leaves
|
|
255
257
|
any config file it can't parse alone (it tells you the entry to add by hand), changes no other entry or text, adds no
|
|
256
258
|
code or hooks, and sends nothing to Lode. Committed, the files give every teammate and sub-agent in the project Lode with no
|
package/skill/scripts/lode.mjs
CHANGED
|
@@ -56,7 +56,7 @@ import { pathToFileURL } from 'node:url';
|
|
|
56
56
|
const BASE = (process.env.LODE_BASE || 'https://trylode.io').replace(/\/$/, '');
|
|
57
57
|
const UA = process.env.LODE_UA || 'lode-skill/0.1 (+https://trylode.io/agents/)';
|
|
58
58
|
|
|
59
|
-
export const NAMES = { xero: 'Xero', 'quickbooks-online': 'QuickBooks Online', hubspot: 'HubSpot', shopify: 'Shopify', stripe: 'Stripe', supabase: 'Supabase', vercel: 'Vercel', netlify: 'Netlify', n8n: 'n8n', lovable: 'Lovable', replit: 'Replit', linear: 'Linear', github: 'GitHub', langchain: 'LangChain', cursor: '
|
|
59
|
+
export const NAMES = { xero: 'Xero', 'quickbooks-online': 'QuickBooks Online', hubspot: 'HubSpot', shopify: 'Shopify', stripe: 'Stripe', supabase: 'Supabase', vercel: 'Vercel', netlify: 'Netlify', n8n: 'n8n', lovable: 'Lovable', replit: 'Replit', linear: 'Linear', github: 'GitHub', langchain: 'LangChain', cursor: 'Grok Build', cloudflare: 'Cloudflare' };
|
|
60
60
|
export const PLATFORMS = {
|
|
61
61
|
xero: ['xero'],
|
|
62
62
|
'quickbooks-online': ['quickbooks-online', 'quickbooks', 'qbo', 'quickbooks online', 'intuit quickbooks'],
|
|
@@ -695,7 +695,10 @@ export function parseRequirements(text) {
|
|
|
695
695
|
export function parsePyproject(text) {
|
|
696
696
|
const out = new Set();
|
|
697
697
|
const t = String(text);
|
|
698
|
-
|
|
698
|
+
// One pass over each list (security review 03-12-2026: the regex was quadratic on unclosed brackets)
|
|
699
|
+
const head = /^[ \t]*(?:dependencies|requires)[ \t]*=[ \t]*\[/gm; const lists = []; let h;
|
|
700
|
+
while ((h = head.exec(t))) { const end = t.indexOf(']', head.lastIndex); if (end < 0) break; lists.push(t.slice(head.lastIndex, end)); head.lastIndex = end + 1; }
|
|
701
|
+
for (const m of lists) for (const q of m.matchAll(/["']([^"']+)["']/g)) { const n = pyName(q[1]); if (n) out.add(n); }
|
|
699
702
|
for (const sec of t.matchAll(/^\[tool\.poetry\.(?:dev-)?dependencies\]\n([\s\S]*?)(?=^\[|$(?![\s\S]))/gm)) for (const l of sec[1].split('\n')) { const n = (l.match(/^\s*([A-Za-z0-9][A-Za-z0-9._-]*)\s*=/) || [])[1]; if (n && n !== 'python') out.add(n); }
|
|
700
703
|
return [...out];
|
|
701
704
|
}
|
|
@@ -851,7 +854,7 @@ async function stack({ share, framework } = {}) {
|
|
|
851
854
|
|
|
852
855
|
|
|
853
856
|
// Integration Triage (LOD-165): fixed symptom codes, kept equal to SYMPTOM_CODES in src/lib/triage.mjs by tests/triage.test.mjs
|
|
854
|
-
export const SYMPTOM_CODES = ["credential-invalid", "token-expired", "scope-missing", "authorize-failed", "access-filtered", "platform-plan-required", "app-plan-required", "account-restricted", "rate-limited", "request-too-large", "runtime-limit-exceeded", "config-missing", "package-not-found", "package-incompatible", "capability-missing", "validation-rejected", "data-mismatch", "webhook-not-received", "webhook-signature-failed", "event-duplicate-or-out-of-order", "api-deprecated", "region-unavailable", "connection-failed", "setup-step-missing", "service-outage", "mcp-connect-failed", "mcp-tool-error", "other"];
|
|
857
|
+
export const SYMPTOM_CODES = ["credential-invalid", "token-expired", "scope-missing", "authorize-failed", "access-filtered", "platform-plan-required", "app-plan-required", "account-restricted", "rate-limited", "request-too-large", "runtime-limit-exceeded", "config-missing", "package-not-found", "package-incompatible", "capability-missing", "validation-rejected", "data-mismatch", "webhook-not-received", "webhook-signature-failed", "event-duplicate-or-out-of-order", "api-deprecated", "region-unavailable", "connection-failed", "setup-step-missing", "service-outage", "mcp-connect-failed", "mcp-tool-error", "other", "connection-expired", "login-required-unattended"];
|
|
855
858
|
export const TRIAGE_OUTCOMES = ['fixed', 'switched', 'gave-up'];
|
|
856
859
|
|
|
857
860
|
async function triageCmd(app, platform, opts) {
|
|
@@ -934,6 +937,9 @@ const gateIsHook = (h) => JSON.stringify(h) === JSON.stringify(GATE_HOOK('warn')
|
|
|
934
937
|
// LOD-278: the failure hook, an opt-in PostToolUseFailure hook over Integration Triage. Same install rules as Gate.
|
|
935
938
|
export const TRIAGE_HOOK = () => ({ matcher: 'Bash|PowerShell', hooks: [{ type: 'command', command: 'node', args: ['${CLAUDE_PROJECT_DIR}/.claude/skills/lode-integration-check/scripts/failure-hook.mjs'], timeout: 3 }] });
|
|
936
939
|
const TRIAGE_FILES_LIST = ['SKILL.md', 'PERMISSIONS.md', 'scripts/lode.mjs', 'scripts/failure-hook.mjs', 'scripts/failure-signals.json'];
|
|
940
|
+
// Lode verify (v0): an opt-in Stop hook over verify.mjs. Same install rules as Gate. No matcher: Stop has none.
|
|
941
|
+
export const VERIFY_HOOK = () => ({ hooks: [{ type: 'command', command: 'node', args: ['${CLAUDE_PROJECT_DIR}/.claude/skills/lode-integration-check/scripts/verify.mjs', '--hook'], timeout: 10 }] });
|
|
942
|
+
const VERIFY_FILES_LIST = ['SKILL.md', 'PERMISSIONS.md', 'scripts/lode.mjs', 'scripts/verify.mjs', 'scripts/gate-packages.json'];
|
|
937
943
|
const HOOK_KINDS = {
|
|
938
944
|
gate: { key: 'gate', filesKey: 'gate_files', event: 'PreToolUse', flag: '--gate', name: 'Lode Gate', Name: 'Lode Gate', entryLabel: 'the Lode Gate hook entry', filesLabel: 'the Gate files', modes: true, does: '(it adds facts; it never blocks)',
|
|
939
945
|
entry: (mode) => GATE_HOOK(mode), is: gateIsHook, files: GATE_FILES_LIST,
|
|
@@ -941,15 +947,21 @@ const HOOK_KINDS = {
|
|
|
941
947
|
triage: { key: 'triage', filesKey: 'triage_files', event: 'PostToolUseFailure', flag: '--triage', name: 'the Lode failure hook', Name: 'The Lode failure hook', entryLabel: 'the Lode failure hook entry', filesLabel: 'the failure hook files', modes: false, does: '(when a command fails with an integration error it recognises, it adds facts; it never blocks)',
|
|
942
948
|
entry: () => TRIAGE_HOOK(), is: (h) => JSON.stringify(h) === JSON.stringify(TRIAGE_HOOK()), files: TRIAGE_FILES_LIST,
|
|
943
949
|
what: "The failure hook reads a failed command's output on this machine and sends Lode a request only when it recognises an integration failure: the one app and platform named and a failure code, at most once per failure in a session. Never the output text, the command, paths, versions or file contents. See PERMISSIONS.md." },
|
|
950
|
+
verify: { key: 'verify', filesKey: 'verify_files', event: 'Stop', flag: '--verify', name: 'the Lode verify hook', Name: 'The Lode verify hook', entryLabel: 'the Lode verify hook entry', filesLabel: 'the verify hook files', modes: false, does: '(when the packages on Lode\'s list or the platform files changed, it checks them against Lode\'s facts and stops Claude once per new finding so you hear about it; it never blocks twice for the same finding)', hookOn: 'when Claude is about to finish',
|
|
951
|
+
entry: () => VERIFY_HOOK(), is: (h) => JSON.stringify(h) === JSON.stringify(VERIFY_HOOK()), files: VERIFY_FILES_LIST,
|
|
952
|
+
what: "The verify hook reads package.json, package-lock.json, requirements.txt and pyproject.toml on this machine and sends Lode a request only when the project uses a package on Lode's list: those package names and platform codes from config file names, with logging off (a verify run is counted by date and run code only), plus a read of Lode's public change feed. Never versions, paths, file contents or the session id. See PERMISSIONS.md." },
|
|
944
953
|
};
|
|
945
|
-
// Removing one hook hands the .gitignore block to
|
|
946
|
-
// ...but only when
|
|
954
|
+
// Removing one hook hands the .gitignore block to another hook that still uses settings.local.json
|
|
955
|
+
// ...but only when that hook has no block of its own (security review 02-12-2026, LOD-278)
|
|
947
956
|
const handOverAtRemove = (marker, K, other, localFile) => marker[other.key]?.file === localFile && !marker[other.key]?.ignore;
|
|
948
957
|
// By default the hook goes in .claude/settings.local.json (this person only, not committed), so nobody who clones
|
|
949
958
|
// the project sends anything without choosing to; --shared puts it in .claude/settings.json for the whole team.
|
|
950
959
|
async function gateInit({ yes = false, remove = false, mode = 'warn', shared = false, src = null, kind = 'gate' } = {}) {
|
|
951
960
|
const K = HOOK_KINDS[kind] ?? HOOK_KINDS.gate;
|
|
952
|
-
|
|
961
|
+
// Every other hook kind (Gate, the failure hook, verify): files, the .gitignore block and a created settings file
|
|
962
|
+
// pass to the first one still on that needs them (generalised from one other hook for verify, 03-12-2026)
|
|
963
|
+
const others = Object.values(HOOK_KINDS).filter((x) => x !== K);
|
|
964
|
+
const heir = () => others.find((o) => handOverAtRemove(marker, K, o, ALLOWED_SETTINGS[0]));
|
|
953
965
|
// Through npx trylode (LOD-262) the user has no lode.mjs, so every command shown is trylode's own.
|
|
954
966
|
const gateCmd = (rm) => (src === 'setup' ? `npx trylode ${rm ? 'remove' : 'setup'} ${K.flag} --yes` : `node lode.mjs init ${K.flag}${rm ? ' --remove' : ''} --yes`);
|
|
955
967
|
const fs = await import('node:fs'); const path = await import('node:path'); const url = await import('node:url'); const os = await import('node:os'); const crypto = await import('node:crypto');
|
|
@@ -1027,11 +1039,11 @@ async function gateInit({ yes = false, remove = false, mode = 'warn', shared = f
|
|
|
1027
1039
|
if (present < 0 && !Object.keys(marker[K.filesKey] ?? {}).length && !ignOurs) return `${K.Name} is not set up here by lode init. Nothing to remove.`;
|
|
1028
1040
|
if (present >= 0) lines.push(` ${settingsRel}: remove ${K.entryLabel} (other settings unchanged)${ours?.created ? '; delete the file if nothing else is left in it' : ''}`);
|
|
1029
1041
|
if (Object.keys(marker[K.filesKey] ?? {}).length) lines.push(` ${skillRel}/: delete ${K.filesLabel} lode init copied, if unchanged`);
|
|
1030
|
-
const handOver = ignOurs &&
|
|
1031
|
-
if (ignOurs) lines.push(handOver ? ` ${ignoreRel}: keep its two lines, since ${
|
|
1042
|
+
const handOver = ignOurs && heir();
|
|
1043
|
+
if (ignOurs) lines.push(handOver ? ` ${ignoreRel}: keep its two lines, since ${handOver.name} still uses ${ALLOWED_SETTINGS[0]}` : ` ${ignoreRel}: remove the two lines lode init added, if they are still there${ignOurs.created ? '; delete the file if nothing else is left in it' : ''}`);
|
|
1032
1044
|
} else {
|
|
1033
1045
|
if (present >= 0) return `${K.Name} is already on in this project. Turn it off with: ${gateCmd(true)}`;
|
|
1034
|
-
lines.push(` ${settingsRel}: ${text == null ? 'create it with' : 'add'} one ${K.event} hook entry that runs ${K.name} on shell commands${K.modes && mode === 'ask' ? ' in ask mode (a warning sends the install to the permission prompt)' : ` ${K.does}`}${text == null ? '' : ' (other settings unchanged)'}${shared ? `; this file is shared, so everyone who opens the project with Claude Code gets ${K.name}` : '; only for you (kept out of git)'}`);
|
|
1046
|
+
lines.push(` ${settingsRel}: ${text == null ? 'create it with' : 'add'} one ${K.event} hook entry that runs ${K.name} ${K.hookOn ?? 'on shell commands'}${K.modes && mode === 'ask' ? ' in ask mode (a warning sends the install to the permission prompt)' : ` ${K.does}`}${text == null ? '' : ' (other settings unchanged)'}${shared ? `; this file is shared, so everyone who opens the project with Claude Code gets ${K.name}` : '; only for you (kept out of git)'}`);
|
|
1035
1047
|
const missing = GATE_FILES.filter((f) => !fs.existsSync(path.join(skillDst, f)));
|
|
1036
1048
|
if (missing.length && path.resolve(skillSrc) !== path.resolve(skillDst)) lines.push(` ${skillRel}/: copy ${missing.join(', ')} (no dependencies, nothing runs on install)`);
|
|
1037
1049
|
if (ign?.need) lines.push(` ${ignoreRel}: ${ign.text == null ? 'create it with' : 'add at the end'} two lines (a comment and ${GATE_IGNORE_LINE}), so git never picks up this hook for teammates`);
|
|
@@ -1046,20 +1058,23 @@ async function gateInit({ yes = false, remove = false, mode = 'warn', shared = f
|
|
|
1046
1058
|
if (!Object.keys(next.hooks).length) delete next.hooks;
|
|
1047
1059
|
if (ours?.created && !Object.keys(next).length) fs.rmSync(settingsFile); else fs.writeFileSync(settingsFile, JSON.stringify(next, null, indent) + '\n');
|
|
1048
1060
|
// The other hook now owns the file this one created, so removing it later deletes the file if nothing else is left
|
|
1049
|
-
|
|
1061
|
+
const owner = others.find((o) => marker[o.key]?.file === settingsRel);
|
|
1062
|
+
if (ours?.created && owner) marker[owner.key].created = true;
|
|
1050
1063
|
}
|
|
1051
1064
|
// Only files from the fixed list, inside the skill folder, not through links, regular files, unchanged
|
|
1052
1065
|
for (const [rel, h] of Object.entries(marker[K.filesKey] ?? {})) {
|
|
1053
1066
|
if (!GATE_FILES.includes(rel) || !safe(path.join(skillRel, rel))) continue;
|
|
1054
1067
|
// A file the other hook also needs stays while that hook is on, and becomes the other hook's to remove (LOD-278)
|
|
1055
|
-
|
|
1068
|
+
const keeper = others.find((o) => marker[o.key] && o.files.map((x) => x.split('/').join(path.sep)).includes(rel));
|
|
1069
|
+
if (keeper) { marker[keeper.filesKey] = { ...(marker[keeper.filesKey] ?? {}), [rel]: h }; continue; }
|
|
1056
1070
|
const f = path.join(skillDst, rel);
|
|
1057
1071
|
if (!path.resolve(f).startsWith(path.resolve(skillDst) + path.sep)) continue;
|
|
1058
1072
|
try { if (fs.lstatSync(f).isFile() && hash(f) === h) fs.rmSync(f); } catch { /* gone */ }
|
|
1059
1073
|
}
|
|
1060
1074
|
for (const d of [path.join(skillDst, 'scripts'), skillDst, path.dirname(skillDst)]) { try { if (!fs.lstatSync(d).isSymbolicLink() && !fs.readdirSync(d).length) fs.rmdirSync(d); } catch { /* not empty */ } }
|
|
1061
|
-
|
|
1062
|
-
|
|
1075
|
+
const ignHeir = ignOurs && heir();
|
|
1076
|
+
if (ignHeir) {
|
|
1077
|
+
marker[ignHeir.key].ignore = ignOurs; // that hook still needs settings.local.json kept out of git
|
|
1063
1078
|
} else if (ignOurs) {
|
|
1064
1079
|
const ir = gateReadText(fs, ignoreFile);
|
|
1065
1080
|
const t = ir.text ?? '';
|
|
@@ -1117,13 +1132,14 @@ export const RULES_MDC = rulesMdc(RULE);
|
|
|
1117
1132
|
// Every block and rule file a released init has written, newest first.
|
|
1118
1133
|
export const KNOWN_BLOCKS = [RULES_BLOCK, rulesBlock(RULE_V1)];
|
|
1119
1134
|
export const KNOWN_MDCS = [RULES_MDC, rulesMdc(RULE_V1)];
|
|
1120
|
-
async function initCmd({ client = 'all', yes = false, remove = false, gate = false, triage = false, gateMode = 'warn', gateShared = false, rules = true, src = null } = {}) {
|
|
1135
|
+
async function initCmd({ client = 'all', yes = false, remove = false, gate = false, triage = false, verify = false, gateMode = 'warn', gateShared = false, rules = true, agentsMd = true, src = null } = {}) {
|
|
1121
1136
|
const serverUrl = src === 'setup' ? SETUP_URL : LODE_URL;
|
|
1122
1137
|
// The command the user or agent should run next: npx trylode's own when called through it (security review
|
|
1123
1138
|
// 01-12-2026: a project has no lode.mjs, so pointing an agent at it failed or wrote the untagged address).
|
|
1124
1139
|
const runCmd = (rm) => (src === 'setup' ? `npx trylode ${rm ? 'remove' : 'setup'}` : `node lode.mjs init${rm ? ' --remove' : ''}`);
|
|
1125
1140
|
if (gate) return gateInit({ yes, remove, mode: gateMode, shared: gateShared, src });
|
|
1126
1141
|
if (triage) return gateInit({ yes, remove, shared: gateShared, src, kind: 'triage' });
|
|
1142
|
+
if (verify) return gateInit({ yes, remove, shared: gateShared, src, kind: 'verify' });
|
|
1127
1143
|
const fs = await import('node:fs'); const path = await import('node:path'); const url = await import('node:url'); const os = await import('node:os'); const crypto = await import('node:crypto');
|
|
1128
1144
|
const cwd = fs.realpathSync(process.cwd());
|
|
1129
1145
|
// Only inside a project: never the home folder or the root, and only where a project marker exists (security review 27-11-2026)
|
|
@@ -1204,7 +1220,8 @@ async function initCmd({ client = 'all', yes = false, remove = false, gate = fal
|
|
|
1204
1220
|
if (!safe(skillRel)) refused.push(`${skillRel}: it or a folder above it is a link, so lode init won't touch it.`);
|
|
1205
1221
|
else if (remove && Object.keys(marker.skill_files || {}).length) plan.push({ do: 'remove-skill', file: skillRel });
|
|
1206
1222
|
else if (!remove && !skillThere && path.resolve(skillSrc) !== path.resolve(skillDst)) plan.push({ do: 'copy-skill', file: skillRel });
|
|
1207
|
-
// The rules line: one fixed block in CLAUDE.md
|
|
1223
|
+
// The rules line: one fixed block in CLAUDE.md and AGENTS.md (each created if missing; AGENTS.md left alone with
|
|
1224
|
+
// --no-agents-md, LOD-287, Paul 03-12-2026), and its own
|
|
1208
1225
|
// Cursor rule file. A fixed list of files, never paths read from the marker; --remove takes out only the exact block
|
|
1209
1226
|
// (or the exact rule file) init writes, and deletes a file only when nothing else is left in it.
|
|
1210
1227
|
// Security review 30-11-2026 (rules line): every instruction file is untrusted. It is checked for links BEFORE it is
|
|
@@ -1231,7 +1248,7 @@ async function initCmd({ client = 'all', yes = false, remove = false, gate = fal
|
|
|
1231
1248
|
};
|
|
1232
1249
|
if (rules || remove) {
|
|
1233
1250
|
const ruleTargets = [];
|
|
1234
|
-
if (remove || client === 'all' || client === 'claude') ruleTargets.push({ file: 'CLAUDE.md', kind: 'md', create: true }, { file: 'AGENTS.md', kind: 'md', create:
|
|
1251
|
+
if (remove || client === 'all' || client === 'claude') ruleTargets.push({ file: 'CLAUDE.md', kind: 'md', create: true }, { file: 'AGENTS.md', kind: 'md', create: agentsMd });
|
|
1235
1252
|
if (remove || client === 'all' || client === 'cursor') ruleTargets.push({ file: path.join('.cursor', 'rules', 'lode.mdc'), kind: 'mdc', create: true });
|
|
1236
1253
|
for (const t of ruleTargets) {
|
|
1237
1254
|
const f = path.join(cwd, t.file);
|
|
@@ -1260,7 +1277,7 @@ async function initCmd({ client = 'all', yes = false, remove = false, gate = fal
|
|
|
1260
1277
|
: p.do === 'copy-skill' ? ` ${p.file}/: copy the Lode Integration Check skill (SKILL.md, PERMISSIONS.md, scripts/lode.mjs; no dependencies, nothing runs on install)`
|
|
1261
1278
|
: ` ${p.file}/: delete the skill files lode init copied, if unchanged`);
|
|
1262
1279
|
if (!remove) lines.push(` ${markerRel}: a small note of what lode init added, so --remove undoes only that`);
|
|
1263
|
-
if (!yes) return `lode init would ${remove ? 'change' : 'write'} these files in ${cwd}:\n${lines.join('\n')}${refusedText}\nNothing has been written and nothing is sent to Lode. If the user agrees, run: ${runCmd(remove)}${client !== 'all' ? ` --client ${client}` : ''}${!remove && !rules ? ' --no-rules' : ''} --yes${!remove && rules && plan.some((p) => p.do === 'rules-add') ?
|
|
1280
|
+
if (!yes) return `lode init would ${remove ? 'change' : 'write'} these files in ${cwd}:\n${lines.join('\n')}${refusedText}\nNothing has been written and nothing is sent to Lode. If the user agrees, run: ${runCmd(remove)}${client !== 'all' ? ` --client ${client}` : ''}${!remove && !rules ? ' --no-rules' : ''}${!remove && rules && !agentsMd ? ' --no-agents-md' : ''} --yes${!remove && rules && plan.some((p) => p.do === 'rules-add') ? ` (add --no-rules to leave out the rules line${plan.some((p) => p.do === 'rules-add' && p.file === 'AGENTS.md' && p.text == null) ? ', or --no-agents-md to leave out the new AGENTS.md' : ''})` : ''}`;
|
|
1264
1281
|
const write = (p, next) => {
|
|
1265
1282
|
if (p.st) { const now = fs.lstatSync(p.f); if (!now.isFile() || now.nlink > 1 || now.ino !== p.st.ino) throw new Error(`${p.file} changed while init ran`); }
|
|
1266
1283
|
const out = JSON.stringify(next, null, p.indent) + '\n';
|
|
@@ -1559,17 +1576,27 @@ export async function main(argv) {
|
|
|
1559
1576
|
return triageCmd(rest[0], rest[1], opts);
|
|
1560
1577
|
}
|
|
1561
1578
|
if (cmd === 'init') {
|
|
1562
|
-
const opts = { client: flag('--client'), yes: flag('--yes'), remove: flag('--remove'), gate: flag('--gate'), triage: flag('--triage'), mode: flag('--mode'), shared: flag('--shared'), noRules: flag('--no-rules'), src: flag('--src') };
|
|
1579
|
+
const opts = { client: flag('--client'), yes: flag('--yes'), remove: flag('--remove'), gate: flag('--gate'), triage: flag('--triage'), verify: flag('--verify'), mode: flag('--mode'), shared: flag('--shared'), noRules: flag('--no-rules'), noAgentsMd: flag('--no-agents-md'), src: flag('--src') };
|
|
1563
1580
|
const client = ['claude', 'cursor', 'all'].includes(opts.client) ? opts.client : 'all';
|
|
1564
|
-
return initCmd({ client, yes: opts.yes === true, remove: opts.remove === true, gate: opts.gate === true, triage: opts.gate !== true && opts.triage === true, gateMode: opts.mode === 'ask' ? 'ask' : 'warn', gateShared: opts.shared === true, rules: opts.noRules !== true, src: opts.src === 'setup' ? 'setup' : null });
|
|
1581
|
+
return initCmd({ client, yes: opts.yes === true, remove: opts.remove === true, gate: opts.gate === true, triage: opts.gate !== true && opts.triage === true, verify: opts.gate !== true && opts.triage !== true && opts.verify === true, gateMode: opts.mode === 'ask' ? 'ask' : 'warn', gateShared: opts.shared === true, rules: opts.noRules !== true, agentsMd: opts.noAgentsMd !== true, src: opts.src === 'setup' ? 'setup' : null });
|
|
1565
1582
|
}
|
|
1566
1583
|
if (cmd === 'watch') {
|
|
1567
1584
|
const opts = { share: flag('--share'), projectCode: flag('--project-code'), since: flag('--since') };
|
|
1568
1585
|
const sub = ['changes', 'stop'].includes(rest[0]) ? rest[0] : 'start';
|
|
1569
1586
|
return watchCmd(sub, { share: opts.share === true, projectCode: opts.projectCode === true, since: opts.since });
|
|
1570
1587
|
}
|
|
1588
|
+
// Lode verify (v0): this project's packages on Lode's list against Lode's facts; exit code 1 only for --fail-on codes
|
|
1589
|
+
if (cmd === 'verify') {
|
|
1590
|
+
let v; try { v = await import('./verify.mjs'); } catch { return 'Lode verify is not in this copy of the skill (scripts/verify.mjs is missing). Install it with: npx trylode setup --verify, or run: npx trylode verify'; }
|
|
1591
|
+
const fo = flag('--fail-on'), since = flag('--since');
|
|
1592
|
+
const failOn = v.parseFailOn(typeof fo === 'string' ? fo : '');
|
|
1593
|
+
if (failOn.error) return `Unknown --fail-on code "${failOn.error}". Use act, any or codes from: ${v.CODES.join(', ')}`;
|
|
1594
|
+
const res = await v.verify(process.cwd(), { since: typeof since === 'string' ? since : undefined, run: v.runCode(process.env) });
|
|
1595
|
+
if (v.failing(res, failOn).length) process.exitCode = 1;
|
|
1596
|
+
return v.format(res, failOn);
|
|
1597
|
+
}
|
|
1571
1598
|
if (cmd === 'platforms') return `Lode covers: ${Object.keys(PLATFORMS).join(', ')}. Facts are source-linked and dated; see https://trylode.io/methodology/`;
|
|
1572
|
-
return 'Usage:\n node lode.mjs check <app> [platform]\n node lode.mjs triage <app> <platform> --symptom <code> [--status 429] [--object o]\n node lode.mjs init [--client claude|cursor|all] [--no-rules] [--yes] [--remove]\n node lode.mjs init --gate [--mode ask] [--shared] [--yes] [--remove]\n node lode.mjs init --triage [--shared] [--yes] [--remove]\n node lode.mjs find <platform> [--category c] [--needs a,b] [--region XX] [--stack a,b] [--framework f]\n node lode.mjs list <platform> [--category <c>] [--all]\n node lode.mjs chose <app|none> <platform> [--considered "A,B"] [--reason code] [--share]\n node lode.mjs outcome <app> <platform> <integrated|failed|abandoned|not-tried> [--failure-reason code] [--share]\n node lode.mjs request <app> <platform> [--needs a,b] [--region XX]\n node lode.mjs overlap <platform> --apps "A,B,C" [--region XX] [--share]\n node lode.mjs recheck [--share]\n node lode.mjs drop <app> <platform> [--reason code] [--switched-to <app>] [--share]\n node lode.mjs adr <platform> --considered "A,B" --chose B [--reason code] [--status s] [--constraint a,b] [--workaround a,b] [--share]\n node lode.mjs adr --update <file> [--status s] [--constraint a,b] [--workaround a,b] [--share]\n node lode.mjs stack [--framework f] [--share]\n node lode.mjs watch [--share] [--project-code] | watch changes [--since d] | watch stop\n node lode.mjs platforms';
|
|
1599
|
+
return 'Usage:\n node lode.mjs check <app> [platform]\n node lode.mjs triage <app> <platform> --symptom <code> [--status 429] [--object o]\n node lode.mjs init [--client claude|cursor|all] [--no-rules] [--yes] [--remove]\n node lode.mjs init --gate [--mode ask] [--shared] [--yes] [--remove]\n node lode.mjs init --triage [--shared] [--yes] [--remove]\n node lode.mjs init --verify [--shared] [--yes] [--remove]\n node lode.mjs verify [--fail-on act|any|code,code] [--since YYYY-MM-DD]\n node lode.mjs find <platform> [--category c] [--needs a,b] [--region XX] [--stack a,b] [--framework f]\n node lode.mjs list <platform> [--category <c>] [--all]\n node lode.mjs chose <app|none> <platform> [--considered "A,B"] [--reason code] [--share]\n node lode.mjs outcome <app> <platform> <integrated|failed|abandoned|not-tried> [--failure-reason code] [--share]\n node lode.mjs request <app> <platform> [--needs a,b] [--region XX]\n node lode.mjs overlap <platform> --apps "A,B,C" [--region XX] [--share]\n node lode.mjs recheck [--share]\n node lode.mjs drop <app> <platform> [--reason code] [--switched-to <app>] [--share]\n node lode.mjs adr <platform> --considered "A,B" --chose B [--reason code] [--status s] [--constraint a,b] [--workaround a,b] [--share]\n node lode.mjs adr --update <file> [--status s] [--constraint a,b] [--workaround a,b] [--share]\n node lode.mjs stack [--framework f] [--share]\n node lode.mjs watch [--share] [--project-code] | watch changes [--since d] | watch stop\n node lode.mjs platforms';
|
|
1573
1600
|
}
|
|
1574
1601
|
|
|
1575
1602
|
// Run only when this very file is the entry point (security review 01-12-2026: endsWith('lode.mjs') also matched trylode.mjs).
|
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Lode verify (v0; LOD-259 and the 03-12-2026 verification-layer proposal on LOD-83): checks a project's integrations
|
|
3
|
+
// against Lode's facts. One engine, three places: a command (`node verify.mjs`, `npx trylode verify`), a CI step
|
|
4
|
+
// (`--fail-on` sets the exit code; the team decides what fails, Lode only returns facts) and an opt-in Claude Code
|
|
5
|
+
// Stop hook (`--hook`, switched on by `node lode.mjs init --verify --yes` or `npx trylode setup --verify --yes`).
|
|
6
|
+
//
|
|
7
|
+
// What it reads, on this machine only: package.json, package-lock.json (installed versions), requirements.txt and
|
|
8
|
+
// pyproject.toml, never through links, at most a few MB each; whether platform config files exist (names only).
|
|
9
|
+
// What it sends, only when the project uses a package on Lode's list (gate-packages.json): one or more
|
|
10
|
+
// POST https://trylode.io/v1/gate with those package names and the platform codes, with "log": false so Lode keeps
|
|
11
|
+
// nothing but the daily rate-limit count; the first of those requests also carries one run code (`hook`, `cli` or `ci`),
|
|
12
|
+
// and Lode keeps only that code and the date (LOD-292); and one GET of the public change feed
|
|
13
|
+
// https://trylode.io/api/changes.json. Never versions, paths, file contents, the session id or anything else. Installed versions are compared with the
|
|
14
|
+
// advisory ranges Lode returns here, on this machine.
|
|
15
|
+
// Fail open: offline, slow or a bad answer gives no findings and exit code 0, so Lode can never break a build or
|
|
16
|
+
// keep an agent from stopping. No dependencies (Node 18+).
|
|
17
|
+
import fs from 'node:fs';
|
|
18
|
+
import path from 'node:path';
|
|
19
|
+
import os from 'node:os';
|
|
20
|
+
import crypto from 'node:crypto';
|
|
21
|
+
import { fileURLToPath } from 'node:url';
|
|
22
|
+
|
|
23
|
+
const VERSION = '0.1';
|
|
24
|
+
// Lode's own tests may point verify at this machine; nothing else can change where it sends (same rule as Gate).
|
|
25
|
+
const BASE = (() => { const u = process.env.LODE_VERIFY_URL || ''; return /^http:\/\/(127\.0\.0\.1|localhost)(:\d+)?$/.test(u) ? u : 'https://trylode.io'; })();
|
|
26
|
+
const UA = /^lode-verify-test(\/[\w.-]+)?$/.test(process.env.LODE_UA || '') ? process.env.LODE_UA : `lode-verify/${VERSION}`;
|
|
27
|
+
export const BUDGET_MS = 2500;
|
|
28
|
+
export const MAX_PACKAGES = 30; // three Gate requests of 10 at most
|
|
29
|
+
const MAX_REASON = 2400;
|
|
30
|
+
|
|
31
|
+
// Platforms told apart by a config file's name only (kept equal to gate.mjs and Lode's src/lib/gate.mjs by a test)
|
|
32
|
+
export const PLATFORM_FILES = { vercel: ['vercel.json', '.vercel/project.json'], netlify: ['netlify.toml'], supabase: ['supabase/config.toml'], cloudflare: ['wrangler.toml', 'wrangler.json', 'wrangler.jsonc'] };
|
|
33
|
+
// Codes verify can report. `act` codes are new facts a person should hear about (the hook stops the agent once for
|
|
34
|
+
// each); `note` codes are listed but never stop the agent. Codes are never reworded; new ones go at the end.
|
|
35
|
+
export const ACT = ['sdk-deprecated', 'installed-affected', 'plan-needed'];
|
|
36
|
+
export const NOTE = ['latest-affected', 'region-limited', 'no-record-on-platform', 'held-record', 'changed-recently'];
|
|
37
|
+
export const CODES = [...ACT, ...NOTE];
|
|
38
|
+
export const SAY = {
|
|
39
|
+
'sdk-deprecated': 'the package is marked deprecated by its publisher',
|
|
40
|
+
'installed-affected': 'the installed version is inside a published security advisory',
|
|
41
|
+
'plan-needed': 'the integration needs a paid platform plan',
|
|
42
|
+
'latest-affected': "the registry's latest version is inside a published security advisory",
|
|
43
|
+
'region-limited': 'only some regions are documented',
|
|
44
|
+
'no-record-on-platform': 'Lode has no record of it on this platform (not documented, not unsupported)',
|
|
45
|
+
'held-record': "Lode's record is not yet verified enough to publish",
|
|
46
|
+
'changed-recently': 'Lode recorded a change to this integration recently',
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// ---------- Reading the project (every file is untrusted) ----------
|
|
50
|
+
// A regular file with one name, under `max` bytes, reached without any link in its path, opened without following a
|
|
51
|
+
// link or blocking (a FIFO or a link to /dev/zero can't hang it), checked again once open. Text, or null.
|
|
52
|
+
export function safeRead(root, rel, max) {
|
|
53
|
+
let p = root;
|
|
54
|
+
const parts = rel.split('/');
|
|
55
|
+
for (let i = 0; i < parts.length; i++) {
|
|
56
|
+
p = path.join(p, parts[i]);
|
|
57
|
+
let st; try { st = fs.lstatSync(p); } catch { return null; }
|
|
58
|
+
if (st.isSymbolicLink()) return null;
|
|
59
|
+
if (i < parts.length - 1 ? !st.isDirectory() : (!st.isFile() || st.nlink > 1 || st.size > max)) return null;
|
|
60
|
+
}
|
|
61
|
+
let ino; try { ino = fs.lstatSync(p).ino; } catch { return null; }
|
|
62
|
+
let fd; try { fd = fs.openSync(p, fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW ?? 0) | (fs.constants.O_NONBLOCK ?? 0)); } catch { return null; }
|
|
63
|
+
try { const st = fs.fstatSync(fd); if (!st.isFile() || st.size > max || st.ino !== ino) return null; return fs.readFileSync(fd, 'utf8'); } catch { return null; } finally { fs.closeSync(fd); }
|
|
64
|
+
}
|
|
65
|
+
const exists = (root, rel) => { let p = root; for (const part of rel.split('/')) { p = path.join(p, part); try { if (fs.lstatSync(p).isSymbolicLink()) return false; } catch { return false; } } return true; };
|
|
66
|
+
|
|
67
|
+
const NPM_NAME = /^(@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/;
|
|
68
|
+
// The suffix is capped (security review 03-12-2026): a version is project text and is shown in the hook's message.
|
|
69
|
+
const VER = /^\d{1,6}\.\d{1,6}\.\d{1,6}([-+][0-9A-Za-z.-]{1,24})?$/;
|
|
70
|
+
const normPypi = (n) => String(n).toLowerCase().replace(/[-_.]+/g, '-');
|
|
71
|
+
const parseJson = (t) => { try { const j = JSON.parse(t); return j && typeof j === 'object' && !Array.isArray(j) ? j : null; } catch { return null; } };
|
|
72
|
+
|
|
73
|
+
// The inside of each `dependencies = [ ... ]` / `requires = [ ... ]` list, found in one pass (security review
|
|
74
|
+
// 03-12-2026: a regex over unclosed brackets was quadratic). Shared shape with parsePyproject in lode.mjs.
|
|
75
|
+
export function tomlLists(text) {
|
|
76
|
+
const out = []; const head = /^[ \t]*(?:dependencies|requires)[ \t]*=[ \t]*\[/gm; let m;
|
|
77
|
+
while ((m = head.exec(text))) { const end = text.indexOf(']', head.lastIndex); if (end < 0) break; out.push(text.slice(head.lastIndex, end)); head.lastIndex = end + 1; }
|
|
78
|
+
return out;
|
|
79
|
+
}
|
|
80
|
+
export function readProject(root) {
|
|
81
|
+
const npm = new Map(); const pypi = new Map(); const read = [];
|
|
82
|
+
const pkg = parseJson(safeRead(root, 'package.json', 1024 * 1024));
|
|
83
|
+
if (pkg) {
|
|
84
|
+
read.push('package.json');
|
|
85
|
+
for (const k of ['dependencies', 'devDependencies', 'optionalDependencies']) {
|
|
86
|
+
const deps = pkg[k];
|
|
87
|
+
if (!deps || typeof deps !== 'object' || Array.isArray(deps)) continue;
|
|
88
|
+
for (const [n, v] of Object.entries(deps)) { const name = n.toLowerCase(); if (NPM_NAME.test(name) && !npm.has(name)) npm.set(name, typeof v === 'string' && VER.test(v) ? v : null); }
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (npm.size) {
|
|
92
|
+
const lock = parseJson(safeRead(root, 'package-lock.json', 20 * 1024 * 1024));
|
|
93
|
+
if (lock) {
|
|
94
|
+
read.push('package-lock.json');
|
|
95
|
+
for (const name of npm.keys()) {
|
|
96
|
+
const v = lock.packages?.[`node_modules/${name}`]?.version ?? lock.dependencies?.[name]?.version;
|
|
97
|
+
if (typeof v === 'string' && VER.test(v)) npm.set(name, v);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const req = safeRead(root, 'requirements.txt', 1024 * 1024);
|
|
102
|
+
if (req != null) {
|
|
103
|
+
read.push('requirements.txt');
|
|
104
|
+
for (const line of req.split('\n').slice(0, 5000)) {
|
|
105
|
+
const m = /^\s*([A-Za-z0-9][A-Za-z0-9._-]{0,100})(\[[^\]]{0,200}\])?\s*(==\s*(\d+(\.\d+){0,5}))?/.exec(line.replace(/#.*/, ''));
|
|
106
|
+
if (m && !line.trim().startsWith('-')) { const n = normPypi(m[1]); if (!pypi.has(n) || m[4]) pypi.set(n, m[4] ?? null); }
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const py = safeRead(root, 'pyproject.toml', 256 * 1024); // smaller cap: keeps a hostile file's parse well under a second
|
|
110
|
+
if (py != null) {
|
|
111
|
+
read.push('pyproject.toml');
|
|
112
|
+
for (const block of tomlLists(py)) for (const q of block.matchAll(/["']([A-Za-z0-9][A-Za-z0-9._-]{0,100})[^"']{0,200}["']/g)) { const n = normPypi(q[1]); if (!pypi.has(n)) pypi.set(n, null); }
|
|
113
|
+
}
|
|
114
|
+
const platforms = Object.keys(PLATFORM_FILES).filter((p) => PLATFORM_FILES[p].some((f) => exists(root, f)));
|
|
115
|
+
return { npm, pypi, platforms, read };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function loadList(dir = path.dirname(fileURLToPath(import.meta.url))) {
|
|
119
|
+
try { const j = JSON.parse(fs.readFileSync(path.join(dir, 'gate-packages.json'), 'utf8')); return { npm: new Set(j.npm ?? []), pypi: new Set(j.pypi ?? []) }; } catch { return { npm: new Set(), pypi: new Set() }; }
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// The packages verify asks about: only names on Lode's list, with the installed version (kept here, never sent).
|
|
123
|
+
export function matched(project, list) {
|
|
124
|
+
const out = [];
|
|
125
|
+
for (const [system, m] of [['npm', project.npm], ['pypi', project.pypi]]) for (const [name, installed] of m) if (list[system]?.has(name)) out.push({ system, name, installed });
|
|
126
|
+
return out.sort((a, b) => (a.system + a.name < b.system + b.name ? -1 : 1)).slice(0, MAX_PACKAGES);
|
|
127
|
+
}
|
|
128
|
+
// What the hook compares between runs: the packages on Lode's list, their versions and the platforms.
|
|
129
|
+
export const projectKey = (pkgs, platforms) => crypto.createHash('sha256').update(JSON.stringify([pkgs.map((p) => [p.system, p.name, p.installed]), platforms])).digest('hex').slice(0, 24);
|
|
130
|
+
|
|
131
|
+
// ---------- Lode's answer (untrusted text) ----------
|
|
132
|
+
const clean = (t, n = 300) => String(t ?? '').replace(/[\p{Cc}\p{Cf}\p{Co}\p{Cn}]/gu, ' ').replace(/\s+/g, ' ').trim().slice(0, n);
|
|
133
|
+
const OK_HOSTS = ['trylode.io', 'www.npmjs.com', 'pypi.org', 'osv.dev'];
|
|
134
|
+
const looksSafe = (t) => !/[`$<>{}\\]|\|\s*\w|\b(curl|wget|bash|sh|sudo|rm|chmod|eval|exec|powershell|iex)\b|(^|[\s(\[])\/\/|\b(javascript|vbscript):|\bdata:[a-z]+\/|\bfile:\/\//i.test(t)
|
|
135
|
+
&& [...t.matchAll(/https?:\/\/([^/\s)\]]+)/gi)].every((m) => OK_HOSTS.includes(m[1].toLowerCase()));
|
|
136
|
+
const ID = /^[A-Za-z0-9-]{3,40}$/;
|
|
137
|
+
const RECORD = /^[a-z0-9][a-z0-9-]{0,80}--[a-z0-9][a-z0-9-]{0,40}$/;
|
|
138
|
+
|
|
139
|
+
// Same comparison as gate.mjs (kept equal by a test): numbers first, a pre-release sorts before its release.
|
|
140
|
+
function cmp(a, b) {
|
|
141
|
+
const split = (v) => { const m = /^(\d+(?:\.\d+)*)(.*)$/.exec(String(v).replace(/^v/, '').split('+')[0]) || [null, '0', String(v)]; return [m[1].split('.').map(Number), m[2].replace(/^[-.]/, '')]; };
|
|
142
|
+
const [na, pa] = split(a), [nb, pb] = split(b);
|
|
143
|
+
for (let i = 0; i < Math.max(na.length, nb.length); i++) { const d = (na[i] || 0) - (nb[i] || 0); if (d) return d < 0 ? -1 : 1; }
|
|
144
|
+
if (pa === pb) return 0;
|
|
145
|
+
if (!pa) return 1;
|
|
146
|
+
if (!pb) return -1;
|
|
147
|
+
return pa < pb ? -1 : 1;
|
|
148
|
+
}
|
|
149
|
+
export function affected(version, ranges) {
|
|
150
|
+
if (!version || !Array.isArray(ranges)) return [];
|
|
151
|
+
return [...new Set(ranges.filter((r) => r && typeof r.id === 'string' && ID.test(r.id)
|
|
152
|
+
&& (!r.introduced || r.introduced === '0' || cmp(version, r.introduced) >= 0)
|
|
153
|
+
&& (r.fixed ? cmp(version, r.fixed) < 0 : r.last_affected ? cmp(version, r.last_affected) <= 0 : true)).map((r) => r.id))].slice(0, 3);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Gate's answer plus recent changes -> one finding per package: { system, package, name, codes, facts, records }
|
|
157
|
+
export function findings(pkgs, answers, changes = [], { since } = {}) {
|
|
158
|
+
const out = [];
|
|
159
|
+
const byKey = new Map(pkgs.map((p) => [`${p.system}:${p.name}`, p]));
|
|
160
|
+
for (const a of answers) {
|
|
161
|
+
if (!a || typeof a !== 'object') continue;
|
|
162
|
+
const p = byKey.get(`${a.system}:${a.package}`);
|
|
163
|
+
if (!p) continue;
|
|
164
|
+
const codes = new Set((Array.isArray(a.warnings) ? a.warnings : []).filter((w) => CODES.includes(w)));
|
|
165
|
+
const facts = (Array.isArray(a.facts) ? a.facts.slice(0, 6) : []).map((f) => clean(f)).filter((t) => t && looksSafe(t));
|
|
166
|
+
// The installed version is checked here; with a known installed version the registry's latest tag is not the
|
|
167
|
+
// version in use, so its advisory becomes a note only when nothing is installed
|
|
168
|
+
if (p.installed) {
|
|
169
|
+
codes.delete('latest-affected');
|
|
170
|
+
const ids = affected(p.installed, a.sdk?.affected);
|
|
171
|
+
if (ids.length) { codes.add('installed-affected'); facts.unshift(clean(`${p.name} ${p.installed} (installed, from this project's files) is inside ${ids.join(', ')} per OSV.dev. https://osv.dev/vulnerability/${ids[0]}`)); }
|
|
172
|
+
}
|
|
173
|
+
const records = (Array.isArray(a.records) ? a.records : []).map((r) => r?.id).filter((id) => typeof id === 'string' && RECORD.test(id));
|
|
174
|
+
const cutoff = since ? Date.parse(since) : NaN;
|
|
175
|
+
for (const e of changes) {
|
|
176
|
+
if (!e || !records.includes(e.record_id) || (Number.isFinite(cutoff) && !(Date.parse(e.observed_at) >= cutoff))) continue;
|
|
177
|
+
const t = clean(e.summary); const url = typeof e.url === 'string' && /^https:\/\/trylode\.io\/[A-Za-z0-9._~\/?=&%-]{0,200}$/.test(e.url) ? e.url : '';
|
|
178
|
+
const day = /^\d{4}-\d{2}-\d{2}/.test(String(e.observed_at)) ? String(e.observed_at).slice(0, 10).split('-').reverse().join('-') : '';
|
|
179
|
+
if (t && looksSafe(t) && facts.length < 9) { codes.add('changed-recently'); facts.push(clean(`${t}${day ? ` (Lode, ${day})` : ''} ${url}`)); }
|
|
180
|
+
}
|
|
181
|
+
if (!codes.size) continue;
|
|
182
|
+
const nm = clean(a.name, 80);
|
|
183
|
+
out.push({ system: p.system, package: p.name, name: nm && looksSafe(nm) && /^[\p{L}\p{N} .&()'+_-]{1,40}$/u.test(nm) && nm.split(' ').length <= 5 ? nm : p.name, ...(p.installed ? { installed: p.installed } : {}), codes: CODES.filter((c) => codes.has(c)), facts, records });
|
|
184
|
+
}
|
|
185
|
+
return out;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async function post(fetchImpl, body, timeoutMs) {
|
|
189
|
+
try {
|
|
190
|
+
const res = await fetchImpl(`${BASE}/v1/gate?log=0`, { method: 'POST', headers: { 'content-type': 'application/json', 'user-agent': UA }, body: JSON.stringify(body), signal: AbortSignal.timeout(timeoutMs) });
|
|
191
|
+
if (!res.ok) return null;
|
|
192
|
+
const j = await res.json();
|
|
193
|
+
return Array.isArray(j?.packages) ? j.packages : null;
|
|
194
|
+
} catch { return null; }
|
|
195
|
+
}
|
|
196
|
+
async function recentChanges(fetchImpl, timeoutMs) {
|
|
197
|
+
try {
|
|
198
|
+
const res = await fetchImpl(`${BASE}/api/changes.json`, { headers: { 'user-agent': UA }, signal: AbortSignal.timeout(timeoutMs) });
|
|
199
|
+
if (!res.ok) return [];
|
|
200
|
+
const j = await res.json();
|
|
201
|
+
return Array.isArray(j?.events) ? j.events.slice(0, 200) : [];
|
|
202
|
+
} catch { return []; }
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// How this run was started, sent once per run with the first request (LOD-292): Lode keeps only this code and the date.
|
|
206
|
+
// Never reword a code; add new ones at the end.
|
|
207
|
+
export const RUN_CODES = ['hook', 'cli', 'ci'];
|
|
208
|
+
export const runCode = (env = {}) => (env.CI === 'true' ? 'ci' : 'cli');
|
|
209
|
+
|
|
210
|
+
// The whole check. { read, platforms, checked, reached, findings }. `run` is one of RUN_CODES; without one, the
|
|
211
|
+
// command's own default (ci when CI=true, else cli; `env` is read only for that).
|
|
212
|
+
export async function verify(root, { fetchImpl = globalThis.fetch, list = loadList(), since, timeoutMs = BUDGET_MS, run, env = process.env } = {}) {
|
|
213
|
+
const runAs = RUN_CODES.includes(run) ? run : runCode(env);
|
|
214
|
+
const project = readProject(root);
|
|
215
|
+
const pkgs = matched(project, list);
|
|
216
|
+
const base = { read: project.read, platforms: project.platforms, checked: pkgs.map((p) => `${p.system === 'pypi' ? 'pypi ' : ''}${p.name}`), key: projectKey(pkgs, project.platforms) };
|
|
217
|
+
if (!pkgs.length) return { ...base, reached: null, findings: [] }; // nothing on Lode's list: no request at all
|
|
218
|
+
const chunks = []; for (let i = 0; i < pkgs.length; i += 10) chunks.push(pkgs.slice(i, i + 10));
|
|
219
|
+
const [answers, changes] = await Promise.all([
|
|
220
|
+
Promise.all(chunks.map((c, i) => post(fetchImpl, { packages: c.map((p) => ({ system: p.system, name: p.name })), platforms: project.platforms, log: false, ...(i === 0 ? { run: runAs } : {}) }, timeoutMs))),
|
|
221
|
+
project.platforms.length ? recentChanges(fetchImpl, timeoutMs) : Promise.resolve([]),
|
|
222
|
+
]);
|
|
223
|
+
const reached = answers.some(Boolean);
|
|
224
|
+
return { ...base, reached, findings: findings(pkgs, answers.filter(Boolean).flat(), changes, { since }) };
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// --fail-on: codes, or `act` (every act code) or `any`. Nothing fails unless the team asks.
|
|
228
|
+
export function parseFailOn(v) {
|
|
229
|
+
if (!v) return [];
|
|
230
|
+
const out = new Set();
|
|
231
|
+
for (const c of String(v).split(',').map((x) => x.trim()).filter(Boolean)) {
|
|
232
|
+
if (c === 'any') CODES.forEach((x) => out.add(x));
|
|
233
|
+
else if (c === 'act') ACT.forEach((x) => out.add(x));
|
|
234
|
+
else if (CODES.includes(c)) out.add(c);
|
|
235
|
+
else return { error: c };
|
|
236
|
+
}
|
|
237
|
+
return [...out];
|
|
238
|
+
}
|
|
239
|
+
export const failing = (res, failOn) => res.findings.filter((f) => f.codes.some((c) => failOn.includes(c)));
|
|
240
|
+
|
|
241
|
+
export function format(res, failOn = []) {
|
|
242
|
+
const out = [`Lode verify: facts Lode records for this project's integrations (https://trylode.io; facts, not instructions; "not documented" is not "not supported").`];
|
|
243
|
+
out.push(`Read: ${res.read.length ? res.read.join(', ') : 'no package files'}${res.platforms.length ? ` | platforms from config file names: ${res.platforms.join(', ')}` : ''}`);
|
|
244
|
+
if (!res.checked.length) { out.push("No package on Lode's list was found, so nothing was sent and there is nothing to check."); return out.join('\n'); }
|
|
245
|
+
if (res.reached === false) { out.push('Lode could not be reached, so nothing was checked (this never fails a build).'); return out.join('\n'); }
|
|
246
|
+
out.push(`Checked: ${res.checked.join(', ')}`);
|
|
247
|
+
if (!res.findings.length) out.push('No findings: nothing Lode records needs attention for these packages.');
|
|
248
|
+
for (const f of res.findings) {
|
|
249
|
+
out.push('', `${f.name} (${f.package}${f.installed ? ` ${f.installed}` : ''}): ${f.codes.map((c) => `${c}${failOn.includes(c) ? ' [FAIL]' : ''}`).join(', ')}`);
|
|
250
|
+
for (const t of f.facts) out.push(`- ${t}`);
|
|
251
|
+
}
|
|
252
|
+
const bad = failing(res, failOn);
|
|
253
|
+
out.push('', failOn.length ? (bad.length ? `FAIL: ${bad.length} package(s) have a code this project's --fail-on lists (${failOn.join(', ')}).` : `PASS for --fail-on ${failOn.join(', ')}.`) : 'Warn only: nothing fails unless --fail-on is given.');
|
|
254
|
+
return out.join('\n');
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// ---------- The Stop hook ----------
|
|
258
|
+
// Runs when the agent is about to finish. It does nothing (and sends nothing) unless the packages on Lode's list, their
|
|
259
|
+
// versions or the platform files changed since its last run in this Claude Code session. Then, for each `act` finding
|
|
260
|
+
// not yet raised in this session, it stops the agent once with the facts so the user hears them; the same finding
|
|
261
|
+
// never stops it twice, so it can't loop: it also lets the agent finish whenever Claude Code says a Stop hook already
|
|
262
|
+
// stopped it (stop_hook_active), and stops it only once the state file is saved. `note` findings never stop it.
|
|
263
|
+
function stateFile(tmp, sessionId, root) {
|
|
264
|
+
if (typeof sessionId !== 'string' || !sessionId) return null;
|
|
265
|
+
return path.join(tmp, `lode-verify-${crypto.createHash('sha256').update(`${sessionId}\0${root}`).digest('hex').slice(0, 24)}`);
|
|
266
|
+
}
|
|
267
|
+
function readState(f) {
|
|
268
|
+
let fd;
|
|
269
|
+
try { fd = fs.openSync(f, fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW ?? 0) | (fs.constants.O_NONBLOCK ?? 0)); } catch (e) { return e.code === 'ENOENT' ? undefined : null; } // none yet, or a link or something else: send nothing
|
|
270
|
+
try {
|
|
271
|
+
const st = fs.fstatSync(fd);
|
|
272
|
+
if (!st.isFile() || st.size > 64 * 1024 || (typeof process.getuid === 'function' && st.uid !== process.getuid())) return null;
|
|
273
|
+
const j = JSON.parse(fs.readFileSync(fd, 'utf8'));
|
|
274
|
+
return typeof j?.key === 'string' && Array.isArray(j.seen) && j.seen.every((x) => typeof x === 'string') ? j : null;
|
|
275
|
+
} catch { return null; } finally { fs.closeSync(fd); }
|
|
276
|
+
}
|
|
277
|
+
// True only when the state is on disk: the hook stops the agent only after it can remember having done so
|
|
278
|
+
// (security review 03-12-2026: an unwritable temp folder looped the block)
|
|
279
|
+
function writeState(f, s) {
|
|
280
|
+
const tmpf = `${f}.${process.pid}`;
|
|
281
|
+
try {
|
|
282
|
+
fs.writeFileSync(tmpf, JSON.stringify(s), { mode: 0o600, flag: 'wx' });
|
|
283
|
+
fs.renameSync(tmpf, f);
|
|
284
|
+
return readState(f)?.key === s.key;
|
|
285
|
+
} catch { try { fs.rmSync(tmpf, { force: true }); } catch { /* none */ } return false; }
|
|
286
|
+
}
|
|
287
|
+
function tidy(tmp) {
|
|
288
|
+
try {
|
|
289
|
+
for (const n of fs.readdirSync(tmp)) if (/^lode-verify-[0-9a-f]{24}(\.\d+)?$/.test(n)) {
|
|
290
|
+
const g = path.join(tmp, n); const st = fs.lstatSync(g);
|
|
291
|
+
if (st.isFile() && (typeof process.getuid !== 'function' || st.uid === process.getuid()) && Date.now() - st.mtimeMs > 86400000) fs.rmSync(g);
|
|
292
|
+
}
|
|
293
|
+
} catch { /* best effort */ }
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export async function hook(input, { fetchImpl = globalThis.fetch, env = process.env, tmp = os.tmpdir(), list = loadList() } = {}) {
|
|
297
|
+
if (!input || typeof input !== 'object') return null;
|
|
298
|
+
// Claude Code's own loop guard: the agent is already continuing because a Stop hook stopped it, so let it finish
|
|
299
|
+
if (input.stop_hook_active === true) return null;
|
|
300
|
+
if (input.hook_event_name && input.hook_event_name !== 'Stop' && input.hook_event_name !== 'SubagentStop') return null;
|
|
301
|
+
const root = typeof env.CLAUDE_PROJECT_DIR === 'string' && env.CLAUDE_PROJECT_DIR ? env.CLAUDE_PROJECT_DIR : (typeof input.cwd === 'string' ? input.cwd : null);
|
|
302
|
+
if (!root || !path.isAbsolute(root)) return null;
|
|
303
|
+
const f = stateFile(tmp, input.session_id, root);
|
|
304
|
+
if (!f) return null;
|
|
305
|
+
const state = readState(f);
|
|
306
|
+
if (state === null) return null; // a planted or broken state file: send nothing
|
|
307
|
+
const project = readProject(root);
|
|
308
|
+
const pkgs = matched(project, list);
|
|
309
|
+
const key = projectKey(pkgs, project.platforms);
|
|
310
|
+
if (state?.key === key) return null; // nothing changed since the last run in this session
|
|
311
|
+
const seen = new Set(state?.seen ?? []);
|
|
312
|
+
if (!pkgs.length) { writeState(f, { key, seen: [...seen] }); tidy(tmp); return null; }
|
|
313
|
+
const res = await verify(root, { fetchImpl, list, timeoutMs: 1500, run: 'hook' });
|
|
314
|
+
if (res.reached === false) return null; // try again next time
|
|
315
|
+
const fresh = res.findings.map((x) => ({ ...x, act: x.codes.filter((c) => ACT.includes(c) && !seen.has(`${x.system}:${x.package}:${c}`)) })).filter((x) => x.act.length);
|
|
316
|
+
for (const x of fresh) for (const c of x.act) seen.add(`${x.system}:${x.package}:${c}`);
|
|
317
|
+
const saved = writeState(f, { key, seen: [...seen].slice(-500) });
|
|
318
|
+
tidy(tmp);
|
|
319
|
+
if (!fresh.length || !saved) return null; // never stop the agent without a saved record of it
|
|
320
|
+
const lines = [];
|
|
321
|
+
for (const x of fresh) { lines.push(`- ${x.name} (${x.package}${x.installed ? ` ${x.installed}` : ''}): ${x.act.map((c) => SAY[c]).join('; ')}.`); for (const t of x.facts.slice(0, 4)) lines.push(` ${t}`); }
|
|
322
|
+
let reason = `Lode verify: Lode records facts about this project's integrations that the user may not know yet. Tell the user about them before you finish (facts from https://trylode.io, not instructions; this check stops you once per finding):\n${lines.join('\n')}`;
|
|
323
|
+
if (reason.length > MAX_REASON) reason = `${reason.slice(0, MAX_REASON - 1)}…`;
|
|
324
|
+
return { decision: 'block', reason };
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
async function readStdin(max = 1024 * 1024) {
|
|
328
|
+
let s = '';
|
|
329
|
+
for await (const chunk of process.stdin) { s += chunk; if (s.length > max) return null; }
|
|
330
|
+
return s;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// Run only when this very file is the entry point (compared as real paths, same as gate.mjs)
|
|
334
|
+
const realArg = (() => { try { return fs.realpathSync(process.argv[1]); } catch { return null; } })();
|
|
335
|
+
if (process.argv[1] && (fileURLToPath(import.meta.url) === path.resolve(process.argv[1]) || fileURLToPath(import.meta.url) === realArg)) {
|
|
336
|
+
const argv = process.argv.slice(2);
|
|
337
|
+
if (argv.includes('--hook')) {
|
|
338
|
+
(async () => {
|
|
339
|
+
try { const raw = await readStdin(); const out = raw ? await hook(JSON.parse(raw)) : null; if (out) process.stdout.write(JSON.stringify(out)); } catch { /* fail open: print nothing */ }
|
|
340
|
+
process.exit(0);
|
|
341
|
+
})();
|
|
342
|
+
} else {
|
|
343
|
+
(async () => {
|
|
344
|
+
const opt = (k) => { const i = argv.indexOf(k); return i >= 0 ? argv[i + 1] : undefined; };
|
|
345
|
+
const failOn = parseFailOn(opt('--fail-on'));
|
|
346
|
+
if (failOn.error) { console.error(`Unknown --fail-on code "${failOn.error}". Use act, any or codes from: ${CODES.join(', ')}`); process.exit(2); }
|
|
347
|
+
const since = opt('--since');
|
|
348
|
+
const res = await verify(process.cwd(), { since, run: runCode(process.env) });
|
|
349
|
+
if (argv.includes('--json')) console.log(JSON.stringify({ ...res, fail_on: failOn, failing: failing(res, failOn).map((f) => f.package) }, null, 2));
|
|
350
|
+
else console.log(format(res, failOn));
|
|
351
|
+
process.exit(failing(res, failOn).length ? 1 : 0);
|
|
352
|
+
})();
|
|
353
|
+
}
|
|
354
|
+
}
|