* enhance(#2483): env-guard the claude reviewer leg against CLAUDE.md injection
The claude reviewer in workflows/review.md was a bare headless `claude -p`
spawn run from the project cwd, so it inherited the invoking user's global
CLAUDE.md, the project CLAUDE.md, and Claude Code auto-memory.
That made it the only reviewer leg seeing anything beyond the prompt file.
gather_context assembles PROJECT.md, the roadmap section, every PLAN file,
CONTEXT.md, RESEARCH.md and REQUIREMENTS.md into the prompt before any
reviewer runs; the gemini leg receives only that prompt and the codex leg
runs --ephemeral. Beyond the measured ~4k tokens/spawn, the asymmetry cuts
at the workflow's own premise: "independent review" meant something
different for the claude leg than for the other two.
Guard both dispatch lines with a per-invocation
`env CLAUDE_CODE_DISABLE_CLAUDE_MDS=1`. `env`, never `export` — the flag
must not leak into the orchestrating session (which may itself be Claude
Code on the SELF_CLI="auto" path) or into any later spawn.
review.md is the only claude -p call site in the installed tree, so this is
two lines on one surface. The self-skip logic is untouched.
* enhance(#2483): fix CRLF-fragile split and regenerate workflow baselines
Two CI failures from the first push, both mine:
1. lint-tests: the new regression test split readFileSync content on a
literal "\n". On a Windows git-autocrlf checkout that leaves a trailing
"\r" on every line (local/no-crlf-fragile-split). Use .split(/\r?\n/).
2. golden-install-parity / workflow-size-budget / workflow-compat: editing
gsd-core/workflows/review.md changes its content hash and byte size, and
both are pinned in committed baselines. Regenerated via the repo's own
generators (npm run size:baseline, npm run gen:golden).
The regenerated diffs are review.md-only: exactly one hash line per
golden-install-parity fixture and one size entry in workflow-size-baseline
— no unrelated drift swept in.
Full suite now green locally: 2113 pass, 0 fail, 3 skipped (run with HOME
and CLAUDE_CONFIG_DIR overridden to throwaway dirs; live profile verified
untouched afterward).
* enhance(#2483): adapt guard-test matcher to the effort-args dispatch reshape
The effortSurface wiring (#2481) reshaped the bare-model dispatch to
`claude $CLAUDE_EFFORT_ARGS -p -`; the invocation matcher's dash-first
form could no longer see it, and the count assertion failed exactly as
designed. The matcher now tolerates variable expansions between `claude`
and its first literal flag. Negative-controlled both ways: a stripped
guard and a deleted dispatch line each still fail.
* enhance(#2483): also guard the claude leg against auto-memory injection
CLAUDE_CODE_DISABLE_CLAUDE_MDS suppresses CLAUDE.md file loading;
auto-memory is an independently-toggled mechanism with its own flag.
Add CLAUDE_CODE_DISABLE_AUTO_MEMORY=1 to both dispatch lines, correct
the docs/COMMANDS.md and changeset claims that credited the first flag
with covering auto-memory, and extend the regression test to require
both flags on every claude invocation (negative-controlled: 2/4
assertions fail with the new flag removed).
* enhance(#2483): match the claude binary in command position, not argument position
The line-oriented invocation matcher counted any line where the token
`claude` was followed by a flag. #2589 (landed on next as 920a5f3f)
reshaped the effort-args lookup from
--host claude 2>/dev/null | jq -r '.effort_argv_string // ""'
to
--host claude --pick effort_argv_string
which put a flag immediately after `claude` and made the config query
read as a third claude dispatch, failing the count assertion.
The defect class is a binary name in *argument* position being read as a
command. Fixed at the class rather than the instance: tokenise the line
and skip any `claude` whose preceding token is a flag. That also covers
the latent sibling one line away in review.md (`command -v claude`),
which escaped today only because its next token is a redirect.
Negative-controlled four ways: stripping CLAUDE_CODE_DISABLE_AUTO_MEMORY=1
fails, stripping the whole env guard fails, adding a genuine third
unguarded dispatch (`timeout 900 claude --output-format text -p -`) still
fails — so the narrowing did not blind the matcher to reshapes, which is
the property the count assertion exists for — and the pre-#2589 jq form of
the lookup still passes, so the matcher is not pinned to today's base.
* enhance(#2483): carry the claude reviewer's memory guard as declared lane data
ADR-2782 Phase 5b replaced the hand-authored per-CLI dispatch legs in
review.md with the declared lane table, so the two `env`-prefixed shell
lines this PR previously added no longer have a surface to live on. The
guard is reimplemented where the lane contract now lives.
`SpawnInvoke` gains an optional `env`, the claude lane declares the pair,
the resolver folds own string-valued entries into `SpawnPlan.env` (absent
or empty resolves to null, so the runner has one shape to test), and the
runner passes it to spawn. Production merges it OVER `process.env` into a
fresh object for that one child, so nothing reaches the orchestrating
session or any other lane in the run.
Declared data rather than a handler (D6): the pairs are static per lane,
which is precisely what the manifest vocabulary is for. The capability
manifest carries the same field, because the lane-fidelity test compares
manifest and descriptor over the union of `invoke`'s keys.
The regression test is rewritten against the resolver and runner rather
than review.md's text. It gains the property the source-text assertions
could only approximate: that `process.env` is never mutated.
Scope boundary, asserted rather than left in prose: `env` is not part of
the trust-disclosure surface, which is safe only while no manifest body
reaches the resolver — the registry's reviewer bodies contribute slugs to
the parity check and execution resolves from `REVIEWER_LANES`. The new
test fails first if that ever changes.
* enhance(#2483): restate the guard's mechanism in the docs and changeset
Both described the fix as two `env`-prefixed dispatch lines, which is the
surface ADR-2782 Phase 5b removed. The user-visible behaviour is
unchanged; the carrier is not, and a changeset that ships a description
of a mechanism the tree does not have is a CHANGELOG entry nobody can
verify against the code.
* enhance(#2483): cover the production spawn wiring end to end
The unit tests stop at the runner's `deps.spawn` seam — every one injects
a spy. Production supplies that seam in `gsd-core/bin/gsd-tools.cjs` as a
hand-written object no test constructs, so the chain could be correct all
the way to `SpawnPlan.env` and the merge could still be wrong or absent
with the suite green. Deleting those four lines was the one mutation that
left every other control silent.
This runs the real `spawnSync` through `gsd-tools review-lane invoke`,
with a `claude` shim on PATH that records the environment it was handed.
It asserts both halves in one test: the pair arrives, and an unrelated
inherited variable survives — a wiring that REPLACED the environment
rather than merging over it would satisfy the first and break every
lane's PATH and HOME.
POSIX-only; mediating a Windows `.cmd` shim is a separate concern the
repo already tests on its own.
Noted rather than fixed: `timeout`, `killSignal`, `maxBuffer` and
`shell: false` on that same object are equally uncovered. That is the
epic's gap, not this change's, and closing it is not in scope here.
* enhance(#2483): validate the invoke.env shape and register it as spawn-only
`env` was the one spawn-invoke field with no shape enforcement: every sibling in
`validateSpawnInvoke` is checked, and a manifest declaring `env` as an array, a
string, a number, or an object with non-string values passed validation in
silence. That matters more than an ordinary schema gap here, because
`resolveLanePlan` DROPS a non-string value rather than coercing it — so an
unvalidated manifest declares a pair that never reaches the spawn, which is the
failure a memory guard can least afford.
Two registrations, not one. `env` was also absent from
`SPAWN_ONLY_INVOKE_FIELDS`, which is the list the openai-http arm rejects
against — so `invoke.env` was accepted on a transport that issues an HTTP POST
and has no child environment at all. It was the only spawn-shaped field accepted
there; the other six each produce two errors. Self-found while sweeping the
class, not raised in review.
Keys are held to the portable POSIX environment-name grammar. That is a policy,
not a claim about what an environment can hold: measured, only NUL is actually
rejected by `spawnSync`, while `=`, a leading digit, a dash and a space are all
carried through to the child (an `A=B` key arrives as the raw entry `A=B=value`).
They are refused because a name outside the grammar is not portably addressable
by the program meant to read it.
`__proto__` is refused for a different and concrete reason. It passes that
grammar and is a real own key once a manifest is JSON-parsed, but assigning it
onto a plain accumulator goes through the inherited `__proto__` setter rather
than creating an own property — and for the string values this field permits the
setter is a no-op that does not even change the prototype. The pair would
validate and then simply vanish before the spawn. (An environment CAN carry a
literal `__proto__` entry; this is about the resolver's accumulator, and the
error message says so.)
Deliberately narrower than the sibling reserved-name guards in this file, which
also reject `constructor`/`prototype`: those guard bracket lookups that resolve
prototype members, whereas this reads via `Object.keys` plus an own-value read,
where `constructor` assigns as an ordinary key the spawn could carry.
`effortChannel` is deliberately left in neither field list: ADR-2782 D2 defines
it for both transports, so it is shared rather than spawn-only.
Reversion-controlled, three mutations, all three fire a named test: dropping
`env` from the discriminator fails `httpTransportRejectsEnv`; removing the
`__proto__` arm fails `envRejectsProtoKeyThatWouldSilentlyVanish`; disabling
the block fails four.
(#2483)
* enhance(#2483): amend ADR-2782 D2 for the invoke.env vocabulary widening
D2 records the spawn `invoke` shape as a closed vocabulary, and its Amendments
section carries a dated entry for every prior widening (Phase 1 #2794, Phase 2
corrections #2795, Phase 5b #2799). This change extended that vocabulary in code
without touching the ADR governing it, so the ADR contradicted the
implementation — and the repo's own convention, recorded in CONTEXT.md, is that
the ADR is amended in the same PR precisely because the prior widenings did it
correctly.
Adds the `invoke.env` row to the D2 table and a dated Amendments entry.
The entry also corrects the authority this change cited. The source comment
pointed at D6, which governs the closed `handler` enum — imperative behavior
admitted first-party — and says nothing about the `invoke` field vocabulary.
That is D2's territory, so the citation never covered the gap.
Two claims are corrected rather than restated, both about the trust boundary
that justifies leaving `env` out of the D5 disclosure signature:
- The regression test does not enforce that boundary. On one forged lane it
shows the resolver folds whatever it is handed, so a future path feeding it
manifest lanes would not make any assertion in that test fail. Its comment
claimed it "will fail first"; that was wrong, and both the comment and the
ADR now say the boundary is a property of the production call chain instead.
- The ADR is internally inconsistent on whether third-party manifest lanes
execute at all: Consequences says adding a reviewer needs "no core patch",
while `gsd-tools.cjs` rejects every slug absent from the first-party
REVIEWER_LANES map. CONTEXT.md, `workflows/review.md` and the resolver's own
header take the first view. #2483 did not create that inconsistency and does
not resolve it; the entry records it rather than settling it in its own favour.
(#2483)
* enhance(#2483): document invoke.env in the capability-manifest reference
ADR-2782 points capability and plugin authors at
`docs/reference/capability-manifest.md` as where the lane vocabulary must be
visible, and its `invoke` row enumerates the spawn sub-shape field by field.
`env` was absent from that table while being part of the real shape, so the one
document a third-party capability author would actually consult to learn the
field exists did not mention it.
Squarely Diataxis reference material — a field-by-field schema description — so
it goes here rather than in the user-facing prose, which was already updated.
States the constraints a manifest author can actually trip, and is explicit that
the name grammar is a portability policy rather than an OS limit, so a reader
does not take it for a claim about what an environment can hold.
(#2483)
* enhance(#2483): disclose and sign the reviewer lane's env and residual invoke fields
`invoke.env` was undisclosed at install time. That was defensible while manifest
lanes could not execute — the premise this PR's own ADR amendment recorded — and
#2927/#3062 retired it: `routeReviewLane` now merges installed overlay `reviewer`
bodies into its lane map via `mergeReviewerLanes`, which is a field-identical merge
by ADR-2782 D1 and deliberately does not deep-validate. An overlay's whole `invoke`
therefore reaches `resolveLanePlan`, and `env` reaches the spawned child. A consented
third-party capability could set `NODE_OPTIONS=--require ./evil.js` on a reviewer lane
with no install-time disclosure and no re-consent.
The same file already decided what `env` means in a manifest: MCP servers fold it into
the disclosure signature and render each key and value in the consent prompt, with an
inline rationale naming this exact shape. Reviewer lanes get the identical treatment.
`env` was the ninth unsigned invoke field, not the first. `defaultHost` (the manifest's
OWN fallback egress host, used whenever the config key resolves to nothing),
`path`, `outputChannel`/`outputArg`, `modelArg`, `effortChannel` and `modelDiscovery`
all reach `resolveLanePlan` and none was bound. Enumerating a ninth name leaves the
tenth open, so the lane signature carries a RESIDUAL of every other declared `invoke`
key — the completeness backstop `rawConfig` already gives the MCP line (#1459 finding 5),
and the "sign the whole object" remedy the recorded decision on this class prefers.
`defaultHost` is also rendered: `resolvedHost` comes from user config, so a lane whose
key is unset displayed "(unresolved …)" — which reads as "no destination" — while the
runtime egresses the plan and review text to the address the manifest picked.
D4.5 is preserved one level down: the extra element is appended ONLY when the lane
declares something beyond the eight already-bound fields, so an env-free lane's
signature stays byte-identical and no already-consented capability is re-prompted for
a field it does not use. A lane that does declare one re-consents, which is the point.
Execution-primitive env names are FLAGGED in the prompt, not refused in the validator.
A denylist cannot be the boundary here: `PATH` alone is a complete execution primitive
for a spawn lane and can never be refused, the child is an arbitrary third-party binary
so the true set spans every interpreter's injection vars, and the MCP `env` this mirrors
refuses nothing and discloses everything. Missing a name costs a quieter line, never a
boundary.
Refs #2483.
* enhance(#2483): exercise the real overlay merge path in the guard test
The test named for the manifest/first-party boundary did not test it. It built a
forged lane locally, handed it straight to `resolveLanePlan`, and asserted that
`REVIEWER_LANES` did not contain it — so no assertion in it depended on the claim its
name made, and a code path that fed manifest lanes to the resolver would not have made
it fail. Its own comment said as much, and named the production chain as the real
carrier of the guarantee: "gsd-tools.cjs builds its lane map solely from REVIEWER_LANES".
That sentence is now false. #3062 merged overlay reviewer bodies into that map, so the
test's premise and its subject both moved.
The replacement routes through `mergeReviewerLanes` — the real helper the production
path calls — and asserts the overlay lane is admitted, resolves, and carries its `env`
into `SpawnPlan.env`. That makes the security property falsifiable instead of narrated.
It then asserts what now backs it: the env is disclosed on the surface, rendered key
and value in the consent prompt, flagged when the name is an execution primitive, and
bound to the signature so a value change, an addition, or a removal each force
re-consent.
Three further cases, because the finding's generative half is what stops it recurring:
the residual backstop is asserted against five fields including one that does not exist
(`aFieldThatDoesNotExistYet`), so a future vocabulary widening cannot silently re-open
this; a fully-enumerated lane is pinned to its original 8-tuple, which is what keeps the
fix from re-prompting every consented capability; and an http lane's manifest-declared
`defaultHost` is asserted to reach both the prompt and the signature.
Reversion-controlled, seven mutations, all seven fail a named test: env dropped from the
surface, the prompt's env line removed, the execution-primitive warning removed, the
signature's extra element never appended, the residual emptied, the defaultHost line
removed, and the declares-something test un-widened. The last of those was SILENT on its
first run and its test was written in response, then the control re-run.
Refs #2483.
* enhance(#2483): correct the ADR amendment's manifest-lane premise
The amendment argued `env` needed no D5 disclosure because a manifest's `invoke`
fields never reach `resolveLanePlan`. That was true when written and #3062 retired it
22 hours after this branch's last commit: `routeReviewLane` now builds its lane map
from `mergeReviewerLanes(REVIEWER_LANES, loadRegistry({includeInstalled: true}))`, and
D1's no-translation-layer rule makes that a field-identical merge, so an overlay's
whole `invoke` reaches the resolver and executes.
The entry had named this exact trigger — "were manifest lanes ever made executable,
`env` must join the disclosed surface in that change, and nothing here will trip if it
does not." Nothing tripped. The premise is rewritten to current truth rather than
annotated, because an ADR is read in fragments and a superseded paragraph left standing
reads as live reasoning to the next author; a one-line dated tombstone points at git for
the withdrawn text.
The rewritten entry records four things the first draft could not: that the enumeration
itself was the defect (`env` was the ninth unbound `invoke` field, and `defaultHost` and
`path` are egress-relevant on their own), that the residual is what closes the class,
that D4.5's byte-identical-signature property is preserved by appending the residual only
when a lane declares something beyond the eight bound fields, and that consent — not
shape validation — is the boundary, since no honest env denylist can exclude `PATH`.
It also closes the internal inconsistency the previous entry could only record. This ADR,
`CONTEXT.md`, `gsd-core/workflows/review.md` and `resolveLanePlan`'s own header all said
overlay lanes reach the resolver while the runtime said otherwise; #3062 resolved that in
the documents' favour, which is what makes the disclosure mandatory rather than defensive.
Refs #2483.
* enhance(#2483): record in the manifest reference that invoke fields are consent-bound
`docs/reference/capability-manifest.md` is the field table ADR-2782 points capability
authors at, and it described `invoke` purely as a schema. A third-party author reading it
could not learn that everything they declare there is shown to the user at install and
bound to the consent signature — which is exactly what they need to know now that an
overlay reviewer lane executes (#2927/#3062).
States the two things the schema alone cannot: that `env` and `defaultHost` are named in
the consent prompt and the rest is covered by a residual, so any change to a declared
`invoke` field forces re-consent; and that `env`'s validation is a portability policy
rather than a safety boundary, since `PATH` is a complete execution primitive and cannot
be refused. Names that are execution primitives are highlighted in the prompt instead.
Refs #2483.
* enhance(#2483): add a Security changeset for the reviewer-lane disclosure
The existing fragment describes the enhancement this PR was opened for and stays as it
is. The disclosure fix is a separate user-visible change of a different type: a
capability declaring `invoke.env` or `invoke.defaultHost` will ask for consent once
more, and users are entitled to read why in the changelog rather than discover it as an
unexplained prompt.
Type is `Security` rather than `Changed` because the entry describes a closed
code-execution disclosure gap, not a behaviour adjustment.
Refs #2483.
* enhance(#2483): correct this round's own claim about who gets re-prompted
Self-found while auditing the round's claims before publishing them. The changeset and
the ADR entry both stated that a capability declaring `invoke.env` or `defaultHost`
"will ask for consent once more". That is wrong, and it overstated the cost of the fix
in the one direction a maintainer would have had to take on trust.
A code change to `disclosureSignature` re-prompts nobody. `hasProjectConsent` matches on
the recomputed bundle `contentHash` — the signature has not been the security binding
since #1459 CB-1/CB-2 — and the upgrade path's `executableSetChanged(old, new)` compares
two disclosures both computed by the CURRENT code, so widening the signature moves both
sides of that comparison equally. First-party capabilities never reach the path at all:
the install flow blocks a first-party id before trust evaluation.
What the widening actually buys is forward-looking, and is the real argument for it: an
upgrade whose manifest edits a declared `invoke` field now registers as an
executable-surface change and re-consents, where before it could change what the lane
runs in silence.
Also measured and recorded, because the D4.5 property was stated more strongly than it
deserved: of the twelve first-party reviewer capabilities, ZERO are in the
byte-identical-signature class — every real lane declares at least `effortChannel`. The
property is a guarantee about minimal lanes, not a description of the fleet, and the ADR
now says so.
Refs #2483.
* enhance(#2483): sign and disclose the probe binary and the lane's outer fields
Found by this round's own adversarial review, and it is the same defect one level out:
the `invoke` residual cannot reach the lane body's OUTER fields, and `probeLane` SPAWNS
`probe.binary` with `--help` before dispatch (`review-lane-runner.cts`, the
`command-exists`/`command-capability` arms). An overlay naming an arbitrary probe binary
therefore executes it — unsigned and undisclosed, exactly as `invoke.env` was, and
reachable on the same #3062 path.
The lane element now carries a second residual over the outer fields, and the probe
binary is shown in the consent prompt when it differs from the dispatch binary — it is a
program that runs, and the user is entitled to see it.
TWO fields stay excluded, and that is a decision rather than an omission:
`reviewsSection` and `timeoutFloorMs` are ADR-2782's cosmetic carve-outs (matrix
A10/A13), where re-consenting would present a prompt carrying no security information.
A test pins that they remain excluded, so a later widening cannot quietly reverse D4.5
while claiming to complete this fix.
Also corrects a miscount introduced by the previous commit: the source comment said the
enumeration had fallen behind by "seven fields" and omitted `fallbackModel`, while
asserting `env` was the ninth. `resolveLanePlan` reads twelve `inv.*` fields and four
were bound, so the number is eight. The comment now states the derivation rather than
just the total.
Reversion-controlled: emptying the outer residual fails "repointing the probe binary must
force re-consent"; removing the render line fails its own named assertion.
Refs #2483.
* enhance(#2483): refuse execution-primitive env names as defence in depth
Adopts the review's B5 after this round's own adversarial pass refuted my reason for
declining it. I had argued a denylist was worthless because `PATH` can never be refused.
That was wrong on the facts: no shipped reviewer manifest declares `PATH`, so it can be
refused, and it is the most complete primitive in the set — repoint it at a directory
holding a fake binary and the declared `invoke.binary` is irrelevant. A list that cannot
be exhaustive can still close the highest-confidence, lowest-legitimacy routes.
So the validator now rejects `PATH`, `NODE_OPTIONS`, `LD_PRELOAD`, `DYLD_INSERT_LIBRARIES`,
`BASH_ENV`, `PYTHONPATH`, `PERL5OPT`, `RUBYOPT`, `GIT_SSH_COMMAND`, `JAVA_TOOL_OPTIONS`
and their siblings on a reviewer lane. A lane needing a specific executable declares an
absolute `invoke.binary` instead of reshaping the child's environment.
The comment states plainly that this is defence in depth and NOT the boundary — the
boundary is install-time consent, which discloses every declared pair and binds it to the
signature, so an unlisted name is still SEEN before it runs. That framing is load-bearing:
a future reader who mistakes the denylist for the control will under-invest in the one
that is, which is the failure mode I was trying to avoid by declining it outright.
Two tests: the rejection itself across ten names, and a guard asserting no shipped
reviewer capability declares a denied key — so if the list ever outgrows its evidence,
that surfaces as a decision rather than a silent removal.
Refs #2483.
* enhance(#2483): fix two stale D5 enumerations elsewhere in the ADR
The previous commit rewrote the amendment's premise but swept only the amendment. Two
normative passages earlier in the same ADR still enumerated the old closed field list and
now contradicted it: the `executableSetChanged` trigger list, and the split-binding note
asserting the seven manifest-derived fields were "everything that is SHA-pinned".
That is the failure the rewrite-don't-annotate rule exists to prevent, one section over —
an ADR is read in fragments, and a fragment carries no supersession marker, so a reader
landing on either passage would have taken the superseded enumeration as current.
Both now name the residual as the mechanism rather than restating a list, which is also
what stops them going stale the next time the vocabulary widens.
Found by this round's adversarial review, which grepped the whole document rather than
the section under edit.
Refs #2483.
* enhance(#2483): stop the probe disclosure claiming a spawn that does not happen
The probe line added one commit ago rendered "probes by running: <binary> --help" for
every lane. That is false for `kind: "command-exists"`, which only calls `hasBinary` — a
PATH/filesystem scan that starts no process. Only `command-capability` spawns.
A false statement in a consent prompt is worse than a missing one: the prompt is the
surface a user is asked to trust, and this one overstated what a lane does. Worse, the
test I wrote to prove the fix used `command-exists` — the kind that does NOT spawn — so
it pinned the wrong claim and would have kept the error green forever.
The surface now carries `probeKind` and the two kinds render differently: a spawn is
described as a spawn, a presence check as a presence check. The test exercises both, and
asserts the `command-exists` path never emits the spawn wording.
Also corrects the field-count parenthetical to state its derivation unambiguously —
`resolveLanePlan` reads thirteen `inv.*` fields including `env` (twelve before this PR),
four were bound, so eight were unbound before `env` and nine including it. The bare
"twelve" was true only of the pre-PR tree and read as a claim about the current one.
And retires two comments that argued AGAINST the validator denylist this round then
shipped. Leaving them would have handed the next reader the reasoning for removing it.
Reversion-controlled: conflating the two probe kinds fails a named test.
Refs #2483.
* enhance(#2483): match the reviewer-lane env denylist case-insensitively
The denylist added one commit ago compared exact case, so `Path`, `path`, `node_options`
and `Node_Options` all passed it. Windows environment lookup is case-insensitive, so
those reach the child as `PATH` and `NODE_OPTIONS` — the exact inputs the list names.
An exactly-cased denylist is worse than none: it reads as a control while admitting the
input it was written to refuse, and the next reader has no reason to doubt it. Members
are stored uppercase and the key is folded before lookup; the name grammar already
constrains keys to ASCII, so a plain fold is sufficient.
Reversion-controlled: restoring the exact-case compare fails `envDenylistIsCaseInsensitive`
on `Path`.
Refs #2483.
* enhance(#2483): correct the docs that still described the denylist as absent
Both the ADR and the manifest reference still said `env` carries no denylist and that
`PATH` "can never be refused" — written when that was this round's position, and left
standing after the round reversed it. A reader landing on either passage would have taken
the superseded argument as current, which is precisely the failure the rewrite-don't-
annotate rule exists to prevent.
Both now describe the denylist, name `PATH`'s inclusion and the case-insensitive match,
and keep the limit explicit: the list cannot be complete against an arbitrary child and
disclosure runs before validation, so consent remains the boundary.
The ADR's byte-identical-signature claim is also corrected rather than softened. With the
outer residual in place, a lane producing no residual is one the validator rejects — it
declares no `flags`, `probe`, `emptyOutput`, `evidenceClass`, `requiresBinaries` or
`promptBudgetKey`. So the property is about the ENCODING, not a claim that any real
signature is unchanged, and it is not the argument for the change being safe. That
argument is that consent binds to the bundle contentHash and no existing consent is
invalidated at all.
Refs #2483.
* test(#2483): cover the three new lane disclosure fields in the injection-safety parity guard
The PARITY test in section N exists to catch a renderer field that skips
`renderValueForPrompt` (#3248). Its payload manifest is hand-maintained, so it
covers the fields that existed when it was written — slug, binary, args,
hostConfigKey, handler — and none of the fields this PR adds.
This PR renders three further manifest-supplied values into consent-prompt
lines: `invoke.env` (keys and values), `invoke.defaultHost` and `probe.binary`.
The gap was silent rather than theoretical: with the lane env line reverted to
the pre-#3248 raw form, the whole 948-test lane/capability/trust-disclosure
suite stayed green.
Two manifests, because the shapes render disjoint lines — `defaultHost` only on
the openai-http branch, `env`/`probe` only where declared, and the probe line
only when the probe binary differs from the dispatch binary.
Non-vacuity is asserted on the typed disclosure object and on structural line
counts, not by substring-matching rendered prose: CONTRIBUTING.md forbids raw
text matching on test output, and this section's own header promises structural
assertions only, so a prose match here would have made that promise false.
Negative-controlled three ways against the merged tree, each producing exactly
one named failure: env rendered raw, defaultHost rendered raw, probe binary
rendered raw.
* docs(#2483): extend the #3248 render-site comment to the fields this PR adds
The comment enumerates every manifest-supplied value that must pass through
`renderValueForPrompt`, and it stopped at `handler` — the reviewer-lane fields
that existed when #3248 landed. This PR renders three more (`defaultHost`, the
probe binary, and the env keys and values), so the list understated its own
contract in the one place a future author would check before adding a fourth.
A comment enumerating a closed set is a set that can silently fall behind the
code it describes; the parity test added alongside is what makes the omission
fail loudly rather than read as deliberate.
---------
Co-authored-by: Tom Boucher <trekkie@nomorestars.com>
1674 lines
87 KiB
TypeScript
1674 lines
87 KiB
TypeScript
/**
|
||
* Capability trust gate — ADR-1244 Phase 4 (Decision D5 + the compatibility half of D6), extended
|
||
* by ADR-2782 Phase 3 (#2796) with a FOURTH executable-surface class (the reviewer lane), and by
|
||
* ADR-2363 Phase 1 (#3248) with a FIFTH, NON-executable class: the instruction surface.
|
||
*
|
||
* PURE module. It computes *what* a capability would do and *whether* policy allows it; it
|
||
* never mutates the filesystem and never performs I/O beyond reading staged files to confirm
|
||
* declared executable artifacts exist. The actual consent decision (yes/no) is passed in by the
|
||
* caller — GSD has no interactive-prompt layer in lib (the runtime/CLI edge owns that), so the
|
||
* gate stays testable and side-effect-free. See docs/explanation/capability-trust-model.md.
|
||
*
|
||
* LEAF MODULE — imports ONLY: node:fs, node:path, and ./semver-compare.cjs.
|
||
*
|
||
* ADR-2782 D5 (#2796): a `reviewer` lane is piped the plan text, requirements, research findings
|
||
* and CONTEXT.md decisions, then its output is read back into REVIEWS.md — making it an executable
|
||
* surface exactly like a hook, command module, or MCP server, and it is disclosed and consent-bound
|
||
* the same way. `disclosureSignature` appends the lane element to its output ONLY when at least one
|
||
* lane is declared (D4.5) — a lane-free manifest's signature stays byte-identical to before this
|
||
* class existed, so no already-consented capability re-prompts on upgrade. The RESOLVED host (as
|
||
* opposed to the declared `hostConfigKey`) is disclosed to a human but deliberately EXCLUDED from
|
||
* the signature — the loader has no config resolver and must compute the same signature as the
|
||
* lifecycle (constraint 2, `.gsd/phase/chore-2796-reviewer-trust-disclosure/40-design.md`).
|
||
*
|
||
* ADR-2363 D5 (#3248): a capability's declared `skills` are INSTRUCTION surfaces — their bodies are
|
||
* copied verbatim into the user's agent instruction context, so their reach is bounded only by what
|
||
* the agent will do when told. They are disclosed BY NAME and never content-scanned (D2 —
|
||
* Kerckhoffs: a shipped rule set is readable by the adversary who installs it). Unlike the four
|
||
* executable classes they never set `hasExecutable` (D3) and never enter `disclosureSignature` (D4):
|
||
* folding them in would perturb the stored signature of every already-consented skill-bearing
|
||
* capability and fire a spurious re-consent on its next upgrade — the harm ADR-2782 D4 rule 5
|
||
* already forbids. Any future signature binding arrives as a versioned v2, never an in-place
|
||
* re-encoding of v1. ADR-2363 D3's class table names "skills, agents", but third-party `agents[]`
|
||
* are deliberately EXCLUDED here: `stageAgentsForRuntimeWithConverter` (`src/install-profiles.cts`)
|
||
* takes only a source directory, with no registry-aware third-party staging path the way
|
||
* `readInstalledCapabilitySkill` gives skills — so a declared agent is never actually staged into
|
||
* the instruction context, and disclosing it would name a surface that does not exist. Agents stay
|
||
* unimplemented pending a maintainer decision.
|
||
*
|
||
* Exports:
|
||
* RESERVED_NAMESPACES — id prefixes third parties may not claim
|
||
* discloseExecutableSurfaces(...) — enumerate the four executable classes + instruction surfaces
|
||
* collectReviewerLaneSurfaces(...) — the reviewer-lane collector, independently testable
|
||
* collectInstructionSurfaces(...) — the instruction-surface collector, independently testable
|
||
* checkReservedNamespace(id) — is this id in a reserved namespace?
|
||
* evaluateSourceAllowed(parsed,...) — strictKnownRegistries enforcement
|
||
* checkEngines(manifest, host) — engines.gsd hard gate + compatVersions downgrade
|
||
* evaluateInstallTrust(args) — compose: source + namespace + engines + disclosure
|
||
* executableSetChanged(old, new) — did the executable surface set change between versions?
|
||
* summarizeDisclosure(disclosure) — human-readable consent-prompt lines
|
||
* summarizeInstructionSurfaces(d) — the instruction-surface section of the consent summary
|
||
* UNRESOLVED_HOST_MARKER — the non-blank marker for an unresolved openai-http host
|
||
* EGRESS_PAYLOAD_CLASSES — the named data classes every reviewer lane receives
|
||
*/
|
||
|
||
import fs from 'node:fs';
|
||
import path from 'node:path';
|
||
|
||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||
const semverMod = require('./semver-compare.cjs') as {
|
||
semverSatisfies: (version: string, range: string) => boolean;
|
||
isSemverNewer: (a: string, b: string) => boolean;
|
||
};
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// Constants
|
||
// ---------------------------------------------------------------------------
|
||
|
||
/**
|
||
* Id prefixes reserved for first-party / vendor capabilities. A third-party capability whose
|
||
* id begins with any of these is rejected at install so it cannot impersonate a first-party
|
||
* one. Match is case-insensitive on the normalized id.
|
||
*/
|
||
const RESERVED_NAMESPACES = ['gsd-', 'gsd-core-', 'anthropic-'];
|
||
|
||
/**
|
||
* ADR-2782 D5's gating requirement (#2796): every reviewer lane is piped the plan text,
|
||
* requirements, research findings and CONTEXT.md decisions. Named explicitly here so disclosure
|
||
* says exactly this — never the unhelpful "sends data to the tool" (design section B5).
|
||
*/
|
||
const EGRESS_PAYLOAD_CLASSES = ['plan text', 'requirements', 'research findings', 'CONTEXT.md decisions'];
|
||
|
||
/**
|
||
* B3 (#2796 matrix): `resolvedHost` must never be a blank string — a blank reads as "no
|
||
* destination" rather than "not resolved". This marker is disclosed for an `openai-http` lane
|
||
* when no resolver was supplied to `collectReviewerLaneSurfaces`, or the supplied resolver could
|
||
* not resolve the declared `hostConfigKey`. Deliberately NOT part of `disclosureSignature`'s input
|
||
* (see the lane signature line) — only the human-facing surface carries it.
|
||
*/
|
||
const UNRESOLVED_HOST_MARKER = '(unresolved — no host resolver was supplied at disclosure time)';
|
||
|
||
/**
|
||
* Loopback hostnames recognized LITERALLY, never by substring (an evil host must not spoof this,
|
||
* e.g. `notlocalhost.example`). D5: localhost is not "safe by default" — it is disclosed and
|
||
* FLAGGED, never omitted (matrix B4).
|
||
*/
|
||
const LOOPBACK_HOSTNAMES = new Set(['localhost', '127.0.0.1', '::1', '[::1]', '0.0.0.0']);
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// Types
|
||
// ---------------------------------------------------------------------------
|
||
|
||
interface CapabilityManifest {
|
||
id?: unknown;
|
||
version?: unknown;
|
||
engines?: unknown;
|
||
compatVersions?: unknown;
|
||
hooks?: unknown;
|
||
commands?: unknown;
|
||
mcpServers?: unknown;
|
||
/** ADR-2782 (#2796): a single reviewer-lane body — never an array (Phase 2's own validator rejects that shape). */
|
||
reviewer?: unknown;
|
||
[k: string]: unknown;
|
||
}
|
||
|
||
interface HookSurface {
|
||
event: string;
|
||
script: string;
|
||
}
|
||
|
||
interface CommandModuleSurface {
|
||
family: string;
|
||
module: string;
|
||
/**
|
||
* TRUST2-3 (#1459): the exported function the host invokes from the module — WHICH code runs. A
|
||
* version that keeps family+module but retargets `router` to a different exported function changes
|
||
* what executes, so it is part of the disclosed + consent-bound surface. Empty when undeclared.
|
||
*/
|
||
router: string;
|
||
}
|
||
|
||
interface McpServerSurface {
|
||
name: string;
|
||
/**
|
||
* The transport TYPE: 'stdio' (spawns command/argv), 'http', or 'sse' (connects to a URL). TRUST2-2
|
||
* (#1459): a non-stdio server was previously invisible to the disclosure/signature — its url/headers
|
||
* could be swapped with no re-consent. Empty when undeclared (the host default is stdio).
|
||
*/
|
||
transport: string;
|
||
/** The command the server spawns (the actual executable — disclosed for honest consent). stdio only. */
|
||
command: string;
|
||
/**
|
||
* Arguments passed to the command. TRUST2-4 (#1459): this is a stringified view for the human
|
||
* summary; the consent SIGNATURE encodes the RAW args array (incl non-string members) via
|
||
* `rawArgs` so a non-string arg change still forces re-consent (the host receives the raw args).
|
||
*/
|
||
argv: string[];
|
||
/**
|
||
* The RAW args array as declared (may contain non-strings). Folded — stable-encoded — into the
|
||
* signature so a change to ANY member (incl a number/object/bool the host would still pass) forces
|
||
* re-consent (TRUST2-4). Empty array when none declared.
|
||
*/
|
||
rawArgs: unknown[];
|
||
/**
|
||
* The URL an http/sse server connects to — TRUST2-2: WHERE the server talks to. A url change is a
|
||
* different remote endpoint and must force re-consent. Empty when undeclared (stdio servers).
|
||
*/
|
||
url: string;
|
||
/**
|
||
* The HTTP headers an http/sse server is given (string→string, stable-sorted) — TRUST2-2: headers
|
||
* carry auth/behavior and a change must force re-consent. Header VALUES are redacted in the human
|
||
* summary but INCLUDED in the signature. Empty object when none.
|
||
*/
|
||
headers: Record<string, string>;
|
||
/**
|
||
* Environment variables (string→string only) the server is spawned with — disclosed because
|
||
* env can change WHAT a command does (e.g. NODE_OPTIONS=--require /tmp/evil.js) without touching
|
||
* command/argv. Any add/change forces re-consent (TRUST-2, #1459). Empty object when none.
|
||
*/
|
||
env: Record<string, string>;
|
||
/** The working directory the server is spawned in (if declared) — also affects what runs. */
|
||
cwd?: string;
|
||
/**
|
||
* Finding 5 (MEDIUM, #1459): the FULL declared server config object (prototype-pollution-safe
|
||
* shallow-cleaned copy). The writer persists the WHOLE config ({...config}), so the signature must
|
||
* bind the WHOLE config — not only the whitelisted fields above — or an upgrade that changes a
|
||
* host-honored field NOT in the whitelist (a future `envFile`/`workingDir`/launch option) would be
|
||
* written verbatim yet leave the signature constant → no re-consent prompt. This is folded into the
|
||
* signature as STABLE (recursively key-sorted) JSON, so any add/change forces re-consent while a
|
||
* pure key reorder does not. NOT shown in the human summary (which stays readable via the key fields).
|
||
*/
|
||
rawConfig: Record<string, unknown>;
|
||
}
|
||
|
||
/**
|
||
* Resolves a reviewer lane's `hostConfigKey` (a dotted key into `.planning/config.json`) to its
|
||
* configured destination host, for HUMAN disclosure only. Optional — the loader has no config
|
||
* access and calls `discloseExecutableSurfaces`/`signatureForManifest` without one; the lifecycle
|
||
* MAY supply one so the consent prompt shows a real destination instead of `UNRESOLVED_HOST_MARKER`.
|
||
* MUST NOT throw is not required of the caller — `collectReviewerLaneSurfaces` treats any thrown
|
||
* error or non-string/empty return as "could not resolve" and falls back to the marker.
|
||
*/
|
||
type ReviewerHostResolver = (hostConfigKey: string) => string | undefined;
|
||
|
||
/**
|
||
* ADR-2782 D5 (#2796): the reviewer-lane executable surface. A capability manifest carries AT MOST
|
||
* ONE `reviewer` body (Phase 2's validator rejects an array), so this collector returns 0 or 1
|
||
* entries per manifest — the array return shape matches the other three collectors for a uniform
|
||
* `Disclosure` and lets `disclosureSignature` sort/fold it the same way.
|
||
*/
|
||
interface ReviewerLaneSurface {
|
||
/** The lane's declared identity (also its config/flag namer). Empty when undeclared/malformed. */
|
||
slug: string;
|
||
/** `'spawn'` | `'openai-http'` as declared, or '' when absent/malformed — disclosure never validates. */
|
||
transport: string;
|
||
/** spawn: the executable name/path as declared. Empty for an openai-http lane or when undeclared. */
|
||
binary: string;
|
||
/** spawn: the declared args, RENDERED (string-filtered) for the human summary — mirrors MCP's argv. */
|
||
args: string[];
|
||
/**
|
||
* spawn: the FULL declared args array (may contain non-strings the host still receives) — folded
|
||
* into the signature so ANY member change forces re-consent (matrix A6, the #1459 bug class:
|
||
* `python3` with innocuous args later becoming `['-c', '<program>']`). Empty when undeclared.
|
||
*/
|
||
rawArgs: unknown[];
|
||
/** openai-http: the dotted config key naming the destination host. Empty for a spawn lane. */
|
||
hostConfigKey: string;
|
||
/**
|
||
* openai-http: the resolved destination host when a resolver was supplied and could resolve
|
||
* `hostConfigKey`; `UNRESOLVED_HOST_MARKER` when a resolver was not supplied or could not resolve
|
||
* it. NEVER '' for an openai-http lane (matrix B3) — a blank reads as "no destination". '' for a
|
||
* spawn lane (no destination concept — mirrors McpServerSurface's empty-when-inapplicable
|
||
* convention). Deliberately EXCLUDED from `disclosureSignature`'s input (design constraint 2): the
|
||
* loader has no resolver and must compute the SAME signature as the lifecycle.
|
||
*/
|
||
resolvedHost: string;
|
||
/**
|
||
* True when `resolvedHost` is a loopback/local destination. D5: localhost is disclosed like any
|
||
* other destination, never treated as "safe by default" (matrix B4). Always false for a spawn
|
||
* lane and for an unresolved openai-http host.
|
||
*/
|
||
isLocalDestination: boolean;
|
||
/** How the review prompt reaches the lane (`'stdin'|'argv'|'argv-file-ref'|'none'`, or ''). */
|
||
promptChannel: string;
|
||
/** The first-party handler module name that post-processes this lane's output, or '' when undeclared. */
|
||
handler: string;
|
||
/**
|
||
* spawn: the per-invocation environment pairs the lane declares (#2483), string-filtered for the
|
||
* human summary exactly as `args` is. Folded into the signature, and rendered key-by-key in the
|
||
* consent prompt, for the SAME reason MCP's `env` already is: env changes WHAT a command does
|
||
* without touching the command (`NODE_OPTIONS=--require evil.js`, `LD_PRELOAD`). Empty when the
|
||
* lane declares none, which keeps an env-free lane's signature byte-identical (D4.5).
|
||
*/
|
||
env: Record<string, string>;
|
||
/**
|
||
* openai-http: the destination host the MANIFEST itself declares, used at runtime whenever
|
||
* `hostConfigKey` resolves to nothing (`resolveLanePlan`: `configured ?? declaredDefault`). It is
|
||
* NOT `resolvedHost` — that one is resolved from user config and is deliberately excluded from the
|
||
* signature (design constraint 2). This one is a pure function of the manifest, so it both signs
|
||
* and renders: without it a lane whose config key is unset discloses `(unresolved)` at consent
|
||
* time while shipping the egress payload classes to an address of the manifest's own choosing.
|
||
*/
|
||
defaultHost: string;
|
||
/**
|
||
* Every OTHER own key the declared `invoke` object carries — the completeness backstop, and the
|
||
* direct analogue of `McpServerSurface.rawConfig` (#1459 finding 5). The explicit fields above are
|
||
* kept first for readability and stability; this catches the rest, so a field ADDED to the invoke
|
||
* vocabulary later is signed from the day it exists rather than from the day someone remembers to
|
||
* widen this list. The enumerated fields (`binary`/`args`/`hostConfigKey`/`promptChannel`) are
|
||
* excluded because they are already bound above; `env` and `defaultHost` are deliberately NOT
|
||
* excluded, mirroring the MCP line's own explicit-then-rawConfig overlap.
|
||
*/
|
||
residualInvoke: Record<string, unknown>;
|
||
/**
|
||
* The same backstop for the lane body's OUTER fields, which `invoke`'s residual cannot reach.
|
||
* `probe` is the reason it exists and is not a hypothetical: `probeLane` SPAWNS `probe.binary`
|
||
* with `--help` (`review-lane-runner.cts`, `command-exists`/`command-capability`), so an overlay
|
||
* naming an arbitrary probe binary executes it — the same class as `invoke.env`, one level out.
|
||
* `requiresBinaries`, `emptyOutput`, `promptBudgetKey` and `modelConfigKey` ride along for the
|
||
* same reason the invoke residual exists: enumerating "the ones that matter" is what failed.
|
||
*
|
||
* TWO fields are deliberately excluded, and the exclusion is a DECISION, not an oversight:
|
||
* `reviewsSection` and `timeoutFloorMs` (D4.5 / matrix A10/A13 — cosmetic, and folding them in
|
||
* would force a re-consent prompt carrying no security information, training click-through).
|
||
* `slug`/`transport`/`handler`/`invoke` are excluded because they are already bound.
|
||
*/
|
||
residualLane: Record<string, unknown>;
|
||
/**
|
||
* spawn: the binary this lane's availability probe touches, or '' when none. Paired with
|
||
* `probeKind` because the two probe kinds do DIFFERENT things and the prompt must not conflate
|
||
* them: `command-capability` SPAWNS `<binary> --help` and parses the output, while
|
||
* `command-exists` only asks `hasBinary` (a PATH/filesystem scan that spawns nothing).
|
||
*/
|
||
probeBinary: string;
|
||
/** The declared probe `kind`, or '' — decides how `probeBinary` is described to the human. */
|
||
probeKind: string;
|
||
/**
|
||
* The data classes that egress to this lane on every run (`EGRESS_PAYLOAD_CLASSES`) — named
|
||
* honestly (Kerckhoffs's Principle) rather than disclosed as an unhelpful "sends data to the tool".
|
||
*/
|
||
egressPayloadClasses: string[];
|
||
}
|
||
|
||
/**
|
||
* ADR-2363 D3 (#3248): an INSTRUCTION surface — an artifact whose body is copied verbatim into the
|
||
* user's agent instruction context. Peer to the four executable-surface classes, and deliberately
|
||
* NOT one of them: a skill body does not execute code, it instructs the thing that does.
|
||
*
|
||
* Disclosure NAMES the surface; it never inspects the body. Content scanning is rejected outright
|
||
* by ADR-2363 D2 (Kerckhoffs — a shipped rule set is readable by the adversary who installs it).
|
||
*/
|
||
interface InstructionSurface {
|
||
/**
|
||
* Which declaration array the name came from — still a discriminator even with one member: a
|
||
* future addition (see `INSTRUCTION_SURFACE_FIELDS`) is why this stays a field rather than being
|
||
* dropped now.
|
||
*/
|
||
kind: 'skill';
|
||
/** The declared stem/name, VERBATIM — never normalized, truncated, or deduped. */
|
||
name: string;
|
||
}
|
||
|
||
interface Disclosure {
|
||
/** Hook scripts the capability registers (each runs as a runtime hook command). */
|
||
hooks: HookSurface[];
|
||
/** Command modules the capability ships (each is require()'d into the GSD CLI process). */
|
||
commandModules: CommandModuleSurface[];
|
||
/** MCP servers the capability declares (each spawned by the host runtime) — name AND command. */
|
||
mcpServers: McpServerSurface[];
|
||
/**
|
||
* ADR-2782 (#2796): the reviewer lane this capability declares — 0 or 1 entries (a manifest
|
||
* carries at most one `reviewer` body). A fourth executable-surface class alongside the three
|
||
* above; a standing egress channel to an external reviewer.
|
||
*/
|
||
reviewerLanes: ReviewerLaneSurface[];
|
||
/**
|
||
* ADR-2363 D5 (#3248): the skills this capability contributes to the agent's instruction context
|
||
* (agents are excluded — see the module header). A FIFTH disclosed class that is deliberately NOT
|
||
* executable: it never contributes to `hasExecutable` (D3) and never enters `disclosureSignature`
|
||
* (D4 — folding it in would perturb the stored signature of every already-consented skill-bearing
|
||
* capability and fire a spurious re-consent on its next upgrade, which ADR-2782 D4 rule 5 forbids).
|
||
*/
|
||
instructionSurfaces: InstructionSurface[];
|
||
/** True when the capability ships ANY executable surface (=> consent required). */
|
||
hasExecutable: boolean;
|
||
/**
|
||
* Declared module/script files that were NOT found under the staged dir (defensive — a
|
||
* manifest referencing a missing artifact is suspicious; surfaced, not silently dropped).
|
||
* Empty when no stagedDir was supplied.
|
||
*/
|
||
missingArtifacts: string[];
|
||
}
|
||
|
||
type StrictKnownRegistries = string[] | null | undefined;
|
||
|
||
interface ParsedSpec {
|
||
kind: 'registry' | 'git' | 'npm' | 'tarball' | 'local';
|
||
raw: string;
|
||
target: string;
|
||
ref?: string;
|
||
}
|
||
|
||
interface SourceVerdict {
|
||
allowed: boolean;
|
||
reason: string | null;
|
||
}
|
||
|
||
interface EnginesVerdict {
|
||
/** Does the capability's *current* version run on this host? */
|
||
compatible: boolean;
|
||
/** The declared engines.gsd range, or null if unconstrained. */
|
||
range: string | null;
|
||
satisfiedBy: 'engines' | 'compatVersions' | 'unconstrained' | null;
|
||
/** When the current version is incompatible but compatVersions names one that works. */
|
||
downgradeTo?: string;
|
||
}
|
||
|
||
interface InstallTrustArgs {
|
||
parsed: ParsedSpec;
|
||
manifest: CapabilityManifest;
|
||
/** Optional staged dir — when given, declared artifacts are existence-checked. */
|
||
stagedDir?: string;
|
||
strictKnownRegistries?: StrictKnownRegistries;
|
||
hostVersion: string;
|
||
/**
|
||
* Optional (#2796): resolves a reviewer lane's `hostConfigKey` to its configured destination, for
|
||
* HUMAN disclosure at install time only — never folds into the consent signature (design
|
||
* constraint 2; see `ReviewerHostResolver`).
|
||
*/
|
||
resolveHost?: ReviewerHostResolver;
|
||
}
|
||
|
||
interface InstallTrustVerdict {
|
||
/** True when no policy gate blocks the install. */
|
||
allowed: boolean;
|
||
/** True when the install is allowed BUT ships executable surfaces => needs consent. */
|
||
requiresConsent: boolean;
|
||
disclosure: Disclosure;
|
||
engines: EnginesVerdict;
|
||
/** Non-empty when allowed === false; each string is a human-readable block reason. */
|
||
blockReasons: string[];
|
||
}
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// Disclosure
|
||
// ---------------------------------------------------------------------------
|
||
|
||
function asString(v: unknown): string {
|
||
return typeof v === 'string' ? v : '';
|
||
}
|
||
|
||
/**
|
||
* Run `fn`, returning `fallback` instead of throwing. Makes each per-class collector total: a
|
||
* hostile manifest (a Proxy with a throwing trap, a throwing getter, or a non-object/null root)
|
||
* degrades ONE surface class to empty rather than crashing disclosure for the other three classes
|
||
* behind it in the same manifest (ADR-2782 #2796 — disclosure runs before validation and must never
|
||
* throw; matrix C5/E2).
|
||
*/
|
||
function safeCollect<T>(fn: () => T, fallback: T): T {
|
||
try {
|
||
return fn();
|
||
} catch {
|
||
return fallback;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Recognize a loopback/local destination from a RESOLVED openai-http host value (matrix B4). Matches
|
||
* literally, never by substring — an evil host must not spoof `localhost` via e.g.
|
||
* `notlocalhost.example`. Falls back to a scheme-less leading-segment match so a bare config value
|
||
* like `localhost:1234` or `192.168.1.5:8080` (no `http://` prefix) is still recognized.
|
||
*
|
||
* The fallback triggers on EITHER `new URL()` throwing (a value that is not parseable as an absolute
|
||
* URL at all, e.g. `192.168.1.5:8080` — WHATWG scheme names cannot start with a digit) OR it
|
||
* succeeding with an EMPTY hostname: `new URL('localhost:1234')` does NOT throw — it mis-parses the
|
||
* scheme-less `host:port` shape as an opaque URL whose "scheme" IS the hostname text
|
||
* (`protocol: "localhost:"`, `hostname: ""`), which would otherwise silently fail to recognize a
|
||
* bare local config value as local.
|
||
*/
|
||
function isLocalHostValue(hostValue: string): boolean {
|
||
let hostname = '';
|
||
try {
|
||
hostname = new URL(hostValue).hostname;
|
||
} catch {
|
||
hostname = '';
|
||
}
|
||
if (!hostname) {
|
||
hostname = extractBareHost(hostValue);
|
||
}
|
||
// WHATWG returns an IPv6 hostname bracketed; a bare config value may not be.
|
||
const lower = hostname.toLowerCase().replace(/^\[/, '').replace(/\]$/, '');
|
||
if (LOOPBACK_HOSTNAMES.has(lower)) return true;
|
||
if (isLoopbackIpv6(lower)) return true;
|
||
return isLoopbackIpv4(lower);
|
||
}
|
||
|
||
/**
|
||
* Pull the host out of a value `new URL()` could not parse — a scheme-less
|
||
* `host:port`, or one carrying a path/query/fragment.
|
||
*
|
||
* IPv6 needs explicit handling: splitting on `:` mangles `[::1]:8080` to `[`,
|
||
* which then matches nothing and silently reports a loopback destination as
|
||
* remote. A bracketed literal is taken through its closing bracket; an unbracketed
|
||
* value with two or more colons is treated as a bare IPv6 address rather than
|
||
* `host:port`, since a host:port has exactly one.
|
||
*/
|
||
function extractBareHost(hostValue: string): string {
|
||
let s = String(hostValue).trim();
|
||
const schemeEnd = s.indexOf('://');
|
||
if (schemeEnd >= 0) s = s.slice(schemeEnd + 3);
|
||
s = s.split(/[/?#]/)[0] || '';
|
||
if (s.startsWith('[')) {
|
||
const close = s.indexOf(']');
|
||
return close > 0 ? s.slice(1, close) : s;
|
||
}
|
||
const colons = (s.match(/:/g) || []).length;
|
||
if (colons >= 2) return s;
|
||
return colons === 1 ? s.slice(0, s.indexOf(':')) : s;
|
||
}
|
||
|
||
/**
|
||
* Render one declared argv member for the human consent prompt.
|
||
*
|
||
* A string prints as itself. Anything else prints in a form that makes its
|
||
* presence and shape visible rather than vanishing: an argv member the host
|
||
* still receives, but which the user was never shown, is a surface consented to
|
||
* unseen. Never throws — a circular or BigInt member must not break the prompt.
|
||
*/
|
||
function renderArgForHuman(arg: unknown): string {
|
||
if (typeof arg === 'string') return arg;
|
||
if (typeof arg === 'bigint') return `<${String(arg)}n>`;
|
||
try {
|
||
const json = JSON.stringify(arg);
|
||
return json === undefined ? `<${typeof arg}>` : `<${json}>`;
|
||
} catch {
|
||
return `<${typeof arg}>`;
|
||
}
|
||
}
|
||
|
||
/** `::1`, its expanded forms, and IPv4-mapped loopback (`::ffff:127.0.0.1`). */
|
||
function isLoopbackIpv6(host: string): boolean {
|
||
if (!host.includes(':')) return false;
|
||
if (host === '::1') return true;
|
||
const mapped = /^::ffff:(.+)$/i.exec(host);
|
||
if (mapped) return isLoopbackIpv4(mapped[1]);
|
||
const groups = host.split(':').filter((g) => g !== '');
|
||
if (groups.length === 0) return false;
|
||
return groups.every((g, i) => (i === groups.length - 1 ? /^0*1$/.test(g) : /^0*$/.test(g)));
|
||
}
|
||
|
||
/**
|
||
* 127.0.0.0/8 under inet_aton semantics, which is what a browser, curl and the
|
||
* OS resolver all accept. `127.1`, `2130706433`, `0x7f000001` and `0177.0.0.1`
|
||
* are every bit as loopback as `127.0.0.1`; a disclosure that flags only the
|
||
* dotted-quad form understates a local destination for the other four.
|
||
*/
|
||
function isLoopbackIpv4(host: string): boolean {
|
||
const parts = host.split('.');
|
||
if (parts.length < 1 || parts.length > 4) return false;
|
||
const nums: number[] = [];
|
||
for (const part of parts) {
|
||
let n: number;
|
||
if (/^0[xX][0-9a-fA-F]+$/.test(part)) n = parseInt(part, 16);
|
||
else if (/^0[0-7]+$/.test(part)) n = parseInt(part, 8);
|
||
else if (/^\d+$/.test(part)) n = parseInt(part, 10);
|
||
else return false;
|
||
if (!Number.isFinite(n) || n < 0) return false;
|
||
nums.push(n);
|
||
}
|
||
// inet_aton: the final part absorbs every remaining octet.
|
||
let addr: number;
|
||
if (nums.length === 1) addr = nums[0];
|
||
else if (nums.length === 2) addr = ((nums[0] & 0xff) * 0x1000000) + (nums[1] & 0xffffff);
|
||
else if (nums.length === 3) addr = ((nums[0] & 0xff) * 0x1000000) + ((nums[1] & 0xff) * 0x10000) + (nums[2] & 0xffff);
|
||
else addr = ((nums[0] & 0xff) * 0x1000000) + ((nums[1] & 0xff) * 0x10000) + ((nums[2] & 0xff) * 0x100) + (nums[3] & 0xff);
|
||
if (!Number.isFinite(addr) || addr < 0 || addr > 0xffffffff) return false;
|
||
return Math.floor(addr / 0x1000000) === 127;
|
||
}
|
||
|
||
/**
|
||
* Collect the `hooks` executable-surface class: [{ event, script }] — scripts run as runtime hook
|
||
* commands. Extracted from the former monolithic `discloseExecutableSurfaces` (ADR-2782 #2796,
|
||
* cyclomatic 51 / cognitive 99 / 110 lines / `risk_level: critical`) — BEHAVIOR UNCHANGED, only
|
||
* isolated so it is independently testable and the orchestrator shrinks instead of growing a fourth
|
||
* class inline. `missingArtifacts` is a shared accumulator the orchestrator passes to every collector
|
||
* that can populate it.
|
||
*/
|
||
function collectHookSurfaces(
|
||
manifest: CapabilityManifest,
|
||
stagedDir: string | undefined,
|
||
missingArtifacts: string[],
|
||
): HookSurface[] {
|
||
const hooks: HookSurface[] = [];
|
||
if (Array.isArray(manifest.hooks)) {
|
||
for (const h of manifest.hooks) {
|
||
if (typeof h !== 'object' || h === null) continue;
|
||
const rec = h as Record<string, unknown>;
|
||
const script = asString(rec['script']);
|
||
const event = asString(rec['event']);
|
||
if (script) {
|
||
hooks.push({ event, script });
|
||
if (stagedDir && !artifactExists(stagedDir, script)) {
|
||
missingArtifacts.push(script);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return hooks;
|
||
}
|
||
|
||
/**
|
||
* Collect the `commands` executable-surface class: [{ family, module, router? }] — modules
|
||
* require()'d into the GSD CLI process. Extracted, BEHAVIOR UNCHANGED — see `collectHookSurfaces`.
|
||
*/
|
||
function collectCommandSurfaces(
|
||
manifest: CapabilityManifest,
|
||
stagedDir: string | undefined,
|
||
missingArtifacts: string[],
|
||
): CommandModuleSurface[] {
|
||
const commandModules: CommandModuleSurface[] = [];
|
||
if (Array.isArray(manifest.commands)) {
|
||
for (const c of manifest.commands) {
|
||
if (typeof c !== 'object' || c === null) continue;
|
||
const rec = c as Record<string, unknown>;
|
||
const moduleName = asString(rec['module']);
|
||
const family = asString(rec['family']);
|
||
// TRUST2-3 (#1459): capture the router (which exported fn runs) so retargeting it forces re-consent.
|
||
const router = asString(rec['router']);
|
||
if (moduleName) {
|
||
commandModules.push({ family, module: moduleName, router });
|
||
if (stagedDir && !artifactExists(stagedDir, moduleName)) {
|
||
missingArtifacts.push(moduleName);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return commandModules;
|
||
}
|
||
|
||
/**
|
||
* Collect the `mcpServers` executable-surface class: object map { name: { command, args } } OR
|
||
* array [{ name, command, args }] (or array [{ name, config: { command, args } }]). Captures the
|
||
* COMMAND, not just the name — the command is the executable that actually runs, and consent must
|
||
* disclose it (Codex R1 H1). Extracted, BEHAVIOR UNCHANGED — see `collectHookSurfaces`. Unlike
|
||
* hooks/commands, an MCP server's command is never existence-checked against `stagedDir` (exactly
|
||
* like a reviewer lane's `binary` — see `collectReviewerLaneSurfaces` — it may be any PATH
|
||
* executable, not necessarily a bundle artifact), so this collector takes no `missingArtifacts`
|
||
* accumulator.
|
||
*/
|
||
function collectMcpSurfaces(manifest: CapabilityManifest): McpServerSurface[] {
|
||
const mcpServers: McpServerSurface[] = [];
|
||
if (manifest.mcpServers && typeof manifest.mcpServers === 'object') {
|
||
const pushServer = (name: string, config: unknown): void => {
|
||
if (!name) return;
|
||
const cfg = (typeof config === 'object' && config !== null) ? (config as Record<string, unknown>) : {};
|
||
const command = asString(cfg['command']);
|
||
// TRUST2-4 (#1459): the RAW args array (incl non-string members) is what the host receives, so it
|
||
// is folded — stable-encoded — into the signature. `argv` is the string-filtered view for the
|
||
// human summary; `rawArgs` is the full declared array bound into the signature.
|
||
const rawArgs = Array.isArray(cfg['args']) ? (cfg['args'] as unknown[]) : [];
|
||
const argv = rawArgs.filter((a): a is string => typeof a === 'string');
|
||
// TRUST2-2 (#1459): a non-stdio MCP server ({ type|transport, url, headers }) was previously
|
||
// invisible to the disclosure/signature. Capture the transport TYPE, the URL, and the HEADERS
|
||
// (string→string, prototype-pollution-safe) so a swapped endpoint or header forces re-consent.
|
||
const transport = asString(cfg['type']) || asString(cfg['transport']);
|
||
const url = asString(cfg['url']);
|
||
const headers: Record<string, string> = {};
|
||
const rawHeaders = cfg['headers'];
|
||
if (rawHeaders && typeof rawHeaders === 'object' && !Array.isArray(rawHeaders)) {
|
||
for (const [k, v] of Object.entries(rawHeaders as Record<string, unknown>)) {
|
||
if (k === '__proto__' || k === 'constructor' || k === 'prototype') continue;
|
||
if (typeof v === 'string') headers[k] = v;
|
||
}
|
||
}
|
||
// TRUST-2 (#1459): env can change WHAT a command does without touching command/argv, so it is
|
||
// part of the disclosed (and consent-bound) surface. Filter to string→string entries only —
|
||
// a non-string env value cannot be exported as a real environment variable, and including it
|
||
// would make the signature depend on un-runnable junk. Prototype-pollution-safe: copy only
|
||
// own enumerable string keys, never __proto__/constructor/prototype.
|
||
const env: Record<string, string> = {};
|
||
const rawEnv = cfg['env'];
|
||
if (rawEnv && typeof rawEnv === 'object' && !Array.isArray(rawEnv)) {
|
||
for (const [k, v] of Object.entries(rawEnv as Record<string, unknown>)) {
|
||
if (k === '__proto__' || k === 'constructor' || k === 'prototype') continue;
|
||
if (typeof v === 'string') env[k] = v;
|
||
}
|
||
}
|
||
const cwd = asString(cfg['cwd']);
|
||
// Finding 5 (MEDIUM, #1459): capture the FULL config (every declared field the writer persists),
|
||
// not just the whitelisted ones. Prototype-pollution-safe: copy only own enumerable keys and
|
||
// never the dangerous keys. The CAP_MARKER the writer stamps on persist (`_gsdCapability`) is the
|
||
// capability id (constant per cap), so it does not perturb the signature; we copy config as
|
||
// DECLARED here (pre-stamp) and the writer adds the marker at write time.
|
||
const rawConfig: Record<string, unknown> = {};
|
||
for (const [k, v] of Object.entries(cfg)) {
|
||
if (k === '__proto__' || k === 'constructor' || k === 'prototype') continue;
|
||
rawConfig[k] = v;
|
||
}
|
||
const surface: McpServerSurface = { name, transport, command, argv, rawArgs, url, headers, env, rawConfig };
|
||
if (cwd) surface.cwd = cwd;
|
||
mcpServers.push(surface);
|
||
};
|
||
if (Array.isArray(manifest.mcpServers)) {
|
||
for (const s of manifest.mcpServers) {
|
||
if (typeof s === 'object' && s !== null) {
|
||
const rec = s as Record<string, unknown>;
|
||
pushServer(asString(rec['name']), rec['config'] ?? rec);
|
||
}
|
||
}
|
||
} else {
|
||
for (const [name, config] of Object.entries(manifest.mcpServers as Record<string, unknown>)) {
|
||
pushServer(name, config);
|
||
}
|
||
}
|
||
}
|
||
return mcpServers;
|
||
}
|
||
|
||
/**
|
||
* Collect the reviewer-lane executable-surface class (ADR-2782 D5, #2796): 0 or 1 entries, since a
|
||
* capability manifest carries AT MOST ONE `reviewer` body (Phase 2's validator rejects an array
|
||
* shape outright — matrix C2b). The array return shape matches the other three collectors so
|
||
* `Disclosure`/`disclosureSignature` treat it uniformly (sort-then-fold), even though today it can
|
||
* never hold more than one entry.
|
||
*
|
||
* TOTAL and absent-safe (matrix C1–C5): no `reviewer` key, `reviewer: null`, a non-object body
|
||
* (array/boolean/number), a malformed `invoke`, non-array `flags`, or the whole manifest being a
|
||
* throwing Proxy/getter all degrade to "no lane" rather than throwing — disclosure runs BEFORE
|
||
* Phase 2's validation, on a manifest validation would reject outright.
|
||
*
|
||
* `resolveHost` is optional — supplied by the lifecycle (never the loader, which has no config
|
||
* access) to disclose the REAL destination of an `openai-http` lane to a human at install/upgrade
|
||
* time. Its return value is NEVER folded into `disclosureSignature` (design constraint 2: the
|
||
* signature must stay a pure function of the manifest, or the loader and lifecycle would compute
|
||
* different signatures for the same manifest and produce a permanent false re-consent loop).
|
||
*/
|
||
function collectReviewerLaneSurfaces(
|
||
manifest: CapabilityManifest,
|
||
resolveHost?: ReviewerHostResolver,
|
||
): ReviewerLaneSurface[] {
|
||
return safeCollect(() => {
|
||
const r = manifest.reviewer;
|
||
// C1 (no reviewer key) / C2a (null) / C2b (non-object: array, boolean, number) all disclose no
|
||
// lane — never an error at this layer. Validation of a malformed body is Phase 2's job.
|
||
if (typeof r !== 'object' || r === null || Array.isArray(r)) return [];
|
||
const rec = r as Record<string, unknown>;
|
||
|
||
const slug = asString(rec['slug']);
|
||
const transport = asString(rec['transport']);
|
||
const handler = asString(rec['handler']);
|
||
|
||
// C3: `invoke` absent/malformed still discloses a lane, with empty binary/args/rawArgs rather
|
||
// than crashing — validating `invoke`'s shape is Phase 2's job, not disclosure's.
|
||
const invokeRaw = rec['invoke'];
|
||
const invoke = (typeof invokeRaw === 'object' && invokeRaw !== null && !Array.isArray(invokeRaw))
|
||
? (invokeRaw as Record<string, unknown>)
|
||
: {};
|
||
|
||
const binary = asString(invoke['binary']);
|
||
// B1b: the RAW declared args (may contain non-strings the host still receives) is what the
|
||
// signature binds; `args` is the string-filtered RENDERED view for a human summary — the exact
|
||
// argv/rawArgs split MCP servers already use for the same reason (TRUST2-4, #1459).
|
||
const rawArgsDeclared = Array.isArray(invoke['args']) ? (invoke['args'] as unknown[]) : [];
|
||
const args = rawArgsDeclared.filter((a): a is string => typeof a === 'string');
|
||
const hostConfigKey = asString(invoke['hostConfigKey']);
|
||
const promptChannel = asString(invoke['promptChannel']);
|
||
|
||
// #2483: the declared env pairs. String-filtered for the human line exactly as `args` is, and
|
||
// prototype-safe (own enumerable keys only, dangerous keys never copied) exactly as `rawConfig`
|
||
// is. Disclosure runs BEFORE validation, so a non-object or non-string-valued `env` reaches here
|
||
// and must degrade to "declares none" rather than throw.
|
||
const env: Record<string, string> = {};
|
||
const envRaw = invoke['env'];
|
||
if (typeof envRaw === 'object' && envRaw !== null && !Array.isArray(envRaw)) {
|
||
for (const [k, v] of Object.entries(envRaw as Record<string, unknown>)) {
|
||
if (k === '__proto__' || k === 'constructor' || k === 'prototype') continue;
|
||
if (typeof v === 'string') env[k] = v;
|
||
}
|
||
}
|
||
const defaultHost = asString(invoke['defaultHost']);
|
||
// The completeness backstop (mirrors rawConfig). Everything the invoke object declares that the
|
||
// explicit fields above do not already bind. Same prototype-safe copy.
|
||
const residualInvoke: Record<string, unknown> = {};
|
||
for (const [k, v] of Object.entries(invoke)) {
|
||
if (k === '__proto__' || k === 'constructor' || k === 'prototype') continue;
|
||
if (k === 'binary' || k === 'args' || k === 'hostConfigKey' || k === 'promptChannel') continue;
|
||
residualInvoke[k] = v;
|
||
}
|
||
// The outer half of the same backstop. `probe` is the one that matters most — its `binary` is
|
||
// spawned before dispatch — and the two exclusions below are ADR-2782's deliberate cosmetic
|
||
// carve-outs, not fields nobody got round to.
|
||
const residualLane: Record<string, unknown> = {};
|
||
for (const [k, v] of Object.entries(rec)) {
|
||
if (k === '__proto__' || k === 'constructor' || k === 'prototype') continue;
|
||
if (k === 'slug' || k === 'transport' || k === 'handler' || k === 'invoke') continue;
|
||
if (k === 'reviewsSection' || k === 'timeoutFloorMs') continue;
|
||
residualLane[k] = v;
|
||
}
|
||
const probeRaw = rec['probe'];
|
||
const probeIsObj = typeof probeRaw === 'object' && probeRaw !== null && !Array.isArray(probeRaw);
|
||
const probeBinary = probeIsObj ? asString((probeRaw as Record<string, unknown>)['binary']) : '';
|
||
const probeKind = probeIsObj ? asString((probeRaw as Record<string, unknown>)['kind']) : '';
|
||
|
||
// An EMPTY (or wholly unrecognised) reviewer body declares no lane and must
|
||
// not be treated as one. Without this, `reviewer: {}` alone flips
|
||
// hasExecutable true and perturbs the disclosure signature — producing a
|
||
// re-consent prompt whose only content is "(no binary declared)". That is a
|
||
// prompt carrying no security information, which is exactly the
|
||
// click-through-training harm this design refuses for reviewsSection and
|
||
// timeoutFloorMs; refusing it there and permitting it here would be
|
||
// inconsistent.
|
||
//
|
||
// The test is deliberately BROAD — any one recognised field with a value is
|
||
// enough. Requiring specifically a binary, or specifically a slug, would let
|
||
// a lane declaring only the other slip through unconsented, which is the far
|
||
// worse failure.
|
||
// `env`/`defaultHost` join the test for the reason the comment above gives for keeping it broad:
|
||
// a lane declaring ONLY an `env` pair would otherwise declare "nothing", disclose nothing, and
|
||
// still hand those pairs to a spawned child once #2927/#3062 made overlay lanes executable —
|
||
// the exact slip-through the broad test exists to refuse.
|
||
const declaresSomething = Boolean(
|
||
slug || transport || handler || binary || hostConfigKey || promptChannel
|
||
|| rawArgsDeclared.length > 0 || Object.keys(env).length > 0 || defaultHost || probeBinary,
|
||
);
|
||
if (!declaresSomething) return [];
|
||
|
||
// B2/B3/B4: resolvedHost/isLocalDestination are only meaningful for an openai-http lane — a
|
||
// spawn lane has no destination concept, so both stay at their inapplicable defaults ('' /
|
||
// false), mirroring McpServerSurface's existing empty-when-inapplicable convention (e.g.
|
||
// `url: ''` for a stdio server). For openai-http, resolvedHost never ends up '' — it is either a
|
||
// real resolved value or the explicit UNRESOLVED_HOST_MARKER (never a blank read as "no
|
||
// destination").
|
||
// The shape test is deliberately WIDER than an exact transport match, and the
|
||
// human summary uses the same one. Disclosure runs BEFORE validation, so a
|
||
// mis-cased or unrecognised `transport` reaches here; keying only on the exact
|
||
// string would leave a lane that plainly declares a hostConfigKey with a BLANK
|
||
// destination, which reads as "no destination" — the precise thing B3 forbids.
|
||
const hasHttpShape = transport === 'openai-http' || (!binary && Boolean(hostConfigKey));
|
||
|
||
let resolvedHost = '';
|
||
let isLocalDestination = false;
|
||
if (hasHttpShape) {
|
||
resolvedHost = UNRESOLVED_HOST_MARKER;
|
||
if (typeof resolveHost === 'function') {
|
||
let resolved: string | undefined;
|
||
try {
|
||
resolved = resolveHost(hostConfigKey);
|
||
} catch {
|
||
resolved = undefined;
|
||
}
|
||
if (typeof resolved === 'string' && resolved) resolvedHost = resolved;
|
||
}
|
||
if (resolvedHost !== UNRESOLVED_HOST_MARKER) {
|
||
isLocalDestination = isLocalHostValue(resolvedHost);
|
||
}
|
||
}
|
||
|
||
const surface: ReviewerLaneSurface = {
|
||
slug,
|
||
transport,
|
||
binary,
|
||
args,
|
||
rawArgs: rawArgsDeclared,
|
||
hostConfigKey,
|
||
resolvedHost,
|
||
isLocalDestination,
|
||
promptChannel,
|
||
handler,
|
||
env,
|
||
defaultHost,
|
||
residualInvoke,
|
||
residualLane,
|
||
probeBinary,
|
||
probeKind,
|
||
// B5: every lane receives the same named egress payload classes — a fresh copy per surface so
|
||
// no caller can mutate the shared constant through a returned surface.
|
||
egressPayloadClasses: [...EGRESS_PAYLOAD_CLASSES],
|
||
};
|
||
return [surface];
|
||
}, []);
|
||
}
|
||
|
||
/**
|
||
* The manifest fields whose declared names become instruction surfaces. Ordered data rather than a
|
||
* hand-rolled loop per field, so a future second member of the class is one row, not a second copy
|
||
* of the same filter. Deliberately a ONE-row table today: third-party `agents[]` are never staged
|
||
* into the instruction context — `stageAgentsForRuntimeWithConverter` (`src/install-profiles.cts`)
|
||
* takes only a source directory, with no registry-aware staging path the way
|
||
* `readInstalledCapabilitySkill` gives skills — so disclosing them would name a surface that does
|
||
* not exist. ADR-2363 D3's class table says "skills, agents"; the agents half is therefore
|
||
* deliberately unimplemented pending a maintainer decision.
|
||
*/
|
||
const INSTRUCTION_SURFACE_FIELDS: ReadonlyArray<{ field: string; kind: InstructionSurface['kind'] }> = [
|
||
{ field: 'skills', kind: 'skill' },
|
||
];
|
||
|
||
/**
|
||
* Collect the instruction surfaces a manifest declares (ADR-2363 D5, #3248) — peer to the four
|
||
* executable-surface collectors, and invoked through the same `safeCollect` wrapper so a hostile
|
||
* value here degrades ONLY this class to empty rather than losing the other four.
|
||
*
|
||
* Liberal in what it accepts, exactly like the existing collectors: a non-object manifest, an
|
||
* absent field, a non-array field, and a non-string/blank member each degrade quietly. A non-array
|
||
* `skills` is NOT a partial success — it yields nothing, because a scalar declares no set.
|
||
*
|
||
* Deliberately does NOT:
|
||
* - dedup (a manifest declaring a stem twice discloses it twice — disclosure reports what the
|
||
* manifest SAYS; collapsing would misreport it, and dedup is the registry's job);
|
||
* - normalize or truncate a name (it is disclosed verbatim so the user sees what was declared);
|
||
* - existence-check the stem against `stagedDir`. A stem is a REGISTRY name, not a bundle-relative
|
||
* artifact path — checking it would repeat the reviewer-lane `binary` mistake (matrix C6) and
|
||
* put registry names into `missingArtifacts`, which is for declared bundle FILES only.
|
||
*/
|
||
function collectInstructionSurfaces(manifest: CapabilityManifest): InstructionSurface[] {
|
||
const surfaces: InstructionSurface[] = [];
|
||
if (typeof manifest !== 'object' || manifest === null) return surfaces;
|
||
for (const { field, kind } of INSTRUCTION_SURFACE_FIELDS) {
|
||
const declared = (manifest as Record<string, unknown>)[field];
|
||
if (!Array.isArray(declared)) continue;
|
||
for (const entry of declared) {
|
||
// A non-string or blank member is dropped INDIVIDUALLY — the valid siblings around it still
|
||
// disclose, mirroring how collectHookSurfaces skips a malformed entry rather than the array.
|
||
if (typeof entry !== 'string') continue;
|
||
if (entry.trim() === '') continue;
|
||
surfaces.push({ kind, name: entry });
|
||
}
|
||
}
|
||
return surfaces;
|
||
}
|
||
|
||
/**
|
||
* Enumerate every executable surface a capability manifest declares.
|
||
*
|
||
* Recognizes the FOUR executable surface kinds a capability can ship:
|
||
* - `hooks`: [{ event, script }] — scripts run as runtime hook commands
|
||
* - `commands`: [{ family, module, router? }] — modules require()'d into the CLI process
|
||
* - `mcpServers`: { <name>: {...} } | [{ name }] — servers spawned by the host runtime
|
||
* - `reviewer`: { slug, transport, invoke, ... } — an external reviewer lane (ADR-2782 D5, #2796)
|
||
*
|
||
* plus ONE non-executable class (ADR-2363 D5, #3248):
|
||
* - `skills`: string[] of owned stems — INSTRUCTION surfaces, whose bodies land in the agent's
|
||
* instruction context. Disclosed by name; they never set `hasExecutable` (D3) and never enter
|
||
* `disclosureSignature` (D4). Stems are registry names, so they are never existence-checked
|
||
* against `stagedDir` and never appear in `missingArtifacts`. `agents` is excluded — see the
|
||
* module header.
|
||
*
|
||
* `mcpServers` is not a first-party capability.json field today, but a third-party manifest may
|
||
* declare it, so the trust gate discloses it whenever present (honest disclosure over the
|
||
* narrower first-party schema). Pure: when `stagedDir` is provided, declared hook/command-module
|
||
* files are existence-checked and any missing ones reported, but nothing is mutated. A reviewer
|
||
* lane's `binary` is NEVER existence-checked against `stagedDir` (matrix C6) — like an MCP server's
|
||
* command, it is a PATH lookup on the user's machine, never a bundle artifact; existence-checking it
|
||
* would block every lane install.
|
||
*
|
||
* TOTAL: never throws, for any manifest shape — including a non-object manifest, a Proxy with
|
||
* throwing traps, or a property with a throwing getter (matrix C5, E2). Disclosure runs BEFORE
|
||
* Phase 2's validation, on a manifest validation would reject outright, so it must tolerate what
|
||
* validation does not. Each surface class is collected independently (`safeCollect`) so a hostile
|
||
* value in ONE class degrades only that class to empty rather than losing the others.
|
||
*
|
||
* `resolveHost` (optional, #2796) is forwarded to `collectReviewerLaneSurfaces` so a caller with
|
||
* config access (the lifecycle, never the loader — see `signatureForManifest`) can disclose the REAL
|
||
* destination of an `openai-http` lane. It never affects the returned signature.
|
||
*/
|
||
function discloseExecutableSurfaces(
|
||
manifest: CapabilityManifest,
|
||
stagedDir?: string,
|
||
resolveHost?: ReviewerHostResolver,
|
||
): Disclosure {
|
||
const missingArtifacts: string[] = [];
|
||
const hooks = safeCollect(() => collectHookSurfaces(manifest, stagedDir, missingArtifacts), [] as HookSurface[]);
|
||
const commandModules = safeCollect(
|
||
() => collectCommandSurfaces(manifest, stagedDir, missingArtifacts),
|
||
[] as CommandModuleSurface[],
|
||
);
|
||
const mcpServers = safeCollect(() => collectMcpSurfaces(manifest), [] as McpServerSurface[]);
|
||
const reviewerLanes = safeCollect(
|
||
() => collectReviewerLaneSurfaces(manifest, resolveHost),
|
||
[] as ReviewerLaneSurface[],
|
||
);
|
||
const instructionSurfaces = safeCollect(
|
||
() => collectInstructionSurfaces(manifest),
|
||
[] as InstructionSurface[],
|
||
);
|
||
|
||
// ADR-2363 D3: instruction surfaces are deliberately ABSENT from this expression. Adding them
|
||
// would silently change `executableSetChanged` and the auto-update re-consent trigger.
|
||
const hasExecutable =
|
||
hooks.length > 0 || commandModules.length > 0 || mcpServers.length > 0 || reviewerLanes.length > 0;
|
||
return { hooks, commandModules, mcpServers, reviewerLanes, instructionSurfaces, hasExecutable, missingArtifacts };
|
||
}
|
||
|
||
/**
|
||
* Existence-check a manifest-declared artifact path under stagedDir, refusing to follow it
|
||
* outside the staged root (defense against `../` traversal in a hostile manifest).
|
||
*/
|
||
function artifactExists(stagedDir: string, relPath: string): boolean {
|
||
if (!relPath || path.isAbsolute(relPath) || relPath.split(/[/\\]/).includes('..')) {
|
||
// A traversal/absolute artifact path is treated as "not present" (and is independently
|
||
// rejected by the validator / lifecycle); never resolve it.
|
||
return false;
|
||
}
|
||
try {
|
||
return fs.existsSync(path.join(stagedDir, relPath));
|
||
} catch {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// Namespace reservation
|
||
// ---------------------------------------------------------------------------
|
||
|
||
/**
|
||
* Is `id` in a reserved namespace? Reserved prefixes are first-party/vendor-only so a
|
||
* third-party capability cannot impersonate a first-party one.
|
||
*/
|
||
function checkReservedNamespace(id: unknown): { reserved: boolean; namespace: string | null } {
|
||
if (typeof id !== 'string' || !id) return { reserved: false, namespace: null };
|
||
const lower = id.toLowerCase();
|
||
for (const ns of RESERVED_NAMESPACES) {
|
||
if (lower.startsWith(ns)) return { reserved: true, namespace: ns };
|
||
}
|
||
return { reserved: false, namespace: null };
|
||
}
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// strictKnownRegistries enforcement
|
||
// ---------------------------------------------------------------------------
|
||
|
||
/**
|
||
* Extract the host of a URL-bearing spec for host-based allowlist matching. Returns '' when no
|
||
* host can be parsed (caller treats '' as non-matching).
|
||
*/
|
||
function specHost(parsed: ParsedSpec): string {
|
||
// git specs may be scp-style (git@host:path) or URL-style; tarball/registry are URLs.
|
||
const raw = parsed.target || parsed.raw || '';
|
||
const scp = /^[^@/]+@([^:]+):/.exec(raw);
|
||
if (scp) return scp[1].toLowerCase();
|
||
try {
|
||
return new URL(raw).hostname.toLowerCase();
|
||
} catch {
|
||
return '';
|
||
}
|
||
}
|
||
|
||
/**
|
||
* True if `host` equals an allowlist entry or is a subdomain of it. Host-based, NOT substring:
|
||
* `github.com` matches `github.com` and `api.github.com`, never `evilgithub.com`.
|
||
*/
|
||
function hostMatchesAllowlist(host: string, list: string[]): boolean {
|
||
if (!host) return false;
|
||
for (const entryRaw of list) {
|
||
const entry = typeof entryRaw === 'string' ? entryRaw.trim().toLowerCase() : '';
|
||
if (!entry) continue;
|
||
if (host === entry || host.endsWith('.' + entry)) return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
/**
|
||
* True for a Windows/UNC network path. Matches any two leading slash-or-backslash characters
|
||
* (`\\`, `//`, and the mixed `\/` / `/\` forms Windows also treats as UNC-absolute).
|
||
*/
|
||
function isUncPath(p: string): boolean {
|
||
return /^[\\/]{2}/.test(p);
|
||
}
|
||
|
||
/** Extract the server host of a UNC path (`\\server\share` -> `server`). */
|
||
function uncHost(p: string): string {
|
||
const m = /^[\\/]{2}([^\\/]+)/.exec(p);
|
||
return m ? m[1].toLowerCase() : '';
|
||
}
|
||
|
||
/**
|
||
* Apply the `capabilities.strict_known_registries` policy to a parsed spec.
|
||
*
|
||
* undefined/null -> permissive: external installs allowed (consent gate still applies).
|
||
* [] -> lockdown: all EXTERNAL installs blocked (local-only).
|
||
* non-empty list -> allowlist: only sources whose host matches an entry are allowed.
|
||
* anything else -> FAIL CLOSED: a malformed policy value blocks the install.
|
||
*
|
||
* Local (filesystem) sources are never "external" and are always allowed — EXCEPT a UNC network
|
||
* path (`\\server\share`), which is remote despite parsing as an "absolute"/local-kind spec and is
|
||
* therefore subject to the policy.
|
||
*/
|
||
function evaluateSourceAllowed(parsed: ParsedSpec, strict: StrictKnownRegistries): SourceVerdict {
|
||
const target = parsed.target || parsed.raw || '';
|
||
const unc = parsed.kind === 'local' && isUncPath(target);
|
||
if (parsed.kind === 'local' && !unc) return { allowed: true, reason: null };
|
||
|
||
if (strict === undefined || strict === null) return { allowed: true, reason: null };
|
||
if (!Array.isArray(strict)) {
|
||
// A security policy must never be silently ignored when it is the wrong type (e.g. a
|
||
// string `"[]"` from a hand-edited config). Fail closed.
|
||
return {
|
||
allowed: false,
|
||
reason:
|
||
'capabilities.strict_known_registries must be an array (or null/unset); refusing the install on a malformed policy value',
|
||
};
|
||
}
|
||
|
||
if (strict.length === 0) {
|
||
return {
|
||
allowed: false,
|
||
reason:
|
||
'capabilities.strict_known_registries is [] — all external capability installs are disabled. ' +
|
||
'Install from a local path, or add an allowed host to the list.',
|
||
};
|
||
}
|
||
|
||
// npm specs carry no host; the "registry" is npm itself. Treat the allowlist token "npm" as
|
||
// permitting the npm source kind.
|
||
if (parsed.kind === 'npm') {
|
||
if (strict.some((e) => typeof e === 'string' && e.trim().toLowerCase() === 'npm')) {
|
||
return { allowed: true, reason: null };
|
||
}
|
||
return {
|
||
allowed: false,
|
||
reason: `npm source is not in capabilities.strict_known_registries (add "npm" to allow it)`,
|
||
};
|
||
}
|
||
|
||
const host = unc ? uncHost(target) : specHost(parsed);
|
||
if (hostMatchesAllowlist(host, strict)) return { allowed: true, reason: null };
|
||
return {
|
||
allowed: false,
|
||
reason: `source host "${host || '(unparseable)'}" is not in capabilities.strict_known_registries`,
|
||
};
|
||
}
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// engines.gsd hard gate + compatVersions downgrade
|
||
// ---------------------------------------------------------------------------
|
||
|
||
/**
|
||
* Hard-gate a manifest against the running host version via engines.gsd, consulting
|
||
* compatVersions for a graceful-downgrade target when the current version is incompatible.
|
||
*/
|
||
function checkEngines(manifest: CapabilityManifest, hostVersion: string): EnginesVerdict {
|
||
const engines = manifest.engines;
|
||
let range: string | null = null;
|
||
if (engines && typeof engines === 'object' && !Array.isArray(engines)) {
|
||
const g = (engines as Record<string, unknown>)['gsd'];
|
||
if (typeof g === 'string' && g) range = g;
|
||
}
|
||
|
||
if (!range) return { compatible: true, range: null, satisfiedBy: 'unconstrained' };
|
||
|
||
if (semverMod.semverSatisfies(hostVersion, range)) {
|
||
return { compatible: true, range, satisfiedBy: 'engines' };
|
||
}
|
||
|
||
// Current version is incompatible — look for a compatVersions entry that works, picking the
|
||
// newest such capability version (best graceful downgrade).
|
||
const compat = manifest.compatVersions;
|
||
let best: string | undefined;
|
||
if (compat && typeof compat === 'object' && !Array.isArray(compat)) {
|
||
for (const [capVer, gsdRange] of Object.entries(compat as Record<string, unknown>)) {
|
||
if (typeof gsdRange !== 'string' || !gsdRange) continue;
|
||
if (!semverMod.semverSatisfies(hostVersion, gsdRange)) continue;
|
||
if (best === undefined || semverMod.isSemverNewer(capVer, best)) best = capVer;
|
||
}
|
||
}
|
||
|
||
if (best !== undefined) {
|
||
return { compatible: false, range, satisfiedBy: 'compatVersions', downgradeTo: best };
|
||
}
|
||
return { compatible: false, range, satisfiedBy: null };
|
||
}
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// Composite install verdict
|
||
// ---------------------------------------------------------------------------
|
||
|
||
/**
|
||
* Compose the full install trust verdict: source policy + reserved-namespace + engines gate +
|
||
* executable-surface disclosure. `allowed` is true only when no gate blocks; `requiresConsent`
|
||
* is true when allowed AND the capability ships any executable surface.
|
||
*
|
||
* engines.gsd is also enforced inside resolveCapabilitySource at resolve time; re-checking here
|
||
* is defense-in-depth and lets callers surface a compatVersions downgrade hint.
|
||
*/
|
||
function evaluateInstallTrust(args: InstallTrustArgs): InstallTrustVerdict {
|
||
const { parsed, manifest, stagedDir, strictKnownRegistries, hostVersion, resolveHost } = args;
|
||
const blockReasons: string[] = [];
|
||
|
||
const src = evaluateSourceAllowed(parsed, strictKnownRegistries);
|
||
if (!src.allowed && src.reason) blockReasons.push(src.reason);
|
||
|
||
const ns = checkReservedNamespace(manifest.id);
|
||
if (ns.reserved) {
|
||
blockReasons.push(
|
||
`capability id "${asString(manifest.id)}" uses the reserved namespace "${ns.namespace}" — ` +
|
||
'reserved for first-party capabilities',
|
||
);
|
||
}
|
||
|
||
const engines = checkEngines(manifest, hostVersion);
|
||
if (!engines.compatible) {
|
||
const hint = engines.downgradeTo
|
||
? ` (compatVersions offers ${engines.downgradeTo} for this host)`
|
||
: '';
|
||
blockReasons.push(
|
||
`capability requires engines.gsd "${engines.range}" but host is ${hostVersion}${hint}`,
|
||
);
|
||
}
|
||
|
||
// #2796: resolveHost is optional and, when supplied, discloses the REAL destination of an
|
||
// openai-http reviewer lane to the human at install/upgrade time — it never affects the
|
||
// consent-binding signature (disclosureSignature never reads resolvedHost; design constraint 2).
|
||
const disclosure = discloseExecutableSurfaces(manifest, stagedDir, resolveHost);
|
||
|
||
// A manifest that declares a hook script or command module NOT present in the staged bundle
|
||
// (missing, or escaping the bundle via an absolute/`..` path) is rejected: such an artifact
|
||
// would run from outside the integrity-pinned, reversible install root. Only enforced when a
|
||
// stagedDir was provided to existence-check against.
|
||
if (stagedDir && disclosure.missingArtifacts.length > 0) {
|
||
blockReasons.push(
|
||
`capability declares executable artifacts not present in the staged bundle (or escaping it): ${disclosure.missingArtifacts.join(', ')}`,
|
||
);
|
||
}
|
||
|
||
const allowed = blockReasons.length === 0;
|
||
const requiresConsent = allowed && disclosure.hasExecutable;
|
||
return { allowed, requiresConsent, disclosure, engines, blockReasons };
|
||
}
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// Executable-set change detection (auto-update re-prompt trigger)
|
||
// ---------------------------------------------------------------------------
|
||
|
||
/**
|
||
* Serialize a value to JSON with object keys RECURSIVELY SORTED, so the result is stable under key
|
||
* reordering. Used to fold an MCP server's `env` map into the disclosure signature: ADDING or
|
||
* CHANGING any env entry changes the signature (forces re-consent), but merely REORDERING the keys
|
||
* does NOT (no false re-prompt). TRUST-2 (#1459).
|
||
*
|
||
* TOTAL (#2796, matrix C5c/E2): a value declared inside an unvalidated manifest — e.g. a reviewer
|
||
* lane's `invoke.args` — may contain a BigInt (which `JSON.stringify` throws on) or a circular
|
||
* reference (which unguarded recursion stack-overflows on). Both are handled without throwing:
|
||
* a BigInt renders as its decimal string; a cycle (an object that is its OWN ancestor in the current
|
||
* recursion path — tracked via `seen`, added before recursing into children and removed once fully
|
||
* processed) renders as the literal string `"[Circular]"`. Neither case is reachable for the golden
|
||
* hooks/mods/mcp fixtures this phase's byte-identity tests pin down, so their output is unaffected.
|
||
*
|
||
* KNOWN LIMIT — signature collision on non-JSON numerics (#2796 isolated review, finding E).
|
||
* `NaN`, `Infinity`, `-Infinity` and `undefined` all render as `null` here, inheriting
|
||
* `JSON.stringify`'s own coercion. Two materially different manifests could therefore share a
|
||
* consent signature. This is NOT reachable through any production path: every manifest arrives via
|
||
* `readManifestBounded`'s strict `JSON.parse`, and the JSON grammar has no `NaN`/`Infinity`/
|
||
* `undefined` literal — such input throws before disclosure runs. `0` vs `-0` IS expressible in
|
||
* valid JSON and does collide, but is inert: `String(0) === String(-0)`, so a spawned process
|
||
* receives identical argv either way.
|
||
*
|
||
* Recorded here rather than only in the PR that found it: reachability rests entirely on the ingest
|
||
* path staying `JSON.parse`-only. Anyone who adds a loader that builds a manifest by other means
|
||
* (a JS config file, a deserializer, a test double promoted to production) re-opens this, and needs
|
||
* to see it at the point they would break it.
|
||
*/
|
||
function stableJson(value: unknown, seen?: Set<unknown>): string {
|
||
if (typeof value === 'bigint') return JSON.stringify(`${value.toString()}n`);
|
||
if (value === null || typeof value !== 'object') {
|
||
try {
|
||
return JSON.stringify(value) ?? 'null';
|
||
} catch {
|
||
// A non-object value whose serialization still throws (defensive; JSON.stringify does not
|
||
// throw for any other typeof today, but this keeps the contract TOTAL against future engines).
|
||
return 'null';
|
||
}
|
||
}
|
||
const seenSet = seen ?? new Set<unknown>();
|
||
if (seenSet.has(value)) return '"[Circular]"';
|
||
try {
|
||
seenSet.add(value);
|
||
if (Array.isArray(value)) {
|
||
return `[${value.map((v) => stableJson(v, seenSet)).join(',')}]`;
|
||
}
|
||
const obj = value as Record<string, unknown>;
|
||
const keys = Object.keys(obj).sort();
|
||
return `{${keys.map((k) => `${JSON.stringify(k)}:${stableJson(obj[k], seenSet)}`).join(',')}}`;
|
||
} catch {
|
||
// A Proxy with a throwing trap, or a getter that throws on read — never propagate (matrix C5).
|
||
return '"[unserializable]"';
|
||
} finally {
|
||
seenSet.delete(value);
|
||
}
|
||
}
|
||
|
||
function disclosureSignature(d: Disclosure): string {
|
||
// TRUST2-1 (#1459): build EVERY surface line via stableJson of an ARRAY of its components, so each
|
||
// component is encoded — a `:`-delimited concatenation let a delimiter inside a component (e.g. an
|
||
// mcp name `x:a` vs command `b`) collide with a different decomposition. JSON-encoding every
|
||
// component makes each line an injective function of its components (no delimiter injection).
|
||
const hooks = d.hooks.map((h) => stableJson(['hook', h.event, h.script])).sort();
|
||
// TRUST2-3: include the router (which exported fn runs) so retargeting it forces re-consent.
|
||
const mods = d.commandModules.map((m) => stableJson(['mod', m.family, m.module, m.router || ''])).sort();
|
||
// Include transport + command + RAW args + url + headers + env + cwd + the FULL declared config so a
|
||
// version that:
|
||
// - swaps the stdio executable it runs (command/args), OR
|
||
// - changes the env it runs with (e.g. NODE_OPTIONS=--require evil.js), OR
|
||
// - changes the cwd it runs in, OR
|
||
// - (TRUST2-2) swaps the transport/url/headers of a non-stdio (http/sse) server, OR
|
||
// - (TRUST2-4) changes a NON-STRING arg the host still receives, OR
|
||
// - (finding 5) changes ANY OTHER declared field the writer persists (a future envFile/workingDir/
|
||
// launch option NOT in the explicit whitelist above)
|
||
// is detected as a changed surface (forces re-consent). The explicit fields are kept FIRST for
|
||
// readability/stability; `rawConfig` is the completeness backstop. All are STABLE-encoded (recursively
|
||
// key-sorted JSON) so any add/change forces re-consent while a pure key reorder does NOT (no false
|
||
// re-prompt).
|
||
const mcp = d.mcpServers
|
||
.map((s) =>
|
||
stableJson([
|
||
'mcp',
|
||
s.name,
|
||
s.transport || '',
|
||
s.command,
|
||
s.rawArgs || [],
|
||
s.url || '',
|
||
s.headers || {},
|
||
s.env || {},
|
||
s.cwd || '',
|
||
// Finding 5: the FULL declared config — completeness so any persisted field change re-consents.
|
||
s.rawConfig || {},
|
||
]),
|
||
)
|
||
.sort();
|
||
// ADR-2782 D5 (#2796): fold in slug/transport/binary/rawArgs/hostConfigKey/promptChannel/handler —
|
||
// every field that changes WHAT runs, WHERE it sends data, or WHAT CODE post-processes its output
|
||
// (matrix A3–A9). Deliberately ABSENT from this line: `reviewsSection` and `timeoutFloorMs` (matrix
|
||
// A10/A13 — cosmetic fields; folding them in would force a re-consent prompt that carries no
|
||
// security information, training users to click through) and the RESOLVED host (design constraint
|
||
// 2 — the loader has no config resolver and must compute the SAME signature as the lifecycle, or a
|
||
// resolver-bearing caller and a resolver-less caller would permanently disagree on one manifest's
|
||
// signature).
|
||
// #2483: the eight-field enumeration above was a CLOSED list over an OPEN vocabulary, and it had
|
||
// already fallen behind by EIGHT fields before `env` made the ninth — `defaultHost` (the manifest's
|
||
// OWN fallback egress host), `path` (appended to it to build the URL), `outputChannel`, `outputArg`,
|
||
// `modelArg`, `effortChannel`, `modelDiscovery` and `fallbackModel` all reach `resolveLanePlan` and
|
||
// none was signed. Counted, because the number is easy to state ambiguously: `resolveLanePlan`
|
||
// reads THIRTEEN distinct `inv.*` fields once `env` is included (twelve before this PR added it),
|
||
// of which the pre-#2483 tuple bound four — so eight were unbound before `env`, nine including it.
|
||
// So the fix is not a ninth name: it is a residual, the same completeness backstop `rawConfig` gives
|
||
// the MCP line one screen up (#1459 finding 5). `env`/`defaultHost` are ALSO named explicitly,
|
||
// mirroring that line's deliberate explicit-then-backstop overlap, because they are the two the
|
||
// human summary renders and a reader should be able to find them in the signature by name.
|
||
//
|
||
// APPENDED ONLY WHEN NON-EMPTY, which is D4.5 one level down: a lane declaring nothing beyond the
|
||
// eight already-bound fields keeps a BYTE-IDENTICAL signature, so this cannot re-prompt every
|
||
// consented capability for a field it does not use. A lane that DOES declare one re-consents — which
|
||
// is the correct outcome, not a cost: those fields were executable and undisclosed.
|
||
const lanes = d.reviewerLanes
|
||
.map((l) => {
|
||
const tuple: unknown[] = [
|
||
'lane', l.slug, l.transport, l.binary, l.rawArgs || [], l.hostConfigKey, l.promptChannel, l.handler,
|
||
];
|
||
const extra = {
|
||
env: l.env || {},
|
||
defaultHost: l.defaultHost || '',
|
||
residual: l.residualInvoke || {},
|
||
laneResidual: l.residualLane || {},
|
||
};
|
||
const declaresExtra = Object.keys(extra.env).length > 0
|
||
|| extra.defaultHost !== ''
|
||
|| Object.keys(extra.residual).length > 0
|
||
|| Object.keys(extra.laneResidual).length > 0;
|
||
if (declaresExtra) tuple.push(extra);
|
||
return stableJson(tuple);
|
||
})
|
||
.sort();
|
||
// D4.5 (the highest-consequence line in this phase): the lane element is appended ONLY when at
|
||
// least one lane is declared. A lane-free manifest's signature stays BYTE-IDENTICAL to before this
|
||
// class existed (matrix A1a/A1b/A1c) — appending unconditionally would change every already-
|
||
// installed capability's signature and re-prompt every user for every capability on next upgrade,
|
||
// whether or not they use any reviewer lane at all.
|
||
return lanes.length > 0 ? JSON.stringify([hooks, mods, mcp, lanes]) : JSON.stringify([hooks, mods, mcp]);
|
||
}
|
||
|
||
/**
|
||
* Did the executable surface set change between two versions? Auto-update must re-prompt for
|
||
* consent when it did (the user consented to one set of executable surfaces, not another).
|
||
*/
|
||
function executableSetChanged(oldD: Disclosure, newD: Disclosure): boolean {
|
||
return disclosureSignature(oldD) !== disclosureSignature(newD);
|
||
}
|
||
|
||
/**
|
||
* THE single source of truth for the consent-binding signature of a capability manifest: run
|
||
* `discloseExecutableSurfaces` then `disclosureSignature`. Both the loader (which checks whether a
|
||
* previously-consented project cap still matches) and the lifecycle (which records the consent)
|
||
* compute the binding through THIS helper so they can never drift. `stagedDir` is forwarded for
|
||
* artifact existence-checking; the signature itself is over the executable SET (hooks/mods/mcp incl.
|
||
* env/cwd), not the missingArtifacts list, so it is a stable key regardless of the stagedDir.
|
||
*/
|
||
function signatureForManifest(manifest: CapabilityManifest, stagedDir?: string): string {
|
||
return disclosureSignature(discloseExecutableSurfaces(manifest, stagedDir));
|
||
}
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// Human-readable consent prompt
|
||
// ---------------------------------------------------------------------------
|
||
|
||
/** Max characters of an env VALUE shown in the human consent prompt before it is truncated. */
|
||
const ENV_VALUE_MAX = 60;
|
||
|
||
/**
|
||
* Environment names that turn a declared pair into arbitrary code execution in a spawned child
|
||
* (#2483). This list drives the consent prompt's WARNING line. The capability validator carries its
|
||
* own denylist that REFUSES these names outright (`DENIED_LANE_ENV_KEYS`); the two are deliberately
|
||
* separate layers rather than one, because they answer different questions: the validator refuses a
|
||
* manifest it can reject, and this list makes sure anything that DOES reach a prompt is read loudly.
|
||
* Neither is the boundary — install-time consent is, since no enumeration of execution-primitive
|
||
* names can be complete against an arbitrary third-party child.
|
||
*/
|
||
const EXECUTION_PRIMITIVE_ENV = new Set([
|
||
'NODE_OPTIONS', 'NODE_REPL_EXTERNAL_MODULE', 'LD_PRELOAD', 'LD_AUDIT', 'LD_LIBRARY_PATH',
|
||
'DYLD_INSERT_LIBRARIES', 'DYLD_LIBRARY_PATH', 'PYTHONSTARTUP', 'PYTHONPATH', 'BASH_ENV', 'ENV',
|
||
'PERL5OPT', 'RUBYOPT', 'JAVA_TOOL_OPTIONS', '_JAVA_OPTIONS', 'CLASSPATH', 'NODE_PATH',
|
||
'GIT_SSH_COMMAND', 'GIT_EXTERNAL_DIFF', 'PATH',
|
||
]);
|
||
|
||
/** Truncate a long env value for the human prompt (the full value is still in the signature). */
|
||
function truncateEnvValue(v: string): string {
|
||
if (typeof v !== 'string') return '';
|
||
return v.length > ENV_VALUE_MAX ? `${v.slice(0, ENV_VALUE_MAX)}… (${v.length} chars)` : v;
|
||
}
|
||
|
||
/**
|
||
* Characters that must never reach the consent prompt unescaped. `summarizeDisclosure`'s lines are
|
||
* joined with `\n` and written RAW to stderr on the needs-consent path, and every value in them is
|
||
* attacker-controlled manifest data. A raw newline forges a line indistinguishable from genuine
|
||
* disclosure text; a raw ESC lets a value rewrite or clear lines already printed; a bidi override
|
||
* visually reorders one. C0, DEL, C1, the bidi/isolate controls, and the line/paragraph separators
|
||
* are all escaped to a visible `\uXXXX`, so the value stays identifiable and cannot forge output.
|
||
*/
|
||
const UNSAFE_PROMPT_CHARS = /[\u0000-\u001f\u007f-\u009f\u200e\u200f\u2028\u2029\u202a-\u202e\u2066-\u2069]/g;
|
||
|
||
/** Max characters of any single manifest-supplied value rendered into the consent prompt. */
|
||
const PROMPT_VALUE_MAX = 200;
|
||
|
||
/**
|
||
* Render one manifest-supplied value safely into a consent-prompt line: escape every character that
|
||
* could forge or rewrite output, then bound the length so one oversized value cannot flood the
|
||
* prompt and push the rest off screen. Escaping is IDENTITY for ordinary names, so this changes no
|
||
* existing rendered output for any well-formed manifest — only the disclosure OBJECT is verbatim;
|
||
* the rendered LINE is always escaped.
|
||
*/
|
||
function renderValueForPrompt(v: unknown): string {
|
||
// `String(v)` on an arbitrary `unknown` risks Object's default `[object Object]` stringification
|
||
// (@typescript-eslint/no-base-to-string) for a non-primitive; every call site here passes a string
|
||
// in practice, but the parameter stays `unknown` for the same total-collector discipline as
|
||
// `renderArgForHuman`, so a non-primitive is JSON-stringified instead of coerced.
|
||
let s: string;
|
||
if (typeof v === 'string') {
|
||
s = v;
|
||
} else if (v === null || v === undefined) {
|
||
s = '';
|
||
} else if (typeof v === 'number' || typeof v === 'boolean' || typeof v === 'bigint') {
|
||
s = String(v);
|
||
} else {
|
||
try {
|
||
s = JSON.stringify(v) ?? '';
|
||
} catch {
|
||
s = '';
|
||
}
|
||
}
|
||
const escaped = s.replace(UNSAFE_PROMPT_CHARS, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, '0')}`);
|
||
return escaped.length > PROMPT_VALUE_MAX
|
||
? `${escaped.slice(0, PROMPT_VALUE_MAX)}… (${escaped.length} chars)`
|
||
: escaped;
|
||
}
|
||
|
||
/**
|
||
* Render the instruction-surface section of a consent summary (ADR-2363 D3/D5, #3248).
|
||
*
|
||
* Extracted as its own exported function for two reasons. It is called from BOTH branches of
|
||
* `summarizeDisclosure` — a skill-only capability has `hasExecutable === false` and takes the early
|
||
* return, so a section appended only at the end would never render for exactly the capabilities
|
||
* that need it. And it gives tests a typed surface to assert on, instead of regex-matching prose out
|
||
* of `summarizeDisclosure` (CONTRIBUTING — "Prohibited: Raw Text Matching on Test Outputs").
|
||
*
|
||
* Returns `[]` when nothing is declared, so either caller can append unconditionally without
|
||
* emitting an empty header.
|
||
*
|
||
* TOTAL for a partial disclosure object: the CLI edge calls `summarizeDisclosure(res.disclosure || {})`
|
||
* (`capability-command-router.cjs`), so a bare `{}` — carrying no `instructionSurfaces` at all —
|
||
* reaches this function whenever a lifecycle result has no disclosure.
|
||
*
|
||
* #3248: every manifest-supplied value rendered here (`kind`, `name`) goes through
|
||
* `renderValueForPrompt` first — the CLI edge writes these lines RAW to stderr on the needs-consent
|
||
* path, and an unescaped name could forge a line or rewrite output already printed (see that
|
||
* function's comment).
|
||
*/
|
||
function summarizeInstructionSurfaces(disclosure: Disclosure): string[] {
|
||
const declared = (disclosure as Partial<Disclosure> | null | undefined)?.instructionSurfaces;
|
||
const surfaces = Array.isArray(declared) ? declared : [];
|
||
if (surfaces.length === 0) return [];
|
||
const lines: string[] = [
|
||
` instruction surfaces (${surfaces.length}): installed into your agent's instruction context`,
|
||
];
|
||
for (const s of surfaces) {
|
||
// #3248: kind/name are manifest-supplied — escape+bound before rendering (see `renderValueForPrompt`).
|
||
const kind = s?.kind ? renderValueForPrompt(s.kind) : '(kind?)';
|
||
const name = s?.name ? renderValueForPrompt(s.name) : '(name?)';
|
||
lines.push(` - ${kind}: ${name}`);
|
||
}
|
||
// ADR-2363 D1/D2, and Kerckhoffs: say plainly that nothing inspected these bodies. A summary that
|
||
// named the surface while implying review would be worse than silence — a "looks checked" line
|
||
// displaces the judgement this prompt exists to provoke (Goodhart, D2).
|
||
lines.push(' these bodies are installed verbatim and are NOT content-scanned');
|
||
return lines;
|
||
}
|
||
|
||
/**
|
||
* Render a disclosure as consent-prompt lines. Returned as an array so the CLI/runtime edge can
|
||
* format it; the lib never writes to stdout.
|
||
*
|
||
* #3248: every manifest-supplied value interpolated into a line (hook event/script, command
|
||
* family/module/router, MCP name/transport/url/command/argv/header-keys/env-keys+values/cwd,
|
||
* reviewer-lane slug/hostConfigKey/resolvedHost/defaultHost/binary/rawArgs/handler/probe-binary/
|
||
* env-keys+values, missingArtifacts entries)
|
||
* goes through `renderValueForPrompt` first, which escapes forging/rewriting control characters and
|
||
* bounds the length. These lines are joined with `\n` and written RAW to stderr on the
|
||
* needs-consent path (`capability-command-router.cjs`), so an unescaped value could forge a line or
|
||
* rewrite/clear output already printed — defeating the informed-consent guarantee this function
|
||
* exists to provide. GSD-authored literals (fallback placeholders, headings, `<redacted>`) are never
|
||
* escaped — only manifest-supplied data is.
|
||
*/
|
||
function summarizeDisclosure(disclosure: Disclosure): string[] {
|
||
const lines: string[] = [];
|
||
const instructionLines = summarizeInstructionSurfaces(disclosure);
|
||
if (!disclosure.hasExecutable) {
|
||
// ADR-2363 D3: "declarative only" is true ONLY when there is no instruction surface either.
|
||
// Claiming it unconditionally told a user their capability contributes nothing to weigh while
|
||
// it was contributing agent instructions — the exact category error ADR-2363 was written to end.
|
||
if (instructionLines.length === 0) {
|
||
lines.push('This capability ships no executable surfaces (declarative only).');
|
||
return lines;
|
||
}
|
||
lines.push('This capability ships no executable surfaces, but contributes agent instructions:');
|
||
for (const line of instructionLines) lines.push(line);
|
||
return lines;
|
||
}
|
||
lines.push('This capability ships executable surfaces that will run in your agent runtime:');
|
||
if (disclosure.hooks.length > 0) {
|
||
lines.push(` hooks (${disclosure.hooks.length}): run as runtime hook commands`);
|
||
for (const h of disclosure.hooks) {
|
||
const event = h.event ? renderValueForPrompt(h.event) : '(event?)';
|
||
lines.push(` - ${event} -> ${renderValueForPrompt(h.script)}`);
|
||
}
|
||
}
|
||
if (disclosure.commandModules.length > 0) {
|
||
lines.push(
|
||
` command modules (${disclosure.commandModules.length}): require()'d into the GSD CLI process`,
|
||
);
|
||
for (const m of disclosure.commandModules) {
|
||
// TRUST2-3 (#1459): show the router (which exported fn runs) so the user consents to the exact entry point.
|
||
const routerSuffix = m.router ? ` [router: ${renderValueForPrompt(m.router)}]` : '';
|
||
const family = m.family ? renderValueForPrompt(m.family) : '(family?)';
|
||
lines.push(` - ${family} -> ${renderValueForPrompt(m.module)}${routerSuffix}`);
|
||
}
|
||
}
|
||
if (disclosure.mcpServers.length > 0) {
|
||
lines.push(` MCP servers (${disclosure.mcpServers.length}): spawned/connected by the host runtime`);
|
||
for (const s of disclosure.mcpServers) {
|
||
// TRUST2-2 (#1459): a non-stdio (http/sse) server connects to a URL; disclose the endpoint, not
|
||
// a (nonexistent) command. A stdio server discloses command + args as before.
|
||
const isRemote = (s.transport === 'http' || s.transport === 'sse') || (!s.command && !!s.url);
|
||
const name = renderValueForPrompt(s.name);
|
||
if (isRemote) {
|
||
const t = s.transport ? renderValueForPrompt(s.transport) : 'http';
|
||
const url = s.url ? renderValueForPrompt(s.url) : '(no url declared)';
|
||
lines.push(` - ${name} -> [${t}] ${url}`);
|
||
// Header VALUES are redacted in the human summary (they may carry secrets); only the KEY set
|
||
// is shown. The full values ARE in the signature, so a value change forces re-consent.
|
||
const hdrKeys = s.headers ? Object.keys(s.headers) : [];
|
||
if (hdrKeys.length > 0) {
|
||
lines.push(` headers: ${hdrKeys.map((k) => `${renderValueForPrompt(k)}=<redacted>`).join(', ')}`);
|
||
}
|
||
} else {
|
||
// Command + args are each escaped individually (not the joined string) so a value that
|
||
// embeds a newline cannot forge a line even when it lands mid-argv.
|
||
const cmd = [s.command, ...s.argv].filter(Boolean).map(renderValueForPrompt).join(' ');
|
||
lines.push(` - ${name} -> ${cmd || '(no command declared)'}`);
|
||
}
|
||
// TRUST-2 (#1459): env can change WHAT runs without touching the command, so show each env key
|
||
// and its (truncated) value — the user is consenting to this exact environment. Truncate first
|
||
// (keeps the prompt readable at the existing 60-char bound), then escape the result (#3248) so
|
||
// the truncated value can still not forge or rewrite output.
|
||
const envKeys = s.env ? Object.keys(s.env) : [];
|
||
if (envKeys.length > 0) {
|
||
lines.push(
|
||
` env: ${envKeys
|
||
.map((k) => `${renderValueForPrompt(k)}=${renderValueForPrompt(truncateEnvValue(s.env[k]))}`)
|
||
.join(', ')}`,
|
||
);
|
||
}
|
||
if (s.cwd) lines.push(` cwd: ${renderValueForPrompt(s.cwd)}`);
|
||
}
|
||
}
|
||
if (disclosure.reviewerLanes.length > 0) {
|
||
lines.push(` reviewer lane (${disclosure.reviewerLanes.length}): an external reviewer receives plan/review data on every run`);
|
||
for (const l of disclosure.reviewerLanes) {
|
||
// B1/B2/B3/B4: disclose binary+args for a spawn lane, or hostConfigKey+resolved destination
|
||
// (flagged local when applicable, never omitted as "safe") for an openai-http lane — never
|
||
// curl/the transport name alone, which would be true and useless (design B2).
|
||
// Branch on the DECLARED SHAPE, not on an exact transport string. A lane
|
||
// whose transport is mis-cased or unrecognised still has a hostConfigKey,
|
||
// and falling through to the spawn branch would print "(no binary
|
||
// declared)" for a lane that in fact egresses to a live remote host —
|
||
// understating the disclosure precisely when it matters. Disclosure runs
|
||
// BEFORE validation, so a non-canonical transport does reach this code.
|
||
const slug = l.slug ? renderValueForPrompt(l.slug) : '(slug?)';
|
||
if (l.transport === 'openai-http' || (!l.binary && l.hostConfigKey)) {
|
||
const localTag = l.isLocalDestination ? ' [local]' : '';
|
||
const hostConfigKey = l.hostConfigKey ? renderValueForPrompt(l.hostConfigKey) : '(hostConfigKey?)';
|
||
lines.push(` - ${slug} -> [openai-http] ${hostConfigKey} => ${renderValueForPrompt(l.resolvedHost)}${localTag}`);
|
||
// #2483: the MANIFEST's own fallback host, which `resolveLanePlan` uses whenever the config
|
||
// key resolves to nothing (`configured ?? declaredDefault`). Without this line a lane whose
|
||
// key is unset renders as "(unresolved)" — which reads as "no destination" — while actually
|
||
// shipping the egress payload classes below to an address the manifest chose. That is the
|
||
// understating-the-disclosure failure the branch test one comment up already refuses.
|
||
// Escaped like every other rendered value (#3248): it is manifest-supplied by the same route.
|
||
if (l.defaultHost) {
|
||
lines.push(` fallback destination declared by this capability: ${renderValueForPrompt(l.defaultHost)}`);
|
||
}
|
||
} else {
|
||
// Render the RAW declared args, not the string-filtered view. The raw
|
||
// array is what the host receives and what the consent signature binds,
|
||
// so a non-string member that is invisible here is a surface the user
|
||
// consented to without being shown — the opposite of the disclosure's
|
||
// whole purpose. `renderArgForHuman` stringifies a non-string member; that
|
||
// string is equally attacker-controlled, so it is escaped too (#3248).
|
||
const cmd = [l.binary, ...l.rawArgs.map(renderArgForHuman)]
|
||
.filter(Boolean)
|
||
.map(renderValueForPrompt)
|
||
.join(' ');
|
||
lines.push(` - ${slug} -> ${cmd || '(no binary declared)'}`);
|
||
}
|
||
if (l.handler) lines.push(` handler: ${renderValueForPrompt(l.handler)}`);
|
||
// The probe binary belongs in the prompt beside the dispatch binary when it differs — but the
|
||
// two probe kinds are NOT the same disclosure and must not be rendered as one.
|
||
// `command-capability` SPAWNS `<binary> --help`; `command-exists` only asks `hasBinary`, which
|
||
// scans PATH and spawns nothing. An earlier revision of this line asserted the spawn for both,
|
||
// which is a FALSE statement in a consent prompt — the one place a claim must be exact.
|
||
if (l.probeBinary && l.probeBinary !== l.binary) {
|
||
const probeBinary = renderValueForPrompt(l.probeBinary);
|
||
lines.push(l.probeKind === 'command-capability'
|
||
? ` probes by running: ${probeBinary} --help`
|
||
: ` probes for the presence of: ${probeBinary} (no process is started)`);
|
||
}
|
||
// #2483: identical treatment to the MCP `env` line above, for the identical reason stated
|
||
// there — env changes WHAT runs without touching the command, so the user consents to this
|
||
// exact environment or not at all. The parity is byte-level and deliberate: since #3248 the
|
||
// MCP line escapes BOTH key and value through `renderValueForPrompt`, and a lane's env is
|
||
// manifest-supplied by the same route — so rendering it raw here would reintroduce, on the
|
||
// newer surface, precisely the prompt-forging vector #3248 closed on the older one.
|
||
const laneEnvKeys = l.env ? Object.keys(l.env) : [];
|
||
if (laneEnvKeys.length > 0) {
|
||
lines.push(` env: ${laneEnvKeys
|
||
.map((k) => `${renderValueForPrompt(k)}=${renderValueForPrompt(truncateEnvValue(l.env[k]))}`)
|
||
.join(', ')}`);
|
||
// Names that make an environment pair an EXECUTION primitive rather than configuration.
|
||
// The validator REFUSES these on a reviewer lane (`DENIED_LANE_ENV_KEYS`), so in practice a
|
||
// first-party or freshly-validated manifest never reaches this line. It still earns its
|
||
// place, and the reason is the reason to keep both layers:
|
||
// - Disclosure runs BEFORE validation, and on manifests validation would reject outright.
|
||
// A user consenting to an already-installed or hand-placed capability sees this line
|
||
// whether or not the validator ever ran on it.
|
||
// - No enumeration of execution-primitive names is complete against an arbitrary
|
||
// third-party child, so consent — not either list — is the boundary. A name missing from
|
||
// both costs a quieter line on a value that is still SHOWN, which is the only
|
||
// incompleteness budget an enumeration like this can honestly carry.
|
||
const flagged = laneEnvKeys.filter((k) => EXECUTION_PRIMITIVE_ENV.has(k));
|
||
if (flagged.length > 0) {
|
||
lines.push(` WARNING — ${flagged.map(renderValueForPrompt).join(', ')} can make this lane run code of the capability's choosing`);
|
||
}
|
||
}
|
||
lines.push(` sends: ${l.egressPayloadClasses.join(', ')}`);
|
||
}
|
||
}
|
||
for (const line of instructionLines) lines.push(line);
|
||
if (disclosure.missingArtifacts.length > 0) {
|
||
lines.push(' WARNING — declared artifacts not found in the staged bundle:');
|
||
for (const a of disclosure.missingArtifacts) {
|
||
lines.push(` - ${renderValueForPrompt(a)}`);
|
||
}
|
||
}
|
||
return lines;
|
||
}
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// Exports
|
||
// ---------------------------------------------------------------------------
|
||
|
||
export = {
|
||
RESERVED_NAMESPACES,
|
||
discloseExecutableSurfaces,
|
||
// #2796: the reviewer-lane collector, exported for independent testability (ADR-2782's own
|
||
// argument for extracting per-class collectors rather than growing the switch inline).
|
||
collectReviewerLaneSurfaces,
|
||
// ADR-2363 D5 (#3248): the instruction-surface collector, exported for independent testability —
|
||
// same rationale as `collectReviewerLaneSurfaces` above.
|
||
collectInstructionSurfaces,
|
||
checkReservedNamespace,
|
||
evaluateSourceAllowed,
|
||
checkEngines,
|
||
evaluateInstallTrust,
|
||
executableSetChanged,
|
||
summarizeDisclosure,
|
||
// ADR-2363 D3/D5 (#3248): the instruction-surface section of the consent summary, exported so
|
||
// callers/tests can assert on it directly — see `summarizeInstructionSurfaces`'s own JSDoc.
|
||
summarizeInstructionSurfaces,
|
||
// #3248: the consent-prompt escaping/bounding helper, exported so tests can assert directly that
|
||
// control characters (newline, ESC, bidi overrides, etc.) never reach a rendered prompt line.
|
||
renderValueForPrompt,
|
||
// #1459: the consent-binding signature (single source of truth for loader + lifecycle consent).
|
||
disclosureSignature,
|
||
signatureForManifest,
|
||
// #2796: the non-blank unresolved-host marker and the named egress payload classes, exported so
|
||
// tests can assert exact equality rather than a loose substring match.
|
||
UNRESOLVED_HOST_MARKER,
|
||
EGRESS_PAYLOAD_CLASSES,
|
||
};
|