Files
insomnia/scripts/circular-references
Bingbing 61aedcf86e refactor: break main-process circular imports (git-service/plugin-window/plugin discovery)
## Background

The main process carried three circular import groups that `scripts/circular-references/known-violations.json` had to record:

- `main/git-service.ts` and `sync/git/repo-file-watcher.ts` imported each other because the `WorkspaceFileIssue` type lived in `git-service`, while the watcher that produces those issues imported the type back.
- `main/plugin-window.ts` reached `main/window-utils.ts` for `getMainWindow`, both directly and through `main/prompt-bridge.ts`.
- `main/templating-worker-database.ts` and `plugins/index.ts` imported each other because `plugins/index` lazily imported the sandbox-backed user-plugin export discovery from the main-only templating worker module.

## Changes

- Move `WorkspaceFileIssue` to `sync/git/repo-file-watcher.ts`, which owns the file issues, and update the renderer type imports.
- Add `main/window-registry.ts` to own `browserWindows` and `getMainWindow`, so `plugin-window`, `prompt-bridge` and `templating-db-auth` read the main window without importing `window-utils`. `window-utils` still writes the registry and drives the plugin window directly.
- Add `common/templating/user-plugin-export-discovery.ts` as the registration slot for the sandbox-backed discovery. `main/templating-worker-database` registers its implementation at module load, and `plugins/index` calls the registered function in the main process while keeping the protocol path in renderers. Calling it without registration throws an explicit error.
- Remove the five resolved cycles from `scripts/circular-references/known-violations.json`.
- Register the discovery stub through the new hook in the plugin-load-order QuickJS test, and assert the main-process registration contract in the templating-worker-database test.

## Testing

- `npm run check-cycle-references`: insomnia 13 -> 8 cycles, 0 new.
- `npm run type-check -w insomnia` and eslint on the changed files: clean.
- `npx vitest run` for the plugins suite, the templating-worker-database suites, plugin-window IPC authorization, and the window security/guard tests: 134 passed, 1 skipped.
- `npx vitest run` for the repo-file-watcher and import suites: 75 passed.
- `npm run build:electron-entrypoints`: succeeds.

## References

Follows #10496 in the circular-reference cleanup chain.
2026-11-03 11:57:55 +08:00
..