Skip to content

feat(cli): load a native application and run it from the CLI - #213

Open
chenxin-yan wants to merge 6 commits into
feat/effect-native-corefrom
feat/effect-native-cli-184
Open

chenxin-yan wants to merge 6 commits into
feat/effect-native-corefrom
feat/effect-native-cli-184

Conversation

@chenxin-yan

@chenxin-yan chenxin-yan commented Oct 2, 2026 •

Copy link
Copy Markdown
Owner

Closes #184. Stacked on #211 (→ #207 → #205).

Adds loadable native applications and the CLI that runs them.

What changed

  • @mitome/core: defineMitome(options). This typed producer composes:

    • an ordinary program,
    • native infrastructure Layers,
    • Providers, with a Default Model and ordered fallbacks,
    • an explicit CLI parseInput/renderResult mapping,
    • optional process-local serving Hosts.

    Requirements that are left open are compile errors (see test/application.types.ts). The original program, Layer and Provider types are preserved.

  • acquire() works in this order:

    1. Validates the selection before acquiring anything.
    2. Builds infrastructure once.
    3. Provisions the Model lazily. An explicit --model never falls back. Configured fallbacks are tried in order, and each failed attempt is released before the next.
    4. Unwinds a partial startup.
    5. Becomes ready only once every Host has started.
  • Application:

    • Serves fresh application-owned Sessions. Each Turn binds its own Turn Scope, never the acquisition Scope.
    • Retains idle Sessions until close or shutdown.
    • Reports a serving Host failure without restarting it or touching healthy Hosts.
    • Shutdown closes admission, cancels and drains all owned work, and only then releases the Model and infrastructure. It is idempotent, and the library never exits the process.
  • CLI commands: mitome run --app <file> [--provider] [--model] [--grace] [input], mitome providers and mitome auth status|login|logout. All load the same --app default export; there is no implicit discovery.

  • CLI output and exit behaviour:

    • stdout carries only the rendered result. Logs and defects go to stderr.
    • --grace (default 5s) bounds cleanup after a signal, after normal completion, and after a failed startup. Expiry exits 1.
  • Docs: new applications.mdx and cli.mdx. CONTEXT.md no longer lists the deleted vocabulary. Codex credential errors now name the real auth login command.

Review

The work went through one design review, an initial implementation, and three rounds of independent verification plus spec, standards and simplicity review. That found and fixed:

  • Session close could free shared dependencies early. Session.close detached its Scope before draining, which could release them under a running cleanup.
  • stdout was not clean. Logs and runtime defects were printed to stdout.
  • --grace didn't always apply. It covered only signals; normal completion and failed-start cleanup are now bounded too.
  • A failing shutdown notification skipped resource release.

Each fix has a regression test that fails without it.

Known limitation (documented in cli.mdx): when a native Layer fails while it is being built, Effect rolls back that Layer's own resources before the application can start shutting down. If that rollback hangs, --grace only bounds it after SIGINT/SIGTERM.

Verification

  • bun run build|check|test -- --force all exit 0 (core 104, cli 19, providers 381, create-mitome 11 tests).
  • Independent offline runs of the compiled binary against a scripted-LanguageModel fixture, with no credentials and no network:
    • one-shot runs from an argument and from stdin;
    • unknown, unqualified or mismatched selection errors, with nothing acquired;
    • offline providers and auth status;
    • failed-start unwinding, including a held release that is bounded by grace;
    • a failing program;
    • SIGINT drain, exiting 130.

Not exercised: the interactive OAuth auth login flow, and real Providers over the network.

Review in cubic

@pullfrog

pullfrog Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Run failed. View the logs →

Pullfrog  | Rerun failed job ➔ | View workflow run | via Pullfrog | Using gpt-6-astra | 𝕏

@chenxin-yan
chenxin-yan added this pull request to stack #212 October 2, 2026 09:52
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4e752b1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
@mitome/core Minor
@mitome/cli Minor
@mitome/providers Minor
create-mitome Minor
@mitome/cli-darwin-arm64 Minor
@mitome/cli-darwin-x64 Minor
@mitome/cli-linux-arm64 Minor
@mitome/cli-linux-arm64-musl Minor
@mitome/cli-linux-x64 Minor
@mitome/cli-linux-x64-musl Minor
@mitome/cli-win32-arm64 Minor
@mitome/cli-win32-x64 Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 32 files

Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

Re-trigger cubic

Comment thread packages/cli/src/index.ts Resolved
Comment thread packages/core/src/application.ts Resolved
Comment thread CONTEXT.md Resolved
Comment thread packages/cli/test/command.test.ts Resolved
Comment thread CONTEXT.md Resolved
Comment thread apps/docs/content/docs/applications.mdx Resolved
@pullfrog

pullfrog Bot commented Oct 2, 2026

Copy link
Copy Markdown

Run failed. View the logs →

Pullfrog  | Rerun failed job ➔ | View workflow run | via Pullfrog | Using gpt-6-astra | 𝕏

@pullfrog

pullfrog Bot commented Oct 6, 2026

Copy link
Copy Markdown

Run failed. View the logs →

Pullfrog  | Rerun failed job ➔ | View workflow run | via Pullfrog | Using gpt-6-astra | 𝕏

@chenxin-yan
chenxin-yan force-pushed the feat/effect-native-cli-184 branch from 6bcb8d2 to 0a13bbb Compare November 1, 2026 00:59
chenxin-yan added a commit that referenced this pull request Nov 1, 2026
Address a #214 review finding: the Approval channel test bounds its poll
and asserts one request appeared, so a Turn that never asks fails at the
assertion instead of the 15s runner timeout. (The review's other point,
building before the binary tests, is fixed in #213's test script.)

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes
Reviewed the supplied incremental delta from 6bcb8d2 to 0a13bbb, limited to the CLI test script.

  • Added a pre-test binary build. Changed the CLI test command to compile dist/local/mitome before Vitest, preventing package-local tests from exercising an absent or stale executable.
  • Verified both execution paths. All 19 CLI tests passed through Turbo and through direct bun run test after workspace prerequisites were built.

Pullfrog  | View workflow run | Using gpt-6-astra | 𝕏

@chenxin-yan
chenxin-yan force-pushed the feat/effect-native-cli-184 branch from 0a13bbb to 7f20647 Compare November 1, 2026 01:12
chenxin-yan added a commit that referenced this pull request Nov 1, 2026
Address a #214 review finding: the Approval channel test bounds its poll
and asserts one request appeared, so a Turn that never asks fails at the
assertion instead of the 15s runner timeout. (The review's other point,
building before the binary tests, is fixed in #213's test script.)
Add defineMitome to @mitome/core: a typed producer composing an ordinary
program with shared infrastructure, Providers, Default and fallback Models,
an explicit CLI mapping and serving Hosts. Unclosed requirements are compile
errors. acquire builds infrastructure once, provisions the selected Model
lazily with ordered configured fallback, serves explicit fresh
application-owned Sessions, binds each Turn's own Scope, unwinds partial
startup, isolates serving-Host failures and shuts down by closing admission
and draining owned work before releasing infrastructure.

The mitome CLI gains run, providers and auth status|login|logout, each
loading the default export of an explicit --app file. run is one-shot with
explicit input/output mapping and a --grace bound on signal shutdown.
Codex credential remedies name the shipped auth command; docs, READMEs and
the glossary describe the native application and CLI.

Refs #184
…o results

An explicit Session close detached its Scope from the application before
its Turn cleanup finished, so a concurrent shutdown could release shared
infrastructure underneath that cleanup. The application now holds a
finalizer awaiting one shared close until it completes.

The CLI grace timer now also starts when the command's own work ends, so
cleanup after ordinary completion or failure is bounded, not only after a
signal. Application Effect logs and unreported failures go to stderr,
keeping stdout to the rendered result.

Refs #184
acquire unwinds a failed startup before it returns, so the CLI's grace,
started only once the command's work ended, never covered that unwind and
a held infrastructure release hung the process. AcquireOptions gains
onShutdown, run once when shutdown begins and before anything is
cancelled or released; the CLI starts its deadline there as well. The
library still waits for all cleanup; only the CLI exits.

Refs #184
…n fails

Effect.ensuring keeps closing the application's resources when onShutdown
defects or is interrupted, and the docs state that a native Layer's own
failed-build rollback runs before shutdown begins.
Exit-aware infrastructure releases now see the startup failure instead of
success. Also address review notes on the docs example, the Application
glossary entry and test environment restoration.
binary.test.ts spawns dist/local/mitome, which only the build script
produces. Turbo builds first, but a direct `bun run test` in packages/cli
on a fresh checkout failed with ENOENT, and after source edits it tested
a stale binary. The compile takes under a second.
@chenxin-yan
chenxin-yan force-pushed the feat/effect-native-cli-184 branch from 7f20647 to 4e752b1 Compare November 1, 2026 01:19
chenxin-yan added a commit that referenced this pull request Nov 1, 2026
Address a #214 review finding: the Approval channel test bounds its poll
and asserts one request appeared, so a Turn that never asks fails at the
assertion instead of the 15s runner timeout. (The review's other point,
building before the binary tests, is fixed in #213's test script.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Load a native application and run it from the CLI

1 participant