JSDoc
Types
ProviderId
typetype ProviderId = "github" | "gitea" | "gitlab"
TokenLookup
typetype TokenLookup = { kind?: "absent"; } | { kind?: "present"; token?: string; }RepoRef
typetype RepoRef = { provider?: "github" | "gitea" | "gitlab"; owner?: string; name?: string; branch?: string; proxyBase?: string; }Author
typetype Author = { name?: string; email?: string; timestampISO?: string; }FileChange
typetype FileChange = { kind?: "write"; path?: string; content?: Uint8Array<ArrayBuffer>; } | { kind?: "delete"; path?: string; }ReadFileResult
typetype ReadFileResult = { kind?: "found"; path?: string; content?: Uint8Array<ArrayBuffer>; versionToken?: string; } | { kind?: "missing"; path?: string; }TreeEntry
typetype TreeEntry = { path?: string; type?: "blob" | "tree"; versionToken?: string; }HeadTreeState
typetype HeadTreeState = { kind?: "fresh"; } | { kind?: "at"; treeOid?: string; commitOid?: string; }CommitInput
typetype CommitInput = { message?: string; base?: { kind?: "fresh"; } | { kind?: "at"; treeOid?: string; commitOid?: string; }; changes?: ({ kind?: "write"; path?: string; content?: Uint8Array<ArrayBuffer>; } | { kind?: "delete"; path?: string; })[]; author?: { name?: string; email?: string; timestampISO?: string; }; }CommitResult
typetype CommitResult = { kind?: "ok"; treeOid?: string; commitOid?: string; } | { kind?: "cas-conflict"; currentTreeOid?: string; }PushResult
typetype PushResult = { kind?: "ok"; commitsAhead?: number; } | { kind?: "non-fast-forward"; remoteOid?: string; } | { kind?: "auth"; reason?: string; } | { kind?: "not-found"; } | { kind?: "network"; retriable?: boolean; }PullResult
typetype PullResult = { kind?: "ok"; fastForwarded?: boolean; newHeadOid?: string; } | { kind?: "diverged"; remoteOid?: string; localOid?: string; } | { kind?: "auth"; reason?: string; } | { kind?: "not-found"; } | { kind?: "network"; retriable?: boolean; }ResetHeadResult
typetype ResetHeadResult = { kind?: "ok"; newHeadOid?: string; } | { kind?: "unknown-oid"; oid?: string; }CloneResult
typetype CloneResult = { kind?: "ok"; headOid?: string; } | { kind?: "auth"; reason?: string; } | { kind?: "not-found"; } | { kind?: "network"; retriable?: boolean; } | { kind?: "empty-init"; reason?: string; }RepoInfo
typetype RepoInfo = { owner?: string; name?: string; isPrivate?: boolean; defaultBranch?: string; pushedAt?: string; }RepoLookupResult
typetype RepoLookupResult = { kind?: "found"; info?: { owner?: string; name?: string; isPrivate?: boolean; defaultBranch?: string; pushedAt?: string; }; } | { kind?: "missing"; } | { kind?: "forbidden"; currentLogin?: string; } | { kind?: "network"; retriable?: boolean; }CreateRepoArgs
typetype CreateRepoArgs = { name?: string; isPrivate?: boolean; }CreatedRepo
typetype CreatedRepo = { owner?: string; name?: string; }CurrentLoginResult
typetype CurrentLoginResult = { kind?: "ok"; login?: string; } | { kind?: "anonymous"; } | { kind?: "network"; retriable?: boolean; }Interfaces
GitFs
interfaceinterface GitFs
readFile
propertyRead a file by path. Returns missing if absent — never throws.
readFile: (path: string) => Promise<ReadFileResult>
listTree
propertyList entries under `prefix`. `prefix === ""` lists root. Returns empty array if prefix points to a non-existent dir. Recursive flat list (every blob below the prefix), not a one-level dir read.
listTree: (prefix: string) => Promise<ReadonlyArray<TreeEntry>>
headTreeState
propertyCurrent HEAD tree state. Pass directly into `commit({ base, ... })` for CAS. Discriminated so "no commits yet" is the named `fresh` variant.
headTreeState: () => Promise<HeadTreeState>
commit
propertyStage + commit `changes` atomically against `input.base`. Returns cas-conflict (does not commit) if HEAD has advanced past `input.base`. Caller's responsibility to refresh + retry. Does NOT push. Push is a separate explicit step.
commit: (input: CommitInput) => Promise<CommitResult>
clone
propertyInitialise the local working tree from `ref`. Idempotent — if the local tree is already cloned for `ref`, returns ok with the existing HEAD. If the remote returns 404 AND `init.allowEmptyOnMissing` is implied (adapter-internal default), MAY init an empty repo locally and return empty-init so the caller can write + push to materialise the remote.
clone: (ref: RepoRef, token: TokenLookup) => Promise<CloneResult>
push
propertyPush current HEAD to `ref.branch`.
push: (ref: RepoRef, token: TokenLookup) => Promise<PushResult>
pull
propertyFetch + fast-forward HEAD from `ref.branch`. If divergent (local commits not on remote), does NOT auto-merge — returns diverged.
pull: (ref: RepoRef, token: TokenLookup) => Promise<PullResult>
resetLocal
propertyDrop all local state (working tree + git db + clone metadata). Used by the "Reset local repo" affordance. Idempotent. After this, `clone()` re-initialises from scratch.
resetLocal: () => Promise<void>
resetHead
propertyRewinds local HEAD to `oid`. Discards local commits not on the path to `oid`. Working-tree state == tree of `oid` after this returns. Idempotent: `resetHead(currentHeadOid)` returns ok with no observable change. Returns `{kind:"unknown-oid"}` (without mutating HEAD) if `oid` is not present in the local object store. This indicates a programmer error or a stale reference — callers that hold a HeadTreeState.commitOid just observed should never see this branch. Caller contract: ONLY `transaction-runner.handleNonFastForward` should call this. It's destructive (local commits between `oid` and current HEAD are unreachable from any ref afterwards), and there is no general-purpose reason to discard local commits — sync conflict recovery is the sole legitimate use case. Adapter implementers MUST also support this from the contract suite (see __tests__/contract/git-fs.contract.ts → describe("resetHead", …)).
resetHead: (oid: string) => Promise<ResetHeadResult>
RepoManagement
interfaceinterface RepoManagement
id
propertyid: "github" | "gitea" | "gitlab"
label
propertylabel: string
listMyRepos
propertyList repos the authenticated user can write to (page 1, ≤100 results). Returns repos sorted by most-recently-pushed.
listMyRepos: (token: TokenLookup) => Promise<ReadonlyArray<RepoInfo>>
createRepo
propertyCreate a repo owned by the authenticated user. Initialises with README.
createRepo: (token: TokenLookup, args: CreateRepoArgs) => Promise<CreatedRepo>
getRepo
propertyProbe a specific repo's visibility to the current token. found → exists + visible missing → does not exist AND token's owner == `owner` (creatable) forbidden → exists but invisible to this token (private/wrong-org) network → transient network error
getRepo: (token: TokenLookup, owner: string, name: string) => Promise<RepoLookupResult>
currentLogin
propertyResolve the login the token belongs to.
currentLogin: (token: TokenLookup) => Promise<CurrentLoginResult>
Constants
ProviderIdSchema
constconst ProviderIdSchema: z.ZodEnum<["github", "gitea", "gitlab"]>
TokenLookupSchema
constconst TokenLookupSchema: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{ kind: z.ZodLiteral<"absent">; }, "strip", z.ZodTypeAny, { kind?: "absent"; }, { kind?: "absent"; }>, z.ZodObject<{ kind: z.ZodLiteral<"present">; token: z.ZodString; }, "strip", z.ZodTypeAny, { kind?: "present"; token?: string; }, { kind?: "present"; token?: string; }>]>tokenAbsent
constconst tokenAbsent: () => TokenLookup
tokenPresent
constconst tokenPresent: (token: string) => TokenLookup
RepoRefSchema
constconst RepoRefSchema: z.ZodObject<{ provider: z.ZodEnum<["github", "gitea", "gitlab"]>; owner: z.ZodString; name: z.ZodString; branch: z.ZodString; proxyBase: z.ZodString; }, "strip", z.ZodTypeAny, { provider?: "github" | "gitea" | "gitlab"; owner?: string; name?: string; branch?: string; proxyBase?: string; }, { provider?: "github" | "gitea" | "gitlab"; owner?: string; name?: string; branch?: string; proxyBase?: string; }>AuthorSchema
constconst AuthorSchema: z.ZodObject<{ name: z.ZodString; email: z.ZodString; timestampISO: z.ZodString; }, "strip", z.ZodTypeAny, { name?: string; email?: string; timestampISO?: string; }, { name?: string; email?: string; timestampISO?: string; }>FileChangeSchema
constconst FileChangeSchema: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{ kind: z.ZodLiteral<"write">; path: z.ZodString; content: z.ZodType<Uint8Array<ArrayBuffer>, z.ZodTypeDef, Uint8Array<ArrayBuffer>>; }, "strip", z.ZodTypeAny, { kind?: "write"; path?: string; content?: Uint8Array<ArrayBuffer>; }, { kind?: "write"; path?: string; content?: Uint8Array<ArrayBuffer>; }>, z.ZodObject<{ kind: z.ZodLiteral<"delete">; path: z.ZodString; }, "strip", z.ZodTypeAny, { kind?: "delete"; path?: string; }, { kind?: "delete"; path?: string; }>]>ReadFileResultSchema
constconst ReadFileResultSchema: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{ kind: z.ZodLiteral<"found">; path: z.ZodString; content: z.ZodType<Uint8Array<ArrayBuffer>, z.ZodTypeDef, Uint8Array<ArrayBuffer>>; versionToken: z.ZodString; }, "strip", z.ZodTypeAny, { kind?: "found"; path?: string; content?: Uint8Array<ArrayBuffer>; versionToken?: string; }, { kind?: "found"; path?: string; content?: Uint8Array<ArrayBuffer>; versionToken?: string; }>, z.ZodObject<{ kind: z.ZodLiteral<"missing">; path: z.ZodString; }, "strip", z.ZodTypeAny, { kind?: "missing"; path?: string; }, { kind?: "missing"; path?: string; }>]>TreeEntrySchema
constconst TreeEntrySchema: z.ZodObject<{ path: z.ZodString; type: z.ZodEnum<["blob", "tree"]>; versionToken: z.ZodString; }, "strip", z.ZodTypeAny, { path?: string; type?: "blob" | "tree"; versionToken?: string; }, { path?: string; type?: "blob" | "tree"; versionToken?: string; }>HeadTreeStateSchema
constconst HeadTreeStateSchema: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{ kind: z.ZodLiteral<"fresh">; }, "strip", z.ZodTypeAny, { kind?: "fresh"; }, { kind?: "fresh"; }>, z.ZodObject<{ kind: z.ZodLiteral<"at">; treeOid: z.ZodString; commitOid: z.ZodString; }, "strip", z.ZodTypeAny, { kind?: "at"; treeOid?: string; commitOid?: string; }, { kind?: "at"; treeOid?: string; commitOid?: string; }>]>CommitInputSchema
constconst CommitInputSchema: z.ZodObject<{ base: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{ kind: z.ZodLiteral<"fresh">; }, "strip", z.ZodTypeAny, { kind?: "fresh"; }, { kind?: "fresh"; }>, z.ZodObject<{ kind: z.ZodLiteral<"at">; treeOid: z.ZodString; commitOid: z.ZodString; }, "strip", z.ZodTypeAny, { kind?: "at"; treeOid?: string; commitOid?: string; }, { kind?: "at"; treeOid?: string; commitOid?: string; }>]>; changes: z.ZodArray<z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{ kind: z.ZodLiteral<"write">; path: z.ZodString; content: z.ZodType<Uint8Array<ArrayBuffer>, z.ZodTypeDef, Uint8Array<ArrayBuffer>>; }, "strip", z.ZodTypeAny, { kind?: "write"; path?: string; content?: Uint8Array<ArrayBuffer>; }, { kind?: "write"; path?: string; content?: Uint8Array<ArrayBuffer>; }>, z.ZodObject<{ kind: z.ZodLiteral<"delete">; path: z.ZodString; }, "strip", z.ZodTypeAny, { kind?: "delete"; path?: string; }, { kind?: "delete"; path?: string; }>]>, "many">; message: z.ZodString; author: z.ZodObject<{ name: z.ZodString; email: z.ZodString; timestampISO: z.ZodString; }, "strip", z.ZodTypeAny, { name?: string; email?: string; timestampISO?: string; }, { name?: string; email?: string; timestampISO?: string; }>; }, "strip", z.ZodTypeAny, { message?: string; base?: { kind?: "fresh"; } | { kind?: "at"; treeOid?: string; commitOid?: string; }; changes?: ({ kind?: "write"; path?: string; content?: Uint8Array<ArrayBuffer>; } | { kind?: "delete"; path?: string; })[]; author?: { name?: string; email?: string; timestampISO?: string; }; }, { message?: string; base?: { kind?: "fresh"; } | { kind?: "at"; treeOid?: string; commitOid?: string; }; changes?: ({ kind?: "write"; path?: string; content?: Uint8Array<ArrayBuffer>; } | { kind?: "delete"; path?: string; })[]; author?: { name?: string; email?: string; timestampISO?: string; }; }>CommitResultSchema
constconst CommitResultSchema: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{ kind: z.ZodLiteral<"ok">; commitOid: z.ZodString; treeOid: z.ZodString; }, "strip", z.ZodTypeAny, { kind?: "ok"; treeOid?: string; commitOid?: string; }, { kind?: "ok"; treeOid?: string; commitOid?: string; }>, z.ZodObject<{ kind: z.ZodLiteral<"cas-conflict">; currentTreeOid: z.ZodString; }, "strip", z.ZodTypeAny, { kind?: "cas-conflict"; currentTreeOid?: string; }, { kind?: "cas-conflict"; currentTreeOid?: string; }>]>PushResultSchema
constconst PushResultSchema: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{ kind: z.ZodLiteral<"ok">; commitsAhead: z.ZodNumber; }, "strip", z.ZodTypeAny, { kind?: "ok"; commitsAhead?: number; }, { kind?: "ok"; commitsAhead?: number; }>, z.ZodObject<{ kind: z.ZodLiteral<"non-fast-forward">; remoteOid: z.ZodString; }, "strip", z.ZodTypeAny, { kind?: "non-fast-forward"; remoteOid?: string; }, { kind?: "non-fast-forward"; remoteOid?: string; }>, z.ZodObject<{ kind: z.ZodLiteral<"auth">; reason: z.ZodString; }, "strip", z.ZodTypeAny, { kind?: "auth"; reason?: string; }, { kind?: "auth"; reason?: string; }>, z.ZodObject<{ kind: z.ZodLiteral<"not-found">; }, "strip", z.ZodTypeAny, { kind?: "not-found"; }, { kind?: "not-found"; }>, z.ZodObject<{ kind: z.ZodLiteral<"network">; retriable: z.ZodBoolean; }, "strip", z.ZodTypeAny, { kind?: "network"; retriable?: boolean; }, { kind?: "network"; retriable?: boolean; }>]>PullResultSchema
constconst PullResultSchema: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{ kind: z.ZodLiteral<"ok">; fastForwarded: z.ZodBoolean; newHeadOid: z.ZodString; }, "strip", z.ZodTypeAny, { kind?: "ok"; fastForwarded?: boolean; newHeadOid?: string; }, { kind?: "ok"; fastForwarded?: boolean; newHeadOid?: string; }>, z.ZodObject<{ kind: z.ZodLiteral<"diverged">; localOid: z.ZodString; remoteOid: z.ZodString; }, "strip", z.ZodTypeAny, { kind?: "diverged"; remoteOid?: string; localOid?: string; }, { kind?: "diverged"; remoteOid?: string; localOid?: string; }>, z.ZodObject<{ kind: z.ZodLiteral<"auth">; reason: z.ZodString; }, "strip", z.ZodTypeAny, { kind?: "auth"; reason?: string; }, { kind?: "auth"; reason?: string; }>, z.ZodObject<{ kind: z.ZodLiteral<"not-found">; }, "strip", z.ZodTypeAny, { kind?: "not-found"; }, { kind?: "not-found"; }>, z.ZodObject<{ kind: z.ZodLiteral<"network">; retriable: z.ZodBoolean; }, "strip", z.ZodTypeAny, { kind?: "network"; retriable?: boolean; }, { kind?: "network"; retriable?: boolean; }>]>ResetHeadResultSchema
constconst ResetHeadResultSchema: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{ kind: z.ZodLiteral<"ok">; newHeadOid: z.ZodString; }, "strip", z.ZodTypeAny, { kind?: "ok"; newHeadOid?: string; }, { kind?: "ok"; newHeadOid?: string; }>, z.ZodObject<{ kind: z.ZodLiteral<"unknown-oid">; oid: z.ZodString; }, "strip", z.ZodTypeAny, { kind?: "unknown-oid"; oid?: string; }, { kind?: "unknown-oid"; oid?: string; }>]>CloneResultSchema
constconst CloneResultSchema: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{ kind: z.ZodLiteral<"ok">; headOid: z.ZodString; }, "strip", z.ZodTypeAny, { kind?: "ok"; headOid?: string; }, { kind?: "ok"; headOid?: string; }>, z.ZodObject<{ kind: z.ZodLiteral<"auth">; reason: z.ZodString; }, "strip", z.ZodTypeAny, { kind?: "auth"; reason?: string; }, { kind?: "auth"; reason?: string; }>, z.ZodObject<{ kind: z.ZodLiteral<"not-found">; }, "strip", z.ZodTypeAny, { kind?: "not-found"; }, { kind?: "not-found"; }>, z.ZodObject<{ kind: z.ZodLiteral<"network">; retriable: z.ZodBoolean; }, "strip", z.ZodTypeAny, { kind?: "network"; retriable?: boolean; }, { kind?: "network"; retriable?: boolean; }>, z.ZodObject<{ kind: z.ZodLiteral<"empty-init">; reason: z.ZodString; }, "strip", z.ZodTypeAny, { kind?: "empty-init"; reason?: string; }, { kind?: "empty-init"; reason?: string; }>]>RepoInfoSchema
constconst RepoInfoSchema: z.ZodObject<{ owner: z.ZodString; name: z.ZodString; isPrivate: z.ZodBoolean; defaultBranch: z.ZodString; pushedAt: z.ZodString; }, "strip", z.ZodTypeAny, { owner?: string; name?: string; isPrivate?: boolean; defaultBranch?: string; pushedAt?: string; }, { owner?: string; name?: string; isPrivate?: boolean; defaultBranch?: string; pushedAt?: string; }>RepoLookupResultSchema
constconst RepoLookupResultSchema: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{ kind: z.ZodLiteral<"found">; info: z.ZodObject<{ owner: z.ZodString; name: z.ZodString; isPrivate: z.ZodBoolean; defaultBranch: z.ZodString; pushedAt: z.ZodString; }, "strip", z.ZodTypeAny, { owner?: string; name?: string; isPrivate?: boolean; defaultBranch?: string; pushedAt?: string; }, { owner?: string; name?: string; isPrivate?: boolean; defaultBranch?: string; pushedAt?: string; }>; }, "strip", z.ZodTypeAny, { kind?: "found"; info?: { owner?: string; name?: string; isPrivate?: boolean; defaultBranch?: string; pushedAt?: string; }; }, { kind?: "found"; info?: { owner?: string; name?: string; isPrivate?: boolean; defaultBranch?: string; pushedAt?: string; }; }>, z.ZodObject<{ kind: z.ZodLiteral<"missing">; }, "strip", z.ZodTypeAny, { kind?: "missing"; }, { kind?: "missing"; }>, z.ZodObject<{ kind: z.ZodLiteral<"forbidden">; currentLogin: z.ZodString; }, "strip", z.ZodTypeAny, { kind?: "forbidden"; currentLogin?: string; }, { kind?: "forbidden"; currentLogin?: string; }>, z.ZodObject<{ kind: z.ZodLiteral<"network">; retriable: z.ZodBoolean; }, "strip", z.ZodTypeAny, { kind?: "network"; retriable?: boolean; }, { kind?: "network"; retriable?: boolean; }>]>CreateRepoArgsSchema
constconst CreateRepoArgsSchema: z.ZodObject<{ name: z.ZodString; isPrivate: z.ZodBoolean; }, "strip", z.ZodTypeAny, { name?: string; isPrivate?: boolean; }, { name?: string; isPrivate?: boolean; }>CreatedRepoSchema
constconst CreatedRepoSchema: z.ZodObject<{ owner: z.ZodString; name: z.ZodString; }, "strip", z.ZodTypeAny, { owner?: string; name?: string; }, { owner?: string; name?: string; }>CurrentLoginResultSchema
constconst CurrentLoginResultSchema: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{ kind: z.ZodLiteral<"ok">; login: z.ZodString; }, "strip", z.ZodTypeAny, { kind?: "ok"; login?: string; }, { kind?: "ok"; login?: string; }>, z.ZodObject<{ kind: z.ZodLiteral<"anonymous">; }, "strip", z.ZodTypeAny, { kind?: "anonymous"; }, { kind?: "anonymous"; }>, z.ZodObject<{ kind: z.ZodLiteral<"network">; retriable: z.ZodBoolean; }, "strip", z.ZodTypeAny, { kind?: "network"; retriable?: boolean; }, { kind?: "network"; retriable?: boolean; }>]>