Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 85 additions & 93 deletions bun.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@
"@eslint/js": "10.0.1",
"@types/node": "^25.9.3",
"@types/ws": "^8.18.1",
"@typescript-eslint/eslint-plugin": "^8.61.0",
"@typescript-eslint/parser": "^8.61.0",
"@typescript-eslint/eslint-plugin": "^8.61.1",
"@typescript-eslint/parser": "^8.61.1",
"eslint": "^10.5.0",
"fast-check": "4.8.0",
"globals": "^17.6.0",
"typescript": "^6.0.3",
"vitest": "^4.1.8"
"vitest": "^4.1.9"
}
}
12 changes: 6 additions & 6 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@
"@types/react": "^19.2.17",
"@types/react-dom": "^19.2.3",
"@types/ws": "^8.18.1",
"@typescript-eslint/eslint-plugin": "^8.61.0",
"@typescript-eslint/parser": "^8.61.0",
"@typescript-eslint/eslint-plugin": "^8.61.1",
"@typescript-eslint/parser": "^8.61.1",
"@vitejs/plugin-react": "^6.0.2",
"@vitest/coverage-v8": "^4.1.8",
"@vitest/coverage-v8": "^4.1.9",
"@vitest/eslint-plugin": "^1.6.20",
"biome": "npm:@biomejs/biome@^2.5.0",
"eslint": "^10.5.0",
Expand All @@ -114,14 +114,14 @@
"eslint-plugin-simple-import-sort": "^13.0.0",
"eslint-plugin-sonarjs": "^4.0.3",
"eslint-plugin-sort-destructure-keys": "^3.0.0",
"eslint-plugin-unicorn": "^65.0.1",
"eslint-plugin-unicorn": "^67.0.0",
"fast-check": "4.8.0",
"globals": "^17.6.0",
"jscpd": "^5.0.9",
"typescript": "^6.0.3",
"typescript-eslint": "^8.61.0",
"typescript-eslint": "^8.61.1",
"vite": "^8.0.16",
"vitest": "^4.1.8",
"vitest": "^4.1.9",
"ws": "^8.21.0"
}
}
10 changes: 5 additions & 5 deletions packages/app/src/docker-git/api-client-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { Effect } from "effect"
import {
authStreamMarkerExitCode,
type AuthStreamMarkers,
authStreamSucceeded,
codexLoginFailureMessage,
codexLoginStreamMarkers,
didAuthStreamSucceed,
githubLoginFailureMessage,
githubLoginStreamMarkers,
gitlabLoginFailureMessage,
Expand Down Expand Up @@ -62,14 +62,14 @@ const requestMarkedAuthStream = (
const output = yield* _(requestTextStream("POST", path, body, writer.writeChunk))
writer.flushVisiblePending()

if (authStreamSucceeded(output, markers)) {
if (didAuthStreamSucceed(output, markers)) {
return output
}

const exitCode = authStreamMarkerExitCode(output, markers)
const message = failureMessage(output, exitCode)
return yield* _(
Effect.fail<ApiRequestError>(
streamFailure("POST", path, failureMessage(output, authStreamMarkerExitCode(output, markers)))
)
Effect.fail<ApiRequestError>(streamFailure("POST", path, message))
)
})

Expand Down
8 changes: 4 additions & 4 deletions packages/app/src/docker-git/api-client-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ export const buildCreateProjectRequest = (
containerName: config.containerName,
serviceName: config.serviceName,
volumeName: config.volumeName,
authorizedKeysPath: resolvedPaths.authorizedKeysContents === undefined
? resolvedPaths.authorizedKeysPath
: defaultTemplateConfig.authorizedKeysPath,
authorizedKeysPath: (resolvedPaths.authorizedKeysContents === undefined
? resolvedPaths
: defaultTemplateConfig).authorizedKeysPath,
authorizedKeysContents: resolvedPaths.authorizedKeysContents,
envGlobalPath: config.envGlobalPath,
envProjectPath: config.envProjectPath,
Expand Down Expand Up @@ -55,6 +55,6 @@ export const buildCreateProjectRequest = (
force: command.force,
forceEnv: command.forceEnv,
waitForClone: command.waitForClone,
...(options?.async === true ? { async: true } : {})
...((options?.async === true) && { async: true })
} satisfies JsonRequest
}
11 changes: 5 additions & 6 deletions packages/app/src/docker-git/api-client-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,14 @@ export const waitForProjectCreation = (
export const startProjectEventPolling = (projectId: string, initialCursor: number) =>
Effect.gen(function*(_) {
const cursorRef = yield* _(Ref.make(initialCursor))
const pollSchedule = Schedule.addDelay(
Schedule.forever,
() => projectEventPollInterval
)
const fiber = yield* _(
pollProjectEventsOnce(projectId, cursorRef).pipe(
Effect.ignore,
Effect.repeat(
Schedule.addDelay(
Schedule.forever,
() => projectEventPollInterval
)
),
Effect.repeat(pollSchedule),
Effect.fork
)
)
Expand Down
37 changes: 17 additions & 20 deletions packages/app/src/docker-git/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,15 @@ const projectPath = (projectId: string, suffix = ""): string => `/projects/${enc

const decodeProjectResponse = (payload: JsonValue) => {
const object = asObject(payload)
return object === null
? decodeProjectDetails(payload)
: decodeProjectDetails(object["project"] ?? payload)
return decodeProjectDetails(object === null ? payload : object["project"] ?? payload)
}

const decodeProjectsResponse = <A>(
payload: JsonValue,
decode: (value: JsonValue) => A | null
): ReadonlyArray<A> => {
const object = asObject(payload)
const items = object === null ? asArray(payload) : asArray(object["projects"])
const items = asArray(object === null ? payload : object["projects"])
return items
.map((item) => decode(item))
.filter((value): value is A => value !== null)
Expand All @@ -93,8 +91,8 @@ const createProjectAsync = (
resolvedPaths: ResolvedCreateRequestPaths
) =>
Effect.gen(function*(_) {
const createRequest = buildCreateProjectRequest(command, resolvedPaths, { async: true })
const payload = yield* _(request("POST", "/projects", createRequest))
const requestBody = buildCreateProjectRequest(command, resolvedPaths, { async: true })
const payload = yield* _(request("POST", "/projects", requestBody))
const accepted = decodeCreateProjectAccepted(payload)
if (accepted === null) {
return yield* _(Effect.fail(invalidCreateAcceptedResponse()))
Expand Down Expand Up @@ -141,8 +139,8 @@ const createProjectWithResolvedPaths = (
return yield* _(createProjectAsync(command, resolvedPaths))
}

const createRequest = buildCreateProjectRequest(command, resolvedPaths)
const projectId = asString(createRequest.outDir)
const requestBody = buildCreateProjectRequest(command, resolvedPaths)
const projectId = asString(requestBody.outDir)
const initialCursor = projectId === null
? null
: yield* _(
Expand All @@ -153,13 +151,12 @@ const createProjectWithResolvedPaths = (
const eventPolling = projectId === null || initialCursor === null
? null
: yield* _(startProjectEventPolling(projectId, initialCursor))
const ensureStopped = eventPolling === null
? Effect.void
: stopProjectEventPolling(eventPolling)
const payload = yield* _(
request("POST", "/projects", createRequest).pipe(
Effect.ensuring(
eventPolling === null
? Effect.void
: stopProjectEventPolling(eventPolling)
)
request("POST", "/projects", requestBody).pipe(
Effect.ensuring(ensureStopped)
)
)
return decodeProjectResponse(payload)
Expand All @@ -176,10 +173,9 @@ const withProjectEventPolling = <A, E, R>(
)
)
const eventPolling = yield* _(startProjectEventPolling(projectId, initialCursor))
const ensureStopped = stopProjectEventPolling(eventPolling)
return yield* _(
effect.pipe(
Effect.ensuring(stopProjectEventPolling(eventPolling))
)
effect.pipe(Effect.ensuring(ensureStopped))
)
})

Expand Down Expand Up @@ -236,8 +232,8 @@ export const readProjectLogs = (projectId: string) =>
Effect.map((payload) => readProjectOutput(payload))
)

export const readContainerTaskSnapshot = (projectId: string, includeDefault: boolean) =>
request("GET", projectPath(projectId, `/tasks${includeDefault ? "?includeDefault=true" : ""}`)).pipe(
export const readContainerTaskSnapshot = (projectId: string, shouldIncludeDefault: boolean) =>
request("GET", projectPath(projectId, `/tasks${shouldIncludeDefault ? "?includeDefault=true" : ""}`)).pipe(
Effect.map((payload) => decodeContainerTaskSnapshot(payload))
)

Expand Down Expand Up @@ -275,7 +271,8 @@ export const createAuthTerminalSession = (

export const deleteTerminalSessionByPath = (path: string) => requestVoid("DELETE", path)

export const applyAllProjects = (activeOnly: boolean) => requestVoid("POST", "/projects/apply-all", { activeOnly })
export const applyAllProjects = (isActiveOnly: boolean) =>
requestVoid("POST", "/projects/apply-all", { activeOnly: isActiveOnly })

export const downAllProjects = () => requestVoid("POST", "/projects/down-all")

Expand Down
10 changes: 5 additions & 5 deletions packages/app/src/docker-git/api-http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ const readErrorPayload = (body: JsonValue): ApiErrorPayload | undefined => {
const details = error["details"]

return {
...(type === null ? {} : { type }),
...(message === null ? {} : { message }),
...(provider === null ? {} : { provider }),
...(command === null ? {} : { command }),
...(details === undefined ? {} : { details })
...(type !== null && { type }),
...(message !== null && { message }),
...(provider !== null && { provider }),
...(command !== null && { command }),
...(details !== undefined && { details })
}
}

Expand Down
13 changes: 5 additions & 8 deletions packages/app/src/docker-git/api-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@ import { type JsonObject, type JsonValue, JsonValueSchema } from "../shared/json

export type { JsonObject, JsonValue } from "../shared/json-schema.js"

export type JsonRequest =
| boolean
| number
| string
| null
| { readonly [key: string]: JsonRequest | undefined }
| ReadonlyArray<JsonRequest>
export type JsonRequest = boolean | number | string | ReadonlyArray<JsonRequest> | {
readonly [key: string]: JsonRequest | undefined
} | null

const JsonValueFromStringSchema: Schema.Schema<JsonValue, string> = Schema.parseJson(JsonValueSchema)

Expand Down Expand Up @@ -47,11 +43,12 @@ export const asString = (value: JsonValue | undefined): string | null => typeof
const renderGithubStatusLine = (entry: JsonObject): string | null => {
const label = asString(entry["label"])
const status = asString(entry["status"])
const login = asString(entry["login"])
if (label === null || status === null) {
return null
}

const login = asString(entry["login"])

if (status === "valid") {
return login === null
? `- ${label}: valid (owner unavailable)`
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/docker-git/browser-frontend-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ export const readBrowserFrontendState = (
Effect.gen(function*(_) {
const fs = yield* _(FileSystem.FileSystem)
const exists = yield* _(Effect.either(fs.exists(statePath)))
const fileExists = Either.match(exists, {
const isFileExists = Either.match(exists, {
onLeft: () => false,
onRight: (value) => value
})
if (!fileExists) {
if (!isFileExists) {
return null
}

Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/docker-git/browser-frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ export const runBrowserFrontendCommandWithOptions = (
if (!decision.shouldStartWeb) {
return Effect.log(`docker-git browser frontend is already running at http://${decision.host}:${decision.port}/`)
}
return options.daemon ? runBrowserFrontendDaemon(decision) : runBrowserFrontend(decision)
return (options.daemon ? runBrowserFrontendDaemon : runBrowserFrontend)(decision)
})
)

Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/docker-git/cli/parser-clone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export const parseClone = (args: ReadonlyArray<string>): Either.Either<Command,
const withRef = resolvedRepo.repoRef !== undefined && raw.repoRef === undefined
? { ...withDefaults, repoRef: resolvedRepo.repoRef }
: withDefaults
const openSsh = raw.openSsh ?? true
const isOpenSsh = raw.openSsh ?? true
const create = yield* _(buildCreateCommand(withRef))
return { ...create, waitForClone: true, openSsh }
return { ...create, waitForClone: true, openSsh: isOpenSsh }
})
}
13 changes: 5 additions & 8 deletions packages/app/src/docker-git/cli/parser-open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const splitOpenArgs = (

const buildOpenCommand = (parts: OpenParts): OpenCommand => ({
_tag: "Open",
...(parts.projectRef === undefined ? {} : { projectRef: parts.projectRef }),
...(parts.projectDir === undefined ? {} : { projectDir: parts.projectDir })
...(parts.projectRef !== undefined && { projectRef: parts.projectRef }),
...(parts.projectDir !== undefined && { projectDir: parts.projectDir })
})

// CHANGE: parse open as a distinct selector-based command
Expand All @@ -42,12 +42,9 @@ export const parseOpen = (args: ReadonlyArray<string>): Either.Either<OpenComman
return Either.flatMap(parseRawOptions(rest), (raw) =>
Either.right(
buildOpenCommand({
...(trimToUndefined(raw.projectDir) === undefined
? {}
: { projectDir: trimToUndefined(raw.projectDir) }),
...(trimToUndefined(raw.containerName ?? raw.repoUrl ?? positionalRef) === undefined
? {}
: { projectRef: trimToUndefined(raw.containerName ?? raw.repoUrl ?? positionalRef) })
...(trimToUndefined(raw.projectDir) !== undefined && { projectDir: trimToUndefined(raw.projectDir) }),
...(trimToUndefined(raw.containerName ?? raw.repoUrl ?? positionalRef) !== undefined &&
{ projectRef: trimToUndefined(raw.containerName ?? raw.repoUrl ?? positionalRef) })
})
))
}
4 changes: 2 additions & 2 deletions packages/app/src/docker-git/cli/parser-scrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ const makeScrapExportCommand = (projectDir: string, archivePath: string, mode: "
const makeScrapImportCommand = (
projectDir: string,
archivePath: string,
wipe: boolean,
shouldWipe: boolean,
mode: "session"
): Command => ({
_tag: "ScrapImport",
projectDir,
archivePath,
wipe,
wipe: shouldWipe,
mode
})

Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/docker-git/cli/parser-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const parsePositiveInt = (
option: string,
raw: string
): Either.Either<number, ParseError> => {
const value = Number.parseInt(raw, 10)
const value = Math.trunc(Number(raw))
if (!Number.isFinite(value) || value <= 0) {
const error: ParseError = {
_tag: "InvalidOption",
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/docker-git/cli/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ const parseBrowser = (args: ReadonlyArray<string>): Either.Either<Command, Parse
// INVARIANT: activeOnly is true only when --active flag is present
// COMPLEXITY: O(n) where n = |args|
const parseApplyAll = (args: ReadonlyArray<string>): Either.Either<Command, ParseError> => {
const activeOnly = args.includes("--active")
const command: Command = { _tag: "ApplyAll", activeOnly }
const isActiveOnly = args.includes("--active")
const command: Command = { _tag: "ApplyAll", activeOnly: isActiveOnly }
return Either.right(command)
}

Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/docker-git/cli/read-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const applyControllerResourceLimitEnv = (
): Effect.Effect<ReadonlyArray<string>> =>
Effect.sync(() => {
const assignments = controllerResourceLimitEnvAssignments(parsed.controllerResourceLimits)
const forceRecreate = shouldForceRecreateForControllerResourceLimitIntent(parsed.controllerResourceLimits, {
const isForceRecreate = shouldForceRecreateForControllerResourceLimitIntent(parsed.controllerResourceLimits, {
cpuLimit: process.env[controllerCpuLimitEnvKey],
ramLimit: process.env[controllerMemoryLimitEnvKey],
pidsLimit: process.env[controllerPidsLimitEnvKey]
Expand All @@ -29,7 +29,7 @@ const applyControllerResourceLimitEnv = (
process.env[assignment.key] = assignment.value
}

process.env[controllerResourceLimitsForceRecreateEnvKey] = forceRecreate ? "1" : "0"
process.env[controllerResourceLimitsForceRecreateEnvKey] = isForceRecreate ? "1" : "0"

return parsed.args
})
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/docker-git/controller-compose-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export const resolveControllerRuntimeOverlayPath = (
path.dirname(composePath),
overlayFileName
)
const exists = yield* _(fs.exists(runtimeOverlayPath).pipe(Effect.mapError(mapComposePathError)))
return exists
const isExists = yield* _(fs.exists(runtimeOverlayPath).pipe(Effect.mapError(mapComposePathError)))
return isExists
? runtimeOverlayPath
: yield* _(
Effect.fail(
Expand Down
Loading