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

checkpointDiff.ts

83 lines3.1 KB

1import * as Schema from "effect/Schema";
2import * as SchemaIssue from "effect/SchemaIssue";
3import * as Struct from "effect/Struct";
4​
5import { NonNegativeInt, ThreadId, TrimmedNonEmptyString } from "./baseSchemas.ts";
6​
7/** Ends a checkpoint diff the server cut off at its output size limit. */
8export const CHECKPOINT_DIFF_TRUNCATED_MARKER = "\n\n[truncated]";
9​
10export const TurnCountRange = Schema.Struct({
11 fromTurnCount: NonNegativeInt,
12 toTurnCount: NonNegativeInt,
13}).check(
14 Schema.makeFilter(
15 (input) =>
16 input.fromTurnCount <= input.toTurnCount ||
17 new SchemaIssue.InvalidValue({
18 message: "fromTurnCount must be less than or equal to toTurnCount",
19 }),
20 { identifier: "OrchestrationTurnDiffRange" },
21 ),
22);
23​
24/** One tracked repository's patch in a thread that reaches several. */
25export const ThreadTurnRepositoryDiff = Schema.Struct({
26 name: TrimmedNonEmptyString,
27 /** The project's tracked path; matches the checkpoint scope's `repositoryPath`. */
28 repositoryPath: TrimmedNonEmptyString,
29 /** The repository folder from the thread's cwd, `/`-separated; may start with `../`. */
30 relativePath: Schema.String,
31 /** Paths are relative to the repository, as Git prints them. */
32 diff: Schema.String,
33});
34export type ThreadTurnRepositoryDiff = typeof ThreadTurnRepositoryDiff.Type;
35​
36export const ThreadTurnDiff = TurnCountRange.mapFields(
37 Struct.assign({
38 threadId: ThreadId,
39 /** The thread folder's own patch; empty when that folder is not a Git repository. */
40 diff: Schema.String,
41 /** Tracked repositories that changed in the range. Absent when the thread has none. */
42 repositories: Schema.optionalKey(Schema.Array(ThreadTurnRepositoryDiff)),
43 }),
44 { unsafePreserveChecks: true },
45);
46​
47export const OrchestrationGetTurnDiffInput = TurnCountRange.mapFields(
48 Struct.assign({
49 threadId: ThreadId,
50 ignoreWhitespace: Schema.optionalKey(Schema.Boolean),
51 }),
52 { unsafePreserveChecks: true },
53);
54export type OrchestrationGetTurnDiffInput = typeof OrchestrationGetTurnDiffInput.Type;
55​
56export const OrchestrationGetTurnDiffResult = ThreadTurnDiff;
57export type OrchestrationGetTurnDiffResult = typeof OrchestrationGetTurnDiffResult.Type;
58​
59export const OrchestrationGetFullThreadDiffInput = Schema.Struct({
60 threadId: ThreadId,
61 toTurnCount: NonNegativeInt,
62 ignoreWhitespace: Schema.optionalKey(Schema.Boolean),
63});
64export type OrchestrationGetFullThreadDiffInput = typeof OrchestrationGetFullThreadDiffInput.Type;
65​
66export const OrchestrationGetFullThreadDiffResult = ThreadTurnDiff;
67export type OrchestrationGetFullThreadDiffResult = typeof OrchestrationGetFullThreadDiffResult.Type;
68​
69export class OrchestrationGetTurnDiffError extends Schema.TaggedError<OrchestrationGetTurnDiffError>()(
70 "OrchestrationGetTurnDiffError",
71 {
72 message: TrimmedNonEmptyString,
73 cause: Schema.optional(Schema.Defect()),
74 },
75) {}
76​
77export class OrchestrationGetFullThreadDiffError extends Schema.TaggedError<OrchestrationGetFullThreadDiffError>()(
78 "OrchestrationGetFullThreadDiffError",
79 {
80 message: TrimmedNonEmptyString,
81 cause: Schema.optional(Schema.Defect()),
82 },
83) {}