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

t3ProjectFile.ts

88 lines3.2 KB

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