litclaude-ai 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/CHANGELOG.md +155 -0
  2. package/LICENSE +21 -0
  3. package/README.md +369 -0
  4. package/README_ko-KR.md +374 -0
  5. package/RELEASE_CHECKLIST.md +165 -0
  6. package/bin/litclaude-ai.js +643 -0
  7. package/cover.png +0 -0
  8. package/docs/agents.md +67 -0
  9. package/docs/hooks.md +134 -0
  10. package/docs/lsp.md +40 -0
  11. package/docs/migration.md +209 -0
  12. package/docs/workflow-compatibility-audit.md +119 -0
  13. package/generate_cover.py +123 -0
  14. package/package.json +48 -0
  15. package/plugins/litclaude/.claude-plugin/plugin.json +25 -0
  16. package/plugins/litclaude/.lsp.json +13 -0
  17. package/plugins/litclaude/.mcp.json +9 -0
  18. package/plugins/litclaude/agents/boulder-executor.md +12 -0
  19. package/plugins/litclaude/agents/librarian-researcher.md +15 -0
  20. package/plugins/litclaude/agents/oracle-verifier.md +16 -0
  21. package/plugins/litclaude/agents/prometheus-planner.md +13 -0
  22. package/plugins/litclaude/agents/qa-runner.md +16 -0
  23. package/plugins/litclaude/agents/quality-reviewer.md +17 -0
  24. package/plugins/litclaude/bin/litclaude-hook.js +110 -0
  25. package/plugins/litclaude/bin/litclaude-hud.js +271 -0
  26. package/plugins/litclaude/bin/litclaude-lsp-doctor.js +15 -0
  27. package/plugins/litclaude/bin/litclaude-mcp.js +70 -0
  28. package/plugins/litclaude/commands/deep-interview.md +21 -0
  29. package/plugins/litclaude/commands/dynamic-workflow.md +36 -0
  30. package/plugins/litclaude/commands/lit-loop.md +40 -0
  31. package/plugins/litclaude/commands/lit-plan.md +35 -0
  32. package/plugins/litclaude/commands/litgoal.md +30 -0
  33. package/plugins/litclaude/commands/review-work.md +35 -0
  34. package/plugins/litclaude/commands/start-work.md +36 -0
  35. package/plugins/litclaude/hooks/hooks.json +54 -0
  36. package/plugins/litclaude/lib/context-pressure.mjs +25 -0
  37. package/plugins/litclaude/lib/hud-accent-palette.mjs +58 -0
  38. package/plugins/litclaude/lib/litgoal/cli.mjs +266 -0
  39. package/plugins/litclaude/lib/litgoal/ledger.mjs +16 -0
  40. package/plugins/litclaude/lib/litgoal/paths.mjs +7 -0
  41. package/plugins/litclaude/lib/litgoal/state.mjs +67 -0
  42. package/plugins/litclaude/lib/mutated-file-paths.mjs +63 -0
  43. package/plugins/litclaude/lib/start-work-continuation.mjs +99 -0
  44. package/plugins/litclaude/lib/workflow-check.mjs +83 -0
  45. package/plugins/litclaude/skills/ai-slop-remover/SKILL.md +142 -0
  46. package/plugins/litclaude/skills/comment-checker/SKILL.md +55 -0
  47. package/plugins/litclaude/skills/debugging/SKILL.md +70 -0
  48. package/plugins/litclaude/skills/debugging/references/methodology/00-setup.md +108 -0
  49. package/plugins/litclaude/skills/debugging/references/methodology/02-investigate.md +126 -0
  50. package/plugins/litclaude/skills/debugging/references/methodology/04-oracle-triple.md +106 -0
  51. package/plugins/litclaude/skills/debugging/references/methodology/05-escalate.md +69 -0
  52. package/plugins/litclaude/skills/debugging/references/methodology/06-fix.md +116 -0
  53. package/plugins/litclaude/skills/debugging/references/methodology/08-qa.md +94 -0
  54. package/plugins/litclaude/skills/debugging/references/methodology/09-cleanup.md +164 -0
  55. package/plugins/litclaude/skills/debugging/references/methodology/partial-runtime-evidence.md +228 -0
  56. package/plugins/litclaude/skills/debugging/references/runtimes/bundled-js-binary.md +415 -0
  57. package/plugins/litclaude/skills/debugging/references/runtimes/go.md +252 -0
  58. package/plugins/litclaude/skills/debugging/references/runtimes/native-binary.md +484 -0
  59. package/plugins/litclaude/skills/debugging/references/runtimes/node.md +260 -0
  60. package/plugins/litclaude/skills/debugging/references/runtimes/python.md +248 -0
  61. package/plugins/litclaude/skills/debugging/references/runtimes/rust.md +234 -0
  62. package/plugins/litclaude/skills/debugging/references/tools/ghidra.md +212 -0
  63. package/plugins/litclaude/skills/debugging/references/tools/playwright-cli.md +194 -0
  64. package/plugins/litclaude/skills/debugging/references/tools/pwndbg.md +263 -0
  65. package/plugins/litclaude/skills/debugging/references/tools/pwntools.md +265 -0
  66. package/plugins/litclaude/skills/deep-interview/SKILL.md +323 -0
  67. package/plugins/litclaude/skills/deep-interview/scripts/render_progress.py +193 -0
  68. package/plugins/litclaude/skills/frontend-ui-ux/SKILL.md +62 -0
  69. package/plugins/litclaude/skills/lit-loop/SKILL.md +144 -0
  70. package/plugins/litclaude/skills/lit-plan/SKILL.md +125 -0
  71. package/plugins/litclaude/skills/litgoal/SKILL.md +219 -0
  72. package/plugins/litclaude/skills/lsp/SKILL.md +63 -0
  73. package/plugins/litclaude/skills/programming/SKILL.md +106 -0
  74. package/plugins/litclaude/skills/programming/references/go/README.md +90 -0
  75. package/plugins/litclaude/skills/programming/references/go/backend-stack.md +641 -0
  76. package/plugins/litclaude/skills/programming/references/go/bootstrap.md +328 -0
  77. package/plugins/litclaude/skills/programming/references/go/bubbletea-v2.md +360 -0
  78. package/plugins/litclaude/skills/programming/references/go/cobra-stack.md +468 -0
  79. package/plugins/litclaude/skills/programming/references/go/concurrency.md +362 -0
  80. package/plugins/litclaude/skills/programming/references/go/data-modeling.md +329 -0
  81. package/plugins/litclaude/skills/programming/references/go/error-handling.md +359 -0
  82. package/plugins/litclaude/skills/programming/references/go/golangci-strict.md +236 -0
  83. package/plugins/litclaude/skills/programming/references/go/grpc-connect.md +375 -0
  84. package/plugins/litclaude/skills/programming/references/go/libraries.md +337 -0
  85. package/plugins/litclaude/skills/programming/references/go/one-liners.md +202 -0
  86. package/plugins/litclaude/skills/programming/references/go/sqlc-pgx.md +471 -0
  87. package/plugins/litclaude/skills/programming/references/go/testing.md +467 -0
  88. package/plugins/litclaude/skills/programming/references/go/type-patterns.md +298 -0
  89. package/plugins/litclaude/skills/programming/references/python/README.md +314 -0
  90. package/plugins/litclaude/skills/programming/references/python/async-anyio.md +442 -0
  91. package/plugins/litclaude/skills/programming/references/python/data-modeling.md +233 -0
  92. package/plugins/litclaude/skills/programming/references/python/data-processing.md +133 -0
  93. package/plugins/litclaude/skills/programming/references/python/error-handling.md +218 -0
  94. package/plugins/litclaude/skills/programming/references/python/fastapi-stack.md +316 -0
  95. package/plugins/litclaude/skills/programming/references/python/httpx2-optimization.md +360 -0
  96. package/plugins/litclaude/skills/programming/references/python/libraries.md +307 -0
  97. package/plugins/litclaude/skills/programming/references/python/one-liners.md +268 -0
  98. package/plugins/litclaude/skills/programming/references/python/orjson-stack.md +378 -0
  99. package/plugins/litclaude/skills/programming/references/python/pydantic-ai.md +285 -0
  100. package/plugins/litclaude/skills/programming/references/python/pyproject-strict.md +232 -0
  101. package/plugins/litclaude/skills/programming/references/python/textual-tui.md +201 -0
  102. package/plugins/litclaude/skills/programming/references/python/type-patterns.md +176 -0
  103. package/plugins/litclaude/skills/programming/references/rust/README.md +317 -0
  104. package/plugins/litclaude/skills/programming/references/rust/async-tokio.md +299 -0
  105. package/plugins/litclaude/skills/programming/references/rust/axum-stack.md +467 -0
  106. package/plugins/litclaude/skills/programming/references/rust/cargo-strict.md +317 -0
  107. package/plugins/litclaude/skills/programming/references/rust/clap-stack.md +409 -0
  108. package/plugins/litclaude/skills/programming/references/rust/concurrency.md +375 -0
  109. package/plugins/litclaude/skills/programming/references/rust/libraries.md +439 -0
  110. package/plugins/litclaude/skills/programming/references/rust/one-liners.md +291 -0
  111. package/plugins/litclaude/skills/programming/references/rust/proptest-insta.md +429 -0
  112. package/plugins/litclaude/skills/programming/references/rust/type-state.md +354 -0
  113. package/plugins/litclaude/skills/programming/references/rust/unsafe-discipline.md +250 -0
  114. package/plugins/litclaude/skills/programming/references/rust/zero-cost-safety.md +527 -0
  115. package/plugins/litclaude/skills/programming/references/rust-ub/README.md +289 -0
  116. package/plugins/litclaude/skills/programming/references/rust-ub/miri-sanitizers-loom.md +411 -0
  117. package/plugins/litclaude/skills/programming/references/rust-ub/ub-taxonomy.md +269 -0
  118. package/plugins/litclaude/skills/programming/references/typescript/README.md +195 -0
  119. package/plugins/litclaude/skills/programming/references/typescript/backend-hono.md +672 -0
  120. package/plugins/litclaude/skills/programming/references/typescript/bootstrap.md +199 -0
  121. package/plugins/litclaude/skills/programming/references/typescript/data-modeling.md +202 -0
  122. package/plugins/litclaude/skills/programming/references/typescript/error-handling.md +169 -0
  123. package/plugins/litclaude/skills/programming/references/typescript/tsconfig-strict.md +152 -0
  124. package/plugins/litclaude/skills/programming/references/typescript/type-patterns.md +196 -0
  125. package/plugins/litclaude/skills/programming/scripts/go/check-no-excuse-rules.sh +173 -0
  126. package/plugins/litclaude/skills/programming/scripts/go/new-project.py +138 -0
  127. package/plugins/litclaude/skills/programming/scripts/go/templates/.editorconfig +13 -0
  128. package/plugins/litclaude/skills/programming/scripts/go/templates/.golangci.yml +95 -0
  129. package/plugins/litclaude/skills/programming/scripts/go/templates/AGENTS.md.tmpl +24 -0
  130. package/plugins/litclaude/skills/programming/scripts/go/templates/README.md.tmpl +12 -0
  131. package/plugins/litclaude/skills/programming/scripts/go/templates/Taskfile.yml +40 -0
  132. package/plugins/litclaude/skills/programming/scripts/go/templates/ci.yml +37 -0
  133. package/plugins/litclaude/skills/programming/scripts/go/templates/config.go +24 -0
  134. package/plugins/litclaude/skills/programming/scripts/go/templates/gitignore +15 -0
  135. package/plugins/litclaude/skills/programming/scripts/go/templates/main.go.tmpl +22 -0
  136. package/plugins/litclaude/skills/programming/scripts/go/templates/run.go +15 -0
  137. package/plugins/litclaude/skills/programming/scripts/python/check-no-excuse-rules.py +687 -0
  138. package/plugins/litclaude/skills/programming/scripts/python/new-project.py +172 -0
  139. package/plugins/litclaude/skills/programming/scripts/python/new-script.py +116 -0
  140. package/plugins/litclaude/skills/programming/scripts/rust/check-no-excuse-rules.py +296 -0
  141. package/plugins/litclaude/skills/programming/scripts/rust/check-no-excuse-rules.sh +158 -0
  142. package/plugins/litclaude/skills/programming/scripts/rust/new-project.py +175 -0
  143. package/plugins/litclaude/skills/programming/scripts/typescript/check-no-excuse-rules.ts +282 -0
  144. package/plugins/litclaude/skills/programming/scripts/typescript/new-project.ts +177 -0
  145. package/plugins/litclaude/skills/refactor/SKILL.md +73 -0
  146. package/plugins/litclaude/skills/remove-ai-slops/SKILL.md +52 -0
  147. package/plugins/litclaude/skills/review-work/SKILL.md +331 -0
  148. package/plugins/litclaude/skills/rules/SKILL.md +66 -0
  149. package/plugins/litclaude/skills/start-work/SKILL.md +132 -0
  150. package/scripts/audit-plan-checkboxes.mjs +37 -0
  151. package/scripts/doctor.mjs +41 -0
  152. package/scripts/inspect-agent-tools.mjs +27 -0
  153. package/scripts/postinstall.mjs +50 -0
  154. package/scripts/qa-claude-plugin-smoke.sh +60 -0
  155. package/scripts/qa-portable-install.sh +136 -0
  156. package/scripts/validate-plugin.mjs +72 -0
@@ -0,0 +1,415 @@
1
+ # Bundled-JS / Embedded-Source Binaries (Bun SEA, Node SEA, Deno compile, pkg, Electron, PyInstaller)
2
+
3
+ A growing class of "binaries" are not stripped C/C++ at all — they are a runtime VM glued onto a high-level-language bundle. The bundle is **plaintext or trivially-decodable** inside the binary.
4
+
5
+ If you reach for `native-binary.md` workflow on these (Ghidra → pwndbg → hex), you will waste hours decompiling a runtime you don't care about while the actual logic sits exposed three megabytes away.
6
+
7
+ **This reference exists because the workflow is fundamentally different from stripped C.**
8
+
9
+ ---
10
+
11
+ ## When to use this reference instead of `native-binary.md`
12
+
13
+ Open this if `file ./target` shows a generic Mach-O / ELF / PE BUT any of:
14
+
15
+ - Size is suspiciously large (50 MB+ for a "simple CLI")
16
+ - `strings -n 8 ./target | rg -i "node_modules|webpack|esbuild|bun|pkg/lib|electron|pyinstaller"` returns hits
17
+ - The binary's CLI flags include things like `--inspect`, `--unhandled-rejections`, npm-style help text
18
+ - Vendor docs say it's built with Bun / pkg / nexe / Deno compile / PyInstaller / Electron / Tauri (UI shell)
19
+ - `head -c 4 ./target | xxd` shows a known runtime magic for an embedded archive section
20
+
21
+ If yes → **stop following `native-binary.md` and follow this**. Triage and dynamic tracing are the same. Static analysis is completely different.
22
+
23
+ ---
24
+
25
+ ## The workflow
26
+
27
+ ```
28
+ [1] Triage → identify the bundler (Bun? pkg? Deno? Electron? PyInstaller?)
29
+ [2] Locate the bundle → find where the embedded source archive starts
30
+ [3] Extract → dump source to disk so you can grep / read it
31
+ [4] Source-level static analysis (rg + Read, NOT Ghidra)
32
+ [5] Runtime verification → debug logs, --inspect, partial-evidence patterns
33
+ [6] Fix / report
34
+ ```
35
+
36
+ Step 3 is the unlock — once you have plaintext source on disk, the rest is normal codebase exploration.
37
+
38
+ ---
39
+
40
+ ## [1] Identify the bundler — 30-second fingerprint
41
+
42
+ ```bash
43
+ # Look for runtime-specific markers in plaintext strings
44
+ strings -n 12 ./target 2>/dev/null | rg -iE 'bun|node_modules|webpack|esbuild|deno|pkg/lib|electron|pyinstaller|nexe|NODE_SEA_FUSE|NODE_SEA_BLOB|tauri|ESZIP_V2|denort' | head -20
45
+ ```
46
+
47
+ | Marker pattern | Bundler | Source format |
48
+ |---|---|---|
49
+ | `@oven/bun-darwin`, `bun-lockfile-format-v`, `// @bun` | **Bun SEA** (compiled via `bun build --compile`) | Plaintext JS, single big bundle |
50
+ | `NODE_SEA_BLOB` + `NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2:1` | **Node SEA** (`node --build-sea` or `--experimental-sea-config`) | Plaintext JS, or V8 code cache (when `useCodeCache: true`), or startup snapshot (when `useSnapshot: true`) — the latter two are NOT plaintext |
51
+ | `pkg/lib/bootstrap.js`, `pkg/prelude`, `PAYLOAD_POSITION` | **pkg** (vercel/pkg) | Plaintext or v8 cached data |
52
+ | `ESZIP_V2`, `denort`, `deno_runtime` | **Deno compile** (`deno compile`) | TS/JS in eszip archive — readable but needs `eszip` crate to walk; not pure plaintext |
53
+ | `Electron`, `app.asar`, `chrome.dll`, `Squirrel.Mac` | **Electron** | `app.asar` archive (TAR-like with JSON header). Source is plaintext JS once extracted |
54
+ | `PyInstaller`, `pyz`, `_MEIPASS`, `pyi-os-utils` | **PyInstaller** | Compressed `.pyc` bytecode — needs `pyinstxtractor` + `decompyle3` to recover Python source |
55
+ | `nexe-`, `nexe_compile`, `:::nexe::` | **nexe** | Plaintext JS appended to node binary |
56
+ | `Tauri`, `tao`, `wry`, `tauri::generate_context` | **Tauri** (Rust shell + JS UI) | **Two worlds**: JS frontend in resource section is extractable here; Rust commands / core logic are native and require [native-binary.md](native-binary.md) |
57
+
58
+ If multiple match (e.g. Tauri + Bun): the outer shell is the first one (Tauri/Electron). The inner JS is the second one's format. **For Tauri specifically, expect to use both this reference (for the UI bundle) and `native-binary.md` (for the Rust binary side).**
59
+
60
+ > **Source-format reality check**: only Bun SEA, pkg (when not using `--public-packages`), nexe, and Electron `.asar` are reliably plaintext. Node SEA with code-cache or snapshot, PyInstaller `.pyc`, and Deno eszip require additional tooling. Don't assume `strings` will find readable code — verify the bundler first.
61
+
62
+ ---
63
+
64
+ ## [2] Locate the bundle
65
+
66
+ ### Bun SEA — JS is just embedded plaintext
67
+
68
+ The JS source is concatenated into the binary as a giant template literal / string. No decoding needed.
69
+
70
+ ```bash
71
+ # Verify by searching for typical JS bundle markers
72
+ strings -n 8 ./target | rg "function|var |let |const |async function" | head -5
73
+
74
+ # Find where the bundle starts (look for "use strict" or banner comment)
75
+ LC_ALL=C grep -aob '"use strict"' ./target | head -5
76
+ LC_ALL=C grep -aob '#!/usr/bin/env bun' ./target | head -5
77
+ ```
78
+
79
+ ### Node SEA — `NODE_SEA_BLOB` resource/segment + activated fuse
80
+
81
+ Per the [Node.js SEA docs](https://nodejs.org/api/single-executable-applications.html), a Node-built SEA contains:
82
+ - A resource (PE), section in `NODE_SEA` segment (Mach-O), or note (ELF) named `NODE_SEA_BLOB`
83
+ - The fuse string `NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2:1` (with trailing `:1` indicating injected; `:0` means a copy of the node binary that has not yet had a blob injected)
84
+
85
+ ```bash
86
+ # Confirm it is a SEA at all
87
+ LC_ALL=C grep -aob 'NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2:1' ./target | head -1
88
+
89
+ # Find the blob resource/section
90
+ LC_ALL=C grep -aob 'NODE_SEA_BLOB' ./target | head
91
+
92
+ # On Mach-O, inspect the segment directly
93
+ otool -l ./target | grep -A4 'NODE_SEA'
94
+ ```
95
+
96
+ The blob format is documented but non-trivial to walk by hand. For extraction, **use postject in reverse** (carve the section bytes) or read the blob via `node:sea` API from inside a debug build of the same binary. Plain `strings` will get you the embedded JS only when the SEA was built without `useCodeCache` and without `useSnapshot` — both of those replace plaintext with V8 cache data or startup snapshot bytes.
97
+
98
+ `node --build-sea sea-config.json` and `node --experimental-sea-config sea-config.json` *generate* SEA blobs; neither inspects an existing executable.
99
+
100
+ ### Deno compile — eszip archive section
101
+
102
+ ```bash
103
+ # Deno-compile binaries embed an eszip v2 archive
104
+ LC_ALL=C grep -aob 'ESZIP_V2' ./target | head -3
105
+ # Also confirm the runtime
106
+ LC_ALL=C grep -aob 'denort' ./target | head -1
107
+ ```
108
+
109
+ To extract, use the `eszip` Rust crate (or the `@deno/eszip` JS port) to parse the archive after carving it out at the offset above. There is no stable Deno CLI flag that inspects compiled-executable eszip contents as of 2026-04 — `deno info` only works on source files.
110
+
111
+ ### pkg — `PAYLOAD_POSITION` marker
112
+
113
+ ```bash
114
+ LC_ALL=C grep -aob 'PAYLOAD_POSITION' ./target | head
115
+ LC_ALL=C grep -aob 'pkg/prelude' ./target | head
116
+ ```
117
+
118
+ For source extraction, use the `pkg-extract` tooling community projects or carve based on the offset reported by the `PAYLOAD_POSITION:<n>` value.
119
+
120
+ ### Electron — `app.asar` is usually a separate file
121
+
122
+ Most Electron apps ship `app.asar` next to the binary, not embedded inside. Extract it with the official tool:
123
+
124
+ ```bash
125
+ # macOS layout
126
+ ls -la /Applications/MyApp.app/Contents/Resources/app.asar
127
+ npx @electron/asar extract app.asar ./extracted/
128
+ # or older:
129
+ npx asar extract app.asar ./extracted/
130
+ ```
131
+
132
+ For single-file builds where the asar is embedded inside the executable, **do not pattern-match arbitrary 4-byte sequences** (the asar format starts with a Pickle-encoded uint32 header size + JSON metadata, and the same bytes appear elsewhere in any binary). Instead, use a Pickle-aware extractor that validates the JSON header before claiming a match — the `asar` npm package's programmatic `extractAll()` API does this. Carve the asar bytes by scanning for a candidate Pickle header (4-byte size + 4-byte payload size + `{"files":` prefix), validate the JSON parses, then feed the carved buffer to `extractAll()`.
133
+
134
+ ### PyInstaller — use `pyinstxtractor`, NOT runtime self-extraction
135
+
136
+ ```bash
137
+ # Recover the embedded archive without running the binary
138
+ python3 pyinstxtractor.py ./target
139
+ # Output: ./target_extracted/ with .pyc files
140
+
141
+ # Decompile the .pyc files back to Python source
142
+ decompyle3 ./target_extracted/main.pyc # Python 3.7+
143
+ uncompyle6 ./target_extracted/main.pyc # older Python
144
+ ```
145
+
146
+ If `pyinstxtractor` cannot read the archive (e.g. non-standard PyInstaller version), use the official `pyi-archive_viewer` tool that ships with PyInstaller. Avoid the "run-the-binary-and-snoop-`/tmp/_MEI*`" approach: it only catches what runs in the time window between `_MEIPASS` extraction and cleanup, and it executes potentially untrusted code.
147
+
148
+ ---
149
+
150
+ ## [3] Extract source to disk — DO NOT skip this
151
+
152
+ **The single biggest mistake** with bundled-JS reverse engineering is trying to read the source out of `strings` output or `xxd` dumps. You will lose data. See "Gotchas" below.
153
+
154
+ ### For Bun SEA / nexe / single-string-blob bundlers
155
+
156
+ Read the binary as bytes, find the JS section, save to a `.js` file:
157
+
158
+ ```python
159
+ # extract_bundled_js.py
160
+ import sys
161
+
162
+ if len(sys.argv) < 2:
163
+ raise SystemExit("usage: extract_bundled_js.py <target>")
164
+
165
+ with open(sys.argv[1], 'rb') as f:
166
+ data = f.read()
167
+
168
+ markers = [b'// @bun', b'"use strict"', b"'use strict'", b'#!/usr/bin/env']
169
+ start = -1
170
+ for m in markers:
171
+ p = data.find(m)
172
+ if p != -1 and (start == -1 or p < start):
173
+ start = p
174
+
175
+ if start == -1:
176
+ raise SystemExit(
177
+ "no bundle marker found — binary may not be Bun/nexe, "
178
+ "or markers were stripped. Try strings(1) for hints."
179
+ )
180
+
181
+ # Heuristic end: look for a long null run AFTER start.
182
+ # This is a heuristic, NOT a guarantee. Verify the tail of the output
183
+ # looks like JS (closing braces, EOF) before trusting it.
184
+ end = data.find(b'\x00' * 1024, start)
185
+ if end == -1:
186
+ end = len(data)
187
+
188
+ bundle = data[start:end]
189
+ print(f'Extracted {len(bundle)} bytes from offset {start} to {end}', file=sys.stderr)
190
+ sys.stdout.buffer.write(bundle)
191
+ ```
192
+
193
+ ```bash
194
+ python3 extract_bundled_js.py ./target > extracted-bundle.js
195
+ wc -c extracted-bundle.js
196
+ # Sanity check the tail is JS, not random binary
197
+ tail -c 200 extracted-bundle.js
198
+ ```
199
+
200
+ ### For PyInstaller
201
+
202
+ Use `pyinstxtractor` then `uncompyle6` / `decompyle3` on the `.pyc` files.
203
+
204
+ ### For Electron .asar
205
+
206
+ ```bash
207
+ npx asar extract app.asar ./extracted/
208
+ # Now ./extracted/ has a normal node_modules + your source layout
209
+ ```
210
+
211
+ ### For Deno compile
212
+
213
+ Use the `eszip` Rust crate or the `@deno/eszip` JS port to walk the archive after carving the eszip section out at the offset reported by the `ESZIP_V2` magic search. There is no stable Deno CLI as of 2026-04 that inspects compiled-binary eszip contents directly.
214
+
215
+ ---
216
+
217
+ ## [4] Source-level static analysis — `rg` + `Read`, not Ghidra
218
+
219
+ Once you have the source on disk, treat it as a normal codebase:
220
+
221
+ ```bash
222
+ # Find function definitions
223
+ rg -n "^function |^const \w+ = (function|\(.*\) =>)" extracted-bundle.js | head
224
+
225
+ # Find specific behavior
226
+ rg -n "claude-opus-4-7|reasoning_effort|api_key" extracted-bundle.js
227
+
228
+ # Resolve minified identifiers — they show up as `var XYZ="value"`
229
+ rg -aoP 'var \w+="[^"]+"' extracted-bundle.js | head -50
230
+ ```
231
+
232
+ For minified bundles, use a template-literal-aware parser to extract specific functions or template strings. Example skeleton:
233
+
234
+ ```python
235
+ def find_template_end(data, start):
236
+ """Walk a JS template literal preserving ${...} interpolation depth.
237
+ Returns position of closing backtick."""
238
+ i = start
239
+ while i < len(data):
240
+ c = data[i:i+1]
241
+ if c == b'\\':
242
+ i += 2; continue
243
+ if c == b'$' and data[i+1:i+2] == b'{':
244
+ depth = 1; i += 2
245
+ while i < len(data) and depth > 0:
246
+ cc = data[i:i+1]
247
+ if cc == b'\\': i += 2; continue
248
+ if cc == b'`':
249
+ j = find_template_end(data, i+1)
250
+ i = j + 1; continue
251
+ if cc == b'{': depth += 1
252
+ elif cc == b'}': depth -= 1
253
+ elif cc in (b'"', b"'"):
254
+ q = cc; i += 1
255
+ while i < len(data) and data[i:i+1] != q:
256
+ if data[i:i+1] == b'\\': i += 2
257
+ else: i += 1
258
+ i += 1; continue
259
+ i += 1
260
+ continue
261
+ if c == b'`': return i
262
+ i += 1
263
+ return -1
264
+ ```
265
+
266
+ For function-body extraction, **track the parameter list separately** before tracking body braces. The naive approach mis-counts destructuring `function f({a, b, ...c})` as the body `{` and exits early.
267
+
268
+ ---
269
+
270
+ ## [5] Runtime verification
271
+
272
+ You usually cannot single-step JS inside a Bun-compiled binary the way you would with `node --inspect`. Workarounds:
273
+
274
+ ### Bun-compiled
275
+
276
+ Bun's inspector takes `--inspect[=<host>:<port>[/<prefix>]]` on the command line. For env-var control of compiled binaries, the form is the same minus the leading `--`:
277
+
278
+ ```bash
279
+ # Default port (6499) auto-prefix
280
+ ./target --inspect
281
+ # → ws://localhost:6499/<auto-prefix> (paste into https://debug.bun.sh)
282
+
283
+ # Explicit host:port[/prefix]
284
+ ./target --inspect=localhost:9229/dbg
285
+ # Or via env var (if --inspect cannot be passed)
286
+ BUN_INSPECT=localhost:9229/dbg ./target
287
+ ```
288
+
289
+ **For HTTP request tracing without an interactive debugger** (highest-value Bun-specific runtime evidence):
290
+
291
+ ```bash
292
+ # Print every fetch() / node:http request as a curl command + full headers/body
293
+ BUN_CONFIG_VERBOSE_FETCH=curl ./target ...
294
+
295
+ # Or just print the request/response without curl-format
296
+ BUN_CONFIG_VERBOSE_FETCH=true ./target ...
297
+ ```
298
+
299
+ Plus generic env-var-based debug logging if the app supports it:
300
+
301
+ ```bash
302
+ APP_DEBUG=1 APP_LOG_LEVEL=debug APP_LOG_FILE=/tmp/trace.log ./target
303
+ ```
304
+
305
+ ### Node SEA / pkg / nexe
306
+ ```bash
307
+ # These usually accept --inspect since they are real Node
308
+ ./target --inspect
309
+ # Then chrome://inspect or node --inspect-brk
310
+ ```
311
+
312
+ ### Electron
313
+ ```bash
314
+ ./target.app/Contents/MacOS/target --inspect=9229 --remote-debugging-port=9223
315
+ # Renderer process is at chrome://inspect, main process via the inspector port
316
+ ```
317
+
318
+ ### When you cannot make a real call
319
+ The target's API may require credentials, network access, or paid quota you don't have. **You are not stuck** — see [methodology/partial-runtime-evidence.md](../methodology/partial-runtime-evidence.md) for the fallback patterns.
320
+
321
+ ---
322
+
323
+ ## ⚠️ Gotchas — read these before extracting
324
+
325
+ ### G1. `strings -n N` silently drops short identifier interpolations
326
+
327
+ `strings` outputs runs of printable characters of length **≥ N**. Default is 4 on most systems; many references (including older versions of `native-binary.md`) recommend `-n 8` for less noise.
328
+
329
+ **With `-n 8`, short template-literal interpolations like `${x}`, `${i}`, `${R}` are silently dropped** because they are 4 chars surrounded by non-printable bytes (newlines or section padding). The result looks like:
330
+
331
+ ```text
332
+ expected: <INSTRUCTIONS>\n${x}\n</INSTRUCTIONS>
333
+ strings: <INSTRUCTIONS>\n</INSTRUCTIONS> ← ${x} is gone, no warning
334
+ ```
335
+
336
+ A consumer reading the strings output would conclude the template is empty.
337
+
338
+ **Mitigation**:
339
+ 1. Use `strings` only for **fingerprinting** (Phase 1 triage), never as the source of extracted text.
340
+ 2. For actual extraction, **read the binary as bytes** with `python3 -c "open('./target','rb').read()"` and grep / parse from there.
341
+ 3. If you must use `strings`, try `strings -n 1 -t x ./target` and post-filter — but byte-level reads are still more reliable.
342
+
343
+ ### G2. Stale cached binary ≠ latest features
344
+
345
+ Bundled-app installers often check a remote version and skip download if a cached binary exists. If you reverse-engineered an old version and the user reports behavior you don't see in the source, **re-run the installer** (or fetch the version manifest manually) before assuming the source is current.
346
+
347
+ ```bash
348
+ # Example pattern - varies by tool
349
+ curl -fsSL https://example.com/install.sh | head -50 # find version-fetch URL
350
+ curl -fsSL https://static.example.com/cli/cli-version.txt
351
+ ./your-tool --version
352
+ # Compare. If different, re-install.
353
+ ```
354
+
355
+ ### G3. APFS / NTFS case-insensitivity silently overwrites files
356
+
357
+ When extracting many minified function bodies (`cVR`, `CVR`, `dpr`, `DPR`, …) and saving each to its own file, **macOS APFS and Windows NTFS treat `cVR.txt` and `CVR.txt` as the same file**. The second write silently overwrites the first.
358
+
359
+ **Mitigation**: prefix filenames with something case-distinguishing, e.g. `mode-cVR.txt`, `mode-CVR.txt`, or use a hash suffix.
360
+
361
+ ### G4. Bun's runtime adds 30-50 MB of unrelated symbols
362
+
363
+ A 70 MB Bun-compiled binary is **mostly Bun runtime** (~50 MB) plus your app (~20 MB). When fingerprinting, you will see thousands of strings like `tree-sitter-typescript`, `react-native-stylex` etc. that the user's actual app doesn't use — these are package names baked into Bun's package-resolution data.
364
+
365
+ **Mitigation**: when grepping for "what does this app do?", filter out runtime noise:
366
+ ```bash
367
+ strings -n 8 ./target | rg -v 'node_modules|@oven/bun|package-lock|tree-sitter|ffmpeg-installer' | head
368
+ ```
369
+
370
+ ### G5. Source maps usually NOT shipped
371
+
372
+ Bundled apps strip source maps for production. Variable names are minified to `T`, `R`, `a`, `r`, etc. Treat the bundle like an obfuscated codebase: identify constants by tracing assignments (`var T="actual-name"`) and resolve interpolations manually.
373
+
374
+ ### G6. The "extract" file is not legally redistributable
375
+
376
+ If reverse-engineering proprietary software, the extracted source is the vendor's IP. Use it for understanding behavior, **never commit it to git**, never post snippets in public issues. Cleanup your `extracted-bundle.js` files in Phase 9.
377
+
378
+ ---
379
+
380
+ ## Silent-failure patterns specific to bundled JS
381
+
382
+ | Pattern | Why it's silent |
383
+ |---|---|
384
+ | Bundle includes unreachable dead code from tree-shaking failures | You read code that never runs — verify with runtime trace |
385
+ | `process.env.X` resolved at BUILD time, not RUNTIME | Setting the env var at runtime has no effect; the value is baked in |
386
+ | `import.meta.url` in compiled binary returns `bun://...` not a real path | File-relative resolution silently breaks |
387
+ | Worker threads spawn from embedded code, look for sub-bundle inside main bundle | Workers may have their own copy of dependencies |
388
+ | Minified identifiers with case variants used in same module | Easy to confuse `cVR` with `CVR` when reading fast |
389
+
390
+ ---
391
+
392
+ ## Phase 9 cleanup specifics for bundled-JS work
393
+
394
+ ```bash
395
+ # Remove extracted bundles — they may contain proprietary source
396
+ rm -f /tmp/extracted-bundle.js /tmp/extracted-*.js
397
+ rm -rf /tmp/asar-extracted/
398
+ rm -rf /tmp/_MEI*
399
+
400
+ # Remove strings dumps
401
+ rm -f /tmp/*-strings.txt /tmp/*-strings-v*.txt
402
+
403
+ # Remove Python helper scripts created for parsing
404
+ rm -f /tmp/extract_bundled_js.py /tmp/parse_template.py
405
+
406
+ # Verify the extraction directory is gone (if you used a workspace dir)
407
+ ls /Users/$USER/local-workspaces/*-extracted/ 2>/dev/null
408
+ # rm -rf only after journal review confirms nothing important is there
409
+ ```
410
+
411
+ ---
412
+
413
+ ## When to escalate back to `native-binary.md`
414
+
415
+ If extraction reveals the "bundle" is actually compiled to v8 cached data (pkg with `--public-packages` or PyInstaller with bytecode-only mode), and decompilation is non-trivial, **switch back to `native-binary.md` workflow** (Ghidra against the runtime + careful tracing). Bundled-JS workflow only helps when the high-level source is recoverable as readable text.
@@ -0,0 +1,252 @@
1
+ # Go Debugging
2
+
3
+ Covers goroutines, `dlv` (Delve), `pprof`, the race detector, and the fact that Go's concurrency model means most bugs are about goroutines doing something quiet and wrong.
4
+
5
+ ---
6
+
7
+ ## Environment detection (Phase 0)
8
+
9
+ ```bash
10
+ go version
11
+ cat go.mod | head -5
12
+
13
+ # Delve installed?
14
+ which dlv
15
+ dlv version
16
+
17
+ # Build constraints
18
+ grep -r '// +build\|//go:build' cmd/ internal/ pkg/ 2>/dev/null | head
19
+
20
+ # pprof wired up?
21
+ grep -r 'net/http/pprof\|runtime/pprof' --include='*.go' | head -3
22
+ ```
23
+
24
+ ---
25
+
26
+ ## Delve (`dlv`) — the Go debugger
27
+
28
+ Go's gc compiler emits DWARF, but plain gdb barely understands goroutines. **Use dlv, not gdb.** Plain gdb on a Go binary will miss goroutine state and print garbage for interface values.
29
+
30
+ ### The five `dlv` launch modes
31
+
32
+ ```bash
33
+ # Build and launch under debugger (equivalent to `go run` + debug)
34
+ dlv debug ./cmd/server -- --port=8080
35
+
36
+ # Debug a test binary
37
+ dlv test ./internal/handler/ # enters the test package under debug
38
+
39
+ # Debug an existing binary (must be built with -gcflags="all=-N -l" for best results)
40
+ dlv exec ./bin/myserver
41
+
42
+ # Attach to a running process
43
+ dlv attach $(pgrep myserver)
44
+
45
+ # Headless mode (IDE / remote attach) — default port 2345
46
+ dlv debug --headless --listen=:2345 --api-version=2 ./cmd/server
47
+ ```
48
+
49
+ ### Building a debuggable binary
50
+
51
+ The compiler inlines and optimizes aggressively in normal builds, which makes stepping confusing. For serious debugging:
52
+
53
+ ```bash
54
+ go build -gcflags="all=-N -l" -o ./bin/server ./cmd/server
55
+ # -N disables optimization
56
+ # -l disables inlining
57
+ ```
58
+
59
+ Then `dlv exec ./bin/server`.
60
+
61
+ ### Essential dlv commands
62
+
63
+ ```
64
+ (dlv) b main.main # breakpoint at function
65
+ (dlv) b handler.go:42 # breakpoint at file:line
66
+ (dlv) b pkg/foo.Bar # breakpoint at type method (Go path syntax)
67
+ (dlv) c / continue # continue until next break
68
+ (dlv) n / next # step over
69
+ (dlv) s / step # step into
70
+ (dlv) so / stepout # step out
71
+ (dlv) bt / stack # stack trace of current goroutine
72
+ (dlv) goroutines # list all goroutines
73
+ (dlv) goroutine <id> # switch to goroutine N
74
+ (dlv) goroutine <id> bt # stack of a specific goroutine
75
+ (dlv) locals # all locals in frame
76
+ (dlv) args # function args
77
+ (dlv) p <expr> # print value (understands interfaces, maps, slices)
78
+ (dlv) vars <regex> # package vars matching regex
79
+ (dlv) regs # registers (rare in Go debugging)
80
+ (dlv) on <bpid> print <expr> # auto-print on breakpoint hit (powerful!)
81
+ (dlv) trace <location> # like breakpoint but just logs, doesn't stop
82
+ ```
83
+
84
+ The `trace` command is underused — it's like a logpoint, no stepping required.
85
+
86
+ ---
87
+
88
+ ## Goroutine-centric debugging
89
+
90
+ Goroutine leaks and deadlocks are the most common Go bugs. `dlv`'s `goroutines` command is the starting point.
91
+
92
+ ```
93
+ (dlv) goroutines -t # with truncated stack
94
+ (dlv) goroutines -s # sorted by stack
95
+ (dlv) goroutines -with user # filter user-spawned goroutines
96
+ ```
97
+
98
+ Common patterns:
99
+
100
+ | You see in `goroutines` | Usually means |
101
+ |---|---|
102
+ | 100s of goroutines stuck at `chan receive` | Producer died; consumers leak |
103
+ | 100s stuck at `semacquire` | Lock contention; a holder probably deadlocked |
104
+ | One stuck at `select` with no default | Missing case or closed channel scenario |
105
+ | Stuck at `netpoll` | External I/O not responding — not a Go bug, check downstream |
106
+ | Growing count over time | Goroutine leak — need to find who's spawning without cleanup |
107
+
108
+ ### Panic signals in Go
109
+
110
+ ```go
111
+ // Without recovery, panics crash the program with a stack trace of ALL goroutines
112
+ // With recovery, they're silent unless explicitly logged:
113
+ defer func() {
114
+ if r := recover(); r != nil {
115
+ log.Printf("recovered panic: %v\n%s", r, debug.Stack()) // GOOD
116
+ // log.Printf("recovered") // BAD — silent
117
+ }
118
+ }()
119
+ ```
120
+
121
+ **Always check for silent recovers** in Phase 8. Grep:
122
+ ```bash
123
+ rg 'recover\(\)' --type go
124
+ ```
125
+
126
+ And inspect each site for whether the panic is actually surfaced.
127
+
128
+ ---
129
+
130
+ ## Race detector — ALWAYS run when the bug is intermittent
131
+
132
+ ```bash
133
+ go test -race ./...
134
+ go run -race ./cmd/server
135
+ go build -race ./cmd/server
136
+ ```
137
+
138
+ The race detector wraps memory accesses and catches concurrent read/write without synchronization. **Run this before attaching dlv** if intermittency is involved — it often finds the bug directly.
139
+
140
+ Output shape:
141
+ ```
142
+ WARNING: DATA RACE
143
+ Read at 0x00c0001a0080 by goroutine 7:
144
+ main.(*Counter).Value()
145
+ /path/to/counter.go:14 +0x3c
146
+ Previous write at 0x00c0001a0080 by goroutine 6:
147
+ main.(*Counter).Inc()
148
+ /path/to/counter.go:10 +0x5f
149
+ ```
150
+
151
+ Both stacks. Both goroutines. The race is obvious from the line pair.
152
+
153
+ ---
154
+
155
+ ## pprof — for perf, memory, goroutine leaks
156
+
157
+ ### Wire it up (idempotent; usually already present)
158
+
159
+ ```go
160
+ import _ "net/http/pprof"
161
+
162
+ func main() {
163
+ go func() {
164
+ log.Println(http.ListenAndServe("localhost:6060", nil))
165
+ }()
166
+ // ... rest of your server
167
+ }
168
+ ```
169
+
170
+ ### Queries
171
+
172
+ ```bash
173
+ # CPU profile (30s)
174
+ go tool pprof http://localhost:6060/debug/pprof/profile?seconds=30
175
+
176
+ # Heap snapshot
177
+ go tool pprof http://localhost:6060/debug/pprof/heap
178
+
179
+ # Goroutine snapshot — find leaks
180
+ go tool pprof http://localhost:6060/debug/pprof/goroutine
181
+
182
+ # Block profile — find blocking ops (needs runtime.SetBlockProfileRate)
183
+ go tool pprof http://localhost:6060/debug/pprof/block
184
+
185
+ # Mutex profile — find lock contention (needs runtime.SetMutexProfileFraction)
186
+ go tool pprof http://localhost:6060/debug/pprof/mutex
187
+ ```
188
+
189
+ Inside pprof:
190
+ ```
191
+ (pprof) top # top functions by self time
192
+ (pprof) list main.handler # annotated source of a function
193
+ (pprof) web # SVG callgraph in browser (requires graphviz)
194
+ (pprof) traces # sample traces
195
+ ```
196
+
197
+ For goroutine leaks, **take two snapshots 30s apart** and diff:
198
+ ```bash
199
+ go tool pprof -base prof1.pb.gz prof2.pb.gz
200
+ ```
201
+
202
+ Goroutines that appear in prof2 but not prof1 are new; if they stick around, they're leaking.
203
+
204
+ ---
205
+
206
+ ## `GODEBUG` — runtime-level observability
207
+
208
+ ```bash
209
+ GODEBUG=gctrace=1 ./myserver # print GC stats
210
+ GODEBUG=schedtrace=1000 ./myserver # scheduler trace every 1000ms
211
+ GODEBUG=scheddetail=1,schedtrace=1000 # detailed scheduler state
212
+ GODEBUG=allocfreetrace=1 ./myserver # every alloc/free (noisy!)
213
+ GODEBUG=memprofilerate=1 ./myserver # profile every allocation
214
+ ```
215
+
216
+ Useful for diagnosing GC pressure, goroutine starvation, or memory pattern issues.
217
+
218
+ ---
219
+
220
+ ## Silent-failure patterns in Go
221
+
222
+ | Pattern | Why it's silent |
223
+ |---|---|
224
+ | `if err != nil { return err }` that returns to a caller that ignores | Error bubbles up, then gets discarded at the top |
225
+ | `defer func() { recover() }()` — bare recover, no log | Panic swallowed, program continues with state corruption |
226
+ | `_, _ = conn.Write(data)` | Intentionally discarded error |
227
+ | Buffered channel send that blocks forever | Sender hangs; hard to see if no deadlock detection |
228
+ | `time.Sleep` in a test | "Works on my machine"; test passes locally, fails in CI |
229
+ | `go func() { ... }()` with no error path | Goroutine dies silently on panic unless recover+log |
230
+ | Context canceled but operation continues | Ignored `ctx.Err()` check |
231
+ | `json.Unmarshal` of zero-value struct field | Input missing the key; silently zero |
232
+ | Closed channel read returning zero value | Consumer doesn't check `ok`; reads forever |
233
+
234
+ ---
235
+
236
+ ## Phase 9 cleanup specifics
237
+
238
+ ```bash
239
+ # Kill dlv sessions
240
+ pkill -f 'dlv' || true
241
+ lsof -iTCP:2345 -sTCP:LISTEN -nP 2>/dev/null # dlv default
242
+
243
+ # Kill pprof HTTP endpoint if you started it just for this session
244
+ lsof -iTCP:6060 -sTCP:LISTEN -nP 2>/dev/null
245
+
246
+ # Revert any `fmt.Println("DEBUG: ...")` or `log.Printf("DEBUG: ...")` additions
247
+ git diff | grep -E '(fmt\.Println\("DEBUG|log\.Printf\("DEBUG|println!)'
248
+ git checkout <file>
249
+
250
+ # Unset env vars
251
+ unset GODEBUG
252
+ ```