trylode 0.2.1 → 0.3.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 +4 -0
- package/README.md +3 -1
- package/bin/cli.mjs +19 -9
- package/package.json +1 -1
- package/skill/PERMISSIONS.md +2 -0
- package/skill/scripts/failure-hook.mjs +173 -0
- package/skill/scripts/failure-signals.json +988 -0
- package/skill/scripts/gate.mjs +5 -3
- package/skill/scripts/lode.mjs +73 -45
package/skill/scripts/gate.mjs
CHANGED
|
@@ -19,7 +19,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
19
19
|
const VERSION = '0.1';
|
|
20
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
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\
|
|
22
|
+
const UA = /^lode-gate-test(\/[\w.-]+)?$/.test(process.env.LODE_UA || '') ? process.env.LODE_UA : `lode-gate/${VERSION}`;
|
|
23
23
|
const BUDGET_MS = 1500;
|
|
24
24
|
const MAX_CONTEXT = 1200;
|
|
25
25
|
// Kept equal to GATE_WARNINGS in Lode's src/lib/gate.mjs (test)
|
|
@@ -125,8 +125,10 @@ const here = path.dirname(fileURLToPath(import.meta.url));
|
|
|
125
125
|
// line that looks like a command or links anywhere but Lode and the package registries is dropped, not shown.
|
|
126
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
127
|
const OK_HOSTS = ['trylode.io', 'www.npmjs.com', 'pypi.org', 'osv.dev'];
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
// Security review 02-12-2026 (LOD-278, same rule as the failure hook): scheme case-insensitive; protocol-relative and
|
|
129
|
+
// script links refused.
|
|
130
|
+
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)
|
|
131
|
+
&& [...t.matchAll(/https?:\/\/([^/\s)\]]+)/gi)].every((m) => OK_HOSTS.includes(m[1].toLowerCase()));
|
|
130
132
|
|
|
131
133
|
// A random code per Claude Code session, kept in the temp folder under a hash of the session id, so Lode can link
|
|
132
134
|
// the checks of one session without ever receiving the session id.
|
package/skill/scripts/lode.mjs
CHANGED
|
@@ -931,16 +931,32 @@ function gateTracked(fs, indexFile, rel) {
|
|
|
931
931
|
return false;
|
|
932
932
|
}
|
|
933
933
|
const gateIsHook = (h) => JSON.stringify(h) === JSON.stringify(GATE_HOOK('warn')) || JSON.stringify(h) === JSON.stringify(GATE_HOOK('ask'));
|
|
934
|
+
// LOD-278: the failure hook, an opt-in PostToolUseFailure hook over Integration Triage. Same install rules as Gate.
|
|
935
|
+
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
|
+
const TRIAGE_FILES_LIST = ['SKILL.md', 'PERMISSIONS.md', 'scripts/lode.mjs', 'scripts/failure-hook.mjs', 'scripts/failure-signals.json'];
|
|
937
|
+
const HOOK_KINDS = {
|
|
938
|
+
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
|
+
entry: (mode) => GATE_HOOK(mode), is: gateIsHook, files: GATE_FILES_LIST,
|
|
940
|
+
what: "Gate sends Lode a request only when the agent installs a package on Lode's list: those package names, the package manager, platform codes from config file names, the mode and a random session code. Never the command, versions, paths or file contents. See PERMISSIONS.md." },
|
|
941
|
+
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
|
+
entry: () => TRIAGE_HOOK(), is: (h) => JSON.stringify(h) === JSON.stringify(TRIAGE_HOOK()), files: TRIAGE_FILES_LIST,
|
|
943
|
+
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." },
|
|
944
|
+
};
|
|
945
|
+
// Removing one hook hands the .gitignore block to the other when the other still uses settings.local.json
|
|
946
|
+
// ...but only when the other hook has no block of its own (security review 02-12-2026, LOD-278)
|
|
947
|
+
const handOverAtRemove = (marker, K, other, localFile) => marker[other.key]?.file === localFile && !marker[other.key]?.ignore;
|
|
934
948
|
// By default the hook goes in .claude/settings.local.json (this person only, not committed), so nobody who clones
|
|
935
949
|
// the project sends anything without choosing to; --shared puts it in .claude/settings.json for the whole team.
|
|
936
|
-
async function gateInit({ yes = false, remove = false, mode = 'warn', shared = false, src = null } = {}) {
|
|
950
|
+
async function gateInit({ yes = false, remove = false, mode = 'warn', shared = false, src = null, kind = 'gate' } = {}) {
|
|
951
|
+
const K = HOOK_KINDS[kind] ?? HOOK_KINDS.gate;
|
|
952
|
+
const other = Object.values(HOOK_KINDS).find((x) => x !== K);
|
|
937
953
|
// Through npx trylode (LOD-262) the user has no lode.mjs, so every command shown is trylode's own.
|
|
938
|
-
const gateCmd = (rm) => (src === 'setup' ? `npx trylode ${rm ? 'remove' : 'setup'}
|
|
954
|
+
const gateCmd = (rm) => (src === 'setup' ? `npx trylode ${rm ? 'remove' : 'setup'} ${K.flag} --yes` : `node lode.mjs init ${K.flag}${rm ? ' --remove' : ''} --yes`);
|
|
939
955
|
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');
|
|
940
956
|
const cwd = fs.realpathSync(process.cwd());
|
|
941
|
-
if (cwd === path.parse(cwd).root || cwd === fs.realpathSync(os.homedir())) return
|
|
957
|
+
if (cwd === path.parse(cwd).root || cwd === fs.realpathSync(os.homedir())) return `lode init ${K.flag} only runs inside a project folder, not your home folder or the root. Nothing was written.`;
|
|
942
958
|
const MARKERS = ['.git', 'package.json', 'pyproject.toml', 'go.mod', 'Gemfile', 'requirements.txt', 'Cargo.toml', 'deno.json', 'composer.json'];
|
|
943
|
-
if (!MARKERS.some((m) => fs.existsSync(path.join(cwd, m)))) return `lode init
|
|
959
|
+
if (!MARKERS.some((m) => fs.existsSync(path.join(cwd, m)))) return `lode init ${K.flag} didn't find a project here (none of ${MARKERS.join(', ')}). Run it from the project's root folder. Nothing was written.`;
|
|
944
960
|
const safe = (rel) => { let p = cwd; for (const part of rel.split(/[\\/]/)) { p = path.join(p, part); try { if (fs.lstatSync(p).isSymbolicLink()) return false; } catch { return true; } } return true; };
|
|
945
961
|
const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
946
962
|
const hash = (f) => crypto.createHash('sha256').update(fs.readFileSync(f)).digest('hex');
|
|
@@ -955,14 +971,18 @@ async function gateInit({ yes = false, remove = false, mode = 'warn', shared = f
|
|
|
955
971
|
let m; try { m = JSON.parse(mr.text); } catch { m = undefined; }
|
|
956
972
|
const plainObj = (o) => !!o && typeof o === 'object' && !Array.isArray(o);
|
|
957
973
|
// A planted note must not steer which file is edited or which hook is taken out (security review 02-12-2026)
|
|
958
|
-
|
|
959
|
-
const
|
|
960
|
-
|
|
961
|
-
|
|
974
|
+
// Every hook's part of the note is checked, whichever hook this run is for (LOD-278)
|
|
975
|
+
const kindOk = (k) => {
|
|
976
|
+
const g = m?.[k.key], ig = g?.ignore, files = m?.[k.filesKey];
|
|
977
|
+
return (g == null || (plainObj(g) && ALLOWED_SETTINGS.includes(g.file) && typeof g.created === 'boolean' && k.is(g.entry)
|
|
978
|
+
&& (ig == null || (plainObj(ig) && ig.line === GATE_IGNORE_LINE && typeof ig.created === 'boolean'))))
|
|
979
|
+
&& (files == null || (plainObj(files) && Object.values(files).every((h) => typeof h === 'string' && /^[0-9a-f]{64}$/.test(h))));
|
|
980
|
+
};
|
|
981
|
+
if (!plainObj(m) || !Object.values(HOOK_KINDS).every(kindOk))
|
|
962
982
|
return `${markerRel} isn't the note lode init writes, so nothing was changed. Nothing was written.`;
|
|
963
983
|
marker = m;
|
|
964
984
|
}
|
|
965
|
-
const settingsRel = remove && ALLOWED_SETTINGS.includes(marker.
|
|
985
|
+
const settingsRel = remove && ALLOWED_SETTINGS.includes(marker[K.key]?.file) ? marker[K.key].file : ALLOWED_SETTINGS[shared ? 1 : 0];
|
|
966
986
|
const settingsFile = path.join(cwd, settingsRel);
|
|
967
987
|
for (const rel of [markerRel, settingsRel]) if (!safe(rel)) return `${rel}: it or a folder above it is a link, so lode init won't write there. Nothing was written.`;
|
|
968
988
|
let cur = {};
|
|
@@ -971,23 +991,23 @@ async function gateInit({ yes = false, remove = false, mode = 'warn', shared = f
|
|
|
971
991
|
const text = sr.text;
|
|
972
992
|
if (text != null) {
|
|
973
993
|
try { cur = JSON.parse(text); if (!gateLossless(text)) cur = undefined; } catch { cur = undefined; }
|
|
974
|
-
const pre = cur?.hooks?.
|
|
994
|
+
const pre = cur?.hooks?.[K.event];
|
|
975
995
|
if (!cur || typeof cur !== 'object' || Array.isArray(cur) || (cur.hooks != null && (typeof cur.hooks !== 'object' || Array.isArray(cur.hooks))) || (pre != null && !Array.isArray(pre)))
|
|
976
|
-
return `${settingsRel}: not plain JSON that lode init can safely edit. Add this under "hooks" -> "
|
|
996
|
+
return `${settingsRel}: not plain JSON that lode init can safely edit. Add this under "hooks" -> "${K.event}" by hand: ${JSON.stringify(K.entry(mode))}. Nothing was written.`;
|
|
977
997
|
}
|
|
978
998
|
const indent = (text?.match(/\n([ \t]+)"/) || [])[1] || 2;
|
|
979
|
-
const pre = cur.hooks?.
|
|
980
|
-
const ours = marker.
|
|
999
|
+
const pre = cur.hooks?.[K.event] ?? [];
|
|
1000
|
+
const ours = marker[K.key];
|
|
981
1001
|
// Only Lode's own hook entry, never an entry named by the note (security review 02-12-2026)
|
|
982
|
-
const present = pre.findIndex(
|
|
1002
|
+
const present = pre.findIndex(K.is);
|
|
983
1003
|
const skillRel = path.join('.claude', 'skills', 'lode-integration-check');
|
|
984
1004
|
const skillDst = path.join(cwd, skillRel), skillSrc = path.resolve(path.dirname(url.fileURLToPath(import.meta.url)), '..');
|
|
985
|
-
const GATE_FILES =
|
|
1005
|
+
const GATE_FILES = K.files.map((f) => f.split('/').join(path.sep));
|
|
986
1006
|
if (!safe(skillRel) || GATE_FILES.some((f) => !safe(path.join(skillRel, f)))) return `${skillRel}: it, a folder in it or a file in it is a link, so lode init won't touch it. Nothing was written.`;
|
|
987
1007
|
// A Gate file already in the project that differs from this skill's own would run on every shell command: refuse
|
|
988
1008
|
if (!remove && path.resolve(skillSrc) !== path.resolve(skillDst)) {
|
|
989
1009
|
const differ = GATE_FILES.filter((f) => { const to = path.join(skillDst, f), from = path.join(skillSrc, f); try { return fs.existsSync(to) && (!fs.lstatSync(to).isFile() || hash(to) !== hash(from)); } catch { return true; } });
|
|
990
|
-
if (differ.length) return `${skillRel}: ${differ.join(', ')} already exist and differ from this copy of the Lode skill, so lode init won't switch
|
|
1010
|
+
if (differ.length) return `${skillRel}: ${differ.join(', ')} already exist and differ from this copy of the Lode skill, so lode init won't switch ${K.name} on (that code would run on every shell command). Check or remove them first. Nothing was written.`;
|
|
991
1011
|
}
|
|
992
1012
|
// settings.local.json must stay out of git, or teammates get Gate without choosing it (security review 02-12-2026)
|
|
993
1013
|
let ign = null;
|
|
@@ -997,77 +1017,84 @@ async function gateInit({ yes = false, remove = false, mode = 'warn', shared = f
|
|
|
997
1017
|
let git = false, gitRoot = null; for (let d = cwd; ; d = path.dirname(d)) { if (fs.existsSync(path.join(d, '.git'))) { git = true; gitRoot = d; break; } if (d === path.dirname(d)) break; }
|
|
998
1018
|
const inRepo = gitRoot ? path.relative(gitRoot, settingsFile).split(path.sep).join('/') : null;
|
|
999
1019
|
if (gitRoot && gateTracked(fs, path.join(gitRoot, '.git', 'index'), inRepo))
|
|
1000
|
-
return `${settingsRel} is already committed to git, so a hook added there would reach everyone who clones the project. To have
|
|
1020
|
+
return `${settingsRel} is already committed to git, so a hook added there would reach everyone who clones the project. To have ${K.name} only for you, untrack it first (git rm --cached ${inRepo}). Nothing was written.`;
|
|
1001
1021
|
const t = (ir.text ?? '').replace(/\r\n/g, '\n');
|
|
1002
1022
|
ign = { text: ir.text, need: git && !t.endsWith(GATE_IGNORE_BLOCK) };
|
|
1003
1023
|
}
|
|
1004
|
-
const ignOurs = marker.
|
|
1024
|
+
const ignOurs = marker[K.key]?.ignore;
|
|
1005
1025
|
const lines = [];
|
|
1006
1026
|
if (remove) {
|
|
1007
|
-
if (present < 0 && !Object.keys(marker.
|
|
1008
|
-
if (present >= 0) lines.push(` ${settingsRel}: remove
|
|
1009
|
-
if (Object.keys(marker.
|
|
1010
|
-
|
|
1027
|
+
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
|
+
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
|
+
if (Object.keys(marker[K.filesKey] ?? {}).length) lines.push(` ${skillRel}/: delete ${K.filesLabel} lode init copied, if unchanged`);
|
|
1030
|
+
const handOver = ignOurs && handOverAtRemove(marker, K, other, ALLOWED_SETTINGS[0]);
|
|
1031
|
+
if (ignOurs) lines.push(handOver ? ` ${ignoreRel}: keep its two lines, since ${other.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' : ''}`);
|
|
1011
1032
|
} else {
|
|
1012
|
-
if (present >= 0) return
|
|
1013
|
-
lines.push(` ${settingsRel}: ${text == null ? 'create it with' : 'add'} one
|
|
1033
|
+
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)'}`);
|
|
1014
1035
|
const missing = GATE_FILES.filter((f) => !fs.existsSync(path.join(skillDst, f)));
|
|
1015
1036
|
if (missing.length && path.resolve(skillSrc) !== path.resolve(skillDst)) lines.push(` ${skillRel}/: copy ${missing.join(', ')} (no dependencies, nothing runs on install)`);
|
|
1016
1037
|
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`);
|
|
1017
1038
|
lines.push(` ${markerRel}: a small note of what lode init added, so --remove undoes only that`);
|
|
1018
1039
|
}
|
|
1019
|
-
const what =
|
|
1020
|
-
if (!yes) return `lode init
|
|
1040
|
+
const what = K.what;
|
|
1041
|
+
if (!yes) return `lode init ${K.flag} would ${remove ? 'change' : 'write'} these files in ${cwd}:\n${lines.join('\n')}\n${remove ? '' : `${what}\n`}Nothing has been written. If the user agrees, run: ${src === 'setup' ? gateCmd(remove) : `node lode.mjs init ${K.flag}${remove ? ' --remove' : ''}${!remove && K.modes && mode === 'ask' ? ' --mode ask' : ''}${!remove && shared ? ' --shared' : ''} --yes`}`;
|
|
1021
1042
|
if (remove) {
|
|
1022
1043
|
if (present >= 0) {
|
|
1023
|
-
const next = { ...cur, hooks: { ...cur.hooks,
|
|
1024
|
-
if (!next.hooks.
|
|
1044
|
+
const next = { ...cur, hooks: { ...cur.hooks, [K.event]: pre.filter((_, i) => i !== present) } };
|
|
1045
|
+
if (!next.hooks[K.event].length) delete next.hooks[K.event];
|
|
1025
1046
|
if (!Object.keys(next.hooks).length) delete next.hooks;
|
|
1026
1047
|
if (ours?.created && !Object.keys(next).length) fs.rmSync(settingsFile); else fs.writeFileSync(settingsFile, JSON.stringify(next, null, indent) + '\n');
|
|
1048
|
+
// The other hook now owns the file this one created, so removing it later deletes the file if nothing else is left
|
|
1049
|
+
if (ours?.created && marker[other.key]?.file === settingsRel) marker[other.key].created = true;
|
|
1027
1050
|
}
|
|
1028
1051
|
// Only files from the fixed list, inside the skill folder, not through links, regular files, unchanged
|
|
1029
|
-
for (const [rel, h] of Object.entries(marker.
|
|
1052
|
+
for (const [rel, h] of Object.entries(marker[K.filesKey] ?? {})) {
|
|
1030
1053
|
if (!GATE_FILES.includes(rel) || !safe(path.join(skillRel, rel))) continue;
|
|
1054
|
+
// A file the other hook also needs stays while that hook is on, and becomes the other hook's to remove (LOD-278)
|
|
1055
|
+
if (marker[other.key] && other.files.map((x) => x.split('/').join(path.sep)).includes(rel)) { marker[other.filesKey] = { ...(marker[other.filesKey] ?? {}), [rel]: h }; continue; }
|
|
1031
1056
|
const f = path.join(skillDst, rel);
|
|
1032
1057
|
if (!path.resolve(f).startsWith(path.resolve(skillDst) + path.sep)) continue;
|
|
1033
1058
|
try { if (fs.lstatSync(f).isFile() && hash(f) === h) fs.rmSync(f); } catch { /* gone */ }
|
|
1034
1059
|
}
|
|
1035
1060
|
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 */ } }
|
|
1036
|
-
if (ignOurs) {
|
|
1061
|
+
if (ignOurs && handOverAtRemove(marker, K, other, ALLOWED_SETTINGS[0])) {
|
|
1062
|
+
marker[other.key].ignore = ignOurs; // the other hook still needs settings.local.json kept out of git
|
|
1063
|
+
} else if (ignOurs) {
|
|
1037
1064
|
const ir = gateReadText(fs, ignoreFile);
|
|
1038
1065
|
const t = ir.text ?? '';
|
|
1039
1066
|
const i = t.lastIndexOf(GATE_IGNORE_BLOCK);
|
|
1040
1067
|
if (!ir.bad && i >= 0 && (i === 0 || t[i - 1] === '\n')) { const rest = t.slice(0, i) + t.slice(i + GATE_IGNORE_BLOCK.length); if (ignOurs.created && rest === '') fs.rmSync(ignoreFile); else fs.writeFileSync(ignoreFile, rest); }
|
|
1041
1068
|
}
|
|
1042
|
-
delete marker.
|
|
1069
|
+
delete marker[K.key]; delete marker[K.filesKey];
|
|
1043
1070
|
} else {
|
|
1044
|
-
const entry =
|
|
1071
|
+
const entry = K.entry(mode);
|
|
1045
1072
|
fs.mkdirSync(path.dirname(settingsFile), { recursive: true });
|
|
1046
|
-
const next = { ...cur, hooks: { ...(cur.hooks ?? {}),
|
|
1073
|
+
const next = { ...cur, hooks: { ...(cur.hooks ?? {}), [K.event]: [...pre, entry] } };
|
|
1047
1074
|
fs.writeFileSync(settingsFile, JSON.stringify(next, null, indent) + '\n');
|
|
1048
1075
|
const back = JSON.parse(fs.readFileSync(settingsFile, 'utf8'));
|
|
1049
1076
|
for (const k of Object.keys(cur)) if (k !== 'hooks' && !same(back[k], cur[k])) throw new Error(`${settingsRel} changed unexpectedly`);
|
|
1050
|
-
for (const k of Object.keys(cur.hooks ?? {})) if (k !==
|
|
1051
|
-
marker.
|
|
1077
|
+
for (const k of Object.keys(cur.hooks ?? {})) if (k !== K.event && !same(back.hooks?.[k], cur.hooks[k])) throw new Error(`${settingsRel} changed unexpectedly`);
|
|
1078
|
+
marker[K.key] = { file: settingsRel, created: text == null, entry };
|
|
1052
1079
|
if (ign?.need) {
|
|
1053
1080
|
const t = ign.text ?? '';
|
|
1054
1081
|
fs.writeFileSync(ignoreFile, `${t}${t && !t.endsWith('\n') ? '\n' : ''}${GATE_IGNORE_BLOCK}`);
|
|
1055
|
-
marker.
|
|
1082
|
+
marker[K.key].ignore = { line: GATE_IGNORE_LINE, created: ign.text == null };
|
|
1056
1083
|
}
|
|
1057
|
-
marker.
|
|
1084
|
+
marker[K.filesKey] = marker[K.filesKey] ?? {};
|
|
1058
1085
|
if (path.resolve(skillSrc) !== path.resolve(skillDst)) for (const rel of GATE_FILES) {
|
|
1059
1086
|
const from = path.join(skillSrc, rel), to = path.join(skillDst, rel);
|
|
1060
1087
|
if (fs.existsSync(to) || !fs.existsSync(from)) continue;
|
|
1061
1088
|
fs.mkdirSync(path.dirname(to), { recursive: true });
|
|
1062
1089
|
if (!safe(path.join(skillRel, rel))) continue;
|
|
1063
1090
|
try { fs.copyFileSync(from, to, fs.constants.COPYFILE_EXCL); } catch { continue; }
|
|
1064
|
-
marker.
|
|
1091
|
+
marker[K.filesKey][rel] = hash(to);
|
|
1065
1092
|
}
|
|
1066
1093
|
}
|
|
1067
|
-
const keep = (marker.added ?? []).length || Object.keys(marker.skill_files ?? {}).length || marker.
|
|
1094
|
+
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);
|
|
1068
1095
|
if (keep) { fs.mkdirSync(path.dirname(markerFile), { recursive: true }); fs.writeFileSync(markerFile, JSON.stringify(marker, null, 2) + '\n'); }
|
|
1069
1096
|
else { try { fs.rmSync(markerFile); } catch { /* none */ } }
|
|
1070
|
-
return `${remove ? 'Removed' : 'Done'}:\n${lines.join('\n')}\n${remove ? '' :
|
|
1097
|
+
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.`;
|
|
1071
1098
|
}
|
|
1072
1099
|
|
|
1073
1100
|
// lode init (Paul approved 27-11-2026): put Lode in the project's own config so teammates and sub-agents have it.
|
|
@@ -1090,12 +1117,13 @@ export const RULES_MDC = rulesMdc(RULE);
|
|
|
1090
1117
|
// Every block and rule file a released init has written, newest first.
|
|
1091
1118
|
export const KNOWN_BLOCKS = [RULES_BLOCK, rulesBlock(RULE_V1)];
|
|
1092
1119
|
export const KNOWN_MDCS = [RULES_MDC, rulesMdc(RULE_V1)];
|
|
1093
|
-
async function initCmd({ client = 'all', yes = false, remove = false, gate = false, gateMode = 'warn', gateShared = false, rules = true, src = null } = {}) {
|
|
1120
|
+
async function initCmd({ client = 'all', yes = false, remove = false, gate = false, triage = false, gateMode = 'warn', gateShared = false, rules = true, src = null } = {}) {
|
|
1094
1121
|
const serverUrl = src === 'setup' ? SETUP_URL : LODE_URL;
|
|
1095
1122
|
// The command the user or agent should run next: npx trylode's own when called through it (security review
|
|
1096
1123
|
// 01-12-2026: a project has no lode.mjs, so pointing an agent at it failed or wrote the untagged address).
|
|
1097
1124
|
const runCmd = (rm) => (src === 'setup' ? `npx trylode ${rm ? 'remove' : 'setup'}` : `node lode.mjs init${rm ? ' --remove' : ''}`);
|
|
1098
1125
|
if (gate) return gateInit({ yes, remove, mode: gateMode, shared: gateShared, src });
|
|
1126
|
+
if (triage) return gateInit({ yes, remove, shared: gateShared, src, kind: 'triage' });
|
|
1099
1127
|
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');
|
|
1100
1128
|
const cwd = fs.realpathSync(process.cwd());
|
|
1101
1129
|
// Only inside a project: never the home folder or the root, and only where a project marker exists (security review 27-11-2026)
|
|
@@ -1317,7 +1345,7 @@ async function initCmd({ client = 'all', yes = false, remove = false, gate = fal
|
|
|
1317
1345
|
marker.skill_files = {};
|
|
1318
1346
|
}
|
|
1319
1347
|
}
|
|
1320
|
-
if ((marker.added || []).length || Object.keys(marker.skill_files || {}).length || marker.
|
|
1348
|
+
if ((marker.added || []).length || Object.keys(marker.skill_files || {}).length || Object.values(HOOK_KINDS).some((k) => marker[k.key] || Object.keys(marker[k.filesKey] || {}).length)) { fs.mkdirSync(path.dirname(markerFile), { recursive: true }); fs.writeFileSync(markerFile, JSON.stringify(marker, null, 2) + '\n'); }
|
|
1321
1349
|
else { try { fs.rmSync(markerFile); } catch { /* none */ } }
|
|
1322
1350
|
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.`;
|
|
1323
1351
|
}
|
|
@@ -1531,9 +1559,9 @@ export async function main(argv) {
|
|
|
1531
1559
|
return triageCmd(rest[0], rest[1], opts);
|
|
1532
1560
|
}
|
|
1533
1561
|
if (cmd === 'init') {
|
|
1534
|
-
const opts = { client: flag('--client'), yes: flag('--yes'), remove: flag('--remove'), gate: flag('--gate'), mode: flag('--mode'), shared: flag('--shared'), noRules: flag('--no-rules'), src: flag('--src') };
|
|
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') };
|
|
1535
1563
|
const client = ['claude', 'cursor', 'all'].includes(opts.client) ? opts.client : 'all';
|
|
1536
|
-
return initCmd({ client, yes: opts.yes === true, remove: opts.remove === true, gate: opts.gate === true, gateMode: opts.mode === 'ask' ? 'ask' : 'warn', gateShared: opts.shared === true, rules: opts.noRules !== true, src: opts.src === 'setup' ? 'setup' : null });
|
|
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 });
|
|
1537
1565
|
}
|
|
1538
1566
|
if (cmd === 'watch') {
|
|
1539
1567
|
const opts = { share: flag('--share'), projectCode: flag('--project-code'), since: flag('--since') };
|
|
@@ -1541,7 +1569,7 @@ export async function main(argv) {
|
|
|
1541
1569
|
return watchCmd(sub, { share: opts.share === true, projectCode: opts.projectCode === true, since: opts.since });
|
|
1542
1570
|
}
|
|
1543
1571
|
if (cmd === 'platforms') return `Lode covers: ${Object.keys(PLATFORMS).join(', ')}. Facts are source-linked and dated; see https://trylode.io/methodology/`;
|
|
1544
|
-
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 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';
|
|
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';
|
|
1545
1573
|
}
|
|
1546
1574
|
|
|
1547
1575
|
// Run only when this very file is the entry point (security review 01-12-2026: endsWith('lode.mjs') also matched trylode.mjs).
|