readingroom 0.5.0 → 0.6.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/dist/index.html CHANGED
@@ -22,8 +22,8 @@
22
22
  } catch (e) {}
23
23
  })();
24
24
  </script>
25
- <script type="module" crossorigin src="/assets/index-B-vdAlId.js"></script>
26
- <link rel="stylesheet" crossorigin href="/assets/index-BAnFy1v7.css">
25
+ <script type="module" crossorigin src="/assets/index-CnOeoBor.js"></script>
26
+ <link rel="stylesheet" crossorigin href="/assets/index-BdKuMa7q.css">
27
27
  </head>
28
28
  <body>
29
29
  <div id="root"></div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "readingroom",
3
- "version": "0.5.0",
3
+ "version": "0.6.2",
4
4
  "description": "Zero-config doc browser for your codebase.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/dashboard.js CHANGED
@@ -1,8 +1,86 @@
1
- import { latestCommitDates } from './git.js';
1
+ import { readFileSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { aiCommitShare, latestCommitDates } from './git.js';
2
4
 
3
5
  const CATEGORIES = ['markdown', 'images', 'pdfs', 'text', 'json', 'code', 'other'];
4
6
  const RANK_LIMIT = 10;
5
7
 
8
+ // Instruction files AI coding agents read, matched by basename anywhere in
9
+ // the tree (AGENTS.md is often nested per-package in monorepos).
10
+ const AGENT_INSTRUCTION_NAMES = new Set([
11
+ 'CLAUDE.md',
12
+ 'AGENTS.md',
13
+ 'GEMINI.md',
14
+ 'QWEN.md',
15
+ 'copilot-instructions.md',
16
+ '.cursorrules',
17
+ '.windsurfrules',
18
+ '.clinerules',
19
+ ]);
20
+
21
+ // Instruction files identified by location rather than basename.
22
+ const AGENT_INSTRUCTION_PATH_RES = [
23
+ /^\.cursor\/rules\/[^/]+\.(md|mdc)$/,
24
+ /^\.github\/instructions\/[^/]+\.instructions\.md$/,
25
+ ];
26
+
27
+ // A skill is a folder directly under a skills directory containing SKILL.md.
28
+ const SKILL_FILE_RE = /^\.(claude|agents|cursor)\/skills\/([^/]+)\/SKILL\.md$/;
29
+
30
+ // A custom slash command is a top-level .md file in a commands directory;
31
+ // .github/prompts is GitHub Copilot's prompt location.
32
+ const COMMAND_FILE_RE = /^\.(claude|agents|cursor)\/commands\/([^/]+)\.md$/;
33
+ const PROMPT_FILE_RE = /^\.github\/prompts\/([^/]+)\.md$/;
34
+
35
+ function isAgentInstructionFile(rel) {
36
+ if (AGENT_INSTRUCTION_NAMES.has(rel.split('/').pop())) return true;
37
+ return AGENT_INSTRUCTION_PATH_RES.some((re) => re.test(rel));
38
+ }
39
+
40
+ function commandMeta(rel) {
41
+ const match = COMMAND_FILE_RE.exec(rel);
42
+ if (match) return { name: match[2], sourceDir: `.${match[1]}` };
43
+ const prompt = PROMPT_FILE_RE.exec(rel);
44
+ if (prompt) return { name: prompt[1], sourceDir: '.github' };
45
+ return null;
46
+ }
47
+
48
+ // Extract `description:` from YAML frontmatter (SKILL.md, command files).
49
+ // Single-line and block-scalar (>, |) forms are supported; anything else
50
+ // degrades to null.
51
+ function parseFrontmatterDescription(text) {
52
+ const lines = text.split(/\r?\n/);
53
+ let inFrontmatter = false;
54
+ for (let i = 0; i < lines.length; i++) {
55
+ const line = lines[i];
56
+ if (!inFrontmatter) {
57
+ if (line.trim() === '---') inFrontmatter = true;
58
+ continue;
59
+ }
60
+ if (line === '---' || line === '...') return null;
61
+ const match = line.match(/^description:[ \t]*(.*)$/);
62
+ if (!match) continue;
63
+ const value = match[1].trim();
64
+ if (value && !/^[|>][+-]?$/.test(value)) {
65
+ return value.replace(/^["']|["']$/g, '').slice(0, 300);
66
+ }
67
+ const parts = [];
68
+ for (let j = i + 1; j < lines.length && /^\s+\S/.test(lines[j]); j++) {
69
+ parts.push(lines[j].trim());
70
+ }
71
+ return parts.join(' ').slice(0, 300) || null;
72
+ }
73
+ return null;
74
+ }
75
+
76
+ function frontmatterDescription(rootAbs, rel) {
77
+ try {
78
+ return parseFrontmatterDescription(readFileSync(path.join(rootAbs, rel), 'utf8').slice(0, 4096));
79
+ } catch {
80
+ return null;
81
+ }
82
+ }
83
+
6
84
  function collectFiles(node, files = [], directories = []) {
7
85
  for (const child of node.children || []) {
8
86
  if (child.type === 'file') files.push(child);
@@ -57,6 +135,13 @@ export async function buildDashboard(tree, rootAbs) {
57
135
  /* Dashboard ranking always has a filesystem fallback. */
58
136
  }
59
137
 
138
+ let aiCommits = null;
139
+ try {
140
+ aiCommits = await aiCommitShare(rootAbs);
141
+ } catch {
142
+ /* The AI share widget needs Git; it hides quietly without it. */
143
+ }
144
+
60
145
  const filesystemRows = files
61
146
  .map((file) => dashboardFile(file, isoFromMtime(file.mtime), 'filesystem'))
62
147
  .filter((file) => file.updatedAt);
@@ -76,6 +161,42 @@ export async function buildDashboard(tree, rootAbs) {
76
161
  .sort(byDate(1))
77
162
  .slice(0, RANK_LIMIT);
78
163
 
164
+ const depth = (file) => (file.path.match(/\//g) || []).length;
165
+ const agentInstructions = files
166
+ .filter((file) => isAgentInstructionFile(file.path))
167
+ .map((file) => dashboardFile(file, isoFromMtime(file.mtime), 'filesystem'))
168
+ .filter((file) => file.updatedAt)
169
+ .sort((a, b) => depth(a) - depth(b) || a.path.localeCompare(b.path));
170
+
171
+ const skills = files
172
+ .flatMap((file) => {
173
+ const match = SKILL_FILE_RE.exec(file.path);
174
+ if (!match) return [];
175
+ return [{
176
+ name: match[2],
177
+ sourceDir: `.${match[1]}`,
178
+ description: frontmatterDescription(rootAbs, file.path),
179
+ path: file.path,
180
+ size: file.size,
181
+ updatedAt: isoFromMtime(file.mtime),
182
+ }];
183
+ })
184
+ .sort((a, b) => a.name.localeCompare(b.name) || a.path.localeCompare(b.path));
185
+
186
+ const commands = files
187
+ .flatMap((file) => {
188
+ const meta = commandMeta(file.path);
189
+ if (!meta) return [];
190
+ return [{
191
+ ...meta,
192
+ description: frontmatterDescription(rootAbs, file.path),
193
+ path: file.path,
194
+ size: file.size,
195
+ updatedAt: isoFromMtime(file.mtime),
196
+ }];
197
+ })
198
+ .sort((a, b) => a.name.localeCompare(b.name) || a.path.localeCompare(b.path));
199
+
79
200
  return {
80
201
  fileCount: files.length,
81
202
  directoryCount: directories.length,
@@ -84,5 +205,9 @@ export async function buildDashboard(tree, rootAbs) {
84
205
  gitAvailable: gitDates !== null,
85
206
  recent,
86
207
  oldest,
208
+ agentInstructions,
209
+ skills,
210
+ commands,
211
+ aiCommits,
87
212
  };
88
213
  }
package/src/git.js CHANGED
@@ -19,6 +19,21 @@ const RECORD = '\x1e';
19
19
  const PRETTY = `%H${FIELD}%h${FIELD}%an${FIELD}%ae${FIELD}%aI${FIELD}%s${RECORD}`;
20
20
  const DASHBOARD_PRETTY = `%aI${RECORD}`;
21
21
  const DASHBOARD_PATH_BATCH = 250;
22
+ const AI_COMMIT_LIMIT = 500;
23
+ const AI_TOP_FILES = 6;
24
+ const AI_BODY_PRETTY = `%H${FIELD}%aI${FIELD}%b${RECORD}`;
25
+
26
+ // AI assistants leave machine-readable traces in commit messages: co-author
27
+ // trailers ("Co-Authored-By: Claude <noreply@anthropic.com>") and footer lines
28
+ // ("🤖 Generated with [Claude Code](https://claude.com/claude-code)"). Bodies
29
+ // are matched, not subjects, so a commit merely *about* Claude doesn't count.
30
+ const AI_TOOLS = [
31
+ { id: 'claude', label: 'Claude', match: [/co-authored-by:[^\n<]*claude/i, /generated with \[?claude code\]?/i] },
32
+ { id: 'copilot', label: 'Copilot', match: [/co-authored-by:[^\n<]*copilot/i, /generated with \[?(github )?copilot\]?/i] },
33
+ { id: 'cursor', label: 'Cursor', match: [/co-authored-by:[^\n<]*cursor/i, /generated with \[?cursor( agent)?\]?/i] },
34
+ { id: 'gemini', label: 'Gemini', match: [/co-authored-by:[^\n<]*gemini/i, /generated with \[?gemini( cli)?\]?/i] },
35
+ { id: 'codex', label: 'Codex', match: [/co-authored-by:[^\n<]*codex/i, /generated with \[?codex\]?/i] },
36
+ ];
22
37
 
23
38
  export class VersionNotFound extends Error {
24
39
  constructor() {
@@ -212,6 +227,102 @@ export async function latestCommitDates(rootAbs, rels) {
212
227
  return dates;
213
228
  }
214
229
 
230
+ /** Parse `AI_BODY_PRETTY` output into { sha, date, body } records. */
231
+ function parseAiBodies(out) {
232
+ const commits = [];
233
+ for (const chunk of String(out).split(RECORD)) {
234
+ // Records after the first start with the newline git appends to each entry.
235
+ const fields = chunk.trim().split(FIELD);
236
+ if (!/^[0-9a-f]{40}$/i.test(fields[0])) continue;
237
+ commits.push({ sha: fields[0], date: fields[1] || '', body: fields.slice(2).join(FIELD) });
238
+ }
239
+ return commits;
240
+ }
241
+
242
+ /** Group `git show --name-only` output by commit sha. */
243
+ function parseAiCommitFiles(out) {
244
+ const filesBySha = new Map();
245
+ let sha = null;
246
+ for (const line of String(out).split(/\r?\n/)) {
247
+ if (line.includes(RECORD)) {
248
+ sha = line.slice(0, line.indexOf(RECORD)).trim() || null;
249
+ if (sha) filesBySha.set(sha, []);
250
+ continue;
251
+ }
252
+ if (!sha || !line.trim()) continue;
253
+ filesBySha.get(sha).push(unquotePath(line.trim()).replace(/\\/g, '/'));
254
+ }
255
+ return filesBySha;
256
+ }
257
+
258
+ /**
259
+ * Share of recent commits authored with an AI assistant, judged by co-author
260
+ * and "generated with" trailers in the message body. Scoped to the served
261
+ * root (repo-wide when the root is the repository itself). Returns
262
+ * { scanned, aiCount, share, byTool, topFiles, latestAiAt }, zeroed stats for
263
+ * a repository with no commits, or null outside Git / when Git fails.
264
+ */
265
+ export async function aiCommitShare(rootAbs) {
266
+ const repo = await findRepo(rootAbs);
267
+ if (!repo) return null;
268
+ let out;
269
+ try {
270
+ const scope = repo.subDir ? ['--', repo.subDir] : [];
271
+ out = await runGit(repo.repoRoot, ['log', '-n', String(AI_COMMIT_LIMIT), `--format=${AI_BODY_PRETTY}`, ...scope]);
272
+ } catch (err) {
273
+ if (isUnborn(err)) return { scanned: 0, aiCount: 0, share: 0, byTool: [], topFiles: [], latestAiAt: null };
274
+ return null;
275
+ }
276
+
277
+ const commits = parseAiBodies(out);
278
+ const toolCounts = new Map();
279
+ const aiShas = [];
280
+ let latestAiAt = null;
281
+ for (const commit of commits) {
282
+ const hits = AI_TOOLS.filter((tool) => tool.match.some((re) => re.test(commit.body)));
283
+ if (hits.length === 0) continue;
284
+ aiShas.push(commit.sha);
285
+ if (!latestAiAt) latestAiAt = commit.date || null; // log walks newest-first
286
+ for (const tool of hits) toolCounts.set(tool.id, (toolCounts.get(tool.id) || 0) + 1);
287
+ }
288
+ const byTool = AI_TOOLS
289
+ .filter((tool) => toolCounts.has(tool.id))
290
+ .map((tool) => ({ id: tool.id, label: tool.label, count: toolCounts.get(tool.id) }))
291
+ .sort((a, b) => b.count - a.count || a.label.localeCompare(b.label));
292
+
293
+ let topFiles = [];
294
+ if (aiShas.length > 0) {
295
+ try {
296
+ const filesBySha = parseAiCommitFiles(
297
+ await runGit(repo.repoRoot, ['show', '--name-only', `--format=%H${RECORD}`, ...aiShas]),
298
+ );
299
+ const counts = new Map();
300
+ for (const files of filesBySha.values()) {
301
+ for (const repoRel of files) {
302
+ let servedRel = repoRel;
303
+ if (repo.subDir) servedRel = repoRel.startsWith(`${repo.subDir}/`) ? repoRel.slice(repo.subDir.length + 1) : null;
304
+ if (servedRel) counts.set(servedRel, (counts.get(servedRel) || 0) + 1);
305
+ }
306
+ }
307
+ topFiles = [...counts]
308
+ .map(([p, count]) => ({ path: p, count }))
309
+ .sort((a, b) => b.count - a.count || a.path.localeCompare(b.path))
310
+ .slice(0, AI_TOP_FILES);
311
+ } catch {
312
+ /* the file ranking is best-effort; the headline share still stands */
313
+ }
314
+ }
315
+
316
+ return {
317
+ scanned: commits.length,
318
+ aiCount: aiShas.length,
319
+ share: commits.length > 0 ? aiShas.length / commits.length : 0,
320
+ byTool,
321
+ topFiles,
322
+ latestAiAt,
323
+ };
324
+ }
325
+
215
326
  /** Commit timeline for rel: { repo, commits, truncated } | null when not a repo. */
216
327
  export async function fileHistory(rootAbs, rel) {
217
328
  const repo = await findRepo(rootAbs);