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

t3ProjectFile.ts

95 lines3.6 KB

1import * as Schema from "effect/Schema";
2import * as SchemaTransformation from "effect/SchemaTransformation";
3​
4import { ThreadEnvMode } from "./environment.ts";
5import { ProjectScriptIcon } from "./orchestration.ts";
6​
7/** File name of the checked-in T3 project file, resolved at the workspace root. */
8export const T3_PROJECT_FILE_NAME = "t3.json";
9​
10/** Public URL of the published JSON Schema for {@link T3ProjectFile}. */
11export const T3_PROJECT_FILE_SCHEMA_URL = "https://t3.codes/schema/t3.json";
12​
13const T3_PROJECT_FILE_PATH_MAX_LENGTH = 512;
14const T3_PROJECT_FILE_MAX_SCRIPTS = 50;
15​
16// Annotations go on the encoded (string) side so they survive into the
17// published JSON Schema; decoding still trims and re-validates non-emptiness.
18const trimmedNonEmpty = (annotations: { readonly description: string }, maxLength?: number) => {
19 const annotated = Schema.String.annotate(annotations);
20 const encoded =
21 maxLength === undefined
22 ? annotated.check(Schema.isNonEmpty())
23 : annotated.check(Schema.isNonEmpty(), Schema.isMaxLength(maxLength));
24 return encoded.pipe(Schema.decodeTo(encoded, SchemaTransformation.trim()));
25};
26​
27export const T3ProjectFileScript = Schema.Struct({
28 name: trimmedNonEmpty({
29 description: "Display name for the script, shown in the T3 Code scripts menu.",
30 }),
31 command: trimmedNonEmpty({
32 description: "Shell command executed in a T3 Code terminal at the project root.",
33 }),
34 icon: Schema.optionalKey(
35 ProjectScriptIcon.annotate({
36 description: 'Icon shown next to the script in the scripts menu. Defaults to "play".',
37 }),
38 ),
39 runOnWorktreeCreate: Schema.optionalKey(
40 Schema.Boolean.annotate({
41 description:
42 "When true, the script runs automatically after a worktree is created for a new thread.",
43 }),
44 ),
45 previewUrl: Schema.optionalKey(
46 trimmedNonEmpty({
47 description:
48 "URL opened in the in-app browser preview when this script runs. Only honored on the desktop build.",
49 }),
50 ),
51 autoOpenPreview: Schema.optionalKey(
52 Schema.Boolean.annotate({
53 description:
54 "When true, automatically open the preview panel at `previewUrl` the moment the script starts.",
55 }),
56 ),
57}).annotate({
58 description: "A project script that team members can import into T3 Code.",
59});
60export type T3ProjectFileScript = typeof T3ProjectFileScript.Type;
61​
62export const T3ProjectFile = Schema.Struct({
63 $schema: Schema.optionalKey(
64 Schema.String.annotate({
65 description: `URL of the JSON Schema for this file, typically "${T3_PROJECT_FILE_SCHEMA_URL}".`,
66 }),
67 ),
68 iconPath: Schema.optionalKey(
69 trimmedNonEmpty(
70 {
71 description:
72 'Workspace-relative path to the project icon (e.g. "assets/logo.svg"). Checked before T3 Code\'s built-in icon locations.',
73 },
74 T3_PROJECT_FILE_PATH_MAX_LENGTH,
75 ),
76 ),
77 defaultThreadEnvMode: Schema.optionalKey(
78 ThreadEnvMode.annotate({
79 description:
80 'Where new threads start for this repository: "worktree" for a fresh git worktree, "local" for the current checkout. A per-project setting in T3 Code overrides this; when neither is set, the global default applies.',
81 }),
82 ),
83 scripts: Schema.optionalKey(
84 Schema.Array(T3ProjectFileScript)
85 .annotate({
86 description: "Project scripts shared with everyone who opens this repository in T3 Code.",
87 })
88 .check(Schema.isMaxLength(T3_PROJECT_FILE_MAX_SCRIPTS)),
89 ),
90}).annotate({
91 title: "T3 project file",
92 description:
93 "Checked-in project configuration for T3 Code (t3.json at the repository root). See https://t3.codes for documentation.",
94});
95export type T3ProjectFile = typeof T3ProjectFile.Type;