Skip to content

feat: load a project plugin module for an iOS target - #6693

Closed
janicduplessis wants to merge 24 commits into
mainfrom
feat/6680-plugin-ios-module
Closed

janicduplessis wants to merge 24 commits into
mainfrom
feat/6680-plugin-ios-module

Conversation

@janicduplessis

@janicduplessis janicduplessis commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Description

A project plugin on main is manifest-only: Stim reads stimPlugin.project and imports nothing, so a plugin can declare an Android build as a fixed command (#6631) and cannot serve an iOS build that needs logic, as Exact's does. This is slice S4 of the design, as amended by #6648, #6650 and #6666: a plugin's module is loaded for an iOS target and plugs into the host adapter in packages/stim-cli/src/integrations/plugin-ios.ts that the in-tree Exact module already uses.

Maintainer decisions this implements, quoted on #6599:

This pull request imports plugin code for the first time and rewrites the passage of LLP 0023 the maintainer approved, so it stays a draft for the maintainer to read.

Fixes #6680. Covers item 1 of #6678 (the shipped plugin's package name is checked before its module is imported).

Solution

Manifest. PROJECT_API_VERSION is 2 and Stim accepts kinds.project 1 and 2. A 1 manifest reads exactly as before (targets.ios still rejects it with the same message). A 2 manifest may declare targets.ios: {} and must then name module, a relative path of plain segments; module without targets.ios rejects the manifest. Detection, platforms and refusals still come from the manifest alone and stay synchronous.

When the module is imported. Only for an iOS operation (stim ios, --plan, a build, or a doctor that covers iOS, plain stim doctor included) in a root the registry selected the plugin for iOS, and only when no bundled integration recognises that folder as an application (or cannot read it).

  • The yield rule works per operation, so a native Android or Swift package folder that holds the plugin's markers still selects the plugin for iOS. There the plugin's ios() loader refuses with STIM_NO_PROJECT, naming the bundled project type, and its doctor reports a note; neither imports anything. Version 1 targets keep their per-operation yield unchanged.
  • A doctor is handed the operations its match was selected for (project-registry.ts), so stim doctor --platform android, or an unscoped doctor where a bundled integration won iOS, never imports the module of a plugin that also has an Android target.
  • The one import is in loadPluginIos (integrations/plugin-module.ts). A new lint rule, stim/computed-import, rejects an import() of a computed path anywhere else in packages/stim-cli/src, with the three existing ones listed in .oxlintrc.json. It does not see createRequire(...)(path).

Loading. loadPluginIos:

  1. For a shipped plugin, checks that the manifest's package name is @stim-cli/plugin-<name> for the entry that named it. The same check rejects the entry where manifests are read, so stim plugin list and stim doctor show it.
  2. Resolves the plugin directory and join(dir, module) with realpath and requires a regular file inside the directory, so .. (already refused by the manifest) and a symbolic link out are refused.
  3. Imports it by file URL through loadKind (kind check, factory check, 30 s limit).
  4. Calls createProjectPlugin(host) with one host object: root, the operation's abort signal, and exec(file, args, { timeoutMs, env }), which runs through runFileAsync in the root with no shell and resolves { code, stdout, stderr } for any exit.
  5. Wraps the returned ios so every call checks its result's shape on a structured clone, refuses a promise (and consumes its rejection), and reads the returned object only inside the guard, so a throwing getter is a refusal naming the plugin.

A refused or timed-out load aborts the host's signal, which ends any program the factory started through exec; exec rejects a timeoutMs that is not a positive number. A CLI command that imported a plugin module exits once its result and output are written (bin/cli.ts, through the same path a failing command already takes), so a timer the module left open cannot keep it running. stimd does not take that path; a handle a module leaves open there stays until stimd exits.

The result is an IosPluginSource for the existing pluginIosProject and pluginIosDoctor, with an offload that always says a plugin build does not run on a build machine. Any failure (missing file, path escape, import error, missing export or member, a throw, a wrong return shape, a program that is not an absolute path) is an error with code STIM_NO_PROJECT and a remedy, naming the plugin and the reason; it never falls back. A doctor load failure is one cost finding, not a failed doctor. Exact still registers and runs exactly as before.

Shipping and staleness.

  • build-plugins.ts (run by the tsdown build) copies each shipped plugin's files, without node_modules, to dist/plugins/<name>, and writes dist/shipped-plugins-digest.mjs, whose bytes are a sha256 over every copied file. The build id hashes the top-level *.mjs of dist, so it now changes when a shipped plugin does, without changing the id algorithm that other Stim versions compute for a dist. A stimd of the old build restarts on the new one as it does for any build change, and a build machine never reuses another build's plugin code.
  • A directory plugin's module, once imported, stays in the process (Node has no unload). loadPluginIos records a stamp of the canonical plugin directory's files (path, size, mtime) at the first import in a process and refuses the plugin in that process once the stamp changes, with a remedy to run the command from a terminal. An unreadable directory is a refusal. The stamp does not cover node_modules or entries whose name starts with a dot: an updated dependency there is served stale, and LLP 0023, the guide and the website say so. A CLI command imports in its own process, so this only stops a long-lived stimd from serving old code.

Public API. stim/plugin adds the types ProjectPluginModule, ProjectPluginHost, ProjectPluginTargets, ProjectPluginIos, ProjectPluginFinding and ProjectPluginIosTarget; ProjectPluginManifest gains module? and targets.ios?; PROJECT_API_VERSION goes from 1 to 2. plugin.api.txt changes by those lines only (57 added, 1 removed: the constant), and ProjectPluginModule is added to the report's implemented interfaces. The release notes carry the project 2 line the API gate asks for. stim plugin list --json reports api.project: 2.

stim plugin test. For a project plugin it now also checks that module names a file inside the plugin directory. It does not import the module; the kit for this kind keeps running in the CLI process, where the other kinds' worker isolation does not apply.

Documents. LLP 0023 "Frozen and experimental plugin kinds", LLP 0014 "Use fixed invocations" and LLP 0009 "Run the client build" are updated; stim guide api and the website's programmatic API page describe the iOS target. The api guide budget goes from 27500 to 28600 bytes for that text.

Before, LLP 0023:

  • Stim reads the manifest and imports no module of the plugin. Project
    detection is synchronous and runs in status, stop, logs, discovery and
    stimd; a detect() function would put plugin code in every one of them.

After, LLP 0023 (first bullet; four bullets follow it for the version rule, loading, staleness and the decisions):

  • Stim reads the manifest to detect a project, list its platforms and refuse
    an operation, and imports no module for any of them. Project detection is
    synchronous and runs in status, stop, logs, discovery and stimd; a
    detect() function would put plugin code in every one of them. A plugin's
    module is imported only to serve an iOS operation (a run, build, plan or
    doctor) on a root the registry selected that plugin for: never in a root of
    another project type, never in a root where the plugin yields to a bundled
    integration, and never for a command that only reads a project's type.
    Maintainer decision: "I think plugins can be code as long as we don't
    execute any code while running regular commands for projects of other
    types", 2026-11-28

LLP 0014 keeps its approved manifest-command passage and its closing paragraph word for word, including "The plugin passage is meant to keep the rule's purpose: the person who owns the machine chooses the program and its arguments, and neither the manifest rules nor Stim's lookup let a checkout replace them." It adds one paragraph after them for module builds, which says that purpose does not hold for a module's build:

A project plugin that declares kinds.project 2 builds its iOS target through its module (LLP 0023), which the machine's owner chose by naming the plugin in plugins. For each build the module returns the program, its argument list and its environment; the program is an absolute path and may be inside the checkout, as Exact's ./exact.mjs is, so it can run the project's own scripts. [...] The trust boundary here is which module the owner listed, not the shape of the command: the manifest rules above do not apply to a module's programs, and the purpose stated for them, that a checkout cannot replace the program, does not hold for a module's build. Maintainer decision: "Accept all", 2026-11-28 (comment), which accepted D1 as shown: "A plugin's module may run a program inside its own checkout". [...]

The plugins setting description in the settings registry drops "never imports its code" and says when a module is imported.

Choices the maintainer has not stated

Most consequential first.

  • The whole-folder rule: no plugin module is imported in a folder any bundled integration recognises as an application or cannot read, whatever operation is asked, and a doctor imports only for a platform the plugin was selected for. This is the pull request's reading of the maintainer's sentence about "projects of other types", not confirmed by the maintainer.
  • Plain stim doctor and stim ios --plan in the plugin's own root import the module, and so does the Desktop next-build plan, which stimd runs in its own process.
  • stimd refuses an edited directory plugin until it restarts, and no command restarts it; Desktop keeps refusing that plugin until stimd exits or moves to another build.
  • Module code runs in-process (the CLI's or stimd's) with no isolation. A CLI command that imported a module exits explicitly once its result is written.
  • host.exec runs any program, including a shell or a bare name found on PATH; only the build program ios.build() returns must be an absolute path.
  • The build and incremental receive the full operation environment, which is now part of the published types.
  • Version 2 makes an older Stim refuse the manifest (speaks project 2, this stim speaks 1: stim engine update).
  • The manifest field names module and targets.ios, targets.ios being an empty object, module required by and only with targets.ios, and a version 1 manifest still ignoring a module key as it did.
  • The refusal text for another integer: "this stim speaks 1 and 2", and the check name "stimPlugin.kinds declares project 1 or 2".
  • One factory export, createProjectPlugin(host), sync or async, called once per load (each operation), returning { ios }. The ProjectPluginIos members mirror the internal IosPlugin as merged, all required; doctor() returns ProjectPluginFinding (no code).
  • The host object: root, signal (the operation's, read through processContext), and exec resolving for any exit and rejecting on spawn failure, timeout or cancellation; cwd fixed to the root; env added to the operation's environment; timeoutMs required.
  • The build program must be an absolute path (it may be inside the checkout).
  • The load limit of 30 s for import plus factory, through loadKind.
  • STIM_NO_PROJECT as the code of every module failure, and its two remedies (fix the plugin and run stim plugin test, or for a shipped plugin update Stim).
  • stim doctor reporting a load failure as one cost finding.
  • A plugin iOS build is never cached or offloaded; a hosted simulator target stays as the adapter allows.
  • Staleness: a per-process stamp of the canonical plugin directory (path, size, mtime, outside node_modules and dot-entries) that refuses after a change, rather than a restart of stimd.
  • The digest file dist/shipped-plugins-digest.mjs as the way the build id covers shipped plugins, and copying a shipped plugin's whole folder without node_modules.
  • The lint rule's scope (packages/stim-cli/src) and its three listed exceptions.
  • stim plugin test checking the module path without importing the module, and its changed help text.
  • In LLP 0014, stating that the approved purpose sentence (a checkout cannot replace the program) does not hold for a module's build, as D1 implies, and placing the module paragraph after the approved passage instead of rewriting it.
  • The wording of the new LLP 0014, 0023 and 0009 passages, the plugins setting description, the guide text and the website section.

Not in this pull request

Test plan

  • plugin-ios-module.test.ts (new): the sentinel test calls every ProjectRegistry method, every load it hands out and doctor unscoped, for iOS and for Android, in React Native, Expo, native Android, Swift package and Exact roots, each with and without the plugin's marker, and a web root, with a configured plugin whose module writes a sentinel and throws; no sentinel, and stim ios in the native Android root with the marker refuses naming that type. A plugin with both targets imports nothing for an Android doctor in its own root or for an unscoped doctor in an Exact root holding its marker, and does import for an unscoped doctor in its own root. The native Android, Swift package and two-target rows fail against the integration code before the whole-folder rule. In the plugin's own root selectIos().load() refuses with STIM_NO_PROJECT naming the failure and the sentinel exists, and the doctor reports one finding. Other cases: a loaded module whose factory runs /bin/sh through host.exec in the root; a missing file, a symbolic link out, no factory, a throwing factory, no ios, a missing member and a wrong return shape each refuse naming the plugin; a non-absolute build program refuses; a shipped plugin with another package name is refused before import; after a load, pointing module at another entry that imports the same changed helper makes the next load refuse; an unreadable plugin directory refuses; an async member (whose promise later rejects, with no unhandled rejection), an ios getter that throws and host.exec with timeoutMs: 'unbounded' each refuse naming the plugin.
  • plugin-ios-module.integration.test.ts (new, real processes): a factory that starts sleep 300 through host.exec and then fails leaves no child behind; removing the abort makes it fail.
  • shipped-plugin-name.test.ts (new): a shipped entry whose package.json names another package is rejected where manifests are read. Breaking the loader to import from platforms() fails the sentinel test.
  • shipped-plugins.test.ts: the build copy includes a module's files, leaves out node_modules, and stimBuildId of the dist changes when a plugin file changes.
  • project-registry.test.ts: version 2 manifest rules (iOS target without module, module without iOS target, .. path, absolute path, iOS target with fields). One existing row changed: "another integer" now declares project 3, since 2 is accepted.
  • plugin-command.integration.test.ts: plugin test passes a contained module without importing it and fails a module linked out of the directory. The api.project expectation is 2.
  • test/runtime-floor.mjs (built package): a plugin whose module starts a setInterval lets ios --plan exit. With the sentinel plugin configured, status, ios --plan, android --plan and stop in a React Native app that holds the marker leave no sentinel; ios --plan in the plugin's root refuses with STIM_NO_PROJECT and the sentinel exists.
  • scripts/oxlint/stim.test.mjs: the new rule accepts literal imports and rejects computed ones.
  • Unchanged and passing: plugin-android.test.ts, exact-ios.test.ts, exact-offload.test.ts, exact-offload-worker.integration.test.ts, guide.test.ts, guide-budget.test.ts.
  • Checks: pnpm run format:check, lint, build, typecheck, knip, test:runtime, node scripts/build-compat.mjs (record updated, no compatibility bump: plugin builds never reach a build machine), node scripts/plugin-api-report.mjs, node scripts/dist-closure.mjs --enforce cli,ios,android,status,status-command,agent-device,net,agent-driver,api.

Real run on a Mac (xcodebuild -version: Xcode 27.1; simulator iPhone 18 Pro on iOS 27.0), in a scratch STIM_HOME with iosSimulatorApp and androidEmulatorApp set to stim-desktop, daemon.mode off and a scratch STIM_ENGINE_ROOT. The fixture is a plugin directory whose module runs xcrun --sdk iphonesimulator --show-sdk-path through host.exec and returns a build of the app's own build.sh, which compiles a SwiftUI @main app with xcrun swiftc for the simulator and signs it ad hoc:

Step Observed
stim plugin list the directory listed as project 2 selected by plugins; "This Stim speaks ... project 2"
stim plugin test <dir> 10 of 10 checks passed, including the module path check
stim ios --plan app dev.stim.fixture6680, cache miss: the fixture builds with its own script, builds on this machine
stim ios owned simulator created and booted, build ok (1.5s), installed, launched, "process alive 3s after launch"; launchctl list in the simulator shows UIKitApplication:dev.stim.fixture6680
stim status the workspace running with the app (labelled bare, see above)
stim logs --errors no matching records
stim stop simulator shut down
Shipped: the fixture as packages/plugin-fixture (@stim-cli/plugin-fixture), built, pnpm pack, tarball extracted and run with plugins: ["fixture"] plugin list shows fixture project 2; ios --plan and stim ios build, install and launch the same app from dist/plugins/fixture; status, logs --errors, stop as above. The folder was removed afterwards.
Sentinel plugin configured, in an Expo app (this repository's apps/mobile), without and then with the plugin's marker file stim status, stim doctor, stim ios --plan and stim stop all exit 0 and leave no sentinel
Final head, fixture and sentinel plugins both configured, the sentinel's root registered as a workspace stim ios on the fixture builds and launches again; stim status (all workspaces), stim doctor, stim ios --plan, stim stop in the Expo app and stim gc (preview) leave no sentinel
Native Android folder (settings.gradle.kts, gradlew) and Swift package folder (Package.swift), each holding the sentinel plugin's marker stim doctor and stim doctor --json exit 0 with the note "The plugin stim-plugin-sentinel does not run here"; stim ios --plan refuses: STIM_NO_PROJECT: The plugin stim-plugin-sentinel does not build the Sentinel project at ... for iOS: Stim also recognises this folder as a native Android project, and it runs no plugin code in a folder a bundled integration serves. (the Swift folder names "a Swift package project"); no sentinel
Plugin with an Android and an iOS target, stim doctor --platform android in its root exit 0, no sentinel
Plugin whose module starts a setInterval, stim ios --plan in its root prints the plan and exits 0 at once
Plugin whose factory awaits host.exec of sleep 300 stim ios --plan refuses after 30 s with ... the module did not load within 30000ms.; the sleep process is gone
Fixture stim ios again on that build built in 1.4 s, launched, status records the build; stop and worktree remove delete the simulator
Sentinel plugin's own root stim ios --plan and stim ios --json refuse with STIM_NO_PROJECT: The plugin stim-plugin-sentinel cannot serve the Sentinel project at ...: the sentinel module ran. and its remedy; the sentinel names the CLI process; stim doctor reports "The plugin stim-plugin-sentinel cannot load"

@janicduplessis janicduplessis added area: cli packages/stim-cli, including its README and guide area: core packages/core area: website website/ area: docs docs/ and root documents ci-full run the macOS, Windows, Desktop and license jobs on this pull request labels Nov 29, 2026
@janicduplessis

Copy link
Copy Markdown
Collaborator Author

Fresh review of fa53d38. Verdict: findings. The loader, containment, name check, version handling, build id and documents hold up well. One finding breaks the maintainer's rule as the issue states it, and four more are smaller.

I ran the worktree build in scratch Stim homes with daemon.mode off and a sentinel plugin whose module writes a file and then throws. I did not repeat the real iOS build and launch.

Findings

1. Breaks the rule: plugin code runs in a native Android or Swift package root that holds the plugin's marker.
plugin-projects.ts#L163-L184, project-registry.ts#L139-L146

The yield rule works one operation at a time. In a folder where a bundled integration serves Android or macOS but not iOS, the plugin still serves ios.

  • With settings.gradle.kts + gradlew + the marker (native Android selected for android), plain stim doctor, stim doctor --json and stim ios --plan all import the module. The sentinel appears and doctor prints "The plugin ... cannot load".
  • The same happens with Package.swift + the marker (Swift package selected for macos).
  • stim doctor --platform android in the same folder imports nothing. That confirms the cause: an unscoped doctor loads the doctor of every provider at the root.

The unit sentinel test's native Android and Swift rows do not hold the marker, so it misses this. React Native and Expo roots with the marker are clean, because those integrations serve iOS.

These texts say this cannot happen:

  • LLP 0023, L101-L103: "never in a root of another project type, never in a root where the plugin yields to a bundled integration".
  • The release note: "never in a root of another project type".
  • The website: "every command in a project of another type read the package.json alone".
  • The api guide: "never in another project's root".
  • The PR body: "or other bundled root that also holds the markers selects the bundled integration".

One possible fix: the plugin yields every operation at a root where any bundled integration recognises an application. Either way, the maintainer should pick the rule.

2. Staleness: the stamp is keyed by the module file, not the plugin directory.
plugin-module.ts#L236-L244

In one process, I loaded a plugin whose a.mjs imports lib/helper.mjs. Then I changed the helper and pointed module at b.mjs, which imports the same helper. The next load returned b running the old helper, with no refusal: Node had cached the helper.

LLP 0023 says a process "refuses that plugin once a file of its directory ... changes". Keying loaded by the plugin's real directory would match that text.

Two smaller gaps in the same rule:

  • The stamp skips node_modules and dot entries, so a module that lives there, or a dependency in node_modules, is served stale without a refusal.
  • treeStamp runs outside fail(), so an unreadable subdirectory surfaces as an unexpected error rather than a refusal that names the plugin.

3. Hang: a module that keeps a handle open stops the command from exiting.

A module whose top level calls setInterval(() => {}, 1000) and returns a valid ios makes stim ios --plan print its plan and then never exit. My 90 s alarm killed it.

The 30 s limit covers only the import and the factory. Nothing names the plugin. In stimd this does no harm, but every CLI command in that root hangs.

4. A child the module started outlives the refused command.
plugin-module.ts#L245-L262

A factory that awaits host.exec('/bin/sh', ['-c', 'exec sleep 300'], { timeoutMs: 600000 }) is refused at 30 s with "did not load within 30000ms". The sleep keeps running, reparented to PID 1, until it ends on its own.

loadKind's timeout does not abort the signal handed to the host. Ctrl-C during the same exec does kill the child, so cancellation itself works.

Related: exec accepts timeoutMs: 'unbounded' at runtime, because the executor's own error says so, while ProjectPluginHost documents a number.

5. Wrong refusal: an ios getter that throws ends as "Unexpected error: ... Report it at ...".
plugin-module.ts#L264-L268

result.value.ios, the member scan and cacheIneligible are read outside any guard, so the refusal neither names the plugin nor carries STIM_NO_PROJECT. This is contrived but cheap to wrap.

6. Document says less than the code: the plugins setting description.
settings-registry.ts#L710

It says the module is imported "only to build and run an iOS app". stim doctor and stim ios --plan also import it.

7. Minor notes (not blocking).

  • The lint rule does not see createRequire(...)(path), which other CLI files use.
  • Each of the three exempt files is exempt as a whole. All three computed imports there are Stim's own engine or kit worker, so the exemptions are justified.
  • stim plugin list accepts a shipped plugin whose package name does not match, and a module path that leaves the directory. Only the load refuses them, and plugin test refuses the second.

What checked out

  • Sentinel. No sentinel appeared in a plain folder, React Native and Expo roots with and without the marker, this repository's apps/mobile, or the plugin's own linked worktree for status, status --json, stop, logs, plugin list, plugin test <dir>, settings set plugins and gc --dry-run. The same holds for doctor, ios --plan and android --plan everywhere except the roots in finding 1. worktree add and worktree warm were clean too. In the plugin's own root, only doctor and ios --plan import the module, and both refuse naming it.
  • Lint rule. Adding import(p) and import(`${p}/x.mjs`) to another file fails oxlint with stim(computed-import).
  • Containment. All of these are refused before import: ../x.mjs, an absolute path, a/../../x.mjs, ./x.mjs, a NUL, a backslash, a symlinked directory or file pointing outside, a directory, and a path over the name limit.
  • Race window. The import uses the realpath result, so exploiting the window between the check and the import needs write access to the plugin directory. That access already lets you replace the module.
  • Shipped name check. A shipped dist/plugins/evil named @stim-cli/plugin-other refuses before import, for both ios --plan and doctor.
  • Trust model actually enforced.
    • When: registry selection.
    • Which file: realpath containment, plus the package name for shipped plugins.
    • Nothing else. The module runs in the CLI or stimd process, with the full environment, and can spawn anything. host.exec accepts a bare sh -c and the program may cd out of the root.
    • LLP 0014 and 0023 describe this correctly. The trust boundary is the module the owner listed.
  • Version handling. A version 1 manifest with a module key is accepted and ignored, as on main. Version 1 with targets.ios gives main's message. Integers 3 and 1.5 are refused with "this stim speaks 1 and 2". The string "2" reads "speaks project 2, this stim speaks 1 and 2", which is confusing, but main has the same shape. The check name changed for version 1 manifests too ("project 1 or 2"), and the PR lists it as a choice.
  • Build id. It changes when one byte of a shipped plugin file changes, and the digest file and dist/plugins ship in the pnpm pack tarball.
  • Documents. Every maintainer quote is word for word and links the right comment. The approved LLP 0014 passage is unchanged; the diff only adds a paragraph after it.
  • Release notes and API report. docs/releases/unreleased.md and plugin.api.txt agree: 57 lines added and 1 removed, with the project 2 line under "Removed (breaking)".
  • PR description. It follows the template and has no iteration history.

Choices the maintainer has not stated, most consequential first

  1. Whether a plugin yields a whole root, or only the operations a bundled integration serves (finding 1).
  2. Plain stim doctor importing the module, and Desktop's next-build plan importing it inside stimd.
  3. The stamp rule: stimd refuses an edited plugin until it restarts, and no command restarts it.
  4. Keeping the module in-process with no isolation, so a hang, a handle or a crash in plugin code is a hang or crash of the command or of stimd.
  5. host.exec running any program, including a shell, and a bare name resolved on PATH. The build program must be absolute; exec's program need not be.
  6. The build and incremental receiving the full operation environment, which is now part of the published types.
  7. PROJECT_API_VERSION 2 making an older Stim refuse a version 2 manifest.
  8. The rest the PR already lists: field names, factory name, the 30 s limit, the STIM_NO_PROJECT code and remedies, the doctor cost finding, the digest file, lint scope, and plugin test not importing.

Checks at this head

  • Exit 0: format:check, build, knip, test:runtime, node scripts/build-compat.mjs, node scripts/plugin-api-report.mjs (reports unchanged), and the lint and typecheck steps after the failing one.
  • Exit 1: lint and typecheck, each with the one unused chmodSync in gc-dependencies.test.ts.
  • Tests, all exit 0: plugin-ios-module, project-registry, shipped-plugins, plugin-command.integration, plugin-android, exact-ios, exact-offload, exact-offload-worker.integration, guide, guide-budget and the oxlint rule tests.

@janicduplessis

Copy link
Copy Markdown
Collaborator Author

Fresh review of e889314 (round 2). Verdict: findings. The round 1 fixes hold: the whole-folder rule, doctor scoping, the abort on a refused load, the guarded getters, the promise refusal and the explicit exit all work as described, and version 1 plugins behave exactly as on main. One finding still lets plugin code run in a folder a person would call a project of another type. The rest are document gaps and smaller notes.

I ran the worktree build in a scratch Stim home (daemon.mode off, scratch STIM_ENGINE_ROOT, both device apps set to stim-desktop) and a build of origin/main (ed989cd) for comparison. I booted no device and did not repeat the real iOS build.

Findings

1. Breaks the rule: a native Xcode project that Stim does not count as an iOS app still runs the plugin's module.
projects.ts#L179-L195, native-xcode-project.ts#L397-L431

bundledApplication reports a folder only when an integration's application is true or a validation says unreadable. The native Xcode integration sets application to false, with not-an-app, for any container that has no iOS application target. So a folder holding a macOS-only .xcodeproj (I used the e2e NativeAcceptance fixture with SDKROOT = macosx and SUPPORTED_PLATFORMS = macosx) plus the plugin's marker imports the module for stim doctor, stim doctor --json, stim doctor --platform ios and stim ios --plan. The sentinel appears and doctor prints "The plugin stim-plugin-sentinel cannot load". From reading the code, a framework-only Xcode project takes the same path; I did not run that one.

This matches the pull request's literal wording ("recognises as an application"), since the native Xcode integration does not call that folder an application. But a person would call it a native Xcode (macOS) project, a project of another type, so it conflicts with the maintainer's sentence. It also contradicts the website, which says every command "in a project of another type" reads the package.json alone. One fix: count any non-null match from the native Xcode and native Android integrations as recognition, since they return null when their files are absent; React Native still needs its application flag because it matches every folder with a package.json.

A constructed variant: a root that is executable but not listable (chmod 111) holding an iOS Xcode project and the marker also imports, because the native Xcode integration returns null when readdirSync(root) fails instead of reporting unreadable. LLP 0023 says no module loads where a bundled integration "cannot read" the folder; here the integration cannot read it and says nothing. Not realistic, noted for completeness.

2. Document says less than the code: the staleness stamp.
plugin-module.ts#L45-L61, LLP 0023

In one Node process, loading a plugin twice from source with a change in between:

Change Next load
entry renamed and module updated refused
imported helper changed refused
file added, file removed refused
mtime only (touch) refused
directory or a subdirectory unreadable refused, naming the plugin
change reverted to the original bytes refused (the mtime differs)
the module writes a file into its own directory on load the next load in that process is refused
helper under a dot folder stale code served
helper under node_modules stale code served
helper in a subfolder that is a symbolic link to a folder outside stale code served
plugin directory replaced by a symbolic link to an edited copy fresh code (new real path)
same size, mtime restored by hand stale code served (contrived)

The documents name the dot-entry and node_modules gaps. They do not name a symbolic link inside the plugin directory (the walk stats the link and does not descend), nor a helper the module imports from outside the directory. Both serve stale code with no refusal.

On "refuses forever": in stimd every refusal lasts until stimd exits, including after a revert or a plain touch, which the documents state. They do not state that a module which writes into its own directory (a cache, a log, a build tree) makes stimd refuse that plugin after its first operation. The walk also has no size bound and runs on every load, so a plugin directory that holds a large build tree is walked in full each time. Neither blocks; both deserve a sentence in LLP 0023 or the guide.

3. Document says less than the code: what host.exec runs.
project-plugin.ts#L62-L66

ProjectPluginHost.exec says file is "an absolute path or a bare name on PATH". A relative path also runs: host.exec('./x.sh', [], { timeoutMs: 2000 }) ran a script in the project root. D1 allows running a program inside the checkout, so the behaviour is within the decision, but the published doc comment should say it, or exec should refuse it.

4. Document says more than the code: the website.
programmatic-api.md#L256-L265

  • "a symbolic link to a file outside it, rejects the plugin": stim plugin list still lists such a plugin as project 2 selected by plugins; a load refuses it and stim plugin test fails its module check (9 of 10, exit 1). "refuses to load the plugin" would be accurate.
  • The list of bundled types that block plugin code omits native Xcode projects, and the macOS case in finding 1 is not covered at all.

5. Document says more than the maintainer stated: rules in LLP 0023 not labelled as the pull request's own.
LLP 0023

LLP 0023's closing list of the pull request's choices names the factory, host members, field names, members, the 30 s limit, the refusal code, the whole-folder rule, the explicit exit, the stamp rule, the digest file and plugin test. These rules stated in the same section are missing from it: plain stim doctor and ios --plan importing the module, stimd importing a module for Desktop or phone operations, module code running with no isolation, and a plugin's iOS build never being cached or offloaded. The description lists them as choices, so only the document needs the labels. For stimd importing, comment 7247747494 ("I think i am actually fine with machine wide processes loading plugins, lets avoid when we can, but i don't want to keep stuff in core from plugins") is the nearest maintainer statement; it answered the machine-wide seam (D5), and the documents do not cite it.

6. Minor.

  • host.exec with timeoutMs: NaN refuses with "not null", because describe goes through JSON.stringify.
  • A folder with the plugin's marker and a committed web.url (a browser web root) imports the module for plain stim doctor and stim ios --plan. Browser web matches every folder, so I read this as intended, but it is another unstated reading of "projects of other types" (see choice 2 below).

What checked out

  • Sentinel rule (a sentinel plugin whose module writes a file and throws, and a second plugin with an Android command target and an iOS module, each run alone). No sentinel in React Native, Expo, native Android, Swift package, Exact and iOS Xcode roots, with or without the marker, nor in a monorepo root, its React Native app subfolder holding the marker, a symbolic link to the React Native root, or a React Native root whose package.json is unreadable, for status, status --json, stop, logs, doctor, doctor --json, doctor --platform ios|android, ios --plan, android --plan, plugin list, plugin test <dir> and gc --dry-run. Native Android and Swift package roots with the marker print the "does not run here" note and ios --plan refuses naming the type. settings set plugins, worktree add, worktree warm and worktree remove in a plugin repository and in a marked React Native repository import nothing. In the plugin's own root (plain, package.json-only, a monorepo subfolder, a linked root, an unreadable root) only doctor, doctor --json, doctor --platform ios and ios --plan import, and doctor --platform android with the two-target plugin imports nothing.
  • Version 1. With a manifest-only plugin with an Android command target, the same 25 roots and 13 commands give the same exit codes and refusal codes on this branch and on origin/main, and the same ios --plan, android --plan, status, stop and logs output. The plain stim doctor text in the plugin's root differs only in the Stim home path; the other doctor outputs I compared by exit code and refusal code only. Only plugin list ("project 2") and plugin test (the check name "project 1 or 2") differ, as the description states.
  • Robustness. Factory: a throw, a rejection, a wrong type, a throwing ios getter, a throwing member getter, a throwing cacheIneligible getter, a Proxy that throws on every trap and a non-function export each refuse at once with STIM_NO_PROJECT naming the plugin; a never-resolving factory refuses at 30 s. Members: a throw, a rejected or never-resolving promise, a thenable whose then getter throws, a wrong type, a returned object with a throwing getter, a value that cannot be cloned and a relative build program each refuse naming the plugin; an async doctor becomes one finding; no unhandled rejection in any case. A 200 MB string is accepted (no size bound, which I do not count as a defect). host.exec: a missing program, a negative, NaN or string timeoutMs, and missing options refuse; a child that ignores SIGTERM and backgrounds a sleep is gone, with its grandchild, after a 1.5 s timeoutMs and after the 30 s load limit; an exec called after the load was refused rejects without spawning. Ctrl-C (SIGINT to the CLI) during ios --plan while the factory awaits a child that ignores SIGTERM and SIGINT exits 130 at once, and the child and its grandchild are gone. A synchronous infinite loop in module code is not bounded, which the description lists as in-process execution.
  • Explicit exit. ios --plan and ios --plan --json with a module that leaves a setInterval running exit 0 at once with byte-identical output to a module without one. doctor --json carrying 3 MB of plugin findings, piped to a reader that waits 4 s, delivers all 3,181,174 bytes as valid JSON, with and without the timer, and plain doctor delivers its 3 MB too. The flag is set only by loadPluginIos, so commands that import nothing take the old path. stimd starts through __stimd, which exits before main is defined, and nothing in src/stimd calls main, so stimd never reaches the explicit exit. I could not exercise a full stim ios run (no device boot), so cleanup after a real launch with a module loaded is not verified here.
  • Containment and shipped name check. containedModule is unchanged since round 1, so its path cases rest on that review, and a module linked out of the directory still refuses. The manifest-read package name check is new since round 1; I did not exercise it against a built dist and rely on shipped-plugin-name.test.ts, which passes.
  • Mutations. Each of these fails its test and was restored at once: dropping the bundledApplication call (the sentinel test), dropping load.abort() (the integration test), keying the stamp by the entry file (the stamp test), skipping the promise refusal (the async member test), and letting a doctor ignore its operations (the two-target test). I did not mutate bin/cli.ts, which needs a rebuild of dist.
  • Documents. Every Maintainer decision: quote the diff adds to LLP 0014 and 0023 ("I think plugins can be code ...", "Accept all" with D1, D2 and D8 as shown) matches comments 7242137981 and 7248276376 word for word, checked by string search, and links the right comment. The approved LLP 0014 passage and its closing paragraph are unchanged; the diff adds one paragraph after them. LLP 0023 labels the whole-folder rule, the explicit exit and the stamp rule as the pull request's own.
  • Description. It follows the template, matches the diff and what I observed, and carries no history of review rounds.

Choices the maintainer has not stated, most consequential first

  1. The whole-folder rule as the reading of "projects of other types", and its boundary: a folder counts as another type only when a bundled integration calls it an application or cannot read it, so a macOS or framework-only Xcode project does not count (finding 1).
  2. A folder with the plugin's markers and a browser web web.url counts as the plugin's own project, so plain stim doctor there imports the module.
  3. Plain stim doctor and stim ios --plan in the plugin's own root import the module, and so does Desktop's next-build plan inside stimd (comment 7247747494 accepts machine-wide processes loading plugins, "lets avoid when we can", for the machine-wide seam; whether that covers these operations is the maintainer's call).
  4. stimd refuses a directory plugin after any change to its files, a revert or touch included, until stimd exits, and no command restarts it.
  5. Module code runs in the CLI or stimd process with no isolation; a command that imported a module exits explicitly once its output is written.
  6. host.exec runs any program, including a shell, a bare name on PATH and a path relative to the project root; only the build program must be absolute.
  7. The build and incremental receive the full operation environment, now part of the published types.
  8. PROJECT_API_VERSION 2 makes an older Stim refuse a version 2 manifest.
  9. The rest the description already lists: field names, the factory name, the 30 s limit, STIM_NO_PROJECT and its remedies, the doctor cost finding, the digest file, copying a shipped plugin's folder without node_modules, the lint rule's scope, and plugin test not importing.

Checks at this head

Exit 0 for each: pnpm run format:check, pnpm run lint, pnpm run build, pnpm run typecheck, pnpm run knip, pnpm run test:runtime, node scripts/build-compat.mjs, node scripts/plugin-api-report.mjs, and pnpm test on plugin-ios-module.test.ts (17 tests), plugin-ios-module.integration.test.ts (1), shipped-plugin-name.test.ts (1), shipped-plugins.test.ts (4), project-registry.test.ts (39), plugin-command.integration.test.ts (9), plugin-android.test.ts (9), exact-ios.test.ts (24), guide.test.ts (102), guide-budget.test.ts (1) and scripts/oxlint/stim.test.mjs (60).

Not verified: a full stim ios build and launch with a module loaded, an ios member called after the operation was cancelled, stimd and Desktop behaviour (daemon off throughout), the shipped package name check against a built dist, a mutation of the explicit exit in bin/cli.ts, Windows and Linux.

@janicduplessis

Copy link
Copy Markdown
Collaborator Author

Coordinator note: stepping back from this pull request instead of running a third fix round.

Two review rounds in a row found confirmed problems in code the previous round had added (the round 1 and round 2 review comments above, plus two adversarial passes whose findings are summarised below). An independent read of the issue, the diff, both rounds and the decision documents concluded that patching will not converge, because three of the four classes of findings come from two choices in the approach:

  • Plugin code runs inside the CLI and stimd process, called synchronously on live objects. The staleness stamp, the promise and clone guards and the explicit process exit each approximate a property the runtime does not give: a fresh module graph, plain data, and nothing outliving the operation. Round 2 found a nested rejected promise that still ends the process, a refused member whose child process survives, and stale code through a symlinked subfolder. A module that writes to stdout, calls process.exit() or loops synchronously is the same class and has no in-process guard.
  • The boundary is defined negatively, through each bundled integration's notion of an application. Round 1 found native Android and Swift package folders, round 2 a macOS-only Xcode project and an unlistable root; a plain Node project holding the marker is another, since the React Native integration matches every folder with a package.json.

The path taken, which stays inside the maintainer's decisions on #6599:

  1. A preparation pull request with the parts both rounds cleared: the computed-import lint rule, shipping a shipped plugin's files with a digest that changes the build id, and the shipped package-name check where manifests are read.
  2. An internal refactor: the members of the internal IosPlugin interface become awaitable, with the in-tree Exact integration's behaviour unchanged.
  3. A new loader pull request: manifest version 2 with the module run in a worker thread, the mechanism the transport and agent-driver test kits already use (kit-host.ts, kit-worker.ts), so that only cloneable data crosses, a fresh worker runs fresh code, and a crash, an exit, a hang or an open handle ends only the worker. The stamp, the clone and promise guards and the explicit exit are not carried over.

The boundary rule for step 3 goes to the maintainer, because both candidate rules are readings of "regular commands for projects of other types": the whole-folder rule this pull request implemented, or "only for iOS work in a folder that holds every marker of the plugin, and only when no bundled integration builds iOS there", which is enforced in one place (the registry's iOS selection) and does not depend on integration internals.

This pull request will be closed when the preparation pull request is open; its branch stays for the commits that move.

@janicduplessis

Copy link
Copy Markdown
Collaborator Author

Closed in favour of the split described in the coordinator note above: the preparation is #6703, the awaitable members are #6702, and a new loader pull request follows for #6680. The branch stays for reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli packages/stim-cli, including its README and guide area: core packages/core area: docs docs/ and root documents area: website website/ ci-full run the macOS, Windows, Desktop and license jobs on this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Load a project plugin's module for an iOS target

1 participant