Skip to content

fix(output): make ref pins shell-literal for agent allow-rules - #5097

Merged
thymikee merged 9 commits into
mainfrom
t3/shell-literal-ref-pins
Nov 25, 2026
Merged

thymikee merged 9 commits into
mainfrom
t3/shell-literal-ref-pins

Conversation

@thymikee

@thymikee thymikee commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Summary

A ref pin this CLI prints is text an agent pastes straight into a shell command, and hosts such as Codex gate those commands with allow-rules whose matchers refuse an unquoted word holding a shell metacharacter. ~ is one, and an EXTENDED_GLOB hazard in zsh. A refused match runs the pasted command in a sandbox that cannot reach the daemon or the device.

The pin is now a plain literal word: @e4-s434592. REF_PIN_SEPARATOR, formatPinnedRef, splitRefGenerationSuffix and splitRecordedRefGenerationSuffix in packages/kernel/src/snapshot.ts own the form; every producer routes through them. The retired ~s spelling is accepted as input only where saved replay scripts and recorded refs are read; live CLI input rejects it. Help text, the skill, website docs, ADR 0014 (amended in place) and CONTEXT.md use the new spelling.

Scope expansion: two readers that split the pin by hand now use the kernel reader, so a token that is only a marker yields no ref body.

Before / after

formatPinnedRef('@e4', 434592) — base @e4~s434592, head @e4-s434592.
splitRefGenerationSuffix('@e4~s3') — base { base: '@e4', generation: 3 }, head null.
splitRecordedRefGenerationSuffix('@e4~s3') — head unchanged from base, so pre-change .ad scripts still replay.

Validation

Head 389c116f86. pnpm install --frozen-lockfile && pnpm build, typecheck, format, lint and check:replay-compat pass. Full vitest --project unit-core: 2144 files, 20975 tests pass. The eager-closure budget test passes: the CLI facade closure stays at 19 modules. No device lane needed — no dispatch, capture or native-execution change.


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

View guided diff Turn on auto-fix

Agents paste the ref pin this CLI prints straight into a command line their
host gates with an allow-rule. The old separator (`@e4~s434592`) is not a
plain literal word: `~` is an EXTENDED_GLOB hazard in zsh and the matchers
reject an unquoted word holding it, so a refused match ran the command
sandboxed, where it cannot reach the daemon. The pin is now `@e4-s434592`.

`REF_PIN_SEPARATOR`, `formatPinnedRef`, `splitRefGenerationSuffix` and
`splitRecordedRefGenerationSuffix` own the form in the kernel. The retired
`~s` spelling is accepted only where saved replay scripts and recorded refs
are read.
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.60 MB 6.59 MB -19.3 kB
Package (unpacked) 6.60 MB 6.58 MB -19.3 kB
Package (download) 2.01 MB 2.01 MB -5.4 kB

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 25.0 ms 21.1 ms -3.9 ms
CLI --help 47.5 ms 47.5 ms -0.0 ms

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed against the latest diff

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread test/output-economy/routine-workflow.ts Resolved
Comment thread packages/kernel/src/snapshot.ts Resolved
Comment thread packages/kernel/src/snapshot.ts Resolved
@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 2 new findings on 38b3082. The verdict and the full list are in the summary comment.

Comment thread packages/kernel/src/snapshot.ts Resolved
@thymikee

Copy link
Copy Markdown
Member Author

At 38b3082, a second pinned ref in the retired form, as in press @e13 @e14~s3, is no longer refused: only @e13 is pressed. This is a regression, so a user's mistake now runs a partial action. The second-ref guard in interaction-touch-targets.ts must refuse any ref-shaped second argument, whatever its separator. Please add a regression test for that input, and restore the deleted warning-routing tests in output-common.test.ts.

These open threads still apply: second-ref guard, deleted warning tests, ADR grammar statement and duplicated ref pattern (not blocking). 11 lower-priority threads also still apply. This thread does not apply and can be resolved, because the current sample mapping and ref pattern already handle the -s form.

Not blocking: take or leave these two notes: replay could strip the retired form from every ref argument, comma-sequence members included, once at the parse boundary, since press @e13~s5,@e14~s5 and is visible @e3~s4 pass through unstripped to parsers that now reject ~s, and the live ~s refusal could be named as a release-note line in the PR body, with the Invalid ref scope error from snapshot --scope (capture path) carrying REF_GRAMMAR_HINT.

Could kernel/snapshot.ts export one pinned-ref pattern and one "looks like a ref" check, shared by the second-ref guard, output/error.ts, kernel/errors.ts, tool-ref-pins.ts and the help validator, with replay stripping recorded pins in one place instead of per command? That would stop these grammar copies from drifting apart again.

All 22 checks pass at 38b3082. Not verified here: local runs of the tests and check:replay-compat, and whether earlier sessions actually saved .ad lines with ~s in comma sequences or in other commands such as is.

Before merge, the second-ref guard needs the fix and its regression test, and the warning-routing tests need to be restored.

…arry it

The second-key guard on press and click matched only the current separator, so
`press @E13 @E14~s3` pressed one key and folded the other into a fallback label.
The kernel now classifies a ref token (`isRefToken`) and names the fix for a
retired pin (`retiredRefPinRefusal`); the touch-target, ref-positional and
gesture entry points use them instead of restating the grammar.
Publication dropped a token such as `@-s3` before comparing it with the
capture, so a malformed projection entry vanished and the rest still published.
It now stays in the set and fails the projection check.
…pinned-ref spellings

output-common.test.ts had lost the appendWarningLinesText, routeResponseWarnings
and collapseWarningText cases, including the #2682 stderr-routing and
jsonData-preservation ones. The two modules that must spell the kernel's pin
grammar themselves (output-common.ts and output/error.ts) now each carry a test
that binds their spelling to the kernel writer, and the ambiguity-candidate
prefix no longer duplicates the grammar a second time in code. Tests build pins
with formatPinnedRef, negative assertions match both separators, and the
help-conformance pseudo-ref check reads a pin through the kernel parser.
@thymikee

Copy link
Copy Markdown
Member Author

Pushed bc2d80d. The second-key guard now classifies through the kernel owner (isRefToken), so press @e13 @e14 , @e14-s3 and @e14~s3 all refuse — the retired one with a typed error that names -s and the exact @e14-s3 fix — instead of pressing one key and folding the other into a fallback label (0b3257f, with regression tests for the second key, the acted ref, and a comma-plan member). The deleted warning-routing tests are restored from main in b682c6d, and pnpm typecheck, pnpm format, pnpm check:replay-compat and the output-economy project are clean on the pushed head.

Comment thread packages/kernel/src/snapshot.ts Fixed
…udgets

A pattern that matched a ref-shaped token re-scanned its own digit run, so a long
pinned token cost quadratic time on command input. The classifier now reuses the
split readers and one anchored plain-ref test, with a long-token case that must
finish fast. The retired-pin hint stays module-private, and the space-separated
second-key refusal moves out of parseTouchTarget, clearing the Fallow unused-export
and cognitive-complexity findings the guards report.
@thymikee

Copy link
Copy Markdown
Member Author

Head is now 33c638d.

Both review points are in: the second-key guard classifies through the kernel owner (isRefToken), so press @e13 @e14, @e14-s3 and @e14~s3 all refuse — the retired one with a typed error naming -s and the exact @e14-s3 fix — and press @e13 @e14~s3 has its own regression test (0b3257f). The warning-routing tests in packages/command-output/src/output-common.test.ts are restored from main in b682c6d (12 cases, including the #2682 stderr-routing and jsonData-preservation ones).

Also fixed on the failing gate: the ref-token classifier no longer carries a pattern that re-scanned its own digit run (CodeQL polynomial-regex alert), now linear with a long adversarial-token test, and the two Fallow findings it reported (unused export, parseTouchTarget cognitive complexity) are cleared — pnpm check:fallow is clean locally. 16 of the 16 review threads are replied to and resolved.

@apex-sentinel-staging

This comment has been minimized.

@thymikee

Copy link
Copy Markdown
Member Author

The code at 33c638d is ready. Not blocking, take it or leave it: the CANDIDATE_REF_PREFIX comment still names readPinnedRefPrefix, which no longer exists, so it could point to splitRefGenerationSuffix/formatPinnedRef or drop the name.

The two problems from the earlier review are fixed: a second ref in the retired form is refused again, with a regression test, and the warning tests are back. These threads no longer apply and can be resolved:

  • Thread: the ref patterns are now anchored and linear, with a long-input test.
  • Thread: the guard now refuses @e14~s3.
  • Thread: all warning tests from the main branch are present and unchanged.
  • Thread: the ADR now says the separator change is not behavior-compatible.
  • Thread: the help validator now reads refs through splitRefGenerationSuffix.

The second-argument guard of press/click now also refuses bare e14, e14-s3 and @e12-sales, which were read as fallback label text before. This is not treated as a regression, because these look like mistyped refs and refusing them is the safer result.

The Runner Build (tvOS + visionOS + watchOS) job failed, likely for an unrelated reason: its build steps passed, the failure came in the post-build teardown steps, and this PR changes no Swift, Xcode project, runner or workflow files. The other unit and check jobs pass. Not verified here: local test runs and the log of the failed job.

Before merge, rerun that job and confirm that it passes.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 25, 2026
… comment

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 4446a8a

Since the review of 33c638d: 0 new · 0 still open · 0 no longer raised

No open findings.

Not in the reviewers' prompt (1 file)
  • packages/command-surface/src/capture/snapshot.ts: its very long or mostly numeric lines were cut; reviewers could still search them

Reviewed with this repository's own Sentinel configuration (1c96b454527d).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

@thymikee thymikee removed the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 25, 2026
@thymikee

Copy link
Copy Markdown
Member Author

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 25, 2026
@thymikee
thymikee merged commit 36d95cc into main Nov 25, 2026
22 of 23 checks passed
@thymikee
thymikee deleted the t3/shell-literal-ref-pins branch November 25, 2026 12:08
@thymikee

Copy link
Copy Markdown
Member Author

Follow-up tracking for the #5097 port to 0.22: include the public SDK formatter from #5124 in the same port. Keeping only the 0.22 side of the overlapping files would silently omit it while the branch's exact export-list test could still pass.

The port needs all four boundaries:

  • src/sdk/index.ts: re-export the canonical formatPinnedRef (or the corresponding public SDK owner after the 0.22 reorganization).
  • src/sdk/index.test.ts: retain the public-export and parser-roundtrip regression.
  • test/integration/installed-package-metro.test.ts: add the name to the exact root export list and invoke it through the installed package.
  • website/docs/docs/client-api.md: retain the API entry, version availability guidance, example, and ref-frame lifetime warning.

Validate the built/installed public API against the 0.22 grammar rather than copying a separator. This is an added export, so it does not need a migration-table row. No forward-port is claimed complete by this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants