-
Notifications
You must be signed in to change notification settings - Fork 2
refactor(instance): add Effect foundation and effectCmd proof #507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f0dbaf2
refactor(instance): add Effect-backed bootstrap
Astro-Han 8e46a0f
refactor(cli): add minimal effectCmd proof
Astro-Han 9c7752c
fix(instance): clean up bootstrap lifecycle
Astro-Han 3b48455
fix(file): use effect instance context during bootstrap
Astro-Han File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import type { Argv } from "yargs" | ||
| import { Effect, Schema } from "effect" | ||
| import { AppRuntime, type AppServices } from "@/effect/app-runtime" | ||
| import { InstanceRef } from "@/effect/instance-ref" | ||
| import { Instance } from "@/project/instance" | ||
| import { InstanceStore } from "@/project/instance-store" | ||
| import { cmd, type WithDoubleDash } from "./cmd/cmd" | ||
|
|
||
| export class CliError extends Schema.TaggedErrorClass<CliError>()("CliError", { | ||
| message: Schema.String, | ||
| exitCode: Schema.optional(Schema.Number), | ||
| }) {} | ||
|
|
||
| export const fail = (message: string, exitCode = 1) => Effect.fail(new CliError({ message, exitCode })) | ||
|
|
||
| interface EffectCmdOpts<Args, A> { | ||
| command: string | readonly string[] | ||
| aliases?: string | readonly string[] | ||
| describe: string | false | ||
| builder?: (yargs: Argv) => Argv<Args> | ||
| instance?: boolean | ((args: WithDoubleDash<Args>) => boolean) | ||
| directory?: (args: WithDoubleDash<Args>) => string | ||
| handler: (args: WithDoubleDash<Args>) => Effect.Effect<A, CliError, AppServices | InstanceStore.Service> | ||
| } | ||
|
|
||
| export const effectCmd = <Args, A>(opts: EffectCmdOpts<Args, A>) => | ||
| cmd<{}, Args>({ | ||
| command: opts.command, | ||
| aliases: opts.aliases, | ||
| describe: opts.describe, | ||
| builder: opts.builder as never, | ||
| async handler(rawArgs) { | ||
| const args = rawArgs as unknown as WithDoubleDash<Args> | ||
| const useInstance = typeof opts.instance === "function" ? opts.instance(args) : opts.instance !== false | ||
| if (!useInstance) { | ||
| await AppRuntime.runPromise(opts.handler(args)) | ||
| return | ||
| } | ||
|
|
||
| const directory = opts.directory?.(args) ?? process.cwd() | ||
| const { store, ctx } = await AppRuntime.runPromise( | ||
| InstanceStore.Service.use((store) => store.load({ directory }).pipe(Effect.map((ctx) => ({ store, ctx })))), | ||
| ) | ||
|
|
||
| try { | ||
| await Instance.restore(ctx, () => | ||
| AppRuntime.runPromise(opts.handler(args).pipe(Effect.provideService(InstanceRef, ctx))), | ||
| ) | ||
| } finally { | ||
| await AppRuntime.runPromise(store.dispose(ctx)) | ||
| } | ||
| }, | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { Context, Effect } from "effect" | ||
|
|
||
| export interface Interface { | ||
| readonly run: Effect.Effect<void> | ||
| } | ||
|
|
||
| export class Service extends Context.Service<Service, Interface>()("@opencode/InstanceBootstrap") {} | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| export * as InstanceBootstrap from "./bootstrap-service" | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.