agentleFS
genex-gamesgenex-games/genex-desktop/.agents/skills/add-ipc-channel/SKILL.md

add-ipc-channel

Skill874 starsChanged 7 days agoMITView on GitHub

Add or change a renderer-to-main IPC channel (a new window.studio call) end to end - main handler, preload, typed API, fixture classification and tests. Use when the renderer needs a new capability from the main process or core.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 0 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Put the logic in StudioCore (src/main/studio-core.ts) or the service under src/main/core/ it delegates to, not in the handler, so it is …

    line 36
  2. Very specific:

    Renderer: - call window.studio.myThing(...) from the owning panel/hook.

    line 42
  3. Very specific:

    Docs: - if users can see the behaviour, update the owning docs/product/*.md page.

    line 43
  4. Very specific:

    Do not add assertions that read index.ts or the preload as text.

    line 66

≈ “Common” is an estimate: at least 1 in 5 of the 372,429 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Add an IPC channel

The renderer reaches main only through the fixed preload API. There is no generic invoke, no eval and no filesystem access from the page; every capability is one named call.

Files, in order

  1. Contract - src/shared/studio-api.ts: add the method to StudioApi with exact parameter and result types. Put shared payload types in a src/shared/*.ts module (browser-safe: no node:, no electron, no imports from src/main|preload|substrate).
  2. Channel map - src/shared/ipc-channels.ts: "studio:my.thing": "myThing" in STUDIO_INVOKE_CHANNELS and "studio:my.thing": { id: string } in StudioInvokePayloads (the payload the preload sends; the result is derived from StudioApi). A push stream from main is a STUDIO_PUSH_CHANNELS entry naming its on* call; a new UI event rides the existing studio:event push and is a UiEventMap key instead, and a new durable record is a CustomEventMap entry read through studio:events (the add-event-type skill). A method the harness calls is no channel either: it is a HarnessHostApi key in src/shared/harness-api.ts (docs/agent/recipes.md, Harness RPC method).
  3. Preload - src/preload/studio-bridge.ts: one line in the returned object, myThing: id => invoke("studio:my.thing", { id }). Keep it a named call; a push stream uses subscribe(channel, listener) like onTerminal.
  4. Main - the domain's registrar, src/main/ipc/<domain>.ts (composed by src/main/index.ts; a new domain gets its own register<Domain>Ipc(handle, deps) there): handle("studio:my.thing", payload => core.myThing(payload.id)); with no payload annotation: handle takes the payload and result types from the map, wraps the result as {ok,value}/{ok,error} and runs the fixture guard. A registrar owns no state: it takes the core and anything else it needs as explicit deps. Push with pushToRenderer. Validate the payload at this boundary (types are not checked at runtime); resolve paths by realpath inside an owned root; never accept a PID, URL to open or absolute path from the page unless the channel exists for exactly that and is native. Put the logic in StudioCore (src/main/studio-core.ts) or the service under src/main/core/ it delegates to, not in the handler, so it is testable in Node.
  5. Classify - src/main/dev/native-policy.ts: add the channel to the fixture-safe list (no account, dialog, download, external app or network) or to the native list. Both lists are checked against the channel map, so an unclassified channel fails npm run typecheck; at runtime fixture profiles refuse it too.
  6. Renderer - call window.studio.myThing(...) from the owning panel/hook.
  7. Docs - if users can see the behaviour, update the owning docs/product/*.md page.

Tests (red first)

  • Behaviour: test the core method or module directly. tests/helpers/core-lite.ts (coreLite()) gives a real StudioCore without a harness; use tests/helpers/studio-rig.ts only when the harness loop must run.
  • Handler wiring, when the handler does more than call the core (pushes, keep-awake, several calls): drive the registrar through the real typed handle() from createIpcHandle with recorders for its deps, as tests/conformance/main-ipc.test.ts does.
  • Hostile input: a table of bad payloads (missing fields, traversal ../, symlink escape, wrong types) asserting the call fails and nothing was written.
  • Policy: node --test tests/conformance/native-policy.test.ts tests/conformance/dev-policy.test.ts.
  • Contract: npm run typecheck (the map types both sides) and tests/conformance/ipc-contract.test.ts (the preload, main and the policy use exactly the map's channels).
  • Rendered check when UI changed: the verify-ui-via-dev-control skill.
npm test -- tests/conformance/native-policy.test.ts tests/conformance/<your-area>.test.ts
npm run verify:architecture   # browser boundary

Do not add assertions that read index.ts or the preload as text; test behaviour.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.