trylode 0.5.0 → 0.5.2
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/PERMISSIONS.md +1 -1
- package/skill/scripts/failure-hook.mjs +1 -1
- package/skill/scripts/lode.mjs +62 -18
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.2",
|
|
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,7 +16,7 @@ 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`, `.vscode/mcp.json`, `.gemini/settings.json`, `.codex/config.toml`, `.claude/lode-init.json`, `CLAUDE.md`, `AGENTS.md`, `GEMINI.md`, `.cursor/rules/lode.mdc`, `.grok/rules/lode.md` (only when the rules line won't be in `AGENTS.md`), and with `--no-agents-md` `.github/copilot-instructions.md` | nothing | only with `--yes`, only inside a project folder and never through links: one `lode` entry in those MCP files (`--client claude`, `cursor`, `vscode`, `gemini` or `codex` picks one client; in `.codex/config.toml` it is one marked `[mcp_servers.lode]` block added at the end, and a file that already names a `lode` server or has an inline `mcp_servers` table is left alone), a copy of this skill in `.claude/skills/`, the Lode rules
|
|
19
|
+
| `init` | `.mcp.json`, `.cursor/mcp.json`, `.vscode/mcp.json`, `.gemini/settings.json`, `.codex/config.toml`, `.claude/lode-init.json`, `CLAUDE.md`, `AGENTS.md`, `GEMINI.md`, `.cursor/rules/lode.mdc`, `.grok/rules/lode.md` (only when the rules line won't be in `AGENTS.md`), and with `--no-agents-md` `.github/copilot-instructions.md` | nothing | only with `--yes`, only inside a project folder and never through links: one `lode` entry in those MCP files (`--client claude`, `cursor`, `vscode`, `gemini` or `codex` picks one client; in `.codex/config.toml` it is one marked `[mcp_servers.lode]` block added at the end, and a file that already names a `lode` server or has an inline `mcp_servers` table is left alone), a copy of this skill in `.claude/skills/`, the Lode rules lines (check integrations with Lode; record integration decisions in `docs/adr/`) as one marked block at the end of `CLAUDE.md`, `AGENTS.md` and `GEMINI.md` (each created if missing; `AGENTS.md` left out with `--no-agents-md`, which writes the line to `.github/copilot-instructions.md` instead; `.grok/rules/lode.md` gets it whenever it won't be in `AGENTS.md`, and is removed only if unchanged and the note says init created it) 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 |
|
|
@@ -84,7 +84,7 @@ export function loadSignals() {
|
|
|
84
84
|
|
|
85
85
|
// ---- Step 2: the hook (PostToolUseFailure). Sends only app, platform, symptom code and status number, never the
|
|
86
86
|
// output text, the command, paths, versions or the session id. Asks once per app, platform and symptom in a session.
|
|
87
|
-
const VERSION = '2026.12.
|
|
87
|
+
const VERSION = '2026.12.5'; // the skill's version: kept equal to SKILL_VERSION in lode.mjs by a test
|
|
88
88
|
// The hook ships inside the skill, so it identifies as the skill: the server already counts `lode-skill` and leaves
|
|
89
89
|
// `lode-skill-test` (Lode's own tests) out of every figure. Only Lode's tests may point it at this machine.
|
|
90
90
|
const BASE = (() => { const u = process.env.LODE_GATE_URL || ''; return /^http:\/\/(127\.0\.0\.1|localhost)(:\d+)?$/.test(u) ? u : 'https://trylode.io'; })();
|
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
|
// The skill's version (year.month.day of its last change; a test makes every change bump it), sent in the user agent
|
|
58
58
|
// so Lode can count which copies agents run. Copies before 03-12-2026 all sent 0.1.
|
|
59
|
-
export const SKILL_VERSION = '2026.12.
|
|
59
|
+
export const SKILL_VERSION = '2026.12.5';
|
|
60
60
|
const UA = process.env.LODE_UA || `lode-skill/${SKILL_VERSION} (+https://trylode.io/agents/)`;
|
|
61
61
|
|
|
62
62
|
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' };
|
|
@@ -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
|
}
|
|
@@ -1128,13 +1172,16 @@ const SETUP_URL = 'https://trylode.io/mcp?src=setup';
|
|
|
1128
1172
|
// blocks and rule files written with v1 are still recognised, so they count as set up and init --remove still takes them out.
|
|
1129
1173
|
export const RULE_V1 = "Before you add, recommend or install a third-party integration or SDK, check it with the Lode MCP server (https://trylode.io/mcp?src=rules): call check_stack for the apps this project already uses, or find_integrations or get_integration for the one you are adding. Quote Lode's facts with their dates. If Lode has no record, say it is not documented by Lode, not that it is unsupported.";
|
|
1130
1174
|
export const RULE = "Before you add, recommend or install a third-party integration or SDK, or decide to build that capability yourself (email, auth, payments, background jobs, rate limiting and similar), check it with the Lode MCP server (https://trylode.io/mcp?src=rules): call check_stack for the apps this project already uses, then find_integrations for the options or get_integration for the one you are adding. Quote Lode's facts with their dates. If Lode has no record, say it is not documented by Lode, not that it is unsupported.";
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
export const
|
|
1134
|
-
|
|
1175
|
+
// LOD-315 (Paul approved the line 04-12-2026; harness 05-12-2026: with it 2 of 2 agent picks saved a decision record, without it 0 of 3):
|
|
1176
|
+
// blocks and rule files from 2026.12.5 add the decision-record line after the rule. Earlier ones are still recognised.
|
|
1177
|
+
export const RULE_DECISION = 'Integration decisions are recorded in docs/adr/. Before adding, changing or removing an integration, check it with Lode and write a new record.';
|
|
1178
|
+
const rulesBlock = (rule, extra) => `<!-- lode:rules (added by lode init; node lode.mjs init --remove --yes takes it out) -->\n## Integrations\n${rule}\n${extra ? `${extra}\n` : ''}<!-- /lode:rules -->\n`;
|
|
1179
|
+
const rulesMdc = (rule, extra) => `---\ndescription: Check third-party integrations with Lode before adding them\nalwaysApply: true\n---\n${rule}\n${extra ? `${extra}\n` : ''}`;
|
|
1180
|
+
export const RULES_BLOCK = rulesBlock(RULE, RULE_DECISION);
|
|
1181
|
+
export const RULES_MDC = rulesMdc(RULE, RULE_DECISION);
|
|
1135
1182
|
// Every block and rule file a released init has written, newest first.
|
|
1136
|
-
export const KNOWN_BLOCKS = [RULES_BLOCK, rulesBlock(RULE_V1)];
|
|
1137
|
-
export const KNOWN_MDCS = [RULES_MDC, rulesMdc(RULE_V1)];
|
|
1183
|
+
export const KNOWN_BLOCKS = [RULES_BLOCK, rulesBlock(RULE), rulesBlock(RULE_V1)];
|
|
1184
|
+
export const KNOWN_MDCS = [RULES_MDC, rulesMdc(RULE), rulesMdc(RULE_V1)];
|
|
1138
1185
|
// LOD-306: the Codex server block (.codex/config.toml), for either address init writes.
|
|
1139
1186
|
export const codexBlock = (u) => `# lode:mcp (added by lode init; npx trylode remove --yes takes it out)\n[mcp_servers.lode]\nurl = "${u}"\n`;
|
|
1140
1187
|
export const KNOWN_TOMLS = [SETUP_URL, LODE_URL].map(codexBlock);
|
|
@@ -1349,18 +1396,17 @@ async function initCmd({ client = 'all', yes = false, remove = false, gate = fal
|
|
|
1349
1396
|
: p.do === 'remove' ? ` ${p.file}: remove the "lode" entry lode init added (other entries unchanged)${p.created ? '; delete the file if nothing else is left in it' : ''}`
|
|
1350
1397
|
: p.do === 'rules-add' && p.kind === 'toml' ? ` ${p.file}: ${p.text == null ? 'create it with' : 'add, at the end,'} one server "lode" -> ${serverUrl}${p.text == null ? '' : '; nothing else in the file changes'} (Codex reads it in a trusted project)`
|
|
1351
1398
|
: p.do === 'rules-remove' && p.kind === 'toml' ? ` ${p.file}: remove the "lode" server lode init added (nothing else in the file changes)`
|
|
1352
|
-
: p.do === 'rules-add' ? ` ${p.file}: ${p.text == null ? 'create it with' : 'add, at the end,'} the Lode rules
|
|
1399
|
+
: p.do === 'rules-add' ? ` ${p.file}: ${p.text == null ? 'create it with' : 'add, at the end,'} the Lode rules lines (the agent checks Lode before it adds an integration, and writes a decision record in docs/adr/)${p.text == null ? '' : '; nothing else in the file changes'}`
|
|
1353
1400
|
: p.do === 'rules-remove' ? ` ${p.file}: remove the Lode rules ${p.kind === 'md' ? 'line' : 'file'} lode init added${p.kind === 'md' ? ' (nothing else in the file changes)' : ''}`
|
|
1354
1401
|
: 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)`
|
|
1355
1402
|
: ` ${p.file}/: delete the skill files lode init copied, if unchanged`);
|
|
1356
1403
|
if (!remove) lines.push(` ${markerRel}: a small note of what lode init added, so --remove undoes only that`);
|
|
1357
1404
|
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
1405
|
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
1406
|
const out = JSON.stringify(next, null, p.indent) + '\n';
|
|
1361
|
-
fs
|
|
1362
|
-
// Check
|
|
1363
|
-
const back = JSON.parse(
|
|
1407
|
+
writeInProject(fs, path, cwd, p.file, p.eol ? out.replace(/\n/g, '\r\n') : out, p.st ?? null);
|
|
1408
|
+
// Check that every other entry is exactly as it was in what was written
|
|
1409
|
+
const back = JSON.parse(out);
|
|
1364
1410
|
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
1411
|
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
1412
|
};
|
|
@@ -1373,9 +1419,8 @@ async function initCmd({ client = 'all', yes = false, remove = false, gate = fal
|
|
|
1373
1419
|
const rulesWrite = (p) => {
|
|
1374
1420
|
if (!safe(p.file)) throw new Error('a link appeared');
|
|
1375
1421
|
if (p.text == null) {
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
fs.writeFileSync(p.f, content(p.kind), { flag: 'wx' });
|
|
1422
|
+
// Re-review 04-12-2026: a new rules file is created by the same link-proof writer as the JSON files
|
|
1423
|
+
writeInProject(fs, path, cwd, p.file, content(p.kind));
|
|
1379
1424
|
return;
|
|
1380
1425
|
}
|
|
1381
1426
|
if (p.do === 'rules-add') {
|
|
@@ -1403,7 +1448,6 @@ async function initCmd({ client = 'all', yes = false, remove = false, gate = fal
|
|
|
1403
1448
|
};
|
|
1404
1449
|
for (const p of plan) {
|
|
1405
1450
|
if (p.do === 'add') {
|
|
1406
|
-
fs.mkdirSync(path.dirname(p.f), { recursive: true });
|
|
1407
1451
|
write(p, { ...p.cur, [p.key]: { ...(p.cur[p.key] || {}), lode: p.entry } });
|
|
1408
1452
|
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
1453
|
}
|
|
@@ -1446,7 +1490,7 @@ async function initCmd({ client = 'all', yes = false, remove = false, gate = fal
|
|
|
1446
1490
|
marker.skill_files = {};
|
|
1447
1491
|
}
|
|
1448
1492
|
}
|
|
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
|
|
1493
|
+
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
1494
|
else { try { fs.rmSync(markerFile); } catch { /* none */ } }
|
|
1451
1495
|
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
1496
|
}
|