Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

environment.ts

131 lines5.7 KB

1import * as Effect from "effect/Effect";
2import * as Schema from "effect/Schema";
3​
4import { EnvironmentId, ProjectId, ThreadId, TrimmedNonEmptyString } from "./baseSchemas.ts";
5​
6export const ExecutionEnvironmentPlatformOs = Schema.Literals([
7 "darwin",
8 "linux",
9 "windows",
10 "unknown",
11]);
12export type ExecutionEnvironmentPlatformOs = typeof ExecutionEnvironmentPlatformOs.Type;
13​
14export const ExecutionEnvironmentPlatformArch = Schema.Literals(["arm64", "x64", "other"]);
15export type ExecutionEnvironmentPlatformArch = typeof ExecutionEnvironmentPlatformArch.Type;
16​
17export const ExecutionEnvironmentPlatform = Schema.Struct({
18 os: ExecutionEnvironmentPlatformOs,
19 arch: ExecutionEnvironmentPlatformArch,
20});
21​
22/**
23 * Where a new thread runs: the project's current checkout ("local") or a
24 * fresh git worktree ("worktree"). Lives here (not settings.ts) so
25 * orchestration contracts can reference it without an import cycle.
26 */
27export const ThreadEnvMode = Schema.Literals(["local", "worktree"]);
28export type ThreadEnvMode = typeof ThreadEnvMode.Type;
29export type ExecutionEnvironmentPlatform = typeof ExecutionEnvironmentPlatform.Type;
30​
31/** How a server can replace itself with another version when asked over RPC.
32 New servers only advertise the stable launcher-backed "boot-service" path;
33 "respawn" remains decodable for compatibility with older servers. */
34export const ServerSelfUpdateMethod = Schema.Literals(["boot-service", "respawn"]);
35export type ServerSelfUpdateMethod = typeof ServerSelfUpdateMethod.Type;
36​
37/** What update path a client should offer for a server: one of the RPC
38 self-update methods above, or "desktop-managed" when the backend's
39 version belongs to the T3 Code desktop app supervising it — updating the
40 app on that machine is the only way to update the server. */
41export const ServerSelfUpdateCapability = Schema.Literals([
42 "boot-service",
43 "respawn",
44 "desktop-managed",
45]);
46export type ServerSelfUpdateCapability = typeof ServerSelfUpdateCapability.Type;
47​
48export const ExecutionEnvironmentCapabilities = Schema.Struct({
49 repositoryIdentity: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
50 connectionProbe: Schema.optionalKey(Schema.Boolean),
51 /** Server exposes the pull-request list, detail, activity, diff, and mutation APIs. Absent on
52 servers from before the pull-request workspace shipped, so clients must not probe them. */
53 pullRequests: Schema.optionalKey(Schema.Boolean),
54 /** Server understands thread.settle / thread.unsettle commands. Absent on
55 pre-settlement servers, so clients treat missing as unsupported and
56 never send the commands under version skew. */
57 threadSettlement: Schema.optionalKey(Schema.Boolean),
58 /** Server understands thread.snooze / thread.unsnooze commands. Same
59 version-skew contract as threadSettlement. */
60 threadSnooze: Schema.optionalKey(Schema.Boolean),
61 /** Server understands thread.pin / thread.unpin commands. Same
62 version-skew contract as threadSettlement. */
63 threadPinning: Schema.optionalKey(Schema.Boolean),
64 /** Server understands thread.pin.reorder (and orderKey on thread.pin).
65 Same version-skew contract as threadSettlement. */
66 threadPinReorder: Schema.optionalKey(Schema.Boolean),
67 /** Server understands regenerateTitle on thread.meta.update. Absent on
68 older servers, so clients hide the action instead of sending it. */
69 threadTitleRegeneration: Schema.optionalKey(Schema.Boolean),
70 /** The update path clients should offer for this server. Absent on
71 servers that must be relaunched manually (dev checkouts, Windows
72 foreground runs, pre-update servers). */
73 serverSelfUpdate: Schema.optionalKey(ServerSelfUpdateCapability),
74 /** Server can stream self-update progress before acknowledging the
75 restart. Clients fall back to server.updateServer when absent. */
76 serverSelfUpdateProgress: Schema.optionalKey(Schema.Boolean),
77});
78export type ExecutionEnvironmentCapabilities = typeof ExecutionEnvironmentCapabilities.Type;
79​
80export const ExecutionEnvironmentDescriptor = Schema.Struct({
81 environmentId: EnvironmentId,
82 label: TrimmedNonEmptyString,
83 platform: ExecutionEnvironmentPlatform,
84 serverVersion: TrimmedNonEmptyString,
85 capabilities: ExecutionEnvironmentCapabilities,
86});
87export type ExecutionEnvironmentDescriptor = typeof ExecutionEnvironmentDescriptor.Type;
88​
89export const EnvironmentConnectionState = Schema.Literals([
90 "connecting",
91 "connected",
92 "disconnected",
93 "error",
94]);
95export type EnvironmentConnectionState = typeof EnvironmentConnectionState.Type;
96​
97export const RepositoryIdentityLocator = Schema.Struct({
98 source: Schema.Literal("git-remote"),
99 remoteName: TrimmedNonEmptyString,
100 remoteUrl: TrimmedNonEmptyString,
101});
102export type RepositoryIdentityLocator = typeof RepositoryIdentityLocator.Type;
103​
104export const RepositoryIdentity = Schema.Struct({
105 canonicalKey: TrimmedNonEmptyString,
106 locator: RepositoryIdentityLocator,
107 rootPath: Schema.optionalKey(TrimmedNonEmptyString),
108 displayName: Schema.optionalKey(TrimmedNonEmptyString),
109 provider: Schema.optionalKey(TrimmedNonEmptyString),
110 owner: Schema.optionalKey(TrimmedNonEmptyString),
111 name: Schema.optionalKey(TrimmedNonEmptyString),
112});
113export type RepositoryIdentity = typeof RepositoryIdentity.Type;
114​
115export const ScopedProjectRef = Schema.Struct({
116 environmentId: EnvironmentId,
117 projectId: ProjectId,
118});
119export type ScopedProjectRef = typeof ScopedProjectRef.Type;
120​
121export const ScopedThreadRef = Schema.Struct({
122 environmentId: EnvironmentId,
123 threadId: ThreadId,
124});
125export type ScopedThreadRef = typeof ScopedThreadRef.Type;
126​
127export const ScopedThreadSessionRef = Schema.Struct({
128 environmentId: EnvironmentId,
129 threadId: ThreadId,
130});
131export type ScopedThreadSessionRef = typeof ScopedThreadSessionRef.Type;