Skip to content

fix(javascript): report Hermes bytecode bundles as unanalyzed application logic - #15135

Draft
lennartorlando wants to merge 2 commits into
morluto:mainfrom
lennartorlando:fix/hermes-bytecode-coverage
Draft

lennartorlando wants to merge 2 commits into
morluto:mainfrom
lennartorlando:fix/hermes-bytecode-coverage

Conversation

@lennartorlando

Copy link
Copy Markdown

Summary

analyze_javascript_application skipped a React Native main.jsbundle and still reported complete coverage; a Hermes bytecode bundle was invisible under any name. A follow-up keeps Hermes bundles as JavaScript components in the Apple, Android and Harmony application projections. No issue is linked: this was found while testing REA v6.10.1 against real macOS, iOS-on-Mac and Electron apps.

Problem and expected behavior

Trigger: a React Native app whose bundle is main.jsbundle (text or Hermes bytecode). The lane selected files by source suffix only, so the file was neither read nor counted. Expected: Hermes bytecode is recognized by its 8-byte magic and reported as unanalyzed application logic with partial coverage; a plain-text .jsbundle is parsed as JavaScript.

Change and scope

  • The shared artifact format recognizer records hermes-bytecode (src/domain/artifactFormatRecognition.ts, src/domain/javascript/hermesBytecode.ts); the JavaScript lane takes that inventory fact before the path suffix. Bytes are digest-verified, never decoded; node Evidence and graph coverage are partial and a limitation names the file. REA does not decompile or disassemble Hermes bytecode.
  • .jsbundle joins the JavaScript source suffixes.
  • One shared predicate (src/domain/javascript/javascriptApplicationFormats.ts) classifies JavaScript application components for the Apple, Android and Harmony projections, so a Hermes file no longer drops out of components.javascript (and Apple keeps the JavaScript runtime family and bridge candidates).
    Contribution scope: ordinary fix; no protection recovery or bytecode decoding added.

Contract and boundary impact

  • Semantic owner and earliest changed stage: the format recognizer table; the JavaScript lane and the three application projections consume its fact.

  • Contribution scope fit and linked maintainer decision: not applicable.

  • CLI and MCP/tool-catalog contract: new artifact_format value hermes-bytecode; coverage becomes partial where it was falsely complete.

  • Provider, bridge, target-format, or platform compatibility: new target format vocabulary entry.

  • Evidence, artifact, provenance, or reconstruction contract: Hermes files are listed with digests and an explicit limitation; listing claims no analysis of their logic.

  • Target selection, authority, upstream behavior, and cleanup details: not applicable.

  • Generated metadata, package, or installation impact: generated catalog picks up the format value (validated by docs:check).

  • Read existing files or captured data.

Evidence and regression coverage

  • Tests added or updated: tests/boundary/filesystem/javascriptHermesBytecodeCoverage.test.ts, tests/boundary/filesystem/hermesApplicationProjections.test.ts, src/domain/artifactFormatRecognition.test.ts, src/application/binary/TargetFormatVocabularies.test.ts.

  • Base reproduction or other evidence: not reproduced at behavior level; the new boundary tests import the new hermesBytecode helper, so on origin/main they fail at module load.

  • User-visible CLI/MCP output: rea analyze-javascript-application /Applications/Readwise.app/Wrapper/Readwise.app --json (Expo/React Native, main.jsbundle with Hermes magic, version 96): before the fix application coverage was complete with no Hermes limitation; after it, coverage is partial with a limitation (also under unknowns) naming main.jsbundle as Hermes bytecode that was not analyzed (about 1.3 s, 343 MB peak). Apple projection of the same app: components.javascript grows from the two extension Action.js files to also include main.jsbundle as hermes-bytecode, and bridge candidates grow from 22 to 33.

  • Remaining proof gaps: Android and Harmony projections are covered by synthetic APK/HAP fixtures only.

  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run check:fast: passed.
  • npm run test:local -- src/application/binary/TargetFormatVocabularies.test.ts src/domain/artifactFormatRecognition.test.ts src/domain/apple/appleApplication.test.ts src/application/javascript/JavaScriptArtifactGraphStructure.test.ts src/application/javascript/JavaScriptArtifactGraphAccumulator.test.ts src/domain/javascript/javascriptSourceParser.test.ts src/domain/javascript/javascriptSourceParserContext.test.ts: 7 files, 338 passed.
  • npm run test:focused -- tests/boundary/filesystem/hermesApplicationProjections.test.ts tests/boundary/filesystem/javascriptHermesBytecodeCoverage.test.ts: 2 files, 5 passed.
  • npm run docs:check: passed.

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable.
  • Package or release metadata impact: generated catalog format list.
  • Security, privacy, process, or containment review: bytecode is never executed or decoded.

Author readiness

Human owner: @lennartorlando

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Author checklist (completed by the PR author before requesting review)

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.
  • I ran every test, build, or measurement needed to validate this change, reported a browser, GPU, or environment gap only when that runtime or hardware is unavailable, and reported the checks I ran and their results without presenting inferred correctness or speedups as measured.
  • Comments explain constraints or non-obvious decisions; task history and conversations stay out of code and docs.
  • Documentation is concise and factual, without punchy slogans or promotional language.
  • This change fixes the root cause and follows the engineering rules in AGENTS.md.
  • Formatted input is interpreted once at the owning boundary, and consumers use the owner's parsed facts. See Interpret boundary facts once.
  • Combined failures preserve partial observations, remaining resources, and cleanup facts. See Own the lifecycle.
  • A hardcoded limit is an REA_ runtime setting with a default, floor, and maximum, unless a fixed ceiling has a stated reason. See Adding a runtime setting.

🤖 Generated with Claude Code

lennartorlando and others added 2 commits November 29, 2026 22:04
…tion logic

analyze_javascript_application skipped a React Native main.jsbundle and
still reported complete coverage. The lane selected files by source suffix
only, so .jsbundle was neither read nor counted, and a Hermes bytecode
bundle under any name was invisible to coverage.

Recognize Hermes bytecode in the shared artifact format recognizer table by
its eight-byte magic, so inventory records artifact_format hermes-bytecode
under any file name. The JavaScript lane takes that inventory fact before
the path suffix: the file becomes a hermes-bytecode relevant file whose
bytes are verified but never decoded, its node evidence is partial, the
graph coverage is partial, and a limitation names the file. REA does not
decompile or disassemble Hermes bytecode.

.jsbundle joins the JavaScript source suffixes with JavaScript grammar, so a
plain-text React Native bundle is parsed like any other JS bundle.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ion projections

Since inventory records Hermes bytecode as hermes-bytecode, the Apple,
Android and Harmony projections, which each accepted only
javascript-bundle, dropped a Hermes bundle from components.javascript.
Apple also lost the JavaScript runtime family and the JavaScript/native
bridge candidates. A Hermes file named main.js regressed against the
parent, where its suffix had supplied javascript-bundle.

Classify JavaScript application components through one shared domain
predicate covering javascript-bundle and hermes-bytecode. Components keep
their precise format; listing one claims no analysis of its logic.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@greptile-apps

greptile-apps Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5 · Fix the .asar traversal failure and satisfy the independent-fixture testing requirement before merging.RetriggerView in GreptileConfidence Score: 4/5 Tier: plus

[Medium impact] The changes affect JavaScript analysis and mobile application projections.

Fix the .asar traversal failure and satisfy the independent-fixture testing requirement before merging.

Findings

  1. P1 `.asar` bundles abort analysis ▶
  2. P2 Tests reuse the production signature ▶
Fix with agent prompt
### Issue 1
src/artifacts/javascript/JavaScriptArtifactFiles.ts:471
A filesystem Hermes bundle named `assets/main.asar` is now added to the expected files, but `visitReader` still follows the `.asar` suffix first. It skips the entry because its inventory format is not `asar`. `assertExpectedFilesWereVisited` then reports that the file disappeared, aborting the directory analysis instead of returning partial coverage.

Choose archive traversal from the inventory format, or let non-ASAR entries reach normal file reading. Add a misleading-suffix regression.

### Issue 2
src/domain/artifactFormatRecognition.test.ts:412-415
The recognition test builds its input from `HERMES_BYTECODE_MAGIC`, the same constant that `hasHermesBytecodeHeader` uses to match it. Both new boundary fixtures do this too. A wrong byte or byte order would keep every new test green while real bundles go unrecognized.

The repository's testing guide requires expectations independent of the implementation. Add at least one fixture with independently specified Hermes header bytes before merging.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Recognizes Hermes bundles from their header, retains them as unanalyzed application logic, and parses plain-text .jsbundle files as JavaScript.

  • JavaScript analysis parses text bundles and marks Hermes bytecode as unanalyzed.
  • Apple, Android, and Harmony projections keep Hermes bundles in their JavaScript components.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Artifact inventory] --> B{Hermes header?}
  B -->|Yes| C[hermes-bytecode]
  B -->|No, .jsbundle| D[JavaScript text]
  C --> E[Verify bytes without decoding]
  E --> F[Partial application coverage]
  C --> G[Apple, Android, Harmony components]
  D --> H[Static JavaScript analysis]
  C --> I{Filesystem .asar name?}
  I -->|Yes| J[Archive branch skips file]
  J --> K[Expected-file check fails]
Loading

Reviews (1) · Last reviewed commit: "fix(mobile): keep Hermes bundles as Java..." · Reviewed by Greptile

occurrence.entry_kind === "file" &&
occurrence.logical_path.toLowerCase().endsWith(".asar");
const kind = relevantKind(occurrence.logical_path);
const kind = relevantOccurrenceKind(occurrence);

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.

P1 .asar bundles abort analysis

A filesystem Hermes bundle named assets/main.asar is now added to the expected files, but visitReader still follows the .asar suffix first. It skips the entry because its inventory format is not asar. assertExpectedFilesWereVisited then reports that the file disappeared, aborting the directory analysis instead of returning partial coverage.

Choose archive traversal from the inventory format, or let non-ASAR entries reach normal file reading. Add a misleading-suffix regression.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/artifacts/javascript/JavaScriptArtifactFiles.ts
Line: 471

Comment:
**`.asar` bundles abort analysis**

A filesystem Hermes bundle named `assets/main.asar` is now added to the expected files, but `visitReader` still follows the `.asar` suffix first. It skips the entry because its inventory format is not `asar`. `assertExpectedFilesWereVisited` then reports that the file disappeared, aborting the directory analysis instead of returning partial coverage.

Choose archive traversal from the inventory format, or let non-ASAR entries reach normal file reading. Add a misleading-suffix regression.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Comment on lines +412 to +415
const hermes = Buffer.concat([
HERMES_BYTECODE_MAGIC,
Buffer.from([0x60, 0, 0, 0]),
]);

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.

P2 Tests reuse the production signature

The recognition test builds its input from HERMES_BYTECODE_MAGIC, the same constant that hasHermesBytecodeHeader uses to match it. Both new boundary fixtures do this too. A wrong byte or byte order would keep every new test green while real bundles go unrecognized.

The repository's testing guide requires expectations independent of the implementation. Add at least one fixture with independently specified Hermes header bytes before merging.

Context Used: AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/artifactFormatRecognition.test.ts
Line: 412-415

Comment:
**Tests reuse the production signature**

The recognition test builds its input from `HERMES_BYTECODE_MAGIC`, the same constant that `hasHermesBytecodeHeader` uses to match it. Both new boundary fixtures do this too. A wrong byte or byte order would keep every new test green while real bundles go unrecognized.

The repository's testing guide requires expectations independent of the implementation. Add at least one fixture with independently specified Hermes header bytes before merging.

**Context Used:** AGENTS.md ([source](https://github.com/morluto/rea/blob/main/AGENTS.md))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant