Repository navigation
feat(home): add Home, an agent that manages threads across your machines #15975
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
Open
t3dotgg
wants to merge
13
commits into
main
Choose a base branch
from
t3code/cross-environment-meta-thread
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+5,318
−295
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3c386b2
feat(home): add Home, an agent that manages threads across your machines
t3dotgg afd2c7d
fix(home): close Home folder, delete, snooze, and rename gaps
t3dotgg 683f654
fix(home): a folder named ..notes inside Home is still Home's folder
t3dotgg f2fe673
fix(home): relay registers, reports are labeled, and nothing starts i…
t3dotgg 0b07c22
fix(home): Home's folder is never the default project for a new thread
t3dotgg 4c9dd77
fix(home): address CI and review findings
t3dotgg af7a7d4
fix(home): keep reports on read errors, stop a replaced Home, recheck…
t3dotgg 1653ce8
fix(home): a replaced Home's queued messages stay held
t3dotgg bcdd359
fix(home): cancel a replaced Home's unstarted turns and never resend …
t3dotgg 571e6f9
fix(home): keep checking until a replaced Home is idle or held
t3dotgg e1857a8
fix(home): hold a replaced Home's queue atomically with a queue.hold …
t3dotgg 24ef069
fix(home): a Home draft never picks Home's folder for a new thread
t3dotgg b5d05a6
test(home): the hold and interrupt for a replaced Home use distinct c…
t3dotgg 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import * as Effect from "effect/Effect"; | ||
| import * as Ref from "effect/Ref"; | ||
| import * as Schema from "effect/Schema"; | ||
|
|
||
| import * as DesktopState from "../../app/DesktopState.ts"; | ||
| import * as IpcChannels from "../channels.ts"; | ||
| import * as DesktopIpc from "../DesktopIpc.ts"; | ||
|
|
||
| /** The renderer turns this on while Home is on, so its relay survives a closed window. */ | ||
| export const setKeepAliveOnClose = DesktopIpc.makeIpcMethod({ | ||
| channel: IpcChannels.SET_KEEP_ALIVE_ON_CLOSE_CHANNEL, | ||
| payload: Schema.Boolean, | ||
| result: Schema.Void, | ||
| handler: Effect.fn("desktop.ipc.setKeepAliveOnClose")(function* (keepAlive) { | ||
| const state = yield* DesktopState.DesktopState; | ||
| yield* Ref.set(state.keepAliveOnClose, keepAlive); | ||
| }), | ||
| }); |
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,85 @@ | ||
| import { expect, it } from "@effect/vitest"; | ||
| import { | ||
| EnvironmentId, | ||
| type FleetHostRequest, | ||
| type FleetInvokeInput, | ||
| ThreadId, | ||
| } from "@t3tools/contracts"; | ||
| import * as NodeCrypto from "@effect/platform-node/NodeCrypto"; | ||
| import * as Deferred from "effect/Deferred"; | ||
| import * as Effect from "effect/Effect"; | ||
| import * as Fiber from "effect/Fiber"; | ||
| import * as Layer from "effect/Layer"; | ||
| import * as Stream from "effect/Stream"; | ||
|
|
||
| import * as FleetBroker from "./FleetBroker.ts"; | ||
|
|
||
| const hub = EnvironmentId.make("hub"); | ||
| const studio = EnvironmentId.make("studio"); | ||
| const layer = FleetBroker.layer.pipe(Layer.provide(NodeCrypto.layer)); | ||
|
|
||
| const invoke: FleetInvokeInput = { | ||
| actor: { environmentId: hub, threadId: ThreadId.make("home") }, | ||
| request: { op: "requests.list", input: { threadId: ThreadId.make("t") } }, | ||
| }; | ||
|
|
||
| // Keeps the desktop's stream open, as a live renderer does, and hands back the first request. | ||
| const serve = (requests: Stream.Stream<FleetHostRequest>) => | ||
| Effect.gen(function* () { | ||
| const first = yield* Deferred.make<FleetHostRequest>(); | ||
| yield* Stream.runForEach(requests, (request) => Deferred.succeed(first, request)).pipe( | ||
| Effect.forkScoped, | ||
| ); | ||
| return first; | ||
| }); | ||
|
|
||
| const host = (clientId: string, connected = true) => ({ | ||
| clientId, | ||
| environments: [{ environmentId: studio, label: "Studio", connected }], | ||
| }); | ||
|
|
||
| it.effect("fails fast when no desktop window relays", () => | ||
| Effect.gen(function* () { | ||
| const broker = yield* FleetBroker.FleetBroker; | ||
| const error = yield* broker.invoke(studio, invoke).pipe(Effect.asVoid, Effect.flip); | ||
| expect(error.code).toBe("environment_unavailable"); | ||
| }).pipe(Effect.provide(layer)), | ||
| ); | ||
|
|
||
| it.effect("relays a call through the desktop and decodes the answer", () => | ||
| Effect.gen(function* () { | ||
| const broker = yield* FleetBroker.FleetBroker; | ||
| const firstRequest = yield* serve(yield* broker.connect(host("desktop"))); | ||
| yield* Effect.yieldNow; | ||
| const call = yield* broker.invoke(studio, invoke).pipe(Effect.forkScoped); | ||
| const request = yield* Deferred.await(firstRequest); | ||
| expect(request).toMatchObject({ environmentId: studio, invoke }); | ||
| yield* broker.respond({ requestId: request.requestId, result: { requestIds: [] } }); | ||
| expect(yield* Fiber.join(call)).toEqual({ requestIds: [] }); | ||
| }).pipe(Effect.scoped, Effect.provide(layer)), | ||
| ); | ||
|
|
||
| it.effect("refuses an environment the desktop reports offline", () => | ||
| Effect.gen(function* () { | ||
| const broker = yield* FleetBroker.FleetBroker; | ||
| yield* serve(yield* broker.connect(host("desktop", false))); | ||
| yield* Effect.yieldNow; | ||
| const error = yield* broker.invoke(studio, invoke).pipe(Effect.asVoid, Effect.flip); | ||
| expect(error.message).toContain("offline"); | ||
| }).pipe(Effect.scoped, Effect.provide(layer)), | ||
| ); | ||
|
|
||
| it.effect("a newer desktop registration fails calls the old one still owed", () => | ||
| Effect.gen(function* () { | ||
| const broker = yield* FleetBroker.FleetBroker; | ||
| const firstRequest = yield* serve(yield* broker.connect(host("old"))); | ||
| yield* Effect.yieldNow; | ||
| const call = yield* broker | ||
| .invoke(studio, invoke) | ||
| .pipe(Effect.asVoid, Effect.flip, Effect.forkScoped); | ||
| yield* Deferred.await(firstRequest); | ||
| yield* serve(yield* broker.connect(host("new"))); | ||
| const error = yield* Fiber.join(call); | ||
| expect(error.code).toBe("environment_unavailable"); | ||
| }).pipe(Effect.scoped, Effect.provide(layer)), | ||
| ); |
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.