Skip to content

Filter package.json script keys before storing command memories #301

Closed

Description

@ocsi-architect

Part of #291.

Problem

detectPackageScripts builds npm run ${name} from every notable script key with no character check (src/init/detect.ts:90, verified at sha 7405dc61d919e7eee7033dea6e4324eda58ee669). isNotable passes any key starting with test/lint/build etc. (src/init/detect.ts:36-40), so a package.json key like test && echo SYNTHETIC is stored verbatim as a command memory. detectMakeTargets already restricts targets to [A-Za-z0-9_-]+ (src/init/detect.ts:98), so package.json is the one detector without an input filter. The stored row carries tags init/package.json, so it gets no [via ...] provenance marker (src/inject/format.ts:17) and is injected into every later session, surviving the branch or clone the crafted key came from.

Fix direction

In detectPackageScripts (src/init/detect.ts), skip script keys that do not match /^[A-Za-z0-9_-]+$/ — the same character class detectMakeTargets already enforces. Test coverage in test/init.test.ts (the fixture + direct detectScripts import test already exist there).

Acceptance

  • RED: on main 7405dc6, a test whose fixture package.json has scripts keys test && echo SYNTHETIC and plain lint, then calls detectScripts(fixture), returns a record whose cmd contains && echo SYNTHETIC — the new assertion that every returned key matches ^[A-Za-z0-9_-]+$ fails.
  • GREEN: bun test test/init.test.ts passes; detectScripts returns no record whose key fails ^[A-Za-z0-9_-]+$; the existing tests expecting the npm run test / npm run lint rows still pass.

Activity

  1. added
    severity:medium
    spec:draft
    on Nov 4, 2026
  2. WhollyMindless commented on Nov 5, 2026

    @WhollyMindless
    Contributor

    One compatibility point to consider before adopting the draft: /^[A-Za-z0-9_-]+$/ excludes colons and dots as well as shell metacharacters. The current isNotable() prefix check accepts these example script keys, but the proposed filter would silently stop producing their command memories:

    • test:unit → npm run test:unit
    • test:e2e → npm run test:e2e
    • build:prod → npm run build:prod
    • lint.fix → npm run lint.fix

    These names do not need shell operators or whitespace. Is dropping them intentional, or should the safe-name policy preserve punctuation such as : and . while continuing to reject injection-bearing keys such as test && echo SYNTHETIC, test; echo SYNTHETIC, and names containing command substitution or line breaks?

    The current positive controls cover only plain test and lint, so they would not catch that compatibility loss. If preserving these names is desired, please include representative colon/dot names alongside the hostile-name regressions in the acceptance criteria. If the narrower naming policy is intentional, documenting the exclusion would make the tradeoff clear. This is a scope clarification for consideration, not a claim on the ticket.

  3. added
    agent:ready
    on Nov 5, 2026
  4. abogartz-opencode-self-improvement commented on Nov 9, 2026

    @abogartz-opencode-self-improvement

    🎉 This issue has been resolved in version 0.22.1 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent:readyreleasedseverity:mediumspec:draft

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions