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

agentSessions.ts

89 lines3.2 KB

1import * as Schema from "effect/Schema";
2import { IsoDateTime, NonNegativeInt, ProjectId, TrimmedNonEmptyString } from "./baseSchemas.ts";
3import { ProviderInstanceId } from "./providerInstance.ts";
4​
5export const AgentSessionSource = Schema.Literals(["claudeAgent", "codex"]);
6export type AgentSessionSource = typeof AgentSessionSource.Type;
7​
8export const AgentSessionImportSource = Schema.Struct({
9 provider: AgentSessionSource,
10 providerInstanceId: ProviderInstanceId,
11 providerSessionId: TrimmedNonEmptyString,
12 filePath: TrimmedNonEmptyString,
13 size: NonNegativeInt,
14 mtimeMs: Schema.NullOr(Schema.Number),
15 device: Schema.Number,
16 inode: Schema.NullOr(Schema.Number),
17 birthtimeMs: Schema.NullOr(Schema.Number),
18});
19export type AgentSessionImportSource = typeof AgentSessionImportSource.Type;
20​
21export const AgentSessionScanInput = Schema.Struct({});
22export type AgentSessionScanInput = typeof AgentSessionScanInput.Type;
23​
24export const AgentSessionProjectGit = Schema.Struct({
25 remoteKey: Schema.NullOr(Schema.String),
26 repository: Schema.NullOr(Schema.String),
27});
28export type AgentSessionProjectGit = typeof AgentSessionProjectGit.Type;
29​
30export const AgentSessionProjectCandidate = Schema.Struct({
31 path: TrimmedNonEmptyString,
32 title: TrimmedNonEmptyString,
33 projectId: Schema.optional(ProjectId),
34 sources: Schema.Array(AgentSessionSource),
35 threadCount: NonNegativeInt,
36 lastActiveAt: Schema.NullOr(IsoDateTime),
37 alreadyImported: Schema.Boolean,
38 git: Schema.optionalKey(Schema.NullOr(AgentSessionProjectGit)),
39});
40export type AgentSessionProjectCandidate = typeof AgentSessionProjectCandidate.Type;
41​
42export const AgentSessionScanResult = Schema.Struct({
43 candidates: Schema.Array(AgentSessionProjectCandidate),
44 scannedAt: IsoDateTime,
45 truncated: Schema.optional(Schema.Boolean),
46});
47export type AgentSessionScanResult = typeof AgentSessionScanResult.Type;
48​
49export const AgentSessionImportInput = Schema.Struct({
50 projectId: ProjectId,
51 expectedWorkspaceRoot: Schema.optional(TrimmedNonEmptyString),
52});
53export type AgentSessionImportInput = typeof AgentSessionImportInput.Type;
54​
55export class AgentSessionImportProjectNotFoundError extends Schema.TaggedError<AgentSessionImportProjectNotFoundError>()(
56 "AgentSessionImportProjectNotFoundError",
57 { projectId: ProjectId },
58) {
59 override get message(): string {
60 return `Project '${this.projectId}' does not exist.`;
61 }
63​
64export class AgentSessionImportProjectChangedError extends Schema.TaggedError<AgentSessionImportProjectChangedError>()(
65 "AgentSessionImportProjectChangedError",
66 { projectId: ProjectId },
67) {
68 override get message(): string {
69 return `Project '${this.projectId}' changed directories. Scan for projects again before importing history.`;
70 }
72​
73export const AgentSessionImportResult = Schema.Struct({
74 importedCount: NonNegativeInt,
75 skippedCount: NonNegativeInt,
76});
77export type AgentSessionImportResult = typeof AgentSessionImportResult.Type;
78​
79export class AgentSessionScanError extends Schema.TaggedError<AgentSessionScanError>()(
80 "AgentSessionScanError",
81 {
82 operation: Schema.Literals(["read-settings", "read-projects"]),
83 cause: Schema.Defect(),
84 },
85) {
86 override get message(): string {
87 return `Failed to scan agent sessions during ${this.operation}.`;
88 }