Skip to content

Commit ff0f9e6

Browse files
committed
refactor: everything
1 parent d124743 commit ff0f9e6

2,025 files changed

Lines changed: 53439 additions & 23835 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

MIGRATION.md

Lines changed: 1436 additions & 0 deletions
Large diffs are not rendered by default.

REFACTOR.md

Lines changed: 93 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,26 @@ The entrypoint chooses the runtime. Packages own the feature wiring.
122122

123123
## Agent Harness
124124

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.
129145

130146
Set up three coordination artifacts before broad parallel work starts:
131147

@@ -199,34 +215,37 @@ Every agent session starts the same way:
199215
7. Claim exactly one `todo` slice by setting it to `in_progress` with your
200216
agent/session id.
201217

202-
### Agent Finish Protocol
218+
### Per-Slice Wrap-Up (then immediately continue)
203219

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:
205222

206223
1. Run focused tests/typecheck for the slice.
207224
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`.
209228
- Set `passes: true` only when acceptance checks actually passed.
210229
- Use `needs_validation` if code is done but the feature was not exercised.
211230
- 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,
213232
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.
222237

223238
### Parallel Work Rules
224239

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.
230249
- Do not mark the whole migration complete because several slices are passing.
231250
Completion means every slice in `REFACTOR_SLICES.json` is passing or explicitly
232251
retired with a reason.
@@ -461,6 +480,38 @@ Electron, or Node host syscalls.
461480
Core may use Inversify decorators and modules, but it must not import an app
462481
container. It exports services and modules; hosts load them.
463482

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 |
507+
| `process.platform` / `process.arch` update logic | app/platform capability supplies host info; core consumes a typed host-info interface |
508+
| Node-only test fixtures in `packages/core` | move the test to the host package or provide a fake pure port; do not weaken the lint rule |
509+
510+
If the business algorithm is valuable but currently mixed with host calls, split
511+
it: put the pure model/decision function in `core`, put host access in
512+
`workspace-server` or an app adapter, and connect them through an injected
513+
interface.
514+
464515
### `packages/workspace-server`
465516

466517
Owns Node-only host syscalls and the tRPC server:
@@ -580,6 +631,9 @@ Work one feature or capability slice at a time.
580631
duplicated, decide which copy owns truth before moving it.
581632
4. **Identify host calls.** Git, fs, spawn, pty, Electron, OS APIs, native
582633
modules, and watchers move to workspace-server or platform adapters.
634+
`process.env`, `process.platform`, `node:crypto`, `node:events`, and
635+
Node-oriented implementation packages count as host calls unless a pure
636+
browser/mobile-compatible abstraction already exists.
583637
5. **Sort logic.**
584638
- Host syscall or source smoothing: `workspace-server`.
585639
- Business orchestration: `core`.
@@ -603,7 +657,10 @@ Work one feature or capability slice at a time.
603657
delegation shims with `// PORT NOTE:` and a retirement condition.
604658
12. **Delete old code when the bridge is gone.**
605659
13. **Update `MIGRATION.md` and `REFACTOR_PROGRESS.md`.**
606-
14. **Validate.** Typecheck, tests, app launch, and a real feature smoke test.
660+
14. **Validate.** Typecheck, package purity checks, tests, app launch, and a
661+
real feature smoke test. If the slice touched `packages/core`, run
662+
`pnpm exec biome lint packages/core` and fix placement until
663+
`noRestrictedImports` is clean.
607664
15. **Update `REFACTOR_SLICES.json`.** Mark `passing` / `passes: true` only when
608665
validation and acceptance checks are complete.
609666

@@ -945,11 +1002,25 @@ For every slice:
9451002

9461003
- read the slice's acceptance criteria before changing code,
9471004
- run the relevant typecheck,
1005+
- run package boundary lint before any broad formatter pass,
9481006
- run focused tests,
9491007
- start the app when user-visible behavior changed,
9501008
- smoke test the feature,
9511009
- watch logs for one real usage cycle when the change affects background work.
9521010

1011+
Use these dry-run checks as gates:
1012+
1013+
```sh
1014+
pnpm exec biome lint packages/core
1015+
pnpm exec biome check packages/core
1016+
pnpm typecheck
1017+
```
1018+
1019+
If a slice touched another package, run the same lint/check command against that
1020+
package too. Do not mark a slice `passing` while Biome reports restricted import
1021+
violations in a touched package. Use `needs_validation` only for missing runtime
1022+
smoke coverage, not for known layer-boundary violations.
1023+
9531024
Typecheck and tests are necessary but not sufficient. The app must actually run.
9541025
Do not set `passes: true` in `REFACTOR_SLICES.json` until the acceptance checks
9551026
and smoke test have passed.

0 commit comments

Comments
 (0)