lintsure 0.3.18 → 0.3.20

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.
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: lintsure-rules
3
3
  description: >-
4
- Use whenever a message starts with "Lintsure:" followed by a rule in plain words ("Lintsure: never let it touch the payment code", "Lintsure: always use our logger"), and whenever the user states a standing rule for how agents must work in this project (never, always, don't, only, ask before). Also use when the user wants to set up, suggest, add or see Lintsure rules ("Lintsure, suggest rules", "what rules do we have"), or share them with other agents ("make Cursor follow these too"). Turns the words into one rule, tries it, and writes it to .lintsure/rules.yml only after the user agrees.
4
+ Use whenever a message starts with "Lintsure:" followed by a rule in plain words ("Lintsure: never let it touch the payment code", "Lintsure: always use our logger"), and whenever the user states a standing rule for how agents must work in this project (never, always, don't, only, ask before). Also use when the user wants to set up, suggest, add or see Lintsure rules ("Lintsure, suggest rules", "what rules do we have"), or share them with other agents ("make Grok Build follow these too"). Turns the words into one rule, tries it, and writes it to .lintsure/rules.yml only after the user agrees.
5
5
  ---
6
6
 
7
7
  # Lintsure rules
@@ -39,9 +39,11 @@ Run `rules.mjs list` and show the list.
39
39
 
40
40
  ## Share the rules with other agents
41
41
 
42
- Each agent (Cursor, Codex, Copilot, Claude Code) reads its own instruction file. When the user wants them to follow the same rules, or after setting up rules for the first time, offer once:
42
+ Each agent (Grok Build, Codex, Copilot, Gemini CLI, Claude Code) reads its own instruction file. When the user wants them to follow the same rules, or after setting up rules for the first time, offer once:
43
43
 
44
- 1. Run `rules.mjs sync`. It writes the rules to `AGENTS.md` and `.cursor/rules/lintsure.mdc`, plus `.github/copilot-instructions.md` and `CLAUDE.md` if those files exist. To pick, pass targets: `rules.mjs sync agents,cursor,copilot,claude`.
44
+ 1. Run `rules.mjs sync`. It writes the rules to `AGENTS.md` and `.grok/rules/lintsure.md`, plus `.github/copilot-instructions.md`, `CLAUDE.md` and `GEMINI.md` if those files exist. To pick, pass targets: `rules.mjs sync agents,grok,copilot,claude,gemini`. Rules tied to files are written as path-scoped files for Claude Code (`.claude/rules/`) and Copilot (`.github/instructions/`), so those agents load them only for matching files.
45
+
46
+ A rule can be for named agents only. When the user says so ("Lintsure: Codex must never touch the migrations"), add `"agents": "codex"` to the rule's JSON. The ids are claude, grok, codex, gemini and copilot, and several go in one comma list. Without it the rule is for every agent. The rules file belongs to the project it sits in, so each project keeps its own rules.
45
47
  2. In shared files Lintsure only writes its own marked block; the user's text stays as it is. Tell the user which files changed.
46
48
  3. After that, adding a rule with `rules.mjs write` keeps those files in step by itself.
47
49
  4. To take it out again: `rules.mjs unsync`.
@@ -1,23 +1,38 @@
1
1
  // One rules file for every agent: writes the rules from .lintsure/rules.yml into the instruction files other agents
2
- // read (AGENTS.md for Codex and many others, Cursor's rules folder, GitHub Copilot, CLAUDE.md). Lintsure owns only its
2
+ // read (AGENTS.md for Codex and many others, Grok Build's rules folder, GitHub Copilot, CLAUDE.md). Lintsure owns only its
3
3
  // own marked block in shared files, so the user's text around it is never touched.
4
- import { readFileSync, writeFileSync, mkdirSync, existsSync, unlinkSync } from "node:fs";
4
+ import { readFileSync, writeFileSync, mkdirSync, existsSync, unlinkSync, readdirSync } from "node:fs";
5
5
  import { join, dirname } from "node:path";
6
6
  import { fileRules } from "./lib.mjs";
7
7
 
8
8
  const START = "<!-- lintsure:rules:start -->", END = "<!-- lintsure:rules:end -->";
9
9
  export const TARGETS = {
10
10
  agents: { file: "AGENTS.md", shared: true, label: "AGENTS.md (Codex, Jules, Amp, Zed and other agents)" },
11
- cursor: { file: ".cursor/rules/lintsure.mdc", shared: false, label: "Cursor (.cursor/rules/lintsure.mdc)" },
11
+ grok: { file: ".grok/rules/lintsure.md", shared: false, label: "Grok Build (.grok/rules/lintsure.md)" },
12
12
  copilot: { file: ".github/copilot-instructions.md", shared: true, label: "GitHub Copilot (.github/copilot-instructions.md)" },
13
13
  claude: { file: "CLAUDE.md", shared: true, label: "CLAUDE.md (Claude Code without the plugin)" },
14
+ gemini: { file: "GEMINI.md", shared: true, label: "Gemini CLI (GEMINI.md)" },
14
15
  };
15
16
 
16
- /** The rules as plain instructions. Says honestly where they're checked. */
17
- export function block(root) {
18
- const rules = fileRules(root);
17
+ // Which agent reads each target. AGENTS.md is read by many agents, so a rule for named agents goes there only when
18
+ // Codex is one of them, and the line says who it is for.
19
+ const READER = { agents: "codex", grok: "grok", copilot: "copilot", claude: "claude", gemini: "gemini" };
20
+ // Agents that can load a rule file only for matching paths: where those files go and how the paths are written.
21
+ const SCOPED = {
22
+ claude: { dir: ".claude/rules", ext: ".md", head: (globs) => `paths:\n${globs.map((g) => ` - ${JSON.stringify(g)}`).join("\n")}` },
23
+ copilot: { dir: ".github/instructions", ext: ".instructions.md", head: (globs) => `applyTo: ${JSON.stringify(globs.join(","))}` },
24
+ };
25
+ const forTarget = (rules, key) => rules.filter((r) => !r.agents || r.agents.includes(READER[key]));
26
+ const ours = (s) => (f) => f.startsWith("lintsure-") && f.endsWith(s.ext);
27
+
28
+ /** The rules as plain instructions, for one target or (with no target) all of them. Says honestly where they're checked. */
29
+ export function block(root, key) {
30
+ const all = fileRules(root), mine = key ? forTarget(all, key) : all;
31
+ // Where the agent can scope a file to paths, rules tied to paths go there (see scoped) and stay out of this block.
32
+ const rules = SCOPED[key] ? mine.filter((r) => !r.paths) : mine;
19
33
  if (!rules.length) return null;
20
- const line = (r) => r.kind === "protect" ? `- ${r.text} (Files: ${r.paths})` : r.kind === "avoid" && r.paths ? `- ${r.text} (In: ${r.paths})` : `- ${r.text}`;
34
+ const only = (r) => key === "agents" && r.agents ? ` (Only for: ${r.agents.join(", ")})` : "";
35
+ const line = (r) => (r.kind === "protect" ? `- ${r.text} (Files: ${r.paths})` : r.kind === "avoid" && r.paths ? `- ${r.text} (In: ${r.paths})` : `- ${r.text}`) + only(r);
21
36
  return [
22
37
  "## Project rules (from Lintsure)",
23
38
  "",
@@ -29,6 +44,25 @@ export function block(root) {
29
44
  ].join("\n");
30
45
  }
31
46
 
47
+ /** Path-scoped rule files for one target: clears Lintsure's old ones, then (unless write is false) writes one file per
48
+ * set of paths. Returns how many files it removed. */
49
+ function scoped(root, key, write = true) {
50
+ const s = SCOPED[key];
51
+ if (!s) return 0;
52
+ const dir = join(root, s.dir), old = existsSync(dir) ? readdirSync(dir).filter(ours(s)) : [];
53
+ for (const f of old) unlinkSync(join(dir, f));
54
+ if (!write) return old.length;
55
+ const groups = new Map();
56
+ for (const r of forTarget(fileRules(root), key)) if (r.paths) groups.set(r.paths, [...(groups.get(r.paths) ?? []), r]);
57
+ let n = 0;
58
+ for (const [paths, rules] of groups) {
59
+ mkdirSync(dir, { recursive: true });
60
+ const globs = String(paths).split(",").map((g) => g.trim()).filter(Boolean);
61
+ writeFileSync(join(dir, `lintsure-${++n}${s.ext}`), `---\n${s.head(globs)}\n---\n\n# Project rules (from Lintsure)\n\nThese hold for the files named above. They come from \`.lintsure/rules.yml\`; change them there, not here.\n\n${rules.map((r) => `- ${r.text}`).join("\n")}\n`);
62
+ }
63
+ return old.length;
64
+ }
65
+
32
66
  function put(path, text, shared) {
33
67
  mkdirSync(dirname(path), { recursive: true });
34
68
  if (!shared) {
@@ -42,34 +76,45 @@ function put(path, text, shared) {
42
76
  if (next !== cur) writeFileSync(path, next);
43
77
  }
44
78
 
79
+ /** Takes Lintsure's text out of one target file (the user's own text stays). True when something was removed. */
80
+ function take(path, shared) {
81
+ if (!existsSync(path)) return false;
82
+ const cur = readFileSync(path, "utf8");
83
+ if (!shared) { if (!cur.includes("Project rules from Lintsure")) return false; unlinkSync(path); return true; }
84
+ const i = cur.indexOf(START), j = cur.indexOf(END);
85
+ if (i < 0 || j <= i) return false;
86
+ writeFileSync(path, (cur.slice(0, i) + cur.slice(j + END.length)).replace(/\n{3,}/g, "\n\n"));
87
+ return true;
88
+ }
89
+
45
90
  /** Which targets already carry Lintsure's rules, so a rules change keeps exactly those in step. */
46
91
  export function synced(root) {
47
- return Object.entries(TARGETS).filter(([, t]) => {
48
- const p = join(root, t.file);
92
+ return Object.entries(TARGETS).filter(([k, t]) => {
93
+ const p = join(root, t.file), s = SCOPED[k], dir = s && join(root, s.dir);
94
+ if (dir && existsSync(dir) && readdirSync(dir).some(ours(s))) return true;
49
95
  if (!existsSync(p)) return false;
50
96
  return !t.shared || readFileSync(p, "utf8").includes(START);
51
97
  }).map(([k]) => k);
52
98
  }
53
99
 
54
- /** Writes the rules to the chosen targets. Default: AGENTS.md and Cursor, plus Copilot and CLAUDE.md when those files exist. */
100
+ /** Writes the rules to the chosen targets. Default: AGENTS.md and Grok Build, plus Copilot, CLAUDE.md and GEMINI.md when those files exist. */
55
101
  export function sync(root, want) {
56
- const text = block(root);
57
- if (!text) return { written: [], note: "No rules in .lintsure/rules.yml yet." };
58
- const keys = want?.length ? want.filter((k) => TARGETS[k]) : ["agents", "cursor", ...["copilot", "claude"].filter((k) => existsSync(join(root, TARGETS[k].file)))];
59
- for (const k of keys) put(join(root, TARGETS[k].file), text, TARGETS[k].shared);
102
+ if (!fileRules(root).length) return { written: [], note: "No rules in .lintsure/rules.yml yet." };
103
+ const keys = want?.length ? want.filter((k) => TARGETS[k]) : ["agents", "grok", ...["copilot", "claude", "gemini"].filter((k) => existsSync(join(root, TARGETS[k].file)))];
104
+ for (const k of keys) {
105
+ const text = block(root, k), p = join(root, TARGETS[k].file);
106
+ if (text) put(p, text, TARGETS[k].shared); else take(p, TARGETS[k].shared);
107
+ scoped(root, k);
108
+ }
60
109
  return { written: keys.map((k) => TARGETS[k].label) };
61
110
  }
62
111
 
63
- /** Takes Lintsure's block out again (the user's own text stays). */
112
+ /** Takes Lintsure's block and its path-scoped files out again (the user's own text stays). */
64
113
  export function unsync(root) {
65
114
  const done = [];
66
115
  for (const [k, t] of Object.entries(TARGETS)) {
67
- const p = join(root, t.file);
68
- if (!existsSync(p)) continue;
69
- const cur = readFileSync(p, "utf8");
70
- if (!t.shared) { if (cur.includes("Project rules from Lintsure")) { unlinkSync(p); done.push(t.label); } continue; }
71
- const i = cur.indexOf(START), j = cur.indexOf(END);
72
- if (i >= 0 && j > i) { writeFileSync(p, (cur.slice(0, i) + cur.slice(j + END.length)).replace(/\n{3,}/g, "\n\n")); done.push(t.label); }
116
+ const a = take(join(root, t.file), t.shared), b = scoped(root, k, false);
117
+ if (a || b) done.push(t.label);
73
118
  }
74
119
  return done;
75
120
  }
@@ -28,7 +28,8 @@ export function fileRules(root) {
28
28
  if (kind === "deps") return { id: `file:${i}`, kind, except, text: say || "Don't add new dependencies without asking." };
29
29
  // A note with "when:" (or "in:") globs applies only to those files: it's shown when the agent edits one, not in Memory.
30
30
  return { id: `file:${i}`, kind, paths: it.when || it.in || null, text: say };
31
- }).filter((r) => r && r.text);
31
+ // "agents: codex, gemini" keeps a rule to those agents. Without it the rule is for every agent.
32
+ }).map((r, i) => r && items[i].agents ? { ...r, agents: String(items[i].agents).toLowerCase().split(/[\s,]+/).filter(Boolean) } : r).filter((r) => r && r.text);
32
33
  out.mode = items.mode;
33
34
  return out;
34
35
  }