# Phase 7: Native Distribution - Context

**Gathered:** 2026-04-13
**Status:** Ready for planning

<domain>
## Phase Boundary

Package the native DWM capture addon with prebuilt binaries so users can install via npm without build tools (no Visual Studio, no CMake). Update the cplugs marketplace plugin to include the native addon. Covers: DWM-13, DWM-14.

</domain>

<decisions>
## Implementation Decisions

### Prebuilt Binary Strategy
- **D-01:** Use prebuildify to bundle prebuilt .node binaries inside the npm package under `prebuilds/win32-x64/`
- **D-02:** Use node-gyp-build at install time to locate the correct prebuild — no compilation needed
- **D-03:** Target NAPI version 8 (already set in CMakeLists.txt) for ABI stability across Node.js 18+
- **D-04:** Build with `/MT` (static CRT linking) to eliminate MSVC runtime DLL dependencies — binary runs on any Windows 10/11 without extra runtimes
- **D-05:** Only ship win32-x64 prebuilds (per v1.1 out-of-scope: ARM64 deferred)

### Build Scripts
- **D-06:** Add `prebuild` npm script that runs prebuildify to create the prebuilt binary
- **D-07:** Add `install` npm script that runs node-gyp-build to load the prebuild at install time
- **D-08:** Keep `build:native` script for development use (cmake-js compile)

### Package.json Updates
- **D-09:** Add `prebuildify` as devDependency
- **D-10:** Add `node-gyp-build` as dependency (runtime, needed at install)
- **D-11:** Update `files` field to include `prebuilds/` directory in the published package

### cplugs Marketplace Update
- **D-12:** Rebuild and republish the cplugs marketplace plugin with the native addon included
- **D-13:** Verify the plugin installs cleanly and the MCP server registers with DWM capture available

### Claude's Discretion
- Exact prebuildify flags and configuration
- Whether to add a postinstall verification script
- CI build configuration details (if any)

</decisions>

<canonical_refs>
## Canonical References

**Downstream agents MUST read these before planning or implementing.**

### Prior Research
- `.planning/research/ARCHITECTURE.md` — Prebuilt binary strategy section (prebuildify + node-gyp-build pattern)
- `.planning/research/PITFALLS.md` — Pitfall #6 (node-gyp build failures), Pitfall #9 (ABI breaks)

### Existing Build System
- `native/CMakeLists.txt` — cmake-js build configuration
- `package.json` — Current scripts and dependencies

### Distribution
- Phase 4 plans/summaries for cplugs marketplace publish pattern

</canonical_refs>

<code_context>
## Existing Code Insights

### Reusable Assets
- `native/CMakeLists.txt`: Already configured for cmake-js with C++17, NAPI 8, static CRT
- Phase 4 distribution: cplugs marketplace publish pattern already established
- `tsup` build: Already configured for TypeScript bundling

### Established Patterns
- `npm run build` produces dist/ via tsup
- Plugin manifest at project root for cplugs

### Integration Points
- `package.json`: Add prebuildify/node-gyp-build deps and scripts
- `dwm-capture.ts`: The `createRequire` loader already handles .node binary location — node-gyp-build provides the standard path resolution

</code_context>

<specifics>
## Specific Ideas

- The prebuildify `--napi --strip` flags produce a minimal binary tagged by NAPI version
- node-gyp-build looks in `prebuilds/{platform}-{arch}/` automatically — no code changes needed in dwm-capture.ts if the binary is placed correctly
- Static CRT linking (`/MT`) is already set by cmake-js via `CMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded` in the build output

</specifics>

<deferred>
## Deferred Ideas

None — discussion stayed within phase scope

</deferred>

---

*Phase: 07-native-distribution*
*Context gathered: 2026-04-13*
