You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: REFACTOR.md
+93-22Lines changed: 93 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -122,10 +122,26 @@ The entrypoint chooses the runtime. Packages own the feature wiring.
122
122
123
123
## Agent Harness
124
124
125
-
This migration will be worked by many agents across many context windows. Treat
126
-
the repo like a handoff between engineers on shifts: every agent must be able to
127
-
arrive cold, understand what is already done, choose one slice, and leave the
128
-
next agent a clean state.
125
+
This migration is worked by many agents running concurrently in the **same
126
+
single working tree** across many context windows. Agents never stop after one
127
+
slice and never hand off: each agent claims a slice, ports it, then immediately
128
+
claims the next, and keeps going until it runs out of context. Treat the repo
129
+
as a shared live workspace that any agent can arrive cold to, understand from
130
+
the coordination files, and continue from.
131
+
132
+
**Non-negotiable working rules for every agent:**
133
+
134
+
-**Never stop.** Finishing a slice is not a stopping point. The instant a slice
135
+
is validated, claim the next highest-priority `todo` and continue. Only stop
136
+
when out of context.
137
+
-**Never commit.** Do not run `git commit`, `git add` for a commit, or create
138
+
branches. All work stays as uncommitted edits in the shared working tree. The
139
+
coordination files below are the synchronization mechanism, not git history.
140
+
-**Never use git worktrees.** Every agent works in the one main working tree.
141
+
Do not create, switch to, or prefer separate worktrees or branches.
142
+
-**Collaborate, don't isolate.** Other agents are editing the same files at the
143
+
same time. Conflict risk is never a reason to stop or to avoid a slice. Make
144
+
your edits, keep the tree typechecking, and keep moving.
129
145
130
146
Set up three coordination artifacts before broad parallel work starts:
131
147
@@ -199,34 +215,37 @@ Every agent session starts the same way:
199
215
7. Claim exactly one `todo` slice by setting it to `in_progress` with your
200
216
agent/session id.
201
217
202
-
### Agent Finish Protocol
218
+
### Per-Slice Wrap-Up (then immediately continue)
203
219
204
-
Every agent session ends by leaving the repo in a clean handoff state:
220
+
When a slice's code is done, do this and then **claim the next slice without
221
+
stopping** — this is a loop, not the end of a session:
205
222
206
223
1. Run focused tests/typecheck for the slice.
207
224
2. Run the relevant smoke test as a user would, not just a unit-level substitute.
208
-
3. Update `REFACTOR_SLICES.json`.
225
+
3. Run `pnpm biome format --write .` and `pnpm typecheck` so the shared tree
226
+
stays green for the other agents working in it.
227
+
4. Update `REFACTOR_SLICES.json`.
209
228
- Set `passes: true` only when acceptance checks actually passed.
210
229
- Use `needs_validation` if code is done but the feature was not exercised.
211
230
- Use `blocked` with a concrete reason if progress cannot continue.
212
-
4. Append a short `REFACTOR_PROGRESS.md` entry: slice id, changed paths,
231
+
5. Append a short `REFACTOR_PROGRESS.md` entry: slice id, changed paths,
213
232
validation run, remaining bridges, and next suggested slice.
214
-
5. Update `MIGRATION.md` for landed architectural movement.
215
-
6. Leave no unrelated edits in files outside the claimed slice.
216
-
7. Before committing, run `pnpm biome format --write .` and `pnpm typecheck`,
217
-
then stage the result. Biome owns formatting for every file including
218
-
`REFACTOR_SLICES.json` — commit the formatted version so CI does not bounce
219
-
it. Never bypass commit hooks with `--no-verify`.
220
-
8. If the harness expects commits, commit the slice with a descriptive message
221
-
only after the worktree is coherent and validation is recorded.
233
+
6. Update `MIGRATION.md` for landed architectural movement.
234
+
7.**Do not commit.** Leave everything as uncommitted edits in the shared tree.
235
+
8. Re-read `REFACTOR_SLICES.json`, claim the next highest-priority unclaimed
236
+
`todo`, and start again. Keep going until out of context.
222
237
223
238
### Parallel Work Rules
224
239
225
-
- One agent owns one slice. Do not work a broad foundational refactor unless it
226
-
is explicitly assigned.
227
-
- Prefer separate git worktrees/branches per agent. Parallel edits to the same
228
-
package registration files, root DI files, or `REFACTOR_SLICES.json` will
229
-
conflict; keep those changes small and merge them deliberately.
240
+
- Every agent works in the **one shared working tree**. No git worktrees, no
241
+
branches, no commits — see the working rules under [Agent Harness](#agent-harness).
242
+
- Claim one slice at a time, but never stop after one. Finish it, then claim the
243
+
next. Foundational/broad slices are fair game when they are the highest-priority
244
+
unclaimed work.
245
+
- Parallel edits to the same files (package registration, root DI, the
246
+
coordination files) are expected. Re-read `REFACTOR_SLICES.json` right before
247
+
editing it so you build on the current state instead of clobbering another
248
+
agent's claim. Keep the tree typechecking after your edits.
230
249
- Do not mark the whole migration complete because several slices are passing.
231
250
Completion means every slice in `REFACTOR_SLICES.json` is passing or explicitly
232
251
retired with a reason.
@@ -461,6 +480,38 @@ Electron, or Node host syscalls.
461
480
Core may use Inversify decorators and modules, but it must not import an app
462
481
container. It exports services and modules; hosts load them.
463
482
483
+
#### Core Purity Gate
484
+
485
+
`core` is portable business logic. Do not move code into `packages/core` just
486
+
because it is "not UI". If it imports Node, shells out, reads paths from the
487
+
host, watches files, checks `process.platform`, reads `process.env`, or depends
488
+
on a Node-oriented implementation package, it is not pure core yet.
489
+
490
+
Before marking a core slice `needs_validation` or `passing`, run:
491
+
492
+
```sh
493
+
pnpm exec biome lint packages/core
494
+
pnpm exec biome check packages/core
495
+
pnpm --filter @posthog/core typecheck
496
+
```
497
+
498
+
`biome lint packages/core` must have zero `noRestrictedImports` errors. If it
499
+
does not, course-correct the placement before continuing:
500
+
501
+
| Found in proposed core code | Correct move |
502
+
|---|---|
503
+
|`node:fs`, `node:path`, `node:os`, `node:child_process`, `node:process`, `process.*`|`workspace-server`, or a `platform`/environment contract injected into core |
504
+
|`node:crypto` for ids, hashes, PKCE, random bytes |`platform` crypto/random contract, or keep the flow in a host package until a contract exists |
505
+
|`node:events` for async iterators/event emitters | use a small shared/platform event abstraction, or keep the event-source owner in `workspace-server`|
506
+
|`@posthog/enricher`, git/file scanners, AST scanning tied to repo files |`workspace-server` owns the scan; core may own only the result model and business decision |
0 commit comments