Personal_AI_Infrastructure icon indicating copy to clipboard operation
Personal_AI_Infrastructure copied to clipboard

ReferenceCheck: `--stale` is mtime-based; proposal for content-anchored `path:line` citations

Open drpaulobernardy opened this issue 2 months ago • 4 comments

Problem

ReferenceCheck.ts --stale flags a reference as stale when the referenced file's mtime is newer than the referrer's (ReferenceCheck.ts ~L649-655). That signal is both noisy and blind:

  • Noisy: any touch of the target (a version bump, a formatter, an unrelated edit, an upgrade that rewrites every file) marks every referrer stale, even when the cited code did not change.
  • Blind: a claim like "see hooks/Foo.hook.ts:128" survives an edit that moves or rewrites line 128. mtime says nothing about which line changed, and a line number alone can't tell "the code moved" from "the code is gone".

Docs, ISAs, knowledge notes and upgrade notes all make claims about code by path:line. Nothing today tells you when one of those claims stopped being true.

Proposal: content-anchored citations

Cite as `path:line` — `literal snippet from that line`. The snippet is short and unique in the file. A checker reads each citation and classifies it by content, not by date:

State Meaning Action
ok line N contains the snippet nothing
moved snippet found on another line report the new line; the claim still holds, only the number is old
changed snippet is nowhere in the file the claim is rotten; re-read the code
gone file doesn't exist rotten

Touching a file without changing the cited line reports nothing. That is the case mtime gets wrong.

Sketch:

const CITATION = /`([^`\s]+?):(\d+)`\s*[—–-]\s*`([^`]+)`/g;
// for each match: read file → lines[n-1].includes(snippet) ? ok
//   : lines.findIndex(l => l.includes(snippet)) >= 0 ? moved : changed

Evidence from running it

I've been running this on a local set of notes that describe hooks and tools (233 citations across 23 files). On the first pass it caught 3 citations whose line had moved. After an upgrade, the moved/changed list is the re-read queue; the rest doesn't need reopening the code.

One limit, stated plainly: it checks that the citation still points at the same code, not that the sentence next to it is true. A wrong claim with a correct citation passes. It narrows what needs re-reading; it doesn't replace re-reading.

Where it could live

Either as a mode of ReferenceCheck.ts (--content), or as its own small tool that ReferenceCheck calls. Snippet-less path:line references can keep today's behavior, so nothing existing breaks.

drpaulobernardy avatar Sep 22 '26 14:09 drpaulobernardy

Thanks @drpaulobernardy. Agreed that mtime is both noisy and blind for path:line citations, and the ok/moved/changed/gone states are a clean way to say it. Adopting it means a citation convention across docs and ISAs as well as a new ReferenceCheck.ts mode, so it's tracked as a design item.

danielmiessler avatar Oct 03 '26 04:10 danielmiessler

Checked v8.761.0: the proposal did not land. --stale is still mtime-only (LIFEOS/TOOLS/ReferenceCheck.ts:55 and :943-946), and the file has no parsing of path:line citations. So all of it remains open.

We have run the checker since filing. Four refinements from use, if you take it up:

  1. Split moved in two: the snippet is on exactly one other line (moved, the claim stands, only the number is old) versus on several lines (ambiguous). An ambiguous citation cannot be re-pointed automatically, so it belongs with the rotten ones, not with moved.
  2. Add a dir state for a path that resolves to a directory; a line number there is meaningless and readFileSync would throw.
  3. Accept the snippet in double backticks as well, for snippets that contain a backtick.
  4. Count path:line pointers that have no snippet and report the number separately; they cannot be checked and silently passing them hides how much of a doc is unverified.

The check itself is a pure function (path, line, snippet) -> state, so other tools (docs lint, ISA verification) can reuse it without going through the CLI. Glad to send a PR for a --content mode of ReferenceCheck.ts if the convention (snippet after the citation) is acceptable.

drpaulobernardy avatar Oct 31 '26 20:10 drpaulobernardy

[!NOTE] 🤖 Kai (AI assistant) responding on behalf of Daniel Miessler

Thanks @drpaulobernardy, and for the four refinements from running it. We would take a PR for this as an opt-in --content mode of ReferenceCheck.ts. The conditions: the check is a pure function (path, line, snippet) -> state in its own module with bun tests for ok, moved, ambiguous, changed, gone and dir; paths resolve through realpathSync and must stay inside the checked tree; path:line references without a snippet keep today's behavior and are counted separately; and the default run and --stale stay unchanged. The snippet convention would be optional, so no doc has to adopt it for the PR to land.

danielmiessler avatar Nov 06 '26 13:11 danielmiessler

[!NOTE] 🤖 Kai (AI assistant) responding on behalf of Daniel Miessler

The content-anchored check you proposed is in: ReferenceCheck.ts --content checks each path:line citation in markdown against the cited file's current content, alongside the existing mtime-based --stale. It was built from PR #2688.

This lands in the next LifeOS release, so I'm closing this now.

danielmiessler avatar Nov 20 '26 02:11 danielmiessler