The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | /** |
| 2 | * The `repos` group: repo CRUD, fork, import, and compaction |
| 3 | * (DESIGN.md §5). Every route is an Effect `HttpApiEndpoint`. Who may |
| 4 | * call it is decided by the middleware applied to its route layer. |
| 5 | */ |
| 6 | import * as HttpApiEndpoint from "effect/http-api/HttpApiEndpoint"; |
| 7 | import * as HttpApiGroup from "effect/http-api/HttpApiGroup"; |
| 8 | import * as HttpApiSchema from "effect/http-api/HttpApiSchema"; |
| 9 | import * as Schema from "effect/Schema"; |
| 10 | import { |
| 11 | ImportFailed, |
| 12 | OwnerName, |
| 13 | Paginated, |
| 14 | RefNotFound, |
| 15 | Repo, |
| 16 | RepoAlreadyExists, |
| 17 | RepoCreated, |
| 18 | RepoName, |
| 19 | RepoNotFound, |
| 20 | RepoNotReady, |
| 21 | RepoPath, |
| 22 | ValidationError, |
| 23 | } from "./Schema.ts"; |
| 24 | |
| 25 | /** Creates a repo owned by `owner`. */ |
| 26 | export const CreateRepo = HttpApiEndpoint.post("create", "/repos", { |
| 27 | payload: Schema.Struct({ |
| 28 | owner: OwnerName, |
| 29 | name: RepoName, |
| 30 | /** Default branch short name. @default "main" */ |
| 31 | defaultBranch: Schema.optional(Schema.String), |
| 32 | description: Schema.optional(Schema.String), |
| 33 | /** |
| 34 | * Anyone can read/clone without a credential when `true`. |
| 35 | * @default false |
| 36 | */ |
| 37 | public: Schema.optional(Schema.Boolean), |
| 38 | /** @default false */ |
| 39 | readOnly: Schema.optional(Schema.Boolean), |
| 40 | }), |
| 41 | success: RepoCreated, |
| 42 | error: [RepoAlreadyExists, ValidationError], |
| 43 | }); |
| 44 | |
| 45 | /** Reads one repo (poll `status` for async fork/import/delete progress). */ |
| 46 | export const GetRepo = HttpApiEndpoint.get("get", "/repos/:owner/:repo", { |
| 47 | params: RepoPath, |
| 48 | success: Repo, |
| 49 | error: [RepoNotFound], |
| 50 | }); |
| 51 | |
| 52 | /** Patches description / default branch / readOnly / public. */ |
| 53 | export const UpdateRepo = HttpApiEndpoint.patch("update", "/repos/:owner/:repo", { |
| 54 | params: RepoPath, |
| 55 | payload: Schema.Struct({ |
| 56 | description: Schema.String.pipe(Schema.NullOr, Schema.optional), |
| 57 | /** Must resolve to an existing branch. */ |
| 58 | defaultBranch: Schema.optional(Schema.String), |
| 59 | readOnly: Schema.optional(Schema.Boolean), |
| 60 | /** Anyone can read/clone without a credential when `true`. */ |
| 61 | public: Schema.optional(Schema.Boolean), |
| 62 | }), |
| 63 | success: Repo, |
| 64 | error: [RepoNotFound, RefNotFound], |
| 65 | }); |
| 66 | |
| 67 | /** |
| 68 | * Lists repos, optionally filtered by owner. Lists everything the |
| 69 | * Registry holds; `public: true` narrows it to public repositories. |
| 70 | */ |
| 71 | export const ListRepos = HttpApiEndpoint.get("list", "/repos", { |
| 72 | query: Schema.Struct({ |
| 73 | owner: Schema.optional(OwnerName), |
| 74 | /** Only public repositories when `true`. */ |
| 75 | public: Schema.optional(Schema.Boolean), |
| 76 | cursor: Schema.optional(Schema.String), |
| 77 | limit: Schema.optional(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 100 }))), |
| 78 | }), |
| 79 | success: Paginated(Repo), |
| 80 | }); |
| 81 | |
| 82 | /** |
| 83 | * Deletes a repo. Async purge: responds 204 immediately, repo `status` |
| 84 | * flips to `'deleting'`, the name frees after the purge alarm completes |
| 85 | * (then 404). |
| 86 | */ |
| 87 | export const DeleteRepo = HttpApiEndpoint.delete("delete", "/repos/:owner/:repo", { |
| 88 | params: RepoPath, |
| 89 | success: HttpApiSchema.NoContent, |
| 90 | error: [RepoNotFound], |
| 91 | }); |
| 92 | |
| 93 | /** |
| 94 | * Forks a repo. The fork starts in `status: 'forking'`; poll |
| 95 | * `GET /repos/:owner/:repo` until `'ready'`. |
| 96 | */ |
| 97 | export const ForkRepo = HttpApiEndpoint.post("fork", "/repos/:owner/:repo/fork", { |
| 98 | params: RepoPath, |
| 99 | payload: Schema.Struct({ |
| 100 | targetOwner: OwnerName, |
| 101 | targetName: RepoName, |
| 102 | }), |
| 103 | success: RepoCreated, |
| 104 | error: [RepoNotFound, RepoAlreadyExists, RepoNotReady], |
| 105 | }); |
| 106 | |
| 107 | /** |
| 108 | * Imports from an external smart-HTTP source. The repo starts in |
| 109 | * `status: 'importing'`; poll `GET /repos/:owner/:repo` until `'ready'`. |
| 110 | */ |
| 111 | export const ImportRepo = HttpApiEndpoint.post("import", "/repos/import", { |
| 112 | payload: Schema.Struct({ |
| 113 | owner: OwnerName, |
| 114 | name: RepoName, |
| 115 | source: Schema.Struct({ |
| 116 | /** Smart-HTTP URL of the source repository. */ |
| 117 | url: Schema.String, |
| 118 | /** Restrict the import to a single ref. */ |
| 119 | ref: Schema.optional(Schema.String), |
| 120 | /** Depth-limit the imported history. */ |
| 121 | depth: Schema.optional(Schema.Int.check(Schema.isGreaterThan(0))), |
| 122 | }), |
| 123 | }), |
| 124 | success: RepoCreated, |
| 125 | error: [RepoAlreadyExists, ImportFailed], |
| 126 | }); |
| 127 | |
| 128 | /** |
| 129 | * Forces a compaction run now (`Maintain`): moves loose object bytes into |
| 130 | * an immutable pack. Normally armed automatically by size thresholds after |
| 131 | * a push — this is the operator/benchmark handle. Returns immediately; poll |
| 132 | * `GET /repos/:owner/:repo` and watch `objects.loose` fall to zero. |
| 133 | */ |
| 134 | export const CompactRepo = HttpApiEndpoint.post("compact", "/repos/:owner/:repo/compact", { |
| 135 | params: RepoPath, |
| 136 | success: HttpApiSchema.NoContent, |
| 137 | error: [RepoNotFound], |
| 138 | }); |
| 139 | |
| 140 | /** The `repos` group, mounted at `/api/v1`. */ |
| 141 | export class Repos extends HttpApiGroup.make("repos") |
| 142 | .add(CreateRepo, GetRepo, UpdateRepo, ListRepos, DeleteRepo, ForkRepo, ImportRepo, CompactRepo) |
| 143 | .prefix("/api/v1") {} |