mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-03-30 22:03:58 +00:00
- Rename packages/opencode → packages/tfcode (directory only) - Rename bin/opencode → bin/tfcode (CLI binary) - Rename .opencode → .tfcode (config directory) - Update package.json name and bin field - Update config directory path references (.tfcode) - Keep internal code references as 'opencode' for easy upstream sync - Keep @opencode-ai/* workspace package names This minimal branding approach allows clean merges from upstream opencode repository while providing tfcode branding for users.
52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
import { ConfigProvider, Layer, ManagedRuntime } from "effect"
|
|
import { InstanceContext } from "../../src/effect/instance-context"
|
|
import { Instance } from "../../src/project/instance"
|
|
|
|
/** ConfigProvider that enables the experimental file watcher. */
|
|
export const watcherConfigLayer = ConfigProvider.layer(
|
|
ConfigProvider.fromUnknown({
|
|
OPENCODE_EXPERIMENTAL_FILEWATCHER: "true",
|
|
OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER: "false",
|
|
}),
|
|
)
|
|
|
|
/**
|
|
* Boot an Instance with the given service layers and run `body` with
|
|
* the ManagedRuntime. Cleanup is automatic — the runtime is disposed
|
|
* and Instance context is torn down when `body` completes.
|
|
*
|
|
* Layers may depend on InstanceContext (provided automatically).
|
|
* Pass extra layers via `options.provide` (e.g. ConfigProvider.layer).
|
|
*/
|
|
export function withServices<S>(
|
|
directory: string,
|
|
layer: Layer.Layer<S, any, InstanceContext>,
|
|
body: (rt: ManagedRuntime.ManagedRuntime<S, never>) => Promise<void>,
|
|
options?: { provide?: Layer.Layer<never>[] },
|
|
) {
|
|
return Instance.provide({
|
|
directory,
|
|
fn: async () => {
|
|
const ctx = Layer.sync(InstanceContext, () =>
|
|
InstanceContext.of({
|
|
directory: Instance.directory,
|
|
worktree: Instance.worktree,
|
|
project: Instance.project,
|
|
}),
|
|
)
|
|
let resolved: Layer.Layer<S> = layer.pipe(Layer.provide(ctx)) as any
|
|
if (options?.provide) {
|
|
for (const l of options.provide) {
|
|
resolved = resolved.pipe(Layer.provide(l)) as any
|
|
}
|
|
}
|
|
const rt = ManagedRuntime.make(resolved)
|
|
try {
|
|
await body(rt)
|
|
} finally {
|
|
await rt.dispose()
|
|
}
|
|
},
|
|
})
|
|
}
|