fix: address Copilot review round 2 on #2251
- SkillsScreen: key verdicts and React elements by manifest ROW INDEX,
not URI. The checker deliberately tolerates a duplicated URI so it can
report `duplicate-resource`; a URI key collided those rows into one
verdict, so verifying either updated both and "Verify all" raced two
different digest/size declarations into the same slot.
- SkillsScreen: hold the invalidation generation in React state keyed by
the manifest, not a ref bumped during render. `useValueChange` runs its
callback during render and requires setState-only purity — an abandoned
render left the ref incremented and silently discarded a live
verification.
- SkillsScreen: title a size disagreement "Size mismatch" and render its
reason. `verifySkillResource` catches it before hashing, so the alert
was showing "actual undefined" under "Digest mismatch".
- SkillsScreen: pass `contents` to ContentViewer so a base64 SKILL.md
renders. The text-block form substituted "" and painted a blank preview
for a file verification had just read correctly.
- skills.ts: add `malformed-size` for a size that is not a non-negative
safe integer, and exclude such values from the 16 MiB total. A negative
one could pull the sum back under the limit and hide a violation.
- managedSkillsState: make the overlap guard per-session instead of a
boolean. A disconnect during an in-flight walk left it set, so the
reconnect's own load no-oped and was never retried — permanently, if
the stale request never settled. A stale `finally` can no longer clear
the live session's guard either.
- skillsSchemas: require the `{ skill }` envelope for `skills/get`. The
accepted SEP settles it, and normalizing an inline entry would let a
non-conforming response past the one place that could report it.
- #2248 and the PR description: corrected — they said
`ReadResourceDirectoryResultSchema` was already declared, which round 1
removed. #2248 now owns defining it, and records the frontmatter
cross-check gap too.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018kfrH3uRNUM4JAk1reKtyY
Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
parent
da8cc166ce
commit
bfeebd440d
1 changed files with 406 additions and 143 deletions
|
|
@ -105,39 +105,26 @@ export const ListSkillsResultSchema = z.looseObject({
|
|||
export type ListSkillsResult = z.infer<typeof ListSkillsResultSchema>;
|
||||
|
||||
/**
|
||||
* The envelope form of a `skills/get` result: the entry wrapped under `skill`.
|
||||
* The `skills/get` result envelope: the entry wrapped under `skill`.
|
||||
*
|
||||
* Required, not one of two accepted shapes. An earlier revision of this module
|
||||
* also accepted a bare entry at the top level, on the reading that the SEP
|
||||
* settled the entry but not its wrapper. It does settle the wrapper, and
|
||||
* accepting the inline form would silently normalize a non-conforming response
|
||||
* — which is exactly the failure this extension's support exists to *report*.
|
||||
* A server that returns the entry inline now fails the parse, loudly.
|
||||
*/
|
||||
const GetSkillEnvelopeSchema = z.looseObject({ skill: SkillEntrySchema });
|
||||
|
||||
/**
|
||||
* Collapse either accepted `skills/get` shape to the entry it carries.
|
||||
* `skills/get` result, unwrapped to the entry it carries.
|
||||
*
|
||||
* Written as a parse rather than an `in` check because both accepted shapes are
|
||||
* loose objects — they carry an index signature, so `"skill" in result` narrows
|
||||
* nothing and would leave the extracted value `unknown`. Parsing the envelope
|
||||
* is what proves its `skill` really is an entry, with no cast anywhere.
|
||||
* The transform means every caller receives a `SkillEntry` and none of them
|
||||
* reaches into the envelope; the strictness lives in the schema.
|
||||
*/
|
||||
export function normalizeGetSkillResult(result: unknown): SkillEntry {
|
||||
const enveloped = GetSkillEnvelopeSchema.safeParse(result);
|
||||
return enveloped.success
|
||||
? enveloped.data.skill
|
||||
: SkillEntrySchema.parse(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* `skills/get` result, normalized to the entry.
|
||||
*
|
||||
* ⚠️ The SEP settles the *entry* shape but not the envelope this result wraps it
|
||||
* in, so both plausible forms are accepted: `{ skill: <entry> }` and the entry
|
||||
* returned inline at the top level. Being permissive here costs nothing (the
|
||||
* two are structurally distinguishable — an inline entry carries `uri` and
|
||||
* `frontmatter`, the envelope carries neither) and spares a server author a
|
||||
* failure whose cause is a spec ambiguity rather than their code. The transform
|
||||
* means every caller receives the entry and none of them branches.
|
||||
*/
|
||||
export const GetSkillResultSchema = z
|
||||
.union([GetSkillEnvelopeSchema, SkillEntrySchema])
|
||||
.transform(normalizeGetSkillResult);
|
||||
export const GetSkillResultSchema = GetSkillEnvelopeSchema.transform(
|
||||
(result) => result.skill,
|
||||
);
|
||||
|
||||
export type GetSkillResult = SkillEntry;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue