trylode 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/PERMISSIONS.md +36 -0
- package/README.md +19 -2
- package/bin/cli.mjs +72 -0
- package/package.json +11 -4
- package/skill/PERMISSIONS.md +24 -0
- package/skill/SKILL.md +307 -0
- package/skill/scripts/gate-packages.json +182 -0
- package/skill/scripts/gate.mjs +214 -0
- package/skill/scripts/lode.mjs +1554 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
{
|
|
2
|
+
"note": "Package names on Lode's list (https://trylode.io/api/stack-signals.json). Lode Gate sends a request only for these.",
|
|
3
|
+
"npm": [
|
|
4
|
+
"@ably/pubsub-device",
|
|
5
|
+
"@ably/pubsub-server",
|
|
6
|
+
"@anthropic-ai/sdk",
|
|
7
|
+
"@arcjet/next",
|
|
8
|
+
"@arcjet/node",
|
|
9
|
+
"@auth0/auth0-react",
|
|
10
|
+
"@auth0/nextjs-auth0",
|
|
11
|
+
"@axiomhq/js",
|
|
12
|
+
"@browserbasehq/sdk",
|
|
13
|
+
"@clerk/backend",
|
|
14
|
+
"@clerk/clerk-react",
|
|
15
|
+
"@clerk/nextjs",
|
|
16
|
+
"@clerk/react",
|
|
17
|
+
"@customerio/cdp-analytics-node",
|
|
18
|
+
"@descope/nextjs-sdk",
|
|
19
|
+
"@descope/node-sdk",
|
|
20
|
+
"@descope/react-sdk",
|
|
21
|
+
"@fal-ai/client",
|
|
22
|
+
"@getbrevo/brevo",
|
|
23
|
+
"@growthbook/growthbook",
|
|
24
|
+
"@hatchet-dev/typescript-sdk",
|
|
25
|
+
"@hexclave/js",
|
|
26
|
+
"@hexclave/next",
|
|
27
|
+
"@hexclave/react",
|
|
28
|
+
"@hubspot/api-client",
|
|
29
|
+
"@kinde-oss/kinde-auth-nextjs",
|
|
30
|
+
"@knocklabs/node",
|
|
31
|
+
"@launchdarkly/node-server-sdk",
|
|
32
|
+
"@lemonsqueezy/lemonsqueezy.js",
|
|
33
|
+
"@libsql/client",
|
|
34
|
+
"@logto/express",
|
|
35
|
+
"@logto/next",
|
|
36
|
+
"@logto/node",
|
|
37
|
+
"@mailchimp/mailchimp_marketing",
|
|
38
|
+
"@mendable/firecrawl-js",
|
|
39
|
+
"@mux/mux-node",
|
|
40
|
+
"@mux/ts",
|
|
41
|
+
"@neondatabase/serverless",
|
|
42
|
+
"@netlify/functions",
|
|
43
|
+
"@notionhq/client",
|
|
44
|
+
"@novu/api",
|
|
45
|
+
"@novu/nextjs",
|
|
46
|
+
"@novu/react",
|
|
47
|
+
"@okta/okta-auth-js",
|
|
48
|
+
"@paddle/paddle-node-sdk",
|
|
49
|
+
"@paypal/paypal-server-sdk",
|
|
50
|
+
"@planetscale/database",
|
|
51
|
+
"@polar-sh/sdk",
|
|
52
|
+
"@prisma/client",
|
|
53
|
+
"@prisma/orm-mongo",
|
|
54
|
+
"@prisma/orm-postgres",
|
|
55
|
+
"@propelauth/nextjs",
|
|
56
|
+
"@propelauth/node",
|
|
57
|
+
"@sanity/client",
|
|
58
|
+
"@sendgrid/mail",
|
|
59
|
+
"@sentry/nextjs",
|
|
60
|
+
"@sentry/node",
|
|
61
|
+
"@shopify/shopify-api",
|
|
62
|
+
"@shopify/shopify-app-remix",
|
|
63
|
+
"@slack/web-api",
|
|
64
|
+
"@stackframe/stack",
|
|
65
|
+
"@storyblok/js",
|
|
66
|
+
"@stripe/stripe-js",
|
|
67
|
+
"@stytch/nextjs",
|
|
68
|
+
"@stytch/vanilla-js",
|
|
69
|
+
"@supabase/ssr",
|
|
70
|
+
"@supabase/supabase-js",
|
|
71
|
+
"@temporalio/client",
|
|
72
|
+
"@temporalio/worker",
|
|
73
|
+
"@temporalio/workflow",
|
|
74
|
+
"@trigger.dev/react-hooks",
|
|
75
|
+
"@trigger.dev/sdk",
|
|
76
|
+
"@trycourier/courier",
|
|
77
|
+
"@unkey/api",
|
|
78
|
+
"@unkey/nextjs",
|
|
79
|
+
"@unkey/ratelimit",
|
|
80
|
+
"@upstash/qstash",
|
|
81
|
+
"@upstash/redis",
|
|
82
|
+
"@vercel/analytics",
|
|
83
|
+
"@vercel/blob",
|
|
84
|
+
"@vercel/functions",
|
|
85
|
+
"@workos-inc/node",
|
|
86
|
+
"@xata.io/client",
|
|
87
|
+
"ably",
|
|
88
|
+
"airtable",
|
|
89
|
+
"algoliasearch",
|
|
90
|
+
"auth0",
|
|
91
|
+
"better-auth",
|
|
92
|
+
"bullmq",
|
|
93
|
+
"cloudinary",
|
|
94
|
+
"contentful",
|
|
95
|
+
"convex",
|
|
96
|
+
"customerio-node",
|
|
97
|
+
"dd-trace",
|
|
98
|
+
"drizzle-orm",
|
|
99
|
+
"exa-js",
|
|
100
|
+
"firebase",
|
|
101
|
+
"firebase-admin",
|
|
102
|
+
"firecrawl",
|
|
103
|
+
"inngest",
|
|
104
|
+
"intuit-oauth",
|
|
105
|
+
"klaviyo-api",
|
|
106
|
+
"loops",
|
|
107
|
+
"mailersend",
|
|
108
|
+
"mailgun.js",
|
|
109
|
+
"mongodb",
|
|
110
|
+
"netlify-cli",
|
|
111
|
+
"newrelic",
|
|
112
|
+
"next-auth",
|
|
113
|
+
"node-mailjet",
|
|
114
|
+
"node-quickbooks",
|
|
115
|
+
"openai",
|
|
116
|
+
"posthog-js",
|
|
117
|
+
"posthog-node",
|
|
118
|
+
"postmark",
|
|
119
|
+
"replicate",
|
|
120
|
+
"resend",
|
|
121
|
+
"rollbar",
|
|
122
|
+
"sparkpost",
|
|
123
|
+
"square",
|
|
124
|
+
"statsig-node",
|
|
125
|
+
"stripe",
|
|
126
|
+
"stytch",
|
|
127
|
+
"svix",
|
|
128
|
+
"twilio",
|
|
129
|
+
"uploadthing",
|
|
130
|
+
"vercel",
|
|
131
|
+
"xero-node"
|
|
132
|
+
],
|
|
133
|
+
"pypi": [
|
|
134
|
+
"algoliasearch",
|
|
135
|
+
"anthropic",
|
|
136
|
+
"auth0-python",
|
|
137
|
+
"brevo-python",
|
|
138
|
+
"cloudinary",
|
|
139
|
+
"contentful",
|
|
140
|
+
"convex",
|
|
141
|
+
"customerio",
|
|
142
|
+
"customerio-cdp-analytics",
|
|
143
|
+
"descope",
|
|
144
|
+
"exa-py",
|
|
145
|
+
"hubspot-api-client",
|
|
146
|
+
"inngest",
|
|
147
|
+
"intuit-oauth",
|
|
148
|
+
"klaviyo-api",
|
|
149
|
+
"knockapi",
|
|
150
|
+
"launchdarkly-server-sdk",
|
|
151
|
+
"mailchimp-marketing",
|
|
152
|
+
"mailersend",
|
|
153
|
+
"mailjet-rest",
|
|
154
|
+
"mux-python",
|
|
155
|
+
"notion-client",
|
|
156
|
+
"novu-py",
|
|
157
|
+
"openai",
|
|
158
|
+
"paddle-python-sdk",
|
|
159
|
+
"posthog",
|
|
160
|
+
"propelauth-py",
|
|
161
|
+
"pyairtable",
|
|
162
|
+
"pymongo",
|
|
163
|
+
"python-quickbooks",
|
|
164
|
+
"replicate",
|
|
165
|
+
"resend",
|
|
166
|
+
"sendgrid",
|
|
167
|
+
"sentry-sdk",
|
|
168
|
+
"shopifyapi",
|
|
169
|
+
"slack-sdk",
|
|
170
|
+
"squareup",
|
|
171
|
+
"stripe",
|
|
172
|
+
"stytch",
|
|
173
|
+
"supabase",
|
|
174
|
+
"temporalio",
|
|
175
|
+
"trycourier",
|
|
176
|
+
"twilio",
|
|
177
|
+
"unkey-py",
|
|
178
|
+
"upstash-redis",
|
|
179
|
+
"workos",
|
|
180
|
+
"xero-python"
|
|
181
|
+
]
|
|
182
|
+
}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Lode Gate (LOD-231): an opt-in Claude Code PreToolUse hook. Just before the agent installs a package on Lode's list
|
|
3
|
+
// (gate-packages.json, from https://trylode.io/api/stack-signals.json), it adds Lode's facts to the agent's context.
|
|
4
|
+
// Switched on only by a person's choice: `node lode.mjs init --gate --yes`, `npx trylode setup --gate --yes`, or installing
|
|
5
|
+
// the `lode-gate` Claude Code plugin (LOD-262); each has its own remove. See PERMISSIONS.md.
|
|
6
|
+
//
|
|
7
|
+
// What it sends, only when an install names a package on Lode's list: those package names, the package manager,
|
|
8
|
+
// Lode platform codes found from config file NAMES in the project (never their contents), the mode and a random
|
|
9
|
+
// code for this Claude Code session. Never the command, versions, paths, file contents or the session id.
|
|
10
|
+
// Installs of other packages send nothing. Any failure (offline, slow, bad answer) passes silently: Gate can't
|
|
11
|
+
// break an install. In `ask` mode a warning sends the install to the permission prompt; Gate never denies.
|
|
12
|
+
// No dependencies (Node 18+). Set LODE_GATE_LOG=0 to get the facts with nothing kept by Lode.
|
|
13
|
+
import fs from 'node:fs';
|
|
14
|
+
import path from 'node:path';
|
|
15
|
+
import os from 'node:os';
|
|
16
|
+
import crypto from 'node:crypto';
|
|
17
|
+
import { fileURLToPath } from 'node:url';
|
|
18
|
+
|
|
19
|
+
const VERSION = '0.1';
|
|
20
|
+
// Lode's own tests may point the hook at this machine; nothing else can change where it sends (security review 30-11-2026).
|
|
21
|
+
const BASE = (() => { const u = process.env.LODE_GATE_URL || ''; return /^http:\/\/(127\.0\.0\.1|localhost)(:\d+)?$/.test(u) ? u : 'https://trylode.io'; })();
|
|
22
|
+
const UA = /^lode-gate-test\b/.test(process.env.LODE_UA || '') ? process.env.LODE_UA : `lode-gate/${VERSION}`;
|
|
23
|
+
const BUDGET_MS = 1500;
|
|
24
|
+
const MAX_CONTEXT = 1200;
|
|
25
|
+
// Kept equal to GATE_WARNINGS in Lode's src/lib/gate.mjs (test)
|
|
26
|
+
const GATE_WARNINGS = ['plan-needed', 'region-limited', 'sdk-deprecated', 'latest-affected', 'pinned-affected', 'no-record-on-platform', 'held-record'];
|
|
27
|
+
// Platforms told apart by a config file's name only (kept equal to PLATFORM_FILES in Lode's src/lib/gate.mjs)
|
|
28
|
+
const PLATFORM_FILES = { vercel: ['vercel.json', '.vercel/project.json'], netlify: ['netlify.toml'], supabase: ['supabase/config.toml'], cloudflare: ['wrangler.toml', 'wrangler.json', 'wrangler.jsonc'] };
|
|
29
|
+
|
|
30
|
+
// BEGIN PARSER
|
|
31
|
+
// Splits a shell command into simple commands and returns every package an install names:
|
|
32
|
+
// [{ manager, system: 'npm'|'pypi', name, version }]. version is an exact pin (e.g. 1.2.3) or null.
|
|
33
|
+
// Anything that isn't a plain registry name (paths, URLs, git specs, requirement files) is skipped.
|
|
34
|
+
function gateTokens(segment) {
|
|
35
|
+
const out = []; let cur = ''; let q = null; let has = false;
|
|
36
|
+
for (const ch of segment) {
|
|
37
|
+
if (q) { if (ch === q) q = null; else cur += ch; continue; }
|
|
38
|
+
if (ch === '"' || ch === "'") { q = ch; has = true; continue; }
|
|
39
|
+
if (/\s/.test(ch)) { if (has || cur) out.push(cur); cur = ''; has = false; continue; }
|
|
40
|
+
cur += ch; has = true;
|
|
41
|
+
}
|
|
42
|
+
if (has || cur) out.push(cur);
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
const NPM_VALUE_FLAGS = new Set(['--registry', '--prefix', '-w', '--workspace', '--filter', '-F', '--cwd', '--tag', '--cache', '--userconfig']);
|
|
46
|
+
const PIP_VALUE_FLAGS = new Set(['-r', '--requirement', '-c', '--constraint', '-e', '--editable', '-i', '--index-url', '--extra-index-url', '-t', '--target', '--prefix', '--root', '-f', '--find-links', '--python', '-p', '--group', '--optional', '-G', '--source', '--platform', '--python-version']);
|
|
47
|
+
function gateNpmSpec(t) {
|
|
48
|
+
if (!t || /^[./~]|^(https?|git|git\+\w+|file|link|github|gitlab|bitbucket|npm|workspace|portal|patch):/i.test(t) || t.includes('/') && !t.startsWith('@')) return null;
|
|
49
|
+
const at = t.startsWith('@') ? t.indexOf('@', 1) : t.indexOf('@');
|
|
50
|
+
const name = (at > 0 ? t.slice(0, at) : t).toLowerCase();
|
|
51
|
+
if (!/^(@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/.test(name)) return null;
|
|
52
|
+
const v = at > 0 ? t.slice(at + 1) : '';
|
|
53
|
+
return { name, version: /^v?\d+\.\d+\.\d+([-+][0-9A-Za-z.-]+)?$/.test(v) ? v.replace(/^v/, '') : null };
|
|
54
|
+
}
|
|
55
|
+
function gatePipSpec(t) {
|
|
56
|
+
if (!t || /^[./~]|:\/\/|^git\+/i.test(t) || /\.(whl|tar\.gz|zip)$/i.test(t)) return null;
|
|
57
|
+
const m = /^([A-Za-z0-9][A-Za-z0-9._-]*)(\[[^\]]*\])?\s*(==\s*(\d+(\.\d+)*))?/.exec(t);
|
|
58
|
+
if (!m) return null;
|
|
59
|
+
return { name: m[1].toLowerCase().replace(/[-_.]+/g, '-'), version: m[4] ?? null };
|
|
60
|
+
}
|
|
61
|
+
// Splits on ; | & and newlines that sit outside quotes, so text inside a quoted argument is never read as a command.
|
|
62
|
+
function gateSegments(command) {
|
|
63
|
+
const out = []; let cur = ''; let q = null;
|
|
64
|
+
for (const ch of command) {
|
|
65
|
+
if (q) { cur += ch; if (ch === q) q = null; continue; }
|
|
66
|
+
if (ch === '"' || ch === "'") { q = ch; cur += ch; continue; }
|
|
67
|
+
if (ch === ';' || ch === '|' || ch === '&' || ch === '\n') { out.push(cur); cur = ''; continue; }
|
|
68
|
+
cur += ch;
|
|
69
|
+
}
|
|
70
|
+
out.push(cur);
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
function parseInstall(command) {
|
|
74
|
+
const found = [];
|
|
75
|
+
if (typeof command !== 'string' || command.length > 20000) return found;
|
|
76
|
+
for (const seg of gateSegments(command)) {
|
|
77
|
+
let t = gateTokens(seg.trim());
|
|
78
|
+
while (t.length && (/^[A-Za-z_][A-Za-z0-9_]*=/.test(t[0]) || ['sudo', 'env', 'command', 'time', 'exec'].includes(t[0]))) t = t.slice(1);
|
|
79
|
+
if (!t.length) continue;
|
|
80
|
+
const bin = t[0].split('/').pop().toLowerCase();
|
|
81
|
+
let manager = null, system = null, rest = null;
|
|
82
|
+
if (bin === 'npm' && ['install', 'i', 'add', 'in'].includes(t[1])) [manager, system, rest] = ['npm', 'npm', t.slice(2)];
|
|
83
|
+
else if (bin === 'pnpm' && ['add', 'install', 'i'].includes(t[1])) [manager, system, rest] = ['pnpm', 'npm', t.slice(2)];
|
|
84
|
+
else if (bin === 'yarn' && t[1] === 'add') [manager, system, rest] = ['yarn', 'npm', t.slice(2)];
|
|
85
|
+
else if (bin === 'yarn' && t[1] === 'global' && t[2] === 'add') [manager, system, rest] = ['yarn', 'npm', t.slice(3)];
|
|
86
|
+
else if (bin === 'bun' && ['add', 'install', 'i', 'a'].includes(t[1])) [manager, system, rest] = ['bun', 'npm', t.slice(2)];
|
|
87
|
+
else if (/^pip3?(\.\d+)?$/.test(bin) && t[1] === 'install') [manager, system, rest] = ['pip', 'pypi', t.slice(2)];
|
|
88
|
+
else if (/^python3?(\.\d+)?$/.test(bin) && t[1] === '-m' && t[2] === 'pip' && t[3] === 'install') [manager, system, rest] = ['pip', 'pypi', t.slice(4)];
|
|
89
|
+
else if (bin === 'uv' && t[1] === 'add') [manager, system, rest] = ['uv', 'pypi', t.slice(2)];
|
|
90
|
+
else if (bin === 'uv' && t[1] === 'pip' && t[2] === 'install') [manager, system, rest] = ['uv', 'pypi', t.slice(3)];
|
|
91
|
+
else if (bin === 'poetry' && t[1] === 'add') [manager, system, rest] = ['poetry', 'pypi', t.slice(2)];
|
|
92
|
+
if (!manager || rest.includes('--dry-run')) continue;
|
|
93
|
+
const valueFlags = system === 'npm' ? NPM_VALUE_FLAGS : PIP_VALUE_FLAGS;
|
|
94
|
+
for (let i = 0; i < rest.length; i++) {
|
|
95
|
+
const a = rest[i];
|
|
96
|
+
if (a === '--') continue;
|
|
97
|
+
if (a.startsWith('-')) { if (valueFlags.has(a)) i++; continue; }
|
|
98
|
+
const spec = system === 'npm' ? gateNpmSpec(a) : gatePipSpec(a);
|
|
99
|
+
if (spec) found.push({ manager, system, name: spec.name, version: spec.version });
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return found;
|
|
103
|
+
}
|
|
104
|
+
// Exact-version comparison for the local "pinned version inside an affected range" check.
|
|
105
|
+
// Numbers first; a version with a pre-release part (1.2.0-beta.1, PyPI 1.2.0rc1) sorts before the release.
|
|
106
|
+
function gateCmp(a, b) {
|
|
107
|
+
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(/^[-.]/, '')]; };
|
|
108
|
+
const [na, pa] = split(a), [nb, pb] = split(b);
|
|
109
|
+
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; }
|
|
110
|
+
if (pa === pb) return 0;
|
|
111
|
+
if (!pa) return 1;
|
|
112
|
+
if (!pb) return -1;
|
|
113
|
+
return pa < pb ? -1 : 1;
|
|
114
|
+
}
|
|
115
|
+
function gateAffected(version, ranges) {
|
|
116
|
+
if (!version) return [];
|
|
117
|
+
return (ranges || []).filter((r) => r && typeof r.id === 'string'
|
|
118
|
+
&& (!r.introduced || r.introduced === '0' || gateCmp(version, r.introduced) >= 0)
|
|
119
|
+
&& (r.fixed ? gateCmp(version, r.fixed) < 0 : r.last_affected ? gateCmp(version, r.last_affected) <= 0 : true)).map((r) => r.id);
|
|
120
|
+
}
|
|
121
|
+
// END PARSER
|
|
122
|
+
|
|
123
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
124
|
+
// Lode's answer is untrusted text: control and formatting characters (incl. Unicode tag characters) are removed, and a
|
|
125
|
+
// line that looks like a command or links anywhere but Lode and the package registries is dropped, not shown.
|
|
126
|
+
const clean = (t, n = 300) => String(t ?? '').replace(/[\p{Cc}\p{Cf}\p{Co}\p{Cn}]/gu, ' ').replace(/\s+/g, ' ').trim().slice(0, n);
|
|
127
|
+
const OK_HOSTS = ['trylode.io', 'www.npmjs.com', 'pypi.org', 'osv.dev'];
|
|
128
|
+
const looksSafe = (t) => !/[`$<>{}\\]|\|\s*\w|\b(curl|wget|bash|sh|sudo|rm|chmod|eval|exec|powershell|iex)\b/i.test(t)
|
|
129
|
+
&& [...t.matchAll(/https?:\/\/([^/\s)]+)/g)].every((m) => OK_HOSTS.includes(m[1].toLowerCase()));
|
|
130
|
+
|
|
131
|
+
// A random code per Claude Code session, kept in the temp folder under a hash of the session id, so Lode can link
|
|
132
|
+
// the checks of one session without ever receiving the session id.
|
|
133
|
+
function sessionCode(sessionId) {
|
|
134
|
+
if (typeof sessionId !== 'string' || !sessionId) return undefined;
|
|
135
|
+
try {
|
|
136
|
+
const dir = os.tmpdir();
|
|
137
|
+
const f = path.join(dir, `lode-gate-${crypto.createHash('sha256').update(sessionId).digest('hex').slice(0, 24)}`);
|
|
138
|
+
const read = () => { const st = fs.lstatSync(f); if (!st.isFile() || (typeof process.getuid === 'function' && st.uid !== process.getuid())) return undefined; const c = fs.readFileSync(f, 'utf8').trim(); return /^[0-9a-f]{16}$/.test(c) ? c : undefined; };
|
|
139
|
+
try { const c = read(); if (c) return c; } catch { /* new session */ }
|
|
140
|
+
const c = crypto.randomBytes(8).toString('hex');
|
|
141
|
+
try { fs.writeFileSync(f, c, { mode: 0o600, flag: 'wx' }); } catch { try { return read(); } catch { return undefined; } }
|
|
142
|
+
// Tidy codes from sessions more than a day old (only this hook's own files)
|
|
143
|
+
try { for (const n of fs.readdirSync(dir)) if (/^lode-gate-[0-9a-f]{24}$/.test(n)) { const g = path.join(dir, n); const st = fs.lstatSync(g); if (st.isFile() && Date.now() - st.mtimeMs > 86400000) fs.rmSync(g); } } catch { /* best effort */ }
|
|
144
|
+
return c;
|
|
145
|
+
} catch { return undefined; }
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export async function run(input, { fetchImpl = globalThis.fetch, env = process.env, mode = 'warn' } = {}) {
|
|
149
|
+
if (!input || !['Bash', 'PowerShell'].includes(input.tool_name)) return null;
|
|
150
|
+
const command = input.tool_input?.command;
|
|
151
|
+
const found = parseInstall(command);
|
|
152
|
+
if (!found.length) return null;
|
|
153
|
+
let list;
|
|
154
|
+
try { list = JSON.parse(fs.readFileSync(path.join(here, 'gate-packages.json'), 'utf8')); } catch { return null; }
|
|
155
|
+
const known = { npm: new Set(list.npm ?? []), pypi: new Set(list.pypi ?? []) };
|
|
156
|
+
const matched = found.filter((p) => known[p.system]?.has(p.name));
|
|
157
|
+
if (!matched.length) return null; // nothing on Lode's list: no request at all
|
|
158
|
+
const root = typeof env.CLAUDE_PROJECT_DIR === 'string' && env.CLAUDE_PROJECT_DIR ? env.CLAUDE_PROJECT_DIR : (typeof input.cwd === 'string' ? input.cwd : null);
|
|
159
|
+
const platforms = root ? Object.keys(PLATFORM_FILES).filter((p) => PLATFORM_FILES[p].some((f) => { try { return fs.existsSync(path.join(root, f)); } catch { return false; } })) : [];
|
|
160
|
+
const body = {
|
|
161
|
+
packages: [...new Map(matched.map((p) => [`${p.system}:${p.name}`, { system: p.system, name: p.name }])).values()].slice(0, 10),
|
|
162
|
+
platforms,
|
|
163
|
+
manager: matched[0].manager,
|
|
164
|
+
mode,
|
|
165
|
+
session: sessionCode(input.session_id),
|
|
166
|
+
};
|
|
167
|
+
const noLog = env.LODE_GATE_LOG === '0';
|
|
168
|
+
let answer;
|
|
169
|
+
try {
|
|
170
|
+
const res = await fetchImpl(`${BASE}/v1/gate${noLog ? '?log=0' : ''}`, { method: 'POST', headers: { 'content-type': 'application/json', 'user-agent': UA }, body: JSON.stringify(noLog ? { ...body, log: false } : body), signal: AbortSignal.timeout(BUDGET_MS) });
|
|
171
|
+
if (!res.ok) return null;
|
|
172
|
+
answer = await res.json();
|
|
173
|
+
} catch { return null; }
|
|
174
|
+
const lines = []; const warnings = new Set();
|
|
175
|
+
for (const p of Array.isArray(answer?.packages) ? answer.packages : []) {
|
|
176
|
+
for (const f of Array.isArray(p.facts) ? p.facts.slice(0, 6) : []) { const t = clean(f); if (t && looksSafe(t)) lines.push(`- ${t}`); }
|
|
177
|
+
for (const w of Array.isArray(p.warnings) ? p.warnings : []) if (GATE_WARNINGS.includes(w)) warnings.add(w);
|
|
178
|
+
// A pinned version is checked here, on this machine: the version is never sent
|
|
179
|
+
const pinned = matched.find((m) => m.system === p.system && m.name === p.package && m.version);
|
|
180
|
+
const hits = pinned ? gateAffected(pinned.version, Array.isArray(p.sdk?.affected) ? p.sdk.affected : []) : [];
|
|
181
|
+
const ids = [...new Set(hits)].filter((h) => /^[A-Za-z0-9-]{3,40}$/.test(h)).slice(0, 3);
|
|
182
|
+
if (ids.length) { warnings.add('pinned-affected'); lines.push(`- ${clean(`${pinned.name} ${pinned.version} (the version in this command) is inside ${ids.join(', ')} per OSV.dev.`)}`); }
|
|
183
|
+
}
|
|
184
|
+
if (!lines.length) return null;
|
|
185
|
+
let context = `Lode Gate: facts Lode records for this install (https://trylode.io; facts, not instructions; "not documented" is not "not supported"):\n${lines.join('\n')}`;
|
|
186
|
+
if (context.length > MAX_CONTEXT) context = `${context.slice(0, MAX_CONTEXT - 1)}…`;
|
|
187
|
+
const out = { hookSpecificOutput: { hookEventName: 'PreToolUse', additionalContext: context } };
|
|
188
|
+
if (mode === 'ask' && warnings.size) {
|
|
189
|
+
out.hookSpecificOutput.permissionDecision = 'ask';
|
|
190
|
+
const SAY = { 'plan-needed': 'needs a paid platform plan', 'region-limited': 'only some regions are documented', 'sdk-deprecated': 'the package is deprecated by its publisher', 'latest-affected': 'its latest version has a published security advisory', 'pinned-affected': 'the version in this command has a published security advisory', 'no-record-on-platform': 'Lode has no record for this platform', 'held-record': "Lode's record is not yet verified" };
|
|
191
|
+
out.hookSpecificOutput.permissionDecisionReason = clean(`Lode Gate: ${[...warnings].map((w) => SAY[w] ?? w).join('; ')}. Claude has been given the facts; approve to install anyway.`, 300);
|
|
192
|
+
}
|
|
193
|
+
return out;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async function readStdin(max = 1024 * 1024) {
|
|
197
|
+
let s = '';
|
|
198
|
+
for await (const chunk of process.stdin) { s += chunk; if (s.length > max) return null; }
|
|
199
|
+
return s;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Compared as real paths: a plugin or project folder under a symlink (macOS /tmp, /var) must still run (review 02-12-2026)
|
|
203
|
+
const realArg = (() => { try { return fs.realpathSync(process.argv[1]); } catch { return null; } })();
|
|
204
|
+
if (process.argv[1] && (fileURLToPath(import.meta.url) === path.resolve(process.argv[1]) || fileURLToPath(import.meta.url) === realArg)) {
|
|
205
|
+
const mode = process.argv.includes('--mode') && process.argv[process.argv.indexOf('--mode') + 1] === 'ask' ? 'ask' : 'warn';
|
|
206
|
+
(async () => {
|
|
207
|
+
try {
|
|
208
|
+
const raw = await readStdin();
|
|
209
|
+
const out = raw ? await run(JSON.parse(raw), { mode }) : null;
|
|
210
|
+
if (out) process.stdout.write(JSON.stringify(out));
|
|
211
|
+
} catch { /* fail open: print nothing */ }
|
|
212
|
+
process.exit(0);
|
|
213
|
+
})();
|
|
214
|
+
}
|