fix: address Copilot review round 1 on #2248

Five findings, all real.

**Critical — `verifySkills` selected `contents[0]`.** These bytes are hashed
against the file's advertised digest, so accepting a block the server
labelled something else verifies one file's content against another file's
digest, and can report that as `verified`. A false pass is worse than a
missing check. `contentsFor(result, uri)` now selects by NORMALIZED identity,
which keeps the canonicalized-echo case that motivated the original code
while rejecting an unrelated block, and reports a read error when nothing
answers for the URI. This is what `onReadSkillFile` already did; the two
paths hash bytes against digests and must not disagree about which bytes.

**`skills/get` was dispatched without the extension gate** that `skills/list`
had. Hoisted into `assertSkillsSupported` so the two cannot drift — declaring
the extension commits a server to both. Without it, an undeclared server's
-32601 is indistinguishable to a script from the -32602 a declared server
returns for a URI it does not serve.

**The TUI could strand a user on a hidden Skills tab.** The tab left the bar
when the gate went false but `activeTab` did not, so the pane kept rendering
for a server that never declared the extension. Reset to `info`, following
the Auth precedent — additionally gated on `connected`, because this gate
reads a server declaration and would otherwise fire during a reconnect.

**The TUI keyed a verdict by URI**, so a refresh replacing the manifest under
the same URI left hashes computed for the previous snapshot describing the
new one. Keyed on the entry now, as the web screen already was.

**A failed "Load more" discarded the pages on screen and the retry cursor.**
Both are preserved now, and the success and failure paths share one
staleness-guarded `commit` helper so they cannot drift on which results they
may write — which is how they came to disagree.

Two nits: the six-skill counts. The docs sentence was more wrong than
reported (five awkward skills of six, three outright violations) and is
rewritten rather than renumbered.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ND46Ci64DC3tzBy9aG81Nc
Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
cliffhall 2026-09-07 18:43:58 -04:00
commit 775107776d

View file

@ -495,6 +495,27 @@ const ALL_SECTIONS = [
"resource",
];
/**
* The sections that open by default — everything except Directory.
*
* Directory is the one section whose content requires a round trip the user has
* not made yet, so open it holds a button and an empty frame: it advertises
* content that is not there, while taking height from the sections that do have
* some. With five open sections in a short pane each is squeezed to its floor
* and scrolls internally, which is the documented fallback but a poor first
* impression — and the one it costs most is the file viewer, the section
* `viewerFlex` exists to give the remainder to.
*
* The same argument as Conformance's auto-collapse, one step earlier: that one
* closes a section whose header already carries the whole answer, this one
* closes a section that has no answer yet. Both are defaults; neither prevents
* opening it, and `openSections` outlives a selection, so a user who opens
* Directory keeps it open across skills.
*/
const DEFAULT_OPEN_SECTIONS = ALL_SECTIONS.filter(
(section) => section !== "directory",
);
/**
* The open set for the FIRST render.
*
@ -508,13 +529,13 @@ function initialOpenSections(
skills: SkillEntry[],
selectedSkillUri: string | undefined,
): string[] {
if (selectedSkillUri === undefined) return ALL_SECTIONS;
if (selectedSkillUri === undefined) return DEFAULT_OPEN_SECTIONS;
const wanted = skillUriIdentity(selectedSkillUri);
const entry = skills.find((skill) => skillUriIdentity(skill.uri) === wanted);
if (entry === undefined) return ALL_SECTIONS;
if (entry === undefined) return DEFAULT_OPEN_SECTIONS;
return checkSkillConformance(entry).length > 0
? ALL_SECTIONS
: ALL_SECTIONS.filter((section) => section !== "conformance");
? DEFAULT_OPEN_SECTIONS
: DEFAULT_OPEN_SECTIONS.filter((section) => section !== "conformance");
}
/**
@ -1032,11 +1053,17 @@ export function SkillsScreen({
(uri: string, key: string, cursor?: string) => {
if (!onReadResourceDirectory) return;
const attempt = (nextAttempt.current += 1);
const write = (next: Omit<DirectoryState, "key" | "attempt">) =>
/**
* Commit a settled result, dropping it when it no longer belongs to the
* pane on screen — a different skill, or a newer read of this one.
*/
const commit = (
next: (prev: DirectoryState) => Omit<DirectoryState, "key" | "attempt">,
) =>
setDirectory((prev) => {
if (prev.key !== null && prev.key !== key) return prev;
if (prev.attempt !== undefined && prev.attempt > attempt) return prev;
return { key, attempt, ...next };
return { key, attempt, ...next(prev) };
});
// The path is claimed before the request goes out, so the header names
// the directory being read rather than continuing to announce the
@ -1058,26 +1085,28 @@ export function SkillsScreen({
// `catch`, which surfaces the message in the section.
void onReadResourceDirectory(uri, cursor)
.then((page) => {
setDirectory((prev) => {
if (prev.key !== null && prev.key !== key) return prev;
if (prev.attempt !== undefined && prev.attempt > attempt) {
return prev;
}
const held = cursor === undefined ? [] : (prev.children ?? []);
return {
key,
attempt,
uri,
children: [...held, ...page.resources],
nextCursor: page.nextCursor,
};
});
commit((prev) => ({
uri,
children: [
...(cursor === undefined ? [] : (prev.children ?? [])),
...page.resources,
],
nextCursor: page.nextCursor,
}));
})
.catch((err: unknown) => {
write({
// A FAILED page leaves what is already on screen where it is, and
// keeps the cursor that would retry it. Replacing the state outright
// made the table vanish and stranded the reader with no way back to
// that page short of restarting at the root (Copilot). Only a first
// read of a directory has nothing to preserve.
commit((prev) => ({
uri,
...(cursor === undefined
? {}
: { children: prev.children, nextCursor: cursor }),
message: err instanceof Error ? err.message : String(err),
});
}));
});
},
[onReadResourceDirectory],