Skip to content

fix(qstack-mode): drop links to a principle qstack does not ship - #2

Merged
dotts-h merged 1 commit into
mainfrom
fix/qstack-dangling-principle-links
Oct 19, 2026
Merged

dotts-h merged 1 commit into
mainfrom
fix/qstack-dangling-principle-links

Conversation

@dotts-h

@dotts-h dotts-h commented Oct 18, 2026

Copy link
Copy Markdown
Owner

Why

diagnose-live.md and diagnose-trace.md tell the agent to read ../principle-guard-the-context-window/SKILL.md. qstack does not ship that principle, so an agent that follows either step opens a file that does not exist.

What changed

  • skills/qstack-mode/playbooks/diagnose-live.md step 4 keeps its rule and drops the pointer. It now says not to paste a raw profile into the main thread.
  • skills/qstack-mode/playbooks/diagnose-trace.md step 5 drops the pointer. The step already says to reduce a large dump in a fresh qstack-agent.

Scope

Two lines in two playbooks. A link check found them while the research corrections were being built in a separate PR.

Blast Radius

Only the two diagnose playbooks change. No script reads them.

Verification

  • A markdown check over all 58 files on this branch reports 0 problems. It checks frontmatter, relative links, anchors, backticked skill paths, long dashes, and curly quotes.
  • git grep guard-the-context-window on this branch returns nothing.

@dotts-h

dotts-h commented Oct 19, 2026

Copy link
Copy Markdown
Owner Author

PASS+NOTES

I verified base 36540f5ac010b847cd864d817e9169389b67ae38 against head 93c006980bee157064289ac15ac711e7c557f2a4. The base is feat/qstack-p1-core, the branch of #1, and the head is one commit on top of it. The stable patch-id of the base-to-head diff is e9a64d0741480b041da2ce221b0a1d4c06c04b5c, so a later rebase can be compared against this verdict. I did not write this PR. I ran every command below in fresh detached worktrees on Windows with Node v22.11.0.

What changes for a user

Both diagnose playbooks say "Bundled skill paths are relative to skills/qstack-mode/SKILL.md." At base, diagnose-live step 4 and diagnose-trace step 5 tell the agent to read ../principle-guard-the-context-window/SKILL.md. From that base, the path is skills/principle-guard-the-context-window/SKILL.md. qstack does not ship that file, so an agent that follows either step gets ENOENT. At head, neither step names a path, and no file in the plugin mentions the principle. pstack ships a principle at that path, so the pointer was most likely copied from pstack along with the playbook text. That last point is an inference.

Commands and results

  1. gh pr view 2 -R dotts-h/qstack and gh pr diff 2 -R dotts-h/qstack. The diff changes one line in skills/qstack-mode/playbooks/diagnose-live.md and one line in skills/qstack-mode/playbooks/diagnose-trace.md. git log --oneline base..head lists one commit, and git merge-base --is-ancestor base head exits 0.
  2. node --test from the plugin root. Base and head both print tests 0, pass 0, and fail 0, and exit 0. The tree has no test files. scripts/ holds only check-verdict.mjs and log.mjs.
  3. node qstack-validate-md.mjs from the plugin root. This markdown check came from the local temp folder, and its coverage matches the check the PR body describes. Base prints checked 58 markdown files, 2 problems and exits 1. Both problems are path not found ../principle-guard-the-context-window/SKILL.md, at diagnose-live.md:10 and diagnose-trace.md:11. Head prints checked 58 markdown files, 0 problems and exits 0.
  4. node check-refs.mjs <base> <head>. I wrote this stricter checker for this review, and its source is at the end of this comment. It checks existence against git-tracked files with exact case. It resolves a playbook's backticked paths from the playbook's declared base. It checks every inline and reference-style markdown link, with GitHub heading slugs for anchors. It also flags every principle-* name that has no skills/<name>/SKILL.md. By contrast, qstack-validate-md.mjs accepts a backticked path that exists under any of four folders and looks only at .md and .mjs tokens. On Windows it also matches untracked files and paths with the wrong case. Results:
    • Base has 58 tracked markdown files, 70 relative links, 135 backticked paths, and 46 principle-name mentions. Head has 58, 70, 133, and 44.
    • Head removes 4 flags. They are the two lines from command 3, each flagged once as a dangling path and once as an unshipped principle name.
    • Head introduces 0 flags, and the command exits 0.
    • Both SHAs share 9 other flags, and none of them points at a plugin file. One is the [PR #123](url) placeholder in a prompt template at skills/why/references/synthesizer-prompt.md:65. The rest are a README table row that names Cursor's default hooks/hooks.json, generic mentions of SKILL.md, features/, and mcps/, and output paths of example commands in the sample feature map. So 69 of the 70 relative links resolve at both SHAs, and the 70th is the placeholder.
  5. node probe-steps.mjs <root>. It reads diagnose-live step 4 and diagnose-trace step 5, resolves each backticked path from skills/qstack-mode/, and opens the file the way an agent would. Base prints ../principle-guard-the-context-window/SKILL.md ENOENT for both steps. Head prints none for both steps.
  6. git grep -n guard-the-context-window. Base prints the two lines. Head prints nothing and exits 1. At head, git grep -n -i -E "guard.the.context|context.window" also prints nothing.
  7. git diff --numstat base head prints 1 1 for each playbook and nothing else. git ls-files --eol shows i/lf for both files at both SHAs. Neither file has a byte-order mark.
  8. git grep -n -i -E "playbook|diagnose|skills/|readFile|readdir" -- scripts at head. The only match is check-verdict.mjs reading the verdict file named on its command line. log.mjs only appends to the log file named on its command line.

PR body claims

  • "an agent that follows either step opens a file that does not exist." Commands 3 to 6 confirm this.
  • "step 4 keeps its rule and drops the pointer. It now says not to paste a raw profile into the main thread." This is accurate. Step 4 now reads "Reduce a large artifact in a fresh qstack-agent. Keep the reduced finding in the main thread. Do not paste a raw profile into the main thread."
  • "step 5 drops the pointer. The step already says to reduce a large dump in a fresh qstack-agent." This is accurate. Step 5 now reads "When the dump is large, reduce it in a fresh qstack-agent and keep the reduced finding in the main thread." The sentence is complete without the pointer.
  • "Two lines in two playbooks" and "Only the two diagnose playbooks change." Commands 1 and 7 confirm this.
  • "No script reads them." Command 8 confirms this.
  • "A markdown check over all 58 files on this branch reports 0 problems." Command 3 reproduces this. I read that checker, and it checks frontmatter, relative links, anchors, backticked skill paths, long dashes, and curly quotes, as the body says.
  • "git grep guard-the-context-window on this branch returns nothing." Command 6 confirms this.
  • "A link check found them while the research corrections were being built in a separate PR." The head cannot show this history. It is consistent with fix(qstack): record verdict runs as K of N and apply four research corrections #3.

Notes

  • node --test runs 0 tests at this base. A green test run says nothing about this PR, or about any PR stacked on feat(qstack): build v1 QA playbooks, skills, principles, and host tools #1, until test files land. No test could cover this change anyway, because it touches only markdown that no script reads.
  • The markdown check the PR body describes is not in the repo, so a reviewer cannot rerun the PR's own verification from the branch. A follow-up PR could commit it under scripts/ with a node --test case.
  • At base, diagnose-live step 4 said "Read ../principle-guard-the-context-window/SKILL.md before you paste a raw profile into the main thread." At head it says "Do not paste a raw profile into the main thread." The new sentence forbids what the old sentence allowed after a read. pstack describes that principle as "Route bulk to subagents; keep summaries in the main thread, not raw payloads." So an agent that had read it would have acted the same way. That is an inference from the principle text, not a run.
check-refs.mjs, run as node check-refs.mjs <base-root> <head-root>
import fs from "node:fs";
import path from "node:path";
import { execFileSync } from "node:child_process";

const roots = process.argv.slice(2);
if (roots.length < 1 || roots.length > 2) {
	console.error("usage: node check-refs.mjs <plugin-root> [<head-plugin-root>]");
	process.exit(2);
}

const posix = path.posix;
const schemeRe = /^[a-z][a-z0-9+.-]*:|^\/\//i;
const codeSpanRe = /(?<!`)(`+)(?!`)(.+?)(?<!`)\1(?!`)/g;
const linkRe = /\[(?:[^[\]]|\[[^\]]*\])*\]\(\s*(?:<([^>\n]*)>|((?:[^\s()]|\([^\s()]*\))*))(?:\s+(?:"[^"]*"|'[^']*'|\([^)]*\)))?\s*\)/g;
const refDefRe = /^ {0,3}\[([^\]]+)\]:\s*(?:<([^>]*)>|(\S+))/;

const git = (root, ...args) => execFileSync("git", ["-C", root, ...args], { encoding: "utf8", maxBuffer: 1 << 26 });

const walkMarkdown = (dir) => fs.readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
	if (entry.name === ".git") return [];
	const full = path.join(dir, entry.name);
	return entry.isDirectory() ? walkMarkdown(full) : entry.name.endsWith(".md") ? [full] : [];
});

const unfencedLines = (text) => {
	const lines = [];
	let fence = null;
	text.split(/\r?\n/).forEach((line, i) => {
		const marker = line.match(/^ {0,3}(`{3,}|~{3,})(.*)$/);
		if (fence) {
			if (marker && marker[1][0] === fence[0] && marker[1].length >= fence.length && !marker[2].trim()) fence = null;
			return;
		}
		if (marker && !(marker[1][0] === "`" && marker[2].includes("`"))) {
			fence = marker[1];
			return;
		}
		lines.push({ n: i + 1, line });
	});
	return lines;
};

const slugger = () => {
	const occurrences = new Map();
	return (heading) => {
		const original = heading.replace(/\[([^\]]*)\]\([^)]*\)/g, "$1").toLowerCase().replace(/[^\p{L}\p{M}\p{N}\p{Pc} -]/gu, "").replace(/ /g, "-");
		let slug = original;
		while (occurrences.has(slug)) {
			occurrences.set(original, occurrences.get(original) + 1);
			slug = `${original}-${occurrences.get(original)}`;
		}
		occurrences.set(slug, 0);
		return slug;
	};
};

const isPathToken = (token) => {
	if (!token || /[<>*{}$|\\]/.test(token) || /^[~/]/.test(token) || schemeRe.test(token) || token.startsWith(".cursor/")) return false;
	if (/^\.{1,2}\//.test(token)) return true;
	if (token.includes("/")) return /\.[A-Za-z0-9]+$/.test(token) || token.endsWith("/");
	return /\.(md|mjs)$/.test(token);
};

const scan = (root) => {
	const sha = git(root, "rev-parse", "HEAD").trim();
	const tracked = new Set(git(root, "ls-files", "-z").split("\0").filter(Boolean));
	const dirs = new Set();
	for (const file of tracked) for (let dir = posix.dirname(file); dir !== "."; dir = posix.dirname(dir)) dirs.add(dir);
	const exists = (rel) => tracked.has(rel) || dirs.has(rel.replace(/\/+$/, ""));
	const inside = (rel) => rel !== ".." && !rel.startsWith("../");
	const topLevel = new Set([...tracked].map((file) => file.split("/")[0]));
	const read = (rel) => fs.readFileSync(path.join(root, rel), "utf8");
	const anchorCache = new Map();
	const anchorsOf = (rel) => {
		if (!anchorCache.has(rel)) {
			const slug = slugger();
			const anchors = new Set();
			for (const { line } of unfencedLines(read(rel))) {
				const heading = line.match(/^ {0,3}#{1,6}(?:\s+(.*?))?(?:\s+#+)?\s*$/);
				if (heading) anchors.add(slug(heading[1] ?? ""));
			}
			anchorCache.set(rel, anchors);
		}
		return anchorCache.get(rel);
	};
	const markdown = [...tracked].filter((file) => file.endsWith(".md")).sort();
	const stats = { markdown: markdown.length, onDisk: walkMarkdown(root).length, links: 0, external: 0, paths: 0, principles: 0 };
	const dangling = [];
	const skillRootOnly = [];

	const checkLink = (file, n, raw) => {
		if (schemeRe.test(raw)) {
			stats.external++;
			return;
		}
		stats.links++;
		const hash = raw.indexOf("#");
		let target = hash < 0 ? raw : raw.slice(0, hash);
		try {
			target = decodeURI(target);
		} catch {}
		const anchor = hash < 0 ? "" : raw.slice(hash + 1);
		const rel = !target ? file : posix.normalize(target.startsWith("/") ? target.slice(1) : posix.join(posix.dirname(file), target));
		const why = !inside(rel) ? `escapes the plugin root as ${rel}`
			: !exists(rel) ? `no tracked file ${rel}`
			: anchor && rel.endsWith(".md") && !anchorsOf(rel).has(anchor) ? `no heading #${anchor} in ${rel}`
			: "";
		if (why) dangling.push({ kind: "link", file, n, token: raw, why });
	};

	const checkPath = (file, n, token, declared) => {
		stats.paths++;
		const bases = [];
		if (declared) bases.push(["declared", posix.dirname(declared)]);
		bases.push(["file", posix.dirname(file)]);
		if (topLevel.has(token.split("/")[0])) bases.push(["root", "."]);
		if (file.startsWith("skills/")) bases.push(["skill", file.split("/").slice(0, 2).join("/")]);
		const tried = bases.map(([name, dir]) => ({ name, rel: posix.normalize(posix.join(dir, token)) }));
		const hits = tried.filter(({ rel }) => inside(rel) && exists(rel)).map(({ name }) => name);
		if (!hits.length) dangling.push({ kind: "path", file, n, token, why: `tried ${tried.map(({ name, rel }) => `${name}:${rel}`).join(", ")}` });
		else if (hits.every((name) => name === "skill")) skillRootOnly.push({ file, n, token });
	};

	for (const file of markdown) {
		const text = read(file);
		const declared = text.match(/paths are relative to `([^`]+)`/)?.[1];
		for (const { n, line } of unfencedLines(text)) {
			const ref = line.match(refDefRe);
			if (ref) checkLink(file, n, ref[2] ?? ref[3]);
			const prose = line.replace(codeSpanRe, (span) => " ".repeat(span.length));
			for (const link of prose.matchAll(linkRe)) checkLink(file, n, link[1] ?? link[2]);
			for (const [, , span] of line.replace(/\[(`+)[^`]+\1\]\(/g, "(").matchAll(codeSpanRe)) {
				for (const word of span.trim().split(/\s+/)) {
					const token = word.replace(/^[("'[]+/, "").replace(/[)"'\],.;:]+$/, "");
					if (isPathToken(token)) checkPath(file, n, token, declared);
				}
			}
		}
		text.split(/\r?\n/).forEach((line, i) => {
			for (const [name] of line.matchAll(/principle-[a-z0-9]+(?:-[a-z0-9]+)*/g)) {
				stats.principles++;
				if (!exists(`skills/${name}/SKILL.md`)) dangling.push({ kind: "principle", file, n: i + 1, token: name, why: `no skills/${name}/SKILL.md` });
			}
		});
	}
	return { root, sha, stats, dangling, skillRootOnly };
};

const show = (d) => `${d.kind} ${d.file}:${d.n} ${d.token} (${d.why})`;
const results = roots.map(scan);
for (const { root, sha, stats, dangling, skillRootOnly } of results) {
	console.log(`== ${root}`);
	console.log(`sha ${sha}`);
	console.log(`${stats.markdown} tracked markdown files (${stats.onDisk} on disk), ${stats.links} relative links, ${stats.external} external links, ${stats.paths} backticked paths, ${stats.principles} principle-name mentions`);
	console.log(`${dangling.length} dangling`);
	for (const d of dangling) console.log(`  ${show(d)}`);
	console.log(`${skillRootOnly.length} backticked paths resolve only from the skill root`);
	for (const s of skillRootOnly) console.log(`  ${s.file}:${s.n} ${s.token}`);
}
if (results.length === 1) process.exit(results[0].dangling.length ? 1 : 0);

const tally = ({ dangling }) => dangling.reduce((map, d) => {
	const key = `${d.kind} ${d.file} ${d.token}`;
	return map.set(key, [...(map.get(key) ?? []), d]);
}, new Map());
const surplus = (a, b) => [...a].flatMap(([key, list]) => list.slice((b.get(key) ?? []).length));
const [baseTally, headTally] = results.map(tally);
const removed = surplus(baseTally, headTally);
const introduced = surplus(headTally, baseTally);
console.log(`== removed by head: ${removed.length}`);
for (const d of removed) console.log(`  ${show(d)}`);
console.log(`== introduced by head: ${introduced.length}`);
for (const d of introduced) console.log(`  ${show(d)}`);
process.exit(introduced.length ? 1 : 0);
probe-steps.mjs, run as node probe-steps.mjs <plugin-root>
import fs from "node:fs";
import path from "node:path";

const root = process.argv[2];
const steps = [
	["skills/qstack-mode/playbooks/diagnose-live.md", "4. "],
	["skills/qstack-mode/playbooks/diagnose-trace.md", "5. "],
];
const declaredBase = path.join(root, "skills", "qstack-mode");

for (const [file, prefix] of steps) {
	const text = fs.readFileSync(path.join(root, file), "utf8");
	if (!text.includes("Bundled skill paths are relative to `skills/qstack-mode/SKILL.md`.")) throw new Error(`${file} lost its declared base`);
	const step = text.split(/\r?\n/).find((line) => line.startsWith(prefix));
	const paths = [...step.matchAll(/`([^`]+)`/g)].map((match) => match[1]).filter((token) => token.includes("/"));
	const opened = paths.map((token) => {
		try {
			fs.readFileSync(path.resolve(declaredBase, token));
			return `${token} opens`;
		} catch (error) {
			return `${token} ${error.code}`;
		}
	});
	console.log(`${file} step ${prefix.trim()} paths an agent would open: ${opened.length ? opened.join(", ") : "none"}`);
}

@dotts-h
dotts-h changed the base branch from feat/qstack-p1-core to main October 19, 2026 09:32
diagnose-live and diagnose-trace pointed at principle-guard-the-context-window, which is not in the plugin. Each step already states the rule, so the pointer goes.

Co-authored-by: Cursor <[email protected]>
@dotts-h
dotts-h force-pushed the fix/qstack-dangling-principle-links branch from 93c0069 to efc1c19 Compare October 19, 2026 09:37
@dotts-h
dotts-h merged commit d74f4a0 into main Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant