@dsmm/dsmm 0.0.0-stage → 0.1.0

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 (125) hide show
  1. package/LICENSE +103 -0
  2. package/README.md +67 -2
  3. package/agent-presets/dsmm-builder/agent.cordis.yml +210 -0
  4. package/agent-presets/dsmm-builder/preset.yml +3 -0
  5. package/agent-presets/dsmm-clarifier/agent.cordis.yml +34 -0
  6. package/agent-presets/dsmm-clarifier/preset.yml +3 -0
  7. package/agent-presets/dsmm-code-search/agent.cordis.yml +34 -0
  8. package/agent-presets/dsmm-code-search/preset.yml +3 -0
  9. package/agent-presets/dsmm-creative/agent.cordis.yml +31 -0
  10. package/agent-presets/dsmm-creative/preset.yml +3 -0
  11. package/agent-presets/dsmm-doc-search/agent.cordis.yml +34 -0
  12. package/agent-presets/dsmm-doc-search/preset.yml +3 -0
  13. package/agent-presets/dsmm-media-reader/agent.cordis.yml +34 -0
  14. package/agent-presets/dsmm-media-reader/preset.yml +3 -0
  15. package/agent-presets/dsmm-oracle/agent.cordis.yml +31 -0
  16. package/agent-presets/dsmm-oracle/preset.yml +3 -0
  17. package/agent-presets/dsmm-oracle-2nd/agent.cordis.yml +31 -0
  18. package/agent-presets/dsmm-oracle-2nd/preset.yml +3 -0
  19. package/agent-presets/dsmm-orchestrator/agent.cordis.yml +215 -0
  20. package/agent-presets/dsmm-orchestrator/preset.yml +3 -0
  21. package/agent-presets/dsmm-plan-critic/agent.cordis.yml +33 -0
  22. package/agent-presets/dsmm-plan-critic/preset.yml +3 -0
  23. package/agent-presets/dsmm-planner/agent.cordis.yml +33 -0
  24. package/agent-presets/dsmm-planner/preset.yml +3 -0
  25. package/agent-presets/dsmm-reviewer/agent.cordis.yml +33 -0
  26. package/agent-presets/dsmm-reviewer/preset.yml +3 -0
  27. package/cordis.patch.yml +8 -0
  28. package/docs/agent-presets.md +17 -0
  29. package/docs/compatibility.md +46 -0
  30. package/docs/design.md +237 -0
  31. package/docs/lsp.md +40 -0
  32. package/docs/migration-from-ocmm.md +48 -0
  33. package/docs/model-routing.md +16 -0
  34. package/docs/releasing.md +50 -0
  35. package/docs/research/deepseek-v4-pro.md +74 -0
  36. package/docs/research/oh-dsh.md +96 -0
  37. package/docs/roadmap.md +207 -0
  38. package/docs/runtime-recovery.md +67 -0
  39. package/docs/safety-guards.md +55 -0
  40. package/docs/settings-status.md +51 -0
  41. package/docs/skill-sync.md +20 -0
  42. package/lib/commands.d.ts +13 -0
  43. package/lib/commands.js +55 -0
  44. package/lib/dsh-events.d.ts +13 -0
  45. package/lib/dsh-events.js +2 -0
  46. package/lib/dsh-types.d.ts +308 -0
  47. package/lib/dsh-types.js +2 -0
  48. package/lib/guards.d.ts +10 -0
  49. package/lib/guards.js +252 -0
  50. package/lib/index.d.ts +31 -0
  51. package/lib/index.js +54 -0
  52. package/lib/lsp.d.ts +30 -0
  53. package/lib/lsp.js +154 -0
  54. package/lib/mode.d.ts +6 -0
  55. package/lib/mode.js +62 -0
  56. package/lib/model-family.d.ts +6 -0
  57. package/lib/model-family.js +49 -0
  58. package/lib/model-routing.d.ts +11 -0
  59. package/lib/model-routing.js +103 -0
  60. package/lib/plan-validation.d.ts +3 -0
  61. package/lib/plan-validation.js +119 -0
  62. package/lib/preset-materializer.d.ts +36 -0
  63. package/lib/preset-materializer.js +258 -0
  64. package/lib/preset-registry.d.ts +5 -0
  65. package/lib/preset-registry.js +126 -0
  66. package/lib/preset-skills.d.ts +12 -0
  67. package/lib/preset-skills.js +28 -0
  68. package/lib/prompts.d.ts +13 -0
  69. package/lib/prompts.js +82 -0
  70. package/lib/recovery-policy.d.ts +25 -0
  71. package/lib/recovery-policy.js +252 -0
  72. package/lib/role-subagents.d.ts +6 -0
  73. package/lib/role-subagents.js +54 -0
  74. package/lib/roles.d.ts +28 -0
  75. package/lib/roles.js +239 -0
  76. package/lib/runtime-recovery.d.ts +5 -0
  77. package/lib/runtime-recovery.js +149 -0
  78. package/lib/session-scope.d.ts +4 -0
  79. package/lib/session-scope.js +17 -0
  80. package/lib/settings.d.ts +112 -0
  81. package/lib/settings.js +363 -0
  82. package/lib/shell-command.d.ts +18 -0
  83. package/lib/shell-command.js +492 -0
  84. package/lib/skills.d.ts +18 -0
  85. package/lib/skills.js +64 -0
  86. package/lib/state.d.ts +13 -0
  87. package/lib/state.js +64 -0
  88. package/lib/status.d.ts +46 -0
  89. package/lib/status.js +155 -0
  90. package/package.json +124 -4
  91. package/patches/agent-presets-root.example.cordis.patch.yml +14 -0
  92. package/patches/ocmm-lsp-mcp.example.cordis.patch.yml +15 -0
  93. package/prompts/deepseek-flash.md +11 -0
  94. package/prompts/deepseek-v4-pro.md +14 -0
  95. package/prompts/deepwork.md +32 -0
  96. package/skills/brainstorming/SKILL.md +15 -0
  97. package/skills/debugging/SKILL.md +12 -0
  98. package/skills/debugging/references/logging.md +91 -0
  99. package/skills/debugging/references/methodology/00-setup.md +108 -0
  100. package/skills/debugging/references/methodology/02-investigate.md +67 -0
  101. package/skills/debugging/references/methodology/03-flaky-triage.md +69 -0
  102. package/skills/debugging/references/methodology/04-hard-reasoning-escalation.md +83 -0
  103. package/skills/debugging/references/methodology/05-escalate.md +69 -0
  104. package/skills/debugging/references/methodology/06-fix.md +123 -0
  105. package/skills/debugging/references/methodology/08-qa.md +94 -0
  106. package/skills/debugging/references/methodology/09-cleanup.md +164 -0
  107. package/skills/debugging/references/methodology/partial-runtime-evidence.md +217 -0
  108. package/skills/debugging/references/runtimes/bundled-js-binary.md +415 -0
  109. package/skills/debugging/references/runtimes/go.md +252 -0
  110. package/skills/debugging/references/runtimes/native-binary.md +484 -0
  111. package/skills/debugging/references/runtimes/node.md +260 -0
  112. package/skills/debugging/references/runtimes/python.md +248 -0
  113. package/skills/debugging/references/runtimes/rust.md +234 -0
  114. package/skills/debugging/references/scripts/dap.mjs +533 -0
  115. package/skills/debugging/references/tools/dap.md +89 -0
  116. package/skills/debugging/references/tools/ghidra.md +212 -0
  117. package/skills/debugging/references/tools/playwright-cli.md +316 -0
  118. package/skills/debugging/references/tools/pwndbg.md +263 -0
  119. package/skills/debugging/references/tools/pwntools.md +265 -0
  120. package/skills/dispatching-parallel-agents/SKILL.md +14 -0
  121. package/skills/receiving-code-review/SKILL.md +13 -0
  122. package/skills/remove-ai-slops/SKILL.md +14 -0
  123. package/skills/requesting-code-review/SKILL.md +10 -0
  124. package/skills/subagent-driven-development/SKILL.md +13 -0
  125. package/skills/writing-plans/SKILL.md +14 -0
@@ -0,0 +1,212 @@
1
+ # Ghidra — Decompile Binaries Into Readable C
2
+
3
+ **https://github.com/NationalSecurityAgency/ghidra**
4
+
5
+ Ghidra is the NSA's open-source reverse-engineering suite. Its defining feature is a **decompiler** that turns machine code back into readable C. For any binary you don't have source for, this is the correct starting point — not `strings`, not hex-staring, not `objdump -d`.
6
+
7
+ **Use Ghidra when**: third-party closed-source libs, malware analysis, vendored binaries whose behavior contradicts docs, CTF challenges, firmware, any time you need to read compiled code.
8
+
9
+ ---
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ # macOS
15
+ brew install --cask ghidra
16
+ # OR download the release ZIP from the repo and ./ghidraRun
17
+
18
+ # Linux
19
+ # Download from https://github.com/NationalSecurityAgency/ghidra/releases
20
+ # Requires JDK 21+
21
+ ./ghidraRun
22
+
23
+ # Dependency
24
+ java -version # must be 21+
25
+ ```
26
+
27
+ Ghidra is a Java Swing app. Looks dated, works well.
28
+
29
+ ---
30
+
31
+ ## First-time workflow (memorize this — it's not obvious)
32
+
33
+ 1. **Start Ghidra**: `ghidraRun`
34
+ 2. **Create a project**: File → New Project → Non-Shared → name it `debug-<binary-name>` (journal this path so you can rm it at Phase 9 if disposable).
35
+ 3. **Import the binary**: File → Import File → pick your target. Accept default format detection.
36
+ 4. **Double-click the imported binary** in the project listing. Ghidra asks to analyze it — say **yes**, accept defaults for the first pass. This takes anywhere from seconds (small binary) to tens of minutes (large binary).
37
+ 5. **Once analysis completes**, you're in the CodeBrowser view.
38
+
39
+ Two panels you'll use 95% of the time:
40
+
41
+ - **Listing** (middle) — the disassembly with Ghidra's inferred labels/types.
42
+ - **Decompiler** (right) — the reconstructed C. The real value.
43
+
44
+ ---
45
+
46
+ ## Finding the right function fast
47
+
48
+ Don't try to read the whole binary. Use these to narrow:
49
+
50
+ ### Symbol Tree (left panel)
51
+
52
+ - `Functions` — all detected functions. Stripped binaries show `FUN_00401234` (address-named); unstripped show actual names.
53
+ - `Imports` — dynamically-linked functions. Great for "does this binary call `system()`, `strcpy`, `curl_easy_perform`?"
54
+ - `Exports` — if it's a library.
55
+
56
+ Click to jump. The Decompiler updates instantly.
57
+
58
+ ### String search
59
+
60
+ ```
61
+ Search → For Strings
62
+ ```
63
+
64
+ Produces a list of all strings. Right-click a string → `References` → `Show References to Address`. Jumps to code that references it. **This is how you find which function handles the error message you saw at runtime.**
65
+
66
+ ### Memory search for bytes
67
+
68
+ ```
69
+ Search → Memory
70
+ ```
71
+
72
+ Search hex or text. Useful for known magic bytes, file-format signatures, constants.
73
+
74
+ ### Cross-references (XREF)
75
+
76
+ Right-click any function / address → `References → Find References to`. Shows every place that calls it. Walk the call graph backward from interesting functions.
77
+
78
+ ---
79
+
80
+ ## Making the decompiler's output readable
81
+
82
+ Ghidra's decompiler is good but needs hints. These three actions dramatically improve its output:
83
+
84
+ ### 1. Rename variables
85
+
86
+ Click a variable in the Decompiler view → press `L` → type a better name. Ghidra propagates the rename across all uses.
87
+
88
+ ### 2. Set types
89
+
90
+ A variable that looks like `undefined4` or `void *` is unhelpful. Click it → press `Ctrl+L` → set type (e.g. `int`, `char *`, `struct my_header *`).
91
+
92
+ For pointers to structs from headers you have, use:
93
+ ```
94
+ File → Parse C Source → paste header file → auto-creates struct types
95
+ ```
96
+
97
+ Then assign the struct type to the pointer. Ghidra resolves field accesses immediately.
98
+
99
+ ### 3. Retype function signatures
100
+
101
+ Click the function name in the Decompiler → press `F` (Edit Function Signature) → set return type + argument types. This propagates through callers.
102
+
103
+ Do these three actions on the 3-5 most relevant functions and the decompiler output becomes near-source-readable.
104
+
105
+ ---
106
+
107
+ ## Patterns for specific bug types
108
+
109
+ ### Looking for integer overflow / buffer overflow
110
+
111
+ ```
112
+ Listing: look for
113
+ - LEA → CMP patterns on sizes
114
+ - memcpy/strcpy/sprintf with non-constant sizes
115
+ Decompiler: look for
116
+ - arithmetic on size_t without bounds check
117
+ - `+ user_input` in a length calculation
118
+ ```
119
+
120
+ ### Looking for a missing auth check
121
+
122
+ Navigate from the handler entry (found via Strings or Imports) and check the control flow:
123
+
124
+ ```
125
+ Decompiler: does the function return early / jump to error handler when some flag is not set?
126
+ If the check is absent, that's the bug.
127
+ ```
128
+
129
+ ### Looking for hardcoded URLs / keys / paths
130
+
131
+ ```
132
+ Search → For Strings → filter `http:` / `https:` / `/etc/` / `bearer ` / `api_key`
133
+ ```
134
+
135
+ ### Looking for dispatch / plugin loading
136
+
137
+ ```
138
+ Imports → dlopen, LoadLibrary, dlsym, GetProcAddress
139
+ ```
140
+
141
+ The strings referenced near those calls are often plugin names.
142
+
143
+ ---
144
+
145
+ ## Scripting (headless Ghidra)
146
+
147
+ When you need to automate analysis across many binaries, or repeat a workflow:
148
+
149
+ ```bash
150
+ # Headless analyzer
151
+ $GHIDRA_INSTALL_DIR/support/analyzeHeadless \
152
+ <project-dir> <project-name> \
153
+ -import <binary> \
154
+ -postScript <script.py or script.java>
155
+ ```
156
+
157
+ Ghidra supports Python 3 scripts (via Jython-compatible API) and Java. Useful scripts:
158
+
159
+ - Dump all function signatures to JSON
160
+ - Find all calls to `system()` with constant arguments
161
+ - Auto-rename FUN_xxx based on heuristics (string refs, call patterns)
162
+
163
+ The community has a large collection: https://github.com/NationalSecurityAgency/ghidra/tree/master/Ghidra/Features/Base/ghidra_scripts
164
+
165
+ ---
166
+
167
+ ## Bookmarks + Notes
168
+
169
+ Ghidra has built-in bookmarks and comments. Use them as your journal inside the project:
170
+
171
+ - Right-click an address → `Set Bookmark` → tag as `Note`. Attach a description.
172
+ - Right-click → `Comments → Set EOL Comment` (shows up inline in decompiler).
173
+
174
+ Treat these as part of the journal. If you end up promoting this Ghidra project (keeping it after the debug session), the comments become durable documentation.
175
+
176
+ ---
177
+
178
+ ## Gotchas
179
+
180
+ - **Large binaries need more Java heap.** Edit `support/launch.properties` and bump `VMARGS=-Xmx8G` (default is often 2G, too small).
181
+ - **Save often.** Ghidra's autosave is not instant; a crash loses uncommitted analysis.
182
+ - **Decompiler has timeouts.** For complex functions it may give up and print `/* WARNING: ... */`. Increase timeout in `Edit → Tool Options → Decompiler`.
183
+ - **Archs beyond x86/ARM/MIPS** sometimes need Sleigh processor module tweaks. Rare but possible.
184
+ - **Signed vs unsigned decompilation** is frequently wrong. Manually retype when integer behavior matters.
185
+
186
+ ---
187
+
188
+ ## When Ghidra is NOT the right tool
189
+
190
+ - You have the source. Go read it.
191
+ - Bug is in your own recently-compiled binary. Rebuild with `-g` and use gdb/pwndbg (see [pwndbg.md](pwndbg.md)).
192
+ - You just need to know which libs a binary links. `ldd` / `otool -L` / `readelf -d` are faster.
193
+ - You just need strings. `strings -n 8` is faster.
194
+
195
+ Ghidra is the right tool when you need to **read the logic** of a binary you don't have source for.
196
+
197
+ ---
198
+
199
+ ## Phase 9 cleanup specifics
200
+
201
+ ```bash
202
+ # If you created a scratch project just for this debug session, journal path and remove:
203
+ # (the journal should have the exact path)
204
+ # Example:
205
+ ls ~/ghidra-projects/ 2>/dev/null
206
+ # rm -rf ~/ghidra-projects/debug-<binary-name>
207
+
208
+ # If you promoted the project (kept it), it's not cleanup — note it in the final summary to the user
209
+
210
+ # Kill any running Ghidra headless processes
211
+ pkill -f 'analyzeHeadless' || true
212
+ ```
@@ -0,0 +1,316 @@
1
+ # Playwright CLI — Browser QA That Actually Drives a Browser
2
+
3
+ **https://playwright.dev/ · https://github.com/microsoft/playwright**
4
+
5
+ For any browser-served web UI bug, this is the correct tool. Not curl. Not imagination. Not a headless HTTP library. A real browser with a real rendering engine, real JS execution, real cookies, real service workers, real viewport.
6
+
7
+ **In Phase 8 Manual QA for browser products, using Playwright is not optional.** Curl cannot catch: CSS that breaks at specific viewport widths, hydration mismatches, client-side router bugs, cookie/session interactions, service-worker caching, JS-triggered navigations. All of those are common bug classes. Drive a browser.
8
+
9
+ > Note: `microsoft/playwright-cli` is the legacy repo; the current tooling lives in `@playwright/test` (npm) and `playwright` (pip), which include the `playwright` CLI. Use those — the legacy `playwright-cli` package is deprecated.
10
+
11
+ ---
12
+
13
+ ## When to reach for Playwright
14
+
15
+ | Bug symptom | Use Playwright? |
16
+ |---|---|
17
+ | Form submit produces wrong result | ✅ — Playwright drives the form exactly as a user does |
18
+ | Page blank in prod, fine locally | ✅ — hydration/env differences need a real browser |
19
+ | CSS looks wrong at a specific width | ✅ — use `--viewport-size` |
20
+ | Click doesn't fire / wrong handler | ✅ — Playwright fires real DOM events |
21
+ | Flash of unstyled content / loading glitch | ✅ — use trace viewer to see frames |
22
+ | API returns wrong data | ❌ — use curl, this isn't a browser bug |
23
+ | Backend returns wrong status code | ❌ — use curl |
24
+ | Client hits a URL that returns 500 | ✅ but also ❌ — Playwright shows the call + response + failure effect on UI |
25
+
26
+ ---
27
+
28
+ ## Install (per-project)
29
+
30
+ Playwright installs browser binaries separately from the npm package.
31
+
32
+ ```bash
33
+ # In the project
34
+ npm init playwright@latest # interactive; picks TS/JS + browsers + config
35
+ # Or if Playwright is already a dep:
36
+ npx playwright install # downloads browsers
37
+ npx playwright install chromium # just chromium
38
+ npx playwright install --with-deps # also installs OS deps (Linux)
39
+ ```
40
+
41
+ Python:
42
+ ```bash
43
+ pip install playwright
44
+ playwright install
45
+ ```
46
+
47
+ ---
48
+
49
+ ## The four things you'll actually use
50
+
51
+ ### 1. `codegen` — record a session, generate the script
52
+
53
+ The fastest way to create a repro. Opens a real browser; your clicks / typing become a Playwright script you can paste into a test.
54
+
55
+ ```bash
56
+ npx playwright codegen https://your-app.local
57
+ npx playwright codegen --viewport-size=375,667 https://your-app.local # iPhone SE size
58
+ npx playwright codegen --device="iPhone 14" https://your-app.local
59
+ ```
60
+
61
+ Click / type / navigate in the browser; watch the script build in the side panel. Copy the generated script into your journal as the repro for Phase 8.
62
+
63
+ ### 2. A one-shot Playwright script — reproduce + capture
64
+
65
+ Usually the Phase 8 QA artifact. Save to `/tmp/debug-repro.spec.ts` (journal it):
66
+
67
+ ```ts
68
+ // /tmp/debug-repro.spec.ts
69
+ import { test, expect } from '@playwright/test';
70
+
71
+ test('refinement chat shows non-empty response when env var set', async ({ page }) => {
72
+ await page.goto('http://localhost:3000/chat');
73
+ await page.fill('textarea[name="message"]', 'Add a logging step');
74
+ await page.click('button[type=submit]');
75
+
76
+ // Wait for the response to appear (not just the spinner to disappear)
77
+ const response = page.locator('[data-testid="assistant-reply"]');
78
+ await expect(response).toBeVisible({ timeout: 30_000 });
79
+ await expect(response).not.toBeEmpty();
80
+
81
+ // Capture evidence
82
+ await page.screenshot({ path: '/tmp/debug-after-fix.png', fullPage: true });
83
+ console.log(await response.textContent());
84
+ });
85
+ ```
86
+
87
+ Run it with tracing enabled for rich post-mortem:
88
+
89
+ ```bash
90
+ npx playwright test /tmp/debug-repro.spec.ts --trace on --headed
91
+ ```
92
+
93
+ ### 3. `PWDEBUG=1` — step through the script with Playwright Inspector
94
+
95
+ ```bash
96
+ PWDEBUG=1 npx playwright test /tmp/debug-repro.spec.ts
97
+ ```
98
+
99
+ Opens the Playwright Inspector alongside the browser. You can step through Playwright actions, see the DOM state at each step, and edit selectors on the fly.
100
+
101
+ Use this when the script doesn't reproduce cleanly and you need to watch it run.
102
+
103
+ ### 4. `show-trace` — post-mortem on a failed run
104
+
105
+ ```bash
106
+ npx playwright show-trace trace.zip
107
+ # or from the test-results dir:
108
+ npx playwright show-trace test-results/<test-name>/trace.zip
109
+ ```
110
+
111
+ Scrubs through a recorded session: timeline, DOM snapshot at each action, network, console, source. When a test failed on CI but passed locally, this is the single best artifact.
112
+
113
+ ---
114
+
115
+ ## Headless vs headed during debugging
116
+
117
+ Always add `--headed` when debugging. Headless browsers sometimes behave subtly differently (font rendering, viewport, media permissions). For QA evidence, run headed and screenshot.
118
+
119
+ ```bash
120
+ npx playwright test --headed
121
+ npx playwright test --headed --project=chromium # pin the browser
122
+ ```
123
+
124
+ ---
125
+
126
+ ## Catching the silent-failure patterns Playwright is good at
127
+
128
+ ```ts
129
+ // Toast that flashes and disappears
130
+ page.on('console', msg => console.log('[browser console]', msg.type(), msg.text()));
131
+
132
+ // Unhandled page errors (uncaught exceptions in the page JS)
133
+ page.on('pageerror', err => console.error('[page error]', err));
134
+
135
+ // Network failures — e.g., backend returned 500 but UI shows nothing
136
+ page.on('response', async resp => {
137
+ if (!resp.ok()) {
138
+ console.warn(`[network ${resp.status()}] ${resp.url()} — ${await resp.text()}`);
139
+ }
140
+ });
141
+
142
+ // Request that never came back
143
+ page.on('requestfailed', req => {
144
+ console.error('[request failed]', req.url(), req.failure()?.errorText);
145
+ });
146
+ ```
147
+
148
+ Add these listeners to the top of the debug script. They surface a lot of the "UI showed nothing" class of bug.
149
+
150
+ ---
151
+
152
+ ## Viewport and device emulation
153
+
154
+ CSS bugs that only appear at specific sizes, or layout bugs on mobile:
155
+
156
+ ```ts
157
+ // At test level
158
+ test.use({ viewport: { width: 375, height: 667 } });
159
+
160
+ // Per-page
161
+ await page.setViewportSize({ width: 375, height: 667 });
162
+
163
+ // Predefined devices
164
+ import { devices } from '@playwright/test';
165
+ test.use({ ...devices['iPhone 14'] });
166
+ ```
167
+
168
+ ---
169
+
170
+ ## Gotchas
171
+
172
+ - **Wait for state, not for time.** `await page.waitForTimeout(2000)` is flaky. Use `await expect(locator).toBeVisible()` or `page.waitForResponse(urlPattern)`.
173
+ - **Stale selectors re-resolve.** Playwright's locators re-find the element on each action, unlike Puppeteer's handles. Don't over-think it.
174
+ - **Service workers persist across test runs in headed mode.** Use a run-owned temporary profile for a clean state; never clear a real profile in place. See the profile-safety procedure below.
175
+ - **Installing on CI requires `--with-deps`** on Linux images that lack the browser's shared-library deps.
176
+ - **Parallel tests share a browser process by default**; if one test polls a debugger port, others may interfere. Use `workers: 1` for debugging.
177
+
178
+ ---
179
+
180
+ ## Profile safety — run-owned empty user-data directory
181
+
182
+ **Never clear cookies, cache, or site data on a user's real browser profile.** This includes Playwright's `context.clearCookies()`, CDP `Network.clearBrowserCookies` and `Storage.clearCookies`, and browser APIs such as `chrome.browsingData.remove`. These operations can erase the user's authenticated state across unrelated sites.
183
+
184
+ Every browser action in this guide uses a **run-owned temporary empty browser profile or isolated empty context**. **Do not sign in to any browser, vendor, site, or account, including disposable or test accounts.** **Do not import, copy, reuse, or sync user browser settings, extensions, cookies, authentication, or storage state**; this includes Playwright `--load-storage`, `storageState`, copied profiles, and connections to an existing CDP session. If a required flow cannot be reached anonymously, stop and **report authentication as a verification limitation** rather than bypassing the boundary or claiming that coverage.
185
+
186
+ `launchPersistentContext` preserves cookies, local storage, and other browser state in its directory. It must use an **independent, run-owned empty user-data directory** made for this debug run; Chrome's main User Data directory and every other existing browser profile are off limits. Never copy a browser profile into the run directory or transfer authentication state from one. This is both safer and the supported Playwright model for persistent contexts.
187
+
188
+ Do not load browser extensions or plugins. The clean profile and `--disable-extensions` are mandatory; `--load-extension` and `--disable-extensions-except` are prohibited. Never sign in to a browser or vendor account (Google, Microsoft, Firefox, or similar), a personal web account, or any target application. Never enable browser setting sync. Cookies, cache, and service-worker data may be created only by anonymous visits made inside this run; they expire with its profile and do not represent returning-user or authenticated coverage.
189
+
190
+ Create the run-owned directories without referring to any existing browser data:
191
+
192
+ ```powershell
193
+ if (-not (Test-Path -LiteralPath $env:TEMP)) { throw "Temporary directory was not found" }
194
+
195
+ $runRoot = Join-Path $env:TEMP ("ocmm-playwright-" + [guid]::NewGuid().ToString("N"))
196
+ $userDataDir = Join-Path $runRoot "user-data"
197
+ $logsDir = Join-Path $runRoot "logs"
198
+ $ownershipToken = [guid]::NewGuid().ToString("N")
199
+ $ownershipMarker = Join-Path $runRoot ".ocmm-run-owner"
200
+ New-Item -ItemType Directory -Path $runRoot -ErrorAction Stop | Out-Null
201
+ New-Item -ItemType Directory -Path $userDataDir -ErrorAction Stop | Out-Null
202
+ New-Item -ItemType Directory -Path $logsDir -ErrorAction Stop | Out-Null
203
+ New-Item -ItemType File -Path $ownershipMarker -Value $ownershipToken -ErrorAction Stop | Out-Null
204
+ $env:PW_USER_DATA_DIR = $userDataDir
205
+ ```
206
+
207
+ Use that empty directory for the persistent context. Cookie clearing is permitted only for this run-owned empty profile:
208
+
209
+ ```ts
210
+ const context = await chromium.launchPersistentContext(process.env.PW_USER_DATA_DIR!, {
211
+ channel: 'chrome',
212
+ headless: false,
213
+ args: [
214
+ '--disable-extensions',
215
+ '--disable-sync',
216
+ ],
217
+ });
218
+ await context.clearCookies(); // safe only for this run-owned empty profile
219
+ ```
220
+
221
+ ## Non-blocking browser-debug launch
222
+
223
+ Prefer the current agent platform's native background task or process tool when it actually exposes one. If no such durable native tool is available, the PowerShell fallback must start the Node browser-debug script with `Start-Process`, capture run-owned logs, record its PID, and return immediately:
224
+
225
+ ```powershell
226
+ $browserDebugScriptInput = $env:PW_BROWSER_DEBUG_SCRIPT
227
+ if ([string]::IsNullOrWhiteSpace($browserDebugScriptInput)) {
228
+ throw "Set PW_BROWSER_DEBUG_SCRIPT to the existing project browser-debug script"
229
+ }
230
+ if (-not (Test-Path -LiteralPath $browserDebugScriptInput -PathType Leaf)) {
231
+ throw "Browser-debug script was not found"
232
+ }
233
+ $resolvedBrowserDebugScript = (Resolve-Path -LiteralPath $browserDebugScriptInput -ErrorAction Stop).Path
234
+ $stdoutLog = Join-Path $logsDir "browser-debug.stdout.log"
235
+ $stderrLog = Join-Path $logsDir "browser-debug.stderr.log"
236
+ $pidFile = Join-Path $runRoot "browser-debug.pid"
237
+ $browserArguments = @(
238
+ ('"{0}"' -f $resolvedBrowserDebugScript),
239
+ "--run-root",
240
+ ('"{0}"' -f $runRoot)
241
+ )
242
+
243
+ $process = Start-Process -FilePath "node" -ArgumentList $browserArguments -RedirectStandardOutput $stdoutLog -RedirectStandardError $stderrLog -PassThru
244
+ $pidRecord = "$($process.Id):$($process.StartTime.ToUniversalTime().Ticks)"
245
+ $pidRecord | Set-Content -LiteralPath $pidFile -NoNewline
246
+ $launchReceipt = [ordered]@{
247
+ runRoot = $runRoot
248
+ pid = $process.Id
249
+ startTimeTicks = $process.StartTime.ToUniversalTime().Ticks
250
+ pidFile = $pidFile
251
+ ownershipMarker = $ownershipMarker
252
+ ownershipToken = $ownershipToken
253
+ stdoutLog = $stdoutLog
254
+ stderrLog = $stderrLog
255
+ }
256
+ Write-Output ($launchReceipt | ConvertTo-Json -Compress)
257
+ ```
258
+
259
+ Do not add `-Wait`: launch must be nonblocking, and no tool call may wait for the entire browser session. `Start-Job` does not survive shell exit, so it does not meet this contract. In a later bounded tool call, confirm readiness through the script's readiness endpoint or bounded log polling (for example, a fixed number of reads with a deadline), then inspect only the recorded PID if the browser exits unexpectedly. Never use an unbounded poll.
260
+
261
+ After closing the context, terminate only the recorded run-owned PID through that same verified Process object and clean up only the directory created by this run. Resolve and validate the exact target before deleting it:
262
+
263
+ ```powershell
264
+ $resolvedTempRoot = (Resolve-Path -LiteralPath $env:TEMP -ErrorAction Stop).Path
265
+ $resolvedRunRoot = [IO.Path]::GetFullPath($runRoot)
266
+ $runRootParent = [IO.Directory]::GetParent($resolvedRunRoot)
267
+ $runRootName = [IO.Path]::GetFileName($resolvedRunRoot)
268
+ if (
269
+ $null -eq $runRootParent -or
270
+ $runRootParent.FullName -ne $resolvedTempRoot -or
271
+ $runRootName -notmatch '^ocmm-playwright-[0-9a-f]{32}$'
272
+ ) {
273
+ throw "Refusing to remove a non-run-owned profile"
274
+ }
275
+ if (
276
+ -not (Test-Path -LiteralPath $ownershipMarker -PathType Leaf) -or
277
+ (Get-Content -LiteralPath $ownershipMarker -Raw).Trim() -ne $ownershipToken
278
+ ) {
279
+ throw "Refusing to remove a run root without its exact ownership marker"
280
+ }
281
+
282
+ $pidRecord = (Get-Content -LiteralPath $pidFile -Raw).Trim().Split(":")
283
+ if ($pidRecord.Count -ne 2) { throw "Refusing to terminate an invalid run-owned PID record" }
284
+ $runOwnedPid = [int]$pidRecord[0]
285
+ $expectedStartTicks = [long]$pidRecord[1]
286
+ $runOwnedProcess = Get-Process -Id $runOwnedPid -ErrorAction SilentlyContinue
287
+ if ($null -ne $runOwnedProcess) {
288
+ if ($runOwnedProcess.StartTime.ToUniversalTime().Ticks -ne $expectedStartTicks) {
289
+ throw "Refusing to terminate a PID that is no longer run-owned"
290
+ }
291
+ $runOwnedProcess.Kill()
292
+ if (-not $runOwnedProcess.WaitForExit(10000)) {
293
+ throw "Run-owned browser process did not exit before cleanup deadline"
294
+ }
295
+ }
296
+
297
+ Remove-Item -LiteralPath $resolvedRunRoot -Recurse -Force
298
+ ```
299
+
300
+ ---
301
+
302
+ ## Phase 9 cleanup specifics
303
+
304
+ ```bash
305
+ # Remove trace files from debug runs
306
+ rm -rf playwright-report/ test-results/ trace.zip
307
+
308
+ # Remove debug spec files from /tmp
309
+ rm -f /tmp/debug-*.spec.ts
310
+
311
+ # Remove screenshot captures
312
+ rm -f /tmp/debug-*.png
313
+
314
+ # If you installed browsers just for this session (rare):
315
+ # Don't remove them — they're useful for future sessions. They live in ~/Library/Caches/ms-playwright (macOS) or ~/.cache/ms-playwright (Linux).
316
+ ```