trylode 0.5.0 → 0.5.1
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/bin/cli.mjs +5 -2
- package/package.json +1 -1
- package/skill/scripts/lode.mjs +51 -10
package/bin/cli.mjs
CHANGED
|
@@ -42,6 +42,9 @@ Setup and remove send nothing to Lode. What Lode Gate sends when it runs: PERMIS
|
|
|
42
42
|
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';
|
|
43
43
|
// LOD-287 (Paul approved the wording 03-12-2026): the one line setup adds when the verify hook is not on.
|
|
44
44
|
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';
|
|
45
|
+
// LOD-307 (Paul approved the wording 04-12-2026, plain address): adds Lode as a claude.ai connector for Claude chat and
|
|
46
|
+
// desktop. Printed only; setup never runs it (it signs in to the user's claude.ai account).
|
|
47
|
+
const CONNECTOR_OFFER = 'To use Lode in Claude chat and desktop, run: claude mcp add --web lode https://trylode.io/mcp';
|
|
45
48
|
|
|
46
49
|
const argv = process.argv.slice(2);
|
|
47
50
|
const cmd = argv[0];
|
|
@@ -73,12 +76,12 @@ async function steps() {
|
|
|
73
76
|
if (gate || triage || verify) {
|
|
74
77
|
const out = [first]; let ok = true;
|
|
75
78
|
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); }
|
|
76
|
-
return { out, ok };
|
|
79
|
+
return { out: [...out, CONNECTOR_OFFER], ok };
|
|
77
80
|
}
|
|
78
81
|
// Offer Gate and verify only when they aren't on yet (dry runs of the reviewed check; they write nothing)
|
|
79
82
|
const dry = await run(['init', '--gate', '--src', 'setup']);
|
|
80
83
|
const dryVerify = await run(['init', '--verify', '--src', 'setup']);
|
|
81
|
-
return { out: [first, ...(/already on in this project/.test(dry) ? [] : [GATE_OFFER]), ...(/already on in this project/.test(dryVerify) ? [] : [VERIFY_OFFER])], ok: true };
|
|
84
|
+
return { out: [first, ...(/already on in this project/.test(dry) ? [] : [GATE_OFFER]), ...(/already on in this project/.test(dryVerify) ? [] : [VERIFY_OFFER]), CONNECTOR_OFFER], ok: true };
|
|
82
85
|
}
|
|
83
86
|
if (cmd === 'remove') {
|
|
84
87
|
// Each hook first (only the ones that are on are reported), then the rest unless only hooks were named
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trylode",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
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/scripts/lode.mjs
CHANGED
|
@@ -900,6 +900,50 @@ const GATE_FILES_LIST = ['SKILL.md', 'PERMISSIONS.md', 'scripts/lode.mjs', 'scri
|
|
|
900
900
|
// Security review 02-12-2026 (LOD-262): every project file gateInit reads is untrusted, so it is read the way init reads
|
|
901
901
|
// (readSafe): a regular file with one name, at most 1 MB, opened without following a link or blocking (a FIFO or a
|
|
902
902
|
// link to /dev/zero used to hang remove), checked again once open. { text } | { text: null } when absent | { bad }.
|
|
903
|
+
// Security review 04-12-2026 (LOD-306, finding 6): setup's JSON files and its note are written without ever following a
|
|
904
|
+
// link. Each folder on the way is made one level at a time and must be a plain folder; a new file is created with O_EXCL
|
|
905
|
+
// and O_NOFOLLOW, an existing one is opened with O_NOFOLLOW and must still be the very file that was read (same inode,
|
|
906
|
+
// one name); and after opening, the folder must still resolve to the same place inside the project, so a folder swapped
|
|
907
|
+
// for a link between the check and the write is caught before anything is written. Re-review 04-12-2026: the opened file
|
|
908
|
+
// must also still be the one at that name (same device and inode), so a swap there and back is caught too; on any doubt
|
|
909
|
+
// the file is emptied through its own descriptor and removed only if the name still points at that very file (never an
|
|
910
|
+
// unlink that could follow a new link). On Linux the opened file's real path comes from the kernel (/proc/self/fd), so
|
|
911
|
+
// Lode's text is written only into a file inside the project. Residual, accepted (Node has no openat): a same-user
|
|
912
|
+
// process racing setup can still leave an empty file outside the project (created, then emptied), and, outside Linux
|
|
913
|
+
// only, one that swaps a folder several times between single system calls could get the text written outside. It can
|
|
914
|
+
// never truncate or overwrite a file that already existed (O_EXCL, and the inode check for existing files).
|
|
915
|
+
export function writeInProject(fs, path, cwd, rel, text, st = null) {
|
|
916
|
+
const dirs = rel.split(/[\\/]/).slice(0, -1);
|
|
917
|
+
let d = cwd;
|
|
918
|
+
for (const part of dirs) {
|
|
919
|
+
d = path.join(d, part);
|
|
920
|
+
let s; try { s = fs.lstatSync(d); } catch { fs.mkdirSync(d); s = fs.lstatSync(d); }
|
|
921
|
+
if (s.isSymbolicLink() || !s.isDirectory()) throw new Error(`${rel}: a folder on its path is a link or not a folder`);
|
|
922
|
+
}
|
|
923
|
+
const f = path.join(cwd, rel), C = fs.constants, NF = C.O_NOFOLLOW ?? 0;
|
|
924
|
+
const fd = st ? fs.openSync(f, C.O_WRONLY | NF | (C.O_NONBLOCK ?? 0)) : fs.openSync(f, C.O_WRONLY | C.O_CREAT | C.O_EXCL | NF, 0o644);
|
|
925
|
+
let s, moved = false;
|
|
926
|
+
try {
|
|
927
|
+
s = fs.fstatSync(fd);
|
|
928
|
+
if (!s.isFile() || s.nlink > 1 || (st && (s.ino !== st.ino || s.dev !== st.dev))) throw new Error(`${rel} changed while init ran`);
|
|
929
|
+
// Where the opened file really is. On Linux the kernel says so (/proc/self/fd), which no later swap can change.
|
|
930
|
+
// Elsewhere: the folder must resolve inside the project both before and after the name is checked against the file.
|
|
931
|
+
const inside = () => fs.realpathSync(path.dirname(f)) === path.join(cwd, ...dirs);
|
|
932
|
+
const atName = () => { try { const n = fs.lstatSync(f); return n.isFile() && n.ino === s.ino && n.dev === s.dev; } catch { return false; } };
|
|
933
|
+
let kernel = null; try { kernel = fs.readlinkSync(`/proc/self/fd/${fd}`); } catch { /* not Linux */ }
|
|
934
|
+
const ok = kernel != null ? kernel === f && atName() : inside() && atName() && inside();
|
|
935
|
+
if (!ok) { moved = true; throw new Error(`${rel}: a folder on its path changed while init ran`); }
|
|
936
|
+
if (st) fs.ftruncateSync(fd, 0);
|
|
937
|
+
fs.writeSync(fd, text, 0);
|
|
938
|
+
} finally {
|
|
939
|
+
if (moved && !st) {
|
|
940
|
+
try { fs.ftruncateSync(fd, 0); } catch { /* nothing was written */ }
|
|
941
|
+
try { const n = fs.lstatSync(f); if (n.isFile() && n.ino === s.ino && n.dev === s.dev && n.nlink === 1) fs.unlinkSync(f); } catch { /* gone or not ours */ }
|
|
942
|
+
}
|
|
943
|
+
fs.closeSync(fd);
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
const markerSt = (fs, f) => { try { const s = fs.lstatSync(f); return s.isFile() ? s : null; } catch { return null; } };
|
|
903
947
|
function gateReadText(fs, f) {
|
|
904
948
|
let st; try { st = fs.lstatSync(f); } catch (e) { return e.code === 'ENOENT' ? { text: null } : { bad: `can't be read (${e.code}).` }; }
|
|
905
949
|
if (!st.isFile()) return { bad: "not a plain file, so it won't be touched." };
|
|
@@ -1110,7 +1154,7 @@ async function gateInit({ yes = false, remove = false, mode = 'warn', shared = f
|
|
|
1110
1154
|
}
|
|
1111
1155
|
}
|
|
1112
1156
|
const keep = (marker.added ?? []).length || Object.keys(marker.skill_files ?? {}).length || Object.values(HOOK_KINDS).some((k) => marker[k.key] || Object.keys(marker[k.filesKey] ?? {}).length);
|
|
1113
|
-
if (keep) { fs
|
|
1157
|
+
if (keep) { writeInProject(fs, path, cwd, markerRel, JSON.stringify(marker, null, 2) + '\n', markerSt(fs, markerFile)); }
|
|
1114
1158
|
else { try { fs.rmSync(markerFile); } catch { /* none */ } }
|
|
1115
1159
|
return `${remove ? 'Removed' : 'Done'}:\n${lines.join('\n')}\n${remove ? '' : `${K.Name} is on for this project from the next Claude Code session. Turn it off with: ${gateCmd(true)}\n`}Nothing was sent to Lode.`;
|
|
1116
1160
|
}
|
|
@@ -1356,11 +1400,10 @@ async function initCmd({ client = 'all', yes = false, remove = false, gate = fal
|
|
|
1356
1400
|
if (!remove) lines.push(` ${markerRel}: a small note of what lode init added, so --remove undoes only that`);
|
|
1357
1401
|
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' : ''})` : ''}`;
|
|
1358
1402
|
const write = (p, next) => {
|
|
1359
|
-
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`); }
|
|
1360
1403
|
const out = JSON.stringify(next, null, p.indent) + '\n';
|
|
1361
|
-
fs
|
|
1362
|
-
// Check
|
|
1363
|
-
const back = JSON.parse(
|
|
1404
|
+
writeInProject(fs, path, cwd, p.file, p.eol ? out.replace(/\n/g, '\r\n') : out, p.st ?? null);
|
|
1405
|
+
// Check that every other entry is exactly as it was in what was written
|
|
1406
|
+
const back = JSON.parse(out);
|
|
1364
1407
|
for (const k of Object.keys(p.cur)) if (k !== p.key && !same(back[k], p.cur[k])) throw new Error(`${p.file} changed unexpectedly`);
|
|
1365
1408
|
for (const k of Object.keys(p.cur[p.key] || {})) if (k !== 'lode' && !same(back[p.key]?.[k], p.cur[p.key][k])) throw new Error(`${p.file} changed unexpectedly`);
|
|
1366
1409
|
};
|
|
@@ -1373,9 +1416,8 @@ async function initCmd({ client = 'all', yes = false, remove = false, gate = fal
|
|
|
1373
1416
|
const rulesWrite = (p) => {
|
|
1374
1417
|
if (!safe(p.file)) throw new Error('a link appeared');
|
|
1375
1418
|
if (p.text == null) {
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
fs.writeFileSync(p.f, content(p.kind), { flag: 'wx' });
|
|
1419
|
+
// Re-review 04-12-2026: a new rules file is created by the same link-proof writer as the JSON files
|
|
1420
|
+
writeInProject(fs, path, cwd, p.file, content(p.kind));
|
|
1379
1421
|
return;
|
|
1380
1422
|
}
|
|
1381
1423
|
if (p.do === 'rules-add') {
|
|
@@ -1403,7 +1445,6 @@ async function initCmd({ client = 'all', yes = false, remove = false, gate = fal
|
|
|
1403
1445
|
};
|
|
1404
1446
|
for (const p of plan) {
|
|
1405
1447
|
if (p.do === 'add') {
|
|
1406
|
-
fs.mkdirSync(path.dirname(p.f), { recursive: true });
|
|
1407
1448
|
write(p, { ...p.cur, [p.key]: { ...(p.cur[p.key] || {}), lode: p.entry } });
|
|
1408
1449
|
marker.added = [...(marker.added || []).filter((a) => a.file !== p.file), { file: p.file, created: p.created, entry: p.entry, ...(p.cur[p.key] == null && !p.created ? { key_created: true } : {}) }];
|
|
1409
1450
|
}
|
|
@@ -1446,7 +1487,7 @@ async function initCmd({ client = 'all', yes = false, remove = false, gate = fal
|
|
|
1446
1487
|
marker.skill_files = {};
|
|
1447
1488
|
}
|
|
1448
1489
|
}
|
|
1449
|
-
if ((marker.added || []).length || Object.keys(marker.skill_files || {}).length || marker.grok_rules === true || Object.values(HOOK_KINDS).some((k) => marker[k.key] || Object.keys(marker[k.filesKey] || {}).length)) { fs
|
|
1490
|
+
if ((marker.added || []).length || Object.keys(marker.skill_files || {}).length || marker.grok_rules === true || Object.values(HOOK_KINDS).some((k) => marker[k.key] || Object.keys(marker[k.filesKey] || {}).length)) { writeInProject(fs, path, cwd, markerRel, JSON.stringify(marker, null, 2) + '\n', markerSt(fs, markerFile)); }
|
|
1450
1491
|
else { try { fs.rmSync(markerFile); } catch { /* none */ } }
|
|
1451
1492
|
return `${remove ? 'Removed' : 'Done'}:\n${lines.join('\n')}${refusedText}${failed.length ? `\nFailed:\n${failed.join('\n')}` : ''}\n${remove ? '' : 'Commit these files so teammates and sub-agents in this project have Lode. Undo with: ' + runCmd(true) + ' --yes\n'}Nothing was sent to Lode.`;
|
|
1452
1493
|
}
|